diff --git a/src/link/output.cpp b/src/link/output.cpp index dab2fd88..09f453b2 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -284,9 +284,9 @@ static void printSymName(char const *name) { // Comparator function for `std::stable_sort` to sort symbols // Symbols are ordered by address, then by parentage -static int compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2) { +static bool compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2) { if (sym1.addr != sym2.addr) - return sym1.addr < sym2.addr ? -1 : 1; + return sym1.addr < sym2.addr; std::string const &sym1_name = sym1.sym->name; std::string const &sym2_name = sym2.sym->name; @@ -299,14 +299,14 @@ static int compareSymbols(SortedSymbol const &sym1, SortedSymbol const &sym2) { // Sort parent labels before their child local labels if (sym2_name.starts_with(sym1_name) && sym2_name[sym1_len] == '.') - return -1; + return true; if (sym1_name.starts_with(sym2_name) && sym1_name[sym2_len] == '.') - return 1; + return false; // Sort local labels before unrelated global labels - return sym1_local ? -1 : 1; + return sym1_local; } - return 0; + return false; } /* diff --git a/test/link/symbols/a.asm b/test/link/symbols/a.asm new file mode 100644 index 00000000..2dd0da36 --- /dev/null +++ b/test/link/symbols/a.asm @@ -0,0 +1,15 @@ +SECTION "alpha", ROM0 +Alpha:: + db 1, 2, 3 +End: + +SECTION "a", WRAM0 +wAlpha:: + ds 3 +.End:: + +SECTION UNION "U", WRAM0 +wStart: + .word1: dw + .word2: dw +wEnd: diff --git a/test/link/symbols/b.asm b/test/link/symbols/b.asm new file mode 100644 index 00000000..eeb0e7ca --- /dev/null +++ b/test/link/symbols/b.asm @@ -0,0 +1,14 @@ +SECTION "beta", ROM0 +Beta:: + db 4, 5, 6 +End: + +SECTION "b", WRAM0 +wBeta:: + ds 3 +.End:: + +SECTION UNION "U", WRAM0 +wStart: + .long1: dl +wEnd: diff --git a/test/link/symbols/out.err b/test/link/symbols/out.err new file mode 100644 index 00000000..e69de29b diff --git a/test/link/symbols/ref.out.bin b/test/link/symbols/ref.out.bin new file mode 100644 index 00000000..3c644bc3 Binary files /dev/null and b/test/link/symbols/ref.out.bin differ diff --git a/test/link/symbols/ref.out.sym b/test/link/symbols/ref.out.sym new file mode 100644 index 00000000..1a0cfd96 --- /dev/null +++ b/test/link/symbols/ref.out.sym @@ -0,0 +1,16 @@ +; File generated by rgblink +00:0000 Beta +00:0003 End +00:0003 Alpha +00:0006 End +00:c000 wStart +00:c000 wStart +00:c000 wStart.long1 +00:c000 wStart.word1 +00:c002 wStart.word2 +00:c004 wEnd +00:c004 wEnd +00:c004 wBeta +00:c007 wBeta.End +00:c007 wAlpha +00:c00a wAlpha.End diff --git a/test/link/test.sh b/test/link/test.sh index b9736c59..bdc15586 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -9,13 +9,14 @@ otemp="$(mktemp)" gbtemp="$(mktemp)" gbtemp2="$(mktemp)" outtemp="$(mktemp)" +outtemp2="$(mktemp)" tests=0 failed=0 rc=0 # Immediate expansion is the desired behavior. # shellcheck disable=SC2064 -trap "rm -f ${otemp@Q} ${gbtemp@Q} ${gbtemp2@Q} ${outtemp@Q}" EXIT +trap "rm -f ${otemp@Q} ${gbtemp@Q} ${gbtemp2@Q} ${outtemp@Q} ${outtemp2@Q}" EXIT bold="$(tput bold)" resbold="$(tput sgr0)" @@ -276,6 +277,17 @@ for i in section-union/*.asm; do evaluateTest done +test="symbols" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +"$RGBASM" -o "$gbtemp2" "$test"/b.asm +continueTest +rgblinkQuiet -o "$gbtemp" -n "$outtemp2" "$gbtemp2" "$otemp" 2>"$outtemp" +tryDiff "$test"/out.err "$outtemp" +tryDiff "$test"/ref.out.sym "$outtemp2" +tryCmpRom "$test"/ref.out.bin +evaluateTest + if [[ "$failed" -eq 0 ]]; then echo "${bold}${green}All ${tests} tests passed!${rescolors}${resbold}" else