[前][次][番号順一覧][スレッド一覧]

ruby-changes:73577

From: Hiroshi <ko1@a...>
Date: Fri, 16 Sep 2022 15:12:59 +0900 (JST)
Subject: [ruby-changes:73577] 7900a9bd38 (ruby_3_0): Backport https://github.com/ruby/ruby/pull/6193

https://git.ruby-lang.org/ruby.git/commit/?id=7900a9bd38

From 7900a9bd388cff65ba98e4fa09b296eb1f4f815e Mon Sep 17 00:00:00 2001
From: Hiroshi SHIBATA <hsbt@r...>
Date: Mon, 29 Aug 2022 17:42:49 +0900
Subject: Backport https://github.com/ruby/ruby/pull/6193

Co-authored-by: Yuta Saito <kateinoigakukun@g...>
---
 configure.ac    |  8 ++++++++
 enc/Makefile.in |  2 ++
 ext/extmk.rb    |  5 ++++-
 lib/mkmf.rb     |  5 +++++
 mjit_worker.c   |  8 +++++++-
 ruby.c          | 18 +++++++++++++++---
 tool/fake.rb    |  1 +
 7 files changed, 42 insertions(+), 5 deletions(-)

diff --git a/configure.ac b/configure.ac
index 49e0c79a4c..eb07c11c57 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2840,6 +2840,14 @@ AS_IF([test "$with_dln_a_out" != yes], [ https://github.com/ruby/ruby/blob/trunk/configure.ac#L2840
 			: ${LDFLAGS=""}
 			: ${LIBPATHENV=DYLD_FALLBACK_LIBRARY_PATH}
 			: ${PRELOADENV=DYLD_INSERT_LIBRARIES}
+                        AS_IF([test x"$enable_shared" = xyes], [
+                            # Resolve symbols from libruby.dylib when --enable-shared
+                            EXTDLDFLAGS='$(LIBRUBYARG_SHARED)'
+                        ], [test "x$EXTSTATIC" = x], [
+                            # When building exts as bundles, a mach-o bundle needs to know its loader
+                            # program to bind symbols from the ruby executable
+                            EXTDLDFLAGS="-bundle_loader '\$(BUILTRUBY)'"
+			])
 			rb_cv_dlopen=yes],
         [aix*], [	: ${LDSHARED='$(CC)'}
 			AS_IF([test "$GCC" = yes], [
diff --git a/enc/Makefile.in b/enc/Makefile.in
index 9203874386..3854f66de6 100644
--- a/enc/Makefile.in
+++ b/enc/Makefile.in
@@ -21,6 +21,7 @@ TRANSSODIR = $(ENCSODIR)/trans https://github.com/ruby/ruby/blob/trunk/enc/Makefile.in#L21
 DLEXT = @DLEXT@
 OBJEXT = @OBJEXT@
 LIBEXT = @LIBEXT@
+EXEEXT = @EXEEXT@
 TIMESTAMPDIR  = $(EXTOUT)/.timestamp
 ENC_TRANS_D   = $(TIMESTAMPDIR)/.enc-trans.time
 ENC_TRANS_SO_D = $(TIMESTAMPDIR)/.enc-trans.so.time
@@ -34,6 +35,7 @@ RUBY_SO_NAME = @RUBY_SO_NAME@ https://github.com/ruby/ruby/blob/trunk/enc/Makefile.in#L35
 LIBRUBY = @LIBRUBY@
 LIBRUBYARG_SHARED = @LIBRUBYARG_SHARED@
 LIBRUBYARG_STATIC = $(LIBRUBYARG_SHARED)
+BUILTRUBY = $(topdir)/miniruby$(EXEEXT)
 
 empty =
 AR = @AR@
diff --git a/ext/extmk.rb b/ext/extmk.rb
index 80a0a1208d..97f1ad9c39 100755
--- a/ext/extmk.rb
+++ b/ext/extmk.rb
@@ -408,8 +408,10 @@ if CROSS_COMPILING https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L408
   $ruby = $mflags.defined?("MINIRUBY") || CONFIG['MINIRUBY']
 elsif sep = config_string('BUILD_FILE_SEPARATOR')
   $ruby = "$(topdir:/=#{sep})#{sep}miniruby" + EXEEXT
-else
+elsif CONFIG['EXTSTATIC']
   $ruby = '$(topdir)/miniruby' + EXEEXT
+else
+  $ruby = '$(topdir)/ruby' + EXEEXT
 end
 $ruby = [$ruby]
 $ruby << "-I'$(topdir)'"
@@ -421,6 +423,7 @@ end https://github.com/ruby/ruby/blob/trunk/ext/extmk.rb#L423
 topruby = $ruby
 $ruby = topruby.join(' ')
 $mflags << "ruby=#$ruby"
+$builtruby = '$(topdir)/miniruby' + EXEEXT # Must be an executable path
 
 MTIMES = [__FILE__, 'rbconfig.rb', srcdir+'/lib/mkmf.rb'].collect {|f| File.mtime(f)}
 
diff --git a/lib/mkmf.rb b/lib/mkmf.rb
index 9468a2c6c4..9435404584 100644
--- a/lib/mkmf.rb
+++ b/lib/mkmf.rb
@@ -2034,6 +2034,11 @@ sitearch = #{CONFIG['sitearch']} https://github.com/ruby/ruby/blob/trunk/lib/mkmf.rb#L2034
 ruby_version = #{RbConfig::CONFIG['ruby_version']}
 ruby = #{$ruby.sub(%r[\A#{Regexp.quote(RbConfig::CONFIG['bindir'])}(?=/|\z)]) {'$(bindir)'}}
 RUBY = $(ruby#{sep})
+BUILTRUBY = #{if defined?($builtruby) && $builtruby
+    $builtruby
+  else
+    File.join('$(bindir)', CONFIG["RUBY_INSTALL_NAME"] + CONFIG['EXEEXT'])
+  end}
 ruby_headers = #{headers.join(' ')}
 
 RM = #{config_string('RM', &possible_command) || '$(RUBY) -run -e rm -- -f'}
diff --git a/mjit_worker.c b/mjit_worker.c
index d3e333da31..f7f0b6bced 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -937,7 +937,13 @@ compile_c_to_so(const char *c_file, const char *so_file) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L937
 # endif
         o_file, NULL
     };
-    args = form_args(6, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, so_args, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS);
+# if defined(__MACH__)
+    extern VALUE rb_libruby_selfpath;
+    const char *loader_args[] = {"-bundle_loader", StringValuePtr(rb_libruby_selfpath), NULL};
+# else
+    const char *loader_args[] = {NULL};
+# endif
+    args = form_args(7, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, so_args, loader_args, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS);
     if (args == NULL) return false;
     exit_code = exec_process(cc_path, args);
     free(args);
diff --git a/ruby.c b/ruby.c
index 2251fde4e2..f502157e97 100644
--- a/ruby.c
+++ b/ruby.c
@@ -26,7 +26,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby.c#L26
 # include <sys/pstat.h>
 #endif
 
-#if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR)
+#if (defined(LOAD_RELATIVE) || defined(__MACH__)) && defined(HAVE_DLADDR)
 # include <dlfcn.h>
 #endif
 
@@ -531,7 +531,7 @@ str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to) https://github.com/ruby/ruby/blob/trunk/ruby.c#L531
 
 void ruby_init_loadpath(void);
 
-#if defined(LOAD_RELATIVE)
+#if defined(LOAD_RELATIVE) || defined(__MACH__)
 static VALUE
 runtime_libruby_path(void)
 {
@@ -607,6 +607,10 @@ runtime_libruby_path(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L607
 #define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index")
 
 VALUE ruby_archlibdir_path, ruby_prefix_path;
+#if defined(__MACH__)
+// A path to libruby.dylib itself or where it's statically linked to.
+VALUE rb_libruby_selfpath;
+#endif
 
 void
 ruby_init_loadpath(void)
@@ -614,6 +618,14 @@ ruby_init_loadpath(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L618
     VALUE load_path, archlibdir = 0;
     ID id_initial_load_path_mark;
     const char *paths = ruby_initial_load_paths;
+#if defined(LOAD_RELATIVE) || defined(__MACH__)
+    VALUE libruby_path = runtime_libruby_path();
+# if defined(__MACH__)
+    rb_libruby_selfpath = libruby_path;
+    rb_gc_register_address(&rb_libruby_selfpath);
+# endif
+#endif
+
 #if defined LOAD_RELATIVE
 #if !defined ENABLE_MULTIARCH
 # define RUBY_ARCH_PATH ""
@@ -627,7 +639,7 @@ ruby_init_loadpath(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L639
     size_t baselen;
     const char *p;
 
-    sopath = runtime_libruby_path();
+    sopath = libruby_path;
     libpath = RSTRING_PTR(sopath);
 
     p = strrchr(libpath, '/');
diff --git a/tool/fake.rb b/tool/fake.rb
index 42174052e2..4946fd6234 100644
--- a/tool/fake.rb
+++ b/tool/fake.rb
@@ -43,6 +43,7 @@ prehook = proc do |extmk| https://github.com/ruby/ruby/blob/trunk/tool/fake.rb#L43
   $extout_prefix = '$(extout)$(target_prefix)/'
   config = RbConfig::CONFIG
   mkconfig = RbConfig::MAKEFILE_CONFIG
+  $builtruby ||= File.join(builddir, config['RUBY_INSTALL_NAME'] + config['EXEEXT'])
   RbConfig.fire_update!("builddir", builddir)
   RbConfig.fire_update!("buildlibdir", builddir)
   RbConfig.fire_update!("libdir", builddir)
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]