1*0a6a1f1dSLionel Sambuc.\" $NetBSD: gelf.3,v 1.2 2014/03/09 16:58:04 christos Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved. 4*0a6a1f1dSLionel Sambuc.\" 5*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 6*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 7*0a6a1f1dSLionel Sambuc.\" are met: 8*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 9*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 10*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 11*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 12*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 13*0a6a1f1dSLionel Sambuc.\" 14*0a6a1f1dSLionel Sambuc.\" This software is provided by Joseph Koshy ``as is'' and 15*0a6a1f1dSLionel Sambuc.\" any express or implied warranties, including, but not limited to, the 16*0a6a1f1dSLionel Sambuc.\" implied warranties of merchantability and fitness for a particular purpose 17*0a6a1f1dSLionel Sambuc.\" are disclaimed. in no event shall Joseph Koshy be liable 18*0a6a1f1dSLionel Sambuc.\" for any direct, indirect, incidental, special, exemplary, or consequential 19*0a6a1f1dSLionel Sambuc.\" damages (including, but not limited to, procurement of substitute goods 20*0a6a1f1dSLionel Sambuc.\" or services; loss of use, data, or profits; or business interruption) 21*0a6a1f1dSLionel Sambuc.\" however caused and on any theory of liability, whether in contract, strict 22*0a6a1f1dSLionel Sambuc.\" liability, or tort (including negligence or otherwise) arising in any way 23*0a6a1f1dSLionel Sambuc.\" out of the use of this software, even if advised of the possibility of 24*0a6a1f1dSLionel Sambuc.\" such damage. 25*0a6a1f1dSLionel Sambuc.\" 26*0a6a1f1dSLionel Sambuc.\" Id: gelf.3 189 2008-07-20 10:38:08Z jkoshy 27*0a6a1f1dSLionel Sambuc.\" 28*0a6a1f1dSLionel Sambuc.Dd September 1, 2006 29*0a6a1f1dSLionel Sambuc.Os 30*0a6a1f1dSLionel Sambuc.Dt GELF 3 31*0a6a1f1dSLionel Sambuc.Sh NAME 32*0a6a1f1dSLionel Sambuc.Nm GElf 33*0a6a1f1dSLionel Sambuc.Nd class-independent API for ELF manipulation 34*0a6a1f1dSLionel Sambuc.Sh LIBRARY 35*0a6a1f1dSLionel Sambuc.Lb libelf 36*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 37*0a6a1f1dSLionel Sambuc.In gelf.h 38*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 39*0a6a1f1dSLionel SambucThis manual page describes a class independent API for manipulating 40*0a6a1f1dSLionel SambucELF objects. 41*0a6a1f1dSLionel SambucThis API allows an application to operate on ELF descriptors without 42*0a6a1f1dSLionel Sambucneeding to the know the ELF class of the descriptor. 43*0a6a1f1dSLionel Sambuc.Pp 44*0a6a1f1dSLionel SambucThe GElf API may be used alongside the ELF API without restriction. 45*0a6a1f1dSLionel Sambuc.Ss GElf Data Structures 46*0a6a1f1dSLionel SambucThe GElf API defines the following class-independent data structures: 47*0a6a1f1dSLionel Sambuc.Bl -tag -width GElf_Sxword 48*0a6a1f1dSLionel Sambuc.It Vt GElf_Addr 49*0a6a1f1dSLionel SambucA representation of ELF addresses. 50*0a6a1f1dSLionel Sambuc.It Vt GElf_Dyn 51*0a6a1f1dSLionel SambucA class-independent representation of ELF 52*0a6a1f1dSLionel Sambuc.Sy .dynamic 53*0a6a1f1dSLionel Sambucsection entries. 54*0a6a1f1dSLionel Sambuc.It Vt GElf_Ehdr 55*0a6a1f1dSLionel SambucA class-independent representation of an ELF Executable Header. 56*0a6a1f1dSLionel Sambuc.It Vt GElf_Half 57*0a6a1f1dSLionel SambucAn unsigned 16 bit quantity. 58*0a6a1f1dSLionel Sambuc.It Vt GElf_Off 59*0a6a1f1dSLionel SambucA class-independent representation of a ELF offset. 60*0a6a1f1dSLionel Sambuc.It Vt GElf_Phdr 61*0a6a1f1dSLionel SambucA class-independent representation of an ELF Program Header Table 62*0a6a1f1dSLionel Sambucentry. 63*0a6a1f1dSLionel Sambuc.It Vt GElf_Rel 64*0a6a1f1dSLionel SambucA class-independent representation of an ELF relocation entry. 65*0a6a1f1dSLionel Sambuc.It Vt GElf_Rela 66*0a6a1f1dSLionel SambucA class-independent representation of an ELF relocation entry with 67*0a6a1f1dSLionel Sambucaddend. 68*0a6a1f1dSLionel Sambuc.It Vt GElf_Shdr 69*0a6a1f1dSLionel SambucA class-independent representation of an ELF Section Header Table 70*0a6a1f1dSLionel Sambucentry. 71*0a6a1f1dSLionel Sambuc.It Vt GElf_Sword 72*0a6a1f1dSLionel SambucA signed 32 bit quantity. 73*0a6a1f1dSLionel Sambuc.It Vt GElf_Sxword 74*0a6a1f1dSLionel SambucA signed 64 bit quantity. 75*0a6a1f1dSLionel Sambuc.It Vt GElf_Sym 76*0a6a1f1dSLionel SambucA class-independent representation of an ELF symbol table entry. 77*0a6a1f1dSLionel Sambuc.It Vt GElf_Word 78*0a6a1f1dSLionel SambucAn unsigned 32 bit quantity. 79*0a6a1f1dSLionel Sambuc.It Vt GElf_Xword 80*0a6a1f1dSLionel SambucAn unsigned 64 bit quantity. 81*0a6a1f1dSLionel Sambuc.El 82*0a6a1f1dSLionel Sambuc.Pp 83*0a6a1f1dSLionel SambucThese data structures are sized to be compatible with the 84*0a6a1f1dSLionel Sambuccorresponding 64 bit ELF structures, and have the same internal 85*0a6a1f1dSLionel Sambucstructure as their 64 bit class-dependent counterparts. 86*0a6a1f1dSLionel SambucClass-dependent ELF structures are described in 87*0a6a1f1dSLionel Sambuc.Xr elf 5 . 88*0a6a1f1dSLionel Sambuc.Ss GElf Programming Model 89*0a6a1f1dSLionel SambucGElf functions always return a 90*0a6a1f1dSLionel Sambuc.Em copy 91*0a6a1f1dSLionel Sambucof the underlying (class-dependent) ELF data structure. 92*0a6a1f1dSLionel SambucThe programming model with GElf is as follows: 93*0a6a1f1dSLionel Sambuc.Bl -enum 94*0a6a1f1dSLionel Sambuc.It 95*0a6a1f1dSLionel SambucAn application will retrieve data from an ELF descriptor using a 96*0a6a1f1dSLionel Sambuc.Fn gelf_get_* 97*0a6a1f1dSLionel Sambucfunction. 98*0a6a1f1dSLionel SambucThis will copy out data into a private 99*0a6a1f1dSLionel Sambuc.Vt GElf_* 100*0a6a1f1dSLionel Sambucdata structure. 101*0a6a1f1dSLionel Sambuc.It 102*0a6a1f1dSLionel SambucThe application will work with its private copy of the GElf 103*0a6a1f1dSLionel Sambucstructure. 104*0a6a1f1dSLionel Sambuc.It 105*0a6a1f1dSLionel SambucOnce done, the application copies the new values back to the 106*0a6a1f1dSLionel Sambucunderlying ELF data structure using the 107*0a6a1f1dSLionel Sambuc.Fn gelf_update_* 108*0a6a1f1dSLionel Sambucfunctions. 109*0a6a1f1dSLionel Sambuc.It 110*0a6a1f1dSLionel SambucThe application will then use the 111*0a6a1f1dSLionel Sambuc.Fn elf_flag* 112*0a6a1f1dSLionel SambucAPIs to indicate to the ELF library that an ELF data structure is dirty. 113*0a6a1f1dSLionel Sambuc.El 114*0a6a1f1dSLionel Sambuc.Pp 115*0a6a1f1dSLionel SambucWhen updating an underlying 32 bit ELF data structure, the GElf 116*0a6a1f1dSLionel Sambucroutines will signal an error if a GElf value is out of range 117*0a6a1f1dSLionel Sambucfor the underlying ELF data type. 118*0a6a1f1dSLionel Sambuc.Ss Namespace use 119*0a6a1f1dSLionel SambucThe GElf interface uses the following symbols: 120*0a6a1f1dSLionel Sambuc.Bl -tag 121*0a6a1f1dSLionel Sambuc.It GElf_* 122*0a6a1f1dSLionel SambucClass-independent data types. 123*0a6a1f1dSLionel Sambuc.It gelf_* 124*0a6a1f1dSLionel SambucFor functions defined in the API set. 125*0a6a1f1dSLionel Sambuc.El 126*0a6a1f1dSLionel Sambuc.Ss GElf Programming APIs 127*0a6a1f1dSLionel SambucThis section provides an overview of the GElf programming APIs. 128*0a6a1f1dSLionel SambucFurther information is provided in the manual page of each function 129*0a6a1f1dSLionel Sambuclisted here. 130*0a6a1f1dSLionel Sambuc.Bl -tag 131*0a6a1f1dSLionel Sambuc.It "Allocating ELF Data Structures" 132*0a6a1f1dSLionel Sambuc.Bl -tag -compact 133*0a6a1f1dSLionel Sambuc.It Fn gelf_newehdr 134*0a6a1f1dSLionel SambucAllocate a new ELF Executable Header. 135*0a6a1f1dSLionel Sambuc.It Fn gelf_newphdr 136*0a6a1f1dSLionel SambucAllocate a new ELF Program Header Table. 137*0a6a1f1dSLionel Sambuc.El 138*0a6a1f1dSLionel Sambuc.It "Data Translation" 139*0a6a1f1dSLionel Sambuc.Bl -tag -compact 140*0a6a1f1dSLionel Sambuc.It Fn gelf_xlatetof 141*0a6a1f1dSLionel SambucTranslate the native representation of an ELF data structure to its 142*0a6a1f1dSLionel Sambucfile representation. 143*0a6a1f1dSLionel Sambuc.It Fn gelf_xlatetom 144*0a6a1f1dSLionel SambucTranslate from the file representation of an ELF data structure to a 145*0a6a1f1dSLionel Sambucnative representation. 146*0a6a1f1dSLionel Sambuc.El 147*0a6a1f1dSLionel Sambuc.It "Retrieving ELF Data" 148*0a6a1f1dSLionel Sambuc.Bl -tag -compact 149*0a6a1f1dSLionel Sambuc.It Fn gelf_getdyn 150*0a6a1f1dSLionel SambucRetrieve an ELF 151*0a6a1f1dSLionel Sambuc.Sy .dynamic 152*0a6a1f1dSLionel Sambuctable entry. 153*0a6a1f1dSLionel Sambuc.It Fn gelf_getehdr 154*0a6a1f1dSLionel SambucRetrieve an ELF Executable Header from the underlying ELF descriptor. 155*0a6a1f1dSLionel Sambuc.It Fn gelf_getphdr 156*0a6a1f1dSLionel SambucRetrieve an ELF Program Header Table entry from the underlying ELF descriptor. 157*0a6a1f1dSLionel Sambuc.It Fn gelf_getrel 158*0a6a1f1dSLionel SambucRetrieve an ELF relocation entry. 159*0a6a1f1dSLionel Sambuc.It Fn gelf_getrela 160*0a6a1f1dSLionel SambucRetrieve an ELF relocation entry with addend. 161*0a6a1f1dSLionel Sambuc.It Fn gelf_getshdr 162*0a6a1f1dSLionel SambucRetrieve an ELF Section Header Table entry from the underlying ELF descriptor. 163*0a6a1f1dSLionel Sambuc.It Fn gelf_getsym 164*0a6a1f1dSLionel SambucRetrieve an ELF symbol table entry. 165*0a6a1f1dSLionel Sambuc.El 166*0a6a1f1dSLionel Sambuc.It Queries 167*0a6a1f1dSLionel Sambuc.Bl -tag -compact 168*0a6a1f1dSLionel Sambuc.It Fn gelf_checksum 169*0a6a1f1dSLionel SambucRetrieves the ELF checksum for an ELF descriptor. 170*0a6a1f1dSLionel Sambuc.It Fn gelf_fsize 171*0a6a1f1dSLionel SambucRetrieves the size of the file representation of an ELF type. 172*0a6a1f1dSLionel Sambuc.It Fn gelf_getclass 173*0a6a1f1dSLionel SambucRetrieves the ELF class of an ELF descriptor. 174*0a6a1f1dSLionel Sambuc.El 175*0a6a1f1dSLionel Sambuc.It "Updating ELF Data" 176*0a6a1f1dSLionel Sambuc.Bl -tag -compact -width ".Fn gelf_update_shdr" 177*0a6a1f1dSLionel Sambuc.It Fn gelf_update_dyn 178*0a6a1f1dSLionel SambucCopy back an ELF 179*0a6a1f1dSLionel Sambuc.Sy .dynamic 180*0a6a1f1dSLionel SambucTable entry. 181*0a6a1f1dSLionel Sambuc.It Fn gelf_update_phdr 182*0a6a1f1dSLionel SambucCopy back an ELF Program Header Table entry. 183*0a6a1f1dSLionel Sambuc.It Fn gelf_update_rel 184*0a6a1f1dSLionel SambucCopy back an ELF relocation entry. 185*0a6a1f1dSLionel Sambuc.It Fn gelf_update_rela 186*0a6a1f1dSLionel SambucCopy back an ELF relocation with addend entry. 187*0a6a1f1dSLionel Sambuc.It Fn gelf_update_shdr 188*0a6a1f1dSLionel SambucCopy back an ELF Section Header Table entry. 189*0a6a1f1dSLionel Sambuc.It Fn gelf_update_sym 190*0a6a1f1dSLionel SambucCopy back an ELF symbol table entry. 191*0a6a1f1dSLionel Sambuc.El 192*0a6a1f1dSLionel Sambuc.El 193*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 194*0a6a1f1dSLionel Sambuc.Xr elf 3 , 195*0a6a1f1dSLionel Sambuc.Xr elf 5 196*0a6a1f1dSLionel Sambuc.Sh HISTORY 197*0a6a1f1dSLionel SambucThe GELF(3) API first appeared in System V Release 4. 198*0a6a1f1dSLionel SambucThis implementation of the API first appeared in 199*0a6a1f1dSLionel Sambuc.Fx 7.0 . 200*0a6a1f1dSLionel Sambuc.Sh AUTHORS 201*0a6a1f1dSLionel SambucThe GElf API was implemented by 202*0a6a1f1dSLionel Sambuc.An "Joseph Koshy" 203*0a6a1f1dSLionel Sambuc.Aq jkoshy@FreeBSD.org . 204