Add test for misaligned section header

Make sure linker does not crash when dlopening
elf-file with odd section header offset.

Bug: http://b/30795430
Bug: http://b/30687964
Test: bionic-unit-tests --gtest_filter=dlfcn.dlopen_invalid*
Change-Id: If59cb6da85b8752a69dc5687de85f9a9b74c92b4
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index a1c5801..9419bf3 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -1161,4 +1161,13 @@
   std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\": W + E load segments are not allowed";
   ASSERT_STREQ(expected_dlerror.c_str(), dlerror());
 }
+
+TEST(dlfcn, dlopen_invalid_unaligned_shdr_offset) {
+  std::string libpath = std::string(getenv("ANDROID_DATA")) + PREBUILT_ELF_PATH + "/libtest_invalid-unaligned_shdr_offset.so";
+  void* handle = dlopen(libpath.c_str(), RTLD_NOW);
+  ASSERT_TRUE(handle == nullptr);
+  std::string expected_dlerror = std::string("dlopen failed: \"") + libpath + "\" has invalid shdr offset/size: ";
+  ASSERT_SUBSTR(expected_dlerror.c_str(), dlerror());
+}
+
 #endif