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