From: Ed Schouten Date: Tue, 29 Mar 2016 21:13:53 +0000 (+0000) Subject: Enable the SafeStack sanitizer on CloudABI by default. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fc79d2ca42be5e803091aaea8a90d3c347a5a5ce;p=platform%2Fupstream%2Fllvm.git Enable the SafeStack sanitizer on CloudABI by default. 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 --- diff --git a/clang/include/clang/Driver/ToolChain.h b/clang/include/clang/Driver/ToolChain.h index e093f63..d671d75 100644 --- a/clang/include/clang/Driver/ToolChain.h +++ b/clang/include/clang/Driver/ToolChain.h @@ -419,6 +419,9 @@ public: /// \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 diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp index e4e6c02..1703710 100644 --- a/clang/lib/Driver/SanitizerArgs.cpp +++ b/clang/lib/Driver/SanitizerArgs.cpp @@ -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) && diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index fd69ca8..11ded7c 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -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, diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index 49283a9..d0418349 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -620,6 +620,7 @@ public: bool isPIEDefault() const override { return false; } SanitizerMask getSupportedSanitizers() const override; + SanitizerMask getDefaultSanitizers() const override; protected: Tool *buildLinker() const override; diff --git a/clang/test/Driver/cloudabi.c b/clang/test/Driver/cloudabi.c index 99a2bc2..2f1f985 100644 --- a/clang/test/Driver/cloudabi.c +++ b/clang/test/Driver/cloudabi.c @@ -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" diff --git a/clang/test/Driver/cloudabi.cpp b/clang/test/Driver/cloudabi.cpp index c3b68ae..9c1b6d0 100644 --- a/clang/test/Driver/cloudabi.cpp +++ b/clang/test/Driver/cloudabi.cpp @@ -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"