why LEA and not just MOV... https://stackoverflow.com/a/46839620 Although, the MOV could be a constant fixup; I wonder if that breaks in cases where RIP isn't always the same for every execution of some routine... on different threads(or something) does the base of code address change so RIP is different? Uhmm I think something like ? struct { void (*a)(void); void (*b)(void ); } table = { myfunc, myfunc2 } table.a(); or void (*table)(void)[] = { myfunc, ... }; //? that is probably wrong syntax table[0](); don't those generate one-time fixups to constants set once to the current code_segment + function_offset ? and having only a few of those fixups instead of every place a function pointer is used reduces load time? (as opposed to LEA RIP(func),... , using MOV func_addr_fixup),... ) On Mon, Jan 6, 2020 at 5:35 PM William Tambe <tambewilliam@xxxxxxxxx> wrote: > On Mon, Jan 6, 2020 at 11:52 AM Florian Weimer <fw@xxxxxxxxxxxxx> wrote: > > > > * William Tambe: > > > > > 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; > > > } > > > > I believe this would be best implemented in the link editor. It sees > > the relocations and can generate the appropriate code. However, for > > Assembly generated to initialize myglobal is as follow: > > .globl myglobal > .section .data.rel.local,"aw",@progbits > .align 8 > .type myglobal, @object > .size myglobal, 8 > myglobal: > .quad myfunc > > Is it actually possible to create a link editor script that convert > the above assembly into instructions in the function _init ? > > > position-indepedent code, usually a table-based approach with a > > minimal loader is typically used. > > Could I have a pointer into the source code showing how it is implemented ? >