This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PR5692


On Fri, Feb 15, 2008 at 02:17:48PM +1030, Alan Modra wrote:
> in preparation to converting is_ppc_elf_target and similar
> functions to use the new infrastructure.

bfd/
	* elf-bfd.h (enum elf_object_id): Add HPPA_ELF_TDATA.
	* elf.c (bfd_elf_allocate_object): Don't check for already allocated
	tdata.
	* elf32-hppa.c (elf32_hppa_mkobject): New function.
	(bfd_elf32_mkobject): Define.
	* elf32-ppc.c (is_ppc_elf_target): Delete.  Replace all uses with..
	(is_ppc_elf): ..this new macro.
	* elf64-ppc.c (is_ppc64_elf_target): Delete.  Replace all uses with..
	(is_ppc64_elf): ..this new macro.
ld/
	* emultempl/alphaelf.em (alpha_after_open): Use elf_object_id.
	* emultempl/hppaelf.em (hppaelf_create_output_section_statements):
	Likewise.
	* emultempl/ppc64elf.em (ppc_create_output_section_statements):
	Likewise.
	* emultempl/ppc32elf.em (is_ppc_elf32_vec): Delete.  Replace all
	uses with..
	(is_ppc_elf): ..this new macro.

Index: bfd/elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.258
diff -u -p -r1.258 elf-bfd.h
--- bfd/elf-bfd.h	12 Feb 2008 11:32:30 -0000	1.258
+++ bfd/elf-bfd.h	15 Feb 2008 07:26:16 -0000
@@ -1401,6 +1401,7 @@ enum elf_object_id
 {
   ALPHA_ELF_TDATA = 1,
   ARM_ELF_TDATA,
+  HPPA_ELF_TDATA,
   I386_ELF_TDATA,
   PPC32_ELF_TDATA,
   PPC64_ELF_TDATA,
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.432
diff -u -p -r1.432 elf.c
--- bfd/elf.c	12 Feb 2008 11:32:30 -0000	1.432
+++ bfd/elf.c	15 Feb 2008 07:26:25 -0000
@@ -226,17 +226,13 @@ bfd_elf_gnu_hash (const char *namearg)
   return h & 0xffffffff;
 }
 
-/* If ABFD does not already have an allocated tdata field then create
-   one, OBJECT_SIZE bytes is length, zeroed out and with the object_id
-   field of an elf_obj_tdata field set to OBJECT_ID.  */
+/* Create a tdata field OBJECT_SIZE bytes in length, zeroed out and with
+   the object_id field of an elf_obj_tdata field set to OBJECT_ID.  */
 bfd_boolean
-bfd_elf_allocate_object (bfd * abfd,
+bfd_elf_allocate_object (bfd *abfd,
 			 size_t object_size,
 			 enum elf_object_id object_id)
 {
-  if (abfd->tdata.any != NULL)
-    return TRUE;
-
   BFD_ASSERT (object_size >= sizeof (struct elf_obj_tdata));
   abfd->tdata.any = bfd_zalloc (abfd, object_size);
   if (abfd->tdata.any == NULL)
Index: bfd/elf32-hppa.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-hppa.c,v
retrieving revision 1.161
diff -u -p -r1.161 elf32-hppa.c
--- bfd/elf32-hppa.c	11 Jan 2008 09:07:03 -0000	1.161
+++ bfd/elf32-hppa.c	15 Feb 2008 07:26:28 -0000
@@ -334,6 +334,15 @@ struct elf32_hppa_link_hash_table
 #define eh_name(eh) \
   (eh ? eh->root.root.string : "<undef>")
 
+/* Override the generic function because we want to mark our BFDs.  */
+
+static bfd_boolean
+elf32_hppa_mkobject (bfd *abfd)
+{
+  return bfd_elf_allocate_object (abfd, sizeof (struct elf_obj_tdata),
+				  HPPA_ELF_TDATA);
+}
+
 /* Assorted hash table functions.  */
 
 /* Initialize an entry in the stub hash table.  */
@@ -4602,11 +4611,12 @@ elf32_hppa_elf_get_symbol_type (Elf_Inte
 /* Misc BFD support code.  */
 #define bfd_elf32_bfd_is_local_label_name    elf_hppa_is_local_label_name
 #define bfd_elf32_bfd_reloc_type_lookup	     elf_hppa_reloc_type_lookup
-#define bfd_elf32_bfd_reloc_name_lookup elf_hppa_reloc_name_lookup
+#define bfd_elf32_bfd_reloc_name_lookup      elf_hppa_reloc_name_lookup
 #define elf_info_to_howto		     elf_hppa_info_to_howto
 #define elf_info_to_howto_rel		     elf_hppa_info_to_howto_rel
 
 /* Stuff for the BFD linker.  */
+#define bfd_elf32_mkobject		     elf32_hppa_mkobject
 #define bfd_elf32_bfd_final_link	     elf32_hppa_final_link
 #define bfd_elf32_bfd_link_hash_table_create elf32_hppa_link_hash_table_create
 #define bfd_elf32_bfd_link_hash_table_free   elf32_hppa_link_hash_table_free
Index: bfd/elf32-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.227
diff -u -p -r1.227 elf32-ppc.c
--- bfd/elf32-ppc.c	15 Feb 2008 03:35:52 -0000	1.227
+++ bfd/elf32-ppc.c	15 Feb 2008 07:26:32 -0000
@@ -1736,6 +1736,10 @@ struct ppc_elf_obj_tdata
 #define elf_local_ptr_offsets(bfd) \
   (ppc_elf_tdata (bfd)->linker_section_pointers)
 
+#define is_ppc_elf(bfd) \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+   && elf_object_id (bfd) == PPC32_ELF_TDATA)
+
 /* Override the generic function because we store some extras.  */
 
 static bfd_boolean
@@ -2743,20 +2747,6 @@ ppc_elf_copy_indirect_symbol (struct bfd
     }
 }
 
-/* Return 1 if target is one of ours.  */
-
-static bfd_boolean
-is_ppc_elf_target (const struct bfd_target *targ)
-{
-  extern const bfd_target bfd_elf32_powerpc_vec;
-  extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
-  extern const bfd_target bfd_elf32_powerpcle_vec;
-
-  return (targ == &bfd_elf32_powerpc_vec
-	  || targ == &bfd_elf32_powerpc_vxworks_vec
-	  || targ == &bfd_elf32_powerpcle_vec);
-}
-
 /* Hook called by the linker routine which adds symbols from an object
    file.  We use it to put .comm items in .sbss, and not .bss.  */
 
@@ -2771,8 +2761,8 @@ ppc_elf_add_symbol_hook (bfd *abfd,
 {
   if (sym->st_shndx == SHN_COMMON
       && !info->relocatable
-      && sym->st_size <= elf_gp_size (abfd)
-      && is_ppc_elf_target (info->output_bfd->xvec))
+      && is_ppc_elf (info->output_bfd)
+      && sym->st_size <= elf_gp_size (abfd))
     {
       /* Common symbols less than or equal to -G nn bytes are automatically
 	 put into .sbss.  */
@@ -2889,7 +2879,7 @@ elf_create_pointer_linker_section (bfd *
     }
   else
     {
-      BFD_ASSERT (is_ppc_elf_target (abfd->xvec));
+      BFD_ASSERT (is_ppc_elf (abfd));
 
       /* Allocation of a pointer to a local symbol.  */
       elf_linker_section_pointers_t **ptr = elf_local_ptr_offsets (abfd);
@@ -3055,7 +3045,7 @@ ppc_elf_check_relocs (bfd *abfd,
 		      sec, abfd);
 #endif
 
-  BFD_ASSERT (is_ppc_elf_target (abfd->xvec));
+  BFD_ASSERT (is_ppc_elf (abfd));
 
   /* Initialize howto table if not already done.  */
   if (!ppc_elf_howto_table[R_PPC_ADDR32])
@@ -3711,8 +3701,7 @@ ppc_elf_merge_private_bfd_data (bfd *ibf
   flagword new_flags;
   bfd_boolean error;
 
-  if (!is_ppc_elf_target (ibfd->xvec)
-      || !is_ppc_elf_target (obfd->xvec))
+  if (!is_ppc_elf (ibfd) || !is_ppc_elf (obfd))
     return TRUE;
 
   /* Check if we have the same endianess.  */
@@ -3825,7 +3814,7 @@ ppc_elf_select_plt_layout (bfd *output_b
 	  if (plt_type == PLT_UNSET)
 	    plt_type = PLT_OLD;
 	  for (ibfd = info->input_bfds; ibfd; ibfd = ibfd->link_next)
-	    if (is_ppc_elf_target (ibfd->xvec))
+	    if (is_ppc_elf (ibfd))
 	      {
 		if (ppc_elf_tdata (ibfd)->has_rel16)
 		  plt_type = PLT_NEW;
@@ -4916,7 +4905,7 @@ ppc_elf_size_dynamic_sections (bfd *outp
       bfd_size_type locsymcount;
       Elf_Internal_Shdr *symtab_hdr;
 
-      if (!is_ppc_elf_target (ibfd->xvec))
+      if (!is_ppc_elf (ibfd))
 	continue;
 
       for (s = ibfd->sections; s != NULL; s = s->next)
@@ -5675,7 +5664,7 @@ elf_finish_pointer_linker_section (bfd *
       /* Handle local symbol.  */
       unsigned long r_symndx = ELF32_R_SYM (rel->r_info);
 
-      BFD_ASSERT (is_ppc_elf_target (input_bfd->xvec));
+      BFD_ASSERT (is_ppc_elf (input_bfd));
       BFD_ASSERT (elf_local_ptr_offsets (input_bfd) != NULL);
       linker_section_ptr = elf_local_ptr_offsets (input_bfd)[r_symndx];
     }
Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.276
diff -u -p -r1.276 elf64-ppc.c
--- bfd/elf64-ppc.c	15 Feb 2008 03:35:52 -0000	1.276
+++ bfd/elf64-ppc.c	15 Feb 2008 07:26:37 -0000
@@ -2425,6 +2425,10 @@ struct ppc64_elf_obj_tdata
 #define ppc64_tlsld_got(bfd) \
   (&ppc64_elf_tdata (bfd)->tlsld_got)
 
+#define is_ppc64_elf(bfd) \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+   && elf_object_id (bfd) == PPC64_ELF_TDATA)
+
 /* Override the generic function because we store some extras.  */
 
 static bfd_boolean
@@ -2434,17 +2438,6 @@ ppc64_elf_mkobject (bfd *abfd)
 				  PPC64_ELF_TDATA);
 }
 
-/* Return 1 if target is one of ours.  */
-
-static bfd_boolean
-is_ppc64_elf_target (const struct bfd_target *targ)
-{
-  extern const bfd_target bfd_elf64_powerpc_vec;
-  extern const bfd_target bfd_elf64_powerpcle_vec;
-
-  return targ == &bfd_elf64_powerpc_vec || targ == &bfd_elf64_powerpcle_vec;
-}
-
 /* Fix bad default arch selected for a 64 bit input bfd when the
    default is 32 bit.  */
 
@@ -3882,7 +3875,7 @@ create_got_section (bfd *abfd, struct bf
   flagword flags;
   struct ppc_link_hash_table *htab = ppc_hash_table (info);
 
-  if (! is_ppc64_elf_target (abfd->xvec))
+  if (!is_ppc64_elf (abfd))
     return FALSE;
 
   if (!htab->got)
@@ -4275,10 +4268,10 @@ ppc64_elf_check_directives (bfd *ibfd, s
   struct ppc_link_hash_entry **p, *eh;
 
   htab = ppc_hash_table (info);
-  if (!is_ppc64_elf_target (info->output_bfd->xvec))
+  if (!is_ppc64_elf (info->output_bfd))
     return TRUE;
 
-  if (is_ppc64_elf_target (ibfd->xvec))
+  if (is_ppc64_elf (ibfd))
     {
       p = &htab->dot_syms;
       while ((eh = *p) != NULL)
@@ -4422,7 +4415,7 @@ ppc64_elf_check_relocs (bfd *abfd, struc
   if ((sec->flags & SEC_ALLOC) == 0)
     return TRUE;
 
-  BFD_ASSERT (is_ppc64_elf_target (abfd->xvec));
+  BFD_ASSERT (is_ppc64_elf (abfd));
 
   htab = ppc_hash_table (info);
   symtab_hdr = &elf_symtab_hdr (abfd);
@@ -4988,7 +4981,7 @@ opd_entry_value (asection *opd_sec,
       return val;
     }
 
-  BFD_ASSERT (is_ppc64_elf_target (opd_bfd->xvec));
+  BFD_ASSERT (is_ppc64_elf (opd_bfd));
 
   relocs = ppc64_elf_tdata (opd_bfd)->opd_relocs;
   if (relocs == NULL)
@@ -7749,7 +7742,7 @@ allocate_dynrelocs (struct elf_link_hash
 	    continue;
 	  }
 
-	if (! is_ppc64_elf_target (gent->owner->xvec))
+	if (!is_ppc64_elf (gent->owner))
 	  continue;
 
 	s = ppc64_elf_tdata (gent->owner)->got;
@@ -7929,7 +7922,7 @@ ppc64_elf_size_dynamic_sections (bfd *ou
       Elf_Internal_Shdr *symtab_hdr;
       asection *srel;
 
-      if (!is_ppc64_elf_target (ibfd->xvec))
+      if (!is_ppc64_elf (ibfd))
 	continue;
 
       for (s = ibfd->sections; s != NULL; s = s->next)
@@ -8006,7 +7999,7 @@ ppc64_elf_size_dynamic_sections (bfd *ou
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     {
-      if (!is_ppc64_elf_target (ibfd->xvec))
+      if (!is_ppc64_elf (ibfd))
 	continue;
 
       if (ppc64_tlsld_got (ibfd)->refcount > 0)
@@ -8093,7 +8086,7 @@ ppc64_elf_size_dynamic_sections (bfd *ou
 
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
     {
-      if (!is_ppc64_elf_target (ibfd->xvec))
+      if (!is_ppc64_elf (ibfd))
 	continue;
 
       s = ppc64_elf_tdata (ibfd)->got;
@@ -9310,7 +9303,7 @@ ppc64_elf_size_stubs (bfd *output_bfd,
 	  asection *section;
 	  Elf_Internal_Sym *local_syms = NULL;
 
-	  if (!is_ppc64_elf_target (input_bfd->xvec))
+	  if (!is_ppc64_elf (input_bfd))
 	    continue;
 
 	  /* We'll need the symbol table in a second.  */
@@ -9961,7 +9954,7 @@ ppc64_elf_relocate_section (bfd *output_
   if (input_section->owner == htab->stub_bfd)
     return TRUE;
 
-  BFD_ASSERT (is_ppc64_elf_target (input_bfd->xvec));
+  BFD_ASSERT (is_ppc64_elf (input_bfd));
 
   local_got_ents = elf_local_got_ents (input_bfd);
   TOCstart = elf_gp (output_bfd);
@@ -11597,7 +11590,7 @@ ppc64_elf_finish_dynamic_sections (bfd *
     {
       asection *s;
 
-      if (!is_ppc64_elf_target (dynobj->xvec))
+      if (!is_ppc64_elf (dynobj))
 	continue;
 
       s = ppc64_elf_tdata (dynobj)->got;
Index: ld/emultempl/alphaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/alphaelf.em,v
retrieving revision 1.11
diff -u -p -r1.11 alphaelf.em
--- ld/emultempl/alphaelf.em	15 Feb 2008 03:35:53 -0000	1.11
+++ ld/emultempl/alphaelf.em	15 Feb 2008 07:27:25 -0000
@@ -32,8 +32,6 @@ static bfd_boolean limit_32bit;
 static bfd_boolean disable_relaxation;
 
 extern bfd_boolean elf64_alpha_use_secureplt;
-extern const bfd_target bfd_elf64_alpha_vec;
-extern const bfd_target bfd_elf64_alpha_freebsd_vec;
 
 
 /* Set the start address as in the Tru64 ld.  */
@@ -42,8 +40,8 @@ extern const bfd_target bfd_elf64_alpha_
 static void
 alpha_after_open (void)
 {
-  if (link_info.output_bfd->xvec == &bfd_elf64_alpha_vec
-      || link_info.output_bfd->xvec == &bfd_elf64_alpha_freebsd_vec)
+  if (bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+      && elf_object_id (link_info.output_bfd) == ALPHA_ELF_TDATA)
     {
       unsigned int num_plt;
       lang_output_section_statement_type *os;
Index: ld/emultempl/hppaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/hppaelf.em,v
retrieving revision 1.50
diff -u -p -r1.50 hppaelf.em
--- ld/emultempl/hppaelf.em	15 Feb 2008 03:35:53 -0000	1.50
+++ ld/emultempl/hppaelf.em	15 Feb 2008 07:27:25 -0000
@@ -67,13 +67,8 @@ hppaelf_after_parse (void)
 static void
 hppaelf_create_output_section_statements (void)
 {
-  extern const bfd_target bfd_elf32_hppa_linux_vec;
-  extern const bfd_target bfd_elf32_hppa_nbsd_vec;
-  extern const bfd_target bfd_elf32_hppa_vec;
-
-  if (link_info.output_bfd->xvec != &bfd_elf32_hppa_linux_vec
-      && link_info.output_bfd->xvec != &bfd_elf32_hppa_nbsd_vec
-      && link_info.output_bfd->xvec != &bfd_elf32_hppa_vec)
+  if (!(bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+	&& elf_object_id (link_info.output_bfd) == HPPA_ELF_TDATA))
     return;
 
   stub_file = lang_add_input_file ("linker stubs",
Index: ld/emultempl/ppc32elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc32elf.em,v
retrieving revision 1.17
diff -u -p -r1.17 ppc32elf.em
--- ld/emultempl/ppc32elf.em	15 Feb 2008 03:35:53 -0000	1.17
+++ ld/emultempl/ppc32elf.em	15 Feb 2008 07:27:25 -0000
@@ -27,17 +27,9 @@ fragment <<EOF
 #include "libbfd.h"
 #include "elf32-ppc.h"
 
-extern const bfd_target bfd_elf32_powerpc_vec;
-extern const bfd_target bfd_elf32_powerpcle_vec;
-extern const bfd_target bfd_elf32_powerpc_vxworks_vec;
-
-static inline int
-is_ppc_elf32_vec(const bfd_target * vec)
-{
-  return (vec == &bfd_elf32_powerpc_vec
-	  || vec == &bfd_elf32_powerpc_vxworks_vec
-	  || vec == &bfd_elf32_powerpcle_vec);
-}
+#define is_ppc_elf(bfd) \
+  (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
+   && elf_object_id (bfd) == PPC32_ELF_TDATA)
 
 /* Whether to run tls optimization.  */
 static int notlsopt = 0;
@@ -52,7 +44,7 @@ static int old_got = 0;
 static void
 ppc_after_open (void)
 {
-  if (is_ppc_elf32_vec (link_info.output_bfd->xvec))
+  if (is_ppc_elf (link_info.output_bfd))
     {
       int new_plt;
       int keep_new;
@@ -109,7 +101,7 @@ ppc_after_open (void)
 static void
 ppc_before_allocation (void)
 {
-  if (is_ppc_elf32_vec (link_info.output_bfd->xvec))
+  if (is_ppc_elf (link_info.output_bfd))
     {
       if (ppc_elf_tls_setup (link_info.output_bfd, &link_info) && !notlsopt)
 	{
Index: ld/emultempl/ppc64elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc64elf.em,v
retrieving revision 1.58
diff -u -p -r1.58 ppc64elf.em
--- ld/emultempl/ppc64elf.em	15 Feb 2008 03:35:53 -0000	1.58
+++ ld/emultempl/ppc64elf.em	15 Feb 2008 07:27:25 -0000
@@ -72,11 +72,8 @@ static int non_overlapping_opd = 0;
 static void
 ppc_create_output_section_statements (void)
 {
-  extern const bfd_target bfd_elf64_powerpc_vec;
-  extern const bfd_target bfd_elf64_powerpcle_vec;
-
-  if (link_info.output_bfd->xvec != &bfd_elf64_powerpc_vec
-      && link_info.output_bfd->xvec != &bfd_elf64_powerpcle_vec)
+  if (!(bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
+	&& elf_object_id (link_info.output_bfd) == PPC64_ELF_TDATA))
     return;
 
   link_info.wrap_char = '.';

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]