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 #include "linkerconfig/common.h"
17 
18 #include <string>
19 #include <vector>
20 
21 #include <android-base/properties.h>
22 #include <android-base/strings.h>
23 
24 #include "linkerconfig/context.h"
25 #include "linkerconfig/section.h"
26 #include "linkerconfig/variables.h"
27 
28 namespace {
29 const std::vector<std::string> kBionicLibs = {
30     "libc.so",
31     "libdl.so",
32     "libdl_android.so",
33     "libm.so",
34 };
35 }  // namespace
36 
37 namespace android {
38 namespace linkerconfig {
39 namespace contents {
40 
41 using android::linkerconfig::modules::Namespace;
42 using android::linkerconfig::modules::Section;
43 
AddStandardSystemLinks(const Context & ctx,Section * section)44 void AddStandardSystemLinks(const Context& ctx, Section* section) {
45   const bool debuggable = android::base::GetBoolProperty("ro.debuggable", false);
46   const std::string system_ns_name = ctx.GetSystemNamespaceName();
47   const bool is_section_vndk_enabled = ctx.IsSectionVndkEnabled();
48   section->ForEachNamespaces([&](Namespace& ns) {
49     if (ns.GetName() != system_ns_name) {
50       ns.GetLink(system_ns_name).AddSharedLib(kBionicLibs);
51       if (!is_section_vndk_enabled || ns.GetName() != "default") {
52         ns.GetLink(system_ns_name)
53             .AddSharedLib(Var("SANITIZER_RUNTIME_LIBRARIES"));
54       }
55       if (debuggable) {
56         // Library on the system image that can be dlopened for debugging purposes.
57         ns.GetLink(system_ns_name).AddSharedLib("libfdtrack.so");
58       }
59     }
60   });
61 }
62 
GetSystemStubLibraries()63 std::vector<std::string> GetSystemStubLibraries() {
64   return android::base::Split(Var("STUB_LIBRARIES", ""), ":");
65 }
66 
67 }  // namespace contents
68 }  // namespace linkerconfig
69 }  // namespace android
70