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

Compiler panics when 'data-layout' field is missing in LLVM target json #33497

Closed
jgallag88 opened this issue May 8, 2016 · 3 comments
Closed

Comments

@jgallag88
Copy link
Contributor

When I upgraded my compiler to the most recent nightly, I found that my project no longer compiles. Instead, rustc panics, producing this error:

$ RUST_BACKTRACE=1 rustc --target i686-unknown-none-gnu -Z no-landing-pads -C no-redzone -C opt-level=1 -A dead_code -L . -L src rust/src/libcore/lib.rs
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Field data-layout in target specification is required', ../src/librustc_back/target/mod.rs:370
stack backtrace:
   1:     0x7f16d61a1d10 - std::sys::backtrace::tracing::imp::write::h9fb600083204ae7f
   2:     0x7f16d61af58b - std::panicking::default_hook::_$u7b$$u7b$closure$u7d$$u7d$::hca543c34f11229ac
   3:     0x7f16d61af12c - std::panicking::default_hook::hc2c969e7453d080c
   4:     0x7f16d61748cf - std::sys_common::unwind::begin_unwind_inner::h30e12d15ce2b2e25
   5:     0x7f16d61769b8 - std::sys_common::unwind::begin_unwind_fmt::hb2de8a9968d38523
   6:     0x7f16d213b0ca - rustc_back::target::Target::from_json::h0865f3d0efe9d5a8
   7:     0x7f16d213d2bf - rustc_back::target::Target::search::load_file::h10b754eb1c29e7bb
   8:     0x7f16d213ca4a - rustc_back::target::Target::search::h5d24d442a2ed9dcf
   9:     0x7f16d2a39e71 - rustc::session::config::build_target_config::h59bc6d485b6e9271
  10:     0x7f16d2a37f6d - rustc::session::build_session_::h6f9ae75b9cc92e18
  11:     0x7f16d2a365a3 - rustc::session::build_session_with_codemap::h0045b7130fdfbb5c
  12:     0x7f16d66b0367 - rustc_driver::run_compiler::h8902aebf8b1849a8
  13:     0x7f16d66ad7bd - std::sys_common::unwind::try::try_fn::h4c74456035d0fcc7
  14:     0x7f16d619f4eb - __rust_try
  15:     0x7f16d619f47d - std::sys_common::unwind::inner_try::h47a4d9cd4a369dcd
  16:     0x7f16d66ae1ea - _<F as std..boxed..FnBox<A>>::call_box::h27f542a39f1d61ef
  17:     0x7f16d61ad6f4 - std::sys::thread::Thread::new::thread_start::h6f266e069bf4ec2b
  18:     0x7f16cdf226f9 - start_thread
  19:     0x7f16d5e02b5c - clone
  20:                0x0 - <unknown>

As the panic message indicates, the target I was supplying was missing the 'data-layout' field:

$ cat i686-unknown-none-gnu.json
{
    "llvm-target": "i686-unknown-none-gnu",
    "target-endian": "little",
    "target-pointer-width": "32",
    "os": "none",
    "arch": "x86",
    "target-env": "gnu",
    "pre-link-args": [ "-m32" ],
    "features": "-mmx,-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-3dnow,-3dnowa,-avx,-avx2",
    "disable-redzone": true,
    "eliminate-frame-pointer": true,
    "linker-is-gnu": true,
    "no-compiler-rt": true,
    "archive-format": "gnu"
}

I added "data-layout": "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128" to the target, and everything builds once again. The requirement that this field be present apparently is caused by a change in LLVM, according to this issue: #31367. It looks like this was fixed for all of the targets rust uses internally by this change: #32939.

Since targets can be supplied by the user, as in the case above, panicking doesn't really seem warranted. Panicking implies there is a bug in the compiler, whereas the problem might be in the user's input. If the problem is in the user's input, it would be nice for the error to indicate this, to prevent confusion.

$ rustc --version --verbose
rustc 1.10.0-nightly (62e2b2fb7 2016-05-06)
binary: rustc
commit-hash: 62e2b2fb7acf5f8331781cd7128c754ed1b66c4f
commit-date: 2016-05-06
host: x86_64-unknown-linux-gnu
release: 1.10.0-nightly
cardoe added a commit to cardoe/rust that referenced this issue Jul 27, 2016
Change all the target generation functions to return a Result<Target,
String> so that targets that are unable to be instantiated can be
expressed as an Err instead of a panic!(). This should improve rust-lang#33497 as
well.
@cardoe
Copy link
Contributor

cardoe commented Jul 27, 2016

This should likely improve with #34980.

@cardoe
Copy link
Contributor

cardoe commented Nov 29, 2016

This can probably be closed now.

With #34980 (part of Rust 1.12.0) the error becomes:

error: Error loading target specification: Field data-layout in target specification is required
  |
  = help: Use `--print target-list` for a list of built-in targets

Which is exactly what would be expected and guides the user to the right solution.

@alexcrichton
Copy link
Member

Yay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants