mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Process linker script before doing sanity checks
This commit is contained in:
@@ -17,7 +17,6 @@
|
||||
#include "link/symbol.h"
|
||||
#include "link/object.h"
|
||||
#include "link/main.h"
|
||||
#include "link/script.h"
|
||||
#include "link/output.h"
|
||||
|
||||
#include "error.h"
|
||||
@@ -63,45 +62,6 @@ static void initFreeSpace(void)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alter sections' attributes based on the linker script
|
||||
*/
|
||||
static void processLinkerScript(void)
|
||||
{
|
||||
if (!linkerScriptName)
|
||||
return;
|
||||
verbosePrint("Reading linker script...\n");
|
||||
|
||||
linkerScript = openFile(linkerScriptName, "r");
|
||||
|
||||
/* Modify all sections according to the linker script */
|
||||
struct SectionPlacement *placement;
|
||||
|
||||
while ((placement = script_NextSection())) {
|
||||
struct Section *section = placement->section;
|
||||
|
||||
/* Check if this doesn't conflict with what the code says */
|
||||
if (section->isBankFixed && placement->bank != section->bank)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s bank placement",
|
||||
section->name);
|
||||
if (section->isAddressFixed && placement->org != section->org)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s address placement",
|
||||
section->name);
|
||||
if (section->isAlignFixed
|
||||
&& (placement->org & section->alignMask) != 0)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s alignment",
|
||||
section->name);
|
||||
|
||||
section->isAddressFixed = true;
|
||||
section->org = placement->org;
|
||||
section->isBankFixed = true;
|
||||
section->bank = placement->bank;
|
||||
section->isAlignFixed = false; /* The alignment is satisfied */
|
||||
}
|
||||
|
||||
fclose(linkerScript);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a section to a given memory location
|
||||
* @param section The section to assign
|
||||
@@ -423,9 +383,6 @@ void assign_AssignSections(void)
|
||||
|
||||
initFreeSpace();
|
||||
|
||||
/* Process linker script, if any */
|
||||
processLinkerScript();
|
||||
|
||||
nbSectionsToAssign = 0;
|
||||
sect_ForEach(categorizeSection, NULL);
|
||||
|
||||
@@ -505,6 +462,4 @@ void assign_Cleanup(void)
|
||||
}
|
||||
|
||||
free(sections);
|
||||
|
||||
script_Cleanup();
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "link/object.h"
|
||||
#include "link/symbol.h"
|
||||
#include "link/section.h"
|
||||
#include "link/assign.h"
|
||||
#include "link/patch.h"
|
||||
#include "link/object.h"
|
||||
#include "link/output.h"
|
||||
#include "link/patch.h"
|
||||
#include "link/section.h"
|
||||
#include "link/script.h"
|
||||
#include "link/symbol.h"
|
||||
|
||||
#include "extern/getopt.h"
|
||||
|
||||
@@ -444,6 +445,43 @@ int main(int argc, char *argv[])
|
||||
for (obj_Setup(argc - curArgIndex); curArgIndex < argc; curArgIndex++)
|
||||
obj_ReadFile(argv[curArgIndex], argc - curArgIndex - 1);
|
||||
|
||||
/* apply the linker script's modifications, */
|
||||
if (linkerScriptName) {
|
||||
verbosePrint("Reading linker script...\n");
|
||||
|
||||
linkerScript = openFile(linkerScriptName, "r");
|
||||
|
||||
/* Modify all sections according to the linker script */
|
||||
struct SectionPlacement *placement;
|
||||
|
||||
while ((placement = script_NextSection())) {
|
||||
struct Section *section = placement->section;
|
||||
|
||||
/* Check if this doesn't conflict with what the code says */
|
||||
if (section->isBankFixed && placement->bank != section->bank)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s bank placement",
|
||||
section->name);
|
||||
if (section->isAddressFixed && placement->org != section->org)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s address placement",
|
||||
section->name);
|
||||
if (section->isAlignFixed
|
||||
&& (placement->org & section->alignMask) != 0)
|
||||
error(NULL, 0, "Linker script contradicts \"%s\"'s alignment",
|
||||
section->name);
|
||||
|
||||
section->isAddressFixed = true;
|
||||
section->org = placement->org;
|
||||
section->isBankFixed = true;
|
||||
section->bank = placement->bank;
|
||||
section->isAlignFixed = false; /* The alignment is satisfied */
|
||||
}
|
||||
|
||||
fclose(linkerScript);
|
||||
|
||||
script_Cleanup();
|
||||
}
|
||||
|
||||
|
||||
/* then process them, */
|
||||
obj_DoSanityChecks();
|
||||
assign_AssignSections();
|
||||
|
||||
Reference in New Issue
Block a user