Skip to content

cdylib fails to link with incremental compilation after panic -> no panic transition #67118

Closed
@davidlattimore

Description

@davidlattimore

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

Metadata

Metadata

Assignees

Labels

A-incr-compArea: Incremental compilationA-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions