blob: e103adebcfc8e4d43719d1f43a4a10001060e5c4 [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: [
7 "linker_allocator.cpp",
8 "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",
107 ],
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 },
201 },
202
Colin Cross97f0aef2016-07-14 16:05:46 -0700203 cppflags: ["-Wold-style-cast"],
204
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800205 // we are going to link libc++_static manually because
206 // when stl is not set to "none" build system adds libdl
207 // to the list of static libraries which needs to be
208 // avoided in the case of building loader.
209 stl: "none",
210
Colin Cross97f0aef2016-07-14 16:05:46 -0700211 // we don't want crtbegin.o (because we have begin.o), so unset it
212 // just for this module
213 nocrt: true,
214
dimitryb8b3a762018-09-25 12:31:11 +0200215 static_executable: true,
216
217 // Leave the symbols in the shared library so that stack unwinders can produce
218 // meaningful name resolution.
219 strip: {
220 keep_symbols: true,
221 },
222
223 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
224 // looking up symbols in the linker by mistake.
225 prefix_symbols: "__dl_",
226
227 sanitize: {
228 hwaddress: false,
229 },
230}
231
232cc_binary {
233 defaults: ["linux_bionic_supported", "linker_defaults"],
234 srcs: [ ":linker_sources" ],
235
236 arch: {
237 arm: {
238 srcs: [ ":linker_sources_arm" ],
239 version_script: ":linker_version_script_arm",
240 },
241 arm64: {
242 srcs: [":linker_sources_arm64"],
243 version_script: ":linker_version_script",
244 },
245 x86: {
246 srcs: [":linker_sources_x86"],
247 version_script: ":linker_version_script",
248 },
249 x86_64: {
250 srcs: [":linker_sources_x86_64"],
251 version_script: ":linker_version_script",
252 },
253 mips: {
254 srcs: [":linker_sources_mips"],
255 version_script: ":linker_version_script",
256 },
257 mips64: {
258 srcs: [":linker_sources_mips64"],
259 version_script: ":linker_version_script",
260 },
261 },
262
263 // We need to access Bionic private headers in the linker.
264 include_dirs: ["bionic/libc"],
265
Colin Cross97f0aef2016-07-14 16:05:46 -0700266 static_libs: [
267 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800268 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700269 "libziparchive",
270 "libutils",
271 "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: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700288 lib64: {
289 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800290 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700291 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800292 system_shared_libs: [],
Colin Cross97f0aef2016-07-14 16:05:46 -0700293 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800294 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700295 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800296 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700297 },
298 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800299 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700300}
dimitry11da1dc2018-01-05 13:35:43 +0100301
302cc_library {
303 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
304 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
305 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
306 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
307 // we use this property to make sure libc.so has its own copy of the code from
308 // libgcc.a it uses.
309 //
310 // DO NOT REMOVE --exclude-libs!
311
Yi Kong7786a342018-08-31 19:01:56 -0700312 ldflags: [
313 "-Wl,--exclude-libs=libgcc.a",
314 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
315 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
316 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
317 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
318 ],
dimitry11da1dc2018-01-05 13:35:43 +0100319
320 // for x86, exclude libgcc_eh.a for the same reasons as above
321 arch: {
dimitry581723e2018-01-05 14:31:44 +0100322 arm: {
323 version_script: "linker.arm.map",
324 },
325 arm64: {
326 version_script: "linker.generic.map",
327 },
dimitry11da1dc2018-01-05 13:35:43 +0100328 x86: {
329 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100330 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100331 },
332 x86_64: {
333 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100334 version_script: "linker.generic.map",
335 },
336 mips: {
337 version_script: "linker.generic.map",
338 },
339 mips64: {
340 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100341 },
342 },
dimitry581723e2018-01-05 14:31:44 +0100343
344 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100345 cflags: [
346 "-Wall",
347 "-Wextra",
348 "-Wunused",
349 "-Werror",
350 ],
351 stl: "none",
352
353 name: "ld-android",
354 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900355 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100356
Ryan Prichard470b6662018-03-27 22:10:55 -0700357 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100358 system_shared_libs: [],
359
360 sanitize: {
361 never: true,
362 },
363}