ELF Linker and Command Language. freescale ColdFire v6.0
Reklama
Reklama
CF.book Page 77 Friday, July 8, 2005 8:59 AM
ELF Linker and Command
Language
6
This chapter explains the CodeWarrior Executable and Linking Format (ELF) Linker.
Beyond making a program file from your project’s object files, the linker has several extended functions for manipulating program code in different ways. You can define variables during linking, control the link order down to the level of single functions, and change the alignment.
You access these functions through commands in the linker command file (LCF). The
LCF syntax and structure are similar to those of a programming language; the syntax includes keywords, directives, and expressions.
This chapter consists of these sections:
• Commands, Directives, and Keywords
LCF Structure
Linker command files consist of three kinds of segments, which must be in this order:
• A memory segment, which begins with the MEMORY{} directive
• Optional closure segments, which begin with the FORCE_ACTIVE{},
KEEP_SECTION{}
, or REF_INCLUDE{} directives
• A sections segment, which begins with the SECTIONS{} directive
Memory Segment
Use the memory segment to divide available memory into segments. Listing 6.1 shows the
pattern.
Listing 6.1 Example Memory Segment
MEMORY { segment_1 (RWX): ORIGIN = 0x80001000, LENGTH = 0x19000
ColdFire Architectures v6.0 - Targeting Manual 77
CF.book Page 78 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Structure segment_2 (RWX): ORIGIN = AFTER(segment_1), LENGTH = 0 segment_x (RWX): ORIGIN = memory address, LENGTH = segment size and so on...
}
In this pattern:
• The (RWX) portion consists of ELF-access permission flags: R = read, W = write, or X
= execute.
• ORIGIN specifies the start address of the memory segment — either an actual memory address or, via the AFTER keyword, the name of the preceding segment.
• LENGTH specifies the size of the memory segment. The value 0 means unlimited
length.
The segment_2 line of Listing 6.1 shows how to use the AFTER and LENGTH
commands to specify a memory segment, even though you do not know the starting address or exact length.
The explanation of the MEMORY directive, at MEMORY, includes more information about
the memory segment.
Closure Segments
An important feature of the linker is deadstripping unused code and data. At times, however, an output file should keep symbols even if there are no direct references to the symbols. Linking for interrupt handlers, for example, usually is at special addresses, without any explicit, control-transfer jumps.
Closure segments let you make symbols immune from deadstripping. This closure is
transitive, so that closing a symbol also forces closure on all other referenced symbols.
For example, suppose that:
• Symbol _abc references symbols _def and _ghi,
• Symbol _def references symbols _jkl and _mno, and
• Symbol _ghi references symbol _pqr
Specifying symbol _abc in a closure segment would force closure on all six of these symbols.
The three closure-segment directives have specific uses:
• FORCE_ACTIVE — Use this directive to make the linker include a symbol that it otherwise would not include.
• KEEP_SECTION — Use this directive to keep a section in the link, particularly a user-defined section.
78 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 79 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Structure
• REF_INCLUDE — Use this directive to keep a section in the link, provided that there is a reference to the file that contains the section. This is a useful way to include version numbers.
Listing 6.2 shows an example of each directive.
Listing 6.2 Example Closure Sections
# 1st closure segment keeps 3 symbols in link
FORCE_ACTIVE {break_handler, interrupt_handler, my_function}
# 2nd closure segment keeps 2 sections in link
KEEP_SECTION {.interrupt1, .interrupt2}
# 3rd closure segment keeps file-dependent section in link
REF_INCLUDE {.version}
Sections Segment
Use the sections segment to define the contents of memory sections, and to define any
global symbols that you want to use in your output file. Listing 6.3 shows the format of a
sections segment.
Listing 6.3 Example Sections Segment
SECTIONS {
.section_name : #The section name, for your reference,
{ # must begin with a period.
filename.c
(.text) #Put .text section from filename.c, filename2.c (.text) #then put .text section from filename2.c, filename.c
(.data) #then put .data section from filename.c, filename2.c (.data) #then put .data section from filename2.c, filename.c
(.bss) #then put .bss section from filename.c, filename2.c (.bss) #then put .bss section from filename2.c.
. = ALIGN (0x10); #Align next section on 16-byte boundary.
} > segment_1
.next_section_name:
#Map these contents to segment_1.
{ more content descriptions
}
} > segment_x #End of .next_section_name definition
#End of sections segment
The explanation of the SECTIONS directive, at SECTIONS, includes more information
about the sections segment.
ColdFire Architectures v6.0 - Targeting Manual 79
CF.book Page 80 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
LCF Syntax
This section explains LCF commands, including practical ways to use them. Subsections are:
• Variables, Expressions, and Integrals
• Arithmetic, Comment Operators
• Specifying Files and Functions
• Position-Independent Code and Data
• Writing Data Directly to Memory
Variables, Expressions, and Integrals
In a linker command file, all symbol names must start with the underscore character (_).
The other characters can be letters, digits, or underscores. These valid lines for an LCF assign values to two symbols:
_dec_num = 99999999;
_hex_num_ = 0x9011276;
Use the standard assignment operator to create global symbols and assign their addresses, according to the pattern:
_symbolicname = some_expression;
NOTE
There must be a semicolon at the end of a symbol assignment statement.
A symbol assignment is valid only at the start of an expression, so a line such as this is not valid: you cannot use something like this:
_sym1 + _sym2 = _sym3;
When the system evaluates an expression and assigns it to a variable, the expression receives the type value absolute or a relocatable:
• Absolute expression — the symbol contains the value that it will have in the output file.
80 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 81 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
• Relocatable expression — the value expression is a fixed offset from the base of a section.
LCF syntax for expressions is very similar to the syntax of the C programming language:
• All integer types are long or unsigned long.
• Octal integers begin with a leading zero; other digits are 0 through 7, as these symbol assignments show:
_octal_number = 01374522;
_octal_number2 = 032405;
• Decimal integers begin with any non-zero digit; other digits are 0 through 9, as these symbol assignments show:
_dec_num = 99999999;
_decimal_number = 123245;
_decvalfour = 9011276;
• Hexadecimal integers begin with a zero and the letter x; other digits are 0 through f, as these symbol assignments show:
_hex_number = 0x999999FF;
_firstfactorspace = 0X123245EE;
_fifthhexval = 0xFFEE;
• Negative integers begin with a minus sign:
_decimal_number = -123456;
Arithmetic, Comment Operators
Use standard C arithmetic and logical operations as you define and use symbols in the
LCF. All operators are left-associative. Table 6.1 lists these operators in the order of
precedence. For additional information about these operators, refer to the C Compiler
Reference.
Table 6.1 LCF Arithmetic Operators
2
3
Precedence
1
4
Operators
- ˜ !
* / %
+ -
>> <<
ColdFire Architectures v6.0 - Targeting Manual 81
CF.book Page 82 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
Table 6.1 LCF Arithmetic Operators ( continued)
7
8
9
Precedence
5
6
|
&&
||
Operators
== != > < <= >=
&
To add comments to your file, use the pound character, C-style slash and asterisk characters, or C++-style double-slash characters, in any of these formats:
# This is a one-line comment
/* This is a
multiline comment */
* (.text) // This is a partial-line comment
Alignment
To align data on a specific byte boundary, use the ALIGN keyword or the ALIGNALL
command. Listing 6.4 and Listing 6.5 are examples for bumping the location counter to
the next 16-byte boundary.
Listing 6.4 ALIGN Keyword Example
file.c (.text)
. = ALIGN (0x10); file.c (.data) # aligned on 16-byte boundary.
Listing 6.5 ALIGNALL Command Example
file.c (.text)
ALIGNALL (0x10); #everything past this point aligned
# on 16 byte boundary file.c (.data)
NOTE
If one segment entry imposes an alignment requirement, that segment’s starting address must conform to that requirement. Otherwise, there could be
82 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 83 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax conflicting section alignment in the code the linker produces.
In general, the instructions for data alignment should be lust before the end of the section.
For more alignment information, see ALIGN
and
Specifying Files and Functions
Defining the contents of a sections segment includes specifying the source file of each
section. The standard method is merely listing the files, as Listing 6.6 shows.
Listing 6.6 Standard Source-File Specification
SECTIONS {
.example_section :
{ main.c
(.text) file2.c (.text) file3.c (.text)
# and so forth
For a large project, however, such a list can be very long. To shorten it, you can use the asterisk ( * ) wild-card character, which represents the filenames of every file in your project. The line
* (.text) in a section definition tells the system to include the .text section from each file.
Furthermore the * wildcard does not duplicate sections already specified; you need not
replace existing lines of the code. In Listing 6.6, replacing the # and so forth
comment line with
* (.text) would add the .text sections from all other project files, without duplicating the .text sections from files main.c, file2.c, or file3.c.
Another possibility as you define a sections segment, is specifying sections from a named group of files. To do so, use the GROUP keyword:
GROUP(fileGroup1) (.text)
GROUP(fileGroup4) (.data)
These two lines would specify including the .text sections from all fileGroup1 files, and the .data sections from all fileGroup4 files.
ColdFire Architectures v6.0 - Targeting Manual 83
CF.book Page 84 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
For precise control over function placement within a section, use the OBJECT keyword.
For example, to place functions beta and alpha before anything else in a section, your
definition could be like Listing 6.7.
Listing 6.7 Function Placement Example
SECTIONS {
.program_section :
{
OBJECT (beta, main.c) # Function beta is 1st section item
OBJECT (alpha, main.c) # Function alpha is 2nd section_item
* (.text) # Remaining_items are .text sections from all files
} > ROOT
NOTE
For C++, you must specify functions by their mangled names.
If you use the OBJECT keyword to specify a function, subsequently using * wild-card character does not specify that function a second time.
For more information about specifying files and functions, see the explanations OBJECT
Stack and Heap
Reserving space for the stack requires some arithmetic operations to set the symbol values
used at runtime. Listing 6.8 is a sections-segment definition code fragment that shows this
arithmetic.
Listing 6.8 Stack Setup Operations
_stack_address = __END_BSS;
_stack_address = _stack_address & ~7; /*align top of stack by 8*/
__SP_INIT = _stack_address + 0x4000; /*set stack to 16KB*/
The heap requires a similar space reservation, which Listing 6.9 shows. Note that the
bottom address of the stack is the top address of the heap.
Listing 6.9 Heap Setup Operations
___heap_addr = __SP_INIT; /* heap grows opposite stack */
___heap_size = 0x50000; /* heap size set to 500KB */
84 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 85 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
Static Initializers
You must invoke static initializers to initialize static data before the start of main(). To do so, use the STATICINIT keyword to have the linker generate the static initializer sections.
In your linker command file, use lines similar to these to tell the linker where to put the table of static initializers (relative to the '.' location counter):
___sinit__ = .;
STATICINIT
The program knows the symbol ___sinit__ at runtime. So in startup code, you can use corresponding lines such as these:
#ifdef __cplusplus
/* call the c++ static initializers */
__call_static_initializers();
#endif
Exception Tables
You need exception tables only for C++ code. To create one, add the EXCEPTION
command to the end of your code section — Listing 6.10 is an example.
The program knows the two symbols __exception_table_start__ and
__exception_table_end__
at runtime.
Listing 6.10 Creating an Exception Table
__exception_table_start__ = .;
EXCEPTION
__exception_table_end__ = .;
Position-Independent Code and Data
For position-independent code (PIC) and position-independent data (PID), your LCF must include .picdynrel and .piddynrel sections. These sections specify where to store the PIC and PID dynamic relocation tables.
In addition, your LCF must define these six symbols:
__START_PICTABLE __END_PICTABLE __PICTABLE_SIZE
__START_PIDTABLE __END_PIDTABLE __PIDTABLE_SIZE
Listing 6.11 is an example definition for PIC and PID.
ColdFire Architectures v6.0 - Targeting Manual 85
CF.book Page 86 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
Listing 6.11 PIC, PID Section Definition
.pictables :
{
. = ALIGN(0x8);
__START_PICTABLE = .;
*(.picdynrel)__END_PICTABLE = .;
__PICTABLE_SIZE = __END_PICTABLE - __START_PICTABLE;
__START_PIDTABLE = .;
*(.piddynrel)__END_PIDTABLE = .;
__PIDTABLE_SIZE = __END_PIDTABLE - __START_PIDTABLE;
} >> DATA
ROM-RAM Copying
In embedded programming, it is common that data or code of a program residing in ROM gets copied into RAM at runtime.
To indicate such data or code, use the LCF to assign it two addresses:
• The memory segment specifies the intended location in RAM
• The sections segment specifies the resident location in ROM, via its AT (address) parameter
For example, suppose that we want to copy all initialized data into RAM at runtime. At runtime, the system loads the .main_data section containing the initialized data to
RAM address 0x80000, but until runtime, this section remains in ROM. Listing 6.12
shows part of the corresponding LCF.
Listing 6.12 Partial LCF for ROM-to-RAM Copy
# ROM location: address 0x0
# RAM location: address 0x800000
# For clarity, no alignment directives in this listing
MEMORY {
TEXT (RX) : ORIGIN = 0x0, LENGTH = 0
DATA (RW) : ORIGIN = 0x800000, LENGTH = 0
}
SECTIONS{
.main :
{
*(.text)
*(.rodata)
} > TEXT
86 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 87 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
# Locate initialized data in ROM area at end of .main.
.main_data : AT( ADDR(.main) + SIZEOF(.main) )
{
*(.data)
*(.sdata)
*(.sbss)
} > DATA
.uninitialized_data:
{
*(SCOMMON)
*(.bss)
*(COMMON)
} >> DATA
For program execution to copy the section from ROM to RAM, a copy table such as
Listing 6.13 must supply the information that the program needs at runtime. This copy
table, which the symbol __S_romp identifies, contains a sequence of three word values per entry:
• ROM start address
• RAM start address
• size
The last entry in this table must be all zeros: this is the reason for the three lines
WRITEW(0) ;
before the table closing brace character.
Listing 6.13 LCF Copy Table for Runtime ROM Copy
# Locate ROM copy table into ROM after initialized data
_romp_at = _main_ROM + SIZEOF(.main_data);
.romp : AT (_romp_at)
{
__S_romp = _romp_at;
WRITEW(_main_ROM); #ROM start address
WRITEW(ADDR(.main_data)); #RAM start address
WRITEW(SIZEOF(.main_data)); #size
WRITEW(0);
WRITEW(0);
WRITEW(0);
}
}
__SP_INIT = . + 0x4000; # set stack to 16kb
__heap_addr = __SP_INIT; # heap grows opposite stack direction
__heap_size = 0x10000; # set heap to 64kb
# end SECTIONS segment
ColdFire Architectures v6.0 - Targeting Manual 87
CF.book Page 88 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
LCF Syntax
# end LCF
Writing Data Directly to Memory
To write data directly to memory, use appropriate WRITEx keywords in your LCF:
• WRITEB writes a byte
• WRITEH writes a two-byte halfword
• WRITEW writes a four-byte word.
The system inserts the data at the section’s current address. Listing 6.14 shows an
example.
Listing 6.14 Embedding Data Directly into Output
.example_data_section :
{
WRITEB 0x48; /* 'H' */
WRITEB 0x69; /* 'i' */
WRITEB 0x21; /* '!' */
To insert a complete binary file, use the INCLUDE keyword, as Listing 6.15 shows.
Listing 6.15 Embedding a Binary File into Output
_musicStart = .;
INCLUDE music.mid
_musicEnd = .;
} > DATA
You must include the binary file in your IDE project. Additionally, the File Mappings target settings panel must specify resource file for all files that have the same extension as
the binary file. Figure 6.1 shows how to make this type designation.
88 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 89 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
Figure 6.1 Marking a Binary File Type as a Resource File
Commands, Directives, and Keywords
The rest of this chapter consists of explanations of all valid LCF functions, keywords, directives, and commands, in alphabetic order.
Table 6.2 LCF Functions, Keywords, Directives, and Commands
ColdFire Architectures v6.0 - Targeting Manual 89
CF.book Page 90 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
.
(location counter)
Denotes the current output location.
Remarks
The period always refers to a location in a sections segment, so is valid only in a sections-section definition. Within such a definition, '.' may appear anywhere a symbol is valid.
Assigning a new, greater value to '.' causes the location counter to advance. But it is not possible to decrease the location-counter value, so it is not possible to assign a new, lesser value to '.' You can use this effect to create empty space in an output
section, as the Listing 6.16 example does.
Example
The code of Listing 6.16 moves the location counter to a position 0x10000 bytes
past the symbol __start.
Listing 6.16 Moving the Location Counter
..data :
{
*.(data)
*.(bss)
*.(COMMON)
__start = .;
. = __start + 0x10000;
__end = .;
} > DATA
ADDR
Returns the address of the named section or memory segment.
ADDR ( sectionName | segmentName)
Parameters
sectionName
Identifier for a file section.
90 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 91 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords segmentName
Identifier for a memory segment
Example
The code of Listing 6.17 uses the ADDR function to assign the address of ROOT to
the symbol __rootbasecode .
Listing 6.17 ADDR() Function
MEMORY{
ROOT (RWX) : ORIGIN = 0x80000400, LENGTH = 0
}
SECTIONS{
.code :
{
__rootbasecode = ADDR(ROOT);
*.(text);
} > ROOT
}
ALIGN
Returns the location-counter value, aligned on a specified boundary.
ALIGN(alignValue)
Parameter
alignValue
Alignment-boundary specifier; must be a power of two.
Remarks
The ALIGN function does not update the location counter; it only performs arithmetic. Updating the location counter requires an assignment such as:
. = ALIGN(0x10); #update location counter to
16-byte alignment
ColdFire Architectures v6.0 - Targeting Manual 91
CF.book Page 92 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
ALIGNALL
Forces minimum alignment for all objects in the current segment to the specified value.
ALIGNALL(alignValue);
Parameter
alignValue
Alignment-value specifier; must be a power of two.
Remarks
ALIGNALL
is the command version of the ALIGN function. It updates the location counter as each object is written to the output.
Example
Listing 6.18 is an example use for ALIGNALL() command.
Listing 6.18 ALIGNALL Example
.code :
{
ALIGNALL(16); // Align code on 16-byte boundary
* (.init)
* (.text)
ALIGNALL(64); //align data on 64-byte boundary
* (.rodata)
} > .text
EXCEPTION
Creates the exception table index in the output file.
EXCEPTION
Remarks
Only C++ code requires exception tables. To create an exception table, add the
EXCEPTION
command, with symbols __exception_table_start__ and
__exception_table_end__
, to the end of your code section segment, just as
Listing 6.19 shows. (At runtime, the system knows the values of the two symbols.)
92 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 93 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
Example
Listing 6.19 shows the code for creating an exception table.
Listing 6.19 Creating an Exception Table
__exception_table_start__ = .;
EXCEPTION
__exception_table_end__ = .;
EXPORTSTRTAB
Creates a string table from the names of exported symbols.
EXPORTSTRTAB
Remarks
Table 6.3 shows the structure of the export string table. As with an ELF string
table, the system zero-terminates the library and symbol names.
Table 6.3 Export String Table Structure
0x00 library name symbol1 name symbol 2 name
1 byte varies varies varies
Example
Listing 6.20 shows the code for creating an export string table.
Listing 6.20 Creating an Export String Table
.expstr:
{
EXPORTSTRTAB
} > EXPSTR
ColdFire Architectures v6.0 - Targeting Manual 93
CF.book Page 94 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
EXPORTSYMTAB
Creates a jump table of the exported symbols.
EXPORTSYMTAB
Remarks
Table 6.4 shows the structure of the export symbol table. The start of the export
symbol table must be aligned on at least a four-byte boundary.
Table 6.4 Export Symbol Table Structure
Size (in bytes) of export table
Index to library name in export string table
Index to symbol1 name in export string table
Address of symbol1
A5 value for symbol1
Index to symbol2 name in export string table
Address of symbolf2
A5 value for symbol2
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
Example
Listing 6.21 shows the code for creating an export symbol table.
Listing 6.21 Creating an Export Symbol Table
.expsym:
{
EXPORTSYMTAB
} > EXPSYM
94 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 95 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
FORCE_ACTIVE
Starts an optional LCF closure segment that specifies symbols the linker should not deadstrip.
FORCE_ACTIVE{ symbol[, symbol] }
Parameter
symbol
Any defined symbol.
IMPORTSTRTAB
Creates a string table from the names of imported symbols.
IMPORTSTRTAB
Remarks
Table 6.5 shows the structure of the import string table. As with an ELF string
table, the system zero-terminates the library and symbol names.
Table 6.5 Import String Table Structure
0x00 library name symbol1 name symbol 2 name
1 byte varies varies varies
Example
Listing 6.22 shows the code for creating an import string table.
Listing 6.22 Creating an Import String Table
.impstr:
{
IMPORTSTRTAB
} > IMPSTR
ColdFire Architectures v6.0 - Targeting Manual 95
CF.book Page 96 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
IMPORTSYMTAB
Creates a jump table of the imported symbols.
IMPORTSYMTAB
Remarks
Table 6.6 shows the structure of the import symbol table. The start of the import
symbol table must be aligned on at least a four-byte boundary.
Table 6.6 Import Symbol Table Structure
Size (in bytes) of import table
Index to library1 name in import string table
Number of entries in library1
Index to symbol1 name in import string table
Address of symbol1 vector in export string table
Index to symbol2 name in import string table
Address of symbol2 vector in export string table
Index to library2 name in import string table
Number of entries in library2
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
4 bytes
Example
Listing 6.23 shows the code for creating an import symbol table.
Listing 6.23 Creating an Import Symbol Table
.expsym:
{
IMPORTSYMTAB
} > EXPSYM
96 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 97 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
INCLUDE
Include a specified binary file in the output file.
INCLUDE filename
Parameter
filename
Name of a binary file in the project. The File Mappings target settings panel must specify resource file for all files that have the same extension as this file.
Remarks
For more information and an example, see the subsection Writing Data Directly to
KEEP_SECTION
Starts an optional LCF closure segment that specifies sections the linker should not deadstrip.
KEEP_SECTION{ sectionType[, sectionType] }
Parameter
sectionType
Identifier for any user-defined or predefined section.
MEMORY
Starts the LCF memory segment, which defines segments of target memory.
MEMORY { memory_spec[, memory_spec] }
Parameters
memory_spec segmentName (accessFlags) : ORIGIN = address,
LENGTH = length [> fileName]
ColdFire Architectures v6.0 - Targeting Manual 97
CF.book Page 98 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords segmentName
Name for a new segment of target memory. Consists of alphanumeric characters; can include the underscore character.
accessFlags
ELF-access permission flags — R = read, W = write, or X = execute.
address
A memory address, such as 0x80000400, or an AFTER command. The format of the AFTER command is AFTER (name[, name]); this command specifies placement of the new memory segment at the end of the named segments.
length
Size of the new memory segment: a value greater than zero. Optionally, the value zero for autolength, in which the linker allocates space for all the data and code of the segment. (Autolength cannot increase the amount of target memory, so the feature can lead to overflow.) fileName
Optional, binary-file destination. The linker writes the segment to this binary file on disk, instead of to an ELF program header. The linker puts this binary file in the same folder as the ELF output file. This option has two variants:
• > fileName: writes the segment to a new binary file.
• >> fileName: appends the segment to an existing binary file.
Remarks
The LCF contains only one MEMORY directive, but this directive can define as many memory segments as you wish.
For each memory segment, the ORIGIN keyword introduces the starting address, and the LENGTH keyword introduces the length value.
There is no overflow checking for the autolength feature. To prevent overflow, you should use the AFTER keyword to specify the segment’s starting address.
If an AFTER keyword has multiple parameter values, the linker uses the highest memory address.
For more information, see the subsection Memory Segment.
Example
Listing 6.24 is an example use of the MEMORY directive.
Listing 6.24 MEMORY Directive Example
MEMORY {
98 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 99 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
TEXT (RX) : ORIGIN = 0x00003000, LENGTH = 0
DATA (RW) : ORIGIN = AFTER(TEXT), LENGTH = 0
}
OBJECT
Sections-segment keyword that specifies a function. Multiple OBJECT keywords control the order of functions in the output file.
OBJECT ( function, sourcefile.c)
Parameters
function
Name of a function.
sourcefile.c
Name of the C file that contains the function.
Remarks
If an OBJECT keyword tells the linker to write an object to the output file, the linker does not write the same object again, in response to either the GROUP keyword or the '*' wildcard character.
REF_INCLUDE
Starts an optional LCF closure segment that specifies sections the linker should not deadstrip, if program code references the files that contain these sections.
REF_INCLUDE{ sectionType[, sectionType] }
Parameter
sectionType
Identifier for any user-defined or predefined section.
Remarks
Useful if you want to include version information from your source file components.
ColdFire Architectures v6.0 - Targeting Manual 99
CF.book Page 100 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
SECTIONS
Starts the LCF sections segment, which defines the contents of target-memory sections.
Also defines global symbols to be used in the output file.
SECTIONS { section_spec[, section_spec] }
Parameters
section_spec sectionName : [AT (loadAddress)] {contents}
> segmentName sectionName
Name for the output section, such as mysection. Must start with a period.
AT (loadAddress)
Optional specifier for the load address of the section. The default value is the relocation address.
contents
Statements that assign a value to a symbol or specify section placement, including
input sections. Subsections Arithmetic, Comment Operators, Specifying Files and
Functions, Alignment, and . (location counter) explain possible contents
statements. segmentName
Predefined memory-segment destination for the contents of the section. The two variants are:
• > segmentName: puts section contents at the beginning of memory segment segmentName
.
• >> segmentName: appends section contents to the end of memory segment segmentName
.
Remarks
For more information, see the subsection Sections Segment.
Example
Listing 6.25 is an example sections-segment definition.
Listing 6.25 SECTIONS Directive Example
SECTIONS {
100 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 101 Friday, July 8, 2005 8:59 AM
}
.text : {
_textSegmentStart = .; alpha.c (.text)
. = ALIGN (0x10); beta.c (.text)
_textSegmentEnd = .;
}
.data : { *(.data) }
.bss
: { *(.bss)
*(COMMON)
}
ELF Linker and Command Language
Commands, Directives, and Keywords
SIZEOF
Returns the size (in bytes) of the specified segment or section.
SIZEOF( segmentName | sectionName)
Parameters
segmentName
Name of a segment.
sectionName
Name of a section.
SIZEOF_ROM
Returns the size (in bytes) that a segment occupies in ROM.
SIZEOF_ROM ( segmentName)
Parameter
segmentName
Name of a ROM segment.
Remarks
Always returns the value 0 until the ROM is built. Accordingly, you should use
SIZEOF_ROM
only within an expression inside a WRITEB, WRITEH, WRITEW, or AT function.
ColdFire Architectures v6.0 - Targeting Manual 101
CF.book Page 102 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
Furthermore, you need SIZEOF_ROM only if you use the COMPRESS option on the memory segment. Without compression, there is no difference between the return values of SIZEOF_ROM and SIZEOF.
WRITEB
Inserts a byte of data at the current address of a section.
WRITEB ( expression);
Parameter
expression
Any expression that returns a value 0x00 to 0xFF.
WRITEH
Inserts a halfword of data at the current address of a section.
WRITEH ( expression);
Parameter
expression
Any expression that returns a value 0x0000 to 0xFFFF
WRITEW
Inserts a word of data at the current address of a section.
WRITEW ( expression);
Parameter
expression
Any expression that returns a value 0x00000000 to 0xFFFFFFFF.
102 ColdFire Architectures v6.0 - Targeting Manual
CF.book Page 103 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
WRITES0COMMENT
Inserts an S0 comment record into an S-record file.
WRITES0COMMENT " comment"
Parameter
comment
Comment text: a string of alphanumerical characters 0-9, A-Z, and a-z, plus space, underscore, and dash characters. Double quotes must enclose the comment string. (If you omit the closing double-quote character, the linker tries to put the entire LCF into the S0 comment.)
Remarks
This command, valid only in an LCF sections segment, creates an S0 record of the form:
S0aa0000bbbbbbbbbbbbbbbbdd
• aa — hexadecimal number of bytes that follow
• bb — ASCII equivalent of comment
• dd — the checksum
This command does not null-terminate the ASCII string.
Within a comment string, do not use these character sequences, which are reserved for LCF comments:
# /* */ //
Example
This example shows that multi-line S0 comments are valid:
WRITES0COMMENT "Line 1 comment
Line 2 comment"
ZERO_FILL_UNINITIALIZED
Forces the linker to put zeroed data into the binary file for uninitialized variables.
ZERO_FILL_UNINITIALIZED
ColdFire Architectures v6.0 - Targeting Manual 103
CF.book Page 104 Friday, July 8, 2005 8:59 AM
ELF Linker and Command Language
Commands, Directives, and Keywords
Remarks
This directive must be between directives MEMORY and SECTIONS; placing it anywhere else would be a syntax error.
Using linker configuration files and the define_section pragma, you can mix uninitialized and initialized data. As the linker does not normally write uninitialized data to the binary file, forcing explicit zeroing of uninitialized data can help with proper placement.
Example
The code of Listing 6.26 tells the linker to write uninitialized data to the binary
files as zeros.
Listing 6.26 ZERO_FILL_UNINITIALIZED Example
MEMORY {
TEXT (RX) :ORIGIN = 0x00030000, LENGTH = 0
DATA (RW) :ORIGIN = AFTER(TEXT), LENGTH = 0
}
ZERO_FILL_UNINITIALIZED
SECTIONS {
.main_application:
{
*(.text)
.=ALIGN(0x8);
*(.rodata)
.=ALIGN(0x8);
} > TEXT
...
}
104 ColdFire Architectures v6.0 - Targeting Manual
Stáhnout
Reklama