[llvm-commits] [llvm] r59202 - in /llvm/trunk: include/llvm/Attributes.h include/llvm/CodeGen/Passes.h lib/AsmParser/LLLexer.cpp lib/AsmParser/llvmAsmParser.y lib/CodeGen/LLVMTargetMachine.cpp lib/CodeGen/StackProtector.cpp lib/VMCore/Attributes.cpp
Bill Wendling
isanbard at gmail.com
Wed Nov 12 17:02:19 PST 2008
Author: void
Date: Wed Nov 12 19:02:14 2008
New Revision: 59202
URL: http://llvm.org/viewvc/llvm-project?rev=59202&view=rev
Log:
Implement stack protectors as function attributes: "ssp" and "sspreq".
Modified:
llvm/trunk/include/llvm/Attributes.h
llvm/trunk/include/llvm/CodeGen/Passes.h
llvm/trunk/lib/AsmParser/LLLexer.cpp
llvm/trunk/lib/AsmParser/llvmAsmParser.y
llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
llvm/trunk/lib/CodeGen/StackProtector.cpp
llvm/trunk/lib/VMCore/Attributes.cpp
Modified: llvm/trunk/include/llvm/Attributes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Attributes.h?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Attributes.h (original)
+++ llvm/trunk/include/llvm/Attributes.h Wed Nov 12 19:02:14 2008
@@ -47,6 +47,8 @@
const Attributes NoInline = 1<<11; // inline=never
const Attributes AlwaysInline = 1<<12; // inline=always
const Attributes OptimizeForSize = 1<<13; // opt_size
+const Attributes StackProtect = 1<<14; // Stack protection.
+const Attributes StackProtectReq = 1<<15; // Stack protection required.
const Attributes Alignment = 0xffff<<16; ///< Alignment of parameter (16 bits)
// 0 = unknown, else in clear (not log)
@@ -55,7 +57,7 @@
/// @brief Attributes that only apply to function.
const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly |
- NoInline | AlwaysInline | OptimizeForSize;
+ NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq;
/// @brief Parameter attributes that do not apply to vararg call arguments.
const Attributes VarArgsIncompatible = StructRet;
Modified: llvm/trunk/include/llvm/CodeGen/Passes.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/Passes.h?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/Passes.h (original)
+++ llvm/trunk/include/llvm/CodeGen/Passes.h Wed Nov 12 19:02:14 2008
@@ -26,16 +26,6 @@
class TargetLowering;
class RegisterCoalescer;
- /// StackProtectorLevel - An enumeration for when to determin when to turn
- /// stack smashing protection (SSP) on.
- namespace SSP {
- enum StackProtectorLevel {
- OFF, // Stack protectors are off.
- SOME, // Stack protectors on only for functions that require them.
- ALL // Stack protectors on for all functions.
- };
- } // end SSP namespace
-
/// createUnreachableBlockEliminationPass - The LLVM code generator does not
/// work well with unreachable basic blocks (what live ranges make sense for a
/// block that cannot be reached?). As such, a code generator should either
@@ -204,8 +194,7 @@
FunctionPass *createStackSlotColoringPass();
/// createStackProtectorPass - This pass adds stack protectors to functions.
- FunctionPass *createStackProtectorPass(SSP::StackProtectorLevel lvl,
- const TargetLowering *tli);
+ FunctionPass *createStackProtectorPass(const TargetLowering *tli);
} // End llvm namespace
Modified: llvm/trunk/lib/AsmParser/LLLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLLexer.cpp?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLLexer.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLLexer.cpp Wed Nov 12 19:02:14 2008
@@ -499,6 +499,8 @@
KEYWORD("noinline", NOINLINE);
KEYWORD("alwaysinline", ALWAYSINLINE);
KEYWORD("optsize", OPTSIZE);
+ KEYWORD("ssp", SSP);
+ KEYWORD("sspreq", SSPREQ);
KEYWORD("type", TYPE);
KEYWORD("opaque", OPAQUE);
Modified: llvm/trunk/lib/AsmParser/llvmAsmParser.y
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/llvmAsmParser.y?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/llvmAsmParser.y (original)
+++ llvm/trunk/lib/AsmParser/llvmAsmParser.y Wed Nov 12 19:02:14 2008
@@ -1137,7 +1137,7 @@
// Function Attributes
%token SIGNEXT ZEROEXT NORETURN INREG SRET NOUNWIND NOALIAS BYVAL NEST
-%token READNONE READONLY GC OPTSIZE NOINLINE ALWAYSINLINE
+%token READNONE READONLY GC OPTSIZE NOINLINE ALWAYSINLINE SSP SSPREQ
// Visibility Styles
%token DEFAULT HIDDEN PROTECTED
@@ -1305,7 +1305,9 @@
| READONLY { $$ = Attribute::ReadOnly; }
| NOINLINE { $$ = Attribute::NoInline; }
| ALWAYSINLINE { $$ = Attribute::AlwaysInline; }
- | OPTSIZE { $$ = Attribute::OptimizeForSize; }
+ | OPTSIZE { $$ = Attribute::OptimizeForSize; }
+ | SSP { $$ = Attribute::StackProtect; }
+ | SSPREQ { $$ = Attribute::StackProtectReq; }
;
OptFuncAttrs : /* empty */ { $$ = Attribute::None; }
Modified: llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp (original)
+++ llvm/trunk/lib/CodeGen/LLVMTargetMachine.cpp Wed Nov 12 19:02:14 2008
@@ -60,19 +60,6 @@
EnableFastISelOption("fast-isel", cl::Hidden,
cl::desc("Enable the experimental \"fast\" instruction selector"));
-// Enable stack protectors.
-static cl::opt<SSP::StackProtectorLevel>
-EnableStackProtector("enable-stack-protector",
- cl::desc("Stack canary protection level: (default: off)"),
- cl::init(SSP::OFF),
- cl::values(clEnumValN(SSP::ALL, "all",
- "All functions get stack protectors."),
- clEnumValN(SSP::SOME, "some",
- "Only functions requiring stack protectors get them."),
- clEnumValN(SSP::OFF, "off",
- "No functions get stack protectors."),
- clEnumValEnd));
-
FileModel::Model
LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
raw_ostream &Out,
@@ -178,8 +165,7 @@
if (!Fast)
PM.add(createCodeGenPreparePass(getTargetLowering()));
- if (EnableStackProtector != SSP::OFF)
- PM.add(createStackProtectorPass(EnableStackProtector, getTargetLowering()));
+ PM.add(createStackProtectorPass(getTargetLowering()));
if (PrintISelInput)
PM.add(createPrintFunctionPass("\n\n"
Modified: llvm/trunk/lib/CodeGen/StackProtector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/StackProtector.cpp?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/StackProtector.cpp (original)
+++ llvm/trunk/lib/CodeGen/StackProtector.cpp Wed Nov 12 19:02:14 2008
@@ -16,6 +16,7 @@
#define DEBUG_TYPE "stack-protector"
#include "llvm/CodeGen/Passes.h"
+#include "llvm/Attributes.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Function.h"
@@ -37,9 +38,6 @@
namespace {
class VISIBILITY_HIDDEN StackProtector : public FunctionPass {
- /// Level - The level of stack protection.
- SSP::StackProtectorLevel Level;
-
/// TLI - Keep a pointer of a TargetLowering to consult for determining
/// target type sizes.
const TargetLowering *TLI;
@@ -64,9 +62,9 @@
bool RequiresStackProtector() const;
public:
static char ID; // Pass identification, replacement for typeid.
- StackProtector() : FunctionPass(&ID), Level(SSP::OFF), TLI(0) {}
- StackProtector(SSP::StackProtectorLevel lvl, const TargetLowering *tli)
- : FunctionPass(&ID), Level(lvl), TLI(tli) {}
+ StackProtector() : FunctionPass(&ID), TLI(0) {}
+ StackProtector(const TargetLowering *tli)
+ : FunctionPass(&ID), TLI(tli) {}
virtual bool runOnFunction(Function &Fn);
};
@@ -76,9 +74,8 @@
static RegisterPass<StackProtector>
X("stack-protector", "Insert stack protectors");
-FunctionPass *llvm::createStackProtectorPass(SSP::StackProtectorLevel lvl,
- const TargetLowering *tli) {
- return new StackProtector(lvl, tli);
+FunctionPass *llvm::createStackProtectorPass(const TargetLowering *tli) {
+ return new StackProtector(tli);
}
bool StackProtector::runOnFunction(Function &Fn) {
@@ -193,10 +190,10 @@
/// add a guard variable to functions that call alloca, and functions with
/// buffers larger than 8 bytes.
bool StackProtector::RequiresStackProtector() const {
- switch (Level) {
- default: return false;
- case SSP::ALL: return true;
- case SSP::SOME: {
+ if (F->hasFnAttr(Attribute::StackProtectReq))
+ return true;
+
+ if (F->hasFnAttr(Attribute::StackProtect)) {
const TargetData *TD = TLI->getTargetData();
for (Function::iterator I = F->begin(), E = F->end(); I != E; ++I) {
@@ -220,5 +217,6 @@
return false;
}
- }
+
+ return false;
}
Modified: llvm/trunk/lib/VMCore/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Attributes.cpp?rev=59202&r1=59201&r2=59202&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Attributes.cpp (original)
+++ llvm/trunk/lib/VMCore/Attributes.cpp Wed Nov 12 19:02:14 2008
@@ -53,6 +53,10 @@
Result += "noinline ";
if (Attrs & Attribute::AlwaysInline)
Result += "alwaysinline ";
+ if (Attrs & Attribute::StackProtect)
+ Result += "ssp ";
+ if (Attrs & Attribute::StackProtectReq)
+ Result += "sspreq ";
if (Attrs & Attribute::Alignment) {
Result += "align ";
Result += utostr((Attrs & Attribute::Alignment) >> 16);
More information about the llvm-commits
mailing list