Merge "Use ld.config.$VER.txt when current VNDK version is $VER"
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 85376e0..66ae191 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -3526,7 +3526,14 @@
std::string error_msg;
- const char* config_file = file_exists(kLdConfigArchFilePath) ? kLdConfigArchFilePath : kLdConfigFilePath;
+ 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.
diff --git a/linker/linker_config.cpp b/linker/linker_config.cpp
index f7d2c53..1af5da8 100644
--- a/linker/linker_config.cpp
+++ b/linker/linker_config.cpp
@@ -33,6 +33,7 @@
#include "linker_utils.h"
#include <android-base/file.h>
+#include <android-base/properties.h>
#include <android-base/scopeguard.h>
#include <android-base/strings.h>
@@ -278,15 +279,6 @@
return true;
}
-static std::string getVndkVersionString() {
- char vndk_version_str[1 + PROP_VALUE_MAX] = {};
- __system_property_get("ro.vndk.version", vndk_version_str + 1);
- if (strlen(vndk_version_str + 1) != 0 && strcmp(vndk_version_str + 1, "current") != 0) {
- vndk_version_str[0] = '-';
- }
- return vndk_version_str;
-}
-
static Config g_config;
static constexpr const char* kDefaultConfigName = "default";
@@ -346,7 +338,7 @@
params.push_back({ "SDK_VER", buf });
}
- static std::string vndk = getVndkVersionString();
+ static std::string vndk = Config::get_vndk_version_string('-');
params.push_back({ "VNDK_VER", vndk });
for (auto&& path : paths) {
@@ -503,6 +495,15 @@
return true;
}
+std::string Config::get_vndk_version_string(const char delimiter) {
+ std::string version = android::base::GetProperty("ro.vndk.version", "");
+ if (version != "" && version != "current") {
+ //add the delimiter char in front of the string and return it.
+ return version.insert(0, 1, delimiter);
+ }
+ return "";
+}
+
NamespaceConfig* Config::create_namespace_config(const std::string& name) {
namespace_configs_.push_back(std::unique_ptr<NamespaceConfig>(new NamespaceConfig(name)));
NamespaceConfig* ns_config_ptr = namespace_configs_.back().get();
diff --git a/linker/linker_config.h b/linker/linker_config.h
index 6f8bffb..dde9362 100644
--- a/linker/linker_config.h
+++ b/linker/linker_config.h
@@ -146,6 +146,8 @@
bool is_asan,
const Config** config,
std::string* error_msg);
+
+ static std::string get_vndk_version_string(const char delimiter);
private:
void clear();