| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 1 | // ======================================================== | 
|  | 2 | // linker_wrapper - Linux Bionic (on the host) | 
|  | 3 | // ======================================================== | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 4 |  | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 5 | // This is used for bionic on (host) Linux to bootstrap our linker embedded into | 
|  | 6 | // a binary. | 
|  | 7 | // | 
|  | 8 | // Host bionic binaries do not have a PT_INTERP section, instead this gets | 
|  | 9 | // embedded as the entry point, and the linker is embedded as ELF sections in | 
|  | 10 | // each binary. There's a linker script that sets all of that up (generated by | 
|  | 11 | // extract_linker), and defines the extern symbols used in this file. | 
| Bob Badour | aa7d835 | 2021-02-19 13:06:22 -0800 | [diff] [blame] | 12 | package { | 
|  | 13 | default_applicable_licenses: ["bionic_linker_license"], | 
|  | 14 | } | 
|  | 15 |  | 
|  | 16 | license { | 
|  | 17 | name: "bionic_linker_license", | 
|  | 18 | visibility: [":__subpackages__"], | 
|  | 19 | license_kinds: [ | 
|  | 20 | "SPDX-license-identifier-BSD", | 
|  | 21 | ], | 
|  | 22 | license_text: [ | 
|  | 23 | "NOTICE", | 
|  | 24 | ], | 
|  | 25 | } | 
|  | 26 |  | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 27 | cc_object { | 
|  | 28 | name: "linker_wrapper", | 
|  | 29 | host_supported: true, | 
|  | 30 | device_supported: false, | 
|  | 31 | target: { | 
| Elliott Hughes | d50a1de | 2018-02-05 17:30:57 -0800 | [diff] [blame] | 32 | linux_bionic: { | 
|  | 33 | enabled: true, | 
|  | 34 | }, | 
|  | 35 | linux_glibc: { | 
|  | 36 | enabled: false, | 
|  | 37 | }, | 
|  | 38 | darwin: { | 
|  | 39 | enabled: false, | 
|  | 40 | }, | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 41 | }, | 
|  | 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: { | 
| Jiyong Park | 3b47d60 | 2020-09-18 16:15:53 +0900 | [diff] [blame] | 57 | arm64: { | 
| Colin Cross | a0a591a | 2021-06-11 12:46:45 -0700 | [diff] [blame] | 58 | srcs: ["arch/arm64/linker_wrapper_begin.S"], | 
| Jiyong Park | 3b47d60 | 2020-09-18 16:15:53 +0900 | [diff] [blame] | 59 | }, | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 60 | x86_64: { | 
| Colin Cross | a0a591a | 2021-06-11 12:46:45 -0700 | [diff] [blame] | 61 | srcs: ["arch/x86_64/linker_wrapper_begin.S"], | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 62 | }, | 
|  | 63 | }, | 
|  | 64 |  | 
| Martin Stjernholm | 82d84bc | 2020-04-06 20:32:09 +0100 | [diff] [blame] | 65 | header_libs: ["libc_headers"], | 
|  | 66 |  | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 67 | // We need to access Bionic private headers in the linker. | 
|  | 68 | include_dirs: ["bionic/libc"], | 
| Jingwen Chen | c579478 | 2021-03-10 03:24:48 -0500 | [diff] [blame] | 69 |  | 
|  | 70 | // b/182338959 | 
|  | 71 | bazel_module: { bp2build_available: false }, | 
| Dan Willemsen | 7ccc50d | 2017-09-18 21:28:14 -0700 | [diff] [blame] | 72 | } | 
|  | 73 |  | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 74 | // ======================================================== | 
|  | 75 | // linker default configuration | 
|  | 76 | // ======================================================== | 
|  | 77 |  | 
|  | 78 | // Configuration for the linker binary and any of its static libraries. | 
|  | 79 | cc_defaults { | 
|  | 80 | name: "linker_defaults", | 
|  | 81 | arch: { | 
|  | 82 | arm: { | 
|  | 83 | cflags: ["-D__work_around_b_24465209__"], | 
|  | 84 | }, | 
|  | 85 | x86: { | 
|  | 86 | cflags: ["-D__work_around_b_24465209__"], | 
|  | 87 | }, | 
|  | 88 | }, | 
|  | 89 |  | 
|  | 90 | cflags: [ | 
|  | 91 | "-fno-stack-protector", | 
|  | 92 | "-Wstrict-overflow=5", | 
|  | 93 | "-fvisibility=hidden", | 
|  | 94 | "-Wall", | 
|  | 95 | "-Wextra", | 
|  | 96 | "-Wunused", | 
|  | 97 | "-Werror", | 
|  | 98 | ], | 
|  | 99 |  | 
|  | 100 | // TODO: split out the asflags. | 
|  | 101 | asflags: [ | 
|  | 102 | "-fno-stack-protector", | 
|  | 103 | "-Wstrict-overflow=5", | 
|  | 104 | "-fvisibility=hidden", | 
|  | 105 | "-Wall", | 
|  | 106 | "-Wextra", | 
|  | 107 | "-Wunused", | 
|  | 108 | "-Werror", | 
|  | 109 | ], | 
|  | 110 |  | 
|  | 111 | product_variables: { | 
|  | 112 | debuggable: { | 
|  | 113 | cppflags: ["-DUSE_LD_CONFIG_FILE"], | 
|  | 114 | }, | 
|  | 115 | }, | 
|  | 116 |  | 
|  | 117 | cppflags: ["-Wold-style-cast"], | 
|  | 118 |  | 
|  | 119 | static_libs: [ | 
|  | 120 | "libziparchive", | 
|  | 121 | "libbase", | 
|  | 122 | "libz", | 
|  | 123 |  | 
|  | 124 | "libasync_safe", | 
|  | 125 |  | 
|  | 126 | "liblog", | 
|  | 127 | ], | 
|  | 128 |  | 
|  | 129 | // We need to access Bionic private headers in the linker. | 
|  | 130 | include_dirs: ["bionic/libc"], | 
|  | 131 | } | 
|  | 132 |  | 
|  | 133 | // ======================================================== | 
|  | 134 | // linker components | 
|  | 135 | // ======================================================== | 
|  | 136 |  | 
|  | 137 | // Enable a module on all targets the linker runs on (ordinary Android targets, Linux Bionic, and | 
|  | 138 | // native bridge implementations). | 
|  | 139 | cc_defaults { | 
|  | 140 | name: "linker_all_targets", | 
|  | 141 | defaults: ["linux_bionic_supported"], | 
|  | 142 | recovery_available: true, | 
| Yifan Hong | b04490d | 2020-10-21 18:36:36 -0700 | [diff] [blame] | 143 | vendor_ramdisk_available: true, | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 144 | native_bridge_supported: true, | 
|  | 145 | } | 
|  | 146 |  | 
|  | 147 | cc_library_static { | 
| Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 148 | name: "liblinker_main", | 
|  | 149 | defaults: ["linker_defaults", "linker_all_targets"], | 
|  | 150 | srcs: ["linker_main.cpp"], | 
|  | 151 |  | 
|  | 152 | // Ensure that the compiler won't insert string function calls before ifuncs are resolved. | 
|  | 153 | cflags: ["-ffreestanding"], | 
|  | 154 | } | 
|  | 155 |  | 
|  | 156 | cc_library_static { | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 157 | name: "liblinker_malloc", | 
|  | 158 | defaults: ["linker_defaults", "linker_all_targets"], | 
|  | 159 | srcs: ["linker_memory.cpp"], | 
|  | 160 | } | 
|  | 161 |  | 
|  | 162 | cc_library_static { | 
|  | 163 | name: "liblinker_debuggerd_stub", | 
|  | 164 | defaults: ["linker_defaults", "linker_all_targets"], | 
|  | 165 | srcs: ["linker_debuggerd_stub.cpp"], | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | // ======================================================== | 
|  | 169 | // template for the linker binary | 
|  | 170 | // ======================================================== | 
|  | 171 |  | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 172 | filegroup { | 
|  | 173 | name: "linker_sources", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 174 | srcs: [ | 
|  | 175 | "dlfcn.cpp", | 
|  | 176 | "linker.cpp", | 
|  | 177 | "linker_block_allocator.cpp", | 
| Dimitry Ivanov | 769b33f | 2016-07-21 11:33:40 -0700 | [diff] [blame] | 178 | "linker_dlwarning.cpp", | 
| Evgenii Stepanov | 0a3637d | 2016-07-06 13:20:59 -0700 | [diff] [blame] | 179 | "linker_cfi.cpp", | 
| Dimitry Ivanov | 4cabfaa | 2017-03-07 11:19:05 -0800 | [diff] [blame] | 180 | "linker_config.cpp", | 
| Ryan Prichard | 551565e | 2019-12-23 16:03:14 -0800 | [diff] [blame] | 181 | "linker_debug.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 182 | "linker_gdb_support.cpp", | 
| Dimitry Ivanov | 48ec288 | 2016-08-04 11:50:36 -0700 | [diff] [blame] | 183 | "linker_globals.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 184 | "linker_libc_support.c", | 
| Dimitry Ivanov | 451909d | 2017-01-26 16:52:59 -0800 | [diff] [blame] | 185 | "linker_libcxx_support.cpp", | 
| Dimitry Ivanov | b943f30 | 2016-08-03 16:00:10 -0700 | [diff] [blame] | 186 | "linker_namespaces.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 187 | "linker_logger.cpp", | 
|  | 188 | "linker_mapped_file_fragment.cpp", | 
| Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 189 | "linker_note_gnu_property.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 190 | "linker_phdr.cpp", | 
| Ryan Prichard | 339ecef | 2020-01-02 16:36:06 -0800 | [diff] [blame] | 191 | "linker_relocate.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 192 | "linker_sdk_versions.cpp", | 
| Dimitry Ivanov | 48ec288 | 2016-08-04 11:50:36 -0700 | [diff] [blame] | 193 | "linker_soinfo.cpp", | 
| Collin Fijalkovich | 47d27aa | 2021-03-24 10:17:39 -0700 | [diff] [blame] | 194 | "linker_transparent_hugepage_support.cpp", | 
| Ryan Prichard | 45d1349 | 2019-01-03 02:51:30 -0800 | [diff] [blame] | 195 | "linker_tls.cpp", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 196 | "linker_utils.cpp", | 
|  | 197 | "rt.cpp", | 
|  | 198 | ], | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 199 | } | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 200 |  | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 201 | filegroup { | 
|  | 202 | name: "linker_sources_arm", | 
|  | 203 | srcs: [ | 
|  | 204 | "arch/arm/begin.S", | 
| Ryan Prichard | 129f7a1 | 2019-12-23 16:45:47 -0800 | [diff] [blame] | 205 | "arch/arm_neon/linker_gnu_hash_neon.cpp", | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 206 | ], | 
|  | 207 | } | 
|  | 208 |  | 
|  | 209 | filegroup { | 
|  | 210 | name: "linker_sources_arm64", | 
|  | 211 | srcs: [ | 
|  | 212 | "arch/arm64/begin.S", | 
| Ryan Prichard | ffaae70 | 2019-01-23 17:47:10 -0800 | [diff] [blame] | 213 | "arch/arm64/tlsdesc_resolver.S", | 
| Ryan Prichard | 129f7a1 | 2019-12-23 16:45:47 -0800 | [diff] [blame] | 214 | "arch/arm_neon/linker_gnu_hash_neon.cpp", | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 215 | ], | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | filegroup { | 
|  | 219 | name: "linker_sources_x86", | 
|  | 220 | srcs: [ | 
|  | 221 | "arch/x86/begin.S", | 
|  | 222 | ], | 
|  | 223 | } | 
|  | 224 |  | 
|  | 225 | filegroup { | 
|  | 226 | name: "linker_sources_x86_64", | 
|  | 227 | srcs: [ | 
|  | 228 | "arch/x86_64/begin.S", | 
|  | 229 | ], | 
|  | 230 | } | 
|  | 231 |  | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 232 | cc_defaults { | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 233 | name: "linker_version_script_overlay", | 
|  | 234 | arch: { | 
|  | 235 | arm:    { version_script: "linker.arm.map"      }, | 
|  | 236 | arm64:  { version_script: "linker.generic.map"  }, | 
|  | 237 | x86:    { version_script: "linker.generic.map"  }, | 
|  | 238 | x86_64: { version_script: "linker.generic.map"  }, | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 239 | }, | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | // A template for the linker binary. May be inherited by native bridge implementations. | 
|  | 243 | cc_defaults { | 
|  | 244 | name: "linker_bin_template", | 
|  | 245 | defaults: ["linker_defaults"], | 
|  | 246 |  | 
|  | 247 | srcs: [":linker_sources"], | 
|  | 248 |  | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 249 | arch: { | 
|  | 250 | arm: { | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 251 | srcs: [":linker_sources_arm"], | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 252 | }, | 
|  | 253 | arm64: { | 
|  | 254 | srcs: [":linker_sources_arm64"], | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 255 | }, | 
|  | 256 | x86: { | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 257 | srcs: [":linker_sources_x86"], | 
|  | 258 | }, | 
|  | 259 | x86_64: { | 
|  | 260 | srcs: [":linker_sources_x86_64"], | 
|  | 261 | }, | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 262 | }, | 
|  | 263 |  | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 264 | // -shared is used to overwrite the -Bstatic and -static flags triggered by enabling | 
|  | 265 | // static_executable. This dynamic linker is actually a shared object linked with static | 
|  | 266 | // libraries. | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 267 | ldflags: [ | 
|  | 268 | "-shared", | 
|  | 269 | "-Wl,-Bsymbolic", | 
|  | 270 | "-Wl,--exclude-libs,ALL", | 
| dimitry | 8e8c2c0 | 2018-01-04 12:08:32 +0100 | [diff] [blame] | 271 | "-Wl,-soname,ld-android.so", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 272 | ], | 
|  | 273 |  | 
| Dimitry Ivanov | fc0d480 | 2016-12-06 11:10:09 -0800 | [diff] [blame] | 274 | // we are going to link libc++_static manually because | 
|  | 275 | // when stl is not set to "none" build system adds libdl | 
|  | 276 | // to the list of static libraries which needs to be | 
|  | 277 | // avoided in the case of building loader. | 
|  | 278 | stl: "none", | 
|  | 279 |  | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 280 | // we don't want crtbegin.o (because we have begin.o), so unset it | 
|  | 281 | // just for this module | 
|  | 282 | nocrt: true, | 
|  | 283 |  | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 284 | static_executable: true, | 
|  | 285 |  | 
|  | 286 | // Leave the symbols in the shared library so that stack unwinders can produce | 
|  | 287 | // meaningful name resolution. | 
|  | 288 | strip: { | 
|  | 289 | keep_symbols: true, | 
|  | 290 | }, | 
|  | 291 |  | 
|  | 292 | // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb | 
|  | 293 | // looking up symbols in the linker by mistake. | 
|  | 294 | prefix_symbols: "__dl_", | 
|  | 295 |  | 
|  | 296 | sanitize: { | 
|  | 297 | hwaddress: false, | 
|  | 298 | }, | 
| dimitry | b8b3a76 | 2018-09-25 12:31:11 +0200 | [diff] [blame] | 299 |  | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 300 | static_libs: [ | 
| Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 301 | "liblinker_main", | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 302 | "liblinker_malloc", | 
|  | 303 |  | 
|  | 304 | "libc++_static", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 305 | "libc_nomalloc", | 
| Ryan Prichard | 249757b | 2019-11-01 17:18:28 -0700 | [diff] [blame] | 306 | "libc_dynamic_dispatch", | 
| Dimitry Ivanov | 451909d | 2017-01-26 16:52:59 -0800 | [diff] [blame] | 307 | "libm", | 
| Ryan Prichard | cdf7175 | 2020-12-16 03:37:22 -0800 | [diff] [blame] | 308 | "libunwind", | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 309 | ], | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 310 |  | 
| Ryan Prichard | d9a4115 | 2019-10-14 16:58:53 -0700 | [diff] [blame] | 311 | // Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a | 
|  | 312 | // definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak | 
|  | 313 | // reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition | 
|  | 314 | // of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a | 
|  | 315 | // non-relative dynamic relocation in the linker binary, which complicates linker startup. | 
|  | 316 | // | 
|  | 317 | // This line should be unnecessary because the linker's dependency on libunwind_llvm.a should | 
|  | 318 | // override libgcc.a, but this line provides a simpler guarantee. It can be removed once the | 
|  | 319 | // linker stops linking against libgcc.a's arm32 unwinder. | 
|  | 320 | whole_static_libs: ["libc_unwind_static"], | 
|  | 321 |  | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 322 | system_shared_libs: [], | 
|  | 323 |  | 
|  | 324 | // Opt out of native_coverage when opting out of system_shared_libs | 
|  | 325 | native_coverage: false, | 
|  | 326 | } | 
|  | 327 |  | 
|  | 328 | // ======================================================== | 
|  | 329 | // linker[_asan][64] binary | 
|  | 330 | // ======================================================== | 
|  | 331 |  | 
|  | 332 | cc_binary { | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 333 | name: "linker", | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 334 | defaults: [ | 
|  | 335 | "linker_bin_template", | 
|  | 336 | "linux_bionic_supported", | 
|  | 337 | "linker_version_script_overlay", | 
|  | 338 | ], | 
|  | 339 |  | 
| Victor Khimenko | d15229d | 2020-05-14 22:14:45 +0200 | [diff] [blame] | 340 | srcs: [ | 
|  | 341 | "linker_translate_path.cpp", | 
|  | 342 | ], | 
|  | 343 |  | 
| Colin Cross | 10fffb4 | 2016-12-08 09:57:35 -0800 | [diff] [blame] | 344 | symlinks: ["linker_asan"], | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 345 | multilib: { | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 346 | lib64: { | 
|  | 347 | suffix: "64", | 
| Colin Cross | 10fffb4 | 2016-12-08 09:57:35 -0800 | [diff] [blame] | 348 | }, | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 349 | }, | 
| Pirama Arumuga Nainar | fcd3538 | 2019-02-14 13:48:01 -0800 | [diff] [blame] | 350 |  | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 351 | compile_multilib: "both", | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 352 |  | 
|  | 353 | recovery_available: true, | 
| Yifan Hong | b04490d | 2020-10-21 18:36:36 -0700 | [diff] [blame] | 354 | vendor_ramdisk_available: true, | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 355 | apex_available: [ | 
|  | 356 | "//apex_available:platform", | 
|  | 357 | "com.android.runtime", | 
|  | 358 | ], | 
| Pirama Arumuga Nainar | fcd3538 | 2019-02-14 13:48:01 -0800 | [diff] [blame] | 359 |  | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 360 | target: { | 
| Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 361 | android: { | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 362 | srcs: [ | 
|  | 363 | "linker_debuggerd_android.cpp", | 
|  | 364 | ], | 
| Dan Albert | 4ea1921 | 2019-07-23 13:31:14 -0700 | [diff] [blame] | 365 | static_libs: [ | 
|  | 366 | "libc++demangle", | 
|  | 367 | "libdebuggerd_handler_fallback", | 
|  | 368 | ], | 
| Dan Willemsen | 7ec52b1 | 2016-11-28 17:02:25 -0800 | [diff] [blame] | 369 | }, | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 370 | linux_bionic: { | 
|  | 371 | static_libs: [ | 
|  | 372 | "liblinker_debuggerd_stub", | 
|  | 373 | ], | 
| Yi Kong | 6f6daaa | 2020-12-10 01:27:44 +0800 | [diff] [blame] | 374 | }, | 
|  | 375 | android_arm64: { | 
|  | 376 | pgo: { | 
|  | 377 | profile_file: "bionic/linker_arm_arm64.profdata", | 
|  | 378 | }, | 
|  | 379 | }, | 
|  | 380 | android_arm: { | 
|  | 381 | pgo: { | 
|  | 382 | profile_file: "bionic/linker_arm_arm64.profdata", | 
|  | 383 | }, | 
|  | 384 | }, | 
|  | 385 | android_x86_64: { | 
|  | 386 | pgo: { | 
|  | 387 | profile_file: "bionic/linker_x86_x86_64.profdata", | 
|  | 388 | }, | 
|  | 389 | }, | 
|  | 390 | android_x86: { | 
|  | 391 | pgo: { | 
|  | 392 | profile_file: "bionic/linker_x86_x86_64.profdata", | 
|  | 393 | }, | 
|  | 394 | }, | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 395 | }, | 
| Yi Kong | a7e363f | 2020-10-01 04:10:01 +0800 | [diff] [blame] | 396 |  | 
|  | 397 | lto: { | 
|  | 398 | never: true, | 
|  | 399 | }, | 
| Yi Kong | 6f6daaa | 2020-12-10 01:27:44 +0800 | [diff] [blame] | 400 | pgo: { | 
|  | 401 | sampling: true, | 
|  | 402 | }, | 
| Colin Cross | 97f0aef | 2016-07-14 16:05:46 -0700 | [diff] [blame] | 403 | } | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 404 |  | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 405 | // ======================================================== | 
|  | 406 | // assorted modules | 
|  | 407 | // ======================================================== | 
|  | 408 |  | 
| Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 409 | sh_binary { | 
|  | 410 | name: "ldd", | 
| Rupert Shuttleworth | a7e29a8 | 2021-02-18 13:35:22 +0000 | [diff] [blame] | 411 | src: "ldd.sh", | 
| Rupert Shuttleworth | 344b8da | 2021-02-09 11:35:04 +0000 | [diff] [blame] | 412 | bazel_module: { bp2build_available: true }, | 
| Elliott Hughes | 90f96b9 | 2019-05-09 15:56:39 -0700 | [diff] [blame] | 413 | } | 
|  | 414 |  | 
| Collin Fijalkovich | c9521e0 | 2021-04-29 11:31:50 -0700 | [diff] [blame] | 415 | // Used to generate binaries that can be backed by transparent hugepages. | 
|  | 416 | cc_defaults { | 
|  | 417 | name: "linker_hugepage_aligned", | 
|  | 418 | arch: { | 
|  | 419 | arm64: { | 
|  | 420 | ldflags: ["-z max-page-size=0x200000"], | 
|  | 421 | }, | 
|  | 422 | x86_64: { | 
|  | 423 | ldflags: ["-z max-page-size=0x200000"], | 
|  | 424 | }, | 
|  | 425 | }, | 
|  | 426 | } | 
|  | 427 |  | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 428 | cc_library { | 
|  | 429 | // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from | 
|  | 430 | // libgcc.a are made static to ld-android.so.  This in turn ensures that libraries that | 
|  | 431 | // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so | 
|  | 432 | // to provide those symbols, but will instead pull them from libgcc.a.  Specifically, | 
|  | 433 | // we use this property to make sure libc.so has its own copy of the code from | 
|  | 434 | // libgcc.a it uses. | 
|  | 435 | // | 
|  | 436 | // DO NOT REMOVE --exclude-libs! | 
|  | 437 |  | 
| Yi Kong | 7786a34 | 2018-08-31 19:01:56 -0700 | [diff] [blame] | 438 | ldflags: [ | 
|  | 439 | "-Wl,--exclude-libs=libgcc.a", | 
| Yi Kong | 7ac2afb | 2019-05-06 16:23:10 -0700 | [diff] [blame] | 440 | "-Wl,--exclude-libs=libgcc_stripped.a", | 
| Yi Kong | 7786a34 | 2018-08-31 19:01:56 -0700 | [diff] [blame] | 441 | "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", | 
|  | 442 | "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", | 
| Ryan Prichard | ef14787 | 2021-01-28 14:06:52 -0800 | [diff] [blame] | 443 | "-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a", | 
| Yi Kong | 7786a34 | 2018-08-31 19:01:56 -0700 | [diff] [blame] | 444 | "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", | 
|  | 445 | ], | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 446 |  | 
|  | 447 | // for x86, exclude libgcc_eh.a for the same reasons as above | 
|  | 448 | arch: { | 
|  | 449 | x86: { | 
|  | 450 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], | 
|  | 451 | }, | 
|  | 452 | x86_64: { | 
|  | 453 | ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], | 
|  | 454 | }, | 
|  | 455 | }, | 
| dimitry | 581723e | 2018-01-05 14:31:44 +0100 | [diff] [blame] | 456 |  | 
|  | 457 | srcs: ["ld_android.cpp"], | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 458 | cflags: [ | 
|  | 459 | "-Wall", | 
|  | 460 | "-Wextra", | 
|  | 461 | "-Wunused", | 
|  | 462 | "-Werror", | 
|  | 463 | ], | 
|  | 464 | stl: "none", | 
|  | 465 |  | 
|  | 466 | name: "ld-android", | 
| Ryan Prichard | 80e40f0 | 2019-10-31 19:54:46 -0700 | [diff] [blame] | 467 | defaults: ["linux_bionic_supported", "linker_version_script_overlay"], | 
| Yifan Hong | 5a39cee | 2020-01-21 16:43:56 -0800 | [diff] [blame] | 468 | ramdisk_available: true, | 
| Yifan Hong | b04490d | 2020-10-21 18:36:36 -0700 | [diff] [blame] | 469 | vendor_ramdisk_available: true, | 
| Jiyong Park | 5603c6e | 2018-04-27 21:53:11 +0900 | [diff] [blame] | 470 | recovery_available: true, | 
| dimitry | 7f04880 | 2019-05-03 15:57:34 +0200 | [diff] [blame] | 471 | native_bridge_supported: true, | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 472 |  | 
| Ryan Prichard | 470b666 | 2018-03-27 22:10:55 -0700 | [diff] [blame] | 473 | nocrt: true, | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 474 | system_shared_libs: [], | 
| Martin Stjernholm | 82d84bc | 2020-04-06 20:32:09 +0100 | [diff] [blame] | 475 | header_libs: ["libc_headers"], | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 476 |  | 
| Pirama Arumuga Nainar | fcd3538 | 2019-02-14 13:48:01 -0800 | [diff] [blame] | 477 | // Opt out of native_coverage when opting out of system_shared_libs | 
|  | 478 | native_coverage: false, | 
|  | 479 |  | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 480 | sanitize: { | 
|  | 481 | never: true, | 
|  | 482 | }, | 
| Jiyong Park | e87e0dc | 2019-10-02 17:09:33 +0900 | [diff] [blame] | 483 |  | 
|  | 484 | apex_available: [ | 
|  | 485 | "//apex_available:platform", | 
|  | 486 | "com.android.runtime", | 
|  | 487 | ], | 
| Yi Kong | 15a05a7 | 2020-09-22 00:56:13 +0800 | [diff] [blame] | 488 |  | 
|  | 489 | lto: { | 
|  | 490 | never: true, | 
|  | 491 | }, | 
| dimitry | 11da1dc | 2018-01-05 13:35:43 +0100 | [diff] [blame] | 492 | } | 
| Elliott Hughes | 15a2b7b | 2019-02-15 13:48:38 -0800 | [diff] [blame] | 493 |  | 
|  | 494 | cc_test { | 
|  | 495 | name: "linker-unit-tests", | 
|  | 496 |  | 
|  | 497 | cflags: [ | 
|  | 498 | "-g", | 
|  | 499 | "-Wall", | 
|  | 500 | "-Wextra", | 
|  | 501 | "-Wunused", | 
|  | 502 | "-Werror", | 
|  | 503 | ], | 
|  | 504 |  | 
|  | 505 | // We need to access Bionic private headers in the linker. | 
|  | 506 | include_dirs: ["bionic/libc"], | 
|  | 507 |  | 
|  | 508 | srcs: [ | 
|  | 509 | // Tests. | 
|  | 510 | "linker_block_allocator_test.cpp", | 
|  | 511 | "linker_config_test.cpp", | 
|  | 512 | "linked_list_test.cpp", | 
| Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 513 | "linker_note_gnu_property_test.cpp", | 
| Elliott Hughes | 15a2b7b | 2019-02-15 13:48:38 -0800 | [diff] [blame] | 514 | "linker_sleb128_test.cpp", | 
|  | 515 | "linker_utils_test.cpp", | 
| Ryan Prichard | 129f7a1 | 2019-12-23 16:45:47 -0800 | [diff] [blame] | 516 | "linker_gnu_hash_test.cpp", | 
| Elliott Hughes | 15a2b7b | 2019-02-15 13:48:38 -0800 | [diff] [blame] | 517 |  | 
|  | 518 | // Parts of the linker that we're testing. | 
|  | 519 | "linker_block_allocator.cpp", | 
|  | 520 | "linker_config.cpp", | 
| Ryan Prichard | 551565e | 2019-12-23 16:03:14 -0800 | [diff] [blame] | 521 | "linker_debug.cpp", | 
| Tamas Petz | 8d55d18 | 2020-02-24 14:15:25 +0100 | [diff] [blame] | 522 | "linker_note_gnu_property.cpp", | 
| Elliott Hughes | 15a2b7b | 2019-02-15 13:48:38 -0800 | [diff] [blame] | 523 | "linker_test_globals.cpp", | 
|  | 524 | "linker_utils.cpp", | 
|  | 525 | ], | 
|  | 526 |  | 
|  | 527 | static_libs: [ | 
|  | 528 | "libasync_safe", | 
|  | 529 | "libbase", | 
|  | 530 | "liblog", | 
|  | 531 | ], | 
| Ryan Prichard | 129f7a1 | 2019-12-23 16:45:47 -0800 | [diff] [blame] | 532 |  | 
|  | 533 | arch: { | 
|  | 534 | arm: { | 
|  | 535 | srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"], | 
|  | 536 | }, | 
|  | 537 | arm64: { | 
|  | 538 | srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"], | 
|  | 539 | }, | 
|  | 540 | }, | 
|  | 541 | } | 
|  | 542 |  | 
|  | 543 | cc_benchmark { | 
|  | 544 | name: "linker-benchmarks", | 
|  | 545 |  | 
|  | 546 | srcs: [ | 
|  | 547 | "linker_gnu_hash_benchmark.cpp", | 
|  | 548 | ], | 
|  | 549 |  | 
|  | 550 | arch: { | 
|  | 551 | arm: { | 
|  | 552 | srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"], | 
|  | 553 | }, | 
|  | 554 | arm64: { | 
|  | 555 | srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"], | 
|  | 556 | }, | 
|  | 557 | }, | 
| Elliott Hughes | 15a2b7b | 2019-02-15 13:48:38 -0800 | [diff] [blame] | 558 | } |