From 3cc35e224c6fe6bb82685ff8b2758553563e2a05 Mon Sep 17 00:00:00 2001 From: Dmitriy Ivanov Date: Tue, 17 Nov 2015 18:36:50 -0800 Subject: [PATCH] Ignore target sdk version for the public namespace This fixes the bug with using the libraries loaded prior to android_set_target_sdk_version call. Bug: http://b/22548808 Change-Id: I3ca2d367b0fa930a437bbb65f780834803d2ef0a --- linker/linker.cpp | 7 +++++-- tests/dlext_test.cpp | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index 27bcb216e..8b678ffb5 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -2255,9 +2255,12 @@ bool init_public_namespace(const char* libs) { g_public_namespace.clear(); }); - soinfo* candidate; for (const auto& soname : sonames) { - if (!find_loaded_library_by_soname(&g_default_namespace, soname.c_str(), &candidate)) { + soinfo* candidate = nullptr; + + find_loaded_library_by_soname(&g_default_namespace, soname.c_str(), &candidate); + + if (candidate == nullptr) { DL_ERR("Error initializing public namespace: \"%s\" was not found" " in the default namespace", soname.c_str()); return false; diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index 83bd5cc06..a56c771e5 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -707,6 +707,8 @@ TEST(dlext, ns_smoke) { dlclose(handle2); } +extern "C" void android_set_application_target_sdk_version(uint32_t target); + TEST(dlext, ns_isolated) { static const char* root_lib = "libnstest_root_not_isolated.so"; std::string path = std::string("libc.so:libc++.so:libdl.so:libm.so:") + g_public_lib; @@ -715,6 +717,8 @@ TEST(dlext, ns_isolated) { void* handle_public = dlopen((lib_path + "/public_namespace_libs/" + g_public_lib).c_str(), RTLD_NOW); ASSERT_TRUE(handle_public != nullptr) << dlerror(); + android_set_application_target_sdk_version(42U); // something > 23 + ASSERT_TRUE(android_init_public_namespace(path.c_str())) << dlerror(); android_namespace_t* ns_not_isolated = android_create_namespace("private", nullptr, (lib_path + "/private_namespace_libs").c_str(), false);