diff mbox

[libgo] Detect Solaris 8/9 SPARC makecontext

Message ID yddbop0ug29.fsf@manam.CeBiTec.Uni-Bielefeld.DE
State New
Headers show

Commit Message

Rainer Orth Feb. 15, 2012, 6:06 p.m. UTC
The libgo setcontext TLS configure test was failing on Solaris 8 and
9/SPARC, breaking bootstrap due to the unhandled case in
runtime/proc.c.  This turned out to be a known issue, documented in the
makecontext(3C) manpage:

NOTES
     The semantics of  the  uc_stack  member  of  the  ucontext_t
     structure  have  changed as they apply to inputs to makecon-
     text(). Prior  to  Solaris  10,  the  ss_sp  member  of  the
     uc_stack  structure  represented  the high memory address of
     the area reserved  for  the  stack.  The  ss_sp  member  now
     represents  the  base  (low memory address), in keeping with
     other uses of ss_sp.

     This change in the meaning  of  ss_sp  is  now  the  default
     behavior.  The  -D__MAKECONTEXT_V2_SOURCE  compilation  flag
     used in Solaris 9 update releases to access this behavior is
     obsolete.

Since it didn't seem easy to autodetect the condition, and
__MAKECONTEXT_V2_SOURCE was only introduced in a Solaris 9 update
(4/03), I've chosed to just hardcode the fact that Solaris 8 and 9
differ on SPARC.

The patch allowed the bootstrap to complete successfully, but since
libgo.so now has undefined references to log2 and trunc, all Go
execution still fail.

	Rainer


2012-02-13  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>

	* configure.ac (libgo_cv_lib_makecontext_stack_top): Set on
	sparc*-*-solaris2.[89]*.
	(MAKECONTEXT_STACK_TOP): Define if appropriate.
	(libgo_cv_lib_setcontext_clobbers_tls): Use it.
	* configure: Regenerate.
	* config.h.in: Regenerate.
	* runtime/proc.c (__go_go) [MAKECONTEXT_STACK_TOP]: Add stack size
	to ss_sp.

Comments

Ian Lance Taylor Feb. 15, 2012, 10:29 p.m. UTC | #1
Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> writes:

> 2012-02-13  Rainer Orth  <ro@CeBiTec.Uni-Bielefeld.DE>
>
> 	* configure.ac (libgo_cv_lib_makecontext_stack_top): Set on
> 	sparc*-*-solaris2.[89]*.
> 	(MAKECONTEXT_STACK_TOP): Define if appropriate.
> 	(libgo_cv_lib_setcontext_clobbers_tls): Use it.
> 	* configure: Regenerate.
> 	* config.h.in: Regenerate.
> 	* runtime/proc.c (__go_go) [MAKECONTEXT_STACK_TOP]: Add stack size
> 	to ss_sp.

Thanks.

Committed.

Ian
diff mbox

Patch

# HG changeset patch
# Parent bdc02d4914d89c66f92b2c0bd67547817cdfc646
Detect Solaris 8/9 SPARC makecontext

diff --git a/libgo/config.h.in b/libgo/config.h.in
--- a/libgo/config.h.in
+++ b/libgo/config.h.in
@@ -182,6 +182,9 @@ 
    */
 #undef LT_OBJDIR
 
+/* Define if makecontext expects top of stack in uc_stack. */
+#undef MAKECONTEXT_STACK_TOP
+
 /* Name of package */
 #undef PACKAGE
 
diff --git a/libgo/configure b/libgo/configure
--- a/libgo/configure
+++ b/libgo/configure
@@ -14871,6 +14871,20 @@  if test "$libgo_has_struct_exception" = 
 
 fi
 
+case "$target" in
+  sparc*-*-solaris2.[89]*)
+    libgo_cv_lib_makecontext_stack_top=yes
+    ;;
+  *)
+    libgo_cv_lib_makecontext_stack_top=no
+    ;;
+esac
+if test "$libgo_cv_lib_makecontext_stack_top" = "yes"; then
+
+$as_echo "#define MAKECONTEXT_STACK_TOP 1" >>confdefs.h
+
+fi
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether setcontext clobbers TLS variables" >&5
 $as_echo_n "checking whether setcontext clobbers TLS variables... " >&6; }
 if test "${libgo_cv_lib_setcontext_clobbers_tls+set}" = set; then :
@@ -14972,6 +14986,9 @@  main ()
     abort ();
 
   c.uc_stack.ss_sp = stack;
+#ifdef MAKECONTEXT_STACK_TOP
+  c.uc_stack.ss_sp += sizeof stack;
+#endif
   c.uc_stack.ss_flags = 0;
   c.uc_stack.ss_size = sizeof stack;
   c.uc_link = NULL;
diff --git a/libgo/configure.ac b/libgo/configure.ac
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -609,6 +609,21 @@  if test "$libgo_has_struct_exception" = 
             [Define to 1 if <math.h> defines struct exception])
 fi
 
+dnl Check if makecontext expects the uc_stack member of ucontext to point
+dnl to the top of the stack.
+case "$target" in
+  sparc*-*-solaris2.[[89]]*)
+    libgo_cv_lib_makecontext_stack_top=yes
+    ;;
+  *)
+    libgo_cv_lib_makecontext_stack_top=no
+    ;;
+esac
+if test "$libgo_cv_lib_makecontext_stack_top" = "yes"; then
+  AC_DEFINE(MAKECONTEXT_STACK_TOP, 1,
+	    [Define if makecontext expects top of stack in uc_stack.])
+fi
+
 dnl See whether setcontext changes the value of TLS variables.
 AC_CACHE_CHECK([whether setcontext clobbers TLS variables],
 [libgo_cv_lib_setcontext_clobbers_tls],
@@ -665,6 +680,9 @@  main ()
     abort ();
 
   c.uc_stack.ss_sp = stack;
+#ifdef MAKECONTEXT_STACK_TOP
+  c.uc_stack.ss_sp += sizeof stack;
+#endif
   c.uc_stack.ss_flags = 0;
   c.uc_stack.ss_size = sizeof stack;
   c.uc_link = NULL;
diff --git a/libgo/runtime/proc.c b/libgo/runtime/proc.c
--- a/libgo/runtime/proc.c
+++ b/libgo/runtime/proc.c
@@ -1297,6 +1297,9 @@  __go_go(void (*fn)(void*), void* arg)
 
 	getcontext(&newg->context);
 	newg->context.uc_stack.ss_sp = sp;
+#ifdef MAKECONTEXT_STACK_TOP
+	newg->context.uc_stack.ss_sp += spsize;
+#endif
 	newg->context.uc_stack.ss_size = spsize;
 	makecontext(&newg->context, kickoff, 0);