-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][Driver] Obey -fuse-ld=... for -print-prog-name=ld output #66698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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.
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang ChangesGCC makes Full diff: https://github.com/llvm/llvm-project/pull/66698.diff 2 Files Affected:
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}}
|
I think the 2013 GCC feature adding -fuse-ld= made this change, which is, frankly, strange. I wish that we don't this... lld has several names. For windows-msvc target triples it is |
It's too late now. Build system code in the wild uses
ISTM that GetLinkerPath ought to produce the right name regardless and if it doesn't we can fix it to do so. |
Can you comment on what projects need this? Can't we fix the projects instead? And what do they do with the linker path? Why don't they invoke the clang driver to run a link action? There are quite a few distributions using lld by default and I haven't heard about any issue about
It is, but the current test will fail. |
They are legion. It comes from autoconf checks for libtool. It doesn't really matter why they're doing it. They are doing it and it will be years before they can all be changed. If you want to use Clang as the compiler for random open source code, it needs to be compatible with GCC in this regard.
I'll be happy to adjust the test so that it matches all the right names, or so that it's restricted to only running on the targets where we know what the names might be. Can you suggest how to do that? |
Do your have some examples of such projects? As mentioned, I know multiple lld based distributions and they don't find BTW: if you make |
I recently encountered this issue when compiling libffi. Note that this issue only manifests when there's no |
GCC makes
-print-prog-name=ld
a special case that looks up thelinker that will be used according to the
-fuse-ld=...
optionstate. This makes Clang follow suit.