9.5.3.2 Provide Command
The PROVIDE
command defines a referenced symbol that is
not otherwise defined.
In some cases, it is desirable for a linker script to define a symbol only if it is
referenced and is not defined by any object included in the link. For example, traditional
linkers defined the symbol
etext
. However, the C standard
indicates that etext
is a valid function name. The PROVIDE
keyword may be used to define a symbol, such as etext
, only if it is referenced but not defined. The syntax is:
PROVIDE(symbol = expression)
.Here is an example of using
PROVIDE
to
define etext
: SECTIONS
{
.text :
{
*(.text)
_etext = .;
PROVIDE(etext = .);
}
}
If the symbol etext
is defined by the program, that definition
is used by the linker. If it is not defined by the program, then the definition provided by
the linker script is used. Compare this with the definition for _etext
(with
a leading underscore) in the linker script, which will trigger an error if it is also defined
in the program.The default linker script used with PIC32M devices makes use of the
PROVIDE
command to define the default _min_stack_size
, _min_heap_size
,
and _vector_spacing
symbol values, for
example:PROVIDE(_min_stack_size = 0x400) ;
PROVIDE(_min_heap_size = 0) ;
PROVIDE(_vector_spacing = 0x00000001);