I am using linker generated copy tables to overlay code sections in program memory. Some code input sections are needed in more than one program memory overlay for an application. Since each input section can only be allocated once, the table() operator is applied to each output code section, allocated as a UNION member, to generate copy tables. Combinations of these tables are then copied into program memory at run time to form the application overlay. The output section within the copy table is offset from the overlay run address by predefined holes to allow the tables to be copied over each other without overwriting the program section in the previously loaded copy table (only fill is overwritten).
Presently, the size of the offset (hole) in each table has a hard coded value in the linker file. An example linker file and portion of the application code showing the order in which tables are copied are shown below.
============== Linker example ============== sizeOfApp1 = 1cf0h; /* Should not use these hardcoded values. */ sizeOfApp2 = 0110h; /* Should not use these hardcoded values. */ SECTIONS { UNION: { App1Objects: align(4) /* 1st Application */ { Text11.obj(.text) ... Text1N.obj(.text) } load=FLASH, table(_App1_copy_table) App2Objects: align(4), fill = 0000h /* 2nd Application */ { . += sizeOfApp1; /* Offset for this table */ Text21.obj(.text) /* Linked in after the hole */ ... Text2N.obj(.text) } load=FLASH, table(_App2_copy_table) App3Objects: align(4), fill = 0000h /* 3rd Application */ { . += sizeOfApp1; /* Offset for this table */ . += sizeOfApp2; /* Offset for this table */ Text31.obj(.text) /* Linked in after the hole */ ... Text3N.obj(.text) } load=FLASH, table(_App3_copy_table) } run=SARAM /* Run Address in SARAM (Overlayed) */ ============ Code example ============ if (externalTables) { copy_in( &App3_copy_table); /* copy in the high memory section in ovly first */ copy_in(&App2_copy_table); /* copy in the lower memory sections in the overlay */ copy_in(&App1_copy_table); }
The offset symbols would require less maintenance as the input sections grow if they were instead set by the linker using either the SIZE operator for each output section(UNION member) and the "." symbol to create a hole for the offset in the SECTIONS directive.
Attempts to use these options caused the linker to generate either a warning that the symbol is being redefined (and not assigned a new value) or an error that the symbol is used before it is assigned a value.
First, is there another or better way to allocate an input section to be used in more than one program memory overlay ?
Second, can the symbols (sizeOfApp1 and sizeOfApp2 shown above) be assigned a value in the linker file using either the SIZE operator or the "." symbol and be used to create a hole within the output sections of the UNION in the SECTIONS directive?