21

I've got a folder in linux, which is contained several shared object files (*.so). How I can find function in shared object files using objdump and bash functions in linux?

For instance, the following example is found me function func1 in mylib.so:

objdump -d mylib.so | grep func1

But i want to find func1 in folder which is contained shared object files. I don't know bash language and how to combinate linux terminal commands.

G-71
  • 3,626
  • 12
  • 45
  • 69

2 Answers2

34

nm is simpler than objdump, for this task.
nm -A *.so | grep func should work. The -A flag tells nm to print the file name.

ugoren
  • 16,023
  • 3
  • 35
  • 65
  • 1
    You need the `-D` option as well to actually look in the list of exported symbols. – jørgensen Feb 20 '12 at 22:31
  • 1
    @jørgensen, it isn't clear from the question whether he wants an exported function. Maybe he wants to know what library he needs to rebuild after changing a function. – ugoren Feb 21 '12 at 07:40
2

You can use also use,

find <path> -name "*.so" -exec nm {} \; | grep func1
Deepak
  • 1,101
  • 9
  • 14
  • 1
    `grep func1 nm {}`?? Do you mean `nm {} | grep func1`? – ugoren Feb 20 '12 at 09:49
  • 1
    You would run nm | grep func1, the execution is from left to right if you are using it without exec. But with exec the execution is from right to left and {} specifies the input from the find command, so the above command means 'run the grep on the result of the nm for all the files from find'. – Deepak Feb 20 '12 at 12:43
  • 2
    I tried your line - it just doesn't work. It just runs `grep func1 nm xxx.so` per file, which searches for `func1` in a file called "nm" and in the binary (without running nm). – ugoren Feb 20 '12 at 13:44
  • Yes, you are right. I did not notice that too closely last time. I have edited my answer. – Deepak Feb 21 '12 at 09:33