Fix underflowing SECTION FRAGMENT fixed address (#2091)

This commit is contained in:
Rangi
2026-09-15 20:22:19 -04:00
committed by GitHub
parent febdf63896
commit d81ab2fb23
3 changed files with 18 additions and 4 deletions
+12 -4
View File
@@ -214,10 +214,8 @@ static void mergeFragments(Section &sect, uint32_t org, uint8_t alignment, uint1
// combination of both. // combination of both.
// The merging is however performed at the *end* of the original section! // The merging is however performed at the *end* of the original section!
if (org != UINT32_MAX) { if (org != UINT32_MAX) {
uint16_t curOrg = org - sect.size; // If both are fixed, they must be compatible
if (uint16_t curOrg = org - sect.size; sect.org != UINT32_MAX && sect.org != curOrg) {
// If both are fixed, they must be the same
if (sect.org != UINT32_MAX && sect.org != curOrg) {
sectError( sectError(
"Section \"%s\" already declared as fixed at incompatible address $%04" PRIx32, "Section \"%s\" already declared as fixed at incompatible address $%04" PRIx32,
sect.name.c_str(), sect.name.c_str(),
@@ -231,6 +229,16 @@ static void mergeFragments(Section &sect, uint32_t org, uint8_t alignment, uint1
sectAlignSize, sectAlignSize,
sect.alignOfs sect.alignOfs
); );
} else if (org < sect.size) {
// Check that `curOrg` did not underflow. Note that it's safe for the above checks to
// use an underflowed value, since their reported errors will still be accurate.
sectError(
"Section \"%s\" already contains %" PRIu32
" bytes, higher than this fragment's fixed address $%04" PRIx32,
sect.name.c_str(),
sect.size,
org
);
} else { } else {
// Otherwise, just override // Otherwise, just override
sect.org = curOrg; sect.org = curOrg;
+4
View File
@@ -0,0 +1,4 @@
SECTION FRAGMENT "test", ROM0
ds $11, 42
SECTION FRAGMENT "test", ROM0[$10]
+2
View File
@@ -0,0 +1,2 @@
FATAL: Section "test" already contains 17 bytes, higher than this fragment's fixed address $0010
at fragment-org-beyond-size.asm(4)