Create a vector containing all input sections.
Previously, we do this piece of code to iterate over all input sections.
for (elf::ObjectFile<ELFT> *F : Symtab.getObjectFiles())
for (InputSectionBase<ELFT> *S : F->getSections())
It turned out that this mechanisms doesn't work well with synthetic
input sections because synthetic input sections don't belong to any
input file.
This patch defines a vector that contains all input sections including
synthetic ones.
llvm-svn: 286051
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 9b19b65..dd46fae 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -29,8 +29,8 @@
#include "Symbols.h"
#include "Target.h"
#include "Writer.h"
-#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/Casting.h"
@@ -193,14 +193,20 @@
// and attach them to I.
for (SectionPattern &Pat : I->SectionPatterns) {
size_t SizeBefore = I->Sections.size();
- for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles()) {
- StringRef Filename = sys::path::filename(F->getName());
+
+ for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections) {
+ if (isDiscarded(S) || S->OutSec)
+ continue;
+
+ StringRef Filename;
+ if (elf::ObjectFile<ELFT> *F = S->getFile())
+ Filename = sys::path::filename(F->getName());
+
if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename))
continue;
- for (InputSectionBase<ELFT> *S : F->getSections())
- if (!isDiscarded(S) && !S->OutSec && Pat.SectionPat.match(S->Name))
- I->Sections.push_back(S);
+ if (Pat.SectionPat.match(S->Name))
+ I->Sections.push_back(S);
if (Pat.SectionPat.match("COMMON"))
I->Sections.push_back(InputSection<ELFT>::CommonInputSection);
}
@@ -363,11 +369,11 @@
template <class ELFT>
void LinkerScript<ELFT>::createSections(OutputSectionFactory<ELFT> &Factory) {
processCommands(Factory);
+
// Add orphan sections.
- for (ObjectFile<ELFT> *F : Symtab<ELFT>::X->getObjectFiles())
- for (InputSectionBase<ELFT> *S : F->getSections())
- if (!isDiscarded(S) && !S->OutSec)
- addSection(Factory, S, getOutputSectionName(S->Name));
+ for (InputSectionBase<ELFT> *S : Symtab<ELFT>::X->Sections)
+ if (!isDiscarded(S) && !S->OutSec)
+ addSection(Factory, S, getOutputSectionName(S->Name));
}
// Sets value of a section-defined symbol. Two kinds of