Every gcov test in the gcov testsuite 
 ( gcc/testsuite/gcc.misc-tests/gcov.exp )
fails because gcov gets a SIGSEGV
on its first invocation of 'fgets()' -  
  'char *fgets_unlocked( char *buf, size_t size, FILE *stream )
  '
is NOT declared, because '__USE_GNU' is NOT defined ; 
__USE_GNU is explicitly '#undef'd in /usr/include/features.h, 
and hence any prexisting user definition of it is discarded,
so stdio.h's :
#ifdef __USE_GNU
extern char *fgets_unlocked (char *__restrict __s, int __n,
                             FILE *__restrict __stream) __wur;
#endif
produces no output, so 'fgets_unlocked' is implicitly declared to return an
int,
producing these warnings when gcov.o is built by 'make bootstrap' :
"
gcc -c  -g -fkeep-inline-functions -DIN_GCC   -W -Wall -Wwrite-strings
-Wstrict-prototypes -Wmissing-prototypes -Wcast-qual -Wold-style-definition
-Wc++-compat -Wmissing-format-attribute -pedantic -Wno-long-long
-Wno-variadic-macros -Wno-overlength-strings   -DHAVE_CONFIG_H -I. -I.
-I../../gcc -I../../gcc/. -I../../gcc/../include -I../../gcc/../libcpp/include 
-I../../gcc/../libdecnumber -I../../gcc/../libdecnumber/bid -I../libdecnumber  
 ../../gcc/gcov.c -o gcov.o
../../gcc/gcov.c: In function 'output_lines':
../../gcc/gcov.c:1931: warning: implicit declaration of function
'fgets_unlocked'
../../gcc/gcov.c:1931: warning: assignment makes pointer from integer without a
cast
../../gcc/gcov.c:1934: warning: implicit declaration of function
'fputs_unlocked'
../../gcc/gcov.c:1974: warning: assignment makes pointer from integer without a
cast
../../gcc/gcov.c:1980: warning: assignment makes pointer from integer without a
cast
"
so gcov gets a SIGSEGV the first time it dereferences the return value of
 fgets(), which is a 64-bit pointer value converted to a 32-bit integer 
 and then back to a 64-bit pointer, on my x86_64 , 
as shown by gdb running gcov with the testsuite 'gcov-1.c' as input:
"...
Reading symbols from /usr/build2/gcc/gcc-4_4-branch/x86_64/gcc/gcov...done.    
(gdb) start gcov-1.c                                                           
Temporary breakpoint 1 at 0x403090: file ../../gcc/gcov.c, line 360.           
Starting program: /usr/build2/gcc/gcc-4_4-branch/x86_64/gcc/gcov gcov-1.c      

Temporary breakpoint 1, main (argc=2, argv=0x7fffffffeb58) at
../../gcc/gcov.c:360
360     {
(gdb) c
Continuing.
File 'gcov-1.c'
Lines executed:100.00% of 6
gcov-1.c:creating 'gcov-1.c.gcov'

Program received signal SIGSEGV, Segmentation fault.
strlen () at ../sysdeps/x86_64/strlen.S:31
31              pcmpeqb (%rdi), %xmm2
Current language:  auto
The current source language is "auto; currently asm".
(gdb) where
#0  strlen () at ../sysdeps/x86_64/strlen.S:31
#1  0x00007ffff781419e in *__GI_fputs_unlocked (str=0xffffffffffffe940 <Address
0xffffffffffffe940 out of bounds>, fp=0x6082a0) at iofputs_u.c:37
#2  0x000000000040428e in output_lines (argc=2, argv=0x7fffffffeb58) at
../../gcc/gcov.c:1934
#3  generate_results (argc=2, argv=0x7fffffffeb58) at ../../gcc/gcov.c:581
#4  main (argc=2, argv=0x7fffffffeb58) at ../../gcc/gcov.c:381
(gdb) up
#1  0x00007ffff781419e in *__GI_fputs_unlocked (str=0xffffffffffffe940 <Address
0xffffffffffffe940 out of bounds>, fp=0x6082a0) at iofputs_u.c:37
37        _IO_size_t len = strlen (str);
Current language:  auto
The current source language is "auto; currently c".
(gdb) up
#2  0x000000000040428e in output_lines (argc=2, argv=0x7fffffffeb58) at
../../gcc/gcov.c:1934
1934                  fputs (retval, gcov_file);
(gdb) print retval
$1 = 0xffffffffffffe940 <Address 0xffffffffffffe940 out of bounds>
"

It appears that the autoconf macro that sets "HAVE_DECL_FGETS_UNLOCKED"
( gcc/acinclude.m4's  gcc_AC_CHECK_DECL ) sets 
  '#define _GNU_SOURCE 1' ,
so it sees the declaration of fgets_unlocked(), while gcov.c's 
  '#define __USE_GNU'
has no effect ( __USE_GNU is #undef'd by features.h ).

Suggested patch:

$ diff -u gcov.c~ gcov.c
--- gcov.c~     2009-04-10 16:48:28.000000000 +0100
+++ gcov.c      2009-09-29 16:53:52.000000000 +0100
@@ -31,8 +31,8 @@

 /* Need an option to show individual block counts, and show
    probabilities of fall through arcs.  */
-#define __USE_XOPEN
-#define __USE_GNU
+#define _XOPEN_SOURCE 1
+#define _GNU_SOURCE   1
 #include <sys/types.h>
 #include <unistd.h>
 #include <stdio.h>


-- 
           Summary: all gcov tests fail because gcov.c's use of '#define
                    __USE_GNU' has no effect
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jason dot vas dot dias at gmail dot com
 GCC build triplet: x86_64-pc-linux-gnu
  GCC host triplet: x86_64-pc-linux-gnu
GCC target triplet: x86_64-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41506

Reply via email to