Skip to content

Commit ef1f999

Browse files
authored
[Object][Wasm] Move WasmSymbolInfo directly into WasmSymbol (NFC) (llvm#80219)
Move the WasmSymbolInfos from their own vector on the WasmLinkingData directly into the WasmSymbol object. Removing the const-ref to an external object allows the vector of WasmSymbols to be safely expanded/reallocated; generating symbol info from the name section will require this, as the numbers of function and data segment names are stored separately. This is a step toward generating symbol information from name sections for llvm#76107
1 parent d4de4c3 commit ef1f999

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

lld/wasm/InputFiles.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "lld/Common/Args.h"
1616
#include "lld/Common/CommonLinkerContext.h"
1717
#include "lld/Common/Reproduce.h"
18+
#include "llvm/BinaryFormat/Wasm.h"
1819
#include "llvm/Object/Binary.h"
1920
#include "llvm/Object/Wasm.h"
2021
#include "llvm/Support/Path.h"
@@ -322,20 +323,19 @@ void ObjFile::addLegacyIndirectFunctionTableIfNeeded(
322323
return;
323324
}
324325

325-
auto *info = make<WasmSymbolInfo>();
326-
info->Name = tableImport->Field;
327-
info->Kind = WASM_SYMBOL_TYPE_TABLE;
328-
info->ImportModule = tableImport->Module;
329-
info->ImportName = tableImport->Field;
330-
info->Flags = WASM_SYMBOL_UNDEFINED;
331-
info->Flags |= WASM_SYMBOL_NO_STRIP;
332-
info->ElementIndex = 0;
333-
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info->Name
326+
WasmSymbolInfo info;
327+
info.Name = tableImport->Field;
328+
info.Kind = WASM_SYMBOL_TYPE_TABLE;
329+
info.ImportModule = tableImport->Module;
330+
info.ImportName = tableImport->Field;
331+
info.Flags = WASM_SYMBOL_UNDEFINED | WASM_SYMBOL_NO_STRIP;
332+
info.ElementIndex = 0;
333+
LLVM_DEBUG(dbgs() << "Synthesizing symbol for table import: " << info.Name
334334
<< "\n");
335335
const WasmGlobalType *globalType = nullptr;
336336
const WasmSignature *signature = nullptr;
337337
auto *wasmSym =
338-
make<WasmSymbol>(*info, globalType, &tableImport->Table, signature);
338+
make<WasmSymbol>(info, globalType, &tableImport->Table, signature);
339339
Symbol *sym = createUndefined(*wasmSym, false);
340340
// We're only sure it's a TableSymbol if the createUndefined succeeded.
341341
if (errorCount())

llvm/include/llvm/BinaryFormat/Wasm.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,15 @@ struct WasmDebugName {
467467
StringRef Name;
468468
};
469469

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

477481
struct WasmSignature {

llvm/include/llvm/Object/Wasm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class WasmSymbol {
4343
assert(!Signature || Signature->Kind != wasm::WasmSignature::Placeholder);
4444
}
4545

46-
const wasm::WasmSymbolInfo &Info;
46+
// Symbol info as represented in the symbol's 'syminfo' entry of an object
47+
// file's symbol table.
48+
wasm::WasmSymbolInfo Info;
4749
const wasm::WasmGlobalType *GlobalType;
4850
const wasm::WasmTableType *TableType;
4951
const wasm::WasmSignature *Signature;

llvm/lib/Object/WasmObjectFile.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -642,9 +642,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
642642
uint32_t Count = readVaruint32(Ctx);
643643
// Clear out any symbol information that was derived from the exports
644644
// section.
645-
LinkingData.SymbolTable.clear();
646645
Symbols.clear();
647-
LinkingData.SymbolTable.reserve(Count);
648646
Symbols.reserve(Count);
649647
StringSet<> SymbolNames;
650648

@@ -844,9 +842,7 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) {
844842
return make_error<GenericBinaryError>("duplicate symbol name " +
845843
Twine(Info.Name),
846844
object_error::parse_failed);
847-
LinkingData.SymbolTable.emplace_back(Info);
848-
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType, TableType,
849-
Signature);
845+
Symbols.emplace_back(Info, GlobalType, TableType, Signature);
850846
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
851847
}
852848

@@ -1390,7 +1386,6 @@ Error WasmObjectFile::parseGlobalSection(ReadContext &Ctx) {
13901386
Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
13911387
uint32_t Count = readVaruint32(Ctx);
13921388
Exports.reserve(Count);
1393-
LinkingData.SymbolTable.reserve(Count);
13941389
Symbols.reserve(Count);
13951390
for (uint32_t I = 0; I < Count; I++) {
13961391
wasm::WasmExport Ex;
@@ -1455,9 +1450,7 @@ Error WasmObjectFile::parseExportSection(ReadContext &Ctx) {
14551450
}
14561451
Exports.push_back(Ex);
14571452
if (Ex.Kind != wasm::WASM_EXTERNAL_MEMORY) {
1458-
LinkingData.SymbolTable.emplace_back(Info);
1459-
Symbols.emplace_back(LinkingData.SymbolTable.back(), GlobalType,
1460-
TableType, Signature);
1453+
Symbols.emplace_back(Info, GlobalType, TableType, Signature);
14611454
LLVM_DEBUG(dbgs() << "Adding symbol: " << Symbols.back() << "\n");
14621455
}
14631456
}

llvm/tools/obj2yaml/wasm2yaml.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ WasmDumper::dumpCustomSection(const WasmSection &WasmSec) {
124124
}
125125

126126
uint32_t SymbolIndex = 0;
127-
for (const wasm::WasmSymbolInfo &Symbol : Obj.linkingData().SymbolTable) {
127+
for (const object::SymbolRef &Sym : Obj.symbols()) {
128+
const wasm::WasmSymbolInfo &Symbol = Obj.getWasmSymbol(Sym).Info;
128129
WasmYAML::SymbolInfo Info;
129130
Info.Index = SymbolIndex++;
130131
Info.Kind = static_cast<uint32_t>(Symbol.Kind);

0 commit comments

Comments
 (0)