Hello, I have written a simple Hello World program.

  #include <stdio.h>
    int main() {
    printf("Hello World");
    return 0;
    }

I wanted to understand how the relocatable object file and executable file look like. The object file corresponding to the main function is

0000000000000000 <main>:
   0:   55                      push   %rbp
   1:   48 89 e5                mov    %rsp,%rbp
   4:   bf 00 00 00 00          mov    $0x0,%edi
   9:   b8 00 00 00 00          mov    $0x0,%eax
   e:   e8 00 00 00 00          callq  13 <main+0x13>
  13:   b8 00 00 00 00          mov    $0x0,%eax
  18:   c9                      leaveq 
  19:   c3                      retq

Here the function call for printf is callq 13. One thing i don't understand is why is it 13. That means call the function at adresss 13, right??. 13 has the next instruction, right?? Please explain me what does this mean??

The executable code corresponding to main is

00000000004004cc <main>:
  4004cc:       55                      push   %rbp
  4004cd:       48 89 e5                mov    %rsp,%rbp
  4004d0:       bf dc 05 40 00          mov    $0x4005dc,%edi
  4004d5:       b8 00 00 00 00          mov    $0x0,%eax
  4004da:       e8 e1 fe ff ff          callq  4003c0 <printf@plt>
  4004df:       b8 00 00 00 00          mov    $0x0,%eax
  4004e4:       c9                      leaveq 
  4004e5:       c3                      retq 

Here it is callq 4003c0. But the binary instruction is e8 e1 fe ff ff. There is nothing that corresponds to 4003c0. What is that i am getting wrong?

Thanks. Bala

asked 06 May '10, 22:15

bala1486's gravatar image

bala1486
3324
accept rate: 0%

edited 09 May '10, 20:21

Jazz's gravatar image

Jazz ♦
7811312




Take a look at this line:

e:   e8 00 00 00 00          callq  13 <main+0x13>

You see a calculation of the address of main, plus the hex value 0x13, an offset.

00000000004004cc <main>:
    4004da:       e8 e1 fe ff ff          callq  4003c0 <printf@plt>
    4004df:       b8 00 00 00 00          mov    $0x0,%eax

If you take your main-address of the second code example (4004cc) and add the offset (0x13), you get 4004df, which corresponds to the same instruction as the one in your first example.

link

answered 09 May '10, 20:20

Jazz's gravatar image

Jazz ♦
7811312
accept rate: 33%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1
×1
×1
×1

Asked: 06 May '10, 22:15

Seen: 901 times

Last updated: 09 May '10, 20:21

Related questions

powered by OSQA