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