ruby-changes:54061
From: nobu <ko1@a...>
Date: Sat, 8 Dec 2018 10:50:44 +0900 (JST)
Subject: [ruby-changes:54061] nobu:r66280 (trunk): Give the MJIT header path name
nobu 2018-12-08 10:50:39 +0900 (Sat, 08 Dec 2018) New Revision: 66280 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66280 Log: Give the MJIT header path name Give the whole MJIT header path name by preloaded shared library mjit_build_dir.so, than building the path from a given directory name and the embedded base name. Modified files: trunk/Makefile.in trunk/mjit.c trunk/ruby-runner.c Index: mjit.c =================================================================== --- mjit.c (revision 66279) +++ mjit.c (revision 66280) @@ -365,10 +365,12 @@ static int https://github.com/ruby/ruby/blob/trunk/mjit.c#L365 init_header_filename(void) { int fd; +#ifdef LOAD_RELATIVE /* Root path of the running ruby process. Equal to RbConfig::TOPDIR. */ VALUE basedir_val; - const char *basedir; - size_t baselen; +#endif + const char *basedir = NULL; + size_t baselen = 0; char *p; #ifdef _WIN32 static const char libpathflag[] = @@ -380,33 +382,32 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L382 ; const size_t libpathflag_len = sizeof(libpathflag) - 1; #endif -#ifndef LOAD_RELATIVE - const char *build_dir = 0; - struct stat st; -#endif +#ifdef LOAD_RELATIVE basedir_val = ruby_prefix_path; basedir = StringValuePtr(basedir_val); baselen = RSTRING_LEN(basedir_val); - -#ifndef LOAD_RELATIVE +#else if (getenv("MJIT_SEARCH_BUILD_DIR")) { /* This path is not intended to be used on production, but using build directory's header file here because people want to run `make test-all` without running `make install`. Don't use $MJIT_SEARCH_BUILD_DIR except for test-all. */ - build_dir = dlsym(RTLD_DEFAULT, "MJIT_BUILD_DIR"); - if (!build_dir) { - verbose(1, "No mjit_build_directory"); - } - else if (build_dir[0] != '/') { - verbose(1, "Non-absolute path MJIT_BUILD_DIR: %s", build_dir); - } - else if (stat(build_dir, &st) || !S_ISDIR(st.st_mode)) { - verbose(1, "Non-directory path MJIT_BUILD_DIR: %s", build_dir); - } - else if (!rb_path_check(build_dir)) { - verbose(1, "Unsafe MJIT_BUILD_DIR: %s", build_dir); + struct stat st; + const char *hdr = dlsym(RTLD_DEFAULT, "MJIT_HEADER"); + if (!hdr) { + verbose(1, "No MJIT_HEADER"); + } + else if (hdr[0] != '/') { + verbose(1, "Non-absolute header file path: %s", hdr); + } + else if (stat(hdr, &st) || !S_ISREG(st.st_mode)) { + verbose(1, "Non-file header file path: %s", hdr); + } + else if ((st.st_uid != getuid()) || (st.st_mode & 022) || + !rb_path_check(hdr)) { + verbose(1, "Unsafe header file: uid=%ld mode=%#o %s", + (long)st.st_uid, (unsigned)st.st_mode, hdr); return FALSE; } else { @@ -415,43 +416,30 @@ init_header_filename(void) https://github.com/ruby/ruby/blob/trunk/mjit.c#L416 verbose(3, "PRELOADENV("PRELOADENV")=%s", getenv(PRELOADENV)); /* assume no other PRELOADENV in test-all */ unsetenv(PRELOADENV); - verbose(3, "MJIT_BUILD_DIR: %s", build_dir); - basedir = build_dir; - baselen = strlen(build_dir); } + verbose(3, "MJIT_HEADER: %s", hdr); + header_file = ruby_strdup(hdr); + if (!header_file) return FALSE; } + else #endif - -#ifndef _MSC_VER { /* A name of the header file included in any C file generated by MJIT for iseqs. */ - static const char header_name[] = MJIT_MIN_HEADER_NAME; + static const char header_name[] = MJIT_HEADER_INSTALL_DIR "/" MJIT_MIN_HEADER_NAME; const size_t header_name_len = sizeof(header_name) - 1; header_file = xmalloc(baselen + header_name_len + 1); p = append_str2(header_file, basedir, baselen); p = append_str2(p, header_name, header_name_len + 1); + } +#ifndef _MSC_VER + { if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) { verbose(1, "Cannot access header file: %s", header_file); xfree(header_file); header_file = NULL; return FALSE; } -#ifndef LOAD_RELATIVE - if (basedir == build_dir) { - memset(&st, 0, sizeof(st)); - if (fstat(fd, &st) || - (st.st_uid != getuid()) || - (st.st_mode & 022)) { - (void)close(fd); - verbose(1, "Unsafe header file: uid=%ld mode=%#o %s", - (long)st.st_uid, (unsigned)st.st_mode, header_file); - xfree(header_file); - header_file = NULL; - return FALSE; - } - } -#endif (void)close(fd); } Index: ruby-runner.c =================================================================== --- ruby-runner.c (revision 66279) +++ ruby-runner.c (revision 66280) @@ -10,7 +10,7 @@ https://github.com/ruby/ruby/blob/trunk/ruby-runner.c#L10 #include "ruby/config.h" #ifdef MAKE_MJIT_BUILD_DIR -const char MJIT_BUILD_DIR[] = BUILDDIR; +const char MJIT_HEADER[] = BUILDDIR "/" MJIT_MIN_HEADER; #else #define STRINGIZE(expr) STRINGIZE0(expr) Index: Makefile.in =================================================================== --- Makefile.in (revision 66279) +++ Makefile.in (revision 66280) @@ -596,7 +596,8 @@ mjit_config.h: https://github.com/ruby/ruby/blob/trunk/Makefile.in#L596 echo '#define RUBY_MJIT_CONFIG_H 1'; \ echo; \ sep=; \ - quote MJIT_MIN_HEADER_NAME "/$(MJIT_HEADER_INSTALL_DIR)/$(MJIT_MIN_HEADER_NAME)"; \ + quote MJIT_HEADER_INSTALL_DIR "/$(MJIT_HEADER_INSTALL_DIR)"; \ + quote MJIT_MIN_HEADER_NAME "$(MJIT_MIN_HEADER_NAME)"; \ sep=,; \ quote "MJIT_CC_COMMON " $(MJIT_CC); \ quote "MJIT_CFLAGS MJIT_ARCHFLAG" $(MJIT_CFLAGS); \ @@ -613,6 +614,8 @@ mjit_config.h: https://github.com/ruby/ruby/blob/trunk/Makefile.in#L614 } > $@ yes-test-almost yes-test-all: mjit_build_dir.$(SOEXT) -mjit_build_dir.$(SOEXT): $(MJIT_MIN_HEADER) $(srcdir)/ruby-runner.c ruby-runner.h +mjit_build_dir.$(SOEXT): $(MJIT_MIN_HEADER) $(srcdir)/ruby-runner.c ruby-runner.h mjit_config.h $(ECHO) making $@ - $(Q) $(DLDSHARED) $(MJIT_DLDFLAGS) $(ARCH_FLAG) $(CFLAGS) $(CPPFLAGS) -DMAKE_MJIT_BUILD_DIR=1 $(OUTFLAG)$@ $(srcdir)/ruby-runner.c + $(Q) $(DLDSHARED) $(MJIT_DLDFLAGS) $(ARCH_FLAG) $(CFLAGS) $(CPPFLAGS) \ + -DMAKE_MJIT_BUILD_DIR=1 -DMJIT_MIN_HEADER='"$(MJIT_MIN_HEADER)"' \ + $(OUTFLAG)$@ $(srcdir)/ruby-runner.c -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/