This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Use synthetic section to hold copy relocations
ClosedPublic

Authored by peter.smith on Feb 7 2017, 6:16 AM.

Details

Summary

This changes adds a new synthetic section CopyRelSection to hold the ZI reserved for the result of the copy relocation, moreover the dynamic copy relocation is made relative to the CopyRelSection. Previously we altered the size of the OutputSection and made the copy relocation relative to an offset into the OutputSection. This change has a couple of small benefits:

  • All dynamic relocations are now relative to an InputSection, this means we can remove the support for OutputSection relative dynamic relocations, which makes us more robust to changes in section offsets after scanRelocs().
  • If assignOffsets() is called on .bss or .bss.rel.ro the offsets and final size of the OutputSection will be correct. Previously the work of scanRelocs() would be destroyed by assignOffsets().

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.Feb 7 2017, 6:16 AM
ruiu edited edge metadata.Feb 7 2017, 1:14 PM

Generally looking good. A few minor comments.

ELF/Relocations.cpp
438–439 ↗(On Diff #87411)

I wonder how many copy relocations are usually made for a program which needs copy relocations. If it is thousands, it is fine to create thousands of input sections here, but if it's more than that, we want to avoid that. (If it is small, I like this approach to create one section per a copy relocation, as it is simple.)

ELF/Symbols.cpp
87 ↗(On Diff #87411)

auto -> InputSection<ELFT>

pcc added a subscriber: pcc.Feb 7 2017, 1:19 PM
pcc added inline comments.
ELF/Symbols.cpp
236 ↗(On Diff #87411)

Can you remove the CopyIsInBssRelRo field now?

peter.smith updated this revision to Diff 87627.Feb 8 2017, 4:02 AM

Thank you very much for the comments. I've updated the diff to make the requested changes.

I've also had a quick investigate into how many copy relocs we would expect to see. I ran readelf --relocs | grep _COPY over most of the executables on my Linux box and came back with most having 0, quite a few having < 10 and a few outliers with 60 to 70. These were gdb and gpartedbin.

I would prefer to keep one section per copy rel as we can assume the offset in the section is 0, otherwise we'll need to record the offset in SharedSymbol.

number of copy relsnumber of executables
04159
1515
2471
3343
4308
5277
6239
793
89
925
107
1112
1210
1313
1411
154
163
176
181
193
202
211
224
264
354
363
661
761
ruiu accepted this revision.Feb 8 2017, 11:37 AM

LGTM

This revision is now accepted and ready to land.Feb 8 2017, 11:37 AM
This revision was automatically updated to reflect the committed changes.