773
[darwin-xtools.git] / cctools / as / as.c
blobeb9a82a1819fa476b1c5e3eb50cc2a4a8d7516c0
1 /* as.c - GAS main program.
2 Copyright (C) 1987 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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 1, or (at your option)
9 any later version.
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.
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. */
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.
27 * bugs
29 * : initialisers
30 * Since no-one else says they will support them in future: I
31 * don't support them now.
35 #include <signal.h>
36 #include <string.h>
37 #include <stdlib.h>
39 #include "as.h"
40 #include "input-scrub.h"
41 #include "symbols.h"
42 #include "sections.h"
43 #include "read.h"
44 #include "md.h"
45 #include "messages.h"
46 #include "xmalloc.h"
47 #include "layout.h"
48 #include "write_object.h"
49 #include "dwarf2dbg.h"
50 #include "stuff/arch.h"
52 /* Used for --gdwarf2 to generate dwarf2 debug info for assembly source files */
53 enum debug_info_type debug_type = DEBUG_NONE;
55 /* ['x'] TRUE if "-x" seen. */
56 char flagseen[128] = { 0 };
58 /* TRUE if -force_cpusubtype_ALL is specified */
59 int force_cpusubtype_ALL = 0;
61 /* set to the corresponding cpusubtype if -arch flag is specified */
62 cpu_subtype_t archflag_cpusubtype = -1;
63 char *specific_archflag = NULL;
65 /* TRUE if the .subsections_via_symbols directive was seen */
66 int subsections_via_symbols = 0;
69 * .include "file" looks in source file dir, then stack.
70 * -I directories are added to the end, then the defaults are added.
72 struct directory_stack include_defaults[] = {
73 #ifdef __OPENSTEP__
74 { 0, "/NextDeveloper/Headers/" },
75 { 0, "/LocalDeveloper/Headers/" },
76 #endif
77 /* No default path for Rhapsody or MacOS X */
78 { 0, NULL }
80 struct directory_stack *include = NULL; /* First dir to search */
81 static struct directory_stack *include_tail = NULL; /* Last in chain */
83 /* apple_version is in apple_version.c which is created by the Makefile */
84 extern char apple_version[];
85 /* this is only used here, thus defined here (was in version.c in GAS) */
86 static char version_string[] = "GNU assembler version 1.38\n";
89 * The list of signals to catch if not ignored.
91 static int sig[] = { SIGHUP, SIGINT, SIGPIPE, SIGTERM, 0};
92 static void got_sig(
93 int sig);
95 static void perform_an_assembly_pass(
96 int argc,
97 char **argv);
99 /* used by error calls (exported) */
100 char *progname = NULL;
102 /* non-NULL if AS_SECURE_LOG_FILE is set */
103 const char *secure_log_file = NULL;
106 main(
107 int argc,
108 char **argv,
109 char **envp)
111 int work_argc; /* variable copy of argc */
112 char **work_argv; /* variable copy of argv */
113 char *arg; /* an arg to program */
114 char a; /* an arg flag (after -) */
115 char *out_file_name;/* name of object file, argument to -o if specified */
116 int i;
117 struct directory_stack *dirtmp;
119 progname = argv[0];
122 * Set up to catch the signals listed in sig[] that are not ignored.
124 for(i = 0; sig[i] != 0; i++)
125 if(signal(sig[i], SIG_IGN) != SIG_IGN)
126 signal(sig[i], got_sig);
128 * Set the default for the flags that will be parsed.
130 memset(flagseen, '\0', sizeof(flagseen)); /* aint seen nothing yet */
131 out_file_name = "a.out"; /* default .o file */
133 /* This is the -dynamic flag, which is now the default */
134 flagseen[(int)'k'] = TRUE;
137 * Parse arguments, but we are only interested in flags.
138 * When we find a flag, we process it then make it's argv[] NULL.
139 * This helps any future argv[] scanners avoid what we processed.
140 * Since it is easy to do here we interpret the special arg "-"
141 * to mean "use stdin" and we set that argv[] pointing to "".
142 * After we have munged argv[], the only things left are source file
143 * name(s) and ""(s) denoting stdin. These file names are used
144 * (perhaps more than once) later.
146 work_argc = argc - 1; /* don't count argv[0] */
147 work_argv = argv + 1; /* skip argv[0] */
148 for( ; work_argc-- ; work_argv++){
150 /* work_argv points to this argument */
151 arg = *work_argv;
153 /* Filename. We need it later. */
154 if(*arg != '-')
155 continue;
157 if(strcmp(arg, "--gstabs") == 0){
158 /* generate stabs for debugging assembly code */
159 flagseen[(int)'g'] = TRUE;
160 *work_argv = NULL; /* NULL means 'not a file-name' */
161 continue;
163 if(strcmp(arg, "--gdwarf2") == 0){
164 debug_type = DEBUG_DWARF2;
165 *work_argv = NULL; /* NULL means 'not a file-name' */
166 continue;
169 /* Keep scanning args looking for flags. */
170 if (arg[1] == '-' && arg[2] == 0) {
171 /* "--" as an argument means read STDIN */
172 /* on this scan, we don't want to think about filenames */
173 *work_argv = ""; /* Code that means 'use stdin'. */
174 continue;
177 /* This better be a switch ( -l where l is a letter. */
178 arg++; /* -> letter. */
180 /* scan all the 1-char flags */
181 while((a = *arg)){
182 arg ++; /* arg -> after letter. */
183 a &= 0x7F; /* ascii only please */
184 if(flagseen[(int)a] && (a != 'I') && (a != 'a') && (a != 'f') &&
185 (a != 'd') && (a != 's') && (a != 'k'))
186 as_warn("%s: Flag option -%c has already been seen!",
187 progname, a);
188 if(a != 'f' && a != 'n')
189 flagseen[(int)a] = TRUE;
190 switch(a){
191 case 'f':
192 if(strcmp(arg-1, "force_cpusubtype_ALL") == 0){
193 force_cpusubtype_ALL = 1;
194 arg = ""; /* Finished with this arg. */
195 break;
197 /* -f means fast - no need for "app" preprocessor. */
198 flagseen[(int)a] = TRUE;
199 break;
201 case 'L': /* -L means keep L* symbols */
202 break;
204 case 'o':
205 if(*arg != '\0') /* Rest of argument is object file-name. */
206 out_file_name = arg;
207 else if(work_argc){ /* Want next arg for a file-name. */
208 *work_argv = NULL; /* This is not a file-name. */
209 work_argc--;
210 out_file_name = *++work_argv;
212 else
213 as_fatal("%s: I expected a filename after -o. \"%s\" "
214 "assumed.", progname, out_file_name);
215 arg = ""; /* Finished with this arg. */
216 break;
218 case 'R':
219 /* -R means put data into text segment */
220 as_fatal("%s: -R option not supported (use the "
221 ".const directive)", progname);
222 flagseen['R'] = FALSE;
223 break;
225 case 'v':
226 fprintf(stderr,"Apple Inc version %s, ", apple_version);
227 fprintf(stderr, "%s", version_string);
228 if(*arg && strcmp(arg,"ersion"))
229 as_fatal("Unknown -v option ignored");
230 while(*arg)
231 arg++; /* Skip the rest */
232 break;
234 case 'W':
235 /* -W means don't warn about things */
236 break;
238 case 'I':
239 /* Add directory to path for includes */
240 dirtmp = (struct directory_stack *)
241 xmalloc(sizeof(struct directory_stack));
242 /* New one goes on the end */
243 dirtmp->next = 0;
244 if(include == 0)
245 include = dirtmp;
246 else
247 include_tail->next = dirtmp;
248 /* Tail follows the last one */
249 include_tail = dirtmp;
250 /* Rest of argument is include file-name. */
251 if(*arg)
252 dirtmp->fname = arg;
253 else if (work_argc){
254 /* Want next arg for a file-name. */
255 /* This is not a file-name. */
256 *work_argv = NULL;
257 work_argc--;
258 dirtmp->fname = *++work_argv;
260 else
261 as_fatal("I expected a filename after -I.");
262 arg = ""; /* Finished with this arg. */
263 break;
265 case 'g':
266 /* generate stabs for debugging assembly code */
267 break;
269 case 'n':
270 #ifdef PPC
271 if(strcmp(arg-1, "no_ppc601") == 0)
272 goto unknown_flag;
273 #endif
274 /* no default .text section */
275 flagseen[(int)a] = TRUE;
276 break;
278 #ifdef PPC
279 case 'p':
280 if(strcmp(arg-1, "ppcasm") == 0)
281 goto unknown_flag;
282 #endif
284 case 'd':
285 if(strcmp(arg-1, "dynamic") == 0){
286 arg = ""; /* Finished with this arg. */
287 flagseen[(int)'k'] = TRUE;
288 break;
290 goto unknown_flag;
292 case 's':
293 if(strcmp(arg-1, "static") == 0){
294 arg = ""; /* Finished with this arg. */
295 flagseen[(int)'k'] = FALSE;
296 break;
298 goto unknown_flag;
300 case 'N':
301 if(strcmp(arg-1, "NEXTSTEP-deployment-target") == 0){
302 arg = ""; /* Finished with this arg. */
303 /* Want next arg for a <release_tag> */
304 if(work_argc){
305 /* This, "-NEXTST..." is not a file-name. */
306 *work_argv = NULL;
307 work_argc--;
308 work_argv++;
309 if(strcmp(*work_argv, "3.3") == 0){
310 flagseen[(int)'k'] = TRUE;
312 else if(strcmp(*work_argv, "3.2") == 0){
313 flagseen[(int)'k'] = FALSE;
315 else{
316 as_fatal("I expected '3.2' or '3.3' after "
317 "-NEXTSTEP-deployment-target.");
320 else
321 as_fatal("I expected a <release_tag> "
322 "after -NEXTSTEP-deployment-target.");
323 break;
325 goto unknown_flag;
327 case 'k':
328 /* use new features incompatible with 3.2 */
329 break;
331 case 'V':
332 /* as driver's -V, verbose, flag */
333 break;
335 case 'a':
336 if(strcmp(arg-1, "arch_multiple") == 0){
337 arch_multiple = 1;
338 arg = ""; /* Finished with this arg. */
339 break;
341 else if(strcmp(arg-1, "arch") == 0){
342 arg = ""; /* Finished with this arg. */
343 /* Want next arg for a <arch_type> */
344 if(work_argc){
345 /* This, "-arch" is not a file-name. */
346 *work_argv = NULL;
347 work_argc--;
348 work_argv++;
349 #ifdef M68K
350 if(strcmp(*work_argv, "m68030") == 0){
351 if(archflag_cpusubtype != -1 &&
352 archflag_cpusubtype !=
353 CPU_SUBTYPE_MC68030_ONLY)
354 as_fatal("can't specify both "
355 "-arch m68030 and -arch "
356 "m68040");
357 specific_archflag = *work_argv;
358 archflag_cpusubtype =
359 CPU_SUBTYPE_MC68030_ONLY;
361 else if(strcmp(*work_argv,
362 "m68040") == 0){
363 if(archflag_cpusubtype != -1 &&
364 archflag_cpusubtype !=
365 CPU_SUBTYPE_MC68040)
366 as_fatal("can't specify both "
367 "-arch m68030 and -arch "
368 "m68040");
369 specific_archflag = *work_argv;
370 archflag_cpusubtype =
371 CPU_SUBTYPE_MC68040;
373 else if(strcmp(*work_argv, "m68k") != 0)
374 as_fatal("I expected 'm68k', "
375 "'m68030' or 'm68040' after "
376 "-arch for this assembler.");
377 #endif
378 #ifdef M88K
379 if(strcmp(*work_argv, "m88k") != 0)
380 as_fatal("I expected 'm88k' after "
381 "-arch for this assembler.");
382 #endif
383 #if defined(PPC) && !defined(ARCH64)
384 if(strcmp(*work_argv, "ppc601") == 0){
385 if(archflag_cpusubtype != -1 &&
386 archflag_cpusubtype !=
387 CPU_SUBTYPE_POWERPC_601)
388 as_fatal("can't specify more "
389 "than one -arch flag ");
390 specific_archflag = *work_argv;
391 archflag_cpusubtype =
392 CPU_SUBTYPE_POWERPC_601;
394 else if(strcmp(*work_argv,
395 "ppc603") == 0){
396 if(archflag_cpusubtype != -1 &&
397 archflag_cpusubtype !=
398 CPU_SUBTYPE_POWERPC_603)
399 as_fatal("can't specify more "
400 "than one -arch flag ");
401 specific_archflag = *work_argv;
402 archflag_cpusubtype =
403 CPU_SUBTYPE_POWERPC_603;
405 else if(strcmp(*work_argv,
406 "ppc603e") == 0){
407 if(archflag_cpusubtype != -1 &&
408 archflag_cpusubtype !=
409 CPU_SUBTYPE_POWERPC_603e)
410 as_fatal("can't specify more "
411 "than one -arch flag ");
412 specific_archflag = *work_argv;
413 archflag_cpusubtype =
414 CPU_SUBTYPE_POWERPC_603e;
416 else if(strcmp(*work_argv,
417 "ppc603ev") == 0){
418 if(archflag_cpusubtype != -1 &&
419 archflag_cpusubtype !=
420 CPU_SUBTYPE_POWERPC_603ev)
421 as_fatal("can't specify more "
422 "than one -arch flag ");
423 specific_archflag = *work_argv;
424 archflag_cpusubtype =
425 CPU_SUBTYPE_POWERPC_603ev;
427 else if(strcmp(*work_argv,
428 "ppc604") == 0){
429 if(archflag_cpusubtype != -1 &&
430 archflag_cpusubtype !=
431 CPU_SUBTYPE_POWERPC_604)
432 as_fatal("can't specify more "
433 "than one -arch flag ");
434 specific_archflag = *work_argv;
435 archflag_cpusubtype =
436 CPU_SUBTYPE_POWERPC_604;
438 else if(strcmp(*work_argv,
439 "ppc604e") == 0){
440 if(archflag_cpusubtype != -1 &&
441 archflag_cpusubtype !=
442 CPU_SUBTYPE_POWERPC_604e)
443 as_fatal("can't specify more "
444 "than one -arch flag ");
445 specific_archflag = *work_argv;
446 archflag_cpusubtype =
447 CPU_SUBTYPE_POWERPC_604e;
449 else if(strcmp(*work_argv,
450 "ppc750") == 0){
451 if(archflag_cpusubtype != -1 &&
452 archflag_cpusubtype !=
453 CPU_SUBTYPE_POWERPC_750)
454 as_fatal("can't specify more "
455 "than one -arch flag ");
456 specific_archflag = *work_argv;
457 archflag_cpusubtype =
458 CPU_SUBTYPE_POWERPC_750;
460 else if(strcmp(*work_argv,
461 "ppc7400") == 0){
462 if(archflag_cpusubtype != -1 &&
463 archflag_cpusubtype !=
464 CPU_SUBTYPE_POWERPC_7400)
465 as_fatal("can't specify more "
466 "than one -arch flag ");
467 specific_archflag = *work_argv;
468 archflag_cpusubtype =
469 CPU_SUBTYPE_POWERPC_7400;
471 else if(strcmp(*work_argv,
472 "ppc7450") == 0){
473 if(archflag_cpusubtype != -1 &&
474 archflag_cpusubtype !=
475 CPU_SUBTYPE_POWERPC_7450)
476 as_fatal("can't specify more "
477 "than one -arch flag ");
478 specific_archflag = *work_argv;
479 archflag_cpusubtype =
480 CPU_SUBTYPE_POWERPC_7450;
482 else if(strcmp(*work_argv,
483 "ppc970") == 0){
484 if(archflag_cpusubtype != -1 &&
485 archflag_cpusubtype !=
486 CPU_SUBTYPE_POWERPC_970)
487 as_fatal("can't specify more "
488 "than one -arch flag ");
489 specific_archflag = *work_argv;
490 archflag_cpusubtype =
491 CPU_SUBTYPE_POWERPC_970;
493 else if(strcmp(*work_argv, "ppc") != 0 &&
494 strcmp(*work_argv, "m98k") != 0)
495 as_fatal("I expected 'ppc' after "
496 "-arch for this assembler.");
497 #endif /* defined(PPC) && !defined(ARCH64) */
498 #if defined(PPC) && defined(ARCH64)
499 if(strcmp(*work_argv,
500 "ppc970-64") == 0){
501 if(archflag_cpusubtype != -1 &&
502 archflag_cpusubtype !=
503 CPU_SUBTYPE_POWERPC_970)
504 as_fatal("can't specify more "
505 "than one -arch flag ");
506 specific_archflag = *work_argv;
507 archflag_cpusubtype =
508 CPU_SUBTYPE_POWERPC_970;
510 else
511 #endif
512 #if defined(PPC) && defined(ARCH64)
513 if(strcmp(*work_argv, "ppc64") != 0)
514 as_fatal("I expected 'ppc64' after "
515 "-arch for this assembler.");
516 #endif
517 #ifdef I860
518 if(strcmp(*work_argv, "i860") != 0)
519 as_fatal("I expected 'i860' after "
520 "-arch for this assembler.");
521 #endif
522 #if defined(I386) && !defined(ARCH64)
523 if(strcmp(*work_argv, "i486") == 0){
524 if(archflag_cpusubtype != -1 &&
525 archflag_cpusubtype !=
526 CPU_SUBTYPE_486)
527 as_fatal("can't specify more "
528 "than one -arch flag ");
529 specific_archflag = *work_argv;
530 archflag_cpusubtype =
531 CPU_SUBTYPE_486;
533 else if(strcmp(*work_argv,
534 "i486SX") == 0){
535 if(archflag_cpusubtype != -1 &&
536 archflag_cpusubtype !=
537 CPU_SUBTYPE_486SX)
538 as_fatal("can't specify more "
539 "than one -arch flag ");
540 specific_archflag = *work_argv;
541 archflag_cpusubtype =
542 CPU_SUBTYPE_486SX;
544 else if(strcmp(*work_argv, "i586") ==0){
545 if(archflag_cpusubtype != -1 &&
546 archflag_cpusubtype !=
547 CPU_SUBTYPE_586)
548 as_fatal("can't specify more "
549 "than one -arch flag ");
550 specific_archflag = *work_argv;
551 archflag_cpusubtype =
552 CPU_SUBTYPE_586;
554 else if(strcmp(*work_argv, "pentium") ==0){
555 if(archflag_cpusubtype != -1 &&
556 archflag_cpusubtype !=
557 CPU_SUBTYPE_PENT)
558 as_fatal("can't specify more "
559 "than one -arch flag ");
560 specific_archflag = *work_argv;
561 archflag_cpusubtype =
562 CPU_SUBTYPE_PENT;
564 else if(strcmp(*work_argv, "pentpro") ==0){
565 if(archflag_cpusubtype != -1 &&
566 archflag_cpusubtype !=
567 CPU_SUBTYPE_PENTPRO)
568 as_fatal("can't specify more "
569 "than one -arch flag ");
570 specific_archflag = *work_argv;
571 archflag_cpusubtype =
572 CPU_SUBTYPE_PENTPRO;
574 else if(strcmp(*work_argv, "i686") ==0){
575 if(archflag_cpusubtype != -1 &&
576 archflag_cpusubtype !=
577 CPU_SUBTYPE_PENTPRO)
578 as_fatal("can't specify more "
579 "than one -arch flag ");
580 specific_archflag = *work_argv;
581 archflag_cpusubtype =
582 CPU_SUBTYPE_PENTPRO;
584 else if(strcmp(*work_argv, "pentIIm3") ==0){
585 if(archflag_cpusubtype != -1 &&
586 archflag_cpusubtype !=
587 CPU_SUBTYPE_PENTII_M3)
588 as_fatal("can't specify more "
589 "than one -arch flag ");
590 specific_archflag = *work_argv;
591 archflag_cpusubtype =
592 CPU_SUBTYPE_PENTII_M3;
594 else if(strcmp(*work_argv, "pentIIm5") ==0){
595 if(archflag_cpusubtype != -1 &&
596 archflag_cpusubtype !=
597 CPU_SUBTYPE_PENTII_M5)
598 as_fatal("can't specify more "
599 "than one -arch flag ");
600 specific_archflag = *work_argv;
601 archflag_cpusubtype =
602 CPU_SUBTYPE_PENTII_M5;
604 else if(strcmp(*work_argv, "pentium4") ==0){
605 if(archflag_cpusubtype != -1 &&
606 archflag_cpusubtype !=
607 CPU_SUBTYPE_PENTIUM_4)
608 as_fatal("can't specify more "
609 "than one -arch flag ");
610 specific_archflag = *work_argv;
611 archflag_cpusubtype =
612 CPU_SUBTYPE_PENTIUM_4;
614 else if(strcmp(*work_argv, "i386") != 0)
615 as_fatal("I expected 'i386', 'i486', 'i486SX', "
616 "'i586', 'pentium', 'i686', 'pentpro', "
617 "'pentIIm3', or 'pentIIm5' after -arch "
618 "for this assembler.");
619 #endif
620 #if defined(I386) && defined(ARCH64)
621 if(strcmp(*work_argv, "x86_64") != 0)
622 as_fatal("I expected 'x86_64' after "
623 "-arch for this assembler.");
624 #endif
625 #ifdef HPPA
626 if(strcmp(*work_argv, "hppa") != 0)
627 as_fatal("I expected 'hppa' after "
628 "-arch for this assembler.");
629 #endif
630 #ifdef SPARC
631 if(strcmp(*work_argv, "sparc") != 0)
632 as_fatal("I expected 'sparc' after "
633 "-arch for this assembler.");
634 #endif
635 #ifdef ARM
636 if(strcmp(*work_argv,
637 "arm") == 0){
638 if(archflag_cpusubtype != -1 &&
639 archflag_cpusubtype !=
640 CPU_SUBTYPE_ARM_V4T)
641 as_fatal("can't specify more "
642 "than one -arch flag ");
643 specific_archflag = *work_argv;
644 archflag_cpusubtype =
645 CPU_SUBTYPE_ARM_V4T;
647 else if(strcmp(*work_argv,
648 "armv4t") == 0){
649 if(archflag_cpusubtype != -1 &&
650 archflag_cpusubtype !=
651 CPU_SUBTYPE_ARM_V4T)
652 as_fatal("can't specify more "
653 "than one -arch flag ");
654 specific_archflag = *work_argv;
655 archflag_cpusubtype =
656 CPU_SUBTYPE_ARM_V4T;
658 else if(strcmp(*work_argv,
659 "armv5") == 0){
660 if(archflag_cpusubtype != -1 &&
661 archflag_cpusubtype !=
662 CPU_SUBTYPE_ARM_V5TEJ)
663 as_fatal("can't specify more "
664 "than one -arch flag ");
665 specific_archflag = *work_argv;
666 archflag_cpusubtype =
667 CPU_SUBTYPE_ARM_V5TEJ;
669 else if(strcmp(*work_argv,
670 "xscale") == 0){
671 if(archflag_cpusubtype != -1 &&
672 archflag_cpusubtype !=
673 CPU_SUBTYPE_ARM_XSCALE)
674 as_fatal("can't specify more "
675 "than one -arch flag ");
676 specific_archflag = *work_argv;
677 archflag_cpusubtype =
678 CPU_SUBTYPE_ARM_XSCALE;
680 else if(strcmp(*work_argv,
681 "armv6") == 0){
682 if(archflag_cpusubtype != -1 &&
683 archflag_cpusubtype !=
684 CPU_SUBTYPE_ARM_V6)
685 as_fatal("can't specify more "
686 "than one -arch flag ");
687 specific_archflag = *work_argv;
688 archflag_cpusubtype =
689 CPU_SUBTYPE_ARM_V6;
691 else if(strcmp(*work_argv,
692 "armv7") == 0){
693 if(archflag_cpusubtype != -1 &&
694 archflag_cpusubtype !=
695 CPU_SUBTYPE_ARM_V7)
696 as_fatal("can't specify more "
697 "than one -arch flag ");
698 specific_archflag = *work_argv;
699 archflag_cpusubtype =
700 CPU_SUBTYPE_ARM_V7;
702 else
703 as_fatal("I expected 'arm' after "
704 "-arch for this assembler.");
705 #endif
707 else
708 as_fatal("I expected an <arch_type> "
709 "after -arch.");
710 break;
712 /* fall through for non -arch flag */
713 default:
714 unknown_flag:
715 --arg;
716 if(md_parse_option(&arg, &work_argc, &work_argv) == 0)
717 as_fatal("%s: I don't understand '%c' flag!", progname,
719 if(arg && *arg)
720 arg++;
721 break;
725 * We have just processed a "-..." arg, which was not a
726 * file-name. Smash it so the
727 * things that look for filenames won't ever see it.
729 * Whatever work_argv points to, it has already been used
730 * as part of a flag, so DON'T re-use it as a filename.
732 *work_argv = NULL; /* NULL means 'not a file-name' */
734 if(flagseen['g'] == TRUE && flagseen['n'] == TRUE)
735 as_fatal("-g can't be specified if -n is specified");
737 * If we haven't seen a -force_cpusubtype_ALL or an -arch flag for a
738 * specific architecture then let the machine instructions in the
739 * assembly determine the cpusubtype of the output file.
741 if(force_cpusubtype_ALL_for_cputype(md_cputype) == TRUE)
742 force_cpusubtype_ALL = TRUE;
743 if(force_cpusubtype_ALL && specific_archflag)
744 archflag_cpusubtype = -1;
747 * Test to see if the AS_SECURE_LOG_FILE environment
748 * variable is set and save the value.
750 secure_log_file = getenv("AS_SECURE_LOG_FILE");
753 * Call the initialization routines.
755 symbol_begin(); /* symbols.c */
756 sections_begin(); /* sections.c */
757 read_begin(); /* read.c */
758 #ifdef PPC
759 if(flagseen[(int)'p'] == TRUE)
760 ppcasm_read_begin(); /* read.c */
761 #endif /* PPC */
762 md_begin(); /* MACHINE.c */
763 input_scrub_begin(); /* input_scrub.c */
765 /* Here with flags set up in flagseen[]. */
766 perform_an_assembly_pass(argc, argv); /* Assemble it. */
768 if(seen_at_least_1_file() && bad_error != TRUE){
770 * If we've been collecting dwarf2 .debug_line info, either for
771 * assembly debugging or on behalf of the compiler, emit it now.
773 dwarf2_finish();
775 layout_addresses();
776 write_object(out_file_name);
779 input_scrub_end();
780 md_end(); /* MACHINE.c */
782 return(bad_error); /* WIN */
785 /* perform_an_assembly_pass()
787 * Here to attempt 1 pass over each input file.
788 * We scan argv[*] looking for filenames or exactly "" which is
789 * shorthand for stdin. Any argv that is NULL is not a file-name.
790 * We set need_pass_2 TRUE if, after this, we still have unresolved
791 * expressions of the form (unknown value)+-(unknown value).
793 * Note the un*x semantics: there is only 1 logical input file, but it
794 * may be a catenation of many 'physical' input files.
796 static
797 void
798 perform_an_assembly_pass(
799 int argc,
800 char **argv)
802 char *buffer; /* Where each bufferful of lines will start. */
803 int saw_a_file;
805 saw_a_file = 0;
807 argv++; /* skip argv[0] */
808 argc--; /* skip argv[0] */
809 while(argc--){
810 if(*argv){ /* Is it a file-name argument? */
811 /* argv -> "" if stdin desired, else -> filename */
812 if((buffer = input_scrub_new_file(*argv))){
813 saw_a_file++;
814 read_a_source_file(buffer);
817 argv++; /* completed that argv */
819 if(!saw_a_file)
820 if((buffer = input_scrub_new_file("")))
821 read_a_source_file(buffer);
824 static
825 void
826 got_sig(
827 int sig)
829 as_bad("Interrupted by signal %d",sig);
830 exit(1);