为什么程序头是可执行的?
我在我的 Linux 机器上的几个二进制文件上使用了 readelf,并在程序头中看到了令我惊讶的东西。该示例来自“ld”实用程序,但它也会出现在我使用 gcc 编译的任何内容中。
PHDR 0x000034 0x08048034 0x08048034 0x00120 0x00120 RE 0x4
该段跨越整个程序头。为什么被标记为可执行?它不包含机器代码。而且,为什么这会出现在标题中?我真的不希望它出现在我的程序图像中。
I used readelf on several binaries on my linux box and saw something that surprised me in the program headers. This eample is from the 'ld' utility, but it also occurs with anything I compile with gcc.
PHDR 0x000034 0x08048034 0x08048034 0x00120 0x00120 R E 0x4
This segment spans the entirety of the program headers. Why is is marked as executable? It doesn't contain machine code. But also, why is even this present in the headers? I don't really want it in my program image.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
指向 PHDR 的 PHDR 告诉加载器 PHDR 本身应该映射到进程地址空间,以便程序本身可以访问它们。
这主要用于动态链接。
内存被标记为可执行的原因是因为 PHDR 小于一页,并且位于可执行代码开头的旁边。如果 PHDR 的权限与程序文本的权限不同,则链接器必须在它们之间插入填充。
The PHDR pointing to the PHDRs tells the loader that the PHDRs themselves should be mapped to the process address space, in order to make them accessible to the program itself.
This is useful mainly for dynamic linking.
The reason the memory is marked as executable is because the PHDRs are smaller than one page, and live right next to the start of the executable code. If the permissions for the PHDRs were different from those of the program text, the linker would have to insert padding between them.
主要的文件 ELF 标头可以轻松找到文件中存储其他部分的偏移量。然后每个子标题描述其部分中的数据。
主 ELF 标头如下所示:
程序标头在那里是因为它们描述了 ELF 可执行文件的可执行部分。
这取自此处
The main File ELF headers are there to easily find the offset in the file where other sections are stored. Then each subheader describes the data in it's section.
Main ELF header looks like this:
The program header(s) are there because they describe the executable parts of the ELF executable.
This is taken from here