public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/41506]  New: all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect
@ 2009-09-29 15:57 jason dot vas dot dias at gmail dot com
  2009-09-29 15:59 ` [Bug gcov-profile/41506] " jason dot vas dot dias at gmail dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jason dot vas dot dias at gmail dot com @ 2009-09-29 15:57 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/41506] all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect
  2009-09-29 15:57 [Bug gcov-profile/41506] New: all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect jason dot vas dot dias at gmail dot com
@ 2009-09-29 15:59 ` jason dot vas dot dias at gmail dot com
  2009-09-29 16:07 ` jakub at gcc dot gnu dot org
  2009-10-05  2:21 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: jason dot vas dot dias at gmail dot com @ 2009-09-29 15:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jason dot vas dot dias at gmail dot com  2009-09-29 15:59 -------
Created an attachment (id=18666)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18666&action=view)
Patch to fix gcov


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/41506] all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect
  2009-09-29 15:57 [Bug gcov-profile/41506] New: all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect jason dot vas dot dias at gmail dot com
  2009-09-29 15:59 ` [Bug gcov-profile/41506] " jason dot vas dot dias at gmail dot com
@ 2009-09-29 16:07 ` jakub at gcc dot gnu dot org
  2009-10-05  2:21 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: jakub at gcc dot gnu dot org @ 2009-09-29 16:07 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jakub at gcc dot gnu dot org  2009-09-29 16:06 -------
It would be helpful to know what you are patching, because neither 4.4 branch
nor trunk gcov.c has anything like that, see e.g.
http://sources.redhat.com/viewcvs/gcc/branches/gcc-4_4-branch/gcc/gcov.c?revision=145122&view=markup


-- 


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug gcov-profile/41506] all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect
  2009-09-29 15:57 [Bug gcov-profile/41506] New: all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect jason dot vas dot dias at gmail dot com
  2009-09-29 15:59 ` [Bug gcov-profile/41506] " jason dot vas dot dias at gmail dot com
  2009-09-29 16:07 ` jakub at gcc dot gnu dot org
@ 2009-10-05  2:21 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-10-05  2:21 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2009-10-05 02:21 -------
As mentioned you are using a modified version of gcov.  There is no such line
in gcov.c


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |WORKSFORME


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-10-05  2:21 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-29 15:57 [Bug gcov-profile/41506] New: all gcov tests fail because gcov.c's use of '#define __USE_GNU' has no effect jason dot vas dot dias at gmail dot com
2009-09-29 15:59 ` [Bug gcov-profile/41506] " jason dot vas dot dias at gmail dot com
2009-09-29 16:07 ` jakub at gcc dot gnu dot org
2009-10-05  2:21 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).