[Instrumentation] Fix a warning
[llvm-project.git] / llvm / test / tools / llvm-nm / XCOFF / export-symbols.test
blobcea2336befe0ed6df5def11c8703a246766ccec4
1 ## Test the "--export-symbols" option.
2 ## The option merges all the output of input files, sorts and prints out unique symbols from the input files.
4 # RUN: yaml2obj --docnum=1 -DFLAG=0x0002 %s -o %t1.o
5 # RUN: yaml2obj --docnum=2 -DFLAG=0x0002 %s -o %t2.o
6 # RUN: yaml2obj --docnum=2 -DFLAG=0x0002 -DSECT=26 %s -o %t2_invalid.o
8 ## Test the following cases:
9 ## Do not export global symbols beginning with "__sinit" , "__sterm" , "." , "(". or regular expression "^__[0-9]+__".
10 ## Do not export hidden and internal symbols.
11 ## Remove name prefixes of global symbols beginning with "__tf1" and "__tf9".
12 # RUN: llvm-nm --export-symbols %t1.o | FileCheck %s --check-prefixes=COMMON,WEAK,RSRC --implicit-check-not={{.}}
14 ## Show that weak symbols are not exported when using the "--no-weak" option.
15 # RUN: llvm-nm --export-symbols --no-weak %t1.o | FileCheck --check-prefixes=COMMON,RSRC  %s --implicit-check-not={{.}}
17 ## Show that only unique symbols (with a different name or visibility) are exported.
18 ## RUN: llvm-nm --export-symbols %t1.o %t2.o | FileCheck --check-prefixes=COMMON,WEAK,OBJ2,RSRC %s --implicit-check-not={{.}}
20 ## Show that __rsrc symbols are not exported when using the "--no-rsrc" option.
21 # RUN: llvm-nm --export-symbols --no-rsrc %t1.o  | FileCheck --check-prefixes=COMMON,WEAK %s --implicit-check-not={{.}}
23 # COMMON:      023__
24 # COMMON-NEXT: __023
25 # COMMON-NEXT: __02er02__
26 # COMMON-NEXT: ____
27 # RSRC-NEXT:   __rsrc
28 # COMMON-NEXT: __rsrc export
29 # COMMON-NEXT: __tf2value
30 # COMMON-NEXT: export_protected_var export
31 # COMMON-NEXT: export_protected_var protected
32 # OBJ2-NEXT:   export_var_in_sec_obj export
33 # COMMON-NEXT: protected_var protected
34 # OBJ2-NEXT:   protected_var_in_sec_obj protected
35 # COMMON-NEXT: tf1value
36 # COMMON-NEXT: tf9value
37 # OBJ2-NEXT:   var1_in_sec_obj
38 # WEAK-NEXT:   weak_func
40 ## Test the behavior of the symbol reference section.
41 # RUN: llvm-nm --export-symbols --no-rsrc %t2_invalid.o 2>&1 | \
42 # RUN:   FileCheck -DFILE=%t2_invalid.o --check-prefixes=INVALID %s
44 # INVALID:      llvm-nm{{(\.exe)?}}: warning: [[FILE]]: for symbol with index 8: the section index (26) is invalid
45 # INVALID-NEXT: export_protected_var export
46 # INVALID-NEXT: export_protected_var protected
47 # INVALID-NEXT: protected_var_in_sec_obj protected
48 # INVALID-NEXT: var1_in_sec_obj
50 ## Show that symbols in shared object files are not exported.
51 ## Generate XCOFF shared object file.
52 # RUN: yaml2obj -DFLAG=0x2000 --docnum=2 %s -o %t_shared.o
53 # RUN: llvm-nm --export-symbols %t_shared.o | count 0
55 ## Test that llvm-nm ignores AIX linker import files when using --export-symbols. These start with "#!".
56 # RUN: echo -e "#!\n bar\n foo " > %t_imp.txt
57 # RUN: llvm-nm --export-symbols %t_imp.txt 2>&1 | count 0
59 --- !XCOFF
60 FileHeader:
61   MagicNumber:       0x1DF
62   Flags:             [[FLAG]]
63 AuxiliaryHeader:
64   Magic:                 0x10B
65   Version:               0x2
66 Sections:
67   - Name:            .text
68     Flags:           [ STYP_TEXT ]
69   - Name:            .data
70     Flags:           [ STYP_DATA ]
71   - Name:            .bss
72     Flags:           [ STYP_DATA ]
73   - Name:            .debug
74     Flags:           [ STYP_DEBUG ]
75 Symbols:
76   - Name:            export_protected_var
77     Section:         .data
78 ## Exported visibility.
79     Type:            0x4000
80     StorageClass:    C_EXT
81     AuxEntries:
82      - Type:                   AUX_CSECT
83        SymbolAlignmentAndType: 0x09
84        StorageMappingClass:    XMC_RW
85   - Name:            export_protected_var
86     Section:         .data
87 ## Protected visibility.
88     Type:            0x3000
89     StorageClass:    C_EXT
90     AuxEntries:
91      - Type:                   AUX_CSECT
92        SymbolAlignmentAndType: 0x09
93        StorageMappingClass:    XMC_RW
94   - Name:            __rsrc
95     Section:         .data
96 ## No visibility.
97     Type:            0x0
98     StorageClass:    C_EXT
99     AuxEntries:
100      - Type:                   AUX_CSECT
101        SymbolAlignmentAndType: 0x09
102        StorageMappingClass:    XMC_RW
103        SectionOrLength:        0x4
104   - Name:            __sinit
105     Section:         .data
106     Type:            0x0
107     StorageClass:    C_EXT
108     AuxEntries:
109      - Type:                   AUX_CSECT
110        SymbolAlignmentAndType: 0x9
111        StorageMappingClass:    XMC_RW
112        SectionOrLength:        0xC
113   - Name:            __sterm
114     Section:         .data
115     Type:            0x0
116     StorageClass:    C_EXT
117     AuxEntries:
118      - Type:                   AUX_CSECT
119        SymbolAlignmentAndType: 0x09
120        StorageMappingClass:    XMC_RW
121        SectionOrLength:        0xC
122   - Name:            .func
123     Section:         .text
124     Type:            0x20
125     StorageClass:    C_EXT
126     AuxEntries:
127      - Type:                   AUX_CSECT
128        SymbolAlignmentAndType: 0x02
129        StorageMappingClass:    XMC_PR
130   - Name:            (func)
131     Section:         .data
132     Type:            0x0
133     StorageClass:    C_EXT
134     AuxEntries:
135      - Type:                   AUX_CSECT
136        SymbolAlignmentAndType: 0x09
137        StorageMappingClass:    XMC_RW
138        SectionOrLength:        0xC
139   - Name:            __023__
140     Section:         .data
141     Type:            0x0
142     StorageClass:    C_EXT
143     AuxEntries:
144      - Type:                   AUX_CSECT
145        SymbolAlignmentAndType: 0x09
146        StorageMappingClass:    XMC_RW
147        SectionOrLength:        0x4
148   - Name:            __tf1_tf1value
149     Section:         .text
150     Type:            0x00
151     StorageClass:    C_EXT
152     AuxEntries:
153      - Type:                   AUX_CSECT
154        SymbolAlignmentAndType: 0x09
155        StorageMappingClass:    XMC_RO
156   - Name:            __tf9_12345678tf9value
157     Section:         .data
158     Type:            0x0
159     StorageClass:    C_EXT
160     AuxEntries:
161      - Type:                   AUX_CSECT
162        SymbolAlignmentAndType: 0x09
163        StorageMappingClass:    XMC_RW
164   - Name:            __tf2value
165     Section:         .data
166     Type:            0x0
167     StorageClass:    C_HIDEXT
168     AuxEntries:
169      - Type:                   AUX_CSECT
170        SymbolAlignmentAndType: 0x21
171        StorageMappingClass:    XMC_TC
172   - Name:            __tf2value
173     Section:         .data
174     Type:            0x0
175     StorageClass:    C_EXT
176     AuxEntries:
177      - Type:                   AUX_CSECT
178        SymbolAlignmentAndType: 0x09
179        StorageMappingClass:    XMC_RW
180   - Name:            weak_func
181     Section:         .data
182     Type:            0x0
183     StorageClass:    C_WEAKEXT
184     AuxEntries:
185      - Type:                   AUX_CSECT
186        SymbolAlignmentAndType: 0x09
187        StorageMappingClass:    XMC_RW
188   - Name:            protected_var
189     Section:         .bss
190     Type:            0x3000
191     StorageClass:    C_EXT
192     AuxEntries:
193      - Type:                   AUX_CSECT
194        SymbolAlignmentAndType: 0x02
195        StorageMappingClass:    XMC_RW
196   - Name:            hidden_var
197     Section:         .data
198 ## Hidden visibility.
199     Type:            0x2000
200     StorageClass:    C_EXT
201     AuxEntries:
202      - Type:                   AUX_CSECT
203        SymbolAlignmentAndType: 0x09
204        StorageMappingClass:    XMC_RW
205   - Name:            internal_var
206     Section:         .data
207 ## Internal visibility.
208     Type:            0x1000
209     StorageClass:    C_EXT
210     AuxEntries:
211      - Type:                   AUX_CSECT
212        SymbolAlignmentAndType: 0x09
213        StorageMappingClass:    XMC_RW
214 ## A symbol that is neither text, nor data, nor bss.
215   - Name:            debug
216     Section:         .debug
217 ## Empty symbol name.
218   - Name:            ""
219     Section:         .data
220     StorageClass:    C_EXT
221     AuxEntries:
222      - Type:                   AUX_CSECT
223        SymbolAlignmentAndType: 0x09
224        StorageMappingClass:    XMC_TC
225   - Name:            undef_var
226     SectionIndex:    0
227     AuxEntries:
228      - Type:                   AUX_CSECT
229        SymbolAlignmentAndType: 0x20
230        StorageMappingClass:    XMC_UA
231 ## Do not export not global symbol.
232   - Name:            hidext_var
233     Section:         .data
234 ## Protected visibility.
235     Type:            0x3000
236     StorageClass:    C_HIDEXT
237     AuxEntries:
238      - Type:                   AUX_CSECT
239        SymbolAlignmentAndType: 0x09
240        StorageMappingClass:    XMC_RW
241 ## Symbol should not be filtered out by option --no-rsrc.
242   - Name:            __tf1___rsrc
243     Section:         .data
244     Type:            0x4000
245     StorageClass:    C_EXT
246     AuxEntries:
247      - Type:                   AUX_CSECT
248        SymbolAlignmentAndType: 0x09
249        StorageMappingClass:    XMC_RW
250        SectionOrLength:        0x4
251 ## Following symbols should not be filtered out by regular expression "^__[0-9]+__".
252   - Name:            __023
253     Section:         .data
254     Type:            0x0
255     StorageClass:    C_EXT
256     AuxEntries:
257      - Type:                   AUX_CSECT
258        SymbolAlignmentAndType: 0x09
259        StorageMappingClass:    XMC_RW
260        SectionOrLength:        0x4
261   - Name:            023__
262     Section:         .data
263     Type:            0x0
264     StorageClass:    C_EXT
265     AuxEntries:
266      - Type:                   AUX_CSECT
267        SymbolAlignmentAndType: 0x09
268        StorageMappingClass:    XMC_RW
269        SectionOrLength:        0x4
270   - Name:            ____
271     Section:         .data
272     Type:            0x0
273     StorageClass:    C_EXT
274     AuxEntries:
275      - Type:                   AUX_CSECT
276        SymbolAlignmentAndType: 0x09
277        StorageMappingClass:    XMC_RW
278        SectionOrLength:        0x4
279   - Name:            __02er02__
280     Section:         .data
281     Type:            0x0
282     StorageClass:    C_EXT
283     AuxEntries:
284      - Type:                   AUX_CSECT
285        SymbolAlignmentAndType: 0x09
286        StorageMappingClass:    XMC_RW
287        SectionOrLength:        0x4
289 --- !XCOFF
290 FileHeader:
291   MagicNumber:       0x1DF
292   Flags:             [[FLAG]]
293 AuxiliaryHeader:
294   Magic:                 0x10B
295   Version:               0x2
296   TextSectionSize:       0x280
297   DataSectionSize:       0x90
298 Sections:
299   - Name:            .text
300     Flags:           [ STYP_TEXT ]
301   - Name:            .data
302     Flags:           [ STYP_DATA ]
303 Symbols:
304   - Name:            export_protected_var
305     Section:         .data
306     Type:            0x4000
307     StorageClass:    C_EXT
308     AuxEntries:
309      - Type:                   AUX_CSECT
310        SymbolAlignmentAndType: 0x09
311        StorageMappingClass:    XMC_RW
312   - Name:            export_protected_var
313     Section:         .data
314     Type:            0x3000
315     StorageClass:    C_EXT
316     AuxEntries:
317      - Type:                   AUX_CSECT
318        SymbolAlignmentAndType: 0x09
319        StorageMappingClass:    XMC_RW
320   - Name:            var1_in_sec_obj
321     Section:         .data
322     Type:            0x0
323     StorageClass:    C_EXT
324     AuxEntries:
325      - Type:                   AUX_CSECT
326        SymbolAlignmentAndType: 0x09
327        StorageMappingClass:    XMC_RW
328        SectionOrLength:        0x4
329   - Name:            protected_var_in_sec_obj
330     Section:         .data
331     Type:            0x3000
332     StorageClass:    C_EXT
333     AuxEntries:
334      - Type:                   AUX_CSECT
335        SymbolAlignmentAndType: 0x09
336        StorageMappingClass:    XMC_RW
337   - Name:            export_var_in_sec_obj
338     SectionIndex:    [[SECT=2]]
339     Type:            0x4000
340     StorageClass:    C_EXT
341     AuxEntries:
342      - Type:                   AUX_CSECT
343        SymbolAlignmentAndType: 0x09
344        StorageMappingClass:    XMC_RW