ChangeLog rotatation and copyright year update
[deliverable/binutils-gdb.git] / ld / emultempl / avrelf.em
CommitLineData
28c9d252 1# This shell script emits a C file. -*- C -*-
b90efa5b 2# Copyright (C) 2006-2015 Free Software Foundation, Inc.
28c9d252 3#
f96b4a7b 4# This file is part of the GNU Binutils.
28c9d252
NC
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
f96b4a7b 8# the Free Software Foundation; either version 3 of the License, or
28c9d252
NC
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
f96b4a7b
NC
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
28c9d252 20
f96b4a7b
NC
21
22# This file is sourced from elf32.em, and defines extra avr-elf specific
23# routines. It is used to generate the trampolines for the avr6 family
24# of devices where one needs to address the issue that it is not possible
28c9d252
NC
25# to reach the whole program memory by using 16 bit pointers.
26
92b93329 27fragment <<EOF
28c9d252
NC
28
29#include "elf32-avr.h"
30#include "ldctor.h"
9d7b48dc 31#include "elf/avr.h"
28c9d252 32
92b93329 33/* The fake file and it's corresponding section meant to hold
28c9d252
NC
34 the linker stubs if needed. */
35
36static lang_input_statement_type *stub_file;
37static asection *avr_stub_section;
38
39/* Variables set by the command-line parameters and transfered
40 to the bfd without use of global shared variables. */
41
42static bfd_boolean avr_no_stubs = FALSE;
43static bfd_boolean avr_debug_relax = FALSE;
44static bfd_boolean avr_debug_stubs = FALSE;
45static bfd_boolean avr_replace_call_ret_sequences = TRUE;
46static bfd_vma avr_pc_wrap_around = 0x10000000;
47
48/* Transfers information to the bfd frontend. */
49
50static void
51avr_elf_set_global_bfd_parameters (void)
52{
53 elf32_avr_setup_params (& link_info,
54 stub_file->the_bfd,
55 avr_stub_section,
56 avr_no_stubs,
57 avr_debug_stubs,
58 avr_debug_relax,
59 avr_pc_wrap_around,
60 avr_replace_call_ret_sequences);
61}
62
63
64/* Makes a conservative estimate of the trampoline section size that could
65 be corrected later on. */
66
67static void
68avr_elf_${EMULATION_NAME}_before_allocation (void)
69{
70 int ret;
71
72 gld${EMULATION_NAME}_before_allocation ();
73
8cc66334 74 /* We only need stubs for avr6, avrxmega6, and avrxmega7. */
e4492aa0 75 if (strcmp ("${EMULATION_NAME}","avr6")
8cc66334
EW
76 && strcmp ("${EMULATION_NAME}","avrxmega6")
77 && strcmp ("${EMULATION_NAME}","avrxmega7") )
28c9d252
NC
78 avr_no_stubs = TRUE;
79
80 avr_elf_set_global_bfd_parameters ();
81
82 /* If generating a relocatable output file, then
83 we don't have to generate the trampolines. */
84 if (link_info.relocatable)
85 avr_no_stubs = TRUE;
86
87 if (avr_no_stubs)
88 return;
89
f13a99db 90 ret = elf32_avr_setup_section_lists (link_info.output_bfd, &link_info);
28c9d252
NC
91
92 if (ret < 0)
93 einfo ("%X%P: can not setup the input section list: %E\n");
94
95 if (ret <= 0)
96 return;
97
98 /* Call into the BFD backend to do the real "stub"-work. */
f13a99db 99 if (! elf32_avr_size_stubs (link_info.output_bfd, &link_info, TRUE))
28c9d252
NC
100 einfo ("%X%P: can not size stub section: %E\n");
101}
102
103/* This is called before the input files are opened. We create a new
104 fake input file to hold the stub section and generate the section itself. */
105
106static void
107avr_elf_create_output_section_statements (void)
108{
109 flagword flags;
110
111 stub_file = lang_add_input_file ("linker stubs",
112 lang_input_file_is_fake_enum,
113 NULL);
114
f13a99db 115 stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
28c9d252
NC
116 if (stub_file->the_bfd == NULL
117 || !bfd_set_arch_mach (stub_file->the_bfd,
f13a99db
AM
118 bfd_get_arch (link_info.output_bfd),
119 bfd_get_mach (link_info.output_bfd)))
28c9d252
NC
120 {
121 einfo ("%X%P: can not create stub BFD %E\n");
122 return;
123 }
124
125 /* Now we add the stub section. */
126
28c9d252
NC
127 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
128 | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
9795b468
AM
129 avr_stub_section = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
130 ".trampolines",
131 flags);
132 if (avr_stub_section == NULL)
28c9d252
NC
133 goto err_ret;
134
135 avr_stub_section->alignment_power = 1;
92b93329 136
28c9d252
NC
137 ldlang_add_file (stub_file);
138
139 return;
140
141 err_ret:
142 einfo ("%X%P: can not make stub section: %E\n");
143 return;
144}
145
146/* Re-calculates the size of the stubs so that we won't waste space. */
147
148static void
eaeb0a9d 149avr_elf_after_allocation (void)
92b93329 150{
28d5f677 151 if (!avr_no_stubs && ! RELAXATION_ENABLED)
28c9d252 152 {
eaeb0a9d
AM
153 /* If relaxing, elf32_avr_size_stubs will be called from
154 elf32_avr_relax_section. */
43315eb7 155 if (!elf32_avr_size_stubs (link_info.output_bfd, &link_info, TRUE))
eaeb0a9d 156 einfo ("%X%P: can not size stub section: %E\n");
28c9d252
NC
157 }
158
eaeb0a9d
AM
159 gld${EMULATION_NAME}_after_allocation ();
160
161 /* Now build the linker stubs. */
162 if (!avr_no_stubs)
163 {
164 if (!elf32_avr_build_stubs (&link_info))
165 einfo ("%X%P: can not build stubs: %E\n");
166 }
28c9d252
NC
167}
168
4d4ef6fd
AM
169static void
170avr_elf_before_parse (void)
171{
172 /* Don't create a demand-paged executable, since this feature isn't
173 meaningful in AVR. */
174 config.magic_demand_paged = FALSE;
175
176 gld${EMULATION_NAME}_before_parse ();
177}
28c9d252 178
9d7b48dc
AB
179static void
180avr_finish (void)
181{
182 bfd *abfd;
183 bfd_boolean avr_link_relax;
184
185 if (link_info.relocatable)
186 {
187 avr_link_relax = TRUE;
188 for (abfd = link_info.input_bfds; abfd != NULL; abfd = abfd->link.next)
189 {
190 /* Don't let the linker stubs prevent the final object being
191 marked as link-relax ready. */
192 if ((elf_elfheader (abfd)->e_flags
193 & EF_AVR_LINKRELAX_PREPARED) == 0
194 && abfd != stub_file->the_bfd)
195 {
196 avr_link_relax = FALSE;
197 break;
198 }
199 }
200 }
201 else
202 {
203 avr_link_relax = RELAXATION_ENABLED;
204 }
205
206 abfd = link_info.output_bfd;
207 if (avr_link_relax)
208 elf_elfheader (abfd)->e_flags |= EF_AVR_LINKRELAX_PREPARED;
209 else
210 elf_elfheader (abfd)->e_flags &= ~EF_AVR_LINKRELAX_PREPARED;
211
212 finish_default ();
213}
28c9d252
NC
214EOF
215
216
217PARSE_AND_LIST_PROLOGUE='
218
219#define OPTION_NO_CALL_RET_REPLACEMENT 301
220#define OPTION_PMEM_WRAP_AROUND 302
221#define OPTION_NO_STUBS 303
222#define OPTION_DEBUG_STUBS 304
223#define OPTION_DEBUG_RELAX 305
224'
225
226PARSE_AND_LIST_LONGOPTS='
92b93329 227 { "no-call-ret-replacement", no_argument,
28c9d252 228 NULL, OPTION_NO_CALL_RET_REPLACEMENT},
92b93329 229 { "pmem-wrap-around", required_argument,
28c9d252 230 NULL, OPTION_PMEM_WRAP_AROUND},
92b93329 231 { "no-stubs", no_argument,
28c9d252 232 NULL, OPTION_NO_STUBS},
92b93329 233 { "debug-stubs", no_argument,
28c9d252 234 NULL, OPTION_DEBUG_STUBS},
92b93329 235 { "debug-relax", no_argument,
28c9d252
NC
236 NULL, OPTION_DEBUG_RELAX},
237'
238
239PARSE_AND_LIST_OPTIONS='
442996ee
AM
240 fprintf (file, _(" --pmem-wrap-around=<val> "
241 "Make the linker relaxation machine assume that a\n"
242 " "
243 " program counter wrap-around occures at address\n"
244 " "
245 " <val>. Supported values: 8k, 16k, 32k and 64k.\n"));
246 fprintf (file, _(" --no-call-ret-replacement "
247 "The relaxation machine normally will\n"
248 " "
249 " substitute two immediately following call/ret\n"
250 " "
251 " instructions by a single jump instruction.\n"
252 " "
253 " This option disables this optimization.\n"));
254 fprintf (file, _(" --no-stubs "
255 "If the linker detects to attempt to access\n"
256 " "
257 " an instruction beyond 128k by a reloc that\n"
258 " "
259 " is limited to 128k max, it inserts a jump\n"
260 " "
261 " stub. You can de-active this with this switch.\n"));
262 fprintf (file, _(" --debug-stubs "
263 "Used for debugging avr-ld.\n"));
264 fprintf (file, _(" --debug-relax "
265 "Used for debugging avr-ld.\n"));
28c9d252
NC
266'
267
268PARSE_AND_LIST_ARGS_CASES='
269
270 case OPTION_PMEM_WRAP_AROUND:
92b93329 271 {
28c9d252
NC
272 /* This variable is defined in the bfd library. */
273 if ((!strcmp (optarg,"32k")) || (!strcmp (optarg,"32K")))
274 avr_pc_wrap_around = 32768;
2a69000b
DC
275 else if ((!strcmp (optarg,"8k")) || (!strcmp (optarg,"8K")))
276 avr_pc_wrap_around = 8192;
28c9d252
NC
277 else if ((!strcmp (optarg,"16k")) || (!strcmp (optarg,"16K")))
278 avr_pc_wrap_around = 16384;
279 else if ((!strcmp (optarg,"64k")) || (!strcmp (optarg,"64K")))
280 avr_pc_wrap_around = 0x10000;
281 else
282 return FALSE;
283 }
284 break;
285
286 case OPTION_DEBUG_STUBS:
287 avr_debug_stubs = TRUE;
288 break;
289
290 case OPTION_DEBUG_RELAX:
291 avr_debug_relax = TRUE;
292 break;
293
294 case OPTION_NO_STUBS:
295 avr_no_stubs = TRUE;
296 break;
297
298 case OPTION_NO_CALL_RET_REPLACEMENT:
299 {
300 /* This variable is defined in the bfd library. */
301 avr_replace_call_ret_sequences = FALSE;
302 }
303 break;
304'
305
306#
307# Put these extra avr-elf routines in ld_${EMULATION_NAME}_emulation
308#
4d4ef6fd 309LDEMUL_BEFORE_PARSE=avr_elf_before_parse
28c9d252 310LDEMUL_BEFORE_ALLOCATION=avr_elf_${EMULATION_NAME}_before_allocation
eaeb0a9d 311LDEMUL_AFTER_ALLOCATION=avr_elf_after_allocation
28c9d252 312LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=avr_elf_create_output_section_statements
9d7b48dc 313LDEMUL_FINISH=avr_finish
This page took 0.435198 seconds and 4 git commands to generate.