This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gcc and gdb bugs (was Re: g77 -O3 -ggdb -> "Internal compiler error")


>>not very important, but:
>>
>>The following FORTRAN code results in an Internal compiler error on
>>i686-pc-linux-gnulibc1 for both egcs-ss-19990502 and egcs-1.1.2 when
>>invoking the compiler with both -ggdb and -O3:
>>(of course, this is not a likely or even useful combination, but the
>>compiler told me to issue a bug report:-)
>
>It's important.  And I've long wondered when we might get a bug report
>like this.

Next time, maybe I'd better *look* at the code, instead of just skimming
it.  Turned out the problem was *not* what I thought, as there's nothing
wrong with the code itself.  Dunno how I so swiftly concluded otherwise.

Anyway, there appears to be some kind of confusion in the back end,
perhaps just in dwarf2out.c (and maybe dwarfout.c, dunno), involving
inline functions, their parameters, and so on.

Further, debugging gcc (the f771 module, but specifically the gcc back
end code linked in with it) with gdb definitely seems to be worse with
gdb 4.18 and gcc 2.95-prerelease than with whatever combinations I was
using a few months ago.

Since I don't know where the bugs are or have time to investigate, this
must necessarily be one huge bug report, which, for now, the egcs/gcc
and gdb developers should pick through to see what they can learn
about the problems I'm having.

First, here's the problematic Fortran code:

      integer function a(n)
      integer n
      a=1
      return
      end

      integer function b()
      integer a
      external a
      b=a(1)
      return
      end

As I now realize (well, as of yesterday, when I started actually looking
into fixing this), there's nothing wrong with the above code.

However, compiled with `-ggdb -O3' on my Redhat Linux 5.2 system by
gcc-2.95 19990524, it crashes.

Second, configured with --enable-checking, it crashes earlier on a seemingly
overly aggressive check in dwarf2out.c.  I have a patch for this,
which might or might not be correct -- if it's in the ballpark, though,
whoever understands this stuff should note that similar code exists in
dwarfout.c:

*** g77-e/gcc/dwarf2out.c.~1~	Sun Apr 18 09:09:25 1999
--- g77-e/gcc/dwarf2out.c	Wed May 26 10:49:51 1999
*************** decl_ultimate_origin (decl)
*** 3606,3611 ****
       register tree decl;
  {
! #ifdef ENABLE_CHECKING 
!   if (DECL_FROM_INLINE (DECL_ORIGIN (decl)))
      /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
         most distant ancestor, this should never happen.  */
--- 3606,3614 ----
       register tree decl;
  {
! #ifdef ENABLE_CHECKING
!   tree origin = DECL_ORIGIN (decl);
! 
!   if (DECL_FROM_INLINE (origin)
!       && DECL_ABSTRACT_ORIGIN (origin) != origin)
      /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the
         most distant ancestor, this should never happen.  */

The above patch solves the problem where a decl's origin is itself,
or its origin's abstract origin is itself.  I think the problem might
actually be in the definition of DECL_FROM_INLINE, as it's unclear
what that's supposed to do for a decl that points its abstract
origin to itself, but this is the most localized change I could find
that cleared up the --enable-checking problem.

Third, proceeding with that fixed, we reach the crash that presumably
the bug-submitter reached (assuming no --enable-checking).

Here, the problem appears to be that add_location_or_const_value_attribute
doesn't expect an ADDRESS for the RTL of a decl (or something like that).

(gdb) r
Starting program: /home3/craig/gnu/f77-e/gcc/f771 -quiet -ggdb -O3 < ../../play/tim.f
Breakpoint 1 at 0x4002d685: file exit.c, line 40.
Breakpoint 3 at 0x4002c7a6: file ../sysdeps/generic/abort.c, line 50.
	.file	"stdin"
	.version	"01.01"
gcc2_compiled.:
	.section	.debug_abbrev
.Ldebug_abbrev0:
	.section	.text
.Ltext0:
	.section	.debug_info
.Ldebug_info0:
	.section	.debug_line
.Ldebug_line0:
.text
	.align 4
.globl a_
	.type	 a_,@function
a_:
.LFB1:
.LM1:

.LBB2:
.LM2:

	pushl %ebp
.LCFI0:
	movl %esp,%ebp
.LCFI1:
	movl $1,%eax
	movl %ebp,%esp
	popl %ebp
	ret
.LBE2:
.LFE1:
.Lfe1:
	.size	 a_,.Lfe1-a_
	.align 4
.globl b_
	.type	 b_,@function
b_:
.LFB2:
.LM3:

.LBB3:
.LM4:

.LBB4:
.LBB5:
.LM5:

.LBE5:
.LBE4:
.LM6:

	pushl %ebp
.LCFI2:
	movl %esp,%ebp
.LCFI3:
	movl $1,%eax
	movl %ebp,%esp
	popl %ebp
	ret
.LBE3:
.LFE2:
.Lfe2:
	.size	 b_,.Lfe2-b_
stdin:54: Internal compiler error in `add_location_or_const_value_attribute', at dwarf2out.c:7243
Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.

Breakpoint 1, exit (status=33) at exit.c:40
40	exit.c: No such file or directory.
(gdb) up
#1  0x80cceff in vfatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.", ap=0xbffff74c)
    at ../../g77-e/gcc/toplev.c:1936
(gdb) 
#2  0x80ccf24 in fatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.") at ../../g77-e/gcc/toplev.c:1953
(gdb) 
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) 
#4  0x816be61 in gen_formal_parameter_die (node=0x82aa19c, 
    context_die=0x82c3ff8) at ../../g77-e/gcc/dwarf2out.c:8182
(gdb) 
#5  0x816ea31 in gen_decl_die (decl=0x82aa19c, context_die=0x82c3ff8)
    at ../../g77-e/gcc/dwarf2out.c:9536
(gdb) p origin
$1 = 0x82a92d0
(gdb) p decl
$2 = 0x82aa19c
(gdb) pt
 <var_decl 0x82aa19c n
    type <pointer_type 0x82b91fc
        type <integer_type 0x82b1194 integer allocated from permanent_obstack
            asm_written permanent SI
            size <integer_cst 0x82a66f0 constant permanent 32>
            align 32 symtab 137107904 alias set -1 precision 32
            min <integer_cst 0x82b11f4 constant permanent -2147483648>
            max <integer_cst 0x82b120c constant permanent 2147483647>
            pointer_to_this <pointer_type 0x82b91fc>>
        allocated from permanent_obstack
        unsigned asm_written permanent SI size <integer_cst 0x82a66f0 32>
        align 32 symtab 137108400 alias set -1>
    allocated from function maybepermanent obstack
    unsigned used SI file stdin line 28 size <integer_cst 0x82a66f0 32>
    align 32 context <function_decl 0x82b931c b_> abstract_origin <parm_decl 0x82a92d0 n> initial <pointer_type 0x82b91fc>
    (address/i:SI (const:SI (const_int 1 [0x1])))>
(gdb) p origin
$3 = 0x82a92d0
(gdb) pt
 <parm_decl 0x82a92d0 n
    type <pointer_type 0x82b91fc
        type <integer_type 0x82b1194 integer allocated from permanent_obstack
            asm_written permanent SI
            size <integer_cst 0x82a66f0 constant permanent 32>
            align 32 symtab 137107904 alias set -1 precision 32
            min <integer_cst 0x82b11f4 constant permanent -2147483648>
            max <integer_cst 0x82b120c constant permanent 2147483647>
            pointer_to_this <pointer_type 0x82b91fc>>
        allocated from permanent_obstack
        unsigned asm_written permanent SI size <integer_cst 0x82a66f0 32>
        align 32 symtab 137108400 alias set -1>
    allocated from function maybepermanent obstack
    readonly unsigned SI file stdin line 19 size <integer_cst 0x82a66f0 32>
    align 32 context <function_decl 0x82b90f8 a_> abstract_origin <parm_decl 0x82a92d0 n> result <pointer_type 0x82b91fc> initial <pointer_type 0x82b91fc>
    (reg/v/u:SI 22)
    incoming-rtl (mem/u/f:SI (reg:SI 16 %argp) 0)>
(gdb) down
#4  0x816be61 in gen_formal_parameter_die (node=0x82aa19c, 
    context_die=0x82c3ff8) at ../../g77-e/gcc/dwarf2out.c:8182
(gdb) down
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) p rtl
$4 = 0x82c2998
(gdb) pr

(address/i:SI (const:SI (const_int 1 [0x1])))
(gdb) 

Fourth, there seems to be one gcc/gdb bug in the above.  Note how
the "crash" message identifies -- correctly, AFAICT -- the location
of the error as line 7243 in dwarf2out.c, but gdb seems to think
the location was really line 7285, which seems quite wrong, as that's
in an entirely different function that doesn't seem to be anywhere
in the call chain (even taking into account inlining).

Fifth, there's another ongoing problem I'm having with re-running
an executable in gdb, illustrated by the transcript of the session
just prior to the above:

[...]
	pushl %ebp
.LCFI2:
	movl %esp,%ebp
.LCFI3:
	movl $1,%eax
	movl %ebp,%esp
	popl %ebp
	ret
.LBE3:
.LFE2:
.Lfe2:
	.size	 b_,.Lfe2-b_
stdin:54: Internal compiler error in `add_location_or_const_value_attribute', at dwarf2out.c:7243
Please submit a full bug report to `egcs-bugs@egcs.cygnus.com'.
See <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.

Breakpoint 1, exit (status=33) at exit.c:40
40	exit.c: No such file or directory.
(gdb) up
#1  0x80cceff in vfatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.", ap=0xbffff74c)
    at ../../g77-e/gcc/toplev.c:1936
(gdb) 
#2  0x80ccf24 in fatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.") at ../../g77-e/gcc/toplev.c:1953
(gdb) 
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) down
#2  0x80ccf24 in fatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.") at ../../g77-e/gcc/toplev.c:1953
(gdb) up
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) down
#2  0x80ccf24 in fatal (
    msgid=0x82553a0 "Internal compiler error in `%s', at %s:%d\nPlease submit a full bug report to `egcs-bugs@egcs.cygnus.com'.\nSee <URL:http://egcs.cygnus.com/faq.html#bugreport> for details.") at ../../g77-e/gcc/toplev.c:1953
(gdb) up
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) frame
#3  0x816aa99 in add_location_or_const_value_attribute (die=0x82c4088, 
    decl=0x82aa19c) at ../../g77-e/gcc/dwarf2out.c:7285
(gdb) p add_location_or_const_value_attribute
$1 = {void (dw_die_ref, 
    tree)} 0x816a73c <add_location_or_const_value_attribute>
(gdb) r
The program being debugged has been started already.
Start it from the beginning? (y or n) y

Starting program: /home3/craig/gnu/f77-e/gcc/f771 -quiet -ggdb -O3 < ../../play/tim.f
Cannot insert breakpoint 1:
Cannot access memory at address 0x4002d685.
(gdb) file f771
A program is being debugged already.  Kill it? (y or n) y

Load new symbol table from "f771"? (y or n) y
Reading symbols from f771...done.
Breakpoint 1 at 0x8049304
Breakpoint 3 at 0x80490c4
[...]

I keep having this problem, and keep having to reload via `file' to
work around it.

If anyone needs more info on any of the above, like the output of -S
when compiling things or whatever, let me know -- at this point, I can't
make any more progress on these bugs.

However, it seems reasonable to suggest they should all be fixed, to the
extent they're in gcc, for the gcc 2.95 release.

        tq vm, (burley)

P.S. I thought it might help the gdb, or gcc, people see the transcript
of the build session I used.  Unfortunately, I didn't save all of it,
but do have a recent rebuild, which at least shows what version of the
compiler I'm using (as I've faithfully named the --prefix tree to hold
the gcc snapshot I'm using to build the gcc I'm working on):

cd ~/gnu/f77-e/gcc/
make -k f771
/develop/egcs/19990524/bin/gcc -c  -DIN_GCC     -g -W -Wall  -DHAVE_CONFIG_H    -I. -I../../g77-e/gcc -I../../g77-e/gcc/config -I../../g77-e/gcc/../include ../../g77-e/gcc/dwarf2out.c
../../g77-e/gcc/dwarf2out.c: In function `gen_unspecified_parameters_die':
../../g77-e/gcc/dwarf2out.c:8203: warning: unused parameter `decl_or_type'
../../g77-e/gcc/dwarf2out.c: In function `gen_subprogram_die':
../../g77-e/gcc/dwarf2out.c:8343: warning: comparison between signed and unsigned
../../g77-e/gcc/dwarf2out.c:8358: warning: comparison between signed and unsigned
../../g77-e/gcc/dwarf2out.c: In function `gen_variable_die':
../../g77-e/gcc/dwarf2out.c:8595: warning: comparison between signed and unsigned
../../g77-e/gcc/dwarf2out.c: In function `dwarf2out_define':
../../g77-e/gcc/dwarf2out.c:9864: warning: unused parameter `lineno'
../../g77-e/gcc/dwarf2out.c:9865: warning: unused parameter `buffer'
echo " toplev.o version.o tree.o print-tree.o stor-layout.o fold-const.o function.o stmt.o except.o expr.o calls.o expmed.o explow.o optabs.o intl.o varasm.o rtl.o print-rtl.o rtlanal.o emit-rtl.o genrtl.o real.o dbxout.o sdbout.o dwarfout.o dwarf2out.o xcoffout.o bitmap.o alias.o gcse.o integrate.o jump.o cse.o loop.o unroll.o flow.o stupid.o combine.o varray.o regclass.o regmove.o local-alloc.o global.o reload.o reload1.o caller-save.o insn-peep.o reorg.o sched.o final.o recog.o reg-stack.o insn-opinit.o insn-recog.o insn-extract.o insn-output.o insn-emit.o lcm.o profile.o insn-attrtab.o i386.o getpwd.o  convert.o mbchar.o dyn-string.o splay-tree.o graph.o sbitmap.o resource.o hash.o" | sed -e 's, \([a-z0-9]\), ../\1,g' -e 's/\.o/.o/g' >stamp-objlist
touch lang-f77
cd f; make "AR_FLAGS_FOR_TARGET=rc" "AR_FOR_TARGET=` if [ -f /home3/craig/gnu/f77-e/gcc/../binutils/ar ] ; then echo /home3/craig/gnu/f77-e/gcc/../binutils/ar ; else if [ "i686-pc-linux-gnu" = "i686-pc-linux-gnu" ] ; then echo ar; else t='s,x,x,'; echo ar | sed -e $t ; fi; fi`" "BISON=`if [ -f /home3/craig/gnu/f77-e/gcc/../bison/bison ] ; then case ../../g77-e/gcc in /*) echo /home3/craig/gnu/f77-e/gcc/../bison/bison -L ../../g77-e/gcc/../bison/ ;; *) echo /home3/craig/gnu/f77-e/gcc/../bison/bison -L /home3/craig/gnu/f77-e/gcc/../../g77-e/gcc/../bison/ ;; esac; else echo bison ; fi`" "BISONFLAGS=" "CFLAGS=-g -W -Wall" "CLIB=" "GCC_FOR_TARGET=./xgcc -B./ -B/develop/egcs/e/i686-pc-linux-gnu/bin/ -I/develop/egcs/e/i686-pc-linux-gnu/include" "LDFLAGS=" "LEX=`if [ -f /home3/craig/gnu/f77-e/gcc/../flex/flex ] ; then echo /home3/craig/gnu/f77-e/gcc/../flex/flex ; else echo flex ; fi`" "LEXFLAGS=" "LN=ln" "LN_S=ln -s" "MAKEINFO=`if [ -f /home3/craig/gnu/f77-e/gcc/../texinfo/makeinfo/Makefile ] ; then echo /home3/cra
ig/gnu/f77-e/gcc/../texinfo/makeinfo/makeinfo ; else echo makeinfo ; fi`" "MAKEINFOFLAGS=" "RANLIB_FOR_TARGET=` if [ -f /home3/craig/gnu/f77-e/gcc/../binutils/ranlib ] ; then echo /home3/craig/gnu/f77-e/gcc/../binutils/ranlib ; else if [ "i686-pc-linux-gnu" = "i686-pc-linux-gnu" ] ; then echo ranlib; else t='s,x,x,'; echo ranlib | sed -e $t ; fi; fi`" "RANLIB_TEST_FOR_TARGET=[ -f ` if [ -f /home3/craig/gnu/f77-e/gcc/../binutils/ranlib ] ; then echo /home3/craig/gnu/f77-e/gcc/../binutils/ranlib ; else if [ "i686-pc-linux-gnu" = "i686-pc-linux-gnu" ] ; then echo ranlib; else t='s,x,x,'; echo ranlib | sed -e $t ; fi; fi` ] || ( [ "i686-pc-linux-gnu" = "i686-pc-linux-gnu" ] && [ -f /usr/bin/ranlib -o -f /bin/ranlib ] )" "SHELL=/bin/sh" "STAGE_PREFIX=" "exeext=" "build_exeext=" "objext=.o" "exec_prefix=/develop/egcs/e" "prefix=/develop/egcs/e" "local_prefix=/usr/local" "gxx_include_dir=/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/gcc-2.95/../../../..`echo /develop/egcs/e | sed -e 's|^/develop/egcs/e||' -e 's|/[^
/]*|/..|g'`/include/g++-2" "tooldir=" "gcc_tooldir=/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/gcc-2.95/../../../../i686-pc-linux-gnu" "bindir=/develop/egcs/e/bin" "libsubdir=/develop/egcs/e/lib/gcc-lib/i686-pc-linux-gnu/gcc-2.95" "datadir=/develop/egcs/e/share" "distdir=../tmp/\$(subdir)" "localedir=/develop/egcs/e/share/locale" "CC=/develop/egcs/19990524/bin/gcc" \
  HOST_CC="`case '/develop/egcs/19990524/bin/gcc' in stage*) echo '/develop/egcs/19990524/bin/gcc' | sed -e 's|stage|../stage|g';; *) echo '/develop/egcs/19990524/bin/gcc';; esac`" \
  HOST_CFLAGS=" -DIN_GCC     -g -W -Wall  -DHAVE_CONFIG_H" HOST_CPPFLAGS="  " \
  ../f771
make[1]: Entering directory `/home3/craig/gnu/f77-e/gcc/f'
rm -f f771
/develop/egcs/19990524/bin/gcc  -DIN_GCC    -g -W -Wall  -W -Wall  -o ../f771 bad.o bit.o bld.o com.o data.o equiv.o expr.o global.o implic.o info.o intrin.o lab.o lex.o malloc.o name.o parse.o proj.o src.o st.o sta.o stb.o stc.o std.o ste.o storag.o stp.o str.o sts.o stt.o stu.o stv.o stw.o symbol.o target.o top.o type.o version.o where.o `cat ../stamp-objlist` `if [ xobstack.o != x ]; then echo ../obstack.o; else true; fi` `case "/develop/egcs/19990524/bin/gcc" in "cc") if [ x != x ]; then echo ../; else true; fi ;; esac` `if [ x != x ]; then echo ../; else true; fi` 
make[1]: Leaving directory `/home3/craig/gnu/f77-e/gcc/f'

Compilation finished at Wed May 26 10:50:08


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]