diff options
author | Sam Clegg <sbc@chromium.org> | 2018-02-09 20:21:50 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-02-09 20:21:50 +0000 |
commit | 0b55ccf6f032260e2b791645d3d9dab3d58148d7 (patch) | |
tree | 797c8ce38f8796f233dd6045bd7fb0288f70c356 /llvm/lib/Object | |
parent | 33979ce32da1613b787b4b8094085e7515e40904 (diff) | |
download | bcm5719-llvm-0b55ccf6f032260e2b791645d3d9dab3d58148d7.tar.gz bcm5719-llvm-0b55ccf6f032260e2b791645d3d9dab3d58148d7.zip |
[WebAssebmly] Report undefined symbols correctly in objdump
Peviously we were reporting undefined symbol as being defined
by the IMPORT sections.
This change reports undefined symbols in the same that other
formats do, and also removes the need to store the section
with each symbol (since it can be derived from the symbol
type).
Differential Revision: https://reviews.llvm.org/D43101
llvm-svn: 324770
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 3b361390ea1..82adc35076d 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -327,7 +327,7 @@ void WasmObjectFile::populateSymbolTable() { 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 @@ void WasmObjectFile::populateSymbolTable() { 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 @@ void WasmObjectFile::populateSymbolTable() { : 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::parseTypeSection(const uint8_t *Ptr, const uint8_t *End) { } 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::parseGlobalSection(const uint8_t *Ptr, const uint8_t *End) } 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::parseStartSection(const uint8_t *Ptr, const uint8_t *End) } 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::parseElemSection(const uint8_t *Ptr, const uint8_t *End) { } 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 @@ WasmObjectFile::getSymbolType(DataRefImpl Symb) const { Expected<section_iterator> 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)); } |