README.Mac 13 KB

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