Hi,
On 6/26/23 8:56 PM, 'Fangrui Song' via Generic System V Application Binary Interface wrote:
>
https://www.sco.com/developers/gabi/latest/ch4.sheader.html says
>
> > SHF_COMPRESSED - This flag identifies a section containing compressed data. SHF_COMPRESSED applies only to non-allocable sections, and cannot be used in conjunction with SHF_ALLOC. In addition,
> SHF_COMPRESSED cannot be applied to sections of type SHT_NOBITS.
>
> I find that the incompatibility with SHF_ALLOC is unnecessary.
>
> In the case of linker input (relocatable object files), having both the SHF_ALLOC and SHF_COMPRESSED flags should be acceptable, as long as the linker is capable of decompressing the content.
> It is also important to ensure that non-linker consumers are compatible with the section, which is relatively easy to confirm.
I don't see that as really beneficial: If an alloc section
is so big that compression is wanted, that's going to be a runtime
issue as well. An early warning of problems to come.
I agree that it could be allowed for ET_REL, because only the
link-editor is involved, and is in a position to uncompress the
input. I won't stand in the way, but it seems a dubious win to me,
and I think it would be better not to encourage it.
>
> Similarly, for linker output (executable or shared object), having both the SHF_ALLOC and SHF_COMPRESSED flags should be permissible.
> The section's address may be insignificant at runtime, as it might encode "relocatable" metadata for purposes such as PGO, coverage, sanitizers, etc.
> The runtime can locate the section using encapsulation symbols (_start$sectionname, _stop$sectionname) and determine whether it needs to be decompressed by parsing the optional ElfNN_Chdr header.
> To differentiate between compressed and uncompressed content, the uncompressed content may begin with 4 zero bytes, as the ch_type field of ElfNN_Chdr is non-zero (typically, 1 or 2 for zlib or zstd
> compression).
>
> Therefore, I propose that we omit the statement about the incompatibility of the SHF_COMPRESSED flag with SHF_ALLOC:
>
> > SHF_COMPRESSED - This flag identifies a section containing compressed data. SHF_COMPRESSED cannot be applied to sections of type SHT_NOBITS.
I disagree with this, particularly as part of the gABI.
I have conceptual and practical concerns.
Sections are a link-time concept, not a runtime one. Runtime
linkers deal in segments, not sections. The section headers
aren't even in memory at load time. While symbols could be
used, it feels more like a workaround than a design. And
requiring the runtime linker to construct segments, filling in
the holes, early in startup, is problematic. ELF features should
be widely useful, rather than trying to cater to absolutely
every scenario,
It also subverts the mapping model that's core to how ELF is
intended to work. The runtime linker is supposed to be a small
piece of code that does an mmap (or equivalent) for each PT_LOAD,
does relocation and some other lightweight work, and gets out
of the way. This pulls in a lot of code, a fair amount of complexity.
and it undermines the VMs ability to share readonly pages. Such
sharing would seem to be particularly important for large sections.
Please note the use of "supposed to be" rather than "are"
in the above. I know that they're already big and complex,
but adding more isn't the answer to that. :-).
Applying COMPRESS to segments rather than sections, makes more
conceptual sense, but it doesn't address the basic problems.
I think that if an allocable section is too large to be in a
final object (EXEC or DYN), then it's also too big to be loaded
onto memory wholesale. Given modern systems, a section has to be
*really* large for that to be true. That sort of data should be
accessed in some other way, outside of linking.
I appreciate your finding that.
The blog mentioned non-allocable, only to disqualify it without
getting into the details, largely to avoid derailing the discussion
of compression with a long negative digression.
It was definitely discussed carefully in house, and when going
through the process of adding COMPRESS to the ABI. ABIs don't
usually do deep dives on the reasons why something is disallowed
though. Describing what is allowed, accurately, and concisely is
hard enough.
Thanks.
- Ali