Project Moved
Note: Ongoing development of libelf has moved to the Elftoolchain project on SourceForge.Net.
LibElf
LibElf is project implementing a BSD-licensed implementation of the SVR4 ELF(3) API. The scope of the project includes:
A TET based test-suite for the API,
Manual pages for section 3 of the FreeBSD manual set,
A tutorial documentation (currently a work-in-progress) 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 for cc -pg profiling.
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 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 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 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 CVS repository.
Design notes are on a seperate page: LibElf/ImplementationNotes. A 'status' page is at: LibElf/ImplementationStatus.
LibElf based Tool Development
Native toolchain work is being tracked at ElfToolChain.
External Projects
The following people/projects are using FreeBSD's LibElf:
ElfUtils, an proposed replacement for GNU binutils by Sam Arun Raj.
Emmanuel Azencot offers more examples of libelf based tools.
References
ELF gABI from SCO.
Linker and Libraries Guide from Sun Microsystems.
LibELF tutorial from Sun Microsystems.
ELF-64 Object File Format including HP and HP-UX extensions, from Hewlett-Packard.
LGPL'ed libelf(3) implementation by Michael Riepe.
An ELF library from the ERTOS project (doesn't implement the elf(3) API).
Standards and specs: An unsung hero: The hardworking ELF. IBM Developerworks article by Peter Seebach.
Test Execution Toolkit from the Open Group.