diff --git a/include/link/assign.h b/include/link/assign.h index 1dab916a..9db93f49 100644 --- a/include/link/assign.h +++ b/include/link/assign.h @@ -35,6 +35,9 @@ extern void CreateSymbolTable(void); extern SLONG MaxBankUsed; extern SLONG MaxAvail[MAXBANKS]; +int +IsSectionNameInUse(const char *name); + void SetLinkerscriptName(char *tzLinkerscriptFile); diff --git a/src/link/assign.c b/src/link/assign.c index 00829b9e..0847fa29 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -216,6 +216,23 @@ FindLargestSection(enum eSectionType type, bool bankFixed) return r; } +int +IsSectionNameInUse(const char *name) +{ + struct sSection *pSection; + + pSection = pSections; + while (pSection) { + if (strcmp(pSection->pzName, name) == 0) + return 1; + + pSection = pSection->pNext; + } + + return 0; +} + + int IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank) { diff --git a/src/link/object.c b/src/link/object.c index c0ae5136..dd3fefeb 100644 --- a/src/link/object.c +++ b/src/link/object.c @@ -9,6 +9,7 @@ #include #include "extern/err.h" +#include "link/assign.h" #include "link/mylink.h" #include "link/main.h" @@ -288,14 +289,19 @@ obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents) { struct sSection *pSection; - pSection = AllocSection(); + char * pzName; if (contents & CONTAINS_SECTION_NAME) { - readasciiz(&pSection->pzName, f); + readasciiz(&pzName, f); + if (IsSectionNameInUse(pzName)) + errx(1, "Section name \"%s\" is already in use.", pzName); } else { - pSection->pzName = ""; + pzName = ""; } + pSection = AllocSection(); + pSection->pzName = pzName; + pSection->nByteSize = readlong(f); pSection->Type = (enum eSectionType) fgetc(f); pSection->nOrg = readlong(f);