Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the first case, take a look at the instruction encoding - it's all zeroes where the function address would go. That's because the object hasn't been linked yet, so the addresses for external symbols haven't been hooked up yet. When you do the final link into the executable format, the system sticks another placeholder in there, and then the dynamic linker will finally add the correct address for <code>printf()</code> at runtime. Here's a quick example for a "Hello, world" program I wrote.</p> <p>First, the disassembly of the object file:</p> <pre><code>00000000 &lt;_main&gt;: 0: 8d 4c 24 04 lea 0x4(%esp),%ecx 4: 83 e4 f0 and $0xfffffff0,%esp 7: ff 71 fc pushl -0x4(%ecx) a: 55 push %ebp b: 89 e5 mov %esp,%ebp d: 51 push %ecx e: 83 ec 04 sub $0x4,%esp 11: e8 00 00 00 00 call 16 &lt;_main+0x16&gt; 16: c7 04 24 00 00 00 00 movl $0x0,(%esp) 1d: e8 00 00 00 00 call 22 &lt;_main+0x22&gt; 22: b8 00 00 00 00 mov $0x0,%eax 27: 83 c4 04 add $0x4,%esp 2a: 59 pop %ecx 2b: 5d pop %ebp 2c: 8d 61 fc lea -0x4(%ecx),%esp 2f: c3 ret </code></pre> <p>Then the relocations:</p> <pre><code>main.o: file format pe-i386 RELOCATION RECORDS FOR [.text]: OFFSET TYPE VALUE 00000012 DISP32 ___main 00000019 dir32 .rdata 0000001e DISP32 _puts </code></pre> <p>As you can see there's a relocation there for <code>_puts</code>, which is what the call to <code>printf</code> turned into. That relocation will get noticed at link time and fixed up. In the case of dynamic library linking, the relocations and fixups might not get fully resolved until the program is running, but you'll get the idea from this example, I hope.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload