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