1214571Sdim# Linker Script for National Semiconductor's CR16-ELF32.
2214571Sdim
3214571Sdim# The next line should be uncommented if it is desired to link
4214571Sdim# without libstart.o and directly enter main.
5214571Sdim
6214571Sdim# ENTRY=_main
7214571Sdim
8214571Sdimtest -z "$ENTRY" && ENTRY=_start
9214571Sdimcat <<EOF
10214571Sdim
11214571Sdim/* Example Linker Script for linking NS CR16 elf32 files. */
12214571Sdim
13214571Sdim/* The next line forces the entry point (${ENTRY} in this script)
14214571Sdim   to be entered in the output file as an undefined symbol.
15214571Sdim   It is needed in case the entry point is not called explicitly
16214571Sdim   (which is the usual case) AND is in an archive.  */
17214571Sdim
18214571SdimOUTPUT_FORMAT("${OUTPUT_FORMAT}")
19214571SdimOUTPUT_ARCH(${ARCH})
20214571SdimEXTERN(${ENTRY})
21214571SdimENTRY(${ENTRY})
22214571Sdim
23214571Sdim/* Define memory regions.  */
24214571SdimMEMORY
25214571Sdim{
26214571Sdim        rom         : ORIGIN = 0x2,         LENGTH = 3M
27214571Sdim        ram         : ORIGIN = 4M,          LENGTH = 10M
28214571Sdim}
29214571Sdim
30214571Sdim/*  Many sections come in three flavours.  There is the 'real' section,
31214571Sdim    like ".data".  Then there are the per-procedure or per-variable
32214571Sdim    sections, generated by -ffunction-sections and -fdata-sections in GCC,
33214571Sdim    and useful for --gc-sections, which for a variable "foo" might be
34214571Sdim    ".data.foo".  Then there are the linkonce sections, for which the linker
35214571Sdim    eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
36214571Sdim    The exact correspondences are:
37214571Sdim
38214571Sdim    Section	Linkonce section
39214571Sdim    .text	.gnu.linkonce.t.foo
40214571Sdim    .rdata	.gnu.linkonce.r.foo
41214571Sdim    .data	.gnu.linkonce.d.foo
42214571Sdim    .bss	.gnu.linkonce.b.foo
43214571Sdim    .debug_info	.gnu.linkonce.wi.foo  */
44214571Sdim
45214571SdimSECTIONS
46214571Sdim{
47214571Sdim  .init :
48214571Sdim  { 
49214571Sdim    __INIT_START = .; 
50214571Sdim    KEEP (*(.init))
51214571Sdim    __INIT_END = .; 
52214571Sdim  } > rom
53214571Sdim
54214571Sdim  .fini :
55214571Sdim  { 
56214571Sdim    __FINI_START = .; 
57214571Sdim    KEEP (*(.fini))
58214571Sdim    __FINI_END = .; 
59214571Sdim  } > rom
60214571Sdim
61214571Sdim  .jcr :
62214571Sdim  { 
63214571Sdim    KEEP (*(.jcr))
64214571Sdim  } > rom
65214571Sdim
66214571Sdim  .text : 
67214571Sdim  {
68214571Sdim    __TEXT_START = .;
69214571Sdim    *(.text) *(.text.*) *(.gnu.linkonce.t.*)
70214571Sdim    __TEXT_END = .;
71214571Sdim  } > rom
72214571Sdim
73214571Sdim  .rdata :
74214571Sdim  {
75214571Sdim    __RDATA_START = .;
76214571Sdim    *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata*)
77214571Sdim    __RDATA_END = .;
78214571Sdim  } > rom
79214571Sdim
80214571Sdim  .ctor ALIGN(4) : 
81214571Sdim  { 
82214571Sdim    __CTOR_START = .; 
83214571Sdim    /* The compiler uses crtbegin.o to find the start
84214571Sdim       of the constructors, so we make sure it is
85214571Sdim       first.  Because this is a wildcard, it
86214571Sdim       doesn't matter if the user does not
87214571Sdim       actually link against crtbegin.o; the
88214571Sdim       linker won't look for a file to match a
89214571Sdim       wildcard.  The wildcard also means that it
90214571Sdim       doesn't matter which directory crtbegin.o
91214571Sdim       is in.  */
92214571Sdim
93214571Sdim    KEEP (*crtbegin*.o(.ctors))
94214571Sdim
95214571Sdim    /* We don't want to include the .ctor section from
96214571Sdim       the crtend.o file until after the sorted ctors.
97214571Sdim       The .ctor section from the crtend file contains the
98214571Sdim       end of ctors marker and it must be last */
99214571Sdim
100214571Sdim    KEEP (*(EXCLUDE_FILE (*crtend*.o) .ctors))
101214571Sdim    KEEP (*(SORT(.ctors.*)))
102214571Sdim    KEEP (*(.ctors))
103214571Sdim    __CTOR_END = .; 
104214571Sdim  } > rom
105214571Sdim
106214571Sdim  .dtor ALIGN(4) : 
107214571Sdim  { 
108214571Sdim    __DTOR_START = .; 
109214571Sdim    KEEP (*crtbegin*.o(.dtors))
110214571Sdim    KEEP (*(EXCLUDE_FILE (*crtend*.o) .dtors))
111214571Sdim    KEEP (*(SORT(.dtors.*)))
112214571Sdim    KEEP (*(.dtors))
113214571Sdim    __DTOR_END = .; 
114214571Sdim  } > rom
115214571Sdim
116214571Sdim  .data :
117214571Sdim  {
118214571Sdim    __DATA_START = .;
119214571Sdim    *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*)
120214571Sdim    __DATA_END = .;
121214571Sdim  } > ram AT > rom
122214571Sdim
123214571Sdim  .bss (NOLOAD) :
124214571Sdim  {
125214571Sdim    __BSS_START = .;
126214571Sdim    *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*)
127214571Sdim    __BSS_END = .;
128214571Sdim  } > ram
129214571Sdim
130214571Sdim/* You may change the sizes of the following sections to fit the actual
131214571Sdim   size your program requires.
132214571Sdim
133214571Sdim   The heap and stack are aligned to the bus width, as a speed optimization
134214571Sdim   for accessing data located there.  */
135214571Sdim
136214571Sdim  .heap :
137214571Sdim  {
138214571Sdim    . = ALIGN(4);
139214571Sdim    __HEAP_START = .;
140214571Sdim    . += 0x2000; __HEAP_MAX = .;
141214571Sdim  } > ram
142214571Sdim
143214571Sdim  .stack :
144214571Sdim  {
145214571Sdim    . = ALIGN(4);
146214571Sdim    . += 0x6000;
147214571Sdim    __STACK_START = .;
148214571Sdim  } > ram
149214571Sdim
150214571Sdim  .istack :
151214571Sdim  {
152214571Sdim    . = ALIGN(4);
153214571Sdim    . += 0x100;
154214571Sdim    __ISTACK_START = .;
155214571Sdim  } > ram
156214571Sdim
157214571Sdim  .comment        0 : { *(.comment) }
158214571Sdim
159214571Sdim  /* DWARF debug sections.
160214571Sdim     Symbols in the DWARF debugging sections are relative to the beginning
161214571Sdim     of the section so we begin them at 0.  */
162214571Sdim
163214571Sdim  .debug_aranges  0 : { *(.debug_aranges) }
164214571Sdim  .debug_pubnames 0 : { *(.debug_pubnames) }
165214571Sdim  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
166214571Sdim  .debug_abbrev   0 : { *(.debug_abbrev) }
167214571Sdim  .debug_line     0 : { *(.debug_line) }
168214571Sdim  .debug_frame    0 : { *(.debug_frame) }
169214571Sdim  .debug_str      0 : { *(.debug_str) }
170214571Sdim  .debug_loc      0 : { *(.debug_loc) }
171214571Sdim  .debug_macinfo  0 : { *(.debug_macinfo) }
172214571Sdim}
173214571Sdim
174214571Sdim__DATA_IMAGE_START = LOADADDR(.data);
175214571SdimEOF
176