xref: /llvm-project/bolt/test/X86/linux-exceptions.s (revision 6e8a1a45a783c13e4cd19bfd20b7a56cab6f7d81)
1# REQUIRES: system-linux
2
3## Check that BOLT correctly parses the Linux kernel exception table.
4
5# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o
6# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \
7# RUN:   -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr
8
9## Verify exception bindings to instructions.
10
11# RUN: llvm-bolt %t.exe --print-normalized -o %t.out --keep-nops=0 \
12# RUN:   --bolt-info=0 | FileCheck %s
13
14## Verify the bindings again on the rewritten binary with nops removed.
15
16# RUN: llvm-bolt %t.out -o %t.out.1 --print-normalized | FileCheck %s
17
18# CHECK:      BOLT-INFO: Linux kernel binary detected
19# CHECK:      BOLT-INFO: parsed 2 exception table entries
20
21  .text
22  .globl _start
23  .type _start, %function
24_start:
25# CHECK: Binary Function "_start"
26  nop
27.L0:
28  mov (%rdi), %rax
29# CHECK:      mov
30# CHECK-SAME: ExceptionEntry: 1 # Fixup: [[FIXUP:[a-zA-Z0-9_]+]]
31  nop
32.L1:
33  mov (%rsi), %rax
34# CHECK:      mov
35# CHECK-SAME: ExceptionEntry: 2 # Fixup: [[FIXUP]]
36  nop
37  ret
38.LF0:
39# CHECK: Secondary Entry Point: [[FIXUP]]
40  jmp foo
41  .size _start, .-_start
42
43  .globl foo
44  .type foo, %function
45foo:
46  ret
47  .size foo, .-foo
48
49
50## Exception table.
51  .section __ex_table,"a",@progbits
52  .align 4
53
54  .long .L0 - .  # instruction
55  .long .LF0 - . # fixup
56  .long 0        # data
57
58  .long .L1 - .  # instruction
59  .long .LF0 - . # fixup
60  .long 0        # data
61
62## Linux kernel version
63  .rodata
64  .align 16
65  .globl linux_banner
66  .type  linux_banner, @object
67linux_banner:
68  .string  "Linux version 6.6.61\n"
69  .size  linux_banner, . - linux_banner
70
71## Fake Linux Kernel sections.
72  .section __ksymtab,"a",@progbits
73  .section __ksymtab_gpl,"a",@progbits
74