[ELF] - Store pointer to PT_LOAD instead of pointer to first section in OutputSection
It is a bit more convinent and helps to simplify logic
of program headers allocation a little.
Differential revision: https://reviews.llvm.org/D34956
llvm-svn: 312711
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index f464483..3088a32 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -726,6 +726,13 @@
removeEmptyCommands();
}
+static OutputSection *findFirstSection(PhdrEntry *Load) {
+ for (OutputSection *Sec : OutputSections)
+ if (Sec->PtLoad == Load)
+ return Sec;
+ return nullptr;
+}
+
// Try to find an address for the file and program headers output sections,
// which were unconditionally added to the first PT_LOAD segment earlier.
//
@@ -761,21 +768,9 @@
return;
}
- OutputSection *ActualFirst = nullptr;
- for (OutputSection *Sec : OutputSections) {
- if (Sec->FirstInPtLoad == Out::ElfHeader) {
- ActualFirst = Sec;
- break;
- }
- }
- if (ActualFirst) {
- for (OutputSection *Sec : OutputSections)
- if (Sec->FirstInPtLoad == Out::ElfHeader)
- Sec->FirstInPtLoad = ActualFirst;
- FirstPTLoad->First = ActualFirst;
- } else {
- Phdrs.erase(It);
- }
+ Out::ElfHeader->PtLoad = nullptr;
+ Out::ProgramHeaders->PtLoad = nullptr;
+ FirstPTLoad->First = findFirstSection(FirstPTLoad);
llvm::erase_if(Phdrs,
[](const PhdrEntry *E) { return E->p_type == PT_PHDR; });