-O compiling mixed language code seg faults

Robert Williams bob@bob.usuf2.usuhs.mil
Sun Feb 1 19:45:00 GMT 1998


Jeffrey A Law wrote:

>   In message < 34D5009C.412EAD18@bob.usuf2.usuhs.mil >you write:
>   > System: egcs-980122, axp/RedHat-5.0, 2.1.82 kernel
>   >
>   > A main Fortran program that calls a C language subroutine
>   > (via an archive library...C code calls assembler routine in same
>   > library)
>   > seg-faults when compiled with the -O option.
>   > It works fine when compiled with -g , or with -g -O2 (or O3).
>   > Working executables are produced with any -On link option.
>   > Looks like a bug.
> Actually, from the description it could just as easily be a bug
> in your code.  You will need to debug it to find out for sure.

The  segmentation fault always occurs here, at "B( I, J ) =
LOG(FLOAT(J)) "
below.
gdb (under ddd) reports that there is no "xlog" or "xlogfloat"
symbol in the current context, and a gdb display of local variables
does not contain "xlog" and "xlogfloat".
"xfloat" does show up in gdb, and ddd.
I've added the lines in lower case to help debugging
because the debugger will not show these variables.
The print statement does show values for these
variables as expected.


      DO 40 J = 1, NCOLB
         DO 30 I = 1, NROWB
            xfloat=float(j)
            xlog=log(xfloat)
            xlogfloat=log(float(j))
*            print *,'i=',i,'  j=',j,'  float(j)=',
*     &              xfloat,'  log(float(j))=', xlog,
*     &              '  xlogfloat=',xlogfloat
            B( I, J ) = LOG(FLOAT(J))
30       CONTINUE
40    CONTINUE

This Fortran code is stable and has been
working well for many years under other compilers.
B is dimensioned 2000x2000, but the seg-fault
occurs long before those limits are reached,
at j=1 and i=1 during the second execution of this
block( i and j have already iterated 1-500
and are now going 1-1000.

That's all I can do for now.

--
Bob Williams, http://bob.usuf2.usuhs.mil/






More information about the Gcc mailing list