blob: bb9d26d8886432c399bca45cb312e8369a0adfbe [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,
dimitry7f048802019-05-03 15:57:34 +02005 native_bridge_supported: true,
Colin Cross97f0aef2016-07-14 16:05:46 -07006
7 srcs: [
Colin Cross97f0aef2016-07-14 16:05:46 -07008 "linker_memory.cpp",
9 ],
Elliott Hughesd50a1de2018-02-05 17:30:57 -080010 cflags: [
11 "-Wall",
12 "-Werror",
13 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070014
15 // We need to access Bionic private headers in the linker.
16 include_dirs: ["bionic/libc"],
Christopher Ferris7a3681e2017-04-24 17:48:32 -070017
Elliott Hughes5e62b342018-10-25 11:00:00 -070018 static_libs: ["libasync_safe", "libbase"],
Colin Cross97f0aef2016-07-14 16:05:46 -070019}
20
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070021// This is used for bionic on (host) Linux to bootstrap our linker embedded into
22// a binary.
23//
24// Host bionic binaries do not have a PT_INTERP section, instead this gets
25// embedded as the entry point, and the linker is embedded as ELF sections in
26// each binary. There's a linker script that sets all of that up (generated by
27// extract_linker), and defines the extern symbols used in this file.
28cc_object {
29 name: "linker_wrapper",
30 host_supported: true,
31 device_supported: false,
32 target: {
Elliott Hughesd50a1de2018-02-05 17:30:57 -080033 linux_bionic: {
34 enabled: true,
35 },
36 linux_glibc: {
37 enabled: false,
38 },
39 darwin: {
40 enabled: false,
41 },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070042 },
43
44 cflags: [
45 "-fno-stack-protector",
46 "-Wstrict-overflow=5",
47 "-fvisibility=hidden",
48 "-Wall",
49 "-Wextra",
50 "-Wno-unused",
51 "-Werror",
52 ],
53
54 srcs: [
55 "linker_wrapper.cpp",
56 ],
57 arch: {
58 x86_64: {
59 srcs: ["arch/x86_64/begin.S"],
60 },
61 },
62
63 prefix_symbols: "__dlwrap_",
64
65 // We need to access Bionic private headers in the linker.
66 include_dirs: ["bionic/libc"],
67}
68
dimitryb8b3a762018-09-25 12:31:11 +020069filegroup {
70 name: "linker_sources",
Colin Cross97f0aef2016-07-14 16:05:46 -070071 srcs: [
72 "dlfcn.cpp",
73 "linker.cpp",
74 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -070075 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -070076 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -080077 "linker_config.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",
87 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070088 "linker_soinfo.cpp",
Ryan Prichard45d13492019-01-03 02:51:30 -080089 "linker_tls.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070090 "linker_utils.cpp",
91 "rt.cpp",
92 ],
dimitryb8b3a762018-09-25 12:31:11 +020093}
Colin Cross97f0aef2016-07-14 16:05:46 -070094
dimitryb8b3a762018-09-25 12:31:11 +020095filegroup {
96 name: "linker_sources_arm",
97 srcs: [
98 "arch/arm/begin.S",
dimitryb8b3a762018-09-25 12:31:11 +020099 ],
100}
101
102filegroup {
103 name: "linker_sources_arm64",
104 srcs: [
105 "arch/arm64/begin.S",
Ryan Prichardffaae702019-01-23 17:47:10 -0800106 "arch/arm64/tlsdesc_resolver.S",
dimitryb8b3a762018-09-25 12:31:11 +0200107 ],
108}
109
110filegroup {
111 name: "linker_sources_x86",
112 srcs: [
113 "arch/x86/begin.S",
114 ],
115}
116
117filegroup {
118 name: "linker_sources_x86_64",
119 srcs: [
120 "arch/x86_64/begin.S",
121 ],
122}
123
124filegroup {
125 name: "linker_sources_mips",
126 srcs: [
127 "arch/mips/begin.S",
128 "linker_mips.cpp",
129 ],
130}
131
132filegroup {
133 name: "linker_sources_mips64",
134 srcs: [
135 "arch/mips64/begin.S",
136 "linker_mips.cpp",
137 ],
138}
139
140filegroup {
141 name: "linker_version_script",
142 srcs: ["linker.generic.map"],
143}
144
145filegroup {
146 name: "linker_version_script_arm",
147 srcs: ["linker.arm.map"],
148}
149
150cc_defaults {
151 name: "linker_defaults",
Colin Cross97f0aef2016-07-14 16:05:46 -0700152 arch: {
153 arm: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700154 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700155 },
156 x86: {
Ryan Prichard7046f392018-05-24 14:07:27 -0700157 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700158 },
159 },
160
Colin Cross97f0aef2016-07-14 16:05:46 -0700161 // -shared is used to overwrite the -Bstatic and -static
162 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
163 // This dynamic linker is actually a shared object linked with static libraries.
164 ldflags: [
165 "-shared",
166 "-Wl,-Bsymbolic",
167 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100168 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700169 ],
170
171 cflags: [
172 "-fno-stack-protector",
173 "-Wstrict-overflow=5",
174 "-fvisibility=hidden",
175 "-Wall",
176 "-Wextra",
177 "-Wunused",
178 "-Werror",
179 ],
180
181 // TODO: split out the asflags.
182 asflags: [
183 "-fno-stack-protector",
184 "-Wstrict-overflow=5",
185 "-fvisibility=hidden",
186 "-Wall",
187 "-Wextra",
188 "-Wunused",
189 "-Werror",
190 ],
191
Jiyong Park02586a22017-05-20 01:01:24 +0900192 product_variables: {
193 debuggable: {
194 cppflags: ["-DUSE_LD_CONFIG_FILE"],
195 },
196 },
197
Colin Cross97f0aef2016-07-14 16:05:46 -0700198 cppflags: ["-Wold-style-cast"],
199
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800200 // we are going to link libc++_static manually because
201 // when stl is not set to "none" build system adds libdl
202 // to the list of static libraries which needs to be
203 // avoided in the case of building loader.
204 stl: "none",
205
Colin Cross97f0aef2016-07-14 16:05:46 -0700206 // we don't want crtbegin.o (because we have begin.o), so unset it
207 // just for this module
208 nocrt: true,
209
dimitryb8b3a762018-09-25 12:31:11 +0200210 static_executable: true,
211
212 // Leave the symbols in the shared library so that stack unwinders can produce
213 // meaningful name resolution.
214 strip: {
215 keep_symbols: true,
216 },
217
218 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
219 // looking up symbols in the linker by mistake.
220 prefix_symbols: "__dl_",
221
222 sanitize: {
223 hwaddress: false,
224 },
225}
226
227cc_binary {
228 defaults: ["linux_bionic_supported", "linker_defaults"],
229 srcs: [ ":linker_sources" ],
230
231 arch: {
232 arm: {
233 srcs: [ ":linker_sources_arm" ],
234 version_script: ":linker_version_script_arm",
Ryan Prichardd9a41152019-10-14 16:58:53 -0700235 static_libs: ["libunwind_llvm"],
dimitryb8b3a762018-09-25 12:31:11 +0200236 },
237 arm64: {
238 srcs: [":linker_sources_arm64"],
239 version_script: ":linker_version_script",
240 },
241 x86: {
242 srcs: [":linker_sources_x86"],
243 version_script: ":linker_version_script",
244 },
245 x86_64: {
246 srcs: [":linker_sources_x86_64"],
247 version_script: ":linker_version_script",
248 },
249 mips: {
250 srcs: [":linker_sources_mips"],
251 version_script: ":linker_version_script",
252 },
253 mips64: {
254 srcs: [":linker_sources_mips64"],
255 version_script: ":linker_version_script",
256 },
257 },
258
259 // We need to access Bionic private headers in the linker.
260 include_dirs: ["bionic/libc"],
261
Colin Cross97f0aef2016-07-14 16:05:46 -0700262 static_libs: [
263 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800264 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700265 "libziparchive",
Colin Cross97f0aef2016-07-14 16:05:46 -0700266 "libbase",
267 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800268
Dan Willemsen4326d842017-05-07 13:07:41 -0700269 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800270
Colin Cross97f0aef2016-07-14 16:05:46 -0700271 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800272 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700273
274 // Important: The liblinker_malloc should be the last library in the list
275 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800276 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700277 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700278
Ryan Prichardd9a41152019-10-14 16:58:53 -0700279 // Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a
280 // definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak
281 // reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition
282 // of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a
283 // non-relative dynamic relocation in the linker binary, which complicates linker startup.
284 //
285 // This line should be unnecessary because the linker's dependency on libunwind_llvm.a should
286 // override libgcc.a, but this line provides a simpler guarantee. It can be removed once the
287 // linker stops linking against libgcc.a's arm32 unwinder.
288 whole_static_libs: ["libc_unwind_static"],
289
Colin Cross97f0aef2016-07-14 16:05:46 -0700290 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800291 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900292 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700293 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900294 lib32: {
295 cflags: ["-DLIB_PATH=\"lib\""],
296 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700297 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900298 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700299 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800300 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700301 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800302 system_shared_libs: [],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800303
304 // Opt out of native_coverage when opting out of system_shared_libs
305 native_coverage: false,
306
Colin Cross97f0aef2016-07-14 16:05:46 -0700307 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800308 android: {
Dan Albert4ea19212019-07-23 13:31:14 -0700309 static_libs: [
310 "libc++demangle",
311 "libdebuggerd_handler_fallback",
312 ],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800313 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700314 },
315 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800316 xom: false,
Jiyong Parke87e0dc2019-10-02 17:09:33 +0900317
318 apex_available: [
319 "//apex_available:platform",
320 "com.android.runtime",
321 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700322}
dimitry11da1dc2018-01-05 13:35:43 +0100323
Elliott Hughes90f96b92019-05-09 15:56:39 -0700324sh_binary {
325 name: "ldd",
326 src: "ldd",
327}
328
dimitry11da1dc2018-01-05 13:35:43 +0100329cc_library {
330 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
331 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
332 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
333 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
334 // we use this property to make sure libc.so has its own copy of the code from
335 // libgcc.a it uses.
336 //
337 // DO NOT REMOVE --exclude-libs!
338
Yi Kong7786a342018-08-31 19:01:56 -0700339 ldflags: [
340 "-Wl,--exclude-libs=libgcc.a",
Yi Kong7ac2afb2019-05-06 16:23:10 -0700341 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700342 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
343 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
344 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
345 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
346 ],
dimitry11da1dc2018-01-05 13:35:43 +0100347
348 // for x86, exclude libgcc_eh.a for the same reasons as above
349 arch: {
dimitry581723e2018-01-05 14:31:44 +0100350 arm: {
351 version_script: "linker.arm.map",
352 },
353 arm64: {
354 version_script: "linker.generic.map",
355 },
dimitry11da1dc2018-01-05 13:35:43 +0100356 x86: {
357 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100358 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100359 },
360 x86_64: {
361 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100362 version_script: "linker.generic.map",
363 },
364 mips: {
365 version_script: "linker.generic.map",
366 },
367 mips64: {
368 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100369 },
370 },
dimitry581723e2018-01-05 14:31:44 +0100371
372 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100373 cflags: [
374 "-Wall",
375 "-Wextra",
376 "-Wunused",
377 "-Werror",
378 ],
379 stl: "none",
380
381 name: "ld-android",
382 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900383 recovery_available: true,
dimitry7f048802019-05-03 15:57:34 +0200384 native_bridge_supported: true,
dimitry11da1dc2018-01-05 13:35:43 +0100385
Ryan Prichard470b6662018-03-27 22:10:55 -0700386 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100387 system_shared_libs: [],
388
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800389 // Opt out of native_coverage when opting out of system_shared_libs
390 native_coverage: false,
391
dimitry11da1dc2018-01-05 13:35:43 +0100392 sanitize: {
393 never: true,
394 },
Jiyong Parke87e0dc2019-10-02 17:09:33 +0900395
396 apex_available: [
397 "//apex_available:platform",
398 "com.android.runtime",
399 ],
dimitry11da1dc2018-01-05 13:35:43 +0100400}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800401
402cc_test {
403 name: "linker-unit-tests",
404
405 cflags: [
406 "-g",
407 "-Wall",
408 "-Wextra",
409 "-Wunused",
410 "-Werror",
411 ],
412
413 // We need to access Bionic private headers in the linker.
414 include_dirs: ["bionic/libc"],
415
416 srcs: [
417 // Tests.
418 "linker_block_allocator_test.cpp",
419 "linker_config_test.cpp",
420 "linked_list_test.cpp",
421 "linker_sleb128_test.cpp",
422 "linker_utils_test.cpp",
423
424 // Parts of the linker that we're testing.
425 "linker_block_allocator.cpp",
426 "linker_config.cpp",
427 "linker_test_globals.cpp",
428 "linker_utils.cpp",
429 ],
430
431 static_libs: [
432 "libasync_safe",
433 "libbase",
434 "liblog",
435 ],
436}