gcov-io.cc is compiled by the host compiler into gcov, gcov-dump
and gcov-tool.  The host compiler need not provide
__builtin_bswap32.  Add a byte-swap helper instead.

Bootstrapped and regression-tested on x86_64-pc-linux-gnu
(default languages, --disable-multilib), with no new regressions
relative to the unmodified baseline.

Also tested with a non-GCC, EDG-based host compiler (GNU extensions
disabled) on a non-glibc platform, where the patch resolves a build
failure.

gcc/ChangeLog:

        * gcov-io.cc (gcov_bswap32): New function.
        (from_file, gcov_magic): Use it instead of __builtin_bswap32.

Signed-off-by: Shiva <[email protected]>
---
 gcc/gcov-io.cc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc
index 0fda8795b21..1c443f97808 100644
--- a/gcc/gcov-io.cc
+++ b/gcc/gcov-io.cc
@@ -91,12 +91,21 @@ gcov_rewrite (void)
 }
 #endif
 
+/* Return VALUE with its bytes in reverse order.  */
+
+static inline gcov_unsigned_t
+gcov_bswap32 (gcov_unsigned_t value)
+{
+  return ((value >> 24) | ((value >> 8) & 0xff00)
+         | ((value << 8) & 0xff0000) | (value << 24));
+}
+
 static inline gcov_unsigned_t
 from_file (gcov_unsigned_t value)
 {
 #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
   if (gcov_var.endian)
-    return __builtin_bswap32 (value);
+    return gcov_bswap32 (value);
 #endif
   return value;
 }
@@ -249,7 +258,7 @@ gcov_magic (gcov_unsigned_t magic, gcov_unsigned_t expected)
   if (magic == expected)
     return 1;
 
-  if (__builtin_bswap32 (magic) == expected)
+  if (gcov_bswap32 (magic) == expected)
     {
       gcov_var.endian = 1;
       return -1;

Reply via email to