[gnu.gcc.bug] BUG in GCC 1.30 with COFF line numbers using -g & -finline-functions

rfg@nsc.nsc.com (Ron Guilmette) (10/27/88)

BUG in GCC 1.30  -- suggested fix included below

If you try to use -g and -finline-functions on GCC 1.30 (or earlier)
and if your system uses COFF (i.e. SDB_DEBUGGING_INFO is #defined)
then you may get ".ln <nnn>" COFF line number directives in the
assembly code produced by GCC, where the value of <nnn> is negative!
This will probably mess-up the mind of your assembler or your linker,
or your sdb(1) debugger.

This happens because COFF symbolics use RELATIVE line numbers (i.e.
relative the the first line of the CURRENT function).  Thus, when
preceeding code gets inline'd into the current function, the RELATIVE
line numbers for the inline'd code are, in fact, negative.

The following simple patch should prevent the negative ".ln <nnn>"
directives from being generated.

diff -rc2 1.30-old/final.c 1.30-new/final.c
*** 1.30-old/final.c	Fri Oct 14 15:19:54 1988
--- 1.30-new/final.c	Wed Oct 26 12:17:49 1988
***************
*** 842,845
  	  && !strcmp (filename, main_input_filename))
  	{
  #ifdef ASM_OUTPUT_SOURCE_LINE
  	  ASM_OUTPUT_SOURCE_LINE (file, last_linenum);

--- 838,843 -----
  	  && !strcmp (filename, main_input_filename))
  	{
+ 	  int relative_linenum;
+ 
  #ifdef ASM_OUTPUT_SOURCE_LINE
  	  ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
***************
*** 845,851
  	  ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  #else
! 	  fprintf (file, "\t.ln\t%d\n",
! 		   (sdb_begin_function_line
! 		    ? last_linenum - sdb_begin_function_line : 1));
  #endif
  	}

--- 843,851 -----
  	  ASM_OUTPUT_SOURCE_LINE (file, last_linenum);
  #else
! 	  relative_linenum = last_linenum - sdb_begin_function_line;
! 	  /* Don't output negative line numbers for earlier inlined code.  */
! 	  if (relative_linenum > 0)
! 	    fprintf (file, "\t.ln\t%d\n",
! 		   (sdb_begin_function_line ? relative_linenum : 1));
  #endif
  	}