Although neither documented anywhere nor included in the header files, Mac OS X APIs contain a function named "Sleep" (note the capital letter 'S') that puts the entire computer to sleep. See here: http://www.cocoabuilder.com/archive/xcode/247054-sleep-and-xcode.html
Unfortunately, this function's name clashes with the way my application handles plugins. My plugins are loaded using dlopen() and then dlsym() is used to lookup the individual functions. The problem is that my plugin API is designed in a way that plugins may implement a Sleep() function but this is not compulsory, i.e. there are plugins which export a Sleep() function and there are plugins which don't export a Sleep() function.
Calling
ptr = dlsym(handle, "Sleep");
however, will always succeed on Mac OS X because it will fall back to the Mac OS X legacy API Sleep() if necessary, i.e. if the plugin exports a Sleep() function, the call above will return the correct function pointer. If the plugin, however, does not export a Sleep() function, then dlsym() will return a pointer to the Mac OS X legacy API Sleep() which puts the entire computer to sleep, thus causing huge trouble!
Therefore I'd like to ask if there is any way to stop dlsym() from importing this legacy function. Is there maybe any way to tell dlsym() to look only for symbols that have been explicitly declared in the file passed in the -exported_symbols_list compiler argument? i.e. I'm building the plugin like this:
gcc -dynamiclib -exported_symbols_list plugin_symbols.txt -o test.dylib obj1.o ...
I'd then like dlsym() to only check the symbol names specified in "plugin_symbols.txt" and return NULL for all names that are not in "plugin_symbols.txt". Is that possible somehow or can you think of another way to prevent dlsym() from importing the legacy Sleep() API?
Thanks!
Have you tried ORing RTLD_FIRST
into the mode
argument given to dlopen()
?