SHT_NULL
中的ELF
部分的目的是什么?来自ELF规范:
SHT_NULL
:此值将节标题标记为无效;它没有相关的部分。节标题的其他成员具有未定义的值。
答案 0 :(得分:4)
elf中SHT_NULL部分的目的是什么?
它用作sentinel。
是由操作系统还是加载程序引用?
没有
这部分的大小是多少?
归零(你可以在readelf -WS a.out
输出中看到)[但见下文]。
为什么这一部分在段 - 段映射中没有条目?
因为该部分不存在于任何细分中。
通常,每个ELF文件的第一部分都是SHT_NULL
类型。理论上,后链接工具也可以将其他部分的类型设置为SHT_NULL
(例如,如果不再需要其数据),并且所有后续工具都应该忽略那一节。这并不常见。
答案 1 :(得分:4)
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.