mirror of
https://github.com/gbdev/rgbds.git
synced 2026-09-06 05:47:07 +00:00
Fix large ds in linker script overflowing the PC
This commit is contained in:
+3
-1
@@ -204,7 +204,9 @@ void layout_Pad(uint32_t length) {
|
|||||||
uint16_t &pc = curAddr[activeType][activeBankIdx];
|
uint16_t &pc = curAddr[activeType][activeBankIdx];
|
||||||
|
|
||||||
assume(pc >= typeInfo.startAddr);
|
assume(pc >= typeInfo.startAddr);
|
||||||
if (uint16_t offset = pc - typeInfo.startAddr; length + offset > typeInfo.size) {
|
// `length + offset` can overflow `uint32_t`, so check just `length` first
|
||||||
|
if (uint16_t offset = pc - typeInfo.startAddr;
|
||||||
|
length > typeInfo.size || length + offset > typeInfo.size) {
|
||||||
scriptError(
|
scriptError(
|
||||||
"Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16,
|
"Cannot increase the current address by %u bytes: only %u bytes to $%04" PRIx16,
|
||||||
length,
|
length,
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
section "foo", rom0
|
||||||
|
Foo:: dw Foo
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
section "bar", rom0
|
||||||
|
Bar:: dw Bar
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
error: Cannot increase the current address by 4294967280 bytes: only 12286 bytes to $4000
|
||||||
|
at script-ds/script.link(4)
|
||||||
|
Linking failed with 1 error
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
ROM0
|
||||||
|
org $1000
|
||||||
|
"foo"
|
||||||
|
ds $ffff_fff0
|
||||||
|
"bar"
|
||||||
@@ -322,6 +322,15 @@ tryDiff "$test"/out.err "$outtemp"
|
|||||||
tryCmp "$test"/out.gb "$gbtemp"
|
tryCmp "$test"/out.gb "$gbtemp"
|
||||||
evaluateTest
|
evaluateTest
|
||||||
|
|
||||||
|
test="script-ds"
|
||||||
|
startTest
|
||||||
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
"$RGBASM" -o "$gbtemp2" "$test"/b.asm
|
||||||
|
continueTest
|
||||||
|
rgblinkQuiet -o "$gbtemp" -l "$test"/script.link "$otemp" "$gbtemp2" 2>"$outtemp"
|
||||||
|
tryDiff "$test"/out.err "$outtemp"
|
||||||
|
evaluateTest
|
||||||
|
|
||||||
test="script-include"
|
test="script-include"
|
||||||
startTest
|
startTest
|
||||||
"$RGBASM" -o "$otemp" "$test"/a.asm
|
"$RGBASM" -o "$otemp" "$test"/a.asm
|
||||||
|
|||||||
Reference in New Issue
Block a user