blob: db379ba974adfbbe6a49e6f8dab1fff1b2494252 [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
18 static_libs: ["libasync_safe"],
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
Colin Cross97f0aef2016-07-14 16:05:46 -070069cc_binary {
Dan Willemsen7ec52b12016-11-28 17:02:25 -080070 defaults: ["linux_bionic_supported"],
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 ],
92
93 arch: {
94 arm: {
dimitry25bf29b2017-08-29 13:38:04 +020095 srcs: [
96 "arch/arm/begin.S",
97 "linker_exidx_static.c",
98 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070099
100 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200101 version_script: "linker.arm.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700102 },
103 arm64: {
104 srcs: ["arch/arm64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200105 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700106 },
107 x86: {
Ryan Prichardf857d592018-02-12 19:59:46 -0800108 srcs: ["arch/x86/begin.S"],
Ryan Prichard7046f392018-05-24 14:07:27 -0700109 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200110 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700111 },
112 x86_64: {
113 srcs: ["arch/x86_64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200114 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700115 },
116 mips: {
117 srcs: [
118 "arch/mips/begin.S",
119 "linker_mips.cpp",
120 ],
dimitry7abea572017-08-29 18:14:49 +0200121 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700122 },
123 mips64: {
124 srcs: [
125 "arch/mips64/begin.S",
126 "linker_mips.cpp",
127 ],
dimitry7abea572017-08-29 18:14:49 +0200128 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700129 },
130 },
131
132 // We need to access Bionic private headers in the linker.
133 include_dirs: ["bionic/libc"],
134
135 // -shared is used to overwrite the -Bstatic and -static
136 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
137 // This dynamic linker is actually a shared object linked with static libraries.
138 ldflags: [
139 "-shared",
140 "-Wl,-Bsymbolic",
141 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100142 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700143 ],
144
Chih-Hung Hsieh73de62e2018-04-16 09:51:50 -0700145 // lld bug: https://bugs.llvm.org/show_bug.cgi?id=36295
146 // error: symbol __aeabi_*@@LIBC_N has undefined version LIBC_N
147 use_clang_lld: false,
148
Colin Cross97f0aef2016-07-14 16:05:46 -0700149 cflags: [
150 "-fno-stack-protector",
151 "-Wstrict-overflow=5",
152 "-fvisibility=hidden",
153 "-Wall",
154 "-Wextra",
155 "-Wunused",
156 "-Werror",
157 ],
158
159 // TODO: split out the asflags.
160 asflags: [
161 "-fno-stack-protector",
162 "-Wstrict-overflow=5",
163 "-fvisibility=hidden",
164 "-Wall",
165 "-Wextra",
166 "-Wunused",
167 "-Werror",
168 ],
169
Jiyong Park02586a22017-05-20 01:01:24 +0900170 product_variables: {
171 debuggable: {
172 cppflags: ["-DUSE_LD_CONFIG_FILE"],
173 },
174 },
175
Colin Cross97f0aef2016-07-14 16:05:46 -0700176 cppflags: ["-Wold-style-cast"],
177
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800178 // we are going to link libc++_static manually because
179 // when stl is not set to "none" build system adds libdl
180 // to the list of static libraries which needs to be
181 // avoided in the case of building loader.
182 stl: "none",
183
Colin Cross97f0aef2016-07-14 16:05:46 -0700184 // we don't want crtbegin.o (because we have begin.o), so unset it
185 // just for this module
186 nocrt: true,
187
188 static_libs: [
189 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800190 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700191 "libziparchive",
192 "libutils",
193 "libbase",
194 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800195
Dan Willemsen4326d842017-05-07 13:07:41 -0700196 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800197
Colin Cross97f0aef2016-07-14 16:05:46 -0700198 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800199 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700200
201 // Important: The liblinker_malloc should be the last library in the list
202 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800203 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700204 ],
205 static_executable: true,
206
207 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800208 symlinks: ["linker_asan"],
Jiyong Park8d7866c2018-05-29 16:34:39 +0900209 recovery_available: true,
Colin Cross97f0aef2016-07-14 16:05:46 -0700210 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700211 lib64: {
212 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800213 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700214 },
215 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800216 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700217 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800218 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700219 },
220 compile_multilib: "both",
221
222 // Leave the symbols in the shared library so that stack unwinders can produce
223 // meaningful name resolution.
224 strip: {
225 keep_symbols: true,
226 },
227
228 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
229 // looking up symbols in the linker by mistake.
230 prefix_symbols: "__dl_",
Evgenii Stepanovbe551f52018-08-13 16:46:15 -0700231
232 sanitize: {
233 hwaddress: false,
234 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700235}
dimitry11da1dc2018-01-05 13:35:43 +0100236
237cc_library {
238 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
239 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
240 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
241 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
242 // we use this property to make sure libc.so has its own copy of the code from
243 // libgcc.a it uses.
244 //
245 // DO NOT REMOVE --exclude-libs!
246
Yi Kong7786a342018-08-31 19:01:56 -0700247 ldflags: [
248 "-Wl,--exclude-libs=libgcc.a",
249 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
250 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
251 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a",
252 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
253 ],
dimitry11da1dc2018-01-05 13:35:43 +0100254
255 // for x86, exclude libgcc_eh.a for the same reasons as above
256 arch: {
dimitry581723e2018-01-05 14:31:44 +0100257 arm: {
258 version_script: "linker.arm.map",
259 },
260 arm64: {
261 version_script: "linker.generic.map",
262 },
dimitry11da1dc2018-01-05 13:35:43 +0100263 x86: {
264 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100265 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100266 },
267 x86_64: {
268 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100269 version_script: "linker.generic.map",
270 },
271 mips: {
272 version_script: "linker.generic.map",
273 },
274 mips64: {
275 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100276 },
277 },
dimitry581723e2018-01-05 14:31:44 +0100278
279 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100280 cflags: [
281 "-Wall",
282 "-Wextra",
283 "-Wunused",
284 "-Werror",
285 ],
286 stl: "none",
287
288 name: "ld-android",
289 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900290 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100291
Ryan Prichard470b6662018-03-27 22:10:55 -0700292 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100293 system_shared_libs: [],
294
295 sanitize: {
296 never: true,
297 },
298}