This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/13421] New: IA32 bigmem pointer subtraction and –ftrapv option causes unjustified program abort
- From: "vik dot heyndrickx at pandora dot be" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 17 Dec 2003 15:29:36 -0000
- Subject: [Bug c/13421] New: IA32 bigmem pointer subtraction and –ftrapv option causes unjustified program abort
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
kernel-2.4.22-1.2115.nptl, glibc-2.3.2-101.1
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --
infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-
checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
Circumstances: ?-ftrapv? is a gcc compiler option used to detect signed integer
overflow conditions, and as such is frequently used to debug programs. This
flag is by default disabled.
On IA32 these days adressible memory for a process can be larger than 2^31
octets. It is possible for a memory block whose lower bound address is less
than 2^31 en whose upper bound address is larger than 2^31, to be assigned.
Subtracting these two addresses is a normal operation to determine the size of
that block. It appears however that when ?-ftrapv? is used to compile a
program, execution of this program is aborted when subtracting these pointers.
In my opinion this should not happen, because there is nothing illegal about.
Example of failing program test.c (it looks "manufactured", but is short, the
real program I encountered this problem with is less manufactured, I got the
addresses from malloc(), and that program was long):
<cut>
long signed diff = 0;
void setdiff (unsigned char *a, unsigned char *b) {
diff = b - a;
}
int main (void) {
unsigned char *a, *b;
a = (unsigned char*)0x7FFFF000u;
b = (unsigned char*)0x80000001u;
setdiff (a, b);
return 0;
}
</cut>
Compiler command line:
gcc -ftrapv test.c
execution of the resulting program a.out:
Aborted
--
Summary: IA32 bigmem pointer subtraction and ?ftrapv option
causes unjustified program abort
Product: gcc
Version: 3.3.2
Status: UNCONFIRMED
Severity: critical
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: vik dot heyndrickx at pandora dot be
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: gcc version 3.3.2 20031022 (Red Hat Linux 3.3.2-1)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13421