Keil™, An ARM® Company

RealView Linker and Utilities Guide

Steering file commands

4.4.2. Steering file commands

Steering file commands enable you to:

  • manage symbols in the symbol table

  • control the copying of symbols from the static symbol table to the dynamic symbol table

  • store information about the libraries that a link unit depends on.

Note

The steering file commands control only global symbols. Local symbols are not affected by any command.

IMPORT

The IMPORT command specifies that a symbol is defined in a shared object at runtime.

Syntax

IMPORT pattern [ AS replacement_pattern] [ ,pattern [ AS replacement_pattern]] *

where:

pattern

Is a string, optionally including wildcard characters (either * or ?), that matches zero or more undefined global symbols. If pattern does not match any undefined global symbol, the linker ignores the command. The operand can match only undefined global symbols.

replacement_pattern

Is a string, optionally including wildcard characters (either * or ?), to which the undefined global symbol is to be renamed. Wildcards must have a corresponding wildcard in replacement_pattern. The characters matched by the replacement_pattern wildcard are substituted for the pattern wildcard.

For example:

IMPORT my_func AS func

imports and renames the undefined symbol my_func as func.

Usage

You cannot import a symbol that has been defined in the current shared object or executable. Only one wildcard character (either * or ?) is permitted in IMPORT.

The undefined symbol is included in the dynamic symbol table (as replacement_pattern if given, otherwise as pattern), if a dynamic symbol table is present.

Note

The IMPORT command only affects undefined global symbols. Symbols that have been resolved by a shared library are implicitly imported into the dynamic symbol table. The linker ignores any IMPORT directive that targets an implicitly imported symbol.

EXPORT

The EXPORT command specifies that a symbol can be accessed by other shared objects or executables.

Syntax

EXPORT pattern [ AS replacement_pattern] [ ,pattern [ AS replacement_pattern]] *

where:

pattern

Is a string, optionally including wildcard characters (either * or ?), that matches zero or more defined global symbols. If pattern does not match any defined global symbol, the linker ignores the command. The operand can match only defined global symbols.

replacement_pattern

Is a string, optionally including wildcard characters (either * or ?), to which the defined global symbol is to be renamed. Wildcards must have a corresponding wildcard in replacement_pattern. The characters matched by the replacement_pattern wildcard are substituted for the pattern wildcard.

For example:

EXPORT my_func AS func1

renames and exports the defined symbol my_func as func1.

Usage

You cannot export a symbol to a name that already exists. Only one wildcard character (either * or ?) is permitted in EXPORT.

The defined global symbol is included in the dynamic symbol table (as replacement_pattern if given, otherwise as pattern), if a dynamic symbol table is present.

RENAME

The RENAME command renames defined and undefined global symbol names.

Syntax

RENAME pattern AS replacement_pattern [ ,pattern AS replacement_pattern] *

where:

pattern

Is a string, optionally including wildcard characters (either * or ?), that matches zero or more global symbols. If pattern does not match any global symbol, the linker ignores the command. The operand can match both defined and undefined symbols.

replacement_pattern

Is a string, optionally including wildcard characters (either * or ?), to which the symbol is to be renamed. Wildcards must have a corresponding wildcard in pattern. The characters matched by the pattern wildcard are substituted for the replacement_pattern wildcard.

For example, for a symbol named func1:

RENAME f* AS my_f*

renames func1 to my_func1.

Usage

You cannot rename a symbol to a symbol name that already exists, even if the target symbol name is being renamed itself. Only one wildcard character (either * or ?) is permitted in RENAME. For example, given an image containing the symbols func1, func2, and func3:

EXPORT func1 AS func2    ;invalid, func2 exists
RENAME func3 AS b2
EXPORT func1 AS func3    ;invalid, func3 exists, even though it is renamed to b2

The linker processes the steering file before doing any replacements. You cannot, therefore, use RENAME A AS B on line 1 and then RENAME B AS A on line 2.

RESOLVE

The RESOLVE command matches specific undefined references to a defined global symbol.

Syntax

RESOLVE pattern AS defined_pattern

where:

pattern

Is a string, optionally including wildcard characters, that must be matched to a defined global symbol.

defined_pattern

Is a string, optionally including wildcard characters, that matches zero or more defined global symbols. If defined_pattern does not match any defined global symbol, the linker ignores the command. You cannot match an undefined reference to an undefined symbol.

Usage

RESOLVE is an extension of the existing armlink ‑‑unresolved command-line option. The difference is that ‑‑unresolved enables all undefined references to match one single definition, whereas RESOLVE enables more specific matching of references to symbols.

The undefined references are removed from the output symbol table.

RESOLVE works when performing partial-linking and when linking normally.

For example, you might have two files file1.c and file2.c, as shown in Example 4.4. Create an ed.txt file containing the line RESOLVE MP3* AS MyMP3*, and issue the following command:

armlink file1.o file2.o ‑‑edit ed.txt ‑‑unresolved foobar

This command has the following effects:

  • The references from file1.o (foo, MP3_Init() and MP3_Play()) are matched to the definitions in file2.o (foobar, MyMP3_Init() and MyMP3_Play() respectively), as specified by the steering file ed.txt.

  • The RESOLVE command in ed.txt matches the MP3 functions and the ‑‑unresolved option matches any other remaining references, in this case, foo to foobar.

  • The output symbol table, whether it is an image or a partial object, does not contain the symbols foo, MP3_Init or MP3_Play.

Example 4.4. Using the RESOLVE command

file1.c

extern int foo;
extern void MP3_Init(void);
extern void MP3_Play(void);

int main(void)
{
  int x = foo + 1;
  MP3_Init();
  MP3_Play();
  return x;
}


file2.c:

int foobar;
void MyMP3_Init()
{
}
void MyMP3_Play()
{
}

REQUIRE

The REQUIRE command creates a DT_NEEDED tag in the dynamic array. DT_NEEDED tags specify dependencies to other shared objects used by the application, for example, a shared library.

Syntax

REQUIRE pattern [ ,pattern] *

where:

pattern

Is a string representing a filename. No wildcards are permitted.

Usage

The linker inserts a DT_NEEDED tag with the value of pattern into the dynamic array. This tells the dynamic loader that the file it is currently loading requires pattern to be loaded.

Note

DT_NEEDED tags inserted as a result of a REQUIRE command are added after DT_NEEDED tags generated from shared objects or DLLs placed on the command line.

HIDE

The HIDE command makes defined global symbols in the symbol table anonymous.

Syntax

HIDE pattern [ ,pattern] *

where:

pattern

Is a string, optionally including wildcard characters, that matches zero or more defined global symbols. If pattern does not match any defined global symbol, the linker ignores the command. You cannot hide undefined symbols.

Usage

HIDE and SHOW can be used to make certain global symbols anonymous in an output image or partially linked object. Hiding symbols in an object file or library can be useful as a means of protecting intellectual property, as shown in Example 4.5. This example produces a partially linked object with all global symbols hidden, except those beginning with os_.

Example 4.5. Using the HIDE command

steer.txt

HIDE *            ; Hides all global symbols
SHOW os_*         ; Shows all symbols beginning with ’os_’

Link this example with the command:

armlink ‑‑partial input_object.o ‑‑edit steer.txt ‑o partial_object.o

This example can be linked with other objects, provided they do not contain references to the hidden symbols. When symbols are hidden in the output object, SHOW commands in subsequent link steps have no effect on them. The hidden references are removed from the output symbol table.

SHOW

The SHOW command makes global symbols visible. This command is useful if you want to unhide a specific symbol that are hidden using a HIDE command with a wildcard.

Syntax

SHOW pattern [ ,pattern] *

where:

pattern

Is a string, optionally including wildcard characters, that matches zero or more global symbols. If pattern does not match any global symbol, the linker ignores the command.

Usage

The usage of SHOW is closely related to that of HIDE. See HIDE for further information.

Copyright © 2007 ARM Limited. All rights reserved.ARM DUI 0377A