Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of the SHT_NULL section in ELF?

Tags:

elf

  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.

like image 520
daemon155 Avatar asked Nov 08 '14 00:11

daemon155


People also ask

What is a ELF section header?

The ELF header's e_shoff member indicates the byte offset from the beginning of the file to the section header table. The e_shnum member indicates how many entries that the section header table contains.

What is an ELF header and what does it do?

The ELF header is always located at the beginning of the ELF file. It describes the ELF file organization and contains the actual sizes of the object file control structures. The initial bytes of an ELF header specify how the file is to be interpreted.

What is a section header in Linux?

A section header is a structure of fixed size and format, consisting of the following fields, or members: sh_name. Specifies the section name. The value of this field is an index into the section header string table section, wherein it indicates the beginning of a null-terminated string that names the section. sh_type.

How do you get ELF headers?

To find them the ELF header is used, which is located at the very start of the file. The first bytes contain the elf magic "\x7fELF" , followed by the class ID (32 or 64 bit ELF file), the data format ID (little endian/big endian), the machine type, etc. Finally, the entry point of this file is at address 0x0.


1 Answers

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.