summaryrefslogtreecommitdiff
path: root/libnativeloader/test/libsystem_testlib.cc
diff options
context:
space:
mode:
author Martin Stjernholm <mast@google.com> 2022-12-23 21:51:13 +0000
committer Treehugger Robot <treehugger-gerrit@google.com> 2023-01-07 21:11:46 +0000
commit453b9fe909c22eb0f01b3072a5213dd46aed6f45 (patch)
tree4a8ba7821d1a4eaaeeacc9cde7a103fe3a303e47 /libnativeloader/test/libsystem_testlib.cc
parentdfbed3af514c47e72fdf9efc556c751dea9487eb (diff)
Undo giving full access to system libs from other system libs.
Directly extending the search path to /system/${LIB} for system APKs may result in system libs being loaded in an app classloader namespace rather than the system namespace. If those libs then depend on other non-public libraries, e.g. in APEXes, that are only accessible through links from the system namespace, then those dependencies will fail to load because the app classloader namespace doesn't have the same links. This CL functionally undoes https://r.android.com/2211602, but only disables tests that break, and adds some tests to exercise the situation above. Also change native libs in the test to use `min_sdk_version` rather than `sdk_version`, because now when they contain code they need an NDK, and one with exactly version 31 is normally not available in the build. (Otoh, the java libraries with `product_specific: true` or `vendor: true` aren't allowed to use `min_sdk_version`.) Test: atest -a libnativeloader_test libnativeloader_lazy_test \ libnativeloader_e2e_tests Bug: 258340826 Bug: 237577392 Change-Id: I95a3fbc6c8021c037fffda1423aa90c62973ec89
Diffstat (limited to 'libnativeloader/test/libsystem_testlib.cc')
-rw-r--r--libnativeloader/test/libsystem_testlib.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/libnativeloader/test/libsystem_testlib.cc b/libnativeloader/test/libsystem_testlib.cc
new file mode 100644
index 0000000000..97d32237b4
--- /dev/null
+++ b/libnativeloader/test/libsystem_testlib.cc
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2022 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.
+ */
+
+#include <dlfcn.h>
+
+#include "log/log.h"
+
+static void __attribute__((constructor)) ctor() {
+ // Load a library that should be available to system libraries through a
+ // linked namespace (i.e. is not directly in /system/${LIB}), and that is not
+ // in public.libraries.txt. We use a real one to avoid having to set up an
+ // APEX test fixture and rerun linkerconfig.
+ void* h = dlopen("libandroidicu.so", RTLD_NOW);
+ if (h == nullptr) {
+ LOG_ALWAYS_FATAL("Failed to load dependency: %s", dlerror());
+ }
+ dlclose(h);
+}