For ASAN TRASH_ALLOC() should be something like this
#define TRASH_ALLOC(A,B) do { MEM_UNDEFINED(A,B); TRASH_FILL(A,B,0xA5); } while(0)
|
Here we make memory region accessible and fill it with constant date for gdb user.
But for valgrind it is
#define TRASH_ALLOC(A,B) do { TRASH_FILL(A,B,0xA5); MEM_UNDEFINED(A,B); } while(0)
|
Filling data and make it write-only.
For ASAN TRASH_FREE() should be something like this:
#define TRASH_FREE(A,B) do { MEM_NOACCESS(A,B); } while(0)
|
No need to fill it with some data because every access will be caught regardless of this. Also, current code unpoisons, fills and poisons memory region. And this prevent ASAN from catching double free.
MEM_UNDEFINED unpoisons memory, i.e. makes it correct. This is counter-intuitive, IMO. And that's why TRASH_ALLOC, TRASH_FREE macros ideally should be different for valgrind and ASAN.
Mostly already implemented with these commits:
c3e25703c75 improve ASAN instrumentation: clang
03eb15933da improve ASAN instrumentation: InnoDB/XtraDB
f2408e7e6a3 Free memory in unit tests. Makes ASAN happier.
36eb0b7a558 improve ASAN instrumentation: table->record[0]
fa331acefd6 improve ASAN instrumentation: mtr
dc28b6d180a improve ASAN instrumentation: MEM_ROOT
a966d422ca5 improve ASAN instrumentation: TRASH
5e7593add40 add support for ASAN instrumentation
6634f460a99 fix compilation with ASAN
Works with safemalloc just fine.
mem_heap_t and Pool are not instrumented.