Skip to content

Conversation

@sgasho
Copy link
Contributor

@sgasho sgasho commented Jan 17, 2026

Export LLVM symbols from rustc_driver on Apple when autodiff is enabled.

On Apple targets, Enzyme can hang if rustc and Enzyme each embed their own LLVM. Exporting LLVM symbols from rustc_driver lets Enzyme reuse

dependencies: rust-lang/enzyme#31
This PR can be merged after rust-lang/enzyme#31 has been merged and enzyme submodule has been updated.

I applied diffs on this PR to #151063 then produced artifacts at https://github.com/rust-lang/rust/actions/runs/21091289355

I confirmed that /path/to/rustc -Zautodiff=Enable -Clto=fat test.rs successfully finished when I used those artifacts↑

r? @ZuseZ4

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 17, 2026
@sgasho sgasho marked this pull request as ready for review January 17, 2026 12:56
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 17, 2026
@bjorn3
Copy link
Member

bjorn3 commented Jan 17, 2026

This seems like it has the same goal as #150992 except implemented in a hackier way.

@sgasho
Copy link
Contributor Author

sgasho commented Jan 17, 2026

Thanks for informing!
I took a look at #150992 and indeed that approach would be better.
I think I can wait until the PR to be merged

@sgasho sgasho marked this pull request as draft January 18, 2026 04:42
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 18, 2026
@sgasho
Copy link
Contributor Author

sgasho commented Jan 19, 2026

After #150992 has been merged, I'll modify this PR or create a new PR to export LLVM symobls for autodiff on Apple target

I leave this PR as a draft for now

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 20, 2026

Also @Kobzol , just for awareness.
As a trade-off for using libloading we'll need to make llvm symbols visible on macos, since we can't have two llvm copies embedded into rustc and enzyme. Making the symbols public might have a perf impact.

@Kobzol
Copy link
Member

Kobzol commented Jan 20, 2026

Is there any other potential perf. impact other than making the toolchain larger?

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 21, 2026

I don't expect it to have any relevant runtime perf impact, but given the surface of LLVM and the complexity of our bootstrap (e.g. PGO) I also wouldn't be too surprised if there's a corner case where this affects a benchmark. On Linux I would have started a perf run, but since we don't have those for apple I'd just merge it when ready. I mainly wanted to make sure that you're aware and ok with this change.

@Kobzol
Copy link
Member

Kobzol commented Jan 21, 2026

Ok. Go ahead :)

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 27, 2026

Ok, now that the Enzyme update landed, can you create some new linux+apple artifacts based on the latest EnzymeAD/Enzyme + #150992 (as it seems almost ready to land)?
Once we verified that those still work, I'll update the submodule once more and we should be good to land the rest.

@bjorn3
Copy link
Member

bjorn3 commented Jan 27, 2026

Why do we actually statically link LLVM on macOS in the first place? I know we do it on Windows to work around the limit around how much symbols can be exported from a single dll, but that is not an issue on macOS.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jan 27, 2026

@Kobzol might know

@Kobzol
Copy link
Member

Kobzol commented Jan 27, 2026

Nope, no idea 😆

@nikic
Copy link
Contributor

nikic commented Jan 27, 2026

I think we currently just always use static linking, except the cases where we went out of the way to use dynamic linking for specific reasons (e.g. x86_64-unknown-linux-gnu so we can built libLLVM with LTO, PGO etc). It would probably make sense to invert this and always use dynamic linking unless there is a reason not to (Windows).

Of course, dynamically linking LLVM does increase startup overhead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants