Skip to content

[Object][Wasm] Move WasmSymbolInfo directly into WasmSymbol (NFC) #80219

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions lld/wasm/InputFiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "lld/Common/Args.h"
#include "lld/Common/CommonLinkerContext.h"
#include "lld/Common/Reproduce.h"
#include "llvm/BinaryFormat/Wasm.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/Wasm.h"
#include "llvm/Support/Path.h"
Expand Down Expand Up @@ -322,20 +323,19 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
return;
}

auto *info = make<WasmSymbolInfo>();
info->Name = tableImport->Field;
info->Kind = WASM_SYMBOL_TYPE_TABLE;
info->ImportModule = tableImport->Module;
info->ImportName = tableImport->Field;
info->Flags = WASM_SYMBOL_UNDEFINED;
info->Flags |= WASM_SYMBOL_NO_STRIP;
info->ElementIndex = 0;
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info->Name
WasmSymbolInfo info;
info.Name = tableImport->Field;
info.Kind = WASM_SYMBOL_TYPE_TABLE;
info.ImportModule = tableImport->Module;
info.ImportName = tableImport->Field;
info.Flags = WASM_SYMBOL_UNDEFINED | WASM_SYMBOL_NO_STRIP;
info.ElementIndex = 0;
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info.Name
<< "\n");
const WasmGlobalType *globalType = nullptr;
const WasmSignature *signature = nullptr;
auto *wasmSym =
make<WasmSymbol>(*info, globalType, &tableImport->Table, signature);
make<WasmSymbol>(info, globalType, &tableImport->Table, signature);
Symbol *sym = createUndefined(*wasmSym, false);
// We're only sure it's a TableSymbol if the createUndefined succeeded.
if (errorCount())
Expand Down
6 changes: 5 additions & 1 deletion llvm/include/llvm/BinaryFormat/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,15 @@ struct WasmDebugName {
StringRef Name;
};

// Info from the linking metadata section of a wasm object file.
struct WasmLinkingData {
uint32_t Version;
std::vector<WasmInitFunc> InitFunctions;
std::vector<StringRef> Comdats;
std::vector<WasmSymbolInfo> SymbolTable;
// The linking section also contains a symbol table. This info (represented
// in a WasmSymbolInfo struct) is stored inside the WasmSymbol object instead
// of in this structure; this allows vectors of WasmSymbols and
// WasmLinkingDatas to be reallocated.
};

struct WasmSignature {
Expand Down
4 changes: 3 additions & 1 deletion llvm/include/llvm/Object/Wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class WasmSymbol {
assert(!Signature || Signature->Kind != wasm::WasmSignature::Placeholder);
}

const wasm::WasmSymbolInfo &Info;
// Symbol info as represented in the symbol's 'syminfo' entry of an object
// file's symbol table.
wasm::WasmSymbolInfo Info;
const wasm::WasmGlobalType *GlobalType;
const wasm::WasmTableType *TableType;
const wasm::WasmSignature *Signature;
Expand Down
11 changes: 2 additions & 9 deletions llvm/lib/Object/WasmObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
uint32_t Count = readVaruint32(Ctx);
// Clear out any symbol information that was derived from the exports
// section.
LinkingData.SymbolTable.clear();
Symbols.clear();
LinkingData.SymbolTable.reserve(Count);
Symbols.reserve(Count);
StringSet<> SymbolNames;

Expand Down Expand Up @@ -844,9 +842,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
return make_error<GenericBinaryError>("duplicate symbol name " +
Twine(Info.Name),
object_error::parse_failed);
LinkingData.SymbolTable.emplace_back(Info);
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType,
Signature);
Symbols.emplace_back(Info, GlobalType, TableType, Signature);
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
}

Expand Down Expand Up @@ -1390,7 +1386,6 @@ Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) {
Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
uint32_t Count = readVaruint32(Ctx);
Exports.reserve(Count);
LinkingData.SymbolTable.reserve(Count);
Symbols.reserve(Count);
for (uint32_t I = 0; I < Count; I++) {
wasm::WasmExport Ex;
Expand Down Expand Up @@ -1455,9 +1450,7 @@ Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
}
Exports.push_back(Ex);
if (Ex.Kind != wasm::WASM_EXTERNAL_MEMORY) {
LinkingData.SymbolTable.emplace_back(Info);
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType,
TableType, Signature);
Symbols.emplace_back(Info, GlobalType, TableType, Signature);
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
}
}
Expand Down
3 changes: 2 additions & 1 deletion llvm/tools/obj2yaml/wasm2yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
}

uint32_t SymbolIndex = 0;
for (const wasm::WasmSymbolInfo &Symbol : Obj.linkingData().SymbolTable) {
for (const object::SymbolRef &Sym : Obj.symbols()) {
const wasm::WasmSymbolInfo &Symbol = Obj.getWasmSymbol(Sym).Info;
WasmYAML::SymbolInfo Info;
Info.Index = SymbolIndex++;
Info.Kind = static_cast<uint32_t>(Symbol.Kind);
Expand Down