Index: test/tools/llvm-objdump/all-headers.test =================================================================== --- test/tools/llvm-objdump/all-headers.test +++ test/tools/llvm-objdump/all-headers.test @@ -1,8 +1,8 @@ # RUN: yaml2obj %s > %t # RUN: llvm-objdump --all-headers %t | FileCheck %s -## Check we print file format, architecture and start address before -## anything else when using --all-headers. +## Check we print file format, architecture and start address followed by the +## other data when using --all-headers. # CHECK: file format ELF64-x86-64 # CHECK-EMPTY: @@ -10,6 +10,9 @@ # CHECK-NEXT: start address: 0x0000000000000000 # CHECK-EMPTY: # CHECK-NEXT: Sections: +# CHECK: SYMBOL TABLE: +# CHECK: Program Header: +# CHECK: Dynamic Section: ## Check how we dump the archives. ## Check we dump the appropriate headers for each file in the archive. Index: test/tools/llvm-objdump/full-contents.test =================================================================== --- test/tools/llvm-objdump/full-contents.test +++ test/tools/llvm-objdump/full-contents.test @@ -2,16 +2,19 @@ # RUN: llvm-objdump --full-contents %t > %t.out1 # RUN: llvm-objdump -s %t > %t.out2 # RUN: cmp %t.out1 %t.out2 -# RUN: FileCheck %s --input-file=%t.out1 +# RUN: FileCheck %s --input-file=%t.out1 --implicit-check-not=.empty-progbits \ +# RUN: --implicit-check-not=.empty-nobits # CHECK: .bss -# CHECK-NEXT: +# CHECK-NEXT: # CHECK: .text -# CHECK-NEXT: 0000 01234567 .#Eg +# CHECK-NEXT: 1010 01234567 .#Eg # CHECK: .user-defined -# CHECK-NEXT: 0000 76543210 vT2. -# CHECK: .empty-section -# CHECK-NEXT: +# CHECK-NEXT: 1020 76543210 vT2. +# CHECK: .nobits-section +# CHECK-NEXT: +# CHECK: .non-alloc +# CHECK: 0000 11112222 .."" # CHECK: .symtab # CHECK: .strtab # CHECK: .shstrtab @@ -26,23 +29,38 @@ - Name: .bss Type: SHT_NOBITS Flags: [ SHF_ALLOC ] + Address: 0x1000 AddressAlign: 0x0000000000000010 Size: 64 - Name: .text Type: SHT_PROGBITS Flags: [ SHF_ALLOC, SHF_EXECINSTR ] + Address: 0x1010 AddressAlign: 0x0000000000000010 Content: "01234567" Size: 4 - Name: .user-defined Type: SHT_PROGBITS Flags: [ SHF_ALLOC ] + Address: 0x1020 AddressAlign: 0x0000000000000010 Content: "76543210" Size: 4 - - Name: .empty-section + - Name: .nobits-section Type: SHT_NOBITS Flags: [ SHF_ALLOC ] + Address: 0x1030 AddressAlign: 0x0000000000000010 Size: 32 - + - Name: .empty-progbits + Type: SHT_PROGBITS + Address: 0x1040 + Flags: [ SHF_ALLOC ] + - Name: .empty-nobits + Type: SHT_NOBITS + Address: 0x1050 + Flags: [ SHF_ALLOC ] + - Name: .non-alloc + Type: SHT_PROGBITS + Flags: [ ] + Content: '11112222' Index: test/tools/llvm-objdump/section-filter.test =================================================================== --- test/tools/llvm-objdump/section-filter.test +++ test/tools/llvm-objdump/section-filter.test @@ -1,24 +1,224 @@ -// This test checks that --section works correctly. -// RUN: llvm-objdump -h %p/Inputs/section-filter.obj -j=.text \ -// RUN: --section=.bss | FileCheck %s - -// CHECK: .text -// CHECK-NOT: .data -// CHECK: .bss - -// Test that the -j alias can be used flexibly. Create a baseline and ensure -// all other combinations are identical. -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s --section .symtab > %t.full -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j .symtab > %t.1 -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j=.symtab > %t.2 -// RUN: llvm-objdump %p/Inputs/section-filter.obj -h -s -j.symtab > %t.3 -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj .symtab > %t.4 -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj=.symtab > %t.5 -// RUN: llvm-objdump %p/Inputs/section-filter.obj -hsj.symtab > %t.6 - -// RUN: cmp %t.full %t.1 -// RUN: cmp %t.full %t.2 -// RUN: cmp %t.full %t.3 -// RUN: cmp %t.full %t.4 -// RUN: cmp %t.full %t.5 -// RUN: cmp %t.full %t.6 +## Test that --section works correctly for -h. +## We test the LMA here too, because the code at the time of writing uses the +## value of --section when looking up section LMAs. +# RUN: yaml2obj %s --docnum=1 -o %t.h.elf +# RUN: llvm-objdump -h %t.h.elf -j=.text --section=.bss \ +# RUN: | FileCheck %s --check-prefix=SHDRS --implicit-check-not=.data --implicit-check-not=.text2 + +# SHDRS: Name Size VMA LMA +# SHDRS: .text 00000001 0000000000000400 0000000000001000 +# SHDRS: .bss 00000001 0000000000000420 0000000000003000 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + Address: 0x400 + AddressAlign: 0x10 + Content: 'c3' + - Name: .text2 + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + Address: 0x401 + Content: '90' + - Name: .data + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_WRITE] + Address: 0x410 + AddressAlign: 0x10 + Content: '42' + - Name: .bss + Type: SHT_NOBITS + Flags: [SHF_ALLOC, SHF_WRITE] + Address: 0x420 + AddressAlign: 0x10 + Size: 1 +ProgramHeaders: + - Type: PT_LOAD + VAddr: 0x400 + PAddr: 0x1000 + Sections: + - Section: .text + - Section: .text2 + - Type: PT_LOAD + VAddr: 0x410 + PAddr: 0x2000 + Sections: + - Section: .data + - Type: PT_LOAD + VAddr: 0x420 + PAddr: 0x3000 + Sections: + - Section: .bss + +## Test that --section works correctly for -d with -r. +## FIXME: Inline relocations are only printed if the relocation section itself is +## specified with --section. This test just characterizes the existing behavior. +## See https://bugs.llvm.org/show_bug.cgi?id=41886 +# RUN: yaml2obj %s --docnum=2 -o %t.o + +## Show non-executable sections are not disassembled even if specified, +## and that only the specified executable sections are disassembled. +## Also show that no relocation sections are dumped because none are +## specified. +## FIXME: This is different behaviour to GNU objdump, which dumps the non- +## executable sections if requested explicitly. +## See https://bugs.llvm.org/show_bug.cgi?id=41897. +# RUN: llvm-objdump -d -r %t.o --section=.text --section=.rodata \ +# RUN: | FileCheck %s --check-prefix=DISASM --implicit-check-not=.text2 \ +# RUN: --implicit-check-not=.rodata --implicit-check-not=R_X86_64 + +## Show that only the specified relocation sections that patch the +## disassembled sections are dumped. +# RUN: llvm-objdump -d -r %t.o --section=.text \ +# RUN: --section=.rela.text --section=.rela.text2 \ +# RUN: | FileCheck %s --check-prefixes=DISASM,RELOC --implicit-check-not=.text2 \ +# RUN: --implicit-check-not=R_X86_64 + +# DISASM: Disassembly of section .text: +# DISASM-EMPTY: +# DISASM-NEXT: 0000000000000400 .text: +# DISASM-NEXT: 400: e8 00 00 00 00 callq 0 <.text+0x5> +# RELOC-NEXT: 00000401: R_X86_64_PC32 foo+1 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + Address: 0x400 + AddressAlign: 0x10 + Content: 'e800000000' + - Name: .text2 + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + Address: 0x401 + Content: '90e800000000' + - Name: .rela.text + Type: SHT_RELA + Info: .text + Relocations: + - Offset: 1 + Symbol: foo + Addend: 1 + Type: R_X86_64_PC32 + - Name: .another.rela.text + Type: SHT_RELA + Info: .text + Relocations: + - Offset: 1 + Symbol: foo + Type: R_X86_64_GOT32 + - Name: .rela.text2 + Type: SHT_RELA + Info: .text2 + Relocations: + - Offset: 1 + Symbol: foo + Addend: 2 + Type: R_X86_64_PLT32 + - Name: .rodata + Type: SHT_PROGBITS + Flags: [SHF_ALLOC] + Size: 4 + - Name: .rela.rodata + Type: SHT_RELA + Info: .rodata + Relocations: + - Offset: 0 + Symbol: foo + Type: R_X86_64_NONE +Symbols: + - Name: foo + +## Test that --section works when dumping relocation sections. +# RUN: llvm-objdump -r %t.o --section=.another.rela.text --section=.rela.rodata \ +# RUN: | FileCheck %s --check-prefix=DUMP-RELOCS --implicit-check-not=R_X86_64 \ +# RUN: --implicit-check-not="RELOCATION RECORDS" + +# DUMP-RELOCS: RELOCATION RECORDS FOR [.text]: +# DUMP-RELOCS: 00000001 R_X86_64_GOT32 foo +# DUMP-RELOCS: RELOCATION RECORDS FOR [.rodata]: +# DUMP-RELOCS: 00000000 R_X86_64_NONE foo + +## Test that --section works with --full-contents. +# RUN: llvm-objdump -s %t.o --section=.text --section=.rela.text2 \ +# RUN: | FileCheck %s --check-prefix=CONTENTS \ +# RUN: --implicit-check-not=.text \ +# RUN: --implicit-check-not=.rodata + +# CONTENTS: Contents of section .text: +# CONTENTS: Contents of section .rela.text2: + +## Test that --section works with --fault-map-section. +# RUN: yaml2obj %s --docnum=3 -o %t2.o +# RUN: llvm-objdump %t2.o --fault-map-section -j __clangast \ +# RUN: | FileCheck %s --check-prefixes=FAULTMAP,NO-FAULTMAP +# RUN: llvm-objdump %t2.o --fault-map-section -j .llvm_faultmaps \ +# RUN: | FileCheck %s --check-prefixes=FAULTMAP,WITH-FAULTMAP + +# FAULTMAP: FaultMap table: +# NO-FAULTMAP-NEXT: +# WITH-FAULTMAP-NEXT: Version: 0x1 +# WITH-FAULTMAP-NEXT: NumFunctions: 0 + +## Test that --section works with --raw-clang-ast. +# RUN: llvm-objdump %t2.o --raw-clang-ast -j .llvm_faultmaps \ +# RUN: | FileCheck %s --check-prefix=NO-AST --allow-empty +# RUN: llvm-objdump %t2.o --raw-clang-ast -j __clangast \ +# RUN: | FileCheck %s --check-prefix=CLANG-AST + +# NO-AST-NOT: {{.}} +# CLANG-AST: foobar + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 +Sections: + - Name: .llvm_faultmaps + Type: SHT_PROGBITS + Content: '0100000000000000' + - Name: __clangast + Type: SHT_PROGBITS + Content: '666f6f626172' # "foobar" + +## Test that the -j alias can be used flexibly. Create a baseline and ensure +## all other combinations are identical. +# RUN: llvm-objdump %t.h.elf -h -s --section .symtab > %t.full +# RUN: llvm-objdump %t.h.elf -h -s -j .symtab > %t.1 +# RUN: llvm-objdump %t.h.elf -h -s -j=.symtab > %t.2 +# RUN: llvm-objdump %t.h.elf -h -s -j.symtab > %t.3 +# RUN: llvm-objdump %t.h.elf -hsj .symtab > %t.4 +# RUN: llvm-objdump %t.h.elf -hsj=.symtab > %t.5 +# RUN: llvm-objdump %t.h.elf -hsj.symtab > %t.6 + +# RUN: cmp %t.full %t.1 +# RUN: cmp %t.full %t.2 +# RUN: cmp %t.full %t.3 +# RUN: cmp %t.full %t.4 +# RUN: cmp %t.full %t.5 +# RUN: cmp %t.full %t.6 + +## Test that an unknown section name causes all section output to be suppressed. +## TODO: Add a warning for this case. +## See https://bugs.llvm.org/show_bug.cgi?id=41898. +# RUN: llvm-objdump %t.h.elf -h --section foobar \ +# RUN: | FileCheck %s --check-prefix=NO-SECTION + +# NO-SECTION: Sections: +# NO-SECTION-NEXT: Idx Name Size VMA Type +# NO-SECTION-NOT: {{.}}