[compiler-rt] r312185 - [SanitizeCoverage] Enable stack-depth coverage for -fsanitize=fuzzer

Matt Morehouse via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 30 15:49:31 PDT 2017


Author: morehouse
Date: Wed Aug 30 15:49:31 2017
New Revision: 312185

URL: http://llvm.org/viewvc/llvm-project?rev=312185&view=rev
Log:
[SanitizeCoverage] Enable stack-depth coverage for -fsanitize=fuzzer

Summary:
- Don't sanitize __sancov_lowest_stack.
- Don't instrument leaf functions.
- Add CoverageStackDepth to Fuzzer and FuzzerNoLink.
- Only enable on Linux.

Reviewers: vitalybuka, kcc, george.karpenkov

Reviewed By: kcc

Subscribers: kubamracek, cfe-commits, llvm-commits, hiraditya

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

Modified:
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc
    compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
    compiler-rt/trunk/test/asan/TestCases/Darwin/interface_symbols_darwin.c
    compiler-rt/trunk/test/asan/TestCases/Linux/interface_symbols_linux.c
    compiler-rt/trunk/test/asan/TestCases/Windows/interface_symbols_windows.c
    compiler-rt/trunk/test/fuzzer/deep-recursion.test

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_coverage_libcdep_new.cc Wed Aug 30 15:49:31 2017
@@ -211,5 +211,10 @@ SANITIZER_INTERFACE_WEAK_DEF(void, __san
 SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_8bit_counters_init, void) {}
 SANITIZER_INTERFACE_WEAK_DEF(void, __sanitizer_cov_pcs_init, void) {}
 }  // extern "C"
+// Weak definition for code instrumented with -fsanitize-coverage=stack-depth
+// and later linked with code containing a strong definition.
+// E.g., -fsanitize=fuzzer-no-link
+SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
+SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE uptr __sancov_lowest_stack;
 
 #endif  // !SANITIZER_FUCHSIA

Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_internal_defs.h Wed Aug 30 15:49:31 2017
@@ -35,6 +35,14 @@
 # define SANITIZER_WEAK_ATTRIBUTE  __attribute__((weak))
 #endif
 
+// TLS is handled differently on different platforms
+#if SANITIZER_LINUX
+# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE \
+    __attribute__((tls_model("initial-exec"))) thread_local
+#else
+# define SANITIZER_TLS_INITIAL_EXEC_ATTRIBUTE
+#endif
+
 //--------------------------- WEAK FUNCTIONS ---------------------------------//
 // When working with weak functions, to simplify the code and make it more
 // portable, when possible define a default implementation using this macro:

Modified: compiler-rt/trunk/test/asan/TestCases/Darwin/interface_symbols_darwin.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Darwin/interface_symbols_darwin.c?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Darwin/interface_symbols_darwin.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/Darwin/interface_symbols_darwin.c Wed Aug 30 15:49:31 2017
@@ -12,6 +12,7 @@
 // RUN:  | grep -v "__sanitizer_weak_hook"                                     \
 // RUN:  | grep -v "__sanitizer_mz"                                            \
 // RUN:  | grep -v "__ubsan_handle_dynamic_type_cache_miss"                    \
+// RUN:  | grep -v "__sancov_lowest_stack"                                     \
 // RUN:  | sed -e "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
 // RUN:  > %t.exports
 //

Modified: compiler-rt/trunk/test/asan/TestCases/Linux/interface_symbols_linux.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Linux/interface_symbols_linux.c?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Linux/interface_symbols_linux.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/Linux/interface_symbols_linux.c Wed Aug 30 15:49:31 2017
@@ -6,6 +6,7 @@
 // RUN:  | grep -v "__sanitizer_syscall"                                       \
 // RUN:  | grep -v "__sanitizer_weak_hook"                                     \
 // RUN:  | grep -v "__ubsan_handle_dynamic_type_cache_miss"                    \
+// RUN:  | grep -v "__sancov_lowest_stack"                                     \
 // RUN:  | sed -e "s/__asan_version_mismatch_check_v[0-9]+/__asan_version_mismatch_check/" \
 // RUN:  > %t.exports
 //

Modified: compiler-rt/trunk/test/asan/TestCases/Windows/interface_symbols_windows.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/Windows/interface_symbols_windows.c?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/Windows/interface_symbols_windows.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/Windows/interface_symbols_windows.c Wed Aug 30 15:49:31 2017
@@ -38,6 +38,7 @@
 // IMPORT: __asan_set_seh_filter
 // IMPORT: __asan_unhandled_exception_filter
 // IMPORT: __asan_test_only_reported_buggy_pointer
+// IMPORT: __sancov_lowest_stack
 //
 // RUN: cat %t.imports1 %t.imports2 %t.imports3 | sort | uniq > %t.imports-sorted
 // RUN: cat %t.exports | sort | uniq > %t.exports-sorted

Modified: compiler-rt/trunk/test/fuzzer/deep-recursion.test
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/deep-recursion.test?rev=312185&r1=312184&r2=312185&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/deep-recursion.test (original)
+++ compiler-rt/trunk/test/fuzzer/deep-recursion.test Wed Aug 30 15:49:31 2017
@@ -1,5 +1,5 @@
 # Test that we can find a stack overflow
 REQUIRES: linux
-RUN: %cpp_compiler -fsanitize-coverage=stack-depth %S/DeepRecursionTest.cpp -o %t
+RUN: %cpp_compiler %S/DeepRecursionTest.cpp -o %t
 RUN: not %t -seed=1 -runs=100000000 2>&1 | FileCheck %s
 CHECK: ERROR: libFuzzer: deadly signal




More information about the llvm-commits mailing list