* write.c (fixup_segment): Don't discard the symbol for a PC
[deliverable/binutils-gdb.git] / gas / as.c
CommitLineData
fecd2382 1/* as.c - GAS main program.
c7a89bde
ILT
2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 1996
3 Free Software Foundation, Inc.
6efd877d 4
a39116f1 5 This file is part of GAS, the GNU Assembler.
6efd877d 6
a39116f1
RP
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
6efd877d 11
a39116f1
RP
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
6efd877d 16
a39116f1 17 You should have received a copy of the GNU General Public License
bfc94743
ILT
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
fecd2382
RP
21
22/*
23 * Main program for AS; a 32-bit assembler of GNU.
24 * Understands command arguments.
25 * Has a few routines that don't fit in other modules because they
26 * are shared.
27 *
28 *
29 * bugs
30 *
31 * : initialisers
32 * Since no-one else says they will support them in future: I
33 * don't support them now.
34 *
35 */
36
ebd6f117
DM
37#include "ansidecl.h"
38#include "libiberty.h"
39
fecd2382
RP
40#define COMMON
41
42#include "as.h"
5d9f0ecf 43#include "subsegs.h"
6aba9d29 44#include "output-file.h"
7e047ac2
ILT
45#include "sb.h"
46#include "macro.h"
d3038350 47
bfc94743
ILT
48#ifdef HAVE_SBRK
49#ifdef NEED_DECLARATION_SBRK
50extern PTR sbrk ();
51#endif
52#endif
53
f5200318 54static void perform_an_assembly_pass PARAMS ((int argc, char **argv));
7e047ac2 55static int macro_expr PARAMS ((const char *, int, sb *, int *));
fecd2382 56
6efd877d 57int listing; /* true if a listing is wanted */
5d9f0ecf 58
85a961c6
ILT
59static char *listing_filename = NULL; /* Name of listing file. */
60
7e047ac2
ILT
61/* Maximum level of macro nesting. */
62
63int max_macro_nest = 100;
64
6efd877d 65char *myname; /* argv[0] */
67f3dd71 66#ifdef BFD_ASSEMBLER
6aba9d29 67segT reg_section, expr_section;
67f3dd71
KR
68segT text_section, data_section, bss_section;
69#endif
ca7bd557 70
c7a89bde
ILT
71int chunksize = 5000;
72
73/* To monitor memory allocation more effectively, make this non-zero.
74 Then the chunk sizes for gas and bfd will be reduced. */
75int debug_memory = 0;
76
bfc94743
ILT
77/* We build a list of defsyms as we read the options, and then define
78 them after we have initialized everything. */
79
80struct defsym_list
81{
82 struct defsym_list *next;
83 char *name;
84 valueT value;
85};
86
87static struct defsym_list *defsyms;
fecd2382 88\f
f5200318
KR
89void
90print_version_id ()
91{
92 static int printed;
93 if (printed)
94 return;
95 printed = 1;
96
97 fprintf (stderr, "GNU assembler version %s (%s)", GAS_VERSION, TARGET_ALIAS);
98#ifdef BFD_ASSEMBLER
99 fprintf (stderr, ", using BFD version %s", BFD_VERSION);
100#endif
101 fprintf (stderr, "\n");
102}
103
ebd6f117
DM
104void
105show_usage (stream)
106 FILE *stream;
fecd2382 107{
ebd6f117
DM
108 fprintf (stream, "Usage: %s [option...] [asmfile...]\n", myname);
109
110 fprintf (stream, "\
111Options:\n\
112-a[sub-option...] turn on listings\n\
113 Sub-options [default hls]:\n\
114 d omit debugging directives\n\
115 h include high-level source\n\
116 l include assembly\n\
117 n omit forms processing\n\
85a961c6
ILT
118 s include symbols\n\
119 =file set listing file name (must be last sub-option)\n");
a2a1a548 120 fprintf (stream, "\
baed44cd 121-D produce assembler debugging messages\n\
c7a89bde 122--defsym SYM=VAL define symbol SYM to given value\n\
ebd6f117
DM
123-f skip whitespace and comment preprocessing\n\
124--help show this message and exit\n\
125-I DIR add DIR to search list for .include directives\n\
126-J don't warn about signed overflow\n\
127-K warn when differences altered for long displacements\n\
128-L keep local symbols (starting with `L')\n");
129 fprintf (stream, "\
7e047ac2 130-M,--mri assemble in MRI compatibility mode\n\
baed44cd 131-nocpp ignored\n\
f3d817d8 132-o OBJFILE name the object-file output OBJFILE (default a.out)\n\
ebd6f117 133-R fold data section into text section\n\
c7a89bde 134--statistics print various measured statistics from execution\n\
ebd6f117
DM
135--version print assembler version number and exit\n\
136-W suppress warnings\n\
137-w ignored\n\
baed44cd 138-X ignored\n\
ebd6f117
DM
139-Z generate object file even after errors\n");
140
f3d817d8 141 md_show_usage (stream);
bfc94743
ILT
142
143 fprintf (stream, "\nReport bugs to bug-gnu-utils@prep.ai.mit.edu\n");
ebd6f117
DM
144}
145
4761bb02
KR
146#ifdef USE_EMULATIONS
147#define EMULATION_ENVIRON "AS_EMULATION"
148
149extern struct emulation mipsbelf, mipslelf, mipself;
150extern struct emulation mipsbecoff, mipslecoff, mipsecoff;
151
4761bb02
KR
152static struct emulation *const emulations[] = { EMULATIONS };
153static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]);
154
155static void
156select_emulation_mode (argc, argv)
157 int argc;
158 char **argv;
159{
160 int i;
161 char *p, *em = 0;
162
163 for (i = 1; i < argc; i++)
164 if (!strncmp ("--em", argv[i], 4))
165 break;
166
167 if (i == argc)
168 goto do_default;
169
170 p = strchr (argv[i], '=');
171 if (p)
172 p++;
173 else
174 p = argv[i+1];
175
176 if (!p || !*p)
177 as_fatal ("missing emulation mode name");
178 em = p;
179
180 do_default:
181 if (em == 0)
182 em = getenv (EMULATION_ENVIRON);
183 if (em == 0)
184 em = DEFAULT_EMULATION;
185
186 if (em)
187 {
188 for (i = 0; i < n_emulations; i++)
189 if (!strcmp (emulations[i]->name, em))
190 break;
191 if (i == n_emulations)
192 as_fatal ("unrecognized emulation name `%s'", em);
193 this_emulation = emulations[i];
194 }
195 else
196 this_emulation = emulations[0];
197
198 this_emulation->init ();
199}
200
201const char *
202default_emul_bfd_name ()
203{
204 abort ();
8095b665 205 return NULL;
4761bb02
KR
206}
207
208void
209common_emul_init ()
210{
211 this_format = this_emulation->format;
212
213 if (this_emulation->leading_underscore == 2)
214 this_emulation->leading_underscore = this_format->dfl_leading_underscore;
215
216 if (this_emulation->default_endian != 2)
217 target_big_endian = this_emulation->default_endian;
218
219 if (this_emulation->fake_label_name == 0)
220 {
221 if (this_emulation->leading_underscore)
222 this_emulation->fake_label_name = "L0\001";
223 else
224 /* What other parameters should we test? */
225 this_emulation->fake_label_name = ".L0\001";
226 }
227}
228#endif
229
ebd6f117 230/*
ebd6f117
DM
231 * Since it is easy to do here we interpret the special arg "-"
232 * to mean "use stdin" and we set that argv[] pointing to "".
233 * After we have munged argv[], the only things left are source file
234 * name(s) and ""(s) denoting stdin. These file names are used
235 * (perhaps more than once) later.
f3d817d8 236 *
ebd6f117
DM
237 * check for new machine-dep cmdline options in
238 * md_parse_option definitions in config/tc-*.c
239 */
240
241void
f3d817d8
DM
242parse_args (pargc, pargv)
243 int *pargc;
244 char ***pargv;
ebd6f117 245{
f3d817d8
DM
246 int old_argc, new_argc;
247 char **old_argv, **new_argv;
248
249 /* Starting the short option string with '-' is for programs that
250 expect options and other ARGV-elements in any order and that care about
251 the ordering of the two. We describe each non-option ARGV-element
252 as if it were the argument of an option with character code 1. */
253
254 char *shortopts;
255 extern CONST char *md_shortopts;
a7aa7a2b
ILT
256 static const char std_shortopts[] =
257 {
258 '-', 'J',
259#ifndef WORKING_DOT_WORD
260 /* -K is not meaningful if .word is not being hacked. */
261 'K',
a2a1a548 262#endif
7e047ac2 263 'L', 'M', 'R', 'W', 'Z', 'f', 'a', ':', ':', 'D', 'I', ':', 'o', ':',
a7aa7a2b
ILT
264#ifndef VMS
265 /* -v takes an argument on VMS, so we don't make it a generic
266 option. */
267 'v',
268#endif
269 'w', 'X',
270 '\0'
271 };
f3d817d8
DM
272 struct option *longopts;
273 extern struct option md_longopts[];
274 extern size_t md_longopts_size;
460531da 275 static const struct option std_longopts[] = {
f3d817d8
DM
276#define OPTION_HELP (OPTION_STD_BASE)
277 {"help", no_argument, NULL, OPTION_HELP},
7e047ac2 278 {"mri", no_argument, NULL, 'M'},
f3d817d8
DM
279#define OPTION_NOCPP (OPTION_STD_BASE + 1)
280 {"nocpp", no_argument, NULL, OPTION_NOCPP},
281#define OPTION_STATISTICS (OPTION_STD_BASE + 2)
282 {"statistics", no_argument, NULL, OPTION_STATISTICS},
283#define OPTION_VERSION (OPTION_STD_BASE + 3)
284 {"version", no_argument, NULL, OPTION_VERSION},
460531da
KR
285#define OPTION_DUMPCONFIG (OPTION_STD_BASE + 4)
286 {"dump-config", no_argument, NULL, OPTION_DUMPCONFIG},
fb870b50
MT
287#define OPTION_VERBOSE (OPTION_STD_BASE + 5)
288 {"verbose", no_argument, NULL, OPTION_VERBOSE},
4761bb02
KR
289#define OPTION_EMULATION (OPTION_STD_BASE + 6)
290 {"emulation", required_argument, NULL, OPTION_EMULATION},
c7a89bde
ILT
291#define OPTION_DEFSYM (OPTION_STD_BASE + 7)
292 {"defsym", required_argument, NULL, OPTION_DEFSYM}
f3d817d8
DM
293 };
294
295 /* Construct the option lists from the standard list and the
296 target dependent list. */
297 shortopts = concat (std_shortopts, md_shortopts, (char *) NULL);
a2a1a548 298 longopts = (struct option *) xmalloc (sizeof (std_longopts) + md_longopts_size);
f3d817d8
DM
299 memcpy (longopts, std_longopts, sizeof (std_longopts));
300 memcpy ((char *) longopts + sizeof (std_longopts),
301 md_longopts, md_longopts_size);
302
303 /* Make a local copy of the old argv. */
304 old_argc = *pargc;
305 old_argv = *pargv;
306
307 /* Initialize a new argv that contains no options. */
308 new_argv = (char **) xmalloc (sizeof (char *) * (old_argc + 1));
309 new_argv[0] = old_argv[0];
310 new_argc = 1;
311 new_argv[new_argc] = NULL;
312
313 while (1)
6efd877d 314 {
f3d817d8
DM
315 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
316 indicate a long option. */
317 int longind;
318 int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts,
319 &longind);
ebd6f117 320
f3d817d8
DM
321 if (optc == -1)
322 break;
6efd877d 323
f3d817d8
DM
324 switch (optc)
325 {
326 default:
327 /* md_parse_option should return 1 if it recognizes optc,
328 0 if not. */
fb870b50
MT
329 if (md_parse_option (optc, optarg) != 0)
330 break;
331 /* `-v' isn't included in the general short_opts list, so check for
332 it explicity here before deciding we've gotten a bad argument. */
333 if (optc == 'v')
334 {
335#ifdef VMS
336 /* Telling getopt to treat -v's value as optional can result
337 in it picking up a following filename argument here. The
338 VMS code in md_parse_option can return 0 in that case,
339 but it has no way of pushing the filename argument back. */
340 if (optarg && *optarg)
341 new_argv[new_argc++] = optarg, new_argv[new_argc] = NULL;
342 else
343#else
344 case 'v':
345#endif
346 case OPTION_VERBOSE:
347 print_version_id ();
348 break;
349 }
350 /*FALLTHRU*/
f3d817d8
DM
351
352 case '?':
353 exit (EXIT_FAILURE);
354
355 case 1: /* File name. */
356 if (!strcmp (optarg, "-"))
357 optarg = "";
358 new_argv[new_argc++] = optarg;
359 new_argv[new_argc] = NULL;
360 break;
361
362 case OPTION_HELP:
363 show_usage (stdout);
460531da 364 exit (EXIT_SUCCESS);
f3d817d8
DM
365
366 case OPTION_NOCPP:
367 break;
368
369 case OPTION_STATISTICS:
460531da 370 flag_print_statistics = 1;
f3d817d8
DM
371 break;
372
373 case OPTION_VERSION:
bfc94743
ILT
374 /* This output is intended to follow the GNU standards document. */
375 printf ("GNU assembler %s\n", GAS_VERSION);
376 printf ("Copyright 1996 Free Software Foundation, Inc.\n");
377 printf ("\
378This program is free software; you may redistribute it under the terms of\n\
379the GNU General Public License. This program has absolutely no warranty.\n");
380 printf ("This assembler was configured for a target of `%s'.\n",
381 TARGET_ALIAS);
460531da
KR
382 exit (EXIT_SUCCESS);
383
4761bb02 384 case OPTION_EMULATION:
e63c594d 385#ifdef USE_EMULATIONS
4761bb02
KR
386 if (strcmp (optarg, this_emulation->name))
387 as_fatal ("multiple emulation names specified");
e63c594d
FF
388#else
389 as_fatal ("emulations not handled in this configuration");
390#endif
4761bb02
KR
391 break;
392
460531da
KR
393 case OPTION_DUMPCONFIG:
394 fprintf (stderr, "alias = %s\n", TARGET_ALIAS);
395 fprintf (stderr, "canonical = %s\n", TARGET_CANONICAL);
396 fprintf (stderr, "cpu-type = %s\n", TARGET_CPU);
397#ifdef TARGET_OBJ_FORMAT
398 fprintf (stderr, "format = %s\n", TARGET_OBJ_FORMAT);
399#endif
400#ifdef TARGET_FORMAT
401 fprintf (stderr, "bfd-target = %s\n", TARGET_FORMAT);
402#endif
403 exit (EXIT_SUCCESS);
f3d817d8 404
c7a89bde
ILT
405 case OPTION_DEFSYM:
406 {
407 char *s;
408 long i;
bfc94743 409 struct defsym_list *n;
c7a89bde
ILT
410
411 for (s = optarg; *s != '\0' && *s != '='; s++)
412 ;
413 if (*s == '\0')
414 as_fatal ("bad defsym; format is --defsym name=value");
415 *s++ = '\0';
416 i = strtol (s, (char **) NULL, 0);
bfc94743
ILT
417 n = (struct defsym_list *) xmalloc (sizeof *n);
418 n->next = defsyms;
419 n->name = optarg;
420 n->value = i;
421 defsyms = n;
c7a89bde
ILT
422 }
423 break;
424
f3d817d8 425 case 'J':
def66e24
DM
426 flag_signed_overflow_ok = 1;
427 break;
428
a7aa7a2b 429#ifndef WORKING_DOT_WORD
f3d817d8 430 case 'K':
def66e24
DM
431 flag_warn_displacement = 1;
432 break;
a7aa7a2b 433#endif
def66e24 434
f3d817d8 435 case 'L':
def66e24
DM
436 flag_keep_locals = 1;
437 break;
438
7e047ac2
ILT
439 case 'M':
440 flag_mri = 1;
c7a89bde
ILT
441#ifdef TC_M68K
442 flag_m68k_mri = 1;
443#endif
7e047ac2
ILT
444 break;
445
f3d817d8 446 case 'R':
def66e24
DM
447 flag_readonly_data_in_text = 1;
448 break;
449
f3d817d8 450 case 'W':
def66e24
DM
451 flag_no_warnings = 1;
452 break;
453
f3d817d8 454 case 'Z':
def66e24 455 flag_always_generate_output = 1;
f3d817d8
DM
456 break;
457
458 case 'a':
459 if (optarg)
6efd877d 460 {
f3d817d8 461 while (*optarg)
d3038350 462 {
f3d817d8
DM
463 switch (*optarg)
464 {
465 case 'd':
466 listing |= LISTING_NODEBUG;
467 break;
468 case 'h':
469 listing |= LISTING_HLL;
470 break;
471 case 'l':
472 listing |= LISTING_LISTING;
473 break;
474 case 'n':
475 listing |= LISTING_NOFORM;
476 break;
477 case 's':
478 listing |= LISTING_SYMBOLS;
479 break;
85a961c6 480 case '=':
c7a89bde 481 listing_filename = xstrdup (optarg + 1);
85a961c6
ILT
482 optarg += strlen (listing_filename);
483 break;
f3d817d8 484 default:
460531da 485 as_fatal ("invalid listing option `%c'", *optarg);
f3d817d8
DM
486 break;
487 }
488 optarg++;
d3038350 489 }
6efd877d 490 }
f3d817d8
DM
491 if (!listing)
492 listing = LISTING_DEFAULT;
493 break;
494
495 case 'D':
496 /* DEBUG is implemented: it debugs different */
baed44cd 497 /* things from other people's assemblers. */
def66e24
DM
498 flag_debug = 1;
499 break;
500
501 case 'f':
502 flag_no_comments = 1;
f3d817d8
DM
503 break;
504
505 case 'I':
506 { /* Include file directory */
c7a89bde 507 char *temp = xstrdup (optarg);
f3d817d8
DM
508 add_include_dir (temp);
509 break;
510 }
511
512 case 'o':
c7a89bde 513 out_file_name = xstrdup (optarg);
f3d817d8
DM
514 break;
515
f3d817d8
DM
516 case 'w':
517 break;
518
519 case 'X':
520 /* -X means treat warnings as errors */
521 break;
6efd877d 522 }
6efd877d 523 }
f3d817d8
DM
524
525 free (shortopts);
526 free (longopts);
527
528 *pargc = new_argc;
529 *pargv = new_argv;
ebd6f117
DM
530}
531
c7a89bde
ILT
532static void dump_statistics ();
533static long start_time;
534
ebd6f117
DM
535int
536main (argc, argv)
537 int argc;
538 char **argv;
539{
c7a89bde
ILT
540 int macro_alternate;
541 int macro_strip_at;
ebd6f117 542 int keep_it;
c7a89bde
ILT
543
544 start_time = get_run_time ();
545
546 if (debug_memory)
547 {
548#ifdef BFD_ASSEMBLER
549 extern long _bfd_chunksize;
550 _bfd_chunksize = 64;
551#endif
552 chunksize = 64;
553 }
ebd6f117 554
a2a1a548
ILT
555#ifdef HOST_SPECIAL_INIT
556 HOST_SPECIAL_INIT (argc, argv);
557#endif
460531da 558
ebd6f117 559 myname = argv[0];
d2a0c9f9
KR
560 xmalloc_set_program_name (myname);
561
87e48495
KR
562 START_PROGRESS (myname, 0);
563
ebd6f117
DM
564#ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
565#define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
566#endif
d2a0c9f9 567
ebd6f117
DM
568 out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
569
4761bb02 570 hex_init ();
ebd6f117
DM
571#ifdef BFD_ASSEMBLER
572 bfd_init ();
8095b665 573 bfd_set_error_program_name (myname);
ebd6f117
DM
574#endif
575
4761bb02
KR
576#ifdef USE_EMULATIONS
577 select_emulation_mode (argc, argv);
578#endif
579
87e48495 580 PROGRESS (1);
ebd6f117 581 symbol_begin ();
87e48495 582 frag_init ();
ebd6f117 583 subsegs_begin ();
f3d817d8 584 parse_args (&argc, &argv);
c7a89bde 585 read_begin ();
7e047ac2
ILT
586 input_scrub_begin ();
587 expr_begin ();
c7a89bde
ILT
588
589 if (flag_print_statistics)
590 xatexit (dump_statistics);
591
592 macro_alternate = 0;
593 macro_strip_at = 0;
594#ifdef TC_I960
595 macro_strip_at = flag_mri;
596#endif
597#ifdef TC_A29K
598 /* For compatibility with the AMD 29K family macro assembler
599 specification. */
600 macro_alternate = 1;
601 macro_strip_at = 1;
602#endif
603
604 macro_init (macro_alternate, flag_mri, macro_strip_at, macro_expr);
67f3dd71 605
87e48495
KR
606 PROGRESS (1);
607
67f3dd71
KR
608#ifdef BFD_ASSEMBLER
609 output_file_create (out_file_name);
610 assert (stdoutput != 0);
fecd2382 611#endif
67f3dd71 612
ebd6f117
DM
613#ifdef tc_init_after_args
614 tc_init_after_args ();
615#endif
616
bfc94743
ILT
617 /* Now that we have fully initialized, and have created the output
618 file, define any symbols requested by --defsym command line
619 arguments. */
620 while (defsyms != NULL)
621 {
622 symbolS *sym;
623 struct defsym_list *next;
624
625 sym = symbol_new (defsyms->name, absolute_section, defsyms->value,
626 &zero_address_frag);
627 symbol_table_insert (sym);
628 next = defsyms->next;
629 free (defsyms);
630 defsyms = next;
631 }
632
87e48495
KR
633 PROGRESS (1);
634
6efd877d 635 perform_an_assembly_pass (argc, argv); /* Assemble it. */
c7a89bde
ILT
636
637#ifdef md_end
638 md_end ();
fb870b50 639#endif
8b13fa4e 640
6efd877d 641 if (seen_at_least_1_file ()
def66e24 642 && !((had_warnings () && flag_always_generate_output)
6efd877d 643 || had_errors () > 0))
398527f2 644 keep_it = 1;
f5200318 645 else
398527f2
KR
646 keep_it = 0;
647
648 if (keep_it)
649 write_object_file ();
650
651#ifndef NO_LISTING
85a961c6 652 listing_print (listing_filename);
f5200318 653#endif
6efd877d 654
ebd6f117 655#ifndef OBJ_VMS /* does its own file handling */
398527f2
KR
656#ifndef BFD_ASSEMBLER
657 if (keep_it)
658#endif
659 output_file_close (out_file_name);
ebd6f117 660#endif
398527f2
KR
661
662 if (!keep_it)
663 unlink (out_file_name);
664
6efd877d 665 input_scrub_end ();
6efd877d 666
87e48495
KR
667 END_PROGRESS (myname);
668
c7a89bde
ILT
669 /* Use xexit instead of return, because under VMS environments they
670 may not place the same interpretation on the value given. */
671 if ((had_warnings () && flag_always_generate_output)
672 || had_errors () > 0)
673 xexit (EXIT_FAILURE);
674 xexit (EXIT_SUCCESS);
675}
676
677static void
678dump_statistics ()
679{
680 extern char **environ;
e63c594d 681#ifdef HAVE_SBRK
c7a89bde 682 char *lim = (char *) sbrk (0);
e63c594d 683#endif
c7a89bde 684 long run_time = get_run_time () - start_time;
ca7bd557 685
c7a89bde
ILT
686 fprintf (stderr, "%s: total time in assembly: %ld.%06ld\n",
687 myname, run_time / 1000000, run_time % 1000000);
e63c594d 688#ifdef HAVE_SBRK
c7a89bde
ILT
689 fprintf (stderr, "%s: data size %ld\n",
690 myname, (long) (lim - (char *) &environ));
e63c594d 691#endif
ca7bd557 692
c7a89bde
ILT
693 subsegs_print_statistics (stderr);
694 write_print_statistics (stderr);
695 symbol_print_statistics (stderr);
696 read_print_statistics (stderr);
697
698#ifdef tc_print_statistics
699 tc_print_statistics (stderr);
700#endif
701#ifdef obj_print_statistics
702 obj_print_statistics (stderr);
703#endif
d3038350 704}
fecd2382 705\f
6efd877d 706
fecd2382
RP
707/* perform_an_assembly_pass()
708 *
709 * Here to attempt 1 pass over each input file.
710 * We scan argv[*] looking for filenames or exactly "" which is
711 * shorthand for stdin. Any argv that is NULL is not a file-name.
712 * We set need_pass_2 TRUE if, after this, we still have unresolved
713 * expressions of the form (unknown value)+-(unknown value).
714 *
715 * Note the un*x semantics: there is only 1 logical input file, but it
716 * may be a catenation of many 'physical' input files.
717 */
6efd877d
KR
718static void
719perform_an_assembly_pass (argc, argv)
720 int argc;
721 char **argv;
fecd2382 722{
6efd877d 723 int saw_a_file = 0;
67f3dd71
KR
724#ifdef BFD_ASSEMBLER
725 flagword applicable;
726#endif
727
6efd877d
KR
728 need_pass_2 = 0;
729
67f3dd71 730#ifndef BFD_ASSEMBLER
5d9f0ecf 731#ifdef MANY_SEGMENTS
f5200318
KR
732 {
733 unsigned int i;
734 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
6efd877d 735 segment_info[i].fix_root = 0;
f5200318 736 }
6efd877d 737 /* Create the three fixed ones */
6aba9d29
JL
738 {
739 segT seg;
740
ebd6f117
DM
741#ifdef TE_APOLLO
742 seg = subseg_new (".wtext", 0);
743#else
6aba9d29 744 seg = subseg_new (".text", 0);
ebd6f117 745#endif
6aba9d29
JL
746 assert (seg == SEG_E0);
747 seg = subseg_new (".data", 0);
748 assert (seg == SEG_E1);
749 seg = subseg_new (".bss", 0);
750 assert (seg == SEG_E2);
ebd6f117
DM
751#ifdef TE_APOLLO
752 create_target_segments ();
753#endif
6aba9d29
JL
754 }
755
e6498b10 756#else /* not MANY_SEGMENTS */
6efd877d
KR
757 text_fix_root = NULL;
758 data_fix_root = NULL;
759 bss_fix_root = NULL;
e6498b10 760#endif /* not MANY_SEGMENTS */
67f3dd71
KR
761#else /* BFD_ASSEMBLER */
762 /* Create the standard sections, and those the assembler uses
763 internally. */
764 text_section = subseg_new (".text", 0);
67f3dd71 765 data_section = subseg_new (".data", 0);
67f3dd71 766 bss_section = subseg_new (".bss", 0);
67f3dd71
KR
767 /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
768 to have relocs, otherwise we don't find out in time. */
769 applicable = bfd_applicable_section_flags (stdoutput);
770 bfd_set_section_flags (stdoutput, text_section,
771 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
772 | SEC_CODE | SEC_READONLY));
773 /* @@ FIXME -- SEC_CODE seems to mean code only, rather than code possibly.*/
774 bfd_set_section_flags (stdoutput, data_section,
775 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC));
776 bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
8b13fa4e 777 seg_info (bss_section)->bss = 1;
67f3dd71
KR
778 subseg_new (BFD_ABS_SECTION_NAME, 0);
779 subseg_new (BFD_UND_SECTION_NAME, 0);
67f3dd71 780 reg_section = subseg_new ("*GAS `reg' section*", 0);
6aba9d29 781 expr_section = subseg_new ("*GAS `expr' section*", 0);
67f3dd71 782
67f3dd71 783#endif /* BFD_ASSEMBLER */
e6498b10 784
6aba9d29
JL
785 subseg_set (text_section, 0);
786
f5200318
KR
787 /* This may add symbol table entries, which requires having an open BFD,
788 and sections already created, in BFD_ASSEMBLER mode. */
789 md_begin ();
790
0bd28bc4
ILT
791#ifdef obj_begin
792 obj_begin ();
793#endif
794
6efd877d
KR
795 argv++; /* skip argv[0] */
796 argc--; /* skip argv[0] */
797 while (argc--)
798 {
799 if (*argv)
800 { /* Is it a file-name argument? */
87e48495 801 PROGRESS (1);
6efd877d
KR
802 saw_a_file++;
803 /* argv->"" if stdin desired, else->filename */
804 read_a_source_file (*argv);
a39116f1 805 }
6efd877d
KR
806 argv++; /* completed that argv */
807 }
808 if (!saw_a_file)
809 read_a_source_file ("");
810} /* perform_an_assembly_pass() */
fecd2382 811
7e047ac2
ILT
812/* The interface between the macro code and gas expression handling. */
813
814static int
815macro_expr (emsg, idx, in, val)
816 const char *emsg;
817 int idx;
818 sb *in;
819 int *val;
820{
821 char *hold;
822 expressionS ex;
823
824 sb_terminate (in);
825
826 hold = input_line_pointer;
827 input_line_pointer = in->ptr + idx;
828 expression (&ex);
829 idx = input_line_pointer - in->ptr;
830 input_line_pointer = hold;
831
832 if (ex.X_op != O_constant)
833 as_bad ("%s", emsg);
834
835 *val = (int) ex.X_add_number;
836
837 return idx;
838}
839
a39116f1 840/* end of as.c */
This page took 0.216883 seconds and 4 git commands to generate.