|
| 1 | +# REQUIRES: system-linux |
| 2 | + |
| 3 | +## Check that BOLT correctly parses the Linux kernel .altinstructions section |
| 4 | +## and annotates alternative instructions. |
| 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,--no-pie |
| 9 | +# RUN: llvm-bolt %t.exe --print-normalized --keep-nops -o %t.out \ |
| 10 | +# RUN: --alt-inst-feature-size=2 | FileCheck %s |
| 11 | + |
| 12 | +## Older kernels used to have padlen field in alt_instr. Check compatibility. |
| 13 | + |
| 14 | +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown --defsym PADLEN=1 \ |
| 15 | +# RUN: %s -o %t.o |
| 16 | +# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \ |
| 17 | +# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie |
| 18 | +# RUN: llvm-bolt %t.exe --print-normalized --keep-nops --alt-inst-has-padlen \ |
| 19 | +# RUN: -o %t.out | FileCheck %s |
| 20 | + |
| 21 | +## Check with a larger size of "feature" field in alt_instr. |
| 22 | + |
| 23 | +# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ |
| 24 | +# RUN: --defsym FEATURE_SIZE_4=1 %s -o %t.o |
| 25 | +# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \ |
| 26 | +# RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie |
| 27 | +# RUN: llvm-bolt %t.exe --print-normalized --keep-nops \ |
| 28 | +# RUN: --alt-inst-feature-size=4 -o %t.out | FileCheck %s |
| 29 | + |
| 30 | +# CHECK: BOLT-INFO: Linux kernel binary detected |
| 31 | +# CHECK: BOLT-INFO: parsed 2 alternative instruction entries |
| 32 | + |
| 33 | + .text |
| 34 | + .globl _start |
| 35 | + .type _start, %function |
| 36 | +_start: |
| 37 | +# CHECK: Binary Function "_start" |
| 38 | +.L0: |
| 39 | + rdtsc |
| 40 | +# CHECK: rdtsc |
| 41 | +# CHECK-SAME: AltInst: 1 |
| 42 | +# CHECK-SAME: AltInst2: 2 |
| 43 | + nop |
| 44 | +# CHECK-NEXT: nop |
| 45 | +# CHECK-SAME: AltInst: 1 |
| 46 | +# CHECK-SAME: AltInst2: 2 |
| 47 | + nop |
| 48 | + nop |
| 49 | +.L1: |
| 50 | + ret |
| 51 | + .size _start, .-_start |
| 52 | + |
| 53 | + .section .altinstr_replacement,"ax",@progbits |
| 54 | +.A0: |
| 55 | + lfence |
| 56 | + rdtsc |
| 57 | +.A1: |
| 58 | + rdtscp |
| 59 | +.Ae: |
| 60 | + |
| 61 | +## Alternative instruction info. |
| 62 | + .section .altinstructions,"a",@progbits |
| 63 | + |
| 64 | + .long .L0 - . # org instruction |
| 65 | + .long .A0 - . # alt instruction |
| 66 | +.ifdef FEATURE_SIZE_4 |
| 67 | + .long 0x72 # feature flags |
| 68 | +.else |
| 69 | + .word 0x72 # feature flags |
| 70 | +.endif |
| 71 | + .byte .L1 - .L0 # org size |
| 72 | + .byte .A1 - .A0 # alt size |
| 73 | +.ifdef PADLEN |
| 74 | + .byte 0 |
| 75 | +.endif |
| 76 | + |
| 77 | + .long .L0 - . # org instruction |
| 78 | + .long .A1 - . # alt instruction |
| 79 | +.ifdef FEATURE_SIZE_4 |
| 80 | + .long 0x3b # feature flags |
| 81 | +.else |
| 82 | + .word 0x3b # feature flags |
| 83 | +.endif |
| 84 | + .byte .L1 - .L0 # org size |
| 85 | + .byte .Ae - .A1 # alt size |
| 86 | +.ifdef PADLEN |
| 87 | + .byte 0 |
| 88 | +.endif |
| 89 | + |
| 90 | +## Fake Linux Kernel sections. |
| 91 | + .section __ksymtab,"a",@progbits |
| 92 | + .section __ksymtab_gpl,"a",@progbits |
0 commit comments