From 5ba8405dfae91649d8ecc1265900fd8eb5f2387b Mon Sep 17 00:00:00 2001 From: AntonioND Date: Sat, 1 Apr 2017 15:26:44 +0100 Subject: [PATCH] Prohibit sections from having the same name To make the behaviour of the linkerscript consistent, every section read from an object file must have an unique name. This is needed as the linkerscript uses the name of sections to place them and it expects every section to have a different name. This doesn't break compatibility with the old behaviour that allowed to continue sections if they had the same name, bank number and starting address. That's still allowed because `rgbasm` outputs a single section if this functionality is used, it is transparent to `rgblink`. Signed-off-by: AntonioND --- include/link/assign.h | 3 +++ src/link/assign.c | 17 +++++++++++++++++ src/link/object.c | 12 +++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) 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);