From b329713c3249d237d1827c326c1fc065104002a6 Mon Sep 17 00:00:00 2001 From: Jakub Jirutka Date: Sun, 16 Apr 2017 16:49:00 +0100 Subject: [PATCH 7/7] Enable stack protector by default for Alpine Linux --- lib/Driver/ToolChains/Linux.cpp | 7 +++++++ lib/Driver/ToolChains/Linux.h | 1 + test/Driver/fsanitize.c | 10 ++++++---- test/Driver/stack-protector.c | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/Driver/ToolChains/Linux.cpp b/lib/Driver/ToolChains/Linux.cpp index 1583c9d..981f9ae 100644 --- a/lib/Driver/ToolChains/Linux.cpp +++ b/lib/Driver/ToolChains/Linux.cpp @@ -829,6 +829,13 @@ bool Linux::isPIEDefault() const { Linux::getTriple().getVendorName().compare("alpine") == 0; } +unsigned Linux::GetDefaultStackProtectorLevel(bool KernelOrKext) const { + StringRef VendorName = Linux::getTriple().getVendorName(); + if (VendorName.compare("alpine") == 0) + return 2; + return 1; +} + SanitizerMask Linux::getSupportedSanitizers() const { const bool IsX86 = getTriple().getArch() == llvm::Triple::x86; const bool IsX86_64 = getTriple().getArch() == llvm::Triple::x86_64; diff --git a/lib/Driver/ToolChains/Linux.h b/lib/Driver/ToolChains/Linux.h index 9778c18..ddd46a1 100644 --- a/lib/Driver/ToolChains/Linux.h +++ b/lib/Driver/ToolChains/Linux.h @@ -36,6 +36,7 @@ public: void AddIAMCUIncludeArgs(const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; bool isPIEDefault() const override; + unsigned GetDefaultStackProtectorLevel(bool KernelOrKext) const override; SanitizerMask getSupportedSanitizers() const override; void addProfileRTLibs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; diff --git a/test/Driver/fsanitize.c b/test/Driver/fsanitize.c index 0752ef6..263485f 100644 --- a/test/Driver/fsanitize.c +++ b/test/Driver/fsanitize.c @@ -491,12 +491,12 @@ // RUN: %clang -fno-sanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NOSP // NOSP-NOT: "-fsanitize=safe-stack" -// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP -// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP-ASAN +// RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP +// RUN: %clang -target x86_64-linux-gnu -fsanitize=address,safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP-ASAN // RUN: %clang -target x86_64-linux-gnu -fstack-protector -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP // RUN: %clang -target x86_64-linux-gnu -fsanitize=safe-stack -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=SP -// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP -// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP +// RUN: %clang -target arm-linux-androideabi -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP +// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP // RUN: %clang -target i386-contiki-unknown -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=NO-SP // NO-SP-NOT: stack-protector // NO-SP: "-fsanitize=safe-stack" @@ -506,6 +506,8 @@ // NO-SP-ASAN-NOT: stack-protector // NO-SP-ASAN: "-fsanitize=address,safe-stack" +// SP-ASAN: "-fsanitize=address,safe-stack" +// SP-ASAN: -stack-protector // NO-SP-ASAN-NOT: stack-protector // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM diff --git a/test/Driver/stack-protector.c b/test/Driver/stack-protector.c index 6769b65..553c189 100644 --- a/test/Driver/stack-protector.c +++ b/test/Driver/stack-protector.c @@ -24,6 +24,20 @@ // SSP-ALL: "-stack-protector" "3" // SSP-ALL-NOT: "-stack-protector-buffer-size" +// RUN: %clang -target x86_64-alpine-linux-musl -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE +// ALPINE: "-stack-protector" "2" + +// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_SPS +// ALPINE_SPS: "-stack-protector" "2" + +// RUN: %clang -target x86_64-alpine-linux-musl -fstack-protector-all -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_ALL +// ALPINE_ALL: "-stack-protector" "3" +// ALPINE_ALL-NOT: "-stack-protector-buffer-size" + +// RUN: %clang -target x86_64-alpine-linux-musl -fno-stack-protector -### %s 2>&1 | FileCheck %s -check-prefix=ALPINE_NOSSP +// ALPINE_NOSSP-NOT: "-stack-protector" +// ALPINE_NOSSP-NOT: "-stack-protector-buffer-size" + // RUN: %clang -target x86_64-scei-ps4 -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4 // RUN: %clang -target x86_64-scei-ps4 -fstack-protector -### %s 2>&1 | FileCheck %s -check-prefix=SSP-PS4 // SSP-PS4: "-stack-protector" "2" -- 2.14.1