Home > Software engineering >  How to identify all C standard library calls in source code?
How to identify all C standard library calls in source code?

Time:06-10

I want to get the information about how many kind of C standard library features are used in my application source code, e.g., whether vector is used or some STL algorithm is used? For C library, I know that I can use objdump -T | grep GLIBC on the compiled binary as the post how to identify all libc calls at compile time? shows. But this method is not applicable for C , e.g., as the result of objdump -T | grep GLIBCxx is not what I expect as below:

0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _Znam
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareERKS4_
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.19 _ZNSt6chrono3_V212system_clock3nowEv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.15 _ZNSt8__detail15_List_node_base7_M_hookEPS0_
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4.22 _ZTINSt6thread6_StateE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt29_Rb_tree_insert_and_rebalancebPSt18_Rb_tree_node_baseS0_RS_
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt14overflow_errorC1EPKc
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4 _ZTVSt9basic_iosIcSt11char_traitsIcEE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.14 _ZSt20__throw_future_errori
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEED1Ev
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4 _ZSt7nothrow
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt9terminatev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE7compareEPKc
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZNSt8ios_baseC2Ev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9_M_appendEPKcm
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZNSt8ios_baseD2Ev
0000000000000000      DO *UND*  0000000000000000  GLIBCXX_3.4.21 _ZTTNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEE
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4 _ZSt17__throw_bad_allocv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.14 _ZSt25__throw_bad_function_callv
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.15 _ZNSt16invalid_argumentD2Ev
0000000000000000      DF *UND*  0000000000000000  GLIBCXX_3.4.21 _ZNSt13runtime_errorC1EPKc

I think I can use libclang to static analyze the source code to get such information, but is there any other method? Thanks!

CodePudding user response:

Many components of the C standard library are templates. Other non-template functions could be declared inline. In either case, there's no guarantee that there will be a call to a function visible in the assembly. The compiler could easily inline all of these, and there would be virtually no way to tell that this had happened.

Only analysis of the literal source text can tell you what you're looking for.

  • Related