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