Re: How do linkers work?

Alan Donovan <adonovan@imerge.co.uk>
21 Oct 1999 14:20:22 -0400

          From comp.compilers

Related articles
How do linkers work? dwilson@ttl.ie (Dave Wilson) (1999-10-21)
Re: How do linkers work? tgakem@pebbles.chem.tue.nl (1999-10-21)
Re: How do linkers work? adonovan@imerge.co.uk (Alan Donovan) (1999-10-21)
Re: How do linkers work? johnmce@texas.net (1999-10-21)
Re: How do linkers work? tgakem@pebbles.chem.tue.nl (1999-10-21)
Re: How do linkers work? strohm@airmail.net (1999-10-27)
| List of all articles for this month |

From: Alan Donovan <adonovan@imerge.co.uk>
Newsgroups: comp.unix.programmer,comp.compilers
Date: 21 Oct 1999 14:20:22 -0400
Organization: Imerge Ltd.
References: 99-10-097
Keywords: linker

Dave Wilson wrote:


> Forgive me if I'm displaying a certain ignorance about current linker
> technology, but I thought linkers could figure out certain things like
> which functions will never get called and leave them out.


If only it were true. That kind of deduction is, in general, a member
of the set of problems that computer scientists call (with
characteristic understatement) "hard". Imagine this code in a client
of the library:


string s("B"); s += "ill"; // "Bill"
FUNC *p = GetSymbolAddress(s);
p();


How can any linker know that this piece of code calls Bill()? It
would have to know what all possible values of "s" were at the time of
GetSymbolAddress. This kind of dataflow analysis is simply not
possible.


However, if the library that Bill() requires is dynamically loadable,
then it won't get loaded until it's called (i.e. never). So though you
have to link against the stub, you pay no speed/size penalty at
runtime.


alan
[I don't believe he was asking about dynamic linking. This was plain old
link-time static linking. There are indeed linkers that garbage collect
unused routines. See subsequent messages. -John]












------------------------------------------------------------------------
    Alan Donovan adonovan@imerge.co.uk http://www.imerge.co.uk
    Imerge Ltd. +44 1223 875265





Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.