diff mbox

libgo patch committed: Add preliminary Solaris support

Message ID mcr62tuzl4d.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Jan. 12, 2011, 6:33 a.m. UTC
This patch to libgo adds preliminary support for Solaris.  This is based
on a patch from Rainer Orth.  I also cleaned up the configure script a
bit.  Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r 42077303a629 libgo/Makefile.am
--- a/libgo/Makefile.am	Tue Jan 11 17:55:34 2011 -0800
+++ b/libgo/Makefile.am	Tue Jan 11 22:16:49 2011 -0800
@@ -1188,7 +1188,8 @@ 
 
 libgo_la_SOURCES = $(runtime_files)
 
-libgo_la_LIBADD = $(libgo_go_objs) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS)
+libgo_la_LIBADD = \
+	$(libgo_go_objs) $(LIBFFI) $(PTHREAD_LIBS) $(MATH_LIBS) $(NET_LIBS)
 
 libgobegin_a_SOURCES = \
 	runtime/go-main.c
@@ -1203,8 +1204,7 @@ 
 	$(AM_GOCFLAGS) $(GOCFLAGS)
 
 GOLINK = $(LIBTOOL) --tag GO --mode-link $(GOC) \
-	$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_GOCFLAGS) $(LTLDFLAGS) \
-	$(PTHREAD_LIBS) $(MATH_LIBS) -o $@
+	$(OPT_LDFLAGS) $(SECTION_LDFLAGS) $(AM_GOCFLAGS) $(LTLDFLAGS) -o $@
 
 # Build a package.
 BUILDARCHIVE = \
diff -r 42077303a629 libgo/configure.ac
--- a/libgo/configure.ac	Tue Jan 11 17:55:34 2011 -0800
+++ b/libgo/configure.ac	Tue Jan 11 22:16:49 2011 -0800
@@ -116,22 +116,28 @@ 
 is_freebsd=no
 is_linux=no
 is_rtems=no
+is_solaris=no
 GOOS=unknown
 case ${host} in
-  *-*-darwin*) is_darwin=yes; GOOS=darwin ;;
-  *-*-freebsd*) is_freebsd=yes; GOOS=freebsd ;;
-  *-*-linux*)  is_linux=yes; GOOS=linux  ;;
-  *-*-rtems*)  is_rtems=yes; GOOS=rtems  ;;
+  *-*-darwin*)   is_darwin=yes;  GOOS=darwin ;;
+  *-*-freebsd*)  is_freebsd=yes; GOOS=freebsd ;;
+  *-*-linux*)    is_linux=yes;   GOOS=linux ;;
+  *-*-rtems*)    is_rtems=yes;   GOOS=rtems ;;
+  *-*-solaris2*) is_solaris=yes; GOOS=solaris ;;
 esac
 AM_CONDITIONAL(LIBGO_IS_DARWIN, test $is_darwin = yes)
 AM_CONDITIONAL(LIBGO_IS_FREEBSD, test $is_freebsd = yes)
 AM_CONDITIONAL(LIBGO_IS_LINUX, test $is_linux = yes)
 AM_CONDITIONAL(LIBGO_IS_RTEMS, test $is_rtems = yes)
+AM_CONDITIONAL(LIBGO_IS_SOLARIS, test $is_solaris = yes)
 AC_SUBST(GOOS)
 
+dnl N.B. Keep in sync with gcc/testsuite/go.test/go-test.exp (go-set-goarch).
 is_386=no
+is_arm=no
+is_sparc=no
+is_sparcv9=no
 is_x86_64=no
-is_arm=no
 GOARCH=unknown
 case ${host} in
 changequote(,)dnl
@@ -143,8 +149,10 @@ 
 #endif],
 [is_386=yes], [is_x86_64=yes])
     if test "$is_386" = "yes"; then
+      is_386=yes
       GOARCH=386
     else
+      is_x86_64=yes
       GOARCH=amd64
     fi
     ;;
@@ -152,22 +160,38 @@ 
     is_arm=yes
     GOARCH=arm
     ;;
+  sparc*-*-*)
+    AC_PREPROC_IFELSE([
+#if defined(__sparcv9) || defined(__arch64__)
+#error 64-bit
+#endif],
+[is_sparc=yes], [is_sparcv9=yes])
+    if test "$is_sparc" = "yes"; then
+      is_sparc=yes
+      GOARCH=sparc
+    else
+      is_sparcv9=yes
+      GOARCH=sparcv9
+    fi
+    ;;
 esac
 AM_CONDITIONAL(LIBGO_IS_386, test $is_386 = yes)
+AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
+AM_CONDITIONAL(LIBGO_IS_SPARC, test $is_sparc = yes)
+AM_CONDITIONAL(LIBGO_IS_SPARCV9, test $isv_sparcv9 = yes)
 AM_CONDITIONAL(LIBGO_IS_X86_64, test $is_x86_64 = yes)
-AM_CONDITIONAL(LIBGO_IS_ARM, test $is_arm = yes)
 AC_SUBST(GOARCH)
 
 dnl Use -fsplit-stack when compiling C code if available.
 AC_CACHE_CHECK([whether -fsplit-stack is supported],
-[ac_cv_libgo_split_stack_supported],
+[libgo_cv_c_split_stack_supported],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -fsplit-stack"
 AC_COMPILE_IFELSE([[int i;]],
-[ac_cv_libgo_split_stack_supported=yes],
-[ac_cv_libgo_split_stack_supported=no])
+[libgo_cv_c_split_stack_supported=yes],
+[libgo_cv_c_split_stack_supported=no])
 CFLAGS=$CFLAGS_hold])
-if test "$ac_cv_libgo_split_stack_supported" = yes; then
+if test "$libgo_cv_c_split_stack_supported" = yes; then
   SPLIT_STACK=-fsplit-stack
   AC_DEFINE(USING_SPLIT_STACK, 1,
 		[Define if the compiler supports -fsplit-stack])
@@ -176,7 +200,7 @@ 
 fi
 AC_SUBST(SPLIT_STACK)
 AM_CONDITIONAL(USING_SPLIT_STACK,
-	test "$ac_cv_libgo_split_stack_supported" = yes)
+	test "$libgo_cv_c_split_stack_supported" = yes)
 
 dnl Check whether the linker does stack munging when calling from
 dnl split-stack into non-split-stack code.  We check this by looking
@@ -184,12 +208,12 @@ 
 dnl possible for the linker to support this for some targets but not
 dnl others.
 AC_CACHE_CHECK([whether linker supports split stack],
-[ac_cv_libgo_linker_supports_split_stack],
-ac_cv_libgo_linker_supports_split_stack=no
+[libgo_cv_c_linker_supports_split_stack],
+libgo_cv_c_linker_supports_split_stack=no
 if $LD --help 2>/dev/null | grep split-stack-adjust-size >/dev/null 2>&1; then
-  ac_cv_libgo_linker_supports_split_stack=yes
+  libgo_cv_c_linker_supports_split_stack=yes
 fi)
-if test "$ac_cv_libgo_linker_supports_split_stack" = yes; then
+if test "$libgo_cv_c_linker_supports_split_stack" = yes; then
   AC_DEFINE(LINKER_SUPPORTS_SPLIT_STACK, 1,
 	    [Define if the linker support split stack adjustments])
 fi
@@ -199,17 +223,48 @@ 
 AC_CHECK_LIB([m], [sqrt], MATH_LIBS=-lm)
 AC_SUBST(MATH_LIBS)
 
+dnl Test for -lsocket and -lnsl.  Copied from libjava/configure.ac.
+AC_CACHE_CHECK([for socket libraries], libgo_cv_lib_sockets,
+  [libgo_cv_lib_sockets=
+   libgo_check_both=no
+   AC_CHECK_FUNC(connect, libgo_check_socket=no, libgo_check_socket=yes)
+   if test "$libgo_check_socket" = "yes"; then
+     unset ac_cv_func_connect
+     AC_CHECK_LIB(socket, main, libgo_cv_lib_sockets="-lsocket",
+     		  libgo_check_both=yes)
+   fi
+   if test "$libgo_check_both" = "yes"; then
+     libgo_old_libs=$LIBS
+     LIBS="$LIBS -lsocket -lnsl"
+     unset ac_cv_func_accept
+     AC_CHECK_FUNC(accept,
+		   [libgo_check_nsl=no
+		    libgo_cv_lib_sockets="-lsocket -lnsl"])
+     unset ac_cv_func_accept
+     LIBS=$libgo_old_libs
+   fi
+   unset ac_cv_func_gethostbyname
+   libgo_old_libs="$LIBS"
+   AC_CHECK_FUNC(gethostbyname, ,
+		 [AC_CHECK_LIB(nsl, main,
+		 	[libgo_cv_lib_sockets="$libgo_cv_lib_sockets -lnsl"])])
+   unset ac_cv_func_gethostbyname
+   LIBS=$libgo_old_libs
+])
+NET_LIBS="$libgo_cv_lib_sockets"
+AC_SUBST(NET_LIBS)
+
 dnl Test whether the compiler supports the -pthread option.
 AC_CACHE_CHECK([whether -pthread is supported],
-[ac_cv_libgo_pthread_supported],
+[libgo_cv_lib_pthread],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -pthread"
 AC_COMPILE_IFELSE([[int i;]],
-[ac_cv_libgo_pthread_supported=yes],
-[ac_cv_libgo_pthread_supported=no])
+[libgo_cv_lib_pthread=yes],
+[libgo_cv_lib_pthread=no])
 CFLAGS=$CFLAGS_hold])
 PTHREAD_CFLAGS=
-if test "$ac_cv_libgo_pthread_supported" = yes; then
+if test "$libgo_cv_lib_pthread" = yes; then
   PTHREAD_CFLAGS=-pthread
 fi
 AC_SUBST(PTHREAD_CFLAGS)
@@ -230,15 +285,15 @@ 
 dnl For x86 we want to use the -minline-all-stringops option to avoid
 dnl forcing a stack split when calling memcpy and friends.
 AC_CACHE_CHECK([whether compiler supports -minline-all-stringops],
-[ac_cv_libgo_compiler_supports_inline_all_stringops],
+[libgo_cv_c_stringops],
 [CFLAGS_hold=$CFLAGS
 CFLAGS="$CFLAGS -minline-all-stringops"
 AC_COMPILE_IFELSE([int i;],
-[ac_cv_libgo_compiler_supports_inline_all_stringops=yes],
-[ac_cv_libgo_compiler_supports_inline_all_stringops=no])
+[libgo_cv_c_stringops=yes],
+[libgo_cv_c_stringops=no])
 CFLAGS=$CFLAGS_hold])
 STRINGOPS_FLAG=
-if test "$ac_cv_libgo_compiler_supports_inline_all_stringops" = yes; then
+if test "$libgo_cv_c_stringops" = yes; then
   STRINGOPS_FLAG=-minline-all-stringops
 fi
 AC_SUBST(STRINGOPS_FLAG)
diff -r 42077303a629 libgo/go/debug/proc/proc_solaris.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/go/debug/proc/proc_solaris.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,17 @@ 
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package proc
+
+import "os"
+
+// Process tracing is not supported on Solaris yet.
+
+func Attach(pid int) (Process, os.Error) {
+	return nil, os.NewError("debug/proc not implemented on Solaris")
+}
+
+func ForkExec(argv0 string, argv []string, envv []string, dir string, fd []*os.File) (Process, os.Error) {
+	return Attach(0)
+}
diff -r 42077303a629 libgo/go/debug/proc/regs_solaris_386.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/go/debug/proc/regs_solaris_386.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,5 @@ 
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package proc
diff -r 42077303a629 libgo/go/debug/proc/regs_solaris_amd64.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/go/debug/proc/regs_solaris_amd64.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,5 @@ 
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package proc
diff -r 42077303a629 libgo/go/debug/proc/regs_solaris_sparc.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/go/debug/proc/regs_solaris_sparc.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,5 @@ 
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package proc
diff -r 42077303a629 libgo/go/debug/proc/regs_solaris_sparcv9.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/go/debug/proc/regs_solaris_sparcv9.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,5 @@ 
+// Copyright 2011 The Go Authors.  All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package proc
diff -r 42077303a629 libgo/syscalls/syscall_solaris.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/syscall_solaris.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,7 @@ 
+// syscall_solaris.go -- Solaris 2 specific syscall interface.
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
diff -r 42077303a629 libgo/syscalls/syscall_solaris_386.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/syscall_solaris_386.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,19 @@ 
+// syscall_solaris_386.go -- Solaris/x86 specific support
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+import "unsafe"
+
+const ARCH = "386"
+
+// FIXME: ptrace(3C) has this, but exec.go expects the next.
+//func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace")
+
+func libc_ptrace(request int, pid Pid_t, addr uintptr, data *byte) int __asm__ ("ptrace")
+
+var dummy *byte
+const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
diff -r 42077303a629 libgo/syscalls/syscall_solaris_amd64.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/syscall_solaris_amd64.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,23 @@ 
+// syscall_solaris_amd64.go -- Solaris/x64 specific support
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
+
+import "unsafe"
+
+const ARCH = "amd64"
+
+// FIXME: ptrace(3C) has this, but exec.go expects the next.
+//func libc_ptrace(request int, pid Pid_t, addr int, data int) int __asm__ ("ptrace")
+
+// 64-bit ptrace(3C) doesn't exist
+func libc_ptrace(request int, pid Pid_t, addr uintptr, data *byte) int {
+	errno := ENOSYS
+	return -1
+}
+
+var dummy *byte
+const sizeofPtr uintptr = uintptr(unsafe.Sizeof(dummy))
diff -r 42077303a629 libgo/syscalls/syscall_solaris_sparc.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/syscall_solaris_sparc.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,7 @@ 
+// syscall_solaris_sparc.go -- Solaris SPARC specific support
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall
diff -r 42077303a629 libgo/syscalls/syscall_solaris_sparcv9.go
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/syscall_solaris_sparcv9.go	Tue Jan 11 22:16:49 2011 -0800
@@ -0,0 +1,7 @@ 
+// syscall_solaris_v9.go -- Solaris sparc9v specific support
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package syscall