R.. GitHub STOP HELPING ICE
R.. GitHub STOP HELPING ICE

Reputation: 215259

Is there a tool to obtain info on a particular symbol in an ELF .o or executable file?

I'm looking for a convenient way (for use in a build testing script) to query individual symbols in an object file. Is there a tool that can answer the question (preferably by its exit status) "does symbol X exist in file Y?" or do I just need to parse the output of nm(1), e.g. with grep and an appropriate regex? Even better would be if such a tool could give detailed information on the symbol (size, type, value, ...).

Upvotes: 3

Views: 2411

Answers (2)

Necrolis
Necrolis

Reputation: 26171

For an executable/shared library, give readelf or Objdump a look over, they can dump a binaries symbols (mangled or unmangled), which you should be able to grep.

Their source is easily obtainable, so you could probably taloir them down into simpler tools for the task at hand or directly import their code base (not that you really need to, you could just load the binary with in question with dlopen and use dlsym to check if the symbol is there).

Objdump is geared towards binaries, nm and readelf will read elf object files.

Upvotes: 5

James
James

Reputation: 25523

You could use libbfd directly, but glancing through the API it isn't obvious how to get straight to the information you want.

Upvotes: 0

Related Questions