From e455d4c3cb470216a130ca7b13f68977c2658c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Thu, 4 Sep 2025 15:10:57 +0300 Subject: [PATCH] build-llvm: Add an option --use-linker= This allows overriding which linker to use. Currently, building LLVM on Ubuntu 25.10 with these scripts fails, if LLD is available. This, because the GCC on that distribution produces object files that LLD (and gold) rejects during linking - see https://github.com/llvm/llvm-project/issues/156667 for details. By building with --use-linker=bfd, linking does succeed in that configuration. Also pass the same option through from build-all.sh. --- build-all.sh | 4 ++-- build-llvm.sh | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build-all.sh b/build-all.sh index fd87b67..da476a3 100755 --- a/build-all.sh +++ b/build-all.sh @@ -24,7 +24,7 @@ HOST_ARGS="" while [ $# -gt 0 ]; do case "$1" in - --enable-asserts|--disable-dylib|--with-clang|--thinlto) + --enable-asserts|--disable-dylib|--with-clang|--thinlto|--use-linker=*) LLVM_ARGS="$LLVM_ARGS $1" ;; --host-clang|--host-clang=*) @@ -120,7 +120,7 @@ while [ $# -gt 0 ]; do shift done if [ -z "$PREFIX" ]; then - echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--llvm-only] [--no-tools] [--wipe-runtimes] [--clean-runtimes] [--stage1] [--profile[=type]] [--pgo[=profile]] [--full-pgo[=type]] dest [pgo-dest]" + echo "$0 [--host-clang[=clang]] [--enable-asserts] [--disable-dylib] [--with-clang] [--use-linker=linker] [--thinlto] [--full-llvm] [--disable-lldb] [--disable-lldb-mi] [--disable-clang-tools-extra] [--host=triple] [--with-default-win32-winnt=0x601] [--with-default-msvcrt=ucrt] [--enable-cfguard|--disable-cfguard] [--no-runtimes] [--llvm-only] [--no-tools] [--wipe-runtimes] [--clean-runtimes] [--stage1] [--profile[=type]] [--pgo[=profile]] [--full-pgo[=type]] dest [pgo-dest]" exit 1 fi if [ -n "$PREFIX_PGO" ] && [ -z "$PGO" ] && [ -z "$FULL_PGO" ]; then diff --git a/build-llvm.sh b/build-llvm.sh index 1a3e306..e94bb3f 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -40,6 +40,9 @@ while [ $# -gt 0 ]; do WITH_CLANG=1 BUILDDIR="$BUILDDIR-withclang" ;; + --use-linker=*) + USE_LINKER="${1#*=}" + ;; --thinlto) LTO="thin" BUILDDIR="$BUILDDIR-thinlto" @@ -104,7 +107,7 @@ done BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$PREFIX" ]; then - echo $0 [--enable-asserts] [--with-clang] [--thinlto] [--lto] [--instrumented[=type]] [--pgo[=profile]] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--no-llvm-tool-reuse] [--macos-native-tools] dest + echo $0 [--enable-asserts] [--with-clang] [--use-linker=linker] [--thinlto] [--lto] [--instrumented[=type]] [--pgo[=profile]] [--disable-dylib] [--full-llvm] [--with-python] [--disable-lldb] [--disable-clang-tools-extra] [--host=triple] [--no-llvm-tool-reuse] [--macos-native-tools] dest exit 1 fi @@ -190,7 +193,7 @@ if [ -n "$HOST" ]; then if [ -n "$WITH_CLANG" ]; then CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++" - CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" + CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=${USE_LINKER:-lld}" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_ASM_COMPILER_TARGET=$HOST" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER_TARGET=$HOST" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER_TARGET=$HOST" @@ -267,12 +270,14 @@ elif [ -n "$WITH_CLANG" ]; then # tools. CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++" - CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" + CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=${USE_LINKER:-lld}" else # Native compilation with the system default compiler. # Use a faster linker, if available. - if command -v ld.lld >/dev/null; then + if [ -n "$USE_LINKER" ]; then + CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=$USE_LINKER" + elif command -v ld.lld >/dev/null; then CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" elif command -v ld.gold >/dev/null; then CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=gold"