抑制共享库的编译时链接 [英] suppressing compile time linkage of shared libraries

查看:84
本文介绍了抑制共享库的编译时链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在集成一个DRM库,出于安全原因,该库不能以明文形式保留在代码存储库中. DRM库仅在安全目标设备上运行时才是明文,因此只能在运行时进行链接.这带来了编译时链接的问题.

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.

例如,如果我创建依赖于DRM库libDrm.so的my_library.so,则如果我仅使用"ld:无法找到-lDrm"从构建中删除libDrm.so,则以下操作将失败 gcc -fPIC -shared -o my_library.so my_library.c -L. -lDrm

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

我知道libDrm.so的符号的动态加载是一种解决方案,但是我不希望在开发的这一阶段编写代码来进行动态加载.我正在寻找快速又脏的东西.我基本上想告诉LD忽略在编译时找不到libDrm.so的事实,因为LD可以在运行时找到它.我怎样才能做到这一点?我看不到LD在运行时是否需要libDrm.so的原因,因此我希望LD具有足够的灵活性以允许这样做.

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.

我目前正在考虑链接从存根编译的libDrm.so版本,以使构建成功完成.在运行时,将从真实实现中创建的libDrm.so的版本链接到其中.

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.

有人知道我可以与LD一起使用的神秘链接器选项,只是告诉LD将与libDrm.so相关的所有链接操作推迟到运行时吗?

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?

推荐答案

我正在寻找又脏又快的东西.

I'm looking for something quick and dirty.

创建一个名为libDrm-stub.so stub 库,并将SONAME设置为libDrm.so.

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.

(要设置SONAME,在链接libDrm-stub.so时使用-Wl,--soname=libDrm.so)

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

我目前正在考虑链接从存根编译的libDrm.so版本,以使构建成功完成.

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

这是正确的方法.

有人知道我可以与LD一起使用的神秘链接器选项,只是告诉LD将与libDrm.so相关的所有链接操作推迟到运行时吗?

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?

您可以尝试使用-Wl,--unresolved-symbols=ignore-all,但这更容易出错,所以我建议不要这样做.

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

这篇关于抑制共享库的编译时链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆