shithub: rgbds

Download patch

ref: c8e602dec130aba90f46cd462731b53e7e3e3820
parent: b168717e9164f788c6f588d8b034980c4422e2dc
author: ISSOtm <eldredhabert0@gmail.com>
date: Sat Oct 15 17:44:43 EDT 2022

Mangle the name of absolute sections

They are unlikely to be unique across files, actually

--- a/src/link/sdas_obj.c
+++ b/src/link/sdas_obj.c
@@ -272,14 +272,12 @@
 
 			getToken(line, "'A' line is too short");
 			assert(strlen(token) != 0); // This should be impossible, tokens are non-empty
-			curSection->name = strdup(token); // We need a pointer that will live longer
-			if (!curSection->name)
-				fatal(where, lineNo, "Failed to alloc new area's name: %s", strerror(errno));
 			// The following is required for fragment offsets to be reliably predicted
 			for (size_t i = 0; i < nbSections; ++i) {
 				if (!strcmp(token, fileSections[i].section->name))
 					fatal(where, lineNo, "Area \"%s\" already defined earlier", token);
 			}
+			char const *sectionName = token; // We'll deal with the section's name depending on type
 
 			expectToken("size", 'A');
 
@@ -299,6 +297,19 @@
 			curSection->isBankFixed = curSection->isAddressFixed;
 			curSection->modifier = curSection->isAddressFixed || (tmp & (1 << AREA_TYPE))
 				? SECTION_NORMAL : SECTION_FRAGMENT;
+			// If the section is absolute, its name might not be unique; thus, mangle the name
+			if (curSection->modifier == SECTION_NORMAL) {
+				size_t len = strlen(where->name) + 1 + strlen(token);
+
+				curSection->name = malloc(len + 1);
+				if (!curSection->name)
+					fatal(where, lineNo, "Failed to alloc new area's name: %s", strerror(errno));
+				sprintf(curSection->name, "%s %s", where->name, sectionName);
+			} else {
+				curSection->name = strdup(sectionName); // We need a pointer that will live longer
+				if (!curSection->name)
+					fatal(where, lineNo, "Failed to alloc new area's name: %s", strerror(errno));
+			}
 
 			expectToken("addr", 'A');