Elfkit
an elf read and manipulation library in pure rust (written from scratch, no bfd, no gnu code, no license infections), intended to be used in binary manipulation utils such as strip, chrpath, objcopy and ld. The end goal is to build a well designed library that facilitates drop-in replacements for gnu ld.
currently elfkit's ld can only link asm and C code with clang and musl libc
cargo build --release --example ld
ln -s $PWD/target/release/examples/ld /usr/bin/ld.elfkit
musl-clang -fuse-ld=elfkit tests/samples/main_c.c
there's also a prettier version of readelf showing of parsing capabilities
cargo run --example readelf ./tests/samples/amd64_exe
implementation status
section specific parsers
type | read | write |
---|---|---|
symbols | ok | ok |
strtab | ok | ok |
relocations | ok | ok |
dynamic | ok | ok |
note | - | - |
gnu_hash | - | - |
hash | - | faked |
versym | - | - |
verneed | - | - |
architectures
abi | headers | relocations |
---|---|---|
x86_64 | ok | minimum viable |
mips32r2 o32 | ok | |
arm eabi | ok |
alternatives
- goblin mach-o and archive support, no-std support, very low level
- elf most popular, most generic use case, no writing, no section parsing
- xmas-elf zero alloc (good for writing an OS), read only
references
- https://en.wikipedia.org/wiki/Executable_and_Linkable_Format
- https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-r252.pdf
- https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf
- http://infocenter.arm.com/help/topic/com.arm.doc.ihi0044f/IHI0044F_aaelf.pdf
- https://dmz-portal.imgtec.com/wiki/MIPS_ABI_Project
- https://dmz-portal.imgtec.com/wiki/MIPS_O32_ABI_-_FR0_and_FR1_Interlinking
- http://www.mindfruit.co.uk/2012/06/relocations-relocations.html#reloc_types_table