Improve error message for align failure (#1721)

This commit is contained in:
Rangi
2025-07-06 08:36:11 -04:00
committed by GitHub
parent 185a3b29e6
commit e14f68d1d7
3 changed files with 20 additions and 10 deletions

View File

@@ -572,18 +572,28 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
uint32_t alignSize = 1 << alignment; // Size of an aligned "block" uint32_t alignSize = 1 << alignment; // Size of an aligned "block"
if (sect->org != UINT32_MAX) { if (sect->org != UINT32_MAX) {
if ((sect->org + curOffset - offset) % alignSize) { if (uint32_t actualOffset = (sect->org + curOffset) % alignSize; actualOffset != offset) {
error( error(
"Section's fixed address fails required alignment (PC = $%04" PRIx32 ")\n", "Section is misaligned (at PC = $%04" PRIx32 ", expected ALIGN[%" PRIu32
sect->org + curOffset ", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n",
sect->org + curOffset,
alignment,
offset,
alignment,
actualOffset
); );
} }
} else if (sect->align != 0 } else if (uint32_t actualOffset =
&& (((sect->alignOfs + curOffset) % (1u << sect->align)) - offset) % alignSize) { ((sect->alignOfs + curOffset) % (1u << sect->align)) % alignSize;
sect->align != 0 && actualOffset != offset) {
error( error(
"Section's alignment fails required alignment (offset from section start = $%04" PRIx32 "Section is misaligned ($%04" PRIx32 " bytes into the section, expected ALIGN[%" PRIu32
")\n", ", %" PRIu32 "], got ALIGN[%" PRIu32 ", %" PRIu32 "])\n",
curOffset curOffset,
alignment,
offset,
alignment,
actualOffset
); );
} else if (alignment >= 16) { } else if (alignment >= 16) {
// Treat an alignment large enough as fixing the address. // Treat an alignment large enough as fixing the address.

View File

@@ -1,3 +1,3 @@
error: fragment-align.asm(25): error: fragment-align.asm(25):
Section's alignment fails required alignment (offset from section start = $0004) Section is misaligned ($0004 bytes into the section, expected ALIGN[2, 0], got ALIGN[2, 1])
error: Assembly aborted (1 error)! error: Assembly aborted (1 error)!

View File

@@ -1,5 +1,5 @@
error: invalid-alignment.asm(9): error: invalid-alignment.asm(9):
Section's fixed address fails required alignment (PC = $4000) Section is misaligned (at PC = $4000, expected ALIGN[16, 0], got ALIGN[16, 16384])
error: invalid-alignment.asm(11): error: invalid-alignment.asm(11):
Alignment must be between 0 and 16, not 20 Alignment must be between 0 and 16, not 20
error: invalid-alignment.asm(13): error: invalid-alignment.asm(13):