On Fri, Sep 22, 2017 at 12:29 PM, Wilco Dijkstra <wilco.dijks...@arm.com> wrote: > Hi, > > You'll get GOT relocations to globals when you use -fpic: > > int x; > int f(void) { return x; } >>gcc -O2 -S -o- -fpic > > f: > adrp x0, :got:x > ldr x0, [x0, #:got_lo12:x] > ldr w0, [x0] > ret > > So it doesn't depend on the compiler but what options you compile for. > There may be an issue with your setup, -fpic shouldn't be on by default.
There's -fpic and there's -fpie. In this case it's more likely to be pie which is about position independent executables. Distros and other downstream packagers default to -fpie these days for security and hardening reasons as it allows them to by default generate code that is position independent and allows things like ASLR to actually take effect. To answer the question when are relocations through the GOT used, the answer is whenever folks want to have position independence either in their libraries or in their executables. regards Ramana