blob: e2cdd148424188947f560bd77144db877f16ea17 [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",
180 ],
181
182 // TODO: split out the asflags.
183 asflags: [
184 "-fno-stack-protector",
185 "-Wstrict-overflow=5",
186 "-fvisibility=hidden",
187 "-Wall",
188 "-Wextra",
189 "-Wunused",
190 "-Werror",
191 ],
192
Jiyong Park02586a22017-05-20 01:01:24 +0900193 product_variables: {
194 debuggable: {
195 cppflags: ["-DUSE_LD_CONFIG_FILE"],
196 },
197 },
198
Colin Cross97f0aef2016-07-14 16:05:46 -0700199 cppflags: ["-Wold-style-cast"],
200
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800201 // we are going to link libc++_static manually because
202 // when stl is not set to "none" build system adds libdl
203 // to the list of static libraries which needs to be
204 // avoided in the case of building loader.
205 stl: "none",
206
Colin Cross97f0aef2016-07-14 16:05:46 -0700207 // we don't want crtbegin.o (because we have begin.o), so unset it
208 // just for this module
209 nocrt: true,
210
dimitryb8b3a762018-09-25 12:31:11 +0200211 static_executable: true,
212
213 // Leave the symbols in the shared library so that stack unwinders can produce
214 // meaningful name resolution.
215 strip: {
216 keep_symbols: true,
217 },
218
219 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
220 // looking up symbols in the linker by mistake.
221 prefix_symbols: "__dl_",
222
223 sanitize: {
224 hwaddress: false,
225 },
226}
227
228cc_binary {
229 defaults: ["linux_bionic_supported", "linker_defaults"],
230 srcs: [ ":linker_sources" ],
231
232 arch: {
233 arm: {
234 srcs: [ ":linker_sources_arm" ],
235 version_script: ":linker_version_script_arm",
236 },
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
279 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800280 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900281 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700282 multilib: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900283 lib32: {
284 cflags: ["-DLIB_PATH=\"lib\""],
285 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700286 lib64: {
Jiyong Park57b9d1e2019-01-17 03:14:45 +0900287 cflags: ["-DLIB_PATH=\"lib64\""],
Colin Cross97f0aef2016-07-14 16:05:46 -0700288 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800289 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700290 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800291 system_shared_libs: [],
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800292
293 // Opt out of native_coverage when opting out of system_shared_libs
294 native_coverage: false,
295
Colin Cross97f0aef2016-07-14 16:05:46 -0700296 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800297 android: {
Dan Albert4ea19212019-07-23 13:31:14 -0700298 static_libs: [
299 "libc++demangle",
300 "libdebuggerd_handler_fallback",
301 ],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800302 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700303 },
304 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800305 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700306}
dimitry11da1dc2018-01-05 13:35:43 +0100307
Elliott Hughes90f96b92019-05-09 15:56:39 -0700308sh_binary {
309 name: "ldd",
310 src: "ldd",
311}
312
dimitry11da1dc2018-01-05 13:35:43 +0100313cc_library {
314 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
315 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
316 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
317 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
318 // we use this property to make sure libc.so has its own copy of the code from
319 // libgcc.a it uses.
320 //
321 // DO NOT REMOVE --exclude-libs!
322
Yi Kong7786a342018-08-31 19:01:56 -0700323 ldflags: [
324 "-Wl,--exclude-libs=libgcc.a",
Yi Kong7ac2afb2019-05-06 16:23:10 -0700325 "-Wl,--exclude-libs=libgcc_stripped.a",
Yi Kong7786a342018-08-31 19:01:56 -0700326 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
327 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
328 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
329 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
330 ],
dimitry11da1dc2018-01-05 13:35:43 +0100331
332 // for x86, exclude libgcc_eh.a for the same reasons as above
333 arch: {
dimitry581723e2018-01-05 14:31:44 +0100334 arm: {
335 version_script: "linker.arm.map",
336 },
337 arm64: {
338 version_script: "linker.generic.map",
339 },
dimitry11da1dc2018-01-05 13:35:43 +0100340 x86: {
341 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100342 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100343 },
344 x86_64: {
345 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100346 version_script: "linker.generic.map",
347 },
348 mips: {
349 version_script: "linker.generic.map",
350 },
351 mips64: {
352 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100353 },
354 },
dimitry581723e2018-01-05 14:31:44 +0100355
356 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100357 cflags: [
358 "-Wall",
359 "-Wextra",
360 "-Wunused",
361 "-Werror",
362 ],
363 stl: "none",
364
365 name: "ld-android",
366 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900367 recovery_available: true,
dimitry7f048802019-05-03 15:57:34 +0200368 native_bridge_supported: true,
dimitry11da1dc2018-01-05 13:35:43 +0100369
Ryan Prichard470b6662018-03-27 22:10:55 -0700370 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100371 system_shared_libs: [],
372
Pirama Arumuga Nainarfcd35382019-02-14 13:48:01 -0800373 // Opt out of native_coverage when opting out of system_shared_libs
374 native_coverage: false,
375
dimitry11da1dc2018-01-05 13:35:43 +0100376 sanitize: {
377 never: true,
378 },
379}
Elliott Hughes15a2b7b2019-02-15 13:48:38 -0800380
381cc_test {
382 name: "linker-unit-tests",
383
384 cflags: [
385 "-g",
386 "-Wall",
387 "-Wextra",
388 "-Wunused",
389 "-Werror",
390 ],
391
392 // We need to access Bionic private headers in the linker.
393 include_dirs: ["bionic/libc"],
394
395 srcs: [
396 // Tests.
397 "linker_block_allocator_test.cpp",
398 "linker_config_test.cpp",
399 "linked_list_test.cpp",
400 "linker_sleb128_test.cpp",
401 "linker_utils_test.cpp",
402
403 // Parts of the linker that we're testing.
404 "linker_block_allocator.cpp",
405 "linker_config.cpp",
406 "linker_test_globals.cpp",
407 "linker_utils.cpp",
408 ],
409
410 static_libs: [
411 "libasync_safe",
412 "libbase",
413 "liblog",
414 ],
415}