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