blob: 8061f401ddce8fbce31f4762de60ca3bb7326fbf [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: {
42 x86_64: {
43 srcs: ["arch/x86_64/begin.S"],
44 },
45 },
46
47 prefix_symbols: "__dlwrap_",
48
49 // We need to access Bionic private headers in the linker.
50 include_dirs: ["bionic/libc"],
51}
52
Ryan Prichard80e40f02019-10-31 19:54:46 -070053// ========================================================
54// linker default configuration
55// ========================================================
56
57// Configuration for the linker binary and any of its static libraries.
58cc_defaults {
59 name: "linker_defaults",
60 arch: {
61 arm: {
62 cflags: ["-D__work_around_b_24465209__"],
63 },
64 x86: {
65 cflags: ["-D__work_around_b_24465209__"],
66 },
67 },
68
69 cflags: [
70 "-fno-stack-protector",
71 "-Wstrict-overflow=5",
72 "-fvisibility=hidden",
73 "-Wall",
74 "-Wextra",
75 "-Wunused",
76 "-Werror",
77 ],
78
79 // TODO: split out the asflags.
80 asflags: [
81 "-fno-stack-protector",
82 "-Wstrict-overflow=5",
83 "-fvisibility=hidden",
84 "-Wall",
85 "-Wextra",
86 "-Wunused",
87 "-Werror",
88 ],
89
90 product_variables: {
91 debuggable: {
92 cppflags: ["-DUSE_LD_CONFIG_FILE"],
93 },
94 },
95
96 cppflags: ["-Wold-style-cast"],
97
98 static_libs: [
99 "libziparchive",
100 "libbase",
101 "libz",
102
103 "libasync_safe",
104
105 "liblog",
106 ],
107
108 // We need to access Bionic private headers in the linker.
109 include_dirs: ["bionic/libc"],
110}
111
112// ========================================================
113// linker components
114// ========================================================
115
116// Enable a module on all targets the linker runs on (ordinary Android targets, Linux Bionic, and
117// native bridge implementations).
118cc_defaults {
119 name: "linker_all_targets",
120 defaults: ["linux_bionic_supported"],
121 recovery_available: true,
122 native_bridge_supported: true,
123}
124
125cc_library_static {
126 name: "liblinker_malloc",
127 defaults: ["linker_defaults", "linker_all_targets"],
128 srcs: ["linker_memory.cpp"],
129}
130
131cc_library_static {
132 name: "liblinker_debuggerd_stub",
133 defaults: ["linker_defaults", "linker_all_targets"],
134 srcs: ["linker_debuggerd_stub.cpp"],
135}
136
137// ========================================================
138// template for the linker binary
139// ========================================================
140
dimitryb8b3a762018-09-25 12:31:11 +0200141filegroup {
142 name: "linker_sources",
Colin Cross97f0aef2016-07-14 16:05:46 -0700143 srcs: [
144 "dlfcn.cpp",
145 "linker.cpp",
146 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -0700147 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -0700148 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -0800149 "linker_config.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700150 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -0700151 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700152 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800153 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -0700154 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -0700155 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700156 "linker_logger.cpp",
157 "linker_mapped_file_fragment.cpp",
158 "linker_phdr.cpp",
159 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -0700160 "linker_soinfo.cpp",
Ryan Prichard45d13492019-01-03 02:51:30 -0800161 "linker_tls.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -0700162 "linker_utils.cpp",
163 "rt.cpp",
164 ],
dimitryb8b3a762018-09-25 12:31:11 +0200165}
Colin Cross97f0aef2016-07-14 16:05:46 -0700166
dimitryb8b3a762018-09-25 12:31:11 +0200167filegroup {
168 name: "linker_sources_arm",
169 srcs: [
170 "arch/arm/begin.S",
dimitryb8b3a762018-09-25 12:31:11 +0200171 ],
172}
173
174filegroup {
175 name: "linker_sources_arm64",
176 srcs: [
177 "arch/arm64/begin.S",
Ryan Prichardffaae702019-01-23 17:47:10 -0800178 "arch/arm64/tlsdesc_resolver.S",
dimitryb8b3a762018-09-25 12:31:11 +0200179 ],
180}
181
182filegroup {
183 name: "linker_sources_x86",
184 srcs: [
185 "arch/x86/begin.S",
186 ],
187}
188
189filegroup {
190 name: "linker_sources_x86_64",
191 srcs: [
192 "arch/x86_64/begin.S",
193 ],
194}
195
196filegroup {
197 name: "linker_sources_mips",
198 srcs: [
199 "arch/mips/begin.S",
200 "linker_mips.cpp",
201 ],
202}
203
204filegroup {
205 name: "linker_sources_mips64",
206 srcs: [
207 "arch/mips64/begin.S",
208 "linker_mips.cpp",
209 ],
210}
211
dimitryb8b3a762018-09-25 12:31:11 +0200212cc_defaults {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700213 name: "linker_version_script_overlay",
214 arch: {
215 arm: { version_script: "linker.arm.map" },
216 arm64: { version_script: "linker.generic.map" },
217 x86: { version_script: "linker.generic.map" },
218 x86_64: { version_script: "linker.generic.map" },
219 mips: { version_script: "linker.generic.map" },
220 mips64: { version_script: "linker.generic.map" },
221 },
222}
223
224// A template for the linker binary. May be inherited by native bridge implementations.
225cc_defaults {
226 name: "linker_bin_template",
227 defaults: ["linker_defaults"],
228
229 srcs: [":linker_sources"],
230
Colin Cross97f0aef2016-07-14 16:05:46 -0700231 arch: {
232 arm: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700233 srcs: [":linker_sources_arm"],
234 static_libs: ["libunwind_llvm"],
235 },
236 arm64: {
237 srcs: [":linker_sources_arm64"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700238 },
239 x86: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700240 srcs: [":linker_sources_x86"],
241 },
242 x86_64: {
243 srcs: [":linker_sources_x86_64"],
244 },
245 mips: {
246 srcs: [":linker_sources_mips"],
247 },
248 mips64: {
249 srcs: [":linker_sources_mips64"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700250 },
251 },
252
Ryan Prichard80e40f02019-10-31 19:54:46 -0700253 // -shared is used to overwrite the -Bstatic and -static flags triggered by enabling
254 // static_executable. This dynamic linker is actually a shared object linked with static
255 // libraries.
Colin Cross97f0aef2016-07-14 16:05:46 -0700256 ldflags: [
257 "-shared",
258 "-Wl,-Bsymbolic",
259 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100260 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700261 ],
262
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800263 // we are going to link libc++_static manually because
264 // when stl is not set to "none" build system adds libdl
265 // to the list of static libraries which needs to be
266 // avoided in the case of building loader.
267 stl: "none",
268
Colin Cross97f0aef2016-07-14 16:05:46 -0700269 // we don't want crtbegin.o (because we have begin.o), so unset it
270 // just for this module
271 nocrt: true,
272
dimitryb8b3a762018-09-25 12:31:11 +0200273 static_executable: true,
274
275 // Leave the symbols in the shared library so that stack unwinders can produce
276 // meaningful name resolution.
277 strip: {
278 keep_symbols: true,
279 },
280
281 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
282 // looking up symbols in the linker by mistake.
283 prefix_symbols: "__dl_",
284
285 sanitize: {
286 hwaddress: false,
287 },
dimitryb8b3a762018-09-25 12:31:11 +0200288
Colin Cross97f0aef2016-07-14 16:05:46 -0700289 static_libs: [
Ryan Prichard80e40f02019-10-31 19:54:46 -0700290 "liblinker_malloc",
291
292 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700293 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800294 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700295 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700296
Ryan Prichardd9a41152019-10-14 16:58:53 -0700297 // Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a
298 // definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak
299 // reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition
300 // of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a
301 // non-relative dynamic relocation in the linker binary, which complicates linker startup.
302 //
303 // This line should be unnecessary because the linker's dependency on libunwind_llvm.a should
304 // override libgcc.a, but this line provides a simpler guarantee. It can be removed once the
305 // linker stops linking against libgcc.a's arm32 unwinder.
306 whole_static_libs: ["libc_unwind_static"],
307
Ryan Prichard80e40f02019-10-31 19:54:46 -0700308 system_shared_libs: [],
309
310 // Opt out of native_coverage when opting out of system_shared_libs
311 native_coverage: false,
312}
313
314// ========================================================
315// linker[_asan][64] binary
316// ========================================================
317
318cc_binary {
Colin Cross97f0aef2016-07-14 16:05:46 -0700319 name: "linker",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700320 defaults: [
321 "linker_bin_template",
322 "linux_bionic_supported",
323 "linker_version_script_overlay",
324 ],
325
Colin Cross10fffb42016-12-08 09:57:35 -0800326 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700327 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900328 lib32: {
329 cflags: ["-DLIB_PATH=\"lib\""],
330 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700331 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900332 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700333 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800334 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700335 },
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800336
Ryan Prichard80e40f02019-10-31 19:54:46 -0700337 compile_multilib: "both",
338 xom: false,
339
340 recovery_available: true,
341 apex_available: [
342 "//apex_available:platform",
343 "com.android.runtime",
344 ],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800345
Colin Cross97f0aef2016-07-14 16:05:46 -0700346 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800347 android: {
Ryan Prichard80e40f02019-10-31 19:54:46 -0700348 srcs: [
349 "linker_debuggerd_android.cpp",
350 ],
Dan Albert4ea19212019-07-23 13:31:14 -0700351 static_libs: [
352 "libc++demangle",
353 "libdebuggerd_handler_fallback",
354 ],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800355 },
Ryan Prichard80e40f02019-10-31 19:54:46 -0700356 linux_bionic: {
357 static_libs: [
358 "liblinker_debuggerd_stub",
359 ],
360 }
Colin Cross97f0aef2016-07-14 16:05:46 -0700361 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700362}
dimitry11da1dc2018-01-05 13:35:43 +0100363
Ryan Prichard80e40f02019-10-31 19:54:46 -0700364// ========================================================
365// assorted modules
366// ========================================================
367
Elliott Hughes90f96b92019-05-09 15:56:39 -0700368sh_binary {
369 name: "ldd",
370 src: "ldd",
371}
372
dimitry11da1dc2018-01-05 13:35:43 +0100373cc_library {
374 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
375 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
376 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
377 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
378 // we use this property to make sure libc.so has its own copy of the code from
379 // libgcc.a it uses.
380 //
381 // DO NOT REMOVE --exclude-libs!
382
Yi Kong7786a342018-08-31 19:01:56 -0700383 ldflags: [
384 "-Wl,--exclude-libs=libgcc.a",
Yi Kong7ac2afb2019-05-06 16:23:10 -0700385 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700386 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
387 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
388 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
389 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
390 ],
dimitry11da1dc2018-01-05 13:35:43 +0100391
392 // for x86, exclude libgcc_eh.a for the same reasons as above
393 arch: {
394 x86: {
395 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
396 },
397 x86_64: {
398 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
399 },
400 },
dimitry581723e2018-01-05 14:31:44 +0100401
402 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100403 cflags: [
404 "-Wall",
405 "-Wextra",
406 "-Wunused",
407 "-Werror",
408 ],
409 stl: "none",
410
411 name: "ld-android",
Ryan Prichard80e40f02019-10-31 19:54:46 -0700412 defaults: ["linux_bionic_supported", "linker_version_script_overlay"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900413 recovery_available: true,
dimitry7f048802019-05-03 15:57:34 +0200414 native_bridge_supported: true,
dimitry11da1dc2018-01-05 13:35:43 +0100415
Ryan Prichard470b6662018-03-27 22:10:55 -0700416 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100417 system_shared_libs: [],
418
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800419 // Opt out of native_coverage when opting out of system_shared_libs
420 native_coverage: false,
421
dimitry11da1dc2018-01-05 13:35:43 +0100422 sanitize: {
423 never: true,
424 },
Jiyong Parke87e0dc2019-10-02 17:09:33 +0900425
426 apex_available: [
427 "//apex_available:platform",
428 "com.android.runtime",
429 ],
dimitry11da1dc2018-01-05 13:35:43 +0100430}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800431
432cc_test {
433 name: "linker-unit-tests",
434
435 cflags: [
436 "-g",
437 "-Wall",
438 "-Wextra",
439 "-Wunused",
440 "-Werror",
441 ],
442
443 // We need to access Bionic private headers in the linker.
444 include_dirs: ["bionic/libc"],
445
446 srcs: [
447 // Tests.
448 "linker_block_allocator_test.cpp",
449 "linker_config_test.cpp",
450 "linked_list_test.cpp",
451 "linker_sleb128_test.cpp",
452 "linker_utils_test.cpp",
453
454 // Parts of the linker that we're testing.
455 "linker_block_allocator.cpp",
456 "linker_config.cpp",
457 "linker_test_globals.cpp",
458 "linker_utils.cpp",
459 ],
460
461 static_libs: [
462 "libasync_safe",
463 "libbase",
464 "liblog",
465 ],
466}