diff --git a/lld/test/wasm/export-name.ll b/lld/test/wasm/export-name.ll --- a/lld/test/wasm/export-name.ll +++ b/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 diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h --- a/lld/wasm/InputChunks.h +++ b/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 getExportName() const { + return function ? function->ExportName : llvm::Optional(); } 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 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -519,9 +519,8 @@ StringRef name = sym->getName(); WasmExport export_; if (auto *f = dyn_cast(sym)) { - StringRef exportName = f->function->getExportName(); - if (!exportName.empty()) { - name = exportName; + if (Optional exportName = f->function->getExportName()) { + name = *exportName; } export_ = {name, WASM_EXTERNAL_FUNCTION, f->getFunctionIndex()}; } else if (auto *g = dyn_cast(sym)) { diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h --- a/llvm/include/llvm/BinaryFormat/Wasm.h +++ b/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 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 ExportName; // For symbols to be exported from the final module union { // For function or global symbols, the index in function or global index // space.