Back to index

cell-binutils  2.17cvs20070401
as.c
Go to the documentation of this file.
00001 /* as.c - GAS main program.
00002    Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
00003    1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
00004    Free Software Foundation, Inc.
00005 
00006    This file is part of GAS, the GNU Assembler.
00007 
00008    GAS is free software; you can redistribute it and/or modify
00009    it under the terms of the GNU General Public License as published by
00010    the Free Software Foundation; either version 2, or (at your option)
00011    any later version.
00012 
00013    GAS is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016    GNU General Public License for more details.
00017 
00018    You should have received a copy of the GNU General Public License
00019    along with GAS; see the file COPYING.  If not, write to the Free
00020    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
00021    02110-1301, USA.  */
00022 
00023 /* Main program for AS; a 32-bit assembler of GNU.
00024    Understands command arguments.
00025    Has a few routines that don't fit in other modules because they
00026    are shared.
00027   
00028                      bugs
00029   
00030    : initialisers
00031        Since no-one else says they will support them in future: I
00032    don't support them now.  */
00033 
00034 #define COMMON
00035 
00036 #include "as.h"
00037 #include "subsegs.h"
00038 #include "output-file.h"
00039 #include "sb.h"
00040 #include "macro.h"
00041 #include "dwarf2dbg.h"
00042 #include "dw2gencfi.h"
00043 #include "bfdver.h"
00044 
00045 #ifdef HAVE_ITBL_CPU
00046 #include "itbl-ops.h"
00047 #else
00048 #define itbl_parse(itbl_file) 1
00049 #define itbl_init()
00050 #endif
00051 
00052 #ifdef HAVE_SBRK
00053 #ifdef NEED_DECLARATION_SBRK
00054 extern PTR sbrk ();
00055 #endif
00056 #endif
00057 
00058 #ifdef USING_CGEN
00059 /* Perform any cgen specific initialisation for gas.  */
00060 extern void gas_cgen_begin (void);
00061 #endif
00062 
00063 /* Keep a record of the itbl files we read in.  */
00064 struct itbl_file_list
00065 {
00066   struct itbl_file_list *next;
00067   char *name;
00068 };
00069 
00070 /* We build a list of defsyms as we read the options, and then define
00071    them after we have initialized everything.  */
00072 struct defsym_list
00073 {
00074   struct defsym_list *next;
00075   char *name;
00076   valueT value;
00077 };
00078 
00079 
00080 /* True if a listing is wanted.  */
00081 int listing;
00082 
00083 /* Type of debugging to generate.  */
00084 enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
00085 int use_gnu_debug_info_extensions = 0;
00086 
00087 #ifndef MD_DEBUG_FORMAT_SELECTOR
00088 #define MD_DEBUG_FORMAT_SELECTOR NULL
00089 #endif
00090 static enum debug_info_type (*md_debug_format_selector) (int *) = MD_DEBUG_FORMAT_SELECTOR;
00091 
00092 /* Maximum level of macro nesting.  */
00093 int max_macro_nest = 100;
00094 
00095 /* argv[0]  */
00096 static char * myname;
00097 
00098 /* The default obstack chunk size.  If we set this to zero, the
00099    obstack code will use whatever will fit in a 4096 byte block.  */
00100 int chunksize = 0;
00101 
00102 /* To monitor memory allocation more effectively, make this non-zero.
00103    Then the chunk sizes for gas and bfd will be reduced.  */
00104 int debug_memory = 0;
00105 
00106 /* Enable verbose mode.  */
00107 int verbose = 0;
00108 
00109 segT reg_section;
00110 segT expr_section;
00111 segT text_section;
00112 segT data_section;
00113 segT bss_section;
00114 
00115 /* Name of listing file.  */
00116 static char *listing_filename = NULL;
00117 
00118 static struct defsym_list *defsyms;
00119 
00120 static struct itbl_file_list *itbl_files;
00121 
00122 static long start_time;
00123 
00124 static int flag_macro_alternate;
00125 
00126 
00127 #ifdef USE_EMULATIONS
00128 #define EMULATION_ENVIRON "AS_EMULATION"
00129 
00130 extern struct emulation mipsbelf, mipslelf, mipself;
00131 extern struct emulation mipsbecoff, mipslecoff, mipsecoff;
00132 extern struct emulation i386coff, i386elf, i386aout;
00133 extern struct emulation crisaout, criself;
00134 
00135 static struct emulation *const emulations[] = { EMULATIONS };
00136 static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]);
00137 
00138 static void
00139 select_emulation_mode (int argc, char **argv)
00140 {
00141   int i;
00142   char *p, *em = 0;
00143 
00144   for (i = 1; i < argc; i++)
00145     if (!strncmp ("--em", argv[i], 4))
00146       break;
00147 
00148   if (i == argc)
00149     goto do_default;
00150 
00151   p = strchr (argv[i], '=');
00152   if (p)
00153     p++;
00154   else
00155     p = argv[i + 1];
00156 
00157   if (!p || !*p)
00158     as_fatal (_("missing emulation mode name"));
00159   em = p;
00160 
00161  do_default:
00162   if (em == 0)
00163     em = getenv (EMULATION_ENVIRON);
00164   if (em == 0)
00165     em = DEFAULT_EMULATION;
00166 
00167   if (em)
00168     {
00169       for (i = 0; i < n_emulations; i++)
00170        if (!strcmp (emulations[i]->name, em))
00171          break;
00172       if (i == n_emulations)
00173        as_fatal (_("unrecognized emulation name `%s'"), em);
00174       this_emulation = emulations[i];
00175     }
00176   else
00177     this_emulation = emulations[0];
00178 
00179   this_emulation->init ();
00180 }
00181 
00182 const char *
00183 default_emul_bfd_name (void)
00184 {
00185   abort ();
00186   return NULL;
00187 }
00188 
00189 void
00190 common_emul_init (void)
00191 {
00192   this_format = this_emulation->format;
00193 
00194   if (this_emulation->leading_underscore == 2)
00195     this_emulation->leading_underscore = this_format->dfl_leading_underscore;
00196 
00197   if (this_emulation->default_endian != 2)
00198     target_big_endian = this_emulation->default_endian;
00199 
00200   if (this_emulation->fake_label_name == 0)
00201     {
00202       if (this_emulation->leading_underscore)
00203        this_emulation->fake_label_name = "L0\001";
00204       else
00205        /* What other parameters should we test?  */
00206        this_emulation->fake_label_name = ".L0\001";
00207     }
00208 }
00209 #endif
00210 
00211 void
00212 print_version_id (void)
00213 {
00214   static int printed;
00215 
00216   if (printed)
00217     return;
00218   printed = 1;
00219 
00220   fprintf (stderr, _("GNU assembler version %s (%s) using BFD version %s\n"),
00221           VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
00222 }
00223 
00224 static void
00225 show_usage (FILE * stream)
00226 {
00227   fprintf (stream, _("Usage: %s [option...] [asmfile...]\n"), myname);
00228 
00229   fprintf (stream, _("\
00230 Options:\n\
00231   -a[sub-option...]    turn on listings\n\
00232                               Sub-options [default hls]:\n\
00233                               c      omit false conditionals\n\
00234                               d      omit debugging directives\n\
00235                               h      include high-level source\n\
00236                               l      include assembly\n\
00237                               m      include macro expansions\n\
00238                               n      omit forms processing\n\
00239                               s      include symbols\n\
00240                               =FILE  list to FILE (must be last sub-option)\n"));
00241 
00242   fprintf (stream, _("\
00243   --alternate             initially turn on alternate macro syntax\n"));
00244   fprintf (stream, _("\
00245   -D                      produce assembler debugging messages\n"));
00246   fprintf (stream, _("\
00247   --defsym SYM=VAL        define symbol SYM to given value\n"));
00248 #ifdef USE_EMULATIONS
00249   {
00250     int i;
00251     char *def_em;
00252 
00253     fprintf (stream, "\
00254   --em=[");
00255     for (i = 0; i < n_emulations - 1; i++)
00256       fprintf (stream, "%s | ", emulations[i]->name);
00257     fprintf (stream, "%s]\n", emulations[i]->name);
00258 
00259     def_em = getenv (EMULATION_ENVIRON);
00260     if (!def_em)
00261       def_em = DEFAULT_EMULATION;
00262     fprintf (stream, _("\
00263                           emulate output (default %s)\n"), def_em);
00264   }
00265 #endif
00266 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
00267   fprintf (stream, _("\
00268   --execstack             require executable stack for this object\n"));
00269   fprintf (stream, _("\
00270   --noexecstack           don't require executable stack for this object\n"));
00271 #endif
00272   fprintf (stream, _("\
00273   -f                      skip whitespace and comment preprocessing\n"));
00274   fprintf (stream, _("\
00275   -g --gen-debug          generate debugging information\n"));
00276   fprintf (stream, _("\
00277   --gstabs                generate STABS debugging information\n"));
00278   fprintf (stream, _("\
00279   --gstabs+               generate STABS debug info with GNU extensions\n"));
00280   fprintf (stream, _("\
00281   --gdwarf-2              generate DWARF2 debugging information\n"));
00282   fprintf (stream, _("\
00283   --hash-size=<value>     set the hash table size close to <value>\n"));
00284   fprintf (stream, _("\
00285   --help                  show this message and exit\n"));
00286   fprintf (stream, _("\
00287   --target-help           show target specific options\n"));
00288   fprintf (stream, _("\
00289   -I DIR                  add DIR to search list for .include directives\n"));
00290   fprintf (stream, _("\
00291   -J                      don't warn about signed overflow\n"));
00292   fprintf (stream, _("\
00293   -K                      warn when differences altered for long displacements\n"));
00294   fprintf (stream, _("\
00295   -L,--keep-locals        keep local symbols (e.g. starting with `L')\n"));
00296   fprintf (stream, _("\
00297   -M,--mri                assemble in MRI compatibility mode\n"));
00298   fprintf (stream, _("\
00299   --MD FILE               write dependency information in FILE (default none)\n"));
00300   fprintf (stream, _("\
00301   -nocpp                  ignored\n"));
00302   fprintf (stream, _("\
00303   -o OBJFILE              name the object-file output OBJFILE (default a.out)\n"));
00304   fprintf (stream, _("\
00305   -R                      fold data section into text section\n"));
00306   fprintf (stream, _("\
00307   --reduce-memory-overheads \n\
00308                           prefer smaller memory use at the cost of longer\n\
00309                           assembly times\n"));
00310   fprintf (stream, _("\
00311   --statistics            print various measured statistics from execution\n"));
00312   fprintf (stream, _("\
00313   --strip-local-absolute  strip local absolute symbols\n"));
00314   fprintf (stream, _("\
00315   --traditional-format    Use same format as native assembler when possible\n"));
00316   fprintf (stream, _("\
00317   --version               print assembler version number and exit\n"));
00318   fprintf (stream, _("\
00319   -W  --no-warn           suppress warnings\n"));
00320   fprintf (stream, _("\
00321   --warn                  don't suppress warnings\n"));
00322   fprintf (stream, _("\
00323   --fatal-warnings        treat warnings as errors\n"));
00324   fprintf (stream, _("\
00325   --itbl INSTTBL          extend instruction set to include instructions\n\
00326                           matching the specifications defined in file INSTTBL\n"));
00327   fprintf (stream, _("\
00328   -w                      ignored\n"));
00329   fprintf (stream, _("\
00330   -X                      ignored\n"));
00331   fprintf (stream, _("\
00332   -Z                      generate object file even after errors\n"));
00333   fprintf (stream, _("\
00334   --listing-lhs-width     set the width in words of the output data column of\n\
00335                           the listing\n"));
00336   fprintf (stream, _("\
00337   --listing-lhs-width2    set the width in words of the continuation lines\n\
00338                           of the output data column; ignored if smaller than\n\
00339                           the width of the first line\n"));
00340   fprintf (stream, _("\
00341   --listing-rhs-width     set the max width in characters of the lines from\n\
00342                           the source file\n"));
00343   fprintf (stream, _("\
00344   --listing-cont-lines    set the maximum number of continuation lines used\n\
00345                           for the output data column of the listing\n"));
00346   fprintf (stream, _("\
00347   @FILE                   read options from FILE\n")); 
00348 
00349   md_show_usage (stream);
00350 
00351   fputc ('\n', stream);
00352 
00353   if (REPORT_BUGS_TO[0] && stream == stdout)
00354     fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
00355 }
00356 
00357 /* Since it is easy to do here we interpret the special arg "-"
00358    to mean "use stdin" and we set that argv[] pointing to "".
00359    After we have munged argv[], the only things left are source file
00360    name(s) and ""(s) denoting stdin. These file names are used
00361    (perhaps more than once) later.
00362 
00363    check for new machine-dep cmdline options in
00364    md_parse_option definitions in config/tc-*.c.  */
00365 
00366 static void
00367 parse_args (int * pargc, char *** pargv)
00368 {
00369   int old_argc;
00370   int new_argc;
00371   char ** old_argv;
00372   char ** new_argv;
00373   /* Starting the short option string with '-' is for programs that
00374      expect options and other ARGV-elements in any order and that care about
00375      the ordering of the two.  We describe each non-option ARGV-element
00376      as if it were the argument of an option with character code 1.  */
00377   char *shortopts;
00378   extern const char *md_shortopts;
00379   static const char std_shortopts[] =
00380   {
00381     '-', 'J',
00382 #ifndef WORKING_DOT_WORD
00383     /* -K is not meaningful if .word is not being hacked.  */
00384     'K',
00385 #endif
00386     'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', ':',':', 'I', ':', 'o', ':',
00387 #ifndef VMS
00388     /* -v takes an argument on VMS, so we don't make it a generic
00389        option.  */
00390     'v',
00391 #endif
00392     'w', 'X',
00393     /* New option for extending instruction set (see also --itbl below).  */
00394     't', ':',
00395     '\0'
00396   };
00397   struct option *longopts;
00398   extern struct option md_longopts[];
00399   extern size_t md_longopts_size;
00400   /* Codes used for the long options with no short synonyms.  */
00401   enum option_values
00402     {
00403       OPTION_HELP = OPTION_STD_BASE,
00404       OPTION_NOCPP,
00405       OPTION_STATISTICS,
00406       OPTION_VERSION,
00407       OPTION_DUMPCONFIG,
00408       OPTION_VERBOSE,
00409       OPTION_EMULATION,
00410       OPTION_DEFSYM,
00411       OPTION_INSTTBL,
00412       OPTION_LISTING_LHS_WIDTH,
00413       OPTION_LISTING_LHS_WIDTH2,
00414       OPTION_LISTING_RHS_WIDTH,
00415       OPTION_LISTING_CONT_LINES,
00416       OPTION_DEPFILE,
00417       OPTION_GSTABS,
00418       OPTION_GSTABS_PLUS,
00419       OPTION_GDWARF2,
00420       OPTION_STRIP_LOCAL_ABSOLUTE,
00421       OPTION_TRADITIONAL_FORMAT,
00422       OPTION_WARN,
00423       OPTION_TARGET_HELP,
00424       OPTION_EXECSTACK,
00425       OPTION_NOEXECSTACK,
00426       OPTION_ALTERNATE,
00427       OPTION_AL,
00428       OPTION_HASH_TABLE_SIZE,
00429       OPTION_REDUCE_MEMORY_OVERHEADS,
00430       OPTION_WARN_FATAL
00431     /* When you add options here, check that they do
00432        not collide with OPTION_MD_BASE.  See as.h.  */
00433     };
00434   
00435   static const struct option std_longopts[] =
00436   {
00437     /* Note: commas are placed at the start of the line rather than
00438        the end of the preceeding line so that it is simpler to
00439        selectively add and remove lines from this list.  */
00440     {"alternate", no_argument, NULL, OPTION_ALTERNATE}
00441     /* The entry for "a" is here to prevent getopt_long_only() from
00442        considering that -a is an abbreviation for --alternate.  This is
00443        necessary because -a=<FILE> is a valid switch but getopt would
00444        normally reject it since --alternate does not take an argument.  */
00445     ,{"a", optional_argument, NULL, 'a'}
00446     /* Handle -al=<FILE>.  */
00447     ,{"al", optional_argument, NULL, OPTION_AL}
00448     ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
00449     ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
00450     ,{"emulation", required_argument, NULL, OPTION_EMULATION}
00451 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
00452     ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
00453     ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
00454 #endif
00455     ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
00456     ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
00457     /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
00458        so we keep it here for backwards compatibility.  */
00459     ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
00460     ,{"gen-debug", no_argument, NULL, 'g'}
00461     ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
00462     ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
00463     ,{"hash-size", required_argument, NULL, OPTION_HASH_TABLE_SIZE}
00464     ,{"help", no_argument, NULL, OPTION_HELP}
00465     /* New option for extending instruction set (see also -t above).
00466        The "-t file" or "--itbl file" option extends the basic set of
00467        valid instructions by reading "file", a text file containing a
00468        list of instruction formats.  The additional opcodes and their
00469        formats are added to the built-in set of instructions, and
00470        mnemonics for new registers may also be defined.  */
00471     ,{"itbl", required_argument, NULL, OPTION_INSTTBL}
00472     /* getopt allows abbreviations, so we do this to stop it from
00473        treating -k as an abbreviation for --keep-locals.  Some
00474        ports use -k to enable PIC assembly.  */
00475     ,{"keep-locals", no_argument, NULL, 'L'}
00476     ,{"keep-locals", no_argument, NULL, 'L'}
00477     ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
00478     ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
00479     ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
00480     ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
00481     ,{"MD", required_argument, NULL, OPTION_DEPFILE}
00482     ,{"mri", no_argument, NULL, 'M'}
00483     ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
00484     ,{"no-warn", no_argument, NULL, 'W'}
00485     ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
00486     ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
00487     ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
00488     ,{"version", no_argument, NULL, OPTION_VERSION}
00489     ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
00490     ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
00491     ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
00492     ,{"warn", no_argument, NULL, OPTION_WARN}
00493   };
00494 
00495   /* Construct the option lists from the standard list and the target
00496      dependent list.  Include space for an extra NULL option and
00497      always NULL terminate.  */
00498   shortopts = concat (std_shortopts, md_shortopts, (char *) NULL);
00499   longopts = xmalloc (sizeof (std_longopts) + md_longopts_size + sizeof (struct option));
00500   memcpy (longopts, std_longopts, sizeof (std_longopts));
00501   memcpy (((char *) longopts) + sizeof (std_longopts), md_longopts, md_longopts_size);
00502   memset (((char *) longopts) + sizeof (std_longopts) + md_longopts_size,
00503          0, sizeof (struct option));
00504 
00505   /* Make a local copy of the old argv.  */
00506   old_argc = *pargc;
00507   old_argv = *pargv;
00508 
00509   /* Initialize a new argv that contains no options.  */
00510   new_argv = xmalloc (sizeof (char *) * (old_argc + 1));
00511   new_argv[0] = old_argv[0];
00512   new_argc = 1;
00513   new_argv[new_argc] = NULL;
00514 
00515   while (1)
00516     {
00517       /* getopt_long_only is like getopt_long, but '-' as well as '--' can
00518         indicate a long option.  */
00519       int longind;
00520       int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts,
00521                                &longind);
00522 
00523       if (optc == -1)
00524        break;
00525 
00526       switch (optc)
00527        {
00528        default:
00529          /* md_parse_option should return 1 if it recognizes optc,
00530             0 if not.  */
00531          if (md_parse_option (optc, optarg) != 0)
00532            break;
00533          /* `-v' isn't included in the general short_opts list, so check for
00534             it explicitly here before deciding we've gotten a bad argument.  */
00535          if (optc == 'v')
00536            {
00537 #ifdef VMS
00538              /* Telling getopt to treat -v's value as optional can result
00539                in it picking up a following filename argument here.  The
00540                VMS code in md_parse_option can return 0 in that case,
00541                but it has no way of pushing the filename argument back.  */
00542              if (optarg && *optarg)
00543               new_argv[new_argc++] = optarg, new_argv[new_argc] = NULL;
00544              else
00545 #else
00546              case 'v':
00547 #endif
00548              case OPTION_VERBOSE:
00549               print_version_id ();
00550               verbose = 1;
00551              break;
00552            }
00553          else
00554            as_bad (_("unrecognized option -%c%s"), optc, optarg ? optarg : "");
00555          /* Fall through.  */
00556 
00557        case '?':
00558          exit (EXIT_FAILURE);
00559 
00560        case 1:                     /* File name.  */
00561          if (!strcmp (optarg, "-"))
00562            optarg = "";
00563          new_argv[new_argc++] = optarg;
00564          new_argv[new_argc] = NULL;
00565          break;
00566 
00567        case OPTION_TARGET_HELP:
00568          md_show_usage (stdout);
00569          exit (EXIT_SUCCESS);
00570 
00571        case OPTION_HELP:
00572          show_usage (stdout);
00573          exit (EXIT_SUCCESS);
00574 
00575        case OPTION_NOCPP:
00576          break;
00577 
00578        case OPTION_STATISTICS:
00579          flag_print_statistics = 1;
00580          break;
00581 
00582        case OPTION_STRIP_LOCAL_ABSOLUTE:
00583          flag_strip_local_absolute = 1;
00584          break;
00585 
00586        case OPTION_TRADITIONAL_FORMAT:
00587          flag_traditional_format = 1;
00588          break;
00589 
00590        case OPTION_VERSION:
00591          /* This output is intended to follow the GNU standards document.  */
00592          printf (_("GNU assembler %s\n"), BFD_VERSION_STRING);
00593          printf (_("Copyright 2007 Free Software Foundation, Inc.\n"));
00594          printf (_("\
00595 This program is free software; you may redistribute it under the terms of\n\
00596 the GNU General Public License.  This program has absolutely no warranty.\n"));
00597          printf (_("This assembler was configured for a target of `%s'.\n"),
00598                 TARGET_ALIAS);
00599          exit (EXIT_SUCCESS);
00600 
00601        case OPTION_EMULATION:
00602 #ifdef USE_EMULATIONS
00603          if (strcmp (optarg, this_emulation->name))
00604            as_fatal (_("multiple emulation names specified"));
00605 #else
00606          as_fatal (_("emulations not handled in this configuration"));
00607 #endif
00608          break;
00609 
00610        case OPTION_DUMPCONFIG:
00611          fprintf (stderr, _("alias = %s\n"), TARGET_ALIAS);
00612          fprintf (stderr, _("canonical = %s\n"), TARGET_CANONICAL);
00613          fprintf (stderr, _("cpu-type = %s\n"), TARGET_CPU);
00614 #ifdef TARGET_OBJ_FORMAT
00615          fprintf (stderr, _("format = %s\n"), TARGET_OBJ_FORMAT);
00616 #endif
00617 #ifdef TARGET_FORMAT
00618          fprintf (stderr, _("bfd-target = %s\n"), TARGET_FORMAT);
00619 #endif
00620          exit (EXIT_SUCCESS);
00621 
00622        case OPTION_DEFSYM:
00623          {
00624            char *s;
00625            valueT i;
00626            struct defsym_list *n;
00627 
00628            for (s = optarg; *s != '\0' && *s != '='; s++)
00629              ;
00630            if (*s == '\0')
00631              as_fatal (_("bad defsym; format is --defsym name=value"));
00632            *s++ = '\0';
00633            i = bfd_scan_vma (s, (const char **) NULL, 0);
00634            n = xmalloc (sizeof *n);
00635            n->next = defsyms;
00636            n->name = optarg;
00637            n->value = i;
00638            defsyms = n;
00639          }
00640          break;
00641 
00642        case OPTION_INSTTBL:
00643        case 't':
00644          {
00645            /* optarg is the name of the file containing the instruction
00646               formats, opcodes, register names, etc.  */
00647            struct itbl_file_list *n;
00648 
00649            if (optarg == NULL)
00650              {
00651               as_warn (_("no file name following -t option"));
00652               break;
00653              }
00654 
00655            n = xmalloc (sizeof * n);
00656            n->next = itbl_files;
00657            n->name = optarg;
00658            itbl_files = n;
00659 
00660            /* Parse the file and add the new instructions to our internal
00661               table.  If multiple instruction tables are specified, the
00662               information from this table gets appended onto the existing
00663               internal table.  */
00664            itbl_files->name = xstrdup (optarg);
00665            if (itbl_parse (itbl_files->name) != 0)
00666              as_fatal (_("failed to read instruction table %s\n"),
00667                      itbl_files->name);
00668          }
00669          break;
00670 
00671        case OPTION_DEPFILE:
00672          start_dependencies (optarg);
00673          break;
00674 
00675        case 'g':
00676          /* Some backends, eg Alpha and Mips, use the -g switch for their
00677             own purposes.  So we check here for an explicit -g and allow
00678             the backend to decide if it wants to process it.  */
00679          if (   old_argv[optind - 1][1] == 'g'
00680              && md_parse_option (optc, optarg))
00681            continue;
00682 
00683          if (md_debug_format_selector)
00684            debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
00685          else if (IS_ELF)
00686            debug_type = DEBUG_DWARF2;
00687          else
00688            debug_type = DEBUG_STABS;
00689          break;
00690 
00691        case OPTION_GSTABS_PLUS:
00692          use_gnu_debug_info_extensions = 1;
00693          /* Fall through.  */
00694        case OPTION_GSTABS:
00695          debug_type = DEBUG_STABS;
00696          break;
00697 
00698        case OPTION_GDWARF2:
00699          debug_type = DEBUG_DWARF2;
00700          break;
00701 
00702        case 'J':
00703          flag_signed_overflow_ok = 1;
00704          break;
00705 
00706 #ifndef WORKING_DOT_WORD
00707        case 'K':
00708          flag_warn_displacement = 1;
00709          break;
00710 #endif
00711        case 'L':
00712          flag_keep_locals = 1;
00713          break;
00714 
00715        case OPTION_LISTING_LHS_WIDTH:
00716          listing_lhs_width = atoi (optarg);
00717          if (listing_lhs_width_second < listing_lhs_width)
00718            listing_lhs_width_second = listing_lhs_width;
00719          break;
00720        case OPTION_LISTING_LHS_WIDTH2:
00721          {
00722            int tmp = atoi (optarg);
00723 
00724            if (tmp > listing_lhs_width)
00725              listing_lhs_width_second = tmp;
00726          }
00727          break;
00728        case OPTION_LISTING_RHS_WIDTH:
00729          listing_rhs_width = atoi (optarg);
00730          break;
00731        case OPTION_LISTING_CONT_LINES:
00732          listing_lhs_cont_lines = atoi (optarg);
00733          break;
00734 
00735        case 'M':
00736          flag_mri = 1;
00737 #ifdef TC_M68K
00738          flag_m68k_mri = 1;
00739 #endif
00740          break;
00741 
00742        case 'R':
00743          flag_readonly_data_in_text = 1;
00744          break;
00745 
00746        case 'W':
00747          flag_no_warnings = 1;
00748          break;
00749 
00750        case OPTION_WARN:
00751          flag_no_warnings = 0;
00752          flag_fatal_warnings = 0;
00753          break;
00754 
00755        case OPTION_WARN_FATAL:
00756          flag_no_warnings = 0;
00757          flag_fatal_warnings = 1;
00758          break;
00759 
00760 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
00761        case OPTION_EXECSTACK:
00762          flag_execstack = 1;
00763          flag_noexecstack = 0;
00764          break;
00765 
00766        case OPTION_NOEXECSTACK:
00767          flag_noexecstack = 1;
00768          flag_execstack = 0;
00769          break;
00770 #endif
00771        case 'Z':
00772          flag_always_generate_output = 1;
00773          break;
00774 
00775        case OPTION_AL:
00776          listing |= LISTING_LISTING;
00777          if (optarg)
00778            listing_filename = xstrdup (optarg);
00779          break;
00780 
00781        case OPTION_ALTERNATE:
00782          optarg = old_argv [optind - 1];
00783          while (* optarg == '-')
00784            optarg ++;
00785 
00786          if (strcmp (optarg, "alternate") == 0)
00787            {
00788              flag_macro_alternate = 1;
00789              break;
00790            }
00791          optarg ++;
00792          /* Fall through.  */
00793 
00794        case 'a':
00795          if (optarg)
00796            {
00797              if (optarg != old_argv[optind] && optarg[-1] == '=')
00798               --optarg;
00799 
00800              if (md_parse_option (optc, optarg) != 0)
00801               break;
00802 
00803              while (*optarg)
00804               {
00805                 switch (*optarg)
00806                   {
00807                   case 'c':
00808                     listing |= LISTING_NOCOND;
00809                     break;
00810                   case 'd':
00811                     listing |= LISTING_NODEBUG;
00812                     break;
00813                   case 'h':
00814                     listing |= LISTING_HLL;
00815                     break;
00816                   case 'l':
00817                     listing |= LISTING_LISTING;
00818                     break;
00819                   case 'm':
00820                     listing |= LISTING_MACEXP;
00821                     break;
00822                   case 'n':
00823                     listing |= LISTING_NOFORM;
00824                     break;
00825                   case 's':
00826                     listing |= LISTING_SYMBOLS;
00827                     break;
00828                   case '=':
00829                     listing_filename = xstrdup (optarg + 1);
00830                     optarg += strlen (listing_filename);
00831                     break;
00832                   default:
00833                     as_fatal (_("invalid listing option `%c'"), *optarg);
00834                     break;
00835                   }
00836                 optarg++;
00837               }
00838            }
00839          if (!listing)
00840            listing = LISTING_DEFAULT;
00841          break;
00842 
00843        case 'D':
00844          /* DEBUG is implemented: it debugs different
00845             things from other people's assemblers.  */
00846          flag_debug = 1;
00847          break;
00848 
00849        case 'f':
00850          flag_no_comments = 1;
00851          break;
00852 
00853        case 'I':
00854          {                  /* Include file directory.  */
00855            char *temp = xstrdup (optarg);
00856 
00857            add_include_dir (temp);
00858            break;
00859          }
00860 
00861        case 'o':
00862          out_file_name = xstrdup (optarg);
00863          break;
00864 
00865        case 'w':
00866          break;
00867 
00868        case 'X':
00869          /* -X means treat warnings as errors.  */
00870          break;
00871 
00872        case OPTION_REDUCE_MEMORY_OVERHEADS:
00873          /* The only change we make at the moment is to reduce
00874             the size of the hash tables that we use.  */
00875          set_gas_hash_table_size (4051);
00876          break;
00877 
00878        case OPTION_HASH_TABLE_SIZE:
00879          {
00880            unsigned long new_size;
00881 
00882             new_size = strtoul (optarg, NULL, 0);
00883             if (new_size)
00884               set_gas_hash_table_size (new_size);
00885             else
00886               as_fatal (_("--hash-size needs a numeric argument"));
00887            break;
00888          }
00889        }
00890     }
00891 
00892   free (shortopts);
00893   free (longopts);
00894 
00895   *pargc = new_argc;
00896   *pargv = new_argv;
00897 
00898 #ifdef md_after_parse_args
00899   md_after_parse_args ();
00900 #endif
00901 }
00902 
00903 static void
00904 dump_statistics (void)
00905 {
00906 #ifdef HAVE_SBRK
00907   char *lim = (char *) sbrk (0);
00908 #endif
00909   long run_time = get_run_time () - start_time;
00910 
00911   fprintf (stderr, _("%s: total time in assembly: %ld.%06ld\n"),
00912           myname, run_time / 1000000, run_time % 1000000);
00913 #ifdef HAVE_SBRK
00914   fprintf (stderr, _("%s: data size %ld\n"),
00915           myname, (long) (lim - (char *) &environ));
00916 #endif
00917 
00918   subsegs_print_statistics (stderr);
00919   write_print_statistics (stderr);
00920   symbol_print_statistics (stderr);
00921   read_print_statistics (stderr);
00922 
00923 #ifdef tc_print_statistics
00924   tc_print_statistics (stderr);
00925 #endif
00926 
00927 #ifdef obj_print_statistics
00928   obj_print_statistics (stderr);
00929 #endif
00930 }
00931 
00932 #ifndef OBJ_VMS
00933 static void
00934 close_output_file (void)
00935 {
00936   output_file_close (out_file_name);
00937 }
00938 #endif
00939 
00940 /* The interface between the macro code and gas expression handling.  */
00941 
00942 static int
00943 macro_expr (const char *emsg, int idx, sb *in, int *val)
00944 {
00945   char *hold;
00946   expressionS ex;
00947 
00948   sb_terminate (in);
00949 
00950   hold = input_line_pointer;
00951   input_line_pointer = in->ptr + idx;
00952   expression_and_evaluate (&ex);
00953   idx = input_line_pointer - in->ptr;
00954   input_line_pointer = hold;
00955 
00956   if (ex.X_op != O_constant)
00957     as_bad ("%s", emsg);
00958 
00959   *val = (int) ex.X_add_number;
00960 
00961   return idx;
00962 }
00963 
00964 /* Here to attempt 1 pass over each input file.
00965    We scan argv[*] looking for filenames or exactly "" which is
00966    shorthand for stdin. Any argv that is NULL is not a file-name.
00967    We set need_pass_2 TRUE if, after this, we still have unresolved
00968    expressions of the form (unknown value)+-(unknown value).
00969 
00970    Note the un*x semantics: there is only 1 logical input file, but it
00971    may be a catenation of many 'physical' input files.  */
00972 
00973 static void
00974 perform_an_assembly_pass (int argc, char ** argv)
00975 {
00976   int saw_a_file = 0;
00977   flagword applicable;
00978 
00979   need_pass_2 = 0;
00980 
00981   /* Create the standard sections, and those the assembler uses
00982      internally.  */
00983   text_section = subseg_new (TEXT_SECTION_NAME, 0);
00984   data_section = subseg_new (DATA_SECTION_NAME, 0);
00985   bss_section = subseg_new (BSS_SECTION_NAME, 0);
00986   /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
00987      to have relocs, otherwise we don't find out in time.  */
00988   applicable = bfd_applicable_section_flags (stdoutput);
00989   bfd_set_section_flags (stdoutput, text_section,
00990                       applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
00991                                    | SEC_CODE | SEC_READONLY));
00992   bfd_set_section_flags (stdoutput, data_section,
00993                       applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
00994                                    | SEC_DATA));
00995   bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
00996   seg_info (bss_section)->bss = 1;
00997   subseg_new (BFD_ABS_SECTION_NAME, 0);
00998   subseg_new (BFD_UND_SECTION_NAME, 0);
00999   reg_section = subseg_new ("*GAS `reg' section*", 0);
01000   expr_section = subseg_new ("*GAS `expr' section*", 0);
01001 
01002   subseg_set (text_section, 0);
01003 
01004   /* This may add symbol table entries, which requires having an open BFD,
01005      and sections already created.  */
01006   md_begin ();
01007 
01008 #ifdef USING_CGEN
01009   gas_cgen_begin ();
01010 #endif
01011 #ifdef obj_begin
01012   obj_begin ();
01013 #endif
01014 
01015   /* Skip argv[0].  */
01016   argv++;
01017   argc--;
01018 
01019   while (argc--)
01020     {
01021       if (*argv)
01022        {                    /* Is it a file-name argument?  */
01023          PROGRESS (1);
01024          saw_a_file++;
01025          /* argv->"" if stdin desired, else->filename.  */
01026          read_a_source_file (*argv);
01027        }
01028       argv++;               /* Completed that argv.  */
01029     }
01030   if (!saw_a_file)
01031     read_a_source_file ("");
01032 }
01033 
01034 
01035 int
01036 main (int argc, char ** argv)
01037 {
01038   int macro_strip_at;
01039   int keep_it;
01040 
01041   start_time = get_run_time ();
01042 
01043 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
01044   setlocale (LC_MESSAGES, "");
01045 #endif
01046 #if defined (HAVE_SETLOCALE)
01047   setlocale (LC_CTYPE, "");
01048 #endif
01049   bindtextdomain (PACKAGE, LOCALEDIR);
01050   textdomain (PACKAGE);
01051 
01052   if (debug_memory)
01053     chunksize = 64;
01054 
01055 #ifdef HOST_SPECIAL_INIT
01056   HOST_SPECIAL_INIT (argc, argv);
01057 #endif
01058 
01059   myname = argv[0];
01060   xmalloc_set_program_name (myname);
01061 
01062   expandargv (&argc, &argv);
01063 
01064   START_PROGRESS (myname, 0);
01065 
01066 #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
01067 #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
01068 #endif
01069 
01070   out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
01071 
01072   hex_init ();
01073   bfd_init ();
01074   bfd_set_error_program_name (myname);
01075 
01076 #ifdef USE_EMULATIONS
01077   select_emulation_mode (argc, argv);
01078 #endif
01079 
01080   PROGRESS (1);
01081   /* Call parse_args before any of the init/begin functions
01082      so that switches like --hash-size can be honored.  */
01083   parse_args (&argc, &argv);
01084   symbol_begin ();
01085   frag_init ();
01086   subsegs_begin ();
01087   read_begin ();
01088   input_scrub_begin ();
01089   expr_begin ();
01090 
01091 #ifndef OBJ_VMS /* Does its own file handling.  */
01092   /* It has to be called after dump_statistics ().  */
01093   xatexit (close_output_file);
01094 #endif
01095 
01096   if (flag_print_statistics)
01097     xatexit (dump_statistics);
01098 
01099   macro_strip_at = 0;
01100 #ifdef TC_I960
01101   macro_strip_at = flag_mri;
01102 #endif
01103 
01104   macro_init (flag_macro_alternate, flag_mri, macro_strip_at, macro_expr);
01105 
01106   PROGRESS (1);
01107 
01108   output_file_create (out_file_name);
01109   assert (stdoutput != 0);
01110 
01111 #ifdef tc_init_after_args
01112   tc_init_after_args ();
01113 #endif
01114 
01115   itbl_init ();
01116 
01117   /* Now that we have fully initialized, and have created the output
01118      file, define any symbols requested by --defsym command line
01119      arguments.  */
01120   while (defsyms != NULL)
01121     {
01122       symbolS *sym;
01123       struct defsym_list *next;
01124 
01125       sym = symbol_new (defsyms->name, absolute_section, defsyms->value,
01126                      &zero_address_frag);
01127       /* Make symbols defined on the command line volatile, so that they
01128         can be redefined inside a source file.  This makes this assembler's
01129         behaviour compatible with earlier versions, but it may not be
01130         completely intuitive.  */
01131       S_SET_VOLATILE (sym);
01132       symbol_table_insert (sym);
01133       next = defsyms->next;
01134       free (defsyms);
01135       defsyms = next;
01136     }
01137 
01138   PROGRESS (1);
01139 
01140   /* Assemble it.  */
01141   perform_an_assembly_pass (argc, argv);
01142 
01143   cond_finish_check (-1);
01144 
01145 #ifdef md_end
01146   md_end ();
01147 #endif
01148 
01149 #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
01150   if ((flag_execstack || flag_noexecstack)
01151       && OUTPUT_FLAVOR == bfd_target_elf_flavour)
01152     {
01153       segT gnustack;
01154 
01155       gnustack = subseg_new (".note.GNU-stack", 0);
01156       bfd_set_section_flags (stdoutput, gnustack,
01157                           SEC_READONLY | (flag_execstack ? SEC_CODE : 0));
01158                                                                              
01159     }
01160 #endif
01161 
01162   /* If we've been collecting dwarf2 .debug_line info, either for
01163      assembly debugging or on behalf of the compiler, emit it now.  */
01164   dwarf2_finish ();
01165 
01166   /* If we constructed dwarf2 .eh_frame info, either via .cfi 
01167      directives from the user or by the backend, emit it now.  */
01168   cfi_finish ();
01169 
01170   if (seen_at_least_1_file ()
01171       && (flag_always_generate_output || had_errors () == 0))
01172     keep_it = 1;
01173   else
01174     keep_it = 0;
01175 
01176   /* This used to be done at the start of write_object_file in
01177      write.c, but that caused problems when doing listings when
01178      keep_it was zero.  This could probably be moved above md_end, but
01179      I didn't want to risk the change.  */
01180   subsegs_finish ();
01181 
01182   if (keep_it)
01183     write_object_file ();
01184 
01185 #ifndef NO_LISTING
01186   listing_print (listing_filename);
01187 #endif
01188 
01189   if (flag_fatal_warnings && had_warnings () > 0 && had_errors () == 0)
01190     as_bad (_("%d warnings, treating warnings as errors"), had_warnings ());
01191 
01192   if (had_errors () > 0 && ! flag_always_generate_output)
01193     keep_it = 0;
01194 
01195   if (!keep_it)
01196     unlink_if_ordinary (out_file_name);
01197 
01198   input_scrub_end ();
01199 
01200   END_PROGRESS (myname);
01201 
01202   /* Use xexit instead of return, because under VMS environments they
01203      may not place the same interpretation on the value given.  */
01204   if (had_errors () > 0)
01205     xexit (EXIT_FAILURE);
01206 
01207   /* Only generate dependency file if assembler was successful.  */
01208   print_dependencies ();
01209 
01210   xexit (EXIT_SUCCESS);
01211 }