diff options
author | Takashi Kokubun <takashikkbn@gmail.com> | 2022-06-08 10:49:00 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-08 10:49:00 -0700 |
commit | da883af42a2569cf449a7115148c41f05cd856a8 (patch) | |
tree | 3caff535c6efd90aeb97a51f52ec04c5810b4fd7 /mjit_worker.c | |
parent | 5a4f997b2e8e819ed40731cd769826112072a9d4 (diff) | |
download | ruby-da883af42a2569cf449a7115148c41f05cd856a8.tar.gz |
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.
Diffstat (limited to 'mjit_worker.c')
-rw-r--r-- | mjit_worker.c | 31 |
1 files 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[] = { 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) } // 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) } 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 |