From 07d448135f328d040e51f49541467004643525ea Mon Sep 17 00:00:00 2001 From: Georgii Rymar Date: Thu, 23 Apr 2020 11:09:38 +0300 Subject: [PATCH] [llvm-readobj][test] - Stop using binaries in gnu-phdrs.test, split and refine it. gnu-phdrs.test uses 2 precompiled objects and has issues: * It does not test all possible program headers. * It does not test target-specific headers (arm, mips). * It does not use --strict-whitespace --match-full-line to check the format of the output. * It is possible to check things better/nicer. * It also tests --section-mapping. This patch makes gnu-phdrs.test to stop using binaries and addresses issues above. It splits --section-mapping testing to gnu-section-mapping.test I am going to use it as a base for a follow-up patch that should also test section to segment mapping conditions that we currently have (see the discussion in D78709) Differential revision: https://reviews.llvm.org/D78805 --- .../llvm-readobj/ELF/Inputs/phdrs-elf.exe-i386 | Bin 7512 -> 0 bytes .../llvm-readobj/ELF/Inputs/phdrs-elf.exe-x86_64 | Bin 9030 -> 0 bytes llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test | 380 ++++++++++++++++----- .../ELF/gnu-section-mapping-no-shdrs.test | 15 - .../llvm-readobj/ELF/gnu-section-mapping.test | 76 +++++ 5 files changed, 370 insertions(+), 101 deletions(-) delete mode 100644 llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-i386 delete mode 100644 llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-x86_64 delete mode 100644 llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-shdrs.test create mode 100644 llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping.test diff --git a/llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-i386 b/llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-i386 deleted file mode 100644 index a5a9541aec5fdbbf1301a821d572a335939b007b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7512 zcmeHMYiwLc6`u93+fD1Z8|Q&ZOxc!A$%EY3v11Y%6g&1hICUO%oRC*@yWYL_ZnF<- z_ik{i3KAC68e=tr{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ifrd9k8y>!O6 diff --git a/llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-x86_64 b/llvm/test/tools/llvm-readobj/ELF/Inputs/phdrs-elf.exe-x86_64 deleted file mode 100644 index 6b6520809d7190c5caa7357d9a2eef0750737413..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9030 zcmeHMeQZT&{Xiwx$hkN zy%&3%G)>wcT+8p=^SkGF@45Hgd)|BZzStA)b-P@GlUqC`Q1jI*5;CtsOfQitVI5+D zP{d>6QBe=bJoqcJ1f`i{+2S?}SbE9M1F{bOX(~^<70^&uP>411T9ND_N^Gx^6v~=1 zFyB;J3gMRk^3d0xES4(BV=}|iAU|Fu$vjk%S0G-2cr1Nn&yxFxeZ&6*l~1@8&`?)U zh;DhUNVLV&0DsKa@{{eX?I3Ue4I_$WJE&lXS3wwbQ*M%)5G=W#1Hi-n{iliB?W6W; z`5C5uv*i1?IT0UhZ`+)RHYeiA+-UP?M|*R7TQHjnZjt@=fg@Vu_w%5Ra3i#40_Sk=a6?|U}{50Uz>WSCDbAUevt4r}6gB+}Ld4&ty zm#h(uY}|2(75Bg zWFHXrT5#)n^jUE0Tvo?E^cL~vt7E_PUcnm7RNA&`fnSu?t$}OPS_N{b4`boY>m^9* zmZFZX-YiIc0qQs~H>W{w{V0@w>!_N4PaS)Ic7K0pW_q$g5$eq4i&D(^K@@)ghM!DM zq7Ul$yl>C<3-#=@;Vu=VGn3XdwHZ1vpf;}up^n{cRP#4Zx{q9$LWhv_$&oj(sC2z) z?HRnu6XsDk3J&@J>nHPBDL zI>mRi^;h{{&-8qTK165g)_n$cIC?+B=#>ARn(vua^8>}=H}989(eXv=?m~HVyiMA< zKF)j9{ERxDn^nib=0&iv4i@BZUpbB`*tGT~YyrGV1l|tkqk-${`Q|3@JbZqgKmm9$ zoHqiq;rw%fyK4S$07n1Aj_`&Xo%wsA{2lf3Jx?hAhvKz+rILE~BV$eLpRoVo{6E6^ zJKg!ecb1mDtB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m}K9U_YEvR?adt zV?>MKX=YaN38e+nv}j5jN~8w$gcdbYnXIPgMg@FyrxP(F77eyPv2_d7T*XMky#VuL zUV{(x%qd~+1w?ZrBd363(KOsbu$k(?NIDHhy?vc~dbFOs-FUDn{ipn{@V=d$VQpV; z@4=pat-o_;xCbq46-DiUJfIa?_gD9J?g@1X+(R&rO2JH?n?|xZ>9i=r|NdZCZg>#i zJORdYS4FX&w*Je*oRqs*{jk|a7=+f!r_{C*xUt}KOm4@>^JaMi#6JN_>GXjB diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test b/llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test index cf6ba17..324fa9f 100644 --- a/llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test +++ b/llvm/test/tools/llvm-readobj/ELF/gnu-phdrs.test @@ -1,97 +1,305 @@ -#Source : -#__thread int a = 1; -#__thread int b; -# -#int main () { -# b = 2; -# throw (a + b) ; -# return 0; -#} -# compiled as clang++ source.cpp -# and clang++ -m32 source.cpp +## Check how llvm-readelf dumps program headers and prints sections to segments mapping. -RUN: llvm-readelf -l %p/Inputs/phdrs-elf.exe-i386 \ -RUN: | FileCheck %s -check-prefix ELF32 -RUN: llvm-readelf -l %p/Inputs/phdrs-elf.exe-x86_64 \ -RUN: | FileCheck %s -check-prefixes ELF64-PHDRS,ELF64-MAPPING -RUN: llvm-readelf -program-headers %p/Inputs/phdrs-elf.exe-x86_64 \ -RUN: | FileCheck %s -check-prefixes ELF64-PHDRS,ELF64-MAPPING +## Check that -l, --program-headers and --segments are the same option. +# RUN: yaml2obj -DBITS=32 -DMACHINE=EM_386 %s -o %t32.elf +# RUN: llvm-readelf -l %t32.elf 2>&1 > %t.readelf-l.txt +# RUN: llvm-readelf --program-headers %t32.elf 2>&1 > %t.readelf-pheaders.txt +# RUN: cmp %t.readelf-l.txt %t.readelf-pheaders.txt +# RUN: llvm-readelf --segments %t32.elf 2>&1 > %t.readelf-segments.txt +# RUN: cmp %t.readelf-l.txt %t.readelf-segments.txt -# Check that -section-mapping produces a mapping and not the program headers. -RUN: llvm-readelf -section-mapping %p/Inputs/phdrs-elf.exe-x86_64 \ -RUN: | FileCheck %s -check-prefix ELF64-MAPPING -implicit-check-not="Program Headers:" +## Check we are able to print program headers of different types. +# RUN: llvm-readelf -l %t32.elf | \ +# RUN: FileCheck %s --check-prefixes=ELF32,MAPPING --strict-whitespace --match-full-lines -# Check that -section-mapping=false -program-headers produces just program headers. -RUN: llvm-readelf -section-mapping=false -program-headers %p/Inputs/phdrs-elf.exe-x86_64 \ -RUN: | FileCheck %s -check-prefix ELF64-PHDRS -implicit-check-not="Section to Segment mapping:" +# RUN: yaml2obj -DBITS=64 -DMACHINE=EM_X86_64 %s -o %t64.elf +# RUN: llvm-readelf -l %t64.elf | \ +# RUN: FileCheck %s --check-prefixes=ELF64,MAPPING --strict-whitespace --match-full-lines -# Check that only one copy of the section/segment mapping table is produced. -RUN: llvm-readelf -section-mapping -program-headers %p/Inputs/phdrs-elf.exe-x86_64 \ -RUN: | FileCheck %s -check-prefix ELF64-ONEMAPPING +# ELF32:There are 23 program headers, starting at offset 52 +# ELF32-EMPTY: +# ELF32-NEXT:Program Headers: +# ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# ELF32-NEXT: PHDR 0x000314 0x00001000 0x00001000 0x00003 0x00003 W 0x1 +# ELF32-NEXT: PHDR 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 +# ELF32-NEXT: NULL 0x000317 0x00002000 0x00002000 0x00007 0x00007 E 0x1 +# ELF32-NEXT: DYNAMIC 0x000314 0x00001000 0x00001000 0x00003 0x00003 RWE 0x1 +# ELF32-NEXT: INTERP 0x00031e 0x00003000 0x00003000 0x00004 0x00004 RW 0x1 +# ELF32-NEXT: [Requesting program interpreter: ABC] +# ELF32-NEXT: NOTE 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: SHLIB 0x000314 0x00001000 0x00001000 0x00001 0x00001 0x1 +# ELF32-NEXT: TLS 0x000322 0x00004000 0x00004000 0x00001 0x00001 0x1 +# ELF32-NEXT: : 0x60000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_EH_FRAME 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: SUNW_UNWIND 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_STACK 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_RELRO 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: GNU_PROPERTY 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x65a3dbe6 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x65a3dbe7 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x65a41be6 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x6fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000000 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000001 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000002 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x70000003 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-NEXT: : 0x7fffffff 0x000314 0x00001000 0x00001000 0x00003 0x00003 0x1 +# ELF32-EMPTY: -ELF32: Elf file type is EXEC (Executable file) -ELF32-NEXT: Entry point 0x8048460 -ELF32-NEXT: There are 10 program headers, starting at offset 52 +# ELF64:There are 23 program headers, starting at offset 64 +# ELF64-EMPTY: +# ELF64-NEXT:Program Headers: +# ELF64-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align +# ELF64-NEXT: PHDR 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 W 0x1 +# ELF64-NEXT: PHDR 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 +# ELF64-NEXT: NULL 0x00054b 0x0000000000002000 0x0000000000002000 0x000007 0x000007 E 0x1 +# ELF64-NEXT: DYNAMIC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 RWE 0x1 +# ELF64-NEXT: INTERP 0x000552 0x0000000000003000 0x0000000000003000 0x000004 0x000004 RW 0x1 +# ELF64-NEXT: [Requesting program interpreter: ABC] +# ELF64-NEXT: NOTE 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: SHLIB 0x000548 0x0000000000001000 0x0000000000001000 0x000001 0x000001 0x1 +# ELF64-NEXT: TLS 0x000556 0x0000000000004000 0x0000000000004000 0x000001 0x000001 0x1 +# ELF64-NEXT: : 0x60000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_EH_FRAME 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: SUNW_UNWIND 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_STACK 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_RELRO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: GNU_PROPERTY 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x65a3dbe6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x65a3dbe7 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x65a41be6 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x6fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000001 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x70000003 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-NEXT: : 0x7fffffff 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ELF64-EMPTY: -ELF32: Program Headers: -ELF32-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align -ELF32-NEXT: PHDR 0x000034 0x08048034 0x08048034 0x00140 0x00140 R E 0x4 -ELF32-NEXT: INTERP 0x000174 0x08048174 0x08048174 0x00013 0x00013 R 0x1 -ELF32-NEXT: [Requesting program interpreter: /lib/ld-linux.so.2] -ELF32-NEXT: LOAD 0x000000 0x08048000 0x08048000 0x006d0 0x006d0 R E 0x1000 -ELF32-NEXT: LOAD 0x000ef0 0x08049ef0 0x08049ef0 0x00128 0x00140 RW 0x1000 -ELF32-NEXT: DYNAMIC 0x000f08 0x08049f08 0x08049f08 0x000e8 0x000e8 RW 0x4 -ELF32-NEXT: NOTE 0x000188 0x08048188 0x08048188 0x00044 0x00044 R 0x4 -ELF32-NEXT: TLS 0x000ef0 0x08049ef0 0x08049ef0 0x00004 0x00008 R 0x4 -ELF32-NEXT: GNU_EH_FRAME 0x000640 0x08048640 0x08048640 0x0001c 0x0001c R 0x4 -ELF32-NEXT: GNU_STACK 0x000000 0x00000000 0x00000000 0x00000 0x00000 RW 0x4 -ELF32-NEXT: GNU_RELRO 0x000ef0 0x08049ef0 0x08049ef0 0x00110 0x00110 R 0x1 +# MAPPING: Section to Segment mapping: +# MAPPING-NEXT: Segment Sections... +# MAPPING-NEXT: 00 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 01 .bar.begin .bar.end {{$}} +# MAPPING-NEXT: 02 .bar.begin .bar.end {{$}} +# MAPPING-NEXT: 03 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 04 .interp {{$}} +# MAPPING-NEXT: 05 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 06 .foo.begin {{$}} +# MAPPING-NEXT: 07 .tls {{$}} +# MAPPING-NEXT: 08 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 09 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 10 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 11 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 12 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 13 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 14 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 15 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 16 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 17 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 18 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 19 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 20 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 21 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 22 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: None .unused .strtab .shstrtab {{$}} -ELF32: Section to Segment mapping: -ELF32-NEXT: Segment Sections... -ELF32-NEXT: 00 -ELF32-NEXT: 01 .interp -ELF32-NEXT: 02 .interp .note.ABI-tag .note.gnu.build-id .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rel.dyn .rel.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame -ELF32-NEXT: 03 .tdata .ctors .dtors .jcr .dynamic .got .got.plt .data .bss -ELF32-NEXT: 04 .dynamic -ELF32-NEXT: 05 .note.ABI-tag .note.gnu.build-id -ELF32-NEXT: 06 .tdata .tbss -ELF32-NEXT: 07 .eh_frame_hdr -ELF32-NEXT: 08 -ELF32-NEXT: 09 .tdata .ctors .dtors .jcr .dynamic .got -ELF32-NEXT: None .comment .shstrtab .symtab .strtab +--- !ELF +FileHeader: + Class: ELFCLASS[[BITS]] + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: [[MACHINE]] + Entry: 0x12345678 +Sections: + - Name: .foo.begin + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1000 + Size: 0x1 + - Name: .foo.end + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Size: 0x2 + - Name: .bar.begin + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x2000 + Size: 0x3 + - Name: .bar.end + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Size: 0x4 + - Name: .interp + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x3000 + Content: "41424300" ## "ABC" + - Name: .tls + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_TLS ] + Address: 0x4000 + Size: 0x1 + - Name: .unused + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC, SHF_TLS ] + Address: 0x5000 + Size: 0x1 +ProgramHeaders: +## Case 1: an arbitrary segment with sections. + - Type: PT_PHDR + Flags: [ PF_W ] + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 2: another segment with different sections. + - Type: PT_PHDR + Flags: [ PF_X ] + VAddr: 0x2000 + Sections: + - Section: .bar.begin + - Section: .bar.end +## Case 3: the PT_NULL segment. + - Type: PT_NULL + Flags: [ PF_X ] + VAddr: 0x2000 + Sections: + - Section: .bar.begin + - Section: .bar.end +## Case 4: the PT_DYNAMIC segment. + - Type: PT_DYNAMIC + Flags: [ PF_R, PF_W, PF_X ] + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 5: the PT_INTERP segment. + - Type: PT_INTERP + Flags: [ PF_R, PF_W ] + VAddr: 0x3000 + Sections: + - Section: .interp +## Case 6: the PT_NOTE segment. + - Type: PT_NOTE + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 7: the PT_SHLIB segment. + - Type: PT_SHLIB + VAddr: 0x1000 + Sections: + - Section: .foo.begin +## Case 8: the PT_TLS segment. + - Type: PT_TLS + VAddr: 0x4000 + Sections: + - Section: .tls +## Case 9: the PT_LOOS segment. + - Type: 0x60000000 ## PT_LOOS + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 10: the PT_GNU_EH_FRAME segment. + - Type: PT_GNU_EH_FRAME + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 11: the PT_SUNW_UNWIND segment. + - Type: 0x6464e550 ## PT_SUNW_UNWIND + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 12: the PT_GNU_STACK segment. + - Type: PT_GNU_STACK + Sections: + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 13: the PT_GNU_RELRO segment. + - Type: PT_GNU_RELRO + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 14: the PT_GNU_PROPERTY segment. + - Type: PT_GNU_PROPERTY + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 15: the PT_OPENBSD_RANDOMIZE segment. + - Type: 0x65a3dbe6 ## PT_OPENBSD_RANDOMIZE + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 16: the PT_OPENBSD_WXNEEDED segment. + - Type: 0x65a3dbe7 ## PT_OPENBSD_WXNEEDED + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 17: the PT_OPENBSD_BOOTDATA segment. + - Type: 0x65a41be6 ## PT_OPENBSD_BOOTDATA + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 18: the PT_HIOS segment. + - Type: 0x6fffffff ## PT_HIOS + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 19: the PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO segment. + - Type: 0x70000000 ## PT_LOPROC/PT_ARM_ARCHEXT/PT_MIPS_REGINFO + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 20: the PT_ARM_EXIDX/PT_MIPS_RTPROC segment. + - Type: 0x70000001 ## PT_ARM_EXIDX, PT_MIPS_RTPROC + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 20: the PT_MIPS_OPTIONS segment. + - Type: 0x70000002 ## PT_MIPS_OPTIONS + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 21: the PT_MIPS_ABIFLAGS segment. + - Type: 0x70000003 ## PT_MIPS_ABIFLAGS + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 22: the PT_HIPROC segment. + - Type: 0x7fffffff ## PT_HIPROC + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end -ELF64-PHDRS: Elf file type is EXEC (Executable file) -ELF64-PHDRS-NEXT: Entry point 0x400610 -ELF64-PHDRS-NEXT: There are 10 program headers, starting at offset 64 +## Check how we dump ARM specific program headers. +# RUN: yaml2obj -DBITS=64 -DMACHINE=EM_ARM %s -o %tarm.elf +# RUN: llvm-readelf --program-headers %tarm.elf | FileCheck %s --check-prefix=ARM -ELF64-PHDRS: Program Headers: -ELF64-PHDRS-NEXT: Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align -ELF64-PHDRS-NEXT: PHDR 0x000040 0x0000000000400040 0x0000000000400040 0x000230 0x000230 R E 0x8 -ELF64-PHDRS-NEXT: INTERP 0x000270 0x0000000000400270 0x0000000000400270 0x00001c 0x00001c R 0x1 -ELF64-PHDRS-NEXT: [Requesting program interpreter: /lib64/ld-linux-x86-64.so.2] -ELF64-PHDRS-NEXT: LOAD 0x000000 0x0000000000400000 0x0000000000400000 0x000924 0x000924 R E 0x200000 -ELF64-PHDRS-NEXT: LOAD 0x000db4 0x0000000000600db4 0x0000000000600db4 0x000274 0x0002a4 RW 0x200000 -ELF64-PHDRS-NEXT: DYNAMIC 0x000dd0 0x0000000000600dd0 0x0000000000600dd0 0x000210 0x000210 RW 0x8 -ELF64-PHDRS-NEXT: NOTE 0x00028c 0x000000000040028c 0x000000000040028c 0x000044 0x000044 R 0x4 -ELF64-PHDRS-NEXT: TLS 0x000db4 0x0000000000600db4 0x0000000000600db4 0x000004 0x000008 R 0x4 -ELF64-PHDRS-NEXT: GNU_EH_FRAME 0x00083c 0x000000000040083c 0x000000000040083c 0x00002c 0x00002c R 0x4 -ELF64-PHDRS-NEXT: GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0x8 -ELF64-PHDRS-NEXT: GNU_RELRO 0x000db4 0x0000000000600db4 0x0000000000600db4 0x00024c 0x00024c R 0x1 +# ARM: : 0x70000000 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ARM-NEXT: EXIDX 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# ARM-NEXT: : 0x70000002 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 -ELF64-MAPPING: Section to Segment mapping: -ELF64-MAPPING-NEXT: Segment Sections... -ELF64-MAPPING-NEXT: 00 -ELF64-MAPPING-NEXT: 01 .interp -ELF64-MAPPING-NEXT: 02 .interp .note.ABI-tag .note.gnu.build-id .hash .gnu.hash .dynsym .dynstr .gnu.version .gnu.version_r .rela.dyn .rela.plt .init .plt .text .fini .rodata .eh_frame_hdr .eh_frame -ELF64-MAPPING-NEXT: 03 .tdata .init_array .fini_array .jcr .dynamic .got .got.plt .data .bss -ELF64-MAPPING-NEXT: 04 .dynamic -ELF64-MAPPING-NEXT: 05 .note.ABI-tag .note.gnu.build-id -ELF64-MAPPING-NEXT: 06 .tdata .tbss -ELF64-MAPPING-NEXT: 07 .eh_frame_hdr -ELF64-MAPPING-NEXT: 08 -ELF64-MAPPING-NEXT: 09 .tdata .init_array .fini_array .jcr .dynamic .got -ELF64-MAPPING-NEXT: None .comment .shstrtab .symtab .strtab +## Check how we dump MIPS specific program headers. +# RUN: yaml2obj -DBITS=64 -DMACHINE=EM_MIPS %s -o %tmips.elf +# RUN: llvm-readelf --program-headers %tmips.elf | FileCheck %s --check-prefix=MIPS -ELF64-ONEMAPPING: Section to Segment mapping: -ELF64-ONEMAPPING-NOT: Section to Segment mapping: +# MIPS: REGINFO 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-NEXT: RTPROC 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-NEXT: OPTIONS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 +# MIPS-NEXT: ABIFLAGS 0x000548 0x0000000000001000 0x0000000000001000 0x000003 0x000003 0x1 diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-shdrs.test b/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-shdrs.test deleted file mode 100644 index 94f8274..0000000 --- a/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping-no-shdrs.test +++ /dev/null @@ -1,15 +0,0 @@ -RUN: llvm-objcopy --strip-sections %p/Inputs/phdrs-elf.exe-x86_64 %t.o -RUN: llvm-readelf --section-mapping %t.o | FileCheck %s -CHECK: Section to Segment mapping: -CHECK-NEXT: Segment Sections... -CHECK-NEXT: 00 {{$}} -CHECK-NEXT: 01 {{$}} -CHECK-NEXT: 02 {{$}} -CHECK-NEXT: 03 {{$}} -CHECK-NEXT: 04 {{$}} -CHECK-NEXT: 05 {{$}} -CHECK-NEXT: 06 {{$}} -CHECK-NEXT: 07 {{$}} -CHECK-NEXT: 08 {{$}} -CHECK-NEXT: 09 {{$}} -CHECK-NOT: {{.}} diff --git a/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping.test b/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping.test new file mode 100644 index 0000000..ddbfdd5 --- /dev/null +++ b/llvm/test/tools/llvm-readobj/ELF/gnu-section-mapping.test @@ -0,0 +1,76 @@ +## Check how llvm-readelf prints sections to segments mapping. + +## Check that --section-mapping produces a sections to segments +## mapping and not anything else. +# RUN: yaml2obj %s -o %t64.elf +# RUN: llvm-readelf --section-mapping %t64.elf \ +# RUN: | FileCheck %s --check-prefix=MAPPING --strict-whitespace --match-full-lines --implicit-check-not={{.}} + +# MAPPING: Section to Segment mapping: +# MAPPING-NEXT: Segment Sections... +# MAPPING-NEXT: 00 .foo.begin .foo.end {{$}} +# MAPPING-NEXT: 01 .bar.begin .bar.end {{$}} +# MAPPING-NEXT: None .strtab .shstrtab {{$}} + +--- !ELF +FileHeader: + Class: ELFCLASS64 + Data: ELFDATA2LSB + Type: ET_EXEC + Machine: EM_X86_64 + Entry: 0x12345678 +Sections: + - Name: .foo.begin + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x1000 + Size: 0x1 + - Name: .foo.end + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Size: 0x2 + - Name: .bar.begin + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Address: 0x2000 + Size: 0x3 + - Name: .bar.end + Type: SHT_PROGBITS + Flags: [ SHF_ALLOC ] + Size: 0x4 +ProgramHeaders: +## Case 1: an arbitrary segment with sections. + - Type: PT_PHDR + Flags: [ PF_W ] + VAddr: 0x1000 + Sections: + - Section: .foo.begin + - Section: .foo.end +## Case 2: another segment with different sections. + - Type: PT_PHDR + Flags: [ PF_X ] + VAddr: 0x2000 + Sections: + - Section: .bar.begin + - Section: .bar.end + +## Check that --section-mapping=false --program-headers produces just program headers. +# RUN: llvm-readelf --section-mapping=false --program-headers %t64.elf \ +# RUN: | FileCheck %s --check-prefix=SEC-MAPPING-FALSE --implicit-check-not="Section to Segment mapping:" + +# SEC-MAPPING-FALSE: Program Headers: + +## Check that only one copy of the section/segment mapping table is produced +## when both --section-mapping and --program-headers are used. +# RUN: llvm-readelf --section-mapping --program-headers %t64.elf \ +# RUN: | FileCheck %s --check-prefix=MAPPING --implicit-check-not="Section to Segment mapping:" + +## Check the output when an object has no section headers. +## RUN: llvm-objcopy --strip-sections %t64.elf %tno-shdrs.o +## RUN: llvm-readelf --section-mapping %tno-shdrs.o | FileCheck %s --check-prefix=NO-SECHDRS + +# NO-SECHDRS: Section to Segment mapping: +# NO-SECHDRS-NEXT: Segment Sections... +# NO-SECHDRS-NEXT: 00 {{$}} +# NO-SECHDRS-NEXT: 01 {{$}} +# NO-SECHDRS-NOT: {{.}} -- 2.7.4