rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.36k stars 12.72k forks source link

Illegal Instruction from rust installation #100161

Closed samothx closed 1 year ago

samothx commented 2 years ago

I am getting an Illegal Instruction when trying to install rust on a VPS running debian 10: Linux version 5.10.0-16-amd64 (debian-kernel@lists.debian.org) (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
workingjubilee commented 2 years ago

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
samothx commented 2 years ago

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 commented 2 years ago

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]

workingjubilee commented 2 years ago

...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.

samothx commented 2 years ago

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: @.***>

cguimaraes commented 2 years ago

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
gardell commented 2 years ago

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

DenisSemakin commented 1 year ago

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

I always got the error: Illegal instruction...

lu-zero commented 1 year ago

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 ()
DenisSemakin commented 1 year ago

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

lu-zero commented 1 year ago

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?

DenisSemakin commented 1 year ago

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

lu-zero commented 1 year ago

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?

DenisSemakin commented 1 year ago

@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
lu-zero commented 1 year ago

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)

DenisSemakin commented 1 year ago

Ok. Thx

ghost commented 1 year ago

@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

DenisSemakin commented 1 year ago

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

blackandcold commented 1 year ago

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.

jamesvren commented 1 year ago

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 ()
KamilDuljas commented 1 year ago

@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.

yangzhenjiang159 commented 1 year ago

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 `

barf commented 1 year ago

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
workingjubilee commented 1 year ago

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

barf commented 1 year ago

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
workingjubilee commented 1 year ago

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.

barf commented 1 year ago

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

workingjubilee commented 1 year ago

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.

barf commented 1 year ago

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

workingjubilee commented 1 year ago

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.

barf commented 1 year ago

Sorry for the confusion, I've been posting on the wrong issue!

corvinux commented 6 months ago

Operating System: Kali GNU/Linux Rolling
Kernel: Linux 6.6.15-686-pae Architecture: x86 curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh info: downloading installer Illegal instruction cat /proc/cpuinfo | grep 'flags' | uniq flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 mmx fxsr sse syscall mmxext 3dnowext 3dnow cpuid 3dnowprefetch vmmcall 210.668345] traps: rustup-init[858] trap invalid opcode ip:ab5e34 sp:bfb9c200 error:0 in rustup-init[451000+969000] [ 221.860274] traps: rustup-init[897] trap invalid opcode ip:aa9e34 sp:bfa22aa0 error:0 in rustup-init[445000+969000] [ 249.567376] traps: rustup-init[936] trap invalid opcode ip:aa9e34 sp:bf910510 error:0 in rustup-init[445000+969000] [ 441.904459] traps: rustup-init[996] trap invalid opcode ip:acbe34 sp:bfa02760 error:0 in rustup-init[467000+969000] [ 699.417758] traps: rustup-init[1208] trap invalid opcode ip:b5fe34 sp:bf9a2ed0 error:0 in rustup-init[4fb000+969000] [ 968.015442] traps: rustup-init[1255] trap invalid opcode ip:b30e34 sp:bfaccdc0 error:0 in rustup-init[4cc000+969000]

workingjubilee commented 6 months ago

@corvinux Hm. Your CPU is likely being identified as i686 incorrectly when it should be i586, since it doesn't support SSE2 (incorrect, I know, but it's what we expect).

corvinux commented 6 months ago

@corvinux Hm. Your CPU is likely being identified as i686 incorrectly when it should be i586, since it doesn't support SSE2 (incorrect, I know, but it's what we expect). @workingjubilee Thanks for reply, the processor is an old AMD Athlon XP/Duron K7. I managed to install Rust with distro package. I tried it just for fun.