[LLVMdev] Multiple Definition error with LTO
Daniel Stewart
stewartd at codeaurora.org
Wed Jun 4 11:58:15 PDT 2014
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 also have a simple main.c to test it out (also simplified):
#include <stdio.h>
#include <string.h>
struct {
char name[40];
} person;
char myname[] = "abcd";
int main ()
{
memcpy ( person.name, myname, strlen(myname)+1 );
printf ("name :%s\n", person.name );
return 0;
}
---
During compilation with:
clang -O0 memcpy.c -o memcpy.o -c
ar cr memcpy.a memcpy.o
clang -O0 -o memcpyTest.exe -flto -static main.c memcpy.a
I get a multiple definition of memcpy error. Now building it with
-fno-builtin works fine. I'm trying to understand what is happening behind
the scenes that requires my use of -fno-builtin (or
-Wl,--allow-multiple-definitions). Did the backend put in references to libc
that are trying to get resolved before loading the optimized archive? I also
notice that replacing memcpy.a with memcpy.o works just fine as well. Can
someone give me some insight?
I've found this discussion
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55994> regarding GCC that
seems to center around the same issue.
Daniel
--
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by
The Linux Foundation
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140604/0756c863/attachment.html>
More information about the llvm-dev
mailing list