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