]> git.ipfire.org Git - thirdparty/gcc.git/blame - boehm-gc/doc/README.darwin
re PR target/78594 (Bug in November 11th, 2016 change to rs6000.md)
[thirdparty/gcc.git] / boehm-gc / doc / README.darwin
CommitLineData
54f28c21
BM
16.5 update:
2I disabled incremental GC on Darwin in this version, since I couldn't
3get gctest to pass when the GC was built as a dynamic library. Building
4with -DMPROTECT_VDB (and threads) on the command line should get you
5back to the old state. - HB
6
7./configure --enable-cplusplus results in a "make check" failure, probably
8because the ::delete override ends up in a separate dl, and Darwin dynamic
9loader semantics appear to be such that this is not really visible to the
10main program, unlike on ELF systems. Someone who understands dynamic
11loading needs to lookat this. For now, gc_cpp.o needs to be linked
12statically, if needed. - HB
13
aa7a966b
BM
14Darwin/MacOSX Support - December 16, 2003
15=========================================
6991c6c9
JS
16
17Important Usage Notes
18=====================
19
20GC_init() MUST be called before calling any other GC functions. This
21is necessary to properly register segments in dynamic libraries. This
22call is required even if you code does not use dynamic libraries as the
23dyld code handles registering all data segments.
24
25When your use of the garbage collector is confined to dylibs and you
26cannot call GC_init() before your libraries' static initializers have
27run and perhaps called GC_malloc(), create an initialization routine
28for each library to call GC_init():
29
30#include <gc/gc.h>
aa7a966b 31extern "C" void my_library_init() { GC_init(); }
6991c6c9
JS
32
33Compile this code into a my_library_init.o, and link it into your
34dylib. When you link the dylib, pass the -init argument with
35_my_library_init (e.g. gcc -dynamiclib -o my_library.dylib a.o b.o c.o
36my_library_init.o -init _my_library_init). This causes
37my_library_init() to be called before any static initializers, and
38will initialize the garbage collector properly.
39
40Note: It doesn't hurt to call GC_init() more than once, so it's best,
41if you have an application or set of libraries that all use the
42garbage collector, to create an initialization routine for each of
43them that calls GC_init(). Better safe than sorry.
44
45The incremental collector is still a bit flaky on darwin. It seems to
46work reliably with workarounds for a few possible bugs in place however
47these workaround may not work correctly in all cases. There may also
48be additional problems that I have not found.
49
aa7a966b
BM
50Thread-local GC allocation will not work with threads that are not
51created using the GC-provided override of pthread_create(). Threads
52created without the GC-provided pthread_create() do not have the
53necessary data structures in the GC to store this data.
54
55
6991c6c9
JS
56Implementation Information
57==========================
58Darwin/MacOSX support is nearly complete. Thread support is reliable on
59Darwin 6.x (MacOSX 10.2) and there have been reports of success on older
60Darwin versions (MacOSX 10.1). Shared library support had also been
61added and the gc can be run from a shared library. There is currently only
62support for Darwin/PPC although adding x86 support should be trivial.
63
aa7a966b 64Thread support is implemented in terms of mach thread_suspend and
6991c6c9
JS
65thread_resume calls. These provide a very clean interface to thread
66suspension. This implementation doesn't rely on pthread_kill so the
aa7a966b
BM
67code works on Darwin < 6.0 (MacOSX 10.1). All the code to stop and
68start the world is located in darwin_stop_world.c.
69
70Since not all uses of the GC enable clients to override pthread_create()
71before threads have been created, the code for stopping the world has
72been rewritten to look for threads using Mach kernel calls. Each
73thread identified in this way is suspended and resumed as above. In
74addition, since Mach kernel threads do not contain pointers to their
75stacks, a stack-walking function has been written to find the stack
76limits. Given an initial stack pointer (for the current thread, a
77pointer to a stack-allocated local variable will do; for a non-active
78thread, we grab the value of register 1 (on PowerPC)), it
79will walk the PPC Mach-O-ABI compliant stack chain until it reaches the
80top of the stack. This appears to work correctly for GCC-compiled C,
81C++, Objective-C, and Objective-C++ code, as well as for Java
82programs that use JNI. If you run code that does not follow the stack
83layout or stack pointer conventions laid out in the PPC Mach-O ABI,
84then this will likely crash the garbage collector.
6991c6c9
JS
85
86The original incremental collector support unfortunatelly no longer works
87on recent Darwin versions. It also relied on some undocumented kernel
88structures. Mach, however, does have a very clean interface to exception
89handing. The current implementation uses Mach's exception handling.
90
91Much thanks goes to Andrew Stone, Dietmar Planitzer, Andrew Begel,
92Jeff Sturm, and Jesse Rosenstock for all their work on the
93Darwin/OS X port.
94
95-Brian Alliet
96brian@brianweb.net
97
98
99Older Information (Most of this no longer applies to the current code)
100======================================================================
101
102While the GC should work on MacOS X Server, MacOS X and Darwin, I only tested
103it on MacOS X Server.
104I've added a PPC assembly version of GC_push_regs(), thus the setjmp() hack is
105no longer necessary. Incremental collection is supported via mprotect/signal.
106The current solution isn't really optimal because the signal handler must decode
107the faulting PPC machine instruction in order to find the correct heap address.
108Further, it must poke around in the register state which the kernel saved away
109in some obscure register state structure before it calls the signal handler -
110needless to say the layout of this structure is no where documented.
111Threads and dynamic libraries are not yet supported (adding dynamic library
112support via the low-level dyld API shouldn't be that hard).
113
114The original MacOS X port was brought to you by Andrew Stone.
115
116
117June, 1 2000
118
119Dietmar Planitzer
120dave.pl@ping.at
121
122Note from Andrew Begel:
123
124One more fix to enable gc.a to link successfully into a shared library for
125MacOS X. You have to add -fno-common to the CFLAGS in the Makefile. MacOSX
126disallows common symbols in anything that eventually finds its way into a
127shared library. (I don't completely understand why, but -fno-common seems to
128work and doesn't mess up the garbage collector's functionality).
129
130Feb 26, 2003
131
132Jeff Sturm and Jesse Rosenstock provided a patch that adds thread support.
133GC_MACOSX_THREADS should be defined in the build and in clients. Real
134dynamic library support is still missing, i.e. dynamic library data segments
135are still not scanned. Code that stores pointers to the garbage collected
136heap in statically allocated variables should not reside in a dynamic
137library. This still doesn't appear to be 100% reliable.
138
139Mar 10, 2003
140Brian Alliet contributed dynamic library support for MacOSX. It could also
141use more testing.