Bug 40734

Summary: ICE on attempt to compile trivial Fortran program
Product: gcc Reporter: al.danial <al.danial>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: d, dfranke, gcc-bugs
Priority: P3    
Version: unknown   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description al.danial@ngc.com 2009-07-13 17:19:11 UTC
> gfortran -v -save-temps hello.f
Driving: gfortran -v -save-temps hello.f -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.4.0/configure --with-gmp=/apps/gmp/4.2.2 --with-mpfr=/apps/mpfr/2.4.1 --prefix=/apps/gcc/4.4.0 --enable-languages=c,c++,fortran,java,objc,obj-c++
Thread model: posix
gcc version 4.4.0 (GCC)
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
 /apps/gcc/4.4.0/libexec/gcc/i686-pc-linux-gnu/4.4.0/f951 hello.f -ffixed-form -quiet -dumpbase hello.f -mtune=generic -auxbase hello -version -fintrinsic-modules-path /apps/gcc/4.4.0/lib/gcc/i686-pc-linux-gnu/4.4.0/finclude -o hello.s
GNU Fortran (GCC) version 4.4.0 (i686-pc-linux-gnu)
        compiled by GNU C version 4.4.0, GMP version 4.2.2, MPFR version 2.4.1.
GGC heuristics: --param ggc-min-expand=99 --param ggc-min-heapsize=129284
<built-in>:0: internal compiler error: Illegal instruction
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.


The source file hello.f is

      program hi
      implicit none
      write(6,*) 'hello'
      end
Comment 1 Daniel Franke 2009-07-13 18:00:16 UTC
Fortran reports are never anything but "normal". 

However, would you really expect that a compiler would be released that can't handle code like the one quoted? I find it hard to believe, especially on a platform as common as i686-pc-linux-gnu.

Does the C-compiler work? Something like ...

$> cat hello.c
#include <stdio.h>
int main() {
  printf("hello\n");
  return 0;
}

$> gcc hello.c && ./a.out

If not, I'd check configuration, compilation and installation.
Comment 2 Jerry DeLisle 2009-07-13 18:12:56 UTC
Try compiling without these:


-lgfortranbegin -lgfortran 

Should not need to do this.  Lets see what it does.
Comment 3 al.danial@ngc.com 2009-07-13 18:30:02 UTC
(In reply to comment #1)
> Fortran reports are never anything but "normal". 
> 
> However, would you really expect that a compiler would be released that can't
> handle code like the one quoted? I find it hard to believe, especially on a
> platform as common as i686-pc-linux-gnu.
> 
> Does the C-compiler work? Something like ...
> 
> $> cat hello.c
> #include <stdio.h>
> int main() {
>   printf("hello\n");
>   return 0;
> }
> 
> $> gcc hello.c && ./a.out
> 
> If not, I'd check configuration, compilation and installation.

The C compiler works fine.  Yes, I'm puzzled by the inability of gfortran to work at all.  For what it's worth, I also built an x86_64 installation of 4.4.0 and on it gfortran works perfectly.  My build procedure on the i686 machine is identical to the procedure for x86_64 (except for the obvious difference of pointing to 32 bit libraries instead of 64 bit for GMP and MPFR).  I agree the problem is most likely on my end however I'm at a loss to figure out why.
Comment 4 al.danial@ngc.com 2009-07-13 18:33:09 UTC
(In reply to comment #2)
> Try compiling without these:
> 
> 
> -lgfortranbegin -lgfortran 
> 
> Should not need to do this.  Lets see what it does.

I don't specify either of these options (or any others for that matter).  The ICE is triggered with

  gfortran hello.f

I'm not sure why the verbose invocation (gfortran -v -save-temps) claims I supply these: -lgfortranbegin -lgfortran -lm -shared-libgcc

Comment 5 Jakub Jelinek 2009-07-13 18:42:45 UTC
My guess would be you have configured libgmp or libmpfr for a different CPU than you really have.  Try
gdb --args /apps/gcc/4.4.0/libexec/gcc/i686-pc-linux-gnu/4.4.0/f951 hello.f
run
and see on which insn it crashed (disas $pc-32 $pc+32)?

Another possibility is the binary got corrupted.
Comment 6 al.danial@ngc.com 2009-07-13 18:51:41 UTC
(In reply to comment #5)
> My guess would be you have configured libgmp or libmpfr for a different CPU
> than you really have.  Try
> gdb --args /apps/gcc/4.4.0/libexec/gcc/i686-pc-linux-gnu/4.4.0/f951 hello.f
> run
> and see on which insn it crashed (disas $pc-32 $pc+32)?
> 
> Another possibility is the binary got corrupted.

>  gdb --args /apps/gcc/4.4.0/libexec/gcc/i686-pc-linux-gnu/4.4.0/f951 hello.f
GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i386-redhat-linux-gnu"...Using host libthread_db library "/lib/tls/libthread_db.so.1".

(gdb) run
Starting program: /apps/gcc/4.4.0/libexec/gcc/i686-pc-linux-gnu/4.4.0/f951 hello.f

Program received signal SIGILL, Illegal instruction.
0x009c0cb9 in __gmpn_submul_1 () from /apps/gmp/4.2.2/lib/libgmp.so.3

(gdb) where
#0  0x009c0cb9 in __gmpn_submul_1 () from /apps/gmp/4.2.2/lib/libgmp.so.3
#1  0x009cd5a2 in __gmpn_sb_divrem_mn () from /apps/gmp/4.2.2/lib/libgmp.so.3
#2  0x00000000 in ?? ()

(gdb) disas $pc-32 $pc+32
Dump of assembler code from 0x9c0c99 to 0x9c0cd9:
0x009c0c99 <__gmpn_submul_1+2>: leave
0x009c0c9a <__gmpn_submul_1+3>: mov    0x8(%esp),%eax
0x009c0c9e <__gmpn_submul_1+7>: pcmpeqd %mm0,%mm0
0x009c0ca1 <__gmpn_submul_1+10>:        movd   0x10(%esp),%mm7
0x009c0ca6 <__gmpn_submul_1+15>:        pcmpeqd %mm6,%mm6
0x009c0ca9 <__gmpn_submul_1+18>:        mov    0x4(%esp),%edx
0x009c0cad <__gmpn_submul_1+22>:        psrlq  $0x20,%mm0
0x009c0cb1 <__gmpn_submul_1+26>:        mov    0xc(%esp),%ecx
0x009c0cb5 <__gmpn_submul_1+30>:        psllq  $0x20,%mm6
0x009c0cb9 <__gmpn_submul_1+34>:        psubq  %mm0,%mm6
0x009c0cbc <__gmpn_submul_1+37>:        psubq  %mm1,%mm0
0x009c0cbf <__gmpn_submul_1+40>:        movd   (%eax),%mm1
0x009c0cc2 <__gmpn_submul_1+43>:        lea    0x4(%eax),%eax
0x009c0cc5 <__gmpn_submul_1+46>:        movd   (%edx),%mm2
0x009c0cc8 <__gmpn_submul_1+49>:        paddq  %mm6,%mm2
0x009c0ccb <__gmpn_submul_1+52>:        pmuludq %mm7,%mm1
0x009c0cce <__gmpn_submul_1+55>:        psubq  %mm1,%mm2
0x009c0cd1 <__gmpn_submul_1+58>:        paddq  %mm2,%mm0
0x009c0cd4 <__gmpn_submul_1+61>:        sub    $0x1,%ecx
0x009c0cd7 <__gmpn_submul_1+64>:        movd   %mm0,(%edx)
End of assembler dump.
(gdb)

yeah, something with GMP.  I'll rebuild it, then rebuild GCC 4.4.0, report what happens.
Comment 7 al.danial@ngc.com 2009-07-13 21:13:00 UTC
One more data point:  the build machine runs CentOS 4.3 and on it gfortran works fine (!).  The ICE happens on a CentOS 4.4 box (using the identical GCC 4.4.0/GMP 4.2.2/MPFR 2.4.1 bits from a shared NFS mount).

I'll mark this as an invalid GCC bug.  Still baffled by the root cause of the problem though...