diff --git a/llvm/docs/CommandGuide/llvm-objdump.rst b/llvm/docs/CommandGuide/llvm-objdump.rst --- a/llvm/docs/CommandGuide/llvm-objdump.rst +++ b/llvm/docs/CommandGuide/llvm-objdump.rst @@ -173,7 +173,8 @@ .. option:: --no-leading-addr - When disassembling, do not print leading addresses. + When disassembling, do not print leading addresses for instructions and 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 --- 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 | 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 +# 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 +# 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 --- a/llvm/tools/llvm-objdump/ObjdumpOpts.td +++ b/llvm/tools/llvm-objdump/ObjdumpOpts.td @@ -118,7 +118,7 @@ "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 and 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 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -458,13 +458,16 @@ 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,