public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
* [binutils-gdb] libsframe: write out SFrame FRE start address correctly
@ 2022-12-25  8:18 Indu Bhagat
  0 siblings, 0 replies; only message in thread
From: Indu Bhagat @ 2022-12-25  8:18 UTC (permalink / raw)
  To: bfd-cvs, gdb-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=68bb0d2765abfdcd9f2b29311c60b5472f0b1a24

commit 68bb0d2765abfdcd9f2b29311c60b5472f0b1a24
Author: Indu Bhagat <indu.bhagat@oracle.com>
Date:   Sun Dec 25 00:06:22 2022 -0800

    libsframe: write out SFrame FRE start address correctly
    
    The following test was failing on ppc64 and s390x:
      "FAIL: encode-1: Encode buffer match"
    
    The offending stub was how we memcpy the FRE start address to the buffer
    (on-disk format).  When the host is big-endian, the address of the
    source buffer for the memcpy needs to point to the uint8_t/uint16_t sized
    value of the FRE start addr, not uint32_t sized value; we intend to copy
    out only the fre_start_addr_sz number of bytes.
    
    ChangeLog:
    
            * libsframe/sframe.c (sframe_encoder_write_fre_start_addr): New
            function.
            (sframe_encoder_write_fre): Use it instead of memcpy.

Diff:
---
 libsframe/sframe.c | 38 +++++++++++++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)

diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index e41c95b9944..c9123404ea7 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -1502,6 +1502,39 @@ sframe_sort_funcdesc (sframe_encoder_ctx *encoder)
   return 0;
 }
 
+/* Write the SFrame FRE start address from the in-memory FRE_START_ADDR
+   to the buffer CONTENTS (on-disk format), given the FRE_TYPE and
+   FRE_START_ADDR_SZ.  */
+
+static int
+sframe_encoder_write_fre_start_addr (char *contents,
+				     uint32_t fre_start_addr,
+				     unsigned int fre_type,
+				     size_t fre_start_addr_sz)
+{
+  int err = 0;
+
+  if (fre_type == SFRAME_FRE_TYPE_ADDR1)
+    {
+      uint8_t uc = fre_start_addr;
+      memcpy (contents, &uc, fre_start_addr_sz);
+    }
+  else if (fre_type == SFRAME_FRE_TYPE_ADDR2)
+    {
+      uint16_t ust = fre_start_addr;
+      memcpy (contents, &ust, fre_start_addr_sz);
+    }
+  else if (fre_type == SFRAME_FRE_TYPE_ADDR4)
+    {
+      uint32_t uit = fre_start_addr;
+      memcpy (contents, &uit, fre_start_addr_sz);
+    }
+  else
+    return sframe_set_errno (&err, SFRAME_ERR_INVAL);
+
+  return 0;
+}
+
 /* Write a frame row entry pointed to by FREP into the buffer CONTENTS.  The
    size in bytes written out are updated in ESZ.
 
@@ -1529,9 +1562,8 @@ sframe_encoder_write_fre (char *contents, sframe_frame_row_entry *frep,
   uint64_t bitmask = SFRAME_BITMASK_OF_SIZE (fre_start_addr_sz);
   sframe_assert ((uint64_t)frep->fre_start_addr <= bitmask);
 
-  memcpy (contents,
-	  &frep->fre_start_addr,
-	  fre_start_addr_sz);
+  sframe_encoder_write_fre_start_addr (contents, frep->fre_start_addr,
+				       fre_type, fre_start_addr_sz);
   contents += fre_start_addr_sz;
 
   memcpy (contents,

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-12-25  8:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-25  8:18 [binutils-gdb] libsframe: write out SFrame FRE start address correctly Indu Bhagat

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).