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