How I can find function in shared object files using objdump and bash functions in linux?

32,182

Solution 1

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.

Solution 2

You can use also use,

find <path> -name "*.so" -exec nm {} \; | grep func1
Share:
32,182
G-71
Author by

G-71

Junior software developer (С++, Python)

Updated on July 09, 2022

Comments

  • G-71
    G-71 almost 2 years

    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.

  • ugoren
    ugoren about 12 years
    grep func1 nm {}?? Do you mean nm {} | grep func1?
  • Deepak
    Deepak about 12 years
    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'.
  • ugoren
    ugoren about 12 years
    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).
  • jørgensen
    jørgensen about 12 years
    You need the -D option as well to actually look in the list of exported symbols.
  • ugoren
    ugoren about 12 years
    @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.
  • Deepak
    Deepak about 12 years
    Yes, you are right. I did not notice that too closely last time. I have edited my answer.