mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
mjit_config.h
* Makefie.in, win32/Makefile.sub: make mjit_config.h from configured variables, including necessary options, e.g., `-m32` for 32bit binary on 64bit platform. * mjit.c: always use configured CC command. as config.h depends on the compiler, different compilers cannot work. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62343 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
61f26a1bf9
commit
f6ca5edf3e
4 changed files with 99 additions and 63 deletions
11
Makefile.in
11
Makefile.in
|
@ -534,3 +534,14 @@ loadpath: verconf.h
|
||||||
un-runnable:
|
un-runnable:
|
||||||
$(ECHO) cannot make runnable, configure with --enable-load-relative.
|
$(ECHO) cannot make runnable, configure with --enable-load-relative.
|
||||||
$(Q) exit 1
|
$(Q) exit 1
|
||||||
|
|
||||||
|
mjit_config.h:
|
||||||
|
$(ECHO) making $@
|
||||||
|
@{ \
|
||||||
|
echo '#ifndef RUBY_MJIT_CONFIG_H'; \
|
||||||
|
echo '#define RUBY_MJIT_CONFIG_H 1'; \
|
||||||
|
set x $(CC) && shift && echo '#define MJIT_CC "'$$1'"' \\; \
|
||||||
|
shift && for w do echo ' , "'$$w'"' \\; done; \
|
||||||
|
echo ' /* MJIT_CC */'; \
|
||||||
|
echo '#endif /* RUBY_MJIT_CONFIG_H */'; \
|
||||||
|
} > $@
|
||||||
|
|
|
@ -206,7 +206,10 @@ main: $(SHOWFLAGS) exts $(ENCSTATIC:static=lib)encs $(MJIT_MIN_HEADER)
|
||||||
@$(NULLCMD)
|
@$(NULLCMD)
|
||||||
|
|
||||||
.PHONY: mjit-headers
|
.PHONY: mjit-headers
|
||||||
mjit-headers: $(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time $(MJIT_MIN_HEADER)
|
mjit-headers: $(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time $(MJIT_MIN_HEADER) mjit_config.h
|
||||||
|
|
||||||
|
mjit.$(OBJEXT): mjit_config.h
|
||||||
|
mjit_config.h: Makefile
|
||||||
|
|
||||||
$(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time: probes.h vm.$(OBJEXT)
|
$(TIMESTAMPDIR)/$(MJIT_HEADER:.h=)$(MJIT_HEADER_SUFFIX).time: probes.h vm.$(OBJEXT)
|
||||||
$(ECHO) building $(@F:.time=.h)
|
$(ECHO) building $(@F:.time=.h)
|
||||||
|
|
136
mjit.c
136
mjit.c
|
@ -560,6 +560,11 @@ free_list(struct rb_mjit_unit_list *list)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "mjit_config.h"
|
||||||
|
#ifndef MJIT_CC
|
||||||
|
#define MJIT_CC "cc"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* XXX_COMMONN_ARGS define the command line arguments of XXX C
|
/* XXX_COMMONN_ARGS define the command line arguments of XXX C
|
||||||
compiler used by MJIT.
|
compiler used by MJIT.
|
||||||
|
|
||||||
|
@ -568,37 +573,57 @@ free_list(struct rb_mjit_unit_list *list)
|
||||||
|
|
||||||
XXX_USE_PCH_ARAGS define additional options to use the precomiled
|
XXX_USE_PCH_ARAGS define additional options to use the precomiled
|
||||||
header. */
|
header. */
|
||||||
static const char *GCC_COMMON_ARGS_DEBUG[] = {"gcc", "-O0", "-g", "-Wfatal-errors", "-fPIC", "-shared", "-w", "-pipe", "-nostartfiles", "-nodefaultlibs", "-nostdlib", NULL};
|
static const char *GCC_DEBUG_ARGS[] = {"-O0", "-g", NULL};
|
||||||
static const char *GCC_COMMON_ARGS[] = {"gcc", "-O2", "-Wfatal-errors", "-fPIC", "-shared", "-w", "-pipe", "-nostartfiles", "-nodefaultlibs", "-nostdlib", NULL};
|
static const char *GCC_OPTIMIZE_ARGS[] = {"-O2", NULL};
|
||||||
static const char *GCC_USE_PCH_ARGS[] = {"-I/tmp", NULL};
|
|
||||||
static const char *GCC_EMIT_PCH_ARGS[] = {NULL};
|
|
||||||
|
|
||||||
#ifdef __MACH__
|
|
||||||
|
|
||||||
static const char *CLANG_COMMON_ARGS_DEBUG[] = {"clang", "-O0", "-g", "-dynamic", "-I/usr/local/include", "-L/usr/local/lib", "-w", "-bundle", NULL};
|
|
||||||
static const char *CLANG_COMMON_ARGS[] = {"clang", "-O2", "-dynamic", "-I/usr/local/include", "-L/usr/local/lib", "-w", "-bundle", NULL};
|
|
||||||
|
|
||||||
|
static const char *GCC_COMMON_ARGS[] = {
|
||||||
|
MJIT_CC,
|
||||||
|
#ifdef __clang__
|
||||||
|
# ifdef __MACH__
|
||||||
|
"-dynamic",
|
||||||
|
# else
|
||||||
|
"-fPIC", "-shared",
|
||||||
|
# endif /* #if __MACH__ */
|
||||||
|
"-w", "-bundle",
|
||||||
#else
|
#else
|
||||||
|
"-Wfatal-errors", "-fPIC", "-shared", "-w",
|
||||||
|
"-pipe", "-nostartfiles", "-nodefaultlibs", "-nostdlib",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
static const char *CLANG_COMMON_ARGS_DEBUG[] = {"clang", "-O0", "-g", "-fPIC", "-shared", "-I/usr/local/include", "-L/usr/local/lib", "-w", "-bundle", NULL};
|
static const char *GCC_LDSHARED_ARGS[] = {
|
||||||
static const char *CLANG_COMMON_ARGS[] = {"clang", "-O2", "-fPIC", "-shared", "-I/usr/local/include", "-L/usr/local/lib", "-w", "-bundle", NULL};
|
"-Wl,-undefined", "-Wl,dynamic_lookup",
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* #if __MACH__ */
|
static const char GCC_USE_PCH_ARGS[] =
|
||||||
|
#ifdef __clang__
|
||||||
|
"-include-pch"
|
||||||
|
#else
|
||||||
|
"-I"
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
|
||||||
|
static const char *GCC_EMIT_PCH_ARGS[] = {
|
||||||
|
#ifdef __clang__
|
||||||
|
"-emit-pch",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
static const char *VC_COMMON_ARGS_DEBUG[] = {"cl.exe", "-nologo", "-O0", "-Zi", "-MD", "-LD", NULL};
|
static const char *VC_COMMON_ARGS[] = {MJIT_CC, "-MD", "-LD", NULL};
|
||||||
static const char *VC_COMMON_ARGS[] = {"cl.exe", "-nologo",
|
static const char *VC_DEBUG_ARGS[] = {"-O0", "-Zi", NULL};
|
||||||
|
static const char *VC_OPTIMIZE_ARGS[] = {
|
||||||
# if _MSC_VER < 1400
|
# if _MSC_VER < 1400
|
||||||
"-O2b2xg-",
|
"-O2b2xg-",
|
||||||
# else
|
# else
|
||||||
"-O2sy-",
|
"-O2sy-",
|
||||||
# endif
|
# endif
|
||||||
"-MD", "-LD", NULL};
|
NULL};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *CLANG_USE_PCH_ARGS[] = {"-include-pch", NULL, "-Wl,-undefined", "-Wl,dynamic_lookup", NULL};
|
|
||||||
static const char *CLANG_EMIT_PCH_ARGS[] = {"-emit-pch", NULL};
|
|
||||||
|
|
||||||
/* Status of the the precompiled header creation. The status is
|
/* Status of the the precompiled header creation. The status is
|
||||||
shared by the workers and the pch thread. */
|
shared by the workers and the pch thread. */
|
||||||
static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status;
|
static enum {PCH_NOT_READY, PCH_FAILED, PCH_SUCCESS} pch_status;
|
||||||
|
@ -612,19 +637,17 @@ make_pch(void)
|
||||||
/* XXX TODO */
|
/* XXX TODO */
|
||||||
exit_code = 0;
|
exit_code = 0;
|
||||||
#else
|
#else
|
||||||
static const char *input[] = {NULL, NULL};
|
const char *last_args[4];
|
||||||
static const char *output[] = {"-o", NULL, NULL};
|
|
||||||
char **args;
|
char **args;
|
||||||
|
|
||||||
verbose(2, "Creating precompiled header");
|
verbose(2, "Creating precompiled header");
|
||||||
input[0] = header_file;
|
last_args[0] = "-o";
|
||||||
output[1] = pch_file;
|
last_args[1] = pch_file;
|
||||||
if (mjit_opts.cc == MJIT_CC_CLANG)
|
last_args[2] = header_file;
|
||||||
args = form_args(4, (mjit_opts.debug ? CLANG_COMMON_ARGS_DEBUG : CLANG_COMMON_ARGS),
|
last_args[3] = NULL;
|
||||||
CLANG_EMIT_PCH_ARGS, input, output);
|
args = form_args(4, GCC_COMMON_ARGS,
|
||||||
else
|
(mjit_opts.debug ? GCC_DEBUG_ARGS : GCC_OPTIMIZE_ARGS),
|
||||||
args = form_args(4, (mjit_opts.debug ? GCC_COMMON_ARGS_DEBUG : GCC_COMMON_ARGS),
|
GCC_EMIT_PCH_ARGS, last_args);
|
||||||
GCC_EMIT_PCH_ARGS, input, output);
|
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
if (mjit_opts.warnings || mjit_opts.verbose)
|
if (mjit_opts.warnings || mjit_opts.verbose)
|
||||||
fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n");
|
fprintf(stderr, "MJIT warning: making precompiled header failed on forming args\n");
|
||||||
|
@ -660,12 +683,14 @@ static int
|
||||||
compile_c_to_so(const char *c_file, const char *so_file)
|
compile_c_to_so(const char *c_file, const char *so_file)
|
||||||
{
|
{
|
||||||
int exit_code;
|
int exit_code;
|
||||||
const char *input[] = {NULL, NULL};
|
const char *files[] = {
|
||||||
const char *output[] = {
|
#ifdef __GNUC__
|
||||||
|
GCC_USE_PCH_ARGS, NULL,
|
||||||
|
#endif
|
||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
"-o",
|
"-o",
|
||||||
#endif
|
#endif
|
||||||
NULL, NULL};
|
NULL, NULL, NULL};
|
||||||
const char *libs[] = {
|
const char *libs[] = {
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
|
@ -690,26 +715,22 @@ compile_c_to_so(const char *c_file, const char *so_file)
|
||||||
int solen;
|
int solen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
input[0] = c_file;
|
files[numberof(files)-2] = c_file;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
solen = strlen(so_file);
|
solen = strlen(so_file);
|
||||||
p = (char *)output[0] = xmalloc(3 + solen + 1);
|
files[0] = p = xmalloc(rb_strlen_lit("-Fe") + solen + 1);
|
||||||
p = append_lit(p, "-Fe");
|
p = append_lit(p, "-Fe");
|
||||||
p = append_str2(p, so_file, solen);
|
p = append_str2(p, so_file, solen);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
args = form_args(4, (mjit_opts.debug ? VC_COMMON_ARGS_DEBUG : VC_COMMON_ARGS),
|
args = form_args(4, VC_COMMON_ARGS,
|
||||||
output, input, libs);
|
(mjit_opts.debug ? VC_DEBUG_ARGS : VC_OPTIMIZE_ARGS),
|
||||||
|
files, libs);
|
||||||
#else
|
#else
|
||||||
output[1] = so_file;
|
files[1] = pch_file;
|
||||||
if (mjit_opts.cc == MJIT_CC_CLANG) {
|
files[numberof(files)-3] = so_file;
|
||||||
CLANG_USE_PCH_ARGS[1] = pch_file;
|
args = form_args(5, GCC_COMMON_ARGS,
|
||||||
args = form_args(5, (mjit_opts.debug ? CLANG_COMMON_ARGS_DEBUG : CLANG_COMMON_ARGS),
|
(mjit_opts.debug ? GCC_DEBUG_ARGS : GCC_OPTIMIZE_ARGS),
|
||||||
CLANG_USE_PCH_ARGS, input, output, libs);
|
GCC_LDSHARED_ARGS, files, libs);
|
||||||
}
|
|
||||||
else {
|
|
||||||
args = form_args(5, (mjit_opts.debug ? GCC_COMMON_ARGS_DEBUG : GCC_COMMON_ARGS),
|
|
||||||
GCC_USE_PCH_ARGS, input, output, libs);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
if (args == NULL)
|
if (args == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -717,7 +738,7 @@ compile_c_to_so(const char *c_file, const char *so_file)
|
||||||
exit_code = exec_process(cc_path, args);
|
exit_code = exec_process(cc_path, args);
|
||||||
xfree(args);
|
xfree(args);
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
xfree((char *)output[0]);
|
xfree((char *)files[0]);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (exit_code != 0)
|
if (exit_code != 0)
|
||||||
|
@ -785,7 +806,8 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -include-pch is used for Clang */
|
/* -include-pch is used for Clang */
|
||||||
if (mjit_opts.cc == MJIT_CC_GCC) {
|
#ifndef __clang__
|
||||||
|
{
|
||||||
const char *s = pch_file;
|
const char *s = pch_file;
|
||||||
const char *e = s + strlen(s);
|
const char *e = s + strlen(s);
|
||||||
static const char suffix[] = ".gch";
|
static const char suffix[] = ".gch";
|
||||||
|
@ -805,6 +827,7 @@ convert_unit_to_func(struct rb_mjit_unit *unit)
|
||||||
}
|
}
|
||||||
fprintf(f, "\"\n");
|
fprintf(f, "\"\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
fprintf(f, "void _pei386_runtime_relocator(void){}\n");
|
fprintf(f, "void _pei386_runtime_relocator(void){}\n");
|
||||||
|
@ -1136,8 +1159,7 @@ mjit_get_iseq_func(const struct rb_iseq_constant_body *body)
|
||||||
#define RUBY_MJIT_HEADER_NAME "rb_mjit_min_header-"
|
#define RUBY_MJIT_HEADER_NAME "rb_mjit_min_header-"
|
||||||
/* GCC and CLANG executable paths. TODO: The paths should absolute
|
/* GCC and CLANG executable paths. TODO: The paths should absolute
|
||||||
ones to prevent changing C compiler for security reasons. */
|
ones to prevent changing C compiler for security reasons. */
|
||||||
#define GCC_PATH "gcc"
|
#define GCC_PATH GCC_COMMON_ARGS[0]
|
||||||
#define CLANG_PATH "clang"
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
# define VC_PATH "cl.exe"
|
# define VC_PATH "cl.exe"
|
||||||
#endif
|
#endif
|
||||||
|
@ -1285,17 +1307,11 @@ mjit_init(struct mjit_options *opts)
|
||||||
if (mjit_opts.max_cache_size < MIN_CACHE_SIZE)
|
if (mjit_opts.max_cache_size < MIN_CACHE_SIZE)
|
||||||
mjit_opts.max_cache_size = MIN_CACHE_SIZE;
|
mjit_opts.max_cache_size = MIN_CACHE_SIZE;
|
||||||
|
|
||||||
if (mjit_opts.cc == MJIT_CC_DEFAULT) {
|
{
|
||||||
#if _MSC_VER
|
#if _MSC_VER
|
||||||
verbose(2, "MJIT: CC defaults to cl");
|
verbose(2, "MJIT: CC defaults to cl");
|
||||||
#else
|
#else
|
||||||
# if defined(__clang__)
|
verbose(2, "MJIT: CC defaults to %s", GCC_PATH);
|
||||||
mjit_opts.cc = MJIT_CC_CLANG;
|
|
||||||
verbose(2, "MJIT: CC defaults to clang");
|
|
||||||
# else
|
|
||||||
mjit_opts.cc = MJIT_CC_GCC;
|
|
||||||
verbose(2, "MJIT: CC defaults to gcc");
|
|
||||||
# endif
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1304,11 +1320,7 @@ mjit_init(struct mjit_options *opts)
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
cc_path = VC_PATH;
|
cc_path = VC_PATH;
|
||||||
#else
|
#else
|
||||||
if (mjit_opts.cc == MJIT_CC_CLANG) {
|
cc_path = GCC_PATH;
|
||||||
cc_path = CLANG_PATH;
|
|
||||||
} else {
|
|
||||||
cc_path = GCC_PATH;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tmp_dir = system_tmpdir();
|
tmp_dir = system_tmpdir();
|
||||||
|
|
|
@ -1234,3 +1234,13 @@ loadpath: verconf.h
|
||||||
@$(CPP) $(XCFLAGS) $(CPPFLAGS) $(srcdir)/loadpath.c | \
|
@$(CPP) $(XCFLAGS) $(CPPFLAGS) $(srcdir)/loadpath.c | \
|
||||||
sed -e '1,/^const char ruby_initial_load_paths/d;/;/,$$d' \
|
sed -e '1,/^const char ruby_initial_load_paths/d;/;/,$$d' \
|
||||||
-e '/^^ /!d;s/ *"\\\\0"$$//;s/" *"//g'
|
-e '/^^ /!d;s/ *"\\\\0"$$//;s/" *"//g'
|
||||||
|
|
||||||
|
mjit_config.h:
|
||||||
|
@$(ECHO) making <<$@
|
||||||
|
#ifndef RUBY_MJIT_CONFIG_H
|
||||||
|
#define RUBY_MJIT_CONFIG_H 1
|
||||||
|
<<KEEP
|
||||||
|
@(set sep=#define MJIT_CC ) & \
|
||||||
|
for %I in ($(CC)) do @(call echo.%%sep%%"%%~I" \& set sep= ,) >> $@
|
||||||
|
$(Q)echo /* MJIT_CC */>> $@
|
||||||
|
$(Q)echo #endif /* RUBY_MJIT_CONFIG_H */ >> $@
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue