From: "tenderlovemaking (Aaron Patterson) via ruby-core" Date: 2025-02-18T19:36:16+00:00 Subject: [ruby-core:121111] [Ruby master Feature#21140] Add a method to get the address of certain JIT related functions Issue #21140 has been updated by tenderlovemaking (Aaron Patterson). Eregon (Benoit Daloze) wrote in #note-13: > Would this API be needed for e.g. a JIT in the FFI gem? (https://railsatscale.com/2025-02-12-tiny-jits-for-a-faster-ffi/) > Looking at the PoC I'm unsure but I think not. It's hard to know for sure until we finish it ���� > I think it's a good idea to have this API not accessible by default because it is deep internals which are meant for experimentation and nothing else. > If there is a convincing non-experimental use case that needs it, then it's a feature it's not accessible by default, because we would actually want to re-discuss and potentially expose the needed parts properly. I don't think providing the method _hurts_ anything. It's experimental and unstable, so people who build anything with it should understand the risks of depending on it. > > This information can be recovered via dlsym > > Why not just use dlsym() then? (e.g. after `dlopen(NULL, flags)`) > It seems basically equivalent to this API (it also takes a function name and returns an integer), and anyway one needs to ability to call native functions to use this API. Many of the functions would work, but the list of functions I provided above do not. Their symbols are not available via `dlsym`. They can be recovered via DWARF, but from my experience with TenderJIT v1, it's a _huge_ pain. ``` [aaron@tc-lan-adapter ~]$ ruby -v -r fiddle -e'p Fiddle::Handle::DEFAULT["rb_vm_throw"]' ruby 3.5.0dev (2025-02-14T21:16:53Z master ba148e71e5) +PRISM [arm64-darwin24] -e:1:in 'Fiddle::Handle#[]': unknown symbol "rb_vm_throw" (Fiddle::DLError) from -e:1:in '
' [aaron@tc-lan-adapter ~]$ ruby -v -r fiddle -e'p Fiddle::Handle::DEFAULT["rb_shape_id"]' ruby 3.5.0dev (2025-02-14T21:16:53Z master ba148e71e5) +PRISM [arm64-darwin24] 4306064836 ``` Both `rb_vm_throw` and `rb_shape_id` are listed in the YJIT bindgen file, but only one symbol is visible via `dlsym`. If all of the symbols were available via `dlsym` then I would not propose this API. ---------------------------------------- Feature #21140: Add a method to get the address of certain JIT related functions https://bugs.ruby-lang.org/issues/21140#change-112033 * Author: tenderlovemaking (Aaron Patterson) * Status: Open ---------------------------------------- Feature #21116 extracted RJIT as a gem. But RJIT accesses certain internal functions which it cannot access as a gem. For example it used the `rb_str_bytesize` function, but this symbol is not exported, so we cannot access it (even from a C extension). Instead of exporting these symbols, I would like to propose an API for getting access to their addresses in Ruby. For example ```ruby RubyVM::RJIT.address_of(:rb_str_bytesize) # => 123456 ``` I would like to limit the addresses to [this list](https://github.com/ruby/ruby/blob/f32d5071b7b01f258eb45cf533496d82d5c0f6a1/tool/rjit/bindgen.rb#L510-L578) which are the ones required by RJIT. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/