xref: /llvm-project/llvm/test/Object/nm-trivial-object.test (revision 55c81d4282c5da0189711261a11537bc8a7fe85c)
1# RUN: yaml2obj %p/Inputs/COFF/i386.yaml | llvm-nm -a -S - \
2# RUN:         | FileCheck %s -check-prefix COFF32
3
4# COFF32: 00000000 d .data
5# COFF32-NEXT: 00000000 t .text
6# COFF32-NEXT: 00000000 d L_.str
7# COFF32-NEXT:          U _SomeOtherFunction
8# COFF32-NEXT: 00000000 T _main
9# COFF32-NEXT:          U _puts
10
11# RUN: yaml2obj %p/Inputs/COFF/x86-64.yaml | llvm-nm -a -S - \
12# RUN:         | FileCheck %s -check-prefix COFF64
13
14# COFF64: 00000000 d .data
15# COFF64-NEXT: 00000000 t .text
16# COFF64-NEXT: 00000000 r ??__Ex@@YAXXZ
17# COFF64-NEXT: 00000000 d L.str
18# COFF64-NEXT:          U SomeOtherFunction
19# COFF64-NEXT: 00000000 T main
20# COFF64-NEXT:          U puts
21
22# RUN: llvm-nm %p/Inputs/trivial-object-test.wasm \
23# RUN:         | FileCheck %s -check-prefix WASM
24
25# WASM:      00000000 d .L.str
26# WASM-NEXT: 00000019 t .LSomeOtherFunction_bitcast
27# WASM-NEXT:          U SomeOtherFunction
28# WASM-NEXT: 00000001 T main
29# WASM-NEXT:          U puts
30# WASM-NEXT: 00000010 D var
31
32# RUN: yaml2obj --docnum=1 %s -o %t.elf-i386
33
34--- !ELF
35FileHeader:
36  Class:   ELFCLASS32
37  Data:    ELFDATA2LSB
38  Type:    ET_REL
39  Machine: EM_386
40Sections:
41  - Name:  .text
42    Type:  SHT_PROGBITS
43    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
44Symbols:
45  - Name:    main
46    Type:    STT_FUNC
47    Section: .text
48    Binding: STB_GLOBAL
49    Size:    0x0000000000000024
50  - Name:    SomeOtherFunction
51    Binding: STB_GLOBAL
52  - Name:    puts
53    Binding: STB_GLOBAL
54
55# RUN: llvm-nm %t.elf-i386 | FileCheck %s -check-prefix=ELF
56
57# ELF-NOT: U
58# ELF:          U SomeOtherFunction
59# ELF: 00000000 T main
60# ELF:          U puts
61
62# RUN: llvm-nm -o %t.elf-i386 | FileCheck %s -DFILE=%t.elf-i386 -check-prefix=ELF-o
63
64# RUN: llvm-nm %t.elf-i386 -S | FileCheck %s -check-prefix ELF-SIZE
65
66# ELF-SIZE:                        U SomeOtherFunction
67# ELF-SIZE-NEXT: 00000000 00000024 T main
68# ELF-SIZE-NEXT:                   U puts
69
70# ELF-o-NOT: U
71# ELF-o: [[FILE]]:          U SomeOtherFunction
72# ELF-o: [[FILE]]: 00000000 T main
73# ELF-o: [[FILE]]:          U puts
74
75# RUN: llvm-nm -u %t.elf-i386 | FileCheck %s -check-prefix ELF-u
76
77# ELF-u: U SomeOtherFunction
78# ELF-u: U puts
79
80## Test different ELF symbols for 64-bit platform.
81
82# RUN: yaml2obj --docnum=2 %s -o %t.elf-x86-64
83# RUN: llvm-nm %t.elf-x86-64 | FileCheck %s -check-prefix ELF64
84
85# ELF64:                  U SomeOtherFunction
86# ELF64: 0000000000000123 a absSym1
87# ELF64: 0000000000000123 A absSym2
88# ELF64: 0000000000002000 D dataSym1
89# ELF64: 0000000000002004 D dataSym2
90# ELF64: 0000000000001000 T textSym1
91# ELF64: 0000000000001004 T textSym2
92# ELF64:                  U undefinedSym
93# ELF64:                  v weakObject1
94# ELF64: 0000000000001000 V weakObject2
95# ELF64:                  w weakSym1
96# ELF64: 0000000000001000 W weakSym2
97
98--- !ELF
99FileHeader:
100  Class:   ELFCLASS64
101  Data:    ELFDATA2LSB
102  Type:    ET_REL
103  Machine: EM_X86_64
104Sections:
105  - Name:  .text
106    Type:  SHT_PROGBITS
107    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
108    Address: 0x1000
109  - Name:  .data
110    Type:  SHT_PROGBITS
111    Flags: [ SHF_ALLOC, SHF_WRITE ]
112    Address: 0x2000
113Symbols:
114  - Name:    absSym1
115    Index:   SHN_ABS
116    Value:   0x0000000000000123
117  - Name:    absSym2
118    Index:   SHN_ABS
119    Binding: STB_GLOBAL
120    Value:   0x0000000000000123
121  - Name:    SomeOtherFunction
122    Binding: STB_GLOBAL
123  - Name:    undefinedSym
124    Binding: STB_GLOBAL
125  - Name:    weakObject1
126    Type:    STT_OBJECT
127    Binding: STB_WEAK
128  - Name:    weakObject2
129    Type:    STT_OBJECT
130    Section: .text
131    Binding: STB_WEAK
132  - Name:    weakSym1
133    Binding: STB_WEAK
134  - Name:    weakSym2
135    Section: .text
136    Binding: STB_WEAK
137  - Name:    dataSym1
138    Type:    STT_OBJECT
139    Section: .data
140    Binding: STB_GLOBAL
141    Value:   0x0000000000000000
142  - Name:    dataSym2
143    Type:    STT_OBJECT
144    Section: .data
145    Binding: STB_GLOBAL
146    Value:   0x0000000000000004
147  - Name:    textSym1
148    Type:    STT_FUNC
149    Section: .text
150    Binding: STB_GLOBAL
151    Value:   0x0000000000000000
152  - Name:    textSym2
153    Type:    STT_FUNC
154    Section: .text
155    Binding: STB_GLOBAL
156    Value:   0x0000000000000004
157
158## Test llvm-nm shows all symbols with -a.
159
160# RUN: yaml2obj --docnum=3 %s -o %t-a.elf-x86-64
161# RUN: llvm-nm -a %t-a.elf-x86-64 | FileCheck %s -check-prefix ELF64-a
162
163# ELF64-a:      00000000 b .bss
164# ELF64-a-NEXT: 00000000 n .comment
165# ELF64-a-NEXT: 00000000 d .data
166# ELF64-a-NEXT: 00000000 N .debug_sec
167# ELF64-a-NEXT: 00000000 t .text
168# ELF64-a-NEXT: 00000000 a fileSym
169# ELF64-a-NEXT: 00000014 T regularSym
170# ELF64-a-NEXT:          U undefSym
171
172--- !ELF
173FileHeader:
174  Class:   ELFCLASS32
175  Data:    ELFDATA2LSB
176  Type:    ET_REL
177  Machine: EM_386
178Sections:
179  - Name:  .rodata
180    Type:  SHT_PROGBITS
181    Flags: [ SHF_ALLOC ]
182  - Name:  .text
183    Type:  SHT_PROGBITS
184    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
185  - Name:  .data
186    Type:  SHT_PROGBITS
187    Flags: [ SHF_WRITE, SHF_ALLOC ]
188  - Name:  .bss
189    Type:  SHT_NOBITS
190    Flags: [ SHF_WRITE, SHF_ALLOC ]
191  - Name:  .debug_sec
192    Type:  SHT_PROGBITS
193  - Name:  .comment
194    Type:  SHT_PROGBITS
195Symbols:
196  - Name:    fileSym
197    Type:    STT_FILE
198    Index:   SHN_ABS
199  - Name:    .text
200    Type:    STT_SECTION
201    Section: .text
202  - Name:    .data
203    Type:    STT_SECTION
204    Section: .data
205  - Name:    .bss
206    Type:    STT_SECTION
207    Section: .bss
208  - Name:    .debug_sec
209    Type:    STT_SECTION
210    Section: .debug_sec
211  - Name:    .comment
212    Type:    STT_SECTION
213    Section: .comment
214  - Name:    undefSym
215    Binding: STB_GLOBAL
216  - Name:    regularSym
217    Type:    STT_FUNC
218    Section: .text
219    Binding: STB_GLOBAL
220    Value:   0x0000000000000014
221
222## Test that we drop the thumb bit only from function addresses.
223
224# RUN: yaml2obj --docnum=4 %s -o %t.elf-arm32
225# RUN: llvm-nm %t.elf-arm32 | FileCheck %s -check-prefix ELF-THUMB
226
227# ELF-THUMB: 00000000 t func
228# ELF-THUMB: 00000003 t sym
229
230--- !ELF
231FileHeader:
232  Class:   ELFCLASS32
233  Data:    ELFDATA2LSB
234  Type:    ET_REL
235  Machine: EM_ARM
236Sections:
237  - Name:  .text
238    Type:  SHT_PROGBITS
239    Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
240Symbols:
241  - Name:    func
242    Type:    STT_FUNC
243    Section: .text
244    Value:   0x0000000000000001
245  - Name:    sym
246    Section: .text
247    Value:   0x0000000000000003
248
249# RUN: llvm-nm %p/Inputs/trivial-object-test.macho-i386 \
250# RUN:         | FileCheck %s -check-prefix macho
251
252# macho:          U _SomeOtherFunction
253# macho: 00000000 T _main
254# macho:          U _puts
255
256# RUN: llvm-nm -U %p/Inputs/trivial-object-test.macho-i386 \
257# RUN:         | FileCheck %s -check-prefix macho-U
258
259# macho-U-NOT:          U _SomeOtherFunction
260# macho-U: 00000000 T _main
261# macho-U-NOT:          U _puts
262
263# RUN: llvm-nm %p/Inputs/trivial-object-test.macho-x86-64 \
264# RUN:         | FileCheck %s -check-prefix macho64
265
266# macho64: 0000000000000028 s L_.str
267# macho64:                  U _SomeOtherFunction
268# macho64: 0000000000000000 T _main
269# macho64:                  U _puts
270
271# RUN: llvm-nm %p/Inputs/macho-text-data-bss.macho-x86_64 \
272# RUN:         | FileCheck %s -check-prefix macho-tdb
273
274# macho-tdb: 0000000000000030 s EH_frame0
275# macho-tdb: 0000000000000070 b _b
276# macho-tdb: 000000000000000c D _d
277# macho-tdb: 0000000000000000 T _t
278# macho-tdb: 0000000000000048 S _t.eh
279
280# RUN: llvm-nm -j %p/Inputs/macho-text-data-bss.macho-x86_64 \
281# RUN:         | FileCheck %s -check-prefix macho-j
282
283# macho-j: EH_frame0
284# macho-j: _b
285# macho-j: _d
286# macho-j: _t
287# macho-j: _t.eh
288
289# RUN: llvm-nm -r %p/Inputs/macho-text-data-bss.macho-x86_64 \
290# RUN:         | FileCheck %s -check-prefix macho-r
291
292# macho-r: 0000000000000048 S _t.eh
293# macho-r-NEXT: 0000000000000000 T _t
294# macho-r-NEXT: 000000000000000c D _d
295# macho-r-NEXT: 0000000000000070 b _b
296# macho-r-NEXT: 0000000000000030 s EH_frame0
297
298# RUN: llvm-nm %p/Inputs/macho-text-data-bss.macho-x86_64 -s __DATA __data \
299# RUN:         | FileCheck %s -check-prefix macho-s
300
301# macho-s: 000000000000000c D _d
302# macho-s-NOT: 0000000000000048 S _t.eh
303# macho-s-NOT: 0000000000000000 T _t
304# macho-s-NOT: 0000000000000070 b _b
305# macho-s-NOT: 0000000000000030 s EH_frame0
306
307# RUN: llvm-nm -x %p/Inputs/macho-text-data-bss.macho-x86_64 \
308# RUN:         | FileCheck %s -check-prefix macho-x
309
310# macho-x: 0000000000000030 0e 05 0000 00000010 EH_frame0
311# macho-x: 0000000000000070 0e 03 0000 0000000d _b
312# macho-x: 000000000000000c 0f 02 0000 00000004 _d
313# macho-x: 0000000000000000 0f 01 0000 00000001 _t
314# macho-x: 0000000000000048 0f 05 0000 00000007 _t.eh
315
316# RUN: llvm-nm -o %p/Inputs/macho-text-data-bss.macho-x86_64 \
317# RUN:         | FileCheck %s -check-prefix macho-o
318
319# macho-o: {{.*}}/macho-text-data-bss.macho-x86_64: 0000000000000030 s EH_frame0
320# macho-o: {{.*}}/macho-text-data-bss.macho-x86_64: 0000000000000070 b _b
321# macho-o: {{.*}}/macho-text-data-bss.macho-x86_64: 000000000000000c D _d
322# macho-o: {{.*}}/macho-text-data-bss.macho-x86_64: 0000000000000000 T _t
323# macho-o: {{.*}}/macho-text-data-bss.macho-x86_64: 0000000000000048 S _t.eh
324
325# RUN: llvm-nm -p -a %p/Inputs/macho-hello-g.macho-x86_64 \
326# RUN:         | FileCheck %s -check-prefix macho-pa
327
328# macho-pa: 0000000000000000 - 00 0000    SO /Volumes/SandBox/
329# macho-pa: 0000000000000000 - 00 0000    SO hello.c
330# macho-pa: 0000000053c8408d - 03 0001   OSO /Volumes/SandBox/hello.o
331# macho-pa: 0000000100000f30 - 01 0000 BNSYM
332# macho-pa: 0000000100000f30 - 01 0000   FUN _main
333# macho-pa: 000000000000003b - 00 0000   FUN
334# macho-pa: 000000000000003b - 01 0000 ENSYM
335# macho-pa: 0000000000000000 - 01 0000    SO
336# macho-pa: 0000000100000000 T __mh_execute_header
337# macho-pa: 0000000100000f30 T _main
338# macho-pa:                  U _printf
339# macho-pa:                  U dyld_stub_binder
340
341# RUN: llvm-nm -u %p/Inputs/macho-hello-g.macho-x86_64 \
342# RUN:         | FileCheck %s -check-prefix macho-u
343
344# macho-u: _printf
345# macho-u: dyld_stub_binder
346
347# RUN: llvm-nm -S -a %p/Inputs/common.coff-i386 \
348# RUN:         | FileCheck %s -check-prefix COFF-COMMON
349
350# COFF-COMMON: 00000000 b .bss
351# COFF-COMMON-NEXT: 00000000 d .data
352# COFF-COMMON-NEXT: 00000000 d .drectve
353# COFF-COMMON-NEXT: 00000000 n .file
354# COFF-COMMON-NEXT: 00000000 r .rdata$zzz
355# COFF-COMMON-NEXT: 00000000 t .text
356# COFF-COMMON-NEXT:          C _a
357
358# RUN: mkdir -p %t
359# RUN: cd %t
360# RUN: cp %p/Inputs/trivial-object-test.macho-i386 a.out
361# RUN: llvm-nm a.out | FileCheck %s -check-prefix A-OUT
362
363# A-OUT:          U _SomeOtherFunction
364# A-OUT: 00000000 T _main
365# A-OUT:          U _puts
366