mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[WebAssembly] Add WebAssembly support to llvm-symbolizer
The only thing missing for basic llvm-symbolizer support is the ability on lib/Object to get a wasm symbol's section ID, which allows sorting and computation of the symbols' sizes. Also, when the WasmAsmParser switches sections on new functions, also add the section to the list of Dwarf sections if Dwarf is being generated for assembly; this allows writing of simple tests. Reviewers: sbc100, jhenderson, aardappel Differential Revision: https://reviews.llvm.org/D73246
This commit is contained in:
parent
59615c393a
commit
b5f6f74751
@ -169,6 +169,7 @@ public:
|
||||
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;
|
||||
|
||||
// Overrides from SectionRef.
|
||||
void moveSectionNext(DataRefImpl &Sec) const override;
|
||||
@ -230,6 +231,7 @@ private:
|
||||
|
||||
const WasmSection &getWasmSection(DataRefImpl Ref) const;
|
||||
const wasm::WasmRelocation &getWasmRelocation(DataRefImpl Ref) const;
|
||||
uint32_t getSymbolSectionIdImpl(const WasmSymbol &Symb) const;
|
||||
|
||||
Error parseSection(WasmSection &Sec);
|
||||
Error parseCustomSection(WasmSection &Sec, ReadContext &Ctx);
|
||||
|
@ -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 @@ int llvm::object::compareAddress(const SymEntry *A, const SymEntry *B) {
|
||||
static unsigned getSectionID(const ObjectFile &O, SectionRef Sec) {
|
||||
if (auto *M = dyn_cast<MachOObjectFile>(&O))
|
||||
return M->getSectionID(Sec);
|
||||
if (const 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 (const auto *M = dyn_cast<WasmObjectFile>(&O))
|
||||
return M->getSymbolSectionId(Sym);
|
||||
return cast<COFFObjectFile>(O).getSymbolSectionID(Sym);
|
||||
}
|
||||
|
||||
|
@ -1365,26 +1365,30 @@ WasmObjectFile::getSymbolSection(DataRefImpl Symb) const {
|
||||
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++; }
|
||||
|
@ -879,6 +879,9 @@ public:
|
||||
auto SecName = ".text." + SymName;
|
||||
auto WS = getContext().getWasmSection(SecName, SectionKind::getText());
|
||||
getStreamer().SwitchSection(WS);
|
||||
// Also generate DWARF for this section if requested.
|
||||
if (getContext().getGenDwarfForAssembly())
|
||||
getContext().addGenDwarfSection(WS);
|
||||
}
|
||||
|
||||
void onEndOfFunction() {
|
||||
|
23
test/tools/llvm-symbolizer/wasm-basic.s
Normal file
23
test/tools/llvm-symbolizer/wasm-basic.s
Normal file
@ -0,0 +1,23 @@
|
||||
# REQUIRES: webassembly-registered-target
|
||||
# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj %s -o %t.o -g
|
||||
|
||||
foo:
|
||||
.functype foo () -> ()
|
||||
nop
|
||||
end_function
|
||||
|
||||
bar:
|
||||
.functype bar (i32) -> (i32)
|
||||
return
|
||||
end_function
|
||||
|
||||
# RUN: llvm-symbolizer -e %t.o 3 4 7 8 | FileCheck %s
|
||||
## Byte 1 is the function length and 2 is the locals declaration.
|
||||
## Currently no line corresponds to them.
|
||||
## TODO: create a loc for .functype?
|
||||
|
||||
## Test 2 functions to ensure wasm's function-sections system works.
|
||||
# CHECK: wasm-basic.s:6:0
|
||||
# CHECK: wasm-basic.s:7:0
|
||||
# CHECK: wasm-basic.s:11:0
|
||||
# CHECK: wasm-basic.s:12:0
|
Loading…
x
Reference in New Issue
Block a user