This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

ldemul options


This patch gets rid of the emulation specific getopt_long calls, and
instead arranges for emulation specific options to be added to
getopt_long params in lexsup.c.  Means we don't have to worry about
the silly duplication of long options, and abbreviations will work.
ldemul_parse_args could disappear, except that it's still used by
aix.em to munge argv.

	* ldemul.c (ldemul_add_options, ldemul_handle_option): New functions.
	(ldemul_parse_args): Return bfd_boolean.  Formatting.
	* ldemul.h (ldemul_add_options, ldemul_handle_option): Declare.
	(ldemul_parse_args): Adjust.
	(struct ld_emulation_xfer_struct): Add add_options and handle_option.
	Return bfd_boolean from parse_args.
	* lexsup.c (parse_args): Malloc shortopts, longopts and
	really_longopts.  Call ldemul_add_options and ldemul_handle_option.
	* emultempl/aix.em (gld${EMULATION_NAME}_add_options): Split out from
	gld${EMULATION_NAME}_parse_args.
	(gld${EMULATION_NAME}_handle_option): Likewise.
	(ld_${EMULATION_NAME}_emulation): Adjust initializer.
	* emultempl/armcoff.em: As for aix.em, but remove parse_args.
	* emultempl/beos.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/elf32.em: Likewise.  Don't duplicate long options either.
	(gld${EMULATION_NAME}_add_sysroot): Prototype.	
	* emultempl/armelf.em (PARSE_AND_LIST_LONGOPTS): Don't duplicate
	options.
	* emultempl/hppaelf.em (PARSE_AND_LIST_LONGOPTS): Likewise.
	* emultempl/ppc32elf.em (PARSE_AND_LIST_LONGOPTS): Likewise.
	* emultempl/ppc64elf.em (PARSE_AND_LIST_LONGOPTS): Likewise.
	* emultempl/armelf_oabi.em (ld_${EMULATION_NAME}_emulation): Adjust
	initializer.
	* emultempl/generic.em: Likewise.
	* emultempl/gld960.em: Likewise.
	* emultempl/gld960c.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/lnk960.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/mipsecoff.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/vanilla.em: Likewise.
	* emultempl/netbsd.em (gldnetbsd_before_parse): Prototype.

-- 
Alan Modra
IBM OzLabs - Linux Technology Centre

Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.11
diff -u -p -r1.11 ldemul.c
--- ld/ldemul.c	30 Nov 2002 08:39:45 -0000	1.11
+++ ld/ldemul.c	28 Feb 2003 00:00:46 -0000
@@ -133,17 +133,38 @@ ldemul_place_orphan (file, s)
   return FALSE;
 }
 
-int
+void
+ldemul_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     int ns;
+     char **shortopts;
+     int nl;
+     struct option **longopts;
+     int nrl;
+     struct option **really_longopts;
+{
+  if (ld_emulation->add_options)
+    (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
+				  nrl, really_longopts);
+}
+
+bfd_boolean
+ldemul_handle_option (optc)
+     int optc;
+{
+  if (ld_emulation->handle_option)
+    return (*ld_emulation->handle_option) (optc);
+  return FALSE;
+}
+
+bfd_boolean
 ldemul_parse_args (argc, argv)
      int argc;
      char **argv;
 {
   /* Try and use the emulation parser if there is one.  */
   if (ld_emulation->parse_args)
-    {
-      return ld_emulation->parse_args (argc, argv);
-    }
-  return 0;
+    return (*ld_emulation->parse_args) (argc, argv);
+  return TRUE;
 }
 
 /* Let the emulation code handle an unrecognized file.  */
Index: ld/ldemul.h
===================================================================
RCS file: /cvs/src/src/ld/ldemul.h,v
retrieving revision 1.9
diff -u -p -r1.9 ldemul.h
--- ld/ldemul.h	30 Nov 2002 08:39:45 -0000	1.9
+++ ld/ldemul.h	28 Feb 2003 00:00:46 -0000
@@ -51,8 +51,12 @@ extern void ldemul_create_output_section
   PARAMS ((void));
 extern bfd_boolean ldemul_place_orphan
   PARAMS ((struct lang_input_statement_struct *, asection *));
-extern int ldemul_parse_args
+extern bfd_boolean ldemul_parse_args
   PARAMS ((int, char **));
+extern void ldemul_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+extern bfd_boolean ldemul_handle_option
+  PARAMS ((int));
 extern bfd_boolean ldemul_unrecognized_file
   PARAMS ((struct lang_input_statement_struct *));
 extern bfd_boolean ldemul_recognized_file
@@ -142,9 +146,18 @@ typedef struct ld_emulation_xfer_struct 
      reading the script.  Used to initialize symbols used in the script.  */
   void	(*set_symbols) PARAMS ((void));
 
-  /* Run to parse args which the base linker doesn't
-     understand. Return non zero on sucess.  */
-  int (*parse_args) PARAMS ((int, char **));
+  /* Parse args which the base linker doesn't understand.
+     Return TRUE if the arg needs no further processing.  */
+  bfd_boolean (*parse_args) PARAMS ((int, char **));
+
+  /* Hook to add options to parameters passed by the base linker to
+     getopt_long and getopt_long_only calls.  */
+  void (*add_options)
+    PARAMS ((int, char **, int, struct option **, int, struct option **));
+
+  /* Companion to the above to handle an option.  Returns TRUE if it is
+     one of our options.  */
+  bfd_boolean (*handle_option) PARAMS ((int));
 
   /* Run to handle files which are not recognized as object files or
      archives.  Return TRUE if the file was handled.  */
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.59
diff -u -p -r1.59 lexsup.c
--- ld/lexsup.c	17 Feb 2003 18:24:37 -0000	1.59
+++ ld/lexsup.c	28 Feb 2003 00:00:47 -0000
@@ -467,11 +467,17 @@ parse_args (argc, argv)
   int is, il, irl;
   int ingroup = 0;
   char *default_dirlist = NULL;
-  char shortopts[OPTION_COUNT * 3 + 2];
-  struct option longopts[OPTION_COUNT + 1];
-  struct option really_longopts[OPTION_COUNT + 1];
+  char *shortopts;
+  struct option *longopts;
+  struct option *really_longopts;
   int last_optind;
 
+  shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
+  longopts = (struct option *) xmalloc (sizeof (*longopts)
+					* (OPTION_COUNT + 1));
+  really_longopts = (struct option *) xmalloc (sizeof (*really_longopts)
+					       * (OPTION_COUNT + 1));
+
   /* Starting the short option string with '-' is for programs that
      expect options and other ARGV-elements in any order and that care about
      the ordering of the two.  We describe each non-option ARGV-element
@@ -516,6 +522,8 @@ parse_args (argc, argv)
   longopts[il].name = NULL;
   really_longopts[irl].name = NULL;
 
+  ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
+
   /* The -G option is ambiguous on different platforms.  Sometimes it
      specifies the largest data size to put into the small data
      section.  Sometimes it is equivalent to --shared.  Unfortunately,
@@ -585,6 +593,9 @@ parse_args (argc, argv)
 	  optind = last_optind;
 	  optc = getopt_long (argc, argv, "-", really_longopts, &longind);
 	}
+
+      if (ldemul_handle_option (optc))
+	continue;
 
       if (optc == -1)
 	break;
Index: ld/emultempl/aix.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/aix.em,v
retrieving revision 1.30
diff -u -p -r1.30 aix.em
--- ld/emultempl/aix.em	30 Nov 2002 08:39:46 -0000	1.30
+++ ld/emultempl/aix.em	28 Feb 2003 00:00:48 -0000
@@ -9,7 +9,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* AIX emulation code for ${EMULATION_NAME}
-   Copyright 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2001, 2002
+   Copyright 1991, 1993, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac at cygnus dot com>
    AIX support by Ian Lance Taylor <ian at cygnus dot com>
@@ -58,8 +58,12 @@ Foundation, Inc., 59 Temple Place - Suit
 
 static void gld${EMULATION_NAME}_before_parse
   PARAMS ((void));
-static int gld${EMULATION_NAME}_parse_args
+static bfd_boolean gld${EMULATION_NAME}_parse_args
   PARAMS ((int, char **));
+static void gld${EMULATION_NAME}_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+static bfd_boolean gld${EMULATION_NAME}_handle_option
+  PARAMS ((int));
 static void gld${EMULATION_NAME}_after_open
   PARAMS ((void));
 static char *gld${EMULATION_NAME}_choose_target
@@ -180,20 +184,7 @@ gld${EMULATION_NAME}_before_parse ()
 
 /* Handle AIX specific options.  */
 
-static int
-gld${EMULATION_NAME}_parse_args (argc, argv)
-     int argc;
-     char **argv;
-{
-  int prevoptind = optind;
-  int prevopterr = opterr;
-  int indx;
-  int longind;
-  int optc;
-  bfd_signed_vma val;
-  const char *end;
-
-  enum
+enum
   {
     OPTION_IGNORE = 300,
     OPTION_AUTOIMP,
@@ -218,6 +209,17 @@ gld${EMULATION_NAME}_parse_args (argc, a
     OPTION_NOLIBPATH,
   };
 
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     int ns;
+     char **shortopts;
+     int nl;
+     struct option **longopts;
+     int nrl ATTRIBUTE_UNUSED;
+     struct option **really_longopts ATTRIBUTE_UNUSED;
+{
+  static const char xtra_short[] = "D:H:KT:z";
+  static const struct option xtra_long[] = {
   /* -binitfini has special handling in the linker backend.  The native linker
      uses the arguemnts to generate a table of init and fini functions for
      the executable.  The important use for this option is to support aix 4.2+
@@ -227,7 +229,6 @@ gld${EMULATION_NAME}_parse_args (argc, a
      the first symbol in the loader symbol table is __rtinit.  The gnu linker
      generates this symbol and makes it the first loader symbol.  */
 
-  static const struct option longopts[] = {
     {"basis", no_argument, NULL, OPTION_IGNORE},
     {"bautoimp", no_argument, NULL, OPTION_AUTOIMP},
     {"bcomprld", no_argument, NULL, OPTION_IGNORE},
@@ -288,6 +289,20 @@ gld${EMULATION_NAME}_parse_args (argc, a
      -bnotypchk, -bnox, -bquiet, -bR, -brename, -breorder, -btypchk,
      -bx, -bX, -bxref.  */
 
+  *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
+  memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
+  *longopts = (struct option *)
+    xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
+}
+
+static bfd_boolean
+gld${EMULATION_NAME}_parse_args (argc, argv)
+     int argc;
+     char **argv;
+{
+  int indx;
+
   /* If the current option starts with -b, change the first : to an =.
      The AIX linker uses : to separate the option from the argument;
      changing it to = lets us treat it as a getopt option.  */
@@ -308,22 +323,20 @@ gld${EMULATION_NAME}_parse_args (argc, a
 	    }
 	}
     }
+  return FALSE;
+}
 
-
-  /* We add s and u so to the short options list so that -s and -u on
-     the command line do not match -static and -unix.  */
-
-  opterr = 0;
-  optc = getopt_long_only (argc, argv, "-D:H:KT:zsu", longopts, &longind);
-  opterr = prevopterr;
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     int optc;
+{
+  bfd_signed_vma val;
+  const char *end;
 
   switch (optc)
     {
-    case 's':
-    case 'u':
     default:
-      optind = prevoptind;
-      return 0;
+      return FALSE;
 
     case 0:
       /* Long option which just sets a flag.  */
@@ -358,10 +371,7 @@ gld${EMULATION_NAME}_parse_args (argc, a
 	 ignore the AIX option, because gcc passes it to the linker.  */
       val = bfd_scan_vma (optarg, &end, 0);
       if (*end != '\0')
-	{
-	  optind = prevoptind;
-	  return 0;
-	}
+	return FALSE;
       lang_section_start (".text", exp_intop (val));
       break;
 
@@ -552,7 +562,7 @@ gld${EMULATION_NAME}_parse_args (argc, a
 
     }
 
-  return 1;
+  return TRUE;
 }
 
 /* This is called when an input file can not be recognized as a BFD
@@ -945,7 +955,7 @@ is_syscall (input, flag)
 
 /* Read an import or export file.  For an import file, this is called
    by the before_allocation emulation routine.  For an export file,
-   this is called by the parse_args emulation routine.  */
+   this is called by the handle_option emulation routine.  */
 
 static void
 gld${EMULATION_NAME}_read_file (filename, import)
@@ -1391,6 +1401,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   0,				/* place_orphan */
   0,				/* set_symbols */
   gld${EMULATION_NAME}_parse_args,
+  gld${EMULATION_NAME}_add_options,
+  gld${EMULATION_NAME}_handle_option,
   gld${EMULATION_NAME}_unrecognized_file,
   NULL,				/* list_options */
   NULL,				/* recognized_file */
Index: ld/emultempl/armcoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armcoff.em,v
retrieving revision 1.14
diff -u -p -r1.14 armcoff.em
--- ld/emultempl/armcoff.em	30 Nov 2002 08:39:46 -0000	1.14
+++ ld/emultempl/armcoff.em	28 Feb 2003 00:00:48 -0000
@@ -4,7 +4,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* emulate the original gld for the given ${EMULATION_NAME}
-   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve at cygnus dot com
 
@@ -43,8 +43,10 @@ Foundation, Inc., 59 Temple Place - Suit
 static void gld${EMULATION_NAME}_before_parse PARAMS ((void));
 static void gld${EMULATION_NAME}_before_allocation PARAMS ((void));
 static char *gld${EMULATION_NAME}_get_script PARAMS ((int *isfile));
-static int  gld${EMULATION_NAME}_parse_args PARAMS((int, char **));
+static void gld${EMULATION_NAME}_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
 static void gld${EMULATION_NAME}_list_options PARAMS ((FILE *));
+static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
 static void gld${EMULATION_NAME}_finish PARAMS ((void));
 static void gld${EMULATION_NAME}_after_open PARAMS ((void));
 
@@ -57,12 +59,25 @@ static char * thumb_entry_symbol = NULL;
 #define OPTION_SUPPORT_OLD_CODE		300
 #define OPTION_THUMB_ENTRY		301
 
-static struct option longopts[] =
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     int ns ATTRIBUTE_UNUSED;
+     char **shortopts ATTRIBUTE_UNUSED;
+     int nl;
+     struct option **longopts;
+     int nrl ATTRIBUTE_UNUSED;
+     struct option **really_longopts ATTRIBUTE_UNUSED;
 {
-  {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
-  {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
-  {NULL, no_argument, NULL, 0}
-};
+  static const struct option xtra_long[] = {
+    {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
+    {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
+    {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));
+}
 
 static void
 gld${EMULATION_NAME}_list_options (file)
@@ -72,34 +87,14 @@ gld${EMULATION_NAME}_list_options (file)
   fprintf (file, _("  --thumb-entry=<sym>  Set the entry point to be Thumb symbol <sym>\n"));
 }
 
-static int
-gld${EMULATION_NAME}_parse_args (argc, argv)
-     int     argc;
-     char ** argv;
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     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_SUPPORT_OLD_CODE:
       support_old_code = 1;
@@ -110,7 +105,7 @@ gld${EMULATION_NAME}_parse_args (argc, a
       break;
     }
   
-  return 1;
+  return TRUE;
 }
 
 static void
@@ -286,7 +281,9 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
-  gld${EMULATION_NAME}_parse_args,
+  NULL, /* parse_args */
+  gld${EMULATION_NAME}_add_options,
+  gld${EMULATION_NAME}_handle_option,
   NULL,	/* unrecognised file */
   gld${EMULATION_NAME}_list_options,
   NULL,	/* recognized file */
Index: ld/emultempl/armelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armelf.em,v
retrieving revision 1.32
diff -u -p -r1.32 armelf.em
--- ld/emultempl/armelf.em	7 Feb 2003 15:32:22 -0000	1.32
+++ ld/emultempl/armelf.em	28 Feb 2003 00:00:48 -0000
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2002
+#   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2002, 2003
 #   Free Software Foundation, Inc.
 #
 # This file is part of GLD, the Gnu Linker.
@@ -195,11 +195,7 @@ PARSE_AND_LIST_PROLOGUE='
 
 PARSE_AND_LIST_SHORTOPTS=p
 
-# Note we have duplicate entries for no-pipeline-knowledge in order
-# to prevent getopt_long_only from thinking that -n is a unique
-# abbreviation for --no-pipeline-knowledge.
 PARSE_AND_LIST_LONGOPTS='
-  { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
   { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
   { "thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
 '
Index: ld/emultempl/armelf_oabi.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/armelf_oabi.em,v
retrieving revision 1.10
diff -u -p -r1.10 armelf_oabi.em
--- ld/emultempl/armelf_oabi.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/armelf_oabi.em	28 Feb 2003 00:00:48 -0000
@@ -4,7 +4,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* emulate the original gld for the given ${EMULATION_NAME}
-   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002
+   Copyright 1991, 1993, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve at cygnus dot com
 
@@ -171,6 +171,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/beos.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/beos.em,v
retrieving revision 1.20
diff -u -p -r1.20 beos.em
--- ld/emultempl/beos.em	30 Nov 2002 08:39:46 -0000	1.20
+++ ld/emultempl/beos.em	28 Feb 2003 00:00:48 -0000
@@ -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
    Free Software Foundation, Inc.
 
 This program is free software; you can redistribute it and/or modify
@@ -58,7 +58,6 @@ static void gld_${EMULATION_NAME}_before
 static bfd_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));
@@ -110,8 +109,20 @@ 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
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     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 +137,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 */
@@ -299,35 +315,17 @@ set_pe_stack_heap (resname, comname)
 }
 
 
+static bfd_boolean gld${EMULATION_NAME}_handle_option
+  PARAMS ((int));
 
-static int
-gld_${EMULATION_NAME}_parse_args(argc, argv)
-     int argc;
-     char **argv;
-{
-  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;
-
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     int optc;
+{
   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);
@@ -380,7 +378,7 @@ gld_${EMULATION_NAME}_parse_args(argc, a
       set_pe_value ("__image_base__");
       break;
     }
-  return 1;
+  return TRUE;
 }
 
 /* Assign values to the special symbols before the linker script is
@@ -870,7 +868,9 @@ struct ld_emulation_xfer_struct ld_${EMU
   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 */
Index: ld/emultempl/elf32.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/elf32.em,v
retrieving revision 1.92
diff -u -p -r1.92 elf32.em
--- ld/emultempl/elf32.em	26 Feb 2003 00:56:14 -0000	1.92
+++ ld/emultempl/elf32.em	28 Feb 2003 00:00:52 -0000
@@ -51,6 +51,7 @@ Foundation, Inc., 59 Temple Place - Suit
 #include "ldemul.h"
 #include <ldgram.h>
 #include "elf/common.h"
+#include "getopt.h"
 
 static void gld${EMULATION_NAME}_before_parse
   PARAMS ((void));
@@ -444,6 +445,8 @@ if [ "x${USE_LIBPATH}" = xyes ] ; then
 
 /* Add the sysroot to every entry in a colon-separated path.  */
 
+static char * gld${EMULATION_NAME}_add_sysroot PARAMS ((const char *));
+
 static char *
 gld${EMULATION_NAME}_add_sysroot (path)
      const char *path;
@@ -1514,8 +1517,6 @@ fi
 
 if test -n "$PARSE_AND_LIST_ARGS_CASES" -o x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 
-if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then
-
 if test -n "$PARSE_AND_LIST_PROLOGUE" ; then
 cat >>e${EMULATION_NAME}.c <<EOF
  $PARSE_AND_LIST_PROLOGUE
@@ -1524,73 +1525,64 @@ fi
 
 cat >>e${EMULATION_NAME}.c <<EOF
 
-#include "getopt.h"
-
 #define OPTION_DISABLE_NEW_DTAGS	(400)
 #define OPTION_ENABLE_NEW_DTAGS		(OPTION_DISABLE_NEW_DTAGS + 1)
 #define OPTION_GROUP			(OPTION_ENABLE_NEW_DTAGS + 1)
 #define OPTION_EH_FRAME_HDR		(OPTION_GROUP + 1)
 
-static struct option longopts[] =
+static void gld${EMULATION_NAME}_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     int ns;
+     char **shortopts;
+     int nl;
+     struct option **longopts;
+     int nrl ATTRIBUTE_UNUSED;
+     struct option **really_longopts ATTRIBUTE_UNUSED;
 {
+  static const char xtra_short[] = "${PARSE_AND_LIST_SHORTOPTS}z:";
+  static const struct option xtra_long[] = {
 EOF
 
 if test x"$GENERATE_SHLIB_SCRIPT" = xyes; then
 cat >>e${EMULATION_NAME}.c <<EOF
-  /* getopt allows abbreviations, so we do this to stop it from
-     treating -d/-e as abbreviations for these options. */
-  {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
-  {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
-  {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
-  {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
-  {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
-  {"Bgroup", no_argument, NULL, OPTION_GROUP},
-  {"Bgroup", no_argument, NULL, OPTION_GROUP},
+    {"disable-new-dtags", no_argument, NULL, OPTION_DISABLE_NEW_DTAGS},
+    {"enable-new-dtags", no_argument, NULL, OPTION_ENABLE_NEW_DTAGS},
+    {"eh-frame-hdr", no_argument, NULL, OPTION_EH_FRAME_HDR},
+    {"Bgroup", no_argument, NULL, OPTION_GROUP},
 EOF
 fi
 
 if test -n "$PARSE_AND_LIST_LONGOPTS" ; then
 cat >>e${EMULATION_NAME}.c <<EOF
- $PARSE_AND_LIST_LONGOPTS
+    $PARSE_AND_LIST_LONGOPTS
 EOF
 fi
 
 cat >>e${EMULATION_NAME}.c <<EOF
-  {NULL, no_argument, NULL, 0}
-};
+    {NULL, no_argument, NULL, 0}
+  };
 
+  *shortopts = (char *) xrealloc (*shortopts, ns + sizeof (xtra_short));
+  memcpy (*shortopts + ns, &xtra_short, sizeof (xtra_short));
+  *longopts = (struct option *)
+    xrealloc (*longopts, nl * sizeof (struct option) + sizeof (xtra_long));
+  memcpy (*longopts + nl, &xtra_long, sizeof (xtra_long));
+}
 
-static int gld${EMULATION_NAME}_parse_args PARAMS ((int, char **));
-
-static int
-gld${EMULATION_NAME}_parse_args (argc, argv)
-     int argc;
-     char ** argv;
-{
-  int longind;
-  int optc;
-  static int prevoptind = -1;
-  int prevopterr = opterr;
-  int wanterror;
-
-  if (prevoptind != optind)
-    opterr = 0;
-
-  wanterror = opterr;
-  prevoptind = optind;
-
-  optc = getopt_long_only (argc, argv,
-			   "-${PARSE_AND_LIST_SHORTOPTS}z:", longopts,
-			   &longind);
-  opterr = prevopterr;
+static bfd_boolean gld${EMULATION_NAME}_handle_option
+  PARAMS ((int));
 
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     int optc;
+{
   switch (optc)
     {
     default:
-      if (wanterror)
-	xexit (1);
-      optind = prevoptind;
-      return 0;
+      return FALSE;
 
 EOF
 
@@ -1663,11 +1655,10 @@ fi
 cat >>e${EMULATION_NAME}.c <<EOF
     }
 
-  return 1;
+  return TRUE;
 }
 
 EOF
-fi
 
 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
 cat >>e${EMULATION_NAME}.c <<EOF
@@ -1721,11 +1712,10 @@ EOF
 fi
 fi
 else
-if test x"$LDEMUL_PARSE_ARGS" != xgld"$EMULATION_NAME"_parse_args; then
 cat >>e${EMULATION_NAME}.c <<EOF
-#define gld${EMULATION_NAME}_parse_args   NULL
+#define gld${EMULATION_NAME}_add_options NULL
+#define gld${EMULATION_NAME}_handle_option NULL
 EOF
-fi
 if test x"$LDEMUL_LIST_OPTIONS" != xgld"$EMULATION_NAME"_list_options; then
 cat >>e${EMULATION_NAME}.c <<EOF
 #define gld${EMULATION_NAME}_list_options NULL
@@ -1754,7 +1744,9 @@ struct ld_emulation_xfer_struct ld_${EMU
   ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
   ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
   ${LDEMUL_SET_SYMBOLS-NULL},
-  ${LDEMUL_PARSE_ARGS-gld${EMULATION_NAME}_parse_args},
+  ${LDEMUL_PARSE_ARGS-NULL},
+  gld${EMULATION_NAME}_add_options,
+  gld${EMULATION_NAME}_handle_option,
   ${LDEMUL_UNRECOGNIZED_FILE-NULL},
   ${LDEMUL_LIST_OPTIONS-gld${EMULATION_NAME}_list_options},
   ${LDEMUL_RECOGNIZED_FILE-NULL},
Index: ld/emultempl/generic.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/generic.em,v
retrieving revision 1.10
diff -u -p -r1.10 generic.em
--- ld/emultempl/generic.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/generic.em	28 Feb 2003 00:00:52 -0000
@@ -141,6 +141,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   ${LDEMUL_PLACE_ORPHAN-NULL},
   ${LDEMUL_SET_SYMBOLS-NULL},
   ${LDEMUL_PARSE_ARGS-NULL},
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   ${LDEMUL_UNRECOGNIZED_FILE-NULL},
   ${LDEMUL_LIST_OPTIONS-NULL},
   ${LDEMUL_RECOGNIZED_FILE-NULL},
Index: ld/emultempl/gld960.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/gld960.em,v
retrieving revision 1.10
diff -u -p -r1.10 gld960.em
--- ld/emultempl/gld960.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/gld960.em	28 Feb 2003 00:00:52 -0000
@@ -1,7 +1,7 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
 cat >e${EMULATION_NAME}.c <<EOF
-/* Copyright 1991, 1992, 1994, 1999, 2000, 2001, 2002
+/* Copyright 1991, 1992, 1994, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
@@ -186,6 +186,8 @@ struct ld_emulation_xfer_struct ld_gld96
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/gld960c.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/gld960c.em,v
retrieving revision 1.11
diff -u -p -r1.11 gld960c.em
--- ld/emultempl/gld960c.em	30 Nov 2002 08:39:46 -0000	1.11
+++ ld/emultempl/gld960c.em	28 Feb 2003 00:00:52 -0000
@@ -1,7 +1,7 @@
 # This shell script emits a C file. -*- C -*-
 # It does some substitutions.
 cat >e${EMULATION_NAME}.c <<EOF
-/* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002
+/* Copyright 1991, 1993, 1994, 1996, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
 
 This file is part of GLD, the Gnu Linker.
@@ -201,6 +201,8 @@ struct ld_emulation_xfer_struct ld_gld96
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/hppaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/hppaelf.em,v
retrieving revision 1.27
diff -u -p -r1.27 hppaelf.em
--- ld/emultempl/hppaelf.em	21 Feb 2003 10:51:24 -0000	1.27
+++ ld/emultempl/hppaelf.em	28 Feb 2003 00:00:52 -0000
@@ -360,12 +360,8 @@ PARSE_AND_LIST_PROLOGUE='
 #define OPTION_STUBGROUP_SIZE		(OPTION_MULTI_SUBSPACE + 1)
 '
 
-# The options are repeated below so that no abbreviations are allowed.
-# Otherwise -s matches stub-group-size
 PARSE_AND_LIST_LONGOPTS='
   { "multi-subspace", no_argument, NULL, OPTION_MULTI_SUBSPACE },
-  { "multi-subspace", no_argument, NULL, OPTION_MULTI_SUBSPACE },
-  { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
 '
 
Index: ld/emultempl/linux.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/linux.em,v
retrieving revision 1.10
diff -u -p -r1.10 linux.em
--- ld/emultempl/linux.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/linux.em	28 Feb 2003 00:00:52 -0000
@@ -9,7 +9,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* Linux a.out emulation code for ${EMULATION_NAME}
-   Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002
+   Copyright 1991, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac at cygnus dot com>
    Linux support by Eric Youngdale <ericy at cais dot cais dot com>
@@ -218,6 +218,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/lnk960.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/lnk960.em,v
retrieving revision 1.10
diff -u -p -r1.10 lnk960.em
--- ld/emultempl/lnk960.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/lnk960.em	28 Feb 2003 00:00:52 -0000
@@ -2,7 +2,7 @@
 # It does some substitutions.
 cat >e${EMULATION_NAME}.c <<EOF
 /* intel coff loader emulation specific stuff
-   Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002
+   Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve at cygnus dot com
 
@@ -341,6 +341,8 @@ struct ld_emulation_xfer_struct ld_lnk96
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/m68kcoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/m68kcoff.em,v
retrieving revision 1.5
diff -u -p -r1.5 m68kcoff.em
--- ld/emultempl/m68kcoff.em	30 Nov 2002 08:39:46 -0000	1.5
+++ ld/emultempl/m68kcoff.em	28 Feb 2003 00:00:52 -0000
@@ -4,7 +4,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* Handle embedded relocs for m68k.
-   Copyright 2000, 2002 Free Software Foundation, Inc.
+   Copyright 2000, 2002, 2003 Free Software Foundation, Inc.
    Written by Michael Sokolov <msokolov at ivan dot Harhan dot ORG>, based on generic.em
    by Steve Chamberlain <steve at cygnus dot com>, embedded relocs code based on
    mipsecoff.em by Ian Lance Taylor <ian at cygnus dot com>.
@@ -237,6 +237,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/mipsecoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/mipsecoff.em,v
retrieving revision 1.10
diff -u -p -r1.10 mipsecoff.em
--- ld/emultempl/mipsecoff.em	30 Nov 2002 08:39:46 -0000	1.10
+++ ld/emultempl/mipsecoff.em	28 Feb 2003 00:00:52 -0000
@@ -9,7 +9,8 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* Handle embedded relocs for MIPS.
-   Copyright 1994, 1995, 1997, 2000, 2002 Free Software Foundation, Inc.
+   Copyright 1994, 1995, 1997, 2000, 2002, 2003
+   Free Software Foundation, Inc.
    Written by Ian Lance Taylor <ian at cygnus dot com> based on generic.em.
 
 This file is part of GLD, the Gnu Linker.
@@ -252,6 +253,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/netbsd.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/netbsd.em,v
retrieving revision 1.1
diff -u -p -r1.1 netbsd.em
--- ld/emultempl/netbsd.em	31 Jul 2002 12:50:09 -0000	1.1
+++ ld/emultempl/netbsd.em	28 Feb 2003 00:00:52 -0000
@@ -1,5 +1,7 @@
 LDEMUL_BEFORE_PARSE=gldnetbsd_before_parse
 cat >>e${EMULATION_NAME}.c <<EOF
+static void gldnetbsd_before_parse PARAMS ((void));
+
 static void
 gldnetbsd_before_parse ()
 {
Index: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.75
diff -u -p -r1.75 pe.em
--- ld/emultempl/pe.em	23 Jan 2003 09:30:44 -0000	1.75
+++ ld/emultempl/pe.em	28 Feb 2003 00:00:53 -0000
@@ -114,10 +114,12 @@ static asection *output_prev_sec_find
 static bfd_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 void gld_${EMULATION_NAME}_finish PARAMS ((void));
 static bfd_boolean gld_${EMULATION_NAME}_open_dynamic_archive
   PARAMS ((const char *, search_dirs_type *, lang_input_statement_type *));
+static void gld${EMULATION_NAME}_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
 static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
 static void set_pe_name PARAMS ((char *, long));
 static void set_pe_subsystem PARAMS ((void));
@@ -228,55 +230,68 @@ gld_${EMULATION_NAME}_before_parse()
 #define OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC	\
 					(OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC + 1)
 
-static struct option longopts[] = {
-  /* 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},
-  {"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},
-  {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
-  {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
-  {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
-  {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
-  {"stack", required_argument, NULL, OPTION_STACK},
-  {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
-  {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
-  {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     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},
+    {"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},
+    {"minor-image-version", required_argument, NULL, OPTION_MINOR_IMAGE_VERSION},
+    {"minor-os-version", required_argument, NULL, OPTION_MINOR_OS_VERSION},
+    {"minor-subsystem-version", required_argument, NULL, OPTION_MINOR_SUBSYSTEM_VERSION},
+    {"section-alignment", required_argument, NULL, OPTION_SECTION_ALIGNMENT},
+    {"stack", required_argument, NULL, OPTION_STACK},
+    {"subsystem", required_argument, NULL, OPTION_SUBSYSTEM},
+    {"support-old-code", no_argument, NULL, OPTION_SUPPORT_OLD_CODE},
+    {"thumb-entry", required_argument, NULL, OPTION_THUMB_ENTRY},
 #ifdef DLL_SUPPORT
-  /* getopt allows abbreviations, so we do this to stop it from treating -o
-     as an abbreviation for this option */
-  {"output-def", required_argument, NULL, OPTION_OUT_DEF},
-  {"output-def", required_argument, NULL, OPTION_OUT_DEF},
-  {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
-  {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
-  {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
-  {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
-  {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
-  {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
-  {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
-  {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
-  {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
-  /* getopt() allows abbreviations, so we do this to stop it from
-     treating -c as an abbreviation for these --compat-implib.  */
-  {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
-  {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
-  {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
-  {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
-  {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
-  {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
-  {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
-  {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
-  {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
-  {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
-  {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
-#endif
-  {NULL, no_argument, NULL, 0}
-};
-
+    /* getopt allows abbreviations, so we do this to stop it from treating -o
+       as an abbreviation for this option */
+    {"output-def", required_argument, NULL, OPTION_OUT_DEF},
+    {"output-def", required_argument, NULL, OPTION_OUT_DEF},
+    {"export-all-symbols", no_argument, NULL, OPTION_EXPORT_ALL},
+    {"exclude-symbols", required_argument, NULL, OPTION_EXCLUDE_SYMBOLS},
+    {"exclude-libs", required_argument, NULL, OPTION_EXCLUDE_LIBS},
+    {"kill-at", no_argument, NULL, OPTION_KILL_ATS},
+    {"add-stdcall-alias", no_argument, NULL, OPTION_STDCALL_ALIASES},
+    {"enable-stdcall-fixup", no_argument, NULL, OPTION_ENABLE_STDCALL_FIXUP},
+    {"disable-stdcall-fixup", no_argument, NULL, OPTION_DISABLE_STDCALL_FIXUP},
+    {"out-implib", required_argument, NULL, OPTION_IMPLIB_FILENAME},
+    {"warn-duplicate-exports", no_argument, NULL, OPTION_WARN_DUPLICATE_EXPORTS},
+    /* getopt() allows abbreviations, so we do this to stop it from
+       treating -c as an abbreviation for these --compat-implib.  */
+    {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
+    {"compat-implib", no_argument, NULL, OPTION_IMP_COMPAT},
+    {"enable-auto-image-base", no_argument, NULL, OPTION_ENABLE_AUTO_IMAGE_BASE},
+    {"disable-auto-image-base", no_argument, NULL, OPTION_DISABLE_AUTO_IMAGE_BASE},
+    {"dll-search-prefix", required_argument, NULL, OPTION_DLL_SEARCH_PREFIX},
+    {"no-default-excludes", no_argument, NULL, OPTION_NO_DEFAULT_EXCLUDES},
+    {"enable-auto-import", no_argument, NULL, OPTION_DLL_ENABLE_AUTO_IMPORT},
+    {"disable-auto-import", no_argument, NULL, OPTION_DLL_DISABLE_AUTO_IMPORT},
+    {"enable-extra-pe-debug", no_argument, NULL, OPTION_ENABLE_EXTRA_PE_DEBUG},
+    {"enable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_ENABLE_RUNTIME_PSEUDO_RELOC},
+    {"disable-runtime-pseudo-reloc", no_argument, NULL, OPTION_DLL_DISABLE_RUNTIME_PSEUDO_RELOC},
+#endif
+    {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.  */
@@ -512,34 +527,14 @@ set_pe_stack_heap (resname, comname)
 }
 
 
-static int
-gld_${EMULATION_NAME}_parse_args (argc, argv)
-     int argc;
-     char **argv;
-{
-  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;
-
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     int optc;
+{
   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);
@@ -661,7 +656,7 @@ gld_${EMULATION_NAME}_parse_args (argc, 
       break;
 #endif
     }
-  return 1;
+  return TRUE;
 }
 
 
@@ -1968,7 +1963,9 @@ struct ld_emulation_xfer_struct ld_${EMU
   gld_${EMULATION_NAME}_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,
   gld_${EMULATION_NAME}_unrecognized_file,
   gld_${EMULATION_NAME}_list_options,
   gld_${EMULATION_NAME}_recognized_file,
Index: ld/emultempl/ppc32elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc32elf.em,v
retrieving revision 1.1
diff -u -p -r1.1 ppc32elf.em
--- ld/emultempl/ppc32elf.em	18 Feb 2003 06:05:06 -0000	1.1
+++ ld/emultempl/ppc32elf.em	28 Feb 2003 00:00:53 -0000
@@ -61,9 +61,7 @@ PARSE_AND_LIST_PROLOGUE='
 #define OPTION_NO_TLS_OPT		301
 '
 
-# The options are repeated below so that no abbreviations are allowed.
 PARSE_AND_LIST_LONGOPTS='
-  { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
   { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
 '
 
Index: ld/emultempl/ppc64elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ppc64elf.em,v
retrieving revision 1.15
diff -u -p -r1.15 ppc64elf.em
--- ld/emultempl/ppc64elf.em	21 Feb 2003 10:51:24 -0000	1.15
+++ ld/emultempl/ppc64elf.em	28 Feb 2003 00:00:53 -0000
@@ -476,16 +476,10 @@ PARSE_AND_LIST_PROLOGUE='
 #define OPTION_NO_TLS_OPT		(OPTION_NO_DOTSYMS + 1)
 '
 
-# The options are repeated below so that no abbreviations are allowed.
-# Otherwise -s matches stub-group-size
 PARSE_AND_LIST_LONGOPTS='
   { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
-  { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
-  { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
   { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
   { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
-  { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
-  { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
   { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
 '
 
Index: ld/emultempl/sunos.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/sunos.em,v
retrieving revision 1.11
diff -u -p -r1.11 sunos.em
--- ld/emultempl/sunos.em	30 Nov 2002 08:39:46 -0000	1.11
+++ ld/emultempl/sunos.em	28 Feb 2003 00:00:53 -0000
@@ -9,7 +9,7 @@ cat >e${EMULATION_NAME}.c <<EOF
 /* This file is is generated by a shell script.  DO NOT EDIT! */
 
 /* SunOS emulation code for ${EMULATION_NAME}
-   Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002
+   Copyright 1991, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003
    Free Software Foundation, Inc.
    Written by Steve Chamberlain <sac at cygnus dot com>
    SunOS shared library support by Ian Lance Taylor <ian at cygnus dot com>
@@ -1047,6 +1047,8 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* place orphan */
   gld${EMULATION_NAME}_set_symbols,
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */
Index: ld/emultempl/ticoff.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ticoff.em,v
retrieving revision 1.5
diff -u -p -r1.5 ticoff.em
--- ld/emultempl/ticoff.em	30 Nov 2002 08:39:46 -0000	1.5
+++ ld/emultempl/ticoff.em	28 Feb 2003 00:00:53 -0000
@@ -3,7 +3,7 @@
 (echo;echo;echo;echo)>e${EMULATION_NAME}.c # there, now line numbers match ;-)
 cat >>e${EMULATION_NAME}.c <<EOF
 /* This file is part of GLD, the Gnu Linker.
-   Copyright 1999, 2000, 2002 Free Software Foundation, Inc.
+   Copyright 1999, 2000, 2002, 2003 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
@@ -43,18 +43,33 @@ static int coff_version;
 
 static void gld_${EMULATION_NAME}_before_parse PARAMS ((void));
 static char *gld_${EMULATION_NAME}_get_script PARAMS ((int *));
-static int gld_${EMULATION_NAME}_parse_args PARAMS ((int, char **));
+static void gld${EMULATION_NAME}_add_options
+  PARAMS ((int, char **, int, struct option **, int, struct option **));
+static bfd_boolean gld${EMULATION_NAME}_handle_option PARAMS ((int));
 static void gld_${EMULATION_NAME}_list_options PARAMS ((FILE *));
 
 /* TI COFF extra command line options */
 #define OPTION_COFF_FORMAT		(300 + 1)
 
-static struct option longopts[] = 
+static void
+gld${EMULATION_NAME}_add_options (ns, shortopts, nl, longopts, nrl, really_longopts)
+     int ns ATTRIBUTE_UNUSED;
+     char **shortopts ATTRIBUTE_UNUSED;
+     int nl;
+     struct option **longopts;
+     int nrl ATTRIBUTE_UNUSED;
+     struct option **really_longopts ATTRIBUTE_UNUSED;
 {
-  /* TI COFF options */
-  {"format", required_argument, NULL, OPTION_COFF_FORMAT },
-  {NULL, no_argument, NULL, 0}
-};
+  static const struct option xtra_long[] = {
+    /* TI COFF options */
+    {"format", required_argument, NULL, OPTION_COFF_FORMAT },
+    {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));
+}
 
 static void
 gld_${EMULATION_NAME}_list_options (file)
@@ -63,34 +78,14 @@ gld_${EMULATION_NAME}_list_options (file
   fprintf (file, _("  --format 0|1|2         Specify which COFF version to use"));
 }				  
 
-static int
-gld_${EMULATION_NAME}_parse_args(argc, argv)
-     int argc;
-     char **argv;
+static bfd_boolean
+gld${EMULATION_NAME}_handle_option (optc)
+     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_COFF_FORMAT:
       if ((*optarg == '0' || *optarg == '1' || *optarg == '2')
@@ -106,11 +101,10 @@ gld_${EMULATION_NAME}_parse_args(argc, a
       else
         {
 	  einfo (_("%P%F: invalid COFF format version %s\n"), optarg);
-
         }
       break;
     }
-  return 1;
+  return FALSE;
 }
 
 static void
@@ -193,7 +187,9 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL, /* open dynamic archive */
   NULL, /* place orphan */
   NULL, /* set_symbols */
-  gld_${EMULATION_NAME}_parse_args,
+  NULL, /* parse_args */
+  gld${EMULATION_NAME}_add_options,
+  gld${EMULATION_NAME}_handle_option,
   NULL, /* unrecognized_file */
   gld_${EMULATION_NAME}_list_options,
   NULL, /* recognized file */
Index: ld/emultempl/vanilla.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/vanilla.em,v
retrieving revision 1.7
diff -u -p -r1.7 vanilla.em
--- ld/emultempl/vanilla.em	22 May 2002 09:02:05 -0000	1.7
+++ ld/emultempl/vanilla.em	28 Feb 2003 00:00:53 -0000
@@ -2,7 +2,8 @@
 # It does some substitutions.
 cat >e${EMULATION_NAME}.c <<EOF
 /* A vanilla emulation with no defaults
-   Copyright 1991, 1992, 1994, 2000, 2001 Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1994, 2000, 2001, 2002, 2003
+   Free Software Foundation, Inc.
    Written by Steve Chamberlain steve at cygnus dot com
 
 This file is part of GLD, the Gnu Linker.
@@ -79,6 +80,8 @@ struct ld_emulation_xfer_struct ld_vanil
   NULL,	/* place orphan */
   NULL,	/* set symbols */
   NULL,	/* parse args */
+  NULL,	/* add_options */
+  NULL,	/* handle_option */
   NULL,	/* unrecognized file */
   NULL,	/* list options */
   NULL,	/* recognized file */


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