Skip to content

Commit 4dc4bc4

Browse files
committedApr 13, 2017
[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
1 parent 859f80b commit 4dc4bc4

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed
 

‎lld/ELF/Relocations.cpp

+17-19
Original file line numberDiff line numberDiff line change
@@ -147,25 +147,27 @@ template <class ELFT>
147147
static unsigned handleARMTlsRelocation(uint32_t Type, SymbolBody &Body,
148148
InputSectionBase &C, uint64_t Offset,
149149
int64_t Addend, RelExpr Expr) {
150-
auto addModuleReloc = [&](uint64_t Off, bool LD) {
151-
// The Dynamic TLS Module Index Relocation can be statically resolved to 1
152-
// if we know that the TLS Symbol is in an executable.
153-
if (!Body.isPreemptible() && !Config->Pic)
154-
In<ELFT>::Got->Relocations.push_back(
155-
{R_ABS, Target->TlsModuleIndexRel, Off, 0, &Body});
156-
else {
157-
SymbolBody *Dest = LD ? nullptr : &Body;
158-
In<ELFT>::RelaDyn->addReloc(
159-
{Target->TlsModuleIndexRel, In<ELFT>::Got, Off, false, Dest, 0});
160-
}
150+
// The Dynamic TLS Module Index Relocation for a symbol defined in an
151+
// executable is always 1. If the target Symbol is not preemtible then
152+
// we know the offset into the TLS block at static link time.
153+
bool NeedDynId = Body.isPreemptible() || Config->Shared;
154+
bool NeedDynOff = Body.isPreemptible();
155+
156+
auto AddTlsReloc = [&](uint64_t Off, uint32_t Type, SymbolBody *Dest,
157+
bool Dyn) {
158+
if (Dyn)
159+
In<ELFT>::RelaDyn->addReloc({Type, In<ELFT>::Got, Off, false, Dest, 0});
160+
else
161+
In<ELFT>::Got->Relocations.push_back({R_ABS, Type, Off, 0, Dest});
161162
};
162163

163164
// Local Dynamic is for access to module local TLS variables, while still
164165
// being suitable for being dynamically loaded via dlopen.
165166
// GOT[e0] is the module index, with a special value of 0 for the current
166167
// module. GOT[e1] is unused. There only needs to be one module index entry.
167168
if (Expr == R_TLSLD_PC && In<ELFT>::Got->addTlsIndex()) {
168-
addModuleReloc(In<ELFT>::Got->getTlsIndexOff(), true);
169+
AddTlsReloc(In<ELFT>::Got->getTlsIndexOff(), Target->TlsModuleIndexRel,
170+
NeedDynId ? nullptr : &Body, NeedDynId);
169171
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
170172
return 1;
171173
}
@@ -176,13 +178,9 @@ static unsigned handleARMTlsRelocation(uint32_t Type, SymbolBody &Body,
176178
if (Expr == R_TLSGD_PC) {
177179
if (In<ELFT>::Got->addDynTlsEntry(Body)) {
178180
uint64_t Off = In<ELFT>::Got->getGlobalDynOffset(Body);
179-
addModuleReloc(Off, false);
180-
if (Body.isPreemptible())
181-
In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, In<ELFT>::Got,
182-
Off + Config->Wordsize, false, &Body, 0});
183-
else
184-
In<ELFT>::Got->Relocations.push_back(
185-
{R_ABS, R_ARM_ABS32, Off + Config->Wordsize, 0, &Body});
181+
AddTlsReloc(Off, Target->TlsModuleIndexRel, &Body, NeedDynId);
182+
AddTlsReloc(Off + Config->Wordsize, Target->TlsOffsetRel, &Body,
183+
NeedDynOff);
186184
}
187185
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
188186
return 1;

‎lld/ELF/Target.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1874,6 +1874,7 @@ void ARMTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type,
18741874
case R_ARM_TLS_LDO32:
18751875
case R_ARM_TLS_LE32:
18761876
case R_ARM_TLS_TPOFF32:
1877+
case R_ARM_TLS_DTPOFF32:
18771878
write32le(Loc, Val);
18781879
break;
18791880
case R_ARM_TLS_DTPMOD32:

0 commit comments

Comments
 (0)
Please sign in to comment.