[lld] r304782 - [ELF] Refactor ThunkCreator to not key on OutputSection for Thunks
Peter Smith via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 6 02:42:44 PDT 2017
Author: psmith
Date: Tue Jun 6 04:42:44 2017
New Revision: 304782
URL: http://llvm.org/viewvc/llvm-project?rev=304782&view=rev
Log:
[ELF] Refactor ThunkCreator to not key on OutputSection for Thunks
In preparation for inserting Thunks into InputSectionDescriptions this
simple change associates added Thunks with a vector of InputSections instead
of an OutputSection. As of now we are just using OutputSection::Sections.
Differential Revision: https://reviews.llvm.org/D33832
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Relocations.h
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=304782&r1=304781&r2=304782&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jun 6 04:42:44 2017
@@ -967,33 +967,38 @@ template <class ELFT> void elf::scanRelo
// in the Sections vector, and recalculate the InputSection output section
// offsets.
// This may invalidate any output section offsets stored outside of InputSection
-void ThunkCreator::mergeThunks(OutputSection *OS,
- std::vector<ThunkSection *> &Thunks) {
- // Order Thunks in ascending OutSecOff
- auto ThunkCmp = [](const ThunkSection *A, const ThunkSection *B) {
- return A->OutSecOff < B->OutSecOff;
- };
- std::stable_sort(Thunks.begin(), Thunks.end(), ThunkCmp);
-
- // Merge sorted vectors of Thunks and InputSections by OutSecOff
- std::vector<InputSection *> Tmp;
- Tmp.reserve(OS->Sections.size() + Thunks.size());
- auto MergeCmp = [](const InputSection *A, const InputSection *B) {
- // std::merge requires a strict weak ordering.
- if (A->OutSecOff < B->OutSecOff)
- return true;
- if (A->OutSecOff == B->OutSecOff)
- // Check if Thunk is immediately before any specific Target InputSection
- // for example Mips LA25 Thunks.
- if (auto *TA = dyn_cast<ThunkSection>(A))
- if (TA && TA->getTargetInputSection() == B)
- return true;
- return false;
- };
- std::merge(OS->Sections.begin(), OS->Sections.end(), Thunks.begin(),
- Thunks.end(), std::back_inserter(Tmp), MergeCmp);
- OS->Sections = std::move(Tmp);
- OS->assignOffsets();
+void ThunkCreator::mergeThunks() {
+ for (auto &KV : ThunkSections) {
+ std::vector<InputSection *> *ISR = KV.first;
+ std::vector<ThunkSection *> &Thunks = KV.second;
+
+ // Order Thunks in ascending OutSecOff
+ auto ThunkCmp = [](const ThunkSection *A, const ThunkSection *B) {
+ return A->OutSecOff < B->OutSecOff;
+ };
+ std::stable_sort(Thunks.begin(), Thunks.end(), ThunkCmp);
+
+ // Merge sorted vectors of Thunks and InputSections by OutSecOff
+ std::vector<InputSection *> Tmp;
+ Tmp.reserve(ISR->size() + Thunks.size());
+ auto MergeCmp = [](const InputSection *A, const InputSection *B) {
+ // std::merge requires a strict weak ordering.
+ if (A->OutSecOff < B->OutSecOff)
+ return true;
+ if (A->OutSecOff == B->OutSecOff)
+ // Check if Thunk is immediately before any specific Target InputSection
+ // for example Mips LA25 Thunks.
+ if (auto *TA = dyn_cast<ThunkSection>(A))
+ if (TA && TA->getTargetInputSection() == B)
+ return true;
+ return false;
+ };
+ std::merge(ISR->begin(), ISR->end(), Thunks.begin(), Thunks.end(),
+ std::back_inserter(Tmp), MergeCmp);
+ OutputSection *OS = Thunks.front()->getParent();
+ OS->Sections = std::move(Tmp);
+ OS->assignOffsets();
+ }
}
ThunkSection *ThunkCreator::getOSThunkSec(ThunkSection *&TS,
@@ -1006,7 +1011,7 @@ ThunkSection *ThunkCreator::getOSThunkSe
break;
}
TS = make<ThunkSection>(OS, Off);
- ThunkSections[OS].push_back(TS);
+ ThunkSections[&OS->Sections].push_back(TS);
}
return TS;
}
@@ -1017,7 +1022,7 @@ ThunkSection *ThunkCreator::getISThunkSe
return TS;
auto *TOS = IS->getParent();
TS = make<ThunkSection>(TOS, IS->OutSecOff);
- ThunkSections[TOS].push_back(TS);
+ ThunkSections[&TOS->Sections].push_back(TS);
ThunkedSections[IS] = TS;
return TS;
}
@@ -1074,8 +1079,7 @@ bool ThunkCreator::createThunks(ArrayRef
}
// Merge all created synthetic ThunkSections back into OutputSection
- for (auto &KV : ThunkSections)
- mergeThunks(KV.first, KV.second);
+ mergeThunks();
return !ThunkSections.empty();
}
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=304782&r1=304781&r2=304782&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Tue Jun 6 04:42:44 2017
@@ -126,7 +126,7 @@ public:
bool createThunks(ArrayRef<OutputSection *> OutputSections);
private:
- void mergeThunks(OutputSection *OS, std::vector<ThunkSection *> &Thunks);
+ void mergeThunks();
ThunkSection *getOSThunkSec(ThunkSection *&TS, OutputSection *OS);
ThunkSection *getISThunkSec(InputSection *IS, OutputSection *OS);
std::pair<Thunk *, bool> getThunk(SymbolBody &Body, uint32_t Type);
@@ -138,7 +138,8 @@ private:
llvm::DenseMap<InputSection *, ThunkSection *> ThunkedSections;
// Track the ThunksSections that need to be inserted into an OutputSection
- std::map<OutputSection *, std::vector<ThunkSection *>> ThunkSections;
+ std::map<std::vector<InputSection *> *, std::vector<ThunkSection *>>
+ ThunkSections;
};
// Return a int64_t to make sure we get the sign extension out of the way as
More information about the llvm-commits
mailing list