Coverage Report

Created: 2026-07-25 10:20

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