3

如果我有一个 ELF 文件,如何获取从库文件“.so”导入的每个函数,显示与该函数关联的共享库?

4

1 回答 1

1

这对我很有效:

nm -uC test

例如,在我刚刚写的这个其他答案的代码上:

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您想以用户友好的方式显示名称,请稍后用于对名称进行解码

于 2012-10-07T21:07:02.347 回答