mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Merge pull request #405 from ISSOtm/output_errors
Make RGBDS behave identically whether writing a .o
This commit is contained in:
@@ -40,6 +40,7 @@ void out_AbsByteGroup(char *s, int32_t length);
|
||||
void out_RelByte(struct Expression *expr);
|
||||
void out_RelWord(struct Expression *expr);
|
||||
void out_PCRelByte(struct Expression *expr);
|
||||
void out_CheckErrors(void);
|
||||
void out_WriteObject(void);
|
||||
void out_Skip(int32_t skip);
|
||||
void out_BinaryFile(char *s);
|
||||
|
||||
@@ -477,6 +477,10 @@ int main(int argc, char *argv[])
|
||||
printf("(%d lines/minute)\n",
|
||||
(int)(60 / timespent * nTotalLines));
|
||||
}
|
||||
out_WriteObject();
|
||||
|
||||
out_CheckErrors();
|
||||
/* If no path specified, don't write file */
|
||||
if (tzObjectname != NULL)
|
||||
out_WriteObject();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -265,15 +265,6 @@ static void writesymbol(struct sSymbol *pSym, FILE *f)
|
||||
int32_t sectid;
|
||||
|
||||
if (!(pSym->nType & SYMF_DEFINED)) {
|
||||
if (pSym->nType & SYMF_LOCAL) {
|
||||
char *name = pSym->tzName;
|
||||
char *localPtr = strchr(name, '.');
|
||||
|
||||
if (localPtr)
|
||||
name = localPtr;
|
||||
errx(1, "%s(%u) : '%s' not defined",
|
||||
pSym->tzFileName, pSym->nFileLine, name);
|
||||
}
|
||||
type = SYM_IMPORT;
|
||||
} else if (pSym->nType & SYMF_EXPORT) {
|
||||
type = SYM_EXPORT;
|
||||
@@ -536,26 +527,49 @@ static void checksectionoverflow(uint32_t delta_size)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Check for errors that could happen while writing an object file
|
||||
* This is important as out_WriteObject is skipped entirely when `-o` is omitted
|
||||
* Therefore, errors such as memory allocations still should be handled in
|
||||
* out_WriteObject and not here
|
||||
*/
|
||||
void out_CheckErrors(void)
|
||||
{
|
||||
/* Local symbols cannot be imported from elsewhere */
|
||||
struct PatchSymbol *pSym = pPatchSymbols;
|
||||
|
||||
while (pSym) {
|
||||
struct sSymbol *pSymbol = pSym->pSymbol;
|
||||
|
||||
if (!(pSymbol->nType & SYMF_DEFINED)
|
||||
&& pSymbol->nType & SYMF_LOCAL) {
|
||||
char *name = pSymbol->tzName;
|
||||
char *localPtr = strchr(name, '.');
|
||||
|
||||
if (localPtr)
|
||||
name = localPtr;
|
||||
errx(1, "%s(%u) : '%s' not defined",
|
||||
pSymbol->tzFileName, pSymbol->nFileLine, name);
|
||||
}
|
||||
pSym = pSym->pNext;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Write an objectfile
|
||||
*/
|
||||
void out_WriteObject(void)
|
||||
{
|
||||
FILE *f;
|
||||
struct PatchSymbol *pSym;
|
||||
struct Section *pSect;
|
||||
|
||||
addexports();
|
||||
|
||||
/* If no path specified, don't write file */
|
||||
if (tzObjectname == NULL)
|
||||
return;
|
||||
|
||||
f = fopen(tzObjectname, "wb");
|
||||
if (f == NULL)
|
||||
fatalerror("Couldn't write file '%s'\n", tzObjectname);
|
||||
|
||||
struct PatchSymbol *pSym;
|
||||
struct Section *pSect;
|
||||
|
||||
fwrite(RGBDS_OBJECT_VERSION_STRING, 1,
|
||||
strlen(RGBDS_OBJECT_VERSION_STRING), f);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user