[WebAssembly] Handle command line options consistently with the ELF backend.

Differential Revision: https://reviews.llvm.org/D61645

llvm-svn: 360266
This commit is contained in:
Sam Clegg 2019-05-08 16:20:05 +00:00
parent e62c693c8e
commit a1282a39ba
4 changed files with 34 additions and 22 deletions

View File

@ -71,6 +71,7 @@ Configuration *elf::Config;
LinkerDriver *elf::Driver;
static void setConfigs(opt::InputArgList &Args);
static void readConfigs(opt::InputArgList &Args);
bool elf::link(ArrayRef<const char *> Args, bool CanExitEarly,
raw_ostream &Error) {
@ -756,7 +757,7 @@ static void parseClangOption(StringRef Opt, const Twine &Msg) {
}
// Initializes Config members by the command line options.
void LinkerDriver::readConfigs(opt::InputArgList &Args) {
static void readConfigs(opt::InputArgList &Args) {
errorHandler().Verbose = Args.hasArg(OPT_verbose);
errorHandler().FatalWarnings =
Args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false);

View File

@ -30,7 +30,6 @@ public:
void addLibrary(StringRef Name);
private:
void readConfigs(llvm::opt::InputArgList &Args);
void createFiles(llvm::opt::InputArgList &Args);
void inferMachineType();
template <class ELFT> void link(llvm::opt::InputArgList &Args);

View File

@ -17,6 +17,10 @@
namespace lld {
namespace wasm {
// This struct contains the global configuration for the linker.
// Most fields are direct mapping from the command line options
// and such fields have the same name as the corresponding options.
// Most fields are initialized by the driver.
struct Configuration {
bool AllowUndefined;
bool CheckFeatures;
@ -48,6 +52,7 @@ struct Configuration {
unsigned LTOO;
unsigned Optimize;
unsigned ThinLTOJobs;
llvm::StringRef Entry;
llvm::StringRef OutputFile;
llvm::StringRef ThinLTOCacheDir;
@ -57,6 +62,9 @@ struct Configuration {
llvm::CachePruningPolicy ThinLTOCachePolicy;
llvm::Optional<std::vector<std::string>> Features;
// The following config options do not directly correspond to any
// particualr command line options.
// True if we are creating position-independent code.
bool Pic;
};

View File

@ -292,11 +292,8 @@ static StringRef getEntry(opt::InputArgList &Args) {
return Arg->getValue();
}
// Some Config members do not directly correspond to any particular
// command line options, but computed based on other Config values.
// This function initialize such members. See Config.h for the details
// of these values.
static void setConfigs(opt::InputArgList &Args) {
// Initializes Config members by the command line options.
static void readConfigs(opt::InputArgList &Args) {
Config->AllowUndefined = Args.hasArg(OPT_allow_undefined);
Config->CheckFeatures =
Args.hasFlag(OPT_check_features, OPT_no_check_features, true);
@ -356,6 +353,26 @@ static void setConfigs(opt::InputArgList &Args) {
}
}
// Some Config members do not directly correspond to any particular
// command line options, but computed based on other Config values.
// This function initialize such members. See Config.h for the details
// of these values.
static void setConfigs() {
Config->Pic = Config->Pie || Config->Shared;
if (Config->Pic) {
if (Config->ExportTable)
error("-shared/-pie is incompatible with --export-table");
Config->ImportTable = true;
}
if (Config->Shared) {
Config->ImportMemory = true;
Config->ExportDynamic = true;
Config->AllowUndefined = true;
}
}
// Some command line options or some combinations of them are not allowed.
// This function checks for such errors.
static void checkOptions(opt::InputArgList &Args) {
@ -514,7 +531,8 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
errorHandler().ErrorLimit = args::getInteger(Args, OPT_error_limit, 20);
setConfigs(Args);
readConfigs(Args);
setConfigs();
checkOptions(Args);
if (auto *Arg = Args.getLastArg(OPT_allow_undefined_file))
@ -525,14 +543,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
return;
}
Config->Pic = Config->Pie || Config->Shared;
if (Config->Pic) {
if (Config->ExportTable)
error("-shared/-pie is incompatible with --export-table");
Config->ImportTable = true;
}
// Handle --trace-symbol.
for (auto *Arg : Args.filtered(OPT_trace_symbol))
Symtab->trace(Arg->getValue());
@ -540,12 +550,6 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
if (!Config->Relocatable)
createSyntheticSymbols();
if (Config->Shared) {
Config->ImportMemory = true;
Config->ExportDynamic = true;
Config->AllowUndefined = true;
}
createFiles(Args);
if (errorCount())
return;