From a312ae5a63b8ba4dea5dc248c118b2c3e20e7851 Mon Sep 17 00:00:00 2001 From: Andy Wingo Date: Tue, 5 Jan 2021 12:08:58 +0100 Subject: [PATCH] [lld][WebAssembly] Add support for handling table symbols This commit adds table symbol support in a partial way, while still including some special cases for the __indirect_function_table symbol. No change in tests. Differential Revision: https://reviews.llvm.org/D94075 --- include/llvm/BinaryFormat/Wasm.h | 4 ++-- include/llvm/Object/Wasm.h | 5 +++-- lib/Object/WasmObjectFile.cpp | 7 +++---- tools/llvm-readobj/WasmDumper.cpp | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/llvm/BinaryFormat/Wasm.h b/include/llvm/BinaryFormat/Wasm.h index 71022792841..bdef959fafd 100644 --- a/include/llvm/BinaryFormat/Wasm.h +++ b/include/llvm/BinaryFormat/Wasm.h @@ -192,8 +192,8 @@ struct WasmSymbolInfo { // For symbols to be exported from the final module Optional ExportName; union { - // For function or global symbols, the index in function or global index - // space. + // For function, table, or global symbols, the index in function, table, or + // global index space. uint32_t ElementIndex; // For a data symbols, the address of the data relative to segment. WasmDataReference DataRef; diff --git a/include/llvm/Object/Wasm.h b/include/llvm/Object/Wasm.h index 089046d7d42..f7cd2e622ae 100644 --- a/include/llvm/Object/Wasm.h +++ b/include/llvm/Object/Wasm.h @@ -35,7 +35,8 @@ namespace object { class WasmSymbol { public: WasmSymbol(const wasm::WasmSymbolInfo &Info, - const wasm::WasmGlobalType *GlobalType, const uint8_t TableType, + const wasm::WasmGlobalType *GlobalType, + const wasm::WasmTableType *TableType, const wasm::WasmEventType *EventType, const wasm::WasmSignature *Signature) : Info(Info), GlobalType(GlobalType), TableType(TableType), @@ -43,7 +44,7 @@ public: const wasm::WasmSymbolInfo &Info; const wasm::WasmGlobalType *GlobalType; - const uint8_t TableType; + const wasm::WasmTableType *TableType; const wasm::WasmEventType *EventType; const wasm::WasmSignature *Signature; diff --git a/lib/Object/WasmObjectFile.cpp b/lib/Object/WasmObjectFile.cpp index c9b13e4afb4..dac16d225bf 100644 --- a/lib/Object/WasmObjectFile.cpp +++ b/lib/Object/WasmObjectFile.cpp @@ -527,7 +527,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { wasm::WasmSymbolInfo Info; const wasm::WasmSignature *Signature = nullptr; const wasm::WasmGlobalType *GlobalType = nullptr; - uint8_t TableType = 0; + const wasm::WasmTableType *TableType = nullptr; const wasm::WasmEventType *EventType = nullptr; Info.Kind = readUint8(Ctx); @@ -609,7 +609,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { Info.Name = readString(Ctx); unsigned TableIndex = Info.ElementIndex - NumImportedTables; wasm::WasmTable &Table = Tables[TableIndex]; - TableType = Table.Type.ElemType; + TableType = &Table.Type; if (Table.SymbolName.empty()) Table.SymbolName = Info.Name; } else { @@ -620,8 +620,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { } else { Info.Name = Import.Field; } - TableType = Import.Table.ElemType; - // FIXME: Parse limits here too. + TableType = &Import.Table; if (!Import.Module.empty()) { Info.ImportModule = Import.Module; } diff --git a/tools/llvm-readobj/WasmDumper.cpp b/tools/llvm-readobj/WasmDumper.cpp index 488c6faa26b..fb7134d20a8 100644 --- a/tools/llvm-readobj/WasmDumper.cpp +++ b/tools/llvm-readobj/WasmDumper.cpp @@ -24,7 +24,7 @@ static const EnumEntry WasmSymbolTypes[] = { #define ENUM_ENTRY(X) \ { #X, wasm::WASM_SYMBOL_TYPE_##X } ENUM_ENTRY(FUNCTION), ENUM_ENTRY(DATA), ENUM_ENTRY(GLOBAL), - ENUM_ENTRY(SECTION), ENUM_ENTRY(EVENT), + ENUM_ENTRY(SECTION), ENUM_ENTRY(EVENT), ENUM_ENTRY(TABLE), #undef ENUM_ENTRY };