Skip to content

Commit

Permalink
enable -fstack-protector on 10.5 for usermode binaries by default.
Browse files Browse the repository at this point in the history
This matches gcc's behavior.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138324 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
nico committed Aug 23, 2011
1 parent 4df54fe commit 2fef111
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
4 changes: 3 additions & 1 deletion include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ class ToolChain {

/// GetDefaultStackProtectorLevel - Get the default stack protector level for
/// this tool chain (0=off, 1=on, 2=all).
virtual unsigned GetDefaultStackProtectorLevel() const { return 0; }
virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
return 0;
}

/// IsUnwindTablesDefault - Does this tool chain use -funwind-tables
/// by default.
Expand Down
9 changes: 6 additions & 3 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,12 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
return !(!isTargetIPhoneOS() && isMacosxVersionLT(10, 6));
}
virtual bool IsUnwindTablesDefault() const;
virtual unsigned GetDefaultStackProtectorLevel() const {
// Stack protectors default to on for 10.6 and beyond.
return !isTargetIPhoneOS() && !isMacosxVersionLT(10, 6);
virtual unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const {
// Stack protectors default to on for user code on 10.5,
// and for everything in 10.6 and beyond
return !isTargetIPhoneOS() &&
(!isMacosxVersionLT(10, 6) ||
(!isMacosxVersionLT(10, 5) && !KernelOrKext));
}
virtual const char *GetDefaultRelocationModel() const;
virtual const char *GetForcedPicModel() const;
Expand Down
6 changes: 4 additions & 2 deletions lib/Driver/Tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1671,8 +1671,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
StackProtectorLevel = 1;
else if (A->getOption().matches(options::OPT_fstack_protector_all))
StackProtectorLevel = 2;
} else
StackProtectorLevel = getToolChain().GetDefaultStackProtectorLevel();
} else {
StackProtectorLevel =
getToolChain().GetDefaultStackProtectorLevel(KernelOrKext);
}
if (StackProtectorLevel) {
CmdArgs.push_back("-stack-protector");
CmdArgs.push_back(Args.MakeArgString(Twine(StackProtectorLevel)));
Expand Down

0 comments on commit 2fef111

Please sign in to comment.