rubyjs / mini_racer

Minimal embedded v8
MIT License
597 stars 93 forks source link

"no suitable image found" error on Ruby 3.1.1 #244

Open mbajur opened 2 years ago

mbajur commented 2 years ago

Hello,

i have an app I'm trying to upgrade from Ruby 2.7.3 to 3.1.1 and here is what's being raised after i try to run any command or start a server:

➜  yyy git:(rails-7) ✗ rails c
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead.
/Users/mbajur/.rvm/gems/ruby-3.1.1/gems/mini_racer-0.6.2/lib/mini_racer.rb:11:in `load': dlopen(/Users/mbajur/.rvm/gems/ruby-3.1.1/extensions/x86_64-darwin-20/3.1.0/mini_racer-0.6.2/mini_racer_extension.bundle, 5): no suitable image found.  Did find: (LoadError)
        /Users/mbajur/.rvm/gems/ruby-3.1.1/extensions/x86_64-darwin-20/3.1.0/mini_racer-0.6.2/mini_racer_extension.bundle: unknown file type, first eight bytes: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        /Users/mbajur/.rvm/gems/ruby-3.1.1/extensions/x86_64-darwin-20/3.1.0/mini_racer-0.6.2/mini_racer_extension.bundle: unknown file type, first eight bytes: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/mini_racer-0.6.2/lib/mini_racer.rb:11:in `<main>'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bootsnap-1.7.7/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler/runtime.rb:60:in `block (2 levels) in require'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler/runtime.rb:55:in `each'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler/runtime.rb:55:in `block in require'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler/runtime.rb:44:in `each'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler/runtime.rb:44:in `require'
        from /Users/mbajur/.rvm/gems/ruby-3.1.1/gems/bundler-2.2.27/lib/bundler.rb:174:in `require'
        from /Users/mbajur/workspace/pro/xxx/yyy/config/application.rb:19:in `<main>'

I was not able to google anything regarding such exception. I'm on macOS Big Sur + RVM. Please have in mind it works perfectly fine on 2.7.3

Thanks!

tisba commented 2 years ago

Hey @mbajur, please check out https://github.com/rubyjs/mini_racer#troubleshooting. I'm guessing you have to re-install (recompile) mini_racer and libv8-node.

mbajur commented 2 years ago

If that means i just need to run gem uninstall --all mini_racer libv8-node and bundle install - it didn't helped :( (together with all the other steps)

tisba commented 2 years ago

hmm, I have no old macOS available. Any idea what that could be @lloeki?

lloeki commented 2 years ago

Hmm, no I don't.

This is weird:

first eight bytes: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00

These are the first bytes one is supposed to get (arm64, but anyway they should not be 0x00 at all):

$ od -xa tmp/arm64-darwin20/mini_racer_extension/3.0.2/mini_racer_extension.bundle | head -1
0000000    facf    feed    000c    0100    0000    0000    0008    0000
ianperera commented 2 years ago

I am getting same issues on Mac OS Big Sur when I run rake db:prepare. Any work around?

This is my platform information

~% bundle platform
Your platform is: x86_64-darwin-20

Your app has gems that work on these platforms:
* arm64-darwin-21
* x86_64-darwin-19
* x86_64-darwin-20
* x86_64-linux

Your Gemfile specifies a Ruby version requirement:
* ruby 3.1.1p18

This is my gem version

% gem --version
3.3.11
tisba commented 2 years ago

There was an update to Xcode Command Line Utilities recently. Did you by any chance install this, @ianperera? This will update libraries that mini_racer is linking to. Make sure to run gem uninstall --all mini_racer libv8-node.

ianperera commented 2 years ago

There was an update to Xcode Command Line Utilities recently. Did you by any chance install this, @ianperera? This will update libraries that mini_racer is linking to. Make sure to run gem uninstall --all mini_racer libv8-node.

This is my gcc informations from xcode 13.2.1.

 % gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.30)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

I have already tried to run this command gem uninstall --all mini_racer libv8-node many times.

tisba commented 2 years ago

If you have the exact same problem, could you make sure that

/Users/USER/.rvm/gems/ruby-3.1.1/extensions/x86_64-darwin-20/3.1.0/mini_racer-0.6.2/mini_racer_extension.bundle

is removed when you uninstall the gems? I'm wondering if there are some leftover elsewhere, like build caches or something. I've never seen that issue before though, but I'm running out of ideas. Unfortunately I only have Monterey (macOS 12 / darwin21) around.

samueldemoura commented 2 years ago

I was having the exact same problem on an Intel Mac running Big Sur, and all the suggestions given above eventually lead to the same error after the final bundle install && rails s. The thing that finally fixed this was simply:

After that, the gem seems to be working as expected.

I'm not sure what exactly is broken, but the mini_racer_extension.bundle that gets installed after a bundle install has a massive section of 0x00s at the beginning, while the one that gets spit out after manually running make has the proper header:

➜ hexdump -n4 mini_racer_extension.bundle
0000000 cf fa ed fe

I didn't bother investigating any deeper and I don't really have any knowledge on bundler/gem internals, but if I had to guess it seems like either some bad parameters are being passed to the make invocation which is causing it to spit out a messed up binary, or the copy/install operation is somehow corrupting the beginning of the file.

It doesn't seem to be related to the Ruby version - OP says it works on 2.7.3 but breaks on 3.1.1, but I'm willing to bet a fresh rebuild on 2.7.3 would fail for him as well, since this is what happened to me on 2.6.9 (previous install was working, many months later I did a fresh reinstall and started getting the error). Also doesn't seem to be related to the version manager, since OP is using rvm and I observed this with both rbenv and asdf.

Either way, hopefully this helps anyone else who stumbles upon this issue via search.

tisba commented 1 year ago

A lot has been updated and changed in the last 12 months. Could you give it another shot with the latest released mini_racer 0.8.0? I recently did some tests with Monterey and Ventura VMs using homebrew + rvm to get a fresh Ruby installation and was able to build mini_racer without any issues.

If you still encounter this issue, it would be helpful if you could provide the complete build logs.

-ping @samueldemoura @ianperera @mbajur