You copied the Doc URL to your clipboard.

21.45 IMPORT and EXTERN

The IMPORT and EXTERN directives provide the assembler with a name that is not defined in the current assembly.

Syntax

directive symbol {[SIZE=n]}

directive symbol {[type]}

directive symbol [attr{,type}{,SIZE=n}]

directive symbol [WEAK {,attr}{,type}{,SIZE=n}]

where:

directive

can be either:

IMPORT

imports the symbol unconditionally.

EXTERN

imports the symbol only if it is referred to inthe current assembly.

symbol

is a symbol name defined in a separately assembledsource file, object file, or library. The symbol name is case-sensitive.

WEAK

prevents the linker generating an error messageif the symbol is not defined elsewhere. It also prevents the linkersearching libraries that are not already included.

attr

can be any one of:

DYNAMIC

sets the ELF symbol visibility to STV_DEFAULT.

PROTECTED

sets the ELF symbol visibility to STV_PROTECTED.

HIDDEN

sets the ELF symbol visibility to STV_HIDDEN.

INTERNAL

sets the ELF symbol visibility to STV_INTERNAL.

type

specifies the symbol type:

DATA

symbol is treatedas data when the source is assembled and linked.

CODE

symbol is treatedas code when the source is assembled and linked.

ELFTYPE=n

symbol is treatedas a particular ELF symbol, as specified by the value of n,where n can be any number from 0 to 15.

If unspecified, the linker determines the most appropriatetype.

n

specifies the size and can be any 32-bit value.If the SIZE attribute is not specified, theassembler calculates the size:

  • For PROC and FUNCTION symbols,the size is set to the size of the code until its ENDP or ENDFUNC.

  • For other symbols, the size is the size of instructionor data on the same source line. If there is no instruction or data,the size is zero.

Usage

The name is resolved at link time to a symbol defined in aseparate object file. The symbol is treated as a program address.If [WEAK] is not specified, the linker generatesan error if no corresponding symbol is found at link time.

If [WEAK] is specified and no corresponding symbolis found at link time:

  • If the referenceis the destination of a B or BL instruction,the value of the symbol is taken as the address of the followinginstruction. This makes the B or BL instructioneffectively a NOP.

  • Otherwise, the value of the symbol is taken as zero.

Example

The 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.

The following examples show the use of the SIZE attribute:

    EXTERN symA [SIZE=4]    EXTERN symA [DATA, SIZE=4]

Related reference

Related information

Was this page helpful? Yes No