Skip to content

Commit

Permalink
Fix possible segfault in combination with fiddle or other libffi usin…
Browse files Browse the repository at this point in the history
…g gems

Fiddle can crash when used together with ffi and it's builtin libffi.
This happens because fiddle is linked to system libffi, but ffi is linked to builtin libffi.
Depending on which of these gems is loaded first, they link to the wrong runtime library.

This issue is similar to the issue in nokogiri: sparklemotion/nokogiri#1959

Fixes ffi#835
  • Loading branch information
larskanis committed Dec 18, 2020
1 parent e3f2cf9 commit 3aa6b25
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/ffi_c/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def system_libffi_usable?
else
$defs << "-DHAVE_FFI_PREP_CIF_VAR"
$defs << "-DUSE_INTERNAL_LIBFFI"

# Ensure libffi symbols aren't exported when using static libffi.
# This is to avoid interference with other gems like fiddle.
# See https://github.com/ffi/ffi/issues/835
append_ldflags "-Wl,--exclude-libs,ALL"
end

ffi_alloc_default = RbConfig::CONFIG['host_os'] =~ /darwin/i && RbConfig::CONFIG['host'] =~ /arm/i
Expand Down

0 comments on commit 3aa6b25

Please sign in to comment.