Index: llvm/test/tools/llvm-readobj/ELF/Inputs/trivial.ll =================================================================== --- llvm/test/tools/llvm-readobj/ELF/Inputs/trivial.ll +++ llvm/test/tools/llvm-readobj/ELF/Inputs/trivial.ll @@ -2,7 +2,6 @@ ; llc -mtriple=i386-pc-win32 trivial.ll -filetype=obj -o trivial.obj.coff-i386 ; llc -mtriple=x86_64-pc-win32 trivial.ll -filetype=obj -o trivial.obj.coff-x86-64 ; llc -mtriple=i386-linux-gnu trivial.ll -filetype=obj -o trivial.obj.elf-i386 -relocation-model=pic -; llc -mtriple=x86_64-linux-gnu trivial.ll -filetype=obj -o trivial.obj.elf-x86-64 -relocation-model=pic ; llc -mtriple=i386-apple-darwin10 trivial.ll -filetype=obj -o trivial.obj.macho-i386 -relocation-model=pic ; llc -mtriple=x86_64-apple-darwin10 trivial.ll -filetype=obj -o trivial.obj.macho-x86-64 -relocation-model=pic ; llc -mtriple=wasm32-unknown-unknown trivial.ll -filetype=obj -o trivial.obj.wasm Index: llvm/test/tools/llvm-readobj/ELF/gnu-file-headers.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/gnu-file-headers.test +++ llvm/test/tools/llvm-readobj/ELF/gnu-file-headers.test @@ -1,81 +1,131 @@ -RUN: llvm-readelf -h %p/Inputs/trivial.obj.elf-i386 \ -RUN: | FileCheck %s -check-prefix ELF32 -RUN: llvm-readelf --file-header %p/Inputs/trivial.obj.elf-i386 \ -RUN: | FileCheck %s -check-prefix ELF32 -RUN: llvm-readelf --file-headers %p/Inputs/trivial.obj.elf-i386 \ -RUN: | FileCheck %s -check-prefix ELF32 -RUN: llvm-readelf -h %p/Inputs/trivial.obj.elf-x86-64 \ -RUN: | FileCheck %s -check-prefix ELF64 -RUN: llvm-readelf --file-header %p/Inputs/trivial.obj.elf-x86-64 \ -RUN: | FileCheck %s -check-prefix ELF64 -RUN: llvm-readelf --file-headers %p/Inputs/trivial.obj.elf-x86-64 \ -RUN: | FileCheck %s -check-prefix ELF64 -RUN: llvm-readelf -h %p/Inputs/trivial.obj.elf-mipsel \ -RUN: | FileCheck %s -check-prefix MIPSEL -RUN: llvm-readelf --file-header %p/Inputs/trivial.obj.elf-mipsel \ -RUN: | FileCheck %s -check-prefix MIPSEL -RUN: llvm-readelf --file-headers %p/Inputs/trivial.obj.elf-mipsel \ -RUN: | FileCheck %s -check-prefix MIPSEL +## In this test we test how llvm-readelf prints file headers. -ELF32: ELF Header: -ELF32-NEXT: Magic: 7f 45 4c 46 01 01 01 03 00 00 00 00 00 00 00 00 -ELF32-NEXT: Class: ELF32 -ELF32-NEXT: Data: 2's complement, little endian -ELF32-NEXT: Version: 1 (current) -ELF32-NEXT: OS/ABI: UNIX - GNU -ELF32-NEXT: ABI Version: 0 -ELF32-NEXT: Type: REL (Relocatable file) -ELF32-NEXT: Machine: Intel 80386 -ELF32-NEXT: Version: 0x1 -ELF32-NEXT: Entry point address: 0x0 -ELF32-NEXT: Start of program headers: 0 (bytes into file) -ELF32-NEXT: Start of section headers: 200 (bytes into file) -ELF32-NEXT: Flags: 0x0 -ELF32-NEXT: Size of this header: 52 (bytes) -ELF32-NEXT: Size of program headers: 0 (bytes) -ELF32-NEXT: Number of program headers: 0 -ELF32-NEXT: Size of section headers: 40 (bytes) -ELF32-NEXT: Number of section headers: 10 -ELF32-NEXT: Section header string table index: 7 +## Case 1: Test EM_386 object. +# RUN: yaml2obj %s --docnum=1 -o %t1 +# RUN: llvm-readelf -h %t1 | FileCheck %s --check-prefix=I386 +# RUN: llvm-readelf --file-header %t1 \ +# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=I386 +# RUN: llvm-readelf --file-headers %t1 \ +# RUN: | FileCheck %s --strict-whitespace --match-full-lines --check-prefix=I386 -ELF64: ELF Header: -ELF64-NEXT: Magic: 7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 -ELF64-NEXT: Class: ELF64 -ELF64-NEXT: Data: 2's complement, little endian -ELF64-NEXT: Version: 1 (current) -ELF64-NEXT: OS/ABI: UNIX - GNU -ELF64-NEXT: ABI Version: 0 -ELF64-NEXT: Type: REL (Relocatable file) -ELF64-NEXT: Machine: Advanced Micro Devices X86-64 -ELF64-NEXT: Version: 0x1 -ELF64-NEXT: Entry point address: 0x0 -ELF64-NEXT: Start of program headers: 0 (bytes into file) -ELF64-NEXT: Start of section headers: 184 (bytes into file) -ELF64-NEXT: Flags: 0x0 -ELF64-NEXT: Size of this header: 64 (bytes) -ELF64-NEXT: Size of program headers: 0 (bytes) -ELF64-NEXT: Number of program headers: 0 -ELF64-NEXT: Size of section headers: 64 (bytes) -ELF64-NEXT: Number of section headers: 10 -ELF64-NEXT: Section header string table index: 7 +# I386:ELF Header: +# I386-NEXT: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 +# I386-NEXT: Class: ELF32 +# I386-NEXT: Data: 2's complement, little endian +# I386-NEXT: Version: 1 (current) +# I386-NEXT: OS/ABI: UNIX - System V +# I386-NEXT: ABI Version: 0x0 +# I386-NEXT: Type: REL (Relocatable file) +# I386-NEXT: Machine: Intel 80386 +# I386-NEXT: Version: 0x1 +# I386-NEXT: Entry point address: 0x11223344 +# I386-NEXT: Start of program headers: 52 (bytes into file) +# I386-NEXT: Start of section headers: 112 (bytes into file) +# I386-NEXT: Flags: 0x0 +# I386-NEXT: Size of this header: 52 (bytes) +# I386-NEXT: Size of program headers: 32 (bytes) +# I386-NEXT: Number of program headers: 1 +# I386-NEXT: Size of section headers: 40 (bytes) +# I386-NEXT: Number of section headers: 4 +# I386-NEXT: Section header string table index: 3 -MIPSEL: ELF Header: -MIPSEL-NEXT: Magic: 7f 45 4c 46 01 01 01 03 00 00 00 00 00 00 00 00 -MIPSEL-NEXT: Class: ELF32 -MIPSEL-NEXT: Data: 2's complement, little endian -MIPSEL-NEXT: Version: 1 (current) -MIPSEL-NEXT: OS/ABI: UNIX - GNU -MIPSEL-NEXT: ABI Version: 0x0 -MIPSEL-NEXT: Type: REL (Relocatable file) -MIPSEL-NEXT: Machine: MIPS R3000 -MIPSEL-NEXT: Version: 0x1 -MIPSEL-NEXT: Entry point address: 0x0 -MIPSEL-NEXT: Start of program headers: 0 (bytes into file) -MIPSEL-NEXT: Start of section headers: 172 (bytes into file) -MIPSEL-NEXT: Flags: 0x50001000, o32, mips32 -MIPSEL-NEXT: Size of this header: 52 (bytes) -MIPSEL-NEXT: Size of program headers: 0 (bytes) -MIPSEL-NEXT: Number of program headers: 0 -MIPSEL-NEXT: Size of section headers: 40 (bytes) -MIPSEL-NEXT: Number of section headers: 9 -MIPSEL-NEXT: Section header string table index: 6 +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_386 + Entry: 0x11223344 +Sections: + - Name: .foo + Type: SHT_PROGBITS +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_R ] + +## Case 2: Test EM_X86_64 object. +# RUN: yaml2obj %s --docnum=2 -o %t2 +# RUN: llvm-readelf -h %t2 | FileCheck %s --check-prefix=X86-64 +# RUN: llvm-readelf --file-header %t2 \ +# RUN: | FileCheck %s --check-prefix=X86-64 --strict-whitespace --match-full-lines +# RUN: llvm-readelf --file-headers %t2 \ +# RUN: | FileCheck %s --check-prefix=X86-64 --strict-whitespace --match-full-lines + +# X86-64:ELF Header: +# X86-64-NEXT: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 +# X86-64-NEXT: Class: ELF64 +# X86-64-NEXT: Data: 2's complement, little endian +# X86-64-NEXT: Version: 1 (current) +# X86-64-NEXT: OS/ABI: UNIX - System V +# X86-64-NEXT: ABI Version: 0x0 +# X86-64-NEXT: Type: REL (Relocatable file) +# X86-64-NEXT: Machine: Advanced Micro Devices X86-64 +# X86-64-NEXT: Version: 0x1 +# X86-64-NEXT: Entry point address: 0x1122334455667788 +# X86-64-NEXT: Start of program headers: 64 (bytes into file) +# X86-64-NEXT: Start of section headers: 152 (bytes into file) +# X86-64-NEXT: Flags: 0x0 +# X86-64-NEXT: Size of this header: 64 (bytes) +# X86-64-NEXT: Size of program headers: 56 (bytes) +# X86-64-NEXT: Number of program headers: 1 +# X86-64-NEXT: Size of section headers: 64 (bytes) +# X86-64-NEXT: Number of section headers: 4 +# X86-64-NEXT: Section header string table index: 3 + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_X86_64 + Entry: 0x1122334455667788 +Sections: + - Name: .foo + Type: SHT_PROGBITS +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_R ] + +## Case 3: Use an arbitrary machine type that allows to show how we print Flags. +## Here we use an EM_MIPS object for that. +# RUN: yaml2obj %s --docnum=3 -o %t3 +# RUN: llvm-readelf -h %t3 | FileCheck %s --check-prefix=MIPSEL +# RUN: llvm-readelf --file-header %t3 \ +# RUN: | FileCheck %s --check-prefix=MIPSEL --strict-whitespace --match-full-lines +# RUN: llvm-readelf --file-headers %t3 \ +# RUN: | FileCheck %s --check-prefix=MIPSEL --strict-whitespace --match-full-lines + +# MIPSEL:ELF Header: +# MIPSEL-NEXT: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 +# MIPSEL-NEXT: Class: ELF32 +# MIPSEL-NEXT: Data: 2's complement, little endian +# MIPSEL-NEXT: Version: 1 (current) +# MIPSEL-NEXT: OS/ABI: UNIX - System V +# MIPSEL-NEXT: ABI Version: 0x0 +# MIPSEL-NEXT: Type: REL (Relocatable file) +# MIPSEL-NEXT: Machine: MIPS R3000 +# MIPSEL-NEXT: Version: 0x1 +# MIPSEL-NEXT: Entry point address: 0x0 +# MIPSEL-NEXT: Start of program headers: 52 (bytes into file) +# MIPSEL-NEXT: Start of section headers: 112 (bytes into file) +# MIPSEL-NEXT: Flags: 0x50001000, o32, mips32 +# MIPSEL-NEXT: Size of this header: 52 (bytes) +# MIPSEL-NEXT: Size of program headers: 32 (bytes) +# MIPSEL-NEXT: Number of program headers: 1 +# MIPSEL-NEXT: Size of section headers: 40 (bytes) +# MIPSEL-NEXT: Number of section headers: 4 +# MIPSEL-NEXT: Section header string table index: 3 + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [ EF_MIPS_ARCH_32, EF_MIPS_ABI_O32 ] +Sections: + - Name: .foo + Type: SHT_PROGBITS +ProgramHeaders: + - Type: PT_LOAD + Flags: [ PF_R ] Index: llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-phdrs.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-phdrs.test +++ llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-phdrs.test @@ -1,5 +1,18 @@ -RUN: llvm-readelf --section-mapping %p/Inputs/trivial.obj.elf-x86-64 | FileCheck %s -CHECK: Section to Segment mapping: -CHECK-NEXT: Segment Sections... -CHECK-NEXT: None .text .rela.text .data .bss .rodata.str1.1 .note.GNU-stack .shstrtab .symtab .strtab {{$}} -CHECK-NOT: {{.}} +## Test the behaviour of --section-mapping when there are no section headers in an object. +# RUN: yaml2obj %s -o %t +# RUN: llvm-readelf --section-mapping %t | FileCheck %s --strict-whitespace --match-full-lines + +# CHECK: Section to Segment mapping: +# CHECK-NEXT: Segment Sections... +# CHECK-NEXT: None .foo .strtab .shstrtab +# CHECK-NOT:{{.}} + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_386 +Sections: + - Name: .foo + Type: SHT_PROGBITS Index: llvm/test/tools/llvm-readobj/ELF/hex-dump.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/hex-dump.test +++ llvm/test/tools/llvm-readobj/ELF/hex-dump.test @@ -1,14 +1,14 @@ ## Test that the -x alias can be used flexibly. Create a baseline and ensure ## all other combinations are identical. -# RUN: llvm-readelf --file-header --hex-dump=.text \ -# RUN: %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.out -# RUN: llvm-readelf -h --hex-dump .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.1 -# RUN: llvm-readelf -h -x .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.2 -# RUN: llvm-readelf -h -x=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.3 -# RUN: llvm-readelf -h -x.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.4 -# RUN: llvm-readelf -hx .text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.5 -# RUN: llvm-readelf -hx=.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.6 -# RUN: llvm-readelf -hx.text %p/Inputs/trivial.obj.elf-x86-64 > %t.hexdump.7 +# RUN: yaml2obj %s -o %t +# RUN: llvm-readelf --file-header --hex-dump=.shstrtab %t > %t.hexdump.out +# RUN: llvm-readelf -h --hex-dump .shstrtab %t > %t.hexdump.1 +# RUN: llvm-readelf -h -x .shstrtab %t > %t.hexdump.2 +# RUN: llvm-readelf -h -x=.shstrtab %t > %t.hexdump.3 +# RUN: llvm-readelf -h -x.shstrtab %t > %t.hexdump.4 +# RUN: llvm-readelf -hx .shstrtab %t > %t.hexdump.5 +# RUN: llvm-readelf -hx=.shstrtab %t > %t.hexdump.6 +# RUN: llvm-readelf -hx.shstrtab %t > %t.hexdump.7 # RUN: cmp %t.hexdump.out %t.hexdump.1 # RUN: cmp %t.hexdump.out %t.hexdump.2 @@ -18,29 +18,25 @@ # RUN: cmp %t.hexdump.out %t.hexdump.6 # RUN: cmp %t.hexdump.out %t.hexdump.7 -# RUN: llvm-readelf -S %p/Inputs/trivial.obj.elf-x86-64 | FileCheck %s --check-prefix=ELF-SEC - -## Both 9 and .strtab refer to .strtab. Test we dump the section only once. -# RUN: llvm-readobj -x 9 -x 9 -x .strtab -x .strtab %p/Inputs/trivial.obj.elf-x86-64 2>&1 | \ -# RUN: FileCheck %s --check-prefix=ELF -# RUN: llvm-readobj -x 9 -x .strtab -x 10 -x not_exist \ -# RUN: %p/Inputs/trivial.obj.elf-x86-64 2>&1 | FileCheck %s -DFILE=%p/Inputs/trivial.obj.elf-x86-64 --check-prefixes=ELF-WARN,ELF +## A sanity check to verify that the .shstrtab section has index 2. +# RUN: llvm-readelf -S %t | FileCheck %s --check-prefix=ELF-SEC +# ELF-SEC: [ 2] .shstrtab -# ELF-SEC: [ 9] .strtab +## Test we dump the section only once when the option is specified multiple times for the same section. +# RUN: llvm-readobj -x 2 -x 2 -x .shstrtab -x .shstrtab %t 2>&1 \ +# RUN: | FileCheck %s --check-prefix=ELF +## Test warnings reported when an unknown section name and index are specified. +# RUN: llvm-readobj -x 2 -x .shstrtab -x 3 -x not_exist %t 2>&1 \ +# RUN: | FileCheck %s -DFILE=%t --check-prefixes=ELF-WARN,ELF # ELF-WARN: warning: '[[FILE]]': could not find section 'not_exist' -# ELF-WARN: warning: '[[FILE]]': could not find section 10 -# ELF: Hex dump of section '.strtab': -# ELF-NEXT: 0x00000000 00747269 7669616c 2e6c6c00 6d61696e .trivial.ll.main -# ELF-NEXT: 0x00000010 002e4c2e 73747200 70757473 00536f6d ..L.str.puts.Som -# ELF-NEXT: 0x00000020 654f7468 65724675 6e637469 6f6e005f eOtherFunction._ -# ELF-NEXT: 0x00000030 474c4f42 414c5f4f 46465345 545f5441 GLOBAL_OFFSET_TA -# ELF-NEXT: 0x00000040 424c455f 00 BLE_. +# ELF-WARN: warning: '[[FILE]]': could not find section 3 +# ELF: Hex dump of section '.shstrtab': +# ELF-NEXT: 0x00000000 002e7368 73747274 6162002e 73747274 ..shstrtab..strt +# ELF-NEXT: 0x00000010 616200 ab. # ELF-NOT: {{.}} ## This test shows that we include the tool name in an error/warning message. - -# RUN: yaml2obj %s -o %t # RUN: llvm-readelf -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readelf # RUN: llvm-readobj -x 10 %t 2>&1 | FileCheck --check-prefix=WARN %s -DTOOL=readobj @@ -48,7 +44,7 @@ --- !ELF FileHeader: - Class: ELFCLASS64 + Class: ELFCLASS32 Data: ELFDATA2LSB Type: ET_DYN - Machine: EM_RISCV + Machine: EM_386 Index: llvm/test/tools/llvm-readobj/ELF/thin-archive-paths.test =================================================================== --- llvm/test/tools/llvm-readobj/ELF/thin-archive-paths.test +++ llvm/test/tools/llvm-readobj/ELF/thin-archive-paths.test @@ -1,7 +1,7 @@ # RUN: rm -rf %t # RUN: mkdir -p %t/a/b # RUN: cd %t -# RUN: cp %p/Inputs/trivial.obj.elf-x86-64 a/b/1.o +# RUN: yaml2obj %s -o a/b/1.o # The archive is deliberately in a different directory to the cwd, to show that # the member paths printed are exactly what's in the archive and not relative # to the cwd. @@ -19,7 +19,7 @@ # ERR1: error: 'a/relative.a': 'b/1.o': {{[Nn]}}o such file or directory # RUN: mkdir -p %t/c -# RUN: cp %p/Inputs/trivial.obj.elf-x86-64 a/b/1.o +# RUN: yaml2obj %s -o a/b/1.o # RUN: llvm-ar rcT c/absolute.a %t/a/b/1.o # Show that absolute paths in the file header printing are correct. @@ -31,3 +31,10 @@ # RUN: not llvm-readobj --file-headers %/t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%/t # RUN: not llvm-readelf --file-headers %/t/c/absolute.a 2>&1 | FileCheck %s --check-prefix=ERR2 -DDIR=%/t # ERR2: error: '[[DIR]]/c/absolute.a': '[[DIR]]/a/b/1.o': {{[Nn]}}o such file or directory + +--- !ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_DYN + Machine: EM_386