Home | History | Annotate | Download | only in gas
      1 /* struct_symbol.h - Internal symbol structure
      2    Copyright (C) 1987-2016 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,
     12    but WITHOUT ANY WARRANTY; without even the implied warranty of
     13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     14    GNU General Public 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 __struc_symbol_h__
     22 #define __struc_symbol_h__
     23 
     24 struct symbol_flags
     25 {
     26   /* Wether the symbol is a local_symbol.  */
     27   unsigned int sy_local_symbol : 1;
     28 
     29   /* Wether symbol has been written.  */
     30   unsigned int sy_written : 1;
     31 
     32   /* Whether symbol value has been completely resolved (used during
     33      final pass over symbol table).  */
     34   unsigned int sy_resolved : 1;
     35 
     36   /* Whether the symbol value is currently being resolved (used to
     37      detect loops in symbol dependencies).  */
     38   unsigned int sy_resolving : 1;
     39 
     40   /* Whether the symbol value is used in a reloc.  This is used to
     41      ensure that symbols used in relocs are written out, even if they
     42      are local and would otherwise not be.  */
     43   unsigned int sy_used_in_reloc : 1;
     44 
     45   /* Whether the symbol is used as an operand or in an expression.
     46      NOTE:  Not all the backends keep this information accurate;
     47      backends which use this bit are responsible for setting it when
     48      a symbol is used in backend routines.  */
     49   unsigned int sy_used : 1;
     50 
     51   /* Whether the symbol can be re-defined.  */
     52   unsigned int sy_volatile : 1;
     53 
     54   /* Whether the symbol is a forward reference.  */
     55   unsigned int sy_forward_ref : 1;
     56 
     57   /* This is set if the symbol is defined in an MRI common section.
     58      We handle such sections as single common symbols, so symbols
     59      defined within them must be treated specially by the relocation
     60      routines.  */
     61   unsigned int sy_mri_common : 1;
     62 
     63   /* This is set if the symbol is set with a .weakref directive.  */
     64   unsigned int sy_weakrefr : 1;
     65 
     66   /* This is set when the symbol is referenced as part of a .weakref
     67      directive, but only if the symbol was not in the symbol table
     68      before.  It is cleared as soon as any direct reference to the
     69      symbol is present.  */
     70   unsigned int sy_weakrefd : 1;
     71 };
     72 
     73 /* The information we keep for a symbol.  Note that the symbol table
     74    holds pointers both to this and to local_symbol structures.  See
     75    below.  */
     76 
     77 struct symbol
     78 {
     79   /* Symbol flags.  */
     80   struct symbol_flags sy_flags;
     81 
     82   /* BFD symbol */
     83   asymbol *bsym;
     84 
     85   /* The value of the symbol.  */
     86   expressionS sy_value;
     87 
     88   /* Forwards and (optionally) backwards chain pointers.  */
     89   struct symbol *sy_next;
     90   struct symbol *sy_previous;
     91 
     92   /* Pointer to the frag this symbol is attached to, if any.
     93      Otherwise, NULL.  */
     94   struct frag *sy_frag;
     95 
     96 #ifdef OBJ_SYMFIELD_TYPE
     97   OBJ_SYMFIELD_TYPE sy_obj;
     98 #endif
     99 
    100 #ifdef TC_SYMFIELD_TYPE
    101   TC_SYMFIELD_TYPE sy_tc;
    102 #endif
    103 
    104 #ifdef TARGET_SYMBOL_FIELDS
    105   TARGET_SYMBOL_FIELDS
    106 #endif
    107 };
    108 
    109 /* A pointer in the symbol may point to either a complete symbol
    110    (struct symbol above) or to a local symbol (struct local_symbol
    111    defined here).  The symbol code can detect the case by examining
    112    the first field.  It is always NULL for a local symbol.
    113 
    114    We do this because we ordinarily only need a small amount of
    115    information for a local symbol.  The symbol table takes up a lot of
    116    space, and storing less information for a local symbol can make a
    117    big difference in assembler memory usage when assembling a large
    118    file.  */
    119 
    120 struct local_symbol
    121 {
    122   /* Symbol flags.  Only sy_local_symbol and sy_resolved are relevant.  */
    123   struct symbol_flags lsy_flags;
    124 
    125   /* The symbol section.  This also serves as a flag.  If this is
    126      reg_section, then this symbol has been converted into a regular
    127      symbol, and lsy_sym points to it.  */
    128   segT lsy_section;
    129 
    130   /* The symbol name.  */
    131   const char *lsy_name;
    132 
    133   /* The symbol frag or the real symbol, depending upon the value in
    134      lsy_section.  */
    135   union
    136   {
    137     fragS *lsy_frag;
    138     symbolS *lsy_sym;
    139   } u;
    140 
    141   /* The value of the symbol.  */
    142   valueT lsy_value;
    143 
    144 #ifdef TC_LOCAL_SYMFIELD_TYPE
    145   TC_LOCAL_SYMFIELD_TYPE lsy_tc;
    146 #endif
    147 };
    148 
    149 #define local_symbol_converted_p(l) ((l)->lsy_section == reg_section)
    150 #define local_symbol_mark_converted(l) ((l)->lsy_section = reg_section)
    151 #define local_symbol_resolved_p(l) ((l)->lsy_flags.sy_resolved)
    152 #define local_symbol_mark_resolved(l) ((l)->lsy_flags.sy_resolved = 1)
    153 #define local_symbol_get_frag(l) ((l)->u.lsy_frag)
    154 #define local_symbol_set_frag(l, f) ((l)->u.lsy_frag = (f))
    155 #define local_symbol_get_real_symbol(l) ((l)->u.lsy_sym)
    156 #define local_symbol_set_real_symbol(l, s) ((l)->u.lsy_sym = (s))
    157 
    158 #endif /* __struc_symbol_h__ */
    159