summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/asan/output_tests
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2012-05-24 13:54:31 +0000
committerDmitry Vyukov <dvyukov@google.com>2012-05-24 13:54:31 +0000
commit7fb7330469af52ae1313b2b47c273e62c61a4dd5 (patch)
tree19ba7be4f7391cfd3125fdb8e1d17d0f308cba84 /compiler-rt/lib/asan/output_tests
parent9ffebff74c65218e3a90311b2ae3092fdbb6742d (diff)
downloadbcm5719-llvm-7fb7330469af52ae1313b2b47c273e62c61a4dd5.tar.gz
bcm5719-llvm-7fb7330469af52ae1313b2b47c273e62c61a4dd5.zip
asan/tsan: weak interceptors
The idea isthat asan/tsan can survive if user intercepts the same functions. At the same time user has an ability to call back into asan/tsan runtime. See the following tests for examples: asan/output_tests/interception_failure_test-linux.cc asan/output_tests/interception_test-linux.cc asan/output_tests/interception_malloc_test-linux.cc llvm-svn: 157388
Diffstat (limited to 'compiler-rt/lib/asan/output_tests')
-rw-r--r--compiler-rt/lib/asan/output_tests/heap-overflow.cc2
-rw-r--r--compiler-rt/lib/asan/output_tests/interception_failure_test-linux.cc17
-rw-r--r--compiler-rt/lib/asan/output_tests/interception_malloc_test-linux.cc19
-rw-r--r--compiler-rt/lib/asan/output_tests/interception_test-linux.cc18
-rw-r--r--compiler-rt/lib/asan/output_tests/strncpy-overflow.cc4
-rwxr-xr-xcompiler-rt/lib/asan/output_tests/test_output.sh10
-rw-r--r--compiler-rt/lib/asan/output_tests/use-after-free.cc4
7 files changed, 66 insertions, 8 deletions
diff --git a/compiler-rt/lib/asan/output_tests/heap-overflow.cc b/compiler-rt/lib/asan/output_tests/heap-overflow.cc
index a8656c6126d..57233e89e2c 100644
--- a/compiler-rt/lib/asan/output_tests/heap-overflow.cc
+++ b/compiler-rt/lib/asan/output_tests/heap-overflow.cc
@@ -13,7 +13,7 @@ int main(int argc, char **argv) {
// Check-Common: {{0x.* is located 0 bytes to the right of 10-byte region}}
// Check-Common: {{allocated by thread T0 here:}}
-// Check-Linux: {{ #0 0x.* in malloc}}
+// Check-Linux: {{ #0 0x.* in __xsan_malloc}}
// Check-Linux: {{ #1 0x.* in main .*heap-overflow.cc:[45]}}
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
diff --git a/compiler-rt/lib/asan/output_tests/interception_failure_test-linux.cc b/compiler-rt/lib/asan/output_tests/interception_failure_test-linux.cc
new file mode 100644
index 00000000000..9e8b7536906
--- /dev/null
+++ b/compiler-rt/lib/asan/output_tests/interception_failure_test-linux.cc
@@ -0,0 +1,17 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+extern "C" long strtol(const char *nptr, char **endptr, int base) {
+ fprintf(stderr, "my_strtol_interceptor\n");
+ return 0;
+}
+
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return (int)strtol(x, 0, 10);
+}
+
+// Check-Common: my_strtol_interceptor
+// CHECK-NOT: heap-use-after-free
+
diff --git a/compiler-rt/lib/asan/output_tests/interception_malloc_test-linux.cc b/compiler-rt/lib/asan/output_tests/interception_malloc_test-linux.cc
new file mode 100644
index 00000000000..e1a19600805
--- /dev/null
+++ b/compiler-rt/lib/asan/output_tests/interception_malloc_test-linux.cc
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+extern "C" void *__xsan_malloc(size_t size);
+extern "C" void *malloc(size_t size) {
+ write(2, "malloc call\n", sizeof("malloc call\n") - 1);
+ return __xsan_malloc(size);
+}
+
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return (int)strtol(x, 0, 10);
+}
+
+// Check-Common: malloc call
+// Check-Common: heap-use-after-free
+
diff --git a/compiler-rt/lib/asan/output_tests/interception_test-linux.cc b/compiler-rt/lib/asan/output_tests/interception_test-linux.cc
new file mode 100644
index 00000000000..84636f861a2
--- /dev/null
+++ b/compiler-rt/lib/asan/output_tests/interception_test-linux.cc
@@ -0,0 +1,18 @@
+#include <stdlib.h>
+#include <stdio.h>
+
+extern "C" long __xsan_strtol(const char *nptr, char **endptr, int base);
+extern "C" long strtol(const char *nptr, char **endptr, int base) {
+ fprintf(stderr, "my_strtol_interceptor\n");
+ return __xsan_strtol(nptr, endptr, base);
+}
+
+int main() {
+ char *x = (char*)malloc(10 * sizeof(char));
+ free(x);
+ return (int)strtol(x, 0, 10);
+}
+
+// Check-Common: my_strtol_interceptor
+// Check-Common: heap-use-after-free
+
diff --git a/compiler-rt/lib/asan/output_tests/strncpy-overflow.cc b/compiler-rt/lib/asan/output_tests/strncpy-overflow.cc
index 2346188bf3b..8b72d0f29c1 100644
--- a/compiler-rt/lib/asan/output_tests/strncpy-overflow.cc
+++ b/compiler-rt/lib/asan/output_tests/strncpy-overflow.cc
@@ -9,13 +9,13 @@ int main(int argc, char **argv) {
}
// Check-Common: {{WRITE of size 1 at 0x.* thread T0}}
-// Check-Linux: {{ #0 0x.* in strncpy}}
+// Check-Linux: {{ #0 0x.* in __xsan_strncpy}}
// Check-Darwin: {{ #0 0x.* in wrap_strncpy}}
// Check-Common: {{ #1 0x.* in main .*strncpy-overflow.cc:[78]}}
// Check-Common: {{0x.* is located 0 bytes to the right of 9-byte region}}
// Check-Common: {{allocated by thread T0 here:}}
-// Check-Linux: {{ #0 0x.* in malloc}}
+// Check-Linux: {{ #0 0x.* in __xsan_malloc}}
// Check-Linux: {{ #1 0x.* in main .*strncpy-overflow.cc:6}}
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
diff --git a/compiler-rt/lib/asan/output_tests/test_output.sh b/compiler-rt/lib/asan/output_tests/test_output.sh
index ca8beb59d90..216760da1b1 100755
--- a/compiler-rt/lib/asan/output_tests/test_output.sh
+++ b/compiler-rt/lib/asan/output_tests/test_output.sh
@@ -14,7 +14,7 @@ run_program() {
./$1 2>&1 | $SYMBOLIZER 2> /dev/null | c++filt > $TMP_ASAN_REPORT
}
-# check_program exe_file source_file check_prefix
+# check_program exe_file source_file check_prefixf
check_program() {
run_program $1
$FILE_CHECK $2 --check-prefix=$3 < $TMP_ASAN_REPORT
@@ -43,10 +43,14 @@ for t in *.cc; do
for b in 32 64; do
for O in 0 1 2 3; do
c=`basename $t .cc`
- if [[ "$c" == *"-so" ]]
- then
+ if [[ "$c" == *"-so" ]]; then
continue
fi
+ if [[ "$c" == *"-linux" ]]; then
+ if [[ "$OS" != "Linux" ]]; then
+ continue
+ fi
+ fi
c_so=$c-so
exe=$c.$b.O$O
so=$c.$b.O$O-so.so
diff --git a/compiler-rt/lib/asan/output_tests/use-after-free.cc b/compiler-rt/lib/asan/output_tests/use-after-free.cc
index a782d62dc50..5d6ab5fd37a 100644
--- a/compiler-rt/lib/asan/output_tests/use-after-free.cc
+++ b/compiler-rt/lib/asan/output_tests/use-after-free.cc
@@ -12,7 +12,7 @@ int main() {
// Check-Common: {{0x.* is located 5 bytes inside of 10-byte region .0x.*,0x.*}}
// Check-Common: {{freed by thread T0 here:}}
-// Check-Linux: {{ #0 0x.* in free}}
+// Check-Linux: {{ #0 0x.* in __xsan_free}}
// Check-Linux: {{ #1 0x.* in main .*use-after-free.cc:[45]}}
// Check-Darwin: {{ #0 0x.* in .*mz_free.*}}
@@ -22,7 +22,7 @@ int main() {
// Check-Common: {{previously allocated by thread T0 here:}}
-// Check-Linux: {{ #0 0x.* in malloc}}
+// Check-Linux: {{ #0 0x.* in __xsan_malloc}}
// Check-Linux: {{ #1 0x.* in main .*use-after-free.cc:3}}
// Check-Darwin: {{ #0 0x.* in .*mz_malloc.*}}
OpenPOWER on IntegriCloud