On Tue, Jan 07, 2020 at 04:04:33PM -0500, William Tambe wrote: > On Tue, Jan 7, 2020 at 3:32 PM J Decker <d3ck0r@xxxxxxxxx> wrote: > > > > I do think having a the reason why you would want to do this instead of 'how can I do this' might help... (something of an X-Y problem) > > I agree; I have added the reason to my previous email: > Such that in the above example the address of myfunc that is used to > initialize myglobal get computed at run-time instead of at compile > time. > The question is what actual problem are you facing with the way it's done now. Do you have some special environment you need to run in where the normal support code to make this work doesn't exist? In a normal system, even though the assembler output for your file looks like myglobal is being initialized at compile time, it actually gets initialized at run-time, by the dynamic linker (ld-linux.so) that's part of glibc (or whatever libc you use). Only the offset from the base address of the program is calculated and initialized at compile (or really link) time. That's assuming you're generating a PIE executable. If you aren't, it will be initialized by the static linker at link time, and there's no apparent reason why you would want to postpone it to run-time since the address can't change.