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

ruby-changes:50120

From: k0kubun <ko1@a...>
Date: Tue, 6 Feb 2018 01:51:16 +0900 (JST)
Subject: [ruby-changes:50120] k0kubun:r62238 (trunk): mjit.c: determine prefix of MJIT header at runtime

k0kubun	2018-02-06 01:51:12 +0900 (Tue, 06 Feb 2018)

  New Revision: 62238

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62238

  Log:
    mjit.c: determine prefix of MJIT header at runtime
    
    so that MJIT can work if Ruby is distributed as prebuilt binary.
    
    Now mjit_init() depends on the internal const TMP_RUBY_PREFIX which is
    only available after ruby_init_loadpath_safe() (L1608) and before
    ruby_init_prelude() (L1681). So the place of mjit_init() is moved.
    
    Makefile.in: Removed static prefix from MJIT_HEADER_ISNTALL_DIR macro.
    And this removes the unused LIBRUBY_LIBDIR macro as well.
    win32/Makefile.sub: ditto.
    
    Patch by: Lars Kanis <lars@g...>
    [Bug #14445]

  Modified files:
    trunk/Makefile.in
    trunk/mjit.c
    trunk/ruby.c
    trunk/win32/Makefile.sub
Index: win32/Makefile.sub
===================================================================
--- win32/Makefile.sub	(revision 62237)
+++ win32/Makefile.sub	(revision 62238)
@@ -285,7 +285,7 @@ LDSHARED_0 = @if exist $(@).manifest $(M https://github.com/ruby/ruby/blob/trunk/win32/Makefile.sub#L285
 LDSHARED_1 = @if exist $(@).manifest $(MANIFESTTOOL) -manifest $(@).manifest -outputresource:$(@);2
 LDSHARED_2 = @if exist $(@).manifest @$(RM) $(@:/=\).manifest
 !endif
-CPPFLAGS = $(DEFS) $(ARCHDEFS) $(CPPFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DLIBRUBY_LIBDIR=\""$(prefix)/lib"\" -DMJIT_HEADER_INSTALL_DIR=\""$(prefix)/include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\"
+CPPFLAGS = $(DEFS) $(ARCHDEFS) $(CPPFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DMJIT_HEADER_INSTALL_DIR=\""include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\"
 MJIT_HEADER_FLAGS = -P
 
 DLDFLAGS = $(LDFLAGS) -dll
Index: Makefile.in
===================================================================
--- Makefile.in	(revision 62237)
+++ Makefile.in	(revision 62238)
@@ -69,7 +69,7 @@ debugflags = @debugflags@ https://github.com/ruby/ruby/blob/trunk/Makefile.in#L69
 warnflags = @warnflags@ @strict_warnflags@
 cppflags = @cppflags@
 XCFLAGS = @XCFLAGS@
-CPPFLAGS = @CPPFLAGS@ $(INCFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DLIBRUBY_LIBDIR=\""$(prefix)/lib"\" -DMJIT_HEADER_INSTALL_DIR=\""$(prefix)/include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\"
+CPPFLAGS = @CPPFLAGS@ $(INCFLAGS) -DMJIT_HEADER_BUILD_DIR=\""$(EXTOUT)/include/$(arch)"\" -DLIBRUBYARG_SHARED=\""$(LIBRUBYARG_SHARED)"\" -DMJIT_HEADER_INSTALL_DIR=\""include/$(RUBY_BASE_NAME)-$(ruby_version)/$(arch)"\"
 MJIT_HEADER_FLAGS = @MJIT_HEADER_FLAGS@
 LDFLAGS = @STATIC@ $(CFLAGS) @LDFLAGS@
 EXTLDFLAGS = @EXTLDFLAGS@
Index: mjit.c
===================================================================
--- mjit.c	(revision 62237)
+++ mjit.c	(revision 62238)
@@ -202,6 +202,13 @@ static VALUE valid_class_serials; https://github.com/ruby/ruby/blob/trunk/mjit.c#L202
 /* Ruby level interface module.  */
 VALUE rb_mMJIT;
 
+#ifdef _WIN32
+/* Linker option to enable libruby in the build directory. */
+static char *libruby_build;
+/* Linker option to enable libruby in the directory after install. */
+static char *libruby_installed;
+#endif
+
 /* Return time in milliseconds as a double.  */
 static double
 real_ms_time(void)
@@ -629,10 +636,12 @@ compile_c_to_so(const char *c_file, cons https://github.com/ruby/ruby/blob/trunk/mjit.c#L636
     int exit_code;
     static const char *input[] = {NULL, NULL};
     static const char *output[] = {"-o",  NULL, NULL};
-    static const char *libs[] = {
+    const char *libs[] = {
 #ifdef _WIN32
+        /* Look for ruby.dll.a in build and install directories. */
+        libruby_installed,
+        libruby_build,
         /* Link to ruby.dll.a, because Windows DLLs don't allow unresolved symbols. */
-        "-L" LIBRUBY_LIBDIR,
         LIBRUBYARG_SHARED,
         "-lmsvcrt",
 # ifdef __GNUC__
@@ -1051,6 +1060,12 @@ static void https://github.com/ruby/ruby/blob/trunk/mjit.c#L1060
 init_header_filename(void)
 {
     FILE *f;
+    /* Root path of the running ruby process. Equal to RbConfig::TOPDIR.  */
+    VALUE basedir_val;
+    char *basedir;
+
+    basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
+    basedir = StringValueCStr(basedir_val);
 
     header_file = xmalloc(strlen(MJIT_HEADER_BUILD_DIR) + 2 + strlen(RUBY_MJIT_HEADER_FILE));
     if (header_file == NULL)
@@ -1061,10 +1076,12 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1076
 
     if ((f = fopen(header_file, "r")) == NULL) {
         xfree(header_file);
-        header_file = xmalloc(strlen(MJIT_HEADER_INSTALL_DIR) + 2 + strlen(RUBY_MJIT_HEADER_FILE));
+        header_file = xmalloc(strlen(basedir) + 1 + strlen(MJIT_HEADER_INSTALL_DIR) + 1 + strlen(RUBY_MJIT_HEADER_FILE) + 1);
         if (header_file == NULL)
             return;
-        strcpy(header_file, MJIT_HEADER_INSTALL_DIR);
+        strcpy(header_file, basedir);
+        strcat(header_file, "/");
+        strcat(header_file, MJIT_HEADER_INSTALL_DIR);
         strcat(header_file, "/");
         strcat(header_file, RUBY_MJIT_HEADER_FILE);
         if ((f = fopen(header_file, "r")) == NULL) {
@@ -1074,6 +1091,16 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1091
         }
     }
     fclose(f);
+
+#ifdef _WIN32
+    libruby_build = xmalloc(2 + strlen(basedir) + 1);
+    strcpy(libruby_build, "-L");
+    strcat(libruby_build, basedir);
+    libruby_installed = xmalloc(2 + strlen(basedir) + 4 + 1);
+    strcpy(libruby_installed, "-L");
+    strcat(libruby_installed, basedir);
+    strcat(libruby_installed, "/lib");
+#endif
 }
 
 /* This is called after each fork in the child in to switch off MJIT
Index: ruby.c
===================================================================
--- ruby.c	(revision 62237)
+++ ruby.c	(revision 62238)
@@ -1551,9 +1551,6 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1551
 	    opt->intern.enc.name = int_enc_name;
     }
 
-    if (opt->mjit.on)
-        mjit_init(&opt->mjit);
-
     if (opt->src.enc.name)
 	rb_warning("-K is specified; it is for 1.8 compatibility and may cause odd behavior");
 
@@ -1609,6 +1606,11 @@ process_options(int argc, char **argv, r https://github.com/ruby/ruby/blob/trunk/ruby.c#L1606
 
     ruby_gc_set_params(opt->safe_level);
     ruby_init_loadpath_safe(opt->safe_level);
+
+    if (opt->mjit.on)
+        /* Using TMP_RUBY_PREFIX created by ruby_init_loadpath_safe(). */
+        mjit_init(&opt->mjit);
+
     Init_enc();
     lenc = rb_locale_encoding();
     rb_enc_associate(rb_progname, lenc);

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

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