[llvm] ad92a3d - [llvm-objdump] --no-leading-addr: hide inline relocation offsets
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 4 10:00:29 PDT 2022
Author: Fangrui Song
Date: 2022-10-04T10:00:21-07:00
New Revision: ad92a3db2e43f1fcac65a1a7949dd24c855d7002
URL: https://github.com/llvm/llvm-project/commit/ad92a3db2e43f1fcac65a1a7949dd24c855d7002
DIFF: https://github.com/llvm/llvm-project/commit/ad92a3db2e43f1fcac65a1a7949dd24c855d7002.diff
LOG: [llvm-objdump] --no-leading-addr: hide inline relocation offsets
It seems to make sense to omit offsets when --no-leading-addr is specified. The output is now closer
to objdump -dr --no-addresses (non-wide output).
Reviewed By: nickdesaulniers
Differential Revision: https://reviews.llvm.org/D135039
Added:
Modified:
llvm/docs/CommandGuide/llvm-objdump.rst
llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
llvm/tools/llvm-objdump/ObjdumpOpts.td
llvm/tools/llvm-objdump/llvm-objdump.cpp
Removed:
################################################################################
diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst
index 07aad86de4a2..d6d1d805e3cb 100644
--- a/llvm/docs/CommandGuide/llvm-objdump.rst
+++ b/llvm/docs/CommandGuide/llvm-objdump.rst
@@ -186,7 +186,8 @@ OPTIONS
.. option:: --no-leading-addr
- When disassembling, do not print leading addresses.
+ When disassembling, do not print leading addresses for instructions or inline
+ relocations.
.. option:: --no-print-imm-hex
diff --git a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
index 16216c68e1b2..5d78b7a372ce 100644
--- a/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
+++ b/llvm/test/tools/llvm-objdump/X86/elf-disassemble-relocs-exec.test
@@ -1,18 +1,31 @@
## Check that 'llvm-objdump -dr' correctly prints relocations in executables.
# RUN: yaml2obj --docnum=1 %s -o %t
-# RUN: llvm-objdump -dr %t | FileCheck %s
+# RUN: llvm-objdump -dr %t | FileCheck %s --match-full-lines --strict-whitespace
+# RUN: llvm-objdump -dr --no-leading-addr %t | FileCheck %s --check-prefix=NOADDR --match-full-lines --strict-whitespace
-# CHECK: 400000: 90 nop
-# CHECK-NEXT: 400001: bf 10 00 40 00 movl $4194320, %edi
-# CHECK-NEXT: 0000000000400002: R_X86_64_32 .rodata
-# CHECK-NEXT: 400006: e8 fc fe ff ff callq 0x3fff07
-# CHECK-NEXT: 0000000000400007: R_X86_64_PLT32 puts-0x4
-# CHECK-NEXT: 40000b: 90 nop
+# RUN: yaml2obj -DBITS=32 %s -o %t.32
+# RUN: llvm-objdump -dr --no-leading-addr %t.32 | FileCheck %s --check-prefix=NOADDR --match-full-lines --strict-whitespace
+
+# CHECK:0000000000400000 <.text>:
+# CHECK-NEXT: 400000: 90 nop
+# CHECK-NEXT: 400001: bf 10 00 40 00 movl $4194320, %edi # imm = 0x400010
+# CHECK-NEXT: 0000000000400002: R_X86_64_32 .rodata
+# CHECK-NEXT: 400006: e8 fc fe ff ff callq 0x3fff07 <puts+0x3fff07>
+# CHECK-NEXT: 0000000000400007: R_X86_64_PLT32 puts-0x4
+# CHECK-NEXT: 40000b: 90 nop
+
+# NOADDR:<.text>:
+# NOADDR-NEXT: 90 nop
+# NOADDR-NEXT: bf 10 00 40 00 movl $4194320, %edi # imm = 0x400010
+# NOADDR-NEXT: R_X86_64_32 .rodata
+# NOADDR-NEXT: e8 fc fe ff ff callq 0x3fff07 <puts+0x3fff07>
+# NOADDR-NEXT: R_X86_64_PLT32 puts-0x4
+# NOADDR-NEXT: 90 nop
--- !ELF
FileHeader:
- Class: ELFCLASS64
+ Class: ELFCLASS[[BITS=64]]
Data: ELFDATA2LSB
Type: ET_EXEC
Machine: EM_X86_64
diff --git a/llvm/tools/llvm-objdump/ObjdumpOpts.td b/llvm/tools/llvm-objdump/ObjdumpOpts.td
index 66c39c01f0c0..4537c34287ae 100644
--- a/llvm/tools/llvm-objdump/ObjdumpOpts.td
+++ b/llvm/tools/llvm-objdump/ObjdumpOpts.td
@@ -129,7 +129,7 @@ def no_show_raw_insn : Flag<["--"], "no-show-raw-insn">,
"do not print the instruction bytes.">;
def no_leading_addr : Flag<["--"], "no-leading-addr">,
- HelpText<"When disassembling, do not print leading addresses">;
+ HelpText<"When disassembling, do not print leading addresses for instructions or inline relocations">;
def raw_clang_ast : Flag<["--"], "raw-clang-ast">,
HelpText<"Dump the raw binary contents of the clang AST section">;
diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp
index 8daeb4e30fcc..a06e644dec3b 100644
--- a/llvm/tools/llvm-objdump/llvm-objdump.cpp
+++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp
@@ -465,13 +465,16 @@ static bool hasMappingSymbols(const ObjectFile &Obj) {
static void printRelocation(formatted_raw_ostream &OS, StringRef FileName,
const RelocationRef &Rel, uint64_t Address,
bool Is64Bits) {
- StringRef Fmt = Is64Bits ? "\t\t%016" PRIx64 ": " : "\t\t\t%08" PRIx64 ": ";
+ StringRef Fmt = Is64Bits ? "%016" PRIx64 ": " : "%08" PRIx64 ": ";
SmallString<16> Name;
SmallString<32> Val;
Rel.getTypeName(Name);
if (Error E = getRelocationValueString(Rel, Val))
reportError(std::move(E), FileName);
- OS << format(Fmt.data(), Address) << Name << "\t" << Val;
+ OS << (Is64Bits || !LeadingAddr ? "\t\t" : "\t\t\t");
+ if (LeadingAddr)
+ OS << format(Fmt.data(), Address);
+ OS << Name << "\t" << Val;
}
static void AlignToInstStartColumn(size_t Start, const MCSubtargetInfo &STI,
More information about the llvm-commits
mailing list