diff --git a/unix/asm.s b/unix/asm.s index d4ca868f..8ed2fdb9 100644 --- a/unix/asm.s +++ b/unix/asm.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" TEXT ·use(SB),NOSPLIT,$0 diff --git a/unix/asm_darwin_386.s b/unix/asm_darwin_386.s index f9338dad..8a727831 100644 --- a/unix/asm_darwin_386.s +++ b/unix/asm_darwin_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_darwin_amd64.s b/unix/asm_darwin_amd64.s index aa137680..6321421f 100644 --- a/unix/asm_darwin_amd64.s +++ b/unix/asm_darwin_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_dragonfly_386.s b/unix/asm_dragonfly_386.s index 68aa5e4d..7e55e0d3 100644 --- a/unix/asm_dragonfly_386.s +++ b/unix/asm_dragonfly_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_dragonfly_amd64.s b/unix/asm_dragonfly_amd64.s index 77b1bf92..d5ed6726 100644 --- a/unix/asm_dragonfly_amd64.s +++ b/unix/asm_dragonfly_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_freebsd_386.s b/unix/asm_freebsd_386.s index 1146f0bc..c9a0a260 100644 --- a/unix/asm_freebsd_386.s +++ b/unix/asm_freebsd_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_freebsd_amd64.s b/unix/asm_freebsd_amd64.s index d80fd12a..35172477 100644 --- a/unix/asm_freebsd_amd64.s +++ b/unix/asm_freebsd_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_freebsd_arm.s b/unix/asm_freebsd_arm.s index aca3f3f7..9227c875 100644 --- a/unix/asm_freebsd_arm.s +++ b/unix/asm_freebsd_arm.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_linux_386.s b/unix/asm_linux_386.s index 5d3ad9ad..4db29093 100644 --- a/unix/asm_linux_386.s +++ b/unix/asm_linux_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_linux_amd64.s b/unix/asm_linux_amd64.s index 0c8c7786..44e25c62 100644 --- a/unix/asm_linux_amd64.s +++ b/unix/asm_linux_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_linux_arm.s b/unix/asm_linux_arm.s index 4137b58f..cf0b5746 100644 --- a/unix/asm_linux_arm.s +++ b/unix/asm_linux_arm.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_netbsd_386.s b/unix/asm_netbsd_386.s index 682e4bd5..48bdcd76 100644 --- a/unix/asm_netbsd_386.s +++ b/unix/asm_netbsd_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_netbsd_amd64.s b/unix/asm_netbsd_amd64.s index e80eaddb..2ede05c7 100644 --- a/unix/asm_netbsd_amd64.s +++ b/unix/asm_netbsd_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_netbsd_arm.s b/unix/asm_netbsd_arm.s index 0b673a32..e8928571 100644 --- a/unix/asm_netbsd_arm.s +++ b/unix/asm_netbsd_arm.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_openbsd_386.s b/unix/asm_openbsd_386.s index 65b0e42f..00576f3c 100644 --- a/unix/asm_openbsd_386.s +++ b/unix/asm_openbsd_386.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_openbsd_amd64.s b/unix/asm_openbsd_amd64.s index 55aada19..790ef77f 100644 --- a/unix/asm_openbsd_amd64.s +++ b/unix/asm_openbsd_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + #include "textflag.h" // diff --git a/unix/asm_solaris_amd64.s b/unix/asm_solaris_amd64.s index f6121318..a33708f0 100644 --- a/unix/asm_solaris_amd64.s +++ b/unix/asm_solaris_amd64.s @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !gccgo + // // System calls for amd64, Solaris are implemented in runtime/syscall_solaris.goc // diff --git a/unix/gccgo.go b/unix/gccgo.go new file mode 100644 index 00000000..5fc9bc90 --- /dev/null +++ b/unix/gccgo.go @@ -0,0 +1,39 @@ +// 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 gccgo + +package unix + +import "syscall" + +// We can't use the gc-syntax .s files for gccgo. On the plus side +// much of the functionality can be written directly in Go. + +//extern gccgoRealSyscall +func realSyscall(trap, a1, a2, a3, a4, a5, a6 uintptr) (r, errno uintptr) + +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + syscall.Entersyscall() + r, errno := realSyscall(trap, a1, a2, a3, 0, 0, 0) + syscall.Exitsyscall() + return r, 0, syscall.Errno(errno) +} + +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + syscall.Entersyscall() + r, errno := realSyscall(trap, a1, a2, a3, a4, a5, a6) + syscall.Exitsyscall() + return r, 0, syscall.Errno(errno) +} + +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno) { + r, errno := realSyscall(trap, a1, a2, a3, 0, 0, 0) + return r, 0, syscall.Errno(errno) +} + +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.Errno) { + r, errno := realSyscall(trap, a1, a2, a3, a4, a5, a6) + return r, 0, syscall.Errno(errno) +} diff --git a/unix/gccgo_c.c b/unix/gccgo_c.c new file mode 100644 index 00000000..991980ea --- /dev/null +++ b/unix/gccgo_c.c @@ -0,0 +1,41 @@ +// 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 gccgo + +#include +#include +#include + +#define _STRINGIFY2_(x) #x +#define _STRINGIFY_(x) _STRINGIFY2_(x) +#define GOSYM_PREFIX _STRINGIFY_(__USER_LABEL_PREFIX__) + +// Call syscall from C code because the gccgo support for calling from +// Go to C does not support varargs functions. + +struct ret { + uintptr_t r; + uintptr_t err; +}; + +struct ret +gccgoRealSyscall(uintptr_t trap, uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5, uintptr_t a6) +{ + struct ret r; + + errno = 0; + r.r = syscall(trap, a1, a2, a3, a4, a5, a6); + r.err = errno; + return r; +} + +// Define the use function in C so that it is not inlined. + +extern void use(void *) __asm__ (GOSYM_PREFIX GOPKGPATH ".use") __attribute__((noinline)); + +void +use(void *p __attribute__ ((unused))) +{ +} diff --git a/unix/gccgo_linux_amd64.go b/unix/gccgo_linux_amd64.go new file mode 100644 index 00000000..bffe1a77 --- /dev/null +++ b/unix/gccgo_linux_amd64.go @@ -0,0 +1,20 @@ +// 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 gccgo,linux,amd64 + +package unix + +import "syscall" + +//extern gettimeofday +func realGettimeofday(*Timeval, *byte) int32 + +func gettimeofday(tv *Timeval) (err syscall.Errno) { + r := realGettimeofday(tv, nil) + if r < 0 { + return syscall.GetErrno() + } + return 0 +} diff --git a/unix/syscall_unix_test.go b/unix/syscall_unix_test.go index ad9a5d72..bcc79d19 100644 --- a/unix/syscall_unix_test.go +++ b/unix/syscall_unix_test.go @@ -118,6 +118,9 @@ func TestPassFD(t *testing.T) { cmd := exec.Command(os.Args[0], "-test.run=^TestPassFD$", "--", tempDir) cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1"} + if lp := os.Getenv("LD_LIBRARY_PATH"); lp != "" { + cmd.Env = append(cmd.Env, "LD_LIBRARY_PATH="+lp) + } cmd.ExtraFiles = []*os.File{writeFile} out, err := cmd.CombinedOutput()