mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Fix bugs with LOAD section size
LOAD blocks did not properly update their parent's size until after closed Additionally, section size wasn't correctly sanitized inside LOAD blocks
This commit is contained in:
@@ -51,23 +51,29 @@ static inline void checkcodesection(void)
|
|||||||
fatalerror("UNIONs cannot contain code or data");
|
fatalerror("UNIONs cannot contain code or data");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void checkSectionSize(struct Section const *sect, uint32_t size)
|
||||||
|
{
|
||||||
|
uint32_t maxSize = maxsize[sect->nType];
|
||||||
|
|
||||||
|
if (size > maxSize)
|
||||||
|
fatalerror("Section '%s' grew too big (max size = 0x%" PRIX32 " bytes, reached 0x%" PRIX32 ").",
|
||||||
|
sect->pzName, maxSize, size);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check if the section has grown too much.
|
* Check if the section has grown too much.
|
||||||
*/
|
*/
|
||||||
static void reserveSpace(uint32_t delta_size)
|
static inline void reserveSpace(uint32_t delta_size)
|
||||||
{
|
{
|
||||||
uint32_t maxSize = maxsize[pCurrentSection->nType];
|
|
||||||
uint32_t newSize = curOffset + delta_size;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This check is here to trap broken code that generates sections that
|
* This check is here to trap broken code that generates sections that
|
||||||
* are too big and to prevent the assembler from generating huge object
|
* are too big and to prevent the assembler from generating huge object
|
||||||
* files or trying to allocate too much memory.
|
* files or trying to allocate too much memory.
|
||||||
* A check at the linking stage is still necessary.
|
* A check at the linking stage is still necessary.
|
||||||
*/
|
*/
|
||||||
if (newSize > maxSize)
|
checkSectionSize(pCurrentSection, curOffset + loadOffset + delta_size);
|
||||||
fatalerror("Section '%s' is too big (max size = 0x%" PRIX32 " bytes, reached 0x%" PRIX32 ").",
|
if (currentLoadSection)
|
||||||
pCurrentSection->pzName, maxSize, newSize);
|
checkSectionSize(currentLoadSection, curOffset + delta_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Section *out_FindSectionByName(const char *pzName)
|
struct Section *out_FindSectionByName(const char *pzName)
|
||||||
@@ -384,8 +390,8 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
|
|||||||
static inline void growSection(uint32_t growth)
|
static inline void growSection(uint32_t growth)
|
||||||
{
|
{
|
||||||
curOffset += growth;
|
curOffset += growth;
|
||||||
if (curOffset > pCurrentSection->size)
|
if (curOffset + loadOffset > pCurrentSection->size)
|
||||||
pCurrentSection->size = curOffset;
|
pCurrentSection->size = curOffset + loadOffset;
|
||||||
if (currentLoadSection && curOffset > currentLoadSection->size)
|
if (currentLoadSection && curOffset > currentLoadSection->size)
|
||||||
currentLoadSection->size = curOffset;
|
currentLoadSection->size = curOffset;
|
||||||
}
|
}
|
||||||
|
|||||||
5
test/asm/load-begin.asm
Normal file
5
test/asm/load-begin.asm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
SECTION "test", ROM0
|
||||||
|
LOAD "RAM", WRAM0
|
||||||
|
ld a, 5
|
||||||
|
ENDL
|
||||||
|
db 1
|
||||||
0
test/asm/load-begin.err
Normal file
0
test/asm/load-begin.err
Normal file
0
test/asm/load-begin.out
Normal file
0
test/asm/load-begin.out
Normal file
1
test/asm/load-begin.out.bin
Normal file
1
test/asm/load-begin.out.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
>
|
||||||
5
test/asm/load-overflow.asm
Normal file
5
test/asm/load-overflow.asm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
SECTION "Overflow", ROM0
|
||||||
|
ds $6000
|
||||||
|
LOAD "oops",WRAM0
|
||||||
|
ds $2001
|
||||||
|
ENDL
|
||||||
2
test/asm/load-overflow.err
Normal file
2
test/asm/load-overflow.err
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
ERROR: load-overflow.asm(4):
|
||||||
|
Section 'Overflow' grew too big (max size = 0x8000 bytes, reached 0x8001).
|
||||||
0
test/asm/load-overflow.out
Normal file
0
test/asm/load-overflow.out
Normal file
5
test/asm/load-trail.asm
Normal file
5
test/asm/load-trail.asm
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
SECTION "test", ROM0
|
||||||
|
db 1
|
||||||
|
LOAD "RAM", WRAM0
|
||||||
|
ld a, 5
|
||||||
|
ENDL
|
||||||
0
test/asm/load-trail.err
Normal file
0
test/asm/load-trail.err
Normal file
0
test/asm/load-trail.out
Normal file
0
test/asm/load-trail.out
Normal file
1
test/asm/load-trail.out.bin
Normal file
1
test/asm/load-trail.out.bin
Normal file
@@ -0,0 +1 @@
|
|||||||
|
>
|
||||||
Reference in New Issue
Block a user