[binutils-gdb] libsframe misaligned uint32_t

Alan Modra amodra@sourceware.org
Wed Jan 21 07:36:20 GMT 2026


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

commit efcfd085473e7f8f730fced9ad3934712a30de87
Author: Alan Modra <amodra@gmail.com>
Date:   Tue Jan 20 08:43:25 2026 +1030

    libsframe misaligned uint32_t
    
    I saw asan complaints about misaligned loads and stores when taking a
    quick look at pr33810 before Jens' patch was applied.  They have
    disappeared now, but it looks to me like a FRE can start on any
    address boundary and there is no padding or suchlike to align the
    FRE fields.
    
            * sframe.c (flip_fre_stack_offsets): Let the compiler know
            that integers may be misaligned.

Diff:
---
 libsframe/sframe.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/libsframe/sframe.c b/libsframe/sframe.c
index 3f76629665c..e915d363ca2 100644
--- a/libsframe/sframe.c
+++ b/libsframe/sframe.c
@@ -402,21 +402,21 @@ flip_fre_start_address (void *addr, uint32_t fre_type)
 }
 
 static void
-flip_fre_stack_offsets (char *offsets, uint8_t offset_size, uint8_t offset_cnt)
+flip_fre_stack_offsets (void *offsets, uint8_t offset_size, uint8_t offset_cnt)
 {
   int j;
 
   if (offset_size == SFRAME_FRE_OFFSET_2B)
     {
-      uint16_t *ust = (uint16_t *)offsets;
-      for (j = offset_cnt; j > 0; ust++, j--)
-	swap_thing (*ust);
+      struct { uint16_t x; } ATTRIBUTE_PACKED *p = offsets;
+      for (j = offset_cnt; j > 0; p++, j--)
+	swap_thing (p->x);
     }
   else if (offset_size == SFRAME_FRE_OFFSET_4B)
     {
-      uint32_t *uit = (uint32_t *)offsets;
-      for (j = offset_cnt; j > 0; uit++, j--)
-	swap_thing (*uit);
+      struct { uint32_t x; } ATTRIBUTE_PACKED *p = offsets;
+      for (j = offset_cnt; j > 0; p++, j--)
+	swap_thing (p->x);
     }
 }


More information about the Binutils-cvs mailing list