Multiple Definition error with LTO

I’m trying to understand why using a local memcpy with LTO results in a “multiple definition” error.

I have an local (optimized) mempy.c (clearly simplified!):

void* memcpy(void* dest, const void* src, unsigned int count) {

return 0;


void* __aeabi_memcpy(void *dest, const void *src, unsigned int size) {

return memcpy(dest,src,size);


I cannot reproduce it on x86_64-pc-linux. What I would suggest:

Run clang with -v to get the linker invocation. Copy and past that but
add -t, the linker should print the member it is fetching. It should
show you if it is fetching a member defining memcpy from libc.a.

Thanks for the reply Rafael. I've ran it with both -t and -Wl,-debug=all to see what the linker is grabbing.

Without -fno-builtin, it grabs libc first.

With -fno-builtin, it loads in my archive first.

What I don't know is how it is making that decision. I will see if I can reproduce on x86_64.