From: Jordan Rupprecht Date: Thu, 3 Oct 2019 22:01:08 +0000 (+0000) Subject: [llvm-objdump] Further rearrange llvm-objdump sections for compatability X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f21fbaa98eb98701922de967c5afedcb1fe07cd7;p=llvm [llvm-objdump] Further rearrange llvm-objdump sections for compatability Summary: rL371826 rearranged some output from llvm-objdump for GNU objdump compatability, but there still seem to be some more. I think this rearrangement is a little closer. Overview of the ordering which matches GNU objdump: * Archive headers * File headers * Section headers * Symbol table * Dwarf debugging * Relocations (if `--disassemble` is not used) * Section contents * Disassembly Reviewers: jhenderson, justice_adams, grimar, ychen, espindola Reviewed By: jhenderson Subscribers: aprantl, emaste, arichardson, jrtc27, atanasyan, seiya, llvm-commits, MaskRay Tags: #llvm Differential Revision: https://reviews.llvm.org/D68066 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@373671 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/MC/COFF/symidx.s b/test/MC/COFF/symidx.s index 46c00334764..5c1e740283c 100644 --- a/test/MC/COFF/symidx.s +++ b/test/MC/COFF/symidx.s @@ -8,8 +8,8 @@ bar: .symidx bar .symidx foo -// CHECK: Contents of section .data: -// CHECK-NEXT: 0000 0[[BAR:[1-9]]]000000 0[[FOO:[1-9]]]000000 // CHECK: SYMBOL TABLE: -// CHECK: [ [[FOO]]](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 foo -// CHECK-NEXT: [ [[BAR]]](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000001 bar +// CHECK: [ [[FOO:[1-9]]]](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000000 foo +// CHECK-NEXT: [ [[BAR:[1-9]]]](sec 1)(fl 0x00)(ty 0)(scl 3) (nx 0) 0x00000001 bar +// CHECK: Contents of section .data: +// CHECK-NEXT: 0000 0[[BAR]]000000 0[[FOO]]000000 diff --git a/test/tools/llvm-objdump/X86/adjust-vma.test b/test/tools/llvm-objdump/X86/adjust-vma.test index f28ff36a190..61eadaffa7e 100644 --- a/test/tools/llvm-objdump/X86/adjust-vma.test +++ b/test/tools/llvm-objdump/X86/adjust-vma.test @@ -3,6 +3,35 @@ # RUN: llvm-objdump --all-headers -D -z --adjust-vma=0x0 %t | FileCheck %s --check-prefixes=COMMON,NOADJUST # RUN: llvm-objdump --all-headers -D -z --adjust-vma=0x123000 %t | FileCheck %s --check-prefixes=COMMON,ADJUST +# NOADJUST: Sections: +# NOADJUST-NEXT: Idx Name Size VMA Type +# NOADJUST-NEXT: 0 00000000 0000000000000000 +# NOADJUST-NEXT: 1 .text 00000002 0000000000000000 TEXT +# NOADJUST-NEXT: 2 .debug_str 00000004 0000000000000000 +# NOADJUST-NEXT: 3 .rela.debug_str 00000018 0000000000000000 +# NOADJUST-NEXT: 4 .data 00000004 0000000000000000 DATA +# NOADJUST-NEXT: 5 .rela.data 00000018 0000000000000000 +# NOADJUST-NEXT: 6 .symtab 00000060 0000000000000000 +# NOADJUST-NEXT: 7 .strtab 00000010 0000000000000000 +# NOADJUST-NEXT: 8 .shstrtab 0000003c 0000000000000000 + +# ADJUST: Sections: +# ADJUST-NEXT: Idx Name Size VMA Type +# ADJUST-NEXT: 0 00000000 0000000000000000 +# ADJUST-NEXT: 1 .text 00000002 0000000000123000 TEXT +# ADJUST-NEXT: 2 .debug_str 00000004 0000000000000000 +# ADJUST-NEXT: 3 .rela.debug_str 00000018 0000000000000000 +# ADJUST-NEXT: 4 .data 00000004 0000000000123000 DATA +# ADJUST-NEXT: 5 .rela.data 00000018 0000000000000000 +# ADJUST-NEXT: 6 .symtab 00000060 0000000000000000 +# ADJUST-NEXT: 7 .strtab 00000010 0000000000000000 +# ADJUST-NEXT: 8 .shstrtab 0000003c 0000000000000000 + +# COMMON: SYMBOL TABLE: +# COMMON-NEXT: 0000000000000001 l F .text 00000000 func +# COMMON-NEXT: 0000000000000000 .text 00000000 sym +# COMMON-NEXT: 0000000000000000 l d .text 00000000 .text + # NOADJUST: 0000000000000000 sym: # NOADJUST-NEXT: 0: {{.*}} nop # NOADJUST: 0000000000000001 func: @@ -41,35 +70,6 @@ # COMMON-NEXT: 0: {{.*}} addb %al, (%rax) ## ... There are more lines here. We do not care. -# NOADJUST: Sections: -# NOADJUST-NEXT: Idx Name Size VMA Type -# NOADJUST-NEXT: 0 00000000 0000000000000000 -# NOADJUST-NEXT: 1 .text 00000002 0000000000000000 TEXT -# NOADJUST-NEXT: 2 .debug_str 00000004 0000000000000000 -# NOADJUST-NEXT: 3 .rela.debug_str 00000018 0000000000000000 -# NOADJUST-NEXT: 4 .data 00000004 0000000000000000 DATA -# NOADJUST-NEXT: 5 .rela.data 00000018 0000000000000000 -# NOADJUST-NEXT: 6 .symtab 00000060 0000000000000000 -# NOADJUST-NEXT: 7 .strtab 00000010 0000000000000000 -# NOADJUST-NEXT: 8 .shstrtab 0000003c 0000000000000000 - -# ADJUST: Sections: -# ADJUST-NEXT: Idx Name Size VMA Type -# ADJUST-NEXT: 0 00000000 0000000000000000 -# ADJUST-NEXT: 1 .text 00000002 0000000000123000 TEXT -# ADJUST-NEXT: 2 .debug_str 00000004 0000000000000000 -# ADJUST-NEXT: 3 .rela.debug_str 00000018 0000000000000000 -# ADJUST-NEXT: 4 .data 00000004 0000000000123000 DATA -# ADJUST-NEXT: 5 .rela.data 00000018 0000000000000000 -# ADJUST-NEXT: 6 .symtab 00000060 0000000000000000 -# ADJUST-NEXT: 7 .strtab 00000010 0000000000000000 -# ADJUST-NEXT: 8 .shstrtab 0000003c 0000000000000000 - -# COMMON: SYMBOL TABLE: -# COMMON-NEXT: 0000000000000001 l F .text 00000000 func -# COMMON-NEXT: 0000000000000000 .text 00000000 sym -# COMMON-NEXT: 0000000000000000 l d .text 00000000 .text - --- !ELF FileHeader: Class: ELFCLASS64 diff --git a/test/tools/llvm-objdump/X86/demangle.s b/test/tools/llvm-objdump/X86/demangle.s index 76aacb68995..5bfdbf73e92 100644 --- a/test/tools/llvm-objdump/X86/demangle.s +++ b/test/tools/llvm-objdump/X86/demangle.s @@ -1,13 +1,13 @@ # RUN: llvm-mc %s -filetype=obj -triple=x86_64-pc-linux -o %t # RUN: llvm-objdump -t -r --demangle %t | FileCheck %s -## Check we demangle symbols when printing relocations. -# CHECK: 000000000000001 R_X86_64_PLT32 foo()-4 - ## Check we demangle symbols when printing symbol table. # CHECK: SYMBOL TABLE: # CHECK-NEXT: 0000000000000000 g F .text 00000000 foo() +## Check we demangle symbols when printing relocations. +# CHECK: 000000000000001 R_X86_64_PLT32 foo()-4 + ## Check the case when relocations are inlined into disassembly. # RUN: llvm-objdump -d -r --demangle %t | FileCheck %s --check-prefix=INLINE # INLINE: foo(): diff --git a/test/tools/llvm-objdump/X86/out-of-section-sym.test b/test/tools/llvm-objdump/X86/out-of-section-sym.test index 4da81c63ca3..d79a05550f0 100644 --- a/test/tools/llvm-objdump/X86/out-of-section-sym.test +++ b/test/tools/llvm-objdump/X86/out-of-section-sym.test @@ -5,12 +5,13 @@ // RUN: cmp %t0 %t1 // RUN: FileCheck --input-file %t0 %s -CHECK: Disassembly of section .text: -CHECK-EMPTY: -CHECK-NEXT: _start: -CHECK-NEXT: 10: c3 retl -CHECK-NEXT: SYMBOL TABLE: +CHECK: SYMBOL TABLE: CHECK-NEXT: 00000010 l d .text 00000000 .text CHECK-NEXT: 00000010 .text 00000000 _start CHECK-NEXT: 00000020 .text 00000000 _fdata CHECK-NEXT: 00000010 .text 00000000 _ftext +CHECK-EMPTY: +CHECK-NEXT: Disassembly of section .text: +CHECK-EMPTY: +CHECK-NEXT: _start: +CHECK-NEXT: 10: c3 retl diff --git a/test/tools/llvm-objdump/all-headers.test b/test/tools/llvm-objdump/all-headers.test index ea45eccee35..7e57eba3b01 100644 --- a/test/tools/llvm-objdump/all-headers.test +++ b/test/tools/llvm-objdump/all-headers.test @@ -1,8 +1,9 @@ # RUN: yaml2obj %s > %t # RUN: llvm-objdump --all-headers %t | FileCheck %s -## Check we print file format, architecture and start address followed by the -## other data when using --all-headers. +## Note: --all-headers (-x) is an alias for --archive-headers --file-headers +## --section-headers --private-headers --reloc --syms (-afhprt). Test for them +## in the following order which provides GNU objdump compatability. # CHECK: file format ELF64-x86-64 # CHECK-EMPTY: @@ -13,6 +14,7 @@ # CHECK: Dynamic Section: # CHECK: Sections: # CHECK: SYMBOL TABLE: +# CHECK: RELOCATION RECORDS FOR [.text]: ## Check how we dump the archives. ## Check we dump the appropriate headers for each file in the archive. @@ -23,26 +25,49 @@ # RUN: llvm-objdump --all-headers %t.a | FileCheck %s --check-prefix=ARCHIVE # ARCHIVE: {{.*}}.a({{.*}}): file format ELF64-x86-64 +# ARCHIVE: rw-r--r-- # ARCHIVE: architecture: x86_64 # ARCHIVE: start address: 0x0000000000000000 -# ARCHIVE: rw-r--r-- # ARCHIVE: Program Header: # ARCHIVE: Dynamic Section: # ARCHIVE: Sections: # ARCHIVE: SYMBOL TABLE: +# ARCHIVE: RELOCATION RECORDS FOR [.text]: # ARCHIVE: {{.*}}.a({{.*}}2): file format ELF64-x86-64 +# ARCHIVE: rw-r--r-- # ARCHIVE: architecture: x86_64 # ARCHIVE: start address: 0x0000000000000000 -# ARCHIVE: rw-r--r-- # ARCHIVE: Program Header: # ARCHIVE: Dynamic Section: # ARCHIVE: Sections: # ARCHIVE: SYMBOL TABLE: +# ARCHIVE: RELOCATION RECORDS FOR [.text]: !ELF FileHeader: Class: ELFCLASS64 Data: ELFDATA2LSB - Type: ET_EXEC + Type: ET_REL Machine: EM_X86_64 Sections: + - Name: .text + Type: SHT_PROGBITS + - Name: .rel.text + Type: SHT_REL + Info: .text + Relocations: + - Offset: 0x1 + Symbol: foo + Type: R_X86_64_32 + - Name: .dynamic + Type: SHT_DYNAMIC + Flags: [ SHF_WRITE, SHF_ALLOC ] + EntSize: 0x0000000000000010 + Entries: + - Tag: DT_INIT + Value: 0x00000000000006A0 + - Tag: DT_NULL + Value: 0x0000000000000000 +Symbols: + - Name: foo + Section: .text diff --git a/test/tools/llvm-objdump/output-ordering.test b/test/tools/llvm-objdump/output-ordering.test new file mode 100644 index 00000000000..0d629af91e0 --- /dev/null +++ b/test/tools/llvm-objdump/output-ordering.test @@ -0,0 +1,70 @@ +# RUN: yaml2obj %s > %t.o +# RUN: llvm-objdump --file-headers --private-headers --section-headers --syms \ +# RUN: --full-contents --dwarf=frames \ +# RUN: --reloc %t.o | FileCheck %s --check-prefixes=CHECK,RELOC +# RUN: llvm-objdump --file-headers --private-headers --section-headers --syms \ +# RUN: --full-contents --dwarf=frames \ +# RUN: --disassemble %t.o | FileCheck %s --check-prefixes=CHECK,DISASM + +## Test the ordering of most of the output. Note that --disassemble suppresses +## --reloc, so we test them independently. + +## File headers (-f) +# CHECK: file format ELF64-x86-64 +# CHECK: architecture: x86_64 +# CHECK: start address: 0x0000000000000000 +## Private headers (-p) +# CHECK: Program Header: +# CHECK: Dynamic Section: +## Section headers (-h) +# CHECK: Sections: +## Symbol table (-t) +# CHECK: SYMBOL TABLE: +## DWARF contents: +# CHECK: .eh_frame contents: +## Relocations (-r) +# RELOC: RELOCATION RECORDS FOR [.text]: +## Section contents (-s) +# CHECK: Contents of section .rel.text: +# CHECK: Contents of section .dynamic: +# CHECK: Contents of section .symtab: +# CHECK: Contents of section .strtab: +# CHECK: Contents of section .shstrtab: +## Disassembly (-d) +# DISASM: Disassembly of section .text: + +!ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Content: e800000000e800000000 + - Name: .rel.text + Type: SHT_REL + Info: .text + Relocations: + - Offset: 0x1 + Symbol: foo + Type: R_X86_64_32 + - Name: .dynamic + Type: SHT_DYNAMIC + Flags: [ SHF_WRITE, SHF_ALLOC ] + EntSize: 0x0000000000000010 + Entries: + - Tag: DT_INIT + Value: 0x00000000000006A0 + - Tag: DT_NULL + Value: 0x0000000000000000 + - Name: .eh_frame + Type: SHT_X86_64_UNWIND + Flags: [ SHF_ALLOC ] + AddressAlign: 0x0000000000000001 + Content: 00000000 +Symbols: + - Name: foo + Section: .text diff --git a/tools/llvm-objdump/llvm-objdump.cpp b/tools/llvm-objdump/llvm-objdump.cpp index f50d3448df3..8b0a04c6104 100644 --- a/tools/llvm-objdump/llvm-objdump.cpp +++ b/tools/llvm-objdump/llvm-objdump.cpp @@ -2076,27 +2076,37 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr, if (StartAddress.getNumOccurrences() || StopAddress.getNumOccurrences()) checkForInvalidStartStopAddress(O, StartAddress, StopAddress); + // Note: the order here matches GNU objdump for compatability. StringRef ArchiveName = A ? A->getFileName() : ""; - if (FileHeaders) - printFileHeaders(O); if (ArchiveHeaders && !MachOOpt && C) printArchiveChild(ArchiveName, *C); - if (Disassemble) - disassembleObject(O, Relocations); - if (Relocations && !Disassemble) - printRelocations(O); - if (DynamicRelocations) - printDynamicRelocations(O); + if (FileHeaders) + printFileHeaders(O); if (PrivateHeaders || FirstPrivateHeader) printPrivateFileHeaders(O, FirstPrivateHeader); if (SectionHeaders) printSectionHeaders(O); - if (SectionContents) - printSectionContents(O); if (SymbolTable) printSymbolTable(O, ArchiveName); + if (DwarfDumpType != DIDT_Null) { + std::unique_ptr DICtx = DWARFContext::create(*O); + // Dump the complete DWARF structure. + DIDumpOptions DumpOpts; + DumpOpts.DumpType = DwarfDumpType; + DICtx->dump(outs(), DumpOpts); + } + if (Relocations && !Disassemble) + printRelocations(O); + if (DynamicRelocations) + printDynamicRelocations(O); + if (SectionContents) + printSectionContents(O); + if (Disassemble) + disassembleObject(O, Relocations); if (UnwindInfo) printUnwindInfo(O); + + // Mach-O specific options: if (ExportsTrie) printExportsTrie(O); if (Rebase) @@ -2107,17 +2117,12 @@ static void dumpObject(ObjectFile *O, const Archive *A = nullptr, printLazyBindTable(O); if (WeakBind) printWeakBindTable(O); + + // Other special sections: if (RawClangAST) printRawClangAST(O); if (FaultMapSection) printFaultMaps(O); - if (DwarfDumpType != DIDT_Null) { - std::unique_ptr DICtx = DWARFContext::create(*O); - // Dump the complete DWARF structure. - DIDumpOptions DumpOpts; - DumpOpts.DumpType = DwarfDumpType; - DICtx->dump(outs(), DumpOpts); - } } static void dumpObject(const COFFImportFile *I, const Archive *A,