You've already forked linux-packaging-mono
Imported Upstream version 5.18.0.167
Former-commit-id: 289509151e0fee68a1b591a20c9f109c3c789d3a
This commit is contained in:
parent
e19d552987
commit
b084638f15
@ -1,30 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s --check-prefix=TLS
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s --check-prefix=TLS
|
||||
; RUN: opt -safe-stack -S -mtriple=i686-linux-android < %s -o - | FileCheck %s --check-prefix=DIRECT-TLS32
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-linux-android < %s -o - | FileCheck %s --check-prefix=DIRECT-TLS64
|
||||
|
||||
|
||||
define void @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; TLS: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
; TLS: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
; TLS: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
; DIRECT-TLS32: %[[USP:.*]] = load i8*, i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
|
||||
; DIRECT-TLS32: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
; DIRECT-TLS32: store i8* %[[USST]], i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
|
||||
|
||||
; DIRECT-TLS64: %[[USP:.*]] = load i8*, i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
|
||||
; DIRECT-TLS64: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
; DIRECT-TLS64: store i8* %[[USST]], i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
|
||||
|
||||
%a = alloca i8, align 8
|
||||
call void @Capture(i8* %a)
|
||||
|
||||
; TLS: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr
|
||||
; DIRECT-TLS32: store i8* %[[USP]], i8* addrspace(256)* inttoptr (i32 36 to i8* addrspace(256)*)
|
||||
; DIRECT-TLS64: store i8* %[[USP]], i8* addrspace(257)* inttoptr (i32 72 to i8* addrspace(257)*)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @Capture(i8*)
|
@ -1,26 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i686-pc-linux-gnu < %s -o - | FileCheck --check-prefixes=COMMON,TLS32 %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck --check-prefixes=COMMON,TLS64 %s
|
||||
|
||||
; RUN: opt -safe-stack -S -mtriple=i686-linux-android < %s -o - | FileCheck --check-prefixes=COMMON,GLOBAL32 %s
|
||||
; RUN: opt -safe-stack -S -mtriple=i686-linux-android24 < %s -o - | FileCheck --check-prefixes=COMMON,TLS32 %s
|
||||
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-linux-android < %s -o - | FileCheck --check-prefixes=COMMON,TLS64 %s
|
||||
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-unknown-fuchsia < %s -o - | FileCheck --check-prefixes=COMMON,FUCHSIA64 %s
|
||||
|
||||
define void @foo() safestack sspreq {
|
||||
entry:
|
||||
; TLS32: %[[StackGuard:.*]] = load i8*, i8* addrspace(256)* inttoptr (i32 20 to i8* addrspace(256)*)
|
||||
; TLS64: %[[StackGuard:.*]] = load i8*, i8* addrspace(257)* inttoptr (i32 40 to i8* addrspace(257)*)
|
||||
; FUCHSIA64: %[[StackGuard:.*]] = load i8*, i8* addrspace(257)* inttoptr (i32 16 to i8* addrspace(257)*)
|
||||
; GLOBAL32: %[[StackGuard:.*]] = load i8*, i8** @__stack_chk_guard
|
||||
; COMMON: store i8* %[[StackGuard]], i8** %[[StackGuardSlot:.*]]
|
||||
%a = alloca i8, align 1
|
||||
call void @Capture(i8* %a)
|
||||
|
||||
; COMMON: %[[A:.*]] = load i8*, i8** %[[StackGuardSlot]]
|
||||
; COMMON: icmp ne i8* %[[StackGuard]], %[[A]]
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @Capture(i8*)
|
@ -1,22 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; Address-of local taken (j = &a)
|
||||
; Requires protector.
|
||||
|
||||
define void @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
%retval = alloca i32, align 4
|
||||
%a = alloca i32, align 4
|
||||
%j = alloca i32*, align 8
|
||||
store i32 0, i32* %retval
|
||||
%0 = load i32, i32* %a, align 4
|
||||
%add = add nsw i32 %0, 1
|
||||
store i32 %add, i32* %a, align 4
|
||||
store i32* %a, i32** %j, align 8
|
||||
ret void
|
||||
}
|
||||
|
@ -1,38 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; array of [16 x i8]
|
||||
|
||||
define void @foo(i8* %a) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
|
||||
; CHECK: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
%a.addr = alloca i8*, align 8
|
||||
%buf = alloca [16 x i8], align 16
|
||||
|
||||
; CHECK: %[[AADDR:.*]] = alloca i8*, align 8
|
||||
; CHECK: store i8* {{.*}}, i8** %[[AADDR]], align 8
|
||||
store i8* %a, i8** %a.addr, align 8
|
||||
|
||||
; CHECK: %[[BUFPTR:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
; CHECK: %[[BUFPTR2:.*]] = bitcast i8* %[[BUFPTR]] to [16 x i8]*
|
||||
; CHECK: %[[GEP:.*]] = getelementptr inbounds [16 x i8], [16 x i8]* %[[BUFPTR2]], i32 0, i32 0
|
||||
%gep = getelementptr inbounds [16 x i8], [16 x i8]* %buf, i32 0, i32 0
|
||||
|
||||
; CHECK: %[[A2:.*]] = load i8*, i8** %[[AADDR]], align 8
|
||||
%a2 = load i8*, i8** %a.addr, align 8
|
||||
|
||||
; CHECK: call i8* @strcpy(i8* %[[GEP]], i8* %[[A2]])
|
||||
%call = call i8* @strcpy(i8* %gep, i8* %a2)
|
||||
|
||||
; CHECK: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i8* @strcpy(i8*, i8*)
|
@ -1,89 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-contiki-unknown < %s -o - | FileCheck -check-prefix=SINGLE-THREAD %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
; array [4 x i8]
|
||||
; Requires protector.
|
||||
|
||||
; CHECK: @__safestack_unsafe_stack_ptr = external thread_local(initialexec) global i8*
|
||||
; SINGLE-THREAD: @__safestack_unsafe_stack_ptr = external global i8*
|
||||
|
||||
define void @foo(i8* %a) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
|
||||
; CHECK: store i8* %[[USST]], i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
%a.addr = alloca i8*, align 8
|
||||
%buf = alloca [4 x i8], align 1
|
||||
|
||||
; CHECK: %[[AADDR:.*]] = alloca i8*, align 8
|
||||
; CHECK: store i8* {{.*}}, i8** %[[AADDR]], align 8
|
||||
store i8* %a, i8** %a.addr, align 8
|
||||
|
||||
; CHECK: %[[BUFPTR:.*]] = getelementptr i8, i8* %[[USP]], i32 -4
|
||||
; CHECK: %[[BUFPTR2:.*]] = bitcast i8* %[[BUFPTR]] to [4 x i8]*
|
||||
; CHECK: %[[GEP:.*]] = getelementptr inbounds [4 x i8], [4 x i8]* %[[BUFPTR2]], i32 0, i32 0
|
||||
%gep = getelementptr inbounds [4 x i8], [4 x i8]* %buf, i32 0, i32 0
|
||||
|
||||
; CHECK: %[[A2:.*]] = load i8*, i8** %[[AADDR]], align 8
|
||||
%a2 = load i8*, i8** %a.addr, align 8
|
||||
|
||||
; CHECK: call i8* @strcpy(i8* %[[GEP]], i8* %[[A2]])
|
||||
%call = call i8* @strcpy(i8* %gep, i8* %a2)
|
||||
|
||||
; CHECK: store i8* %[[USP]], i8** @__safestack_unsafe_stack_ptr
|
||||
ret void
|
||||
}
|
||||
|
||||
; Load from an array at a fixed offset, no overflow.
|
||||
define i8 @StaticArrayFixedSafe() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define i8 @StaticArrayFixedSafe(
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i8
|
||||
%buf = alloca i8, i32 4, align 1
|
||||
%gep = getelementptr inbounds i8, i8* %buf, i32 2
|
||||
%x = load i8, i8* %gep, align 1
|
||||
ret i8 %x
|
||||
}
|
||||
|
||||
; Load from an array at a fixed offset with overflow.
|
||||
define i8 @StaticArrayFixedUnsafe() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define i8 @StaticArrayFixedUnsafe(
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i8
|
||||
%buf = alloca i8, i32 4, align 1
|
||||
%gep = getelementptr inbounds i8, i8* %buf, i32 5
|
||||
%x = load i8, i8* %gep, align 1
|
||||
ret i8 %x
|
||||
}
|
||||
|
||||
; Load from an array at an unknown offset.
|
||||
define i8 @StaticArrayVariableUnsafe(i32 %ofs) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define i8 @StaticArrayVariableUnsafe(
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i8
|
||||
%buf = alloca i8, i32 4, align 1
|
||||
%gep = getelementptr inbounds i8, i8* %buf, i32 %ofs
|
||||
%x = load i8, i8* %gep, align 1
|
||||
ret i8 %x
|
||||
}
|
||||
|
||||
; Load from an array of an unknown size.
|
||||
define i8 @DynamicArrayUnsafe(i32 %sz) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define i8 @DynamicArrayUnsafe(
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i8
|
||||
%buf = alloca i8, i32 %sz, align 1
|
||||
%gep = getelementptr inbounds i8, i8* %buf, i32 2
|
||||
%x = load i8, i8* %gep, align 1
|
||||
ret i8 %x
|
||||
}
|
||||
|
||||
declare i8* @strcpy(i8*, i8*)
|
@ -1,51 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
%struct.S = type { [100 x i32] }
|
||||
|
||||
; Safe access to a byval argument.
|
||||
define i32 @ByValSafe(%struct.S* byval nocapture readonly align 8 %zzz) norecurse nounwind readonly safestack uwtable {
|
||||
entry:
|
||||
; CHECK-LABEL: @ByValSafe
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i32
|
||||
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 3
|
||||
%0 = load i32, i32* %arrayidx, align 4
|
||||
ret i32 %0
|
||||
}
|
||||
|
||||
; Unsafe access to a byval argument.
|
||||
; Argument is copied to the unsafe stack.
|
||||
define i32 @ByValUnsafe(%struct.S* byval nocapture readonly align 8 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
|
||||
entry:
|
||||
; CHECK-LABEL: @ByValUnsafe
|
||||
; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
|
||||
; CHECK: store {{.*}} @__safestack_unsafe_stack_ptr
|
||||
; CHECK: %[[B:.*]] = getelementptr i8, i8* %[[A]], i32 -400
|
||||
; CHECK: %[[C:.*]] = bitcast %struct.S* %zzz to i8*
|
||||
; CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %[[B]], i8* %[[C]], i64 400, i32 8, i1 false)
|
||||
; CHECK: ret i32
|
||||
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
|
||||
%0 = load i32, i32* %arrayidx, align 4
|
||||
ret i32 %0
|
||||
}
|
||||
|
||||
; Highly aligned byval argument.
|
||||
define i32 @ByValUnsafeAligned(%struct.S* byval nocapture readonly align 64 %zzz, i64 %idx) norecurse nounwind readonly safestack uwtable {
|
||||
entry:
|
||||
; CHECK-LABEL: @ByValUnsafeAligned
|
||||
; CHECK: %[[A:.*]] = load {{.*}} @__safestack_unsafe_stack_ptr
|
||||
; CHECK: %[[B:.*]] = ptrtoint i8* %[[A]] to i64
|
||||
; CHECK: and i64 %[[B]], -64
|
||||
; CHECK: ret i32
|
||||
%arrayidx = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 0
|
||||
%0 = load i32, i32* %arrayidx, align 64
|
||||
%arrayidx2 = getelementptr inbounds %struct.S, %struct.S* %zzz, i64 0, i32 0, i64 %idx
|
||||
%1 = load i32, i32* %arrayidx2, align 4
|
||||
%add = add nsw i32 %1, %0
|
||||
ret i32 %add
|
||||
}
|
||||
|
178
external/llvm/test/Transforms/SafeStack/X86/call.ll
vendored
178
external/llvm/test/Transforms/SafeStack/X86/call.ll
vendored
@ -1,178 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; no arrays / no nested arrays
|
||||
; Requires no protector.
|
||||
|
||||
define void @foo(i8* %a) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @foo(
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%a.addr = alloca i8*, align 8
|
||||
store i8* %a, i8** %a.addr, align 8
|
||||
%0 = load i8*, i8** %a.addr, align 8
|
||||
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(i8*, ...)
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
define void @call_memset(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_memset
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @llvm.memset.p0i8.i64(i8* %arraydecay, i8 1, i64 %len, i32 1, i1 false)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @call_constant_memset() safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_constant_memset
|
||||
; CHECK-NOT: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 2
|
||||
call void @llvm.memset.p0i8.i64(i8* %arraydecay, i8 1, i64 7, i32 1, i1 false)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @call_constant_overflow_memset() safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_constant_overflow_memset
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 7
|
||||
call void @llvm.memset.p0i8.i64(i8* %arraydecay, i8 1, i64 5, i32 1, i1 false)
|
||||
ret void
|
||||
}
|
||||
|
||||
define void @call_constant_underflow_memset() safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_constant_underflow_memset
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr [10 x i8], [10 x i8]* %q, i32 0, i32 -1
|
||||
call void @llvm.memset.p0i8.i64(i8* %arraydecay, i8 1, i64 3, i32 1, i1 false)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Readnone nocapture -> safe
|
||||
define void @call_readnone(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_readnone
|
||||
; CHECK-NOT: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @readnone(i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Arg0 is readnone, arg1 is not. Pass alloca ptr as arg0 -> safe
|
||||
define void @call_readnone0_0(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_readnone0_0
|
||||
; CHECK-NOT: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @readnone0(i8* %arraydecay, i8* zeroinitializer)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Arg0 is readnone, arg1 is not. Pass alloca ptr as arg1 -> unsafe
|
||||
define void @call_readnone0_1(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_readnone0_1
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @readnone0(i8 *zeroinitializer, i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Readonly nocapture -> unsafe
|
||||
define void @call_readonly(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_readonly
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @readonly(i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Readonly nocapture -> unsafe
|
||||
define void @call_arg_readonly(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_arg_readonly
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @arg_readonly(i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Readwrite nocapture -> unsafe
|
||||
define void @call_readwrite(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_readwrite
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @readwrite(i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Captures the argument -> unsafe
|
||||
define void @call_capture(i64 %len) safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: define void @call_capture
|
||||
; CHECK: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%q = alloca [10 x i8], align 1
|
||||
%arraydecay = getelementptr inbounds [10 x i8], [10 x i8]* %q, i32 0, i32 0
|
||||
call void @capture(i8* %arraydecay)
|
||||
ret void
|
||||
}
|
||||
|
||||
; Lifetime intrinsics are always safe.
|
||||
define void @call_lifetime(i32* %p) {
|
||||
; CHECK-LABEL: define void @call_lifetime
|
||||
; CHECK-NOT: @__safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
entry:
|
||||
%q = alloca [100 x i8], align 16
|
||||
%0 = bitcast [100 x i8]* %q to i8*
|
||||
call void @llvm.lifetime.start.p0i8(i64 100, i8* %0)
|
||||
call void @llvm.lifetime.end.p0i8(i64 100, i8* %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @readonly(i8* nocapture) readonly
|
||||
declare void @arg_readonly(i8* readonly nocapture)
|
||||
declare void @readwrite(i8* nocapture)
|
||||
declare void @capture(i8* readnone) readnone
|
||||
|
||||
declare void @readnone(i8* nocapture) readnone
|
||||
declare void @readnone0(i8* nocapture readnone, i8* nocapture)
|
||||
|
||||
declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i32, i1) nounwind argmemonly
|
||||
|
||||
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) nounwind argmemonly
|
||||
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) nounwind argmemonly
|
@ -1,39 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; PtrToInt/IntToPtr Cast
|
||||
|
||||
define void @IntToPtr() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: @IntToPtr(
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret void
|
||||
%a = alloca i32, align 4
|
||||
%0 = ptrtoint i32* %a to i64
|
||||
%1 = inttoptr i64 %0 to i32*
|
||||
ret void
|
||||
}
|
||||
|
||||
define i8 @BitCastNarrow() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: @BitCastNarrow(
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i8
|
||||
%a = alloca i32, align 4
|
||||
%0 = bitcast i32* %a to i8*
|
||||
%1 = load i8, i8* %0, align 1
|
||||
ret i8 %1
|
||||
}
|
||||
|
||||
define i64 @BitCastWide() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-LABEL: @BitCastWide(
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
; CHECK: ret i64
|
||||
%a = alloca i32, align 4
|
||||
%0 = bitcast i32* %a to i64*
|
||||
%1 = load i64, i64* %0, align 1
|
||||
ret i64 %1
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
; RUN: opt -safe-stack -safe-stack-coloring=1 -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
; %x and %y share a stack slot between them, but not with the stack guard.
|
||||
define void @f() safestack sspreq {
|
||||
; CHECK-LABEL: define void @f
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
; CHECK: getelementptr i8, i8* %[[USP]], i32 -16
|
||||
|
||||
; CHECK: %[[A:.*]] = getelementptr i8, i8* %[[USP]], i32 -8
|
||||
; CHECK: %[[StackGuardSlot:.*]] = bitcast i8* %[[A]] to i8**
|
||||
; CHECK: store i8* %{{.*}}, i8** %[[StackGuardSlot]]
|
||||
|
||||
%x = alloca i64, align 8
|
||||
%y = alloca i64, align 8
|
||||
%x0 = bitcast i64* %x to i8*
|
||||
%y0 = bitcast i64* %y to i8*
|
||||
|
||||
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %x0)
|
||||
; CHECK: getelementptr i8, i8* %[[USP]], i32 -16
|
||||
call void @capture64(i64* %x)
|
||||
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %x0)
|
||||
|
||||
call void @llvm.lifetime.start.p0i8(i64 -1, i8* %y0)
|
||||
; CHECK: getelementptr i8, i8* %[[USP]], i32 -16
|
||||
call void @capture64(i64* %y)
|
||||
call void @llvm.lifetime.end.p0i8(i64 -1, i8* %y0)
|
||||
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
|
||||
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
|
||||
declare void @capture64(i64*)
|
@ -1,44 +0,0 @@
|
||||
; RUN: opt -safe-stack -safe-stack-coloring=1 -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -safe-stack-coloring=1 -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
define void @f() safestack {
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
; CHECK: %[[USST:.*]] = getelementptr i8, i8* %[[USP]], i32 -16
|
||||
|
||||
%x = alloca i32, align 4
|
||||
%x1 = alloca i32, align 4
|
||||
%x2 = alloca i32, align 4
|
||||
%0 = bitcast i32* %x to i8*
|
||||
call void @llvm.lifetime.start.p0i8(i64 4, i8* %0)
|
||||
|
||||
; CHECK: %[[A1:.*]] = getelementptr i8, i8* %[[USP]], i32 -4
|
||||
; CHECK: %[[A2:.*]] = bitcast i8* %[[A1]] to i32*
|
||||
; CHECK: call void @capture(i32* nonnull %[[A2]])
|
||||
|
||||
call void @capture(i32* nonnull %x)
|
||||
call void @llvm.lifetime.end.p0i8(i64 4, i8* %0)
|
||||
%1 = bitcast i32* %x1 to i8*
|
||||
call void @llvm.lifetime.start.p0i8(i64 4, i8* %1)
|
||||
|
||||
; CHECK: %[[B1:.*]] = getelementptr i8, i8* %[[USP]], i32 -4
|
||||
; CHECK: %[[B2:.*]] = bitcast i8* %[[B1]] to i32*
|
||||
; CHECK: call void @capture(i32* nonnull %[[B2]])
|
||||
|
||||
call void @capture(i32* nonnull %x1)
|
||||
call void @llvm.lifetime.end.p0i8(i64 4, i8* %1)
|
||||
%2 = bitcast i32* %x2 to i8*
|
||||
call void @llvm.lifetime.start.p0i8(i64 4, i8* %2)
|
||||
|
||||
; CHECK: %[[C1:.*]] = getelementptr i8, i8* %[[USP]], i32 -4
|
||||
; CHECK: %[[C2:.*]] = bitcast i8* %[[C1]] to i32*
|
||||
; CHECK: call void @capture(i32* nonnull %[[C2]])
|
||||
|
||||
call void @capture(i32* nonnull %x2)
|
||||
call void @llvm.lifetime.end.p0i8(i64 4, i8* %2)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture)
|
||||
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture)
|
||||
declare void @capture(i32*)
|
File diff suppressed because it is too large
Load Diff
@ -1,26 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
%struct.nest = type { %struct.pair, %struct.pair }
|
||||
%struct.pair = type { i32, i32 }
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; Nested structure, no arrays, no address-of expressions.
|
||||
; Verify that the resulting gep-of-gep does not incorrectly trigger
|
||||
; a safe stack protector.
|
||||
; safestack attribute
|
||||
; Requires no protector.
|
||||
; CHECK-LABEL: @foo(
|
||||
define void @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
%c = alloca %struct.nest, align 4
|
||||
%b = getelementptr inbounds %struct.nest, %struct.nest* %c, i32 0, i32 1
|
||||
%_a = getelementptr inbounds %struct.pair, %struct.pair* %b, i32 0, i32 0
|
||||
%0 = load i32, i32* %_a, align 4
|
||||
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(i8*, ...)
|
@ -1,20 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
%class.A = type { [2 x i8] }
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; [2 x i8] in a class
|
||||
; safestack attribute
|
||||
; Requires no protector.
|
||||
; CHECK-LABEL: @foo(
|
||||
define signext i8 @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
%a = alloca %class.A, align 1
|
||||
%array = getelementptr inbounds %class.A, %class.A* %a, i32 0, i32 0
|
||||
%arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %array, i32 0, i64 0
|
||||
%0 = load i8, i8* %arrayidx, align 1
|
||||
ret i8 %0
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
%struct.deep = type { %union.anon }
|
||||
%union.anon = type { %struct.anon }
|
||||
%struct.anon = type { %struct.anon.0 }
|
||||
%struct.anon.0 = type { %union.anon.1 }
|
||||
%union.anon.1 = type { [2 x i8] }
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; [2 x i8] nested in several layers of structs and unions
|
||||
; safestack attribute
|
||||
; Requires no protector.
|
||||
; CHECK-LABEL: @foo(
|
||||
define signext i8 @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK-NOT: __safestack_unsafe_stack_ptr
|
||||
%x = alloca %struct.deep, align 1
|
||||
%b = getelementptr inbounds %struct.deep, %struct.deep* %x, i32 0, i32 0
|
||||
%c = bitcast %union.anon* %b to %struct.anon*
|
||||
%d = getelementptr inbounds %struct.anon, %struct.anon* %c, i32 0, i32 0
|
||||
%e = getelementptr inbounds %struct.anon.0, %struct.anon.0* %d, i32 0, i32 0
|
||||
%array = bitcast %union.anon.1* %e to [2 x i8]*
|
||||
%arrayidx = getelementptr inbounds [2 x i8], [2 x i8]* %array, i32 0, i64 0
|
||||
%0 = load i8, i8* %arrayidx, align 1
|
||||
ret i8 %0
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
; Test llvm.dbg.value for dynamic allocas moved onto the unsafe stack.
|
||||
; In the dynamic alloca case, the dbg.value does not change with the exception
|
||||
; of the alloca pointer in the first argument being replaced with the new stack
|
||||
; top address.
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
define void @f(i32 %n) safestack !dbg !6 {
|
||||
entry:
|
||||
tail call void @llvm.dbg.value(metadata i32 %n, metadata !11, metadata !14), !dbg !15
|
||||
%0 = zext i32 %n to i64, !dbg !16
|
||||
|
||||
; CHECK: store i8* %[[VLA:.*]], i8** @__safestack_unsafe_stack_ptr
|
||||
; CHECK: tail call void @llvm.dbg.value(metadata i8* %[[VLA]], metadata ![[TYPE:.*]], metadata !DIExpression(DW_OP_deref))
|
||||
; CHECK: call void @capture({{.*}} %[[VLA]])
|
||||
|
||||
%vla = alloca i8, i64 %0, align 16, !dbg !16
|
||||
tail call void @llvm.dbg.value(metadata i8* %vla, metadata !12, metadata !17), !dbg !18
|
||||
call void @capture(i8* nonnull %vla), !dbg !19
|
||||
ret void, !dbg !20
|
||||
}
|
||||
|
||||
declare void @capture(i8*)
|
||||
declare void @llvm.dbg.value(metadata, metadata, metadata)
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3, !4}
|
||||
!llvm.ident = !{!5}
|
||||
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 272832) (llvm/trunk 272831)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
|
||||
!1 = !DIFile(filename: "../llvm/1.cc", directory: "/code/build-llvm")
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{!"clang version 3.9.0 (trunk 272832) (llvm/trunk 272831)"}
|
||||
!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fi", scope: !1, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !10)
|
||||
!7 = !DISubroutineType(types: !8)
|
||||
!8 = !{null, !9}
|
||||
!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
||||
!10 = !{!11, !12}
|
||||
!11 = !DILocalVariable(name: "n", arg: 1, scope: !6, file: !1, line: 2, type: !9)
|
||||
|
||||
; CHECK-DAG: ![[TYPE]] = !DILocalVariable(name: "x",
|
||||
!12 = !DILocalVariable(name: "x", scope: !6, file: !1, line: 3, type: !13)
|
||||
!13 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
|
||||
!14 = !DIExpression()
|
||||
!15 = !DILocation(line: 2, column: 12, scope: !6)
|
||||
!16 = !DILocation(line: 3, column: 3, scope: !6)
|
||||
|
||||
!17 = !DIExpression(DW_OP_deref)
|
||||
!18 = !DILocation(line: 3, column: 8, scope: !6)
|
||||
!19 = !DILocation(line: 4, column: 3, scope: !6)
|
||||
!20 = !DILocation(line: 5, column: 1, scope: !6)
|
@ -1,80 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
; Test debug location for the local variables moved onto the unsafe stack.
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
%struct.S = type { [100 x i8] }
|
||||
|
||||
; Function Attrs: safestack uwtable
|
||||
define void @f(%struct.S* byval align 8 %zzz) #0 !dbg !12 {
|
||||
; CHECK: define void @f
|
||||
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
|
||||
%xxx = alloca %struct.S, align 1
|
||||
call void @llvm.dbg.declare(metadata %struct.S* %zzz, metadata !18, metadata !19), !dbg !20
|
||||
call void @llvm.dbg.declare(metadata %struct.S* %xxx, metadata !21, metadata !19), !dbg !22
|
||||
|
||||
; dbg.declare for %zzz and %xxx are gone; replaced with dbg.declare based off the unsafe stack pointer
|
||||
; CHECK-NOT: call void @llvm.dbg.declare
|
||||
; CHECK: call void @llvm.dbg.declare(metadata i8* %[[USP]], metadata ![[VAR_ARG:.*]], metadata !DIExpression(DW_OP_constu, 104, DW_OP_minus))
|
||||
; CHECK-NOT: call void @llvm.dbg.declare
|
||||
; CHECK: call void @llvm.dbg.declare(metadata i8* %[[USP]], metadata ![[VAR_LOCAL:.*]], metadata !DIExpression(DW_OP_constu, 208, DW_OP_minus))
|
||||
; CHECK-NOT: call void @llvm.dbg.declare
|
||||
|
||||
call void @Capture(%struct.S* %zzz), !dbg !23
|
||||
call void @Capture(%struct.S* %xxx), !dbg !24
|
||||
|
||||
; dbg.declare appears before the first use
|
||||
; CHECK: call void @Capture
|
||||
; CHECK: call void @Capture
|
||||
|
||||
ret void, !dbg !25
|
||||
}
|
||||
|
||||
; CHECK-DAG: ![[VAR_ARG]] = !DILocalVariable(name: "zzz"
|
||||
; 100 aligned up to 8
|
||||
|
||||
; CHECK-DAG: ![[VAR_LOCAL]] = !DILocalVariable(name: "xxx"
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
|
||||
|
||||
declare void @Capture(%struct.S*) #2
|
||||
|
||||
attributes #0 = { safestack uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #1 = { nounwind readnone }
|
||||
attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!15, !16}
|
||||
!llvm.ident = !{!17}
|
||||
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 254019) (llvm/trunk 254036)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
|
||||
!1 = !DIFile(filename: "../llvm/2.cc", directory: "/code/build-llvm")
|
||||
!2 = !{}
|
||||
!3 = !{!4}
|
||||
!4 = !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 4, size: 800, align: 8, elements: !5, identifier: "_ZTS1S")
|
||||
!5 = !{!6}
|
||||
!6 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !4, file: !1, line: 5, baseType: !7, size: 800, align: 8)
|
||||
!7 = !DICompositeType(tag: DW_TAG_array_type, baseType: !8, size: 800, align: 8, elements: !9)
|
||||
!8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
|
||||
!9 = !{!10}
|
||||
!10 = !DISubrange(count: 100)
|
||||
!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1f1S", scope: !1, file: !1, line: 10, type: !13, isLocal: false, isDefinition: true, scopeLine: 10, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
|
||||
!13 = !DISubroutineType(types: !14)
|
||||
!14 = !{null, !4}
|
||||
!15 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!16 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!17 = !{!"clang version 3.8.0 (trunk 254019) (llvm/trunk 254036)"}
|
||||
!18 = !DILocalVariable(name: "zzz", arg: 1, scope: !12, file: !1, line: 10, type: !4)
|
||||
!19 = !DIExpression()
|
||||
!20 = !DILocation(line: 10, column: 10, scope: !12)
|
||||
!21 = !DILocalVariable(name: "xxx", scope: !12, file: !1, line: 11, type: !4)
|
||||
!22 = !DILocation(line: 11, column: 5, scope: !12)
|
||||
!23 = !DILocation(line: 12, column: 3, scope: !12)
|
||||
!24 = !DILocation(line: 13, column: 3, scope: !12)
|
||||
!25 = !DILocation(line: 14, column: 1, scope: !12)
|
@ -1,96 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
; Test llvm.dbg.value for the local variables moved onto the unsafe stack.
|
||||
; SafeStack rewrites them relative to the unsafe stack pointer (base address of
|
||||
; the unsafe stack frame).
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
; Function Attrs: noinline safestack uwtable
|
||||
define void @f() #0 !dbg !6 {
|
||||
entry:
|
||||
; CHECK: %[[USP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
%x1 = alloca i32, align 4
|
||||
%x2 = alloca i32, align 4
|
||||
%0 = bitcast i32* %x1 to i8*, !dbg !13
|
||||
%1 = bitcast i32* %x2 to i8*, !dbg !14
|
||||
|
||||
; Unhandled dbg.value: expression does not start with OP_DW_deref
|
||||
; CHECK: call void @llvm.dbg.value(metadata ![[EMPTY:.*]], metadata !{{.*}}, metadata !{{.*}})
|
||||
tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !23), !dbg !16
|
||||
|
||||
; Unhandled dbg.value: expression does not start with OP_DW_deref
|
||||
; CHECK: call void @llvm.dbg.value(metadata ![[EMPTY]], metadata !{{.*}}, metadata !{{.*}})
|
||||
tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !24), !dbg !16
|
||||
|
||||
; Supported dbg.value: rewritted based on the [[USP]] value.
|
||||
; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X1:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_constu, 4, DW_OP_minus))
|
||||
tail call void @llvm.dbg.value(metadata i32* %x1, metadata !10, metadata !15), !dbg !16
|
||||
call void @capture(i32* nonnull %x1), !dbg !17
|
||||
|
||||
; An extra non-dbg.value metadata use of %x2. Replaced with an empty metadata.
|
||||
; CHECK: call void @llvm.random.metadata.use(metadata ![[EMPTY]])
|
||||
call void @llvm.random.metadata.use(metadata i32* %x2)
|
||||
|
||||
; CHECK: call void @llvm.dbg.value(metadata i8* %[[USP]], metadata ![[X2:.*]], metadata !DIExpression(DW_OP_deref, DW_OP_constu, 8, DW_OP_minus))
|
||||
call void @llvm.dbg.value(metadata i32* %x2, metadata !12, metadata !15), !dbg !18
|
||||
call void @capture(i32* nonnull %x2), !dbg !19
|
||||
ret void, !dbg !20
|
||||
}
|
||||
|
||||
; Function Attrs: argmemonly nounwind
|
||||
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
|
||||
|
||||
declare void @capture(i32*) #2
|
||||
|
||||
; Function Attrs: argmemonly nounwind
|
||||
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
|
||||
|
||||
; Function Attrs: nounwind readnone
|
||||
declare void @llvm.dbg.value(metadata, metadata, metadata) #3
|
||||
|
||||
declare void @llvm.random.metadata.use(metadata)
|
||||
|
||||
attributes #0 = { noinline safestack uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #1 = { argmemonly nounwind }
|
||||
attributes #2 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
|
||||
attributes #3 = { nounwind readnone }
|
||||
attributes #4 = { nounwind }
|
||||
|
||||
!llvm.dbg.cu = !{!0}
|
||||
!llvm.module.flags = !{!3, !4}
|
||||
!llvm.ident = !{!5}
|
||||
|
||||
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 271022) (llvm/trunk 271027)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
|
||||
!1 = !DIFile(filename: "../llvm/2.cc", directory: "/code/build-llvm")
|
||||
|
||||
; CHECK-DAG: ![[EMPTY]] = !{}
|
||||
!2 = !{}
|
||||
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
||||
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
||||
!5 = !{!"clang version 3.9.0 (trunk 271022) (llvm/trunk 271027)"}
|
||||
!6 = distinct !DISubprogram(name: "f", linkageName: "_Z1fv", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !9)
|
||||
!7 = !DISubroutineType(types: !8)
|
||||
!8 = !{null}
|
||||
!9 = !{!10, !12}
|
||||
|
||||
; CHECK-DAG: ![[X1]] = !DILocalVariable(name: "x1",
|
||||
!10 = !DILocalVariable(name: "x1", scope: !6, file: !1, line: 5, type: !11)
|
||||
!11 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
|
||||
|
||||
; CHECK-DAG: ![[X2]] = !DILocalVariable(name: "x2",
|
||||
!12 = !DILocalVariable(name: "x2", scope: !6, file: !1, line: 6, type: !11)
|
||||
!13 = !DILocation(line: 5, column: 3, scope: !6)
|
||||
!14 = !DILocation(line: 6, column: 3, scope: !6)
|
||||
|
||||
!15 = !DIExpression(DW_OP_deref)
|
||||
!16 = !DILocation(line: 5, column: 7, scope: !6)
|
||||
!17 = !DILocation(line: 8, column: 3, scope: !6)
|
||||
!18 = !DILocation(line: 6, column: 7, scope: !6)
|
||||
!19 = !DILocation(line: 9, column: 3, scope: !6)
|
||||
!20 = !DILocation(line: 10, column: 1, scope: !6)
|
||||
!21 = !DILocation(line: 10, column: 1, scope: !22)
|
||||
!22 = !DILexicalBlockFile(scope: !6, file: !1, discriminator: 1)
|
||||
!23 = !DIExpression()
|
||||
!24 = !DIExpression(DW_OP_constu, 42, DW_OP_minus)
|
@ -1,22 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; Variable sized alloca
|
||||
; safestack attribute
|
||||
; Requires protector.
|
||||
define void @foo(i32 %n) nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: %[[SP:.*]] = load i8*, i8** @__safestack_unsafe_stack_ptr
|
||||
%n.addr = alloca i32, align 4
|
||||
%a = alloca i32*, align 8
|
||||
store i32 %n, i32* %n.addr, align 4
|
||||
%0 = load i32, i32* %n.addr, align 4
|
||||
%conv = sext i32 %0 to i64
|
||||
%1 = alloca i8, i64 %conv
|
||||
%2 = bitcast i8* %1 to i32*
|
||||
store i32* %2, i32** %a, align 8
|
||||
; CHECK: store i8* %[[SP:.*]], i8** @__safestack_unsafe_stack_ptr
|
||||
ret void
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; Addr-of a pointer
|
||||
; safestack attribute
|
||||
; Requires protector.
|
||||
define void @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
%a = alloca i32*, align 8
|
||||
%b = alloca i32**, align 8
|
||||
%call = call i32* @getp()
|
||||
store i32* %call, i32** %a, align 8
|
||||
store i32** %a, i32*** %b, align 8
|
||||
%0 = load i32**, i32*** %b, align 8
|
||||
call void @funcall2(i32** %0)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare void @funcall2(i32**)
|
||||
declare i32* @getp()
|
@ -1,23 +0,0 @@
|
||||
; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
|
||||
|
||||
@.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
|
||||
|
||||
; Addr-of a local cast to a ptr of a different type
|
||||
; (e.g., int a; ... ; float *b = &a;)
|
||||
; safestack attribute
|
||||
; Requires protector.
|
||||
define void @foo() nounwind uwtable safestack {
|
||||
entry:
|
||||
; CHECK: __safestack_unsafe_stack_ptr
|
||||
%a = alloca i32, align 4
|
||||
%b = alloca float*, align 8
|
||||
store i32 0, i32* %a, align 4
|
||||
%0 = bitcast i32* %a to float*
|
||||
store float* %0, float** %b, align 8
|
||||
%1 = load float*, float** %b, align 8
|
||||
%call = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), float* %1)
|
||||
ret void
|
||||
}
|
||||
|
||||
declare i32 @printf(i8*, ...)
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user