/usr/cygnus/hosttype/targettype/lib/ldscripts/
In
that directory, there will be files with the .x,
.xbn, .xn,
.xr, .xs,
and .xu extensions.
The linker script accomplishes the following processes to result.
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 doesn’t 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 it’s 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
to which you can refer later in the script. In the following example’s
case, it’s 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, we set up the memory map
of the board’s 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 = .; } > ramIn 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.