ELF Format note (11) -- program header structure, elfformat

Source: Internet
Author: User

ELF Format note (11) -- program header structure, elfformat

Ilocker: Follow Android Security (novice) QQ: 2597294287

The program header table is a struct array. Each struct element in the array is a program header, and each program header describes a segment ).

 

A so usually has two LOAD segments. android linker loads the so segment according to the maximum virtual address in the memory minus the minimum virtual address, to calculate the memory size to be applied.

 

In addition to two LOAD segments, data in other segments is also required by the execution program. For example, DYNAMIC links require DYNAMIC segments and c ++ exception stack expansion requires EXIDX segments. Therefore, other segments also need to be loaded to the memory. They are actually located inside the two LOAD segments.

Sections and segments are divided from two different angles: the Link View and the execution view, they have a ing relationship (each segment "contains" one or more sections ):

 

Program header structure:

typedef struct {  Elf32_Word p_type;  Elf32_Off  p_offset;  Elf32_Addr p_vaddr;  Elf32_Addr p_paddr;  Elf32_Word p_filesz;  Elf32_Word p_memsz;  Elf32_Word p_flags;  Elf32_Word p_align;} Elf32_Phdr;

P_type: segment type, such as PT_LOAD and PT_DYNAMIC ).

P_offset: the offset of the first byte of the segment data relative to the beginning of the file.

P_vaddr: the virtual address (only an offset) of the first byte of the data segment in the memory ).

P_paddr: Do not worry about it for the moment.

P_filesz: the size of the segment data in the file, which can be 0.

P_memsz: the size of the segment data in the memory image in bytes, which can be 0.

P_flags: block memory image access permissions: PF_X (executable), PF_W (writable), and PF_R (readable ).

P_align: If it is 0 or 1, align is not required. Otherwise, p_align should be a positive integer power of 2, and p_vaddr and p_offset should be equal after mod on p_align.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.