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