This section describes some fundamental GAS data types.
The definition for struct symbol
, also known as symbolS
, is
located in `struc-symbol.h'. Symbol structures contain the following
fields:
sy_value
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 in write_object_file
.
The expression is often simply a constant. Before resolve_symbol_value
is called, the value is the offset from the frag (see section Frags). Afterward,
the frag address has been added in.
sy_resolved
sy_resolving
sy_used_in_reloc
sy_next
sy_previous
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
sy_used
sy_mri_common
COMMON
pseudo-op when assembling in MRI mode.
bsym
BFD_ASSEMBLER
is defined, this points to the BFD asymbol
that
will be used in writing the object file.
sy_name_offset
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
BFD_ASSEMBLER
is not defined.) This is the
format-specific symbol structure, as it would be written into the object file.
sy_number
BFD_ASSEMBLER
is not defined.) This is a 24-bit symbol
number, for use in constructing relocation table entries.
sy_obj
OBJ_SYMFIELD_TYPE
. If no macro by
that name is defined in `obj-format.h', this field is not defined.
sy_tc
TC_SYMFIELD_TYPE
. If no macro
by that name is defined in `targ-cpu.h', this field is not defined.
TARGET_SYMBOL_FIELDS
OBJ_SYMFIELD_TYPE
and TC_SYMFIELD_TYPE
.
There are a number of access routines used to extract the fields of a
symbolS
structure. When possible, these routines should be used rather
than referring to the fields directly. These routines will work for any GAS
version.
S_SET_VALUE
S_GET_VALUE
resolve_symbol_value
to be
called if necessary, so S_GET_VALUE
should only be called when it is
safe to resolve symbols (i.e., after the entire input file has been read and
all symbols have been defined).
S_SET_SEGMENT
S_GET_SEGMENT
S_GET_NAME
S_SET_NAME
S_IS_EXTERNAL
S_IS_EXTERN
S_IS_EXTERNAL
. Don't use it.
S_IS_WEAK
S_IS_COMMON
S_IS_DEFINED
S_IS_DEBUG
S_IS_LOCAL
S_IS_EXTERNAL
. The `-L' assembler option affects the return value
of this function.
S_SET_EXTERNAL
S_CLEAR_EXTERNAL
S_SET_WEAK
S_GET_TYPE
S_GET_DESC
S_GET_OTHER
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
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
S_SET_SIZE
Expressions are stored in an expressionS
structure. The structure is
defined in `expr.h'.
The macro expression
will create an expressionS
structure based
on the text found at the global variable input_line_pointer
.
A single expressionS
structure can represent a single operation.
Complex expressions are formed by creating expression symbols and
combining them in expressionS
structures. An expression symbol is
created by calling make_expr_symbol
. An expression symbol should
naturally never appear in a symbol table, and the implementation of
S_IS_LOCAL
(see section Symbols) reflects that. The function
expr_symbol_where
returns non-zero if a symbol is an expression symbol,
and also returns the file and line for the expression which caused it to be
created.
The expressionS
structure has two symbol fields, a number field, an
operator field, and a field indicating whether the number is unsigned.
The operator field is of type operatorT
, and describes how to interpret
the other fields; see the definition in `expr.h' for the possibilities.
An operatorT
value of O_big
indicates either a floating point
number, stored in the global variable generic_floating_point_number
, or
an integer to large to store in an offsetT
type, stored in the global
array generic_bignum
. This rather inflexible approach makes it
impossible to use floating point numbers or large expressions in complex
expressions.
A fixup is basically anything which can not be resolved in the first pass. Sometimes a fixup can be resolved by the end of the assembly; if not, the fixup becomes a relocation entry in the object file.
A fixup is created by a call to fix_new
or fix_new_exp
. Both
take a frag (see section Frags), a position within the frag, a size, an indication
of whether the fixup is PC relative, and a type. In a BFD_ASSEMBLER
GAS, the type is nominally a bfd_reloc_code_real_type
, but several
targets use other type codes to represent fixups that can not be described as
relocations.
The fixS
structure has a number of fields, several of which are obsolete
or are only used by a particular target. The important fields are:
fx_frag
fx_where
fx_addsy
fx_subsy
fx_offset
fx_addnumber
md_apply_fix
and tc_gen_reloc
. The machine independent code does
not use it.
fx_next
fx_r_type
BFD_ASSEMBLER
, or
if the target defines NEED_FX_R_TYPE
.
fx_size
fx_pcrel
fx_done
fx_file
fx_line
tc_fix_data
TC_FIX_TYPE
, and is only defined if the target defines
that macro.
The fragS
structure is defined in `as.h'. Each frag represents a
portion of the final object file. As GAS reads the source file, it creates
frags to hold the data that it reads. At the end of the assembly the frags and
fixups are processed to produce the final contents.
fr_address
relax_segment
fills in this field.
fr_next
fr_fix
fr_var
fr_fix
characters. May be zero.
fr_offset
fr_type
. Generally,
if fr_var
is non-zero, this is a repeat count: the fr_var
characters are output fr_offset
times.
line
fr_type
fr_offset
,
fr_symbol
and the variable-length tail of the frag, as well as the
treatment it gets in various phases of processing. It does not affect the
initial fr_fix
characters; they are always supposed to be output
verbatim (fixups aside). See below for specific values this field can have.
fr_subtype
md_relax_frag
isn't defined, this is
assumed to be an index into TC_GENERIC_RELAX_TABLE
for the generic
relaxation code to process (see section Relaxation). If md_relax_frag
is
defined, this field is available for any use by the CPU-specific code.
fr_symbol
fr_type
.
fr_opcode
fr_pcrel_adjust
fr_bsr
struct
frag
is defined before the CPU-specific header files are included, they must
unconditionally be defined.
fr_file
fr_line
fr_literal
These are the possible relaxation states, provided in the enumeration type
relax_stateT
, and the interpretations they represent for the other
fields:
rs_align
rs_align_code
fr_offset
is the logarithm (base 2) of the alignment in bytes.
(For example, if alignment on an 8-byte boundary were desired, fr_offset
would have a value of 3.) The variable characters indicate the fill pattern to
be used. The fr_subtype
field holds the maximum number of bytes to skip
when doing this alignment. If more bytes are needed, the alignment is not
done. An fr_subtype
value of 0 means no maximum, which is the normal
case. Target backends can use rs_align_code
to handle certain types of
alignment differently.
rs_broken_word
rs_fill
fr_offset
times. If
fr_offset
is 0, this frag has a length of fr_fix
. Most frags
have this type.
rs_machine_dependent
fr_symbol
and fr_offset
, and fr_subtype
indicates the
particular machine-specific addressing mode desired. See section Relaxation.
rs_org
fr_symbol
and fr_offset
; one
character from the variable-length tail is used as the fill character.
A chain of frags is built up for each subsection. The data structure
describing a chain is called a frchainS
, and contains the following
fields:
frch_root
frch_last
frch_next
frchainS
structures.
frch_seg
frch_subseg
fix_root, fix_tail
BFD_ASSEMBLER
is defined). Point to first and last
fixS
structures associated with this subsection.
frch_obstack
frch_frag_now
A frchainS
corresponds to a subsection; each section has a list of
frchainS
records associated with it. In most cases, only one subsection
of each section is used, so the list will only be one element long, but any
processing of frag chains should be prepared to deal with multiple chains per
section.
After the input files have been completely processed, and no more frags are to be generated, the frag chains are joined into one per section for further processing. After this point, it is safe to operate on one chain per section.
The assembler always has a current frag, named frag_now
. More space is
allocated for the current frag using the frag_more
function; this
returns a pointer to the amount of requested space. Relaxing is done using
variant frags allocated by frag_var
or frag_variant
(see section Relaxation).
Go to the first, previous, next, last section, table of contents.