Do not mutate Script->Opt.Commands from a leaf helper function.

Factory::addInputSec added an output section to Script->Opt.Commands,
but that is too subtle. This patch makes it explicit so that it is easy
to see when a new element is added to Script->Opt.Commands.

llvm-svn: 315129
This commit is contained in:
Rui Ueyama
2017-10-06 23:34:43 +00:00
parent b12792a4c0
commit c54d5b16d5
4 changed files with 38 additions and 28 deletions

View File

@@ -417,6 +417,7 @@ void LinkerScript::processCommands(OutputSectionFactory &Factory) {
// Add input sections to an output section.
for (InputSectionBase *S : V)
Factory.addInputSec(S, Sec->Name, Sec);
assert(Sec->SectionIndex == INT_MAX);
Sec->SectionIndex = I;
if (Sec->Noload)
@@ -466,10 +467,12 @@ void LinkerScript::addOrphanSections(OutputSectionFactory &Factory) {
if (OutputSection *Sec = findByName(
makeArrayRef(Opt.Commands).slice(0, End), Name)) {
Factory.addInputSec(S, Name, Sec);
} else {
Factory.addInputSec(S, Name, nullptr);
assert(S->getOutputSection()->SectionIndex == INT_MAX);
continue;
}
if (OutputSection *OS = Factory.addInputSec(S, Name))
Script->Opt.Commands.push_back(OS);
assert(S->getOutputSection()->SectionIndex == INT_MAX);
}
}