Index: lld/trunk/COFF/Driver.h =================================================================== --- lld/trunk/COFF/Driver.h +++ lld/trunk/COFF/Driver.h @@ -54,6 +54,10 @@ // Tokenizes a given string and then parses as command line options. llvm::opt::InputArgList parse(StringRef S) { return parse(tokenize(S)); } + // Tokenizes a given string and then parses as command line options in + // .drectve section. + llvm::opt::InputArgList parseDirectives(StringRef S); + private: // Parses command line options. llvm::opt::InputArgList parse(llvm::ArrayRef Args); Index: lld/trunk/COFF/Driver.cpp =================================================================== --- lld/trunk/COFF/Driver.cpp +++ lld/trunk/COFF/Driver.cpp @@ -227,7 +227,7 @@ void LinkerDriver::parseDirectives(StringRef S) { ArgParser Parser; // .drectve is always tokenized using Windows shell rules. - opt::InputArgList Args = Parser.parse(S); + opt::InputArgList Args = Parser.parseDirectives(S); for (auto *Arg : Args) { switch (Arg->getOption().getUnaliasedOption().getID()) { Index: lld/trunk/COFF/DriverUtils.cpp =================================================================== --- lld/trunk/COFF/DriverUtils.cpp +++ lld/trunk/COFF/DriverUtils.cpp @@ -750,6 +750,22 @@ return Args; } +// Tokenizes and parses a given string as command line in .drective section. +opt::InputArgList ArgParser::parseDirectives(StringRef S) { + // Make InputArgList from string vectors. + unsigned MissingIndex; + unsigned MissingCount; + + opt::InputArgList Args = + Table.ParseArgs(tokenize(S), MissingIndex, MissingCount); + + if (MissingCount) + fatal(Twine(Args.getArgString(MissingIndex)) + ": missing argument"); + for (auto *Arg : Args.filtered(OPT_UNKNOWN)) + warn("ignoring unknown argument: " + Arg->getSpelling()); + return Args; +} + // link.exe has an interesting feature. If LINK or _LINK_ environment // variables exist, their contents are handled as command line strings. // So you can pass extra arguments using them.