blob: 8d7fae5628976c6e1810c69979790d893579d914 [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 ],
Chih-Hung Hsieh84f0dcd2017-10-02 11:47:31 -07009 cflags: ["-Wall", "-Werror"],
Colin Cross97f0aef2016-07-14 16:05:46 -070010
11 // We need to access Bionic private headers in the linker.
12 include_dirs: ["bionic/libc"],
Christopher Ferris7a3681e2017-04-24 17:48:32 -070013
14 static_libs: ["libasync_safe"],
Colin Cross97f0aef2016-07-14 16:05:46 -070015}
16
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070017// This is used for bionic on (host) Linux to bootstrap our linker embedded into
18// a binary.
19//
20// Host bionic binaries do not have a PT_INTERP section, instead this gets
21// embedded as the entry point, and the linker is embedded as ELF sections in
22// each binary. There's a linker script that sets all of that up (generated by
23// extract_linker), and defines the extern symbols used in this file.
24cc_object {
25 name: "linker_wrapper",
26 host_supported: true,
27 device_supported: false,
28 target: {
29 linux_bionic: { enabled: true },
Dan Willemsen3a3982d2017-10-02 10:41:07 -070030 linux_glibc: { enabled: false },
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070031 darwin: { enabled: false },
32 },
33
34 cflags: [
35 "-fno-stack-protector",
36 "-Wstrict-overflow=5",
37 "-fvisibility=hidden",
38 "-Wall",
39 "-Wextra",
40 "-Wno-unused",
41 "-Werror",
42 ],
43
44 srcs: [
45 "linker_wrapper.cpp",
46 ],
47 arch: {
48 x86_64: {
49 srcs: ["arch/x86_64/begin.S"],
50 },
51 },
52
53 prefix_symbols: "__dlwrap_",
54
55 // We need to access Bionic private headers in the linker.
56 include_dirs: ["bionic/libc"],
57}
58
Colin Cross97f0aef2016-07-14 16:05:46 -070059cc_binary {
Dan Willemsen7ec52b12016-11-28 17:02:25 -080060 defaults: ["linux_bionic_supported"],
Colin Cross97f0aef2016-07-14 16:05:46 -070061 srcs: [
62 "dlfcn.cpp",
63 "linker.cpp",
64 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -070065 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -070066 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -080067 "linker_config.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070068 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070069 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070070 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -080071 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -070072 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -070073 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070074 "linker_logger.cpp",
75 "linker_mapped_file_fragment.cpp",
76 "linker_phdr.cpp",
77 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070078 "linker_soinfo.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070079 "linker_utils.cpp",
80 "rt.cpp",
81 ],
82
83 arch: {
84 arm: {
dimitry25bf29b2017-08-29 13:38:04 +020085 srcs: [
86 "arch/arm/begin.S",
87 "linker_exidx_static.c",
88 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070089
90 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +020091 version_script: "linker.arm.map",
Colin Cross97f0aef2016-07-14 16:05:46 -070092 },
93 arm64: {
94 srcs: ["arch/arm64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +020095 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -070096 },
97 x86: {
98 srcs: ["arch/x86/begin.c"],
99
100 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200101 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700102 },
103 x86_64: {
104 srcs: ["arch/x86_64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200105 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700106 },
107 mips: {
108 srcs: [
109 "arch/mips/begin.S",
110 "linker_mips.cpp",
111 ],
dimitry7abea572017-08-29 18:14:49 +0200112 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700113 },
114 mips64: {
115 srcs: [
116 "arch/mips64/begin.S",
117 "linker_mips.cpp",
118 ],
dimitry7abea572017-08-29 18:14:49 +0200119 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700120 },
121 },
122
123 // We need to access Bionic private headers in the linker.
124 include_dirs: ["bionic/libc"],
125
126 // -shared is used to overwrite the -Bstatic and -static
127 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
128 // This dynamic linker is actually a shared object linked with static libraries.
129 ldflags: [
130 "-shared",
131 "-Wl,-Bsymbolic",
132 "-Wl,--exclude-libs,ALL",
dimitry8e8c2c02018-01-04 12:08:32 +0100133 "-Wl,-soname,ld-android.so",
Colin Cross97f0aef2016-07-14 16:05:46 -0700134 ],
135
136 cflags: [
137 "-fno-stack-protector",
138 "-Wstrict-overflow=5",
139 "-fvisibility=hidden",
140 "-Wall",
141 "-Wextra",
142 "-Wunused",
143 "-Werror",
144 ],
145
146 // TODO: split out the asflags.
147 asflags: [
148 "-fno-stack-protector",
149 "-Wstrict-overflow=5",
150 "-fvisibility=hidden",
151 "-Wall",
152 "-Wextra",
153 "-Wunused",
154 "-Werror",
155 ],
156
Jiyong Park02586a22017-05-20 01:01:24 +0900157 product_variables: {
158 debuggable: {
159 cppflags: ["-DUSE_LD_CONFIG_FILE"],
160 },
161 },
162
Colin Cross97f0aef2016-07-14 16:05:46 -0700163 cppflags: ["-Wold-style-cast"],
164
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800165 // we are going to link libc++_static manually because
166 // when stl is not set to "none" build system adds libdl
167 // to the list of static libraries which needs to be
168 // avoided in the case of building loader.
169 stl: "none",
170
Colin Cross97f0aef2016-07-14 16:05:46 -0700171 // we don't want crtbegin.o (because we have begin.o), so unset it
172 // just for this module
173 nocrt: true,
174
175 static_libs: [
176 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800177 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700178 "libziparchive",
179 "libutils",
180 "libbase",
181 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800182
Dan Willemsen4326d842017-05-07 13:07:41 -0700183 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800184
Colin Cross97f0aef2016-07-14 16:05:46 -0700185 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800186 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700187
188 // Important: The liblinker_malloc should be the last library in the list
189 // to overwrite any other malloc implementations by other static libraries.
190 "liblinker_malloc"
191 ],
192 static_executable: true,
193
194 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800195 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700196 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700197 lib64: {
198 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800199 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700200 },
201 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800202 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700203 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800204 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700205 android64: {
206 cflags: ["-DTARGET_IS_64_BIT"],
207 },
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800208 linux_bionic: {
209 cflags: ["-DTARGET_IS_64_BIT"],
210 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700211 },
212 compile_multilib: "both",
213
214 // Leave the symbols in the shared library so that stack unwinders can produce
215 // meaningful name resolution.
216 strip: {
217 keep_symbols: true,
218 },
219
220 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
221 // looking up symbols in the linker by mistake.
222 prefix_symbols: "__dl_",
223}
dimitry11da1dc2018-01-05 13:35:43 +0100224
225cc_library {
226 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
227 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
228 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
229 // to provide those symbols, but will instead pull them from libgcc.a. Specifically,
230 // we use this property to make sure libc.so has its own copy of the code from
231 // libgcc.a it uses.
232 //
233 // DO NOT REMOVE --exclude-libs!
234
235 ldflags: ["-Wl,--exclude-libs=libgcc.a"],
236
237 // for x86, exclude libgcc_eh.a for the same reasons as above
238 arch: {
dimitry581723e2018-01-05 14:31:44 +0100239 arm: {
240 version_script: "linker.arm.map",
241 },
242 arm64: {
243 version_script: "linker.generic.map",
244 },
dimitry11da1dc2018-01-05 13:35:43 +0100245 x86: {
246 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100247 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100248 },
249 x86_64: {
250 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
dimitry581723e2018-01-05 14:31:44 +0100251 version_script: "linker.generic.map",
252 },
253 mips: {
254 version_script: "linker.generic.map",
255 },
256 mips64: {
257 version_script: "linker.generic.map",
dimitry11da1dc2018-01-05 13:35:43 +0100258 },
259 },
dimitry581723e2018-01-05 14:31:44 +0100260
261 srcs: ["ld_android.cpp"],
dimitry11da1dc2018-01-05 13:35:43 +0100262 cflags: [
263 "-Wall",
264 "-Wextra",
265 "-Wunused",
266 "-Werror",
267 ],
268 stl: "none",
269
270 name: "ld-android",
271 defaults: ["linux_bionic_supported"],
272
273 // NOTE: ld-android.so needs __aeabi_unwind_cpp_pr0 from libgcc.a but libgcc.a
274 // needs a few symbols from libc. Using --no-undefined here results in having to
275 // link against libc creating a circular dependency which is removed and we end
276 // up with missing symbols. Since this library is just a bunch of stubs, we set
277 // allow_undefined_symbols to remove --no-undefined from the linker flags.
278 allow_undefined_symbols: true,
279 system_shared_libs: [],
280
281 sanitize: {
282 never: true,
283 },
284}