Load named unexported symbols with dlsym?

2019-07-04 03:17发布

问题:

Is it possible to load a named unexported symbol from a framework using dlsym?

The symbol I'm trying to import has a name by which it is referred to within the framework. It is a function I need to call.

I'm trying to do it the usual dlopen + dlsym way, but when I try to load a symbol that isn't exported, dlsym returns a NULL pointer.

回答1:

dlsym can only load functions that are listed in the symbol table. You can list the symbol table by running nm on the framework in question.

You can verify this in the dyld source: ImageLoaderMachOClassic::findExportedSymbol is the internal implementation of dlsym, it simply binary searches the symbol table:

And ImageLoaderMachO::parseLoadCmds loads the symbol table from the load commands in the Mach header:



标签: dlsym