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