0

I want to find some external symbols, used by one shared library (.so) in another. I easily can run

 nm -D ./lib_the_one.so

and get list of used symbols by grepping, for example ' U ' (undefined symbols):

          U The_external_symbol

Now I want to know, how many usages of some symbol is present (statically) in the whole library "lib_the_one.so". More exact,

  • how many direct calls are there for some external function
  • how many times the external variable is referenced

For example, I want to know that there are 10 functions in my "lib_the_one.so" with calls to calloc inside them and 5 functions with calls to malloc.

How can I do this using nm, objdump or any other util binutils (my OS is Linux)?

osgx
  • 90,338
  • 53
  • 357
  • 513

1 Answers1

0

you can use objdump and grep on each symbol, it should give you the number of times a symbol is referenced, here I call malloc twice from two different function:

objdump  -D test_prog | grep malloc
0000000000400928 <malloc@plt>:
400b91: e8 92 fd ff ff          callq  400928 <malloc@plt>
400c9c: e8 87 fc ff ff          callq  400928 <malloc@plt>

Note: Ignore the first one it's the plt entry.

iabdalkader
  • 17,009
  • 4
  • 47
  • 74
  • mux, hmm, can you show in the source of objdump, how it translates the address 400928 to the symbol name @plt? – osgx Aug 11 '13 at 10:40
  • @osgx no, but I guess it looks it up in the symbol table. – iabdalkader Aug 11 '13 at 10:56
  • @osgx actually if you multiply the index of the symbol (from the symbol table .dynsym) by the size of each entry (16 bytes) and then add that to the address of the plt (from readelf) you get the address of that symbol. I'm guessing this is how objdump does it. – iabdalkader Aug 11 '13 at 11:35