diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index f947703368..f834f5213e 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,33 @@
+2006-06-20  Alan Modra  <amodra@bigpond.net.au>
+
+	* elf-bfd.h: Formatting.
+	(_bfd_elf_map_sections_to_segments): Declare.
+	* elf-eh-frame.c (_bfd_elf_discard_section_eh_frame_hdr): Don't
+	clear program_header_size.
+	* elf.c (get_program_header_size): Move.  Don't use or set saved
+	program_header_size here.
+	(elf_modify_segment_map): New function.  Split out from..
+	(assign_file_positions_for_load_sections): ..here.  Assert
+	header size is correct.  Remove dead code.
+	(_bfd_elf_map_sections_to_segments): Rename from
+	map_sections_to_segments.  Make global.  Use get_program_header_size
+	when we need estimate of header size.  Call elf_modify_segment_map.
+	Set program_header_size.
+	(print_segment_map): Delete.
+	(_bfd_elf_sizeof_headers): If segment_map available, get the
+	actual size.
+	* elf32-arm.c (elf32_arm_symbian_modify_segment_map): Make safe
+	for calling more than once.
+	* elf32-bfin.c (elf32_bfinfdpic_modify_segment_map): Likewise.
+	* elf32-frv.c (elf32_frvfdpic_modify_segment_map): Likewise.
+	* elfxx-mips.c (_bfd_mips_elf_modify_segment_map): Likewise.
+	* elf32-i370.c (elf_backend_add_symbol_hook): Delete.
+	(elf_backend_additional_program_headers): Delete.
+	(elf_backend_modify_segment_map): Delete.
+	* elf64-hppa.c (elf64_hppa_modify_segment_map): Convert to ISO C.
+	* elfxx-ia64.c (elfNN_ia64_modify_segment_map): Likewise.
+	* doc/bfdint.texi: Delete SIZEOF_HEADERS difficulties.
+
 2006-06-19  Vladimir Prus  <vladimir@codesourcery.com>
 
 	* elf32-arm.c (elf32_arm_swap_symbol_out): Don't set low
diff --git a/bfd/doc/bfdint.texi b/bfd/doc/bfdint.texi
index 98826fd520..79813decc7 100644
--- a/bfd/doc/bfdint.texi
+++ b/bfd/doc/bfdint.texi
@@ -1744,23 +1744,6 @@ support.
 The processor function hooks and constants are ad hoc and need better
 documentation.
 
-When a linker script uses @samp{SIZEOF_HEADERS}, the ELF backend must
-guess at the number of program segments which will be required, in
-@samp{get_program_header_size}.  This is because the linker calls
-@samp{bfd_sizeof_headers} before it knows all the section addresses and
-sizes.  The ELF backend may later discover, when creating program
-segments, that more program segments are required.  This is currently
-reported as an error in @samp{assign_file_positions_for_segments}.
-
-In practice this makes it difficult to use @samp{SIZEOF_HEADERS} except
-with a carefully defined linker script.  Unfortunately,
-@samp{SIZEOF_HEADERS} is required for fast program loading on a native
-system, since it permits the initial code section to appear on the same
-page as the program segments, saving a page read when the program starts
-running.  Fortunately, native systems permit careful definition of the
-linker script.  Still, ideally it would be possible to use relaxation to
-compute the number of program segments.
-
 @node BFD glossary
 @section BFD glossary
 @cindex glossary for bfd
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index d5c7d1bc54..98134161f7 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1864,10 +1864,12 @@ extern bfd_boolean bfd_elf_gc_common_final_link
 extern bfd_boolean bfd_elf_reloc_symbol_deleted_p
   (bfd_vma, void *);
 
-extern struct elf_segment_map *
-_bfd_elf_make_dynamic_segment
+extern struct elf_segment_map * _bfd_elf_make_dynamic_segment
   (bfd *, asection *);
 
+extern bfd_boolean _bfd_elf_map_sections_to_segments
+  (bfd *, struct bfd_link_info *);
+
 /* Exported interface for writing elf corefile notes. */
 extern char *elfcore_write_note
   (bfd *, char *, int *, const char *, int, const void *, int);
diff --git a/bfd/elf-eh-frame.c b/bfd/elf-eh-frame.c
index b430b8bb60..91596dfab2 100644
--- a/bfd/elf-eh-frame.c
+++ b/bfd/elf-eh-frame.c
@@ -846,8 +846,6 @@ _bfd_elf_discard_section_eh_frame_hdr (bfd *abfd, struct bfd_link_info *info)
   if (hdr_info->table)
     sec->size += 4 + hdr_info->fde_count * 8;
 
-  /* Request program headers to be recalculated.  */
-  elf_tdata (abfd)->program_header_size = 0;
   elf_tdata (abfd)->eh_frame_hdr = sec;
   return TRUE;
 }
diff --git a/bfd/elf.c b/bfd/elf.c
index 05fa187768..44621e6102 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -3560,6 +3560,89 @@ _bfd_elf_compute_section_file_positions (bfd *abfd,
   return TRUE;
 }
 
+/* Make an initial estimate of the size of the program header.  If we
+   get the number wrong here, we'll redo section placement.  */
+
+static bfd_size_type
+get_program_header_size (bfd *abfd, struct bfd_link_info *info)
+{
+  size_t segs;
+  asection *s;
+  const struct elf_backend_data *bed;
+
+  /* Assume we will need exactly two PT_LOAD segments: one for text
+     and one for data.  */
+  segs = 2;
+
+  s = bfd_get_section_by_name (abfd, ".interp");
+  if (s != NULL && (s->flags & SEC_LOAD) != 0)
+    {
+      /* If we have a loadable interpreter section, we need a
+	 PT_INTERP segment.  In this case, assume we also need a
+	 PT_PHDR segment, although that may not be true for all
+	 targets.  */
+      segs += 2;
+    }
+
+  if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
+    {
+      /* We need a PT_DYNAMIC segment.  */
+      ++segs;
+    }
+
+  if (elf_tdata (abfd)->eh_frame_hdr)
+    {
+      /* We need a PT_GNU_EH_FRAME segment.  */
+      ++segs;
+    }
+
+  if (elf_tdata (abfd)->stack_flags)
+    {
+      /* We need a PT_GNU_STACK segment.  */
+      ++segs;
+    }
+
+  if (elf_tdata (abfd)->relro)
+    {
+      /* We need a PT_GNU_RELRO segment.  */
+      ++segs;
+    }
+
+  for (s = abfd->sections; s != NULL; s = s->next)
+    {
+      if ((s->flags & SEC_LOAD) != 0
+	  && strncmp (s->name, ".note", 5) == 0)
+	{
+	  /* We need a PT_NOTE segment.  */
+	  ++segs;
+	}
+    }
+
+  for (s = abfd->sections; s != NULL; s = s->next)
+    {
+      if (s->flags & SEC_THREAD_LOCAL)
+	{
+	  /* We need a PT_TLS segment.  */
+	  ++segs;
+	  break;
+	}
+    }
+
+  /* Let the backend count up any program headers it might need.  */
+  bed = get_elf_backend_data (abfd);
+  if (bed->elf_backend_additional_program_headers)
+    {
+      int a;
+
+      a = (*bed->elf_backend_additional_program_headers) (abfd, info);
+      if (a == -1)
+	abort ();
+      segs += a;
+    }
+
+  return segs * bed->s->sizeof_phdr;
+}
+
 /* Create a mapping from a set of sections to a program segment.  */
 
 static struct elf_segment_map *
@@ -3614,359 +3697,413 @@ _bfd_elf_make_dynamic_segment (bfd *abfd, asection *dynsec)
   return m;
 }
 
-/* Set up a mapping from BFD sections to program segments.  */
+/* Possibly add or remove segments from the segment map.  */
 
 static bfd_boolean
-map_sections_to_segments (bfd *abfd)
+elf_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
 {
-  asection **sections = NULL;
-  asection *s;
-  unsigned int i;
-  unsigned int count;
-  struct elf_segment_map *mfirst;
-  struct elf_segment_map **pm;
   struct elf_segment_map *m;
-  asection *last_hdr;
-  bfd_vma last_size;
-  unsigned int phdr_index;
-  bfd_vma maxpagesize;
-  asection **hdrpp;
-  bfd_boolean phdr_in_segment = TRUE;
-  bfd_boolean writable;
-  int tls_count = 0;
-  asection *first_tls = NULL;
-  asection *dynsec, *eh_frame_hdr;
-  bfd_size_type amt;
+  const struct elf_backend_data *bed;
 
-  if (elf_tdata (abfd)->segment_map != NULL)
-    return TRUE;
-
-  if (bfd_count_sections (abfd) == 0)
-    return TRUE;
-
-  /* Select the allocated sections, and sort them.  */
-
-  sections = bfd_malloc2 (bfd_count_sections (abfd), sizeof (asection *));
-  if (sections == NULL)
-    goto error_return;
-
-  i = 0;
-  for (s = abfd->sections; s != NULL; s = s->next)
+  /* The placement algorithm assumes that non allocated sections are
+     not in PT_LOAD segments.  We ensure this here by removing such
+     sections from the segment map.  We also remove excluded
+     sections.  */
+  for (m = elf_tdata (abfd)->segment_map;
+       m != NULL;
+       m = m->next)
     {
-      if ((s->flags & SEC_ALLOC) != 0)
+      unsigned int i, new_count;
+
+      new_count = 0;
+      for (i = 0; i < m->count; i ++)
 	{
-	  sections[i] = s;
-	  ++i;
+	  if ((m->sections[i]->flags & SEC_EXCLUDE) == 0
+	      && ((m->sections[i]->flags & SEC_ALLOC) != 0
+		  || m->p_type != PT_LOAD))
+	    {
+	      if (i != new_count)
+		m->sections[new_count] = m->sections[i];
+
+	      new_count ++;
+	    }
 	}
-    }
-  BFD_ASSERT (i <= bfd_count_sections (abfd));
-  count = i;
 
-  qsort (sections, (size_t) count, sizeof (asection *), elf_sort_sections);
-
-  /* Build the mapping.  */
-
-  mfirst = NULL;
-  pm = &mfirst;
-
-  /* If we have a .interp section, then create a PT_PHDR segment for
-     the program headers and a PT_INTERP segment for the .interp
-     section.  */
-  s = bfd_get_section_by_name (abfd, ".interp");
-  if (s != NULL && (s->flags & SEC_LOAD) != 0)
-    {
-      amt = sizeof (struct elf_segment_map);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_PHDR;
-      /* FIXME: UnixWare and Solaris set PF_X, Irix 5 does not.  */
-      m->p_flags = PF_R | PF_X;
-      m->p_flags_valid = 1;
-      m->includes_phdrs = 1;
-
-      *pm = m;
-      pm = &m->next;
-
-      amt = sizeof (struct elf_segment_map);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_INTERP;
-      m->count = 1;
-      m->sections[0] = s;
-
-      *pm = m;
-      pm = &m->next;
+      if (new_count != m->count)
+	m->count = new_count;
     }
 
-  /* Look through the sections.  We put sections in the same program
-     segment when the start of the second section can be placed within
-     a few bytes of the end of the first section.  */
-  last_hdr = NULL;
-  last_size = 0;
-  phdr_index = 0;
-  maxpagesize = get_elf_backend_data (abfd)->maxpagesize;
-  writable = FALSE;
-  dynsec = bfd_get_section_by_name (abfd, ".dynamic");
-  if (dynsec != NULL
-      && (dynsec->flags & SEC_LOAD) == 0)
-    dynsec = NULL;
-
-  /* Deal with -Ttext or something similar such that the first section
-     is not adjacent to the program headers.  This is an
-     approximation, since at this point we don't know exactly how many
-     program headers we will need.  */
-  if (count > 0)
+  /* Yes, we call elf_backend_modify_segment_map at least two times
+     for the linker.  The final time the link_orders are available.  */
+  bed = get_elf_backend_data (abfd);
+  if (bed->elf_backend_modify_segment_map != NULL)
     {
-      bfd_size_type phdr_size;
-
-      phdr_size = elf_tdata (abfd)->program_header_size;
-      if (phdr_size == 0)
-	phdr_size = get_elf_backend_data (abfd)->s->sizeof_phdr;
-      if ((abfd->flags & D_PAGED) == 0
-	  || sections[0]->lma < phdr_size
-	  || sections[0]->lma % maxpagesize < phdr_size % maxpagesize)
-	phdr_in_segment = FALSE;
+      if (! (*bed->elf_backend_modify_segment_map) (abfd, info))
+	return FALSE;
     }
 
-  for (i = 0, hdrpp = sections; i < count; i++, hdrpp++)
+  return TRUE;
+}
+
+/* Set up a mapping from BFD sections to program segments.  */
+
+bfd_boolean
+_bfd_elf_map_sections_to_segments (bfd *abfd, struct bfd_link_info *info)
+{
+  unsigned int count;
+  struct elf_segment_map *m;
+  asection **sections = NULL;
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+
+  if (elf_tdata (abfd)->segment_map == NULL
+      && bfd_count_sections (abfd) != 0)
     {
-      asection *hdr;
-      bfd_boolean new_segment;
+      asection *s;
+      unsigned int i;
+      struct elf_segment_map *mfirst;
+      struct elf_segment_map **pm;
+      asection *last_hdr;
+      bfd_vma last_size;
+      unsigned int phdr_index;
+      bfd_vma maxpagesize;
+      asection **hdrpp;
+      bfd_boolean phdr_in_segment = TRUE;
+      bfd_boolean writable;
+      int tls_count = 0;
+      asection *first_tls = NULL;
+      asection *dynsec, *eh_frame_hdr;
+      bfd_size_type amt;
 
-      hdr = *hdrpp;
+      /* Select the allocated sections, and sort them.  */
 
-      /* See if this section and the last one will fit in the same
-         segment.  */
-
-      if (last_hdr == NULL)
-	{
-	  /* If we don't have a segment yet, then we don't need a new
-	     one (we build the last one after this loop).  */
-	  new_segment = FALSE;
-	}
-      else if (last_hdr->lma - last_hdr->vma != hdr->lma - hdr->vma)
-	{
-	  /* If this section has a different relation between the
-             virtual address and the load address, then we need a new
-             segment.  */
-	  new_segment = TRUE;
-	}
-      else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
-	       < BFD_ALIGN (hdr->lma, maxpagesize))
-	{
-	  /* If putting this section in this segment would force us to
-             skip a page in the segment, then we need a new segment.  */
-	  new_segment = TRUE;
-	}
-      else if ((last_hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0
-	       && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0)
-	{
-	  /* We don't want to put a loadable section after a
-             nonloadable section in the same segment.
-             Consider .tbss sections as loadable for this purpose.  */
-	  new_segment = TRUE;
-	}
-      else if ((abfd->flags & D_PAGED) == 0)
-	{
-	  /* If the file is not demand paged, which means that we
-             don't require the sections to be correctly aligned in the
-             file, then there is no other reason for a new segment.  */
-	  new_segment = FALSE;
-	}
-      else if (! writable
-	       && (hdr->flags & SEC_READONLY) == 0
-	       && (((last_hdr->lma + last_size - 1)
-		    & ~(maxpagesize - 1))
-		   != (hdr->lma & ~(maxpagesize - 1))))
-	{
-	  /* We don't want to put a writable section in a read only
-             segment, unless they are on the same page in memory
-             anyhow.  We already know that the last section does not
-             bring us past the current section on the page, so the
-             only case in which the new section is not on the same
-             page as the previous section is when the previous section
-             ends precisely on a page boundary.  */
-	  new_segment = TRUE;
-	}
-      else
-	{
-	  /* Otherwise, we can use the same segment.  */
-	  new_segment = FALSE;
-	}
-
-      if (! new_segment)
-	{
-	  if ((hdr->flags & SEC_READONLY) == 0)
-	    writable = TRUE;
-	  last_hdr = hdr;
-	  /* .tbss sections effectively have zero size.  */
-	  if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) != SEC_THREAD_LOCAL)
-	    last_size = hdr->size;
-	  else
-	    last_size = 0;
-	  continue;
-	}
-
-      /* We need a new program segment.  We must create a new program
-         header holding all the sections from phdr_index until hdr.  */
-
-      m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment);
-      if (m == NULL)
+      sections = bfd_malloc2 (bfd_count_sections (abfd), sizeof (asection *));
+      if (sections == NULL)
 	goto error_return;
 
-      *pm = m;
-      pm = &m->next;
+      i = 0;
+      for (s = abfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_ALLOC) != 0)
+	    {
+	      sections[i] = s;
+	      ++i;
+	    }
+	}
+      BFD_ASSERT (i <= bfd_count_sections (abfd));
+      count = i;
 
-      if ((hdr->flags & SEC_READONLY) == 0)
-	writable = TRUE;
-      else
-	writable = FALSE;
+      qsort (sections, (size_t) count, sizeof (asection *), elf_sort_sections);
 
-      last_hdr = hdr;
-      /* .tbss sections effectively have zero size.  */
-      if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) != SEC_THREAD_LOCAL)
-	last_size = hdr->size;
-      else
-	last_size = 0;
-      phdr_index = i;
-      phdr_in_segment = FALSE;
-    }
+      /* Build the mapping.  */
 
-  /* Create a final PT_LOAD program segment.  */
-  if (last_hdr != NULL)
-    {
-      m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment);
-      if (m == NULL)
-	goto error_return;
+      mfirst = NULL;
+      pm = &mfirst;
 
-      *pm = m;
-      pm = &m->next;
-    }
-
-  /* If there is a .dynamic section, throw in a PT_DYNAMIC segment.  */
-  if (dynsec != NULL)
-    {
-      m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
-      if (m == NULL)
-	goto error_return;
-      *pm = m;
-      pm = &m->next;
-    }
-
-  /* For each loadable .note section, add a PT_NOTE segment.  We don't
-     use bfd_get_section_by_name, because if we link together
-     nonloadable .note sections and loadable .note sections, we will
-     generate two .note sections in the output file.  FIXME: Using
-     names for section types is bogus anyhow.  */
-  for (s = abfd->sections; s != NULL; s = s->next)
-    {
-      if ((s->flags & SEC_LOAD) != 0
-	  && strncmp (s->name, ".note", 5) == 0)
+      /* If we have a .interp section, then create a PT_PHDR segment for
+	 the program headers and a PT_INTERP segment for the .interp
+	 section.  */
+      s = bfd_get_section_by_name (abfd, ".interp");
+      if (s != NULL && (s->flags & SEC_LOAD) != 0)
 	{
 	  amt = sizeof (struct elf_segment_map);
 	  m = bfd_zalloc (abfd, amt);
 	  if (m == NULL)
 	    goto error_return;
 	  m->next = NULL;
-	  m->p_type = PT_NOTE;
+	  m->p_type = PT_PHDR;
+	  /* FIXME: UnixWare and Solaris set PF_X, Irix 5 does not.  */
+	  m->p_flags = PF_R | PF_X;
+	  m->p_flags_valid = 1;
+	  m->includes_phdrs = 1;
+
+	  *pm = m;
+	  pm = &m->next;
+
+	  amt = sizeof (struct elf_segment_map);
+	  m = bfd_zalloc (abfd, amt);
+	  if (m == NULL)
+	    goto error_return;
+	  m->next = NULL;
+	  m->p_type = PT_INTERP;
 	  m->count = 1;
 	  m->sections[0] = s;
 
 	  *pm = m;
 	  pm = &m->next;
 	}
-      if (s->flags & SEC_THREAD_LOCAL)
-	{
-	  if (! tls_count)
-	    first_tls = s;
-	  tls_count++;
-	}
-    }
 
-  /* If there are any SHF_TLS output sections, add PT_TLS segment.  */
-  if (tls_count > 0)
-    {
-      int i;
+      /* Look through the sections.  We put sections in the same program
+	 segment when the start of the second section can be placed within
+	 a few bytes of the end of the first section.  */
+      last_hdr = NULL;
+      last_size = 0;
+      phdr_index = 0;
+      maxpagesize = bed->maxpagesize;
+      writable = FALSE;
+      dynsec = bfd_get_section_by_name (abfd, ".dynamic");
+      if (dynsec != NULL
+	  && (dynsec->flags & SEC_LOAD) == 0)
+	dynsec = NULL;
 
-      amt = sizeof (struct elf_segment_map);
-      amt += (tls_count - 1) * sizeof (asection *);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_TLS;
-      m->count = tls_count;
-      /* Mandated PF_R.  */
-      m->p_flags = PF_R;
-      m->p_flags_valid = 1;
-      for (i = 0; i < tls_count; ++i)
+      /* Deal with -Ttext or something similar such that the first section
+	 is not adjacent to the program headers.  This is an
+	 approximation, since at this point we don't know exactly how many
+	 program headers we will need.  */
+      if (count > 0)
 	{
-	  BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL);
-	  m->sections[i] = first_tls;
-	  first_tls = first_tls->next;
+	  bfd_size_type phdr_size = elf_tdata (abfd)->program_header_size;
+
+	  if (phdr_size == 0)
+	    phdr_size = get_program_header_size (abfd, info);
+	  if ((abfd->flags & D_PAGED) == 0
+	      || sections[0]->lma < phdr_size
+	      || sections[0]->lma % maxpagesize < phdr_size % maxpagesize)
+	    phdr_in_segment = FALSE;
 	}
 
-      *pm = m;
-      pm = &m->next;
+      for (i = 0, hdrpp = sections; i < count; i++, hdrpp++)
+	{
+	  asection *hdr;
+	  bfd_boolean new_segment;
+
+	  hdr = *hdrpp;
+
+	  /* See if this section and the last one will fit in the same
+	     segment.  */
+
+	  if (last_hdr == NULL)
+	    {
+	      /* If we don't have a segment yet, then we don't need a new
+		 one (we build the last one after this loop).  */
+	      new_segment = FALSE;
+	    }
+	  else if (last_hdr->lma - last_hdr->vma != hdr->lma - hdr->vma)
+	    {
+	      /* If this section has a different relation between the
+		 virtual address and the load address, then we need a new
+		 segment.  */
+	      new_segment = TRUE;
+	    }
+	  else if (BFD_ALIGN (last_hdr->lma + last_size, maxpagesize)
+		   < BFD_ALIGN (hdr->lma, maxpagesize))
+	    {
+	      /* If putting this section in this segment would force us to
+		 skip a page in the segment, then we need a new segment.  */
+	      new_segment = TRUE;
+	    }
+	  else if ((last_hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) == 0
+		   && (hdr->flags & (SEC_LOAD | SEC_THREAD_LOCAL)) != 0)
+	    {
+	      /* We don't want to put a loadable section after a
+		 nonloadable section in the same segment.
+		 Consider .tbss sections as loadable for this purpose.  */
+	      new_segment = TRUE;
+	    }
+	  else if ((abfd->flags & D_PAGED) == 0)
+	    {
+	      /* If the file is not demand paged, which means that we
+		 don't require the sections to be correctly aligned in the
+		 file, then there is no other reason for a new segment.  */
+	      new_segment = FALSE;
+	    }
+	  else if (! writable
+		   && (hdr->flags & SEC_READONLY) == 0
+		   && (((last_hdr->lma + last_size - 1)
+			& ~(maxpagesize - 1))
+		       != (hdr->lma & ~(maxpagesize - 1))))
+	    {
+	      /* We don't want to put a writable section in a read only
+		 segment, unless they are on the same page in memory
+		 anyhow.  We already know that the last section does not
+		 bring us past the current section on the page, so the
+		 only case in which the new section is not on the same
+		 page as the previous section is when the previous section
+		 ends precisely on a page boundary.  */
+	      new_segment = TRUE;
+	    }
+	  else
+	    {
+	      /* Otherwise, we can use the same segment.  */
+	      new_segment = FALSE;
+	    }
+
+	  if (! new_segment)
+	    {
+	      if ((hdr->flags & SEC_READONLY) == 0)
+		writable = TRUE;
+	      last_hdr = hdr;
+	      /* .tbss sections effectively have zero size.  */
+	      if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD))
+		  != SEC_THREAD_LOCAL)
+		last_size = hdr->size;
+	      else
+		last_size = 0;
+	      continue;
+	    }
+
+	  /* We need a new program segment.  We must create a new program
+	     header holding all the sections from phdr_index until hdr.  */
+
+	  m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment);
+	  if (m == NULL)
+	    goto error_return;
+
+	  *pm = m;
+	  pm = &m->next;
+
+	  if ((hdr->flags & SEC_READONLY) == 0)
+	    writable = TRUE;
+	  else
+	    writable = FALSE;
+
+	  last_hdr = hdr;
+	  /* .tbss sections effectively have zero size.  */
+	  if ((hdr->flags & (SEC_THREAD_LOCAL | SEC_LOAD)) != SEC_THREAD_LOCAL)
+	    last_size = hdr->size;
+	  else
+	    last_size = 0;
+	  phdr_index = i;
+	  phdr_in_segment = FALSE;
+	}
+
+      /* Create a final PT_LOAD program segment.  */
+      if (last_hdr != NULL)
+	{
+	  m = make_mapping (abfd, sections, phdr_index, i, phdr_in_segment);
+	  if (m == NULL)
+	    goto error_return;
+
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      /* If there is a .dynamic section, throw in a PT_DYNAMIC segment.  */
+      if (dynsec != NULL)
+	{
+	  m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
+	  if (m == NULL)
+	    goto error_return;
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      /* For each loadable .note section, add a PT_NOTE segment.  We don't
+	 use bfd_get_section_by_name, because if we link together
+	 nonloadable .note sections and loadable .note sections, we will
+	 generate two .note sections in the output file.  FIXME: Using
+	 names for section types is bogus anyhow.  */
+      for (s = abfd->sections; s != NULL; s = s->next)
+	{
+	  if ((s->flags & SEC_LOAD) != 0
+	      && strncmp (s->name, ".note", 5) == 0)
+	    {
+	      amt = sizeof (struct elf_segment_map);
+	      m = bfd_zalloc (abfd, amt);
+	      if (m == NULL)
+		goto error_return;
+	      m->next = NULL;
+	      m->p_type = PT_NOTE;
+	      m->count = 1;
+	      m->sections[0] = s;
+
+	      *pm = m;
+	      pm = &m->next;
+	    }
+	  if (s->flags & SEC_THREAD_LOCAL)
+	    {
+	      if (! tls_count)
+		first_tls = s;
+	      tls_count++;
+	    }
+	}
+
+      /* If there are any SHF_TLS output sections, add PT_TLS segment.  */
+      if (tls_count > 0)
+	{
+	  int i;
+
+	  amt = sizeof (struct elf_segment_map);
+	  amt += (tls_count - 1) * sizeof (asection *);
+	  m = bfd_zalloc (abfd, amt);
+	  if (m == NULL)
+	    goto error_return;
+	  m->next = NULL;
+	  m->p_type = PT_TLS;
+	  m->count = tls_count;
+	  /* Mandated PF_R.  */
+	  m->p_flags = PF_R;
+	  m->p_flags_valid = 1;
+	  for (i = 0; i < tls_count; ++i)
+	    {
+	      BFD_ASSERT (first_tls->flags & SEC_THREAD_LOCAL);
+	      m->sections[i] = first_tls;
+	      first_tls = first_tls->next;
+	    }
+
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME
+	 segment.  */
+      eh_frame_hdr = elf_tdata (abfd)->eh_frame_hdr;
+      if (eh_frame_hdr != NULL
+	  && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0)
+	{
+	  amt = sizeof (struct elf_segment_map);
+	  m = bfd_zalloc (abfd, amt);
+	  if (m == NULL)
+	    goto error_return;
+	  m->next = NULL;
+	  m->p_type = PT_GNU_EH_FRAME;
+	  m->count = 1;
+	  m->sections[0] = eh_frame_hdr->output_section;
+
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      if (elf_tdata (abfd)->stack_flags)
+	{
+	  amt = sizeof (struct elf_segment_map);
+	  m = bfd_zalloc (abfd, amt);
+	  if (m == NULL)
+	    goto error_return;
+	  m->next = NULL;
+	  m->p_type = PT_GNU_STACK;
+	  m->p_flags = elf_tdata (abfd)->stack_flags;
+	  m->p_flags_valid = 1;
+
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      if (elf_tdata (abfd)->relro)
+	{
+	  amt = sizeof (struct elf_segment_map);
+	  m = bfd_zalloc (abfd, amt);
+	  if (m == NULL)
+	    goto error_return;
+	  m->next = NULL;
+	  m->p_type = PT_GNU_RELRO;
+	  m->p_flags = PF_R;
+	  m->p_flags_valid = 1;
+
+	  *pm = m;
+	  pm = &m->next;
+	}
+
+      free (sections);
+      elf_tdata (abfd)->segment_map = mfirst;
     }
 
-  /* If there is a .eh_frame_hdr section, throw in a PT_GNU_EH_FRAME
-     segment.  */
-  eh_frame_hdr = elf_tdata (abfd)->eh_frame_hdr;
-  if (eh_frame_hdr != NULL
-      && (eh_frame_hdr->output_section->flags & SEC_LOAD) != 0)
-    {
-      amt = sizeof (struct elf_segment_map);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_GNU_EH_FRAME;
-      m->count = 1;
-      m->sections[0] = eh_frame_hdr->output_section;
+  if (!elf_modify_segment_map (abfd, info))
+    return FALSE;
 
-      *pm = m;
-      pm = &m->next;
-    }
+  for (count = 0, m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+    ++count;
+  elf_tdata (abfd)->program_header_size = count * bed->s->sizeof_phdr;
 
-  if (elf_tdata (abfd)->stack_flags)
-    {
-      amt = sizeof (struct elf_segment_map);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_GNU_STACK;
-      m->p_flags = elf_tdata (abfd)->stack_flags;
-      m->p_flags_valid = 1;
-
-      *pm = m;
-      pm = &m->next;
-    }
-
-  if (elf_tdata (abfd)->relro)
-    {
-      amt = sizeof (struct elf_segment_map);
-      m = bfd_zalloc (abfd, amt);
-      if (m == NULL)
-	goto error_return;
-      m->next = NULL;
-      m->p_type = PT_GNU_RELRO;
-      m->p_flags = PF_R;
-      m->p_flags_valid = 1;
-
-      *pm = m;
-      pm = &m->next;
-    }
-
-  free (sections);
-  sections = NULL;
-
-  elf_tdata (abfd)->segment_map = mfirst;
   return TRUE;
 
  error_return:
@@ -4062,42 +4199,6 @@ vma_page_aligned_bias (bfd_vma vma, ufile_ptr off, bfd_vma maxpagesize)
   return ((vma - off) % maxpagesize);
 }
 
-static void
-print_segment_map (bfd *abfd)
-{
-  struct elf_segment_map *m;
-  unsigned int i, j;
-
-  fprintf (stderr, _(" Section to Segment mapping:\n"));
-  fprintf (stderr, _("  Segment              Sections...\n"));
-
-  for (i= 0, m = elf_tdata (abfd)->segment_map;
-       m != NULL;
-       i++, m = m->next)
-    {
-      const char *pt = get_segment_type (m->p_type);
-      char buf[32];
-
-      if (pt == NULL)
-	{
-	  if (m->p_type >= PT_LOPROC && m->p_type <= PT_HIPROC)
-	    sprintf (buf, "LOPROC+%7.7x",
-		     (unsigned int) (m->p_type - PT_LOPROC));
-	  else if (m->p_type >= PT_LOOS && m->p_type <= PT_HIOS)
-	    sprintf (buf, "LOOS+%7.7x",
-		     (unsigned int) (m->p_type - PT_LOOS));
-	  else
-	    snprintf (buf, sizeof (buf), "%8.8x",
-		      (unsigned int) m->p_type);
-	  pt = buf;
-	}
-      fprintf (stderr, "  %2.2d: %14.14s:  ", i, pt);
-      for (j = 0; j < m->count; j++)
-	fprintf (stderr, "%s ", m->sections [j]->name);
-      putc ('\n',stderr);
-    }
-}
-
 /* Assign file positions to the sections based on the mapping from
    sections to segments.  This function also sets up some fields in
    the file header.  */
@@ -4112,84 +4213,30 @@ assign_file_positions_for_load_sections (bfd *abfd,
   Elf_Internal_Phdr *p;
   file_ptr off, voff;
   bfd_size_type maxpagesize;
-  unsigned int count;
   unsigned int alloc;
   unsigned int i;
 
-  if (elf_tdata (abfd)->segment_map == NULL)
-    {
-      if (! map_sections_to_segments (abfd))
-	return FALSE;
-    }
-  else
-    {
-      /* The placement algorithm assumes that non allocated sections are
-	 not in PT_LOAD segments.  We ensure this here by removing such
-	 sections from the segment map.  We also remove excluded
-	 sections.  */
-      for (m = elf_tdata (abfd)->segment_map;
-	   m != NULL;
-	   m = m->next)
-	{
-	  unsigned int new_count;
+  if (!elf_modify_segment_map (abfd, link_info))
+    return FALSE;
 
-	  new_count = 0;
-	  for (i = 0; i < m->count; i ++)
-	    {
-	      if ((m->sections[i]->flags & SEC_EXCLUDE) == 0
-		  && ((m->sections[i]->flags & SEC_ALLOC) != 0
-		      || m->p_type != PT_LOAD))
-		{
-		  if (i != new_count)
-		    m->sections[new_count] = m->sections[i];
-
-		  new_count ++;
-		}
-	    }
-
-	  if (new_count != m->count)
-	    m->count = new_count;
-	}
-    }
-
-  if (bed->elf_backend_modify_segment_map)
-    {
-      if (! (*bed->elf_backend_modify_segment_map) (abfd, link_info))
-	return FALSE;
-    }
-
-  count = 0;
+  alloc = 0;
   for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
-    ++count;
+    ++alloc;
 
   elf_elfheader (abfd)->e_phoff = bed->s->sizeof_ehdr;
   elf_elfheader (abfd)->e_phentsize = bed->s->sizeof_phdr;
-  elf_elfheader (abfd)->e_phnum = count;
+  elf_elfheader (abfd)->e_phnum = alloc;
 
-  if (count == 0)
-    {
-      elf_tdata (abfd)->next_file_pos = bed->s->sizeof_ehdr;
-      return TRUE;
-    }
-
-  /* If we already counted the number of program segments, make sure
-     that we allocated enough space.  This happens when SIZEOF_HEADERS
-     is used in a linker script.  */
-  alloc = elf_tdata (abfd)->program_header_size / bed->s->sizeof_phdr;
-  if (alloc != 0 && count > alloc)
-    {
-      ((*_bfd_error_handler)
-       (_("%B: Not enough room for program headers (allocated %u, need %u)"),
-	abfd, alloc, count));
-      print_segment_map (abfd);
-      bfd_set_error (bfd_error_bad_value);
-      return FALSE;
-    }
+  if (elf_tdata (abfd)->program_header_size == 0)
+    elf_tdata (abfd)->program_header_size = alloc * bed->s->sizeof_phdr;
+  else
+    BFD_ASSERT (elf_tdata (abfd)->program_header_size
+		== alloc * bed->s->sizeof_phdr);
 
   if (alloc == 0)
     {
-      alloc = count;
-      elf_tdata (abfd)->program_header_size = alloc * bed->s->sizeof_phdr;
+      elf_tdata (abfd)->next_file_pos = bed->s->sizeof_ehdr;
+      return TRUE;
     }
 
   phdrs = bfd_alloc2 (abfd, alloc, sizeof (Elf_Internal_Phdr));
@@ -4527,13 +4574,6 @@ assign_file_positions_for_load_sections (bfd *abfd,
 	}
     }
 
-  /* Clear out any program headers we allocated but did not use.  */
-  for (; count < alloc; count++, p++)
-    {
-      memset (p, 0, sizeof *p);
-      p->p_type = PT_NULL;
-    }
-
   elf_tdata (abfd)->next_file_pos = off;
   return TRUE;
 }
@@ -4709,112 +4749,6 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
   return TRUE;
 }
 
-/* Get the size of the program header.
-
-   If this is called by the linker before any of the section VMA's are set, it
-   can't calculate the correct value for a strange memory layout.  This only
-   happens when SIZEOF_HEADERS is used in a linker script.  In this case,
-   SORTED_HDRS is NULL and we assume the normal scenario of one text and one
-   data segment (exclusive of .interp and .dynamic).
-
-   ??? User written scripts must either not use SIZEOF_HEADERS, or assume there
-   will be two segments.  */
-
-static bfd_size_type
-get_program_header_size (bfd *abfd, struct bfd_link_info *info)
-{
-  size_t segs;
-  asection *s;
-  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
-
-  /* We can't return a different result each time we're called.  */
-  if (elf_tdata (abfd)->program_header_size != 0)
-    return elf_tdata (abfd)->program_header_size;
-
-  if (elf_tdata (abfd)->segment_map != NULL)
-    {
-      struct elf_segment_map *m;
-
-      segs = 0;
-      for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
-	++segs;
-      elf_tdata (abfd)->program_header_size = segs * bed->s->sizeof_phdr;
-      return elf_tdata (abfd)->program_header_size;
-    }
-
-  /* Assume we will need exactly two PT_LOAD segments: one for text
-     and one for data.  */
-  segs = 2;
-
-  s = bfd_get_section_by_name (abfd, ".interp");
-  if (s != NULL && (s->flags & SEC_LOAD) != 0)
-    {
-      /* If we have a loadable interpreter section, we need a
-	 PT_INTERP segment.  In this case, assume we also need a
-	 PT_PHDR segment, although that may not be true for all
-	 targets.  */
-      segs += 2;
-    }
-
-  if (bfd_get_section_by_name (abfd, ".dynamic") != NULL)
-    {
-      /* We need a PT_DYNAMIC segment.  */
-      ++segs;
-    }
-
-  if (elf_tdata (abfd)->eh_frame_hdr)
-    {
-      /* We need a PT_GNU_EH_FRAME segment.  */
-      ++segs;
-    }
-
-  if (elf_tdata (abfd)->stack_flags)
-    {
-      /* We need a PT_GNU_STACK segment.  */
-      ++segs;
-    }
-
-  if (elf_tdata (abfd)->relro)
-    {
-      /* We need a PT_GNU_RELRO segment.  */
-      ++segs;
-    }
-
-  for (s = abfd->sections; s != NULL; s = s->next)
-    {
-      if ((s->flags & SEC_LOAD) != 0
-	  && strncmp (s->name, ".note", 5) == 0)
-	{
-	  /* We need a PT_NOTE segment.  */
-	  ++segs;
-	}
-    }
-
-  for (s = abfd->sections; s != NULL; s = s->next)
-    {
-      if (s->flags & SEC_THREAD_LOCAL)
-	{
-	  /* We need a PT_TLS segment.  */
-	  ++segs;
-	  break;
-	}
-    }
-
-  /* Let the backend count up any program headers it might need.  */
-  if (bed->elf_backend_additional_program_headers)
-    {
-      int a;
-
-      a = (*bed->elf_backend_additional_program_headers) (abfd, info);
-      if (a == -1)
-	abort ();
-      segs += a;
-    }
-
-  elf_tdata (abfd)->program_header_size = segs * bed->s->sizeof_phdr;
-  return elf_tdata (abfd)->program_header_size;
-}
-
 /* Work out the file positions of all the sections.  This is called by
    _bfd_elf_compute_section_file_positions.  All the section sizes and
    VMAs must be known before this is called.
@@ -7118,11 +7052,24 @@ _bfd_elf_find_inliner_info (bfd *abfd,
 int
 _bfd_elf_sizeof_headers (bfd *abfd, struct bfd_link_info *info)
 {
-  int ret;
+  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
+  int ret = bed->s->sizeof_ehdr;
 
-  ret = get_elf_backend_data (abfd)->s->sizeof_ehdr;
   if (!info->relocatable)
-    ret += get_program_header_size (abfd, info);
+    {
+      struct elf_segment_map *m;
+      bfd_size_type phdr_size = 0;
+
+      for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+	phdr_size += bed->s->sizeof_phdr;
+
+      if (phdr_size == 0)
+	phdr_size = get_program_header_size (abfd, info);
+
+      elf_tdata (abfd)->program_header_size = phdr_size;
+      ret += phdr_size;
+    }
+
   return ret;
 }
 
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index bc7bcd1cea..3a7613572d 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -9493,9 +9493,16 @@ elf32_arm_symbian_modify_segment_map (bfd *abfd,
   dynsec = bfd_get_section_by_name (abfd, ".dynamic");
   if (dynsec)
     {
-      m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
-      m->next = elf_tdata (abfd)->segment_map;
-      elf_tdata (abfd)->segment_map = m;
+      for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next)
+	if (m->p_type == PT_DYNAMIC)
+	  break;
+
+      if (m == NULL)
+	{
+	  m = _bfd_elf_make_dynamic_segment (abfd, dynsec);
+	  m->next = elf_tdata (abfd)->segment_map;
+	  elf_tdata (abfd)->segment_map = m;
+	}
     }
 
   /* Also call the generic arm routine.  */
diff --git a/bfd/elf32-bfin.c b/bfd/elf32-bfin.c
index 661d4bdd24..ed3db10a2b 100644
--- a/bfd/elf32-bfin.c
+++ b/bfd/elf32-bfin.c
@@ -4234,8 +4234,11 @@ elf32_bfinfdpic_modify_segment_map (bfd *output_bfd,
 	  /* Add the stack section to the PT_GNU_STACK segment,
 	     such that its size and alignment requirements make it
 	     to the segment.  */
-	  m->sections[m->count] = sec;
-	  m->count++;
+	  if (m->count == 0)
+	    {
+	      m->sections[m->count] = sec;
+	      m->count++;
+	    }
 	}
     }
 
diff --git a/bfd/elf32-frv.c b/bfd/elf32-frv.c
index 1758e27591..de2358be34 100644
--- a/bfd/elf32-frv.c
+++ b/bfd/elf32-frv.c
@@ -5757,8 +5757,11 @@ elf32_frvfdpic_modify_segment_map (bfd *output_bfd,
 	  /* Add the stack section to the PT_GNU_STACK segment,
 	     such that its size and alignment requirements make it
 	     to the segment.  */
-	  m->sections[m->count] = sec;
-	  m->count++;
+	  if (m->count == 0)
+	    {
+	      m->sections[m->count] = sec;
+	      m->count++;
+	    }
 	}
     }
 
diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c
index 2119dcc03d..6a013f8165 100644
--- a/bfd/elf32-i370.c
+++ b/bfd/elf32-i370.c
@@ -1440,19 +1440,9 @@ i370_noop (void)
   return 1;
 }
 
-/* We need to define these at least as no-ops to link glibc ld.so.  */
-
-#define elf_backend_add_symbol_hook \
-  (bfd_boolean (*) \
-     (bfd *, struct bfd_link_info *, Elf_Internal_Sym *, \
-      const char **, flagword *, asection **, bfd_vma *)) i370_noop
 #define elf_backend_finish_dynamic_symbol \
   (bfd_boolean (*) \
      (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, \
       Elf_Internal_Sym *)) i370_noop
-#define elf_backend_additional_program_headers \
-  (int (*) (bfd *, struct bfd_link_info *)) i370_noop
-#define elf_backend_modify_segment_map \
-  (bfd_boolean (*) (bfd *, struct bfd_link_info *)) i370_noop
 
 #include "elf32-target.h"
diff --git a/bfd/elf64-hppa.c b/bfd/elf64-hppa.c
index 143c84a927..7fcc94f6b3 100644
--- a/bfd/elf64-hppa.c
+++ b/bfd/elf64-hppa.c
@@ -204,9 +204,6 @@ static bfd_boolean elf64_hppa_finish_dynamic_symbol
   PARAMS ((bfd *, struct bfd_link_info *,
 	   struct elf_link_hash_entry *, Elf_Internal_Sym *));
 
-static bfd_boolean elf64_hppa_modify_segment_map
-  PARAMS ((bfd *, struct bfd_link_info *));
-
 static enum elf_reloc_type_class elf64_hppa_reloc_type_class
   PARAMS ((const Elf_Internal_Rela *));
 
@@ -2641,9 +2638,8 @@ elf64_hppa_additional_program_headers (bfd *abfd,
    existence of a .interp section.  */
 
 static bfd_boolean
-elf64_hppa_modify_segment_map (abfd, info)
-     bfd *abfd;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
+elf64_hppa_modify_segment_map (bfd *abfd,
+			       struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   struct elf_segment_map *m;
   asection *s;
diff --git a/bfd/elfxx-ia64.c b/bfd/elfxx-ia64.c
index e515997aa1..c05796754e 100644
--- a/bfd/elfxx-ia64.c
+++ b/bfd/elfxx-ia64.c
@@ -215,8 +215,6 @@ static bfd_boolean elfNN_ia64_add_symbol_hook
   PARAMS ((bfd *abfd, struct bfd_link_info *info, Elf_Internal_Sym *sym,
 	   const char **namep, flagword *flagsp, asection **secp,
 	   bfd_vma *valp));
-static bfd_boolean elfNN_ia64_modify_segment_map
-  PARAMS ((bfd *, struct bfd_link_info *));
 static bfd_boolean elfNN_ia64_is_local_label_name
   PARAMS ((bfd *abfd, const char *name));
 static bfd_boolean elfNN_ia64_dynamic_symbol_p
@@ -1655,9 +1653,8 @@ elfNN_ia64_additional_program_headers (bfd *abfd,
 }
 
 static bfd_boolean
-elfNN_ia64_modify_segment_map (abfd, info)
-     bfd *abfd;
-     struct bfd_link_info *info ATTRIBUTE_UNUSED;
+elfNN_ia64_modify_segment_map (bfd *abfd,
+			       struct bfd_link_info *info ATTRIBUTE_UNUSED)
 {
   struct elf_segment_map *m, **pm;
   Elf_Internal_Shdr *hdr;
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index a1a7d1ecd4..7d5059e591 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -9230,15 +9230,18 @@ _bfd_mips_elf_modify_segment_map (bfd *abfd,
 		     || (*pm)->p_type == PT_INTERP))
 	    pm = &(*pm)->next;
 
-	  amt = sizeof (struct elf_segment_map);
-	  options_segment = bfd_zalloc (abfd, amt);
-	  options_segment->next = *pm;
-	  options_segment->p_type = PT_MIPS_OPTIONS;
-	  options_segment->p_flags = PF_R;
-	  options_segment->p_flags_valid = TRUE;
-	  options_segment->count = 1;
-	  options_segment->sections[0] = s;
-	  *pm = options_segment;
+	  if (*pm == NULL || (*pm)->p_type != PT_MIPS_OPTIONS)
+	    {
+	      amt = sizeof (struct elf_segment_map);
+	      options_segment = bfd_zalloc (abfd, amt);
+	      options_segment->next = *pm;
+	      options_segment->p_type = PT_MIPS_OPTIONS;
+	      options_segment->p_flags = PF_R;
+	      options_segment->p_flags_valid = TRUE;
+	      options_segment->count = 1;
+	      options_segment->sections[0] = s;
+	      *pm = options_segment;
+	    }
 	}
     }
   else
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 6347778ab8..ca2b57493a 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,47 @@
+2006-06-20  Alan Modra  <amodra@bigpond.net.au>
+
+	* Makefile.am (ELF_DEPS): Define.  Use in emul file deps.  Fix
+	many ELF emul file deps that incorrectly said they needed elf32.em
+	instead of generic.em.  Add genelf.em as required.
+	* Makefile.in: Regenerate.
+	* ldlang.c (lang_process): Call ldemul_finish before
+	lang_check_section_addresses.
+	* emulparams/arcelf.sh: Generic elf target needs genelf.
+	* emulparams/d30v_e.sh: Likewise.
+	* emulparams/d30v_o.sh: Likewise.
+	* emulparams/d30velf.sh: Likewise.
+	* emulparams/elf32_dlx.sh: Likewise.
+	* emulparams/elf32_i860.sh: Likewise.
+	* emulparams/elf32fr30.sh: Likewise.
+	* emulparams/elf32frv.sh: Likewise.
+	* emulparams/elf32iq10.sh: Likewise.
+	* emulparams/elf32iq2000.sh: Likewise.
+	* emulparams/elf32mt.sh: Likewise.
+	* emulparams/mn10200.sh: Likewise.
+	* emulparams/or32.sh: Likewise.
+	* emulparams/or32elf.sh: Likewise.
+	* emulparams/pjelf.sh: Likewise.
+	* emulparams/msp430all.sh: Likewise.  Extract common entries.
+	* emulparams/pjlelf.sh: Include pjelf.sh.
+	* emulparams/elf32frvfd.sh (EXTRA_EM_FILE): Unset.
+	* emulparams/mn10300.sh (EXTRA_EM_FILE): Unset.
+	* emultempl/elf-generic.em: New file.
+	* emultempl/genelf.em: New file.
+	* emultempl/elf32.em: Include elf-generic.em.
+	(gld${EMULATION_NAME}_layout_sections_again): Delete.
+	(gld${EMULATION_NAME}_finish): Call gld${EMULATION_NAME}_map_segments.
+	* emultempl/hppaelf.em (hppaelf_layout_sections_again): Likewise.
+	(gld${EMULATION_NAME}_finish): Rename from hppaelf_finish.  Call
+	gld${EMULATION_NAME}_map_segments.
+	(LDEMUL_FINISH): Update.
+	* emultempl/mmo.em: Correct comment.  Include elf-bfd.h and
+	source elf-generic.em.
+	(mmo_finish): Call gld${EMULATION_NAME}_map_segments.
+	* emultempl/ppc64elf.em (ppc_layout_sections_again): Likewise.
+	(gld${EMULATION_NAME}_finish): Rename from ppc_finish.  Call
+	gld${EMULATION_NAME}_map_segments.
+	(LDEMUL_FINISH): Update.
+
 2006-06-19  Alan Modra  <amodra@bigpond.net.au>
 
 	* ldexp.c (fold_name): Adjust bfd_sizeof_headers call.
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 6083035e96..be61372d4f 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -475,6 +475,7 @@ stringify.sed: ${srcdir}/emultempl/$(STRINGIFY)
 
 GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh "${srcdir}" "${libdir}" "${prefix}" "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@
 GEN_DEPENDS = $(srcdir)/genscripts.sh stringify.sed
+ELF_DEPS = $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/elf-generic.em
 
 @TDIRS@
 
@@ -493,56 +494,57 @@ eaixrs6.c: $(srcdir)/emulparams/aixrs6.sh \
 ealpha.c: $(srcdir)/emulparams/alpha.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/alpha.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} alpha "$(tdir_alpha)"
-earcelf.c: $(srcdir)/emulparams/arcelf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+earcelf.c: $(srcdir)/emulparams/arcelf.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} arcelf "$(tdir_arcelf)"
 earmelf.c: $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf "$(tdir_armelf)"
 earmelfb.c: $(srcdir)/emulparams/armelfb.sh $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb "$(tdir_armelfb)"
 earmelf_fbsd.c: $(srcdir)/emulparams/armelf_fbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_fbsd "$(tdir_armelf_fbsd)"
 earmelf_linux.c: $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_linux "$(tdir_armelf_linux)"
 earmelf_linux_eabi.c: $(srcdir)/emulparams/armelf_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_linux_eabi "$(tdir_armelf_linux_abi)"
 earmelfb_linux.c: $(srcdir)/emulparams/armelfb_linux.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_linux "$(tdir_armelfb_linux)"
 earmelfb_linux_eabi.c: $(srcdir)/emulparams/armelfb_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_linux_eabi "$(tdir_armelfb_linux_abi)"
 earmelf_nbsd.c: $(srcdir)/emulparams/armelf_nbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_nbsd "$(tdir_armelf_nbsd)"
 earmelfb_nbsd.c: $(srcdir)/emulparams/armelfb_nbsd.sh \
   $(srcdir)/emulparams/armelf_nbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_nbsd "$(tdir_armelfb_nbsd)"
 earmelf_vxworks.c: $(srcdir)/emulparams/armelf_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/elf.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_vxworks "$(tdir_armelf)"
@@ -559,7 +561,7 @@ earmnbsd.c:	$(srcdir)/emulparams/armnbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armnbsd "$(tdir_armnbsd)"
 earmnto.c: $(srcdir)/emulparams/armnto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armnto "$(tdir_armnto)"
 earm_epoc_pe.c: $(srcdir)/emulparams/arm_epoc_pe.sh \
@@ -569,32 +571,32 @@ earmpe.c: $(srcdir)/emulparams/armpe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armpe "$(tdir_armpe)"
 earmsymbian.c: $(srcdir)/emulparams/armsymbian.sh \
-  $(srcdir)/emulparams/armelf.sh $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emulparams/armelf.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/armbpabi.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} armsymbian "$(tdir_armelf)"
-eavr2.c: $(srcdir)/emulparams/avr2.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr2.c: $(srcdir)/emulparams/avr2.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr2 "$(tdir_avr2)"
-eavr1.c: $(srcdir)/emulparams/avr1.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr1.c: $(srcdir)/emulparams/avr1.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr1 "$(tdir_avr2)"
-eavr3.c: $(srcdir)/emulparams/avr3.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr3.c: $(srcdir)/emulparams/avr3.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr3 "$(tdir_avr2)"
-eavr4.c: $(srcdir)/emulparams/avr4.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr4.c: $(srcdir)/emulparams/avr4.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr4 "$(tdir_avr2)"
-eavr5.c: $(srcdir)/emulparams/avr5.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr5.c: $(srcdir)/emulparams/avr5.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr5 "$(tdir_avr2)"
-eavr6.c: $(srcdir)/emulparams/avr6.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr6.c: $(srcdir)/emulparams/avr6.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr6 "$(tdir_avr2)"
 ecoff_i860.c: $(srcdir)/emulparams/coff_i860.sh \
@@ -607,332 +609,354 @@ ecrisaout.c: $(srcdir)/emulparams/crisaout.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/crisaout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} crisaout "$(tdir_cris)"
 ecriself.c: $(srcdir)/emulparams/criself.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} criself "$(tdir_cris)"
 ecrislinux.c: $(srcdir)/emulparams/crislinux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} crislinux "$(tdir_cris)"
 ed10velf.c: $(srcdir)/emulparams/d10velf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d10velf "$(tdir_d10v)"
-ed30velf.c: $(srcdir)/emulparams/d30velf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30velf.c: $(srcdir)/emulparams/d30velf.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30velf "$(tdir_d30v)"
-ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30v_o "$(tdir_d30v)"
-ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30v_e "$(tdir_d30v)"
 edelta68.c: $(srcdir)/emulparams/delta68.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/delta68.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} delta68 "$(tdir_delta68)"
 eelf32bfin.c: $(srcdir)/emulparams/bfin.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bfin "$(tdir_elf32bfin)" bfin
 eelf32bfinfd.c: $(srcdir)/emulparams/elf32bfinfd.sh $(srcdir)/emulparams/bfin.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bfinfd "$(tdir_elf32bfinfd)" elf32bfinfd
 eelf32_dlx.c: $(srcdir)/emulparams/elf32_dlx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_dlx "$(tdir_elf32_dlx)"
 eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16x "$(tdir_xc16x)"
 eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16xl "$(tdir_xc16xl)"
 eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16xs "$(tdir_xc16xs)"		
 eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/xstormy16.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xstormy16 "$(tdir_xstormy16)"
 eelf32am33lin.c: $(srcdir)/emulparams/elf32am33lin.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32am33lin "$(tdir_mn10300)"
 eelf32vax.c: $(srcdir)/emulparams/elf32vax.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32vax "$(tdir_elf32vax)"
 eelf32xtensa.c: $(srcdir)/emulparams/elf32xtensa.sh \
-  $(srcdir)/emulparams/xtensa-config.sh $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emulparams/xtensa-config.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/xtensaelf.em $(INCDIR)/xtensa-config.h \
   $(BFDDIR)/elf-bfd.h $(BFDDIR)/libbfd.h $(INCDIR)/elf/xtensa.h \
   $(srcdir)/scripttempl/elfxtensa.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xtensa "$(tdir_elf32xtensa)"
 eelf32fr30.c: $(srcdir)/emulparams/elf32fr30.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32fr30 "$(tdir_fr30)"
 eelf32frv.c: $(srcdir)/emulparams/elf32frv.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32frv "$(tdir_frv)"
+eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
+  $(srcdir)/emulparams/elf32frv.sh \
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32frvfd "$(tdir_frv)"
 eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32mcore "$(tdir_mcore)"
 em32relf.c: $(srcdir)/emulparams/m32relf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32relf "$(tdir_m32r)"
 em32rlelf.c: $(srcdir)/emulparams/m32rlelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32rlelf "$(tdir_m32rlelf)"
 em32relf_linux.c: $(srcdir)/emulparams/m32relf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32relf_linux "$(tdir_m32relf_linux)"
 em32rlelf_linux.c: $(srcdir)/emulparams/m32rlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32rlelf_linux "$(tdir_m32rlelf_linux)"
 eelf32_sparc.c: $(srcdir)/emulparams/elf32_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_sparc "$(tdir_elf32_sparc)"
 eelf32_sparc_vxworks.c: $(srcdir)/emulparams/elf32_sparc_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/elf32_sparc.sh \
-  $(srcdir)/emultempl/vxworks.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/vxworks.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_sparc_vxworks "$(tdir_elf32_sparc_vxworks)"
 eelf32_i860.c: $(srcdir)/emulparams/elf32_i860.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_i860 "$(tdir_elf32_i860)"
 eelf32_i960.c: $(srcdir)/emulparams/elf32_i960.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_i960 "$(tdir_elf32_i960)"
 eelf32b4300.c: $(srcdir)/emulparams/elf32b4300.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32b4300 "$(tdir_elf32b4300)"
 eelf32cr16c.c: $(srcdir)/emulparams/elf32cr16c.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf32cr16c.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32cr16c "$(tdir_elf32cr16c)"
 eelf32bmip.c: $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bmip "$(tdir_elf32bmip)"
 eelf32bsmip.c: $(srcdir)/emulparams/elf32bsmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bsmip "$(tdir_elf32bsmip)"
 eelf32btsmip.c: $(srcdir)/emulparams/elf32btsmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32btsmip "$(tdir_elf32btsmip)"
 eelf32crx.c: $(srcdir)/emulparams/elf32crx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/crxelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/crxelf.em \
   $(srcdir)/scripttempl/elf32crx.sc ${GEN_DEPENDS} 
 	${GENSCRIPTS} elf32crx "$(tdir_elf32crx)"
 eelf32btsmipn32.c: $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32btsmipn32 "$(tdir_elf32btsmipn32)"
 eelf32ltsmip.c: $(srcdir)/emulparams/elf32ltsmip.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ltsmip "$(tdir_elf32ltsmip)"
 eelf32ltsmipn32.c: $(srcdir)/emulparams/elf32ltsmipn32.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ltsmipn32 "$(tdir_elf32ltsmipn32)"
 eelf32ebmip.c: $(srcdir)/emulparams/elf32ebmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ebmip "$(tdir_elf32ebmip)"
 eelf32ebmipvxworks.c: $(srcdir)/emulparams/elf32ebmipvxworks.sh \
   $(srcdir)/emulparams/elf32ebmip.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ebmipvxworks "$(tdir_elf32ebmipvxworks)"
 eelf32elmip.c: $(srcdir)/emulparams/elf32elmip.sh \
   $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32elmip "$(tdir_elf32elmip)"
 eelf32elmipvxworks.c: $(srcdir)/emulparams/elf32elmipvxworks.sh \
   $(srcdir)/emulparams/elf32elmip.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32elmipvxworks "$(tdir_elf32elmipvxworks)"
 eelf32bmipn32.c: $(srcdir)/emulparams/elf32bmipn32.sh \
   $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bmipn32 "$(tdir_elf32bmipn32)"
 eelf32l4300.c: $(srcdir)/emulparams/elf32l4300.sh \
   $(srcdir)/emulparams/elf32b4300.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32l4300 "$(tdir_elf32l4300)"
 eelf32lmip.c: $(srcdir)/emulparams/elf32lmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lmip "$(tdir_elf32lmip)"
 eelf32mipswindiss.c: $(srcdir)/emulparams/elf32mipswindiss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32mipswindiss "$(tdir_elf32mipswindiss)"
+eelf32m32c.c: $(srcdir)/emulparams/elf32m32c.sh \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32m32c "$(tdir_m32c)"
+eelf32mt.c: $(srcdir)/emulparams/elf32mt.sh \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32mt "$(tdir_mt)"
 eelf32lppc.c: $(srcdir)/emulparams/elf32lppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppc "$(tdir_elf32lppc)"
 eelf32lppcnto.c: $(srcdir)/emulparams/elf32lppcnto.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppcnto "$(tdir_elf32lppcnto)"
 eelf32lppcsim.c: $(srcdir)/emulparams/elf32lppcsim.sh \
   $(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppcsim "$(tdir_elf32lppcsim)"
 eelf32ppcnto.c: $(srcdir)/emulparams/elf32ppcnto.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcnto "$(tdir_elf32ppcnto)"
 eelf32ppcwindiss.c: $(srcdir)/emulparams/elf32ppcwindiss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcwindiss "$(tdir_elf32ppcwindiss)"
 eelf32ppcvxworks.c: $(srcdir)/emulparams/elf32ppcvxworks.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/vxworks.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/vxworks.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcvxworks "$(tdir_elf32ppcvxworks)"
 eelf32lsmip.c: $(srcdir)/emulparams/elf32lsmip.sh \
   $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lsmip "$(tdir_elf32lsmip)"
 eelf32openrisc.c: $(srcdir)/emulparams/elf32openrisc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32openrisc "$(tdir_openrisc)"
 eelf32ppc.c: $(srcdir)/emulparams/elf32ppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppc "$(tdir_elf32ppc)"
 eelf32ppc_fbsd.c: $(srcdir)/emulparams/elf32ppc_fbsd.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppc_fbsd "$(tdir_elf32ppc_fbsd)"
 eelf32ppcsim.c: $(srcdir)/emulparams/elf32ppcsim.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcsim "$(tdir_elf32ppcsim)"
 eelf32ppclinux.c: $(srcdir)/emulparams/elf32ppclinux.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppclinux "$(tdir_elf32ppclinux)"
 eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64ppc "$(tdir_elf64ppc)"
 eelf64lppc.c: $(srcdir)/emulparams/elf64lppc.sh \
   $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64lppc "$(tdir_elf64lppc)"
 eelf32i370.c: $(srcdir)/emulparams/elf32i370.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfi370.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elfi370.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32i370 "$(tdir_elf32i370)"
 eelf32ip2k.c: $(srcdir)/emulparams/elf32ip2k.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/ip2k.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/ip2k.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ip2k "$(tdir_ip2k)"
 eelf32iq2000.c: $(srcdir)/emulparams/elf32iq2000.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32iq2000 "$(tdir_iq2000)"
 eelf32iq10.c: $(srcdir)/emulparams/elf32iq10.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32iq10 "$(tdir_iq10)"
 eelf64alpha.c: $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha "$(tdir_elf64alpha)"
 eelf64alpha_fbsd.c: $(srcdir)/emulparams/elf64alpha_fbsd.sh \
   $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha_fbsd "$(tdir_elf64alpha_fbsd)"
 eelf64alpha_nbsd.c: $(srcdir)/emulparams/elf64alpha_nbsd.sh \
   $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha_nbsd "$(tdir_elf64alpha_nbsd)"
 eelf64hppa.c: $(srcdir)/emulparams/elf64hppa.sh \
   $(srcdir)/emulparams/hppa64linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64hppa "$(tdir_elf64hppa)"
 eelf64_aix.c: $(srcdir)/emulparams/elf64_aix.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_aix "$(tdir_elf64_aix)"
 eelf64_ia64.c: $(srcdir)/emulparams/elf64_ia64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/ia64elf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/ia64elf.em \
   $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_ia64 "$(tdir_elf64_ia64)"
 eelf64_ia64_fbsd.c: $(srcdir)/emulparams/elf64_ia64_fbsd.sh \
   $(srcdir)/emulparams/elf64_ia64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/ia64elf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/ia64elf.em \
   $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_ia64_fbsd "$(tdir_elf64_ia64_fbsd)"
 eelf64_s390.c: $(srcdir)/emulparams/elf64_s390.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_s390 "$(tdir_elf64_s390)"
 eelf64_sparc.c: $(srcdir)/emulparams/elf64_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_sparc "$(tdir_elf64_sparc)"
 eelf64_sparc_fbsd.c: $(srcdir)/emulparams/elf64_sparc_fbsd.sh \
   $(srcdir)/emulparams/elf64_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_sparc_fbsd "$(tdir_elf64_sparc_fbsd)"
 eelf64bmip.c: $(srcdir)/emulparams/elf64bmip.sh \
   $(srcdir)/emulparams/elf32bmipn32.sh $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64bmip "$(tdir_elf64bmip)"
 eelf64mmix.c: $(srcdir)/emulparams/elf64mmix.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/mmix-elfnmmo.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/mmix-elfnmmo.em \
   $(srcdir)/emultempl/mmixelf.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64mmix "$(tdir_elf64mmix)"
 emmo.c: $(srcdir)/emulparams/mmo.sh $(srcdir)/emultempl/mmix-elfnmmo.em \
-  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/mmo.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/emultempl/mmo.em \
   $(srcdir)/scripttempl/mmo.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mmo "$(tdir_mmo)"
 eelf64btsmip.c: $(srcdir)/emulparams/elf64btsmip.sh \
   $(srcdir)/emulparams/elf32bmipn32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64btsmip "$(tdir_elf64btsmip)"
 eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
   $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf32bmipn32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64ltsmip "$(tdir_elf64ltsmip)"
 eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386 "$(tdir_elf_i386)"
 eelf_x86_64.c: $(srcdir)/emulparams/elf_x86_64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_x86_64 "$(tdir_elf_x86_64)"
 eelf_x86_64_fbsd.c: $(srcdir)/emulparams/elf_x86_64_fbsd.sh \
   $(srcdir)/emulparams/elf_x86_64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_x86_64_fbsd "$(tdir_elf_x86_64_fbsd)"
 eelf_i386_be.c: $(srcdir)/emulparams/elf_i386_be.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_be "$(tdir_elf_i386_be)"
 eelf_i386_chaos.c: $(srcdir)/emulparams/elf_i386_chaos.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf_chaos.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf_chaos.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_chaos "$(tdir_elf_i386_chaos)"
 eelf_i386_fbsd.c: $(srcdir)/emulparams/elf_i386_fbsd.sh \
   $(srcdir)/emulparams/elf_i386.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_fbsd "$(tdir_elf_i386_fbsd)"
 eelf_i386_ldso.c: $(srcdir)/emulparams/elf_i386_ldso.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_ldso "$(tdir_elf_i386_ldso)"
 eelf_i386_vxworks.c: $(srcdir)/emulparams/elf_i386_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emultempl/vxworks.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_vxworks "$(tdir_elf_i386_vxworks)"
 eelf_s390.c: $(srcdir)/emulparams/elf_s390.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_s390 "$(tdir_elf_s390)"
 egld960.c: $(srcdir)/emulparams/gld960.sh \
   $(srcdir)/emultempl/gld960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
@@ -962,31 +986,31 @@ eh8300sxn.c: $(srcdir)/emulparams/h8300sxn.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/h8300sxn.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxn "$(tdir_h8300sxn)"
 eh8300elf.c: $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300elf "$(tdir_h8300elf)"
 eh8300helf.c: $(srcdir)/emulparams/h8300helf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300helf "$(tdir_h8300helf)"
 eh8300self.c: $(srcdir)/emulparams/h8300self.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300self "$(tdir_h8300self)"
 eh8300hnelf.c: $(srcdir)/emulparams/h8300hnelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300hnelf "$(tdir_h8300hnelf)"
 eh8300snelf.c: $(srcdir)/emulparams/h8300snelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300snelf "$(tdir_h8300snelf)"
 eh8300sxelf.c: $(srcdir)/emulparams/h8300sxelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxelf "$(tdir_h8300sxelf)"
 eh8300sxnelf.c: $(srcdir)/emulparams/h8300sxnelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxnelf "$(tdir_h8300sxnelf)"
 eh8500.c: $(srcdir)/emulparams/h8500.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/h8500.sc ${GEN_DEPENDS}
@@ -1010,24 +1034,24 @@ ehp3hpux.c: $(srcdir)/emulparams/hp3hpux.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hp3hpux "$(tdir_hp3hpux)"
 ehppaelf.c: $(srcdir)/emulparams/hppaelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/hppaelf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppaelf "$(tdir_hppaelf)"
 ehppalinux.c: $(srcdir)/emulparams/hppalinux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppalinux "$(tdir_hppalinux)"
 ehppanbsd.c: $(srcdir)/emulparams/hppanbsd.sh \
   $(srcdir)/emulparams/hppaelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppanbsd "$(tdir_hppanbsd)"
 ehppaobsd.c: $(srcdir)/emulparams/hppaobsd.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppaobsd "$(tdir_hppaobsd)"
 ehppa64linux.c: $(srcdir)/emulparams/hppa64linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppa64linux "$(tdir_hppa64linux)"
 ei386aout.c: $(srcdir)/emulparams/i386aout.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -1048,13 +1072,13 @@ ei386linux.c: $(srcdir)/emulparams/i386linux.sh \
   $(srcdir)/emultempl/linux.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386linux "$(tdir_i386linux)"
 ei386lynx.c: $(srcdir)/emulparams/i386lynx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386lynx "$(tdir_i386lynx)"
 ei386mach.c: $(srcdir)/emulparams/i386mach.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386mach "$(tdir_i386mach)"
 ei386moss.c: $(srcdir)/emulparams/i386moss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386moss "$(tdir_i386moss)"
 ei386msdos.c: $(srcdir)/emulparams/i386msdos.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/i386msdos.sc ${GEN_DEPENDS}
@@ -1063,10 +1087,10 @@ ei386nbsd.c:	$(srcdir)/emulparams/i386nbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nbsd "$(tdir_i386nbsd)"
 ei386nto.c:	$(srcdir)/emulparams/i386nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nto "$(tdir_i386nto)"
 ei386nw.c:	$(srcdir)/emulparams/i386nw.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nw "$(tdir_i386nw)"
 ei386pe.c: $(srcdir)/emulparams/i386pe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
@@ -1078,19 +1102,19 @@ elnk960.c: $(srcdir)/emulparams/lnk960.sh \
   $(srcdir)/emultempl/lnk960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} lnk960 "$(tdir_lnk960)"
 em68hc11elf.c: $(srcdir)/emulparams/m68hc11elf.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc11.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc11elf "$(tdir_m68hc11)"
 em68hc11elfb.c: $(srcdir)/emulparams/m68hc11elfb.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc11.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc11elfb "$(tdir_m68hc11b)"
 em68hc12elf.c: $(srcdir)/emulparams/m68hc12elf.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc12.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc12elf "$(tdir_m68hc12)"
 em68hc12elfb.c: $(srcdir)/emulparams/m68hc12elfb.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc12.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc12elfb "$(tdir_m68hc12b)"
 em68k4knbsd.c:	$(srcdir)/emulparams/m68k4knbsd.sh \
@@ -1106,12 +1130,12 @@ em68kcoff.c: $(srcdir)/emulparams/m68kcoff.sh \
   $(srcdir)/emultempl/m68kcoff.em $(srcdir)/scripttempl/m68kcoff.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kcoff "$(tdir_m68kcoff)"
 em68kelf.c: $(srcdir)/emulparams/m68kelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/m68kelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/m68kelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kelf "$(tdir_m68kelf)"
 em68kelfnbsd.c: $(srcdir)/emulparams/m68kelfnbsd.sh \
   $(srcdir)/emulparams/m68kelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/m68kelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/m68kelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kelfnbsd "$(tdir_m68kelfnbsd)"
 em68klinux.c: $(srcdir)/emulparams/m68klinux.sh \
@@ -1121,7 +1145,7 @@ em68knbsd.c:	$(srcdir)/emulparams/m68knbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68knbsd "$(tdir_m68knbsd)"
 em68kpsos.c:	$(srcdir)/emulparams/m68kpsos.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/psos.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/psos.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kpsos "$(tdir_m68kpsos)"
 em88kbcs.c: $(srcdir)/emulparams/m88kbcs.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/m88kbcs.sc ${GEN_DEPENDS}
@@ -1157,245 +1181,305 @@ emipspe.c: $(srcdir)/emulparams/mipspe.sh \
 	${GENSCRIPTS} mipspe "$(tdir_mips)"
 emn10300.c: $(srcdir)/emulparams/mn10300.sh \
   $(srcdir)/emulparams/mn10200.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mn10300 "$(tdir_mn10300)"
 emn10200.c: $(srcdir)/emulparams/mn10200.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mn10200 "$(tdir_mn10200)"
 emsp430x110.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x110 "$(tdir_msp430x110)" msp430all
 emsp430x112.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x112 "$(tdir_msp430x112)" msp430all
 emsp430x1101.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1101 "$(tdir_msp430x1101)" msp430all
 emsp430x1111.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1111 "$(tdir_msp430x1111)" msp430all
 emsp430x1121.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1121 "$(tdir_msp430x1121)" msp430all
 emsp430x1122.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1122 "$(tdir_msp430x1122)" msp430all
 emsp430x1132.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1132 "$(tdir_msp430x1132)" msp430all
 emsp430x122.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x122 "$(tdir_msp430x122)" msp430all
 emsp430x123.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x123 "$(tdir_msp430x123)" msp430all
 emsp430x1222.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1222 "$(tdir_msp430x1222)" msp430all
 emsp430x1232.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1232 "$(tdir_msp430x1232)" msp430all
 emsp430x133.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x133 "$(tdir_msp430x133)" msp430all
 emsp430x135.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x135 "$(tdir_msp430x135)" msp430all
 emsp430x1331.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1331 "$(tdir_msp430x1331)" msp430all
 emsp430x1351.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1351 "$(tdir_msp430x1351)" msp430all
 emsp430x147.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x147 "$(tdir_msp430x147)" msp430all
 emsp430x148.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x148 "$(tdir_msp430x148)" msp430all
 emsp430x149.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x149 "$(tdir_msp430x149)" msp430all
 emsp430x155.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x155 "$(tdir_msp430x155)" msp430all
 emsp430x156.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x156 "$(tdir_msp430x156)" msp430all
 emsp430x157.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x157 "$(tdir_msp430x157)" msp430all
 emsp430x167.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x167 "$(tdir_msp430x167)" msp430all
 emsp430x168.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x168 "$(tdir_msp430x168)" msp430all
 emsp430x169.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x169 "$(tdir_msp430x169)" msp430all
 emsp430x1610.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1610 "$(tdir_msp430x1610)" msp430all
 emsp430x1611.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1611 "$(tdir_msp430x1611)" msp430all
 emsp430x1612.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1612 "$(tdir_msp430x1612)" msp430all
 emsp430x2101.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2101 "$(tdir_msp430x2101)" msp430all
 emsp430x2111.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2111 "$(tdir_msp430x2111)" msp430all
 emsp430x2121.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2121 "$(tdir_msp430x2121)" msp430all
 emsp430x2131.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2131 "$(tdir_msp430x2131)" msp430all
 emsp430x311.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x311 "$(tdir_msp430x311)" msp430all
 emsp430x312.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x312 "$(tdir_msp430x312)" msp430all
 emsp430x313.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x313 "$(tdir_msp430x313)" msp430all
 emsp430x314.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x314 "$(tdir_msp430x314)" msp430all
 emsp430x315.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x315 "$(tdir_msp430x315)" msp430all
 emsp430x323.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x323 "$(tdir_msp430x323)" msp430all
 emsp430x325.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x325 "$(tdir_msp430x325)" msp430all
 emsp430x336.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x336 "$(tdir_msp430x336)" msp430all
 emsp430x337.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x337 "$(tdir_msp430x337)" msp430all
 emsp430x412.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x412 "$(tdir_msp430x412)" msp430all
 emsp430x413.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x413 "$(tdir_msp430x413)" msp430all
 emsp430x415.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x415 "$(tdir_msp430x415)" msp430all
 emsp430x417.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x417 "$(tdir_msp430x417)" msp430all
 emsp430xE423.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE423 "$(tdir_msp430xE423)" msp430all
 emsp430xE425.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE425 "$(tdir_msp430xE425)" msp430all
 emsp430xE427.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE427 "$(tdir_msp430xE427)" msp430all
 emsp430xW423.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW423 "$(tdir_msp430xW423)" msp430all
 emsp430xW425.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW425 "$(tdir_msp430xW425)" msp430all
 emsp430xW427.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW427 "$(tdir_msp430xW427)" msp430all
 emsp430xG437.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG437 "$(tdir_msp430xG437)" msp430all
 emsp430xG438.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG438 "$(tdir_msp430xG438)" msp430all
 emsp430xG439.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG439 "$(tdir_msp430xG439)" msp430all
 emsp430x435.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x435 "$(tdir_msp430x435)" msp430all
 emsp430x436.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x436 "$(tdir_msp430x436)" msp430all
 emsp430x437.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x437 "$(tdir_msp430x437)" msp430all
 emsp430x447.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x447 "$(tdir_msp430x447)" msp430all
 emsp430x448.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x448 "$(tdir_msp430x448)" msp430all
 emsp430x449.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x449 "$(tdir_msp430x449)" msp430all
 enews.c: $(srcdir)/emulparams/news.sh \
@@ -1409,7 +1493,8 @@ eor32.c: $(srcdir)/emulparams/or32.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/or32.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} or32 "$(tdir_or32)"
 eor32elf.c: $(srcdir)/emulparams/or32elf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} or32elf "$(tdir_or32elf)"
 epc532macha.c: $(srcdir)/emulparams/pc532macha.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -1418,22 +1503,24 @@ epdp11.c: $(srcdir)/emulparams/pdp11.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pdp11 "$(tdir_pdp11)"
 epjelf.c: $(srcdir)/emulparams/pjelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pjelf "$(tdir_pjelf)"
-epjlelf.c: $(srcdir)/emulparams/pjlelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+epjlelf.c: $(srcdir)/emulparams/pjlelf.sh $(srcdir)/emulparams/pjelf.sh \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pjlelf "$(tdir_pjlelf)"
 eppcmacos.c:	$(srcdir)/emulparams/ppcmacos.sh \
   $(srcdir)/emultempl/aix.em $(srcdir)/scripttempl/aix.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcmacos "$(tdir_ppcmacos)"
 eppcnw.c:	$(srcdir)/emulparams/ppcnw.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcnw "$(tdir_ppcnw)"
 eppcpe.c: $(srcdir)/emulparams/ppcpe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/ppcpe.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcpe "$(tdir_ppcpe)"
 eppclynx.c: $(srcdir)/emulparams/ppclynx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppclynx "$(tdir_ppclynx)"
 eriscix.c: $(srcdir)/emulparams/riscix.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -1442,87 +1529,87 @@ esh.c: $(srcdir)/emulparams/sh.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/sh.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} sh "$(tdir_sh)"
 eshelf.c: $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf "$(tdir_shelf)"
 eshelf32.c: $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32 "$(tdir_shelf32)"
 eshelf32_linux.c: $(srcdir)/emulparams/shelf32_linux.sh \
   $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32_linux "$(tdir_shelf32_linux)"
 eshelf32_nbsd.c: $(srcdir)/emulparams/shelf32_nbsd.sh \
   $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32_nbsd "$(tdir_shelf32_nbsd)"
 eshelf64.c: $(srcdir)/emulparams/shelf64.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf64 "$(tdir_shelf64)"
 eshelf64_nbsd.c: $(srcdir)/emulparams/shelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf64_nbsd "$(tdir_shelf64_nbsd)"
 eshelf_linux.c: $(srcdir)/emulparams/shelf_linux.sh \
   $(srcdir)/emulparams/shlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_linux "$(tdir_shelf_linux)"
 eshlelf_linux.c: $(srcdir)/emulparams/shlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_linux "$(tdir_shlelf_linux)"
 eshelf_nbsd.c: $(srcdir)/emulparams/shelf_nbsd.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_nbsd "$(tdir_shelf_nbsd)"
 eshelf_nto.c: $(srcdir)/emulparams/shelf_nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_nto "$(tdir_shelf_nto)"
 eshlelf_nbsd.c: $(srcdir)/emulparams/shlelf_nbsd.sh \
   $(srcdir)/emulparams/shelf_nbsd.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_nbsd "$(tdir_shlelf_nbsd)"
 eshlelf_nto.c: $(srcdir)/emulparams/shlelf_nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_nto "$(tdir_shlelf_nto)"
 eshlelf.c: $(srcdir)/emulparams/shlelf.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf "$(tdir_shlelf)"
 eshlsymbian.c: $(srcdir)/emulparams/shlsymbian.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf32sh-symbian.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf32sh-symbian.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlsymbian "$(tdir_shlelf)"
 eshlelf32.c: $(srcdir)/emulparams/shlelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h $(srcdir)/emulparams/shelf32.sh \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32 "$(tdir_shlelf32)"
 eshlelf32_linux.c: $(srcdir)/emulparams/shlelf32_linux.sh \
   $(srcdir)/emulparams/shelf32_linux.sh $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32_linux "$(tdir_shlelf32_linux)"
 eshlelf32_nbsd.c: $(srcdir)/emulparams/shlelf32_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32_nbsd "$(tdir_shlelf32_nbsd)"
 eshlelf64.c: $(srcdir)/emulparams/shlelf64.sh \
   $(srcdir)/emulparams/shelf64.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf64 "$(tdir_shlelf64)"
 eshlelf64_nbsd.c: $(srcdir)/emulparams/shlelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf64_nbsd "$(tdir_shlelf64_nbsd)"
 eshl.c: $(srcdir)/emulparams/shl.sh \
   $(srcdir)/emulparams/sh.sh \
@@ -1583,7 +1670,7 @@ evsta.c: $(srcdir)/emulparams/vsta.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} vsta "$(tdir_vsta)"
 ev850.c: $(srcdir)/emulparams/v850.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/v850.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/v850.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} v850 "$(tdir_v850)"
 ew65.c: $(srcdir)/emulparams/w65.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/w65.sc ${GEN_DEPENDS}
@@ -1598,17 +1685,6 @@ ez8001.c: $(srcdir)/emulparams/z8001.sh \
 ez8002.c: $(srcdir)/emulparams/z8002.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/z8000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} z8002 "$(tdir_z8002)"
-eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
-  $(srcdir)/emulparams/elf32frv.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32frvfd "$(tdir_frv)"
-eelf32m32c.c: $(srcdir)/emulparams/elf32m32c.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32m32c "$(tdir_m32c)"
-eelf32mt.c: $(srcdir)/emulparams/elf32mt.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32mt "$(tdir_mt)"
 
 # We need this for automake to use YLWRAP.
 EXTRA_ld_new_SOURCES = deffilep.y
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 6ea730d88d..6633a2fe82 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -658,6 +658,7 @@ POTFILES = $(CFILES) $(HFILES) $(EMULATION_FILES)
 # These all start with e so 'make clean' can find them.
 GENSCRIPTS = LIB_PATH='${LIB_PATH}' $(SHELL) $(srcdir)/genscripts.sh "${srcdir}" "${libdir}" "${prefix}" "${exec_prefix}" @host@ @target@ @target_alias@ "@EMULATION_LIBPATH@" "@NATIVE_LIB_DIRS@" @use_sysroot@
 GEN_DEPENDS = $(srcdir)/genscripts.sh stringify.sed
+ELF_DEPS = $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/elf-generic.em
 
 # We need this for automake to use YLWRAP.
 EXTRA_ld_new_SOURCES = deffilep.y
@@ -1304,56 +1305,57 @@ eaixrs6.c: $(srcdir)/emulparams/aixrs6.sh \
 ealpha.c: $(srcdir)/emulparams/alpha.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/alpha.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} alpha "$(tdir_alpha)"
-earcelf.c: $(srcdir)/emulparams/arcelf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+earcelf.c: $(srcdir)/emulparams/arcelf.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} arcelf "$(tdir_arcelf)"
 earmelf.c: $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf "$(tdir_armelf)"
 earmelfb.c: $(srcdir)/emulparams/armelfb.sh $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb "$(tdir_armelfb)"
 earmelf_fbsd.c: $(srcdir)/emulparams/armelf_fbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_fbsd "$(tdir_armelf_fbsd)"
 earmelf_linux.c: $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_linux "$(tdir_armelf_linux)"
 earmelf_linux_eabi.c: $(srcdir)/emulparams/armelf_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_linux_eabi "$(tdir_armelf_linux_abi)"
 earmelfb_linux.c: $(srcdir)/emulparams/armelfb_linux.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_linux "$(tdir_armelfb_linux)"
 earmelfb_linux_eabi.c: $(srcdir)/emulparams/armelfb_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux_eabi.sh \
   $(srcdir)/emulparams/armelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_linux_eabi "$(tdir_armelfb_linux_abi)"
 earmelf_nbsd.c: $(srcdir)/emulparams/armelf_nbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_nbsd "$(tdir_armelf_nbsd)"
 earmelfb_nbsd.c: $(srcdir)/emulparams/armelfb_nbsd.sh \
   $(srcdir)/emulparams/armelf_nbsd.sh \
   $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armelfb_nbsd "$(tdir_armelfb_nbsd)"
 earmelf_vxworks.c: $(srcdir)/emulparams/armelf_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/armelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/elf.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} armelf_vxworks "$(tdir_armelf)"
@@ -1370,7 +1372,7 @@ earmnbsd.c:	$(srcdir)/emulparams/armnbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armnbsd "$(tdir_armnbsd)"
 earmnto.c: $(srcdir)/emulparams/armnto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/armelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/armelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armnto "$(tdir_armnto)"
 earm_epoc_pe.c: $(srcdir)/emulparams/arm_epoc_pe.sh \
@@ -1380,32 +1382,32 @@ earmpe.c: $(srcdir)/emulparams/armpe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} armpe "$(tdir_armpe)"
 earmsymbian.c: $(srcdir)/emulparams/armsymbian.sh \
-  $(srcdir)/emulparams/armelf.sh $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emulparams/armelf.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/armelf.em $(srcdir)/scripttempl/armbpabi.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} armsymbian "$(tdir_armelf)"
-eavr2.c: $(srcdir)/emulparams/avr2.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr2.c: $(srcdir)/emulparams/avr2.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr2 "$(tdir_avr2)"
-eavr1.c: $(srcdir)/emulparams/avr1.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr1.c: $(srcdir)/emulparams/avr1.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr1 "$(tdir_avr2)"
-eavr3.c: $(srcdir)/emulparams/avr3.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr3.c: $(srcdir)/emulparams/avr3.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr3 "$(tdir_avr2)"
-eavr4.c: $(srcdir)/emulparams/avr4.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr4.c: $(srcdir)/emulparams/avr4.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr4 "$(tdir_avr2)"
-eavr5.c: $(srcdir)/emulparams/avr5.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr5.c: $(srcdir)/emulparams/avr5.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr5 "$(tdir_avr2)"
-eavr6.c: $(srcdir)/emulparams/avr6.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/avr.sc \
+eavr6.c: $(srcdir)/emulparams/avr6.sh $(srcdir)/emultempl/avrelf.em \
+  $(ELF_DEPS) $(srcdir)/scripttempl/avr.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} avr6 "$(tdir_avr2)"
 ecoff_i860.c: $(srcdir)/emulparams/coff_i860.sh \
@@ -1418,332 +1420,354 @@ ecrisaout.c: $(srcdir)/emulparams/crisaout.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/crisaout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} crisaout "$(tdir_cris)"
 ecriself.c: $(srcdir)/emulparams/criself.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} criself "$(tdir_cris)"
 ecrislinux.c: $(srcdir)/emulparams/crislinux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} crislinux "$(tdir_cris)"
 ed10velf.c: $(srcdir)/emulparams/d10velf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elfd10v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d10velf "$(tdir_d10v)"
-ed30velf.c: $(srcdir)/emulparams/d30velf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30velf.c: $(srcdir)/emulparams/d30velf.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30velf "$(tdir_d30v)"
-ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30v_o.c: $(srcdir)/emulparams/d30v_o.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30v_o "$(tdir_d30v)"
-ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
+ed30v_e.c: $(srcdir)/emulparams/d30v_e.sh $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/scripttempl/elfd30v.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} d30v_e "$(tdir_d30v)"
 edelta68.c: $(srcdir)/emulparams/delta68.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/delta68.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} delta68 "$(tdir_delta68)"
 eelf32bfin.c: $(srcdir)/emulparams/bfin.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bfin "$(tdir_elf32bfin)" bfin
 eelf32bfinfd.c: $(srcdir)/emulparams/elf32bfinfd.sh $(srcdir)/emulparams/bfin.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bfinfd "$(tdir_elf32bfinfd)" elf32bfinfd
 eelf32_dlx.c: $(srcdir)/emulparams/elf32_dlx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/dlx.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_dlx "$(tdir_elf32_dlx)"
 eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16x "$(tdir_xc16x)"
 eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16xl "$(tdir_xc16xl)"
 eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xc16xs "$(tdir_xc16xs)"		
 eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/xstormy16.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xstormy16 "$(tdir_xstormy16)"
 eelf32am33lin.c: $(srcdir)/emulparams/elf32am33lin.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32am33lin "$(tdir_mn10300)"
 eelf32vax.c: $(srcdir)/emulparams/elf32vax.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32vax "$(tdir_elf32vax)"
 eelf32xtensa.c: $(srcdir)/emulparams/elf32xtensa.sh \
-  $(srcdir)/emulparams/xtensa-config.sh $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emulparams/xtensa-config.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/xtensaelf.em $(INCDIR)/xtensa-config.h \
   $(BFDDIR)/elf-bfd.h $(BFDDIR)/libbfd.h $(INCDIR)/elf/xtensa.h \
   $(srcdir)/scripttempl/elfxtensa.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32xtensa "$(tdir_elf32xtensa)"
 eelf32fr30.c: $(srcdir)/emulparams/elf32fr30.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32fr30 "$(tdir_fr30)"
 eelf32frv.c: $(srcdir)/emulparams/elf32frv.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32frv "$(tdir_frv)"
+eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
+  $(srcdir)/emulparams/elf32frv.sh \
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32frvfd "$(tdir_frv)"
 eelf32mcore.c: $(srcdir)/emulparams/elf32mcore.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32mcore "$(tdir_mcore)"
 em32relf.c: $(srcdir)/emulparams/m32relf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32relf "$(tdir_m32r)"
 em32rlelf.c: $(srcdir)/emulparams/m32rlelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32rlelf "$(tdir_m32rlelf)"
 em32relf_linux.c: $(srcdir)/emulparams/m32relf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32relf_linux "$(tdir_m32relf_linux)"
 em32rlelf_linux.c: $(srcdir)/emulparams/m32rlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m32rlelf_linux "$(tdir_m32rlelf_linux)"
 eelf32_sparc.c: $(srcdir)/emulparams/elf32_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_sparc "$(tdir_elf32_sparc)"
 eelf32_sparc_vxworks.c: $(srcdir)/emulparams/elf32_sparc_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emulparams/elf32_sparc.sh \
-  $(srcdir)/emultempl/vxworks.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/vxworks.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_sparc_vxworks "$(tdir_elf32_sparc_vxworks)"
 eelf32_i860.c: $(srcdir)/emulparams/elf32_i860.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_i860 "$(tdir_elf32_i860)"
 eelf32_i960.c: $(srcdir)/emulparams/elf32_i960.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32_i960 "$(tdir_elf32_i960)"
 eelf32b4300.c: $(srcdir)/emulparams/elf32b4300.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32b4300 "$(tdir_elf32b4300)"
 eelf32cr16c.c: $(srcdir)/emulparams/elf32cr16c.sh \
-  $(srcdir)/emultempl/elf32.em \
+  $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf32cr16c.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32cr16c "$(tdir_elf32cr16c)"
 eelf32bmip.c: $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bmip "$(tdir_elf32bmip)"
 eelf32bsmip.c: $(srcdir)/emulparams/elf32bsmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bsmip "$(tdir_elf32bsmip)"
 eelf32btsmip.c: $(srcdir)/emulparams/elf32btsmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32btsmip "$(tdir_elf32btsmip)"
 eelf32crx.c: $(srcdir)/emulparams/elf32crx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/crxelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/crxelf.em \
   $(srcdir)/scripttempl/elf32crx.sc ${GEN_DEPENDS} 
 	${GENSCRIPTS} elf32crx "$(tdir_elf32crx)"
 eelf32btsmipn32.c: $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32btsmipn32 "$(tdir_elf32btsmipn32)"
 eelf32ltsmip.c: $(srcdir)/emulparams/elf32ltsmip.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ltsmip "$(tdir_elf32ltsmip)"
 eelf32ltsmipn32.c: $(srcdir)/emulparams/elf32ltsmipn32.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ltsmipn32 "$(tdir_elf32ltsmipn32)"
 eelf32ebmip.c: $(srcdir)/emulparams/elf32ebmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ebmip "$(tdir_elf32ebmip)"
 eelf32ebmipvxworks.c: $(srcdir)/emulparams/elf32ebmipvxworks.sh \
   $(srcdir)/emulparams/elf32ebmip.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ebmipvxworks "$(tdir_elf32ebmipvxworks)"
 eelf32elmip.c: $(srcdir)/emulparams/elf32elmip.sh \
   $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32elmip "$(tdir_elf32elmip)"
 eelf32elmipvxworks.c: $(srcdir)/emulparams/elf32elmipvxworks.sh \
   $(srcdir)/emulparams/elf32elmip.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/vxworks.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/vxworks.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32elmipvxworks "$(tdir_elf32elmipvxworks)"
 eelf32bmipn32.c: $(srcdir)/emulparams/elf32bmipn32.sh \
   $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32bmipn32 "$(tdir_elf32bmipn32)"
 eelf32l4300.c: $(srcdir)/emulparams/elf32l4300.sh \
   $(srcdir)/emulparams/elf32b4300.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32l4300 "$(tdir_elf32l4300)"
 eelf32lmip.c: $(srcdir)/emulparams/elf32lmip.sh \
   $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lmip "$(tdir_elf32lmip)"
 eelf32mipswindiss.c: $(srcdir)/emulparams/elf32mipswindiss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32mipswindiss "$(tdir_elf32mipswindiss)"
+eelf32m32c.c: $(srcdir)/emulparams/elf32m32c.sh \
+  $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32m32c "$(tdir_m32c)"
+eelf32mt.c: $(srcdir)/emulparams/elf32mt.sh \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+	${GENSCRIPTS} elf32mt "$(tdir_mt)"
 eelf32lppc.c: $(srcdir)/emulparams/elf32lppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppc "$(tdir_elf32lppc)"
 eelf32lppcnto.c: $(srcdir)/emulparams/elf32lppcnto.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppcnto "$(tdir_elf32lppcnto)"
 eelf32lppcsim.c: $(srcdir)/emulparams/elf32lppcsim.sh \
   $(srcdir)/emulparams/elf32lppc.sh $(srcdir)/emulparams/elf32ppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lppcsim "$(tdir_elf32lppcsim)"
 eelf32ppcnto.c: $(srcdir)/emulparams/elf32ppcnto.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcnto "$(tdir_elf32ppcnto)"
 eelf32ppcwindiss.c: $(srcdir)/emulparams/elf32ppcwindiss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcwindiss "$(tdir_elf32ppcwindiss)"
 eelf32ppcvxworks.c: $(srcdir)/emulparams/elf32ppcvxworks.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emulparams/vxworks.sh \
-  $(srcdir)/emultempl/vxworks.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/vxworks.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcvxworks "$(tdir_elf32ppcvxworks)"
 eelf32lsmip.c: $(srcdir)/emulparams/elf32lsmip.sh \
   $(srcdir)/emulparams/elf32lmip.sh $(srcdir)/emulparams/elf32bmip.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32lsmip "$(tdir_elf32lsmip)"
 eelf32openrisc.c: $(srcdir)/emulparams/elf32openrisc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32openrisc "$(tdir_openrisc)"
 eelf32ppc.c: $(srcdir)/emulparams/elf32ppc.sh \
   $(srcdir)/emulparams/elf32ppccommon.sh $(srcdir)/emultempl/ppc32elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppc "$(tdir_elf32ppc)"
 eelf32ppc_fbsd.c: $(srcdir)/emulparams/elf32ppc_fbsd.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppc_fbsd "$(tdir_elf32ppc_fbsd)"
 eelf32ppcsim.c: $(srcdir)/emulparams/elf32ppcsim.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppcsim "$(tdir_elf32ppcsim)"
 eelf32ppclinux.c: $(srcdir)/emulparams/elf32ppclinux.sh \
   $(srcdir)/emulparams/elf32ppc.sh $(srcdir)/emulparams/elf32ppccommon.sh \
-  $(srcdir)/emultempl/ppc32elf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/ppc32elf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ppclinux "$(tdir_elf32ppclinux)"
 eelf64ppc.c: $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64ppc "$(tdir_elf64ppc)"
 eelf64lppc.c: $(srcdir)/emulparams/elf64lppc.sh \
   $(srcdir)/emulparams/elf64ppc.sh $(srcdir)/emultempl/ppc64elf.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64lppc "$(tdir_elf64lppc)"
 eelf32i370.c: $(srcdir)/emulparams/elf32i370.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elfi370.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elfi370.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32i370 "$(tdir_elf32i370)"
 eelf32ip2k.c: $(srcdir)/emulparams/elf32ip2k.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/ip2k.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/ip2k.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32ip2k "$(tdir_ip2k)"
 eelf32iq2000.c: $(srcdir)/emulparams/elf32iq2000.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32iq2000 "$(tdir_iq2000)"
 eelf32iq10.c: $(srcdir)/emulparams/elf32iq10.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/iq2000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf32iq10 "$(tdir_iq10)"
 eelf64alpha.c: $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha "$(tdir_elf64alpha)"
 eelf64alpha_fbsd.c: $(srcdir)/emulparams/elf64alpha_fbsd.sh \
   $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha_fbsd "$(tdir_elf64alpha_fbsd)"
 eelf64alpha_nbsd.c: $(srcdir)/emulparams/elf64alpha_nbsd.sh \
   $(srcdir)/emulparams/elf64alpha.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/alphaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/alphaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64alpha_nbsd "$(tdir_elf64alpha_nbsd)"
 eelf64hppa.c: $(srcdir)/emulparams/elf64hppa.sh \
   $(srcdir)/emulparams/hppa64linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64hppa "$(tdir_elf64hppa)"
 eelf64_aix.c: $(srcdir)/emulparams/elf64_aix.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_aix "$(tdir_elf64_aix)"
 eelf64_ia64.c: $(srcdir)/emulparams/elf64_ia64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/ia64elf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/ia64elf.em \
   $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_ia64 "$(tdir_elf64_ia64)"
 eelf64_ia64_fbsd.c: $(srcdir)/emulparams/elf64_ia64_fbsd.sh \
   $(srcdir)/emulparams/elf64_ia64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/ia64elf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/ia64elf.em \
   $(srcdir)/emultempl/needrelax.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_ia64_fbsd "$(tdir_elf64_ia64_fbsd)"
 eelf64_s390.c: $(srcdir)/emulparams/elf64_s390.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_s390 "$(tdir_elf64_s390)"
 eelf64_sparc.c: $(srcdir)/emulparams/elf64_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_sparc "$(tdir_elf64_sparc)"
 eelf64_sparc_fbsd.c: $(srcdir)/emulparams/elf64_sparc_fbsd.sh \
   $(srcdir)/emulparams/elf64_sparc.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64_sparc_fbsd "$(tdir_elf64_sparc_fbsd)"
 eelf64bmip.c: $(srcdir)/emulparams/elf64bmip.sh \
   $(srcdir)/emulparams/elf32bmipn32.sh $(srcdir)/emultempl/irix.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64bmip "$(tdir_elf64bmip)"
 eelf64mmix.c: $(srcdir)/emulparams/elf64mmix.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/mmix-elfnmmo.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/mmix-elfnmmo.em \
   $(srcdir)/emultempl/mmixelf.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64mmix "$(tdir_elf64mmix)"
 emmo.c: $(srcdir)/emulparams/mmo.sh $(srcdir)/emultempl/mmix-elfnmmo.em \
-  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/mmo.em \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/elf-generic.em \
+  $(srcdir)/emultempl/mmo.em \
   $(srcdir)/scripttempl/mmo.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mmo "$(tdir_mmo)"
 eelf64btsmip.c: $(srcdir)/emulparams/elf64btsmip.sh \
   $(srcdir)/emulparams/elf32bmipn32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64btsmip "$(tdir_elf64btsmip)"
 eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
   $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf32bmipn32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf64ltsmip "$(tdir_elf64ltsmip)"
 eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386 "$(tdir_elf_i386)"
 eelf_x86_64.c: $(srcdir)/emulparams/elf_x86_64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_x86_64 "$(tdir_elf_x86_64)"
 eelf_x86_64_fbsd.c: $(srcdir)/emulparams/elf_x86_64_fbsd.sh \
   $(srcdir)/emulparams/elf_x86_64.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_x86_64_fbsd "$(tdir_elf_x86_64_fbsd)"
 eelf_i386_be.c: $(srcdir)/emulparams/elf_i386_be.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_be "$(tdir_elf_i386_be)"
 eelf_i386_chaos.c: $(srcdir)/emulparams/elf_i386_chaos.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf_chaos.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf_chaos.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_chaos "$(tdir_elf_i386_chaos)"
 eelf_i386_fbsd.c: $(srcdir)/emulparams/elf_i386_fbsd.sh \
   $(srcdir)/emulparams/elf_i386.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_fbsd "$(tdir_elf_i386_fbsd)"
 eelf_i386_ldso.c: $(srcdir)/emulparams/elf_i386_ldso.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_ldso "$(tdir_elf_i386_ldso)"
 eelf_i386_vxworks.c: $(srcdir)/emulparams/elf_i386_vxworks.sh \
   $(srcdir)/emulparams/vxworks.sh $(srcdir)/emultempl/vxworks.em \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_i386_vxworks "$(tdir_elf_i386_vxworks)"
 eelf_s390.c: $(srcdir)/emulparams/elf_s390.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} elf_s390 "$(tdir_elf_s390)"
 egld960.c: $(srcdir)/emulparams/gld960.sh \
   $(srcdir)/emultempl/gld960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
@@ -1773,31 +1797,31 @@ eh8300sxn.c: $(srcdir)/emulparams/h8300sxn.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/h8300sxn.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxn "$(tdir_h8300sxn)"
 eh8300elf.c: $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300elf "$(tdir_h8300elf)"
 eh8300helf.c: $(srcdir)/emulparams/h8300helf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300helf "$(tdir_h8300helf)"
 eh8300self.c: $(srcdir)/emulparams/h8300self.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300self "$(tdir_h8300self)"
 eh8300hnelf.c: $(srcdir)/emulparams/h8300hnelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300hnelf "$(tdir_h8300hnelf)"
 eh8300snelf.c: $(srcdir)/emulparams/h8300snelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300snelf "$(tdir_h8300snelf)"
 eh8300sxelf.c: $(srcdir)/emulparams/h8300sxelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxelf "$(tdir_h8300sxelf)"
 eh8300sxnelf.c: $(srcdir)/emulparams/h8300sxnelf.sh \
   $(srcdir)/emulparams/h8300elf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} h8300sxnelf "$(tdir_h8300sxnelf)"
 eh8500.c: $(srcdir)/emulparams/h8500.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/h8500.sc ${GEN_DEPENDS}
@@ -1821,24 +1845,24 @@ ehp3hpux.c: $(srcdir)/emulparams/hp3hpux.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hp3hpux "$(tdir_hp3hpux)"
 ehppaelf.c: $(srcdir)/emulparams/hppaelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/hppaelf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppaelf "$(tdir_hppaelf)"
 ehppalinux.c: $(srcdir)/emulparams/hppalinux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppalinux "$(tdir_hppalinux)"
 ehppanbsd.c: $(srcdir)/emulparams/hppanbsd.sh \
   $(srcdir)/emulparams/hppaelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppanbsd "$(tdir_hppanbsd)"
 ehppaobsd.c: $(srcdir)/emulparams/hppaobsd.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/hppaelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/hppaelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppaobsd "$(tdir_hppaobsd)"
 ehppa64linux.c: $(srcdir)/emulparams/hppa64linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} hppa64linux "$(tdir_hppa64linux)"
 ei386aout.c: $(srcdir)/emulparams/i386aout.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -1859,13 +1883,13 @@ ei386linux.c: $(srcdir)/emulparams/i386linux.sh \
   $(srcdir)/emultempl/linux.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386linux "$(tdir_i386linux)"
 ei386lynx.c: $(srcdir)/emulparams/i386lynx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386lynx "$(tdir_i386lynx)"
 ei386mach.c: $(srcdir)/emulparams/i386mach.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386mach "$(tdir_i386mach)"
 ei386moss.c: $(srcdir)/emulparams/i386moss.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386moss "$(tdir_i386moss)"
 ei386msdos.c: $(srcdir)/emulparams/i386msdos.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/i386msdos.sc ${GEN_DEPENDS}
@@ -1874,10 +1898,10 @@ ei386nbsd.c:	$(srcdir)/emulparams/i386nbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nbsd "$(tdir_i386nbsd)"
 ei386nto.c:	$(srcdir)/emulparams/i386nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nto "$(tdir_i386nto)"
 ei386nw.c:	$(srcdir)/emulparams/i386nw.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} i386nw "$(tdir_i386nw)"
 ei386pe.c: $(srcdir)/emulparams/i386pe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
@@ -1889,19 +1913,19 @@ elnk960.c: $(srcdir)/emulparams/lnk960.sh \
   $(srcdir)/emultempl/lnk960.em $(srcdir)/scripttempl/i960.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} lnk960 "$(tdir_lnk960)"
 em68hc11elf.c: $(srcdir)/emulparams/m68hc11elf.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc11.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc11elf "$(tdir_m68hc11)"
 em68hc11elfb.c: $(srcdir)/emulparams/m68hc11elfb.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc11.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc11elfb "$(tdir_m68hc11b)"
 em68hc12elf.c: $(srcdir)/emulparams/m68hc12elf.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc12.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc12elf "$(tdir_m68hc12)"
 em68hc12elfb.c: $(srcdir)/emulparams/m68hc12elfb.sh \
-  $(srcdir)/emultempl/m68hc1xelf.em $(srcdir)/emultempl/elf32.em \
+  $(srcdir)/emultempl/m68hc1xelf.em $(ELF_DEPS) \
   $(srcdir)/scripttempl/elfm68hc12.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68hc12elfb "$(tdir_m68hc12b)"
 em68k4knbsd.c:	$(srcdir)/emulparams/m68k4knbsd.sh \
@@ -1917,12 +1941,12 @@ em68kcoff.c: $(srcdir)/emulparams/m68kcoff.sh \
   $(srcdir)/emultempl/m68kcoff.em $(srcdir)/scripttempl/m68kcoff.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kcoff "$(tdir_m68kcoff)"
 em68kelf.c: $(srcdir)/emulparams/m68kelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/m68kelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/m68kelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kelf "$(tdir_m68kelf)"
 em68kelfnbsd.c: $(srcdir)/emulparams/m68kelfnbsd.sh \
   $(srcdir)/emulparams/m68kelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/m68kelf.em \
+  $(ELF_DEPS) $(srcdir)/emultempl/m68kelf.em \
   $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kelfnbsd "$(tdir_m68kelfnbsd)"
 em68klinux.c: $(srcdir)/emulparams/m68klinux.sh \
@@ -1932,7 +1956,7 @@ em68knbsd.c:	$(srcdir)/emulparams/m68knbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68knbsd "$(tdir_m68knbsd)"
 em68kpsos.c:	$(srcdir)/emulparams/m68kpsos.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/psos.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/psos.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} m68kpsos "$(tdir_m68kpsos)"
 em88kbcs.c: $(srcdir)/emulparams/m88kbcs.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/m88kbcs.sc ${GEN_DEPENDS}
@@ -1968,245 +1992,305 @@ emipspe.c: $(srcdir)/emulparams/mipspe.sh \
 	${GENSCRIPTS} mipspe "$(tdir_mips)"
 emn10300.c: $(srcdir)/emulparams/mn10300.sh \
   $(srcdir)/emulparams/mn10200.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mn10300 "$(tdir_mn10300)"
 emn10200.c: $(srcdir)/emulparams/mn10200.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} mn10200 "$(tdir_mn10200)"
 emsp430x110.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x110 "$(tdir_msp430x110)" msp430all
 emsp430x112.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x112 "$(tdir_msp430x112)" msp430all
 emsp430x1101.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1101 "$(tdir_msp430x1101)" msp430all
 emsp430x1111.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1111 "$(tdir_msp430x1111)" msp430all
 emsp430x1121.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1121 "$(tdir_msp430x1121)" msp430all
 emsp430x1122.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1122 "$(tdir_msp430x1122)" msp430all
 emsp430x1132.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1132 "$(tdir_msp430x1132)" msp430all
 emsp430x122.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x122 "$(tdir_msp430x122)" msp430all
 emsp430x123.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x123 "$(tdir_msp430x123)" msp430all
 emsp430x1222.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1222 "$(tdir_msp430x1222)" msp430all
 emsp430x1232.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1232 "$(tdir_msp430x1232)" msp430all
 emsp430x133.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x133 "$(tdir_msp430x133)" msp430all
 emsp430x135.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x135 "$(tdir_msp430x135)" msp430all
 emsp430x1331.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1331 "$(tdir_msp430x1331)" msp430all
 emsp430x1351.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1351 "$(tdir_msp430x1351)" msp430all
 emsp430x147.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x147 "$(tdir_msp430x147)" msp430all
 emsp430x148.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x148 "$(tdir_msp430x148)" msp430all
 emsp430x149.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x149 "$(tdir_msp430x149)" msp430all
 emsp430x155.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x155 "$(tdir_msp430x155)" msp430all
 emsp430x156.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x156 "$(tdir_msp430x156)" msp430all
 emsp430x157.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x157 "$(tdir_msp430x157)" msp430all
 emsp430x167.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x167 "$(tdir_msp430x167)" msp430all
 emsp430x168.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x168 "$(tdir_msp430x168)" msp430all
 emsp430x169.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x169 "$(tdir_msp430x169)" msp430all
 emsp430x1610.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1610 "$(tdir_msp430x1610)" msp430all
 emsp430x1611.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1611 "$(tdir_msp430x1611)" msp430all
 emsp430x1612.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x1612 "$(tdir_msp430x1612)" msp430all
 emsp430x2101.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2101 "$(tdir_msp430x2101)" msp430all
 emsp430x2111.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2111 "$(tdir_msp430x2111)" msp430all
 emsp430x2121.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2121 "$(tdir_msp430x2121)" msp430all
 emsp430x2131.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x2131 "$(tdir_msp430x2131)" msp430all
 emsp430x311.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x311 "$(tdir_msp430x311)" msp430all
 emsp430x312.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x312 "$(tdir_msp430x312)" msp430all
 emsp430x313.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x313 "$(tdir_msp430x313)" msp430all
 emsp430x314.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x314 "$(tdir_msp430x314)" msp430all
 emsp430x315.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x315 "$(tdir_msp430x315)" msp430all
 emsp430x323.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x323 "$(tdir_msp430x323)" msp430all
 emsp430x325.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x325 "$(tdir_msp430x325)" msp430all
 emsp430x336.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x336 "$(tdir_msp430x336)" msp430all
 emsp430x337.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430_3.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430_3.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x337 "$(tdir_msp430x337)" msp430all
 emsp430x412.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x412 "$(tdir_msp430x412)" msp430all
 emsp430x413.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x413 "$(tdir_msp430x413)" msp430all
 emsp430x415.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x415 "$(tdir_msp430x415)" msp430all
 emsp430x417.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x417 "$(tdir_msp430x417)" msp430all
 emsp430xE423.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE423 "$(tdir_msp430xE423)" msp430all
 emsp430xE425.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE425 "$(tdir_msp430xE425)" msp430all
 emsp430xE427.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xE427 "$(tdir_msp430xE427)" msp430all
 emsp430xW423.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW423 "$(tdir_msp430xW423)" msp430all
 emsp430xW425.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW425 "$(tdir_msp430xW425)" msp430all
 emsp430xW427.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xW427 "$(tdir_msp430xW427)" msp430all
 emsp430xG437.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG437 "$(tdir_msp430xG437)" msp430all
 emsp430xG438.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG438 "$(tdir_msp430xG438)" msp430all
 emsp430xG439.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430xG439 "$(tdir_msp430xG439)" msp430all
 emsp430x435.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x435 "$(tdir_msp430x435)" msp430all
 emsp430x436.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x436 "$(tdir_msp430x436)" msp430all
 emsp430x437.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x437 "$(tdir_msp430x437)" msp430all
 emsp430x447.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x447 "$(tdir_msp430x447)" msp430all
 emsp430x448.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x448 "$(tdir_msp430x448)" msp430all
 emsp430x449.c: $(srcdir)/emulparams/msp430all.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf32msp430.sc \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf32msp430.sc \
   ${GEN_DEPENDS}
 	${GENSCRIPTS} msp430x449 "$(tdir_msp430x449)" msp430all
 enews.c: $(srcdir)/emulparams/news.sh \
@@ -2220,7 +2304,8 @@ eor32.c: $(srcdir)/emulparams/or32.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/or32.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} or32 "$(tdir_or32)"
 eor32elf.c: $(srcdir)/emulparams/or32elf.sh \
-  $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} or32elf "$(tdir_or32elf)"
 epc532macha.c: $(srcdir)/emulparams/pc532macha.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -2229,22 +2314,24 @@ epdp11.c: $(srcdir)/emulparams/pdp11.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pdp11 "$(tdir_pdp11)"
 epjelf.c: $(srcdir)/emulparams/pjelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pjelf "$(tdir_pjelf)"
-epjlelf.c: $(srcdir)/emulparams/pjlelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+epjlelf.c: $(srcdir)/emulparams/pjlelf.sh $(srcdir)/emulparams/pjelf.sh \
+  $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/genelf.em \
+  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} pjlelf "$(tdir_pjlelf)"
 eppcmacos.c:	$(srcdir)/emulparams/ppcmacos.sh \
   $(srcdir)/emultempl/aix.em $(srcdir)/scripttempl/aix.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcmacos "$(tdir_ppcmacos)"
 eppcnw.c:	$(srcdir)/emulparams/ppcnw.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/nw.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcnw "$(tdir_ppcnw)"
 eppcpe.c: $(srcdir)/emulparams/ppcpe.sh \
   $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/ppcpe.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppcpe "$(tdir_ppcpe)"
 eppclynx.c: $(srcdir)/emulparams/ppclynx.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} ppclynx "$(tdir_ppclynx)"
 eriscix.c: $(srcdir)/emulparams/riscix.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
@@ -2253,87 +2340,87 @@ esh.c: $(srcdir)/emulparams/sh.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/sh.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} sh "$(tdir_sh)"
 eshelf.c: $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf "$(tdir_shelf)"
 eshelf32.c: $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32 "$(tdir_shelf32)"
 eshelf32_linux.c: $(srcdir)/emulparams/shelf32_linux.sh \
   $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32_linux "$(tdir_shelf32_linux)"
 eshelf32_nbsd.c: $(srcdir)/emulparams/shelf32_nbsd.sh \
   $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf32_nbsd "$(tdir_shelf32_nbsd)"
 eshelf64.c: $(srcdir)/emulparams/shelf64.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf64 "$(tdir_shelf64)"
 eshelf64_nbsd.c: $(srcdir)/emulparams/shelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf64_nbsd "$(tdir_shelf64_nbsd)"
 eshelf_linux.c: $(srcdir)/emulparams/shelf_linux.sh \
   $(srcdir)/emulparams/shlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_linux "$(tdir_shelf_linux)"
 eshlelf_linux.c: $(srcdir)/emulparams/shlelf_linux.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_linux "$(tdir_shlelf_linux)"
 eshelf_nbsd.c: $(srcdir)/emulparams/shelf_nbsd.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_nbsd "$(tdir_shelf_nbsd)"
 eshelf_nto.c: $(srcdir)/emulparams/shelf_nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shelf_nto "$(tdir_shelf_nto)"
 eshlelf_nbsd.c: $(srcdir)/emulparams/shlelf_nbsd.sh \
   $(srcdir)/emulparams/shelf_nbsd.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_nbsd "$(tdir_shlelf_nbsd)"
 eshlelf_nto.c: $(srcdir)/emulparams/shlelf_nto.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf_nto "$(tdir_shlelf_nto)"
 eshlelf.c: $(srcdir)/emulparams/shlelf.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf "$(tdir_shlelf)"
 eshlsymbian.c: $(srcdir)/emulparams/shlsymbian.sh \
   $(srcdir)/emulparams/shelf.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf32sh-symbian.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf32sh-symbian.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlsymbian "$(tdir_shlelf)"
 eshlelf32.c: $(srcdir)/emulparams/shlelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h $(srcdir)/emulparams/shelf32.sh \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32 "$(tdir_shlelf32)"
 eshlelf32_linux.c: $(srcdir)/emulparams/shlelf32_linux.sh \
   $(srcdir)/emulparams/shelf32_linux.sh $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32_linux "$(tdir_shlelf32_linux)"
 eshlelf32_nbsd.c: $(srcdir)/emulparams/shlelf32_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
   $(BFDDIR)/libbfd.h $(INCDIR)/libiberty.h \
   $(srcdir)/emultempl/sh64elf.em $(INCDIR)/elf/sh.h $(BFDDIR)/elf-bfd.h \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf32_nbsd "$(tdir_shlelf32_nbsd)"
 eshlelf64.c: $(srcdir)/emulparams/shlelf64.sh \
   $(srcdir)/emulparams/shelf64.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf64 "$(tdir_shlelf64)"
 eshlelf64_nbsd.c: $(srcdir)/emulparams/shlelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf64_nbsd.sh \
   $(srcdir)/emulparams/shelf32_nbsd.sh $(srcdir)/emulparams/shelf32.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} shlelf64_nbsd "$(tdir_shlelf64_nbsd)"
 eshl.c: $(srcdir)/emulparams/shl.sh \
   $(srcdir)/emulparams/sh.sh \
@@ -2394,7 +2481,7 @@ evsta.c: $(srcdir)/emulparams/vsta.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/aout.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} vsta "$(tdir_vsta)"
 ev850.c: $(srcdir)/emulparams/v850.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/v850.sc ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/v850.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} v850 "$(tdir_v850)"
 ew65.c: $(srcdir)/emulparams/w65.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/w65.sc ${GEN_DEPENDS}
@@ -2409,17 +2496,6 @@ ez8001.c: $(srcdir)/emulparams/z8001.sh \
 ez8002.c: $(srcdir)/emulparams/z8002.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/scripttempl/z8000.sc ${GEN_DEPENDS}
 	${GENSCRIPTS} z8002 "$(tdir_z8002)"
-eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
-  $(srcdir)/emulparams/elf32frv.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32frvfd "$(tdir_frv)"
-eelf32m32c.c: $(srcdir)/emulparams/elf32m32c.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32m32c "$(tdir_m32c)"
-eelf32mt.c: $(srcdir)/emulparams/elf32mt.sh \
-  $(srcdir)/emultempl/elf32.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
-	${GENSCRIPTS} elf32mt "$(tdir_mt)"
 
 # The generated emulation files mostly have the same dependencies.
 $(EMULATION_OFILES): ../bfd/bfd.h sysdep.h config.h $(INCDIR)/bfdlink.h \
diff --git a/ld/emulparams/arcelf.sh b/ld/emulparams/arcelf.sh
index f023093e30..6c524c9a76 100644
--- a/ld/emulparams/arcelf.sh
+++ b/ld/emulparams/arcelf.sh
@@ -1,4 +1,6 @@
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-littlearc"
 LITTLE_OUTPUT_FORMAT="elf32-littlearc"
 BIG_OUTPUT_FORMAT="elf32-bigarc"
@@ -8,4 +10,3 @@ NONPAGED_TEXT_START_ADDR=0x0
 ARCH=arc
 MACHINE=
 ENTRY=start
-#TEMPLATE_NAME=elf32
diff --git a/ld/emulparams/d30v_e.sh b/ld/emulparams/d30v_e.sh
index a8ab5a25db..617a048c89 100644
--- a/ld/emulparams/d30v_e.sh
+++ b/ld/emulparams/d30v_e.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elfd30v
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-d30v"
 TEXT_START_ADDR=0x00000000
 DATA_START_ADDR=0x20000000
diff --git a/ld/emulparams/d30v_o.sh b/ld/emulparams/d30v_o.sh
index 6cbcb42abd..79ba83ba7e 100644
--- a/ld/emulparams/d30v_o.sh
+++ b/ld/emulparams/d30v_o.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elfd30v
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-d30v"
 TEXT_START_ADDR=0x00000000
 DATA_START_ADDR=0x20000000
diff --git a/ld/emulparams/d30velf.sh b/ld/emulparams/d30velf.sh
index 949de78655..ab0d70f6bf 100644
--- a/ld/emulparams/d30velf.sh
+++ b/ld/emulparams/d30velf.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elfd30v
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-d30v"
 TEXT_START_ADDR=0x00000000
 DATA_START_ADDR=0x20000000
diff --git a/ld/emulparams/elf32_dlx.sh b/ld/emulparams/elf32_dlx.sh
index d3ff81c341..525b209209 100644
--- a/ld/emulparams/elf32_dlx.sh
+++ b/ld/emulparams/elf32_dlx.sh
@@ -1,5 +1,6 @@
 SCRIPT_NAME=dlx
 TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-dlx"
 ARCH=dlx
 MACHINE=
diff --git a/ld/emulparams/elf32_i860.sh b/ld/emulparams/elf32_i860.sh
index 1ab4204331..589067f818 100644
--- a/ld/emulparams/elf32_i860.sh
+++ b/ld/emulparams/elf32_i860.sh
@@ -1,5 +1,7 @@
 # A work in progress...
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-i860-little"
 BIG_OUTPUT_FORMAT="elf32-i860"
 LITTLE_OUTPUT_FORMAT="elf32-i860-little"
diff --git a/ld/emulparams/elf32fr30.sh b/ld/emulparams/elf32fr30.sh
index 069c623cd3..d078155909 100755
--- a/ld/emulparams/elf32fr30.sh
+++ b/ld/emulparams/elf32fr30.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-fr30"
 TEXT_START_ADDR=0x10000
 ARCH=fr30
diff --git a/ld/emulparams/elf32frv.sh b/ld/emulparams/elf32frv.sh
index 16773b716c..903707243f 100755
--- a/ld/emulparams/elf32frv.sh
+++ b/ld/emulparams/elf32frv.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-frv"
 TEXT_START_ADDR=0x10000
 ARCH=frv
diff --git a/ld/emulparams/elf32frvfd.sh b/ld/emulparams/elf32frvfd.sh
index 7029d47163..c174669626 100644
--- a/ld/emulparams/elf32frvfd.sh
+++ b/ld/emulparams/elf32frvfd.sh
@@ -3,6 +3,7 @@ unset STACK_ADDR
 OUTPUT_FORMAT="elf32-frvfdpic"
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 TEMPLATE_NAME=elf32
+unset EXTRA_EM_FILE
 GENERATE_SHLIB_SCRIPT=yes
 GENERATE_PIE_SCRIPT=yes
 EMBEDDED= # This gets us program headers mapped as part of the text segment.
diff --git a/ld/emulparams/elf32iq10.sh b/ld/emulparams/elf32iq10.sh
index 1721f5228d..2c0d75f100 100755
--- a/ld/emulparams/elf32iq10.sh
+++ b/ld/emulparams/elf32iq10.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=iq2000
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-iq2000"
 DATA_ADDR=0x1000
 TEXT_START_ADDR=0x80000000
diff --git a/ld/emulparams/elf32iq2000.sh b/ld/emulparams/elf32iq2000.sh
index 18f239da37..a21276ac22 100755
--- a/ld/emulparams/elf32iq2000.sh
+++ b/ld/emulparams/elf32iq2000.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=iq2000
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-iq2000"
 DATA_ADDR=0x1000
 TEXT_START_ADDR=0x80000000
diff --git a/ld/emulparams/elf32mt.sh b/ld/emulparams/elf32mt.sh
index 667979e65b..04fc1ed83d 100644
--- a/ld/emulparams/elf32mt.sh
+++ b/ld/emulparams/elf32mt.sh
@@ -1,5 +1,7 @@
 MACHINE=
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-mt"
 # See also `include/elf/mt.h'
 TEXT_START_ADDR=0x2000
diff --git a/ld/emulparams/mn10200.sh b/ld/emulparams/mn10200.sh
index f96224b049..74f48d0c48 100644
--- a/ld/emulparams/mn10200.sh
+++ b/ld/emulparams/mn10200.sh
@@ -2,6 +2,8 @@
 # mn10300.sh
 
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-mn10200"
 TEXT_START_ADDR=0x0
 ARCH=mn10200
diff --git a/ld/emulparams/mn10300.sh b/ld/emulparams/mn10300.sh
index 23bbda440d..121987c29e 100644
--- a/ld/emulparams/mn10300.sh
+++ b/ld/emulparams/mn10300.sh
@@ -2,4 +2,5 @@
 OUTPUT_FORMAT="elf32-mn10300"
 ARCH=mn10300
 TEMPLATE_NAME=elf32
+unset EXTRA_EM_FILE
 GENERATE_SHLIB_SCRIPT=yes
diff --git a/ld/emulparams/msp430all.sh b/ld/emulparams/msp430all.sh
index baee02eefd..57d21c2d40 100644
--- a/ld/emulparams/msp430all.sh
+++ b/ld/emulparams/msp430all.sh
@@ -4,1005 +4,550 @@
 
 MSP430_NAME=${EMULATION_NAME}
 
-if [ "${MSP430_NAME}" = "msp430x110" ] ; then
-ARCH=msp:11
-MACHINE=
 SCRIPT_NAME=elf32msp430
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-msp430"
+MACHINE=
 MAXPAGESIZE=1
 EMBEDDED=yes
-TEMPLATE_NAME=generic
 
+if [ "${MSP430_NAME}" = "msp430x110" ] ; then
+ARCH=msp:11
 ROM_START=0xfc00
 ROM_SIZE=0x3e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1101" ] ; then
 ARCH=msp:110
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xfc00
 ROM_SIZE=0x3e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1111" ] ; then
 ARCH=msp:110
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf800
 ROM_SIZE=0x07e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x112" ] ; then
 ARCH=msp:11
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0xfe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1121" ] ; then
 ARCH=msp:110
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0x0fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1122" ] ; then
 ARCH=msp:110
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0x0fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1132" ] ; then
 ARCH=msp:110
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x122" ] ; then
 ARCH=msp:12
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0xfe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1222" ] ; then
 ARCH=msp:12
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0xfe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x123" ] ; then
 ARCH=msp:12
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1232" ] ; then
 ARCH=msp:12
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x133" ] ; then
 ARCH=msp:13
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1331" ] ; then
 ARCH=msp:13
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x135" ] ; then
 ARCH=msp:13
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1351" ] ; then
 ARCH=msp:13
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x147" ] ; then
 ARCH=msp:14
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1K
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x148" ] ; then
 ARCH=msp:14
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x4000
 ROM_SIZE=0xbfe0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430x149" ] ; then
 ARCH=msp:14
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x1100
 ROM_SIZE=0xeee0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430x155" ] ; then
 ARCH=msp:15
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x156" ] ; then
 ARCH=msp:15
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xa000
 ROM_SIZE=0x5fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x157" ] ; then
 ARCH=msp:15
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1K
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x167" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1K
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x168" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x4000
 ROM_SIZE=0xbfe0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430x169" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x1100
 ROM_SIZE=0xeee0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1610" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x1100
 RAM_SIZE=0x1400
-
 STACK=0x2500
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1611" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x4000
 ROM_SIZE=0xbfe0
 RAM_START=0x1100
 RAM_SIZE=0x2800
-
 STACK=0x3900
 fi
 
 if [ "${MSP430_NAME}" = "msp430x1612" ] ; then
 ARCH=msp:16
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x2500
 ROM_SIZE=0xdae0
 RAM_START=0x1100
 RAM_SIZE=0x1400
-
 STACK=0x2500
 fi
 
 if [ "${MSP430_NAME}" = "msp430x2101" ] ; then
 ARCH=msp:21
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xFC00
 ROM_SIZE=0x03e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x2111" ] ; then
 ARCH=msp:21
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xF800
 ROM_SIZE=0x07e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x2121" ] ; then
 ARCH=msp:21
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0x0fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x2131" ] ; then
 ARCH=msp:21
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x311" ] ; then
 ARCH=msp:31
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf800
 ROM_SIZE=0x07e0
 RAM_START=0x0200
 RAM_SIZE=128
-
 STACK=0x280
 fi
 
 if [ "${MSP430_NAME}" = "msp430x312" ] ; then
 ARCH=msp:31
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0x0fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x313" ] ; then
 ARCH=msp:31
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x314" ] ; then
 ARCH=msp:31
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xd000
 ROM_SIZE=0x2fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x315" ] ; then
 ARCH=msp:31
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x323" ] ; then
 ARCH=msp:32
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x325" ] ; then
 ARCH=msp:32
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x336" ] ; then
 ARCH=msp:33
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xa000
 ROM_SIZE=0x5fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x337" ] ; then
 ARCH=msp:33
-MACHINE=
 SCRIPT_NAME=elf32msp430_3
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x412" ] ; then
 ARCH=msp:41
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xf000
 ROM_SIZE=0x0fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x413" ] ; then
 ARCH=msp:41
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430x415" ] ; then
 ARCH=msp:41
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x417" ] ; then
 ARCH=msp:41
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x435" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430x436" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xa000
 ROM_SIZE=0x5fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x437" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x447" ] ; then
 ARCH=msp:44
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430x448" ] ; then
 ARCH=msp:44
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x4000
 ROM_SIZE=0xbfe0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430x449" ] ; then
 ARCH=msp:44
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x1100
 ROM_SIZE=0xeee0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430xE423" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430xE425" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430xE427" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430xG437" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=1024
-
 STACK=0x600
 fi
 
 if [ "${MSP430_NAME}" = "msp430xG438" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x4000
 ROM_SIZE=0xbef0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430xG439" ] ; then
 ARCH=msp:43
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x1100
 ROM_SIZE=0xeee0
 RAM_START=0x0200
 RAM_SIZE=0x0800
-
 STACK=0xa00
 fi
 
 if [ "${MSP430_NAME}" = "msp430xW423" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xe000
 ROM_SIZE=0x1fe0
 RAM_START=0x0200
 RAM_SIZE=256
-
 STACK=0x300
 fi
 
 if [ "${MSP430_NAME}" = "msp430xW425" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0xc000
 ROM_SIZE=0x3fe0
 RAM_START=0x0200
 RAM_SIZE=512
-
 STACK=0x400
 fi
 
 if [ "${MSP430_NAME}" = "msp430xW427" ] ; then
 ARCH=msp:42
-MACHINE=
-SCRIPT_NAME=elf32msp430
-OUTPUT_FORMAT="elf32-msp430"
-MAXPAGESIZE=1
-EMBEDDED=yes
-TEMPLATE_NAME=generic
-
 ROM_START=0x8000
 ROM_SIZE=0x7fe0
 RAM_START=0x0200
 RAM_SIZE=0x400
-
 STACK=0x600
 fi
diff --git a/ld/emulparams/or32.sh b/ld/emulparams/or32.sh
index 0717eb7e06..0e22e45d8c 100644
--- a/ld/emulparams/or32.sh
+++ b/ld/emulparams/or32.sh
@@ -1,6 +1,5 @@
 SCRIPT_NAME=or32
 OUTPUT_FORMAT="coff-or32-big"
-# OUTPUT_FORMAT="elf32-or32"
 TEXT_START_ADDR=0x1000000
 TARGET_PAGE_SIZE=0x1000000
 ARCH=or32
diff --git a/ld/emulparams/or32elf.sh b/ld/emulparams/or32elf.sh
index 5f6b46719f..5cb3208ccc 100644
--- a/ld/emulparams/or32elf.sh
+++ b/ld/emulparams/or32elf.sh
@@ -1,4 +1,6 @@
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-or32"
 TEXT_START_ADDR=0x1000000
 TARGET_PAGE_SIZE=0x1000000
diff --git a/ld/emulparams/pjelf.sh b/ld/emulparams/pjelf.sh
index 97eba8fcb3..e4d2fa59f0 100644
--- a/ld/emulparams/pjelf.sh
+++ b/ld/emulparams/pjelf.sh
@@ -1,4 +1,6 @@
 SCRIPT_NAME=elf
+TEMPLATE_NAME=generic
+EXTRA_EM_FILE=genelf
 OUTPUT_FORMAT="elf32-pj"
 TEXT_START_ADDR=0x1000000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
diff --git a/ld/emulparams/pjlelf.sh b/ld/emulparams/pjlelf.sh
index eb568105aa..88c2b64604 100644
--- a/ld/emulparams/pjlelf.sh
+++ b/ld/emulparams/pjlelf.sh
@@ -1,5 +1,2 @@
-SCRIPT_NAME=elf
+. ${srcdir}/emulparams/pjelf.sh
 OUTPUT_FORMAT="elf32-pjl"
-TEXT_START_ADDR=0x1000000
-MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
-ARCH=pj
diff --git a/ld/emultempl/elf-generic.em b/ld/emultempl/elf-generic.em
new file mode 100644
index 0000000000..a573a4414d
--- /dev/null
+++ b/ld/emultempl/elf-generic.em
@@ -0,0 +1,60 @@
+# This shell script emits a C file. -*- C -*-
+#   Copyright 2006 Free Software Foundation, Inc.
+#
+# This file is part of GLD, the Gnu Linker.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+# This file is sourced from elf32.em and from ELF targets that use
+# generic.em.
+#
+cat >>e${EMULATION_NAME}.c <<EOF
+
+static void
+gld${EMULATION_NAME}_map_segments (bfd_boolean need_layout)
+{
+  while (1)
+    {
+      if (output_bfd->xvec->flavour == bfd_target_elf_flavour)
+	{
+	  bfd_size_type phdr_size;
+
+	  phdr_size = elf_tdata (output_bfd)->program_header_size;
+	  if (!_bfd_elf_map_sections_to_segments (output_bfd, &link_info))
+	    einfo ("%F%P: map sections to segments failed: %E\n");
+
+	  if (phdr_size != elf_tdata (output_bfd)->program_header_size)
+	    need_layout = TRUE;
+	}
+
+      if (!need_layout)
+	break;
+
+      lang_reset_memory_regions ();
+
+      /* Resize the sections.  */
+      lang_size_sections (NULL, TRUE);
+
+      /* Redo special stuff.  */
+      ldemul_after_allocation ();
+
+      /* Do the assignments again.  */
+      lang_do_assignments ();
+
+      need_layout = FALSE;
+    }
+}
+EOF
diff --git a/ld/emultempl/elf32.em b/ld/emultempl/elf32.em
index 7f97ab7e69..9eb532386d 100644
--- a/ld/emultempl/elf32.em
+++ b/ld/emultempl/elf32.em
@@ -60,8 +60,7 @@ static void gld${EMULATION_NAME}_before_parse (void);
 static void gld${EMULATION_NAME}_after_open (void);
 static void gld${EMULATION_NAME}_before_allocation (void);
 static bfd_boolean gld${EMULATION_NAME}_place_orphan (asection *s);
-static void gld${EMULATION_NAME}_layout_sections_again (void);
-static void gld${EMULATION_NAME}_finish (void) ATTRIBUTE_UNUSED;
+static void gld${EMULATION_NAME}_finish (void);
 
 EOF
 
@@ -79,6 +78,7 @@ fi
 
 # Import any needed special functions and/or overrides.
 #
+. ${srcdir}/emultempl/elf-generic.em
 if test -n "$EXTRA_EM_FILE" ; then
 . ${srcdir}/emultempl/${EXTRA_EM_FILE}.em
 fi
@@ -1559,27 +1559,12 @@ fi
 if test x"$LDEMUL_FINISH" != xgld"$EMULATION_NAME"_finish; then
 cat >>e${EMULATION_NAME}.c <<EOF
 
-static void
-gld${EMULATION_NAME}_layout_sections_again (void)
-{
-  lang_reset_memory_regions ();
-
-  /* Resize the sections.  */
-  lang_size_sections (NULL, TRUE);
-
-  /* Redo special stuff.  */
-  ldemul_after_allocation ();
-
-  /* Do the assignments again.  */
-  lang_do_assignments ();
-}
-
 static void
 gld${EMULATION_NAME}_finish (void)
 {
-  if (bfd_elf_discard_info (output_bfd, &link_info))
-    gld${EMULATION_NAME}_layout_sections_again ();
+  bfd_boolean need_layout = bfd_elf_discard_info (output_bfd, &link_info);
 
+  gld${EMULATION_NAME}_map_segments (need_layout);
   finish_default ();
 }
 EOF
diff --git a/ld/emultempl/genelf.em b/ld/emultempl/genelf.em
new file mode 100644
index 0000000000..dae75a16eb
--- /dev/null
+++ b/ld/emultempl/genelf.em
@@ -0,0 +1,39 @@
+# This shell script emits a C file. -*- C -*-
+#   Copyright 2006 Free Software Foundation, Inc.
+#
+# This file is part of GLD, the Gnu Linker.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+# This file is sourced from generic.em
+#
+cat >>e${EMULATION_NAME}.c <<EOF
+#include "elf-bfd.h"
+
+EOF
+. ${srcdir}/emultempl/elf-generic.em
+cat >>e${EMULATION_NAME}.c <<EOF
+
+static void
+gld${EMULATION_NAME}_finish (void)
+{
+  gld${EMULATION_NAME}_map_segments (FALSE);
+  finish_default ();
+}
+EOF
+# Put these extra routines in ld_${EMULATION_NAME}_emulation
+#
+LDEMUL_FINISH=gld${EMULATION_NAME}_finish
diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em
index 82f37b6916..61e53cbee4 100644
--- a/ld/emultempl/hppaelf.em
+++ b/ld/emultempl/hppaelf.em
@@ -220,9 +220,8 @@ hppaelf_layout_sections_again (void)
   /* If we have changed sizes of the stub sections, then we need
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
-  need_laying_out = 0;
-
-  gld${EMULATION_NAME}_layout_sections_again ();
+  gld${EMULATION_NAME}_map_segments (TRUE);
+  need_laying_out = -1;
 }
 
 
@@ -248,7 +247,7 @@ build_section_lists (lang_statement_union_type *statement)
    to build linker stubs.  */
 
 static void
-hppaelf_finish (void)
+gld${EMULATION_NAME}_finish (void)
 {
   /* bfd_elf_discard_info just plays with debugging sections,
      ie. doesn't affect any code, so we can delay resizing the
@@ -288,8 +287,8 @@ hppaelf_finish (void)
 	}
     }
 
-  if (need_laying_out)
-    hppaelf_layout_sections_again ();
+  if (need_laying_out != -1)
+    gld${EMULATION_NAME}_map_segments (need_laying_out);
 
   if (! link_info.relocatable)
     {
@@ -381,5 +380,5 @@ PARSE_AND_LIST_ARGS_CASES='
 # Put these extra hppaelf routines in ld_${EMULATION_NAME}_emulation
 #
 LDEMUL_AFTER_PARSE=hppaelf_after_parse
-LDEMUL_FINISH=hppaelf_finish
+LDEMUL_FINISH=gld${EMULATION_NAME}_finish
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=hppaelf_create_output_section_statements
diff --git a/ld/emultempl/mmo.em b/ld/emultempl/mmo.em
index 0a7d648bf1..3bf1c5b8a8 100644
--- a/ld/emultempl/mmo.em
+++ b/ld/emultempl/mmo.em
@@ -18,16 +18,18 @@
 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
-# This file is sourced from elf32.em and mmo.em, used to define
-# linker MMIX-specifics common to ELF and MMO.
+# This file is sourced from generic.em
 
 cat >>e${EMULATION_NAME}.c <<EOF
 /* Need to have this define before mmix-elfnmmo, which includes
    needrelax.em which uses this name for the before_allocation function,
    normally defined in elf32.em.  */
 #define gldmmo_before_allocation before_allocation_default
+
+#include "elf-bfd.h"
 EOF
 
+. ${srcdir}/emultempl/elf-generic.em
 . ${srcdir}/emultempl/mmix-elfnmmo.em
 
 cat >>e${EMULATION_NAME}.c <<EOF
@@ -112,6 +114,7 @@ static void
 mmo_finish (void)
 {
   bfd_map_over_sections (output_bfd, mmo_wipe_sec_reloc_flag, NULL);
+  gld${EMULATION_NAME}_map_segments (FALSE);
   finish_default ();
 }
 
diff --git a/ld/emultempl/ppc64elf.em b/ld/emultempl/ppc64elf.em
index ea337712ed..8823b11b3f 100644
--- a/ld/emultempl/ppc64elf.em
+++ b/ld/emultempl/ppc64elf.em
@@ -258,9 +258,8 @@ ppc_layout_sections_again (void)
   /* If we have changed sizes of the stub sections, then we need
      to recalculate all the section offsets.  This may mean we need to
      add even more stubs.  */
-  need_laying_out = 0;
-
-  gld${EMULATION_NAME}_layout_sections_again ();
+  gld${EMULATION_NAME}_map_segments (TRUE);
+  need_laying_out = -1;
 }
 
 
@@ -311,7 +310,7 @@ build_section_lists (lang_statement_union_type *statement)
 /* Final emulation specific call.  */
 
 static void
-ppc_finish (void)
+gld${EMULATION_NAME}_finish (void)
 {
   /* e_entry on PowerPC64 points to the function descriptor for
      _start.  If _start is missing, default to the first function
@@ -353,8 +352,8 @@ ppc_finish (void)
 	}
     }
 
-  if (need_laying_out)
-    ppc_layout_sections_again ();
+  if (need_laying_out != -1)
+    gld${EMULATION_NAME}_map_segments (need_laying_out);
 
   if (link_info.relocatable)
     {
@@ -574,6 +573,6 @@ PARSE_AND_LIST_ARGS_CASES='
 #
 LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
 LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
-LDEMUL_FINISH=ppc_finish
+LDEMUL_FINISH=gld${EMULATION_NAME}_finish
 LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
 LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
diff --git a/ld/ldlang.c b/ld/ldlang.c
index a9af491b78..8d9eaf6f1d 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5568,13 +5568,13 @@ lang_process (void)
 
   lang_do_assignments ();
 
+  ldemul_finish ();
+
   /* Make sure that the section addresses make sense.  */
   if (! link_info.relocatable
       && command_line.check_section_addresses)
     lang_check_section_addresses ();
 
-  /* Final stuffs.  */
-  ldemul_finish ();
   lang_end ();
 }
 
diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog
index 667c03265e..d8ef44b775 100644
--- a/ld/testsuite/ChangeLog
+++ b/ld/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2006-06-20  Alan Modra  <amodra@bigpond.net.au>
+
+	* ld-elf/eh1.d: Update for fewer program headers.
+	* ld-elf/eh2.d: Likewise.
+	* ld-elf/eh3.d: Likewise.
+
 2006-06-19  Vladimir Prus  <vladimir@codesourcery.com>
 
 	* ld-arm/arm-elf.exp: New test.
diff --git a/ld/testsuite/ld-elf/eh1.d b/ld/testsuite/ld-elf/eh1.d
index 897955b2b6..d7a5b15d32 100644
--- a/ld/testsuite/ld-elf/eh1.d
+++ b/ld/testsuite/ld-elf/eh1.d
@@ -22,11 +22,11 @@ The section .eh_frame contains:
   DW_CFA_nop
   DW_CFA_nop
 
-00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0
-  DW_CFA_advance_loc: 0 to 004000b0
+00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_offset: 16
   DW_CFA_offset: r6 at cfa-16
-  DW_CFA_advance_loc: 0 to 004000b0
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_reg: r6
 
 00000038 ZERO terminator
diff --git a/ld/testsuite/ld-elf/eh2.d b/ld/testsuite/ld-elf/eh2.d
index 6f4f2c58ed..c1ef3994fb 100644
--- a/ld/testsuite/ld-elf/eh2.d
+++ b/ld/testsuite/ld-elf/eh2.d
@@ -22,11 +22,11 @@ The section .eh_frame contains:
   DW_CFA_nop
   DW_CFA_nop
 
-00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0
-  DW_CFA_advance_loc: 0 to 004000b0
+00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_offset: 16
   DW_CFA_offset: r6 at cfa-16
-  DW_CFA_advance_loc: 0 to 004000b0
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_reg: r6
 
 00000038 ZERO terminator
diff --git a/ld/testsuite/ld-elf/eh3.d b/ld/testsuite/ld-elf/eh3.d
index 492c87784b..f1d2a52375 100644
--- a/ld/testsuite/ld-elf/eh3.d
+++ b/ld/testsuite/ld-elf/eh3.d
@@ -22,11 +22,11 @@ The section .eh_frame contains:
   DW_CFA_nop
   DW_CFA_nop
 
-00000018 0000001c 0000001c FDE cie=00000000 pc=004000b0..004000b0
-  DW_CFA_advance_loc: 0 to 004000b0
+00000018 0000001c 0000001c FDE cie=00000000 pc=00400078..00400078
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_offset: 16
   DW_CFA_offset: r6 at cfa-16
-  DW_CFA_advance_loc: 0 to 004000b0
+  DW_CFA_advance_loc: 0 to 00400078
   DW_CFA_def_cfa_reg: r6
 
 00000038 ZERO terminator