-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Avoid the proc_macro
crate being dynamically linked.
#45601
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
Comments
I've wished for a while that proc macros were binaries the compiler booted up and talked to rather than dynamic libraries. This might be a good reason to make that change - libproc_macro would just be a normal rlib that defines the IPC protocol. |
Yes, that's another approach which I should've mentioned in the first comment. The reason why I suggested the dlsym approach was that, to my understanding, it would be a much larger re-architecture of the system to add IPC. I don't know what tools we have access to from within rustc for IPC, and what the best approach would be to implement it, but if we decide that that is the approach we want to take I could look into it. |
I am strongly in favor of anything that moves us away from using the awful |
Just got hit by this today by having an indirect I'm partial to sfackler's suggestion of turning proc_macros into binaries with IPC instead of dynamic libraries. Has there been any decision on whether this should be the future goal - or any other decision for a solution to this current issue? I might be interested in working on this; but without a concrete plan it's difficult to say what "working on this" would mean. |
Triage: that PR was merged, did it end up fixing this, or not? |
I believe this was fixed. Proc macro crates are a combination of |
Currently the
proc_macro
crate is dynamically linked. This is so that it can be provided by the compiler when writing procedural macros and has access to unstable compiler internals.Unfortunately, it's possible for programs which are not compiler plugins to
extern crate proc_macro
. This happens right now if you use any crate which wants to provide conversions for its types fromproc_macro::TokenStream
. This can potentially happen deep in your dependencies without it being obvious. This means that suddenly your program will no longer work when run on systems which either don't have the same version of theproc_macro
dylib installed, or which don't have it installed at all.Ideally, for the best experience, we'd make the
proc_macro
crate a small statically linked shim, which when loaded into the compiler, usesdlsym(3)
(and the windows equivalent) to actually gain access to compiler internals. When not loaded into the compiler, it would panic when used like it does today.This way crates which depend on
proc_macro
to provide things likeFrom
impls won't be accidental footguns which break end user applications. IIRC @dtolnay has run into this in the past with theproc_macro_hack
crate, and the current master version ofsyn
has this problem as well.cc @alexcrichton who I talked to about this a bit at Rust Belt Rust.
The text was updated successfully, but these errors were encountered: