| Steering file commands4.4.2. Steering file commandsSteering 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.
NoteThe steering file commands control only global symbols. Local symbols are not affected by any command. The IMPORT command specifies that a symbol is defined in a shared object at runtime. IMPORT pattern [ AS replacement_pattern] [ ,pattern [ AS replacement_pattern]] *
where: patternIs 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_patternIs 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.
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. NoteThe 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. The EXPORT command specifies that a symbol can be accessed by other shared objects or executables. EXPORT pattern [ AS replacement_pattern] [ ,pattern [ AS replacement_pattern]] *
where: patternIs 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_patternIs 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.
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. The RENAME command renames defined and undefined global symbol names. RENAME pattern AS replacement_pattern [ ,pattern AS replacement_pattern] *
where: patternIs 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_patternIs 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.
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. The RESOLVE command matches specific undefined references to a defined global symbol. RESOLVE pattern AS defined_pattern
where: patternIs a string, optionally including wildcard characters, that must be matched to a defined global symbol. defined_patternIs 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.
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()
{
}
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. REQUIRE pattern [ ,pattern] *
where: patternIs a string representing a filename. No wildcards are permitted.
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. NoteDT_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.
The HIDE command makes defined global symbols in the symbol table anonymous. HIDE pattern [ ,pattern] *
where: patternIs 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.
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. 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. SHOW pattern [ ,pattern] *
where: patternIs 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.
The usage of SHOW is closely related to that of HIDE. See HIDE for further information. |