[v2,3/3] bfd/ELF/x86: avoid layering violation in link hash table entry init

Message ID 2250ab62-8f0c-4672-a92f-ba31b8d90018@suse.com
State New
Headers
Series PE/COFF: function size (and fallout) |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed

Commit Message

Jan Beulich April 7, 2025, 1:54 p.m. UTC
  There's no reason not to do as the comment says, just like all other
architectures do when they need custom field: Call the allocation method
of the "superclass". Which is the ELF one, of which in turn the BFD one
is the "superclass", dealt with accordingly by
_bfd_elf_link_hash_newfunc().
---
v2: New.
  

Patch

--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -609,8 +609,7 @@  _bfd_elf_x86_get_local_sym_hash (struct
   return &ret->elf;
 }
 
-/* Create an entry in a x86 ELF linker hash table.  NB: THIS MUST BE IN
-   SYNC WITH _bfd_elf_link_hash_newfunc.  */
+/* Create an entry in an x86 ELF linker hash table.  */
 
 struct bfd_hash_entry *
 _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
@@ -629,27 +628,14 @@  _bfd_x86_elf_link_hash_newfunc (struct b
     }
 
   /* Call the allocation method of the superclass.  */
-  entry = _bfd_link_hash_newfunc (entry, table, string);
+  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
   if (entry != NULL)
     {
       struct elf_x86_link_hash_entry *eh
        = (struct elf_x86_link_hash_entry *) entry;
-      struct elf_link_hash_table *htab
-	= (struct elf_link_hash_table *) table;
 
-      memset (&eh->elf.size, 0,
-	      (sizeof (struct elf_x86_link_hash_entry)
-	       - offsetof (struct elf_link_hash_entry, size)));
+      memset (&eh->elf + 1, 0, sizeof (*eh) - sizeof (eh->elf));
       /* Set local fields.  */
-      eh->elf.indx = -1;
-      eh->elf.dynindx = -1;
-      eh->elf.got = htab->init_got_refcount;
-      eh->elf.plt = htab->init_plt_refcount;
-      /* Assume that we have been called by a non-ELF symbol reader.
-	 This flag is then reset by the code which reads an ELF input
-	 file.  This ensures that a symbol created by a non-ELF symbol
-	 reader will have the flag set correctly.  */
-      eh->elf.non_elf = 1;
       eh->plt_second.offset = (bfd_vma) -1;
       eh->plt_got.offset = (bfd_vma) -1;
       eh->tlsdesc_got = (bfd_vma) -1;