[clang] [FatLTO] Detect LLD linker more reliably (PR #128285)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 21 20:46:14 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
@llvm/pr-subscribers-clang
Author: Vincent Lee (thevinster)
<details>
<summary>Changes</summary>
It's possible to have an `ld-path` point to a linker that doesn't have the `ld.lld` filename (e.g. linker wrapper that may emit telemetry before invoking the linker). This was causing mis-compilations with fatLTO since the check couldn't reliably detect that it was using lld. Instead, rely on the value from `-fuse-ld` to determine whether lld is enabled.
---
Full diff: https://github.com/llvm/llvm-project/pull/128285.diff
3 Files Affected:
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (+2-3)
- (added) clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper ()
- (modified) clang/test/Driver/fat-lto-objects.c (+3)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 360754bdb3161..4f60287a1142b 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -862,13 +862,12 @@ void tools::addLTOOptions(const ToolChain &ToolChain, const ArgList &Args,
const llvm::Triple &Triple = ToolChain.getTriple();
const bool IsOSAIX = Triple.isOSAIX();
const bool IsAMDGCN = Triple.isAMDGCN();
- const char *Linker = Args.MakeArgString(ToolChain.GetLinkerPath());
+ StringRef Linker = Args.getLastArgValue(options::OPT_fuse_ld_EQ);
const Driver &D = ToolChain.getDriver();
const bool IsFatLTO = Args.hasFlag(options::OPT_ffat_lto_objects,
options::OPT_fno_fat_lto_objects, false);
const bool IsUnifiedLTO = Args.hasArg(options::OPT_funified_lto);
- if (llvm::sys::path::filename(Linker) != "ld.lld" &&
- llvm::sys::path::stem(Linker) != "ld.lld" && !Triple.isOSOpenBSD()) {
+ if (Linker != "lld" && Linker != "lld-link" && !Triple.isOSOpenBSD()) {
// Tell the linker to load the plugin. This has to come before
// AddLinkerInputs as gold requires -plugin and AIX ld requires -bplugin to
// come before any -plugin-opt/-bplugin_opt that -Wl might forward.
diff --git a/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper b/clang/test/Driver/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper
new file mode 100755
index 0000000000000..e69de29bb2d1d
diff --git a/clang/test/Driver/fat-lto-objects.c b/clang/test/Driver/fat-lto-objects.c
index fae64ea7fd1a1..7b87e2b468886 100644
--- a/clang/test/Driver/fat-lto-objects.c
+++ b/clang/test/Driver/fat-lto-objects.c
@@ -49,5 +49,8 @@
// RUN: -fuse-ld=lld -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s
// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \
// RUN: -fuse-ld=lld -fno-lto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=NOLTO %s
+// RUN: %clang --target=x86_64-unknown-linux-gnu --sysroot=%S/Inputs/basic_cross_linux_tree %s \
+// RUN: -fuse-ld=lld --ld-path=%S/Inputs/basic_cross_linux_tree/usr/x86_64-unknown-linux-gnu/bin/lld-wrapper \
+// RUN: -flto -ffat-lto-objects -### 2>&1 | FileCheck --check-prefix=LTO %s
// LTO: "--fat-lto-objects"
// NOLTO-NOT: "--fat-lto-objects"
``````````
</details>
https://github.com/llvm/llvm-project/pull/128285
More information about the cfe-commits
mailing list