[SCP-184] Fix incompatible library check when there's no libruby.so #2250
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.
What does this PR do?:
Add a missing check for a
NULL
result ofdlsym
that happens when Ruby is not built withlibruby.so
.Motivation:
The logic in
ddtrace_profiling_loader.c
follows Ruby'sdln.c
; see the big comment at the top of the former for why it needs to exist.The
incompatible_library
sanity check exists to try to catch situations where the library being loaded is linked to a differentlibruby.so
(or equivalent in other OSs) than the one that is doing the loading.BUT when we implemented
incompatible_library
we missed an check that upstream Ruby does.From https://github.com/ruby/ruby/blob/v3_1_2/dln.c#L295:
Ruby actually checks that the symbol found is not NULL (e.g. with the
ex &&
check). This is important, because there's a valid situation in which the symbol is expected to be NULL: when Ruby is built with--disable-shared
at compilation time.What
--disable-shared
does is that it builds the Ruby VM logic inside theruby
executable itself INSTEAD OF splitting the logic between theruby
executable and thelibruby.so
shared library.To properly support this configuration, we should, like upstream Ruby does, consider a library compatible if the symbol lookup returns
NULL
.Additional Notes:
Here's a few ways of telling if there's a
libruby
:RbConfig::CONFIG['configure_args']
will contain--disable-shared
RbConfig::CONFIG['LIBRUBY']
will belibruby-static.a
instead of, for instancelibruby.so.3.1.1
How to test the change?:
I couldn't find a prebuilt docker image that had Ruby compiled with
--disable-shared
.To reproduce the issue, I downloaded the latest Ruby version, configured it with
./configure --disable-shared
, compiled and installed it, and then installeddd-trace-rb
, and tried to start the profiler.Without this fix, profiling did not work, I would get:
With the fix, the profiler starts up successfully.