[PATCH] D27654: Stop intercepting mallinfo and mallopt on FreeBSD
Dimitry Andric via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 11 13:38:39 PST 2016
dim created this revision.
dim added reviewers: kcc, emaste.
dim added a subscriber: llvm-commits.
Herald added a subscriber: kubabrecka.
In https://bugs.freebsd.org/215125 I was notified that some configure
scripts attempt to test for the Linux-specific `mallinfo` and `mallopt`
functions by compiling and linking small programs which references the
functions, and observing whether that results in errors.
On FreeBSD there are neither `mallinfo` nor `mallopt` functions, so
normally these tests would fail, but when sanitizers are enabled, they
incorrectly succeed, because the sanitizers define interceptors for
these functions.
Fix this by not intercepting `mallinfo` and `mallopt` for FreeBSD, in
all of the sanitizers.
https://reviews.llvm.org/D27654
Files:
lib/asan/asan_malloc_linux.cc
lib/lsan/lsan_interceptors.cc
lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
Index: lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
===================================================================
--- lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
+++ lib/sanitizer_common/tests/sanitizer_allocator_testlib.cc
@@ -172,11 +172,13 @@
void malloc_usable_size() {
}
+#if !SANITIZER_FREEBSD
void mallinfo() {
}
void mallopt() {
}
+#endif
} // extern "C"
namespace std {
Index: lib/lsan/lsan_interceptors.cc
===================================================================
--- lib/lsan/lsan_interceptors.cc
+++ lib/lsan/lsan_interceptors.cc
@@ -127,6 +127,7 @@
return GetMallocUsableSize(ptr);
}
+#if !SANITIZER_FREEBSD
struct fake_mallinfo {
int x[10];
};
@@ -140,6 +141,7 @@
INTERCEPTOR(int, mallopt, int cmd, int value) {
return -1;
}
+#endif
INTERCEPTOR(void*, pvalloc, uptr size) {
ENSURE_LSAN_INITED;
@@ -286,8 +288,10 @@
INTERCEPT_FUNCTION(valloc);
INTERCEPT_FUNCTION(pvalloc);
INTERCEPT_FUNCTION(malloc_usable_size);
+#if !SANITIZER_FREEBSD_
INTERCEPT_FUNCTION(mallinfo);
INTERCEPT_FUNCTION(mallopt);
+#endif
INTERCEPT_FUNCTION(pthread_create);
INTERCEPT_FUNCTION(pthread_join);
Index: lib/asan/asan_malloc_linux.cc
===================================================================
--- lib/asan/asan_malloc_linux.cc
+++ lib/asan/asan_malloc_linux.cc
@@ -114,6 +114,7 @@
return asan_malloc_usable_size(ptr, pc, bp);
}
+#if !SANITIZER_FREEBSD
// 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
@@ -131,6 +132,7 @@
INTERCEPTOR(int, mallopt, int cmd, int value) {
return -1;
}
+#endif
INTERCEPTOR(int, posix_memalign, void **memptr, uptr alignment, uptr size) {
GET_STACK_TRACE_MALLOC;
@@ -168,7 +170,9 @@
struct MallocDebugL {
void *(*calloc)(uptr n_elements, uptr elem_size);
void (*free)(void *mem);
+#if !SANITIZER_FREEBSD
fake_mallinfo (*mallinfo)(void);
+#endif
void *(*malloc)(uptr bytes);
uptr (*malloc_usable_size)(void *mem);
void *(*memalign)(uptr alignment, uptr bytes);
@@ -183,7 +187,10 @@
WRAP(realloc), WRAP(memalign), WRAP(malloc_usable_size)};
ALIGNED(32) const MallocDebugL asan_malloc_dispatch_l = {
- WRAP(calloc), WRAP(free), WRAP(mallinfo),
+ WRAP(calloc), WRAP(free),
+#if !SANITIZER_FREEBSD
+ WRAP(mallinfo),
+#endif
WRAP(malloc), WRAP(malloc_usable_size), WRAP(memalign),
WRAP(posix_memalign), WRAP(pvalloc), WRAP(realloc),
WRAP(valloc)};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D27654.81002.patch
Type: text/x-patch
Size: 2657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161211/87c95dc0/attachment.bin>
More information about the llvm-commits
mailing list