summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDmitriy Ivanov <dimitry@google.com>2015-05-30 13:04:39 -0700
committerDmitriy Ivanov <dimitry@google.com>2015-06-01 16:57:33 -0700
commitc4ebe60e1a2fc165ff11442765325628e27f2a05 (patch)
tree01a510b550aed2f303ca0c9dbf1cf081a55a5d5c /tests
parentc5e02eeb353c3cdd357413f563701d5018fc76a5 (diff)
downloadbionic-c4ebe60e1a2fc165ff11442765325628e27f2a05.zip
bionic-c4ebe60e1a2fc165ff11442765325628e27f2a05.tar.gz
bionic-c4ebe60e1a2fc165ff11442765325628e27f2a05.tar.bz2
Fix dlsym(handle_of_main_executable, ...)
According to man dlopen(3) and posix docs in the case when si is handle of the main executable we need to search not only in the executable and its dependencies but also in all libraries loaded with RTLD_GLOBAL. see also: http://pubs.opengroup.org/onlinepubs/9699919799/functions/dlopen.html Bug: http://b/21528224 Bug: http://b/17512583 Bug: https://code.google.com/p/android/issues/detail?id=173822 Change-Id: Ib2801367ba48b6f3704da89a6d9f5e6911430013 (cherry picked from commit f439b5a3186ca0fef1092f45770abc716da9d87a)
Diffstat (limited to 'tests')
-rw-r--r--tests/dlfcn_test.cpp28
-rw-r--r--tests/libs/Android.mk8
2 files changed, 34 insertions, 2 deletions
diff --git a/tests/dlfcn_test.cpp b/tests/dlfcn_test.cpp
index a5abda7..3c9b8e3 100644
--- a/tests/dlfcn_test.cpp
+++ b/tests/dlfcn_test.cpp
@@ -145,13 +145,28 @@ TEST(dlfcn, dlsym_from_sofile_with_preload) {
dlclose(preload);
}
+TEST(dlfcn, dlsym_handle_global_sym) {
+ // check that we do not look into global group
+ // when looking up symbol by handle
+ void* handle = dlopen("libtest_empty.so", RTLD_NOW);
+ dlopen("libtest_with_dependency.so", RTLD_NOW | RTLD_GLOBAL);
+ void* sym = dlsym(handle, "getRandomNumber");
+ ASSERT_TRUE(sym == nullptr);
+ ASSERT_SUBSTR("undefined symbol: getRandomNumber", dlerror());
+
+ sym = dlsym(handle, "DlSymTestFunction");
+ ASSERT_TRUE(sym == nullptr);
+ ASSERT_SUBSTR("undefined symbol: DlSymTestFunction", dlerror());
+ dlclose(handle);
+}
+
TEST(dlfcn, dlsym_with_dependencies) {
void* handle = dlopen("libtest_with_dependency.so", RTLD_NOW);
- ASSERT_TRUE(handle != NULL);
+ ASSERT_TRUE(handle != nullptr);
dlerror();
// This symbol is in DT_NEEDED library.
void* sym = dlsym(handle, "getRandomNumber");
- ASSERT_TRUE(sym != NULL);
+ ASSERT_TRUE(sym != nullptr) << dlerror();
int (*fn)(void);
fn = reinterpret_cast<int (*)(void)>(sym);
EXPECT_EQ(4, fn());
@@ -583,6 +598,15 @@ TEST(dlfcn, dlopen_check_rtld_global) {
// RTLD_GLOBAL implies RTLD_NODELETE, let's check that
void* sym_after_dlclose = dlsym(RTLD_DEFAULT, "dlopen_testlib_simple_func");
ASSERT_EQ(sym, sym_after_dlclose);
+
+ // Check if dlsym() for main program's handle searches RTLD_GLOBAL
+ // shared libraries after symbol was not found in the main executable
+ // and dependent libraries.
+ void* handle_for_main_executable = dlopen(nullptr, RTLD_NOW);
+ sym = dlsym(handle_for_main_executable, "dlopen_testlib_simple_func");
+ ASSERT_TRUE(sym != nullptr) << dlerror();
+
+ dlclose(handle_for_main_executable);
}
// libtest_with_dependency_loop.so -> libtest_with_dependency_loop_a.so ->
diff --git a/tests/libs/Android.mk b/tests/libs/Android.mk
index 15fa55c..a5ef622 100644
--- a/tests/libs/Android.mk
+++ b/tests/libs/Android.mk
@@ -405,6 +405,14 @@ module := libtest_dlsym_from_this_grandchild
include $(LOCAL_PATH)/Android.build.testlib.mk
# -----------------------------------------------------------------------------
+# Empty library
+# -----------------------------------------------------------------------------
+libtest_empty_src_files := empty.cpp
+
+module := libtest_empty
+include $(LOCAL_PATH)/Android.build.testlib.mk
+
+# -----------------------------------------------------------------------------
# Library with weak undefined function
# -----------------------------------------------------------------------------
libtest_dlopen_weak_undefined_func_src_files := \