as.c revision 1.1 1 1.1 skrll /* as.c - GAS main program.
2 1.1 skrll Copyright 1987, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1.1 skrll 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 1.1 skrll Free Software Foundation, Inc.
5 1.1 skrll
6 1.1 skrll This file is part of GAS, the GNU Assembler.
7 1.1 skrll
8 1.1 skrll GAS is free software; you can redistribute it and/or modify
9 1.1 skrll it under the terms of the GNU General Public License as published by
10 1.1 skrll the Free Software Foundation; either version 3, or (at your option)
11 1.1 skrll any later version.
12 1.1 skrll
13 1.1 skrll GAS is distributed in the hope that it will be useful, but WITHOUT
14 1.1 skrll ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 1.1 skrll or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 1.1 skrll License for more details.
17 1.1 skrll
18 1.1 skrll You should have received a copy of the GNU General Public License
19 1.1 skrll along with GAS; see the file COPYING. If not, write to the Free
20 1.1 skrll Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
21 1.1 skrll 02110-1301, USA. */
22 1.1 skrll
23 1.1 skrll /* Main program for AS; a 32-bit assembler of GNU.
24 1.1 skrll Understands command arguments.
25 1.1 skrll Has a few routines that don't fit in other modules because they
26 1.1 skrll are shared.
27 1.1 skrll
28 1.1 skrll bugs
29 1.1 skrll
30 1.1 skrll : initialisers
31 1.1 skrll Since no-one else says they will support them in future: I
32 1.1 skrll don't support them now. */
33 1.1 skrll
34 1.1 skrll #define COMMON
35 1.1 skrll
36 1.1 skrll #include "as.h"
37 1.1 skrll #include "subsegs.h"
38 1.1 skrll #include "output-file.h"
39 1.1 skrll #include "sb.h"
40 1.1 skrll #include "macro.h"
41 1.1 skrll #include "dwarf2dbg.h"
42 1.1 skrll #include "dw2gencfi.h"
43 1.1 skrll #include "bfdver.h"
44 1.1 skrll
45 1.1 skrll #ifdef HAVE_ITBL_CPU
46 1.1 skrll #include "itbl-ops.h"
47 1.1 skrll #else
48 1.1 skrll #define itbl_init()
49 1.1 skrll #endif
50 1.1 skrll
51 1.1 skrll #ifdef HAVE_SBRK
52 1.1 skrll #ifdef NEED_DECLARATION_SBRK
53 1.1 skrll extern void *sbrk ();
54 1.1 skrll #endif
55 1.1 skrll #endif
56 1.1 skrll
57 1.1 skrll #ifdef USING_CGEN
58 1.1 skrll /* Perform any cgen specific initialisation for gas. */
59 1.1 skrll extern void gas_cgen_begin (void);
60 1.1 skrll #endif
61 1.1 skrll
62 1.1 skrll /* We build a list of defsyms as we read the options, and then define
63 1.1 skrll them after we have initialized everything. */
64 1.1 skrll struct defsym_list
65 1.1 skrll {
66 1.1 skrll struct defsym_list *next;
67 1.1 skrll char *name;
68 1.1 skrll valueT value;
69 1.1 skrll };
70 1.1 skrll
71 1.1 skrll
72 1.1 skrll /* True if a listing is wanted. */
73 1.1 skrll int listing;
74 1.1 skrll
75 1.1 skrll /* Type of debugging to generate. */
76 1.1 skrll enum debug_info_type debug_type = DEBUG_UNSPECIFIED;
77 1.1 skrll int use_gnu_debug_info_extensions = 0;
78 1.1 skrll
79 1.1 skrll #ifndef MD_DEBUG_FORMAT_SELECTOR
80 1.1 skrll #define MD_DEBUG_FORMAT_SELECTOR NULL
81 1.1 skrll #endif
82 1.1 skrll static enum debug_info_type (*md_debug_format_selector) (int *) = MD_DEBUG_FORMAT_SELECTOR;
83 1.1 skrll
84 1.1 skrll /* Maximum level of macro nesting. */
85 1.1 skrll int max_macro_nest = 100;
86 1.1 skrll
87 1.1 skrll /* argv[0] */
88 1.1 skrll static char * myname;
89 1.1 skrll
90 1.1 skrll /* The default obstack chunk size. If we set this to zero, the
91 1.1 skrll obstack code will use whatever will fit in a 4096 byte block. */
92 1.1 skrll int chunksize = 0;
93 1.1 skrll
94 1.1 skrll /* To monitor memory allocation more effectively, make this non-zero.
95 1.1 skrll Then the chunk sizes for gas and bfd will be reduced. */
96 1.1 skrll int debug_memory = 0;
97 1.1 skrll
98 1.1 skrll /* Enable verbose mode. */
99 1.1 skrll int verbose = 0;
100 1.1 skrll
101 1.1 skrll segT reg_section;
102 1.1 skrll segT expr_section;
103 1.1 skrll segT text_section;
104 1.1 skrll segT data_section;
105 1.1 skrll segT bss_section;
106 1.1 skrll
107 1.1 skrll /* Name of listing file. */
108 1.1 skrll static char *listing_filename = NULL;
109 1.1 skrll
110 1.1 skrll static struct defsym_list *defsyms;
111 1.1 skrll
112 1.1 skrll #ifdef HAVE_ITBL_CPU
113 1.1 skrll /* Keep a record of the itbl files we read in. */
114 1.1 skrll struct itbl_file_list
115 1.1 skrll {
116 1.1 skrll struct itbl_file_list *next;
117 1.1 skrll char *name;
118 1.1 skrll };
119 1.1 skrll static struct itbl_file_list *itbl_files;
120 1.1 skrll #endif
121 1.1 skrll
122 1.1 skrll static long start_time;
123 1.1 skrll
124 1.1 skrll static int flag_macro_alternate;
125 1.1 skrll
126 1.1 skrll
127 1.1 skrll #ifdef USE_EMULATIONS
129 1.1 skrll #define EMULATION_ENVIRON "AS_EMULATION"
130 1.1 skrll
131 1.1 skrll extern struct emulation mipsbelf, mipslelf, mipself;
132 1.1 skrll extern struct emulation mipsbecoff, mipslecoff, mipsecoff;
133 1.1 skrll extern struct emulation i386coff, i386elf, i386aout;
134 1.1 skrll extern struct emulation crisaout, criself;
135 1.1 skrll
136 1.1 skrll static struct emulation *const emulations[] = { EMULATIONS };
137 1.1 skrll static const int n_emulations = sizeof (emulations) / sizeof (emulations[0]);
138 1.1 skrll
139 1.1 skrll static void
140 1.1 skrll select_emulation_mode (int argc, char **argv)
141 1.1 skrll {
142 1.1 skrll int i;
143 1.1 skrll char *p, *em = 0;
144 1.1 skrll
145 1.1 skrll for (i = 1; i < argc; i++)
146 1.1 skrll if (!strncmp ("--em", argv[i], 4))
147 1.1 skrll break;
148 1.1 skrll
149 1.1 skrll if (i == argc)
150 1.1 skrll goto do_default;
151 1.1 skrll
152 1.1 skrll p = strchr (argv[i], '=');
153 1.1 skrll if (p)
154 1.1 skrll p++;
155 1.1 skrll else
156 1.1 skrll p = argv[i + 1];
157 1.1 skrll
158 1.1 skrll if (!p || !*p)
159 1.1 skrll as_fatal (_("missing emulation mode name"));
160 1.1 skrll em = p;
161 1.1 skrll
162 1.1 skrll do_default:
163 1.1 skrll if (em == 0)
164 1.1 skrll em = getenv (EMULATION_ENVIRON);
165 1.1 skrll if (em == 0)
166 1.1 skrll em = DEFAULT_EMULATION;
167 1.1 skrll
168 1.1 skrll if (em)
169 1.1 skrll {
170 1.1 skrll for (i = 0; i < n_emulations; i++)
171 1.1 skrll if (!strcmp (emulations[i]->name, em))
172 1.1 skrll break;
173 1.1 skrll if (i == n_emulations)
174 1.1 skrll as_fatal (_("unrecognized emulation name `%s'"), em);
175 1.1 skrll this_emulation = emulations[i];
176 1.1 skrll }
177 1.1 skrll else
178 1.1 skrll this_emulation = emulations[0];
179 1.1 skrll
180 1.1 skrll this_emulation->init ();
181 1.1 skrll }
182 1.1 skrll
183 1.1 skrll const char *
184 1.1 skrll default_emul_bfd_name (void)
185 1.1 skrll {
186 1.1 skrll abort ();
187 1.1 skrll return NULL;
188 1.1 skrll }
189 1.1 skrll
190 1.1 skrll void
191 1.1 skrll common_emul_init (void)
192 1.1 skrll {
193 1.1 skrll this_format = this_emulation->format;
194 1.1 skrll
195 1.1 skrll if (this_emulation->leading_underscore == 2)
196 1.1 skrll this_emulation->leading_underscore = this_format->dfl_leading_underscore;
197 1.1 skrll
198 1.1 skrll if (this_emulation->default_endian != 2)
199 1.1 skrll target_big_endian = this_emulation->default_endian;
200 1.1 skrll
201 1.1 skrll if (this_emulation->fake_label_name == 0)
202 1.1 skrll {
203 1.1 skrll if (this_emulation->leading_underscore)
204 1.1 skrll this_emulation->fake_label_name = "L0\001";
205 1.1 skrll else
206 1.1 skrll /* What other parameters should we test? */
207 1.1 skrll this_emulation->fake_label_name = ".L0\001";
208 1.1 skrll }
209 1.1 skrll }
210 1.1 skrll #endif
211 1.1 skrll
212 1.1 skrll void
213 1.1 skrll print_version_id (void)
214 1.1 skrll {
215 1.1 skrll static int printed;
216 1.1 skrll
217 1.1 skrll if (printed)
218 1.1 skrll return;
219 1.1 skrll printed = 1;
220 1.1 skrll
221 1.1 skrll fprintf (stderr, _("GNU assembler version %s (%s) using BFD version %s\n"),
222 1.1 skrll VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
223 1.1 skrll }
224 1.1 skrll
225 1.1 skrll static void
226 1.1 skrll show_usage (FILE * stream)
227 1.1 skrll {
228 1.1 skrll fprintf (stream, _("Usage: %s [option...] [asmfile...]\n"), myname);
229 1.1 skrll
230 1.1 skrll fprintf (stream, _("\
231 1.1 skrll Options:\n\
232 1.1 skrll -a[sub-option...] turn on listings\n\
233 1.1 skrll Sub-options [default hls]:\n\
234 1.1 skrll c omit false conditionals\n\
235 1.1 skrll d omit debugging directives\n\
236 1.1 skrll g include general info\n\
237 1.1 skrll h include high-level source\n\
238 1.1 skrll l include assembly\n\
239 1.1 skrll m include macro expansions\n\
240 1.1 skrll n omit forms processing\n\
241 1.1 skrll s include symbols\n\
242 1.1 skrll =FILE list to FILE (must be last sub-option)\n"));
243 1.1 skrll
244 1.1 skrll fprintf (stream, _("\
245 1.1 skrll --alternate initially turn on alternate macro syntax\n"));
246 1.1 skrll fprintf (stream, _("\
247 1.1 skrll -D produce assembler debugging messages\n"));
248 1.1 skrll fprintf (stream, _("\
249 1.1 skrll --debug-prefix-map OLD=NEW Map OLD to NEW in debug information\n"));
250 1.1 skrll fprintf (stream, _("\
251 1.1 skrll --defsym SYM=VAL define symbol SYM to given value\n"));
252 1.1 skrll #ifdef USE_EMULATIONS
253 1.1 skrll {
254 1.1 skrll int i;
255 1.1 skrll char *def_em;
256 1.1 skrll
257 1.1 skrll fprintf (stream, "\
258 1.1 skrll --em=[");
259 1.1 skrll for (i = 0; i < n_emulations - 1; i++)
260 1.1 skrll fprintf (stream, "%s | ", emulations[i]->name);
261 1.1 skrll fprintf (stream, "%s]\n", emulations[i]->name);
262 1.1 skrll
263 1.1 skrll def_em = getenv (EMULATION_ENVIRON);
264 1.1 skrll if (!def_em)
265 1.1 skrll def_em = DEFAULT_EMULATION;
266 1.1 skrll fprintf (stream, _("\
267 1.1 skrll emulate output (default %s)\n"), def_em);
268 1.1 skrll }
269 1.1 skrll #endif
270 1.1 skrll #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
271 1.1 skrll fprintf (stream, _("\
272 1.1 skrll --execstack require executable stack for this object\n"));
273 1.1 skrll fprintf (stream, _("\
274 1.1 skrll --noexecstack don't require executable stack for this object\n"));
275 1.1 skrll #endif
276 1.1 skrll fprintf (stream, _("\
277 1.1 skrll -f skip whitespace and comment preprocessing\n"));
278 1.1 skrll fprintf (stream, _("\
279 1.1 skrll -g --gen-debug generate debugging information\n"));
280 1.1 skrll fprintf (stream, _("\
281 1.1 skrll --gstabs generate STABS debugging information\n"));
282 1.1 skrll fprintf (stream, _("\
283 1.1 skrll --gstabs+ generate STABS debug info with GNU extensions\n"));
284 1.1 skrll fprintf (stream, _("\
285 1.1 skrll --gdwarf-2 generate DWARF2 debugging information\n"));
286 1.1 skrll fprintf (stream, _("\
287 1.1 skrll --hash-size=<value> set the hash table size close to <value>\n"));
288 1.1 skrll fprintf (stream, _("\
289 1.1 skrll --help show this message and exit\n"));
290 1.1 skrll fprintf (stream, _("\
291 1.1 skrll --target-help show target specific options\n"));
292 1.1 skrll fprintf (stream, _("\
293 1.1 skrll -I DIR add DIR to search list for .include directives\n"));
294 1.1 skrll fprintf (stream, _("\
295 1.1 skrll -J don't warn about signed overflow\n"));
296 1.1 skrll fprintf (stream, _("\
297 1.1 skrll -K warn when differences altered for long displacements\n"));
298 1.1 skrll fprintf (stream, _("\
299 1.1 skrll -L,--keep-locals keep local symbols (e.g. starting with `L')\n"));
300 1.1 skrll fprintf (stream, _("\
301 1.1 skrll -M,--mri assemble in MRI compatibility mode\n"));
302 1.1 skrll fprintf (stream, _("\
303 1.1 skrll --MD FILE write dependency information in FILE (default none)\n"));
304 1.1 skrll fprintf (stream, _("\
305 1.1 skrll -nocpp ignored\n"));
306 1.1 skrll fprintf (stream, _("\
307 1.1 skrll -o OBJFILE name the object-file output OBJFILE (default a.out)\n"));
308 1.1 skrll fprintf (stream, _("\
309 1.1 skrll -R fold data section into text section\n"));
310 1.1 skrll fprintf (stream, _("\
311 1.1 skrll --reduce-memory-overheads \n\
312 1.1 skrll prefer smaller memory use at the cost of longer\n\
313 1.1 skrll assembly times\n"));
314 1.1 skrll fprintf (stream, _("\
315 1.1 skrll --statistics print various measured statistics from execution\n"));
316 1.1 skrll fprintf (stream, _("\
317 1.1 skrll --strip-local-absolute strip local absolute symbols\n"));
318 1.1 skrll fprintf (stream, _("\
319 1.1 skrll --traditional-format Use same format as native assembler when possible\n"));
320 1.1 skrll fprintf (stream, _("\
321 1.1 skrll --version print assembler version number and exit\n"));
322 1.1 skrll fprintf (stream, _("\
323 1.1 skrll -W --no-warn suppress warnings\n"));
324 1.1 skrll fprintf (stream, _("\
325 1.1 skrll --warn don't suppress warnings\n"));
326 1.1 skrll fprintf (stream, _("\
327 1.1 skrll --fatal-warnings treat warnings as errors\n"));
328 1.1 skrll #ifdef HAVE_ITBL_CPU
329 1.1 skrll fprintf (stream, _("\
330 1.1 skrll --itbl INSTTBL extend instruction set to include instructions\n\
331 1.1 skrll matching the specifications defined in file INSTTBL\n"));
332 1.1 skrll #endif
333 1.1 skrll fprintf (stream, _("\
334 1.1 skrll -w ignored\n"));
335 1.1 skrll fprintf (stream, _("\
336 1.1 skrll -X ignored\n"));
337 1.1 skrll fprintf (stream, _("\
338 1.1 skrll -Z generate object file even after errors\n"));
339 1.1 skrll fprintf (stream, _("\
340 1.1 skrll --listing-lhs-width set the width in words of the output data column of\n\
341 1.1 skrll the listing\n"));
342 1.1 skrll fprintf (stream, _("\
343 1.1 skrll --listing-lhs-width2 set the width in words of the continuation lines\n\
344 1.1 skrll of the output data column; ignored if smaller than\n\
345 1.1 skrll the width of the first line\n"));
346 1.1 skrll fprintf (stream, _("\
347 1.1 skrll --listing-rhs-width set the max width in characters of the lines from\n\
348 1.1 skrll the source file\n"));
349 1.1 skrll fprintf (stream, _("\
350 1.1 skrll --listing-cont-lines set the maximum number of continuation lines used\n\
351 1.1 skrll for the output data column of the listing\n"));
352 1.1 skrll fprintf (stream, _("\
353 1.1 skrll @FILE read options from FILE\n"));
354 1.1 skrll
355 1.1 skrll md_show_usage (stream);
356 1.1 skrll
357 1.1 skrll fputc ('\n', stream);
358 1.1 skrll
359 1.1 skrll if (REPORT_BUGS_TO[0] && stream == stdout)
360 1.1 skrll fprintf (stream, _("Report bugs to %s\n"), REPORT_BUGS_TO);
361 1.1 skrll }
362 1.1 skrll
363 1.1 skrll /* Since it is easy to do here we interpret the special arg "-"
364 1.1 skrll to mean "use stdin" and we set that argv[] pointing to "".
365 1.1 skrll After we have munged argv[], the only things left are source file
366 1.1 skrll name(s) and ""(s) denoting stdin. These file names are used
367 1.1 skrll (perhaps more than once) later.
368 1.1 skrll
369 1.1 skrll check for new machine-dep cmdline options in
370 1.1 skrll md_parse_option definitions in config/tc-*.c. */
371 1.1 skrll
372 1.1 skrll static void
373 1.1 skrll parse_args (int * pargc, char *** pargv)
374 1.1 skrll {
375 1.1 skrll int old_argc;
376 1.1 skrll int new_argc;
377 1.1 skrll char ** old_argv;
378 1.1 skrll char ** new_argv;
379 1.1 skrll /* Starting the short option string with '-' is for programs that
380 1.1 skrll expect options and other ARGV-elements in any order and that care about
381 1.1 skrll the ordering of the two. We describe each non-option ARGV-element
382 1.1 skrll as if it were the argument of an option with character code 1. */
383 1.1 skrll char *shortopts;
384 1.1 skrll extern const char *md_shortopts;
385 1.1 skrll static const char std_shortopts[] =
386 1.1 skrll {
387 1.1 skrll '-', 'J',
388 1.1 skrll #ifndef WORKING_DOT_WORD
389 1.1 skrll /* -K is not meaningful if .word is not being hacked. */
390 1.1 skrll 'K',
391 1.1 skrll #endif
392 1.1 skrll 'L', 'M', 'R', 'W', 'Z', 'a', ':', ':', 'D', 'f', 'g', ':',':', 'I', ':', 'o', ':',
393 1.1 skrll #ifndef VMS
394 1.1 skrll /* -v takes an argument on VMS, so we don't make it a generic
395 1.1 skrll option. */
396 1.1 skrll 'v',
397 1.1 skrll #endif
398 1.1 skrll 'w', 'X',
399 1.1 skrll #ifdef HAVE_ITBL_CPU
400 1.1 skrll /* New option for extending instruction set (see also --itbl below). */
401 1.1 skrll 't', ':',
402 1.1 skrll #endif
403 1.1 skrll '\0'
404 1.1 skrll };
405 1.1 skrll struct option *longopts;
406 1.1 skrll extern struct option md_longopts[];
407 1.1 skrll extern size_t md_longopts_size;
408 1.1 skrll /* Codes used for the long options with no short synonyms. */
409 1.1 skrll enum option_values
410 1.1 skrll {
411 1.1 skrll OPTION_HELP = OPTION_STD_BASE,
412 1.1 skrll OPTION_NOCPP,
413 1.1 skrll OPTION_STATISTICS,
414 1.1 skrll OPTION_VERSION,
415 1.1 skrll OPTION_DUMPCONFIG,
416 1.1 skrll OPTION_VERBOSE,
417 1.1 skrll OPTION_EMULATION,
418 1.1 skrll OPTION_DEBUG_PREFIX_MAP,
419 1.1 skrll OPTION_DEFSYM,
420 1.1 skrll OPTION_LISTING_LHS_WIDTH,
421 1.1 skrll OPTION_LISTING_LHS_WIDTH2,
422 1.1 skrll OPTION_LISTING_RHS_WIDTH,
423 1.1 skrll OPTION_LISTING_CONT_LINES,
424 1.1 skrll OPTION_DEPFILE,
425 1.1 skrll OPTION_GSTABS,
426 1.1 skrll OPTION_GSTABS_PLUS,
427 1.1 skrll OPTION_GDWARF2,
428 1.1 skrll OPTION_STRIP_LOCAL_ABSOLUTE,
429 1.1 skrll OPTION_TRADITIONAL_FORMAT,
430 1.1 skrll OPTION_WARN,
431 1.1 skrll OPTION_TARGET_HELP,
432 1.1 skrll OPTION_EXECSTACK,
433 1.1 skrll OPTION_NOEXECSTACK,
434 1.1 skrll OPTION_ALTERNATE,
435 1.1 skrll OPTION_AL,
436 1.1 skrll OPTION_HASH_TABLE_SIZE,
437 1.1 skrll OPTION_REDUCE_MEMORY_OVERHEADS,
438 1.1 skrll OPTION_WARN_FATAL
439 1.1 skrll /* When you add options here, check that they do
440 1.1 skrll not collide with OPTION_MD_BASE. See as.h. */
441 1.1 skrll };
442 1.1 skrll
443 1.1 skrll static const struct option std_longopts[] =
444 1.1 skrll {
445 1.1 skrll /* Note: commas are placed at the start of the line rather than
446 1.1 skrll the end of the preceeding line so that it is simpler to
447 1.1 skrll selectively add and remove lines from this list. */
448 1.1 skrll {"alternate", no_argument, NULL, OPTION_ALTERNATE}
449 1.1 skrll /* The entry for "a" is here to prevent getopt_long_only() from
450 1.1 skrll considering that -a is an abbreviation for --alternate. This is
451 1.1 skrll necessary because -a=<FILE> is a valid switch but getopt would
452 1.1 skrll normally reject it since --alternate does not take an argument. */
453 1.1 skrll ,{"a", optional_argument, NULL, 'a'}
454 1.1 skrll /* Handle -al=<FILE>. */
455 1.1 skrll ,{"al", optional_argument, NULL, OPTION_AL}
456 1.1 skrll ,{"debug-prefix-map", required_argument, NULL, OPTION_DEBUG_PREFIX_MAP}
457 1.1 skrll ,{"defsym", required_argument, NULL, OPTION_DEFSYM}
458 1.1 skrll ,{"dump-config", no_argument, NULL, OPTION_DUMPCONFIG}
459 1.1 skrll ,{"emulation", required_argument, NULL, OPTION_EMULATION}
460 1.1 skrll #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
461 1.1 skrll ,{"execstack", no_argument, NULL, OPTION_EXECSTACK}
462 1.1 skrll ,{"noexecstack", no_argument, NULL, OPTION_NOEXECSTACK}
463 1.1 skrll #endif
464 1.1 skrll ,{"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}
465 1.1 skrll ,{"gdwarf-2", no_argument, NULL, OPTION_GDWARF2}
466 1.1 skrll /* GCC uses --gdwarf-2 but GAS uses to use --gdwarf2,
467 1.1 skrll so we keep it here for backwards compatibility. */
468 1.1 skrll ,{"gdwarf2", no_argument, NULL, OPTION_GDWARF2}
469 1.1 skrll ,{"gen-debug", no_argument, NULL, 'g'}
470 1.1 skrll ,{"gstabs", no_argument, NULL, OPTION_GSTABS}
471 1.1 skrll ,{"gstabs+", no_argument, NULL, OPTION_GSTABS_PLUS}
472 1.1 skrll ,{"hash-size", required_argument, NULL, OPTION_HASH_TABLE_SIZE}
473 1.1 skrll ,{"help", no_argument, NULL, OPTION_HELP}
474 1.1 skrll #ifdef HAVE_ITBL_CPU
475 1.1 skrll /* New option for extending instruction set (see also -t above).
476 1.1 skrll The "-t file" or "--itbl file" option extends the basic set of
477 1.1 skrll valid instructions by reading "file", a text file containing a
478 1.1 skrll list of instruction formats. The additional opcodes and their
479 1.1 skrll formats are added to the built-in set of instructions, and
480 1.1 skrll mnemonics for new registers may also be defined. */
481 1.1 skrll ,{"itbl", required_argument, NULL, 't'}
482 1.1 skrll #endif
483 1.1 skrll /* getopt allows abbreviations, so we do this to stop it from
484 1.1 skrll treating -k as an abbreviation for --keep-locals. Some
485 1.1 skrll ports use -k to enable PIC assembly. */
486 1.1 skrll ,{"keep-locals", no_argument, NULL, 'L'}
487 1.1 skrll ,{"keep-locals", no_argument, NULL, 'L'}
488 1.1 skrll ,{"listing-lhs-width", required_argument, NULL, OPTION_LISTING_LHS_WIDTH}
489 1.1 skrll ,{"listing-lhs-width2", required_argument, NULL, OPTION_LISTING_LHS_WIDTH2}
490 1.1 skrll ,{"listing-rhs-width", required_argument, NULL, OPTION_LISTING_RHS_WIDTH}
491 1.1 skrll ,{"listing-cont-lines", required_argument, NULL, OPTION_LISTING_CONT_LINES}
492 1.1 skrll ,{"MD", required_argument, NULL, OPTION_DEPFILE}
493 1.1 skrll ,{"mri", no_argument, NULL, 'M'}
494 1.1 skrll ,{"nocpp", no_argument, NULL, OPTION_NOCPP}
495 1.1 skrll ,{"no-warn", no_argument, NULL, 'W'}
496 1.1 skrll ,{"reduce-memory-overheads", no_argument, NULL, OPTION_REDUCE_MEMORY_OVERHEADS}
497 1.1 skrll ,{"statistics", no_argument, NULL, OPTION_STATISTICS}
498 1.1 skrll ,{"strip-local-absolute", no_argument, NULL, OPTION_STRIP_LOCAL_ABSOLUTE}
499 1.1 skrll ,{"version", no_argument, NULL, OPTION_VERSION}
500 1.1 skrll ,{"verbose", no_argument, NULL, OPTION_VERBOSE}
501 1.1 skrll ,{"target-help", no_argument, NULL, OPTION_TARGET_HELP}
502 1.1 skrll ,{"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}
503 1.1 skrll ,{"warn", no_argument, NULL, OPTION_WARN}
504 1.1 skrll };
505 1.1 skrll
506 1.1 skrll /* Construct the option lists from the standard list and the target
507 1.1 skrll dependent list. Include space for an extra NULL option and
508 1.1 skrll always NULL terminate. */
509 1.1 skrll shortopts = concat (std_shortopts, md_shortopts, (char *) NULL);
510 1.1 skrll longopts = xmalloc (sizeof (std_longopts) + md_longopts_size + sizeof (struct option));
511 1.1 skrll memcpy (longopts, std_longopts, sizeof (std_longopts));
512 1.1 skrll memcpy (((char *) longopts) + sizeof (std_longopts), md_longopts, md_longopts_size);
513 1.1 skrll memset (((char *) longopts) + sizeof (std_longopts) + md_longopts_size,
514 1.1 skrll 0, sizeof (struct option));
515 1.1 skrll
516 1.1 skrll /* Make a local copy of the old argv. */
517 1.1 skrll old_argc = *pargc;
518 1.1 skrll old_argv = *pargv;
519 1.1 skrll
520 1.1 skrll /* Initialize a new argv that contains no options. */
521 1.1 skrll new_argv = xmalloc (sizeof (char *) * (old_argc + 1));
522 1.1 skrll new_argv[0] = old_argv[0];
523 1.1 skrll new_argc = 1;
524 1.1 skrll new_argv[new_argc] = NULL;
525 1.1 skrll
526 1.1 skrll while (1)
527 1.1 skrll {
528 1.1 skrll /* getopt_long_only is like getopt_long, but '-' as well as '--' can
529 1.1 skrll indicate a long option. */
530 1.1 skrll int longind;
531 1.1 skrll int optc = getopt_long_only (old_argc, old_argv, shortopts, longopts,
532 1.1 skrll &longind);
533 1.1 skrll
534 1.1 skrll if (optc == -1)
535 1.1 skrll break;
536 1.1 skrll
537 1.1 skrll switch (optc)
538 1.1 skrll {
539 1.1 skrll default:
540 1.1 skrll /* md_parse_option should return 1 if it recognizes optc,
541 1.1 skrll 0 if not. */
542 1.1 skrll if (md_parse_option (optc, optarg) != 0)
543 1.1 skrll break;
544 1.1 skrll /* `-v' isn't included in the general short_opts list, so check for
545 1.1 skrll it explicitly here before deciding we've gotten a bad argument. */
546 1.1 skrll if (optc == 'v')
547 1.1 skrll {
548 1.1 skrll #ifdef VMS
549 1.1 skrll /* Telling getopt to treat -v's value as optional can result
550 1.1 skrll in it picking up a following filename argument here. The
551 1.1 skrll VMS code in md_parse_option can return 0 in that case,
552 1.1 skrll but it has no way of pushing the filename argument back. */
553 1.1 skrll if (optarg && *optarg)
554 1.1 skrll new_argv[new_argc++] = optarg, new_argv[new_argc] = NULL;
555 1.1 skrll else
556 1.1 skrll #else
557 1.1 skrll case 'v':
558 1.1 skrll #endif
559 1.1 skrll case OPTION_VERBOSE:
560 1.1 skrll print_version_id ();
561 1.1 skrll verbose = 1;
562 1.1 skrll break;
563 1.1 skrll }
564 1.1 skrll else
565 1.1 skrll as_bad (_("unrecognized option -%c%s"), optc, optarg ? optarg : "");
566 1.1 skrll /* Fall through. */
567 1.1 skrll
568 1.1 skrll case '?':
569 1.1 skrll exit (EXIT_FAILURE);
570 1.1 skrll
571 1.1 skrll case 1: /* File name. */
572 1.1 skrll if (!strcmp (optarg, "-"))
573 1.1 skrll optarg = "";
574 1.1 skrll new_argv[new_argc++] = optarg;
575 1.1 skrll new_argv[new_argc] = NULL;
576 1.1 skrll break;
577 1.1 skrll
578 1.1 skrll case OPTION_TARGET_HELP:
579 1.1 skrll md_show_usage (stdout);
580 1.1 skrll exit (EXIT_SUCCESS);
581 1.1 skrll
582 1.1 skrll case OPTION_HELP:
583 1.1 skrll show_usage (stdout);
584 1.1 skrll exit (EXIT_SUCCESS);
585 1.1 skrll
586 1.1 skrll case OPTION_NOCPP:
587 1.1 skrll break;
588 1.1 skrll
589 1.1 skrll case OPTION_STATISTICS:
590 1.1 skrll flag_print_statistics = 1;
591 1.1 skrll break;
592 1.1 skrll
593 1.1 skrll case OPTION_STRIP_LOCAL_ABSOLUTE:
594 1.1 skrll flag_strip_local_absolute = 1;
595 1.1 skrll break;
596 1.1 skrll
597 1.1 skrll case OPTION_TRADITIONAL_FORMAT:
598 1.1 skrll flag_traditional_format = 1;
599 1.1 skrll break;
600 1.1 skrll
601 1.1 skrll case OPTION_VERSION:
602 1.1 skrll /* This output is intended to follow the GNU standards document. */
603 1.1 skrll printf (_("GNU assembler %s\n"), BFD_VERSION_STRING);
604 1.1 skrll printf (_("Copyright 2007 Free Software Foundation, Inc.\n"));
605 1.1 skrll printf (_("\
606 1.1 skrll This program is free software; you may redistribute it under the terms of\n\
607 1.1 skrll the GNU General Public License version 3 or later.\n\
608 1.1 skrll This program has absolutely no warranty.\n"));
609 1.1 skrll printf (_("This assembler was configured for a target of `%s'.\n"),
610 1.1 skrll TARGET_ALIAS);
611 1.1 skrll exit (EXIT_SUCCESS);
612 1.1 skrll
613 1.1 skrll case OPTION_EMULATION:
614 1.1 skrll #ifdef USE_EMULATIONS
615 1.1 skrll if (strcmp (optarg, this_emulation->name))
616 1.1 skrll as_fatal (_("multiple emulation names specified"));
617 1.1 skrll #else
618 1.1 skrll as_fatal (_("emulations not handled in this configuration"));
619 1.1 skrll #endif
620 1.1 skrll break;
621 1.1 skrll
622 1.1 skrll case OPTION_DUMPCONFIG:
623 1.1 skrll fprintf (stderr, _("alias = %s\n"), TARGET_ALIAS);
624 1.1 skrll fprintf (stderr, _("canonical = %s\n"), TARGET_CANONICAL);
625 1.1 skrll fprintf (stderr, _("cpu-type = %s\n"), TARGET_CPU);
626 1.1 skrll #ifdef TARGET_OBJ_FORMAT
627 1.1 skrll fprintf (stderr, _("format = %s\n"), TARGET_OBJ_FORMAT);
628 1.1 skrll #endif
629 1.1 skrll #ifdef TARGET_FORMAT
630 1.1 skrll fprintf (stderr, _("bfd-target = %s\n"), TARGET_FORMAT);
631 1.1 skrll #endif
632 1.1 skrll exit (EXIT_SUCCESS);
633 1.1 skrll
634 1.1 skrll case OPTION_DEBUG_PREFIX_MAP:
635 1.1 skrll add_debug_prefix_map (optarg);
636 1.1 skrll break;
637 1.1 skrll
638 1.1 skrll case OPTION_DEFSYM:
639 1.1 skrll {
640 1.1 skrll char *s;
641 1.1 skrll valueT i;
642 1.1 skrll struct defsym_list *n;
643 1.1 skrll
644 1.1 skrll for (s = optarg; *s != '\0' && *s != '='; s++)
645 1.1 skrll ;
646 1.1 skrll if (*s == '\0')
647 1.1 skrll as_fatal (_("bad defsym; format is --defsym name=value"));
648 1.1 skrll *s++ = '\0';
649 1.1 skrll i = bfd_scan_vma (s, (const char **) NULL, 0);
650 1.1 skrll n = xmalloc (sizeof *n);
651 1.1 skrll n->next = defsyms;
652 1.1 skrll n->name = optarg;
653 1.1 skrll n->value = i;
654 1.1 skrll defsyms = n;
655 1.1 skrll }
656 1.1 skrll break;
657 1.1 skrll
658 1.1 skrll #ifdef HAVE_ITBL_CPU
659 1.1 skrll case 't':
660 1.1 skrll {
661 1.1 skrll /* optarg is the name of the file containing the instruction
662 1.1 skrll formats, opcodes, register names, etc. */
663 1.1 skrll struct itbl_file_list *n;
664 1.1 skrll
665 1.1 skrll if (optarg == NULL)
666 1.1 skrll {
667 1.1 skrll as_warn (_("no file name following -t option"));
668 1.1 skrll break;
669 1.1 skrll }
670 1.1 skrll
671 1.1 skrll n = xmalloc (sizeof * n);
672 1.1 skrll n->next = itbl_files;
673 1.1 skrll n->name = optarg;
674 1.1 skrll itbl_files = n;
675 1.1 skrll
676 1.1 skrll /* Parse the file and add the new instructions to our internal
677 1.1 skrll table. If multiple instruction tables are specified, the
678 1.1 skrll information from this table gets appended onto the existing
679 1.1 skrll internal table. */
680 1.1 skrll itbl_files->name = xstrdup (optarg);
681 1.1 skrll if (itbl_parse (itbl_files->name) != 0)
682 1.1 skrll as_fatal (_("failed to read instruction table %s\n"),
683 1.1 skrll itbl_files->name);
684 1.1 skrll }
685 1.1 skrll break;
686 1.1 skrll #endif
687 1.1 skrll
688 1.1 skrll case OPTION_DEPFILE:
689 1.1 skrll start_dependencies (optarg);
690 1.1 skrll break;
691 1.1 skrll
692 1.1 skrll case 'g':
693 1.1 skrll /* Some backends, eg Alpha and Mips, use the -g switch for their
694 1.1 skrll own purposes. So we check here for an explicit -g and allow
695 1.1 skrll the backend to decide if it wants to process it. */
696 1.1 skrll if ( old_argv[optind - 1][1] == 'g'
697 1.1 skrll && md_parse_option (optc, optarg))
698 1.1 skrll continue;
699 1.1 skrll
700 1.1 skrll if (md_debug_format_selector)
701 1.1 skrll debug_type = md_debug_format_selector (& use_gnu_debug_info_extensions);
702 1.1 skrll else if (IS_ELF)
703 1.1 skrll debug_type = DEBUG_DWARF2;
704 1.1 skrll else
705 1.1 skrll debug_type = DEBUG_STABS;
706 1.1 skrll break;
707 1.1 skrll
708 1.1 skrll case OPTION_GSTABS_PLUS:
709 1.1 skrll use_gnu_debug_info_extensions = 1;
710 1.1 skrll /* Fall through. */
711 1.1 skrll case OPTION_GSTABS:
712 1.1 skrll debug_type = DEBUG_STABS;
713 1.1 skrll break;
714 1.1 skrll
715 1.1 skrll case OPTION_GDWARF2:
716 1.1 skrll debug_type = DEBUG_DWARF2;
717 1.1 skrll break;
718 1.1 skrll
719 1.1 skrll case 'J':
720 1.1 skrll flag_signed_overflow_ok = 1;
721 1.1 skrll break;
722 1.1 skrll
723 1.1 skrll #ifndef WORKING_DOT_WORD
724 1.1 skrll case 'K':
725 1.1 skrll flag_warn_displacement = 1;
726 1.1 skrll break;
727 1.1 skrll #endif
728 1.1 skrll case 'L':
729 1.1 skrll flag_keep_locals = 1;
730 1.1 skrll break;
731 1.1 skrll
732 1.1 skrll case OPTION_LISTING_LHS_WIDTH:
733 1.1 skrll listing_lhs_width = atoi (optarg);
734 1.1 skrll if (listing_lhs_width_second < listing_lhs_width)
735 1.1 skrll listing_lhs_width_second = listing_lhs_width;
736 1.1 skrll break;
737 1.1 skrll case OPTION_LISTING_LHS_WIDTH2:
738 1.1 skrll {
739 1.1 skrll int tmp = atoi (optarg);
740 1.1 skrll
741 1.1 skrll if (tmp > listing_lhs_width)
742 1.1 skrll listing_lhs_width_second = tmp;
743 1.1 skrll }
744 1.1 skrll break;
745 1.1 skrll case OPTION_LISTING_RHS_WIDTH:
746 1.1 skrll listing_rhs_width = atoi (optarg);
747 1.1 skrll break;
748 1.1 skrll case OPTION_LISTING_CONT_LINES:
749 1.1 skrll listing_lhs_cont_lines = atoi (optarg);
750 1.1 skrll break;
751 1.1 skrll
752 1.1 skrll case 'M':
753 1.1 skrll flag_mri = 1;
754 1.1 skrll #ifdef TC_M68K
755 1.1 skrll flag_m68k_mri = 1;
756 1.1 skrll #endif
757 1.1 skrll break;
758 1.1 skrll
759 1.1 skrll case 'R':
760 1.1 skrll flag_readonly_data_in_text = 1;
761 1.1 skrll break;
762 1.1 skrll
763 1.1 skrll case 'W':
764 1.1 skrll flag_no_warnings = 1;
765 1.1 skrll break;
766 1.1 skrll
767 1.1 skrll case OPTION_WARN:
768 1.1 skrll flag_no_warnings = 0;
769 1.1 skrll flag_fatal_warnings = 0;
770 1.1 skrll break;
771 1.1 skrll
772 1.1 skrll case OPTION_WARN_FATAL:
773 1.1 skrll flag_no_warnings = 0;
774 1.1 skrll flag_fatal_warnings = 1;
775 1.1 skrll break;
776 1.1 skrll
777 1.1 skrll #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
778 1.1 skrll case OPTION_EXECSTACK:
779 1.1 skrll flag_execstack = 1;
780 1.1 skrll flag_noexecstack = 0;
781 1.1 skrll break;
782 1.1 skrll
783 1.1 skrll case OPTION_NOEXECSTACK:
784 1.1 skrll flag_noexecstack = 1;
785 1.1 skrll flag_execstack = 0;
786 1.1 skrll break;
787 1.1 skrll #endif
788 1.1 skrll case 'Z':
789 1.1 skrll flag_always_generate_output = 1;
790 1.1 skrll break;
791 1.1 skrll
792 1.1 skrll case OPTION_AL:
793 1.1 skrll listing |= LISTING_LISTING;
794 1.1 skrll if (optarg)
795 1.1 skrll listing_filename = xstrdup (optarg);
796 1.1 skrll break;
797 1.1 skrll
798 1.1 skrll case OPTION_ALTERNATE:
799 1.1 skrll optarg = old_argv [optind - 1];
800 1.1 skrll while (* optarg == '-')
801 1.1 skrll optarg ++;
802 1.1 skrll
803 1.1 skrll if (strcmp (optarg, "alternate") == 0)
804 1.1 skrll {
805 1.1 skrll flag_macro_alternate = 1;
806 1.1 skrll break;
807 1.1 skrll }
808 1.1 skrll optarg ++;
809 1.1 skrll /* Fall through. */
810 1.1 skrll
811 1.1 skrll case 'a':
812 1.1 skrll if (optarg)
813 1.1 skrll {
814 1.1 skrll if (optarg != old_argv[optind] && optarg[-1] == '=')
815 1.1 skrll --optarg;
816 1.1 skrll
817 1.1 skrll if (md_parse_option (optc, optarg) != 0)
818 1.1 skrll break;
819 1.1 skrll
820 1.1 skrll while (*optarg)
821 1.1 skrll {
822 1.1 skrll switch (*optarg)
823 1.1 skrll {
824 1.1 skrll case 'c':
825 1.1 skrll listing |= LISTING_NOCOND;
826 1.1 skrll break;
827 1.1 skrll case 'd':
828 1.1 skrll listing |= LISTING_NODEBUG;
829 1.1 skrll break;
830 1.1 skrll case 'g':
831 1.1 skrll listing |= LISTING_GENERAL;
832 1.1 skrll break;
833 1.1 skrll case 'h':
834 1.1 skrll listing |= LISTING_HLL;
835 1.1 skrll break;
836 1.1 skrll case 'l':
837 1.1 skrll listing |= LISTING_LISTING;
838 1.1 skrll break;
839 1.1 skrll case 'm':
840 1.1 skrll listing |= LISTING_MACEXP;
841 1.1 skrll break;
842 1.1 skrll case 'n':
843 1.1 skrll listing |= LISTING_NOFORM;
844 1.1 skrll break;
845 1.1 skrll case 's':
846 1.1 skrll listing |= LISTING_SYMBOLS;
847 1.1 skrll break;
848 1.1 skrll case '=':
849 1.1 skrll listing_filename = xstrdup (optarg + 1);
850 1.1 skrll optarg += strlen (listing_filename);
851 1.1 skrll break;
852 1.1 skrll default:
853 1.1 skrll as_fatal (_("invalid listing option `%c'"), *optarg);
854 1.1 skrll break;
855 1.1 skrll }
856 1.1 skrll optarg++;
857 1.1 skrll }
858 1.1 skrll }
859 1.1 skrll if (!listing)
860 1.1 skrll listing = LISTING_DEFAULT;
861 1.1 skrll break;
862 1.1 skrll
863 1.1 skrll case 'D':
864 1.1 skrll /* DEBUG is implemented: it debugs different
865 1.1 skrll things from other people's assemblers. */
866 1.1 skrll flag_debug = 1;
867 1.1 skrll break;
868 1.1 skrll
869 1.1 skrll case 'f':
870 1.1 skrll flag_no_comments = 1;
871 1.1 skrll break;
872 1.1 skrll
873 1.1 skrll case 'I':
874 1.1 skrll { /* Include file directory. */
875 1.1 skrll char *temp = xstrdup (optarg);
876 1.1 skrll
877 1.1 skrll add_include_dir (temp);
878 1.1 skrll break;
879 1.1 skrll }
880 1.1 skrll
881 1.1 skrll case 'o':
882 1.1 skrll out_file_name = xstrdup (optarg);
883 1.1 skrll break;
884 1.1 skrll
885 1.1 skrll case 'w':
886 1.1 skrll break;
887 1.1 skrll
888 1.1 skrll case 'X':
889 1.1 skrll /* -X means treat warnings as errors. */
890 1.1 skrll break;
891 1.1 skrll
892 1.1 skrll case OPTION_REDUCE_MEMORY_OVERHEADS:
893 1.1 skrll /* The only change we make at the moment is to reduce
894 1.1 skrll the size of the hash tables that we use. */
895 1.1 skrll set_gas_hash_table_size (4051);
896 1.1 skrll break;
897 1.1 skrll
898 1.1 skrll case OPTION_HASH_TABLE_SIZE:
899 1.1 skrll {
900 1.1 skrll unsigned long new_size;
901 1.1 skrll
902 1.1 skrll new_size = strtoul (optarg, NULL, 0);
903 1.1 skrll if (new_size)
904 1.1 skrll set_gas_hash_table_size (new_size);
905 1.1 skrll else
906 1.1 skrll as_fatal (_("--hash-size needs a numeric argument"));
907 1.1 skrll break;
908 1.1 skrll }
909 1.1 skrll }
910 1.1 skrll }
911 1.1 skrll
912 1.1 skrll free (shortopts);
913 1.1 skrll free (longopts);
914 1.1 skrll
915 1.1 skrll *pargc = new_argc;
916 1.1 skrll *pargv = new_argv;
917 1.1 skrll
918 1.1 skrll #ifdef md_after_parse_args
919 1.1 skrll md_after_parse_args ();
920 1.1 skrll #endif
921 1.1 skrll }
922 1.1 skrll
923 1.1 skrll static void
924 1.1 skrll dump_statistics (void)
925 1.1 skrll {
926 1.1 skrll #ifdef HAVE_SBRK
927 1.1 skrll char *lim = (char *) sbrk (0);
928 1.1 skrll #endif
929 1.1 skrll long run_time = get_run_time () - start_time;
930 1.1 skrll
931 1.1 skrll fprintf (stderr, _("%s: total time in assembly: %ld.%06ld\n"),
932 1.1 skrll myname, run_time / 1000000, run_time % 1000000);
933 1.1 skrll #ifdef HAVE_SBRK
934 1.1 skrll fprintf (stderr, _("%s: data size %ld\n"),
935 1.1 skrll myname, (long) (lim - (char *) &environ));
936 1.1 skrll #endif
937 1.1 skrll
938 1.1 skrll subsegs_print_statistics (stderr);
939 1.1 skrll write_print_statistics (stderr);
940 1.1 skrll symbol_print_statistics (stderr);
941 1.1 skrll read_print_statistics (stderr);
942 1.1 skrll
943 1.1 skrll #ifdef tc_print_statistics
944 1.1 skrll tc_print_statistics (stderr);
945 1.1 skrll #endif
946 1.1 skrll
947 1.1 skrll #ifdef obj_print_statistics
948 1.1 skrll obj_print_statistics (stderr);
949 1.1 skrll #endif
950 1.1 skrll }
951 1.1 skrll
952 1.1 skrll #ifndef OBJ_VMS
953 1.1 skrll static void
954 1.1 skrll close_output_file (void)
955 1.1 skrll {
956 1.1 skrll output_file_close (out_file_name);
957 1.1 skrll }
958 1.1 skrll #endif
959 1.1 skrll
960 1.1 skrll /* The interface between the macro code and gas expression handling. */
961 1.1 skrll
962 1.1 skrll static int
963 1.1 skrll macro_expr (const char *emsg, int idx, sb *in, int *val)
964 1.1 skrll {
965 1.1 skrll char *hold;
966 1.1 skrll expressionS ex;
967 1.1 skrll
968 1.1 skrll sb_terminate (in);
969 1.1 skrll
970 1.1 skrll hold = input_line_pointer;
971 1.1 skrll input_line_pointer = in->ptr + idx;
972 1.1 skrll expression_and_evaluate (&ex);
973 1.1 skrll idx = input_line_pointer - in->ptr;
974 1.1 skrll input_line_pointer = hold;
975 1.1 skrll
976 1.1 skrll if (ex.X_op != O_constant)
977 1.1 skrll as_bad ("%s", emsg);
978 1.1 skrll
979 1.1 skrll *val = (int) ex.X_add_number;
980 1.1 skrll
981 1.1 skrll return idx;
982 1.1 skrll }
983 1.1 skrll
984 1.1 skrll /* Here to attempt 1 pass over each input file.
986 1.1 skrll We scan argv[*] looking for filenames or exactly "" which is
987 1.1 skrll shorthand for stdin. Any argv that is NULL is not a file-name.
988 1.1 skrll We set need_pass_2 TRUE if, after this, we still have unresolved
989 1.1 skrll expressions of the form (unknown value)+-(unknown value).
990 1.1 skrll
991 1.1 skrll Note the un*x semantics: there is only 1 logical input file, but it
992 1.1 skrll may be a catenation of many 'physical' input files. */
993 1.1 skrll
994 1.1 skrll static void
995 1.1 skrll perform_an_assembly_pass (int argc, char ** argv)
996 1.1 skrll {
997 1.1 skrll int saw_a_file = 0;
998 1.1 skrll flagword applicable;
999 1.1 skrll
1000 1.1 skrll need_pass_2 = 0;
1001 1.1 skrll
1002 1.1 skrll /* Create the standard sections, and those the assembler uses
1003 1.1 skrll internally. */
1004 1.1 skrll text_section = subseg_new (TEXT_SECTION_NAME, 0);
1005 1.1 skrll data_section = subseg_new (DATA_SECTION_NAME, 0);
1006 1.1 skrll bss_section = subseg_new (BSS_SECTION_NAME, 0);
1007 1.1 skrll /* @@ FIXME -- we're setting the RELOC flag so that sections are assumed
1008 1.1 skrll to have relocs, otherwise we don't find out in time. */
1009 1.1 skrll applicable = bfd_applicable_section_flags (stdoutput);
1010 1.1 skrll bfd_set_section_flags (stdoutput, text_section,
1011 1.1 skrll applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1012 1.1 skrll | SEC_CODE | SEC_READONLY));
1013 1.1 skrll bfd_set_section_flags (stdoutput, data_section,
1014 1.1 skrll applicable & (SEC_ALLOC | SEC_LOAD | SEC_RELOC
1015 1.1 skrll | SEC_DATA));
1016 1.1 skrll bfd_set_section_flags (stdoutput, bss_section, applicable & SEC_ALLOC);
1017 1.1 skrll seg_info (bss_section)->bss = 1;
1018 1.1 skrll subseg_new (BFD_ABS_SECTION_NAME, 0);
1019 1.1 skrll subseg_new (BFD_UND_SECTION_NAME, 0);
1020 1.1 skrll reg_section = subseg_new ("*GAS `reg' section*", 0);
1021 1.1 skrll expr_section = subseg_new ("*GAS `expr' section*", 0);
1022 1.1 skrll
1023 1.1 skrll subseg_set (text_section, 0);
1024 1.1 skrll
1025 1.1 skrll /* This may add symbol table entries, which requires having an open BFD,
1026 1.1 skrll and sections already created. */
1027 1.1 skrll md_begin ();
1028 1.1 skrll
1029 1.1 skrll #ifdef USING_CGEN
1030 1.1 skrll gas_cgen_begin ();
1031 1.1 skrll #endif
1032 1.1 skrll #ifdef obj_begin
1033 1.1 skrll obj_begin ();
1034 1.1 skrll #endif
1035 1.1 skrll
1036 1.1 skrll /* Skip argv[0]. */
1037 1.1 skrll argv++;
1038 1.1 skrll argc--;
1039 1.1 skrll
1040 1.1 skrll while (argc--)
1041 1.1 skrll {
1042 1.1 skrll if (*argv)
1043 1.1 skrll { /* Is it a file-name argument? */
1044 1.1 skrll PROGRESS (1);
1045 1.1 skrll saw_a_file++;
1046 1.1 skrll /* argv->"" if stdin desired, else->filename. */
1047 1.1 skrll read_a_source_file (*argv);
1048 1.1 skrll }
1049 1.1 skrll argv++; /* Completed that argv. */
1050 1.1 skrll }
1051 1.1 skrll if (!saw_a_file)
1052 1.1 skrll read_a_source_file ("");
1053 1.1 skrll }
1054 1.1 skrll
1055 1.1 skrll #ifdef OBJ_ELF
1057 1.1 skrll static void
1058 1.1 skrll create_obj_attrs_section (void)
1059 1.1 skrll {
1060 1.1 skrll segT s;
1061 1.1 skrll char *p;
1062 1.1 skrll addressT addr;
1063 1.1 skrll offsetT size;
1064 1.1 skrll const char *name;
1065 1.1 skrll
1066 1.1 skrll size = bfd_elf_obj_attr_size (stdoutput);
1067 1.1 skrll if (size)
1068 1.1 skrll {
1069 1.1 skrll name = get_elf_backend_data (stdoutput)->obj_attrs_section;
1070 1.1 skrll if (!name)
1071 1.1 skrll name = ".gnu.attributes";
1072 1.1 skrll s = subseg_new (name, 0);
1073 1.1 skrll elf_section_type (s)
1074 1.1 skrll = get_elf_backend_data (stdoutput)->obj_attrs_section_type;
1075 1.1 skrll bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
1076 1.1 skrll addr = frag_now_fix ();
1077 1.1 skrll p = frag_more (size);
1078 1.1 skrll bfd_elf_set_obj_attr_contents (stdoutput, (bfd_byte *)p, size);
1079 1.1 skrll }
1080 1.1 skrll }
1081 1.1 skrll #endif
1082 1.1 skrll
1083 1.1 skrll
1085 1.1 skrll int
1086 1.1 skrll main (int argc, char ** argv)
1087 1.1 skrll {
1088 1.1 skrll char ** argv_orig = argv;
1089 1.1 skrll
1090 1.1 skrll int macro_strip_at;
1091 1.1 skrll int keep_it;
1092 1.1 skrll
1093 1.1 skrll start_time = get_run_time ();
1094 1.1 skrll
1095 1.1 skrll #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
1096 1.1 skrll setlocale (LC_MESSAGES, "");
1097 1.1 skrll #endif
1098 1.1 skrll #if defined (HAVE_SETLOCALE)
1099 1.1 skrll setlocale (LC_CTYPE, "");
1100 1.1 skrll #endif
1101 1.1 skrll bindtextdomain (PACKAGE, LOCALEDIR);
1102 1.1 skrll textdomain (PACKAGE);
1103 1.1 skrll
1104 1.1 skrll if (debug_memory)
1105 1.1 skrll chunksize = 64;
1106 1.1 skrll
1107 1.1 skrll #ifdef HOST_SPECIAL_INIT
1108 1.1 skrll HOST_SPECIAL_INIT (argc, argv);
1109 1.1 skrll #endif
1110 1.1 skrll
1111 1.1 skrll myname = argv[0];
1112 1.1 skrll xmalloc_set_program_name (myname);
1113 1.1 skrll
1114 1.1 skrll expandargv (&argc, &argv);
1115 1.1 skrll
1116 1.1 skrll START_PROGRESS (myname, 0);
1117 1.1 skrll
1118 1.1 skrll #ifndef OBJ_DEFAULT_OUTPUT_FILE_NAME
1119 1.1 skrll #define OBJ_DEFAULT_OUTPUT_FILE_NAME "a.out"
1120 1.1 skrll #endif
1121 1.1 skrll
1122 1.1 skrll out_file_name = OBJ_DEFAULT_OUTPUT_FILE_NAME;
1123 1.1 skrll
1124 1.1 skrll hex_init ();
1125 1.1 skrll bfd_init ();
1126 1.1 skrll bfd_set_error_program_name (myname);
1127 1.1 skrll
1128 1.1 skrll #ifdef USE_EMULATIONS
1129 1.1 skrll select_emulation_mode (argc, argv);
1130 1.1 skrll #endif
1131 1.1 skrll
1132 1.1 skrll PROGRESS (1);
1133 1.1 skrll /* Call parse_args before any of the init/begin functions
1134 1.1 skrll so that switches like --hash-size can be honored. */
1135 1.1 skrll parse_args (&argc, &argv);
1136 1.1 skrll symbol_begin ();
1137 1.1 skrll frag_init ();
1138 1.1 skrll subsegs_begin ();
1139 1.1 skrll read_begin ();
1140 1.1 skrll input_scrub_begin ();
1141 1.1 skrll expr_begin ();
1142 1.1 skrll
1143 1.1 skrll #ifndef OBJ_VMS /* Does its own file handling. */
1144 1.1 skrll /* It has to be called after dump_statistics (). */
1145 1.1 skrll xatexit (close_output_file);
1146 1.1 skrll #endif
1147 1.1 skrll
1148 1.1 skrll if (flag_print_statistics)
1149 1.1 skrll xatexit (dump_statistics);
1150 1.1 skrll
1151 1.1 skrll macro_strip_at = 0;
1152 1.1 skrll #ifdef TC_I960
1153 1.1 skrll macro_strip_at = flag_mri;
1154 1.1 skrll #endif
1155 1.1 skrll
1156 1.1 skrll macro_init (flag_macro_alternate, flag_mri, macro_strip_at, macro_expr);
1157 1.1 skrll
1158 1.1 skrll PROGRESS (1);
1159 1.1 skrll
1160 1.1 skrll output_file_create (out_file_name);
1161 1.1 skrll assert (stdoutput != 0);
1162 1.1 skrll
1163 1.1 skrll #ifdef tc_init_after_args
1164 1.1 skrll tc_init_after_args ();
1165 1.1 skrll #endif
1166 1.1 skrll
1167 1.1 skrll itbl_init ();
1168 1.1 skrll
1169 1.1 skrll /* Now that we have fully initialized, and have created the output
1170 1.1 skrll file, define any symbols requested by --defsym command line
1171 1.1 skrll arguments. */
1172 1.1 skrll while (defsyms != NULL)
1173 1.1 skrll {
1174 1.1 skrll symbolS *sym;
1175 1.1 skrll struct defsym_list *next;
1176 1.1 skrll
1177 1.1 skrll sym = symbol_new (defsyms->name, absolute_section, defsyms->value,
1178 1.1 skrll &zero_address_frag);
1179 1.1 skrll /* Make symbols defined on the command line volatile, so that they
1180 1.1 skrll can be redefined inside a source file. This makes this assembler's
1181 1.1 skrll behaviour compatible with earlier versions, but it may not be
1182 1.1 skrll completely intuitive. */
1183 1.1 skrll S_SET_VOLATILE (sym);
1184 1.1 skrll symbol_table_insert (sym);
1185 1.1 skrll next = defsyms->next;
1186 1.1 skrll free (defsyms);
1187 1.1 skrll defsyms = next;
1188 1.1 skrll }
1189 1.1 skrll
1190 1.1 skrll PROGRESS (1);
1191 1.1 skrll
1192 1.1 skrll /* Assemble it. */
1193 1.1 skrll perform_an_assembly_pass (argc, argv);
1194 1.1 skrll
1195 1.1 skrll cond_finish_check (-1);
1196 1.1 skrll
1197 1.1 skrll #ifdef md_end
1198 1.1 skrll md_end ();
1199 1.1 skrll #endif
1200 1.1 skrll
1201 1.1 skrll #ifdef OBJ_ELF
1202 1.1 skrll if (IS_ELF)
1203 1.1 skrll create_obj_attrs_section ();
1204 1.1 skrll #endif
1205 1.1 skrll
1206 1.1 skrll #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
1207 1.1 skrll if ((flag_execstack || flag_noexecstack)
1208 1.1 skrll && OUTPUT_FLAVOR == bfd_target_elf_flavour)
1209 1.1 skrll {
1210 1.1 skrll segT gnustack;
1211 1.1 skrll
1212 1.1 skrll gnustack = subseg_new (".note.GNU-stack", 0);
1213 1.1 skrll bfd_set_section_flags (stdoutput, gnustack,
1214 1.1 skrll SEC_READONLY | (flag_execstack ? SEC_CODE : 0));
1215 1.1 skrll
1216 1.1 skrll }
1217 1.1 skrll #endif
1218 1.1 skrll
1219 1.1 skrll /* If we've been collecting dwarf2 .debug_line info, either for
1220 1.1 skrll assembly debugging or on behalf of the compiler, emit it now. */
1221 1.1 skrll dwarf2_finish ();
1222 1.1 skrll
1223 1.1 skrll /* If we constructed dwarf2 .eh_frame info, either via .cfi
1224 1.1 skrll directives from the user or by the backend, emit it now. */
1225 1.1 skrll cfi_finish ();
1226 1.1 skrll
1227 1.1 skrll if (seen_at_least_1_file ()
1228 1.1 skrll && (flag_always_generate_output || had_errors () == 0))
1229 1.1 skrll keep_it = 1;
1230 1.1 skrll else
1231 1.1 skrll keep_it = 0;
1232 1.1 skrll
1233 1.1 skrll /* This used to be done at the start of write_object_file in
1234 1.1 skrll write.c, but that caused problems when doing listings when
1235 1.1 skrll keep_it was zero. This could probably be moved above md_end, but
1236 1.1 skrll I didn't want to risk the change. */
1237 1.1 skrll subsegs_finish ();
1238 1.1 skrll
1239 1.1 skrll if (keep_it)
1240 1.1 skrll write_object_file ();
1241 1.1 skrll
1242 1.1 skrll fflush (stderr);
1243 1.1 skrll
1244 1.1 skrll #ifndef NO_LISTING
1245 1.1 skrll listing_print (listing_filename, argv_orig);
1246 1.1 skrll #endif
1247 1.1 skrll
1248 1.1 skrll if (flag_fatal_warnings && had_warnings () > 0 && had_errors () == 0)
1249 1.1 skrll as_bad (_("%d warnings, treating warnings as errors"), had_warnings ());
1250 1.1 skrll
1251 1.1 skrll if (had_errors () > 0 && ! flag_always_generate_output)
1252 1.1 skrll keep_it = 0;
1253 1.1 skrll
1254 1.1 skrll if (!keep_it)
1255 1.1 skrll unlink_if_ordinary (out_file_name);
1256 1.1 skrll
1257 1.1 skrll input_scrub_end ();
1258 1.1 skrll
1259 1.1 skrll END_PROGRESS (myname);
1260 1.1 skrll
1261 1.1 skrll /* Use xexit instead of return, because under VMS environments they
1262 1.1 skrll may not place the same interpretation on the value given. */
1263 1.1 skrll if (had_errors () > 0)
1264 1.1 skrll xexit (EXIT_FAILURE);
1265 1.1 skrll
1266 1.1 skrll /* Only generate dependency file if assembler was successful. */
1267 print_dependencies ();
1268
1269 xexit (EXIT_SUCCESS);
1270 }
1271