Subversion Repositories Kolibri OS

Rev

Rev 5222 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* as.c - GAS main program.
  2.    Copyright (C) 1987-2015 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GAS, the GNU Assembler.
  5.  
  6.    GAS is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 3, or (at your option)
  9.    any later version.
  10.  
  11.    GAS is distributed in the hope that it will be useful, but WITHOUT
  12.    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  13.    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
  14.    License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GAS; see the file COPYING.  If not, write to the Free
  18.    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
  19.    02110-1301, USA.  */
  20.  
  21. /* Main program for AS; a 32-bit assembler of GNU.
  22.    Understands command arguments.
  23.    Has a few routines that don't fit in other modules because they
  24.    are shared.
  25.  
  26.                         bugs
  27.  
  28.    : initialisers
  29.         Since no-one else says they will support them in future: I
  30.    don't support them now.  */
  31.  
  32. #define COMMON
  33.  
  34. #include "as.h"
  35. #include "subsegs.h"
  36. #include "output-file.h"
  37. #include "sb.h"
  38. #include "macro.h"
  39. #include "dwarf2dbg.h"
  40. #include "dw2gencfi.h"
  41. #include "bfdver.h"
  42.  
  43. #ifdef HAVE_ITBL_CPU
  44. #include "itbl-ops.h"
  45. #else
  46. #define itbl_init()
  47. #endif
  48.  
  49. #ifdef HAVE_SBRK
  50. #ifdef NEED_DECLARATION_SBRK
  51. extern void *sbrk ();
  52. #endif
  53. #endif
  54.  
  55. #ifdef USING_CGEN
  56. /* Perform any cgen specific initialisation for gas.  */
  57. extern void gas_cgen_begin (void);
  58. #endif
  59.  
  60. /* We build a list of defsyms as we read the options, and then define
  61.    them after we have initialized everything.  */
  62. struct defsym_list
  63. {
  64.   struct defsym_list *next;
  65.   char *name;
  66.   valueT value;
  67. };
  68.  
  69.  
  70. /* True if a listing is wanted.  */
  71. int listing;
  72.  
  73. /* Type of debugging to generate.  */
  74. enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
  75. int use_gnu_debug_info_extensions = 0;
  76.  
  77. #ifndef MD_DEBUG_FORMAT_SELECTOR
  78. #define MD_DEBUG_FORMAT_SELECTOR NULL
  79. #endif
  80. static enum debug_info_type (*md_debug_format_selector) (int *) = MD_DEBUG_FORMAT_SELECTOR;
  81.  
  82. /* Maximum level of macro nesting.  */
  83. int max_macro_nest = 100;
  84.  
  85. /* argv[0]  */
  86. static char * myname;
  87.  
  88. /* The default obstack chunk size.  If we set this to zero, the
  89.    obstack code will use whatever will fit in a 4096 byte block.  */
  90. int chunksize = 0;
  91.  
  92. /* To monitor memory allocation more effectively, make this non-zero.
  93.    Then the chunk sizes for gas and bfd will be reduced.  */
  94. int debug_memory = 0;
  95.  
  96. /* Enable verbose mode.  */
  97. int verbose = 0;
  98.  
  99. /* Keep the output file.  */
  100. static int keep_it = 0;
  101.  
  102. segT reg_section;
  103. segT expr_section;
  104. segT text_section;
  105. segT data_section;
  106. segT bss_section;
  107.  
  108. /* Name of listing file.  */
  109. static char *listing_filename = NULL;
  110.  
  111. static struct defsym_list *defsyms;
  112.  
  113. #ifdef HAVE_ITBL_CPU
  114. /* Keep a record of the itbl files we read in.  */
  115. struct itbl_file_list
  116. {
  117.   struct itbl_file_list *next;
  118.   char *name;
  119. };
  120. static struct itbl_file_list *itbl_files;
  121. #endif
  122.  
  123. static long start_time;
  124. #ifdef HAVE_SBRK
  125. char *start_sbrk;
  126. #endif
  127.  
  128. static int flag_macro_alternate;
  129.  
  130. #ifdef USE_EMULATIONS
  131. #define EMULATION_ENVIRON "AS_EMULATION"
  132.  
  133. extern struct emulation mipsbelf, mipslelf, mipself;
  134. extern struct emulation i386coff, i386elf, i386aout;
  135. extern struct emulation crisaout, criself;
  136.  
  137. static struct emulation *const emulations[] = { EMULATIONS };
  138. static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]);
  139.  
  140. static void
  141. select_emulation_mode (int argc, char **argv)
  142. {
  143.   int i;
  144.   char *p, *em = 0;
  145.  
  146.   for (i = 1; i < argc; i++)
  147.     if (!strncmp ("--em", argv[i], 4))
  148.       break;
  149.  
  150.   if (i == argc)
  151.     goto do_default;
  152.  
  153.   p = strchr (argv[i], '=');
  154.   if (p)
  155.     p++;
  156.   else
  157.     p = argv[i + 1];
  158.  
  159.   if (!p || !*p)
  160.     as_fatal (_("missing emulation mode name"));
  161.   em = p;
  162.  
  163.  do_default:
  164.   if (em == 0)
  165.     em = getenv (EMULATION_ENVIRON);
  166.   if (em == 0)
  167.     em = DEFAULT_EMULATION;
  168.  
  169.   if (em)
  170.     {
  171.       for (i = 0; i < n_emulations; i++)
  172.         if (!strcmp (emulations[i]->name, em))
  173.           break;
  174.       if (i == n_emulations)
  175.         as_fatal (_("unrecognized emulation name `%s'"), em);
  176.       this_emulation = emulations[i];
  177.     }
  178.   else
  179.     this_emulation = emulations[0];
  180.  
  181.   this_emulation->init ();
  182. }
  183.  
  184. const char *
  185. default_emul_bfd_name (void)
  186. {
  187.   abort ();
  188.   return NULL;
  189. }
  190.  
  191. void
  192. common_emul_init (void)
  193. {
  194.   this_format = this_emulation->format;
  195.  
  196.   if (this_emulation->leading_underscore == 2)
  197.     this_emulation->leading_underscore = this_format->dfl_leading_underscore;
  198.  
  199.   if (this_emulation->default_endian != 2)
  200.     target_big_endian = this_emulation->default_endian;
  201.  
  202.   if (this_emulation->fake_label_name == 0)
  203.     {
  204.       if (this_emulation->leading_underscore)
  205.         this_emulation->fake_label_name = "L0\001";
  206.       else
  207.         /* What other parameters should we test?  */
  208.         this_emulation->fake_label_name = ".L0\001";
  209.     }
  210. }
  211. #endif
  212.  
  213. void
  214. print_version_id (void)
  215. {
  216.   static int printed;
  217.  
  218.   if (printed)
  219.     return;
  220.   printed = 1;
  221.  
  222.   fprintf (stderr, _("GNU assembler version %s (%s) using BFD version %s\n"),
  223.            VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
  224. }
  225.  
  226. #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
  227. enum compressed_debug_section_type flag_compress_debug
  228.   = COMPRESS_DEBUG_GABI_ZLIB;
  229. #endif
  230.  
  231. static void
  232. show_usage (FILE * stream)
  233. {
  234.   fprintf (stream, _("Usage: %s [option...] [asmfile...]\n"), myname);
  235.  
  236.   fprintf (stream, _("\
  237. Options:\n\
  238.   -a[sub-option...]       turn on listings\n\
  239.                           Sub-options [default hls]:\n\
  240.                           c      omit false conditionals\n\
  241.                           d      omit debugging directives\n\
  242.                           g      include general info\n\
  243.                           h      include high-level source\n\
  244.                           l      include assembly\n\
  245.                           m      include macro expansions\n\
  246.                           n      omit forms processing\n\
  247.                           s      include symbols\n\
  248.                           =FILE  list to FILE (must be last sub-option)\n"));
  249.  
  250.   fprintf (stream, _("\
  251.  --alternate             initially turn on alternate macro syntax\n"));
  252. #ifdef DEFAULT_FLAG_COMPRESS_DEBUG
  253.   fprintf (stream, _("\
  254.  --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]\n\
  255.                          compress DWARF debug sections using zlib [default]\n"));
  256.   fprintf (stream, _("\
  257.  --nocompress-debug-sections\n\
  258.                          don't compress DWARF debug sections\n"));
  259. #else
  260.   fprintf (stream, _("\
  261.  --compress-debug-sections[={none|zlib|zlib-gnu|zlib-gabi}]\n\
  262.                          compress DWARF debug sections using zlib\n"));
  263.   fprintf (stream, _("\
  264.  --nocompress-debug-sections\n\
  265.                          don't compress DWARF debug sections [default]\n"));
  266. #endif
  267.   fprintf (stream, _("\
  268.  -D                      produce assembler debugging messages\n"));
  269.   fprintf (stream, _("\
  270.  --debug-prefix-map OLD=NEW\n\
  271.                          map OLD to NEW in debug information\n"));
  272.   fprintf (stream, _("\
  273.  --defsym SYM=VAL        define symbol SYM to given value\n"));
  274. #ifdef USE_EMULATIONS
  275.   {
  276.     int i;
  277.     char *def_em;
  278.  
  279.     fprintf (stream, "\
  280.  --em=[");
  281.     for (i = 0; i < n_emulations - 1; i++)
  282.       fprintf (stream, "%s | ", emulations[i]->name);
  283.     fprintf (stream, "%s]\n", emulations[i]->name);
  284.  
  285.     def_em = getenv (EMULATION_ENVIRON);
  286.     if (!def_em)
  287.       def_em = DEFAULT_EMULATION;
  288.     fprintf (stream, _("\
  289.                          emulate output (default %s)\n"), def_em);
  290.   }
  291. #endif
  292. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  293.   fprintf (stream, _("\
  294.  --execstack             require executable stack for this object\n"));
  295.   fprintf (stream, _("\
  296.  --noexecstack           don't require executable stack for this object\n"));
  297.   fprintf (stream, _("\
  298.  --size-check=[error|warning]\n\
  299.                           ELF .size directive check (default --size-check=error)\n"));
  300.   fprintf (stream, _("\
  301.  --sectname-subst        enable section name substitution sequences\n"));
  302. #endif
  303.   fprintf (stream, _("\
  304.  -f                      skip whitespace and comment preprocessing\n"));
  305.   fprintf (stream, _("\
  306.  -g --gen-debug          generate debugging information\n"));
  307.   fprintf (stream, _("\
  308.  --gstabs                generate STABS debugging information\n"));
  309.   fprintf (stream, _("\
  310.  --gstabs+               generate STABS debug info with GNU extensions\n"));
  311.   fprintf (stream, _("\
  312.  --gdwarf-2              generate DWARF2 debugging information\n"));
  313.   fprintf (stream, _("\
  314.  --gdwarf-sections       generate per-function section names for DWARF line information\n"));
  315.   fprintf (stream, _("\
  316.  --hash-size=<value>     set the hash table size close to <value>\n"));
  317.   fprintf (stream, _("\
  318.  --help                  show this message and exit\n"));
  319.   fprintf (stream, _("\
  320.  --target-help           show target specific options\n"));
  321.   fprintf (stream, _("\
  322.  -I DIR                  add DIR to search list for .include directives\n"));
  323.   fprintf (stream, _("\
  324.  -J                      don't warn about signed overflow\n"));
  325.   fprintf (stream, _("\
  326.  -K                      warn when differences altered for long displacements\n"));
  327.   fprintf (stream, _("\
  328.  -L,--keep-locals        keep local symbols (e.g. starting with `L')\n"));
  329.   fprintf (stream, _("\
  330.  -M,--mri                assemble in MRI compatibility mode\n"));
  331.   fprintf (stream, _("\
  332.  --MD FILE               write dependency information in FILE (default none)\n"));
  333.   fprintf (stream, _("\
  334.  -nocpp                  ignored\n"));
  335.   fprintf (stream, _("\
  336.  -o OBJFILE              name the object-file output OBJFILE (default a.out)\n"));
  337.   fprintf (stream, _("\
  338.  -R                      fold data section into text section\n"));
  339.   fprintf (stream, _("\
  340.  --reduce-memory-overheads \n\
  341.                          prefer smaller memory use at the cost of longer\n\
  342.                          assembly times\n"));
  343.   fprintf (stream, _("\
  344.  --statistics            print various measured statistics from execution\n"));
  345.   fprintf (stream, _("\
  346.  --strip-local-absolute  strip local absolute symbols\n"));
  347.   fprintf (stream, _("\
  348.  --traditional-format    Use same format as native assembler when possible\n"));
  349.   fprintf (stream, _("\
  350.  --version               print assembler version number and exit\n"));
  351.   fprintf (stream, _("\
  352.  -W  --no-warn           suppress warnings\n"));
  353.   fprintf (stream, _("\
  354.  --warn                  don't suppress warnings\n"));
  355.   fprintf (stream, _("\
  356.  --fatal-warnings        treat warnings as errors\n"));
  357. #ifdef HAVE_ITBL_CPU
  358.   fprintf (stream, _("\
  359.  --itbl INSTTBL          extend instruction set to include instructions\n\
  360.                          matching the specifications defined in file INSTTBL\n"));
  361. #endif
  362.   fprintf (stream, _("\
  363.  -w                      ignored\n"));
  364.   fprintf (stream, _("\
  365.  -X                      ignored\n"));
  366.   fprintf (stream, _("\
  367.  -Z                      generate object file even after errors\n"));
  368.   fprintf (stream, _("\
  369.  --listing-lhs-width     set the width in words of the output data column of\n\
  370.                          the listing\n"));
  371.   fprintf (stream, _("\
  372.  --listing-lhs-width2    set the width in words of the continuation lines\n\
  373.                          of the output data column; ignored if smaller than\n\
  374.                          the width of the first line\n"));
  375.   fprintf (stream, _("\
  376.  --listing-rhs-width     set the max width in characters of the lines from\n\
  377.                          the source file\n"));
  378.   fprintf (stream, _("\
  379.  --listing-cont-lines    set the maximum number of continuation lines used\n\
  380.                          for the output data column of the listing\n"));
  381.   fprintf (stream, _("\
  382.  @FILE                   read options from FILE\n"));
  383.  
  384.   md_show_usage (stream);
  385.  
  386.   fputc ('\n', stream);
  387.  
  388.   if (REPORT_BUGS_TO[0] && stream == stdout)
  389.     fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
  390. }
  391.  
  392. /* Since it is easy to do here we interpret the special arg "-"
  393.    to mean "use stdin" and we set that argv[] pointing to "".
  394.    After we have munged argv[], the only things left are source file
  395.    name(s) and ""(s) denoting stdin. These file names are used
  396.    (perhaps more than once) later.
  397.  
  398.    check for new machine-dep cmdline options in
  399.    md_parse_option definitions in config/tc-*.c.  */
  400.  
  401. static void
  402. parse_args (int * pargc, char *** pargv)
  403. {
  404.   int old_argc;
  405.   int new_argc;
  406.   char ** old_argv;
  407.   char ** new_argv;
  408.   /* Starting the short option string with '-' is for programs that
  409.      expect options and other ARGV-elements in any order and that care about
  410.      the ordering of the two.  We describe each non-option ARGV-element
  411.      as if it were the argument of an option with character code 1.  */
  412.   char *shortopts;
  413.   extern const char *md_shortopts;
  414.   static const char std_shortopts[] =
  415.   {
  416.     '-', 'J',
  417. #ifndef WORKING_DOT_WORD
  418.     /* -K is not meaningful if .word is not being hacked.  */
  419.     'K',
  420. #endif
  421.     'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', ':',':', 'I', ':', 'o', ':',
  422. #ifndef VMS
  423.     /* -v takes an argument on VMS, so we don't make it a generic
  424.        option.  */
  425.     'v',
  426. #endif
  427.     'w', 'X',
  428. #ifdef HAVE_ITBL_CPU
  429.     /* New option for extending instruction set (see also --itbl below).  */
  430.     't', ':',
  431. #endif
  432.     '\0'
  433.   };
  434.   struct option *longopts;
  435.   extern struct option md_longopts[];
  436.   extern size_t md_longopts_size;
  437.   /* Codes used for the long options with no short synonyms.  */
  438.   enum option_values
  439.     {
  440.       OPTION_HELP = OPTION_STD_BASE,
  441.       OPTION_NOCPP,
  442.       OPTION_STATISTICS,
  443.       OPTION_VERSION,
  444.       OPTION_DUMPCONFIG,
  445.       OPTION_VERBOSE,
  446.       OPTION_EMULATION,
  447.       OPTION_DEBUG_PREFIX_MAP,
  448.       OPTION_DEFSYM,
  449.       OPTION_LISTING_LHS_WIDTH,
  450.       OPTION_LISTING_LHS_WIDTH2,
  451.       OPTION_LISTING_RHS_WIDTH,
  452.       OPTION_LISTING_CONT_LINES,
  453.       OPTION_DEPFILE,
  454.       OPTION_GSTABS,
  455.       OPTION_GSTABS_PLUS,
  456.       OPTION_GDWARF2,
  457.       OPTION_GDWARF_SECTIONS,
  458.       OPTION_STRIP_LOCAL_ABSOLUTE,
  459.       OPTION_TRADITIONAL_FORMAT,
  460.       OPTION_WARN,
  461.       OPTION_TARGET_HELP,
  462.       OPTION_EXECSTACK,
  463.       OPTION_NOEXECSTACK,
  464.       OPTION_SIZE_CHECK,
  465.       OPTION_SECTNAME_SUBST,
  466.       OPTION_ALTERNATE,
  467.       OPTION_AL,
  468.       OPTION_HASH_TABLE_SIZE,
  469.       OPTION_REDUCE_MEMORY_OVERHEADS,
  470.       OPTION_WARN_FATAL,
  471.       OPTION_COMPRESS_DEBUG,
  472.       OPTION_NOCOMPRESS_DEBUG
  473.     /* When you add options here, check that they do
  474.        not collide with OPTION_MD_BASE.  See as.h.  */
  475.     };
  476.  
  477.   static const struct option std_longopts[] =
  478.   {
  479.     /* Note: commas are placed at the start of the line rather than
  480.        the end of the preceding line so that it is simpler to
  481.        selectively add and remove lines from this list.  */
  482.     {"alternate", no_argument, NULL, OPTION_ALTERNATE}
  483.     /* The entry for "a" is here to prevent getopt_long_only() from
  484.        considering that -a is an abbreviation for --alternate.  This is
  485.        necessary because -a=<FILE> is a valid switch but getopt would
  486.        normally reject it since --alternate does not take an argument.  */
  487.     ,{"a", optional_argument, NULL, 'a'}
  488.     /* Handle -al=<FILE>.  */
  489.     ,{"al", optional_argument, NULL, OPTION_AL}
  490.     ,{"compress-debug-sections", optional_argument, NULL, OPTION_COMPRESS_DEBUG}
  491.     ,{"nocompress-debug-sections", no_argument, NULL, OPTION_NOCOMPRESS_DEBUG}
  492.     ,{"debug-prefix-map", required_argument, NULL, OPTION_DEBUG_PREFIX_MAP}
  493.     ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
  494.     ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
  495.     ,{"emulation", required_argument, NULL, OPTION_EMULATION}
  496. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  497.     ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
  498.     ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
  499.     ,{"size-check", required_argument, NULL, OPTION_SIZE_CHECK}
  500.     ,{"sectname-subst", no_argument, NULL, OPTION_SECTNAME_SUBST}
  501. #endif
  502.     ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
  503.     ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
  504.     /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
  505.        so we keep it here for backwards compatibility.  */
  506.     ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
  507.     ,{"gdwarf-sections", no_argument, NULL, OPTION_GDWARF_SECTIONS}
  508.     ,{"gen-debug", no_argument, NULL, 'g'}
  509.     ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
  510.     ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
  511.     ,{"hash-size", required_argument, NULL, OPTION_HASH_TABLE_SIZE}
  512.     ,{"help", no_argument, NULL, OPTION_HELP}
  513. #ifdef HAVE_ITBL_CPU
  514.     /* New option for extending instruction set (see also -t above).
  515.        The "-t file" or "--itbl file" option extends the basic set of
  516.        valid instructions by reading "file", a text file containing a
  517.        list of instruction formats.  The additional opcodes and their
  518.        formats are added to the built-in set of instructions, and
  519.        mnemonics for new registers may also be defined.  */
  520.     ,{"itbl", required_argument, NULL, 't'}
  521. #endif
  522.     /* getopt allows abbreviations, so we do this to stop it from
  523.        treating -k as an abbreviation for --keep-locals.  Some
  524.        ports use -k to enable PIC assembly.  */
  525.     ,{"keep-locals", no_argument, NULL, 'L'}
  526.     ,{"keep-locals", no_argument, NULL, 'L'}
  527.     ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
  528.     ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
  529.     ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
  530.     ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
  531.     ,{"MD", required_argument, NULL, OPTION_DEPFILE}
  532.     ,{"mri", no_argument, NULL, 'M'}
  533.     ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
  534.     ,{"no-warn", no_argument, NULL, 'W'}
  535.     ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
  536.     ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
  537.     ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
  538.     ,{"version", no_argument, NULL, OPTION_VERSION}
  539.     ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
  540.     ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
  541.     ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
  542.     ,{"warn", no_argument, NULL, OPTION_WARN}
  543.   };
  544.  
  545.   /* Construct the option lists from the standard list and the target
  546.      dependent list.  Include space for an extra NULL option and
  547.      always NULL terminate.  */
  548.   shortopts = concat (std_shortopts, md_shortopts, (char *) NULL);
  549.   longopts = (struct option *) xmalloc (sizeof (std_longopts)
  550.                                         + md_longopts_size + sizeof (struct option));
  551.   memcpy (longopts, std_longopts, sizeof (std_longopts));
  552.   memcpy (((char *) longopts) + sizeof (std_longopts), md_longopts, md_longopts_size);
  553.   memset (((char *) longopts) + sizeof (std_longopts) + md_longopts_size,
  554.           0, sizeof (struct option));
  555.  
  556.   /* Make a local copy of the old argv.  */
  557.   old_argc = *pargc;
  558.   old_argv = *pargv;
  559.  
  560.   /* Initialize a new argv that contains no options.  */
  561.   new_argv = (char **) xmalloc (sizeof (char *) * (old_argc + 1));
  562.   new_argv[0] = old_argv[0];
  563.   new_argc = 1;
  564.   new_argv[new_argc] = NULL;
  565.  
  566.   while (1)
  567.     {
  568.       /* getopt_long_only is like getopt_long, but '-' as well as '--' can
  569.          indicate a long option.  */
  570.       int longind;
  571.       int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts,
  572.                                    &longind);
  573.  
  574.       if (optc == -1)
  575.         break;
  576.  
  577.       switch (optc)
  578.         {
  579.         default:
  580.           /* md_parse_option should return 1 if it recognizes optc,
  581.              0 if not.  */
  582.           if (md_parse_option (optc, optarg) != 0)
  583.             break;
  584.           /* `-v' isn't included in the general short_opts list, so check for
  585.              it explicitly here before deciding we've gotten a bad argument.  */
  586.           if (optc == 'v')
  587.             {
  588. #ifdef VMS
  589.               /* Telling getopt to treat -v's value as optional can result
  590.                  in it picking up a following filename argument here.  The
  591.                  VMS code in md_parse_option can return 0 in that case,
  592.                  but it has no way of pushing the filename argument back.  */
  593.               if (optarg && *optarg)
  594.                 new_argv[new_argc++] = optarg, new_argv[new_argc] = NULL;
  595.               else
  596. #else
  597.               case 'v':
  598. #endif
  599.               case OPTION_VERBOSE:
  600.                 print_version_id ();
  601.                 verbose = 1;
  602.               break;
  603.             }
  604.           else
  605.             as_bad (_("unrecognized option -%c%s"), optc, optarg ? optarg : "");
  606.           /* Fall through.  */
  607.  
  608.         case '?':
  609.           exit (EXIT_FAILURE);
  610.  
  611.         case 1:                 /* File name.  */
  612.           if (!strcmp (optarg, "-"))
  613.             optarg = "";
  614.           new_argv[new_argc++] = optarg;
  615.           new_argv[new_argc] = NULL;
  616.           break;
  617.  
  618.         case OPTION_TARGET_HELP:
  619.           md_show_usage (stdout);
  620.           exit (EXIT_SUCCESS);
  621.  
  622.         case OPTION_HELP:
  623.           show_usage (stdout);
  624.           exit (EXIT_SUCCESS);
  625.  
  626.         case OPTION_NOCPP:
  627.           break;
  628.  
  629.         case OPTION_STATISTICS:
  630.           flag_print_statistics = 1;
  631.           break;
  632.  
  633.         case OPTION_STRIP_LOCAL_ABSOLUTE:
  634.           flag_strip_local_absolute = 1;
  635.           break;
  636.  
  637.         case OPTION_TRADITIONAL_FORMAT:
  638.           flag_traditional_format = 1;
  639.           break;
  640.  
  641.         case OPTION_VERSION:
  642.           /* This output is intended to follow the GNU standards document.  */
  643.           printf (_("GNU assembler %s\n"), BFD_VERSION_STRING);
  644.           printf (_("Copyright (C) 2015 Free Software Foundation, Inc.\n"));
  645.           printf (_("\
  646. This program is free software; you may redistribute it under the terms of\n\
  647. the GNU General Public License version 3 or later.\n\
  648. This program has absolutely no warranty.\n"));
  649.           printf (_("This assembler was configured for a target of `%s'.\n"),
  650.                   TARGET_ALIAS);
  651.           exit (EXIT_SUCCESS);
  652.  
  653.         case OPTION_EMULATION:
  654. #ifdef USE_EMULATIONS
  655.           if (strcmp (optarg, this_emulation->name))
  656.             as_fatal (_("multiple emulation names specified"));
  657. #else
  658.           as_fatal (_("emulations not handled in this configuration"));
  659. #endif
  660.           break;
  661.  
  662.         case OPTION_DUMPCONFIG:
  663.           fprintf (stderr, _("alias = %s\n"), TARGET_ALIAS);
  664.           fprintf (stderr, _("canonical = %s\n"), TARGET_CANONICAL);
  665.           fprintf (stderr, _("cpu-type = %s\n"), TARGET_CPU);
  666. #ifdef TARGET_OBJ_FORMAT
  667.           fprintf (stderr, _("format = %s\n"), TARGET_OBJ_FORMAT);
  668. #endif
  669. #ifdef TARGET_FORMAT
  670.           fprintf (stderr, _("bfd-target = %s\n"), TARGET_FORMAT);
  671. #endif
  672.           exit (EXIT_SUCCESS);
  673.  
  674.         case OPTION_COMPRESS_DEBUG:
  675.           if (optarg)
  676.             {
  677. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  678.               if (strcasecmp (optarg, "none") == 0)
  679.                 flag_compress_debug = COMPRESS_DEBUG_NONE;
  680.               else if (strcasecmp (optarg, "zlib") == 0)
  681.                 flag_compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
  682.               else if (strcasecmp (optarg, "zlib-gnu") == 0)
  683.                 flag_compress_debug = COMPRESS_DEBUG_GNU_ZLIB;
  684.               else if (strcasecmp (optarg, "zlib-gabi") == 0)
  685.                 flag_compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
  686.               else
  687.                 as_fatal (_("Invalid --compress-debug-sections option: `%s'"),
  688.                           optarg);
  689. #else
  690.               as_fatal (_("--compress-debug-sections=%s is unsupported"),
  691.                         optarg);
  692. #endif
  693.             }
  694.           else
  695.             flag_compress_debug = COMPRESS_DEBUG_GABI_ZLIB;
  696.           break;
  697.  
  698.         case OPTION_NOCOMPRESS_DEBUG:
  699.           flag_compress_debug = COMPRESS_DEBUG_NONE;
  700.           break;
  701.  
  702.         case OPTION_DEBUG_PREFIX_MAP:
  703.           add_debug_prefix_map (optarg);
  704.           break;
  705.  
  706.         case OPTION_DEFSYM:
  707.           {
  708.             char *s;
  709.             valueT i;
  710.             struct defsym_list *n;
  711.  
  712.             for (s = optarg; *s != '\0' && *s != '='; s++)
  713.               ;
  714.             if (*s == '\0')
  715.               as_fatal (_("bad defsym; format is --defsym name=value"));
  716.             *s++ = '\0';
  717.             i = bfd_scan_vma (s, (const char **) NULL, 0);
  718.             n = (struct defsym_list *) xmalloc (sizeof *n);
  719.             n->next = defsyms;
  720.             n->name = optarg;
  721.             n->value = i;
  722.             defsyms = n;
  723.           }
  724.           break;
  725.  
  726. #ifdef HAVE_ITBL_CPU
  727.         case 't':
  728.           {
  729.             /* optarg is the name of the file containing the instruction
  730.                formats, opcodes, register names, etc.  */
  731.             struct itbl_file_list *n;
  732.  
  733.             if (optarg == NULL)
  734.               {
  735.                 as_warn (_("no file name following -t option"));
  736.                 break;
  737.               }
  738.  
  739.             n = xmalloc (sizeof * n);
  740.             n->next = itbl_files;
  741.             n->name = optarg;
  742.             itbl_files = n;
  743.  
  744.             /* Parse the file and add the new instructions to our internal
  745.                table.  If multiple instruction tables are specified, the
  746.                information from this table gets appended onto the existing
  747.                internal table.  */
  748.             itbl_files->name = xstrdup (optarg);
  749.             if (itbl_parse (itbl_files->name) != 0)
  750.               as_fatal (_("failed to read instruction table %s\n"),
  751.                         itbl_files->name);
  752.           }
  753.           break;
  754. #endif
  755.  
  756.         case OPTION_DEPFILE:
  757.           start_dependencies (optarg);
  758.           break;
  759.  
  760.         case 'g':
  761.           /* Some backends, eg Alpha and Mips, use the -g switch for their
  762.              own purposes.  So we check here for an explicit -g and allow
  763.              the backend to decide if it wants to process it.  */
  764.           if (   old_argv[optind - 1][1] == 'g'
  765.               && md_parse_option (optc, optarg))
  766.             continue;
  767.  
  768.           if (md_debug_format_selector)
  769.             debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
  770.           else if (IS_ELF)
  771.             debug_type = DEBUG_DWARF2;
  772.           else
  773.             debug_type = DEBUG_STABS;
  774.           break;
  775.  
  776.         case OPTION_GSTABS_PLUS:
  777.           use_gnu_debug_info_extensions = 1;
  778.           /* Fall through.  */
  779.         case OPTION_GSTABS:
  780.           debug_type = DEBUG_STABS;
  781.           break;
  782.  
  783.         case OPTION_GDWARF2:
  784.           debug_type = DEBUG_DWARF2;
  785.           break;
  786.  
  787.         case OPTION_GDWARF_SECTIONS:
  788.           flag_dwarf_sections = TRUE;
  789.           break;
  790.  
  791.         case 'J':
  792.           flag_signed_overflow_ok = 1;
  793.           break;
  794.  
  795. #ifndef WORKING_DOT_WORD
  796.         case 'K':
  797.           flag_warn_displacement = 1;
  798.           break;
  799. #endif
  800.         case 'L':
  801.           flag_keep_locals = 1;
  802.           break;
  803.  
  804.         case OPTION_LISTING_LHS_WIDTH:
  805.           listing_lhs_width = atoi (optarg);
  806.           if (listing_lhs_width_second < listing_lhs_width)
  807.             listing_lhs_width_second = listing_lhs_width;
  808.           break;
  809.         case OPTION_LISTING_LHS_WIDTH2:
  810.           {
  811.             int tmp = atoi (optarg);
  812.  
  813.             if (tmp > listing_lhs_width)
  814.               listing_lhs_width_second = tmp;
  815.           }
  816.           break;
  817.         case OPTION_LISTING_RHS_WIDTH:
  818.           listing_rhs_width = atoi (optarg);
  819.           break;
  820.         case OPTION_LISTING_CONT_LINES:
  821.           listing_lhs_cont_lines = atoi (optarg);
  822.           break;
  823.  
  824.         case 'M':
  825.           flag_mri = 1;
  826. #ifdef TC_M68K
  827.           flag_m68k_mri = 1;
  828. #endif
  829.           break;
  830.  
  831.         case 'R':
  832.           flag_readonly_data_in_text = 1;
  833.           break;
  834.  
  835.         case 'W':
  836.           flag_no_warnings = 1;
  837.           break;
  838.  
  839.         case OPTION_WARN:
  840.           flag_no_warnings = 0;
  841.           flag_fatal_warnings = 0;
  842.           break;
  843.  
  844.         case OPTION_WARN_FATAL:
  845.           flag_no_warnings = 0;
  846.           flag_fatal_warnings = 1;
  847.           break;
  848.  
  849. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  850.         case OPTION_EXECSTACK:
  851.           flag_execstack = 1;
  852.           flag_noexecstack = 0;
  853.           break;
  854.  
  855.         case OPTION_NOEXECSTACK:
  856.           flag_noexecstack = 1;
  857.           flag_execstack = 0;
  858.           break;
  859.  
  860.         case OPTION_SIZE_CHECK:
  861.           if (strcasecmp (optarg, "error") == 0)
  862.             flag_size_check = size_check_error;
  863.           else if (strcasecmp (optarg, "warning") == 0)
  864.             flag_size_check = size_check_warning;
  865.           else
  866.             as_fatal (_("Invalid --size-check= option: `%s'"), optarg);
  867.           break;
  868.  
  869.         case OPTION_SECTNAME_SUBST:
  870.           flag_sectname_subst = 1;
  871.           break;
  872. #endif
  873.         case 'Z':
  874.           flag_always_generate_output = 1;
  875.           break;
  876.  
  877.         case OPTION_AL:
  878.           listing |= LISTING_LISTING;
  879.           if (optarg)
  880.             listing_filename = xstrdup (optarg);
  881.           break;
  882.  
  883.         case OPTION_ALTERNATE:
  884.           optarg = old_argv [optind - 1];
  885.           while (* optarg == '-')
  886.             optarg ++;
  887.  
  888.           if (strcmp (optarg, "alternate") == 0)
  889.             {
  890.               flag_macro_alternate = 1;
  891.               break;
  892.             }
  893.           optarg ++;
  894.           /* Fall through.  */
  895.  
  896.         case 'a':
  897.           if (optarg)
  898.             {
  899.               if (optarg != old_argv[optind] && optarg[-1] == '=')
  900.                 --optarg;
  901.  
  902.               if (md_parse_option (optc, optarg) != 0)
  903.                 break;
  904.  
  905.               while (*optarg)
  906.                 {
  907.                   switch (*optarg)
  908.                     {
  909.                     case 'c':
  910.                       listing |= LISTING_NOCOND;
  911.                       break;
  912.                     case 'd':
  913.                       listing |= LISTING_NODEBUG;
  914.                       break;
  915.                     case 'g':
  916.                       listing |= LISTING_GENERAL;
  917.                       break;
  918.                     case 'h':
  919.                       listing |= LISTING_HLL;
  920.                       break;
  921.                     case 'l':
  922.                       listing |= LISTING_LISTING;
  923.                       break;
  924.                     case 'm':
  925.                       listing |= LISTING_MACEXP;
  926.                       break;
  927.                     case 'n':
  928.                       listing |= LISTING_NOFORM;
  929.                       break;
  930.                     case 's':
  931.                       listing |= LISTING_SYMBOLS;
  932.                       break;
  933.                     case '=':
  934.                       listing_filename = xstrdup (optarg + 1);
  935.                       optarg += strlen (listing_filename);
  936.                       break;
  937.                     default:
  938.                       as_fatal (_("invalid listing option `%c'"), *optarg);
  939.                       break;
  940.                     }
  941.                   optarg++;
  942.                 }
  943.             }
  944.           if (!listing)
  945.             listing = LISTING_DEFAULT;
  946.           break;
  947.  
  948.         case 'D':
  949.           /* DEBUG is implemented: it debugs different
  950.              things from other people's assemblers.  */
  951.           flag_debug = 1;
  952.           break;
  953.  
  954.         case 'f':
  955.           flag_no_comments = 1;
  956.           break;
  957.  
  958.         case 'I':
  959.           {                     /* Include file directory.  */
  960.             char *temp = xstrdup (optarg);
  961.  
  962.             add_include_dir (temp);
  963.             break;
  964.           }
  965.  
  966.         case 'o':
  967.           out_file_name = xstrdup (optarg);
  968.           break;
  969.  
  970.         case 'w':
  971.           break;
  972.  
  973.         case 'X':
  974.           /* -X means treat warnings as errors.  */
  975.           break;
  976.  
  977.         case OPTION_REDUCE_MEMORY_OVERHEADS:
  978.           /* The only change we make at the moment is to reduce
  979.              the size of the hash tables that we use.  */
  980.           set_gas_hash_table_size (4051);
  981.           break;
  982.  
  983.         case OPTION_HASH_TABLE_SIZE:
  984.           {
  985.             unsigned long new_size;
  986.  
  987.             new_size = strtoul (optarg, NULL, 0);
  988.             if (new_size)
  989.               set_gas_hash_table_size (new_size);
  990.             else
  991.               as_fatal (_("--hash-size needs a numeric argument"));
  992.             break;
  993.           }
  994.         }
  995.     }
  996.  
  997.   free (shortopts);
  998.   free (longopts);
  999.  
  1000.   *pargc = new_argc;
  1001.   *pargv = new_argv;
  1002.  
  1003. #ifdef md_after_parse_args
  1004.   md_after_parse_args ();
  1005. #endif
  1006. }
  1007.  
  1008. static void
  1009. dump_statistics (void)
  1010. {
  1011. #ifdef HAVE_SBRK
  1012.   char *lim = (char *) sbrk (0);
  1013. #endif
  1014.   long run_time = get_run_time () - start_time;
  1015.  
  1016.   fprintf (stderr, _("%s: total time in assembly: %ld.%06ld\n"),
  1017.            myname, run_time / 1000000, run_time % 1000000);
  1018. #ifdef HAVE_SBRK
  1019.   fprintf (stderr, _("%s: data size %ld\n"),
  1020.            myname, (long) (lim - start_sbrk));
  1021. #endif
  1022.  
  1023.   subsegs_print_statistics (stderr);
  1024.   write_print_statistics (stderr);
  1025.   symbol_print_statistics (stderr);
  1026.   read_print_statistics (stderr);
  1027.  
  1028. #ifdef tc_print_statistics
  1029.   tc_print_statistics (stderr);
  1030. #endif
  1031.  
  1032. #ifdef obj_print_statistics
  1033.   obj_print_statistics (stderr);
  1034. #endif
  1035. }
  1036.  
  1037. static void
  1038. close_output_file (void)
  1039. {
  1040.   output_file_close (out_file_name);
  1041.   if (!keep_it)
  1042.     unlink_if_ordinary (out_file_name);
  1043. }
  1044.  
  1045. /* The interface between the macro code and gas expression handling.  */
  1046.  
  1047. static size_t
  1048. macro_expr (const char *emsg, size_t idx, sb *in, offsetT *val)
  1049. {
  1050.   char *hold;
  1051.   expressionS ex;
  1052.  
  1053.   sb_terminate (in);
  1054.  
  1055.   hold = input_line_pointer;
  1056.   input_line_pointer = in->ptr + idx;
  1057.   expression_and_evaluate (&ex);
  1058.   idx = input_line_pointer - in->ptr;
  1059.   input_line_pointer = hold;
  1060.  
  1061.   if (ex.X_op != O_constant)
  1062.     as_bad ("%s", emsg);
  1063.  
  1064.   *val = ex.X_add_number;
  1065.  
  1066.   return idx;
  1067. }
  1068. /* Here to attempt 1 pass over each input file.
  1069.    We scan argv[*] looking for filenames or exactly "" which is
  1070.    shorthand for stdin. Any argv that is NULL is not a file-name.
  1071.    We set need_pass_2 TRUE if, after this, we still have unresolved
  1072.    expressions of the form (unknown value)+-(unknown value).
  1073.  
  1074.    Note the un*x semantics: there is only 1 logical input file, but it
  1075.    may be a catenation of many 'physical' input files.  */
  1076.  
  1077. static void
  1078. perform_an_assembly_pass (int argc, char ** argv)
  1079. {
  1080.   int saw_a_file = 0;
  1081. #ifndef OBJ_MACH_O
  1082.   flagword applicable;
  1083. #endif
  1084.  
  1085.   need_pass_2 = 0;
  1086.  
  1087. #ifndef OBJ_MACH_O
  1088.   /* Create the standard sections, and those the assembler uses
  1089.      internally.  */
  1090.   text_section = subseg_new (TEXT_SECTION_NAME, 0);
  1091.   data_section = subseg_new (DATA_SECTION_NAME, 0);
  1092.   bss_section = subseg_new (BSS_SECTION_NAME, 0);
  1093.   /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
  1094.      to have relocs, otherwise we don't find out in time.  */
  1095.   applicable = bfd_applicable_section_flags (stdoutput);
  1096.   bfd_set_section_flags (stdoutput, text_section,
  1097.                          applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
  1098.                                        | SEC_CODE | SEC_READONLY));
  1099.   bfd_set_section_flags (stdoutput, data_section,
  1100.                          applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
  1101.                                        | SEC_DATA));
  1102.   bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
  1103.   seg_info (bss_section)->bss = 1;
  1104. #endif
  1105.   subseg_new (BFD_ABS_SECTION_NAME, 0);
  1106.   subseg_new (BFD_UND_SECTION_NAME, 0);
  1107.   reg_section = subseg_new ("*GAS `reg' section*", 0);
  1108.   expr_section = subseg_new ("*GAS `expr' section*", 0);
  1109.  
  1110. #ifndef OBJ_MACH_O
  1111.   subseg_set (text_section, 0);
  1112. #endif
  1113.  
  1114.   /* This may add symbol table entries, which requires having an open BFD,
  1115.      and sections already created.  */
  1116.   md_begin ();
  1117.  
  1118. #ifdef USING_CGEN
  1119.   gas_cgen_begin ();
  1120. #endif
  1121. #ifdef obj_begin
  1122.   obj_begin ();
  1123. #endif
  1124.  
  1125.   /* Skip argv[0].  */
  1126.   argv++;
  1127.   argc--;
  1128.  
  1129.   while (argc--)
  1130.     {
  1131.       if (*argv)
  1132.         {                       /* Is it a file-name argument?  */
  1133.           PROGRESS (1);
  1134.           saw_a_file++;
  1135.           /* argv->"" if stdin desired, else->filename.  */
  1136.           read_a_source_file (*argv);
  1137.         }
  1138.       argv++;                   /* Completed that argv.  */
  1139.     }
  1140.   if (!saw_a_file)
  1141.     read_a_source_file ("");
  1142. }
  1143.  
  1144. int
  1145. main (int argc, char ** argv)
  1146. {
  1147.   char ** argv_orig = argv;
  1148.  
  1149.   int macro_strip_at;
  1150.  
  1151.   start_time = get_run_time ();
  1152. #ifdef HAVE_SBRK
  1153.   start_sbrk = (char *) sbrk (0);
  1154. #endif
  1155.  
  1156. #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
  1157.   setlocale (LC_MESSAGES, "");
  1158. #endif
  1159. #if defined (HAVE_SETLOCALE)
  1160.   setlocale (LC_CTYPE, "");
  1161. #endif
  1162.   bindtextdomain (PACKAGE, LOCALEDIR);
  1163.   textdomain (PACKAGE);
  1164.  
  1165.   if (debug_memory)
  1166.     chunksize = 64;
  1167.  
  1168. #ifdef HOST_SPECIAL_INIT
  1169.   HOST_SPECIAL_INIT (argc, argv);
  1170. #endif
  1171.  
  1172.   myname = argv[0];
  1173.   xmalloc_set_program_name (myname);
  1174.  
  1175.   expandargv (&argc, &argv);
  1176.  
  1177.   START_PROGRESS (myname, 0);
  1178.  
  1179. #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
  1180. #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
  1181. #endif
  1182.  
  1183.   out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
  1184.  
  1185.   hex_init ();
  1186.   bfd_init ();
  1187.   bfd_set_error_program_name (myname);
  1188.  
  1189. #ifdef USE_EMULATIONS
  1190.   select_emulation_mode (argc, argv);
  1191. #endif
  1192.  
  1193.   PROGRESS (1);
  1194.   /* Call parse_args before any of the init/begin functions
  1195.      so that switches like --hash-size can be honored.  */
  1196.   parse_args (&argc, &argv);
  1197.   symbol_begin ();
  1198.   frag_init ();
  1199.   subsegs_begin ();
  1200.   read_begin ();
  1201.   input_scrub_begin ();
  1202.   expr_begin ();
  1203.  
  1204.   /* It has to be called after dump_statistics ().  */
  1205.   xatexit (close_output_file);
  1206.  
  1207.   if (flag_print_statistics)
  1208.     xatexit (dump_statistics);
  1209.  
  1210.   macro_strip_at = 0;
  1211. #ifdef TC_I960
  1212.   macro_strip_at = flag_mri;
  1213. #endif
  1214.  
  1215.   macro_init (flag_macro_alternate, flag_mri, macro_strip_at, macro_expr);
  1216.  
  1217.   PROGRESS (1);
  1218.  
  1219.   output_file_create (out_file_name);
  1220.   gas_assert (stdoutput != 0);
  1221.  
  1222.   dot_symbol_init ();
  1223.  
  1224. #ifdef tc_init_after_args
  1225.   tc_init_after_args ();
  1226. #endif
  1227.  
  1228.   itbl_init ();
  1229.  
  1230.   dwarf2_init ();
  1231.  
  1232.   local_symbol_make (".gasversion.", absolute_section,
  1233.                      BFD_VERSION / 10000UL, &predefined_address_frag);
  1234.  
  1235.   /* Now that we have fully initialized, and have created the output
  1236.      file, define any symbols requested by --defsym command line
  1237.      arguments.  */
  1238.   while (defsyms != NULL)
  1239.     {
  1240.       symbolS *sym;
  1241.       struct defsym_list *next;
  1242.  
  1243.       sym = symbol_new (defsyms->name, absolute_section, defsyms->value,
  1244.                         &zero_address_frag);
  1245.       /* Make symbols defined on the command line volatile, so that they
  1246.          can be redefined inside a source file.  This makes this assembler's
  1247.          behaviour compatible with earlier versions, but it may not be
  1248.          completely intuitive.  */
  1249.       S_SET_VOLATILE (sym);
  1250.       symbol_table_insert (sym);
  1251.       next = defsyms->next;
  1252.       free (defsyms);
  1253.       defsyms = next;
  1254.     }
  1255.  
  1256.   PROGRESS (1);
  1257.  
  1258.   /* Assemble it.  */
  1259.   perform_an_assembly_pass (argc, argv);
  1260.  
  1261.   cond_finish_check (-1);
  1262.  
  1263. #ifdef md_end
  1264.   md_end ();
  1265. #endif
  1266.  
  1267. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  1268.   if ((flag_execstack || flag_noexecstack)
  1269.       && OUTPUT_FLAVOR == bfd_target_elf_flavour)
  1270.     {
  1271.       segT gnustack;
  1272.  
  1273.       gnustack = subseg_new (".note.GNU-stack", 0);
  1274.       bfd_set_section_flags (stdoutput, gnustack,
  1275.                              SEC_READONLY | (flag_execstack ? SEC_CODE : 0));
  1276.  
  1277.     }
  1278. #endif
  1279.  
  1280.   /* If we've been collecting dwarf2 .debug_line info, either for
  1281.      assembly debugging or on behalf of the compiler, emit it now.  */
  1282.   dwarf2_finish ();
  1283.  
  1284.   /* If we constructed dwarf2 .eh_frame info, either via .cfi
  1285.      directives from the user or by the backend, emit it now.  */
  1286.   cfi_finish ();
  1287.  
  1288.   keep_it = 0;
  1289.   if (seen_at_least_1_file ())
  1290.     {
  1291.       int n_warns, n_errs;
  1292.       char warn_msg[50];
  1293.       char err_msg[50];
  1294.  
  1295.       write_object_file ();
  1296.  
  1297.       n_warns = had_warnings ();
  1298.       n_errs = had_errors ();
  1299.  
  1300.       if (n_warns == 1)
  1301.         sprintf (warn_msg, _("%d warning"), n_warns);
  1302.       else
  1303.         sprintf (warn_msg, _("%d warnings"), n_warns);
  1304.       if (n_errs == 1)
  1305.         sprintf (err_msg, _("%d error"), n_errs);
  1306.   else
  1307.         sprintf (err_msg, _("%d errors"), n_errs);
  1308.  
  1309.       if (flag_fatal_warnings && n_warns != 0)
  1310.         {
  1311.           if (n_errs == 0)
  1312.             as_bad (_("%s, treating warnings as errors"), warn_msg);
  1313.           n_errs += n_warns;
  1314.         }
  1315.  
  1316.       if (n_errs == 0)
  1317.         keep_it = 1;
  1318.       else if (flag_always_generate_output)
  1319.         {
  1320.           /* The -Z flag indicates that an object file should be generated,
  1321.              regardless of warnings and errors.  */
  1322.           keep_it = 1;
  1323.           fprintf (stderr, _("%s, %s, generating bad object file\n"),
  1324.                    err_msg, warn_msg);
  1325.         }
  1326.     }
  1327.  
  1328.   fflush (stderr);
  1329.  
  1330. #ifndef NO_LISTING
  1331.   listing_print (listing_filename, argv_orig);
  1332. #endif
  1333.  
  1334.   input_scrub_end ();
  1335.  
  1336.   END_PROGRESS (myname);
  1337.  
  1338.   /* Use xexit instead of return, because under VMS environments they
  1339.      may not place the same interpretation on the value given.  */
  1340.   if (had_errors () != 0)
  1341.     xexit (EXIT_FAILURE);
  1342.  
  1343.   /* Only generate dependency file if assembler was successful.  */
  1344.   print_dependencies ();
  1345.  
  1346.   xexit (EXIT_SUCCESS);
  1347. }
  1348.