[Gc] Dynamic lib support for GC on MacOSX

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


Ok, more problems with my code.

If GC_init() is called from the init method of a dylib that itself is  
linked with other dylibs that need the garbage collector too, we can  
crash the GC before GC_init() finishes.

I have liblk.dylib with an init method (-init oft_init2 passed on link  
line for the dylib) that calls GC_init(). I also have libcommon.dylib  
with an init method (-init oft_init1 passed on the link line for the  
dylib) that also calls GC_init(). The call to  
_dyld_bind_fully_image_containing_address() in GC_init_dyld() triggers  
the dynamic loader again which results in this stacktrace and segfault.  
The segfault occurs while trying to call the GC before initialization  
has finished, during a second reentrant loading of the liblk.dylib.

Andy

PS. Can a bundle have an init method like a dylib can? The initial  
bundle being loaded via NSLinkModule() does not call GC_init() since I  
figured it was linked with liblk.dylib and libcommon.dylib which did.

PPS. I don't have control over the application binary to make it call  
GC_init(). This is an XEmacs plug-in module.


Program received signal EXC_BAD_ACCESS, Could not access memory.
0x01cadc84 in single_client_gc_alloc_template<0>::allocate(unsigned  
long) (n=17) at /usr/local/include/gc/new_gc_alloc.h:199
199                 if (0 == (op = *flh)) {
(gdb) bt
#0  0x01cadc84 in single_client_gc_alloc_template<0>::allocate(unsigned  
long) (n=17) at /usr/local/include/gc/new_gc_alloc.h:199
#1  0x01cadb88 in gc_typed_allocator<char>::allocate(unsigned long,  
void const*) (this=0xbfffb264, n=17, hint=0x0) at ../alloc/alloc.h:234
#2  0x01cadb08 in std::basic_string<char, std::char_traits<char>,  
gc_typed_allocator<char> >::_Rep::_S_create(unsigned long,  
gc_typed_allocator<char> const&) (__capacity=4, __alloc=@0xbfffb4a0) at  
/usr/include/gcc/darwin/3.3/c++/bits/basic_string.tcc:443
#3  0x01cad5b4 in char* std::basic_string<char, std::char_traits<char>,  
gc_typed_allocator<char> >::_S_construct<char const*>(char const*, char  
const*, gc_typed_allocator<char> const&, std::forward_iterator_tag)  
(__beg=0x1c90774 "Grey", __end=0x1c90778 "", __a=@0xbfffb4a0) at  
/usr/include/gcc/darwin/3.3/c++/bits/basic_string.tcc:150
#4  0x01cad408 in char* std::basic_string<char, std::char_traits<char>,  
gc_typed_allocator<char> >::_S_construct_aux<char const*>(char const*,  
char const*, gc_typed_allocator<char> const&, __false_type)  
(__beg=0x1c90774 "Grey", __end=0x1c90778 "", __a=@0xbfffb4a0) at  
/usr/include/gcc/darwin/3.3/c++/bits/basic_string.h:754
#5  0x01cad340 in char* std::basic_string<char, std::char_traits<char>,  
gc_typed_allocator<char> >::_S_construct<char const*>(char const*, char  
const*, gc_typed_allocator<char> const&) (__beg=0x1c90774 "Grey",  
__end=0x1c90778 "", __a=@0xbfffb4a0) at  
/usr/include/gcc/darwin/3.3/c++/bits/basic_string.h:771
#6  0x01cad21c 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:228
#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
#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
#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 ()
#29 0x00069170 in dll_open (fname=0xbfffc110  
"/Users/abegel/Developer/harmonia/src/Library/Application  
Support/Harmonia/PlugIns/Harmonia_XEmacs.adapter/Contents/MacOS/ 
libHarmonia_XEmacs.dylib") at sysdll.c:271
#30 0x00069444 in emodules_load (module=0xffffffd0 <Address 0xffffffd0  
out of bounds>, modname=0x187a28 "", modver=0x187a28 "") at  
emodules.c:349
#31 0x00069b18 in Fload_module (file=6, name=17, version=0) at  
emodules.c:103


On Saturday, June 28, 2003, at 03:16  PM, Brian Alliet wrote:

> On Saturday, June 28, 2003, at 06:11  PM, Andrew Begel wrote:
>
>> Thank you very much. GC_init() did the trick.
>
> great!
>
>> Question, is it dangerous to call GC_init() more than once?
>
> Nope. After you call it the first time its basically a noop. All it'll  
> do is acquire the gc lock, check a few flags and return.
>
> -Brian
>
> _______________________________________________
> Gc mailing list
> Gc@linux.hpl.hp.com
> http://linux.hpl.hp.com/cgi-bin/mailman/listinfo/gc
>

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