Answers to: Doubts in executable and relocatable object filehttp://linuxexchange.org/questions/352/doubts-in-executable-and-relocatable-object-file<p>Hello, I have written a simple Hello World program.</p> <pre><code> #include &lt;stdio.h&gt; int main() { printf("Hello World"); return 0; } </code></pre> <p>I wanted to understand how the relocatable object file and executable file look like. The object file corresponding to the main function is</p> <pre><code>0000000000000000 &lt;main&gt;: 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 &lt;main+0x13&gt; 13: b8 00 00 00 00 mov $0x0,%eax 18: c9 leaveq 19: c3 retq </code></pre> <p>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??</p> <p>The executable code corresponding to main is</p> <pre><code>00000000004004cc &lt;main&gt;: 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 &lt;printf@plt&gt; 4004df: b8 00 00 00 00 mov $0x0,%eax 4004e4: c9 leaveq 4004e5: c3 retq </code></pre> <p>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?</p> <p>Thanks. Bala</p>enSun, 09 May 2010 20:20:55 -0400Answer by Jazzhttp://linuxexchange.org/questions/352/doubts-in-executable-and-relocatable-object-file/412<p>Take a look at this line:</p> <pre><code>e: e8 00 00 00 00 callq 13 &lt;main+0x13&gt; </code></pre> <p>You see a calculation of the address of main, plus the hex value 0x13, an offset.</p> <pre><code>00000000004004cc &lt;main&gt;: 4004da: e8 e1 fe ff ff callq 4003c0 &lt;printf@plt&gt; 4004df: b8 00 00 00 00 mov $0x0,%eax </code></pre> <p>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.</p>JazzSun, 09 May 2010 20:20:55 -0400http://linuxexchange.org/questions/352/doubts-in-executable-and-relocatable-object-file/412