From: Ian Lance Taylor Date: Wed, 30 Mar 2011 22:34:55 +0000 (+0000) Subject: libgo: Support systems which do not have strerror_r. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8955c80a1cc754999cfa93d03c04307281e6136f;p=gcc.git libgo: Support systems which do not have strerror_r. From-SVN: r171757 --- diff --git a/libgo/Makefile.am b/libgo/Makefile.am index 0a13bc96188..476d4aaf3a2 100644 --- a/libgo/Makefile.am +++ b/libgo/Makefile.am @@ -1264,7 +1264,11 @@ endif if LIBGO_IS_RTEMS syscall_errstr_file = syscalls/errstr_rtems.go else +if HAVE_STRERROR_R syscall_errstr_file = syscalls/errstr.go +else +syscall_errstr_file = syscalls/errstr_nor.go +endif endif # Declare libc_strerror_r which is the Go name for strerror_r. @@ -1273,7 +1277,7 @@ if LIBGO_IS_RTEMS syscall_errstr_decl_file = syscalls/errstr_decl_rtems.go else if LIBGO_IS_LINUX -# In Linux the POSIX strerror_r is called __xpg_strerror_r. +# On GNU/Linux the POSIX strerror_r is called __xpg_strerror_r. syscall_errstr_decl_file = syscalls/errstr_decl_linux.go else # On other systems we hope strerror_r is just strerror_r. diff --git a/libgo/Makefile.in b/libgo/Makefile.in index f605f9cec9b..5797fad7f3b 100644 --- a/libgo/Makefile.in +++ b/libgo/Makefile.in @@ -1638,13 +1638,14 @@ go_testing_script_files = \ # Define Sleep. @LIBGO_IS_RTEMS_TRUE@syscall_sleep_file = syscalls/sleep_rtems.go -@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go +@HAVE_STRERROR_R_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr_nor.go +@HAVE_STRERROR_R_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_file = syscalls/errstr.go # Define Errstr. @LIBGO_IS_RTEMS_TRUE@syscall_errstr_file = syscalls/errstr_rtems.go # On other systems we hope strerror_r is just strerror_r. @LIBGO_IS_LINUX_FALSE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl.go -# In Linux the POSIX strerror_r is called __xpg_strerror_r. +# On GNU/Linux the POSIX strerror_r is called __xpg_strerror_r. @LIBGO_IS_LINUX_TRUE@@LIBGO_IS_RTEMS_FALSE@syscall_errstr_decl_file = syscalls/errstr_decl_linux.go # Declare libc_strerror_r which is the Go name for strerror_r. diff --git a/libgo/configure b/libgo/configure index ca3544e5f2b..6fe02592306 100644 --- a/libgo/configure +++ b/libgo/configure @@ -603,6 +603,8 @@ am__EXEEXT_TRUE LTLIBOBJS LIBOBJS STRINGOPS_FLAG +HAVE_STRERROR_R_FALSE +HAVE_STRERROR_R_TRUE HAVE_SYS_MMAN_H_FALSE HAVE_SYS_MMAN_H_TRUE PTHREAD_LIBS @@ -10898,7 +10900,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 10901 "configure" +#line 10903 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -11004,7 +11006,7 @@ else lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_status=$lt_dlunknown cat > conftest.$ac_ext <<_LT_EOF -#line 11007 "configure" +#line 11009 "configure" #include "confdefs.h" #if HAVE_DLFCN_H @@ -14151,7 +14153,8 @@ else HAVE_SYS_MMAN_H_FALSE= fi -for ac_func in srandom random strsignal + +for ac_func in srandom random strerror_r strsignal do : as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh` ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var" @@ -14164,6 +14167,14 @@ _ACEOF fi done + if test "$ac_cv_func_strerror_r" = yes; then + HAVE_STRERROR_R_TRUE= + HAVE_STRERROR_R_FALSE='#' +else + HAVE_STRERROR_R_TRUE='#' + HAVE_STRERROR_R_FALSE= +fi + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for __sync_bool_compare_and_swap_4" >&5 $as_echo_n "checking for __sync_bool_compare_and_swap_4... " >&6; } @@ -14537,6 +14548,10 @@ if test -z "${HAVE_SYS_MMAN_H_TRUE}" && test -z "${HAVE_SYS_MMAN_H_FALSE}"; then as_fn_error "conditional \"HAVE_SYS_MMAN_H\" was never defined. Usually this means the macro was only invoked conditionally." "$LINENO" 5 fi +if test -z "${HAVE_STRERROR_R_TRUE}" && test -z "${HAVE_STRERROR_R_FALSE}"; then + as_fn_error "conditional \"HAVE_STRERROR_R\" was never defined. +Usually this means the macro was only invoked conditionally." "$LINENO" 5 +fi : ${CONFIG_STATUS=./config.status} ac_write_fail=0 diff --git a/libgo/configure.ac b/libgo/configure.ac index 2ec9f5c475e..7839278e881 100644 --- a/libgo/configure.ac +++ b/libgo/configure.ac @@ -380,7 +380,9 @@ esac AC_CHECK_HEADERS(sys/mman.h syscall.h sys/epoll.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h) AM_CONDITIONAL(HAVE_SYS_MMAN_H, test "$ac_cv_header_sys_mman_h" = yes) -AC_CHECK_FUNCS(srandom random strsignal) + +AC_CHECK_FUNCS(srandom random strerror_r strsignal) +AM_CONDITIONAL(HAVE_STRERROR_R, test "$ac_cv_func_strerror_r" = yes) AC_CACHE_CHECK([for __sync_bool_compare_and_swap_4], [libgo_cv_func___sync_bool_compare_and_swap_4], diff --git a/libgo/syscalls/errstr_nor.go b/libgo/syscalls/errstr_nor.go new file mode 100644 index 00000000000..358b3ee9cf6 --- /dev/null +++ b/libgo/syscalls/errstr_nor.go @@ -0,0 +1,32 @@ +// errstr.go -- Error strings when there is no strerror_r. + +// 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 ( + "sync" + "unsafe" +) + +func libc_strerror(int) *byte __asm__ ("strerror") + +var errstr_lock sync.Mutex + +func Errstr(errno int) string { + errstr_lock.Lock() + + bp := libc_strerror(errno) + b := (*[1000]byte)(unsafe.Pointer(bp)) + i := 0 + for b[i] != 0 { + i++ + } + s := string(b[:i]) + + errstr_lock.Unlock() + + return s +}