oracle / truffleruby

A high performance implementation of the Ruby programming language, built on GraalVM.
https://www.graalvm.org/ruby/
Other
3.02k stars 185 forks source link

External LLVMFunction rb_check_safe_obj cannot be found with sqlite3 1.3.13 and Rails 5 #2618

Closed eregon closed 2 years ago

eregon commented 2 years ago

See https://github.com/thoughtbot/factory_bot/runs/5458798971?check_suite_focus=true and https://github.com/thoughtbot/factory_bot/issues/1529#issuecomment-1061727535

Rails 5 is anyway not supported with Ruby 3+ so that part does not matter (https://github.com/rails/rails/issues/40938), but it'd still be good to understand why this error happens, and it seems to be different on CRuby.

$ truffleruby -rsqlite3 -e 'db = SQLite3::Database.new "test.db"; p db'
truffleruby: an internal exception escaped out of the interpreter,
please report it to https://github.com/oracle/truffleruby/issues.

External LLVMFunction rb_check_safe_obj cannot be found. (com.oracle.truffle.llvm.runtime.except.LLVMLinkerException)
/home/eregon/.rubies/truffleruby-dev/lib/gems/gems/sqlite3-1.3.13/ext/sqlite3/database.c:60:in `initialize'
    from /home/eregon/.rubies/truffleruby-dev/lib/truffle/truffle/cext_ruby.rb:41:in `initialize'
    from -e:1:in `<main>'
eregon commented 2 years ago

It's the same error on CRuby 3.0.2:

$ ruby -v -rsqlite3 -e 'db = SQLite3::Database.new "test.db"; p db'
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
ruby: symbol lookup error: /home/eregon/.rubies/ruby-3.0.2/lib/ruby/gems/3.0.0/gems/sqlite3-1.3.13/lib/sqlite3/sqlite3_native.so: undefined symbol: rb_check_safe_obj

I just missed it above because there was a newer sqlite3 1.4.2 installed, and so -rsqlite3 picked that.

This is fixed in sqlite3 1.4.2: https://github.com/sparklemotion/sqlite3-ruby/blob/194493be44cd41b73e612eed69ba49354f0d32e7/CHANGELOG.rdoc https://github.com/sparklemotion/sqlite3-ruby/blob/v1.4.2/ext/sqlite3/database.c#L43

Problematic code was: https://github.com/sparklemotion/sqlite3-ruby/blob/v1.3.13/ext/sqlite3/database.c#L60

eregon commented 2 years ago

And there is a compile-time warning:

database.c: In function ‘initialize’:
database.c:60:3: warning: implicit declaration of function ‘rb_check_safe_obj’; did you mean ‘rb_check_safe_str’? [-Wimplicit-function-declaration]
   60 |   rb_check_safe_obj(file);
      |   ^~~~~~~~~~~~~~~~~
      |   rb_check_safe_str

But unfortunately gem install completely hides this, unless using -V (gem i -V sqlite3). Same for bundle install.

Maybe CRuby and/or TruffleRuby should have -Werror=implicit-function-declaration by default.

eregon commented 2 years ago

CRuby issue to address this https://bugs.ruby-lang.org/issues/18615

eregon commented 2 years ago

CRuby 3.2+ will use -Werror=implicit-function-declaration, and TruffleRuby will add it for the 22.2 release.