Add stack protector support to clang. This generates the 'ssp' and 'sspreq'
function attributes. There are predefined macros that are defined when stack
protectors are used: __SSP__=1 with -fstack-protector and __SSP_ALL__=2 with
-fstack-protector-all.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74405 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index a3ffb48..a1efe01 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -660,6 +660,11 @@
static llvm::cl::opt<bool>
StaticDefine("static-define", llvm::cl::desc("Should __STATIC__ be defined"));
+static llvm::cl::opt<int>
+StackProtector("stack-protector",
+ llvm::cl::desc("Enable stack protectors"),
+ llvm::cl::init(-1));
+
static void InitializeLanguageStandard(LangOptions &Options, LangKind LK,
TargetInfo *Target,
const llvm::StringMap<bool> &Features) {
@@ -814,6 +819,10 @@
Options.Static = StaticDefine;
+ assert(StackProtector <= 2 && "Invalid value for -stack-protector");
+ if (StackProtector != -1)
+ Options.StackProtector = StackProtector;
+
if (MainFileName.getPosition())
Options.setMainFileName(MainFileName.c_str());
}