1 cc_library_static { 2 name: "liblinker_malloc", 3 defaults: ["linux_bionic_supported"], 4 5 srcs: [ 6 "linker_allocator.cpp", 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"], 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. 27 cc_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 68 cc_binary { 69 defaults: ["linux_bionic_supported"], 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_utils.cpp", 89 "rt.cpp", 90 ], 91 92 arch: { 93 arm: { 94 srcs: [ 95 "arch/arm/begin.S", 96 "linker_exidx_static.c", 97 ], 98 99 cflags: ["-D__work_around_b_24465209__"], 100 version_script: "linker.arm.map", 101 }, 102 arm64: { 103 srcs: ["arch/arm64/begin.S"], 104 version_script: "linker.generic.map", 105 }, 106 x86: { 107 srcs: ["arch/x86/begin.S"], 108 cflags: ["-D__work_around_b_24465209__"], 109 version_script: "linker.generic.map", 110 }, 111 x86_64: { 112 srcs: ["arch/x86_64/begin.S"], 113 version_script: "linker.generic.map", 114 }, 115 mips: { 116 srcs: [ 117 "arch/mips/begin.S", 118 "linker_mips.cpp", 119 ], 120 version_script: "linker.generic.map", 121 }, 122 mips64: { 123 srcs: [ 124 "arch/mips64/begin.S", 125 "linker_mips.cpp", 126 ], 127 version_script: "linker.generic.map", 128 }, 129 }, 130 131 // We need to access Bionic private headers in the linker. 132 include_dirs: ["bionic/libc"], 133 134 // -shared is used to overwrite the -Bstatic and -static 135 // flags triggered by LOCAL_FORCE_STATIC_EXECUTABLE. 136 // This dynamic linker is actually a shared object linked with static libraries. 137 ldflags: [ 138 "-shared", 139 "-Wl,-Bsymbolic", 140 "-Wl,--exclude-libs,ALL", 141 "-Wl,-soname,ld-android.so", 142 ], 143 144 cflags: [ 145 "-fno-stack-protector", 146 "-Wstrict-overflow=5", 147 "-fvisibility=hidden", 148 "-Wall", 149 "-Wextra", 150 "-Wunused", 151 "-Werror", 152 ], 153 154 // TODO: split out the asflags. 155 asflags: [ 156 "-fno-stack-protector", 157 "-Wstrict-overflow=5", 158 "-fvisibility=hidden", 159 "-Wall", 160 "-Wextra", 161 "-Wunused", 162 "-Werror", 163 ], 164 165 product_variables: { 166 debuggable: { 167 cppflags: ["-DUSE_LD_CONFIG_FILE"], 168 }, 169 }, 170 171 cppflags: ["-Wold-style-cast"], 172 173 // we are going to link libc++_static manually because 174 // when stl is not set to "none" build system adds libdl 175 // to the list of static libraries which needs to be 176 // avoided in the case of building loader. 177 stl: "none", 178 179 // we don't want crtbegin.o (because we have begin.o), so unset it 180 // just for this module 181 nocrt: true, 182 183 static_libs: [ 184 "libc_nomalloc", 185 "libm", 186 "libziparchive", 187 "libutils", 188 "libbase", 189 "libz", 190 191 "libasync_safe", 192 193 "liblog", 194 "libc++_static", 195 196 // Important: The liblinker_malloc should be the last library in the list 197 // to overwrite any other malloc implementations by other static libraries. 198 "liblinker_malloc", 199 ], 200 static_executable: true, 201 202 name: "linker", 203 symlinks: ["linker_asan"], 204 multilib: { 205 lib64: { 206 suffix: "64", 207 }, 208 }, 209 target: { 210 android: { 211 static_libs: ["libdebuggerd_handler_fallback"], 212 }, 213 }, 214 compile_multilib: "both", 215 216 // Leave the symbols in the shared library so that stack unwinders can produce 217 // meaningful name resolution. 218 strip: { 219 keep_symbols: true, 220 }, 221 222 // Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb 223 // looking up symbols in the linker by mistake. 224 prefix_symbols: "__dl_", 225 } 226 227 cc_library { 228 // NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from 229 // libgcc.a are made static to ld-android.so. This in turn ensures that libraries that 230 // a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so 231 // to provide those symbols, but will instead pull them from libgcc.a. Specifically, 232 // we use this property to make sure libc.so has its own copy of the code from 233 // libgcc.a it uses. 234 // 235 // DO NOT REMOVE --exclude-libs! 236 237 ldflags: ["-Wl,--exclude-libs=libgcc.a"], 238 239 // for x86, exclude libgcc_eh.a for the same reasons as above 240 arch: { 241 arm: { 242 version_script: "linker.arm.map", 243 }, 244 arm64: { 245 version_script: "linker.generic.map", 246 }, 247 x86: { 248 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], 249 version_script: "linker.generic.map", 250 }, 251 x86_64: { 252 ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"], 253 version_script: "linker.generic.map", 254 }, 255 mips: { 256 version_script: "linker.generic.map", 257 }, 258 mips64: { 259 version_script: "linker.generic.map", 260 }, 261 }, 262 263 srcs: ["ld_android.cpp"], 264 cflags: [ 265 "-Wall", 266 "-Wextra", 267 "-Wunused", 268 "-Werror", 269 ], 270 stl: "none", 271 272 name: "ld-android", 273 defaults: ["linux_bionic_supported"], 274 275 nocrt: true, 276 system_shared_libs: [], 277 278 sanitize: { 279 never: true, 280 }, 281 } 282