How to list imported symbols in ELF executable?

21

3

For PE executable, I can list the imported symbols using

dumpbin /imports FILE.EXE

or using the depends utility which is GUI application.

`nm ELF-binary' just returns "no symbols".

Xiè Jìléi

Posted 2010-07-09T13:14:27.397

Reputation: 14 766

see also list the symbols in a .so file

– bartolo-otrit – 2016-08-20T17:24:56.847

Answers

17

Try objdump -T 'ELF-file'

Mr Shunz

Posted 2010-07-09T13:14:27.397

Reputation: 2 037

I thought objdump -T worked mainly on shared libraries... – jim mcnamara – 2010-07-09T14:35:07.063

well... not really, if I do: objdump -t /bin/ls it returns: "SYMBOL TABLE: no symbols", with -T (which lists DYNAMIC SYMBOL TABLE) outputs a lot of data, like: "00000000 DF UND 00000000 GLIBC_2.0 strchr" – Mr Shunz – 2010-07-09T15:11:23.497

5

The output from objdump is a little excessive for this purpose, and requires a good bit of parsing to find the actual imports.

I prefer readelf for this purpose:

readelf -d dynamic-buffer-test

Dynamic section at offset 0x630a8 contains 23 entries:
 Tag                Type                 Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]

As you can see, the required libraries are marked with "NEEDED".

CyberTech

Posted 2010-07-09T13:14:27.397

Reputation: 69

It just depends on the mode in which you invoke it. Try objdump -p /path/to/binary | grep NEEDED. – sherrellbc – 2016-11-08T21:37:51.927

This only seems to list libraries, not symbols. – plugwash – 2019-07-09T19:57:26.133

5

I prefer readelf.

readelf -s <file>

Grazfather

Posted 2010-07-09T13:14:27.397

Reputation: 51

That only lists required libraries. The question is about what symbols are imported from said libraries. – Alcaro – 2017-06-13T10:49:50.323

1

Along with the other answers posted here I would like to propose another. The contents printed are a function of the file format, where ELF lends itself nicely to solving this problem.

objdump -p /path/to/binary | grep NEEDED

The grep simply extracts the contents of the Dynamic Section, but its the format of the objdump -p output that makes this a simple solution.

sherrellbc

Posted 2010-07-09T13:14:27.397

Reputation: 447