xref: /llvm-project/lld/test/COFF/symbolizer-inline.s (revision 1da67ecefddad87e76b475b7f60917fdded0834c)
1# REQUIRES: x86
2# RUN: llvm-mc -filetype=obj %s -o %t.obj -triple x86_64-windows-msvc
3# RUN: lld-link -entry:main -nodefaultlib %t.obj -out:%t.exe -pdb:%t.pdb -debug
4# RUN: llvm-symbolizer --obj=%t.exe --relative-address \
5# RUN:   0x1014 0x1015 0x1018 0x1019 0x101c 0x101d 0x1023 0x1024 \
6# RUN:   0x1037 0x103A 0x104B 0x104E | FileCheck %s
7
8# Compiled from this cpp code, with modifications to add extra inline line and
9# file changes:
10# clang -cc1 -triple x86_64-windows-msvc -gcodeview -S test.cpp
11#
12# __attribute__((always_inline)) int inlinee_2(int x) {
13#   return x + 1;
14# }
15# __attribute__((always_inline)) int inlinee_1(int x) {
16#   return inlinee_2(x) + 2;
17# }
18# int main() {
19#   int x = inlinee_1(33);
20#   int y = inlinee_2(22);
21#   int z = inlinee_2(11);
22#   return x + y + z;
23# }
24
25	.text
26	.def	 @feat.00;
27	.scl	3;
28	.type	0;
29	.endef
30	.globl	@feat.00
31.set @feat.00, 0
32	.file	"test.cpp"
33	.def	 main;
34	.scl	2;
35	.type	32;
36	.endef
37	.globl	main                            # -- Begin function main
38	.p2align	4, 0x90
39main:                                   # @main
40.Lfunc_begin0:
41	.cv_func_id 0
42	.cv_file	1 "C:\\src\\test.cpp" "67680A954FC00F980188190C8D23C68E" 1
43  .cv_file  2 "C:\\src\\fakefile.cpp" "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" 1
44	.cv_loc	0 1 9 0                         # test.cpp:9:0
45# %bb.0:                                # %entry
46	subq	$32, %rsp
47	movl	$0, 12(%rsp)
48	movl	$33, 16(%rsp)
49.Ltmp0:
50	.cv_inline_site_id 1 within 0 inlined_at 1 10 11
51	.cv_loc	1 1 6 20                        # test.cpp:6:20
52
53# CHECK: inlinee_1
54# CHECK-NEXT: C:\src\test.cpp:6:0
55# CHECK-NEXT: main
56# CHECK-NEXT: C:\src\test.cpp:10:11
57
58# CHECK: inlinee_1
59# CHECK-NEXT: C:\src\test.cpp:6:0
60# CHECK-NEXT: main
61# CHECK-NEXT: C:\src\test.cpp:10:11
62	movl	16(%rsp), %eax
63
64# Add a line change here.
65  .cv_loc 1 1 7 7
66
67# CHECK: inlinee_1
68# CHECK-NEXT: C:\src\test.cpp:7:0
69# CHECK-NEXT: main
70# CHECK-NEXT: C:\src\test.cpp:10:11
71
72# CHECK: inlinee_1
73# CHECK-NEXT: C:\src\test.cpp:7:0
74# CHECK-NEXT: main
75# CHECK-NEXT: C:\src\test.cpp:10:11
76	movl	%eax, 20(%rsp)
77.Ltmp1:
78	.cv_inline_site_id 2 within 1 inlined_at 1 6 10
79	.cv_loc	2 1 2 10                        # test.cpp:2:10
80
81# CHECK: inlinee_2
82# CHECK-NEXT: C:\src\test.cpp:2:0
83# CHECK-NEXT: inlinee_1
84# CHECK-NEXT: C:\src\test.cpp:6:0
85# CHECK-NEXT: main
86# CHECK-NEXT: C:\src\test.cpp:10:11
87
88# CHECK: inlinee_2
89# CHECK-NEXT: C:\src\test.cpp:2:0
90# CHECK-NEXT: inlinee_1
91# CHECK-NEXT: C:\src\test.cpp:6:0
92# CHECK-NEXT: main
93# CHECK-NEXT: C:\src\test.cpp:10:11
94	movl	20(%rsp), %eax
95	.cv_loc	2 1 2 12                        # test.cpp:2:12
96	addl	$1, %eax
97
98# Add a file change.
99  .cv_loc 2 2 102 0                       # fakefile.cpp:102:0
100
101# CHECK: inlinee_2
102# CHECK-NEXT: C:\src\fakefile.cpp:102:0
103# CHECK-NEXT: inlinee_1
104# CHECK-NEXT: C:\src\test.cpp:6:0
105# CHECK-NEXT: main
106# CHECK-NEXT: C:\src\test.cpp:10:11
107  nop
108
109.Ltmp2:
110	.cv_loc	1 1 6 23                        # test.cpp:6:23
111
112# CHECK: inlinee_1
113# CHECK-NEXT: C:\src\test.cpp:6:0
114# CHECK-NEXT: main
115# CHECK-NEXT: C:\src\test.cpp:10:11
116	addl	$2, %eax
117.Ltmp3:
118	.cv_loc	0 1 10 7                        # test.cpp:10:7
119	movl	%eax, 8(%rsp)
120	movl	$22, 28(%rsp)
121.Ltmp4:
122# Add a .cv_loc 0 so there is a gap in the inline site.
123# CHECK: main
124# CHECK-NEXT: C:\src\test.cpp:0:0
125
126# CHECK: inlinee_2
127# CHECK-NEXT: C:\src\test.cpp:2:0
128# CHECK-NEXT: main
129# CHECK-NEXT: C:\src\test.cpp:11:11
130	.cv_inline_site_id 3 within 0 inlined_at 1 11 11
131	.cv_loc	3 1 2 10                        # test.cpp:2:10
132	movl	28(%rsp), %eax
133  .cv_loc 0 1 0 0
134  nop
135	.cv_loc	3 1 2 12                        # test.cpp:2:12
136	addl	$1, %eax
137.Ltmp5:
138	.cv_loc	0 1 11 7                        # test.cpp:11:7
139	movl	%eax, 4(%rsp)
140	movl	$11, 24(%rsp)
141.Ltmp6:
142# Same test as above but modify the .cv_inline_linetable to use an annotation
143# that clang doesn't emit.
144# CHECK-NOT: inlinee_2
145# CHECK: main
146# CHECK-NEXT: C:\src\test.cpp:11:7
147
148# CHECK: inlinee_2
149# CHECK-NEXT: C:\src\test.cpp:1:0
150# CHECK-NEXT: main
151# CHECK-NEXT: C:\src\test.cpp:11:7
152.cv_inline_site_id 4 within 0 inlined_at 1 0 0
153	movl	24(%rsp), %eax
154  nop
155	addl	$1, %eax
156.Ltmp7:
157	.cv_loc	0 1 13 3                        # test.cpp:13:3
158	addq	$32, %rsp
159	retq
160.Ltmp8:
161.Lfunc_end0:
162                                        # -- End function
163	.section	.debug$S,"dr"
164	.p2align	2
165	.long	4                               # Debug section magic
166	.long	241
167	.long	.Ltmp10-.Ltmp9                  # Subsection size
168.Ltmp9:
169	.short	.Ltmp12-.Ltmp11                 # Record length
170.Ltmp11:
171	.short	4412                            # Record kind: S_COMPILE3
172	.long	1                               # Flags and language
173	.short	208                             # CPUType
174	.short	12                              # Frontend version
175	.short	0
176	.short	0
177	.short	0
178	.short	12000                           # Backend version
179	.short	0
180	.short	0
181	.short	0
182	.asciz	"clang version 12.0.0 (https://github.com/llvm/llvm-project.git 2ef947fe318d081b12add3d411bbb2af6373c66d)" # Null-terminated compiler version string
183	.p2align	2
184.Ltmp12:
185.Ltmp10:
186	.p2align	2
187	.long	246                             # Inlinee lines subsection
188	.long	.Ltmp14-.Ltmp13                 # Subsection size
189.Ltmp13:
190	.long	0                               # Inlinee lines signature
191
192                                        # Inlined function inlinee_1 starts at test.cpp:5
193	.long	4098                            # Type index of inlined function
194	.cv_filechecksumoffset	1               # Offset into filechecksum table
195	.long	5                               # Starting line number
196
197                                        # Inlined function inlinee_2 starts at test.cpp:1
198	.long	4099                            # Type index of inlined function
199	.cv_filechecksumoffset	1               # Offset into filechecksum table
200	.long	1                               # Starting line number
201.Ltmp14:
202	.p2align	2
203	.long	241                             # Symbol subsection for main
204	.long	.Ltmp16-.Ltmp15                 # Subsection size
205.Ltmp15:
206	.short	.Ltmp18-.Ltmp17                 # Record length
207.Ltmp17:
208	.short	4423                            # Record kind: S_GPROC32_ID
209	.long	0                               # PtrParent
210	.long	0                               # PtrEnd
211	.long	0                               # PtrNext
212	.long	.Lfunc_end0-main                # Code size
213	.long	0                               # Offset after prologue
214	.long	0                               # Offset before epilogue
215	.long	4102                            # Function type index
216	.secrel32	main                    # Function section relative address
217	.secidx	main                            # Function section index
218	.byte	0                               # Flags
219	.asciz	"main"                          # Function name
220	.p2align	2
221.Ltmp18:
222	.short	.Ltmp20-.Ltmp19                 # Record length
223.Ltmp19:
224	.short	4114                            # Record kind: S_FRAMEPROC
225	.long	32                              # FrameSize
226	.long	0                               # Padding
227	.long	0                               # Offset of padding
228	.long	0                               # Bytes of callee saved registers
229	.long	0                               # Exception handler offset
230	.short	0                               # Exception handler section
231	.long	81920                           # Flags (defines frame register)
232	.p2align	2
233.Ltmp20:
234	.short	.Ltmp22-.Ltmp21                 # Record length
235.Ltmp21:
236	.short	4414                            # Record kind: S_LOCAL
237	.long	116                             # TypeIndex
238	.short	0                               # Flags
239	.asciz	"x"
240	.p2align	2
241.Ltmp22:
242	.cv_def_range	 .Ltmp0 .Ltmp8, frame_ptr_rel, 8
243	.short	.Ltmp24-.Ltmp23                 # Record length
244.Ltmp23:
245	.short	4414                            # Record kind: S_LOCAL
246	.long	116                             # TypeIndex
247	.short	0                               # Flags
248	.asciz	"y"
249	.p2align	2
250.Ltmp24:
251	.cv_def_range	 .Ltmp0 .Ltmp8, frame_ptr_rel, 4
252	.short	.Ltmp26-.Ltmp25                 # Record length
253.Ltmp25:
254	.short	4414                            # Record kind: S_LOCAL
255	.long	116                             # TypeIndex
256	.short	0                               # Flags
257	.asciz	"z"
258	.p2align	2
259.Ltmp26:
260	.cv_def_range	 .Ltmp0 .Ltmp8, frame_ptr_rel, 0
261	.short	.Ltmp28-.Ltmp27                 # Record length
262.Ltmp27:
263	.short	4429                            # Record kind: S_INLINESITE
264	.long	0                               # PtrParent
265	.long	0                               # PtrEnd
266	.long	4098                            # Inlinee type index
267	.cv_inline_linetable	1 1 5 .Lfunc_begin0 .Lfunc_end0
268	.p2align	2
269.Ltmp28:
270	.short	.Ltmp30-.Ltmp29                 # Record length
271.Ltmp29:
272	.short	4414                            # Record kind: S_LOCAL
273	.long	116                             # TypeIndex
274	.short	1                               # Flags
275	.asciz	"x"
276	.p2align	2
277.Ltmp30:
278	.cv_def_range	 .Ltmp0 .Ltmp3, frame_ptr_rel, 16
279	.short	.Ltmp32-.Ltmp31                 # Record length
280.Ltmp31:
281	.short	4429                            # Record kind: S_INLINESITE
282	.long	0                               # PtrParent
283	.long	0                               # PtrEnd
284	.long	4099                            # Inlinee type index
285	.cv_inline_linetable	2 1 1 .Lfunc_begin0 .Lfunc_end0
286	.p2align	2
287.Ltmp32:
288	.short	.Ltmp34-.Ltmp33                 # Record length
289.Ltmp33:
290	.short	4414                            # Record kind: S_LOCAL
291	.long	116                             # TypeIndex
292	.short	1                               # Flags
293	.asciz	"x"
294	.p2align	2
295.Ltmp34:
296	.cv_def_range	 .Ltmp1 .Ltmp2, frame_ptr_rel, 20
297	.short	2                               # Record length
298	.short	4430                            # Record kind: S_INLINESITE_END
299	.short	2                               # Record length
300	.short	4430                            # Record kind: S_INLINESITE_END
301	.short	.Ltmp36-.Ltmp35                 # Record length
302.Ltmp35:
303	.short	4429                            # Record kind: S_INLINESITE
304	.long	0                               # PtrParent
305	.long	0                               # PtrEnd
306	.long	4099                            # Inlinee type index
307	.cv_inline_linetable	3 1 1 .Lfunc_begin0 .Lfunc_end0
308	.p2align	2
309.Ltmp36:
310	.short	.Ltmp38-.Ltmp37                 # Record length
311.Ltmp37:
312	.short	4414                            # Record kind: S_LOCAL
313	.long	116                             # TypeIndex
314	.short	1                               # Flags
315	.asciz	"x"
316	.p2align	2
317.Ltmp38:
318	.cv_def_range	 .Ltmp4 .Ltmp5, frame_ptr_rel, 28
319	.short	2                               # Record length
320	.short	4430                            # Record kind: S_INLINESITE_END
321	.short	.Ltmp40-.Ltmp39                 # Record length
322.Ltmp39:
323	.short	4429                            # Record kind: S_INLINESITE
324	.long	0                               # PtrParent
325	.long	0                               # PtrEnd
326	.long	4099                            # Inlinee type index
327# Changed inline line table annotations.
328  .byte 0x0C, 0x4, 0x47
329  .byte 0x0C, 0x3, 0x5
330	.p2align	2
331.Ltmp40:
332	.short	.Ltmp42-.Ltmp41                 # Record length
333.Ltmp41:
334	.short	4414                            # Record kind: S_LOCAL
335	.long	116                             # TypeIndex
336	.short	1                               # Flags
337	.asciz	"x"
338	.p2align	2
339.Ltmp42:
340	.cv_def_range	 .Ltmp6 .Ltmp7, frame_ptr_rel, 24
341	.short	2                               # Record length
342	.short	4430                            # Record kind: S_INLINESITE_END
343	.short	2                               # Record length
344	.short	4431                            # Record kind: S_PROC_ID_END
345.Ltmp16:
346	.p2align	2
347	.cv_linetable	0, main, .Lfunc_end0
348	.cv_filechecksums                       # File index to string table offset subsection
349	.cv_stringtable                         # String table
350	.long	241
351	.long	.Ltmp44-.Ltmp43                 # Subsection size
352.Ltmp43:
353	.short	.Ltmp46-.Ltmp45                 # Record length
354.Ltmp45:
355	.short	4428                            # Record kind: S_BUILDINFO
356	.long	4105                            # LF_BUILDINFO index
357	.p2align	2
358.Ltmp46:
359.Ltmp44:
360	.p2align	2
361	.section	.debug$T,"dr"
362	.p2align	2
363	.long	4                               # Debug section magic
364	# ArgList (0x1000)
365	.short	0xa                             # Record length
366	.short	0x1201                          # Record kind: LF_ARGLIST
367	.long	0x1                             # NumArgs
368	.long	0x74                            # Argument: int
369	# Procedure (0x1001)
370	.short	0xe                             # Record length
371	.short	0x1008                          # Record kind: LF_PROCEDURE
372	.long	0x74                            # ReturnType: int
373	.byte	0x0                             # CallingConvention: NearC
374	.byte	0x0                             # FunctionOptions
375	.short	0x1                             # NumParameters
376	.long	0x1000                          # ArgListType: (int)
377	# FuncId (0x1002)
378	.short	0x16                            # Record length
379	.short	0x1601                          # Record kind: LF_FUNC_ID
380	.long	0x0                             # ParentScope
381	.long	0x1001                          # FunctionType: int (int)
382	.asciz	"inlinee_1"                     # Name
383	.byte	242
384	.byte	241
385	# FuncId (0x1003)
386	.short	0x16                            # Record length
387	.short	0x1601                          # Record kind: LF_FUNC_ID
388	.long	0x0                             # ParentScope
389	.long	0x1001                          # FunctionType: int (int)
390	.asciz	"inlinee_2"                     # Name
391	.byte	242
392	.byte	241
393	# ArgList (0x1004)
394	.short	0x6                             # Record length
395	.short	0x1201                          # Record kind: LF_ARGLIST
396	.long	0x0                             # NumArgs
397	# Procedure (0x1005)
398	.short	0xe                             # Record length
399	.short	0x1008                          # Record kind: LF_PROCEDURE
400	.long	0x74                            # ReturnType: int
401	.byte	0x0                             # CallingConvention: NearC
402	.byte	0x0                             # FunctionOptions
403	.short	0x0                             # NumParameters
404	.long	0x1004                          # ArgListType: ()
405	# FuncId (0x1006)
406	.short	0x12                            # Record length
407	.short	0x1601                          # Record kind: LF_FUNC_ID
408	.long	0x0                             # ParentScope
409	.long	0x1005                          # FunctionType: int ()
410	.asciz	"main"                          # Name
411	.byte	243
412	.byte	242
413	.byte	241
414	# StringId (0x1007)
415	.short	0x2a                            # Record length
416	.short	0x1605                          # Record kind: LF_STRING_ID
417	.long	0x0                             # Id
418	.asciz	"C:\\src\\tests\\symbolizer\\asm-test"  # StringData
419	.byte	243
420	.byte	242
421	.byte	241
422	# StringId (0x1008)
423	.short	0xe                             # Record length
424	.short	0x1605                          # Record kind: LF_STRING_ID
425	.long	0x0                             # Id
426	.asciz	"<stdin>"                       # StringData
427	# BuildInfo (0x1009)
428	.short	0x1a                            # Record length
429	.short	0x1603                          # Record kind: LF_BUILDINFO
430	.short	0x5                             # NumArgs
431	.long	0x1007                          # Argument: C:\src
432	.long	0x0                             # Argument
433	.long	0x1008                          # Argument: <stdin>
434	.long	0x0                             # Argument
435	.long	0x0                             # Argument
436	.byte	242
437	.byte	241
438