[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#136659: gcc: optimisation on sparc leads to unalligned access in memcpy



Package: gcc
Version: 1:2.95.2-13
Severity: normal

To add to my problem (reported on debian devel) here is a test program to
reproduce it:

Output with o=2 (unaligned)

ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=2
Now we are going to memcpy dst=a+x+o=0xeffffc7e
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc7e
Bus error

Output with o=4 (aligned)

ecki@auric:~$ gcc -O2 -o bla bla.c
ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=4
Now we are going to memcpy dst=a+x+o=0xeffffc80
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc80
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc80
result of memcpy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb

Note: in both cases the pointer to the target (of bcopy and memcpy) are the
same a+x+o=0xeffffc7e and &(tmp_iphdr->saddr)=0xeffffc7e. The first case
works with memcpy, the second doesnt. This looks clearly like some broken
optimization.

Indeed:

ecki@auric:~$ gcc -O0 -o bla bla.c
ecki@auric:~$ ./bla
Start of struct 0xeffffc70, content: a=aaaaaaaaaaaaaa rel-pos x=12 offset
o=2
Now we are going to memcpy dst=a+x+o=0xeffffc7e
result of a+x+o access: b=aaaabbbbbbbbbb
Now we are going to bcopy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of bcopy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb
Now we are going to memcpy dst=&(tmp_iphdr->saddr)=0xeffffc7e
result of memcpy &(tmp_iphdr->saddr) access: b=aaaabbbbbbbbbb

I guess this means I should report a bug against gcc

-- System Information
Debian Release: 2.2
Kernel Version: Linux auric 2.4.15-pre4 #1 SMP Thu Nov 15 09:26:46 EST 2001
sparc64 unknown

Versions of the packages gcc depends on:
ii  binutils       2.10.0.9-4     The GNU assembler, linker and binary utiliti
ii  cpp            2.95.2-13      The GNU C preprocessor.
ii  libc6          2.1.3-20       GNU C Library: Shared libraries and Timezone



Reply to: