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

2.4 Frags

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
The address of the frag. This is not set until the assembler rescans the list of all frags after the entire input file is parsed. The function relax_segment fills in this field.

fr_next
Pointer to the next frag in this (sub)section.

fr_fix
Fixed number of characters we know we're going to emit to the output file. May be zero.

fr_var
Variable number of characters we may output, after the initial fr_fix characters. May be zero.

fr_offset
The interpretation of this field is controlled by fr_type. Generally, if fr_var is non-zero, this is a repeat count: the fr_var characters are output fr_offset times.

line
Holds line number info when an assembler listing was requested.

fr_type
Relaxation state. This field indicates the interpretation of 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
Relaxation substate. If the macro 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 5. Relaxation). If md_relax_frag is defined, this field is available for any use by the CPU-specific code.

fr_symbol
This normally indicates the symbol to use when relaxing the frag according to fr_type.

fr_opcode
Points to the lowest-addressed byte of the opcode, for use in relaxation.

tc_frag_data
Target specific fragment data of type TC_FRAG_TYPE. Only present if TC_FRAG_TYPE is defined.

fr_file
fr_line
The file and line where this frag was last modified.

fr_literal
Declared as a one-character array, this last field grows arbitrarily large to hold the actual contents of the frag.

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
The start of the following frag should be aligned on some boundary. In this frag, 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
This indicates that "broken word" processing should be done (see section 6. Broken words). If broken word processing is not necessary on the target machine, this enumerator value will not be defined.

rs_cfa
This state is used to implement exception frame optimizations. The fr_symbol is an expression symbol for the subtraction which may be relaxed. The fr_opcode field holds the frag for the preceding command byte. The fr_offset field holds the offset within that frag. The fr_subtype field is used during relaxation to hold the current size of the frag.

rs_fill
The variable characters are to be repeated fr_offset times. If fr_offset is 0, this frag has a length of fr_fix. Most frags have this type.

rs_leb128
This state is used to implement the DWARF "little endian base 128" variable length number format. The fr_symbol is always an expression symbol, as constant expressions are emitted directly. The fr_offset field is used during relaxation to hold the previous size of the number so that we can determine if the fragment changed size.

rs_machine_dependent
Displacement relaxation is to be done on this frag. The target is indicated by fr_symbol and fr_offset, and fr_subtype indicates the particular machine-specific addressing mode desired. See section 5. Relaxation.

rs_org
The start of the following frag should be pushed back to some specific offset within the section. (Some assemblers use the value as an absolute address; GAS does not handle final absolute addresses, but rather requires that the linker set them.) The offset is given by 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
Points to the first frag in the chain. May be NULL if there are no frags in this chain.
frch_last
Points to the last frag in the chain, or NULL if there are none.
frch_next
Next in the list of frchainS structures.
frch_seg
Indicates the section this frag chain belongs to.
frch_subseg
Subsection (subsegment) number of this frag chain.
fix_root, fix_tail
(Defined only if BFD_ASSEMBLER is defined). Point to first and last fixS structures associated with this subsection.
frch_obstack
Not currently used. Intended to be used for frag allocation for this subsection. This should reduce frag generation caused by switching sections.
frch_frag_now
The current frag for this subsegment.

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. The function frag_room says by how much the current frag can be extended. Relaxing is done using variant frags allocated by frag_var or frag_variant (see section 5. Relaxation).


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

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