aboutsummaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@chromium.org>2024-02-02 10:44:52 -0800
committerGitHub <noreply@github.com>2024-02-02 10:44:52 -0800
commitef1f999e13bd58394bc1099c87a470d91682153d (patch)
tree510139b4e4e8c42d9f418ac8581a0cf9bcea8172 /llvm
parentd4de4c3eafa9b70c255a4d6d5a14dccff79d10e9 (diff)
downloadllvm-ef1f999e13bd58394bc1099c87a470d91682153d.zip
llvm-ef1f999e13bd58394bc1099c87a470d91682153d.tar.gz
llvm-ef1f999e13bd58394bc1099c87a470d91682153d.tar.bz2
[Object][Wasm] Move WasmSymbolInfo directly into WasmSymbol (NFC) (#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 #76107
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/BinaryFormat/Wasm.h6
-rw-r--r--llvm/include/llvm/Object/Wasm.h4
-rw-r--r--llvm/lib/Object/WasmObjectFile.cpp11
-rw-r--r--llvm/tools/obj2yaml/wasm2yaml.cpp3
4 files changed, 12 insertions, 12 deletions
diff --git a/llvm/include/llvm/BinaryFormat/Wasm.h b/llvm/include/llvm/BinaryFormat/Wasm.h
index cd13b70..aec6ea0 100644
--- a/llvm/include/llvm/BinaryFormat/Wasm.h
+++ b/llvm/include/llvm/BinaryFormat/Wasm.h
@@ -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 {
diff --git a/llvm/include/llvm/Object/Wasm.h b/llvm/include/llvm/Object/Wasm.h
index 927dce8..13d9a17e 100644
--- a/llvm/include/llvm/Object/Wasm.h
+++ b/llvm/include/llvm/Object/Wasm.h
@@ -43,7 +43,9 @@ public:
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;
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp
index 953e7c7..4778562 100644
--- a/llvm/lib/Object/WasmObjectFile.cpp
+++ b/llvm/lib/Object/WasmObjectFile.cpp
@@ -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;
@@ -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");
}
@@ -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;
@@ -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");
}
}
diff --git a/llvm/tools/obj2yaml/wasm2yaml.cpp b/llvm/tools/obj2yaml/wasm2yaml.cpp
index c15d64c..9aa7f5a 100644
--- a/llvm/tools/obj2yaml/wasm2yaml.cpp
+++ b/llvm/tools/obj2yaml/wasm2yaml.cpp
@@ -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);