sorbet: sorbet-static has "Illegal instruction" on AMD Phenom II

CPU: AMD Phenom™ II X4 955 Processor (model 4, stepping 2) OS: openSUSE-LEAP-15.1

$ gem install --user sorbet-static
$ ~/.gem/ruby/2.5.0/gems/sorbet-static-0.4.4573-x86_64-linux/libexec/sorbet
Illegal instruction

I guess this is somehow caused, by how the binaries for https://rubygems.org/gems/sorbet are being build.

I tried to compile sorbet-static myself, but that failed due to some bazel errors. See: #1486

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 18 (4 by maintainers)

Most upvoted comments

I’m getting something similar when running it in docker using the linux/amd64 platform. It works great when running it natively on my mac.

/usr/local/bundle/gems/sorbet-0.5.10974/bin/srb: line 46: 362 Illegal instruction “${sorbet}” “${args[@]}”

Found the problem, I managed

I was having the same issue as you on my project on apple silicon + docker. But when trying to recreate to test it on a clean docker container I couldn’t replicate the issue. Running this command resulted in no errors:

docker run --platform linux/amd64 -it ruby:3.2.2 bash
echo "
source 'https://rubygems.org'

gem 'sorbet', :group => :development
gem 'sorbet-runtime'
gem 'tapioca', require: false, :group => :development
" > Gemfile

bundle install
bundle exec ruby -e 'puts(require "sorbet-runtime")'

Trying this here, but replacing bundle exec ruby -e 'puts(require "sorbet-runtime")' with bundle exec srb init. I still get the same problem. 😕

/usr/local/bundle/gems/sorbet-0.5.11068/bin/srb: line 46: 261 Illegal instruction “${sorbet}” “${args[@]}”

I managed to reproduce your problem and the binary is indeed not working. I managed to get it working by compiling the Linux distribution with the flag “–copt=-march=x86-64” instead of “–copt=-march=sandybridge”. This is concerning because it seems that the gem in it’s current state is unusable in MacBooks with Docker containers on x86-64 architecture.

I don’t know if this flag is important to this gem performance, but the only solution I see here is compiling the binary ourselves or convincing the repo mainteners to compile the binary with “–copt=-march=x86-64”.

Yep, can confirm this. Making the docker image as described in the previous comment, and then running bundle exec srb init ends in:

/usr/local/bundle/gems/sorbet-0.5.11141/bin/srb: line 46:   255 Illegal instruction     "${sorbet}" "${args[@]}"
/usr/local/lib/ruby/3.2.0/json/common.rb:216:in `parse': unexpected token at '' (JSON::ParserError)
	from /usr/local/lib/ruby/3.2.0/json/common.rb:216:in `parse'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/require_everything.rb:134:in `rb_file_paths'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/require_everything.rb:46:in `require_all_files'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/require_everything.rb:20:in `require_everything'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/gem-generator-tracepoint.rb:39:in `block in main'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/gem-generator-tracepoint/tracer.rb:80:in `trace'
	from /usr/local/bundle/gems/sorbet-0.5.11141/lib/gem-generator-tracepoint.rb:38:in `main'
	from /usr/local/bundle/gems/sorbet-0.5.11141/bin/srb-rbi:251:in `block in make_step'
	from /usr/local/bundle/gems/sorbet-0.5.11141/bin/srb-rbi:135:in `init'
	from /usr/local/bundle/gems/sorbet-0.5.11141/bin/srb-rbi:215:in `main'
	from /usr/local/bundle/gems/sorbet-0.5.11141/bin/srb-rbi:256:in `<main>'

This is on an M1 MacBook Pro running Sonoma.

I’m getting something similar when running it in docker using the linux/amd64 platform. It works great when running it natively on my mac.

/usr/local/bundle/gems/sorbet-0.5.10974/bin/srb: line 46: 362 Illegal instruction “${sorbet}” “${args[@]}”

I was having the same issue as you on my project on apple silicon + docker. But when trying to recreate to test it on a clean docker container I couldn’t replicate the issue. Running this command resulted in no errors:

docker run --platform linux/amd64 -it ruby:3.2.2 bash
echo "
source 'https://rubygems.org'

gem 'sorbet', :group => :development
gem 'sorbet-runtime'
gem 'tapioca', require: false, :group => :development
" > Gemfile

bundle install
bundle exec ruby -e 'puts(require "sorbet-runtime")'

After digging up my dockerfile I notice some commands to cleanup some gems artifacts in the directory ‘/usr/local/bundle/gems/’ . I commented them out from the dockerfile and Sorbet started working normally.

@DarkDimius is there any documentation on how to use the WASM version?

I was able to successfully compile and run on an Intel Xeon L5520 using this option:

  build --copt=-march=native

Now that I have a working binary, I’m not sure if there’s a better way to get it running in my project other than dropping it into ~/.gem/ruby/2.6.0/gems/sorbet-static-0.4.5072-x86_64-linux/libexec/sorbet.

EDIT: I see I can use https://github.com/sorbet/sorbet/tree/master/gems/sorbet#environment-variables SRB_SORBET_EXE=bazel-bin/main/sorbet.