In ELF files, the section header table is an array of 64-byte Elf64_Shdr structures (or 40-byte Elf32_Shdr for 32-bit). Each structure describes name, type, flags, address, offset, size, link, info, alignment, and entry size.
When building llvm-project with -O3 -ffunction-sections -fdata-sections -Wa,--crel,--allow-experimental-crel , the section header tables occupy 17.6% of the total .o file size. In a -g -Wa,--crel,--allow-experimental-crel build, the section header tables occupy 13.9% of the total .o file size.
Last year I developed this format along with CREL and mentioned it in a few places. Recently refined it with CLEB128 and posted at https://groups.google.com/g/generic-abi/c/9DPPniRXFa8/m/32BVkrLrAgAJ , which received a lot of support.
Prototype https://github.com/MaskRay/llvm-project/tree/demo-cshdr
- Core functionality requires <200 lines, making clang, lld, llvm-readelf, llvm-ar, llvm-objdump work with compact section header table.
- yaml2obj and tests need a lot of lines

- CLEB128 (counted LEB128) llvm/lib/Support/LEB128.cpp . https://groups.google.com/g/generic-abi/c/9DPPniRXFa8/m/MJ3jetzZAAAJ suggested that we adopt a canonical name for this variable-length integer encoding. CLEB128 (counted LEB128) looks fantastic to me.
2024 prototype using unsigned LEB128 https://github.com/MaskRay/llvm-project/tree/demo-cshdr-2024
Detailed write-up: https://maskray.me/blog/2024-03-31-a-compact-section-header-table-for-elf
Note: The unsigned prefix-based variable-length integer encoding is identical to the one in MLIR bytecode, rather than the more common Little Endian Base 128 (LEB128) encoding used in DWARF and WebAssembly. This prototype doesn’t add variable-length signed integers. If we ever introduce them, we should use sign extension (MSB as sign) instead of zig-zag encoding (LSB as sign). MLIR, as sign extension actually generates faster code on most architectures.
Combining crel and cshdr, the object file is usually smaller than the WebAssembly binary format:
clang -c -Wa,--crel,--allow-experimental-crel,--cshdr -fno-asynchronous-unwind-tables -fno-exceptions -fno-ident -fno-addrsig -fno-unique-section-names a.cc
clang -c --target=wasm64 a.cc