blob: 78d425ea27fa551c61f6ba49730a9649f26d5fa0 [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"],
Colin Cross97f0aef2016-07-14 16:05:46 -07004
5 srcs: [
6 "linker_allocator.cpp",
7 "linker_memory.cpp",
8 ],
Elliott Hughesd50a1de2018-02-05 17:30:57 -08009 cflags: [
10 "-Wall",
11 "-Werror",
12 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070013
14 // We need to access Bionic private headers in the linker.
15 include_dirs: ["bionic/libc"],
Christopher Ferris7a3681e2017-04-24 17:48:32 -070016
17 static_libs: ["libasync_safe"],
Colin Cross97f0aef2016-07-14 16:05:46 -070018}
19
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070020// This is used for bionic on (host) Linux to bootstrap our linker embedded into
21// a binary.
22//
23// Host bionic binaries do not have a PT_INTERP section, instead this gets
24// embedded as the entry point, and the linker is embedded as ELF sections in
25// each binary. There's a linker script that sets all of that up (generated by
26// extract_linker), and defines the extern symbols used in this file.
27cc_object {
28 name: "linker_wrapper",
29 host_supported: true,
30 device_supported: false,
31 target: {
Elliott Hughesd50a1de2018-02-05 17:30:57 -080032 linux_bionic: {
33 enabled: true,
34 },
35 linux_glibc: {
36 enabled: false,
37 },
38 darwin: {
39 enabled: false,
40 },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070041 },
42
43 cflags: [
44 "-fno-stack-protector",
45 "-Wstrict-overflow=5",
46 "-fvisibility=hidden",
47 "-Wall",
48 "-Wextra",
49 "-Wno-unused",
50 "-Werror",
51 ],
52
53 srcs: [
54 "linker_wrapper.cpp",
55 ],
56 arch: {
57 x86_64: {
58 srcs: ["arch/x86_64/begin.S"],
59 },
60 },
61
62 prefix_symbols: "__dlwrap_",
63
64 // We need to access Bionic private headers in the linker.
65 include_dirs: ["bionic/libc"],
66}
67
Colin Cross97f0aef2016-07-14 16:05:46 -070068cc_binary {
Dan Willemsen7ec52b12016-11-28 17:02:25 -080069 defaults: ["linux_bionic_supported"],
Colin Cross97f0aef2016-07-14 16:05:46 -070070 srcs: [
71 "dlfcn.cpp",
72 "linker.cpp",
73 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -070074 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -070075 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -080076 "linker_config.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070077 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070078 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070079 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -080080 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -070081 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -070082 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070083 "linker_logger.cpp",
84 "linker_mapped_file_fragment.cpp",
85 "linker_phdr.cpp",
86 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070087 "linker_soinfo.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070088 "linker_utils.cpp",
89 "rt.cpp",
90 ],
91
92 arch: {
93 arm: {
dimitry25bf29b2017-08-29 13:38:04 +020094 srcs: [
95 "arch/arm/begin.S",
96 "linker_exidx_static.c",
97 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070098
99 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200100 version_script: "linker.arm.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700101 },
102 arm64: {
103 srcs: ["arch/arm64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200104 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700105 },
106 x86: {
Ryan Prichardf857d592018-02-12 19:59:46 -0800107 srcs: ["arch/x86/begin.S"],
Ryan Prichard7046f392018-05-24 14:07:27 -0700108 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200109 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700110 },
111 x86_64: {
112 srcs: ["arch/x86_64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200113 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700114 },
115 mips: {
116 srcs: [
117 "arch/mips/begin.S",
118 "linker_mips.cpp",
119 ],
dimitry7abea572017-08-29 18:14:49 +0200120 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700121 },
122 mips64: {
123 srcs: [
124 "arch/mips64/begin.S",
125 "linker_mips.cpp",
126 ],
dimitry7abea572017-08-29 18:14:49 +0200127 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700128 },
129 },
130
131 // We need to access Bionic private headers in the linker.
132 include_dirs: ["bionic/libc"],
133
134 // -shared is used to overwrite the -Bstatic and -static
135 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
136 // This dynamic linker is actually a shared object linked with static libraries.
137 ldflags: [
138 "-shared",
139 "-Wl,-Bsymbolic",
140 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100141 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700142 ],
143
Chih-Hung Hsieh73de62e2018-04-16 09:51:50 -0700144 // lld bug: https://bugs.llvm.org/show_bug.cgi?id=36295
145 // error: symbol __aeabi_*@@LIBC_N has undefined version LIBC_N
146 use_clang_lld: false,
147
Colin Cross97f0aef2016-07-14 16:05:46 -0700148 cflags: [
149 "-fno-stack-protector",
150 "-Wstrict-overflow=5",
151 "-fvisibility=hidden",
152 "-Wall",
153 "-Wextra",
154 "-Wunused",
155 "-Werror",
156 ],
157
158 // TODO: split out the asflags.
159 asflags: [
160 "-fno-stack-protector",
161 "-Wstrict-overflow=5",
162 "-fvisibility=hidden",
163 "-Wall",
164 "-Wextra",
165 "-Wunused",
166 "-Werror",
167 ],
168
Jiyong Park02586a22017-05-20 01:01:24 +0900169 product_variables: {
170 debuggable: {
171 cppflags: ["-DUSE_LD_CONFIG_FILE"],
172 },
173 },
174
Colin Cross97f0aef2016-07-14 16:05:46 -0700175 cppflags: ["-Wold-style-cast"],
176
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800177 // we are going to link libc++_static manually because
178 // when stl is not set to "none" build system adds libdl
179 // to the list of static libraries which needs to be
180 // avoided in the case of building loader.
181 stl: "none",
182
Colin Cross97f0aef2016-07-14 16:05:46 -0700183 // we don't want crtbegin.o (because we have begin.o), so unset it
184 // just for this module
185 nocrt: true,
186
187 static_libs: [
188 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800189 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700190 "libziparchive",
191 "libutils",
192 "libbase",
193 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800194
Dan Willemsen4326d842017-05-07 13:07:41 -0700195 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800196
Colin Cross97f0aef2016-07-14 16:05:46 -0700197 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800198 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700199
200 // Important: The liblinker_malloc should be the last library in the list
201 // to overwrite any other malloc implementations by other static libraries.
Elliott Hughesd50a1de2018-02-05 17:30:57 -0800202 "liblinker_malloc",
Colin Cross97f0aef2016-07-14 16:05:46 -0700203 ],
204 static_executable: true,
205
206 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800207 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700208 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700209 lib64: {
210 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800211 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700212 },
213 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800214 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700215 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800216 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700217 },
218 compile_multilib: "both",
219
220 // Leave the symbols in the shared library so that stack unwinders can produce
221 // meaningful name resolution.
222 strip: {
223 keep_symbols: true,
224 },
225
226 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
227 // looking up symbols in the linker by mistake.
228 prefix_symbols: "__dl_",
229}
dimitry11da1dc2018-01-05 13:35:43 +0100230
231cc_library {
232 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
233 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
234 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
235 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
236 // we use this property to make sure libc.so has its own copy of the code from
237 // libgcc.a it uses.
238 //
239 // DO NOT REMOVE --exclude-libs!
240
241 ldflags: ["-Wl,--exclude-libs=libgcc.a"],
242
243 // for x86, exclude libgcc_eh.a for the same reasons as above
244 arch: {
dimitry581723e2018-01-05 14:31:44 +0100245 arm: {
246 version_script: "linker.arm.map",
247 },
248 arm64: {
249 version_script: "linker.generic.map",
250 },
dimitry11da1dc2018-01-05 13:35:43 +0100251 x86: {
252 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100253 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100254 },
255 x86_64: {
256 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100257 version_script: "linker.generic.map",
258 },
259 mips: {
260 version_script: "linker.generic.map",
261 },
262 mips64: {
263 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100264 },
265 },
dimitry581723e2018-01-05 14:31:44 +0100266
267 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100268 cflags: [
269 "-Wall",
270 "-Wextra",
271 "-Wunused",
272 "-Werror",
273 ],
274 stl: "none",
275
276 name: "ld-android",
277 defaults: ["linux_bionic_supported"],
Jiyong Park5603c6e2018-04-27 21:53:11 +0900278 recovery_available: true,
dimitry11da1dc2018-01-05 13:35:43 +0100279
Ryan Prichard470b6662018-03-27 22:10:55 -0700280 nocrt: true,
dimitry11da1dc2018-01-05 13:35:43 +0100281 system_shared_libs: [],
282
283 sanitize: {
284 never: true,
285 },
286}