blob: 78a97ec3c831992f930054d58899f0e6001266e8 [file] [log] [blame]
Colin Cross97f0aef2016-07-14 16:05:46 -07001cc_library_static {
2 name: "liblinker_malloc",
Dan Willemsen7ec52b12016-11-28 17:02:25 -08003 defaults: ["linux_bionic_supported"],
Jiyong Park8d7866c2018-05-29 16:34:39 +09004 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -07005
6 srcs: [
Colin Cross97f0aef2016-07-14 16:05:46 -07007 "linker_memory.cpp",
8 ],
Elliott Hughesd50a1de2018-02-05 17:30:57 -08009 cflags: [
10 "-Wall",
11 "-Werror",
12 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070013
14 // We need to access Bionic private headers in the linker.
15 include_dirs: ["bionic/libc"],
Christopher Ferris7a3681e2017-04-24 17:48:32 -070016
Elliott Hughes5e62b342018-10-25 11:00:00 -070017 static_libs: ["libasync_safe", "libbase"],
Colin Cross97f0aef2016-07-14 16:05:46 -070018}
19
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070020// This is used for bionic on (host) Linux to bootstrap our linker embedded into
21// a binary.
22//
23// Host bionic binaries do not have a PT_INTERP section, instead this gets
24// embedded as the entry point, and the linker is embedded as ELF sections in
25// each binary. There's a linker script that sets all of that up (generated by
26// extract_linker), and defines the extern symbols used in this file.
27cc_object {
28 name: "linker_wrapper",
29 host_supported: true,
30 device_supported: false,
31 target: {
Elliott Hughesd50a1de2018-02-05 17:30:57 -080032 linux_bionic: {
33 enabled: true,
34 },
35 linux_glibc: {
36 enabled: false,
37 },
38 darwin: {
39 enabled: false,
40 },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070041 },
42
43 cflags: [
44 "-fno-stack-protector",
45 "-Wstrict-overflow=5",
46 "-fvisibility=hidden",
47 "-Wall",
48 "-Wextra",
49 "-Wno-unused",
50 "-Werror",
51 ],
52
53 srcs: [
54 "linker_wrapper.cpp",
55 ],
56 arch: {
57 x86_64: {
58 srcs: ["arch/x86_64/begin.S"],
59 },
60 },
61
62 prefix_symbols: "__dlwrap_",
63
64 // We need to access Bionic private headers in the linker.
65 include_dirs: ["bionic/libc"],
66}
67
dimitryb8b3a762018-09-25 12:31:11 +020068filegroup {
69 name: "linker_sources",
Colin Cross97f0aef2016-07-14 16:05:46 -070070 srcs: [
71 "dlfcn.cpp",
72 "linker.cpp",
73 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -070074 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -070075 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -080076 "linker_config.cpp",
Ryan Prichard772affd2019-12-23 16:03:14 -080077 "linker_debug.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070078 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070079 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070080 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -080081 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -070082 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -070083 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070084 "linker_logger.cpp",
85 "linker_mapped_file_fragment.cpp",
86 "linker_phdr.cpp",
Ryan Prichardf56ac992020-01-02 16:36:06 -080087 "linker_relocate.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070088 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070089 "linker_soinfo.cpp",
Ryan Prichard45d13492019-01-03 02:51:30 -080090 "linker_tls.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070091 "linker_utils.cpp",
92 "rt.cpp",
93 ],
dimitryb8b3a762018-09-25 12:31:11 +020094}
Colin Cross97f0aef2016-07-14 16:05:46 -070095
dimitryb8b3a762018-09-25 12:31:11 +020096filegroup {
97 name: "linker_sources_arm",
98 srcs: [
99 "arch/arm/begin.S",
100 "linker_exidx_static.c",
Ryan Prichardb5d9d2d2019-12-23 16:45:47 -0800101 "arch/arm_neon/linker_gnu_hash_neon.cpp",
dimitryb8b3a762018-09-25 12:31:11 +0200102 ],
103}
104
105filegroup {
106 name: "linker_sources_arm64",
107 srcs: [
108 "arch/arm64/begin.S",
Ryan Prichardffaae702019-01-23 17:47:10 -0800109 "arch/arm64/tlsdesc_resolver.S",
Ryan Prichardb5d9d2d2019-12-23 16:45:47 -0800110 "arch/arm_neon/linker_gnu_hash_neon.cpp",
dimitryb8b3a762018-09-25 12:31:11 +0200111 ],
112}
113
114filegroup {
115 name: "linker_sources_x86",
116 srcs: [
117 "arch/x86/begin.S",
118 ],
119}
120
121filegroup {
122 name: "linker_sources_x86_64",
123 srcs: [
124 "arch/x86_64/begin.S",
125 ],
126}
127
128filegroup {
129 name: "linker_sources_mips",
130 srcs: [
131 "arch/mips/begin.S",
132 "linker_mips.cpp",
133 ],
134}
135
136filegroup {
137 name: "linker_sources_mips64",
138 srcs: [
139 "arch/mips64/begin.S",
140 "linker_mips.cpp",
141 ],
142}
143
144filegroup {
145 name: "linker_version_script",
146 srcs: ["linker.generic.map"],
147}
148
149filegroup {
150 name: "linker_version_script_arm",
151 srcs: ["linker.arm.map"],
152}
153
154cc_defaults {
155 name: "linker_defaults",
Colin Cross97f0aef2016-07-14 16:05:46 -0700156 arch: {
157 arm: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700158 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700159 },
160 x86: {
Ryan Prichard7046f392018-05-24 14:07:27 -0700161 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700162 },
163 },
164
Colin Cross97f0aef2016-07-14 16:05:46 -0700165 // -shared is used to overwrite the -Bstatic and -static
166 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
167 // This dynamic linker is actually a shared object linked with static libraries.
168 ldflags: [
169 "-shared",
170 "-Wl,-Bsymbolic",
171 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100172 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700173 ],
174
175 cflags: [
176 "-fno-stack-protector",
177 "-Wstrict-overflow=5",
178 "-fvisibility=hidden",
179 "-Wall",
180 "-Wextra",
181 "-Wunused",
182 "-Werror",
Ryan Prichard9ee80692019-01-15 16:10:36 -0800183
184 // Define _USING_LIBCXX so <stdatomic.h> defers to the <atomic> header. When a Soong module
185 // uses the platform libc++, Soong automatically passes this macro, but the dynamic linker
186 // links against libc++ manually.
187 "-D_USING_LIBCXX",
Colin Cross97f0aef2016-07-14 16:05:46 -0700188 ],
189
190 // TODO: split out the asflags.
191 asflags: [
192 "-fno-stack-protector",
193 "-Wstrict-overflow=5",
194 "-fvisibility=hidden",
195 "-Wall",
196 "-Wextra",
197 "-Wunused",
198 "-Werror",
199 ],
200
Jiyong Park02586a22017-05-20 01:01:24 +0900201 product_variables: {
202 debuggable: {
203 cppflags: ["-DUSE_LD_CONFIG_FILE"],
204 },
Jackeagledb658422020-01-02 12:20:51 +0100205 bliss: {
Danny Baumann7b6b6c92018-08-29 11:21:52 +0200206 target_process_sdk_version_override: {
207 cppflags: ["-DSDK_VERSION_OVERRIDES=\"%s\""],
208 },
Christopher R. Palmer9dc396a2017-04-08 22:40:01 +0200209 target_shim_libs: {
210 cppflags: ["-DLD_SHIM_LIBS=\"%s\""],
211 },
212 },
Jiyong Park02586a22017-05-20 01:01:24 +0900213 },
214
Colin Cross97f0aef2016-07-14 16:05:46 -0700215 cppflags: ["-Wold-style-cast"],
216
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800217 // we are going to link libc++_static manually because
218 // when stl is not set to "none" build system adds libdl
219 // to the list of static libraries which needs to be
220 // avoided in the case of building loader.
221 stl: "none",
222
Colin Cross97f0aef2016-07-14 16:05:46 -0700223 // we don't want crtbegin.o (because we have begin.o), so unset it
224 // just for this module
225 nocrt: true,
226
dimitryb8b3a762018-09-25 12:31:11 +0200227 static_executable: true,
228
229 // Leave the symbols in the shared library so that stack unwinders can produce
230 // meaningful name resolution.
231 strip: {
232 keep_symbols: true,
233 },
234
235 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
236 // looking up symbols in the linker by mistake.
237 prefix_symbols: "__dl_",
238
239 sanitize: {
240 hwaddress: false,
241 },
242}
243
244cc_binary {
245 defaults: ["linux_bionic_supported", "linker_defaults"],
246 srcs: [ ":linker_sources" ],
247
248 arch: {
249 arm: {
250 srcs: [ ":linker_sources_arm" ],
251 version_script: ":linker_version_script_arm",
252 },
253 arm64: {
254 srcs: [":linker_sources_arm64"],
255 version_script: ":linker_version_script",
256 },
257 x86: {
258 srcs: [":linker_sources_x86"],
259 version_script: ":linker_version_script",
260 },
261 x86_64: {
262 srcs: [":linker_sources_x86_64"],
263 version_script: ":linker_version_script",
264 },
265 mips: {
266 srcs: [":linker_sources_mips"],
267 version_script: ":linker_version_script",
268 },
269 mips64: {
270 srcs: [":linker_sources_mips64"],
271 version_script: ":linker_version_script",
272 },
273 },
274
275 // We need to access Bionic private headers in the linker.
276 include_dirs: ["bionic/libc"],
277
Colin Cross97f0aef2016-07-14 16:05:46 -0700278 static_libs: [
279 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800280 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700281 "libziparchive",
282 "libutils",
283 "libbase",
284 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800285
Dan Willemsen4326d842017-05-07 13:07:41 -0700286 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800287
Colin Cross97f0aef2016-07-14 16:05:46 -0700288 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800289 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700290
291 // Important: The liblinker_malloc should be the last library in the list
292 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800293 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700294 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700295
296 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800297 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900298 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700299 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900300 lib32: {
301 cflags: ["-DLIB_PATH=\"lib\""],
302 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700303 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900304 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700305 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800306 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700307 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800308 system_shared_libs: [],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800309
310 // Opt out of native_coverage when opting out of system_shared_libs
311 native_coverage: false,
312
Colin Cross97f0aef2016-07-14 16:05:46 -0700313 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800314 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700315 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800316 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700317 },
318 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800319 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700320}
dimitry11da1dc2018-01-05 13:35:43 +0100321
322cc_library {
323 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
324 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
325 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
326 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
327 // we use this property to make sure libc.so has its own copy of the code from
328 // libgcc.a it uses.
329 //
330 // DO NOT REMOVE --exclude-libs!
331
Yi Kong7786a342018-08-31 19:01:56 -0700332 ldflags: [
333 "-Wl,--exclude-libs=libgcc.a",
Yi Kongbffe6f12019-05-06 20:12:46 -0700334 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700335 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
336 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
337 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
338 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
339 ],
dimitry11da1dc2018-01-05 13:35:43 +0100340
341 // for x86, exclude libgcc_eh.a for the same reasons as above
342 arch: {
dimitry581723e2018-01-05 14:31:44 +0100343 arm: {
344 version_script: "linker.arm.map",
345 },
346 arm64: {
347 version_script: "linker.generic.map",
348 },
dimitry11da1dc2018-01-05 13:35:43 +0100349 x86: {
350 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100351 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100352 },
353 x86_64: {
354 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100355 version_script: "linker.generic.map",
356 },
357 mips: {
358 version_script: "linker.generic.map",
359 },
360 mips64: {
361 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100362 },
363 },
dimitry581723e2018-01-05 14:31:44 +0100364
365 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100366 cflags: [
367 "-Wall",
368 "-Wextra",
369 "-Wunused",
370 "-Werror",
371 ],
372 stl: "none",
373
374 name: "ld-android",
375 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900376 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100377
Ryan Prichard470b6662018-03-27 22:10:55 -0700378 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100379 system_shared_libs: [],
380
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800381 // Opt out of native_coverage when opting out of system_shared_libs
382 native_coverage: false,
383
dimitry11da1dc2018-01-05 13:35:43 +0100384 sanitize: {
385 never: true,
386 },
387}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800388
389cc_test {
390 name: "linker-unit-tests",
391
392 cflags: [
393 "-g",
394 "-Wall",
395 "-Wextra",
396 "-Wunused",
397 "-Werror",
398 ],
399
400 // We need to access Bionic private headers in the linker.
401 include_dirs: ["bionic/libc"],
402
403 srcs: [
404 // Tests.
405 "linker_block_allocator_test.cpp",
406 "linker_config_test.cpp",
407 "linked_list_test.cpp",
408 "linker_sleb128_test.cpp",
409 "linker_utils_test.cpp",
Ryan Prichardb5d9d2d2019-12-23 16:45:47 -0800410 "linker_gnu_hash_test.cpp",
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800411
412 // Parts of the linker that we're testing.
413 "linker_block_allocator.cpp",
414 "linker_config.cpp",
Ryan Prichard772affd2019-12-23 16:03:14 -0800415 "linker_debug.cpp",
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800416 "linker_test_globals.cpp",
417 "linker_utils.cpp",
418 ],
419
420 static_libs: [
421 "libasync_safe",
422 "libbase",
423 "liblog",
424 ],
Ryan Prichardb5d9d2d2019-12-23 16:45:47 -0800425
426 arch: {
427 arm: {
428 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
429 },
430 arm64: {
431 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
432 },
433 },
434}
435
436cc_benchmark {
437 name: "linker-benchmarks",
438
439 srcs: [
440 "linker_gnu_hash_benchmark.cpp",
441 ],
442
443 arch: {
444 arm: {
445 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
446 },
447 arm64: {
448 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
449 },
450 },
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800451}