How to set the dynamic linker path for a shared library?

半世苍凉 提交于 2019-12-04 10:02:05
jacwah

ld doesn't include a .interp section if -shared is used, as @MichaelDillon already said. You can however provide this section yourself.

const char interp_section[] __attribute__((section(".interp"))) = "/path/to/dynamic/linker";

The line above will save the string "/path/to/dynamic/linker" in the .interp section using GCC attributes.

If you're trying to build a shared object that's also executable by itself, check this question out. It has a more comprehensive description of the process.

The INTERP segment only goes into binaries which need to load the ELF interpreter (ld.so) in the first place. A shared library has no INTERP segment because the ELF interpreter is already loaded before the shared library is loaded.

In most linux systems the ldconfig is run at every system boot and it looks definitions in /etc/ld.so.conf for looking in directories that have shared libraries. In the file /etc/ld.so.cache there are mappings for shared libraries sonames and the library full path. Consider reading this article: http://grahamwideman.wordpress.com/2009/02/09/the-linux-loader-and-how-it-finds-libraries/#comment-164

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