I feel like I remember hearing about this before but I can't find any mention of it in my mail archives. It seems pretty simple to add support for LLVM's Address Sanitizer (asan) by using the hooks we already have for valgrind.
In fact I think this would actually be sufficient. I'm not sure what the MEMPOOL valgrind stuff is though. I don't think it's relevant to address sanitizer which only tracks references to free'd or unallocated pointers. I don't even see any need offhand for a configure flag or autoconf test. We could have a configure flag just to be consistent with valgrind but it seems pointless. If you're compiling with asan I don't see any reason to not use it. I'm building this to see if it works now. Incidentally there's another sanitizer called msan that looks even more promising. It's more like valgrind in that it tracks undefined memory. It's not working for me though and I haven't spent much time trying to figure out why yet. diff --git a/src/include/utils/memdebug.h b/src/include/utils/memdebug.h index 608facc..7696986 100644 --- a/src/include/utils/memdebug.h +++ b/src/include/utils/memdebug.h @@ -19,6 +19,27 @@ #ifdef USE_VALGRIND #include <valgrind/memcheck.h> + +#elif __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__) + +#include <sanitizer/asan_interface.h> + +#define VALGRIND_MAKE_MEM_DEFINED(addr, size) \ + ASAN_UNPOISON_MEMORY_REGION(addr, size) + +#define VALGRIND_MAKE_MEM_NOACCESS(addr, size) \ + ASAN_POISON_MEMORY_REGION(addr, size) + +#define VALGRIND_MAKE_MEM_UNDEFINED(addr, size) \ + ASAN_UNPOISON_MEMORY_REGION(addr, size) + +#define VALGRIND_CHECK_MEM_IS_DEFINED(addr, size) do {} while (0) +#define VALGRIND_CREATE_MEMPOOL(context, redzones, zeroed) do {} while (0) +#define VALGRIND_DESTROY_MEMPOOL(context) do {} while (0) +#define VALGRIND_MEMPOOL_ALLOC(context, addr, size) do {} while (0) +#define VALGRIND_MEMPOOL_FREE(context, addr) do {} while (0) +#define VALGRIND_MEMPOOL_CHANGE(context, optr, nptr, size) do {} while (0) + #else #define VALGRIND_CHECK_MEM_IS_DEFINED(addr, size) do {} while (0) #define VALGRIND_CREATE_MEMPOOL(context, redzones, zeroed) do {} while (0) -- greg -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers