I'm digging in dynamic relocation process and i created a very simple shared object:
int func_1(int v)
{
v + 10;
}
int func_2()
{
return func_1(10);
}
compiled as:
gcc -fPIC -c libtest.c
gcc -shared -nostdlib -o libtest.so libtest.o
If we look at dynamic relocations for the shared object:
$ objdump -R libtest.so
libtest.so: file format elf32-i386
DYNAMIC RELOCATION RECORDS
OFFSET TYPE VALUE
00002000 R_386_JUMP_SLOT func_1
there is a R_386_JUMP_SLOT for the symbol func_1
so the call in the func_2
is resolved by PLT. I can't figure out the reason for this...If func_1
is declared as private (static
) the relocation disappears and the call is resolved (by static linker) with a relative branch. Why passing from PLT is better than a relative jump?