Blame SOURCES/binutils-CIE-generation.patch

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