* doc/{all.texi,as.texinfo}: Add documentation for HPPA port.
[deliverable/binutils-gdb.git] / gas / as.c
CommitLineData
fecd2382 1/* as.c - GAS main program.
3340f7e5 2 Copyright (C) 1987, 1990, 1991, 1992 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
35#include <stdio.h>
36#include <string.h>
37
38#ifdef _POSIX_SOURCE
6efd877d 39#include <sys/types.h> /* For pid_t in signal.h */
fecd2382
RP
40#endif
41#include <signal.h>
42
43#define COMMON
44
45#include "as.h"
5d9f0ecf 46#include "subsegs.h"
6aba9d29 47#include "output-file.h"
d3038350 48
fecd2382 49#ifndef SIGTY
f5200318
KR
50#ifdef __STDC__
51#define SIGTY void
52#else
fecd2382 53#define SIGTY int
f5200318
KR
54#endif /* __STDC__ */
55#endif /* SIGTY */
fecd2382 56
6aba9d29
JL
57#if 0
58/* Not currently used. */
f5200318 59static SIGTY got_sig PARAMS ((int sig));
6aba9d29 60#endif
f5200318 61static void perform_an_assembly_pass PARAMS ((int argc, char **argv));
fecd2382 62
d3038350
KR
63#ifndef EXIT_SUCCESS
64#define EXIT_SUCCESS 0
65#define EXIT_FAILURE 1
66#endif
67
6efd877d 68int listing; /* true if a listing is wanted */
5d9f0ecf 69
6efd877d 70char *myname; /* argv[0] */
67f3dd71 71#ifdef BFD_ASSEMBLER
6aba9d29 72segT reg_section, expr_section;
67f3dd71
KR
73segT text_section, data_section, bss_section;
74#endif
fecd2382 75\f
f5200318
KR
76void
77print_version_id ()
78{
79 static int printed;
80 if (printed)
81 return;
82 printed = 1;
83
84 fprintf (stderr, "GNU assembler version %s (%s)", GAS_VERSION, TARGET_ALIAS);
85#ifdef BFD_ASSEMBLER
86 fprintf (stderr, ", using BFD version %s", BFD_VERSION);
87#endif
88 fprintf (stderr, "\n");
89}
90
6efd877d
KR
91int
92main (argc, argv)
93 int argc;
94 char **argv;
fecd2382 95{
6efd877d
KR
96 int work_argc; /* variable copy of argc */
97 char **work_argv; /* variable copy of argv */
98 char *arg; /* an arg to program */
99 char a; /* an arg flag (after -) */
398527f2 100 int keep_it;
6efd877d 101
d3038350
KR
102#if 0 /* do we need any of this?? */
103 {
104 static const int sig[] = {SIGHUP, SIGINT, SIGPIPE, SIGTERM, 0};
105
106 for (a = 0; sig[a] != 0; a++)
107 if (signal (sig[a], SIG_IGN) != SIG_IGN)
108 signal (sig[a], got_sig);
109 }
110#endif
6efd877d
KR
111
112 myname = argv[0];
113 memset (flagseen, '\0', sizeof (flagseen)); /* aint seen nothing yet */
fecd2382
RP
114#ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
115#define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
d3038350 116#endif
6efd877d
KR
117 out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
118
67f3dd71
KR
119#ifdef BFD_ASSEMBLER
120 bfd_init ();
121#endif
122
d3038350
KR
123 symbol_begin ();
124 subsegs_begin ();
125 read_begin ();
d3038350
KR
126 input_scrub_begin ();
127 frag_init ();
6efd877d 128 /*
67f3dd71
KR
129 * Parse arguments, but we are only interested in flags.
130 * When we find a flag, we process it then make it's argv[] NULL.
131 * This helps any future argv[] scanners avoid what we processed.
132 * Since it is easy to do here we interpret the special arg "-"
133 * to mean "use stdin" and we set that argv[] pointing to "".
134 * After we have munged argv[], the only things left are source file
135 * name(s) and ""(s) denoting stdin. These file names are used
136 * (perhaps more than once) later.
137 */
6efd877d
KR
138 /* FIXME-SOMEDAY this should use getopt. */
139 work_argc = argc - 1; /* don't count argv[0] */
140 work_argv = argv + 1; /* skip argv[0] */
141 for (; work_argc--; work_argv++)
142 {
143 arg = *work_argv; /* work_argv points to this argument */
144
145 if (*arg != '-') /* Filename. We need it later. */
146 continue; /* Keep scanning args looking for flags. */
147 if (arg[1] == '-' && arg[2] == 0)
148 {
149 /* "--" as an argument means read STDIN */
150 /* on this scan, we don't want to think about filenames */
151 *work_argv = ""; /* Code that means 'use stdin'. */
152 continue;
153 }
154 /* This better be a switch. */
155 arg++; /*->letter. */
156
157 while ((a = *arg) != '\0')
158 { /* scan all the 1-char flags */
159 arg++; /* arg->after letter. */
160 a &= 0x7F; /* ascii only please */
6aba9d29 161 flagseen[(unsigned char) a] = 1;
6efd877d
KR
162 switch (a)
163 {
6efd877d
KR
164 case 'a':
165 {
166 int loop = 1;
167
168 while (loop)
169 {
170 switch (*arg)
171 {
172 case 'l':
173 listing |= LISTING_LISTING;
174 arg++;
175 break;
176 case 's':
177 listing |= LISTING_SYMBOLS;
178 arg++;
179 break;
180 case 'h':
181 listing |= LISTING_HLL;
182 arg++;
183 break;
184
185 case 'n':
186 listing |= LISTING_NOFORM;
187 arg++;
188 break;
189 case 'd':
190 listing |= LISTING_NODEBUG;
191 arg++;
192 break;
193 default:
194 if (!listing)
195 listing = LISTING_DEFAULT;
196 loop = 0;
197 break;
198 }
199 }
200 }
201
202 break;
203
204
205 case 'f':
206 break; /* -f means fast - no need for "app" preprocessor. */
207
208 case 'D':
209 /* DEBUG is implemented: it debugs different */
210 /* things to other people's assemblers. */
211 break;
212
6efd877d
KR
213 case 'I':
214 { /* Include file directory */
215
216 char *temp = NULL;
217 if (*arg)
d3038350
KR
218 {
219 temp = strdup (arg);
220 if (!temp)
6aba9d29 221 as_fatal ("virtual memory exhausted");
d3038350 222 }
6efd877d
KR
223 else if (work_argc)
224 {
225 *work_argv = NULL;
226 work_argc--;
227 temp = *++work_argv;
228 }
229 else
230 as_warn ("%s: I expected a filename after -I", myname);
231 add_include_dir (temp);
232 arg = ""; /* Finished with this arg. */
233 break;
234 }
235
236#ifdef WARN_SIGNED_OVERFLOW_WORD
237 /* Don't warn about signed overflow. */
238 case 'J':
239 break;
fecd2382 240#endif
6efd877d 241
fecd2382 242#ifndef WORKING_DOT_WORD
6efd877d
KR
243 case 'K':
244 break;
fecd2382 245#endif
6efd877d
KR
246
247 case 'L': /* -L means keep L* symbols */
248 break;
249
250 case 'o':
251 if (*arg) /* Rest of argument is object file-name. */
d3038350
KR
252 {
253 out_file_name = strdup (arg);
254 if (!out_file_name)
255 as_fatal ("virtual memory exhausted");
256 }
6efd877d
KR
257 else if (work_argc)
258 { /* Want next arg for a file-name. */
259 *work_argv = NULL; /* This is not a file-name. */
260 work_argc--;
261 out_file_name = *++work_argv;
262 }
263 else
d3038350
KR
264 as_warn ("%s: I expected a filename after -o. \"%s\" assumed.",
265 myname, out_file_name);
6efd877d
KR
266 arg = ""; /* Finished with this arg. */
267 break;
268
269 case 'R':
270 /* -R means put data into text segment */
67f3dd71 271 flag_readonly_data_in_text = 1;
6efd877d
KR
272 break;
273
274 case 'v':
fecd2382 275#ifdef VMS
6efd877d
KR
276 {
277 extern char *compiler_version_string;
278 compiler_version_string = arg;
279 }
fecd2382 280#else /* not VMS */
6efd877d 281 if (*arg && strcmp (arg, "ersion"))
d3038350 282 {
f5200318 283 as_warn ("Unknown option `-v%s' ignored", arg);
d3038350
KR
284 arg += strlen (arg);
285 break;
286 }
287
f5200318 288 print_version_id ();
d3038350 289#endif /* not VMS */
6efd877d
KR
290 while (*arg)
291 arg++; /* Skip the rest */
292 break;
293
294 case 'W':
6efd877d 295 /* -W means don't warn about things */
67f3dd71
KR
296 flag_suppress_warnings = 1;
297 break;
298
299 case 'w':
6efd877d
KR
300 case 'X':
301 /* -X means treat warnings as errors */
67f3dd71 302 break;
6efd877d
KR
303 case 'Z':
304 /* -Z means attempt to generate object file even after errors. */
67f3dd71 305 flag_always_generate_output = 1;
6efd877d
KR
306 break;
307
308 default:
309 --arg;
310 if (md_parse_option (&arg, &work_argc, &work_argv) == 0)
311 as_warn ("%s: I don't understand '%c' flag.", myname, a);
312 if (arg && *arg)
313 arg++;
314 break;
315 }
316 }
317 /*
67f3dd71
KR
318 * We have just processed a "-..." arg, which was not a
319 * file-name. Smash it so the
320 * things that look for filenames won't ever see it.
321 *
322 * Whatever work_argv points to, it has already been used
323 * as part of a flag, so DON'T re-use it as a filename.
324 */
6efd877d
KR
325 *work_argv = NULL; /* NULL means 'not a file-name' */
326 }
67f3dd71
KR
327
328#ifdef BFD_ASSEMBLER
329 output_file_create (out_file_name);
330 assert (stdoutput != 0);
fecd2382 331#endif
67f3dd71 332
6efd877d
KR
333 /* Here with flags set up in flagseen[]. */
334 perform_an_assembly_pass (argc, argv); /* Assemble it. */
fecd2382 335#ifdef TC_I960
6efd877d 336 brtab_emit ();
fecd2382 337#endif
8b13fa4e 338
6efd877d 339 if (seen_at_least_1_file ()
67f3dd71 340 && !((had_warnings () && flag_always_generate_output)
6efd877d 341 || had_errors () > 0))
398527f2 342 keep_it = 1;
f5200318 343 else
398527f2
KR
344 keep_it = 0;
345
346 if (keep_it)
347 write_object_file ();
348
349#ifndef NO_LISTING
350 listing_print ("");
f5200318 351#endif
6efd877d 352
398527f2
KR
353#ifndef BFD_ASSEMBLER
354 if (keep_it)
355#endif
356 output_file_close (out_file_name);
357
358 if (!keep_it)
359 unlink (out_file_name);
360
6efd877d 361 input_scrub_end ();
398527f2
KR
362#ifdef md_end
363 md_end ();
364#endif
6efd877d 365
d3038350
KR
366 if ((had_warnings () && flagseen['Z'])
367 || had_errors () > 0)
368 return EXIT_FAILURE;
369 return EXIT_SUCCESS;
370}
fecd2382 371\f
6efd877d 372
fecd2382
RP
373/* perform_an_assembly_pass()
374 *
375 * Here to attempt 1 pass over each input file.
376 * We scan argv[*] looking for filenames or exactly "" which is
377 * shorthand for stdin. Any argv that is NULL is not a file-name.
378 * We set need_pass_2 TRUE if, after this, we still have unresolved
379 * expressions of the form (unknown value)+-(unknown value).
380 *
381 * Note the un*x semantics: there is only 1 logical input file, but it
382 * may be a catenation of many 'physical' input files.
383 */
6efd877d
KR
384static void
385perform_an_assembly_pass (argc, argv)
386 int argc;
387 char **argv;
fecd2382 388{
6efd877d 389 int saw_a_file = 0;
67f3dd71
KR
390#ifdef BFD_ASSEMBLER
391 flagword applicable;
392#endif
393
6efd877d
KR
394 need_pass_2 = 0;
395
67f3dd71 396#ifndef BFD_ASSEMBLER
5d9f0ecf 397#ifdef MANY_SEGMENTS
f5200318
KR
398 {
399 unsigned int i;
400 for (i = SEG_E0; i < SEG_UNKNOWN; i++)
6efd877d 401 segment_info[i].fix_root = 0;
f5200318 402 }
6efd877d 403 /* Create the three fixed ones */
6aba9d29
JL
404 {
405 segT seg;
406
407 seg = subseg_new (".text", 0);
408 assert (seg == SEG_E0);
409 seg = subseg_new (".data", 0);
410 assert (seg == SEG_E1);
411 seg = subseg_new (".bss", 0);
412 assert (seg == SEG_E2);
413 }
414
e6498b10 415#else /* not MANY_SEGMENTS */
6efd877d
KR
416 text_fix_root = NULL;
417 data_fix_root = NULL;
418 bss_fix_root = NULL;
e6498b10 419#endif /* not MANY_SEGMENTS */
67f3dd71
KR
420#else /* BFD_ASSEMBLER */
421 /* Create the standard sections, and those the assembler uses
422 internally. */
423 text_section = subseg_new (".text", 0);
67f3dd71 424 data_section = subseg_new (".data", 0);
67f3dd71 425 bss_section = subseg_new (".bss", 0);
67f3dd71
KR
426 /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
427 to have relocs, otherwise we don't find out in time. */
428 applicable = bfd_applicable_section_flags (stdoutput);
429 bfd_set_section_flags (stdoutput, text_section,
430 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
431 | SEC_CODE | SEC_READONLY));
432 /* @@ FIXME -- SEC_CODE seems to mean code only, rather than code possibly.*/
433 bfd_set_section_flags (stdoutput, data_section,
434 applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC));
435 bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
8b13fa4e 436 seg_info (bss_section)->bss = 1;
67f3dd71
KR
437 subseg_new (BFD_ABS_SECTION_NAME, 0);
438 subseg_new (BFD_UND_SECTION_NAME, 0);
67f3dd71 439 reg_section = subseg_new ("*GAS `reg' section*", 0);
6aba9d29 440 expr_section = subseg_new ("*GAS `expr' section*", 0);
67f3dd71 441
67f3dd71 442#endif /* BFD_ASSEMBLER */
e6498b10 443
6aba9d29
JL
444 subseg_set (text_section, 0);
445
f5200318
KR
446 /* This may add symbol table entries, which requires having an open BFD,
447 and sections already created, in BFD_ASSEMBLER mode. */
448 md_begin ();
449
6efd877d
KR
450 argv++; /* skip argv[0] */
451 argc--; /* skip argv[0] */
452 while (argc--)
453 {
454 if (*argv)
455 { /* Is it a file-name argument? */
456 saw_a_file++;
457 /* argv->"" if stdin desired, else->filename */
458 read_a_source_file (*argv);
a39116f1 459 }
6efd877d
KR
460 argv++; /* completed that argv */
461 }
462 if (!saw_a_file)
463 read_a_source_file ("");
464} /* perform_an_assembly_pass() */
fecd2382 465\f
6aba9d29
JL
466#if 0
467/* This is not currently used. */
fecd2382 468static SIGTY
6efd877d
KR
469got_sig (sig)
470 int sig;
fecd2382 471{
6efd877d
KR
472 static here_before = 0;
473
474 as_bad ("Interrupted by signal %d", sig);
475 if (here_before++)
d3038350 476 exit (EXIT_FAILURE);
f5200318 477#if 0 /* If SIGTY is void, this produces warnings. */
6efd877d 478 return ((SIGTY) 0);
f5200318 479#endif
fecd2382 480}
6aba9d29 481#endif
fecd2382 482
a39116f1 483/* end of as.c */
This page took 0.126336 seconds and 4 git commands to generate.