Skip to content
Advertisement

dump methods from shared libraries

to list all methods from a shared library I use the

objdump -T shared_library.so

what has an output like this:

00013318 g    DF .text  00000020  Base        apr_os_dir_get
0001afc0 g    DF .text  000000f8  Base        apr_socket_send
00020808 g    DF .text  00000004  Base        apr_shm_create_ex

But when I try to pipe the output of find into objdump like this

find ./lib -name "*.so" | objdump -T

I get this error:

objdump: 'a.out': No such file

and this lib folder does contain a lot of shared library files.

What is wrong with my command?

SK

Advertisement

Answer

find ./lib -name "*.so" | xargs objdump -T

or

find ./lib -name "*.so" -exec objdump -T {} +

objdump expects the name of the library to be passed on the command line. However, piping the output of find to it sends the filenames to objdump’s standard input, which it ignores. If you don’t give objdump a filename on the command line, it defaults to looking for one named a.out, which is the default output filename of some compilers and linkers.

There are a couple ways to use the files found by find as parameters to objdump.

xargs

xargs reads from standard input and then runs another command with what it read from standard input as that command’s arguments. In this case, the filenames in the output of find will be piped to xargs, which will concatenate them into a single line, append it to the command argument from its own command line, and run that. For example, if the lib folder contains the three files libone.so, libtwo.so, and libthree.so, xargs will run the command objdump -T libone.so libtwo.so libthree.so.

Some commands do not accept multiple filenames at a time, and must instead be called multiple times with only a single filename argument. To do this, pass -n1 to xargs, e.g. find ./lib -name "*.so" | xargs -n1 objdump -T. With the above example files, xargs would run objdump -T libone.so, then objdump -T libtwo.so, and then objdump -T libthree.so. (Though objdump does accept multiple filename arguments, so it is not necessary in this case unless the lib folder contains so many files that you’re worried about exceeding the maximum command line length.)

find -exec

find has its own option to run commands and pass the filenames it found as command-line arguments. The -exec option accepts a command, and replaces the string {} with the filename or filenames found, with + indicating the end of the command to run.

If you want to run the command multiple times with only a single filename, like xargs -n1 does, use ; instead of + in the command: find ./lib -name "*.so" -exec objdump -T {} ;.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement