-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Linking a staticlib into shared C library or executable with gcc causes considerbly larger binary than linking into a cdylib or executable with rustc #111593
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
For |
That makes a lot of sense, sorry for missing that. Passing Do you think this would be useful to add to e.g. https://doc.rust-lang.org/reference/linkage.html ? |
You need both. Without the version script the linker needs to export all symbols, but without
Yeah, could be useful to add a recommendation to pass |
Yeah, with that it's also the same in both cases. Thanks! I'll prepare a PR for adding a sentence about that to the docs some time later :) |
…e paragraph about staticlibs Fixes rust-lang/rust#111593
…e paragraph about staticlibs Fixes rust-lang/rust#111593
See https://github.com/sdroege/rust-staticlib-bloat-test for the code. This doesn't use cargo to make the actual compiler invocations clear (the same behaviour can be observed with cargo).
With Rust 1.69 and gcc 13.1.1 on Linux x86-64 the following can be observed:
--strip-all
)my_test
)libstaticlib.so
)my_staticlib_test
)libmy_staticlib_test_dylib.so
)The actual size comes from the enabled overflow checks (
-C debug-assertions=on
) , and thus all the panic and string formatting machinery that is included. However, this should be approximately the same code in either case so that doesn't explain the difference. (Disabling the overflow checks gives a more expected result because the function from the library compiles down to a few instructions) Also note that this compiles with-C panic=abort
so having the assertion in anextern "C"
function is not UB.The question here now is what exactly the difference between both cases is, and how the
staticlib
case can be improved. Maybe this requires changes in the compiler, maybe this just requires invoking the linker differently (in which case this would be useful to add to the documentation).The text was updated successfully, but these errors were encountered: