1 /* as.c - GAS main program.
2 Copyright (C) 1987, 1990, 1991, 1992 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 2, 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.
39 #include <sys/types.h> /* For pid_t in signal.h */
51 /* This prototype for got_sig() is ansi. If you want
52 anything else, then your compiler is lying to you when
53 it says that it is __STDC__. If you want to change it,
54 #ifdef protect it from those of us with real ansi
59 static void got_sig (int sig);
60 static void perform_an_assembly_pass (int argc, char **argv);
68 static SIGTY got_sig ();
69 static void perform_an_assembly_pass ();
71 #endif /* not __STDC__ */
74 #define EXIT_SUCCESS 0
75 #define EXIT_FAILURE 1
78 int listing; /* true if a listing is wanted */
80 char *myname; /* argv[0] */
82 segT big_section, reg_section, pass1_section;
83 segT diff_section, absent_section;
84 segT text_section, data_section, bss_section;
92 int work_argc; /* variable copy of argc */
93 char **work_argv; /* variable copy of argv */
94 char *arg; /* an arg to program */
95 char a; /* an arg flag (after -) */
97 #if 0 /* do we need any of this?? */
99 static const int sig[] = {SIGHUP, SIGINT, SIGPIPE, SIGTERM, 0};
101 for (a = 0; sig[a] != 0; a++)
102 if (signal (sig[a], SIG_IGN) != SIG_IGN)
103 signal (sig[a], got_sig);
108 memset (flagseen, '\0', sizeof (flagseen)); /* aint seen nothing yet */
109 #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
110 #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
112 out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
122 input_scrub_begin ();
125 * Parse arguments, but we are only interested in flags.
126 * When we find a flag, we process it then make it's argv[] NULL.
127 * This helps any future argv[] scanners avoid what we processed.
128 * Since it is easy to do here we interpret the special arg "-"
129 * to mean "use stdin" and we set that argv[] pointing to "".
130 * After we have munged argv[], the only things left are source file
131 * name(s) and ""(s) denoting stdin. These file names are used
132 * (perhaps more than once) later.
134 /* FIXME-SOMEDAY this should use getopt. */
135 work_argc = argc - 1; /* don't count argv[0] */
136 work_argv = argv + 1; /* skip argv[0] */
137 for (; work_argc--; work_argv++)
139 arg = *work_argv; /* work_argv points to this argument */
141 if (*arg != '-') /* Filename. We need it later. */
142 continue; /* Keep scanning args looking for flags. */
143 if (arg[1] == '-' && arg[2] == 0)
145 /* "--" as an argument means read STDIN */
146 /* on this scan, we don't want to think about filenames */
147 *work_argv = ""; /* Code that means 'use stdin'. */
150 /* This better be a switch. */
151 arg++; /*->letter. */
153 while ((a = *arg) != '\0')
154 { /* scan all the 1-char flags */
155 arg++; /* arg->after letter. */
156 a &= 0x7F; /* ascii only please */
169 listing |= LISTING_LISTING;
173 listing |= LISTING_SYMBOLS;
177 listing |= LISTING_HLL;
182 listing |= LISTING_NOFORM;
186 listing |= LISTING_NODEBUG;
191 listing = LISTING_DEFAULT;
202 break; /* -f means fast - no need for "app" preprocessor. */
205 /* DEBUG is implemented: it debugs different */
206 /* things to other people's assemblers. */
210 { /* Include file directory */
217 as_fatal ("virtual memory exhuasted");
226 as_warn ("%s: I expected a filename after -I", myname);
227 add_include_dir (temp);
228 arg = ""; /* Finished with this arg. */
232 #ifdef WARN_SIGNED_OVERFLOW_WORD
233 /* Don't warn about signed overflow. */
238 #ifndef WORKING_DOT_WORD
243 case 'L': /* -L means keep L* symbols */
247 if (*arg) /* Rest of argument is object file-name. */
249 out_file_name = strdup (arg);
251 as_fatal ("virtual memory exhausted");
254 { /* Want next arg for a file-name. */
255 *work_argv = NULL; /* This is not a file-name. */
257 out_file_name = *++work_argv;
260 as_warn ("%s: I expected a filename after -o. \"%s\" assumed.",
261 myname, out_file_name);
262 arg = ""; /* Finished with this arg. */
266 /* -R means put data into text segment */
267 flag_readonly_data_in_text = 1;
273 extern char *compiler_version_string;
274 compiler_version_string = arg;
277 if (*arg && strcmp (arg, "ersion"))
279 as_warn ("Unknown -v option ignored");
284 fprintf (stderr, "GNU assembler version %s (%s)",
285 GAS_VERSION, TARGET_ALIAS);
287 fprintf (stderr, ", using BFD version %s", BFD_VERSION);
289 fprintf (stderr, "\n");
292 arg++; /* Skip the rest */
296 /* -W means don't warn about things */
297 flag_suppress_warnings = 1;
302 /* -X means treat warnings as errors */
305 /* -Z means attempt to generate object file even after errors. */
306 flag_always_generate_output = 1;
311 if (md_parse_option (&arg, &work_argc, &work_argv) == 0)
312 as_warn ("%s: I don't understand '%c' flag.", myname, a);
319 * We have just processed a "-..." arg, which was not a
320 * file-name. Smash it so the
321 * things that look for filenames won't ever see it.
323 * Whatever work_argv points to, it has already been used
324 * as part of a flag, so DON'T re-use it as a filename.
326 *work_argv = NULL; /* NULL means 'not a file-name' */
330 output_file_create (out_file_name);
331 assert (stdoutput != 0);
334 /* Here with flags set up in flagseen[]. */
335 perform_an_assembly_pass (argc, argv); /* Assemble it. */
339 if (seen_at_least_1_file ()
340 && !((had_warnings () && flag_always_generate_output)
341 || had_errors () > 0))
343 write_object_file (); /* relax() addresses then emit object file */
344 } /* we also check in write_object_file() just before emit. */
347 md_end (); /* MACHINE.c */
353 if ((had_warnings () && flagseen['Z'])
354 || had_errors () > 0)
360 /* perform_an_assembly_pass()
362 * Here to attempt 1 pass over each input file.
363 * We scan argv[*] looking for filenames or exactly "" which is
364 * shorthand for stdin. Any argv that is NULL is not a file-name.
365 * We set need_pass_2 TRUE if, after this, we still have unresolved
366 * expressions of the form (unknown value)+-(unknown value).
368 * Note the un*x semantics: there is only 1 logical input file, but it
369 * may be a catenation of many 'physical' input files.
372 perform_an_assembly_pass (argc, argv)
384 #ifndef BFD_ASSEMBLER
386 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
388 segment_info[i].fix_root = 0;
390 /* Create the three fixed ones */
391 subseg_new (SEG_E0, 0);
392 subseg_new (SEG_E1, 0);
393 subseg_new (SEG_E2, 0);
394 strcpy (segment_info[SEG_E0].scnhdr.s_name, ".text");
395 strcpy (segment_info[SEG_E1].scnhdr.s_name, ".data");
396 strcpy (segment_info[SEG_E2].scnhdr.s_name, ".bss");
398 subseg_new (SEG_E0, 0);
399 #else /* not MANY_SEGMENTS */
400 text_fix_root = NULL;
401 data_fix_root = NULL;
404 subseg_new (SEG_TEXT, 0);
405 #endif /* not MANY_SEGMENTS */
406 #else /* BFD_ASSEMBLER */
407 /* Create the standard sections, and those the assembler uses
409 text_section = subseg_new (".text", 0);
410 text_section->output_section = text_section;
411 data_section = subseg_new (".data", 0);
412 data_section->output_section = data_section;
413 bss_section = subseg_new (".bss", 0);
414 bss_section->output_section = bss_section;
415 /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
416 to have relocs, otherwise we don't find out in time. */
417 applicable = bfd_applicable_section_flags (stdoutput);
418 bfd_set_section_flags (stdoutput, text_section,
419 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
420 | SEC_CODE | SEC_READONLY));
421 /* @@ FIXME -- SEC_CODE seems to mean code only, rather than code possibly.*/
422 bfd_set_section_flags (stdoutput, data_section,
423 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC));
424 bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
425 subseg_new (BFD_ABS_SECTION_NAME, 0);
426 subseg_new (BFD_UND_SECTION_NAME, 0);
427 big_section = subseg_new ("*GAS `big' section*", 0);
428 reg_section = subseg_new ("*GAS `reg' section*", 0);
429 pass1_section = subseg_new ("*GAS `pass1' section*", 0);
430 diff_section = subseg_new ("*GAS `diff' section*", 0);
431 absent_section = subseg_new ("*GAS `absent' section*", 0);
433 subseg_new (".text", 0);
434 #endif /* BFD_ASSEMBLER */
436 argv++; /* skip argv[0] */
437 argc--; /* skip argv[0] */
441 { /* Is it a file-name argument? */
443 /* argv->"" if stdin desired, else->filename */
444 read_a_source_file (*argv);
446 argv++; /* completed that argv */
449 read_a_source_file ("");
450 } /* perform_an_assembly_pass() */
456 static here_before = 0;
458 as_bad ("Interrupted by signal %d", sig);