This is an archive of the discontinued LLVM Phabricator instance.

[ELF] - R_X86_64_SIZE64/R_X86_64_SIZE32 relocations implemented.
ClosedPublic

Authored by grimar on Dec 8 2015, 7:58 AM.

Details

Summary

R_X86_64_SIZE64/R_X86_64_SIZE32 relocations were introduced in 0.98v of "System V Application Binary Interface x86-64" (http://www.x86-64.org/documentation/abi.pdf).

Calculation for them is Z + A, where:
Z - Represents the size of the symbol whose index resides in the relocation entry.
A - Represents the addend used to compute the value of the relocatable field.

Currently afaik gold does not support these, but bfd does.

Diff Detail

Repository
rL LLVM

Event Timeline

grimar updated this revision to Diff 42180.Dec 8 2015, 7:58 AM
grimar retitled this revision from to [ELF] - R_X86_64_SIZE64/R_X86_64_SIZE32 relocations implemented..
grimar updated this object.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
grimar added inline comments.
ELF/Target.cpp
645 ↗(On Diff #42180)
// This check could be moved at upper level, but that
// would require adding Target->isSizeReloc() method.
// SIZE32/64 relocations exist only for x64 now,
// so it does not need such generic handling and that is why it is here.
ruiu added inline comments.Dec 8 2015, 9:34 AM
ELF/Target.cpp
645 ↗(On Diff #42180)

I don't understand why you had to do this. Is this described in the spec?

grimar updated this revision to Diff 42271.Dec 9 2015, 1:47 AM
  • Addressed review comments.
  • Added Target::isSizeDynReloc()
  • Updated test.
ELF/Target.cpp
645 ↗(On Diff #42180)

Point was to skip unnecessary calculations below since anyways dynamic relocation should be created for that case.
But I did a mistake in logic. Not Config->Shared have to be checked but canBePreempted(). If this relocation is against something that CBP then dynamic relocation is created and there is no need to perform any calculations.
Updated the test to cover that case.

Unfortunately I was need to add isSizeDynReloc() to target that wanted to avoid. Another way I see - to add CBP or Body argument for relocateOne and perform check inside like in first version of patch.

ruiu added inline comments.Dec 9 2015, 10:26 AM
ELF/Target.cpp
510–511 ↗(On Diff #42271)

Is this correct? If my understanding is correct, if a symbol can be preempted, SIZE relocations for the symbol are ignored in this implementation. Is this what you expected?

grimar added inline comments.Dec 10 2015, 1:44 AM
ELF/Target.cpp
510–511 ↗(On Diff #42271)

Keyword here "Dyn", this method checks if size relocation requires dynamic reloc.

If symbol can be preempted then it requires dynamic size relocation R_X86_64_SIZE64/R_X86_64_SIZE32 which is placed to .rela.dyn, and relocation calculation therefore ignored. For not CBP symbols I dont create dynamic relocation and resolve it during static link.
That how it works I believe, and covered in tests (relocation-size-shared.s both resolves some size relocs statically and also creates few dynamic ones).

ruiu accepted this revision.Dec 10 2015, 3:04 PM
ruiu edited edge metadata.

LGTM

This revision is now accepted and ready to land.Dec 10 2015, 3:04 PM
This revision was automatically updated to reflect the committed changes.