Blame SOURCES/binutils-ppc-hash-insert.patch

d8cd42
diff -rup binutils.orig/gas/config/tc-ppc.c binutils-2.35/gas/config/tc-ppc.c
d8cd42
--- binutils.orig/gas/config/tc-ppc.c	2022-02-03 11:10:42.835719394 +0000
d8cd42
+++ binutils-2.35/gas/config/tc-ppc.c	2022-02-03 11:13:04.298724661 +0000
d8cd42
@@ -1738,12 +1738,12 @@ ppc_setup_opcodes (void)
d8cd42
 
d8cd42
       if ((ppc_cpu & op->flags) != 0
d8cd42
 	  && !(ppc_cpu & op->deprecated))
d8cd42
-	str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+	str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
     }
d8cd42
 
d8cd42
   if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
d8cd42
     for (op = powerpc_opcodes; op < op_end; op++)
d8cd42
-      str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+      str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
 
d8cd42
   op_end = prefix_opcodes + prefix_num_opcodes;
d8cd42
   for (op = prefix_opcodes; op < op_end; op++)
d8cd42
@@ -1772,12 +1772,12 @@ ppc_setup_opcodes (void)
d8cd42
 
d8cd42
       if ((ppc_cpu & op->flags) != 0
d8cd42
 	  && !(ppc_cpu & op->deprecated))
d8cd42
-	str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+	str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
     }
d8cd42
 
d8cd42
   if ((ppc_cpu & PPC_OPCODE_ANY) != 0)
d8cd42
     for (op = prefix_opcodes; op < op_end; op++)
d8cd42
-      str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+      str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
 
d8cd42
   op_end = vle_opcodes + vle_num_opcodes;
d8cd42
   for (op = vle_opcodes; op < op_end; op++)
d8cd42
@@ -1807,7 +1807,7 @@ ppc_setup_opcodes (void)
d8cd42
 
d8cd42
       if ((ppc_cpu & op->flags) != 0
d8cd42
 	  && !(ppc_cpu & op->deprecated))
d8cd42
-	str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+	str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
     }
d8cd42
 
d8cd42
   /* SPE2 instructions */
d8cd42
@@ -1841,11 +1841,11 @@ ppc_setup_opcodes (void)
d8cd42
 	    }
d8cd42
 
d8cd42
 	  if ((ppc_cpu & op->flags) != 0 && !(ppc_cpu & op->deprecated))
d8cd42
-	    str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+	    str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
 	}
d8cd42
 
d8cd42
       for (op = spe2_opcodes; op < op_end; op++)
d8cd42
-	str_hash_insert (ppc_hash, op->name, (void *) op);
d8cd42
+	str_hash_insert_or_replace (ppc_hash, op->name, (void *) op, 0);
d8cd42
     }
d8cd42
 
d8cd42
   /* Insert the macros into a hash table.  */
d8cd42
diff -rup binutils.orig/gas/hash.c binutils-2.35/gas/hash.c
d8cd42
--- binutils.orig/gas/hash.c	2022-02-03 11:10:42.827719448 +0000
d8cd42
+++ binutils-2.35/gas/hash.c	2022-02-03 11:12:00.506175797 +0000
d8cd42
@@ -32,6 +32,24 @@ htab_insert (htab_t htab, PTR element)
d8cd42
   *slot = element;
d8cd42
 }
d8cd42
 
d8cd42
+void **
d8cd42
+htab_insert_or_replace (htab_t htab, void *element, int replace)
d8cd42
+{
d8cd42
+  void **slot = htab_find_slot (htab, element, INSERT);
d8cd42
+  if (*slot != NULL)
d8cd42
+    {
d8cd42
+      if (replace)
d8cd42
+	{
d8cd42
+	  if (htab->del_f)
d8cd42
+	    (*htab->del_f) (*slot);
d8cd42
+	  *slot = element;
d8cd42
+	}
d8cd42
+      return slot;
d8cd42
+    }
d8cd42
+  *slot = element;
d8cd42
+  return NULL;
d8cd42
+}
d8cd42
+
d8cd42
 /* Print statistics about a hash table.  */
d8cd42
 
d8cd42
 void
d8cd42
diff -rup binutils.orig/gas/hash.h binutils-2.35/gas/hash.h
d8cd42
--- binutils.orig/gas/hash.h	2022-02-03 11:10:42.830719428 +0000
d8cd42
+++ binutils-2.35/gas/hash.h	2022-02-03 11:12:25.002002561 +0000
d8cd42
@@ -103,6 +103,19 @@ str_hash_insert (htab_t table, const cha
d8cd42
   htab_insert (table, string_tuple_alloc (key, value));
d8cd42
 }
d8cd42
 
d8cd42
+extern void ** htab_insert_or_replace (htab_t, void *, int);
d8cd42
+
d8cd42
+static inline void **
d8cd42
+str_hash_insert_or_replace (htab_t table, const char *key, void *value, int replace)
d8cd42
+{
d8cd42
+  string_tuple_t *elt = string_tuple_alloc (key, value);
d8cd42
+  void **slot = htab_insert_or_replace (table, elt, replace);
d8cd42
+  if (slot && !replace)
d8cd42
+    free (elt);
d8cd42
+  return slot;
d8cd42
+}
d8cd42
+
d8cd42
+
d8cd42
 static inline htab_t
d8cd42
 str_htab_create (void)
d8cd42
 {