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 */
57 static SIGTY got_sig PARAMS ((int sig));
58 static void perform_an_assembly_pass PARAMS ((int argc, char **argv));
61 #define EXIT_SUCCESS 0
62 #define EXIT_FAILURE 1
65 int listing; /* true if a listing is wanted */
67 char *myname; /* argv[0] */
69 segT big_section, reg_section, pass1_section;
70 segT diff_section, absent_section;
71 segT text_section, data_section, bss_section;
82 fprintf (stderr, "GNU assembler version %s (%s)", GAS_VERSION, TARGET_ALIAS);
84 fprintf (stderr, ", using BFD version %s", BFD_VERSION);
86 fprintf (stderr, "\n");
94 int work_argc; /* variable copy of argc */
95 char **work_argv; /* variable copy of argv */
96 char *arg; /* an arg to program */
97 char a; /* an arg flag (after -) */
99 #if 0 /* do we need any of this?? */
101 static const int sig[] = {SIGHUP, SIGINT, SIGPIPE, SIGTERM, 0};
103 for (a = 0; sig[a] != 0; a++)
104 if (signal (sig[a], SIG_IGN) != SIG_IGN)
105 signal (sig[a], got_sig);
110 memset (flagseen, '\0', sizeof (flagseen)); /* aint seen nothing yet */
111 #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
112 #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
114 out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
123 input_scrub_begin ();
126 * Parse arguments, but we are only interested in flags.
127 * When we find a flag, we process it then make it's argv[] NULL.
128 * This helps any future argv[] scanners avoid what we processed.
129 * Since it is easy to do here we interpret the special arg "-"
130 * to mean "use stdin" and we set that argv[] pointing to "".
131 * After we have munged argv[], the only things left are source file
132 * name(s) and ""(s) denoting stdin. These file names are used
133 * (perhaps more than once) later.
135 /* FIXME-SOMEDAY this should use getopt. */
136 work_argc = argc - 1; /* don't count argv[0] */
137 work_argv = argv + 1; /* skip argv[0] */
138 for (; work_argc--; work_argv++)
140 arg = *work_argv; /* work_argv points to this argument */
142 if (*arg != '-') /* Filename. We need it later. */
143 continue; /* Keep scanning args looking for flags. */
144 if (arg[1] == '-' && arg[2] == 0)
146 /* "--" as an argument means read STDIN */
147 /* on this scan, we don't want to think about filenames */
148 *work_argv = ""; /* Code that means 'use stdin'. */
151 /* This better be a switch. */
152 arg++; /*->letter. */
154 while ((a = *arg) != '\0')
155 { /* scan all the 1-char flags */
156 arg++; /* arg->after letter. */
157 a &= 0x7F; /* ascii only please */
170 listing |= LISTING_LISTING;
174 listing |= LISTING_SYMBOLS;
178 listing |= LISTING_HLL;
183 listing |= LISTING_NOFORM;
187 listing |= LISTING_NODEBUG;
192 listing = LISTING_DEFAULT;
203 break; /* -f means fast - no need for "app" preprocessor. */
206 /* DEBUG is implemented: it debugs different */
207 /* things to other people's assemblers. */
211 { /* Include file directory */
218 as_fatal ("virtual memory exhuasted");
227 as_warn ("%s: I expected a filename after -I", myname);
228 add_include_dir (temp);
229 arg = ""; /* Finished with this arg. */
233 #ifdef WARN_SIGNED_OVERFLOW_WORD
234 /* Don't warn about signed overflow. */
239 #ifndef WORKING_DOT_WORD
244 case 'L': /* -L means keep L* symbols */
248 if (*arg) /* Rest of argument is object file-name. */
250 out_file_name = strdup (arg);
252 as_fatal ("virtual memory exhausted");
255 { /* Want next arg for a file-name. */
256 *work_argv = NULL; /* This is not a file-name. */
258 out_file_name = *++work_argv;
261 as_warn ("%s: I expected a filename after -o. \"%s\" assumed.",
262 myname, out_file_name);
263 arg = ""; /* Finished with this arg. */
267 /* -R means put data into text segment */
268 flag_readonly_data_in_text = 1;
274 extern char *compiler_version_string;
275 compiler_version_string = arg;
278 if (*arg && strcmp (arg, "ersion"))
280 as_warn ("Unknown option `-v%s' ignored", arg);
288 arg++; /* Skip the rest */
292 /* -W means don't warn about things */
293 flag_suppress_warnings = 1;
298 /* -X means treat warnings as errors */
301 /* -Z means attempt to generate object file even after errors. */
302 flag_always_generate_output = 1;
307 if (md_parse_option (&arg, &work_argc, &work_argv) == 0)
308 as_warn ("%s: I don't understand '%c' flag.", myname, a);
315 * We have just processed a "-..." arg, which was not a
316 * file-name. Smash it so the
317 * things that look for filenames won't ever see it.
319 * Whatever work_argv points to, it has already been used
320 * as part of a flag, so DON'T re-use it as a filename.
322 *work_argv = NULL; /* NULL means 'not a file-name' */
326 output_file_create (out_file_name);
327 assert (stdoutput != 0);
330 /* Here with flags set up in flagseen[]. */
331 perform_an_assembly_pass (argc, argv); /* Assemble it. */
335 if (seen_at_least_1_file ()
336 && !((had_warnings () && flag_always_generate_output)
337 || had_errors () > 0))
339 write_object_file (); /* relax() addresses then emit object file */
340 } /* we also check in write_object_file() just before emit. */
344 output_file_close (out_file_name);
345 unlink (out_file_name);
350 md_end (); /* MACHINE.c */
356 if ((had_warnings () && flagseen['Z'])
357 || had_errors () > 0)
363 /* perform_an_assembly_pass()
365 * Here to attempt 1 pass over each input file.
366 * We scan argv[*] looking for filenames or exactly "" which is
367 * shorthand for stdin. Any argv that is NULL is not a file-name.
368 * We set need_pass_2 TRUE if, after this, we still have unresolved
369 * expressions of the form (unknown value)+-(unknown value).
371 * Note the un*x semantics: there is only 1 logical input file, but it
372 * may be a catenation of many 'physical' input files.
375 perform_an_assembly_pass (argc, argv)
386 #ifndef BFD_ASSEMBLER
390 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
391 segment_info[i].fix_root = 0;
393 /* Create the three fixed ones */
394 subseg_new (SEG_E0, 0);
395 subseg_new (SEG_E1, 0);
396 subseg_new (SEG_E2, 0);
397 strcpy (segment_info[SEG_E0].scnhdr.s_name, ".text");
398 strcpy (segment_info[SEG_E1].scnhdr.s_name, ".data");
399 strcpy (segment_info[SEG_E2].scnhdr.s_name, ".bss");
401 subseg_new (SEG_E0, 0);
402 #else /* not MANY_SEGMENTS */
403 text_fix_root = NULL;
404 data_fix_root = NULL;
407 subseg_new (SEG_TEXT, 0);
408 #endif /* not MANY_SEGMENTS */
409 #else /* BFD_ASSEMBLER */
410 /* Create the standard sections, and those the assembler uses
412 text_section = subseg_new (".text", 0);
413 data_section = subseg_new (".data", 0);
414 bss_section = subseg_new (".bss", 0);
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 /* This may add symbol table entries, which requires having an open BFD,
437 and sections already created, in BFD_ASSEMBLER mode. */
440 argv++; /* skip argv[0] */
441 argc--; /* skip argv[0] */
445 { /* Is it a file-name argument? */
447 /* argv->"" if stdin desired, else->filename */
448 read_a_source_file (*argv);
450 argv++; /* completed that argv */
453 read_a_source_file ("");
454 } /* perform_an_assembly_pass() */
460 static here_before = 0;
462 as_bad ("Interrupted by signal %d", sig);
465 #if 0 /* If SIGTY is void, this produces warnings. */