mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Fix intra-section ALIGN not computing offset correctly
This commit is contained in:
@@ -383,24 +383,24 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
|||||||
{
|
{
|
||||||
checksection();
|
checksection();
|
||||||
struct Section *sect = sect_GetSymbolSection();
|
struct Section *sect = sect_GetSymbolSection();
|
||||||
|
uint16_t alignSize = 1 << alignment; // Size of an aligned "block"
|
||||||
|
|
||||||
if (sect->org != -1) {
|
if (sect->org != -1) {
|
||||||
if ((sym_GetPCValue() - offset) % (1 << alignment))
|
if ((sym_GetPCValue() - offset) % alignSize)
|
||||||
error("Section's fixed address fails required alignment (PC = $%04"
|
error("Section's fixed address fails required alignment (PC = $%04" PRIx32
|
||||||
PRIx32 ")\n", sym_GetPCValue());
|
")\n", sym_GetPCValue());
|
||||||
} else if (sect->align != 0) {
|
} else if (sect->align != 0) {
|
||||||
if ((((sect->alignOfs + curOffset) % (1 << sect->align))
|
if ((((sect->alignOfs + curOffset) % (1 << sect->align)) - offset) % alignSize) {
|
||||||
- offset) % (1 << alignment)) {
|
|
||||||
error("Section's alignment fails required alignment (offset from section start = $%04"
|
error("Section's alignment fails required alignment (offset from section start = $%04"
|
||||||
PRIx32 ")\n", curOffset);
|
PRIx32 ")\n", curOffset);
|
||||||
} else if (alignment > sect->align) {
|
} else if (alignment > sect->align) {
|
||||||
sect->align = alignment;
|
sect->align = alignment;
|
||||||
sect->alignOfs =
|
sect->alignOfs = (offset - curOffset) % alignSize;
|
||||||
(offset - curOffset) % (1 << alignment);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sect->align = alignment;
|
sect->align = alignment;
|
||||||
sect->alignOfs = offset;
|
// We need `(sect->alignOfs + curOffset) % alignSize == offset
|
||||||
|
sect->alignOfs = (offset - curOffset) % alignSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user