Skip to content

Commit 9736bd8

Browse files
committed
[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 mstorsjo/llvm-mingw#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.
1 parent 914a846 commit 9736bd8

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

lld/MinGW/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
448448
add("-errorlimit:" + s);
449449
}
450450

451+
if (auto *a = args.getLastArg(OPT_rpath))
452+
warn("parameter " + a->getSpelling() + " has no effect on PE/COFF "
453+
"targets");
454+
451455
for (auto *a : args.filtered(OPT_mllvm))
452456
add("-mllvm:" + StringRef(a->getValue()));
453457

lld/MinGW/Options.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ defm: EqNoHelp<"sysroot">;
243243
def: F<"sort-common">;
244244
def: F<"start-group">;
245245

246+
// Ignored options, that produce warnings
247+
defm rpath: EqNoHelp<"rpath">;
248+
246249
// Ignore GCC collect2 LTO plugin related options. Note that we don't support
247250
// GCC LTO, but GCC collect2 passes these options even in non-LTO mode.
248251
def: J<"plugin-opt=-fresolution=">;

lld/test/MinGW/driver.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,3 +446,9 @@ RUN: ld.lld -### foo.o -m i386pep --build-id=none 2>&1 | FileCheck -check-prefix
446446
RUN: ld.lld -### foo.o -m i386pep -s 2>&1 | FileCheck -check-prefix=NO_BUILD_ID %s
447447
RUN: ld.lld -### foo.o -m i386pep -S 2>&1 | FileCheck -check-prefix=NO_BUILD_ID %s
448448
NO_BUILD_ID: -build-id:no
449+
450+
RUN: ld.lld -### foo.o -m i386pep -rpath foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
451+
RUN: ld.lld -### foo.o -m i386pep --rpath foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
452+
RUN: ld.lld -### foo.o -m i386pep -rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
453+
RUN: ld.lld -### foo.o -m i386pep --rpath=foo 2>&1 | FileCheck -check-prefix=WARN_RPATH %s
454+
WARN_RPATH: warning: parameter -{{-?}}rpath has no effect on PE/COFF targets

0 commit comments

Comments
 (0)