ld: Add --warn-textrel and obsolete --warn-shared-textrel
[deliverable/binutils-gdb.git] / ld / emultempl / ppc64elf.em
CommitLineData
1f808cd5 1# This shell script emits a C file. -*- C -*-
b3adc24a 2# Copyright (C) 2002-2020 Free Software Foundation, Inc.
1f808cd5 3#
f96b4a7b 4# This file is part of the GNU Binutils.
1f808cd5
AM
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
1f808cd5
AM
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.
1f808cd5
AM
20#
21
075a2b89 22# This file is sourced from elf.em, and defines extra powerpc64-elf
1f808cd5
AM
23# specific routines.
24#
92b93329 25fragment <<EOF
1f808cd5 26
9c1d81c1 27#include "ldctor.h"
83490352 28#include "elf-bfd.h"
1f808cd5 29#include "elf64-ppc.h"
f05eb3b7 30#include "ldlex.h"
7341d5e2 31#include "elf/ppc64.h"
1f808cd5 32
e7d1c40c
AM
33static asection *ppc_add_stub_section (const char *, asection *);
34static void ppc_layout_sections_again (void);
35
36static struct ppc64_elf_params params = { NULL,
37 &ppc_add_stub_section,
38 &ppc_layout_sections_again,
9e7028aa 39 1, -1, -1, 0,
2420fff6 40 ${DEFAULT_PLT_STATIC_CHAIN-0}, -1, 5,
407aa07c 41 -1, 0, -1, -1, 0};
e7d1c40c 42
9c1d81c1
AM
43/* Fake input file for stubs. */
44static lang_input_statement_type *stub_file;
45
deb04cdb
AM
46/* Whether we need to call ppc_layout_sections_again. */
47static int need_laying_out = 0;
48
fac1652d
AM
49/* Whether to add ".foo" entries for each "foo" in a version script. */
50static int dotsyms = 1;
51
e5096e3f 52/* Whether to run tls optimization. */
c5614fa4
AM
53static int no_tls_opt = 0;
54
55/* Whether to run opd optimization. */
56static int no_opd_opt = 0;
57
3e04d765
AM
58/* Whether to convert inline PLT calls to direct. */
59static int no_inline_opt = 0;
60
c5614fa4
AM
61/* Whether to run toc optimization. */
62static int no_toc_opt = 0;
e5096e3f 63
d43d0b53
AM
64/* Whether to sort input toc and got sections. */
65static int no_toc_sort = 0;
66
6c2573b7
AM
67/* Input .toc sections will be placed in this output section. */
68static const char *toc_section_name = ".got";
0b9a4d73
AM
69static asection *toc_section = 0;
70
9c1d81c1
AM
71/* This is called before the input files are opened. We create a new
72 fake input file to hold the stub sections. */
73
74static void
7d8a3a28 75ppc_create_output_section_statements (void)
9c1d81c1 76{
5503fea1 77 if (!(bfd_get_flavour (link_info.output_bfd) == bfd_target_elf_flavour
4dfe6ac6 78 && elf_object_id (link_info.output_bfd) == PPC64_ELF_DATA))
a015f5ec
AM
79 return;
80
b9cf773d
AM
81 link_info.wrap_char = '.';
82
9c1d81c1
AM
83 stub_file = lang_add_input_file ("linker stubs",
84 lang_input_file_is_fake_enum,
85 NULL);
f13a99db 86 stub_file->the_bfd = bfd_create ("linker stubs", link_info.output_bfd);
9c1d81c1
AM
87 if (stub_file->the_bfd == NULL
88 || !bfd_set_arch_mach (stub_file->the_bfd,
f13a99db
AM
89 bfd_get_arch (link_info.output_bfd),
90 bfd_get_mach (link_info.output_bfd)))
9c1d81c1 91 {
d003af55 92 einfo (_("%F%P: can not create BFD: %E\n"));
9c1d81c1
AM
93 return;
94 }
95
d457dcf6 96 stub_file->the_bfd->flags |= BFD_LINKER_CREATED;
9c1d81c1 97 ldlang_add_file (stub_file);
e7d1c40c 98 params.stub_bfd = stub_file->the_bfd;
7d4c687d 99 if (params.save_restore_funcs < 0)
0e1862bb 100 params.save_restore_funcs = !bfd_link_relocatable (&link_info);
e7d1c40c 101 if (!ppc64_elf_init_stub_bfd (&link_info, &params))
d003af55 102 einfo (_("%F%P: can not init BFD: %E\n"));
9c1d81c1
AM
103}
104
dbd1e97e
AM
105/* Called after opening files but before mapping sections. */
106
107static void
108ppc_after_open (void)
109{
110 if (stub_file != NULL && link_info.relro && params.object_in_toc)
111 {
112 /* We have a .toc section that might be written to at run time.
113 Don't put .toc into the .got output section. */
114 lang_output_section_statement_type *got;
115
116 got = lang_output_section_find (".got");
117 if (got != NULL)
118 {
119 lang_statement_union_type *s;
120 for (s = got->children.head; s != NULL; s = s->header.next)
121 if (s->header.type == lang_wild_statement_enum
122 && s->wild_statement.filename == NULL)
123 {
124 struct wildcard_list **i = &s->wild_statement.section_list;
125 while (*i != NULL)
126 if (strcmp ((*i)->spec.name, ".toc") == 0)
127 *i = (*i)->next;
128 else
129 i = &(*i)->next;
130 }
6c2573b7
AM
131 /* Instead, .toc input sections will be mapped to the
132 read/write .toc output section. If user scripts don't
133 provide one then we'll lose toc sorting and multi-toc. */
134 toc_section_name = ".toc";
dbd1e97e
AM
135 }
136 }
137 gld${EMULATION_NAME}_after_open ();
138}
139
d43d0b53
AM
140/* Move the input section statement at *U which happens to be on LIST
141 to be just before *TO. */
142
143static void
144move_input_section (lang_statement_list_type *list,
145 lang_statement_union_type **u,
146 lang_statement_union_type **to)
147{
148 lang_statement_union_type *s = *u;
149 asection *i = s->input_section.section;
150 asection *p, *n;
151
152 /* Snip the input section from the statement list. If it was the
153 last statement, fix the list tail pointer. */
154 *u = s->header.next;
155 if (*u == NULL)
156 list->tail = u;
157 /* Add it back in the new position. */
158 s->header.next = *to;
159 *to = s;
160 if (list->tail == to)
161 list->tail = &s->header.next;
162
163 /* Trim I off the bfd map_head/map_tail doubly linked lists. */
164 n = i->map_head.s;
165 p = i->map_tail.s;
166 (p != NULL ? p : i->output_section)->map_head.s = n;
167 (n != NULL ? n : i->output_section)->map_tail.s = p;
168
169 /* Add I back on in its new position. */
170 if (s->header.next->header.type == lang_input_section_enum)
171 {
172 n = s->header.next->input_section.section;
173 p = n->map_tail.s;
174 }
175 else
176 {
177 /* If the next statement is not an input section statement then
178 TO must point at the previous input section statement
179 header.next field. */
180 lang_input_section_type *prev = (lang_input_section_type *)
181 ((char *) to - offsetof (lang_statement_union_type, header.next));
182
183 ASSERT (prev->header.type == lang_input_section_enum);
184 p = prev->section;
185 n = p->map_head.s;
186 }
187 i->map_head.s = n;
188 i->map_tail.s = p;
189 (p != NULL ? p : i->output_section)->map_head.s = i;
190 (n != NULL ? n : i->output_section)->map_tail.s = i;
191}
192
193/* Sort input section statements in the linker script tree rooted at
194 LIST so that those whose owning bfd happens to have a section
195 called .init or .fini are placed first. Place any TOC sections
196 referenced by small TOC relocs next, with TOC sections referenced
197 only by bigtoc relocs last. */
198
199static void
200sort_toc_sections (lang_statement_list_type *list,
201 lang_statement_union_type **ini,
202 lang_statement_union_type **small)
203{
204 lang_statement_union_type *s, **u;
205 asection *i;
206
207 u = &list->head;
208 while ((s = *u) != NULL)
209 {
210 switch (s->header.type)
211 {
212 case lang_wild_statement_enum:
213 sort_toc_sections (&s->wild_statement.children, ini, small);
214 break;
215
216 case lang_group_statement_enum:
217 sort_toc_sections (&s->group_statement.children, ini, small);
218 break;
219
220 case lang_input_section_enum:
221 i = s->input_section.section;
222 /* Leave the stub_file .got where it is. We put the .got
223 header there. */
224 if (i->owner == stub_file->the_bfd)
225 break;
226 if (bfd_get_section_by_name (i->owner, ".init") != NULL
227 || bfd_get_section_by_name (i->owner, ".fini") != NULL)
228 {
229 if (ini != NULL && *ini != s)
230 {
231 move_input_section (list, u, ini);
232 if (small == ini)
233 small = &s->header.next;
234 ini = &s->header.next;
235 continue;
236 }
237 if (small == ini)
238 small = &s->header.next;
239 ini = &s->header.next;
240 break;
241 }
242 else if (ini == NULL)
243 ini = u;
244
245 if (ppc64_elf_has_small_toc_reloc (i))
246 {
247 if (small != NULL && *small != s)
248 {
249 move_input_section (list, u, small);
250 small = &s->header.next;
251 continue;
252 }
253 small = &s->header.next;
254 }
255 else if (small == NULL)
256 small = u;
257 break;
258
259 default:
260 break;
261 }
262 u = &s->header.next;
263 }
264}
265
ba761f19
AM
266static void
267prelim_size_sections (void)
268{
269 if (expld.phase != lang_mark_phase_enum)
270 {
271 expld.phase = lang_mark_phase_enum;
58e6cc77 272 expld.dataseg.phase = exp_seg_none;
ba761f19
AM
273 one_lang_size_sections_pass (NULL, FALSE);
274 /* We must not cache anything from the preliminary sizing. */
275 lang_reset_memory_regions ();
276 }
277}
278
836c6af1 279static void
7d8a3a28 280ppc_before_allocation (void)
836c6af1 281{
a015f5ec 282 if (stub_file != NULL)
e0468e59 283 {
74f0fb50 284 if (!no_opd_opt
e7d1c40c 285 && !ppc64_elf_edit_opd (&link_info))
d003af55 286 einfo (_("%X%P: can not edit %s: %E\n"), "opd");
e5096e3f 287
3e04d765
AM
288 if (!no_inline_opt
289 && !bfd_link_relocatable (&link_info))
290 {
291 prelim_size_sections ();
292
293 if (!ppc64_elf_inline_plt (&link_info))
294 einfo (_("%X%P: inline PLT: %E\n"));
295 }
296
e7d1c40c 297 if (ppc64_elf_tls_setup (&link_info)
f13a99db 298 && !no_tls_opt)
a015f5ec
AM
299 {
300 /* Size the sections. This is premature, but we want to know the
301 TLS segment layout so that certain optimizations can be done. */
ba761f19 302 prelim_size_sections ();
a015f5ec 303
33c0ec9d 304 if (!ppc64_elf_tls_optimize (&link_info))
d003af55 305 einfo (_("%X%P: TLS problem %E\n"));
a015f5ec 306 }
c5614fa4
AM
307
308 if (!no_toc_opt
0e1862bb 309 && !bfd_link_relocatable (&link_info))
ba761f19
AM
310 {
311 prelim_size_sections ();
312
313 if (!ppc64_elf_edit_toc (&link_info))
d003af55 314 einfo (_("%X%P: can not edit %s: %E\n"), "toc");
ba761f19 315 }
d43d0b53
AM
316
317 if (!no_toc_sort)
318 {
319 lang_output_section_statement_type *toc_os;
320
6c2573b7 321 toc_os = lang_output_section_find (toc_section_name);
d43d0b53
AM
322 if (toc_os != NULL)
323 sort_toc_sections (&toc_os->children, NULL, NULL);
324 }
e0468e59
AM
325 }
326
836c6af1
AM
327 gld${EMULATION_NAME}_before_allocation ();
328}
329
9c1d81c1
AM
330struct hook_stub_info
331{
332 lang_statement_list_type add;
333 asection *input_section;
334};
335
336/* Traverse the linker tree to find the spot where the stub goes. */
337
b34976b6 338static bfd_boolean
7d8a3a28 339hook_in_stub (struct hook_stub_info *info, lang_statement_union_type **lp)
9c1d81c1
AM
340{
341 lang_statement_union_type *l;
b34976b6 342 bfd_boolean ret;
9c1d81c1
AM
343
344 for (; (l = *lp) != NULL; lp = &l->header.next)
345 {
346 switch (l->header.type)
347 {
348 case lang_constructors_statement_enum:
349 ret = hook_in_stub (info, &constructor_list.head);
350 if (ret)
351 return ret;
352 break;
353
354 case lang_output_section_statement_enum:
355 ret = hook_in_stub (info,
356 &l->output_section_statement.children.head);
357 if (ret)
358 return ret;
359 break;
360
361 case lang_wild_statement_enum:
362 ret = hook_in_stub (info, &l->wild_statement.children.head);
363 if (ret)
364 return ret;
365 break;
366
367 case lang_group_statement_enum:
368 ret = hook_in_stub (info, &l->group_statement.children.head);
369 if (ret)
370 return ret;
371 break;
372
373 case lang_input_section_enum:
374 if (l->input_section.section == info->input_section)
375 {
376 /* We've found our section. Insert the stub immediately
377 before its associated input section. */
378 *lp = info->add.head;
379 *(info->add.tail) = l;
b34976b6 380 return TRUE;
9c1d81c1
AM
381 }
382 break;
383
384 case lang_data_statement_enum:
385 case lang_reloc_statement_enum:
386 case lang_object_symbols_statement_enum:
387 case lang_output_statement_enum:
388 case lang_target_statement_enum:
389 case lang_input_statement_enum:
390 case lang_assignment_statement_enum:
391 case lang_padding_statement_enum:
392 case lang_address_statement_enum:
393 case lang_fill_statement_enum:
394 break;
395
396 default:
397 FAIL ();
398 break;
399 }
400 }
b34976b6 401 return FALSE;
9c1d81c1
AM
402}
403
404
405/* Call-back for ppc64_elf_size_stubs. */
406
407/* Create a new stub section, and arrange for it to be linked
408 immediately before INPUT_SECTION. */
409
410static asection *
7d8a3a28 411ppc_add_stub_section (const char *stub_sec_name, asection *input_section)
9c1d81c1
AM
412{
413 asection *stub_sec;
414 flagword flags;
415 asection *output_section;
9c1d81c1
AM
416 lang_output_section_statement_type *os;
417 struct hook_stub_info info;
418
9c1d81c1 419 flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE
e4e0193e 420 | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_KEEP);
9795b468
AM
421 stub_sec = bfd_make_section_anyway_with_flags (stub_file->the_bfd,
422 stub_sec_name, flags);
bd518033 423 if (stub_sec == NULL
fd361982
AM
424 || !bfd_set_section_alignment (stub_sec, (params.plt_stub_align > 5
425 ? params.plt_stub_align
426 : params.plt_stub_align < -5
427 ? -params.plt_stub_align
428 : 5)))
9c1d81c1
AM
429 goto err_ret;
430
431 output_section = input_section->output_section;
24ef1aa7 432 os = lang_output_section_get (output_section);
9c1d81c1
AM
433
434 info.input_section = input_section;
435 lang_list_init (&info.add);
b9c361e0 436 lang_add_section (&info.add, stub_sec, NULL, os);
9c1d81c1
AM
437
438 if (info.add.head == NULL)
439 goto err_ret;
440
441 if (hook_in_stub (&info, &os->children.head))
442 return stub_sec;
443
444 err_ret:
d003af55 445 einfo (_("%X%P: can not make stub section: %E\n"));
9c1d81c1
AM
446 return NULL;
447}
448
449
450/* Another call-back for ppc64_elf_size_stubs. */
451
452static void
7d8a3a28 453ppc_layout_sections_again (void)
9c1d81c1
AM
454{
455 /* If we have changed sizes of the stub sections, then we need
456 to recalculate all the section offsets. This may mean we need to
457 add even more stubs. */
d871d478 458 ldelf_map_segments (TRUE);
1f808cd5 459
0e1862bb 460 if (!bfd_link_relocatable (&link_info))
1c865ab2 461 ppc64_elf_set_toc (&link_info, link_info.output_bfd);
eaeb0a9d
AM
462
463 need_laying_out = -1;
1f808cd5
AM
464}
465
9c1d81c1 466
0b9a4d73 467static void
7d8a3a28 468build_toc_list (lang_statement_union_type *statement)
0b9a4d73 469{
7b986e99
AM
470 if (statement->header.type == lang_input_section_enum)
471 {
472 asection *i = statement->input_section.section;
473
dbaa2011 474 if (i->sec_info_type != SEC_INFO_TYPE_JUST_SYMS
7b986e99
AM
475 && (i->flags & SEC_EXCLUDE) == 0
476 && i->output_section == toc_section)
927be08e
AM
477 {
478 if (!ppc64_elf_next_toc_section (&link_info, i))
d003af55 479 einfo (_("%X%P: linker script separates .got and .toc\n"));
927be08e 480 }
7b986e99 481 }
0b9a4d73
AM
482}
483
484
9c1d81c1 485static void
7d8a3a28 486build_section_lists (lang_statement_union_type *statement)
9c1d81c1 487{
7b986e99 488 if (statement->header.type == lang_input_section_enum)
9c1d81c1 489 {
7b986e99
AM
490 asection *i = statement->input_section.section;
491
00f93c44 492 if (!bfd_input_just_syms (i->owner)
7b986e99
AM
493 && (i->flags & SEC_EXCLUDE) == 0
494 && i->output_section != NULL
f13a99db 495 && i->output_section->owner == link_info.output_bfd)
7b986e99
AM
496 {
497 if (!ppc64_elf_next_input_section (&link_info, i))
d003af55 498 einfo (_("%X%P: can not size stub section: %E\n"));
7b986e99 499 }
9c1d81c1
AM
500 }
501}
502
fac1652d 503
eaeb0a9d
AM
504/* Call the back-end function to set TOC base after we have placed all
505 the sections. */
1f808cd5 506static void
eaeb0a9d 507gld${EMULATION_NAME}_after_allocation (void)
1f808cd5 508{
75938853
AM
509 int ret;
510
836c6af1
AM
511 /* If generating a relocatable output file, then we don't have any
512 stubs. */
0e1862bb 513 if (stub_file != NULL && !bfd_link_relocatable (&link_info))
1f808cd5 514 {
75938853 515 ret = ppc64_elf_setup_section_lists (&link_info);
92b7a70f 516 if (ret < 0)
d003af55 517 einfo (_("%X%P: can not size stub section: %E\n"));
da44f4e5 518 else
9c1d81c1 519 {
927be08e
AM
520 ppc64_elf_start_multitoc_partition (&link_info);
521
e7d1c40c 522 if (!params.no_multi_toc)
927be08e
AM
523 {
524 toc_section = bfd_get_section_by_name (link_info.output_bfd,
6c2573b7 525 toc_section_name);
927be08e
AM
526 if (toc_section != NULL)
527 lang_for_each_statement (build_toc_list);
528 }
529
530 if (ppc64_elf_layout_multitoc (&link_info)
e7d1c40c 531 && !params.no_multi_toc
927be08e 532 && toc_section != NULL)
0b9a4d73
AM
533 lang_for_each_statement (build_toc_list);
534
927be08e 535 ppc64_elf_finish_multitoc_partition (&link_info);
0b9a4d73 536
836c6af1 537 lang_for_each_statement (build_section_lists);
9c1d81c1 538
70cc837d 539 if (!ppc64_elf_check_init_fini (&link_info))
d003af55 540 einfo (_("%P: .init/.fini fragments use differing TOC pointers\n"));
70cc837d 541
836c6af1 542 /* Call into the BFD backend to do the real work. */
e7d1c40c 543 if (!ppc64_elf_size_stubs (&link_info))
d003af55 544 einfo (_("%X%P: can not size stub section: %E\n"));
1f808cd5 545 }
9c1d81c1 546 }
1f808cd5 547
da44f4e5
AM
548 /* We can't parse and merge .eh_frame until the glink .eh_frame has
549 been generated. Otherwise the glink .eh_frame CIE won't be
550 merged with other CIEs, and worse, the glink .eh_frame FDEs won't
551 be listed in .eh_frame_hdr. */
552 ret = bfd_elf_discard_info (link_info.output_bfd, &link_info);
553 if (ret < 0)
554 {
d003af55 555 einfo (_("%X%P: .eh_frame/.stab edit: %E\n"));
da44f4e5
AM
556 return;
557 }
558 else if (ret > 0)
559 need_laying_out = 1;
560
44bd1acd
AM
561 /* Call map_segments regardless of the state of need_laying_out.
562 need_laying_out set to -1 means we have just laid everything out,
563 but ppc64_elf_size_stubs strips .branch_lt and .eh_frame if
564 unneeded, after ppc_layout_sections_again. Another call removes
565 these sections from the segment map. Their presence is
566 innocuous except for confusing ELF_SECTION_IN_SEGMENT. */
d871d478 567 ldelf_map_segments (need_laying_out > 0);
44bd1acd 568
0e1862bb 569 if (need_laying_out != -1 && !bfd_link_relocatable (&link_info))
44bd1acd 570 ppc64_elf_set_toc (&link_info, link_info.output_bfd);
eaeb0a9d
AM
571}
572
573
574/* Final emulation specific call. */
575
576static void
577gld${EMULATION_NAME}_finish (void)
578{
7341d5e2
AM
579 char *msg = NULL;
580 char *line, *endline;
581
eaeb0a9d
AM
582 /* e_entry on PowerPC64 points to the function descriptor for
583 _start. If _start is missing, default to the first function
584 descriptor in the .opd section. */
459609d6
AM
585 if (stub_file != NULL
586 && (elf_elfheader (link_info.output_bfd)->e_flags & EF_PPC64_ABI) == 1)
7341d5e2
AM
587 entry_section = ".opd";
588
589 if (params.emit_stub_syms < 0)
590 params.emit_stub_syms = 1;
591 if (stub_file != NULL
0e1862bb 592 && !bfd_link_relocatable (&link_info)
7341d5e2 593 && !ppc64_elf_build_stubs (&link_info, config.stats ? &msg : NULL))
d003af55 594 einfo (_("%X%P: can not build stubs: %E\n"));
7341d5e2
AM
595
596 fflush (stdout);
597 for (line = msg; line != NULL; line = endline)
9c1d81c1 598 {
7341d5e2
AM
599 endline = strchr (line, '\n');
600 if (endline != NULL)
601 *endline++ = '\0';
602 fprintf (stderr, "%s: %s\n", program_name, line);
9c1d81c1 603 }
7341d5e2 604 fflush (stderr);
5e2ab612 605 free (msg);
99877b66 606
1e035701 607 finish_default ();
9c1d81c1 608}
1f808cd5 609
76dc39fe 610
fac1652d
AM
611/* Add a pattern matching ".foo" for every "foo" in a version script.
612
613 The reason for doing this is that many shared library version
614 scripts export a selected set of functions or data symbols, forcing
615 others local. eg.
616
617 . VERS_1 {
618 . global:
619 . this; that; some; thing;
620 . local:
621 . *;
622 . };
623
624 To make the above work for PowerPC64, we need to export ".this",
625 ".that" and so on, otherwise only the function descriptor syms are
626 exported. Lack of an exported function code sym may cause a
627 definition to be pulled in from a static library. */
628
7d8a3a28
AM
629static struct bfd_elf_version_expr *
630gld${EMULATION_NAME}_new_vers_pattern (struct bfd_elf_version_expr *entry)
fac1652d
AM
631{
632 struct bfd_elf_version_expr *dot_entry;
fac1652d
AM
633 unsigned int len;
634 char *dot_pat;
635
b7b7fe3f 636 if (!dotsyms
ae5a3597
AM
637 || entry->pattern[0] == '.'
638 || (!entry->literal && entry->pattern[0] == '*'))
fac1652d
AM
639 return entry;
640
7d8a3a28 641 dot_entry = xmalloc (sizeof *dot_entry);
108ba305 642 *dot_entry = *entry;
fac1652d 643 dot_entry->next = entry;
ae5a3597
AM
644 len = strlen (entry->pattern) + 2;
645 dot_pat = xmalloc (len);
646 dot_pat[0] = '.';
647 memcpy (dot_pat + 1, entry->pattern, len - 1);
648 dot_entry->pattern = dot_pat;
71755fdf 649 dot_entry->script = 1;
fac1652d
AM
650 return dot_entry;
651}
652
1f808cd5
AM
653EOF
654
dc27aea4 655if grep -q 'ld_elf32_spu_emulation' ldemul-list.h; then
92b93329 656 fragment <<EOF
dc27aea4
AM
657/* Special handling for embedded SPU executables. */
658extern bfd_boolean embedded_spu_file (lang_input_statement_type *, const char *);
dc27aea4
AM
659
660static bfd_boolean
661ppc64_recognized_file (lang_input_statement_type *entry)
662{
663 if (embedded_spu_file (entry, "-m64"))
664 return TRUE;
665
d871d478 666 return ldelf_load_symbols (entry);
dc27aea4
AM
667}
668EOF
669LDEMUL_RECOGNIZED_FILE=ppc64_recognized_file
670fi
671
9c1d81c1
AM
672# Define some shell vars to insert bits of code into the standard elf
673# parse_args and list_options functions.
674#
58d180e8 675PARSE_AND_LIST_PROLOGUE=${PARSE_AND_LIST_PROLOGUE}'
f378ab09
AM
676enum ppc64_opt
677{
678 OPTION_STUBGROUP_SIZE = 321,
679 OPTION_PLT_STATIC_CHAIN,
680 OPTION_NO_PLT_STATIC_CHAIN,
681 OPTION_PLT_THREAD_SAFE,
682 OPTION_NO_PLT_THREAD_SAFE,
683 OPTION_PLT_ALIGN,
684 OPTION_NO_PLT_ALIGN,
685 OPTION_PLT_LOCALENTRY,
686 OPTION_NO_PLT_LOCALENTRY,
687 OPTION_STUBSYMS,
688 OPTION_NO_STUBSYMS,
689 OPTION_SAVRES,
690 OPTION_NO_SAVRES,
691 OPTION_DOTSYMS,
692 OPTION_NO_DOTSYMS,
693 OPTION_NO_TLS_OPT,
694 OPTION_TLS_GET_ADDR_OPT,
695 OPTION_NO_TLS_GET_ADDR_OPT,
9e7028aa
AM
696 OPTION_TLS_GET_ADDR_REGSAVE,
697 OPTION_NO_TLS_GET_ADDR_REGSAVE,
f378ab09 698 OPTION_NO_OPD_OPT,
3e04d765 699 OPTION_NO_INLINE_OPT,
f378ab09
AM
700 OPTION_NO_TOC_OPT,
701 OPTION_NO_MULTI_TOC,
702 OPTION_NO_TOC_SORT,
703 OPTION_NON_OVERLAPPING_OPD
704};
9c1d81c1
AM
705'
706
58d180e8 707PARSE_AND_LIST_LONGOPTS=${PARSE_AND_LIST_LONGOPTS}'
9c1d81c1 708 { "stub-group-size", required_argument, NULL, OPTION_STUBGROUP_SIZE },
9df0ef5f
AM
709 { "plt-static-chain", no_argument, NULL, OPTION_PLT_STATIC_CHAIN },
710 { "no-plt-static-chain", no_argument, NULL, OPTION_NO_PLT_STATIC_CHAIN },
794e51c0
AM
711 { "plt-thread-safe", no_argument, NULL, OPTION_PLT_THREAD_SAFE },
712 { "no-plt-thread-safe", no_argument, NULL, OPTION_NO_PLT_THREAD_SAFE },
713 { "plt-align", optional_argument, NULL, OPTION_PLT_ALIGN },
714 { "no-plt-align", no_argument, NULL, OPTION_NO_PLT_ALIGN },
f378ab09
AM
715 { "plt-localentry", optional_argument, NULL, OPTION_PLT_LOCALENTRY },
716 { "no-plt-localentry", no_argument, NULL, OPTION_NO_PLT_LOCALENTRY },
0b9a4d73 717 { "emit-stub-syms", no_argument, NULL, OPTION_STUBSYMS },
b02c4cfa 718 { "no-emit-stub-syms", no_argument, NULL, OPTION_NO_STUBSYMS },
fac1652d
AM
719 { "dotsyms", no_argument, NULL, OPTION_DOTSYMS },
720 { "no-dotsyms", no_argument, NULL, OPTION_NO_DOTSYMS },
7d4c687d
AM
721 { "save-restore-funcs", no_argument, NULL, OPTION_SAVRES },
722 { "no-save-restore-funcs", no_argument, NULL, OPTION_NO_SAVRES },
e5096e3f 723 { "no-tls-optimize", no_argument, NULL, OPTION_NO_TLS_OPT },
7c9cf415 724 { "tls-get-addr-optimize", no_argument, NULL, OPTION_TLS_GET_ADDR_OPT },
a7f2871e 725 { "no-tls-get-addr-optimize", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_OPT },
9e7028aa
AM
726 { "tls-get-addr-regsave", no_argument, NULL, OPTION_TLS_GET_ADDR_REGSAVE },
727 { "no-tls-get-addr-regsave", no_argument, NULL, OPTION_NO_TLS_GET_ADDR_REGSAVE},
c5614fa4 728 { "no-opd-optimize", no_argument, NULL, OPTION_NO_OPD_OPT },
3e04d765 729 { "no-inline-optimize", no_argument, NULL, OPTION_NO_INLINE_OPT },
c5614fa4 730 { "no-toc-optimize", no_argument, NULL, OPTION_NO_TOC_OPT },
4c52953f 731 { "no-multi-toc", no_argument, NULL, OPTION_NO_MULTI_TOC },
d43d0b53 732 { "no-toc-sort", no_argument, NULL, OPTION_NO_TOC_SORT },
3f764659 733 { "non-overlapping-opd", no_argument, NULL, OPTION_NON_OVERLAPPING_OPD },
9c1d81c1
AM
734'
735
58d180e8 736PARSE_AND_LIST_OPTIONS=${PARSE_AND_LIST_OPTIONS}'
9c1d81c1 737 fprintf (file, _("\
442996ee
AM
738 --stub-group-size=N Maximum size of a group of input sections that\n\
739 can be handled by one stub section. A negative\n\
740 value locates all stubs before their branches\n\
741 (with a group size of -N), while a positive\n\
742 value allows two groups of input sections, one\n\
743 before, and one after each stub section.\n\
744 Values of +/-1 indicate the linker should\n\
745 choose suitable defaults.\n"
9c1d81c1 746 ));
fac1652d 747 fprintf (file, _("\
df5f2391 748 --plt-static-chain PLT call stubs should load r11'${DEFAULT_PLT_STATIC_CHAIN- (default)}'\n"
794e51c0
AM
749 ));
750 fprintf (file, _("\
df5f2391 751 --no-plt-static-chain PLT call stubs should not load r11'${DEFAULT_PLT_STATIC_CHAIN+ (default)}'\n"
794e51c0
AM
752 ));
753 fprintf (file, _("\
df5f2391 754 --plt-thread-safe PLT call stubs with load-load barrier\n"
794e51c0
AM
755 ));
756 fprintf (file, _("\
df5f2391 757 --no-plt-thread-safe PLT call stubs without barrier\n"
794e51c0
AM
758 ));
759 fprintf (file, _("\
df5f2391 760 --plt-align [=<align>] Align PLT call stubs to fit cache lines\n"
9df0ef5f
AM
761 ));
762 fprintf (file, _("\
df5f2391 763 --no-plt-align Dont'\''t align individual PLT call stubs\n"
9df0ef5f
AM
764 ));
765 fprintf (file, _("\
df5f2391 766 --plt-localentry Optimize calls to ELFv2 localentry:0 functions\n"
f378ab09
AM
767 ));
768 fprintf (file, _("\
df5f2391 769 --no-plt-localentry Don'\''t optimize ELFv2 calls\n"
f378ab09
AM
770 ));
771 fprintf (file, _("\
df5f2391 772 --emit-stub-syms Label linker stubs with a symbol\n"
0b9a4d73
AM
773 ));
774 fprintf (file, _("\
df5f2391 775 --no-emit-stub-syms Don'\''t label linker stubs with a symbol\n"
b02c4cfa
AM
776 ));
777 fprintf (file, _("\
442996ee
AM
778 --dotsyms For every version pattern \"foo\" in a version\n\
779 script, add \".foo\" so that function code\n\
780 symbols are treated the same as function\n\
781 descriptor symbols. Defaults to on.\n"
fac1652d
AM
782 ));
783 fprintf (file, _("\
df5f2391 784 --no-dotsyms Don'\''t do anything special in version scripts\n"
fac1652d 785 ));
e5096e3f 786 fprintf (file, _("\
7d4c687d
AM
787 --save-restore-funcs Provide register save and restore routines used\n\
788 by gcc -Os code. Defaults to on for normal\n\
789 final link, off for ld -r.\n"
790 ));
791 fprintf (file, _("\
df5f2391 792 --no-save-restore-funcs Don'\''t provide these routines\n"
7d4c687d
AM
793 ));
794 fprintf (file, _("\
df5f2391 795 --no-tls-optimize Don'\''t try to optimize TLS accesses\n"
e5096e3f 796 ));
3f764659 797 fprintf (file, _("\
df5f2391 798 --tls-get-addr-optimize Force use of special __tls_get_addr call\n"
7c9cf415
AM
799 ));
800 fprintf (file, _("\
df5f2391 801 --no-tls-get-addr-optimize Don'\''t use a special __tls_get_addr call\n"
a7f2871e
AM
802 ));
803 fprintf (file, _("\
9e7028aa
AM
804 --tls-get-addr-regsave Force register save __tls_get_addr stub\n"
805 ));
806 fprintf (file, _("\
807 --no-tls-get-addr-regsave Don'\''t use register save __tls_get_addr stub\n"
808 ));
809 fprintf (file, _("\
df5f2391 810 --no-opd-optimize Don'\''t optimize the OPD section\n"
c5614fa4
AM
811 ));
812 fprintf (file, _("\
3e04d765
AM
813 --no-inline-optimize Don'\''t convert inline PLT to direct calls\n"
814 ));
815 fprintf (file, _("\
df5f2391 816 --no-toc-optimize Don'\''t optimize the TOC section\n"
c5614fa4
AM
817 ));
818 fprintf (file, _("\
df5f2391 819 --no-multi-toc Disallow automatic multiple toc sections\n"
4c52953f
AM
820 ));
821 fprintf (file, _("\
df5f2391 822 --no-toc-sort Don'\''t sort TOC and GOT sections\n"
d43d0b53
AM
823 ));
824 fprintf (file, _("\
442996ee 825 --non-overlapping-opd Canonicalize .opd, so that there are no\n\
df5f2391 826 overlapping .opd entries\n"
3f764659 827 ));
9c1d81c1
AM
828'
829
58d180e8 830PARSE_AND_LIST_ARGS_CASES=${PARSE_AND_LIST_ARGS_CASES}'
9c1d81c1
AM
831 case OPTION_STUBGROUP_SIZE:
832 {
833 const char *end;
6c19b93b
AM
834 params.group_size = bfd_scan_vma (optarg, &end, 0);
835 if (*end)
df5f2391 836 einfo (_("%F%P: invalid number `%s'\''\n"), optarg);
9c1d81c1
AM
837 }
838 break;
fac1652d 839
9df0ef5f 840 case OPTION_PLT_STATIC_CHAIN:
e7d1c40c 841 params.plt_static_chain = 1;
9df0ef5f
AM
842 break;
843
844 case OPTION_NO_PLT_STATIC_CHAIN:
e7d1c40c 845 params.plt_static_chain = 0;
9df0ef5f
AM
846 break;
847
794e51c0 848 case OPTION_PLT_THREAD_SAFE:
e7d1c40c 849 params.plt_thread_safe = 1;
794e51c0
AM
850 break;
851
852 case OPTION_NO_PLT_THREAD_SAFE:
e7d1c40c 853 params.plt_thread_safe = 0;
794e51c0
AM
854 break;
855
856 case OPTION_PLT_ALIGN:
857 if (optarg != NULL)
858 {
859 char *end;
691d2e9a
AM
860 long val = strtol (optarg, &end, 0);
861 if (*end || (unsigned long) val + 8 > 16)
df5f2391 862 einfo (_("%F%P: invalid --plt-align `%s'\''\n"), optarg);
e05fa0ba 863 params.plt_stub_align = val;
794e51c0
AM
864 }
865 else
e05fa0ba 866 params.plt_stub_align = 5;
794e51c0
AM
867 break;
868
869 case OPTION_NO_PLT_ALIGN:
e05fa0ba 870 params.plt_stub_align = 0;
794e51c0
AM
871 break;
872
f378ab09
AM
873 case OPTION_PLT_LOCALENTRY:
874 params.plt_localentry0 = 1;
875 break;
876
877 case OPTION_NO_PLT_LOCALENTRY:
878 params.plt_localentry0 = 0;
879 break;
880
0b9a4d73 881 case OPTION_STUBSYMS:
e7d1c40c 882 params.emit_stub_syms = 1;
0b9a4d73
AM
883 break;
884
b02c4cfa 885 case OPTION_NO_STUBSYMS:
e7d1c40c 886 params.emit_stub_syms = 0;
b02c4cfa
AM
887 break;
888
fac1652d 889 case OPTION_DOTSYMS:
e5096e3f 890 dotsyms = 1;
fac1652d
AM
891 break;
892
893 case OPTION_NO_DOTSYMS:
e5096e3f
AM
894 dotsyms = 0;
895 break;
896
7d4c687d
AM
897 case OPTION_SAVRES:
898 params.save_restore_funcs = 1;
899 break;
900
901 case OPTION_NO_SAVRES:
902 params.save_restore_funcs = 0;
903 break;
904
e5096e3f 905 case OPTION_NO_TLS_OPT:
c5614fa4
AM
906 no_tls_opt = 1;
907 break;
908
7c9cf415
AM
909 case OPTION_TLS_GET_ADDR_OPT:
910 params.tls_get_addr_opt = 1;
911 break;
912
a7f2871e 913 case OPTION_NO_TLS_GET_ADDR_OPT:
7c9cf415 914 params.tls_get_addr_opt = 0;
a7f2871e
AM
915 break;
916
9e7028aa
AM
917 case OPTION_TLS_GET_ADDR_REGSAVE:
918 params.no_tls_get_addr_regsave = 0;
919 break;
920
921 case OPTION_NO_TLS_GET_ADDR_REGSAVE:
922 params.no_tls_get_addr_regsave = 1;
923 break;
924
c5614fa4
AM
925 case OPTION_NO_OPD_OPT:
926 no_opd_opt = 1;
927 break;
928
3e04d765
AM
929 case OPTION_NO_INLINE_OPT:
930 no_inline_opt = 1;
931 break;
932
c5614fa4
AM
933 case OPTION_NO_TOC_OPT:
934 no_toc_opt = 1;
fac1652d 935 break;
3f764659 936
4c52953f 937 case OPTION_NO_MULTI_TOC:
e7d1c40c 938 params.no_multi_toc = 1;
4c52953f
AM
939 break;
940
d43d0b53
AM
941 case OPTION_NO_TOC_SORT:
942 no_toc_sort = 1;
943 break;
944
3f764659 945 case OPTION_NON_OVERLAPPING_OPD:
e7d1c40c 946 params.non_overlapping_opd = 1;
3f764659 947 break;
f05eb3b7
AM
948
949 case OPTION_TRADITIONAL_FORMAT:
950 no_tls_opt = 1;
7c9cf415 951 params.tls_get_addr_opt = 0;
f05eb3b7
AM
952 no_opd_opt = 1;
953 no_toc_opt = 1;
e7d1c40c 954 params.no_multi_toc = 1;
f05eb3b7 955 no_toc_sort = 1;
e7d1c40c 956 params.plt_static_chain = 1;
f05eb3b7 957 return FALSE;
9c1d81c1
AM
958'
959
1f808cd5
AM
960# Put these extra ppc64elf routines in ld_${EMULATION_NAME}_emulation
961#
dbd1e97e
AM
962LDEMUL_NEW_VERS_PATTERN=gld${EMULATION_NAME}_new_vers_pattern
963LDEMUL_CREATE_OUTPUT_SECTION_STATEMENTS=ppc_create_output_section_statements
964LDEMUL_AFTER_OPEN=ppc_after_open
836c6af1 965LDEMUL_BEFORE_ALLOCATION=ppc_before_allocation
1f808cd5 966LDEMUL_AFTER_ALLOCATION=gld${EMULATION_NAME}_after_allocation
8ded5a0f 967LDEMUL_FINISH=gld${EMULATION_NAME}_finish
This page took 0.893562 seconds and 4 git commands to generate.