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