1 Star 1 Fork 5

aosp-riscv/platform_bionic

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Android.bp 14.31 KB
一键复制 编辑 原始数据 按行查看 历史
unicornx 提交于 2022-02-21 15:11 +08:00 . !16sync from RVI upstream: linker_wrapper
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580
// ========================================================
// linker_wrapper - Linux Bionic (on the host)
// ========================================================
// 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.
package {
default_applicable_licenses: ["bionic_linker_license"],
}
license {
name: "bionic_linker_license",
visibility: [":__subpackages__"],
license_kinds: [
"SPDX-license-identifier-BSD",
],
license_text: [
"NOTICE",
],
}
cc_object {
name: "linker_wrapper",
host_supported: true,
device_supported: false,
target: {
linux_bionic: {
enabled: true,
},
linux_glibc: {
enabled: false,
},
darwin: {
enabled: false,
},
},
cflags: [
"-fno-stack-protector",
"-Wstrict-overflow=5",
"-fvisibility=hidden",
"-Wall",
"-Wextra",
"-Wno-unused",
"-Werror",
],
srcs: [
"linker_wrapper.cpp",
],
arch: {
arm64: {
srcs: ["arch/arm64/begin.S"],
},
riscv64: {
srcs: ["arch/riscv64/begin.S"],
},
x86_64: {
srcs: ["arch/x86_64/begin.S"],
},
},
prefix_symbols: "__dlwrap_",
header_libs: ["libc_headers"],
// We need to access Bionic private headers in the linker.
include_dirs: ["bionic/libc"],
// b/182338959
bazel_module: { bp2build_available: false },
}
// ========================================================
// 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",
"liblog",
],
// 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,
vendor_ramdisk_available: true,
native_bridge_supported: true,
}
cc_library_static {
name: "liblinker_main",
defaults: ["linker_defaults", "linker_all_targets"],
srcs: ["linker_main.cpp"],
// Ensure that the compiler won't insert string function calls before ifuncs are resolved.
cflags: ["-ffreestanding"],
}
cc_library_static {
name: "liblinker_malloc",
defaults: ["linker_defaults", "linker_all_targets"],
srcs: ["linker_memory.cpp"],
}
cc_library_static {
name: "liblinker_debuggerd_stub",
defaults: ["linker_defaults", "linker_all_targets"],
srcs: ["linker_debuggerd_stub.cpp"],
}
// ========================================================
// template for the linker binary
// ========================================================
filegroup {
name: "linker_sources",
srcs: [
"dlfcn.cpp",
"linker.cpp",
"linker_block_allocator.cpp",
"linker_dlwarning.cpp",
"linker_cfi.cpp",
"linker_config.cpp",
"linker_debug.cpp",
"linker_gdb_support.cpp",
"linker_globals.cpp",
"linker_libc_support.c",
"linker_libcxx_support.cpp",
"linker_namespaces.cpp",
"linker_logger.cpp",
"linker_mapped_file_fragment.cpp",
"linker_note_gnu_property.cpp",
"linker_phdr.cpp",
"linker_relocate.cpp",
"linker_sdk_versions.cpp",
"linker_soinfo.cpp",
"linker_transparent_hugepage_support.cpp",
"linker_tls.cpp",
"linker_utils.cpp",
"rt.cpp",
],
}
filegroup {
name: "linker_sources_arm",
srcs: [
"arch/arm/begin.S",
"arch/arm_neon/linker_gnu_hash_neon.cpp",
],
}
filegroup {
name: "linker_sources_arm64",
srcs: [
"arch/arm64/begin.S",
"arch/arm64/tlsdesc_resolver.S",
"arch/arm_neon/linker_gnu_hash_neon.cpp",
],
}
filegroup {
name: "linker_sources_riscv64",
srcs: [
"arch/riscv64/begin.S",
],
}
filegroup {
name: "linker_sources_x86",
srcs: [
"arch/x86/begin.S",
],
}
filegroup {
name: "linker_sources_x86_64",
srcs: [
"arch/x86_64/begin.S",
],
}
cc_defaults {
name: "linker_version_script_overlay",
arch: {
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" },
},
}
// A template for the linker binary. May be inherited by native bridge implementations.
cc_defaults {
name: "linker_bin_template",
defaults: ["linker_defaults"],
srcs: [":linker_sources"],
arch: {
arm: {
srcs: [":linker_sources_arm"],
},
arm64: {
srcs: [":linker_sources_arm64"],
},
riscv64: {
srcs: [":linker_sources_riscv64"],
},
x86: {
srcs: [":linker_sources_x86"],
},
x86_64: {
srcs: [":linker_sources_x86_64"],
},
},
// -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.
ldflags: [
"-shared",
"-Wl,-Bsymbolic",
"-Wl,--exclude-libs,ALL",
"-Wl,-soname,ld-android.so",
],
// 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",
// we don't want crtbegin.o (because we have begin.o), so unset it
// just for this module
nocrt: true,
static_executable: true,
// Leave the symbols in the shared library so that stack unwinders can produce
// meaningful name resolution.
strip: {
keep_symbols: 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,
},
static_libs: [
"liblinker_main",
"liblinker_malloc",
"libc++_static",
"libc_nomalloc",
"libc_dynamic_dispatch",
"libm",
"libunwind",
],
// 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"],
system_shared_libs: [],
// Opt out of native_coverage when opting out of system_shared_libs
native_coverage: false,
}
// ========================================================
// linker[_asan][64] binary
// ========================================================
cc_binary {
name: "linker",
defaults: [
"linker_bin_template",
"linux_bionic_supported",
"linker_version_script_overlay",
],
srcs: [
"linker_translate_path.cpp",
],
symlinks: ["linker_asan"],
multilib: {
lib64: {
suffix: "64",
},
},
compile_multilib: "both",
recovery_available: true,
vendor_ramdisk_available: true,
apex_available: [
"//apex_available:platform",
"com.android.runtime",
],
target: {
android: {
srcs: [
"linker_debuggerd_android.cpp",
],
static_libs: [
"libc++demangle",
"libdebuggerd_handler_fallback",
],
},
linux_bionic: {
static_libs: [
"liblinker_debuggerd_stub",
],
},
android_arm64: {
pgo: {
profile_file: "bionic/linker_arm_arm64.profdata",
},
},
android_riscv64: {
pgo: {
profile_file: "bionic/linker_riscv_riscv64.profdata",
},
},
android_arm: {
pgo: {
profile_file: "bionic/linker_arm_arm64.profdata",
},
},
android_x86_64: {
pgo: {
profile_file: "bionic/linker_x86_x86_64.profdata",
},
},
android_x86: {
pgo: {
profile_file: "bionic/linker_x86_x86_64.profdata",
},
},
},
lto: {
never: true,
},
pgo: {
sampling: true,
},
}
// ========================================================
// assorted modules
// ========================================================
sh_binary {
name: "ldd",
src: "ldd.sh",
bazel_module: { bp2build_available: true },
}
// 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"],
},
},
}
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!
ldflags: [
"-Wl,--exclude-libs=libgcc.a",
"-Wl,--exclude-libs=libgcc_stripped.a",
"-Wl,--exclude-libs=libclang_rt.builtins-arm-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-aarch64-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-i686-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-riscv64-android.a",
"-Wl,--exclude-libs=libclang_rt.builtins-x86_64-android.a",
],
// 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"],
},
},
srcs: ["ld_android.cpp"],
cflags: [
"-Wall",
"-Wextra",
"-Wunused",
"-Werror",
],
stl: "none",
name: "ld-android",
defaults: ["linux_bionic_supported", "linker_version_script_overlay"],
ramdisk_available: true,
vendor_ramdisk_available: true,
recovery_available: true,
native_bridge_supported: true,
nocrt: true,
system_shared_libs: [],
header_libs: ["libc_headers"],
// Opt out of native_coverage when opting out of system_shared_libs
native_coverage: false,
sanitize: {
never: true,
},
apex_available: [
"//apex_available:platform",
"com.android.runtime",
],
lto: {
never: true,
},
}
cc_test {
name: "linker-unit-tests",
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",
"linker_note_gnu_property_test.cpp",
"linker_sleb128_test.cpp",
"linker_utils_test.cpp",
"linker_gnu_hash_test.cpp",
// Parts of the linker that we're testing.
"linker_block_allocator.cpp",
"linker_config.cpp",
"linker_debug.cpp",
"linker_note_gnu_property.cpp",
"linker_test_globals.cpp",
"linker_utils.cpp",
],
static_libs: [
"libasync_safe",
"libbase",
"liblog",
],
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"],
},
},
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aosp-riscv/platform_bionic.git
git@gitee.com:aosp-riscv/platform_bionic.git
aosp-riscv
platform_bionic
platform_bionic
riscv64-android-12.0.0_dev

搜索帮助