[llvm] 66bfbed - [WebAssembly] Support wasm exports with zero-length names.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 16:30:33 PDT 2020
Author: Dan Gohman
Date: 2020-03-26T16:20:43-07:00
New Revision: 66bfbedbdfb98bb3c8fbda9ee839e46b430122d1
URL: https://github.com/llvm/llvm-project/commit/66bfbedbdfb98bb3c8fbda9ee839e46b430122d1
DIFF: https://github.com/llvm/llvm-project/commit/66bfbedbdfb98bb3c8fbda9ee839e46b430122d1.diff
LOG: [WebAssembly] Support wasm exports with zero-length names.
Zero-length strings are valid export names in WebAssembly, so allow
users to specify them.
Differential Revision: https://reviews.llvm.org/D71793
Added:
Modified:
lld/test/wasm/export-name.ll
lld/wasm/InputChunks.h
lld/wasm/Writer.cpp
llvm/include/llvm/BinaryFormat/Wasm.h
Removed:
################################################################################
diff --git a/lld/test/wasm/export-name.ll b/lld/test/wasm/export-name.ll
index 83a8bd907c79..b02f253760d1 100644
--- a/lld/test/wasm/export-name.ll
+++ b/lld/test/wasm/export-name.ll
@@ -8,6 +8,10 @@ define void @foo() #0 {
ret void
}
+define void @qux() #1 {
+ ret void
+}
+
define void @_start() {
call void @foo()
ret void
@@ -15,6 +19,8 @@ define void @_start() {
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 @@ attributes #0 = { "wasm-export-name"="bar" }
; 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
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
index 030c9a9dd561..cadff6883fa4 100644
--- a/lld/wasm/InputChunks.h
+++ b/lld/wasm/InputChunks.h
@@ -130,8 +130,8 @@ class InputFunction : public InputChunk {
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(); }
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
index ca0bfef4599e..9f4b6adc48bb 100644
--- a/lld/wasm/Writer.cpp
+++ b/lld/wasm/Writer.cpp
@@ -520,9 +520,8 @@ void Writer::calculateExports() {
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)) {
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index e39760e59ec2..dd743dbbbefa 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -132,7 +132,7 @@ struct WasmFunction {
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
More information about the llvm-commits
mailing list