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

Panic=abort as a target option? #36647

Closed
phil-opp opened this issue Sep 22, 2016 · 4 comments · Fixed by #36794
Closed

Panic=abort as a target option? #36647

phil-opp opened this issue Sep 22, 2016 · 4 comments · Fixed by #36794

Comments

@phil-opp
Copy link
Contributor

Let's assume a target with no unwinding support (e.g. a small system on a chip). RFC 1513 added a -C panic=strategy flag and a cargo profile option for disabling the unwinding machinery. However, even with those options, we still need dummy implementations for eh_personality and _Unwind_Resume.

The reason is that the cross-compiled sysroot (e.g. via xargo) still contains references to those functions. We can avoid this by setting RUSTFLAGS to -C panic=abort when invoking xargo. This way, the sysroot is created without unwinding. This solution works, but feels a bit hacky.

We could solve this problem in an easier way if we added a option for panic=abort in the target json. Then we could express targets without unwinding support and xargo would automatically compile the sysroot correctly.

@hanna-kruppe
Copy link
Contributor

A concept of targets without unwinding support would not only be useful for embedded programming but also for GPU-ish targets.

@alexcrichton
Copy link
Member

This seems reasonable to me. The current default is set here but we could make that an option and instead punt the default to the target spec.

@japaric
Copy link
Member

japaric commented Sep 25, 2016

I'll give this a try.

japaric pushed a commit to japaric/rust that referenced this issue Sep 28, 2016
Now a target can define its panic strategy in its specification. If a
user doesn't specify a panic strategy via the command line, i.e. '-C
panic', then the compiler will use the panic strategy defined by the
target specification.

Custom targets can pick their panic strategy via the "panic-strategy"
field of their target specification JSON file. If omitted in the
specification, the strategy defaults to "unwind".

closes rust-lang#36647
@japaric
Copy link
Member

japaric commented Sep 28, 2016

Fix in #36794

sophiajt pushed a commit to sophiajt/rust that referenced this issue Sep 29, 2016
add a panic-strategy field to the target specification

Now a target can define its panic strategy in its specification. If a
user doesn't specify a panic strategy via the command line, i.e. '-C
panic', then the compiler will use the panic strategy defined by the
target specification.

Custom targets can pick their panic strategy via the "panic-strategy"
field of their target specification JSON file. If omitted in the
specification, the strategy defaults to "unwind".

closes rust-lang#36647

---

I checked that compiling an executable for a custom target with "panic-strategy" set to "abort" doesn't need the "eh_personality" lang item and also that standard crates compiled for that custom target didn't contained undefined symbols to _Unwind_Resume. But this needs an actual unit test, any suggestion on how to test this?

Most of the noise in the diff is due to moving `PanicStrategy` from the `rustc` to the `rustc_back` crate.

r? @alexcrichton
cc @phil-opp
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

Successfully merging a pull request may close this issue.

4 participants