Sort linked sections by alignment before size (#2201)

Note that Libbet has no canonical hash and is sensitive to floating section placement
This commit is contained in:
Rangi authored and GitHub committed 2026-10-11 03:40:15 +02:00
1 parent d73a05aa78
commit 9d6dab13d8
4 files changed
+15 -8

No files matched your search

+9 -7
View File
@@ -416,14 +416,16 @@ static void categorizeSection(Section &section) {
constraints |= ALIGN_CONSTRAINED;
}
// Insert section while keeping the list sorted by decreasing alignment and size
std::deque<Section *> &sections = unassignedSections[constraints];
// Insert section while keeping the list sorted by decreasing size
auto pos = sections.begin();
while (pos != sections.end() && (*pos)->size > section.size) {
++pos;
}
sections.insert(pos, &section);
auto const compareSections = [](Section const *prev, Section const &sect) {
assume(prev->isAlignFixed == sect.isAlignFixed);
if (sect.isAlignFixed && prev->alignMask != sect.alignMask) {
return prev->alignMask > sect.alignMask;
}
return prev->size > sect.size;
};
sections.insert(std::lower_bound(RANGE(sections), section, compareSections), &section);
}
static void checkOverlayCompat() {