Boost logo

Boost :

From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-09-29 05:02:47


"John H. Spicer" <jhs_at_[hidden]> writes:
> I don't agree with that interpretation of 3.6.2. I have always
> assumed that the 3.6.2 was intended to permit an implementation that
> loads object files on-demand, so that the use of an unresolved
> reference to a function or object would cause the object file to be
> loaded and the static initializations to be performed. In such a
> model, a use of an inline function would only cause the object file to
> be loaded if it happened that the implementation required an
> out-of-line definition in that object file.

Out-of-line definition of inline function can be forced. For example, every
shared library where static_list is used may have its own out-of-line
definiton of <code>inline void multiply_defined() {}</code>.
While linking a shared library this definition cannot be optimized away just
because at the time of linking it's unknown whether main program has it or
not. As a result, every shared library where multiply_defined is used
out-of-line has it. This is truly multiply defined function.
The dilemma for a linker is which multiply_defined to use. Only one among
all these definitions should be used, otherwise you could end up with two
different addresses for one function and comparison might give unexpected
result (not sure about this, correct me if I'm wrong).
I can think of two different stategies: (a) use multiply_defined defined in
main program and (b) use multiply_defined defined in first loaded shared
library where it is used.
The first choice is great at runtime because it allows to avoid loading of
any shared library. The second choice is good for minimizing executable
size.
Even in case of static linking the question remains. Depending on the answer
static objects from different TUs might have been initialized. The
standrard should be more specific about this behavior.

-- 
Alexander Nasonov
Remove minus and all between minus and at from my e-mail for timely response

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk