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

Roland McGrath via cfe-commits cfe-commits at lists.llvm.org
Mon Sep 18 14:10:00 PDT 2023


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

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.


>From aff75e8f64c8d2515f5fc152b33d5be514568269 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Mon, 18 Sep 2023 13:39:08 -0700
Subject: [PATCH] [clang][Driver] Obey -fuse-ld=... for -print-prog-name=ld
 output

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.
---
 clang/lib/Driver/Driver.cpp            | 3 ++-
 clang/test/Driver/print-prog-name-ld.c | 4 ++++
 2 files changed, 6 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Driver/print-prog-name-ld.c

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}}



More information about the cfe-commits mailing list