Hi H.J.,
The sh_size in the section header, and the d_size
in the data descriptor, are the sum of the overhead
(the compression header: ZLIB + 8 in BE) and the number
of compressed bytes.
The size recorded in that compression header (ch_size for
the gABI format, "ZLIB" + 8 for the old one), are the
resulting value for sh_size and d_size when the data is
uncompressed. It doesn't include the size of the compression
header --- in the uncompressed state, there is no compression
header.
The decompress process, roughly, is:
- Verify the compression header, acquire the
uncompressed length.
- Allocate a replacement data buffer of that size,
and do the decompression.
- Update the data buffer (a_align, d_buf, d_size)
to use your new buffer.
- Update the section header sh_size. For gABI,
clear the SHF_COMPRESSED flag. For the old
style, deal with renaming the section from
.zdebug* to .debug*.
The way I think of this is that compression pushes the original
value of sh_size into the compression header, and decompression
pops it back.
- Ali