blob: c8c125681dd0981dfec8fd4f747959f04c71933b [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 },
30 linux: { enabled: false },
31 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",
133 ],
134
135 cflags: [
136 "-fno-stack-protector",
137 "-Wstrict-overflow=5",
138 "-fvisibility=hidden",
139 "-Wall",
140 "-Wextra",
141 "-Wunused",
142 "-Werror",
143 ],
144
145 // TODO: split out the asflags.
146 asflags: [
147 "-fno-stack-protector",
148 "-Wstrict-overflow=5",
149 "-fvisibility=hidden",
150 "-Wall",
151 "-Wextra",
152 "-Wunused",
153 "-Werror",
154 ],
155
Jiyong Park02586a22017-05-20 01:01:24 +0900156 product_variables: {
157 debuggable: {
158 cppflags: ["-DUSE_LD_CONFIG_FILE"],
159 },
160 },
161
Colin Cross97f0aef2016-07-14 16:05:46 -0700162 cppflags: ["-Wold-style-cast"],
163
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800164 // we are going to link libc++_static manually because
165 // when stl is not set to "none" build system adds libdl
166 // to the list of static libraries which needs to be
167 // avoided in the case of building loader.
168 stl: "none",
169
Colin Cross97f0aef2016-07-14 16:05:46 -0700170 // we don't want crtbegin.o (because we have begin.o), so unset it
171 // just for this module
172 nocrt: true,
173
174 static_libs: [
175 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800176 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700177 "libziparchive",
178 "libutils",
179 "libbase",
180 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800181
Dan Willemsen4326d842017-05-07 13:07:41 -0700182 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800183
Colin Cross97f0aef2016-07-14 16:05:46 -0700184 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800185 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700186
187 // Important: The liblinker_malloc should be the last library in the list
188 // to overwrite any other malloc implementations by other static libraries.
189 "liblinker_malloc"
190 ],
191 static_executable: true,
192
193 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800194 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700195 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700196 lib64: {
197 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800198 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700199 },
200 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800201 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700202 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800203 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700204 android64: {
205 cflags: ["-DTARGET_IS_64_BIT"],
206 },
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800207 linux_bionic: {
208 cflags: ["-DTARGET_IS_64_BIT"],
209 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700210 },
211 compile_multilib: "both",
212
213 // Leave the symbols in the shared library so that stack unwinders can produce
214 // meaningful name resolution.
215 strip: {
216 keep_symbols: true,
217 },
218
219 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
220 // looking up symbols in the linker by mistake.
221 prefix_symbols: "__dl_",
222}