[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

2.1 Symbols

The definition for the symbol structure, symbolS, is located in `struc-symbol.h'.

In general, the fields of this structure may not be referred to directly. Instead, you must use one of the accessor functions defined in `symbol.h'. These accessor functions should work for any GAS version.

Symbol structures contain the following fields:

sy_value
This is an expressionS that describes the value of the symbol. It might refer to one or more other symbols; if so, its true value may not be known until resolve_symbol_value is called with finalize_syms non-zero in write_object_file.

The expression is often simply a constant. Before resolve_symbol_value is called with finalize_syms set, the value is the offset from the frag (see section 2.4 Frags). Afterward, the frag address has been added in.

sy_resolved
This field is non-zero if the symbol's value has been completely resolved. It is used during the final pass over the symbol table.

sy_resolving
This field is used to detect loops while resolving the symbol's value.

sy_used_in_reloc
This field is non-zero if the symbol is used by a relocation entry. If a local symbol is used in a relocation entry, it must be possible to redirect those relocations to other symbols, or this symbol cannot be removed from the final symbol list.

sy_next
sy_previous
These pointers to other symbolS structures describe a singly or doubly linked list. (If SYMBOLS_NEED_BACKPOINTERS is not defined, the sy_previous field will be omitted; SYMBOLS_NEED_BACKPOINTERS is always defined if BFD_ASSEMBLER.) These fields should be accessed with the symbol_next and symbol_previous macros.

sy_frag
This points to the frag (see section 2.4 Frags) that this symbol is attached to.

sy_used
Whether the symbol is used as an operand or in an expression. Note: Not all of the backends keep this information accurate; backends which use this bit are responsible for setting it when a symbol is used in backend routines.

sy_mri_common
Whether the symbol is an MRI common symbol created by the COMMON pseudo-op when assembling in MRI mode.

bsym
If BFD_ASSEMBLER is defined, this points to the BFD asymbol that will be used in writing the object file.

sy_name_offset
(Only used if BFD_ASSEMBLER is not defined.) This is the position of the symbol's name in the string table of the object file. On some formats, this will start at position 4, with position 0 reserved for unnamed symbols. This field is not used until write_object_file is called.

sy_symbol
(Only used if BFD_ASSEMBLER is not defined.) This is the format-specific symbol structure, as it would be written into the object file.

sy_number
(Only used if BFD_ASSEMBLER is not defined.) This is a 24-bit symbol number, for use in constructing relocation table entries.

sy_obj
This format-specific data is of type OBJ_SYMFIELD_TYPE. If no macro by that name is defined in `obj-format.h', this field is not defined.

sy_tc
This processor-specific data is of type TC_SYMFIELD_TYPE. If no macro by that name is defined in `targ-cpu.h', this field is not defined.

Here is a description of the accessor functions. These should be used rather than referring to the fields of symbolS directly.

S_SET_VALUE
Set the symbol's value.

S_GET_VALUE
Get the symbol's value. This will cause resolve_symbol_value to be called if necessary.

S_SET_SEGMENT
Set the section of the symbol.

S_GET_SEGMENT
Get the symbol's section.

S_GET_NAME
Get the name of the symbol.

S_SET_NAME
Set the name of the symbol.

S_IS_EXTERNAL
Return non-zero if the symbol is externally visible.

S_IS_EXTERN
A synonym for S_IS_EXTERNAL. Don't use it.

S_IS_WEAK
Return non-zero if the symbol is weak.

S_IS_COMMON
Return non-zero if this is a common symbol. Common symbols are sometimes represented as undefined symbols with a value, in which case this function will not be reliable.

S_IS_DEFINED
Return non-zero if this symbol is defined. This function is not reliable when called on a common symbol.

S_IS_DEBUG
Return non-zero if this is a debugging symbol.

S_IS_LOCAL
Return non-zero if this is a local assembler symbol which should not be included in the final symbol table. Note that this is not the opposite of S_IS_EXTERNAL. The `-L' assembler option affects the return value of this function.

S_SET_EXTERNAL
Mark the symbol as externally visible.

S_CLEAR_EXTERNAL
Mark the symbol as not externally visible.

S_SET_WEAK
Mark the symbol as weak.

S_GET_TYPE
S_GET_DESC
S_GET_OTHER
Get the type, desc, and other fields of the symbol. These are only defined for object file formats for which they make sense (primarily a.out).

S_SET_TYPE
S_SET_DESC
S_SET_OTHER
Set the type, desc, and other fields of the symbol. These are only defined for object file formats for which they make sense (primarily a.out).

S_GET_SIZE
Get the size of a symbol. This is only defined for object file formats for which it makes sense (primarily ELF).

S_SET_SIZE
Set the size of a symbol. This is only defined for object file formats for which it makes sense (primarily ELF).

symbol_get_value_expression
Get a pointer to an expressionS structure which represents the value of the symbol as an expression.

symbol_set_value_expression
Set the value of a symbol to an expression.

symbol_set_frag
Set the frag where a symbol is defined.

symbol_get_frag
Get the frag where a symbol is defined.

symbol_mark_used
Mark a symbol as having been used in an expression.

symbol_clear_used
Clear the mark indicating that a symbol was used in an expression.

symbol_used_p
Return whether a symbol was used in an expression.

symbol_mark_used_in_reloc
Mark a symbol as having been used by a relocation.

symbol_clear_used_in_reloc
Clear the mark indicating that a symbol was used in a relocation.

symbol_used_in_reloc_p
Return whether a symbol was used in a relocation.

symbol_mark_mri_common
Mark a symbol as an MRI common symbol.

symbol_clear_mri_common
Clear the mark indicating that a symbol is an MRI common symbol.

symbol_mri_common_p
Return whether a symbol is an MRI common symbol.

symbol_mark_written
Mark a symbol as having been written.

symbol_clear_written
Clear the mark indicating that a symbol was written.

symbol_written_p
Return whether a symbol was written.

symbol_mark_resolved
Mark a symbol as having been resolved.

symbol_resolved_p
Return whether a symbol has been resolved.

symbol_section_p
Return whether a symbol is a section symbol.

symbol_equated_p
Return whether a symbol is equated to another symbol.

symbol_constant_p
Return whether a symbol has a constant value, including being an offset within some frag.

symbol_get_bfdsym
Return the BFD symbol associated with a symbol.

symbol_set_bfdsym
Set the BFD symbol associated with a symbol.

symbol_get_obj
Return a pointer to the OBJ_SYMFIELD_TYPE field of a symbol.

symbol_set_obj
Set the OBJ_SYMFIELD_TYPE field of a symbol.

symbol_get_tc
Return a pointer to the TC_SYMFIELD_TYPE field of a symbol.

symbol_set_tc
Set the TC_SYMFIELD_TYPE field of a symbol.

When BFD_ASSEMBLER is defined, GAS attempts to store local symbols--symbols which will not be written to the output file--using a different structure, struct local_symbol. This structure can only represent symbols whose value is an offset within a frag.

Code outside of the symbol handler will always deal with symbolS structures and use the accessor functions. The accessor functions correctly deal with local symbols. struct local_symbol is much smaller than symbolS (which also automatically creates a bfd asymbol structure), so this saves space when assembling large files.

The first field of symbolS is bsym, the pointer to the BFD symbol. The first field of struct local_symbol is a pointer which is always set to NULL. This is how the symbol accessor functions can distinguish local symbols from ordinary symbols. The symbol accessor functions automatically convert a local symbol into an ordinary symbol when necessary.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by system on December, 2 2004 using texi2html