From 350bdad61cc6551db649fcaeb8642f4a1d6b139a Mon Sep 17 00:00:00 2001 From: Dimitry Ivanov Date: Tue, 1 Mar 2016 13:11:28 -0800 Subject: [PATCH] linker: print "not accessible" error message to the log Print properties of the namespace on "library is not accessible" error to better diagnose problems with native library accessiblity Bug: http://b/27406143 Change-Id: Icf3d6c604f09dfa015de863fdb1267d343930d2a --- linker/linker.cpp | 21 +++++++++++++++++++-- tests/dlext_test.cpp | 8 ++++++-- tests/gtest_main.cpp | 7 +++++++ tests/utils.h | 2 ++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/linker/linker.cpp b/linker/linker.cpp index a38a56603..0afbd40d0 100644 --- a/linker/linker.cpp +++ b/linker/linker.cpp @@ -93,6 +93,9 @@ struct android_namespace_t { default_library_paths_ = library_paths; } + const std::vector& get_permitted_paths() const { + return permitted_paths_; + } void set_permitted_paths(std::vector&& permitted_paths) { permitted_paths_ = permitted_paths; } @@ -1814,8 +1817,22 @@ static bool load_library(android_namespace_t* ns, } } else { // do not load libraries if they are not accessible for the specified namespace. - DL_ERR("library \"%s\" is not accessible for the namespace \"%s\"", - name, ns->get_name()); + const char* needed_or_dlopened_by = task->get_needed_by() == nullptr ? + "(unknown)" : + task->get_needed_by()->get_realpath(); + + DL_ERR("library \"%s\" needed or dlopened by \"%s\" is not accessible for the namespace \"%s\"", + name, needed_or_dlopened_by, ns->get_name()); + + PRINT("library \"%s\" (\"%s\") needed or dlopened by \"%s\" is not accessible for the" + " namespace: [name=\"%s\", ld_library_paths=\"%s\", default_library_paths=\"%s\"," + " permitted_paths=\"%s\"]", + name, realpath.c_str(), + needed_or_dlopened_by, + ns->get_name(), + android::base::Join(ns->get_ld_library_paths(), ':').c_str(), + android::base::Join(ns->get_default_library_paths(), ':').c_str(), + android::base::Join(ns->get_permitted_paths(), ':').c_str()); return false; } } diff --git a/tests/dlext_test.cpp b/tests/dlext_test.cpp index c64ec159f..66d885952 100644 --- a/tests/dlext_test.cpp +++ b/tests/dlext_test.cpp @@ -799,7 +799,9 @@ TEST(dlext, ns_isolated) { // Check dlopen by absolute path handle2 = android_dlopen_ext(lib_private_external_path.c_str(), RTLD_NOW, &extinfo); ASSERT_TRUE(handle2 == nullptr); - ASSERT_EQ("dlopen failed: library \"" + lib_private_external_path + "\" is not accessible for the namespace \"private_isolated1\"", dlerror()); + ASSERT_EQ("dlopen failed: library \"" + lib_private_external_path + "\" needed" + " or dlopened by \"" + get_executable_name() + "\" is not accessible" + " for the namespace \"private_isolated1\"", dlerror()); extinfo.library_namespace = ns_isolated2; @@ -899,7 +901,9 @@ TEST(dlext, ns_shared) { // Check dlopen by absolute path handle2 = android_dlopen_ext(lib_private_external_path.c_str(), RTLD_NOW, &extinfo); ASSERT_TRUE(handle2 == nullptr); - ASSERT_EQ("dlopen failed: library \"" + lib_private_external_path + "\" is not accessible for the namespace \"private_isolated_shared\"", dlerror()); + ASSERT_EQ("dlopen failed: library \"" + lib_private_external_path + "\" needed" + " or dlopened by \"" + get_executable_name() + "\" is not accessible" + " for the namespace \"private_isolated_shared\"", dlerror()); // load libnstest_root.so to shared namespace in order to check that everything is different // except shared libnstest_dlopened.so diff --git a/tests/gtest_main.cpp b/tests/gtest_main.cpp index 7360f1239..ad23aa80c 100644 --- a/tests/gtest_main.cpp +++ b/tests/gtest_main.cpp @@ -46,6 +46,12 @@ #endif +static std::string g_executable_name; + +const std::string& get_executable_name() { + return g_executable_name; +} + namespace testing { namespace internal { @@ -1113,6 +1119,7 @@ static bool PickOptions(std::vector& args, IsolationTestOptions& options) } int main(int argc, char** argv) { + g_executable_name = argv[0]; std::vector arg_list; for (int i = 0; i < argc; ++i) { arg_list.push_back(argv[i]); diff --git a/tests/utils.h b/tests/utils.h index 828c8d052..a335c6663 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -119,4 +119,6 @@ static inline void AssertChildExited(int pid, int expected_exit_status) { ASSERT_EQ(expected_exit_status, WEXITSTATUS(status)); } +const std::string& get_executable_name(); + #endif -- 2.11.0