aboutsummaryrefslogtreecommitdiffstats
path: root/tests/dlext_test.cpp
diff options
context:
space:
mode:
authorDimitry Ivanov <dimitry@google.com>2017-03-27 14:11:02 -0700
committerDimitry Ivanov <dimitry@google.com>2017-04-01 19:15:32 -0700
commitdedcf35bcc98e8b62fb6480022cd11ae671280ad (patch)
tree922564308baea40441defe570dce912aff258615 /tests/dlext_test.cpp
parenteca0f9910d3b1fc5608fc82b1ff28325f74678cb (diff)
downloadandroid_bionic-dedcf35bcc98e8b62fb6480022cd11ae671280ad.tar.gz
android_bionic-dedcf35bcc98e8b62fb6480022cd11ae671280ad.tar.bz2
android_bionic-dedcf35bcc98e8b62fb6480022cd11ae671280ad.zip
Fix lookup logic for linked namespaces
When looking for already loaded libraries include linked namespaces to the search, but check if the library is accessible from the main namespace. Bug: http://b/36008422 Bug: http://b/35417197 Bug: http://b/34052337 Bug: http://b/36660652 Bug: https://issuetracker.google.com/36636090 Test: run bionic-unit-tests --gtest_filter=dl*:Dl* Change-Id: Ic7c1d48114da3ca5dc6512ef03f595dd17b6ed17 (cherry picked from commit d3e7d088453e089b3d625b0864ccdf3c74893f18)
Diffstat (limited to 'tests/dlext_test.cpp')
-rw-r--r--tests/dlext_test.cpp59
1 files changed, 51 insertions, 8 deletions
diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp
index 808b708da..a0226a6f6 100644
--- a/tests/dlext_test.cpp
+++ b/tests/dlext_test.cpp
@@ -672,8 +672,59 @@ TEST(dlext, ns_smoke) {
ASSERT_TRUE(handle != nullptr) << dlerror();
dlclose(handle);
+ // dlopen for a public library using an absolute path should work
+ // 1. For isolated namespaces
android_dlextinfo extinfo;
extinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
+ extinfo.library_namespace = ns2;
+ handle = android_dlopen_ext(lib_public_path.c_str(), RTLD_NOW, &extinfo);
+ ASSERT_TRUE(handle != nullptr) << dlerror();
+ ASSERT_TRUE(handle == handle_public);
+
+ dlclose(handle);
+
+ // 1.1 even if it wasn't loaded before
+ dlclose(handle_public);
+
+ handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW | RTLD_NOLOAD);
+ ASSERT_TRUE(handle_public == nullptr);
+ ASSERT_EQ(std::string("dlopen failed: library \"") + lib_public_path +
+ "\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
+
+ handle = android_dlopen_ext(lib_public_path.c_str(), RTLD_NOW, &extinfo);
+ ASSERT_TRUE(handle != nullptr) << dlerror();
+
+ handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
+ ASSERT_TRUE(handle == handle_public);
+
+ dlclose(handle);
+
+ // 2. And for regular namespaces (make sure it does not load second copy of the library)
+ extinfo.library_namespace = ns1;
+ handle = android_dlopen_ext(lib_public_path.c_str(), RTLD_NOW, &extinfo);
+ ASSERT_TRUE(handle != nullptr) << dlerror();
+ ASSERT_TRUE(handle == handle_public);
+
+ dlclose(handle);
+
+ // 2.1 Unless it was not loaded before - in which case it will load a duplicate.
+ // TODO(dimitry): This is broken. Maybe we need to deprecate non-isolated namespaces?
+ dlclose(handle_public);
+
+ handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW | RTLD_NOLOAD);
+ ASSERT_TRUE(handle_public == nullptr);
+ ASSERT_EQ(std::string("dlopen failed: library \"") + lib_public_path +
+ "\" wasn't loaded and RTLD_NOLOAD prevented it", dlerror());
+
+ handle = android_dlopen_ext(lib_public_path.c_str(), RTLD_NOW, &extinfo);
+ ASSERT_TRUE(handle != nullptr) << dlerror();
+
+ handle_public = dlopen(lib_public_path.c_str(), RTLD_NOW);
+
+ ASSERT_TRUE(handle != handle_public);
+
+ dlclose(handle);
+
extinfo.library_namespace = ns1;
void* handle1 = android_dlopen_ext(root_lib, RTLD_NOW, &extinfo);
@@ -685,14 +736,6 @@ TEST(dlext, ns_smoke) {
ASSERT_TRUE(handle1 != handle2);
- // dlopen for a public library using an absolute path should work for isolated namespaces
- extinfo.library_namespace = ns2;
- handle = android_dlopen_ext(lib_public_path.c_str(), RTLD_NOW, &extinfo);
- ASSERT_TRUE(handle != nullptr) << dlerror();
- ASSERT_TRUE(handle == handle_public);
-
- dlclose(handle);
-
typedef const char* (*fn_t)();
fn_t ns_get_local_string1 = reinterpret_cast<fn_t>(dlsym(handle1, "ns_get_local_string"));