1*5ac3bc71Schristos.\" $NetBSD: gelf.3,v 1.5 2024/03/03 17:37:33 christos Exp $ 2e81373b4Schristos.\" 39dd9d0cfSchristos.\" Copyright (c) 2006,2008 Joseph Koshy. All rights reserved. 49dd9d0cfSchristos.\" 59dd9d0cfSchristos.\" Redistribution and use in source and binary forms, with or without 69dd9d0cfSchristos.\" modification, are permitted provided that the following conditions 79dd9d0cfSchristos.\" are met: 89dd9d0cfSchristos.\" 1. Redistributions of source code must retain the above copyright 99dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer. 109dd9d0cfSchristos.\" 2. Redistributions in binary form must reproduce the above copyright 119dd9d0cfSchristos.\" notice, this list of conditions and the following disclaimer in the 129dd9d0cfSchristos.\" documentation and/or other materials provided with the distribution. 139dd9d0cfSchristos.\" 149dd9d0cfSchristos.\" This software is provided by Joseph Koshy ``as is'' and 159dd9d0cfSchristos.\" any express or implied warranties, including, but not limited to, the 169dd9d0cfSchristos.\" implied warranties of merchantability and fitness for a particular purpose 179dd9d0cfSchristos.\" are disclaimed. in no event shall Joseph Koshy be liable 189dd9d0cfSchristos.\" for any direct, indirect, incidental, special, exemplary, or consequential 199dd9d0cfSchristos.\" damages (including, but not limited to, procurement of substitute goods 209dd9d0cfSchristos.\" or services; loss of use, data, or profits; or business interruption) 219dd9d0cfSchristos.\" however caused and on any theory of liability, whether in contract, strict 229dd9d0cfSchristos.\" liability, or tort (including negligence or otherwise) arising in any way 239dd9d0cfSchristos.\" out of the use of this software, even if advised of the possibility of 249dd9d0cfSchristos.\" such damage. 259dd9d0cfSchristos.\" 26c5261b83Sjkoshy.\" Id: gelf.3 3743 2019-06-12 19:36:30Z jkoshy 279dd9d0cfSchristos.\" 28c5261b83Sjkoshy.Dd June 12, 2019 299dd9d0cfSchristos.Dt GELF 3 30c5261b83Sjkoshy.Os 319dd9d0cfSchristos.Sh NAME 32c5261b83Sjkoshy.Nm gelf 339dd9d0cfSchristos.Nd class-independent API for ELF manipulation 349dd9d0cfSchristos.Sh LIBRARY 359dd9d0cfSchristos.Lb libelf 369dd9d0cfSchristos.Sh SYNOPSIS 379dd9d0cfSchristos.In gelf.h 389dd9d0cfSchristos.Sh DESCRIPTION 399dd9d0cfSchristosThis manual page describes a class independent API for manipulating 409dd9d0cfSchristosELF objects. 419dd9d0cfSchristosThis API allows an application to operate on ELF descriptors without 429dd9d0cfSchristosneeding to the know the ELF class of the descriptor. 439dd9d0cfSchristos.Pp 449dd9d0cfSchristosThe GElf API may be used alongside the ELF API without restriction. 459dd9d0cfSchristos.Ss GElf Data Structures 469dd9d0cfSchristosThe GElf API defines the following class-independent data structures: 479dd9d0cfSchristos.Bl -tag -width GElf_Sxword 489dd9d0cfSchristos.It Vt GElf_Addr 499dd9d0cfSchristosA representation of ELF addresses. 509dd9d0cfSchristos.It Vt GElf_Dyn 519dd9d0cfSchristosA class-independent representation of ELF 529dd9d0cfSchristos.Sy .dynamic 539dd9d0cfSchristossection entries. 549dd9d0cfSchristos.It Vt GElf_Ehdr 559dd9d0cfSchristosA class-independent representation of an ELF Executable Header. 569dd9d0cfSchristos.It Vt GElf_Half 579dd9d0cfSchristosAn unsigned 16 bit quantity. 589dd9d0cfSchristos.It Vt GElf_Off 599dd9d0cfSchristosA class-independent representation of a ELF offset. 609dd9d0cfSchristos.It Vt GElf_Phdr 619dd9d0cfSchristosA class-independent representation of an ELF Program Header Table 629dd9d0cfSchristosentry. 639dd9d0cfSchristos.It Vt GElf_Rel 649dd9d0cfSchristosA class-independent representation of an ELF relocation entry. 659dd9d0cfSchristos.It Vt GElf_Rela 669dd9d0cfSchristosA class-independent representation of an ELF relocation entry with 679dd9d0cfSchristosaddend. 689dd9d0cfSchristos.It Vt GElf_Shdr 699dd9d0cfSchristosA class-independent representation of an ELF Section Header Table 709dd9d0cfSchristosentry. 719dd9d0cfSchristos.It Vt GElf_Sword 729dd9d0cfSchristosA signed 32 bit quantity. 739dd9d0cfSchristos.It Vt GElf_Sxword 749dd9d0cfSchristosA signed 64 bit quantity. 759dd9d0cfSchristos.It Vt GElf_Sym 769dd9d0cfSchristosA class-independent representation of an ELF symbol table entry. 779dd9d0cfSchristos.It Vt GElf_Word 789dd9d0cfSchristosAn unsigned 32 bit quantity. 799dd9d0cfSchristos.It Vt GElf_Xword 809dd9d0cfSchristosAn unsigned 64 bit quantity. 819dd9d0cfSchristos.El 829dd9d0cfSchristos.Pp 839dd9d0cfSchristosThese data structures are sized to be compatible with the 849dd9d0cfSchristoscorresponding 64 bit ELF structures, and have the same internal 859dd9d0cfSchristosstructure as their 64 bit class-dependent counterparts. 869dd9d0cfSchristosClass-dependent ELF structures are described in 879dd9d0cfSchristos.Xr elf 5 . 889dd9d0cfSchristos.Ss GElf Programming Model 899dd9d0cfSchristosGElf functions always return a 909dd9d0cfSchristos.Em copy 919dd9d0cfSchristosof the underlying (class-dependent) ELF data structure. 929dd9d0cfSchristosThe programming model with GElf is as follows: 939dd9d0cfSchristos.Bl -enum 949dd9d0cfSchristos.It 959dd9d0cfSchristosAn application will retrieve data from an ELF descriptor using a 969dd9d0cfSchristos.Fn gelf_get_* 979dd9d0cfSchristosfunction. 989dd9d0cfSchristosThis will copy out data into a private 999dd9d0cfSchristos.Vt GElf_* 1009dd9d0cfSchristosdata structure. 1019dd9d0cfSchristos.It 1029dd9d0cfSchristosThe application will work with its private copy of the GElf 1039dd9d0cfSchristosstructure. 1049dd9d0cfSchristos.It 1059dd9d0cfSchristosOnce done, the application copies the new values back to the 1069dd9d0cfSchristosunderlying ELF data structure using the 1079dd9d0cfSchristos.Fn gelf_update_* 1089dd9d0cfSchristosfunctions. 1099dd9d0cfSchristos.It 1109dd9d0cfSchristosThe application will then use the 1119dd9d0cfSchristos.Fn elf_flag* 1129dd9d0cfSchristosAPIs to indicate to the ELF library that an ELF data structure is dirty. 1139dd9d0cfSchristos.El 1149dd9d0cfSchristos.Pp 1159dd9d0cfSchristosWhen updating an underlying 32 bit ELF data structure, the GElf 1169dd9d0cfSchristosroutines will signal an error if a GElf value is out of range 1179dd9d0cfSchristosfor the underlying ELF data type. 1189dd9d0cfSchristos.Ss Namespace use 1199dd9d0cfSchristosThe GElf interface uses the following symbols: 120c5261b83Sjkoshy.Bl -tag -width indent 1219dd9d0cfSchristos.It GElf_* 1229dd9d0cfSchristosClass-independent data types. 1239dd9d0cfSchristos.It gelf_* 1249dd9d0cfSchristosFor functions defined in the API set. 1259dd9d0cfSchristos.El 1269dd9d0cfSchristos.Ss GElf Programming APIs 1279dd9d0cfSchristosThis section provides an overview of the GElf programming APIs. 1289dd9d0cfSchristosFurther information is provided in the manual page of each function 1299dd9d0cfSchristoslisted here. 130c5261b83Sjkoshy.Bl -tag -width indent 1319dd9d0cfSchristos.It "Allocating ELF Data Structures" 132c5261b83Sjkoshy.Bl -tag -compact -width indent 1339dd9d0cfSchristos.It Fn gelf_newehdr 1349dd9d0cfSchristosAllocate a new ELF Executable Header. 1359dd9d0cfSchristos.It Fn gelf_newphdr 1369dd9d0cfSchristosAllocate a new ELF Program Header Table. 1379dd9d0cfSchristos.El 1389dd9d0cfSchristos.It "Data Translation" 139c5261b83Sjkoshy.Bl -tag -compact -width indent 1409dd9d0cfSchristos.It Fn gelf_xlatetof 1419dd9d0cfSchristosTranslate the native representation of an ELF data structure to its 1429dd9d0cfSchristosfile representation. 1439dd9d0cfSchristos.It Fn gelf_xlatetom 1449dd9d0cfSchristosTranslate from the file representation of an ELF data structure to a 1459dd9d0cfSchristosnative representation. 1469dd9d0cfSchristos.El 1479dd9d0cfSchristos.It "Retrieving ELF Data" 148c5261b83Sjkoshy.Bl -tag -compact -width indent 1499dd9d0cfSchristos.It Fn gelf_getdyn 1509dd9d0cfSchristosRetrieve an ELF 1519dd9d0cfSchristos.Sy .dynamic 1529dd9d0cfSchristostable entry. 1539dd9d0cfSchristos.It Fn gelf_getehdr 1549dd9d0cfSchristosRetrieve an ELF Executable Header from the underlying ELF descriptor. 1559dd9d0cfSchristos.It Fn gelf_getphdr 1569dd9d0cfSchristosRetrieve an ELF Program Header Table entry from the underlying ELF descriptor. 1579dd9d0cfSchristos.It Fn gelf_getrel 1589dd9d0cfSchristosRetrieve an ELF relocation entry. 1599dd9d0cfSchristos.It Fn gelf_getrela 1609dd9d0cfSchristosRetrieve an ELF relocation entry with addend. 1619dd9d0cfSchristos.It Fn gelf_getshdr 1629dd9d0cfSchristosRetrieve an ELF Section Header Table entry from the underlying ELF descriptor. 1639dd9d0cfSchristos.It Fn gelf_getsym 1649dd9d0cfSchristosRetrieve an ELF symbol table entry. 1659dd9d0cfSchristos.El 1669dd9d0cfSchristos.It Queries 167c5261b83Sjkoshy.Bl -tag -compact -width indent 1689dd9d0cfSchristos.It Fn gelf_checksum 1699dd9d0cfSchristosRetrieves the ELF checksum for an ELF descriptor. 1709dd9d0cfSchristos.It Fn gelf_fsize 1719dd9d0cfSchristosRetrieves the size of the file representation of an ELF type. 1729dd9d0cfSchristos.It Fn gelf_getclass 1739dd9d0cfSchristosRetrieves the ELF class of an ELF descriptor. 1749dd9d0cfSchristos.El 1759dd9d0cfSchristos.It "Updating ELF Data" 1769dd9d0cfSchristos.Bl -tag -compact -width ".Fn gelf_update_shdr" 1779dd9d0cfSchristos.It Fn gelf_update_dyn 1789dd9d0cfSchristosCopy back an ELF 1799dd9d0cfSchristos.Sy .dynamic 1809dd9d0cfSchristosTable entry. 1819dd9d0cfSchristos.It Fn gelf_update_phdr 1829dd9d0cfSchristosCopy back an ELF Program Header Table entry. 1839dd9d0cfSchristos.It Fn gelf_update_rel 1849dd9d0cfSchristosCopy back an ELF relocation entry. 1859dd9d0cfSchristos.It Fn gelf_update_rela 1869dd9d0cfSchristosCopy back an ELF relocation with addend entry. 1879dd9d0cfSchristos.It Fn gelf_update_shdr 1889dd9d0cfSchristosCopy back an ELF Section Header Table entry. 1899dd9d0cfSchristos.It Fn gelf_update_sym 1909dd9d0cfSchristosCopy back an ELF symbol table entry. 1919dd9d0cfSchristos.El 1929dd9d0cfSchristos.El 1939dd9d0cfSchristos.Sh SEE ALSO 1949dd9d0cfSchristos.Xr elf 3 , 1959dd9d0cfSchristos.Xr elf 5 1969dd9d0cfSchristos.Sh HISTORY 197c5261b83SjkoshyThe 198c5261b83Sjkoshy.Nm 199c5261b83SjkoshyAPI first appeared in 200c5261b83Sjkoshy.At V.4 . 2019dd9d0cfSchristosThis implementation of the API first appeared in 2029dd9d0cfSchristos.Fx 7.0 . 2039dd9d0cfSchristos.Sh AUTHORS 2049dd9d0cfSchristosThe GElf API was implemented by 20542bd3019Schristos.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org . 206