Skip to content

Conversation

xal-0
Copy link
Member

@xal-0 xal-0 commented Jul 18, 2025

Adds three hidden options that can enable the Memory/Thread/AddressSanitizer
LLVM passes even when Julia is not built with any sanitizers enabled. In
conjunction with #59033 this lets us build a ThreadSanitizer version of Julia in
only a few minutes rather than hours.

  • Adds the --target-sanitize=(memory|thread|address) flags to enable those
    LLVM passes when compiling code ahead of time with --output-*.
  • JITted code will enable the passes for a sanitizer only if the runtime is
    built with it.
  • Adds the corresponding options to CodegenParams.

@xal-0 xal-0 added the building Build system, or building Julia or its dependencies label Jul 18, 2025
@Keno
Copy link
Member

Keno commented Jul 18, 2025

Can we spell this as --target-sanitize= just to follow the convention of other compilers?

@xal-0
Copy link
Member Author

xal-0 commented Jul 18, 2025

I'm also open to suggestions on ways to clean up the duplication between jl_options_t/jl_cgparams_t/OptimizationsOptions. I expect we'll accumulate more codegen knobs and AOT-only options because of juliac.

Copy link
Member

@Keno Keno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine for now - we can think about refactoring the options struct at a later time.

@vchuravy
Copy link
Member

Since these change codegen behavior, we should probably also thread them through the cache options (e.g.

JL_DLLEXPORT uint8_t jl_cache_flags(void)
{
// OOICCDDP
uint8_t flags = 0;
flags |= (jl_options.use_pkgimages & 1); // 0-bit
flags |= (jl_options.debug_level & 3) << DEBUG_LEVEL; // 1-2 bit
flags |= (jl_options.check_bounds & 3) << 3; // 3-4 bit
flags |= (jl_options.can_inline & 1) << 5; // 5-bit
flags |= (jl_options.opt_level & 3) << OPT_LEVEL; // 6-7 bit
return flags;
}
& co) such that the native code in pkgimages is adjusted, and you can do tsan/asan with respect to it.

@Keno
Copy link
Member

Keno commented Jul 18, 2025

& co) such that the native code in pkgimages is adjusted, and you can do tsan/asan with respect to it.

We should also make sure that the sanitizer abi tags are still working and probably enable more of them on Yggdrasil

@xal-0 xal-0 changed the title Add --target-sanitize-(memory|thread|address) Add --target-sanitize=(memory|thread|address) Jul 30, 2025
@xal-0
Copy link
Member Author

xal-0 commented Jul 30, 2025

I've added the sanitizer flags to Base.CacheFlags (by extending the UInt8 to a UInt64, so we hopefully don't have to do this again in the near future). Ideally this would use the same variable-length format as the new CPU features struct, but I don't think it's worth making that change now.

@xal-0
Copy link
Member Author

xal-0 commented Aug 1, 2025

Since the Base.CacheFlags change breaks Pkg.test(), this will have to wait for JuliaLang/Pkg.jl#4347.

Keno pushed a commit that referenced this pull request Aug 13, 2025
This will be used by Pkg instead of parsing a single UInt8, so #59035
and other changes to CacheFlags can be made without breaking Pkg in the
future, as mentioned in JuliaLang/Pkg.jl#4347
(also ref:
JuliaLang/Pkg.jl#4347 (comment)).
@vtjnash
Copy link
Member

vtjnash commented Aug 14, 2025

Options that affect only the base image (--ouput-incremental=false) and get copied from there should not be put into the Base.CacheFlags struct, which is for flags that can be different from the base image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
building Build system, or building Julia or its dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants