From d35f02708812b1c2f9c543e66e10ed56cad48caf Mon Sep 17 00:00:00 2001 From: Kostya Serebryany Date: Fri, 4 Jul 2014 07:30:34 +0000 Subject: [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 --- lib/asan/asan_malloc_linux.cc | 5 +++++ lib/lsan/lsan_interceptors.cc | 6 ++++++ lib/msan/msan_interceptors.cc | 7 +++++++ lib/tsan/rtl/tsan_interceptors.cc | 5 +++++ test/sanitizer_common/CMakeLists.txt | 1 + test/sanitizer_common/TestCases/Linux/aligned_alloc.c | 8 ++++++++ test/sanitizer_common/TestCases/print-stack-trace.cc | 2 +- test/sanitizer_common/lit.common.cfg | 2 ++ 8 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 test/sanitizer_common/TestCases/Linux/aligned_alloc.c 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 +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 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) -- cgit v1.2.1