This is an old revision of the document!
LibElf
LibElf is project implementing a BSD-licensed implementation of the SVR4 [http://www.freebsd.org/cgi/man.cgi?query=elf&apropos=0&sektion=0&manpath=SunOS+5.10&format=html ELF(3)] API. The scope of the project includes:
- an implementation of the ELF(3) API,
- a TET based test-suite for the API,
- manual pages suitable for section 3 of the FreeBSD manual set,
- and, optionally, tutorial documentation suitable for inclusion in the FreeBSD Developer's Handbook.
JosephKoshy is the developer working on this project.
Rationale
In the absence of a common API to read and manipulate ELF objects, many of FreeBSD's tools implement ad-hoc ELF parsers inside themselves.
FreeBSD tools which implement ad-hoc parsers include:
btxld(8): reads and parses the ELF header when loading files.elfdump(1): displays information about ELF files.gprof(1): reporting tool forcc -pgprofiling.kgzip(8): compresses a kernel.pmcstat(8): performance monitoring controller for PMC based profiling.
The downside of implementing ad-hoc ELF parsers is:
- the extra effort in developing & maintaining the parser code,
- parsing bugs that weaken the quality of the overall system,
- the added difficulty in making such tools cross-platform.
The use of a common ELF API alleviates these problems to some degree.
ELF Handling Alternatives
The GNU binutils toolset implements one such common API;
the [http://sources.redhat.com/binutils/ Binary File Descriptor]
library (-lbfd). The BFD library supports a very large range
of cross-targets. However, its implementation is distributed
under a restrictive license (GPL, not even LGPL), which makes it
unsuitable for use in developing BSD-licensed tools.
The SVR4 ELF(3) API implements architecture-independent parsing of ELF files. While its scope is narrower than that of BFD, it fits FreeBSD's needs reasonably well. Apart from (Open)Solaris code, a small number of 3rd-party open-source applications use this API.
The ERTOS project's [http://www.ertos.nicta.com.au/software/kenge/libelf/devel/ ELF library] can also handle ELF files, but offers an API different from ELF(3).
The ELF(3) API
The elf(3) API seems to have first appeared in SysV Unix (namely, SVR4),
As the API evolved, it developed 32 and 64 bit variants. The [http://www.freebsd.org/cgi/man.cgi?query=gelf&apropos=0&sektion=0&manpath=SunOS+5.10&format=html GELF(3)] sub-API was added to provide an ELF class-independent way of manipulating ELF files.
ELF(3) is currently in use in Solaris and other SVR4 derived systems. An LGPL-ed implementation of this API is present in some GNU operating systems.
Development
LibElf is being developed in FreeBSD's Perforce repository. Design notes are on a seperate page: LibElf/ImplementationNotes.
P4:[http://perforce.freebsd.org/depotTreeBrowser.cgi?FSPC=//depot/user/jkoshy/projects/libbsdelf //depot/user/jkoshy/projects/libbsdelf]
References
- [http://docs.sun.com/app/docs/doc/817-1984 Linker and Libraries Guide] from Sun Microsystems.
- [http://developers.sun.com/solaris/articles/elf.html LibELF tutorial] from Sun Microsystems.
- [http://www.mr511.de/software/english.html LGPL'ed libelf(3) implementation] by Michael Riepe.
- An [http://www.ertos.nicta.com.au/software/kenge/libelf/devel/ ELF library] from the ERTOS project (doesn't implement the
elf(3)API). - [http://www-128.ibm.com/developerworks/power/library/pa-spec12/?ca=dgr-lnxw41ELFHero Standards and specs: An unsung hero: The hardworking ELF]. IBM Developerworks article by Peter Seebach.
- [http://tetworks.opengroup.org/tet/ Test Execution Toolkit] from the Open Group.