as.c 37 KB

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