preprocessor/6084: cpp Segmentation Fault
Gerwin, Joshua A
joshua.a.gerwin@intel.com
Fri Apr 12 16:06:00 GMT 2002
The following reply was made to PR preprocessor/6084; it has been noted by GNATS.
From: "Gerwin, Joshua A" <joshua.a.gerwin@intel.com>
To: "'Phil Edwards'" <phil@jaj.com>, joshg@hf.intel.com, gcc-gnats@gcc.gnu.org,
rnesius@ichips.intel.com, "Nguyen, Tuan"<tuan.nguyen@intel.com>,
gcc-bugs@gcc.gnu.org, neil@daikokuya.demon.co.uk
Cc:
Subject: RE: preprocessor/6084: cpp Segmentation Fault
Date: Fri, 12 Apr 2002 15:57:12 -0700
> -----Original Message-----
> From: Phil Edwards [mailto:phil@jaj.com]
> Sent: Friday, April 12, 2002 1:27 PM
> To: joshg@hf.intel.com; gcc-gnats@gcc.gnu.org;
> rnesius@ichips.intel.com;
> tuan.nguyen@intel.com; gcc-bugs@gcc.gnu.org;
> neil@daikokuya.demon.co.uk
> Subject: Re: preprocessor/6084: cpp Segmentation Fault
>
>
> I haven't been able to reproduce this using today's 3.1
> sources. (More at
> the end.)
>
My hunch is that this is either a 3.0 problem, perhaps fixed in your version
of 3.1, or that the libc.so we're linking during compile is significantly
different. Note that I could produce a segfault in strlen with minimal
options and no source at all, simply by having both -dD and -DM present.
%cat empty.c
/* no source */
%which cpp
/path/to/gcc/3.0.3-64/bin/cpp
%cpp -dM -dD empty.c
cpp: Internal error: Segmentation Fault (program cpp0)
Please submit a full bug report.
See <URL:http://www.gnu.org/software/gcc/bugs.html> for instructions.
Running gcc, I observe
(gdb) file /path/to/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0
Load new symbol table from
"/path/to/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0"? (y or
n) y
Reading symbols from
/path/to/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0...done.
(gdb) run -dM -dD empty.c
Starting program:
/path/to/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0 -dM -dD
empty.c
Program received signal SIGSEGV, Segmentation fault.
0xffffffff7f44035c in strlen () from /usr/lib/64/libc.so.1
(gdb) bt
#0 0xffffffff7f44035c in strlen () from /usr/lib/64/libc.so.1
#1 0xffffffff7f48d6d4 in _doprnt () from /usr/lib/64/libc.so.1
#2 0xffffffff7f48f180 in fprintf () from /usr/lib/64/libc.so.1
#3 0x100003d28 in maybe_print_line ()
#4 0x100003e1c in cb_define ()
#5 0x100004904 in do_define ()
#6 0x100004778 in run_directive ()
#7 0x100011d20 in init_builtins ()
#8 0x100012344 in cpp_start_read ()
#9 0x100003680 in do_preprocessing ()
#10 0x10000349c in main ()
(gdb)
Also noteworthy, reversing the parameters fixes the segfault!
(gdb) run -dD -dM
The program being debugged has been started already.
Start it from the beginning? (y or n) y
Starting program:
/usr/intel/pkgs/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0 -dD
-dM
^D
#define __USER_LABEL_PREFIX__
#define __HAVE_BUILTIN_SETJMP__ 1
#define __REGISTER_PREFIX__
#define __VERSION__ "3.0.3"
Program exited normally.
(gdb) run -dM -dD
Starting program:
/usr/intel/pkgs/gcc/3.0.3-64/lib/gcc-lib/sparcv9-sun-solaris2/3.0.3/cpp0 -dM
-dD
^D
Program received signal SIGSEGV, Segmentation fault.
0xffffffff7f44035c in strlen () from /usr/lib/64/libc.so.1
Here's the maybe_print_line function and related symbols, for handy
reference:
static void
maybe_print_line (line)
unsigned int line;
{
/* End the previous line of text (probably only needed until we get
multi-line tokens fixed). */
if (print.printed)
{
putc ('\n', print.outf);
print.lineno++;
print.printed = 0;
}
if (options->no_line_commands)
{
print.lineno = line;
return;
}
/* print.lineno is zero if this is the first token of the file. We
handle this specially, so that a first line of "# 1 "foo.c" in
file foo.i outputs just the foo.c line, and not a foo.i line. */
if (line >= print.lineno && line < print.lineno + 8 && print.lineno)
{
while (line > print.lineno)
{
putc ('\n', print.outf);
print.lineno++;
}
}
else
{
print.lineno = line;
print_line ("");
}
}
static void
print_line (special_flags)
const char *special_flags;
{
/* End any previous line of text. */
if (print.printed)
putc ('\n', print.outf);
print.printed = 0;
fprintf (print.outf, "# %u \"%s\"%s%s\n",
print.lineno, print.last_fname, special_flags,
print.syshdr_flags);
}
(gdb) whatis print
type = struct printer
(gdb) ptype struct printer
type = struct printer {
FILE *outf;
char *last_fname;
char *syshdr_flags;
unsigned int lineno;
unsigned char printed;
}
This is about all the source diving I can do for it today.
Josh Gerwin, System Programmer/Analyst
joshua.a.gerwin@intel.com
Intel Corp.
NorthWest Engineering Computing
More information about the Gcc-prs
mailing list