From: Evgeniy Stepanov Date: Mon, 11 Apr 2016 22:27:55 +0000 (+0000) Subject: Allow simultaneous safestack and stackprotector attributes. X-Git-Tag: llvmorg-3.9.0-rc1~9410 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=368d3074ba4993408825ef563fe5b8198a34077b;p=platform%2Fupstream%2Fllvm.git Allow simultaneous safestack and stackprotector attributes. This is the clang part of http://reviews.llvm.org/D18846. SafeStack instrumentation pass adds stack protector canaries if both attributes are present on a function. StackProtector pass will step back if the function has a safestack attribute. llvm-svn: 266005 --- diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index a585918..9fbb12c 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -4878,15 +4878,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // -stack-protector=0 is default. unsigned StackProtectorLevel = 0; - if (getToolChain().getSanitizerArgs().needsSafeStackRt()) { - Args.ClaimAllArgs(options::OPT_fno_stack_protector); - Args.ClaimAllArgs(options::OPT_fstack_protector_all); - Args.ClaimAllArgs(options::OPT_fstack_protector_strong); - Args.ClaimAllArgs(options::OPT_fstack_protector); - } else if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, - options::OPT_fstack_protector_all, - options::OPT_fstack_protector_strong, - options::OPT_fstack_protector)) { + if (Arg *A = Args.getLastArg(options::OPT_fno_stack_protector, + options::OPT_fstack_protector_all, + options::OPT_fstack_protector_strong, + options::OPT_fstack_protector)) { if (A->getOption().matches(options::OPT_fstack_protector)) { StackProtectorLevel = std::max( LangOptions::SSPOn, diff --git a/clang/test/CodeGen/stack-protector.c b/clang/test/CodeGen/stack-protector.c index ecfbc90..b97d814 100644 --- a/clang/test/CodeGen/stack-protector.c +++ b/clang/test/CodeGen/stack-protector.c @@ -1,13 +1,13 @@ -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 0 | FileCheck -check-prefix=NOSSP %s -// NOSSP: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 1 | FileCheck -check-prefix=WITHSSP %s -// WITHSSP: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 2 | FileCheck -check-prefix=SSPSTRONG %s -// SSPSTRONG: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 3 | FileCheck -check-prefix=SSPREQ %s -// SSPREQ: define {{.*}}void @test1(i8* %msg) #0 { -// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack | FileCheck -check-prefix=SAFESTACK %s -// SAFESTACK: define {{.*}}void @test1(i8* %msg) #0 { +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SSPSTRONG %s +// RUN: %clang_cc1 -emit-llvm -o - %s -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SSPREQ %s + +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 0 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-NOSSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 1 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSP %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 2 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPSTRONG %s +// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=safe-stack -stack-protector 3 | FileCheck -check-prefix=DEF -check-prefix=SAFESTACK-SSPREQ %s typedef __SIZE_TYPE__ size_t; @@ -15,18 +15,21 @@ int printf(const char * _Format, ...); size_t strlen(const char *s); char *strcpy(char *s1, const char *s2); +// DEF: define {{.*}}void @test1(i8* %msg) #[[A:.*]] { void test1(const char *msg) { char a[strlen(msg) + 1]; strcpy(a, msg); printf("%s\n", a); } -// NOSSP: attributes #{{.*}} = { nounwind{{.*}} } - -// WITHSSP: attributes #{{.*}} = { nounwind ssp{{.*}} } - -// SSPSTRONG: attributes #{{.*}} = { nounwind sspstrong{{.*}} } +// NOSSP-NOT: attributes #[[A]] = {{.*}} ssp +// SSP: attributes #[[A]] = {{.*}} ssp +// SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong +// SSPREQ: attributes #[[A]] = {{.*}} sspreq -// SSPREQ: attributes #{{.*}} = { nounwind sspreq{{.*}} } +// SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack +// SAFESTACK-NOSSP-NOT: ssp -// SAFESTACK: attributes #{{.*}} = { nounwind safestack{{.*}} } +// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp +// SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong +// SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c index 57a3573..d9bf342 100644 --- a/clang/test/Driver/fsanitize.c +++ b/clang/test/Driver/fsanitize.c @@ -317,16 +317,21 @@ // 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=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 -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 -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=SP -// RUN: %clang -target aarch64-linux-android -fsanitize=safe-stack -### %s 2>&1 | FileCheck %s -check-prefix=SP -// SP-NOT: stack-protector +// 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 +// NO-SP-NOT: stack-protector +// NO-SP: "-fsanitize=safe-stack" // SP: "-fsanitize=safe-stack" -// SP-ASAN-NOT: stack-protector -// SP-ASAN: "-fsanitize=address,safe-stack" +// SP: -stack-protector +// NO-SP-NOT: stack-protector + +// NO-SP-ASAN-NOT: stack-protector +// NO-SP-ASAN: "-fsanitize=address,safe-stack" +// NO-SP-ASAN-NOT: stack-protector // RUN: %clang -target powerpc64-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM // RUN: %clang -target powerpc64le-unknown-linux-gnu -fsanitize=memory %s -### 2>&1 | FileCheck %s -check-prefix=CHECK-SANM