* emultempl/ppc64elf.em (gld${EMULATION_NAME}_finish): Enable
[binutils-gdb.git] / ld / emultempl / beos.em
index e6e6b58cfbcf7c3b2cd875d3f7738cd2ee21d8a3..0431baf7cca89571159dc9be5e693b4867933f79 100644 (file)
@@ -7,7 +7,7 @@ else
 fi
 cat >e${EMULATION_NAME}.c <<EOF
 /* This file is part of GLD, the Gnu Linker.
-   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002
+   Copyright 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
    Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify
@@ -42,7 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "ldlang.h"
 #include "ldfile.h"
 #include "ldemul.h"
-#include "ldgram.h"
+#include <ldgram.h>
 #include "ldlex.h"
 #include "ldmisc.h"
 #include "ldctor.h"
@@ -51,44 +51,15 @@ 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 **));
-
-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 (*) 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;
 
 extern const char *output_filename;
 
 static void
-gld_${EMULATION_NAME}_before_parse()
+gld_${EMULATION_NAME}_before_parse (void)
 {
-  const bfd_arch_info_type *arch = bfd_scan_arch ("${OUTPUT_ARCH}");
-  if (arch)
-    {
-      ldfile_output_architecture = arch->arch;
-      ldfile_output_machine = arch->mach;
-      ldfile_output_machine_name = arch->printable_name;
-    }
-  else
-    ldfile_output_architecture = bfd_arch_${ARCH};
+  ldfile_set_output_arch ("${OUTPUT_ARCH}", bfd_arch_`echo ${ARCH} | sed -e 's/:.*//'`);
   output_filename = "a.exe";
 }
 \f
@@ -110,8 +81,14 @@ gld_${EMULATION_NAME}_before_parse()
 #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},
@@ -126,9 +103,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 */
@@ -169,9 +151,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. */
@@ -189,7 +169,7 @@ set_pe_name (name, val)
 
 
 static void
-set_pe_subsystem ()
+set_pe_subsystem (void)
 {
   const char *sver;
   int len;
@@ -265,11 +245,8 @@ set_pe_subsystem ()
 }
 
 
-
 static void
-set_pe_value (name)
-     char *name;
-
+set_pe_value (char *name)
 {
   char *end;
   set_pe_name (name,  strtoul (optarg, &end, 0));
@@ -282,9 +259,7 @@ set_pe_value (name)
 }
 
 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 == ',')
@@ -299,38 +274,16 @@ set_pe_stack_heap (resname, comname)
 }
 
 
-
-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",
@@ -380,14 +333,14 @@ 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. */
@@ -396,7 +349,7 @@ gld_${EMULATION_NAME}_set_symbols()
 
   if (!init[IMAGEBASEOFF].inited)
     {
-      if (link_info.relocateable)
+      if (link_info.relocatable)
        init[IMAGEBASEOFF].value = 0;
       else if (init[DLLOFF].value)
        init[IMAGEBASEOFF].value = BEOS_DLL_IMAGE_BASE;
@@ -404,8 +357,8 @@ 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 (link_info.relocatable)
     return;
 
   /* Glue the assignments into the abs section */
@@ -439,7 +392,7 @@ gld_${EMULATION_NAME}_set_symbols()
 }
 
 static void
-gld_${EMULATION_NAME}_after_open()
+gld_${EMULATION_NAME}_after_open (void)
 {
   /* Pass the wacky PE command line options into the output bfd.
      FIXME: This should be done via a function, rather than by
@@ -457,9 +410,7 @@ gld_${EMULATION_NAME}_after_open()
 /* Callback functions for qsort in sort_sections. */
 
 static int
-sort_by_file_name (a, b)
-     const PTR a;
-     const PTR b;
+sort_by_file_name (const void *a, const void *b)
 {
   const lang_statement_union_type *const *ra = a;
   const lang_statement_union_type *const *rb = b;
@@ -514,9 +465,7 @@ return 0;
 }
 
 static int
-sort_by_section_name (a, b)
-     const PTR a;
-     const PTR b;
+sort_by_section_name (const void *a, const void *b)
 {
   const lang_statement_union_type *const *ra = a;
   const lang_statement_union_type *const *rb = b;
@@ -541,10 +490,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) PARAMS ((const PTR, const PTR));
+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;
@@ -587,8 +536,7 @@ 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->header.next)
     switch (s->header.type)
@@ -675,7 +623,7 @@ sort_sections (s)
 }
 
 static void
-gld_${EMULATION_NAME}_before_allocation()
+gld_${EMULATION_NAME}_before_allocation (void)
 {
   extern lang_statement_list_type *stat_ptr;
 
@@ -730,11 +678,8 @@ 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 bfd_boolean
+gld${EMULATION_NAME}_place_orphan (lang_input_statement_type *file, asection *s)
 {
   const char *secname;
   char *output_secname, *ps;
@@ -742,14 +687,14 @@ gld${EMULATION_NAME}_place_orphan (file, s)
   lang_statement_union_type *l;
 
   if ((s->flags & SEC_ALLOC) == 0)
-    return false;
+    return FALSE;
 
   /* 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;
+  if (link_info.relocatable)
+    return FALSE;
 
   secname = bfd_get_section_name (s->owner, s);
 
@@ -758,7 +703,7 @@ gld${EMULATION_NAME}_place_orphan (file, s)
   if (*secname == '\$')
     einfo ("%P%F: section %s has '\$' as first character\n", secname);
   if (strchr (secname + 1, '\$') == NULL)
-    return false;
+    return FALSE;
 
   /* Look up the output section.  The Microsoft specs say sections names in
      image files never contain a '\$'.  Fortunately, lang_..._lookup creates
@@ -802,12 +747,12 @@ gld${EMULATION_NAME}_place_orphan (file, s)
       tmp->spec.name = xmalloc (strlen (output_secname) + 2);
       sprintf (tmp->spec.name, "%s\$", output_secname);
       tmp->spec.exclude_name_list = NULL;
-      tmp->sorted = false;
+      tmp->sorted = FALSE;
       new = new_stat (lang_wild_statement, &os->children);
       new->filename = NULL;
-      new->filenames_sorted = false;
+      new->filenames_sorted = FALSE;
       new->section_list = tmp;
-      new->keep_sections = false;
+      new->keep_sections = FALSE;
       lang_list_init (&new->children);
       l = new;
     }
@@ -819,12 +764,11 @@ gld${EMULATION_NAME}_place_orphan (file, s)
      sort_sections.  */
   lang_add_section (&l->wild_statement.children, s, os, file);
 
-  return true;
+  return TRUE;
 }
 \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.
@@ -834,19 +778,19 @@ cat >>e${EMULATION_NAME}.c <<EOF
 {
   *isfile = 0;
 
-  if (link_info.relocateable == true && config.build_constructors == true)
+  if (link_info.relocatable && 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 (link_info.relocatable) 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
 
@@ -870,10 +814,13 @@ struct ld_emulation_xfer_struct ld_${EMULATION_NAME}_emulation =
   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 */
 };
 EOF