I'd like to get function's address by name.
For example, currently I am using dlsym:
unsigned long get_func_addr(const char *func_name) { return (unsigned long)dlsym(NULL, func_name); } However, dlsym only works for extern function. It won't work for static function. I know there could multiple static functions with same name in different files. But I need to at least get one static function's address with the name. Sometime static function will be inlned. But it's OK if C file is compiled with debug. I think with -g, the symbol table of static functions is present, but how can I access it?
I don't want to created a table for mapping the string to function address. I need to find a way to do it dynamically.
uintptr_tfromstdint.hinstead ofunsigned long.nm <file>will give you symbol addresses (including functions) if you have debug symbols in the file.