1# REQUIRES: system-linux 2 3## Check that BOLT correctly updates the Linux kernel static keys jump table. 4 5# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown %s -o %t.o 6# RUN: link_fdata %s %t.o %t.fdata 7# RUN: llvm-strip --strip-unneeded %t.o 8# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \ 9# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr 10 11## Verify static keys jump bindings to instructions. 12 13# RUN: llvm-bolt %t.exe --print-normalized -o %t.out --keep-nops=0 \ 14# RUN: --bolt-info=0 2>&1 | FileCheck %s 15 16## Verify that profile is matched correctly. 17 18# RUN: llvm-bolt %t.exe --print-normalized -o %t.out --keep-nops=0 \ 19# RUN: --bolt-info=0 --data %t.fdata 2>&1 \ 20# RUN: | FileCheck --check-prefix=CHECK-FDATA %s 21 22## Verify the bindings again on the rewritten binary with nops removed. 23 24# RUN: llvm-bolt %t.out -o %t.out.1 --print-normalized 2>&1 | FileCheck %s 25 26# CHECK: BOLT-INFO: Linux kernel binary detected 27# CHECK: BOLT-INFO: parsed 2 static keys jump entries 28 29 .text 30 .globl _start 31 .type _start, %function 32_start: 33# CHECK: Binary Function "_start" 34 nop 35.L0: 36 jmp L1 37# CHECK: jit 38# CHECK-SAME: # ID: 1 {{.*}} # Likely: 1 # InitValue: 0 39 nop 40L1: 41 .nops 5 42# CHECK: jit 43# CHECK-SAME: # ID: 2 {{.*}} # Likely: 0 # InitValue: 0 44 jmp .L0 45 46## Check that a branch profile associated with a NOP is handled properly when 47## dynamic branch is created. 48 49# FDATA: 1 _start #L1# 1 _start #L2# 3 42 50# CHECK-FDATA: jit {{.*}} # ID: 2 51# CHECK-FDATA-NEXT: jmp 52# CHECK-FDATA-NEXT: Successors: {{.*}} (mispreds: 3, count: 42) 53L2: 54 nop 55 .size _start, .-_start 56 57 .globl foo 58 .type foo, %function 59foo: 60 ret 61 .size foo, .-foo 62 63 64## Static keys jump table. 65 .rodata 66 .globl __start___jump_table 67 .type __start___jump_table, %object 68__start___jump_table: 69 70 .long .L0 - . # Jump address 71 .long L1 - . # Target address 72 .quad fake_static_key + 1 - . # Key address; LSB = 1 : likely 73 74 .long L1 - . # Jump address 75 .long L2 - . # Target address 76 .quad fake_static_key -. # Key address; LSB = 0 : unlikely 77 78 .globl __stop___jump_table 79 .type __stop___jump_table, %object 80__stop___jump_table: 81 82## Staic keys (we just use the label ignoring the format of the keys). 83 .data 84 .align 8 85fake_static_key: 86 .quad 0 87 88## Linux kernel version 89 .rodata 90 .align 16 91 .globl linux_banner 92 .type linux_banner, @object 93linux_banner: 94 .string "Linux version 6.6.61\n" 95 .size linux_banner, . - linux_banner 96 97## Fake Linux Kernel sections. 98 .section __ksymtab,"a",@progbits 99 .section __ksymtab_gpl,"a",@progbits 100