[前][次][番号順一覧][スレッド一覧]

ruby-changes:35790

From: yugui <ko1@a...>
Date: Sat, 11 Oct 2014 11:12:02 +0900 (JST)
Subject: [ruby-changes:35790] yugui:r47872 (trunk): Merges a patch form naclports.

yugui	2014-10-11 11:11:53 +0900 (Sat, 11 Oct 2014)

  New Revision: 47872

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=47872

  Log:
    Merges a patch form naclports.
    
    * configure.in (RUBY_NACL and others): Supports PNaCl.
    * dln.c: replace the old hacky dynamic loading over HTTP with nacl_io.
    * file.c: tenatively use access(2) instead of eaccess.
      (rb_file_load_ok): weaken with attribute but not by postprocess.
    * io.c (socket.h): now NaCl has socket.h
      (flock): disable here instead of nacl/ioctl.h
    * nacl/GNUmakefile.in (CC, LD, NM, AR, AS, RANLIB, OBJDUMP, OBJCOPY):
      respect path to them if they are absolute.
      This helps naclports to build ruby in their source tree.
      (PROGRAM_NMF, .SUFFIXES): support .pnexe for PNaCl.
      (ruby.o, file.o): move the hack to attributes in ruby.c and file.c
    * nacl/ioctl.h: removed. move the hack to io.c.
    * nacl/nacl-config.rb: support arm, pnacl and others.
    * nacl/pepper_main.c: support build in a naclports tree.
    * ruby.c (rb_load_file): weaken with attribute but not by postprocess.
    
    The patch is by sbc@g... and the Native Client Authors.
    It is available at:
    * https://chromium.googlesource.com/external/naclports.git/+/873ca4910a5f9d4206306aacb4ed79c587c6a5f3/ports/ruby/nacl.patch

  Removed files:
    trunk/nacl/ioctl.h
  Modified files:
    trunk/configure.in
    trunk/dln.c
    trunk/file.c
    trunk/io.c
    trunk/nacl/GNUmakefile.in
    trunk/nacl/README.nacl
    trunk/nacl/nacl-config.rb
    trunk/nacl/pepper_main.c
    trunk/ruby.c
Index: configure.in
===================================================================
--- configure.in	(revision 47871)
+++ configure.in	(revision 47872)
@@ -96,8 +96,11 @@ AC_DEFUN([RUBY_NACL], https://github.com/ruby/ruby/blob/trunk/configure.in#L96
                        [no], [nacl_cv_build_variant=glibc],
                        [yes], [nacl_cv_build_variant=newlib])])
 
-  AS_CASE(["$build_cpu"],
-          [x86_64|i?86], [nacl_cv_cpu_nick=x86], [nacl_cv_cpu_nick=$build_cpu])
+  AS_CASE(["$target_cpu"],
+          [x86_64|i?86], [nacl_cv_cpu_nick=x86],
+          [le32], [nacl_cv_cpu_nick=pnacl
+                   ac_cv_exeext=.pexe],
+          [nacl_cv_cpu_nick=$target_cpu])
   AS_CASE(["$build_os"],
           [linux*], [nacl_cv_os_nick=linux],
           [darwin*], [nacl_cv_os_nick=mac],
@@ -111,6 +114,9 @@ AC_DEFUN([RUBY_NACL], https://github.com/ruby/ruby/blob/trunk/configure.in#L114
   if test -d \
     "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"; then
     NACL_TOOLCHAIN="${nacl_cv_os_nick}_${nacl_cv_cpu_nick}_${nacl_cv_build_variant}"
+  elif test -d \
+    "${NACL_SDK_ROOT}/toolchain/${nacl_cv_os_nick}_x86_${nacl_cv_cpu_nick}/${nacl_cv_build_variant}"; then
+    NACL_TOOLCHAIN="${nacl_cv_os_nick}_x86_${nacl_cv_cpu_nick}/${nacl_cv_build_variant}"
   else
     AS_CASE(
       ["${nacl_cv_build_variant}"],
@@ -791,12 +797,16 @@ fi https://github.com/ruby/ruby/blob/trunk/configure.in#L797
 RUBY_TRY_CFLAGS(-Qunused-arguments, [RUBY_APPEND_OPTIONS(rb_cv_wsuppress_flags, -Qunused-arguments)])
 
 if test "$GCC" = yes; then
-    # -D_FORTIFY_SOURCE
-    # When defined _FORTIFY_SOURCE, glibc enables some additional sanity
-    # argument check. The performance drop is very little and Ubuntu enables
-    # _FORTIFY_SOURCE=2 by default. So, let's support it for protecting us from
-    # a mistake of silly C extensions.
-    RUBY_TRY_CFLAGS(-D_FORTIFY_SOURCE=2, [RUBY_APPEND_OPTION(XCFLAGS, -D_FORTIFY_SOURCE=2)])
+    # NaCl's glibc build generates undefined references to __memset_chk.
+    # TODO(sbc): Remove this once NaCl's glibc is fixed.
+    AS_CASE(["$target_os"], [nacl], [], [
+      # -D_FORTIFY_SOURCE
+      # When defined _FORTIFY_SOURCE, glibc enables some additional sanity
+      # argument check. The performance drop is very little and Ubuntu enables
+      # _FORTIFY_SOURCE=2 by default. So, let's support it for protecting us from
+      # a mistake of silly C extensions.
+      RUBY_TRY_CFLAGS(-D_FORTIFY_SOURCE=2, [RUBY_APPEND_OPTION(XCFLAGS, -D_FORTIFY_SOURCE=2)])
+   ])
 
     # -fstack-protector
     AS_CASE(["$target_os"],
@@ -1087,12 +1097,9 @@ main() https://github.com/ruby/ruby/blob/trunk/configure.in#L1097
   LIBS="-lm $LIBS"
   if test "${nacl_cv_build_variant}" = "newlib"; then
     RUBY_APPEND_OPTION(CPPFLAGS, -DNACL_NEWLIB)
-    RUBY_APPEND_OPTION(LIBS, '-lnosys')
   else
     RUBY_APPEND_OPTION(XCFLAGS, -fPIC)
   fi
-  ac_cv_func_shutdown=no
-  ac_cv_func_fcntl=no
   ],
 [	LIBS="-lm $LIBS"])
 
Index: io.c
===================================================================
--- io.c	(revision 47871)
+++ io.c	(revision 47872)
@@ -32,9 +32,7 @@ https://github.com/ruby/ruby/blob/trunk/io.c#L32
 #if defined HAVE_NET_SOCKET_H
 # include <net/socket.h>
 #elif defined HAVE_SYS_SOCKET_H
-# ifndef __native_client__
-#  include <sys/socket.h>
-# endif
+# include <sys/socket.h>
 #endif
 
 #if defined(__BOW__) || defined(__CYGWIN__) || defined(_WIN32) || defined(__EMX__) || defined(__BEOS__) || defined(__HAIKU__)
@@ -53,9 +51,6 @@ https://github.com/ruby/ruby/blob/trunk/io.c#L51
 #if defined(HAVE_SYS_IOCTL_H) && !defined(_WIN32)
 #include <sys/ioctl.h>
 #endif
-#if defined(__native_client__) && defined(NACL_NEWLIB)
-# include "nacl/ioctl.h"
-#endif
 #if defined(HAVE_FCNTL_H) || defined(_WIN32)
 #include <fcntl.h>
 #elif defined(HAVE_SYS_FCNTL_H)
@@ -8947,6 +8942,14 @@ typedef long fcntl_arg_t; https://github.com/ruby/ruby/blob/trunk/io.c#L8942
 typedef int fcntl_arg_t;
 #endif
 
+#if defined __native_client__ && !defined __GLIBC__
+// struct flock is currently missing the NaCl newlib headers
+// TODO(sbc): remove this once it gets added.
+#undef F_GETLK
+#undef F_SETLK
+#undef F_SETLKW
+#endif
+
 static long
 fcntl_narg_len(int cmd)
 {
Index: nacl/ioctl.h
===================================================================
--- nacl/ioctl.h	(revision 47871)
+++ nacl/ioctl.h	(revision 47872)
@@ -1,7 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/nacl/ioctl.h#L0
-// Copyright 2012 Google Inc. All Rights Reserved.
-// Author: yugui@g... (Yugui Sonoda)
-#ifndef RUBY_NACL_IOCTL_H
-#define RUBY_NACL_IOCTL_H
-int ioctl(int fd, int request, ...);
-struct flock{};
-#endif
Index: nacl/pepper_main.c
===================================================================
--- nacl/pepper_main.c	(revision 47871)
+++ nacl/pepper_main.c	(revision 47872)
@@ -210,7 +210,7 @@ pruby_async_return_value(void* data, VAL https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L210
 static struct PP_Var
 pruby_cstr_to_var(const char* str)
 {
-#ifdef PPB_VAR_INTERFACE_1_0
+#ifndef PPB_VAR_INTERFACE_1_1
   if (var_interface != NULL)
     return var_interface->VarFromUtf8(module_id, str, strlen(str));
   return PP_MakeUndefined();
@@ -252,7 +252,7 @@ pruby_str_to_var(volatile VALUE str) https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L252
     fprintf(stderr, "[BUG] Unexpected object type: %x\n", TYPE(str));
     exit(EXIT_FAILURE);
   }
-#ifdef PPB_VAR_INTERFACE_1_0
+#ifndef PPB_VAR_INTERFACE_1_1
   if (var_interface != NULL) {
     return var_interface->VarFromUtf8(module_id, RSTRING_PTR(str), RSTRING_LEN(str));
   }
@@ -517,7 +517,7 @@ static void Instance_DidDestroy(PP_Insta https://github.com/ruby/ruby/blob/trunk/nacl/pepper_main.c#L517
  *     the top left of the plugin's coordinate system (not the page).  If the
  *     plugin is invisible, @a clip will be (0, 0, 0, 0).
  */
-#ifdef PPP_INSTANCE_INTERFACE_1_0
+#ifndef PPP_INSTANCE_INTERFACE_1_1
 static void
 Instance_DidChangeView(PP_Instance instance,
                        const struct PP_Rect* position,
Index: nacl/nacl-config.rb
===================================================================
--- nacl/nacl-config.rb	(revision 47871)
+++ nacl/nacl-config.rb	(revision 47872)
@@ -27,14 +27,12 @@ module NaClConfig https://github.com/ruby/ruby/blob/trunk/nacl/nacl-config.rb#L27
   INSTALL_PROGRAM = config['INSTALL_PROGRAM']
   INSTALL_LIBRARY = config['INSTALL_DATA']
 
-  SEL_LDR = [
-    File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], 'bin', "sel_ldr_#{cpu_nick}"),
-    File.join(SDK_ROOT, 'tools', "sel_ldr_#{cpu_nick}")
-  ].find{|path| File.executable?(path)} or raise "No sel_ldr found"
-  IRT_CORE = [
-    File.join(SDK_ROOT, 'toolchain', config['NACL_TOOLCHAIN'], 'bin', "irt_core_#{cpu_nick}.nexe"),
-    File.join(SDK_ROOT, 'tools', "irt_core_#{cpu_nick}.nexe")
-  ].find{|path| File.exist?(path)} or raise "No irt_core found"
+  if cpu_nick == 'x86_64' or cpu_nick == 'x86_32'
+    SEL_LDR = File.join(SDK_ROOT, 'tools', "sel_ldr_#{cpu_nick}")
+    IRT_CORE = File.join(SDK_ROOT, 'tools', "irt_core_#{cpu_nick}.nexe")
+    raise "No sel_ldr found" if not File.executable?(SEL_LDR)
+    raise "No irt_core found" if not File.exists?(IRT_CORE)
+  end
   RUNNABLE_LD = File.join(HOST_LIB, 'runnable-ld.so')
 
   module_function
Index: nacl/README.nacl
===================================================================
--- nacl/README.nacl	(revision 47871)
+++ nacl/README.nacl	(revision 47872)
@@ -6,14 +6,14 @@ https://github.com/ruby/ruby/blob/trunk/nacl/README.nacl#L6
 You need to install the following things before building NaCl port of Ruby.
 * Ruby 1.9.3 or later
 * Python 2.6 or later
-* NativeClient SDK pepper 22 or later
+* NativeClient SDK pepper 37 or later
 * GNU make
 
 == Steps
 (1) Extract all files from the tarball:
      $ tar xzf ruby-X.Y.Z.tar.gz
 (2) Set NACL_SDK_ROOT environment variable to the path to the Native Client SDK you installed:
-     $ export NACL_SDK_ROOT=/home/yugui/src/nacl_sdk/pepper_16
+     $ export NACL_SDK_ROOT=/home/yugui/src/nacl_sdk/pepper_37
 (3) Configure
      $ ./configure --prefix=/tmp/nacl-ruby --host=x86_64-nacl --with-baseruby=/path/to/ruby-1.9.3
 (4) Make
Index: nacl/GNUmakefile.in
===================================================================
--- nacl/GNUmakefile.in	(revision 47871)
+++ nacl/GNUmakefile.in	(revision 47872)
@@ -7,45 +7,54 @@ include Makefile https://github.com/ruby/ruby/blob/trunk/nacl/GNUmakefile.in#L7
 NACL_SDK_ROOT=@NACL_SDK_ROOT@
 NACL_TOOLCHAIN=@NACL_TOOLCHAIN@
 NACL_TOOLCHAIN_DIR=$(NACL_SDK_ROOT)/toolchain/$(NACL_TOOLCHAIN)
+
+# Don't override CC/LD/etc if they are already set to absolute
+# paths (this is the case when building in the naclports tree).
+ifeq ($(dir $(CC)),./)
 CC:=$(NACL_TOOLCHAIN_DIR)/bin/$(CC)
+endif
+ifeq ($(dir $(LD)),./)
 LD:=$(NACL_TOOLCHAIN_DIR)/bin/$(LD)
+endif
+ifeq ($(dir $(NM)),./)
 NM:=$(NACL_TOOLCHAIN_DIR)/bin/$(NM)
+endif
+ifeq ($(dir $(AR)),./)
 AR:=$(NACL_TOOLCHAIN_DIR)/bin/$(AR)
+endif
+ifeq ($(dir $(AS)),./)
 AS:=$(NACL_TOOLCHAIN_DIR)/bin/$(AS)
+endif
+ifeq ($(dir $(RANLIB)),./)
 RANLIB:=$(NACL_TOOLCHAIN_DIR)/bin/$(RANLIB)
+endif
+ifeq ($(dir $(OBJDUMP)),./)
 OBJDUMP:=$(NACL_TOOLCHAIN_DIR)/bin/$(OBJDUMP)
+endif
+ifeq ($(dir $(OBJCOPY)),./)
 OBJCOPY:=$(NACL_TOOLCHAIN_DIR)/bin/$(OBJCOPY)
+endif
 PYTHON=@PYTHON@
 
 PPROGRAM=pepper-$(PROGRAM)
 PEPPER_LIBS=-lppapi
-PROGRAM_NMF=$(PROGRAM:.nexe=.nmf)
-PPROGRAM_NMF=$(PPROGRAM:.nexe=.nmf)
+PROGRAM_NMF=$(PROGRAM:$(EXEEXT)=.nmf)
+PPROGRAM_NMF=$(PPROGRAM:$(EXEEXT)=.nmf)
 
 GNUmakefile: $(srcdir)/nacl/GNUmakefile.in
 $(PPROGRAM): $(PROGRAM) pepper_main.$(OBJEXT)
 	$(Q)$(MAKE) $(MFLAGS) PROGRAM=$(PPROGRAM) MAINOBJ="pepper_main.$(OBJEXT)" LIBS="$(LIBS) $(PEPPER_LIBS)" program
-$(PROGRAM_NMF) $(PPROGRAM_NMF): $(@:.nmf=.nexe) nacl/create_nmf.rb
+$(PROGRAM_NMF) $(PPROGRAM_NMF): $(@:.nmf=$(EXEEXT)) nacl/create_nmf.rb
 
 .PHONY: pprogram package show_naclflags
-.SUFFIXES: .nexe .nmf
-.nexe.nmf:
+.SUFFIXES: $(EXEEXT) .nmf
+$(EXEEXT).nmf:
 	$(ECHO) generating manifest $@
-	$(Q)$(MINIRUBY) $(srcdir)/nacl/create_nmf.rb --verbose=$(V) $(@:.nmf=.nexe) $@
+	$(Q)$(MINIRUBY) $(srcdir)/nacl/create_nmf.rb --verbose=$(V) $(@:.nmf=$(EXEEXT)) $@
 
 pepper_main.$(OBJEXT): $(srcdir)/nacl/pepper_main.c
 	@$(ECHO) compiling nacl/pepper_main.c
 	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c $(srcdir)/nacl/pepper_main.c
-ruby.$(OBJEXT):
-	@$(ECHO) compiling $<
-	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@.tmp -c $<
-	$(Q) $(OBJCOPY) --weaken-symbol=rb_load_file $@.tmp $@
-	@-$(RM) $@.tmp
-file.$(OBJEXT):
-	@$(ECHO) compiling $<
-	$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@.tmp -c $<
-	$(Q) $(OBJCOPY) --weaken-symbol=rb_file_load_ok $@.tmp $@
-	@-$(RM) $@.tmp
 
 .rbconfig.time:
 	@$(MAKE) .rbconfig.raw.time RBCONFIG=.rbconfig.raw.time
Index: dln.c
===================================================================
--- dln.c	(revision 47871)
+++ dln.c	(revision 47872)
@@ -1325,28 +1325,13 @@ dln_load(const char *file) https://github.com/ruby/ruby/blob/trunk/dln.c#L1325
 # define RTLD_GLOBAL 0
 #endif
 
-#ifdef __native_client__
-	char* p, *orig;
-        if (file[0] == '.' && file[1] == '/') file+=2;
-	orig = strdup(file);
-	for (p = file; *p; ++p) {
-	    if (*p == '/') *p = '_';
-	}
-#endif
 	/* Load file */
 	if ((handle = (void*)dlopen(file, RTLD_LAZY|RTLD_GLOBAL)) == NULL) {
-#ifdef __native_client__
-            free(orig);
-#endif
 	    error = dln_strerror();
 	    goto failed;
 	}
 
 	init_fct = (void(*)())(VALUE)dlsym(handle, buf);
-#ifdef __native_client__
-	strcpy(file, orig);
-	free(orig);
-#endif
 	if (init_fct == NULL) {
 	    error = DLN_ERROR();
 	    dlclose(handle);
Index: ruby.c
===================================================================
--- ruby.c	(revision 47871)
+++ ruby.c	(revision 47872)
@@ -1729,6 +1729,9 @@ load_file(VALUE parser, VALUE fname, int https://github.com/ruby/ruby/blob/trunk/ruby.c#L1729
     return (NODE *)rb_ensure(load_file_internal, (VALUE)&arg, restore_lineno, rb_gv_get("$."));
 }
 
+#ifdef __native_client__
+__attribute__((weak))
+#endif
 void *
 rb_load_file(const char *fname)
 {
Index: file.c
===================================================================
--- file.c	(revision 47871)
+++ file.c	(revision 47872)
@@ -1190,6 +1190,14 @@ rb_group_member(GETGROUPS_T gid) https://github.com/ruby/ruby/blob/trunk/file.c#L1190
 #define USE_GETEUID 1
 #endif
 
+#ifdef __native_client__
+// Although the NaCl toolchain contain eaccess() is it not yet
+// overridden by nacl_io.
+// TODO(sbc): Remove this once eaccess() is wired up correctly
+// in NaCl.
+#define eaccess access
+#endif
+
 #ifndef HAVE_EACCESS
 int
 eaccess(const char *path, int mode)
@@ -5503,7 +5511,7 @@ rb_path_check(const char *path) https://github.com/ruby/ruby/blob/trunk/file.c#L5511
 
 #ifndef _WIN32
 #ifdef __native_client__
-__attribute__((noinline))
+__attribute__((noinline,weak))
 #endif
 int
 rb_file_load_ok(const char *path)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]