Im writing a profiling tool for my App and im using dladdr to convert function pointer to name. Everything work fine as long as Im in debug but as soon as I compile in release (using XCode 5.1) all name conversion fail and return NULL ex:
#include <dlfcn.h>
int main( int argc, char **argv )
{
Dl_info info;
if( dladdr( main, &info ) != 0 )
{ fprintf( stderr, "%s\n", info.dli_sname ); }
I tried multiple compiler flags that I pass to the C/C++ Flags: -export-dynamic -fPIC as well as -Wl,--export-dynamic nothing works... Is there a way to still compile with optimization and retain the function address -> name translation functionalities of dladdr?
clang and gcc support the -rdynamic
option as a linker option. This should provide the ability for dladdr to function as expected in release mode. -rdynamic
is defined as:
-rdynamic Pass the flag -export-dynamic to the ELF linker, on targets that support it. This instructs the linker to add all symbols, not only used ones, to the dynamic symbol table. This option is needed for some uses of dlopen or to allow obtaining backtraces from within a program.
More information on gcc linker options can be found here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With