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