Skip to content

Commit 7370311

Browse files
committed
[GR-29448] Do not link against libtruffleruby for C extensions
* So a built C extension can be reused from multiple builds if they have the same ABI. * Ideally we would still link to libtruffleruby without a -rpath, but that needs support in Sulong to specify a libraryPath from Ruby when loading a C extension.
1 parent f18b9df commit 7370311

File tree

3 files changed

+9
-33
lines changed

3 files changed

+9
-33
lines changed

lib/mri/mkmf.rb

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2302,25 +2302,6 @@ def depend_rules(depend)
23022302
# +VPATH+ and added to the list of +INCFLAGS+.
23032303
#
23042304
def create_makefile(target, srcprefix = nil)
2305-
if defined?(::TruffleRuby) and Truffle::Boot.get_option('building-core-cexts') and target != 'libtruffleruby'
2306-
# Replace the -rpath argument in $LIBRUBYARG with a relative path to libtruffleruby for core C exts
2307-
# Relative path from lib/mri/$TARGET to lib/cext/libtruffleruby.so
2308-
nesting = target.count('/')
2309-
target_dir_to_libtruffleruby_dir = "#{'../' * nesting}../cext"
2310-
if Truffle::Platform.darwin?
2311-
origin_token = '@loader_path'
2312-
else
2313-
origin_token = '$$ORIGIN' # $$ so the Makefile does not expand it
2314-
end
2315-
2316-
librubyarg = $LIBRUBYARG.split(' ')
2317-
rpath_index = librubyarg.index('-rpath')
2318-
raise 'Could not find -rpath in $LIBRUBYARG' unless rpath_index
2319-
# Extra quotes so the shell does not try to interpret $ORIGIN
2320-
librubyarg[rpath_index + 1] = "'#{origin_token}/#{target_dir_to_libtruffleruby_dir}'"
2321-
$LIBRUBYARG = librubyarg.join(' ')
2322-
end
2323-
23242305
$target = target
23252306
libpath = $DEFLIBPATH|$LIBPATH
23262307
message "creating Makefile\n"
@@ -2839,6 +2820,12 @@ def MAIN_DOES_NOTHING(*refs)
28392820
"$(CC) #{OUTFLAG}#{CONFTEST}#{$EXEEXT} $(INCFLAGS) $(CPPFLAGS) " \
28402821
"$(CFLAGS) $(src) $(LIBPATH) $(LDFLAGS) $(ARCH_FLAG) $(LOCAL_LIBS) $(LIBS)"
28412822

2823+
if defined?(::TruffleRuby)
2824+
# We need to link to libtruffleruby for MakeMakefile#try_link to succeed
2825+
libtruffleruby_dir = File.dirname(RbConfig::CONFIG['libtruffleruby'])
2826+
TRY_LINK << " -L#{libtruffleruby_dir} -ltruffleruby"
2827+
end
2828+
28422829
##
28432830
# Command which will link a shared library
28442831

lib/truffle/rbconfig.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,8 @@ module RbConfig
126126
dldflags << rpath_libcxx
127127
end
128128

129-
# Link to libtruffleruby by absolute path
130-
libtruffleruby_dir = File.dirname(libtruffleruby)
131-
librubyarg = "-L#{libtruffleruby_dir} -rpath #{libtruffleruby_dir} -ltruffleruby -lgraalvm-llvm"
129+
# We do not link to libtruffleruby here to workaround GR-29448
130+
librubyarg = '-lgraalvm-llvm'
132131

133132
warnflags = warnflags.join(' ')
134133

@@ -173,6 +172,7 @@ module RbConfig
173172
'LIBRUBYARG_STATIC' => '',
174173
'LIBRUBY_SO' => "cext/libtruffleruby.#{Truffle::Platform::SOEXT}",
175174
'LIBS' => libs,
175+
'libtruffleruby' => libtruffleruby,
176176
'NULLCMD' => ':',
177177
'OBJEXT' => 'o',
178178
'optflags' => optflags,

src/main/c/cext/extconf.rb

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,4 @@ module Truffle::Platform
2323
# -DRUBY_EXPORT is added in MRI's configure.in.
2424
$CFLAGS << " -DRUBY_EXPORT"
2525

26-
# Do no link against libtruffleruby for libtruffleruby itself.
27-
# We still need libtruffleruby to link against libgraalvm-llvm,
28-
# otherwise linking fails with "Undefined symbols" on macOS.
29-
if Truffle::Platform.darwin?
30-
# Set the install_name of libtruffleruby on macOS, so C exts linking to it
31-
# will know they need to look at the rpath to find it.
32-
$LIBRUBYARG = "-Wl,-install_name,@rpath/libtruffleruby.dylib -lgraalvm-llvm"
33-
else
34-
$LIBRUBYARG = "-lgraalvm-llvm"
35-
end
36-
3726
create_makefile('libtruffleruby')

0 commit comments

Comments
 (0)