xref: /llvm-project/llvm/test/tools/llvm-objcopy/COFF/remove-section.test (revision ecd6d7254e6452bd4663a473f46bd13bcf2bfeec)
155c81d42SFangrui Song# RUN: yaml2obj %s -o %t.in.o
2f9e1434eSMartin Storsjo#
3*ecd6d725SFangrui Song# RUN: llvm-objdump --section-headers %t.in.o | FileCheck %s --check-prefixes=SECTIONS-PRE
4f9e1434eSMartin Storsjo# RUN: llvm-objdump -t %t.in.o | FileCheck %s --check-prefixes=SYMBOLS-PRE
5f9e1434eSMartin Storsjo#
6f9e1434eSMartin Storsjo# RUN: llvm-objcopy -R .bss %t.in.o %t.remove-bss.o
7*ecd6d725SFangrui Song# RUN: llvm-objdump --section-headers %t.remove-bss.o | FileCheck %s --check-prefix=SECTIONS-REMOVE-BSS
8f9e1434eSMartin Storsjo# RUN: llvm-objdump -t %t.remove-bss.o | FileCheck %s --check-prefix=SYMBOLS-REMOVE-BSS
9f9e1434eSMartin Storsjo#
10f9e1434eSMartin Storsjo# RUN: llvm-objcopy --remove-section .bss %t.in.o %t.cmp.o
11f9e1434eSMartin Storsjo# RUN: cmp %t.remove-bss.o %t.cmp.o
12f9e1434eSMartin Storsjo#
13f9e1434eSMartin Storsjo# RUN: llvm-objcopy -R .text %t.in.o %t.remove-text.o
14*ecd6d725SFangrui Song# RUN: llvm-objdump --section-headers %t.remove-text.o | FileCheck %s --check-prefix=SECTIONS-REMOVE-TEXT
15f9e1434eSMartin Storsjo# RUN: llvm-objdump -t %t.remove-text.o | FileCheck %s --check-prefix=SYMBOLS-REMOVE-TEXT
16f9e1434eSMartin Storsjo#
17f9e1434eSMartin Storsjo# RUN: not llvm-objcopy -R .comdat %t.in.o %t.remove-comdat.o 2>&1 | FileCheck %s --check-prefix=ERROR-RELOC
18f9e1434eSMartin Storsjo#
19f9e1434eSMartin Storsjo# RUN: llvm-objcopy -R .text -R .comdat %t.in.o %t.remove-text-comdat.o
20*ecd6d725SFangrui Song# RUN: llvm-objdump --section-headers %t.remove-text-comdat.o | FileCheck %s --check-prefix=SECTIONS-REMOVE-TEXT-COMDAT
21f9e1434eSMartin Storsjo# RUN: llvm-objdump -t %t.remove-text-comdat.o | FileCheck %s --check-prefix=SYMBOLS-REMOVE-TEXT-COMDAT
22f9e1434eSMartin Storsjo#
23f9e1434eSMartin Storsjo#
24f9e1434eSMartin Storsjo# SECTIONS-PRE: Sections:
25f9e1434eSMartin Storsjo# SECTIONS-PRE-NEXT: Idx Name
26f9e1434eSMartin Storsjo# SECTIONS-PRE-NEXT: 0 .text
27f9e1434eSMartin Storsjo# SECTIONS-PRE-NEXT: 1 .bss
28f9e1434eSMartin Storsjo# SECTIONS-PRE-NEXT: 2 .comdat
29f9e1434eSMartin Storsjo# SECTIONS-PRE-NEXT: 3 .associative
30f9e1434eSMartin Storsjo# SECTIONS-PRE-EMPTY:
31f9e1434eSMartin Storsjo#
32f9e1434eSMartin Storsjo# SYMBOLS-PRE: SYMBOL TABLE:
33f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec -1){{.*}} @feat.00
34f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 1){{.*}} .text
35f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: AUX scnlen {{.*}} assoc 1 comdat 0
36f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 2){{.*}} .bss
37f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: AUX scnlen {{.*}} assoc 2 comdat 0
38f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 4){{.*}} .associative
39f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: AUX scnlen {{.*}} assoc 3 comdat 5
40f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 3){{.*}} .comdat
41f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: AUX scnlen {{.*}} assoc 3 comdat 2
42f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 3){{.*}} foo
43f9e1434eSMartin Storsjo# SYMBOLS-PRE-NEXT: {{.*}}(sec 1){{.*}} main
44f9e1434eSMartin Storsjo# SYMBOLS-PRE-EMPTY:
45f9e1434eSMartin Storsjo#
46f9e1434eSMartin Storsjo#
47f9e1434eSMartin Storsjo# Removing the .bss section removes one symbol and its aux symbol,
48f9e1434eSMartin Storsjo# and updates the section indices in symbols pointing to later
49f9e1434eSMartin Storsjo# symbols, including the aux section defintitions.
50f9e1434eSMartin Storsjo#
51f9e1434eSMartin Storsjo# Testing that the absolute symbol @feat.00 survives the section number
52f9e1434eSMartin Storsjo# mangling.
53f9e1434eSMartin Storsjo#
54f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS: Sections:
55f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS-NEXT: Idx Name
56f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS-NEXT: 0 .text
57f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS-NEXT: 1 .comdat
58f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS-NEXT: 2 .associative
59f9e1434eSMartin Storsjo# SECTIONS-REMOVE-BSS-EMPTY:
60f9e1434eSMartin Storsjo#
61f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS: SYMBOL TABLE:
62f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec -1){{.*}} @feat.00
63f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec 1){{.*}} .text
64f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: AUX scnlen {{.*}} assoc 1 comdat 0
65f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec 3){{.*}} .associative
66f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: AUX scnlen {{.*}} assoc 2 comdat 5
67f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec 2){{.*}} .comdat
68f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: AUX scnlen {{.*}} assoc 2 comdat 2
69f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec 2){{.*}} foo
70f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-NEXT: {{.*}}(sec 1){{.*}} main
71f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-BSS-EMPTY:
72f9e1434eSMartin Storsjo#
73f9e1434eSMartin Storsjo#
74f9e1434eSMartin Storsjo# Removing the .text section is ok and just removes the external symbol
75f9e1434eSMartin Storsjo# referring to it.
76f9e1434eSMartin Storsjo#
77f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT: Sections:
78f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-NEXT: Idx Name
79f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-NEXT: 0 .bss
80f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-NEXT: 1 .comdat
81f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-NEXT: 2 .associative
82f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-EMPTY:
83f9e1434eSMartin Storsjo#
84f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT: SYMBOL TABLE:
85f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: {{.*}}(sec -1){{.*}} @feat.00
86f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: {{.*}}(sec 1){{.*}} .bss
87f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: AUX scnlen {{.*}} assoc 1 comdat 0
88f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: {{.*}}(sec 3){{.*}} .associative
89f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: AUX scnlen {{.*}} assoc 2 comdat 5
90f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: {{.*}}(sec 2){{.*}} .comdat
91f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: AUX scnlen {{.*}} assoc 2 comdat 2
92f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-NEXT: {{.*}}(sec 2){{.*}} foo
93f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-EMPTY:
94f9e1434eSMartin Storsjo#
95f9e1434eSMartin Storsjo#
96f9e1434eSMartin Storsjo# Removing the .comdat section fails, since the .text section has relocations
97f9e1434eSMartin Storsjo# against it.
98f9e1434eSMartin Storsjo#
995316a0d2SJames Henderson# ERROR-RELOC: relocation target 'foo' ({{.*}}) not found
100f9e1434eSMartin Storsjo#
101f9e1434eSMartin Storsjo#
102f9e1434eSMartin Storsjo# Removing the .comdat section and .text (with a relocation against .comdat)
103f9e1434eSMartin Storsjo# works, as it also removes the .associative section transitively.
104f9e1434eSMartin Storsjo#
105f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-COMDAT: Sections:
106f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-COMDAT-NEXT: Idx Name
107f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-COMDAT-NEXT: 0 .bss
108f9e1434eSMartin Storsjo# SECTIONS-REMOVE-TEXT-COMDAT-EMPTY:
109f9e1434eSMartin Storsjo#
110f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-COMDAT: SYMBOL TABLE:
111f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-COMDAT-NEXT: {{.*}}(sec -1){{.*}} @feat.00
112f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-COMDAT-NEXT: {{.*}}(sec 1){{.*}} .bss
113f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-COMDAT-NEXT: AUX scnlen {{.*}} assoc 1 comdat 0
114f9e1434eSMartin Storsjo# SYMBOLS-REMOVE-TEXT-COMDAT-EMPTY:
115f9e1434eSMartin Storsjo
116f9e1434eSMartin Storsjo--- !COFF
117f9e1434eSMartin Storsjoheader:
118f9e1434eSMartin Storsjo  Machine:         IMAGE_FILE_MACHINE_AMD64
119f9e1434eSMartin Storsjo  Characteristics: [  ]
120f9e1434eSMartin Storsjosections:
121f9e1434eSMartin Storsjo  - Name:            .text
122f9e1434eSMartin Storsjo    Characteristics: [  ]
123f9e1434eSMartin Storsjo    Alignment:       4
124f9e1434eSMartin Storsjo    SectionData:     488B0500000000C3
125f9e1434eSMartin Storsjo    Relocations:
126f9e1434eSMartin Storsjo      - VirtualAddress:  3
127f9e1434eSMartin Storsjo        SymbolName:      foo
128f9e1434eSMartin Storsjo        Type:            IMAGE_REL_AMD64_REL32
129f9e1434eSMartin Storsjo  - Name:            .bss
130f9e1434eSMartin Storsjo    Characteristics: [  ]
131f9e1434eSMartin Storsjo    Alignment:       4
132f9e1434eSMartin Storsjo    SectionData:     ''
133f9e1434eSMartin Storsjo  - Name:            .comdat
134f9e1434eSMartin Storsjo    Characteristics: [ IMAGE_SCN_LNK_COMDAT ]
135f9e1434eSMartin Storsjo    Alignment:       1
136f9e1434eSMartin Storsjo    SectionData:     '2A000000'
137f9e1434eSMartin Storsjo  - Name:            .associative
138f9e1434eSMartin Storsjo    Characteristics: [ IMAGE_SCN_LNK_COMDAT ]
139f9e1434eSMartin Storsjo    Alignment:       1
140f9e1434eSMartin Storsjo    SectionData:     '0000000000000000'
141f9e1434eSMartin Storsjosymbols:
142f9e1434eSMartin Storsjo  - Name:            '@feat.00'
143f9e1434eSMartin Storsjo    Value:           0
144f9e1434eSMartin Storsjo    SectionNumber:   -1
145f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
146f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
147f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_STATIC
148f9e1434eSMartin Storsjo  - Name:            .text
149f9e1434eSMartin Storsjo    Value:           0
150f9e1434eSMartin Storsjo    SectionNumber:   1
151f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
152f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
153f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_STATIC
154f9e1434eSMartin Storsjo    SectionDefinition:
155f9e1434eSMartin Storsjo      Length:          8
156f9e1434eSMartin Storsjo      NumberOfRelocations: 1
157f9e1434eSMartin Storsjo      NumberOfLinenumbers: 0
158f9e1434eSMartin Storsjo      CheckSum:        583624169
159f9e1434eSMartin Storsjo      Number:          1
160f9e1434eSMartin Storsjo  - Name:            .bss
161f9e1434eSMartin Storsjo    Value:           0
162f9e1434eSMartin Storsjo    SectionNumber:   2
163f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
164f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
165f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_STATIC
166f9e1434eSMartin Storsjo    SectionDefinition:
167f9e1434eSMartin Storsjo      Length:          0
168f9e1434eSMartin Storsjo      NumberOfRelocations: 0
169f9e1434eSMartin Storsjo      NumberOfLinenumbers: 0
170f9e1434eSMartin Storsjo      CheckSum:        0
171f9e1434eSMartin Storsjo      Number:          2
172f9e1434eSMartin Storsjo  - Name:            .associative
173f9e1434eSMartin Storsjo    Value:           0
174f9e1434eSMartin Storsjo    SectionNumber:   4
175f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
176f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
177f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_STATIC
178f9e1434eSMartin Storsjo    SectionDefinition:
179f9e1434eSMartin Storsjo      Length:          8
180f9e1434eSMartin Storsjo      NumberOfRelocations: 0
181f9e1434eSMartin Storsjo      NumberOfLinenumbers: 0
182f9e1434eSMartin Storsjo      CheckSum:        0
183f9e1434eSMartin Storsjo      Number:          3
184f9e1434eSMartin Storsjo      Selection:       IMAGE_COMDAT_SELECT_ASSOCIATIVE
185f9e1434eSMartin Storsjo  - Name:            .comdat
186f9e1434eSMartin Storsjo    Value:           0
187f9e1434eSMartin Storsjo    SectionNumber:   3
188f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
189f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
190f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_STATIC
191f9e1434eSMartin Storsjo    SectionDefinition:
192f9e1434eSMartin Storsjo      Length:          4
193f9e1434eSMartin Storsjo      NumberOfRelocations: 0
194f9e1434eSMartin Storsjo      NumberOfLinenumbers: 0
195f9e1434eSMartin Storsjo      CheckSum:        3482275674
196f9e1434eSMartin Storsjo      Number:          3
197f9e1434eSMartin Storsjo      Selection:       IMAGE_COMDAT_SELECT_ANY
198f9e1434eSMartin Storsjo  - Name:            foo
199f9e1434eSMartin Storsjo    Value:           0
200f9e1434eSMartin Storsjo    SectionNumber:   3
201f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
202f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
203f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
204f9e1434eSMartin Storsjo  - Name:            main
205f9e1434eSMartin Storsjo    Value:           0
206f9e1434eSMartin Storsjo    SectionNumber:   1
207f9e1434eSMartin Storsjo    SimpleType:      IMAGE_SYM_TYPE_NULL
208f9e1434eSMartin Storsjo    ComplexType:     IMAGE_SYM_DTYPE_NULL
209f9e1434eSMartin Storsjo    StorageClass:    IMAGE_SYM_CLASS_EXTERNAL
210f9e1434eSMartin Storsjo...
211