This is an archive of the discontinued LLVM Phabricator instance.

[LLD][ELF] Tidy up handleARMTlsRelocation [NFC]
ClosedPublic

Authored by peter.smith on Apr 6 2017, 3:32 AM.

Details

Summary

Replace addModuleReloc with AddTlsReloc so that we can use it for both the module relocation and the offset relocation. This is a refactoring of the patch in D31749 that doesn't obscure the fix (as observed in D31672).

Diff Detail

Event Timeline

peter.smith created this revision.Apr 6 2017, 3:32 AM
rafael added inline comments.Apr 6 2017, 3:09 PM
ELF/Relocations.cpp
160

Why Config->Pic? Is it not always 1 for position independent executables?

peter.smith updated this revision to Diff 94500.Apr 7 2017, 3:02 AM

Yes, we can use Config->Shared instead, thanks for pointing that out. I've updated to use Config->Shared and have put back the use of TlsOffsetRel in the Got, it could be possible to add another field to make it use a more regular relocation code, but I'm not sure that is a net win in readability. I'm happy to make the change if it is important to others though.

ruiu added inline comments.Apr 10 2017, 6:38 PM
ELF/Target.cpp
1842 ↗(On Diff #94500)

Why do you need this?

1845–1847 ↗(On Diff #94500)

This is not a comment to this particular patch, but we need to remove this piece of code and instead create a way to just set "1" to .got without using this type of relocation in an odd way.

peter.smith added inline comments.Apr 11 2017, 3:12 AM
ELF/Target.cpp
1842 ↗(On Diff #94500)

It is so the same relocation code can be used in:

AddTlsReloc(Off + Config->Wordsize, Target->TlsOffsetRel, &Body, NeedDynOff);

Without it, it would need to be

AddTlsReloc(Off + Config->Wordsize, NeedDynOff ? Target->TlsOffsetRel : R_ARM_ABS32, NeedDynOff);

As when we statically come to resolve the R_ARM_TLS_DTPOFF32 we get unknown relocation code.

I thought that the trade off in adding R_ARM_TLS_DTPOFF32 was worth it as it emphasized that the dynamic relocation was just being evaluated at static link time. I'm not hugely fussed about doing it this way.

1845–1847 ↗(On Diff #94500)

These possibilities come to mind:

  • Add a function to add arbitrary constants to the GotSection, the module index becomes In<ELFT>::Got->addConstant(Off, 1);
  • Add a function to add the executables module index at an offset, In<ELFT>::Got->addModuleIndex(Off)
  • Make an ARMGotSection that handles the module index in a similar way to the MipsGotSection

I'd like if we have a solution that both you and Rafael are happy with. I have a weak preference for resolving the Relocation as 1 until there are other cases where we need to write arbitrary constants to the GotSection, but as I say this is a weak preference and I'm happy to change it.

ruiu accepted this revision.Apr 12 2017, 2:47 PM

LGTM

ELF/Target.cpp
1842 ↗(On Diff #94500)

Got it. Thank you for explaining. I think I'm slightly inclined to go with R_ARM_ABS32, but because we already have TLS relocations here, I"m OK with the new code.

This revision is now accepted and ready to land.Apr 12 2017, 2:47 PM
This revision was automatically updated to reflect the committed changes.