1cc_library_static { 2 name: "liblinker_malloc", 3 defaults: ["linux_bionic_supported"], 4 recovery_available: true, 5 6 srcs: [ 7 "linker_memory.cpp", 8 ], 9 cflags: [ 10 "-Wall", 11 "-Werror", 12 ], 13 14 // We need to access Bionic private headers in the linker. 15 include_dirs: ["bionic/libc"], 16 17 static_libs: ["libasync_safe", "libbase"], 18} 19 20// This is used for bionic on (host) Linux to bootstrap our linker embedded into 21// a binary. 22// 23// Host bionic binaries do not have a PT_INTERP section, instead this gets 24// embedded as the entry point, and the linker is embedded as ELF sections in 25// each binary. There's a linker script that sets all of that up (generated by 26// extract_linker), and defines the extern symbols used in this file. 27cc_object { 28 name: "linker_wrapper", 29 host_supported: true, 30 device_supported: false, 31 target: { 32 linux_bionic: { 33 enabled: true, 34 }, 35 linux_glibc: { 36 enabled: false, 37 }, 38 darwin: { 39 enabled: false, 40 }, 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: { 57 x86_64: { 58 srcs: ["arch/x86_64/begin.S"], 59 }, 60 }, 61 62 prefix_symbols: "__dlwrap_", 63 64 // We need to access Bionic private headers in the linker. 65 include_dirs: ["bionic/libc"], 66} 67 68filegroup { 69 name: "linker_sources", 70 srcs: [ 71 "dlfcn.cpp", 72 "linker.cpp", 73 "linker_block_allocator.cpp", 74 "linker_dlwarning.cpp", 75 "linker_cfi.cpp", 76 "linker_config.cpp", 77 "linker_gdb_support.cpp", 78 "linker_globals.cpp", 79 "linker_libc_support.c", 80 "linker_libcxx_support.cpp", 81 "linker_main.cpp", 82 "linker_namespaces.cpp", 83 "linker_logger.cpp", 84 "linker_mapped_file_fragment.cpp", 85 "linker_phdr.cpp", 86 "linker_sdk_versions.cpp", 87 "linker_soinfo.cpp", 88 "linker_tls.cpp", 89 "linker_utils.cpp", 90 "rt.cpp", 91 ], 92} 93 94filegroup { 95 name: "linker_sources_arm", 96 srcs: [ 97 "arch/arm/begin.S", 98 "linker_exidx_static.c", 99 ], 100} 101 102filegroup { 103 name: "linker_sources_arm64", 104 srcs: [ 105 "arch/arm64/begin.S", 106 "arch/arm64/tlsdesc_resolver.S", 107 ], 108} 109 110filegroup { 111 name: "linker_sources_x86", 112 srcs: [ 113 "arch/x86/begin.S", 114 ], 115} 116 117filegroup { 118 name: "linker_sources_x86_64", 119 srcs: [ 120 "arch/x86_64/begin.S", 121 ], 122} 123 124filegroup { 125 name: "linker_sources_mips", 126 srcs: [ 127 "arch/mips/begin.S", 128 "linker_mips.cpp", 129 ], 130} 131 132filegroup { 133 name: "linker_sources_mips64", 134 srcs: [ 135 "arch/mips64/begin.S", 136 "linker_mips.cpp", 137 ], 138} 139 140filegroup { 141 name: "linker_version_script", 142 srcs: ["linker.generic.map"], 143} 144 145filegroup { 146 name: "linker_version_script_arm", 147 srcs: ["linker.arm.map"], 148} 149 150cc_defaults { 151 name: "linker_defaults", 152 arch: { 153 arm: { 154 cflags: ["-D__work_around_b_24465209__"], 155 }, 156 x86: { 157 cflags: ["-D__work_around_b_24465209__"], 158 }, 159 }, 160 161 // -shared is used to overwrite the -Bstatic and -static 162 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE. 163 // This dynamic linker is actually a shared object linked with static libraries. 164 ldflags: [ 165 "-shared", 166 "-Wl,-Bsymbolic", 167 "-Wl,--exclude-libs,ALL", 168 "-Wl,-soname,ld-android.so", 169 ], 170 171 cflags: [ 172 "-fno-stack-protector", 173 "-Wstrict-overflow=5", 174 "-fvisibility=hidden", 175 "-Wall", 176 "-Wextra", 177 "-Wunused", 178 "-Werror", 179 180 // Define _USING_LIBCXX so <stdatomic.h> defers to the <atomic> header. When a Soong module 181 // uses the platform libc++, Soong automatically passes this macro, but the dynamic linker 182 // links against libc++ manually. 183 "-D_USING_LIBCXX", 184 ], 185 186 // TODO: split out the asflags. 187 asflags: [ 188 "-fno-stack-protector", 189 "-Wstrict-overflow=5", 190 "-fvisibility=hidden", 191 "-Wall", 192 "-Wextra", 193 "-Wunused", 194 "-Werror", 195 ], 196 197 product_variables: { 198 debuggable: { 199 cppflags: ["-DUSE_LD_CONFIG_FILE"], 200 }, 201 }, 202 203 cppflags: ["-Wold-style-cast"], 204 205 // we are going to link libc++_static manually because 206 // when stl is not set to "none" build system adds libdl 207 // to the list of static libraries which needs to be 208 // avoided in the case of building loader. 209 stl: "none", 210 211 // we don't want crtbegin.o (because we have begin.o), so unset it 212 // just for this module 213 nocrt: true, 214 215 static_executable: true, 216 217 // Leave the symbols in the shared library so that stack unwinders can produce 218 // meaningful name resolution. 219 strip: { 220 keep_symbols: true, 221 }, 222 223 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb 224 // looking up symbols in the linker by mistake. 225 prefix_symbols: "__dl_", 226 227 sanitize: { 228 hwaddress: false, 229 }, 230} 231 232cc_binary { 233 defaults: ["linux_bionic_supported", "linker_defaults"], 234 srcs: [ ":linker_sources" ], 235 236 arch: { 237 arm: { 238 srcs: [ ":linker_sources_arm" ], 239 version_script: ":linker_version_script_arm", 240 }, 241 arm64: { 242 srcs: [":linker_sources_arm64"], 243 version_script: ":linker_version_script", 244 }, 245 x86: { 246 srcs: [":linker_sources_x86"], 247 version_script: ":linker_version_script", 248 }, 249 x86_64: { 250 srcs: [":linker_sources_x86_64"], 251 version_script: ":linker_version_script", 252 }, 253 mips: { 254 srcs: [":linker_sources_mips"], 255 version_script: ":linker_version_script", 256 }, 257 mips64: { 258 srcs: [":linker_sources_mips64"], 259 version_script: ":linker_version_script", 260 }, 261 }, 262 263 // We need to access Bionic private headers in the linker. 264 include_dirs: ["bionic/libc"], 265 266 static_libs: [ 267 "libc_nomalloc", 268 "libm", 269 "libziparchive", 270 "libutils", 271 "libbase", 272 "libz", 273 274 "libasync_safe", 275 276 "liblog", 277 "libc++_static", 278 279 // Important: The liblinker_malloc should be the last library in the list 280 // to overwrite any other malloc implementations by other static libraries. 281 "liblinker_malloc", 282 ], 283 284 name: "linker", 285 symlinks: ["linker_asan"], 286 recovery_available: true, 287 multilib: { 288 lib32: { 289 cflags: ["-DLIB_PATH=\"lib\""], 290 }, 291 lib64: { 292 cflags: ["-DLIB_PATH=\"lib64\""], 293 suffix: "64", 294 }, 295 }, 296 system_shared_libs: [], 297 298 // Opt out of native_coverage when opting out of system_shared_libs 299 native_coverage: false, 300 301 target: { 302 android: { 303 static_libs: ["libdebuggerd_handler_fallback"], 304 }, 305 }, 306 compile_multilib: "both", 307 xom: false, 308} 309 310cc_library { 311 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from 312 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that 313 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so 314 // to provide those symbols, but will instead pull them from libgcc.a. Specifically, 315 // we use this property to make sure libc.so has its own copy of the code from 316 // libgcc.a it uses. 317 // 318 // DO NOT REMOVE --exclude-libs! 319 320 ldflags: [ 321 "-Wl,--exclude-libs=libgcc.a", 322 "-Wl,--exclude-libs=libgcc_stripped.a", 323 "-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a", 324 "-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a", 325 "-Wl,--exclude-libs=libclang_rt.builtins-x86-android.a", 326 "-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a", 327 ], 328 329 // for x86, exclude libgcc_eh.a for the same reasons as above 330 arch: { 331 arm: { 332 version_script: "linker.arm.map", 333 }, 334 arm64: { 335 version_script: "linker.generic.map", 336 }, 337 x86: { 338 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], 339 version_script: "linker.generic.map", 340 }, 341 x86_64: { 342 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], 343 version_script: "linker.generic.map", 344 }, 345 mips: { 346 version_script: "linker.generic.map", 347 }, 348 mips64: { 349 version_script: "linker.generic.map", 350 }, 351 }, 352 353 srcs: ["ld_android.cpp"], 354 cflags: [ 355 "-Wall", 356 "-Wextra", 357 "-Wunused", 358 "-Werror", 359 ], 360 stl: "none", 361 362 name: "ld-android", 363 defaults: ["linux_bionic_supported"], 364 recovery_available: true, 365 366 nocrt: true, 367 system_shared_libs: [], 368 369 // Opt out of native_coverage when opting out of system_shared_libs 370 native_coverage: false, 371 372 sanitize: { 373 never: true, 374 }, 375} 376 377cc_test { 378 name: "linker-unit-tests", 379 380 cflags: [ 381 "-g", 382 "-Wall", 383 "-Wextra", 384 "-Wunused", 385 "-Werror", 386 ], 387 388 // We need to access Bionic private headers in the linker. 389 include_dirs: ["bionic/libc"], 390 391 srcs: [ 392 // Tests. 393 "linker_block_allocator_test.cpp", 394 "linker_config_test.cpp", 395 "linked_list_test.cpp", 396 "linker_sleb128_test.cpp", 397 "linker_utils_test.cpp", 398 399 // Parts of the linker that we're testing. 400 "linker_block_allocator.cpp", 401 "linker_config.cpp", 402 "linker_test_globals.cpp", 403 "linker_utils.cpp", 404 ], 405 406 static_libs: [ 407 "libasync_safe", 408 "libbase", 409 "liblog", 410 ], 411} 412