On Mon, Jan 6, 2020 at 2:20 AM Segher Boessenkool <segher@xxxxxxxxxxxxxxxxxxx> wrote: > > On Sun, Jan 05, 2020 at 11:57:26PM -0500, William Tambe wrote: > > Is there a way to make GCC generate instructions within the crti.S > > _init function to initialize a global variable, instead of generating > > .long or .quad assembly statement ? > > The idea being to make GCC generate instructions to initialize a > > global variable, just like it generates instructions to initialize a > > local variable. > > Have a look at attribute((constructor))? I have used the attribute((constructor)) before, but this is not what I am looking for. I would like for GCC to automatically generate instructions to initialize global variables without having to manually create a function with attribute((constructor)) to initialize those global variables. In the example below from my previous email, GCC should automatically generate instructions to initialize myglobal just like it generates instructions to initialize mylocal; except those instructions to initialize myglobal are to be generated within the crti.S _init function: void myfunc (void) {} void *myglobal = myfunc; void main (void) { void *mylocal = myfunc; } > > > Segher