summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2025-01-21 15:07:40 +0000
committer Martin Stjernholm <mast@google.com> 2025-01-28 00:46:55 -0800
commit162e2634caca054659a829df1040ee052b900c34 (patch)
tree864878bda454be5069a1f417597bf8ccfde2a43b
parentdaacc31423f8bcece99953d23661f0bffc91011f (diff)
Allow ART internal libs to load libs in NATIVELOADER_DEFAULT_NAMESPACE_LIBS.
This complements the treatment of NATIVELOADER_DEFAULT_NAMESPACE_LIBS, so that ART internal libs can load the libraries listed in that variable, as well as the other way around. This makes it possible to load libartagent(d).so without absolute paths in run tests on target, so use that to re-enable 900-hello-plugin. Test: art/test/testrunner/testrunner.py --target --64 900 in armv8 target chroot Test: art/test/testrunner/testrunner.py --host 900 Bug: 186654484 Change-Id: Ic418b26b2b77af8839af7b65ad44ea8b5121169c
-rw-r--r--dalvikvm/Android.bp4
-rw-r--r--dalvikvm/dalvikvm.cc40
-rw-r--r--libnativeloader/native_loader.cpp5
-rw-r--r--test/900-hello-plugin/run.py12
-rw-r--r--test/knownfailures.json6
5 files changed, 49 insertions, 18 deletions
diff --git a/dalvikvm/Android.bp b/dalvikvm/Android.bp
index 1ab408c484..026689ed6c 100644
--- a/dalvikvm/Android.bp
+++ b/dalvikvm/Android.bp
@@ -40,8 +40,12 @@ art_cc_binary {
],
target: {
android: {
+ header_libs: [
+ "libnativeloader-headers",
+ ],
shared_libs: [
"libsigchain",
+ "libdl_android",
],
},
linux: {
diff --git a/dalvikvm/dalvikvm.cc b/dalvikvm/dalvikvm.cc
index 27709fda4a..ebdcef1775 100644
--- a/dalvikvm/dalvikvm.cc
+++ b/dalvikvm/dalvikvm.cc
@@ -14,10 +14,12 @@
* limitations under the License.
*/
+#include <dlfcn.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
#include <algorithm>
#include <memory>
@@ -27,8 +29,42 @@
#include "nativehelper/ScopedLocalRef.h"
#include "nativehelper/toStringArray.h"
+#ifdef ART_TARGET_ANDROID
+#include "nativeloader/dlext_namespaces.h"
+#endif
+
namespace art {
+// This complements the treatment of NATIVELOADER_DEFAULT_NAMESPACE_LIBS in
+// art/libnativeloader/native_loader.cpp: The libraries listed in that variable
+// are added to the default namespace, which for dalvikvm runs means they can
+// access all internal libs in com_android_art. However, to allow the opposite
+// direction we need links for them from com_android_art back to default, and
+// that's done here. See comments in native_loader.cpp for full discussion.
+static bool initNativeloaderExtraLibsLinks() {
+#ifdef ART_TARGET_ANDROID
+ const char* links = getenv("NATIVELOADER_DEFAULT_NAMESPACE_LIBS");
+ if (links == nullptr || *links == 0) {
+ return true;
+ }
+ struct android_namespace_t* art_ns = android_get_exported_namespace("com_android_art");
+ if (art_ns == nullptr) {
+ fprintf(stderr,
+ "Warning: com_android_art namespace not found - "
+ "NATIVELOADER_DEFAULT_NAMESPACE_LIBS ignored\n");
+ return true;
+ }
+ if (!android_link_namespaces(art_ns, nullptr, links)) {
+ fprintf(stderr,
+ "Error adding linker namespace links from com_android_art to default for %s: %s",
+ links,
+ dlerror());
+ return false;
+ }
+#endif // ART_TARGET_ANDROID
+ return true;
+}
+
// Determine whether or not the specified method is public.
static bool IsMethodPublic(JNIEnv* env, jclass c, jmethodID method_id) {
ScopedLocalRef<jobject> reflected(env, env->ToReflectedMethod(c, method_id, JNI_FALSE));
@@ -148,6 +184,10 @@ static int dalvikvm(int argc, char** argv) {
}
}
+ if (!initNativeloaderExtraLibsLinks()) {
+ return EXIT_FAILURE;
+ }
+
if (need_extra) {
fprintf(stderr, "%s must be followed by an additional argument giving a value\n", what);
return EXIT_FAILURE;
diff --git a/libnativeloader/native_loader.cpp b/libnativeloader/native_loader.cpp
index f37f661a3e..964279446f 100644
--- a/libnativeloader/native_loader.cpp
+++ b/libnativeloader/native_loader.cpp
@@ -70,6 +70,11 @@ using ::android::nativeloader::LibraryNamespaces;
// the APEX. In that case the default namespace links to the ART namespace
// (com_android_art) for all libraries, which means this can be used to load
// test libraries that depend on ART internal libraries.
+//
+// There's also code in art/dalvikvm.cc to add links from com_android_art back
+// to the default namespace for NATIVELOADER_DEFAULT_NAMESPACE_LIBS, enabling
+// access in the opposite direction as well. Useful e.g. to load ART plugins in
+// NATIVELOADER_DEFAULT_NAMESPACE_LIBS.
constexpr const char* kNativeloaderExtraLibs = "nativeloader-extra-libs";
std::mutex g_namespaces_mutex;
diff --git a/test/900-hello-plugin/run.py b/test/900-hello-plugin/run.py
index 607a0e5d40..f56ee8a532 100644
--- a/test/900-hello-plugin/run.py
+++ b/test/900-hello-plugin/run.py
@@ -18,18 +18,6 @@
def run(ctx, args):
plugin = "libartagent.so" if args.O else "libartagentd.so"
- # Adjust the agent path when running on device.
- if not args.host:
- for i, opt in enumerate(args.runtime_option):
- if opt.startswith("-Djava.library.path="):
- libpath = opt.split("=")[-1]
- assert libpath.startswith("/data/nativetest"), libpath
-
- # The linker configuration used for dalvikvm(64) in the ART APEX requires us
- # to pass the full path to the agent to the runtime when running on device.
- plugin = f"{libpath}/{plugin}"
- break
-
ctx.default_run(
args,
runtime_option=[
diff --git a/test/knownfailures.json b/test/knownfailures.json
index 33a4548d7a..8905bb5595 100644
--- a/test/knownfailures.json
+++ b/test/knownfailures.json
@@ -1441,12 +1441,6 @@
"description": ["Uses the low-ram flag which does not work with CMS"]
},
{
- "tests": ["900-hello-plugin"],
- "variant": "target",
- "bug": "b/186654484",
- "description": ["Disabled after the switch to avoid allow_all_shared_libs from the ART namespace to system."]
- },
- {
"tests": ["2001-virtual-structural-multithread"],
"env_vars": {"SANITIZE_HOST": "address"},
"bug": "b/176786675",