[PATCH] D73246: [WIP] Add WebAssembly support to llvm-symbolizer
Derek Schuff via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 17:41:37 PST 2020
dschuff created this revision.
dschuff added a reviewer: sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, jgravelle-google.
Herald added a project: LLVM.
Recognize WebAssembly object files when sorting symbols by section ID
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D73246
Files:
llvm/include/llvm/Object/Wasm.h
llvm/lib/Object/SymbolSize.cpp
llvm/lib/Object/WasmObjectFile.cpp
Index: llvm/lib/Object/WasmObjectFile.cpp
===================================================================
--- llvm/lib/Object/WasmObjectFile.cpp
+++ llvm/lib/Object/WasmObjectFile.cpp
@@ -1365,26 +1365,30 @@
return section_end();
DataRefImpl Ref;
+ Ref.d.a = getSymbolSectionIdImpl(Sym);
+ return section_iterator(SectionRef(Ref, this));
+}
+
+uint32_t WasmObjectFile::getSymbolSectionId(SymbolRef Symb) const {
+ const WasmSymbol &Sym = getWasmSymbol(Symb);
+ return getSymbolSectionIdImpl(Sym);
+}
+
+uint32_t WasmObjectFile::getSymbolSectionIdImpl(const WasmSymbol &Sym) const {
switch (Sym.Info.Kind) {
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
- Ref.d.a = CodeSection;
- break;
+ return CodeSection;
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
- Ref.d.a = GlobalSection;
- break;
+ return GlobalSection;
case wasm::WASM_SYMBOL_TYPE_DATA:
- Ref.d.a = DataSection;
- break;
+ return DataSection;
case wasm::WASM_SYMBOL_TYPE_SECTION:
- Ref.d.a = Sym.Info.ElementIndex;
- break;
+ return Sym.Info.ElementIndex;
case wasm::WASM_SYMBOL_TYPE_EVENT:
- Ref.d.a = EventSection;
- break;
+ return EventSection;
default:
llvm_unreachable("Unknown WasmSymbol::SymbolType");
}
- return section_iterator(SectionRef(Ref, this));
}
void WasmObjectFile::moveSectionNext(DataRefImpl &Sec) const { Sec.d.a++; }
Index: llvm/lib/Object/SymbolSize.cpp
===================================================================
--- llvm/lib/Object/SymbolSize.cpp
+++ llvm/lib/Object/SymbolSize.cpp
@@ -11,6 +11,7 @@
#include "llvm/Object/COFF.h"
#include "llvm/Object/ELFObjectFile.h"
#include "llvm/Object/MachO.h"
+#include "llvm/Object/Wasm.h"
using namespace llvm;
using namespace object;
@@ -27,12 +28,17 @@
static unsigned getSectionID(const ObjectFile &O, SectionRef Sec) {
if (auto *M = dyn_cast<MachOObjectFile>(&O))
return M->getSectionID(Sec);
+ if (auto *M = dyn_cast<WasmObjectFile>(&O))
+ return Sec.getIndex();
+
return cast<COFFObjectFile>(O).getSectionID(Sec);
}
static unsigned getSymbolSectionID(const ObjectFile &O, SymbolRef Sym) {
if (auto *M = dyn_cast<MachOObjectFile>(&O))
return M->getSymbolSectionID(Sym);
+ if (auto *M = dyn_cast<WasmObjectFile>(&O))
+ return M->getSymbolSectionId(Sym);
return cast<COFFObjectFile>(O).getSymbolSectionID(Sym);
}
@@ -74,6 +80,8 @@
// Compute the size as the gap to the next symbol
for (unsigned I = 0, N = Addresses.size() - 1; I < N; ++I) {
auto &P = Addresses[I];
+ dbgs() << "Address " << P.Address <<'\n';
+
if (P.I == O.symbol_end())
continue;
Index: llvm/include/llvm/Object/Wasm.h
===================================================================
--- llvm/include/llvm/Object/Wasm.h
+++ llvm/include/llvm/Object/Wasm.h
@@ -168,6 +168,8 @@
uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
+ uint32_t getSymbolSectionId(SymbolRef Sym) const;
+ uint32_t getSymbolSectionIdImpl(const WasmSymbol &Symb) const;
// Overrides from SectionRef.
void moveSectionNext(DataRefImpl &Sec) const override;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73246.239747.patch
Type: text/x-patch
Size: 3281 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200123/67655334/attachment.bin>
More information about the llvm-commits
mailing list