brintos

brintos / llvm-project-archived public Read only

0
0
Text · 5.8 KiB · cdb47b4 Raw
130 lines · plain
1;; When BTI is enabled, keep the range check for a jump table for hardening,2;; even with an unreachable default.3;;4;; We check with and without the branch-target-enforcement module attribute,5;; and in each case, try overriding it with the opposite function attribute.6;; Expect to see a range check whenever there is BTI, and not where there7;; isn't.8 9; RUN: sed s/SPACE/4/ %s | sed '/test_jumptable/s/{/#1 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-TBB10; RUN: sed s/SPACE/4/ %s | sed '/test_jumptable/s/{/#0 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-TBB11; RUN: sed s/SPACE/4/ %s | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-TBB12; RUN: sed s/SPACE/4/ %s | sed '/test_jumptable/s/{/#1 {/' | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-TBB13 14; RUN: sed s/SPACE/400/ %s | sed '/test_jumptable/s/{/#1 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-TBH15; RUN: sed s/SPACE/400/ %s | sed '/test_jumptable/s/{/#0 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-TBH16; RUN: sed s/SPACE/400/ %s | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-TBH17; RUN: sed s/SPACE/400/ %s | sed '/test_jumptable/s/{/#1 {/' | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-TBH18 19; RUN: sed s/SPACE/400000/ %s | sed '/test_jumptable/s/{/#1 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-MOV20; RUN: sed s/SPACE/400000/ %s | sed '/test_jumptable/s/{/#0 {/' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-MOV21; RUN: sed s/SPACE/400000/ %s | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=NOBTI-MOV22; RUN: sed s/SPACE/400000/ %s | sed '/test_jumptable/s/{/#1 {/' | sed '/^..for-non-bti-build-sed-will-delete-everything-after-this-line/q' | llc -mtriple=thumbv8.1m.main-linux-gnu -mattr=+pacbti -o - | FileCheck %s --check-prefix=BTI-MOV23 24declare i32 @llvm.arm.space(i32, i32)25 26attributes #0 = { norecurse }27attributes #1 = { norecurse "branch-target-enforcement" }28 29define ptr @test_jumptable(ptr %src, ptr %dst) {30entry:31  %sw = load i32, ptr %src, align 432  %src.postinc = getelementptr inbounds i32, ptr %src, i32 133  switch i32 %sw, label %default [34    i32 0, label %sw.035    i32 1, label %sw.136    i32 2, label %sw.237    i32 3, label %sw.338  ]39 40sw.0:41  %store.0 = call i32 @llvm.arm.space(i32 SPACE, i32 14142)42  store i32 %store.0, ptr %dst, align 443  br label %exit44 45sw.1:46  %store.1 = call i32 @llvm.arm.space(i32 SPACE, i32 31415)47  %dst.1 = getelementptr inbounds i32, ptr %dst, i32 148  store i32 %store.1, ptr %dst.1, align 449  br label %exit50 51sw.2:52  %store.2 = call i32 @llvm.arm.space(i32 SPACE, i32 27182)53  %dst.2 = getelementptr inbounds i32, ptr %dst, i32 254  store i32 %store.2, ptr %dst.2, align 455  br label %exit56 57sw.3:58  %store.3 = call i32 @llvm.arm.space(i32 SPACE, i32 16180)59  %dst.3 = getelementptr inbounds i32, ptr %dst, i32 360  store i32 %store.3, ptr %dst.3, align 461  br label %exit62 63default:64  unreachable65 66exit:67  ret ptr %src.postinc68}69 70; NOBTI-TBB:      test_jumptable:71; NOBTI-TBB-NEXT:         .fnstart72; NOBTI-TBB-NEXT: @ %bb73; NOBTI-TBB-NEXT:         ldr     [[INDEX:r[0-9]+]], [r0], #474; NOBTI-TBB-NEXT: .LCPI75; NOBTI-TBB-NEXT:         tbb     [pc, [[INDEX]]]76 77; BTI-TBB:        test_jumptable:78; BTI-TBB-NEXT:           .fnstart79; BTI-TBB-NEXT:   @ %bb80; BTI-TBB-NEXT:           bti81; BTI-TBB-NEXT:           ldr     [[INDEX:r[0-9]+]], [r0], #482; BTI-TBB-NEXT:           cmp     [[INDEX]], #383; BTI-TBB-NEXT:           bhi     .LBB84; BTI-TBB-NEXT:   @ %bb85; BTI-TBB-NEXT:   .LCPI86; BTI-TBB-NEXT:           tbb     [pc, [[INDEX]]]87 88; NOBTI-TBH:      test_jumptable:89; NOBTI-TBH-NEXT:         .fnstart90; NOBTI-TBH-NEXT: @ %bb91; NOBTI-TBH-NEXT:         ldr     [[INDEX:r[0-9]+]], [r0], #492; NOBTI-TBH-NEXT: .LCPI93; NOBTI-TBH-NEXT:         tbh     [pc, [[INDEX]], lsl #1]94 95; BTI-TBH:        test_jumptable:96; BTI-TBH-NEXT:           .fnstart97; BTI-TBH-NEXT:   @ %bb98; BTI-TBH-NEXT:           bti99; BTI-TBH-NEXT:           ldr     [[INDEX:r[0-9]+]], [r0], #4100; BTI-TBH-NEXT:           cmp     [[INDEX]], #3101; BTI-TBH-NEXT:           bhi.w   .LBB102; BTI-TBH-NEXT:   @ %bb103; BTI-TBH-NEXT:   .LCPI104; BTI-TBH-NEXT:           tbh     [pc, [[INDEX]], lsl #1]105 106; NOBTI-MOV:      test_jumptable:107; NOBTI-MOV-NEXT:         .fnstart108; NOBTI-MOV-NEXT: @ %bb109; NOBTI-MOV-NEXT:         ldr     [[INDEX:r[0-9]+]], [r0], #4110; NOBTI-MOV-NEXT:         adr.w   [[ADDR:r[0-9]+]], .LJTI111; NOBTI-MOV-NEXT:         add.w   [[ADDR]], [[ADDR]], [[INDEX]], lsl #2112; NOBTI-MOV-NEXT:         mov     pc, [[ADDR]]113 114; BTI-MOV:        test_jumptable:115; BTI-MOV-NEXT:           .fnstart116; BTI-MOV-NEXT:   @ %bb117; BTI-MOV-NEXT:           bti118; BTI-MOV-NEXT:           ldr     [[INDEX:r[0-9]+]], [r0], #4119; BTI-MOV-NEXT:           cmp     [[INDEX]], #3120; BTI-MOV-NEXT:           bls     .LBB121; BTI-MOV-NEXT:           b.w     .LBB122; BTI-MOV-NEXT:   .LBB123; BTI-MOV-NEXT:           adr.w   [[ADDR:r[0-9]+]], .LJTI124; BTI-MOV-NEXT:           add.w   [[ADDR]], [[ADDR]], [[INDEX]], lsl #2125; BTI-MOV-NEXT:           mov     pc, [[ADDR]]126 127; for-non-bti-build-sed-will-delete-everything-after-this-line128!llvm.module.flags = !{!0}129!0 = !{i32 8, !"branch-target-enforcement", i32 1}130