From time to time, when disassembling x86 binaries, I stumble on
reference to PLT
and GOT
, especially when calling procedures from a
dynamic library.
For example, when running a program in gdb
:
(gdb) info file
Symbols from "/home/user/hello".
Local exec file: `/home/user/hello', file type elf64-x86-64.
Entry point: 0x400400
0x0000000000400200 - 0x000000000040021c is .interp
0x000000000040021c - 0x000000000040023c is .note.ABI-tag
0x000000000040023c - 0x0000000000400260 is .note.gnu.build-id
0x0000000000400260 - 0x0000000000400284 is .hash
0x0000000000400288 - 0x00000000004002a4 is .gnu.hash
0x00000000004002a8 - 0x0000000000400308 is .dynsym
0x0000000000400308 - 0x0000000000400345 is .dynstr
0x0000000000400346 - 0x000000000040034e is .gnu.version
0x0000000000400350 - 0x0000000000400370 is .gnu.version_r
0x0000000000400370 - 0x0000000000400388 is .rela.dyn
0x0000000000400388 - 0x00000000004003b8 is .rela.plt
0x00000000004003b8 - 0x00000000004003c6 is .init
=> 0x00000000004003d0 - 0x0000000000400400 is .plt
0x0000000000400400 - 0x00000000004005dc is .text
0x00000000004005dc - 0x00000000004005e5 is .fini
0x00000000004005e8 - 0x00000000004005fa is .rodata
0x00000000004005fc - 0x0000000000400630 is .eh_frame_hdr
0x0000000000400630 - 0x00000000004006f4 is .eh_frame
0x00000000006006f8 - 0x0000000000600700 is .init_array
0x0000000000600700 - 0x0000000000600708 is .fini_array
0x0000000000600708 - 0x0000000000600710 is .jcr
0x0000000000600710 - 0x00000000006008f0 is .dynamic
=> 0x00000000006008f0 - 0x00000000006008f8 is .got
=> 0x00000000006008f8 - 0x0000000000600920 is .got.plt
0x0000000000600920 - 0x0000000000600930 is .data
0x0000000000600930 - 0x0000000000600938 is .bss
And, then when disassembling (puts@plt
):
(gdb) disas foo
Dump of assembler code for function foo:
0x000000000040050c <+0>: push %rbp
0x000000000040050d <+1>: mov %rsp,%rbp
0x0000000000400510 <+4>: sub $0x10,%rsp
0x0000000000400514 <+8>: mov %edi,-0x4(%rbp)
0x0000000000400517 <+11>: mov $0x4005ec,%edi
=> 0x000000000040051c <+16>: callq 0x4003e0 <puts@plt>
0x0000000000400521 <+21>: leaveq
0x0000000000400522 <+22>: retq
End of assembler dump.
So, what are these GOT/PLT ?