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