Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

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