I am trying to see everything in big picture regarding compilation and linking.
I have below simple function implemented in add_caller.c
:
extern int add(int a, int b);
int
main(int argc, char **argv){
int a = 45;
int b = 43;
int c = add(45,43);
return 0;
}
Function add
is defined in other C file.
Now I compile and create object file add_caller.o
file using cmd :
gcc -g -c add_caller.c -o add_caller.o
Now i disassemble the add_caller.o file. I want to see how disassembly code put a reference to external add
function prior linking.
vmx@vmx:~/Documents/NASMAssembly$ objdump -S --disassemble add_caller.o
add_caller.o: file format elf32-i386
Disassembly of section .text:
00000000 <main>:
extern int add(int a, int b);
int
main(int argc, char **argv){
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 20 sub $0x20,%esp
int a = 45;
9: c7 44 24 14 2d 00 00 movl $0x2d,0x14(%esp)
10: 00
int b = 43;
11: c7 44 24 18 2b 00 00 movl $0x2b,0x18(%esp)
18: 00
int c = add(45,43);
19: c7 44 24 04 2b 00 00 movl $0x2b,0x4(%esp)
20: 00
21: c7 04 24 2d 00 00 00 movl $0x2d,(%esp)
28: e8 fc ff ff ff call 29 <main+0x29>
2d: 89 44 24 1c mov %eax,0x1c(%esp)
return 0;
31: b8 00 00 00 00 mov $0x0,%eax
}
36: c9 leave
37: c3 ret
Here in disassemble code above, I understand it fully except I was expecting some info which relates to add
function in line(= address) no 28. I am sure it relates to it somehow, but can someone explain how info in line 28 maps to call to function 'add'. What does 29 <main+0x29>
mean in line
`28: e8 fc ff ff ff call 29 <main+0x29>`