Fix alignment compatibility with current lower alignment

This commit is contained in:
Rangi42
2025-07-07 12:19:09 -04:00
committed by Eldred Habert
parent e14f68d1d7
commit 202c91471c
3 changed files with 41 additions and 23 deletions

View File

@@ -583,12 +583,14 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
actualOffset actualOffset
); );
} }
} else if (uint32_t actualOffset = } else {
((sect->alignOfs + curOffset) % (1u << sect->align)) % alignSize; if (uint32_t actualOffset = (sect->alignOfs + curOffset) % alignSize,
sect->align != 0 && actualOffset != offset) { sectAlignSize = 1 << sect->align;
sect->align != 0 && actualOffset % sectAlignSize != offset % sectAlignSize) {
error( error(
"Section is misaligned ($%04" PRIx32 " bytes into the section, expected ALIGN[%" PRIu32 "Section is misaligned ($%04" PRIx32
", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n", " bytes into the section, expected ALIGN[%" PRIu32 ", %" PRIu32
"], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n",
curOffset, curOffset,
alignment, alignment,
offset, offset,
@@ -608,6 +610,7 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
// We need `(sect->alignOfs + curOffset) % alignSize == offset` // We need `(sect->alignOfs + curOffset) % alignSize == offset`
sect->alignOfs = (offset - curOffset) % alignSize; sect->alignOfs = (offset - curOffset) % alignSize;
} }
}
} }
static void growSection(uint32_t growth) { static void growSection(uint32_t growth) {

View File

@@ -0,0 +1,15 @@
SECTION "test1", ROM0
align 4 ; PC = $xxx0
dw $0123
align 4, 2 ; PC = $xxx2
ds align [8, $C2] ; PC = $xxC2 (ds 0)
align 8, $C2 ; PC = $xxC2
dw $4567
SECTION "test2", ROM0[$01C0]
align 4 ; PC = $01C0
dw $89ab
align 4, 2 ; PC = $01C2
ds align [8, $C2] ; PC = $01C2 (ds 0)
align 8, $C2 ; PC = $01C2
dw $cdef

Binary file not shown.