Reputation: 27
I wanted to how this mapping done between source file and the object file
void main()
{
printf("Hello world !!\n");
}
With the object file:
Disassembly of section .text:
00000000 <main>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 e4 f0 and $0xfffffff0,%esp
6: 83 ec 10 sub $0x10,%esp
9: b8 00 00 00 00 mov $0x0,%eax
e: 89 04 24 mov %eax,(%esp)
11: e8 fc ff ff ff call 12 <main+0x12>
16: b8 00 00 00 00 mov $0x0,%eax
1b: c9 leave
1c: c3 ret
Upvotes: 0
Views: 404
Reputation: 28900
objdump -d ./a.out --source --line-numbers
Works like a charm !
000000000040052c <main>:
main():
/home/stdcall/temp/test.c:2
void main()
{
40052c: 55 push %rbp
40052d: 48 89 e5 mov %rsp,%rbp
/home/stdcall/temp/test.c:3
printf("Hello world !!\n");
400530: bf e4 05 40 00 mov $0x4005e4,%edi
400535: e8 d6 fe ff ff callq 400410 <puts@plt>
/home/stdcall/temp/test.c:4
}
40053a: 5d pop %rbp
40053b: c3 retq
40053c: 0f 1f 40 00 nopl 0x0(%rax)
Upvotes: 2
Reputation: 2568
try compile with gcc hello.c -g -o hello
options . then do ojbdump -S hello | less
Upvotes: 0