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