blob: 9125fd60e647ebe2d891a54af4d0f92bbf5aca5d [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 ],
9
10 // We need to access Bionic private headers in the linker.
11 include_dirs: ["bionic/libc"],
Christopher Ferris7a3681e2017-04-24 17:48:32 -070012
13 static_libs: ["libasync_safe"],
Colin Cross97f0aef2016-07-14 16:05:46 -070014}
15
Dan Willemsen7ccc50d2017-09-18 21:28:14 -070016// This is used for bionic on (host) Linux to bootstrap our linker embedded into
17// a binary.
18//
19// Host bionic binaries do not have a PT_INTERP section, instead this gets
20// embedded as the entry point, and the linker is embedded as ELF sections in
21// each binary. There's a linker script that sets all of that up (generated by
22// extract_linker), and defines the extern symbols used in this file.
23cc_object {
24 name: "linker_wrapper",
25 host_supported: true,
26 device_supported: false,
27 target: {
28 linux_bionic: { enabled: true },
29 linux: { enabled: false },
30 darwin: { enabled: false },
31 },
32
33 cflags: [
34 "-fno-stack-protector",
35 "-Wstrict-overflow=5",
36 "-fvisibility=hidden",
37 "-Wall",
38 "-Wextra",
39 "-Wno-unused",
40 "-Werror",
41 ],
42
43 srcs: [
44 "linker_wrapper.cpp",
45 ],
46 arch: {
47 x86_64: {
48 srcs: ["arch/x86_64/begin.S"],
49 },
50 },
51
52 prefix_symbols: "__dlwrap_",
53
54 // We need to access Bionic private headers in the linker.
55 include_dirs: ["bionic/libc"],
56}
57
Colin Cross97f0aef2016-07-14 16:05:46 -070058cc_binary {
Dan Willemsen7ec52b12016-11-28 17:02:25 -080059 defaults: ["linux_bionic_supported"],
Colin Cross97f0aef2016-07-14 16:05:46 -070060 srcs: [
61 "dlfcn.cpp",
62 "linker.cpp",
63 "linker_block_allocator.cpp",
Dimitry Ivanov769b33f2016-07-21 11:33:40 -070064 "linker_dlwarning.cpp",
Evgenii Stepanov0a3637d2016-07-06 13:20:59 -070065 "linker_cfi.cpp",
Dimitry Ivanov4cabfaa2017-03-07 11:19:05 -080066 "linker_config.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070067 "linker_gdb_support.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070068 "linker_globals.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070069 "linker_libc_support.c",
Dimitry Ivanov451909d2017-01-26 16:52:59 -080070 "linker_libcxx_support.cpp",
Dimitry Ivanov3f660572016-09-09 10:00:39 -070071 "linker_main.cpp",
Dimitry Ivanovb943f302016-08-03 16:00:10 -070072 "linker_namespaces.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070073 "linker_logger.cpp",
74 "linker_mapped_file_fragment.cpp",
75 "linker_phdr.cpp",
76 "linker_sdk_versions.cpp",
Dimitry Ivanov48ec2882016-08-04 11:50:36 -070077 "linker_soinfo.cpp",
Colin Cross97f0aef2016-07-14 16:05:46 -070078 "linker_utils.cpp",
79 "rt.cpp",
80 ],
81
82 arch: {
83 arm: {
dimitry25bf29b2017-08-29 13:38:04 +020084 srcs: [
85 "arch/arm/begin.S",
86 "linker_exidx_static.c",
87 ],
Colin Cross97f0aef2016-07-14 16:05:46 -070088
89 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +020090 version_script: "linker.arm.map",
Colin Cross97f0aef2016-07-14 16:05:46 -070091 },
92 arm64: {
93 srcs: ["arch/arm64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +020094 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -070095 },
96 x86: {
97 srcs: ["arch/x86/begin.c"],
98
99 cflags: ["-D__work_around_b_24465209__"],
dimitry7abea572017-08-29 18:14:49 +0200100 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700101 },
102 x86_64: {
103 srcs: ["arch/x86_64/begin.S"],
dimitry7abea572017-08-29 18:14:49 +0200104 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700105 },
106 mips: {
107 srcs: [
108 "arch/mips/begin.S",
109 "linker_mips.cpp",
110 ],
dimitry7abea572017-08-29 18:14:49 +0200111 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700112 },
113 mips64: {
114 srcs: [
115 "arch/mips64/begin.S",
116 "linker_mips.cpp",
117 ],
dimitry7abea572017-08-29 18:14:49 +0200118 version_script: "linker.generic.map",
Colin Cross97f0aef2016-07-14 16:05:46 -0700119 },
120 },
121
122 // We need to access Bionic private headers in the linker.
123 include_dirs: ["bionic/libc"],
124
125 // -shared is used to overwrite the -Bstatic and -static
126 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE.
127 // This dynamic linker is actually a shared object linked with static libraries.
128 ldflags: [
129 "-shared",
130 "-Wl,-Bsymbolic",
131 "-Wl,--exclude-libs,ALL",
132 ],
133
134 cflags: [
135 "-fno-stack-protector",
136 "-Wstrict-overflow=5",
137 "-fvisibility=hidden",
138 "-Wall",
139 "-Wextra",
140 "-Wunused",
141 "-Werror",
142 ],
143
144 // TODO: split out the asflags.
145 asflags: [
146 "-fno-stack-protector",
147 "-Wstrict-overflow=5",
148 "-fvisibility=hidden",
149 "-Wall",
150 "-Wextra",
151 "-Wunused",
152 "-Werror",
153 ],
154
Jiyong Park02586a22017-05-20 01:01:24 +0900155 product_variables: {
156 debuggable: {
157 cppflags: ["-DUSE_LD_CONFIG_FILE"],
158 },
159 },
160
Colin Cross97f0aef2016-07-14 16:05:46 -0700161 cppflags: ["-Wold-style-cast"],
162
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800163 // we are going to link libc++_static manually because
164 // when stl is not set to "none" build system adds libdl
165 // to the list of static libraries which needs to be
166 // avoided in the case of building loader.
167 stl: "none",
168
Colin Cross97f0aef2016-07-14 16:05:46 -0700169 // we don't want crtbegin.o (because we have begin.o), so unset it
170 // just for this module
171 nocrt: true,
172
173 static_libs: [
174 "libc_nomalloc",
Dimitry Ivanov451909d2017-01-26 16:52:59 -0800175 "libm",
Colin Cross97f0aef2016-07-14 16:05:46 -0700176 "libziparchive",
177 "libutils",
178 "libbase",
179 "libz",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800180
Dan Willemsen4326d842017-05-07 13:07:41 -0700181 "libasync_safe",
Josh Gaoec0dbc32017-02-08 17:27:20 -0800182
Colin Cross97f0aef2016-07-14 16:05:46 -0700183 "liblog",
Dimitry Ivanovfc0d4802016-12-06 11:10:09 -0800184 "libc++_static",
Colin Cross97f0aef2016-07-14 16:05:46 -0700185
186 // Important: The liblinker_malloc should be the last library in the list
187 // to overwrite any other malloc implementations by other static libraries.
188 "liblinker_malloc"
189 ],
190 static_executable: true,
191
192 name: "linker",
Colin Cross10fffb42016-12-08 09:57:35 -0800193 symlinks: ["linker_asan"],
Colin Cross97f0aef2016-07-14 16:05:46 -0700194 multilib: {
Colin Cross97f0aef2016-07-14 16:05:46 -0700195 lib64: {
196 suffix: "64",
Colin Cross10fffb42016-12-08 09:57:35 -0800197 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700198 },
199 target: {
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800200 android: {
Dan Willemsen4326d842017-05-07 13:07:41 -0700201 static_libs: ["libdebuggerd_handler_fallback"],
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800202 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700203 android64: {
204 cflags: ["-DTARGET_IS_64_BIT"],
205 },
Dan Willemsen7ec52b12016-11-28 17:02:25 -0800206 linux_bionic: {
207 cflags: ["-DTARGET_IS_64_BIT"],
208 },
Colin Cross97f0aef2016-07-14 16:05:46 -0700209 },
210 compile_multilib: "both",
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}