Blame SOURCES/binutils-CIE-generation.patch

d02871
--- binutils.orig/gas/dw2gencfi.c	2022-09-08 13:54:05.539276706 +0100
d02871
+++ binutils-2.35.2/gas/dw2gencfi.c	2022-09-08 14:05:56.128016840 +0100
d02871
@@ -2054,6 +2054,64 @@ output_fde (struct fde_entry *fde, struc
d02871
   symbol_set_value_now (end_address);
d02871
 }
d02871
 
d02871
+/* Allow these insns to be put in the initial sequence of a CIE.
d02871
+   If J is non-NULL, then compare I and J insns for a match.  */
d02871
+
d02871
+static inline bfd_boolean
d02871
+initial_cie_insn (const struct cfi_insn_data *i, const struct cfi_insn_data *j)
d02871
+{
d02871
+  if (j && i->insn != j->insn)
d02871
+    return FALSE;
d02871
+
d02871
+  switch (i->insn)
d02871
+    {
d02871
+    case DW_CFA_offset:
d02871
+    case DW_CFA_def_cfa:
d02871
+    case DW_CFA_val_offset:
d02871
+      if (j)
d02871
+	{
d02871
+	  if (i->u.ri.reg != j->u.ri.reg)
d02871
+	    return FALSE;
d02871
+	  if (i->u.ri.offset != j->u.ri.offset)
d02871
+	    return FALSE;
d02871
+	}
d02871
+      break;
d02871
+
d02871
+    case DW_CFA_register:
d02871
+      if (j)
d02871
+	{
d02871
+	  if (i->u.rr.reg1 != j->u.rr.reg1)
d02871
+	    return FALSE;
d02871
+	  if (i->u.rr.reg2 != j->u.rr.reg2)
d02871
+	    return FALSE;
d02871
+	}
d02871
+      break;
d02871
+
d02871
+    case DW_CFA_def_cfa_register:
d02871
+    case DW_CFA_restore:
d02871
+    case DW_CFA_undefined:
d02871
+    case DW_CFA_same_value:
d02871
+      if (j)
d02871
+	{
d02871
+	  if (i->u.r != j->u.r)
d02871
+	    return FALSE;
d02871
+	}
d02871
+      break;
d02871
+
d02871
+    case DW_CFA_def_cfa_offset:
d02871
+      if (j)
d02871
+	{
d02871
+	  if (i->u.i != j->u.i)
d02871
+	    return FALSE;
d02871
+	}
d02871
+      break;
d02871
+
d02871
+    default:
d02871
+      return FALSE;
d02871
+    }
d02871
+  return TRUE;
d02871
+}
d02871
+
d02871
 static struct cie_entry *
d02871
 select_cie_for_fde (struct fde_entry *fde, bfd_boolean eh_frame,
d02871
 		    struct cfi_insn_data **pfirst, int align)
d02871
@@ -2099,71 +2157,15 @@ select_cie_for_fde (struct fde_entry *fd
d02871
 	   i != cie->last && j != NULL;
d02871
 	   i = i->next, j = j->next)
d02871
 	{
d02871
-	  if (i->insn != j->insn)
d02871
-	    goto fail;
d02871
-	  switch (i->insn)
d02871
-	    {
d02871
-	    case DW_CFA_advance_loc:
d02871
-	    case DW_CFA_remember_state:
d02871
-	      /* We reached the first advance/remember in the FDE,
d02871
-		 but did not reach the end of the CIE list.  */
d02871
-	      goto fail;
d02871
-
d02871
-	    case DW_CFA_offset:
d02871
-	    case DW_CFA_def_cfa:
d02871
-	      if (i->u.ri.reg != j->u.ri.reg)
d02871
-		goto fail;
d02871
-	      if (i->u.ri.offset != j->u.ri.offset)
d02871
-		goto fail;
d02871
-	      break;
d02871
-
d02871
-	    case DW_CFA_register:
d02871
-	      if (i->u.rr.reg1 != j->u.rr.reg1)
d02871
-		goto fail;
d02871
-	      if (i->u.rr.reg2 != j->u.rr.reg2)
d02871
-		goto fail;
d02871
-	      break;
d02871
-
d02871
-	    case DW_CFA_def_cfa_register:
d02871
-	    case DW_CFA_restore:
d02871
-	    case DW_CFA_undefined:
d02871
-	    case DW_CFA_same_value:
d02871
-	      if (i->u.r != j->u.r)
d02871
-		goto fail;
d02871
-	      break;
d02871
-
d02871
-	    case DW_CFA_def_cfa_offset:
d02871
-	      if (i->u.i != j->u.i)
d02871
-		goto fail;
d02871
-	      break;
d02871
-
d02871
-	    case CFI_escape:
d02871
-	    case CFI_val_encoded_addr:
d02871
-	    case CFI_label:
d02871
-	      /* Don't bother matching these for now.  */
d02871
-	      goto fail;
d02871
-
d02871
-	    default:
d02871
-	      abort ();
d02871
-	    }
d02871
+	  if (!initial_cie_insn (i, j))
d02871
+	    break;
d02871
 	}
d02871
 
d02871
-      /* Success if we reached the end of the CIE list, and we've either
d02871
-	 run out of FDE entries or we've encountered an advance,
d02871
-	 remember, or escape.  */
d02871
-      if (i == cie->last
d02871
-	  && (!j
d02871
-	      || j->insn == DW_CFA_advance_loc
d02871
-	      || j->insn == DW_CFA_remember_state
d02871
-	      || j->insn == CFI_escape
d02871
-	      || j->insn == CFI_val_encoded_addr
d02871
-	      || j->insn == CFI_label))
d02871
+      if (i == cie->last)
d02871
 	{
d02871
 	  *pfirst = j;
d02871
 	  return cie;
d02871
 	}
d02871
-
d02871
-    fail:;
d02871
     }
d02871
 
d02871
   cie = XNEW (struct cie_entry);
d02871
@@ -2181,11 +2183,7 @@ select_cie_for_fde (struct fde_entry *fd
d02871
 #endif
d02871
 
d02871
   for (i = cie->first; i ; i = i->next)
d02871
-    if (i->insn == DW_CFA_advance_loc
d02871
-	|| i->insn == DW_CFA_remember_state
d02871
-	|| i->insn == CFI_escape
d02871
-	|| i->insn == CFI_val_encoded_addr
d02871
-	|| i->insn == CFI_label)
d02871
+    if (!initial_cie_insn (i, NULL))
d02871
       break;
d02871
 
d02871
   cie->last = i;