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)
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
30 * Since no-one else says they will support them in future: I
31 * don't support them now.
40 #include "input-scrub.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
[] = {
74 { 0, "/NextDeveloper/Headers/" },
75 { 0, "/LocalDeveloper/Headers/" },
77 /* No default path for Rhapsody or MacOS X */
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};
95 static void perform_an_assembly_pass(
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
;
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 */
117 struct directory_stack
*dirtmp
;
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 */
153 /* Filename. We need it later. */
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' */
163 if(strcmp(arg
, "--gdwarf2") == 0){
164 debug_type
= DEBUG_DWARF2
;
165 *work_argv
= NULL
; /* NULL means 'not a file-name' */
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'. */
177 /* This better be a switch ( -l where l is a letter. */
178 arg
++; /* -> letter. */
180 /* scan all the 1-char flags */
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!",
188 if(a
!= 'f' && a
!= 'n')
189 flagseen
[(int)a
] = TRUE
;
192 if(strcmp(arg
-1, "force_cpusubtype_ALL") == 0){
193 force_cpusubtype_ALL
= 1;
194 arg
= ""; /* Finished with this arg. */
197 /* -f means fast - no need for "app" preprocessor. */
198 flagseen
[(int)a
] = TRUE
;
201 case 'L': /* -L means keep L* symbols */
205 if(*arg
!= '\0') /* Rest of argument is object file-name. */
207 else if(work_argc
){ /* Want next arg for a file-name. */
208 *work_argv
= NULL
; /* This is not a file-name. */
210 out_file_name
= *++work_argv
;
213 as_fatal("%s: I expected a filename after -o. \"%s\" "
214 "assumed.", progname
, out_file_name
);
215 arg
= ""; /* Finished with this arg. */
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
;
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");
231 arg
++; /* Skip the rest */
235 /* -W means don't warn about things */
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 */
247 include_tail
->next
= dirtmp
;
248 /* Tail follows the last one */
249 include_tail
= dirtmp
;
250 /* Rest of argument is include file-name. */
254 /* Want next arg for a file-name. */
255 /* This is not a file-name. */
258 dirtmp
->fname
= *++work_argv
;
261 as_fatal("I expected a filename after -I.");
262 arg
= ""; /* Finished with this arg. */
266 /* generate stabs for debugging assembly code */
271 if(strcmp(arg
-1, "no_ppc601") == 0)
274 /* no default .text section */
275 flagseen
[(int)a
] = TRUE
;
280 if(strcmp(arg
-1, "ppcasm") == 0)
285 if(strcmp(arg
-1, "dynamic") == 0){
286 arg
= ""; /* Finished with this arg. */
287 flagseen
[(int)'k'] = TRUE
;
293 if(strcmp(arg
-1, "static") == 0){
294 arg
= ""; /* Finished with this arg. */
295 flagseen
[(int)'k'] = FALSE
;
301 if(strcmp(arg
-1, "NEXTSTEP-deployment-target") == 0){
302 arg
= ""; /* Finished with this arg. */
303 /* Want next arg for a <release_tag> */
305 /* This, "-NEXTST..." is not a file-name. */
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
;
316 as_fatal("I expected '3.2' or '3.3' after "
317 "-NEXTSTEP-deployment-target.");
321 as_fatal("I expected a <release_tag> "
322 "after -NEXTSTEP-deployment-target.");
328 /* use new features incompatible with 3.2 */
332 /* as driver's -V, verbose, flag */
336 if(strcmp(arg
-1, "arch_multiple") == 0){
338 arg
= ""; /* Finished with this arg. */
341 else if(strcmp(arg
-1, "arch") == 0){
342 arg
= ""; /* Finished with this arg. */
343 /* Want next arg for a <arch_type> */
345 /* This, "-arch" is not a file-name. */
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 "
357 specific_archflag
= *work_argv
;
358 archflag_cpusubtype
=
359 CPU_SUBTYPE_MC68030_ONLY
;
361 else if(strcmp(*work_argv
,
363 if(archflag_cpusubtype
!= -1 &&
364 archflag_cpusubtype
!=
366 as_fatal("can't specify both "
367 "-arch m68030 and -arch "
369 specific_archflag
= *work_argv
;
370 archflag_cpusubtype
=
373 else if(strcmp(*work_argv
, "m68k") != 0)
374 as_fatal("I expected 'm68k', "
375 "'m68030' or 'm68040' after "
376 "-arch for this assembler.");
379 if(strcmp(*work_argv
, "m88k") != 0)
380 as_fatal("I expected 'm88k' after "
381 "-arch for this assembler.");
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
,
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
;
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.");
518 if(strcmp(*work_argv
, "i860") != 0)
519 as_fatal("I expected 'i860' after "
520 "-arch for this assembler.");
522 #if defined(I386) && !defined(ARCH64)
523 if(strcmp(*work_argv
, "i486") == 0){
524 if(archflag_cpusubtype
!= -1 &&
525 archflag_cpusubtype
!=
527 as_fatal("can't specify more "
528 "than one -arch flag ");
529 specific_archflag
= *work_argv
;
530 archflag_cpusubtype
=
533 else if(strcmp(*work_argv
,
535 if(archflag_cpusubtype
!= -1 &&
536 archflag_cpusubtype
!=
538 as_fatal("can't specify more "
539 "than one -arch flag ");
540 specific_archflag
= *work_argv
;
541 archflag_cpusubtype
=
544 else if(strcmp(*work_argv
, "i586") ==0){
545 if(archflag_cpusubtype
!= -1 &&
546 archflag_cpusubtype
!=
548 as_fatal("can't specify more "
549 "than one -arch flag ");
550 specific_archflag
= *work_argv
;
551 archflag_cpusubtype
=
554 else if(strcmp(*work_argv
, "pentium") ==0){
555 if(archflag_cpusubtype
!= -1 &&
556 archflag_cpusubtype
!=
558 as_fatal("can't specify more "
559 "than one -arch flag ");
560 specific_archflag
= *work_argv
;
561 archflag_cpusubtype
=
564 else if(strcmp(*work_argv
, "pentpro") ==0){
565 if(archflag_cpusubtype
!= -1 &&
566 archflag_cpusubtype
!=
568 as_fatal("can't specify more "
569 "than one -arch flag ");
570 specific_archflag
= *work_argv
;
571 archflag_cpusubtype
=
574 else if(strcmp(*work_argv
, "i686") ==0){
575 if(archflag_cpusubtype
!= -1 &&
576 archflag_cpusubtype
!=
578 as_fatal("can't specify more "
579 "than one -arch flag ");
580 specific_archflag
= *work_argv
;
581 archflag_cpusubtype
=
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.");
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.");
626 if(strcmp(*work_argv
, "hppa") != 0)
627 as_fatal("I expected 'hppa' after "
628 "-arch for this assembler.");
631 if(strcmp(*work_argv
, "sparc") != 0)
632 as_fatal("I expected 'sparc' after "
633 "-arch for this assembler.");
636 if(strcmp(*work_argv
,
638 if(archflag_cpusubtype
!= -1 &&
639 archflag_cpusubtype
!=
641 as_fatal("can't specify more "
642 "than one -arch flag ");
643 specific_archflag
= *work_argv
;
644 archflag_cpusubtype
=
647 else if(strcmp(*work_argv
,
649 if(archflag_cpusubtype
!= -1 &&
650 archflag_cpusubtype
!=
652 as_fatal("can't specify more "
653 "than one -arch flag ");
654 specific_archflag
= *work_argv
;
655 archflag_cpusubtype
=
658 else if(strcmp(*work_argv
,
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
,
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
,
682 if(archflag_cpusubtype
!= -1 &&
683 archflag_cpusubtype
!=
685 as_fatal("can't specify more "
686 "than one -arch flag ");
687 specific_archflag
= *work_argv
;
688 archflag_cpusubtype
=
691 else if(strcmp(*work_argv
,
693 if(archflag_cpusubtype
!= -1 &&
694 archflag_cpusubtype
!=
696 as_fatal("can't specify more "
697 "than one -arch flag ");
698 specific_archflag
= *work_argv
;
699 archflag_cpusubtype
=
703 as_fatal("I expected 'arm' after "
704 "-arch for this assembler.");
708 as_fatal("I expected an <arch_type> "
712 /* fall through for non -arch flag */
716 if(md_parse_option(&arg
, &work_argc
, &work_argv
) == 0)
717 as_fatal("%s: I don't understand '%c' flag!", progname
,
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 */
759 if(flagseen
[(int)'p'] == TRUE
)
760 ppcasm_read_begin(); /* read.c */
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.
776 write_object(out_file_name
);
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.
798 perform_an_assembly_pass(
802 char *buffer
; /* Where each bufferful of lines will start. */
807 argv
++; /* skip argv[0] */
808 argc
--; /* skip argv[0] */
810 if(*argv
){ /* Is it a file-name argument? */
811 /* argv -> "" if stdin desired, else -> filename */
812 if((buffer
= input_scrub_new_file(*argv
))){
814 read_a_source_file(buffer
);
817 argv
++; /* completed that argv */
820 if((buffer
= input_scrub_new_file("")))
821 read_a_source_file(buffer
);
829 as_bad("Interrupted by signal %d",sig
);