[compiler-rt] r293346 - Revert "Stop intercepting some malloc-related functions on FreeBSD and macOS"
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 27 15:53:20 PST 2017
Author: eugenis
Date: Fri Jan 27 17:53:20 2017
New Revision: 293346
URL: http://llvm.org/viewvc/llvm-project?rev=293346&view=rev
Log:
Revert "Stop intercepting some malloc-related functions on FreeBSD and macOS"
This reverts r293337, which breaks tests on Windows:
malloc-no-intercept-499eb7.o : error LNK2019: unresolved external symbol _mallinfo referenced in function _main
Removed:
compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c
Modified:
compiler-rt/trunk/lib/asan/asan_malloc_linux.cc
compiler-rt/trunk/lib/lsan/lsan_interceptors.cc
compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
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=293346&r1=293345&r2=293346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_malloc_linux.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_malloc_linux.cc Fri Jan 27 17:53:20 2017
@@ -50,14 +50,12 @@ INTERCEPTOR(void, free, void *ptr) {
asan_free(ptr, &stack, FROM_MALLOC);
}
-#if SANITIZER_INTERCEPT_CFREE
INTERCEPTOR(void, cfree, void *ptr) {
GET_STACK_TRACE_FREE;
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
return;
asan_free(ptr, &stack, FROM_MALLOC);
}
-#endif // SANITIZER_INTERCEPT_CFREE
INTERCEPTOR(void*, malloc, uptr size) {
if (UNLIKELY(!asan_inited))
@@ -93,24 +91,22 @@ INTERCEPTOR(void*, realloc, void *ptr, u
return asan_realloc(ptr, size, &stack);
}
-#if SANITIZER_INTERCEPT_MEMALIGN
INTERCEPTOR(void*, memalign, uptr boundary, uptr size) {
GET_STACK_TRACE_MALLOC;
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);
DTLS_on_libc_memalign(res, size);
return res;
}
-#endif // SANITIZER_INTERCEPT_MEMALIGN
-
-INTERCEPTOR(void*, aligned_alloc, uptr boundary, uptr size) {
- GET_STACK_TRACE_MALLOC;
- return asan_memalign(boundary, size, &stack, FROM_MALLOC);
-}
INTERCEPTOR(uptr, malloc_usable_size, void *ptr) {
GET_CURRENT_PC_BP_SP;
@@ -118,7 +114,6 @@ INTERCEPTOR(uptr, malloc_usable_size, vo
return asan_malloc_usable_size(ptr, pc, bp);
}
-#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
// We avoid including malloc.h for portability reasons.
// man mallinfo says the fields are "long", but the implementation uses int.
// It doesn't matter much -- we just need to make sure that the libc's mallinfo
@@ -136,7 +131,6 @@ INTERCEPTOR(struct fake_mallinfo, mallin
INTERCEPTOR(int, mallopt, int cmd, int value) {
return -1;
}
-#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
GET_STACK_TRACE_MALLOC;
@@ -149,12 +143,10 @@ INTERCEPTOR(void*, valloc, uptr size) {
return asan_valloc(size, &stack);
}
-#if SANITIZER_INTERCEPT_PVALLOC
INTERCEPTOR(void*, pvalloc, uptr size) {
GET_STACK_TRACE_MALLOC;
return asan_pvalloc(size, &stack);
}
-#endif // SANITIZER_INTERCEPT_PVALLOC
INTERCEPTOR(void, malloc_stats, void) {
__asan_print_accumulated_stats();
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=293346&r1=293345&r2=293346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/lsan/lsan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/lsan/lsan_interceptors.cc Fri Jan 27 17:53:20 2017
@@ -19,7 +19,6 @@
#include "sanitizer_common/sanitizer_flags.h"
#include "sanitizer_common/sanitizer_internal_defs.h"
#include "sanitizer_common/sanitizer_linux.h"
-#include "sanitizer_common/sanitizer_platform_interceptors.h"
#include "sanitizer_common/sanitizer_platform_limits_posix.h"
#include "sanitizer_common/sanitizer_tls_get_addr.h"
#include "lsan.h"
@@ -87,26 +86,11 @@ INTERCEPTOR(void*, realloc, void *q, upt
return Reallocate(stack, q, size, 1);
}
-#if SANITIZER_INTERCEPT_MEMALIGN
INTERCEPTOR(void*, memalign, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE_MALLOC;
return Allocate(stack, size, alignment, kAlwaysClearMemory);
}
-#define LSAN_MAYBE_INTERCEPT_MEMALIGN INTERCEPT_FUNCTION(memalign)
-
-INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
- ENSURE_LSAN_INITED;
- GET_STACK_TRACE_MALLOC;
- void *res = Allocate(stack, size, alignment, kAlwaysClearMemory);
- DTLS_on_libc_memalign(res, size);
- return res;
-}
-#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN INTERCEPT_FUNCTION(__libc_memalign)
-#else
-#define LSAN_MAYBE_INTERCEPT_MEMALIGN
-#define LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN
-#endif // SANITIZER_INTERCEPT_MEMALIGN
INTERCEPTOR(void*, aligned_alloc, uptr alignment, uptr size) {
ENSURE_LSAN_INITED;
@@ -122,6 +106,14 @@ INTERCEPTOR(int, posix_memalign, void **
return 0;
}
+INTERCEPTOR(void *, __libc_memalign, uptr alignment, uptr size) {
+ ENSURE_LSAN_INITED;
+ GET_STACK_TRACE_MALLOC;
+ void *res = Allocate(stack, size, alignment, kAlwaysClearMemory);
+ DTLS_on_libc_memalign(res, size);
+ return res;
+}
+
INTERCEPTOR(void*, valloc, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE_MALLOC;
@@ -135,7 +127,6 @@ INTERCEPTOR(uptr, malloc_usable_size, vo
return GetMallocUsableSize(ptr);
}
-#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
struct fake_mallinfo {
int x[10];
};
@@ -145,18 +136,11 @@ INTERCEPTOR(struct fake_mallinfo, mallin
internal_memset(&res, 0, sizeof(res));
return res;
}
-#define LSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo)
INTERCEPTOR(int, mallopt, int cmd, int value) {
return -1;
}
-#define LSAN_MAYBE_INTERCEPT_MALLOPT INTERCEPT_FUNCTION(mallopt)
-#else
-#define LSAN_MAYBE_INTERCEPT_MALLINFO
-#define LSAN_MAYBE_INTERCEPT_MALLOPT
-#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
-#if SANITIZER_INTERCEPT_PVALLOC
INTERCEPTOR(void*, pvalloc, uptr size) {
ENSURE_LSAN_INITED;
GET_STACK_TRACE_MALLOC;
@@ -168,17 +152,8 @@ INTERCEPTOR(void*, pvalloc, uptr size) {
}
return Allocate(stack, size, GetPageSizeCached(), kAlwaysClearMemory);
}
-#define LSAN_MAYBE_INTERCEPT_PVALLOC INTERCEPT_FUNCTION(pvalloc)
-#else
-#define LSAN_MAYBE_INTERCEPT_PVALLOC
-#endif // SANITIZER_INTERCEPT_PVALLOC
-#if SANITIZER_INTERCEPT_CFREE
INTERCEPTOR(void, cfree, void *p) ALIAS(WRAPPER_NAME(free));
-#define LSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree)
-#else
-#define LSAN_MAYBE_INTERCEPT_CFREE
-#endif // SANITIZER_INTERCEPT_CFREE
#define OPERATOR_NEW_BODY \
ENSURE_LSAN_INITED; \
@@ -302,18 +277,17 @@ namespace __lsan {
void InitializeInterceptors() {
INTERCEPT_FUNCTION(malloc);
INTERCEPT_FUNCTION(free);
- LSAN_MAYBE_INTERCEPT_CFREE;
+ INTERCEPT_FUNCTION(cfree);
INTERCEPT_FUNCTION(calloc);
INTERCEPT_FUNCTION(realloc);
- LSAN_MAYBE_INTERCEPT_MEMALIGN;
- LSAN_MAYBE_INTERCEPT___LIBC_MEMALIGN;
- INTERCEPT_FUNCTION(aligned_alloc);
+ INTERCEPT_FUNCTION(memalign);
INTERCEPT_FUNCTION(posix_memalign);
+ INTERCEPT_FUNCTION(__libc_memalign);
INTERCEPT_FUNCTION(valloc);
- LSAN_MAYBE_INTERCEPT_PVALLOC;
+ INTERCEPT_FUNCTION(pvalloc);
INTERCEPT_FUNCTION(malloc_usable_size);
- LSAN_MAYBE_INTERCEPT_MALLINFO;
- LSAN_MAYBE_INTERCEPT_MALLOPT;
+ INTERCEPT_FUNCTION(mallinfo);
+ INTERCEPT_FUNCTION(mallopt);
INTERCEPT_FUNCTION(pthread_create);
INTERCEPT_FUNCTION(pthread_join);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h?rev=293346&r1=293345&r2=293346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_platform_interceptors.h Fri Jan 27 17:53:20 2017
@@ -316,9 +316,4 @@
#define SANITIZER_INTERCEPT_UTMP SI_NOT_WINDOWS && !SI_MAC && !SI_FREEBSD
#define SANITIZER_INTERCEPT_UTMPX SI_LINUX_NOT_ANDROID || SI_MAC || SI_FREEBSD
-#define SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO (!SI_FREEBSD && !SI_MAC)
-#define SANITIZER_INTERCEPT_MEMALIGN (!SI_FREEBSD && !SI_MAC)
-#define SANITIZER_INTERCEPT_PVALLOC (!SI_FREEBSD && !SI_MAC)
-#define SANITIZER_INTERCEPT_CFREE (!SI_FREEBSD && !SI_MAC)
-
#endif // #ifndef SANITIZER_PLATFORM_INTERCEPTORS_H
Modified: compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc?rev=293346&r1=293345&r2=293346&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc (original)
+++ compiler-rt/trunk/lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc Fri Jan 27 17:53:20 2017
@@ -139,7 +139,6 @@ void *realloc(void *p, size_t size) {
return p;
}
-#if SANITIZER_INTERCEPT_MEMALIGN
void *memalign(size_t alignment, size_t size) {
if (UNLIKELY(!thread_inited))
thread_init();
@@ -147,7 +146,6 @@ void *memalign(size_t alignment, size_t
SANITIZER_MALLOC_HOOK(p, size);
return p;
}
-#endif // SANITIZER_INTERCEPT_MEMALIGN
int posix_memalign(void **memptr, size_t alignment, size_t size) {
if (UNLIKELY(!thread_inited))
@@ -167,26 +165,18 @@ void *valloc(size_t size) {
return p;
}
-#if SANITIZER_INTERCEPT_CFREE
void cfree(void *p) ALIAS("free");
-#endif // SANITIZER_INTERCEPT_CFREE
-#if SANITIZER_INTERCEPT_PVALLOC
void *pvalloc(size_t size) ALIAS("valloc");
-#endif // SANITIZER_INTERCEPT_PVALLOC
-#if SANITIZER_INTERCEPT_MEMALIGN
void *__libc_memalign(size_t alignment, size_t size) ALIAS("memalign");
-#endif // SANITIZER_INTERCEPT_MEMALIGN
void malloc_usable_size() {
}
-#if SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
void mallinfo() {
}
void mallopt() {
}
-#endif // SANITIZER_INTERCEPT_MALLOPT_AND_MALLINFO
} // extern "C"
namespace std {
Removed: compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c?rev=293345&view=auto
==============================================================================
--- compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c (original)
+++ compiler-rt/trunk/test/asan/TestCases/malloc-no-intercept.c (removed)
@@ -1,24 +0,0 @@
-// Test that on non-glibc platforms, a number of malloc-related functions are
-// not intercepted.
-
-// RUN: not %clang_asan -Dtestfunc=mallinfo %s -o %t
-// RUN: not %clang_asan -Dtestfunc=mallopt %s -o %t
-// RUN: not %clang_asan -Dtestfunc=memalign %s -o %t
-// RUN: not %clang_asan -Dtestfunc=pvalloc %s -o %t
-// RUN: not %clang_asan -Dtestfunc=cfree %s -o %t
-
-#include <stdlib.h>
-
-// For glibc, cause link failures by referencing a nonexistent function.
-#ifdef __GLIBC__
-#undef testfunc
-#define testfunc nonexistent_function
-#endif
-
-void testfunc(void);
-
-int main(void)
-{
- testfunc();
- return 0;
-}
More information about the llvm-commits
mailing list