1 /*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 // This namespace is where no-vendor-variant VNDK libraries are loaded for a
18 // vendor process. Note that we do not simply export these libraries from the
19 // "system" namespace, because in some cases both the core variant and the
20 // vendor variant of a VNDK library may be loaded. In such cases, we do not
21 // want to eliminate double-loading because doing so means the global states
22 // of the library would be shared.
23 //
24 // Only the no-vendor-variant VNDK libraries are whitelisted in this namespace.
25 // This is to ensure that we do not load libraries needed by no-vendor-variant
26 // VNDK libraries into vndk_in_system namespace.
27
28 #include "linkerconfig/namespacebuilder.h"
29
30 #include "linkerconfig/environment.h"
31
32 using android::linkerconfig::modules::AsanPath;
33 using android::linkerconfig::modules::IsProductVndkVersionDefined;
34 using android::linkerconfig::modules::Namespace;
35
36 namespace android {
37 namespace linkerconfig {
38 namespace contents {
BuildVndkInSystemNamespace(const Context & ctx)39 Namespace BuildVndkInSystemNamespace([[maybe_unused]] const Context& ctx) {
40 Namespace ns("vndk_in_system",
41 /*is_isolated=*/true,
42 /*is_visible=*/false);
43
44 // The search paths here should be kept the same as that of the 'system' namespace.
45 ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN);
46 ns.AddSearchPath(Var("SYSTEM_EXT") + "/${LIB}", AsanPath::WITH_DATA_ASAN);
47 if (!IsProductVndkVersionDefined()) {
48 ns.AddSearchPath(Var("PRODUCT") + "/${LIB}", AsanPath::WITH_DATA_ASAN);
49 }
50
51 if (android::linkerconfig::modules::IsVndkInSystemNamespace()) {
52 ns.AddWhitelisted(Var("VNDK_USING_CORE_VARIANT_LIBRARIES"));
53 }
54
55 // The links here should be identical to that of the 'vndk' namespace for the
56 // [vendor] section, with the following exceptions:
57 // 1. 'vndk_in_system' needs to be freely linked back to 'vndk'.
58 // 2. 'vndk_in_system' does not need to link to 'default', as any library that
59 // requires anything vendor would not be a vndk_in_system library.
60 if (ctx.IsProductSection()) {
61 ns.GetLink(ctx.GetSystemNamespaceName())
62 .AddSharedLib(Var("LLNDK_LIBRARIES_PRODUCT"));
63 } else {
64 ns.GetLink(ctx.GetSystemNamespaceName())
65 .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR"));
66 }
67 ns.GetLink("vndk").AllowAllSharedLibs();
68 ns.AddRequires(std::vector{"libneuralnetworks.so"});
69
70 return ns;
71 }
72 } // namespace contents
73 } // namespace linkerconfig
74 } // namespace android
75