Skip to content
Advertisement

Linux C program: How to find the library to which a function belongs

Say at runtime, I want to find out where a function “printf” is defined. How would I do this? My first attempt was to print out the address of “printf” and compare it against the virtual address mapping of the process:

my program:

JavaScript

output:

JavaScript

However, this says the function is defined in my own program!

JavaScript

Shouldnt it be a call into libc? How do I find out where this “printf” or any other function came from?

Advertisement

Answer

At runtime, you can use gdb for this:

JavaScript

If you don’t want to interrupt your program or are reluctant to use gdb, you may also ask ld.so to output some debugging info:

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