[clang] [LinkerWrapper][Driver] Do not parse GNU options for MSVC-style linkers (PR #243300)
Srividya Sundaram via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 6 07:25:26 PST 2026
================
@@ -197,6 +204,57 @@ void printCommands(ArrayRef<StringRef> CmdArgs) {
exit(EXIT_FAILURE);
}
+/// Return the option visibility for the last '--linker-flavor=' (default
+/// 'gnu'), so that only options valid for that linker flavor are parsed. The
+/// flavor must be known before parsing, so read it from the raw arguments.
+static unsigned getFlavorVisibility(ArrayRef<const char *> ArgStrings) {
+ StringRef Name = clang::getLinkerFlavorName(clang::LinkerFlavor::GNU);
+ for (StringRef Arg : ArgStrings)
+ if (Arg.consume_front("--linker-flavor="))
+ Name = Arg;
+
+ std::optional<clang::LinkerFlavor> Flavor =
+ clang::getLinkerFlavorFromName(Name);
+ if (!Flavor)
+ reportError(
+ createStringError("invalid linker flavor '" + Name.str() + "'"));
----------------
srividya-sundaram wrote:
Could the error also list the valid values?
Right now it's just `error: invalid linker flavor 'bogus'`, so the user has to go look up what's allowed.
Something like `invalid linker flavor 'bogus'; expected 'gnu' or 'msvc'` would help.
https://github.com/llvm/llvm-project/pull/243300
More information about the cfe-commits
mailing list