[compiler-rt] r212322 - [sanitizer] support c11 aligned_alloc, Linux only for now
Kostya Serebryany
kcc at google.com
Fri Jul 4 00:30:35 PDT 2014
Author: kcc
Date: Fri Jul 4 02:30:34 2014
New Revision: 212322
URL: http://llvm.org/viewvc/llvm-project?rev=212322&view=rev
Log:
[sanitizer] support c11 aligned_alloc, Linux only for now
Added:
compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
Modified:
compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
compiler-rt/trunk/lib/msan/msan_interceptors.cc
compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc
compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
Modified: compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_malloc_linux.cc?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Fri Jul 4 02:30:34 2014
@@ -106,6 +106,11 @@ INTERCEPTOR(void*, memalign, uptr bounda
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);
Modified: compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/lsan/lsan_interceptors.cc?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Fri Jul 4 02:30:34 2014
@@ -105,6 +105,12 @@ INTERCEPTOR(void*, memalign, uptr alignm
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;
Modified: compiler-rt/trunk/lib/msan/msan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_interceptors.cc?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_interceptors.cc Fri Jul 4 02:30:34 2014
@@ -162,6 +162,13 @@ INTERCEPTOR(void *, memalign, SIZE_T bou
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);
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc Fri Jul 4 02:30:34 2014
@@ -738,6 +738,11 @@ TSAN_INTERCEPTOR(void*, memalign, uptr a
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());
Modified: compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/test/sanitizer_common/CMakeLists.txt Fri Jul 4 02:30:34 2014
@@ -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.
Added: compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/aligned_alloc.c?rev=212322&view=auto
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/aligned_alloc.c (added)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/Linux/aligned_alloc.c Fri Jul 4 02:30:34 2014
@@ -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;
+}
Modified: compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc (original)
+++ compiler-rt/trunk/test/sanitizer_common/TestCases/print-stack-trace.cc Fri Jul 4 02:30:34 2014
@@ -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>
Modified: compiler-rt/trunk/test/sanitizer_common/lit.common.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/sanitizer_common/lit.common.cfg?rev=212322&r1=212321&r2=212322&view=diff
==============================================================================
--- compiler-rt/trunk/test/sanitizer_common/lit.common.cfg (original)
+++ compiler-rt/trunk/test/sanitizer_common/lit.common.cfg Fri Jul 4 02:30:34 2014
@@ -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)
More information about the llvm-commits
mailing list