This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/8726: GCC 3.2.1 miscompiles Samba 2.2.7 on 32-bit sparc
- From: Paul Eggert <eggert at twinsun dot com>
- To: gcc-gnats at gcc dot gnu dot org
- Date: Tue, 26 Nov 2002 17:04:56 -0800 (PST)
- Subject: optimization/8726: GCC 3.2.1 miscompiles Samba 2.2.7 on 32-bit sparc
>Number: 8726
>Category: optimization
>Synopsis: GCC 3.2.1 -O2 miscompiles Samba 2.2.7 on 32-bit sparc
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Nov 26 17:06:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator: Paul Eggert.
>Release: 3.2.1
>Organization:
Twin Sun, Inc.
>Environment:
System: SunOS sic.twinsun.com 5.8 Generic_108528-17 sun4u sparc SUNW,UltraSPARC-IIi-Engine
Architecture: sun4
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sparc-sun-solaris2.8
configured with: ../gcc-3.2.1/configure --disable-nls --enable-languages=c,c++ --prefix=/opt/reb/lib/gcc/gcc-3.2.1 --with-system-zlib
>Description:
Samba 2.2.7 (32-bit sparc) mishandles 64-bit file locks because
GCC 3.2.1 miscompiles the file-locking code. I have narrowed
down the problem to a simple test case enclosed below.
>How-To-Repeat:
Compile and run the following program with "gcc -O2 t.i; ./a.out".
a.out will exit with nonzero status; it should exit with zero status.
# 1 "t.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "t.c"
int fcntl_lock(int fd, int op, long long offset, long long count, int type);
int vfswrap_lock(char *fsp, int fd, int op, long long offset, long long count, int type)
{
int result;
result = fcntl_lock(fd, op, offset, count,type);
return result;
}
int fcntl_lock(int fd, int op, long long offset, long long count, int type)
{
return type;
}
int
main (void)
{
return vfswrap_lock (0, 1, 2, 3, 4, 5) != 5;
}
The problem can be found in the assembly code for vfswrap_lock.
The "st" followed by the "ldd" puts garbage into the "type" argument.
vfswrap_lock:
!#PROLOGUE# 0
add %sp, -48, %sp
!#PROLOGUE# 1
mov %o1, %o0
mov %o2, %o1
mov %o3, %o2
st %o5, [%sp+136]
mov %o4, %o3
ldd [%sp+136], %o4
sethi %hi(fcntl_lock), %g1
jmpl %g1 + %lo(fcntl_lock), %g0
sub %sp, -48, %sp
>Fix:
A workaround is to not compile with -O2.
>Release-Note:
>Audit-Trail:
>Unformatted: