Search code examples
shared-librariesnm

nm - show file that declares a symbol in a .so file


Is it possible for nm to show the file that declares a symbol in a .so file? Let's say I have some file:

//file.cpp
int get_data();

int main(){
    return 0;
}

If I compile this file into a shared object file, file.so, I should get a "U" for the get_data symbol when I use nm -C file.so. Is it possible for nm to also show the file name? For larger projects it would be helpful to be able to determine what file is declaring the unresolved symbols.


Solution

  • If I compile this file into a shared object file, file.so, I should get a "U" for the get_data symbol

    You are mistaken: since nothing references get_data, you wouldn't in fact get a U for it.

    To answer your question: the info that file.cpp referenced get_data symbol is gone, unless you compiled file.cpp with debugging info.

    If you did, you could use objdump -dS file.so to find that file.cpp is where the reference originates.