diff options
author | George Rimar <grimar@accesssoftek.com> | 2016-01-21 09:14:22 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2016-01-21 09:14:22 +0000 |
commit | bfd29a1567ed3d208bcf45858199fb24a2eec52e (patch) | |
tree | 2e9bd122219c100f9e9aabde421e435787bafbcf | |
parent | e902459c4b3e5dbe62ff31a52c2203cb4e89f338 (diff) | |
download | bcm5719-llvm-bfd29a1567ed3d208bcf45858199fb24a2eec52e.tar.gz bcm5719-llvm-bfd29a1567ed3d208bcf45858199fb24a2eec52e.zip |
[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
llvm-svn: 258392
-rw-r--r-- | lld/ELF/Writer.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index ce334aa5e66..6828b11cf74 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -192,6 +192,34 @@ template <bool Is64Bits> struct DenseMapInfo<SectionKey<Is64Bits>> { }; } +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)) { |