ELF段识别
在 ELF 可执行文件中,我用零值字节覆盖了所有节名称。即使这样,该文件也可以正确链接和执行。操作系统如何识别文件中的各个部分,例如符号表等?我的印象是这些部分的名称就是为了这个目的。一个相关的问题是,那么节名有什么用呢?
In an ELF executable file, I over-wrote all the section names by zero-valued bytes. Even then, the file can be linked and executed correctly. How does the OS identify various sections like the symbols-table, etc. in the file? I was under the impression that the section names serve this purpose. A related question is that what is the use of section names then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与 32 位 Windows 中使用的目标文件不同,如果不使用链接器脚本,则 ELF 目标文件中的节名称将被忽略。
每个“PROGBITS”部分都包含标志,指定该部分是否可写、可执行和/或什至不是映像的一部分(调试信息)。
(实际上,Windows使用的目标文件也有这样的标志,但它们通常设置为0,并且节名称用于区分代码节和数据节。)
对于其他节类型(例如符号表),很清楚如何无论如何,他们都必须得到处理。
对于可执行文件和共享库,这些部分无论如何都会被忽略。相反,使用文件的“程序头”。
“程序头”告诉操作系统必须将文件中的某个地址范围加载到内存中。一个“程序头”可以涵盖多个部分。而且“程序头”没有名称。
例子:
Unlike the object files used in 32-bit Windows, the section names in ELF object files are ignored if no linker script is used.
Each "PROGBITS" section contains flags that specify if the section is writeable, executable and/or not even part of the image (debug information).
(Actually, the object files used by Windows also have such flags, but they are typically set to 0 and the section name is used to distinguish between code and data sections.)
For other section types (such as symbol tables) it is clear how they have to be handled anyway.
For executable files and shared libraries, the sections are ignored anyway. Instead, the "program headers" of the file are used.
A "program header" tells the OS that a certain address range in the file must be loaded to memory. A "program header" may cover multiple sections. And "program headers" don't have names.
Example: