I have two 3rd party libraries A.so and B.so that I am linking together with my executable executable.exe. A.so contains a bug that is addressed by B.so, that is, say:
A::subroutine1()may crash with a floating point exception when called (FP arithmetic bug)B::subroutine1()is a fixed implementation that should always be called instead ofA::subroutine1().
What is the correct linking order for A and B? What I am doing now is:
ifort <....> executable.exe <...> -lA -lB
I am still getting the floating point exception from time to time (the error is not reproducible exactly, so it’s pretty difficult to debug). However, when it crashes, the program lets me know that A::subroutine1() is the offender – so the wrong version of subroutine1() gets linked in for some reason.
I will flip the linking order as a 1st stab at this, but is there a tool that I can use to inspect executable.exe to see what version of subroutine1() will be called at runtime?
thanks!
If you want
subroutine1fromlibB.soto be called, then correct link order is-lB -lA(for Linux and most other UNIX shared library implementations).No: that information is not usually recorded in the executable file. The rule is: whichever shared library defines the
subroutine1first is the one that will be used.For example, if you link with
-lC -lB -lA, and at link timelibC.sodoes not definesubroutine1, but later you rebuildlibC.so(without relinking the executable) so it does, thensubroutine1fromlibC.sowill be called.However note that there are complications. For example,
libA.somay be linked with-Bsymbolic, which will cause all calls tosubroutine1from withinlibA.soto bind tosubroutine1withinlibA.soitself.