[PATCH] D119888: [lld][WebAssemlby] Warn on unknown -z flags
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 15 13:26:59 PST 2022
sbc100 created this revision.
Herald added a subscriber: wingo.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
This code mirrors that in lld/ELF/Driver.cpp, as does the new test code.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D119888
Files:
lld/test/wasm/driver.ll
lld/wasm/Driver.cpp
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ 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<const char *> 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);
Index: lld/test/wasm/driver.ll
===================================================================
--- lld/test/wasm/driver.ll
+++ 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119888.409037.patch
Type: text/x-patch
Size: 3071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220215/f1e66d4a/attachment.bin>
More information about the llvm-commits
mailing list