From a45e370ce447563cded1de094a5baf128cbd29dd Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Mon, 6 May 2024 14:34:18 -0700 Subject: [PATCH 1/2] Set toolchain clang linker to gold BFD doesn't work with Swift symbols. We get nasty errors like this: ``` error: link command failed with exit code 1 (use -v to see invocation) /usr/bin/ld: ...wift/CMakeFiles/swiftDispatch.dir/Block.swift.o: relocation R_X86_64_PC32 against protected symbol `$s8Dispatch0A13WorkItemFlagsVSYAAMc' can not be used when making a shared object /usr/bin/ld: final link failed: bad value ``` --- utils/build-presets.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/build-presets.ini b/utils/build-presets.ini index e522ce98990f6..a2cb8bd314039 100644 --- a/utils/build-presets.ini +++ b/utils/build-presets.ini @@ -904,7 +904,9 @@ reconfigure # gcc version on amazon linux 2 is too old to configure and build tablegen. # Use the clang that we install in the path for macros -llvm-cmake-options=-DCROSS_TOOLCHAIN_FLAGS_LLVM_NATIVE='-DCMAKE_C_COMPILER=clang;-DCMAKE_CXX_COMPILER=clang++' +llvm-cmake-options= + -DCROSS_TOOLCHAIN_FLAGS_LLVM_NATIVE='-DCMAKE_C_COMPILER=clang;-DCMAKE_CXX_COMPILER=clang++' + -DCLANG_DEFAULT_LINKER=gold [preset: buildbot_linux] mixin-preset= From d83ceb81c20c42b1e7e6dcf44f3e55e0e7132598 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Mon, 13 May 2024 11:52:51 -0700 Subject: [PATCH 2/2] Use consistent clang through build The just-built Swift driver was picking up the system clang, which would try to use the bfd linker instead of gold or lld. bfd doesn't like how Swift handles protected symbols and fails with the following error: ``` error: link command failed with exit code 1 (use -v to see invocation) /usr/bin/ld: /home/build-user/build/buildbot_linux/libdispatch-linux-x86_64/src/swift/CMakeFiles/swiftDispatch.dir/Block.swift.o: relocation R_X86_64_PC32 against protected symbol `$s8Dispatch0A13WorkItemFlagsVSYAAMc' can not be used when making a shared object /usr/bin/ld: final link failed: bad value ``` This patch tells the Swift-Driver where it should find its clang, and makes it match the clang that is in use through the rest of the build. --- utils/build-script-impl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/utils/build-script-impl b/utils/build-script-impl index 75373fb674cfc..e24517a776441 100755 --- a/utils/build-script-impl +++ b/utils/build-script-impl @@ -1665,6 +1665,8 @@ for host in "${ALL_HOSTS[@]}"; do else CLANG_BIN="$(build_directory_bin ${LOCAL_HOST} llvm)" fi + export SWIFT_DRIVER_CLANG_EXEC="${CLANG_BIN}/clang" + export SWIFT_DRIVER_CLANGXX_EXEC="${CLANG_BIN}/clang++" if [[ "${NATIVE_SWIFT_TOOLS_PATH}" ]] ; then SWIFTC_BIN="${NATIVE_SWIFT_TOOLS_PATH}/swiftc" @@ -2734,6 +2736,8 @@ for host in "${ALL_HOSTS[@]}"; do else CLANG_BIN="$(build_directory_bin ${LOCAL_HOST} llvm)" fi + export SWIFT_DRIVER_CLANG_EXEC="${CLANG_BIN}/clang" + export SWIFT_DRIVER_CLANGXX_EXEC="${CLANG_BIN}/clang++" if [[ "${NATIVE_SWIFT_TOOLS_PATH}" ]] ; then SWIFTC_BIN="${NATIVE_SWIFT_TOOLS_PATH}/swiftc" @@ -3081,6 +3085,20 @@ for host in "${ALL_HOSTS[@]}"; do continue fi + # Have to set the clang path or the driver will try to link with the wrong + # clang + if [[ "${NATIVE_CLANG_TOOLS_PATH}" ]] ; then + CLANG_BIN="${NATIVE_CLANG_TOOLS_PATH}" + if [[ ! -f "${CLANG_BIN}/clang" ]] ; then + echo "error: clang does not exist at the specified native tools path: ${CLANG_BIN}/clang" + exit 1 + fi + else + CLANG_BIN="$(build_directory_bin ${LOCAL_HOST} llvm)" + fi + export SWIFT_DRIVER_CLANG_EXEC="${CLANG_BIN}/clang" + export SWIFT_DRIVER_CLANGXX_EXEC="${CLANG_BIN}/clang++" + # Set the build options for this host set_build_options_for_host $host