[PATCH] D66968: [WebAssembly] Implement NO_STRIP

Dan Gohman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 11:42:11 PDT 2019


sunfish created this revision.
sunfish added a reviewer: sbc100.
Herald added subscribers: dexonsmith, steven_wu, aheejin, jgravelle-google, mehdi_amini, dschuff.
Herald added a project: LLVM.

This patch replaces https://reviews.llvm.org/D62443 and removes the Emscripten-specific behavior. It just implements support for the NO_STRIP flag, which will allow `__attribute__((used))` to be implemented.

This accompanies https://reviews.llvm.org/D62542, which will move to setting the NO_STRIP flag, and will continue to set EXPORTED for Emscripten targets for compatibility.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D66968

Files:
  tools/lld/docs/ReleaseNotes.rst
  tools/lld/docs/WebAssembly.rst
  tools/lld/wasm/LTO.cpp
  tools/lld/wasm/MarkLive.cpp
  tools/lld/wasm/Symbols.cpp
  tools/lld/wasm/Symbols.h


Index: tools/lld/wasm/Symbols.h
===================================================================
--- tools/lld/wasm/Symbols.h
+++ tools/lld/wasm/Symbols.h
@@ -107,6 +107,10 @@
   WasmSymbolType getWasmType() const;
   bool isExported() const;
 
+  // Indicates that the symbol is used in an __attribute__((used)) directive
+  // or similar.
+  bool isNoStrip() const;
+
   const WasmSignature* getSignature() const;
 
   bool isInGOT() const { return gotIndex != INVALID_INDEX; }
Index: tools/lld/wasm/Symbols.cpp
===================================================================
--- tools/lld/wasm/Symbols.cpp
+++ tools/lld/wasm/Symbols.cpp
@@ -155,6 +155,10 @@
   return flags & WASM_SYMBOL_EXPORTED;
 }
 
+bool Symbol::isNoStrip() const {
+  return flags & WASM_SYMBOL_NO_STRIP;
+}
+
 uint32_t FunctionSymbol::getFunctionIndex() const {
   if (auto *f = dyn_cast<DefinedFunction>(this))
     return f->function->getFunctionIndex();
Index: tools/lld/wasm/MarkLive.cpp
===================================================================
--- tools/lld/wasm/MarkLive.cpp
+++ tools/lld/wasm/MarkLive.cpp
@@ -71,7 +71,7 @@
 
   // We need to preserve any exported symbol
   for (Symbol *sym : symtab->getSymbols())
-    if (sym->isExported())
+    if (sym->isNoStrip() || sym->isExported())
       enqueue(sym);
 
   // For relocatable output, we need to preserve all the ctor functions
Index: tools/lld/wasm/LTO.cpp
===================================================================
--- tools/lld/wasm/LTO.cpp
+++ tools/lld/wasm/LTO.cpp
@@ -105,6 +105,7 @@
     // be removed.
     r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f;
     r.VisibleToRegularObj = config->relocatable || sym->isUsedInRegularObj ||
+                            sym->isNoStrip() ||
                             (r.Prevailing && sym->isExported());
     if (r.Prevailing)
       undefine(sym);
Index: tools/lld/docs/WebAssembly.rst
===================================================================
--- tools/lld/docs/WebAssembly.rst
+++ tools/lld/docs/WebAssembly.rst
@@ -109,7 +109,7 @@
 and use these stub functions at the otherwise invalid call sites.
 
 The default behaviour is to generate these stub function and to produce
-a warning.  The ``--falal-warnings`` flag can be used to disable this behaviour
+a warning.  The ``--fatal-warnings`` flag can be used to disable this behaviour
 and error out if mismatched are found.
 
 Imports and Exports
Index: tools/lld/docs/ReleaseNotes.rst
===================================================================
--- tools/lld/docs/ReleaseNotes.rst
+++ tools/lld/docs/ReleaseNotes.rst
@@ -44,4 +44,7 @@
 WebAssembly Improvements
 ------------------------
 
-* ...
+* `__data_end` and `__heap_base` are no longer exported by default,
+  as it's best to keep them internal when possible. They can be
+  explicitly exported with `--export=__data_end` and
+  `--export=__heap_base`, respectively.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66968.217950.patch
Type: text/x-patch
Size: 2937 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190829/06483300/attachment.bin>


More information about the llvm-commits mailing list