You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider this very simple sample code, referred to as test.rs hereinafter:
fnmain(){}#[no_mangle]pubstaticFOO:i32 = 1;
When compiling it without optimizations, we get the following result:
$ rustc test.rs -C linker=/bin/false
$ nm test.0.o
0000000000000040 s _FOO
U __ZN2rt10lang_start20hacfbaccc148e05fdU4xE
0000000000000000 t __ZN4main20h82df1d8932225dfbeaaE
0000000000000010 T _main
If we enable optimizations (like cargo build does) we get this:
$ rustc test.rs -C opt-level=3 -C linker=/bin/false
$ nm test.0.o
U __ZN2rt10lang_start20hacfbaccc148e05fdU4xE
0000000000000000 t __ZN4main20h82df1d8932225dfbeaaE
0000000000000010 T _main
My understanding is that it is not the compiler's job to trim this (apparently) unused symbol from the object file, but the linker's. Indeed, one could imagine that the FOO symbol might be expected by another object file that would be linked into the final executable.
The text was updated successfully, but these errors were encountered:
The relevant logic for this I believe is here and may just be a bit too eager. There's a few other locations that we check for "extern fn or #[no_mangle] static", and we may just need to add it here as well.
It would probably be good to sort this out more thoroughly though as it seems like this keeps coming up!
$ nm test.0.o
0000000000000000 R FOO
0000000000000000 T main
U _ZN3std2rt10lang_start17he6ada39161c356c2E
0000000000000000 t _ZN4test4main17hf4d700377696cbb0E
With optimizations:
$ nm test.0.o
0000000000000000 R FOO
0000000000000000 T main
U _ZN3std2rt10lang_start17he6ada39161c356c2E
0000000000000000 t _ZN4test4main17hf4d700377696cbb0E
Consider this very simple sample code, referred to as
test.rs
hereinafter:When compiling it without optimizations, we get the following result:
If we enable optimizations (like
cargo build
does) we get this:My understanding is that it is not the compiler's job to trim this (apparently) unused symbol from the object file, but the linker's. Indeed, one could imagine that the
FOO
symbol might be expected by another object file that would be linked into the final executable.The text was updated successfully, but these errors were encountered: