[PATCH] D23674: Do not set __guard_local to hidden for OpenBSD SSP

Stefan Kempf via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 09:21:46 PDT 2016


sisnkemp created this revision.
sisnkemp added a reviewer: timshen.
sisnkemp added subscribers: timshen, sisnkemp, llvm-commits.

__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.


https://reviews.llvm.org/D23674

Files:
  lib/CodeGen/TargetLoweringBase.cpp

Index: lib/CodeGen/TargetLoweringBase.cpp
===================================================================
--- lib/CodeGen/TargetLoweringBase.cpp
+++ lib/CodeGen/TargetLoweringBase.cpp
@@ -1817,9 +1817,7 @@
   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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23674.68554.patch
Type: text/x-patch
Size: 642 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160818/42070fc1/attachment.bin>


More information about the llvm-commits mailing list