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]

[PATCH] clean up elf32-i386-vxworks hooking mechanism


This cleans up the BFD elf32-i386 target vector to put its
backend-specific parameters into a new struct hung off of struct
elf_backend_data rather than overloading struct elf_i386_link_hash_table
for this purpose.  The latter is actual dynamic state.  The former is
just a constant table that varies by particular backend.

I tested that this showed no regressions for --target=i686-wrs-vxworks
compared to the unmodified trunk.  However, since I don't actually have
vxworks, I'm not sure how thorough my testing really was.  To be able to
do any tests at all, I built gcc --target=i686-wrs-vxworks from the 4.6
branch.  But I was not able to do a really usable build, i.e. no libgcc,
just gcc itself (--enable-languages=c).  The results (both before and
after this bfd change) look like this:

			=== binutils Summary ===

	# of expected passes		72
	# of expected failures		1
	# of untested testcases		8
	# of unsupported tests		9

			=== ld Summary ===

	# of expected passes		58
	# of expected failures		5
	# of untested testcases		12
	# of unsupported tests		13

Ok for trunk?


Thanks,
Roland


bfd/
2011-07-27  Roland McGrath  <mcgrathr@google.com>

	* elf32-i386.c (struct elf_i386_backend_data): New type.
	(get_elf_i386_backend_data): New macro.
	(elf_i386_arch_bed): New variable.
	(elf_backend_arch_data): New macro.
	(struct elf_i386_link_hash_table): Remove plt0_pad_byte and is_vxworks.
	(elf_i386_link_hash_table_create): Don't initialize them.
	(elf_i386_create_dynamic_sections): Find is_vxworks flags in
	elf_i386_backend_data, not elf_i386_link_hash_table.
	(elf_i386_adjust_dynamic_symbol): Likewise.
	(elf_i386_allocate_dynrelocs): Likewise.
	(elf_i386_readonly_dynrelocs): Likewise.
	(elf_i386_size_dynamic_sections): Likewise.
	(elf_i386_relocate_section): Likewise.
	(elf_i386_finish_dynamic_symbol): Likewise.
	(elf_i386_finish_dynamic_sections): Likewise.  Same for plt0_pad_byte.
	(elf_i386_vxworks_link_hash_table_create): Function removed.
	(elf_i386_vxworks_arch_bed): New variable.
	(elf_backend_arch_data): New macro in elf32-i386-vxworks stanza.

	* elf-bfd.h (elf_backend_data): New member arch_backend_data.
	* elfxx-target.h (elf_backend_arch_data): New macro.
	(elfNN_bed): Use it as initializer for the new member.

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 495f9f2..209fb29 100644
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index bf63ee8..e6ea580 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -714,6 +714,10 @@ struct elf_backend_data
   /* The BFD flags applied to sections created for dynamic linking.  */
   flagword dynamic_sec_flags;
 
+  /* Architecture-specific data for this backend.
+     This is actually a pointer to some type like struct elf_ARCH_data.  */
+  const void *arch_data;
+
   /* A function to translate an ELF RELA relocation to a BFD arelent
      structure.  */
   void (*elf_info_to_howto)
diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index b42e1a2..39050ec 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -620,6 +620,30 @@ static const bfd_byte elf_i386_eh_frame_plt[] =
 #define PLTRESOLVE_RELOCS 2
 #define PLT_NON_JUMP_SLOT_RELOCS 2
 
+/* Architecture-specific backend data for i386.  */
+
+struct elf_i386_backend_data
+{
+  /* Value used to fill the unused bytes of the first PLT entry.  */
+  bfd_byte plt0_pad_byte;
+
+  /* True if the target system is VxWorks.  */
+  int is_vxworks;
+};
+
+#define get_elf_i386_backend_data(abfd) \
+  ((const struct elf_i386_backend_data *) \
+   get_elf_backend_data (abfd)->arch_data)
+
+/* These are the standard parameters.  */
+static const struct elf_i386_backend_data elf_i386_arch_bed =
+  {
+    0,                                  /* plt0_pad_byte */
+    0,                                  /* is_vxworks */
+  };
+
+#define	elf_backend_arch_data	&elf_i386_arch_bed
+
 /* i386 ELF linker hash entry.  */
 
 struct elf_i386_link_hash_entry
@@ -720,14 +744,8 @@ struct elf_i386_link_hash_table
   /* The (unloaded but important) .rel.plt.unloaded section on VxWorks.  */
   asection *srelplt2;
 
-  /* True if the target system is VxWorks.  */
-  int is_vxworks;
-
   /* The index of the next unused R_386_TLS_DESC slot in .rel.plt.  */
   bfd_vma next_tls_desc_index;
-
-  /* Value used to fill the last word of the first plt entry.  */
-  bfd_byte plt0_pad_byte;
 };
 
 /* Get the i386 ELF linker hash table from a link_info structure.  */
@@ -866,9 +884,7 @@ elf_i386_link_hash_table_create (bfd *abfd)
   ret->next_tls_desc_index = 0;
   ret->sgotplt_jump_table_size = 0;
   ret->sym_cache.abfd = NULL;
-  ret->is_vxworks = 0;
   ret->srelplt2 = NULL;
-  ret->plt0_pad_byte = 0;
   ret->tls_module_base = NULL;
 
   ret->loc_hash_table = htab_try_create (1024,
@@ -924,7 +940,7 @@ elf_i386_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info)
       || (!info->shared && !htab->srelbss))
     abort ();
 
-  if (htab->is_vxworks
+  if (get_elf_i386_backend_data (dynobj)->is_vxworks
       && !elf_vxworks_create_dynamic_sections (dynobj, info,
 					       &htab->srelplt2))
     return FALSE;
@@ -2079,7 +2095,8 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info,
      we can keep the dynamic relocs and avoid the copy reloc.  This
      doesn't work on VxWorks, where we can not have dynamic relocations
      (other than copy and jump slot relocations) in an executable.  */
-  if (ELIMINATE_COPY_RELOCS && !htab->is_vxworks)
+  if (ELIMINATE_COPY_RELOCS
+      && !get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
     {
       struct elf_i386_link_hash_entry * eh;
       struct elf_dyn_relocs *p;
@@ -2205,7 +2222,8 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 	  htab->elf.srelplt->size += sizeof (Elf32_External_Rel);
 	  htab->next_tls_desc_index++;
 
-	  if (htab->is_vxworks && !info->shared)
+	  if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks
+              && !info->shared)
 	    {
 	      /* VxWorks has a second set of relocations for each PLT entry
 		 in executables.  They go in a separate relocation section,
@@ -2335,7 +2353,7 @@ elf_i386_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 	    }
 	}
 
-      if (htab->is_vxworks)
+      if (get_elf_i386_backend_data (info->output_bfd)->is_vxworks)
 	{
 	  struct elf_dyn_relocs **pp;
 	  for (pp = &eh->dyn_relocs; (p = *pp) != NULL; )
@@ -2469,8 +2487,7 @@ elf_i386_readonly_dynrelocs (struct elf_link_hash_entry *h, void *inf)
 /* Set the sizes of the dynamic sections.  */
 
 static bfd_boolean
-elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
-				struct bfd_link_info *info)
+elf_i386_size_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
 {
   struct elf_i386_link_hash_table *htab;
   bfd *dynobj;
@@ -2530,7 +2547,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 		     linker script /DISCARD/, so we'll be discarding
 		     the relocs too.  */
 		}
-	      else if (htab->is_vxworks
+	      else if (get_elf_i386_backend_data (output_bfd)->is_vxworks
 		       && strcmp (p->sec->output_section->name,
 				  ".tls_vars") == 0)
 		{
@@ -2779,7 +2796,7 @@ elf_i386_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
 		return FALSE;
 	    }
 	}
-      if (htab->is_vxworks
+      if (get_elf_i386_backend_data (output_bfd)->is_vxworks
 	  && !elf_vxworks_add_dynamic_entries (output_bfd, info))
 	return FALSE;
     }
@@ -2954,7 +2971,8 @@ elf_i386_relocate_section (bfd *output_bfd,
   local_tlsdesc_gotents = elf_i386_local_tlsdesc_gotent (input_bfd);
   /* We have to handle relocations in vxworks .tls_vars sections
      specially, because the dynamic loader is 'weird'.  */
-  is_vxworks_tls = (htab->is_vxworks && info->shared
+  is_vxworks_tls = (get_elf_i386_backend_data (output_bfd)->is_vxworks
+                    && info->shared
 		    && !strcmp (input_section->output_section->name,
 				".tls_vars"));
 
@@ -4301,7 +4319,7 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
 		       + got_offset),
 		      plt->contents + h->plt.offset + 2);
 
-	  if (htab->is_vxworks)
+	  if (get_elf_i386_backend_data (output_bfd)->is_vxworks)
 	    {
 	      int s, k, reloc_index;
 
@@ -4500,7 +4518,8 @@ do_glob_dat:
      is relative to the ".got" section.  */
   if (sym != NULL
       && (strcmp (h->root.root.string, "_DYNAMIC") == 0
-	  || (!htab->is_vxworks && h == htab->elf.hgot)))
+	  || (!get_elf_i386_backend_data (output_bfd)->is_vxworks
+              && h == htab->elf.hgot)))
     sym->st_shndx = SHN_ABS;
 
   return TRUE;
@@ -4576,7 +4595,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
 	  switch (dyn.d_tag)
 	    {
 	    default:
-	      if (htab->is_vxworks
+	      if (get_elf_i386_backend_data (output_bfd)->is_vxworks
 		  && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
 		break;
 	      continue;
@@ -4633,7 +4652,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
 	      memcpy (htab->elf.splt->contents, elf_i386_pic_plt0_entry,
 		      sizeof (elf_i386_pic_plt0_entry));
 	      memset (htab->elf.splt->contents + sizeof (elf_i386_pic_plt0_entry),
-		      htab->plt0_pad_byte,
+		      get_elf_i386_backend_data (output_bfd)->plt0_pad_byte,
 		      PLT_ENTRY_SIZE - sizeof (elf_i386_pic_plt0_entry));
 	    }
 	  else
@@ -4641,7 +4660,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
 	      memcpy (htab->elf.splt->contents, elf_i386_plt0_entry,
 		      sizeof(elf_i386_plt0_entry));
 	      memset (htab->elf.splt->contents + sizeof (elf_i386_plt0_entry),
-		      htab->plt0_pad_byte,
+		      get_elf_i386_backend_data (output_bfd)->plt0_pad_byte,
 		      PLT_ENTRY_SIZE - sizeof (elf_i386_plt0_entry));
 	      bfd_put_32 (output_bfd,
 			  (htab->elf.sgotplt->output_section->vma
@@ -4654,7 +4673,7 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
 			   + 8),
 			  htab->elf.splt->contents + 8);
 
-	      if (htab->is_vxworks)
+	      if (get_elf_i386_backend_data (output_bfd)->is_vxworks)
 		{
 		  Elf_Internal_Rela rel;
 
@@ -4684,7 +4703,8 @@ elf_i386_finish_dynamic_sections (bfd *output_bfd,
 	    ->this_hdr.sh_entsize = 4;
 
 	  /* Correct the .rel.plt.unloaded relocations.  */
-	  if (htab->is_vxworks && !info->shared)
+	  if (get_elf_i386_backend_data (output_bfd)->is_vxworks
+              && !info->shared)
 	    {
 	      int num_plts = (htab->elf.splt->size / PLT_ENTRY_SIZE) - 1;
 	      unsigned char *p;
@@ -4938,31 +4958,17 @@ elf_i386_fbsd_post_process_headers (bfd *abfd, struct bfd_link_info *info)
 #define TARGET_LITTLE_NAME		"elf32-i386-vxworks"
 #undef	ELF_OSABI
 
-/* Like elf_i386_link_hash_table_create but with tweaks for VxWorks.  */
-
-static struct bfd_link_hash_table *
-elf_i386_vxworks_link_hash_table_create (bfd *abfd)
-{
-  struct bfd_link_hash_table *ret;
-  struct elf_i386_link_hash_table *htab;
-
-  ret = elf_i386_link_hash_table_create (abfd);
-  if (ret)
-    {
-      htab = (struct elf_i386_link_hash_table *) ret;
-      htab->is_vxworks = 1;
-      htab->plt0_pad_byte = 0x90;
-    }
-
-  return ret;
-}
+static const struct elf_i386_backend_data elf_i386_vxworks_arch_bed =
+  {
+    0x90,                               /* plt0_pad_byte */
+    1,                                  /* is_vxworks */
+  };
 
+#undef	elf_backend_arch_data
+#define	elf_backend_arch_data	&elf_i386_vxworks_arch_bed
 
 #undef elf_backend_relocs_compatible
 #undef elf_backend_post_process_headers
-#undef bfd_elf32_bfd_link_hash_table_create
-#define bfd_elf32_bfd_link_hash_table_create \
-  elf_i386_vxworks_link_hash_table_create
 #undef elf_backend_add_symbol_hook
 #define elf_backend_add_symbol_hook \
   elf_vxworks_add_symbol_hook
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index b51ac9f..96ecce3 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -310,6 +310,10 @@
 #define elf_info_to_howto_rel 0
 #endif
 
+#ifndef elf_backend_arch_data
+#define elf_backend_arch_data NULL
+#endif
+
 #ifndef ELF_TARGET_ID
 #define ELF_TARGET_ID	GENERIC_ELF_DATA
 #endif
@@ -668,6 +672,7 @@ static struct elf_backend_data elfNN_bed =
   ELF_MINPAGESIZE,		/* minpagesize */
   ELF_COMMONPAGESIZE,		/* commonpagesize */
   ELF_DYNAMIC_SEC_FLAGS,	/* dynamic_sec_flags */
+  elf_backend_arch_data,
   elf_info_to_howto,
   elf_info_to_howto_rel,
   elf_backend_sym_is_global,


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