Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 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 | #include "linkerconfig/variableloader.h" |
| 18 | |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 19 | #include <android-base/result.h> |
Kiyoung Kim | 20326ff | 2020-01-13 11:44:05 +0900 | [diff] [blame] | 20 | #include <android-base/strings.h> |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 21 | #include <climits> |
| 22 | #include <cstdlib> |
| 23 | #include <cstring> |
| 24 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 25 | #include "linkerconfig/environment.h" |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 26 | #include "linkerconfig/librarylistloader.h" |
| 27 | #include "linkerconfig/log.h" |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 28 | #include "linkerconfig/variables.h" |
| 29 | |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 30 | using android::base::ErrnoErrorf; |
| 31 | using android::base::Result; |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 32 | using android::linkerconfig::modules::GetProductVndkVersion; |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 33 | using android::linkerconfig::modules::GetVendorVndkVersion; |
| 34 | using android::linkerconfig::modules::Variables; |
| 35 | |
| 36 | namespace { |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 37 | using namespace android::linkerconfig::generator; |
| 38 | |
Kiyoung Kim | 20326ff | 2020-01-13 11:44:05 +0900 | [diff] [blame] | 39 | // 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 |
| 42 | std::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 Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 72 | void LoadVndkVersionVariable() { |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 73 | Variables::AddValue("VENDOR_VNDK_VERSION", GetVendorVndkVersion()); |
| 74 | Variables::AddValue("PRODUCT_VNDK_VERSION", GetProductVndkVersion()); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 75 | } |
| 76 | |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 77 | Result<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 | |
| 90 | void 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 Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 100 | void 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 Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 104 | } |
| 105 | |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 106 | void LoadLibraryListVariables(const std::string& root) { |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 107 | auto private_library_path_vendor = root + |
| 108 | "/system/etc/vndkprivate.libraries." + |
| 109 | GetVendorVndkVersion() + ".txt"; |
| 110 | auto llndk_library_path_vendor = |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 111 | root + "/system/etc/llndk.libraries." + GetVendorVndkVersion() + ".txt"; |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 112 | auto vndksp_library_path_vendor = |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 113 | root + "/system/etc/vndksp.libraries." + GetVendorVndkVersion() + ".txt"; |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 114 | 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 Kim | 11b05d5 | 2019-12-30 10:51:10 +0900 | [diff] [blame] | 127 | auto vndkcorevariant_library_path = |
| 128 | root + "/system/etc/vndkcorevariant.libraries.txt"; |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 129 | auto sanitizer_library_path = root + "/system/etc/sanitizer.libraries.txt"; |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 130 | |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 131 | Variables::AddValue("LLNDK_LIBRARIES_VENDOR", |
| 132 | GetPublicLibrariesString(llndk_library_path_vendor, |
| 133 | private_library_path_vendor)); |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 134 | |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 135 | Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_VENDOR", |
| 136 | GetPrivateLibrariesString(llndk_library_path_vendor, |
| 137 | private_library_path_vendor)); |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 138 | |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 139 | Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_VENDOR", |
| 140 | GetPublicLibrariesString(vndksp_library_path_vendor, |
| 141 | private_library_path_vendor)); |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 142 | |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 143 | Variables::AddValue("VNDK_CORE_LIBRARIES_VENDOR", |
| 144 | GetPublicLibrariesString(vndkcore_library_path_vendor, |
| 145 | private_library_path_vendor)); |
| 146 | |
Kiyoung Kim | fec6e10 | 2020-01-20 19:55:40 +0900 | [diff] [blame] | 147 | if (GetProductVndkVersion() != "") { |
| 148 | Variables::AddValue("LLNDK_LIBRARIES_PRODUCT", |
| 149 | GetPublicLibrariesString(llndk_library_path_product, |
| 150 | private_library_path_product)); |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 151 | |
Kiyoung Kim | fec6e10 | 2020-01-20 19:55:40 +0900 | [diff] [blame] | 152 | Variables::AddValue("PRIVATE_LLNDK_LIBRARIES_PRODUCT", |
| 153 | GetPrivateLibrariesString(llndk_library_path_product, |
| 154 | private_library_path_product)); |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 155 | |
Kiyoung Kim | fec6e10 | 2020-01-20 19:55:40 +0900 | [diff] [blame] | 156 | Variables::AddValue("VNDK_SAMEPROCESS_LIBRARIES_PRODUCT", |
| 157 | GetPublicLibrariesString(vndksp_library_path_product, |
| 158 | private_library_path_product)); |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 159 | |
Kiyoung Kim | fec6e10 | 2020-01-20 19:55:40 +0900 | [diff] [blame] | 160 | Variables::AddValue("VNDK_CORE_LIBRARIES_PRODUCT", |
| 161 | GetPublicLibrariesString(vndkcore_library_path_product, |
| 162 | private_library_path_product)); |
| 163 | } |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 164 | |
Kiyoung Kim | 18eb4c6 | 2019-09-27 14:06:54 +0900 | [diff] [blame] | 165 | Variables::AddValue("VNDK_USING_CORE_VARIANT_LIBRARIES", |
| 166 | GetPublicLibrariesString(vndkcorevariant_library_path, |
Justin Yun | 2a07d26 | 2019-12-16 17:47:02 +0900 | [diff] [blame] | 167 | private_library_path_vendor)); |
Kiyoung Kim | 18eb4c6 | 2019-09-27 14:06:54 +0900 | [diff] [blame] | 168 | |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 169 | Variables::AddValue("SANITIZER_RUNTIME_LIBRARIES", |
| 170 | GetLibrariesString(sanitizer_library_path)); |
Kiyoung Kim | 20326ff | 2020-01-13 11:44:05 +0900 | [diff] [blame] | 171 | |
| 172 | Variables::AddValue("STUB_LIBRARIES", |
| 173 | android::base::Join(stub_libraries, ':')); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 174 | } |
| 175 | } // namespace |
| 176 | |
| 177 | namespace android { |
| 178 | namespace linkerconfig { |
| 179 | namespace generator { |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 180 | |
| 181 | void LoadVariables(const std::string& root) { |
Kiyoung Kim | 853438d | 2019-07-16 09:51:14 +0900 | [diff] [blame] | 182 | LoadVndkVersionVariable(); |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 183 | LoadPartitionPathVariables(root); |
| 184 | LoadLibraryListVariables(root); |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 185 | } |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 186 | |
Kiyoung Kim | e9a77fe | 2019-05-23 11:04:20 +0900 | [diff] [blame] | 187 | } // namespace generator |
| 188 | } // namespace linkerconfig |
Jooyung Han | a3d5d09 | 2019-09-26 23:23:50 +0900 | [diff] [blame] | 189 | } // namespace android |