[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Technical Reference: Base Operating System and Extensions, Volume 1


elf32_getphdr, elf32_newphdr, elf64_getphdr, elf64_newphdr Subroutine

Purpose

Retrieve class-dependent program header table

Library

cc [flag...] file... -lelf [library]...
#include <libelf.h>

Syntax


Elf32_Phdr *elf32_getphdr(Elf * elf);
Elf32_Phdr *elf32_newphdr(Elf * elf, size_t count);
Elf64_Phdr *elf64_getphdr(Elf * elf);
Elf64_Phdr *elf64_newphdr(Elf * elf, size_t count);

Description

For a 32-bit class file, elf32_getphdr returns a pointer to the program execution header table, if one is available for the ELF descriptor elf.

elf32_newphdr allocates a new table with count entries, regardless of whether one existed previously, and sets the ELF_F_DIRTY bit for the table [see the elf_flagdata subroutine]. Specifying a zero count deletes an existing table. Note this behavior differs from that of elf32_newehdr [see the elf32_getehdr subroutine], allowing a program to replace or delete the program header table, changing its size if necessary.

If no program header table exists, the file is not a 32-bit class file, an error occurs, or elf is null, both functions return a null pointer. Additionally, elf32_newphdr and elf64_newphdr return a null pointer if count is zero.

The table is an array of Elf32_Phdr structures, each of which includes the following members.

   	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;

elf64_getphdr and elf64_newhdr provide the same functionality for 64-bit class files. The table is an array of Elf64_Phdr structures, each of which includes the following members.

           Elf64_Word      p_type;
           Elf64_Word      p_flags;
           Elf64_Off       p_offset;
           Elf64_Addr      p_vaddr;
           Elf64_Addr      p_paddr;
           Elf64_Xword     p_filesz;
           Elf64_Xword     p_memsz;
           Elf64_Xword     p_align;

The ELF headers e_phnum member tells how many entries the program header table has [see the elf64_getehdr subroutine]. A program may inspect this value to determine the size of an existing table; elf32_newphdr and elf64_newphdr automatically set the member's value to count. If the program is building a new file, it is responsible for creating the file's ELF header before creating the program header table.

Related Information

The elf_begin (elf_begin Subroutine) subroutine, elf_flagdata (elf_flagdata, elf_flagehdr, elf_flagelf, elf_flagphdr, elf_flagscn, elf_flagshdr Subroutine) subroutine, elf32_getehdr (elf32_getehdr, elf32_newehdr, elf64_getehdr, elf64_newehdr Subroutine) subroutine, elf64_getehdr (elf32_getehdr, elf32_newehdr, elf64_getehdr, elf64_newehdr Subroutine) subroutine.

Introduction to ELF Subroutines.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]