[Gc] Boehm-GC Patch for Cygwin-64

Bernd Edlinger <[email protected]> Tue, 13 May 2014 10:49:03 +0200
Newsgroups gmane.comp.programming.garbage-collection.boehmgc
Message-ID <[email protected]>
Hi,

I'm about to add support for Cygwin-64 to GCC's boehm_gc.

There were a few build-problems under Cygwin-64.

The define __CYGWIN32__ is only defined for the 32-bit variant,
but __CYGWIN__ is defined for 32-bit and 64-bit variants.
And the registers are of course different ones in win32_threads.c.

Could some one please take care, that this change (or an equivalent fix)
also goes to the original boehm_gc source?


Thanks
Bernd Edlinger.


boehm-gc/ChangeLog:

2014-05-11  Bernd Edlinger  <[email protected]>

	Fix current cygwin-64 build problems.
	* include/gc_config_macros.h (GC_PTHREADS): Use __CYGWIN__ instead
	of __CYGWIN32__ here.
	* win32_threads.c (GC_push_all_stacks): Push all X86_64 registers.
	(GC_get_thread_stack_base): Get the stack base for X86_64.


diff -pur boehm-gc/include/gc_config_macros.h boehm-gc/include/gc_config_macros.h
--- boehm-gc/include/gc_config_macros.h	2012-11-04 23:56:02.000000000 +0100
+++ boehm-gc/include/gc_config_macros.h	2014-05-05 15:48:50.430664000 +0200
@@ -23,7 +23,7 @@
 	defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) || \
 	defined(GC_DGUX386_THREADS) || defined(GC_DARWIN_THREADS) || \
 	defined(GC_AIX_THREADS) || \
-        (defined(GC_WIN32_THREADS) && defined(__CYGWIN32__))
+        (defined(GC_WIN32_THREADS) && defined(__CYGWIN__))
 #   define GC_PTHREADS
 # endif
 
diff -pur boehm-gc/win32_threads.c boehm-gc/win32_threads.c
--- boehm-gc/win32_threads.c	2009-05-17 22:07:18.000000000 +0200
+++ boehm-gc/win32_threads.c	2014-05-05 15:51:34.290039000 +0200
@@ -365,7 +365,11 @@ void GC_push_all_stacks()
 #       define PUSH1(reg) GC_push_one((word)context.reg)
 #       define PUSH2(r1,r2) PUSH1(r1), PUSH1(r2)
 #       define PUSH4(r1,r2,r3,r4) PUSH2(r1,r2), PUSH2(r3,r4)
-#       if defined(I386)
+#       if defined(__x86_64__) 
+          PUSH4(Rdi,Rsi,Rbx,Rdx), PUSH2(Rcx,Rax), PUSH1(Rbp);
+          PUSH4(R8,R9,R10,R11), PUSH4(R12,R13,R14,R15);
+          sp = (ptr_t)context.Rsp;
+#       elif defined(I386)
           PUSH4(Edi,Esi,Ebx,Edx), PUSH2(Ecx,Eax), PUSH1(Ebp);
 	  sp = (ptr_t)context.Esp;
 #       elif defined(ARM32)
@@ -755,8 +759,12 @@ int GC_pthread_detach(pthread_t thread)
 
 GC_PTR GC_get_thread_stack_base()
 {
+#ifdef __x86_64__
+  return ((NT_TIB*)NtCurrentTeb())->StackBase;
+#else
   extern GC_PTR _tlsbase __asm__ ("%fs:4");
   return _tlsbase;
+#endif
 }
 
 #else /* !CYGWIN32 */