[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Reducing code size of Position Independent Executables (PIE) by shrinking the size of dynamic relocations section
- To: "Rahul Chaudhry via gnu-gabi" <gnu-gabi@sourceware.org>
- Subject: Re: Reducing code size of Position Independent Executables (PIE) by shrinking the size of dynamic relocations section
- From: Florian Weimer <fw@deneb.enyo.de>
- Date: Sun, 10 Dec 2017 00:06:26 +0100
- Authentication-results: sourceware.org; auth=none
- Cc: Sriraman Tallam <tmsriram@google.com>, Rahul Chaudhry <rahulchaudhry@google.com>, hegdesmailbox@gmail.com, Florian Weimer <fweimer@redhat.com>, David Edelsohn <dje.gcc@gmail.com>, Rafael Avila de Espindola <rafael.espindola@gmail.com>, Binutils Development <binutils@sourceware.org>, Alan Modra <amodra@gmail.com>, Cary Coutant <ccoutant@gmail.com>, Xinliang David Li <davidxl@google.com>, Sterling Augustine <saugustine@google.com>, Paul Pluzhnikov <ppluzhnikov@google.com>, Ian Lance Taylor <iant@google.com>, "H.J. Lu" <hjl.tools@gmail.com>, Luis Lozano <llozano@google.com>, Peter Collingbourne <pcc@google.com>, Rui Ueyama <ruiu@google.com>, llvm-dev@lists.llvm.org
- Delivered-to: listarch-gnu-gabi@sourceware.org
- Delivered-to: mailing list gnu-gabi@sourceware.org
- In-reply-to: <CAJRD=ooGubyUOLE6W7LHdeU2ZNDEG1A=84+P=1iOvfmD7-7GNg@mail.gmail.com> (Rahul Chaudhry via gnu-gabi's message of "Thu, 7 Dec 2017 14:51:20 -0800")
- List-help: <mailto:gnu-gabi-help@sourceware.org>
- List-id: <gnu-gabi.sourceware.org>
- List-post: <mailto:gnu-gabi@sourceware.org>
- List-subscribe: <mailto:gnu-gabi-subscribe@sourceware.org>
- Mailing-list: contact gnu-gabi-help@sourceware.org; run by ezmlm
- References: <CAGWvnynFwXFGLj3tAVgDatn0zmuHcWHyRNuDvR+wRZCXLnar_A@mail.gmail.com> <8737cosnym.fsf@localhost.localdomain.i-did-not-set--mail-host-address--so-tickle-me> <CAGWvnynEe3QkhDMGc=Tx8Vr44egtv3xLuh1yiVcAhv+e3GLtZg@mail.gmail.com> <a3e5c76c-8cb9-fc53-a30a-96b2c85079e1@gmail.com> <a68a5d29-09d6-e758-8680-d94f42762adf@redhat.com> <7e698a5f-32d7-6549-7e23-8850b85e6c10@gmail.com> <CAAs8Hmziqc0hebPndiGuZN=buFm=M+O+2fGCfsv_rvDro9zJZA@mail.gmail.com> <CAJRD=ooGubyUOLE6W7LHdeU2ZNDEG1A=84+P=1iOvfmD7-7GNg@mail.gmail.com>
- Sender: gnu-gabi-owner@sourceware.org
* Rahul Chaudhry via gnu-gabi:
> The encoding used is a simple combination of delta-encoding and a
> bitmap of offsets. The section consists of 64-bit entries: higher
> 8-bits contain delta since last offset, and lower 56-bits contain a
> bitmap for which words to apply the relocation to. This is best
> described by showing the code for decoding the section:
>
> typedef struct
> {
> Elf64_Xword r_data; /* jump and bitmap for relative relocations */
> } Elf64_Relrz;
>
> #define ELF64_R_JUMP(val) ((val) >> 56)
> #define ELF64_R_BITS(val) ((val) & 0xffffffffffffff)
>
> #ifdef DO_RELRZ
> {
> ElfW(Addr) offset = 0;
> for (; relative < end; ++relative)
> {
> ElfW(Addr) jump = ELFW(R_JUMP) (relative->r_data);
> ElfW(Addr) bits = ELFW(R_BITS) (relative->r_data);
> offset += jump * sizeof(ElfW(Addr));
> if (jump == 0)
> {
> ++relative;
> offset = relative->r_data;
> }
> ElfW(Addr) r_offset = offset;
> for (; bits != 0; bits >>= 1)
> {
> if ((bits&1) != 0)
> elf_machine_relrz_relative (l_addr, (void *) (l_addr + r_offset));
> r_offset += sizeof(ElfW(Addr));
> }
> }
> }
> #endif
That data-dependent “if ((bits&1) != 0)” branch looks a bit nasty.
Have you investigated whether some sort of RLE-style encoding would be
beneficial? If there are blocks of relative relocations, it might even
be possible to use vector instructions to process them (although more
than four relocations at a time are probably not achievable in a
power-efficient manner on current x86-64).