xref: /llvm-project/bolt/test/X86/linux-orc.s (revision 6e8a1a45a783c13e4cd19bfd20b7a56cab6f7d81)
1# REQUIRES: system-linux
2
3## Check that BOLT correctly updates ORC unwind information used by the Linux
4## kernel.
5
6# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
7# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
8# RUN:   -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
9
10## Verify reading contents of ORC sections.
11
12# RUN: llvm-bolt %t.exe --dump-orc -o /dev/null 2>&1 | FileCheck %s \
13# RUN:   --check-prefix=CHECK-ORC
14
15# CHECK-ORC: 	    BOLT-INFO: ORC unwind information:
16# CHECK-ORC-NEXT: {sp: 8, bp: 0, info: 0x5}: _start
17# CHECK-ORC-NEXT: {terminator}
18# CHECK-ORC-NEXT: {sp: 8, bp: 0, info: 0x5}: foo
19# CHECK-ORC-NEXT: {sp: 16, bp: -16, info: 0x15}: foo
20# CHECK-ORC-NEXT: {sp: 16, bp: -16, info: 0x14}: foo
21# CHECK-ORC-NEXT: {sp: 8, bp: 0, info: 0x5}: foo
22# CHECK-ORC-NEXT: {terminator}
23# CHECK-ORC-NEXT: {terminator}
24# CHECK-ORC-NEXT: {terminator}
25
26
27## Verify ORC bindings to instructions.
28
29# RUN: llvm-bolt %t.exe --print-normalized --dump-orc --print-orc -o %t.out \
30# RUN:   --keep-nops=0 --bolt-info=0 2>&1 | FileCheck %s
31
32
33## Verify ORC bindings after rewrite.
34
35# RUN: llvm-bolt %t.out -o %t.out.1 --print-normalized --print-orc \
36# RUN:   2>&1 | FileCheck %s
37
38## Verify ORC binding after rewrite when some of the functions are skipped.
39
40# RUN: llvm-bolt %t.exe -o %t.out --skip-funcs=bar --bolt-info=0 --keep-nops=0
41# RUN: llvm-bolt %t.out -o %t.out.1 --print-normalized --print-orc \
42# RUN:   2>&1 | FileCheck %s
43
44# CHECK:      BOLT-INFO: Linux kernel binary detected
45# CHECK:      BOLT-INFO: parsed 9 ORC entries
46
47  .text
48  .globl _start
49  .type _start, %function
50_start:
51# CHECK: Binary Function "_start"
52
53  call foo
54# CHECK:      callq foo           # ORC: {sp: 8, bp: 0, info: 0x5}
55  ret
56  .size _start, .-_start
57
58  .globl foo
59  .type foo, %function
60foo:
61# CHECK: Binary Function "foo"
62
63  push %rbp
64# CHECK:      pushq   %rbp        # ORC: {sp: 8, bp: 0, info: 0x5}
65.L1:
66  mov %rsp, %rbp
67# CHECK:      movq    %rsp, %rbp  # ORC: {sp: 16, bp: -16, info: 0x15}
68.L2:
69  pop %rbp
70# CHECK:      popq    %rbp        # ORC: {sp: 16, bp: -16, info: 0x14}
71  nop
72.L3:
73  ret
74# CHECK:      retq                # ORC: {sp: 8, bp: 0, info: 0x5}
75  .size foo, .-foo
76
77  .globl bar
78  .type bar, %function
79bar:
80# CHECK:   Binary Function "bar"
81	ret
82## Same ORC info propagated from foo above.
83# CHECK:      retq                # ORC: {sp: 8, bp: 0, info: 0x5}
84.L4:
85  .size bar, .-bar
86
87# CHECK: BOLT-WARNING: Linux kernel support is experimental
88
89  .section .orc_unwind,"a",@progbits
90  .align 4
91  .section .orc_unwind_ip,"a",@progbits
92  .align 4
93
94## ORC for _start.
95  .section .orc_unwind
96  .2byte 8
97  .2byte 0
98  .2byte 5
99  .section .orc_unwind_ip
100  .long _start - .
101
102  .section .orc_unwind
103  .2byte 0
104  .2byte 0
105  .2byte 0
106  .section .orc_unwind_ip
107  .long foo - .
108
109## ORC for foo.
110  .section .orc_unwind
111  .2byte 8
112  .2byte 0
113  .2byte 5
114  .section .orc_unwind_ip
115  .long foo - .
116
117  .section .orc_unwind
118  .2byte 16
119  .2byte -16
120  .2byte 21
121  .section .orc_unwind_ip
122  .long .L1 - .
123
124  .section .orc_unwind
125  .2byte 16
126  .2byte -16
127  .2byte 20
128  .section .orc_unwind_ip
129  .long .L2 - .
130
131  .section .orc_unwind
132  .2byte 8
133  .2byte 0
134  .2byte 5
135  .section .orc_unwind_ip
136  .long .L3 - .
137
138  .section .orc_unwind
139  .2byte 0
140  .2byte 0
141  .2byte 0
142  .section .orc_unwind_ip
143  .long .L4 - .
144
145## Duplicate terminator entries to test ORC reader.
146  .section .orc_unwind
147  .2byte 0
148  .2byte 0
149  .2byte 0
150  .section .orc_unwind_ip
151  .long .L4 - .
152
153  .section .orc_unwind
154  .2byte 0
155  .2byte 0
156  .2byte 0
157  .section .orc_unwind_ip
158  .long .L4 - .
159
160## Linux kernel version
161  .rodata
162  .align 16
163  .globl linux_banner
164  .type  linux_banner, @object
165linux_banner:
166  .string  "Linux version 6.6.61\n"
167  .size  linux_banner, . - linux_banner
168
169## Fake Linux Kernel sections.
170  .section __ksymtab,"a",@progbits
171  .section __ksymtab_gpl,"a",@progbits
172