]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
x86: Add is_x86_elf
authorH.J. Lu <hjl.tools@gmail.com>
Sat, 2 Sep 2017 14:23:46 +0000 (07:23 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Sat, 2 Sep 2017 14:24:42 +0000 (07:24 -0700)
Share is_x86_elf in elf32-i386.c and elf64-x86-64.c.

* elf32-i386.c (is_i386_elf): Removed.
(elf_i386_check_relocs): Replace is_i386_elf with is_x86_elf.
(elf_i386_size_dynamic_sections): Likewise.
(elf_i386_relocate_section): Likewise.
* elf64-x86-64.c (is_x86_64_elf): Removed.
(elf_x86_64_check_relocs): Replace is_x86_64_elf with
is_x86_elf.
(elf_x86_64_size_dynamic_sections): Likewise.
(elf_x86_64_relocate_section): Likewise.
* elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
target_id.
* elfxx-x86.h (elf_x86_link_hash_table): Add target_id.
(is_x86_elf): New.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf64-x86-64.c
bfd/elfxx-x86.c
bfd/elfxx-x86.h

index efee0544f6087e440f49bc80dcd1cef18f38416d..5830e42b0f31498f24bc35f1c420f980f970db49 100644 (file)
@@ -1,3 +1,19 @@
+2017-09-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf32-i386.c (is_i386_elf): Removed.
+       (elf_i386_check_relocs): Replace is_i386_elf with is_x86_elf.
+       (elf_i386_size_dynamic_sections): Likewise.
+       (elf_i386_relocate_section): Likewise.
+       * elf64-x86-64.c (is_x86_64_elf): Removed.
+       (elf_x86_64_check_relocs): Replace is_x86_64_elf with
+       is_x86_elf.
+       (elf_x86_64_size_dynamic_sections): Likewise.
+       (elf_x86_64_relocate_section): Likewise.
+       * elfxx-x86.c (_bfd_x86_elf_link_hash_table_create): Initialize
+       target_id.
+       * elfxx-x86.h (elf_x86_link_hash_table): Add target_id.
+       (is_x86_elf): New.
+
 2017-09-02  H.J. Lu  <hongjiu.lu@intel.com>
 
        * elf32-i386.c (elf_i386_compute_jump_table_size): Removed.
index 573a8edcc91e830ca67e5a0d4e9fef494470f0b0..bc2b2191f4f759e8ba2d4599fe90f28e2ccf58a3 100644 (file)
@@ -853,11 +853,6 @@ static const struct elf_i386_backend_data elf_i386_arch_bed =
 
 #define        elf_backend_arch_data   &elf_i386_arch_bed
 
-#define is_i386_elf(bfd)                               \
-  (bfd_get_flavour (bfd) == bfd_target_elf_flavour     \
-   && elf_tdata (bfd) != NULL                          \
-   && elf_object_id (bfd) == I386_ELF_DATA)
-
 /* Return TRUE if the TLS access code sequence support transition
    from R_TYPE.  */
 
@@ -1487,8 +1482,6 @@ elf_i386_check_relocs (bfd *abfd,
   if ((sec->flags & SEC_ALLOC) == 0)
     return TRUE;
 
-  BFD_ASSERT (is_i386_elf (abfd));
-
   htab = elf_x86_hash_table (info, I386_ELF_DATA);
   if (htab == NULL)
     {
@@ -1496,6 +1489,8 @@ elf_i386_check_relocs (bfd *abfd,
       return FALSE;
     }
 
+  BFD_ASSERT (is_x86_elf (abfd, htab));
+
   /* Get the section contents.  */
   if (elf_section_data (sec)->this_hdr.contents != NULL)
     contents = elf_section_data (sec)->this_hdr.contents;
@@ -2566,7 +2561,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
       Elf_Internal_Shdr *symtab_hdr;
       asection *srel;
 
-      if (! is_i386_elf (ibfd))
+      if (! is_x86_elf (ibfd, htab))
        continue;
 
       for (s = ibfd->sections; s != NULL; s = s->next)
@@ -3005,8 +3000,6 @@ elf_i386_relocate_section (bfd *output_bfd,
   bfd_boolean is_vxworks_tls;
   unsigned plt_entry_size;
 
-  BFD_ASSERT (is_i386_elf (input_bfd));
-
   /* Skip if check_relocs failed.  */
   if (input_section->check_relocs_failed)
     return FALSE;
@@ -3014,6 +3007,9 @@ elf_i386_relocate_section (bfd *output_bfd,
   htab = elf_x86_hash_table (info, I386_ELF_DATA);
   if (htab == NULL)
     return FALSE;
+
+  BFD_ASSERT (is_x86_elf (input_bfd, htab));
+
   symtab_hdr = &elf_symtab_hdr (input_bfd);
   sym_hashes = elf_sym_hashes (input_bfd);
   local_got_offsets = elf_local_got_offsets (input_bfd);
index dcebd68c5a6fe6592756d30b2c6fbf6a9b5a998e..7a6e1f1e829ad3550e2e93e3160b713c75744a29 100644 (file)
@@ -968,11 +968,6 @@ static const struct elf_x86_64_backend_data elf_x86_64_arch_bed =
 
 #define        elf_backend_arch_data   &elf_x86_64_arch_bed
 
-#define is_x86_64_elf(bfd)                             \
-  (bfd_get_flavour (bfd) == bfd_target_elf_flavour     \
-   && elf_tdata (bfd) != NULL                          \
-   && elf_object_id (bfd) == X86_64_ELF_DATA)
-
 static bfd_boolean
 elf64_x86_64_elf_object_p (bfd *abfd)
 {
@@ -1877,8 +1872,6 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
   if ((sec->flags & SEC_ALLOC) == 0)
     return TRUE;
 
-  BFD_ASSERT (is_x86_64_elf (abfd));
-
   htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
   if (htab == NULL)
     {
@@ -1886,6 +1879,8 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
       return FALSE;
     }
 
+  BFD_ASSERT (is_x86_elf (abfd, htab));
+
   /* Get the section contents.  */
   if (elf_section_data (sec)->this_hdr.contents != NULL)
     contents = elf_section_data (sec)->this_hdr.contents;
@@ -2971,7 +2966,7 @@ elf_x86_64_size_dynamic_sections (bfd *output_bfd,
       Elf_Internal_Shdr *symtab_hdr;
       asection *srel;
 
-      if (! is_x86_64_elf (ibfd))
+      if (! is_x86_elf (ibfd, htab))
        continue;
 
       for (s = ibfd->sections; s != NULL; s = s->next)
@@ -3395,8 +3390,6 @@ elf_x86_64_relocate_section (bfd *output_bfd,
   Elf_Internal_Rela *relend;
   unsigned int plt_entry_size;
 
-  BFD_ASSERT (is_x86_64_elf (input_bfd));
-
   /* Skip if check_relocs failed.  */
   if (input_section->check_relocs_failed)
     return FALSE;
@@ -3404,6 +3397,9 @@ elf_x86_64_relocate_section (bfd *output_bfd,
   htab = elf_x86_hash_table (info, X86_64_ELF_DATA);
   if (htab == NULL)
     return FALSE;
+
+  BFD_ASSERT (is_x86_elf (input_bfd, htab));
+
   plt_entry_size = htab->plt.plt_entry_size;
   symtab_hdr = &elf_symtab_hdr (input_bfd);
   sym_hashes = elf_sym_hashes (input_bfd);
index 6b7c119393ee96eeb84f151a5bc14f2cb218cfd6..b3d241cf360b7e056c6aef159339dd487c12f379 100644 (file)
@@ -310,6 +310,7 @@ _bfd_x86_elf_link_hash_table_create (bfd *abfd)
          ret->tls_get_addr = "___tls_get_addr";
        }
     }
+  ret->target_id = bed->target_id;
 
   ret->loc_hash_table = htab_try_create (1024,
                                         _bfd_x86_elf_local_htab_hash,
index a95b5c60a2f2ef7a12fd4838d0990be2e6122561..e38313578103ab10ee4353e3287dbc06a4d6a012 100644 (file)
@@ -313,6 +313,7 @@ struct elf_x86_link_hash_table
 
   bfd_vma (*r_info) (bfd_vma, bfd_vma);
   bfd_vma (*r_sym) (bfd_vma);
+  enum elf_target_id target_id;
   unsigned int sizeof_reloc;
   unsigned int got_entry_size;
   unsigned int pointer_r_type;
@@ -386,6 +387,11 @@ struct elf_x86_plt
 #define elf_x86_compute_jump_table_size(htab) \
   ((htab)->elf.srelplt->reloc_count * (htab)->got_entry_size)
 
+#define is_x86_elf(bfd, htab)                          \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour     \
+   && elf_tdata (bfd) != NULL                          \
+   && elf_object_id (bfd) == (htab)->target_id)
+
 extern bfd_boolean _bfd_x86_elf_mkobject
   (bfd *);