ruby: add DTV-based TLS access for ruby_current_ec#29
Closed
ruby: add DTV-based TLS access for ruby_current_ec#29
Conversation
Member
Author
Coredump Test PlanThis PR needs a coredump test for a dynamically-linked Ruby on musl (Alpine Linux) to exercise the DTV-based Test:
|
06640ae to
c5ef637
Compare
18d5d03 to
817a7d3
Compare
df8e5c6 to
1b19af1
Compare
When TLSDESC relocations are unavailable (e.g. some musl setups or dynamically allocated TLS), the Ruby execution context can still be found by traversing the Dynamic Thread Vector (DTV). This commit: - Adds a shared dtv_read() helper in tsd.h (alongside existing tsd_read) that traverses the DTV using DTVInfo from PR open-telemetry#929's libc introspection. This helper is available to all interpreters, not just Ruby. - Generalizes VisitTLSRelocations into VisitRelocations with a pluggable relocation type filter, enabling lookup of DTPMOD64 relocations to find the TLS module ID offset for libruby.so. - Adds DTVInfo, current_ec_tls_offset, and tls_module_id fields to RubyProcInfo so the eBPF unwinder can use DTV traversal. - Implements UpdateLibcInfo for Ruby to receive DTVInfo when the libc package provides it (may arrive from a separate DSO like ld-linux.so). - Adds a DTV fallback path in ruby_tracer.ebpf.c between the existing TLSDESC path and the ractor fallback.
Adds a coredump test for a shared-library Ruby 3.4.7 on amd64, where libruby.so uses R_X86_64_DTPMOD64 relocations (the default x86_64 TLS dialect). This exercises the DTV-based TLS lookup path: VisitRelocations with DTPMOD64 filter, UpdateLibcInfo with DTVInfo, and dtv_read() in the eBPF unwinder. This test is amd64-only because aarch64 linkers aggressively relax GD TLS to TLSDESC, making it impossible to produce DTPMOD64 relocations on aarch64 with standard toolchains. Captured via gdb attach + breakpoint on rb_vm_exec to ensure a clean snapshot deep in the Ruby VM stack.
- Convert relocation type checks from chained || expressions to switch statements in both ruby.go Loader() and pfelf VisitTLSRelocations() for improved readability. - Include module_id in DTV read failure DEBUG_PRINT for easier debugging.
Address review feedback from fabled: move arch-specific relocation type checks into pfelf as abstract RelocType constants (RelTLSDESC, RelDTPMOD64) with a bitmask-based filter, replacing the function argument in VisitRelocations. This centralizes the arch-to-reloc mapping in classifyReloc() and simplifies callers.
18d5d03 to
cb7528d
Compare
cb7528d to
29d29fd
Compare
Ruby 3.4.7 built from source with ruby-install on Alpine (musl libc), linked with --enable-shared. This exercises the DTV-based TLS access path for ruby_current_ec on musl, where TLSDESC relocations are not used and we fall back to DTPMOD64.
29d29fd to
1a9790f
Compare
Move the architecture dispatch (switch f.Machine) from classifyReloc, which was called on every relocation entry, into VisitRelocations where it runs once to select an arch-specific classifier function. This avoids redundant machine-type checks in the inner loop. Rename checkFunc to filterFunc for clarity. Addresses review feedback from @fabled.
1a9790f to
017dfbc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
superceded by open-telemetry#1226