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