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

ASAN fixes. #51755

Merged
merged 2 commits into from
Nov 20, 2023
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
2 changes: 1 addition & 1 deletion src/dlload.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ JL_DLLEXPORT JL_NO_SANITIZE void *jl_dlopen(const char *filename, unsigned flags
dlopen = (dlopen_prototype*)dlsym(RTLD_NEXT, "dlopen");
if (!dlopen)
return NULL;
void *libdl_handle = dlopen("libdl.so", RTLD_NOW | RTLD_NOLOAD);
void *libdl_handle = dlopen("libdl.so.2", RTLD_NOW | RTLD_NOLOAD);
assert(libdl_handle);
dlopen = (dlopen_prototype*)dlsym(libdl_handle, "dlopen");
dlclose(libdl_handle);
Expand Down
7 changes: 3 additions & 4 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -2285,10 +2285,9 @@ void (ijl_longjmp)(jmp_buf _Buf, int _Value);
#define jl_setjmp_name "sigsetjmp"
#endif
#define jl_setjmp(a,b) sigsetjmp(a,b)
#if defined(_COMPILER_ASAN_ENABLED_) && __GLIBC__
// Bypass the ASAN longjmp wrapper - we're unpoisoning the stack ourselves.
JL_DLLIMPORT int __attribute__ ((nothrow)) (__libc_siglongjmp)(jl_jmp_buf buf, int val);
#define jl_longjmp(a,b) __libc_siglongjmp(a,b)
#if defined(_COMPILER_ASAN_ENABLED_) && defined(__GLIBC__)
extern void (*real_siglongjmp)(jmp_buf _Buf, int _Value);
#define jl_longjmp(a,b) real_siglongjmp(a,b)
#else
#define jl_longjmp(a,b) siglongjmp(a,b)
#endif
Expand Down
18 changes: 18 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ extern "C" {
#endif

#if defined(_COMPILER_ASAN_ENABLED_)
#if __GLIBC__
#include <dlfcn.h>
// Bypass the ASAN longjmp wrapper - we are unpoisoning the stack ourselves,
// since ASAN normally unpoisons far too much.
// c.f. interceptor in jl_dlopen as well
void (*real_siglongjmp)(jmp_buf _Buf, int _Value) = NULL;
#endif
static inline void sanitizer_start_switch_fiber(jl_ptls_t ptls, jl_task_t *from, jl_task_t *to) {
if (to->copy_stack)
__sanitizer_start_switch_fiber(&from->ctx.asan_fake_stack, (char*)ptls->stackbase-ptls->stacksize, ptls->stacksize);
Expand Down Expand Up @@ -1226,6 +1233,17 @@ void jl_init_tasks(void) JL_GC_DISABLED
exit(1);
}
#endif
#if defined(_COMPILER_ASAN_ENABLED_) && __GLIBC__
void *libc_handle = dlopen("libc.so.6", RTLD_NOW | RTLD_NOLOAD);
if (libc_handle) {
*(void**)&real_siglongjmp = dlsym(libc_handle, "siglongjmp");
dlclose(libc_handle);
}
if (real_siglongjmp == NULL) {
jl_safe_printf("failed to get real siglongjmp\n");
exit(1);
}
#endif
}

#if defined(_COMPILER_ASAN_ENABLED_)
Expand Down