blob: a9907ca4461aceaaef37f0c0c5c8cbd5831954af [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",
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",
106 ],
107}
108
109filegroup {
110 name: "linker_sources_x86",
111 srcs: [
112 "arch/x86/begin.S",
113 ],
114}
115
116filegroup {
117 name: "linker_sources_x86_64",
118 srcs: [
119 "arch/x86_64/begin.S",
120 ],
121}
122
123filegroup {
124 name: "linker_sources_mips",
125 srcs: [
126 "arch/mips/begin.S",
127 "linker_mips.cpp",
128 ],
129}
130
131filegroup {
132 name: "linker_sources_mips64",
133 srcs: [
134 "arch/mips64/begin.S",
135 "linker_mips.cpp",
136 ],
137}
138
139filegroup {
140 name: "linker_version_script",
141 srcs: ["linker.generic.map"],
142}
143
144filegroup {
145 name: "linker_version_script_arm",
146 srcs: ["linker.arm.map"],
147}
148
149cc_defaults {
150 name: "linker_defaults",
Colin Cross97f0aef2016-07-14 16:05:46 -0700151 arch: {
152 arm: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700153 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700154 },
155 x86: {
Ryan Prichard7046f392018-05-24 14:07:27 -0700156 cflags: ["-D__work_around_b_24465209__"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700157 },
158 },
159
Colin Cross97f0aef2016-07-14 16:05:46 -0700160 // -shared is used to overwrite the -Bstatic and -static
161 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
162 // This dynamic linker is actually a shared object linked with static libraries.
163 ldflags: [
164 "-shared",
165 "-Wl,-Bsymbolic",
166 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100167 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700168 ],
169
170 cflags: [
171 "-fno-stack-protector",
172 "-Wstrict-overflow=5",
173 "-fvisibility=hidden",
174 "-Wall",
175 "-Wextra",
176 "-Wunused",
177 "-Werror",
178 ],
179
180 // TODO: split out the asflags.
181 asflags: [
182 "-fno-stack-protector",
183 "-Wstrict-overflow=5",
184 "-fvisibility=hidden",
185 "-Wall",
186 "-Wextra",
187 "-Wunused",
188 "-Werror",
189 ],
190
Jiyong Park02586a22017-05-20 01:01:24 +0900191 product_variables: {
192 debuggable: {
193 cppflags: ["-DUSE_LD_CONFIG_FILE"],
194 },
195 },
196
Colin Cross97f0aef2016-07-14 16:05:46 -0700197 cppflags: ["-Wold-style-cast"],
198
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800199 // we are going to link libc++_static manually because
200 // when stl is not set to "none" build system adds libdl
201 // to the list of static libraries which needs to be
202 // avoided in the case of building loader.
203 stl: "none",
204
Colin Cross97f0aef2016-07-14 16:05:46 -0700205 // we don't want crtbegin.o (because we have begin.o), so unset it
206 // just for this module
207 nocrt: true,
208
dimitryb8b3a762018-09-25 12:31:11 +0200209 static_executable: true,
210
211 // Leave the symbols in the shared library so that stack unwinders can produce
212 // meaningful name resolution.
213 strip: {
214 keep_symbols: true,
215 },
216
217 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
218 // looking up symbols in the linker by mistake.
219 prefix_symbols: "__dl_",
220
221 sanitize: {
222 hwaddress: false,
223 },
224}
225
226cc_binary {
227 defaults: ["linux_bionic_supported", "linker_defaults"],
228 srcs: [ ":linker_sources" ],
229
230 arch: {
231 arm: {
232 srcs: [ ":linker_sources_arm" ],
233 version_script: ":linker_version_script_arm",
234 },
235 arm64: {
236 srcs: [":linker_sources_arm64"],
237 version_script: ":linker_version_script",
238 },
239 x86: {
240 srcs: [":linker_sources_x86"],
241 version_script: ":linker_version_script",
242 },
243 x86_64: {
244 srcs: [":linker_sources_x86_64"],
245 version_script: ":linker_version_script",
246 },
247 mips: {
248 srcs: [":linker_sources_mips"],
249 version_script: ":linker_version_script",
250 },
251 mips64: {
252 srcs: [":linker_sources_mips64"],
253 version_script: ":linker_version_script",
254 },
255 },
256
257 // We need to access Bionic private headers in the linker.
258 include_dirs: ["bionic/libc"],
259
Colin Cross97f0aef2016-07-14 16:05:46 -0700260 static_libs: [
261 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800262 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700263 "libziparchive",
264 "libutils",
265 "libbase",
266 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800267
Dan Willemsen4326d842017-05-07 13:07:41 -0700268 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800269
Colin Cross97f0aef2016-07-14 16:05:46 -0700270 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800271 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700272
273 // Important: The liblinker_malloc should be the last library in the list
274 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800275 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700276 ],
Colin Cross97f0aef2016-07-14 16:05:46 -0700277
278 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800279 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900280 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700281 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700282 lib64: {
283 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800284 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700285 },
286 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800287 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700288 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800289 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700290 },
291 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800292 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700293}
dimitry11da1dc2018-01-05 13:35:43 +0100294
295cc_library {
296 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
297 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
298 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
299 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
300 // we use this property to make sure libc.so has its own copy of the code from
301 // libgcc.a it uses.
302 //
303 // DO NOT REMOVE --exclude-libs!
304
Yi Kong7786a342018-08-31 19:01:56 -0700305 ldflags: [
306 "-Wl,--exclude-libs=libgcc.a",
307 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
308 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
309 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
310 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
311 ],
dimitry11da1dc2018-01-05 13:35:43 +0100312
313 // for x86, exclude libgcc_eh.a for the same reasons as above
314 arch: {
dimitry581723e2018-01-05 14:31:44 +0100315 arm: {
316 version_script: "linker.arm.map",
317 },
318 arm64: {
319 version_script: "linker.generic.map",
320 },
dimitry11da1dc2018-01-05 13:35:43 +0100321 x86: {
322 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100323 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100324 },
325 x86_64: {
326 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100327 version_script: "linker.generic.map",
328 },
329 mips: {
330 version_script: "linker.generic.map",
331 },
332 mips64: {
333 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100334 },
335 },
dimitry581723e2018-01-05 14:31:44 +0100336
337 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100338 cflags: [
339 "-Wall",
340 "-Wextra",
341 "-Wunused",
342 "-Werror",
343 ],
344 stl: "none",
345
346 name: "ld-android",
347 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900348 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100349
Ryan Prichard470b6662018-03-27 22:10:55 -0700350 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100351 system_shared_libs: [],
352
353 sanitize: {
354 never: true,
355 },
356}