10.12. Linker Example¶
This example links three object files named demo.c.o, ctrl.c.o, and tables.c.o and creates a program called demo.out.
Assume that target memory has the following program memory configuration:
Address Range |
Contents |
---|---|
0x00000000 to 0x00001000 |
SLOW_MEM |
0x00001000 to 0x00002000 |
FAST_MEM |
0x08000000 to 0x08000400 |
EEPROM |
The output sections are constructed in the following manner:
Executable code, contained in the .text sections of demo.c.o, ctrl.c.o, and tables.c.o, must be linked into FAST_MEM.
A set of interrupt vectors, contained in the .intvecs section of tables.c.o, must be linked at address FAST_MEM.
A table of coefficients, contained in the .data section of tables.c.o, must be linked into EEPROM. The remainder of block FLASH must be initialized to the value 0xFF00FF00.
A set of variables, contained in the .bss section of ctrl.c.o, must be linked into SLOW_MEM and preinitialized to 0x00000100.
The .bss sections of demo.c.o and tables.c.o must be linked into SLOW_MEM.
The following example shows the linker command file for this example. After the linker command file, the map file is shown.
/*****************************************************************************/
/*** Specify Link Options ***/
/*****************************************************************************/
--entry_point SETUP /* Define the program entry point */
--output_file=demo.out /* Name the output file */
--map_file=demo.map /* Create an output map file */
/*****************************************************************************/
/*** Specify the Input Files ***/
/*****************************************************************************/
demo.c.o
ctrl.c.o
tables.c.o
/*****************************************************************************/
/*** Specify the Memory Configurations ***/
/*****************************************************************************/
MEMORY
{
FAST_MEM : org = 0x00000000 len = 0x00001000 /* PROGRAM MEMORY (ROM) */
SLOW_MEM : org = 0x00001000 len = 0x00001000 /* DATA MEMORY (RAM) */
EEPROM : org = 0x08000000 len = 0x00000400 /* COEFFICIENTS (EEPROM) */
}
/*****************************************************************************/
/* Specify the Output Sections */
/*****************************************************************************/
SECTIONS
{
.text : {} > FAST_MEM /* Link all .text sections into ROM */
.intvecs : {} > 0x0 /* Link interrupt vectors at 0x0 */
.data : /* Link .data sections */
{
tables.c.o(.data)
. = 0x400; /* Create hole at end of block */
} > EEPROM, fill = 0xFF00FF00 /* Fill and link into EEPROM */
ctrl_vars: /* Create new sections for ctrl variables */
{
ctrl.c.o(.bss)
} > SLOW_MEM, fill = 0x00000100 /* Fill with 0x100 and link into RAM */
.bss : {} > SLOW_MEM /* Link remaining .bss sections into RAM */
}
/*****************************************************************************/
/*** End of Command File ***/
/*****************************************************************************/
Invoke the linker by entering the following command:
tiarmclang demo.cmd
This creates the following map file and an output file called demo.out that can be run on an Arm device.
OUTPUT FILE NAME: <demo.out>
ENTRY POINT SYMBOL: "SETUP" address: 000000d4
MEMORY CONFIGURATION
name origin length attributes fill
-------- -------- --------- ---------- --------
FAST_MEM 00000000 000001000 RWIX
SLOW_MEM 00001000 000001000 RWIX
EEPROM 08000000 000000400 RWIX
SECTION ALLOCATION MAP
output attributes/
section page origin length input sections
-------- ---- ---------- ---------- ----------------
.text 0 00000020 00000138
00000020 000000a0 ctrl.c.o (.text)
000000c0 00000000 tables.c.o (.text)
000000c0 00000098 demo.c.o (.text)
.intvecs 0 00000000 00000020
00000000 00000020 tables.c.o (.intvecs)
.data 0 08000000 00000400
08000000 00000168 tables.c.o (.data)
08000168 00000298 --HOLE-- [fill = ff00ff00]
08000400 00000000 ctrl.c.o (.data)
08000400 00000000 demo.c.o (.data)
ctrl_var 0 00001000 00000500
00001000 00000500 ctrl.c.o (.bss) [fill = 00000100]
.bss 0 00001500 00000100 UNINITIALIZED
00001500 00000100 demo.c.o (.bss)
00001600 00000000 tables.c.o (.bss)
GLOBAL SYMBOLS
address name address name
-------- ---- -------- ----
000000d4 SETUP 00000020 clear
00000020 clear 000000b8 set
000000b8 set 000000c0 x42
000000c0 x42 000000d4 SETUP
[4 symbols]