-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Closed
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-proc-macrosArea: Procedural macrosArea: Procedural macrosI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.
Description
readelf --wide --syms build/x86_64-unknown-linux-gnu/stage0-rustc/release/deps/libproc_macro_hack-cdb4209108fe6fa9.so | grep GLOBAL | grep -v UND | wc -l
shows over 5500 exported symbols. It should limit exports to only those that are used, just like for cdylib's. This should decrease the size of proc macros by allowing more effecting garbage collection of dead code.
ptrca
Metadata
Metadata
Assignees
Labels
A-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesA-proc-macrosArea: Procedural macrosArea: Procedural macrosI-heavyIssue: Problems and improvements with respect to binary size of generated code.Issue: Problems and improvements with respect to binary size of generated code.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
eddyb commentedon Jul 29, 2022
I just about almost opened my own issue, as this looks like it could cause e.g. #59998:
(noticed the excess of exports in @fasterthanlime's latest blog post, about RA/proc macros)
Frankly I think I got confused at some point and expected proc macros to get more
cdylib
treatment than they actually do, I even described them in the past as "cdylib
+rmeta
".And there are certainly places where it looks like that was the intention:
rust/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Lines 23 to 26 in b4151a4
rust/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Lines 142 to 146 in b4151a4
But also this seems to apply? So what's the actual crate type for a proc macro?
rust/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Lines 260 to 267 in b4151a4
Ah there it is! For some reason we just completely bypass symbol-hiding for proc macros:
rust/compiler/rustc_codegen_ssa/src/back/linker.rs
Lines 651 to 661 in 9067d52
bjorn3 commentedon Jul 29, 2022
That is exactly what I was reading when I opened this issue :)
eddyb commentedon Jul 29, 2022
(i.e. the original proc macro impl) is what appears to have added the proc macro case here (which seems to have been called
RustcMacro
back then):rust/src/librustc_trans/back/linker.rs
Lines 240 to 248 in 7a26aec
So what happened was that proc macros were a lot more like
dylib
s thancdylib
s originally, and this was consistently implemented.However, at some point, @michaelwoerister refactored
symbol_export
, in:dylib
s to being likecdylib
s, at least in terms of symbol exportsBut that decision couldn't have changed anything (at least not in the way we might expect) because of the bail-out from export hiding that proc macros have been hit by.
Nowadays not even
dylib
crates complete ignore export hiding, only proc macros do.I believe this also tripped me up in the past, since
crate_export_threshold
looked correct, and I guess I never looked in depth at what's actually being exported, welp.bjorn3 commentedon Jul 30, 2022
Removing the gate at
rust/compiler/rustc_codegen_ssa/src/back/linker.rs
Lines 651 to 661 in 9067d52
Edit: Symbol visibility for
rust_metadata_*
was set to Rust instead of C.Edit2: Changing that doesn't seem to be enough.
Edit3: Needed to add the symbol for proc macros too. It was limited to dylibs. It works now.
bjorn3 commentedon Jul 30, 2022
Opened #99944 with a fix.
Auto merge of rust-lang#99944 - bjorn3:hide_proc_macro_symbols, r=eddyb
eddyb commentedon Aug 2, 2022
Beautiful, thanks @bjorn3! ✨
est31 commentedon Aug 2, 2022
I wonder what the impact of this reduction has been.
bjorn3 commentedon Aug 2, 2022
#99944 (comment) shows quite significant build time improvements. serde_derive debug got almost 3MB smaller (down to 23MB). Same for serde_derive opt (down to 8MB). I don't think we benchmark compilation of any other proc macro on perf.rust-lang.org.