diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index 10c4eedb58e8e..ade0ac68747b4 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -800,6 +800,10 @@ impl<'a> Linker for GccLinker<'a> { // The object files have far more public symbols than we actually want to export, // so we hide them all here. + if self.sess.opts.unstable_opts.export_all_symbols { + return; + } + if !self.sess.target.limit_rdylib_exports { return; } @@ -1138,6 +1142,10 @@ impl<'a> Linker for MsvcLinker<'a> { } } + if self.sess.opts.unstable_opts.export_all_symbols { + return; + } + let path = tmpdir.join("lib.def"); let res = try { let mut f = File::create_buffered(&path)?; diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 9219b5a7e8aca..0a04e019bd61f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2343,6 +2343,8 @@ options! { "enforce the type length limit when monomorphizing instances in codegen"), experimental_default_bounds: bool = (false, parse_bool, [TRACKED], "enable default bounds for experimental group of auto traits"), + export_all_symbols: bool = (false, parse_bool, [TRACKED], + "disable symbol export filtering for dylibs and cdylibs, exporting all symbols"), export_executable_symbols: bool = (false, parse_bool, [TRACKED], "export symbols from executables, as if they were dynamic libraries"), external_clangrt: bool = (false, parse_bool, [UNTRACKED], diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index adba8f19894a8..5ded02f95d5e5 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1243,6 +1243,13 @@ pub fn rustc_cargo( cargo.rustflag("-Zdefault-visibility=protected"); } + // On Apple, Enzyme can hang if rustc and Enzyme each embed their own LLVM. + // Export all symbols from rustc_driver so Enzyme reuses rustc's LLVM. + // Related: https://github.com/rust-lang/enzyme/pull/31 + if builder.config.llvm_enzyme && target.contains("apple") && build_compiler.stage != 0 { + cargo.rustflag("-Zexport-all-symbols"); + } + if is_lto_stage(build_compiler) { match builder.config.rust_lto { RustcLto::Thin | RustcLto::Fat => { diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 2300904f22c10..3d5c2ec7be72d 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -512,6 +512,7 @@ auto: --enable-full-tools --enable-sanitizers --enable-profiler + --set llvm.enzyme=true --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1