aboutsummaryrefslogtreecommitdiff
path: root/llvm/tools/llvm-objdump/llvm-objdump.cpp
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2020-03-22 15:03:10 -0700
committerFangrui Song <maskray@google.com>2020-03-26 08:28:59 -0700
commit87de9a0786d922a1b52db6cd8b12f642d1d00d85 (patch)
treef1a319b5cd9f43ae755a02c87c04d9686423715b /llvm/tools/llvm-objdump/llvm-objdump.cpp
parent62dea6e9be31b100962f9ad41c1b79467a53f6cd (diff)
downloadllvm-87de9a0786d922a1b52db6cd8b12f642d1d00d85.zip
llvm-87de9a0786d922a1b52db6cd8b12f642d1d00d85.tar.gz
llvm-87de9a0786d922a1b52db6cd8b12f642d1d00d85.tar.bz2
[X86InstPrinter] Change printPCRelImm to print the target address in hexadecimal form
``` // llvm-objdump -d output (before) 400000: e8 0b 00 00 00 callq 11 400005: e8 0b 00 00 00 callq 11 // llvm-objdump -d output (after) 400000: e8 0b 00 00 00 callq 0x400010 400005: e8 0b 00 00 00 callq 0x400015 // GNU objdump -d. The lack of 0x is not ideal because the result cannot be re-assembled 400000: e8 0b 00 00 00 callq 400010 400005: e8 0b 00 00 00 callq 400015 ``` In llvm-objdump, we pass the address of the next MCInst. Ideally we should just thread the address of the current address, unfortunately we cannot call X86MCCodeEmitter::encodeInstruction (X86MCCodeEmitter requires MCInstrInfo and MCContext) to get the length of the MCInst. MCInstPrinter::printInst has other callers (e.g llvm-mc -filetype=asm, llvm-mca) which set Address to 0. They leave MCInstPrinter::PrintBranchImmAsAddress as false and this change is a no-op for them. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D76580
Diffstat (limited to 'llvm/tools/llvm-objdump/llvm-objdump.cpp')
-rw-r--r--llvm/tools/llvm-objdump/llvm-objdump.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index e9cd34e..4514f3c 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -735,9 +735,15 @@ public:
unsigned Column = OS.tell() - Start;
OS.indent(Column < TabStop - 1 ? TabStop - 1 - Column : 7 - Column % 8);
- if (MI)
- IP.printInst(MI, Address.Address, "", STI, OS);
- else
+ if (MI) {
+ // See MCInstPrinter::printInst. On targets where a PC relative immediate
+ // is relative to the next instruction and the length of a MCInst is
+ // difficult to measure (x86), this is the address of the next
+ // instruction.
+ uint64_t Addr =
+ Address.Address + (STI.getTargetTriple().isX86() ? Bytes.size() : 0);
+ IP.printInst(MI, Addr, "", STI, OS);
+ } else
OS << "\t<unknown>";
}
};