1Lars Farm's suggestions on building the collector: 2---------------------------------------------------------------------------- 3Garbage Collection on MacOS - a manual 'MakeFile' 4------------------------------------------------- 5 6Project files and IDE's are great on the Macintosh, but they do have 7problems when used as distribution media. This note tries to provide 8porting instructions in pure TEXT form to avoid those problems. A manual 9'makefile' if you like. 10 11 GC version: 4.12a2 12 Codewarrior: CWPro1 13 date: 18 July 1997 14 15The notes may or may not apply to earlier or later versions of the 16GC/CWPro. Actually, they do apply to earlier versions of both except that 17until recently a project could only build one target so each target was a 18separate project. The notes will most likely apply to future versions too. 19Possibly with minor tweaks. 20 21This is just to record my experiences. These notes do not mean I now 22provide a supported port of the GC to MacOS. It works for me. If it works 23for you, great. If it doesn't, sorry, try again...;-) Still, if you find 24errors, please let me know. 25 26 mailto: lars.farm@ite.mh.se 27 28 address: Lars Farm 29 Kr�nv�gen 33b 30 856 44 Sundsvall 31 Sweden 32 33Porting to MacOS is a bit more complex than it first seems. Which MacOS? 3468K/PowerPC? Which compiler? Each supports both 68K and PowerPC and offer a 35large number of (unique to each environment) compiler settings. Each 36combination of compiler/68K/PPC/settings require a unique combination of 37standard libraries. And the IDE's does not select them for you. They don't 38even check that the library is built with compatible setting and this is 39the major source of problems when porting the GC (and otherwise too). 40 41You will have to make choices when you configure the GC. I've made some 42choices here, but there are other combinations of settings and #defines 43that work too. 44 45As for target settings the major obstacles may be: 46- 68K Processor: check "4-byte Ints". 47- PPC Processor: uncheck "Store Static Data in TOC". 48 49What you need to do: 50=================== 51 521) Build the GC as a library 532) Test that the library works with 'test.c'. 543) Test that the C++ interface 'gc_cpp.cc/h' works with 'test_cpp.cc'. 55 561) The Libraries: 57================= 58I made one project with four targets (68K/PPC tempmem or appheap). One target 59will suffice if you're able to decide which one you want. I wasn't... 60 61Codewarrior allows a large number of compiler/linker settings. I used these: 62 63Settings shared by all targets: 64------------------------------ 65o Access Paths: 66 - User Paths: the GC folder 67 - System Paths: {Compiler}:Metrowerks Standard Library: 68 {Compiler}:MacOS Support:Headers: 69 {Compiler}:MacOS Support:MacHeaders: 70o C/C++ language: 71 - inlining: normal 72 - direct to SOM: off 73 - enable/check: exceptions, RTTI, bool (and if you like pool strings) 74 75PowerPC target settings 76----------------------- 77o Target Settings: 78 - name of target 79 - MacOS PPC Linker 80o PPC Target 81 - name of library 82o C/C++ language 83 - prefix file as described below 84o PPC Processor 85 - Struct Alignment: PowerPC 86 - uncheck "Store Static Data in TOC" -- important! 87 I don't think the others matter, I use full optimization and its ok 88o PPC Linker 89 - Factory Settings (SYM file with full paths, faster linking, dead-strip 90 static init, Main: __start) 91 92 9368K target settings 94------------------- 95o Target Settings: 96 - name of target 97 - MacOS 68K Linker 98o 68K Target 99 - name of library 100 - A5 relative data 101o C/C++ language 102 - prefix file as described below 103o 68K Processor 104 - Code model: smart 105 - Struct alignment: 68K 106 - FP: SANE 107 - enable 4-Byte Ints -- important! 108 I don't think the others matter. I selected... 109 - enable: 68020 110 - enable: global register allocation 111o IR Optimizer 112 - enable: Optimize Space, Optimize Speed 113 I suppose the others would work too, but haven't tried... 114o 68K Linker 115 - Factory Settings (New Style MacsBug,SYM file with full paths, 116 A6 Frames, fast link, Merge compiler glue into segment 1, 117 dead-strip static init) 118 119Prefix Files to configure the GC sources 120---------------------------------------- 121The Codewarrior equivalent of commandline compilers -DNAME=X is to use 122prefix-files. A TEXT file that is automatically #included before the first byte 123of every source file. I used these: 124 125---- ( cut here ) ---- gc_prefix_tempmem.h -- 68K and PPC ----- 126 #include "gc_prefix_common.h" 127 #undef USE_TEMPORARY_MEMORY 128 #define USE_TEMPORARY_MEMORY 129---- ( cut here ) ---- gc_prefix_appmem.h -- 68K and PPC ----- 130 #include "gc_prefix_common.h" 131 #undef USE_TEMPORARY_MEMORY 132// #define USE_TEMPORARY_MEMORY 133 134---- ( cut here ) ---- gc_prefix_common.h -------------------- 135// gc_prefix_common.h 136// ------------------ 137// Codewarrior prefix file to configure the GC libraries 138// 139// prefix files are the Codewarrior equivalent of the 140// command line option -Dname=x frequently seen in makefiles 141 142#if !__MWERKS__ 143 #error only tried this with Codewarrior 144#endif 145 146#if macintosh 147 #define MSL_USE_PRECOMPILED_HEADERS 0 148 #include <ansi_prefix.mac.h> 149 #ifndef __STDC__ 150 #define __STDC__ 0 151 #endif 152 153 // See list of #defines to configure the library in: 'MakeFile' 154 // see also README 155 156 #define SILENT // no collection messages. In case 157 // of trouble you might want this off 158 #define ALL_INTERIOR_POINTERS // follows interior pointers. 159//#define DONT_ADD_BYTE_AT_END // disables the padding if defined. 160//#define SMALL_CONFIG // whether to use a smaller heap. 161 #define NO_SIGNALS // signals aren't real on the Macintosh. 162 #define ATOMIC_UNCOLLECTABLE // GC_malloc_atomic_uncollectable() 163 164 // define either or none as per personal preference 165 // used in malloc.c 166 #define REDIRECT_MALLOC GC_malloc 167//#define REDIRECT_MALLOC GC_malloc_uncollectable 168 // if REDIRECT_MALLOC is #defined make sure that the GC library 169 // is listed before the ANSI/ISO libs in the Codewarrior 170 // 'Link order' panel 171//#define IGNORE_FREE 172 173 // mac specific configs 174//#define USE_TEMPORARY_MEMORY // use Macintosh temporary memory. 175//#define SHARED_LIBRARY_BUILD // build for use in a shared library. 176 177#else 178 // could build Win32 here too, or in the future 179 // Rhapsody PPC-mach, Rhapsody PPC-MacOS, 180 // Rhapsody Intel-mach, Rhapsody Intel-Win32,... 181 // ... ugh this will get messy ... 182#endif 183 184// make sure ints are at least 32-bit 185// ( could be set to 16-bit by compiler settings (68K) ) 186 187struct gc_private_assert_intsize_{ char x[ sizeof(int)>=4 ? 1 : 0 ]; }; 188 189#if __powerc 190 #if __option(toc_data) 191 #error turn off "store static data in TOC" when using GC 192 // ... or find a way to add TOC to the root set...(?) 193 #endif 194#endif 195---- ( cut here ) ---- end of gc_prefix_common.h ----------------- 196 197Files to build the GC libraries: 198-------------------------------- 199 allchblk.c 200 alloc.c 201 blacklst.c 202 checksums.c 203 dbg_mlc.c 204 finalize.c 205 headers.c 206 mach_dep.c 207 MacOS.c -- contains MacOS code 208 malloc.c 209 mallocx.c 210 mark.c 211 mark_rts.c 212 misc.c 213 new_hblk.c 214 obj_map.c 215 os_dep.c -- contains MacOS code 216 ptr_chck.c 217 reclaim.c 218 stubborn.c 219 typd_mlc.c 220 gc++.cc -- this is 'gc_cpp.cc' with less 'inline' and 221 -- throw std::bad_alloc when out of memory 222 -- gc_cpp.cc works just fine too 223 2242) Test that the library works with 'test.c'. 225============================================= 226 227The test app is just an ordinary ANSI-C console app. Make sure settings 228match the library you're testing. 229 230Files 231----- 232 test.c 233 the GC library to test -- link order before ANSI libs 234 suitable Mac+ANSI libraries 235 236prefix: 237------ 238---- ( cut here ) ---- gc_prefix_testlib.h -- all libs ----- 239#define MSL_USE_PRECOMPILED_HEADERS 0 240#include <ansi_prefix.mac.h> 241#undef NDEBUG 242 243#define ALL_INTERIOR_POINTERS /* for GC_priv.h 244---- ( cut here ) ---- 245 2463) Test that the C++ interface 'gc_cpp.cc/h' works with 'test_cpp.cc'. 247 248The test app is just an ordinary ANSI-C console app. Make sure settings match 249the library you're testing. 250 251Files 252----- 253 test_cpp.cc 254 the GC library to test -- link order before ANSI libs 255 suitable Mac+ANSI libraries 256 257prefix: 258------ 259same as for test.c 260 261For convenience I used one test-project with several targets so that all 262test apps are build at once. Two for each library to test: test.c and 263gc_app.cc. When I was satisfied that the libraries were ok. I put the 264libraries + gc.h + the c++ interface-file in a folder that I then put into 265the MSL hierarchy so that I don't have to alter access-paths in projects 266that use the GC. 267 268After that, just add the proper GC library to your project and the GC is in 269action! malloc will call GC_malloc and free GC_free, new/delete too. You 270don't have to call free or delete. You may have to be a bit cautious about 271delete if you're freeing other resources than RAM. See gc_cpp.h. You can 272also keep coding as always with delete/free. That works too. If you want, 273"include <gc.h> and tweak it's use a bit. 274 275Symantec SPM 276============ 277It has been a while since I tried the GC in SPM, but I think that the above 278instructions should be sufficient to guide you through in SPM too. SPM 279needs to know where the global data is. Use the files 'datastart.c' and 280'dataend.c'. Put 'datastart.c' at the top of your project and 'dataend.c' 281at the bottom of your project so that all data is surrounded. This is not 282needed in Codewarrior because it provides intrinsic variables 283__datastart__, __data_end__ that wraps all globals. 284 285Source Changes (GC 4.12a2) 286========================== 287Very few. Just one tiny in the GC, not strictly needed. 288- MacOS.c line 131 in routine GC_MacFreeTemporaryMemory() 289 change # if !defined(SHARED_LIBRARY_BUILD) 290 to # if !defined(SILENT) && !defined(SHARED_LIBRARY_BUILD) 291 To turn off a message when the application quits (actually, I faked 292 this change by #defining SHARED_LIBRARY_BUILD in a statically linked 293 library for more than a year without ill effects but perhaps this is 294 better). 295 296- test_cpp.cc 297 made the first lines of main() look like this: 298 ------------ 299 int main( int argc, char* argv[] ) { 300 #endif 301 #if macintosh // MacOS 302 char* argv_[] = {"test_cpp","10"}; // doesn't 303 argv=argv_; // have a 304 argc = sizeof(argv_)/sizeof(argv_[0]); // commandline 305 #endif // 306 307 int i, iters, n; 308 # ifndef __GNUC__ 309 alloc dummy_to_fool_the_compiler_into_doing_things_it_currently_cant_handle; 310 ------------ 311 312- config.h 313 __MWERKS__ does not have to mean MACOS. You can use Codewarrior to 314 build a Win32 or BeOS library and soon a Rhapsody library. You may 315 have to change that #if... 316 317 318 319 It worked for me, hope it works for you. 320 321 Lars Farm 322 18 July 1997 323---------------------------------------------------------------------------- 324 325 326Patrick Beard's instructions (may be dated): 327 328v4.3 of the collector now runs under Symantec C++/THINK C v7.0.4, and 329Metrowerks C/C++ v4.5 both 68K and PowerPC. Project files are provided 330to build and test the collector under both development systems. 331 332Configuration 333------------- 334 335To configure the collector, under both development systems, a prefix file 336is used to set preprocessor directives. This file is called "MacOS_config.h". 337Also to test the collector, "MacOS_Test_config.h" is provided. 338 339Testing 340------- 341 342To test the collector (always a good idea), build one of the gctest projects, 343gctest.� (Symantec C++/THINK C), mw/gctest.68K.�, or mw/gctest.PPC.�. The 344test will ask you how many times to run; 1 should be sufficient. 345 346Building 347-------- 348 349For your convenience project files for the major Macintosh development 350systems are provided. 351 352For Symantec C++/THINK C, you must build the two projects gclib-1.� and 353gclib-2.�. It has to be split up because the collector has more than 32k 354of static data and no library can have more than this in the Symantec 355environment. (Future versions will probably fix this.) 356 357For Metrowerks C/C++ 4.5 you build gc.68K.�/gc.PPC.� and the result will 358be a library called gc.68K.lib/gc.PPC.lib. 359 360Using 361----- 362 363Under Symantec C++/THINK C, you can just add the gclib-1.� and gclib-2.� 364projects to your own project. Under Metrowerks, you add gc.68K.lib or 365gc.PPC.lib and two additional files. You add the files called datastart.c 366and dataend.c to your project, bracketing all files that use the collector. 367See mw/gctest.� for an example. 368 369Include the projects/libraries you built above into your own project, 370#include "gc.h", and call GC_malloc. You don't have to call GC_free. 371 372 373Patrick C. Beard 374January 4, 1995 375