[lld] r300192 - [ELF] Tidy up handleARMTlsRelocation [NFC]
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 13 03:56:40 PDT 2017
Author: psmith
Date: Thu Apr 13 05:56:40 2017
New Revision: 300192
URL: http://llvm.org/viewvc/llvm-project?rev=300192&view=rev
Log:
[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
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=300192&r1=300191&r2=300192&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Apr 13 05:56:40 2017
@@ -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(u
// 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(u
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;
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=300192&r1=300191&r2=300192&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Apr 13 05:56:40 2017
@@ -1874,6 +1874,7 @@ void ARMTargetInfo::relocateOne(uint8_t
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:
More information about the llvm-commits
mailing list