1 |
13 |
serginhofr |
/*======================================================================*/
|
2 |
|
|
/* Default maven linker script */
|
3 |
|
|
/*======================================================================*/
|
4 |
|
|
/* This is the default linker script for maven. It is based off of the
|
5 |
|
|
mips idt32.ld linker script. I have added many more comments and
|
6 |
|
|
tried to clean things up a bit. For more information about standard
|
7 |
|
|
MIPS sections see Section 9.5 of "See MIPS Run Linux" by Dominic
|
8 |
|
|
Sweetman. For more generic information about the init, fini, ctors,
|
9 |
|
|
and dtors sections see the paper titled "ELF From the Programmers
|
10 |
|
|
Perspective" by Hongiu Lu. */
|
11 |
|
|
|
12 |
|
|
/*----------------------------------------------------------------------*/
|
13 |
|
|
/* Setup */
|
14 |
|
|
/*----------------------------------------------------------------------*/
|
15 |
|
|
|
16 |
|
|
/* The OUTPUT_ARCH command specifies the machine architecture where the
|
17 |
|
|
argument is one of the names used in the BFD library. More
|
18 |
|
|
specifically one of the entires in bfd/cpu-mips.c */
|
19 |
|
|
|
20 |
|
|
OUTPUT_ARCH( "riscv" )
|
21 |
|
|
|
22 |
|
|
/* The ENTRY command specifies the entry point (ie. first instruction to
|
23 |
|
|
execute). The symbol _start is defined in crt0.S */
|
24 |
|
|
|
25 |
|
|
ENTRY( _start )
|
26 |
|
|
|
27 |
|
|
/* The GROUP command is special since the listed archives will be
|
28 |
|
|
searched repeatedly until there are no new undefined references. We
|
29 |
|
|
need this since -lc depends on -lgloss and -lgloss depends on -lc. I
|
30 |
|
|
thought gcc would automatically include -lgcc when needed, but
|
31 |
|
|
idt32.ld includes it explicitly here and I was seeing link errors
|
32 |
|
|
without it. */
|
33 |
|
|
|
34 |
|
|
GROUP( -lc -lgloss -lgcc )
|
35 |
|
|
|
36 |
|
|
/*----------------------------------------------------------------------*/
|
37 |
|
|
/* Sections */
|
38 |
|
|
/*----------------------------------------------------------------------*/
|
39 |
|
|
/* This is where we specify how the input sections map to output
|
40 |
|
|
sections. The .= commands set the location counter, and the
|
41 |
|
|
sections are inserted in increasing address order according to the
|
42 |
|
|
location counter. The following statement will take all of the .bar
|
43 |
|
|
input sections and reloate them into the .foo output section which
|
44 |
|
|
starts at address 0x1000.
|
45 |
|
|
|
46 |
|
|
. = 0.x1000;
|
47 |
|
|
.foo : { *(.bar) }
|
48 |
|
|
|
49 |
|
|
If we wrap an input specification with a KEEP command then it
|
50 |
|
|
prevents it from being eliminted during "link-time garbage
|
51 |
|
|
collection". I'm not sure what this is, so I just followed what was
|
52 |
|
|
done in idt32.ld.
|
53 |
|
|
|
54 |
|
|
We can also set a global external symbol to a specific address in the
|
55 |
|
|
output binary with this syntax:
|
56 |
|
|
|
57 |
|
|
_etext = .;
|
58 |
|
|
PROVIDE( etext = . );
|
59 |
|
|
|
60 |
|
|
This will set the global symbol _ftext to the current location. If we
|
61 |
|
|
wrap this in a PROVIDE commad, the symbol will only be set if it is
|
62 |
|
|
not defined. We do this with symbols which don't begin with an
|
63 |
|
|
underscore since technically in ansi C someone might have a function
|
64 |
|
|
with the same name (eg. etext).
|
65 |
|
|
|
66 |
|
|
If we need to label the beginning of a section we need to make sure
|
67 |
|
|
that the linker doesn't insert an orphan section inbetween where we
|
68 |
|
|
set the symbol and the actual begining of the section. We can do that
|
69 |
|
|
by assigning the location dot to itself.
|
70 |
|
|
|
71 |
|
|
. = .
|
72 |
|
|
_ftext = .;
|
73 |
|
|
.text :
|
74 |
|
|
{ }
|
75 |
|
|
|
76 |
|
|
*/
|
77 |
|
|
|
78 |
|
|
SECTIONS
|
79 |
|
|
{
|
80 |
|
|
|
81 |
|
|
/*--------------------------------------------------------------------*/
|
82 |
|
|
/* Code and read-only segment */
|
83 |
|
|
/*--------------------------------------------------------------------*/
|
84 |
|
|
|
85 |
|
|
/* Begining of code and text segment */
|
86 |
|
|
. = 0x00010000;
|
87 |
|
|
_ftext = .;
|
88 |
|
|
PROVIDE( eprol = . );
|
89 |
|
|
|
90 |
|
|
/* text: Program code section */
|
91 |
|
|
.text :
|
92 |
|
|
{
|
93 |
|
|
*(.text)
|
94 |
|
|
*(.text.*)
|
95 |
|
|
*(.gnu.linkonce.t.*)
|
96 |
|
|
}
|
97 |
|
|
|
98 |
|
|
/* init: Code to execute before main (called by crt0.S) */
|
99 |
|
|
.init :
|
100 |
|
|
{
|
101 |
|
|
KEEP( *(.init) )
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
/* fini: Code to execute after main (called by crt0.S) */
|
105 |
|
|
.fini :
|
106 |
|
|
{
|
107 |
|
|
KEEP( *(.fini) )
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
/* rodata: Read-only data */
|
111 |
|
|
.rodata :
|
112 |
|
|
{
|
113 |
|
|
*(.rdata)
|
114 |
|
|
*(.rodata)
|
115 |
|
|
*(.rodata.*)
|
116 |
|
|
*(.gnu.linkonce.r.*)
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
/* End of code and read-only segment */
|
120 |
|
|
PROVIDE( etext = . );
|
121 |
|
|
_etext = .;
|
122 |
|
|
|
123 |
|
|
/*--------------------------------------------------------------------*/
|
124 |
|
|
/* Global constructor/destructor segement */
|
125 |
|
|
/*--------------------------------------------------------------------*/
|
126 |
|
|
|
127 |
|
|
.preinit_array :
|
128 |
|
|
{
|
129 |
|
|
PROVIDE_HIDDEN (__preinit_array_start = .);
|
130 |
|
|
KEEP (*(.preinit_array))
|
131 |
|
|
PROVIDE_HIDDEN (__preinit_array_end = .);
|
132 |
|
|
}
|
133 |
|
|
|
134 |
|
|
.init_array :
|
135 |
|
|
{
|
136 |
|
|
PROVIDE_HIDDEN (__init_array_start = .);
|
137 |
|
|
KEEP (*(SORT(.init_array.*)))
|
138 |
|
|
KEEP (*(.init_array ))
|
139 |
|
|
PROVIDE_HIDDEN (__init_array_end = .);
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
.fini_array :
|
143 |
|
|
{
|
144 |
|
|
PROVIDE_HIDDEN (__fini_array_start = .);
|
145 |
|
|
KEEP (*(SORT(.fini_array.*)))
|
146 |
|
|
KEEP (*(.fini_array ))
|
147 |
|
|
PROVIDE_HIDDEN (__fini_array_end = .);
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
/*--------------------------------------------------------------------*/
|
151 |
|
|
/* Other misc gcc segments (this was in idt32.ld) */
|
152 |
|
|
/*--------------------------------------------------------------------*/
|
153 |
|
|
/* I am not quite sure about these sections but it seems they are for
|
154 |
|
|
C++ exception handling. I think .jcr is for "Java Class
|
155 |
|
|
Registration" but it seems to end up in C++ binaries as well. */
|
156 |
|
|
|
157 |
|
|
.eh_frame_hdr : { *(.eh_frame_hdr) }
|
158 |
|
|
.eh_frame : { KEEP( *(.eh_frame) ) }
|
159 |
|
|
.gcc_except_table : { *(.gcc_except_table) }
|
160 |
|
|
.jcr : { KEEP (*(.jcr)) }
|
161 |
|
|
|
162 |
|
|
/*--------------------------------------------------------------------*/
|
163 |
|
|
/* Initialized data segment */
|
164 |
|
|
/*--------------------------------------------------------------------*/
|
165 |
|
|
|
166 |
|
|
/* Start of initialized data segment */
|
167 |
|
|
. = ALIGN(16);
|
168 |
|
|
_fdata = .;
|
169 |
|
|
|
170 |
|
|
/* data: Writable data */
|
171 |
|
|
.data :
|
172 |
|
|
{
|
173 |
|
|
*(.data)
|
174 |
|
|
*(.data.*)
|
175 |
|
|
*(.gnu.linkonce.d.*)
|
176 |
|
|
}
|
177 |
|
|
|
178 |
|
|
/* End of initialized data segment */
|
179 |
|
|
PROVIDE( edata = . );
|
180 |
|
|
_edata = .;
|
181 |
|
|
|
182 |
|
|
/* Have _gp point to middle of sdata/sbss to maximize displacement range */
|
183 |
|
|
. = ALIGN(16);
|
184 |
|
|
_gp = . + 0x800;
|
185 |
|
|
|
186 |
|
|
/* Writable small data segment */
|
187 |
|
|
.sdata :
|
188 |
|
|
{
|
189 |
|
|
*(.sdata)
|
190 |
|
|
*(.sdata.*)
|
191 |
|
|
*(.srodata.*)
|
192 |
|
|
*(.gnu.linkonce.s.*)
|
193 |
|
|
}
|
194 |
|
|
|
195 |
|
|
/*--------------------------------------------------------------------*/
|
196 |
|
|
/* Uninitialized data segment */
|
197 |
|
|
/*--------------------------------------------------------------------*/
|
198 |
|
|
|
199 |
|
|
/* Start of uninitialized data segment */
|
200 |
|
|
. = ALIGN(8);
|
201 |
|
|
_fbss = .;
|
202 |
|
|
|
203 |
|
|
/* Writable uninitialized small data segment */
|
204 |
|
|
.sbss :
|
205 |
|
|
{
|
206 |
|
|
*(.sbss)
|
207 |
|
|
*(.sbss.*)
|
208 |
|
|
*(.gnu.linkonce.sb.*)
|
209 |
|
|
}
|
210 |
|
|
|
211 |
|
|
/* bss: Uninitialized writeable data section */
|
212 |
|
|
. = .;
|
213 |
|
|
_bss_start = .;
|
214 |
|
|
.bss :
|
215 |
|
|
{
|
216 |
|
|
*(.bss)
|
217 |
|
|
*(.bss.*)
|
218 |
|
|
*(.gnu.linkonce.b.*)
|
219 |
|
|
*(COMMON)
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
/* End of uninitialized data segment (used by syscalls.c for heap) */
|
223 |
|
|
PROVIDE( end = . );
|
224 |
|
|
_end = ALIGN(8);
|
225 |
|
|
}
|