G
Gary Labowitz
Karl Heinz Buchegger said:Peter van Merkerk wrote:
Also note that with the existence of virtual functions it got much harder
for the linker to figure out if a function is referenced or not.
I'm not sure of this. It wouldn't make sense for a function name that occurs
in a program to be left out of the external references table. Unless linkers
have changed a lot since I worked on them each function call that is
unresolved results in an address for that function of zero and a flag (in a
table of some sort) indicating that it is an unresolved external reference.
The linker's job is to search the libraries it has available and link in the
object file that contains the code for that referenced function. If the
object code of that referenced function also contains code for some other
number of functions, all that code is linked in whether it is referenced or
not. This is what causes bloat.
The opposite side of that coin is to make more and more object files with
less and less functions in them. This leads to library bloat. (It also makes
the linkage process take longer.) It's always a trade-off, and you also want
to keep functionally related code together for maintenance ease.
I can't recall any system specifically linking in only the code of a
referenced function from a module that has several functions in it. You use
one -- you get them all.
The resulting exe has all the referenced function addresses filled in;
usually relative to the start of the exe's code. That table that told where
the unreferenced function addresses were in the object files now tells where
the relative addresses are in the exe. It's the loader's job to adjust them
to actual addresses when the exe is loaded. (I believe they are adjusted to
virtual addresses nowadays so that the code can be placed anywhere in real
memory and the machine's virtual addressing mechanism adjusts all addresses
to real memory address.)
Anyway, the way it always worked before: if you reference a function, you
get the entire object file that contains that function linked in. No way
out.