diff options
author | Derek Schuff <dschuff@chromium.org> | 2024-02-07 11:51:19 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-07 11:51:19 -0800 |
commit | 8b0f47bfa4b6aa1bafa10261444c93aba5a2d31d (patch) | |
tree | eefe89c0482e4ebbc8dad1f0d819e2a38ab045e1 /llvm/tools | |
parent | 2ecf608829252d7d5b530a03b87817cd948a3386 (diff) | |
download | llvm-8b0f47bfa4b6aa1bafa10261444c93aba5a2d31d.zip llvm-8b0f47bfa4b6aa1bafa10261444c93aba5a2d31d.tar.gz llvm-8b0f47bfa4b6aa1bafa10261444c93aba5a2d31d.tar.bz2 |
[Object][Wasm] Use file offset for section addresses in linked wasm files (#80529)
Wasm has no unified virtual memory space as other object formats and
architectures do, so previously WasmObjectFile reported 0 for all
section addresses, and until 428cf71ff used section offsets for function
symbols. Now we use file offsets for function symbols, and this change
switches section addresses to do the same (in linked files). The main
result of this is that objdump now reports VMAs in section listings, and
also uses file offets rather than section offsets when disassembling
linked binaries (matching the behavior of other disassemblers and stack
traces produced by browwsers). To make this work, this PR also updates
objdump's generation of synthetics fallback symbols to match lib/Object
and also correctly plumbs symbol types for regular and dummy symbols
through to the backend to avoid needing special knowledge of address 0.
This also paves the way for generating symbols from name sections rather
than symbol tables or imports (see #76107) by allowing the
disassembler's synthetic fallback symbols match the name-section
generated symbols (in a followup PR).
Diffstat (limited to 'llvm/tools')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index b4467ec..de52ebc 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -29,6 +29,7 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringSet.h" #include "llvm/ADT/Twine.h" +#include "llvm/BinaryFormat/Wasm.h" #include "llvm/DebugInfo/BTF/BTFParser.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" #include "llvm/DebugInfo/Symbolize/SymbolizableModule.h" @@ -1149,7 +1150,11 @@ addMissingWasmCodeSymbols(const WasmObjectFile &Obj, SymbolAddresses.insert(Sym.Addr); for (const wasm::WasmFunction &Function : Obj.functions()) { - uint64_t Address = Function.CodeSectionOffset; + // This adjustment mirrors the one in WasmObjectFile::getSymbolAddress. + uint32_t Adjustment = Obj.isRelocatableObject() || Obj.isSharedObject() + ? 0 + : Section->getAddress(); + uint64_t Address = Function.CodeSectionOffset + Adjustment; // Only add fallback symbols for functions not already present in the symbol // table. if (SymbolAddresses.count(Address)) @@ -1354,6 +1359,10 @@ SymbolInfoTy objdump::createSymbolInfo(const ObjectFile &Obj, const SymbolRef::Type SymType = unwrapOrError(Symbol.getType(), FileName); return SymbolInfoTy(Addr, Name, SymType, /*IsMappingSymbol=*/false, /*IsXCOFF=*/true); + } else if (Obj.isWasm()) { + uint8_t SymType = + cast<WasmObjectFile>(&Obj)->getWasmSymbol(Symbol).Info.Kind; + return SymbolInfoTy(Addr, Name, SymType, false); } else { uint8_t Type = Obj.isELF() ? getElfSymbolType(Obj, Symbol) : (uint8_t)ELF::STT_NOTYPE; @@ -1366,8 +1375,9 @@ static SymbolInfoTy createDummySymbolInfo(const ObjectFile &Obj, uint8_t Type) { if (Obj.isXCOFF() && (SymbolDescription || TracebackTable)) return SymbolInfoTy(std::nullopt, Addr, Name, std::nullopt, false); - else - return SymbolInfoTy(Addr, Name, Type); + if (Obj.isWasm()) + return SymbolInfoTy(Addr, Name, wasm::WASM_SYMBOL_TYPE_SECTION); + return SymbolInfoTy(Addr, Name, Type); } static void collectBBAddrMapLabels( |