[lld] r305156 - Move clearOutputSections before createPhdrs. NFC.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 10 15:12:32 PDT 2017
Author: rafael
Date: Sat Jun 10 17:12:32 2017
New Revision: 305156
URL: http://llvm.org/viewvc/llvm-project?rev=305156&view=rev
Log:
Move clearOutputSections before createPhdrs. NFC.
Modified:
lld/trunk/ELF/LinkerScript.cpp
lld/trunk/ELF/LinkerScript.h
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=305156&r1=305155&r2=305156&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Sat Jun 10 17:12:32 2017
@@ -958,7 +958,8 @@ void LinkerScript::assignAddresses(
}
// Creates program headers as instructed by PHDRS linker script command.
-std::vector<PhdrEntry> LinkerScript::createPhdrs() {
+std::vector<PhdrEntry> LinkerScript::createPhdrs(
+ ArrayRef<OutputSectionCommand *> OutputSectionCommands) {
std::vector<PhdrEntry> Ret;
// Process PHDRS and FILEHDR keywords because they are not
@@ -979,7 +980,8 @@ std::vector<PhdrEntry> LinkerScript::cre
}
// Add output sections to program headers.
- for (OutputSection *Sec : *OutputSections) {
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ OutputSection *Sec = Cmd->Sec;
if (!(Sec->Flags & SHF_ALLOC))
break;
Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=305156&r1=305155&r2=305156&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Sat Jun 10 17:12:32 2017
@@ -274,7 +274,8 @@ public:
void adjustSectionsBeforeSorting();
void adjustSectionsAfterSorting();
- std::vector<PhdrEntry> createPhdrs();
+ std::vector<PhdrEntry>
+ createPhdrs(ArrayRef<OutputSectionCommand *> OutputSectionCommands);
bool ignoreInterpSection();
bool hasLMA(OutputSection *Sec);
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=305156&r1=305155&r2=305156&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Sat Jun 10 17:12:32 2017
@@ -1212,18 +1212,19 @@ template <class ELFT> void Writer<ELFT>:
for (BaseCommand *Base : Script->Opt.Commands)
if (auto *Cmd = dyn_cast<OutputSectionCommand>(Base))
OutputSectionCommands.push_back(Cmd);
+ clearOutputSections();
// Binary and relocatable output does not have PHDRS.
// The headers have to be created before finalize as that can influence the
// image base and the dynamic section on mips includes the image base.
if (!Config->Relocatable && !Config->OFormatBinary) {
- Phdrs = Script->hasPhdrsCommands() ? Script->createPhdrs() : createPhdrs();
+ Phdrs = Script->hasPhdrsCommands()
+ ? Script->createPhdrs(OutputSectionCommands)
+ : createPhdrs();
addPtArmExid(Phdrs);
Out::ProgramHeaders->Size = sizeof(Elf_Phdr) * Phdrs.size();
}
- clearOutputSections();
-
// Compute the size of .rela.dyn and .rela.plt early since we need
// them to populate .dynamic.
for (SyntheticSection *SS : {In<ELFT>::RelaDyn, In<ELFT>::RelaPlt})
@@ -1386,7 +1387,7 @@ template <class ELFT> std::vector<PhdrEn
AddHdr(PT_PHDR, PF_R)->add(Out::ProgramHeaders);
// PT_INTERP must be the second entry if exists.
- if (OutputSection *Sec = findSection(".interp"))
+ if (OutputSection *Sec = findSectionInScript(".interp"))
AddHdr(PT_INTERP, Sec->getPhdrFlags())->add(Sec);
// Add the first PT_LOAD segment for regular output sections.
@@ -1397,7 +1398,8 @@ template <class ELFT> std::vector<PhdrEn
Load->add(Out::ElfHeader);
Load->add(Out::ProgramHeaders);
- for (OutputSection *Sec : OutputSections) {
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ OutputSection *Sec = Cmd->Sec;
if (!(Sec->Flags & SHF_ALLOC))
break;
if (!needsPtLoad(Sec))
@@ -1419,9 +1421,11 @@ template <class ELFT> std::vector<PhdrEn
// Add a TLS segment if any.
PhdrEntry TlsHdr(PT_TLS, PF_R);
- for (OutputSection *Sec : OutputSections)
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ OutputSection *Sec = Cmd->Sec;
if (Sec->Flags & SHF_TLS)
TlsHdr.add(Sec);
+ }
if (TlsHdr.First)
Ret.push_back(std::move(TlsHdr));
@@ -1433,9 +1437,11 @@ template <class ELFT> std::vector<PhdrEn
// PT_GNU_RELRO includes all sections that should be marked as
// read-only by dynamic linker after proccessing relocations.
PhdrEntry RelRo(PT_GNU_RELRO, PF_R);
- for (OutputSection *Sec : OutputSections)
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ OutputSection *Sec = Cmd->Sec;
if (needsPtLoad(Sec) && isRelroSection(Sec))
RelRo.add(Sec);
+ }
if (RelRo.First)
Ret.push_back(std::move(RelRo));
@@ -1447,7 +1453,7 @@ template <class ELFT> std::vector<PhdrEn
// PT_OPENBSD_RANDOMIZE is an OpenBSD-specific feature. That makes
// the dynamic linker fill the segment with random data.
- if (OutputSection *Sec = findSection(".openbsd.randomdata"))
+ if (OutputSection *Sec = findSectionInScript(".openbsd.randomdata"))
AddHdr(PT_OPENBSD_RANDOMIZE, Sec->getPhdrFlags())->add(Sec);
// PT_GNU_STACK is a special section to tell the loader to make the
@@ -1470,7 +1476,8 @@ template <class ELFT> std::vector<PhdrEn
// Create one PT_NOTE per a group of contiguous .note sections.
PhdrEntry *Note = nullptr;
- for (OutputSection *Sec : OutputSections) {
+ for (OutputSectionCommand *Cmd : OutputSectionCommands) {
+ OutputSection *Sec = Cmd->Sec;
if (Sec->Type == SHT_NOTE) {
if (!Note || Script->hasLMA(Sec))
Note = AddHdr(PT_NOTE, PF_R);
@@ -1486,15 +1493,17 @@ template <class ELFT>
void Writer<ELFT>::addPtArmExid(std::vector<PhdrEntry> &Phdrs) {
if (Config->EMachine != EM_ARM)
return;
- auto I = std::find_if(
- OutputSections.begin(), OutputSections.end(),
- [](OutputSection *Sec) { return Sec->Type == SHT_ARM_EXIDX; });
- if (I == OutputSections.end())
+ auto I =
+ std::find_if(OutputSectionCommands.begin(), OutputSectionCommands.end(),
+ [](OutputSectionCommand *Cmd) {
+ return Cmd->Sec->Type == SHT_ARM_EXIDX;
+ });
+ if (I == OutputSectionCommands.end())
return;
// PT_ARM_EXIDX is the ARM EHABI equivalent of PT_GNU_EH_FRAME
PhdrEntry ARMExidx(PT_ARM_EXIDX, PF_R);
- ARMExidx.add(*I);
+ ARMExidx.add((*I)->Sec);
Phdrs.push_back(ARMExidx);
}
More information about the llvm-commits
mailing list