blob: 9bfb5ef5857ace6540a2f710c95997bf00b87ee3 [file] [log] [blame]
Kiyoung Kime9a77fe2019-05-23 11:04:20 +09001/*
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#include "linkerconfig/variableloader.h"
18
Kiyoung Kim853438d2019-07-16 09:51:14 +090019#include <android-base/result.h>
Kiyoung Kim20326ff2020-01-13 11:44:05 +090020#include <android-base/strings.h>
Kiyoung Kim853438d2019-07-16 09:51:14 +090021#include <climits>
22#include <cstdlib>
23#include <cstring>
24
Kiyoung Kime9a77fe2019-05-23 11:04:20 +090025#include "linkerconfig/environment.h"
Kiyoung Kim853438d2019-07-16 09:51:14 +090026#include "linkerconfig/librarylistloader.h"
27#include "linkerconfig/log.h"
Kiyoung Kime9a77fe2019-05-23 11:04:20 +090028#include "linkerconfig/variables.h"
29
Kiyoung Kim853438d2019-07-16 09:51:14 +090030using android::base::ErrnoErrorf;
31using android::base::Result;
Justin Yun2a07d262019-12-16 17:47:02 +090032using android::linkerconfig::modules::GetProductVndkVersion;
Kiyoung Kime9a77fe2019-05-23 11:04:20 +090033using android::linkerconfig::modules::GetVendorVndkVersion;
34using android::linkerconfig::modules::Variables;
35
36namespace {
Kiyoung Kim853438d2019-07-16 09:51:14 +090037using namespace android::linkerconfig::generator;
38
Kiyoung Kim20326ff2020-01-13 11:44:05 +090039// Stub libraries are list of libraries which has stub interface and installed
40// in system image so other partition and APEX modules can link to it.
41// TODO(b/147210213) : Generate this list on build and read from the file
42std::vector<std::string> stub_libraries = {
43 "libEGL.so",
44 "libGLESv1_CM.so",
45 "libGLESv2.so",
46 "libGLESv3.so",
47 "libRS.so",
48 "libaaudio.so",
49 "libandroid.so",
50 "libandroid_net.so",
51 "libbinder_ndk.so",
52 "libc.so",
53 "libcgrouprc.so",
54 "libclang_rt.asan-arm-android.so",
55 "libclang_rt.asan-i686-android.so",
56 "libclang_rt.asan-x86_64-android.so",
57 "libdl.so",
58 "libdl_android.so",
59 "libft2.so",
60 "liblog.so",
61 "libm.so",
62 "libmediametrics.so",
63 "libmediandk.so",
64 "libnativewindow.so",
65 "libneuralnetworks_packageinfo.so",
66 "libstatssocket.so",
67 "libsync.so",
68 "libvndksupport.so",
69 "libvulkan.so",
70};
71
Kiyoung Kim853438d2019-07-16 09:51:14 +090072void LoadVndkVersionVariable() {
Justin Yun2a07d262019-12-16 17:47:02 +090073 Variables::AddValue("VENDOR_VNDK_VERSION", GetVendorVndkVersion());
74 Variables::AddValue("PRODUCT_VNDK_VERSION", GetProductVndkVersion());
Kiyoung Kime9a77fe2019-05-23 11:04:20 +090075}
76
Kiyoung Kim853438d2019-07-16 09:51:14 +090077Result<std::string> GetRealPath(std::string target_path) {
78 char resolved_path[PATH_MAX];
79 if (realpath(target_path.c_str(), resolved_path) != nullptr) {
80 int start_index = 0;
81 if (resolved_path[0] == '/') {
82 start_index = 1;
83 }
84 return &resolved_path[start_index];
85 }
86
87 return ErrnoErrorf("Failed to get realpath from {}", target_path);
88}
89
90void LoadVariableFromPartitionPath(std::string variable_name, std::string path) {
91 auto real_path = GetRealPath(path);
92
93 if (real_path) {
94 Variables::AddValue(variable_name, *real_path);
95 } else {
96 LOG(WARNING) << real_path.error();
97 }
98}
99
Jooyung Hana3d5d092019-09-26 23:23:50 +0900100void LoadPartitionPathVariables(const std::string& root) {
101 // TODO(b/141714913): generalize path handling
102 LoadVariableFromPartitionPath("PRODUCT", root + "/product");
103 LoadVariableFromPartitionPath("SYSTEM_EXT", root + "/system_ext");
Kiyoung Kim853438d2019-07-16 09:51:14 +0900104}
105
Jooyung Hana3d5d092019-09-26 23:23:50 +0900106void LoadLibraryListVariables(const std::string& root) {
Justin Yun2a07d262019-12-16 17:47:02 +0900107 auto private_library_path_vendor = root +
108 "/system/etc/vndkprivate.libraries." +
109 GetVendorVndkVersion() + ".txt";
110 auto llndk_library_path_vendor =
Jooyung Hana3d5d092019-09-26 23:23:50 +0900111 root + "/system/etc/llndk.libraries." + GetVendorVndkVersion() + ".txt";
Justin Yun2a07d262019-12-16 17:47:02 +0900112 auto vndksp_library_path_vendor =
Jooyung Hana3d5d092019-09-26 23:23:50 +0900113 root + "/system/etc/vndksp.libraries." + GetVendorVndkVersion() + ".txt";
Justin Yun2a07d262019-12-16 17:47:02 +0900114 auto vndkcore_library_path_vendor = root + "/system/etc/vndkcore.libraries." +
115 GetVendorVndkVersion() + ".txt";
116
117 auto private_library_path_product = root +
118 "/system/etc/vndkprivate.libraries." +
119 GetProductVndkVersion() + ".txt";
120 auto llndk_library_path_product =
121 root + "/system/etc/llndk.libraries." + GetProductVndkVersion() + ".txt";
122 auto vndksp_library_path_product =
123 root + "/system/etc/vndksp.libraries." + GetProductVndkVersion() + ".txt";
124 auto vndkcore_library_path_product = root + "/system/etc/vndkcore.libraries." +
125 GetProductVndkVersion() + ".txt";
126
Kiyoung Kim11b05d52019-12-30 10:51:10 +0900127 auto vndkcorevariant_library_path =
128 root + "/system/etc/vndkcorevariant.libraries.txt";
Jooyung Hana3d5d092019-09-26 23:23:50 +0900129 auto sanitizer_library_path = root + "/system/etc/sanitizer.libraries.txt";
Kiyoung Kim853438d2019-07-16 09:51:14 +0900130
Justin Yun2a07d262019-12-16 17:47:02 +0900131 Variables::AddValue("LLNDK_LIBRARIES_VENDOR",
132 GetPublicLibrariesString(llndk_library_path_vendor,
133 private_library_path_vendor));
Kiyoung Kim853438d2019-07-16 09:51:14 +0900134
Justin Yun2a07d262019-12-16 17:47:02 +0900135 Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_VENDOR",
136 GetPrivateLibrariesString(llndk_library_path_vendor,
137 private_library_path_vendor));
Kiyoung Kim853438d2019-07-16 09:51:14 +0900138
Justin Yun2a07d262019-12-16 17:47:02 +0900139 Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_VENDOR",
140 GetPublicLibrariesString(vndksp_library_path_vendor,
141 private_library_path_vendor));
Kiyoung Kim853438d2019-07-16 09:51:14 +0900142
Justin Yun2a07d262019-12-16 17:47:02 +0900143 Variables::AddValue("VNDK_CORE_LIBRARIES_VENDOR",
144 GetPublicLibrariesString(vndkcore_library_path_vendor,
145 private_library_path_vendor));
146
Kiyoung Kimfec6e102020-01-20 19:55:40 +0900147 if (GetProductVndkVersion() != "") {
148 Variables::AddValue("LLNDK_LIBRARIES_PRODUCT",
149 GetPublicLibrariesString(llndk_library_path_product,
150 private_library_path_product));
Justin Yun2a07d262019-12-16 17:47:02 +0900151
Kiyoung Kimfec6e102020-01-20 19:55:40 +0900152 Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_PRODUCT",
153 GetPrivateLibrariesString(llndk_library_path_product,
154 private_library_path_product));
Justin Yun2a07d262019-12-16 17:47:02 +0900155
Kiyoung Kimfec6e102020-01-20 19:55:40 +0900156 Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_PRODUCT",
157 GetPublicLibrariesString(vndksp_library_path_product,
158 private_library_path_product));
Justin Yun2a07d262019-12-16 17:47:02 +0900159
Kiyoung Kimfec6e102020-01-20 19:55:40 +0900160 Variables::AddValue("VNDK_CORE_LIBRARIES_PRODUCT",
161 GetPublicLibrariesString(vndkcore_library_path_product,
162 private_library_path_product));
163 }
Kiyoung Kim853438d2019-07-16 09:51:14 +0900164
Kiyoung Kim18eb4c62019-09-27 14:06:54 +0900165 Variables::AddValue("VNDK_USING_CORE_VARIANT_LIBRARIES",
166 GetPublicLibrariesString(vndkcorevariant_library_path,
Justin Yun2a07d262019-12-16 17:47:02 +0900167 private_library_path_vendor));
Kiyoung Kim18eb4c62019-09-27 14:06:54 +0900168
Kiyoung Kim853438d2019-07-16 09:51:14 +0900169 Variables::AddValue("SANITIZER_RUNTIME_LIBRARIES",
170 GetLibrariesString(sanitizer_library_path));
Kiyoung Kim20326ff2020-01-13 11:44:05 +0900171
172 Variables::AddValue("STUB_LIBRARIES",
173 android::base::Join(stub_libraries, ':'));
Kiyoung Kime9a77fe2019-05-23 11:04:20 +0900174}
175} // namespace
176
177namespace android {
178namespace linkerconfig {
179namespace generator {
Jooyung Hana3d5d092019-09-26 23:23:50 +0900180
181void LoadVariables(const std::string& root) {
Kiyoung Kim853438d2019-07-16 09:51:14 +0900182 LoadVndkVersionVariable();
Jooyung Hana3d5d092019-09-26 23:23:50 +0900183 LoadPartitionPathVariables(root);
184 LoadLibraryListVariables(root);
Kiyoung Kime9a77fe2019-05-23 11:04:20 +0900185}
Jooyung Hana3d5d092019-09-26 23:23:50 +0900186
Kiyoung Kime9a77fe2019-05-23 11:04:20 +0900187} // namespace generator
188} // namespace linkerconfig
Jooyung Hana3d5d092019-09-26 23:23:50 +0900189} // namespace android