blob: 1880c27ec5ce5faa31137d0e4ea007a77a1f12fc [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",
99 "linker_exidx_static.c",
100 ],
101}
102
103filegroup {
104 name: "linker_sources_arm64",
105 srcs: [
106 "arch/arm64/begin.S",
Ryan Prichardffaae702019-01-23 17:47:10 -0800107 "arch/arm64/tlsdesc_resolver.S",
dimitryb8b3a762018-09-25 12:31:11 +0200108 ],
109}
110
111filegroup {
112 name: "linker_sources_x86",
113 srcs: [
114 "arch/x86/begin.S",
115 ],
116}
117
118filegroup {
119 name: "linker_sources_x86_64",
120 srcs: [
121 "arch/x86_64/begin.S",
122 ],
123}
124
125filegroup {
126 name: "linker_sources_mips",
127 srcs: [
128 "arch/mips/begin.S",
129 "linker_mips.cpp",
130 ],
131}
132
133filegroup {
134 name: "linker_sources_mips64",
135 srcs: [
136 "arch/mips64/begin.S",
137 "linker_mips.cpp",
138 ],
139}
140
141filegroup {
142 name: "linker_version_script",
143 srcs: ["linker.generic.map"],
144}
145
146filegroup {
147 name: "linker_version_script_arm",
148 srcs: ["linker.arm.map"],
149}
150
151cc_defaults {
152 name: "linker_defaults",
Colin Cross97f0aef2016-07-14 16:05:46 -0700153 arch: {
154 arm: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700155 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700156 },
157 x86: {
Ryan Prichard7046f392018-05-24 14:07:27 -0700158 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700159 },
160 },
161
Colin Cross97f0aef2016-07-14 16:05:46 -0700162 // -shared is used to overwrite the -Bstatic and -static
163 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
164 // This dynamic linker is actually a shared object linked with static libraries.
165 ldflags: [
166 "-shared",
167 "-Wl,-Bsymbolic",
168 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100169 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700170 ],
171
172 cflags: [
173 "-fno-stack-protector",
174 "-Wstrict-overflow=5",
175 "-fvisibility=hidden",
176 "-Wall",
177 "-Wextra",
178 "-Wunused",
179 "-Werror",
Ryan Prichard9ee80692019-01-15 16:10:36 -0800180
181 // Define _USING_LIBCXX so <stdatomic.h> defers to the <atomic> header. When a Soong module
182 // uses the platform libc++, Soong automatically passes this macro, but the dynamic linker
183 // links against libc++ manually.
184 "-D_USING_LIBCXX",
Colin Cross97f0aef2016-07-14 16:05:46 -0700185 ],
186
187 // TODO: split out the asflags.
188 asflags: [
189 "-fno-stack-protector",
190 "-Wstrict-overflow=5",
191 "-fvisibility=hidden",
192 "-Wall",
193 "-Wextra",
194 "-Wunused",
195 "-Werror",
196 ],
197
Jiyong Park02586a22017-05-20 01:01:24 +0900198 product_variables: {
199 debuggable: {
200 cppflags: ["-DUSE_LD_CONFIG_FILE"],
201 },
202 },
203
Colin Cross97f0aef2016-07-14 16:05:46 -0700204 cppflags: ["-Wold-style-cast"],
205
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800206 // we are going to link libc++_static manually because
207 // when stl is not set to "none" build system adds libdl
208 // to the list of static libraries which needs to be
209 // avoided in the case of building loader.
210 stl: "none",
211
Colin Cross97f0aef2016-07-14 16:05:46 -0700212 // we don't want crtbegin.o (because we have begin.o), so unset it
213 // just for this module
214 nocrt: true,
215
dimitryb8b3a762018-09-25 12:31:11 +0200216 static_executable: true,
217
218 // Leave the symbols in the shared library so that stack unwinders can produce
219 // meaningful name resolution.
220 strip: {
221 keep_symbols: true,
222 },
223
224 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
225 // looking up symbols in the linker by mistake.
226 prefix_symbols: "__dl_",
227
228 sanitize: {
229 hwaddress: false,
230 },
231}
232
233cc_binary {
234 defaults: ["linux_bionic_supported", "linker_defaults"],
235 srcs: [ ":linker_sources" ],
236
237 arch: {
238 arm: {
239 srcs: [ ":linker_sources_arm" ],
240 version_script: ":linker_version_script_arm",
241 },
242 arm64: {
243 srcs: [":linker_sources_arm64"],
244 version_script: ":linker_version_script",
245 },
246 x86: {
247 srcs: [":linker_sources_x86"],
248 version_script: ":linker_version_script",
249 },
250 x86_64: {
251 srcs: [":linker_sources_x86_64"],
252 version_script: ":linker_version_script",
253 },
254 mips: {
255 srcs: [":linker_sources_mips"],
256 version_script: ":linker_version_script",
257 },
258 mips64: {
259 srcs: [":linker_sources_mips64"],
260 version_script: ":linker_version_script",
261 },
262 },
263
264 // We need to access Bionic private headers in the linker.
265 include_dirs: ["bionic/libc"],
266
Colin Cross97f0aef2016-07-14 16:05:46 -0700267 static_libs: [
268 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800269 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700270 "libziparchive",
Colin Cross97f0aef2016-07-14 16:05:46 -0700271 "libbase",
272 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800273
Dan Willemsen4326d842017-05-07 13:07:41 -0700274 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800275
Colin Cross97f0aef2016-07-14 16:05:46 -0700276 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800277 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700278
279 // Important: The liblinker_malloc should be the last library in the list
280 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800281 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700282 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700283
284 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800285 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900286 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700287 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900288 lib32: {
289 cflags: ["-DLIB_PATH=\"lib\""],
290 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700291 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900292 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700293 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800294 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700295 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800296 system_shared_libs: [],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800297
298 // Opt out of native_coverage when opting out of system_shared_libs
299 native_coverage: false,
300
Colin Cross97f0aef2016-07-14 16:05:46 -0700301 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800302 android: {
Dan Albert4ea19212019-07-23 13:31:14 -0700303 static_libs: [
304 "libc++demangle",
305 "libdebuggerd_handler_fallback",
306 ],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800307 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700308 },
309 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800310 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700311}
dimitry11da1dc2018-01-05 13:35:43 +0100312
Elliott Hughes90f96b92019-05-09 15:56:39 -0700313sh_binary {
314 name: "ldd",
315 src: "ldd",
316}
317
dimitry11da1dc2018-01-05 13:35:43 +0100318cc_library {
319 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
320 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
321 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
322 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
323 // we use this property to make sure libc.so has its own copy of the code from
324 // libgcc.a it uses.
325 //
326 // DO NOT REMOVE --exclude-libs!
327
Yi Kong7786a342018-08-31 19:01:56 -0700328 ldflags: [
329 "-Wl,--exclude-libs=libgcc.a",
Yi Kong7ac2afb2019-05-06 16:23:10 -0700330 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700331 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
332 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
333 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
334 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
335 ],
dimitry11da1dc2018-01-05 13:35:43 +0100336
337 // for x86, exclude libgcc_eh.a for the same reasons as above
338 arch: {
dimitry581723e2018-01-05 14:31:44 +0100339 arm: {
340 version_script: "linker.arm.map",
341 },
342 arm64: {
343 version_script: "linker.generic.map",
344 },
dimitry11da1dc2018-01-05 13:35:43 +0100345 x86: {
346 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100347 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100348 },
349 x86_64: {
350 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100351 version_script: "linker.generic.map",
352 },
353 mips: {
354 version_script: "linker.generic.map",
355 },
356 mips64: {
357 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100358 },
359 },
dimitry581723e2018-01-05 14:31:44 +0100360
361 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100362 cflags: [
363 "-Wall",
364 "-Wextra",
365 "-Wunused",
366 "-Werror",
367 ],
368 stl: "none",
369
370 name: "ld-android",
371 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900372 recovery_available: true,
dimitry7f048802019-05-03 15:57:34 +0200373 native_bridge_supported: true,
dimitry11da1dc2018-01-05 13:35:43 +0100374
Ryan Prichard470b6662018-03-27 22:10:55 -0700375 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100376 system_shared_libs: [],
377
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800378 // Opt out of native_coverage when opting out of system_shared_libs
379 native_coverage: false,
380
dimitry11da1dc2018-01-05 13:35:43 +0100381 sanitize: {
382 never: true,
383 },
384}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800385
386cc_test {
387 name: "linker-unit-tests",
388
389 cflags: [
390 "-g",
391 "-Wall",
392 "-Wextra",
393 "-Wunused",
394 "-Werror",
395 ],
396
397 // We need to access Bionic private headers in the linker.
398 include_dirs: ["bionic/libc"],
399
400 srcs: [
401 // Tests.
402 "linker_block_allocator_test.cpp",
403 "linker_config_test.cpp",
404 "linked_list_test.cpp",
405 "linker_sleb128_test.cpp",
406 "linker_utils_test.cpp",
407
408 // Parts of the linker that we're testing.
409 "linker_block_allocator.cpp",
410 "linker_config.cpp",
411 "linker_test_globals.cpp",
412 "linker_utils.cpp",
413 ],
414
415 static_libs: [
416 "libasync_safe",
417 "libbase",
418 "liblog",
419 ],
420}