ref: 85ff75d2d3e71e598526e94aa5987f35a385f1ef
parent: adef2e18cc8b269723109e1a316246e6a2e21513
parent: 5ba8405dfae91649d8ecc1265900fd8eb5f2387b
author: AntonioND <[email protected]>
date: Sat Apr 1 20:36:28 EDT 2017
Merge pull request #146 from AntonioND/an/same-name Prohibit sections from having the same name
--- a/include/link/assign.h
+++ b/include/link/assign.h
@@ -35,6 +35,9 @@
extern SLONG MaxBankUsed;
extern SLONG MaxAvail[MAXBANKS];
+int
+IsSectionNameInUse(const char *name);
+
void
SetLinkerscriptName(char *tzLinkerscriptFile);
--- a/src/link/assign.c
+++ b/src/link/assign.c
@@ -217,6 +217,23 @@
}
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)
{
struct sSection *pSection;
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -9,6 +9,7 @@
#include <string.h>
#include "extern/err.h"
+#include "link/assign.h"
#include "link/mylink.h"
#include "link/main.h"
@@ -288,13 +289,18 @@
{
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);