[PATCH] D71793: [WebAssembly] Support wasm exports with zero-length names.

Dan Gohman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 20 21:49:58 PST 2019


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

Zero-length strings are valid export names in WebAssembly, so allow
users to specify them.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71793

Files:
  lld/test/wasm/export-name.ll
  lld/wasm/InputChunks.h
  lld/wasm/Writer.cpp
  llvm/include/llvm/BinaryFormat/Wasm.h


Index: llvm/include/llvm/BinaryFormat/Wasm.h
===================================================================
--- llvm/include/llvm/BinaryFormat/Wasm.h
+++ llvm/include/llvm/BinaryFormat/Wasm.h
@@ -131,7 +131,7 @@
   uint32_t CodeSectionOffset;
   uint32_t Size;
   uint32_t CodeOffset;  // start of Locals and Body
-  StringRef ExportName; // from the "export" section
+  Optional<StringRef> ExportName; // from the "export" section
   StringRef SymbolName; // from the "linking" section
   StringRef DebugName;  // from the "name" section
   uint32_t Comdat;      // from the "comdat info" section
@@ -180,7 +180,7 @@
   uint32_t Flags;
   StringRef ImportModule; // For undefined symbols the module of the import
   StringRef ImportName;   // For undefined symbols the name of the import
-  StringRef ExportName;   // For symbols to be exported from the final module
+  Optional<StringRef> ExportName;   // For symbols to be exported from the final module
   union {
     // For function or global symbols, the index in function or global index
     // space.
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -519,9 +519,8 @@
     StringRef name = sym->getName();
     WasmExport export_;
     if (auto *f = dyn_cast<DefinedFunction>(sym)) {
-      StringRef exportName = f->function->getExportName();
-      if (!exportName.empty()) {
-        name = exportName;
+      if (Optional<StringRef> exportName = f->function->getExportName()) {
+        name = *exportName;
       }
       export_ = {name, WASM_EXTERNAL_FUNCTION, f->getFunctionIndex()};
     } else if (auto *g = dyn_cast<DefinedGlobal>(sym)) {
Index: lld/wasm/InputChunks.h
===================================================================
--- lld/wasm/InputChunks.h
+++ lld/wasm/InputChunks.h
@@ -130,8 +130,8 @@
   void writeTo(uint8_t *sectionStart) const override;
   StringRef getName() const override { return function->SymbolName; }
   StringRef getDebugName() const override { return function->DebugName; }
-  StringRef getExportName() const {
-    return function ? function->ExportName : "";
+  llvm::Optional<StringRef> getExportName() const {
+    return function ? function->ExportName : llvm::Optional<StringRef>();
   }
   uint32_t getComdat() const override { return function->Comdat; }
   uint32_t getFunctionInputOffset() const { return getInputSectionOffset(); }
Index: lld/test/wasm/export-name.ll
===================================================================
--- lld/test/wasm/export-name.ll
+++ lld/test/wasm/export-name.ll
@@ -8,6 +8,10 @@
     ret void
 }
 
+define void @qux() #1 {
+    ret void
+}
+
 define void @_start() {
     call void @foo()
     ret void
@@ -15,6 +19,8 @@
 
 attributes #0 = { "wasm-export-name"="bar" }
 
+attributes #1 = { "wasm-export-name"="" }
+
 ; CHECK:       - Type:            EXPORT
 ; CHECK-NEXT:    Exports:
 ; CHECK-NEXT:      - Name:            memory
@@ -23,6 +29,9 @@
 ; CHECK-NEXT:      - Name:            bar
 ; CHECK-NEXT:        Kind:            FUNCTION
 ; CHECK-NEXT:        Index:           0
-; CHECK-NEXT:      - Name:            _start
+; CHECK-NEXT:      - Name:            ''
 ; CHECK-NEXT:        Kind:            FUNCTION
 ; CHECK-NEXT:        Index:           1
+; CHECK-NEXT:      - Name:            _start
+; CHECK-NEXT:        Kind:            FUNCTION
+; CHECK-NEXT:        Index:           2


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71793.234999.patch
Type: text/x-patch
Size: 3452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191221/5eee999b/attachment.bin>


More information about the llvm-commits mailing list