The relocation formats REL and RELA for ELF are inefficient. In a release build of Clang for x86-64, .rela.* sections consume a significant portion (approximately 20.9%) of the file size. I have developed an alternative relocation format (tentatively named RELLEB), which yields a significant reduction: x86-64: 17.2%, aarch64: 16.5%, riscv64: 32.4%!
Elf32_Rel and Elf32_Rela sacrifice flexibility to maintain a smaller size, limiting relocation types to a maximum of 255. RELLEB allows 2**32 relocation types, aligning with Elf64_Rel/Elf64_Rela.
I have analyzed many architectures including Arm (AArch32/AArch64), Power, RISC-V, MIPS, RISC-V, z/Architecture, and x86, written a detailed analysis of the size problem and my solution at A compact relocation format for ELF | MaskRay ,
created a generic ABI proposal https://groups.google.com/g/generic-abi/c/yb0rjw56ORw,
and developed a prototype at GitHub - MaskRay/llvm-project at demo-relleb
- clang
- -mrelleb: use SHT_RELLEB instead of SHT_REL/SHT_RELA
- -Xclang --compress-relocations={none,zlib,zstd}: compress
SHT_REL/SHT_RELA/SHT_RELLEB
- ld.lld
- handle SHT_RELLEB input sections
- -z relleb: use .relleb.dyn instead of .rel.dyn/.rela.dyn for dynamic
relocations. Can be used together with --pack-dyn-relocs=relr - -r: copy SHT_RELLEB and rewrite
- llvm-readelf
- -S: recognize SHT_RELLEB
- -d: recognize DT_RELLEB
- -r: dump SHT_RELLEB sections
- yaml2obj/obj2yaml
- MCTargetOptions
- llvm-mc -relleb
- llc -relleb
- ld.lld -mllvm -relleb for LTO
Unimplemented yet
- ld.lld
- –emit-relocs
- llvm-objdump
- -d -r
Example:
myclang++ -fuse-ld-lld =mrelleb a.cc b.cc
I am looking forward to your thoughts:)
Here are a few use cases that will benefit from a compact relocation type:
- Marker relocations (R_RISCV_RELAX, etc)
.llvm_addrsig.llvm.call-graph-profile.debug_namesSmaller object file cost for .debug_names intended only for linking