In an C program, I need to re-initialize all global variables as they where when the program starts for tests purpose.
I want to reproduce the data copy from Load Memory Address, LMA to VMA (run-time address) done by GCC libraries with a reinitialization function. For example, if foo variables are declared as global and initialized. And if my re-initialization function is re_init():
#include <stdio.h>
int foo1 = 42;
int foo2 = 777;
int main(){
foo1 = 0;
foo2 = 0;
re_init();
printf("foo1:%d and foo2:%d",foo1,foo2);
return 0;
}
then I want to have as an output :
foo1:42 and foo2:777
I believe that the right way to do this is to the default linker file and maybe the startup code that copy initiation values to RAM. So, with GCC (cygwin), what should I do to achieve this?
Edit: This page seems o have more precision on it : http://sources.redhat.com/binutils/docs-2.12/ld.info/Output-Section-LMA.html#Output%20Section%20LMA