I am trying to list all real file dependencies of an ELF executable in order to improve granularity of incremental building/testing.
When I link an executable against a set of libraries, the symbols from the STATIC ones appear on top of the linker map, which is good. I would like to also know when the linker include a symbol from a shared library and the path to the defining file.
For exemple if I have an executable looking like:
#include "ext_src.h"
#include "ext_lib.h"
#include "int_src.h"
int main(){
ext_src();
ext_lib();
int_src();
}
Where each of the 3 functions comes from a different library, the compiler command being:
/usr/bin/cc -O3 -DNDEBUG -Wl,-Map=exec2.map exec2.c.o -o exec2 -Wl,-rpath,backend_libs: backend_libs/libsub.so backend_libs/libEXT_dependence1.so extern/lib/an_extern_lib/libext_lib_normal.a
I can only have the information I seek (which is that ext_lib() comes from ext_lib.c.o) for the static library on top of the linker map:
Membre d'archive inclu pour satisfaire la référence par fichier (symbole)
extern/lib/an_extern_lib/libext_lib_normal.a(ext_lib.c.o)
CMakeFiles/exec2.dir/entry/exec2.c.o (ext_lib)
/usr/lib/x86_64-linux-gnu/libc_nonshared.a(elf-init.oS)
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o (__libc_csu_init)
The information does not seem to be anywhere in the linker map. Indeed I cant find the module I know where ext_src() is defined in it.
Does someone have an idea how to get the file from which ext_src is defined? It need to be in a way that it would list only the symbols that my executable actually uses
Edit: I also forgot to mention that I control the compilation of the libraries I link to. Thus I am open to a solution involving compiling theses libraries with weird flags, debug sections...