diff options
author | 2025-01-20 21:37:47 +0000 | |
---|---|---|
committer | 2025-01-28 00:46:55 -0800 | |
commit | 1107d58d6fb1e4c421f9d4df44220fed3ebf6b06 (patch) | |
tree | b618cc824ba5d3c1bc49d0f6e1c519560195ea5c | |
parent | 30dfb7e6ef338b97d5f091f6a1270dada08e27e9 (diff) |
Use libarttest(d)_external to fix 674-hiddenapi, and enable it on
target again.
This requires adding an extra link from system to default linker
namespaces for NATIVELOADER_DEFAULT_NAMESPACE_LIBS, since some of the
test cases load a child class with the boot class loader, which in turn
loads libarttest(d)_external.so.
Test: art/test/testrunner/testrunner.py --target --64 674
in armv8 target chroot
Test: art/test/testrunner/testrunner.py --host 674
Bug: 186654484
Change-Id: I19a3332d99a4d8b2c7682e688cf3d965425a2eb0
-rw-r--r-- | test/674-hiddenapi/hiddenapi.cc | 30 | ||||
-rw-r--r-- | test/674-hiddenapi/run.py | 4 | ||||
-rw-r--r-- | test/674-hiddenapi/src-art/Main.java | 16 | ||||
-rw-r--r-- | test/Android.bp | 6 | ||||
-rw-r--r-- | test/knownfailures.json | 1 |
5 files changed, 52 insertions, 5 deletions
diff --git a/test/674-hiddenapi/hiddenapi.cc b/test/674-hiddenapi/hiddenapi.cc index f1b0c18c27..a851e3f425 100644 --- a/test/674-hiddenapi/hiddenapi.cc +++ b/test/674-hiddenapi/hiddenapi.cc @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <dlfcn.h> + #include "base/sdk_version.h" #include "dex/art_dex_file_loader.h" #include "hidden_api.h" @@ -21,6 +23,10 @@ #include "runtime.h" #include "ti-agent/scoped_utf_chars.h" +#ifdef ART_TARGET_ANDROID +#include "nativeloader/dlext_namespaces.h" +#endif + namespace art { namespace Test674HiddenApi { @@ -29,6 +35,30 @@ static constexpr uint64_t kPreventMetaReflectionBlocklistAccess = 142365358; std::vector<std::vector<std::unique_ptr<const DexFile>>> opened_dex_files; +// The JNI entrypoints below end up in libarttest(d).so, while the test makes +// copies of libarttest(d)_external.so and loads them instead. Those libs depend +// on libarttest(d).so, so its exported symbols become visible directly in them. +// Hence we don't need to create wrappers for the JNI methods in +// libarttest(d)_external.so. + +extern "C" JNIEXPORT void JNICALL +Java_Main_addDefaultNamespaceLibsLinkToSystemLinkerNamespace(JNIEnv*, jclass) { +#ifdef ART_TARGET_ANDROID + const char* links = getenv("NATIVELOADER_DEFAULT_NAMESPACE_LIBS"); + if (links == nullptr || *links == 0) { + LOG(FATAL) << "Expected NATIVELOADER_DEFAULT_NAMESPACE_LIBS to be set"; + } + struct android_namespace_t* system_ns = android_get_exported_namespace("system"); + if (system_ns == nullptr) { + LOG(FATAL) << "Failed to retrieve system namespace"; + } + if (!android_link_namespaces(system_ns, nullptr, links)) { + LOG(FATAL) << "Error adding linker namespace link from system to default for " << links << ": " + << dlerror(); + } +#endif +} + extern "C" JNIEXPORT void JNICALL Java_Main_init(JNIEnv*, jclass) { Runtime* runtime = Runtime::Current(); runtime->SetHiddenApiEnforcementPolicy(hiddenapi::EnforcementPolicy::kEnabled); diff --git a/test/674-hiddenapi/run.py b/test/674-hiddenapi/run.py index 1e364faf15..97b8be95c8 100644 --- a/test/674-hiddenapi/run.py +++ b/test/674-hiddenapi/run.py @@ -1,5 +1,3 @@ -#!/bin/bash -# # Copyright (C) 2019 The Android Open Source Project # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,6 +14,8 @@ def run(ctx, args): + args.testlib += [args.testlib[0] + "_external"] + # Make verification soft fail so that we can re-verify boot classpath # methods at runtime. # diff --git a/test/674-hiddenapi/src-art/Main.java b/test/674-hiddenapi/src-art/Main.java index 5a1b89b0eb..f215e592d2 100644 --- a/test/674-hiddenapi/src-art/Main.java +++ b/test/674-hiddenapi/src-art/Main.java @@ -15,6 +15,7 @@ */ import dalvik.system.PathClassLoader; + import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -31,7 +32,7 @@ public class Main { public static void main(String[] args) throws Exception { System.loadLibrary(args[0]); - prepareNativeLibFileName(args[0]); + prepareNativeLibFileName(args[1]); // Enable hidden API checks in case they are disabled by default. init(); @@ -75,6 +76,16 @@ public class Main { doTest(DexDomain.CorePlatform, DexDomain.Application, true); doUnloading(); + // The following tests use the boot class loader to load ChildClass, and + // that class loader uses the "system" namespace in the native linker + // namespace config rather than the usual "clns-XXX" namespaces created for + // class loaders by libnativeloader. Hence we need to add links to the libs + // in NATIVELOADER_DEFAULT_NAMESPACE_LIBS (in particular libarttest(d).so) + // to the "system" namespace, so that the tests below can load the copy of + // libarttest(d)_external.so (which depends on libarttest(d).so). Note that + // this cannot be undone. + addDefaultNamespaceLibsLinkToSystemLinkerNamespace(); + // Append child to boot class path, first as a platform dex file. // It should not be allowed to access non-public, non-core platform API members. int childIdx = appendToBootClassLoader(DEX_CHILD, /* isCorePlatform */ false); @@ -127,7 +138,7 @@ public class Main { addAllApisToSdk); } - // Routine which tries to figure out the absolute path of our native library. + // Routine which tries to figure out the absolute path of our native libarttest(d)_external.so. private static void prepareNativeLibFileName(String arg) throws Exception { String libName = System.mapLibraryName(arg); Method libPathsMethod = Runtime.class.getDeclaredMethod("getLibPaths"); @@ -179,6 +190,7 @@ public class Main { private static ClassLoader BOOT_CLASS_LOADER = Object.class.getClassLoader(); + private static native void addDefaultNamespaceLibsLinkToSystemLinkerNamespace(); private static native int appendToBootClassLoader(String dexPath, boolean isCorePlatform); private static native void setDexDomain(int index, boolean isCorePlatform); private static native void init(); diff --git a/test/Android.bp b/test/Android.bp index d33c9b7935..e7e37f6c7c 100644 --- a/test/Android.bp +++ b/test/Android.bp @@ -949,6 +949,12 @@ cc_defaults { "libnativehelper", "libunwindstack", ], + target: { + android: { + header_libs: ["libnativeloader-headers"], + shared_libs: ["libdl_android"], + }, + }, } art_cc_test_library { diff --git a/test/knownfailures.json b/test/knownfailures.json index d6ea226808..c8922410d2 100644 --- a/test/knownfailures.json +++ b/test/knownfailures.json @@ -1443,7 +1443,6 @@ { "tests": ["150-loadlibrary", "656-annotation-lookup-generic-jni", - "674-hiddenapi", "900-hello-plugin"], "variant": "target", "bug": "b/186654484", |