suppressing compile time linkage of shared libraries

蓝咒 提交于 2019-12-08 11:54:07

问题


I am integrating a DRM library that cannot be persisted in a code repository in the clear for security reasons. The DRM library will only be in the clear at run time when on the secure target device, thus it will only be available for linking at runtime. This presents a problem for compile time linking.

For example, if I am creating my_library.so which depends on the DRM lib, libDrm.so, the following will fail if I simply remove the libDrm.so from the build with "ld: cannot find -lDrm" gcc -fPIC -shared -o my_library.so my_library.c -L. -lDrm

I am aware that dynamic loading of the symbols for libDrm.so is a solution but I don't want write the code to do the dynamic loading in this stage of the development. I'm looking for something quick and dirty. I basically want to tell LD to ignore the fact that libDrm.so can't be found at compile time because LD will be able to find it at run time. How can I do this? I don't see an reason LD would need libDrm.so at compile time if it will be available at run time so I'm hoping LD is flexible enough to allow this.

I'm currently considering linking a version of libDrm.so which is compiled from stubs only to get the build to complete successfully. At runtime the the version of libDrm.so created from the real implementation will be linked in.

Anyone know of an esoteric linker option that I can use with LD to just tell LD to defer all linking operations related to libDrm.so until runtime?


回答1:


I'm looking for something quick and dirty.

Create a stub library called libDrm-stub.so, with SONAME set to libDrm.so.

In that library, provide do-nothing implementations of all the functions you call. Link your binary against that stub library, but don't ship it on the device.

(To set SONAME, use -Wl,--soname=libDrm.so when linking libDrm-stub.so)

I'm currently considering linking a version of libDrm.so which is compiled from stubs only to get the build to complete successfully.

That's the right approach.

Anyone know of an esoteric linker option that I can use with LD to just tell LD to defer all linking operations related to libDrm.so until runtime?

You could try to use -Wl,--unresolved-symbols=ignore-all, but this is much more error-prone, so I suggest not doing that.



来源:https://stackoverflow.com/questions/22585492/suppressing-compile-time-linkage-of-shared-libraries

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