[cfe-dev] How to prevent insertion of memcpy()
Chris Lattner
clattner at apple.com
Tue May 29 21:30:14 PDT 2012
On May 29, 2012, at 9:51 AM, Dmitry Vyukov wrote:
> Hi,
>
> I have the following program:
>
> // test.c
> #include <stdlib.h>
> struct foo_t {
> int x[1024];
> };
> __thread struct foo_t g_foo;
> void bar(struct foo_t* foo) {
> g_foo = *foo;
> }
> int main() {
> struct foo_t* f = (struct foo_t*)malloc(sizeof(struct foo_t));
> bar(f);
> return 0;
> }
>
> When I compile it with clang I see that it inserts memcpy() in function bar():
Hi Dmitry,
Short answer: you can't. Freestanding implementations are required to provide memcpy.
-Chris
>
> $ clang -v
> clang version 3.2 (trunk 157390)
> Target: x86_64-unknown-linux-gnu
> Thread model: posix
> $ clang test.c -g && objdump -dCS a.out
>
> void bar(struct foo_t* foo) {
> 4005b0: 55 push %rbp
> 4005b1: 48 89 e5 mov %rsp,%rbp
> 4005b4: 48 83 ec 10 sub $0x10,%rsp
> 4005b8: 48 89 7d f8 mov %rdi,-0x8(%rbp)
> g_foo = *foo;
> 4005bc: 48 8b 7d f8 mov -0x8(%rbp),%rdi
> 4005c0: 64 48 8b 04 25 00 00 mov %fs:0x0,%rax
> 4005c7: 00 00
> 4005c9: 48 8d 80 00 f0 ff ff lea -0x1000(%rax),%rax
> 4005d0: ba 00 10 00 00 mov $0x1000,%edx
> 4005d5: 48 89 7d f0 mov %rdi,-0x10(%rbp)
> 4005d9: 48 89 c7 mov %rax,%rdi
> 4005dc: 48 8b 75 f0 mov -0x10(%rbp),%rsi
> 4005e0: e8 c3 fe ff ff callq 4004a8 <memcpy at plt>
> }
> 4005e5: 48 83 c4 10 add $0x10,%rsp
> 4005e9: 5d pop %rbp
> 4005ea: c3 retq
> 4005eb: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
>
> How do I disable that feature? I've tried -fno-builtin and/or -ffreestanding with no success.
> TIA
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120529/a6949765/attachment.html>
More information about the cfe-dev
mailing list