The following is an example of a linker script for an m68k-based target board.
STARTUP(crt0.o)The m68k-coff configuration default does not link in crt0.o because it assumes that a developer has crt0. This behavior is controlled in the config file for each architecture in a macro called STARTFILE_SPEC. If STARTFILE_SPEC is set to NULL, gcc formats its command line and doesnt add crt0.o. Any filename can be specified with STARTUP although the default is always crt0.o.
If you use only ld to link, you control whether or not to link in crt0.o on the command line.
If you have multiple crt0
files, you can leave STARTUP
out, and link in crt0.o
in the makefile or use different linker scripts. Sometimes this option
is used to initialize floating point values or to add device support.
2.
Using GROUP,
load the specified file.
GROUP(-lgcc-liop-lc)In this case, the file is a relocated library that contains the definitions for the low-level functions needed by libc.a. The file to load could have also been specified on the command line, but as its always needed, it might as well be here as a default.
3.
SEARCH_DIR
specifies the path in which to look for files.
SEARCH_DIR(.)4.
__DYNAMIC = 0;5.
6.
Specify a name for a section
that can be referred to later in the script. In the following examples
case, its only a pointer to the beginning of free RAM space with an upper
limit at 2M. If the output file exceeds the upper limit, MEMORY
produces an error message. First, in this case, well set up the memory
map of the boards stack for high memory for both the rom68k
and mon68k
monitors.
MEMORY
{
ram : ORIGIN = 0x10000, LENGTH = 2M
}
SECTIONS
{
.text :
{
CREATE_OBJECT_SYMBOLS
*(.text)
etext = .;
__CTOR_LIST__ = .;
LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2)
*(.ctors)
LONG(0)
__CTOR_END__ = .;
__DTOR_LIST__ = .;
LONG((__DTOR_END__ - __DTOR_LIST__) / 4 - 2)
*(.dtors)
LONG(0)
__DTOR_END__ = .;
*(.lit)
*(.shdata) }
> ram
.shbss SIZEOF(.text) + ADDR(.text) : {
*(.shbss)
}
In a coff
file, all the actual instructions reside in .text
for also setting up the constructor and destructor tables for G++. Notice
that the section description redirects itself to the RAM variable that
was set up earlier.
2.
Set up the .data
section.
.talias : { } > ram
.data : {
*(.data)
CONSTRUCTORS
_edata = .;
} > ram
In a coff
file, this is where all of the initialized data goes. CONSTRUCTORS
is a special command used by ld.
.bss SIZEOF(.data) + ADDR(.data) :
{
__bss_start = ALIGN(0x8);
*(.bss)
*(COMMON)
end = ALIGN(0x8);
_end = ALIGN(0x8);
__end = ALIGN(0x8);
}
.mstack : { } > ram
.rstack : { } > ram
.stab . (NOLOAD) :
{
[ .stab ]
}
.stabstr . (NOLOAD) :
{
[ .stabstr ]
}
}
In a coff
file, this is where uninitialized data goes. The default values for _bss_start
and _end
are set here for use by the crt0
file when it zeros the .bss
section.
|
© 2005 Red Hat, Inc. All rights reserved. About Red Hat : Legal statement : Privacy statement : Contact |