Re: llvm ld vs binutils ld
- In reply to: Konstantin Belousov : "Re: llvm ld vs binutils ld"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 02 Feb 2024 21:10:02 UTC
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