Running opt passes via Clang on OSX dlclose segfault issue


I would like to be able to run the LLVMHello pass (modified to be registered as a standard pass) via clang on OSX, but I am not able to do so because during llvm_shutdown there is a segfault.

I have traced the issue to the fact that in the StaticList (ManagedStatic.cpp) cleanup dlclose gets called on the library followed by the destructor for the std::function stored in the GlobalExtensions (PassManagerBuilder.h) vector, leading to a bad access since the library has been unloaded. On Linux this can be worked around by linking with -znodelete, but on OSX, as far as I can tell, there is not an equivalent linker flag.

The easiest solution I was able to come up with, but that likely isn’t acceptable, is to just pass RTLD_NODELETE to the dlopen arguments in

I am willing to fix this and submit a patch if the work required is not too large, but first I want to see what the general opinion on this issue is and get some guidance on what an acceptable fix would be.

-Cannada Lewis