* emultempl/hppaelf.em (build_section_lists): New function.
[deliverable/binutils-gdb.git] / ld / emultempl / beos.em
index 4ad033bf4ec9cdd8babc8f5c9fa1cb1c350844aa..e6e6b58cfbcf7c3b2cd875d3f7738cd2ee21d8a3 100644 (file)
@@ -1,13 +1,14 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
-if [ -z "$MACHINE" ]; then 
+if [ -z "$MACHINE" ]; then
   OUTPUT_ARCH=${ARCH}
 else
   OUTPUT_ARCH=${ARCH}:${MACHINE}
 fi
 cat >e${EMULATION_NAME}.c <<EOF
 /* This file is part of GLD, the Gnu Linker.
-   Copyright 1995, 1996, 1997, 1998, 2000 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002
+   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
@@ -28,8 +29,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
    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. */ 
-  
+   the correct entry point by default. */
+
 #include "bfd.h"
 #include "sysdep.h"
 #include "bfdlink.h"
@@ -37,11 +38,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "libiberty.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"
@@ -59,15 +60,18 @@ static boolean gld${EMULATION_NAME}_place_orphan
 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 int sort_by_file_name PARAMS ((const PTR, const PTR));
+static int sort_by_section_name PARAMS ((const PTR, const PTR));
 static lang_statement_union_type **sort_sections_1
   PARAMS ((lang_statement_union_type **, lang_statement_union_type *, int,
-          int (*)()));
+          int (*) PARAMS((const PTR, const PTR))));
 static void sort_sections PARAMS ((lang_statement_union_type *));
 
+static void set_pe_name PARAMS ((char *, long int));
+static void set_pe_subsystem PARAMS ((void));
+static void set_pe_value PARAMS ((char *));
+static void set_pe_stack_heap PARAMS ((char *, char *));
+
 static struct internal_extra_pe_aouthdr pe;
 static int dll;
 
@@ -76,7 +80,6 @@ extern const char *output_filename;
 static void
 gld_${EMULATION_NAME}_before_parse()
 {
-  output_filename = "a.exe";
   const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
   if (arch)
     {
@@ -86,6 +89,7 @@ gld_${EMULATION_NAME}_before_parse()
     }
   else
     ldfile_output_architecture = bfd_arch_${ARCH};
+  output_filename = "a.exe";
 }
 \f
 /* PE format extra command line options.  */
@@ -111,8 +115,8 @@ static struct option longopts[] = {
     {"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},
@@ -145,7 +149,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),
@@ -190,7 +194,7 @@ set_pe_subsystem ()
   const char *sver;
   int len;
   int i;
-  static const struct 
+  static const struct
     {
       const char *name;
       const int value;
@@ -265,7 +269,7 @@ set_pe_subsystem ()
 static void
 set_pe_value (name)
      char *name;
-     
+
 {
   char *end;
   set_pe_name (name,  strtoul (optarg, &end, 0));
@@ -336,10 +340,10 @@ gld_${EMULATION_NAME}_parse_args(argc, argv)
       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:
@@ -412,7 +416,7 @@ gld_${EMULATION_NAME}_set_symbols()
   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_assop ('='init[j].symbol, exp_intop (val)));
       if (init[j].size == sizeof(short))
        *(short *)init[j].ptr = val;
       else if (init[j].size == sizeof(int))
@@ -426,7 +430,7 @@ gld_${EMULATION_NAME}_set_symbols()
     }
   /* Restore the pointer. */
   stat_ptr = save;
-  
+
   if (pe.FileAlignment >
       pe.SectionAlignment)
     {
@@ -454,11 +458,11 @@ gld_${EMULATION_NAME}_after_open()
 
 static int
 sort_by_file_name (a, b)
-     void *a;
-     void *b;
+     const PTR a;
+     const PTR b;
 {
-  lang_statement_union_type **ra = a;
-  lang_statement_union_type **rb = b;
+  const lang_statement_union_type *const *ra = a;
+  const lang_statement_union_type *const *rb = b;
   int i, a_sec, b_sec;
 
   i = strcmp ((*ra)->input_section.ifile->the_bfd->my_archive->filename,
@@ -471,19 +475,19 @@ sort_by_file_name (a, b)
   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) )
     {
-       i =  (((*ra)->input_section.section->reloc_count > 
+       i =  (((*ra)->input_section.section->reloc_count >
                 (*rb)->input_section.section->reloc_count) ? -1 : 0);
        if ( i != 0)
          return i;
 
-        return  (((*ra)->input_section.section->reloc_count > 
+        return  (((*ra)->input_section.section->reloc_count >
                 (*rb)->input_section.section->reloc_count) ? 0 : 1);
     }
   else
@@ -491,12 +495,12 @@ sort_by_file_name (a, b)
        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, 
+       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, 
+       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);
@@ -511,11 +515,11 @@ return 0;
 
 static int
 sort_by_section_name (a, b)
-     void *a;
-     void *b;
+     const PTR a;
+     const PTR b;
 {
-  lang_statement_union_type **ra = a;
-  lang_statement_union_type **rb = b;
+  const lang_statement_union_type *const *ra = a;
+  const lang_statement_union_type *const *rb = b;
   int i;
   i = strcmp ((*ra)->input_section.section->name,
                 (*rb)->input_section.section->name);
@@ -540,7 +544,7 @@ 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) ();
+     int (*sort_func) PARAMS ((const PTR, const PTR));
 {
   lang_statement_union_type **vec;
   lang_statement_union_type *p;
@@ -553,7 +557,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);
@@ -586,7 +590,7 @@ static void
 sort_sections (s)
      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:
@@ -595,66 +599,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
+                 && strncmp (sec->spec.name, ".idata", 6) == 0)
                {
-                 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.ifile->the_bfd->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;
@@ -663,7 +674,7 @@ sort_sections (s)
       }
 }
 
-static void  
+static void
 gld_${EMULATION_NAME}_before_allocation()
 {
   extern lang_statement_list_type *stat_ptr;
@@ -764,12 +775,17 @@ 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
@@ -778,11 +794,20 @@ gld${EMULATION_NAME}_place_orphan (file, s)
         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);
+      lang_wild_statement_type *new;
+      struct wildcard_list *tmp;
+
+      tmp = (struct wildcard_list *) xmalloc (sizeof *tmp);
+      tmp->next = NULL;
+      tmp->spec.name = xmalloc (strlen (output_secname) + 2);
+      sprintf (tmp->spec.name, "%s\$", output_secname);
+      tmp->spec.exclude_name_list = NULL;
+      tmp->sorted = false;
+      new = new_stat (lang_wild_statement, &os->children);
       new->filename = NULL;
+      new->filenames_sorted = false;
+      new->section_list = tmp;
+      new->keep_sections = false;
       lang_list_init (&new->children);
       l = new;
     }
@@ -792,7 +817,7 @@ gld${EMULATION_NAME}_place_orphan (file, s)
      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, os, file);
 
   return true;
 }
@@ -806,7 +831,7 @@ EOF
 sc="-f stringify.sed"
 
 cat >>e${EMULATION_NAME}.c <<EOF
-{                           
+{
   *isfile = 0;
 
   if (link_info.relocateable == true && config.build_constructors == true)
@@ -826,7 +851,7 @@ echo '; }'                                                 >> e${EMULATION_NAME}
 cat >>e${EMULATION_NAME}.c <<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,
@@ -849,6 +874,6 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   NULL,        /* unrecognized file */
   NULL,        /* list options */
   NULL,        /* recognized file */
-  NULL         /* find_potential_libraries */
+  NULL /* find_potential_libraries */
 };
 EOF
This page took 0.02921 seconds and 4 git commands to generate.