diff --git a/src/link/assign.cpp b/src/link/assign.cpp index 5c0b6b15..e1ce2560 100644 --- a/src/link/assign.cpp +++ b/src/link/assign.cpp @@ -379,15 +379,15 @@ static void categorizeSection(Section §ion) { sections.insert(pos, §ion); } -static std::vector
checkOverlayCompat() { - std::vector
unfixedSections; +static std::vector
checkOverlayCompat() { + std::vector
unfixedSections; if (!options.overlayFileName) { return unfixedSections; } for (uint8_t constraints = std::size(unassignedSections); constraints--;) { - if ((constraints & (BANK_CONSTRAINED | ORG_CONSTRAINED)) + if (((constraints & BANK_CONSTRAINED) && (constraints & ORG_CONSTRAINED)) || unassignedSections[constraints].empty()) { continue; } @@ -418,17 +418,26 @@ void assign_AssignSections() { }); // Overlaying requires only fully-constrained sections - if (std::vector
unfixedSections = checkOverlayCompat(); !unfixedSections.empty()) { + if (std::vector
unfixedSections = checkOverlayCompat(); + !unfixedSections.empty()) { size_t nbUnfixedSections = unfixedSections.size(); - fputs("FATAL: All sections must be fixed when using an overlay file", stderr); - for (size_t i = 0; i < nbUnfixedSections; ++i) { - fprintf(stderr, "%c \"%s\"", i == 0 ? ';' : ',', unfixedSections[i]->name.c_str()); + std::string unfixedList; + for (Section const *section : unfixedSections) { + unfixedList += "\n- \""; + unfixedList += section->name; + unfixedList += '"'; } - if (nbSectionsToAssign != nbUnfixedSections) { - fprintf(stderr, " and %" PRIu64 " more", nbSectionsToAssign - nbUnfixedSections); + if (nbSectionsToAssign > nbUnfixedSections) { + unfixedList += "\n- and "; + unfixedList += std::to_string(nbSectionsToAssign - nbUnfixedSections); + unfixedList += " more"; } - fprintf(stderr, " %s not\n", nbSectionsToAssign == 1 ? "is" : "are"); - exit(1); + fatal( + "All sections must be fixed when using an overlay file; %" PRIu64 " %s not:%s", + nbSectionsToAssign, + nbSectionsToAssign == 1 ? "is" : "are", + unfixedList.c_str() + ); } // Assign sections in decreasing constraint order diff --git a/test/link/overlay/unfixed/a.asm b/test/link/overlay/unfixed/a.asm new file mode 100644 index 00000000..74b90c72 --- /dev/null +++ b/test/link/overlay/unfixed/a.asm @@ -0,0 +1,4 @@ +FOR n, 15 + SECTION "test {d:n}", ROM0 + db n +ENDR diff --git a/test/link/overlay/unfixed/out.err b/test/link/overlay/unfixed/out.err new file mode 100644 index 00000000..61810354 --- /dev/null +++ b/test/link/overlay/unfixed/out.err @@ -0,0 +1,13 @@ +FATAL: All sections must be fixed when using an overlay file; 15 are not: +- "test 14" +- "test 13" +- "test 12" +- "test 11" +- "test 10" +- "test 9" +- "test 8" +- "test 7" +- "test 6" +- "test 5" +- and 5 more +Linking aborted with 1 error diff --git a/test/link/overlay/unfixed/overlay.gb b/test/link/overlay/unfixed/overlay.gb new file mode 100644 index 00000000..0d0987a9 --- /dev/null +++ b/test/link/overlay/unfixed/overlay.gb @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/test/link/test.sh b/test/link/test.sh index 7c4ec42d..6dbfa267 100755 --- a/test/link/test.sh +++ b/test/link/test.sh @@ -233,6 +233,14 @@ tryDiff "$test"/out.err "$outtemp" tryCmp "$test"/out.gb "$gbtemp" evaluateTest +test="overlay/unfixed" +startTest +"$RGBASM" -o "$otemp" "$test"/a.asm +continueTest +rgblinkQuiet -o "$gbtemp" -O "$test"/overlay.gb "$otemp" 2>"$outtemp" +tryDiff "$test"/out.err "$outtemp" +evaluateTest + test="overlay/tiny" startTest "$RGBASM" -o "$otemp" "$test"/a.asm