Handle empty relro segment or incorrectly sized file.
If the file has no relro segment, the generated relro file will have
length 0, which caused mmap to fail. If the relro file has nonzero size,
but is too short (e.g. because it's for the wrong version of the
library), the linker would segfault while comparing the data. Fix both
these issues: don't try to map a zero length file, and don't try to
compare data that would be beyond the end of the file.
Improve test to explicitly generate two versions of the library: one
with -z relro, and one with -z norelro, so we can test both cases; also
explicitly test the case where the relro file has length 0.
Bug: 14299541
Change-Id: Id8b95585edda90e8bb5de452a35b70ed2d224934
diff --git a/tests/Android.mk b/tests/Android.mk
index 0014af6..c6fa54e 100644
--- a/tests/Android.mk
+++ b/tests/Android.mk
@@ -190,17 +190,32 @@
endif
# -----------------------------------------------------------------------------
-# Library used by dlext tests.
+# Library used by dlext tests - with/without GNU RELRO program header
# -----------------------------------------------------------------------------
libdlext_test_src_files := \
dlext_test_library.cpp \
+libdlext_test_ldflags := \
+ -Wl,-z,relro \
+
module := libdlext_test
module_tag := optional
build_type := target
build_target := SHARED_LIBRARY
include $(LOCAL_PATH)/Android.build.mk
+libdlext_test_norelro_src_files := \
+ dlext_test_library.cpp \
+
+libdlext_test_norelro_ldflags := \
+ -Wl,-z,norelro \
+
+module := libdlext_test_norelro
+module_tag := optional
+build_type := target
+build_target := SHARED_LIBRARY
+include $(LOCAL_PATH)/Android.build.mk
+
# -----------------------------------------------------------------------------
# Tests for the device using bionic's .so. Run with:
# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests