Jason R
Jason R

Reputation: 11696

How to locate what symbol corresponds to a specified offset in an ELF shared library?

I have an application that is linked against an ELF shared library. The library that it's using has all of its unneeded symbols stripped (using strip --strip-unneeded). I'm trying to debug a heap-corruption problem. I have a stack trace generated by glibc's malloc() implementation, that contains a bunch of entries like this:

/lib/libfoo.so.0(+0x1c4853)[0x7fe5ae6c8853]
/lib/libfoo.so.0(+0x1dc094)[0x7fe5ae6e0094]
/lib/libfoo.so.0(+0x1d7902)[0x7fe5ae6db902]

These obviously aren't very useful. On my development machine (which is separate from the one where the bug is occurring, and I don't have ready access to that system), I have a copy of the library that hasn't been stripped. Can I easily map the above symbol offsets to the corresponding functions that they occur in? As a bonus, it would be even better if I could map them to source line numbers.

Upvotes: 2

Views: 1320

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

Nos provided, then deleted, the following correct answer:

You can use the addr2line tool for this, which is part of binutils so it should already installed on your system.

addr2line -e /path/to/libfoo.so.0 -fp 0x1c4853

The output should be something like e.g.

some_function at /dev/src/main.c:11

Upvotes: 3

Related Questions