[SafeStack] Use proper API to get stack guard
Using the proper API automatically sets `__stack_chk_guard` to `dso_local` if `Reloc::Static`. This wasn't strictly necessary until recently when dso_local was no longer implied by `TargetMachine::shouldAssumeDSOLocal` for `__stack_chk_guard`. By using the proper API, we can avoid generating unnecessary GOT relocations. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D102646
This commit is contained in:
parent
71cca4f728
commit
056733d019
|
@ -373,9 +373,13 @@ bool SafeStack::IsSafeStackAlloca(const Value *AllocaPtr, uint64_t AllocaSize) {
|
|||
|
||||
Value *SafeStack::getStackGuard(IRBuilder<> &IRB, Function &F) {
|
||||
Value *StackGuardVar = TL.getIRStackGuard(IRB);
|
||||
if (!StackGuardVar)
|
||||
StackGuardVar =
|
||||
F.getParent()->getOrInsertGlobal("__stack_chk_guard", StackPtrTy);
|
||||
Module *M = F.getParent();
|
||||
|
||||
if (!StackGuardVar) {
|
||||
TL.insertSSPDeclarations(*M);
|
||||
return IRB.CreateCall(Intrinsic::getDeclaration(M, Intrinsic::stackguard));
|
||||
}
|
||||
|
||||
return IRB.CreateLoad(StackPtrTy, StackGuardVar, "StackGuard");
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ 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
|
||||
; GLOBAL32: %[[StackGuard:.*]] = call i8* @llvm.stackguard()
|
||||
; COMMON: store i8* %[[StackGuard]], i8** %[[StackGuardSlot:.*]]
|
||||
%a = alloca i8, align 1
|
||||
call void @Capture(i8* %a)
|
||||
|
|
|
@ -8,7 +8,7 @@ entry:
|
|||
|
||||
; CHECK: %[[A:.*]] = getelementptr i8, i8* %[[USP]], i32 -8
|
||||
; CHECK: %[[StackGuardSlot:.*]] = bitcast i8* %[[A]] to i8**
|
||||
; CHECK: %[[StackGuard:.*]] = load i8*, i8** @__stack_chk_guard
|
||||
; CHECK: %[[StackGuard:.*]] = call i8* @llvm.stackguard()
|
||||
; CHECK: store i8* %[[StackGuard]], i8** %[[StackGuardSlot]]
|
||||
%a = alloca i8, align 1
|
||||
|
||||
|
|
Loading…
Reference in New Issue