From 190678107bc79a19ce787ce94233661ae1dc45ef Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Tue, 7 Apr 2020 20:41:20 +0200 Subject: [PATCH] Prevent RGBLINK from crashing when getting the bank of a constant --- src/link/patch.c | 5 +++++ test/link/bank-const/a.asm | 2 ++ test/link/bank-const/b.asm | 2 ++ test/link/bank-const/err.out | 2 ++ test/link/test.sh | 6 ++++++ 5 files changed, 17 insertions(+) create mode 100644 test/link/bank-const/a.asm create mode 100644 test/link/bank-const/b.asm create mode 100644 test/link/bank-const/err.out diff --git a/src/link/patch.c b/src/link/patch.c index e25ddd12..e4a32aab 100644 --- a/src/link/patch.c +++ b/src/link/patch.c @@ -260,6 +260,11 @@ static int32_t computeRPNExpr(struct Patch const *patch, patch->fileName, fileSymbols[value]->name); value = 1; + } else if (!symbol->section) { + error("%s: Requested BANK() of non-label symbol \"%s\"", + patch->fileName, + fileSymbols[value]->name); + value = 1; } else { value = symbol->section->bank; } diff --git a/test/link/bank-const/a.asm b/test/link/bank-const/a.asm new file mode 100644 index 00000000..3590ea57 --- /dev/null +++ b/test/link/bank-const/a.asm @@ -0,0 +1,2 @@ +CONSTANT equ 0 +EXPORT CONSTANT diff --git a/test/link/bank-const/b.asm b/test/link/bank-const/b.asm new file mode 100644 index 00000000..e38f3129 --- /dev/null +++ b/test/link/bank-const/b.asm @@ -0,0 +1,2 @@ +SECTION "Test", ROM0[0] + db BANK(CONSTANT) diff --git a/test/link/bank-const/err.out b/test/link/bank-const/err.out new file mode 100644 index 00000000..8c7d5ef1 --- /dev/null +++ b/test/link/bank-const/err.out @@ -0,0 +1,2 @@ +error: bank-const/b.asm(2): Requested BANK() of non-label symbol "CONSTANT" +Linking failed with 1 error diff --git a/test/link/test.sh b/test/link/test.sh index d0da25ee..e3751791 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -80,6 +80,12 @@ $RGBLINK -o $gbtemp2 $otemp i="high-low.asm" tryCmp $gbtemp $gbtemp2 rc=$(($? || $rc)) +$RGBASM -o $otemp bank-const/a.asm +$RGBASM -o $gbtemp2 bank-const/b.asm +$RGBLINK -o $gbtemp $gbtemp2 $otemp > $outtemp 2>&1 +i="bank-const.asm" tryDiff bank-const/err.out $outtemp +rc=$(($? || $rc)) + $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