[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
This commit is contained in:
Dan Gohman 2019-12-20 21:44:24 -08:00
parent d865437d9c
commit 66bfbedbdf
4 changed files with 15 additions and 7 deletions

View File

@ -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

View File

@ -130,8 +130,8 @@ public:
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(); }

View File

@ -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)) {

View File

@ -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