[RFC] Compressed SHT_SYMTAB/SHT_STRTAB for ELF

In ELF executables and DSOs, .symtab and .strtab sections can consume a significant portion of the file size (10+% or even 20+%). In many scenarios, we cannot remove them due to symbolizers (crash reporters, Linux perf, etc) and other analysis tools. However, it’s natural to compress them using the standard SHF_COMPRESSED feature. We need linker and binary utilities support.

With the latest lld, we can compress .strtab, but the non-NUL terminated .strtab is not accepted by llvm-readelf

% myclang -fuse-ld=lld a.c -Wl,--compress-sections=.strtab=zstd -o a
% llvm-readelf -s a
...
warning: 'a': unable to get the string table for the SHT_SYMTAB section: SHT_STRTAB string table section [index 29] is non-null terminated

Symbol table '.symtab' contains 36 entries:
   Num:    Value          Size Type    Bind   Vis       Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT   UND <?>
     1: 00000000000002c4    32 OBJECT  LOCAL  DEFAULT     2 <?>
1 Like

Does this include .debug_* sections?

Some use cases include .debug_* (at least -gmlt, possibly also -fdebug-info-for-profiling) while some don’t.

So llvm-dwarfdump would also need to learn about this compression? I know there is some provision already for compressed .debug sections, if it all Just Works with both zlib/zstd then that’s great.

I support the direction here. It seems a straightforward improvement using existing flags.

I do wonder what the default behaviors should be. Should compressed DWARF imply compressed symbol tables? I’m guessing not, as it may take a while for support for compressed symbol tables to propagate through the ecosystem.

I would also vote for compression flags in objcopy to recompress, when explicitly specified.

1 Like

Thanks for the support!

Yes, the feature will need its own flag to wait for adoption within the ecosystem.

Some .gnu_debuglink users (often used with debug files in /usr/lib/debug/.build_id) compress debug sections and now the uncompressed .strtab/.strsym sizes are significant.

binutils feature request: 31884 – Compressed .strtab and .symtab

llvm-objcopy has --compress-sections <section>=[none|zlib|zstd]. We could extend it to decompress .symtab/.strtab