diff options
author | Lev Rumyantsev <levarum@google.com> | 2020-09-27 04:22:16 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-09-27 04:22:16 +0000 |
commit | ac7012ba00d8f26ae2083aad749daa7dd9cb3066 (patch) | |
tree | 1563706ec3d6a9d336aeb6a9d0edc3b175ff7b96 | |
parent | 614cc1f343bd361148015f89c88ee8ca7991baa0 (diff) | |
parent | b5679b45e8b85e0f4896072f5aa87300a5656267 (diff) | |
download | native_bridge_support-ac7012ba00d8f26ae2083aad749daa7dd9cb3066.tar.gz |
2020-09-25: merge master to rvc-dev am: b5679b45e8android-mainline-11.0.0_r44android-mainline-11.0.0_r23android-mainline-11.0.0_r15android11-mainline-os-statsd-releaseandroid11-mainline-extservices-release
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/libs/native_bridge_support/+/12703091
Change-Id: Id9f740e43ba1f5b23a5ce4ddfa9c4f1ebee51fb8
-rw-r--r-- | linker/linker_translate_path.cpp | 142 | ||||
-rw-r--r-- | native_bridge_support.mk | 20 |
2 files changed, 100 insertions, 62 deletions
diff --git a/linker/linker_translate_path.cpp b/linker/linker_translate_path.cpp index 02a501c..b5f5816 100644 --- a/linker/linker_translate_path.cpp +++ b/linker/linker_translate_path.cpp @@ -15,75 +15,116 @@ */ #include "linker_translate_path.h" -#include "linker.h" + +#include <string> #include <android/api-level.h> -#include <string> +#include "linker.h" + +// Handle dlopen by full path. +// +// 1. Translate original path to native_bridge path. +// +// Native bridge libraries reside in $LIB/$ABI subdirectory. For example: +// /system/lib/liblog.so -> /system/lib/arm/liblog.so +// +// Native bridge libraries do not use apex. For example: +// /apex/com.android.i18n/lib/libicuuc.so -> /system/lib/arm/libicuuc.so +// +// 2. Repeat linker workaround to open apex libraries by system path (see http://b/121248172). +// +// For older target SDK versions, linker allows to open apex libraries by system path, so it does: +// /system/lib/libicuuc.so -> /apex/com.android.art/lib/libicuuc.so +// +// Adding native bridge path translation, we get: +// /system/lib/libicuuc.so -> /apex/com.android.art/lib/libicuuc.so -> /system/lib/arm/libicuuc.so #if defined(__arm__) #define SYSTEM_LIB(name) \ { "/system/lib/" name, "/system/lib/arm/" name } +#define APEX_LIB(apex, name) \ + { "/apex/" apex "/lib/" name, "/system/lib/arm/" name } #elif defined(__aarch64__) #define SYSTEM_LIB(name) \ { "/system/lib64/" name, "/system/lib64/arm64/" name } +#define APEX_LIB(apex, name) \ + { "/apex/" apex "/lib64/" name, "/system/lib64/arm64/" name } #else #error "Unknown guest arch" #endif -// Workaround for dlopen(/system/lib(64)/<soname>) when .so is in /apex. http://b/121248172 /** - * Translate /system path to /apex path if needed - * The workaround should work only when targetSdkVersion < Q. + * Translate /system path or /apex path to native_bridge path + * Function name is misleading, as it overrides the corresponding function in original linker. * - * param out_name_to_apex pointing to /apex path + * param out_name pointing to native_bridge path * return true if translation is needed */ -bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_apex) { +bool translateSystemPathToApexPath(const char* name, std::string* out_name) { static constexpr const char* kPathTranslation[][2] = { - SYSTEM_LIB("libEGL.so"), - SYSTEM_LIB("libGLESv1_CM.so"), - SYSTEM_LIB("libGLESv2.so"), - SYSTEM_LIB("libGLESv3.so"), - SYSTEM_LIB("libOpenMAXAL.so"), - SYSTEM_LIB("libOpenSLES.so"), - SYSTEM_LIB("libRS.so"), - SYSTEM_LIB("libaaudio.so"), - SYSTEM_LIB("libamidi.so"), - SYSTEM_LIB("libandroid.so"), - SYSTEM_LIB("libbinder_ndk.so"), - SYSTEM_LIB("libc.so"), - SYSTEM_LIB("libcamera2ndk.so"), - SYSTEM_LIB("libdl.so"), - SYSTEM_LIB("libjnigraphics.so"), - SYSTEM_LIB("liblog.so"), - SYSTEM_LIB("libm.so"), - SYSTEM_LIB("libmediandk.so"), - SYSTEM_LIB("libnativewindow.so"), - SYSTEM_LIB("libstdc++.so"), - SYSTEM_LIB("libsync.so"), - SYSTEM_LIB("libvulkan.so"), - SYSTEM_LIB("libwebviewchromium_plat_support.so"), - SYSTEM_LIB("libz.so")}; + // Libraries accessible by system path. + SYSTEM_LIB("libEGL.so"), + SYSTEM_LIB("libGLESv1_CM.so"), + SYSTEM_LIB("libGLESv2.so"), + SYSTEM_LIB("libGLESv3.so"), + SYSTEM_LIB("libOpenMAXAL.so"), + SYSTEM_LIB("libOpenSLES.so"), + SYSTEM_LIB("libRS.so"), + SYSTEM_LIB("libaaudio.so"), + SYSTEM_LIB("libamidi.so"), + SYSTEM_LIB("libandroid.so"), + SYSTEM_LIB("libbinder_ndk.so"), + SYSTEM_LIB("libc.so"), + SYSTEM_LIB("libcamera2ndk.so"), + SYSTEM_LIB("libdl.so"), + SYSTEM_LIB("libjnigraphics.so"), + SYSTEM_LIB("liblog.so"), + SYSTEM_LIB("libm.so"), + SYSTEM_LIB("libmediandk.so"), + SYSTEM_LIB("libnativewindow.so"), + SYSTEM_LIB("libstdc++.so"), + SYSTEM_LIB("libsync.so"), + SYSTEM_LIB("libvulkan.so"), + SYSTEM_LIB("libwebviewchromium_plat_support.so"), + SYSTEM_LIB("libz.so"), + // Apex/system after R. + APEX_LIB("com.android.i18n", "libandroidicu.so"), + APEX_LIB("com.android.i18n", "libicui18n.so"), + APEX_LIB("com.android.i18n", "libicuuc.so"), + // Apex/system on R (see http://b/161958857). + APEX_LIB("com.android.art", "libicui18n.so"), + APEX_LIB("com.android.art", "libicuuc.so"), + APEX_LIB("com.android.art", "libnativehelper.so"), + // Apex/system on Q. + APEX_LIB("com.android.runtime", "libicui18n.so"), + APEX_LIB("com.android.runtime", "libicuuc.so"), + }; static constexpr const char* kPathTranslationQ[][2] = { - SYSTEM_LIB("libicui18n.so"), SYSTEM_LIB("libicuuc.so"), SYSTEM_LIB("libneuralnetworks.so")}; + // Apps targeting below Q can open apex libraries by system path. + SYSTEM_LIB("libicui18n.so"), + SYSTEM_LIB("libicuuc.so"), + SYSTEM_LIB("libneuralnetworks.so"), + }; - // Libraries from greylist. Only convert these for apps targeting N or below. - static constexpr const char* kPathTranslationN[][2] = {SYSTEM_LIB("libandroid_runtime.so"), - SYSTEM_LIB("libbinder.so"), - SYSTEM_LIB("libcrypto.so"), - SYSTEM_LIB("libcutils.so"), - SYSTEM_LIB("libexpat.so"), - SYSTEM_LIB("libgui.so"), - SYSTEM_LIB("libmedia.so"), - SYSTEM_LIB("libnativehelper.so"), - SYSTEM_LIB("libssl.so"), - SYSTEM_LIB("libstagefright.so"), - SYSTEM_LIB("libsqlite.so"), - SYSTEM_LIB("libui.so"), - SYSTEM_LIB("libutils.so"), - SYSTEM_LIB("libvorbisidec.so")}; + static constexpr const char* kPathTranslationN[][2] = { + // Apps targeting below N can open greylisted libraries. + SYSTEM_LIB("libandroid_runtime.so"), + SYSTEM_LIB("libbinder.so"), + SYSTEM_LIB("libcrypto.so"), + SYSTEM_LIB("libcutils.so"), + SYSTEM_LIB("libexpat.so"), + SYSTEM_LIB("libgui.so"), + SYSTEM_LIB("libmedia.so"), + SYSTEM_LIB("libnativehelper.so"), + SYSTEM_LIB("libssl.so"), + SYSTEM_LIB("libstagefright.so"), + SYSTEM_LIB("libsqlite.so"), + SYSTEM_LIB("libui.so"), + SYSTEM_LIB("libutils.so"), + SYSTEM_LIB("libvorbisidec.so"), + }; if (name == nullptr) { return false; @@ -93,7 +134,7 @@ bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_ap if (auto it = std::find_if(std::begin(kPathTranslation), std::end(kPathTranslation), comparator); it != std::end(kPathTranslation)) { - *out_name_to_apex = (*it)[1]; + *out_name = (*it)[1]; return true; } @@ -101,7 +142,7 @@ bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_ap if (auto it = std::find_if(std::begin(kPathTranslationQ), std::end(kPathTranslationQ), comparator); it != std::end(kPathTranslationQ)) { - *out_name_to_apex = (*it)[1]; + *out_name = (*it)[1]; return true; } } @@ -110,11 +151,10 @@ bool translateSystemPathToApexPath(const char* name, std::string* out_name_to_ap if (auto it = std::find_if(std::begin(kPathTranslationN), std::end(kPathTranslationN), comparator); it != std::end(kPathTranslationN)) { - *out_name_to_apex = (*it)[1]; + *out_name = (*it)[1]; return true; } } return false; } -// End Workaround for dlopen(/system/lib/<soname>) when .so is in /apex. diff --git a/native_bridge_support.mk b/native_bridge_support.mk index 66133a3..b56361f 100644 --- a/native_bridge_support.mk +++ b/native_bridge_support.mk @@ -63,16 +63,14 @@ NATIVE_BRIDGE_ORIG_GUEST_LIBS := \ NATIVE_BRIDGE_ORIG_GUEST_LIBS += \ libandroidicu.bootstrap -# TODO(b/137072946): enable to build renderscript! -# -#NATIVE_BRIDGE_PRODUCT_PACKAGES += \ -# libclcore.bc \ -# libclcore_neon.bc -# -#NATIVE_BRIDGE_ORIG_GUEST_LIBS += \ -# libRS \ -# libRSDriver \ -# libRSSupport \ +NATIVE_BRIDGE_PRODUCT_PACKAGES += \ + libclcore.bc \ + libclcore_neon.bc + +NATIVE_BRIDGE_ORIG_GUEST_LIBS += \ + libRS \ + libRSDriver \ + libnative_bridge_guest_libRSSupport # These native libraries are needed to pass CtsJniTestCases, we do not use them in any way and # once/if build system allows us to build dummy arm libraries they can be replaced with empty ones. @@ -80,7 +78,7 @@ NATIVE_BRIDGE_ORIG_GUEST_LIBS += \ # libart \ # libvorbisidec - +# These libraries need special support on the native bridge implementation side. NATIVE_BRIDGE_MODIFIED_GUEST_LIBS := \ libaaudio \ libamidi \ |