implemented Setup.hs to build boehm cpp libs and install them;
[hs-boehmgc.git] / gc-7.2 / doc / README.win32
1 The collector has at various times been compiled under Windows 95 & later, NT,
2 and XP, with the original Microsoft SDK, with Visual C++ 2.0, 4.0, and 6, with
3 the GNU win32 tools, with Borland 4.5,  with Watcom C, and recently
4 with the Digital Mars compiler.  It is likely that some of these have been
5 broken in the meantime.  Patches are appreciated.
6
7 For historical reasons,
8 the collector test program "gctest" is linked as a GUI application,
9 but does not open any windows.  Its output normally appears in the file
10 "gctest.gc.log".  It may be started from the file manager.  The hour glass
11 cursor may appear as long as it's running.  If it is started from the
12 command line, it will usually run in the background.  Wait a few
13 minutes (a few seconds on a modern machine) before you check the output.
14 You should see either a failure indication or a "Collector appears to
15 work" message.
16
17 The cord test program has not been ported (but should port
18 easily).  A toy editor (cord/de.exe) based on cords (heavyweight
19 strings represented as trees) has been ported and is included.
20 It runs fine under either win32 or win32S.  It serves as an example
21 of a true Windows application, except that it was written by a
22 nonexpert Windows programmer.  (There are some peculiarities
23 in the way files are displayed.  The <cr> is displayed explicitly
24 for standard DOS text files.  As in the UNIX version, control
25 characters are displayed explicitly, but in this case as red text.
26 This may be suboptimal for some tastes and/or sets of default
27 window colors.)
28
29 In general -DREDIRECT_MALLOC is unlikely to work unless the
30 application is completely statically linked.
31
32 The collector normally allocates memory from the OS with VirtualAlloc.
33 This appears to cause problems under Windows NT and Windows 2000 (but
34 not Windows 95/98) if the memory is later passed to CreateDIBitmap.
35 To work around this problem, build the collector with -DUSE_GLOBAL_ALLOC.
36 This is currently incompatible with -DUSE_MUNMAP.  (Thanks to Jonathan
37 Clark for tracking this down.  There's some chance this may be fixed
38 in 6.1alpha4, since we now separate heap sections with an unused page.)
39
40 [Threads and incremental collection are discussed near the end, below.]
41
42 Microsoft Tools
43 ---------------
44 For Microsoft development tools, rename NT_MAKEFILE as
45 MAKEFILE.  (Make sure that the CPU environment variable is defined
46 to be i386.)  In order to use the gc_cpp.h C++ interface, all
47 client code should include gc_cpp.h.
48
49 For historical reasons,
50 the collector test program "gctest" is linked as a GUI application,
51 but does not open any windows.  Its output appears in the file
52 "gctest.gc.log".  It may be started from the file manager.  The hour glass
53 cursor may appear as long as it's running.  If it is started from the
54 command line, it will usually run in the background.  Wait a few
55 minutes (a few seconds on a modern machine) before you check the output.
56 You should see either a failure indication or a "Collector appears to
57 work" message.
58
59 If you would prefer a VC++.NET project file, ask boehm@acm.org.  One has
60 been contributed, but it seems to contain some absolute paths etc., so
61 it can presumably only be a starting point, and is not in the standard
62 distribution.  It is unclear (to me, Hans Boehm) whether it is feasible to
63 change that.
64
65 Clients may need to define GC_NOT_DLL before including gc.h, if the
66 collector was built as a static library (as it normally is in the
67 absence of thread support).
68
69 GNU Tools
70 ---------
71 The collector should be buildable under Cygwin with the
72 "./configure; make check" machinery.
73
74 MinGW builds (including for x86_64) are available via cross-compilation, e.g.
75 "./configure --host=i686-pc-mingw32; make check"
76
77 To build the collector as a DLL, pass "--enable-shared --disable-static" to
78 configure (this will instruct make compile with -D GC_DLL).
79
80 Parallel marker could be enabled via "--enable-parallel-mark".
81
82 Memory unmapping could be enabled via "--enable-munmap" (not well supported
83 on Cygwin currently).
84
85 Borland Tools
86 -------------
87 [Rarely tested.]
88 For Borland tools, use BCC_MAKEFILE.  Note that
89 Borland's compiler defaults to 1 byte alignment in structures (-a1),
90 whereas Visual C++ appears to default to 8 byte alignment (/Zp8).
91 The garbage collector in its default configuration EXPECTS AT
92 LEAST 4 BYTE ALIGNMENT.  Thus the BORLAND DEFAULT MUST
93 BE OVERRIDDEN.  (In my opinion, it should usually be anyway.
94 I expect that -a1 introduces major performance penalties on a
95 486 or Pentium.)  Note that this changes structure layouts.  (As a last
96 resort, gcconfig.h can be changed to allow 1 byte alignment.  But
97 this has significant negative performance implications.)
98 The Makefile is set up to assume Borland 4.5.  If you have another
99 version, change the line near the top.  By default, it does not
100 require the assembler.  If you do have the assembler, I recommend
101 removing the -DUSE_GENERIC.
102
103 Digital Mars compiler
104 ---------------------
105
106 Same as MS Visual C++ but might require
107 -DAO_OLD_STYLE_INTERLOCKED_COMPARE_EXCHANGE option to compile with the
108 parallel marker enabled.
109
110 Watcom compiler
111 ---------------
112
113 Ivan V. Demakov's README for the Watcom port:
114
115 The collector has been compiled with Watcom C 10.6 and 11.0.
116 It runs under win32, win32s, and even under msdos with dos4gw
117 dos-extender. It should also run under OS/2, though this isn't
118 tested. Under win32 the collector can be built either as dll
119 or as static library.
120
121 Note that all compilations were done under Windows 95 or NT.
122 For unknown reason compiling under Windows 3.11 for NT (one
123 attempt has been made) leads to broken executables.
124
125 Incremental collection is not supported.
126
127 cord is not ported.
128
129 Before compiling you may need to edit WCC_MAKEFILE to set target
130 platform, library type (dynamic or static), calling conventions, and
131 optimization options.
132
133 To compile the collector and testing programs use the command:
134     wmake -f WCC_MAKEFILE
135
136 All programs using gc should be compiled with 4-byte alignment.
137 For further explanations on this see comments about Borland.
138
139 If the gc is compiled as dll, the macro ``GC_DLL'' should be defined before
140 including "gc.h" (for example, with -DGC_DLL compiler option). It's
141 important, otherwise resulting programs will not run.
142
143 Ivan Demakov (email: ivan@tgrad.nsk.su)
144
145 Note from Ivan Maidanski:
146
147 Special note for OpenWatcom users: the C (unlike the C++) compiler (of the
148 latest stable release, not sure for older ones) doesn't force pointer global
149 variables (i.e. not struct fields, not sure for locals) to be aligned unless
150 optimizing for speed (eg. "-ot" option is set); the "-zp" option (or align
151 pragma) only controls alignment for structs; I don't know whether it's a bug or
152 a feature (see an old report of same kind -
153 http://bugzilla.openwatcom.org/show_bug.cgi?id=664), so You are warned.
154
155
156 Incremental Collection
157 ----------------------
158 There is some support for incremental collection.  By default, the
159 collector chooses between explicit page protection, and GetWriteWatch-based
160 write tracking automatically, depending on the platform.
161
162 The former is slow and interacts poorly with a debugger.
163 Pages are protected.  Protection faults are caught by a handler
164 installed at the bottom of the handler
165 stack.  Whenever possible, I recommend adding a call to
166 GC_enable_incremental at the last possible moment, after most
167 debugging is complete.  No system
168 calls are wrapped by the collector itself.  It may be necessary
169 to wrap ReadFile calls that use a buffer in the heap, so that the
170 call does not encounter a protection fault while it's running.
171 (As usual, none of this is an issue unless GC_enable_incremental
172 is called.)
173
174 Note that incremental collection is disabled with -DSMALL_CONFIG.
175
176 Threads
177 -------
178
179 This version of the collector by default handles threads similarly
180 to other platforms.  James Clark's code which tracks threads attached
181 to the collector DLL still exists, but requires that both
182 - the collector is built in a DLL with GC_DLL defined, and
183 - GC_use_threads_discovery() is called before GC initialization, which
184   in turn must happen before creating additional threads.
185 We generally recommend avoiding this if possible, since it seems to
186 be less than 100% reliable.
187
188 Use gc.mak (a.k.a NT_THREADS_MAKEFILE) instead of NT_MAKEFILE
189 to build a version that supports both kinds of thread tracking.
190 To build the garbage collector
191 test with VC++ from the command line, use
192
193 nmake /F ".\gc.mak" CFG="gctest - Win32 Release"
194
195 This requires that the subdirectory gctest\Release exist.
196 The test program and DLL will reside in the Release directory.
197
198 This version currently supports incremental collection only if it is
199 enabled before any additional threads are created.
200
201 Since 6.3alpha2, threads are also better supported in static library builds
202 with Microsoft tools (use NT_STATIC_THREADS_MAKEFILE) and with the GNU
203 tools.  The collector must be built with GC_THREADS defined.
204 (NT_STATIC_THREADS_MAKEFILE does this implicitly.  Under Cygwin,
205 ./configure --enable-threads=posix should be used.)
206
207 For the normal, non-dll-based thread tracking to work properly,
208 threads should be created with GC_CreateThread or GC_beginthreadex,
209 and exit normally or call GC_endthreadex or GC_ExitThread.  (For
210 Cygwin, use standard pthread calls instead.)  As in the pthread
211 case, including gc.h will redefine CreateThread, _beginthreadex,
212 _endthreadex, and ExitThread to call the GC_ versions instead.
213
214 Note that, as usual, GC_CreateThread tends to introduce resource leaks
215 that are avoided by GC_beginthreadex.  There is currently no equivalent of
216 _beginthread, and it should not be used.
217
218 GC_INIT should be called from the main executable before other GC calls.
219
220 We strongly advise against using the TerminateThread() win32 API call,
221 especially with the garbage collector.  Any use is likely to provoke a
222 crash in the GC, since it makes it impossible for the collector to
223 correctly track threads.
224
225 To build the collector for Mingw32 Pthreads, use Makefile.direct and
226 explicitly set GC_WIN32_PTHREADS.  Use -DPTW32_STATIC_LIB for the static
227 threads library.