diff --git a/libnativeloader/library_namespaces.cpp b/libnativeloader/library_namespaces.cpp index f7f972ffc..c22ce8abf 100644 --- a/libnativeloader/library_namespaces.cpp +++ b/libnativeloader/library_namespaces.cpp @@ -43,6 +43,7 @@ namespace { constexpr const char* kVendorNamespaceName = "sphal"; constexpr const char* kVndkNamespaceName = "vndk"; constexpr const char* kRuntimeNamespaceName = "runtime"; +constexpr const char* kNeuralNetworksNamespaceName = "neuralnetworks"; // classloader-namespace is a linker namespace that is created for the loaded // app. To be specific, it is created for the app classloader. When @@ -238,6 +239,14 @@ NativeLoaderNamespace* LibraryNamespaces::Create(JNIEnv* env, uint32_t target_sd } } + // Give access to NNAPI libraries (apex-updated LLNDK library). + auto nnapi_ns = + NativeLoaderNamespace::GetExportedNamespace(kNeuralNetworksNamespaceName, is_bridged); + if (!app_ns.Link(nnapi_ns, neuralnetworks_public_libraries())) { + *error_msg = app_ns.GetError(); + return nullptr; + } + // Give access to VNDK-SP libraries from the 'vndk' namespace. if (unbundled_vendor_or_product_app && !vndksp_libraries().empty()) { auto vndk_ns = NativeLoaderNamespace::GetExportedNamespace(kVndkNamespaceName, is_bridged); diff --git a/libnativeloader/public_libraries.cpp b/libnativeloader/public_libraries.cpp index c205eb133..10e23fdf1 100644 --- a/libnativeloader/public_libraries.cpp +++ b/libnativeloader/public_libraries.cpp @@ -51,6 +51,8 @@ const std::vector kRuntimePublicLibraries = { constexpr const char* kRuntimeApexLibPath = "/apex/com.android.runtime/" LIB; +constexpr const char* kNeuralNetworksApexPublicLibrary = "libneuralnetworks.so"; + // TODO(b/130388701): do we need this? std::string root_dir() { static const char* android_root_env = getenv("ANDROID_ROOT"); @@ -219,6 +221,12 @@ static std::string InitDefaultPublicLibraries() { sonames.erase(it); } } + + // Remove the public libs in the nnapi namespace. + auto it = std::find(sonames.begin(), sonames.end(), kNeuralNetworksApexPublicLibrary); + if (it != sonames.end()) { + sonames.erase(it); + } return android::base::Join(sonames, ':'); } @@ -267,6 +275,10 @@ static std::string InitVndkspLibraries() { return android::base::Join(sonames, ':'); } +static std::string InitNeuralNetworksPublicLibraries() { + return kNeuralNetworksApexPublicLibrary; +} + } // namespace const std::string& default_public_libraries() { @@ -289,6 +301,11 @@ const std::string& extended_public_libraries() { return list; } +const std::string& neuralnetworks_public_libraries() { + static std::string list = InitNeuralNetworksPublicLibraries(); + return list; +} + const std::string& llndk_libraries() { static std::string list = InitLlndkLibraries(); return list; diff --git a/libnativeloader/public_libraries.h b/libnativeloader/public_libraries.h index 9b6dea88a..9bb3366da 100644 --- a/libnativeloader/public_libraries.h +++ b/libnativeloader/public_libraries.h @@ -26,6 +26,7 @@ const std::string& default_public_libraries(); const std::string& runtime_public_libraries(); const std::string& vendor_public_libraries(); const std::string& extended_public_libraries(); +const std::string& neuralnetworks_public_libraries(); const std::string& llndk_libraries(); const std::string& vndksp_libraries(); diff --git a/rootdir/etc/ld.config.legacy.txt b/rootdir/etc/ld.config.legacy.txt index ad1449389..f0b1fd292 100644 --- a/rootdir/etc/ld.config.legacy.txt +++ b/rootdir/etc/ld.config.legacy.txt @@ -42,7 +42,7 @@ namespace.default.asan.search.paths += /odm/${LIB} # APEX related namespaces. ############################################################################### -additional.namespaces = runtime,conscrypt,media,resolv +additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv # Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt. # If a shared library or an executable requests a shared library that @@ -51,8 +51,8 @@ additional.namespaces = runtime,conscrypt,media,resolv # shared library cannot be loaded from the runtime namespace either, the # dynamic linker tries to load the shared library from the resolv namespace. # Finally, if all attempts fail, the dynamic linker returns an error. -namespace.default.links = runtime,resolv -namespace.default.asan.links = runtime,resolv +namespace.default.links = runtime,resolv,neuralnetworks +namespace.default.asan.links = runtime,resolv,neuralnetworks namespace.default.link.runtime.shared_libs = libandroidicu.so namespace.default.link.runtime.shared_libs += libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so @@ -71,6 +71,9 @@ namespace.default.link.runtime.shared_libs += libpac.so # to be loaded in the default namespace. namespace.default.link.resolv.shared_libs = libnetd_resolv.so +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -158,6 +161,27 @@ namespace.resolv.link.default.shared_libs += libbinder_ndk.so namespace.resolv.link.default.shared_libs += liblog.so namespace.resolv.link.default.shared_libs += libvndksupport.so +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so + + ############################################################################### # Namespace config for binaries under /postinstall. # Only one default namespace is defined and it has no directories other than diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt index 66e8dadca..11f75cf78 100644 --- a/rootdir/etc/ld.config.txt +++ b/rootdir/etc/ld.config.txt @@ -35,7 +35,7 @@ dir.postinstall = /postinstall dir.system = /data [system] -additional.namespaces = runtime,conscrypt,media,resolv,sphal,vndk,rs +additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv,sphal,vndk,rs ############################################################################### # "default" namespace @@ -132,7 +132,7 @@ namespace.default.asan.permitted.paths += /system/${LIB}/bootstrap # shared library cannot be loaded from the runtime namespace either, the # dynamic linker tries to load the shared library from the resolv namespace. # Finally, if all attempts fail, the dynamic linker returns an error. -namespace.default.links = runtime,resolv +namespace.default.links = runtime,resolv,neuralnetworks namespace.default.link.runtime.shared_libs = libandroidicu.so namespace.default.link.runtime.shared_libs += libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so @@ -152,6 +152,9 @@ namespace.default.link.runtime.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% # to be loaded in the default namespace. namespace.default.link.resolv.shared_libs = libnetd_resolv.so +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -186,13 +189,16 @@ namespace.media.asan.search.paths = /apex/com.android.media/${LIB} namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors namespace.media.asan.permitted.paths = /apex/com.android.media/${LIB}/extractors -namespace.media.links = default +namespace.media.links = default,neuralnetworks namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.media.link.default.shared_libs += libbinder_ndk.so namespace.media.link.default.shared_libs += libcgrouprc.so namespace.media.link.default.shared_libs += libmediametrics.so namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% +# LLNDK library moved into apex +namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "conscrypt" APEX namespace # @@ -270,7 +276,7 @@ namespace.sphal.asan.permitted.paths += /vendor/${LIB} # libs listed here can be used. Order is important here as the namespaces are # tried in this order. rs should be before vndk because both are capable # of loading libRS_internal.so -namespace.sphal.links = rs,default,vndk +namespace.sphal.links = rs,default,vndk,neuralnetworks # Renderscript gets separate namespace namespace.sphal.link.rs.shared_libs = libRS_internal.so @@ -280,6 +286,10 @@ namespace.sphal.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% namespace.sphal.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES% +# LLNDK library moved into apex +namespace.sphal.link.neuralnetworks.shared_libs = libneuralnetworks.so + + ############################################################################### # "rs" namespace # @@ -319,7 +329,7 @@ namespace.rs.asan.permitted.paths += /data/asan/vendor/${LIB} namespace.rs.asan.permitted.paths += /vendor/${LIB} namespace.rs.asan.permitted.paths += /data -namespace.rs.links = default,vndk +namespace.rs.links = default,vndk,neuralnetworks namespace.rs.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.rs.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% @@ -329,6 +339,10 @@ namespace.rs.link.default.shared_libs += %PRIVATE_LLNDK_LIBRARIES% namespace.rs.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES% +# LLNDK library moved into apex +namespace.rs.link.neuralnetworks.shared_libs = libneuralnetworks.so + + ############################################################################### # "vndk" namespace # @@ -374,7 +388,7 @@ namespace.vndk.asan.permitted.paths += /system/${LIB}/vndk-sp%VNDK_VER # The "vndk" namespace links to "default" namespace for LLNDK libs and links to # "sphal" namespace for vendor libs. The ordering matters. The "default" # namespace has higher priority than the "sphal" namespace. -namespace.vndk.links = default,sphal,runtime +namespace.vndk.links = default,sphal,runtime,neuralnetworks # When these NDK libs are required inside this namespace, then it is redirected # to the default namespace. This is possible since their ABI is stable across @@ -387,6 +401,28 @@ namespace.vndk.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES% # Allow VNDK-SP extensions to use vendor libraries namespace.vndk.link.sphal.allow_all_shared_libs = true +# LLNDK library moved into apex +namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so + +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so ############################################################################### # Namespace config for vendor processes. In O, no restriction is enforced for @@ -395,7 +431,7 @@ namespace.vndk.link.sphal.allow_all_shared_libs = true # (LL-NDK only) access. ############################################################################### [vendor] -additional.namespaces = runtime,system,vndk%VNDK_IN_SYSTEM_NS% +additional.namespaces = runtime,system,neuralnetworks,vndk%VNDK_IN_SYSTEM_NS% ############################################################################### # "default" namespace @@ -436,7 +472,7 @@ namespace.default.asan.permitted.paths += /odm namespace.default.asan.permitted.paths += /data/asan/vendor namespace.default.asan.permitted.paths += /vendor -namespace.default.links = system,vndk%VNDK_IN_SYSTEM_NS%,runtime +namespace.default.links = system,vndk%VNDK_IN_SYSTEM_NS%,runtime,neuralnetworks namespace.default.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES% namespace.default.link.system.shared_libs = %LLNDK_LIBRARIES% namespace.default.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% @@ -444,6 +480,9 @@ namespace.default.link.vndk_in_system.shared_libs = %VNDK_USING_CORE_VARIANT_LIB namespace.default.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES% namespace.default.link.vndk.shared_libs += %VNDK_CORE_LIBRARIES% +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -459,6 +498,7 @@ namespace.runtime.links = system # classloader-namespace for oat files, and tighten this up. namespace.runtime.link.system.allow_all_shared_libs = true + ############################################################################### # "vndk" namespace # @@ -492,7 +532,7 @@ namespace.vndk.asan.search.paths += /system/${LIB}/vndk%VNDK_VER% # Android releases. The links here should be identical to that of the # 'vndk_in_system' namespace, except for the link between 'vndk' and # 'vndk_in_system'. -namespace.vndk.links = system,default%VNDK_IN_SYSTEM_NS%,runtime +namespace.vndk.links = system,default%VNDK_IN_SYSTEM_NS%,runtime,neuralnetworks namespace.vndk.link.system.shared_libs = %LLNDK_LIBRARIES% namespace.vndk.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% @@ -503,6 +543,9 @@ namespace.vndk.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES% namespace.vndk.link.vndk_in_system.shared_libs = %VNDK_USING_CORE_VARIANT_LIBRARIES% +# LLNDK library moved into apex +namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "system" namespace # @@ -572,14 +615,34 @@ namespace.vndk_in_system.whitelisted = %VNDK_USING_CORE_VARIANT_LIBRARIES% # 1. 'vndk_in_system' needs to be freely linked back to 'vndk'. # 2. 'vndk_in_system' does not need to link to 'default', as any library that # requires anything vendor would not be a vndk_in_system library. -namespace.vndk_in_system.links = vndk,system,runtime +namespace.vndk_in_system.links = vndk,system,runtime,neuralnetworks namespace.vndk_in_system.link.runtime.shared_libs = %SANITIZER_RUNTIME_LIBRARIES% namespace.vndk_in_system.link.system.shared_libs = %LLNDK_LIBRARIES% namespace.vndk_in_system.link.system.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% namespace.vndk_in_system.link.vndk.allow_all_shared_libs = true +namespace.vndk_in_system.link.neuralnetworks.shared_libs = libneuralnetworks.so +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so ############################################################################### # Namespace config for native tests that need access to both system and vendor @@ -588,7 +651,7 @@ namespace.vndk_in_system.link.vndk.allow_all_shared_libs = true # includes the requisite namespace setup for APEXes. ############################################################################### [unrestricted] -additional.namespaces = runtime,media,conscrypt,resolv +additional.namespaces = runtime,media,conscrypt,resolv,neuralnetworks # Visible to allow links to be created at runtime, e.g. through # android_link_namespaces in libnativeloader. @@ -606,7 +669,7 @@ namespace.default.asan.search.paths += /data/asan/vendor/${LIB} namespace.default.asan.search.paths += /vendor/${LIB} # Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt. -namespace.default.links = runtime,resolv +namespace.default.links = runtime,resolv,neuralnetworks namespace.default.link.runtime.shared_libs = libandroidicu.so namespace.default.link.runtime.shared_libs += libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so @@ -622,6 +685,7 @@ namespace.default.link.runtime.shared_libs += libpac.so namespace.default.link.runtime.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% namespace.default.link.resolv.shared_libs = libnetd_resolv.so +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so ############################################################################### # "runtime" APEX namespace @@ -655,12 +719,16 @@ namespace.media.asan.search.paths = /apex/com.android.media/${LIB} namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors namespace.media.asan.permitted.paths = /apex/com.android.media/${LIB}/extractors -namespace.media.links = default +namespace.media.links = default,neuralnetworks namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.media.link.default.shared_libs += libbinder_ndk.so namespace.media.link.default.shared_libs += libmediametrics.so namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% +# LLNDK library moved into apex +namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so + + ############################################################################### # "conscrypt" APEX namespace # @@ -696,6 +764,25 @@ namespace.resolv.link.default.shared_libs += libdl.so namespace.resolv.link.default.shared_libs += libbinder_ndk.so namespace.resolv.link.default.shared_libs += liblog.so +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so ############################################################################### # Namespace config for binaries under /postinstall. diff --git a/rootdir/etc/ld.config.vndk_lite.txt b/rootdir/etc/ld.config.vndk_lite.txt index 69535a91c..0bb60ab99 100644 --- a/rootdir/etc/ld.config.vndk_lite.txt +++ b/rootdir/etc/ld.config.vndk_lite.txt @@ -35,7 +35,7 @@ dir.postinstall = /postinstall dir.system = /data [system] -additional.namespaces = runtime,conscrypt,media,resolv,sphal,vndk,rs +additional.namespaces = runtime,conscrypt,media,neuralnetworks,resolv,sphal,vndk,rs ############################################################################### # "default" namespace @@ -72,7 +72,7 @@ namespace.default.asan.search.paths += /vendor/${LIB} # shared library cannot be loaded from the runtime namespace either, the # dynamic linker tries to load the shared library from the resolv namespace. # Finally, if all attempts fail, the dynamic linker returns an error. -namespace.default.links = runtime,resolv +namespace.default.links = runtime,resolv,neuralnetworks namespace.default.link.runtime.shared_libs = libandroidicu.so namespace.default.link.runtime.shared_libs += libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so @@ -91,6 +91,9 @@ namespace.default.link.runtime.shared_libs += libpac.so # to be loaded in the default namespace. namespace.default.link.resolv.shared_libs = libnetd_resolv.so +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -124,12 +127,15 @@ namespace.media.asan.search.paths = /apex/com.android.media/${LIB} namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors -namespace.media.links = default +namespace.media.links = default,neuralnetworks namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.media.link.default.shared_libs += libbinder_ndk.so namespace.media.link.default.shared_libs += libmediametrics.so namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% +# LLNDK library moved into apex +namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "conscrypt" APEX namespace # @@ -207,7 +213,7 @@ namespace.sphal.asan.permitted.paths += /vendor/${LIB} # libs listed here can be used. Order is important here as the namespaces are # tried in this order. rs should be before vndk because both are capable # of loading libRS_internal.so -namespace.sphal.links = rs,default,vndk +namespace.sphal.links = rs,default,vndk,neuralnetworks # Renderscript gets separate namespace namespace.sphal.link.rs.shared_libs = libRS_internal.so @@ -217,6 +223,9 @@ namespace.sphal.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% namespace.sphal.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES% +# LLNDK library moved into apex +namespace.sphal.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "rs" namespace # @@ -256,7 +265,7 @@ namespace.rs.asan.permitted.paths += /data/asan/vendor/${LIB} namespace.rs.asan.permitted.paths += /vendor/${LIB} namespace.rs.asan.permitted.paths += /data -namespace.rs.links = default,vndk +namespace.rs.links = default,vndk,neuralnetworks namespace.rs.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.rs.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% @@ -266,6 +275,9 @@ namespace.rs.link.default.shared_libs += %PRIVATE_LLNDK_LIBRARIES% namespace.rs.link.vndk.shared_libs = %VNDK_SAMEPROCESS_LIBRARIES% +# LLNDK library moved into apex +namespace.rs.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "vndk" namespace # @@ -310,10 +322,31 @@ namespace.vndk.asan.permitted.paths += /system/${LIB}/vndk-sp%VNDK_VER # When these NDK libs are required inside this namespace, then it is redirected # to the default namespace. This is possible since their ABI is stable across # Android releases. -namespace.vndk.links = default +namespace.vndk.links = default,neuralnetworks namespace.vndk.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.vndk.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% +namespace.vndk.link.neuralnetworks.shared_libs = libneuralnetworks.so + +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so ############################################################################### @@ -323,7 +356,7 @@ namespace.vndk.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% # (LL-NDK only) access. ############################################################################### [vendor] -additional.namespaces = runtime +additional.namespaces = runtime,neuralnetworks namespace.default.isolated = false @@ -365,7 +398,7 @@ namespace.default.asan.search.paths += /%PRODUCT%/${LIB} namespace.default.asan.search.paths += /data/asan/system/${LIB}/vndk%VNDK_VER% namespace.default.asan.search.paths += /system/${LIB}/vndk%VNDK_VER% -namespace.default.links = runtime +namespace.default.links = runtime,neuralnetworks namespace.default.link.runtime.shared_libs = libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so # TODO(b/120786417 or b/134659294): libicuuc.so and libicui18n.so are kept for app compat. @@ -377,6 +410,9 @@ namespace.default.link.runtime.shared_libs += libnativeloader.so # Workaround for b/124772622 namespace.default.link.runtime.shared_libs += libandroidicu.so +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -392,6 +428,27 @@ namespace.runtime.links = default # classloader-namespace for oat files, and tighten this up. namespace.runtime.link.default.allow_all_shared_libs = true +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so + + ############################################################################### # Namespace config for native tests that need access to both system and vendor # libraries. This replicates the default linker config (done by @@ -399,7 +456,7 @@ namespace.runtime.link.default.allow_all_shared_libs = true # includes the requisite namespace setup for APEXes. ############################################################################### [unrestricted] -additional.namespaces = runtime,media,conscrypt,resolv +additional.namespaces = runtime,media,conscrypt,resolv,neuralnetworks # Visible to allow links to be created at runtime, e.g. through # android_link_namespaces in libnativeloader. @@ -417,7 +474,7 @@ namespace.default.asan.search.paths += /data/asan/vendor/${LIB} namespace.default.asan.search.paths += /vendor/${LIB} # Keep in sync with the "platform" namespace in art/build/apex/ld.config.txt. -namespace.default.links = runtime,resolv +namespace.default.links = runtime,resolv,neuralnetworks namespace.default.link.runtime.shared_libs = libandroidicu.so namespace.default.link.runtime.shared_libs += libdexfile_external.so namespace.default.link.runtime.shared_libs += libdexfiled_external.so @@ -434,6 +491,9 @@ namespace.default.link.runtime.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% namespace.default.link.resolv.shared_libs = libnetd_resolv.so +# LLNDK library moved into apex +namespace.default.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "runtime" APEX namespace # @@ -450,7 +510,6 @@ namespace.runtime.asan.search.paths = /apex/com.android.runtime/${LIB} namespace.runtime.links = default # TODO(b/130340935): Use a dynamically created linker namespace similar to # classloader-namespace for oat files, and tighten this up. -namespace.runtime.link.default.allow_all_shared_libs = true ############################################################################### # "media" APEX namespace @@ -465,12 +524,15 @@ namespace.media.asan.search.paths = /apex/com.android.media/${LIB} namespace.media.permitted.paths = /apex/com.android.media/${LIB}/extractors -namespace.media.links = default +namespace.media.links = default,neuralnetworks namespace.media.link.default.shared_libs = %LLNDK_LIBRARIES% namespace.media.link.default.shared_libs += libbinder_ndk.so namespace.media.link.default.shared_libs += libmediametrics.so namespace.media.link.default.shared_libs += %SANITIZER_RUNTIME_LIBRARIES% +# LLNDK library moved into apex +namespace.media.link.neuralnetworks.shared_libs = libneuralnetworks.so + ############################################################################### # "conscrypt" APEX namespace # @@ -505,6 +567,27 @@ namespace.resolv.link.default.shared_libs += libm.so namespace.resolv.link.default.shared_libs += libdl.so namespace.resolv.link.default.shared_libs += libbinder_ndk.so +############################################################################### +# "neuralnetworks" APEX namespace +# +# This namespace is for libraries within the NNAPI APEX. +############################################################################### +namespace.neuralnetworks.isolated = true +namespace.neuralnetworks.visible = true + +namespace.neuralnetworks.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.asan.search.paths = /apex/com.android.neuralnetworks/${LIB} +namespace.neuralnetworks.links = default +namespace.neuralnetworks.link.default.shared_libs = libc.so +namespace.neuralnetworks.link.default.shared_libs += libcgrouprc.so +namespace.neuralnetworks.link.default.shared_libs += libdl.so +namespace.neuralnetworks.link.default.shared_libs += liblog.so +namespace.neuralnetworks.link.default.shared_libs += libm.so +namespace.neuralnetworks.link.default.shared_libs += libnativewindow.so +namespace.neuralnetworks.link.default.shared_libs += libsync.so +namespace.neuralnetworks.link.default.shared_libs += libvndksupport.so + + ############################################################################### # Namespace config for binaries under /postinstall. # Only default namespace is defined and default has no directories diff --git a/rootdir/update_and_install_ld_config.mk b/rootdir/update_and_install_ld_config.mk index ee29afcc4..dbe60e54b 100644 --- a/rootdir/update_and_install_ld_config.mk +++ b/rootdir/update_and_install_ld_config.mk @@ -40,6 +40,7 @@ llndk_libraries_file := $(library_lists_dir)/llndk.libraries.$(vndk_version).txt vndksp_libraries_file := $(library_lists_dir)/vndksp.libraries.$(vndk_version).txt vndkcore_libraries_file := $(library_lists_dir)/vndkcore.libraries.txt vndkprivate_libraries_file := $(library_lists_dir)/vndkprivate.libraries.txt +llndk_moved_to_apex_libraries_file := $(library_lists_dir)/llndkinapex.libraries.txt ifeq ($(my_vndk_use_core_variant),true) vndk_using_core_variant_libraries_file := $(library_lists_dir)/vndk_using_core_variant.libraries.$(vndk_version).txt endif @@ -65,6 +66,10 @@ else vndksp_libraries_list := $(VNDK_SAMEPROCESS_LIBRARIES) endif +# LLNDK libraries that has been moved to an apex package and no longer are present on +# /system image. +llndk_libraries_moved_to_apex_list:=$(LLNDK_MOVED_TO_APEX_LIBRARIES) + # $(1): list of libraries # $(2): output file to write the list of libraries to define write-libs-to-file @@ -91,6 +96,14 @@ $(LOCAL_BUILT_MODULE): private-filter-out-private-libs = \ while read -r privatelib; do sed -i.bak "s/$$privatelib//" $(2) ; done < $(PRIVATE_VNDK_PRIVATE_LIBRARIES_FILE) && \ sed -i.bak -e 's/::\+/:/g ; s/^:\+// ; s/:\+$$//' $(2) && \ rm -f $(2).bak + +# # Given a file with a list of libs in "a:b:c" format, filter-out the LLNDK libraries migrated into apex file +# # and write resulting list to a new file in "a:b:c" format + $(LOCAL_BUILT_MODULE): private-filter-out-llndk-in-apex-libs = \ + for lib in $(PRIVATE_LLNDK_LIBRARIES_MOVED_TO_APEX_LIST); do sed -i.bak s/$$lib.so// $(1); done && \ + sed -i.bak -e 's/::\+/:/g ; s/^:\+// ; s/:\+$$//' $(1) && \ + rm -f $(1).bak + $(LOCAL_BUILT_MODULE): PRIVATE_LLNDK_LIBRARIES_FILE := $(llndk_libraries_file) $(LOCAL_BUILT_MODULE): PRIVATE_VNDK_SP_LIBRARIES_FILE := $(vndksp_libraries_file) $(LOCAL_BUILT_MODULE): PRIVATE_VNDK_CORE_LIBRARIES_FILE := $(vndkcore_libraries_file) @@ -100,6 +113,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_VNDK_VERSION_SUFFIX := $(vndk_version_suffix) $(LOCAL_BUILT_MODULE): PRIVATE_INTERMEDIATES_DIR := $(intermediates_dir) $(LOCAL_BUILT_MODULE): PRIVATE_COMP_CHECK_SCRIPT := $(compatibility_check_script) $(LOCAL_BUILT_MODULE): PRIVATE_VNDK_VERSION_TAG := \#VNDK$(vndk_version)\# +$(LOCAL_BUILT_MODULE): PRIVATE_LLNDK_LIBRARIES_MOVED_TO_APEX_LIST := $(llndk_libraries_moved_to_apex_list) deps := $(llndk_libraries_file) $(vndksp_libraries_file) $(vndkcore_libraries_file) \ $(vndkprivate_libraries_file) ifeq ($(check_backward_compatibility),true) @@ -118,6 +132,7 @@ ifeq ($(check_backward_compatibility),true) endif @mkdir -p $(dir $@) $(call private-filter-out-private-libs,$(PRIVATE_LLNDK_LIBRARIES_FILE),$(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered) + $(call private-filter-out-llndk-in-apex-libs,$(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered) $(hide) sed -e "s?%LLNDK_LIBRARIES%?$$(cat $(PRIVATE_INTERMEDIATES_DIR)/llndk_filtered)?g" $< >$@ $(call private-filter-out-private-libs,$(PRIVATE_VNDK_SP_LIBRARIES_FILE),$(PRIVATE_INTERMEDIATES_DIR)/vndksp_filtered) $(hide) sed -i.bak -e "s?%VNDK_SAMEPROCESS_LIBRARIES%?$$(cat $(PRIVATE_INTERMEDIATES_DIR)/vndksp_filtered)?g" $@ @@ -162,6 +177,7 @@ compatibility_check_script := intermediates_dir := library_lists_dir := llndk_libraries_file := +llndk_moved_to_apex_libraries_file := vndksp_libraries_file := vndkcore_libraries_file := vndkprivate_libraries_file :=