Patchwork Go patch committed: Use __builtin_unwind_init

login
register
mail settings
Submitter Ian Taylor
Date Jan. 5, 2011, 12:24 a.m.
Message ID <mcr1v4snqof.fsf@google.com>
Download mbox | patch
Permalink /patch/77553/
State New
Headers show

Comments

Ian Taylor - Jan. 5, 2011, 12:24 a.m.
The Go runtime library used a hack, SAVE_REGS, to force all callee-saved
registers to be saved on the stack, so that the garbage collector can
see them reliably.  Joseph pointed out in a comment in PR 46964 that the
__builtin_unwind_init function does the same thing.  This is in fact
what the Boehm garbage collector does.  This patch uses the builtin
function rather than the SAVE_REGS hack.  This fixes PRs 46959, 46960,
46961, 46962, 46963, and 46964, which are about different targets
failing to define SAVE_REGS.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r e88088fffdd4 libgo/runtime/go-go.c
--- a/libgo/runtime/go-go.c	Tue Jan 04 16:06:33 2011 -0800
+++ b/libgo/runtime/go-go.c	Tue Jan 04 16:19:01 2011 -0800
@@ -25,21 +25,6 @@ 
 				void **);
 #endif
 
-/* We need to ensure that all callee-saved registers are stored on the
-   stack, in case they hold pointers.  */
-
-#if defined(__i386__)
- #ifndef __PIC__
-  #define SAVE_REGS asm ("" : : : "esi", "edi", "ebx")
- #else
-  #define SAVE_REGS asm ("" : : : "esi", "edi")
- #endif
-#elif defined(__x86_64__)
- #define SAVE_REGS asm ("" : : : "r12", "r13", "r14", "r15", "rbp", "rbx")
-#else
- #error must define SAVE_REGS
-#endif
-
 /* We stop the threads by sending them the signal GO_SIG_STOP and we
    start them by sending them the signal GO_SIG_START.  */
 
@@ -344,7 +329,7 @@ 
      needed if we are called directly, since otherwise we might miss
      something that a function somewhere up the call stack is holding
      in a register.  */
-  SAVE_REGS;
+  __builtin_unwind_init ();
 
   stop_for_gc ();
 
@@ -433,7 +418,7 @@ 
   struct __go_thread_id *p;
 
   /* Make sure all the registers for this thread are on the stack.  */
-  SAVE_REGS;
+  __builtin_unwind_init ();
 
   me = pthread_self ();
   for (p = __go_all_thread_ids; p != NULL; p = p->next)