]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - ld/emultempl/beos.em
Update year range in copyright notice of binutils files
[thirdparty/binutils-gdb.git] / ld / emultempl / beos.em
index 3c9e3edc9b2ae6785b4d7a5e8eb06291fe03266e..97cde99c335252562784672909126a802d23986a 100644 (file)
@@ -1,42 +1,53 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-cat >e${EMULATION_NAME}.c <<EOF
+if [ -z "$MACHINE" ]; then
+  OUTPUT_ARCH=${ARCH}
+else
+  OUTPUT_ARCH=${ARCH}:${MACHINE}
+fi
+fragment <<EOF
 /* This file is part of GLD, the Gnu Linker.
-   Copyright 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1995-2020 Free Software Foundation, Inc.
 
-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 file is part of the GNU Binutils.
 
-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.
+   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 3 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.  */
 
-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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* For WINDOWS_NT */
 /* The original file generated returned different default scripts depending
    on whether certain switches were set, but these switches pertain to the
    Linux system and that particular version of coff.  In the NT case, we
    only determine if the subsystem is console or windows in order to select
-   the correct entry point by default. */ 
-  
-#include "bfd.h"
+   the correct entry point by default. */
+
 #include "sysdep.h"
+#include "bfd.h"
 #include "bfdlink.h"
+#include "ctf-api.h"
 #include "getopt.h"
 #include "libiberty.h"
+#include "filenames.h"
 #include "ld.h"
 #include "ldmain.h"
-#include "ldgram.h"
 #include "ldexp.h"
 #include "ldlang.h"
 #include "ldfile.h"
 #include "ldemul.h"
+#include <ldgram.h>
 #include "ldlex.h"
 #include "ldmisc.h"
 #include "ldctor.h"
@@ -45,34 +56,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 #define TARGET_IS_${EMULATION_NAME}
 
-static void gld_${EMULATION_NAME}_set_symbols PARAMS ((void));
-static void gld_${EMULATION_NAME}_after_open PARAMS ((void));
-static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
-static void gld_${EMULATION_NAME}_before_allocation PARAMS ((void));
-static boolean gld${EMULATION_NAME}_place_orphan
-  PARAMS ((lang_input_statement_type *, asection *));
-static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
-static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
-
-#if 0 /* argument to qsort so don't prototype */
-static int sort_by_file_name PARAMS ((void *, void *));
-static int sort_by_section_name PARAMS ((void *, void *));
-#endif
-static lang_statement_union_type **sort_sections_1
-  PARAMS ((lang_statement_union_type **, lang_statement_union_type *, int,
-          int (*)()));
-static void sort_sections PARAMS ((lang_statement_union_type *));
-
 static struct internal_extra_pe_aouthdr pe;
 static int dll;
 
 extern const char *output_filename;
 
 static void
-gld_${EMULATION_NAME}_before_parse()
+gld_${EMULATION_NAME}_before_parse (void)
 {
+  ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
   output_filename = "a.exe";
-  ldfile_output_architecture = bfd_arch_${ARCH};
 }
 \f
 /* PE format extra command line options.  */
@@ -89,17 +82,23 @@ gld_${EMULATION_NAME}_before_parse()
 #define OPTION_MINOR_OS_VERSION                (OPTION_MINOR_IMAGE_VERSION + 1)
 #define OPTION_MINOR_SUBSYSTEM_VERSION (OPTION_MINOR_OS_VERSION + 1)
 #define OPTION_SECTION_ALIGNMENT       (OPTION_MINOR_SUBSYSTEM_VERSION + 1)
-#define OPTION_STACK                    (OPTION_SECTION_ALIGNMENT + 1)
-#define OPTION_SUBSYSTEM                (OPTION_STACK + 1)
+#define OPTION_STACK                   (OPTION_SECTION_ALIGNMENT + 1)
+#define OPTION_SUBSYSTEM               (OPTION_STACK + 1)
 #define OPTION_HEAP                    (OPTION_SUBSYSTEM + 1)
 
-static struct option longopts[] = {
-  /* PE options */
+static void
+gld${EMULATION_NAME}_add_options
+  (int ns ATTRIBUTE_UNUSED, char **shortopts ATTRIBUTE_UNUSED, int nl,
+   struct option **longopts, int nrl ATTRIBUTE_UNUSED,
+   struct option **really_longopts ATTRIBUTE_UNUSED)
+{
+  static const struct option xtra_long[] = {
+    /* PE options */
     {"base-file", required_argument, NULL, OPTION_BASE_FILE},
     {"dll", no_argument, NULL, OPTION_DLL},
     {"file-alignment", required_argument, NULL, OPTION_FILE_ALIGNMENT},
-    {"heap", required_argument, NULL, OPTION_HEAP}, 
-    {"image-base", required_argument, NULL, OPTION_IMAGE_BASE}, 
+    {"heap", required_argument, NULL, OPTION_HEAP},
+    {"image-base", required_argument, NULL, OPTION_IMAGE_BASE},
     {"major-image-version", required_argument, NULL, OPTION_MAJOR_IMAGE_VERSION},
     {"major-os-version", required_argument, NULL, OPTION_MAJOR_OS_VERSION},
     {"major-subsystem-version", required_argument, NULL, OPTION_MAJOR_SUBSYSTEM_VERSION},
@@ -109,9 +108,14 @@ static struct option longopts[] = {
     {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
     {"stack", required_argument, NULL, OPTION_STACK},
     {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
-   {NULL, no_argument, NULL, 0}
+    {NULL, no_argument, NULL, 0}
   };
 
+  *longopts = (struct option *)
+    xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
+}
+
 
 /* PE/WIN32; added routines to get the subsystem type, heap and/or stack
    parameters which may be input from the command line */
@@ -132,7 +136,7 @@ static definfo init[] =
 #define IMAGEBASEOFF 0
   D(ImageBase,"__image_base__", BEOS_EXE_IMAGE_BASE),
 #define DLLOFF 1
-  {&dll, sizeof(dll), 0, "__dll__"},
+  {&dll, sizeof(dll), 0, "__dll__", 0},
   D(SectionAlignment,"__section_alignment__", PE_DEF_SECTION_ALIGNMENT),
   D(FileAlignment,"__file_alignment__", PE_DEF_FILE_ALIGNMENT),
   D(MajorOperatingSystemVersion,"__major_os_version__", 4),
@@ -152,9 +156,7 @@ static definfo init[] =
 
 
 static void
-set_pe_name (name, val)
-     char *name;
-     long val;
+set_pe_name (char *name, long val)
 {
   int i;
   /* Find the name and set it. */
@@ -172,12 +174,12 @@ set_pe_name (name, val)
 
 
 static void
-set_pe_subsystem ()
+set_pe_subsystem (void)
 {
   const char *sver;
   int len;
   int i;
-  static const struct 
+  static const struct
     {
       const char *name;
       const int value;
@@ -190,10 +192,6 @@ set_pe_subsystem ()
       { "wwindows", 2, "_wWinMainCRTStartup" },
       { "console", 3, "_mainCRTStartup" },
       { "wconsole", 3, "_wmainCRTStartup" },
-#if 0
-      /* The Microsoft linker does not recognize this.  */
-      { "os2", 5, "" },
-#endif
       { "posix", 7, "___PosixProcessStartup"},
       { 0, 0, 0 }
     };
@@ -212,7 +210,7 @@ set_pe_subsystem ()
        set_pe_name ("__minor_subsystem_version__",
                     strtoul (end + 1, &end, 0));
       if (*end != '\0')
-       einfo ("%P: warning: bad version number in -subsystem option\n");
+       einfo (_("%P: warning: bad version number in -subsystem option\n"));
     }
 
   for (i = 0; v[i].name; i++)
@@ -223,51 +221,31 @@ set_pe_subsystem ()
          set_pe_name ("__subsystem__", v[i].value);
 
          /* If the subsystem is windows, we use a different entry
-            point.  We also register the entry point as an undefined
-            symbol. from lang_add_entry() The reason we do
-            this is so that the user
-            doesn't have to because they would have to use the -u
-            switch if they were specifying an entry point other than
-            _mainCRTStartup.  Specifically, if creating a windows
-            application, entry point _WinMainCRTStartup must be
-            specified.  What I have found for non console
-            applications (entry not _mainCRTStartup) is that the .obj
-            that contains mainCRTStartup is brought in since it is
-            the first encountered in libc.lib and it has other
-            symbols in it which will be pulled in by the link
-            process.  To avoid this, adding -u with the entry point
-            name specified forces the correct .obj to be used.  We
-            can avoid making the user do this by always adding the
-            entry point name as an undefined symbol.  */
-         lang_add_entry (v[i].entry, 1);
+            point.  */
+         lang_default_entry (v[i].entry);
 
          return;
        }
     }
-  einfo ("%P%F: invalid subsystem type %s\n", optarg);
+  einfo (_("%F%P: invalid subsystem type %s\n"), optarg);
 }
 
 
-
 static void
-set_pe_value (name)
-     char *name;
-     
+set_pe_value (char *name)
 {
   char *end;
   set_pe_name (name,  strtoul (optarg, &end, 0));
   if (end == optarg)
     {
-      einfo ("%P%F: invalid hex number for PE parameter '%s'\n", optarg);
+      einfo (_("%F%P: invalid hex number for PE parameter '%s'\n"), optarg);
     }
 
   optarg = end;
 }
 
 static void
-set_pe_stack_heap (resname, comname)
-     char *resname;
-     char *comname;
+set_pe_stack_heap (char *resname, char *comname)
 {
   set_pe_value (resname);
   if (*optarg == ',')
@@ -277,56 +255,30 @@ set_pe_stack_heap (resname, comname)
     }
   else if (*optarg)
     {
-      einfo ("%P%F: strange hex info for PE parameter '%s'\n", optarg);
+      einfo (_("%F%P: strange hex info for PE parameter '%s'\n"), optarg);
     }
 }
 
 
-
-static int
-gld_${EMULATION_NAME}_parse_args(argc, argv)
-     int argc;
-     char **argv;
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (int optc)
 {
-  int longind;
-  int optc;
-  int prevoptind = optind;
-  int prevopterr = opterr;
-  int wanterror;
-  static int lastoptind = -1;
-
-  if (lastoptind != optind)
-    opterr = 0;
-  wanterror = opterr;
-
-  lastoptind = optind;
-
-  optc = getopt_long_only (argc, argv, "-", longopts, &longind);
-  opterr = prevopterr;
-
   switch (optc)
     {
     default:
-      if (wanterror)
-       xexit (1);
-      optind =  prevoptind;
-      return 0;
+      return FALSE;
 
     case OPTION_BASE_FILE:
-      link_info.base_file = (PTR) fopen (optarg, FOPEN_WB);
+      link_info.base_file = fopen (optarg, FOPEN_WB);
       if (link_info.base_file == NULL)
-       {
-         fprintf (stderr, "%s: Can't open base file %s\n",
-                  program_name, optarg);
-         xexit (1);
-       }
+       einfo (_("%F%P: cannot open base file %s\n"), optarg);
       break;
 
       /* PE options */
-    case OPTION_HEAP: 
+    case OPTION_HEAP:
       set_pe_stack_heap ("__size_of_heap_reserve__", "__size_of_heap_commit__");
       break;
-    case OPTION_STACK: 
+    case OPTION_STACK:
       set_pe_stack_heap ("__size_of_stack_reserve__", "__size_of_stack_commit__");
       break;
     case OPTION_SUBSYSTEM:
@@ -363,23 +315,22 @@ gld_${EMULATION_NAME}_parse_args(argc, argv)
       set_pe_value ("__image_base__");
       break;
     }
-  return 1;
+  return TRUE;
 }
 \f
 /* Assign values to the special symbols before the linker script is
    read.  */
 
 static void
-gld_${EMULATION_NAME}_set_symbols()
+gld_${EMULATION_NAME}_set_symbols (void)
 {
   /* Run through and invent symbols for all the
      names and insert the defaults. */
   int j;
-  lang_statement_list_type *save;
 
   if (!init[IMAGEBASEOFF].inited)
     {
-      if (link_info.relocateable)
+      if (bfd_link_relocatable (&link_info))
        init[IMAGEBASEOFF].value = 0;
       else if (init[DLLOFF].value)
        init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE;
@@ -387,19 +338,18 @@ gld_${EMULATION_NAME}_set_symbols()
        init[IMAGEBASEOFF].value = BEOS_EXE_IMAGE_BASE;
     }
 
-  /* Don't do any symbol assignments if this is a relocateable link.  */
-  if (link_info.relocateable)
+  /* Don't do any symbol assignments if this is a relocatable link.  */
+  if (bfd_link_relocatable (&link_info))
     return;
 
   /* Glue the assignments into the abs section */
-  save = stat_ptr;
-
-  stat_ptr = &(abs_output_section->children);
+  push_stat_ptr (&abs_output_section->children);
 
   for (j = 0; init[j].ptr; j++)
     {
       long val = init[j].value;
-      lang_add_assignment (exp_assop ('=' ,init[j].symbol, exp_intop (val)));
+      lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val),
+                                      FALSE));
       if (init[j].size == sizeof(short))
        *(short *)init[j].ptr = val;
       else if (init[j].size == sizeof(int))
@@ -412,109 +362,107 @@ gld_${EMULATION_NAME}_set_symbols()
       else     abort();
     }
   /* Restore the pointer. */
-  stat_ptr = save;
-  
+  pop_stat_ptr ();
+
   if (pe.FileAlignment >
       pe.SectionAlignment)
     {
-      einfo ("%P: warning, file alignment > section alignment.\n");
+      einfo (_("%P: warning, file alignment > section alignment\n"));
     }
 }
 
 static void
-gld_${EMULATION_NAME}_after_open()
+gld_${EMULATION_NAME}_after_open (void)
 {
+  after_open_default ();
+
   /* Pass the wacky PE command line options into the output bfd.
      FIXME: This should be done via a function, rather than by
      including an internal BFD header.  */
-  if (!coff_data(output_bfd)->pe)
+  if (!coff_data(link_info.output_bfd)->pe)
     {
-      einfo ("%F%P: PE operations on non PE file.\n");
+      einfo (_("%F%P: PE operations on non PE file\n"));
     }
 
-  pe_data(output_bfd)->pe_opthdr = pe;
-  pe_data(output_bfd)->dll = init[DLLOFF].value;
+  pe_data(link_info.output_bfd)->pe_opthdr = pe;
+  pe_data(link_info.output_bfd)->dll = init[DLLOFF].value;
 
 }
 \f
 /* Callback functions for qsort in sort_sections. */
 
 static int
-sort_by_file_name (a, b)
-     void *a;
-     void *b;
+sort_by_file_name (const void *a, const void *b)
 {
-  lang_statement_union_type **ra = a;
-  lang_statement_union_type **rb = b;
+  const lang_input_section_type *const *ra = a;
+  const lang_input_section_type *const *rb = b;
+  asection *sa = (*ra)->section;
+  asection *sb = (*rb)->section;
   int i, a_sec, b_sec;
 
-  i = strcmp ((*ra)->input_section.ifile->the_bfd->my_archive->filename,
-             (*rb)->input_section.ifile->the_bfd->my_archive->filename);
+  i = filename_cmp (sa->owner->my_archive->filename,
+                   sb->owner->my_archive->filename);
   if (i != 0)
     return i;
 
-  i = strcmp ((*ra)->input_section.ifile->filename,
-                (*rb)->input_section.ifile->filename);
+  i = filename_cmp (sa->owner->filename, sb->owner->filename);
   if (i != 0)
     return i;
   /* the tail idata4/5 are the only ones without relocs to an
-     idata$6 section unless we are importing by ordinal, 
+     idata$6 section unless we are importing by ordinal,
      so sort them to last to terminate the IAT
      and HNT properly. if no reloc this one is import by ordinal
      so we have to sort by section contents */
 
-  if ( ((*ra)->input_section.section->reloc_count + (*rb)->input_section.section->reloc_count) )
+  if (sa->reloc_count + sb->reloc_count != 0)
     {
-       i =  (((*ra)->input_section.section->reloc_count > 
-                (*rb)->input_section.section->reloc_count) ? -1 : 0);
-       if ( i != 0)
-         return i;
+      i = sa->reloc_count > sb->reloc_count ? -1 : 0;
+      if (i != 0)
+       return i;
 
-        return  (((*ra)->input_section.section->reloc_count > 
-                (*rb)->input_section.section->reloc_count) ? 0 : 1);
+      return sa->reloc_count > sb->reloc_count ? 0 : 1;
     }
   else
     {
-       if ( (strcmp( (*ra)->input_section.section->name, ".idata$6") == 0) )
-          return 0; /* don't sort .idata$6 or .idata$7 FIXME dlltool eliminate .idata$7 */
-
-       if (! bfd_get_section_contents ((*ra)->input_section.ifile->the_bfd, 
-         (*ra)->input_section.section, &a_sec, (file_ptr) 0, (bfd_size_type)sizeof(a_sec)))
-            einfo ("%F%B: Can't read contents of section .idata: %E\n",
-                 (*ra)->input_section.ifile->the_bfd);
-
-       if (! bfd_get_section_contents ((*rb)->input_section.ifile->the_bfd, 
-        (*rb)->input_section.section, &b_sec, (file_ptr) 0, (bfd_size_type)sizeof(b_sec) ))
-           einfo ("%F%B: Can't read contents of section .idata: %E\n",
-                (*rb)->input_section.ifile->the_bfd);
-
-      i =  ((a_sec < b_sec) ? -1 : 0);
-      if ( i != 0)
-        return i;
-      return  ((a_sec < b_sec) ? 0 : 1);
-   }
-return 0;
+      /* don't sort .idata$6 or .idata$7 FIXME dlltool eliminate .idata$7 */
+      if ((strcmp (sa->name, ".idata$6") == 0))
+       return 0;
+
+      if (!bfd_get_section_contents (sa->owner, sa, &a_sec, (file_ptr) 0,
+                                    (bfd_size_type) sizeof (a_sec)))
+       einfo (_("%F%P: %pB: can't read contents of section .idata: %E\n"),
+              sa->owner);
+
+      if (!bfd_get_section_contents (sb->owner, sb, &b_sec, (file_ptr) 0,
+                                    (bfd_size_type) sizeof (b_sec)))
+       einfo (_("%F%P: %pB: can't read contents of section .idata: %E\n"),
+              sb->owner);
+
+      i = a_sec < b_sec ? -1 : 0;
+      if (i != 0)
+       return i;
+      return a_sec < b_sec ? 0 : 1;
+    }
+  return 0;
 }
 
 static int
-sort_by_section_name (a, b)
-     void *a;
-     void *b;
+sort_by_section_name (const void *a, const void *b)
 {
-  lang_statement_union_type **ra = a;
-  lang_statement_union_type **rb = b;
+  const lang_input_section_type *const *ra = a;
+  const lang_input_section_type *const *rb = b;
+  const char *sna = (*ra)->section->name;
+  const char *snb = (*rb)->section->name;
   int i;
-  i = strcmp ((*ra)->input_section.section->name,
-                (*rb)->input_section.section->name);
-/* this is a hack to make .stab and .stabstr last, so we don't have
-   to fix strip/objcopy for .reloc sections.
-   FIXME stripping images with a .rsrc section still needs to be fixed */
-  if ( i != 0)
+  i = strcmp (sna, snb);
+  /* This is a hack to make .stab and .stabstr last, so we don't have
+     to fix strip/objcopy for .reloc sections.
+     FIXME stripping images with a .rsrc section still needs to be fixed.  */
+  if (i != 0)
     {
-      if ((strncmp ((*ra)->input_section.section->name, ".stab", 5) == 0)
-           && (strncmp ((*rb)->input_section.section->name, ".stab", 5) != 0))
-         return 1;
-      return i;
+      if ((CONST_STRNEQ (sna, ".stab"))
+         && (!CONST_STRNEQ (snb, ".stab")))
+       return 1;
     }
   return i;
 }
@@ -524,10 +472,10 @@ sort_by_section_name (a, b)
    The result is a pointer to the last element's "next" pointer.  */
 
 static lang_statement_union_type **
-sort_sections_1 (startptr, next_after, count, sort_func)
-     lang_statement_union_type **startptr,*next_after;
-     int count;
-     int (*sort_func) ();
+sort_sections_1 (lang_statement_union_type **startptr,
+                lang_statement_union_type *next_after,
+                int count,
+                int (*sort_func) (const void *, const void *))
 {
   lang_statement_union_type **vec;
   lang_statement_union_type *p;
@@ -540,7 +488,7 @@ sort_sections_1 (startptr, next_after, count, sort_func)
   vec = ((lang_statement_union_type **)
         xmalloc (count * sizeof (lang_statement_union_type *)));
 
-  for (p = *startptr, i = 0; i < count; i++, p = p->next)
+  for (p = *startptr, i = 0; i < count; i++, p = p->header.next)
     vec[i] = p;
 
   qsort (vec, count, sizeof (vec[0]), sort_func);
@@ -570,10 +518,9 @@ sort_sections_1 (startptr, next_after, count, sort_func)
    place_orphans routine to implement grouped sections.  */
 
 static void
-sort_sections (s)
-     lang_statement_union_type *s;
+sort_sections (lang_statement_union_type *s)
 {
-  for (; s ; s = s->next)
+  for (; s ; s = s->header.next)
     switch (s->header.type)
       {
       case lang_output_section_statement_enum:
@@ -582,66 +529,73 @@ sort_sections (s)
       case lang_wild_statement_enum:
        {
          lang_statement_union_type **p = &s->wild_statement.children.head;
+         struct wildcard_list *sec;
 
-         /* Is this the .idata section?  */
-         if (s->wild_statement.section_name != NULL
-             && strncmp (s->wild_statement.section_name, ".idata", 6) == 0)
+         for (sec = s->wild_statement.section_list; sec; sec = sec->next)
            {
-             /* Sort the children.  We want to sort any objects in
-                 the same archive.  In order to handle the case of
-                 including a single archive multiple times, we sort
-                 all the children by archive name and then by object
-                 name.  After sorting them, we re-thread the pointer
-                 chain.  */
-
-             while (*p)
+             /* Is this the .idata section?  */
+             if (sec->spec.name != NULL
+                 && CONST_STRNEQ (sec->spec.name, ".idata"))
                {
-                 lang_statement_union_type *start = *p;
-                 if (start->header.type != lang_input_section_enum
-                     || !start->input_section.ifile->the_bfd->my_archive)
-                   p = &(start->header.next);
-                 else
+                 /* Sort the children.  We want to sort any objects in
+                    the same archive.  In order to handle the case of
+                    including a single archive multiple times, we sort
+                    all the children by archive name and then by object
+                    name.  After sorting them, we re-thread the pointer
+                    chain.  */
+
+                 while (*p)
                    {
-                     lang_statement_union_type *end;
-                     int count;
-
-                     for (end = start, count = 0;
-                          end && end->header.type == lang_input_section_enum;
-                          end = end->next)
-                       count++;
-
-                     p = sort_sections_1 (p, end, count, sort_by_file_name);
+                     lang_statement_union_type *start = *p;
+                     if (start->header.type != lang_input_section_enum
+                         || !start->input_section.section->owner->my_archive)
+                       p = &(start->header.next);
+                     else
+                       {
+                         lang_statement_union_type *end;
+                         int count;
+
+                         for (end = start, count = 0;
+                              end && (end->header.type
+                                      == lang_input_section_enum);
+                              end = end->header.next)
+                           count++;
+
+                         p = sort_sections_1 (p, end, count,
+                                              sort_by_file_name);
+                       }
                    }
+                 break;
                }
-             break;
-           }
 
-         /* If this is a collection of grouped sections, sort them.
-            The linker script must explicitly mention "*(.foo\$)" or
-            "*(.foo\$*)".  Don't sort them if \$ is not the last
-            character (not sure if this is really useful, but it
-            allows explicitly mentioning some \$ sections and letting
-            the linker handle the rest).  */
-         if (s->wild_statement.section_name != NULL)
-           {
-             char *q = strchr (s->wild_statement.section_name, '\$');
-
-             if (q != NULL
-                 && (q[1] == '\0'
-                     || (q[1] == '*' && q[2] == '\0')))
+             /* If this is a collection of grouped sections, sort them.
+                The linker script must explicitly mention "*(.foo\$)" or
+                "*(.foo\$*)".  Don't sort them if \$ is not the last
+                character (not sure if this is really useful, but it
+                allows explicitly mentioning some \$ sections and letting
+                the linker handle the rest).  */
+             if (sec->spec.name != NULL)
                {
-                 lang_statement_union_type *end;
-                 int count;
+                 char *q = strchr (sec->spec.name, '\$');
 
-                 for (end = *p, count = 0; end; end = end->next)
+                 if (q != NULL
+                     && (q[1] == '\0'
+                         || (q[1] == '*' && q[2] == '\0')))
                    {
-                     if (end->header.type != lang_input_section_enum)
-                       abort ();
-                     count++;
+                     lang_statement_union_type *end;
+                     int count;
+
+                     for (end = *p, count = 0; end; end = end->header.next)
+                       {
+                         if (end->header.type != lang_input_section_enum)
+                           abort ();
+                         count++;
+                       }
+                     (void) sort_sections_1 (p, end, count,
+                                             sort_by_section_name);
                    }
-                 (void) sort_sections_1 (p, end, count, sort_by_section_name);
+                 break;
                }
-             break;
            }
        }
        break;
@@ -650,21 +604,20 @@ sort_sections (s)
       }
 }
 
-static void  
-gld_${EMULATION_NAME}_before_allocation()
+static void
+gld_${EMULATION_NAME}_before_allocation (void)
 {
-  extern lang_statement_list_type *stat_ptr;
-
 #ifdef TARGET_IS_ppcpe
   /* Here we rummage through the found bfds to collect toc information */
   {
     LANG_FOR_EACH_INPUT_STATEMENT (is)
-      {
-       if (!ppc_process_before_allocation(is->the_bfd, &link_info))
-         {
-           einfo("Errors encountered processing file %s\n", is->filename);
-         }
-      }
+    {
+      if (!ppc_process_before_allocation(is->the_bfd, &link_info))
+       {
+         einfo (_("%P: errors encountered processing file %s\n"),
+                is->filename);
+       }
+    }
   }
 
   /* We have seen it all. Allocate it, and carry on */
@@ -679,12 +632,13 @@ gld_${EMULATION_NAME}_before_allocation()
      option?  krk@cygnus.com */
   {
     LANG_FOR_EACH_INPUT_STATEMENT (is)
-      {
-       if (!arm_process_before_allocation (is->the_bfd, & link_info))
-         {
-           einfo ("Errors encountered processing file %s", is->filename);
-         }
-      }
+    {
+      if (!arm_process_before_allocation (is->the_bfd, & link_info))
+       {
+         einfo (_("%P: errors encountered processing file %s\n"),
+                is->filename);
+       }
+    }
   }
 
   /* We have seen it all. Allocate it, and carry on */
@@ -693,6 +647,8 @@ gld_${EMULATION_NAME}_before_allocation()
 #endif /* TARGET_IS_ppcpe */
 
   sort_sections (stat_ptr->head);
+
+  before_allocation_default ();
 }
 \f
 /* Place an orphan section.  We use this to put sections with a '\$' in them
@@ -706,35 +662,31 @@ gld_${EMULATION_NAME}_before_allocation()
    but I'm leaving this here in case we want to enable it for sections
    which are not mentioned in the linker script.  */
 
-/*ARGSUSED*/
-static boolean
-gld${EMULATION_NAME}_place_orphan (file, s)
-     lang_input_statement_type *file;
-     asection *s;
+static lang_output_section_statement_type *
+gld${EMULATION_NAME}_place_orphan (asection *s,
+                                  const char *secname,
+                                  int constraint)
 {
-  const char *secname;
   char *output_secname, *ps;
   lang_output_section_statement_type *os;
   lang_statement_union_type *l;
 
   if ((s->flags & SEC_ALLOC) == 0)
-    return false;
+    return NULL;
 
   /* Don't process grouped sections unless doing a final link.
      If they're marked as COMDAT sections, we don't want .text\$foo to
      end up in .text and then have .text disappear because it's marked
      link-once-discard.  */
-  if (link_info.relocateable)
-    return false;
-
-  secname = bfd_get_section_name (s->owner, s);
+  if (bfd_link_relocatable (&link_info))
+    return NULL;
 
   /* Everything from the '\$' on gets deleted so don't allow '\$' as the
      first character.  */
   if (*secname == '\$')
-    einfo ("%P%F: section %s has '\$' as first character\n", secname);
+    einfo (_("%F%P: section %s has '\$' as first character\n"), secname);
   if (strchr (secname + 1, '\$') == NULL)
-    return false;
+    return NULL;
 
   /* Look up the output section.  The Microsoft specs say sections names in
      image files never contain a '\$'.  Fortunately, lang_..._lookup creates
@@ -742,7 +694,7 @@ gld${EMULATION_NAME}_place_orphan (file, s)
   output_secname = xstrdup (secname);
   ps = strchr (output_secname + 1, '\$');
   *ps = 0;
-  os = lang_output_section_statement_lookup (output_secname);
+  os = lang_output_section_statement_lookup (output_secname, constraint, TRUE);
 
   /* Find the '\$' wild statement for this section.  We currently require the
      linker script to explicitly mention "*(.foo\$)".
@@ -751,75 +703,66 @@ gld${EMULATION_NAME}_place_orphan (file, s)
 
   ps[0] = '\$';
   ps[1] = 0;
-  for (l = os->children.head; l; l = l->next)
-    {
-      if (l->header.type == lang_wild_statement_enum
-         && strcmp (l->wild_statement.section_name, output_secname) == 0)
-       break;
-    }
+  for (l = os->children.head; l; l = l->header.next)
+    if (l->header.type == lang_wild_statement_enum)
+      {
+       struct wildcard_list *sec;
+
+       for (sec = l->wild_statement.section_list; sec; sec = sec->next)
+         if (sec->spec.name && strcmp (sec->spec.name, output_secname) == 0)
+           break;
+       if (sec)
+         break;
+      }
   ps[0] = 0;
   if (l == NULL)
-#if 1
-    einfo ("%P%F: *(%s\$) missing from linker script\n", output_secname);
-#else /* FIXME: This block is untried.  It exists to convey the intent,
-        should one decide to not require *(.foo\$) to appear in the linker
-        script.  */
-    {
-      lang_wild_statement_type *new = new_stat (lang_wild_statement,
-                                               &os->children);
-      new->section_name = xmalloc (strlen (output_secname) + 2);
-      sprintf (new->section_name, "%s\$", output_secname);
-      new->filename = NULL;
-      lang_list_init (&new->children);
-      l = new;
-    }
-#endif
+    einfo (_("%F%P: *(%s\$) missing from linker script\n"), output_secname);
 
   /* Link the input section in and we're done for now.
      The sections still have to be sorted, but that has to wait until
      all such sections have been processed by us.  The sorting is done by
      sort_sections.  */
-  wild_doit (&l->wild_statement.children, s, os, file);
+  lang_add_section (&l->wild_statement.children, s, NULL, os);
 
-  return true;
+  return os;
 }
 \f
 static char *
-gld_${EMULATION_NAME}_get_script(isfile)
-     int *isfile;
+gld_${EMULATION_NAME}_get_script (int *isfile)
 EOF
 # Scripts compiled in.
 # sed commands to quote an ld script as a C string.
 sc="-f stringify.sed"
 
-cat >>e${EMULATION_NAME}.c <<EOF
-{                           
+fragment <<EOF
+{
   *isfile = 0;
 
-  if (link_info.relocateable == true && config.build_constructors == true)
+  if (bfd_link_relocatable (&link_info) && config.build_constructors)
     return
 EOF
-sed $sc ldscripts/${EMULATION_NAME}.xu                     >> e${EMULATION_NAME}.c
-echo '  ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c
-sed $sc ldscripts/${EMULATION_NAME}.xr                     >> e${EMULATION_NAME}.c
-echo '  ; else if (!config.text_read_only) return'         >> e${EMULATION_NAME}.c
-sed $sc ldscripts/${EMULATION_NAME}.xbn                    >> e${EMULATION_NAME}.c
-echo '  ; else if (!config.magic_demand_paged) return'     >> e${EMULATION_NAME}.c
-sed $sc ldscripts/${EMULATION_NAME}.xn                     >> e${EMULATION_NAME}.c
-echo '  ; else return'                                     >> e${EMULATION_NAME}.c
-sed $sc ldscripts/${EMULATION_NAME}.x                      >> e${EMULATION_NAME}.c
-echo '; }'                                                 >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xu                 >> e${EMULATION_NAME}.c
+echo '  ; else if (bfd_link_relocatable (&link_info)) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xr                 >> e${EMULATION_NAME}.c
+echo '  ; else if (!config.text_read_only) return'     >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xbn                >> e${EMULATION_NAME}.c
+echo '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xn                 >> e${EMULATION_NAME}.c
+echo '  ; else return'                                 >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.x                  >> e${EMULATION_NAME}.c
+echo '; }'                                             >> e${EMULATION_NAME}.c
 
-cat >>e${EMULATION_NAME}.c <<EOF
+fragment <<EOF
 
 
-struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation = 
+struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
 {
   gld_${EMULATION_NAME}_before_parse,
   syslib_default,
   hll_default,
   after_parse_default,
   gld_${EMULATION_NAME}_after_open,
+  after_check_relocs_default,
   after_allocation_default,
   set_output_arch_default,
   ldemul_default_target,
@@ -827,15 +770,21 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   gld_${EMULATION_NAME}_get_script,
   "${EMULATION_NAME}",
   "${OUTPUT_FORMAT}",
-  NULL, /* finish */
+  finish_default,
   NULL, /* create output section statements */
   NULL, /* open dynamic archive */
   gld${EMULATION_NAME}_place_orphan,
   gld_${EMULATION_NAME}_set_symbols,
-  gld_${EMULATION_NAME}_parse_args,
+  NULL, /* parse_args */
+  gld${EMULATION_NAME}_add_options,
+  gld${EMULATION_NAME}_handle_option,
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL,        /* find_potential_libraries */
+  NULL,        /* new_vers_pattern */
+  NULL,        /* extra_map_file_text */
+  ${LDEMUL_EMIT_CTF_EARLY-NULL},
+  ${LDEMUL_EXAMINE_STRTAB_FOR_CTF-NULL}
 };
 EOF