1# Linker Script for National Semiconductor's CRX-ELF32.
2#
3# Copyright (C) 2014-2021 Free Software Foundation, Inc.
4#
5# Copying and distribution of this file, with or without modification,
6# are permitted in any medium without royalty provided the copyright
7# notice and this notice are preserved.
8
9# Using an empty script for ld -r is better than mashing together
10# sections.  This hack likely leaves ld -Ur broken.
11test -n "${RELOCATING}" || exit 0
12
13# The next line should be uncommented if it is desired to link
14# without libstart.o and directly enter main.
15
16# ENTRY=_main
17
18test -z "$ENTRY" && ENTRY=_start
19cat <<EOF
20
21/* Example Linker Script for linking NS CRX elf32 files.
22
23   Copyright (C) 2014-2021 Free Software Foundation, Inc.
24
25   Copying and distribution of this script, with or without modification,
26   are permitted in any medium without royalty provided the copyright
27   notice and this notice are preserved.  */
28
29
30OUTPUT_FORMAT("${OUTPUT_FORMAT}")
31OUTPUT_ARCH(${ARCH})
32${RELOCATING+ENTRY(${ENTRY})}
33
34/* Define memory regions.  */
35MEMORY
36{
37	rom	    : ORIGIN = 0x2,	    LENGTH = 3M
38	ram	    : ORIGIN = 4M,	    LENGTH = 10M
39}
40
41/*  Many sections come in three flavours.  There is the 'real' section,
42    like ".data".  Then there are the per-procedure or per-variable
43    sections, generated by -ffunction-sections and -fdata-sections in GCC,
44    and useful for --gc-sections, which for a variable "foo" might be
45    ".data.foo".  Then there are the linkonce sections, for which the linker
46    eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
47    The exact correspondences are:
48
49    Section	Linkonce section
50    .text	.gnu.linkonce.t.foo
51    .rdata	.gnu.linkonce.r.foo
52    .data	.gnu.linkonce.d.foo
53    .bss	.gnu.linkonce.b.foo
54    .debug_info	.gnu.linkonce.wi.foo  */
55
56SECTIONS
57{
58  .init :
59  {
60    __INIT_START = .;
61    KEEP (*(SORT_NONE(.init)))
62    __INIT_END = .;
63  } > rom
64
65  .fini :
66  {
67    __FINI_START = .;
68    KEEP (*(SORT_NONE(.fini)))
69    __FINI_END = .;
70  } > rom
71
72  .jcr :
73  {
74    KEEP (*(.jcr))
75  } > rom
76
77  .text :
78  {
79    __TEXT_START = .;
80    *(.text) *(.text.*) *(.gnu.linkonce.t.*)
81    __TEXT_END = .;
82  } > rom
83
84  .rdata :
85  {
86    __RDATA_START = .;
87    *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata.*)
88    __RDATA_END = .;
89  } > rom
90
91  .ctor ALIGN(4) :
92  {
93    __CTOR_START = .;
94    /* The compiler uses crtbegin.o to find the start
95       of the constructors, so we make sure it is
96       first.  Because this is a wildcard, it
97       doesn't matter if the user does not
98       actually link against crtbegin.o; the
99       linker won't look for a file to match a
100       wildcard.  The wildcard also means that it
101       doesn't matter which directory crtbegin.o
102       is in.  */
103
104    KEEP (*crtbegin.o(.ctors))
105    KEEP (*crtbegin?.o(.ctors))
106
107    /* We don't want to include the .ctor section from
108       the crtend.o file until after the sorted ctors.
109       The .ctor section from the crtend file contains the
110       end of ctors marker and it must be last */
111
112    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o) .ctors))
113    KEEP (*(SORT(.ctors.*)))
114    KEEP (*(.ctors))
115    __CTOR_END = .;
116  } > rom
117
118  .dtor ALIGN(4) :
119  {
120    __DTOR_START = .;
121    KEEP (*crtbegin.o(.dtors))
122    KEEP (*crtbegin?.o(.dtors))
123    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o) .dtors))
124    KEEP (*(SORT(.dtors.*)))
125    KEEP (*(.dtors))
126    __DTOR_END = .;
127  } > rom
128
129  .data :
130  {
131    __DATA_START = .;
132    *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*)
133    __DATA_END = .;
134  } > ram AT > rom
135
136  .bss (NOLOAD) :
137  {
138    __BSS_START = .;
139    *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*)
140    __BSS_END = .;
141  } > ram
142
143/* You may change the sizes of the following sections to fit the actual
144   size your program requires.
145
146   The heap and stack are aligned to the bus width, as a speed optimization
147   for accessing data located there.  */
148
149  .heap (NOLOAD) :
150  {
151    . = ALIGN(4);
152    __HEAP_START = .;
153    . += 0x2000; __HEAP_MAX = .;
154  } > ram
155
156  .stack (NOLOAD) :
157  {
158    . = ALIGN(4);
159    . += 0x6000;
160    __STACK_START = .;
161  } > ram
162
163  .istack (NOLOAD) :
164  {
165    . = ALIGN(4);
166    . += 0x100;
167    __ISTACK_START = .;
168  } > ram
169
170  .comment        0 : { *(.comment) }
171
172EOF
173
174. $srcdir/scripttempl/DWARF.sc
175
176cat <<EOF
177}
178
179__DATA_IMAGE_START = LOADADDR(.data);
180EOF
181