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