[ELF] - Fix crash relative to SHF_LINK_ORDER sections.
authorGeorge Rimar <grimar@accesssoftek.com>
Thu, 8 Mar 2018 15:06:58 +0000 (15:06 +0000)
committerGeorge Rimar <grimar@accesssoftek.com>
Thu, 8 Mar 2018 15:06:58 +0000 (15:06 +0000)
commit1136ec64e86973dc9f3b0da528d752029dc33731
tree7e08387b924e29f25800a5dd52b57755a1f58fc4
parent6d1aec126078d75d8fe6971d6b62a376c6d1de1a
[ELF] - Fix crash relative to SHF_LINK_ORDER sections.

Our code assumes all input sections in an output SHF_LINK_ORDER
section has SHF_LINK_ORDER flag. We do not check that and that can cause a crash.

That happens because we call
std::stable_sort(Sections.begin(), Sections.end(), compareByFilePosition);,
where compareByFilePosition predicate does not expect to see
null when calls getLinkOrderDep.

The same might happen when sections refer to non-regular sections.
Test cases demonstrate the issues, patch fixes them.

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

llvm-svn: 327006
lld/ELF/InputFiles.cpp
lld/ELF/InputSection.cpp
lld/ELF/OutputSections.cpp
lld/test/ELF/section-metadata-err.s
lld/test/ELF/section-metadata-err2.s [new file with mode: 0644]
lld/test/ELF/section-metadata-err3.s [new file with mode: 0644]