diff options
author | Rahman Lavaee <rahmanl@google.com> | 2022-07-16 00:48:50 -0700 |
---|---|---|
committer | Rahman Lavaee <rahmanl@google.com> | 2022-07-18 16:51:22 -0700 |
commit | ed93d157dec8133be1fc4be6e995e3d11da8d5b2 (patch) | |
tree | 860ccbc71ce8f4aad5e03f05ab76d44e2a1f4840 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | 555ae5b8f5aa93ab090af853a8b7a83f815b3f20 (diff) | |
download | llvm-ed93d157dec8133be1fc4be6e995e3d11da8d5b2.zip llvm-ed93d157dec8133be1fc4be6e995e3d11da8d5b2.tar.gz llvm-ed93d157dec8133be1fc4be6e995e3d11da8d5b2.tar.bz2 |
[llvm-objdump] Support --symbolize-operands when there is a single SHT_LLVM_BB_ADDR_MAP section for all text sections
When linking, using `-Wl,-z,keep-text-section-prefix` results in multiple text sections while all `SHT_LLVM_BB_ADDR_MAP` sections are linked into a single one.
In such case, we should not read the corresponding section for each text section, and instead read all `SHT_LLVM_BB_ADDR_MAP` sections before disassembly.
Reviewed By: jhenderson, MaskRay
Differential Revision: https://reviews.llvm.org/D129924
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 3996224..9e4fa7c 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1278,6 +1278,25 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj, LLVM_DEBUG(LVP.dump()); + std::unordered_map<uint64_t, BBAddrMap> AddrToBBAddrMap; + auto ReadBBAddrMap = [&](Optional<unsigned> SectionIndex = None) { + AddrToBBAddrMap.clear(); + if (const auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) { + auto BBAddrMapsOrErr = Elf->readBBAddrMap(SectionIndex); + if (!BBAddrMapsOrErr) + reportWarning(toString(BBAddrMapsOrErr.takeError()), + Obj.getFileName()); + for (auto &FunctionBBAddrMap : *BBAddrMapsOrErr) + AddrToBBAddrMap.emplace(FunctionBBAddrMap.Addr, + std::move(FunctionBBAddrMap)); + } + }; + + // For non-relocatable objects, Read all LLVM_BB_ADDR_MAP sections into a + // single mapping, since they don't have any conflicts. + if (SymbolizeOperands && !Obj.isRelocatableObject()) + ReadBBAddrMap(); + for (const SectionRef &Section : ToolSectionFilter(Obj)) { if (FilterSections.empty() && !DisassembleAll && (!Section.isText() || Section.isVirtual())) @@ -1288,19 +1307,10 @@ static void disassembleObject(const Target *TheTarget, ObjectFile &Obj, if (!SectSize) continue; - std::unordered_map<uint64_t, BBAddrMap> AddrToBBAddrMap; - if (SymbolizeOperands) { - if (auto *Elf = dyn_cast<ELFObjectFileBase>(&Obj)) { - // Read the BB-address-map corresponding to this section, if present. - auto SectionBBAddrMapsOrErr = Elf->readBBAddrMap(Section.getIndex()); - if (!SectionBBAddrMapsOrErr) - reportWarning(toString(SectionBBAddrMapsOrErr.takeError()), - Obj.getFileName()); - for (auto &FunctionBBAddrMap : *SectionBBAddrMapsOrErr) - AddrToBBAddrMap.emplace(FunctionBBAddrMap.Addr, - std::move(FunctionBBAddrMap)); - } - } + // For relocatable object files, read the LLVM_BB_ADDR_MAP section + // corresponding to this section, if present. + if (SymbolizeOperands && Obj.isRelocatableObject()) + ReadBBAddrMap(Section.getIndex()); // Get the list of all the symbols in this section. SectionSymbolsTy &Symbols = AllSymbols[Section]; |