Search code examples
gcccompiler-constructionmemcpylibc

Getting GCC to compile without inserting call to memcpy


I'm currently using GCC 4.5.3, compiled for PowerPC 440, and am compiling some code that doesn't require libc. I don't have any direct calls to memcpy(), but the compiler seems to be inserting one during the build.

There are linker options like -nostdlib, -nostartfiles, -nodefaultlibs but I'm unable to use them as I'm not doing the linking phase. I'm only compiling. With something like this:

$ powerpc-440-eabi-gcc -O2 -g -c -o output.o input.c

If I check the output.o with nm, I see a reference to memcpy:

$ powerpc-440-eabi-nm output.o | grep memcpy
     U memcpy
$ 

The GCC man page makes it clear how to remove calls to memcpy and other libc calls with the linker, but I don't want the compiler to insert them in the first place, as I'm using a completely different linker (not GNU's ld, and it doesn't know about libc).

Thanks for any help you can provide.


Solution

  • You need to disable a that optimization with -fno-builtin. I had this problem once when trying to compile memcpy for a C library. It called itself. Oops!