Program linked against libraries that share symbol names runs wrong implementation

点点圈 提交于 2019-12-11 10:56:25

问题


This a bit difficult to understand but I'm doing my best.

On Red Hat 6.4 with gcc 4.4.6 & ld 2.20.51,

I am linking into a binary executable PROGRAM code from one shared library (.so) and a static library (.a).

The shared library exposes an API invoked directly by PROGRAM. The implementation of this shared library is compiled & linked against a static library static lib1.

The static library also exposes its own API which is invoked directly by PROGRAM. And some of its implementation is based on a subset of the static lib1's files that were copied directly into it.

None of the APIs (of either library) actually expose a data type or a function implemented by static lib1.

Because the code was copied the symbols are identical.

During runtime I see this behaviour:

  1. If the order of libraries to the linker is shared library, static library, then calls to the shared library API and calls to the static library* API will both use the implementation in the **static lib1.
  2. If the order of libraries to the linker is static library, shared library, then calls to the shared library API and calls to the static library API will both use the implementation in the static library 1 - code from lib1 modified.

How do I get all calls to the static library API to run the implementation in code from lib 1 modified and those in the shared library API run the implementation in static lib1?

来源:https://stackoverflow.com/questions/36776143/program-linked-against-libraries-that-share-symbol-names-runs-wrong-implementati

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!