[llvm] [BOLT] Add validation for direct call/branch targets, bypassing invalid functions (PR #165406)
Maksim Panchenko via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 4 16:50:03 PST 2025
================
@@ -0,0 +1,47 @@
+## Test that BOLT errs when detecting the target
+## of a direct call/branch is a invalid instruction
+
+# REQUIRES: system-linux
+# RUN: rm -rf %t && mkdir -p %t && cd %t
+# RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o main.o
+# RUN: %clang %cflags -pie -Wl,-q %t/main.o -o main.exe
+# RUN: llvm-bolt %t/main.exe -o %t/main.exe.bolt -lite=0 2>&1 | FileCheck %s --check-prefix=CHECK-TARGETS
+
+# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function external_corrupt, an external branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
+# CHECK-TARGETS: BOLT-WARNING: corrupted control flow detected in function internal_corrupt, an internal branch/call targets an invalid instruction at address 0x{{[0-9a-f]+}}
+
+
+.globl internal_corrupt
+.type internal_corrupt, at function
+.align 16
+internal_corrupt:
+ leaq .Lopts_1(%rip),%rax
+ addq $25,%rax
+ .byte 0xf3,0xc3
+.L8xchar_1:
+ addq $12,%rax
+.Ldone_1:
+ .byte 0xf3,0xc3
+.align 64
+.Lopts_1:
+.byte 114,1,52,40,56,120,44,105,110,116,41,0 # data '114' will be disassembled as 'jb', check for internal branch: jb + 0x1
----------------
maksfb wrote:
Is it possible to use regular instructions, like `jb`, targeting a middle of instruction and data in code (to test both)?
https://github.com/llvm/llvm-project/pull/165406
More information about the llvm-commits
mailing list