[lld] r258392 - [ELF] - Refactoring of Writer<ELFT>::scanRelocs()
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 21 01:14:23 PST 2016
Author: grimar
Date: Thu Jan 21 03:14:22 2016
New Revision: 258392
URL: http://llvm.org/viewvc/llvm-project?rev=258392&view=rev
Log:
[ELF] - Refactoring of Writer<ELFT>::scanRelocs()
Code for handling TLS relocations was moved out scanRelocs() to new function handleTlsRelocations().
That is because scanRelocs already too large to put more TLS code into it.
Differential revision: http://reviews.llvm.org/D16354
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=258392&r1=258391&r2=258392&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Jan 21 03:14:22 2016
@@ -192,6 +192,34 @@ template <bool Is64Bits> struct DenseMap
};
}
+template <class ELFT, class RelT>
+static bool handleTlsRelocation(unsigned Type, SymbolBody *Body,
+ InputSectionBase<ELFT> &C, RelT &RI) {
+ if (Target->isTlsLocalDynamicReloc(Type)) {
+ if (Target->isTlsOptimized(Type, nullptr))
+ return true;
+ if (Out<ELFT>::Got->addCurrentModuleTlsIndex())
+ Out<ELFT>::RelaDyn->addReloc({&C, &RI});
+ return true;
+ }
+
+ if (!Body || !Body->isTls())
+ return false;
+
+ if (Target->isTlsGlobalDynamicReloc(Type)) {
+ bool Opt = Target->isTlsOptimized(Type, Body);
+ if (!Opt && Out<ELFT>::Got->addDynTlsEntry(Body)) {
+ Out<ELFT>::RelaDyn->addReloc({&C, &RI});
+ Out<ELFT>::RelaDyn->addReloc({nullptr, nullptr});
+ Body->setUsedInDynamicReloc();
+ return true;
+ }
+ if (!canBePreempted(Body, true))
+ return true;
+ }
+ return !Target->isTlsDynReloc(Type, *Body);
+}
+
// The reason we have to do this early scan is as follows
// * To mmap the output file, we need to know the size
// * For that, we need to know how many dynamic relocs we will have.
@@ -219,14 +247,6 @@ void Writer<ELFT>::scanRelocs(
if (Target->isGotRelative(Type))
HasGotOffRel = true;
- if (Target->isTlsLocalDynamicReloc(Type)) {
- if (Target->isTlsOptimized(Type, nullptr))
- continue;
- if (Out<ELFT>::Got->addCurrentModuleTlsIndex())
- Out<ELFT>::RelaDyn->addReloc({&C, &RI});
- continue;
- }
-
// Set "used" bit for --as-needed.
if (Body && Body->isUndefined() && !Body->isWeak())
if (auto *S = dyn_cast<SharedSymbol<ELFT>>(Body->repl()))
@@ -235,19 +255,7 @@ void Writer<ELFT>::scanRelocs(
if (Body)
Body = Body->repl();
- if (Body && Body->isTls() && Target->isTlsGlobalDynamicReloc(Type)) {
- bool Opt = Target->isTlsOptimized(Type, Body);
- if (!Opt && Out<ELFT>::Got->addDynTlsEntry(Body)) {
- Out<ELFT>::RelaDyn->addReloc({&C, &RI});
- Out<ELFT>::RelaDyn->addReloc({nullptr, nullptr});
- Body->setUsedInDynamicReloc();
- continue;
- }
- if (!canBePreempted(Body, true))
- continue;
- }
-
- if (Body && Body->isTls() && !Target->isTlsDynReloc(Type, *Body))
+ if (handleTlsRelocation<ELFT>(Type, Body, C, RI))
continue;
if (Target->relocNeedsDynRelative(Type)) {
More information about the llvm-commits
mailing list