[PATCH] D48554: Handle absolute symbols as branch targets in disassembly.

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 25 22:22:57 PDT 2018


MaskRay added inline comments.


================
Comment at: test/tools/llvm-objdump/call-absolute-symbol-elf.test:3
+
+CHECK: 201000:	e8 fb f0 df ff 	callq	-2100997 <foo>
----------------
I find that on AArch64 PowerPC x86_64 ... all these call/branch instructions print the immediate value without taking account of PC (what they print are relative addresses, instead of absolute addresses as printed by `objdump`)

The PowerPC one at least appends `.+` before the immediate to tell you it is a relative address.

https://github.com/llvm-mirror/llvm/tree/master/lib/Target/PowerPC/InstPrinter/PPCInstPrinter.cpp#L386
void PPCInstPrinter::printBranchOperand(const MCInst *MI, unsigned OpNo,
                                        raw_ostream &O) {
  if (!MI->getOperand(OpNo).isImm())
    return printOperand(MI, OpNo, O);

  // Branches can take an immediate operand.  This is used by the branch
  // selection pass to print .+8, an eight byte displacement from the PC.
  O << ".+";
  printAbsBranchOperand(MI, OpNo, O);
}



================
Comment at: tools/llvm-objdump/llvm-objdump.cpp:1725
+                });
+            if (TargetSym == TargetSectionSymbols->begin()) {
+              TargetSectionSymbols = &AbsoluteSymbols;
----------------
Reasonable behavior. I have verified that `objdump` does something similar (`foo + 4`). It has one extra heuristic: if the target address is less than the absolute symbol of the smallest address, it can print something like `foo - 4`. But I think we don't need such heuristic.


Repository:
  rL LLVM

https://reviews.llvm.org/D48554





More information about the llvm-commits mailing list