This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: gccgo branch and darwin
- From: Ian Lance Taylor <iant at google dot com>
- To: Arnaud Lacombe <lacombar at gmail dot com>
- Cc: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Wed, 01 Dec 2010 14:02:47 -0800
- Subject: Re: gccgo branch and darwin
- References: <20101119195558.GA18808@bromo.med.uc.edu> <AANLkTimq5aDWPj7Bi8kT_ACUbK8XAx39QZWOha5nCt0z@mail.gmail.com> <AANLkTimn7eO7KGNgdskpFwOLP_XjPLZ5q3WvGMNnmP9R@mail.gmail.com> <AANLkTi=_BmJtRdPQJo6=9SOcoUHnFVeX_ytaeKvxj=kc@mail.gmail.com> <AANLkTinqS4XYGCtB7=9z4KLRj=NiJ4GcxyS4SaNLsbi5@mail.gmail.com>
Arnaud Lacombe <lacombar@gmail.com> writes:
> On Fri, Nov 19, 2010 at 11:58 PM, Arnaud Lacombe <lacombar@gmail.com> wrote:
>
> One nits; is there any reason to use `__xpg_strerror_r()' which is not
> POSIX, versus 'strerror_r()' [0] ?
I did this because on GNU/Linux the POSIX compliant strerror_r is
actually named __xpg_strerror_r. The <string.h> file is set up such
that that variant is used if strerror_r is called with
-D_XOPEN_SOURCE=600 or _D_POSIX_C_SOURCE=200112L. If you use
-DGNU_SOURCE, then when calling strerror_r you get the GNU version,
which returns char * rather than int. This happened because the GNU
version was defined before the POSIX version.
> As RTEMS prototypes has already been mangled to make it return `int'
> instead of the `char *', that would allow to merge all
> `libgo/syscalls/errstr*.go'.
The RTEMS variant assumes the behaviour of the newlib strerror_r.
Declaring it with a return type of int is a bug.
I cleaned up this area to isolate the GNU/Linux dependency with the
following patch. This should make the code more likely to work on other
systems. Committed to gccgo branch.
Ian
diff -r c800c9ea5175 libgo/Makefile.am
--- a/libgo/Makefile.am Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/Makefile.am Wed Dec 01 13:56:00 2010 -0800
@@ -1110,6 +1110,7 @@
syscall_sysfile_os_file = syscalls/sysfile_rtems.go
syscall_syscall_file = syscalls/syscall_stubs.go
syscall_errstr_file = syscalls/errstr_rtems.go
+syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go
else
syscall_exec_os_file = syscalls/exec.go
syscall_socket_os_file = syscalls/socket_linux.go
@@ -1117,10 +1118,16 @@
syscall_sysfile_os_file = syscalls/sysfile_linux.go
syscall_syscall_file = syscalls/syscall.go
syscall_errstr_file = syscalls/errstr.go
+if LIBGO_IS_LINUX
+syscall_errstr_decl_file = syscalls/errstr_decl_linux.go
+else
+syscall_errstr_decl_file = syscalls/errstr_decl.go
+endif
endif
go_syscall_files = \
$(syscall_errstr_file) \
+ $(syscall_errstr_decl_file) \
syscalls/exec_helpers.go \
$(syscall_exec_os_file) \
syscalls/socket.go \
diff -r c800c9ea5175 libgo/syscalls/errstr.go
--- a/libgo/syscalls/errstr.go Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/syscalls/errstr.go Wed Dec 01 13:56:00 2010 -0800
@@ -6,26 +6,24 @@
package syscall
-const ENONE = 0;
+const ENONE = 0
-// FIXME: The name is only right for glibc.
-func libc_strerror_r(int, *byte, Size_t) int __asm__ ("__xpg_strerror_r")
func GetErrno() int
func SetErrno(int)
func Errstr(errno int) string {
for len := Size_t(128); ; len *= 2 {
- b := make([]byte, len);
- r := libc_strerror_r(errno, &b[0], len);
+ b := make([]byte, len)
+ r := libc_strerror_r(errno, &b[0], len)
if r >= 0 {
- i := 0;
+ i := 0
for b[i] != 0 {
- i++;
+ i++
}
- return string(b[0:i]);
+ return string(b[:i])
}
if GetErrno() != ERANGE {
- return "Errstr failure";
+ return "Errstr failure"
}
}
}
diff -r c800c9ea5175 libgo/syscalls/errstr_decl.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl.go Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,9 @@
+// errstr.go -- Declare strerror_r.
+
+// 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.
+
+package syscall
+
+func libc_strerror_r(int, *byte, Size_t) int __asm__ ("strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_decl_linux.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl_linux.go Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,9 @@
+// errstr_decl_linux.go -- Declare strerror_r for GNU/Linux.
+
+// 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.
+
+package syscall
+
+func libc_strerror_r(int, *byte, Size_t) int __asm__ ("__xpg_strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_decl_rtems.go
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libgo/syscalls/errstr_decl_rtems.go Wed Dec 01 13:56:00 2010 -0800
@@ -0,0 +1,10 @@
+// errstr.go -- Declare strerror_r for RTEMS.
+
+// 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.
+
+package syscall
+
+// RTEMS uses strerror_r in newlib, which is a GNU extension returning a char *.
+func libc_strerror_r(int, *byte, Size_t) *byte __asm__ ("strerror_r")
diff -r c800c9ea5175 libgo/syscalls/errstr_rtems.go
--- a/libgo/syscalls/errstr_rtems.go Wed Dec 01 13:31:12 2010 -0800
+++ b/libgo/syscalls/errstr_rtems.go Wed Dec 01 13:56:00 2010 -0800
@@ -8,8 +8,6 @@
const ENONE = 0
-// RTEMS uses strerror_r in newlib, which is a GNU extension returning a char *.
-func libc_strerror_r(int, *byte, Size_t) int __asm__ ("strerror_r")
func GetErrno() int
func SetErrno(int)