[lld] r370416 - [WebAssembly] Implement NO_STRIP

Dan Gohman via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 29 15:41:06 PDT 2019


Author: djg
Date: Thu Aug 29 15:41:05 2019
New Revision: 370416

URL: http://llvm.org/viewvc/llvm-project?rev=370416&view=rev
Log:
[WebAssembly] Implement NO_STRIP

This patch implements support for the NO_STRIP flag, which will allow
__attribute__((used)) to be implemented.

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

Differential Revision: https://reviews.llvm.org/D66968

Modified:
    lld/trunk/docs/ReleaseNotes.rst
    lld/trunk/docs/WebAssembly.rst
    lld/trunk/test/wasm/export.ll
    lld/trunk/wasm/LTO.cpp
    lld/trunk/wasm/MarkLive.cpp
    lld/trunk/wasm/Symbols.cpp
    lld/trunk/wasm/Symbols.h

Modified: lld/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/docs/ReleaseNotes.rst?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/docs/ReleaseNotes.rst (original)
+++ lld/trunk/docs/ReleaseNotes.rst Thu Aug 29 15:41:05 2019
@@ -44,4 +44,7 @@ MachO Improvements
 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.

Modified: lld/trunk/docs/WebAssembly.rst
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/docs/WebAssembly.rst?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/docs/WebAssembly.rst (original)
+++ lld/trunk/docs/WebAssembly.rst Thu Aug 29 15:41:05 2019
@@ -109,7 +109,7 @@ trap at runtime (functions that contain
 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

Modified: lld/trunk/test/wasm/export.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/export.ll?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/test/wasm/export.ll (original)
+++ lld/trunk/test/wasm/export.ll Thu Aug 29 15:41:05 2019
@@ -1,8 +1,15 @@
+; Test in default mode
 ; RUN: llc -filetype=obj %s -o %t.o
 ; RUN: not wasm-ld --export=missing -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s
 ; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.o
 ; RUN: obj2yaml %t.wasm | FileCheck %s
 
+; Now test in Emscripten mode
+; RUN: llc -filetype=obj %s -o %t.o -mtriple=wasm32-unknown-emscripten
+; RUN: not wasm-ld --export=missing -o %t.wasm %t.o 2>&1 | FileCheck -check-prefix=CHECK-ERROR %s
+; RUN: wasm-ld --export=hidden_function -o %t.wasm %t.o
+; RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=CHECK,EMSCRIPTEN
+
 @llvm.used = appending global [1 x i8*] [i8* bitcast (i32 ()* @used_function to i8*)], section "llvm.metadata"
 
 target triple = "wasm32-unknown-unknown"
@@ -43,9 +50,9 @@ entry:
 ; CHECK-NEXT:       - Name:            hidden_function
 ; CHECK-NEXT:         Kind:            FUNCTION
 ; CHECK-NEXT:         Index:           0
-; CHECK-NEXT:       - Name:            used_function
-; CHECK-NEXT:         Kind:            FUNCTION
-; CHECK-NEXT:         Index:           1
+; EMSCRIPTEN-NEXT:  - Name:            used_function
+; EMSCRIPTEN-NEXT:    Kind:            FUNCTION
+; EMSCRIPTEN-NEXT:    Index:           1
 ; CHECK-NEXT:       - Name:            _start
 ; CHECK-NEXT:         Kind:            FUNCTION
 ; CHECK-NEXT:         Index:           2

Modified: lld/trunk/wasm/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/LTO.cpp?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/wasm/LTO.cpp (original)
+++ lld/trunk/wasm/LTO.cpp Thu Aug 29 15:41:05 2019
@@ -105,6 +105,7 @@ void BitcodeCompiler::add(BitcodeFile &f
     // 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);

Modified: lld/trunk/wasm/MarkLive.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/MarkLive.cpp?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/wasm/MarkLive.cpp (original)
+++ lld/trunk/wasm/MarkLive.cpp Thu Aug 29 15:41:05 2019
@@ -69,9 +69,9 @@ void lld::wasm::markLive() {
   if (!config->entry.empty())
     enqueue(symtab->find(config->entry));
 
-  // We need to preserve any exported symbol
+  // We need to preserve any no-strip or 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

Modified: lld/trunk/wasm/Symbols.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.cpp?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.cpp (original)
+++ lld/trunk/wasm/Symbols.cpp Thu Aug 29 15:41:05 2019
@@ -155,6 +155,10 @@ bool Symbol::isExported() const {
   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();

Modified: lld/trunk/wasm/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Symbols.h?rev=370416&r1=370415&r2=370416&view=diff
==============================================================================
--- lld/trunk/wasm/Symbols.h (original)
+++ lld/trunk/wasm/Symbols.h Thu Aug 29 15:41:05 2019
@@ -107,6 +107,10 @@ public:
   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; }




More information about the llvm-commits mailing list