[PATCH] D31751: [LLD][ELF] Tidy up handleARMTlsRelocation [NFC]
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 6 03:32:54 PDT 2017
peter.smith created this revision.
Herald added subscribers: rengolin, aemerson.
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 https://reviews.llvm.org/D31749 that doesn't obscure the fix (as observed in https://reviews.llvm.org/D31672).
https://reviews.llvm.org/D31751
Files:
ELF/Relocations.cpp
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -154,25 +154,27 @@
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)
- Got->Relocations.push_back(
- {R_ABS, Target->TlsModuleIndexRel, Off, 0, &Body});
- else {
- SymbolBody *Dest = LD ? nullptr : &Body;
- In<ELFT>::RelaDyn->addReloc(
- {Target->TlsModuleIndexRel, 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->Pic;
+ bool NeedDynOff = Body.isPreemptible();
+
+ auto AddTlsReloc = [&](uint64_t Off, uint32_t Type, SymbolBody *Dest,
+ bool Dyn) {
+ if (Dyn)
+ In<ELFT>::RelaDyn->addReloc({Type, Got, Off, false, Dest, 0});
+ else
+ Got->Relocations.push_back({R_ABS, Type, Off, 0, Dest});
};
// Local Dynamic is for access to module local TLS variables, while still
// being suitable for being dynamically loaded via dlopen.
// 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 && Got->addTlsIndex()) {
- addModuleReloc(Got->getTlsIndexOff(), true);
+ AddTlsReloc(Got->getTlsIndexOff(), Target->TlsModuleIndexRel,
+ NeedDynId ? nullptr : &Body, NeedDynId);
C.Relocations.push_back({Expr, Type, Offset, Addend, &Body});
return 1;
}
@@ -183,13 +185,9 @@
if (Expr == R_TLSGD_PC) {
if (Got->addDynTlsEntry(Body)) {
uint64_t Off = Got->getGlobalDynOffset(Body);
- addModuleReloc(Off, false);
- if (Body.isPreemptible())
- In<ELFT>::RelaDyn->addReloc({Target->TlsOffsetRel, Got,
- Off + Config->Wordsize, false, &Body, 0});
- else
- Got->Relocations.push_back(
- {R_ABS, Target->TlsOffsetRel, 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31751.94342.patch
Type: text/x-patch
Size: 2829 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170406/0a983faf/attachment.bin>
More information about the llvm-commits
mailing list