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 { 39 Namespace BuildVndkInSystemNamespace([[maybe_unused]] const Context& ctx) { 40 Namespace ns("vndk_in_system", /*is_isolated=*/true, 41 /*is_visible=*/true); 42 43 // The search paths here should be kept the same as that of the 'system' namespace. 44 ns.AddSearchPath("/system/${LIB}", AsanPath::WITH_DATA_ASAN); 45 ns.AddSearchPath(Var("SYSTEM_EXT") + "/${LIB}", AsanPath::WITH_DATA_ASAN); 46 if (!IsProductVndkVersionDefined()) { 47 ns.AddSearchPath(Var("PRODUCT") + "/${LIB}", AsanPath::WITH_DATA_ASAN); 48 } 49 50 if (android::linkerconfig::modules::IsVndkInSystemNamespace()) { 51 ns.AddWhitelisted(Var("VNDK_USING_CORE_VARIANT_LIBRARIES")); 52 } 53 54 // The links here should be identical to that of the 'vndk' namespace for the 55 // [vendor] section, with the following exceptions: 56 // 1. 'vndk_in_system' needs to be freely linked back to 'vndk'. 57 // 2. 'vndk_in_system' does not need to link to 'default', as any library that 58 // requires anything vendor would not be a vndk_in_system library. 59 if (ctx.IsProductSection()) { 60 ns.GetLink(ctx.GetSystemNamespaceName()) 61 .AddSharedLib(Var("LLNDK_LIBRARIES_PRODUCT")); 62 } else { 63 ns.GetLink(ctx.GetSystemNamespaceName()) 64 .AddSharedLib(Var("LLNDK_LIBRARIES_VENDOR")); 65 } 66 ns.GetLink("vndk").AllowAllSharedLibs(); 67 ns.AddRequires(std::vector{"libneuralnetworks.so"}); 68 69 return ns; 70 } 71 } // namespace contents 72 } // namespace linkerconfig 73 } // namespace android 74