-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function attribute "patchable-function-prefix" to support -fpatch…
…able-function-entry=N,M where M>0 Similar to the function attribute `prefix` (prefix data), "patchable-function-prefix" inserts data (M NOPs) before the function entry label. -fpatchable-function-entry=2,1 (1 NOP before entry, 1 NOP after entry) will look like: ``` .type foo,@function .Ltmp0: # @foo nop foo: .Lfunc_begin0: # optional `bti c` (AArch64 Branch Target Identification) or # `endbr64` (Intel Indirect Branch Tracking) nop .section __patchable_function_entries,"awo",@progbits,get,unique,0 .p2align 3 .quad .Ltmp0 ``` -fpatchable-function-entry=N,0 + -mbranch-protection=bti/-fcf-protection=branch has two reasonable placements (https://gcc.gnu.org/ml/gcc-patches/2020-01/msg01185.html): ``` (a) (b) func: func: .Ltmp0: bti c bti c .Ltmp0: nop nop ``` (a) needs no additional code. If the consensus is to go for (b), we will need more code in AArch64BranchTargets.cpp / X86IndirectBranchTracking.cpp . Differential Revision: https://reviews.llvm.org/D73070
- Loading branch information
Showing
8 changed files
with
135 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 33 additions & 13 deletions
46
llvm/test/CodeGen/AArch64/patchable-function-entry-bti.ll
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,43 @@ | ||
; RUN: llc -mtriple=aarch64 %s -o - | FileCheck --check-prefixes=CHECK %s | ||
|
||
define i32 @f0() "patchable-function-entry"="0" "branch-target-enforcement" { | ||
define void @f0() "patchable-function-entry"="0" "branch-target-enforcement" { | ||
; CHECK-LABEL: f0: | ||
; CHECK-NEXT: .Lfunc_begin0: | ||
; CHECK: %bb.0: | ||
; CHECK-NEXT: .Lfunc_begin0: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: hint #34 | ||
; CHECK-NEXT: mov w0, wzr | ||
; CHECK-NOT: .section __patchable_function_entries | ||
ret i32 0 | ||
; CHECK-NEXT: ret | ||
; CHECK-NOT: .section __patchable_function_entries | ||
ret void | ||
} | ||
|
||
define i32 @f1() "patchable-function-entry"="1" "branch-target-enforcement" { | ||
;; -fpatchable-function-entry=1 -mbranch-protection=bti | ||
define void @f1() "patchable-function-entry"="1" "branch-target-enforcement" { | ||
; CHECK-LABEL: f1: | ||
; CHECK-NEXT: .Lfunc_begin1: | ||
; CHECK-NEXT: .Lfunc_begin1: | ||
; CHECK: hint #34 | ||
; CHECK-NEXT: nop | ||
; CHECK-NEXT: mov w0, wzr | ||
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0 | ||
; CHECK-NEXT: .p2align 3 | ||
; CHECK-NEXT: .xword .Lfunc_begin1 | ||
ret i32 0 | ||
; CHECK-NEXT: ret | ||
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0 | ||
; CHECK-NEXT: .p2align 3 | ||
; CHECK-NEXT: .xword .Lfunc_begin1 | ||
ret void | ||
} | ||
|
||
;; -fpatchable-function-entry=2,1 -mbranch-protection=bti | ||
define void @f2_1() "patchable-function-entry"="1" "patchable-function-prefix"="1" "branch-target-enforcement" { | ||
; CHECK-LABEL: .type f2_1,@function | ||
; CHECK-NEXT: .Ltmp0: | ||
; CHECK-NEXT: nop | ||
; CHECK-NEXT: f2_1: | ||
; CHECK-NEXT: .Lfunc_begin2: | ||
; CHECK: // %bb.0: | ||
; CHECK-NEXT: hint #34 | ||
; CHECK-NEXT: nop | ||
; CHECK-NEXT: ret | ||
; CHECK: .Lfunc_end2: | ||
; CHECK-NEXT: .size f2_1, .Lfunc_end2-f2_1 | ||
; CHECK: .section __patchable_function_entries,"awo",@progbits,f1,unique,0 | ||
; CHECK-NEXT: .p2align 3 | ||
; CHECK-NEXT: .xword .Ltmp0 | ||
ret void | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters