title: Using GCC's builtin functions in arm
body: <p>I'm working on a cortex-m3 board with a bare-metal toolchain without libc.</p>
  
  <p>I implemented memcpy which copies data byte-to-byte but it's too slow. In GCC manual, it says it provides __builtin_memcpy and I decided to use it. So here is the implementation with __builtin_memcpy.</p>
  
  <pre><code>#include &lt;stddef.h&gt;
  
  void *memcpy(void *dest, const void *src, size_t n)
  {
      return __builtin_memcpy(dest,src,n);
  }
  </code></pre>
  
  <p>When I compile this code, it becomes a recursive function which never ends.</p>
  
  <pre><code>$ arm-none-eabi-gcc -march=armv7-m -mcpu=cortex-m3 -mtune=cortex-m3 \
    -O2 -ffreestanding -c memcpy.c -o memcpy.o
  $ arm-none-eabi-objdump -d memcpy.o
  
  memcpy.o:     file format elf32-littlearm
  
  
  Disassembly of section .text:
  
  00000000 &lt;memcpy&gt;:
     0:   f7ff bffe       b.w     0 &lt;memcpy&gt;
  </code></pre>
  
  <p>Am I doing wrong? How can I use the compiler-generated memcpy version?</p>