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