* [gcov]:Remove ftruncate
@ 2004-07-29 18:30 Nathan Sidwell
2004-07-29 18:34 ` Richard Sandiford
0 siblings, 1 reply; 2+ messages in thread
From: Nathan Sidwell @ 2004-07-29 18:30 UTC (permalink / raw)
To: GCC Patches, Richard Sandiford
[-- Attachment #1: Type: text/plain, Size: 321 bytes --]
Hi,
I've installed this patch which removes the need for ftruncate within
libgcov.
booted & tested with & without --enable-coverage on i686-pc-linux-gnu
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
[-- Attachment #2: gcov.patch --]
[-- Type: text/plain, Size: 11612 bytes --]
2004-07-29 Nathan Sidwell <nathan@codesourcery.com>
* gcov-io.h: Allow zero tag as EOF indicator.
(gcov_is_eof): Remove.
(gcov_truncate): Remove.
* gcov-io.c (gcov_seek): Always SEEK_SET.
* libgcov.c (gcov_exit): Don't use gcov_truncate. Write explicit
EOF tag.
* coverage.c (read_counts_file): Don't use gcov_is_eof.
* gcov-dump.c (dump_file): Likewise.
* gcov.c (read_graph_file, read_count_file): Likewise.
Index: coverage.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/coverage.c,v
retrieving revision 1.41
diff -c -3 -p -r1.41 coverage.c
*** coverage.c 25 Jul 2004 19:15:42 -0000 1.41
--- coverage.c 28 Jul 2004 19:03:15 -0000
*************** read_counts_file (void)
*** 292,305 ****
}
gcov_sync (offset, length);
if ((is_error = gcov_is_error ()))
! break;
! }
!
! if (!gcov_is_eof ())
! {
! error (is_error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
! da_file_name);
! htab_delete (counts_hash);
}
gcov_close ();
--- 292,303 ----
}
gcov_sync (offset, length);
if ((is_error = gcov_is_error ()))
! {
! error (is_error < 0 ? "`%s' has overflowed" : "`%s' is corrupted",
! da_file_name);
! htab_delete (counts_hash);
! break;
! }
}
gcov_close ();
Index: gcov-dump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov-dump.c,v
retrieving revision 1.19
diff -c -3 -p -r1.19 gcov-dump.c
*** gcov-dump.c 10 Jul 2003 14:13:00 -0000 1.19
--- gcov-dump.c 28 Jul 2004 19:03:15 -0000
*************** dump_file (const char *filename)
*** 254,261 ****
break;
}
}
- if (!gcov_is_eof ())
- printf ("%s:early end of file\n", filename);
gcov_close ();
}
--- 254,259 ----
Index: gcov-io.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov-io.c,v
retrieving revision 1.15
diff -c -3 -p -r1.15 gcov-io.c
*** gcov-io.c 23 Feb 2004 17:02:50 -0000 1.15
--- gcov-io.c 28 Jul 2004 19:03:16 -0000
*************** gcov_sync (gcov_position_t base, gcov_un
*** 514,521 ****
#endif
#if IN_LIBGCOV
! /* Move to the a set position in a gcov file. BASE is zero to move to
! the end, and nonzero to move to that position. */
GCOV_LINKAGE void
gcov_seek (gcov_position_t base)
--- 514,520 ----
#endif
#if IN_LIBGCOV
! /* Move to the a set position in a gcov file. */
GCOV_LINKAGE void
gcov_seek (gcov_position_t base)
*************** gcov_seek (gcov_position_t base)
*** 523,529 ****
GCOV_CHECK_WRITING ();
if (gcov_var.offset)
gcov_write_block (gcov_var.offset);
! fseek (gcov_var.file, base << 2, base ? SEEK_SET : SEEK_END);
gcov_var.start = ftell (gcov_var.file) >> 2;
}
#endif
--- 522,528 ----
GCOV_CHECK_WRITING ();
if (gcov_var.offset)
gcov_write_block (gcov_var.offset);
! fseek (gcov_var.file, base << 2, SEEK_SET);
gcov_var.start = ftell (gcov_var.file) >> 2;
}
#endif
Index: gcov-io.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov-io.h,v
retrieving revision 1.50
diff -c -3 -p -r1.50 gcov-io.h
*** gcov-io.h 25 Apr 2004 16:38:07 -0000 1.50
--- gcov-io.h 28 Jul 2004 19:03:18 -0000
*************** typedef HOST_WIDEST_INT gcov_type;
*** 243,249 ****
#define gcov_seek __gcov_seek
#define gcov_rewrite __gcov_rewrite
#define gcov_is_error __gcov_is_error
- #define gcov_is_eof __gcov_is_eof
#define gcov_write_unsigned __gcov_write_unsigned
#define gcov_write_counter __gcov_write_counter
#define gcov_write_summary __gcov_write_summary
--- 243,248 ----
*************** typedef HOST_WIDEST_INT gcov_type;
*** 284,290 ****
/* The record tags. Values [1..3f] are for tags which may be in either
file. Values [41..9f] for those in the note file and [a1..ff] for
! the data file. */
#define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
#define GCOV_TAG_FUNCTION_LENGTH (2)
--- 283,290 ----
/* The record tags. Values [1..3f] are for tags which may be in either
file. Values [41..9f] for those in the note file and [a1..ff] for
! the data file. The tag value zero is used as an explicit end of
! file marker -- it is not required to be present. */
#define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000)
#define GCOV_TAG_FUNCTION_LENGTH (2)
*************** GCOV_LINKAGE int gcov_close (void);
*** 510,516 ****
/* Available everywhere. */
static gcov_position_t gcov_position (void);
static int gcov_is_error (void);
- static int gcov_is_eof (void);
GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void);
GCOV_LINKAGE gcov_type gcov_read_counter (void);
--- 510,515 ----
*************** GCOV_LINKAGE void gcov_write_counter (gc
*** 522,528 ****
GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, gcov_unsigned_t);
GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/,
const struct gcov_summary *);
- static void gcov_truncate (void);
static void gcov_rewrite (void);
GCOV_LINKAGE void gcov_seek (gcov_position_t /*position*/);
#else
--- 521,526 ----
*************** gcov_position (void)
*** 567,580 ****
return gcov_var.start + gcov_var.offset;
}
- /* Return nonzero if we read to end of file. */
-
- static inline int
- gcov_is_eof (void)
- {
- return !gcov_var.overread;
- }
-
/* Return nonzero if the error flag is set. */
static inline int
--- 565,570 ----
*************** gcov_rewrite (void)
*** 595,609 ****
gcov_var.offset = 0;
fseek (gcov_var.file, 0L, SEEK_SET);
}
-
- #ifdef __MINGW32__
- #define ftruncate _chsize
- #endif
- static inline void
- gcov_truncate (void)
- {
- ftruncate (fileno (gcov_var.file), 0L);
- }
#endif
#endif /* IN_LIBGCOV >= 0 */
--- 585,590 ----
Index: gcov.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/gcov.c,v
retrieving revision 1.81
diff -c -3 -p -r1.81 gcov.c
*** gcov.c 28 Jul 2004 09:57:38 -0000 1.81
--- gcov.c 28 Jul 2004 19:03:22 -0000
*************** read_graph_file (void)
*** 896,909 ****
}
gcov_sync (base, length);
if (gcov_is_error ())
! break;
! }
! if (!gcov_is_eof ())
! {
! corrupt:;
! fnotice (stderr, "%s:corrupted\n", bbg_file_name);
! gcov_close ();
! return 1;
}
gcov_close ();
--- 896,907 ----
}
gcov_sync (base, length);
if (gcov_is_error ())
! {
! corrupt:;
! fnotice (stderr, "%s:corrupted\n", bbg_file_name);
! gcov_close ();
! return 1;
! }
}
gcov_close ();
*************** read_count_file (void)
*** 1055,1068 ****
}
gcov_sync (base, length);
if ((error = gcov_is_error ()))
! break;
! }
!
! if (!gcov_is_eof ())
! {
! fnotice (stderr, error < 0 ? "%s:overflowed\n" : "%s:corrupted\n",
! da_file_name);
! goto cleanup;
}
gcov_close ();
--- 1053,1063 ----
}
gcov_sync (base, length);
if ((error = gcov_is_error ()))
! {
! fnotice (stderr, error < 0 ? "%s:overflowed\n" : "%s:corrupted\n",
! da_file_name);
! goto cleanup;
! }
}
gcov_close ();
Index: libgcov.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/libgcov.c,v
retrieving revision 1.25
diff -c -3 -p -r1.25 libgcov.c
*** libgcov.c 23 Apr 2004 22:50:16 -0000 1.25
--- libgcov.c 28 Jul 2004 19:03:22 -0000
*************** gcov_exit (void)
*** 164,169 ****
--- 164,170 ----
int error = 0;
gcov_unsigned_t tag, length;
gcov_position_t summary_pos = 0;
+ gcov_position_t eof_pos = 0;
memset (&this_object, 0, sizeof (this_object));
memset (&object, 0, sizeof (object));
*************** gcov_exit (void)
*** 218,226 ****
{
fprintf (stderr, "profiling:%s:Not a gcov data file\n",
gi_ptr->filename);
! read_fatal:;
! gcov_close ();
! continue;
}
length = gcov_read_unsigned ();
if (!gcov_version (gi_ptr, length))
--- 219,225 ----
{
fprintf (stderr, "profiling:%s:Not a gcov data file\n",
gi_ptr->filename);
! goto read_fatal;
}
length = gcov_read_unsigned ();
if (!gcov_version (gi_ptr, length))
*************** gcov_exit (void)
*** 228,239 ****
length = gcov_read_unsigned ();
if (length != gi_ptr->stamp)
! {
! /* Read from a different compilation. Overwrite the
! file. */
! gcov_truncate ();
! goto rewrite;
! }
/* Merge execution counts for each function. */
for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
--- 227,234 ----
length = gcov_read_unsigned ();
if (length != gi_ptr->stamp)
! /* Read from a different compilation. Overwrite the file. */
! goto rewrite;
/* Merge execution counts for each function. */
for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++)
*************** gcov_exit (void)
*** 284,295 ****
/* Check program & object summary */
while (1)
{
- gcov_position_t base = gcov_position ();
int is_program;
tag = gcov_read_unsigned ();
if (!tag)
break;
length = gcov_read_unsigned ();
is_program = tag == GCOV_TAG_PROGRAM_SUMMARY;
if (length != GCOV_TAG_SUMMARY_LENGTH
--- 279,291 ----
/* Check program & object summary */
while (1)
{
int is_program;
+ eof_pos = gcov_position ();
tag = gcov_read_unsigned ();
if (!tag)
break;
+
length = gcov_read_unsigned ();
is_program = tag == GCOV_TAG_PROGRAM_SUMMARY;
if (length != GCOV_TAG_SUMMARY_LENGTH
*************** gcov_exit (void)
*** 300,318 ****
goto read_error;
if (is_program && program.checksum == gcov_crc32)
{
! summary_pos = base;
goto rewrite;
}
}
}
! if (!gcov_is_eof ())
! {
! read_error:;
! fprintf (stderr, error < 0 ? "profiling:%s:Overflow merging\n"
! : "profiling:%s:Error merging\n", gi_ptr->filename);
! goto read_fatal;
! }
rewrite:;
gcov_rewrite ();
if (!summary_pos)
--- 296,316 ----
goto read_error;
if (is_program && program.checksum == gcov_crc32)
{
! summary_pos = eof_pos;
goto rewrite;
}
}
}
+ goto rewrite;
! read_error:;
! fprintf (stderr, error < 0 ? "profiling:%s:Overflow merging\n"
! : "profiling:%s:Error merging\n", gi_ptr->filename);
!
! read_fatal:;
! gcov_close ();
! continue;
!
rewrite:;
gcov_rewrite ();
if (!summary_pos)
*************** gcov_exit (void)
*** 414,421 ****
gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, &object);
/* Generate whole program statistics. */
! gcov_seek (summary_pos);
gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program);
if ((error = gcov_close ()))
fprintf (stderr, error < 0 ?
"profiling:%s:Overflow writing\n" :
--- 412,422 ----
gcov_write_summary (GCOV_TAG_OBJECT_SUMMARY, &object);
/* Generate whole program statistics. */
! if (eof_pos)
! gcov_seek (eof_pos);
gcov_write_summary (GCOV_TAG_PROGRAM_SUMMARY, &program);
+ if (!summary_pos)
+ gcov_write_unsigned (0);
if ((error = gcov_close ()))
fprintf (stderr, error < 0 ?
"profiling:%s:Overflow writing\n" :
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [gcov]:Remove ftruncate
2004-07-29 18:30 [gcov]:Remove ftruncate Nathan Sidwell
@ 2004-07-29 18:34 ` Richard Sandiford
0 siblings, 0 replies; 2+ messages in thread
From: Richard Sandiford @ 2004-07-29 18:34 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: GCC Patches
Nathan Sidwell <nathan@codesourcery.com> writes:
> I've installed this patch which removes the need for ftruncate within
> libgcov.
Thanks! And sorry again for the earlier stupidity...
Richard
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-07-29 9:02 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-29 18:30 [gcov]:Remove ftruncate Nathan Sidwell
2004-07-29 18:34 ` Richard Sandiford
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).