as.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* as.h - global header file
  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. #ifndef GAS
  17. #define GAS 1
  18. /* I think this stuff is largely out of date. xoxorich.
  19. CAPITALISED names are #defined.
  20. "lowercaseH" is #defined if "lowercase.h" has been #include-d.
  21. "lowercaseT" is a typedef of "lowercase" objects.
  22. "lowercaseP" is type "pointer to object of type 'lowercase'".
  23. "lowercaseS" is typedef struct ... lowercaseS.
  24. #define DEBUG to enable all the "know" assertion tests.
  25. #define SUSPECT when debugging hash code.
  26. #define COMMON as "extern" for all modules except one, where you #define
  27. COMMON as "".
  28. If TEST is #defined, then we are testing a module: #define COMMON as "". */
  29. #include "alloca-conf.h"
  30. /* Now, tend to the rest of the configuration. */
  31. /* System include files first... */
  32. #include <stdio.h>
  33. #ifdef STRING_WITH_STRINGS
  34. #include <string.h>
  35. #include <strings.h>
  36. #else
  37. #ifdef HAVE_STRING_H
  38. #include <string.h>
  39. #else
  40. #ifdef HAVE_STRINGS_H
  41. #include <strings.h>
  42. #endif
  43. #endif
  44. #endif
  45. #ifdef HAVE_STDLIB_H
  46. #include <stdlib.h>
  47. #endif
  48. #ifdef HAVE_UNISTD_H
  49. #include <unistd.h>
  50. #endif
  51. #ifdef HAVE_SYS_TYPES_H
  52. /* for size_t, pid_t */
  53. #include <sys/types.h>
  54. #endif
  55. #ifdef HAVE_ERRNO_H
  56. #include <errno.h>
  57. #endif
  58. #include <stdarg.h>
  59. #include "getopt.h"
  60. /* The first getopt value for machine-independent long options.
  61. 150 isn't special; it's just an arbitrary non-ASCII char value. */
  62. #define OPTION_STD_BASE 150
  63. /* The first getopt value for machine-dependent long options.
  64. 190 gives the standard options room to grow. */
  65. #define OPTION_MD_BASE 190
  66. #ifdef DEBUG
  67. #undef NDEBUG
  68. #endif
  69. #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
  70. #define __PRETTY_FUNCTION__ ((char *) NULL)
  71. #endif
  72. #define gas_assert(P) \
  73. ((void) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0)))
  74. #undef abort
  75. #define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
  76. /* Now GNU header files... */
  77. #include "ansidecl.h"
  78. #include "bfd.h"
  79. #include "libiberty.h"
  80. /* Define the standard progress macros. */
  81. #include "progress.h"
  82. /* This doesn't get taken care of anywhere. */
  83. #ifndef __MWERKS__ /* Metrowerks C chokes on the "defined (inline)" */
  84. #if !defined (__GNUC__) && !defined (inline)
  85. #define inline
  86. #endif
  87. #endif /* !__MWERKS__ */
  88. /* Other stuff from config.h. */
  89. #ifdef NEED_DECLARATION_ENVIRON
  90. extern char **environ;
  91. #endif
  92. #ifdef NEED_DECLARATION_ERRNO
  93. extern int errno;
  94. #endif
  95. #ifdef NEED_DECLARATION_FFS
  96. extern int ffs (int);
  97. #endif
  98. #ifdef NEED_DECLARATION_FREE
  99. extern void free ();
  100. #endif
  101. #ifdef NEED_DECLARATION_MALLOC
  102. extern void *malloc ();
  103. extern void *realloc ();
  104. #endif
  105. #ifdef NEED_DECLARATION_STRSTR
  106. extern char *strstr ();
  107. #endif
  108. #if !HAVE_DECL_MEMPCPY
  109. void *mempcpy(void *, const void *, size_t);
  110. #endif
  111. #if !HAVE_DECL_VSNPRINTF
  112. extern int vsnprintf(char *, size_t, const char *, va_list);
  113. #endif
  114. /* This is needed for VMS. */
  115. #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
  116. #define unlink remove
  117. #endif
  118. /* Hack to make "gcc -Wall" not complain about obstack macros. */
  119. #if !defined (memcpy) && !defined (bcopy)
  120. #define bcopy(src,dest,size) memcpy (dest, src, size)
  121. #endif
  122. /* Make Saber happier on obstack.h. */
  123. #ifdef SABER
  124. #undef __PTR_TO_INT
  125. #define __PTR_TO_INT(P) ((int) (P))
  126. #undef __INT_TO_PTR
  127. #define __INT_TO_PTR(P) ((char *) (P))
  128. #endif
  129. #ifndef __LINE__
  130. #define __LINE__ "unknown"
  131. #endif /* __LINE__ */
  132. #ifndef __FILE__
  133. #define __FILE__ "unknown"
  134. #endif /* __FILE__ */
  135. #ifndef FOPEN_WB
  136. #ifdef USE_BINARY_FOPEN
  137. #include "fopen-bin.h"
  138. #else
  139. #include "fopen-same.h"
  140. #endif
  141. #endif
  142. #ifndef EXIT_SUCCESS
  143. #define EXIT_SUCCESS 0
  144. #define EXIT_FAILURE 1
  145. #endif
  146. #ifndef SEEK_SET
  147. #define SEEK_SET 0
  148. #endif
  149. #define obstack_chunk_alloc xmalloc
  150. #define obstack_chunk_free xfree
  151. #define xfree free
  152. #include "asintl.h"
  153. #define BAD_CASE(val) \
  154. { \
  155. as_fatal (_("Case value %ld unexpected at line %d of file \"%s\"\n"), \
  156. (long) val, __LINE__, __FILE__); \
  157. }
  158. #include "flonum.h"
  159. /* These are assembler-wide concepts */
  160. extern bfd *stdoutput;
  161. typedef bfd_vma addressT;
  162. typedef bfd_signed_vma offsetT;
  163. /* Type of symbol value, etc. For use in prototypes. */
  164. typedef addressT valueT;
  165. #ifndef COMMON
  166. #ifdef TEST
  167. #define COMMON /* Declare our COMMONs storage here. */
  168. #else
  169. #define COMMON extern /* Our commons live elsewhere. */
  170. #endif
  171. #endif
  172. /* COMMON now defined */
  173. #ifndef ENABLE_CHECKING
  174. #define ENABLE_CHECKING 0
  175. #endif
  176. #if ENABLE_CHECKING || defined (DEBUG)
  177. #ifndef know
  178. #define know(p) gas_assert(p) /* Verify our assumptions! */
  179. #endif /* not yet defined */
  180. #else
  181. #define know(p) do {} while (0) /* know() checks are no-op.ed */
  182. #endif
  183. /* input_scrub.c */
  184. /* Supplies sanitised buffers to read.c.
  185. Also understands printing line-number part of error messages. */
  186. /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
  187. typedef asection *segT;
  188. #define SEG_NORMAL(SEG) ( (SEG) != absolute_section \
  189. && (SEG) != undefined_section \
  190. && (SEG) != reg_section \
  191. && (SEG) != expr_section)
  192. typedef int subsegT;
  193. /* What subseg we are accessing now? */
  194. COMMON subsegT now_subseg;
  195. /* Segment our instructions emit to. */
  196. COMMON segT now_seg;
  197. #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
  198. extern segT reg_section, expr_section;
  199. /* Shouldn't these be eliminated someday? */
  200. extern segT text_section, data_section, bss_section;
  201. #define absolute_section bfd_abs_section_ptr
  202. #define undefined_section bfd_und_section_ptr
  203. enum _relax_state
  204. {
  205. /* Dummy frag used by listing code. */
  206. rs_dummy = 0,
  207. /* Variable chars to be repeated fr_offset times.
  208. Fr_symbol unused. Used with fr_offset == 0 for a
  209. constant length frag. */
  210. rs_fill,
  211. /* Align. The fr_offset field holds the power of 2 to which to
  212. align. The fr_var field holds the number of characters in the
  213. fill pattern. The fr_subtype field holds the maximum number of
  214. bytes to skip when aligning, or 0 if there is no maximum. */
  215. rs_align,
  216. /* Align code. The fr_offset field holds the power of 2 to which
  217. to align. This type is only generated by machine specific
  218. code, which is normally responsible for handling the fill
  219. pattern. The fr_subtype field holds the maximum number of
  220. bytes to skip when aligning, or 0 if there is no maximum. */
  221. rs_align_code,
  222. /* Test for alignment. Like rs_align, but used by several targets
  223. to warn if data is not properly aligned. */
  224. rs_align_test,
  225. /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
  226. character. */
  227. rs_org,
  228. #ifndef WORKING_DOT_WORD
  229. /* JF: gunpoint */
  230. rs_broken_word,
  231. #endif
  232. /* Machine specific relaxable (or similarly alterable) instruction. */
  233. rs_machine_dependent,
  234. /* .space directive with expression operand that needs to be computed
  235. later. Similar to rs_org, but different.
  236. fr_symbol: operand
  237. 1 variable char: fill character */
  238. rs_space,
  239. /* A DWARF leb128 value; only ELF uses this. The subtype is 0 for
  240. unsigned, 1 for signed. */
  241. rs_leb128,
  242. /* Exception frame information which we may be able to optimize. */
  243. rs_cfa,
  244. /* Cross-fragment dwarf2 line number optimization. */
  245. rs_dwarf2dbg
  246. };
  247. typedef enum _relax_state relax_stateT;
  248. /* This type is used in prototypes, so it can't be a type that will be
  249. widened for argument passing. */
  250. typedef unsigned int relax_substateT;
  251. /* Enough bits for address, but still an integer type.
  252. Could be a problem, cross-assembling for 64-bit machines. */
  253. typedef addressT relax_addressT;
  254. struct relax_type
  255. {
  256. /* Forward reach. Signed number. > 0. */
  257. offsetT rlx_forward;
  258. /* Backward reach. Signed number. < 0. */
  259. offsetT rlx_backward;
  260. /* Bytes length of this address. */
  261. unsigned char rlx_length;
  262. /* Next longer relax-state. 0 means there is no 'next' relax-state. */
  263. relax_substateT rlx_more;
  264. };
  265. typedef struct relax_type relax_typeS;
  266. /* main program "as.c" (command arguments etc). */
  267. COMMON unsigned char flag_no_comments; /* -f */
  268. COMMON unsigned char flag_debug; /* -D */
  269. COMMON unsigned char flag_signed_overflow_ok; /* -J */
  270. #ifndef WORKING_DOT_WORD
  271. COMMON unsigned char flag_warn_displacement; /* -K */
  272. #endif
  273. /* True if local symbols should be retained. */
  274. COMMON int flag_keep_locals; /* -L */
  275. /* True if we are assembling in MRI mode. */
  276. COMMON int flag_mri;
  277. /* Should the data section be made read-only and appended to the text
  278. section? */
  279. COMMON unsigned char flag_readonly_data_in_text; /* -R */
  280. /* True if warnings should be inhibited. */
  281. COMMON int flag_no_warnings; /* -W */
  282. /* True if warnings count as errors. */
  283. COMMON int flag_fatal_warnings; /* --fatal-warnings */
  284. /* True if we should attempt to generate output even if non-fatal errors
  285. are detected. */
  286. COMMON unsigned char flag_always_generate_output; /* -Z */
  287. /* This is true if the assembler should output time and space usage. */
  288. COMMON unsigned char flag_print_statistics;
  289. /* True if local absolute symbols are to be stripped. */
  290. COMMON int flag_strip_local_absolute;
  291. /* True if we should generate a traditional format object file. */
  292. COMMON int flag_traditional_format;
  293. /* Type of compressed debug sections we should generate. */
  294. COMMON enum compressed_debug_section_type flag_compress_debug;
  295. /* TRUE if .note.GNU-stack section with SEC_CODE should be created */
  296. COMMON int flag_execstack;
  297. /* TRUE if .note.GNU-stack section with SEC_CODE should be created */
  298. COMMON int flag_noexecstack;
  299. /* name of emitted object file */
  300. COMMON char *out_file_name;
  301. /* name of file defining extensions to the basic instruction set */
  302. COMMON char *insttbl_file_name;
  303. /* TRUE if we need a second pass. */
  304. COMMON int need_pass_2;
  305. /* TRUE if we should do no relaxing, and
  306. leave lots of padding. */
  307. COMMON int linkrelax;
  308. /* TRUE if we should produce a listing. */
  309. extern int listing;
  310. /* Type of debugging information we should generate. We currently support
  311. stabs, ECOFF, and DWARF2.
  312. NOTE! This means debug information about the assembly source code itself
  313. and _not_ about possible debug information from a high-level language.
  314. This is especially relevant to DWARF2, since the compiler may emit line
  315. number directives that the assembler resolves. */
  316. enum debug_info_type
  317. {
  318. DEBUG_UNSPECIFIED,
  319. DEBUG_NONE,
  320. DEBUG_STABS,
  321. DEBUG_ECOFF,
  322. DEBUG_DWARF,
  323. DEBUG_DWARF2
  324. };
  325. extern enum debug_info_type debug_type;
  326. extern int use_gnu_debug_info_extensions;
  327. COMMON bfd_boolean flag_dwarf_sections;
  328. /* Maximum level of macro nesting. */
  329. extern int max_macro_nest;
  330. /* Verbosity level. */
  331. extern int verbose;
  332. /* Obstack chunk size. Keep large for efficient space use, make small to
  333. increase malloc calls for monitoring memory allocation. */
  334. extern int chunksize;
  335. struct _pseudo_type
  336. {
  337. /* assembler mnemonic, lower case, no '.' */
  338. const char *poc_name;
  339. /* Do the work */
  340. void (*poc_handler) (int);
  341. /* Value to pass to handler */
  342. int poc_val;
  343. };
  344. typedef struct _pseudo_type pseudo_typeS;
  345. #if (__GNUC__ >= 2) && !defined(VMS)
  346. /* for use with -Wformat */
  347. #if __GNUC__ == 2 && __GNUC_MINOR__ < 6
  348. /* Support for double underscores in attribute names was added in gcc
  349. 2.6, so avoid them if we are using an earlier version. */
  350. #define __printf__ printf
  351. #define __format__ format
  352. #endif
  353. #define PRINTF_LIKE(FCN) \
  354. void FCN (const char *format, ...) \
  355. __attribute__ ((__format__ (__printf__, 1, 2)))
  356. #define PRINTF_WHERE_LIKE(FCN) \
  357. void FCN (char *file, unsigned int line, const char *format, ...) \
  358. __attribute__ ((__format__ (__printf__, 3, 4)))
  359. #else /* __GNUC__ < 2 || defined(VMS) */
  360. #define PRINTF_LIKE(FCN) void FCN (const char *format, ...)
  361. #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, \
  362. unsigned int line, \
  363. const char *format, ...)
  364. #endif /* __GNUC__ < 2 || defined(VMS) */
  365. PRINTF_LIKE (as_bad);
  366. PRINTF_LIKE (as_fatal) ATTRIBUTE_NORETURN;
  367. PRINTF_LIKE (as_tsktsk);
  368. PRINTF_LIKE (as_warn);
  369. PRINTF_WHERE_LIKE (as_bad_where);
  370. PRINTF_WHERE_LIKE (as_warn_where);
  371. void as_assert (const char *, int, const char *);
  372. void as_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
  373. void sprint_value (char *, addressT);
  374. int had_errors (void);
  375. int had_warnings (void);
  376. void as_warn_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, unsigned);
  377. void as_bad_value_out_of_range (char *, offsetT, offsetT, offsetT, char *, unsigned);
  378. void print_version_id (void);
  379. char * app_push (void);
  380. char * atof_ieee (char *, int, LITTLENUM_TYPE *);
  381. char * ieee_md_atof (int, char *, int *, bfd_boolean);
  382. char * vax_md_atof (int, char *, int *);
  383. char * input_scrub_include_file (char *, char *);
  384. void input_scrub_insert_line (const char *);
  385. void input_scrub_insert_file (char *);
  386. char * input_scrub_new_file (char *);
  387. char * input_scrub_next_buffer (char **bufp);
  388. size_t do_scrub_chars (size_t (*get) (char *, size_t), char *, size_t);
  389. int gen_to_words (LITTLENUM_TYPE *, int, long);
  390. int had_err (void);
  391. int ignore_input (void);
  392. void cond_finish_check (int);
  393. void cond_exit_macro (int);
  394. int seen_at_least_1_file (void);
  395. void app_pop (char *);
  396. void as_where (char **, unsigned int *);
  397. void bump_line_counters (void);
  398. void do_scrub_begin (int);
  399. void input_scrub_begin (void);
  400. void input_scrub_close (void);
  401. void input_scrub_end (void);
  402. int new_logical_line (char *, int);
  403. int new_logical_line_flags (char *, int, int);
  404. void subsegs_begin (void);
  405. void subseg_change (segT, int);
  406. segT subseg_new (const char *, subsegT);
  407. segT subseg_force_new (const char *, subsegT);
  408. void subseg_set (segT, subsegT);
  409. int subseg_text_p (segT);
  410. int seg_not_empty_p (segT);
  411. void start_dependencies (char *);
  412. void register_dependency (char *);
  413. void print_dependencies (void);
  414. segT subseg_get (const char *, int);
  415. const char *remap_debug_filename (const char *);
  416. void add_debug_prefix_map (const char *);
  417. struct expressionS;
  418. struct fix;
  419. typedef struct symbol symbolS;
  420. typedef struct frag fragS;
  421. /* literal.c */
  422. valueT add_to_literal_pool (symbolS *, valueT, segT, int);
  423. int check_eh_frame (struct expressionS *, unsigned int *);
  424. int eh_frame_estimate_size_before_relax (fragS *);
  425. int eh_frame_relax_frag (fragS *);
  426. void eh_frame_convert_frag (fragS *);
  427. int generic_force_reloc (struct fix *);
  428. #include "expr.h" /* Before targ-*.h */
  429. /* This one starts the chain of target dependant headers. */
  430. #include "targ-env.h"
  431. #ifdef OBJ_MAYBE_ELF
  432. #define IS_ELF (OUTPUT_FLAVOR == bfd_target_elf_flavour)
  433. #else
  434. #ifdef OBJ_ELF
  435. #define IS_ELF 1
  436. #else
  437. #define IS_ELF 0
  438. #endif
  439. #endif
  440. #include "write.h"
  441. #include "frags.h"
  442. #include "hash.h"
  443. #include "read.h"
  444. #include "symbols.h"
  445. #include "tc.h"
  446. #include "obj.h"
  447. #ifdef USE_EMULATIONS
  448. #include "emul.h"
  449. #endif
  450. #include "listing.h"
  451. #ifdef H_TICK_HEX
  452. extern int enable_h_tick_hex;
  453. #endif
  454. #ifdef TC_M68K
  455. /* True if we are assembling in m68k MRI mode. */
  456. COMMON int flag_m68k_mri;
  457. #define DOLLAR_AMBIGU flag_m68k_mri
  458. #else
  459. #define flag_m68k_mri 0
  460. #endif
  461. #ifdef WARN_COMMENTS
  462. COMMON int warn_comment;
  463. COMMON unsigned int found_comment;
  464. COMMON char * found_comment_file;
  465. #endif
  466. #if defined OBJ_ELF || defined OBJ_MAYBE_ELF
  467. /* If .size directive failure should be error or warning. */
  468. COMMON enum
  469. {
  470. size_check_error = 0,
  471. size_check_warning
  472. }
  473. flag_size_check;
  474. /* If section name substitution sequences should be honored */
  475. COMMON int flag_sectname_subst;
  476. #endif
  477. #ifndef DOLLAR_AMBIGU
  478. #define DOLLAR_AMBIGU 0
  479. #endif
  480. #ifndef NUMBERS_WITH_SUFFIX
  481. #define NUMBERS_WITH_SUFFIX 0
  482. #endif
  483. #ifndef LOCAL_LABELS_DOLLAR
  484. #define LOCAL_LABELS_DOLLAR 0
  485. #endif
  486. #ifndef LOCAL_LABELS_FB
  487. #define LOCAL_LABELS_FB 0
  488. #endif
  489. #ifndef LABELS_WITHOUT_COLONS
  490. #define LABELS_WITHOUT_COLONS 0
  491. #endif
  492. #ifndef NO_PSEUDO_DOT
  493. #define NO_PSEUDO_DOT 0
  494. #endif
  495. #ifndef TEXT_SECTION_NAME
  496. #define TEXT_SECTION_NAME ".text"
  497. #define DATA_SECTION_NAME ".data"
  498. #define BSS_SECTION_NAME ".bss"
  499. #endif
  500. #ifndef OCTETS_PER_BYTE_POWER
  501. #define OCTETS_PER_BYTE_POWER 0
  502. #endif
  503. #ifndef OCTETS_PER_BYTE
  504. #define OCTETS_PER_BYTE (1<<OCTETS_PER_BYTE_POWER)
  505. #endif
  506. #if OCTETS_PER_BYTE != (1<<OCTETS_PER_BYTE_POWER)
  507. #error "Octets per byte conflicts with its power-of-two definition!"
  508. #endif
  509. #endif /* GAS */