|
Message-Id: <20170629225614.19061-1-amonakov@ispras.ru> Date: Fri, 30 Jun 2017 01:56:14 +0300 From: Alexander Monakov <amonakov@...ras.ru> To: musl@...ts.openwall.com Subject: [RFC PATCH] Allow annotating calloc for Valgrind With mal0_clear entered only for larger-than-one-page allocations, a few additional nops and stack accesses don't matter. This only needs Valgrind headers to build, Valgrind itself doesn't need to be built/installed. However, valgrind.h unconditionally includes stdarg.h. Untested. --- configure | 11 +++++++++++ src/malloc/malloc.c | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/configure b/configure index c2db298c..7e78094f 100755 --- a/configure +++ b/configure @@ -30,6 +30,7 @@ System types: Optional features: --enable-optimize=... optimize listed components for speed over size [auto] --enable-debug build with debugging information [disabled] + --enable-valgrind add Valgrind annotations [disabled] --enable-warnings build with recommended warnings flags [disabled] --enable-visibility use global visibility options to optimize PIC [auto] --enable-wrapper=... build given musl toolchain wrapper [auto] @@ -134,6 +135,7 @@ build= target= optimize=auto debug=no +valgrind=no warnings=no visibility=auto shared=auto @@ -161,6 +163,8 @@ case "$arg" in --disable-optimize) optimize=no ;; --enable-debug|--enable-debug=yes) debug=yes ;; --disable-debug|--enable-debug=no) debug=no ;; +--enable-valgrind|--enable-valgrind=yes) valgrind=yes ;; +--disable-valgrind|--enable-valgrind=no) valgrind=no ;; --enable-warnings|--enable-warnings=yes) warnings=yes ;; --disable-warnings|--enable-warnings=no) warnings=no ;; --enable-visibility|--enable-visibility=yes) visibility=yes ;; @@ -390,6 +394,13 @@ tryflag CFLAGS_MEMOPS -fno-tree-loop-distribute-patterns # test "$debug" = yes && CFLAGS_AUTO=-g +if test x"$valgrind" = xyes ; then +CPPFLAGS="$CPPFLAGS -DVG_MEMCHECK_H='<memcheck.h>'" +else +CPPFLAGS="$CPPFLAGS -DVG_MEMCHECK_H='</dev/null>'" +fi +CPPFLAGS="${CPPFLAGS# }" + # # Preprocess asm files to add extra debugging information if debug is # enabled, our assembler supports the needed directives, and the diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c index b56fdaa2..d4c229bd 100644 --- a/src/malloc/malloc.c +++ b/src/malloc/malloc.c @@ -8,6 +8,7 @@ #include "libc.h" #include "atomic.h" #include "pthread_impl.h" +#include VG_MEMCHECK_H #if defined(__GNUC__) && defined(__PIC__) #define inline inline __attribute__((always_inline)) @@ -373,6 +374,9 @@ static size_t mal0_clear(char *p, size_t pagesz, size_t n) typedef unsigned long long T; char *pp = p + n; size_t i = (uintptr_t)pp & (pagesz - 1); +#ifdef VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE + VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(p, n); +#endif for (;;) { pp = memset(pp - i, 0, i); if (pp - p < pagesz) return pp - p; -- 2.11.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.