libgo: fix build on AIX

Since aix/ppc64 has been added to GC toolchain, a mix between new and
old files were created in gcc toolchain.
This commit corrects this merge for aix/ppc64 and aix/ppc.

Change-Id: I237ed6a3671996dce47163bd8afe7d6c6d7efb48
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/167658
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/libgo/go/archive/tar/stat_actime1.go b/libgo/go/archive/tar/stat_actime1.go
index e2c79a5..2a7f7f3 100644
--- a/libgo/go/archive/tar/stat_actime1.go
+++ b/libgo/go/archive/tar/stat_actime1.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build hurd linux dragonfly openbsd solaris
+// +build aix hurd linux dragonfly openbsd solaris
 
 package tar
 
diff --git a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
index 2831975..a14362b 100644
--- a/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
+++ b/libgo/go/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go
@@ -35,7 +35,9 @@
 	writeLock lockType = syscall.F_WRLCK
 )
 
-type inode = uint64 // type of syscall.Stat_t.Ino
+// type of syscall.Stat_t.Ino for 64 bits architectures.
+// For 32 bits architecture, it's easier to cast it instead.
+type inode = uint64
 
 type inodeLock struct {
 	owner File
@@ -59,7 +61,7 @@
 	if err != nil {
 		return err
 	}
-	ino := fi.Sys().(*syscall.Stat_t).Ino
+	ino := uint64(fi.Sys().(*syscall.Stat_t).Ino)
 
 	mu.Lock()
 	if i, dup := inodes[f]; dup && i != ino {
diff --git a/libgo/go/internal/syscall/unix/at_largefile.go b/libgo/go/internal/syscall/unix/at_largefile.go
index 5318d23..82e0dcf 100644
--- a/libgo/go/internal/syscall/unix/at_largefile.go
+++ b/libgo/go/internal/syscall/unix/at_largefile.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix hurd linux solaris,386 solaris,sparc
+// +build hurd linux solaris,386 solaris,sparc
 
 package unix
 
diff --git a/libgo/go/internal/syscall/unix/at_regfile.go b/libgo/go/internal/syscall/unix/at_regfile.go
index 004c801..14fdb70 100644
--- a/libgo/go/internal/syscall/unix/at_regfile.go
+++ b/libgo/go/internal/syscall/unix/at_regfile.go
@@ -2,7 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build !aix
 // +build !hurd
 // +build !linux
 // +build !solaris !386
diff --git a/libgo/go/internal/syscall/unix/ioctl_aix.go b/libgo/go/internal/syscall/unix/ioctl_aix.go
index 19d56c3..af105d6 100644
--- a/libgo/go/internal/syscall/unix/ioctl_aix.go
+++ b/libgo/go/internal/syscall/unix/ioctl_aix.go
@@ -9,17 +9,12 @@
 	"unsafe"
 )
 
-//go:cgo_import_dynamic libc_ioctl ioctl "libc.a/shr_64.o"
-//go:linkname libc_ioctl libc_ioctl
-var libc_ioctl uintptr
-
-// Implemented in syscall/syscall_aix.go.
-func syscall6(trap, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno)
+//extern __go_ioctl_ptr
+func ioctl(int32, int32, unsafe.Pointer) int32
 
 func Ioctl(fd int, cmd int, args uintptr) (err error) {
-	_, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_ioctl)), 3, uintptr(fd), uintptr(cmd), uintptr(args), 0, 0, 0)
-	if e1 != 0 {
-		err = e1
+	if ioctl(int32(fd), int32(cmd), unsafe.Pointer(args)) < 0 {
+		return syscall.GetErrno()
 	}
 	return
 }
diff --git a/libgo/go/net/interface_aix.go b/libgo/go/net/interface_aix.go
index 9a8b5bb..1fe9bba 100644
--- a/libgo/go/net/interface_aix.go
+++ b/libgo/go/net/interface_aix.go
@@ -32,6 +32,8 @@
 const _RTAX_IFA = 5
 const _RTAX_MAX = 8
 
+const _SIOCGIFMTU = -0x3fd796aa
+
 func getIfList() ([]byte, error) {
 	needed, err := syscall.Getkerninfo(_KINFO_RT_IFLIST, 0, 0, 0)
 	if err != nil {
@@ -62,7 +64,7 @@
 		}
 		if ifm.Type == syscall.RTM_IFINFO {
 			if ifindex == 0 || ifindex == int(ifm.Index) {
-				sdl := (*rawSockaddrDatalink)(unsafe.Pointer(&tab[syscall.SizeofIfMsghdr]))
+				sdl := (*rawSockaddrDatalink)(unsafe.Pointer(&tab[unsafe.Sizeof(syscall.IfMsgHdr)]))
 
 				ifi := &Interface{Index: int(ifm.Index), Flags: linkFlags(ifm.Flags)}
 				ifi.Name = string(sdl.Data[:sdl.Nlen])
@@ -75,7 +77,7 @@
 				if err != nil {
 					return nil, err
 				}
-				err = unix.Ioctl(sock, syscall.SIOCGIFMTU, uintptr(unsafe.Pointer(ifr)))
+				err = unix.Ioctl(sock, _SIOCGIFMTU, uintptr(unsafe.Pointer(ifr)))
 				if err != nil {
 					return nil, err
 				}
@@ -131,7 +133,7 @@
 		if ifm.Type == syscall.RTM_NEWADDR {
 			if ifi == nil || ifi.Index == int(ifm.Index) {
 				mask := ifm.Addrs
-				off := uint(syscall.SizeofIfMsghdr)
+				off := uint(unsafe.Sizeof(syscall.IfMsgHdr))
 
 				var iprsa, nmrsa *syscall.RawSockaddr
 				for i := uint(0); i < _RTAX_MAX; i++ {
diff --git a/libgo/go/net/interface_stub.go b/libgo/go/net/interface_stub.go
index 0b3580e..d8afd5e 100644
--- a/libgo/go/net/interface_stub.go
+++ b/libgo/go/net/interface_stub.go
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build aix nacl hurd js,wasm
+// +build nacl hurd js,wasm
 
 package net
 
diff --git a/libgo/go/net/sockoptip_aix.go b/libgo/go/net/sockoptip_aix.go
deleted file mode 100644
index 1e28fe6..0000000
--- a/libgo/go/net/sockoptip_aix.go
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2017 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 net
-
-import "syscall"
-
-func setIPv4MulticastInterface(fd *netFD, ifi *Interface) error {
-	return syscall.ENOPROTOOPT
-}
-
-func setIPv4MulticastLoopback(fd *netFD, v bool) error {
-	return syscall.ENOPROTOOPT
-}
diff --git a/libgo/go/os/dir_gccgo.go b/libgo/go/os/dir_gccgo.go
index 60f70aa..ad77a40 100644
--- a/libgo/go/os/dir_gccgo.go
+++ b/libgo/go/os/dir_gccgo.go
@@ -16,9 +16,6 @@
 //extern pathconf
 func libc_pathconf(*byte, int) int
 
-//extern fdopendir
-func libc_fdopendir(int32) *syscall.DIR
-
 func clen(n []byte) int {
 	for i := 0; i < len(n); i++ {
 		if n[i] == 0 {
diff --git a/libgo/go/os/dir_libc64_gccgo.go b/libgo/go/os/dir_libc64_gccgo.go
index dc3ba7f..3582243 100644
--- a/libgo/go/os/dir_libc64_gccgo.go
+++ b/libgo/go/os/dir_libc64_gccgo.go
@@ -10,3 +10,6 @@
 
 //extern closedir64
 func libc_closedir(*syscall.DIR) int
+
+//extern fdopendir64
+func libc_fdopendir(int32) *syscall.DIR
diff --git a/libgo/go/os/dir_libc_gccgo.go b/libgo/go/os/dir_libc_gccgo.go
index b46eb4c..a3be43b 100644
--- a/libgo/go/os/dir_libc_gccgo.go
+++ b/libgo/go/os/dir_libc_gccgo.go
@@ -10,3 +10,6 @@
 
 //extern closedir
 func libc_closedir(*syscall.DIR) int
+
+//extern fdopendir
+func libc_fdopendir(int32) *syscall.DIR
diff --git a/libgo/go/os/sys_aix.go b/libgo/go/os/sys_aix.go
deleted file mode 100644
index 53a40f2..0000000
--- a/libgo/go/os/sys_aix.go
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018 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 os
-
-import "syscall"
-
-// gethostname syscall cannot be used because it also returns the domain.
-// Therefore, hostname is retrieve with uname syscall and the Nodename field.
-
-func hostname() (name string, err error) {
-	var u syscall.Utsname
-	if errno := syscall.Uname(&u); errno != nil {
-		return "", NewSyscallError("uname", errno)
-	}
-	b := make([]byte, len(u.Nodename))
-	i := 0
-	for ; i < len(u.Nodename); i++ {
-		if u.Nodename[i] == 0 {
-			break
-		}
-		b[i] = byte(u.Nodename[i])
-	}
-	return string(b[:i]), nil
-}
diff --git a/libgo/go/runtime/malloc.go b/libgo/go/runtime/malloc.go
index b6a7ee1..c0b4caa 100644
--- a/libgo/go/runtime/malloc.go
+++ b/libgo/go/runtime/malloc.go
@@ -218,7 +218,7 @@
 	// we further limit it to 31 bits.
 	//
 	// WebAssembly currently has a limit of 4GB linear memory.
-	heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosAix))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 60*sys.GoosAix
+	heapAddrBits = (_64bit*(1-sys.GoarchWasm)*(1-sys.GoosAix))*48 + (1-_64bit+sys.GoarchWasm)*(32-(sys.GoarchMips+sys.GoarchMipsle)) + 60*(sys.GoosAix*_64bit)
 
 	// maxAlloc is the maximum size of an allocation. On 64-bit,
 	// it's theoretically possible to allocate 1<<heapAddrBits bytes. On
@@ -259,7 +259,7 @@
 	// logHeapArenaBytes is log_2 of heapArenaBytes. For clarity,
 	// prefer using heapArenaBytes where possible (we need the
 	// constant to compute some other constants).
-	logHeapArenaBytes = (6+20)*(_64bit*(1-sys.GoosWindows)*(1-sys.GoosAix)) + (2+20)*(_64bit*sys.GoosWindows) + (2+20)*(1-_64bit) + (8+20)*sys.GoosAix
+	logHeapArenaBytes = (6+20)*(_64bit*(1-sys.GoosWindows)*(1-sys.GoosAix)) + (2+20)*(_64bit*sys.GoosWindows) + (2+20)*(1-_64bit) + (8+20)*(sys.GoosAix*_64bit)
 
 	// heapArenaBitmapBytes is the size of each heap arena's bitmap.
 	heapArenaBitmapBytes = heapArenaBytes / (sys.PtrSize * 8 / 2)
@@ -282,7 +282,7 @@
 	//
 	// We use the L1 map on aix/ppc64 to keep the same L2 value
 	// as on Linux.
-	arenaL1Bits = 6*(_64bit*sys.GoosWindows) + 12*sys.GoosAix
+	arenaL1Bits = 6*(_64bit*sys.GoosWindows) + 12*(sys.GoosAix*_64bit)
 
 	// arenaL2Bits is the number of bits of the arena number
 	// covered by the second level arena index.
diff --git a/libgo/go/runtime/mem_gccgo.go b/libgo/go/runtime/mem_gccgo.go
index 44f4648..9874678 100644
--- a/libgo/go/runtime/mem_gccgo.go
+++ b/libgo/go/runtime/mem_gccgo.go
@@ -187,6 +187,11 @@
 func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) {
 	mSysStatInc(sysStat, n)
 
+	if GOOS == "aix" {
+		// AIX does not allow mapping a range that is already mapped.
+		// So always unmap first even if it is already unmapped.
+		munmap(v, n)
+	}
 	p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, mmapFD, 0)
 	if err == _ENOMEM {
 		throw("runtime: out of memory")
diff --git a/libgo/go/runtime/netpoll_aix.go b/libgo/go/runtime/netpoll_aix.go
index 86c3e96..70bf9eb 100644
--- a/libgo/go/runtime/netpoll_aix.go
+++ b/libgo/go/runtime/netpoll_aix.go
@@ -37,7 +37,6 @@
 const _POLLOUT = 0x0002
 const _POLLHUP = 0x2000
 const _POLLERR = 0x4000
-const _O_NONBLOCK = 0x4
 
 var (
 	pfds           []pollfd
diff --git a/libgo/go/runtime/os_aix.go b/libgo/go/runtime/os_aix.go
index 1003616..9211f21 100644
--- a/libgo/go/runtime/os_aix.go
+++ b/libgo/go/runtime/os_aix.go
@@ -62,12 +62,19 @@
 		if clock_gettime(_CLOCK_REALTIME, &ts) != 0 {
 			throw("clock_gettime")
 		}
-		ts.tv_sec += ns / 1e9
-		ts.tv_nsec += ns % 1e9
-		if ts.tv_nsec >= 1e9 {
-			ts.tv_sec++
-			ts.tv_nsec -= 1e9
+
+		sec := int64(ts.tv_sec) + ns/1e9
+		nsec := int64(ts.tv_nsec) + ns%1e9
+		if nsec >= 1e9 {
+			sec++
+			nsec -= 1e9
 		}
+		if sec != int64(timespec_sec_t(sec)) {
+			// Handle overflows (timespec_sec_t is 32-bit in 32-bit applications)
+			sec = 1<<31 - 1
+		}
+		ts.tv_sec = timespec_sec_t(sec)
+		ts.tv_nsec = timespec_nsec_t(nsec)
 
 		if sem_timedwait((*semt)(unsafe.Pointer(_m_.mos.waitsema)), &ts) != 0 {
 			err := errno()
diff --git a/libgo/go/runtime/stubs2.go b/libgo/go/runtime/stubs2.go
index 304c8e4..1cb910c 100644
--- a/libgo/go/runtime/stubs2.go
+++ b/libgo/go/runtime/stubs2.go
@@ -7,7 +7,6 @@
 // +build !nacl
 // +build !js
 // +build !darwin
-// +build !aix
 
 package runtime
 
diff --git a/libgo/go/runtime/timestub2.go b/libgo/go/runtime/timestub2.go
index 00c2c55..7a28603 100644
--- a/libgo/go/runtime/timestub2.go
+++ b/libgo/go/runtime/timestub2.go
@@ -5,8 +5,6 @@
 // +build !darwin
 // +build !windows
 // +build !freebsd
-// +build !aix
-
 package runtime
 
 func walltime() (sec int64, nsec int32)
diff --git a/libgo/go/syscall/exec_aix_test.go b/libgo/go/syscall/exec_aix_test.go
deleted file mode 100644
index 22b752c..0000000
--- a/libgo/go/syscall/exec_aix_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2015 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.
-
-// +build aix
-
-package syscall
-
-import "unsafe"
-
-//go:cgo_import_dynamic libc_Getpgid getpgid "libc.a/shr_64.o"
-//go:cgo_import_dynamic libc_Getpgrp getpgrp "libc.a/shr_64.o"
-
-//go:linkname libc_Getpgid libc_Getpgid
-//go:linkname libc_Getpgrp libc_Getpgrp
-
-var (
-	libc_Getpgid,
-	libc_Getpgrp libcFunc
-)
-
-func Getpgid(pid int) (pgid int, err error) {
-	r0, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_Getpgid)), 1, uintptr(pid), 0, 0, 0, 0, 0)
-	pgid = int(r0)
-	if e1 != 0 {
-		err = e1
-	}
-	return
-}
-
-func Getpgrp() (pgrp int) {
-	r0, _, _ := syscall6(uintptr(unsafe.Pointer(&libc_Getpgrp)), 0, 0, 0, 0, 0, 0, 0)
-	pgrp = int(r0)
-	return
-}
-
-var Ioctl = ioctl
diff --git a/libgo/go/syscall/exec_unix.go b/libgo/go/syscall/exec_unix.go
index bad2ce4..ec21f80 100644
--- a/libgo/go/syscall/exec_unix.go
+++ b/libgo/go/syscall/exec_unix.go
@@ -299,7 +299,6 @@
 
 // execveLibc is non-nil on OS using libc syscall, set to execve in exec_libc.go; this
 // avoids a build dependency for other platforms.
-var execveLibc func(path uintptr, argv uintptr, envp uintptr) Errno
 var execveDarwin func(path *byte, argv **byte, envp **byte) error
 
 // Exec invokes the execve(2) system call.
@@ -321,10 +320,7 @@
 	var err1 error
 	if runtime.GOOS == "solaris" || runtime.GOOS == "aix" || runtime.GOOS == "hurd" {
 		// RawSyscall should never be used on Solaris or AIX.
-		err1 = execveLibc(
-			uintptr(unsafe.Pointer(argv0p)),
-			uintptr(unsafe.Pointer(&argvp[0])),
-			uintptr(unsafe.Pointer(&envvp[0])))
+		err1 = raw_execve(argv0p, &argvp[0], &envvp[0])
 	} else if runtime.GOOS == "darwin" {
 		// Similarly on Darwin.
 		err1 = execveDarwin(argv0p, &argvp[0], &envvp[0])
diff --git a/libgo/go/syscall/flock_aix.go b/libgo/go/syscall/flock_aix.go
deleted file mode 100644
index c9eab43..0000000
--- a/libgo/go/syscall/flock_aix.go
+++ /dev/null
@@ -1,18 +0,0 @@
-// Copyright 2018 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"
-
-// On AIX, there is no flock() system call.
-
-// FcntlFlock performs a fcntl syscall for the F_GETLK, F_SETLK or F_SETLKW command.
-func FcntlFlock(fd uintptr, cmd int, lk *Flock_t) (err error) {
-	_, _, e1 := syscall6(uintptr(unsafe.Pointer(&libc_fcntl)), 3, uintptr(fd), uintptr(cmd), uintptr(unsafe.Pointer(lk)), 0, 0, 0)
-	if e1 != 0 {
-		err = errnoErr(e1)
-	}
-	return
-}
diff --git a/libgo/go/syscall/libcall_aix.go b/libgo/go/syscall/libcall_aix.go
index 072f92a..8d9f59e 100644
--- a/libgo/go/syscall/libcall_aix.go
+++ b/libgo/go/syscall/libcall_aix.go
@@ -10,6 +10,9 @@
 	"unsafe"
 )
 
+// For exec_unix.go.
+const SYS_EXECVE = 0
+
 //sys	Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
 //open64at(dirfd _C_int, path *byte, flags _C_int, mode Mode_t) _C_int
 
@@ -139,3 +142,6 @@
 func Unlinkat(dirfd int, path string) (err error) {
 	return unlinkat(dirfd, path, 0)
 }
+
+//sys	Getkerninfo(op int32, where uintptr, size uintptr, arg int64) (i int32, err error)
+//getkerninfo(op _C_int, where *byte, size *byte, arg _C_long) _C_int
diff --git a/libgo/go/syscall/syscall_funcs.go b/libgo/go/syscall/syscall_funcs.go
new file mode 100644
index 0000000..4b1ee32
--- /dev/null
+++ b/libgo/go/syscall/syscall_funcs.go
@@ -0,0 +1,45 @@
+// Copyright 2009 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.
+
+// +build darwin dragonfly freebsd hurd linux netbsd openbsd solaris
+
+package syscall
+
+//extern __go_syscall6
+func syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) uintptr
+
+// Do a system call.  We look at the size of uintptr to see how to pass
+// the arguments, so that we don't pass a 64-bit value when the function
+// expects a 32-bit one.
+func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
+	Entersyscall()
+	SetErrno(0)
+	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
+	err = GetErrno()
+	Exitsyscall()
+	return r, 0, err
+}
+
+func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
+	Entersyscall()
+	SetErrno(0)
+	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
+	err = GetErrno()
+	Exitsyscall()
+	return r, 0, err
+}
+
+func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
+	SetErrno(0)
+	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
+	err = GetErrno()
+	return r, 0, err
+}
+
+func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
+	SetErrno(0)
+	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
+	err = GetErrno()
+	return r, 0, err
+}
diff --git a/libgo/go/syscall/syscall_funcs_stubs.go b/libgo/go/syscall/syscall_funcs_stubs.go
new file mode 100644
index 0000000..c68ab26
--- /dev/null
+++ b/libgo/go/syscall/syscall_funcs_stubs.go
@@ -0,0 +1,29 @@
+// Copyright 2010 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.
+
+// +build aix rtems
+
+// These are stubs.
+
+package syscall
+
+func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
+	z := -1
+	return uintptr(z), 0, ENOSYS
+}
+
+func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
+	z := -1
+	return uintptr(z), 0, ENOSYS
+}
+
+func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
+	z := -1
+	return uintptr(z), 0, ENOSYS
+}
+
+func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
+	z := -1
+	return uintptr(z), 0, ENOSYS
+}
diff --git a/libgo/go/syscall/syscall_stubs.go b/libgo/go/syscall/syscall_stubs.go
deleted file mode 100644
index 00288ee..0000000
--- a/libgo/go/syscall/syscall_stubs.go
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2010 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.
-
-// +build rtems
-
-// These are stubs.
-
-package syscall
-
-func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
-	z := -1
-	return uintptr(z), 0, uintptr(ENOSYS)
-}
-
-func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
-	z := -1
-	return uintptr(z), 0, uintptr(ENOSYS)
-}
-
-func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr) {
-	z := -1
-	return uintptr(z), 0, uintptr(ENOSYS)
-}
-
-func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr) {
-	z := -1
-	return uintptr(z), 0, uintptr(ENOSYS)
-}
diff --git a/libgo/go/syscall/syscall_unix.go b/libgo/go/syscall/syscall_unix.go
index b786dc5..ec8f343 100644
--- a/libgo/go/syscall/syscall_unix.go
+++ b/libgo/go/syscall/syscall_unix.go
@@ -19,9 +19,6 @@
 	Stderr = 2
 )
 
-//extern __go_syscall6
-func syscall6(trap uintptr, a1, a2, a3, a4, a5, a6 uintptr) uintptr
-
 const (
 	darwin64Bit    = runtime.GOOS == "darwin" && sizeofPtr == 8
 	dragonfly64Bit = runtime.GOOS == "dragonfly" && sizeofPtr == 8
@@ -29,41 +26,6 @@
 	solaris64Bit   = runtime.GOOS == "solaris" && sizeofPtr == 8
 )
 
-// Do a system call.  We look at the size of uintptr to see how to pass
-// the arguments, so that we don't pass a 64-bit value when the function
-// expects a 32-bit one.
-func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
-	Entersyscall()
-	SetErrno(0)
-	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
-	err = GetErrno()
-	Exitsyscall()
-	return r, 0, err
-}
-
-func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
-	Entersyscall()
-	SetErrno(0)
-	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
-	err = GetErrno()
-	Exitsyscall()
-	return r, 0, err
-}
-
-func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) {
-	SetErrno(0)
-	r := syscall6(trap, a1, a2, a3, 0, 0, 0)
-	err = GetErrno()
-	return r, 0, err
-}
-
-func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) {
-	SetErrno(0)
-	r := syscall6(trap, a1, a2, a3, a4, a5, a6)
-	err = GetErrno()
-	return r, 0, err
-}
-
 // clen returns the index of the first NULL byte in n or len(n) if n contains no NULL byte.
 func clen(n []byte) int {
 	for i := 0; i < len(n); i++ {
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index 418ba2c..c9dd8d4 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -1024,6 +1024,18 @@
       -e 's/ifi_change/Change/' \
     >> ${OUT}
 
+# The if_msghdr struct.
+grep '^type _if_msghdr ' gen-sysinfo.go | \
+    sed -e 's/_if_msghdr/IfMsgHdr/' \
+		-e 's/ifm_msglen/Msglen/' \
+		-e 's/ifm_version/Version/' \
+		-e 's/ifm_type/Type/' \
+		-e 's/ifm_addrs/Addrs/' \
+		-e 's/ifm_flags/Flags/' \
+		-e 's/ifm_index/Index/' \
+		-e 's/ifm_addrlen/Addrlen/' \
+		>> ${OUT}
+
 # The interface information types and flags.
 grep '^const _IFA' gen-sysinfo.go | \
     sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
diff --git a/libgo/runtime/go-varargs.c b/libgo/runtime/go-varargs.c
index cf033af..2b186ef 100644
--- a/libgo/runtime/go-varargs.c
+++ b/libgo/runtime/go-varargs.c
@@ -96,6 +96,8 @@
 
 #endif
 
+#ifdef HAVE_SYSCALL
+
 // __go_syscall6 is called by both the runtime and syscall packages.
 // We use uintptr_t to make sure that the types match, since the Go
 // and C "int" types are not the same.
@@ -106,3 +108,5 @@
 {
   return syscall (flag, a1, a2, a3, a4, a5, a6);
 }
+
+#endif