[Gc] Dynamic lib support for GC on MacOSX

Brian Alliet brian@brian-web.com
Mon, 30 Jun 2003 19:52:34 -0400


On Monday, June 30, 2003, at 02:17  PM, Andrew Begel wrote:
[snip]
> #7  0x01cad1a4 in std::basic_string<char, std::char_traits<char>, 
> gc_typed_allocator<char> >::basic_string(char const*, 
> gc_typed_allocator<char> const&) (this=0x1d0948c, __s=0x1c90774 
> "Grey", __a=@0xbfffb4a0) at 
> /usr/include/gcc/darwin/3.3/c++/bits/basic_string.tcc:226

You can't call this until gc_init() completes. I know you aren't 
intentionally calling it, but its happening, and thats whats causing 
the crash.

> #8  0x01c9f6ec in __static_initialization_and_destruction_0(int, int) 
> (__initialize_p=1, __priority=65535) at 
> ../lk/iparser/AbstractIncDebug.h:34
> #9  0x01ca0424 in _GLOBAL__I__Z5dummyPcm () at 
> ../lk/version/VDifferentialImpl.h:101
> #10 0x8fe16594 in __dyld_call_module_initializers_for_objects ()
> #11 0x8fe160a0 in __dyld_call_module_initializers ()
> #12 0x8fe106f0 in __dyld_link_in_need_modules ()
> #13 0x8fe12b94 in __dyld__dyld_bind_fully_image_containing_address ()
> #14 0x90005374 in _dyld_bind_fully_image_containing_address ()
> #15 0x0244e694 in GC_init_dyld () at dyn_load.c:1059
> #16 0x024f29d4 in alloc_init() () at alloc.cc:36
> #17 0x024f2934 in oft_init1 () at macosx.cc:7
> #18 0x8fe0901c in __dyld_call_image_init_routines ()
> #19 0x8fe106e4 in __dyld_link_in_need_modules ()
> #20 0x8fe12b94 in __dyld__dyld_bind_fully_image_containing_address ()
> #21 0x90005374 in _dyld_bind_fully_image_containing_address ()
> #22 0x0244e694 in GC_init_dyld () at dyn_load.c:1059

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.)

> #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)

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!

-Brian