-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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:
on a Debian-based Linux distribution.
cc --version
cc (Debian 8.3.0-6) 8.3.0
Metadata
Metadata
Assignees
Labels
A-incr-compArea: Incremental compilationArea: Incremental compilationA-linkageArea: linking into static, shared libraries and binariesArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.Category: This is a bug.P-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.