gcov-tool: Flexible endian adjustment for merging coverage data

gcc/ChangeLog:
2020-05-27  Dong JianQiang  <dongjianqiang2@huawei.com>

	PR gcov-profile/95332
	* gcov-io.c (gcov_var::endian): Move field.
	(from_file): Add IN_GCOV_TOOL check.
	* gcov-io.h (gcov_magic): Ditto.

libgcc/ChangeLog:
2020-05-27  Dong JianQiang  <dongjianqiang2@huawei.com>

	PR gcov-profile/95332
	* libgcov-util.c (read_gcda_file): Call gcov_magic.
	* libgcov.h (gcov_magic): Disable GCC poison.

(cherry picked from commit 17d1594bfe08f3c768e024b180816cbe37ac08ac)
parent 81211dbf
...@@ -48,6 +48,7 @@ struct gcov_var ...@@ -48,6 +48,7 @@ struct gcov_var
unsigned overread; /* Number of words overread. */ unsigned overread; /* Number of words overread. */
int error; /* < 0 overflow, > 0 disk error. */ int error; /* < 0 overflow, > 0 disk error. */
int mode; /* < 0 writing, > 0 reading */ int mode; /* < 0 writing, > 0 reading */
int endian; /* Swap endianness. */
#if IN_LIBGCOV #if IN_LIBGCOV
/* Holds one block plus 4 bytes, thus all coverage reads & writes /* Holds one block plus 4 bytes, thus all coverage reads & writes
fit within this buffer and we always can transfer GCOV_BLOCK_SIZE fit within this buffer and we always can transfer GCOV_BLOCK_SIZE
...@@ -55,7 +56,6 @@ struct gcov_var ...@@ -55,7 +56,6 @@ struct gcov_var
or 8 byte objects. */ or 8 byte objects. */
gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1]; gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1];
#else #else
int endian; /* Swap endianness. */
/* Holds a variable length block, as the compiler can write /* Holds a variable length block, as the compiler can write
strings and needs to backtrack. */ strings and needs to backtrack. */
size_t alloc; size_t alloc;
...@@ -100,7 +100,7 @@ gcov_rewrite (void) ...@@ -100,7 +100,7 @@ gcov_rewrite (void)
static inline gcov_unsigned_t from_file (gcov_unsigned_t value) static inline gcov_unsigned_t from_file (gcov_unsigned_t value)
{ {
#if !IN_LIBGCOV #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
if (gcov_var.endian) if (gcov_var.endian)
{ {
value = (value >> 16) | (value << 16); value = (value >> 16) | (value << 16);
...@@ -222,7 +222,7 @@ gcov_close (void) ...@@ -222,7 +222,7 @@ gcov_close (void)
return gcov_var.error; return gcov_var.error;
} }
#if !IN_LIBGCOV #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
/* Check if MAGIC is EXPECTED. Use it to determine endianness of the /* Check if MAGIC is EXPECTED. Use it to determine endianness of the
file. Returns +1 for same endian, -1 for other endian and zero for file. Returns +1 for same endian, -1 for other endian and zero for
not EXPECTED. */ not EXPECTED. */
......
...@@ -326,6 +326,9 @@ struct gcov_summary ...@@ -326,6 +326,9 @@ struct gcov_summary
#if !IN_LIBGCOV #if !IN_LIBGCOV
GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/); GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/);
#endif
#if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t); GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t);
#endif #endif
......
...@@ -261,7 +261,7 @@ read_gcda_file (const char *filename) ...@@ -261,7 +261,7 @@ read_gcda_file (const char *filename)
{ {
unsigned tags[4]; unsigned tags[4];
unsigned depth = 0; unsigned depth = 0;
unsigned magic, version; unsigned version;
struct gcov_info *obj_info; struct gcov_info *obj_info;
int i; int i;
...@@ -276,8 +276,7 @@ read_gcda_file (const char *filename) ...@@ -276,8 +276,7 @@ read_gcda_file (const char *filename)
} }
/* Read magic. */ /* Read magic. */
magic = gcov_read_unsigned (); if (!gcov_magic (gcov_read_unsigned (), GCOV_DATA_MAGIC))
if (magic != GCOV_DATA_MAGIC)
{ {
fnotice (stderr, "%s:not a gcov data file\n", filename); fnotice (stderr, "%s:not a gcov data file\n", filename);
gcov_close (); gcov_close ();
......
...@@ -147,7 +147,7 @@ extern struct gcov_info *gcov_list; ...@@ -147,7 +147,7 @@ extern struct gcov_info *gcov_list;
/* Poison these, so they don't accidentally slip in. */ /* Poison these, so they don't accidentally slip in. */
#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length #pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length
#pragma GCC poison gcov_time gcov_magic #pragma GCC poison gcov_time
#ifdef HAVE_GAS_HIDDEN #ifdef HAVE_GAS_HIDDEN
#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment