aboutsummaryrefslogtreecommitdiff
path: root/BUILD.bazel
diff options
context:
space:
mode:
authorJingwen Chen <jingwen@google.com>2021-09-29 11:44:03 +0000
committerJingwen Chen <jingwen@google.com>2021-10-07 12:15:10 +0000
commit018e5fca650e0e220cc0bd22cb3566ef0af5da99 (patch)
tree612302263565dede498b2335c63da1d981105e93 /BUILD.bazel
parent7cc90b2747a50b6cf86581ecfb674e4bcc292f8d (diff)
downloadlinux-x86-018e5fca650e0e220cc0bd22cb3566ef0af5da99.tar.gz
Add crt library link support, and split crt/nocrt cc_toolchains.
This CL adds support for splitting device cc_toolchains to crt/no_crt variants, and adding the crtbegin/crtend libraries to shared libraries link actions. Sample aquery output for: libasyncio (crt link enabled): https://gist.github.com/jin/b4c7e364f7a0dd6b429ed0d424df5674 libc (crt link disabled): https://gist.github.com/jin/52eb86114db69cc2e4d3adbb8a60c89d The no_crt variants are used by very few modules: libc/libdl/libm, and crt objects themselves. Test: presubmits Change-Id: Icb8847bec888d332dcb9d4e92df3863e7d237ca1
Diffstat (limited to 'BUILD.bazel')
-rw-r--r--BUILD.bazel189
1 files changed, 89 insertions, 100 deletions
diff --git a/BUILD.bazel b/BUILD.bazel
index 919f9cab2..11c9d332f 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -59,67 +59,6 @@ android_cc_toolchain(
toolchain_identifier = "x86_64-toolchain",
)
-toolchain(
- name = "cc_toolchain_x86_64_def",
- exec_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
- ],
- target_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:android",
- ],
- toolchain = ":cc_toolchain_x86_64",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
-)
-
-# Toolchain to compile for the linux host.
-# TODO(b/186628704): automatically generate from Soong.
-android_cc_toolchain(
- name = "cc_toolchain_x86_64_linux_host",
- target_os = "linux_glibc",
- target_arch = "x86_64",
- clang_version = ":clang",
- clang_version_directory = generated_constants.CLANG_DEFAULT_VERSION,
- libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:linux_glibc_x86_64"],
- linker_flags = [
- "-m64",
- "-Wl,-z,noexecstack",
- "-Wl,-z,relro",
- "-Wl,-z,now",
- "-Wl,--no-undefined-version",
- ],
- target_flags = [
- "-m64",
- "-fdiagnostics-color",
- "-Wa,--noexecstack",
- "-fPIC",
- "-U_FORTIFY_SOURCE",
- "-D_FORTIFY_SOURCE=2",
- "-fstack-protector",
- # Workaround differences in inttypes.h between host and target.
- # See bug 12708004.
- "-D__STDC_FORMAT_MACROS",
- "-D__STDC_CONSTANT_MACROS",
- ],
- toolchain_identifier = "x86_64-toolchain",
-)
-
-# TODO(b/181803350): Fix linux toolchain flag set, as the current flags are for android.
-toolchain(
- name = "cc_toolchain_x86_64_linux_host_def",
- exec_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
- ],
- target_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
- ],
- toolchain = ":cc_toolchain_x86_64_linux_host",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
-)
-
# x86 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_x86",
@@ -140,20 +79,6 @@ android_cc_toolchain(
toolchain_identifier = "x86-toolchain",
)
-toolchain(
- name = "cc_toolchain_x86_def",
- exec_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
- ],
- target_compatible_with = [
- "//build/bazel/platforms/arch:x86",
- "//build/bazel/platforms/os:android",
- ],
- toolchain = ":cc_toolchain_x86",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
-)
-
# arm64 toolchain definition.
android_cc_toolchain(
name = "cc_toolchain_arm64",
@@ -173,23 +98,9 @@ android_cc_toolchain(
toolchain_identifier = "arm64-toolchain",
)
-toolchain(
- name = "cc_toolchain_arm64_def",
- exec_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
- ],
- target_compatible_with = [
- "//build/bazel/platforms/arch:arm64",
- "//build/bazel/platforms/os:android",
- ],
- toolchain = ":cc_toolchain_arm64",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
-)
-
# arm32 toolchain definition.
android_cc_toolchain(
- name = "cc_toolchain_arm32",
+ name = "cc_toolchain_arm",
target_os = "android",
target_arch = "arm",
clang_version = ":clang",
@@ -204,20 +115,98 @@ android_cc_toolchain(
toolchain_identifier = "arm-toolchain",
)
-toolchain(
- name = "cc_toolchain_arm32_def",
- exec_compatible_with = [
- "//build/bazel/platforms/arch:x86_64",
- "//build/bazel/platforms/os:linux",
+# Toolchain to compile for the linux host.
+# TODO(b/186628704): automatically generate from Soong.
+android_cc_toolchain(
+ name = "cc_toolchain_x86_64_linux_host",
+ target_os = "linux_glibc",
+ target_arch = "x86_64",
+ clang_version = ":clang",
+ clang_version_directory = generated_constants.CLANG_DEFAULT_VERSION,
+ libclang_rt_builtin = _LIBCLANG_RT_PREBUILT_MAP["//build/bazel/platforms/os_arch:linux_glibc_x86_64"],
+ linker_flags = [
+ "-m64",
+ "-Wl,-z,noexecstack",
+ "-Wl,-z,relro",
+ "-Wl,-z,now",
+ "-Wl,--no-undefined-version",
],
- target_compatible_with = [
- "//build/bazel/platforms/arch:arm",
- "//build/bazel/platforms/os:android",
+ target_flags = [
+ "-m64",
+ "-fdiagnostics-color",
+ "-Wa,--noexecstack",
+ "-fPIC",
+ "-U_FORTIFY_SOURCE",
+ "-D_FORTIFY_SOURCE=2",
+ "-fstack-protector",
+ # Workaround differences in inttypes.h between host and target.
+ # See bug 12708004.
+ "-D__STDC_FORMAT_MACROS",
+ "-D__STDC_CONSTANT_MACROS",
],
- toolchain = ":cc_toolchain_arm32",
- toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+ toolchain_identifier = "x86_64-toolchain",
)
+toolchain_type(name = "nocrt_toolchain")
+
+ARCHITECTURES = ["x86_64", "x86", "arm", "arm64"]
+
+# Device toolchains with crt libraries
+[
+ toolchain(
+ name = "cc_toolchain_%s_def" % arch,
+ exec_compatible_with = [
+ "//build/bazel/platforms/arch:x86_64",
+ "//build/bazel/platforms/os:linux",
+ ],
+ target_compatible_with = [
+ "//build/bazel/platforms/arch:%s" % arch,
+ "//build/bazel/platforms/os:android",
+ ],
+ toolchain = ":cc_toolchain_%s" % arch,
+ toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
+ ) for arch in ARCHITECTURES
+]
+
+# Device toolchains without crt libraries
+[
+ toolchain(
+ name = "cc_toolchain_%s_nocrt_def" % arch,
+ exec_compatible_with = [
+ "//build/bazel/platforms/arch:x86_64",
+ "//build/bazel/platforms/os:linux",
+ ],
+ target_compatible_with = [
+ "//build/bazel/platforms/arch:%s" % arch,
+ "//build/bazel/platforms/os:android",
+ ],
+ toolchain = ":cc_toolchain_%s_nocrt" % arch,
+ toolchain_type = ":nocrt_toolchain",
+ ) for arch in ARCHITECTURES
+]
+
+# Host toolchains for linux x86_64
+[
+ toolchain(
+ name = "%s_def" % toolchain_name,
+ exec_compatible_with = [
+ "//build/bazel/platforms/arch:x86_64",
+ "//build/bazel/platforms/os:linux",
+ ],
+ target_compatible_with = [
+ "//build/bazel/platforms/arch:x86_64",
+ "//build/bazel/platforms/os:linux",
+ ],
+ # TODO(b/181803350): Fix linux toolchain flag set, as the current flags are for android.
+ toolchain = toolchain_name,
+ toolchain_type = toolchain_type,
+ ) for (toolchain_name, toolchain_type) in
+ [
+ ("cc_toolchain_x86_64_linux_host", "@bazel_tools//tools/cpp:toolchain_type"),
+ ("cc_toolchain_x86_64_linux_host_nocrt", "nocrt_toolchain"),
+ ]
+]
+
cc_import(
name = "libclang_rt",
static_library = select(_LIBCLANG_RT_PREBUILT_MAP),