[llvm-commits] [llvm] r161446 - /llvm/trunk/lib/CodeGen/StackProtector.cpp

Aaron Ballman aaron at aaronballman.com
Tue Aug 7 14:20:08 PDT 2012


Do we know why gcc does this?  I'm all for compatibility, but it seems
like it's taking away a fairly nice safety feature so I am hoping
there's some more logic here.

~Aaron

On Tue, Aug 7, 2012 at 4:59 PM, Bill Wendling <isanbard at gmail.com> wrote:
> Author: void
> Date: Tue Aug  7 15:59:05 2012
> New Revision: 161446
>
> URL: http://llvm.org/viewvc/llvm-project?rev=161446&view=rev
> Log:
> For non-Darwin platforms, we want to generate stack protectors only for
> character arrays. This is in line with what GCC does.
> <rdar://problem/10529227>
>
> Modified:
>     llvm/trunk/lib/CodeGen/StackProtector.cpp
>
> Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=161446&r1=161445&r2=161446&view=diff
> ==============================================================================
> --- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
> +++ llvm/trunk/lib/CodeGen/StackProtector.cpp Tue Aug  7 15:59:05 2012
> @@ -28,6 +28,7 @@
>  #include "llvm/Support/CommandLine.h"
>  #include "llvm/Target/TargetData.h"
>  #include "llvm/Target/TargetLowering.h"
> +#include "llvm/ADT/Triple.h"
>  using namespace llvm;
>
>  // SSPBufferSize - The lower bound for a buffer to be considered for stack
> @@ -111,6 +112,8 @@
>      return false;
>
>    const TargetData *TD = TLI->getTargetData();
> +  const TargetMachine &TM = TLI->getTargetMachine();
> +  Triple Trip(TM.getTargetTriple());
>
>    for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
>      BasicBlock *BB = I;
> @@ -123,11 +126,17 @@
>            // protectors.
>            return true;
>
> -        if (ArrayType *AT = dyn_cast<ArrayType>(AI->getAllocatedType()))
> +        if (ArrayType *AT = dyn_cast<ArrayType>(AI->getAllocatedType())) {
> +          // If we're on a non-Darwin platform, don't add stack protectors
> +          // unless the array is a character array.
> +          if (!Trip.isOSDarwin() && !AT->getElementType()->isIntegerTy(8))
> +            continue;
> +
>            // If an array has more than SSPBufferSize bytes of allocated space,
>            // then we emit stack protectors.
>            if (SSPBufferSize <= TD->getTypeAllocSize(AT))
>              return true;
> +        }
>        }
>    }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list