检查静态链接的可执行文件中的文本段 [英] examining text segment in a statically linked executable

查看:109
本文介绍了检查静态链接的可执行文件中的文本段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个静态链接的应用程序二进制文件,它链接到多个用户库和pthread库.该应用程序仅使用这些库中每个库的有限功能集.从以前的帖子库和可执行文件的大小以及我的实验我意识到,链接器仅包含使用/需要的功能(在可执行文件中),而不包含库的全部内容.

I have a statically linked application binary that links against multiple user libraries and the pthread library. The application only uses a limited set of functions from each of these libraries. From a previous post Size of a library and the executable and from my experiments I realize that the linker only includes functions(in the executable) that are used/needed and not the entire contents of library.

我想找出每个相应库中的哪些函数已链接 到可执行文件及其地址(VMA).最终,我想根据映射到文本段的函数(在库中)为每个库编译一个包含开始和结束虚拟内存地址(VMA)的列表.

I want to find out which functions from each of the respective libraries are linked to the executable and their addresses (VMA). Ultimately I want to compile a list that contains the start and the end Virtual Memory Addresses (VMAs) for the each of the libraries based on the functions (in the library) that are mapped to the text segment.

执行此操作的一种方法是在库中列出功能列表,然后在可执行文件及其映射到的相应虚拟内存地址中查找每个功能.但这对我来说似乎很乏味.有没有更简单的方法可以做到这一点?谢谢.

One approach to do this is to make a list of functions in the library and then look for each of these functions in the executable and the corresponding Virtual Memory address it is mapped to. But this seems rather tedious to me. Is there a simpler way to accomplish this? Thanks.

推荐答案

我想找出每个相应库中的哪些函数链接到可执行文件及其地址(VMA).

I want to find out which functions from each of the respective libraries are linked to the executable and their addresses (VMA).

-Wl,-Map=foo.map参数添加到链接行.生成的foo.map文件将告诉您以上所有内容.

Add -Wl,-Map=foo.map argument to your link line. The resulting foo.map file will tell you all of the above.

最终,我想编译一个列表,其中包含每个库的开始和结束虚拟内存地址(VMA)

Ultimately I want to compile a list that contains the start and the end Virtual Memory Addresses (VMAs) for the each of the libraries

假定链接器不对函数进行重新排序(因此,单个库中的所有函数都占据连续范围的文本地址).在简单的情况下,这种假设可能是正确的,但绝不能保证.参见例如此补丁.

That assumes that the linker does not re-order functions (and thus all functions from a single library occupy continuous range of text addresses). This assumption is probably true in simple cases, but in no way is guaranteed. See e.g. this patch.

这篇关于检查静态链接的可执行文件中的文本段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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