diff options
author | Alexey Lapshin <a.v.lapshin@mail.ru> | 2019-02-27 13:17:36 +0000 |
---|---|---|
committer | Alexey Lapshin <a.v.lapshin@mail.ru> | 2019-02-27 13:17:36 +0000 |
commit | 77fc1f6049a7414ec193c9ff8226eeb5662a5878 (patch) | |
tree | b2bffed96e676b25942dbe39194e0f08a153f638 /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | ef920358277603c69f4f548d2e5c40842972dd71 (diff) | |
download | llvm-77fc1f6049a7414ec193c9ff8226eeb5662a5878.zip llvm-77fc1f6049a7414ec193c9ff8226eeb5662a5878.tar.gz llvm-77fc1f6049a7414ec193c9ff8226eeb5662a5878.tar.bz2 |
[DebugInfo] add SectionedAddress to DebugInfo interfaces.
That patch is the fix for https://bugs.llvm.org/show_bug.cgi?id=40703
"wrong line number info for obj file compiled with -ffunction-sections"
bug. The problem happened with only .o files. If object file contains
several .text sections then line number information showed incorrectly.
The reason for this is that DwarfLineTable could not detect section which
corresponds to specified address(because address is the local to the
section). And as the result it could not select proper sequence in the
line table. The fix is to pass SectionIndex with the address. So that it
would be possible to differentiate addresses from various sections. With
this fix llvm-objdump shows correct line numbers for disassembled code.
Differential review: https://reviews.llvm.org/D58194
llvm-svn: 354972
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 914789f..8ff1667 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -508,7 +508,8 @@ public: Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts)); } virtual ~SourcePrinter() = default; - virtual void printSourceLine(raw_ostream &OS, uint64_t Address, + virtual void printSourceLine(raw_ostream &OS, + object::SectionedAddress Address, StringRef Delimiter = "; "); }; @@ -538,7 +539,8 @@ bool SourcePrinter::cacheSource(const DILineInfo &LineInfo) { return true; } -void SourcePrinter::printSourceLine(raw_ostream &OS, uint64_t Address, +void SourcePrinter::printSourceLine(raw_ostream &OS, + object::SectionedAddress Address, StringRef Delimiter) { if (!Symbolizer) return; @@ -599,14 +601,15 @@ class PrettyPrinter { public: virtual ~PrettyPrinter() = default; virtual void printInst(MCInstPrinter &IP, const MCInst *MI, - ArrayRef<uint8_t> Bytes, uint64_t Address, - raw_ostream &OS, StringRef Annot, - MCSubtargetInfo const &STI, SourcePrinter *SP, + ArrayRef<uint8_t> Bytes, + object::SectionedAddress Address, raw_ostream &OS, + StringRef Annot, MCSubtargetInfo const &STI, + SourcePrinter *SP, std::vector<RelocationRef> *Rels = nullptr) { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address); if (!NoLeadingAddr) - OS << format("%8" PRIx64 ":", Address); + OS << format("%8" PRIx64 ":", Address.Address); if (!NoShowRawInsn) { OS << "\t"; dumpBytes(Bytes, OS); @@ -633,13 +636,13 @@ public: } } void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes, - uint64_t Address, raw_ostream &OS, StringRef Annot, - MCSubtargetInfo const &STI, SourcePrinter *SP, + object::SectionedAddress Address, raw_ostream &OS, + StringRef Annot, MCSubtargetInfo const &STI, SourcePrinter *SP, std::vector<RelocationRef> *Rels) override { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address, ""); if (!MI) { - printLead(Bytes, Address, OS); + printLead(Bytes, Address.Address, OS); OS << " <unknown>"; return; } @@ -661,9 +664,9 @@ public: std::vector<RelocationRef>::const_iterator RelCur = Rels->begin(); std::vector<RelocationRef>::const_iterator RelEnd = Rels->end(); auto PrintReloc = [&]() -> void { - while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address)) { - if (RelCur->getOffset() == Address) { - printRelocation(*RelCur, Address, 4); + while ((RelCur != RelEnd) && (RelCur->getOffset() <= Address.Address)) { + if (RelCur->getOffset() == Address.Address) { + printRelocation(*RelCur, Address.Address, 4); return; } ++RelCur; @@ -675,7 +678,7 @@ public: Separator = "\n"; if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address, ""); - printLead(Bytes, Address, OS); + printLead(Bytes, Address.Address, OS); OS << Preamble; Preamble = " "; StringRef Inst; @@ -693,7 +696,7 @@ public: OS << " } " << PacketBundle.second; PrintReloc(); Bytes = Bytes.slice(4); - Address += 4; + Address.Address += 4; } } }; @@ -702,8 +705,8 @@ HexagonPrettyPrinter HexagonPrettyPrinterInst; class AMDGCNPrettyPrinter : public PrettyPrinter { public: void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes, - uint64_t Address, raw_ostream &OS, StringRef Annot, - MCSubtargetInfo const &STI, SourcePrinter *SP, + object::SectionedAddress Address, raw_ostream &OS, + StringRef Annot, MCSubtargetInfo const &STI, SourcePrinter *SP, std::vector<RelocationRef> *Rels) override { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address); @@ -733,7 +736,7 @@ public: } } - OS << format("// %012" PRIX64 ": ", Address); + OS << format("// %012" PRIX64 ": ", Address.Address); if (Bytes.size() >=4) { for (auto D : makeArrayRef(reinterpret_cast<const U32*>(Bytes.data()), Bytes.size() / sizeof(U32))) @@ -754,13 +757,13 @@ AMDGCNPrettyPrinter AMDGCNPrettyPrinterInst; class BPFPrettyPrinter : public PrettyPrinter { public: void printInst(MCInstPrinter &IP, const MCInst *MI, ArrayRef<uint8_t> Bytes, - uint64_t Address, raw_ostream &OS, StringRef Annot, - MCSubtargetInfo const &STI, SourcePrinter *SP, + object::SectionedAddress Address, raw_ostream &OS, + StringRef Annot, MCSubtargetInfo const &STI, SourcePrinter *SP, std::vector<RelocationRef> *Rels) override { if (SP && (PrintSource || PrintLines)) SP->printSourceLine(OS, Address); if (!NoLeadingAddr) - OS << format("%8" PRId64 ":", Address / 8); + OS << format("%8" PRId64 ":", Address.Address / 8); if (!NoShowRawInsn) { OS << "\t"; dumpBytes(Bytes, OS); @@ -1323,9 +1326,10 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, if (Size == 0) Size = 1; - PIP.printInst( - *IP, Disassembled ? &Inst : nullptr, Bytes.slice(Index, Size), - SectionAddr + Index + VMAAdjustment, outs(), "", *STI, &SP, &Rels); + PIP.printInst(*IP, Disassembled ? &Inst : nullptr, + Bytes.slice(Index, Size), + {SectionAddr + Index + VMAAdjustment, Section.getIndex()}, + outs(), "", *STI, &SP, &Rels); outs() << CommentStream.str(); Comments.clear(); |