Re: I'm a stupid blond :( Please help me!!!

From: Peter van Merkerk (merkerk_at_deadspam.com)
Date: 12/05/03


Date: Fri, 5 Dec 2003 23:20:12 +0100


"Gary Labowitz" <glabowitz@comcast.net> wrote in message
news:t7udnYO_Z9kXJk2i4p2dnA@comcast.com...
> "Karl Heinz Buchegger" <kbuchegg@gascad.at> wrote in message
> news:3FD05564.8300D296@gascad.at...
> > 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.

That doesn't happen with all linkers

> 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.

Well for one the linker that comes with Microsoft Visual Studio 6 (not
exactly state-of-the-art) links only the code of referenced functions. It
most certainly does not link the code of all functions in an .obj file,
unless every function in that .obj is referenced. What you are saying may be
true for some linkers but certainly not for 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.)

I won't comment on this part because it is drifting quite far away from the
topic of this newsgroup. But for the record; this explanation is not
necessarilly entirely accurate (what exactly happens depends on the OS).

> 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.

There is a way out; use a better linker. If you are interested I can mail
you a MSVC6 project that demonstrates that an object file is only partially
linked in when only a few functions in that object file are referenced.

--
Peter van Merkerk
peter.van.merkerk(at)dse.nl


Relevant Pages

  • Re: Home brew Z80 CP/M computer
    ... nice pile of assemblers and linkers. ... But it doesn't say what the SLR tools do with it. ... The thing that I absolutely _LOVED_ about the SLR tools was how well they dealt with external references. ... Reading between the lines, it was easy enough to figure out that Steve had defined a stack machine to do the address calculations, and embedded that into the linker. ...
    (comp.os.cpm)
  • Re: strange linking problem
    ... I usually use C, and since strings ... > files and looks for unsatisfied references to functions and variables. ... then I don't understand how the linker does not either ... that there should be a data area of a certain size and a certain name. ...
    (comp.lang.fortran)
  • Re: static variables discarded by the VS.NET2003 linker
    ... an object file containing definitions of global variables of any type/ ... I simply added artificial references to the code, ... because both have back references and the linker would thus try to include ...
    (microsoft.public.vc.language)
  • Re: Strange linker warning?
    ... The warning means that the linker optimized away all references to functions ... The optimization kicks in only after all symbols are resolved. ... your link is pulling in something that references CEDDK. ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: Calling native C++ dll code from managed C++
    ... In the project's Property Pages dialog box, click Linker, ... __DllMainCRTStartup@12 to the Force Symbol References property. ... LNK1120: 1 unresolved externals ...
    (microsoft.public.dotnet.languages.vc)