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