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
Labels
A-linkage
Area: linking into static, shared libraries and binaries
C-bug
Category: This is a bug.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
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: