]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gprofng: need to know that experiment was created on big-endian machine
authorVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Thu, 26 Jun 2025 04:25:02 +0000 (21:25 -0700)
committerVladimir Mezentsev <vladimir.mezentsev@oracle.com>
Thu, 26 Jun 2025 17:43:50 +0000 (10:43 -0700)
gprofng/ChangeLog
2025-06-25  Vladimir Mezentsev  <vladimir.mezentsev@oracle.com>

* configure.ac: Add AC_C_BIGENDIAN.
* common/config.h.in: Rebuild.
* configure: Rebuild.
* libcollector/collector.c (log_header_write): Save big-endian flag.
* src/DbeSession.h (is_bigendian): New function.
* src/DbeSession.cc: Likewise.
* src/Experiment.cc: Set 'bigendian' and 'need_swap_endian'.
* src/Experiment.h: New field 'bigendian'.
* src/LoadObject.cc: Remove an unused variable.
* src/LoadObject.h: Likewise.

gprofng/common/config.h.in
gprofng/configure
gprofng/configure.ac
gprofng/libcollector/collector.c
gprofng/src/DbeSession.cc
gprofng/src/DbeSession.h
gprofng/src/Experiment.cc
gprofng/src/Experiment.h
gprofng/src/LoadObject.cc
gprofng/src/LoadObject.h

index f8484f238fd54d1b61847c0fc3a30aa751220a3a..aabb043957af258beedf7752d958ef5552d0ae4b 100644 (file)
@@ -1,5 +1,8 @@
 /* common/config.h.in.  Generated from configure.ac by autoheader.  */
 
+/* Define if building universal (internal helper macro) */
+#undef AC_APPLE_UNIVERSAL_BUILD
+
 /* Enable debugging output. */
 #undef DEBUG
 
 /* Version number of package */
 #undef VERSION
 
+/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
+   significant byte first (like Motorola and SPARC, unlike Intel). */
+#if defined AC_APPLE_UNIVERSAL_BUILD
+# if defined __BIG_ENDIAN__
+#  define WORDS_BIGENDIAN 1
+# endif
+#else
+# ifndef WORDS_BIGENDIAN
+#  undef WORDS_BIGENDIAN
+# endif
+#endif
+
 /* Define to 1 if on MINIX. */
 #undef _MINIX
 
index 3f408634ca53c419333a524714632b12b56c3871..2edfff107dd5334ed35007febd28ba5f25bde207 100755 (executable)
@@ -15623,6 +15623,230 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 # Only expand once:
 
 
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether byte ordering is bigendian" >&5
+$as_echo_n "checking whether byte ordering is bigendian... " >&6; }
+if ${ac_cv_c_bigendian+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_cv_c_bigendian=unknown
+    # See if we're dealing with a universal compiler.
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#ifndef __APPLE_CC__
+              not a universal capable compiler
+            #endif
+            typedef int dummy;
+
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+       # Check for potential -arch flags.  It is not universal unless
+       # there are at least two -arch flags with different values.
+       ac_arch=
+       ac_prev=
+       for ac_word in $CC $CFLAGS $CPPFLAGS $LDFLAGS; do
+        if test -n "$ac_prev"; then
+          case $ac_word in
+            i?86 | x86_64 | ppc | ppc64)
+              if test -z "$ac_arch" || test "$ac_arch" = "$ac_word"; then
+                ac_arch=$ac_word
+              else
+                ac_cv_c_bigendian=universal
+                break
+              fi
+              ;;
+          esac
+          ac_prev=
+        elif test "x$ac_word" = "x-arch"; then
+          ac_prev=arch
+        fi
+       done
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if sys/param.h defines the BYTE_ORDER macro.
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+            #include <sys/param.h>
+
+int
+main ()
+{
+#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
+                    && defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
+                    && LITTLE_ENDIAN)
+             bogus endian macros
+            #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  # It does; now see whether it defined to BIG_ENDIAN or not.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/types.h>
+               #include <sys/param.h>
+
+int
+main ()
+{
+#if BYTE_ORDER != BIG_ENDIAN
+                not big endian
+               #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_bigendian=yes
+else
+  ac_cv_c_bigendian=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
+      cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <limits.h>
+
+int
+main ()
+{
+#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
+             bogus endian macros
+            #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  # It does; now see whether it defined to _BIG_ENDIAN or not.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <limits.h>
+
+int
+main ()
+{
+#ifndef _BIG_ENDIAN
+                not big endian
+               #endif
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_c_bigendian=yes
+else
+  ac_cv_c_bigendian=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+    fi
+    if test $ac_cv_c_bigendian = unknown; then
+      # Compile a test program.
+      if test "$cross_compiling" = yes; then :
+  # Try to guess by grepping values from an object file.
+        cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+short int ascii_mm[] =
+                 { 0x4249, 0x4765, 0x6E44, 0x6961, 0x6E53, 0x7953, 0 };
+               short int ascii_ii[] =
+                 { 0x694C, 0x5454, 0x656C, 0x6E45, 0x6944, 0x6E61, 0 };
+               int use_ascii (int i) {
+                 return ascii_mm[i] + ascii_ii[i];
+               }
+               short int ebcdic_ii[] =
+                 { 0x89D3, 0xE3E3, 0x8593, 0x95C5, 0x89C4, 0x9581, 0 };
+               short int ebcdic_mm[] =
+                 { 0xC2C9, 0xC785, 0x95C4, 0x8981, 0x95E2, 0xA8E2, 0 };
+               int use_ebcdic (int i) {
+                 return ebcdic_mm[i] + ebcdic_ii[i];
+               }
+               extern int foo;
+
+int
+main ()
+{
+return use_ascii (foo) == use_ebcdic (foo);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  if grep BIGenDianSyS conftest.$ac_objext >/dev/null; then
+             ac_cv_c_bigendian=yes
+           fi
+           if grep LiTTleEnDian conftest.$ac_objext >/dev/null ; then
+             if test "$ac_cv_c_bigendian" = unknown; then
+               ac_cv_c_bigendian=no
+             else
+               # finding both strings is unlikely to happen, but who knows?
+               ac_cv_c_bigendian=unknown
+             fi
+           fi
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+$ac_includes_default
+int
+main ()
+{
+
+            /* Are we little or big endian?  From Harbison&Steele.  */
+            union
+            {
+              long int l;
+              char c[sizeof (long int)];
+            } u;
+            u.l = 1;
+            return u.c[sizeof (long int) - 1] == 1;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  ac_cv_c_bigendian=no
+else
+  ac_cv_c_bigendian=yes
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+    fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_c_bigendian" >&5
+$as_echo "$ac_cv_c_bigendian" >&6; }
+ case $ac_cv_c_bigendian in #(
+   yes)
+     $as_echo "#define WORDS_BIGENDIAN 1" >>confdefs.h
+;; #(
+   no)
+      ;; #(
+   universal)
+
+$as_echo "#define AC_APPLE_UNIVERSAL_BUILD 1" >>confdefs.h
+
+     ;; #(
+   *)
+     as_fn_error $? "unknown endianness
+ presetting ac_cv_c_bigendian=no (or yes) will help" "$LINENO" 5 ;;
+ esac
+
 
 GPROFNG_LIBADD="-L../../libiberty -liberty"
 if test "$enable_shared" = "yes"; then
@@ -17145,6 +17369,7 @@ if test -z "${am__fastdepCXX_TRUE}" && test -z "${am__fastdepCXX_FALSE}"; then
   as_fn_error $? "conditional \"am__fastdepCXX\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+
 if test -z "${BUILD_COLLECTOR_TRUE}" && test -z "${BUILD_COLLECTOR_FALSE}"; then
   as_fn_error $? "conditional \"BUILD_COLLECTOR\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
index d7a2c386d103e7bc1cac4451f8f370671a586938..1f473b9b5833b859b940e1dfc0130726a16b0236 100644 (file)
@@ -33,6 +33,7 @@ gl_PROG_BISON([BISON],[3.0.4])
 
 AC_DISABLE_SHARED
 LT_INIT
+AC_C_BIGENDIAN
 
 GPROFNG_LIBADD="-L../../libiberty -liberty"
 if test "$enable_shared" = "yes"; then
index c5fa3cbb30e85ccba9fd0fc45e3d51bdfe94716f..3bb3fc3cfff3213e81b41dce7d99b420cda9b4e0 100644 (file)
@@ -2051,8 +2051,15 @@ log_header_write (sp_origin_t origin)
     {
       long page_size = CALL_UTIL (sysconf)(_SC_PAGESIZE);
       long npages = CALL_UTIL (sysconf)(_SC_PHYS_PAGES);
-      __collector_log_write ("<system hostname=\"%s\" arch=\"%s\" os=\"%s %s\" pagesz=\"%ld\" npages=\"%ld\">\n",
-                            sysinfo.nodename, sysinfo.machine, sysinfo.sysname, sysinfo.release, page_size, npages);
+#ifdef WORDS_BIGENDIAN
+      int bigendian = 1;
+#else
+      int bigendian = 0;
+#endif
+      __collector_log_write ("<system hostname=\"%s\" arch=\"%s\" os=\"%s %s\" "
+               "pagesz=\"%ld\" npages=\"%ld\" bigendian=\"%d\">\n",
+               sysinfo.nodename, sysinfo.machine, sysinfo.sysname,
+               sysinfo.release, page_size, npages, bigendian);
     }
 
   //YXXX Updating this section?  Check similar cut/paste code in:
index f3426cefd3158beea9e97c7d14afa925a1305ac7..b0aa74552536dd015880adbbcd8fc6b5e1277f8a 100644 (file)
@@ -2016,6 +2016,17 @@ DbeSession::is_omp_available ()
   return status_ompavail == 1;
 }
 
+bool
+DbeSession::is_bigendian ()
+{
+#ifdef WORDS_BIGENDIAN
+  return true;
+#else
+  return false;
+#endif
+
+}
+
 bool
 DbeSession::has_java ()
 {
index 5cbddae4c924889b41618822775b6dd2de1017df..7db0998cfbb9a32e4d76796dbe397c3ffe21839f 100644 (file)
@@ -120,6 +120,7 @@ public:
   bool is_timeline_available ();
   bool is_ifreq_available ();
   bool is_omp_available ();
+  static bool is_bigendian ();
   bool has_java ();
   bool has_ompavail ();
 
index 45550e8d38ff918c579121cabe0ced2b24f9e339..4cbb7f6d33bf4cdd828d3d60273ace54a19a51af 100644 (file)
@@ -541,10 +541,14 @@ Experiment::ExperimentHandler::startElement (char*, char*, char *qName, Attribut
            exp->platform = RISCV;
          else
            exp->platform = Sparc;
-         exp->need_swap_endian = (DbeSession::platform == Sparc) ?
-                 (exp->platform != Sparc) : (exp->platform == Sparc);
          exp->architecture = xstrdup (str);
        }
+      str = attrs->getValue (NTXT ("bigendian"));
+      if (str != NULL)
+       {
+         exp->bigendian = *str == '1';
+         exp->need_swap_endian = DbeSession::is_bigendian () != exp->bigendian;
+       }
       str = attrs->getValue (NTXT ("pagesz"));
       if (str != NULL)
        exp->page_size = atoi (str);
@@ -1314,6 +1318,7 @@ Experiment::Experiment ()
   exp_maj_version = 0;
   exp_min_version = 0;
   platform = Unknown;
+  bigendian = DbeSession::is_bigendian();  // can be changed in log.xml reading
   wsize = Wnone;
   page_size = 4096;
   npages = 0;
index 2047a15f1c47faf180f446e4d733c58af272c507..c85aadd5181f3a26a8b1e45b90def4459964d384 100644 (file)
@@ -135,6 +135,7 @@ public:
                        // for current experiment, i.e. 8 for 32bit addresses
   int broken;           // If SP_JCMD_RUN line not seen
   int obsolete;         // If pointer file experiment detected
+  bool bigendian;       // the experiment was created on a big_endian machine
   bool hwc_default;     // True if HW counters were enabled by default
   int hwc_bogus;        // Count of bogus HWC packets
   int hwc_lost_int;     // Count of packets reflecting lost interrupt
index 3cdeb9d3e7b79bf05da10e7df08b31a21368d840..bf49e9d24a851ef8e94b8ed0010bf2703bb157ed 100644 (file)
@@ -87,7 +87,6 @@ LoadObject::LoadObject (const char *loname)
   size = 0;
   type = SEG_UNKNOWN;
   isReadStabs = false;
-  need_swap_endian = false;
   instHTable = new DbeInstr*[LO_InstHTableSize];
   for (int i = 0; i < LO_InstHTableSize; i++)
     instHTable[i] = NULL;
index 14dfe2682a9df45bec4055bfcbda4613148b1281..dd40ea0a050c1cf53d22f7535e102f1c29c8015d 100644 (file)
@@ -167,7 +167,6 @@ public:
 
   unsigned int flags;           // SEG_FLAG_*
   bool isReadStabs;
-  bool need_swap_endian;
   int seg_idx;                  // for compatibility (ADDRESS)
   seg_type type;
   int64_t size;                 // size of loadobject in bytes