diff --git a/lld/MinGW/Driver.cpp b/lld/MinGW/Driver.cpp --- a/lld/MinGW/Driver.cpp +++ b/lld/MinGW/Driver.cpp @@ -418,6 +418,23 @@ for (auto *a : args.filtered(OPT_mllvm)) add("-mllvm:" + StringRef(a->getValue())); + if (auto *arg = args.getLastArg(OPT_plugin_opt_mcpu_eq)) + add("-mllvm:-mcpu=" + StringRef(arg->getValue())); + + for (auto *a : args.filtered(OPT_plugin_opt_eq_minus)) + add("-mllvm:-" + StringRef(a->getValue())); + + // GCC collect2 passes -plugin-opt=path/to/lto-wrapper with an absolute or + // relative path. Just ignore. If not ended with "lto-wrapper" (or + // "lto-wrapper.exe" for GCC cross-compiled for Windows), consider it an + // unsupported LLVMgold.so option and error. + for (opt::Arg *arg : args.filtered(OPT_plugin_opt_eq)) { + StringRef v(arg->getValue()); + if (!v.ends_with("lto-wrapper") && !v.ends_with("lto-wrapper.exe")) + error(arg->getSpelling() + ": unknown plugin option '" + arg->getValue() + + "'"); + } + for (auto *a : args.filtered(OPT_Xlink)) add(a->getValue()); diff --git a/lld/MinGW/Options.td b/lld/MinGW/Options.td --- a/lld/MinGW/Options.td +++ b/lld/MinGW/Options.td @@ -131,6 +131,13 @@ defm wrap: Eq<"wrap", "Use wrapper functions for symbol">, MetaVarName<"">; +def plugin_opt_eq_minus: J<"plugin-opt=-">, + HelpText<"Specify an LLVM option for compatibility with LLVMgold.so">; +def plugin_opt_mcpu_eq: J<"plugin-opt=mcpu=">; +// This may be either an unhandled LLVMgold.so feature or GCC passed +// -plugin-opt=path/to/{liblto_plugin.so,lto-wrapper} +def plugin_opt_eq : J<"plugin-opt=">; + // LLD specific options def _HASH_HASH_HASH : Flag<["-"], "###">, HelpText<"Print (but do not run) the commands to run for this compilation">; @@ -174,6 +181,10 @@ def: F<"no-undefined">; def: F<"pic-executable">; defm: EqNoHelp<"plugin">; -defm: EqNoHelp<"plugin-opt">; defm: EqNoHelp<"sysroot">; def: F<"start-group">; + +// 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=">; +def: J<"plugin-opt=-pass-through=">; diff --git a/lld/test/MinGW/driver.test b/lld/test/MinGW/driver.test --- a/lld/test/MinGW/driver.test +++ b/lld/test/MinGW/driver.test @@ -371,3 +371,10 @@ RUN: ld.lld -### foo.o -m i386pep --guard-longjmp 2>&1 | FileCheck -check-prefix=GUARD_LONGJMP_NO_CF %s RUN: ld.lld -### foo.o -m i386pep --no-guard-cf --guard-longjmp 2>&1 | FileCheck -check-prefix=GUARD_LONGJMP_NO_CF %s GUARD_LONGJMP_NO_CF: warning: parameter --guard-longjmp only takes effect when used with --guard-cf + +RUN: ld.lld -### foo.o -m i386pep -plugin-opt=mcpu=x86-64 -plugin-opt=-emulated-tls 2>&1 | FileCheck -check-prefix=LTO_OPTS %s +LTO_OPTS: -mllvm:-mcpu=x86-64 -mllvm:-emulated-tls + +Test GCC specific LTO options that GCC passes unconditionally, that we ignore. + +RUN: ld.lld -### foo.o -m i386pep -plugin /usr/lib/gcc/x86_64-w64-mingw32/10-posix/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-w64-mingw32/10-posix/lto-wrapper -plugin-opt=-fresolution=/tmp/ccM9d4fP.res -plugin-opt=-pass-through=-lmingw32