有没有办法将Linux共享库加载到特定的内存位置? [英] Is there a way to load a Linux shared library into a specific memory location?

查看:125
本文介绍了有没有办法将Linux共享库加载到特定的内存位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Linux应用程序,该应用程序在运行时会加载非常小的(一些小功能)共享库。由于各种重要原因,我需要将共享库加载到某个虚拟内存范围内。但是, dlopen()没有提供任何方法(我可以看到)来告诉它或提示它将加载的内容放在何处。

I have a Linux application which loads in very small (a few small functions) shared libraries at run-time. For various Important Reasons™ I need the shared libraries to be loaded into a certain virtual memory range. However, dlopen() doesn't provide any means (that I can see) to tell it, or hint to it, where to put what it loads.

有没有办法告诉 dlopen()应该将加载的库放在哪里?

Is there a way to tell dlopen() where it should put the library it loads?

dlopen()是否可以提供该功能?

Is there some alternative to dlopen() which would provide that functionality?

推荐答案

我认为,如果您愿意修改库,则预链接程序实际上可能演示了一种方法。目的是修改库,使其具有首选地址。预链接的目的是为了提高性能,但是我怀疑可以对其进行修改以适合您的用例。
请注意,在一般情况下您将无法保证会发生这种情况,但是在受控情况下,您可能可以保证会发生这种情况。
当然,检查预链接可以使您了解所涉及的elf的各个部分,并更加明智地确定是否可能。
http://en.wikipedia.org/wiki/Prelink#
或参见 http://packages.qa.debian.org/prelink 以获得源于Debian。

I think that the prelink program may actually demonstrate a way to do this if you are willing to modify the library. The goal is to modify the library so that it will have a preferred address. The intent of prelink is to do this for performance, but my suspicion is that it can be modified to work for your use case. Note that you will never be guaranteed that this will happen in the general case, but in controlled cases you may be able to guarantee that it will happen. Certainly examining prelink will allow you to understand the parts of elf involved and make a more informed determination about whether it is possible. http://en.wikipedia.org/wiki/Prelink# Or see http://packages.qa.debian.org/prelink for the sources in Debian.

这篇关于有没有办法将Linux共享库加载到特定的内存位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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