Extract ld.config.txt lookup code
This commit extracts ld.config.txt lookup code into
`get_ld_config_file_path()`.
Bug: 78605339
Test: aosp_walleye-userdebug builds and boots
Change-Id: I129f19cd032de02a56bda57231521c02a4b4e4c0
Merged-In: I129f19cd032de02a56bda57231521c02a4b4e4c0
(cherry picked from commit 21e496cf2916d8361f378ed96357bf806b0f198c)
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 96f424e..44ca7b6 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3717,6 +3717,38 @@
return namespaces;
}
+static std::string get_ld_config_file_vndk_path() {
+ std::string ld_config_file_vndk = kLdConfigFilePath;
+ size_t insert_pos = ld_config_file_vndk.find_last_of('.');
+ if (insert_pos == std::string::npos) {
+ insert_pos = ld_config_file_vndk.length();
+ }
+ ld_config_file_vndk.insert(insert_pos, Config::get_vndk_version_string('.'));
+ return ld_config_file_vndk;
+}
+
+static std::string get_ld_config_file_path() {
+#ifdef USE_LD_CONFIG_FILE
+ // This is a debugging/testing only feature. Must not be available on
+ // production builds.
+ const char* ld_config_file_env = getenv("LD_CONFIG_FILE");
+ if (ld_config_file_env != nullptr && file_exists(ld_config_file_env)) {
+ return ld_config_file_env;
+ }
+#endif
+
+ if (file_exists(kLdConfigArchFilePath)) {
+ return kLdConfigArchFilePath;
+ }
+
+ std::string ld_config_file_vndk = get_ld_config_file_vndk_path();
+ if (file_exists(ld_config_file_vndk.c_str())) {
+ return ld_config_file_vndk;
+ }
+
+ return kLdConfigFilePath;
+}
+
std::vector<android_namespace_t*> init_default_namespaces(const char* executable_path) {
g_default_namespace.set_name("(default)");
@@ -3734,31 +3766,16 @@
std::string error_msg;
- std::string ld_config_vndk = kLdConfigFilePath;
- size_t insert_pos = ld_config_vndk.find_last_of('.');
- if (insert_pos == std::string::npos) {
- insert_pos = ld_config_vndk.length();
- }
- ld_config_vndk.insert(insert_pos, Config::get_vndk_version_string('.'));
- const char* ld_config_txt = file_exists(ld_config_vndk.c_str()) ? ld_config_vndk.c_str() : kLdConfigFilePath;
- const char* config_file = file_exists(kLdConfigArchFilePath) ? kLdConfigArchFilePath : ld_config_txt;
-#ifdef USE_LD_CONFIG_FILE
- // This is a debugging/testing only feature. Must not be available on
- // production builds.
- const char* ld_config_file = getenv("LD_CONFIG_FILE");
- if (ld_config_file != nullptr && file_exists(ld_config_file)) {
- config_file = ld_config_file;
- }
-#endif
+ std::string ld_config_file_path = get_ld_config_file_path();
- if (!Config::read_binary_config(config_file,
+ if (!Config::read_binary_config(ld_config_file_path.c_str(),
executable_path,
g_is_asan,
&config,
&error_msg)) {
if (!error_msg.empty()) {
DL_WARN("Warning: couldn't read \"%s\" for \"%s\" (using default configuration instead): %s",
- config_file,
+ ld_config_file_path.c_str(),
executable_path,
error_msg.c_str());
}