How to fix: Illegal instruction(code dumped)

target: x86_64-unknown-linux-musl

When I run a rust bin on Linux, it shows err:

Illegal instruction(code dumped)

Why and How to Fix?

Thx

can you provide the build command which generate the rust bin?
i think the easiest way to fix the issue is to rebuild the rust bin on the machine where you run the rust bin.

cargo build --release --target x86_64-unknown-linux-musl --features "webui"

and I also use other target, like x86_64-unknown-linux-gnu, but it is not work

the run machine is low performance, cannot rebuild on it

Does the code you're trying to run happen to be open-source? In case it is, you should share a link to it, so others can try reproducing the issue, which would make it easier to figure out what exactly is going on.


Edit: Ah, so your latest edit suggest, this may be about cross compilation? What's the architecture of the machine you build on vs. the one you run on? Also, is this code also runnable on the built machine and if you does it run fine there?

it`s not open source.
it can run on the build machine. the build machine is amd, but the target machine is Cloud

Thanks for the context! Unfortunately, I'm not too familiar with cross compilation of Rust myself, but this information should make it easier for others to help you!

Thx

Are you sure you don't use target-cpu=native compilation flag somewhere in your Cargo config on your local machine?

1 Like

To add to what @newpavlov wrote in addition to specifying the target you probably need to add RUSTFLAGS="-C target-cpu=... to your build environment, where the target architecture is set to where you will run the binary.

I've hit panic=abort deliberately triggering an illegal instruction, but I think that's a Windows last ditch implementation?

can you try to run command lscpu on the target machine? it will show the architecture of the target machine.

that my first thought too. check whether you have a .cargo\config.toml file on local machine which contains incompatible compiler flags. the config file path cargo would check is listed in manual:

https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

1 Like