Changeset: 4e9e0b6735df for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4e9e0b6735df
Modified Files:
cmake/monetdb-toolchain.cmake
gdk/gdk_utils.c
Branch: Jul2021
Log Message:
Use atomic instruction and no DEADBEEF processing when using sanitizer.
diffs (96 lines):
diff --git a/cmake/monetdb-toolchain.cmake b/cmake/monetdb-toolchain.cmake
--- a/cmake/monetdb-toolchain.cmake
+++ b/cmake/monetdb-toolchain.cmake
@@ -19,7 +19,7 @@ function(monetdb_default_toolchain)
if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
MT_addCompilerFlag("-fsanitize=address" "-fsanitize=address"
"${CMAKE_C_FLAGS}" "all" CMAKE_C_FLAGS)
MT_addCompilerFlag("-fno-omit-frame-pointer" "-fno-omit-frame-pointer"
"${CMAKE_C_FLAGS}" "all" CMAKE_C_FLAGS)
- add_definitions(-DNO_ATOMIC_INSTRUCTIONS)
+ add_definitions(-DSANITIZER)
else()
message(FATAL_ERROR "Sanitizer only supported with GCC")
endif()
diff --git a/gdk/gdk_utils.c b/gdk/gdk_utils.c
--- a/gdk/gdk_utils.c
+++ b/gdk/gdk_utils.c
@@ -1850,7 +1850,7 @@ GDKvm_cursize(void)
/* we allocate extra space and return a pointer offset by this amount */
#define MALLOC_EXTRA_SPACE (2 * SIZEOF_VOID_P)
-#ifdef NDEBUG
+#if defined(NDEBUG) || defined(SANITIZER)
#define DEBUG_SPACE 0
#else
#define DEBUG_SPACE 16
@@ -1897,7 +1897,7 @@ GDKmalloc_internal(size_t size)
/* just before the pointer that we return, write how much we
* asked of malloc */
((size_t *) s)[-1] = nsize + MALLOC_EXTRA_SPACE + DEBUG_SPACE;
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
/* just before that, write how much was asked of us */
((size_t *) s)[-2] = size;
/* write pattern to help find out-of-bounds writes */
@@ -1914,7 +1914,7 @@ GDKmalloc(size_t size)
if ((s = GDKmalloc_internal(size)) == NULL)
return NULL;
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
/* write a pattern to help make sure all data is properly
* initialized by the caller */
DEADBEEFCHK memset(s, '\xBD', size);
@@ -1978,7 +1978,7 @@ GDKfree(void *s)
asize = ((size_t *) s)[-1]; /* how much allocated last */
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
assert((asize & 2) == 0); /* check against duplicate free */
/* check for out-of-bounds writes */
{
@@ -1989,7 +1989,7 @@ GDKfree(void *s)
((size_t *) s)[-1] |= 2; /* indicate area is freed */
#endif
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
/* overwrite memory that is to be freed with a pattern that
* will help us recognize access to already freed memory in
* the debugger */
@@ -2005,7 +2005,7 @@ void *
GDKrealloc(void *s, size_t size)
{
size_t nsize, asize;
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
size_t osize;
size_t *os;
#endif
@@ -2024,7 +2024,7 @@ GDKrealloc(void *s, size_t size)
GDKerror("allocating too much memory\n");
return NULL;
}
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
assert((asize & 2) == 0); /* check against duplicate free */
/* check for out-of-bounds writes */
osize = ((size_t *) s)[-2]; /* how much asked for last */
@@ -2042,7 +2042,7 @@ GDKrealloc(void *s, size_t size)
s = realloc((char *) s - MALLOC_EXTRA_SPACE,
nsize + MALLOC_EXTRA_SPACE + DEBUG_SPACE);
if (s == NULL) {
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
os[-1] &= ~2; /* not freed after all */
#endif
GDKsyserror("realloc failed; memory requested: %zu, memory in
use: %zu, virtual memory in use: %zu\n", size, GDKmem_cursize(),
GDKvm_cursize());;
@@ -2052,7 +2052,7 @@ GDKrealloc(void *s, size_t size)
/* just before the pointer that we return, write how much we
* asked of malloc */
((size_t *) s)[-1] = nsize + MALLOC_EXTRA_SPACE + DEBUG_SPACE;
-#ifndef NDEBUG
+#if !defined(NDEBUG) && !defined(SANITIZER)
/* just before that, write how much was asked of us */
((size_t *) s)[-2] = size;
/* if growing, initialize new memory with debug pattern */
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list