Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[common] Update ASan to be compatible with Clang 18 #1930

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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