[PATCH] D126924: [lld][WebAssembly] Add support for --require-defined linker flag
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 2 14:56:53 PDT 2022
sbc100 updated this revision to Diff 433897.
sbc100 added a comment.
- add test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126924/new/
https://reviews.llvm.org/D126924
Files:
lld/test/wasm/driver.s
lld/wasm/Config.h
lld/wasm/Driver.cpp
lld/wasm/Options.td
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -1585,6 +1585,13 @@
// Delay reporting error about explicit exports until after
// addStartStopSymbols which can create optional symbols.
+ for (auto &name : config->requireDefined) {
+ Symbol *sym = symtab->find(name);
+ if (!sym || !sym->isDefined()) {
+ error(Twine("required symbol `") + name + "` not defined");
+ }
+ }
+
for (auto &name : config->requiredExports) {
Symbol *sym = symtab->find(name);
if (!sym || !sym->isDefined()) {
Index: lld/wasm/Options.td
===================================================================
--- lld/wasm/Options.td
+++ lld/wasm/Options.td
@@ -35,6 +35,9 @@
def no_ # NAME: Flag<["--", "-"], "no-" # name>, HelpText<help2>;
}
+defm require_defined: Eq<"require-defined",
+ "Force symbol to be added to symbol table as an undefined one">;
+
// The following flags are shared with the ELF linker
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">;
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -902,6 +902,9 @@
for (auto *arg : args.filtered(OPT_export_if_defined))
config->exportedSymbols.insert(arg->getValue());
+ for (auto *arg : args.filtered(OPT_require_defined))
+ config->requireDefined.push_back(arg->getValue());
+
for (auto *arg : args.filtered(OPT_export)) {
config->exportedSymbols.insert(arg->getValue());
config->requiredExports.push_back(arg->getValue());
Index: lld/wasm/Config.h
===================================================================
--- lld/wasm/Config.h
+++ lld/wasm/Config.h
@@ -72,6 +72,7 @@
llvm::StringSet<> allowUndefinedSymbols;
llvm::StringSet<> exportedSymbols;
std::vector<llvm::StringRef> requiredExports;
+ std::vector<llvm::StringRef> requireDefined;
std::vector<llvm::StringRef> searchPaths;
llvm::CachePruningPolicy thinLTOCachePolicy;
llvm::Optional<std::vector<std::string>> features;
Index: lld/test/wasm/driver.s
===================================================================
--- lld/test/wasm/driver.s
+++ lld/test/wasm/driver.s
@@ -40,3 +40,6 @@
## 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
+
+# RUN: not wasm-ld %t.o --require-defined=foo -o /dev/null 2>&1 | FileCheck -check-prefix=REQUIRE-DEFINED %s
+# REQUIRE-DEFINED: wasm-ld: error: required symbol `foo` not defined
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126924.433897.patch
Type: text/x-patch
Size: 2653 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/14890df0/attachment.bin>
More information about the llvm-commits
mailing list