开发者

correct linking order with ifort and .so libraries

开发者 https://www.devze.com 2023-04-12 13:33 出处:网络
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:

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 of A::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 subroutine1 from libB.so to be called, then correct link order is -lB -lA (for Linux and most other UNIX shared library implementations).

is there a tool that I can use to inspect executable.exe to see what version of subroutine1() will be called at runtime

No: that information is not usually recorded in the executable file. The rule is: whichever shared library defines the subroutine1 first is the one that will be used.

For example, if you link with -lC -lB -lA, and at link time libC.so does not define subroutine1, but later you rebuild libC.so (without relinking the executable) so it does, then subroutine1 from libC.so will be called.

However note that there are complications. For example, libA.so may be linked with -Bsymbolic, which will cause all calls to subroutine1 from within libA.so to bind to subroutine1 within libA.so itself.

0

精彩评论

暂无评论...
验证码 换一张
取 消