ELF linking question related to symbol collisions
Wed Nov 20 21:13:00 GMT 2013
On Wed, Nov 20, 2013 at 8:22 AM, Florian Weimer <firstname.lastname@example.org> wrote:
> I've got a program which links (indirectly) to two DSOs which define the
> same function. Is it guaranteed that ld.so resolves a symbol reference to
> the topologically closest definition (from its own dependency graph), or
> will ld.so pick a definition more or less at random?
To be clear:
Program -> lib1.so -> lib1a.so (defines foo)
\--> lib2.so -> lib2a.so (defines foo)
Call sequence is: Program->lib1.so (some function)-> foo (which foo?)
Program was built with `-l1 -l2' (very important because it sequences DT_NEEDED)
In this case the topological sort results in the following flat
sequence (on x86-64):
Thus the answer to "which foo?" is "lib1a.so's foo."
It's the closest definition from the *program* not ld.so, but since
ld.so is always
the first dependency then it can be correct to say this also.
Warning! The answer changes if you link with `-l2 -l1' because it changes
the DT_NEEDED ordering which changes the order in which the graph
Beware that if you introduce cycles the problem becomes non-deterministic
and depends on where you break the cycle. We have several bugs open at
the moment against glibc to make the cycle breaking deterministic and to
enable testing for millions of permutations of N cycles to double check
that the present code does the right thing. We'd appreciate any contributions
in this area as the dynamic linker code is in my opinion in need of refactoring
and simplification to enable future development.
Lastly the VDSO has it's scope inserted into the search list, but if I remember
correctly it is only searched by a special set of internal functions which the
user can't access e.g. _dl_vdso_vsym and used for filling in the relocation
values required by indirect function support.
Please ask any questions if this sounds confusing. The thing I hated most
when dealing with ELF was the lack of experts willing to talk about it when
I had questions.
More information about the Libc-help