Correct error message for unconstrained sections with overlay (#1879)

This commit is contained in:
Rangi
2025-12-28 19:21:53 -05:00
committed by GitHub
parent 63a911e657
commit 41fe1d8f25
4 changed files with 80 additions and 66 deletions

View File

@@ -36,19 +36,6 @@ struct FreeSpace {
// Table of free space for each bank // Table of free space for each bank
static std::vector<std::deque<FreeSpace>> memory[SECTTYPE_INVALID]; static std::vector<std::deque<FreeSpace>> memory[SECTTYPE_INVALID];
// Init the free space-modelling structs
static void initFreeSpace() {
for (SectionType type : EnumSeq(SECTTYPE_INVALID)) {
memory[type].resize(sectTypeBanks(type));
for (std::deque<FreeSpace> &bankMem : memory[type]) {
bankMem.push_back({
.address = sectionTypeInfo[type].startAddr,
.size = sectionTypeInfo[type].size,
});
}
}
}
// Assigns a section to a given memory location // Assigns a section to a given memory location
static void assignSection(Section &section, MemoryLocation const &location) { static void assignSection(Section &section, MemoryLocation const &location) {
// Propagate the assigned location to all UNIONs/FRAGMENTs // Propagate the assigned location to all UNIONs/FRAGMENTs
@@ -368,36 +355,74 @@ static void categorizeSection(Section &section) {
sections.insert(pos, &section); sections.insert(pos, &section);
} }
static std::vector<Section const *> checkOverlayCompat() { static void checkOverlayCompat() {
std::vector<Section const *> unfixedSections; auto isFixed = [](uint8_t constraints) {
return (constraints & BANK_CONSTRAINED) && (constraints & ORG_CONSTRAINED);
};
if (!options.overlayFileName) { std::string unfixedList;
return unfixedSections;
size_t nbUnfixedSections = 0;
for (uint8_t constraints = std::size(unassignedSections); constraints--;) {
if (!isFixed(constraints)) {
nbUnfixedSections += unassignedSections[constraints].size();
}
} }
if (nbUnfixedSections == 0) {
return;
}
size_t nbListed = 0;
for (uint8_t constraints = std::size(unassignedSections); constraints--;) { for (uint8_t constraints = std::size(unassignedSections); constraints--;) {
if (((constraints & BANK_CONSTRAINED) && (constraints & ORG_CONSTRAINED)) if (isFixed(constraints)) {
|| unassignedSections[constraints].empty()) {
continue; continue;
} }
for (Section *section : unassignedSections[constraints]) { for (Section const *section : unassignedSections[constraints]) {
unfixedSections.push_back(section); if (nbListed == 10) {
unfixedList += "\n- and ";
if (unfixedSections.size() == 10) { unfixedList += std::to_string(nbUnfixedSections - nbListed);
return unfixedSections; unfixedList += " more";
break;
} }
unfixedList += "\n- \"";
unfixedList += section->name;
unfixedList += "\" (";
if (!(constraints & (BANK_CONSTRAINED | ORG_CONSTRAINED))) {
unfixedList += "bank and address";
} else if (!(constraints & BANK_CONSTRAINED)) {
unfixedList += "bank";
} else {
assume(!(constraints & ORG_CONSTRAINED));
unfixedList += "address";
}
unfixedList += " not specified)";
++nbListed;
} }
} }
return unfixedSections; fatal(
"All sections must be fixed when using an overlay file; %zu %s not:%s",
nbUnfixedSections,
nbUnfixedSections == 1 ? "is" : "are",
unfixedList.c_str()
);
} }
void assign_AssignSections() { void assign_AssignSections() {
verbosePrint(VERB_NOTICE, "Beginning assignment...\n"); verbosePrint(VERB_NOTICE, "Beginning assignment...\n");
// Initialize assignment // Initialize the free space-modelling structs
initFreeSpace(); for (SectionType type : EnumSeq(SECTTYPE_INVALID)) {
memory[type].resize(sectTypeBanks(type));
for (std::deque<FreeSpace> &bankMem : memory[type]) {
bankMem.push_back({
.address = sectionTypeInfo[type].startAddr,
.size = sectionTypeInfo[type].size,
});
}
}
// Generate linked lists of sections to assign // Generate linked lists of sections to assign
static uint64_t nbSectionsToAssign = 0; // `static` so `sect_ForEach` callback can see it static uint64_t nbSectionsToAssign = 0; // `static` so `sect_ForEach` callback can see it
@@ -407,26 +432,8 @@ void assign_AssignSections() {
}); });
// Overlaying requires only fully-constrained sections // Overlaying requires only fully-constrained sections
if (std::vector<Section const *> unfixedSections = checkOverlayCompat(); if (options.overlayFileName) {
!unfixedSections.empty()) { checkOverlayCompat();
size_t nbUnfixedSections = unfixedSections.size();
std::string unfixedList;
for (Section const *section : unfixedSections) {
unfixedList += "\n- \"";
unfixedList += section->name;
unfixedList += '"';
}
if (nbSectionsToAssign > nbUnfixedSections) {
unfixedList += "\n- and ";
unfixedList += std::to_string(nbSectionsToAssign - nbUnfixedSections);
unfixedList += " more";
}
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 // Assign sections in decreasing constraint order

View File

@@ -80,14 +80,15 @@ void sym_TraceLocalAliasedSymbols(std::string const &name) {
plural ? "are" : "is" plural ? "are" : "is"
); );
int count = 0; size_t nbListed = 0;
for (Symbol *local : locals) { for (Symbol *local : locals) {
assume(local->src); if (nbListed == 3) {
local->src->printBacktrace(local->lineNo); fprintf(stderr, " ...and %zu more\n", locals.size() - nbListed);
if (++count == 3 && locals.size() > 3) {
fprintf(stderr, " ...and %zu more\n", locals.size() - 3);
break; break;
} }
assume(local->src);
local->src->printBacktrace(local->lineNo);
++nbListed;
} }
} }

View File

@@ -1,4 +1,10 @@
FOR n, 15 FOR n, 1, 5
SECTION "test {d:n}", ROM0 SECTION "ROMX[$40{02x:n}] BANK[5]", ROMX[$4000 + n], BANK[5]
db n
SECTION "ROMX BANK[{d:n}]", ROMX, BANK[n]
db n
SECTION "ROMX[$40{02x:n}]", ROMX[$4000 + n]
db n
SECTION "ROMX #{d:n}", ROMX
db n db n
ENDR ENDR

View File

@@ -1,13 +1,13 @@
FATAL: All sections must be fixed when using an overlay file; 15 are not: FATAL: All sections must be fixed when using an overlay file; 12 are not:
- "test 14" - "ROMX BANK[4]" (address not specified)
- "test 13" - "ROMX BANK[3]" (address not specified)
- "test 12" - "ROMX BANK[2]" (address not specified)
- "test 11" - "ROMX BANK[1]" (address not specified)
- "test 10" - "ROMX[$4004]" (bank not specified)
- "test 9" - "ROMX[$4003]" (bank not specified)
- "test 8" - "ROMX[$4002]" (bank not specified)
- "test 7" - "ROMX[$4001]" (bank not specified)
- "test 6" - "ROMX #4" (bank and address not specified)
- "test 5" - "ROMX #3" (bank and address not specified)
- and 5 more - and 2 more
Linking aborted with 1 error Linking aborted with 1 error