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
+2
View File
@@ -0,0 +1,2 @@
SECTION "fixed", ROM0[$4321]
assert @ == $4321
+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);
+2
View File
@@ -0,0 +1,2 @@
FATAL: Unable to place "aligned" (ROM0 section) with align mask $8000 and offset $6420
Linking aborted with 1 error
+2
View File
@@ -0,0 +1,2 @@
SECTION "aligned", ROM0, ALIGN[15, $6420]
assert @ == $6420
+2
View File
@@ -0,0 +1,2 @@
error: Section "z"'s fixed address $4321 is outside of range [$0000; $3fff]
Linking failed with 1 error
View File
+2
View File
@@ -0,0 +1,2 @@
SECTION "z", ROM0[$4321]
assert @ == $4321