[PATCH] D102646: [SafeStack] Use proper API to get stack guard

Pengxuan Zheng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 30 00:54:02 PDT 2021


This revision was automatically updated to reflect the committed changes.
Closed by commit rG056733d0195b: [SafeStack] Use proper API to get stack guard (authored by pzheng).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102646/new/

https://reviews.llvm.org/D102646

Files:
  llvm/lib/CodeGen/SafeStack.cpp
  llvm/test/Transforms/SafeStack/X86/abi_ssp.ll
  llvm/test/Transforms/SafeStack/X86/ssp.ll


Index: llvm/test/Transforms/SafeStack/X86/ssp.ll
===================================================================
--- llvm/test/Transforms/SafeStack/X86/ssp.ll
+++ llvm/test/Transforms/SafeStack/X86/ssp.ll
@@ -8,7 +8,7 @@
 
 ; 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
 
Index: llvm/test/Transforms/SafeStack/X86/abi_ssp.ll
===================================================================
--- llvm/test/Transforms/SafeStack/X86/abi_ssp.ll
+++ llvm/test/Transforms/SafeStack/X86/abi_ssp.ll
@@ -13,7 +13,7 @@
 ; 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)
Index: llvm/lib/CodeGen/SafeStack.cpp
===================================================================
--- llvm/lib/CodeGen/SafeStack.cpp
+++ llvm/lib/CodeGen/SafeStack.cpp
@@ -373,9 +373,13 @@
 
 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");
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102646.348676.patch
Type: text/x-patch
Size: 2057 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210530/fc347f4a/attachment.bin>


More information about the llvm-commits mailing list