ref: 63103c050d9cb31c43a0e979971df9b3a79bfab9
parent: 7e107ab41a231f7aa8926b31c638b13905fcec12
author: Ben10do <[email protected]>
date: Tue Apr 4 21:09:51 EDT 2017
Remove support for old object files Remove support for RGB0 and RGB1-2 object files, reducing the amount of duplicate work that needs doing when maintaining the linker in the future. A new error message has also been implemented if an unsupported object file version has been encounted, which informs the user that they should reassemble.
--- a/src/link/object.c
+++ b/src/link/object.c
@@ -19,11 +19,6 @@
UBYTE dummymem;
BBOOL oReadLib = 0;
-enum ObjectFileContents {
- CONTAINS_SECTION_NAME = 1 << 0,
- CONTAINS_SECTION_ALIGNMENT = 1 << 1
-};
-
/*
* The usual byte order stuff
*
@@ -137,170 +132,21 @@
}
return pSym;
}
-/*
- * RGB0 object reader routines
- *
- */
-struct sSection *
-obj_ReadRGB0Section(FILE * f)
-{
- struct sSection *pSection;
-
- pSection = AllocSection();
-
- pSection->pzName = "";
- pSection->nByteSize = readlong(f);
- pSection->Type = (enum eSectionType) fgetc(f);
- pSection->nOrg = -1;
- pSection->nBank = -1;
- pSection->nAlign = 1;
-
- if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
- errx(1, "ROMX sections can't be used with option -t.");
- }
- if ((options & OPT_CONTWRAM) && (pSection->Type == SECT_WRAMX)) {
- errx(1, "WRAMX sections can't be used with option -w.");
- }
-
- if ((pSection->Type == SECT_ROMX) || (pSection->Type == SECT_ROM0)) {
- /*
- * These sectiontypes contain data...
- *
- */
- if (pSection->nByteSize) {
- pSection->pData = malloc(pSection->nByteSize);
- if (!pSection->pData) {
- err(1, NULL);
- }
-
- SLONG nNumberOfPatches;
- struct sPatch **ppPatch, *pPatch;
-
- fread(pSection->pData, sizeof(UBYTE),
- pSection->nByteSize, f);
- nNumberOfPatches = readlong(f);
- ppPatch = &pSection->pPatches;
-
- /*
- * And patches...
- *
- */
- while (nNumberOfPatches--) {
- pPatch = malloc(sizeof *pPatch);
- if (!pPatch) {
- err(1, NULL);
- }
-
- *ppPatch = pPatch;
- readasciiz(&pPatch->pzFilename, f);
-
- pPatch->nLineNo =
- readlong(f);
- pPatch->nOffset =
- readlong(f);
- pPatch->Type =
- (enum ePatchType)
- fgetc(f);
-
- if ((pPatch->nRPNSize = readlong(f)) > 0) {
- pPatch->pRPN = malloc(pPatch->nRPNSize);
- if (!pPatch->pRPN) {
- err(1, NULL);
- }
-
- fread(pPatch->pRPN, sizeof(UBYTE),
- pPatch->nRPNSize, f);
- } else
- pPatch->pRPN = NULL;
-
- pPatch->pNext = NULL;
- ppPatch = &(pPatch->pNext);
- }
- } else {
- /* Skip number of patches */
- readlong(f);
- pSection->pData = &dummymem;
- }
- }
- return pSection;
-}
-
-void
-obj_ReadRGB0(FILE * pObjfile)
-{
- struct sSection *pFirstSection;
- SLONG nNumberOfSymbols, nNumberOfSections, i;
-
- nNumberOfSymbols = readlong(pObjfile);
- nNumberOfSections = readlong(pObjfile);
-
- /* First comes the symbols */
-
- if (nNumberOfSymbols) {
- tSymbols = malloc(nNumberOfSymbols * sizeof(struct sSymbol *));
- if (!tSymbols) {
- err(1, NULL);
- }
-
- for (i = 0; i < nNumberOfSymbols; i += 1)
- tSymbols[i] = obj_ReadSymbol(pObjfile);
- } else
- tSymbols = (struct sSymbol **) & dummymem;
-
- /* Next we have the sections */
-
- pFirstSection = NULL;
- while (nNumberOfSections--) {
- struct sSection *pNewSection;
-
- pNewSection = obj_ReadRGB0Section(pObjfile);
- pNewSection->nNumberOfSymbols = nNumberOfSymbols;
- if (pFirstSection == NULL)
- pFirstSection = pNewSection;
- }
-
- /*
- * Fill in the pSection entry in the symbolstructure.
- * This REALLY needs some cleaning up... but, hey, it works
- *
- */
-
- for (i = 0; i < nNumberOfSymbols; i += 1) {
- struct sSection *pConvSect = pFirstSection;
-
- if (tSymbols[i]->Type != SYM_IMPORT
- && tSymbols[i]->nSectionID != -1) {
- SLONG j = 0;
- while (j != tSymbols[i]->nSectionID) {
- j += 1;
- pConvSect = pConvSect->pNext;
- }
- tSymbols[i]->pSection = pConvSect;
- } else
- tSymbols[i]->pSection = NULL;
- }
-}
/*
- * RGB1 object reader routines
+ * RGB object reader routines
*
*/
-
struct sSection *
-obj_ReadRGBSection(FILE * f, enum ObjectFileContents contents)
+obj_ReadRGBSection(FILE * f)
{
struct sSection *pSection;
- char * pzName;
+ char *pzName;
+ readasciiz(&pzName, f);
+ if (IsSectionNameInUse(pzName))
+ errx(1, "Section name \"%s\" is already in use.", pzName);
- if (contents & CONTAINS_SECTION_NAME) {
- readasciiz(&pzName, f);
- if (IsSectionNameInUse(pzName))
- errx(1, "Section name \"%s\" is already in use.", pzName);
- } else {
- pzName = "";
- }
-
pSection = AllocSection();
pSection->pzName = pzName;
@@ -308,13 +154,8 @@
pSection->Type = (enum eSectionType) fgetc(f);
pSection->nOrg = readlong(f);
pSection->nBank = readlong(f);
+ pSection->nAlign = readlong(f);
- if (contents & CONTAINS_SECTION_ALIGNMENT) {
- pSection->nAlign = readlong(f);
- } else {
- pSection->nAlign = 1;
- }
-
if ((options & OPT_TINY) && (pSection->Type == SECT_ROMX)) {
errx(1, "ROMX sections can't be used with option -t.");
}
@@ -380,7 +221,7 @@
}
void
-obj_ReadRGB(FILE * pObjfile, enum ObjectFileContents contents)
+obj_ReadRGB(FILE * pObjfile)
{
struct sSection *pFirstSection;
SLONG nNumberOfSymbols, nNumberOfSections, i;
@@ -407,7 +248,7 @@
while (nNumberOfSections--) {
struct sSection *pNewSection;
- pNewSection = obj_ReadRGBSection(pObjfile, contents);
+ pNewSection = obj_ReadRGBSection(pObjfile);
pNewSection->nNumberOfSymbols = nNumberOfSymbols;
if (pFirstSection == NULL)
pFirstSection = pNewSection;
@@ -448,20 +289,12 @@
tzHeader[4] = 0;
if (strncmp(tzHeader, "RGB", 3) == 0) {
switch (tzHeader[3]) {
- case '0':
- obj_ReadRGB0(pObjfile);
- break;
- case '1':
- case '2':
- //V2 is really the same but the are new patch types
- obj_ReadRGB(pObjfile, 0);
- break;
- case '3': // V3 is very similiar, but contains section names and byte alignment
+ case '3':
case '4': // V4 supports OAM sections, but is otherwise identical
- obj_ReadRGB(pObjfile, CONTAINS_SECTION_NAME | CONTAINS_SECTION_ALIGNMENT);
+ obj_ReadRGB(pObjfile);
break;
default:
- errx(1, "'%s' is an unsupported version", tzObjectfile);
+ errx(1, "'%s' uses an unsupported object file version. Please reassemble it.", tzObjectfile);
}
} else {
errx(1, "'%s' is not a valid object", tzObjectfile);