File a1.rs:
#[no_mangle]
pub extern "C" fn run_user_code() {
let v: Option<u8> = None;
println!("{}", &format!("{}", v.unwrap()));
}
Compile with:
rustc a1.rs --crate-type cdylib -C opt-level=2 -C incremental=$PWD/inc
Change None to Some(1), then recompile with the same command.
Fails with:
undefined reference to `<&T as core::fmt::Display>::fmt
/usr/bin/ld: a1.1hldx78ihfiq7lq.rcgu.o: relocation R_X86_64_PC32 against undefined hidden symbol `_ZN44_$LT$$RF$T$u20$as$u20$core..fmt..Display$GT$3fmt17ha6d3a12a9cb13cebE' can not be used when making a shared object
My guess is that when it compiles the first version, which should always panic, some symbols aren't needed and get optimised away or somehow altered. Then when the code is changed to not panic, those symbols remain absent (or in an unusable state) and it fails to link.
The following things make this behaviour go away:
- Setting opt-level=0
- Disabling incremental compilation.
- Not producing a cdylib.
- Removing
#[no_mangle]
Tested with:
- rustc 1.41.0-nightly (ae1b871 2019-12-06)
- rustc 1.39.0 (4560ea7 2019-11-04)
on a Debian-based Linux distribution.
cc --version
cc (Debian 8.3.0-6) 8.3.0
File a1.rs:
Compile with:
rustc a1.rs --crate-type cdylib -C opt-level=2 -C incremental=$PWD/incChange
NonetoSome(1), then recompile with the same command.Fails with:
My guess is that when it compiles the first version, which should always panic, some symbols aren't needed and get optimised away or somehow altered. Then when the code is changed to not panic, those symbols remain absent (or in an unusable state) and it fails to link.
The following things make this behaviour go away:
#[no_mangle]Tested with:
on a Debian-based Linux distribution.