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

ruby-changes:72813

From: Yuta <ko1@a...>
Date: Thu, 4 Aug 2022 16:29:41 +0900 (JST)
Subject: [ruby-changes:72813] 00f411c58a (master): Add `-bundle_loader` to mjit compilation args on macOS

https://git.ruby-lang.org/ruby.git/commit/?id=00f411c58a

From 00f411c58ac6105f135ff4501ea5bd1d691fcc32 Mon Sep 17 00:00:00 2001
From: Yuta Saito <kateinoigakukun@g...>
Date: Sat, 30 Jul 2022 20:26:57 +0900
Subject: Add `-bundle_loader` to mjit compilation args on macOS

---
 mjit.c | 12 ++++++++++--
 ruby.c | 18 +++++++++++++++---
 2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/mjit.c b/mjit.c
index 01ad7339f0..98f4af3d18 100644
--- a/mjit.c
+++ b/mjit.c
@@ -811,8 +811,16 @@ start_compiling_c_to_so(const char *c_file, const char *so_file) https://github.com/ruby/ruby/blob/trunk/mjit.c#L811
 # endif
         c_file, NULL
     };
-    char **args = form_args(7, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, cc_added_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
+
+    char **args = form_args(8, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, cc_added_args,
+                            so_args, loader_args, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS);
     if (args == NULL) return -1;
 
     rb_vm_t *vm = GET_VM();
diff --git a/ruby.c b/ruby.c
index 46fb019701..9b9bfb54c7 100644
--- a/ruby.c
+++ b/ruby.c
@@ -22,7 +22,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby.c#L22
 # include <sys/cygwin.h>
 #endif
 
-#if defined(LOAD_RELATIVE) && defined(HAVE_DLADDR)
+#if (defined(LOAD_RELATIVE) || defined(__MACH__)) && defined(HAVE_DLADDR)
 # include <dlfcn.h>
 #endif
 
@@ -534,7 +534,7 @@ str_conv_enc(VALUE str, rb_encoding *from, rb_encoding *to) https://github.com/ruby/ruby/blob/trunk/ruby.c#L534
 
 void ruby_init_loadpath(void);
 
-#if defined(LOAD_RELATIVE)
+#if defined(LOAD_RELATIVE) || defined(__MACH__)
 static VALUE
 runtime_libruby_path(void)
 {
@@ -615,6 +615,10 @@ runtime_libruby_path(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L615
 #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)
@@ -622,6 +626,14 @@ ruby_init_loadpath(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L626
     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 ""
@@ -635,7 +647,7 @@ ruby_init_loadpath(void) https://github.com/ruby/ruby/blob/trunk/ruby.c#L647
     size_t baselen;
     const char *p;
 
-    sopath = runtime_libruby_path();
+    sopath = libruby_path;
     libpath = RSTRING_PTR(sopath);
 
     p = strrchr(libpath, '/');
-- 
cgit v1.2.1


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

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