diff options
author | Sam Clegg <sbc@chromium.org> | 2017-09-26 18:21:12 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2017-09-26 18:21:12 +0000 |
commit | afd34c6df76a68b581205a21733ceedf8676932d (patch) | |
tree | e81f19fd4fb611d77e25cc99a551762fbce2ba3d /llvm/lib/Object/WasmObjectFile.cpp | |
parent | 9d10bdf6448f8971e5c893d23bcb7d933a0efce4 (diff) | |
download | llvm-afd34c6df76a68b581205a21733ceedf8676932d.zip llvm-afd34c6df76a68b581205a21733ceedf8676932d.tar.gz llvm-afd34c6df76a68b581205a21733ceedf8676932d.tar.bz2 |
[WebAssembly] Use function/global index space in WasmSymbol
It is useful for the symbol to contain the index of the
function of global it represents in the function/global
index space.
For imports we also store the import index so that the
linker can find, for example, the signature of the
corresponding function, which is defined by the import
In the long run we need to decide whether this API
surface should be closer to binary (where imported
functions are seperate) or the wasm spec (where the
function index space is unified).
Differential Revision: https://reviews.llvm.org/D38189
llvm-svn: 314230
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 77fcac5..c320b91 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -303,13 +303,15 @@ Error WasmObjectFile::parseNameSection(const uint8_t *Ptr, const uint8_t *End) { void WasmObjectFile::populateSymbolTable() { // Add imports to symbol table size_t ImportIndex = 0; + size_t GlobalIndex = 0; + size_t FunctionIndex = 0; for (const wasm::WasmImport& Import : Imports) { switch (Import.Kind) { case wasm::WASM_EXTERNAL_GLOBAL: 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, ImportIndex); + ImportSection, GlobalIndex++, ImportIndex); DEBUG(dbgs() << "Adding import: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); break; @@ -317,7 +319,7 @@ void WasmObjectFile::populateSymbolTable() { SymbolMap.try_emplace(Import.Field, Symbols.size()); Symbols.emplace_back(Import.Field, WasmSymbol::SymbolType::FUNCTION_IMPORT, - ImportSection, ImportIndex); + ImportSection, FunctionIndex++, ImportIndex); DEBUG(dbgs() << "Adding import: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); break; @@ -328,7 +330,6 @@ void WasmObjectFile::populateSymbolTable() { } // Add exports to symbol table - size_t ExportIndex = 0; for (const wasm::WasmExport& Export : Exports) { if (Export.Kind == wasm::WASM_EXTERNAL_FUNCTION || Export.Kind == wasm::WASM_EXTERNAL_GLOBAL) { @@ -339,18 +340,17 @@ void WasmObjectFile::populateSymbolTable() { auto Pair = SymbolMap.try_emplace(Export.Name, Symbols.size()); if (Pair.second) { Symbols.emplace_back(Export.Name, ExportType, - ExportSection, ExportIndex); + ExportSection, Export.Index); DEBUG(dbgs() << "Adding export: " << Symbols.back() << " sym index:" << Symbols.size() << "\n"); } else { uint32_t SymIndex = Pair.first->second; Symbols[SymIndex] = - WasmSymbol(Export.Name, ExportType, ExportSection, ExportIndex); + WasmSymbol(Export.Name, ExportType, ExportSection, Export.Index); DEBUG(dbgs() << "Replacing existing symbol: " << Symbols[SymIndex] << " sym index:" << SymIndex << "\n"); } } - ExportIndex++; } } @@ -825,19 +825,17 @@ uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol& Sym) const { switch (Sym.Type) { case WasmSymbol::SymbolType::FUNCTION_IMPORT: case WasmSymbol::SymbolType::GLOBAL_IMPORT: - return 0; case WasmSymbol::SymbolType::FUNCTION_EXPORT: - return Exports[Sym.ElementIndex].Index; + case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME: + return Sym.ElementIndex; case WasmSymbol::SymbolType::GLOBAL_EXPORT: { - uint32_t GlobalIndex = Exports[Sym.ElementIndex].Index - NumImportedGlobals; + uint32_t GlobalIndex = Sym.ElementIndex - NumImportedGlobals; assert(GlobalIndex < Globals.size()); const wasm::WasmGlobal& Global = Globals[GlobalIndex]; // WasmSymbols correspond only to I32_CONST globals assert(Global.InitExpr.Opcode == wasm::WASM_OPCODE_I32_CONST); return Global.InitExpr.Value.Int32; } - case WasmSymbol::SymbolType::DEBUG_FUNCTION_NAME: - return Sym.ElementIndex; } llvm_unreachable("invalid symbol type"); } |