问题
- What is the purpose of the
SHT_NULL
section inELF
? - Is it referenced by the OS or the loader?
- What is the size of this section?
- Does it have anything to do with the NULL pointer ?
- 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