rust icon indicating copy to clipboard operation
rust copied to clipboard

Illegal Instruction from rust installation

Open samothx opened this issue 2 years ago • 3 comments

I am getting an Illegal Instruction when trying to install rust on a VPS running debian 10: Linux version 5.10.0-16-amd64 ([email protected]) (gcc-10 (Debian 10.2.1-6) 10.2.1 20210110, GNU ld (GNU Binutils for Debian) 2.35.2) #1 SMP Debian 5.10.127-1 (2022-06-30)

I tried this code:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

I expected to see this happen: installation of rust

Instead, this happened:

info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/thomas/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/thomas/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/thomas/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/thomas/.profile
  /home/thomas/.bashrc
  /home/thomas/.zshenv

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
Illegal instruction

samothx avatar Aug 05 '22 05:08 samothx

This issue is found in Rustup. Can someone transfer this there?

Unfortunately quite a lot of action happens right after that message. It may be due to SHA2 acceleration, or it may even have been a malformed instruction. https://github.com/rust-lang/rustup/issues/595

But it may also be due to OpenSSL. https://github.com/rust-lang/rustup/issues/1565

Would you please run this in the shell?

cat /proc/cpuinfo | grep 'flags' | uniq

workingjubilee avatar Aug 06 '22 01:08 workingjubilee

cat /proc/cpuinfo | grep 'flags' | uniq

flags : fpu de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 syscall nx lm nopl cpuid tsc_known_freq pni cx16 hypervisor lahf_lm svm abm sse4a 3dnowprefetch vmmcall

samothx avatar Aug 06 '22 04:08 samothx

I also found this in dmsg: [109268.842512] traps: rustup-init[37790] trap invalid opcode ip:55bdc536d208 sp:7ffe5633c1d0 error:0 in rustup-init[55bdc4e00000+a88000] [109586.401035] traps: rustup-init[38248] trap invalid opcode ip:557e4f76d208 sp:7fffcf846240 error:0 in rustup-init[557e4f200000+a88000] [110370.282129] traps: rustup-init[39127] trap invalid opcode ip:5586a4f6d208 sp:7ffc96683e20 error:0 in rustup-init[5586a4a00000+a88000]

samothx avatar Aug 06 '22 04:08 samothx

...why the hell would it advertise it supports SSE4a but it wouldn't advertise support for SSE3 or SSSE3? I mean it looks normal aside from that...

If you run with ulimit -c unlimited you should be able to get a core dump and then attach gdb to it in order to determine which instruction was in fact located at that address during that execution. Very peculiar.

workingjubilee avatar Aug 07 '22 10:08 workingjubilee

Not quite sure what exactly you want me to do: I have called called 'ulimit -c unlimited', installed gdb and started it with the downloaded rustup-init executable with the following output:

...

  1. Proceed with installation (default)
  2. Customize installation
  3. Cancel installation

1

info: profile set to 'default' info: default host triple is x86_64-unknown-linux-gnu info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu' [New Thread 0x7ffff7a67700 (LWP 19681)] [New Thread 0x7ffff7866700 (LWP 19682)]

Thread 1 "rustup-init" received signal SIGILL, Illegal instruction. 0x000055555596d208 in sha2::sha512::x86::sha512_compress_x86_64_avx2 () (gdb)

On Sun, 2022-08-07 at 03:02 -0700, Jubilee wrote:

...why the hell would it advertise it supports SSE4a but it wouldn't advertise support for SSE3 or SSSE3? I mean it looks normal aside from that... If you run with ulimit -c unlimited you should be able to get a core dump and then attach gdb to it in order to determine which instruction was in fact located at that address during that execution. Very peculiar. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

samothx avatar Aug 09 '22 04:08 samothx

I am having a similar issue when installing Rust in my 10+ old laptop (running Void Linux Linux 5.13.19_1 i686 GNU/Linux).

$ cat /proc/cpuinfo | grep 'flags' | uniq
flags		: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov clflush dts acpi mmx fxsr sse sse2 ss tm pbe nx bts cpuid est tm2 pti
$ dmesg
[ 2896.175549] traps: rustup-init[6740] trap invalid opcode ip:9b053c sp:bf81d590 error:0 in rustup-init[4dc000+9d2000]
[ 2940.808251] traps: rustup-init[6785] trap invalid opcode ip:97253c sp:bfcb2a50 error:0 in rustup-init[49e000+9d2000]
$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/pico/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /home/pico/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/pico/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/pico/.profile
  /home/pico/.bash_profile
  /home/pico/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: i686-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is i686-unknown-linux-gnu
info: syncing channel updates for 'stable-i686-unknown-linux-gnu'
Illegal instruction

cguimaraes avatar Aug 30 '22 15:08 cguimaraes

This issue is most likely due to https://github.com/RustCrypto/hashes/pull/386 which has been fixed in 0.2.4 of the cpufeatures crate but https://github.com/rust-lang/rustup/blob/master/Cargo.lock#L350 is locked to 0.2.2

Checking for avx2 on my Intel Pentium M 725 machine which doesn't support it, returns true on cpufeatures versions earlier than 0.2.4

gardell avatar Sep 29 '22 21:09 gardell

Can anybody tell me how can I install rust on my pc?

I always got the error: Illegal instruction...

DenisSemakin avatar Dec 05 '22 08:12 DenisSemakin

Here a backtrace:

Thread 1 "rustup-init" received signal SIGILL, Illegal instruction.
0x00007ffff781bc11 in sha2::sha512::x86::sha512_compress_x86_64_avx2 ()
(gdb) bt
#0  0x00007ffff781bc11 in sha2::sha512::x86::sha512_compress_x86_64_avx2 ()
#1  0x00007ffff78179d3 in sha2::sha512::Engine512::update ()
#2  0x00007ffff77b9a04 in sequoia_openpgp::parse::hashed_reader::<impl sequoia_openpgp::parse::Cookie>::hash_update ()
#3  0x00007ffff76c2082 in rustup::dist::signatures::verify_signature ()
#4  0x00007ffff76bf7f8 in rustup::dist::download::DownloadCfg::check_signature ()
#5  0x00007ffff766e8f4 in rustup::dist::download::DownloadCfg::download_and_check ()
#6  0x00007ffff766d088 in rustup::dist::dist::dl_v2_manifest ()
#7  0x00007ffff76689e0 in rustup::dist::dist::try_update_from_dist_ ()
#8  0x00007ffff7665aaa in rustup::install::InstallMethod::install ()
#9  0x00007ffff7663237 in rustup::toolchain::DistributableToolchain::install_from_dist ()
#10 0x00007ffff774d0aa in rustup::cli::self_update::install ()
#11 0x00007ffff7746a46 in rustup::cli::setup_mode::main ()
#12 0x00007ffff73cd071 in rustup_init::main ()
#13 0x00007ffff73cb223 in std::sys_common::backtrace::__rust_begin_short_backtrace ()
#14 0x00007ffff73cd940 in main ()

lu-zero avatar Dec 07 '22 17:12 lu-zero

@lu-zero Yes, it's well-known fact. And what next?

DenisSemakin avatar Dec 13 '22 07:12 DenisSemakin

The root problem is in https://github.com/RustCrypto/utils/blob/master/cpufeatures/src/x86.rs cpufeatures should use stdarch detection when built in std instead of relying on its minimalistic approach.

Long story short, there is a disagreement on what is in the cpu registers, what the kernel wants to support and what the virtualization system offers.

What is your PC exactly?

lu-zero avatar Dec 13 '22 11:12 lu-zero

I'm newbie in Rust. Cargo, rustc, rustup all these words are new for me. I've just wanted to start learning this prog language but faced with this problem. I want to install Rust on virtual machine (Virtual Box or QEMU) with 5.x and 6.x Linux kernel. @lu-zero

DenisSemakin avatar Dec 13 '22 11:12 DenisSemakin

that's not a PC and qemu and virtualbox are very different how did you manage to configure either of them to trigger the sigill?

lu-zero avatar Dec 13 '22 12:12 lu-zero

@lu-zero I didn't configure the VM myself. Sysadmin just gave it to me with already installed OS. Actually I don't understand little bit where exactly the bug is? On HW side or SW? If it could help somehow here is the lscpu flags on VM:

Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm
                                  constant_tsc rep_good nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popc
                                 nt tsc_deadline_timer aes f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced fsgsbas
                                 e tsc_adjust bmi1 hle smep bmi2 erms invpcid rtm rdseed adx smap clflushopt clwb arat md_clear flush_l1d arch_capabilities

DenisSemakin avatar Dec 14 '22 01:12 DenisSemakin

You'd need a tiny program based on https://github.com/RustCrypto/utils/tree/master/cpufeatures to confirm it still misdetects avx2, install rustup on real hardware to build it (getting binaries from unknown sources is never a great idea)

lu-zero avatar Dec 14 '22 08:12 lu-zero

Ok. Thx

DenisSemakin avatar Dec 14 '22 08:12 DenisSemakin

@DenisSemakin

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

it can corrupt your installation and give "illegal instruction".

try command rustup self uninstall

now you can use a "Standalone installers" stable version

https://forge.rust-lang.org/infra/other-installation-methods.html#standalone-installers

unzip and then look for "install.sh"

chmod +x ./install.sh sudo ./install.sh

open a new terminal

rustc --version

After 3 days "Rustup corrupted my installations, and I managed to install it"

"Pentium M" i686 now has Rust :D

ghost avatar Dec 15 '22 06:12 ghost

@sparkillay I knew it. I suspected that somewhere should be a resource with that. Thanks!

DenisSemakin avatar Dec 15 '22 09:12 DenisSemakin

Hi I can also report the "trap invalid opcode ip: sp: error:0 in rustup-init" messages when trying to connect to a machine using Rustdesk.

I have a Q6600. Modern arch (Ryzen 2400G) is not affected.

Is there a way to update that specific lib which does the check? What is the cause of the error?

I'd like to understand and maybe help.

blackandcold avatar Dec 30 '22 23:12 blackandcold

I have this issue with latest rustup-init in a ubuntu VM. Here is the detail information:

# /tmp/rustup-init --version
rustup-init 1.25.2 (17db695f1 2023-02-01)

# cat /etc/os-release | grep VER
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy

# uname -r
5.15.0-53-generic

# lscpu | grep avx
# lscpu | grep Flags
Flags:                           fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pse36 clflush mmx fxsr sse sse2 syscall nx rdtscp lm rep_good nopl cpuid tsc_known_freq pni ssse3 cx16 pcid x2apic movbe popcnt aes f16c rdrand hypervisor lahf_lm abm pti bmi1 smep bmi2

# gdb output
Thread 1 "rustup-init" received signal SIGILL, Illegal instruction.
0x000055555594e131 in sha2::sha512::x86::sha512_compress_x86_64_avx2 ()

jamesvren avatar Mar 02 '23 02:03 jamesvren

@gardell , update cpufeatures to 0.2.5 in rustup was merged in this commit but it is not part of current rustup version (1.25.2)

I have some workaround for Qemu users. Despite I use Intel procesor I pass argument -cpu Opteron_G5 and omit avx2 issue. @DenisSemakin until the new version will not be released, The W/A deals with the issue.

KamilDuljas avatar Apr 12 '23 10:04 KamilDuljas

Is there any way to solve this problem now?

`$ cat /proc/cpuinfo | grep 'flags'

flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx rdtscp lm constant_tsc nopl xtopology nonstop_tsc cpuid tsc_known_freq pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes f16c rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single pti fsgsbase tsc_adjust bmi1 smep bmi2 invpcid rdseed adx smap clflushopt dtherm arat pln pts `

yangzhenjiang159 avatar Apr 13 '23 03:04 yangzhenjiang159

hello, also seeing a SIGILL error (illegal instruction) when attempting to install on PPC64 (POWER5+)

$ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
info: downloading installer
Illegal instruction

barf avatar Apr 13 '23 07:04 barf

These issues do not seem to be with rustc, properly speaking, so I am going to close this, sorry.

workingjubilee avatar Jun 21 '23 00:06 workingjubilee

Hello can we please re-open this?

To reproduce (without POWER hardware) you can grep the objdump for 'vxor' which is optional AltiVec instruction, which AFAIK is not present on some IBM servers or embedded platforms etc:

$ wget https://static.rust-lang.org/rustup/dist/powerpc64-unknown-linux-gnu/rustup-init
$ objdump -d rustup-init |grep vxor

barf avatar Aug 23 '23 23:08 barf

The PowerPC64 target is defined to include Altivec support[^1]. As I understand it, POWER servers for some time have full support for Altivec. Many architectures have highly "off-spec" embedded implementations which de facto are separate CPU architectures, so it is not surprising if the embedded chips do not support it.

[^1]: It will surprise no one who knows the history of Clang, and thus LLVM, to know that the PPC64 target as-understood by LLVM is equivalent to the PowerPC G5, minus some deprecated instructions which the G5 would architecturally support.

workingjubilee avatar Aug 24 '23 06:08 workingjubilee

Thanks for looking at this @workingjubilee -- can the rust installer be built without optimisations that break compatibility like this? It seems like a compiler flag issue?

Building rust from sources is also impacted by this unfortunately, SIGILL also results running $ python3 x.py

barf avatar Aug 24 '23 07:08 barf

Compatibility with what? You have not named the actual hardware you even want to run anything on. There are x86-64 chips that rustc and Rustup cannot easily run on either, because those x86 chips are also wildly off-spec.

workingjubilee avatar Aug 24 '23 07:08 workingjubilee

Debian on POWER5 (IBM 9406-520) -- no AltiVec and definately not off-spec, IBM made the architecture...

barf avatar Aug 24 '23 08:08 barf

The x86-64 CPUs I am referring to which cannot run common x86-64 binaries were made by none other than Intel. And no, not as a quirk of Intel64 vs. AMD64. Rather, the first "Xeon Phi" CPUs were deliberately nonconformant and only implemented AVX instructions, not SSE. I hope you can see, from that, that the lines a compiler has to draw as to what it does for default support are often very arbitrary.

The problem you are running into cannot be fixed by merely changing how Rustup is built, because then Rustup would download rustc binaries that use Altivec instructions. Likewise, much like C compilers are built with other C compilers, generally, the Rust compiler is built with a Rust compiler. I see you already have #110278 open for that, so please pursue it there.

workingjubilee avatar Aug 24 '23 17:08 workingjubilee