blob: a51b73fe4ddbf8bfbedead3b67a0c134660f4dc7 [file] [log] [blame]
Ryan Prichard80e40f02019-10-31 19:54:46 -07001// ========================================================
2// linker_wrapper - Linux Bionic (on the host)
3// ========================================================
Colin Cross97f0aef2016-07-14 16:05:46 -07004
Dan Willemsen7ccc50d2017-09-18 21:28:14 -07005// This is used for bionic on (host) Linux to bootstrap our linker embedded into
6// a binary.
7//
8// Host bionic binaries do not have a PT_INTERP section, instead this gets
9// embedded as the entry point, and the linker is embedded as ELF sections in
10// each binary. There's a linker script that sets all of that up (generated by
11// extract_linker), and defines the extern symbols used in this file.
12cc_object {
13 name: "linker_wrapper",
14 host_supported: true,
15 device_supported: false,
16 target: {
Elliott Hughesd50a1de2018-02-05 17:30:57 -080017 linux_bionic: {
18 enabled: true,
19 },
20 linux_glibc: {
21 enabled: false,
22 },
23 darwin: {
24 enabled: false,
25 },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070026 },
27
28 cflags: [
29 "-fno-stack-protector",
30 "-Wstrict-overflow=5",
31 "-fvisibility=hidden",
32 "-Wall",
33 "-Wextra",
34 "-Wno-unused",
35 "-Werror",
36 ],
37
38 srcs: [
39 "linker_wrapper.cpp",
40 ],
41 arch: {
Jiyong Park3b47d602020-09-18 16:15:53 +090042 arm64: {
43 srcs: ["arch/arm64/begin.S"],
44 },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070045 x86_64: {
46 srcs: ["arch/x86_64/begin.S"],
47 },
48 },
49
50 prefix_symbols: "__dlwrap_",
51
Martin Stjernholm82d84bc2020-04-06 20:32:09 +010052 header_libs: ["libc_headers"],
53
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070054 // We need to access Bionic private headers in the linker.
55 include_dirs: ["bionic/libc"],
56}
57
Ryan Prichard80e40f02019-10-31 19:54:46 -070058// ========================================================
59// linker default configuration
60// ========================================================
61
62// Configuration for the linker binary and any of its static libraries.
63cc_defaults {
64 name: "linker_defaults",
65 arch: {
66 arm: {
67 cflags: ["-D__work_around_b_24465209__"],
68 },
69 x86: {
70 cflags: ["-D__work_around_b_24465209__"],
71 },
72 },
73
74 cflags: [
75 "-fno-stack-protector",
76 "-Wstrict-overflow=5",
77 "-fvisibility=hidden",
78 "-Wall",
79 "-Wextra",
80 "-Wunused",
81 "-Werror",
82 ],
83
84 // TODO: split out the asflags.
85 asflags: [
86 "-fno-stack-protector",
87 "-Wstrict-overflow=5",
88 "-fvisibility=hidden",
89 "-Wall",
90 "-Wextra",
91 "-Wunused",
92 "-Werror",
93 ],
94
95 product_variables: {
96 debuggable: {
97 cppflags: ["-DUSE_LD_CONFIG_FILE"],
98 },
99 },
100
101 cppflags: ["-Wold-style-cast"],
102
103 static_libs: [
104 "libziparchive",
105 "libbase",
106 "libz",
107
108 "libasync_safe",
109
110 "liblog",
111 ],
112
113 // We need to access Bionic private headers in the linker.
114 include_dirs: ["bionic/libc"],
115}
116
117// ========================================================
118// linker components
119// ========================================================
120
121// Enable a module on all targets the linker runs on (ordinary Android targets, Linux Bionic, and
122// native bridge implementations).
123cc_defaults {
124 name: "linker_all_targets",
125 defaults: ["linux_bionic_supported"],
126 recovery_available: true,
127 native_bridge_supported: true,
128}
129
130cc_library_static {
Ryan Prichard249757b2019-11-01 17:18:28 -0700131 name: "liblinker_main",
132 defaults: ["linker_defaults", "linker_all_targets"],
133 srcs: ["linker_main.cpp"],
134
135 // Ensure that the compiler won't insert string function calls before ifuncs are resolved.
136 cflags: ["-ffreestanding"],
137}
138
139cc_library_static {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700140 name: "liblinker_malloc",
141 defaults: ["linker_defaults", "linker_all_targets"],
142 srcs: ["linker_memory.cpp"],
143}
144
145cc_library_static {
146 name: "liblinker_debuggerd_stub",
147 defaults: ["linker_defaults", "linker_all_targets"],
148 srcs: ["linker_debuggerd_stub.cpp"],
149}
150
151// ========================================================
152// template for the linker binary
153// ========================================================
154
dimitryb8b3a762018-09-25 12:31:11 +0200155filegroup {
156 name: "linker_sources",
Colin Cross97f0aef2016-07-14 16:05:46 -0700157 srcs: [
158 "dlfcn.cpp",
159 "linker.cpp",
160 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -0700161 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -0700162 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -0800163 "linker_config.cpp",
Ryan Prichard551565e2019-12-23 16:03:14 -0800164 "linker_debug.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700165 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -0700166 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700167 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800168 "linker_libcxx_support.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -0700169 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700170 "linker_logger.cpp",
171 "linker_mapped_file_fragment.cpp",
172 "linker_phdr.cpp",
Ryan Prichard339ecef2020-01-02 16:36:06 -0800173 "linker_relocate.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700174 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -0700175 "linker_soinfo.cpp",
Ryan Prichard45d13492019-01-03 02:51:30 -0800176 "linker_tls.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700177 "linker_utils.cpp",
178 "rt.cpp",
179 ],
dimitryb8b3a762018-09-25 12:31:11 +0200180}
Colin Cross97f0aef2016-07-14 16:05:46 -0700181
dimitryb8b3a762018-09-25 12:31:11 +0200182filegroup {
183 name: "linker_sources_arm",
184 srcs: [
185 "arch/arm/begin.S",
Ryan Prichard129f7a12019-12-23 16:45:47 -0800186 "arch/arm_neon/linker_gnu_hash_neon.cpp",
dimitryb8b3a762018-09-25 12:31:11 +0200187 ],
188}
189
190filegroup {
191 name: "linker_sources_arm64",
192 srcs: [
193 "arch/arm64/begin.S",
Ryan Prichardffaae702019-01-23 17:47:10 -0800194 "arch/arm64/tlsdesc_resolver.S",
Ryan Prichard129f7a12019-12-23 16:45:47 -0800195 "arch/arm_neon/linker_gnu_hash_neon.cpp",
dimitryb8b3a762018-09-25 12:31:11 +0200196 ],
197}
198
199filegroup {
200 name: "linker_sources_x86",
201 srcs: [
202 "arch/x86/begin.S",
203 ],
204}
205
206filegroup {
207 name: "linker_sources_x86_64",
208 srcs: [
209 "arch/x86_64/begin.S",
210 ],
211}
212
dimitryb8b3a762018-09-25 12:31:11 +0200213cc_defaults {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700214 name: "linker_version_script_overlay",
215 arch: {
216 arm: { version_script: "linker.arm.map" },
217 arm64: { version_script: "linker.generic.map" },
218 x86: { version_script: "linker.generic.map" },
219 x86_64: { version_script: "linker.generic.map" },
Ryan Prichard80e40f02019-10-31 19:54:46 -0700220 },
221}
222
223// A template for the linker binary. May be inherited by native bridge implementations.
224cc_defaults {
225 name: "linker_bin_template",
226 defaults: ["linker_defaults"],
227
228 srcs: [":linker_sources"],
229
Colin Cross97f0aef2016-07-14 16:05:46 -0700230 arch: {
231 arm: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700232 srcs: [":linker_sources_arm"],
233 static_libs: ["libunwind_llvm"],
234 },
235 arm64: {
236 srcs: [":linker_sources_arm64"],
Peter Collingbournef2b1e032019-12-10 17:41:16 -0800237 static_libs: ["libgcc_stripped"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700238 },
239 x86: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700240 srcs: [":linker_sources_x86"],
Peter Collingbournef2b1e032019-12-10 17:41:16 -0800241 static_libs: ["libgcc_stripped"],
Ryan Prichard80e40f02019-10-31 19:54:46 -0700242 },
243 x86_64: {
244 srcs: [":linker_sources_x86_64"],
Peter Collingbournef2b1e032019-12-10 17:41:16 -0800245 static_libs: ["libgcc_stripped"],
Ryan Prichard80e40f02019-10-31 19:54:46 -0700246 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700247 },
248
Ryan Prichard80e40f02019-10-31 19:54:46 -0700249 // -shared is used to overwrite the -Bstatic and -static flags triggered by enabling
250 // static_executable. This dynamic linker is actually a shared object linked with static
251 // libraries.
Colin Cross97f0aef2016-07-14 16:05:46 -0700252 ldflags: [
253 "-shared",
254 "-Wl,-Bsymbolic",
255 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100256 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700257 ],
258
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800259 // we are going to link libc++_static manually because
260 // when stl is not set to "none" build system adds libdl
261 // to the list of static libraries which needs to be
262 // avoided in the case of building loader.
263 stl: "none",
264
Colin Cross97f0aef2016-07-14 16:05:46 -0700265 // we don't want crtbegin.o (because we have begin.o), so unset it
266 // just for this module
267 nocrt: true,
268
dimitryb8b3a762018-09-25 12:31:11 +0200269 static_executable: true,
270
271 // Leave the symbols in the shared library so that stack unwinders can produce
272 // meaningful name resolution.
273 strip: {
274 keep_symbols: true,
275 },
276
277 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
278 // looking up symbols in the linker by mistake.
279 prefix_symbols: "__dl_",
280
281 sanitize: {
282 hwaddress: false,
283 },
dimitryb8b3a762018-09-25 12:31:11 +0200284
Colin Cross97f0aef2016-07-14 16:05:46 -0700285 static_libs: [
Ryan Prichard249757b2019-11-01 17:18:28 -0700286 "liblinker_main",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700287 "liblinker_malloc",
288
289 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700290 "libc_nomalloc",
Ryan Prichard249757b2019-11-01 17:18:28 -0700291 "libc_dynamic_dispatch",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800292 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700293 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700294
Ryan Prichardd9a41152019-10-14 16:58:53 -0700295 // Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a
296 // definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak
297 // reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition
298 // of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a
299 // non-relative dynamic relocation in the linker binary, which complicates linker startup.
300 //
301 // This line should be unnecessary because the linker's dependency on libunwind_llvm.a should
302 // override libgcc.a, but this line provides a simpler guarantee. It can be removed once the
303 // linker stops linking against libgcc.a's arm32 unwinder.
304 whole_static_libs: ["libc_unwind_static"],
305
Ryan Prichard80e40f02019-10-31 19:54:46 -0700306 system_shared_libs: [],
307
308 // Opt out of native_coverage when opting out of system_shared_libs
309 native_coverage: false,
310}
311
312// ========================================================
313// linker[_asan][64] binary
314// ========================================================
315
316cc_binary {
Colin Cross97f0aef2016-07-14 16:05:46 -0700317 name: "linker",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700318 defaults: [
319 "linker_bin_template",
320 "linux_bionic_supported",
321 "linker_version_script_overlay",
322 ],
323
Victor Khimenkod15229d2020-05-14 22:14:45 +0200324 srcs: [
325 "linker_translate_path.cpp",
326 ],
327
Colin Cross10fffb42016-12-08 09:57:35 -0800328 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700329 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700330 lib64: {
331 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800332 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700333 },
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800334
Ryan Prichard80e40f02019-10-31 19:54:46 -0700335 compile_multilib: "both",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700336
337 recovery_available: true,
338 apex_available: [
339 "//apex_available:platform",
340 "com.android.runtime",
341 ],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800342
Colin Cross97f0aef2016-07-14 16:05:46 -0700343 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800344 android: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700345 srcs: [
346 "linker_debuggerd_android.cpp",
347 ],
Dan Albert4ea19212019-07-23 13:31:14 -0700348 static_libs: [
349 "libc++demangle",
350 "libdebuggerd_handler_fallback",
351 ],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800352 },
Ryan Prichard80e40f02019-10-31 19:54:46 -0700353 linux_bionic: {
354 static_libs: [
355 "liblinker_debuggerd_stub",
356 ],
357 }
Colin Cross97f0aef2016-07-14 16:05:46 -0700358 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700359}
dimitry11da1dc2018-01-05 13:35:43 +0100360
Ryan Prichard80e40f02019-10-31 19:54:46 -0700361// ========================================================
362// assorted modules
363// ========================================================
364
Elliott Hughes90f96b92019-05-09 15:56:39 -0700365sh_binary {
366 name: "ldd",
367 src: "ldd",
368}
369
dimitry11da1dc2018-01-05 13:35:43 +0100370cc_library {
371 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
372 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
373 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
374 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
375 // we use this property to make sure libc.so has its own copy of the code from
376 // libgcc.a it uses.
377 //
378 // DO NOT REMOVE --exclude-libs!
379
Yi Kong7786a342018-08-31 19:01:56 -0700380 ldflags: [
381 "-Wl,--exclude-libs=libgcc.a",
Yi Kong7ac2afb2019-05-06 16:23:10 -0700382 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700383 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
384 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
385 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
386 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
387 ],
dimitry11da1dc2018-01-05 13:35:43 +0100388
389 // for x86, exclude libgcc_eh.a for the same reasons as above
390 arch: {
391 x86: {
392 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
393 },
394 x86_64: {
395 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
396 },
397 },
dimitry581723e2018-01-05 14:31:44 +0100398
399 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100400 cflags: [
401 "-Wall",
402 "-Wextra",
403 "-Wunused",
404 "-Werror",
405 ],
406 stl: "none",
407
408 name: "ld-android",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700409 defaults: ["linux_bionic_supported", "linker_version_script_overlay"],
Yifan Hong5a39cee2020-01-21 16:43:56 -0800410 ramdisk_available: true,
Jiyong Park5603c6e2018-04-27 21:53:11 +0900411 recovery_available: true,
dimitry7f048802019-05-03 15:57:34 +0200412 native_bridge_supported: true,
dimitry11da1dc2018-01-05 13:35:43 +0100413
Ryan Prichard470b6662018-03-27 22:10:55 -0700414 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100415 system_shared_libs: [],
Martin Stjernholm82d84bc2020-04-06 20:32:09 +0100416 header_libs: ["libc_headers"],
dimitry11da1dc2018-01-05 13:35:43 +0100417
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800418 // Opt out of native_coverage when opting out of system_shared_libs
419 native_coverage: false,
420
dimitry11da1dc2018-01-05 13:35:43 +0100421 sanitize: {
422 never: true,
423 },
Jiyong Parke87e0dc2019-10-02 17:09:33 +0900424
425 apex_available: [
426 "//apex_available:platform",
427 "com.android.runtime",
428 ],
dimitry11da1dc2018-01-05 13:35:43 +0100429}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800430
431cc_test {
432 name: "linker-unit-tests",
433
434 cflags: [
435 "-g",
436 "-Wall",
437 "-Wextra",
438 "-Wunused",
439 "-Werror",
440 ],
441
442 // We need to access Bionic private headers in the linker.
443 include_dirs: ["bionic/libc"],
444
445 srcs: [
446 // Tests.
447 "linker_block_allocator_test.cpp",
448 "linker_config_test.cpp",
449 "linked_list_test.cpp",
450 "linker_sleb128_test.cpp",
451 "linker_utils_test.cpp",
Ryan Prichard129f7a12019-12-23 16:45:47 -0800452 "linker_gnu_hash_test.cpp",
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800453
454 // Parts of the linker that we're testing.
455 "linker_block_allocator.cpp",
456 "linker_config.cpp",
Ryan Prichard551565e2019-12-23 16:03:14 -0800457 "linker_debug.cpp",
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800458 "linker_test_globals.cpp",
459 "linker_utils.cpp",
460 ],
461
462 static_libs: [
463 "libasync_safe",
464 "libbase",
465 "liblog",
466 ],
Ryan Prichard129f7a12019-12-23 16:45:47 -0800467
468 arch: {
469 arm: {
470 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
471 },
472 arm64: {
473 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
474 },
475 },
476}
477
478cc_benchmark {
479 name: "linker-benchmarks",
480
481 srcs: [
482 "linker_gnu_hash_benchmark.cpp",
483 ],
484
485 arch: {
486 arm: {
487 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
488 },
489 arm64: {
490 srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
491 },
492 },
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800493}