Skip to content

Commit

Permalink
[SSP] Do not set __guard_local to hidden for OpenBSD SSP
Browse files Browse the repository at this point in the history
__guard_local is defined as long on OpenBSD. If the source file contains
a definition of __guard_local, it mismatches with the int8 pointer type
used in LLVM. In that case, Module::getOrInsertGlobal() returns a
cast operation instead of a GlobalVariable. Trying to set the
visibility on the cast operation leads to random segfaults (seen when
compiling the OpenBSD kernel, which also runs with stack protection).

In the kernel, the hidden attribute does not matter. For userspace code,
__guard_local is defined as hidden in the startup code. If a program
re-defines __guard_local, the definition from the startup code will
either win or the linker complains about multiple definitions
(depending on whether the re-defined __guard_local is placed in the
common segment or not).

It also matches what gcc on OpenBSD does.

Thanks Stefan Kempf <[email protected]> for the patch!

Differential Revision: http://reviews.llvm.org/D23674

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279449 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
timshen91 committed Aug 22, 2016
1 parent 11ee15b commit 06e3fec
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,9 +1817,7 @@ Value *TargetLoweringBase::getIRStackGuard(IRBuilder<> &IRB) const {
if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
PointerType *PtrTy = Type::getInt8PtrTy(M.getContext());
auto Guard = cast<GlobalValue>(M.getOrInsertGlobal("__guard_local", PtrTy));
Guard->setVisibility(GlobalValue::HiddenVisibility);
return Guard;
return M.getOrInsertGlobal("__guard_local", PtrTy);
}
return nullptr;
}
Expand Down

0 comments on commit 06e3fec

Please sign in to comment.