diff options
author | Victor Khimenko <khim@google.com> | 2020-05-17 22:41:44 +0200 |
---|---|---|
committer | Victor Khimenko <khim@google.com> | 2020-05-19 02:32:07 +0200 |
commit | 9b3e026c8f64dbbf84a7ae7b7f62688c3d0c91c4 (patch) | |
tree | 9c82585cf2e63511f7c5d5e4bb29d6ea3a0a93ba /linker/linker_translate_path.cpp | |
parent | 57a1c3908ff5a2e427f5d45992d0b463fd71b87a (diff) |
Refactor translateSystemPathToApexPath
This is more efficient and easier to read.
Test: bionic-unit-tests --gtest_filter=*icu*
Change-Id: Iddeed7cd4a1d48d8968f97951a9af004ccce52e8
Diffstat (limited to 'linker/linker_translate_path.cpp')
-rw-r--r-- | linker/linker_translate_path.cpp | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/linker/linker_translate_path.cpp b/linker/linker_translate_path.cpp index df7d0aabe..4f3fdfbc3 100644 --- a/linker/linker_translate_path.cpp +++ b/linker/linker_translate_path.cpp @@ -31,13 +31,14 @@ #include "linker_utils.h" #if defined(__LP64__) -static const char* const kSystemLibDir = "/system/lib64"; -static const char* const kI18nApexLibDir = "/apex/com.android.i18n/lib64"; +#define APEX_LIB(apex, name) \ + { "/system/lib64/" name, "/apex/" apex "/lib64/" name } #else -static const char* const kSystemLibDir = "/system/lib"; -static const char* const kI18nApexLibDir = "/apex/com.android.i18n/lib"; +#define APEX_LIB(apex, name) \ + { "/system/lib/" name, "/apex/" apex "/lib/" name } #endif + // Workaround for dlopen(/system/lib(64)/<soname>) when .so is in /apex. http://b/121248172 /** * Translate /system path to /apex path if needed @@ -47,27 +48,22 @@ static const char* const kI18nApexLibDir = "/apex/com.android.i18n/lib"; * return true if translation is needed */ bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_apex) { - static const char* const kSystemToArtApexLibs[] = { - "libicuuc.so", - "libicui18n.so", + static constexpr const char* kPathTranslationQ[][2] = { + APEX_LIB("com.android.i18n", "libicui18n.so"), + APEX_LIB("com.android.i18n", "libicuuc.so") }; - // New mapping for new apex should be added below - - // Nothing to do if target sdk version is Q or above - if (get_application_target_sdk_version() >= 29) { - return false; - } - // If the path isn't /system/lib, there's nothing to do. - if (name == nullptr || dirname(name) != kSystemLibDir) { + if (name == nullptr) { return false; } - const char* base_name = basename(name); + auto comparator = [name](auto p) { return strcmp(name, p[0]) == 0; }; - for (const char* soname : kSystemToArtApexLibs) { - if (strcmp(base_name, soname) == 0) { - *out_name_to_apex = std::string(kI18nApexLibDir) + "/" + base_name; + if (get_application_target_sdk_version() < __ANDROID_API_Q__) { + if (auto it = + std::find_if(std::begin(kPathTranslationQ), std::end(kPathTranslationQ), comparator); + it != std::end(kPathTranslationQ)) { + *out_name_to_apex = (*it)[1]; return true; } } |