xref: /netbsd-src/external/bsd/elftoolchain/dist/libelf/elf.3 (revision 5ac3bc719ce6e70593039505b491894133237d12)
1*5ac3bc71Schristos.\"	$NetBSD: elf.3,v 1.6 2024/03/03 17:37:33 christos Exp $
2e81373b4Schristos.\"
3c5261b83Sjkoshy.\" Copyright (c) 2006-2008,2011,2019 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: elf.3 3927 2021-03-07 17:22:22Z jkoshy
279dd9d0cfSchristos.\"
28c5261b83Sjkoshy.Dd March 7, 2021
299dd9d0cfSchristos.Dt ELF 3
30c5261b83Sjkoshy.Os
319dd9d0cfSchristos.Sh NAME
329dd9d0cfSchristos.Nm elf
339dd9d0cfSchristos.Nd API for manipulating ELF objects
349dd9d0cfSchristos.Sh LIBRARY
359dd9d0cfSchristos.Lb libelf
369dd9d0cfSchristos.Sh SYNOPSIS
379dd9d0cfSchristos.In libelf.h
389dd9d0cfSchristos.Sh DESCRIPTION
399dd9d0cfSchristosThe
409dd9d0cfSchristos.Lb libelf
419dd9d0cfSchristosprovides functions that allow an application to read and manipulate
429dd9d0cfSchristosELF object files, and to read
439dd9d0cfSchristos.Xr ar 1
449dd9d0cfSchristosarchives.
459dd9d0cfSchristosThe library allows the manipulation of ELF objects in a byte ordering
469dd9d0cfSchristosand word-size independent way, allowing an application to read and
479dd9d0cfSchristoscreate ELF objects for 32 and 64 bit architectures and for little-
489dd9d0cfSchristosand big-endian machines.
499dd9d0cfSchristosThe library is capable of processing ELF objects that use extended
509dd9d0cfSchristossection numbering.
519dd9d0cfSchristos.Pp
529dd9d0cfSchristosThis manual page serves to provide an overview of the functionality in
539dd9d0cfSchristosthe ELF library.
549dd9d0cfSchristosFurther information may found in the manual pages for individual
55c5261b83Sjkoshy.Xr ELF 3
569dd9d0cfSchristosfunctions that comprise the library.
579dd9d0cfSchristos.Ss ELF Concepts
589dd9d0cfSchristosAs described in
599dd9d0cfSchristos.Xr elf 5 ,
609dd9d0cfSchristosELF files contain several data structures that are laid out in a
619dd9d0cfSchristosspecific way.
629dd9d0cfSchristosELF files begin with an
639dd9d0cfSchristos.Dq Executable Header ,
649dd9d0cfSchristosand may contain an optional
659dd9d0cfSchristos.Dq Program Header Table ,
669dd9d0cfSchristosand optional data in the form of ELF
679dd9d0cfSchristos.Dq sections .
689dd9d0cfSchristosA
699dd9d0cfSchristos.Dq Section Header Table
709dd9d0cfSchristosdescribes the content of the data in these sections.
719dd9d0cfSchristos.Pp
729dd9d0cfSchristosELF objects have an associated
739dd9d0cfSchristos.Dq "ELF class"
749dd9d0cfSchristoswhich denotes the natural machine word size for the architecture
759dd9d0cfSchristosthe object is associated with.
769dd9d0cfSchristosObjects for 32 bit architectures have an ELF class of
779dd9d0cfSchristos.Dv ELFCLASS32 .
789dd9d0cfSchristosObjects for 64 bit architectures have an ELF class of
799dd9d0cfSchristos.Dv ELFCLASS64 .
809dd9d0cfSchristos.Pp
819dd9d0cfSchristosELF objects also have an associated
829dd9d0cfSchristos.Dq endianness
839dd9d0cfSchristoswhich denotes the endianness of the machine architecture associated
849dd9d0cfSchristoswith the object.
859dd9d0cfSchristosThis may be
869dd9d0cfSchristos.Dv ELFDATA2LSB
879dd9d0cfSchristosfor little-endian architectures and
889dd9d0cfSchristos.Dv ELFDATA2MSB
899dd9d0cfSchristosfor big-endian architectures.
909dd9d0cfSchristos.Pp
919dd9d0cfSchristosELF objects are also associated with an API version number.
929dd9d0cfSchristosThis version number determines the layout of the individual components
939dd9d0cfSchristosof an ELF file and the semantics associated with these.
949dd9d0cfSchristos.Ss Data Representation And Translation
959dd9d0cfSchristosThe
96c5261b83Sjkoshy.Xr ELF 3
979dd9d0cfSchristoslibrary distinguishes between
989dd9d0cfSchristos.Dq native
999dd9d0cfSchristosrepresentations of ELF data structures and their
1009dd9d0cfSchristos.Dq file
1019dd9d0cfSchristosrepresentations.
1029dd9d0cfSchristos.Pp
1039dd9d0cfSchristosAn application would work with ELF data in its
1049dd9d0cfSchristos.Dq native
1059dd9d0cfSchristosrepresentation, i.e., using the native byteorder and alignment mandated
1069dd9d0cfSchristosby the processor the application is running on.
1079dd9d0cfSchristosThe
1089dd9d0cfSchristos.Dq file
1099dd9d0cfSchristosrepresentation of the same data could use a different byte ordering
1109dd9d0cfSchristosand follow different constraints on object alignment than these native
1119dd9d0cfSchristosconstraints.
1129dd9d0cfSchristos.Pp
1139dd9d0cfSchristosAccordingly, the
114c5261b83Sjkoshy.Xr ELF 3
1159dd9d0cfSchristoslibrary offers translation facilities
1169dd9d0cfSchristos.Xr ( elf32_xlatetof 3 ,
1179dd9d0cfSchristos.Xr elf32_xlatetom 3 ,
1189dd9d0cfSchristos.Xr elf64_xlatetof 3
1199dd9d0cfSchristosand
1209dd9d0cfSchristos.Xr elf64_xlatetom 3 )
121c5261b83Sjkoshyto and from these representations.
122c5261b83SjkoshyIt also provides higher-level APIs
123c5261b83Sjkoshy.Xr ( gelf_xlatetof 3 ,
124c5261b83Sjkoshy.Xr gelf_xlatetom 3 )
125c5261b83Sjkoshythat retrieve and store data from the ELF object in a class-agnostic
126c5261b83Sjkoshymanner.
1279dd9d0cfSchristos.Ss Library Working Version
1289dd9d0cfSchristosConceptually, there are three version numbers associated with an
1299dd9d0cfSchristosapplication using the ELF library to manipulate ELF objects:
1309dd9d0cfSchristos.Bl -bullet -compact -offset indent
1319dd9d0cfSchristos.It
1329dd9d0cfSchristosThe ELF version that the application was compiled against.
1339dd9d0cfSchristosThis version determines the ABI expected by the application.
1349dd9d0cfSchristos.It
1359dd9d0cfSchristosThe ELF version of the ELF object being manipulated by the
1369dd9d0cfSchristosapplication through the ELF library.
1379dd9d0cfSchristos.It
1389dd9d0cfSchristosThe ELF version (or set of versions) supported by the ELF library itself.
1399dd9d0cfSchristos.El
1409dd9d0cfSchristos.Pp
1419dd9d0cfSchristosIn order to facilitate working with ELF objects of differing versions,
1429dd9d0cfSchristosthe ELF library requires the application to call the
1439dd9d0cfSchristos.Fn elf_version
1449dd9d0cfSchristosfunction before invoking many of its operations, in order to inform
1459dd9d0cfSchristosthe library of the application's desired working version.
1469dd9d0cfSchristos.Pp
1479dd9d0cfSchristosIn the current implementation, all three versions have to be
1489dd9d0cfSchristos.Dv EV_CURRENT .
1499dd9d0cfSchristos.Ss Namespace use
1509dd9d0cfSchristosThe ELF library uses the following prefixes:
1519dd9d0cfSchristos.Bl -tag -width "ELF_F_*"
1529dd9d0cfSchristos.It Dv elf_
1539dd9d0cfSchristosUsed for class-independent functions.
1549dd9d0cfSchristos.It Dv elf32_
1559dd9d0cfSchristosUsed for functions working with 32 bit ELF objects.
1569dd9d0cfSchristos.It Dv elf64_
1579dd9d0cfSchristosUsed for functions working with 64 bit ELF objects.
1589dd9d0cfSchristos.It Dv Elf_
1599dd9d0cfSchristosUsed for class-independent data types.
1609dd9d0cfSchristos.It Dv ELF_C_
1619dd9d0cfSchristosUsed for command values used in a few functions.
1629dd9d0cfSchristosThese symbols are defined as members of the
163c5261b83Sjkoshy.Vt Elf_Cmd
1649dd9d0cfSchristosenumeration.
1659dd9d0cfSchristos.It Dv ELF_E_
1669dd9d0cfSchristosUsed for error numbers.
1679dd9d0cfSchristos.It Dv ELF_F_
1689dd9d0cfSchristosUsed for flags.
1699dd9d0cfSchristos.It Dv ELF_K_
1709dd9d0cfSchristosThese constants define the kind of file associated with an ELF
1719dd9d0cfSchristosdescriptor.
1729dd9d0cfSchristosSee
1739dd9d0cfSchristos.Xr elf_kind 3 .
1749dd9d0cfSchristosThe symbols are defined by the
1759dd9d0cfSchristos.Vt Elf_Kind
1769dd9d0cfSchristosenumeration.
1779dd9d0cfSchristos.It Dv ELF_T_
1789dd9d0cfSchristosThese values are defined by the
1799dd9d0cfSchristos.Vt Elf_Type
1809dd9d0cfSchristosenumeration, and denote the types of ELF data structures
1819dd9d0cfSchristosthat can be present in an ELF object.
1829dd9d0cfSchristos.El
1839dd9d0cfSchristos.Pp
1849dd9d0cfSchristosIn addition, the library uses symbols with prefixes
1859dd9d0cfSchristos.Dv _ELF
1869dd9d0cfSchristosand
1879dd9d0cfSchristos.Dv _libelf
1889dd9d0cfSchristosfor its internal use.
1899dd9d0cfSchristos.Ss Descriptors
1909dd9d0cfSchristosApplications communicate with the library using descriptors.
1919dd9d0cfSchristosThese are:
1929dd9d0cfSchristos.Bl -tag -width ".Vt Elf_Data"
1939dd9d0cfSchristos.It Vt Elf
1949dd9d0cfSchristosAn
1959dd9d0cfSchristos.Vt Elf
1969dd9d0cfSchristosdescriptor represents an ELF object or an
1979dd9d0cfSchristos.Xr ar 1
1989dd9d0cfSchristosarchive.
1999dd9d0cfSchristosIt is allocated using one of the
2009dd9d0cfSchristos.Fn elf_begin
2019dd9d0cfSchristosor
2029dd9d0cfSchristos.Fn elf_memory
2039dd9d0cfSchristosfunctions.
2049dd9d0cfSchristosAn
2059dd9d0cfSchristos.Vt Elf
2069dd9d0cfSchristosdescriptor can be used to read and write data to an ELF file.
2079dd9d0cfSchristosAn
2089dd9d0cfSchristos.Vt Elf
2099dd9d0cfSchristosdescriptor can be associated with zero or more
2109dd9d0cfSchristos.Vt Elf_Scn
2119dd9d0cfSchristossection descriptors.
2129dd9d0cfSchristos.Pp
2139dd9d0cfSchristosGiven an ELF descriptor, the application may retrieve the ELF
2149dd9d0cfSchristosobject's class-dependent
2159dd9d0cfSchristos.Dq "Executable Header"
2169dd9d0cfSchristosstructures using the
2179dd9d0cfSchristos.Fn elf32_getehdr
2189dd9d0cfSchristosor
2199dd9d0cfSchristos.Fn elf64_getehdr
2209dd9d0cfSchristosfunctions.
2219dd9d0cfSchristosA new Ehdr structure may be allocated using the
2229dd9d0cfSchristos.Fn elf64_newehdr
2239dd9d0cfSchristosor
2249dd9d0cfSchristos.Fn elf64_newehdr
2259dd9d0cfSchristosfunctions.
2269dd9d0cfSchristos.Pp
2279dd9d0cfSchristosThe
2289dd9d0cfSchristos.Dq "Program Header Table"
2299dd9d0cfSchristosassociated with an ELF descriptor may be allocated using the
2309dd9d0cfSchristos.Fn elf32_getphdr
2319dd9d0cfSchristosor
2329dd9d0cfSchristos.Fn elf64_getphdr
2339dd9d0cfSchristosfunctions.
2349dd9d0cfSchristosA new program header table may be allocated or an existing table
2359dd9d0cfSchristosresized using the
2369dd9d0cfSchristos.Fn elf32_newphdr
2379dd9d0cfSchristosor
2389dd9d0cfSchristos.Fn elf64_newphdr
2399dd9d0cfSchristosfunctions.
2409dd9d0cfSchristos.Pp
2419dd9d0cfSchristosThe
2429dd9d0cfSchristos.Vt Elf
2439dd9d0cfSchristosstructure is opaque and has no members visible to the
2449dd9d0cfSchristosapplication.
2459dd9d0cfSchristos.It Vt Elf_Data
2469dd9d0cfSchristosAn
2479dd9d0cfSchristos.Vt Elf_Data
2489dd9d0cfSchristosdata structure describes an individual chunk of a ELF file as
2499dd9d0cfSchristosrepresented in memory.
2509dd9d0cfSchristosIt has the following application-visible members:
2519dd9d0cfSchristos.Bl -tag -width ".Vt unsigned int d_version" -compact
2529dd9d0cfSchristos.It Vt "uint64_t d_align"
2539dd9d0cfSchristosThe in-file alignment of the data buffer within its containing ELF section.
2549dd9d0cfSchristosThis value must be non-zero and a power of two.
2559dd9d0cfSchristos.It Vt "void *d_buf"
2569dd9d0cfSchristosA pointer to data in memory.
2579dd9d0cfSchristos.It Vt "uint64_t d_off"
2589dd9d0cfSchristosThe offset within the containing section where this descriptor's data
2599dd9d0cfSchristoswould be placed.
2609dd9d0cfSchristosThis field will be computed by the library unless the application
2619dd9d0cfSchristosrequests full control of the ELF object's layout.
2629dd9d0cfSchristos.It Vt "uint64_t d_size"
2639dd9d0cfSchristosThe number of bytes of data in this descriptor.
2649dd9d0cfSchristos.It Vt "Elf_Type d_type"
2659dd9d0cfSchristosThe ELF type (see below) of the data in this descriptor.
2669dd9d0cfSchristos.It Vt "unsigned int d_version"
2679dd9d0cfSchristosThe operating version for the data in this buffer.
2689dd9d0cfSchristos.El
2699dd9d0cfSchristos.Pp
2709dd9d0cfSchristos.Vt Elf_Data
271c5261b83Sjkoshydescriptors are usually used in conjunction with
2729dd9d0cfSchristos.Vt Elf_Scn
2739dd9d0cfSchristosdescriptors.
2749dd9d0cfSchristos.It Vt Elf_Scn
2759dd9d0cfSchristos.Vt Elf_Scn
276c5261b83Sjkoshydescriptors represent sections in an ELF object.
277c5261b83SjkoshyThese descriptors are opaque and contain no application modifiable
278c5261b83Sjkoshyfields.
2799dd9d0cfSchristos.Pp
280c5261b83SjkoshyThe
281c5261b83Sjkoshy.Vt Elf_Scn
282c5261b83Sjkoshydescriptor for a specific section in an ELF object can be
283c5261b83Sjkoshyretrieved using the
2849dd9d0cfSchristos.Fn elf_getscn
2859dd9d0cfSchristosfunction.
286c5261b83SjkoshyThe sections contained in an ELF object can be traversed using the
2879dd9d0cfSchristos.Fn elf_nextscn
2889dd9d0cfSchristosfunction.
289c5261b83SjkoshyNew sections are allocated using the
2909dd9d0cfSchristos.Fn elf_newscn
2919dd9d0cfSchristosfunction.
2929dd9d0cfSchristos.Pp
2939dd9d0cfSchristosThe
294c5261b83Sjkoshy.Vt Elf_Data
295c5261b83Sjkoshydescriptors associated with a given section can be retrieved
296c5261b83Sjkoshyusing the
297c5261b83Sjkoshy.Fn elf_getdata
298c5261b83Sjkoshyfunction.
299c5261b83SjkoshyNew data descriptors can be added to a section
300c5261b83Sjkoshydescriptor using the
301c5261b83Sjkoshy.Fn elf_newdata
302c5261b83Sjkoshyfunction.
303c5261b83SjkoshyThe untranslated
304c5261b83Sjkoshy.Dq file
305c5261b83Sjkoshyrepresentation of data in a section can be retrieved using the
306c5261b83Sjkoshy.Fn elf_rawdata
307c5261b83Sjkoshyfunction.
3089dd9d0cfSchristos.El
3099dd9d0cfSchristos.Ss Supported Elf Types
3109dd9d0cfSchristosThe following ELF datatypes are supported by the library.
3119dd9d0cfSchristos.Pp
3129dd9d0cfSchristos.Bl -tag -width ".Dv ELF_T_SYMINFO" -compact
3139dd9d0cfSchristos.It Dv ELF_T_ADDR
3149dd9d0cfSchristosMachine addresses.
3159dd9d0cfSchristos.It Dv ELF_T_BYTE
3169dd9d0cfSchristosByte data.
3179dd9d0cfSchristosThe library will not attempt to translate byte data.
3189dd9d0cfSchristos.It Dv ELF_T_CAP
3199dd9d0cfSchristosSoftware and hardware capability records.
3209dd9d0cfSchristos.It Dv ELF_T_DYN
3219dd9d0cfSchristosRecords used in a section of type
3229dd9d0cfSchristos.Dv SHT_DYNAMIC .
3239dd9d0cfSchristos.It Dv ELF_T_EHDR
3249dd9d0cfSchristosELF executable header.
3259dd9d0cfSchristos.It Dv ELF_T_GNUHASH
3269dd9d0cfSchristosGNU-style hash tables.
3279dd9d0cfSchristos.It Dv ELF_T_HALF
3289dd9d0cfSchristos16-bit unsigned words.
3299dd9d0cfSchristos.It Dv ELF_T_LWORD
3309dd9d0cfSchristos64 bit unsigned words.
3319dd9d0cfSchristos.It Dv ELF_T_MOVE
3329dd9d0cfSchristosELF Move records.
3339dd9d0cfSchristos.\".It Dv ELF_T_MOVEP
3349dd9d0cfSchristos.\" As yet unsupported.
3359dd9d0cfSchristos.It Dv ELF_T_NOTE
3369dd9d0cfSchristosELF Note structures.
3379dd9d0cfSchristos.It Dv ELF_T_OFF
3389dd9d0cfSchristosFile offsets.
3399dd9d0cfSchristos.It Dv ELF_T_PHDR
3409dd9d0cfSchristosELF program header table entries.
3419dd9d0cfSchristos.It Dv ELF_T_REL
3429dd9d0cfSchristosELF relocation entries.
3439dd9d0cfSchristos.It Dv ELF_T_RELA
3449dd9d0cfSchristosELF relocation entries with addends.
3459dd9d0cfSchristos.It Dv ELF_T_SHDR
3469dd9d0cfSchristosELF section header entries.
3479dd9d0cfSchristos.It Dv ELF_T_SWORD
3489dd9d0cfSchristosSigned 32-bit words.
3499dd9d0cfSchristos.It Dv ELF_T_SXWORD
3509dd9d0cfSchristosSigned 64-bit words.
3519dd9d0cfSchristos.It Dv ELF_T_SYMINFO
3529dd9d0cfSchristosELF symbol information.
3539dd9d0cfSchristos.It Dv ELF_T_SYM
3549dd9d0cfSchristosELF symbol table entries.
3559dd9d0cfSchristos.It Dv ELF_T_VDEF
3569dd9d0cfSchristosSymbol version definition records.
3579dd9d0cfSchristos.It Dv ELF_T_VNEED
3589dd9d0cfSchristosSymbol version requirement records.
3599dd9d0cfSchristos.It Dv ELF_T_WORD
3609dd9d0cfSchristosUnsigned 32-bit words.
3619dd9d0cfSchristos.It Dv ELF_T_XWORD
3629dd9d0cfSchristosUnsigned 64-bit words.
3639dd9d0cfSchristos.El
3649dd9d0cfSchristos.Pp
3659dd9d0cfSchristosThe symbol
3669dd9d0cfSchristos.Dv ELF_T_NUM
3679dd9d0cfSchristosdenotes the number of Elf types known to the library.
3689dd9d0cfSchristos.Pp
3699dd9d0cfSchristosThe following table shows the mapping between ELF section types
3709dd9d0cfSchristosdefined in
3719dd9d0cfSchristos.Xr elf 5
3729dd9d0cfSchristosand the types supported by the library.
3739dd9d0cfSchristos.Bl -column ".Dv SHT_PREINIT_ARRAY" ".Dv ELF_T_SYMINFO"
3749dd9d0cfSchristos.It Em Section Type Ta Em "Library Type" Ta Em Description
3759dd9d0cfSchristos.It Dv SHT_DYNAMIC Ta Dv ELF_T_DYN Ta Xo
3769dd9d0cfSchristos.Sq .dynamic
3779dd9d0cfSchristossection entries.
3789dd9d0cfSchristos.Xc
3799dd9d0cfSchristos.It Dv SHT_DYNSYM Ta Dv ELF_T_SYM Ta Symbols for dynamic linking.
3809dd9d0cfSchristos.It Dv SHT_FINI_ARRAY Ta Dv ELF_T_ADDR Ta Termination function pointers.
38142bd3019Schristos.It Dv SHT_GNU_HASH Ta Dv ELF_T_GNUHASH Ta GNU hash sections.
38242bd3019Schristos.It Dv SHT_GNU_LIBLIST Ta Dv ELF_T_WORD Ta List of libraries to be pre-linked.
38342bd3019Schristos.It Dv SHT_GNU_verdef Ta Dv ELF_T_VDEF Ta Symbol version definitions.
38442bd3019Schristos.It Dv SHT_GNU_verneed Ta Dv ELF_T_VNEED Ta Symbol versioning requirements.
38542bd3019Schristos.It Dv SHT_GNU_versym Ta Dv ELF_T_HALF Ta Version symbols.
3869dd9d0cfSchristos.It Dv SHT_GROUP Ta Dv ELF_T_WORD Ta Section group marker.
3879dd9d0cfSchristos.It Dv SHT_HASH Ta Dv ELF_T_HASH Ta Symbol hashes.
3889dd9d0cfSchristos.It Dv SHT_INIT_ARRAY Ta Dv ELF_T_ADDR Ta Initialization function pointers.
3899dd9d0cfSchristos.It Dv SHT_NOBITS Ta Dv ELF_T_BYTE Ta Xo
3909dd9d0cfSchristosEmpty sections.
3919dd9d0cfSchristosSee
3929dd9d0cfSchristos.Xr elf 5 .
3939dd9d0cfSchristos.Xc
3949dd9d0cfSchristos.It Dv SHT_NOTE Ta Dv ELF_T_NOTE Ta ELF note records.
3959dd9d0cfSchristos.It Dv SHT_PREINIT_ARRAY Ta Dv ELF_T_ADDR Ta Pre-initialization function pointers.
3969dd9d0cfSchristos.It Dv SHT_PROGBITS Ta Dv ELF_T_BYTE Ta Machine code.
3979dd9d0cfSchristos.It Dv SHT_REL Ta Dv ELF_T_REL Ta ELF relocation records.
3989dd9d0cfSchristos.It Dv SHT_RELA Ta Dv ELF_T_RELA Ta Relocation records with addends.
3999dd9d0cfSchristos.It Dv SHT_STRTAB Ta Dv ELF_T_BYTE Ta String tables.
4009dd9d0cfSchristos.It Dv SHT_SYMTAB Ta Dv ELF_T_SYM Ta Symbol tables.
4019dd9d0cfSchristos.It Dv SHT_SYMTAB_SHNDX Ta Dv ELF_T_WORD Ta Used with extended section numbering.
40242bd3019Schristos.It Dv SHT_SUNW_dof Ta Dv ELF_T_BYTE Ta Xo
40342bd3019SchristosUsed by
40442bd3019Schristos.Xr dtrace 1 .
40542bd3019Schristos.Xc
4069dd9d0cfSchristos.It Dv SHT_SUNW_move Ta Dv ELF_T_MOVE Ta ELF move records.
4079dd9d0cfSchristos.It Dv SHT_SUNW_syminfo Ta Dv ELF_T_SYMINFO Ta Additional symbol flags.
40842bd3019Schristos.It Dv SHT_SUNW_verdef Ta Dv ELF_T_VDEF Ta Xo
40942bd3019SchristosSame as
41042bd3019Schristos.Dv SHT_GNU_verdef .
41142bd3019Schristos.Xc
41242bd3019Schristos.It Dv SHT_SUNW_verneed Ta Dv ELF_T_VNEED Ta Xo
41342bd3019SchristosSame as
41442bd3019Schristos.Dv SHT_GNU_verneed .
41542bd3019Schristos.Xc
41642bd3019Schristos.It Dv SHT_SUNW_versym Ta Dv ELF_T_HALF Ta Xo
41742bd3019SchristosSame as
41842bd3019Schristos.Dv SHT_GNU_versym .
41942bd3019Schristos.Xc
4209dd9d0cfSchristos.El
42142bd3019Schristos.Pp
42242bd3019SchristosSection types in the range
423c5261b83Sjkoshy.Dv [ SHT_LOOS ,
42442bd3019Schristos.Dv SHT_HIUSER ]
42542bd3019Schristosare otherwise considered to be of type
42642bd3019Schristos.Dv ELF_T_BYTE .
4279dd9d0cfSchristos.Ss Functional Grouping
4289dd9d0cfSchristosThis section contains a brief overview of the available functionality
4299dd9d0cfSchristosin the ELF library.
4309dd9d0cfSchristosEach function listed here is described further in its own manual page.
4319dd9d0cfSchristos.Bl -tag -width indent
4329dd9d0cfSchristos.It "Archive Access"
433c5261b83Sjkoshy.Bl -tag -compact -width indent
4349dd9d0cfSchristos.It Fn elf_getarsym
4359dd9d0cfSchristosRetrieve the archive symbol table.
4369dd9d0cfSchristos.It Fn elf_getarhdr
4379dd9d0cfSchristosRetrieve the archive header for an object.
4389dd9d0cfSchristos.It Fn elf_getbase
4399dd9d0cfSchristosRetrieve the offset of a member inside an archive.
4409dd9d0cfSchristos.It Fn elf_next
4419dd9d0cfSchristosIterate through an
4429dd9d0cfSchristos.Xr ar 1
4439dd9d0cfSchristosarchive.
4449dd9d0cfSchristos.It Fn elf_rand
4459dd9d0cfSchristosRandom access inside an
4469dd9d0cfSchristos.Xr ar 1
4479dd9d0cfSchristosarchive.
4489dd9d0cfSchristos.El
4499dd9d0cfSchristos.It "Data Structures"
450c5261b83Sjkoshy.Bl -tag -compact -width indent
4519dd9d0cfSchristos.It Fn elf_getdata
4529dd9d0cfSchristosRetrieve translated data for an ELF section.
4539dd9d0cfSchristos.It Fn elf_getscn
4549dd9d0cfSchristosRetrieve the section descriptor for a named section.
4559dd9d0cfSchristos.It Fn elf_ndxscn
4569dd9d0cfSchristosRetrieve the index for a section.
4579dd9d0cfSchristos.It Fn elf_newdata
4589dd9d0cfSchristosAdd a new
4599dd9d0cfSchristos.Vt Elf_Data
4609dd9d0cfSchristosdescriptor to an ELF section.
4619dd9d0cfSchristos.It Fn elf_newscn
4629dd9d0cfSchristosAdd a new section descriptor to an ELF descriptor.
4639dd9d0cfSchristos.It Fn elf_nextscn
4649dd9d0cfSchristosIterate through the sections in an ELF object.
4659dd9d0cfSchristos.It Fn elf_rawdata
4669dd9d0cfSchristosRetrieve untranslated data for an ELF section.
4679dd9d0cfSchristos.It Fn elf_rawfile
4689dd9d0cfSchristosReturn a pointer to the untranslated file contents for an ELF object.
4699dd9d0cfSchristos.It Fn elf32_getehdr , Fn elf64_getehdr
4709dd9d0cfSchristosRetrieve the Executable Header in an ELF object.
4719dd9d0cfSchristos.It Fn elf32_getphdr , Fn elf64_getphdr
4729dd9d0cfSchristosRetrieve the Program Header Table in an ELF object.
4739dd9d0cfSchristos.It Fn elf32_getshdr , Fn elf64_getshdr
4749dd9d0cfSchristosRetrieve the ELF section header associated with an
4759dd9d0cfSchristos.Vt Elf_Scn
4769dd9d0cfSchristosdescriptor.
4779dd9d0cfSchristos.It Fn elf32_newehdr , Fn elf64_newehdr
4789dd9d0cfSchristosAllocate an Executable Header in an ELF object.
4799dd9d0cfSchristos.It Fn elf32_newphdr , Fn elf64_newphdr
4809dd9d0cfSchristosAllocate or resize the Program Header Table in an ELF object.
4819dd9d0cfSchristos.El
4829dd9d0cfSchristos.It "Data Translation"
483c5261b83Sjkoshy.Bl -tag -compact -width indent
4849dd9d0cfSchristos.It Fn elf32_xlatetof , Fn elf64_xlatetof
4859dd9d0cfSchristosTranslate an ELF data structure from its native representation to its
4869dd9d0cfSchristosfile representation.
4879dd9d0cfSchristos.It Fn elf32_xlatetom , Fn elf64_xlatetom
4889dd9d0cfSchristosTranslate an ELF data structure from its file representation to a
4899dd9d0cfSchristosnative representation.
4909dd9d0cfSchristos.El
4919dd9d0cfSchristos.It "Error Reporting"
492c5261b83Sjkoshy.Bl -tag -compact -width indent
4939dd9d0cfSchristos.It Fn elf_errno
4949dd9d0cfSchristosRetrieve the current error.
4959dd9d0cfSchristos.It Fn elf_errmsg
4969dd9d0cfSchristosRetrieve a human readable description of the current error.
4979dd9d0cfSchristos.El
4989dd9d0cfSchristos.It "Initialization"
499c5261b83Sjkoshy.Bl -tag -compact -width indent
5009dd9d0cfSchristos.It Fn elf_begin
5019dd9d0cfSchristosOpens an
5029dd9d0cfSchristos.Xr ar 1
5039dd9d0cfSchristosarchive or ELF object given a file descriptor.
5049dd9d0cfSchristos.It Fn elf_end
5059dd9d0cfSchristosClose an ELF descriptor and release all its resources.
5069dd9d0cfSchristos.It Fn elf_memory
5079dd9d0cfSchristosOpens an
5089dd9d0cfSchristos.Xr ar 1
5099dd9d0cfSchristosarchive or ELF object present in a memory arena.
5109dd9d0cfSchristos.It Fn elf_version
5119dd9d0cfSchristosSets the operating version.
5129dd9d0cfSchristos.El
5139dd9d0cfSchristos.It "IO Control"
5149dd9d0cfSchristos.Bl -tag -width ".Fn elf_setshstrndx" -compact
5159dd9d0cfSchristos.It Fn elf_cntl
5169dd9d0cfSchristosManage the association between and ELF descriptor and its underlying file.
5179dd9d0cfSchristos.It Fn elf_flagdata
5189dd9d0cfSchristosMark an
5199dd9d0cfSchristos.Vt Elf_Data
5209dd9d0cfSchristosdescriptor as dirty.
5219dd9d0cfSchristos.It Fn elf_flagehdr
5229dd9d0cfSchristosMark the ELF Executable Header in an ELF descriptor as dirty.
5239dd9d0cfSchristos.It Fn elf_flagphdr
5249dd9d0cfSchristosMark the ELF Program Header Table in an ELF descriptor as dirty.
5259dd9d0cfSchristos.It Fn elf_flagscn
5269dd9d0cfSchristosMark an
5279dd9d0cfSchristos.Vt Elf_Scn
5289dd9d0cfSchristosdescriptor as dirty.
5299dd9d0cfSchristos.It Fn elf_flagshdr
5309dd9d0cfSchristosMark an ELF Section Header as dirty.
5319dd9d0cfSchristos.It Fn elf_setshstrndx
5329dd9d0cfSchristosSet the index of the section name string table for the ELF object.
5339dd9d0cfSchristos.It Fn elf_update
5349dd9d0cfSchristosRecompute ELF object layout and optionally write the modified object
5359dd9d0cfSchristosback to the underlying file.
5369dd9d0cfSchristos.El
5379dd9d0cfSchristos.It "Queries"
5389dd9d0cfSchristos.Bl -tag -width ".Fn elf_getshstrndx" -compact
5399dd9d0cfSchristos.It Fn elf32_checksum , Fn elf64_checkum
5409dd9d0cfSchristosCompute checksum of an ELF object.
5419dd9d0cfSchristos.It Fn elf_getident
5429dd9d0cfSchristosRetrieve the identification bytes for an ELF object.
543c5261b83Sjkoshy.It Fn elf_getphdrnum
544c5261b83SjkoshyRetrieve the number of program headers in an ELF object.
545c5261b83Sjkoshy.It Fn elf_getshdrnum
5469dd9d0cfSchristosRetrieve the number of sections in an ELF object.
547c5261b83Sjkoshy.It Fn elf_getshdrstrndx
5489dd9d0cfSchristosRetrieve the section index of the section name string table in
5499dd9d0cfSchristosan ELF object.
5509dd9d0cfSchristos.It Fn elf_hash
5519dd9d0cfSchristosCompute the ELF hash value of a string.
5529dd9d0cfSchristos.It Fn elf_kind
5539dd9d0cfSchristosQuery the kind of object associated with an ELF descriptor.
5549dd9d0cfSchristos.It Fn elf32_fsize , Fn elf64_fsize
5559dd9d0cfSchristosReturn the size of the file representation of an ELF type.
5569dd9d0cfSchristos.El
5579dd9d0cfSchristos.El
5589dd9d0cfSchristos.Ss Controlling ELF Object Layout
5599dd9d0cfSchristosIn the usual mode of operation, library will compute section
5609dd9d0cfSchristosoffsets and alignments based on the contents of an ELF descriptor's
5619dd9d0cfSchristossections without need for further intervention by the
5629dd9d0cfSchristosapplication.
5639dd9d0cfSchristos.Pp
5649dd9d0cfSchristosHowever, if the application wishes to take complete charge of the
5659dd9d0cfSchristoslayout of the ELF file, it may set the
5669dd9d0cfSchristos.Dv ELF_F_LAYOUT
5679dd9d0cfSchristosflag on an ELF descriptor using
5689dd9d0cfSchristos.Xr elf_flagelf 3 ,
5699dd9d0cfSchristosfollowing which the library will use the data offsets and alignments
5709dd9d0cfSchristosspecified by the application when laying out the file.
5719dd9d0cfSchristosApplication control of file layout is described further in the
5729dd9d0cfSchristos.Xr elf_update 3
5739dd9d0cfSchristosmanual page.
5749dd9d0cfSchristos.Pp
5759dd9d0cfSchristosGaps in between sections will be filled with the fill character
5769dd9d0cfSchristosset by function
5779dd9d0cfSchristos.Fn elf_fill .
5789dd9d0cfSchristos.Ss Error Handling
5799dd9d0cfSchristosIn case an error is encountered, these library functions set an
5809dd9d0cfSchristosinternal error number and signal the presence of the error by
581c5261b83Sjkoshyreturning a special return value.
5829dd9d0cfSchristosThe application can check the
5839dd9d0cfSchristoscurrent error number by calling
5849dd9d0cfSchristos.Xr elf_errno 3 .
5859dd9d0cfSchristosA human readable description of the recorded error is available by
5869dd9d0cfSchristoscalling
5879dd9d0cfSchristos.Xr elf_errmsg 3 .
5889dd9d0cfSchristos.Ss Memory Management Rules
5899dd9d0cfSchristosThe library keeps track of all
5909dd9d0cfSchristos.Vt Elf_Scn
5919dd9d0cfSchristosand
5929dd9d0cfSchristos.Vt Elf_Data
5939dd9d0cfSchristosdescriptors associated with an ELF descriptor and recovers them
5949dd9d0cfSchristoswhen the descriptor is closed using
5959dd9d0cfSchristos.Xr elf_end 3 .
5969dd9d0cfSchristosThus the application must not call
5979dd9d0cfSchristos.Xr free 3
5989dd9d0cfSchristoson data structures allocated by the ELF library.
5999dd9d0cfSchristos.Pp
6009dd9d0cfSchristosConversely the library will not
6019dd9d0cfSchristosfree data that it has not allocated.
6029dd9d0cfSchristosAs an example, an application may call
6039dd9d0cfSchristos.Xr elf_newdata 3
6049dd9d0cfSchristosto allocate a new
6059dd9d0cfSchristos.Vt Elf_Data
6069dd9d0cfSchristosdescriptor and can set the
6079dd9d0cfSchristos.Va d_off
6089dd9d0cfSchristosmember of the descriptor to point to a region of memory allocated
6099dd9d0cfSchristosusing
6109dd9d0cfSchristos.Xr malloc 3 .
6119dd9d0cfSchristosIt is the applications responsibility to free this arena, though the
6129dd9d0cfSchristoslibrary will reclaim the space used by the
6139dd9d0cfSchristos.Vt Elf_Data
6149dd9d0cfSchristosdescriptor itself.
6159dd9d0cfSchristos.Sh SEE ALSO
6169dd9d0cfSchristos.Xr gelf 3 ,
617c5261b83Sjkoshy.Xr ar 5 ,
6189dd9d0cfSchristos.Xr elf 5
6199dd9d0cfSchristos.Sh HISTORY
620c5261b83SjkoshyThe original
621c5261b83Sjkoshy.Nm
622c5261b83SjkoshyAPI was developed for
623c5261b83Sjkoshy.At V .
624c5261b83SjkoshyThe current implementation of the API appeared in
625e81373b4Schristos.Fx 7.0
626e81373b4Schristosand
627e81373b4Schristos.Nx 6.0 .
6289dd9d0cfSchristos.Sh AUTHORS
6299dd9d0cfSchristosThe ELF library was written by
63042bd3019Schristos.An Joseph Koshy Aq Mt jkoshy@FreeBSD.org .
631