-
Notifications
You must be signed in to change notification settings - Fork 13.3k
#[inline]
causes duplicated symbols in the final binary
#105771
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
This is expected. |
Thanks, I will try the identical code folding option. But I am still wondering whether a hybrid approach can be adopted, maybe something like:
Or more aggressively, ignore specialization entirely:
|
That is literally what |
Is there an option to enable this behavior? There are situations where I am willing to trade runtime performance for smaller binary size. |
There isn't at this moment. I opened #89154 last year to suggest adding this as option, but haven't received any feedback yet. |
Triage: Thanks for reporting. Let's close as duplicate of / handled by #89154 . |
I noticed that if a function is marked
#[inline]
in an upstream crate, then even if upstream have already generated a function instance, downstream creates will not reuse the existing instance, instead, they will generate their own instance, which causes duplicated symbols generated in the binary file, which causes size bloat.Note that this happens in the situation where a function is marked
#[inline]
, but not actually being inlined, so the function will have a symbol entry of its own.To reproduce, you can make a project with the following dependency graph:
where a fairly complex (to prevent being inlined) inline function is defined in
upstream
crate, and allupstream
,left
andright
crates calls the inline function.downstream
crate is for collecting all symbols generated in all the crates. I wrote a shell script for generating a such project locally (Usage:<SCRIPT> <PROJECT PATH>
):You can inspect the result binary using
llvm-nm
andllvm-objdump
. In my case,llvm-nm
gives me the following output:Note the three duplicated
__ZN3top15inline_function17hcd434eca693902bbE
symbol. And usingllvm-objdump
, I got three pieces of duplicated assembly code:And If I remove the
#[inline]
attribute in theupstream
crate, there will be no duplicated symbols."fat"
LTO seems to be able to merge the duplicated symbols, but not all project can enable this option, so is it possible to fix this problem even if"fat"
LTO is not used? Also,codegen-units=1
does not seem to help.The text was updated successfully, but these errors were encountered: