summaryrefslogtreecommitdiffstats
path: root/lld/ELF/LinkerScript.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2017-04-05 02:05:48 +0000
committerRui Ueyama <ruiu@google.com>2017-04-05 02:05:48 +0000
commit72e107f30241b47c9b440ba5362c1cdc9b4a08e4 (patch)
tree293fd7dff2db263b9e930015cb6e1c1dd999439d /lld/ELF/LinkerScript.cpp
parent0932cdb04941ab8786dc5bfcb1348711350fcfab (diff)
downloadbcm5719-llvm-72e107f30241b47c9b440ba5362c1cdc9b4a08e4.tar.gz
bcm5719-llvm-72e107f30241b47c9b440ba5362c1cdc9b4a08e4.zip
Return a result from computeInputSections instead of mutating its argument.
This should improve readability. llvm-svn: 299498
Diffstat (limited to 'lld/ELF/LinkerScript.cpp')
-rw-r--r--lld/ELF/LinkerScript.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 65bb362f383..d6199a94e9f 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -330,28 +330,32 @@ static void sortSections(InputSectionBase **Begin, InputSectionBase **End,
}
// Compute and remember which sections the InputSectionDescription matches.
-void LinkerScript::computeInputSections(InputSectionDescription *I) {
- // Collects all sections that satisfy constraints of I
- // and attach them to I.
- for (SectionPattern &Pat : I->SectionPatterns) {
- size_t SizeBefore = I->Sections.size();
-
- for (InputSectionBase *S : InputSections) {
- if (S->Assigned)
+std::vector<InputSectionBase *>
+LinkerScript::computeInputSections(const InputSectionDescription *Cmd) {
+ std::vector<InputSectionBase *> Ret;
+
+ // Collects all sections that satisfy constraints of Cmd.
+ for (const SectionPattern &Pat : Cmd->SectionPatterns) {
+ size_t SizeBefore = Ret.size();
+
+ for (InputSectionBase *Sec : InputSections) {
+ if (Sec->Assigned)
continue;
+
// For -emit-relocs we have to ignore entries like
// .rela.dyn : { *(.rela.data) }
// which are common because they are in the default bfd script.
- if (S->Type == SHT_REL || S->Type == SHT_RELA)
+ if (Sec->Type == SHT_REL || Sec->Type == SHT_RELA)
continue;
- StringRef Filename = basename(S);
- if (!I->FilePat.match(Filename) || Pat.ExcludedFilePat.match(Filename))
+ StringRef Filename = basename(Sec);
+ if (!Cmd->FilePat.match(Filename) ||
+ Pat.ExcludedFilePat.match(Filename) ||
+ !Pat.SectionPat.match(Sec->Name))
continue;
- if (!Pat.SectionPat.match(S->Name))
- continue;
- I->Sections.push_back(S);
- S->Assigned = true;
+
+ Ret.push_back(Sec);
+ Sec->Assigned = true;
}
// Sort sections as instructed by SORT-family commands and --sort-section
@@ -365,8 +369,8 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) {
// --sort-section is handled as an inner SORT command.
// 3. If one SORT command is given, and if it is SORT_NONE, don't sort.
// 4. If no SORT command is given, sort according to --sort-section.
- InputSectionBase **Begin = I->Sections.data() + SizeBefore;
- InputSectionBase **End = I->Sections.data() + I->Sections.size();
+ InputSectionBase **Begin = Ret.data() + SizeBefore;
+ InputSectionBase **End = Ret.data() + Ret.size();
if (Pat.SortOuter != SortSectionPolicy::None) {
if (Pat.SortInner == SortSectionPolicy::Default)
sortSections(Begin, End, Config->SortSection);
@@ -375,6 +379,7 @@ void LinkerScript::computeInputSections(InputSectionDescription *I) {
sortSections(Begin, End, Pat.SortOuter);
}
}
+ return Ret;
}
void LinkerScript::discard(ArrayRef<InputSectionBase *> V) {
@@ -394,7 +399,8 @@ LinkerScript::createInputSectionList(OutputSectionCommand &OutCmd) {
auto *Cmd = dyn_cast<InputSectionDescription>(Base.get());
if (!Cmd)
continue;
- computeInputSections(Cmd);
+
+ Cmd->Sections = computeInputSections(Cmd);
for (InputSectionBase *S : Cmd->Sections)
Ret.push_back(static_cast<InputSectionBase *>(S));
}
OpenPOWER on IntegriCloud