title: Why doesn't gcc reference the PLT for function calls?
body: <p>I'm trying to learn assembly by compiling simple functions and looking at the output.</p>
  
  <p>I'm looking at calling functions in other libraries. Here's a toy C function that calls a function defined elsewhere:</p>
  
  <pre><code>void give_me_a_ptr(void*);
  
  void foo() {
      give_me_a_ptr("foo");
  }
  </code></pre>
  
  <p>Here's the assembly produced by gcc:</p>
  
  <pre><code>$ gcc -Wall -Wextra -g -O0 -c call_func.c
  $ objdump -d call_func.o 
  
  call_func.o:     file format elf64-x86-64
  
  Disassembly of section .text:
  
  0000000000000000 &lt;foo&gt;:
     0:   55                      push   %rbp
     1:   48 89 e5                mov    %rsp,%rbp
     4:   bf 00 00 00 00          mov    $0x0,%edi
     9:   e8 00 00 00 00          callq  e &lt;foo+0xe&gt;
     e:   90                      nop
     f:   5d                      pop    %rbp
    10:   c3                      retq   
  </code></pre>
  
  <p>I was expecting something like <code>call &lt;give_me_a_ptr@plt&gt;</code>. Why is this jumping to a relative position before it even knows where <code>give_me_a_ptr</code> is defined?</p>
  
  <p>I'm also puzzled by <code>mov $0, %edi</code>. This looks like it's passing a null pointer -- surely <code>mov $address_of_string, %rdi</code> would be correct here?</p>