public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libsframe: write out SFrame FRE start address correctly
@ 2022-12-24 19:40 Indu Bhagat
  0 siblings, 0 replies; only message in thread
From: Indu Bhagat @ 2022-12-24 19:40 UTC (permalink / raw)
  To: binutils; +Cc: Indu Bhagat

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 src address of the
buffer 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.
---
 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,
-- 
2.37.2


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

only message in thread, other threads:[~2022-12-24 19:40 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-24 19:40 [PATCH] 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).