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.
This commit is contained in:
Martin Storsjö committed 2025-09-04 23:24:42 +03:00
1 parent 9347c21f74
commit e455d4c3cb
2 files changed
+11 -6

No files matched your search

+2 -2
View File
@@ -24,7 +24,7 @@ HOST_ARGS=""
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
--enable-asserts|--disable-dylib|--with-clang|--thinlto) --enable-asserts|--disable-dylib|--with-clang|--thinlto|--use-linker=*)
LLVM_ARGS="$LLVM_ARGS $1" LLVM_ARGS="$LLVM_ARGS $1"
;; ;;
--host-clang|--host-clang=*) --host-clang|--host-clang=*)
@@ -120,7 +120,7 @@ while [ $# -gt 0 ]; do
shift shift
done done
if [ -z "$PREFIX" ]; then 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 exit 1
fi fi
if [ -n "$PREFIX_PGO" ] && [ -z "$PGO" ] && [ -z "$FULL_PGO" ]; then if [ -n "$PREFIX_PGO" ] && [ -z "$PGO" ] && [ -z "$FULL_PGO" ]; then
+9 -4
View File
@@ -40,6 +40,9 @@ while [ $# -gt 0 ]; do
WITH_CLANG=1 WITH_CLANG=1
BUILDDIR="$BUILDDIR-withclang" BUILDDIR="$BUILDDIR-withclang"
;; ;;
--use-linker=*)
USE_LINKER="${1#*=}"
;;
--thinlto) --thinlto)
LTO="thin" LTO="thin"
BUILDDIR="$BUILDDIR-thinlto" BUILDDIR="$BUILDDIR-thinlto"
@@ -104,7 +107,7 @@ done
BUILDDIR="$BUILDDIR$ASSERTSSUFFIX" BUILDDIR="$BUILDDIR$ASSERTSSUFFIX"
if [ -z "$CHECKOUT_ONLY" ]; then if [ -z "$CHECKOUT_ONLY" ]; then
if [ -z "$PREFIX" ]; 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 exit 1
fi fi
@@ -190,7 +193,7 @@ if [ -n "$HOST" ]; then
if [ -n "$WITH_CLANG" ]; then if [ -n "$WITH_CLANG" ]; then
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang"
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_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_ASM_COMPILER_TARGET=$HOST"
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER_TARGET=$HOST" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER_TARGET=$HOST"
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER_TARGET=$HOST" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER_TARGET=$HOST"
@@ -267,12 +270,14 @@ elif [ -n "$WITH_CLANG" ]; then
# tools. # tools.
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=clang"
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=clang++"
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld" CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=${USE_LINKER:-lld}"
else else
# Native compilation with the system default compiler. # Native compilation with the system default compiler.
# Use a faster linker, if available. # 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" CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=lld"
elif command -v ld.gold >/dev/null; then elif command -v ld.gold >/dev/null; then
CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=gold" CMAKEFLAGS="$CMAKEFLAGS -DLLVM_USE_LINKER=gold"