diff --git a/src/asm/section.cpp b/src/asm/section.cpp index 4acf8b52..5157a6ec 100644 --- a/src/asm/section.cpp +++ b/src/asm/section.cpp @@ -717,8 +717,17 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) { } else if (alignment == 16) { // Treat an alignment large enough as fixing the address. // Note that this also ensures that a section's alignment never becomes 16 or greater. - sect->align = 0; // Reset the alignment, since we're fixing the address. - sect->org = offset - curOffset; + if (offset < curOffset) { + error( + "Section already contains %" PRIu32 + " bytes, higher than this aligned address $%04" PRIx32, + curOffset, + offset + ); + } else { + sect->align = 0; // Reset the alignment, since we're fixing the address. + sect->org = offset - curOffset; + } } else if (alignment > sect->align) { sect->align = alignment; // We need `(sect->alignOfs + curOffset) & alignMask == offset` diff --git a/test/asm/align-beyond-size.asm b/test/asm/align-beyond-size.asm new file mode 100644 index 00000000..a570f6d9 --- /dev/null +++ b/test/asm/align-beyond-size.asm @@ -0,0 +1,3 @@ +SECTION "test", ROM0 +db 1, 2, 3 +align 16, 2 diff --git a/test/asm/align-beyond-size.err b/test/asm/align-beyond-size.err new file mode 100644 index 00000000..73f24fc4 --- /dev/null +++ b/test/asm/align-beyond-size.err @@ -0,0 +1,3 @@ +error: Section already contains 3 bytes, higher than this aligned address $0002 + at align-beyond-size.asm(3) +Assembly aborted with 1 error