5.8.43. IMPORT or EXTERN directive

The IMPORT directive provides the assembler with a name that is not defined in the current assembly. EXTERN is a synonym for IMPORT. See also EXPORT or GLOBAL directive.

Syntax

The syntax of IMPORT is:

IMPORT symbol{[qualifier{,qualifier}]}

where:

symbol

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

qualifier

can be:

FPREGARGS

specifies that symbol defines a function that expects floating-point arguments passed in floating-point registers.

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.

Usage

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 Branch or Branch Link instruction, the value of the symbol is taken as the address of the referencing instruction. The instruction becomes B {PC} or BL {PC}.

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

You must avoid executing B {PC} and BL {PC} at runtime as they are non-terminating loops.

To avoid trying to access symbols that are not found at link time, use code like the example below to test your environment at runtime.

Example

This example tests to see if the C++ library has been linked, and branches conditionally on the result.

		AREA 		Example, CODE, READONLY
		IMPORT 		__CPP_INITIALIZE[WEAK]						; If C++ library linked
										; gets the address of
										; CPP_INIT function.
		LDR		r0,__CPP_INITIALIZE						; If not linked, address
										; is zeroed.
		CMP		r0,#0						; Test if zero.
		BEQ		nocplusplus						; Branch on the result.
Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0041C
Non-Confidential