[ELF] Tidy up handleARMTlsRelocation [NFC]

Replace addModuleReloc with AddTlsReloc so that we can use it for both the
module relocation and the offset relocation.

Differential Revision: https://reviews.llvm.org/D31751

llvm-svn: 300192
This commit is contained in:
Peter Smith 2017-04-13 10:56:40 +00:00
parent 859f80b06f
commit 4dc4bc4e3c
2 changed files with 18 additions and 19 deletions

View File

@ -147,17 +147,18 @@ template <class ELFT>
static unsigned handleARMTlsRelocation(uint32_t Type, SymbolBody &Body,
InputSectionBase &C, uint64_t Offset,
int64_t Addend, RelExpr Expr) {
auto addModuleReloc = [&](uint64_t Off, bool LD) {
// The Dynamic TLS Module Index Relocation can be statically resolved to 1
// if we know that the TLS Symbol is in an executable.
if (!Body.isPreemptible() && !Config->Pic)
In<ELFT>::Got->Relocations.push_back(
{R_ABS, Target->TlsModuleIndexRel, Off, 0, &Body});
else {
SymbolBody *Dest = LD ? nullptr : &Body;
In<ELFT>::RelaDyn->addReloc(
{Target->TlsModuleIndexRel, In<ELFT>::Got, Off, false, Dest, 0});
}
// The Dynamic TLS Module Index Relocation for a symbol defined in an
// executable is always 1. If the target Symbol is not preemtible then
// we know the offset into the TLS block at static link time.
bool NeedDynId = Body.isPreemptible() || Config->Shared;
bool NeedDynOff = Body.isPreemptible();
auto AddTlsReloc = [&](uint64_t Off, uint32_t Type, SymbolBody *Dest,
bool Dyn) {
if (Dyn)
In<ELFT>::RelaDyn->addReloc({Type, In<ELFT>::Got, Off, false, Dest, 0});
else
In<ELFT>::Got->Relocations.push_back({R_ABS, Type, Off, 0, Dest});
};
// Local Dynamic is for access to module local TLS variables, while still
@ -165,7 +166,8 @@ static unsigned handleARMTlsRelocation(uint32_t Type, SymbolBody &Body,
// GOT[e0] is the module index, with a special value of 0 for the current
// module. GOT[e1] is unused. There only needs to be one module index entry.
if (Expr == R_TLSLD_PC && In<ELFT>::Got->addTlsIndex()) {
addModuleReloc(In<ELFT>::Got->getTlsIndexOff(), true);
AddTlsReloc(In<ELFT>::Got->getTlsIndexOff(), Target->TlsModuleIndexRel,
NeedDynId ? nullptr : &Body, NeedDynId);
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
return 1;
}
@ -176,13 +178,9 @@ static unsigned handleARMTlsRelocation(uint32_t Type, SymbolBody &Body,
if (Expr == R_TLSGD_PC) {
if (In<ELFT>::Got->addDynTlsEntry(Body)) {
uint64_t Off = In<ELFT>::Got->getGlobalDynOffset(Body);
addModuleReloc(Off, false);
if (Body.isPreemptible())
In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, In<ELFT>::Got,
Off + Config->Wordsize, false, &Body, 0});
else
In<ELFT>::Got->Relocations.push_back(
{R_ABS, R_ARM_ABS32, Off + Config->Wordsize, 0, &Body});
AddTlsReloc(Off, Target->TlsModuleIndexRel, &Body, NeedDynId);
AddTlsReloc(Off + Config->Wordsize, Target->TlsOffsetRel, &Body,
NeedDynOff);
}
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
return 1;

View File

@ -1874,6 +1874,7 @@ void ARMTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
case R_ARM_TLS_LDO32:
case R_ARM_TLS_LE32:
case R_ARM_TLS_TPOFF32:
case R_ARM_TLS_DTPOFF32:
write32le(Loc, Val);
break;
case R_ARM_TLS_DTPMOD32: