[PATCH] D16354: [ELF] - Refactoring of Writer<ELFT>::scanRelocs()
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 20 05:26:43 PST 2016
grimar created this revision.
grimar added reviewers: ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.
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.
http://reviews.llvm.org/D16354
Files:
ELF/Writer.cpp
Index: ELF/Writer.cpp
===================================================================
--- ELF/Writer.cpp
+++ ELF/Writer.cpp
@@ -192,6 +192,35 @@
};
}
+template <class ELFT, bool isRela>
+static bool handleTlsRelocations(unsigned Type, SymbolBody *Body,
+ InputSectionBase<ELFT> &C,
+ const Elf_Rel_Impl<ELFT, isRela> &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,35 +248,15 @@
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()))
S->File->IsUsed = true;
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 (handleTlsRelocations<ELFT>(Type, Body, C, RI))
continue;
if (Target->relocNeedsDynRelative(Type)) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16354.45382.patch
Type: text/x-patch
Size: 2596 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160120/90448bf8/attachment.bin>
More information about the llvm-commits
mailing list