[llvm] r324770 - [WebAssebmly] Report undefined symbols correctly in objdump
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 9 12:21:50 PST 2018
Author: sbc
Date: Fri Feb 9 12:21:50 2018
New Revision: 324770
URL: http://llvm.org/viewvc/llvm-project?rev=324770&view=rev
Log:
[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
Modified:
llvm/trunk/include/llvm/Object/Wasm.h
llvm/trunk/lib/Object/WasmObjectFile.cpp
llvm/trunk/test/MC/WebAssembly/weak-alias.ll
llvm/trunk/test/tools/llvm-objdump/WebAssembly/symbol-table.test
Modified: llvm/trunk/include/llvm/Object/Wasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Object/Wasm.h?rev=324770&r1=324769&r2=324770&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Object/Wasm.h (original)
+++ llvm/trunk/include/llvm/Object/Wasm.h Fri Feb 9 12:21:50 2018
@@ -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;
};
Modified: llvm/trunk/lib/Object/WasmObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Object/WasmObjectFile.cpp?rev=324770&r1=324769&r2=324770&view=diff
==============================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp (original)
+++ llvm/trunk/lib/Object/WasmObjectFile.cpp Fri Feb 9 12:21:50 2018
@@ -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(c
}
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
}
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(
}
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(c
}
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(DataRefImp
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));
}
Modified: llvm/trunk/test/MC/WebAssembly/weak-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/weak-alias.ll?rev=324770&r1=324769&r2=324770&view=diff
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/weak-alias.ll (original)
+++ llvm/trunk/test/MC/WebAssembly/weak-alias.ll Fri Feb 9 12:21:50 2018
@@ -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
Modified: llvm/trunk/test/tools/llvm-objdump/WebAssembly/symbol-table.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objdump/WebAssembly/symbol-table.test?rev=324770&r1=324769&r2=324770&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objdump/WebAssembly/symbol-table.test (original)
+++ llvm/trunk/test/tools/llvm-objdump/WebAssembly/symbol-table.test Fri Feb 9 12:21:50 2018
@@ -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
More information about the llvm-commits
mailing list