host support for darwin9
Shantonu Sen
ssen@opendarwin.org
Sat Jun 3 02:45:00 GMT 2006
I noticed that the host-darwin.c is for PPC Darwin only. It looks like
there is no corresponding Intel Darwin host file, which makes my
question why there is an architecture-specific host file for PPC at
all. It looks like this is to handle running out of stack space and
printing a helpful hint. Is this still necessary? Empirically, modern
version of Mac OS X have an 8MB stack limit, and I've never
experienced this problem myself. It seems like you can improve
portability for all supported versions of Darwin by removing rs6000/
host-darwin.c completely.
Shantonu
On Jun 2, 2006, at 7:02 PM, Geoffrey Keating wrote:
> This patch adds some autoconfiscation so that GCC can build on
> darwin9. Of course, there isn't a final darwin9 yet, so there could
> still be changes, but I'm fairly sure this is at least in the right
> direction.
>
> The changes are all related to better standards conformance on
> Darwin:
>
> - there is no longer a 'struct sigaltstack', it's called stack_t, but
> that doesn't exist on earlier Darwin versions; fortunately recent
> (even Panther) headers also prototype the sigaltstack() function, so
> the declaration is no longer necessary;
>
> - fields for a number of structures have grown underscores.
> Apparently you are supposed to just use __r0 in your source.
> I expect this to change once someone realises that __r0 is not a
> very safe name either, so I made provision for that with macros.
>
> I'll call this a bugfix and commit it to the trunk, since it'll be
> annoying if 4.2 doesn't build on darwin9; it might be final before
> 4.3 is.
>
> --
> - Geoffrey Keating <geoffk@apple.com>
>
> ===File ~/patches/gcc-leopardconfig.patch===================
> Index: gcc/ChangeLog
> 2006-06-02 Geoffrey Keating <geoffk@apple.com>
>
> * config/rs6000/host-darwin.c (sigaltstack): Protect prototype with
> HAVE_DECL_SIGALTSTACK.
> (MC_FLD): New.
> (segv_handler): Use MC_FLD.
> * configure.ac: Check for a sigaltstack declaration.
> Compute HAS_MCONTEXT_T_UNDERSCORES on Darwin.
> * configure: Regenerate.
> * config.in: Regenerate.
>
> Index: boehm-gc/ChangeLog
> 2006-06-02 Geoffrey Keating <geoffk@apple.com>
>
> * configure.ac: Define HAS_PPC_THREAD_STATE_R0,
> HAS_PPC_THREAD_STATE___R0, HAS_PPC_THREAD_STATE64_R0,
> HAS_PPC_THREAD_STATE64___R0, HAS_I386_THREAD_STATE_EAX,
> HAS_I386_THREAD_STATE___EAX.
> * configure: Regenerate.
> * include/gc_config.h.in: Regenerate.
> * darwin_stop_world.c (PPC_RED_ZONE_SIZE): Use standard Darwin
> macro names to determine value.
> (THREAD_STATE): New.
> (THREAD_FLD): New.
> (GC_push_all_stacks): Use THREAD_STATE and THREAD_FLD in both
> versions.
>
> Index: gcc/configure.ac
> ===================================================================
> --- gcc/configure.ac (revision 114258)
> +++ gcc/configure.ac (working copy)
> @@ -1154,6 +1154,12 @@
> #endif
> ])
>
> +gcc_AC_CHECK_DECLS(sigaltstack, , ,[
> +#include "ansidecl.h"
> +#include "system.h"
> +#include <signal.h>
> +])
> +
> # More time-related stuff.
> AC_CACHE_CHECK(for struct tms, ac_cv_struct_tms, [
> AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
> @@ -1337,6 +1343,22 @@
> fi
> fi
>
> +case ${host} in
> + powerpc-*-darwin*)
> + AC_CACHE_CHECK([whether mcontext_t fields have underscores],
> + gcc_cv_mcontext_underscores,
> + AC_COMPILE_IFELSE([
> +#include <ucontext.h>
> +int main() { mcontext_t m; if (m->ss.srr0) return 0; return 0; }
> +],
> + gcc_cv_mcontext_underscores=no, gcc_cv_mcontext_underscores=yes))
> + if test $gcc_cv_mcontext_underscores = yes; then
> + AC_DEFINE(HAS_MCONTEXT_T_UNDERSCORES,,dnl
> + [mcontext_t fields start with __])
> + fi
> + ;;
> +esac
> +
> # ---------
> # Threading
> # ---------
> Index: gcc/config/rs6000/host-darwin.c
> ===================================================================
> --- gcc/config/rs6000/host-darwin.c (revision 114258)
> +++ gcc/config/rs6000/host-darwin.c (working copy)
> @@ -33,10 +33,20 @@
> static void segv_handler (int, siginfo_t *, void *);
> static void darwin_rs6000_extra_signals (void);
>
> +#ifndef HAVE_DECL_SIGALTSTACK
> /* This doesn't have a prototype in signal.h in 10.2.x and earlier,
> fixed in later releases. */
> extern int sigaltstack(const struct sigaltstack *, struct
> sigaltstack *);
> +#endif
>
> +/* The fields of the mcontext_t type have acquired underscores in
> later
> + OS versions. */
> +#ifdef HAS_MCONTEXT_T_UNDERSCORES
> +#define MC_FLD(x) __ ## x
> +#else
> +#define MC_FLD(x) x
> +#endif
> +
> #undef HOST_HOOKS_EXTRA_SIGNALS
> #define HOST_HOOKS_EXTRA_SIGNALS darwin_rs6000_extra_signals
>
> @@ -68,7 +78,7 @@
> sigaddset (&sigset, SIGSEGV);
> sigprocmask (SIG_UNBLOCK, &sigset, NULL);
>
> - faulting_insn = *(unsigned *)uc->uc_mcontext->ss.srr0;
> + faulting_insn = *(unsigned *)uc->uc_mcontext->MC_FLD(ss).MC_FLD
> (srr0);
>
> /* Note that this only has to work for GCC, so we don't have to
> deal
> with all the possible cases (GCC has no AltiVec code, for
> @@ -117,7 +127,8 @@
> }
>
> fprintf (stderr, "[address=%08lx pc=%08x]\n",
> - uc->uc_mcontext->es.dar, uc->uc_mcontext->ss.srr0);
> + uc->uc_mcontext->MC_FLD(es).MC_FLD(dar),
> + uc->uc_mcontext->MC_FLD(ss).MC_FLD(srr0));
> internal_error ("Segmentation Fault");
> exit (FATAL_EXIT_CODE);
> }
> Index: boehm-gc/darwin_stop_world.c
> ===================================================================
> --- boehm-gc/darwin_stop_world.c (revision 114258)
> +++ boehm-gc/darwin_stop_world.c (working copy)
> @@ -14,12 +14,43 @@
> Page 50: "If a leaf procedure's red zone usage would exceed 224
> bytes, then
> it must set up a stack frame just like routines that call other
> routines."
> */
> -#ifdef POWERPC
> -# if CPP_WORDSZ == 32
> -# define PPC_RED_ZONE_SIZE 224
> -# elif CPP_WORDSZ == 64
> -# define PPC_RED_ZONE_SIZE 320
> +#if defined(__ppc__)
> +# define PPC_RED_ZONE_SIZE 224
> +#elif defined(__ppc64__)
> +# define PPC_RED_ZONE_SIZE 320
> +#endif
> +
> +/* Try to work out the right way to access thread state structure
> members.
> + The structure has changed its definition in different Darwin
> versions. */
> +#if defined(__ppc__)
> +# define THREAD_STATE ppc_thread_state_t
> +# if defined (HAS_PPC_THREAD_STATE_R0)
> +# define THREAD_FLD(x) x
> +# elif defined (HAS_PPC_THREAD_STATE___R0)
> +# define THREAD_FLD(x) __ ## x
> +# else
> +# error can not work out how to access fields of ppc_thread_state_t
> # endif
> +#elif defined(__ppc64__)
> +# define THREAD_STATE ppc_thread_state64_t
> +# if defined (HAS_PPC_THREAD_STATE64_R0)
> +# define THREAD_FLD(x) x
> +# elif defined (HAS_PPC_THREAD_STATE64___R0)
> +# define THREAD_FLD(x) __ ## x
> +# else
> +# error can not work out how to access fields of
> ppc_thread_state64_t
> +# endif
> +#elif defined(__i386__)
> +# define THREAD_STATE i386_thread_state_t
> +# if defined (HAS_I386_THREAD_STATE_EAX)
> +# define THREAD_FLD(x) x
> +# elif defined (HAS_I386_THREAD_STATE___EAX)
> +# define THREAD_FLD(x) __ ## x
> +# else
> +# error can not work out how to access fields of i386_thread_state_t
> +# endif
> +#else
> +# error unknown architecture
> #endif
>
> typedef struct StackFrame {
> @@ -75,7 +106,7 @@
> GC_thread p;
> pthread_t me;
> ptr_t lo, hi;
> - ppc_thread_state_t state;
> + THREAD_STATE state;
> mach_msg_type_number_t thread_state_count =
> MACHINE_THREAD_STATE_COUNT;
>
> me = pthread_self();
> @@ -95,39 +126,39 @@
> &thread_state_count);
> if(r != KERN_SUCCESS) ABORT("thread_get_state failed");
>
> - lo = (void*)(state.r1 - PPC_RED_ZONE_SIZE);
> + lo = (void*)(state . THREAD_FLD (r1) - PPC_RED_ZONE_SIZE);
>
> - GC_push_one(state.r0);
> - GC_push_one(state.r2);
> - GC_push_one(state.r3);
> - GC_push_one(state.r4);
> - GC_push_one(state.r5);
> - GC_push_one(state.r6);
> - GC_push_one(state.r7);
> - GC_push_one(state.r8);
> - GC_push_one(state.r9);
> - GC_push_one(state.r10);
> - GC_push_one(state.r11);
> - GC_push_one(state.r12);
> - GC_push_one(state.r13);
> - GC_push_one(state.r14);
> - GC_push_one(state.r15);
> - GC_push_one(state.r16);
> - GC_push_one(state.r17);
> - GC_push_one(state.r18);
> - GC_push_one(state.r19);
> - GC_push_one(state.r20);
> - GC_push_one(state.r21);
> - GC_push_one(state.r22);
> - GC_push_one(state.r23);
> - GC_push_one(state.r24);
> - GC_push_one(state.r25);
> - GC_push_one(state.r26);
> - GC_push_one(state.r27);
> - GC_push_one(state.r28);
> - GC_push_one(state.r29);
> - GC_push_one(state.r30);
> - GC_push_one(state.r31);
> + GC_push_one(state . THREAD_FLD (r0));
> + GC_push_one(state . THREAD_FLD (r2));
> + GC_push_one(state . THREAD_FLD (r3));
> + GC_push_one(state . THREAD_FLD (r4));
> + GC_push_one(state . THREAD_FLD (r5));
> + GC_push_one(state . THREAD_FLD (r6));
> + GC_push_one(state . THREAD_FLD (r7));
> + GC_push_one(state . THREAD_FLD (r8));
> + GC_push_one(state . THREAD_FLD (r9));
> + GC_push_one(state . THREAD_FLD (r10));
> + GC_push_one(state . THREAD_FLD (r11));
> + GC_push_one(state . THREAD_FLD (r12));
> + GC_push_one(state . THREAD_FLD (r13));
> + GC_push_one(state . THREAD_FLD (r14));
> + GC_push_one(state . THREAD_FLD (r15));
> + GC_push_one(state . THREAD_FLD (r16));
> + GC_push_one(state . THREAD_FLD (r17));
> + GC_push_one(state . THREAD_FLD (r18));
> + GC_push_one(state . THREAD_FLD (r19));
> + GC_push_one(state . THREAD_FLD (r20));
> + GC_push_one(state . THREAD_FLD (r21));
> + GC_push_one(state . THREAD_FLD (r22));
> + GC_push_one(state . THREAD_FLD (r23));
> + GC_push_one(state . THREAD_FLD (r24));
> + GC_push_one(state . THREAD_FLD (r25));
> + GC_push_one(state . THREAD_FLD (r26));
> + GC_push_one(state . THREAD_FLD (r27));
> + GC_push_one(state . THREAD_FLD (r28));
> + GC_push_one(state . THREAD_FLD (r29));
> + GC_push_one(state . THREAD_FLD (r30));
> + GC_push_one(state . THREAD_FLD (r31));
> } /* p != me */
> if(p->flags & MAIN_THREAD)
> hi = GC_stackbottom;
> @@ -166,78 +197,74 @@
> lo = GC_approx_sp();
> hi = (ptr_t)FindTopOfStack(0);
> } else {
> -# if defined(POWERPC)
> -# if CPP_WORDSZ == 32
> - ppc_thread_state_t info;
> -# else
> - ppc_thread_state64_t info;
> -# endif
> +# if defined(__ppc__) || defined(__ppc64__)
> + THREAD_STATE info;
> mach_msg_type_number_t outCount = THREAD_STATE_MAX;
> r = thread_get_state(thread, MACHINE_THREAD_STATE,
> (natural_t *)&info, &outCount);
> if(r != KERN_SUCCESS) ABORT("task_get_state failed");
>
> - lo = (void*)(info.r1 - PPC_RED_ZONE_SIZE);
> - hi = (ptr_t)FindTopOfStack(info.r1);
> + lo = (void*)(info . THREAD_FLD (r1) - PPC_RED_ZONE_SIZE);
> + hi = (ptr_t)FindTopOfStack(info . THREAD_FLD (r1));
>
> - GC_push_one(info.r0);
> - GC_push_one(info.r2);
> - GC_push_one(info.r3);
> - GC_push_one(info.r4);
> - GC_push_one(info.r5);
> - GC_push_one(info.r6);
> - GC_push_one(info.r7);
> - GC_push_one(info.r8);
> - GC_push_one(info.r9);
> - GC_push_one(info.r10);
> - GC_push_one(info.r11);
> - GC_push_one(info.r12);
> - GC_push_one(info.r13);
> - GC_push_one(info.r14);
> - GC_push_one(info.r15);
> - GC_push_one(info.r16);
> - GC_push_one(info.r17);
> - GC_push_one(info.r18);
> - GC_push_one(info.r19);
> - GC_push_one(info.r20);
> - GC_push_one(info.r21);
> - GC_push_one(info.r22);
> - GC_push_one(info.r23);
> - GC_push_one(info.r24);
> - GC_push_one(info.r25);
> - GC_push_one(info.r26);
> - GC_push_one(info.r27);
> - GC_push_one(info.r28);
> - GC_push_one(info.r29);
> - GC_push_one(info.r30);
> - GC_push_one(info.r31);
> + GC_push_one(info . THREAD_FLD (r0));
> + GC_push_one(info . THREAD_FLD (r2));
> + GC_push_one(info . THREAD_FLD (r3));
> + GC_push_one(info . THREAD_FLD (r4));
> + GC_push_one(info . THREAD_FLD (r5));
> + GC_push_one(info . THREAD_FLD (r6));
> + GC_push_one(info . THREAD_FLD (r7));
> + GC_push_one(info . THREAD_FLD (r8));
> + GC_push_one(info . THREAD_FLD (r9));
> + GC_push_one(info . THREAD_FLD (r10));
> + GC_push_one(info . THREAD_FLD (r11));
> + GC_push_one(info . THREAD_FLD (r12));
> + GC_push_one(info . THREAD_FLD (r13));
> + GC_push_one(info . THREAD_FLD (r14));
> + GC_push_one(info . THREAD_FLD (r15));
> + GC_push_one(info . THREAD_FLD (r16));
> + GC_push_one(info . THREAD_FLD (r17));
> + GC_push_one(info . THREAD_FLD (r18));
> + GC_push_one(info . THREAD_FLD (r19));
> + GC_push_one(info . THREAD_FLD (r20));
> + GC_push_one(info . THREAD_FLD (r21));
> + GC_push_one(info . THREAD_FLD (r22));
> + GC_push_one(info . THREAD_FLD (r23));
> + GC_push_one(info . THREAD_FLD (r24));
> + GC_push_one(info . THREAD_FLD (r25));
> + GC_push_one(info . THREAD_FLD (r26));
> + GC_push_one(info . THREAD_FLD (r27));
> + GC_push_one(info . THREAD_FLD (r28));
> + GC_push_one(info . THREAD_FLD (r29));
> + GC_push_one(info . THREAD_FLD (r30));
> + GC_push_one(info . THREAD_FLD (r31));
> # else
> /* FIXME: Remove after testing: */
> WARN("This is completely untested and likely will not work\n", 0);
> - i386_thread_state_t info;
> + THREAD_STATE info;
> mach_msg_type_number_t outCount = THREAD_STATE_MAX;
> r = thread_get_state(thread, MACHINE_THREAD_STATE,
> (natural_t *)&info, &outCount);
> if(r != KERN_SUCCESS) ABORT("task_get_state failed");
>
> - lo = (void*)info.esp;
> - hi = (ptr_t)FindTopOfStack(info.esp);
> + lo = (void*)info . THREAD_FLD (esp);
> + hi = (ptr_t)FindTopOfStack(info . THREAD_FLD (esp));
>
> - GC_push_one(info.eax);
> - GC_push_one(info.ebx);
> - GC_push_one(info.ecx);
> - GC_push_one(info.edx);
> - GC_push_one(info.edi);
> - GC_push_one(info.esi);
> - /* GC_push_one(info.ebp); */
> - /* GC_push_one(info.esp); */
> - GC_push_one(info.ss);
> - GC_push_one(info.eip);
> - GC_push_one(info.cs);
> - GC_push_one(info.ds);
> - GC_push_one(info.es);
> - GC_push_one(info.fs);
> - GC_push_one(info.gs);
> + GC_push_one(info . THREAD_FLD (eax));
> + GC_push_one(info . THREAD_FLD (ebx));
> + GC_push_one(info . THREAD_FLD (ecx));
> + GC_push_one(info . THREAD_FLD (edx));
> + GC_push_one(info . THREAD_FLD (edi));
> + GC_push_one(info . THREAD_FLD (esi));
> + /* GC_push_one(info . THREAD_FLD (ebp)); */
> + /* GC_push_one(info . THREAD_FLD (esp)); */
> + GC_push_one(info . THREAD_FLD (ss));
> + GC_push_one(info . THREAD_FLD (eip));
> + GC_push_one(info . THREAD_FLD (cs));
> + GC_push_one(info . THREAD_FLD (ds));
> + GC_push_one(info . THREAD_FLD (es));
> + GC_push_one(info . THREAD_FLD (fs));
> + GC_push_one(info . THREAD_FLD (gs));
> # endif /* !POWERPC */
> }
> # if DEBUG_THREADS
> Index: boehm-gc/configure.ac
> ===================================================================
> --- boehm-gc/configure.ac (revision 114258)
> +++ boehm-gc/configure.ac (working copy)
> @@ -232,6 +232,39 @@
> esac
> AM_CONDITIONAL(POWERPC_DARWIN,test x$powerpc_darwin = xtrue)
>
> +# Darwin needs a few extra special tests to deal with variation in
> the
> +# system headers.
> +case "$host" in
> + powerpc*-*-darwin*)
> + AC_CHECK_MEMBER(ppc_thread_state_t.r0,
> + AC_DEFINE(HAS_PPC_THREAD_STATE_R0,,[ppc_thread_state_t has
> field r0]),,
> + [#include <mach/thread_status.h>])
> + AC_CHECK_MEMBER(ppc_thread_state_t.__r0,
> + AC_DEFINE(HAS_PPC_THREAD_STATE___R0,,dnl
> + [ppc_thread_state_t has field __r0]),,
> + [#include <mach/thread_status.h>])
> + AC_CHECK_MEMBER(ppc_thread_state64_t.r0,
> + AC_DEFINE(HAS_PPC_THREAD_STATE64_R0,,dnl
> + [ppc_thread_state64_t has field r0]),,
> + [#include <mach/thread_status.h>])
> + AC_CHECK_MEMBER(ppc_thread_state64_t.__r0,
> + AC_DEFINE(HAS_PPC_THREAD_STATE64___R0,,dnl
> + [ppc_thread_state64_t has field __r0]),,
> + [#include <mach/thread_status.h>])
> + ;;
> + i?86*-*-darwin*)
> + AC_CHECK_MEMBER(i386_thread_state_t.eax,
> + AC_DEFINE(HAS_I386_THREAD_STATE_EAX,,dnl
> + [i386_thread_state_t has field eax]),,
> + [#include <mach/thread_status.h>])
> + AC_CHECK_MEMBER(i386_thread_state_t.__eax,
> + AC_DEFINE(HAS_I386_THREAD_STATE___EAX,,dnl
> + [i386_thread_state_t has field __eax]),,
> + [#include <mach/thread_status.h>])
> + ;;
> + *) ;;
> +esac
> +
> # We never want libdl on darwin. It is a fake libdl that just ends
> up making
> # dyld calls anyway
> case "$host" in
> ============================================================
More information about the Gcc-patches
mailing list