[PATCH v4 6/7] Support different fragment ordering in frag_offset_ignore_align_p

Evgeny Karpov evgeny@kmaps.co
Thu Aug 14 22:50:50 GMT 2025


This patch extends frag_offset_ignore_align_p to support different fragment
order in the same way it is done in frag_offset_fixed_p.

gas/ChangeLog:

	* frags.c (frag_offset_ignore_align_p): Update.
---
 gas/frags.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/gas/frags.c b/gas/frags.c
index 0ad1240a7bd..96683505565 100644
--- a/gas/frags.c
+++ b/gas/frags.c
@@ -456,8 +456,8 @@ frag_offset_fixed_p (const fragS *frag1, const
fragS *frag2, offsetT *offset)
   return false;
 }

-/* Return TRUE if FRAG2 follows FRAG1 with a fixed relationship
-   between the two assuming alignment frags do nothing.  Set OFFSET to
+/* Return TRUE if FRAG1 and FRAG2 have a fixed relationship between
+   their start addresses assuming alignment frags do nothing.  Set OFFSET to
    the difference in address not already accounted for in the frag
    FR_ADDRESS.  */

@@ -495,6 +495,25 @@ frag_offset_ignore_align_p (const fragS *frag1,
const fragS *frag2,
 	}
     }

+  /* Maybe frag1 is after frag2.  */
+  off = frag1->fr_address - frag2->fr_address;
+  frag = frag2;
+  while (frag->fr_type == rs_fill
+	 || frag->fr_type == rs_align
+	 || frag->fr_type == rs_align_code
+	 || frag->fr_type == rs_align_test)
+    {
+      off -= frag->fr_fix + frag->fr_offset * frag->fr_var;
+      frag = frag->fr_next;
+      if (frag == NULL)
+	break;
+      if (frag == frag1)
+	{
+	  *offset = off;
+	  return true;
+	}
+    }
+
   return false;
 }

-- 
2.39.5


More information about the Binutils mailing list