title: What is the reason function names are prefixed with an underscore by the compiler?
body: <p>When I see the assembly code of a C app, like this:</p>
  
  <pre><code>emacs hello.c
  clang -S -O hello.c -o hello.s
  cat hello.s
  </code></pre>
  
  <p>Function names are prefixed with an underscore (e.g. <code>callq _printf</code>). Why is this done and what advantages does it have?</p>
  
  <hr>
  
  <p>Example:</p>
  
  <p><strong>hello.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  
  int main() {
    char *myString = malloc(strlen("Hello, World!") + 1);
    memcpy(myString, "Hello, World!", strlen("Hello, World!") + 1);
    printf("%s", myString);
    return 0;
  }
  </code></pre>
  
  <p><strong>hello.s</strong></p>
  
  <pre><code>_main:                       ; Here
  Leh_func_begin0:
      pushq   %rbp
  Ltmp0:
      movq    %rsp, %rbp
  Ltmp1:
      movl    $14, %edi
      callq   _malloc          ; Here
      movabsq $6278066737626506568, %rcx
      movq    %rcx, (%rax)
      movw    $33, 12(%rax)
      movl    $1684828783, 8(%rax)
      leaq    L_.str1(%rip), %rdi
      movq    %rax, %rsi
      xorb    %al, %al
      callq   _printf          ; Here
      xorl    %eax, %eax
      popq    %rbp
      ret
  Leh_func_end0:
  </code></pre>