mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Save object file name of each symbol in linker
This is useful to generate error messages when there is a symbol that appears in more than one object file. Signed-off-by: Antonio Niño Díaz <antonio_nd@outlook.com>
This commit is contained in:
@@ -89,6 +89,7 @@ struct sSymbol {
|
|||||||
SLONG nSectionID; /* internal to object.c */
|
SLONG nSectionID; /* internal to object.c */
|
||||||
struct sSection *pSection;
|
struct sSection *pSection;
|
||||||
SLONG nOffset;
|
SLONG nOffset;
|
||||||
|
char *pzObjFileName; /* Object file where the symbol is located. */
|
||||||
char *pzFileName; /* Source file where the symbol was defined. */
|
char *pzFileName; /* Source file where the symbol was defined. */
|
||||||
ULONG nFileLine; /* Line where the symbol was defined. */
|
ULONG nFileLine; /* Line where the symbol was defined. */
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void sym_Init(void);
|
void sym_Init(void);
|
||||||
void sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank);
|
void sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank,
|
||||||
|
char *tzObjFileName, char *tzFileName, ULONG nFileLine);
|
||||||
SLONG sym_GetValue(char *tzName);
|
SLONG sym_GetValue(char *tzName);
|
||||||
SLONG sym_GetBank(char *tzName);
|
SLONG sym_GetBank(char *tzName);
|
||||||
|
|
||||||
|
|||||||
@@ -566,16 +566,21 @@ CreateSymbolTable(void)
|
|||||||
((pSect->tSymbols[i]->pSection == pSect) ||
|
((pSect->tSymbols[i]->pSection == pSect) ||
|
||||||
(pSect->tSymbols[i]->pSection == NULL))) {
|
(pSect->tSymbols[i]->pSection == NULL))) {
|
||||||
if (pSect->tSymbols[i]->pSection == NULL)
|
if (pSect->tSymbols[i]->pSection == NULL)
|
||||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
sym_CreateSymbol(
|
||||||
pzName,
|
pSect->tSymbols[i]->pzName,
|
||||||
pSect->tSymbols[i]->
|
pSect->tSymbols[i]->nOffset,
|
||||||
nOffset, -1);
|
-1,
|
||||||
|
pSect->tSymbols[i]->pzObjFileName,
|
||||||
|
pSect->tSymbols[i]->pzFileName,
|
||||||
|
pSect->tSymbols[i]->nFileLine);
|
||||||
else
|
else
|
||||||
sym_CreateSymbol(pSect->tSymbols[i]->
|
sym_CreateSymbol(
|
||||||
pzName,
|
pSect->tSymbols[i]->pzName,
|
||||||
pSect->nOrg +
|
pSect->nOrg + pSect->tSymbols[i]->nOffset,
|
||||||
pSect->tSymbols[i]->
|
pSect->nBank,
|
||||||
nOffset, pSect->nBank);
|
pSect->tSymbols[i]->pzObjFileName,
|
||||||
|
pSect->tSymbols[i]->pzFileName,
|
||||||
|
pSect->tSymbols[i]->nFileLine);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pSect = pSect->pNext;
|
pSect = pSect->pNext;
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ AllocSection(void)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
struct sSymbol *
|
struct sSymbol *
|
||||||
obj_ReadSymbol(FILE * f)
|
obj_ReadSymbol(FILE * f, char *tzObjectfile)
|
||||||
{
|
{
|
||||||
struct sSymbol *pSym;
|
struct sSymbol *pSym;
|
||||||
|
|
||||||
@@ -128,6 +128,8 @@ obj_ReadSymbol(FILE * f)
|
|||||||
readasciiz(&pSym->pzName, f);
|
readasciiz(&pSym->pzName, f);
|
||||||
pSym->Type = (enum eSymbolType)fgetc(f);
|
pSym->Type = (enum eSymbolType)fgetc(f);
|
||||||
|
|
||||||
|
pSym->pzObjFileName = tzObjectfile;
|
||||||
|
|
||||||
if (pSym->Type != SYM_IMPORT) {
|
if (pSym->Type != SYM_IMPORT) {
|
||||||
readasciiz(&pSym->pzFileName, f);
|
readasciiz(&pSym->pzFileName, f);
|
||||||
pSym->nFileLine = readlong(f);
|
pSym->nFileLine = readlong(f);
|
||||||
@@ -268,7 +270,7 @@ obj_ReadRGBSection(FILE * f)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
obj_ReadRGB(FILE * pObjfile)
|
obj_ReadRGB(FILE * pObjfile, char *tzObjectfile)
|
||||||
{
|
{
|
||||||
struct sSection *pFirstSection;
|
struct sSection *pFirstSection;
|
||||||
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
SLONG nNumberOfSymbols, nNumberOfSections, i;
|
||||||
@@ -285,7 +287,7 @@ obj_ReadRGB(FILE * pObjfile)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < nNumberOfSymbols; i += 1)
|
for (i = 0; i < nNumberOfSymbols; i += 1)
|
||||||
tSymbols[i] = obj_ReadSymbol(pObjfile);
|
tSymbols[i] = obj_ReadSymbol(pObjfile, tzObjectfile);
|
||||||
} else
|
} else
|
||||||
tSymbols = (struct sSymbol **) & dummymem;
|
tSymbols = (struct sSymbol **) & dummymem;
|
||||||
|
|
||||||
@@ -337,7 +339,7 @@ obj_ReadOpenFile(FILE * pObjfile, char *tzObjectfile)
|
|||||||
if (strncmp(tzHeader, "RGB", 3) == 0) {
|
if (strncmp(tzHeader, "RGB", 3) == 0) {
|
||||||
switch (tzHeader[3]) {
|
switch (tzHeader[3]) {
|
||||||
case '5':
|
case '5':
|
||||||
obj_ReadRGB(pObjfile);
|
obj_ReadRGB(pObjfile, tzObjectfile);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
errx(1, "'%s' uses an unsupported object file version (%s). Please reassemble it.", tzObjectfile, tzHeader);
|
errx(1, "'%s' uses an unsupported object file version (%s). Please reassemble it.", tzObjectfile, tzHeader);
|
||||||
|
|||||||
@@ -12,8 +12,10 @@
|
|||||||
struct ISymbol {
|
struct ISymbol {
|
||||||
char *pzName;
|
char *pzName;
|
||||||
SLONG nValue;
|
SLONG nValue;
|
||||||
SLONG nBank;
|
SLONG nBank; /* -1 = constant */
|
||||||
//-1 = const
|
char tzObjFileName[_MAX_PATH + 1]; /* Object file where the symbol was defined. */
|
||||||
|
char tzFileName[_MAX_PATH + 1]; /* Source file where the symbol was defined. */
|
||||||
|
ULONG nFileLine; /* Line where the symbol was defined. */
|
||||||
struct ISymbol *pNext;
|
struct ISymbol *pNext;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,7 +78,8 @@ sym_GetBank(char *tzName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
|
sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank, char *tzObjFileName,
|
||||||
|
char *tzFileName, ULONG nFileLine)
|
||||||
{
|
{
|
||||||
if (strcmp(tzName, "@") == 0)
|
if (strcmp(tzName, "@") == 0)
|
||||||
return;
|
return;
|
||||||
@@ -102,6 +105,11 @@ sym_CreateSymbol(char *tzName, SLONG nValue, SLONG nBank)
|
|||||||
(*ppSym)->nValue = nValue;
|
(*ppSym)->nValue = nValue;
|
||||||
(*ppSym)->nBank = nBank;
|
(*ppSym)->nBank = nBank;
|
||||||
(*ppSym)->pNext = NULL;
|
(*ppSym)->pNext = NULL;
|
||||||
|
strncpy((*ppSym)->tzObjFileName, tzObjFileName,
|
||||||
|
sizeof((*ppSym)->tzObjFileName));
|
||||||
|
strncpy((*ppSym)->tzFileName, tzFileName,
|
||||||
|
sizeof((*ppSym)->tzFileName));
|
||||||
|
(*ppSym)->nFileLine = nFileLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user