@@ -583,30 +583,33 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset) {
583583 actualOffset
584584 );
585585 }
586- } else if (uint32_t actualOffset =
587- ((sect->alignOfs + curOffset) % (1u << sect->align )) % alignSize;
588- sect->align != 0 && actualOffset != offset) {
589- error (
590- " Section is misaligned ($%04" PRIx32 " bytes into the section, expected ALIGN[%" PRIu32
591- " , %" PRIu32 " ], got ALIGN[%" PRIu32 " , %" PRIu32 " ])\n " ,
592- curOffset,
593- alignment,
594- offset,
595- alignment,
596- actualOffset
597- );
598- } else if (alignment >= 16 ) {
599- // Treat an alignment large enough as fixing the address.
600- // Note that this also ensures that a section's alignment never becomes 16 or greater.
601- if (alignment > 16 ) {
602- error (" Alignment must be between 0 and 16, not %u\n " , alignment);
586+ } else {
587+ if (uint32_t actualOffset = (sect->alignOfs + curOffset) % alignSize,
588+ sectAlignSize = 1 << sect->align ;
589+ sect->align != 0 && actualOffset % sectAlignSize != offset % sectAlignSize) {
590+ error (
591+ " Section is misaligned ($%04" PRIx32
592+ " bytes into the section, expected ALIGN[%" PRIu32 " , %" PRIu32
593+ " ], got ALIGN[%" PRIu32 " , %" PRIu32 " ])\n " ,
594+ curOffset,
595+ alignment,
596+ offset,
597+ alignment,
598+ actualOffset
599+ );
600+ } else if (alignment >= 16 ) {
601+ // Treat an alignment large enough as fixing the address.
602+ // Note that this also ensures that a section's alignment never becomes 16 or greater.
603+ if (alignment > 16 ) {
604+ error (" Alignment must be between 0 and 16, not %u\n " , alignment);
605+ }
606+ sect->align = 0 ; // Reset the alignment, since we're fixing the address.
607+ sect->org = offset - curOffset;
608+ } else if (alignment > sect->align ) {
609+ sect->align = alignment;
610+ // We need `(sect->alignOfs + curOffset) % alignSize == offset`
611+ sect->alignOfs = (offset - curOffset) % alignSize;
603612 }
604- sect->align = 0 ; // Reset the alignment, since we're fixing the address.
605- sect->org = offset - curOffset;
606- } else if (alignment > sect->align ) {
607- sect->align = alignment;
608- // We need `(sect->alignOfs + curOffset) % alignSize == offset`
609- sect->alignOfs = (offset - curOffset) % alignSize;
610613 }
611614}
612615
0 commit comments