1## Check how llvm-readelf prints sections to segments mapping.
2
3## Check that --section-mapping produces a sections to segments
4## mapping and not anything else.
5# RUN: yaml2obj %s -o %t64.elf
6# RUN: llvm-readelf --section-mapping %t64.elf \
7# RUN:   | FileCheck %s --check-prefix=MAPPING --strict-whitespace --match-full-lines --implicit-check-not={{.}}
8
9#      MAPPING: Section to Segment mapping:
10# MAPPING-NEXT:  Segment Sections...
11# MAPPING-NEXT:   00     .foo.begin .foo.end {{$}}
12# MAPPING-NEXT:   01     .bar.begin .bar.end {{$}}
13# MAPPING-NEXT:   None   .strtab .shstrtab {{$}}
14
15--- !ELF
16FileHeader:
17  Class:   ELFCLASS64
18  Data:    ELFDATA2LSB
19  Type:    ET_EXEC
20  Machine: EM_X86_64
21  Entry:   0x12345678
22Sections:
23  - Name:    .foo.begin
24    Type:    SHT_PROGBITS
25    Flags:   [ SHF_ALLOC ]
26    Address: 0x1000
27    Size:    0x1
28  - Name:    .foo.end
29    Type:    SHT_PROGBITS
30    Flags:   [ SHF_ALLOC ]
31    Size:    0x2
32  - Name:    .bar.begin
33    Type:    SHT_PROGBITS
34    Flags:   [ SHF_ALLOC ]
35    Address: 0x2000
36    Size:    0x3
37  - Name:    .bar.end
38    Type:    SHT_PROGBITS
39    Flags:   [ SHF_ALLOC ]
40    Size:    0x4
41ProgramHeaders:
42## Case 1: an arbitrary segment with sections.
43  - Type:  PT_PHDR
44    Flags: [ PF_W ]
45    VAddr: 0x1000
46    Sections:
47      - Section: .foo.begin
48      - Section: .foo.end
49## Case 2: another segment with different sections.
50  - Type:  PT_PHDR
51    Flags: [ PF_X ]
52    VAddr: 0x2000
53    Sections:
54      - Section: .bar.begin
55      - Section: .bar.end
56
57## Check that --section-mapping=false --program-headers produces just program headers.
58# RUN: llvm-readelf --section-mapping=false --program-headers %t64.elf \
59# RUN:   | FileCheck %s --check-prefix=SEC-MAPPING-FALSE --implicit-check-not="Section to Segment mapping:"
60
61# SEC-MAPPING-FALSE: Program Headers:
62
63## Check that only one copy of the section/segment mapping table is produced
64## when both --section-mapping and --program-headers are used.
65# RUN: llvm-readelf --section-mapping --program-headers %t64.elf \
66# RUN:   | FileCheck %s --check-prefix=MAPPING --implicit-check-not="Section to Segment mapping:"
67
68## Check the output when an object has no section headers.
69## RUN: llvm-objcopy --strip-sections %t64.elf %tno-shdrs.o
70## RUN: llvm-readelf --section-mapping %tno-shdrs.o | FileCheck %s --check-prefix=NO-SECHDRS
71
72# NO-SECHDRS:      Section to Segment mapping:
73# NO-SECHDRS-NEXT:  Segment Sections...
74# NO-SECHDRS-NEXT:   00 {{$}}
75# NO-SECHDRS-NEXT:   01 {{$}}
76# NO-SECHDRS-NOT: {{.}}
77