From 81247063bf783162dee6207ce9102fd71bab4a9f Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 29 May 2013 05:07:49 +0000 Subject: [PATCH] [WinLink] Add -subsystem and -out command line option parsing. The code to actually consume these flags will be added soon. llvm-svn: 182824 --- .../lld/ReaderWriter/PECOFFTargetInfo.h | 13 +++++++- lld/lib/Driver/WinLinkDriver.cpp | 32 +++++++++++++++++++ lld/lib/Driver/WinLinkOptions.td | 8 +++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h b/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h index 67c3e12f7f02..6b8e4b015b9a 100644 --- a/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h +++ b/lld/include/lld/ReaderWriter/PECOFFTargetInfo.h @@ -14,13 +14,14 @@ #include "lld/ReaderWriter/Reader.h" #include "lld/ReaderWriter/Writer.h" +#include "llvm/Support/COFF.h" #include "llvm/Support/ErrorHandling.h" namespace lld { class PECOFFTargetInfo : public TargetInfo { public: - PECOFFTargetInfo() {} + PECOFFTargetInfo() : _subsystem(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN) {} virtual error_code parseFile( std::unique_ptr &mb, @@ -31,10 +32,20 @@ public: virtual void addPasses(PassManager &pm) const {} + void setSubsystem(llvm::COFF::WindowsSubsystem subsystem) { + _subsystem = subsystem; + } + + llvm::COFF::WindowsSubsystem getSubsystem() { + return _subsystem; + } + virtual ErrorOr relocKindFromString(StringRef str) const; virtual ErrorOr stringFromRelocKind(Reference::Kind kind) const; private: + llvm::COFF::WindowsSubsystem _subsystem; + mutable std::unique_ptr _reader; mutable std::unique_ptr _writer; }; diff --git a/lld/lib/Driver/WinLinkDriver.cpp b/lld/lib/Driver/WinLinkDriver.cpp index 0656040dc1b1..6a117a6c1251 100644 --- a/lld/lib/Driver/WinLinkDriver.cpp +++ b/lld/lib/Driver/WinLinkDriver.cpp @@ -13,6 +13,7 @@ /// //===----------------------------------------------------------------------===// +#include "llvm/ADT/StringSwitch.h" #include "llvm/Option/Arg.h" #include "llvm/Option/Option.h" @@ -62,6 +63,15 @@ int findDoubleDash(int argc, const char *argv[]) { return -1; } +// Parses -subsystem command line option. +llvm::COFF::WindowsSubsystem strToWinSubsystem(std::string str) { + std::string arg(StringRef(str).lower()); + return llvm::StringSwitch(arg) + .Case("windows", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI) + .Case("console", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI) + .Default(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN); +} + } // namespace @@ -101,6 +111,13 @@ bool WinLinkDriver::parse(int argc, const char *argv[], return true; } + // Show warning for unknown arguments + for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN), + ie = parsedArgs->filtered_end(); it != ie; ++it) { + diagnostics << "warning: ignoring unknown argument: " + << (*it)->getAsString(*parsedArgs) << "\n"; + } + // Copy -mllvm for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_mllvm), ie = parsedArgs->filtered_end(); @@ -108,6 +125,21 @@ bool WinLinkDriver::parse(int argc, const char *argv[], info.appendLLVMOption((*it)->getValue()); } + // Handle -subsystem + if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem)) { + llvm::COFF::WindowsSubsystem subsystem = strToWinSubsystem(arg->getValue()); + if (subsystem == llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN) { + diagnostics << "error: unknown subsystem name: " + << arg->getValue() << "\n"; + return true; + } + info.setSubsystem(subsystem); + } + + // Hanlde -out + if (llvm::opt::Arg *outpath = parsedArgs->getLastArg(OPT_out)) + info.setOutputPath(outpath->getValue()); + // Add input files for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT), ie = parsedArgs->filtered_end(); diff --git a/lld/lib/Driver/WinLinkOptions.td b/lld/lib/Driver/WinLinkOptions.td index c4307c1d3952..94198c1c6175 100644 --- a/lld/lib/Driver/WinLinkOptions.td +++ b/lld/lib/Driver/WinLinkOptions.td @@ -5,5 +5,13 @@ include "llvm/Option/OptParser.td" def mllvm : Separate<["-", "/"], "mllvm">, HelpText<"Options to pass to LLVM">; +def out : Separate<["-", "/"], "out">, + HelpText<"Path to file to write output">; +def out_c : Joined<["-", "/"], "out:">, Alias; + +def subsystem : Separate<["-", "/"], "subsystem">, + HelpText<"Specify subsystem">; +def subsystem_c: Joined<["-", "/"], "subsystem:">, Alias; + def help : Flag<["-", "/"], "help">; def help_q : Flag<["-", "/"], "?">, Alias;