3

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, ...).

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711

2 Answers2

5

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.

Necrolis
  • 25,836
  • 3
  • 63
  • 101
  • nm handles object files -- I don't understand what your intended distinction between "binaries" and "object files" is here. – Perry Feb 28 '12 at 23:29
  • @Perry: good catch, I wasn't concentrating too hard when I made this reply (hence the horrid grammar :|) – Necrolis Feb 29 '12 at 06:58
0

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

James
  • 24,676
  • 13
  • 84
  • 130