mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[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
This commit is contained in:
parent
25efe28daf
commit
8287e385f0
@ -41,14 +41,13 @@ public:
|
||||
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 @@ public:
|
||||
}
|
||||
|
||||
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 @@ private:
|
||||
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<uint32_t> SymbolMap;
|
||||
};
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
|
@ -231,13 +231,13 @@ entry:
|
||||
; 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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user