From 540893e43fb7a5e08deec0d951fd3c1d957f8f89 Mon Sep 17 00:00:00 2001 From: Maksim Panchenko Date: Tue, 11 Jun 2024 10:52:51 -0700 Subject: [BOLT] Add auto parsing for Linux kernel .altinstructions (#95068) .altinstructions section contains a list of structures where fields can have different sizes while other fields could be present or not depending on the kernel version. Add automatic detection of such variations and use it by default. The user can still overwrite the automatic detection with `--alt-inst-has-padlen` and `--alt-inst-feature-size` options. --- bolt/test/X86/linux-alt-instruction.s | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'bolt/test') diff --git a/bolt/test/X86/linux-alt-instruction.s b/bolt/test/X86/linux-alt-instruction.s index 2cdf315..66cd33a 100644 --- a/bolt/test/X86/linux-alt-instruction.s +++ b/bolt/test/X86/linux-alt-instruction.s @@ -12,24 +12,30 @@ ## Older kernels used to have padlen field in alt_instr. Check compatibility. # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown --defsym PADLEN=1 \ -# RUN: %s -o %t.o -# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \ +# RUN: %s -o %t.padlen.o +# RUN: %clang %cflags -nostdlib %t.padlen.o -o %t.padlen.exe \ # RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie -# RUN: llvm-bolt %t.exe --print-normalized --alt-inst-has-padlen -o %t.out \ +# RUN: llvm-bolt %t.padlen.exe --print-normalized --alt-inst-has-padlen -o %t.padlen.out \ # RUN: | FileCheck %s ## Check with a larger size of "feature" field in alt_instr. # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-unknown \ -# RUN: --defsym FEATURE_SIZE_4=1 %s -o %t.o -# RUN: %clang %cflags -nostdlib %t.o -o %t.exe \ +# RUN: --defsym FEATURE_SIZE_4=1 %s -o %t.fs4.o +# RUN: %clang %cflags -nostdlib %t.fs4.o -o %t.fs4.exe \ # RUN: -Wl,--image-base=0xffffffff80000000,--no-dynamic-linker,--no-eh-frame-hdr,--no-pie -# RUN: llvm-bolt %t.exe --print-normalized --alt-inst-feature-size=4 -o %t.out \ +# RUN: llvm-bolt %t.fs4.exe --print-normalized --alt-inst-feature-size=4 -o %t.fs4.out \ # RUN: | FileCheck %s ## Check that out-of-bounds read is handled properly. -# RUN: not llvm-bolt %t.exe --print-normalized --alt-inst-feature-size=2 -o %t.out +# RUN: not llvm-bolt %t.fs4.exe --alt-inst-feature-size=2 -o %t.fs4.out + +## Check that BOLT automatically detects structure fields in .altinstructions. + +# RUN: llvm-bolt %t.exe --print-normalized -o %t.out | FileCheck %s +# RUN: llvm-bolt %t.exe --print-normalized -o %t.padlen.out | FileCheck %s +# RUN: llvm-bolt %t.exe --print-normalized -o %t.fs4.out | FileCheck %s # CHECK: BOLT-INFO: Linux kernel binary detected # CHECK: BOLT-INFO: parsed 2 alternative instruction entries -- cgit v1.1