From e8a670f0eddd31d81b6ef275db434317d37482f7 Mon Sep 17 00:00:00 2001 From: sgasho Date: Thu, 12 Feb 2026 23:23:31 +0900 Subject: [PATCH 1/4] enable enzyme with llvm link shared on macos --- src/ci/github-actions/jobs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 2300904f22c10..6182a1904922b 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -512,6 +512,8 @@ auto: --enable-full-tools --enable-sanitizers --enable-profiler + --set llvm.enzyme=true + --set llvm.link-shared=true --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1 From aaef5c6319a52badde8468a21544c7512a7c3e70 Mon Sep 17 00:00:00 2001 From: sgasho Date: Tue, 17 Feb 2026 01:20:01 +0900 Subject: [PATCH 2/4] implement export all symbols --- compiler/rustc_codegen_ssa/src/back/linker.rs | 8 ++++++++ compiler/rustc_session/src/options.rs | 2 ++ src/bootstrap/src/core/build_steps/compile.rs | 7 +++++++ 3 files changed, 17 insertions(+) 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 => { From 9fcb55de931715e8f1a447b1a2cf03c667abab66 Mon Sep 17 00:00:00 2001 From: sgasho Date: Tue, 17 Feb 2026 01:22:18 +0900 Subject: [PATCH 3/4] remove llvm.link-shared for apple dist --- src/ci/github-actions/jobs.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 6182a1904922b..3d5c2ec7be72d 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -513,7 +513,6 @@ auto: --enable-sanitizers --enable-profiler --set llvm.enzyme=true - --set llvm.link-shared=true --set rust.jemalloc --set rust.lto=thin --set rust.codegen-units=1 From b176c34e00c72ecb7cad74149fdbec60c5bf47f9 Mon Sep 17 00:00:00 2001 From: sgasho Date: Tue, 17 Feb 2026 23:37:36 +0900 Subject: [PATCH 4/4] Revert "implement export all symbols" This reverts commit aaef5c6319a52badde8468a21544c7512a7c3e70. --- compiler/rustc_codegen_ssa/src/back/linker.rs | 8 -------- compiler/rustc_session/src/options.rs | 2 -- src/bootstrap/src/core/build_steps/compile.rs | 7 ------- 3 files changed, 17 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index ade0ac68747b4..10c4eedb58e8e 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -800,10 +800,6 @@ 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; } @@ -1142,10 +1138,6 @@ 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 0a04e019bd61f..9219b5a7e8aca 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -2343,8 +2343,6 @@ 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 5ded02f95d5e5..adba8f19894a8 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -1243,13 +1243,6 @@ 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 => {