[llvm-commits] [PATCH] Make use of OpenBSD's libc routines for stack protector

Eli Friedman eli.friedman at gmail.com
Mon Aug 13 15:28:03 PDT 2012


On Mon, Aug 13, 2012 at 3:10 PM, Brad Smith <brad at comstyle.com> wrote:
> On Sat, Aug 11, 2012 at 03:49:15AM -0400, Brad Smith wrote:
>> On Thu, Aug 09, 2012 at 01:40:14AM -0700, Eli Friedman wrote:
>> > On Thu, Aug 9, 2012 at 12:52 AM, Brad Smith <brad at comstyle.com> wrote:
>> > > This makes LLVM use OpenBSD's libc routines for stack protector.
>> >
>> > +#if defined(__OpenBSD__)
>> >
>> > This is wrong; you want to check if the target is OpenBSD, not if the
>> > host is OpenBSD.
>>
>> You're right. How about this?
>
> Ok, here is the diff with a test addition.

+        if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS()
== llvm::Triple::OpenBSD)
+          StackGuardVar = M->getOrInsertGlobal("__guard", PtrTy);

80 columns.  (Also elsewhere.)

+  if (Triple(TLI->getTargetMachine().getTargetTriple()).getOS() ==
llvm::Triple::OpenBSD) {
+    Constant *StackChkFail =
+      M->getOrInsertFunction("__stack_smash_handler",
+                             Type::getVoidTy(F->getContext()), NULL);
+    Constant *G = new GlobalVariable(*M,
+                          ArrayType::get(Type::getInt1Ty(F->getContext()),
+                          F->getName().size() + 1),
+                          true, GlobalVariable::PrivateLinkage,
+                          ConstantDataArray::getString(F->getContext(),
+                                  F->getName(), true),
+                           "SSH", false, 0);
+    CallInst::Create(StackChkFail, G, "", FailBB);

You're declaring a global of type [N x i1], and initializing it with
an initializer of type [N x i8].  Also this doesn't compile on trunk.

-Eli



More information about the llvm-commits mailing list