From 4877bb783cfd7ef9ec8190c71663c68530024026 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Sun, 22 Mar 2020 01:46:10 +0100 Subject: [PATCH] Add more tests for unionized sections + fix bugs Implementing those tests found a few bugs... oops --- src/asm/section.c | 6 ++++- src/link/section.c | 4 +++ test/asm/section-union.err | 2 +- test/link/section-union/align-conflict.asm | 10 ++++++++ test/link/section-union/align-conflict.out | 6 +++++ test/link/section-union/bad-types.asm | 10 ++++++++ test/link/section-union/bad-types.out | 6 +++++ test/link/section-union/bank-conflict.asm | 8 ++++++ test/link/section-union/bank-conflict.out | 6 +++++ test/link/section-union/data-overlay.asm | 10 ++++++++ test/link/section-union/data-overlay.out | 6 +++++ test/link/section-union/different-data.asm | 8 ++++++ test/link/section-union/different-data.out | 6 +++++ test/link/section-union/different-size.asm | 8 ++++++ test/link/section-union/different-size.out | 6 +++++ .../link/section-union/different-syntaxes.asm | 10 ++++++++ .../link/section-union/different-syntaxes.out | 6 +++++ test/link/section-union/{ => good}/a.asm | 0 test/link/section-union/{ => good}/b.asm | 0 .../link/section-union/{ => good}/ref.out.bin | Bin .../link/section-union/{ => good}/script.link | 0 test/link/section-union/no-room.asm | 12 +++++++++ test/link/section-union/no-room.out | 2 ++ test/link/section-union/org-conflict.asm | 8 ++++++ test/link/section-union/org-conflict.out | 6 +++++ test/link/section-union/split-data.asm | 10 ++++++++ test/link/section-union/split-data.out | 6 +++++ test/link/test.sh | 23 ++++++++++++++---- 28 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 test/link/section-union/align-conflict.asm create mode 100644 test/link/section-union/align-conflict.out create mode 100644 test/link/section-union/bad-types.asm create mode 100644 test/link/section-union/bad-types.out create mode 100644 test/link/section-union/bank-conflict.asm create mode 100644 test/link/section-union/bank-conflict.out create mode 100644 test/link/section-union/data-overlay.asm create mode 100644 test/link/section-union/data-overlay.out create mode 100644 test/link/section-union/different-data.asm create mode 100644 test/link/section-union/different-data.out create mode 100644 test/link/section-union/different-size.asm create mode 100644 test/link/section-union/different-size.out create mode 100644 test/link/section-union/different-syntaxes.asm create mode 100644 test/link/section-union/different-syntaxes.out rename test/link/section-union/{ => good}/a.asm (100%) rename test/link/section-union/{ => good}/b.asm (100%) rename test/link/section-union/{ => good}/ref.out.bin (100%) rename test/link/section-union/{ => good}/script.link (100%) create mode 100644 test/link/section-union/no-room.asm create mode 100644 test/link/section-union/no-room.out create mode 100644 test/link/section-union/org-conflict.asm create mode 100644 test/link/section-union/org-conflict.out create mode 100644 test/link/section-union/split-data.asm create mode 100644 test/link/section-union/split-data.out diff --git a/src/asm/section.c b/src/asm/section.c index f2ac719d..812d5da5 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -155,6 +155,10 @@ static struct Section *getSection(char const *pzName, enum SectionType type, 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 @@ static struct Section *getSection(char const *pzName, enum SectionType type, 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); } } diff --git a/src/link/section.c b/src/link/section.c index d52afee1..3cdaee06 100644 --- a/src/link/section.c +++ b/src/link/section.c @@ -38,6 +38,10 @@ void sect_ForEach(void (*callback)(struct Section *, void *), void *arg) 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) diff --git a/test/asm/section-union.err b/test/asm/section-union.err index 533d56e5..871b97db 100644 --- a/test/asm/section-union.err +++ b/test/asm/section-union.err @@ -3,6 +3,6 @@ ERROR: section-union.asm(37): 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) diff --git a/test/link/section-union/align-conflict.asm b/test/link/section-union/align-conflict.asm new file mode 100644 index 00000000..7a92349b --- /dev/null +++ b/test/link/section-union/align-conflict.asm @@ -0,0 +1,10 @@ +IF !DEF(SECOND) +ATTRS equs ",ALIGN[2]" +ELSE +ATTRS equs "[$CAFE]" +ENDC + +SECTION UNION "conflicting alignment", WRAM0 ATTRS + db + + PURGE ATTRS diff --git a/test/link/section-union/align-conflict.out b/test/link/section-union/align-conflict.out new file mode 100644 index 00000000..1e4766ef --- /dev/null +++ b/test/link/section-union/align-conflict.out @@ -0,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) diff --git a/test/link/section-union/bad-types.asm b/test/link/section-union/bad-types.asm new file mode 100644 index 00000000..e8c2e5f9 --- /dev/null +++ b/test/link/section-union/bad-types.asm @@ -0,0 +1,10 @@ +IF !DEF(SECOND) +TYPE equs "HRAM" +ELSE +TYPE equs "WRAM0" +ENDC + +SECTION UNION "conflicting types", TYPE + db + + PURGE TYPE diff --git a/test/link/section-union/bad-types.out b/test/link/section-union/bad-types.out new file mode 100644 index 00000000..bd5fdfcf --- /dev/null +++ b/test/link/section-union/bad-types.out @@ -0,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) diff --git a/test/link/section-union/bank-conflict.asm b/test/link/section-union/bank-conflict.asm new file mode 100644 index 00000000..cc5c6aac --- /dev/null +++ b/test/link/section-union/bank-conflict.asm @@ -0,0 +1,8 @@ +IF !DEF(SECOND) +SECOND equs "4" +ENDC + +SECTION UNION "conflicting banks", WRAMX, BANK[SECOND] + db + + PURGE SECOND diff --git a/test/link/section-union/bank-conflict.out b/test/link/section-union/bank-conflict.out new file mode 100644 index 00000000..c806274f --- /dev/null +++ b/test/link/section-union/bank-conflict.out @@ -0,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) diff --git a/test/link/section-union/data-overlay.asm b/test/link/section-union/data-overlay.asm new file mode 100644 index 00000000..be65b67e --- /dev/null +++ b/test/link/section-union/data-overlay.asm @@ -0,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 diff --git a/test/link/section-union/data-overlay.out b/test/link/section-union/data-overlay.out new file mode 100644 index 00000000..b2cfb039 --- /dev/null +++ b/test/link/section-union/data-overlay.out @@ -0,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) diff --git a/test/link/section-union/different-data.asm b/test/link/section-union/different-data.asm new file mode 100644 index 00000000..ca6b1537 --- /dev/null +++ b/test/link/section-union/different-data.asm @@ -0,0 +1,8 @@ +IF !DEF(SECOND) +DATA = 1 +ELSE +DATA = 2 +ENDC + +SECTION UNION "different data", ROM0 + db DATA diff --git a/test/link/section-union/different-data.out b/test/link/section-union/different-data.out new file mode 100644 index 00000000..46619e1c --- /dev/null +++ b/test/link/section-union/different-data.out @@ -0,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) diff --git a/test/link/section-union/different-size.asm b/test/link/section-union/different-size.asm new file mode 100644 index 00000000..6514bf93 --- /dev/null +++ b/test/link/section-union/different-size.asm @@ -0,0 +1,8 @@ +IF !DEF(SECOND) +SIZE = 69 +ELSE +SIZE = 420 +ENDC + +SECTION UNION "different section sizes", ROM0 + ds SIZE diff --git a/test/link/section-union/different-size.out b/test/link/section-union/different-size.out new file mode 100644 index 00000000..bc6131f6 --- /dev/null +++ b/test/link/section-union/different-size.out @@ -0,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) diff --git a/test/link/section-union/different-syntaxes.asm b/test/link/section-union/different-syntaxes.asm new file mode 100644 index 00000000..d261d21f --- /dev/null +++ b/test/link/section-union/different-syntaxes.asm @@ -0,0 +1,10 @@ +IF !DEF(SECOND) +INSTR equs "sbc a" +ELSE +INSTR equs "db $9f" +ENDC + +SECTION UNION "different syntaxes", ROM0 + INSTR + + PURGE INSTR diff --git a/test/link/section-union/different-syntaxes.out b/test/link/section-union/different-syntaxes.out new file mode 100644 index 00000000..52dd7709 --- /dev/null +++ b/test/link/section-union/different-syntaxes.out @@ -0,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) diff --git a/test/link/section-union/a.asm b/test/link/section-union/good/a.asm similarity index 100% rename from test/link/section-union/a.asm rename to test/link/section-union/good/a.asm diff --git a/test/link/section-union/b.asm b/test/link/section-union/good/b.asm similarity index 100% rename from test/link/section-union/b.asm rename to test/link/section-union/good/b.asm diff --git a/test/link/section-union/ref.out.bin b/test/link/section-union/good/ref.out.bin similarity index 100% rename from test/link/section-union/ref.out.bin rename to test/link/section-union/good/ref.out.bin diff --git a/test/link/section-union/script.link b/test/link/section-union/good/script.link similarity index 100% rename from test/link/section-union/script.link rename to test/link/section-union/good/script.link diff --git a/test/link/section-union/no-room.asm b/test/link/section-union/no-room.asm new file mode 100644 index 00000000..a6202ab3 --- /dev/null +++ b/test/link/section-union/no-room.asm @@ -0,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 diff --git a/test/link/section-union/no-room.out b/test/link/section-union/no-room.out new file mode 100644 index 00000000..4a1104da --- /dev/null +++ b/test/link/section-union/no-room.out @@ -0,0 +1,2 @@ +error: Unable to place "test" (WRAMX section) in bank $02 with align mask ffffffc0 +--- diff --git a/test/link/section-union/org-conflict.asm b/test/link/section-union/org-conflict.asm new file mode 100644 index 00000000..b51635b3 --- /dev/null +++ b/test/link/section-union/org-conflict.asm @@ -0,0 +1,8 @@ +IF !DEF(SECOND) +ADDR = $BEEF +ELSE +ADDR = $BABE +ENDC + +SECTION UNION "conflicting address", SRAM[ADDR] + db diff --git a/test/link/section-union/org-conflict.out b/test/link/section-union/org-conflict.out new file mode 100644 index 00000000..b5a332ec --- /dev/null +++ b/test/link/section-union/org-conflict.out @@ -0,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) diff --git a/test/link/section-union/split-data.asm b/test/link/section-union/split-data.asm new file mode 100644 index 00000000..2ddff420 --- /dev/null +++ b/test/link/section-union/split-data.asm @@ -0,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 diff --git a/test/link/section-union/split-data.out b/test/link/section-union/split-data.out new file mode 100644 index 00000000..36db397f --- /dev/null +++ b/test/link/section-union/split-data.out @@ -0,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) diff --git a/test/link/test.sh b/test/link/test.sh index 68d33600..d987090c 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -80,12 +80,25 @@ $RGBLINK -o $gbtemp2 $otemp 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