Skip to content

segfault when unloading a shared library

1 message · EJ Nikelski

#
Dear List,

   Martin, thanks for the extremely useful advice.  As valgrind is not
yet officially available for OS X, I grabbed the 3.5.0 beta from svn,
built it, and gave it a go.  The results were enlightening:

-------------------------------------------------
Unloading shared library: mniMincIO. Library unload path is
/Users/jnikelski/R_libs/2.9/mniMincIO
now dyn.unload("/Users/jnikelski/R_libs/2.9/mniMincIO/libs/i386/mniMincIO.so")
...
Unloading shared library mniMincIO in R_unload_mniMincIO
==3254== Jump to the invalid address stated on the next line
==3254==    at 0x80765E0: ???
==3254==    by 0x8090430: H5_term_library (in
/usr/local/bic/2009.08.10/lib/libhdf5.0.0.0.dylib)
==3254==    by 0x653DC6: __cxa_finalize (in /usr/lib/libSystem.B.dylib)
==3254==    by 0x68983E: dwarf2_unwind_dyld_remove_image_hook (in
/usr/lib/libSystem.B.dylib)
==3254==    by 0x8FE030D4: dyld::removeImage(ImageLoader*) (in /usr/lib/dyld)
==3254==    by 0x8FE031FD: dyld::garbageCollectImages() (in /usr/lib/dyld)
==3254==    by 0x8FE0BE05: dlclose (in /usr/lib/dyld)
==3254==    by 0x685E31: dlclose (in /usr/lib/libSystem.B.dylib)
==3254==    by 0x31ACDC: DeleteDLL (in
/Library/Frameworks/R.framework/Versions/2.9/Resources/lib/libR.dylib)
==3254==    by 0x31BA95: do_dynunload (in
/Library/Frameworks/R.framework/Versions/2.9/Resources/lib/libR.dylib)
==3254==    by 0x3F267E: do_internal (in
/Library/Frameworks/R.framework/Versions/2.9/Resources/lib/libR.dylib)
==3254==    by 0x3B7337: Rf_eval (in
/Library/Frameworks/R.framework/Versions/2.9/Resources/lib/libR.dylib)
==3254==  Address 0x80765e0 is not stack'd, malloc'd or (recently) free'd
==3254==

 *** caught segfault ***
address 0x0, cause 'memory not mapped'
--------------------------------------

   It would appear that during certain read/write operations, the HDF
lib registers its own clean up call via an atexit() routine.  The
unload of the upstream library (mniMincIO, in this case) appears to
trigger the atexit() HDF routine ... however, the HDF library is
already unloaded ... causing a jump into oblivion.

   There are 2 possible solutions that are immediately obvious to me:
(1) use the H5dont_atexit() function to prevent the registering of the
cleanup function, and/or (2) find some way of forcing the HDF library
not to unload.  I would prefer (2), but am not sophisticated enough to
figure out the best way to do this.  Any Mac experts following this
thread?  Simon?

Cheers,

-Jim
On Thu, Aug 13, 2009 at 3:44 PM, Martin Morgan<mtmorgan at fhcrc.org> wrote: