]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
sframe: Ignore section padding when converting endianness
authorJens Remus <jremus@linux.ibm.com>
Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)
committerJens Remus <jremus@linux.ibm.com>
Fri, 11 Jul 2025 08:29:40 +0000 (10:29 +0200)
The .sframe section may have a trailing padding due to the architecture-
specific default section alignment.  Do not treat this padding as error
when converting between target and host endianness.

This can be observed when building Binutils with SFrame s390x support on
x86-64 for s390x using configure option "--target=s390x-ibm-linux-gnu"
and running the GAS test suite.

While at it reuse the determined SFrame section header size.

libsframe/
* sframe.c (flip_sframe): Ignore .sframe section padding.  Reuse
SFrame header size.

Reported-by: Indu Bhagat <indu.bhagat@oracle.com>
Signed-off-by: Jens Remus <jremus@linux.ibm.com>
libsframe/sframe.c

index ea0e1c7cd23096344aaa550f933de6e2c85588a9..977abf5ef0a1e29667d8390ebc952d811e7d0b84 100644 (file)
@@ -520,7 +520,7 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign)
          fre_offset = fdep->sfde_func_start_fre_off;
        }
 
-      fp = frame_buf + sframe_get_hdr_size (ihp) + ihp->sfh_freoff;
+      fp = frame_buf + hdrsz + ihp->sfh_freoff;
       fp += fre_offset;
       for (; j < prev_frep_index + num_fres; j++)
        {
@@ -535,8 +535,12 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign)
       prev_frep_index = j;
     }
   /* All FDEs and FREs must have been endian flipped by now.  */
-  if ((j != ihp->sfh_num_fres) || (bytes_flipped != (buf_size - hdrsz)))
+  if ((j != ihp->sfh_num_fres) || (bytes_flipped > (buf_size - hdrsz)))
     goto bad;
+  /* Optional trailing section padding.  */
+  for (fp = frame_buf + hdrsz + bytes_flipped; fp < frame_buf + buf_size; fp++)
+    if (*fp != '\0')
+      goto bad;
 
   /* Success.  */
   return 0;