ref: f6b7e39ce7fc91f5e0320719625bae86761c09cc
parent: 1363dd8f34ecbe5d7c0eb900a955f92303c50718
parent: b44f5825a57942f7ceb29d02fca9f9ea35e5f4f1
author: Eldred Habert <eldredhabert0@gmail.com>
date: Tue Sep 3 06:05:19 EDT 2019
Merge pull request #405 from ISSOtm/output_errors Make RGBDS behave identically whether writing a .o
--- a/include/asm/output.h
+++ b/include/asm/output.h
@@ -40,6 +40,7 @@
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);
--- a/src/asm/main.c
+++ b/src/asm/main.c
@@ -477,6 +477,10 @@
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;
}
--- a/src/asm/output.c
+++ b/src/asm/output.c
@@ -265,15 +265,6 @@
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;
@@ -537,24 +528,47 @@
}
/*
+ * 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);