1

I'd like to do some analysis of C code on Linux/BSD to see the frequency of library functions being used. So basically I'd like to compile the code and after the compilation step somehow print out all the functions this code uses. For example: "chown, mmap, etc, etc". I want to run this over a few thousand open source applications so looking for automation.

Is there a way to do this?

Note. dynamic instrumentation like strace or ptrace wouldn't work for me as I cannot run all the applications and even if i did i may not go through every single code path so might miss some calls that are possible (ie. calls that only happen in error conditions)

1 Answers1

1

Try running objdump -T | grep GLIBC on the compiled binary.

For example:

$ objdump -T /bin/lessecho|grep GLIBC
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 putchar
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 puts
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.4   __stack_chk_fail
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 strchr
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 __libc_start_main
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 strcmp
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __printf_chk
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 exit
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.2.5 fwrite
0000000000000000      DF *UND*  0000000000000000  GLIBC_2.3.4 __fprintf_chk
0000000000000000  w   DF *UND*  0000000000000000  GLIBC_2.2.5 __cxa_finalize
0000000000202040 g    DO .bss   0000000000000008  GLIBC_2.2.5 stderr

Also nm -D will show similar data.

neuhaus
  • 3,886
  • 1
  • 10
  • 27