Skip to content

Commit

Permalink
[common] Update ASan to be compatible with Clang 18
Browse files Browse the repository at this point in the history
Newer Clang versions added more ASan callbacks, in particular
`__asan_register_elf_globals()` and `__asan_unregister_elf_globals()`.
Our code replicates exactly what the Clang/LLVM code does for these two
callbacks.

Signed-off-by: Dmitrii Kuvaiskii <dmitrii.kuvaiskii@intel.com>
  • Loading branch information
Dmitrii Kuvaiskii committed Jun 27, 2024
1 parent f05ae1c commit ecb165e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions common/include/asan.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,9 @@ void __asan_register_globals(struct __asan_global* globals, size_t n);
* implementation does nothing (and we don't even handle `.fini_array`). */
void __asan_unregister_globals(struct __asan_global* globals, size_t n);

void __asan_register_elf_globals(uintptr_t* flag, void* start, void* stop);
void __asan_unregister_elf_globals(uintptr_t* flag, void* start, void* stop);

/* Callbacks for setting the shadow memory to specific values. As with load/store callbacks, LLVM
* normally generates inline stores and calls these functions only for bigger areas. This is
* controlled by `-mllvm -asan-max-inline-poisoning-size=N`. */
Expand Down
22 changes: 22 additions & 0 deletions common/src/asan.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,28 @@ void __asan_unregister_globals(struct __asan_global* globals, size_t n) {
__UNUSED(n);
}

void __asan_register_elf_globals(uintptr_t* flag, void* start, void* stop) {
if (*flag || start == stop)
return;

assert(IS_ALIGNED((uintptr_t)stop - (uintptr_t)start, sizeof(struct __asan_global)));
struct __asan_global* globals_start = start;
struct __asan_global* globals_stop = stop;
__asan_register_globals(globals_start, globals_stop - globals_start);
*flag = 1;
}

void __asan_unregister_elf_globals(uintptr_t* flag, void* start, void* stop) {
if (!*flag || start == stop)
return;

assert(IS_ALIGNED((uintptr_t)stop - (uintptr_t)start, sizeof(struct __asan_global)));
struct __asan_global* globals_start = start;
struct __asan_global* globals_stop = stop;
__asan_unregister_globals(globals_start, globals_stop - globals_start);
*flag = 0;
}

#define DEFINE_ASAN_SET_SHADOW(name, value) \
__attribute__((noinline)) \
void __asan_set_shadow_ ## name (uintptr_t addr, size_t size) { \
Expand Down

0 comments on commit ecb165e

Please sign in to comment.