diff --git a/lld/test/wasm/driver.ll b/lld/test/wasm/driver.ll --- a/lld/test/wasm/driver.ll +++ b/lld/test/wasm/driver.ll @@ -2,7 +2,7 @@ target triple = "wasm32-unknown-unknown" -define hidden void @entry() local_unnamed_addr #0 { +define hidden void @_start() local_unnamed_addr #0 { entry: ret void } @@ -24,3 +24,18 @@ ; RUN: not wasm-ld --relocatable --shared-memory %t.o 2>&1 \ ; RUN: | FileCheck -check-prefix=SHARED-MEM %s ; SHARED-MEM: error: -r and --shared-memory may not be used together + +; RUN: wasm-ld %t.o -z foo -o /dev/null 2>&1 | FileCheck -check-prefix=ERR10 %s +; RUN: wasm-ld %t.o -z foo -o /dev/null --version 2>&1 | FileCheck -check-prefix=ERR10 %s +; ERR10: warning: unknown -z value: foo + +;; Check we report "unknown -z value" error even with -v. +; RUN: wasm-ld %t.o -z foo -o /dev/null -v 2>&1 | FileCheck -check-prefix=ERR10 %s + +;; Note: in GNU ld, --fatal-warning still leads to a warning. +; RUN: not wasm-ld %t.o -z foo --fatal-warnings 2>&1 | FileCheck --check-prefix=ERR10-FATAL %s +; ERR10-FATAL: error: unknown -z value: foo + +;; stack-size without an = is also an error +; RUN: not wasm-ld %t.o -z stack-size 2>&1 | FileCheck -check-prefix=ERR11 %s +; ERR11: unknown -z value: stack-size diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -357,8 +357,6 @@ config->exportAll = args.hasArg(OPT_export_all); config->exportTable = args.hasArg(OPT_export_table); config->growableTable = args.hasArg(OPT_growable_table); - errorHandler().fatalWarnings = - args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); config->importMemory = args.hasArg(OPT_import_memory); config->sharedMemory = args.hasArg(OPT_shared_memory); config->importTable = args.hasArg(OPT_import_table); @@ -808,10 +806,28 @@ }); } +static bool isKnownZFlag(StringRef s) { + // For now, we only support a very limited set of -z flags + return s.startswith("stack-size="); +} + +// Report a warning for an unknown -z option. +static void checkZOptions(opt::InputArgList &args) { + for (auto *arg : args.filtered(OPT_z)) + if (!isKnownZFlag(arg->getValue())) + warn("unknown -z value: " + StringRef(arg->getValue())); +} + void LinkerDriver::linkerMain(ArrayRef argsArr) { WasmOptTable parser; opt::InputArgList args = parser.parse(argsArr.slice(1)); + // Interpret the flags early because error()/warn() depend on them. + errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20); + errorHandler().fatalWarnings = + args.hasFlag(OPT_fatal_warnings, OPT_no_fatal_warnings, false); + checkZOptions(args); + // Handle --help if (args.hasArg(OPT_help)) { parser.printHelp(lld::outs(), @@ -848,8 +864,6 @@ cl::ResetAllOptionOccurrences(); cl::ParseCommandLineOptions(v.size(), v.data()); - errorHandler().errorLimit = args::getInteger(args, OPT_error_limit, 20); - readConfigs(args); createFiles(args);