Fix constrained empty sections escaping their regions (#2137)

This commit is contained in:
Eldred Habert
2026-09-21 15:54:10 -04:00
committed by GitHub
parent c8b05a6a46
commit 63a06f02c3
8 changed files with 20 additions and 2 deletions
+10 -2
View File
@@ -338,8 +338,16 @@ static void placeSection(Section &section) {
}
}
assignSection(section, location);
return;
// This check safely handles sections with impossible alignment and no fixed address.
// The above `location.address = section.typeInfo().startAddr` would be valid on its own,
// but `location.makeAddressAligned(...)` can increase `location.address` above the valid
// range for its `section`, which would violate an assumption in `assignSection`.
// Note that sections with fixed addresses are handled earlier by `sect_DoSanityChecks`,
// but this check would safely handle them too if they ever reached it.
if (location.address <= section.typeInfo().endAddr() + 1) {
assignSection(section, location);
return;
}
}
FreeSpaceIter iter = tryPlacing(section, location);