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

ruby-changes:72102

From: Takashi <ko1@a...>
Date: Thu, 9 Jun 2022 02:49:19 +0900 (JST)
Subject: [ruby-changes:72102] da883af42a (master): MJIT: Directly compile .c to .so (#5987)

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

From da883af42a2569cf449a7115148c41f05cd856a8 Mon Sep 17 00:00:00 2001
From: Takashi Kokubun <takashikkbn@g...>
Date: Wed, 8 Jun 2022 10:49:00 -0700
Subject: MJIT: Directly compile .c to .so (#5987)

I'm planning to redesign the MJIT worker pipeline, and this allows you to simplify the implementation and let it run efficiently except for MinGW.
---
 mjit_worker.c | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/mjit_worker.c b/mjit_worker.c
index 6261ddc317..3f482db006 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -297,7 +297,7 @@ static const char *const CC_COMMON_ARGS[] = { https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L297
 static const char *const CC_DEBUG_ARGS[] = {MJIT_DEBUGFLAGS NULL};
 static const char *const CC_OPTIMIZE_ARGS[] = {MJIT_OPTFLAGS NULL};
 
-static const char *const CC_LDSHARED_ARGS[] = {MJIT_LDSHARED GCC_PIC_FLAGS NULL};
+static const char *const CC_LDSHARED_ARGS[] = {MJIT_LDSHARED MJIT_CFLAGS GCC_PIC_FLAGS NULL};
 static const char *const CC_DLDFLAGS_ARGS[] = {MJIT_DLDFLAGS NULL};
 // `CC_LINKER_ARGS` are linker flags which must be passed to `-c` as well.
 static const char *const CC_LINKER_ARGS[] = {
@@ -907,8 +907,8 @@ make_pch(void) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L907
 }
 
 // Compile .c file to .so file. It returns true if it succeeds. (non-mswin)
-// Not compiling .c to .so directly because it fails on MinGW, and this helps
-// to generate no .dSYM on macOS.
+// MinGW compiles it in two steps because otherwise it fails without any error output.
+# ifdef _WIN32 // MinGW
 static bool
 compile_c_to_so(const char *c_file, const char *so_file)
 {
@@ -949,6 +949,31 @@ compile_c_to_so(const char *c_file, const char *so_file) https://github.com/ruby/ruby/blob/trunk/mjit_worker.c#L949
     }
     return exit_code == 0;
 }
+# else // _WIN32
+static bool
+compile_c_to_so(const char *c_file, const char *so_file)
+{
+    const char *so_args[] = {
+        "-o", so_file,
+# ifdef _WIN32
+        libruby_pathflag,
+# endif
+# ifdef __clang__
+        "-include-pch", pch_file,
+# 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 (args == NULL) return false;
+    int exit_code = exec_process(cc_path, args);
+    free(args);
+    if (exit_code != 0) {
+        verbose(2, "compile_c_to_so: failed to compile .c to .so: %d", exit_code);
+    }
+    return exit_code == 0;
+}
+# endif // _WIN32
 #endif // _MSC_VER
 
 #if USE_JIT_COMPACTION
-- 
cgit v1.2.1


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

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