Cannot dlopen a library linked with CoreFoundation in a non-main thread

Number:rdar://7209349 Date Originated:9/9/2009
Status:Open Resolved:
Product:MacOS X Product Version:10.6
Classification:Crash Reproducible:Always
One cannot call dlopen a library linked with CoreFoundation in a (sub) thread if CoreFoundation wasn't initialized in the first place. CFInitialize is called, apparently checks if the thread is the main thread and if it is not, crashes with a SIGTRAP.

Steps to Reproduce:
1. Create a shared library linked with CoreFoundation framework.
2. Create a program that is not linked with CoreFoundation and that dlopen-s the above-mentioned library in a thread.

Expected Results:
This should open the library.

Actual Results:
The process crashes.

This didn't occur with MacOS X 10.5.x.


Bug closed

Report was closed on 29-Mar-2013 03:14 PM It seems it cannot be reproduced with 10.9

A few workarounds

1) link the CoreFoundation library into the application so it gets loaded (and initialized) at runtime in the main thread. The main application thread does not need to make any API calls into the CoreFoundation library....simply loading it is sufficient.

2) Use the DYLD_INSERT_LIBRARIES environment variable to specify the CoreFoundation library be pre-loaded when starting the application. (see DYLD(1) man page) ex: % DYLD_INSERT_LIBRARIES=/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation % export DYLD_INSERT_LIBRARIES % app

By blade.doyle at Feb. 8, 2012, 1:40 a.m. (reply...)

I also get this error.

CFInitialize crashes with a SIGTRAP for me too.

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!