Skip to content

Commit

Permalink
Enable the SafeStack sanitizer on CloudABI by default.
Browse files Browse the repository at this point in the history
Over the last month we've been testing SafeStack extensively. As far as
we know, it works perfectly fine. That why I'd like to see us having
this enabled by default for CloudABI.

This change introduces a getDefaultSanitizers() function that toolchains
can use to specify which sanitizers are enabled by default. Once all
flags are processed, only flags that had no -fno-sanitize overrides are
enabled.

Extend the thests for CloudABI to test both the default case and the
case in which we want to explicitly disable SafeStack.

Reviewed by:	eugenis, pcc
Differential Revision:	http://reviews.llvm.org/D18505

llvm-svn: 264787
  • Loading branch information
EdSchouten committed Mar 29, 2016
1 parent 4cfe93c commit fc79d2c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
3 changes: 3 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ class ToolChain {

/// \brief Return sanitizers which are available in this toolchain.
virtual SanitizerMask getSupportedSanitizers() const;

/// \brief Return sanitizers which are enabled by default.
virtual SanitizerMask getDefaultSanitizers() const { return 0; }
};

} // end namespace driver
Expand Down
3 changes: 3 additions & 0 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}
}

// Enable toolchain specific default sanitizers if not explicitly disabled.
Kinds |= TC.getDefaultSanitizers() & ~AllRemove;

// We disable the vptr sanitizer if it was enabled by group expansion but RTTI
// is disabled.
if ((Kinds & Vptr) &&
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2988,6 +2988,10 @@ SanitizerMask CloudABI::getSupportedSanitizers() const {
return Res;
}

SanitizerMask CloudABI::getDefaultSanitizers() const {
return SanitizerKind::SafeStack;
}

/// OpenBSD - OpenBSD tool chain which can call as(1) and ld(1) directly.

OpenBSD::OpenBSD(const Driver &D, const llvm::Triple &Triple,
Expand Down
1 change: 1 addition & 0 deletions clang/lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ class LLVM_LIBRARY_VISIBILITY CloudABI : public Generic_ELF {
bool isPIEDefault() const override { return false; }

SanitizerMask getSupportedSanitizers() const override;
SanitizerMask getDefaultSanitizers() const override;

protected:
Tool *buildLinker() const override;
Expand Down
11 changes: 8 additions & 3 deletions clang/test/Driver/cloudabi.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s
// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
// CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
// RUN: %clang %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s -check-prefix=SAFESTACK
// SAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections" {{.*}} "-fsanitize=safe-stack"
// SAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"

// RUN: %clang %s -### -target x86_64-unknown-cloudabi -fno-sanitize=safe-stack 2>&1 | FileCheck %s -check-prefix=NOSAFESTACK
// NOSAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
// NOSAFESTACK-NOT: "-fsanitize=safe-stack"
// NOSAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc" "-lcompiler_rt" "crtend.o"
11 changes: 8 additions & 3 deletions clang/test/Driver/cloudabi.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// RUN: %clangxx %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s
// CHECK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
// CHECK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" "-lcompiler_rt" "crtend.o"
// RUN: %clangxx %s -### -target x86_64-unknown-cloudabi 2>&1 | FileCheck %s -check-prefix=SAFESTACK
// SAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections" {{.*}} "-fsanitize=safe-stack"
// SAFESTACK: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" "-lcompiler_rt" "crtend.o"

// RUN: %clangxx %s -### -target x86_64-unknown-cloudabi -fno-sanitize=safe-stack 2>&1 | FileCheck %s -check-prefix=NOSAFESTACk
// NOSAFESTACK: "-cc1" "-triple" "x86_64-unknown-cloudabi" {{.*}} "-ffunction-sections" "-fdata-sections"
// NOSAFESTACK-NOT: "-fsanitize=safe-stack"
// NOSAFESTACk: "-Bstatic" "--eh-frame-hdr" "--gc-sections" "-o" "a.out" "crt0.o" "crtbegin.o" "{{.*}}" "{{.*}}" "-lc++" "-lc++abi" "-lunwind" "-lc" "-lcompiler_rt" "crtend.o"

0 comments on commit fc79d2c

Please sign in to comment.