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

Specific code layout can cause compiler panic with lto=true #59137

Closed
GinjaNinja32 opened this issue Mar 12, 2019 · 10 comments
Closed

Specific code layout can cause compiler panic with lto=true #59137

GinjaNinja32 opened this issue Mar 12, 2019 · 10 comments
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@GinjaNinja32
Copy link

GinjaNinja32 commented Mar 12, 2019

The specific setup I'm seeing to cause this is a three-crate workspace:

  • parent, a binary, depending on shared
  • child, a library, with crate-type = ["dylib"], depending on shared
  • shared, a library, also with crate-type = ["dylib"]

For my specific use case, there are many crates like child, and parent loads them dynamically via libloading, but this is not required to reproduce the panic.

Script to create this (place in empty directory and run)

#! /bin/bash

set -euo pipefail

mkdir -p child/src
cat <<EOF > child/Cargo.toml
[package]
name = "child"
version = "0.1.0"

[lib]
crate-type = ["dylib"]

[dependencies]
shared = { path = "../shared" }
EOF
cat <<EOF > child/src/lib.rs
extern crate shared;
EOF

mkdir -p parent/src
cat <<EOF > parent/Cargo.toml
[package]
name = "parent"
version = "0.1.0"

[dependencies]
shared = { path = "../shared" }
EOF
cat <<EOF > parent/src/main.rs
extern crate shared;

fn main() {}
EOF

mkdir -p shared/src
cat <<EOF > shared/Cargo.toml
[package]
name = "shared"
version = "0.1.0"

[lib]
crate-type = ["dylib"]
EOF
cat <<EOF > shared/src/lib.rs
EOF

cat <<EOF > Cargo.toml
[workspace]
members = ["parent", "child", "shared"]

[profile.release]
lto = false
EOF

set -x

cat Cargo.toml

# OK
cargo build

# OK
cargo build --release

sed -i 's/lto = false/lto = true/' Cargo.toml

cat Cargo.toml

# Fails
RUST_BACKTRACE=full cargo build --release

I expected to see this happen: Either a successful build, or a standard compiler error.

Instead, this happened: LTO broke the compiler:

$ cargo build --release
   Compiling shared v0.1.0 (/home/nyx/rustbug/shared)
   Compiling child v0.1.0 (/home/nyx/rustbug/child)
   Compiling parent v0.1.0 (/home/nyx/rustbug/parent)
thread 'rustc' panicked at 'assertion failed: !are_upstream_rust_objects_already_included(sess)', src/librustc_codegen_llvm/back/link.rs:1402:9
stack backtrace:
   0:     0x7f7e1f91e793 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::hf8722b0178fb1b63
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x7f7e1f916c48 - std::sys_common::backtrace::_print::hc40139e5f1d656ee
                               at src/libstd/sys_common/backtrace.rs:70
   2:     0x7f7e1f91a922 - std::panicking::default_hook::{{closure}}::h993d43465919c16a
                               at src/libstd/sys_common/backtrace.rs:58
                               at src/libstd/panicking.rs:200
   3:     0x7f7e1f91a694 - std::panicking::default_hook::h73d2c2ec3d9ba5a4
                               at src/libstd/panicking.rs:215
   4:     0x7f7e1b3f631f - rustc::util::common::panic_hook::he83c1d31ee2662ae
   5:     0x7f7e1f91b109 - std::panicking::rust_panic_with_hook::h744417edfe714d72
                               at src/libstd/panicking.rs:482
   6:     0x7f7e153e8374 - std::panicking::begin_panic::hf2f2c845ae9fde35
   7:     0x7f7e15441d85 - rustc_codegen_llvm::back::link::link_natively::had7c6ec0331ae050
   8:     0x7f7e1543badf - rustc_codegen_llvm::back::link::link_binary::h190e3be9b1179a44
   9:     0x7f7e15323882 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::join_codegen_and_link::{{closure}}::h378fa211691cf192
  10:     0x7f7e1531d843 - rustc::util::common::time::hba8b261a48e7f916
  11:     0x7f7e153570b4 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::join_codegen_and_link::h1b338c342f4da9e8
  12:     0x7f7e1fcf48cd - rustc_driver::driver::compile_input::h65aaa3180b3e84e4
  13:     0x7f7e1fc4fdd0 - rustc_driver::run_compiler_with_pool::h7731b79ae97e4d21
  14:     0x7f7e1fc5bc05 - <scoped_tls::ScopedKey<T>>::set::h10a9d6691c6667b2
  15:     0x7f7e1fc4ec1a - rustc_driver::run_compiler::hccae18cc847caa81
  16:     0x7f7e1fc5bdba - <scoped_tls::ScopedKey<T>>::set::h71212949a1d6fa63
  17:     0x7f7e1fccd802 - std::sys_common::backtrace::__rust_begin_short_backtrace::h76607ec057ea37b9
  18:     0x7f7e1f92c529 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:92
  19:     0x7f7e1fce4fa0 - <F as alloc::boxed::FnBox<A>>::call_box::h33b88f71d009a576
  20:     0x7f7e1f92b2ed - std::sys::unix::thread::Thread::new::thread_start::h6fb76bcf544b6181
                               at /rustc/2aa4c46cfdd726e97360c2734835aa3515e8c858/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
                               at src/libstd/sys/unix/thread.rs:81
  21:     0x7f7e1f6a06b9 - start_thread
  22:     0x7f7e1efca41c - clone
  23:                0x0 - <unknown>
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.33.0 (2aa4c46cf 2019-02-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C lto --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `parent`.

To learn more, run the command again with --verbose.

Meta

rustc --version --verbose:

rustc 1.33.0 (2aa4c46cf 2019-02-28)
binary: rustc
commit-hash: 2aa4c46cfdd726e97360c2734835aa3515e8c858
commit-date: 2019-02-28
host: x86_64-unknown-linux-gnu
release: 1.33.0
LLVM version: 8.0
@jonas-schievink jonas-schievink added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 12, 2019
@hellow554
Copy link
Contributor

Can you setup a repo with the example?

@GinjaNinja32
Copy link
Author

GinjaNinja32 commented Mar 13, 2019

https://github.com/GinjaNinja32/rust-issues/tree/59137

@hellow554
Copy link
Contributor

Also happens on debug when lto=true is enabled.

@hellow554
Copy link
Contributor

hellow554 commented Mar 13, 2019

Has nothing to do with child. When you delete it, the ICE is still present.
Has nothing to do with incremental compiling.

@hellow554
Copy link
Contributor

hellow554 commented Mar 13, 2019

https://github.com/rust-lang/rust/blob/master/src/librustc_codegen_llvm/back/link.rs#L1399-L1401

// If we're performing LTO, then it should have been previously required
// that all upstream rust dependencies were available in an rlib format.
assert!(!are_upstream_rust_objects_already_included(sess));

CC #53031
CC @michaelwoerister @alexcrichton

@michaelwoerister
Copy link
Member

Thanks for the bug report, @GinjaNinja32! And thanks for already taking a look, @hellow554!

I suspect this is related to using dylib (i.e. "Rust dylibs") dependencies.

Nominating for priority assignment.

@pnkfelix
Copy link
Member

triage: P-high. Leaving nominated for discussion at meeting.

@pnkfelix pnkfelix added the P-high High priority label Mar 14, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 14, 2019

discussed at meeting. assigning to @michaelwoerister

@pnkfelix
Copy link
Member

and removing nomination tag

@michaelwoerister
Copy link
Member

The assertion here seems to be out of place. #59696 removes it which should fix the issue.

michaelwoerister added a commit to michaelwoerister/rust that referenced this issue Apr 5, 2019
Centril added a commit to Centril/rust that referenced this issue Apr 5, 2019
…=alexcrichton

Remove invalid assertion back::link::from add_upstream_rust_crates().

This removes a misplaced assertion. The function containing the assertion is actually only ever called for upstream crates that are not considered for LTO, so we don't care whether upstream code has been merged in by LTO or not.

Fixes rust-lang#59137

r? @alexcrichton
Centril added a commit to Centril/rust that referenced this issue Apr 5, 2019
…=alexcrichton

Remove invalid assertion back::link::from add_upstream_rust_crates().

This removes a misplaced assertion. The function containing the assertion is actually only ever called for upstream crates that are not considered for LTO, so we don't care whether upstream code has been merged in by LTO or not.

Fixes rust-lang#59137

r? @alexcrichton
Centril added a commit to Centril/rust that referenced this issue Apr 5, 2019
…=alexcrichton

Remove invalid assertion back::link::from add_upstream_rust_crates().

This removes a misplaced assertion. The function containing the assertion is actually only ever called for upstream crates that are not considered for LTO, so we don't care whether upstream code has been merged in by LTO or not.

Fixes rust-lang#59137

r? @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

5 participants