Index: include/llvm/Object/Wasm.h =================================================================== --- include/llvm/Object/Wasm.h +++ include/llvm/Object/Wasm.h @@ -41,14 +41,13 @@ GLOBAL_EXPORT, }; - WasmSymbol(StringRef Name, SymbolType Type, uint32_t Section, - uint32_t ElementIndex, uint32_t FunctionType = 0) - : Name(Name), Type(Type), Section(Section), ElementIndex(ElementIndex), + WasmSymbol(StringRef Name, SymbolType Type, uint32_t ElementIndex, + uint32_t FunctionType = 0) + : Name(Name), Type(Type), ElementIndex(ElementIndex), FunctionType(FunctionType) {} StringRef Name; SymbolType Type; - uint32_t Section; uint32_t Flags = 0; // Index into either the function or global index space. @@ -68,8 +67,8 @@ } bool isTypeFunction() const { - return Type == WasmSymbol::SymbolType::FUNCTION_IMPORT || - Type == WasmSymbol::SymbolType::FUNCTION_EXPORT; + return Type == SymbolType::FUNCTION_IMPORT || + Type == SymbolType::FUNCTION_EXPORT; } bool isTypeGlobal() const { @@ -266,8 +265,8 @@ wasm::WasmLinkingData LinkingData; uint32_t NumImportedGlobals = 0; uint32_t NumImportedFunctions = 0; - uint32_t ImportSection = 0; - uint32_t ExportSection = 0; + uint32_t CodeSection = 0; + uint32_t DataSection = 0; StringMap SymbolMap; }; Index: lib/Object/WasmObjectFile.cpp =================================================================== --- lib/Object/WasmObjectFile.cpp +++ lib/Object/WasmObjectFile.cpp @@ -327,7 +327,7 @@ assert(Import.Global.Type == wasm::WASM_TYPE_I32); SymbolMap.try_emplace(Import.Field, Symbols.size()); Symbols.emplace_back(Import.Field, WasmSymbol::SymbolType::GLOBAL_IMPORT, - ImportSection, GlobalIndex++); + GlobalIndex++); DEBUG(dbgs() << "Adding import: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); break; @@ -335,7 +335,7 @@ SymbolMap.try_emplace(Import.Field, Symbols.size()); Symbols.emplace_back(Import.Field, WasmSymbol::SymbolType::FUNCTION_IMPORT, - ImportSection, FunctionIndex++, Import.SigIndex); + FunctionIndex++, Import.SigIndex); DEBUG(dbgs() << "Adding import: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); break; @@ -354,14 +354,13 @@ : WasmSymbol::SymbolType::GLOBAL_EXPORT; auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size()); if (Pair.second) { - Symbols.emplace_back(Export.Name, ExportType, - ExportSection, Export.Index); + Symbols.emplace_back(Export.Name, ExportType, Export.Index); DEBUG(dbgs() << "Adding export: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); } else { uint32_t SymIndex = Pair.first->second; const WasmSymbol &OldSym = Symbols[SymIndex]; - WasmSymbol NewSym(Export.Name, ExportType, ExportSection, Export.Index); + WasmSymbol NewSym(Export.Name, ExportType, Export.Index); NewSym.setAltIndex(OldSym.ElementIndex); Symbols[SymIndex] = NewSym; @@ -628,7 +627,6 @@ } Error WasmObjectFile::parseImportSection(const uint8_t *Ptr, const uint8_t *End) { - ImportSection = Sections.size(); uint32_t Count = readVaruint32(Ptr); Imports.reserve(Count); for (uint32_t i = 0; i < Count; i++) { @@ -726,7 +724,6 @@ } Error WasmObjectFile::parseExportSection(const uint8_t *Ptr, const uint8_t *End) { - ExportSection = Sections.size(); uint32_t Count = readVaruint32(Ptr); Exports.reserve(Count); for (uint32_t i = 0; i < Count; i++) { @@ -783,6 +780,7 @@ } Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) { + CodeSection = Sections.size(); const uint8_t *CodeSectionStart = Ptr; uint32_t FunctionCount = readVaruint32(Ptr); if (FunctionCount != FunctionTypes.size()) { @@ -846,6 +844,7 @@ } Error WasmObjectFile::parseDataSection(const uint8_t *Ptr, const uint8_t *End) { + DataSection = Sections.size(); const uint8_t *Start = Ptr; uint32_t Count = readVaruint32(Ptr); DataSegments.reserve(Count); @@ -987,7 +986,13 @@ Expected WasmObjectFile::getSymbolSection(DataRefImpl Symb) const { DataRefImpl Ref; - Ref.d.a = getWasmSymbol(Symb).Section; + const WasmSymbol& Sym = getWasmSymbol(Symb); + if (Sym.Type == WasmSymbol::SymbolType::GLOBAL_EXPORT) + Ref.d.a = DataSection; + else if (Sym.Type == WasmSymbol::SymbolType::FUNCTION_EXPORT) + Ref.d.a = CodeSection; + else + return section_end(); return section_iterator(SectionRef(Ref, this)); } Index: test/MC/WebAssembly/weak-alias.ll =================================================================== --- test/MC/WebAssembly/weak-alias.ll +++ test/MC/WebAssembly/weak-alias.ll @@ -231,13 +231,13 @@ ; CHECK-NEXT: ... ; CHECK-SYMS: SYMBOL TABLE: -; CHECK-SYMS-NEXT: 00000001 gw F EXPORT .hidden foo_alias -; CHECK-SYMS-NEXT: 00000000 gw EXPORT .hidden bar_alias -; CHECK-SYMS-NEXT: 00000001 g F EXPORT .hidden foo -; CHECK-SYMS-NEXT: 00000002 g F EXPORT .hidden call_direct -; CHECK-SYMS-NEXT: 00000003 g F EXPORT .hidden call_alias -; CHECK-SYMS-NEXT: 00000004 g F EXPORT .hidden call_direct_ptr -; CHECK-SYMS-NEXT: 00000008 g EXPORT direct_address -; CHECK-SYMS-NEXT: 00000005 g F EXPORT .hidden call_alias_ptr -; CHECK-SYMS-NEXT: 00000010 g EXPORT alias_address -; CHECK-SYMS-NEXT: 00000000 g EXPORT bar +; CHECK-SYMS-NEXT: 00000001 gw F CODE .hidden foo_alias +; CHECK-SYMS-NEXT: 00000000 gw DATA .hidden bar_alias +; CHECK-SYMS-NEXT: 00000001 g F CODE .hidden foo +; CHECK-SYMS-NEXT: 00000002 g F CODE .hidden call_direct +; CHECK-SYMS-NEXT: 00000003 g F CODE .hidden call_alias +; CHECK-SYMS-NEXT: 00000004 g F CODE .hidden call_direct_ptr +; CHECK-SYMS-NEXT: 00000008 g DATA direct_address +; CHECK-SYMS-NEXT: 00000005 g F CODE .hidden call_alias_ptr +; CHECK-SYMS-NEXT: 00000010 g DATA alias_address +; CHECK-SYMS-NEXT: 00000000 g DATA bar Index: test/tools/llvm-objdump/WebAssembly/symbol-table.test =================================================================== --- test/tools/llvm-objdump/WebAssembly/symbol-table.test +++ test/tools/llvm-objdump/WebAssembly/symbol-table.test @@ -1,8 +1,8 @@ RUN: llvm-objdump -t %p/../Inputs/trivial.obj.wasm | FileCheck %s CHECK: SYMBOL TABLE: -CHECK-NEXT: 00000000 g F IMPORT puts -CHECK-NEXT: 00000000 g F IMPORT SomeOtherFunction -CHECK-NEXT: 00000002 g F EXPORT main -CHECK-NEXT: 00000010 g EXPORT var +CHECK-NEXT: 00000000 g F *UND* puts +CHECK-NEXT: 00000000 g F *UND* SomeOtherFunction +CHECK-NEXT: 00000002 g F CODE main +CHECK-NEXT: 00000010 g DATA var