[lld] [LLD] [MinGW] Recognize the -rpath option (PR #102886)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 12:59:13 PDT 2024
https://github.com/mstorsjo updated https://github.com/llvm/llvm-project/pull/102886
>From d65e1dd4d8713f9b9c507c79dfe44d4d4d45cd26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin at martin.st>
Date: Mon, 12 Aug 2024 14:59:39 +0300
Subject: [PATCH] [LLD] [MinGW] Recognize the -rpath option
GNU ld silently accepts the -rpath option for Windows targets,
as a no-op.
This has lead to some build systems (and users) passing this
option while building for Windows/MinGW, even if Windows doesn't
have any concept like rpath.
Older versions of Conan did include -rpath in the pkg-config
files it generated, see e.g.
https://github.com/conan-io/conan/blob/17c58f0c61931f9de218ac571cd97a8e0befa68e/conans/client/generators/pkg_config.py#L104-L114
and
https://github.com/conan-io/conan/blob/17c58f0c61931f9de218ac571cd97a8e0befa68e/conans/client/build/compiler_flags.py#L26-L34
- and see https://github.com/mstorsjo/llvm-mingw/issues/300
for user reports about this issue.
Recognize the option in LLD for MinGW targets, to improve drop-in
compatibility compared to GNU ld, but produce a warning to alert
users that the option really has no effect for these targets.
---
lld/MinGW/Driver.cpp | 3 +++
lld/MinGW/Options.td | 3 +++
lld/test/MinGW/driver.test | 6 ++++++
3 files changed, 12 insertions(+)
diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp
index 35fd478a21905..c7d7b9cfca386 100644
--- a/lld/MinGW/Driver.cpp
+++ b/lld/MinGW/Driver.cpp
@@ -448,6 +448,9 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
add("-errorlimit:" + s);
}
+ if (auto *a = args.getLastArg(OPT_rpath))
+ warn("parameter " + a->getSpelling() + " has no effect on PE/COFF targets");
+
for (auto *a : args.filtered(OPT_mllvm))
add("-mllvm:" + StringRef(a->getValue()));
diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td
index 56f67e3dd96c4..7bd5fb80749da 100644
--- a/lld/MinGW/Options.td
+++ b/lld/MinGW/Options.td
@@ -243,6 +243,9 @@ defm: EqNoHelp<"sysroot">;
def: F<"sort-common">;
def: F<"start-group">;
+// Ignored options, that produce warnings
+defm rpath: EqNoHelp<"rpath">;
+
// Ignore GCC collect2 LTO plugin related options. Note that we don't support
// GCC LTO, but GCC collect2 passes these options even in non-LTO mode.
def: J<"plugin-opt=-fresolution=">;
diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test
index cbccd09793c2f..0dab66b613c77 100644
--- a/lld/test/MinGW/driver.test
+++ b/lld/test/MinGW/driver.test
@@ -446,3 +446,9 @@ RUN: ld.lld -### foo.o -m i386pep --build-id=none 2>&1 | FileCheck -check-prefix
RUN: ld.lld -### foo.o -m i386pep -s 2>&1 | FileCheck -check-prefix=NO_BUILD_ID %s
RUN: ld.lld -### foo.o -m i386pep -S 2>&1 | FileCheck -check-prefix=NO_BUILD_ID %s
NO_BUILD_ID: -build-id:no
+
+RUN: ld.lld -### foo.o -m i386pep -rpath foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
+RUN: ld.lld -### foo.o -m i386pep --rpath foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
+RUN: ld.lld -### foo.o -m i386pep -rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
+RUN: ld.lld -### foo.o -m i386pep --rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
+WARN_RPATH: warning: parameter -{{-?}}rpath has no effect on PE/COFF targets
More information about the llvm-commits
mailing list