diff options
author | Richard Lowe <richlowe@richlowe.net> | 2011-03-14 14:05:30 -0400 |
---|---|---|
committer | Richard Lowe <richlowe@richlowe.net> | 2011-03-14 14:05:30 -0400 |
commit | c10c16dec587a0662068f6e2991c29ed3a9db943 (patch) | |
tree | f414286f4bba41d75683ed4fbbaa6bfa4bf7fabd /usr/src/man/man3elf | |
parent | 68caef18a23a498d9e3017b983562c0f4fd8ab23 (diff) | |
download | illumos-gate-c10c16dec587a0662068f6e2991c29ed3a9db943.tar.gz |
243 system manual pages should live with the software
Reviewed by: garrett@nexenta.com
Reviewed by: gwr@nexenta.com
Reviewed by: trisk@opensolaris.org
Approved by: gwr@nexenta.com
--HG--
extra : rebase_source : 0c599d0bec0dc8865fbba67721a7a6cd6b1feefb
Diffstat (limited to 'usr/src/man/man3elf')
27 files changed, 4418 insertions, 0 deletions
diff --git a/usr/src/man/man3elf/Makefile b/usr/src/man/man3elf/Makefile new file mode 100644 index 0000000000..300141b231 --- /dev/null +++ b/usr/src/man/man3elf/Makefile @@ -0,0 +1,189 @@ +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet +# at http://www.illumos.org/license/CDDL. +# + +# Copyright 2011, Richard Lowe + +include ../../Makefile.master + +MANSECT = 3elf + +MANFILES = elf.3elf \ + elf32_checksum.3elf \ + elf32_fsize.3elf \ + elf32_getehdr.3elf \ + elf32_getphdr.3elf \ + elf32_getshdr.3elf \ + elf32_xlatetof.3elf \ + elf_begin.3elf \ + elf_cntl.3elf \ + elf_errmsg.3elf \ + elf_fill.3elf \ + elf_flagdata.3elf \ + elf_getarhdr.3elf \ + elf_getarsym.3elf \ + elf_getbase.3elf \ + elf_getdata.3elf \ + elf_getident.3elf \ + elf_getscn.3elf \ + elf_hash.3elf \ + elf_kind.3elf \ + elf_rawfile.3elf \ + elf_strptr.3elf \ + elf_update.3elf \ + elf_version.3elf \ + gelf.3elf \ + nlist.3elf + +MANSOFILES = elf32_newehdr.3elf \ + elf32_newphdr.3elf \ + elf32_xlatetom.3elf \ + elf64_checksum.3elf \ + elf64_fsize.3elf \ + elf64_getehdr.3elf \ + elf64_getphdr.3elf \ + elf64_getshdr.3elf \ + elf64_newehdr.3elf \ + elf64_newphdr.3elf \ + elf64_xlatetof.3elf \ + elf64_xlatetom.3elf \ + elf_end.3elf \ + elf_errno.3elf \ + elf_flagehdr.3elf \ + elf_flagelf.3elf \ + elf_flagphdr.3elf \ + elf_flagscn.3elf \ + elf_flagshdr.3elf \ + elf_getphdrnum.3elf \ + elf_getphnum.3elf \ + elf_getshdrnum.3elf \ + elf_getshdrstrndx.3elf \ + elf_getshnum.3elf \ + elf_getshstrndx.3elf \ + elf_memory.3elf \ + elf_ndxscn.3elf \ + elf_newdata.3elf \ + elf_newscn.3elf \ + elf_next.3elf \ + elf_nextscn.3elf \ + elf_rand.3elf \ + elf_rawdata.3elf \ + gelf_checksum.3elf \ + gelf_fsize.3elf \ + gelf_getcap.3elf \ + gelf_getclass.3elf \ + gelf_getdyn.3elf \ + gelf_getehdr.3elf \ + gelf_getmove.3elf \ + gelf_getphdr.3elf \ + gelf_getrel.3elf \ + gelf_getrela.3elf \ + gelf_getshdr.3elf \ + gelf_getsym.3elf \ + gelf_getsyminfo.3elf \ + gelf_getsymshndx.3elf \ + gelf_newehdr.3elf \ + gelf_newphdr.3elf \ + gelf_update_cap.3elf \ + gelf_update_dyn.3elf \ + gelf_update_ehdr.3elf \ + gelf_update_getmove.3elf \ + gelf_update_move.3elf \ + gelf_update_phdr.3elf \ + gelf_update_rel.3elf \ + gelf_update_rela.3elf \ + gelf_update_shdr.3elf \ + gelf_update_sym.3elf \ + gelf_update_syminfo.3elf \ + gelf_update_symshndx.3elf \ + gelf_xlatetof.3elf \ + gelf_xlatetom.3elf + +MANFILES += $(MANSOFILES) + +elf64_checksum.3elf := SOSRC = man3elf/elf32_checksum.3elf + +elf64_fsize.3elf := SOSRC = man3elf/elf32_fsize.3elf + +elf32_newehdr.3elf := SOSRC = man3elf/elf32_getehdr.3elf +elf64_getehdr.3elf := SOSRC = man3elf/elf32_getehdr.3elf +elf64_newehdr.3elf := SOSRC = man3elf/elf32_getehdr.3elf +elf32_newphdr.3elf := SOSRC = man3elf/elf32_getphdr.3elf +elf64_getphdr.3elf := SOSRC = man3elf/elf32_getphdr.3elf +elf64_newphdr.3elf := SOSRC = man3elf/elf32_getphdr.3elf +elf64_getshdr.3elf := SOSRC = man3elf/elf32_getshdr.3elf + +elf32_xlatetom.3elf := SOSRC = man3elf/elf32_xlatetof.3elf +elf64_xlatetof.3elf := SOSRC = man3elf/elf32_xlatetof.3elf +elf64_xlatetom.3elf := SOSRC = man3elf/elf32_xlatetof.3elf + +elf_end.3elf := SOSRC = man3elf/elf_begin.3elf +elf_memory.3elf := SOSRC = man3elf/elf_begin.3elf +elf_next.3elf := SOSRC = man3elf/elf_begin.3elf +elf_rand.3elf := SOSRC = man3elf/elf_begin.3elf + +elf_errno.3elf := SOSRC = man3elf/elf_errmsg.3elf + +elf_flagehdr.3elf := SOSRC = man3elf/elf_flagdata.3elf +elf_flagelf.3elf := SOSRC = man3elf/elf_flagdata.3elf +elf_flagphdr.3elf := SOSRC = man3elf/elf_flagdata.3elf +elf_flagscn.3elf := SOSRC = man3elf/elf_flagdata.3elf +elf_flagshdr.3elf := SOSRC = man3elf/elf_flagdata.3elf + +elf_newdata.3elf := SOSRC = man3elf/elf_getdata.3elf +elf_rawdata.3elf := SOSRC = man3elf/elf_getdata.3elf + +elf_getphdrnum.3elf := SOSRC = man3elf/elf_getident.3elf +elf_getphnum.3elf := SOSRC = man3elf/elf_getident.3elf +elf_getshdrnum.3elf := SOSRC = man3elf/elf_getident.3elf +elf_getshdrstrndx.3elf := SOSRC = man3elf/elf_getident.3elf +elf_getshnum.3elf := SOSRC = man3elf/elf_getident.3elf +elf_getshstrndx.3elf := SOSRC = man3elf/elf_getident.3elf + +elf_ndxscn.3elf := SOSRC = man3elf/elf_getscn.3elf +elf_newscn.3elf := SOSRC = man3elf/elf_getscn.3elf +elf_nextscn.3elf := SOSRC = man3elf/elf_getscn.3elf + +gelf_checksum.3elf := SOSRC = man3elf/gelf.3elf +gelf_fsize.3elf := SOSRC = man3elf/gelf.3elf +gelf_getcap.3elf := SOSRC = man3elf/gelf.3elf +gelf_getclass.3elf := SOSRC = man3elf/gelf.3elf +gelf_getdyn.3elf := SOSRC = man3elf/gelf.3elf +gelf_getehdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_getmove.3elf := SOSRC = man3elf/gelf.3elf +gelf_getphdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_getrel.3elf := SOSRC = man3elf/gelf.3elf +gelf_getrela.3elf := SOSRC = man3elf/gelf.3elf +gelf_getshdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_getsym.3elf := SOSRC = man3elf/gelf.3elf +gelf_getsyminfo.3elf := SOSRC = man3elf/gelf.3elf +gelf_getsymshndx.3elf := SOSRC = man3elf/gelf.3elf +gelf_newehdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_newphdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_cap.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_dyn.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_ehdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_getmove.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_move.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_phdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_rel.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_rela.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_shdr.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_sym.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_syminfo.3elf := SOSRC = man3elf/gelf.3elf +gelf_update_symshndx.3elf := SOSRC = man3elf/gelf.3elf +gelf_xlatetof.3elf := SOSRC = man3elf/gelf.3elf +gelf_xlatetom.3elf := SOSRC = man3elf/gelf.3elf + +.KEEP_STATE: + +include ../Makefile.man + +install: $(ROOTMANFILES) diff --git a/usr/src/man/man3elf/elf.3elf b/usr/src/man/man3elf/elf.3elf new file mode 100644 index 0000000000..1b0d20c625 --- /dev/null +++ b/usr/src/man/man3elf/elf.3elf @@ -0,0 +1,476 @@ +'\" te +.\" Copyright 1989 AT&T All Rights Reserved 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] +.TH elf 3ELF "23 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf \- object file access library +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +\fB#include <libelf.h>\fR +.fi + +.SH DESCRIPTION +.sp +.LP +Functions in the \fBELF\fR access library let a program manipulate \fBELF\fR +(Executable and Linking Format) object files, archive files, and archive +members. The header provides type and function declarations for all library +services. +.sp +.LP +Programs communicate with many of the higher-level routines using an \fIELF +descriptor\fR. That is, when the program starts working with a file, +\fBelf_begin\fR(3ELF) creates an \fBELF\fR descriptor through which the program +manipulates the structures and information in the file. These \fBELF\fR +descriptors can be used both to read and to write files. After the program +establishes an \fBELF\fR descriptor for a file, it may then obtain +\fIsection\fR \fIdescriptors\fR to manipulate the sections of the file (see +\fBelf_getscn\fR(3ELF)). Sections hold the bulk of an object file's real +information, such as text, data, the symbol table, and so on. A section +descriptor ``belongs'' to a particular \fBELF\fR descriptor, just as a section +belongs to a file. Finally, \fIdata\fR \fIdescriptors\fR are available through +section descriptors, allowing the program to manipulate the information +associated with a section. A data descriptor ``belongs'' to a section +descriptor. +.sp +.LP +Descriptors provide private handles to a file and its pieces. In other words, a +data descriptor is associated with one section descriptor, which is associated +with one \fBELF\fR descriptor, which is associated with one file. Although +descriptors are private, they give access to data that may be shared. Consider +programs that combine input files, using incoming data to create or update +another file. Such a program might get data descriptors for an input and an +output section. It then could update the output descriptor to reuse the input +descriptor's data. That is, the descriptors are distinct, but they could share +the associated data bytes. This sharing avoids the space overhead for duplicate +buffers and the performance overhead for copying data unnecessarily. +.SS "File Classes" +.sp +.LP +\fBELF\fR provides a framework in which to define a family of object files, +supporting multiple processors and architectures. An important distinction +among object files is the \fIclass\fR, or capacity, of the file. The 32-bit +class supports architectures in which a 32-bit object can represent addresses, +file sizes, and so on, as in the following: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +NamePurpose +_ +\fBElf32_Addr\fRUnsigned address +_ +\fBElf32_Half\fRUnsigned medium integer +_ +\fBElf32_Off\fRUnsigned file offset +_ +\fBElf32_Sword\fRSigned large integer +_ +\fBElf32_Word\fRUnsigned large integer +_ +\fBunsigned char\fRUnsigned small integer +.TE + +.sp +.LP +The 64\(mibit class works the same as the 32\(mibit class, substituting 64 for +32 as necessary. Other classes will be defined as necessary, to support larger +(or smaller) machines. Some library services deal only with data objects for a +specific class, while others are class-independent. To make this distinction +clear, library function names reflect their status, as described below. +.SS "Data Representation" +.sp +.LP +Conceptually, two parallel sets of objects support cross compilation +environments. One set corresponds to file contents, while the other set +corresponds to the native memory image of the program manipulating the file. +Type definitions supplied by the headers work on the native machine, which may +have different data encodings (size, byte order, and so on) than the target +machine. Although native memory objects should be at least as big as the file +objects (to avoid information loss), they may be bigger if that is more natural +for the host machine. +.sp +.LP +Translation facilities exist to convert between file and memory +representations. Some library routines convert data automatically, while others +leave conversion as the program's responsibility. Either way, programs that +create object files must write file-typed objects to those files; programs that +read object files must take a similar view. See \fBelf32_xlatetof\fR(3ELF) and +\fBelf32_fsize\fR(3ELF) for more information. +.sp +.LP +Programs may translate data explicitly, taking full control over the object +file layout and semantics. If the program prefers not to have and exercise +complete control, the library provides a higher-level interface that hides many +object file details. \fBelf_begin()\fR and related functions let a program deal +with the native memory types, converting between memory objects and their file +equivalents automatically when reading or writing an object file. +.SS "ELF Versions" +.sp +.LP +Object file versions allow \fBELF\fR to adapt to new requirements. \fIThree\fR +\fIindependent\fR \fIversions\fR can be important to a program. First, an +application program knows about a particular version by virtue of being +compiled with certain headers. Second, the access library similarly is compiled +with header files that control what versions it understands. Third, an +\fBELF\fR object file holds a value identifying its version, determined by the +\fBELF\fR version known by the file's creator. Ideally, all three versions +would be the same, but they may differ. +.sp +.LP +If a program's version is newer than the access library, the program might use +information unknown to the library. Translation routines might not work +properly, leading to undefined behavior. This condition merits installing a new +library. +.sp +.LP +The library's version might be newer than the program's and the file's. The +library understands old versions, thus avoiding compatibility problems in this +case. +.sp +.LP +Finally, a file's version might be newer than either the program or the library +understands. The program might or might not be able to process the file +properly, depending on whether the file has extra information and whether that +information can be safely ignored. Again, the safe alternative is to install a +new library that understands the file's version. +.sp +.LP +To accommodate these differences, a program must use \fBelf_version\fR(3ELF) to +pass its version to the library, thus establishing the \fIworking version\fR +for the process. Using this, the library accepts data from and presents data to +the program in the proper representations. When the library reads object files, +it uses each file's version to interpret the data. When writing files or +converting memory types to the file equivalents, the library uses the program's +working version for the file data. +.SS "System Services" +.sp +.LP +As mentioned above, \fBelf_begin()\fR and related routines provide a +higher-level interface to \fBELF\fR files, performing input and output on +behalf of the application program. These routines assume a program can hold +entire files in memory, without explicitly using temporary files. When reading +a file, the library routines bring the data into memory and perform subsequent +operations on the memory copy. Programs that wish to read or write large object +files with this model must execute on a machine with a large process virtual +address space. If the underlying operating system limits the number of open +files, a program can use \fBelf_cntl\fR(3ELF) to retrieve all necessary data +from the file, allowing the program to close the file descriptor and reuse it. +.sp +.LP +Although the \fBelf_begin()\fR interfaces are convenient and efficient for many +programs, they might be inappropriate for some. In those cases, an application +may invoke the \fBelf32_xlatetom\fR(3ELF) or \fBelf32_xlatetof\fR(3ELF) data +translation routines directly. These routines perform no input or output, +leaving that as the application's responsibility. By assuming a larger share of +the job, an application controls its input and output model. +.SS "Library Names" +.sp +.LP +Names associated with the library take several forms. +.sp +.ne 2 +.mk +.na +\fB\fBelf_\fR\fIname\fR\fR +.ad +.RS 18n +.rt +These class-independent names perform some service, \fIname\fR, for the +program. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBelf32_\fR\fIname\fR\fR +.ad +.RS 18n +.rt +Service names with an embedded class, \fB32\fR here, indicate they work only +for the designated class of files. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBElf_\fR\fIType\fR\fR +.ad +.RS 18n +.rt +Data types can be class-independent as well, distinguished by \fIType\fR. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBElf32_\fR\fIType\fR\fR +.ad +.RS 18n +.rt +Class-dependent data types have an embedded class name, \fB32\fR here. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_\fR\fICMD\fR\fR +.ad +.RS 18n +.rt +Several functions take commands that control their actions. These values are +members of the \fBElf_Cmd\fR enumeration; they range from zero through +\fBELF_C_NUM\fR\(mi1\fB\&.\fR +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_F_\fR\fIFLAG\fR\fR +.ad +.RS 18n +.rt +Several functions take flags that control library status and/or actions. Flags +are bits that may be combined. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF32_FSZ_\fR\fITYPE\fR\fR +.ad +.RS 18n +.rt +These constants give the file sizes in bytes of the basic \fBELF\fR types for +the 32-bit class of files. See \fBelf32_fsize()\fR for more information. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_K_\fR\fIKIND\fR\fR +.ad +.RS 18n +.rt +The function \fBelf_kind()\fR identifies the \fIKIND\fR of file associated with +an \fBELF\fR descriptor. These values are members of the \fBElf_Kind\fR +enumeration; they range from zero through \fBELF_K_NUM\fR\(mi1\fB\&.\fR +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_T_\fR\fITYPE\fR\fR +.ad +.RS 18n +.rt +When a service function, such as \fBelf32_xlatetom()\fR or +\fBelf32_xlatetof()\fR, deals with multiple types, names of this form specify +the desired \fITYPE\fR. Thus, for example, \fBELF_T_EHDR\fR is directly related +to \fBElf32_Ehdr\fR. These values are members of the \fBElf_Type\fR +enumeration; they range from zero through \fBELF_T_NUM\fR\(mi1\fB\&.\fR +.RE + +.SH EXAMPLES +.LP +\fBExample 1 \fRAn interpretation of elf file. +.sp +.LP +The basic interpretation of an ELF file consists of: + +.RS +4 +.TP +.ie t \(bu +.el o +opening an ELF object file +.RE +.RS +4 +.TP +.ie t \(bu +.el o +obtaining an ELF descriptor +.RE +.RS +4 +.TP +.ie t \(bu +.el o +analyzing the file using the descriptor. +.RE +.sp +.LP +The following example opens the file, obtains the ELF descriptor, and prints +out the names of each section in the file. + +.sp +.in +2 +.nf +#include <fcntl.h> +#include <stdio.h> +#include <libelf.h> +#include <stdlib.h> +#include <string.h> +static void failure(void); +void +main(int argc, char ** argv) +{ + Elf32_Shdr * shdr; + Elf32_Ehdr * ehdr; + Elf * elf; + Elf_Scn * scn; + Elf_Data * data; + int fd; + unsigned int cnt; + + /* Open the input file */ + if ((fd = open(argv[1], O_RDONLY)) == -1) + exit(1); + + /* Obtain the ELF descriptor */ + (void) elf_version(EV_CURRENT); + if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) + failure(); + + /* Obtain the .shstrtab data buffer */ + if (((ehdr = elf32_getehdr(elf)) == NULL) || + ((scn = elf_getscn(elf, ehdr->e_shstrndx)) == NULL) || + ((data = elf_getdata(scn, NULL)) == NULL)) + failure(); + + /* Traverse input filename, printing each section */ + for (cnt = 1, scn = NULL; scn = elf_nextscn(elf, scn); cnt++) { + if ((shdr = elf32_getshdr(scn)) == NULL) + failure(); + (void) printf("[%d] %s\en", cnt, + (char *)data->d_buf + shdr->sh_name); + } +} /* end main */ + +static void +failure() +{ + (void) fprintf(stderr, "%s\en", elf_errmsg(elf_errno())); + exit(1); +} +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBar.h\fR(3HEAD), \fBelf32_checksum\fR(3ELF), \fBelf32_fsize\fR(3ELF), +\fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_cntl\fR(3ELF), \fBelf_errmsg\fR(3ELF), \fBelf_fill\fR(3ELF), +\fBelf_getarhdr\fR(3ELF), \fBelf_getarsym\fR(3ELF), \fBelf_getbase\fR(3ELF), +\fBelf_getdata\fR(3ELF), \fBelf_getident\fR(3ELF), \fBelf_getscn\fR(3ELF), +\fBelf_hash\fR(3ELF), \fBelf_kind\fR(3ELF), \fBelf_memory\fR(3ELF), +\fBelf_rawfile\fR(3ELF), \fBelf_strptr\fR(3ELF), \fBelf_update\fR(3ELF), +\fBelf_version\fR(3ELF), \fBgelf\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5), \fBlfcompile\fR(5) +.sp +.LP +\fIANSI C Programmer's Guide\fR +.SS "SPARC only" +.sp +.LP +\fBa.out\fR(4) +.SH NOTES +.sp +.LP +Information in the \fBELF\fR headers is separated into common parts and +processor-specific parts. A program can make a processor's information +available by including the appropriate header: +\fB<sys/elf_\fR\fINAME\fR\fB\&.h>\fR where \fINAME\fR matches the processor +name as used in the \fBELF\fR file header. +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +NameProcessor +_ +\fBM32\fRAT&T WE 32100 +_ +\fBSPARC\fRSPARC +_ +\fB386\fRIntel 80386, 80486, Pentium +.TE + +.sp +.LP +Other processors will be added to the table as necessary. +.sp +.LP +To illustrate, a program could use the following code to ``see'' the +processor-specific information for the SPARC based system. +.sp +.in +2 +.nf +\fB#include <libelf.h> +#include <sys/elf_SPARC.h>\fR +.fi +.in -2 + +.sp +.LP +Without the \fB<sys/elf_SPARC.h>\fR definition, only the common \fBELF\fR +information would be visible. +.sp +.LP +A program could use the following code to ``see'' the processor-specific +information for the Intel 80386: +.sp +.in +2 +.nf +\fB#include <libelf.h> +#include <sys/elf_386.h>\fR +.fi +.in -2 + +.sp +.LP +Without the \fB<sys/elf_386.h>\fR definition, only the common \fBELF\fR +information would be visible. +.sp +.LP +Although reading the objects is rather straightforward, writing/updating them +can corrupt the shared offsets among sections. Upon creation, relationships are +established among the sections that must be maintained even if the object's +size is changed. diff --git a/usr/src/man/man3elf/elf32_checksum.3elf b/usr/src/man/man3elf/elf32_checksum.3elf new file mode 100644 index 0000000000..e84aaaf11c --- /dev/null +++ b/usr/src/man/man3elf/elf32_checksum.3elf @@ -0,0 +1,60 @@ +'\" 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] +.TH elf32_checksum 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_checksum, elf64_checksum \- return checksum of elf image +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBlong\fR \fBelf32_checksum\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBlong\fR \fBelf64_checksum\fR(\fBElf *\fR\fIelf\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf32_checksum()\fR function returns a simple checksum of selected +sections of the image identified by \fIelf\fR. The value is typically used as +the \fB\&.dynamic\fR tag \fBDT_CHECKSUM\fR, recorded in dynamic executables and +shared objects. +.sp +.LP +Selected sections of the image are used to calcluate the checksum in order that +its value is not affected by utilities such as \fBstrip\fR(1). +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf_version\fR(3ELF), \fBgelf\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf32_fsize.3elf b/usr/src/man/man3elf/elf32_fsize.3elf new file mode 100644 index 0000000000..64ab041990 --- /dev/null +++ b/usr/src/man/man3elf/elf32_fsize.3elf @@ -0,0 +1,76 @@ +'\" 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] +.TH elf32_fsize 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_fsize, elf64_fsize \- return the size of an object file type +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBsize_t\fR \fBelf32_fsize\fR(\fBElf_Type\fR \fItype\fR, \fBsize_t\fR \fIcount\fR, \fBunsigned\fR \fIver\fR); +.fi + +.LP +.nf +\fBsize_t\fR \fBelf64_fsize\fR(\fBElf_Type\fR \fItype\fR, \fBsize_t\fR \fIcount\fR, \fBunsigned\fR \fIver\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBelf32_fsize()\fR gives the size in bytes of the 32-bit file representation +of \fIcount\fR data objects with the given \fBtype\fR. The library uses version +\fBver\fR to calculate the size. See \fBelf\fR(3ELF) and +\fBelf_version\fR(3ELF). +.sp +.LP +Constant values are available for the sizes of fundamental types: +.sp +.in +2 +.nf +\fBElf_Type File Size Memory Size +ELF_T_ADDR ELF32_FSZ_ADDR sizeof(Elf32_Addr) +ELF_T_BYTE 1 sizeof(unsigned char) +ELF_T_HALF ELF32_FSZ_HALF sizeof(Elf32_Half) +ELT_T_OFF ELF32_FSZ_OFF sizeof(Elf32_Off) +ELF_T_SWORD ELF32_FSZ_SWORD sizeof(Elf32_Sword) +ELF_T_WORD ELF32_FSZ_WORD sizeof(Elf32_Word)\fR +.fi +.in -2 + +.sp +.LP +\fBelf32_fsize()\fR returns \fB0\fR if the value of \fBtype\fR or \fBver\fR is +unknown. See \fBelf32_xlatetof\fR(3ELF) for a list of the \fBtype\fR values. +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_version\fR(3ELF), +\fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf32_getehdr.3elf b/usr/src/man/man3elf/elf32_getehdr.3elf new file mode 100644 index 0000000000..ee5a817a30 --- /dev/null +++ b/usr/src/man/man3elf/elf32_getehdr.3elf @@ -0,0 +1,109 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 2002, 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] +.TH elf32_getehdr 3ELF "19 Jun 2002" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_getehdr, elf32_newehdr, elf64_getehdr, elf64_newehdr \- retrieve +class-dependent object file header +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf32_Ehdr *\fR\fBelf32_getehdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf32_Ehdr *\fR\fBelf32_newehdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf64_Ehdr *\fR\fBelf64_getehdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf64_Ehdr *\fR\fBelf64_newehdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +For a 32-bit class file, \fBelf32_getehdr()\fR returns a pointer to an +\fBELF\fR header, if one is available for the \fBELF\fR descriptor \fIelf\fR. +If no header exists for the descriptor, \fBelf32_newehdr()\fR allocates a clean +one, but it otherwise behaves the same as \fBelf32_getehdr()\fR. It does not +allocate a new header if one exists already. If no header exists for +\fBelf32_getehdr()\fR, one cannot be created for \fBelf32_newehdr()\fR, a +system error occurs, the file is not a 32-bit class file, or \fIelf\fR is +\fINULL\fR, both functions return a null pointer. +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.sp +.LP +The header includes the following members: +.sp +.in +2 +.nf +unsigned char e_ident[EI_NIDENT]; +Elf32_Half e_type; +Elf32_Half e_machine; +Elf32_Word e_version; +Elf32_Addr e_entry; +Elf32_Off e_phoff; +Elf32_Off e_shoff; +Elf32_Word e_flags; +Elf32_Half e_ehsize; +Elf32_Half e_phentsize; +Elf32_Half e_phnum; +Elf32_Half e_shentsize; +Elf32_Half e_shnum; +Elf32_Half e_shstrndx; +.fi +.in -2 + +.sp +.LP +The \fBelf32_newehdr()\fR function automatically sets the \fBELF_F_DIRTY\fR +bit. See \fBelf_flagdata\fR(3ELF). +.sp +.LP +An application can use \fBelf_getident()\fR to inspect the identification bytes +from a file. +.sp +.LP +An application can use \fBelf_getshnum()\fR and \fBelf_getshstrndx()\fR to +obtain section header information. The location of this section header +information differs between standard \fBELF\fR files to those that require +Extended Sections. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf_begin\fR(3ELF), \fBelf_flagdata\fR(3ELF), +\fBelf_getident\fR(3ELF), \fBelf_getshnum\fR(3ELF), +\fBelf_getshstrndx\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf32_getphdr.3elf b/usr/src/man/man3elf/elf32_getphdr.3elf new file mode 100644 index 0000000000..d70740231d --- /dev/null +++ b/usr/src/man/man3elf/elf32_getphdr.3elf @@ -0,0 +1,123 @@ +'\" 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] +.TH elf32_getphdr 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_getphdr, elf32_newphdr, elf64_getphdr, elf64_newphdr \- retrieve +class-dependent program header table +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf32_Phdr *\fR\fBelf32_getphdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf32_Phdr *\fR\fBelf32_newphdr\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIcount\fR); +.fi + +.LP +.nf +\fBElf64_Phdr *\fR\fBelf64_getphdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf64_Phdr *\fR\fBelf64_newphdr\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIcount\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +For a 32-bit class file, \fBelf32_getphdr()\fR returns a pointer to the program +execution header table, if one is available for the \fBELF\fR descriptor +\fIelf\fR. +.sp +.LP +\fBelf32_newphdr()\fR allocates a new table with \fIcount\fR entries, +regardless of whether one existed previously, and sets the \fBELF_F_DIRTY\fR +bit for the table. See \fBelf_flagdata\fR(3ELF). Specifying a zero \fIcount\fR +deletes an existing table. Note this behavior differs from that of +\fBelf32_newehdr()\fR allowing a program to replace or delete the program +header table, changing its size if necessary. See \fBelf32_getehdr\fR(3ELF). +.sp +.LP +If no program header table exists, the file is not a 32-bit class file, an +error occurs, or \fIelf\fR is \fINULL,\fR both functions return a null pointer. +Additionally, \fBelf32_newphdr()\fR returns a null pointer if \fIcount\fR is +\fB0\fR. +.sp +.LP +The table is an array of \fBElf32_Phdr\fR structures, each of which includes +the following members: +.sp +.in +2 +.nf +\fBElf32_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;\fR +.fi +.in -2 + +.sp +.LP +The \fBElf64_Phdr\fR structures include the following members: +.sp +.in +2 +.nf +\fBElf64_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;\fR +.fi +.in -2 + +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.sp +.LP +The \fBELF\fR header's \fBe_phnum\fR member tells how many entries the program +header table has. See \fBelf32_getehdr\fR(3ELF). A program may inspect this +value to determine the size of an existing table; \fBelf32_newphdr()\fR +automatically sets the member's value to \fIcount\fR. If the program is +building a new file, it is responsible for creating the file's \fBELF\fR header +before creating the program header table. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_flagdata\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf32_getshdr.3elf b/usr/src/man/man3elf/elf32_getshdr.3elf new file mode 100644 index 0000000000..a458688399 --- /dev/null +++ b/usr/src/man/man3elf/elf32_getshdr.3elf @@ -0,0 +1,98 @@ +'\" 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] +.TH elf32_getshdr 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_getshdr, elf64_getshdr \- retrieve class-dependent section header +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf32_Shdr *\fR\fBelf32_getshdr\fR(\fBElf_Scn *\fR\fIscn\fR); +.fi + +.LP +.nf +\fBElf64_Shdr *\fR\fBelf64_getshdr\fR(\fBElf_Scn *\fR\fIscn\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +For a 32-bit class file, \fBelf32_getshdr()\fR returns a pointer to a section +header for the section descriptor \fIscn\fR. Otherwise, the file is not a +32-bit class file, \fIscn\fR was \fINULL,\fR or an error occurred; +\fBelf32_getshdr()\fR then returns \fINULL\fR. +.sp +.LP +The \fBelf32_getshdr\fR header includes the following members: +.sp +.in +2 +.nf +\fBElf32_Word sh_name; +Elf32_Word sh_type; +Elf32_Word sh_flags; +Elf32_Addr sh_addr; +Elf32_Off sh_offset; +Elf32_Word sh_size; +Elf32_Word sh_link; +Elf32_Word sh_info; +Elf32_Word sh_addralign; +Elf32_Word sh_entsize;\fR +.fi +.in -2 + +.sp +.LP +while the \fBelf64_getshdr\fR header includes the following members: +.sp +.in +2 +.nf +\fBElf64_Word sh_name; +Elf64_Word sh_type; +Elf64_Xword sh_flags; +Elf64_Addr sh_addr; +Elf64_Off sh_offset; +Elf64_Xword sh_size; +Elf64_Word sh_link; +Elf64_Word sh_info; +Elf64_Xword sh_addralign; +Elf64_Xword sh_entsize;\fR +.fi +.in -2 + +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.sp +.LP +If the program is building a new file, it is responsible for creating the +file's \fBELF\fR header before creating sections. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf_flagdata\fR(3ELF), \fBelf_getscn\fR(3ELF), +\fBelf_strptr\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf32_xlatetof.3elf b/usr/src/man/man3elf/elf32_xlatetof.3elf new file mode 100644 index 0000000000..36b5e6cca2 --- /dev/null +++ b/usr/src/man/man3elf/elf32_xlatetof.3elf @@ -0,0 +1,164 @@ +'\" 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] +.TH elf32_xlatetof 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf32_xlatetof, elf32_xlatetom, elf64_xlatetof, elf64_xlatetom \- +class-dependent data translation +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf_Data *\fR\fBelf32_xlatetof\fR(\fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBelf32_xlatetom\fR(\fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBelf64_xlatetof\fR(\fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBelf64_xlatetom\fR(\fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBelf32_xlatetom()\fR translates various data structures from their 32-bit +class file representations to their memory representations; +\fBelf32_xlatetof()\fR provides the inverse. This conversion is particularly +important for cross development environments. \fIsrc\fR is a pointer to the +source buffer that holds the original data; \fIdst\fR is a pointer to a +destination buffer that will hold the translated copy. \fIencode\fR gives the +byte encoding in which the file objects are to be represented and must have one +of the encoding values defined for the \fBELF\fR header's +\fBe_ident[EI_DATA]\fR entry (see \fBelf_getident\fR(3ELF)). If the data can be +translated, the functions return \fIdst\fR. Otherwise, they return \fINULL\fR +because an error occurred, such as incompatible types, destination buffer +overflow, etc. +.sp +.LP +\fBelf_getdata\fR(3ELF) describes the \fBElf_Data\fR descriptor, which the +translation routines use as follows: +.sp +.ne 2 +.mk +.na +\fB\fBd_buf\fR\fR +.ad +.RS 13n +.rt +Both the source and destination must have valid buffer pointers. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_type\fR\fR +.ad +.RS 13n +.rt +This member's value specifies the type of the data to which \fBd_buf\fR points +and the type of data to be created in the destination. The program supplies a +\fBd_type\fR value in the source; the library sets the destination's +\fBd_type\fR to the same value. These values are summarized below. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_size\fR\fR +.ad +.RS 13n +.rt +This member holds the total size, in bytes, of the memory occupied by the +source data and the size allocated for the destination data. If the destination +buffer is not large enough, the routines do not change its original contents. +The translation routines reset the destination's \fBd_size\fR member to the +actual size required, after the translation occurs. The source and destination +sizes may differ. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_version\fR\fR +.ad +.RS 13n +.rt +This member holds the version number of the objects (desired) in the buffer. +The source and destination versions are independent. +.RE + +.sp +.LP +Translation routines allow the source and destination buffers to coincide. That +is, \fBdst\(->d_buf\fR may equal \fBsrc\(->d_buf\fR. Other cases where the +source and destination buffers overlap give undefined behavior. +.sp +.in +2 +.nf +\fBElf_Type 32-Bit Memory Type +ELF_T_ADDR Elf32_Addr +ELF_T_BYTE unsigned char +ELF_T_DYN Elf32_Dyn +ELF_T_EHDR Elf32_Ehdr +ELF_T_HALF Elf32_Half +ELT_T_OFF Elf32_Off +ELF_T_PHDR Elf32_Phdr +ELF_T_REL Elf32_Rel +ELF_T_RELA Elf32_Rela +ELF_T_SHDR Elf32_Shdr +ELF_T_SWORD Elf32_Sword +ELF_T_SYM Elf32_Sym +ELF_T_WORD Elf32_Word\fR +.fi +.in -2 + +.sp +.LP +Translating buffers of type \fBELF_T_BYTE\fR does not change the byte order. +.sp +.LP +For the 64\(mibit class, replace 32 with 64 as appropriate. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_fsize\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBelf_getident\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_begin.3elf b/usr/src/man/man3elf/elf_begin.3elf new file mode 100644 index 0000000000..e9eec45613 --- /dev/null +++ b/usr/src/man/man3elf/elf_begin.3elf @@ -0,0 +1,388 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_begin 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_begin, elf_end, elf_memory, elf_next, elf_rand \- process ELF object files +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf *\fR\fBelf_begin\fR(\fBint\fR \fIfildes\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBElf *\fR\fIref\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_end\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf *\fR\fBelf_memory\fR(\fBchar *\fR\fIimage\fR, \fBsize_t\fR \fIsz\fR); +.fi + +.LP +.nf +\fBElf_Cmd\fR \fBelf_next\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBsize_t\fR \fBelf_rand\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIoffset\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_begin()\fR, \fBelf_end()\fR, \fBelf_memory()\fR, \fBelf_next()\fR, +and \fBelf_rand()\fR functions work together to process Executable and Linking +Format (ELF) object files, either individually or as members of archives. After +obtaining an \fBELF\fR descriptor from \fBelf_begin()\fR or \fBelf_memory()\fR, +the program can read an existing file, update an existing file, or create a new +file. The \fIfildes\fR argument is an open file descriptor that +\fBelf_begin()\fR uses for reading or writing. The \fIelf\fR argument is an +\fBELF\fR descriptor previously returned from \fBelf_begin()\fR. The initial +file offset (see \fBlseek\fR(2)) is unconstrained, and the resulting file +offset is undefined. +.sp +.LP +The \fIcmd\fR argument can take the following values: +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_NULL\fR\fR +.ad +.RS 15n +.rt +When a program sets \fIcmd\fR to this value, \fBelf_begin()\fR returns a null +pointer, without opening a new descriptor. \fIref\fR is ignored for this +command. See the examples below for more information. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_READ\fR\fR +.ad +.RS 15n +.rt +When a program wants to examine the contents of an existing file, it should set +\fIcmd\fR to this value. Depending on the value of \fIref\fR, this command +examines archive members or entire files. Three cases can occur. +.RS +4 +.TP +.ie t \(bu +.el o +If \fIref\fR is a null pointer, \fBelf_begin()\fR allocates a new \fBELF\fR +descriptor and prepares to process the entire file. If the file being read is +an archive, \fBelf_begin()\fR also prepares the resulting descriptor to examine +the initial archive member on the next call to \fBelf_begin()\fR, as if the +program had used \fB elf_next()\fR or \fBelf_rand()\fR to ``move'' to the +initial member. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +If \fIref\fR is a non-null descriptor associated with an archive file, +\fBelf_begin()\fR lets a program obtain a separate \fBELF\fR descriptor +associated with an individual member. The program should have used +\fBelf_next()\fR or \fBelf_rand()\fR to position \fIref\fR appropriately +(except for the initial member, which \fBelf_begin()\fR prepares; see the +example below). In this case, \fIfildes\fR should be the same file descriptor +used for the parent archive. +.RE +.RS +4 +.TP +.ie t \(bu +.el o +If \fIref\fR is a non-null \fBELF\fR descriptor that is not an archive, +\fBelf_begin()\fR increments the number of activations for the descriptor and +returns \fIref\fR, without allocating a new descriptor and without changing the +descriptor's read/write permissions. To terminate the descriptor for \fIref\fR, +the program must call \fBelf_end()\fR once for each activation. See the +examples below for more information. +.RE +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_RDWR\fR\fR +.ad +.RS 15n +.rt +This command duplicates the actions of \fBELF_C_READ\fR and additionally allows +the program to update the file image (see \fBelf_update\fR(3ELF)). Using +\fBELF_C_READ\fR gives a read-only view of the file, while \fBELF_C_RDWR\fR +lets the program read \fIand\fR write the file. \fBELF_C_RDWR\fR is not valid +for archive members. If \fIref\fR is non-null, it must have been created with +the \fBELF_C_RDWR\fR command. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_WRITE\fR\fR +.ad +.RS 15n +.rt +If the program wants to ignore previous file contents, presumably to create a +new file, it should set \fIcmd\fR to this value. \fIref\fR is ignored for this +command. +.RE + +.sp +.LP +The \fBelf_begin()\fR function operates on all files (including files with zero +bytes), providing it can allocate memory for its internal structures and read +any necessary information from the file. Programs reading object files can call +\fBelf_kind\fR(3ELF) or \fBelf32_getehdr\fR(3ELF) to determine the file type +(only object files have an \fBELF\fR header). If the file is an archive with no +more members to process, or an error occurs, \fBelf_begin()\fR returns a null +pointer. Otherwise, the return value is a non-null \fBELF\fR descriptor. +.sp +.LP +Before the first call to \fBelf_begin()\fR, a program must call +\fBelf_version()\fR to coordinate versions. +.sp +.LP +The \fBelf_end()\fR function is used to terminate an \fBELF\fR descriptor, +\fIelf\fR, and to deallocate data associated with the descriptor. Until the +program terminates a descriptor, the data remain allocated. A null pointer is +allowed as an argument, to simplify error handling. If the program wants to +write data associated with the \fBELF\fR descriptor to the file, it must use +\fBelf_update()\fR before calling \fBelf_end()\fR. +.sp +.LP +Calling \fBelf_end()\fR removes one activation and returns the remaining +activation count. The library does not terminate the descriptor until the +activation count reaches \fB0\fR. Consequently, a \fB0\fR return value +indicates the \fBELF\fR descriptor is no longer valid. +.sp +.LP +The \fBelf_memory()\fR function returns a pointer to an \fBELF\fR descriptor. +The \fBELF\fR image has read operations enabled ( \fBELF_C_READ\fR). The +\fIimage\fR argument is a pointer to an image of the Elf file mapped into +memory. The \fIsz\fR argument is the size of the \fBELF\fR image. An \fBELF\fR +image that is mapped in with \fBelf_memory()\fR can be read and modified, but +the \fBELF\fR image size cannot be changed. +.sp +.LP +The \fBelf_next()\fR function provides sequential access to the next archive +member. Having an \fBELF\fR descriptor, \fIelf\fR, associated with an archive +member, \fBelf_next()\fR prepares the containing archive to access the +following member when the program calls \fBelf_begin()\fR. After successfully +positioning an archive for the next member, \fBelf_next()\fR returns the value +\fBELF_C_READ\fR. Otherwise, the open file was not an archive, \fIelf\fR was +\fINULL\fR, or an error occurred, and the return value is \fBELF_C_NULL\fR. In +either case, the return value can be passed as an argument to +\fBelf_begin()\fR, specifying the appropriate action. +.sp +.LP +The \fBelf_rand()\fR function provides random archive processing, preparing +\fIelf\fR to access an arbitrary archive member. The \fIelf\fR argument must be +a descriptor for the archive itself, not a member within the archive. The +\fIoffset\fR argument specifies the byte offset from the beginning of the +archive to the archive header of the desired member. See +\fBelf_getarsym\fR(3ELF) for more information about archive member offsets. +When \fBelf_rand()\fR works, it returns \fIoffset\fR. Otherwise, it returns +\fB0\fR, because an error occurred, \fIelf\fR was \fI NULL\fR, or the file was +not an archive (no archive member can have a zero offset). A program can mix +random and sequential archive processing. +.SS "System Services" +.sp +.LP +When processing a file, the library decides when to read or write the file, +depending on the program's requests. Normally, the library assumes the file +descriptor remains usable for the life of the \fBELF\fR descriptor. If, +however, a program must process many files simultaneously and the underlying +operating system limits the number of open files, the program can use +\fBelf_cntl()\fR to let it reuse file descriptors. After calling +\fBelf_cntl()\fR with appropriate arguments, the program can close the file +descriptor without interfering with the library. +.sp +.LP +All data associated with an \fBELF\fR descriptor remain allocated until +\fBelf_end()\fR terminates the descriptor's last activation. After the +descriptors have been terminated, the storage is released; attempting to +reference such data gives undefined behavior. Consequently, a program that +deals with multiple input (or output) files must keep the \fBELF\fR descriptors +active until it finishes with them. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample program of calling the \fBelf_begin()\fR function. +.sp +.LP +A prototype for reading a file appears on the next page. If the file is a +simple object file, the program executes the loop one time, receiving a null +descriptor in the second iteration. In this case, both \fBelf\fR and \fBarf\fR +will have the same value, the activation count will be \fB2\fR, and the program +calls \fBelf_end()\fR twice to terminate the descriptor. If the file is an +archive, the loop processes each archive member in turn, ignoring those that +are not object files. + +.sp +.in +2 +.nf +\fBif (elf_version(EV_CURRENT) == EV_NONE) +{ + /* library out of date */ + /* recover from error */ +} +cmd = ELF_C_READ; +arf = elf_begin(fildes, cmd, (Elf *)0); +while ((elf = elf_begin(fildes, cmd, arf)) != 0) +{ + if ((ehdr = elf32_getehdr(elf)) != 0) + { + /* process the file \|.\|.\|. */ + } + cmd = elf_next(elf); + elf_end(elf); +} +elf_end(arf);\fR +.fi +.in -2 + +.sp +.LP +Alternatively, the next example illustrates random archive processing. After +identifying the file as an archive, the program repeatedly processes archive +members of interest. For clarity, this example omits error checking and ignores +simple object files. Additionally, this fragment preserves the \fBELF\fR +descriptors for all archive members, because it does not call \fBelf_end()\fR +to terminate them. + +.sp +.in +2 +.nf +\fBelf_version(EV_CURRENT); +arf = elf_begin(fildes, ELF_C_READ, (Elf *)0); +if (elf_kind(arf) != ELF_K_AR) +{ + /* not an archive */ +} +/* initial processing */ +/* set offset = \|.\|.\|. for desired member header */ +while (elf_rand(arf, offset) == offset) +{ + if ((elf = elf_begin(fildes, ELF_C_READ, arf)) == 0) + break; + if ((ehdr = elf32_getehdr(elf)) != 0) + { + /* process archive member \|.\|.\|. */ + } + /* set offset = \|.\|.\|. for desired member header */ +}\fR +.fi +.in -2 + +.sp +.LP +An archive starts with a ``magic string'' that has \fBSARMAG\fR bytes; the +initial archive member follows immediately. An application could thus provide +the following function to rewind an archive (the function returns \fB\(mi1\fR +for errors and \fB0\fR otherwise). + +.sp +.in +2 +.nf +\fB#include <ar.h> +#include <libelf.h> +int +rewindelf(Elf *elf) +{ + if (elf_rand(elf, (size_t)SARMAG) == SARMAG) + return 0; + return \(mi1; +}\fR +.fi +.in -2 + +.sp +.LP +The following outline shows how one might create a new \fBELF\fR file. This +example is simplified to show the overall flow. + +.sp +.in +2 +.nf +\fBelf_version(EV_CURRENT); +fildes = open("path/name", O_RDWR|O_TRUNC|O_CREAT, 0666); +if ((elf = elf_begin(fildes, ELF_C_WRITE, (Elf *)0)) == 0) + return; +ehdr = elf32_newehdr(elf); +phdr = elf32_newphdr(elf, count); +scn = elf_newscn(elf); +shdr = elf32_getshdr(scn); +data = elf_newdata(scn); +elf_update(elf, ELF_C_WRITE); +elf_end(elf);\fR +.fi +.in -2 + +.sp +.LP +Finally, the following outline shows how one might update an existing \fBELF\fR +file. Again, this example is simplified to show the overall flow. + +.sp +.in +2 +.nf +\fBelf_version(EV_CURRENT); +fildes = open("path/name", O_RDWR); +elf = elf_begin(fildes, ELF_C_RDWR, (Elf *)0); +/* add new or delete old information */ +\|.\|.\|. +/* ensure that the memory image of the file is complete */ +elf_update(elf, ELF_C_NULL); +elf_update(elf, ELF_C_WRITE); /* update file */ +elf_end(elf);\fR +.fi +.in -2 + +.sp +.LP +Notice that both file creation examples open the file with write \fIand\fR read +permissions. On systems that support \fBmmap\fR(2), the library uses it to +enhance performance, and \fBmmap\fR(2) requires a readable file descriptor. +Although the library can use a write-only file descriptor, the application will +not obtain the performance advantages of \fBmmap\fR(2). + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBcreat\fR(2), \fBlseek\fR(2), \fBmmap\fR(2), \fBopen\fR(2), +\fBar.h\fR(3HEAD), \fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), +\fBelf_cntl\fR(3ELF), \fBelf_getarhdr\fR(3ELF), \fBelf_getarsym\fR(3ELF), +\fBelf_getbase\fR(3ELF), \fBelf_getdata\fR(3ELF), \fBelf_getscn\fR(3ELF), +\fBelf_kind\fR(3ELF), \fBelf_rawfile\fR(3ELF), \fBelf_update\fR(3ELF), +\fBelf_version\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_cntl.3elf b/usr/src/man/man3elf/elf_cntl.3elf new file mode 100644 index 0000000000..7b2b07809c --- /dev/null +++ b/usr/src/man/man3elf/elf_cntl.3elf @@ -0,0 +1,102 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_cntl 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_cntl \- control an elf file descriptor +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBint\fR \fBelf_cntl\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBelf_cntl()\fR instructs the library to modify its behavior with respect to +an \fBELF\fR descriptor, \fIelf\fR. As \fBelf_begin\fR(3ELF) describes, an +\fBELF\fR descriptor can have multiple activations, and multiple \fBELF\fR +descriptors may share a single file descriptor. Generally, \fBelf_cntl()\fR +commands apply to all activations of \fIelf\fR. Moreover, if the \fBELF\fR +descriptor is associated with an archive file, descriptors for members within +the archive will also be affected as described below. Unless stated otherwise, +operations on archive members do not affect the descriptor for the containing +archive. +.sp +.LP +The \fIcmd\fR argument tells what actions to take and may have the following +values: +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_FDDONE\fR\fR +.ad +.RS 16n +.rt +This value tells the library not to use the file descriptor associated with +\fIelf\fR. A program should use this command when it has requested all the +information it cares to use and wishes to avoid the overhead of reading the +rest of the file. The memory for all completed operations remains valid, but +later file operations, such as the initial \fBelf_getdata()\fR for a section, +will fail if the data are not in memory already. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_FDREAD\fR\fR +.ad +.RS 16n +.rt +This command is similar to \fBELF_C_FDDONE\fR, except it forces the library to +read the rest of the file. A program should use this command when it must close +the file descriptor but has not yet read everything it needs from the file. +After \fBelf_cntl()\fR completes the \fBELF_C_FDREAD\fR command, future +operations, such as \fBelf_getdata()\fR, will use the memory version of the +file without needing to use the file descriptor. +.RE + +.sp +.LP +If \fBelf_cntl()\fR succeeds, it returns \fB0\fR. Otherwise \fIelf\fR was +\fINULL\fR or an error occurred, and the function returns \fB\(mi1\fR\&. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf_begin\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBelf_rawfile\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) +.SH NOTES +.sp +.LP +If the program wishes to use the ``raw'' operations (see \fBelf_rawdata()\fR, +which \fBelf_getdata\fR(3ELF) describes, and \fBelf_rawfile\fR(3ELF)) after +disabling the file descriptor with \fBELF_C_FDDONE\fR or \fBELF_C_FDREAD\fR, it +must execute the raw operations explicitly beforehand. Otherwise, the raw file +operations will fail. Calling \fBelf_rawfile()\fR makes the entire image +available, thus supporting subsequent \fBelf_rawdata()\fR calls. diff --git a/usr/src/man/man3elf/elf_errmsg.3elf b/usr/src/man/man3elf/elf_errmsg.3elf new file mode 100644 index 0000000000..473d6adbf7 --- /dev/null +++ b/usr/src/man/man3elf/elf_errmsg.3elf @@ -0,0 +1,87 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_errmsg 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_errmsg, elf_errno \- error handling +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBconst char *\fR\fBelf_errmsg\fR(\fBint\fR \fIerr\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_errno\fR(\fBvoid\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +If an \fBELF\fR library function fails, a program can call \fBelf_errno()\fR to +retrieve the library's internal error number. As a side effect, this function +resets the internal error number to \fB0\fR, which indicates no error. +.sp +.LP +The \fBelf_errmsg()\fR function takes an error number, \fIerr\fR, and returns a +null-terminated error message (with no trailing new-line) that describes the +problem. A zero \fIerr\fR retrieves a message for the most recent error. If no +error has occurred, the return value is a null pointer (not a pointer to the +null string). Using \fIerr\fR of \fB\(mi1\fR also retrieves the most recent +error, except it guarantees a non-null return value, even when no error has +occurred. If no message is available for the given number, \fBelf_errmsg()\fR +returns a pointer to an appropriate message. This function does not have the +side effect of clearing the internal error number. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample program of calling the \fBelf_errmsg()\fR function. +.sp +.LP +The following fragment clears the internal error number and checks it later for +errors. Unless an error occurs after the first call to \fBelf_errno()\fR, the +next call will return \fB0\fR. + +.sp +.in +2 +.nf +\fB(void)elf_errno(\|); +/* processing \|.\|.\|. */ +while (more_to_do) +{ + if ((err = elf_errno(\|)) != 0) + { + /* print msg */ + msg = elf_errmsg(err); + } +}\fR +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_fill.3elf b/usr/src/man/man3elf/elf_fill.3elf new file mode 100644 index 0000000000..78c51992d7 --- /dev/null +++ b/usr/src/man/man3elf/elf_fill.3elf @@ -0,0 +1,56 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_fill 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_fill \- set fill byte +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBvoid\fR \fBelf_fill\fR(\fBint\fR \fIfill\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +Alignment constraints for \fBELF\fR files sometimes require the presence of +``holes.'' For example, if the data for one section are required to begin on an +eight-byte boundary, but the preceding section is too ``short,'' the library +must fill the intervening bytes. These bytes are set to the \fIfill\fR +character. The library uses zero bytes unless the application supplies a value. +See \fBelf_getdata\fR(3ELF) for more information about these holes. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf_flagdata\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBelf_update\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) +.SH NOTES +.sp +.LP +An application can assume control of the object file organization by setting +the \fBELF_F_LAYOUT\fR bit (see \fBelf_flagdata\fR(3ELF)). When this is done, +the library does \fInot\fR fill holes. diff --git a/usr/src/man/man3elf/elf_flagdata.3elf b/usr/src/man/man3elf/elf_flagdata.3elf new file mode 100644 index 0000000000..25c49025cb --- /dev/null +++ b/usr/src/man/man3elf/elf_flagdata.3elf @@ -0,0 +1,162 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_flagdata 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_flagdata, elf_flagehdr, elf_flagelf, elf_flagphdr, elf_flagscn, +elf_flagshdr \- manipulate flags +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBunsigned\fR \fBelf_flagdata\fR(\fBElf_Data *\fR\fIdata\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.LP +.nf +\fBunsigned\fR \fBelf_flagehdr\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.LP +.nf +\fBunsigned\fR \fBelf_flagelf\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.LP +.nf +\fBunsigned\fR \fBelf_flagphdr\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.LP +.nf +\fBunsigned\fR \fBelf_flagscn\fR(\fBElf_Scn *\fR\fIscn\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.LP +.nf +\fBunsigned\fR \fBelf_flagshdr\fR(\fBElf_Scn *\fR\fIscn\fR, \fBElf_Cmd\fR \fIcmd\fR, \fBunsigned\fR \fIflags\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +These functions manipulate the flags associated with various structures of an +\fBELF\fR file. Given an \fBELF\fR descriptor (\fIelf\fR), a data descriptor +(\fIdata\fR), or a section descriptor (\fIscn\fR), the functions may set or +clear the associated status bits, returning the updated bits. A null descriptor +is allowed, to simplify error handling; all functions return \fB0\fR for this +degenerate case. +.sp +.LP +\fIcmd\fR may have the following values: +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_CLR\fR\fR +.ad +.RS 13n +.rt +The functions clear the bits that are asserted in \fIflags\fR. Only the +non-zero bits in \fIflags\fR are cleared; zero bits do not change the status of +the descriptor. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_SET\fR\fR +.ad +.RS 13n +.rt +The functions set the bits that are asserted in \fIflags\fR. Only the non-zero +bits in \fIflags\fR are set; zero bits do not change the status of the +descriptor. +.RE + +.sp +.LP +Descriptions of the defined \fIflags\fR bits appear below: +.sp +.ne 2 +.mk +.na +\fB\fBELF_F_DIRTY\fR\fR +.ad +.RS 16n +.rt +When the program intends to write an \fBELF\fR file, this flag asserts the +associated information needs to be written to the file. Thus, for example, a +program that wished to update the \fBELF\fR header of an existing file would +call \fBelf_flagehdr()\fR with this bit set in \fIflags\fR and \fIcmd\fR equal +to \fBELF_C_SET\fR. A later call to \fBelf_update()\fR would write the marked +header to the file. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_F_LAYOUT\fR\fR +.ad +.RS 16n +.rt +Normally, the library decides how to arrange an output file. That is, it +automatically decides where to place sections, how to align them in the file, +etc. If this bit is set for an \fBELF\fR descriptor, the program assumes +responsibility for determining all file positions. This bit is meaningful only +for \fBelf_flagelf()\fR and applies to the entire file associated with the +descriptor. +.RE + +.sp +.LP +When a flag bit is set for an item, it affects all the subitems as well. Thus, +for example, if the program sets the \fBELF_F_DIRTY\fR bit with +\fBelf_flagelf()\fR, the entire logical file is ``dirty.'' +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample display of calling the \fBelf_flagdata()\fR function. +.sp +.LP +The following fragment shows how one might mark the \fBELF\fR header to be +written to the output file: + +.sp +.in +2 +.nf +\fB/* dirty ehdr \|.\|.\|. */ +ehdr = elf32_getehdr(elf); +elf_flagehdr(elf, ELF_C_SET, ELF_F_DIRTY);\fR +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBelf_update\fR(3ELF), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_getarhdr.3elf b/usr/src/man/man3elf/elf_getarhdr.3elf new file mode 100644 index 0000000000..2b4343d465 --- /dev/null +++ b/usr/src/man/man3elf/elf_getarhdr.3elf @@ -0,0 +1,107 @@ +'\" 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] +.TH elf_getarhdr 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getarhdr \- retrieve archive member header +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR... ] +#include <libelf.h> + +\fBElf_Arhdr *\fR\fBelf_getarhdr\fR(\fBElf *\fR\fIelf\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBelf_getarhdr()\fR returns a pointer to an archive member header, if one is +available for the \fBELF\fR descriptor \fIelf\fR. Otherwise, no archive member +header exists, an error occurred, or \fIelf\fR was null; \fBelf_getarhdr()\fR +then returns a null value. The header includes the following members. +.sp +.in +2 +.nf +\fBchar *ar_name; +time_t ar_date; +uid_t ar_uid; +gid_t ar_gid; +mode_t ar_mode; +off_t ar_size; +char *ar_rawname;\fR +.fi +.in -2 + +.sp +.LP +An archive member name, available through \fBar_name\fR, is a null-terminated +string, with the \fBar\fR format control characters removed. The +\fBar_rawname\fR member holds a null-terminated string that represents the +original name bytes in the file, including the terminating slash and trailing +blanks as specified in the archive format. +.sp +.LP +In addition to ``regular'' archive members, the archive format defines some +special members. All special member names begin with a slash (\fB/\fR), +distinguishing them from regular members (whose names may not contain a slash). +These special members have the names (\fBar_name\fR) defined below. +.sp +.ne 2 +.mk +.na +\fB\fB/\fR\fR +.ad +.RS 6n +.rt +This is the archive symbol table. If present, it will be the first archive +member. A program may access the archive symbol table through +\fBelf_getarsym()\fR. The information in the symbol table is useful for random +archive processing (see \fBelf_rand()\fR on \fBelf_begin\fR(3ELF)). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB//\fR\fR +.ad +.RS 6n +.rt +This member, if present, holds a string table for long archive member names. An +archive member's header contains a 16-byte area for the name, which may be +exceeded in some file systems. The library automatically retrieves long member +names from the string table, setting \fBar_name\fR to the appropriate value. +.RE + +.sp +.LP +Under some error conditions, a member's name might not be available. Although +this causes the library to set \fBar_name\fR to a null pointer, the +\fBar_rawname\fR member will be set as usual. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBar.h\fR(3HEAD), \fBelf\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_getarsym\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_getarsym.3elf b/usr/src/man/man3elf/elf_getarsym.3elf new file mode 100644 index 0000000000..767f69d5f8 --- /dev/null +++ b/usr/src/man/man3elf/elf_getarsym.3elf @@ -0,0 +1,109 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_getarsym 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getarsym \- retrieve archive symbol table +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf_Arsym *\fR\fBelf_getarsym\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIptr\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_getarsym()\fR function returns a pointer to the archive symbol +table, if one is available for the \fBELF\fR descriptor \fIelf\fR. Otherwise, +the archive doesn't have a symbol table, an error occurred, or \fIelf\fR was +null; \fBelf_getarsym()\fR then returns a null value. The symbol table is an +array of structures that include the following members. +.sp +.in +2 +.nf +\fBchar *as_name; +size_t as_off; +unsigned long as_hash;\fR +.fi +.in -2 + +.sp +.LP +These members have the following semantics: +.sp +.ne 2 +.mk +.na +\fB\fBas_name\fR\fR +.ad +.RS 11n +.rt +A pointer to a null-terminated symbol name resides here. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBas_off\fR\fR +.ad +.RS 11n +.rt +This value is a byte offset from the beginning of the archive to the member's +header. The archive member residing at the given offset defines the associated +symbol. Values in \fBas_off\fR may be passed as arguments to \fBelf_rand()\fR. +See \fBelf_begin\fR(3ELF) to access the desired archive member. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBas_hash\fR\fR +.ad +.RS 11n +.rt +This is a hash value for the name, as computed by \fBelf_hash()\fR. +.RE + +.sp +.LP +If \fIptr\fR is non-null, the library stores the number of table entries in the +location to which \fIptr\fR points. This value is set to \fB0\fR when the +return value is \fINULL\fR. The table's last entry, which is included in the +count, has a null \fBas_name\fR, a zero value for \fBas_off\fR, and \fB~0UL\fR +for \fBas_hash\fR. +.sp +.LP +The hash value returned is guaranteed not to be the bit pattern of all ones ( +\fB~0UL\fR). +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBar.h\fR(3HEAD), \fBelf\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_getarhdr\fR(3ELF), \fBelf_hash\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_getbase.3elf b/usr/src/man/man3elf/elf_getbase.3elf new file mode 100644 index 0000000000..dc065386b0 --- /dev/null +++ b/usr/src/man/man3elf/elf_getbase.3elf @@ -0,0 +1,50 @@ +'\" 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] +.TH elf_getbase 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getbase \- get the base offset for an object file +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBoff_t\fR \fBelf_getbase\fR(\fBElf *\fR\fIelf\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_getbase()\fR function returns the file offset of the first byte of +the file or archive member associated with \fIelf\fR, if it is known or +obtainable, and \fB\(mi1\fR otherwise. A null \fIelf\fR is allowed, to simplify +error handling; the return value in this case is \fB\(mi1\fR\&. The base offset +of an archive member is the beginning of the member's information, \fInot\fR +the beginning of the archive member header. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBar.h\fR(3HEAD), \fBelf\fR(3ELF), \fBelf_begin\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_getdata.3elf b/usr/src/man/man3elf/elf_getdata.3elf new file mode 100644 index 0000000000..6f882923d4 --- /dev/null +++ b/usr/src/man/man3elf/elf_getdata.3elf @@ -0,0 +1,327 @@ +'\" 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] +.TH elf_getdata 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getdata, elf_newdata, elf_rawdata \- get section data +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf_Data *\fR\fBelf_getdata\fR(\fBElf_Scn *\fR\fIscn\fR, \fBElf_Data *\fR\fIdata\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBelf_newdata\fR(\fBElf_Scn *\fR\fIscn\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBelf_rawdata\fR(\fBElf_Scn *\fR\fIscn\fR, \fBElf_Data *\fR\fIdata\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +These functions access and manipulate the data associated with a section +descriptor, \fIscn\fR. When reading an existing file, a section will have a +single data buffer associated with it. A program may build a new section in +pieces, however, composing the new data from multiple data buffers. For this +reason, the data for a section should be viewed as a list of buffers, each of +which is available through a data descriptor. +.sp +.LP +The \fBelf_getdata()\fR function lets a program step through a section's data +list. If the incoming data descriptor, \fIdata\fR, is null, the function +returns the first buffer associated with the section. Otherwise, \fIdata\fR +should be a data descriptor associated with \fIscn\fR, and the function gives +the program access to the next data element for the section. If \fIscn\fR is +null or an error occurs, \fBelf_getdata()\fR returns a null pointer. +.sp +.LP +The \fBelf_getdata()\fR function translates the data from file representations +into memory representations (see \fBelf32_xlatetof\fR(3ELF)) and presents +objects with memory data types to the program, based on the file's \fIclass\fR +(see \fBelf\fR(3ELF)). The working library version (see +\fBelf_version\fR(3ELF)) specifies what version of the memory structures the +program wishes \fBelf_getdata()\fR to present. +.sp +.LP +The \fBelf_newdata()\fR function creates a new data descriptor for a section, +appending it to any data elements already associated with the section. As +described below, the new data descriptor appears empty, indicating the element +holds no data. For convenience, the descriptor's type (\fBd_type\fR below) is +set to \fBELF_T_BYTE\fR, and the version (\fBd_version\fR below) is set to the +working version. The program is responsible for setting (or changing) the +descriptor members as needed. This function implicitly sets the +\fBELF_F_DIRTY\fR bit for the section's data (see \fBelf_flagdata\fR(3ELF)). If +\fI scn\fR is null or an error occurs, \fBelf_newdata()\fR returns a null +pointer. +.sp +.LP +The \fBelf_rawdata()\fR function differs from \fBelf_getdata()\fR by returning +only uninterpreted bytes, regardless of the section type. This function +typically should be used only to retrieve a section image from a file being +read, and then only when a program must avoid the automatic data translation +described below. Moreover, a program may not close or disable (see +\fBelf_cntl\fR(3ELF)) the file descriptor associated with \fIelf\fR before the +initial raw operation, because \fBelf_rawdata()\fR might read the data from the +file to ensure it doesn't interfere with \fBelf_getdata()\fR. See +\fBelf_rawfile\fR(3ELF) for a related facility that applies to the entire file. +When \fBelf_getdata()\fR provides the right translation, its use is recommended +over \fBelf_rawdata()\fR. If \fIscn\fR is null or an error occurs, +\fBelf_rawdata()\fR returns a null pointer. +.sp +.LP +The \fBElf_Data\fR structure includes the following members: +.sp +.in +2 +.nf +void *d_buf; +Elf_Type d_type; +size_t d_size; +off_t d_off; +size_t d_align; +unsigned d_version; +.fi +.in -2 + +.sp +.LP +These members are available for direct manipulation by the program. +Descriptions appear below. +.sp +.ne 2 +.mk +.na +\fB\fBd_buf\fR\fR +.ad +.RS 13n +.rt +A pointer to the data buffer resides here. A data element with no data has a +null pointer. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_type\fR\fR +.ad +.RS 13n +.rt +This member's value specifies the type of the data to which \fBd_buf\fR points. +A section's type determines how to interpret the section contents, as +summarized below. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_size\fR\fR +.ad +.RS 13n +.rt +This member holds the total size, in bytes, of the memory occupied by the data. +This may differ from the size as represented in the file. The size will be zero +if no data exist. (See the discussion of \fBSHT_NOBITS\fR below for more +information.) +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_off\fR\fR +.ad +.RS 13n +.rt +This member gives the offset, within the section, at which the buffer resides. +This offset is relative to the file's section, not the memory object's. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_align\fR\fR +.ad +.RS 13n +.rt +This member holds the buffer's required alignment, from the beginning of the +section. That is, \fBd_off\fR will be a multiple of this member's value. For +example, if this member's value is \fB4\fR, the beginning of the buffer will be +four-byte aligned within the section. Moreover, the entire section will be +aligned to the maximum of its constituents, thus ensuring appropriate alignment +for a buffer within the section and within the file. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBd_version\fR\fR +.ad +.RS 13n +.rt +This member holds the version number of the objects in the buffer. When the +library originally read the data from the object file, it used the working +version to control the translation to memory objects. +.RE + +.SS "Data Alignment" +.sp +.LP +As mentioned above, data buffers within a section have explicit alignment +constraints. Consequently, adjacent buffers sometimes will not abut, causing +``holes'' within a section. Programs that create output files have two ways of +dealing with these holes. +.sp +.LP +First, the program can use \fBelf_fill()\fR to tell the library how to set the +intervening bytes. When the library must generate gaps in the file, it uses the +fill byte to initialize the data there. The library's initial fill value is +\fB0\fR, and \fBelf_fill()\fR lets the application change that. +.sp +.LP +Second, the application can generate its own data buffers to occupy the gaps, +filling the gaps with values appropriate for the section being created. A +program might even use different fill values for different sections. For +example, it could set text sections' bytes to no-operation instructions, while +filling data section holes with zero. Using this technique, the library finds +no holes to fill, because the application eliminated them. +.SS "Section and Memory Types" +.sp +.LP +The \fBelf_getdata()\fR function interprets sections' data according to the +section type, as noted in the section header available through +\fBelf32_getshdr()\fR. The following table shows the section types and how the +library represents them with memory data types for the 32-bit file class. Other +classes would have similar tables. By implication, the memory data types +control translation by \fBelf32_xlatetof\fR(3ELF) +.sp + +.sp +.TS +tab(); +cw(1.83i) cw(1.83i) cw(1.83i) +lw(1.83i) lw(1.83i) lw(1.83i) +. +Section TypeElf_Type32-bit Type +\fBSHT_DYNAMIC\fR\fBELF_T_DYN\fR\fBElf32_Dyn\fR +\fBSHT_DYNSYM\fR\fBELF_T_SYM\fR\fBElf32_Sym\fR +\fBSHT_FINI_ARRAY\fR\fBELF_T_ADDR\fR\fBElf32_Addr\fR +\fBSHT_GROUP\fR\fBELF_T_WORD\fR\fBElf32_Word\fR +\fBSHT_HASH\fR\fBELF_T_WORD\fR\fBElf32_Word\fR +\fBSHT_INIT_ARRAY\fR\fBELF_T_ADDR\fR\fBElf32_Addr\fR +\fBSHT_NOBITS\fR\fBELF_T_BYTE\fR\fBunsigned char\fR +\fBSHT_NOTE\fR\fBELF_T_NOTE\fR\fBunsigned char\fR +\fBSHT_NULL\fR\fInone\fR\fInone\fR +\fBSHT_PREINIT_ARRAY\fR\fBELF_T_ADDR\fR\fBElf32_Addr\fR +\fBSHT_PROGBITS\fR\fBELF_T_BYTE\fR\fBunsigned char\fR +\fBSHT_REL\fR\fBELF_T_REL\fR\fBElf32_Rel\fR +\fBSHT_RELA\fR\fBELF_T_RELA\fR\fBElf32_Rela\fR +\fBSHT_STRTAB\fR\fBELF_T_BYTE\fR\fBunsigned char\fR +\fBSHT_SYMTAB\fR\fBELF_T_SYM\fR\fBElf32_Sym\fR +\fBSHT_SUNW_comdat\fR\fBELF_T_BYTE\fR\fBunsigned char\fR +\fBSHT_SUNW_move\fR\fBELF_T_MOVE\fR\fBElf32_Move\fR (sparc) +\fBSHT_SUNW_move\fR\fBELF_T_MOVEP\fR\fBElf32_Move\fR (ia32) +\fBSHT_SUNW_syminfo\fR\fBELF_T_SYMINFO\fR\fBElf32_Syminfo\fR +\fBSHT_SUNW_verdef\fR\fBELF_T_VDEF\fR\fBElf32_Verdef\fR +\fBSHT_SUNW_verneed\fR\fBELF_T_VNEED\fR\fBElf32_Verneed\fR +\fBSHT_SUNW_versym\fR\fBELF_T_HALF\fR\fBElf32_Versym\fR +\fIother\fR\fBELF_T_BYTE\fR\fBunsigned char\fR +.TE + +.sp +.LP +The \fBelf_rawdata()\fR function creates a buffer with type \fBELF_T_BYTE\fR. +.sp +.LP +As mentioned above, the program's working version controls what structures the +library creates for the application. The library similarly interprets section +types according to the versions. If a section type belongs to a version newer +than the application's working version, the library does not translate the +section data. Because the application cannot know the data format in this case, +the library presents an untranslated buffer of type \fBELF_T_BYTE\fR, just as +it would for an unrecognized section type. +.sp +.LP +A section with a special type, \fBSHT_NOBITS\fR, occupies no space in an object +file, even when the section header indicates a non-zero size. +\fBelf_getdata()\fR and \fBelf_rawdata()\fR work on such a section, setting the +\fIdata\fR structure to have a null buffer pointer and the type indicated +above. Although no data are present, the \fBd_size\fR value is set to the size +from the section header. When a program is creating a new section of type +\fBSHT_NOBITS\fR, it should use \fBelf_newdata()\fR to add data buffers to the +section. These empty data buffers should have the \fBd_size\fR members set to +the desired size and the \fBd_buf\fR members set to \fI NULL\fR. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample program of calling \fBelf_getdata()\fR. +.sp +.LP +The following fragment obtains the string table that holds section names +(ignoring error checking). See \fBelf_strptr\fR(3ELF) for a variation of string +table handling. + +.sp +.in +2 +.nf +ehdr = elf32_getehdr(elf); +scn = elf_getscn(elf, (size_t)ehdr->e_shstrndx); +shdr = elf32_getshdr(scn); +if (shdr->sh_type != SHT_STRTAB) +{ +/* not a string table */ +} +data = 0; +if ((data = elf_getdata(scn, data)) == 0 || data->d_size == 0) +{ +/* error or no data */ +} +.fi +.in -2 + +.sp +.LP +The \fBe_shstrndx\fR member in an \fBELF\fR header holds the section table +index of the string table. The program gets a section descriptor for that +section, verifies it is a string table, and then retrieves the data. When this +fragment finishes, \fBdata->d_buf\fR points at the first byte of the string +table, and \fBdata->d_size\fR holds the string table's size in bytes. + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf64_getehdr\fR(3ELF), +\fBelf32_getshdr\fR(3ELF), \fBelf64_getshdr\fR(3ELF), +\fBelf32_xlatetof\fR(3ELF), \fBelf64_xlatetof\fR(3ELF), \fBelf_cntl\fR(3ELF), +\fBelf_fill\fR(3ELF), \fBelf_flagdata\fR(3ELF), \fBelf_getscn\fR(3ELF), +\fBelf_rawfile\fR(3ELF), \fBelf_strptr\fR(3ELF), \fBelf_version\fR(3ELF), +\fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_getident.3elf b/usr/src/man/man3elf/elf_getident.3elf new file mode 100644 index 0000000000..f0c1bdc084 --- /dev/null +++ b/usr/src/man/man3elf/elf_getident.3elf @@ -0,0 +1,199 @@ +'\" te +.\" Copyright (c) 2009, Sun Microsystems, Inc. All Rights Reserved +.\" Copyright 1989 AT&T +.\" 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] +.TH elf_getident 3ELF "18 Jun 2009" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getident, elf_getphdrnum, elf_getshdrnum, elf_getshdrstrndx, elf_getphnum, +elf_getshnum, elf_getshstrndx \- retrieve \fBELF\fR header data +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBchar *\fR\fBelf_getident\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_getphdrnum\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_getshdrnum\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_getshdrstrndx\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.SS "Obsolete Interfaces" +.LP +.nf +\fBint\fR \fBelf_getphnum\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_getshnum\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBelf_getshstrndx\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIdst\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +As \fBelf\fR(3ELF) explains, \fBELF\fR provides a framework for various classes +of files, where basic objects might have 32 or 64 bits. To accommodate these +differences, without forcing the larger sizes on smaller machines, the initial +bytes in an \fBELF\fR file hold identification information common to all file +classes. The \fBe_ident\fR of every \fBELF\fR header has \fBEI_NIDENT\fR bytes +with interpretations described in the following table. +.sp + +.sp +.TS +tab(); +lw(1.83i) lw(1.83i) lw(1.83i) +lw(1.83i) lw(1.83i) lw(1.83i) +. +\fBe_ident Index\fR\fBValue\fR\fBPurpose\fR + +\fBEI_MAG0\fR\fBELFMAG0\fRFile identification +\fBEI_MAG1\fR\fBELFMAG1\fR +\fBEI_MAG2\fR\fBELFMAG2\fR +\fBEI_MAG3\fR\fBELFMAG3\fR + +\fBEI_CLASS\fR\fBELFCLASSNONE\fRFile class +\fBELFCLASS32\fR +\fBELFCLASS64\fR + +\fBEI_DATA\fR\fBELFDATANONE\fRData encoding +\fBELFDATA2LSB\fR +\fBELFDATA2MSB\fR + +\fBEI_VERSION\fR\fBEV_CURRENT\fRFile version + +7-150Unused, set to zero +.TE + +.sp +.LP +Other kinds of files might have identification data, though they would not +conform to \fBe_ident\fR. See \fBelf_kind\fR(3ELF) for information on other +kinds of files. +.sp +.LP +The \fBelf_getident()\fR function returns a pointer to the initial bytes of the +file. If the library recognizes the file, a conversion from the file image to +the memory image can occur. The identification bytes are guaranteed to be +unmodified, though the size of the unmodified area depends on the file type. If +the \fIdst\fR argument is non-null, the library stores the number of +identification bytes in the location to which \fIdst\fR points. If no data are +present, \fIelf\fR is \fINULL\fR, or an error occurs, the return value is a +null pointer, with \fB0\fR stored through \fIdst\fR, if \fIdst\fR is non-null. +.sp +.LP +The \fBelf_getphdrnum()\fR function obtains the number of program headers +recorded in the \fBELF\fR file. The number of sections in a file is typically +recorded in the \fBe_phnum\fR field of the \fBELF\fR header. A file that +requires the \fBELF\fR extended program header records the value \fBPN_XNUM\fR +in the \fBe_phnum\fR field and records the number of sections in the +\fBsh_info\fR field of section header 0. See USAGE. The \fIdst\fR argument +points to the location where the number of sections is stored. If \fIelf\fR is +\fINULL\fR or an error occurs, \fBelf_getphdrnum()\fR returns \fB\(mi1\fR\&. +.sp +.LP +The \fBelf_getshdrnum()\fR function obtains the number of sections recorded in +the \fBELF\fR file. The number of sections in a file is typically recorded in +the \fBe_shnum\fR field of the \fBELF\fR header. A file that requires \fBELF\fR +extended section records the value \fB0\fR in the \fBe_shnum\fR field and +records the number of sections in the \fBsh_size\fR field of section header 0. +See USAGE. The \fIdst\fR argument points to the location where the number of +sections is stored. If a call to \fBelf_newscn\fR(3ELF) that uses the same +\fIelf\fR descriptor is performed, the value obtained by \fBelf_getshnum()\fR +is valid only after a successful call to \fBelf_update\fR(3ELF). If \fIelf\fR +is \fINULL\fR or an error occurs, \fBelf_getshdrnum()\fR returns \fB\(mi1\fR\&. +.sp +.LP +The \fBelf_getshdrstrndx()\fR function obtains the section index of the string +table associated with the section headers in the \fBELF\fR file. The section +header string table index is typically recorded in the \fBe_shstrndx\fR field +of the \fBELF\fR header. A file that requires \fBELF\fR extended section +records the value \fBSHN_XINDEX\fR in the \fBe_shstrndx\fR field and records +the string table index in the \fBsh_link\fR field of section header 0. See +USAGE. The \fIdst\fR argument points to the location where the section header +string table index is stored. If \fIelf\fR is \fINULL\fR or an error occurs, +\fBelf_getshdrstrndx()\fR returns \fB\(mi1\fR\&. +.sp +.LP +The \fBelf_getphnum()\fR, \fBelf_getshnum()\fR, and \fBelf_getshstrndx()\fR +functions behave in a manner similar to \fBelf_getphdrnum()\fR, +\fBelf_getshdrnum()\fR, and \fBelf_getshdrstrndx()\fR, respectively, except +that they return 0 if \fIelf\fR is \fINULL\fR or an error occurs. Because these +return values differ from those used by some other systems, they are therefore +non-portable and their use is discouraged. The \fBelf_getphdrnum()\fR, +\fBelf_getshdrnum()\fR, and \fBelf_getshdrstrndx()\fR functions should be used +instead. +.SH USAGE +.sp +.LP +ELF extended sections allow an ELF file to contain more than \fB0xff00\fR +(\fBSHN_LORESERVE\fR) section. ELF extended program headers allow an ELF file +to contain \fB0xffff\fR (\fBPN_XNUM\fR) or more program headers. See the +\fILinker and Libraries Guide\fR for more information. +.SH RETURN VALUES +.sp +.LP +Upon successful completion, the \fBelf_getident()\fR function returns 1. +Otherwise, it return 0. +.sp +.LP +Upon successful completion, the \fBelf_getphdrnum()\fR, \fBelf_getshdrnum()\fR, +and \fBelf_getshdrstrndx()\fR functions return 0. Otherwise, they return -1. +.sp +.LP +Upon successful completion, the \fBelf_getphnum()\fR, \fBelf_getshnum()\fR, and +\fBelf_getshstrndx()\fR functions return 1. Otherwise, they return 0. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilitySee below. +_ +MT-LevelMT-Safe +.TE + +.sp +.LP +The \fBelf_getident()\fR, \fBelf_getphdrnum()\fR, \fBelf_getshdrnum()\fR, and +\fBelf_getshdrstrndx()\fR functions are Committed. The \fBelf_getphnum()\fR, +\fBelf_getshnum()\fR, and \fBelf_getshstrndx()\fR functions are Committed +(Obsolete). +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_kind\fR(3ELF), \fBelf_newscn\fR(3ELF), \fBelf_rawfile\fR(3ELF), +\fBelf_update\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) +.sp +.LP +\fILinker and Libraries Guide\fR diff --git a/usr/src/man/man3elf/elf_getscn.3elf b/usr/src/man/man3elf/elf_getscn.3elf new file mode 100644 index 0000000000..8f0bf6640d --- /dev/null +++ b/usr/src/man/man3elf/elf_getscn.3elf @@ -0,0 +1,124 @@ +'\" 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] +.TH elf_getscn 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_getscn, elf_ndxscn, elf_newscn, elf_nextscn \- get section information +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf_Scn *\fR\fBelf_getscn\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIindex\fR); +.fi + +.LP +.nf +\fBsize_t\fR \fBelf_ndxscn\fR(\fBElf_Scn *\fR\fIscn\fR); +.fi + +.LP +.nf +\fBElf_Scn *\fR\fBelf_newscn\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBElf_Scn *\fR\fBelf_nextscn\fR(\fBElf *\fR\fIelf\fR, \fBElf_Scn *\fR\fIscn\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +These functions provide indexed and sequential access to the sections +associated with the \fBELF\fR descriptor \fIelf\fR. If the program is building +a new file, it is responsible for creating the file's \fBELF\fR header before +creating sections; see \fBelf32_getehdr\fR(3ELF). +.sp +.LP +The \fBelf_getscn()\fR function returns a section descriptor, given an +\fIindex\fR into the file's section header table. Note that the first ``real'' +section has an index of \fB1\fR. Although a program can get a section +descriptor for the section whose \fIindex\fR is \fB0\fR (\fBSHN_UNDEF\fR, the +undefined section), the section has no data and the section header is ``empty'' +(though present). If the specified section does not exist, an error occurs, or +\fIelf\fR is \fINULL\fR, \fBelf_getscn()\fR returns a null pointer. +.sp +.LP +The \fBelf_newscn()\fR function creates a new section and appends it to the +list for \fIelf\fR. Because the \fBSHN_UNDEF\fR section is required and not +``interesting'' to applications, the library creates it automatically. Thus the +first call to \fBelf_newscn()\fR for an \fBELF\fR descriptor with no existing +sections returns a descriptor for section 1. If an error occurs or \fIelf\fR is +\fINULL\fR, \fBelf_newscn()\fR returns a null pointer. +.sp +.LP +After creating a new section descriptor, the program can use +\fBelf32_getshdr()\fR to retrieve the newly created, ``clean'' section header. +The new section descriptor will have no associated data (see +\fBelf_getdata\fR(3ELF)). When creating a new section in this way, the library +updates the \fBe_shnum\fR member of the \fBELF\fR header and sets the +\fBELF_F_DIRTY\fR bit for the section (see \fBelf_flagdata\fR(3ELF)). If the +program is building a new file, it is responsible for creating the file's +\fBELF\fR header (see \fBelf32_getehdr\fR(3ELF)) before creating new sections. +.sp +.LP +The \fBelf_nextscn()\fR function takes an existing section descriptor, +\fIscn\fR, and returns a section descriptor for the next higher section. One +may use a null \fIscn\fR to obtain a section descriptor for the section whose +index is \fB1\fR (skipping the section whose index is \fBSHN_UNDEF\fR). If no +further sections are present or an error occurs, \fBelf_nextscn()\fR returns a +null pointer. +.sp +.LP +The \fBelf_ndxscn()\fR function takes an existing section descriptor, +\fIscn\fR, and returns its section table index. If \fIscn\fR is null or an +error occurs, \fBelf_ndxscn()\fR returns \fBSHN_UNDEF\fR. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample of calling \fBelf_getscn()\fR function. +.sp +.LP +An example of sequential access appears below. Each pass through the loop +processes the next section in the file; the loop terminates when all sections +have been processed. + +.sp +.in +2 +.nf +\fBscn = 0; +while ((scn = elf_nextscn(elf, scn)) != 0) +{ + /* process section */ +}\fR +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf32_getshdr\fR(3ELF), +\fBelf_begin\fR(3ELF), \fBelf_flagdata\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_hash.3elf b/usr/src/man/man3elf/elf_hash.3elf new file mode 100644 index 0000000000..ae5ccb0d95 --- /dev/null +++ b/usr/src/man/man3elf/elf_hash.3elf @@ -0,0 +1,60 @@ +'\" 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] +.TH elf_hash 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_hash \- compute hash value +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBunsigned long\fR \fBelf_hash\fR(\fBconst char *\fR\fIname\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_hash()\fR function computes a hash value, given a null terminated +string, \fIname\fR. The returned hash value, \fIh\fR, can be used as a bucket +index, typically after computing \fIh \fRmod x to ensure appropriate bounds. +.sp +.LP +Hash tables may be built on one machine and used on another because +\fBelf_hash()\fR uses unsigned arithmetic to avoid possible differences in +various machines' signed arithmetic. Although \fIname\fR is shown as +\fBchar*\fR above, \fBelf_hash()\fR treats it as \fBunsigned char*\fR to avoid +sign extension differences. Using \fBchar*\fR eliminates type conflicts with +expressions such as \fBelf_hash(\fR\fIname\fR\fB).\fR +.sp +.LP +\fBELF\fR files' symbol hash tables are computed using this function (see +\fBelf_getdata\fR(3ELF) and \fBelf32_xlatetof\fR(3ELF)). The hash value +returned is guaranteed not to be the bit pattern of all ones ( \fB~0UL\fR). +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_getdata\fR(3ELF), +\fBlibelf\fR(3LIB), \fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_kind.3elf b/usr/src/man/man3elf/elf_kind.3elf new file mode 100644 index 0000000000..f3d2f99753 --- /dev/null +++ b/usr/src/man/man3elf/elf_kind.3elf @@ -0,0 +1,102 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_kind 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_kind \- determine file type +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBElf_Kind\fR \fBelf_kind\fR(\fBElf *\fR\fIelf\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +This function returns a value identifying the kind of file associated with an +\fBELF\fR descriptor (\fIelf\fR). Defined values are below: +.sp +.ne 2 +.mk +.na +\fB\fBELF_K_AR\fR\fR +.ad +.RS 14n +.rt +The file is an archive [see \fBar.h\fR(3HEAD)]. An \fBELF\fR descriptor may +also be associated with an archive \fImember\fR, not the archive itself, and +then \fBelf_kind()\fR identifies the member's type. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_K_COFF\fR\fR +.ad +.RS 14n +.rt +The file is a \fBCOFF\fR object file. \fBelf_begin\fR(3ELF) describes the +library's handling for \fBCOFF\fR files. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_K_ELF\fR\fR +.ad +.RS 14n +.rt +The file is an \fBELF\fR file. The program may use \fBelf_getident()\fR to +determine the class. Other functions, such as \fBelf32_getehdr()\fR, are +available to retrieve other file information. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_K_NONE\fR\fR +.ad +.RS 14n +.rt +This indicates a kind of file unknown to the library. +.RE + +.sp +.LP +Other values are reserved, to be assigned as needed to new kinds of files. +\fIelf\fR should be a value previously returned by \fBelf_begin()\fR. A null +pointer is allowed, to simplify error handling, and causes \fBelf_kind()\fR to +return \fBELF_K_NONE\fR. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBar.h\fR(3HEAD), \fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), +\fBelf_begin\fR(3ELF), \fBelf_getident\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) diff --git a/usr/src/man/man3elf/elf_rawfile.3elf b/usr/src/man/man3elf/elf_rawfile.3elf new file mode 100644 index 0000000000..84bc2de4fe --- /dev/null +++ b/usr/src/man/man3elf/elf_rawfile.3elf @@ -0,0 +1,87 @@ +'\" 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] +.TH elf_rawfile 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_rawfile \- retrieve uninterpreted file contents +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBchar *\fR\fBelf_rawfile\fR(\fBElf *\fR\fIelf\fR, \fBsize_t *\fR\fIptr\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_rawfile()\fR function returns a pointer to an uninterpreted byte +image of the file. This function should be used only to retrieve a file being +read. For example, a program might use \fBelf_rawfile()\fR to retrieve the +bytes for an archive member. +.sp +.LP +A program may not close or disable (see \fBelf_cntl\fR(3ELF)) the file +descriptor associated with \fIelf\fR before the initial call to +\fBelf_rawfile()\fR \fB,\fR because \fBelf_rawfile()\fR might have to read the +data from the file if it does not already have the original bytes in memory. +Generally, this function is more efficient for unknown file types than for +object files. The library implicitly translates object files in memory, while +it leaves unknown files unmodified. Thus, asking for the uninterpreted image of +an object file may create a duplicate copy in memory. +.sp +.LP +\fBelf_rawdata()\fR is a related function, providing access to sections within +a file. See \fBelf_getdata\fR(3ELF). +.sp +.LP +If \fIptr\fR is non-null, the library also stores the file's size, in bytes, in +the location to which \fIptr\fR points. If no data are present, \fIelf\fR is +null, or an error occurs, the return value is a null pointer, with \fB0\fR +stored through \fIptr\fR, if \fIptr\fR is non-null. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getehdr\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_cntl\fR(3ELF), \fBelf_getdata\fR(3ELF), \fBelf_getident\fR(3ELF), +\fBelf_kind\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) +.SH NOTES +.sp +.LP +A program that uses \fBelf_rawfile()\fR and that also interprets the same file +as an object file potentially has two copies of the bytes in memory. If such a +program requests the raw image first, before it asks for translated information +(through such functions as \fBelf32_getehdr()\fR, \fBelf_getdata()\fR, and so +on), the library ``freezes'' its original memory copy for the raw image. It +then uses this frozen copy as the source for creating translated objects, +without reading the file again. Consequently, the application should view the +raw file image returned by \fBelf_rawfile()\fR as a read-only buffer, unless it +wants to alter its own view of data subsequently translated. In any case, the +application may alter the translated objects without changing bytes visible in +the raw image. +.sp +.LP +Multiple calls to \fBelf_rawfile()\fR with the same \fBELF\fR descriptor return +the same value; the library does not create duplicate copies of the file. diff --git a/usr/src/man/man3elf/elf_strptr.3elf b/usr/src/man/man3elf/elf_strptr.3elf new file mode 100644 index 0000000000..930b3980ef --- /dev/null +++ b/usr/src/man/man3elf/elf_strptr.3elf @@ -0,0 +1,84 @@ +'\" 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] +.TH elf_strptr 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_strptr \- make a string pointer +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBchar *\fR\fBelf_strptr\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIsection\fR, \fBsize_t\fR \fIoffset\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_strptr()\fR function converts a string section \fIoffset\fR to a +string pointer. \fIelf\fR identifies the file in which the string section +resides, and \fIsection\fR identifies the section table index for the strings. +\fBelf_strptr()\fR normally returns a pointer to a string, but it returns a +null pointer when \fIelf\fR is null, \fIsection\fR is invalid or is not a +section of type \fBSHT_STRTAB\fR, the section data cannot be obtained, +\fIoffset\fR is invalid, or an error occurs. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample program of calling \fBelf_strptr()\fR function. +.sp +.LP +A prototype for retrieving section names appears below. The file header +specifies the section name string table in the \fBe_shstrndx\fR member. The +following code loops through the sections, printing their names. + +.sp +.in +2 +.nf +\fB/* handle the error */ +if ((ehdr = elf32_getehdr(elf)) == 0) { + return; +} +ndx = ehdr->e_shstrndx; +scn = 0; +while ((scn = elf_nextscn(elf, scn)) != 0) { + char *name = 0; + if ((shdr = elf32_getshdr(scn)) != 0) + name = elf_strptr(elf, ndx, (size_t)shdr->sh_name); + printf("'%s'\en", name? name: "(null)"); +}\fR +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), +\fBelf_getdata\fR(3ELF), \fBlibelf\fR(3LIB), \fBattributes\fR(5) +.SH NOTES +.sp +.LP +A program may call \fBelf_getdata()\fR to retrieve an entire string table +section. For some applications, that would be both more efficient and more +convenient than using \fBelf_strptr()\fR. diff --git a/usr/src/man/man3elf/elf_update.3elf b/usr/src/man/man3elf/elf_update.3elf new file mode 100644 index 0000000000..112e53459b --- /dev/null +++ b/usr/src/man/man3elf/elf_update.3elf @@ -0,0 +1,230 @@ +'\" te +.\" Copyright 1989 AT&T Copyright (c) 1996, 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] +.TH elf_update 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_update \- update an ELF descriptor +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBoff_t\fR \fBelf_update\fR(\fBElf *\fR\fIelf\fR, \fBElf_Cmd\fR \fIcmd\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +The \fBelf_update()\fR function causes the library to examine the information +associated with an \fBELF\fR descriptor, \fIelf\fR, and to recalculate the +structural data needed to generate the file's image. +.sp +.LP +The \fIcmd\fR argument can have the following values: +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_NULL\fR\fR +.ad +.RS 15n +.rt +This value tells \fBelf_update()\fR to recalculate various values, updating +only the \fBELF\fR descriptor's memory structures. Any modified structures are +flagged with the \fBELF_F_DIRTY\fR bit. A program thus can update the +structural information and then reexamine them without changing the file +associated with the \fBELF\fR descriptor. Because this does not change the +file, the \fBELF\fR descriptor may allow reading, writing, or both reading and +writing (see \fBelf_begin\fR(3ELF)). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBELF_C_WRITE\fR\fR +.ad +.RS 15n +.rt +If \fIcmd\fR has this value, \fBelf_update()\fR duplicates its \fBELF_C_NULL\fR +actions and also writes any ``dirty'' information associated with the \fBELF\fR +descriptor to the file. That is, when a program has used +\fBelf_getdata\fR(3ELF) or the \fBelf_flagdata\fR(3ELF) facilities to supply +new (or update existing) information for an \fBELF\fR descriptor, those data +will be examined, coordinated, translated if necessary (see +\fBelf32_xlatetof\fR(3ELF)), and written to the file. When portions of the file +are written, any \fBELF_F_DIRTY\fR bits are reset, indicating those items no +longer need to be written to the file (see \fBelf_flagdata\fR(3ELF)). The +sections' data are written in the order of their section header entries, and +the section header table is written to the end of the file. When the \fBELF\fR +descriptor was created with \fBelf_begin()\fR, it must have allowed writing the +file. That is, the \fBelf_begin()\fR command must have been either +\fBELF_C_RDWR\fR or \fBELF_C_WRITE\fR. +.RE + +.sp +.LP +If \fBelf_update()\fR succeeds, it returns the total size of the file image +(not the memory image), in bytes. Otherwise an error occurred, and the function +returns \fB\(mi1\fR\&. +.sp +.LP +When updating the internal structures, \fBelf_update()\fR sets some members +itself. Members listed below are the application's responsibility and retain +the values given by the program. +.sp +.LP +The following table shows ELF Header members: +.sp + +.sp +.TS +tab(); +lw(1.65i) lw(3.85i) +lw(1.65i) lw(3.85i) +. +MemberNotes + +e_ident[EI_DATA]Library controls other \fBe_ident\fR values +e_type +e_machine +e_version +e_entry +e_phoffOnly when \fBELF_F_LAYOUT\fR asserted +e_shoffOnly when \fBELF_F_LAYOUT\fR asserted +e_flags +e_shstrndx +.TE + +.sp +.LP +The following table shows the Program Header members: +.sp + +.sp +.TS +tab(); +lw(1.65i) lw(3.85i) +lw(1.65i) lw(3.85i) +. +MemberNotes + +p_typeThe application controls all +p_offsetprogram header entries +p_vaddr +p_paddr +p_filesz +p_memsz +p_flags +p_align +.TE + +.sp +.LP +The following table shows the Section Header members: +.sp + +.sp +.TS +tab(); +lw(1.65i) lw(3.85i) +lw(1.65i) lw(3.85i) +. +MemberNotes + +sh_name +sh_type +sh_flags +sh_addr +sh_offsetOnly when \fBELF_F_LAYOUT\fR asserted +sh_sizeOnly when \fBELF_F_LAYOUT\fR asserted +sh_link +sh_info +sh_addralignOnly when \fBELF_F_LAYOUT\fR asserted +sh_entsize +.TE + +.sp +.LP +The following table shows the Data Descriptor members: +.sp + +.sp +.TS +tab(); +lw(1.65i) lw(3.85i) +lw(1.65i) lw(3.85i) +. +MemberNotes + +d_buf +d_type +d_size +d_offOnly when \fBELF_F_LAYOUT\fR asserted +d_align +d_version +.TE + +.sp +.LP +Note that the program is responsible for two particularly important members +(among others) in the \fBELF\fR header. The \fBe_version\fR member controls the +version of data structures written to the file. If the version is +\fBEV_NONE\fR, the library uses its own internal version. The +\fBe_ident[EI_DATA]\fR entry controls the data encoding used in the file. As a +special case, the value may be \fBELFDATANONE\fR to request the native data +encoding for the host machine. An error occurs in this case if the native +encoding doesn't match a file encoding known by the library. +.sp +.LP +Further note that the program is responsible for the \fBsh_entsize\fR section +header member. Although the library sets it for sections with known types, it +cannot reliably know the correct value for all sections. Consequently, the +library relies on the program to provide the values for unknown section types. +If the entry size is unknown or not applicable, the value should be set to +\fB0\fR. +.sp +.LP +When deciding how to build the output file, \fBelf_update()\fR obeys the +alignments of individual data buffers to create output sections. A section's +most strictly aligned data buffer controls the section's alignment. The library +also inserts padding between buffers, as necessary, to ensure the proper +alignment of each buffer. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_fsize\fR(3ELF), \fBelf32_getehdr\fR(3ELF), +\fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBelf_flagdata\fR(3ELF), \fBelf_getdata\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) +.SH NOTES +.sp +.LP +As mentioned above, the \fBELF_C_WRITE\fR command translates data as necessary, +before writing them to the file. This translation is \fInot\fR always +transparent to the application program. If a program has obtained pointers to +data associated with a file (for example, see \fBelf32_getehdr\fR(3ELF) and +\fBelf_getdata\fR(3ELF)), the program should reestablish the pointers after +calling \fBelf_update()\fR. diff --git a/usr/src/man/man3elf/elf_version.3elf b/usr/src/man/man3elf/elf_version.3elf new file mode 100644 index 0000000000..4a43c9e93d --- /dev/null +++ b/usr/src/man/man3elf/elf_version.3elf @@ -0,0 +1,88 @@ +'\" 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] +.TH elf_version 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +elf_version \- coordinate ELF library and application versions +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR ... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <libelf.h> + +\fBunsigned\fR \fBelf_version\fR(\fBunsigned\fR \fIver\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +As \fBelf\fR(3ELF) explains, the program, the library, and an object file have +independent notions of the latest \fBELF\fR version. \fBelf_version()\fR lets a +program query the \fBELF\fR library's \fIinternal version\fR. It further lets +the program specify what memory types it uses by giving its own \fIworking +version\fR, \fBver\fR, to the library. Every program that uses the \fBELF\fR +library must coordinate versions as described below. +.sp +.LP +The header <\fBlibelf.h\fR> supplies the version to the program with the macro +\fBEV_CURRENT\fR. If the library's internal version (the highest version known +to the library) is lower than that known by the program itself, the library may +lack semantic knowledge assumed by the program. Accordingly, +\fBelf_version()\fR will not accept a working version unknown to the library. +.sp +.LP +Passing \fIver\fR equal to \fBEV_NONE\fR causes \fBelf_version()\fR to return +the library's internal version, without altering the working version. If +\fBver\fR is a version known to the library, \fBelf_version()\fR returns the +previous (or initial) working version number. Otherwise, the working version +remains unchanged and \fBelf_version()\fR returns \fBEV_NONE\fR. +.SH EXAMPLES +.LP +\fBExample 1 \fRA sample display of using the \fBelf_version()\fR function. +.sp +.LP +The following excerpt from an application program protects itself from using an +older library: + +.sp +.in +2 +.nf +\fBif (elf_version(EV_CURRENT) == EV_NONE) { + /* library out of date */ + /* recover from error */ +}\fR +.fi +.in -2 + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), \fBelf_begin\fR(3ELF), +\fBlibelf\fR(3LIB), \fBattributes\fR(5) +.SH NOTES +.sp +.LP +The working version should be the same for all operations on a particular +\fBELF\fR descriptor. Changing the version between operations on a descriptor +will probably not give the expected results. diff --git a/usr/src/man/man3elf/gelf.3elf b/usr/src/man/man3elf/gelf.3elf new file mode 100644 index 0000000000..61ec1b886e --- /dev/null +++ b/usr/src/man/man3elf/gelf.3elf @@ -0,0 +1,685 @@ +'\" te +.\" Copyright (c) 2004, 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] +.TH gelf 3ELF "8 June 2004" "SunOS 5.11" "ELF Library Functions" +.SH NAME +gelf, gelf_checksum, gelf_fsize, gelf_getcap, gelf_getclass, gelf_getdyn, +gelf_getehdr, gelf_getmove, gelf_getphdr, gelf_getrel, gelf_getrela, +gelf_getshdr, gelf_getsym, gelf_getsyminfo, gelf_getsymshndx, gelf_newehdr, +gelf_newphdr, gelf_update_cap, gelf_update_dyn, gelf_update_ehdr, +gelf_update_getmove, gelf_update_move, gelf_update_phdr, gelf_update_rel, +gelf_update_rela, gelf_update_shdr, gelf_update_sym, gelf_update_symshndx, +gelf_update_syminfo, gelf_xlatetof, gelf_xlatetom \- generic class-independent +ELF interface +.SH SYNOPSIS +.LP +.nf +\fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB\(milelf\fR [ \fIlibrary\fR... ] +#include <gelf.h> + +\fBlong\fR \fBgelf_checksum\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBsize_t\fR \fBgelf_fsize\fR(\fBElf *\fR\fIelf\fR, \fBElf_Type\fR \fItype\fR, \fBsize_t\fR \fIcnt\fR, \fBunsigned\fR \fIver\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_getcap\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Cap *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_getclass\fR(\fBElf *\fR\fIelf\fR); +.fi + +.LP +.nf +\fBGElf_Dyn *\fR\fBgelf_getdyn\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Dyn *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Ehdr *\fR\fBgelf_getehdr\fR(\fBElf *\fR\fIelf\fR, \fBGElf_Ehdr *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Move *\fR\fBgelf_getmove\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Move *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Phdr *\fR\fBgelf_getphdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIndx\fR, \fBGElf_Phdr *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Rel *\fR\fBgelf_getrel\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Rel *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Rela *\fR\fBgelf_getrela\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Rela *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Shdr *\fR\fBgelf_getshdr\fR(\fBElf_Scn *\fR\fIscn\fR, \fBGElf_Shdr *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Sym *\fR\fBgelf_getsym\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Syminfo *\fR\fBgelf_getsyminfo\fR(\fBElf_Data *\fR\fIsrc\fR, \fBint\fR \fIndx\fR, \fBGElf_Syminfo *\fR\fIdst\fR); +.fi + +.LP +.nf +\fBGElf_Sym *\fR\fBgelf_getsymshndx\fR(\fBElf_Data *\fR\fIsymsrc\fR, \fBElf_Data *\fR\fIshndxsrc\fR, + \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIsymdst\fR, \fBElf32_Word *\fR\fIshndxdst\fR); +.fi + +.LP +.nf +\fBunsigned long\fR \fBgelf_newehdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIclass\fR); +.fi + +.LP +.nf +\fBunsigned long\fR \fBgelf_newphdr\fR(\fBElf *\fR\fIelf\fR, \fBsize_t\fR \fIphnum\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_cap\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Cap *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_dyn\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Dyn *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_ehdr\fR(\fBElf *\fR\fIelf\fR, \fBGElf_Ehdr *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_move\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Move *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_phdr\fR(\fBElf *\fR\fIelf\fR, \fBint\fR \fIndx\fR, \fBGElf_Phdr *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_rel\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Rel *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_rela\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Rela *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_shdr\fR(\fBElf_Scn *\fR\fIdst\fR, \fBGElf_Shdr *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_sym\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Sym *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_syminfo\fR(\fBElf_Data *\fR\fIdst\fR, \fBint\fR \fIndx\fR, \fBGElf_Syminfo *\fR\fIsrc\fR); +.fi + +.LP +.nf +\fBint\fR \fBgelf_update_symshndx\fR(\fBElf_Data *\fR\fIsymdst\fR, \fBElf_Data *\fR\fIshndxdst\fR, \fBint\fR \fIndx\fR, + \fBGElf_Sym *\fR\fIsymsrc\fR, \fBElf32_Word\fR \fIshndxsrc\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBgelf_xlatetof\fR(\fBElf *\fR\fIelf\fR, \fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.LP +.nf +\fBElf_Data *\fR\fBgelf_xlatetom\fR(\fBElf *\fR\fIelf\fR, \fBElf_Data *\fR\fIdst\fR, \fBconst Elf_Data *\fR\fIsrc\fR, + \fBunsigned\fR \fIencode\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBGElf\fR is a generic, \fBELF\fR class-independent \fBAPI\fR for manipulating +\fBELF\fR object files. \fBGElf\fR provides a single, common interface for +handling 32-bit and 64-bit \fBELF\fR format object files. \fBGElf\fR is a +translation layer between the application and the class-dependent parts of the +\fBELF\fR library. Thus, the application can use \fBGElf\fR, which in turn, +will call the corresponding \fBelf32_\fR or \fBelf64_\fR functions on behalf of +the application. The data structures returned are all large enough to hold +32-bit and 64-bit data. +.sp +.LP +\fBGElf\fR provides a simple, class-independent layer of indirection over the +class-dependent \fBELF32\fR and \fBELF64\fR \fBAPI\fR's. \fBGElf\fR is +stateless, and may be used along side the \fBELF32\fR and \fBELF64\fR +\fBAPI\fR's. +.sp +.LP +\fBGElf\fR always returns a copy of the underlying \fBELF32\fR or \fBELF64\fR +structure, and therefore the programming practice of using the address of an +\fBELF\fR header as the base offset for the \fBELF\fR's mapping into memory +should be avoided. Also, data accessed by type-casting the \fBElf_Data\fR +buffer to a class-dependent type and treating it like an array, for example, a +symbol table, will not work under \fBGElf\fR, and the \fBgelf_get\fR functions +must be used instead. See the EXAMPLE section. +.sp +.LP +Programs that create or modify \fBELF\fR files using \fBlibelf\fR(3LIB) need to +perform an extra step when using \fBGElf\fR. Modifications to \fBGElf\fR values +must be explicitly flushed to the underlying \fBELF32\fR or \fBELF64\fR +structures by way of the \fBgelf_update_\fR interfaces. Use of \fBelf_update\fR +or \fBelf_flagelf\fR and the like remains the same. +.sp +.LP +The sizes of versioning structures remain the same between \fBELF32\fR and +\fBELF64\fR. The \fBGElf\fR \fBAPI\fR only defines types for versioning, rather +than a functional \fBAPI\fR. The processing of versioning information will stay +the same in the \fBGElf\fR environment as it was in the class-dependent +\fBELF\fR environment. +.SS "List of Functions" +.sp +.ne 2 +.mk +.na +\fB\fBgelf_checksum()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_checksum\fR(3ELF) and \fBelf64_checksum\fR(3ELF). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_fsize()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_fsize\fR(3ELF) and \fBelf64_fsize\fR(3ELF). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getcap()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Cap\fR or \fBElf64_Cap\fR information from the +capability table at the given index. \fBdst\fR points to the location where the +\fBGElf_Cap\fR capability entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getclass()\fR\fR +.ad +.RS 26n +.rt +Returns one of the constants \fBELFCLASS32\fR, \fBELFCLASS64\fR or +\fBELFCLASSNONE\fR. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getdyn()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Dyn\fR or \fBElf64_Dyn\fR information from the dynamic +table at the given index. \fBdst\fR points to the location where the +\fBGElf_Dyn\fR dynamic entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getehdr()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_getehdr\fR(3ELF) and \fBelf64_getehdr\fR(3ELF). \fBdst\fR +points to the location where the \fBGElf_Ehdr\fR header is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getmove()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Move\fR or \fBElf64_Move\fR information from the move +table at the given index. \fBdst\fR points to the location where the +\fBGElf_Move\fR move entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getphdr()\fR\fR +.ad +.RS 26n +.rt +An analog to\fBelf32_getphdr\fR(3ELF) and \fBelf64_getphdr\fR(3ELF). \fBdst\fR +points to the location where the \fBGElf_Phdr\fR program header is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getrel()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Rel\fR or \fBElf64_Rel\fR information from the +relocation table at the given index. \fBdst\fR points to the location where the +\fBGElf_Rel\fR relocation entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getrela()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Rela\fR or \fBElf64_Rela\fR information from the +relocation table at the given index. \fBdst\fR points to the location where the +\fBGElf_Rela\fR relocation entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getshdr()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_getshdr\fR(3ELF) and \fBelf64_getshdr\fR(3ELF). \fBdst\fR +points to the location where the \fBGElf_Shdr\fR section header is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getsym()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Sym\fR or \fBElf64_Sym\fR information from the symbol +table at the given index. \fBdst\fR points to the location where the +\fBGElf_Sym\fR symbol entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getsyminfo()\fR\fR +.ad +.RS 26n +.rt +Retrieves the \fBElf32_Syminfo\fR or \fBElf64_Syminfo\fR information from the +relocation table at the given index. \fBdst\fR points to the location where the +\fBGElf_Syminfo\fR symbol information entry is stored. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_getsymshndx()\fR\fR +.ad +.RS 26n +.rt +Provides an extension to \fBgelf_getsym()\fR that retrieves the \fBElf32_Sym\fR +or \fBElf64_Sym\fR information, and the section index from the symbol table at +the given index \fIndx\fR. +.sp +The symbols section index is typically recorded in the \fBst_shndx\fR field of +the symbols structure. However, a file that requires \fBELF\fR Extended +Sections may record an \fBst_shndx\fR of \fBSHN_XINDEX\fR indicating that the +section index must be obtained from an associated \fBSHT_SYMTAB_SHNDX\fR +section entry. If \fIxshndx\fR and \fIshndxdata\fR are non-null, the value +recorded at index \fIndx\fR of the \fBSHT_SYMTAB_SHNDX\fR table pointed to by +\fIshndxdata\fR is returned in \fIxshndx\fR. See USAGE. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_newehdr()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_newehdr\fR(3ELF) and \fBelf64_newehdr\fR(3ELF). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_newphdr()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_newphdr\fR(3ELF) and \fBelf64_newphdr\fR(3ELF). +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_cap()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Cap\fR information back into the underlying \fBElf32_Cap\fR +or \fBElf64_Cap\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_dyn()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Dyn\fR information back into the underlying \fBElf32_Dyn\fR +or \fBElf64_Dyn\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_ehdr()\fR\fR +.ad +.RS 26n +.rt +Copies the contents of the \fBGElf_Ehdr\fR \fBELF\fR header to the underlying +\fBElf32_Ehdr\fR or \fBElf64_Ehdr\fR structure. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_move()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Move\fR information back into the underlying +\fBElf32_Move\fR or \fBElf64_Move\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_phdr()\fR\fR +.ad +.RS 26n +.rt +Copies of the contents of \fBGElf_Phdr\fR program header to underlying the +\fBElf32_Phdr\fR or \fBElf64_Phdr\fR structure. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_rel()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Rel\fR information back into the underlying \fBElf32_Rel\fR +or \fBElf64_Rel\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_rela()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Rela\fR information back into the underlying +\fBElf32_Rela\fR or \fBElf64_Rela\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_shdr()\fR\fR +.ad +.RS 26n +.rt +Copies of the contents of \fBGElf_Shdr\fR section header to underlying the +\fBElf32_Shdr\fR or \fBElf64_Shdr\fR structure. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_sym()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Sym\fR information back into the underlying \fBElf32_Sym\fR +or \fBElf64_Sym\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_syminfo()\fR\fR +.ad +.RS 26n +.rt +Copies the \fBGElf_Syminfo\fR information back into the underlying +\fBElf32_Syminfo\fR or \fBElf64_Syminfo\fR structure at the given index. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_update_symshndx()\fR\fR +.ad +.RS 26n +.rt +Provides an extension to \fBgelf_update_sym()\fR that copies the \fBGElf_Sym\fR +information back into the \fBElf32_Sym\fR or \fBElf64_Sym\fR structure at the +given index \fIndx\fR, and copies the extended \fIxshndx\fR section index into +the \fBElf32_Word\fR at the given index \fIndx\fR in the buffer described by +\fBshndxdata\fR. See USAGE. +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_xlatetof()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_xlatetof\fR(3ELF) and \fBelf64_xlatetof\fR(3ELF) +.RE + +.sp +.ne 2 +.mk +.na +\fB\fBgelf_xlatetom()\fR\fR +.ad +.RS 26n +.rt +An analog to \fBelf32_xlatetom\fR(3ELF) and \fBelf64_xlatetom\fR(3ELF) +.RE + +.SH RETURN VALUES +.sp +.LP +Upon failure, all \fBGElf\fR functions return \fB0\fR and set \fIelf_errno\fR. +See \fBelf_errno\fR(3ELF) +.SH EXAMPLES +.LP +\fBExample 1 \fRPrinting the ELF Symbol Table +.sp +.in +2 +.nf +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <libelf.h> +#include <gelf.h> + +void +main(int argc, char **argv) +{ + Elf *elf; + Elf_Scn *scn = NULL; + GElf_Shdr shdr; + Elf_Data *data; + int fd, ii, count; + + elf_version(EV_CURRENT); + + fd = open(argv[1], O_RDONLY); + elf = elf_begin(fd, ELF_C_READ, NULL); + + while ((scn = elf_nextscn(elf, scn)) != NULL) { + gelf_getshdr(scn, &shdr); + if (shdr.sh_type == SHT_SYMTAB) { + /* found a symbol table, go print it. */ + break; + } + } + + data = elf_getdata(scn, NULL); + count = shdr.sh_size / shdr.sh_entsize; + + /* print the symbol names */ + for (ii = 0; ii < count; ++ii) { + GElf_Sym sym; + gelf_getsym(data, ii, &sym); + printf("%s\en", elf_strptr(elf, shdr.sh_link, sym.st_name)); + } + elf_end(elf); + close(fd); +} +.fi +.in -2 + +.SH USAGE +.sp +.LP +ELF Extended Sections are employed to allow an ELF file to contain more than +\fB0xff00\fR (\fBSHN_LORESERVE\fR) section. See the \fILinker and Libraries +Guide\fR for more information. +.SH FILES +.sp +.ne 2 +.mk +.na +\fB\fB/lib/libelf.so.1\fR\fR +.ad +.RS 23n +.rt +shared object +.RE + +.sp +.ne 2 +.mk +.na +\fB\fB/lib/64/libelf.so.1\fR\fR +.ad +.RS 23n +.rt +64-bit shared object +.RE + +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT LevelMT-Safe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBelf32_checksum\fR(3ELF), \fBelf32_fsize\fR(3ELF), +\fBelf32_getehdr\fR(3ELF), \fBelf32_newehdr\fR(3ELF), +\fBelf32_getphdr\fR(3ELF), \fBelf32_newphdr\fR(3ELF), +\fBelf32_getshdr\fR(3ELF), \fBelf32_xlatetof\fR(3ELF), +\fBelf32_xlatetom\fR(3ELF), \fBelf_errno\fR(3ELF), \fBlibelf\fR(3LIB), +\fBattributes\fR(5) +.sp +.LP +\fILinker and Libraries Guide\fR diff --git a/usr/src/man/man3elf/nlist.3elf b/usr/src/man/man3elf/nlist.3elf new file mode 100644 index 0000000000..8bb9a1c1f6 --- /dev/null +++ b/usr/src/man/man3elf/nlist.3elf @@ -0,0 +1,76 @@ +'\" 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] +.TH nlist 3ELF "11 Jul 2001" "SunOS 5.11" "ELF Library Functions" +.SH NAME +nlist \- get entries from name list +.SH SYNOPSIS +.LP +.nf +cc [ \fIflag\fR... ] \fIfile\fR ... \fB-lelf\fR [ \fIlibrary\fR ... ] +#include <nlist.h> + +\fBint\fR \fBnlist\fR(\fBconst char *\fR\fIfilename\fR, \fBstruct nlist *\fR\fInl\fR); +.fi + +.SH DESCRIPTION +.sp +.LP +\fBnlist()\fR examines the name list in the executable file whose name is +pointed to by \fIfilename\fR, and selectively extracts a list of values and +puts them in the array of \fBnlist()\fR structures pointed to by \fBnl\fR. The +name list \fBnl\fR consists of an array of structures containing names of +variables, types, and values. The list is terminated with a null name, that is, +a null string is in the name position of the structure. Each variable name is +looked up in the name list of the file. If the name is found, the type, value, +storage class, and section number of the name are inserted in the other fields. +The type field may be set to 0 if the file was not compiled with the \fB-g\fR +option to \fBcc\fR. +.sp +.LP +\fBnlist()\fR will always return the information for an external symbol of a +given name if the name exists in the file. If an external symbol does not +exist, and there is more than one symbol with the specified name in the file +(such as static symbols defined in separate files), the values returned will be +for the last occurrence of that name in the file. If the name is not found, all +fields in the structure except \fBn_name\fR are set to 0. +.sp +.LP +This function is useful for examining the system name list kept in the file +\fB/dev/ksyms\fR. In this way programs can obtain system addresses that are up +to date. +.SH RETURN VALUES +.sp +.LP +All value entries are set to 0 if the file cannot be read or if it does not +contain a valid name list. +.sp +.LP +\fBnlist()\fR returns 0 on success, \(mi1 on error. +.SH ATTRIBUTES +.sp +.LP +See \fBattributes\fR(5) for descriptions of the following attributes: +.sp + +.sp +.TS +tab() box; +cw(2.75i) |cw(2.75i) +lw(2.75i) |lw(2.75i) +. +ATTRIBUTE TYPEATTRIBUTE VALUE +_ +Interface StabilityStable +_ +MT-LevelSafe +.TE + +.SH SEE ALSO +.sp +.LP +\fBelf\fR(3ELF), \fBkvm_nlist\fR(3KVM), \fBkvm_open\fR(3KVM), +\fBlibelf\fR(3LIB), \fBa.out\fR(4), \fBattributes\fR(5), \fBksyms\fR(7D), +\fBmem\fR(7D) |