I've done a bunch of reading on dynamic linker relocations and position independent code including procedure linkage tables and global offset tables. I don't understand why a statically linked executable needs a PLT and GOT. I compiled a hello world program on my ubuntu x86_64 machine and when I dump the section headers with readelf -S
it shows PLT and GOT sections.
I also created a shared library with a simple increment function that I compiled with gcc -shared
without -fpic
and I also see PLT and GOT sections. I didn't expect this either.
I don't understand why a statically linked executable needs a PLT and GOT.
It doesn't.
I compiled a hello world program on my ubuntu x86_64 machine and when I dump the section headers with readelf -S it shows PLT and GOT sections.
This is an accident of implementation. The sections come from crt1.o
, and there isn't a separate crt1s.o
for fully-static linking, so you end up with .plt
and .got
entries from there.
You can strip these sections, and the binary will still work:
objcopy -R.got -R.plt a.out a.out2
Note: do not strip .rela.plt
, as that section is still needed to implement IFUNC
s.