rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
260 stars 25 forks source link

Building core with the feature panic_immediate_abort #55

Closed parraman closed 4 years ago

parraman commented 4 years ago

Hi,

I'd like to know if it is possible to compile the core library with the feature panic_immediate_abort. If I am not mistaken, this feature is not activated by default when the library is compiled. What I need is for the code not to call the panic hook but directly generate an abort that lowers to an illegal instruction or trap.

I tried to use the RUSTFLAGS tag:

export RUSTFLAGS=--cfg features="panic_immediate_abort"

but it has not worked, as it is apparently not used when compiling sysroot, but only when generating the final library.

I don't know if I'm doing anything wrong. Thanks in advance!

phil-opp commented 4 years ago

I don't think that it's currently possible to build libcore with this feature. However, it should be fairly straightforward to add, in case you want to create a pull request:

First, add a new configuration option to cargo-xbuild by extending config.rs. Don't forget to update the Readme and the help.txt. Next, extend the core dependency declaration of liballoc, which is defined here:

https://github.com/rust-osdev/cargo-xbuild/blob/6407731b96b925080dc90ba7657d87cfa5f49dcc/src/sysroot.rs#L159-L163

You probably want to add something like:

if config.panic_immediate_abort {
    stoml.push_str("features = ['panic_immediate_abort']\n");
}

This should be enough to support this.