Make __stack_chk_guard dso_local if Reloc::Static

This is currently implied by TargetMachine::shouldAssumeDSOLocal
but will be changed in the future.
This commit is contained in:
Fangrui Song 2020-12-04 16:57:45 -08:00
parent 54971c3a75
commit 2518433f86
1 changed files with 7 additions and 4 deletions

View File

@ -1969,10 +1969,13 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const {
// Currently only support "standard" __stack_chk_guard.
// TODO: add LOAD_STACK_GUARD support.
void TargetLoweringBase::insertSSPDeclarations(Module &M) const {
if (!M.getNamedValue("__stack_chk_guard"))
new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
GlobalVariable::ExternalLinkage,
nullptr, "__stack_chk_guard");
if (!M.getNamedValue("__stack_chk_guard")) {
auto *GV = new GlobalVariable(M, Type::getInt8PtrTy(M.getContext()), false,
GlobalVariable::ExternalLinkage, nullptr,
"__stack_chk_guard");
if (getTargetMachine().getRelocationModel() == Reloc::Static)
GV->setDSOLocal(true);
}
}
// Currently only support "standard" __stack_chk_guard.