Support dead-stripping in ELF objects

Michael Spencer bigcheesegs at gmail.com
Fri Apr 5 16:46:10 PDT 2013


On Tue, Apr 2, 2013 at 6:49 PM, Nick Kledzik <kledzik at apple.com> wrote:

> On Apr 2, 2013, at 6:23 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:
>
>
> This is a good idea, but I think we need more for an effective and
> portable implementation.
>
> I very much agree!
>
>
> We need a detailed specification of what guarantees the compiler is making
> for the linker. I've thought about this in terms of both deadstripping and
> how to make atomization of ELF files faster and have the following:
>
> Section flags:
> * SHF_VALID_SIZE
>   * There shall be a symbol with st_value of 0.
>   * For each symbol, st_value + st_size shall be the st_value of another
> symbol, or sh_size (the end of the section).
>   * For each symbol, the range [st_value, st_value + st_size) shall be
> non-overlapping.
>
> So these say that the whole section is "covered" by the set of symbol
> ranges.  Is that too strict?  What if the compiler 16-byte aligned the
> start of each function.  Should the padding at the end be included in each
> st_size?  If the padding is not in the st_size, then that would allow the
> linker optimizations like replacing the padding with small functions...
>

You're right, that is too strict. Non-overlapping is the main point.


>
>
>   * If a relocation in this section has a target symbol which is in a
> section with this flag set, r_addend must be less than st_size.
>
> I assume you mean the st_size of the target symbol.  But that would
> disallow valid C code.  You can write:
>
>        char* x = &foo + 100;
> or
>        char* y = &foo - 50;
>
> where 100 > sizeof(foo).  Supporting this sort of stuff is why "scattered
> relocations" were created for mach-o long ago.  You see mach-o does not
> have RELA relocations (that is relocations with addends). Scattered
> relocations give you the final value and the symbol.  You can then subtract
> the two to get the addend.    Anyway, with addends, you don't need this
> st_size check.
>
> Which reminds me this additional information is not just about dead
> stripping it also enable ordering.  That is, when you link, you can pass
> the linker an ordered list of "hot" functions/data and the linker can
> rearrange the atoms to group the hot atoms together.  The end result is
> less paging and less dirty pages.  And that is how "scattered relocation"
> got its name (yes, "scattered" seems like increasing entropy, whereas order
> files are attempting to better organize the code.  But in someone's mind
> moving the functions at all was "scattering" them).
>
> -Nick
>

Jumping between objects is not valid in C or C++, it just happens to work.
However, this should actually be allowed in SHF_VALID_SIZE, as the section
is still stuck together, and you're guaranteed for this to be true at the
ABI level. Where this actually does need to apply is
SHF_SUBSECTIONS_VIA_SYMBOLS, as we can't make any guarantees about what
content is going to be outside the object's boundaries.

- Michael Spencer
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130405/a8a5eb67/attachment.html>


More information about the llvm-commits mailing list