From 7233f568a7c8e7b991b9be91b7159c4d05c731f6 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 4 Nov 2019 03:24:19 +0100 Subject: [PATCH 1/2] Report overlapping sections whenever possible --- include/link/output.h | 7 +++++++ src/link/assign.c | 44 ++++++++++++++++++++++++++----------------- src/link/output.c | 14 ++++++++++++++ 3 files changed, 48 insertions(+), 17 deletions(-) diff --git a/include/link/output.h b/include/link/output.h index 0cf531c6..6b1719f2 100644 --- a/include/link/output.h +++ b/include/link/output.h @@ -20,6 +20,13 @@ */ void out_AddSection(struct Section const *section); +/** + * Finds an assigned section overlapping another one. + * @param section The section that is being overlapped + * @return A section overlapping it + */ +struct Section const *out_OverlappingSection(struct Section const *section); + /** * Writes all output (bin, sym, map) files. */ diff --git a/src/link/assign.c b/src/link/assign.c index 7ee31558..5053128a 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -1,6 +1,7 @@ #include #include +#include #include "link/assign.h" #include "link/section.h" @@ -284,32 +285,41 @@ static void placeSection(struct Section *section) return; } + /* Please adjust depending on longest message below */ + char where[64]; + if (section->isBankFixed && nbbanks(section->type) != 1) { if (section->isAddressFixed) - errx(1, "Unable to place \"%s\" (%s section) at $%02x:%04x", - section->name, typeNames[section->type], - section->bank, section->org); + snprintf(where, 64, "at $%02x:%04x", + section->bank, section->org); else if (section->isAlignFixed) - errx(1, "Unable to place \"%s\" (%s section) in bank %u with align mask %x", - section->name, typeNames[section->type], - section->bank, ~section->alignMask); + snprintf(where, 64, "in bank %02x with align mask %x", + section->bank, ~section->alignMask); else - errx(1, "Unable to place \"%s\" (%s section) in bank %u", - section->name, typeNames[section->type], - section->bank); + snprintf(where, 64, "in bank %02x", section->bank); } else { if (section->isAddressFixed) - errx(1, "Unable to place \"%s\" (%s section) at address $%x", - section->name, typeNames[section->type], - section->org); + snprintf(where, 64, "at address $%04x", section->org); else if (section->isAlignFixed) - errx(1, "Unable to place \"%s\" (%s section) with align mask %x", - section->name, typeNames[section->type], - ~section->alignMask); + snprintf(where, 64, "with align mask %x", + ~section->alignMask); else - errx(1, "Unable to place \"%s\" (%s section) anywhere", - section->name, typeNames[section->type]); + strcpy(where, "anywhere"); } + + /* If a section failed to go to several places, nothing we can report */ + if (!section->isBankFixed || !section->isAddressFixed) + errx(1, "Unable to place \"%s\" (%s section) %s", + section->name, typeNames[section->type], where); + /* If the section just can't fit the bank, report that */ + else if (section->org + section->size > endaddr(section->type) + 1) + errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region", + section->name, typeNames[section->type], where); + /* Otherwise there is overlap with another section */ + else + errx(1, "Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"", + section->name, typeNames[section->type], where, + out_OverlappingSection(section)->name); } struct UnassignedSection { diff --git a/src/link/output.c b/src/link/output.c index d7bd7132..1ddd1aa1 100644 --- a/src/link/output.c +++ b/src/link/output.c @@ -78,6 +78,20 @@ void out_AddSection(struct Section const *section) *ptr = newSection; } +struct Section const *out_OverlappingSection(struct Section const *section) +{ + struct SortedSection *ptr = + sections[section->type].banks[section->bank].sections; + + while (ptr) { + if (ptr->section->org < section->org + section->size + && section->org < ptr->section->org + ptr->section->size) + return ptr->section; + ptr = ptr->next; + } + return NULL; +} + /** * Performs sanity checks on the overlay file. */ From 44173dbe8b2bbae5349c09e4a3201b71b51d5b6c Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Wed, 6 Nov 2019 08:48:24 +0100 Subject: [PATCH 2/2] Improve error messages slightly --- src/link/assign.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/link/assign.c b/src/link/assign.c index 5053128a..524de74f 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -293,10 +293,10 @@ static void placeSection(struct Section *section) snprintf(where, 64, "at $%02x:%04x", section->bank, section->org); else if (section->isAlignFixed) - snprintf(where, 64, "in bank %02x with align mask %x", + snprintf(where, 64, "in bank $%02x with align mask %x", section->bank, ~section->alignMask); else - snprintf(where, 64, "in bank %02x", section->bank); + snprintf(where, 64, "in bank $%02x", section->bank); } else { if (section->isAddressFixed) snprintf(where, 64, "at address $%04x", section->org); @@ -313,8 +313,9 @@ static void placeSection(struct Section *section) section->name, typeNames[section->type], where); /* If the section just can't fit the bank, report that */ else if (section->org + section->size > endaddr(section->type) + 1) - errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region", - section->name, typeNames[section->type], where); + errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)", + section->name, typeNames[section->type], where, + section->org + section->size, endaddr(section->type) + 1); /* Otherwise there is overlap with another section */ else errx(1, "Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",