xref: /netbsd-src/external/gpl3/binutils.old/dist/gas/doc/internals.texi (revision e992f068c547fd6e84b3f104dc2340adcc955732)
116dce513Schristos\input texinfo
2*e992f068Schristos@c  Copyright (C) 1991-2022 Free Software Foundation, Inc.
316dce513Schristos@setfilename internals.info
416dce513Schristos@node Top
516dce513Schristos@top Assembler Internals
616dce513Schristos@raisesections
716dce513Schristos@cindex internals
816dce513Schristos
916dce513SchristosThis chapter describes the internals of the assembler.  It is incomplete, but
1016dce513Schristosit may help a bit.
1116dce513Schristos
1216dce513SchristosThis chapter is not updated regularly, and it may be out of date.
1316dce513Schristos
1416dce513Schristos@menu
1516dce513Schristos* Data types::		Data types
1616dce513Schristos* GAS processing::      What GAS does when it runs
1716dce513Schristos* Porting GAS::         Porting GAS
1816dce513Schristos* Relaxation::          Relaxation
1916dce513Schristos* Broken words::        Broken words
2016dce513Schristos* Internal functions::  Internal functions
2116dce513Schristos* Test suite::          Test suite
2216dce513Schristos@end menu
2316dce513Schristos
2416dce513Schristos@node Data types
2516dce513Schristos@section Data types
2616dce513Schristos@cindex internals, data types
2716dce513Schristos
2816dce513SchristosThis section describes some fundamental GAS data types.
2916dce513Schristos
3016dce513Schristos@menu
3116dce513Schristos* Symbols::             The symbolS structure
3216dce513Schristos* Expressions::         The expressionS structure
3316dce513Schristos* Fixups::		The fixS structure
3416dce513Schristos* Frags::               The fragS structure
3516dce513Schristos@end menu
3616dce513Schristos
3716dce513Schristos@node Symbols
3816dce513Schristos@subsection Symbols
3916dce513Schristos@cindex internals, symbols
4016dce513Schristos@cindex symbols, internal
4116dce513Schristos@cindex symbolS structure
4216dce513Schristos
4316dce513SchristosThe definition for the symbol structure, @code{symbolS}, is located in
44012573ebSchristos@file{symbols.c}.
4516dce513Schristos
46012573ebSchristosThe fields of this structure may not be referred to directly.
4716dce513SchristosInstead, you must use one of the accessor functions defined in @file{symbol.h}.
4816dce513Schristos
4916dce513SchristosSymbol structures contain the following fields:
5016dce513Schristos
5116dce513Schristos@table @code
5216dce513Schristos@item sy_value
5316dce513SchristosThis is an @code{expressionS} that describes the value of the symbol.  It might
5416dce513Schristosrefer to one or more other symbols; if so, its true value may not be known
5516dce513Schristosuntil @code{resolve_symbol_value} is called with @var{finalize_syms} non-zero
5616dce513Schristosin @code{write_object_file}.
5716dce513Schristos
5816dce513SchristosThe expression is often simply a constant.  Before @code{resolve_symbol_value}
5916dce513Schristosis called with @var{finalize_syms} set, the value is the offset from the frag
6016dce513Schristos(@pxref{Frags}).  Afterward, the frag address has been added in.
6116dce513Schristos
6216dce513Schristos@item sy_resolved
6316dce513SchristosThis field is non-zero if the symbol's value has been completely resolved.  It
6416dce513Schristosis used during the final pass over the symbol table.
6516dce513Schristos
6616dce513Schristos@item sy_resolving
6716dce513SchristosThis field is used to detect loops while resolving the symbol's value.
6816dce513Schristos
6916dce513Schristos@item sy_used_in_reloc
7016dce513SchristosThis field is non-zero if the symbol is used by a relocation entry.  If a local
7116dce513Schristossymbol is used in a relocation entry, it must be possible to redirect those
7216dce513Schristosrelocations to other symbols, or this symbol cannot be removed from the final
7316dce513Schristossymbol list.
7416dce513Schristos
7516dce513Schristos@item sy_next
7616dce513Schristos@itemx sy_previous
7716dce513SchristosThese pointers to other @code{symbolS} structures describe a doubly
7816dce513Schristoslinked list.  These fields should be accessed with
7916dce513Schristosthe @code{symbol_next} and @code{symbol_previous} macros.
8016dce513Schristos
8116dce513Schristos@item sy_frag
8216dce513SchristosThis points to the frag (@pxref{Frags}) that this symbol is attached to.
8316dce513Schristos
8416dce513Schristos@item sy_used
8516dce513SchristosWhether the symbol is used as an operand or in an expression.  Note: Not all of
8616dce513Schristosthe backends keep this information accurate; backends which use this bit are
8716dce513Schristosresponsible for setting it when a symbol is used in backend routines.
8816dce513Schristos
8916dce513Schristos@item sy_mri_common
9016dce513SchristosWhether the symbol is an MRI common symbol created by the @code{COMMON}
9116dce513Schristospseudo-op when assembling in MRI mode.
9216dce513Schristos
9316dce513Schristos@item sy_volatile
9416dce513SchristosWhether the symbol can be re-defined.
9516dce513Schristos
9616dce513Schristos@item sy_forward_ref
9716dce513SchristosWhether the symbol's value must only be evaluated upon use.
9816dce513Schristos
9916dce513Schristos@item sy_weakrefr
10016dce513SchristosWhether the symbol is a @code{weakref} alias to another symbol.
10116dce513Schristos
10216dce513Schristos@item sy_weakrefd
10316dce513SchristosWhether the symbol is or was referenced by one or more @code{weakref} aliases,
10416dce513Schristosand has not had any direct references.
10516dce513Schristos
10616dce513Schristos@item bsym
10716dce513SchristosThis points to the BFD @code{asymbol} that
10816dce513Schristoswill be used in writing the object file.
10916dce513Schristos
11016dce513Schristos@item sy_obj
11116dce513SchristosThis format-specific data is of type @code{OBJ_SYMFIELD_TYPE}.  If no macro by
11216dce513Schristosthat name is defined in @file{obj-format.h}, this field is not defined.
11316dce513Schristos
11416dce513Schristos@item sy_tc
11516dce513SchristosThis processor-specific data is of type @code{TC_SYMFIELD_TYPE}.  If no macro
11616dce513Schristosby that name is defined in @file{targ-cpu.h}, this field is not defined.
11716dce513Schristos
11816dce513Schristos@end table
11916dce513Schristos
12016dce513SchristosHere is a description of the accessor functions.  These should be used rather
12116dce513Schristosthan referring to the fields of @code{symbolS} directly.
12216dce513Schristos
12316dce513Schristos@table @code
12416dce513Schristos@item S_SET_VALUE
12516dce513Schristos@cindex S_SET_VALUE
12616dce513SchristosSet the symbol's value.
12716dce513Schristos
12816dce513Schristos@item S_GET_VALUE
12916dce513Schristos@cindex S_GET_VALUE
13016dce513SchristosGet the symbol's value.  This will cause @code{resolve_symbol_value} to be
13116dce513Schristoscalled if necessary.
13216dce513Schristos
13316dce513Schristos@item S_SET_SEGMENT
13416dce513Schristos@cindex S_SET_SEGMENT
13516dce513SchristosSet the section of the symbol.
13616dce513Schristos
13716dce513Schristos@item S_GET_SEGMENT
13816dce513Schristos@cindex S_GET_SEGMENT
13916dce513SchristosGet the symbol's section.
14016dce513Schristos
14116dce513Schristos@item S_GET_NAME
14216dce513Schristos@cindex S_GET_NAME
14316dce513SchristosGet the name of the symbol.
14416dce513Schristos
14516dce513Schristos@item S_SET_NAME
14616dce513Schristos@cindex S_SET_NAME
14716dce513SchristosSet the name of the symbol.
14816dce513Schristos
14916dce513Schristos@item S_IS_EXTERNAL
15016dce513Schristos@cindex S_IS_EXTERNAL
15116dce513SchristosReturn non-zero if the symbol is externally visible.
15216dce513Schristos
15316dce513Schristos@item S_IS_WEAK
15416dce513Schristos@cindex S_IS_WEAK
15516dce513SchristosReturn non-zero if the symbol is weak, or if it is a @code{weakref} alias or
15616dce513Schristossymbol that has not been strongly referenced.
15716dce513Schristos
15816dce513Schristos@item S_IS_WEAKREFR
15916dce513Schristos@cindex S_IS_WEAKREFR
16016dce513SchristosReturn non-zero if the symbol is a @code{weakref} alias.
16116dce513Schristos
16216dce513Schristos@item S_IS_WEAKREFD
16316dce513Schristos@cindex S_IS_WEAKREFD
16416dce513SchristosReturn non-zero if the symbol was aliased by a @code{weakref} alias and has not
16516dce513Schristoshad any strong references.
16616dce513Schristos
16716dce513Schristos@item S_IS_VOLATILE
16816dce513Schristos@cindex S_IS_VOLATILE
16916dce513SchristosReturn non-zero if the symbol may be re-defined. Such symbols get created by
17016dce513Schristosthe @code{=} operator, @code{equ}, or @code{set}.
17116dce513Schristos
17216dce513Schristos@item S_IS_FORWARD_REF
17316dce513Schristos@cindex S_IS_FORWARD_REF
17416dce513SchristosReturn non-zero if the symbol is a forward reference, that is its value must
17516dce513Schristosonly be determined upon use.
17616dce513Schristos
17716dce513Schristos@item S_IS_COMMON
17816dce513Schristos@cindex S_IS_COMMON
17916dce513SchristosReturn non-zero if this is a common symbol.  Common symbols are sometimes
18016dce513Schristosrepresented as undefined symbols with a value, in which case this function will
18116dce513Schristosnot be reliable.
18216dce513Schristos
18316dce513Schristos@item S_IS_DEFINED
18416dce513Schristos@cindex S_IS_DEFINED
18516dce513SchristosReturn non-zero if this symbol is defined.  This function is not reliable when
18616dce513Schristoscalled on a common symbol.
18716dce513Schristos
18816dce513Schristos@item S_IS_DEBUG
18916dce513Schristos@cindex S_IS_DEBUG
19016dce513SchristosReturn non-zero if this is a debugging symbol.
19116dce513Schristos
19216dce513Schristos@item S_IS_LOCAL
19316dce513Schristos@cindex S_IS_LOCAL
19416dce513SchristosReturn non-zero if this is a local assembler symbol which should not be
19516dce513Schristosincluded in the final symbol table.  Note that this is not the opposite of
19616dce513Schristos@code{S_IS_EXTERNAL}.  The @samp{-L} assembler option affects the return value
19716dce513Schristosof this function.
19816dce513Schristos
19916dce513Schristos@item S_SET_EXTERNAL
20016dce513Schristos@cindex S_SET_EXTERNAL
20116dce513SchristosMark the symbol as externally visible.
20216dce513Schristos
20316dce513Schristos@item S_CLEAR_EXTERNAL
20416dce513Schristos@cindex S_CLEAR_EXTERNAL
20516dce513SchristosMark the symbol as not externally visible.
20616dce513Schristos
20716dce513Schristos@item S_SET_WEAK
20816dce513Schristos@cindex S_SET_WEAK
20916dce513SchristosMark the symbol as weak.
21016dce513Schristos
21116dce513Schristos@item S_SET_WEAKREFR
21216dce513Schristos@cindex S_SET_WEAKREFR
21316dce513SchristosMark the symbol as the referrer in a @code{weakref} directive.  The symbol it
21416dce513Schristosaliases must have been set to the value expression before this point.  If the
21516dce513Schristosalias has already been used, the symbol is marked as used too.
21616dce513Schristos
21716dce513Schristos@item S_CLEAR_WEAKREFR
21816dce513Schristos@cindex S_CLEAR_WEAKREFR
21916dce513SchristosClear the @code{weakref} alias status of a symbol.  This is implicitly called
22016dce513Schristoswhenever a symbol is defined or set to a new expression.
22116dce513Schristos
22216dce513Schristos@item S_SET_WEAKREFD
22316dce513Schristos@cindex S_SET_WEAKREFD
22416dce513SchristosMark the symbol as the referred symbol in a @code{weakref} directive.
22516dce513SchristosImplicitly marks the symbol as weak, but see below.  It should only be called
22616dce513Schristosif the referenced symbol has just been added to the symbol table.
22716dce513Schristos
22816dce513Schristos@item S_SET_WEAKREFD
22916dce513Schristos@cindex S_SET_WEAKREFD
23016dce513SchristosClear the @code{weakref} aliased status of a symbol.  This is implicitly called
23116dce513Schristoswhenever the symbol is looked up, as part of a direct reference or a
23216dce513Schristosdefinition, but not as part of a @code{weakref} directive.
23316dce513Schristos
23416dce513Schristos@item S_SET_VOLATILE
23516dce513Schristos@cindex S_SET_VOLATILE
23616dce513SchristosIndicate that the symbol may be re-defined.
23716dce513Schristos
23816dce513Schristos@item S_CLEAR_VOLATILE
23916dce513Schristos@cindex S_CLEAR_VOLATILE
24016dce513SchristosIndicate that the symbol may no longer be re-defined.
24116dce513Schristos
24216dce513Schristos@item S_SET_FORWARD_REF
24316dce513Schristos@cindex S_SET_FORWARD_REF
24416dce513SchristosIndicate that the symbol is a forward reference, that is its value must only
24516dce513Schristosbe determined upon use.
24616dce513Schristos
24716dce513Schristos@item S_GET_TYPE
24816dce513Schristos@itemx S_GET_DESC
24916dce513Schristos@itemx S_GET_OTHER
25016dce513Schristos@cindex S_GET_TYPE
25116dce513Schristos@cindex S_GET_DESC
25216dce513Schristos@cindex S_GET_OTHER
25316dce513SchristosGet the @code{type}, @code{desc}, and @code{other} fields of the symbol.  These
25416dce513Schristosare only defined for object file formats for which they make sense (primarily
25516dce513Schristosa.out).
25616dce513Schristos
25716dce513Schristos@item S_SET_TYPE
25816dce513Schristos@itemx S_SET_DESC
25916dce513Schristos@itemx S_SET_OTHER
26016dce513Schristos@cindex S_SET_TYPE
26116dce513Schristos@cindex S_SET_DESC
26216dce513Schristos@cindex S_SET_OTHER
26316dce513SchristosSet the @code{type}, @code{desc}, and @code{other} fields of the symbol.  These
26416dce513Schristosare only defined for object file formats for which they make sense (primarily
26516dce513Schristosa.out).
26616dce513Schristos
26716dce513Schristos@item S_GET_SIZE
26816dce513Schristos@cindex S_GET_SIZE
26916dce513SchristosGet the size of a symbol.  This is only defined for object file formats for
27016dce513Schristoswhich it makes sense (primarily ELF).
27116dce513Schristos
27216dce513Schristos@item S_SET_SIZE
27316dce513Schristos@cindex S_SET_SIZE
27416dce513SchristosSet the size of a symbol.  This is only defined for object file formats for
27516dce513Schristoswhich it makes sense (primarily ELF).
27616dce513Schristos
27716dce513Schristos@item symbol_get_value_expression
27816dce513Schristos@cindex symbol_get_value_expression
27916dce513SchristosGet a pointer to an @code{expressionS} structure which represents the value of
28016dce513Schristosthe symbol as an expression.
28116dce513Schristos
28216dce513Schristos@item symbol_set_value_expression
28316dce513Schristos@cindex symbol_set_value_expression
28416dce513SchristosSet the value of a symbol to an expression.
28516dce513Schristos
28616dce513Schristos@item symbol_set_frag
28716dce513Schristos@cindex symbol_set_frag
28816dce513SchristosSet the frag where a symbol is defined.
28916dce513Schristos
29016dce513Schristos@item symbol_get_frag
29116dce513Schristos@cindex symbol_get_frag
29216dce513SchristosGet the frag where a symbol is defined.
29316dce513Schristos
29416dce513Schristos@item symbol_mark_used
29516dce513Schristos@cindex symbol_mark_used
29616dce513SchristosMark a symbol as having been used in an expression.
29716dce513Schristos
29816dce513Schristos@item symbol_clear_used
29916dce513Schristos@cindex symbol_clear_used
30016dce513SchristosClear the mark indicating that a symbol was used in an expression.
30116dce513Schristos
30216dce513Schristos@item symbol_used_p
30316dce513Schristos@cindex symbol_used_p
30416dce513SchristosReturn whether a symbol was used in an expression.
30516dce513Schristos
30616dce513Schristos@item symbol_mark_used_in_reloc
30716dce513Schristos@cindex symbol_mark_used_in_reloc
30816dce513SchristosMark a symbol as having been used by a relocation.
30916dce513Schristos
31016dce513Schristos@item symbol_clear_used_in_reloc
31116dce513Schristos@cindex symbol_clear_used_in_reloc
31216dce513SchristosClear the mark indicating that a symbol was used in a relocation.
31316dce513Schristos
31416dce513Schristos@item symbol_used_in_reloc_p
31516dce513Schristos@cindex symbol_used_in_reloc_p
31616dce513SchristosReturn whether a symbol was used in a relocation.
31716dce513Schristos
31816dce513Schristos@item symbol_mark_mri_common
31916dce513Schristos@cindex symbol_mark_mri_common
32016dce513SchristosMark a symbol as an MRI common symbol.
32116dce513Schristos
32216dce513Schristos@item symbol_clear_mri_common
32316dce513Schristos@cindex symbol_clear_mri_common
32416dce513SchristosClear the mark indicating that a symbol is an MRI common symbol.
32516dce513Schristos
32616dce513Schristos@item symbol_mri_common_p
32716dce513Schristos@cindex symbol_mri_common_p
32816dce513SchristosReturn whether a symbol is an MRI common symbol.
32916dce513Schristos
33016dce513Schristos@item symbol_mark_written
33116dce513Schristos@cindex symbol_mark_written
33216dce513SchristosMark a symbol as having been written.
33316dce513Schristos
33416dce513Schristos@item symbol_clear_written
33516dce513Schristos@cindex symbol_clear_written
33616dce513SchristosClear the mark indicating that a symbol was written.
33716dce513Schristos
33816dce513Schristos@item symbol_written_p
33916dce513Schristos@cindex symbol_written_p
34016dce513SchristosReturn whether a symbol was written.
34116dce513Schristos
34216dce513Schristos@item symbol_mark_resolved
34316dce513Schristos@cindex symbol_mark_resolved
34416dce513SchristosMark a symbol as having been resolved.
34516dce513Schristos
34616dce513Schristos@item symbol_resolved_p
34716dce513Schristos@cindex symbol_resolved_p
34816dce513SchristosReturn whether a symbol has been resolved.
34916dce513Schristos
35016dce513Schristos@item symbol_section_p
35116dce513Schristos@cindex symbol_section_p
35216dce513SchristosReturn whether a symbol is a section symbol.
35316dce513Schristos
35416dce513Schristos@item symbol_equated_p
35516dce513Schristos@cindex symbol_equated_p
35616dce513SchristosReturn whether a symbol is equated to another symbol.
35716dce513Schristos
35816dce513Schristos@item symbol_constant_p
35916dce513Schristos@cindex symbol_constant_p
36016dce513SchristosReturn whether a symbol has a constant value, including being an offset within
36116dce513Schristossome frag.
36216dce513Schristos
36316dce513Schristos@item symbol_get_bfdsym
36416dce513Schristos@cindex symbol_get_bfdsym
36516dce513SchristosReturn the BFD symbol associated with a symbol.
36616dce513Schristos
36716dce513Schristos@item symbol_set_bfdsym
36816dce513Schristos@cindex symbol_set_bfdsym
36916dce513SchristosSet the BFD symbol associated with a symbol.
37016dce513Schristos
37116dce513Schristos@item symbol_get_obj
37216dce513Schristos@cindex symbol_get_obj
37316dce513SchristosReturn a pointer to the @code{OBJ_SYMFIELD_TYPE} field of a symbol.
37416dce513Schristos
37516dce513Schristos@item symbol_set_obj
37616dce513Schristos@cindex symbol_set_obj
37716dce513SchristosSet the @code{OBJ_SYMFIELD_TYPE} field of a symbol.
37816dce513Schristos
37916dce513Schristos@item symbol_get_tc
38016dce513Schristos@cindex symbol_get_tc
38116dce513SchristosReturn a pointer to the @code{TC_SYMFIELD_TYPE} field of a symbol.
38216dce513Schristos
38316dce513Schristos@item symbol_set_tc
38416dce513Schristos@cindex symbol_set_tc
38516dce513SchristosSet the @code{TC_SYMFIELD_TYPE} field of a symbol.
38616dce513Schristos
38716dce513Schristos@end table
38816dce513Schristos
38916dce513SchristosGAS attempts to store local
39016dce513Schristossymbols--symbols which will not be written to the output file--using a
39116dce513Schristosdifferent structure, @code{struct local_symbol}.  This structure can only
39216dce513Schristosrepresent symbols whose value is an offset within a frag.
39316dce513Schristos
39416dce513SchristosCode outside of the symbol handler will always deal with @code{symbolS}
39516dce513Schristosstructures and use the accessor functions.  The accessor functions correctly
39616dce513Schristosdeal with local symbols.  @code{struct local_symbol} is much smaller than
39716dce513Schristos@code{symbolS} (which also automatically creates a bfd @code{asymbol}
39816dce513Schristosstructure), so this saves space when assembling large files.
39916dce513Schristos
40016dce513Schristos@node Expressions
40116dce513Schristos@subsection Expressions
40216dce513Schristos@cindex internals, expressions
40316dce513Schristos@cindex expressions, internal
40416dce513Schristos@cindex expressionS structure
40516dce513Schristos
40616dce513SchristosExpressions are stored in an @code{expressionS} structure.  The structure is
40716dce513Schristosdefined in @file{expr.h}.
40816dce513Schristos
40916dce513Schristos@cindex expression
41016dce513SchristosThe macro @code{expression} will create an @code{expressionS} structure based
41116dce513Schristoson the text found at the global variable @code{input_line_pointer}.
41216dce513Schristos
41316dce513Schristos@cindex make_expr_symbol
41416dce513Schristos@cindex expr_symbol_where
41516dce513SchristosA single @code{expressionS} structure can represent a single operation.
41616dce513SchristosComplex expressions are formed by creating @dfn{expression symbols} and
41716dce513Schristoscombining them in @code{expressionS} structures.  An expression symbol is
41816dce513Schristoscreated by calling @code{make_expr_symbol}.  An expression symbol should
41916dce513Schristosnaturally never appear in a symbol table, and the implementation of
42016dce513Schristos@code{S_IS_LOCAL} (@pxref{Symbols}) reflects that.  The function
42116dce513Schristos@code{expr_symbol_where} returns non-zero if a symbol is an expression symbol,
42216dce513Schristosand also returns the file and line for the expression which caused it to be
42316dce513Schristoscreated.
42416dce513Schristos
42516dce513SchristosThe @code{expressionS} structure has two symbol fields, a number field, an
42616dce513Schristosoperator field, and a field indicating whether the number is unsigned.
42716dce513Schristos
42816dce513SchristosThe operator field is of type @code{operatorT}, and describes how to interpret
42916dce513Schristosthe other fields; see the definition in @file{expr.h} for the possibilities.
43016dce513Schristos
43116dce513SchristosAn @code{operatorT} value of @code{O_big} indicates either a floating point
43216dce513Schristosnumber, stored in the global variable @code{generic_floating_point_number}, or
43316dce513Schristosan integer too large to store in an @code{offsetT} type, stored in the global
43416dce513Schristosarray @code{generic_bignum}.  This rather inflexible approach makes it
43516dce513Schristosimpossible to use floating point numbers or large expressions in complex
43616dce513Schristosexpressions.
43716dce513Schristos
43816dce513Schristos@node Fixups
43916dce513Schristos@subsection Fixups
44016dce513Schristos@cindex internals, fixups
44116dce513Schristos@cindex fixups
44216dce513Schristos@cindex fixS structure
44316dce513Schristos
44416dce513SchristosA @dfn{fixup} is basically anything which can not be resolved in the first
44516dce513Schristospass.  Sometimes a fixup can be resolved by the end of the assembly; if not,
44616dce513Schristosthe fixup becomes a relocation entry in the object file.
44716dce513Schristos
44816dce513Schristos@cindex fix_new
44916dce513Schristos@cindex fix_new_exp
45016dce513SchristosA fixup is created by a call to @code{fix_new} or @code{fix_new_exp}.  Both
45116dce513Schristostake a frag (@pxref{Frags}), a position within the frag, a size, an indication
45216dce513Schristosof whether the fixup is PC relative, and a type.
45316dce513SchristosThe type is nominally a @code{bfd_reloc_code_real_type}, but several
45416dce513Schristostargets use other type codes to represent fixups that can not be described as
45516dce513Schristosrelocations.
45616dce513Schristos
45716dce513SchristosThe @code{fixS} structure has a number of fields, several of which are obsolete
45816dce513Schristosor are only used by a particular target.  The important fields are:
45916dce513Schristos
46016dce513Schristos@table @code
46116dce513Schristos@item fx_frag
46216dce513SchristosThe frag (@pxref{Frags}) this fixup is in.
46316dce513Schristos
46416dce513Schristos@item fx_where
46516dce513SchristosThe location within the frag where the fixup occurs.
46616dce513Schristos
46716dce513Schristos@item fx_addsy
46816dce513SchristosThe symbol this fixup is against.  Typically, the value of this symbol is added
46916dce513Schristosinto the object contents.  This may be NULL.
47016dce513Schristos
47116dce513Schristos@item fx_subsy
47216dce513SchristosThe value of this symbol is subtracted from the object contents.  This is
47316dce513Schristosnormally NULL.
47416dce513Schristos
47516dce513Schristos@item fx_offset
47616dce513SchristosA number which is added into the fixup.
47716dce513Schristos
47816dce513Schristos@item fx_addnumber
47916dce513SchristosSome CPU backends use this field to convey information between
48016dce513Schristos@code{md_apply_fix} and @code{tc_gen_reloc}.  The machine independent code does
48116dce513Schristosnot use it.
48216dce513Schristos
48316dce513Schristos@item fx_next
48416dce513SchristosThe next fixup in the section.
48516dce513Schristos
48616dce513Schristos@item fx_r_type
48716dce513SchristosThe type of the fixup.
48816dce513Schristos
48916dce513Schristos@item fx_size
49016dce513SchristosThe size of the fixup.  This is mostly used for error checking.
49116dce513Schristos
49216dce513Schristos@item fx_pcrel
49316dce513SchristosWhether the fixup is PC relative.
49416dce513Schristos
49516dce513Schristos@item fx_done
49616dce513SchristosNon-zero if the fixup has been applied, and no relocation entry needs to be
49716dce513Schristosgenerated.
49816dce513Schristos
49916dce513Schristos@item fx_file
50016dce513Schristos@itemx fx_line
50116dce513SchristosThe file and line where the fixup was created.
50216dce513Schristos
50316dce513Schristos@item tc_fix_data
50416dce513SchristosThis has the type @code{TC_FIX_TYPE}, and is only defined if the target defines
50516dce513Schristosthat macro.
50616dce513Schristos@end table
50716dce513Schristos
50816dce513Schristos@node Frags
50916dce513Schristos@subsection Frags
51016dce513Schristos@cindex internals, frags
51116dce513Schristos@cindex frags
51216dce513Schristos@cindex fragS structure.
51316dce513Schristos
51416dce513SchristosThe @code{fragS} structure is defined in @file{as.h}.  Each frag represents a
51516dce513Schristosportion of the final object file.  As GAS reads the source file, it creates
51616dce513Schristosfrags to hold the data that it reads.  At the end of the assembly the frags and
51716dce513Schristosfixups are processed to produce the final contents.
51816dce513Schristos
51916dce513Schristos@table @code
52016dce513Schristos@item fr_address
52116dce513SchristosThe address of the frag.  This is not set until the assembler rescans the list
52216dce513Schristosof all frags after the entire input file is parsed.  The function
52316dce513Schristos@code{relax_segment} fills in this field.
52416dce513Schristos
52516dce513Schristos@item fr_next
52616dce513SchristosPointer to the next frag in this (sub)section.
52716dce513Schristos
52816dce513Schristos@item fr_fix
52916dce513SchristosFixed number of characters we know we're going to emit to the output file.  May
53016dce513Schristosbe zero.
53116dce513Schristos
53216dce513Schristos@item fr_var
53316dce513SchristosVariable number of characters we may output, after the initial @code{fr_fix}
53416dce513Schristoscharacters.  May be zero.
53516dce513Schristos
53616dce513Schristos@item fr_offset
53716dce513SchristosThe interpretation of this field is controlled by @code{fr_type}.  Generally,
53816dce513Schristosif @code{fr_var} is non-zero, this is a repeat count: the @code{fr_var}
53916dce513Schristoscharacters are output @code{fr_offset} times.
54016dce513Schristos
54116dce513Schristos@item line
54216dce513SchristosHolds line number info when an assembler listing was requested.
54316dce513Schristos
54416dce513Schristos@item fr_type
54516dce513SchristosRelaxation state.  This field indicates the interpretation of @code{fr_offset},
54616dce513Schristos@code{fr_symbol} and the variable-length tail of the frag, as well as the
54716dce513Schristostreatment it gets in various phases of processing.  It does not affect the
54816dce513Schristosinitial @code{fr_fix} characters; they are always supposed to be output
54916dce513Schristosverbatim (fixups aside).  See below for specific values this field can have.
55016dce513Schristos
55116dce513Schristos@item fr_subtype
55216dce513SchristosRelaxation substate.  If the macro @code{md_relax_frag} isn't defined, this is
55316dce513Schristosassumed to be an index into @code{TC_GENERIC_RELAX_TABLE} for the generic
55416dce513Schristosrelaxation code to process (@pxref{Relaxation}).  If @code{md_relax_frag} is
55516dce513Schristosdefined, this field is available for any use by the CPU-specific code.
55616dce513Schristos
55716dce513Schristos@item fr_symbol
55816dce513SchristosThis normally indicates the symbol to use when relaxing the frag according to
55916dce513Schristos@code{fr_type}.
56016dce513Schristos
56116dce513Schristos@item fr_opcode
56216dce513SchristosPoints to the lowest-addressed byte of the opcode, for use in relaxation.
56316dce513Schristos
56416dce513Schristos@item tc_frag_data
56516dce513SchristosTarget specific fragment data of type TC_FRAG_TYPE.
56616dce513SchristosOnly present if @code{TC_FRAG_TYPE} is defined.
56716dce513Schristos
56816dce513Schristos@item fr_file
56916dce513Schristos@itemx fr_line
57016dce513SchristosThe file and line where this frag was last modified.
57116dce513Schristos
57216dce513Schristos@item fr_literal
57316dce513SchristosDeclared as a one-character array, this last field grows arbitrarily large to
57416dce513Schristoshold the actual contents of the frag.
57516dce513Schristos@end table
57616dce513Schristos
57716dce513SchristosThese are the possible relaxation states, provided in the enumeration type
57816dce513Schristos@code{relax_stateT}, and the interpretations they represent for the other
57916dce513Schristosfields:
58016dce513Schristos
58116dce513Schristos@table @code
58216dce513Schristos@item rs_align
58316dce513Schristos@itemx rs_align_code
58416dce513SchristosThe start of the following frag should be aligned on some boundary.  In this
58516dce513Schristosfrag, @code{fr_offset} is the logarithm (base 2) of the alignment in bytes.
58616dce513Schristos(For example, if alignment on an 8-byte boundary were desired, @code{fr_offset}
58716dce513Schristoswould have a value of 3.)  The variable characters indicate the fill pattern to
58816dce513Schristosbe used.  The @code{fr_subtype} field holds the maximum number of bytes to skip
58916dce513Schristoswhen doing this alignment.  If more bytes are needed, the alignment is not
59016dce513Schristosdone.  An @code{fr_subtype} value of 0 means no maximum, which is the normal
59116dce513Schristoscase.  Target backends can use @code{rs_align_code} to handle certain types of
59216dce513Schristosalignment differently.
59316dce513Schristos
59416dce513Schristos@item rs_broken_word
59516dce513SchristosThis indicates that ``broken word'' processing should be done (@pxref{Broken
59616dce513Schristoswords}).  If broken word processing is not necessary on the target machine,
59716dce513Schristosthis enumerator value will not be defined.
59816dce513Schristos
59916dce513Schristos@item rs_cfa
60016dce513SchristosThis state is used to implement exception frame optimizations.  The
60116dce513Schristos@code{fr_symbol} is an expression symbol for the subtraction which may be
60216dce513Schristosrelaxed.  The @code{fr_opcode} field holds the frag for the preceding command
60316dce513Schristosbyte.  The @code{fr_offset} field holds the offset within that frag.  The
60416dce513Schristos@code{fr_subtype} field is used during relaxation to hold the current size of
60516dce513Schristosthe frag.
60616dce513Schristos
60716dce513Schristos@item rs_fill
60816dce513SchristosThe variable characters are to be repeated @code{fr_offset} times.  If
60916dce513Schristos@code{fr_offset} is 0, this frag has a length of @code{fr_fix}.  Most frags
61016dce513Schristoshave this type.
61116dce513Schristos
61216dce513Schristos@item rs_leb128
61316dce513SchristosThis state is used to implement the DWARF ``little endian base 128''
61416dce513Schristosvariable length number format.  The @code{fr_symbol} is always an expression
61516dce513Schristossymbol, as constant expressions are emitted directly.  The @code{fr_offset}
61616dce513Schristosfield is used during relaxation to hold the previous size of the number so
61716dce513Schristosthat we can determine if the fragment changed size.
61816dce513Schristos
61916dce513Schristos@item rs_machine_dependent
62016dce513SchristosDisplacement relaxation is to be done on this frag.  The target is indicated by
62116dce513Schristos@code{fr_symbol} and @code{fr_offset}, and @code{fr_subtype} indicates the
62216dce513Schristosparticular machine-specific addressing mode desired.  @xref{Relaxation}.
62316dce513Schristos
62416dce513Schristos@item rs_org
62516dce513SchristosThe start of the following frag should be pushed back to some specific offset
62616dce513Schristoswithin the section.  (Some assemblers use the value as an absolute address; GAS
62716dce513Schristosdoes not handle final absolute addresses, but rather requires that the linker
62816dce513Schristosset them.)  The offset is given by @code{fr_symbol} and @code{fr_offset}; one
62916dce513Schristoscharacter from the variable-length tail is used as the fill character.
63016dce513Schristos@end table
63116dce513Schristos
63216dce513Schristos@cindex frchainS structure
63316dce513SchristosA chain of frags is built up for each subsection.  The data structure
63416dce513Schristosdescribing a chain is called a @code{frchainS}, and contains the following
63516dce513Schristosfields:
63616dce513Schristos
63716dce513Schristos@table @code
63816dce513Schristos@item frch_root
63916dce513SchristosPoints to the first frag in the chain.  May be NULL if there are no frags in
64016dce513Schristosthis chain.
64116dce513Schristos@item frch_last
64216dce513SchristosPoints to the last frag in the chain, or NULL if there are none.
64316dce513Schristos@item frch_next
64416dce513SchristosNext in the list of @code{frchainS} structures.
64516dce513Schristos@item frch_seg
64616dce513SchristosIndicates the section this frag chain belongs to.
64716dce513Schristos@item frch_subseg
64816dce513SchristosSubsection (subsegment) number of this frag chain.
64916dce513Schristos@item fix_root, fix_tail
65016dce513SchristosPoint to first and last @code{fixS} structures associated with this subsection.
65116dce513Schristos@item frch_obstack
65216dce513SchristosNot currently used.  Intended to be used for frag allocation for this
65316dce513Schristossubsection.  This should reduce frag generation caused by switching sections.
65416dce513Schristos@item frch_frag_now
65516dce513SchristosThe current frag for this subsegment.
65616dce513Schristos@end table
65716dce513Schristos
65816dce513SchristosA @code{frchainS} corresponds to a subsection; each section has a list of
65916dce513Schristos@code{frchainS} records associated with it.  In most cases, only one subsection
66016dce513Schristosof each section is used, so the list will only be one element long, but any
66116dce513Schristosprocessing of frag chains should be prepared to deal with multiple chains per
66216dce513Schristossection.
66316dce513Schristos
66416dce513SchristosAfter the input files have been completely processed, and no more frags are to
66516dce513Schristosbe generated, the frag chains are joined into one per section for further
66616dce513Schristosprocessing.  After this point, it is safe to operate on one chain per section.
66716dce513Schristos
66816dce513SchristosThe assembler always has a current frag, named @code{frag_now}.  More space is
66916dce513Schristosallocated for the current frag using the @code{frag_more} function; this
67016dce513Schristosreturns a pointer to the amount of requested space.  The function
67116dce513Schristos@code{frag_room} says by how much the current frag can be extended.
67216dce513SchristosRelaxing is done using variant frags allocated by @code{frag_var}
67316dce513Schristosor @code{frag_variant} (@pxref{Relaxation}).
67416dce513Schristos
67516dce513Schristos@node GAS processing
67616dce513Schristos@section What GAS does when it runs
67716dce513Schristos@cindex internals, overview
67816dce513Schristos
67916dce513SchristosThis is a quick look at what an assembler run looks like.
68016dce513Schristos
68116dce513Schristos@itemize @bullet
68216dce513Schristos@item
68316dce513SchristosThe assembler initializes itself by calling various init routines.
68416dce513Schristos
68516dce513Schristos@item
68616dce513SchristosFor each source file, the @code{read_a_source_file} function reads in the file
68716dce513Schristosand parses it.  The global variable @code{input_line_pointer} points to the
68816dce513Schristoscurrent text; it is guaranteed to be correct up to the end of the line, but not
68916dce513Schristosfarther.
69016dce513Schristos
69116dce513Schristos@item
69216dce513SchristosFor each line, the assembler passes labels to the @code{colon} function, and
69316dce513Schristosisolates the first word.  If it looks like a pseudo-op, the word is looked up
69416dce513Schristosin the pseudo-op hash table @code{po_hash} and dispatched to a pseudo-op
69516dce513Schristosroutine.  Otherwise, the target dependent @code{md_assemble} routine is called
69616dce513Schristosto parse the instruction.
69716dce513Schristos
69816dce513Schristos@item
69916dce513SchristosWhen pseudo-ops or instructions output data, they add it to a frag, calling
70016dce513Schristos@code{frag_more} to get space to store it in.
70116dce513Schristos
70216dce513Schristos@item
70316dce513SchristosPseudo-ops and instructions can also output fixups created by @code{fix_new} or
70416dce513Schristos@code{fix_new_exp}.
70516dce513Schristos
70616dce513Schristos@item
70716dce513SchristosFor certain targets, instructions can create variant frags which are used to
70816dce513Schristosstore relaxation information (@pxref{Relaxation}).
70916dce513Schristos
71016dce513Schristos@item
71116dce513SchristosWhen the input file is finished, the @code{write_object_file} routine is
71216dce513Schristoscalled.  It assigns addresses to all the frags (@code{relax_segment}), resolves
71316dce513Schristosall the fixups (@code{fixup_segment}), resolves all the symbol values (using
71416dce513Schristos@code{resolve_symbol_value}), and finally writes out the file.
71516dce513Schristos@end itemize
71616dce513Schristos
71716dce513Schristos@node Porting GAS
71816dce513Schristos@section Porting GAS
71916dce513Schristos@cindex porting
72016dce513Schristos
72116dce513SchristosEach GAS target specifies two main things: the CPU file and the object format
72216dce513Schristosfile.  Two main switches in the @file{configure.ac} file handle this.  The
72316dce513Schristosfirst switches on CPU type to set the shell variable @code{cpu_type}.  The
72416dce513Schristossecond switches on the entire target to set the shell variable @code{fmt}.
72516dce513Schristos
72616dce513SchristosThe configure script uses the value of @code{cpu_type} to select two files in
72716dce513Schristosthe @file{config} directory: @file{tc-@var{CPU}.c} and @file{tc-@var{CPU}.h}.
72816dce513SchristosThe configuration process will create a file named @file{targ-cpu.h} in the
72916dce513Schristosbuild directory which includes @file{tc-@var{CPU}.h}.
73016dce513Schristos
73116dce513SchristosThe configure script also uses the value of @code{fmt} to select two files:
73216dce513Schristos@file{obj-@var{fmt}.c} and @file{obj-@var{fmt}.h}.  The configuration process
73316dce513Schristoswill create a file named @file{obj-format.h} in the build directory which
73416dce513Schristosincludes @file{obj-@var{fmt}.h}.
73516dce513Schristos
73616dce513SchristosYou can also set the emulation in the configure script by setting the @code{em}
73716dce513Schristosvariable.  Normally the default value of @samp{generic} is fine.  The
73816dce513Schristosconfiguration process will create a file named @file{targ-env.h} in the build
73916dce513Schristosdirectory which includes @file{te-@var{em}.h}.
74016dce513Schristos
74116dce513SchristosThere is a special case for COFF. For historical reason, the GNU COFF
74216dce513Schristosassembler doesn't follow the documented behavior on certain debug symbols for
74316dce513Schristosthe compatibility with other COFF assemblers. A port can define
74416dce513Schristos@code{STRICTCOFF} in the configure script to make the GNU COFF assembler
74516dce513Schristosto follow the documented behavior.
74616dce513Schristos
74716dce513SchristosPorting GAS to a new CPU requires writing the @file{tc-@var{CPU}} files.
74816dce513SchristosPorting GAS to a new object file format requires writing the
74916dce513Schristos@file{obj-@var{fmt}} files.  There is sometimes some interaction between these
75016dce513Schristostwo files, but it is normally minimal.
75116dce513Schristos
75216dce513SchristosThe best approach is, of course, to copy existing files.  The documentation
75316dce513Schristosbelow assumes that you are looking at existing files to see usage details.
75416dce513Schristos
75516dce513SchristosThese interfaces have grown over time, and have never been carefully thought
75616dce513Schristosout or designed.  Nothing about the interfaces described here is cast in stone.
75716dce513SchristosIt is possible that they will change from one version of the assembler to the
75816dce513Schristosnext.  Also, new macros are added all the time as they are needed.
75916dce513Schristos
76016dce513Schristos@menu
76116dce513Schristos* CPU backend::                 Writing a CPU backend
76216dce513Schristos* Object format backend::       Writing an object format backend
76316dce513Schristos* Emulations::                  Writing emulation files
76416dce513Schristos@end menu
76516dce513Schristos
76616dce513Schristos@node CPU backend
76716dce513Schristos@subsection Writing a CPU backend
76816dce513Schristos@cindex CPU backend
76916dce513Schristos@cindex @file{tc-@var{CPU}}
77016dce513Schristos
77116dce513SchristosThe CPU backend files are the heart of the assembler.  They are the only parts
77216dce513Schristosof the assembler which actually know anything about the instruction set of the
77316dce513Schristosprocessor.
77416dce513Schristos
77516dce513SchristosYou must define a reasonably small list of macros and functions in the CPU
77616dce513Schristosbackend files.  You may define a large number of additional macros in the CPU
77716dce513Schristosbackend files, not all of which are documented here.  You must, of course,
77816dce513Schristosdefine macros in the @file{.h} file, which is included by every assembler
77916dce513Schristossource file.  You may define the functions as macros in the @file{.h} file, or
78016dce513Schristosas functions in the @file{.c} file.
78116dce513Schristos
78216dce513Schristos@table @code
78316dce513Schristos@item TC_@var{CPU}
78416dce513Schristos@cindex TC_@var{CPU}
78516dce513SchristosBy convention, you should define this macro in the @file{.h} file.  For
78616dce513Schristosexample, @file{tc-m68k.h} defines @code{TC_M68K}.  You might have to use this
78716dce513Schristosif it is necessary to add CPU specific code to the object format file.
78816dce513Schristos
78916dce513Schristos@item TARGET_FORMAT
79016dce513SchristosThis macro is the BFD target name to use when creating the output file.  This
79116dce513Schristoswill normally depend upon the @code{OBJ_@var{FMT}} macro.
79216dce513Schristos
79316dce513Schristos@item TARGET_ARCH
79416dce513SchristosThis macro is the BFD architecture to pass to @code{bfd_set_arch_mach}.
79516dce513Schristos
79616dce513Schristos@item TARGET_MACH
79716dce513SchristosThis macro is the BFD machine number to pass to @code{bfd_set_arch_mach}.  If
79816dce513Schristosit is not defined, GAS will use 0.
79916dce513Schristos
80016dce513Schristos@item TARGET_BYTES_BIG_ENDIAN
80116dce513SchristosYou should define this macro to be non-zero if the target is big endian, and
80216dce513Schristoszero if the target is little endian.
80316dce513Schristos
80416dce513Schristos@item md_shortopts
80516dce513Schristos@itemx md_longopts
80616dce513Schristos@itemx md_longopts_size
80716dce513Schristos@itemx md_parse_option
80816dce513Schristos@itemx md_show_usage
80916dce513Schristos@itemx md_after_parse_args
81016dce513Schristos@cindex md_shortopts
81116dce513Schristos@cindex md_longopts
81216dce513Schristos@cindex md_longopts_size
81316dce513Schristos@cindex md_parse_option
81416dce513Schristos@cindex md_show_usage
81516dce513Schristos@cindex md_after_parse_args
81616dce513SchristosGAS uses these variables and functions during option processing.
81716dce513Schristos@code{md_shortopts} is a @code{const char *} which GAS adds to the machine
81816dce513Schristosindependent string passed to @code{getopt}.  @code{md_longopts} is a
81916dce513Schristos@code{struct option []} which GAS adds to the machine independent long options
82016dce513Schristospassed to @code{getopt}; you may use @code{OPTION_MD_BASE}, defined in
82116dce513Schristos@file{as.h}, as the start of a set of long option indices, if necessary.
82216dce513Schristos@code{md_longopts_size} is a @code{size_t} holding the size @code{md_longopts}.
82316dce513Schristos
82416dce513SchristosGAS will call @code{md_parse_option} whenever @code{getopt} returns an
82516dce513Schristosunrecognized code, presumably indicating a special code value which appears in
82616dce513Schristos@code{md_longopts}.  This function should return non-zero if it handled the
82716dce513Schristosoption and zero otherwise.  There is no need to print a message about an option
82816dce513Schristosnot being recognized.  This will be handled by the generic code.
82916dce513Schristos
83016dce513SchristosGAS will call @code{md_show_usage} when a usage message is printed; it should
83116dce513Schristosprint a description of the machine specific options. @code{md_after_pase_args},
83216dce513Schristosif defined, is called after all options are processed, to let the backend
83316dce513Schristosoverride settings done by the generic option parsing.
83416dce513Schristos
83516dce513Schristos@item md_begin
83616dce513Schristos@cindex md_begin
83716dce513SchristosGAS will call this function at the start of the assembly, after the command
83816dce513Schristosline arguments have been parsed and all the machine independent initializations
83916dce513Schristoshave been completed.
84016dce513Schristos
84116dce513Schristos@item md_cleanup
84216dce513Schristos@cindex md_cleanup
84316dce513SchristosIf you define this macro, GAS will call it at the end of each input file.
84416dce513Schristos
84516dce513Schristos@item md_assemble
84616dce513Schristos@cindex md_assemble
84716dce513SchristosGAS will call this function for each input line which does not contain a
84816dce513Schristospseudo-op.  The argument is a null terminated string.  The function should
84916dce513Schristosassemble the string as an instruction with operands.  Normally
85016dce513Schristos@code{md_assemble} will do this by calling @code{frag_more} and writing out
85116dce513Schristossome bytes (@pxref{Frags}).  @code{md_assemble} will call @code{fix_new} to
85216dce513Schristoscreate fixups as needed (@pxref{Fixups}).  Targets which need to do special
85316dce513Schristospurpose relaxation will call @code{frag_var}.
85416dce513Schristos
85516dce513Schristos@item md_pseudo_table
85616dce513Schristos@cindex md_pseudo_table
85716dce513SchristosThis is a const array of type @code{pseudo_typeS}.  It is a mapping from
85816dce513Schristospseudo-op names to functions.  You should use this table to implement
85916dce513Schristospseudo-ops which are specific to the CPU.
86016dce513Schristos
86116dce513Schristos@item tc_conditional_pseudoop
86216dce513Schristos@cindex tc_conditional_pseudoop
86316dce513SchristosIf this macro is defined, GAS will call it with a @code{pseudo_typeS} argument.
86416dce513SchristosIt should return non-zero if the pseudo-op is a conditional which controls
86516dce513Schristoswhether code is assembled, such as @samp{.if}.  GAS knows about the normal
86616dce513Schristosconditional pseudo-ops, and you should normally not have to define this macro.
86716dce513Schristos
86816dce513Schristos@item comment_chars
86916dce513Schristos@cindex comment_chars
87016dce513SchristosThis is a null terminated @code{const char} array of characters which start a
87116dce513Schristoscomment.
87216dce513Schristos
87316dce513Schristos@item tc_comment_chars
87416dce513Schristos@cindex tc_comment_chars
87516dce513SchristosIf this macro is defined, GAS will use it instead of @code{comment_chars}.
87616dce513SchristosThis has the advantage that this macro does not have to refer to a constant
87716dce513Schristosarray.
87816dce513Schristos
87916dce513Schristos@item tc_symbol_chars
88016dce513Schristos@cindex tc_symbol_chars
88116dce513SchristosIf this macro is defined, it is a pointer to a null terminated list of
88216dce513Schristoscharacters which may appear in an operand.  GAS already assumes that all
88316dce513Schristosalphanumeric characters, and @samp{$}, @samp{.}, and @samp{_} may appear in an
88416dce513Schristosoperand (see @samp{symbol_chars} in @file{app.c}).  This macro may be defined
88516dce513Schristosto treat additional characters as appearing in an operand.  This affects the
88616dce513Schristosway in which GAS removes whitespace before passing the string to
88716dce513Schristos@samp{md_assemble}.
88816dce513Schristos
88916dce513Schristos@item line_comment_chars
89016dce513Schristos@cindex line_comment_chars
89116dce513SchristosThis is a null terminated @code{const char} array of characters which start a
89216dce513Schristoscomment when they appear at the start of a line.
89316dce513Schristos
89416dce513Schristos@item line_separator_chars
89516dce513Schristos@cindex line_separator_chars
89616dce513SchristosThis is a null terminated @code{const char} array of characters which separate
89716dce513Schristoslines (null and newline are such characters by default, and need not be
89816dce513Schristoslisted in this array).  Note that line_separator_chars do not separate lines
89916dce513Schristosif found in a comment, such as after a character in line_comment_chars or
90016dce513Schristoscomment_chars.
90116dce513Schristos
90216dce513Schristos@item tc_line_separator_chars
90316dce513Schristos@cindex tc_line_separator_chars
90416dce513SchristosIf this macro is defined, GAS will use it instead of
90516dce513Schristos@code{line_separator_chars}.  This has the advantage that this macro does not
90616dce513Schristoshave to refer to a constant array.
90716dce513Schristos
90816dce513Schristos
90916dce513Schristos@item EXP_CHARS
91016dce513Schristos@cindex EXP_CHARS
91116dce513SchristosThis is a null terminated @code{const char} array of characters which may be
91216dce513Schristosused as the exponent character in a floating point number.  This is normally
91316dce513Schristos@code{"eE"}.
91416dce513Schristos
91516dce513Schristos@item FLT_CHARS
91616dce513Schristos@cindex FLT_CHARS
91716dce513SchristosThis is a null terminated @code{const char} array of characters which may be
91816dce513Schristosused to indicate a floating point constant.  A zero followed by one of these
91916dce513Schristoscharacters is assumed to be followed by a floating point number; thus they
92016dce513Schristosoperate the way that @code{0x} is used to indicate a hexadecimal constant.
92116dce513SchristosUsually this includes @samp{r} and @samp{f}.
92216dce513Schristos
92316dce513Schristos@item LEX_AT
92416dce513Schristos@cindex LEX_AT
92516dce513SchristosYou may define this macro to the lexical type of the @kbd{@@} character.  The
92616dce513Schristosdefault is zero.
92716dce513Schristos
92816dce513SchristosLexical types are a combination of @code{LEX_NAME} and @code{LEX_BEGIN_NAME},
92916dce513Schristosboth defined in @file{read.h}.  @code{LEX_NAME} indicates that the character
93016dce513Schristosmay appear in a name.  @code{LEX_BEGIN_NAME} indicates that the character may
93116dce513Schristosappear at the beginning of a name.
93216dce513Schristos
93316dce513Schristos@item LEX_BR
93416dce513Schristos@cindex LEX_BR
93516dce513SchristosYou may define this macro to the lexical type of the brace characters @kbd{@{},
93616dce513Schristos@kbd{@}}, @kbd{[}, and @kbd{]}.  The default value is zero.
93716dce513Schristos
93816dce513Schristos@item LEX_PCT
93916dce513Schristos@cindex LEX_PCT
94016dce513SchristosYou may define this macro to the lexical type of the @kbd{%} character.  The
94116dce513Schristosdefault value is zero.
94216dce513Schristos
94316dce513Schristos@item LEX_QM
94416dce513Schristos@cindex LEX_QM
94516dce513SchristosYou may define this macro to the lexical type of the @kbd{?} character.  The
94616dce513Schristosdefault value it zero.
94716dce513Schristos
94816dce513Schristos@item LEX_DOLLAR
94916dce513Schristos@cindex LEX_DOLLAR
95016dce513SchristosYou may define this macro to the lexical type of the @kbd{$} character.  The
95116dce513Schristosdefault value is @code{LEX_NAME | LEX_BEGIN_NAME}.
95216dce513Schristos
95316dce513Schristos@item NUMBERS_WITH_SUFFIX
95416dce513Schristos@cindex NUMBERS_WITH_SUFFIX
95516dce513SchristosWhen this macro is defined to be non-zero, the parser allows the radix of a
95616dce513Schristosconstant to be indicated with a suffix.  Valid suffixes are binary (B),
95716dce513Schristosoctal (Q), and hexadecimal (H).  Case is not significant.
95816dce513Schristos
95916dce513Schristos@item SINGLE_QUOTE_STRINGS
96016dce513Schristos@cindex SINGLE_QUOTE_STRINGS
96116dce513SchristosIf you define this macro, GAS will treat single quotes as string delimiters.
96216dce513SchristosNormally only double quotes are accepted as string delimiters.
96316dce513Schristos
96416dce513Schristos@item NO_STRING_ESCAPES
96516dce513Schristos@cindex NO_STRING_ESCAPES
96616dce513SchristosIf you define this macro, GAS will not permit escape sequences in a string.
96716dce513Schristos
96816dce513Schristos@item ONLY_STANDARD_ESCAPES
96916dce513Schristos@cindex ONLY_STANDARD_ESCAPES
97016dce513SchristosIf you define this macro, GAS will warn about the use of nonstandard escape
97116dce513Schristossequences in a string.
97216dce513Schristos
97316dce513Schristos@item md_start_line_hook
97416dce513Schristos@cindex md_start_line_hook
97516dce513SchristosIf you define this macro, GAS will call it at the start of each line.
97616dce513Schristos
97716dce513Schristos@item LABELS_WITHOUT_COLONS
97816dce513Schristos@cindex LABELS_WITHOUT_COLONS
97916dce513SchristosIf you define this macro, GAS will assume that any text at the start of a line
98016dce513Schristosis a label, even if it does not have a colon.
98116dce513Schristos
98216dce513Schristos@item TC_START_LABEL
98316dce513Schristos@itemx TC_START_LABEL_WITHOUT_COLON
98416dce513Schristos@cindex TC_START_LABEL
98516dce513SchristosYou may define this macro to control what GAS considers to be a label.  The
98616dce513Schristosdefault definition is to accept any name followed by a colon character.
98716dce513Schristos
98816dce513Schristos@item TC_START_LABEL_WITHOUT_COLON
98916dce513Schristos@cindex TC_START_LABEL_WITHOUT_COLON
99016dce513SchristosSame as TC_START_LABEL, but should be used instead of TC_START_LABEL when
99116dce513SchristosLABELS_WITHOUT_COLONS is defined.
99216dce513Schristos
99316dce513Schristos@item TC_FAKE_LABEL
99416dce513Schristos@cindex TC_FAKE_LABEL
99516dce513SchristosYou may define this macro to control what GAS considers to be a fake
99616dce513Schristoslabel.  The default fake label is FAKE_LABEL_NAME.
99716dce513Schristos
99816dce513Schristos@item NO_PSEUDO_DOT
99916dce513Schristos@cindex NO_PSEUDO_DOT
100016dce513SchristosIf you define this macro, GAS will not require pseudo-ops to start with a
100116dce513Schristos@kbd{.} character.
100216dce513Schristos
100316dce513Schristos@item TC_EQUAL_IN_INSN
100416dce513Schristos@cindex TC_EQUAL_IN_INSN
100516dce513SchristosIf you define this macro, it should return nonzero if the instruction is
100616dce513Schristospermitted to contain an @kbd{=} character.  GAS will call it with two
100716dce513Schristosarguments, the character before the @kbd{=} character, and the value of
100816dce513Schristosthe string preceding the equal sign. GAS uses this macro to decide if a
100916dce513Schristos@kbd{=} is an assignment or an instruction.
101016dce513Schristos
101116dce513Schristos@item TC_EOL_IN_INSN
101216dce513Schristos@cindex TC_EOL_IN_INSN
101316dce513SchristosIf you define this macro, it should return nonzero if the current input line
101416dce513Schristospointer should be treated as the end of a line.
101516dce513Schristos
101616dce513Schristos@item TC_CASE_SENSITIVE
101716dce513Schristos@cindex TC_CASE_SENSITIVE
101816dce513SchristosDefine this macro if instruction mnemonics and pseudos are case sensitive.
101916dce513SchristosThe default is to have it undefined giving case insensitive names.
102016dce513Schristos
102116dce513Schristos@item md_parse_name
102216dce513Schristos@cindex md_parse_name
102316dce513SchristosIf this macro is defined, GAS will call it for any symbol found in an
102416dce513Schristosexpression.  You can define this to handle special symbols in a special way.
102516dce513SchristosIf a symbol always has a certain value, you should normally enter it in the
102616dce513Schristossymbol table, perhaps using @code{reg_section}.
102716dce513Schristos
102816dce513Schristos@item md_undefined_symbol
102916dce513Schristos@cindex md_undefined_symbol
103016dce513SchristosGAS will call this function when a symbol table lookup fails, before it
103116dce513Schristoscreates a new symbol.  Typically this would be used to supply symbols whose
103216dce513Schristosname or value changes dynamically, possibly in a context sensitive way.
103316dce513SchristosPredefined symbols with fixed values, such as register names or condition
103416dce513Schristoscodes, are typically entered directly into the symbol table when @code{md_begin}
103516dce513Schristosis called.  One argument is passed, a @code{char *} for the symbol.
103616dce513Schristos
103716dce513Schristos@item md_operand
103816dce513Schristos@cindex md_operand
103916dce513SchristosGAS will call this function with one argument, an @code{expressionS}
104016dce513Schristospointer, for any expression that can not be recognized.  When the function
104116dce513Schristosis called, @code{input_line_pointer} will point to the start of the
104216dce513Schristosexpression.
104316dce513Schristos
104416dce513Schristos@item md_register_arithmetic
104516dce513Schristos@cindex md_register_arithmetic
104616dce513SchristosIf this macro is defined and evaluates to zero then GAS will not fold
104716dce513Schristosexpressions that add or subtract a constant to/from a register to give
104816dce513Schristosanother register.  For example GAS's default behaviour is to fold the
104916dce513Schristosexpression "r8 + 1" into "r9", which is probably not the result
105016dce513Schristosintended by the programmer.  The default is to allow such folding,
105116dce513Schristossince this maintains backwards compatibility with earlier releases of
105216dce513SchristosGAS.
105316dce513Schristos
105416dce513Schristos@item tc_unrecognized_line
105516dce513Schristos@cindex tc_unrecognized_line
105616dce513SchristosIf you define this macro, GAS will call it when it finds a line that it can not
105716dce513Schristosparse.
105816dce513Schristos
105916dce513Schristos@item md_do_align
106016dce513Schristos@cindex md_do_align
106116dce513SchristosYou may define this macro to handle an alignment directive.  GAS will call it
106216dce513Schristoswhen the directive is seen in the input file.  For example, the i386 backend
106316dce513Schristosuses this to generate efficient nop instructions of varying lengths, depending
106416dce513Schristosupon the number of bytes that the alignment will skip.
106516dce513Schristos
106616dce513Schristos@item HANDLE_ALIGN
106716dce513Schristos@cindex HANDLE_ALIGN
106816dce513SchristosYou may define this macro to do special handling for an alignment directive.
106916dce513SchristosGAS will call it at the end of the assembly.
107016dce513Schristos
107116dce513Schristos@item TC_IMPLICIT_LCOMM_ALIGNMENT (@var{size}, @var{p2var})
107216dce513Schristos@cindex TC_IMPLICIT_LCOMM_ALIGNMENT
107316dce513SchristosAn @code{.lcomm} directive with no explicit alignment parameter will use this
107416dce513Schristosmacro to set @var{p2var} to the alignment that a request for @var{size} bytes
107516dce513Schristoswill have.  The alignment is expressed as a power of two.  If no alignment
107616dce513Schristosshould take place, the macro definition should do nothing.  Some targets define
107716dce513Schristosa @code{.bss} directive that is also affected by this macro.  The default
107816dce513Schristosdefinition will set @var{p2var} to the truncated power of two of sizes up to
107916dce513Schristoseight bytes.
108016dce513Schristos
108116dce513Schristos@item md_flush_pending_output
108216dce513Schristos@cindex md_flush_pending_output
108316dce513SchristosIf you define this macro, GAS will call it each time it skips any space because of a
108416dce513Schristosspace filling or alignment or data allocation pseudo-op.
108516dce513Schristos
108616dce513Schristos@item TC_PARSE_CONS_EXPRESSION
108716dce513Schristos@cindex TC_PARSE_CONS_EXPRESSION
108816dce513SchristosYou may define this macro to parse an expression used in a data allocation
108916dce513Schristospseudo-op such as @code{.word}.  You can use this to recognize relocation
109016dce513Schristosdirectives that may appear in such directives.
109116dce513Schristos
109216dce513Schristos@item REPEAT_CONS_EXPRESSION
109316dce513Schristos@cindex REPEAT_CONS_EXPRESSION
109416dce513SchristosIf you define this macro, GAS will recognize repeat counts in data allocation
109516dce513Schristospseudo-ops, as used on the MIPS.
109616dce513Schristos
109716dce513Schristos@item md_cons_align
109816dce513Schristos@cindex md_cons_align
109916dce513SchristosYou may define this macro to do any special alignment before a data allocation
110016dce513Schristospseudo-op.
110116dce513Schristos
110216dce513Schristos@item TC_CONS_FIX_NEW
110316dce513Schristos@cindex TC_CONS_FIX_NEW
110416dce513SchristosYou may define this macro to generate a fixup for a data allocation pseudo-op.
110516dce513Schristos
110616dce513Schristos@item TC_ADDRESS_BYTES
110716dce513Schristos@cindex TC_ADDRESS_BYTES
110816dce513SchristosDefine this macro to specify the number of bytes used to store an address.
1109*e992f068SchristosUsed to implement @code{dc.a}.  If not defined by the target, a default will
1110*e992f068Schristosbe supplied.  Targets are assumed to have a reloc for this size.
111116dce513Schristos
111216dce513Schristos@item TC_INIT_FIX_DATA (@var{fixp})
111316dce513Schristos@cindex TC_INIT_FIX_DATA
111416dce513SchristosA C statement to initialize the target specific fields of fixup @var{fixp}.
111516dce513SchristosThese fields are defined with the @code{TC_FIX_TYPE} macro.
111616dce513Schristos
111716dce513Schristos@item TC_FIX_DATA_PRINT (@var{stream}, @var{fixp})
111816dce513Schristos@cindex TC_FIX_DATA_PRINT
111916dce513SchristosA C statement to output target specific debugging information for
112016dce513Schristosfixup @var{fixp} to @var{stream}.  This macro is called by @code{print_fixup}.
112116dce513Schristos
1122012573ebSchristos@item TC_FRAG_INIT (@var{fragp}, @var{max_bytes})
112316dce513Schristos@cindex TC_FRAG_INIT
1124012573ebSchristosA C statement to initialize the target specific fields of frag @var{fragp}
1125012573ebSchristoswith maximum number of bytes @var{max_bytes}.  These fields are defined
1126012573ebSchristoswith the @code{TC_FRAG_TYPE} macro.
112716dce513Schristos
112816dce513Schristos@item md_number_to_chars
112916dce513Schristos@cindex md_number_to_chars
113016dce513SchristosThis should just call either @code{number_to_chars_bigendian} or
113116dce513Schristos@code{number_to_chars_littleendian}, whichever is appropriate.  On targets like
113216dce513Schristosthe MIPS which support options to change the endianness, which function to call
113316dce513Schristosis a runtime decision.  On other targets, @code{md_number_to_chars} can be a
113416dce513Schristossimple macro.
113516dce513Schristos
113616dce513Schristos@item md_atof (@var{type},@var{litP},@var{sizeP})
113716dce513Schristos@cindex md_atof
113816dce513SchristosThis function is called to convert an ASCII string into a floating point value
113916dce513Schristosin format used by the CPU.  It takes three arguments.  The first is @var{type}
114016dce513Schristoswhich is a byte describing the type of floating point number to be created.  It
114116dce513Schristosis one of the characters defined in the @code{FLT_CHARS} macro.  Possible
114216dce513Schristosvalues are @var{'f'} or @var{'s'} for single precision, @var{'d'} or @var{'r'}
114316dce513Schristosfor double precision and @var{'x'} or @var{'p'} for extended precision.  Either
114416dce513Schristoslower or upper case versions of these letters can be used.  Note: some targets
114516dce513Schristosdo not support all of these types, and some targets may also support other
114616dce513Schristostypes not mentioned here.
114716dce513Schristos
114816dce513SchristosThe second parameter is @var{litP} which is a pointer to a byte array where the
114916dce513Schristosconverted value should be stored.  The value is converted into LITTLENUMs and
115016dce513Schristosis stored in the target's endian-ness order.  (@var{LITTLENUM} is defined in
115116dce513Schristosgas/bignum.h).  Single precision values occupy 2 littlenums.  Double precision
115216dce513Schristosvalues occupy 4 littlenums and extended precision values occupy either 5 or 6
115316dce513Schristoslittlenums, depending upon the target.
115416dce513Schristos
115516dce513SchristosThe third argument is @var{sizeP}, which is a pointer to a integer that should
115616dce513Schristosbe filled in with the number of chars emitted into the byte array.
115716dce513Schristos
115816dce513SchristosThe function should return NULL upon success or an error string upon failure.
115916dce513Schristos
116016dce513Schristos@item TC_LARGEST_EXPONENT_IS_NORMAL
116116dce513Schristos@cindex TC_LARGEST_EXPONENT_IS_NORMAL (@var{precision})
116216dce513SchristosThis macro is used only by @file{atof-ieee.c}.  It should evaluate to true
116316dce513Schristosif floats of the given precision use the largest exponent for normal numbers
116416dce513Schristosinstead of NaNs and infinities.  @var{precision} is @samp{F_PRECISION} for
116516dce513Schristossingle precision, @samp{D_PRECISION} for double precision, or
116616dce513Schristos@samp{X_PRECISION} for extended double precision.
116716dce513Schristos
116816dce513SchristosThe macro has a default definition which returns 0 for all cases.
116916dce513Schristos
117016dce513Schristos@item WORKING_DOT_WORD
117116dce513Schristos@itemx md_short_jump_size
117216dce513Schristos@itemx md_long_jump_size
117316dce513Schristos@itemx md_create_short_jump
117416dce513Schristos@itemx md_create_long_jump
117516dce513Schristos@itemx TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
117616dce513Schristos@cindex WORKING_DOT_WORD
117716dce513Schristos@cindex md_short_jump_size
117816dce513Schristos@cindex md_long_jump_size
117916dce513Schristos@cindex md_create_short_jump
118016dce513Schristos@cindex md_create_long_jump
118116dce513Schristos@cindex TC_CHECK_ADJUSTED_BROKEN_DOT_WORD
118216dce513SchristosIf @code{WORKING_DOT_WORD} is defined, GAS will not do broken word processing
118316dce513Schristos(@pxref{Broken words}).  Otherwise, you should set @code{md_short_jump_size} to
118416dce513Schristosthe size of a short jump (a jump that is just long enough to jump around a
118516dce513Schristosnumber of long jumps) and @code{md_long_jump_size} to the size of a long jump
118616dce513Schristos(a jump that can go anywhere in the function).  You should define
118716dce513Schristos@code{md_create_short_jump} to create a short jump around a number of long
118816dce513Schristosjumps, and define @code{md_create_long_jump} to create a long jump.
118916dce513SchristosIf defined, the macro TC_CHECK_ADJUSTED_BROKEN_DOT_WORD will be called for each
119016dce513Schristosadjusted word just before the word is output.  The macro takes two arguments,
119116dce513Schristosan @code{addressT} with the adjusted word and a pointer to the current
119216dce513Schristos@code{struct broken_word}.
119316dce513Schristos
119416dce513Schristos@item md_estimate_size_before_relax
119516dce513Schristos@cindex md_estimate_size_before_relax
119616dce513SchristosThis function returns an estimate of the size of a @code{rs_machine_dependent}
119716dce513Schristosfrag before any relaxing is done.  It may also create any necessary
119816dce513Schristosrelocations.
119916dce513Schristos
120016dce513Schristos@item md_relax_frag
120116dce513Schristos@cindex md_relax_frag
120216dce513SchristosThis macro may be defined to relax a frag.  GAS will call this with the
120316dce513Schristossegment, the frag, and the change in size of all previous frags;
120416dce513Schristos@code{md_relax_frag} should return the change in size of the frag.
120516dce513Schristos@xref{Relaxation}.
120616dce513Schristos
120716dce513Schristos@item TC_GENERIC_RELAX_TABLE
120816dce513Schristos@cindex TC_GENERIC_RELAX_TABLE
120916dce513SchristosIf you do not define @code{md_relax_frag}, you may define
121016dce513Schristos@code{TC_GENERIC_RELAX_TABLE} as a table of @code{relax_typeS} structures.  The
121116dce513Schristosmachine independent code knows how to use such a table to relax PC relative
121216dce513Schristosreferences.  See @file{tc-m68k.c} for an example.  @xref{Relaxation}.
121316dce513Schristos
1214012573ebSchristos@item md_generic_table_relax_frag
1215012573ebSchristos@cindex md_generic_table_relax_frag
1216012573ebSchristosIf defined, it is a C statement that is invoked, instead of
1217012573ebSchristosthe default implementation, to scan @code{TC_GENERIC_RELAX_TABLE}.
1218012573ebSchristos
121916dce513Schristos@item md_prepare_relax_scan
122016dce513Schristos@cindex md_prepare_relax_scan
122116dce513SchristosIf defined, it is a C statement that is invoked prior to scanning
122216dce513Schristosthe relax table.
122316dce513Schristos
122416dce513Schristos@item LINKER_RELAXING_SHRINKS_ONLY
122516dce513Schristos@cindex LINKER_RELAXING_SHRINKS_ONLY
122616dce513SchristosIf you define this macro, and the global variable @samp{linkrelax} is set
1227012573ebSchristos(because of a command-line option, or unconditionally in @code{md_begin}), a
122816dce513Schristos@samp{.align} directive will cause extra space to be allocated.  The linker can
122916dce513Schristosthen discard this space when relaxing the section.
123016dce513Schristos
123116dce513Schristos@item TC_LINKRELAX_FIXUP (@var{segT})
123216dce513Schristos@cindex TC_LINKRELAX_FIXUP
123316dce513SchristosIf defined, this macro allows control over whether fixups for a
123416dce513Schristosgiven section will be processed when the @var{linkrelax} variable is
123516dce513Schristosset.  The macro is given the N_TYPE bits for the section in its
123616dce513Schristos@var{segT} argument.  If the macro evaluates to a non-zero value
123716dce513Schristosthen the fixups will be converted into relocs, otherwise they will
123816dce513Schristosbe passed to @var{md_apply_fix} as normal.
123916dce513Schristos
124016dce513Schristos@item md_convert_frag
124116dce513Schristos@cindex md_convert_frag
124216dce513SchristosGAS will call this for each rs_machine_dependent fragment.
124316dce513SchristosThe instruction is completed using the data from the relaxation pass.
124416dce513SchristosIt may also create any necessary relocations.
124516dce513Schristos@xref{Relaxation}.
124616dce513Schristos
124716dce513Schristos@item TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
124816dce513Schristos@cindex TC_FINALIZE_SYMS_BEFORE_SIZE_SEG
124916dce513SchristosSpecifies the value to be assigned to @code{finalize_syms} before the function
125016dce513Schristos@code{size_segs} is called.  Since @code{size_segs} calls @code{cvt_frag_to_fill}
125116dce513Schristoswhich can call @code{md_convert_frag}, this constant governs whether the symbols
125216dce513Schristosaccessed in @code{md_convert_frag} will be fully resolved.  In particular it
125316dce513Schristosgoverns whether local symbols will have been resolved, and had their frag
125416dce513Schristosinformation removed.  Depending upon the processing performed by
125516dce513Schristos@code{md_convert_frag} the frag information may or may not be necessary, as may
125616dce513Schristosthe resolved values of the symbols.  The default value is 1.
125716dce513Schristos
125816dce513Schristos@item TC_VALIDATE_FIX (@var{fixP}, @var{seg}, @var{skip})
125916dce513Schristos@cindex TC_VALIDATE_FIX
126016dce513SchristosThis macro is evaluated for each fixup (when @var{linkrelax} is not set).
126116dce513SchristosIt may be used to change the fixup in @code{struct fix *@var{fixP}} before
126216dce513Schristosthe generic code sees it, or to fully process the fixup.  In the latter case,
126316dce513Schristosa @code{goto @var{skip}} will bypass the generic code.
126416dce513Schristos
126516dce513Schristos@item md_apply_fix (@var{fixP}, @var{valP}, @var{seg})
126616dce513Schristos@cindex md_apply_fix
126716dce513SchristosGAS will call this for each fixup that passes the @code{TC_VALIDATE_FIX} test
126816dce513Schristoswhen @var{linkrelax} is not set.  It should store the correct value in the
126916dce513Schristosobject file.  @code{struct fix *@var{fixP}} is the fixup @code{md_apply_fix}
127016dce513Schristosis operating on.  @code{valueT *@var{valP}} is the value to store into the
127116dce513Schristosobject files, or at least is the generic code's best guess.  Specifically,
127216dce513Schristos*@var{valP} is the value of the fixup symbol, perhaps modified by
127316dce513Schristos@code{MD_APPLY_SYM_VALUE}, plus @code{@var{fixP}->fx_offset} (symbol addend),
127416dce513Schristosless @code{MD_PCREL_FROM_SECTION} for pc-relative fixups.
127516dce513Schristos@code{segT @var{seg}} is the section the fix is in.
127616dce513Schristos@code{fixup_segment} performs a generic overflow check on *@var{valP} after
127716dce513Schristos@code{md_apply_fix} returns.  If the overflow check is relevant for the target
127816dce513Schristosmachine, then @code{md_apply_fix} should modify *@var{valP}, typically to the
127916dce513Schristosvalue stored in the object file.
128016dce513Schristos
128116dce513Schristos@item TC_FORCE_RELOCATION (@var{fix})
128216dce513Schristos@cindex TC_FORCE_RELOCATION
128316dce513SchristosIf this macro returns non-zero, it guarantees that a relocation will be emitted
128416dce513Schristoseven when the value can be resolved locally, as @code{fixup_segment} tries to
128516dce513Schristosreduce the number of relocations emitted.  For example, a fixup expression
128616dce513Schristosagainst an absolute symbol will normally not require a reloc.  If undefined,
128716dce513Schristosa default of @w{@code{(S_FORCE_RELOC ((@var{fix})->fx_addsy))}} is used.
128816dce513Schristos
128916dce513Schristos@item TC_FORCE_RELOCATION_ABS (@var{fix})
129016dce513Schristos@cindex TC_FORCE_RELOCATION_ABS
129116dce513SchristosLike @code{TC_FORCE_RELOCATION}, but used only for fixup expressions against an
129216dce513Schristosabsolute symbol.  If undefined, @code{TC_FORCE_RELOCATION} will be used.
129316dce513Schristos
129416dce513Schristos@item TC_FORCE_RELOCATION_LOCAL (@var{fix})
129516dce513Schristos@cindex TC_FORCE_RELOCATION_LOCAL
129616dce513SchristosLike @code{TC_FORCE_RELOCATION}, but used only for fixup expressions against a
129716dce513Schristossymbol in the current section.  If undefined, fixups that are not
129816dce513Schristos@code{fx_pcrel} or for which @code{TC_FORCE_RELOCATION}
129916dce513Schristosreturns non-zero, will emit relocs.
130016dce513Schristos
130116dce513Schristos@item TC_FORCE_RELOCATION_SUB_SAME (@var{fix}, @var{seg})
130216dce513Schristos@cindex TC_FORCE_RELOCATION_SUB_SAME
130316dce513SchristosThis macro controls resolution of fixup expressions involving the
130416dce513Schristosdifference of two symbols in the same section.  If this macro returns zero,
130516dce513Schristosthe subtrahend will be resolved and @code{fx_subsy} set to @code{NULL} for
130616dce513Schristos@code{md_apply_fix}.  If undefined, the default of
130716dce513Schristos@w{@code{! SEG_NORMAL (@var{seg})}} will be used.
130816dce513Schristos
130916dce513Schristos@item TC_FORCE_RELOCATION_SUB_ABS (@var{fix}, @var{seg})
131016dce513Schristos@cindex TC_FORCE_RELOCATION_SUB_ABS
131116dce513SchristosLike @code{TC_FORCE_RELOCATION_SUB_SAME}, but used when the subtrahend is an
131216dce513Schristosabsolute symbol.  If the macro is undefined a default of @code{0} is used.
131316dce513Schristos
131416dce513Schristos@item TC_FORCE_RELOCATION_SUB_LOCAL (@var{fix}, @var{seg})
131516dce513Schristos@cindex TC_FORCE_RELOCATION_SUB_LOCAL
131616dce513SchristosLike @code{TC_FORCE_RELOCATION_SUB_ABS}, but the subtrahend is a symbol in the
131716dce513Schristossame section as the fixup.
131816dce513Schristos
131916dce513Schristos@item TC_VALIDATE_FIX_SUB (@var{fix}, @var{seg})
132016dce513Schristos@cindex TC_VALIDATE_FIX_SUB
132116dce513SchristosThis macro is evaluated for any fixup with a @code{fx_subsy} that
132216dce513Schristos@code{fixup_segment} cannot reduce to a number.  If the macro returns
132316dce513Schristos@code{false} an error will be reported.
132416dce513Schristos
132516dce513Schristos@item TC_GLOBAL_REGISTER_SYMBOL_OK
132616dce513Schristos@cindex TC_GLOBAL_REGISTER_SYMBOL_OK
132716dce513SchristosDefine this macro if global register symbols are supported. The default
132816dce513Schristosis to disallow global register symbols.
132916dce513Schristos
133016dce513Schristos@item MD_APPLY_SYM_VALUE (@var{fix})
133116dce513Schristos@cindex MD_APPLY_SYM_VALUE
133216dce513SchristosThis macro controls whether the symbol value becomes part of the value passed
133316dce513Schristosto @code{md_apply_fix}.  If the macro is undefined, or returns non-zero, the
133416dce513Schristossymbol value will be included.  For ELF, a suitable definition might simply be
133516dce513Schristos@code{0}, because ELF relocations don't include the symbol value in the addend.
133616dce513Schristos
133716dce513Schristos@item S_FORCE_RELOC (@var{sym}, @var{strict})
133816dce513Schristos@cindex S_FORCE_RELOC
133916dce513SchristosThis function returns true for symbols
134016dce513Schristosthat should not be reduced to section symbols or eliminated from expressions,
134116dce513Schristosbecause they may be overridden by the linker.  ie. for symbols that are
134216dce513Schristosundefined or common, and when @var{strict} is set, weak, or global (for ELF
134316dce513Schristosassemblers that support ELF shared library linking semantics).
134416dce513Schristos
134516dce513Schristos@item EXTERN_FORCE_RELOC
134616dce513Schristos@cindex EXTERN_FORCE_RELOC
134716dce513SchristosThis macro controls whether @code{S_FORCE_RELOC} returns true for global
134816dce513Schristossymbols.  If undefined, the default is @code{true} for ELF assemblers, and
134916dce513Schristos@code{false} for non-ELF.
135016dce513Schristos
135116dce513Schristos@item tc_gen_reloc
135216dce513Schristos@cindex tc_gen_reloc
135316dce513SchristosGAS will call this to generate a reloc.  GAS will pass
135416dce513Schristosthe resulting reloc to @code{bfd_install_relocation}.  This currently works
135516dce513Schristospoorly, as @code{bfd_install_relocation} often does the wrong thing, and
135616dce513Schristosinstances of @code{tc_gen_reloc} have been written to work around the problems,
135716dce513Schristoswhich in turns makes it difficult to fix @code{bfd_install_relocation}.
135816dce513Schristos
135916dce513Schristos@item RELOC_EXPANSION_POSSIBLE
136016dce513Schristos@cindex RELOC_EXPANSION_POSSIBLE
136116dce513SchristosIf you define this macro, it means that @code{tc_gen_reloc} may return multiple
136216dce513Schristosrelocation entries for a single fixup.  In this case, the return value of
136316dce513Schristos@code{tc_gen_reloc} is a pointer to a null terminated array.
136416dce513Schristos
136516dce513Schristos@item MAX_RELOC_EXPANSION
136616dce513Schristos@cindex MAX_RELOC_EXPANSION
136716dce513SchristosYou must define this if @code{RELOC_EXPANSION_POSSIBLE} is defined; it
136816dce513Schristosindicates the largest number of relocs which @code{tc_gen_reloc} may return for
136916dce513Schristosa single fixup.
137016dce513Schristos
137116dce513Schristos@item tc_fix_adjustable
137216dce513Schristos@cindex tc_fix_adjustable
137316dce513SchristosYou may define this macro to indicate whether a fixup against a locally defined
137416dce513Schristossymbol should be adjusted to be against the section symbol.  It should return a
137516dce513Schristosnon-zero value if the adjustment is acceptable.
137616dce513Schristos
137716dce513Schristos@item MD_PCREL_FROM_SECTION (@var{fixp}, @var{section})
137816dce513Schristos@cindex MD_PCREL_FROM_SECTION
137916dce513SchristosIf you define this macro, it should return the position from which the PC
138016dce513Schristosrelative adjustment for a PC relative fixup should be made.  On many
138116dce513Schristosprocessors, the base of a PC relative instruction is the next instruction,
138216dce513Schristosso this macro would return the length of an instruction, plus the address of
138316dce513Schristosthe PC relative fixup.  The latter can be calculated as
138416dce513Schristos@var{fixp}->fx_where + @var{fixp}->fx_frag->fr_address .
138516dce513Schristos
138616dce513Schristos@item md_pcrel_from
138716dce513Schristos@cindex md_pcrel_from
138816dce513SchristosThis is the default value of @code{MD_PCREL_FROM_SECTION}.  The difference is
138916dce513Schristosthat @code{md_pcrel_from} does not take a section argument.
139016dce513Schristos
139116dce513Schristos@item tc_frob_label
139216dce513Schristos@cindex tc_frob_label
139316dce513SchristosIf you define this macro, GAS will call it each time a label is defined.
139416dce513Schristos
139516dce513Schristos@item tc_new_dot_label
139616dce513Schristos@cindex tc_new_dot_label
139716dce513SchristosIf you define this macro, GAS will call it each time a fake label is created
139816dce513Schristosoff the special dot symbol.
139916dce513Schristos
140016dce513Schristos@item md_section_align
140116dce513Schristos@cindex md_section_align
140216dce513SchristosGAS will call this function for each section at the end of the assembly, to
140316dce513Schristospermit the CPU backend to adjust the alignment of a section.  The function
140416dce513Schristosmust take two arguments, a @code{segT} for the section and a @code{valueT}
140516dce513Schristosfor the size of the section, and return a @code{valueT} for the rounded
140616dce513Schristossize.
140716dce513Schristos
140816dce513Schristos@item md_macro_start
140916dce513Schristos@cindex md_macro_start
141016dce513SchristosIf defined, GAS will call this macro when it starts to include a macro
141116dce513Schristosexpansion.  @code{macro_nest} indicates the current macro nesting level, which
141216dce513Schristosincludes the one being expanded.
141316dce513Schristos
141416dce513Schristos@item md_macro_info
141516dce513Schristos@cindex md_macro_info
141616dce513SchristosIf defined, GAS will call this macro after the macro expansion has been
141716dce513Schristosincluded in the input and after parsing the macro arguments.  The single
141816dce513Schristosargument is a pointer to the macro processing's internal representation of the
141916dce513Schristosmacro (macro_entry *), which includes expansion of the formal arguments.
142016dce513Schristos
142116dce513Schristos@item md_macro_end
142216dce513Schristos@cindex md_macro_end
142316dce513SchristosComplement to md_macro_start.  If defined, it is called when finished
142416dce513Schristosprocessing an inserted macro expansion, just before decrementing macro_nest.
142516dce513Schristos
142616dce513Schristos@item DOUBLEBAR_PARALLEL
142716dce513Schristos@cindex DOUBLEBAR_PARALLEL
142816dce513SchristosAffects the preprocessor so that lines containing '||' don't have their
142916dce513Schristoswhitespace stripped following the double bar.  This is useful for targets that
143016dce513Schristosimplement parallel instructions.
143116dce513Schristos
143216dce513Schristos@item KEEP_WHITE_AROUND_COLON
143316dce513Schristos@cindex KEEP_WHITE_AROUND_COLON
143416dce513SchristosNormally, whitespace is compressed and removed when, in the presence of the
143516dce513Schristoscolon, the adjoining tokens can be distinguished.  This option affects the
143616dce513Schristospreprocessor so that whitespace around colons is preserved.  This is useful
143716dce513Schristoswhen colons might be removed from the input after preprocessing but before
143816dce513Schristosassembling, so that adjoining tokens can still be distinguished if there is
143916dce513Schristoswhitespace, or concatenated if there is not.
144016dce513Schristos
144116dce513Schristos@item tc_frob_section
144216dce513Schristos@cindex tc_frob_section
144316dce513SchristosIf you define this macro, GAS will call it for each
144416dce513Schristossection at the end of the assembly.
144516dce513Schristos
144616dce513Schristos@item tc_frob_file_before_adjust
144716dce513Schristos@cindex tc_frob_file_before_adjust
144816dce513SchristosIf you define this macro, GAS will call it after the symbol values are
144916dce513Schristosresolved, but before the fixups have been changed from local symbols to section
145016dce513Schristossymbols.
145116dce513Schristos
145216dce513Schristos@item tc_frob_symbol
145316dce513Schristos@cindex tc_frob_symbol
145416dce513SchristosIf you define this macro, GAS will call it for each symbol.  You can indicate
145516dce513Schristosthat the symbol should not be included in the object file by defining this
145616dce513Schristosmacro to set its second argument to a non-zero value.
145716dce513Schristos
145816dce513Schristos@item tc_frob_file
145916dce513Schristos@cindex tc_frob_file
146016dce513SchristosIf you define this macro, GAS will call it after the symbol table has been
146116dce513Schristoscompleted, but before the relocations have been generated.
146216dce513Schristos
146316dce513Schristos@item tc_frob_file_after_relocs
146416dce513SchristosIf you define this macro, GAS will call it after the relocs have been
146516dce513Schristosgenerated.
146616dce513Schristos
146716dce513Schristos@item tc_cfi_reloc_for_encoding
146816dce513Schristos@cindex tc_cfi_reloc_for_encoding
146916dce513SchristosThis macro is used to indicate whether a cfi encoding requires a relocation.
147016dce513SchristosIt should return the required relocation type.  Defining this macro implies
147116dce513Schristosthat Compact EH is supported.
147216dce513Schristos
147316dce513Schristos@item md_post_relax_hook
147416dce513SchristosIf you define this macro, GAS will call it after relaxing and sizing the
147516dce513Schristossegments.
147616dce513Schristos
147716dce513Schristos@item LISTING_HEADER
147816dce513SchristosA string to use on the header line of a listing.  The default value is simply
147916dce513Schristos@code{"GAS LISTING"}.
148016dce513Schristos
148116dce513Schristos@item LISTING_WORD_SIZE
148216dce513SchristosThe number of bytes to put into a word in a listing.  This affects the way the
148316dce513Schristosbytes are clumped together in the listing.  For example, a value of 2 might
148416dce513Schristosprint @samp{1234 5678} where a value of 1 would print @samp{12 34 56 78}.  The
148516dce513Schristosdefault value is 4.
148616dce513Schristos
148716dce513Schristos@item LISTING_LHS_WIDTH
148816dce513SchristosThe number of words of data to print on the first line of a listing for a
148916dce513Schristosparticular source line, where each word is @code{LISTING_WORD_SIZE} bytes.  The
149016dce513Schristosdefault value is 1.
149116dce513Schristos
149216dce513Schristos@item LISTING_LHS_WIDTH_SECOND
149316dce513SchristosLike @code{LISTING_LHS_WIDTH}, but applying to the second and subsequent line
149416dce513Schristosof the data printed for a particular source line.  The default value is 1.
149516dce513Schristos
149616dce513Schristos@item LISTING_LHS_CONT_LINES
149716dce513SchristosThe maximum number of continuation lines to print in a listing for a particular
149816dce513Schristossource line.  The default value is 4.
149916dce513Schristos
150016dce513Schristos@item LISTING_RHS_WIDTH
150116dce513SchristosThe maximum number of characters to print from one line of the input file.  The
150216dce513Schristosdefault value is 100.
150316dce513Schristos
150416dce513Schristos@item TC_COFF_SECTION_DEFAULT_ATTRIBUTES
150516dce513Schristos@cindex TC_COFF_SECTION_DEFAULT_ATTRIBUTES
150616dce513SchristosThe COFF @code{.section} directive will use the value of this macro to set
150716dce513Schristosa new section's attributes when a directive has no valid flags or when the
150816dce513Schristosflag is @code{w}. The default value of the macro is @code{SEC_LOAD | SEC_DATA}.
150916dce513Schristos
151016dce513Schristos@item DWARF2_FORMAT (@var{sec})
151116dce513Schristos@cindex DWARF2_FORMAT
151216dce513SchristosIf you define this, it should return one of @code{dwarf2_format_32bit},
151316dce513Schristos@code{dwarf2_format_64bit}, or @code{dwarf2_format_64bit_irix} to indicate
151416dce513Schristosthe size of internal DWARF section offsets and the format of the DWARF initial
151516dce513Schristoslength fields.  When @code{dwarf2_format_32bit} is returned, the initial
151616dce513Schristoslength field will be 4 bytes long and section offsets are 32 bits in size.
151716dce513SchristosFor @code{dwarf2_format_64bit} and @code{dwarf2_format_64bit_irix}, section
151816dce513Schristosoffsets are 64 bits in size, but the initial length field differs.  An 8 byte
151916dce513Schristosinitial length is indicated by @code{dwarf2_format_64bit_irix} and
152016dce513Schristos@code{dwarf2_format_64bit} indicates a 12 byte initial length field in
152116dce513Schristoswhich the first four bytes are 0xffffffff and the next 8 bytes are
152216dce513Schristosthe section's length.
152316dce513Schristos
152416dce513SchristosIf you don't define this, @code{dwarf2_format_32bit} will be used as
152516dce513Schristosthe default.
152616dce513Schristos
152716dce513SchristosThis define only affects debug
152816dce513Schristossections generated by the assembler.  DWARF 2 sections generated by
152916dce513Schristosother tools will be unaffected by this setting.
153016dce513Schristos
153116dce513Schristos@item DWARF2_ADDR_SIZE (@var{bfd})
153216dce513Schristos@cindex DWARF2_ADDR_SIZE
153316dce513SchristosIt should return the size of an address, as it should be represented in
153416dce513Schristosdebugging info.  If you don't define this macro, the default definition uses
153516dce513Schristosthe number of bits per address, as defined in @var{bfd}, divided by 8.
153616dce513Schristos
153716dce513Schristos@item   MD_DEBUG_FORMAT_SELECTOR
153816dce513Schristos@cindex MD_DEBUG_FORMAT_SELECTOR
153916dce513SchristosIf defined this macro is the name of a function to be called when the
154016dce513Schristos@samp{--gen-debug} switch is detected on the assembler's command line.  The
154116dce513Schristosprototype for the function looks like this:
154216dce513Schristos
154316dce513Schristos@smallexample
154416dce513Schristos   enum debug_info_type MD_DEBUG_FORMAT_SELECTOR (int * use_gnu_extensions)
154516dce513Schristos@end smallexample
154616dce513Schristos
154716dce513SchristosThe function should return the debug format that is preferred by the CPU
154816dce513Schristosbackend.  This format will be used when generating assembler specific debug
154916dce513Schristosinformation.
155016dce513Schristos
1551*e992f068Schristos@item md_emit_single_noop_insn
1552*e992f068Schristos@itemx md_single_noop_insn
1553*e992f068SchristosThese macro facilitate the @var{.nop} directive.  If defined the
1554*e992f068Schristos@var{md_emit_single_noop_insn) macro provides code to insert a single no-op
1555*e992f068Schristosinstruction into the output stream.  If this involves calling @var{md_assemble}
1556*e992f068Schristoswith a fixed string then the alternative macro @var{md_single_noop_insn} can be
1557*e992f068Schristosdefined, specifying the string to pass.  If neither of these macros are defined
1558*e992f068Schristosthen the @var{.nop} directive will call @var{md_assemble} with the string
1559*e992f068Schristos@option{nop}.
1560*e992f068Schristos
156116dce513Schristos@item md_allow_local_subtract (@var{left}, @var{right}, @var{section})
156216dce513SchristosIf defined, GAS will call this macro when evaluating an expression which is the
156316dce513Schristosdifference of two symbols defined in the same section.  It takes three
156416dce513Schristosarguments: @code{expressioS * @var{left}} which is the symbolic expression on
156516dce513Schristosthe left hand side of the subtraction operation, @code{expressionS *
156616dce513Schristos@var{right}} which is the symbolic expression on the right hand side of the
156716dce513Schristossubtraction, and @code{segT @var{section}} which is the section containing the two
156816dce513Schristossymbols.  The macro should return a non-zero value if the expression should be
156916dce513Schristosevaluated.  Targets which implement link time relaxation which may change the
157016dce513Schristosposition of the two symbols relative to each other should ensure that this
157116dce513Schristosmacro returns zero in situations where this can occur.
157216dce513Schristos
157316dce513Schristos@item md_allow_eh_opt
157416dce513SchristosIf defined, GAS will check this macro before performing any optimizations on
157516dce513Schristosthe DWARF call frame debug information that is emitted.  Targets which
157616dce513Schristosimplement link time relaxation may need to define this macro and set it to zero
157716dce513Schristosif it is possible to change the size of a function's prologue.
157816dce513Schristos@end table
157916dce513Schristos
158016dce513Schristos@node Object format backend
158116dce513Schristos@subsection Writing an object format backend
158216dce513Schristos@cindex object format backend
158316dce513Schristos@cindex @file{obj-@var{fmt}}
158416dce513Schristos
158516dce513SchristosAs with the CPU backend, the object format backend must define a few things,
158616dce513Schristosand may define some other things.  The interface to the object format backend
158716dce513Schristosis generally simpler; most of the support for an object file format consists of
158816dce513Schristosdefining a number of pseudo-ops.
158916dce513Schristos
159016dce513SchristosThe object format @file{.h} file must include @file{targ-cpu.h}.
159116dce513Schristos
159216dce513Schristos@table @code
159316dce513Schristos@item OBJ_@var{format}
159416dce513Schristos@cindex OBJ_@var{format}
159516dce513SchristosBy convention, you should define this macro in the @file{.h} file.  For
159616dce513Schristosexample, @file{obj-elf.h} defines @code{OBJ_ELF}.  You might have to use this
159716dce513Schristosif it is necessary to add object file format specific code to the CPU file.
159816dce513Schristos
159916dce513Schristos@item obj_begin
160016dce513SchristosIf you define this macro, GAS will call it at the start of the assembly, after
1601012573ebSchristosthe command-line arguments have been parsed and all the machine independent
160216dce513Schristosinitializations have been completed.
160316dce513Schristos
160416dce513Schristos@item obj_app_file
160516dce513Schristos@cindex obj_app_file
160616dce513SchristosIf you define this macro, GAS will invoke it when it sees a @code{.file}
160716dce513Schristospseudo-op or a @samp{#} line as used by the C preprocessor.
160816dce513Schristos
160916dce513Schristos@item OBJ_COPY_SYMBOL_ATTRIBUTES
161016dce513Schristos@cindex OBJ_COPY_SYMBOL_ATTRIBUTES
161116dce513SchristosYou should define this macro to copy object format specific information from
161216dce513Schristosone symbol to another.  GAS will call it when one symbol is equated to
161316dce513Schristosanother.
161416dce513Schristos
161516dce513Schristos@item obj_sec_sym_ok_for_reloc
161616dce513Schristos@cindex obj_sec_sym_ok_for_reloc
161716dce513SchristosYou may define this macro to indicate that it is OK to use a section symbol in
161816dce513Schristosa relocation entry.  If it is not, GAS will define a new symbol at the start
161916dce513Schristosof a section.
162016dce513Schristos
162116dce513Schristos@item EMIT_SECTION_SYMBOLS
162216dce513Schristos@cindex EMIT_SECTION_SYMBOLS
162316dce513SchristosYou should define this macro with a zero value if you do not want to include
162416dce513Schristossection symbols in the output symbol table.  The default value for this macro
162516dce513Schristosis one.
162616dce513Schristos
162716dce513Schristos@item obj_adjust_symtab
162816dce513Schristos@cindex obj_adjust_symtab
162916dce513SchristosIf you define this macro, GAS will invoke it just before setting the symbol
163016dce513Schristostable of the output BFD.  For example, the COFF support uses this macro to
163116dce513Schristosgenerate a @code{.file} symbol if none was generated previously.
163216dce513Schristos
163316dce513Schristos@item SEPARATE_STAB_SECTIONS
163416dce513Schristos@cindex SEPARATE_STAB_SECTIONS
163516dce513SchristosYou may define this macro to a nonzero value to indicate that stabs should be
163616dce513Schristosplaced in separate sections, as in ELF.
163716dce513Schristos
163816dce513Schristos@item INIT_STAB_SECTION
163916dce513Schristos@cindex INIT_STAB_SECTION
164016dce513SchristosYou may define this macro to initialize the stabs section in the output file.
164116dce513Schristos
164216dce513Schristos@item OBJ_PROCESS_STAB
164316dce513Schristos@cindex OBJ_PROCESS_STAB
164416dce513SchristosYou may define this macro to do specific processing on a stabs entry.
164516dce513Schristos
164616dce513Schristos@item obj_frob_section
164716dce513Schristos@cindex obj_frob_section
164816dce513SchristosIf you define this macro, GAS will call it for each section at the end of the
164916dce513Schristosassembly.
165016dce513Schristos
165116dce513Schristos@item obj_frob_file_before_adjust
165216dce513Schristos@cindex obj_frob_file_before_adjust
165316dce513SchristosIf you define this macro, GAS will call it after the symbol values are
165416dce513Schristosresolved, but before the fixups have been changed from local symbols to section
165516dce513Schristossymbols.
165616dce513Schristos
165716dce513Schristos@item obj_frob_symbol
165816dce513Schristos@cindex obj_frob_symbol
165916dce513SchristosIf you define this macro, GAS will call it for each symbol.  You can indicate
166016dce513Schristosthat the symbol should not be included in the object file by defining this
166116dce513Schristosmacro to set its second argument to a non-zero value.
166216dce513Schristos
166316dce513Schristos@item obj_set_weak_hook
166416dce513Schristos@cindex obj_set_weak_hook
166516dce513SchristosIf you define this macro, @code{S_SET_WEAK} will call it before modifying the
166616dce513Schristossymbol's flags.
166716dce513Schristos
166816dce513Schristos@item obj_clear_weak_hook
166916dce513Schristos@cindex obj_clear_weak_hook
167016dce513SchristosIf you define this macro, @code{S_CLEAR_WEAKREFD} will call it after cleaning
167116dce513Schristosthe @code{weakrefd} flag, but before modifying any other flags.
167216dce513Schristos
167316dce513Schristos@item obj_frob_file
167416dce513Schristos@cindex obj_frob_file
167516dce513SchristosIf you define this macro, GAS will call it after the symbol table has been
167616dce513Schristoscompleted, but before the relocations have been generated.
167716dce513Schristos
167816dce513Schristos@item obj_frob_file_after_relocs
167916dce513SchristosIf you define this macro, GAS will call it after the relocs have been
168016dce513Schristosgenerated.
168116dce513Schristos
168216dce513Schristos@item SET_SECTION_RELOCS (@var{sec}, @var{relocs}, @var{n})
168316dce513Schristos@cindex SET_SECTION_RELOCS
168416dce513SchristosIf you define this, it will be called after the relocations have been set for
168516dce513Schristosthe section @var{sec}.  The list of relocations is in @var{relocs}, and the
168616dce513Schristosnumber of relocations is in @var{n}.
168716dce513Schristos@end table
168816dce513Schristos
168916dce513Schristos@node Emulations
169016dce513Schristos@subsection Writing emulation files
169116dce513Schristos
169216dce513SchristosNormally you do not have to write an emulation file.  You can just use
169316dce513Schristos@file{te-generic.h}.
169416dce513Schristos
169516dce513SchristosIf you do write your own emulation file, it must include @file{obj-format.h}.
169616dce513Schristos
169716dce513SchristosAn emulation file will often define @code{TE_@var{EM}}; this may then be used
169816dce513Schristosin other files to change the output.
169916dce513Schristos
170016dce513Schristos@node Relaxation
170116dce513Schristos@section Relaxation
170216dce513Schristos@cindex relaxation
170316dce513Schristos
170416dce513Schristos@dfn{Relaxation} is a generic term used when the size of some instruction or
170516dce513Schristosdata depends upon the value of some symbol or other data.
170616dce513Schristos
170716dce513SchristosGAS knows to relax a particular type of PC relative relocation using a table.
170816dce513SchristosYou can also define arbitrarily complex forms of relaxation yourself.
170916dce513Schristos
171016dce513Schristos@menu
171116dce513Schristos* Relaxing with a table::       Relaxing with a table
171216dce513Schristos* General relaxing::            General relaxing
171316dce513Schristos@end menu
171416dce513Schristos
171516dce513Schristos@node Relaxing with a table
171616dce513Schristos@subsection Relaxing with a table
171716dce513Schristos
171816dce513SchristosIf you do not define @code{md_relax_frag}, and you do define
171916dce513Schristos@code{TC_GENERIC_RELAX_TABLE}, GAS will relax @code{rs_machine_dependent} frags
172016dce513Schristosbased on the frag subtype and the displacement to some specified target
172116dce513Schristosaddress.  The basic idea is that several machines have different addressing
172216dce513Schristosmodes for instructions that can specify different ranges of values, with
172316dce513Schristossuccessive modes able to access wider ranges, including the entirety of the
172416dce513Schristosprevious range.  Smaller ranges are assumed to be more desirable (perhaps the
172516dce513Schristosinstruction requires one word instead of two or three); if this is not the
172616dce513Schristoscase, don't describe the smaller-range, inferior mode.
172716dce513Schristos
172816dce513SchristosThe @code{fr_subtype} field of a frag is an index into a CPU-specific
172916dce513Schristosrelaxation table.  That table entry indicates the range of values that can be
173016dce513Schristosstored, the number of bytes that will have to be added to the frag to
173116dce513Schristosaccommodate the addressing mode, and the index of the next entry to examine if
173216dce513Schristosthe value to be stored is outside the range accessible by the current
173316dce513Schristosaddressing mode.  The @code{fr_symbol} field of the frag indicates what symbol
173416dce513Schristosis to be accessed; the @code{fr_offset} field is added in.
173516dce513Schristos
173616dce513SchristosIf the @code{TC_PCREL_ADJUST} macro is defined, which currently should only happen
173716dce513Schristosfor the NS32k family, the @code{TC_PCREL_ADJUST} macro is called on the frag to
173816dce513Schristoscompute an adjustment to be made to the displacement.
173916dce513Schristos
174016dce513SchristosThe value fitted by the relaxation code is always assumed to be a displacement
174116dce513Schristosfrom the current frag.  (More specifically, from @code{fr_fix} bytes into the
174216dce513Schristosfrag.)
174316dce513Schristos@ignore
174416dce513SchristosThis seems kinda silly.  What about fitting small absolute values?  I suppose
174516dce513Schristos@code{md_assemble} is supposed to take care of that, but if the operand is a
174616dce513Schristosdifference between symbols, it might not be able to, if the difference was not
174716dce513Schristoscomputable yet.
174816dce513Schristos@end ignore
174916dce513Schristos
175016dce513SchristosThe end of the relaxation sequence is indicated by a ``next'' value of 0.  This
175116dce513Schristosmeans that the first entry in the table can't be used.
175216dce513Schristos
175316dce513SchristosFor some configurations, the linker can do relaxing within a section of an
175416dce513Schristosobject file.  If call instructions of various sizes exist, the linker can
175516dce513Schristosdetermine which should be used in each instance, when a symbol's value is
175616dce513Schristosresolved.  In order for the linker to avoid wasting space and having to insert
175716dce513Schristosno-op instructions, it must be able to expand or shrink the section contents
175816dce513Schristoswhile still preserving intra-section references and meeting alignment
175916dce513Schristosrequirements.
176016dce513Schristos
176116dce513SchristosFor the H8/300, I think the linker expands calls that can't reach, and doesn't
176216dce513Schristosworry about alignment issues; the cpu probably never needs any significant
176316dce513Schristosalignment beyond the instruction size.
176416dce513Schristos
176516dce513SchristosThe relaxation table type contains these fields:
176616dce513Schristos
176716dce513Schristos@table @code
176816dce513Schristos@item long rlx_forward
176916dce513SchristosForward reach, must be non-negative.
177016dce513Schristos@item long rlx_backward
177116dce513SchristosBackward reach, must be zero or negative.
177216dce513Schristos@item rlx_length
177316dce513SchristosLength in bytes of this addressing mode.
177416dce513Schristos@item rlx_more
177516dce513SchristosIndex of the next-longer relax state, or zero if there is no next relax state.
177616dce513Schristos@end table
177716dce513Schristos
177816dce513SchristosThe relaxation is done in @code{relax_segment} in @file{write.c}.  The
177916dce513Schristosdifference in the length fields between the original mode and the one finally
178016dce513Schristoschosen by the relaxing code is taken as the size by which the current frag will
178116dce513Schristosbe increased in size.  For example, if the initial relaxing mode has a length
178216dce513Schristosof 2 bytes, and because of the size of the displacement, it gets upgraded to a
178316dce513Schristosmode with a size of 6 bytes, it is assumed that the frag will grow by 4 bytes.
178416dce513Schristos(The initial two bytes should have been part of the fixed portion of the frag,
178516dce513Schristossince it is already known that they will be output.)  This growth must be
178616dce513Schristoseffected by @code{md_convert_frag}; it should increase the @code{fr_fix} field
178716dce513Schristosby the appropriate size, and fill in the appropriate bytes of the frag.
178816dce513Schristos(Enough space for the maximum growth should have been allocated in the call to
178916dce513Schristosfrag_var as the second argument.)
179016dce513Schristos
179116dce513SchristosIf relocation records are needed, they should be emitted by
179216dce513Schristos@code{md_estimate_size_before_relax}.  This function should examine the target
179316dce513Schristossymbol of the supplied frag and correct the @code{fr_subtype} of the frag if
179416dce513Schristosneeded.  When this function is called, if the symbol has not yet been defined,
179516dce513Schristosit will not become defined later; however, its value may still change if the
179616dce513Schristossection it is in gets relaxed.
179716dce513Schristos
179816dce513SchristosUsually, if the symbol is in the same section as the frag (given by the
179916dce513Schristos@var{sec} argument), the narrowest likely relaxation mode is stored in
180016dce513Schristos@code{fr_subtype}, and that's that.
180116dce513Schristos
180216dce513SchristosIf the symbol is undefined, or in a different section (and therefore movable
180316dce513Schristosto an arbitrarily large distance), the largest available relaxation mode is
180416dce513Schristosspecified, @code{fix_new} is called to produce the relocation record,
180516dce513Schristos@code{fr_fix} is increased to include the relocated field (remember, this
180616dce513Schristosstorage was allocated when @code{frag_var} was called), and @code{frag_wane} is
180716dce513Schristoscalled to convert the frag to an @code{rs_fill} frag with no variant part.
180816dce513SchristosSometimes changing addressing modes may also require rewriting the instruction.
180916dce513SchristosIt can be accessed via @code{fr_opcode} or @code{fr_fix}.
181016dce513Schristos
181116dce513SchristosIf you generate frags separately for the basic insn opcode and any relaxable
181216dce513Schristosoperands, do not call @code{fix_new} thinking you can emit fixups for the
181316dce513Schristosopcode field from the relaxable frag.  It is not guaranteed to be the same frag.
181416dce513SchristosIf you need to emit fixups for the opcode field from inspection of the
181516dce513Schristosrelaxable frag, then you need to generate a common frag for both the basic
181616dce513Schristosopcode and relaxable fields, or you need to provide the frag for the opcode to
181716dce513Schristospass to @code{fix_new}.  The latter can be done for example by defining
181816dce513Schristos@code{TC_FRAG_TYPE} to include a pointer to it and defining @code{TC_FRAG_INIT}
181916dce513Schristosto set the pointer.
182016dce513Schristos
182116dce513SchristosSometimes @code{fr_var} is increased instead, and @code{frag_wane} is not
182216dce513Schristoscalled.  I'm not sure, but I think this is to keep @code{fr_fix} referring to
182316dce513Schristosan earlier byte, and @code{fr_subtype} set to @code{rs_machine_dependent} so
182416dce513Schristosthat @code{md_convert_frag} will get called.
182516dce513Schristos
182616dce513Schristos@node General relaxing
182716dce513Schristos@subsection General relaxing
182816dce513Schristos
182916dce513SchristosIf using a simple table is not suitable, you may implement arbitrarily complex
183016dce513Schristosrelaxation semantics yourself.  For example, the MIPS backend uses this to emit
183116dce513Schristosdifferent instruction sequences depending upon the size of the symbol being
183216dce513Schristosaccessed.
183316dce513Schristos
183416dce513SchristosWhen you assemble an instruction that may need relaxation, you should allocate
183516dce513Schristosa frag using @code{frag_var} or @code{frag_variant} with a type of
183616dce513Schristos@code{rs_machine_dependent}.  You should store some sort of information in the
183716dce513Schristos@code{fr_subtype} field so that you can figure out what to do with the frag
183816dce513Schristoslater.
183916dce513Schristos
184016dce513SchristosWhen GAS reaches the end of the input file, it will look through the frags and
184116dce513Schristoswork out their final sizes.
184216dce513Schristos
184316dce513SchristosGAS will first call @code{md_estimate_size_before_relax} on each
184416dce513Schristos@code{rs_machine_dependent} frag.  This function must return an estimated size
184516dce513Schristosfor the frag.
184616dce513Schristos
184716dce513SchristosGAS will then loop over the frags, calling @code{md_relax_frag} on each
184816dce513Schristos@code{rs_machine_dependent} frag.  This function should return the change in
184916dce513Schristossize of the frag.  GAS will keep looping over the frags until none of the frags
185016dce513Schristoschanges size.
185116dce513Schristos
185216dce513Schristos@node Broken words
185316dce513Schristos@section Broken words
185416dce513Schristos@cindex internals, broken words
185516dce513Schristos@cindex broken words
185616dce513Schristos
185716dce513SchristosSome compilers, including GCC, will sometimes emit switch tables specifying
185816dce513Schristos16-bit @code{.word} displacements to branch targets, and branch instructions
185916dce513Schristosthat load entries from that table to compute the target address.  If this is
186016dce513Schristosdone on a 32-bit machine, there is a chance (at least with really large
186116dce513Schristosfunctions) that the displacement will not fit in 16 bits.  The assembler
186216dce513Schristoshandles this using a concept called @dfn{broken words}.  This idea is well
186316dce513Schristosnamed, since there is an implied promise that the 16-bit field will in fact
186416dce513Schristoshold the specified displacement.
186516dce513Schristos
186616dce513SchristosIf broken word processing is enabled, and a situation like this is encountered,
186716dce513Schristosthe assembler will insert a jump instruction into the instruction stream, close
186816dce513Schristosenough to be reached with the 16-bit displacement.  This jump instruction will
186916dce513Schristostransfer to the real desired target address.  Thus, as long as the @code{.word}
187016dce513Schristosvalue really is used as a displacement to compute an address to jump to, the
187116dce513Schristosnet effect will be correct (minus a very small efficiency cost).  If
187216dce513Schristos@code{.word} directives with label differences for values are used for other
187316dce513Schristospurposes, however, things may not work properly.  For targets which use broken
187416dce513Schristoswords, the @samp{-K} option will warn when a broken word is discovered.
187516dce513Schristos
187616dce513SchristosThe broken word code is turned off by the @code{WORKING_DOT_WORD} macro.  It
187716dce513Schristosisn't needed if @code{.word} emits a value large enough to contain an address
187816dce513Schristos(or, more correctly, any possible difference between two addresses).
187916dce513Schristos
188016dce513Schristos@node Internal functions
188116dce513Schristos@section Internal functions
188216dce513Schristos
188316dce513SchristosThis section describes basic internal functions used by GAS.
188416dce513Schristos
188516dce513Schristos@menu
188616dce513Schristos* Warning and error messages::  Warning and error messages
188716dce513Schristos* Hash tables::                 Hash tables
188816dce513Schristos@end menu
188916dce513Schristos
189016dce513Schristos@node Warning and error messages
189116dce513Schristos@subsection Warning and error messages
189216dce513Schristos
189316dce513Schristos@deftypefun  @{@} int had_warnings (void)
189416dce513Schristos@deftypefunx @{@} int had_errors (void)
189516dce513SchristosReturns non-zero if any warnings or errors, respectively, have been printed
189616dce513Schristosduring this invocation.
189716dce513Schristos@end deftypefun
189816dce513Schristos
189916dce513Schristos@deftypefun  @{@} void as_tsktsk (const char *@var{format}, ...)
190016dce513Schristos@deftypefunx @{@} void as_warn (const char *@var{format}, ...)
190116dce513Schristos@deftypefunx @{@} void as_bad (const char *@var{format}, ...)
190216dce513Schristos@deftypefunx @{@} void as_fatal (const char *@var{format}, ...)
190316dce513SchristosThese functions display messages about something amiss with the input file, or
190416dce513Schristosinternal problems in the assembler itself.  The current file name and line
190516dce513Schristosnumber are printed, followed by the supplied message, formatted using
190616dce513Schristos@code{vfprintf}, and a final newline.
190716dce513Schristos
190816dce513SchristosAn error indicated by @code{as_bad} will result in a non-zero exit status when
190916dce513Schristosthe assembler has finished.  Calling @code{as_fatal} will result in immediate
191016dce513Schristostermination of the assembler process.
191116dce513Schristos@end deftypefun
191216dce513Schristos
191316dce513Schristos@deftypefun @{@} void as_warn_where (char *@var{file}, unsigned int @var{line}, const char *@var{format}, ...)
191416dce513Schristos@deftypefunx @{@} void as_bad_where (char *@var{file}, unsigned int @var{line}, const char *@var{format}, ...)
191516dce513SchristosThese variants permit specification of the file name and line number, and are
191616dce513Schristosused when problems are detected when reprocessing information saved away when
191716dce513Schristosprocessing some earlier part of the file.  For example, fixups are processed
191816dce513Schristosafter all input has been read, but messages about fixups should refer to the
191916dce513Schristosoriginal filename and line number that they are applicable to.
192016dce513Schristos@end deftypefun
192116dce513Schristos
192216dce513Schristos@node Test suite
192316dce513Schristos@section Test suite
192416dce513Schristos@cindex test suite
192516dce513Schristos
192616dce513SchristosThe test suite is kind of lame for most processors.  Often it only checks to
192716dce513Schristossee if a couple of files can be assembled without the assembler reporting any
192816dce513Schristoserrors.  For more complete testing, write a test which either examines the
192916dce513Schristosassembler listing, or runs @code{objdump} and examines its output.  For the
193016dce513Schristoslatter, the TCL procedure @code{run_dump_test} may come in handy.  It takes the
193116dce513Schristosbase name of a file, and looks for @file{@var{file}.d}.  This file should
193216dce513Schristoscontain as its initial lines a set of variable settings in @samp{#} comments,
193316dce513Schristosin the form:
193416dce513Schristos
193516dce513Schristos@example
193616dce513Schristos        #@var{varname}: @var{value}
193716dce513Schristos@end example
193816dce513Schristos
193916dce513SchristosThe @var{varname} may be @code{objdump}, @code{nm}, or @code{as}, in which case
194016dce513Schristosit specifies the options to be passed to the specified programs.  Exactly one
194116dce513Schristosof @code{objdump} or @code{nm} must be specified, as that also specifies which
194216dce513Schristosprogram to run after the assembler has finished.  If @var{varname} is
194316dce513Schristos@code{source}, it specifies the name of the source file; otherwise,
194416dce513Schristos@file{@var{file}.s} is used.  If @var{varname} is @code{name}, it specifies the
194516dce513Schristosname of the test to be used in the @code{pass} or @code{fail} messages.
194616dce513Schristos
194716dce513SchristosThe non-commented parts of the file are interpreted as regular expressions, one
194816dce513Schristosper line.  Blank lines in the @code{objdump} or @code{nm} output are skipped,
194916dce513Schristosas are blank lines in the @code{.d} file; the other lines are tested to see if
195016dce513Schristosthe regular expression matches the program output.  If it does not, the test
195116dce513Schristosfails.
195216dce513Schristos
195316dce513SchristosNote that this means the tests must be modified if the @code{objdump} output
195416dce513Schristosstyle is changed.
195516dce513Schristos
195616dce513Schristos@bye
195716dce513Schristos@c Local Variables:
195816dce513Schristos@c fill-column: 79
195916dce513Schristos@c End:
1960