ELF: Don't process the partition end marker during combineEhSections().
Otherwise the getPartition() accessor may return an OOB pointer. Found
using _GLIBCXX_DEBUG.
The error is benign (we never dereference the pointer for the end marker)
so this wasn't caught by e.g. the sanitizer bots.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@363026 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/ELF/Writer.cpp b/ELF/Writer.cpp
index 6614d9c..c6ba893 100644
--- a/ELF/Writer.cpp
+++ b/ELF/Writer.cpp
@@ -178,7 +178,9 @@
template <class ELFT> static void combineEhSections() {
for (InputSectionBase *&S : InputSections) {
- if (!S->isLive())
+ // Ignore dead sections and the partition end marker (.part.end),
+ // whose partition number is out of bounds.
+ if (!S->isLive() || S->Partition == 255)
continue;
Partition &Part = S->getPartition();
@@ -442,7 +444,7 @@
if (Partitions.size() != 1) {
// Create the partition end marker. This needs to be in partition number 255
// so that it is sorted after all other partitions. It also has other
- // special handling (see createPhdrs()).
+ // special handling (see createPhdrs() and combineEhSections()).
In.PartEnd = make<BssSection>(".part.end", Config->MaxPageSize, 1);
In.PartEnd->Partition = 255;
Add(In.PartEnd);