mjit.c: prefix and archdir in init
* ruby.c (ruby_init_loadpath_safe): store prefix and archlibdir paths. * mjit.c (compile_c_to_so, init_header_filename): use just one library path on Windows. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63269 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9ce0a84640
commit
67800ea9c7
60
mjit.c
60
mjit.c
@ -208,10 +208,8 @@ static VALUE valid_class_serials;
|
|||||||
VALUE rb_mMJIT;
|
VALUE rb_mMJIT;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Linker option to enable libruby in the build directory. */
|
/* Linker option to enable libruby. */
|
||||||
static char *libruby_build;
|
static char *libruby_pathflag;
|
||||||
/* Linker option to enable libruby in the directory after install. */
|
|
||||||
static char *libruby_installed;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Return time in milliseconds as a double. */
|
/* Return time in milliseconds as a double. */
|
||||||
@ -582,6 +580,15 @@ static const char *const CC_DLDFLAGS_ARGS[] = {
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const char *const CC_LIBS[] = {
|
||||||
|
MJIT_LIBS
|
||||||
|
#if defined __GNUC__ && !defined __clang__ && !defined _WIN32
|
||||||
|
"-lmsvcrt",
|
||||||
|
"-lgcc",
|
||||||
|
#endif
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
#define CC_CODEFLAG_ARGS (mjit_opts.debug ? CC_DEBUG_ARGS : CC_OPTIMIZE_ARGS)
|
#define CC_CODEFLAG_ARGS (mjit_opts.debug ? CC_DEBUG_ARGS : CC_OPTIMIZE_ARGS)
|
||||||
/* Status of the precompiled header creation. The status is
|
/* Status of the precompiled header creation. The status is
|
||||||
shared by the workers and the pch thread. */
|
shared by the workers and the pch thread. */
|
||||||
@ -652,45 +659,37 @@ compile_c_to_so(const char *c_file, const char *so_file)
|
|||||||
#ifndef _MSC_VER
|
#ifndef _MSC_VER
|
||||||
"-o",
|
"-o",
|
||||||
#endif
|
#endif
|
||||||
NULL, NULL, NULL};
|
NULL, NULL,
|
||||||
const char *libs[] = {
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
# ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
MJIT_LIBS
|
|
||||||
"-link",
|
"-link",
|
||||||
libruby_installed,
|
|
||||||
libruby_build,
|
|
||||||
# else
|
|
||||||
/* Look for ruby.dll.a in build and install directories. */
|
|
||||||
libruby_installed,
|
|
||||||
libruby_build,
|
|
||||||
MJIT_LIBS
|
|
||||||
"-lmsvcrt",
|
|
||||||
"-lgcc",
|
|
||||||
# endif
|
# endif
|
||||||
|
libruby_pathflag,
|
||||||
#endif
|
#endif
|
||||||
NULL};
|
NULL,
|
||||||
|
};
|
||||||
char **args;
|
char **args;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
char *p;
|
char *p;
|
||||||
int solen;
|
int solen;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
files[numberof(files)-2] = c_file;
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
solen = strlen(so_file);
|
solen = strlen(so_file);
|
||||||
files[0] = p = xmalloc(rb_strlen_lit("-Fe") + 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';
|
||||||
|
files[1] = c_file;
|
||||||
#else
|
#else
|
||||||
# ifdef __clang__
|
# ifdef __clang__
|
||||||
files[1] = pch_file;
|
files[1] = pch_file;
|
||||||
# endif
|
# endif
|
||||||
files[numberof(files)-3] = so_file;
|
files[numberof(files)-3] = c_file;
|
||||||
|
files[numberof(files)-4] = so_file;
|
||||||
#endif
|
#endif
|
||||||
args = form_args(5, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS,
|
args = form_args(5, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS,
|
||||||
files, libs, CC_DLDFLAGS_ARGS);
|
files, CC_LIBS, CC_DLDFLAGS_ARGS);
|
||||||
if (args == NULL)
|
if (args == NULL)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
@ -1162,6 +1161,8 @@ mjit_get_iseq_func(struct rb_iseq_constant_body *body)
|
|||||||
ones to prevent changing C compiler for security reasons. */
|
ones to prevent changing C compiler for security reasons. */
|
||||||
#define CC_PATH CC_COMMON_ARGS[0]
|
#define CC_PATH CC_COMMON_ARGS[0]
|
||||||
|
|
||||||
|
extern VALUE ruby_archlibdir_path, ruby_prefix_path;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_header_filename(void)
|
init_header_filename(void)
|
||||||
{
|
{
|
||||||
@ -1176,13 +1177,6 @@ init_header_filename(void)
|
|||||||
const size_t header_name_len = sizeof(header_name) - 1;
|
const size_t header_name_len = sizeof(header_name) - 1;
|
||||||
char *p;
|
char *p;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
static const char libdirname[] = "/"
|
|
||||||
# ifdef LIBDIR_BASENAME
|
|
||||||
LIBDIR_BASENAME
|
|
||||||
# else
|
|
||||||
"lib"
|
|
||||||
# endif
|
|
||||||
;
|
|
||||||
static const char libpathflag[] =
|
static const char libpathflag[] =
|
||||||
# ifdef _MSC_VER
|
# ifdef _MSC_VER
|
||||||
"-LIBPATH:"
|
"-LIBPATH:"
|
||||||
@ -1193,7 +1187,7 @@ init_header_filename(void)
|
|||||||
const size_t libpathflag_len = sizeof(libpathflag) - 1;
|
const size_t libpathflag_len = sizeof(libpathflag) - 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"));
|
basedir_val = ruby_prefix_path;
|
||||||
basedir = StringValuePtr(basedir_val);
|
basedir = StringValuePtr(basedir_val);
|
||||||
baselen = RSTRING_LEN(basedir_val);
|
baselen = RSTRING_LEN(basedir_val);
|
||||||
verlen = strlen(ruby_version);
|
verlen = strlen(ruby_version);
|
||||||
@ -1212,15 +1206,13 @@ init_header_filename(void)
|
|||||||
(void)close(fd);
|
(void)close(fd);
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
p = libruby_build = xmalloc(libpathflag_len + baselen + 1);
|
basedir_val = ruby_archlibdir_path;
|
||||||
|
basedir = StringValuePtr(basedir_val);
|
||||||
|
baselen = RSTRING_LEN(basedir_val);
|
||||||
|
libruby_pathflag = p = xmalloc(libpathflag_len + baselen + 1);
|
||||||
p = append_str(p, libpathflag);
|
p = append_str(p, libpathflag);
|
||||||
p = append_str2(p, basedir, baselen);
|
p = append_str2(p, basedir, baselen);
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
|
|
||||||
libruby_installed = xmalloc(libpathflag_len + baselen + sizeof(libdirname));
|
|
||||||
p = append_str2(libruby_installed, libruby_build, p - libruby_build);
|
|
||||||
p = append_str(p, libdirname);
|
|
||||||
*p = '\0';
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
41
ruby.c
41
ruby.c
@ -497,10 +497,27 @@ dladdr_path(const void* addr)
|
|||||||
|
|
||||||
#define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index")
|
#define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index")
|
||||||
|
|
||||||
|
VALUE ruby_archlibdir_path, ruby_prefix_path;
|
||||||
|
|
||||||
void
|
void
|
||||||
ruby_init_loadpath_safe(int safe_level)
|
ruby_init_loadpath_safe(int safe_level)
|
||||||
{
|
{
|
||||||
VALUE load_path;
|
static const char libdir[] = "/"
|
||||||
|
#ifdef LIBDIR_BASENAME
|
||||||
|
LIBDIR_BASENAME
|
||||||
|
#else
|
||||||
|
"lib"
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_MULTIARCH
|
||||||
|
"/"RUBY_ARCH
|
||||||
|
#endif
|
||||||
|
;
|
||||||
|
const ptrdiff_t libdir_len = (ptrdiff_t)sizeof(libdir)
|
||||||
|
#ifdef ENABLE_MULTIARCH
|
||||||
|
- rb_strlen_lit("/"RUBY_ARCH)
|
||||||
|
#endif
|
||||||
|
- 1;
|
||||||
|
VALUE load_path, archlibdir = 0;
|
||||||
ID id_initial_load_path_mark;
|
ID id_initial_load_path_mark;
|
||||||
const char *paths = ruby_initial_load_paths;
|
const char *paths = ruby_initial_load_paths;
|
||||||
#if defined LOAD_RELATIVE
|
#if defined LOAD_RELATIVE
|
||||||
@ -561,23 +578,22 @@ ruby_init_loadpath_safe(int safe_level)
|
|||||||
p = strrchr(libpath, '/');
|
p = strrchr(libpath, '/');
|
||||||
if (p) {
|
if (p) {
|
||||||
static const char bindir[] = "/bin";
|
static const char bindir[] = "/bin";
|
||||||
#ifdef LIBDIR_BASENAME
|
|
||||||
static const char libdir[] = "/"LIBDIR_BASENAME;
|
|
||||||
#else
|
|
||||||
static const char libdir[] = "/lib";
|
|
||||||
#endif
|
|
||||||
const ptrdiff_t bindir_len = (ptrdiff_t)sizeof(bindir) - 1;
|
const ptrdiff_t bindir_len = (ptrdiff_t)sizeof(bindir) - 1;
|
||||||
const ptrdiff_t libdir_len = (ptrdiff_t)sizeof(libdir) - 1;
|
|
||||||
|
|
||||||
#ifdef ENABLE_MULTIARCH
|
|
||||||
const char *p2 = NULL;
|
const char *p2 = NULL;
|
||||||
|
|
||||||
|
#ifdef ENABLE_MULTIARCH
|
||||||
multiarch:
|
multiarch:
|
||||||
#endif
|
#endif
|
||||||
if (p - libpath >= bindir_len && !STRNCASECMP(p - bindir_len, bindir, bindir_len)) {
|
if (p - libpath >= bindir_len && !STRNCASECMP(p - bindir_len, bindir, bindir_len)) {
|
||||||
p -= bindir_len;
|
p -= bindir_len;
|
||||||
|
archlibdir = rb_str_subseq(sopath, 0, p - libpath);
|
||||||
|
rb_str_cat_cstr(archlibdir, libdir);
|
||||||
|
OBJ_FREEZE_RAW(archlibdir);
|
||||||
}
|
}
|
||||||
else if (p - libpath >= libdir_len && !strncmp(p - libdir_len, libdir, libdir_len)) {
|
else if (p - libpath >= libdir_len && !strncmp(p - libdir_len, libdir, libdir_len)) {
|
||||||
|
archlibdir = rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath);
|
||||||
|
OBJ_FREEZE_RAW(archlibdir);
|
||||||
p -= libdir_len;
|
p -= libdir_len;
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_MULTIARCH
|
#ifdef ENABLE_MULTIARCH
|
||||||
@ -603,6 +619,13 @@ ruby_init_loadpath_safe(int safe_level)
|
|||||||
#define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len))
|
#define RUBY_RELATIVE(path, len) rubylib_path_new((path), (len))
|
||||||
#define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)
|
#define PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len)
|
||||||
#endif
|
#endif
|
||||||
|
rb_gc_register_address(&ruby_prefix_path);
|
||||||
|
ruby_prefix_path = PREFIX_PATH();
|
||||||
|
OBJ_FREEZE_RAW(ruby_prefix_path);
|
||||||
|
if (!archlibdir) archlibdir = ruby_prefix_path;
|
||||||
|
rb_gc_register_address(&ruby_archlibdir_path);
|
||||||
|
ruby_archlibdir_path = archlibdir;
|
||||||
|
|
||||||
load_path = GET_VM()->load_path;
|
load_path = GET_VM()->load_path;
|
||||||
|
|
||||||
if (safe_level == 0) {
|
if (safe_level == 0) {
|
||||||
@ -618,7 +641,7 @@ ruby_init_loadpath_safe(int safe_level)
|
|||||||
paths += len + 1;
|
paths += len + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rb_const_set(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"), rb_obj_freeze(PREFIX_PATH()));
|
rb_const_set(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX"), ruby_prefix_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user