与 ifort 和 .so 库的正确链接顺序

发布于 2024-12-09 05:25:59 字数 579 浏览 3 评论 0原文

我有两个第 3 方库 A.so 和 B.so,我将它们与我的可执行文件executable.exe 链接在一起。 A.so 包含一个已由 B.so 解决的错误,即:

  • A::subroutine1() 调用时可能会因浮点异常而崩溃(FP 算术错误)
  • B ::subroutine1() 是一个固定实现,应始终调用它而不是 A::subroutine1()

A 和 B 的正确链接顺序是什么?我现在正在做的是:

ifort <....> executable.exe <...> -lA -lB

我仍然时不时地收到浮点异常(该错误无法准确重现,因此很难调试)。然而,当它崩溃时,程序让我知道 A::subroutine1() 是违规者 - 因此由于某种原因链接了错误版本的 subroutine1() 。

我将翻转链接顺序作为第一个尝试,但是是否有一个工具可以用来检查executable.exe以查看在运行时将调用哪个版本的subroutine1()?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空宴 2024-12-16 05:25:59

如果您希望调用 libB.so 中的 subroutine1,那么正确的链接顺序是 -lB -lA(对于 Linux 和大多数其他 UNIX 共享库实现)。

是否有一个工具可以用来检查executable.exe以查看运行时将调用哪个版本的subroutine1()

否:该信息通常不会记录在可执行文件中。规则是:首先定义 subroutine1 的共享库将被使用。

例如,如果您使用 -lC -lB -lA 进行链接,并且在链接时 libC.so 确实定义 subroutine1< /code>,但稍后您重建 libC.so无需重新链接可执行文件),然后从 libC 重建 subroutine1。所以将被调用。

但请注意,存在并发症。例如,libA.so 可以与 -Bsymbolic 链接,这将导致从 libA.so< 内部对 subroutine1 的所有调用/code> 绑定到 libA.so 本身内的 subroutine1

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文