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