Skip to content

Commit

Permalink
Fix profiler not picking up VM compilation settings correctly
Browse files Browse the repository at this point in the history
See the huge comment for details :)
  • Loading branch information
ivoanjo committed Aug 23, 2024
1 parent fe15909 commit a4c7c18
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions ext/datadog_profiling_native_extension/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,27 @@ def skip_building_extension!(reason)
require "debase/ruby_core_source"
dir_config("ruby") # allow user to pass in non-standard core include directory

# This is a workaround for a weird issue...
#
# The mkmf tool defines a `with_cppflags` helper that debase-ruby_core_source uses. This helper temporarily
# replaces `$CPPFLAGS` (aka the C pre-processor [not c++!] flags) with a different set when doing something.
#
# The debase-ruby_core_source gem uses `with_cppflags` during makefile generation to inject extra headers into the
# path. But because `with_cppflags` replaces `$CPPFLAGS`, well, the default `$CPPFLAGS` are not included in the
# makefile.
#
# This is a problem because the default `$CPPFLAGS` carries configuration that was set when Ruby was being built.
# Thus, if we ignore it, we don't compile the profiler with the exact same configuration as Ruby.
# In practice, this can generate crashes and weird bugs if the Ruby configuration is tweaked in a manner that
# changes some of the internal structures that the profiler relies on. Concretely, setting for instance
# `VM_CHECK_MODE=1` when building Ruby will trigger this issue (because somethings in structures the profiler reads
# are ifdef'd out using this setting).
#
# To workaround this issue, we override `with_cppflags` for debase-ruby_core_source to still include `$CPPFLAGS`.
Debase::RubyCoreSource.define_singleton_method(:with_cppflags) do |newflags, &block|
super("#{newflags} #{$CPPFLAGS}", &block)
end

Debase::RubyCoreSource
.create_makefile_with_core(
proc do
Expand Down

0 comments on commit a4c7c18

Please sign in to comment.