Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
davidlattimore opened this issue Dec 7, 2019 · 4 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@davidlattimore
Copy link
Contributor

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
@jonas-schievink jonas-schievink added A-incr-comp Area: Incremental compilation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. I-nominated T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 7, 2019
@pnkfelix
Copy link
Member

I should see how this behaves on a branch with #67020

@pnkfelix
Copy link
Member

triage: P-high, removing nomination. Assigning to self to see if I can replicate, and if so, how it behaves with respect to PR #67020

@pnkfelix pnkfelix added P-high High priority and removed I-nominated labels Dec 12, 2019
@pnkfelix pnkfelix self-assigned this Dec 12, 2019
@pnkfelix
Copy link
Member

I just replicated the problem, and confirmed that it is fixed by PR #67020.

Thank you so much for tracking this down to such a nice example.

@pnkfelix
Copy link
Member

closing as duplicate of #59535

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants