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 [http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libelf/ implementation of the ELF(3) API],
- A [http://perforce.freebsd.org/depotTreeBrowser.cgi?FSPC=//depot/user/jkoshy/projects/libbsdelf/ts TET based test-suite] for the API,
- [http://www.freebsd.org/cgi/man.cgi?query=elf&apropos=0&sektion=3&manpath=FreeBSD+8-current&format=html Manual pages] for section 3 of the FreeBSD manual set,
- A [http://people.freebsd.org/~jkoshy/download/libelf/article.html 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 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 CVS repository.
CVS: [http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libelf/ http://www.freebsd.org/cgi/cvsweb.cgi/src/lib/libelf/]
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:
- [http://code.google.com/p/aski-m/wiki/ElfUtils ElfUtils], an proposed replacement for GNU binutils by Sam Arun Raj.
- [http://freemanu1.free.fr/elf_examples/index.html Emmanuel Azencot] offers more examples of libelf based tools.
References
- [http://www.caldera.com/developers/gabi/ ELF gABI] from SCO.
- [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://devresource.hp.com/drc/STK/docs/refs/elf-64-hp.pdf ELF-64 Object File Format] including HP and HP-UX extensions, from Hewlett-Packard.
- [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.