Merge pull request #146 from AntonioND/an/same-name

Prohibit sections from having the same name
This commit is contained in:
AntonioND
2017-04-02 00:36:28 +01:00
committed by GitHub
3 changed files with 29 additions and 3 deletions

View File

@@ -35,6 +35,9 @@ extern void CreateSymbolTable(void);
extern SLONG MaxBankUsed; extern SLONG MaxBankUsed;
extern SLONG MaxAvail[MAXBANKS]; extern SLONG MaxAvail[MAXBANKS];
int
IsSectionNameInUse(const char *name);
void void
SetLinkerscriptName(char *tzLinkerscriptFile); SetLinkerscriptName(char *tzLinkerscriptFile);

View File

@@ -216,6 +216,23 @@ FindLargestSection(enum eSectionType type, bool bankFixed)
return r; 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 int
IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank) IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank)
{ {

View File

@@ -9,6 +9,7 @@
#include <string.h> #include <string.h>
#include "extern/err.h" #include "extern/err.h"
#include "link/assign.h"
#include "link/mylink.h" #include "link/mylink.h"
#include "link/main.h" #include "link/main.h"
@@ -288,14 +289,19 @@ obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents)
{ {
struct sSection *pSection; struct sSection *pSection;
pSection = AllocSection(); char * pzName;
if (contents & CONTAINS_SECTION_NAME) { 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 { } else {
pSection->pzName = ""; pzName = "";
} }
pSection = AllocSection();
pSection->pzName = pzName;
pSection->nByteSize = readlong(f); pSection->nByteSize = readlong(f);
pSection->Type = (enum eSectionType) fgetc(f); pSection->Type = (enum eSectionType) fgetc(f);
pSection->nOrg = readlong(f); pSection->nOrg = readlong(f);