如何使用导入的库获取关联的函数名称

时间:2012-10-07 20:34:01

标签: linux elf

如果我有一个ELF文件,我怎样才能从库文件“.so”中导入每个函数,显示与该函数关联的共享库?

1 个答案:

答案 0 :(得分:1)

这对我很有用:

nm -uC test

E.g。来自this other answer的代码,我刚才写道:

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

输出

 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

我有点意识到这不足以说明哪个共享对象应该满足依赖关系,但我想这些库的nm输出的一点点连接应该会带你走很长的路。

删除-C标志以防止名称解码。如果您打算对数据进行交叉引用,这可能非常有效。如果您想以用户友好的方式展示名称,请稍后使用c++filt对名称进行解码