Skip to content

Commit

Permalink
Support LLD linker for Darwin (#286)
Browse files Browse the repository at this point in the history
Users can use with `--linkopt=-fuse-ld=ld64.lld` flag.

Eventually, we should make this the default. But only after we hear from
some users that it works for their projects. This PR will make it easy
for them to test.
  • Loading branch information
siddharthab authored Mar 14, 2024
1 parent 8f4a0b2 commit 6bca3e2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ set -x
test_args=(
"--extra_toolchains=${toolchain_name}"
"--copt=-v"
"--linkopt=-Wl,-v"
"--linkopt=-Wl,-t"
)

Expand Down
4 changes: 1 addition & 3 deletions toolchain/BUILD.llvm_repo
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ filegroup(

filegroup(
name = "ld",
srcs = [
"bin/ld.lld",
],
srcs = glob(["bin/ld.lld", "bin/ld64.lld"]),
)

filegroup(
Expand Down
4 changes: 4 additions & 0 deletions toolchain/osx_cc_wrapper.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ function parse_option() {

if [[ -f %{toolchain_path_prefix}bin/clang ]]; then
execroot_path=""
execroot_abs_path="${PWD}/"
elif [[ ${BASH_SOURCE[0]} == "/"* ]]; then
# Some consumers of `CcToolchainConfigInfo` (e.g. `cmake` from rules_foreign_cc)
# change CWD and call $CC (this script) with its absolute path.
# For cases like this, we'll try to find `clang` through an absolute path.
# This script is at _execroot_/external/_repo_name_/bin/cc_wrapper.sh
execroot_path="${BASH_SOURCE[0]%/*/*/*/*}/"
execroot_abs_path="$(cd "${execroot_path}" && pwd -P)/"
else
echo >&2 "ERROR: could not find clang; PWD=\"${PWD}\"; PATH=\"${PATH}\"."
exit 5
Expand All @@ -71,6 +73,8 @@ function sanitize_option() {
local -r opt=$1
if [[ ${opt} == */cc_wrapper.sh ]]; then
printf "%s" "${execroot_path}%{toolchain_path_prefix}bin/clang"
elif [[ ${opt} == "-fuse-ld=ld64.lld" ]]; then
echo "-fuse-ld=${execroot_abs_path}%{toolchain_path_prefix}bin/ld64.lld"
elif [[ ${opt} =~ ^-fsanitize-(ignore|black)list=[^/] ]]; then
# shellcheck disable=SC2206
parts=(${opt/=/ }) # Split flag name and value into array.
Expand Down

0 comments on commit 6bca3e2

Please sign in to comment.