diff options
author | Maksim Panchenko <maks@fb.com> | 2021-08-31 11:53:54 -0700 |
---|---|---|
committer | Maksim Panchenko <maks@fb.com> | 2021-09-07 11:24:24 -0700 |
commit | 6300e4ac5806c9255c68c6fada37b2ce70efc524 (patch) | |
tree | 285719ed7c2197e6c2222355329cd14c7643495c /llvm/tools/llvm-objdump/llvm-objdump.cpp | |
parent | b81fc14f2da1800432e864c27abb01c1a219a97e (diff) | |
download | llvm-6300e4ac5806c9255c68c6fada37b2ce70efc524.zip llvm-6300e4ac5806c9255c68c6fada37b2ce70efc524.tar.gz llvm-6300e4ac5806c9255c68c6fada37b2ce70efc524.tar.bz2 |
[llvm-objdump] Fix 'llvm-objdump -dr' for executables with relocations
Print relocations interleaved with disassembled instructions for
executables with relocatable sections, e.g. those built with "-Wl,-q".
Differential Revision: https://reviews.llvm.org/D109016
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 330597d..6a9980b 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -1285,6 +1285,10 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, if (shouldAdjustVA(Section)) VMAAdjustment = AdjustVMA; + // In executable and shared objects, r_offset holds a virtual address. + // Subtract SectionAddr from the r_offset field of a relocation to get + // the section offset. + uint64_t RelAdjustment = Obj->isRelocatableObject() ? 0 : SectionAddr; uint64_t Size; uint64_t Index; bool PrintedSection = false; @@ -1431,7 +1435,8 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, // For --reloc: print zero blocks patched by relocations, so that // relocations can be shown in the dump. if (RelCur != RelEnd) - MaxOffset = RelCur->getOffset() - Index; + MaxOffset = std::min(RelCur->getOffset() - RelAdjustment - Index, + MaxOffset); if (size_t N = countSkippableZeroBytes(Bytes.slice(Index, MaxOffset))) { @@ -1580,7 +1585,7 @@ static void disassembleObject(const Target *TheTarget, const ObjectFile *Obj, if (Obj->getArch() != Triple::hexagon) { // Print relocation for instruction and data. while (RelCur != RelEnd) { - uint64_t Offset = RelCur->getOffset(); + uint64_t Offset = RelCur->getOffset() - RelAdjustment; // If this relocation is hidden, skip it. if (getHidden(*RelCur) || SectionAddr + Offset < StartAddress) { ++RelCur; |