1*d003e0d7SEd Maste.\" Copyright (c) 2006-2008,2011,2019 Joseph Koshy. All rights reserved. 22de3b87aSKai Wang.\" 32de3b87aSKai Wang.\" Redistribution and use in source and binary forms, with or without 42de3b87aSKai Wang.\" modification, are permitted provided that the following conditions 52de3b87aSKai Wang.\" are met: 62de3b87aSKai Wang.\" 1. Redistributions of source code must retain the above copyright 72de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer. 82de3b87aSKai Wang.\" 2. Redistributions in binary form must reproduce the above copyright 92de3b87aSKai Wang.\" notice, this list of conditions and the following disclaimer in the 102de3b87aSKai Wang.\" documentation and/or other materials provided with the distribution. 112de3b87aSKai Wang.\" 122de3b87aSKai Wang.\" This software is provided by Joseph Koshy ``as is'' and 132de3b87aSKai Wang.\" any express or implied warranties, including, but not limited to, the 142de3b87aSKai Wang.\" implied warranties of merchantability and fitness for a particular purpose 152de3b87aSKai Wang.\" are disclaimed. in no event shall Joseph Koshy be liable 162de3b87aSKai Wang.\" for any direct, indirect, incidental, special, exemplary, or consequential 172de3b87aSKai Wang.\" damages (including, but not limited to, procurement of substitute goods 182de3b87aSKai Wang.\" or services; loss of use, data, or profits; or business interruption) 192de3b87aSKai Wang.\" however caused and on any theory of liability, whether in contract, strict 202de3b87aSKai Wang.\" liability, or tort (including negligence or otherwise) arising in any way 212de3b87aSKai Wang.\" out of the use of this software, even if advised of the possibility of 222de3b87aSKai Wang.\" such damage. 232de3b87aSKai Wang.\" 24*d003e0d7SEd Maste.\" $Id: elf.3 3743 2019-06-12 19:36:30Z jkoshy $ 252de3b87aSKai Wang.\" 26*d003e0d7SEd Maste.Dd June 12, 2019 272de3b87aSKai Wang.Dt ELF 3 28ae500c1fSEd Maste.Os 292de3b87aSKai Wang.Sh NAME 302de3b87aSKai Wang.Nm elf 312de3b87aSKai Wang.Nd API for manipulating ELF objects 322de3b87aSKai Wang.Sh LIBRARY 332de3b87aSKai Wang.Lb libelf 342de3b87aSKai Wang.Sh SYNOPSIS 352de3b87aSKai Wang.In libelf.h 362de3b87aSKai Wang.Sh DESCRIPTION 372de3b87aSKai WangThe 382de3b87aSKai Wang.Lb libelf 392de3b87aSKai Wangprovides functions that allow an application to read and manipulate 402de3b87aSKai WangELF object files, and to read 412de3b87aSKai Wang.Xr ar 1 422de3b87aSKai Wangarchives. 432de3b87aSKai WangThe library allows the manipulation of ELF objects in a byte ordering 442de3b87aSKai Wangand word-size independent way, allowing an application to read and 452de3b87aSKai Wangcreate ELF objects for 32 and 64 bit architectures and for little- 462de3b87aSKai Wangand big-endian machines. 472de3b87aSKai WangThe library is capable of processing ELF objects that use extended 482de3b87aSKai Wangsection numbering. 492de3b87aSKai Wang.Pp 502de3b87aSKai WangThis manual page serves to provide an overview of the functionality in 512de3b87aSKai Wangthe ELF library. 522de3b87aSKai WangFurther information may found in the manual pages for individual 532de3b87aSKai Wang.Xr ELF 3 542de3b87aSKai Wangfunctions that comprise the library. 552de3b87aSKai Wang.Ss ELF Concepts 562de3b87aSKai WangAs described in 572de3b87aSKai Wang.Xr elf 5 , 582de3b87aSKai WangELF files contain several data structures that are laid out in a 592de3b87aSKai Wangspecific way. 602de3b87aSKai WangELF files begin with an 612de3b87aSKai Wang.Dq Executable Header , 622de3b87aSKai Wangand may contain an optional 632de3b87aSKai Wang.Dq Program Header Table , 642de3b87aSKai Wangand optional data in the form of ELF 652de3b87aSKai Wang.Dq sections . 662de3b87aSKai WangA 672de3b87aSKai Wang.Dq Section Header Table 682de3b87aSKai Wangdescribes the content of the data in these sections. 692de3b87aSKai Wang.Pp 702de3b87aSKai WangELF objects have an associated 712de3b87aSKai Wang.Dq "ELF class" 722de3b87aSKai Wangwhich denotes the natural machine word size for the architecture 732de3b87aSKai Wangthe object is associated with. 742de3b87aSKai WangObjects for 32 bit architectures have an ELF class of 752de3b87aSKai Wang.Dv ELFCLASS32 . 762de3b87aSKai WangObjects for 64 bit architectures have an ELF class of 772de3b87aSKai Wang.Dv ELFCLASS64 . 782de3b87aSKai Wang.Pp 792de3b87aSKai WangELF objects also have an associated 802de3b87aSKai Wang.Dq endianness 812de3b87aSKai Wangwhich denotes the endianness of the machine architecture associated 822de3b87aSKai Wangwith the object. 832de3b87aSKai WangThis may be 842de3b87aSKai Wang.Dv ELFDATA2LSB 852de3b87aSKai Wangfor little-endian architectures and 862de3b87aSKai Wang.Dv ELFDATA2MSB 872de3b87aSKai Wangfor big-endian architectures. 882de3b87aSKai Wang.Pp 892de3b87aSKai WangELF objects are also associated with an API version number. 902de3b87aSKai WangThis version number determines the layout of the individual components 912de3b87aSKai Wangof an ELF file and the semantics associated with these. 922de3b87aSKai Wang.Ss Data Representation And Translation 932de3b87aSKai WangThe 942de3b87aSKai Wang.Xr ELF 3 952de3b87aSKai Wanglibrary distinguishes between 962de3b87aSKai Wang.Dq native 972de3b87aSKai Wangrepresentations of ELF data structures and their 982de3b87aSKai Wang.Dq file 992de3b87aSKai Wangrepresentations. 1002de3b87aSKai Wang.Pp 1012de3b87aSKai WangAn application would work with ELF data in its 1022de3b87aSKai Wang.Dq native 1032de3b87aSKai Wangrepresentation, i.e., using the native byteorder and alignment mandated 1042de3b87aSKai Wangby the processor the application is running on. 1052de3b87aSKai WangThe 1062de3b87aSKai Wang.Dq file 1072de3b87aSKai Wangrepresentation of the same data could use a different byte ordering 1082de3b87aSKai Wangand follow different constraints on object alignment than these native 1092de3b87aSKai Wangconstraints. 1102de3b87aSKai Wang.Pp 1112de3b87aSKai WangAccordingly, the 1122de3b87aSKai Wang.Xr ELF 3 1132de3b87aSKai Wanglibrary offers translation facilities 1142de3b87aSKai Wang.Xr ( elf32_xlatetof 3 , 1152de3b87aSKai Wang.Xr elf32_xlatetom 3 , 1162de3b87aSKai Wang.Xr elf64_xlatetof 3 1172de3b87aSKai Wangand 1182de3b87aSKai Wang.Xr elf64_xlatetom 3 ) 119ae500c1fSEd Masteto and from these representations. 120ae500c1fSEd MasteIt also provides higher-level APIs 121ae500c1fSEd Maste.Xr ( gelf_xlatetof 3 , 122ae500c1fSEd Maste.Xr gelf_xlatetom 3 ) 123ae500c1fSEd Mastethat retrieve and store data from the ELF object in a class-agnostic 124ae500c1fSEd Mastemanner. 1252de3b87aSKai Wang.Ss Library Working Version 1262de3b87aSKai WangConceptually, there are three version numbers associated with an 1272de3b87aSKai Wangapplication using the ELF library to manipulate ELF objects: 1282de3b87aSKai Wang.Bl -bullet -compact -offset indent 1292de3b87aSKai Wang.It 1302de3b87aSKai WangThe ELF version that the application was compiled against. 1312de3b87aSKai WangThis version determines the ABI expected by the application. 1322de3b87aSKai Wang.It 1332de3b87aSKai WangThe ELF version of the ELF object being manipulated by the 1342de3b87aSKai Wangapplication through the ELF library. 1352de3b87aSKai Wang.It 1362de3b87aSKai WangThe ELF version (or set of versions) supported by the ELF library itself. 1372de3b87aSKai Wang.El 1382de3b87aSKai Wang.Pp 1392de3b87aSKai WangIn order to facilitate working with ELF objects of differing versions, 1402de3b87aSKai Wangthe ELF library requires the application to call the 1412de3b87aSKai Wang.Fn elf_version 1422de3b87aSKai Wangfunction before invoking many of its operations, in order to inform 1432de3b87aSKai Wangthe library of the application's desired working version. 1442de3b87aSKai Wang.Pp 1452de3b87aSKai WangIn the current implementation, all three versions have to be 1462de3b87aSKai Wang.Dv EV_CURRENT . 1472de3b87aSKai Wang.Ss Namespace use 1482de3b87aSKai WangThe ELF library uses the following prefixes: 1492de3b87aSKai Wang.Bl -tag -width "ELF_F_*" 1502de3b87aSKai Wang.It Dv elf_ 1512de3b87aSKai WangUsed for class-independent functions. 1522de3b87aSKai Wang.It Dv elf32_ 1532de3b87aSKai WangUsed for functions working with 32 bit ELF objects. 1542de3b87aSKai Wang.It Dv elf64_ 1552de3b87aSKai WangUsed for functions working with 64 bit ELF objects. 1562de3b87aSKai Wang.It Dv Elf_ 1572de3b87aSKai WangUsed for class-independent data types. 1582de3b87aSKai Wang.It Dv ELF_C_ 1592de3b87aSKai WangUsed for command values used in a few functions. 1602de3b87aSKai WangThese symbols are defined as members of the 161ae500c1fSEd Maste.Vt Elf_Cmd 1622de3b87aSKai Wangenumeration. 1632de3b87aSKai Wang.It Dv ELF_E_ 1642de3b87aSKai WangUsed for error numbers. 1652de3b87aSKai Wang.It Dv ELF_F_ 1662de3b87aSKai WangUsed for flags. 1672de3b87aSKai Wang.It Dv ELF_K_ 1682de3b87aSKai WangThese constants define the kind of file associated with an ELF 1692de3b87aSKai Wangdescriptor. 1702de3b87aSKai WangSee 1712de3b87aSKai Wang.Xr elf_kind 3 . 1722de3b87aSKai WangThe symbols are defined by the 1732de3b87aSKai Wang.Vt Elf_Kind 1742de3b87aSKai Wangenumeration. 1752de3b87aSKai Wang.It Dv ELF_T_ 1762de3b87aSKai WangThese values are defined by the 1772de3b87aSKai Wang.Vt Elf_Type 1782de3b87aSKai Wangenumeration, and denote the types of ELF data structures 1792de3b87aSKai Wangthat can be present in an ELF object. 1802de3b87aSKai Wang.El 1812de3b87aSKai Wang.Pp 1822de3b87aSKai WangIn addition, the library uses symbols with prefixes 1832de3b87aSKai Wang.Dv _ELF 1842de3b87aSKai Wangand 1852de3b87aSKai Wang.Dv _libelf 1862de3b87aSKai Wangfor its internal use. 1872de3b87aSKai Wang.Ss Descriptors 1882de3b87aSKai WangApplications communicate with the library using descriptors. 1892de3b87aSKai WangThese are: 1902de3b87aSKai Wang.Bl -tag -width ".Vt Elf_Data" 1912de3b87aSKai Wang.It Vt Elf 1922de3b87aSKai WangAn 1932de3b87aSKai Wang.Vt Elf 1942de3b87aSKai Wangdescriptor represents an ELF object or an 1952de3b87aSKai Wang.Xr ar 1 1962de3b87aSKai Wangarchive. 1972de3b87aSKai WangIt is allocated using one of the 1982de3b87aSKai Wang.Fn elf_begin 1992de3b87aSKai Wangor 2002de3b87aSKai Wang.Fn elf_memory 2012de3b87aSKai Wangfunctions. 2022de3b87aSKai WangAn 2032de3b87aSKai Wang.Vt Elf 2042de3b87aSKai Wangdescriptor can be used to read and write data to an ELF file. 2052de3b87aSKai WangAn 2062de3b87aSKai Wang.Vt Elf 2072de3b87aSKai Wangdescriptor can be associated with zero or more 2082de3b87aSKai Wang.Vt Elf_Scn 2092de3b87aSKai Wangsection descriptors. 2102de3b87aSKai Wang.Pp 2112de3b87aSKai WangGiven an ELF descriptor, the application may retrieve the ELF 2122de3b87aSKai Wangobject's class-dependent 2132de3b87aSKai Wang.Dq "Executable Header" 2142de3b87aSKai Wangstructures using the 2152de3b87aSKai Wang.Fn elf32_getehdr 2162de3b87aSKai Wangor 2172de3b87aSKai Wang.Fn elf64_getehdr 2182de3b87aSKai Wangfunctions. 2192de3b87aSKai WangA new Ehdr structure may be allocated using the 2202de3b87aSKai Wang.Fn elf64_newehdr 2212de3b87aSKai Wangor 2222de3b87aSKai Wang.Fn elf64_newehdr 2232de3b87aSKai Wangfunctions. 2242de3b87aSKai Wang.Pp 2252de3b87aSKai WangThe 2262de3b87aSKai Wang.Dq "Program Header Table" 2272de3b87aSKai Wangassociated with an ELF descriptor may be allocated using the 2282de3b87aSKai Wang.Fn elf32_getphdr 2292de3b87aSKai Wangor 2302de3b87aSKai Wang.Fn elf64_getphdr 2312de3b87aSKai Wangfunctions. 2322de3b87aSKai WangA new program header table may be allocated or an existing table 2332de3b87aSKai Wangresized using the 2342de3b87aSKai Wang.Fn elf32_newphdr 2352de3b87aSKai Wangor 2362de3b87aSKai Wang.Fn elf64_newphdr 2372de3b87aSKai Wangfunctions. 2382de3b87aSKai Wang.Pp 2392de3b87aSKai WangThe 2402de3b87aSKai Wang.Vt Elf 2412de3b87aSKai Wangstructure is opaque and has no members visible to the 2422de3b87aSKai Wangapplication. 2432de3b87aSKai Wang.It Vt Elf_Data 2442de3b87aSKai WangAn 2452de3b87aSKai Wang.Vt Elf_Data 2462de3b87aSKai Wangdata structure describes an individual chunk of a ELF file as 2472de3b87aSKai Wangrepresented in memory. 2482de3b87aSKai WangIt has the following application-visible members: 2492de3b87aSKai Wang.Bl -tag -width ".Vt unsigned int d_version" -compact 2502de3b87aSKai Wang.It Vt "uint64_t d_align" 2512de3b87aSKai WangThe in-file alignment of the data buffer within its containing ELF section. 2522de3b87aSKai WangThis value must be non-zero and a power of two. 2532de3b87aSKai Wang.It Vt "void *d_buf" 2542de3b87aSKai WangA pointer to data in memory. 2552de3b87aSKai Wang.It Vt "uint64_t d_off" 2562de3b87aSKai WangThe offset within the containing section where this descriptor's data 2572de3b87aSKai Wangwould be placed. 2582de3b87aSKai WangThis field will be computed by the library unless the application 2592de3b87aSKai Wangrequests full control of the ELF object's layout. 2602de3b87aSKai Wang.It Vt "uint64_t d_size" 2612de3b87aSKai WangThe number of bytes of data in this descriptor. 2622de3b87aSKai Wang.It Vt "Elf_Type d_type" 2632de3b87aSKai WangThe ELF type (see below) of the data in this descriptor. 2642de3b87aSKai Wang.It Vt "unsigned int d_version" 2652de3b87aSKai WangThe operating version for the data in this buffer. 2662de3b87aSKai Wang.El 2672de3b87aSKai Wang.Pp 2682de3b87aSKai Wang.Vt Elf_Data 269*d003e0d7SEd Mastedescriptors are usually used in conjunction with 2702de3b87aSKai Wang.Vt Elf_Scn 2712de3b87aSKai Wangdescriptors. 2722de3b87aSKai Wang.It Vt Elf_Scn 2732de3b87aSKai Wang.Vt Elf_Scn 274*d003e0d7SEd Mastedescriptors represent sections in an ELF object. 275*d003e0d7SEd MasteThese descriptors are opaque and contain no application modifiable 276*d003e0d7SEd Mastefields. 2772de3b87aSKai Wang.Pp 278*d003e0d7SEd MasteThe 279*d003e0d7SEd Maste.Vt Elf_Scn 280*d003e0d7SEd Mastedescriptor for a specific section in an ELF object can be 281*d003e0d7SEd Masteretrieved using the 2822de3b87aSKai Wang.Fn elf_getscn 2832de3b87aSKai Wangfunction. 284*d003e0d7SEd MasteThe sections contained in an ELF object can be traversed using the 2852de3b87aSKai Wang.Fn elf_nextscn 2862de3b87aSKai Wangfunction. 287*d003e0d7SEd MasteNew sections are allocated using the 2882de3b87aSKai Wang.Fn elf_newscn 2892de3b87aSKai Wangfunction. 2902de3b87aSKai Wang.Pp 2912de3b87aSKai WangThe 292*d003e0d7SEd Maste.Vt Elf_Data 293*d003e0d7SEd Mastedescriptors associated with a given section can be retrieved 294*d003e0d7SEd Masteusing the 295*d003e0d7SEd Maste.Fn elf_getdata 296*d003e0d7SEd Mastefunction. 297*d003e0d7SEd MasteNew data descriptors can be added to a section 298*d003e0d7SEd Mastedescriptor using the 299*d003e0d7SEd Maste.Fn elf_newdata 300*d003e0d7SEd Mastefunction. 301*d003e0d7SEd MasteThe untranslated 302*d003e0d7SEd Maste.Dq file 303*d003e0d7SEd Masterepresentation of data in a section can be retrieved using the 304*d003e0d7SEd Maste.Fn elf_rawdata 305*d003e0d7SEd Mastefunction. 3062de3b87aSKai Wang.El 3072de3b87aSKai Wang.Ss Supported Elf Types 3082de3b87aSKai WangThe following ELF datatypes are supported by the library. 3092de3b87aSKai Wang.Pp 3102de3b87aSKai Wang.Bl -tag -width ".Dv ELF_T_SYMINFO" -compact 3112de3b87aSKai Wang.It Dv ELF_T_ADDR 3122de3b87aSKai WangMachine addresses. 3132de3b87aSKai Wang.It Dv ELF_T_BYTE 3142de3b87aSKai WangByte data. 3152de3b87aSKai WangThe library will not attempt to translate byte data. 3162de3b87aSKai Wang.It Dv ELF_T_CAP 3172de3b87aSKai WangSoftware and hardware capability records. 3182de3b87aSKai Wang.It Dv ELF_T_DYN 3192de3b87aSKai WangRecords used in a section of type 3202de3b87aSKai Wang.Dv SHT_DYNAMIC . 3212de3b87aSKai Wang.It Dv ELF_T_EHDR 3222de3b87aSKai WangELF executable header. 3232de3b87aSKai Wang.It Dv ELF_T_GNUHASH 3242de3b87aSKai WangGNU-style hash tables. 3252de3b87aSKai Wang.It Dv ELF_T_HALF 3262de3b87aSKai Wang16-bit unsigned words. 3272de3b87aSKai Wang.It Dv ELF_T_LWORD 3282de3b87aSKai Wang64 bit unsigned words. 3292de3b87aSKai Wang.It Dv ELF_T_MOVE 3302de3b87aSKai WangELF Move records. 3312de3b87aSKai Wang.\".It Dv ELF_T_MOVEP 3322de3b87aSKai Wang.\" As yet unsupported. 3332de3b87aSKai Wang.It Dv ELF_T_NOTE 3342de3b87aSKai WangELF Note structures. 3352de3b87aSKai Wang.It Dv ELF_T_OFF 3362de3b87aSKai WangFile offsets. 3372de3b87aSKai Wang.It Dv ELF_T_PHDR 3382de3b87aSKai WangELF program header table entries. 3392de3b87aSKai Wang.It Dv ELF_T_REL 3402de3b87aSKai WangELF relocation entries. 3412de3b87aSKai Wang.It Dv ELF_T_RELA 3422de3b87aSKai WangELF relocation entries with addends. 3432de3b87aSKai Wang.It Dv ELF_T_SHDR 3442de3b87aSKai WangELF section header entries. 3452de3b87aSKai Wang.It Dv ELF_T_SWORD 3462de3b87aSKai WangSigned 32-bit words. 3472de3b87aSKai Wang.It Dv ELF_T_SXWORD 3482de3b87aSKai WangSigned 64-bit words. 3492de3b87aSKai Wang.It Dv ELF_T_SYMINFO 3502de3b87aSKai WangELF symbol information. 3512de3b87aSKai Wang.It Dv ELF_T_SYM 3522de3b87aSKai WangELF symbol table entries. 3532de3b87aSKai Wang.It Dv ELF_T_VDEF 3542de3b87aSKai WangSymbol version definition records. 3552de3b87aSKai Wang.It Dv ELF_T_VNEED 3562de3b87aSKai WangSymbol version requirement records. 3572de3b87aSKai Wang.It Dv ELF_T_WORD 3582de3b87aSKai WangUnsigned 32-bit words. 3592de3b87aSKai Wang.It Dv ELF_T_XWORD 3602de3b87aSKai WangUnsigned 64-bit words. 3612de3b87aSKai Wang.El 3622de3b87aSKai Wang.Pp 3632de3b87aSKai WangThe symbol 3642de3b87aSKai Wang.Dv ELF_T_NUM 3652de3b87aSKai Wangdenotes the number of Elf types known to the library. 3662de3b87aSKai Wang.Pp 3672de3b87aSKai WangThe following table shows the mapping between ELF section types 3682de3b87aSKai Wangdefined in 3692de3b87aSKai Wang.Xr elf 5 3702de3b87aSKai Wangand the types supported by the library. 3712de3b87aSKai Wang.Bl -column ".Dv SHT_PREINIT_ARRAY" ".Dv ELF_T_SYMINFO" 3722de3b87aSKai Wang.It Em Section Type Ta Em "Library Type" Ta Em Description 3732de3b87aSKai Wang.It Dv SHT_DYNAMIC Ta Dv ELF_T_DYN Ta Xo 3742de3b87aSKai Wang.Sq .dynamic 3752de3b87aSKai Wangsection entries. 3762de3b87aSKai Wang.Xc 3772de3b87aSKai Wang.It Dv SHT_DYNSYM Ta Dv ELF_T_SYM Ta Symbols for dynamic linking. 3782de3b87aSKai Wang.It Dv SHT_FINI_ARRAY Ta Dv ELF_T_ADDR Ta Termination function pointers. 379cf781b2eSEd Maste.It Dv SHT_GNU_HASH Ta Dv ELF_T_GNUHASH Ta GNU hash sections. 380cf781b2eSEd Maste.It Dv SHT_GNU_LIBLIST Ta Dv ELF_T_WORD Ta List of libraries to be pre-linked. 381cf781b2eSEd Maste.It Dv SHT_GNU_verdef Ta Dv ELF_T_VDEF Ta Symbol version definitions. 382cf781b2eSEd Maste.It Dv SHT_GNU_verneed Ta Dv ELF_T_VNEED Ta Symbol versioning requirements. 383cf781b2eSEd Maste.It Dv SHT_GNU_versym Ta Dv ELF_T_HALF Ta Version symbols. 3842de3b87aSKai Wang.It Dv SHT_GROUP Ta Dv ELF_T_WORD Ta Section group marker. 3852de3b87aSKai Wang.It Dv SHT_HASH Ta Dv ELF_T_HASH Ta Symbol hashes. 3862de3b87aSKai Wang.It Dv SHT_INIT_ARRAY Ta Dv ELF_T_ADDR Ta Initialization function pointers. 3872de3b87aSKai Wang.It Dv SHT_NOBITS Ta Dv ELF_T_BYTE Ta Xo 3882de3b87aSKai WangEmpty sections. 3892de3b87aSKai WangSee 3902de3b87aSKai Wang.Xr elf 5 . 3912de3b87aSKai Wang.Xc 3922de3b87aSKai Wang.It Dv SHT_NOTE Ta Dv ELF_T_NOTE Ta ELF note records. 3932de3b87aSKai Wang.It Dv SHT_PREINIT_ARRAY Ta Dv ELF_T_ADDR Ta Pre-initialization function pointers. 3942de3b87aSKai Wang.It Dv SHT_PROGBITS Ta Dv ELF_T_BYTE Ta Machine code. 3952de3b87aSKai Wang.It Dv SHT_REL Ta Dv ELF_T_REL Ta ELF relocation records. 3962de3b87aSKai Wang.It Dv SHT_RELA Ta Dv ELF_T_RELA Ta Relocation records with addends. 3972de3b87aSKai Wang.It Dv SHT_STRTAB Ta Dv ELF_T_BYTE Ta String tables. 3982de3b87aSKai Wang.It Dv SHT_SYMTAB Ta Dv ELF_T_SYM Ta Symbol tables. 3992de3b87aSKai Wang.It Dv SHT_SYMTAB_SHNDX Ta Dv ELF_T_WORD Ta Used with extended section numbering. 400cf781b2eSEd Maste.It Dv SHT_SUNW_dof Ta Dv ELF_T_BYTE Ta Xo 401cf781b2eSEd MasteUsed by 402cf781b2eSEd Maste.Xr dtrace 1 . 403cf781b2eSEd Maste.Xc 4042de3b87aSKai Wang.It Dv SHT_SUNW_move Ta Dv ELF_T_MOVE Ta ELF move records. 4052de3b87aSKai Wang.It Dv SHT_SUNW_syminfo Ta Dv ELF_T_SYMINFO Ta Additional symbol flags. 406cf781b2eSEd Maste.It Dv SHT_SUNW_verdef Ta Dv ELF_T_VDEF Ta Xo 407cf781b2eSEd MasteSame as 408cf781b2eSEd Maste.Dv SHT_GNU_verdef . 409cf781b2eSEd Maste.Xc 410cf781b2eSEd Maste.It Dv SHT_SUNW_verneed Ta Dv ELF_T_VNEED Ta Xo 411cf781b2eSEd MasteSame as 412cf781b2eSEd Maste.Dv SHT_GNU_verneed . 413cf781b2eSEd Maste.Xc 414cf781b2eSEd Maste.It Dv SHT_SUNW_versym Ta Dv ELF_T_HALF Ta Xo 415cf781b2eSEd MasteSame as 416cf781b2eSEd Maste.Dv SHT_GNU_versym . 417cf781b2eSEd Maste.Xc 4182de3b87aSKai Wang.El 419cf781b2eSEd Maste.Pp 420cf781b2eSEd MasteSection types in the range 421ae500c1fSEd Maste.Dv [ SHT_LOOS , 422cf781b2eSEd Maste.Dv SHT_HIUSER ] 423cf781b2eSEd Masteare otherwise considered to be of type 424cf781b2eSEd Maste.Dv ELF_T_BYTE . 4252de3b87aSKai Wang.Ss Functional Grouping 4262de3b87aSKai WangThis section contains a brief overview of the available functionality 4272de3b87aSKai Wangin the ELF library. 4282de3b87aSKai WangEach function listed here is described further in its own manual page. 4292de3b87aSKai Wang.Bl -tag -width indent 4302de3b87aSKai Wang.It "Archive Access" 431ae500c1fSEd Maste.Bl -tag -compact -width indent 4322de3b87aSKai Wang.It Fn elf_getarsym 4332de3b87aSKai WangRetrieve the archive symbol table. 4342de3b87aSKai Wang.It Fn elf_getarhdr 4352de3b87aSKai WangRetrieve the archive header for an object. 4362de3b87aSKai Wang.It Fn elf_getbase 4372de3b87aSKai WangRetrieve the offset of a member inside an archive. 4382de3b87aSKai Wang.It Fn elf_next 4392de3b87aSKai WangIterate through an 4402de3b87aSKai Wang.Xr ar 1 4412de3b87aSKai Wangarchive. 4422de3b87aSKai Wang.It Fn elf_rand 4432de3b87aSKai WangRandom access inside an 4442de3b87aSKai Wang.Xr ar 1 4452de3b87aSKai Wangarchive. 4462de3b87aSKai Wang.El 4472de3b87aSKai Wang.It "Data Structures" 448ae500c1fSEd Maste.Bl -tag -compact -width indent 4492de3b87aSKai Wang.It Fn elf_getdata 4502de3b87aSKai WangRetrieve translated data for an ELF section. 4512de3b87aSKai Wang.It Fn elf_getscn 4522de3b87aSKai WangRetrieve the section descriptor for a named section. 4532de3b87aSKai Wang.It Fn elf_ndxscn 4542de3b87aSKai WangRetrieve the index for a section. 4552de3b87aSKai Wang.It Fn elf_newdata 4562de3b87aSKai WangAdd a new 4572de3b87aSKai Wang.Vt Elf_Data 4582de3b87aSKai Wangdescriptor to an ELF section. 4592de3b87aSKai Wang.It Fn elf_newscn 4602de3b87aSKai WangAdd a new section descriptor to an ELF descriptor. 4612de3b87aSKai Wang.It Fn elf_nextscn 4622de3b87aSKai WangIterate through the sections in an ELF object. 4632de3b87aSKai Wang.It Fn elf_rawdata 4642de3b87aSKai WangRetrieve untranslated data for an ELF section. 4652de3b87aSKai Wang.It Fn elf_rawfile 4662de3b87aSKai WangReturn a pointer to the untranslated file contents for an ELF object. 4672de3b87aSKai Wang.It Fn elf32_getehdr , Fn elf64_getehdr 4682de3b87aSKai WangRetrieve the Executable Header in an ELF object. 4692de3b87aSKai Wang.It Fn elf32_getphdr , Fn elf64_getphdr 4702de3b87aSKai WangRetrieve the Program Header Table in an ELF object. 4712de3b87aSKai Wang.It Fn elf32_getshdr , Fn elf64_getshdr 4722de3b87aSKai WangRetrieve the ELF section header associated with an 4732de3b87aSKai Wang.Vt Elf_Scn 4742de3b87aSKai Wangdescriptor. 4752de3b87aSKai Wang.It Fn elf32_newehdr , Fn elf64_newehdr 4762de3b87aSKai WangAllocate an Executable Header in an ELF object. 4772de3b87aSKai Wang.It Fn elf32_newphdr , Fn elf64_newphdr 4782de3b87aSKai WangAllocate or resize the Program Header Table in an ELF object. 4792de3b87aSKai Wang.El 4802de3b87aSKai Wang.It "Data Translation" 481ae500c1fSEd Maste.Bl -tag -compact -width indent 4822de3b87aSKai Wang.It Fn elf32_xlatetof , Fn elf64_xlatetof 4832de3b87aSKai WangTranslate an ELF data structure from its native representation to its 4842de3b87aSKai Wangfile representation. 4852de3b87aSKai Wang.It Fn elf32_xlatetom , Fn elf64_xlatetom 4862de3b87aSKai WangTranslate an ELF data structure from its file representation to a 4872de3b87aSKai Wangnative representation. 4882de3b87aSKai Wang.El 4892de3b87aSKai Wang.It "Error Reporting" 490ae500c1fSEd Maste.Bl -tag -compact -width indent 4912de3b87aSKai Wang.It Fn elf_errno 4922de3b87aSKai WangRetrieve the current error. 4932de3b87aSKai Wang.It Fn elf_errmsg 4942de3b87aSKai WangRetrieve a human readable description of the current error. 4952de3b87aSKai Wang.El 4962de3b87aSKai Wang.It "Initialization" 497ae500c1fSEd Maste.Bl -tag -compact -width indent 4982de3b87aSKai Wang.It Fn elf_begin 4992de3b87aSKai WangOpens an 5002de3b87aSKai Wang.Xr ar 1 5012de3b87aSKai Wangarchive or ELF object given a file descriptor. 5022de3b87aSKai Wang.It Fn elf_end 5032de3b87aSKai WangClose an ELF descriptor and release all its resources. 5042de3b87aSKai Wang.It Fn elf_memory 5052de3b87aSKai WangOpens an 5062de3b87aSKai Wang.Xr ar 1 5072de3b87aSKai Wangarchive or ELF object present in a memory arena. 5082de3b87aSKai Wang.It Fn elf_version 5092de3b87aSKai WangSets the operating version. 5102de3b87aSKai Wang.El 5112de3b87aSKai Wang.It "IO Control" 5122de3b87aSKai Wang.Bl -tag -width ".Fn elf_setshstrndx" -compact 5132de3b87aSKai Wang.It Fn elf_cntl 5142de3b87aSKai WangManage the association between and ELF descriptor and its underlying file. 5152de3b87aSKai Wang.It Fn elf_flagdata 5162de3b87aSKai WangMark an 5172de3b87aSKai Wang.Vt Elf_Data 5182de3b87aSKai Wangdescriptor as dirty. 5192de3b87aSKai Wang.It Fn elf_flagehdr 5202de3b87aSKai WangMark the ELF Executable Header in an ELF descriptor as dirty. 5212de3b87aSKai Wang.It Fn elf_flagphdr 5222de3b87aSKai WangMark the ELF Program Header Table in an ELF descriptor as dirty. 5232de3b87aSKai Wang.It Fn elf_flagscn 5242de3b87aSKai WangMark an 5252de3b87aSKai Wang.Vt Elf_Scn 5262de3b87aSKai Wangdescriptor as dirty. 5272de3b87aSKai Wang.It Fn elf_flagshdr 5282de3b87aSKai WangMark an ELF Section Header as dirty. 5292de3b87aSKai Wang.It Fn elf_setshstrndx 5302de3b87aSKai WangSet the index of the section name string table for the ELF object. 5312de3b87aSKai Wang.It Fn elf_update 5322de3b87aSKai WangRecompute ELF object layout and optionally write the modified object 5332de3b87aSKai Wangback to the underlying file. 5342de3b87aSKai Wang.El 5352de3b87aSKai Wang.It "Queries" 5362de3b87aSKai Wang.Bl -tag -width ".Fn elf_getshstrndx" -compact 5372de3b87aSKai Wang.It Fn elf32_checksum , Fn elf64_checkum 5382de3b87aSKai WangCompute checksum of an ELF object. 5392de3b87aSKai Wang.It Fn elf_getident 5402de3b87aSKai WangRetrieve the identification bytes for an ELF object. 541ae500c1fSEd Maste.It Fn elf_getphdrnum 542ae500c1fSEd MasteRetrieve the number of program headers in an ELF object. 543ae500c1fSEd Maste.It Fn elf_getshdrnum 5442de3b87aSKai WangRetrieve the number of sections in an ELF object. 545ae500c1fSEd Maste.It Fn elf_getshdrstrndx 5462de3b87aSKai WangRetrieve the section index of the section name string table in 5472de3b87aSKai Wangan ELF object. 5482de3b87aSKai Wang.It Fn elf_hash 5492de3b87aSKai WangCompute the ELF hash value of a string. 5502de3b87aSKai Wang.It Fn elf_kind 5512de3b87aSKai WangQuery the kind of object associated with an ELF descriptor. 5522de3b87aSKai Wang.It Fn elf32_fsize , Fn elf64_fsize 5532de3b87aSKai WangReturn the size of the file representation of an ELF type. 5542de3b87aSKai Wang.El 5552de3b87aSKai Wang.El 5562de3b87aSKai Wang.Ss Controlling ELF Object Layout 5572de3b87aSKai WangIn the usual mode of operation, library will compute section 5582de3b87aSKai Wangoffsets and alignments based on the contents of an ELF descriptor's 5592de3b87aSKai Wangsections without need for further intervention by the 5602de3b87aSKai Wangapplication. 5612de3b87aSKai Wang.Pp 5622de3b87aSKai WangHowever, if the application wishes to take complete charge of the 5632de3b87aSKai Wanglayout of the ELF file, it may set the 5642de3b87aSKai Wang.Dv ELF_F_LAYOUT 5652de3b87aSKai Wangflag on an ELF descriptor using 5662de3b87aSKai Wang.Xr elf_flagelf 3 , 5672de3b87aSKai Wangfollowing which the library will use the data offsets and alignments 5682de3b87aSKai Wangspecified by the application when laying out the file. 5692de3b87aSKai WangApplication control of file layout is described further in the 5702de3b87aSKai Wang.Xr elf_update 3 5712de3b87aSKai Wangmanual page. 5722de3b87aSKai Wang.Pp 5732de3b87aSKai WangGaps in between sections will be filled with the fill character 5742de3b87aSKai Wangset by function 5752de3b87aSKai Wang.Fn elf_fill . 5762de3b87aSKai Wang.Ss Error Handling 5772de3b87aSKai WangIn case an error is encountered, these library functions set an 5782de3b87aSKai Wanginternal error number and signal the presence of the error by 5792de3b87aSKai Wangreturning an special return value. 5802de3b87aSKai WangThe application can check the 5812de3b87aSKai Wangcurrent error number by calling 5822de3b87aSKai Wang.Xr elf_errno 3 . 5832de3b87aSKai WangA human readable description of the recorded error is available by 5842de3b87aSKai Wangcalling 5852de3b87aSKai Wang.Xr elf_errmsg 3 . 5862de3b87aSKai Wang.Ss Memory Management Rules 5872de3b87aSKai WangThe library keeps track of all 5882de3b87aSKai Wang.Vt Elf_Scn 5892de3b87aSKai Wangand 5902de3b87aSKai Wang.Vt Elf_Data 5912de3b87aSKai Wangdescriptors associated with an ELF descriptor and recovers them 5922de3b87aSKai Wangwhen the descriptor is closed using 5932de3b87aSKai Wang.Xr elf_end 3 . 5942de3b87aSKai WangThus the application must not call 5952de3b87aSKai Wang.Xr free 3 5962de3b87aSKai Wangon data structures allocated by the ELF library. 5972de3b87aSKai Wang.Pp 5982de3b87aSKai WangConversely the library will not 5992de3b87aSKai Wangfree data that it has not allocated. 6002de3b87aSKai WangAs an example, an application may call 6012de3b87aSKai Wang.Xr elf_newdata 3 6022de3b87aSKai Wangto allocate a new 6032de3b87aSKai Wang.Vt Elf_Data 6042de3b87aSKai Wangdescriptor and can set the 6052de3b87aSKai Wang.Va d_off 6062de3b87aSKai Wangmember of the descriptor to point to a region of memory allocated 6072de3b87aSKai Wangusing 6082de3b87aSKai Wang.Xr malloc 3 . 6092de3b87aSKai WangIt is the applications responsibility to free this arena, though the 6102de3b87aSKai Wanglibrary will reclaim the space used by the 6112de3b87aSKai Wang.Vt Elf_Data 6122de3b87aSKai Wangdescriptor itself. 6132de3b87aSKai Wang.Sh SEE ALSO 6142de3b87aSKai Wang.Xr gelf 3 , 615ae500c1fSEd Maste.Xr ar 5 , 6162de3b87aSKai Wang.Xr elf 5 6172de3b87aSKai Wang.Sh HISTORY 618*d003e0d7SEd MasteThe original 619*d003e0d7SEd Maste.Nm 620*d003e0d7SEd MasteAPI was developed for 621*d003e0d7SEd Maste.At V . 622*d003e0d7SEd MasteThe current implementation of the API appeared in 6232de3b87aSKai Wang.Fx 7.0 . 6242de3b87aSKai Wang.Sh AUTHORS 6252de3b87aSKai WangThe ELF library was written by 626b00fe64fSEd Maste.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org . 627