What is the use of the SHT_NULL section in ELF?

岁酱吖の 提交于 2019-12-23 11:00:10

问题


  1. What is the purpose of the SHT_NULL section in ELF?
  2. Is it referenced by the OS or the loader?
  3. What is the size of this section?
  4. Does it have anything to do with the NULL pointer ?
  5. Additionally, why does this section not have an entry in the section-segments mapping?

From the ELF specification:

SHT_NULL : This value marks the section header as inactive; it does not have an associated section. Other members of the section header have undefined values.


回答1:


What is the purpose of the SHT_NULL section in elf?

It serves as a sentinel.

Is it referenced by the operating system or the loader?

No.

What is the size of this section ?

Zero (you can see that in readelf -WS a.out output) [but see below].

why does this section not have an entry in the section-segments mapping ?

Because that section is not present in any segment.


Normally, the very first section in every ELF file is of type SHT_NULL. In theory, a post-link tool may set the type of some other section to SHT_NULL as well (e.g. if its data is no longer needed), and all subsequent tools are supposed to ignore that section. This is not common.




回答2:


One "use" of SHT_NULL is that it is mandatory for the first header table entry (index 0, named SHN_UNDEF), which is magic.

This is documented on the System V ABI Update (recommended by the LSB):

If the number of sections is greater than or equal to SHN_LORESERVE (0xff00), e_shnum has the value SHN_UNDEF (0) and the actual number of section header table entries is contained in the sh_size field of the section header at index 0 (otherwise, the sh_size member of the initial entry contains 0).

and:

Other section type values are reserved. As mentioned before, the section header for index 0 (SHN_UNDEF) exists, even though the index marks undefined section references. This entry holds the following.

followed by a table that specifies what each entry of he section header means in that special case. In particular, sh_type must be SHT_NULL.

From the above, this first section seems to exist to allow a large number of sections to be encoded, but I haven't tested kernel and compiler support.



来源:https://stackoverflow.com/questions/26812142/what-is-the-use-of-the-sht-null-section-in-elf

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