public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jan Hubicka <hubicka@ucw.cz>
Cc: "H.J. Lu" <hjl.tools@gmail.com>,
	Jan Beulich <JBeulich@novell.com>,
	       "H. Peter Anvin" <hpa@zytor.com>,
	GCC Development <gcc@gcc.gnu.org>,
	       x32-abi@googlegroups.com,
	Binutils <binutils@sourceware.org>,
	       GNU C Library <libc-alpha@sourceware.org>
Subject: Re: x32 psABI draft version 0.2
Date: Thu, 17 Feb 2011 23:07:00 -0000	[thread overview]
Message-ID: <20110217230727.GK30899@tyan-ft48-01.lab.bos.redhat.com> (raw)
In-Reply-To: <20110217224956.GA20055@kam.mff.cuni.cz>

On Thu, Feb 17, 2011 at 11:49:56PM +0100, Jan Hubicka wrote:
> The blog claims
> Architecture 	libxul.so size 	relocations size 	%
> x86 	21,869,684 	1,884,864 	8.61%
> x86-64 	29,629,040 	5,751,984 	19.41%
> 
> The REL encoding also grows twice for 64bit target?
> 
> > REL.  There might be better ways how to get the numbers down.
> 
> These are difficult since they mostly come from vtables and we need to be
> pretty smart to optimize vtable out completely.  Mozilla recently started to
> use elfhack (in official builds) that is sort of their own dynamic linker
> handling PC relative relcoations only.  Pretty ugly IMO but they claim 16%
> savings on x86-64, 6% on x86

By better ways I meant create new relocations for relative relocs that would
be even more compact (assuming we can't or don't want to change the fact
that vtables contain pointers instead of pc relative pointers and assuming
Mozilla doesn't want to change implementation language to something saner
than C++ ;) ).
On my libxul.so I see:
 0x000000006ffffff9 (RELACOUNT)          161261
Relocation section '.rela.dyn' at offset 0x75a10 contains 186467 entries:
Relocation section '.rela.plt' at offset 0x4ba358 contains 4722 entries:
so all that it actually matters there are relative relocations.
So one way to cut down the size of .rela.dyn section would be a relocation
like
R_X86_64_RELATIVE_BLOCK where applying such a relocation with r_offset O and
r_addend N would be:
uint64_t *ptr = O;
for (i = 0; i < N; i++)
  ptr[i] += bias;
Then e.g.
0000003ec6d86008  0000000000000008 R_X86_64_RELATIVE                               0000003ec5aef3f3
0000003ec6d86010  0000000000000008 R_X86_64_RELATIVE                               0000003ec5af92f6
0000003ec6d86018  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b06d17
0000003ec6d86020  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b1dc5f
0000003ec6d86028  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b1edaf
0000003ec6d86030  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b27358
0000003ec6d86038  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b30f9f
0000003ec6d86040  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b3317d
0000003ec6d86048  0000000000000008 R_X86_64_RELATIVE                               0000003ec5b34479
could be represented as:
0000003ec6d86008  00000000000000MN R_X86_64_RELATIVE_BLOCK                         0000000000000009
I see many hundreds of consecutive R_X86_64_RELATIVE relocs in libxul.so, though
of course it would need much better analysis over larger body of code.

In most programs if the library is prelinked all relative relocs are skipped
and .rela.dyn for them doesn't need to be even paged in, but Mozilla is quite
special in that it one of the most common security relevant packages and thus
wants randomization, but is linked against huge libraries, so the question is
if Mozilla is the right candidate to drive our decisions on.

Another alternative to compress relative relocations would be an indirect
relative relocation, which would give you in r_offset address of a block of addresses
and r_addend the size of that block, and the block would just contain offsets
on which words need to be += bias.  Then, instead of changing RELA to REL to
save 8 bytes from 24 you'd save 16 bytes from those 24 (well, for x32 half of that).

	Jakub

  parent reply	other threads:[~2011-02-17 23:07 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16 19:22 H.J. Lu
2011-02-16 20:04 ` H. Peter Anvin
2011-02-16 20:29   ` Roland McGrath
2011-02-16 20:35   ` Chris Metcalf
2011-02-16 20:39     ` Andrew Pinski
2011-02-16 20:46       ` H.J. Lu
2011-02-16 22:13         ` Chris Metcalf
2011-02-17  8:35   ` Jan Beulich
2011-02-17 12:14     ` H.J. Lu
2011-02-17 16:14       ` John Reiser
2011-02-17 17:59         ` Jakub Jelinek
2011-02-17 14:29     ` Jakub Jelinek
2011-02-17 15:22       ` Jan Hubicka
2011-02-17 15:30         ` H.J. Lu
2011-02-17 15:45           ` Jan Hubicka
2011-02-17 15:49             ` H.J. Lu
2011-02-17 16:10               ` Jan Beulich
2011-02-17 17:59                 ` H.J. Lu
2011-02-18  8:10                   ` Jan Beulich
2011-02-18 17:53                     ` H.J. Lu
2011-02-18 20:32                       ` Jan Hubicka
2011-02-21  8:04                       ` Jan Beulich
2011-02-17 18:07             ` Jakub Jelinek
2011-02-17 19:56               ` H. Peter Anvin
2011-02-17 22:50               ` Jan Hubicka
2011-02-17 23:00                 ` H. Peter Anvin
2011-02-17 23:07                 ` Jakub Jelinek [this message]
2011-02-18  8:49                   ` Jan Beulich
2011-02-17 18:14         ` Joseph S. Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110217230727.GK30899@tyan-ft48-01.lab.bos.redhat.com \
    --to=jakub@redhat.com \
    --cc=JBeulich@novell.com \
    --cc=binutils@sourceware.org \
    --cc=gcc@gcc.gnu.org \
    --cc=hjl.tools@gmail.com \
    --cc=hpa@zytor.com \
    --cc=hubicka@ucw.cz \
    --cc=libc-alpha@sourceware.org \
    --cc=x32-abi@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).