-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Fix ASAN on macos #60726
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
base: master
Are you sure you want to change the base?
Fix ASAN on macos #60726
Conversation
73fe367 to
5e4ceaf
Compare
|
Does this build on your machine? |
5e4ceaf to
316141d
Compare
|
After the push it does |
f3872b8 to
46ab024
Compare
|
Add a job to the buildkite CI? |
|
That's the plan |
contrib/asan/build.sh
Outdated
| fi | ||
|
|
||
| make -C "$TOOLCHAIN/deps" install-clang install-llvm-tools install-patchelf | ||
| make -C "$TOOLCHAIN/deps" install-clang install-llvm-tools install-patchelf install-zstd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should install-zlib too, since our LLVM links against it.
| /** | ||
| * @brief Check if Julia is built with AddressSanitizer (ASAN) enabled. | ||
| * | ||
| * @return Returns 1 if Julia is built with ASAN, 0 otherwise. | ||
| */ | ||
| JL_DLLEXPORT int jl_is_asanbuild(void) JL_NOTSAFEPOINT | ||
| { | ||
| #ifdef _COMPILER_ASAN_ENABLED_ | ||
| return 1; | ||
| #else | ||
| return 0; | ||
| #endif | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use jl_options.target_sanitize_address?
This commit improves AddressSanitizer (ASAN) support with several fixes:
1. Fix race condition in gc_scrub_record_task (gc-debug.c)
- Multiple GC threads could concurrently call gc_scrub_record_task
during the mark phase, causing data races on jl_gc_debug_tasks
- Added pthread_mutex_t with static initialization to protect the
arraylist operations
2. Add jl_is_asanbuild() API function (jlapi.c, julia.h)
- New function to detect at runtime if Julia was built with ASAN
- Exported for use in Julia code
3. Add ASAN library path detection for pkgimage linking (linking.jl)
- On macOS, pkgimages need to link against libclang_rt.asan_osx_dynamic
- Uses Libdl.dlopen with RTLD_NOLOAD to find the already-loaded ASAN
runtime library path without requiring environment variables
4. Add automatic ASAN options for LLVM compatibility (init.c, Make.inc)
- When Julia is built with ASAN but LLVM is not (common with
BinaryBuilder LLVM), std::vector container overflow detection
causes false positives due to mixing instrumented and
non-instrumented code
- Added __asan_default_options() to automatically disable
detect_container_overflow when LLVM lacks ASAN
- Added LLVM_SANITIZE=1 build option to indicate LLVM has sanitizers
5. Add __GLIBC__ guard for ELF-specific sanitizer code (dlload.c)
- The link_map struct and related code is glibc-specific
6. Fix flisp Makefile for Darwin (flisp/Makefile)
- Static AddressSanitizer runtime is not supported on Darwin
- Skip -static-libsan flag on macOS
7. Add jmpbuf_sp implementation for macOS aarch64 (julia_internal.h)
- Required for ASAN stack unpoisoning on Apple Silicon
- Implements pointer demangling using Apple's TSD mechanism
8. Disable ASAN global ctor/dtor for JITLink compatibility (pipeline.cpp)
- ASAN module constructors/destructors that register globals are not
compatible with JITLink on ARM64 due to Page21 relocation range limits
- Stack/heap/use-after-free detection still works
Co-Authored-By: Claude Opus 4.5 <[email protected]>
46ab024 to
7a83c71
Compare
This commit improves AddressSanitizer (ASAN) support with several fixes:
Fix race condition in gc_scrub_record_task (gc-debug.c)
during the mark phase, causing data races on jl_gc_debug_tasks
arraylist operations
Add jl_is_asanbuild() API function (jlapi.c, julia.h)
Add ASAN library path detection for pkgimage linking (linking.jl)
runtime library path without requiring environment variables
Add automatic ASAN options for LLVM compatibility (init.c, Make.inc)
BinaryBuilder LLVM), std::vector container overflow detection
causes false positives due to mixing instrumented and
non-instrumented code
detect_container_overflow when LLVM lacks ASAN
Co-Authored-By: Claude Opus 4.5 [email protected]