From df019224f8168d5bb460afbc28b51dc0ff27f5f2 Mon Sep 17 00:00:00 2001 From: Sylvain Ageneau Date: Sat, 22 Dec 2012 00:54:47 -0300 Subject: [PATCH] mobile: support Nacl and PNacl This patch adds support for chrome's Native Client and Portable Native Client --- src/aclocal.m4 | 28 ++++++++++++++++++++++++++++ src/c/stacks.d | 2 +- src/c/unixint.d | 4 ++-- src/c/unixsys.d | 22 ++++++++++++++++++++-- src/cmp/cmpdefs.lsp | 8 ++++++-- src/cmp/cmpname.lsp | 13 +++++++++++++ src/configure | 29 +++++++++++++++++++++++++++++ src/ecl/configpre.h | 3 --- src/h/config.h.in | 41 ++++++++++++++++++++++++++--------------- src/lsp/config.lsp.in | 4 ++-- 10 files changed, 127 insertions(+), 27 deletions(-) diff --git a/src/aclocal.m4 b/src/aclocal.m4 index c182878b8..cde4167a1 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -449,10 +449,38 @@ case "${host_os}" in esac case "${host}" in + *-nacl) + thehost='linux' + THREAD_CFLAGS='-D_THREAD_SAFE' + THREAD_LIBS='-lpthread' + SHARED_LDFLAGS="-shared ${LDFLAGS}" + BUNDLE_LDFLAGS="-shared ${LDFLAGS}" + ECL_GC_DIR=gc-unstable + ECL_LDRPATH='-Wl,--rpath,~A' + CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 ${CFLAGS}" + SONAME="${SHAREDPREFIX}ecl.${SHAREDEXT}.SOVERSION" + SONAME_LDFLAGS="-Wl,-soname,SONAME" + ECL_ADD_FEATURE([nacl]) + ;; + *-pnacl) + thehost='linux' + THREAD_CFLAGS='-D_THREAD_SAFE' + THREAD_LIBS='-lpthread' + dnl SHARED_LDFLAGS="-shared ${LDFLAGS}" + dnl BUNDLE_LDFLAGS="-shared ${LDFLAGS}" + ECL_GC_DIR=gc-unstable + dnl ECL_LDRPATH='-Wl,--rpath,~A' + CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 ${CFLAGS}" + dnl SONAME="${SHAREDPREFIX}ecl.${SHAREDEXT}.SOVERSION" + dnl SONAME_LDFLAGS="-Wl,-soname,SONAME" + ECL_ADD_FEATURE([nacl]) + ECL_ADD_FEATURE([pnacl]) + ;; i686*-android*) THREAD_LIBS='' CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DANDROID -DPLATFORM_ANDROID -DUSE_GET_STACKBASE_FOR_MAIN -DIGNORE_DYNAMIC_LOADING -DNO_GETCONTEXT -DHAVE_GETTIMEOFDAY -DHAVE_SIGPROCMASK ${CFLAGS}" ECL_ADD_FEATURE([android]) + ;; esac case "${host_cpu}" in diff --git a/src/c/stacks.d b/src/c/stacks.d index e71a02f45..dd8f615db 100644 --- a/src/c/stacks.d +++ b/src/c/stacks.d @@ -97,7 +97,7 @@ ecl_cs_set_org(cl_env_ptr env) env->cs_org = (char*)(&env); env->cs_barrier = env->cs_org; env->cs_max_size = 0; -#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) +#if defined(HAVE_SYS_RESOURCE_H) && defined(RLIMIT_STACK) && !defined(NACL) { struct rlimit rl; cl_index size; diff --git a/src/c/unixint.d b/src/c/unixint.d index 2fbfd929c..014d60a10 100644 --- a/src/c/unixint.d +++ b/src/c/unixint.d @@ -673,7 +673,7 @@ handler_fn_prototype(fpe_signal_handler, int sig, siginfo_t *info, void *data) feclearexcept(FE_ALL_EXCEPT); # endif #endif /* !_MSC_VER */ -#ifdef SA_SIGINFO +#if defined(SA_SIGINFO) && !defined(NACL) if (info) { if (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV) { condition = @'division-by-zero'; @@ -726,7 +726,7 @@ handler_fn_prototype(sigsegv_handler, int sig, siginfo_t *info, void *aux) the_env = ecl_process_env(); unlikely_if (zombie_process(the_env)) return; -#if defined(SA_SIGINFO) +#if defined(SA_SIGINFO) && !defined(NACL) # if defined(ECL_USE_MPROTECT) /* We access the environment when it was protected. That * means there was a pending signal. */ diff --git a/src/c/unixsys.d b/src/c/unixsys.d index f5c1ee222..4bc874a5a 100644 --- a/src/c/unixsys.d +++ b/src/c/unixsys.d @@ -47,7 +47,12 @@ cl_object si_getpid(void) { +#if defined(NACL) + FElibc_error("si_getpid not implemented",1); + @(return Cnil) +#else @(return ecl_make_fixnum(getpid())) +#endif } cl_object @@ -66,6 +71,10 @@ ecl_def_ct_base_string(fake_out_name, "PIPE-WRITE-ENDPOINT", 19, static, const); cl_object si_make_pipe() { +#if defined(NACL) + FElibc_error("si_make_pipe not implemented",1); + @(return Cnil) +#else cl_object output; int fds[2], ret; #if defined(ECL_MS_WINDOWS_HOST) @@ -84,6 +93,7 @@ si_make_pipe() output = cl_make_two_way_stream(in, out); } @(return output) +#endif } static cl_object @@ -237,7 +247,10 @@ static cl_object ecl_waitpid(cl_object pid, cl_object wait) { cl_object status, code; -#if defined(ECL_MS_WINDOWS_HOST) +#if defined(NACL) + FElibc_error("ecl_waitpid not implemented",1); + @(return Cnil) +#elif defined(ECL_MS_WINDOWS_HOST) cl_env_ptr the_env = ecl_process_env(); HANDLE *hProcess = ecl_foreign_data_pointer_safe(pid); DWORD exitcode; @@ -649,7 +662,7 @@ create_descriptor(cl_object stream, cl_object direction, if (child_stdout) CloseHandle(child_stdout); if (child_stderr) CloseHandle(child_stderr); } -#else /* mingw */ +#elif !defined(NACL) /* mingw */ { int child_stdin, child_stdout, child_stderr; int pipe_fd[2]; @@ -730,6 +743,11 @@ create_descriptor(cl_object stream, cl_object direction, close(child_stdout); close(child_stderr); } +#else +{ + FElibc_error("ext::run-program not implemented",1); + @(return Cnil) +} #endif /* mingw */ if (Null(pid)) { if (parent_write) close(parent_write); diff --git a/src/cmp/cmpdefs.lsp b/src/cmp/cmpdefs.lsp index 8210fd4cc..4a3974336 100644 --- a/src/cmp/cmpdefs.lsp +++ b/src/cmp/cmpdefs.lsp @@ -45,8 +45,12 @@ coprocessor).") (defvar *ld-format* #-msvc "~A -o ~S -L~S ~{~S ~} ~@[~S~]~{ '~A'~} ~A" #+msvc "~A -Fe~S~* ~{~S ~} ~@[~S~]~{ '~A'~} ~A") -(defvar *cc-format* #-msvc "~A -I. \"-I~A\" ~A ~:[~*~;~A~] -w -c \"~A\" -o \"~A\"~{ '~A'~}" - #+msvc "~A -I. -I\"~A\" ~A ~:[~*~;~A~] -w -c \"~A\" -Fo\"~A\"~{ '~A'~}") +(defvar *cc-format* (cond ((member :msvc *features*) + "~A -I. \"-I~A\" ~A ~:[~*~;~A~] -w -c \"~A\" -o \"~A\"~{ '~A'~}") + ((member :nacl *features*) ;; pnacl-clang doesn't support -w + "~A -I. \"-I~A\" ~A ~:[~*~;~A~] -c \"~A\" -o \"~A\"~{ '~A'~}") + (t + "~A -I. \"-I~A\" ~A ~:[~*~;~A~] -w -c \"~A\" -o \"~A\"~{ '~A'~}"))) #-dlopen (defvar *ld-flags* "@LDFLAGS@ -lecl @CORE_LIBS@ @FASL_LIBS@ @LIBS@") diff --git a/src/cmp/cmpname.lsp b/src/cmp/cmpname.lsp index be6b27a2d..f9af4e422 100644 --- a/src/cmp/cmpname.lsp +++ b/src/cmp/cmpname.lsp @@ -97,7 +97,20 @@ initialization function in object files have more or less unpredictable names, we store them in a string in the object file. This string is recognized by the TAG it has at the beginning This function searches that tag and retrieves the function name it precedes." + #-pnacl (with-open-file (stream file :direction :input :element-type '(unsigned-byte 8)) + (when (search-tag stream tag) + (let ((name (read-name stream))) + name))) + #+pnacl + (let* ((pnacl-dis (or (ext:getenv "PNACL_DIS") + (error "please set the PNACL_DIS environment variable to your toolchain's pnacl-dis location"))) + (stream (ext:run-program + pnacl-dis + (list (namestring (translate-logical-pathname file))) + :wait nil :input NIL :output :STREAM :error :OUTPUT))) + (unless stream + (error "Unable to disasemble file ~a" file)) (when (search-tag stream tag) (let ((name (read-name stream))) name)))) diff --git a/src/configure b/src/configure index 1af77f82f..13dc9c638 100755 --- a/src/configure +++ b/src/configure @@ -5070,12 +5070,41 @@ LSP_FEATURES="(cons :android ${LSP_FEATURES})" esac case "${host}" in + *-nacl) + thehost='linux' + THREAD_CFLAGS='-D_THREAD_SAFE' + THREAD_LIBS='-lpthread' + SHARED_LDFLAGS="-shared ${LDFLAGS}" + BUNDLE_LDFLAGS="-shared ${LDFLAGS}" + ECL_GC_DIR=gc-unstable + ECL_LDRPATH='-Wl,--rpath,~A' + CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 ${CFLAGS}" + SONAME="${SHAREDPREFIX}ecl.${SHAREDEXT}.SOVERSION" + SONAME_LDFLAGS="-Wl,-soname,SONAME" + +LSP_FEATURES="(cons :nacl ${LSP_FEATURES})" + + ;; + *-pnacl) + thehost='linux' + THREAD_CFLAGS='-D_THREAD_SAFE' + THREAD_LIBS='-lpthread' + ECL_GC_DIR=gc-unstable + CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 ${CFLAGS}" + +LSP_FEATURES="(cons :nacl ${LSP_FEATURES})" + + +LSP_FEATURES="(cons :pnacl ${LSP_FEATURES})" + + ;; i686*-android*) THREAD_LIBS='' CFLAGS="-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -DANDROID -DPLATFORM_ANDROID -DUSE_GET_STACKBASE_FOR_MAIN -DIGNORE_DYNAMIC_LOADING -DNO_GETCONTEXT -DHAVE_GETTIMEOFDAY -DHAVE_SIGPROCMASK ${CFLAGS}" LSP_FEATURES="(cons :android ${LSP_FEATURES})" + ;; esac case "${host_cpu}" in diff --git a/src/ecl/configpre.h b/src/ecl/configpre.h index 643eff4e8..2cbbdc5f3 100644 --- a/src/ecl/configpre.h +++ b/src/ecl/configpre.h @@ -1,6 +1,3 @@ -/* -*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*- */ -/* vim: set filetype=c tabstop=8 shiftwidth=4 expandtab: */ - /* ecl/configpre.h. Generated from configure.ac by autoheader. */ /* Define if building universal (internal helper macro) */ diff --git a/src/h/config.h.in b/src/h/config.h.in index 242bc021b..7bd23902b 100644 --- a/src/h/config.h.in +++ b/src/h/config.h.in @@ -124,12 +124,13 @@ /* We use hierarchical package names, like in Allegro CL */ #undef ECL_RELATIVE_PACKAGE_NAMES -/* Use mprotect for fast interrupt dispatch */ +/* Use mprotect for fast interrupt dispatch */ +#ifndef NACL #undef ECL_USE_MPROTECT +#endif #if defined(ECL_MS_WINDOWS_HOST) # define ECL_USE_GUARD_PAGE #endif - /* Integer types */ @ECL_STDINT_HEADER@ #undef ecl_uint8_t @@ -327,28 +328,36 @@ typedef unsigned char ecl_base_char; #undef HAVE_NANOSLEEP /* Float version if isnan() */ #undef HAVE_ISNANF -/* float.h for epsilons, maximum real numbers, etc */ +/* float.h for epsilons, maximum real numbers, etc */ #undef HAVE_FLOAT_H -/* select() */ +/* select() */ +#ifndef NACL #undef HAVE_SELECT +#endif #undef HAVE_SYS_SELECT_H #undef HAVE_SYS_IOCTL_H -/* putenv() or setenv() */ +/* putenv() or setenv() */ #undef HAVE_SETENV #undef HAVE_PUTENV -/* times() and sys/times.h */ +/* times() and sys/times.h */ +#ifndef NACL #undef HAVE_TIMES -/* gettimeofday() and sys/time.h */ +#endif +/* gettimeofday() and sys/time.h */ #undef HAVE_GETTIMEOFDAY -/* getrusage() and sys/resource.h */ +/* getrusage() and sys/resource.h */ +#ifndef NACL #undef HAVE_GETRUSAGE -/* user home directory, user name, etc... */ +#endif +/* user home directory, user name, etc... */ #undef HAVE_PW_H -/* symbolic links and checking their existence */ +/* symbolic links and checking their existence */ +#ifndef NACL #undef HAVE_LSTAT -/* safe creation of temporary files */ +#endif +/* safe creation of temporary files */ #undef HAVE_MKSTEMP -/* timer for userland threads */ +/* timer for userland threads */ #undef HAVE_ALARM /* filesytem */ #undef HAVE_DIRENT_H @@ -356,11 +365,13 @@ typedef unsigned char ecl_base_char; #undef HAVE_DLFCN_H #undef HAVE_LINK_H #undef HAVE_MACH_O_DYLD_H -/* POSIX signals */ +/* POSIX signals */ +#ifndef NACL #undef HAVE_SIGPROCMASK -/* isatty() checks whether a file is connected to a */ +#endif +/* isatty() checks whether a file is connected to a */ #undef HAVE_ISATTY -/* can manipulate floating point environment */ +/* can manipulate floating point environment */ #undef HAVE_FENV_H /* can activate individual traps in floating point environment */ /* this flag has to be deactivated for the Itanium architecture, where */ diff --git a/src/lsp/config.lsp.in b/src/lsp/config.lsp.in index 9bd29db27..7d69b395d 100644 --- a/src/lsp/config.lsp.in +++ b/src/lsp/config.lsp.in @@ -7,12 +7,12 @@ ;; (in-package "LISP") -#+(and (not ecl-min) uname) +#+(and (not ecl-min) (not nacl) uname) (ffi:clines " #include ") -#+(and (not ecl-min) uname) +#+(and (not ecl-min) (not nacl) uname) (defun uname () (ffi:c-inline () () :object "{ cl_object output;