diff --git a/lld/wasm/Config.h b/lld/wasm/Config.h --- a/lld/wasm/Config.h +++ b/lld/wasm/Config.h @@ -72,6 +72,7 @@ llvm::StringSet<> allowUndefinedSymbols; llvm::StringSet<> exportedSymbols; std::vector requiredExports; + std::vector requireDefined; std::vector searchPaths; llvm::CachePruningPolicy thinLTOCachePolicy; llvm::Optional> features; diff --git a/lld/wasm/Options.td b/lld/wasm/Options.td --- a/lld/wasm/Options.td +++ b/lld/wasm/Options.td @@ -35,6 +35,9 @@ def no_ # NAME: Flag<["--", "-"], "no-" # name>, HelpText; } +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">; diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp --- a/lld/wasm/Writer.cpp +++ b/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()) {