Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 1 | cc_library_static { |
| 2 | name: "liblinker_malloc", |
Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 3 | defaults: ["linux_bionic_supported"], |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 4 | |
| 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 Ferris | 7a3681e | 2017-04-24 17:48:32 -0700 | [diff] [blame] | 12 | |
| 13 | static_libs: ["libasync_safe"], |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 14 | } |
| 15 | |
Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 16 | // 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. |
| 23 | cc_object { |
| 24 | name: "linker_wrapper", |
| 25 | host_supported: true, |
| 26 | device_supported: false, |
| 27 | target: { |
| 28 | linux_bionic: { enabled: true }, |
Dan Willemsen | 3a3982d | 2017-10-02 10:41:07 -0700 | [diff] [blame^] | 29 | linux_glibc: { enabled: false }, |
Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 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 Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 58 | cc_binary { |
Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 59 | defaults: ["linux_bionic_supported"], |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 60 | srcs: [ |
| 61 | "dlfcn.cpp", |
| 62 | "linker.cpp", |
| 63 | "linker_block_allocator.cpp", |
Dimitry Ivanov | 769b33f | 2016-07-21 11:33:40 -0700 | [diff] [blame] | 64 | "linker_dlwarning.cpp", |
Evgenii Stepanov | 0a3637d | 2016-07-06 13:20:59 -0700 | [diff] [blame] | 65 | "linker_cfi.cpp", |
Dimitry Ivanov | 4cabfaa | 2017-03-07 11:19:05 -0800 | [diff] [blame] | 66 | "linker_config.cpp", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 67 | "linker_gdb_support.cpp", |
Dimitry Ivanov | 48ec288 | 2016-08-04 11:50:36 -0700 | [diff] [blame] | 68 | "linker_globals.cpp", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 69 | "linker_libc_support.c", |
Dimitry Ivanov | 451909d | 2017-01-26 16:52:59 -0800 | [diff] [blame] | 70 | "linker_libcxx_support.cpp", |
Dimitry Ivanov | 3f66057 | 2016-09-09 10:00:39 -0700 | [diff] [blame] | 71 | "linker_main.cpp", |
Dimitry Ivanov | b943f30 | 2016-08-03 16:00:10 -0700 | [diff] [blame] | 72 | "linker_namespaces.cpp", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 73 | "linker_logger.cpp", |
| 74 | "linker_mapped_file_fragment.cpp", |
| 75 | "linker_phdr.cpp", |
| 76 | "linker_sdk_versions.cpp", |
Dimitry Ivanov | 48ec288 | 2016-08-04 11:50:36 -0700 | [diff] [blame] | 77 | "linker_soinfo.cpp", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 78 | "linker_utils.cpp", |
| 79 | "rt.cpp", |
| 80 | ], |
| 81 | |
| 82 | arch: { |
| 83 | arm: { |
dimitry | 25bf29b | 2017-08-29 13:38:04 +0200 | [diff] [blame] | 84 | srcs: [ |
| 85 | "arch/arm/begin.S", |
| 86 | "linker_exidx_static.c", |
| 87 | ], |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 88 | |
| 89 | cflags: ["-D__work_around_b_24465209__"], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 90 | version_script: "linker.arm.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 91 | }, |
| 92 | arm64: { |
| 93 | srcs: ["arch/arm64/begin.S"], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 94 | version_script: "linker.generic.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 95 | }, |
| 96 | x86: { |
| 97 | srcs: ["arch/x86/begin.c"], |
| 98 | |
| 99 | cflags: ["-D__work_around_b_24465209__"], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 100 | version_script: "linker.generic.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 101 | }, |
| 102 | x86_64: { |
| 103 | srcs: ["arch/x86_64/begin.S"], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 104 | version_script: "linker.generic.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 105 | }, |
| 106 | mips: { |
| 107 | srcs: [ |
| 108 | "arch/mips/begin.S", |
| 109 | "linker_mips.cpp", |
| 110 | ], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 111 | version_script: "linker.generic.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 112 | }, |
| 113 | mips64: { |
| 114 | srcs: [ |
| 115 | "arch/mips64/begin.S", |
| 116 | "linker_mips.cpp", |
| 117 | ], |
dimitry | 7abea57 | 2017-08-29 18:14:49 +0200 | [diff] [blame] | 118 | version_script: "linker.generic.map", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 119 | }, |
| 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 Park | 02586a2 | 2017-05-20 01:01:24 +0900 | [diff] [blame] | 155 | product_variables: { |
| 156 | debuggable: { |
| 157 | cppflags: ["-DUSE_LD_CONFIG_FILE"], |
| 158 | }, |
| 159 | }, |
| 160 | |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 161 | cppflags: ["-Wold-style-cast"], |
| 162 | |
Dimitry Ivanov | fc0d480 | 2016-12-06 11:10:09 -0800 | [diff] [blame] | 163 | // 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 Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 169 | // 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 Ivanov | 451909d | 2017-01-26 16:52:59 -0800 | [diff] [blame] | 175 | "libm", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 176 | "libziparchive", |
| 177 | "libutils", |
| 178 | "libbase", |
| 179 | "libz", |
Josh Gao | ec0dbc3 | 2017-02-08 17:27:20 -0800 | [diff] [blame] | 180 | |
Dan Willemsen | 4326d84 | 2017-05-07 13:07:41 -0700 | [diff] [blame] | 181 | "libasync_safe", |
Josh Gao | ec0dbc3 | 2017-02-08 17:27:20 -0800 | [diff] [blame] | 182 | |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 183 | "liblog", |
Dimitry Ivanov | fc0d480 | 2016-12-06 11:10:09 -0800 | [diff] [blame] | 184 | "libc++_static", |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 185 | |
| 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 Cross | 10fffb4 | 2016-12-08 09:57:35 -0800 | [diff] [blame] | 193 | symlinks: ["linker_asan"], |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 194 | multilib: { |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 195 | lib64: { |
| 196 | suffix: "64", |
Colin Cross | 10fffb4 | 2016-12-08 09:57:35 -0800 | [diff] [blame] | 197 | }, |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 198 | }, |
| 199 | target: { |
Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 200 | android: { |
Dan Willemsen | 4326d84 | 2017-05-07 13:07:41 -0700 | [diff] [blame] | 201 | static_libs: ["libdebuggerd_handler_fallback"], |
Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 202 | }, |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 203 | android64: { |
| 204 | cflags: ["-DTARGET_IS_64_BIT"], |
| 205 | }, |
Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 206 | linux_bionic: { |
| 207 | cflags: ["-DTARGET_IS_64_BIT"], |
| 208 | }, |
Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 209 | }, |
| 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 | } |