[Patch] libgcov.c re-factoring

Jan Hubicka hubicka@ucw.cz
Sun Jan 5 20:08:00 GMT 2014


> 2014-01-03  Rong Xu  <xur@google.com>
> 
>         * gcc/gcov-io.c (gcov_var): Move from gcov-io.h.
>         (gcov_position): Ditto.
>         (gcov_is_error): Ditto.
>         (gcov_rewrite): Ditto.
>         * gcc/gcov-io.h: Refactor. Move gcov_var to gcov-io.h, and libgcov
>         only part to libgcc/libgcov.h.
>         * libgcc/libgcov-driver.c: Use libgcov.h.
>         (buffer_fn_data): Use xmalloc instead of malloc.
>         (gcov_exit_merge_gcda): Ditto.
>         * libgcc/libgcov-driver-system.c (allocate_filename_struct): Ditto.
>         * libgcc/libgcov.h: New common header files for libgcov-*.h.
>         * libgcc/libgcov-interface.c: Use libgcov.h
>         * libgcc/libgcov-merge.c: Ditto.
>         * libgcc/libgcov-profiler.c: Ditto.
>         * libgcc/Makefile.in: Add dependence to libgcov.h

OK, with the licence changes and...
> 
> Index: gcc/gcov-io.c
> ===================================================================
> --- gcc/gcov-io.c       (revision 206100)
> +++ gcc/gcov-io.c       (working copy)
> @@ -36,6 +36,61 @@ static const gcov_unsigned_t *gcov_read_words (uns
>  static void gcov_allocate (unsigned);
>  #endif
> 
> +/* Optimum number of gcov_unsigned_t's read from or written to disk.  */
> +#define GCOV_BLOCK_SIZE (1 << 10)
> +
> +GCOV_LINKAGE struct gcov_var
> +{
> +  FILE *file;
> +  gcov_position_t start;       /* Position of first byte of block */
> +  unsigned offset;             /* Read/write position within the block.  */
> +  unsigned length;             /* Read limit in the block.  */
> +  unsigned overread;           /* Number of words overread.  */
> +  int error;                   /* < 0 overflow, > 0 disk error.  */
> +  int mode;                    /* < 0 writing, > 0 reading */
> +#if IN_LIBGCOV
> +  /* Holds one block plus 4 bytes, thus all coverage reads & writes
> +     fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
> +     to and from the disk. libgcov never backtracks and only writes 4
> +     or 8 byte objects.  */
> +  gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
> +#else
> +  int endian;                  /* Swap endianness.  */
> +  /* Holds a variable length block, as the compiler can write
> +     strings and needs to backtrack.  */
> +  size_t alloc;
> +  gcov_unsigned_t *buffer;
> +#endif
> +} gcov_var;
> +
> +/* Save the current position in the gcov file.  */
> +static inline gcov_position_t
> +gcov_position (void)
> +{
> +  gcc_assert (gcov_var.mode > 0);
> +  return gcov_var.start + gcov_var.offset;
> +}
> +
> +/* Return nonzero if the error flag is set.  */
> +static inline int
> +gcov_is_error (void)
> +{
> +  return gcov_var.file ? gcov_var.error : 1;
> +}
> +
> +#if IN_LIBGCOV
> +/* Move to beginning of file and initialize for writing.  */
> +GCOV_LINKAGE inline void
> +gcov_rewrite (void)
> +{
> +  gcc_assert (gcov_var.mode > 0);

I would turn those two asserts into checking asserts so they do not
bloat the runtime lib.

Thanks,
Honza



More information about the Gcc-patches mailing list