title: Builtins in Clang not so builtin?
body: <p>If I have the following in <code>strlen.c</code>:</p>
  
  <pre><code>int call_strlen(char *s) {
    return __builtin_strlen(s);
  }
  </code></pre>
  
  <p>And then compile it with both gcc and clang like this:</p>
  
  <pre><code>gcc -c -o strlen-gcc.o strlen.c
  
  clang -c -o strlen-clang.o strlen.c
  </code></pre>
  
  <p>I am surprised to see that strlen-clang.o contains a reference to "strlen", whereas gcc has expectedly inlined the function and has no such reference.  (see objdumps below).  Is this a bug in clang?  I have tested it in several versions of the clang compiler, including 3.8.</p>
  
  <p>Edit: the reason this is important for me is that I'm linking with <code>-nostdlib</code>, and the clang-compiled version gives me a link error that strlen is not found.</p>
  
  <p><strong>Clang</strong></p>
  
  <pre><code>@&gt; objdump -d strlen-clang.o 
  
  strlen-clang.o:     file format elf64-x86-64
  
  
  Disassembly of section .text:
  
  0000000000000000 &lt;call_strlen&gt;:
     0: 55                    push   %rbp
     1: 48 89 e5              mov    %rsp,%rbp
     4: 48 83 ec 10           sub    $0x10,%rsp
     8: 48 89 7d f8           mov    %rdi,-0x8(%rbp)
     c: 48 8b 7d f8           mov    -0x8(%rbp),%rdi
    10: e8 00 00 00 00        callq  15 &lt;call_strlen+0x15&gt;
    15: 89 c1                 mov    %eax,%ecx
    17: 89 c8                 mov    %ecx,%eax
    19: 48 83 c4 10           add    $0x10,%rsp
    1d: 5d                    pop    %rbp
    1e: c3                    retq   
  
  
  @&gt; objdump -t strlen-clang.o 
  
  strlen-clang.o:     file format elf64-x86-64
  
  SYMBOL TABLE:
  0000000000000000 l    df *ABS*  0000000000000000 strlen.c
  0000000000000000 l    d  .text  0000000000000000 .text
  0000000000000000 l    d  .data  0000000000000000 .data
  0000000000000000 l    d  .bss 0000000000000000 .bss
  0000000000000000 l    d  .comment 0000000000000000 .comment
  0000000000000000 l    d  .note.GNU-stack  0000000000000000 .note.GNU-stack
  0000000000000000 l    d  .eh_frame  0000000000000000 .eh_frame
  0000000000000000 g     F .text  000000000000001f call_strlen
  0000000000000000         *UND*  0000000000000000 strlen
  </code></pre>
  
  <p><strong>GCC</strong></p>
  
  <pre><code>@&gt; objdump -d strlen-gcc.o 
  
  strlen-gcc.o:     file format elf64-x86-64
  
  
  Disassembly of section .text:
  
  0000000000000000 &lt;call_strlen&gt;:
     0:   55                      push   %rbp
     1:   48 89 e5                mov    %rsp,%rbp
     4:   48 89 7d f8             mov    %rdi,-0x8(%rbp)
     8:   48 8b 45 f8             mov    -0x8(%rbp),%rax
     c:   48 c7 c1 ff ff ff ff    mov    $0xffffffffffffffff,%rcx
    13:   48 89 c2                mov    %rax,%rdx
    16:   b8 00 00 00 00          mov    $0x0,%eax
    1b:   48 89 d7                mov    %rdx,%rdi
    1e:   f2 ae                   repnz scas %es:(%rdi),%al
    20:   48 89 c8                mov    %rcx,%rax
    23:   48 f7 d0                not    %rax
    26:   48 83 e8 01             sub    $0x1,%rax
    2a:   5d                      pop    %rbp
    2b:   c3                      retq   
  
  @&gt; objdump -t strlen-gcc.o 
  
  strlen-gcc.o:     file format elf64-x86-64
  
  SYMBOL TABLE:
  0000000000000000 l    df *ABS*  0000000000000000 strlen.c
  0000000000000000 l    d  .text  0000000000000000 .text
  0000000000000000 l    d  .data  0000000000000000 .data
  0000000000000000 l    d  .bss 0000000000000000 .bss
  0000000000000000 l    d  .note.GNU-stack  0000000000000000 .note.GNU-stack
  0000000000000000 l    d  .eh_frame  0000000000000000 .eh_frame
  0000000000000000 l    d  .comment 0000000000000000 .comment
  0000000000000000 g     F .text  000000000000002c call_strlen
  </code></pre>