On MSVC when I add the linker switch /VERBOSE I'm able to track the link resolution of individual functions, and thereby the reason that libraries are linked in:
-Wl,--verbose
doesn't do the same for Linux linkers, and I can't find anything else in ld/lld/gold/mold that does. Is there anything similar?
In case this is of interest to others:
On ld and compatible linkers, --cref
achieves similar results. Here's a snippet of the result of building the above code with g++ -Wl,--cref tst.cpp
:
Cross Reference Table
Symbol File
CXXABI_1.3 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
CXXABI_1.3.1 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
CXXABI_1.3.10 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
CXXABI_1.3.11 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
...
std::cout /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
/tmp/cc8SMng2.o
std::cout@@GLIBCXX_3.4 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
std::cout@GLIBCXX_3.4 /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
...
std::ios_base::Init::Init() /usr/lib/gcc/x86_64-linux-gnu/9/libstdc++.so
/tmp/cc8SMng2.o
...
The first line for each symbol is the location of its definition, the next lines (for the same symbol) are locations referencing it.