summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2014-07-04 07:30:34 +0000
committerKostya Serebryany <kcc@google.com>2014-07-04 07:30:34 +0000
commitd35f02708812b1c2f9c543e66e10ed56cad48caf (patch)
treedf9b4628502da7e2b6e293f4bc7fdc3f0630486c
parenteafe9dfd5e787ae2d16ce8074ed715a4d72730b0 (diff)
downloadcompiler-rt-d35f02708812b1c2f9c543e66e10ed56cad48caf.tar.gz
[sanitizer] support c11 aligned_alloc, Linux only for now
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212322 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/asan/asan_malloc_linux.cc5
-rw-r--r--lib/lsan/lsan_interceptors.cc6
-rw-r--r--lib/msan/msan_interceptors.cc7
-rw-r--r--lib/tsan/rtl/tsan_interceptors.cc5
-rw-r--r--test/sanitizer_common/CMakeLists.txt1
-rw-r--r--test/sanitizer_common/TestCases/Linux/aligned_alloc.c8
-rw-r--r--test/sanitizer_common/TestCases/print-stack-trace.cc2
-rw-r--r--test/sanitizer_common/lit.common.cfg2
8 files changed, 35 insertions, 1 deletions
diff --git a/lib/asan/asan_malloc_linux.cc b/lib/asan/asan_malloc_linux.cc
index 0c368d81a..077a50c85 100644
--- a/lib/asan/asan_malloc_linux.cc
+++ b/lib/asan/asan_malloc_linux.cc
@@ -106,6 +106,11 @@ INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
return asan_memalign(boundary, size, &stack, FROM_MALLOC);
}
+INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) {
+ GET_STACK_TRACE_MALLOC;
+ return asan_memalign(boundary, size, &stack, FROM_MALLOC);
+}
+
INTERCEPTOR(void*, __libc_memalign, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
void *res = asan_memalign(boundary, size, &stack, FROM_MALLOC);
diff --git a/lib/lsan/lsan_interceptors.cc b/lib/lsan/lsan_interceptors.cc
index 38dc62e7c..ad8ca90bf 100644
--- a/lib/lsan/lsan_interceptors.cc
+++ b/lib/lsan/lsan_interceptors.cc
@@ -105,6 +105,12 @@ INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
return Allocate(stack, size, alignment, kAlwaysClearMemory);
}
+INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
+ ENSURE_LSAN_INITED;
+ GET_STACK_TRACE;
+ return Allocate(stack, size, alignment, kAlwaysClearMemory);
+}
+
INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE;
diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc
index 7525818ca..74a19b851 100644
--- a/lib/msan/msan_interceptors.cc
+++ b/lib/msan/msan_interceptors.cc
@@ -162,6 +162,13 @@ INTERCEPTOR(void *, memalign, SIZE_T boundary, SIZE_T size) {
return ptr;
}
+INTERCEPTOR(void *, aligned_alloc, SIZE_T boundary, SIZE_T size) {
+ GET_MALLOC_STACK_TRACE;
+ CHECK_EQ(boundary & (boundary - 1), 0);
+ void *ptr = MsanReallocate(&stack, 0, size, boundary, false);
+ return ptr;
+}
+
INTERCEPTOR(void *, __libc_memalign, SIZE_T boundary, SIZE_T size) {
GET_MALLOC_STACK_TRACE;
CHECK_EQ(boundary & (boundary - 1), 0);
diff --git a/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc
index 53c7c2618..37e46501f 100644
--- a/lib/tsan/rtl/tsan_interceptors.cc
+++ b/lib/tsan/rtl/tsan_interceptors.cc
@@ -738,6 +738,11 @@ TSAN_INTERCEPTOR(void*, memalign, uptr align, uptr sz) {
return user_alloc(thr, pc, sz, align);
}
+TSAN_INTERCEPTOR(void*, aligned_alloc, uptr align, uptr sz) {
+ SCOPED_INTERCEPTOR_RAW(memalign, align, sz);
+ return user_alloc(thr, pc, sz, align);
+}
+
TSAN_INTERCEPTOR(void*, valloc, uptr sz) {
SCOPED_INTERCEPTOR_RAW(valloc, sz);
return user_alloc(thr, pc, sz, GetPageSizeCached());
diff --git a/test/sanitizer_common/CMakeLists.txt b/test/sanitizer_common/CMakeLists.txt
index dcb09ca00..13eecbdc1 100644
--- a/test/sanitizer_common/CMakeLists.txt
+++ b/test/sanitizer_common/CMakeLists.txt
@@ -10,6 +10,7 @@ endif()
if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
list(APPEND SUPPORTED_TOOLS tsan)
list(APPEND SUPPORTED_TOOLS msan)
+ list(APPEND SUPPORTED_TOOLS lsan)
endif()
# Create a separate config for each tool we support.
diff --git a/test/sanitizer_common/TestCases/Linux/aligned_alloc.c b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
new file mode 100644
index 000000000..12af18dd3
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
@@ -0,0 +1,8 @@
+// RUN: %clang -std=c11 -O0 %s -o %t && %run %t
+#include <stdlib.h>
+extern void *aligned_alloc (size_t alignment, size_t size);
+int main() {
+ volatile void *p = aligned_alloc(128, 1024);
+ free((void*)p);
+ return 0;
+}
diff --git a/test/sanitizer_common/TestCases/print-stack-trace.cc b/test/sanitizer_common/TestCases/print-stack-trace.cc
index 98d9ddf5d..c84d0da9c 100644
--- a/test/sanitizer_common/TestCases/print-stack-trace.cc
+++ b/test/sanitizer_common/TestCases/print-stack-trace.cc
@@ -3,7 +3,7 @@
//
// Not yet implemented for TSan.
// https://code.google.com/p/address-sanitizer/issues/detail?id=243
-// XFAIL: tsan
+// XFAIL: tsan,lsan
#include <sanitizer/common_interface_defs.h>
diff --git a/test/sanitizer_common/lit.common.cfg b/test/sanitizer_common/lit.common.cfg
index 6e2d7729b..6e768b1b5 100644
--- a/test/sanitizer_common/lit.common.cfg
+++ b/test/sanitizer_common/lit.common.cfg
@@ -11,6 +11,8 @@ elif config.tool_name == "tsan":
tool_cflags = ["-fsanitize=thread"]
elif config.tool_name == "msan":
tool_cflags = ["-fsanitize=memory"]
+elif config.tool_name == "lsan":
+ tool_cflags = ["-fsanitize=leak"]
else:
lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)