[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:44:23 PDT 2022


sbc100 created this revision.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, jgravelle-google, dschuff.
Herald added a project: All.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

This option is the same as option --undefined except that if symbol is
not defined in the output file then the linker will issue an error and
exit.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126924

Files:
  lld/wasm/Config.h
  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/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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126924.433893.patch
Type: text/x-patch
Size: 1587 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220602/660f60cf/attachment.bin>


More information about the llvm-commits mailing list