Support dead-stripping in ELF objects

Rafael EspĂ­ndola rafael.espindola at gmail.com
Wed Apr 3 08:45:08 PDT 2013


> == Deadstripping ==
>
> The deadstrip roots is the set of all symbols defined in sections not marked
> SHF_DEADSTRIP, symbols with STF_NO_DEADSTRIP, and any implementation defined
> symbols.
>
> A symbol is live if it is a deadstrip root, or it is referenced from a
> deadstrip root or another live symbol, or it is in a section not marked
> SHF_SUBSECTION_VIA_SYMBOLS that has other live symbols.
>
> A symbol X is referenced by Z if:
> * If Z and X are not in a section marked SHF_VALID_SIZE.
>   * There is a relocation in the section containing Z with a resolved symbol
> which comes from the same file and has the same st_shndx as X (the section
> containing Z references the section containing X).
> * If Z is not in a section marked SHF_VALID_SIZE but X is.
>   * There is a relocation in the section containing Z with the resolved
> symbol X.
> * If both Z and X are in sections marked SHF_VALID_SIZE.
>   * There is a relocation with an r_offset within the range [st_value,
> st_value + st_size) of Z with the resolved symbol X.
>
> Any symbol that is not live may be removed if allowed by section flags.

Do we need to compute this? We should only need to know if a symbol is
referenced, not who is referencing it. With that we can just say that
a symbol is referenced if

* A relocation points to it.
* It is in a section without SHF_SUBSECTION_VIA_SYMBOLS and a
relocation points to that section.

My concern is that in the non  SHF_SUBSECTION_VIA_SYMBOLS case the
full symbol reference graph as defined above would be n^2 in cases
like .text and .eh_frame. There is (approximately) one symbol in
.eh_frame for each symbol in .text and it has a relocation to the
corresponding .text symbol. We would get n^2 edges without
SHF_SUBSECTION_VIA_SYMBOLS.

> - Michael Spencer
>

Cheers,
Rafael



More information about the llvm-commits mailing list