r266005 - Allow simultaneous safestack and stackprotector attributes.

Robinson, Paul via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 12 10:15:53 PDT 2016



> -----Original Message-----
> From: cfe-commits [mailto:cfe-commits-bounces at lists.llvm.org] On Behalf Of
> Evgeniy Stepanov via cfe-commits
> Sent: Monday, April 11, 2016 3:28 PM
> To: cfe-commits at lists.llvm.org
> Subject: r266005 - Allow simultaneous safestack and stackprotector
> attributes.
> 
> Author: eugenis
> Date: Mon Apr 11 17:27:55 2016
> New Revision: 266005
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=266005&view=rev
> Log:
> 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.
> 
> Modified:
>     cfe/trunk/lib/Driver/Tools.cpp
>     cfe/trunk/test/CodeGen/stack-protector.c
>     cfe/trunk/test/Driver/fsanitize.c
> 
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/lib/Driver/Tools.cpp?rev=266005&r1=266004&r2=266005&view
> =diff
> ==========================================================================
> ====
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Mon Apr 11 17:27:55 2016
> @@ -4878,15 +4878,10 @@ void Clang::ConstructJob(Compilation &C,
> 
>    // -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<unsigned>(
>            LangOptions::SSPOn,
> 
> Modified: cfe/trunk/test/CodeGen/stack-protector.c
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/stack-
> protector.c?rev=266005&r1=266004&r2=266005&view=diff
> ==========================================================================
> ====
> --- cfe/trunk/test/CodeGen/stack-protector.c (original)
> +++ cfe/trunk/test/CodeGen/stack-protector.c Mon Apr 11 17:27:55 2016
> @@ -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{{.*}} }
> -
> -// SSPREQ: attributes #{{.*}} = { nounwind sspreq{{.*}} }
> -
> -// SAFESTACK: attributes #{{.*}} = { nounwind safestack{{.*}} }
> +// NOSSP-NOT: attributes #[[A]] = {{.*}} ssp
> +// SSP: attributes #[[A]] = {{.*}} ssp

Note that because 'ssp' is a prefix of 'sspstrong' and 'sspreq'
this will match those attributes, not just 'ssp'.  You want a
regex that guarantees a space after 'ssp', which is probably
+// SSP: attributes #[[A]] = {{.*}} ssp{{ }}

> +// SSPSTRONG: attributes #[[A]] = {{.*}} sspstrong
> +// SSPREQ: attributes #[[A]] = {{.*}} sspreq
> +
> +// SAFESTACK-NOSSP: attributes #[[A]] = {{.*}} safestack
> +// SAFESTACK-NOSSP-NOT: ssp
> +
> +// SAFESTACK-SSP: attributes #[[A]] = {{.*}} safestack ssp

Same here.
--paulr

> +// SAFESTACK-SSPSTRONG: attributes #[[A]] = {{.*}} safestack sspstrong
> +// SAFESTACK-SSPREQ: attributes #[[A]] = {{.*}} safestack sspreq
> 
> Modified: cfe/trunk/test/Driver/fsanitize.c
> URL: http://llvm.org/viewvc/llvm-
> project/cfe/trunk/test/Driver/fsanitize.c?rev=266005&r1=266004&r2=266005&v
> iew=diff
> ==========================================================================
> ====
> --- cfe/trunk/test/Driver/fsanitize.c (original)
> +++ cfe/trunk/test/Driver/fsanitize.c Mon Apr 11 17:27:55 2016
> @@ -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
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


More information about the cfe-commits mailing list