as.h 17 KB

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