shithub: rgbds

Download patch

ref: 7af2d5dfe1b586484b678ff136cb35c378612c72
parent: c59cb6a828c259292dd0eade7ea23d6112e84f4e
author: Jakub Kądziołka <kuba@kadziolka.net>
date: Sun Mar 3 17:55:17 EST 2019

Print location information in linker errors where viable

--- a/include/link/symbol.h
+++ b/include/link/symbol.h
@@ -15,7 +15,7 @@
 void sym_CreateSymbol(char *tzName, int32_t nValue, int32_t nBank,
 		      char *tzObjFileName, char *tzFileName,
 		      uint32_t nFileLine);
-int32_t sym_GetValue(char *tzName);
-int32_t sym_GetBank(char *tzName);
+int32_t sym_GetValue(struct sPatch *pPatch, char *tzName);
+int32_t sym_GetBank(struct sPatch *pPatch, char *tzName);
 
 #endif /* RGBDS_LINK_SYMBOL_H */
--- a/src/link/patch.c
+++ b/src/link/patch.c
@@ -35,13 +35,13 @@
 	return rpnstack[rpnp];
 }
 
-static int32_t getsymvalue(int32_t symid)
+static int32_t getsymvalue(struct sPatch *pPatch, int32_t symid)
 {
 	const struct sSymbol *tSymbol = pCurrentSection->tSymbols[symid];
 
 	switch (tSymbol->Type) {
 	case SYM_IMPORT:
-		return sym_GetValue(tSymbol->pzName);
+		return sym_GetValue(pPatch, tSymbol->pzName);
 
 	case SYM_EXPORT:
 	case SYM_LOCAL:
@@ -75,7 +75,7 @@
 	return n;
 }
 
-static int32_t getsymbank(int32_t symid)
+static int32_t getsymbank(struct sPatch *pPatch, int32_t symid)
 {
 	int32_t nBank;
 	const struct sSymbol *tSymbol = pCurrentSection->tSymbols[symid];
@@ -82,7 +82,7 @@
 
 	switch (tSymbol->Type) {
 	case SYM_IMPORT:
-		nBank = sym_GetBank(tSymbol->pzName);
+		nBank = sym_GetBank(pPatch, tSymbol->pzName);
 		break;
 	case SYM_EXPORT:
 	case SYM_LOCAL:
@@ -209,8 +209,8 @@
 			t |= (*rpn++) << 8;
 			t |= (*rpn++) << 16;
 			t |= (*rpn++) << 24;
-			rpnpush(getsymvalue(t));
-			pPatch->oRelocPatch |= (getsymbank(t) != -1);
+			rpnpush(getsymvalue(pPatch, t));
+			pPatch->oRelocPatch |= (getsymbank(pPatch, t) != -1);
 			size -= 4;
 			break;
 		case RPN_BANK_SYM:
@@ -219,7 +219,7 @@
 			t |= (*rpn++) << 8;
 			t |= (*rpn++) << 16;
 			t |= (*rpn++) << 24;
-			rpnpush(getsymbank(t));
+			rpnpush(getsymbank(pPatch, t));
 			size -= 4;
 			break;
 		case RPN_BANK_SECT:
@@ -229,7 +229,9 @@
 			struct sSection *pSection = GetSectionByName(name);
 
 			if (pSection == NULL) {
-				errx(1, "Requested BANK() of section \"%s\", which was not found.\n",
+				errx(1,
+				     "%s(%ld) : Requested BANK() of section \"%s\", which was not found.\n",
+				     pPatch->pzFilename, pPatch->nLineNo,
 				     name);
 			}
 
--- a/src/link/symbol.c
+++ b/src/link/symbol.c
@@ -15,6 +15,7 @@
 
 #include "link/main.h"
 #include "link/patch.h"
+#include "link/mylink.h"
 
 #include "types.h"
 
@@ -53,7 +54,7 @@
 		tHash[i] = NULL;
 }
 
-int32_t sym_GetValue(char *tzName)
+int32_t sym_GetValue(struct sPatch *pPatch, char *tzName)
 {
 	if (strcmp(tzName, "@") == 0)
 		return nPC;
@@ -68,10 +69,13 @@
 			return ((*ppSym)->nValue);
 	}
 
-	errx(1, "Unknown symbol '%s'", tzName);
+	errx(1,
+	     "%s(%ld) : Unknown symbol '%s'",
+	     pPatch->pzFilename, pPatch->nLineNo,
+	     tzName);
 }
 
-int32_t sym_GetBank(char *tzName)
+int32_t sym_GetBank(struct sPatch *pPatch, char *tzName)
 {
 	struct ISymbol **ppSym;
 
@@ -83,7 +87,10 @@
 			return ((*ppSym)->nBank);
 	}
 
-	errx(1, "Unknown symbol '%s'", tzName);
+	errx(1,
+	     "%s(%ld) : Unknown symbol '%s'",
+	     pPatch->pzFilename, pPatch->nLineNo,
+	     tzName);
 }
 
 void sym_CreateSymbol(char *tzName, int32_t nValue, int32_t nBank,