blob: 38a53f81ff9316891bb412e38303595caa4809f6 [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",
179 ],
180
181 // TODO: split out the asflags.
182 asflags: [
183 "-fno-stack-protector",
184 "-Wstrict-overflow=5",
185 "-fvisibility=hidden",
186 "-Wall",
187 "-Wextra",
188 "-Wunused",
189 "-Werror",
190 ],
191
Jiyong Park02586a22017-05-20 01:01:24 +0900192 product_variables: {
193 debuggable: {
194 cppflags: ["-DUSE_LD_CONFIG_FILE"],
195 },
196 },
197
Colin Cross97f0aef2016-07-14 16:05:46 -0700198 cppflags: ["-Wold-style-cast"],
199
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800200 // we are going to link libc++_static manually because
201 // when stl is not set to "none" build system adds libdl
202 // to the list of static libraries which needs to be
203 // avoided in the case of building loader.
204 stl: "none",
205
Colin Cross97f0aef2016-07-14 16:05:46 -0700206 // we don't want crtbegin.o (because we have begin.o), so unset it
207 // just for this module
208 nocrt: true,
209
dimitryb8b3a762018-09-25 12:31:11 +0200210 static_executable: true,
211
212 // Leave the symbols in the shared library so that stack unwinders can produce
213 // meaningful name resolution.
214 strip: {
215 keep_symbols: true,
216 },
217
218 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
219 // looking up symbols in the linker by mistake.
220 prefix_symbols: "__dl_",
221
222 sanitize: {
223 hwaddress: false,
224 },
225}
226
227cc_binary {
228 defaults: ["linux_bionic_supported", "linker_defaults"],
229 srcs: [ ":linker_sources" ],
230
231 arch: {
232 arm: {
233 srcs: [ ":linker_sources_arm" ],
234 version_script: ":linker_version_script_arm",
235 },
236 arm64: {
237 srcs: [":linker_sources_arm64"],
238 version_script: ":linker_version_script",
239 },
240 x86: {
241 srcs: [":linker_sources_x86"],
242 version_script: ":linker_version_script",
243 },
244 x86_64: {
245 srcs: [":linker_sources_x86_64"],
246 version_script: ":linker_version_script",
247 },
248 mips: {
249 srcs: [":linker_sources_mips"],
250 version_script: ":linker_version_script",
251 },
252 mips64: {
253 srcs: [":linker_sources_mips64"],
254 version_script: ":linker_version_script",
255 },
256 },
257
258 // We need to access Bionic private headers in the linker.
259 include_dirs: ["bionic/libc"],
260
Colin Cross97f0aef2016-07-14 16:05:46 -0700261 static_libs: [
262 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800263 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700264 "libziparchive",
265 "libutils",
266 "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: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700283 lib64: {
284 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800285 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700286 },
Dan Willemsen6b3be172018-12-03 13:57:20 -0800287 system_shared_libs: [],
Colin Cross97f0aef2016-07-14 16:05:46 -0700288 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800289 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700290 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800291 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700292 },
293 compile_multilib: "both",
Ivan Lozanof17fd1d2018-11-27 07:56:17 -0800294 xom: false,
Colin Cross97f0aef2016-07-14 16:05:46 -0700295}
dimitry11da1dc2018-01-05 13:35:43 +0100296
297cc_library {
298 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
299 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
300 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
301 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
302 // we use this property to make sure libc.so has its own copy of the code from
303 // libgcc.a it uses.
304 //
305 // DO NOT REMOVE --exclude-libs!
306
Yi Kong7786a342018-08-31 19:01:56 -0700307 ldflags: [
308 "-Wl,--exclude-libs=libgcc.a",
309 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
310 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
311 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
312 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
313 ],
dimitry11da1dc2018-01-05 13:35:43 +0100314
315 // for x86, exclude libgcc_eh.a for the same reasons as above
316 arch: {
dimitry581723e2018-01-05 14:31:44 +0100317 arm: {
318 version_script: "linker.arm.map",
319 },
320 arm64: {
321 version_script: "linker.generic.map",
322 },
dimitry11da1dc2018-01-05 13:35:43 +0100323 x86: {
324 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100325 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100326 },
327 x86_64: {
328 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100329 version_script: "linker.generic.map",
330 },
331 mips: {
332 version_script: "linker.generic.map",
333 },
334 mips64: {
335 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100336 },
337 },
dimitry581723e2018-01-05 14:31:44 +0100338
339 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100340 cflags: [
341 "-Wall",
342 "-Wextra",
343 "-Wunused",
344 "-Werror",
345 ],
346 stl: "none",
347
348 name: "ld-android",
349 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900350 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100351
Ryan Prichard470b6662018-03-27 22:10:55 -0700352 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100353 system_shared_libs: [],
354
355 sanitize: {
356 never: true,
357 },
358}