public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/13421] New: IA32 bigmem pointer subtraction and –ftrapv option causes unjustified program abort
@ 2003-12-17 16:33 vik dot heyndrickx at pandora dot be
  2004-04-06  5:13 ` [Bug middle-end/13421] " eggert at twinsun dot com
  0 siblings, 1 reply; 5+ messages in thread
From: vik dot heyndrickx at pandora dot be @ 2003-12-17 16:33 UTC (permalink / raw)
  To: gcc-bugs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 2236 bytes --]

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-02  6:33 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-13421-4@http.gcc.gnu.org/bugzilla/>
2021-12-29  6:12 ` [Bug middle-end/13421] IA32 bigmem pointer subtraction and –ftrapv option causes unjustified program abort pinskia at gcc dot gnu.org
2023-06-25  2:01 ` pinskia at gcc dot gnu.org
2024-04-30 11:05 ` cvs-commit at gcc dot gnu.org
2024-05-02  6:33 ` rguenth at gcc dot gnu.org
2003-12-17 16:33 [Bug c/13421] New: IA32 bigmem pointer subtraction and –ftrapv " vik dot heyndrickx at pandora dot be
2004-04-06  5:13 ` [Bug middle-end/13421] " eggert at twinsun dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).