aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2017-03-07 03:36:01 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2017-03-07 03:36:03 +0000
commit4dde93a73aaabf2021b02f6ca96c6ac162262fa3 (patch)
tree110f5fb24301524b9b4a49c6425429106602186c
parentcdf19c84e8c10f5afa079790e5a2b0a55a3599e9 (diff)
parent77ad64267c65fe876f27265ee91063810f5fe71a (diff)
downloadbionic-o-preview.tar.gz
Merge "Remove g_default_ld_paths global variable"android-o-preview-1o-preview
-rw-r--r--linker/linker.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/linker/linker.cpp b/linker/linker.cpp
index a3d1db2c4..432d008b9 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -207,7 +207,6 @@ static bool is_greylisted(android_namespace_t* ns, const char* name, const soinf
}
// END OF WORKAROUND
-static const char* const* g_default_ld_paths;
static std::vector<std::string> g_ld_preload_names;
static bool g_anonymous_namespace_initialized;
@@ -1783,18 +1782,22 @@ void do_android_get_LD_LIBRARY_PATH(char* buffer, size_t buffer_size) {
// See b/17302493 for further details.
// Once the above bug is fixed, this code can be modified to use
// snprintf again.
- size_t required_len = 0;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
- required_len += strlen(g_default_ld_paths[i]) + 1;
+ const auto& default_ld_paths = g_default_namespace.get_default_library_paths();
+
+ size_t required_size = 0;
+ for (const auto& path : default_ld_paths) {
+ required_size += path.size() + 1;
}
- if (buffer_size < required_len) {
+
+ if (buffer_size < required_size) {
__libc_fatal("android_get_LD_LIBRARY_PATH failed, buffer too small: "
- "buffer len %zu, required len %zu", buffer_size, required_len);
+ "buffer len %zu, required len %zu", buffer_size, required_size);
}
+
char* end = buffer;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
+ for (size_t i = 0; i < default_ld_paths.size(); ++i) {
if (i > 0) *end++ = ':';
- end = stpcpy(end, g_default_ld_paths[i]);
+ end = stpcpy(end, default_ld_paths[i].c_str());
}
}
@@ -3342,20 +3345,20 @@ void init_default_namespace() {
const char *interp = phdr_table_get_interpreter_name(somain->phdr, somain->phnum,
somain->load_bias);
const char* bname = basename(interp);
- if (bname && (strcmp(bname, "linker_asan") == 0 || strcmp(bname, "linker_asan64") == 0)) {
- g_default_ld_paths = kAsanDefaultLdPaths;
- g_is_asan = true;
- } else {
- g_default_ld_paths = kDefaultLdPaths;
- }
+
+ bool is_asan = bname != nullptr &&
+ (strcmp(bname, "linker_asan") == 0 ||
+ strcmp(bname, "linker_asan64") == 0);
+ auto default_ld_paths = is_asan ? kAsanDefaultLdPaths : kDefaultLdPaths;
+ g_is_asan = is_asan;
char real_path[PATH_MAX];
std::vector<std::string> ld_default_paths;
- for (size_t i = 0; g_default_ld_paths[i] != nullptr; ++i) {
- if (realpath(g_default_ld_paths[i], real_path) != nullptr) {
+ for (size_t i = 0; default_ld_paths[i] != nullptr; ++i) {
+ if (realpath(default_ld_paths[i], real_path) != nullptr) {
ld_default_paths.push_back(real_path);
} else {
- ld_default_paths.push_back(g_default_ld_paths[i]);
+ ld_default_paths.push_back(default_ld_paths[i]);
}
}