ref: 4877bb783cfd7ef9ec8190c71663c68530024026
parent: 275b8e15ff2eb13eeeef9e8d60783ffa839007e6
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Mar 21 21:46:10 EDT 2020
Add more tests for unionized sections + fix bugs Implementing those tests found a few bugs... oops
--- a/src/asm/section.c
+++ b/src/asm/section.c
@@ -155,6 +155,10 @@
if (pSect->nOrg != -1 && pSect->nOrg != org)
fail("Section \"%s\" already declared as fixed at different address $%x",
pSect->pzName, pSect->nOrg);
+ else if (pSect->nAlign != 0
+ && ((pSect->nAlign - 1) & org))
+ fail("Section \"%s\" already declared as aligned to %u bytes",
+ pSect->pzName, pSect->nAlign);
else
/* Otherwise, just override */
pSect->nOrg = org;
@@ -207,7 +211,7 @@
fail("Section \"%s\" already declared as unaligned",
pSect->pzName);
else
- fail("Section \"%s\" already declared as aligned to %u bits",
+ fail("Section \"%s\" already declared as aligned to %u bytes",
pSect->pzName, pSect->nAlign);
}
}
--- a/src/link/section.c
+++ b/src/link/section.c
@@ -38,6 +38,10 @@
static void mergeSections(struct Section *target, struct Section *other)
{
+ if (target->type != other->type)
+ errx(1, "Section \"%s\" is defined with conflicting types %s and %s",
+ other->name,
+ typeNames[target->type], typeNames[other->type]);
if (other->isAddressFixed) {
if (target->isAddressFixed) {
if (target->org != other->org)
--- a/test/asm/section-union.err
+++ b/test/asm/section-union.err
@@ -3,6 +3,6 @@
ERROR: section-union.asm(37):
Section "test" already declared as fixed at $c000
ERROR: section-union.asm(37):
- Section "test" already declared as aligned to 256 bits
+ Section "test" already declared as aligned to 256 bytes
ERROR: section-union.asm(37):
Cannot create section "test" (3 errors)
--- a/test/link/section-union/a.asm
+++ /dev/null
@@ -1,21 +1,0 @@
-SECTION UNION "a", WRAM0
- ds 10
-a1:
-
-SECTION UNION "b", WRAMX,ALIGN[4]
-banked::
- ds 10
-b1:
-
-SECTION UNION "c", HRAM[$FFC0]
- ds 5
-c1::
-
-
-SECTION "output 1", ROM0
- dw a1,a2 ; $C00A, $C02A
- dw b1,b2 ; $DABA, $DAB2
- dw c1,c2 ; $FFC5, $FFC5
-
-SECTION "output 3", ROM0
- db BANK(banked)
--- /dev/null
+++ b/test/link/section-union/align-conflict.asm
@@ -1,0 +1,10 @@
+IF !DEF(SECOND)
+ATTRS equs ",ALIGN[2]"
+ELSE
+ATTRS equs "[$CAFE]"
+ENDC
+
+SECTION UNION "conflicting alignment", WRAM0 ATTRS
+ db
+
+ PURGE ATTRS
--- /dev/null
+++ b/test/link/section-union/align-conflict.out
@@ -1,0 +1,6 @@
+error: Section "conflicting alignment" is defined with conflicting 4-byte alignment and address $cafe
+---
+ERROR: -(18):
+ Section "conflicting alignment" already declared as aligned to 4 bytes
+ERROR: -(18):
+ Cannot create section "conflicting alignment" (1 errors)
--- a/test/link/section-union/b.asm
+++ /dev/null
@@ -1,18 +1,0 @@
-SECTION UNION "a", WRAM0
-a1: ; This is here to check that the two `a1` don't conflict
- ds 42
-a2::
-
-SECTION UNION "b", WRAMX[$DAB0]
- ds 2
-b2::
-
-SECTION UNION "c", HRAM[$FFC0]
-b1: ; Same but in different sections now
- ds 5
-c2::
-
-SECTION "output 2", ROM0
- dw a1,a2
- dw b1,b2
- dw c1,c2
--- /dev/null
+++ b/test/link/section-union/bad-types.asm
@@ -1,0 +1,10 @@
+IF !DEF(SECOND)
+TYPE equs "HRAM"
+ELSE
+TYPE equs "WRAM0"
+ENDC
+
+SECTION UNION "conflicting types", TYPE
+ db
+
+ PURGE TYPE
--- /dev/null
+++ b/test/link/section-union/bad-types.out
@@ -1,0 +1,6 @@
+error: Section "conflicting types" is defined with conflicting types HRAM and WRAM0
+---
+ERROR: -(18):
+ Section "conflicting types" already exists but with type HRAM
+ERROR: -(18):
+ Cannot create section "conflicting types" (1 errors)
--- /dev/null
+++ b/test/link/section-union/bank-conflict.asm
@@ -1,0 +1,8 @@
+IF !DEF(SECOND)
+SECOND equs "4"
+ENDC
+
+SECTION UNION "conflicting banks", WRAMX, BANK[SECOND]
+ db
+
+ PURGE SECOND
--- /dev/null
+++ b/test/link/section-union/bank-conflict.out
@@ -1,0 +1,6 @@
+error: Section "conflicting banks" is defined with conflicting banks 4 and 1
+---
+ERROR: -(14):
+ Section "conflicting banks" already declared with different bank 4
+ERROR: -(14):
+ Cannot create section "conflicting banks" (1 errors)
--- /dev/null
+++ b/test/link/section-union/data-overlay.asm
@@ -1,0 +1,10 @@
+IF !DEF(SECOND)
+DATA equs "ds 4"
+ELSE
+DATA equs "db $aa, $bb, $cc, $dd"
+ENDC
+
+SECTION UNION "overlaid data", ROM0
+ DATA
+
+ PURGE DATA
--- /dev/null
+++ b/test/link/section-union/data-overlay.out
@@ -1,0 +1,6 @@
+error: Section "overlaid data" is of type ROM0, which cannot be unionized
+---
+ERROR: -(18):
+ Cannot declare ROM sections as UNION
+ERROR: -(18):
+ Cannot create section "overlaid data" (1 errors)
--- /dev/null
+++ b/test/link/section-union/different-data.asm
@@ -1,0 +1,8 @@
+IF !DEF(SECOND)
+DATA = 1
+ELSE
+DATA = 2
+ENDC
+
+SECTION UNION "different data", ROM0
+ db DATA
--- /dev/null
+++ b/test/link/section-union/different-data.out
@@ -1,0 +1,6 @@
+error: Section "different data" is of type ROM0, which cannot be unionized
+---
+ERROR: -(16):
+ Cannot declare ROM sections as UNION
+ERROR: -(16):
+ Cannot create section "different data" (1 errors)
--- /dev/null
+++ b/test/link/section-union/different-size.asm
@@ -1,0 +1,8 @@
+IF !DEF(SECOND)
+SIZE = 69
+ELSE
+SIZE = 420
+ENDC
+
+SECTION UNION "different section sizes", ROM0
+ ds SIZE
--- /dev/null
+++ b/test/link/section-union/different-size.out
@@ -1,0 +1,6 @@
+error: Section "different section sizes" is of type ROM0, which cannot be unionized
+---
+ERROR: -(16):
+ Cannot declare ROM sections as UNION
+ERROR: -(16):
+ Cannot create section "different section sizes" (1 errors)
--- /dev/null
+++ b/test/link/section-union/different-syntaxes.asm
@@ -1,0 +1,10 @@
+IF !DEF(SECOND)
+INSTR equs "sbc a"
+ELSE
+INSTR equs "db $9f"
+ENDC
+
+SECTION UNION "different syntaxes", ROM0
+ INSTR
+
+ PURGE INSTR
--- /dev/null
+++ b/test/link/section-union/different-syntaxes.out
@@ -1,0 +1,6 @@
+error: Section "different syntaxes" is of type ROM0, which cannot be unionized
+---
+ERROR: -(18):
+ Cannot declare ROM sections as UNION
+ERROR: -(18):
+ Cannot create section "different syntaxes" (1 errors)
--- /dev/null
+++ b/test/link/section-union/good/a.asm
@@ -1,0 +1,21 @@
+SECTION UNION "a", WRAM0
+ ds 10
+a1:
+
+SECTION UNION "b", WRAMX,ALIGN[4]
+banked::
+ ds 10
+b1:
+
+SECTION UNION "c", HRAM[$FFC0]
+ ds 5
+c1::
+
+
+SECTION "output 1", ROM0
+ dw a1,a2 ; $C00A, $C02A
+ dw b1,b2 ; $DABA, $DAB2
+ dw c1,c2 ; $FFC5, $FFC5
+
+SECTION "output 3", ROM0
+ db BANK(banked)
--- /dev/null
+++ b/test/link/section-union/good/b.asm
@@ -1,0 +1,18 @@
+SECTION UNION "a", WRAM0
+a1: ; This is here to check that the two `a1` don't conflict
+ ds 42
+a2::
+
+SECTION UNION "b", WRAMX[$DAB0]
+ ds 2
+b2::
+
+SECTION UNION "c", HRAM[$FFC0]
+b1: ; Same but in different sections now
+ ds 5
+c2::
+
+SECTION "output 2", ROM0
+ dw a1,a2
+ dw b1,b2
+ dw c1,c2
binary files /dev/null b/test/link/section-union/good/ref.out.bin differ
--- /dev/null
+++ b/test/link/section-union/good/script.link
@@ -1,0 +1,9 @@
+ROM0
+ "output 1"
+ "output 2"
+ "output 3"
+WRAM0
+ "a" ; $C000
+WRAMX 1
+ ORG $DAB0
+ "b"
--- /dev/null
+++ b/test/link/section-union/no-room.asm
@@ -1,0 +1,12 @@
+; NB: the error is that there is no room to place the unionized section in,
+; so RGBASM can't possibly error out.
+IF !DEF(SECOND)
+ SECTION "bloat", WRAMX[$d000], BANK[2]
+ ds $fe0
+
+ SECTION UNION "test", WRAMX, BANK[2]
+ db
+ELSE
+ SECTION UNION "test", WRAMX, ALIGN[6]
+ db
+ENDC
--- /dev/null
+++ b/test/link/section-union/no-room.out
@@ -1,0 +1,2 @@
+error: Unable to place "test" (WRAMX section) in bank $02 with align mask ffffffc0
+---
--- /dev/null
+++ b/test/link/section-union/org-conflict.asm
@@ -1,0 +1,8 @@
+IF !DEF(SECOND)
+ADDR = $BEEF
+ELSE
+ADDR = $BABE
+ENDC
+
+SECTION UNION "conflicting address", SRAM[ADDR]
+ db
--- /dev/null
+++ b/test/link/section-union/org-conflict.out
@@ -1,0 +1,6 @@
+error: Section "conflicting address" is defined with conflicting addresses $beef and $babe
+---
+ERROR: -(16):
+ Section "conflicting address" already declared as fixed at different address $beef
+ERROR: -(16):
+ Cannot create section "conflicting address" (1 errors)
binary files a/test/link/section-union/ref.out.bin /dev/null differ
--- a/test/link/section-union/script.link
+++ /dev/null
@@ -1,9 +1,0 @@
-ROM0
- "output 1"
- "output 2"
- "output 3"
-WRAM0
- "a" ; $C000
-WRAMX 1
- ORG $DAB0
- "b"
--- /dev/null
+++ b/test/link/section-union/split-data.asm
@@ -1,0 +1,10 @@
+IF !DEF(SECOND)
+DATA equs "ds 1\ndb $aa"
+ELSE
+DATA equs "db $bb\nds 1"
+ENDC
+
+SECTION UNION "mutually-overlaid data", ROM0
+ DATA
+
+ PURGE DATA
--- /dev/null
+++ b/test/link/section-union/split-data.out
@@ -1,0 +1,6 @@
+error: Section "mutually-overlaid data" is of type ROM0, which cannot be unionized
+---
+ERROR: -(18):
+ Cannot declare ROM sections as UNION
+ERROR: -(18):
+ Cannot create section "mutually-overlaid data" (1 errors)
--- a/test/link/test.sh
+++ b/test/link/test.sh
@@ -80,12 +80,25 @@
i="high-low.asm" tryCmp $gbtemp $gbtemp2
rc=$(($? || $rc))
-$RGBASM -o $otemp section-union/a.asm
-$RGBASM -o $gbtemp2 section-union/b.asm
-$RGBLINK -o $gbtemp -l section-union/script.link $otemp $gbtemp2
-dd if=$gbtemp count=1 bs=$(printf %s $(wc -c < section-union/ref.out.bin)) > $otemp 2>/dev/null
-i="section-union.asm" tryCmp section-union/ref.out.bin $otemp
+$RGBASM -o $otemp section-union/good/a.asm
+$RGBASM -o $gbtemp2 section-union/good/b.asm
+$RGBLINK -o $gbtemp -l section-union/good/script.link $otemp $gbtemp2
+dd if=$gbtemp count=1 bs=$(printf %s $(wc -c < section-union/good/ref.out.bin)) > $otemp 2>/dev/null
+i="section-union.asm" tryCmp section-union/good/ref.out.bin $otemp
rc=$(($? || $rc))
+for i in section-union/*.asm; do
+ $RGBASM -o $otemp $i
+ $RGBASM -o $gbtemp2 $i -DSECOND
+ if $RGBLINK $otemp $gbtemp2 > $outtemp 2>&1; then
+ echo -e "${bold}${red}$i didn't fail to link!${rescolors}${resbold}"
+ rc=1
+ fi
+ echo --- >> $outtemp
+ # Ensure RGBASM also errors out
+ echo 'SECOND equs "1"' | cat $i - $i | $RGBASM - 2>> $outtemp
+ tryDiff ${i%.asm}.out $outtemp
+ rc=$(($? || $rc))
+done
rm -f $otemp $gbtemp $gbtemp2 $outtemp
exit $rc