[prev in list] [next in list] [prev in thread] [next in thread]
List: cfe-dev
Subject: [cfe-dev] Fwd: How to prevent insertion of memcpy()
From: Dmitry Vyukov <dvyukov () google ! com>
Date: 2012-05-29 16:51:05
Message-ID: CACT4Y+Zem5VY3Ty0zW-BV1_-0uYYa+8=PF1tdVjxFZS9HUGnxg () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
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():
$ 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@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
[Attachment #5 (text/html)]
<div class="gmail_quote">Hi,<div><br></div><div>I have the following \
program:</div><div><br></div><div><font face="courier new, monospace">// \
test.c</font></div><div><div><font face="courier new, monospace">#include \
<stdlib.h></font></div> <div>
<font face="courier new, monospace">struct foo_t {</font></div><div><font \
face="courier new, monospace"> int x[1024];</font></div><div><font face="courier \
new, monospace">};</font></div><div><font face="courier new, monospace">__thread \
struct foo_t g_foo;</font></div>
<div><font face="courier new, monospace">void bar(struct foo_t* foo) \
{</font></div><div><font face="courier new, monospace"> g_foo = \
*foo;</font></div><div><font face="courier new, monospace">}</font></div><div><font \
face="courier new, monospace">int main() {</font></div>
<div><font face="courier new, monospace"> struct foo_t* f = (struct \
foo_t*)malloc(sizeof(struct foo_t));</font></div><div><font face="courier new, \
monospace"> bar(f);</font></div><div><font face="courier new, monospace"> return \
0;</font></div>
<div><font face="courier new, monospace">}</font></div></div><div><br></div><div>When \
I compile it with clang I see that it inserts memcpy() in function \
bar():</div><div><br></div><div><div>$ clang -v</div><div>clang version 3.2 (trunk \
157390)</div>
<div>Target: x86_64-unknown-linux-gnu</div><div>Thread model: posix</div><div>$ clang \
test.c -g && objdump -dCS a.out</div></div><div><br></div><div><div><font \
face="courier new, monospace">void bar(struct foo_t* foo) {</font></div>
<div><font face="courier new, monospace"> 4005b0: 55 push \
%rbp</font></div><div><font face="courier new, monospace"> 4005b1: 48 89 e5 \
mov %rsp,%rbp</font></div><div> <font face="courier new, monospace"> 4005b4: \
48 83 ec 10 sub $0x10,%rsp</font></div> <div><font face="courier new, \
monospace"> 4005b8: 48 89 7d f8 mov \
%rdi,-0x8(%rbp)</font></div><div><font face="courier new, monospace"> g_foo = \
*foo;</font></div><div><font face="courier new, monospace"> 4005bc: 48 8b 7d \
f8 mov -0x8(%rbp),%rdi</font></div>
<div><font face="courier new, monospace"> 4005c0: 64 48 8b 04 25 00 00 mov \
%fs:0x0,%rax</font></div><div><font face="courier new, monospace"> 4005c7: 00 \
00 </font></div><div><font face="courier new, monospace"> 4005c9: 48 8d 80 00 \
f0 ff ff lea -0x1000(%rax),%rax</font></div>
<div><font face="courier new, monospace"> 4005d0: ba 00 10 00 00 mov \
$0x1000,%edx</font></div><div><font face="courier new, monospace"> 4005d5: 48 \
89 7d f0 mov %rdi,-0x10(%rbp)</font></div>
<div><font face="courier new, monospace"> 4005d9: 48 89 c7 mov \
%rax,%rdi</font></div><div><font face="courier new, monospace"> 4005dc: 48 8b \
75 f0 mov -0x10(%rbp),%rsi</font></div>
<div><font face="courier new, monospace"> 4005e0: e8 c3 fe ff ff \
<b>callq 4004a8 <memcpy@plt></b></font></div><div><font face="courier new, \
monospace">}</font></div><div><font face="courier new, monospace"> 4005e5: 48 \
83 c4 10 add $0x10,%rsp</font></div>
<div><font face="courier new, monospace"> 4005e9: 5d pop \
%rbp</font></div><div><font face="courier new, monospace"> 4005ea: c3 \
retq </font></div><div><font face="courier new, monospace"> 4005eb: 0f 1f 44 \
00 00 nopl 0x0(%rax,%rax,1)</font></div>
</div><div><br></div><div>How do I disable that feature? I've tried -fno-builtin \
and/or -ffreestanding with no success.</div><div>TIA</div> </div><br>
_______________________________________________
cfe-dev mailing list
cfe-dev@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic