Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get associated function names with the imported library

Tags:

linux

elf

if i have an ELF file, how can i get each functions imported from a library file ".so" , displaying that shared library associated with the function ?

like image 260
Anwar Mohamed Avatar asked Dec 07 '25 13:12

Anwar Mohamed


1 Answers

This works nicely for me:

nm -uC test

E.g. on the code from this other answer I just wrote:

g++ -O0 -I ~/custom/boost/ test.cpp -o test 
nm -uC test

The output is

 w _Jv_RegisterClasses
 U _Unwind_Resume@@GCC_3.0
 U std::string::compare(std::string const&) const@@GLIBCXX_3.4
 U std::allocator<char>::allocator()@@GLIBCXX_3.4
 U std::allocator<char>::~allocator()@@GLIBCXX_3.4
 U std::ostream::operator<<(std::ostream& (*)(std::ostream&))@@GLIBCXX_3.4
 U std::ostream::operator<<(int)@@GLIBCXX_3.4
 U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)@@GLIBCXX_3.4
 U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)@@GLIBCXX_3.4
 U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()@@GLIBCXX_3.4
 U std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()@@GLIBCXX_3.4
 U std::ios_base::Init::Init()@@GLIBCXX_3.4
 U std::ios_base::Init::~Init()@@GLIBCXX_3.4
 U std::__throw_bad_alloc()@@GLIBCXX_3.4
 U std::_Rb_tree_decrement(std::_Rb_tree_node_base const*)@@GLIBCXX_3.4
 U std::_Rb_tree_decrement(std::_Rb_tree_node_base*)@@GLIBCXX_3.4
 U std::_Rb_tree_increment(std::_Rb_tree_node_base const*)@@GLIBCXX_3.4
 U std::_Rb_tree_increment(std::_Rb_tree_node_base*)@@GLIBCXX_3.4
 U std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)@@GLIBCXX_3.4
 U std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)@@GLIBCXX_3.4
 U std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@@GLIBCXX_3.4
 U operator delete(void*)@@GLIBCXX_3.4
 U operator new(unsigned long)@@GLIBCXX_3.4
 U __cxa_atexit@@GLIBC_2.2.5
 U __cxa_begin_catch@@CXXABI_1.3
 U __cxa_end_catch@@CXXABI_1.3
 U __cxa_rethrow@@CXXABI_1.3
 w __gmon_start__
 U __gxx_personality_v0@@CXXABI_1.3
 U __libc_start_main@@GLIBC_2.2.5
 U memmove@@GLIBC_2.2.5
 w pthread_cancel

I'm somewhat aware of the deficiency that this doesn't say which shared object should fulfil the dependency, but I guess a little join on the output of nm for those libraries should take you a long way.

Drop the -C flag to prevent name demangling. This could be highly effective if you intend to do a crossreference on the data. Use c++filt to demangle names later, in case you want to present the names in user-friendly fashion

like image 70
sehe Avatar answered Dec 10 '25 05:12

sehe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!