Well, I ended up taking a whole different approach but i wanted to share my final conclusion here:
I base this on How to fetch the end address of my code
In the code, you must add an extern reference to the variable:
extern char var2[];
A linker script must be written as follows:
SECTIONS
{
.mysection : {
*(.mysection);
var2 = .;
}
}
INSERT AFTER .mysection
Add the linker script during the linkage (e.g ld -T <PATH_TO_MY_LINKER_SCRIPT>
)
The INSERT AFTER
part is used so my linker script would be added to the default linker script.
I had to use 'gold' to link my elf file and apparently the version I used doesn't support the 'INSERT AFTER' syntax. So the actual solution should be to copy the default linker script and just add my script information to it.
I haven't tested it though, but I still hope it can help someone.