Currently, clang generates references to __guard_local as if it had 
default visibility.  This is non-optimal on various archs, so lets tell 
clang that __guard_local is hidden.

I *think* this is the right way to tell clang this and it seems to work on 
amd64, generating
        movq    __guard_local(%rip), %rax
instead of
        movq    __guard_local@GOTPCREL(%rip), %rax

Is this the right way to do this in clang, or is there a cleaner way?


Philip

Index: lib/CodeGen/TargetLoweringBase.cpp
===================================================================
RCS file: /data/src/openbsd/src/gnu/llvm/lib/CodeGen/TargetLoweringBase.cpp,v
retrieving revision 1.2
diff -u -p -r1.2 TargetLoweringBase.cpp
--- lib/CodeGen/TargetLoweringBase.cpp  14 Jan 2017 20:04:01 -0000      1.2
+++ lib/CodeGen/TargetLoweringBase.cpp  19 Jan 2017 23:25:08 -0000
@@ -1818,7 +1818,10 @@ Value *TargetLoweringBase::getIRStackGua
   if (getTargetMachine().getTargetTriple().isOSOpenBSD()) {
     Module &M = *IRB.GetInsertBlock()->getParent()->getParent();
     PointerType *PtrTy = Type::getInt8PtrTy(M.getContext());
-    return M.getOrInsertGlobal("__guard_local", PtrTy);
+    Constant *C = M.getOrInsertGlobal("__guard_local", PtrTy);
+    if (GlobalVariable *G = dyn_cast_or_null<GlobalVariable>(C))
+      G->setVisibility(GlobalValue::HiddenVisibility);
+    return C;
   }
   return nullptr;
 }

Reply via email to