diff --git a/src/system/runtime_loader/elf.cpp b/src/system/runtime_loader/elf.cpp index 907c6a2ad0..e8d8af9657 100644 --- a/src/system/runtime_loader/elf.cpp +++ b/src/system/runtime_loader/elf.cpp @@ -612,7 +612,18 @@ unload_library(void* handle, image_id imageID, bool addOn) if (status == B_OK) { while ((image = get_disposable_images().head) != NULL) { - // call image fini here... + // Call the exit hooks that live in this image. + // Note: With the Itanium ABI this shouldn't really be done this + // way anymore, since global destructors are registered via + // __cxa_atexit() (the ones that are registered dynamically) and the + // termination routine should call __cxa_finalize() for the image. + // The reason why we still do it is that hooks registered with + // atexit() aren't associated with the image. We could find out + // there which image the hooks lives in and register it + // respectively, but since that would be done always, that's + // probably more expensive than calling + // call_atexit_hooks_for_range() only here, which happens only when + // libraries are unloaded dynamically. if (gRuntimeLoader.call_atexit_hooks_for_range) { gRuntimeLoader.call_atexit_hooks_for_range( image->regions[0].vmstart, image->regions[0].vmsize);