xref: /titanic_41/usr/src/man/man3elf/elf32_getphdr.3elf (revision 0c79d02b29618f74322989ec8ceafaa5486ac1db)
te
Copyright 1989 AT&T Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
ELF32_GETPHDR 3ELF "Jul 11, 2001"
NAME
elf32_getphdr, elf32_newphdr, elf64_getphdr, elf64_newphdr - retrieve class-dependent program header table
SYNOPSIS

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

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 elf_flagdata(3ELF). Specifying a zero count deletes an existing table. Note this behavior differs from that of elf32_newehdr() allowing a program to replace or delete the program header table, changing its size if necessary. See elf32_getehdr(3ELF).

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() returns a null pointer if count is 0.

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;

The Elf64_Phdr structures include 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;

For the 64-bit class, replace 32 with 64 as appropriate.

The ELF header's e_phnum member tells how many entries the program header table has. See elf32_getehdr(3ELF). A program may inspect this value to determine the size of an existing table; elf32_newphdr() automatically sets 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.

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Stable
MT-Level MT-Safe
SEE ALSO

elf(3ELF), elf32_getehdr(3ELF), elf_begin(3ELF), elf_flagdata(3ELF), libelf(3LIB), attributes(5)