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