76 lines · plain
1; RUN: llc -mtriple=x86_64-unknown-unknown -x86-indirect-branch-tracking < %s | FileCheck %s2 3;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4;; This test verify the handling of ''nocf_check'' attribute by the backend. ;;5;; The file was generated using the following C code: ;;6;; ;;7;; void __attribute__((nocf_check)) NoCfCheckFunc(void) {} ;;8;; ;;9;; typedef void(*FuncPointer)(void); ;;10;; void NoCfCheckCall(FuncPointer f) { ;;11;; __attribute__((nocf_check)) FuncPointer p = f; ;;12;; (*p)(); ;;13;; NoCfCheckFunc(); ;;14;; } ;;15;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;16 17; Make sure that a function with ''nocf_check'' attribute is not instrumented18; with endbr instruction at the beginning.19define void @NoCfCheckFunc() #0 {20; CHECK-LABEL: NoCfCheckFunc21; CHECK-NOT: endbr6422; CHECK: retq23entry:24 ret void25}26 27; Ensure the notrack prefix is added before an indirect call using a pointer28; with ''nocf_check'' attribute. Also ensure a direct call to a function with29; the ''nocf_check'' attribute is correctly generated without notrack prefix.30define void @NoCfCheckCall(ptr %f) #1 {31; CHECK-LABEL: NoCfCheckCall32; CHECK: notrack call33; CHECK: callq NoCfCheckFunc34entry:35 %f.addr = alloca ptr, align 436 %p = alloca ptr, align 437 store ptr %f, ptr %f.addr, align 438 %0 = load ptr, ptr %f.addr, align 439 store ptr %0, ptr %p, align 440 %1 = load ptr, ptr %p, align 441 call void %1() #242 call void @NoCfCheckFunc() #243 ret void44}45 46;; NOTRACK tail call is not implemented, so nocf_check just disables tail call.47define void @NoCfCheckTail(ptr %p) #1 {48; CHECK-LABEL: NoCfCheckTail:49; CHECK: notrack callq *%rax50 %f = load ptr, ptr %p, align 451 tail call void %f() #252 ret void53}54 55define void @NoCfCheckTailCond(ptr %f, i1 %x) #1 {56; CHECK-LABEL: NoCfCheckTailCond:57; CHECK: notrack callq *%rdi58; CHECK: notrack callq *%rdi59entry:60 br i1 %x, label %bb1, label %bb261bb1:62 tail call void %f() #263 ret void64bb2:65 tail call void %f() #266 ret void67}68 69attributes #0 = { nocf_check noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-soft-float"="false" }70attributes #1 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-soft-float"="false" }71attributes #2 = { nocf_check }72 73!llvm.module.flags = !{!0}74 75!0 = !{i32 8, !"cf-protection-branch", i32 1}76