Coverage Report

Created: 2026-03-10 08:46

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