summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ryan Prichard <rprichard@google.com> 2024-04-16 20:34:49 -0700
committer Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-04-22 11:23:04 +0000
commitd229e50a7cf690dd6183efb4dad56ccb90349a71 (patch)
tree29f828cfcb797f27f6e62b848400c753727cd8e7
parent4a79b17f374df876803e34edb60476fe33ab1671 (diff)
ART standalone tests: use static STL and version scripts
Set "stl" to "libc++_static" in art_standalone_test_defaults. By default, localize/hide all of a test binary's symbols. In particular, symbols from libc++_static.a must not be exported from the test executable, because only *some* libc++ symbols would be exported (e.g. those that are also seen in other .dynsym sections at build time), and exporting this subset of symbols can break libc++ (e.g. inconsistent facet registration, b/331873741). It is also important to hide libbase.a symbols, such as constructors/destructors for internal classes like LogMessage. Using a version script also hides vaguely-linked libc++ symbols that could come from libc++'s headers, not libc++_static.a, such as vtables and template functions. `--exclude-libs=libc++_static.a` wouldn't hide these symbols. Bug: 331873741 Bug: 333438055 Test: atest art_libnativebridge_cts_tests art_standalone_artd_tests art_standalone_cmdline_tests art_standalone_compiler_tests art_standalone_dex2oat_cts_tests art_standalone_dex2oat_tests art_standalone_dexdump_tests art_standalone_dexlist_tests art_standalone_dexopt_chroot_setup_tests art_standalone_dexoptanalyzer_tests art_standalone_dexpreopt_tests art_standalone_disassembler_tests art_standalone_libartbase_tests art_standalone_libartpalette_tests art_standalone_libartservice_tests art_standalone_libarttools_tests art_standalone_libdexfile_external_tests art_standalone_libdexfile_support_tests art_standalone_libdexfile_tests art_standalone_libprofile_tests art_standalone_oatdump_tests art_standalone_odrefresh_tests art_standalone_profman_tests art_standalone_runtime_tests art_standalone_sigchain_tests libnativeloader_lazy_test libnativeloader_test Change-Id: Ibfe8de492c76c83c76b00c7124d5a94775579d03
-rw-r--r--libnativeloader/Android.bp11
-rw-r--r--libnativeloader/libnativeloader_test.map26
-rw-r--r--test/Android.bp28
-rw-r--r--test/art-standalone-gtest-version.map32
-rw-r--r--test/art-standalone-test-version.map20
5 files changed, 106 insertions, 11 deletions
diff --git a/libnativeloader/Android.bp b/libnativeloader/Android.bp
index 3b685747aa..47b6961167 100644
--- a/libnativeloader/Android.bp
+++ b/libnativeloader/Android.bp
@@ -135,12 +135,11 @@ cc_defaults {
cflags: ["-DANDROID"],
- // The tests mock libdl_android and libnativebridge symbols, so export them
- // to override the ones loaded from their libs.
- ldflags: [
- "-Wl,--export-dynamic-symbol=android_*",
- "-Wl,--export-dynamic-symbol=NativeBridge*",
- ],
+ // Ordinarily, symbols are only exported if they are referenced by some
+ // shared object dependency. Instead, export everything using
+ // --export-dynamic, then restrict the visibility using the version script.
+ ldflags: ["-Wl,--export-dynamic"],
+ version_script: "libnativeloader_test.map",
header_libs: [
"libnativebridge-headers",
diff --git a/libnativeloader/libnativeloader_test.map b/libnativeloader/libnativeloader_test.map
new file mode 100644
index 0000000000..1f26f9ffc8
--- /dev/null
+++ b/libnativeloader/libnativeloader_test.map
@@ -0,0 +1,26 @@
+#
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{
+ global:
+ # The tests mock libdl_android and libnativebridge symbols, so export them
+ # to override the ones loaded from their libs.
+ android_*;
+ NativeBridge*;
+
+ local:
+ *;
+};
diff --git a/test/Android.bp b/test/Android.bp
index c3f781cc4c..6c91cf1a80 100644
--- a/test/Android.bp
+++ b/test/Android.bp
@@ -154,6 +154,19 @@ filegroup {
srcs: ["art-gtests-target-standalone-with-boot-image-template.xml"],
}
+// Version script for `art_standalone_test_defaults`.
+filegroup {
+ name: "art-standalone-test-version",
+ srcs: ["art-standalone-test-version.map"],
+}
+
+// Version script for `art_standalone_gtest_defaults`. In particular, it adds
+// libsigchain's libc.so interceptors.
+filegroup {
+ name: "art-standalone-gtest-version",
+ srcs: ["art-standalone-gtest-version.map"],
+}
+
// When soong builds the tests in a sandbox, the targets of symlinks
// must be declared as inputs to soong modules that use them, or else
// it will be a dangling symlink in the sandbox.
@@ -219,6 +232,15 @@ art_cc_defaults {
min_sdk_version: "31", // Same as the ART APEX.
+ // Link libc++ statically to avoid needing the system libc++.so, which may
+ // be incompatible. The linker exports symbols from an executable that are
+ // referenced in the .dynsym tables of shared object dependencies, so use a
+ // version script to restrict exports. The version script is needed for
+ // hiding symbols from libc++ (either libc++_static.a or vaguely-linked
+ // symbols in other object files) and from other libraries, such as libbase.
+ stl: "libc++_static",
+ version_script: ":art-standalone-test-version",
+
// Make standalone tests check their own NEEDED dependencies for disallowed
// libraries. Add standalone_test_lib_check and its dependencies, except
// libgtest which is expected to be added by the tests.
@@ -347,11 +369,7 @@ art_cc_defaults {
static_libs: [
"libart-gtest",
],
- // Reduce test executable size by disabling automatic export of static lib symbols.
- // Don't use --exclude-libs=ALL, because it breaks tests under ASAN by hiding __asan* symbols.
- ldflags: [
- "-Wl,--exclude-libs=libart-gtest.a",
- ],
+ version_script: ":art-standalone-gtest-version",
test_for: [
"com.android.art",
"com.android.art.debug",
diff --git a/test/art-standalone-gtest-version.map b/test/art-standalone-gtest-version.map
new file mode 100644
index 0000000000..0c66d3ff45
--- /dev/null
+++ b/test/art-standalone-gtest-version.map
@@ -0,0 +1,32 @@
+#
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{
+ global:
+ # Export libsigchain's libc.so interceptors.
+ sigaction;
+ sigaction64;
+ signal;
+ sigprocmask;
+ sigprocmask64;
+
+ # Allow jni_compiler_test to find Java_MyClassNatives_bar within itself
+ # using dlopen(NULL, ...).
+ Java_MyClassNatives_*;
+
+ local:
+ *;
+};
diff --git a/test/art-standalone-test-version.map b/test/art-standalone-test-version.map
new file mode 100644
index 0000000000..e342e43eab
--- /dev/null
+++ b/test/art-standalone-test-version.map
@@ -0,0 +1,20 @@
+#
+# Copyright (C) 2024 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+{
+ local:
+ *;
+};