struc-symbol.h revision 89857
133965Sjdp/* struct_symbol.h - Internal symbol structure
278828Sobrien   Copyright 1987, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001
377298Sobrien   Free Software Foundation, Inc.
433965Sjdp
533965Sjdp   This file is part of GAS, the GNU Assembler.
633965Sjdp
733965Sjdp   GAS is free software; you can redistribute it and/or modify
833965Sjdp   it under the terms of the GNU General Public License as published by
933965Sjdp   the Free Software Foundation; either version 2, or (at your option)
1033965Sjdp   any later version.
1133965Sjdp
1233965Sjdp   GAS is distributed in the hope that it will be useful,
1333965Sjdp   but WITHOUT ANY WARRANTY; without even the implied warranty of
1433965Sjdp   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1533965Sjdp   GNU General Public License for more details.
1633965Sjdp
1733965Sjdp   You should have received a copy of the GNU General Public License
1860484Sobrien   along with GAS; see the file COPYING.  If not, write to the Free
1960484Sobrien   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
2060484Sobrien   02111-1307, USA.  */
2133965Sjdp
2233965Sjdp#ifndef __struc_symbol_h__
2333965Sjdp#define __struc_symbol_h__
2433965Sjdp
2577298Sobrien#ifdef BFD_ASSEMBLER
2677298Sobrien/* The BFD code wants to walk the list in both directions.  */
2777298Sobrien#undef  SYMBOLS_NEED_BACKPOINTERS
2877298Sobrien#define SYMBOLS_NEED_BACKPOINTERS
2977298Sobrien#endif
3077298Sobrien
3160484Sobrien/* The information we keep for a symbol.  Note that the symbol table
3260484Sobrien   holds pointers both to this and to local_symbol structures.  See
3360484Sobrien   below.  */
3433965Sjdp
3533965Sjdpstruct symbol
3633965Sjdp{
3760484Sobrien#ifdef BFD_ASSEMBLER
3860484Sobrien  /* BFD symbol */
3960484Sobrien  asymbol *bsym;
4060484Sobrien#else
4133965Sjdp  /* The (4-origin) position of sy_name in the symbol table of the object
4233965Sjdp     file.  This will be 0 for (nameless) .stabd symbols.
4333965Sjdp
4477298Sobrien     Not used until write_object_file() time.  */
4533965Sjdp  unsigned long sy_name_offset;
4633965Sjdp
4733965Sjdp  /* What we write in .o file (if permitted).  */
4833965Sjdp  obj_symbol_type sy_symbol;
4933965Sjdp
5077298Sobrien  /* The 24 bit symbol number.  Symbol numbers start at 0 and are unsigned.  */
5133965Sjdp  long sy_number;
5233965Sjdp#endif
5333965Sjdp
5433965Sjdp  /* The value of the symbol.  */
5533965Sjdp  expressionS sy_value;
5633965Sjdp
5733965Sjdp  /* Forwards and (optionally) backwards chain pointers.  */
5833965Sjdp  struct symbol *sy_next;
5933965Sjdp#ifdef SYMBOLS_NEED_BACKPOINTERS
6033965Sjdp  struct symbol *sy_previous;
6133965Sjdp#endif /* SYMBOLS_NEED_BACKPOINTERS */
6233965Sjdp
6333965Sjdp  /* Pointer to the frag this symbol is attached to, if any.
6433965Sjdp     Otherwise, NULL.  */
6533965Sjdp  struct frag *sy_frag;
6633965Sjdp
6733965Sjdp  unsigned int written : 1;
6833965Sjdp  /* Whether symbol value has been completely resolved (used during
6933965Sjdp     final pass over symbol table).  */
7033965Sjdp  unsigned int sy_resolved : 1;
7133965Sjdp  /* Whether the symbol value is currently being resolved (used to
7233965Sjdp     detect loops in symbol dependencies).  */
7333965Sjdp  unsigned int sy_resolving : 1;
7433965Sjdp  /* Whether the symbol value is used in a reloc.  This is used to
7533965Sjdp     ensure that symbols used in relocs are written out, even if they
7633965Sjdp     are local and would otherwise not be.  */
7733965Sjdp  unsigned int sy_used_in_reloc : 1;
7833965Sjdp
7977298Sobrien  /* Whether the symbol is used as an operand or in an expression.
8033965Sjdp     NOTE:  Not all the backends keep this information accurate;
8133965Sjdp     backends which use this bit are responsible for setting it when
8233965Sjdp     a symbol is used in backend routines.  */
8333965Sjdp  unsigned int sy_used : 1;
8433965Sjdp
8533965Sjdp  /* This is set if the symbol is defined in an MRI common section.
8633965Sjdp     We handle such sections as single common symbols, so symbols
8733965Sjdp     defined within them must be treated specially by the relocation
8833965Sjdp     routines.  */
8933965Sjdp  unsigned int sy_mri_common : 1;
9033965Sjdp
9133965Sjdp#ifdef OBJ_SYMFIELD_TYPE
9233965Sjdp  OBJ_SYMFIELD_TYPE sy_obj;
9333965Sjdp#endif
9433965Sjdp
9533965Sjdp#ifdef TC_SYMFIELD_TYPE
9633965Sjdp  TC_SYMFIELD_TYPE sy_tc;
9733965Sjdp#endif
9877298Sobrien
9977298Sobrien#ifdef TARGET_SYMBOL_FIELDS
10077298Sobrien  TARGET_SYMBOL_FIELDS
10177298Sobrien#endif
10233965Sjdp};
10333965Sjdp
10460484Sobrien#ifdef BFD_ASSEMBLER
10533965Sjdp
10660484Sobrien/* A pointer in the symbol may point to either a complete symbol
10760484Sobrien   (struct symbol above) or to a local symbol (struct local_symbol
10860484Sobrien   defined here).  The symbol code can detect the case by examining
10960484Sobrien   the first field.  It is always NULL for a local symbol.
11033965Sjdp
11160484Sobrien   We do this because we ordinarily only need a small amount of
11260484Sobrien   information for a local symbol.  The symbol table takes up a lot of
11360484Sobrien   space, and storing less information for a local symbol can make a
11460484Sobrien   big difference in assembler memory usage when assembling a large
11560484Sobrien   file.  */
11633965Sjdp
11760484Sobrienstruct local_symbol
11860484Sobrien{
11960484Sobrien  /* This pointer is always NULL to indicate that this is a local
12060484Sobrien     symbol.  */
12160484Sobrien  asymbol *lsy_marker;
12233965Sjdp
12360484Sobrien  /* The symbol section.  This also serves as a flag.  If this is
12460484Sobrien     reg_section, then this symbol has been converted into a regular
12589857Sobrien     symbol, and lsy_sym points to it.  */
12660484Sobrien  segT lsy_section;
12733965Sjdp
12860484Sobrien  /* The symbol name.  */
12960484Sobrien  const char *lsy_name;
13033965Sjdp
13160484Sobrien  /* The symbol frag or the real symbol, depending upon the value in
13289857Sobrien     lsy_section.  If the symbol has been fully resolved, lsy_frag is
13360484Sobrien     set to NULL.  */
13460484Sobrien  union
13560484Sobrien  {
13660484Sobrien    fragS *lsy_frag;
13760484Sobrien    symbolS *lsy_sym;
13860484Sobrien  } u;
13933965Sjdp
14089857Sobrien  /* The value of the symbol.  */
14189857Sobrien  valueT lsy_value;
14289857Sobrien
14389857Sobrien#ifdef TC_LOCAL_SYMFIELD_TYPE
14489857Sobrien  TC_LOCAL_SYMFIELD_TYPE lsy_tc;
14589857Sobrien#endif
14660484Sobrien};
14733965Sjdp
14860484Sobrien#define local_symbol_converted_p(l) ((l)->lsy_section == reg_section)
14960484Sobrien#define local_symbol_mark_converted(l) ((l)->lsy_section = reg_section)
15060484Sobrien#define local_symbol_resolved_p(l) ((l)->u.lsy_frag == NULL)
15160484Sobrien#define local_symbol_mark_resolved(l) ((l)->u.lsy_frag = NULL)
15260484Sobrien#define local_symbol_get_frag(l) ((l)->u.lsy_frag)
15360484Sobrien#define local_symbol_set_frag(l, f) ((l)->u.lsy_frag = (f))
15460484Sobrien#define local_symbol_get_real_symbol(l) ((l)->u.lsy_sym)
15560484Sobrien#define local_symbol_set_real_symbol(l, s) ((l)->u.lsy_sym = (s))
15633965Sjdp
15760484Sobrien#endif /* BFD_ASSEMBLER */
15833965Sjdp
15933965Sjdp#endif /* __struc_symbol_h__ */
160