blob: 23cd22a45155713a627a8c8038a286b5eb4f5d8e [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",
Colin Cross97f0aef2016-07-14 16:05:46 -070077 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070078 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070079 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -080080 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -070081 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -070082 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070083 "linker_logger.cpp",
84 "linker_mapped_file_fragment.cpp",
85 "linker_phdr.cpp",
86 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070087 "linker_soinfo.cpp",
Ryan Prichard45d13492019-01-03 02:51:30 -080088 "linker_tls.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070089 "linker_utils.cpp",
90 "rt.cpp",
91 ],
dimitryb8b3a762018-09-25 12:31:11 +020092}
Colin Cross97f0aef2016-07-14 16:05:46 -070093
dimitryb8b3a762018-09-25 12:31:11 +020094filegroup {
95 name: "linker_sources_arm",
96 srcs: [
97 "arch/arm/begin.S",
98 "linker_exidx_static.c",
99 ],
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",
Ryan Prichard9ee80692019-01-15 16:10:36 -0800179
180 // Define _USING_LIBCXX so <stdatomic.h> defers to the <atomic> header. When a Soong module
181 // uses the platform libc++, Soong automatically passes this macro, but the dynamic linker
182 // links against libc++ manually.
183 "-D_USING_LIBCXX",
Colin Cross97f0aef2016-07-14 16:05:46 -0700184 ],
185
186 // TODO: split out the asflags.
187 asflags: [
188 "-fno-stack-protector",
189 "-Wstrict-overflow=5",
190 "-fvisibility=hidden",
191 "-Wall",
192 "-Wextra",
193 "-Wunused",
194 "-Werror",
195 ],
196
Jiyong Park02586a22017-05-20 01:01:24 +0900197 product_variables: {
198 debuggable: {
199 cppflags: ["-DUSE_LD_CONFIG_FILE"],
200 },
Christopher R. Palmer0ff05db2017-04-08 22:40:01 +0200201 bliss: {
Danny Baumann36f57d32018-08-29 11:21:52 +0200202 target_process_sdk_version_override: {
203 cppflags: ["-DSDK_VERSION_OVERRIDES=\"%s\""],
204 },
Christopher R. Palmer0ff05db2017-04-08 22:40:01 +0200205 target_shim_libs: {
206 cppflags: ["-DLD_SHIM_LIBS=\"%s\""],
207 },
208 },
Jiyong Park02586a22017-05-20 01:01:24 +0900209 },
210
Colin Cross97f0aef2016-07-14 16:05:46 -0700211 cppflags: ["-Wold-style-cast"],
212
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800213 // we are going to link libc++_static manually because
214 // when stl is not set to "none" build system adds libdl
215 // to the list of static libraries which needs to be
216 // avoided in the case of building loader.
217 stl: "none",
218
Colin Cross97f0aef2016-07-14 16:05:46 -0700219 // we don't want crtbegin.o (because we have begin.o), so unset it
220 // just for this module
221 nocrt: true,
222
dimitryb8b3a762018-09-25 12:31:11 +0200223 static_executable: true,
224
225 // Leave the symbols in the shared library so that stack unwinders can produce
226 // meaningful name resolution.
227 strip: {
228 keep_symbols: true,
229 },
230
231 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
232 // looking up symbols in the linker by mistake.
233 prefix_symbols: "__dl_",
234
235 sanitize: {
236 hwaddress: false,
237 },
238}
239
240cc_binary {
241 defaults: ["linux_bionic_supported", "linker_defaults"],
242 srcs: [ ":linker_sources" ],
243
244 arch: {
245 arm: {
246 srcs: [ ":linker_sources_arm" ],
247 version_script: ":linker_version_script_arm",
248 },
249 arm64: {
250 srcs: [":linker_sources_arm64"],
251 version_script: ":linker_version_script",
252 },
253 x86: {
254 srcs: [":linker_sources_x86"],
255 version_script: ":linker_version_script",
256 },
257 x86_64: {
258 srcs: [":linker_sources_x86_64"],
259 version_script: ":linker_version_script",
260 },
261 mips: {
262 srcs: [":linker_sources_mips"],
263 version_script: ":linker_version_script",
264 },
265 mips64: {
266 srcs: [":linker_sources_mips64"],
267 version_script: ":linker_version_script",
268 },
269 },
270
271 // We need to access Bionic private headers in the linker.
272 include_dirs: ["bionic/libc"],
273
Colin Cross97f0aef2016-07-14 16:05:46 -0700274 static_libs: [
275 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800276 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700277 "libziparchive",
278 "libutils",
279 "libbase",
280 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800281
Dan Willemsen4326d842017-05-07 13:07:41 -0700282 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800283
Colin Cross97f0aef2016-07-14 16:05:46 -0700284 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800285 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700286
287 // Important: The liblinker_malloc should be the last library in the list
288 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800289 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700290 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700291
292 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800293 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900294 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700295 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900296 lib32: {
297 cflags: ["-DLIB_PATH=\"lib\""],
298 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700299 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900300 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700301 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800302 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700303 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800304 system_shared_libs: [],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800305
306 // Opt out of native_coverage when opting out of system_shared_libs
307 native_coverage: false,
308
Colin Cross97f0aef2016-07-14 16:05:46 -0700309 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800310 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700311 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800312 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700313 },
314 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800315 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700316}
dimitry11da1dc2018-01-05 13:35:43 +0100317
318cc_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 Kongbffe6f12019-05-06 20:12:46 -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,
dimitry11da1dc2018-01-05 13:35:43 +0100373
Ryan Prichard470b6662018-03-27 22:10:55 -0700374 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100375 system_shared_libs: [],
376
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800377 // Opt out of native_coverage when opting out of system_shared_libs
378 native_coverage: false,
379
dimitry11da1dc2018-01-05 13:35:43 +0100380 sanitize: {
381 never: true,
382 },
383}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800384
385cc_test {
386 name: "linker-unit-tests",
387
388 cflags: [
389 "-g",
390 "-Wall",
391 "-Wextra",
392 "-Wunused",
393 "-Werror",
394 ],
395
396 // We need to access Bionic private headers in the linker.
397 include_dirs: ["bionic/libc"],
398
399 srcs: [
400 // Tests.
401 "linker_block_allocator_test.cpp",
402 "linker_config_test.cpp",
403 "linked_list_test.cpp",
404 "linker_sleb128_test.cpp",
405 "linker_utils_test.cpp",
406
407 // Parts of the linker that we're testing.
408 "linker_block_allocator.cpp",
409 "linker_config.cpp",
410 "linker_test_globals.cpp",
411 "linker_utils.cpp",
412 ],
413
414 static_libs: [
415 "libasync_safe",
416 "libbase",
417 "liblog",
418 ],
419}