1# This test is checking to ensure that if a section is removed in the presence
2# of a segment that the segment maintains its shape and properties and that any
3# section inside that segment maintains the relative positioning it had in the
4# segment. Note worthy is that .text3 keeps its offset despite it being
5# possible to place it after .text when .text2 is removed.
6
7# RUN: yaml2obj %s -o %t
8# RUN: llvm-objcopy -R .text2 %t %t2
9# RUN: llvm-readobj --file-headers --program-headers --sections %t2 | FileCheck %s
10# RUN: od -t x1 -j 8192 -N 4 %t2 | FileCheck %s --check-prefix=DATA
11
12!ELF
13FileHeader:
14  Class:           ELFCLASS64
15  Data:            ELFDATA2LSB
16  Type:            ET_EXEC
17  Machine:         EM_X86_64
18Sections:
19  - Name:            .text
20    Type:            SHT_PROGBITS
21    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
22    Address:         0x1000
23    AddressAlign:    0x1000
24    Size:            4096
25  - Name:            .text2
26    Type:            SHT_PROGBITS
27    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
28    Address:         0x2000
29    AddressAlign:    0x1000
30    Size:            4096
31    Content:         "DEADBEEF"
32  - Name:            .text3
33    Type:            SHT_PROGBITS
34    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
35    Address:         0x3000
36    AddressAlign:    0x1000
37    Size:            4096
38ProgramHeaders:
39  - Type:     PT_LOAD
40    Flags:    [ PF_X, PF_R ]
41    FirstSec: .text
42    LastSec:  .text3
43## TODO (grimar): without the following line (i.e. without an empty symbol table),
44## llvm-objcopy adds an empty .strtab section. It doesn't look correct.
45Symbols: []
46
47# Make sure that when we remove a section we overwrite it with zeros
48# DATA: {{^[^[:blank:]]+}} 00 00 00 00
49
50#CHECK: SectionHeaderCount: 4
51
52# CHECK: Sections [
53# CHECK:   Section {
54# CHECK-NEXT:     Index: 0
55# CHECK-NEXT:     Name:  (0)
56# CHECK-NEXT:     Type: SHT_NULL (0x0)
57# CHECK-NEXT:     Flags [ (0x0)
58# CHECK-NEXT:     ]
59# CHECK-NEXT:     Address: 0x0
60# CHECK-NEXT:     Offset:
61# CHECK-NEXT:     Size:
62# CHECK-NEXT:     Link: 0
63# CHECK-NEXT:     Info: 0
64# CHECK-NEXT:     AddressAlignment: 0
65# CHECK-NEXT:     EntrySize: 0
66# CHECK-NEXT:   }
67# CHECK-NEXT:   Section {
68# CHECK-NEXT:     Index: 1
69# CHECK-NEXT:     Name: .text
70# CHECK-NEXT:     Type: SHT_PROGBITS
71# CHECK-NEXT:     Flags [
72# CHECK-NEXT:       SHF_ALLOC
73# CHECK-NEXT:       SHF_EXECINSTR
74# CHECK-NEXT:     ]
75# CHECK-NEXT:     Address: 0x1000
76# CHECK-NEXT:     Offset: 0x1000
77# CHECK-NEXT:     Size:
78# CHECK-NEXT:     Link: 0
79# CHECK-NEXT:     Info: 0
80# CHECK-NEXT:     AddressAlignment: 4096
81# CHECK-NEXT:     EntrySize: 0
82# CHECK-NEXT:   }
83# CHECK-NEXT:   Section {
84# CHECK-NEXT:     Index: 2
85# CHECK-NEXT:     Name: .text3
86# CHECK-NEXT:     Type: SHT_PROGBITS (0x1)
87# CHECK-NEXT:     Flags [
88# CHECK-NEXT:       SHF_ALLOC
89# CHECK-NEXT:       SHF_EXECINSTR
90# CHECK-NEXT:     ]
91# CHECK-NEXT:     Address: 0x3000
92# CHECK-NEXT:     Offset: 0x3000
93# CHECK-NEXT:     Size:
94# CHECK-NEXT:     Link: 0
95# CHECK-NEXT:     Info: 0
96# CHECK-NEXT:     AddressAlignment: 4096
97# CHECK-NEXT:     EntrySize: 0
98# CHECK-NEXT:   }
99# CHECK-NEXT:   Section {
100# CHECK-NEXT:     Index: 3
101# CHECK-NEXT:     Name: .shstrtab
102# CHECK-NEXT:     Type: SHT_STRTAB (0x3)
103# CHECK-NEXT:     Flags [ (0x0)
104# CHECK-NEXT:     ]
105# CHECK-NEXT:     Address: 0x0
106# CHECK-NEXT:     Offset:
107# CHECK-NEXT:     Size:
108# CHECK-NEXT:     Link: 0
109# CHECK-NEXT:     Info: 0
110# CHECK-NEXT:     AddressAlignment: 1
111# CHECK-NEXT:     EntrySize: 0
112# CHECK-NEXT:   }
113# CHECK-NEXT: ]
114
115#CHECK:     ProgramHeaders [
116#CHECK-NEXT:  ProgramHeader {
117#CHECK-NEXT:    Type: PT_LOAD (0x1)
118#CHECK-NEXT:    Offset: 0x1000
119#CHECK-NEXT:    VirtualAddress: 0x0
120#CHECK-NEXT:    PhysicalAddress: 0x0
121#CHECK-NEXT:    FileSize: 12288
122#CHECK-NEXT:    MemSize: 12288
123#CHECK-NEXT:    Flags [ (0x5)
124#CHECK-NEXT:      PF_R (0x4)
125#CHECK-NEXT:      PF_X (0x1)
126#CHECK-NEXT:    ]
127#CHECK-NEXT:    Alignment: 4096
128#CHECK-NEXT:  }
129#CHECK-NEXT:]
130