[PATCH] optimize handle_COMDAT

Oleg Tolmatcev oleg.tolmatcev@gmail.com
Sat Apr 29 12:39:00 GMT 2023


Thanks for the review. Here is a new version.

---
 bfd/coffcode.h   | 448 +++++++++++++++++++++++-------
-----------------
 bfd/libcoff-in.h |  11 ++
 bfd/peicode.h    |  21 +++
 3 files changed, 256 insertions(+), 224 deletions(-)

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 594f3e0457..ab11e957e9 100644
+      insert_flags (pe_data (abfd)->flags_hash, symname, isym.n_scnum,
+                    sec_flags, (esym - esymstart) / bfd_coff_symesz (abfd));
+  if (htab_elements (pe_data (abfd)->flags_hash) == 0)
+    fill_flags_hash (abfd, hdr);
+
+  struct flags_entry *found
+      = find_flags (pe_data (abfd)->flags_hash, name, section->target_index);
+          found = find_flags (pe_data (abfd)->flags_hash,
target_name_underscore,
+                              section->target_index);
+          free (target_name_underscore);
+#else
+          found = find_flags (pe_data (abfd)->flags_hash, target_name,
+                              section->target_index);
+#endif
+        }
+      /* Is this the name we're looking for ?  */
+      if (found != NULL)
+        {
+          insert_coff_comdat_info (abfd, section, found->name, found->symbol);
+          return sec_flags | found->sec_flags;
+        }
     }
-
- breakloop:
-  return sec_flags;
+  return sec_flags | SEC_LINK_ONCE;
 }


diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h
index a0d286d37f..cdd504605b 100644
--- a/bfd/libcoff-in.h
+++ b/bfd/libcoff-in.h
@@ -24,6 +24,7 @@

 #include "bfdlink.h"
 #include "coff-bfd.h"
+#include "hashtab.h"

 #ifdef __cplusplus
 extern "C" {
@@ -153,10 +154,20 @@ typedef struct pe_tdata
     const char *style;
     asection *sec;
   } build_id;
+
+    htab_t flags_hash;
 } pe_data_type;

 #define pe_data(bfd)        ((bfd)->tdata.pe_obj_data)

+struct flags_entry
+{
+  flagword sec_flags;
+  const char *name;
+  int target_index;
+  long symbol;
+};
+
 /* Tdata for XCOFF files.  */

 struct xcoff_tdata
diff --git a/bfd/peicode.h b/bfd/peicode.h
index e2e2be65b5..df1e678b5a 100644
--- a/bfd/peicode.h
+++ b/bfd/peicode.h
@@ -255,6 +255,25 @@ coff_swap_scnhdr_in (bfd * abfd, void * ext, void * in)
 #endif
 }

+static hashval_t
+htab_hash_flags (const void *entry)
+{
+  const struct flags_entry *fe = entry;
+  hashval_t h = 0;
+  h = iterative_hash (fe->name, strlen (fe->name), h);
+  h = iterative_hash_object (fe->target_index, h);
+  return h;
+}
+
+static int
+htab_eq_flags (const void *e1, const void *e2)
+{
+  const struct flags_entry *fe1 = e1;
+  const struct flags_entry *fe2 = e2;
+  return strcmp (fe1->name, fe2->name) == 0
+         && fe1->target_index == fe2->target_index;
+}
+
 static bool
 pe_mkobject (bfd * abfd)
 {
@@ -291,6 +310,8 @@ pe_mkobject (bfd * abfd)
   pe->dos_message[14] = 0x24;
   pe->dos_message[15] = 0x0;

+  pe->flags_hash = htab_create (10, htab_hash_flags, htab_eq_flags, NULL);
+
   memset (& pe->pe_opthdr, 0, sizeof pe->pe_opthdr);

   bfd_coff_long_section_names (abfd)
--
2.40.0.windows.1


More information about the Binutils mailing list