[ELF] - Do not crash when discarding sections that are referenced by others.

SHF_LINK_ORDER sections adds special ordering requirements.
Such sections references other sections. Previously we would crash
if section that other were referenced to was discarded by script.

Patch fixes that by discarding all dependent sections in that case.
It supports chained dependencies, testcase is provided.

Differential revision: https://reviews.llvm.org/D30033

llvm-svn: 295332
This commit is contained in:
George Rimar
2017-02-16 16:06:13 +00:00
parent cb2d950214
commit 505ac8dc41
2 changed files with 37 additions and 0 deletions

View File

@@ -277,6 +277,11 @@ void LinkerScript<ELFT>::discard(ArrayRef<InputSectionBase<ELFT> *> V) {
for (InputSectionBase<ELFT> *S : V) {
S->Live = false;
reportDiscarded(S);
InputSection<ELFT> *IS = dyn_cast<InputSection<ELFT>>(S);
if (!IS || IS->DependentSections.empty())
continue;
discard(IS->DependentSections);
}
}