mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-23 19:42:08 +00:00
Refactor error reporting to simplify BSD-style err (#949)
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
#include "link/script.h"
|
||||
#include "link/output.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
#include "helpers.h"
|
||||
|
||||
struct MemoryLocation {
|
||||
@@ -46,13 +46,13 @@ static void initFreeSpace(void)
|
||||
for (enum SectionType type = 0; type < SECTTYPE_INVALID; type++) {
|
||||
memory[type] = malloc(sizeof(*memory[type]) * nbbanks(type));
|
||||
if (!memory[type])
|
||||
err(1, "Failed to init free space for region %d", type);
|
||||
err("Failed to init free space for region %d", type);
|
||||
|
||||
for (uint32_t bank = 0; bank < nbbanks(type); bank++) {
|
||||
memory[type][bank].next =
|
||||
malloc(sizeof(*memory[type][0].next));
|
||||
if (!memory[type][bank].next)
|
||||
err(1, "Failed to init free space for region %d bank %" PRIu32,
|
||||
err("Failed to init free space for region %d bank %" PRIu32,
|
||||
type, bank);
|
||||
memory[type][bank].next->address = startaddr[type];
|
||||
memory[type][bank].next->size = maxsize[type];
|
||||
@@ -301,7 +301,7 @@ static void placeSection(struct Section *section)
|
||||
struct FreeSpace *newSpace = malloc(sizeof(*newSpace));
|
||||
|
||||
if (!newSpace)
|
||||
err(1, "Failed to split new free space");
|
||||
err("Failed to split new free space");
|
||||
/* Append the new space after the chosen one */
|
||||
newSpace->prev = freeSpace;
|
||||
newSpace->next = freeSpace->next;
|
||||
@@ -352,16 +352,16 @@ static void placeSection(struct Section *section)
|
||||
|
||||
/* If a section failed to go to several places, nothing we can report */
|
||||
if (!section->isBankFixed || !section->isAddressFixed)
|
||||
errx(1, "Unable to place \"%s\" (%s section) %s",
|
||||
errx("Unable to place \"%s\" (%s section) %s",
|
||||
section->name, typeNames[section->type], where);
|
||||
/* If the section just can't fit the bank, report that */
|
||||
else if (section->org + section->size > endaddr(section->type) + 1)
|
||||
errx(1, "Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)",
|
||||
errx("Unable to place \"%s\" (%s section) %s: section runs past end of region ($%04x > $%04x)",
|
||||
section->name, typeNames[section->type], where,
|
||||
section->org + section->size, endaddr(section->type) + 1);
|
||||
/* Otherwise there is overlap with another section */
|
||||
else
|
||||
errx(1, "Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
||||
errx("Unable to place \"%s\" (%s section) %s: section overlaps with \"%s\"",
|
||||
section->name, typeNames[section->type], where,
|
||||
out_OverlappingSection(section)->name);
|
||||
}
|
||||
@@ -418,7 +418,7 @@ void assign_AssignSections(void)
|
||||
/* Generate linked lists of sections to assign */
|
||||
sections = malloc(sizeof(*sections) * nbSectionsToAssign + 1);
|
||||
if (!sections)
|
||||
err(1, "Failed to allocate memory for section assignment");
|
||||
err("Failed to allocate memory for section assignment");
|
||||
|
||||
initFreeSpace();
|
||||
|
||||
@@ -447,7 +447,7 @@ void assign_AssignSections(void)
|
||||
/* Overlaying requires only fully-constrained sections */
|
||||
verbosePrint("Assigning other sections...\n");
|
||||
if (overlayFileName)
|
||||
errx(1, "All sections must be fixed when using an overlay file; %" PRIu64 " %sn't",
|
||||
errx("All sections must be fixed when using an overlay file; %" PRIu64 " %sn't",
|
||||
nbSectionsToAssign, nbSectionsToAssign == 1 ? "is" : "are");
|
||||
|
||||
/* Assign all remaining sections by decreasing constraint order */
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
#include "link/patch.h"
|
||||
#include "link/output.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "extern/getopt.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "platform.h"
|
||||
#include "version.h"
|
||||
|
||||
@@ -156,7 +157,7 @@ FILE *openFile(char const *fileName, char const *mode)
|
||||
file = fdopen(1, mode);
|
||||
|
||||
if (!file)
|
||||
err(1, "Could not open file \"%s\"", fileName);
|
||||
err("Could not open file \"%s\"", fileName);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "link/section.h"
|
||||
#include "link/symbol.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
#include "helpers.h"
|
||||
#include "linkdefs.h"
|
||||
|
||||
@@ -50,7 +50,7 @@ static struct Assertion *assertions;
|
||||
type tmpVal = func(tmpFile); \
|
||||
/* TODO: maybe mark the condition as `unlikely`; how to do that portably? */ \
|
||||
if (tmpVal == (errval)) { \
|
||||
errx(1, __VA_ARGS__, feof(tmpFile) \
|
||||
errx(__VA_ARGS__, feof(tmpFile) \
|
||||
? "Unexpected end of file" \
|
||||
: strerror(errno)); \
|
||||
} \
|
||||
@@ -289,13 +289,13 @@ static void readPatch(FILE *file, struct Patch *patch, char const *fileName, cha
|
||||
|
||||
patch->rpnExpression = malloc(sizeof(*patch->rpnExpression) * patch->rpnSize);
|
||||
if (!patch->rpnExpression)
|
||||
err(1, "%s: Failed to alloc \"%s\"'s patch #%" PRIu32 "'s RPN expression",
|
||||
err("%s: Failed to alloc \"%s\"'s patch #%" PRIu32 "'s RPN expression",
|
||||
fileName, sectName, i);
|
||||
size_t nbElementsRead = fread(patch->rpnExpression, sizeof(*patch->rpnExpression),
|
||||
patch->rpnSize, file);
|
||||
|
||||
if (nbElementsRead != patch->rpnSize)
|
||||
errx(1, "%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
errx("%s: Cannot read \"%s\"'s patch #%" PRIu32 "'s RPN expression: %s",
|
||||
fileName, sectName, i,
|
||||
feof(file) ? "Unexpected end of file" : strerror(errno));
|
||||
}
|
||||
@@ -327,7 +327,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
tryReadlong(tmp, file, "%s: Cannot read \"%s\"'s' size: %s",
|
||||
fileName, section->name);
|
||||
if (tmp < 0 || tmp > UINT16_MAX)
|
||||
errx(1, "\"%s\"'s section size (%" PRId32 ") is invalid",
|
||||
errx("\"%s\"'s section size (%" PRId32 ") is invalid",
|
||||
section->name, tmp);
|
||||
section->size = tmp;
|
||||
section->offset = 0;
|
||||
@@ -373,13 +373,13 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
uint8_t *data = malloc(sizeof(*data) * section->size + 1);
|
||||
|
||||
if (!data)
|
||||
err(1, "%s: Unable to read \"%s\"'s data", fileName,
|
||||
err("%s: Unable to read \"%s\"'s data", fileName,
|
||||
section->name);
|
||||
if (section->size) {
|
||||
size_t nbElementsRead = fread(data, sizeof(*data),
|
||||
section->size, file);
|
||||
if (nbElementsRead != section->size)
|
||||
errx(1, "%s: Cannot read \"%s\"'s data: %s",
|
||||
errx("%s: Cannot read \"%s\"'s data: %s",
|
||||
fileName, section->name,
|
||||
feof(file) ? "Unexpected end of file"
|
||||
: strerror(errno));
|
||||
@@ -394,7 +394,7 @@ static void readSection(FILE *file, struct Section *section, char const *fileNam
|
||||
malloc(sizeof(*patches) * section->nbPatches + 1);
|
||||
|
||||
if (!patches)
|
||||
err(1, "%s: Unable to read \"%s\"'s patches", fileName, section->name);
|
||||
err("%s: Unable to read \"%s\"'s patches", fileName, section->name);
|
||||
for (uint32_t i = 0; i < section->nbPatches; i++)
|
||||
readPatch(file, &patches[i], fileName, section->name, i, fileNodes);
|
||||
section->patches = patches;
|
||||
@@ -462,7 +462,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
FILE *file = strcmp("-", fileName) ? fopen(fileName, "rb") : stdin;
|
||||
|
||||
if (!file)
|
||||
err(1, "Could not open file %s", fileName);
|
||||
err("Could not open file %s", fileName);
|
||||
|
||||
/* Begin by reading the magic bytes and version number */
|
||||
unsigned versionNumber;
|
||||
@@ -470,13 +470,13 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
&versionNumber);
|
||||
|
||||
if (matchedElems != 1)
|
||||
errx(1, "\"%s\" is not a RGBDS object file", fileName);
|
||||
errx("\"%s\" is not a RGBDS object file", fileName);
|
||||
|
||||
verbosePrint("Reading object file %s, version %u\n",
|
||||
fileName, versionNumber);
|
||||
|
||||
if (versionNumber != RGBDS_OBJECT_VERSION_NUMBER)
|
||||
errx(1, "\"%s\" is an incompatible version %u object file",
|
||||
errx("\"%s\" is an incompatible version %u object file",
|
||||
fileName, versionNumber);
|
||||
|
||||
uint32_t revNum;
|
||||
@@ -484,7 +484,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
tryReadlong(revNum, file, "%s: Cannot read revision number: %s",
|
||||
fileName);
|
||||
if (revNum != RGBDS_OBJECT_REV)
|
||||
errx(1, "%s is a revision 0x%04" PRIx32 " object file; only 0x%04x is supported",
|
||||
errx("%s is a revision 0x%04" PRIx32 " object file; only 0x%04x is supported",
|
||||
fileName, revNum, RGBDS_OBJECT_REV);
|
||||
|
||||
uint32_t nbSymbols;
|
||||
@@ -500,7 +500,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
tryReadlong(nodes[fileID].nbNodes, file, "%s: Cannot read number of nodes: %s", fileName);
|
||||
nodes[fileID].nodes = calloc(nodes[fileID].nbNodes, sizeof(nodes[fileID].nodes[0]));
|
||||
if (!nodes[fileID].nodes)
|
||||
err(1, "Failed to get memory for %s's nodes", fileName);
|
||||
err("Failed to get memory for %s's nodes", fileName);
|
||||
verbosePrint("Reading %u nodes...\n", nodes[fileID].nbNodes);
|
||||
for (uint32_t i = nodes[fileID].nbNodes; i--; )
|
||||
readFileStackNode(file, nodes[fileID].nodes, i, fileName);
|
||||
@@ -510,12 +510,12 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
malloc(sizeof(*fileSymbols) * nbSymbols + 1);
|
||||
|
||||
if (!fileSymbols)
|
||||
err(1, "Failed to get memory for %s's symbols", fileName);
|
||||
err("Failed to get memory for %s's symbols", fileName);
|
||||
|
||||
struct SymbolList *symbolList = malloc(sizeof(*symbolList));
|
||||
|
||||
if (!symbolList)
|
||||
err(1, "Failed to register %s's symbol list", fileName);
|
||||
err("Failed to register %s's symbol list", fileName);
|
||||
symbolList->symbolList = fileSymbols;
|
||||
symbolList->nbSymbols = nbSymbols;
|
||||
symbolList->next = symbolLists;
|
||||
@@ -530,7 +530,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
struct Symbol *symbol = malloc(sizeof(*symbol));
|
||||
|
||||
if (!symbol)
|
||||
err(1, "%s: Couldn't create new symbol", fileName);
|
||||
err("%s: Couldn't create new symbol", fileName);
|
||||
readSymbol(file, symbol, fileName, nodes[fileID].nodes);
|
||||
|
||||
fileSymbols[i] = symbol;
|
||||
@@ -549,7 +549,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
/* Read section */
|
||||
fileSections[i] = malloc(sizeof(*fileSections[i]));
|
||||
if (!fileSections[i])
|
||||
err(1, "%s: Couldn't create new section", fileName);
|
||||
err("%s: Couldn't create new section", fileName);
|
||||
|
||||
fileSections[i]->nextu = NULL;
|
||||
readSection(file, fileSections[i], fileName, nodes[fileID].nodes);
|
||||
@@ -558,7 +558,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
fileSections[i]->symbols = malloc(nbSymPerSect[i]
|
||||
* sizeof(*fileSections[i]->symbols));
|
||||
if (!fileSections[i]->symbols)
|
||||
err(1, "%s: Couldn't link to symbols",
|
||||
err("%s: Couldn't link to symbols",
|
||||
fileName);
|
||||
} else {
|
||||
fileSections[i]->symbols = NULL;
|
||||
@@ -609,7 +609,7 @@ void obj_ReadFile(char const *fileName, unsigned int fileID)
|
||||
struct Assertion *assertion = malloc(sizeof(*assertion));
|
||||
|
||||
if (!assertion)
|
||||
err(1, "%s: Couldn't create new assertion", fileName);
|
||||
err("%s: Couldn't create new assertion", fileName);
|
||||
readAssertion(file, assertion, fileName, i, nodes[fileID].nodes);
|
||||
linkPatchToPCSect(&assertion->patch, fileSections);
|
||||
assertion->fileSymbols = fileSymbols;
|
||||
|
||||
@@ -16,10 +16,8 @@
|
||||
#include "link/section.h"
|
||||
#include "link/symbol.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "linkdefs.h"
|
||||
|
||||
#include "platform.h" // MIN_NB_ELMS
|
||||
|
||||
#define BANK_SIZE 0x4000
|
||||
@@ -77,7 +75,7 @@ void out_AddSection(struct Section const *section)
|
||||
uint32_t minNbBanks = targetBank + 1;
|
||||
|
||||
if (minNbBanks > maxNbBanks[section->type])
|
||||
errx(1, "Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||
errx("Section \"%s\" has an invalid bank range (%" PRIu32 " > %" PRIu32 ")",
|
||||
section->name, section->bank,
|
||||
maxNbBanks[section->type] - 1);
|
||||
|
||||
@@ -92,7 +90,7 @@ void out_AddSection(struct Section const *section)
|
||||
sections[section->type].nbBanks = minNbBanks;
|
||||
}
|
||||
if (!sections[section->type].banks)
|
||||
err(1, "Failed to realloc banks");
|
||||
err("Failed to realloc banks");
|
||||
|
||||
struct SortedSection *newSection = malloc(sizeof(*newSection));
|
||||
struct SortedSection **ptr = section->size
|
||||
@@ -100,7 +98,7 @@ void out_AddSection(struct Section const *section)
|
||||
: §ions[section->type].banks[targetBank].zeroLenSections;
|
||||
|
||||
if (!newSection)
|
||||
err(1, "Failed to add new section \"%s\"", section->name);
|
||||
err("Failed to add new section \"%s\"", section->name);
|
||||
newSection->section = section;
|
||||
|
||||
while (*ptr && (*ptr)->section->org < section->org)
|
||||
@@ -145,15 +143,15 @@ static uint32_t checkOverlaySize(void)
|
||||
fseek(overlayFile, 0, SEEK_SET);
|
||||
|
||||
if (overlaySize % BANK_SIZE)
|
||||
errx(1, "Overlay file must have a size multiple of 0x4000");
|
||||
errx("Overlay file must have a size multiple of 0x4000");
|
||||
|
||||
uint32_t nbOverlayBanks = overlaySize / BANK_SIZE;
|
||||
|
||||
if (is32kMode && nbOverlayBanks != 2)
|
||||
errx(1, "Overlay must be exactly 0x8000 bytes large");
|
||||
errx("Overlay must be exactly 0x8000 bytes large");
|
||||
|
||||
if (nbOverlayBanks < 2)
|
||||
errx(1, "Overlay must be at least 0x8000 bytes large");
|
||||
errx("Overlay must be at least 0x8000 bytes large");
|
||||
|
||||
return nbOverlayBanks;
|
||||
}
|
||||
@@ -178,7 +176,7 @@ static void coverOverlayBanks(uint32_t nbOverlayBanks)
|
||||
realloc(sections[SECTTYPE_ROMX].banks,
|
||||
sizeof(*sections[SECTTYPE_ROMX].banks) * nbUncoveredBanks);
|
||||
if (!sections[SECTTYPE_ROMX].banks)
|
||||
err(1, "Failed to realloc banks for overlay");
|
||||
err("Failed to realloc banks for overlay");
|
||||
for (uint32_t i = sections[SECTTYPE_ROMX].nbBanks; i < nbUncoveredBanks; i++) {
|
||||
sections[SECTTYPE_ROMX].banks[i].sections = NULL;
|
||||
sections[SECTTYPE_ROMX].banks[i].zeroLenSections = NULL;
|
||||
@@ -317,7 +315,7 @@ static void writeSymBank(struct SortedSections const *bankSections,
|
||||
struct SortedSymbol *symList = malloc(sizeof(*symList) * nbSymbols);
|
||||
|
||||
if (!symList)
|
||||
err(1, "Failed to allocate symbol list");
|
||||
err("Failed to allocate symbol list");
|
||||
|
||||
uint32_t idx = 0;
|
||||
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
#include "link/section.h"
|
||||
#include "link/symbol.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "linkdefs.h"
|
||||
#include "opmath.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
/*
|
||||
* This is an "empty"-type stack. Apart from the actual values, we also remember
|
||||
* whether the value is a placeholder inserted for error recovery. This allows
|
||||
@@ -43,7 +42,7 @@ static void initRPNStack(void)
|
||||
stack.values = malloc(sizeof(*stack.values) * stack.capacity);
|
||||
stack.errorFlags = malloc(sizeof(*stack.errorFlags) * stack.capacity);
|
||||
if (!stack.values || !stack.errorFlags)
|
||||
err(1, "Failed to init RPN stack");
|
||||
err("Failed to init RPN stack");
|
||||
}
|
||||
|
||||
static void clearRPNStack(void)
|
||||
@@ -57,7 +56,7 @@ static void pushRPN(int32_t value, bool comesFromError)
|
||||
static const size_t increase_factor = 2;
|
||||
|
||||
if (stack.capacity > SIZE_MAX / increase_factor)
|
||||
errx(1, "Overflow in RPN stack resize");
|
||||
errx("Overflow in RPN stack resize");
|
||||
|
||||
stack.capacity *= increase_factor;
|
||||
stack.values =
|
||||
@@ -70,7 +69,7 @@ static void pushRPN(int32_t value, bool comesFromError)
|
||||
* the overflow check above. Hence the stringent check below.
|
||||
*/
|
||||
if (!stack.values || !stack.errorFlags || !stack.capacity)
|
||||
err(1, "Failed to resize RPN stack");
|
||||
err("Failed to resize RPN stack");
|
||||
}
|
||||
|
||||
stack.values[stack.size] = value;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "link/script.h"
|
||||
#include "link/section.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
|
||||
FILE *linkerScript;
|
||||
char *includeFileName;
|
||||
@@ -36,7 +36,7 @@ static uint32_t fileStackIndex;
|
||||
static void pushFile(char *newFileName)
|
||||
{
|
||||
if (fileStackIndex == UINT32_MAX)
|
||||
errx(1, "%s(%" PRIu32 "): INCLUDE recursion limit reached",
|
||||
errx("%s(%" PRIu32 "): INCLUDE recursion limit reached",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
if (fileStackIndex == fileStackSize) {
|
||||
@@ -45,7 +45,7 @@ static void pushFile(char *newFileName)
|
||||
fileStackSize *= 2;
|
||||
fileStack = realloc(fileStack, sizeof(*fileStack) * fileStackSize);
|
||||
if (!fileStack)
|
||||
err(1, "%s(%" PRIu32 "): Internal INCLUDE error",
|
||||
err("%s(%" PRIu32 "): Internal INCLUDE error",
|
||||
linkerScriptName, lineNo);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ static void pushFile(char *newFileName)
|
||||
|
||||
linkerScript = fopen(newFileName, "r");
|
||||
if (!linkerScript)
|
||||
err(1, "%s(%" PRIu32 "): Could not open \"%s\"",
|
||||
err("%s(%" PRIu32 "): Could not open \"%s\"",
|
||||
linkerScriptName, lineNo, newFileName);
|
||||
lineNo = 1;
|
||||
linkerScriptName = newFileName;
|
||||
@@ -177,7 +177,7 @@ static int nextChar(void)
|
||||
int curchar = getc(linkerScript);
|
||||
|
||||
if (curchar == EOF && ferror(linkerScript))
|
||||
err(1, "%s(%" PRIu32 "): Unexpected error in %s",
|
||||
err("%s(%" PRIu32 "): Unexpected error in %s",
|
||||
linkerScriptName, lineNo, __func__);
|
||||
return curchar;
|
||||
}
|
||||
@@ -226,7 +226,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
do {
|
||||
curchar = nextChar();
|
||||
if (curchar == EOF || isNewline(curchar)) {
|
||||
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
||||
errx("%s(%" PRIu32 "): Unterminated string",
|
||||
linkerScriptName, lineNo);
|
||||
} else if (curchar == '"') {
|
||||
/* Quotes force a string termination */
|
||||
@@ -235,7 +235,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
/* Backslashes are escape sequences */
|
||||
curchar = nextChar();
|
||||
if (curchar == EOF || isNewline(curchar))
|
||||
errx(1, "%s(%" PRIu32 "): Unterminated string",
|
||||
errx("%s(%" PRIu32 "): Unterminated string",
|
||||
linkerScriptName, lineNo);
|
||||
else if (curchar == 'n')
|
||||
curchar = '\n';
|
||||
@@ -244,7 +244,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
else if (curchar == 't')
|
||||
curchar = '\t';
|
||||
else if (curchar != '\\' && curchar != '"')
|
||||
errx(1, "%s(%" PRIu32 "): Illegal character escape",
|
||||
errx("%s(%" PRIu32 "): Illegal character escape",
|
||||
linkerScriptName, lineNo);
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
capacity *= 2;
|
||||
token.attr.string = realloc(token.attr.string, capacity);
|
||||
if (!token.attr.string)
|
||||
err(1, "%s: Failed to allocate memory for string",
|
||||
err("%s: Failed to allocate memory for string",
|
||||
__func__);
|
||||
}
|
||||
token.attr.string[size++] = curchar;
|
||||
@@ -268,7 +268,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
capacity *= 2;
|
||||
str = realloc(str, capacity);
|
||||
if (!str)
|
||||
err(1, "%s: Failed to allocate memory for token",
|
||||
err("%s: Failed to allocate memory for token",
|
||||
__func__);
|
||||
}
|
||||
str[size] = toupper(curchar);
|
||||
@@ -318,7 +318,7 @@ static struct LinkerScriptToken *nextToken(void)
|
||||
if (tryParseNumber(str, &token.attr.number))
|
||||
token.type = TOKEN_NUMBER;
|
||||
else
|
||||
errx(1, "%s(%" PRIu32 "): Unknown token \"%s\"",
|
||||
errx("%s(%" PRIu32 "): Unknown token \"%s\"",
|
||||
linkerScriptName, lineNo, str);
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ static void processCommand(enum LinkerScriptCommand command, uint16_t arg, uint1
|
||||
}
|
||||
|
||||
if (arg < *pc)
|
||||
errx(1, "%s(%" PRIu32 "): `%s` cannot be used to go backwards (currently at $%x)",
|
||||
errx("%s(%" PRIu32 "): `%s` cannot be used to go backwards (currently at $%x)",
|
||||
linkerScriptName, lineNo, commands[command], *pc);
|
||||
*pc = arg;
|
||||
}
|
||||
@@ -394,11 +394,11 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
if (type != SECTTYPE_INVALID) {
|
||||
if (curaddr[type][bankID] > endaddr(type) + 1)
|
||||
errx(1, "%s(%" PRIu32 "): Sections would extend past the end of %s ($%04" PRIx16 " > $%04" PRIx16 ")",
|
||||
errx("%s(%" PRIu32 "): Sections would extend past the end of %s ($%04" PRIx16 " > $%04" PRIx16 ")",
|
||||
linkerScriptName, lineNo, typeNames[type],
|
||||
curaddr[type][bankID], endaddr(type));
|
||||
if (curaddr[type][bankID] < startaddr[type])
|
||||
errx(1, "%s(%" PRIu32 "): PC underflowed ($%04" PRIx16 " < $%04" PRIx16 ")",
|
||||
errx("%s(%" PRIu32 "): PC underflowed ($%04" PRIx16 " < $%04" PRIx16 ")",
|
||||
linkerScriptName, lineNo,
|
||||
curaddr[type][bankID], startaddr[type]);
|
||||
}
|
||||
@@ -419,7 +419,7 @@ struct SectionPlacement *script_NextSection(void)
|
||||
break;
|
||||
|
||||
case TOKEN_NUMBER:
|
||||
errx(1, "%s(%" PRIu32 "): stray number \"%" PRIu32 "\"",
|
||||
errx("%s(%" PRIu32 "): stray number \"%" PRIu32 "\"",
|
||||
linkerScriptName, lineNo,
|
||||
token->attr.number);
|
||||
|
||||
@@ -432,13 +432,13 @@ struct SectionPlacement *script_NextSection(void)
|
||||
parserState = PARSER_LINEEND;
|
||||
|
||||
if (type == SECTTYPE_INVALID)
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the section",
|
||||
errx("%s(%" PRIu32 "): Didn't specify a location before the section",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
section.section =
|
||||
sect_GetSection(token->attr.string);
|
||||
if (!section.section)
|
||||
errx(1, "%s(%" PRIu32 "): Unknown section \"%s\"",
|
||||
errx("%s(%" PRIu32 "): Unknown section \"%s\"",
|
||||
linkerScriptName, lineNo,
|
||||
token->attr.string);
|
||||
section.org = curaddr[type][bankID];
|
||||
@@ -467,10 +467,10 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
if (tokType == TOKEN_COMMAND) {
|
||||
if (type == SECTTYPE_INVALID)
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a location before the command",
|
||||
errx("%s(%" PRIu32 "): Didn't specify a location before the command",
|
||||
linkerScriptName, lineNo);
|
||||
if (!hasArg)
|
||||
errx(1, "%s(%" PRIu32 "): Command specified without an argument",
|
||||
errx("%s(%" PRIu32 "): Command specified without an argument",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
processCommand(attr.command, arg, &curaddr[type][bankID]);
|
||||
@@ -481,16 +481,16 @@ struct SectionPlacement *script_NextSection(void)
|
||||
* specifying the number is optional.
|
||||
*/
|
||||
if (!hasArg && nbbanks(type) != 1)
|
||||
errx(1, "%s(%" PRIu32 "): Didn't specify a bank number",
|
||||
errx("%s(%" PRIu32 "): Didn't specify a bank number",
|
||||
linkerScriptName, lineNo);
|
||||
else if (!hasArg)
|
||||
arg = bankranges[type][0];
|
||||
else if (arg < bankranges[type][0])
|
||||
errx(1, "%s(%" PRIu32 "): specified bank number is too low (%" PRIu32 " < %" PRIu32 ")",
|
||||
errx("%s(%" PRIu32 "): specified bank number is too low (%" PRIu32 " < %" PRIu32 ")",
|
||||
linkerScriptName, lineNo,
|
||||
arg, bankranges[type][0]);
|
||||
else if (arg > bankranges[type][1])
|
||||
errx(1, "%s(%" PRIu32 "): specified bank number is too high (%" PRIu32 " > %" PRIu32 ")",
|
||||
errx("%s(%" PRIu32 "): specified bank number is too high (%" PRIu32 " > %" PRIu32 ")",
|
||||
linkerScriptName, lineNo,
|
||||
arg, bankranges[type][1]);
|
||||
bank = arg;
|
||||
@@ -510,7 +510,7 @@ struct SectionPlacement *script_NextSection(void)
|
||||
|
||||
case PARSER_INCLUDE:
|
||||
if (token->type != TOKEN_STRING)
|
||||
errx(1, "%s(%" PRIu32 "): Expected a file name after INCLUDE",
|
||||
errx("%s(%" PRIu32 "): Expected a file name after INCLUDE",
|
||||
linkerScriptName, lineNo);
|
||||
|
||||
/* Switch to that file */
|
||||
@@ -530,7 +530,7 @@ lineend:
|
||||
return NULL;
|
||||
parserState = PARSER_LINEEND;
|
||||
} else if (token->type != TOKEN_NEWLINE)
|
||||
errx(1, "%s(%" PRIu32 "): Unexpected %s at the end of the line",
|
||||
errx("%s(%" PRIu32 "): Unexpected %s at the end of the line",
|
||||
linkerScriptName, lineNo,
|
||||
tokenTypes[token->type]);
|
||||
break;
|
||||
|
||||
@@ -14,8 +14,7 @@
|
||||
#include "link/main.h"
|
||||
#include "link/section.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
|
||||
#include "error.h"
|
||||
#include "hashmap.h"
|
||||
|
||||
HashMap sections;
|
||||
@@ -44,12 +43,12 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
if (other->isAddressFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != other->org)
|
||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%04"
|
||||
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||
PRIx16 " and $%04" PRIx16,
|
||||
other->name, target->org, other->org);
|
||||
} else if (target->isAlignFixed) {
|
||||
if ((other->org - target->alignOfs) & target->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and address $%04" PRIx16,
|
||||
other->name, target->alignMask + 1,
|
||||
target->alignOfs, other->org);
|
||||
@@ -60,14 +59,14 @@ static void checkSectUnionCompat(struct Section *target, struct Section *other)
|
||||
} else if (other->isAlignFixed) {
|
||||
if (target->isAddressFixed) {
|
||||
if ((target->org - other->alignOfs) & other->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting address $%04"
|
||||
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->org,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
} else if (target->isAlignFixed
|
||||
&& (other->alignMask & target->alignOfs)
|
||||
!= (target->alignMask & other->alignOfs)) {
|
||||
errx(1, "Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->alignMask + 1, target->alignOfs,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
@@ -85,13 +84,13 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
|
||||
if (target->isAddressFixed) {
|
||||
if (target->org != org)
|
||||
errx(1, "Section \"%s\" is defined with conflicting addresses $%04"
|
||||
errx("Section \"%s\" is defined with conflicting addresses $%04"
|
||||
PRIx16 " and $%04" PRIx16,
|
||||
other->name, target->org, other->org);
|
||||
|
||||
} else if (target->isAlignFixed) {
|
||||
if ((org - target->alignOfs) & target->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and address $%04" PRIx16,
|
||||
other->name, target->alignMask + 1,
|
||||
target->alignOfs, other->org);
|
||||
@@ -107,14 +106,14 @@ static void checkFragmentCompat(struct Section *target, struct Section *other)
|
||||
|
||||
if (target->isAddressFixed) {
|
||||
if ((target->org - ofs) & other->alignMask)
|
||||
errx(1, "Section \"%s\" is defined with conflicting address $%04"
|
||||
errx("Section \"%s\" is defined with conflicting address $%04"
|
||||
PRIx16 " and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->org,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
|
||||
} else if (target->isAlignFixed
|
||||
&& (other->alignMask & target->alignOfs) != (target->alignMask & ofs)) {
|
||||
errx(1, "Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
errx("Section \"%s\" is defined with conflicting %d-byte alignment (offset %"
|
||||
PRIu16 ") and %d-byte alignment (offset %" PRIu16 ")",
|
||||
other->name, target->alignMask + 1, target->alignOfs,
|
||||
other->alignMask + 1, other->alignOfs);
|
||||
@@ -132,7 +131,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
// Common checks
|
||||
|
||||
if (target->type != other->type)
|
||||
errx(1, "Section \"%s\" is defined with conflicting types %s and %s",
|
||||
errx("Section \"%s\" is defined with conflicting types %s and %s",
|
||||
other->name, typeNames[target->type], typeNames[other->type]);
|
||||
|
||||
if (other->isBankFixed) {
|
||||
@@ -140,7 +139,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
target->isBankFixed = true;
|
||||
target->bank = other->bank;
|
||||
} else if (target->bank != other->bank) {
|
||||
errx(1, "Section \"%s\" is defined with conflicting banks %" PRIu32 " and %"
|
||||
errx("Section \"%s\" is defined with conflicting banks %" PRIu32 " and %"
|
||||
PRIu32, other->name, target->bank, other->bank);
|
||||
}
|
||||
}
|
||||
@@ -161,7 +160,7 @@ static void mergeSections(struct Section *target, struct Section *other, enum Se
|
||||
target->data = realloc(target->data,
|
||||
sizeof(*target->data) * target->size + 1);
|
||||
if (!target->data)
|
||||
errx(1, "Failed to concatenate \"%s\"'s fragments", target->name);
|
||||
errx("Failed to concatenate \"%s\"'s fragments", target->name);
|
||||
memcpy(target->data + target->size - other->size, other->data, other->size);
|
||||
/* Adjust patches' PC offsets */
|
||||
for (uint32_t patchID = 0; patchID < other->nbPatches; patchID++)
|
||||
@@ -184,14 +183,14 @@ void sect_AddSection(struct Section *section)
|
||||
|
||||
if (other) {
|
||||
if (section->modifier != other->modifier)
|
||||
errx(1, "Section \"%s\" defined as %s and %s", section->name,
|
||||
errx("Section \"%s\" defined as %s and %s", section->name,
|
||||
sectionModNames[section->modifier], sectionModNames[other->modifier]);
|
||||
else if (section->modifier == SECTION_NORMAL)
|
||||
errx(1, "Section name \"%s\" is already in use", section->name);
|
||||
errx("Section name \"%s\" is already in use", section->name);
|
||||
else
|
||||
mergeSections(other, section, section->modifier);
|
||||
} else if (section->modifier == SECTION_UNION && sect_HasData(section->type)) {
|
||||
errx(1, "Section \"%s\" is of type %s, which cannot be unionized",
|
||||
errx("Section \"%s\" is of type %s, which cannot be unionized",
|
||||
section->name, typeNames[section->type]);
|
||||
} else {
|
||||
/* If not, add it */
|
||||
@@ -302,5 +301,5 @@ void sect_DoSanityChecks(void)
|
||||
{
|
||||
sect_ForEach(doSanityChecks, NULL);
|
||||
if (sanityChecksFailed)
|
||||
errx(1, "Sanity checks failed");
|
||||
errx("Sanity checks failed");
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "link/symbol.h"
|
||||
#include "link/main.h"
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "error.h"
|
||||
#include "hashmap.h"
|
||||
|
||||
HashMap symbols;
|
||||
|
||||
Reference in New Issue
Block a user