Skip to content

Commit

Permalink
build: ASAN fixes for glibc (JuliaLang#51755)
Browse files Browse the repository at this point in the history
For the `sigsetjmp` bypass; looks like glibc removed the
`__libc_siglongjmp` symbol in glibc 2.34, so change to using the
approach taking by our `dlopen` wrapper instead.

Adopts topolarity's fixes from JuliaLang#50170
Resolves JuliaLang#47698

Co-authored-by: Jameson Nash <vtjnash@gmail.com>
  • Loading branch information
2 people authored and mkitti committed Dec 9, 2023
1 parent 1131b6e commit 4f39714
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
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 @@ -2287,10 +2287,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

0 comments on commit 4f39714

Please sign in to comment.