aboutsummaryrefslogtreecommitdiffstats
path: root/mjit_worker.c
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2020-05-03 16:15:45 -0700
committerTakashi Kokubun <takashikkbn@gmail.com>2020-05-03 16:41:25 -0700
commit9aa5fe1bf89db8cd215b24d8ddfb668714681b83 (patch)
treead09a67e5ef72749c5920020df3f47d536a0c025 /mjit_worker.c
parent077619848623e9c7f8d6d8041596199115b7fc68 (diff)
downloadruby-9aa5fe1bf89db8cd215b24d8ddfb668714681b83.tar.gz
Split compile and link for MinGW support
MinGW test_jit fails with no error message. Perhaps linker flags should not be passed when compilation is happening. Anyway splitting these stages doesn't matter for performance. So let me just split it to fix the issue. Probably this helps Solaris's issue too.
Diffstat (limited to 'mjit_worker.c')
-rw-r--r--mjit_worker.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/mjit_worker.c b/mjit_worker.c
index 145ad54383..49903f2cd4 100644
--- a/mjit_worker.c
+++ b/mjit_worker.c
@@ -855,30 +855,45 @@ make_pch(void)
}
// 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.
static bool
compile_c_to_so(const char *c_file, const char *so_file)
{
- const char *options[] = {
- "-o", so_file, c_file,
+ char* o_file = alloca(strlen(c_file) + 1);
+ strcpy(o_file, c_file);
+ o_file[strlen(c_file) - 1] = 'o';
+
+ const char *o_args[] = {
+ "-o", o_file, c_file,
# ifdef __clang__
"-include-pch", pch_file,
# endif
+ "-c", NULL
+ };
+ char **args = form_args(5, cc_common_args, CC_CODEFLAG_ARGS, cc_added_args, o_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 .o: %d", exit_code);
+ return false;
+ }
+
+ const char *so_args[] = {
+ "-o", so_file,
# ifdef _WIN32
libruby_pathflag,
# endif
- NULL
+ o_file, NULL
};
-
- char **args = form_args(7, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, cc_added_args,
- options, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS);
- if (args == NULL)
- return false;
-
- int exit_code = exec_process(cc_path, args);
+ args = form_args(6, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, so_args, CC_LIBS, CC_DLDFLAGS_ARGS, CC_LINKER_ARGS);
+ if (args == NULL) return false;
+ exit_code = exec_process(cc_path, args);
free(args);
-
- if (exit_code != 0)
- verbose(2, "compile_c_to_so: compile error: %d", exit_code);
+ if (!mjit_opts.save_temps) remove_file(o_file);
+ if (exit_code != 0) {
+ verbose(2, "compile_c_to_so: failed to link .o to .so: %d", exit_code);
+ }
return exit_code == 0;
}