2019-11-01 03:54:46 +01:00
|
|
|
// ========================================================
|
|
|
|
// linker_wrapper - Linux Bionic (on the host)
|
|
|
|
// ========================================================
|
2016-07-15 01:05:46 +02:00
|
|
|
|
2017-09-19 06:28:14 +02:00
|
|
|
// This is used for bionic on (host) Linux to bootstrap our linker embedded into
|
|
|
|
// a binary.
|
|
|
|
//
|
|
|
|
// Host bionic binaries do not have a PT_INTERP section, instead this gets
|
|
|
|
// embedded as the entry point, and the linker is embedded as ELF sections in
|
|
|
|
// each binary. There's a linker script that sets all of that up (generated by
|
|
|
|
// extract_linker), and defines the extern symbols used in this file.
|
2021-02-19 22:06:22 +01:00
|
|
|
package {
|
2024-02-02 14:57:12 +01:00
|
|
|
default_team: "trendy_team_native_tools_libraries",
|
2021-02-19 22:06:22 +01:00
|
|
|
default_applicable_licenses: ["bionic_linker_license"],
|
|
|
|
}
|
|
|
|
|
|
|
|
license {
|
|
|
|
name: "bionic_linker_license",
|
|
|
|
visibility: [":__subpackages__"],
|
|
|
|
license_kinds: [
|
|
|
|
"SPDX-license-identifier-BSD",
|
|
|
|
],
|
|
|
|
license_text: [
|
|
|
|
"NOTICE",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2017-09-19 06:28:14 +02:00
|
|
|
cc_object {
|
|
|
|
name: "linker_wrapper",
|
|
|
|
host_supported: true,
|
|
|
|
device_supported: false,
|
2022-03-09 00:07:57 +01:00
|
|
|
enabled: false,
|
2017-09-19 06:28:14 +02:00
|
|
|
target: {
|
2018-02-06 02:30:57 +01:00
|
|
|
linux_bionic: {
|
|
|
|
enabled: true,
|
|
|
|
},
|
2017-09-19 06:28:14 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
cflags: [
|
|
|
|
"-fno-stack-protector",
|
|
|
|
"-Wstrict-overflow=5",
|
|
|
|
"-fvisibility=hidden",
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wno-unused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
"linker_wrapper.cpp",
|
|
|
|
],
|
|
|
|
arch: {
|
2020-09-18 09:15:53 +02:00
|
|
|
arm64: {
|
2021-06-11 21:46:45 +02:00
|
|
|
srcs: ["arch/arm64/linker_wrapper_begin.S"],
|
2020-09-18 09:15:53 +02:00
|
|
|
},
|
2022-10-22 05:54:59 +02:00
|
|
|
riscv64: {
|
|
|
|
srcs: ["arch/riscv64/linker_wrapper_begin.S"],
|
|
|
|
},
|
2017-09-19 06:28:14 +02:00
|
|
|
x86_64: {
|
2021-06-11 21:46:45 +02:00
|
|
|
srcs: ["arch/x86_64/linker_wrapper_begin.S"],
|
2017-09-19 06:28:14 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-04-06 21:32:09 +02:00
|
|
|
header_libs: ["libc_headers"],
|
|
|
|
|
2017-09-19 06:28:14 +02:00
|
|
|
// We need to access Bionic private headers in the linker.
|
|
|
|
include_dirs: ["bionic/libc"],
|
|
|
|
}
|
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
// ========================================================
|
|
|
|
// linker default configuration
|
|
|
|
// ========================================================
|
|
|
|
|
|
|
|
// Configuration for the linker binary and any of its static libraries.
|
|
|
|
cc_defaults {
|
|
|
|
name: "linker_defaults",
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
cflags: ["-D__work_around_b_24465209__"],
|
|
|
|
},
|
|
|
|
x86: {
|
|
|
|
cflags: ["-D__work_around_b_24465209__"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
cflags: [
|
|
|
|
"-fno-stack-protector",
|
|
|
|
"-Wstrict-overflow=5",
|
|
|
|
"-fvisibility=hidden",
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
|
|
|
|
// TODO: split out the asflags.
|
|
|
|
asflags: [
|
|
|
|
"-fno-stack-protector",
|
|
|
|
"-Wstrict-overflow=5",
|
|
|
|
"-fvisibility=hidden",
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
|
|
|
|
product_variables: {
|
|
|
|
debuggable: {
|
|
|
|
cppflags: ["-DUSE_LD_CONFIG_FILE"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
cppflags: ["-Wold-style-cast"],
|
|
|
|
|
|
|
|
static_libs: [
|
|
|
|
"libziparchive",
|
|
|
|
"libbase",
|
|
|
|
"libz",
|
|
|
|
|
|
|
|
"libasync_safe",
|
|
|
|
|
2022-08-19 06:09:18 +02:00
|
|
|
"liblog_for_runtime_apex",
|
2019-11-01 03:54:46 +01:00
|
|
|
],
|
|
|
|
|
|
|
|
// We need to access Bionic private headers in the linker.
|
|
|
|
include_dirs: ["bionic/libc"],
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================
|
|
|
|
// linker components
|
|
|
|
// ========================================================
|
|
|
|
|
|
|
|
// Enable a module on all targets the linker runs on (ordinary Android targets, Linux Bionic, and
|
|
|
|
// native bridge implementations).
|
|
|
|
cc_defaults {
|
|
|
|
name: "linker_all_targets",
|
|
|
|
defaults: ["linux_bionic_supported"],
|
|
|
|
recovery_available: true,
|
2020-10-22 03:36:36 +02:00
|
|
|
vendor_ramdisk_available: true,
|
2019-11-01 03:54:46 +01:00
|
|
|
native_bridge_supported: true,
|
|
|
|
}
|
|
|
|
|
2019-11-02 01:18:28 +01:00
|
|
|
cc_library_static {
|
|
|
|
name: "liblinker_main",
|
2024-01-19 20:05:36 +01:00
|
|
|
defaults: [
|
|
|
|
"linker_defaults",
|
|
|
|
"linker_all_targets",
|
|
|
|
],
|
2019-11-02 01:18:28 +01:00
|
|
|
srcs: ["linker_main.cpp"],
|
|
|
|
|
|
|
|
// Ensure that the compiler won't insert string function calls before ifuncs are resolved.
|
|
|
|
cflags: ["-ffreestanding"],
|
2024-01-04 19:06:50 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.runtime",
|
|
|
|
],
|
2019-11-02 01:18:28 +01:00
|
|
|
}
|
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
cc_library_static {
|
|
|
|
name: "liblinker_malloc",
|
2024-01-19 20:05:36 +01:00
|
|
|
defaults: [
|
|
|
|
"linker_defaults",
|
|
|
|
"linker_all_targets",
|
|
|
|
],
|
2019-11-01 03:54:46 +01:00
|
|
|
srcs: ["linker_memory.cpp"],
|
2024-01-04 19:06:50 +01:00
|
|
|
apex_available: [
|
|
|
|
"com.android.runtime",
|
|
|
|
],
|
2019-11-01 03:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cc_library_static {
|
|
|
|
name: "liblinker_debuggerd_stub",
|
2024-01-19 20:05:36 +01:00
|
|
|
defaults: [
|
|
|
|
"linker_defaults",
|
|
|
|
"linker_all_targets",
|
|
|
|
],
|
2019-11-01 03:54:46 +01:00
|
|
|
srcs: ["linker_debuggerd_stub.cpp"],
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================
|
|
|
|
// template for the linker binary
|
|
|
|
// ========================================================
|
|
|
|
|
2018-09-25 12:31:11 +02:00
|
|
|
filegroup {
|
|
|
|
name: "linker_sources",
|
2016-07-15 01:05:46 +02:00
|
|
|
srcs: [
|
|
|
|
"dlfcn.cpp",
|
|
|
|
"linker.cpp",
|
2023-08-22 23:07:48 +02:00
|
|
|
"linker_auxv.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_block_allocator.cpp",
|
2016-07-21 20:33:40 +02:00
|
|
|
"linker_dlwarning.cpp",
|
2016-07-06 22:20:59 +02:00
|
|
|
"linker_cfi.cpp",
|
2017-03-07 20:19:05 +01:00
|
|
|
"linker_config.cpp",
|
2019-12-24 01:03:14 +01:00
|
|
|
"linker_debug.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_gdb_support.cpp",
|
2016-08-04 20:50:36 +02:00
|
|
|
"linker_globals.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_libc_support.c",
|
2017-01-27 01:52:59 +01:00
|
|
|
"linker_libcxx_support.cpp",
|
2016-08-04 01:00:10 +02:00
|
|
|
"linker_namespaces.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_logger.cpp",
|
|
|
|
"linker_mapped_file_fragment.cpp",
|
2020-02-24 14:15:25 +01:00
|
|
|
"linker_note_gnu_property.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_phdr.cpp",
|
2020-01-03 01:36:06 +01:00
|
|
|
"linker_relocate.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_sdk_versions.cpp",
|
2016-08-04 20:50:36 +02:00
|
|
|
"linker_soinfo.cpp",
|
2021-03-24 18:17:39 +01:00
|
|
|
"linker_transparent_hugepage_support.cpp",
|
Reorganize static TLS memory for ELF TLS
For ELF TLS "local-exec" accesses, the static linker assumes that an
executable's TLS segment is located at a statically-known offset from the
thread pointer (i.e. "variant 1" for ARM and "variant 2" for x86).
Because these layouts are incompatible, Bionic generally needs to allocate
its TLS slots differently between different architectures.
To allow per-architecture TLS slots:
- Replace the TLS_SLOT_xxx enumerators with macros. New ARM slots are
generally negative, while new x86 slots are generally positive.
- Define a bionic_tcb struct that provides two things:
- a void* raw_slots_storage[BIONIC_TLS_SLOTS] field
- an inline accessor function: void*& tls_slot(size_t tpindex);
For ELF TLS, it's necessary to allocate a temporary TCB (i.e. TLS slots),
because the runtime linker doesn't know how large the static TLS area is
until after it has loaded all of the initial solibs.
To accommodate Golang, it's necessary to allocate the pthread keys at a
fixed, small, positive offset from the thread pointer.
This CL moves the pthread keys into bionic_tls, then allocates a single
mapping per thread that looks like so:
- stack guard
- stack [omitted for main thread and with pthread_attr_setstack]
- static TLS:
- bionic_tcb [exec TLS will either precede or succeed the TCB]
- bionic_tls [prefixed by the pthread keys]
- [solib TLS segments will be placed here]
- guard page
As before, if the new mapping includes a stack, the pthread_internal_t
is allocated on it.
At startup, Bionic allocates a temporary bionic_tcb object on the stack,
then allocates a temporary bionic_tls object using mmap. This mmap is
delayed because the linker can't currently call async_safe_fatal() before
relocating itself.
Later, Bionic allocates a stack-less thread mapping for the main thread,
and copies slots from the temporary TCB to the new TCB.
(See *::copy_from_bootstrap methods.)
Bug: http://b/78026329
Test: bionic unit tests
Test: verify that a Golang app still works
Test: verify that a Golang app crashes if bionic_{tls,tcb} are swapped
Merged-In: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
Change-Id: I6543063752f4ec8ef6dc9c7f2a06ce2a18fc5af3
(cherry picked from commit 1e660b70da625fcbf1e43dfae09b7b4817fa1660)
2019-01-03 11:51:30 +01:00
|
|
|
"linker_tls.cpp",
|
2016-07-15 01:05:46 +02:00
|
|
|
"linker_utils.cpp",
|
|
|
|
"rt.cpp",
|
|
|
|
],
|
2018-09-25 12:31:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "linker_sources_arm",
|
|
|
|
srcs: [
|
|
|
|
"arch/arm/begin.S",
|
2019-12-24 01:45:47 +01:00
|
|
|
"arch/arm_neon/linker_gnu_hash_neon.cpp",
|
2018-09-25 12:31:11 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "linker_sources_arm64",
|
|
|
|
srcs: [
|
|
|
|
"arch/arm64/begin.S",
|
Implement arm64 TLSDESC
Each TLSDESC relocation relocates a 2-word descriptor in the GOT that
contains:
- the address of a TLS resolver function
- an argument to pass (indirectly) to the resolver function
(Specifically, the address of the 2-word descriptor is passed to the
resolver.)
The loader resolves R_GENERIC_TLSDESC relocations using one of three
resolver functions that it defines:
- tlsdesc_resolver_static
- tlsdesc_resolver_dynamic
- tlsdesc_resolver_unresolved_weak
The resolver functions are written in assembly because they have a
restrictive calling convention. They're only allowed to modify x0 and
(apparently) the condition codes.
For a relocation to memory in static TLS (i.e. the executable or an solib
loaded initially), the loader uses a simple resolver function,
tlsdesc_resolver_static, that returns the static offset it receives from
the loader.
For relocations to dynamic TLS memory (i.e. memory in a dlopen'ed solib),
the loader uses tlsdesc_resolver_dynamic, which allocates TLS memory on
demand. It inlines the fast path of __tls_get_addr, then falls back to
__tls_get_addr when it needs to allocate memory. The loader handles these
dynamic TLS relocations in two passes:
- In the first pass, it allocates a table of TlsDynamicResolverArg
objects, one per dynamic TLSDESC relocation.
- In the second pass, once the table is finalized, it writes the
addresses of the TlsDynamicResolverArg objects into the TLSDESC
relocations.
tlsdesc_resolver_unresolved_weak returns a negated thread pointer so that
taking the address of an unresolved weak TLS symbols produces NULL.
The loader handles R_GENERIC_TLSDESC in a target-independent way, but
only for arm64, because Bionic has only implemented the resolver functions
for arm64.
Bug: http://b/78026329
Test: bionic unit tests
Test: check that backtrace works inside a resolver function and inside
__tls_get_addr called from a resolver
(gdbclient.py, b __tls_get_addr, bt)
Merged-In: I752e59ff986292449892c449dad2546e6f0ff7b6
Change-Id: I752e59ff986292449892c449dad2546e6f0ff7b6
2019-01-24 02:47:10 +01:00
|
|
|
"arch/arm64/tlsdesc_resolver.S",
|
2019-12-24 01:45:47 +01:00
|
|
|
"arch/arm_neon/linker_gnu_hash_neon.cpp",
|
2018-09-25 12:31:11 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2022-10-22 05:54:59 +02:00
|
|
|
filegroup {
|
|
|
|
name: "linker_sources_riscv64",
|
|
|
|
srcs: [
|
|
|
|
"arch/riscv64/begin.S",
|
2024-01-31 00:03:14 +01:00
|
|
|
"arch/riscv64/tlsdesc_resolver.S",
|
2022-10-22 05:54:59 +02:00
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2018-09-25 12:31:11 +02:00
|
|
|
filegroup {
|
|
|
|
name: "linker_sources_x86",
|
|
|
|
srcs: [
|
|
|
|
"arch/x86/begin.S",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
|
|
|
filegroup {
|
|
|
|
name: "linker_sources_x86_64",
|
|
|
|
srcs: [
|
|
|
|
"arch/x86_64/begin.S",
|
|
|
|
],
|
|
|
|
}
|
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
cc_defaults {
|
|
|
|
name: "linker_version_script_overlay",
|
|
|
|
arch: {
|
2024-01-19 20:05:36 +01:00
|
|
|
arm: {
|
|
|
|
version_script: "linker.arm.map",
|
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
version_script: "linker.generic.map",
|
|
|
|
},
|
|
|
|
riscv64: {
|
|
|
|
version_script: "linker.generic.map",
|
|
|
|
},
|
|
|
|
x86: {
|
|
|
|
version_script: "linker.generic.map",
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
version_script: "linker.generic.map",
|
|
|
|
},
|
2019-11-01 03:54:46 +01:00
|
|
|
},
|
2018-09-25 12:31:11 +02:00
|
|
|
}
|
2016-07-15 01:05:46 +02:00
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
// A template for the linker binary. May be inherited by native bridge implementations.
|
2018-09-25 12:31:11 +02:00
|
|
|
cc_defaults {
|
2019-11-01 03:54:46 +01:00
|
|
|
name: "linker_bin_template",
|
|
|
|
defaults: ["linker_defaults"],
|
|
|
|
|
|
|
|
srcs: [":linker_sources"],
|
|
|
|
|
2016-07-15 01:05:46 +02:00
|
|
|
arch: {
|
|
|
|
arm: {
|
2019-11-01 03:54:46 +01:00
|
|
|
srcs: [":linker_sources_arm"],
|
2022-08-12 02:27:50 +02:00
|
|
|
|
|
|
|
// Arm 32 bit does not produce complete exidx unwind information
|
|
|
|
// so keep the .debug_frame which is relatively small and does
|
|
|
|
// include needed unwind information.
|
|
|
|
// See b/242162222 for details.
|
|
|
|
strip: {
|
|
|
|
keep_symbols_and_debug_frame: true,
|
|
|
|
},
|
2019-11-01 03:54:46 +01:00
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
srcs: [":linker_sources_arm64"],
|
2022-08-12 02:27:50 +02:00
|
|
|
|
|
|
|
// Leave the symbols in the shared library so that stack unwinders can produce
|
|
|
|
// meaningful name resolution.
|
|
|
|
strip: {
|
|
|
|
keep_symbols: true,
|
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
},
|
2022-10-22 05:54:59 +02:00
|
|
|
riscv64: {
|
|
|
|
srcs: [":linker_sources_riscv64"],
|
|
|
|
|
|
|
|
// Leave the symbols in the shared library so that stack unwinders can produce
|
|
|
|
// meaningful name resolution.
|
|
|
|
strip: {
|
|
|
|
keep_symbols: true,
|
|
|
|
},
|
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
x86: {
|
2019-11-01 03:54:46 +01:00
|
|
|
srcs: [":linker_sources_x86"],
|
2022-08-12 02:27:50 +02:00
|
|
|
|
|
|
|
// Leave the symbols in the shared library so that stack unwinders can produce
|
|
|
|
// meaningful name resolution.
|
|
|
|
strip: {
|
|
|
|
keep_symbols: true,
|
|
|
|
},
|
2019-11-01 03:54:46 +01:00
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
srcs: [":linker_sources_x86_64"],
|
2022-08-12 02:27:50 +02:00
|
|
|
|
|
|
|
// Leave the symbols in the shared library so that stack unwinders can produce
|
|
|
|
// meaningful name resolution.
|
|
|
|
strip: {
|
|
|
|
keep_symbols: true,
|
|
|
|
},
|
2019-11-01 03:54:46 +01:00
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
},
|
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
// -shared is used to overwrite the -Bstatic and -static flags triggered by enabling
|
|
|
|
// static_executable. This dynamic linker is actually a shared object linked with static
|
|
|
|
// libraries.
|
2016-07-15 01:05:46 +02:00
|
|
|
ldflags: [
|
|
|
|
"-shared",
|
|
|
|
"-Wl,-Bsymbolic",
|
|
|
|
"-Wl,--exclude-libs,ALL",
|
2018-01-04 12:08:32 +01:00
|
|
|
"-Wl,-soname,ld-android.so",
|
2024-03-26 21:24:06 +01:00
|
|
|
// When the linker applies its own IRELATIVE relocations, it will only read DT_REL[A] and
|
|
|
|
// DT_JMPREL, not DT_ANDROID_REL[A], which can also theoretically contain IRELATIVE
|
|
|
|
// relocations. lld has been taught to not store them there as a bug workaround (see
|
|
|
|
// https://llvm.org/pr86751) but the workaround could be removed at some point in the
|
|
|
|
// future. So we explicitly prevent it from doing so by disabling DT_ANDROID_REL[A] when
|
|
|
|
// linking the linker (DT_RELR cannot encode IRELATIVE relocations).
|
|
|
|
"-Wl,--pack-dyn-relocs=relr",
|
2016-07-15 01:05:46 +02:00
|
|
|
],
|
|
|
|
|
2016-12-06 20:10:09 +01:00
|
|
|
// we are going to link libc++_static manually because
|
|
|
|
// when stl is not set to "none" build system adds libdl
|
|
|
|
// to the list of static libraries which needs to be
|
|
|
|
// avoided in the case of building loader.
|
|
|
|
stl: "none",
|
|
|
|
|
2016-07-15 01:05:46 +02:00
|
|
|
// we don't want crtbegin.o (because we have begin.o), so unset it
|
|
|
|
// just for this module
|
|
|
|
nocrt: true,
|
|
|
|
|
2018-09-25 12:31:11 +02:00
|
|
|
static_executable: true,
|
|
|
|
|
|
|
|
// Insert an extra objcopy step to add prefix to symbols. This is needed to prevent gdb
|
|
|
|
// looking up symbols in the linker by mistake.
|
|
|
|
prefix_symbols: "__dl_",
|
|
|
|
|
|
|
|
sanitize: {
|
|
|
|
hwaddress: false,
|
|
|
|
},
|
|
|
|
|
2016-07-15 01:05:46 +02:00
|
|
|
static_libs: [
|
2019-11-02 01:18:28 +01:00
|
|
|
"liblinker_main",
|
2019-11-01 03:54:46 +01:00
|
|
|
"liblinker_malloc",
|
2017-02-09 02:27:20 +01:00
|
|
|
|
2024-05-03 03:15:00 +02:00
|
|
|
// Use a version of libc++ built without exceptions, because accessing EH globals uses
|
|
|
|
// ELF TLS, which is not supported in the loader.
|
|
|
|
"libc++_static_noexcept",
|
2019-11-01 03:54:46 +01:00
|
|
|
"libc_nomalloc",
|
2019-11-02 01:18:28 +01:00
|
|
|
"libc_dynamic_dispatch",
|
2019-11-01 03:54:46 +01:00
|
|
|
"libm",
|
2020-12-16 12:37:22 +01:00
|
|
|
"libunwind",
|
2016-07-15 01:05:46 +02:00
|
|
|
],
|
|
|
|
|
2019-10-15 01:58:53 +02:00
|
|
|
// Ensure that if the linker needs __gnu_Unwind_Find_exidx, then the linker will have a
|
|
|
|
// definition of the symbol. The linker links against libgcc.a, whose arm32 unwinder has a weak
|
|
|
|
// reference to __gnu_Unwind_Find_exidx, which isn't sufficient to pull in the strong definition
|
|
|
|
// of __gnu_Unwind_Find_exidx from libc. An unresolved weak reference would create a
|
|
|
|
// non-relative dynamic relocation in the linker binary, which complicates linker startup.
|
|
|
|
//
|
|
|
|
// This line should be unnecessary because the linker's dependency on libunwind_llvm.a should
|
|
|
|
// override libgcc.a, but this line provides a simpler guarantee. It can be removed once the
|
|
|
|
// linker stops linking against libgcc.a's arm32 unwinder.
|
|
|
|
whole_static_libs: ["libc_unwind_static"],
|
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
system_shared_libs: [],
|
|
|
|
|
|
|
|
// Opt out of native_coverage when opting out of system_shared_libs
|
|
|
|
native_coverage: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========================================================
|
|
|
|
// linker[_asan][64] binary
|
|
|
|
// ========================================================
|
|
|
|
|
|
|
|
cc_binary {
|
2016-07-15 01:05:46 +02:00
|
|
|
name: "linker",
|
2019-11-01 03:54:46 +01:00
|
|
|
defaults: [
|
|
|
|
"linker_bin_template",
|
|
|
|
"linux_bionic_supported",
|
|
|
|
"linker_version_script_overlay",
|
|
|
|
],
|
|
|
|
|
2020-05-14 22:14:45 +02:00
|
|
|
srcs: [
|
|
|
|
"linker_translate_path.cpp",
|
|
|
|
],
|
|
|
|
|
2016-12-08 18:57:35 +01:00
|
|
|
symlinks: ["linker_asan"],
|
2023-03-23 00:12:49 +01:00
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
symlinks: ["linker_hwasan"],
|
|
|
|
},
|
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
multilib: {
|
|
|
|
lib64: {
|
|
|
|
suffix: "64",
|
2016-12-08 18:57:35 +01:00
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
},
|
2019-02-14 22:48:01 +01:00
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
compile_multilib: "both",
|
|
|
|
|
|
|
|
recovery_available: true,
|
2020-10-22 03:36:36 +02:00
|
|
|
vendor_ramdisk_available: true,
|
2019-11-01 03:54:46 +01:00
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"com.android.runtime",
|
|
|
|
],
|
2019-02-14 22:48:01 +01:00
|
|
|
|
2016-07-15 01:05:46 +02:00
|
|
|
target: {
|
2016-11-29 02:02:25 +01:00
|
|
|
android: {
|
2019-11-01 03:54:46 +01:00
|
|
|
srcs: [
|
|
|
|
"linker_debuggerd_android.cpp",
|
|
|
|
],
|
2019-07-23 22:31:14 +02:00
|
|
|
static_libs: [
|
2024-05-03 03:15:00 +02:00
|
|
|
"libc++demangle_noexcept",
|
2019-07-23 22:31:14 +02:00
|
|
|
"libdebuggerd_handler_fallback",
|
|
|
|
],
|
2016-11-29 02:02:25 +01:00
|
|
|
},
|
2019-11-01 03:54:46 +01:00
|
|
|
linux_bionic: {
|
|
|
|
static_libs: [
|
|
|
|
"liblinker_debuggerd_stub",
|
|
|
|
],
|
2020-12-09 18:27:44 +01:00
|
|
|
},
|
2016-07-15 01:05:46 +02:00
|
|
|
},
|
2020-09-30 22:10:01 +02:00
|
|
|
|
2022-01-24 20:19:58 +01:00
|
|
|
afdo: true,
|
2016-07-15 01:05:46 +02:00
|
|
|
}
|
2018-01-05 13:35:43 +01:00
|
|
|
|
2019-11-01 03:54:46 +01:00
|
|
|
// ========================================================
|
|
|
|
// assorted modules
|
|
|
|
// ========================================================
|
|
|
|
|
2019-05-10 00:56:39 +02:00
|
|
|
sh_binary {
|
|
|
|
name: "ldd",
|
2021-02-18 14:35:22 +01:00
|
|
|
src: "ldd.sh",
|
2019-05-10 00:56:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-29 20:31:50 +02:00
|
|
|
// Used to generate binaries that can be backed by transparent hugepages.
|
|
|
|
cc_defaults {
|
|
|
|
name: "linker_hugepage_aligned",
|
|
|
|
arch: {
|
|
|
|
arm64: {
|
|
|
|
ldflags: ["-z max-page-size=0x200000"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
ldflags: ["-z max-page-size=0x200000"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2018-01-05 13:35:43 +01:00
|
|
|
cc_library {
|
|
|
|
// NOTE: --exclude-libs=libgcc.a makes sure that any symbols ld-android.so pulls from
|
|
|
|
// libgcc.a are made static to ld-android.so. This in turn ensures that libraries that
|
|
|
|
// a) pull symbols from libgcc.a and b) depend on ld-android.so will not rely on ld-android.so
|
|
|
|
// to provide those symbols, but will instead pull them from libgcc.a. Specifically,
|
|
|
|
// we use this property to make sure libc.so has its own copy of the code from
|
|
|
|
// libgcc.a it uses.
|
|
|
|
//
|
|
|
|
// DO NOT REMOVE --exclude-libs!
|
|
|
|
|
2018-09-01 04:01:56 +02:00
|
|
|
ldflags: [
|
|
|
|
"-Wl,--exclude-libs=libgcc.a",
|
2019-05-07 01:23:10 +02:00
|
|
|
"-Wl,--exclude-libs=libgcc_stripped.a",
|
2018-09-01 04:01:56 +02:00
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
|
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
|
2022-10-22 05:54:59 +02:00
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-riscv64-android.a",
|
2021-01-28 23:06:52 +01:00
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
|
2018-09-01 04:01:56 +02:00
|
|
|
"-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
|
|
|
|
],
|
2018-01-05 13:35:43 +01:00
|
|
|
|
|
|
|
// for x86, exclude libgcc_eh.a for the same reasons as above
|
|
|
|
arch: {
|
|
|
|
x86: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
|
|
|
|
},
|
|
|
|
x86_64: {
|
|
|
|
ldflags: ["-Wl,--exclude-libs=libgcc_eh.a"],
|
|
|
|
},
|
|
|
|
},
|
2018-01-05 14:31:44 +01:00
|
|
|
|
|
|
|
srcs: ["ld_android.cpp"],
|
2018-01-05 13:35:43 +01:00
|
|
|
cflags: [
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
stl: "none",
|
|
|
|
|
|
|
|
name: "ld-android",
|
2024-01-19 20:05:36 +01:00
|
|
|
defaults: [
|
|
|
|
"linux_bionic_supported",
|
|
|
|
"linker_version_script_overlay",
|
|
|
|
],
|
2020-01-22 01:43:56 +01:00
|
|
|
ramdisk_available: true,
|
2020-10-22 03:36:36 +02:00
|
|
|
vendor_ramdisk_available: true,
|
2018-04-27 14:53:11 +02:00
|
|
|
recovery_available: true,
|
2019-05-03 15:57:34 +02:00
|
|
|
native_bridge_supported: true,
|
2018-01-05 13:35:43 +01:00
|
|
|
|
2018-03-28 07:10:55 +02:00
|
|
|
nocrt: true,
|
2018-01-05 13:35:43 +01:00
|
|
|
system_shared_libs: [],
|
2020-04-06 21:32:09 +02:00
|
|
|
header_libs: ["libc_headers"],
|
2018-01-05 13:35:43 +01:00
|
|
|
|
2019-02-14 22:48:01 +01:00
|
|
|
// Opt out of native_coverage when opting out of system_shared_libs
|
|
|
|
native_coverage: false,
|
|
|
|
|
2018-01-05 13:35:43 +01:00
|
|
|
sanitize: {
|
|
|
|
never: true,
|
|
|
|
},
|
2019-10-02 10:09:33 +02:00
|
|
|
|
|
|
|
apex_available: [
|
|
|
|
"//apex_available:platform",
|
|
|
|
"com.android.runtime",
|
|
|
|
],
|
2018-01-05 13:35:43 +01:00
|
|
|
}
|
2019-02-15 22:48:38 +01:00
|
|
|
|
|
|
|
cc_test {
|
|
|
|
name: "linker-unit-tests",
|
2021-09-30 23:04:39 +02:00
|
|
|
test_suites: ["device-tests"],
|
2019-02-15 22:48:38 +01:00
|
|
|
|
|
|
|
cflags: [
|
|
|
|
"-g",
|
|
|
|
"-Wall",
|
|
|
|
"-Wextra",
|
|
|
|
"-Wunused",
|
|
|
|
"-Werror",
|
|
|
|
],
|
|
|
|
|
|
|
|
// We need to access Bionic private headers in the linker.
|
|
|
|
include_dirs: ["bionic/libc"],
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
// Tests.
|
|
|
|
"linker_block_allocator_test.cpp",
|
|
|
|
"linker_config_test.cpp",
|
|
|
|
"linked_list_test.cpp",
|
2020-02-24 14:15:25 +01:00
|
|
|
"linker_note_gnu_property_test.cpp",
|
2019-02-15 22:48:38 +01:00
|
|
|
"linker_sleb128_test.cpp",
|
|
|
|
"linker_utils_test.cpp",
|
2019-12-24 01:45:47 +01:00
|
|
|
"linker_gnu_hash_test.cpp",
|
2024-02-03 07:11:08 +01:00
|
|
|
"linker_crt_pad_segment_test.cpp",
|
2019-02-15 22:48:38 +01:00
|
|
|
|
|
|
|
// Parts of the linker that we're testing.
|
2024-02-03 07:11:08 +01:00
|
|
|
":elf_note_sources",
|
2019-02-15 22:48:38 +01:00
|
|
|
"linker_block_allocator.cpp",
|
|
|
|
"linker_config.cpp",
|
2019-12-24 01:03:14 +01:00
|
|
|
"linker_debug.cpp",
|
2020-02-24 14:15:25 +01:00
|
|
|
"linker_note_gnu_property.cpp",
|
2019-02-15 22:48:38 +01:00
|
|
|
"linker_test_globals.cpp",
|
|
|
|
"linker_utils.cpp",
|
2024-02-03 07:11:08 +01:00
|
|
|
"linker_phdr.cpp",
|
|
|
|
"linker_mapped_file_fragment.cpp",
|
|
|
|
"linker_sdk_versions.cpp",
|
|
|
|
"linker_dlwarning.cpp",
|
2019-02-15 22:48:38 +01:00
|
|
|
],
|
|
|
|
|
|
|
|
static_libs: [
|
|
|
|
"libasync_safe",
|
|
|
|
"libbase",
|
2022-08-19 06:09:18 +02:00
|
|
|
"liblog_for_runtime_apex",
|
2024-03-13 21:35:49 +01:00
|
|
|
"libprocinfo", // For procinfo::MappedFileSize()
|
2019-02-15 22:48:38 +01:00
|
|
|
],
|
2019-12-24 01:45:47 +01:00
|
|
|
|
2024-02-03 07:11:08 +01:00
|
|
|
data_libs: [
|
|
|
|
"crt_pad_segment_disabled",
|
|
|
|
"crt_pad_segment_enabled",
|
|
|
|
"no_crt_pad_segment",
|
|
|
|
],
|
|
|
|
|
2019-12-24 01:45:47 +01:00
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
|
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
cc_benchmark {
|
|
|
|
name: "linker-benchmarks",
|
|
|
|
|
|
|
|
srcs: [
|
|
|
|
"linker_gnu_hash_benchmark.cpp",
|
|
|
|
],
|
|
|
|
|
|
|
|
arch: {
|
|
|
|
arm: {
|
|
|
|
srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
|
|
|
|
},
|
|
|
|
arm64: {
|
|
|
|
srcs: ["arch/arm_neon/linker_gnu_hash_neon.cpp"],
|
|
|
|
},
|
|
|
|
},
|
2019-02-15 22:48:38 +01:00
|
|
|
}
|