diff --git a/src/link/assign.c b/src/link/assign.c index 5f25d3fd..0824ca42 100644 --- a/src/link/assign.c +++ b/src/link/assign.c @@ -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(); } diff --git a/src/link/main.c b/src/link/main.c index 990b2a48..0b8a8ddf 100644 --- a/src/link/main.c +++ b/src/link/main.c @@ -18,12 +18,13 @@ #include #include -#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();