Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[X86] Add support for
-mharden-sls=[none|all|return|indirect-jmp]
The patch addresses the feature request from ClangBuiltLinux/linux#1633. The implementation borrows a lot from aarch64. Reviewed By: nickdesaulniers, MaskRay Differential Revision: https://reviews.llvm.org/D126137
- Loading branch information
1 parent
e183665
commit a2ea5b4
Showing
8 changed files
with
174 additions
and
5 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
; RUN: llc -mattr=harden-sls-ret -mtriple=x86_64-unknown-unknown < %s | FileCheck %s -check-prefixes=CHECK,RET | ||
; RUN: llc -mattr=harden-sls-ijmp -mtriple=x86_64-unknown-unknown < %s | FileCheck %s -check-prefixes=CHECK,IJMP | ||
|
||
define dso_local i32 @double_return(i32 %a, i32 %b) local_unnamed_addr { | ||
; CHECK-LABEL: double_return: | ||
; CHECK: jle | ||
; CHECK-NOT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
entry: | ||
%cmp = icmp sgt i32 %a, 0 | ||
br i1 %cmp, label %if.then, label %if.else | ||
|
||
if.then: ; preds = %entry | ||
%div = sdiv i32 %a, %b | ||
ret i32 %div | ||
|
||
if.else: ; preds = %entry | ||
%div1 = sdiv i32 %b, %a | ||
ret i32 %div1 | ||
} | ||
|
||
@__const.indirect_branch.ptr = private unnamed_addr constant [2 x i8*] [i8* blockaddress(@indirect_branch, %return), i8* blockaddress(@indirect_branch, %l2)], align 8 | ||
|
||
; Function Attrs: norecurse nounwind readnone | ||
define dso_local i32 @indirect_branch(i32 %a, i32 %b, i32 %i) { | ||
; CHECK-LABEL: indirect_branch: | ||
; CHECK: jmpq * | ||
; RET-NOT: int3 | ||
; IJMP-NEXT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
entry: | ||
%idxprom = sext i32 %i to i64 | ||
%arrayidx = getelementptr inbounds [2 x i8*], [2 x i8*]* @__const.indirect_branch.ptr, i64 0, i64 %idxprom | ||
%0 = load i8*, i8** %arrayidx, align 8 | ||
indirectbr i8* %0, [label %return, label %l2] | ||
|
||
l2: ; preds = %entry | ||
br label %return | ||
|
||
return: ; preds = %entry, %l2 | ||
%retval.0 = phi i32 [ 1, %l2 ], [ 0, %entry ] | ||
ret i32 %retval.0 | ||
} | ||
|
||
define i32 @asmgoto() { | ||
; CHECK-LABEL: asmgoto: | ||
; CHECK: # %bb.0: # %entry | ||
; CHECK: jmp .L | ||
; CHECK-NOT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
; CHECK: retq | ||
; RET-NEXT: int3 | ||
; IJMP-NOT: int3 | ||
entry: | ||
callbr void asm sideeffect "jmp $0", "X"(i8* blockaddress(@asmgoto, %d)) | ||
to label %asm.fallthrough [label %d] | ||
; The asm goto above produces a direct branch: | ||
|
||
asm.fallthrough: ; preds = %entry | ||
ret i32 0 | ||
|
||
d: ; preds = %asm.fallthrough, %entry | ||
ret i32 1 | ||
} | ||
|
||
define void @bar(void ()* %0) { | ||
; CHECK-LABEL: bar: | ||
; CHECK: jmpq * | ||
; RET-NOT: int3 | ||
; IJMP-NEXT: int3 | ||
; CHECK-NOT: ret | ||
tail call void %0() | ||
ret void | ||
} | ||
|
||
declare dso_local void @foo() | ||
|
||
define dso_local void @bar2() { | ||
; CHECK-LABEL: bar2: | ||
; CHECK: jmp foo | ||
; CHECK-NOT: int3 | ||
; CHECK-NOT: ret | ||
tail call void @foo() | ||
ret void | ||
} |