diff options
author | Pengxuan Zheng <pzheng@quicinc.com> | 2021-05-17 12:16:07 -0700 |
---|---|---|
committer | Pengxuan Zheng <pzheng@quicinc.com> | 2021-05-30 00:52:48 -0700 |
commit | 056733d0195b28fb1c5a7952b2adc10013edf19c (patch) | |
tree | 33af0b4ec9d83cb23aa6315fa93c5e83cee78f08 /llvm/lib/CodeGen/SafeStack.cpp | |
parent | 71cca4f728d7421e40ec9aec0816313391fe9b59 (diff) | |
download | llvm-056733d0195b28fb1c5a7952b2adc10013edf19c.zip llvm-056733d0195b28fb1c5a7952b2adc10013edf19c.tar.gz llvm-056733d0195b28fb1c5a7952b2adc10013edf19c.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/CodeGen/SafeStack.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SafeStack.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/SafeStack.cpp b/llvm/lib/CodeGen/SafeStack.cpp index 3680617..e097843d 100644 --- a/llvm/lib/CodeGen/SafeStack.cpp +++ b/llvm/lib/CodeGen/SafeStack.cpp @@ -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"); } |