[Gc] Dynamic lib support for GC on MacOSX

Andrew Begel abegel@eecs.berkeley.edu
Mon, 30 Jun 2003 17:06:14 -0700


On Monday, June 30, 2003, at 04:52  PM, Brian Alliet wrote:

> On Monday, June 30, 2003, at 02:17  PM, Andrew Begel wrote:
>
> Are you calling GC_init or GC_init_dyld()? You shouldn't be invoking 
> GC_init_dyld directly. (This may just be that the stacktrace is a 
> little in accurate, if so, ignore that last comment.)

I'm calling GC_init(). The trace is a bit screwy.

>
>> #23 0x03a7e578 in alloc_init() () at alloc.cc:36
>> #24 0x03a7e4d8 in oft_init2 () at macosx.cc:7
>> #25 0x8fe0901c in __dyld_call_image_init_routines ()
>> #26 0x8fe106e4 in __dyld_link_in_need_modules ()
>> #27 0x8fe121a4 in __dyld__dyld_link_module ()
>> #28 0x90016ae8 in NSLinkModule ()
>
> This obviously just isn't working. I think what you are trying to do 
> might be impossible. This dyld init function stuff is a little weird. 
> I have one last idea. It appears you are using c++, so you can setup 
> static initializers. First of all, ditch the whole "-init somemethod" 
> thing (unless you are using it for other stuff, then keep it, but 
> don't put GC_init stuff in there). Then make some class similar to the 
> following (this syntax is probably wrong, I've been doing too much 
> java and not enough c++ lately :), but you get the idea)

I'll give the following a try and see if it works.

>
> static initialized = 0;
> class MyGCInit {
> 	public:
> 		MyGCInit() {
> 			if(initialized) return;
> 			GC_init();
> 			initialized = 1;
> 		}
> };
>
> and add an instance of that class to EVERY module that calls the GC. 
> (just "MyGCInit gcInit"; or something) Be sure to add it BEFORE any 
> other static initialization that might call the GC. This *should* 
> ensure the gc is initialized before any code is run or any other 
> static initializer is run. (Somebody who is more familiar with c++ 
> please correct me if I'm wrong).
>
> If that doesn't work. You'll probably have to modify the emacs source 
> to call GC_init() in main(). Good luck!

Why will putting it in main() work. If you have a binary that links 
against dylibs that need the garbage collector, dyld will link them in 
*before* main() gets a chance to call GC_init(). Thus, this scheme only 
works for loading bundles, not dynamiclibs.

Andrew


>
> -Brian
>
>

-----------
Andrew Begel
Ph.D. Candidate
Computer Science Division
University of California, Berkeley