[clang] [clang][Driver] Obey -fuse-ld=... for -print-prog-name=ld output (PR #66698)

via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 14:11:08 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

GCC makes `-print-prog-name=ld` a special case that looks up the
linker that will be used according to the `-fuse-ld=...` option
state.  This makes Clang follow suit.


---
Full diff: https://github.com/llvm/llvm-project/pull/66698.diff


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+2-1) 
- (added) clang/test/Driver/print-prog-name-ld.c (+4) 


``````````diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 84b8fc7685fed42..afda1bb14b420b6 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2189,7 +2189,8 @@ bool Driver::HandleImmediateArgs(const Compilation &C) {
 
     // Null program name cannot have a path.
     if (! ProgName.empty())
-      llvm::outs() << GetProgramPath(ProgName, TC);
+      llvm::outs() << (ProgName == "ld" ? TC.GetLinkerPath()
+                                        : GetProgramPath(ProgName, TC));
 
     llvm::outs() << "\n";
     return false;
diff --git a/clang/test/Driver/print-prog-name-ld.c b/clang/test/Driver/print-prog-name-ld.c
new file mode 100644
index 000000000000000..0aa75306bb01a8d
--- /dev/null
+++ b/clang/test/Driver/print-prog-name-ld.c
@@ -0,0 +1,4 @@
+// Test that -print-prog-name=ld correctly obeys -fuse-ld=...
+
+// RUN: %clang -print-prog-name=ld -fuse-ld=lld 2>&1 | FileCheck %s
+// CHECK:{{.*ld(64)?\.lld}}

``````````

</details>


https://github.com/llvm/llvm-project/pull/66698


More information about the cfe-commits mailing list