Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 2 Feb 2024 13:10:02 -0800
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        Mike Karels <mike@karels.net>, Dimitry Andric <dim@freebsd.org>, FreeBSD CURRENT <freebsd-current@freebsd.org>
Subject:   Re: llvm ld vs binutils ld
Message-ID:  <Zb1aKmgKpKbuCzVD@troutmask.apl.washington.edu>
In-Reply-To: <Zb1VNoamb-FMfHjC@kib.kiev.ua>
References:  <ZbU4oToBDJhRSCPa@troutmask.apl.washington.edu> <A4F07C03-21D4-4B6F-A7B3-6AFE534D11E6@FreeBSD.org> <ZbXks0fl3IRTlLV5@troutmask.apl.washington.edu> <ZbYmwFn_fE15khgF@kib.kiev.ua> <Zb1Lh5a8XC5REwbu@troutmask.apl.washington.edu> <Zb1VNoamb-FMfHjC@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Feb 02, 2024 at 10:48:54PM +0200, Konstantin Belousov wrote:
> On Fri, Feb 02, 2024 at 12:07:35PM -0800, Steve Kargl wrote:
> > 
> > Thanks for the explanation, but I think I now have a conundrum.
> > Suppose I have two shared libraries libfoo.so and libbar.so, and
> > suppose bah@@XXX_1.0 is in libbar.so's symbol map.  If my main
> > program uses bah() and I compile with 'cc -o z main.c -lfoo -lbar',
> > then the linker finds bah@XXX_1.0.
> > 
> > Now suppose a developer adds a new procedure to libfoo.so and she
> > just so happens to name her new function bah() with a symbol map
> > entry of bah@YYY_a.b.
> > 
> > Which bah@ is linked when rebuilding or loading 'z'?  Does it
> > depend on the search order for ld-config.so.1?
> 
> In the 'z' binary either bah@XXX_1.0 or bah@YYY_1.0 is specified as
> the symbol to resolve at the call site. Dynamic linker searches for
> corresponding versioned symbol in the global namespace, typically.
> 
> So now the question is reduced to what version of the symbol bah get
> recorded into the 'z' binary.  It is done by static linker, which looks
> up symbols linearly in the order of object files and libraries specified
> on the command line (*).  If you did 'cc -o z main.c -lfoo -lbar', and
> both libfoo.so and libbar.so provided the bah symbol, the first found
> definition is recorded, together with its version.  The final answer
> is lookup finds bah in libfoo.so and bah@YYY_1.0 is recorded.
> 
> * There are many ways to direct static linker to find specific version
> of the symbol, changing the default behavior.

Thank you.  This essentially confirms my fears.  

-- 
Steve



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Zb1aKmgKpKbuCzVD>