[asan] Remove runtime flag detect_stack_use_after_scope
authorVitaly Buka <vitalybuka@google.com>
Mon, 29 Aug 2016 17:16:59 +0000 (17:16 +0000)
committerVitaly Buka <vitalybuka@google.com>
Mon, 29 Aug 2016 17:16:59 +0000 (17:16 +0000)
Summary:
We are going to use store instructions to poison some allocas.
Runtime flag will require branching in instrumented code on every lifetime
intrinsic. We'd like to avoid that.

Reviewers: eugenis

Subscribers: llvm-commits, kubabrecka

Differential Revision: https://reviews.llvm.org/D23967

llvm-svn: 279981

compiler-rt/lib/asan/asan_flags.inc
compiler-rt/lib/asan/asan_interface_internal.h
compiler-rt/lib/asan/asan_poisoning.cc
compiler-rt/lib/asan/asan_rtl.cc
compiler-rt/lib/asan/asan_win.cc
compiler-rt/lib/asan/asan_win_dll_thunk.cc
compiler-rt/lib/asan/asan_win_dynamic_runtime_thunk.cc
compiler-rt/test/asan/TestCases/use-after-scope-types.cc
compiler-rt/test/asan/TestCases/use-after-scope.cc

index 805002a61164302da9f7841e8c4145e2ca87c799..9496a47490c7547a9b8085d941362db18d8d45d1 100644 (file)
@@ -46,8 +46,6 @@ ASAN_FLAG(bool, replace_intrin, true,
           "If set, uses custom wrappers for memset/memcpy/memmove intrinsics.")
 ASAN_FLAG(bool, detect_stack_use_after_return, false,
           "Enables stack-use-after-return checking at run-time.")
-ASAN_FLAG(bool, detect_stack_use_after_scope, true,
-          "Enables stack-use-after-scope checking at run-time.")
 ASAN_FLAG(int, min_uar_stack_size_log, 16, // We can't do smaller anyway.
           "Minimum fake stack size log.")
 ASAN_FLAG(int, max_uar_stack_size_log,
index 9462a8c76149571eb6ced027039011a4f82e98ce..6f75bb6197acc03a25d55282a6af47cad091e2f6 100644 (file)
@@ -174,10 +174,6 @@ extern "C" {
   SANITIZER_INTERFACE_ATTRIBUTE
   extern int __asan_option_detect_stack_use_after_return;
 
-// Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_scope
-  SANITIZER_INTERFACE_ATTRIBUTE
-  extern int __asan_option_detect_stack_use_after_scope;
-
   SANITIZER_INTERFACE_ATTRIBUTE
   extern uptr *__asan_test_only_reported_buggy_pointer;
 
index dafd06a30cb0129b0bf5ba8f8519c5bb545b8963..e6487a0154cc55347e917613a77da457bf1eb833 100644 (file)
@@ -339,13 +339,11 @@ void __asan_set_shadow_f8(uptr addr, uptr size) {
 }
 
 void __asan_poison_stack_memory(uptr addr, uptr size) {
-  if (!__asan_option_detect_stack_use_after_scope) return;
   VReport(1, "poisoning: %p %zx\n", (void *)addr, size);
   PoisonAlignedStackMemory(addr, size, true);
 }
 
 void __asan_unpoison_stack_memory(uptr addr, uptr size) {
-  if (!__asan_option_detect_stack_use_after_scope) return;
   VReport(1, "unpoisoning: %p %zx\n", (void *)addr, size);
   PoisonAlignedStackMemory(addr, size, false);
 }
index a4f82bf6a2217076e81d8cb230536488e8447bd5..5a1128d6e3a64d8f9e5d05a56fd4e77aa3cbb44e 100644 (file)
@@ -33,7 +33,6 @@
 #include "ubsan/ubsan_platform.h"
 
 int __asan_option_detect_stack_use_after_return;  // Global interface symbol.
-int __asan_option_detect_stack_use_after_scope;  // Global interface symbol.
 uptr *__asan_test_only_reported_buggy_pointer;  // Used only for testing asan.
 
 namespace __asan {
@@ -446,9 +445,6 @@ static void AsanInitInternal() {
   __asan_option_detect_stack_use_after_return =
       flags()->detect_stack_use_after_return;
 
-  __asan_option_detect_stack_use_after_scope =
-      flags()->detect_stack_use_after_scope;
-
   // Re-exec ourselves if we need to set additional env or command line args.
   MaybeReexec();
 
index 0616e408794803439ae4feb80ec73ce1ae2ba943..5b29aec8c74a404c80dc07ea9242e79aee6fe96c 100644 (file)
@@ -37,12 +37,6 @@ int __asan_should_detect_stack_use_after_return() {
   return __asan_option_detect_stack_use_after_return;
 }
 
-SANITIZER_INTERFACE_ATTRIBUTE
-int __asan_should_detect_stack_use_after_scope() {
-  __asan_init();
-  return __asan_option_detect_stack_use_after_scope;
-}
-
 // -------------------- A workaround for the absence of weak symbols ----- {{{
 // We don't have a direct equivalent of weak symbols when using MSVC, but we can
 // use the /alternatename directive to tell the linker to default a specific
index 4316415ac953161e0d64fd1edddfd4f2c67136bb..77efbdb98a596f148c6d9e0dc21a89da08d2ab23 100644 (file)
@@ -198,11 +198,9 @@ static void InterceptHooks();
 // Don't use the INTERFACE_FUNCTION machinery for this function as we actually
 // want to call it in the __asan_init interceptor.
 WRAP_W_V(__asan_should_detect_stack_use_after_return)
-WRAP_W_V(__asan_should_detect_stack_use_after_scope)
 
 extern "C" {
   int __asan_option_detect_stack_use_after_return;
-  int __asan_option_detect_stack_use_after_scope;
 
   // Manually wrap __asan_init as we need to initialize
   // __asan_option_detect_stack_use_after_return afterwards.
@@ -216,8 +214,6 @@ extern "C" {
     fn();
     __asan_option_detect_stack_use_after_return =
         (__asan_should_detect_stack_use_after_return() != 0);
-    __asan_option_detect_stack_use_after_scope =
-        (__asan_should_detect_stack_use_after_scope() != 0);
 
     InterceptHooks();
   }
index c79071494d5319e7c7b560c026920545390b48d7..c6e2a65a4a8d47ba57a136d15d87e058cf48c603 100644 (file)
@@ -15,7 +15,6 @@
 //
 // This includes:
 //  - forwarding the detect_stack_use_after_return runtime option
-//  - forwarding the detect_stack_use_after_scope runtime option
 //  - working around deficiencies of the MD runtime
 //  - installing a custom SEH handler
 //
@@ -51,23 +50,6 @@ int __asan_option_detect_stack_use_after_return =
     __asan_should_detect_stack_use_after_return();
 }
 
-////////////////////////////////////////////////////////////////////////////////
-// Define a copy of __asan_option_detect_stack_use_after_scope that should be
-// used when linking an MD runtime with a set of object files on Windows.
-//
-// The ASan MD runtime dllexports '__asan_option_detect_stack_use_after_scope',
-// so normally we would just dllimport it.  Unfortunately, the dllimport
-// attribute adds __imp_ prefix to the symbol name of a variable.
-// Since in general we don't know if a given TU is going to be used
-// with a MT or MD runtime and we don't want to use ugly __imp_ names on Windows
-// just to work around this issue, let's clone the variable that is constant
-// after initialization anyways.
-extern "C" {
-__declspec(dllimport) int __asan_should_detect_stack_use_after_scope();
-int __asan_option_detect_stack_use_after_scope =
-    __asan_should_detect_stack_use_after_scope();
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // For some reason, the MD CRT doesn't call the C/C++ terminators during on DLL
 // unload or on exit.  ASan relies on LLVM global_dtors to call
index b21368164d1ed8fc1565e74fc89031ca56e4fbc1..53ae3400e3cbee73d82f14fe3b85e1431eedc823 100644 (file)
@@ -1,17 +1,15 @@
 // RUN: %clangxx_asan %stdcxx11 -O0 -fsanitize-address-use-after-scope %s -o %t
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 0 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 1 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 2 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 3 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 4 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 5 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 6 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 7 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 8 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 9 2>&1 | FileCheck %s
-// RUN: %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 10 2>&1 | FileCheck %s
-
-// RUN: %env_asan_opts=detect_stack_use_after_scope=0 %run %t 11
+// RUN: not %run %t 0 2>&1 | FileCheck %s
+// RUN: not %run %t 1 2>&1 | FileCheck %s
+// RUN: not %run %t 2 2>&1 | FileCheck %s
+// RUN: not %run %t 3 2>&1 | FileCheck %s
+// RUN: not %run %t 4 2>&1 | FileCheck %s
+// RUN: not %run %t 5 2>&1 | FileCheck %s
+// RUN: not %run %t 6 2>&1 | FileCheck %s
+// RUN: not %run %t 7 2>&1 | FileCheck %s
+// RUN: not %run %t 8 2>&1 | FileCheck %s
+// RUN: not %run %t 9 2>&1 | FileCheck %s
+// RUN: not %run %t 10 2>&1 | FileCheck %s
 
 #include <stdlib.h>
 #include <string>
index f669bf9438614c2bfac8fc8754d2132d9a462a90..d92dae6572cec61da8cf483a2fce0460f9490d0f 100644 (file)
@@ -1,7 +1,5 @@
 // RUN: %clangxx_asan -O1 -fsanitize-address-use-after-scope %s -o %t && \
-// RUN:     %env_asan_opts=detect_stack_use_after_scope=1 not %run %t 2>&1 | FileCheck %s
-
-// RUN: %env_asan_opts=detect_stack_use_after_scope=0 %run %t
+// RUN:     not %run %t 2>&1 | FileCheck %s
 
 volatile int *p = 0;