blob: 8c3ae6d872278be5ac73a8e24c2908c221db683a [file] [log] [blame]
Kiyoung Kim7d422b32019-03-05 17:06:13 +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
Bob Badour2da51982021-02-03 22:30:12 -080017package {
18 default_applicable_licenses: ["Android-Apache-2.0"],
19}
20
Kiyoung Kim7d422b32019-03-05 17:06:13 +090021cc_defaults {
22 name: "linkerconfig_defaults",
23 cflags: [
24 "-Wall",
25 "-Werror",
26 "-Wextra",
27 ],
Jooyung Han86b57f62020-01-06 18:09:30 +090028 defaults: ["libapexutil-deps"],
Kiyoung Kim7d422b32019-03-05 17:06:13 +090029 static_libs: [
Jooyung Han86b57f62020-01-06 18:09:30 +090030 "libapexutil",
Kiyoung Kim7d422b32019-03-05 17:06:13 +090031 "libbase",
32 "liblog",
Kiyoung Kim197857e2020-10-06 17:07:25 +090033 "libprotobuf-cpp-lite",
Jooyung Hanb6323922020-08-11 08:56:29 +000034 "libxml2",
Kiyoung Kim197857e2020-10-06 17:07:25 +090035 "lib_linker_config_proto_lite",
Kiyoung Kim7d422b32019-03-05 17:06:13 +090036 ],
Jooyung Hanb6323922020-08-11 08:56:29 +000037 target: {
38 host: {
39 static_libs: [
40 "libicui18n",
41 "libicuuc",
42 ],
43 },
44 not_windows: {
45 static_libs: ["libicuuc_stubdata"],
46 },
47 },
Jooyung Hana3d5d092019-09-26 23:23:50 +090048 host_supported: true,
Kiyoung Kim7d422b32019-03-05 17:06:13 +090049}
50
Kiyoung Kim853438d2019-07-16 09:51:14 +090051cc_defaults {
52 name: "linkerconfig_test_defaults",
53 defaults: ["linkerconfig_defaults"],
54 cflags: [
55 "-g",
56 "-Wunused",
57 ],
58 test_suites: ["general-tests"],
59}
60
Kiyoung Kim7d422b32019-03-05 17:06:13 +090061cc_library_static {
62 name: "linkerconfig_modules",
63 defaults: [ "linkerconfig_defaults" ],
Kiyoung Kimff9cbf72019-03-14 18:26:24 +090064 export_include_dirs: [ "modules/include" ],
Kiyoung Kim7d422b32019-03-05 17:06:13 +090065 srcs: [
66 "modules/*.cc",
67 ],
Jooyung Hanb6323922020-08-11 08:56:29 +000068 generated_sources: ["apex-info-list"],
Kiyoung Kimb1645062020-11-30 14:58:47 +090069 apex_available: [
70 "//apex_available:platform",
71 "com.android.runtime",
72 ],
Kiyoung Kim7d422b32019-03-05 17:06:13 +090073}
74
Kiyoung Kimff9cbf72019-03-14 18:26:24 +090075cc_library_static {
76 name: "linkerconfig_contents",
77 defaults: [ "linkerconfig_defaults" ],
78 export_include_dirs: [ "contents/include" ],
79 static_libs: [
80 "linkerconfig_modules",
81 ],
82 srcs: [
83 "contents/namespace/*.cc",
84 "contents/section/*.cc",
85 "contents/configuration/*.cc",
86 "contents/context/*.cc",
Martin Stjernholmcb9df4f2019-10-02 20:47:12 +010087 "contents/common/*.cc",
Kiyoung Kimff9cbf72019-03-14 18:26:24 +090088 ],
Kiyoung Kimb1645062020-11-30 14:58:47 +090089 apex_available: [
90 "//apex_available:platform",
91 "com.android.runtime",
92 ],
Kiyoung Kimff9cbf72019-03-14 18:26:24 +090093}
94
Kiyoung Kim853438d2019-07-16 09:51:14 +090095cc_library_static {
96 name: "linkerconfig_generator",
97 defaults : [ "linkerconfig_defaults" ],
98 export_include_dirs: [ "generator/include" ],
Kiyoung Kime9a77fe2019-05-23 11:04:20 +090099 static_libs: [
100 "linkerconfig_modules",
101 "linkerconfig_contents",
102 ],
103 srcs: [
104 "generator/*.cc",
Kiyoung Kim15e38352019-07-11 17:07:03 +0900105 ],
Kiyoung Kimb1645062020-11-30 14:58:47 +0900106 apex_available: [
107 "//apex_available:platform",
108 "com.android.runtime",
109 ],
Kiyoung Kim853438d2019-07-16 09:51:14 +0900110}
111
112cc_binary {
113 name: "linkerconfig",
114 defaults: [ "linkerconfig_defaults" ],
115 static_libs: [
116 "linkerconfig_modules",
117 "linkerconfig_contents",
118 "linkerconfig_generator",
119 ],
120 srcs: [
121 "main.cc",
122 ],
Jooyung Han3cb5bcd2020-02-12 04:21:16 +0900123 required: [
124 // files from /system/etc
125 "sanitizer.libraries.txt",
126 "vndkcorevariant.libraries.txt",
Jooyung Han7c2b73a2020-02-12 08:53:51 +0900127 // Note that even thought linkerconfig requires at least one version of VNDK APEXes,
128 // we can't list it here because the exact version is unknown at build-time. It is decided
129 // at runtime according to ro.vndk.version (or ro.product.vndk.version)
Jooyung Han3cb5bcd2020-02-12 04:21:16 +0900130 ],
Martin Stjernholm908bfdb2020-08-07 19:00:55 +0100131 target: {
132 android: {
133 // This binary needs to be static on device, but it's also packaged
134 // as a host prebuilt in runtime-module-host-exports. On host it
135 // should link all libraries statically except libc and other system
136 // libraries, so enable this only on device.
137 static_executable: true,
138 },
Martin Stjernholmaefc84e2020-09-01 19:27:53 +0100139 host: {
140 stl: "c++_static", // Link libc++ statically.
141 },
Martin Stjernholm908bfdb2020-08-07 19:00:55 +0100142 },
Yi Kong867b2022020-10-12 00:31:18 +0800143
144 // Device does not boot when global ThinLTO is enabled for linkerconfig.
145 // http://b/170573443
146 lto: {
147 never: true,
148 },
Kiyoung Kimb1645062020-11-30 14:58:47 +0900149
150 apex_available: [
151 "//apex_available:platform",
152 "com.android.runtime",
153 ],
Kiyoung Kime9a77fe2019-05-23 11:04:20 +0900154}
155
Kiyoung Kim7d422b32019-03-05 17:06:13 +0900156cc_test {
157 name: "linkerconfig_modules_unittest",
Kiyoung Kim853438d2019-07-16 09:51:14 +0900158 defaults: [ "linkerconfig_test_defaults" ],
Kiyoung Kim7d422b32019-03-05 17:06:13 +0900159 srcs: [
160 "modules/tests/*_test.cc",
161 ],
162 static_libs: [
Jooyung Han33a95052019-12-06 19:47:30 +0900163 "libgmock",
Kiyoung Kim7d422b32019-03-05 17:06:13 +0900164 "linkerconfig_modules",
Kiyoung Kimb9727632020-12-08 16:14:57 +0900165 "libc++fs",
Kiyoung Kim7d422b32019-03-05 17:06:13 +0900166 ],
Kiyoung Kimf9920e22020-08-31 13:55:25 +0900167 data: [
168 "modules/tests/data/linker.config.*",
169 ],
Kiyoung Kimff9cbf72019-03-14 18:26:24 +0900170}
171
172cc_test {
173 name: "linkerconfig_backward_compatibility_test",
Kiyoung Kim853438d2019-07-16 09:51:14 +0900174 defaults: [ "linkerconfig_test_defaults" ],
Kiyoung Kimff9cbf72019-03-14 18:26:24 +0900175 srcs: [
176 "contents/tests/backward_compatibility/*_test.cc",
177 ],
178 static_libs: [
179 "linkerconfig_modules",
180 "linkerconfig_contents",
181 ],
Kiyoung Kim15e38352019-07-11 17:07:03 +0900182}
Kiyoung Kim853438d2019-07-16 09:51:14 +0900183
184cc_test {
185 name: "linkerconfig_generator_unittest",
186 defaults: [ "linkerconfig_test_defaults" ],
187 srcs: [
188 "generator/tests/*_test.cc",
189 ],
190 static_libs: [
191 "linkerconfig_modules",
192 "linkerconfig_contents",
193 "linkerconfig_generator",
194 ],
195 data: [
196 "generator/tests/data/*.txt",
197 ],
Kiyoung Kim84cbf002019-08-21 19:46:51 +0900198}
199
200cc_test {
201 name: "linkerconfig_contents_fulltest",
202 defaults: [ "linkerconfig_test_defaults" ],
203 local_include_dirs: [
204 "contents/tests/configuration/include",
205 ],
206 srcs: [
207 "contents/tests/configuration/*_test.cc",
208 ],
209 static_libs: [
210 "linkerconfig_modules",
211 "linkerconfig_contents",
212 ],
Kiyoung Kim722dad62019-12-19 15:59:55 +0900213}
214
215prebuilt_etc {
216 name: "ld.config.recovery.txt",
217 recovery: true,
218 filename: "ld.config.txt",
219 src: ":generate_recovery_linker_config",
220}
221
222genrule {
223 name: "generate_recovery_linker_config",
224 recovery: true,
Kiyoung Kim5c8366d2019-12-30 18:43:00 +0900225 out: ["ld.config.txt"],
Kiyoung Kim722dad62019-12-19 15:59:55 +0900226 tools: ["linkerconfig"],
Kiyoung Kim5c8366d2019-12-30 18:43:00 +0900227 cmd: "$(location linkerconfig) --recovery --target $(genDir)",
Martin Stjernholmcb9df4f2019-10-02 20:47:12 +0100228}
Jooyung Hanfcaa89a2020-03-20 18:20:23 +0900229
230genrule {
231 name: "linkerconfig_diff_test_host_tools",
232 out: ["linkerconfig_diff_test_host_tools.zip"],
Kiyoung Kim197857e2020-10-06 17:07:25 +0900233 tools: ["conv_apex_manifest", "conv_linker_config", "linkerconfig", "soong_zip"],
Jooyung Hanfcaa89a2020-03-20 18:20:23 +0900234 cmd: "HOST_OUT_BIN=$$(dirname $(location conv_apex_manifest)) && " +
235 "HOST_SOONG_OUT=$$(dirname $$HOST_OUT_BIN) && " +
236 "LIBCPLUSPLUS=$$(find $${HOST_SOONG_OUT}/lib64 -name \"libc++.*\") && " +
237 "mkdir -p $(genDir)/tools/bin && " +
238 "mkdir -p $(genDir)/tools/lib64 && " +
239 "cp $(location conv_apex_manifest) $(genDir)/tools/bin && " +
Kiyoung Kim197857e2020-10-06 17:07:25 +0900240 "cp $(location conv_linker_config) $(genDir)/tools/bin && " +
Jooyung Hanfcaa89a2020-03-20 18:20:23 +0900241 "cp $(location linkerconfig) $(genDir)/tools/bin && " +
242 "cp $$LIBCPLUSPLUS $(genDir)/tools/lib64 && " +
243 "$(location soong_zip) -C $(genDir)/tools -D $(genDir)/tools -o $(out)",
244}
245
246sh_test_host {
247 name: "linkerconfig_diff_test",
248 src: "rundiff.sh",
249 filename: "linkerconfig_diff_test.sh",
Jooyung Hanfcaa89a2020-03-20 18:20:23 +0900250 test_config: "linkerconfig_diff_test.xml",
251 data: [
Jooyung Hana8df5052022-01-26 16:25:30 +0900252 "testdata/root/**/*",
253 "testdata/root/**/.*", // copy .keep files
254 "testdata/golden_output/**/*",
255 "testdata/prepare_root.sh",
Jooyung Hanfcaa89a2020-03-20 18:20:23 +0900256 // workaround to use host tools(conv_apex_manifest, linkerconfig) on build server
257 // ":conv_apex_manifest",
258 // ":linkerconfig",
259 ":linkerconfig_diff_test_host_tools",
260 ],
Julien Desprez18c550a2021-06-28 17:19:12 +0000261 test_options: {
262 unit_test: true,
263 },
Martin Stjernholm908bfdb2020-08-07 19:00:55 +0100264}