| |||
| Home > Directives Reference > Miscellaneous directives > EXTERN | |||
The EXTERN directive provides the assembler with
a name that is not defined in the current assembly.
EXTERN is very similar to IMPORT,
except that the name is not imported if no reference to it is found
in the current assembly (see IMPORT, and EXPORT or GLOBAL).
EXTERNsymbol{[WEAK,attr]}
where:
symbolis a symbol name defined in a separately assembled source file, object file, or library. The symbol name is case-sensitive.
[WEAK]prevents the linker generating an error message if the symbol is not defined elsewhere. It also prevents the linker searching libraries that are not already included.
[attr]is symbol visibility when linked into a dynamic component. By default, the symbol binding defines visibility, that is, global and weak symbols are visible to other external objects and local symbols are not hidden.
Valid attributes are:
DYNAMIC is
visible to other components, and can be redefined by other components.symbol
HIDDEN cannot
be referenced outside the component where it is defined, either
directly or indirectly.symbol
The linker also accepts INTERNAL and
currently treats it as HIDDEN. If you specify
both, for example:
EXTERN SymA[WEAK,INTERNAL,HIDDEN]
the assembler chooses the most restrictive (INTERNAL).
PROTECTED is
visible to other components, and cannot be redefined by other components.symbol
The name is resolved at link time to a symbol defined in a
separate object file. The symbol is treated as a program address.
If [WEAK] is not specified, the linker generates an
error if no corresponding symbol is found at link time.
If [WEAK] is specified and no corresponding
symbol is found at link time:
If the
reference is the destination of a B or BL instruction,
the value of the symbol is taken as the address of the following
instruction. This makes the B or BL instruction
effectively a NOP.
Otherwise, the value of the symbol is taken as zero.
This example tests to see if the C++ library has been linked, and branches conditionally on the result.
AREA Example, CODE, READONLY
EXTERN __CPP_INITIALIZE[WEAK] ; If C++ library linked, gets the address of
; __CPP_INITIALIZE function.
LDR r0,=__CPP_INITIALIZE ; If not linked, address is zeroed.
CMP r0,#0 ; Test if zero.
BEQ nocplusplus ; Branch on the result.