diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-27 02:02:29 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-04-27 02:02:29 +0000 |
commit | 67800ea9c785f963701345e516c768b53dd84f82 (patch) | |
tree | 7a1250fffa559595304a5d815b3a6201e058f0e3 | |
parent | 9ce0a846408f28830f5e90387495a2ba9e8c1c2a (diff) | |
download | ruby-67800ea9c785f963701345e516c768b53dd84f82.tar.gz |
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
-rw-r--r-- | mjit.c | 60 | ||||
-rw-r--r-- | ruby.c | 41 |
2 files changed, 58 insertions, 43 deletions
@@ -208,10 +208,8 @@ static VALUE valid_class_serials; VALUE rb_mMJIT; #ifdef _WIN32 -/* Linker option to enable libruby in the build directory. */ -static char *libruby_build; -/* Linker option to enable libruby in the directory after install. */ -static char *libruby_installed; +/* Linker option to enable libruby. */ +static char *libruby_pathflag; #endif /* Return time in milliseconds as a double. */ @@ -582,6 +580,15 @@ static const char *const CC_DLDFLAGS_ARGS[] = { 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) /* Status of the precompiled header creation. The status is 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 "-o", #endif - NULL, NULL, NULL}; - const char *libs[] = { + NULL, NULL, #ifdef _WIN32 # ifdef _MSC_VER - MJIT_LIBS "-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 + libruby_pathflag, #endif - NULL}; + NULL, + }; char **args; #ifdef _MSC_VER char *p; int solen; #endif - files[numberof(files)-2] = c_file; #ifdef _MSC_VER solen = strlen(so_file); files[0] = p = xmalloc(rb_strlen_lit("-Fe") + solen + 1); p = append_lit(p, "-Fe"); p = append_str2(p, so_file, solen); *p = '\0'; + files[1] = c_file; #else # ifdef __clang__ files[1] = pch_file; # endif - files[numberof(files)-3] = so_file; + files[numberof(files)-3] = c_file; + files[numberof(files)-4] = so_file; #endif args = form_args(5, CC_LDSHARED_ARGS, CC_CODEFLAG_ARGS, - files, libs, CC_DLDFLAGS_ARGS); + files, CC_LIBS, CC_DLDFLAGS_ARGS); if (args == NULL) 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. */ #define CC_PATH CC_COMMON_ARGS[0] +extern VALUE ruby_archlibdir_path, ruby_prefix_path; + static void init_header_filename(void) { @@ -1176,13 +1177,6 @@ init_header_filename(void) const size_t header_name_len = sizeof(header_name) - 1; char *p; #ifdef _WIN32 - static const char libdirname[] = "/" -# ifdef LIBDIR_BASENAME - LIBDIR_BASENAME -# else - "lib" -# endif - ; static const char libpathflag[] = # ifdef _MSC_VER "-LIBPATH:" @@ -1193,7 +1187,7 @@ init_header_filename(void) const size_t libpathflag_len = sizeof(libpathflag) - 1; #endif - basedir_val = rb_const_get(rb_cObject, rb_intern_const("TMP_RUBY_PREFIX")); + basedir_val = ruby_prefix_path; basedir = StringValuePtr(basedir_val); baselen = RSTRING_LEN(basedir_val); verlen = strlen(ruby_version); @@ -1212,15 +1206,13 @@ init_header_filename(void) (void)close(fd); #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_str2(p, basedir, baselen); *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 } @@ -497,10 +497,27 @@ dladdr_path(const void* addr) #define INITIAL_LOAD_PATH_MARK rb_intern_const("@gem_prelude_index") +VALUE ruby_archlibdir_path, ruby_prefix_path; + void 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; const char *paths = ruby_initial_load_paths; #if defined LOAD_RELATIVE @@ -561,23 +578,22 @@ ruby_init_loadpath_safe(int safe_level) p = strrchr(libpath, '/'); if (p) { 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 libdir_len = (ptrdiff_t)sizeof(libdir) - 1; -#ifdef ENABLE_MULTIARCH const char *p2 = NULL; +#ifdef ENABLE_MULTIARCH multiarch: #endif if (p - libpath >= bindir_len && !STRNCASECMP(p - bindir_len, bindir, 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)) { + archlibdir = rb_str_subseq(sopath, 0, (p2 ? p2 : p) - libpath); + OBJ_FREEZE_RAW(archlibdir); p -= libdir_len; } #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 PREFIX_PATH() RUBY_RELATIVE(ruby_exec_prefix, exec_prefix_len) #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; if (safe_level == 0) { @@ -618,7 +641,7 @@ ruby_init_loadpath_safe(int safe_level) 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); } |