-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
271 additions
and
685 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
diff --git a/toolchain/BUILD.llvm_repo b/toolchain/BUILD.llvm_repo | ||
index a09616e..95f9280 100644 | ||
--- a/toolchain/BUILD.llvm_repo | ||
+++ b/toolchain/BUILD.llvm_repo | ||
@@ -19,7 +19,7 @@ exports_files(glob([ | ||
"bin/*", | ||
"lib/*", | ||
"include/*", | ||
-])) | ||
+], allow_empty = True)) | ||
|
||
## LLVM toolchain files | ||
|
||
@@ -45,12 +45,12 @@ filegroup( | ||
srcs = glob([ | ||
"include/**/c++/**", | ||
"lib/clang/*/include/**", | ||
- ]), | ||
+ ], allow_empty = True), | ||
) | ||
|
||
filegroup( | ||
name = "bin", | ||
- srcs = glob(["bin/**"]), | ||
+ srcs = glob(["bin/**"], allow_empty = True), | ||
) | ||
|
||
filegroup( | ||
@@ -67,6 +67,7 @@ filegroup( | ||
"lib/libclang*.a", | ||
"lib/liblld*.a", | ||
], | ||
+ allow_empty = True, | ||
), | ||
# Do not include the .dylib files in the linker sandbox because they will | ||
# not be available at runtime. Any library linked from the toolchain should |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
diff --git a/toolchain/BUILD.llvm_repo b/toolchain/BUILD.llvm_repo | ||
index 94a1a98..a09616e 100644 | ||
--- a/toolchain/BUILD.llvm_repo | ||
+++ b/toolchain/BUILD.llvm_repo | ||
@@ -36,6 +36,7 @@ filegroup( | ||
name = "ld", | ||
srcs = [ | ||
"bin/ld.lld", | ||
+ "bin/ld64.lld", | ||
], | ||
) | ||
|
||
diff --git a/toolchain/cc_toolchain_config.bzl b/toolchain/cc_toolchain_config.bzl | ||
index da1e330..dc0da9f 100644 | ||
--- a/toolchain/cc_toolchain_config.bzl | ||
+++ b/toolchain/cc_toolchain_config.bzl | ||
@@ -112,8 +112,6 @@ def cc_toolchain_config( | ||
"-fdebug-prefix-map={}=__bazel_toolchain_llvm_repo__/".format(toolchain_path_prefix), | ||
] | ||
|
||
- is_xcompile = not (host_os == target_os and host_arch == target_arch) | ||
- | ||
# Default compiler flags: | ||
compile_flags = [ | ||
"--target=" + target_system_name, | ||
@@ -149,12 +147,17 @@ def cc_toolchain_config( | ||
# unused symbols are not stripped. | ||
link_libs = [] | ||
|
||
+ use_lld = True | ||
+ | ||
# Linker flags: | ||
- if host_os == "darwin" and not is_xcompile: | ||
- # lld is experimental for Mach-O, so we use the native ld64 linker. | ||
- # TODO: How do we cross-compile from Linux to Darwin? | ||
- use_lld = False | ||
+ if target_os == "darwin": | ||
+ ld = "ld64.lld" | ||
+ ld_path = toolchain_path_prefix + "/bin/" + ld | ||
+ compile_flags.append("-mmacosx-version-min=12.0") | ||
link_flags.extend([ | ||
+ "-mmacosx-version-min=12.0", | ||
+ "-Wl,-platform_version,macos,12.0,12.0", | ||
+ "--ld-path=" + ld_path, | ||
"-headerpad_max_install_names", | ||
# This will issue a warning on macOS ventura; see: | ||
# https://github.com/python/cpython/issues/97524 | ||
@@ -163,98 +166,19 @@ def cc_toolchain_config( | ||
"dynamic_lookup", | ||
]) | ||
else: | ||
- # Note that for xcompiling from darwin to linux, the native ld64 is | ||
- # not an option because it is not a cross-linker, so lld is the | ||
- # only option. | ||
- use_lld = True | ||
+ ld = "ld.lld" | ||
+ ld_path = toolchain_path_prefix + "/bin/" + ld | ||
link_flags.extend([ | ||
- "-fuse-ld=lld", | ||
+ "--ld-path=" + ld_path, | ||
"-Wl,--build-id=md5", | ||
"-Wl,--hash-style=gnu", | ||
"-Wl,-z,relro,-z,now", | ||
]) | ||
|
||
- # Flags related to C++ standard. | ||
- # The linker has no way of knowing if there are C++ objects; so we | ||
- # always link C++ libraries. | ||
- cxx_standard = compiler_configuration["cxx_standard"] | ||
- stdlib = compiler_configuration["stdlib"] | ||
- if stdlib == "builtin-libc++" and is_xcompile: | ||
- stdlib = "stdc++" | ||
- if stdlib == "builtin-libc++": | ||
- cxx_flags = [ | ||
- "-std=" + cxx_standard, | ||
- "-stdlib=libc++", | ||
- ] | ||
- if use_lld: | ||
- # For single-platform builds, we can statically link the bundled | ||
- # libraries. | ||
- link_flags.extend([ | ||
- "-l:libc++.a", | ||
- "-l:libc++abi.a", | ||
- "-l:libunwind.a", | ||
- # Compiler runtime features. | ||
- "-rtlib=compiler-rt", | ||
- # To support libunwind. | ||
- "-lpthread", | ||
- "-ldl", | ||
- ]) | ||
- else: | ||
- # The only known mechanism to static link libraries in ld64 is to | ||
- # not have the corresponding .dylib files in the library search | ||
- # path. The link time sandbox does not include the .dylib files, so | ||
- # anything we pick up from the toolchain should be statically | ||
- # linked. However, several system libraries on macOS dynamically | ||
- # link libc++ and libc++abi, so static linking them becomes a problem. | ||
- # We need to ensure that they are dynamic linked from the system | ||
- # sysroot and not static linked from the toolchain, so explicitly | ||
- # have the sysroot directory on the search path and then add the | ||
- # toolchain directory back after we are done. | ||
- link_flags.extend([ | ||
- "-L{}/usr/lib".format(compiler_configuration["sysroot_path"]), | ||
- "-lc++", | ||
- "-lc++abi", | ||
- ]) | ||
- | ||
- # Let's provide the path to the toolchain library directory | ||
- # explicitly as part of the search path to make it easy for a user | ||
- # to pick up something. This also makes the behavior consistent with | ||
- # targets when a user explicitly depends on something like | ||
- # libomp.dylib, which adds this directory to the search path, and would | ||
- # (unintentionally) lead to static linking of libraries from the | ||
- # toolchain. | ||
- link_flags.extend([ | ||
- "-L{}lib".format(toolchain_path_prefix), | ||
- ]) | ||
- elif stdlib == "libc++": | ||
- cxx_flags = [ | ||
- "-std=" + cxx_standard, | ||
- "-stdlib=libc++", | ||
- ] | ||
- | ||
- link_flags.extend([ | ||
- "-l:c++.a", | ||
- "-l:c++abi.a", | ||
- ]) | ||
- elif stdlib == "stdc++": | ||
- cxx_flags = [ | ||
- "-std=" + cxx_standard, | ||
- "-stdlib=libstdc++", | ||
- ] | ||
- | ||
- link_flags.extend([ | ||
- "-l:libstdc++.a", | ||
- ]) | ||
- elif stdlib == "none": | ||
- cxx_flags = [ | ||
- "-nostdlib", | ||
- ] | ||
- | ||
- link_flags.extend([ | ||
- "-nostdlib", | ||
- ]) | ||
- else: | ||
- fail("Unknown value passed for stdlib: {stdlib}".format(stdlib = stdlib)) | ||
+ link_flags.extend([ | ||
+ "-pthread", | ||
+ "-ldl", | ||
+ ]) | ||
|
||
opt_link_flags = ["-Wl,--gc-sections"] if target_os == "linux" else [] | ||
|
||
@@ -325,7 +249,7 @@ def cc_toolchain_config( | ||
"dwp": tools_path_prefix + "llvm-dwp", | ||
"gcc": wrapper_bin_prefix + "cc_wrapper.sh", | ||
"gcov": tools_path_prefix + "llvm-profdata", | ||
- "ld": tools_path_prefix + "ld.lld" if use_lld else _host_tools.get_and_assert(host_tools_info, "ld"), | ||
+ "ld": tools_path_prefix + ld if use_lld else _host_tools.get_and_assert(host_tools_info, "ld"), | ||
"llvm-cov": tools_path_prefix + "llvm-cov", | ||
"llvm-profdata": tools_path_prefix + "llvm-profdata", | ||
"nm": tools_path_prefix + "llvm-nm", | ||
@@ -342,6 +266,8 @@ def cc_toolchain_config( | ||
# `lld` is being used as the linker. | ||
supports_start_end_lib = use_lld | ||
|
||
+ cxx_flags = [] | ||
+ | ||
# Replace flags with any user-provided overrides. | ||
if compiler_configuration["compile_flags"] != None: | ||
compile_flags = _fmt_flags(compiler_configuration["compile_flags"], toolchain_path_prefix) | ||
diff --git a/toolchain/internal/common.bzl b/toolchain/internal/common.bzl | ||
index 37bff8c..286efbf 100644 | ||
--- a/toolchain/internal/common.bzl | ||
+++ b/toolchain/internal/common.bzl | ||
@@ -21,6 +21,7 @@ host_tool_features = struct( | ||
toolchain_tools = [ | ||
"clang-cpp", | ||
"ld.lld", | ||
+ "ld64.lld", | ||
"llvm-ar", | ||
"llvm-dwp", | ||
"llvm-profdata", |
Oops, something went wrong.