Open MSxDOS opened 6 years ago
The #[link]
is necessary for Rust to know whether it has to apply dllimport
to the symbols in the extern block. While this doesn't matter as much for functions (because the linker can statically link a stub function that jumps to the dynamically linked version), for statics this is a dealbreaker because without dllimport
the code is generated as if the static has a hardcoded address. and there's just no way for the linker to magic a solution. The bug here is that for some reason it is still linking successfully instead of failing to link.
External statics return stuff from incorrect memory locations when their
extern
blocks are not marked with#[link(name = "their_lib_name")]
explicitly .Environment
Example
Test
cdylib
type library calledlibtest
:Test binary (marked):
Result - OK:
Now after removing
#[link(name = "libtest")]
from above theextern
block in our test binary and instead linking via build script:Result: