Remove is_merge_section_for.
[deliverable/binutils-gdb.git] / ld / emultempl / aarch64elf.em
CommitLineData
a06ea964 1# This shell script emits a C file. -*- C -*-
b90efa5b 2# Copyright (C) 2009-2015 Free Software Foundation, Inc.
a06ea964
NC
3# Contributed by ARM Ltd.
4#
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3 of the license, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; see the file COPYING3. If not,
19# see <http://www.gnu.org/licenses/>.
20#
21
22# This file is sourced from elf32.em, and defines extra aarch64-elf
23# specific routines.
24#
25fragment <<EOF
26
27#include "ldctor.h"
28#include "elf/aarch64.h"
29
30static int no_enum_size_warning = 0;
31static int no_wchar_size_warning = 0;
32static int pic_veneer = 0;
68fcca92 33static int fix_erratum_835769 = 0;
a06ea964
NC
34
35static void
36gld${EMULATION_NAME}_before_parse (void)
37{
38#ifndef TARGET_ /* I.e., if not generic. */
39 ldfile_set_output_arch ("`echo ${ARCH}`", bfd_arch_unknown);
40#endif /* not TARGET_ */
41 input_flags.dynamic = ${DYNAMIC_LINK-TRUE};
42 config.has_shared = `if test -n "$GENERATE_SHLIB_SCRIPT" ; then echo TRUE ; else echo FALSE ; fi`;
e2caaa1f 43 config.separate_code = `if test "x${SEPARATE_CODE}" = xyes ; then echo TRUE ; else echo FALSE ; fi`;
a06ea964
NC
44}
45
46static void
47aarch64_elf_before_allocation (void)
48{
49 /* We should be able to set the size of the interworking stub section. We
50 can't do it until later if we have dynamic sections, though. */
51 if (! elf_hash_table (&link_info)->dynamic_sections_created)
52 {
53 /* Here we rummage through the found bfds to collect information. */
54 LANG_FOR_EACH_INPUT_STATEMENT (is)
55 {
56 /* Initialise mapping tables for code/data. */
4390599b 57 bfd_elf${ELFSIZE}_aarch64_init_maps (is->the_bfd);
a06ea964
NC
58 }
59 }
60
61 /* Call the standard elf routine. */
62 gld${EMULATION_NAME}_before_allocation ();
63}
64
65/* Fake input file for stubs. */
66static lang_input_statement_type *stub_file;
67
68/* Whether we need to call gldarm_layout_sections_again. */
69static int need_laying_out = 0;
70
71/* Maximum size of a group of input sections that can be handled by
72 one stub section. A value of +/-1 indicates the bfd back-end
73 should use a suitable default size. */
74static bfd_signed_vma group_size = 1;
75
76struct hook_stub_info
77{
78 lang_statement_list_type add;
79 asection *input_section;
80};
81
82/* Traverse the linker tree to find the spot where the stub goes. */
83
84static bfd_boolean
85hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
86{
87 lang_statement_union_type *l;
88 bfd_boolean ret;
89
90 for (; (l = *lp) != NULL; lp = &l->header.next)
91 {
92 switch (l->header.type)
93 {
94 case lang_constructors_statement_enum:
95 ret = hook_in_stub (info, &constructor_list.head);
96 if (ret)
97 return ret;
98 break;
99
100 case lang_output_section_statement_enum:
101 ret = hook_in_stub (info,
102 &l->output_section_statement.children.head);
103 if (ret)
104 return ret;
105 break;
106
107 case lang_wild_statement_enum:
108 ret = hook_in_stub (info, &l->wild_statement.children.head);
109 if (ret)
110 return ret;
111 break;
112
113 case lang_group_statement_enum:
114 ret = hook_in_stub (info, &l->group_statement.children.head);
115 if (ret)
116 return ret;
117 break;
118
119 case lang_input_section_enum:
120 if (l->input_section.section == info->input_section)
121 {
122 /* We've found our section. Insert the stub immediately
123 after its associated input section. */
124 *(info->add.tail) = l->header.next;
125 l->header.next = info->add.head;
126 return TRUE;
127 }
128 break;
129
130 case lang_data_statement_enum:
131 case lang_reloc_statement_enum:
132 case lang_object_symbols_statement_enum:
133 case lang_output_statement_enum:
134 case lang_target_statement_enum:
135 case lang_input_statement_enum:
136 case lang_assignment_statement_enum:
137 case lang_padding_statement_enum:
138 case lang_address_statement_enum:
139 case lang_fill_statement_enum:
140 break;
141
142 default:
143 FAIL ();
144 break;
145 }
146 }
147 return FALSE;
148}
149
150
4390599b 151/* Call-back for elf${ELFSIZE}_aarch64_size_stubs. */
a06ea964
NC
152
153/* Create a new stub section, and arrange for it to be linked
154 immediately after INPUT_SECTION. */
155
156static asection *
4390599b 157elf${ELFSIZE}_aarch64_add_stub_section (const char *stub_sec_name,
a06ea964
NC
158 asection *input_section)
159{
160 asection *stub_sec;
161 flagword flags;
162 asection *output_section;
a06ea964
NC
163 lang_output_section_statement_type *os;
164 struct hook_stub_info info;
165
166 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
167 | SEC_HAS_CONTENTS | SEC_RELOC | SEC_IN_MEMORY | SEC_KEEP);
168 stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
169 stub_sec_name, flags);
170 if (stub_sec == NULL)
171 goto err_ret;
172
173 bfd_set_section_alignment (stub_file->the_bfd, stub_sec, 3);
174
175 output_section = input_section->output_section;
24ef1aa7 176 os = lang_output_section_get (output_section);
a06ea964
NC
177
178 info.input_section = input_section;
179 lang_list_init (&info.add);
180 lang_add_section (&info.add, stub_sec, NULL, os);
181
182 if (info.add.head == NULL)
183 goto err_ret;
184
185 if (hook_in_stub (&info, &os->children.head))
186 return stub_sec;
187
188 err_ret:
189 einfo ("%X%P: can not make stub section: %E\n");
190 return NULL;
191}
192
4390599b 193/* Another call-back for elf${ELFSIZE}_aarch64_size_stubs. */
a06ea964
NC
194
195static void
196gldaarch64_layout_sections_again (void)
197{
198 /* If we have changed sizes of the stub sections, then we need
199 to recalculate all the section offsets. This may mean we need to
200 add even more stubs. */
201 gld${EMULATION_NAME}_map_segments (TRUE);
202 need_laying_out = -1;
203}
204
205static void
206build_section_lists (lang_statement_union_type *statement)
207{
208 if (statement->header.type == lang_input_section_enum)
209 {
210 asection *i = statement->input_section.section;
211
212 if (!((lang_input_statement_type *) i->owner->usrdata)->flags.just_syms
213 && (i->flags & SEC_EXCLUDE) == 0
214 && i->output_section != NULL
215 && i->output_section->owner == link_info.output_bfd)
4390599b 216 elf${ELFSIZE}_aarch64_next_input_section (& link_info, i);
a06ea964
NC
217 }
218}
219
220static void
221gld${EMULATION_NAME}_after_allocation (void)
222{
75938853
AM
223 int ret;
224
a06ea964
NC
225 /* bfd_elf32_discard_info just plays with debugging sections,
226 ie. doesn't affect any code, so we can delay resizing the
227 sections. It's likely we'll resize everything in the process of
228 adding stubs. */
75938853
AM
229 ret = bfd_elf_discard_info (link_info.output_bfd, & link_info);
230 if (ret < 0)
231 {
232 einfo ("%X%P: .eh_frame/.stab edit: %E\n");
233 return;
234 }
235 else if (ret > 0)
a06ea964
NC
236 need_laying_out = 1;
237
238 /* If generating a relocatable output file, then we don't
239 have to examine the relocs. */
240 if (stub_file != NULL && !link_info.relocatable)
241 {
75938853
AM
242 ret = elf${ELFSIZE}_aarch64_setup_section_lists (link_info.output_bfd,
243 &link_info);
a06ea964
NC
244 if (ret != 0)
245 {
246 if (ret < 0)
247 {
248 einfo ("%X%P: could not compute sections lists for stub generation: %E\n");
249 return;
250 }
251
252 lang_for_each_statement (build_section_lists);
253
254 /* Call into the BFD backend to do the real work. */
4390599b 255 if (! elf${ELFSIZE}_aarch64_size_stubs (link_info.output_bfd,
a06ea964
NC
256 stub_file->the_bfd,
257 & link_info,
258 group_size,
4390599b 259 & elf${ELFSIZE}_aarch64_add_stub_section,
a06ea964
NC
260 & gldaarch64_layout_sections_again))
261 {
262 einfo ("%X%P: cannot size stub section: %E\n");
263 return;
264 }
265 }
266 }
267
268 if (need_laying_out != -1)
269 gld${EMULATION_NAME}_map_segments (need_laying_out);
270}
271
272static void
273gld${EMULATION_NAME}_finish (void)
274{
275 if (! link_info.relocatable)
276 {
277 /* Now build the linker stubs. */
278 if (stub_file->the_bfd->sections != NULL)
279 {
4390599b 280 if (! elf${ELFSIZE}_aarch64_build_stubs (& link_info))
a06ea964
NC
281 einfo ("%X%P: can not build stubs: %E\n");
282 }
283 }
284
285 finish_default ();
286}
287
288/* This is a convenient point to tell BFD about target specific flags.
289 After the output has been created, but before inputs are read. */
290static void
291aarch64_elf_create_output_section_statements (void)
292{
293 if (strstr (bfd_get_target (link_info.output_bfd), "aarch64") == NULL)
294 {
295 /* The arm backend needs special fields in the output hash structure.
296 These will only be created if the output format is an arm format,
297 hence we do not support linking and changing output formats at the
298 same time. Use a link followed by objcopy to change output formats. */
299 einfo ("%F%X%P: error: Cannot change output format whilst linking AArch64 binaries.\n");
300 return;
301 }
302
4390599b 303 bfd_elf${ELFSIZE}_aarch64_set_options (link_info.output_bfd, &link_info,
a06ea964
NC
304 no_enum_size_warning,
305 no_wchar_size_warning,
68fcca92 306 pic_veneer, fix_erratum_835769);
a06ea964
NC
307
308 stub_file = lang_add_input_file ("linker stubs",
309 lang_input_file_is_fake_enum,
310 NULL);
311 stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
312 if (stub_file->the_bfd == NULL
313 || ! bfd_set_arch_mach (stub_file->the_bfd,
314 bfd_get_arch (link_info.output_bfd),
315 bfd_get_mach (link_info.output_bfd)))
316 {
317 einfo ("%X%P: can not create BFD %E\n");
318 return;
319 }
320
321 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
322 ldlang_add_file (stub_file);
323}
324
325/* Avoid processing the fake stub_file in vercheck, stat_needed and
326 check_needed routines. */
327
328static void (*real_func) (lang_input_statement_type *);
329
330static void aarch64_for_each_input_file_wrapper (lang_input_statement_type *l)
331{
332 if (l != stub_file)
333 (*real_func) (l);
334}
335
336static void
337aarch64_lang_for_each_input_file (void (*func) (lang_input_statement_type *))
338{
339 real_func = func;
340 lang_for_each_input_file (&aarch64_for_each_input_file_wrapper);
341}
342
343#define lang_for_each_input_file aarch64_lang_for_each_input_file
344
345EOF
346
347# Define some shell vars to insert bits of code into the standard elf
348# parse_args and list_options functions.
349#
350PARSE_AND_LIST_PROLOGUE='
351#define OPTION_NO_ENUM_SIZE_WARNING 309
352#define OPTION_PIC_VENEER 310
353#define OPTION_STUBGROUP_SIZE 311
354#define OPTION_NO_WCHAR_SIZE_WARNING 312
68fcca92 355#define OPTION_FIX_ERRATUM_835769 313
a06ea964
NC
356'
357
358PARSE_AND_LIST_SHORTOPTS=p
359
360PARSE_AND_LIST_LONGOPTS='
361 { "no-pipeline-knowledge", no_argument, NULL, '\'p\''},
362 { "no-enum-size-warning", no_argument, NULL, OPTION_NO_ENUM_SIZE_WARNING},
363 { "pic-veneer", no_argument, NULL, OPTION_PIC_VENEER},
364 { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
365 { "no-wchar-size-warning", no_argument, NULL, OPTION_NO_WCHAR_SIZE_WARNING},
68fcca92 366 { "fix-cortex-a53-835769", no_argument, NULL, OPTION_FIX_ERRATUM_835769},
a06ea964
NC
367'
368
369PARSE_AND_LIST_OPTIONS='
370 fprintf (file, _(" --no-enum-size-warning Don'\''t warn about objects with incompatible\n"
371 " enum sizes\n"));
372 fprintf (file, _(" --no-wchar-size-warning Don'\''t warn about objects with incompatible"
373 " wchar_t sizes\n"));
374 fprintf (file, _(" --pic-veneer Always generate PIC interworking veneers\n"));
375 fprintf (file, _("\
376 --stub-group-size=N Maximum size of a group of input sections that can be\n\
377 handled by one stub section. A negative value\n\
378 locates all stubs after their branches (with a\n\
379 group size of -N), while a positive value allows\n\
380 two groups of input sections, one before, and one\n\
381 after each stub section. Values of +/-1 indicate\n\
382 the linker should choose suitable defaults.\n"
383 ));
68fcca92 384 fprintf (file, _(" --fix-cortex-a53-835769 Fix erratum 835769\n"));
a06ea964
NC
385'
386
387PARSE_AND_LIST_ARGS_CASES='
388 case '\'p\'':
389 /* Only here for backwards compatibility. */
390 break;
391
392 case OPTION_NO_ENUM_SIZE_WARNING:
393 no_enum_size_warning = 1;
394 break;
395
396 case OPTION_NO_WCHAR_SIZE_WARNING:
397 no_wchar_size_warning = 1;
398 break;
399
400 case OPTION_PIC_VENEER:
401 pic_veneer = 1;
402 break;
403
68fcca92
JW
404 case OPTION_FIX_ERRATUM_835769:
405 fix_erratum_835769 = 1;
406 break;
407
a06ea964
NC
408 case OPTION_STUBGROUP_SIZE:
409 {
410 const char *end;
411
412 group_size = bfd_scan_vma (optarg, &end, 0);
413 if (*end)
414 einfo (_("%P%F: invalid number `%s'\''\n"), optarg);
415 }
416 break;
417'
418
419# We have our own before_allocation etc. functions, but they call
420# the standard routines, so give them a different name.
421LDEMUL_BEFORE_ALLOCATION=aarch64_elf_before_allocation
422LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
423LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=aarch64_elf_create_output_section_statements
424
425# Replace the elf before_parse function with our own.
426LDEMUL_BEFORE_PARSE=gld"${EMULATION_NAME}"_before_parse
427
428# Call the extra arm-elf function
429LDEMUL_FINISH=gld${EMULATION_NAME}_finish
This page took 0.168818 seconds and 4 git commands to generate.