diff mbox series

libgo patch committed: Solaris fixes

Message ID CAOyqgcVeDQofKauu5rP1Kp2u4L8=Rr4r8kA3Wb-Xt09shmZnDQ@mail.gmail.com
State New
Headers show
Series libgo patch committed: Solaris fixes | expand

Commit Message

Ian Lance Taylor Jan. 21, 2019, 11:05 p.m. UTC
This libgo patch fixes the build and some tests for Solaris after the
recent update to 1.12beta2.  It also changes c-archive mode to fetch
argc/argv/env from /proc, which fixes it to work instead of crashing
as it did before.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu and x86_64-sun-solaris2.11.  Committed to
mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 268129)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -1,4 +1,4 @@ 
-e7427654f3af83e1feea727a62a97172d7721403
+0c870ba6b3b43e0e56231f40c56b58dad0e36d9e
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
Index: libgo/Makefile.am
===================================================================
--- libgo/Makefile.am	(revision 268084)
+++ libgo/Makefile.am	(working copy)
@@ -1082,7 +1082,7 @@  $(eval $(call PACKAGE_template,internal/
 internal_x_net_lif_lo = \
 	internal/x/net/lif.lo
 internal_x_net_lif_check = \
-	internal_org/x/net/lif/check
+	internal/x/net/lif/check
 
 endif
 
Index: libgo/Makefile.in
===================================================================
--- libgo/Makefile.in	(revision 268084)
+++ libgo/Makefile.in	(working copy)
@@ -1131,7 +1131,7 @@  extra_check_libs_cmd_vet_internal_cfg =
 @LIBGO_IS_SOLARIS_TRUE@	internal/x/net/lif.lo
 
 @LIBGO_IS_SOLARIS_TRUE@internal_x_net_lif_check = \
-@LIBGO_IS_SOLARIS_TRUE@	internal_org/x/net/lif/check
+@LIBGO_IS_SOLARIS_TRUE@	internal/x/net/lif/check
 
 TPACKAGES = $(shell cat $(srcdir)/check-packages.txt)
 TEST_PACKAGES = $(addsuffix /check,$(TPACKAGES)) \
Index: libgo/go/internal/x/net/lif/syscall.go
===================================================================
--- libgo/go/internal/x/net/lif/syscall.go	(revision 268084)
+++ libgo/go/internal/x/net/lif/syscall.go	(working copy)
@@ -11,18 +11,12 @@  import (
 	"unsafe"
 )
 
-//go:cgo_import_dynamic libc_ioctl ioctl "libc.so"
-
-//go:linkname procIoctl libc_ioctl
-
-var procIoctl uintptr
-
-func sysvicall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (uintptr, uintptr, syscall.Errno)
+//extern __go_ioctl_ptr
+func libc_ioctl(int32, int32, unsafe.Pointer) int32
 
 func ioctl(s, ioc uintptr, arg unsafe.Pointer) error {
-	_, _, errno := sysvicall6(uintptr(unsafe.Pointer(&procIoctl)), 3, s, ioc, uintptr(arg), 0, 0, 0)
-	if errno != 0 {
-		return error(errno)
+	if libc_ioctl(int32(s), int32(ioc), arg) < 0 {
+		return syscall.GetErrno()
 	}
 	return nil
 }
Index: libgo/go/internal/x/net/lif/zsys_solaris.go
===================================================================
--- libgo/go/internal/x/net/lif/zsys_solaris.go	(nonexistent)
+++ libgo/go/internal/x/net/lif/zsys_solaris.go	(working copy)
@@ -0,0 +1,101 @@ 
+// Created by cgo -godefs - DO NOT EDIT
+// cgo -godefs defs_solaris.go
+
+package lif
+
+import "unsafe"
+
+const (
+	sysAF_UNSPEC = 0x0
+	sysAF_INET   = 0x2
+	sysAF_INET6  = 0x1a
+
+	sysSOCK_DGRAM = 0x1
+)
+
+type sockaddrStorage struct {
+	Family     uint16
+	X_ss_pad1  [6]int8
+	X_ss_align float64
+	X_ss_pad2  [240]int8
+}
+
+const (
+	sysLIFC_NOXMIT          = 0x1
+	sysLIFC_EXTERNAL_SOURCE = 0x2
+	sysLIFC_TEMPORARY       = 0x4
+	sysLIFC_ALLZONES        = 0x8
+	sysLIFC_UNDER_IPMP      = 0x10
+	sysLIFC_ENABLED         = 0x20
+
+	sysSIOCGLIFADDR    = -0x3f87968f
+	sysSIOCGLIFDSTADDR = -0x3f87968d
+	sysSIOCGLIFFLAGS   = -0x3f87968b
+	sysSIOCGLIFMTU     = -0x3f879686
+	sysSIOCGLIFNETMASK = -0x3f879683
+	sysSIOCGLIFMETRIC  = -0x3f879681
+	sysSIOCGLIFNUM     = -0x3ff3967e
+	sysSIOCGLIFINDEX   = -0x3f87967b
+	sysSIOCGLIFSUBNET  = -0x3f879676
+	sysSIOCGLIFLNKINFO = -0x3f879674
+	sysSIOCGLIFCONF    = -0x3fef965b
+	sysSIOCGLIFHWADDR  = -0x3f879640
+)
+
+const (
+	sysIFF_UP          = 0x1
+	sysIFF_BROADCAST   = 0x2
+	sysIFF_DEBUG       = 0x4
+	sysIFF_LOOPBACK    = 0x8
+	sysIFF_POINTOPOINT = 0x10
+	sysIFF_NOTRAILERS  = 0x20
+	sysIFF_RUNNING     = 0x40
+	sysIFF_NOARP       = 0x80
+	sysIFF_PROMISC     = 0x100
+	sysIFF_ALLMULTI    = 0x200
+	sysIFF_INTELLIGENT = 0x400
+	sysIFF_MULTICAST   = 0x800
+	sysIFF_MULTI_BCAST = 0x1000
+	sysIFF_UNNUMBERED  = 0x2000
+	sysIFF_PRIVATE     = 0x8000
+)
+
+const (
+	sizeofLifnum       = 0xc
+	sizeofLifreq       = 0x178
+	sizeofLifconf      = 0x18
+	sizeofLifIfinfoReq = 0x10
+)
+
+type lifnum struct {
+	Family    uint16
+	Flags     int32
+	Count     int32
+}
+
+type lifreq struct {
+	Name   [32]int8
+	Lifru1 [4]byte
+	Type   uint32
+	Lifru  [336]byte
+}
+
+type lifconf struct {
+	Family    uint16
+	Flags     int32
+	Len       int32
+	Lifcu     [unsafe.Sizeof(unsafe.Pointer(nil))]byte
+}
+
+type lifIfinfoReq struct {
+	Maxhops      uint8
+	Reachtime    uint32
+	Reachretrans uint32
+	Maxmtu       uint32
+}
+
+const (
+	sysIFT_IPV4 = 0xc8
+	sysIFT_IPV6 = 0xc9
+	sysIFT_6TO4 = 0xca
+)
Index: libgo/go/internal/x/net/lif/zsys_solaris_amd64.go
===================================================================
--- libgo/go/internal/x/net/lif/zsys_solaris_amd64.go	(revision 268084)
+++ libgo/go/internal/x/net/lif/zsys_solaris_amd64.go	(nonexistent)
@@ -1,103 +0,0 @@ 
-// Created by cgo -godefs - DO NOT EDIT
-// cgo -godefs defs_solaris.go
-
-package lif
-
-const (
-	sysAF_UNSPEC = 0x0
-	sysAF_INET   = 0x2
-	sysAF_INET6  = 0x1a
-
-	sysSOCK_DGRAM = 0x1
-)
-
-type sockaddrStorage struct {
-	Family     uint16
-	X_ss_pad1  [6]int8
-	X_ss_align float64
-	X_ss_pad2  [240]int8
-}
-
-const (
-	sysLIFC_NOXMIT          = 0x1
-	sysLIFC_EXTERNAL_SOURCE = 0x2
-	sysLIFC_TEMPORARY       = 0x4
-	sysLIFC_ALLZONES        = 0x8
-	sysLIFC_UNDER_IPMP      = 0x10
-	sysLIFC_ENABLED         = 0x20
-
-	sysSIOCGLIFADDR    = -0x3f87968f
-	sysSIOCGLIFDSTADDR = -0x3f87968d
-	sysSIOCGLIFFLAGS   = -0x3f87968b
-	sysSIOCGLIFMTU     = -0x3f879686
-	sysSIOCGLIFNETMASK = -0x3f879683
-	sysSIOCGLIFMETRIC  = -0x3f879681
-	sysSIOCGLIFNUM     = -0x3ff3967e
-	sysSIOCGLIFINDEX   = -0x3f87967b
-	sysSIOCGLIFSUBNET  = -0x3f879676
-	sysSIOCGLIFLNKINFO = -0x3f879674
-	sysSIOCGLIFCONF    = -0x3fef965b
-	sysSIOCGLIFHWADDR  = -0x3f879640
-)
-
-const (
-	sysIFF_UP          = 0x1
-	sysIFF_BROADCAST   = 0x2
-	sysIFF_DEBUG       = 0x4
-	sysIFF_LOOPBACK    = 0x8
-	sysIFF_POINTOPOINT = 0x10
-	sysIFF_NOTRAILERS  = 0x20
-	sysIFF_RUNNING     = 0x40
-	sysIFF_NOARP       = 0x80
-	sysIFF_PROMISC     = 0x100
-	sysIFF_ALLMULTI    = 0x200
-	sysIFF_INTELLIGENT = 0x400
-	sysIFF_MULTICAST   = 0x800
-	sysIFF_MULTI_BCAST = 0x1000
-	sysIFF_UNNUMBERED  = 0x2000
-	sysIFF_PRIVATE     = 0x8000
-)
-
-const (
-	sizeofLifnum       = 0xc
-	sizeofLifreq       = 0x178
-	sizeofLifconf      = 0x18
-	sizeofLifIfinfoReq = 0x10
-)
-
-type lifnum struct {
-	Family    uint16
-	Pad_cgo_0 [2]byte
-	Flags     int32
-	Count     int32
-}
-
-type lifreq struct {
-	Name   [32]int8
-	Lifru1 [4]byte
-	Type   uint32
-	Lifru  [336]byte
-}
-
-type lifconf struct {
-	Family    uint16
-	Pad_cgo_0 [2]byte
-	Flags     int32
-	Len       int32
-	Pad_cgo_1 [4]byte
-	Lifcu     [8]byte
-}
-
-type lifIfinfoReq struct {
-	Maxhops      uint8
-	Pad_cgo_0    [3]byte
-	Reachtime    uint32
-	Reachretrans uint32
-	Maxmtu       uint32
-}
-
-const (
-	sysIFT_IPV4 = 0xc8
-	sysIFT_IPV6 = 0xc9
-	sysIFT_6TO4 = 0xca
-)
Index: libgo/go/runtime/signal_unix.go
===================================================================
--- libgo/go/runtime/signal_unix.go	(revision 268084)
+++ libgo/go/runtime/signal_unix.go	(working copy)
@@ -441,7 +441,10 @@  func raisebadsignal(sig uint32, c *sigct
 	//
 	// On FreeBSD, the libthr sigaction code prevents
 	// this from working so we fall through to raise.
-	if GOOS != "freebsd" && (isarchive || islibrary) && handler == _SIG_DFL && c.sigcode() != _SI_USER {
+	//
+	// The argument above doesn't hold for SIGPIPE, which won't
+	// necessarily be re-raised if we return.
+	if GOOS != "freebsd" && (isarchive || islibrary) && handler == _SIG_DFL && c.sigcode() != _SI_USER && sig != _SIGPIPE {
 		return
 	}
 
Index: libgo/runtime/go-libmain.c
===================================================================
--- libgo/runtime/go-libmain.c	(revision 268078)
+++ libgo/runtime/go-libmain.c	(working copy)
@@ -11,11 +11,129 @@ 
 #include <stdlib.h>
 #include <time.h>
 #include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
 
 #include "runtime.h"
 #include "array.h"
 #include "arch.h"
 
+#if defined(__sun) && defined(__SVR4)
+
+/* Read a file into memory on Solaris, returning an malloc'ed buffer
+   and setting *SIZE to its size.  */
+
+static char *
+read_file (const char *fn, size_t *size)
+{
+  struct stat st;
+  char *buf;
+  int o;
+  ssize_t got;
+
+  if (stat (fn, &st) < 0)
+    return NULL;
+  buf = malloc ((size_t) st.st_size);
+  if (buf == NULL)
+    return NULL;
+  o = open (fn, O_RDONLY);
+  if (o < 0)
+    {
+      free (buf);
+      return NULL;
+    }
+  got = read (o, buf, st.st_size);
+  close (o);
+  if (got != st.st_size)
+    {
+      free (buf);
+      return NULL;
+    }
+
+  *size = (size_t) got;
+  return buf;
+}
+
+/* On Solaris we don't get passed argc/argv, but we can fetch it from
+   /proc/PID/cmdline.  */
+
+static void
+read_cmdline (int *argc, char ***argv)
+{
+  pid_t pid;
+  char fn[50];
+  char *argbuf;
+  size_t argsize;
+  char *envbuf;
+  size_t envsize;
+  char *p;
+  int i;
+  int ac;
+
+  *argc = 0;
+  *argv = NULL;
+
+  pid = getpid ();
+  snprintf (fn, sizeof fn, "/proc/%ld/cmdline", (long) pid);
+  argbuf = read_file (fn, &argsize);
+  if (argbuf == NULL)
+    return;
+
+  snprintf (fn, sizeof fn, "/proc/%ld/environ", (long) pid);
+  envbuf = read_file (fn, &envsize);
+  if (envbuf == NULL)
+    {
+      free (argbuf);
+      return;
+    }
+
+  i = 0;
+  for (p = argbuf; p < argbuf + argsize; p++)
+    if (*p == '\0')
+      ++i;
+  ac = i;
+  ++i; // For trailing NULL.
+  for (p = envbuf; p < envbuf + envsize; p++)
+    if (*p == '\0')
+      ++i;
+  ++i; // For trailing NULL.
+
+  *argv = (char **) malloc (i * sizeof (char *));
+  if (*argv == NULL)
+    {
+      free (argbuf);
+      free (envbuf);
+      return;
+    }
+
+  *argc = ac;
+  (*argv)[0] = argbuf;
+  i = 0;
+  for (p = argbuf; p < argbuf + argsize; p++)
+    {
+      if (*p == '\0')
+	{
+	  ++i;
+	  (*argv)[i] = p + 1;
+	}
+    }
+  (*argv)[i] = NULL;
+  ++i;
+  (*argv)[i] = envbuf;
+  for (p = envbuf; p < envbuf + envsize; p++)
+    {
+      if (*p == '\0')
+	{
+	  ++i;
+	  (*argv)[i] = p + 1;
+	}
+    }
+  (*argv)[i] = NULL;
+}
+
+#endif /* defined(__sun) && defined(__SVR4) */
+
 /* This is used when building a standalone Go library using the Go
    command's -buildmode=c-archive or -buildmode=c-shared option.  It
    starts up the Go code as a global constructor but does not take any
@@ -64,6 +182,10 @@  __go_init (int argc, char **argv, char**
   struct args *a;
   pthread_t tid;
 
+#if defined(__sun) && defined(__SVR4)
+  read_cmdline (&argc, &argv);
+#endif
+
   runtime_isarchive = true;
 
   setIsCgo ();