[Gc] porting Hans Boehm GC to MacOSX

Boehm, Hans hans_boehm@hp.com
Mon, 10 Feb 2003 10:46:28 -0800

The garbage collector currently has two major deficiencies on MacOSX:

1) Lack of dynamic library support.  It looks like this requires real work, since MacOSX chose not to use the ELF executable file format.  Until someone fixes this, the collector won't see pointers in dynamic library data sections.  The fix involves devising a way to enumerate these data sections.  (Something like dl_iterate_phdr() in glibc.) Once you have that, the rest is easy.

2) Pthread support.

Both of these have been discussed on the java@gcc.gnu.org mailing list.

As far as pthread support is concerned, I would like to see the linux_threads.c code turn into generic pthread support.  I think it's very close.  As the comments say, it relies on pthread internals, but currently only to a small extent.  The code currently supports some very different pthread implementations, though admittedly with a few ifdefs here and there.  (The Irix support code is different only because I couldn't test the result if I reintegrated it.  The Solaris thread support code is currently very different for historical reasons, and the issues there are more complicated.  But I believe linux_threads.c could be made to work with modern Solaris versions as well.)

I'm not a Darwin expert, but here's what I gathered from other discussions:
Things appear to be complicated by the fact that at least early releases didn't contain a full pthread implementation.  In particular, signals  and pthread_kill were not really supported.  The collector relies on those.  It seemed possible to work around that by reaching into the underlying Mach layer, but documentation for that seemed scarce.  I'm not sure if/when that was fixed.  It may be acceptable just to ignore that problem for now.  If so, the FreeBSD code may be close.  If you need to deal with the Mach layer, there's a lot more work to be done.

My suggestion would be:

1) I would start with the most recent GC version, i.e. 6.2alpha3.  I think it contains some relevant fixes.

2) Introduce a GC_MACOSX_THREADS macro that's used analogously to the GC_FREEBSD_THREADS macro.  Initially handle both in the same way.  (But use the existing FREEBSD definitions of DATASTART, etc.  Handle MACOSX like FREEBSD, but don't tell the collector that MACOSX is FREEBSD.)

3) Add a suitable definitions of SIG_SUSPEND (in gc_priv.h).  (Ideally this should probably be moved to gcconfig.h)  It looks like SIG_THR_RESTART is getting defined to SIGXCPU in linux_threads.c.  I would guess that's OK.


> -----Original Message-----
> From: Renaud Blanch [mailto:renaud.blanch@laposte.net]
> Sent: Sunday, February 09, 2003 9:24 AM
> To: gc@napali.hpl.hp.com
> Subject: [Gc] porting Hans Boehm GC to MacOSX
> I'm porting a c++ library using gc to Jaguar.
> I use fink's port of the lib (gc-6.1-3 avaible in the 
> unstable branch) 
> and it works great except for one thing :
> The lib is not compiled with pthread support, which I need.
> The trouble is that gc relies on pthread's implementation specificic 
> features.
> Since Darwin is based on FreeBSD sources I tried to use 
> -DGC_FREEBSD_THREADS but SIGRTMIN is then undefined and 
> there's issues 
> with DATASTART and DATAEND definitions (conflicts between MACOSX and 
> FREEBSD definitions ?).
> So my question is :
> Has someone already done that work ?
> If not, I'm interessed in doing it but I'm not familar with Darwin 
> pthread internals so ... can someone interessed help me to 
> contribute a 
> patch to gc ?
> I need advice on
> - starting from FreeBSD code a good option ?
> - what is SIGRTMIN ?
> - ...
> Renaud
> --
> renaud.blanch@lri.fr
> http://www.lri.fr/~blanch/
> _______________________________________________
> Gc mailing list
> Gc@linux.hpl.hp.com
> http://linux.hpl.hp.com/cgi-bin/mailman/listinfo/gc