+static void
+parse_args (int * pargc, char *** pargv)
+{
+ int old_argc;
+ int new_argc;
+ char ** old_argv;
+ char ** new_argv;
+ /* 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
+ as if it were the argument of an option with character code 1. */
+ char *shortopts;
+ extern const char *md_shortopts;
+ static const char std_shortopts[] =
+ {
+ '-', 'J',
+#ifndef WORKING_DOT_WORD
+ /* -K is not meaningful if .word is not being hacked. */
+ 'K',
+#endif
+ 'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', ':',':', 'I', ':', 'o', ':',
+#ifndef VMS
+ /* -v takes an argument on VMS, so we don't make it a generic
+ option. */
+ 'v',
+#endif
+ 'w', 'X',
+#ifdef HAVE_ITBL_CPU
+ /* New option for extending instruction set (see also --itbl below). */
+ 't', ':',
+#endif
+ '\0'
+ };
+ struct option *longopts;
+ extern struct option md_longopts[];
+ extern size_t md_longopts_size;
+ /* Codes used for the long options with no short synonyms. */
+ enum option_values
+ {
+ OPTION_HELP = OPTION_STD_BASE,
+ OPTION_NOCPP,
+ OPTION_STATISTICS,
+ OPTION_VERSION,
+ OPTION_DUMPCONFIG,
+ OPTION_VERBOSE,
+ OPTION_EMULATION,
+ OPTION_DEBUG_PREFIX_MAP,
+ OPTION_DEFSYM,
+ OPTION_LISTING_LHS_WIDTH,
+ OPTION_LISTING_LHS_WIDTH2,
+ OPTION_LISTING_RHS_WIDTH,
+ OPTION_LISTING_CONT_LINES,
+ OPTION_DEPFILE,
+ OPTION_GSTABS,
+ OPTION_GSTABS_PLUS,
+ OPTION_GDWARF2,
+ OPTION_GDWARF_SECTIONS,
+ OPTION_STRIP_LOCAL_ABSOLUTE,
+ OPTION_TRADITIONAL_FORMAT,
+ OPTION_WARN,
+ OPTION_TARGET_HELP,
+ OPTION_EXECSTACK,
+ OPTION_NOEXECSTACK,
+ OPTION_SIZE_CHECK,
+ OPTION_ELF_STT_COMMON,
+ OPTION_SECTNAME_SUBST,
+ OPTION_ALTERNATE,
+ OPTION_AL,
+ OPTION_HASH_TABLE_SIZE,
+ OPTION_REDUCE_MEMORY_OVERHEADS,
+ OPTION_WARN_FATAL,
+ OPTION_COMPRESS_DEBUG,
+ OPTION_NOCOMPRESS_DEBUG
+ /* When you add options here, check that they do
+ not collide with OPTION_MD_BASE. See as.h. */
+ };
+
+ static const struct option std_longopts[] =
+ {
+ /* Note: commas are placed at the start of the line rather than
+ the end of the preceding line so that it is simpler to
+ selectively add and remove lines from this list. */
+ {"alternate", no_argument, NULL, OPTION_ALTERNATE}
+ /* The entry for "a" is here to prevent getopt_long_only() from
+ considering that -a is an abbreviation for --alternate. This is
+ necessary because -a=<FILE> is a valid switch but getopt would
+ normally reject it since --alternate does not take an argument. */
+ ,{"a", optional_argument, NULL, 'a'}
+ /* Handle -al=<FILE>. */
+ ,{"al", optional_argument, NULL, OPTION_AL}
+ ,{"compress-debug-sections", optional_argument, NULL, OPTION_COMPRESS_DEBUG}
+ ,{"nocompress-debug-sections", no_argument, NULL, OPTION_NOCOMPRESS_DEBUG}
+ ,{"debug-prefix-map", required_argument, NULL, OPTION_DEBUG_PREFIX_MAP}
+ ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
+ ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
+ ,{"emulation", required_argument, NULL, OPTION_EMULATION}
+#if defined OBJ_ELF || defined OBJ_MAYBE_ELF
+ ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
+ ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
+ ,{"size-check", required_argument, NULL, OPTION_SIZE_CHECK}
+ ,{"elf-stt-common", required_argument, NULL, OPTION_ELF_STT_COMMON}
+ ,{"sectname-subst", no_argument, NULL, OPTION_SECTNAME_SUBST}
+#endif
+ ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
+ ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
+ /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
+ so we keep it here for backwards compatibility. */
+ ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
+ ,{"gdwarf-sections", no_argument, NULL, OPTION_GDWARF_SECTIONS}
+ ,{"gen-debug", no_argument, NULL, 'g'}
+ ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
+ ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
+ ,{"hash-size", required_argument, NULL, OPTION_HASH_TABLE_SIZE}
+ ,{"help", no_argument, NULL, OPTION_HELP}
+#ifdef HAVE_ITBL_CPU
+ /* New option for extending instruction set (see also -t above).
+ The "-t file" or "--itbl file" option extends the basic set of
+ valid instructions by reading "file", a text file containing a
+ list of instruction formats. The additional opcodes and their
+ formats are added to the built-in set of instructions, and
+ mnemonics for new registers may also be defined. */
+ ,{"itbl", required_argument, NULL, 't'}
+#endif
+ /* getopt allows abbreviations, so we do this to stop it from
+ treating -k as an abbreviation for --keep-locals. Some
+ ports use -k to enable PIC assembly. */
+ ,{"keep-locals", no_argument, NULL, 'L'}
+ ,{"keep-locals", no_argument, NULL, 'L'}
+ ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
+ ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
+ ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
+ ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
+ ,{"MD", required_argument, NULL, OPTION_DEPFILE}
+ ,{"mri", no_argument, NULL, 'M'}
+ ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
+ ,{"no-warn", no_argument, NULL, 'W'}
+ ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
+ ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
+ ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
+ ,{"version", no_argument, NULL, OPTION_VERSION}
+ ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
+ ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
+ ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
+ ,{"warn", no_argument, NULL, OPTION_WARN}
+ };
+
+ /* Construct the option lists from the standard list and the target
+ dependent list. Include space for an extra NULL option and
+ always NULL terminate. */
+ shortopts = concat (std_shortopts, md_shortopts, (char *) NULL);
+ longopts = (struct option *) xmalloc (sizeof (std_longopts)
+ + md_longopts_size + sizeof (struct option));
+ memcpy (longopts, std_longopts, sizeof (std_longopts));
+ memcpy (((char *) longopts) + sizeof (std_longopts), md_longopts, md_longopts_size);
+ memset (((char *) longopts) + sizeof (std_longopts) + md_longopts_size,
+ 0, sizeof (struct option));
+
+ /* Make a local copy of the old argv. */
+ old_argc = *pargc;
+ old_argv = *pargv;
+
+ /* Initialize a new argv that contains no options. */
+ new_argv = XNEWVEC (char *, old_argc + 1);
+ new_argv[0] = old_argv[0];
+ new_argc = 1;
+ new_argv[new_argc] = NULL;
+
+ while (1)
+ {
+ /* getopt_long_only is like getopt_long, but '-' as well as '--' can
+ indicate a long option. */
+ int longind;
+ int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts,
+ &longind);