ArmClang and IAR support compression in the linker. Does clang support similar operations of compression?

ArmClang and IAR support compression in the linker. Does clang support similar operations of compression?
IAR Compression:
(1) packbits - Compresses with the PackBits algorithm. Thismethod generates good results for data with many identicalconsecutive bytes.
(2) lz77 - Compresses with the Lempel-Ziv-77 algorithm.This method handles a larger variety of inputs well, but hasa slightly larger decompressor.

ARMclang Compression:
https://software-dl.ti.com/codegen/docs/tiarmclang/compiler_tools_user_guide/compiler_manual/linker_description/08_using_linker_generated_copy_tables/compression-stdz0754720.html

At least in Arm Compiler (armclang) the compression is done by the linker armlink. The equivalent tool in llvm-project is LLD. Some code that runs at boot time needs to be able decompress the code as well. In a proprietary toolchain where the linker and libraries can be tightly integrated this can be built into the C-library.

At present LLD does not support compression for non-debug sections.

While I would like to see such a feature added, and would volunteer to work on it! I think it would be hard to get this type of feature into LLD for the following reasons:

  • There would need to be an interface change to linker scripts to identify what can and can’t be compressed. Ideally this would be coordinated with GNU ld, as both linkers share the same linker script syntax.
  • Compression of addressable sections is not particularly pleasant for a linker to handle. For example what if data contains a pointer to some address that depends on the size of an area that will be compressed? This would add complexity to LLD for a relatively niche use case. I’m not sure if the LLD maintainers will be willing to accept that.
  • The C-library or user-code doing the decompression needs to know the algorithm used, and how to find the compressed data.

An alternative solution that we’re thinking about is a 2 stage link with the first stage producing an uncompressed ELF file, then compressing the ELF file using an external tool, with a separate boot-loader doing the decompression.

If there is a possibility that LLD would accept some form of compression implementation we’d be interested in working on it.

There is a loader in LLVM: