public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* CREL dynamic relocations
@ 2024-03-24  5:50 Fangrui Song
  2024-03-25 11:52 ` Florian Weimer
  0 siblings, 1 reply; 7+ messages in thread
From: Fangrui Song @ 2024-03-24  5:50 UTC (permalink / raw)
  To: libc-alpha

I have proposed a compact relocation format CREL at
https://groups.google.com/g/generic-abi/c/yb0rjw56ORw/m/eiBcYxSfAQAJ
(previously named RELLEB).

CREL primarily targets static relocations, achieving significant .o
file size reduction for lld builds: 18.0% for x86-64/aarch64 and 34.3%
for riscv64.
CREL holds promise for dynamic relocations as well, surpassing
Android's packed relocation format.

* R_*_GLOB_DAT and R_*_JUMP_SLOT relocations can typically be encoded
with repeated 0x09 0x01 (when shift==3, offset++, symidx++).
* Absolute relocation (__cxa_pure_virtual@CXXABI_1.3 + 0) relocations
typically require just one byte (offset+=n)

While CREL's benefit for non-relative relocations is smaller than
RELR's optimizing for relative relocations, it still shines for
programs where non-relative relocations make up more than 5% of the
file size
(quite a few GUI libraries, probably due to C++ virtual tables).
We could even consider phasing out REL/RELA for new architectures in
favor of CREL.

I'd love to hear your feedback on CREL and hope someone might consider
implementing rtld support (and binutils support if you like that as
well:) )
https://sourceware.org/bugzilla/show_bug.cgi?id=31541

I've notified binutils and GCC folks at
https://sourceware.org/pipermail/binutils/2024-March/133153.html
("CREL relocation format for ELF (was: RELLEB)").

^ permalink raw reply	[flat|nested] 7+ messages in thread
* CREL dynamic relocations
@ 2024-04-09 15:32 Wilco Dijkstra
  2024-04-11  2:41 ` Fangrui Song
  0 siblings, 1 reply; 7+ messages in thread
From: Wilco Dijkstra @ 2024-04-09 15:32 UTC (permalink / raw)
  To: maskray; +Cc: 'GNU C Library', Florian Weimer

Hi,

I like the general idea of more compact relocations, however what I don't get is
what the overall goal is. If the goal is more compact object files, why don't we just
add a (de)compress pass using a fast compression algorithm? CPU time is cheap
today, and real compression easily gives 2-4x reduction of object file size, far more
than you could achieve by just compressing relocations.

Alternatively, if we wanted to access and process ELF files without any decompression,
we could define compact relocations as fixed-size entries. Using 64 bits for a compact
RELA relocation gives a straightforward 4x compression. Out of range values could
use the next entry to extend the ranges.

So my main issue with the proposal is that it tries too hard to compress relocations.
For example using offset compression for relocations, symbol indices and even addends
seems to have little value: the signed offset means you lose one bit, and if out of range
values are rare or not grouped together, offset encodings are actually less efficient.

I don't get the discussion about relocation numbers on AArch64 - 4 or 5 bits would
handle all frequently used relocations, so we'd just remap them to fit in the short
encoding. Hence I don't see a need at all for a signed offset encoding.

So my suggestion is to either go for compression of the whole object file or use a
simpler approach that isn't almost a compression algorithm.

Cheers,
Wilco



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2024-04-18  4:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-24  5:50 CREL dynamic relocations Fangrui Song
2024-03-25 11:52 ` Florian Weimer
2024-03-25 18:51   ` Fangrui Song
2024-04-09 15:32 Wilco Dijkstra
2024-04-11  2:41 ` Fangrui Song
2024-04-12 16:18   ` enh
2024-04-18  4:31     ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).