, , . , file :
64- LSB ELF
, , , , . . , :
snoot.c
#include <stdio.h>
int square(int test) {
return test*test;
}
int func() {
n = 7;
printf("The answer is %d\n", square(n)-5);
}
gcc -shared -fpic snoot.c -o libsnoot.so
strip libsnoot.so
. objdump -T libsnoot.so, :
libsnoot.so: file format elf64-x86-64
DYNAMIC SYMBOL TABLE:
0000000000000580 l d .init 0000000000000000 .init
0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.2.5 printf
0000000000000000 w D *UND* 0000000000000000 __gmon_start__
0000000000000000 w D *UND* 0000000000000000 _Jv_RegisterClasses
0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable
0000000000000000 w DF *UND* 0000000000000000 GLIBC_2.2.5 __cxa_finalize
0000000000201028 g D .got.plt 0000000000000000 Base _edata
00000000000006e0 g DF .text 0000000000000010 Base square
0000000000201030 g D .bss 0000000000000000 Base _end
0000000000201028 g D .bss 0000000000000000 Base __bss_start
0000000000000580 g DF .init 0000000000000000 Base _init
0000000000000724 g DF .fini 0000000000000000 Base _fini
00000000000006f0 g DF .text 0000000000000032 Base func
.text , . , , ( , C), . , . , square :
testsnoot.c
extern void square(void);
int main() {
square();
}
, so , :
gcc testsnoot.c -o testsnoot -L. -lsnoot
, :
LD_LIBRARY_PATH = "" gdb./testsnoot
, LD_LIBRARY_PATH, , , .
(gdb) b square
Breakpoint 1 at 0x400560
(gdb) r
Starting program: /home/edward/test/testsnoot
Missing separate debuginfos, use: dnf debuginfo-install glibc-2.24-4.fc25.x86_64
Breakpoint 1, 0x00007ffff7bd56e4 in square () from ./libsnoot.so
(gdb) x/20i $pc
=> 0x7ffff7bd56e4 <square+4>: mov %edi,-0x4(%rbp)
0x7ffff7bd56e7 <square+7>: mov -0x4(%rbp),%eax
0x7ffff7bd56ea <square+10>: imul -0x4(%rbp),%eax
0x7ffff7bd56ee <square+14>: pop %rbp
0x7ffff7bd56ef <square+15>: retq
0x7ffff7bd56f0 <func>: push %rbp
0x7ffff7bd56f1 <func+1>: mov %rsp,%rbp
0x7ffff7bd56f4 <func+4>: sub $0x10,%rsp
0x7ffff7bd56f8 <func+8>: movl $0x7,-0x4(%rbp)
0x7ffff7bd56ff <func+15>: mov -0x4(%rbp),%eax
0x7ffff7bd5702 <func+18>: mov %eax,%edi
0x7ffff7bd5704 <func+20>: callq 0x7ffff7bd55b0 <square@plt>
0x7ffff7bd5709 <func+25>: sub $0x5,%eax
0x7ffff7bd570c <func+28>: mov %eax,%esi
0x7ffff7bd570e <func+30>: lea 0x18(%rip),%rdi # 0x7ffff7bd572d
0x7ffff7bd5715 <func+37>: mov $0x0,%eax
0x7ffff7bd571a <func+42>: callq 0x7ffff7bd55c0 <printf@plt>
0x7ffff7bd571f <func+47>: nop
0x7ffff7bd5720 <func+48>: leaveq
0x7ffff7bd5721 <func+49>: retq
, . , , -0x4(%rbp), , , , .
, , .
, , , .