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.
It doesn't.
This is an accident of implementation. The sections come from
crt1.o
, and there isn't a separatecrt1s.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:
Note: do not strip
.rela.plt
, as that section is still needed to implementIFUNC
s.