OLD | NEW |
1 /* IBM S/390-specific support for 32-bit ELF | 1 /* IBM S/390-specific support for 32-bit ELF |
2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, | 2 Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, |
3 2011 Free Software Foundation, Inc. | 3 2011, 2012 Free Software Foundation, Inc. |
4 Contributed by Carl B. Pedersen and Martin Schwidefsky. | 4 Contributed by Carl B. Pedersen and Martin Schwidefsky. |
5 | 5 |
6 This file is part of BFD, the Binary File Descriptor library. | 6 This file is part of BFD, the Binary File Descriptor library. |
7 | 7 |
8 This program is free software; you can redistribute it and/or modify | 8 This program is free software; you can redistribute it and/or modify |
9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
10 the Free Software Foundation; either version 3 of the License, or | 10 the Free Software Foundation; either version 3 of the License, or |
11 (at your option) any later version. | 11 (at your option) any later version. |
12 | 12 |
13 This program is distributed in the hope that it will be useful, | 13 This program is distributed in the hope that it will be useful, |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 GNU General Public License for more details. | 16 GNU General Public License for more details. |
17 | 17 |
18 You should have received a copy of the GNU General Public License | 18 You should have received a copy of the GNU General Public License |
19 along with this program; if not, write to the Free Software | 19 along with this program; if not, write to the Free Software |
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA | 20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
21 02110-1301, USA. */ | 21 02110-1301, USA. */ |
22 | 22 |
23 #include "sysdep.h" | 23 #include "sysdep.h" |
24 #include "bfd.h" | 24 #include "bfd.h" |
25 #include "bfdlink.h" | 25 #include "bfdlink.h" |
26 #include "libbfd.h" | 26 #include "libbfd.h" |
27 #include "elf-bfd.h" | 27 #include "elf-bfd.h" |
| 28 #include "elf/s390.h" |
28 | 29 |
29 static reloc_howto_type *elf_s390_reloc_type_lookup | 30 static bfd_reloc_status_type |
30 PARAMS ((bfd *, bfd_reloc_code_real_type)); | 31 s390_tls_reloc (bfd *, arelent *, asymbol *, void *, |
31 static void elf_s390_info_to_howto | 32 » » asection *, bfd *, char **); |
32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); | 33 static bfd_reloc_status_type |
33 static bfd_boolean elf_s390_is_local_label_name | 34 s390_elf_ldisp_reloc (bfd *, arelent *, asymbol *, void *, |
34 PARAMS ((bfd *, const char *)); | 35 » » asection *, bfd *, char **); |
35 static struct bfd_hash_entry *link_hash_newfunc | |
36 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); | |
37 static struct bfd_link_hash_table *elf_s390_link_hash_table_create | |
38 PARAMS ((bfd *)); | |
39 static bfd_boolean create_got_section | |
40 PARAMS((bfd *, struct bfd_link_info *)); | |
41 static bfd_boolean elf_s390_create_dynamic_sections | |
42 PARAMS((bfd *, struct bfd_link_info *)); | |
43 static void elf_s390_copy_indirect_symbol | |
44 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *, | |
45 » struct elf_link_hash_entry *)); | |
46 static bfd_boolean elf_s390_check_relocs | |
47 PARAMS ((bfd *, struct bfd_link_info *, asection *, | |
48 » const Elf_Internal_Rela *)); | |
49 struct elf_s390_link_hash_entry; | |
50 static void elf_s390_adjust_gotplt | |
51 PARAMS ((struct elf_s390_link_hash_entry *)); | |
52 static bfd_boolean elf_s390_adjust_dynamic_symbol | |
53 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); | |
54 static bfd_boolean allocate_dynrelocs | |
55 PARAMS ((struct elf_link_hash_entry *, PTR)); | |
56 static bfd_boolean readonly_dynrelocs | |
57 PARAMS ((struct elf_link_hash_entry *, PTR)); | |
58 static bfd_boolean elf_s390_size_dynamic_sections | |
59 PARAMS ((bfd *, struct bfd_link_info *)); | |
60 static bfd_boolean elf_s390_relocate_section | |
61 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, | |
62 » Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); | |
63 static bfd_boolean elf_s390_finish_dynamic_symbol | |
64 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, | |
65 » Elf_Internal_Sym *)); | |
66 static enum elf_reloc_type_class elf_s390_reloc_type_class | |
67 PARAMS ((const Elf_Internal_Rela *)); | |
68 static bfd_boolean elf_s390_finish_dynamic_sections | |
69 PARAMS ((bfd *, struct bfd_link_info *)); | |
70 static bfd_boolean elf_s390_object_p | |
71 PARAMS ((bfd *)); | |
72 static bfd_boolean elf_s390_grok_prstatus | |
73 PARAMS ((bfd *, Elf_Internal_Note *)); | |
74 static int elf_s390_tls_transition | |
75 PARAMS ((struct bfd_link_info *, int, int)); | |
76 static bfd_reloc_status_type s390_tls_reloc | |
77 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
78 static bfd_vma dtpoff_base | |
79 PARAMS ((struct bfd_link_info *)); | |
80 static bfd_vma tpoff | |
81 PARAMS ((struct bfd_link_info *, bfd_vma)); | |
82 static void invalid_tls_insn | |
83 PARAMS ((bfd *, asection *, Elf_Internal_Rela *)); | |
84 static bfd_reloc_status_type s390_elf_ldisp_reloc | |
85 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); | |
86 | |
87 #include "elf/s390.h" | |
88 | 36 |
89 /* The relocation "howto" table. */ | 37 /* The relocation "howto" table. */ |
90 | 38 |
91 static reloc_howto_type elf_howto_table[] = | 39 static reloc_howto_type elf_howto_table[] = |
92 { | 40 { |
93 HOWTO (R_390_NONE, /* type */ | 41 HOWTO (R_390_NONE, /* type */ |
94 0, /* rightshift */ | 42 0, /* rightshift */ |
95 0, /* size (0 = byte, 1 = short, 2 = long) */ | 43 0, /* size (0 = byte, 1 = short, 2 = long) */ |
96 0, /* bitsize */ | 44 0, /* bitsize */ |
97 FALSE, /* pc_relative */ | 45 FALSE, /* pc_relative */ |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 HOWTO(R_390_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, | 152 HOWTO(R_390_TLS_TPOFF, 0, 2, 32, FALSE, 0, complain_overflow_bitfield, |
205 bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, 0xffffffff, FALSE), | 153 bfd_elf_generic_reloc, "R_390_TLS_TPOFF", FALSE, 0, 0xffffffff, FALSE), |
206 HOWTO(R_390_20, 0, 2, 20, FALSE, 8, complain_overflow_dont, | 154 HOWTO(R_390_20, 0, 2, 20, FALSE, 8, complain_overflow_dont, |
207 s390_elf_ldisp_reloc, "R_390_20", FALSE, 0,0x0fffff00, FALSE), | 155 s390_elf_ldisp_reloc, "R_390_20", FALSE, 0,0x0fffff00, FALSE), |
208 HOWTO(R_390_GOT20, 0, 2, 20, FALSE, 8, complain_overflow_dont, | 156 HOWTO(R_390_GOT20, 0, 2, 20, FALSE, 8, complain_overflow_dont, |
209 s390_elf_ldisp_reloc, "R_390_GOT20", FALSE, 0,0x0fffff00, FALSE), | 157 s390_elf_ldisp_reloc, "R_390_GOT20", FALSE, 0,0x0fffff00, FALSE), |
210 HOWTO(R_390_GOTPLT20, 0, 2, 20, FALSE, 8, complain_overflow_dont, | 158 HOWTO(R_390_GOTPLT20, 0, 2, 20, FALSE, 8, complain_overflow_dont, |
211 s390_elf_ldisp_reloc, "R_390_GOTPLT20", FALSE, 0,0x0fffff00, FALSE), | 159 s390_elf_ldisp_reloc, "R_390_GOTPLT20", FALSE, 0,0x0fffff00, FALSE), |
212 HOWTO(R_390_TLS_GOTIE20, 0, 2, 20, FALSE, 8, complain_overflow_dont, | 160 HOWTO(R_390_TLS_GOTIE20, 0, 2, 20, FALSE, 8, complain_overflow_dont, |
213 s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", FALSE, 0,0x0fffff00, FALSE), | 161 s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", FALSE, 0,0x0fffff00, FALSE), |
| 162 HOWTO(R_390_IRELATIVE, 0, 2, 32, TRUE, 0, complain_overflow_bitfield, |
| 163 bfd_elf_generic_reloc, "R_390_IRELATIVE", FALSE, 0, 0xffffffff, FALSE), |
214 }; | 164 }; |
215 | 165 |
216 /* GNU extension to record C++ vtable hierarchy. */ | 166 /* GNU extension to record C++ vtable hierarchy. */ |
217 static reloc_howto_type elf32_s390_vtinherit_howto = | 167 static reloc_howto_type elf32_s390_vtinherit_howto = |
218 HOWTO (R_390_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_390
_GNU_VTINHERIT", FALSE,0, 0, FALSE); | 168 HOWTO (R_390_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_390
_GNU_VTINHERIT", FALSE,0, 0, FALSE); |
219 static reloc_howto_type elf32_s390_vtentry_howto = | 169 static reloc_howto_type elf32_s390_vtentry_howto = |
220 HOWTO (R_390_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_v
table_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE); | 170 HOWTO (R_390_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_v
table_reloc_fn,"R_390_GNU_VTENTRY", FALSE,0,0, FALSE); |
221 | 171 |
222 static reloc_howto_type * | 172 static reloc_howto_type * |
223 elf_s390_reloc_type_lookup (abfd, code) | 173 elf_s390_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, |
224 bfd *abfd ATTRIBUTE_UNUSED; | 174 » » » bfd_reloc_code_real_type code) |
225 bfd_reloc_code_real_type code; | |
226 { | 175 { |
227 switch (code) | 176 switch (code) |
228 { | 177 { |
229 case BFD_RELOC_NONE: | 178 case BFD_RELOC_NONE: |
230 return &elf_howto_table[(int) R_390_NONE]; | 179 return &elf_howto_table[(int) R_390_NONE]; |
231 case BFD_RELOC_8: | 180 case BFD_RELOC_8: |
232 return &elf_howto_table[(int) R_390_8]; | 181 return &elf_howto_table[(int) R_390_8]; |
233 case BFD_RELOC_390_12: | 182 case BFD_RELOC_390_12: |
234 return &elf_howto_table[(int) R_390_12]; | 183 return &elf_howto_table[(int) R_390_12]; |
235 case BFD_RELOC_16: | 184 case BFD_RELOC_16: |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 case BFD_RELOC_390_TLS_TPOFF: | 266 case BFD_RELOC_390_TLS_TPOFF: |
318 return &elf_howto_table[(int) R_390_TLS_TPOFF]; | 267 return &elf_howto_table[(int) R_390_TLS_TPOFF]; |
319 case BFD_RELOC_390_20: | 268 case BFD_RELOC_390_20: |
320 return &elf_howto_table[(int) R_390_20]; | 269 return &elf_howto_table[(int) R_390_20]; |
321 case BFD_RELOC_390_GOT20: | 270 case BFD_RELOC_390_GOT20: |
322 return &elf_howto_table[(int) R_390_GOT20]; | 271 return &elf_howto_table[(int) R_390_GOT20]; |
323 case BFD_RELOC_390_GOTPLT20: | 272 case BFD_RELOC_390_GOTPLT20: |
324 return &elf_howto_table[(int) R_390_GOTPLT20]; | 273 return &elf_howto_table[(int) R_390_GOTPLT20]; |
325 case BFD_RELOC_390_TLS_GOTIE20: | 274 case BFD_RELOC_390_TLS_GOTIE20: |
326 return &elf_howto_table[(int) R_390_TLS_GOTIE20]; | 275 return &elf_howto_table[(int) R_390_TLS_GOTIE20]; |
| 276 case BFD_RELOC_390_IRELATIVE: |
| 277 return &elf_howto_table[(int) R_390_IRELATIVE]; |
327 case BFD_RELOC_VTABLE_INHERIT: | 278 case BFD_RELOC_VTABLE_INHERIT: |
328 return &elf32_s390_vtinherit_howto; | 279 return &elf32_s390_vtinherit_howto; |
329 case BFD_RELOC_VTABLE_ENTRY: | 280 case BFD_RELOC_VTABLE_ENTRY: |
330 return &elf32_s390_vtentry_howto; | 281 return &elf32_s390_vtentry_howto; |
331 default: | 282 default: |
332 break; | 283 break; |
333 } | 284 } |
334 return 0; | 285 return 0; |
335 } | 286 } |
336 | 287 |
(...skipping 13 matching lines...) Expand all Loading... |
350 if (strcasecmp (elf32_s390_vtentry_howto.name, r_name) == 0) | 301 if (strcasecmp (elf32_s390_vtentry_howto.name, r_name) == 0) |
351 return &elf32_s390_vtentry_howto; | 302 return &elf32_s390_vtentry_howto; |
352 | 303 |
353 return NULL; | 304 return NULL; |
354 } | 305 } |
355 | 306 |
356 /* We need to use ELF32_R_TYPE so we have our own copy of this function, | 307 /* We need to use ELF32_R_TYPE so we have our own copy of this function, |
357 and elf32-s390.c has its own copy. */ | 308 and elf32-s390.c has its own copy. */ |
358 | 309 |
359 static void | 310 static void |
360 elf_s390_info_to_howto (abfd, cache_ptr, dst) | 311 elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, |
361 bfd *abfd ATTRIBUTE_UNUSED; | 312 » » » arelent *cache_ptr, |
362 arelent *cache_ptr; | 313 » » » Elf_Internal_Rela *dst) |
363 Elf_Internal_Rela *dst; | |
364 { | 314 { |
365 unsigned int r_type = ELF32_R_TYPE(dst->r_info); | 315 unsigned int r_type = ELF32_R_TYPE(dst->r_info); |
366 switch (r_type) | 316 switch (r_type) |
367 { | 317 { |
368 case R_390_GNU_VTINHERIT: | 318 case R_390_GNU_VTINHERIT: |
369 cache_ptr->howto = &elf32_s390_vtinherit_howto; | 319 cache_ptr->howto = &elf32_s390_vtinherit_howto; |
370 break; | 320 break; |
371 | 321 |
372 case R_390_GNU_VTENTRY: | 322 case R_390_GNU_VTENTRY: |
373 cache_ptr->howto = &elf32_s390_vtentry_howto; | 323 cache_ptr->howto = &elf32_s390_vtentry_howto; |
374 break; | 324 break; |
375 | 325 |
376 default: | 326 default: |
377 if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0])) | 327 if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0])) |
378 { | 328 { |
379 (*_bfd_error_handler) (_("%B: invalid relocation type %d"), | 329 (*_bfd_error_handler) (_("%B: invalid relocation type %d"), |
380 abfd, (int) r_type); | 330 abfd, (int) r_type); |
381 r_type = R_390_NONE; | 331 r_type = R_390_NONE; |
382 } | 332 } |
383 cache_ptr->howto = &elf_howto_table[r_type]; | 333 cache_ptr->howto = &elf_howto_table[r_type]; |
384 } | 334 } |
385 } | 335 } |
386 | 336 |
387 /* A relocation function which doesn't do anything. */ | 337 /* A relocation function which doesn't do anything. */ |
388 static bfd_reloc_status_type | 338 static bfd_reloc_status_type |
389 s390_tls_reloc (abfd, reloc_entry, symbol, data, input_section, | 339 s390_tls_reloc (bfd *abfd ATTRIBUTE_UNUSED, |
390 » » output_bfd, error_message) | 340 » » arelent *reloc_entry, |
391 bfd *abfd ATTRIBUTE_UNUSED; | 341 » » asymbol *symbol ATTRIBUTE_UNUSED, |
392 arelent *reloc_entry; | 342 » » void * data ATTRIBUTE_UNUSED, |
393 asymbol *symbol ATTRIBUTE_UNUSED; | 343 » » asection *input_section, |
394 PTR data ATTRIBUTE_UNUSED; | 344 » » bfd *output_bfd, |
395 asection *input_section; | 345 » » char **error_message ATTRIBUTE_UNUSED) |
396 bfd *output_bfd; | |
397 char **error_message ATTRIBUTE_UNUSED; | |
398 { | 346 { |
399 if (output_bfd) | 347 if (output_bfd) |
400 reloc_entry->address += input_section->output_offset; | 348 reloc_entry->address += input_section->output_offset; |
401 return bfd_reloc_ok; | 349 return bfd_reloc_ok; |
402 } | 350 } |
403 | 351 |
404 /* Handle the large displacement relocs. */ | 352 /* Handle the large displacement relocs. */ |
405 static bfd_reloc_status_type | 353 static bfd_reloc_status_type |
406 s390_elf_ldisp_reloc (abfd, reloc_entry, symbol, data, input_section, | 354 s390_elf_ldisp_reloc (bfd *abfd ATTRIBUTE_UNUSED, |
407 output_bfd, error_message) | 355 » » arelent *reloc_entry, |
408 bfd *abfd ATTRIBUTE_UNUSED; | 356 » » asymbol *symbol, |
409 arelent *reloc_entry; | 357 » » void * data ATTRIBUTE_UNUSED, |
410 asymbol *symbol; | 358 » » asection *input_section, |
411 PTR data ATTRIBUTE_UNUSED; | 359 » » bfd *output_bfd, |
412 asection *input_section; | 360 » » char **error_message ATTRIBUTE_UNUSED) |
413 bfd *output_bfd; | |
414 char **error_message ATTRIBUTE_UNUSED; | |
415 { | 361 { |
416 reloc_howto_type *howto = reloc_entry->howto; | 362 reloc_howto_type *howto = reloc_entry->howto; |
417 bfd_vma relocation; | 363 bfd_vma relocation; |
418 bfd_vma insn; | 364 bfd_vma insn; |
419 | 365 |
420 if (output_bfd != (bfd *) NULL | 366 if (output_bfd != (bfd *) NULL |
421 && (symbol->flags & BSF_SECTION_SYM) == 0 | 367 && (symbol->flags & BSF_SECTION_SYM) == 0 |
422 && (! howto->partial_inplace | 368 && (! howto->partial_inplace |
423 || reloc_entry->addend == 0)) | 369 || reloc_entry->addend == 0)) |
424 { | 370 { |
(...skipping 23 matching lines...) Expand all Loading... |
448 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); | 394 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); |
449 | 395 |
450 if ((bfd_signed_vma) relocation < - 0x80000 | 396 if ((bfd_signed_vma) relocation < - 0x80000 |
451 || (bfd_signed_vma) relocation > 0x7ffff) | 397 || (bfd_signed_vma) relocation > 0x7ffff) |
452 return bfd_reloc_overflow; | 398 return bfd_reloc_overflow; |
453 else | 399 else |
454 return bfd_reloc_ok; | 400 return bfd_reloc_ok; |
455 } | 401 } |
456 | 402 |
457 static bfd_boolean | 403 static bfd_boolean |
458 elf_s390_is_local_label_name (abfd, name) | 404 elf_s390_is_local_label_name (bfd *abfd, const char *name) |
459 bfd *abfd; | |
460 const char *name; | |
461 { | 405 { |
462 if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L')) | 406 if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L')) |
463 return TRUE; | 407 return TRUE; |
464 | 408 |
465 return _bfd_elf_is_local_label_name (abfd, name); | 409 return _bfd_elf_is_local_label_name (abfd, name); |
466 } | 410 } |
467 | 411 |
468 /* Functions for the 390 ELF linker. */ | 412 /* Functions for the 390 ELF linker. */ |
469 | 413 |
470 /* The name of the dynamic interpreter. This is put in the .interp | 414 /* The name of the dynamic interpreter. This is put in the .interp |
471 section. */ | 415 section. */ |
472 | 416 |
473 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1" | 417 #define ELF_DYNAMIC_INTERPRETER "/lib/ld.so.1" |
474 | 418 |
475 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid | 419 /* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid |
476 copying dynamic variables from a shared lib into an app's dynbss | 420 copying dynamic variables from a shared lib into an app's dynbss |
477 section, and instead use a dynamic relocation to point into the | 421 section, and instead use a dynamic relocation to point into the |
478 shared lib. */ | 422 shared lib. */ |
479 #define ELIMINATE_COPY_RELOCS 1 | 423 #define ELIMINATE_COPY_RELOCS 1 |
480 | 424 |
481 /* The size in bytes of the first entry in the procedure linkage table. */ | 425 /* The size in bytes of the first entry in the procedure linkage table. */ |
482 #define PLT_FIRST_ENTRY_SIZE 32 | 426 #define PLT_FIRST_ENTRY_SIZE 32 |
483 /* The size in bytes of an entry in the procedure linkage table. */ | 427 /* The size in bytes of an entry in the procedure linkage table. */ |
484 #define PLT_ENTRY_SIZE 32 | 428 #define PLT_ENTRY_SIZE 32 |
485 | 429 |
486 #define GOT_ENTRY_SIZE 4 | 430 #define GOT_ENTRY_SIZE 4 |
487 | 431 |
| 432 #define RELA_ENTRY_SIZE sizeof (Elf32_External_Rela) |
| 433 |
488 /* The first three entries in a procedure linkage table are reserved, | 434 /* The first three entries in a procedure linkage table are reserved, |
489 and the initial contents are unimportant (we zero them out). | 435 and the initial contents are unimportant (we zero them out). |
490 Subsequent entries look like this. See the SVR4 ABI 386 | 436 Subsequent entries look like this. See the SVR4 ABI 386 |
491 supplement to see how this works. */ | 437 supplement to see how this works. */ |
492 | 438 |
493 /* For the s390, simple addr offset can only be 0 - 4096. | 439 /* For the s390, simple addr offset can only be 0 - 4096. |
494 To use the full 2 GB address space, several instructions | 440 To use the full 2 GB address space, several instructions |
495 are needed to load an address in a register and execute | 441 are needed to load an address in a register and execute |
496 a branch( or just saving the address) | 442 a branch( or just saving the address) |
497 | 443 |
498 Furthermore, only r 0 and 1 are free to use!!! */ | 444 Furthermore, only r 0 and 1 are free to use!!! */ |
499 | 445 |
500 /* The first 3 words in the GOT are then reserved. | 446 /* The first 3 words in the GOT are then reserved. |
501 Word 0 is the address of the dynamic table. | 447 Word 0 is the address of the dynamic table. |
502 Word 1 is a pointer to a structure describing the object | 448 Word 1 is a pointer to a structure describing the object |
503 Word 2 is used to point to the loader entry address. | 449 Word 2 is used to point to the loader entry address. |
504 | 450 |
505 The code for position independent PLT entries looks like this: | 451 The code for position independent PLT entries looks like this: |
506 | 452 |
507 r12 holds addr of the current GOT at entry to the PLT | 453 r12 holds addr of the current GOT at entry to the PLT |
508 | 454 |
509 The GOT holds the address in the PLT to be executed. | 455 The GOT holds the address in the PLT to be executed. |
510 The loader then gets: | 456 The loader then gets: |
511 24(15) = Pointer to the structure describing the object. | 457 24(15) = Pointer to the structure describing the object. |
512 28(15) = Offset in symbol table | 458 28(15) = Offset into rela.plt |
513 | 459 |
514 The loader must then find the module where the function is | 460 The loader must then find the module where the function is |
515 and insert the address in the GOT. | 461 and insert the address in the GOT. |
516 | 462 |
517 Note: 390 can only address +- 64 K relative. | 463 Note: 390 can only address +- 64 K relative. |
518 We check if offset > 65536, then make a relative branch -64xxx | 464 We check if offset > 65536, then make a relative branch -64xxx |
519 back to a previous defined branch | 465 back to a previous defined branch |
520 | 466 |
521 PLT1: BASR 1,0 # 2 bytes | 467 PLT1: BASR 1,0 # 2 bytes |
522 L 1,22(1) # 4 bytes Load offset in GOT in r 1 | 468 L 1,22(1) # 4 bytes Load offset in GOT in r 1 |
523 L 1,(1,12) # 4 bytes Load address from GOT in r1 | 469 L 1,(1,12) # 4 bytes Load address from GOT in r1 |
524 BCR 15,1 # 2 bytes Jump to address | 470 BCR 15,1 # 2 bytes Jump to address |
525 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | 471 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
526 L 1,14(1) # 4 bytes Load offset in symol table in r1 | 472 L 1,14(1) # 4 bytes Load offset in symol table in r1 |
527 BRC 15,-x # 4 bytes Jump to start of PLT | 473 BRC 15,-x # 4 bytes Jump to start of PLT |
528 .word 0 # 2 bytes filler | 474 .word 0 # 2 bytes filler |
529 .long ? # 4 bytes offset in GOT | 475 .long ? # 4 bytes offset in GOT |
530 .long ? # 4 bytes offset into symbol table | 476 .long ? # 4 bytes offset into rela.plt |
531 | 477 |
532 This was the general case. There are two additional, optimizes PLT | 478 This was the general case. There are two additional, optimizes PLT |
533 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768. | 479 definitions. One for GOT offsets < 4096 and one for GOT offsets < 32768. |
534 First the one for GOT offsets < 4096: | 480 First the one for GOT offsets < 4096: |
535 | 481 |
536 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1 | 482 PLT1: L 1,<offset>(12) # 4 bytes Load address from GOT in R1 |
537 BCR 15,1 # 2 bytes Jump to address | 483 BCR 15,1 # 2 bytes Jump to address |
538 .word 0,0,0 # 6 bytes filler | 484 .word 0,0,0 # 6 bytes filler |
539 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | 485 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
540 L 1,14(1) # 4 bytes Load offset in symbol table in r1 | 486 L 1,14(1) # 4 bytes Load offset in rela.plt in r1 |
541 BRC 15,-x # 4 bytes Jump to start of PLT | 487 BRC 15,-x # 4 bytes Jump to start of PLT |
542 .word 0,0,0 # 6 bytes filler | 488 .word 0,0,0 # 6 bytes filler |
543 .long ? # 4 bytes offset into symbol table | 489 .long ? # 4 bytes offset into rela.plt |
544 | 490 |
545 Second the one for GOT offsets < 32768: | 491 Second the one for GOT offsets < 32768: |
546 | 492 |
547 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1 | 493 PLT1: LHI 1,<offset> # 4 bytes Load offset in GOT to r1 |
548 L 1,(1,12) # 4 bytes Load address from GOT to r1 | 494 L 1,(1,12) # 4 bytes Load address from GOT to r1 |
549 BCR 15,1 # 2 bytes Jump to address | 495 BCR 15,1 # 2 bytes Jump to address |
550 .word 0 # 2 bytes filler | 496 .word 0 # 2 bytes filler |
551 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | 497 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
552 L 1,14(1) # 4 bytes Load offset in symbol table in r1 | 498 L 1,14(1) # 4 bytes Load offset in rela.plt in r1 |
553 BRC 15,-x # 4 bytes Jump to start of PLT | 499 BRC 15,-x # 4 bytes Jump to start of PLT |
554 .word 0,0,0 # 6 bytes filler | 500 .word 0,0,0 # 6 bytes filler |
555 .long ? # 4 bytes offset into symbol table | 501 .long ? # 4 bytes offset into rela.plt |
556 | 502 |
557 Total = 32 bytes per PLT entry | 503 Total = 32 bytes per PLT entry |
558 | 504 |
559 The code for static build PLT entries looks like this: | 505 The code for static build PLT entries looks like this: |
560 | 506 |
561 PLT1: BASR 1,0 # 2 bytes | 507 PLT1: BASR 1,0 # 2 bytes |
562 L 1,22(1) # 4 bytes Load address of GOT entry | 508 L 1,22(1) # 4 bytes Load address of GOT entry |
563 L 1,0(0,1) # 4 bytes Load address from GOT in r1 | 509 L 1,0(0,1) # 4 bytes Load address from GOT in r1 |
564 BCR 15,1 # 2 bytes Jump to address | 510 BCR 15,1 # 2 bytes Jump to address |
565 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time | 511 RET1: BASR 1,0 # 2 bytes Return from GOT 1st time |
566 L 1,14(1) # 4 bytes Load offset in symbol table in r1 | 512 L 1,14(1) # 4 bytes Load offset in symbol table in r1 |
567 BRC 15,-x # 4 bytes Jump to start of PLT | 513 BRC 15,-x # 4 bytes Jump to start of PLT |
568 .word 0 # 2 bytes filler | 514 .word 0 # 2 bytes filler |
569 .long ? # 4 bytes address of GOT entry | 515 .long ? # 4 bytes address of GOT entry |
570 .long ? # 4 bytes offset into symbol table */ | 516 .long ? # 4 bytes offset into rela.plt */ |
571 | 517 |
572 #define PLT_PIC_ENTRY_WORD0 0x0d105810 | 518 static const bfd_byte elf_s390_plt_entry[PLT_ENTRY_SIZE] = |
573 #define PLT_PIC_ENTRY_WORD1 0x10165811 | 519 { |
574 #define PLT_PIC_ENTRY_WORD2 0xc00007f1 | 520 0x0d, 0x10, /* basr %r1,%r0 */ |
575 #define PLT_PIC_ENTRY_WORD3 0x0d105810 | 521 0x58, 0x10, 0x10, 0x16, /* l %r1,22(%r1) */ |
576 #define PLT_PIC_ENTRY_WORD4 0x100ea7f4 | 522 0x58, 0x10, 0x10, 0x00, /* l %r1,0(%r1) */ |
| 523 0x07, 0xf1, /* br %r1 */ |
| 524 0x0d, 0x10, /* basr %r1,%r0 */ |
| 525 0x58, 0x10, 0x10, 0x0e, /* l %r1,14(%r1) */ |
| 526 0xa7, 0xf4, 0x00, 0x00, /* j first plt */ |
| 527 0x00, 0x00, /* padding */ |
| 528 0x00, 0x00, 0x00, 0x00, /* GOT offset */ |
| 529 0x00, 0x00, 0x00, 0x00 /* rela.plt offset */ |
| 530 }; |
577 | 531 |
578 #define PLT_PIC12_ENTRY_WORD0 0x5810c000 | 532 /* Generic PLT pic entry. */ |
579 #define PLT_PIC12_ENTRY_WORD1 0x07f10000 | 533 static const bfd_byte elf_s390_plt_pic_entry[PLT_ENTRY_SIZE] = |
580 #define PLT_PIC12_ENTRY_WORD2 0x00000000 | 534 { |
581 #define PLT_PIC12_ENTRY_WORD3 0x0d105810 | 535 0x0d, 0x10, /* basr %r1,%r0 */ |
582 #define PLT_PIC12_ENTRY_WORD4 0x100ea7f4 | 536 0x58, 0x10, 0x10, 0x16, /* l %r1,22(%r1) */ |
| 537 0x58, 0x11, 0xc0, 0x00, /* l %r1,0(%r1,%r12) */ |
| 538 0x07, 0xf1, /* br %r1 */ |
| 539 0x0d, 0x10, /* basr %r1,%r0 */ |
| 540 0x58, 0x10, 0x10, 0x0e, /* l %r1,14(%r1) */ |
| 541 0xa7, 0xf4, 0x00, 0x00, /* j first plt */ |
| 542 0x00, 0x00, /* padding */ |
| 543 0x00, 0x00, 0x00, 0x00, /* GOT offset */ |
| 544 0x00, 0x00, 0x00, 0x00 /* rela.plt offset */ |
| 545 }; |
583 | 546 |
584 #define PLT_PIC16_ENTRY_WORD0 0xa7180000 | 547 /* Optimized PLT pic entry for GOT offset < 4k. xx will be replaced |
585 #define PLT_PIC16_ENTRY_WORD1 0x5811c000 | 548 when generating the PLT slot with the GOT offset. */ |
586 #define PLT_PIC16_ENTRY_WORD2 0x07f10000 | 549 static const bfd_byte elf_s390_plt_pic12_entry[PLT_ENTRY_SIZE] = |
587 #define PLT_PIC16_ENTRY_WORD3 0x0d105810 | 550 { |
588 #define PLT_PIC16_ENTRY_WORD4 0x100ea7f4 | 551 0x58, 0x10, 0xc0, 0x00, /* l %r1,xx(%r12) */ |
| 552 0x07, 0xf1, /* br %r1 */ |
| 553 0x00, 0x00, 0x00, 0x00, /* padding */ |
| 554 0x00, 0x00, |
| 555 0x0d, 0x10, /* basr %r1,%r0 */ |
| 556 0x58, 0x10, 0x10, 0x0e, /* l %r1,14(%r1) */ |
| 557 0xa7, 0xf4, 0x00, 0x00, /* j first plt */ |
| 558 0x00, 0x00, 0x00, 0x00, |
| 559 0x00, 0x00, 0x00, 0x00 |
| 560 }; |
589 | 561 |
590 #define PLT_ENTRY_WORD0 0x0d105810 | 562 /* Optimized PLT pic entry for GOT offset < 32k. xx will be replaced |
591 #define PLT_ENTRY_WORD1 0x10165810 | 563 when generating the PLT slot with the GOT offset. */ |
592 #define PLT_ENTRY_WORD2 0x100007f1 | 564 static const bfd_byte elf_s390_plt_pic16_entry[PLT_ENTRY_SIZE] = |
593 #define PLT_ENTRY_WORD3 0x0d105810 | 565 { |
594 #define PLT_ENTRY_WORD4 0x100ea7f4 | 566 0xa7, 0x18, 0x00, 0x00, /* lhi %r1,xx */ |
| 567 0x58, 0x11, 0xc0, 0x00, /* l %r1,0(%r1,%r12) */ |
| 568 0x07, 0xf1, /* br %r1 */ |
| 569 0x00, 0x00, |
| 570 0x0d, 0x10, /* basr %r1,%r0 */ |
| 571 0x58, 0x10, 0x10, 0x0e, /* l %r1,14(%r1) */ |
| 572 0xa7, 0xf4, 0x00, 0x00, /* j first plt */ |
| 573 0x00, 0x00, 0x00, 0x00, |
| 574 0x00, 0x00, 0x00, 0x00, |
| 575 0x00, 0x00 |
| 576 }; |
595 | 577 |
596 /* The first PLT entry pushes the offset into the symbol table | 578 /* The first PLT entry pushes the offset into the rela.plt |
597 from R1 onto the stack at 8(15) and the loader object info | 579 from R1 onto the stack at 8(15) and the loader object info |
598 at 12(15), loads the loader address in R1 and jumps to it. */ | 580 at 12(15), loads the loader address in R1 and jumps to it. */ |
599 | 581 |
600 /* The first entry in the PLT for PIC code: | 582 /* The first entry in the PLT for PIC code: |
601 | 583 |
602 PLT0: | 584 PLT0: |
603 ST 1,28(15) # R1 has offset into symbol table | 585 ST 1,28(15) # R1 has offset into rela.plt |
604 L 1,4(12) # Get loader ino(object struct address) | 586 L 1,4(12) # Get loader ino(object struct address) |
605 ST 1,24(15) # Store address | 587 ST 1,24(15) # Store address |
606 L 1,8(12) # Entry address of loader in R1 | 588 L 1,8(12) # Entry address of loader in R1 |
607 BR 1 # Jump to loader | 589 BR 1 # Jump to loader |
608 | 590 |
609 The first entry in the PLT for static code: | 591 The first entry in the PLT for static code: |
610 | 592 |
611 PLT0: | 593 PLT0: |
612 ST 1,28(15) # R1 has offset into symbol table | 594 ST 1,28(15) # R1 has offset into rela.plt |
613 BASR 1,0 | 595 BASR 1,0 |
614 L 1,18(0,1) # Get address of GOT | 596 L 1,18(0,1) # Get address of GOT |
615 MVC 24(4,15),4(1) # Move loader ino to stack | 597 MVC 24(4,15),4(1) # Move loader ino to stack |
616 L 1,8(1) # Get address of loader | 598 L 1,8(1) # Get address of loader |
617 BR 1 # Jump to loader | 599 BR 1 # Jump to loader |
618 .word 0 # filler | 600 .word 0 # filler |
619 .long got # address of GOT */ | 601 .long got # address of GOT */ |
620 | 602 |
621 #define PLT_PIC_FIRST_ENTRY_WORD0 0x5010f01c | 603 static const bfd_byte elf_s390_plt_first_entry[PLT_FIRST_ENTRY_SIZE] = |
622 #define PLT_PIC_FIRST_ENTRY_WORD1 0x5810c004 | 604 { |
623 #define PLT_PIC_FIRST_ENTRY_WORD2 0x5010f018 | 605 0x50, 0x10, 0xf0, 0x1c, /* st %r1,28(%r15) */ |
624 #define PLT_PIC_FIRST_ENTRY_WORD3 0x5810c008 | 606 0x0d, 0x10, /* basr %r1,%r0 */ |
625 #define PLT_PIC_FIRST_ENTRY_WORD4 0x07f10000 | 607 0x58, 0x10, 0x10, 0x12, /* l %r1,18(%r1) */ |
| 608 0xd2, 0x03, 0xf0, 0x18, 0x10, 0x04, /* mvc 24(4,%r15),4(%r1) */ |
| 609 0x58, 0x10, 0x10, 0x08, /* l %r1,8(%r1) */ |
| 610 0x07, 0xf1, /* br %r1 */ |
| 611 0x00, 0x00, 0x00, 0x00, |
| 612 0x00, 0x00, 0x00, 0x00, |
| 613 0x00, 0x00 |
| 614 }; |
626 | 615 |
627 #define PLT_FIRST_ENTRY_WORD0 0x5010f01c | 616 static const bfd_byte elf_s390_plt_pic_first_entry[PLT_FIRST_ENTRY_SIZE] = |
628 #define PLT_FIRST_ENTRY_WORD1 0x0d105810 | 617 { |
629 #define PLT_FIRST_ENTRY_WORD2 0x1012D203 | 618 0x50, 0x10, 0xf0, 0x1c, /* st %r1,28(%r15) */ |
630 #define PLT_FIRST_ENTRY_WORD3 0xf0181004 | 619 0x58, 0x10, 0xc0, 0x04, /* l %r1,4(%r12) */ |
631 #define PLT_FIRST_ENTRY_WORD4 0x58101008 | 620 0x50, 0x10, 0xf0, 0x18, /* st %r1,24(%r15) */ |
632 #define PLT_FIRST_ENTRY_WORD5 0x07f10000 | 621 0x58, 0x10, 0xc0, 0x08, /* l %r1,8(%r12) */ |
| 622 0x07, 0xf1, /* br %r1 */ |
| 623 0x00, 0x00, 0x00, 0x00, |
| 624 0x00, 0x00, 0x00, 0x00, |
| 625 0x00, 0x00, 0x00, 0x00, |
| 626 0x00, 0x00 |
| 627 }; |
633 | 628 |
634 /* The s390 linker needs to keep track of the number of relocs that it | |
635 decides to copy as dynamic relocs in check_relocs for each symbol. | |
636 This is so that it can later discard them if they are found to be | |
637 unnecessary. We store the information in a field extending the | |
638 regular ELF linker hash table. */ | |
639 | |
640 struct elf_s390_dyn_relocs | |
641 { | |
642 struct elf_s390_dyn_relocs *next; | |
643 | |
644 /* The input section of the reloc. */ | |
645 asection *sec; | |
646 | |
647 /* Total number of relocs copied for the input section. */ | |
648 bfd_size_type count; | |
649 | |
650 /* Number of pc-relative relocs copied for the input section. */ | |
651 bfd_size_type pc_count; | |
652 }; | |
653 | 629 |
654 /* s390 ELF linker hash entry. */ | 630 /* s390 ELF linker hash entry. */ |
655 | 631 |
656 struct elf_s390_link_hash_entry | 632 struct elf_s390_link_hash_entry |
657 { | 633 { |
658 struct elf_link_hash_entry elf; | 634 struct elf_link_hash_entry elf; |
659 | 635 |
660 /* Track dynamic relocs copied for this symbol. */ | 636 /* Track dynamic relocs copied for this symbol. */ |
661 struct elf_s390_dyn_relocs *dyn_relocs; | 637 struct elf_dyn_relocs *dyn_relocs; |
662 | 638 |
663 /* Number of GOTPLT references for a function. */ | 639 /* Number of GOTPLT references for a function. */ |
664 bfd_signed_vma gotplt_refcount; | 640 bfd_signed_vma gotplt_refcount; |
665 | 641 |
666 #define GOT_UNKNOWN 0 | 642 #define GOT_UNKNOWN 0 |
667 #define GOT_NORMAL 1 | 643 #define GOT_NORMAL 1 |
668 #define GOT_TLS_GD 2 | 644 #define GOT_TLS_GD 2 |
669 #define GOT_TLS_IE 3 | 645 #define GOT_TLS_IE 3 |
670 #define GOT_TLS_IE_NLT 4 | 646 #define GOT_TLS_IE_NLT 4 |
671 unsigned char tls_type; | 647 unsigned char tls_type; |
| 648 |
| 649 /* For pointer equality reasons we might need to change the symbol |
| 650 type from STT_GNU_IFUNC to STT_FUNC together with its value and |
| 651 section entry. So after alloc_dynrelocs only these values should |
| 652 be used. In order to check whether a symbol is IFUNC use |
| 653 s390_is_ifunc_symbol_p. */ |
| 654 bfd_vma ifunc_resolver_address; |
| 655 asection *ifunc_resolver_section; |
672 }; | 656 }; |
673 | 657 |
674 #define elf_s390_hash_entry(ent) \ | 658 #define elf_s390_hash_entry(ent) \ |
675 ((struct elf_s390_link_hash_entry *)(ent)) | 659 ((struct elf_s390_link_hash_entry *)(ent)) |
676 | 660 |
| 661 /* This structure represents an entry in the local PLT list needed for |
| 662 local IFUNC symbols. */ |
| 663 struct plt_entry |
| 664 { |
| 665 /* The section of the local symbol. |
| 666 Set in relocate_section and used in finish_dynamic_sections. */ |
| 667 asection *sec; |
| 668 |
| 669 union |
| 670 { |
| 671 bfd_signed_vma refcount; |
| 672 bfd_vma offset; |
| 673 } plt; |
| 674 }; |
| 675 |
677 /* NOTE: Keep this structure in sync with | 676 /* NOTE: Keep this structure in sync with |
678 the one declared in elf64-s390.c. */ | 677 the one declared in elf64-s390.c. */ |
679 struct elf_s390_obj_tdata | 678 struct elf_s390_obj_tdata |
680 { | 679 { |
681 struct elf_obj_tdata root; | 680 struct elf_obj_tdata root; |
682 | 681 |
| 682 /* A local PLT is needed for ifunc symbols. */ |
| 683 struct plt_entry *local_plt; |
| 684 |
683 /* TLS type for each local got entry. */ | 685 /* TLS type for each local got entry. */ |
684 char *local_got_tls_type; | 686 char *local_got_tls_type; |
685 }; | 687 }; |
686 | 688 |
687 #define elf_s390_tdata(abfd) \ | 689 #define elf_s390_tdata(abfd) \ |
688 ((struct elf_s390_obj_tdata *) (abfd)->tdata.any) | 690 ((struct elf_s390_obj_tdata *) (abfd)->tdata.any) |
689 | 691 |
| 692 #define elf_s390_local_plt(abfd) \ |
| 693 (elf_s390_tdata (abfd)->local_plt) |
| 694 |
690 #define elf_s390_local_got_tls_type(abfd) \ | 695 #define elf_s390_local_got_tls_type(abfd) \ |
691 (elf_s390_tdata (abfd)->local_got_tls_type) | 696 (elf_s390_tdata (abfd)->local_got_tls_type) |
692 | 697 |
693 #define is_s390_elf(bfd) \ | 698 #define is_s390_elf(bfd) \ |
694 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ | 699 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \ |
695 && elf_tdata (bfd) != NULL \ | 700 && elf_tdata (bfd) != NULL \ |
696 && elf_object_id (bfd) == S390_ELF_DATA) | 701 && elf_object_id (bfd) == S390_ELF_DATA) |
697 | 702 |
698 static bfd_boolean | 703 static bfd_boolean |
699 elf_s390_mkobject (bfd *abfd) | 704 elf_s390_mkobject (bfd *abfd) |
700 { | 705 { |
701 return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), | 706 return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata), |
702 S390_ELF_DATA); | 707 S390_ELF_DATA); |
703 } | 708 } |
704 | 709 |
705 static bfd_boolean | 710 static bfd_boolean |
706 elf_s390_object_p (abfd) | 711 elf_s390_object_p (bfd *abfd) |
707 bfd *abfd; | |
708 { | 712 { |
709 /* Set the right machine number for an s390 elf32 file. */ | 713 /* Set the right machine number for an s390 elf32 file. */ |
710 return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31); | 714 return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_31); |
711 } | 715 } |
712 | 716 |
713 /* s390 ELF linker hash table. */ | 717 /* s390 ELF linker hash table. */ |
714 | 718 |
715 struct elf_s390_link_hash_table | 719 struct elf_s390_link_hash_table |
716 { | 720 { |
717 struct elf_link_hash_table elf; | 721 struct elf_link_hash_table elf; |
718 | 722 |
719 /* Short-cuts to get to dynamic linker sections. */ | 723 /* Short-cuts to get to dynamic linker sections. */ |
720 asection *sgot; | |
721 asection *sgotplt; | |
722 asection *srelgot; | |
723 asection *splt; | |
724 asection *srelplt; | |
725 asection *sdynbss; | 724 asection *sdynbss; |
726 asection *srelbss; | 725 asection *srelbss; |
| 726 asection *irelifunc; |
727 | 727 |
728 union { | 728 union |
| 729 { |
729 bfd_signed_vma refcount; | 730 bfd_signed_vma refcount; |
730 bfd_vma offset; | 731 bfd_vma offset; |
731 } tls_ldm_got; | 732 } tls_ldm_got; |
732 | 733 |
733 /* Small local sym cache. */ | 734 /* Small local sym cache. */ |
734 struct sym_cache sym_cache; | 735 struct sym_cache sym_cache; |
735 }; | 736 }; |
736 | 737 |
737 /* Get the s390 ELF linker hash table from a link_info structure. */ | 738 /* Get the s390 ELF linker hash table from a link_info structure. */ |
738 | 739 |
739 #define elf_s390_hash_table(p) \ | 740 #define elf_s390_hash_table(p) \ |
740 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ | 741 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ |
741 == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL) | 742 == S390_ELF_DATA ? ((struct elf_s390_link_hash_table *) ((p)->hash)) : NULL) |
742 | 743 |
| 744 #undef ELF64 |
| 745 #include "elf-s390-common.c" |
| 746 |
743 /* Create an entry in an s390 ELF linker hash table. */ | 747 /* Create an entry in an s390 ELF linker hash table. */ |
744 | 748 |
745 static struct bfd_hash_entry * | 749 static struct bfd_hash_entry * |
746 link_hash_newfunc (entry, table, string) | 750 link_hash_newfunc (struct bfd_hash_entry *entry, |
747 struct bfd_hash_entry *entry; | 751 » » struct bfd_hash_table *table, |
748 struct bfd_hash_table *table; | 752 » » const char *string) |
749 const char *string; | |
750 { | 753 { |
751 /* Allocate the structure if it has not already been allocated by a | 754 /* Allocate the structure if it has not already been allocated by a |
752 subclass. */ | 755 subclass. */ |
753 if (entry == NULL) | 756 if (entry == NULL) |
754 { | 757 { |
755 entry = bfd_hash_allocate (table, | 758 entry = bfd_hash_allocate (table, |
756 sizeof (struct elf_s390_link_hash_entry)); | 759 sizeof (struct elf_s390_link_hash_entry)); |
757 if (entry == NULL) | 760 if (entry == NULL) |
758 return entry; | 761 return entry; |
759 } | 762 } |
760 | 763 |
761 /* Call the allocation method of the superclass. */ | 764 /* Call the allocation method of the superclass. */ |
762 entry = _bfd_elf_link_hash_newfunc (entry, table, string); | 765 entry = _bfd_elf_link_hash_newfunc (entry, table, string); |
763 if (entry != NULL) | 766 if (entry != NULL) |
764 { | 767 { |
765 struct elf_s390_link_hash_entry *eh; | 768 struct elf_s390_link_hash_entry *eh; |
766 | 769 |
767 eh = (struct elf_s390_link_hash_entry *) entry; | 770 eh = (struct elf_s390_link_hash_entry *) entry; |
768 eh->dyn_relocs = NULL; | 771 eh->dyn_relocs = NULL; |
769 eh->gotplt_refcount = 0; | 772 eh->gotplt_refcount = 0; |
770 eh->tls_type = GOT_UNKNOWN; | 773 eh->tls_type = GOT_UNKNOWN; |
| 774 eh->ifunc_resolver_address = 0; |
| 775 eh->ifunc_resolver_section = NULL; |
771 } | 776 } |
772 | 777 |
773 return entry; | 778 return entry; |
774 } | 779 } |
775 | 780 |
776 /* Create an s390 ELF linker hash table. */ | 781 /* Create an s390 ELF linker hash table. */ |
777 | 782 |
778 static struct bfd_link_hash_table * | 783 static struct bfd_link_hash_table * |
779 elf_s390_link_hash_table_create (abfd) | 784 elf_s390_link_hash_table_create (bfd *abfd) |
780 bfd *abfd; | |
781 { | 785 { |
782 struct elf_s390_link_hash_table *ret; | 786 struct elf_s390_link_hash_table *ret; |
783 bfd_size_type amt = sizeof (struct elf_s390_link_hash_table); | 787 bfd_size_type amt = sizeof (struct elf_s390_link_hash_table); |
784 | 788 |
785 ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt); | 789 ret = (struct elf_s390_link_hash_table *) bfd_malloc (amt); |
786 if (ret == NULL) | 790 if (ret == NULL) |
787 return NULL; | 791 return NULL; |
788 | 792 |
789 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, | 793 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc, |
790 sizeof (struct elf_s390_link_hash_entry), | 794 sizeof (struct elf_s390_link_hash_entry), |
791 S390_ELF_DATA)) | 795 S390_ELF_DATA)) |
792 { | 796 { |
793 free (ret); | 797 free (ret); |
794 return NULL; | 798 return NULL; |
795 } | 799 } |
796 | 800 |
797 ret->sgot = NULL; | 801 ret->elf.sgot = NULL; |
798 ret->sgotplt = NULL; | 802 ret->elf.sgotplt = NULL; |
799 ret->srelgot = NULL; | 803 ret->elf.srelgot = NULL; |
800 ret->splt = NULL; | 804 ret->elf.splt = NULL; |
801 ret->srelplt = NULL; | 805 ret->elf.srelplt = NULL; |
802 ret->sdynbss = NULL; | 806 ret->sdynbss = NULL; |
803 ret->srelbss = NULL; | 807 ret->srelbss = NULL; |
804 ret->tls_ldm_got.refcount = 0; | 808 ret->tls_ldm_got.refcount = 0; |
805 ret->sym_cache.abfd = NULL; | 809 ret->sym_cache.abfd = NULL; |
806 | 810 |
807 return &ret->elf.root; | 811 return &ret->elf.root; |
808 } | 812 } |
809 | 813 |
810 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up | 814 /* Create .got, .gotplt, and .rela.got sections in DYNOBJ, and set up |
811 shortcuts to them in our hash table. */ | 815 shortcuts to them in our hash table. */ |
812 | 816 |
813 static bfd_boolean | 817 static bfd_boolean |
814 create_got_section (dynobj, info) | 818 create_got_section (bfd *dynobj, struct bfd_link_info *info) |
815 bfd *dynobj; | |
816 struct bfd_link_info *info; | |
817 { | 819 { |
818 struct elf_s390_link_hash_table *htab; | 820 struct elf_s390_link_hash_table *htab; |
819 | 821 |
820 if (! _bfd_elf_create_got_section (dynobj, info)) | 822 if (! _bfd_elf_create_got_section (dynobj, info)) |
821 return FALSE; | 823 return FALSE; |
822 | 824 |
823 htab = elf_s390_hash_table (info); | 825 htab = elf_s390_hash_table (info); |
824 htab->sgot = bfd_get_section_by_name (dynobj, ".got"); | 826 htab->elf.sgot = bfd_get_linker_section (dynobj, ".got"); |
825 htab->sgotplt = bfd_get_section_by_name (dynobj, ".got.plt"); | 827 htab->elf.sgotplt = bfd_get_linker_section (dynobj, ".got.plt"); |
826 htab->srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); | 828 htab->elf.srelgot = bfd_get_linker_section (dynobj, ".rela.got"); |
827 if (!htab->sgot || !htab->sgotplt || !htab->srelgot) | 829 if (!htab->elf.sgot || !htab->elf.sgotplt || !htab->elf.srelgot) |
828 abort (); | 830 abort (); |
829 | 831 |
830 return TRUE; | 832 return TRUE; |
831 } | 833 } |
832 | 834 |
833 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and | 835 /* Create .plt, .rela.plt, .got, .got.plt, .rela.got, .dynbss, and |
834 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our | 836 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our |
835 hash table. */ | 837 hash table. */ |
836 | 838 |
837 static bfd_boolean | 839 static bfd_boolean |
838 elf_s390_create_dynamic_sections (dynobj, info) | 840 elf_s390_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) |
839 bfd *dynobj; | |
840 struct bfd_link_info *info; | |
841 { | 841 { |
842 struct elf_s390_link_hash_table *htab; | 842 struct elf_s390_link_hash_table *htab; |
843 | 843 |
844 htab = elf_s390_hash_table (info); | 844 htab = elf_s390_hash_table (info); |
845 if (!htab->sgot && !create_got_section (dynobj, info)) | 845 if (!htab->elf.sgot && !create_got_section (dynobj, info)) |
846 return FALSE; | 846 return FALSE; |
847 | 847 |
848 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) | 848 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) |
849 return FALSE; | 849 return FALSE; |
850 | 850 |
851 htab->splt = bfd_get_section_by_name (dynobj, ".plt"); | 851 htab->elf.splt = bfd_get_linker_section (dynobj, ".plt"); |
852 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); | 852 htab->elf.srelplt = bfd_get_linker_section (dynobj, ".rela.plt"); |
853 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); | 853 htab->sdynbss = bfd_get_linker_section (dynobj, ".dynbss"); |
854 if (!info->shared) | 854 if (!info->shared) |
855 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); | 855 htab->srelbss = bfd_get_linker_section (dynobj, ".rela.bss"); |
856 | 856 |
857 if (!htab->splt || !htab->srelplt || !htab->sdynbss | 857 if (!htab->elf.splt || !htab->elf.srelplt || !htab->sdynbss |
858 || (!info->shared && !htab->srelbss)) | 858 || (!info->shared && !htab->srelbss)) |
859 abort (); | 859 abort (); |
860 | 860 |
861 return TRUE; | 861 return TRUE; |
862 } | 862 } |
863 | 863 |
864 /* Copy the extra info we tack onto an elf_link_hash_entry. */ | 864 /* Copy the extra info we tack onto an elf_link_hash_entry. */ |
865 | 865 |
866 static void | 866 static void |
867 elf_s390_copy_indirect_symbol (info, dir, ind) | 867 elf_s390_copy_indirect_symbol (struct bfd_link_info *info, |
868 struct bfd_link_info *info; | 868 » » » struct elf_link_hash_entry *dir, |
869 struct elf_link_hash_entry *dir, *ind; | 869 » » » struct elf_link_hash_entry *ind) |
870 { | 870 { |
871 struct elf_s390_link_hash_entry *edir, *eind; | 871 struct elf_s390_link_hash_entry *edir, *eind; |
872 | 872 |
873 edir = (struct elf_s390_link_hash_entry *) dir; | 873 edir = (struct elf_s390_link_hash_entry *) dir; |
874 eind = (struct elf_s390_link_hash_entry *) ind; | 874 eind = (struct elf_s390_link_hash_entry *) ind; |
875 | 875 |
876 if (eind->dyn_relocs != NULL) | 876 if (eind->dyn_relocs != NULL) |
877 { | 877 { |
878 if (edir->dyn_relocs != NULL) | 878 if (edir->dyn_relocs != NULL) |
879 { | 879 { |
880 » struct elf_s390_dyn_relocs **pp; | 880 » struct elf_dyn_relocs **pp; |
881 » struct elf_s390_dyn_relocs *p; | 881 » struct elf_dyn_relocs *p; |
882 | 882 |
883 /* Add reloc counts against the indirect sym to the direct sym | 883 /* Add reloc counts against the indirect sym to the direct sym |
884 list. Merge any entries against the same section. */ | 884 list. Merge any entries against the same section. */ |
885 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) | 885 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) |
886 { | 886 { |
887 » struct elf_s390_dyn_relocs *q; | 887 » struct elf_dyn_relocs *q; |
888 | 888 |
889 for (q = edir->dyn_relocs; q != NULL; q = q->next) | 889 for (q = edir->dyn_relocs; q != NULL; q = q->next) |
890 if (q->sec == p->sec) | 890 if (q->sec == p->sec) |
891 { | 891 { |
892 q->pc_count += p->pc_count; | 892 q->pc_count += p->pc_count; |
893 q->count += p->count; | 893 q->count += p->count; |
894 *pp = p->next; | 894 *pp = p->next; |
895 break; | 895 break; |
896 } | 896 } |
897 if (q == NULL) | 897 if (q == NULL) |
(...skipping 23 matching lines...) Expand all Loading... |
921 dir->ref_dynamic |= ind->ref_dynamic; | 921 dir->ref_dynamic |= ind->ref_dynamic; |
922 dir->ref_regular |= ind->ref_regular; | 922 dir->ref_regular |= ind->ref_regular; |
923 dir->ref_regular_nonweak |= ind->ref_regular_nonweak; | 923 dir->ref_regular_nonweak |= ind->ref_regular_nonweak; |
924 dir->needs_plt |= ind->needs_plt; | 924 dir->needs_plt |= ind->needs_plt; |
925 } | 925 } |
926 else | 926 else |
927 _bfd_elf_link_hash_copy_indirect (info, dir, ind); | 927 _bfd_elf_link_hash_copy_indirect (info, dir, ind); |
928 } | 928 } |
929 | 929 |
930 static int | 930 static int |
931 elf_s390_tls_transition (info, r_type, is_local) | 931 elf_s390_tls_transition (struct bfd_link_info *info, |
932 struct bfd_link_info *info; | 932 » » » int r_type, |
933 int r_type; | 933 » » » int is_local) |
934 int is_local; | |
935 { | 934 { |
936 if (info->shared) | 935 if (info->shared) |
937 return r_type; | 936 return r_type; |
938 | 937 |
939 switch (r_type) | 938 switch (r_type) |
940 { | 939 { |
941 case R_390_TLS_GD32: | 940 case R_390_TLS_GD32: |
942 case R_390_TLS_IE32: | 941 case R_390_TLS_IE32: |
943 if (is_local) | 942 if (is_local) |
944 return R_390_TLS_LE32; | 943 return R_390_TLS_LE32; |
945 return R_390_TLS_IE32; | 944 return R_390_TLS_IE32; |
946 case R_390_TLS_GOTIE32: | 945 case R_390_TLS_GOTIE32: |
947 if (is_local) | 946 if (is_local) |
948 return R_390_TLS_LE32; | 947 return R_390_TLS_LE32; |
949 return R_390_TLS_GOTIE32; | 948 return R_390_TLS_GOTIE32; |
950 case R_390_TLS_LDM32: | 949 case R_390_TLS_LDM32: |
951 return R_390_TLS_LE32; | 950 return R_390_TLS_LE32; |
952 } | 951 } |
953 | 952 |
954 return r_type; | 953 return r_type; |
955 } | 954 } |
956 | 955 |
957 /* Look through the relocs for a section during the first phase, and | 956 /* Look through the relocs for a section during the first phase, and |
958 allocate space in the global offset table or procedure linkage | 957 allocate space in the global offset table or procedure linkage |
959 table. */ | 958 table. */ |
960 | 959 |
961 static bfd_boolean | 960 static bfd_boolean |
962 elf_s390_check_relocs (abfd, info, sec, relocs) | 961 elf_s390_check_relocs (bfd *abfd, |
963 bfd *abfd; | 962 » » struct bfd_link_info *info, |
964 struct bfd_link_info *info; | 963 » » asection *sec, |
965 asection *sec; | 964 » » const Elf_Internal_Rela *relocs) |
966 const Elf_Internal_Rela *relocs; | |
967 { | 965 { |
968 struct elf_s390_link_hash_table *htab; | 966 struct elf_s390_link_hash_table *htab; |
969 Elf_Internal_Shdr *symtab_hdr; | 967 Elf_Internal_Shdr *symtab_hdr; |
970 struct elf_link_hash_entry **sym_hashes; | 968 struct elf_link_hash_entry **sym_hashes; |
971 const Elf_Internal_Rela *rel; | 969 const Elf_Internal_Rela *rel; |
972 const Elf_Internal_Rela *rel_end; | 970 const Elf_Internal_Rela *rel_end; |
973 asection *sreloc; | 971 asection *sreloc; |
974 bfd_signed_vma *local_got_refcounts; | 972 bfd_signed_vma *local_got_refcounts; |
975 int tls_type, old_tls_type; | 973 int tls_type, old_tls_type; |
| 974 Elf_Internal_Sym *isym; |
976 | 975 |
977 if (info->relocatable) | 976 if (info->relocatable) |
978 return TRUE; | 977 return TRUE; |
979 | 978 |
980 BFD_ASSERT (is_s390_elf (abfd)); | 979 BFD_ASSERT (is_s390_elf (abfd)); |
981 | 980 |
982 htab = elf_s390_hash_table (info); | 981 htab = elf_s390_hash_table (info); |
983 symtab_hdr = &elf_symtab_hdr (abfd); | 982 symtab_hdr = &elf_symtab_hdr (abfd); |
984 sym_hashes = elf_sym_hashes (abfd); | 983 sym_hashes = elf_sym_hashes (abfd); |
985 local_got_refcounts = elf_local_got_refcounts (abfd); | 984 local_got_refcounts = elf_local_got_refcounts (abfd); |
(...skipping 10 matching lines...) Expand all Loading... |
996 r_symndx = ELF32_R_SYM (rel->r_info); | 995 r_symndx = ELF32_R_SYM (rel->r_info); |
997 | 996 |
998 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) | 997 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) |
999 { | 998 { |
1000 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), | 999 (*_bfd_error_handler) (_("%B: bad symbol index: %d"), |
1001 abfd, r_symndx); | 1000 abfd, r_symndx); |
1002 return FALSE; | 1001 return FALSE; |
1003 } | 1002 } |
1004 | 1003 |
1005 if (r_symndx < symtab_hdr->sh_info) | 1004 if (r_symndx < symtab_hdr->sh_info) |
1006 » h = NULL; | 1005 » { |
| 1006 » /* A local symbol. */ |
| 1007 » isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
| 1008 » » » » » abfd, r_symndx); |
| 1009 » if (isym == NULL) |
| 1010 » return FALSE; |
| 1011 |
| 1012 » if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
| 1013 » { |
| 1014 » struct plt_entry *plt; |
| 1015 |
| 1016 » if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info)) |
| 1017 » » return FALSE; |
| 1018 |
| 1019 » if (local_got_refcounts == NULL) |
| 1020 » » { |
| 1021 » » if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr)) |
| 1022 » » return FALSE; |
| 1023 » » local_got_refcounts = elf_local_got_refcounts (abfd); |
| 1024 » » } |
| 1025 » plt = elf_s390_local_plt (abfd); |
| 1026 » plt[r_symndx].plt.refcount++; |
| 1027 » } |
| 1028 » h = NULL; |
| 1029 » } |
1007 else | 1030 else |
1008 { | 1031 { |
1009 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | 1032 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
1010 while (h->root.type == bfd_link_hash_indirect | 1033 while (h->root.type == bfd_link_hash_indirect |
1011 || h->root.type == bfd_link_hash_warning) | 1034 || h->root.type == bfd_link_hash_warning) |
1012 h = (struct elf_link_hash_entry *) h->root.u.i.link; | 1035 h = (struct elf_link_hash_entry *) h->root.u.i.link; |
1013 } | 1036 } |
1014 | 1037 |
1015 /* Create got section and local_got_refcounts array if they | 1038 /* Create got section and local_got_refcounts array if they |
1016 are needed. */ | 1039 are needed. */ |
(...skipping 15 matching lines...) Expand all Loading... |
1032 case R_390_TLS_GD32: | 1055 case R_390_TLS_GD32: |
1033 case R_390_TLS_GOTIE12: | 1056 case R_390_TLS_GOTIE12: |
1034 case R_390_TLS_GOTIE20: | 1057 case R_390_TLS_GOTIE20: |
1035 case R_390_TLS_GOTIE32: | 1058 case R_390_TLS_GOTIE32: |
1036 case R_390_TLS_IEENT: | 1059 case R_390_TLS_IEENT: |
1037 case R_390_TLS_IE32: | 1060 case R_390_TLS_IE32: |
1038 case R_390_TLS_LDM32: | 1061 case R_390_TLS_LDM32: |
1039 if (h == NULL | 1062 if (h == NULL |
1040 && local_got_refcounts == NULL) | 1063 && local_got_refcounts == NULL) |
1041 { | 1064 { |
1042 » bfd_size_type size; | 1065 » if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr)) |
1043 | |
1044 » size = symtab_hdr->sh_info; | |
1045 » size *= (sizeof (bfd_signed_vma) + sizeof(char)); | |
1046 » local_got_refcounts = ((bfd_signed_vma *) | |
1047 » » » » bfd_zalloc (abfd, size)); | |
1048 » if (local_got_refcounts == NULL) | |
1049 return FALSE; | 1066 return FALSE; |
1050 » elf_local_got_refcounts (abfd) = local_got_refcounts; | 1067 » local_got_refcounts = elf_local_got_refcounts (abfd); |
1051 » elf_s390_local_got_tls_type (abfd) | |
1052 » » = (char *) (local_got_refcounts + symtab_hdr->sh_info); | |
1053 } | 1068 } |
1054 /* Fall through. */ | 1069 /* Fall through. */ |
1055 case R_390_GOTOFF16: | 1070 case R_390_GOTOFF16: |
1056 case R_390_GOTOFF32: | 1071 case R_390_GOTOFF32: |
1057 case R_390_GOTPC: | 1072 case R_390_GOTPC: |
1058 case R_390_GOTPCDBL: | 1073 case R_390_GOTPCDBL: |
1059 » if (htab->sgot == NULL) | 1074 » if (htab->elf.sgot == NULL) |
1060 { | 1075 { |
1061 if (htab->elf.dynobj == NULL) | 1076 if (htab->elf.dynobj == NULL) |
1062 htab->elf.dynobj = abfd; | 1077 htab->elf.dynobj = abfd; |
1063 if (!create_got_section (htab->elf.dynobj, info)) | 1078 if (!create_got_section (htab->elf.dynobj, info)) |
1064 return FALSE; | 1079 return FALSE; |
1065 } | 1080 } |
1066 } | 1081 } |
1067 | 1082 |
| 1083 if (h != NULL) |
| 1084 { |
| 1085 if (htab->elf.dynobj == NULL) |
| 1086 htab->elf.dynobj = abfd; |
| 1087 if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info)) |
| 1088 return FALSE; |
| 1089 |
| 1090 /* Make sure an IFUNC symbol defined in a non-shared object |
| 1091 always gets a PLT slot. */ |
| 1092 if (s390_is_ifunc_symbol_p (h) && h->def_regular) |
| 1093 { |
| 1094 /* The symbol is called by the dynamic loader in order |
| 1095 to resolve the relocation. So it is in fact also |
| 1096 referenced. */ |
| 1097 h->ref_regular = 1; |
| 1098 h->needs_plt = 1; |
| 1099 } |
| 1100 } |
1068 switch (r_type) | 1101 switch (r_type) |
1069 { | 1102 { |
1070 case R_390_GOTOFF16: | 1103 case R_390_GOTOFF16: |
1071 case R_390_GOTOFF32: | 1104 case R_390_GOTOFF32: |
1072 case R_390_GOTPC: | 1105 case R_390_GOTPC: |
1073 case R_390_GOTPCDBL: | 1106 case R_390_GOTPCDBL: |
1074 » /* Got is created, nothing to be done. */ | 1107 » /* These relocs do not need a GOT slot. They just load the |
| 1108 » GOT pointer itself or address something else relative to |
| 1109 » the GOT. Since the GOT pointer has been set up above we |
| 1110 » are done. */ |
1075 break; | 1111 break; |
1076 | 1112 |
1077 case R_390_PLT16DBL: | 1113 case R_390_PLT16DBL: |
1078 case R_390_PLT32DBL: | 1114 case R_390_PLT32DBL: |
1079 case R_390_PLT32: | 1115 case R_390_PLT32: |
1080 case R_390_PLTOFF16: | 1116 case R_390_PLTOFF16: |
1081 case R_390_PLTOFF32: | 1117 case R_390_PLTOFF32: |
1082 /* This symbol requires a procedure linkage table entry. We | 1118 /* This symbol requires a procedure linkage table entry. We |
1083 actually build the entry in adjust_dynamic_symbol, | 1119 actually build the entry in adjust_dynamic_symbol, |
1084 because this might be a case of linking PIC code which is | 1120 because this might be a case of linking PIC code which is |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1205 info->flags |= DF_STATIC_TLS; | 1241 info->flags |= DF_STATIC_TLS; |
1206 /* Fall through. */ | 1242 /* Fall through. */ |
1207 | 1243 |
1208 case R_390_8: | 1244 case R_390_8: |
1209 case R_390_16: | 1245 case R_390_16: |
1210 case R_390_32: | 1246 case R_390_32: |
1211 case R_390_PC16: | 1247 case R_390_PC16: |
1212 case R_390_PC16DBL: | 1248 case R_390_PC16DBL: |
1213 case R_390_PC32DBL: | 1249 case R_390_PC32DBL: |
1214 case R_390_PC32: | 1250 case R_390_PC32: |
1215 » if (h != NULL && !info->shared) | 1251 » if (h != NULL) |
1216 { | 1252 { |
1217 /* If this reloc is in a read-only section, we might | 1253 /* If this reloc is in a read-only section, we might |
1218 need a copy reloc. We can't check reliably at this | 1254 need a copy reloc. We can't check reliably at this |
1219 stage whether the section is read-only, as input | 1255 stage whether the section is read-only, as input |
1220 sections have not yet been mapped to output sections. | 1256 sections have not yet been mapped to output sections. |
1221 Tentatively set the flag for now, and correct in | 1257 Tentatively set the flag for now, and correct in |
1222 adjust_dynamic_symbol. */ | 1258 adjust_dynamic_symbol. */ |
1223 h->non_got_ref = 1; | 1259 h->non_got_ref = 1; |
1224 | 1260 |
1225 » /* We may need a .plt entry if the function this reloc | 1261 » if (!info->shared) |
1226 » » refers to is in a shared lib. */ | 1262 » » { |
1227 » h->plt.refcount += 1; | 1263 » » /* We may need a .plt entry if the function this reloc |
| 1264 » » refers to is in a shared lib. */ |
| 1265 » » h->plt.refcount += 1; |
| 1266 » » } |
1228 } | 1267 } |
1229 | 1268 |
1230 /* If we are creating a shared library, and this is a reloc | 1269 /* If we are creating a shared library, and this is a reloc |
1231 against a global symbol, or a non PC relative reloc | 1270 against a global symbol, or a non PC relative reloc |
1232 against a local symbol, then we need to copy the reloc | 1271 against a local symbol, then we need to copy the reloc |
1233 into the shared library. However, if we are linking with | 1272 into the shared library. However, if we are linking with |
1234 -Bsymbolic, we do not need to copy a reloc against a | 1273 -Bsymbolic, we do not need to copy a reloc against a |
1235 global symbol which is defined in an object we are | 1274 global symbol which is defined in an object we are |
1236 including in the link (i.e., DEF_REGULAR is set). At | 1275 including in the link (i.e., DEF_REGULAR is set). At |
1237 this point we have not seen all the input files, so it is | 1276 this point we have not seen all the input files, so it is |
(...skipping 20 matching lines...) Expand all Loading... |
1258 && (! SYMBOLIC_BIND (info, h) | 1297 && (! SYMBOLIC_BIND (info, h) |
1259 || h->root.type == bfd_link_hash_defweak | 1298 || h->root.type == bfd_link_hash_defweak |
1260 || !h->def_regular)))) | 1299 || !h->def_regular)))) |
1261 || (ELIMINATE_COPY_RELOCS | 1300 || (ELIMINATE_COPY_RELOCS |
1262 && !info->shared | 1301 && !info->shared |
1263 && (sec->flags & SEC_ALLOC) != 0 | 1302 && (sec->flags & SEC_ALLOC) != 0 |
1264 && h != NULL | 1303 && h != NULL |
1265 && (h->root.type == bfd_link_hash_defweak | 1304 && (h->root.type == bfd_link_hash_defweak |
1266 || !h->def_regular))) | 1305 || !h->def_regular))) |
1267 { | 1306 { |
1268 » struct elf_s390_dyn_relocs *p; | 1307 » struct elf_dyn_relocs *p; |
1269 » struct elf_s390_dyn_relocs **head; | 1308 » struct elf_dyn_relocs **head; |
1270 | 1309 |
1271 /* We must copy these reloc types into the output file. | 1310 /* We must copy these reloc types into the output file. |
1272 Create a reloc section in dynobj and make room for | 1311 Create a reloc section in dynobj and make room for |
1273 this reloc. */ | 1312 this reloc. */ |
1274 if (sreloc == NULL) | 1313 if (sreloc == NULL) |
1275 { | 1314 { |
1276 if (htab->elf.dynobj == NULL) | 1315 if (htab->elf.dynobj == NULL) |
1277 htab->elf.dynobj = abfd; | 1316 htab->elf.dynobj = abfd; |
1278 | 1317 |
1279 sreloc = _bfd_elf_make_dynamic_reloc_section | 1318 sreloc = _bfd_elf_make_dynamic_reloc_section |
1280 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); | 1319 (sec, htab->elf.dynobj, 2, abfd, /*rela?*/ TRUE); |
1281 | 1320 |
1282 if (sreloc == NULL) | 1321 if (sreloc == NULL) |
1283 return FALSE; | 1322 return FALSE; |
1284 } | 1323 } |
1285 | 1324 |
1286 /* If this is a global symbol, we count the number of | 1325 /* If this is a global symbol, we count the number of |
1287 relocations we need for this symbol. */ | 1326 relocations we need for this symbol. */ |
1288 if (h != NULL) | 1327 if (h != NULL) |
1289 { | 1328 { |
1290 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs; | 1329 head = &((struct elf_s390_link_hash_entry *) h)->dyn_relocs; |
1291 } | 1330 } |
1292 else | 1331 else |
1293 { | 1332 { |
1294 /* Track dynamic relocs needed for local syms too. | 1333 /* Track dynamic relocs needed for local syms too. |
1295 We really need local syms available to do this | 1334 We really need local syms available to do this |
1296 easily. Oh well. */ | 1335 easily. Oh well. */ |
1297 asection *s; | 1336 asection *s; |
1298 void *vpp; | 1337 void *vpp; |
1299 Elf_Internal_Sym *isym; | |
1300 | 1338 |
1301 isym = bfd_sym_from_r_symndx (&htab->sym_cache, | 1339 isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
1302 abfd, r_symndx); | 1340 abfd, r_symndx); |
1303 if (isym == NULL) | 1341 if (isym == NULL) |
1304 return FALSE; | 1342 return FALSE; |
1305 | 1343 |
1306 s = bfd_section_from_elf_index (abfd, isym->st_shndx); | 1344 s = bfd_section_from_elf_index (abfd, isym->st_shndx); |
1307 if (s == NULL) | 1345 if (s == NULL) |
1308 s = sec; | 1346 s = sec; |
1309 | 1347 |
1310 vpp = &elf_section_data (s)->local_dynrel; | 1348 vpp = &elf_section_data (s)->local_dynrel; |
1311 » » head = (struct elf_s390_dyn_relocs **) vpp; | 1349 » » head = (struct elf_dyn_relocs **) vpp; |
1312 } | 1350 } |
1313 | 1351 |
1314 p = *head; | 1352 p = *head; |
1315 if (p == NULL || p->sec != sec) | 1353 if (p == NULL || p->sec != sec) |
1316 { | 1354 { |
1317 bfd_size_type amt = sizeof *p; | 1355 bfd_size_type amt = sizeof *p; |
1318 | 1356 |
1319 » » p = ((struct elf_s390_dyn_relocs *) | 1357 » » p = ((struct elf_dyn_relocs *) |
1320 bfd_alloc (htab->elf.dynobj, amt)); | 1358 bfd_alloc (htab->elf.dynobj, amt)); |
1321 if (p == NULL) | 1359 if (p == NULL) |
1322 return FALSE; | 1360 return FALSE; |
1323 p->next = *head; | 1361 p->next = *head; |
1324 *head = p; | 1362 *head = p; |
1325 p->sec = sec; | 1363 p->sec = sec; |
1326 p->count = 0; | 1364 p->count = 0; |
1327 p->pc_count = 0; | 1365 p->pc_count = 0; |
1328 } | 1366 } |
1329 | 1367 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1382 } | 1420 } |
1383 | 1421 |
1384 /* Update the got entry reference counts for the section being removed. */ | 1422 /* Update the got entry reference counts for the section being removed. */ |
1385 | 1423 |
1386 static bfd_boolean | 1424 static bfd_boolean |
1387 elf_s390_gc_sweep_hook (bfd *abfd, | 1425 elf_s390_gc_sweep_hook (bfd *abfd, |
1388 struct bfd_link_info *info, | 1426 struct bfd_link_info *info, |
1389 asection *sec, | 1427 asection *sec, |
1390 const Elf_Internal_Rela *relocs) | 1428 const Elf_Internal_Rela *relocs) |
1391 { | 1429 { |
| 1430 struct elf_s390_link_hash_table *htab; |
1392 Elf_Internal_Shdr *symtab_hdr; | 1431 Elf_Internal_Shdr *symtab_hdr; |
1393 struct elf_link_hash_entry **sym_hashes; | 1432 struct elf_link_hash_entry **sym_hashes; |
1394 bfd_signed_vma *local_got_refcounts; | 1433 bfd_signed_vma *local_got_refcounts; |
1395 const Elf_Internal_Rela *rel, *relend; | 1434 const Elf_Internal_Rela *rel, *relend; |
1396 | 1435 |
1397 if (info->relocatable) | 1436 if (info->relocatable) |
1398 return TRUE; | 1437 return TRUE; |
1399 | 1438 |
| 1439 htab = elf_s390_hash_table (info); |
| 1440 if (htab == NULL) |
| 1441 return FALSE; |
| 1442 |
1400 elf_section_data (sec)->local_dynrel = NULL; | 1443 elf_section_data (sec)->local_dynrel = NULL; |
1401 | 1444 |
1402 symtab_hdr = &elf_symtab_hdr (abfd); | 1445 symtab_hdr = &elf_symtab_hdr (abfd); |
1403 sym_hashes = elf_sym_hashes (abfd); | 1446 sym_hashes = elf_sym_hashes (abfd); |
1404 local_got_refcounts = elf_local_got_refcounts (abfd); | 1447 local_got_refcounts = elf_local_got_refcounts (abfd); |
1405 | 1448 |
1406 relend = relocs + sec->reloc_count; | 1449 relend = relocs + sec->reloc_count; |
1407 for (rel = relocs; rel < relend; rel++) | 1450 for (rel = relocs; rel < relend; rel++) |
1408 { | 1451 { |
1409 unsigned long r_symndx; | 1452 unsigned long r_symndx; |
1410 unsigned int r_type; | 1453 unsigned int r_type; |
1411 struct elf_link_hash_entry *h = NULL; | 1454 struct elf_link_hash_entry *h = NULL; |
1412 | 1455 |
1413 r_symndx = ELF32_R_SYM (rel->r_info); | 1456 r_symndx = ELF32_R_SYM (rel->r_info); |
1414 if (r_symndx >= symtab_hdr->sh_info) | 1457 if (r_symndx >= symtab_hdr->sh_info) |
1415 { | 1458 { |
1416 struct elf_s390_link_hash_entry *eh; | 1459 struct elf_s390_link_hash_entry *eh; |
1417 » struct elf_s390_dyn_relocs **pp; | 1460 » struct elf_dyn_relocs **pp; |
1418 » struct elf_s390_dyn_relocs *p; | 1461 » struct elf_dyn_relocs *p; |
1419 | 1462 |
1420 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; | 1463 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
1421 while (h->root.type == bfd_link_hash_indirect | 1464 while (h->root.type == bfd_link_hash_indirect |
1422 || h->root.type == bfd_link_hash_warning) | 1465 || h->root.type == bfd_link_hash_warning) |
1423 h = (struct elf_link_hash_entry *) h->root.u.i.link; | 1466 h = (struct elf_link_hash_entry *) h->root.u.i.link; |
1424 eh = (struct elf_s390_link_hash_entry *) h; | 1467 eh = (struct elf_s390_link_hash_entry *) h; |
1425 | 1468 |
1426 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) | 1469 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) |
1427 if (p->sec == sec) | 1470 if (p->sec == sec) |
1428 { | 1471 { |
1429 /* Everything must go for SEC. */ | 1472 /* Everything must go for SEC. */ |
1430 *pp = p->next; | 1473 *pp = p->next; |
1431 break; | 1474 break; |
1432 } | 1475 } |
1433 } | 1476 } |
| 1477 else |
| 1478 { |
| 1479 Elf_Internal_Sym *isym; |
| 1480 |
| 1481 /* A local symbol. */ |
| 1482 isym = bfd_sym_from_r_symndx (&htab->sym_cache, |
| 1483 abfd, r_symndx); |
| 1484 if (isym == NULL) |
| 1485 return FALSE; |
| 1486 |
| 1487 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
| 1488 { |
| 1489 struct plt_entry *plt = elf_s390_local_plt (abfd); |
| 1490 if (plt[r_symndx].plt.refcount > 0) |
| 1491 plt[r_symndx].plt.refcount--; |
| 1492 } |
| 1493 } |
1434 | 1494 |
1435 r_type = ELF32_R_TYPE (rel->r_info); | 1495 r_type = ELF32_R_TYPE (rel->r_info); |
1436 r_type = elf_s390_tls_transition (info, r_type, h != NULL); | 1496 r_type = elf_s390_tls_transition (info, r_type, h != NULL); |
1437 switch (r_type) | 1497 switch (r_type) |
1438 { | 1498 { |
1439 case R_390_TLS_LDM32: | 1499 case R_390_TLS_LDM32: |
1440 if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0) | 1500 if (elf_s390_hash_table (info)->tls_ldm_got.refcount > 0) |
1441 elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1; | 1501 elf_s390_hash_table (info)->tls_ldm_got.refcount -= 1; |
1442 break; | 1502 break; |
1443 | 1503 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 } | 1582 } |
1523 | 1583 |
1524 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT | 1584 /* Make sure we emit a GOT entry if the symbol was supposed to have a PLT |
1525 entry but we found we will not create any. Called when we find we will | 1585 entry but we found we will not create any. Called when we find we will |
1526 not have any PLT for this symbol, by for example | 1586 not have any PLT for this symbol, by for example |
1527 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link, | 1587 elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link, |
1528 or elf_s390_size_dynamic_sections if no dynamic sections will be | 1588 or elf_s390_size_dynamic_sections if no dynamic sections will be |
1529 created (we're only linking static objects). */ | 1589 created (we're only linking static objects). */ |
1530 | 1590 |
1531 static void | 1591 static void |
1532 elf_s390_adjust_gotplt (h) | 1592 elf_s390_adjust_gotplt (struct elf_s390_link_hash_entry *h) |
1533 struct elf_s390_link_hash_entry *h; | |
1534 { | 1593 { |
1535 if (h->elf.root.type == bfd_link_hash_warning) | 1594 if (h->elf.root.type == bfd_link_hash_warning) |
1536 h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link; | 1595 h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link; |
1537 | 1596 |
1538 if (h->gotplt_refcount <= 0) | 1597 if (h->gotplt_refcount <= 0) |
1539 return; | 1598 return; |
1540 | 1599 |
1541 /* We simply add the number of gotplt references to the number | 1600 /* We simply add the number of gotplt references to the number |
1542 * of got references for this symbol. */ | 1601 * of got references for this symbol. */ |
1543 h->elf.got.refcount += h->gotplt_refcount; | 1602 h->elf.got.refcount += h->gotplt_refcount; |
1544 h->gotplt_refcount = -1; | 1603 h->gotplt_refcount = -1; |
1545 } | 1604 } |
1546 | 1605 |
1547 /* Adjust a symbol defined by a dynamic object and referenced by a | 1606 /* Adjust a symbol defined by a dynamic object and referenced by a |
1548 regular object. The current definition is in some section of the | 1607 regular object. The current definition is in some section of the |
1549 dynamic object, but we're not including those sections. We have to | 1608 dynamic object, but we're not including those sections. We have to |
1550 change the definition to something the rest of the link can | 1609 change the definition to something the rest of the link can |
1551 understand. */ | 1610 understand. */ |
1552 | 1611 |
1553 static bfd_boolean | 1612 static bfd_boolean |
1554 elf_s390_adjust_dynamic_symbol (info, h) | 1613 elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, |
1555 struct bfd_link_info *info; | 1614 » » » » struct elf_link_hash_entry *h) |
1556 struct elf_link_hash_entry *h; | |
1557 { | 1615 { |
1558 struct elf_s390_link_hash_table *htab; | 1616 struct elf_s390_link_hash_table *htab; |
1559 asection *s; | 1617 asection *s; |
1560 | 1618 |
| 1619 /* STT_GNU_IFUNC symbol must go through PLT. */ |
| 1620 if (s390_is_ifunc_symbol_p (h)) |
| 1621 return TRUE; |
| 1622 |
1561 /* If this is a function, put it in the procedure linkage table. We | 1623 /* If this is a function, put it in the procedure linkage table. We |
1562 will fill in the contents of the procedure linkage table later | 1624 will fill in the contents of the procedure linkage table later |
1563 (although we could actually do it here). */ | 1625 (although we could actually do it here). */ |
1564 if (h->type == STT_FUNC | 1626 if (h->type == STT_FUNC |
1565 || h->needs_plt) | 1627 || h->needs_plt) |
1566 { | 1628 { |
1567 if (h->plt.refcount <= 0 | 1629 if (h->plt.refcount <= 0 |
1568 || SYMBOL_CALLS_LOCAL (info, h) | 1630 || SYMBOL_CALLS_LOCAL (info, h) |
1569 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT | 1631 || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
1570 && h->root.type != bfd_link_hash_undefweak)) | 1632 && h->root.type != bfd_link_hash_undefweak)) |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 /* If -z nocopyreloc was given, we won't generate them either. */ | 1683 /* If -z nocopyreloc was given, we won't generate them either. */ |
1622 if (info->nocopyreloc) | 1684 if (info->nocopyreloc) |
1623 { | 1685 { |
1624 h->non_got_ref = 0; | 1686 h->non_got_ref = 0; |
1625 return TRUE; | 1687 return TRUE; |
1626 } | 1688 } |
1627 | 1689 |
1628 if (ELIMINATE_COPY_RELOCS) | 1690 if (ELIMINATE_COPY_RELOCS) |
1629 { | 1691 { |
1630 struct elf_s390_link_hash_entry * eh; | 1692 struct elf_s390_link_hash_entry * eh; |
1631 struct elf_s390_dyn_relocs *p; | 1693 struct elf_dyn_relocs *p; |
1632 | 1694 |
1633 eh = (struct elf_s390_link_hash_entry *) h; | 1695 eh = (struct elf_s390_link_hash_entry *) h; |
1634 for (p = eh->dyn_relocs; p != NULL; p = p->next) | 1696 for (p = eh->dyn_relocs; p != NULL; p = p->next) |
1635 { | 1697 { |
1636 s = p->sec->output_section; | 1698 s = p->sec->output_section; |
1637 if (s != NULL && (s->flags & SEC_READONLY) != 0) | 1699 if (s != NULL && (s->flags & SEC_READONLY) != 0) |
1638 break; | 1700 break; |
1639 } | 1701 } |
1640 | 1702 |
1641 /* If we didn't find any dynamic relocs in read-only sections, then | 1703 /* If we didn't find any dynamic relocs in read-only sections, then |
1642 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ | 1704 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ |
1643 if (p == NULL) | 1705 if (p == NULL) |
1644 { | 1706 { |
1645 h->non_got_ref = 0; | 1707 h->non_got_ref = 0; |
1646 return TRUE; | 1708 return TRUE; |
1647 } | 1709 } |
1648 } | 1710 } |
1649 | 1711 |
1650 if (h->size == 0) | |
1651 { | |
1652 (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), | |
1653 h->root.root.string); | |
1654 return TRUE; | |
1655 } | |
1656 | |
1657 /* We must allocate the symbol in our .dynbss section, which will | 1712 /* We must allocate the symbol in our .dynbss section, which will |
1658 become part of the .bss section of the executable. There will be | 1713 become part of the .bss section of the executable. There will be |
1659 an entry for this symbol in the .dynsym section. The dynamic | 1714 an entry for this symbol in the .dynsym section. The dynamic |
1660 object will contain position independent code, so all references | 1715 object will contain position independent code, so all references |
1661 from the dynamic object to this symbol will go through the global | 1716 from the dynamic object to this symbol will go through the global |
1662 offset table. The dynamic linker will use the .dynsym entry to | 1717 offset table. The dynamic linker will use the .dynsym entry to |
1663 determine the address it must put in the global offset table, so | 1718 determine the address it must put in the global offset table, so |
1664 both the dynamic object and the regular object will refer to the | 1719 both the dynamic object and the regular object will refer to the |
1665 same memory location for the variable. */ | 1720 same memory location for the variable. */ |
1666 | 1721 |
1667 htab = elf_s390_hash_table (info); | 1722 htab = elf_s390_hash_table (info); |
1668 | 1723 |
1669 /* We must generate a R_390_COPY reloc to tell the dynamic linker to | 1724 /* We must generate a R_390_COPY reloc to tell the dynamic linker to |
1670 copy the initial value out of the dynamic object and into the | 1725 copy the initial value out of the dynamic object and into the |
1671 runtime process image. */ | 1726 runtime process image. */ |
1672 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) | 1727 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0) |
1673 { | 1728 { |
1674 htab->srelbss->size += sizeof (Elf32_External_Rela); | 1729 htab->srelbss->size += sizeof (Elf32_External_Rela); |
1675 h->needs_copy = 1; | 1730 h->needs_copy = 1; |
1676 } | 1731 } |
1677 | 1732 |
1678 s = htab->sdynbss; | 1733 s = htab->sdynbss; |
1679 | 1734 |
1680 return _bfd_elf_adjust_dynamic_copy (h, s); | 1735 return _bfd_elf_adjust_dynamic_copy (h, s); |
1681 } | 1736 } |
1682 | 1737 |
1683 /* Allocate space in .plt, .got and associated reloc sections for | 1738 /* Allocate space in .plt, .got and associated reloc sections for |
1684 dynamic relocs. */ | 1739 dynamic relocs. */ |
1685 | 1740 |
1686 static bfd_boolean | 1741 static bfd_boolean |
1687 allocate_dynrelocs (h, inf) | 1742 allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
1688 struct elf_link_hash_entry *h; | |
1689 PTR inf; | |
1690 { | 1743 { |
1691 struct bfd_link_info *info; | 1744 struct bfd_link_info *info; |
1692 struct elf_s390_link_hash_table *htab; | 1745 struct elf_s390_link_hash_table *htab; |
1693 struct elf_s390_link_hash_entry *eh; | 1746 struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry *)h; |
1694 struct elf_s390_dyn_relocs *p; | 1747 struct elf_dyn_relocs *p; |
1695 | 1748 |
1696 if (h->root.type == bfd_link_hash_indirect) | 1749 if (h->root.type == bfd_link_hash_indirect) |
1697 return TRUE; | 1750 return TRUE; |
1698 | 1751 |
1699 info = (struct bfd_link_info *) inf; | 1752 info = (struct bfd_link_info *) inf; |
1700 htab = elf_s390_hash_table (info); | 1753 htab = elf_s390_hash_table (info); |
1701 | 1754 |
1702 if (htab->elf.dynamic_sections_created | 1755 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it |
1703 && h->plt.refcount > 0) | 1756 here if it is defined and referenced in a non-shared object. */ |
| 1757 if (s390_is_ifunc_symbol_p (h) && h->def_regular) |
| 1758 return s390_elf_allocate_ifunc_dyn_relocs (info, h, |
| 1759 » » » » » &eh->dyn_relocs); |
| 1760 else if (htab->elf.dynamic_sections_created |
| 1761 » && h->plt.refcount > 0) |
1704 { | 1762 { |
1705 /* Make sure this symbol is output as a dynamic symbol. | 1763 /* Make sure this symbol is output as a dynamic symbol. |
1706 Undefined weak syms won't yet be marked as dynamic. */ | 1764 Undefined weak syms won't yet be marked as dynamic. */ |
1707 if (h->dynindx == -1 | 1765 if (h->dynindx == -1 |
1708 && !h->forced_local) | 1766 && !h->forced_local) |
1709 { | 1767 { |
1710 if (! bfd_elf_link_record_dynamic_symbol (info, h)) | 1768 if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
1711 return FALSE; | 1769 return FALSE; |
1712 } | 1770 } |
1713 | 1771 |
1714 if (info->shared | 1772 if (info->shared |
1715 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) | 1773 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) |
1716 { | 1774 { |
1717 » asection *s = htab->splt; | 1775 » asection *s = htab->elf.splt; |
1718 | 1776 |
1719 /* If this is the first .plt entry, make room for the special | 1777 /* If this is the first .plt entry, make room for the special |
1720 first entry. */ | 1778 first entry. */ |
1721 if (s->size == 0) | 1779 if (s->size == 0) |
1722 s->size += PLT_FIRST_ENTRY_SIZE; | 1780 s->size += PLT_FIRST_ENTRY_SIZE; |
1723 | 1781 |
1724 h->plt.offset = s->size; | 1782 h->plt.offset = s->size; |
1725 | 1783 |
1726 /* If this symbol is not defined in a regular file, and we are | 1784 /* If this symbol is not defined in a regular file, and we are |
1727 not generating a shared library, then set the symbol to this | 1785 not generating a shared library, then set the symbol to this |
1728 location in the .plt. This is required to make function | 1786 location in the .plt. This is required to make function |
1729 pointers compare as equal between the normal executable and | 1787 pointers compare as equal between the normal executable and |
1730 the shared library. */ | 1788 the shared library. */ |
1731 if (! info->shared | 1789 if (! info->shared |
1732 && !h->def_regular) | 1790 && !h->def_regular) |
1733 { | 1791 { |
1734 h->root.u.def.section = s; | 1792 h->root.u.def.section = s; |
1735 h->root.u.def.value = h->plt.offset; | 1793 h->root.u.def.value = h->plt.offset; |
1736 } | 1794 } |
1737 | 1795 |
1738 /* Make room for this entry. */ | 1796 /* Make room for this entry. */ |
1739 s->size += PLT_ENTRY_SIZE; | 1797 s->size += PLT_ENTRY_SIZE; |
1740 | 1798 |
1741 /* We also need to make an entry in the .got.plt section, which | 1799 /* We also need to make an entry in the .got.plt section, which |
1742 will be placed in the .got section by the linker script. */ | 1800 will be placed in the .got section by the linker script. */ |
1743 » htab->sgotplt->size += GOT_ENTRY_SIZE; | 1801 » htab->elf.sgotplt->size += GOT_ENTRY_SIZE; |
1744 | 1802 |
1745 /* We also need to make an entry in the .rela.plt section. */ | 1803 /* We also need to make an entry in the .rela.plt section. */ |
1746 » htab->srelplt->size += sizeof (Elf32_External_Rela); | 1804 » htab->elf.srelplt->size += sizeof (Elf32_External_Rela); |
1747 } | 1805 } |
1748 else | 1806 else |
1749 { | 1807 { |
1750 h->plt.offset = (bfd_vma) -1; | 1808 h->plt.offset = (bfd_vma) -1; |
1751 h->needs_plt = 0; | 1809 h->needs_plt = 0; |
1752 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); | 1810 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); |
1753 } | 1811 } |
1754 } | 1812 } |
1755 else | 1813 else |
1756 { | 1814 { |
1757 h->plt.offset = (bfd_vma) -1; | 1815 h->plt.offset = (bfd_vma) -1; |
1758 h->needs_plt = 0; | 1816 h->needs_plt = 0; |
1759 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); | 1817 elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h); |
1760 } | 1818 } |
1761 | 1819 |
1762 /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to | 1820 /* If R_390_TLS_{IE32,GOTIE32,GOTIE12,IEENT} symbol is now local to |
1763 the binary, we can optimize a bit. IE32 and GOTIE32 get converted | 1821 the binary, we can optimize a bit. IE32 and GOTIE32 get converted |
1764 to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT | 1822 to R_390_TLS_LE32 requiring no TLS entry. For GOTIE12 and IEENT |
1765 we can save the dynamic TLS relocation. */ | 1823 we can save the dynamic TLS relocation. */ |
1766 if (h->got.refcount > 0 | 1824 if (h->got.refcount > 0 |
1767 && !info->shared | 1825 && !info->shared |
1768 && h->dynindx == -1 | 1826 && h->dynindx == -1 |
1769 && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE) | 1827 && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE) |
1770 { | 1828 { |
1771 if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT) | 1829 if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT) |
1772 /* For the GOTIE access without a literal pool entry the offset has | 1830 /* For the GOTIE access without a literal pool entry the offset has |
1773 to be stored somewhere. The immediate value in the instruction | 1831 to be stored somewhere. The immediate value in the instruction |
1774 is not bit enough so the value is stored in the got. */ | 1832 is not bit enough so the value is stored in the got. */ |
1775 { | 1833 { |
1776 » h->got.offset = htab->sgot->size; | 1834 » h->got.offset = htab->elf.sgot->size; |
1777 » htab->sgot->size += GOT_ENTRY_SIZE; | 1835 » htab->elf.sgot->size += GOT_ENTRY_SIZE; |
1778 } | 1836 } |
1779 else | 1837 else |
1780 h->got.offset = (bfd_vma) -1; | 1838 h->got.offset = (bfd_vma) -1; |
1781 } | 1839 } |
1782 else if (h->got.refcount > 0) | 1840 else if (h->got.refcount > 0) |
1783 { | 1841 { |
1784 asection *s; | 1842 asection *s; |
1785 bfd_boolean dyn; | 1843 bfd_boolean dyn; |
1786 int tls_type = elf_s390_hash_entry(h)->tls_type; | 1844 int tls_type = elf_s390_hash_entry(h)->tls_type; |
1787 | 1845 |
1788 /* Make sure this symbol is output as a dynamic symbol. | 1846 /* Make sure this symbol is output as a dynamic symbol. |
1789 Undefined weak syms won't yet be marked as dynamic. */ | 1847 Undefined weak syms won't yet be marked as dynamic. */ |
1790 if (h->dynindx == -1 | 1848 if (h->dynindx == -1 |
1791 && !h->forced_local) | 1849 && !h->forced_local) |
1792 { | 1850 { |
1793 if (! bfd_elf_link_record_dynamic_symbol (info, h)) | 1851 if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
1794 return FALSE; | 1852 return FALSE; |
1795 } | 1853 } |
1796 | 1854 |
1797 s = htab->sgot; | 1855 s = htab->elf.sgot; |
1798 h->got.offset = s->size; | 1856 h->got.offset = s->size; |
1799 s->size += GOT_ENTRY_SIZE; | 1857 s->size += GOT_ENTRY_SIZE; |
1800 /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */ | 1858 /* R_390_TLS_GD32 needs 2 consecutive GOT slots. */ |
1801 if (tls_type == GOT_TLS_GD) | 1859 if (tls_type == GOT_TLS_GD) |
1802 s->size += GOT_ENTRY_SIZE; | 1860 s->size += GOT_ENTRY_SIZE; |
1803 dyn = htab->elf.dynamic_sections_created; | 1861 dyn = htab->elf.dynamic_sections_created; |
1804 /* R_390_TLS_IE32 needs one dynamic relocation, | 1862 /* R_390_TLS_IE32 needs one dynamic relocation, |
1805 R_390_TLS_GD32 needs one if local symbol and two if global. */ | 1863 R_390_TLS_GD32 needs one if local symbol and two if global. */ |
1806 if ((tls_type == GOT_TLS_GD && h->dynindx == -1) | 1864 if ((tls_type == GOT_TLS_GD && h->dynindx == -1) |
1807 || tls_type >= GOT_TLS_IE) | 1865 || tls_type >= GOT_TLS_IE) |
1808 » htab->srelgot->size += sizeof (Elf32_External_Rela); | 1866 » htab->elf.srelgot->size += sizeof (Elf32_External_Rela); |
1809 else if (tls_type == GOT_TLS_GD) | 1867 else if (tls_type == GOT_TLS_GD) |
1810 » htab->srelgot->size += 2 * sizeof (Elf32_External_Rela); | 1868 » htab->elf.srelgot->size += 2 * sizeof (Elf32_External_Rela); |
1811 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | 1869 else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
1812 || h->root.type != bfd_link_hash_undefweak) | 1870 || h->root.type != bfd_link_hash_undefweak) |
1813 && (info->shared | 1871 && (info->shared |
1814 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) | 1872 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) |
1815 » htab->srelgot->size += sizeof (Elf32_External_Rela); | 1873 » htab->elf.srelgot->size += sizeof (Elf32_External_Rela); |
1816 } | 1874 } |
1817 else | 1875 else |
1818 h->got.offset = (bfd_vma) -1; | 1876 h->got.offset = (bfd_vma) -1; |
1819 | 1877 |
1820 eh = (struct elf_s390_link_hash_entry *) h; | |
1821 if (eh->dyn_relocs == NULL) | 1878 if (eh->dyn_relocs == NULL) |
1822 return TRUE; | 1879 return TRUE; |
1823 | 1880 |
1824 /* In the shared -Bsymbolic case, discard space allocated for | 1881 /* In the shared -Bsymbolic case, discard space allocated for |
1825 dynamic pc-relative relocs against symbols which turn out to be | 1882 dynamic pc-relative relocs against symbols which turn out to be |
1826 defined in regular objects. For the normal shared case, discard | 1883 defined in regular objects. For the normal shared case, discard |
1827 space for pc-relative relocs that have become local due to symbol | 1884 space for pc-relative relocs that have become local due to symbol |
1828 visibility changes. */ | 1885 visibility changes. */ |
1829 | 1886 |
1830 if (info->shared) | 1887 if (info->shared) |
1831 { | 1888 { |
1832 if (SYMBOL_CALLS_LOCAL (info, h)) | 1889 if (SYMBOL_CALLS_LOCAL (info, h)) |
1833 { | 1890 { |
1834 » struct elf_s390_dyn_relocs **pp; | 1891 » struct elf_dyn_relocs **pp; |
1835 | 1892 |
1836 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) | 1893 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) |
1837 { | 1894 { |
1838 p->count -= p->pc_count; | 1895 p->count -= p->pc_count; |
1839 p->pc_count = 0; | 1896 p->pc_count = 0; |
1840 if (p->count == 0) | 1897 if (p->count == 0) |
1841 *pp = p->next; | 1898 *pp = p->next; |
1842 else | 1899 else |
1843 pp = &p->next; | 1900 pp = &p->next; |
1844 } | 1901 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 | 1959 |
1903 sreloc->size += p->count * sizeof (Elf32_External_Rela); | 1960 sreloc->size += p->count * sizeof (Elf32_External_Rela); |
1904 } | 1961 } |
1905 | 1962 |
1906 return TRUE; | 1963 return TRUE; |
1907 } | 1964 } |
1908 | 1965 |
1909 /* Find any dynamic relocs that apply to read-only sections. */ | 1966 /* Find any dynamic relocs that apply to read-only sections. */ |
1910 | 1967 |
1911 static bfd_boolean | 1968 static bfd_boolean |
1912 readonly_dynrelocs (h, inf) | 1969 readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf) |
1913 struct elf_link_hash_entry *h; | |
1914 PTR inf; | |
1915 { | 1970 { |
1916 struct elf_s390_link_hash_entry *eh; | 1971 struct elf_s390_link_hash_entry *eh; |
1917 struct elf_s390_dyn_relocs *p; | 1972 struct elf_dyn_relocs *p; |
1918 | 1973 |
1919 eh = (struct elf_s390_link_hash_entry *) h; | 1974 eh = (struct elf_s390_link_hash_entry *) h; |
1920 for (p = eh->dyn_relocs; p != NULL; p = p->next) | 1975 for (p = eh->dyn_relocs; p != NULL; p = p->next) |
1921 { | 1976 { |
1922 asection *s = p->sec->output_section; | 1977 asection *s = p->sec->output_section; |
1923 | 1978 |
1924 if (s != NULL && (s->flags & SEC_READONLY) != 0) | 1979 if (s != NULL && (s->flags & SEC_READONLY) != 0) |
1925 { | 1980 { |
1926 struct bfd_link_info *info = (struct bfd_link_info *) inf; | 1981 struct bfd_link_info *info = (struct bfd_link_info *) inf; |
1927 | 1982 |
1928 info->flags |= DF_TEXTREL; | 1983 info->flags |= DF_TEXTREL; |
1929 | 1984 |
1930 /* Not an error, just cut short the traversal. */ | 1985 /* Not an error, just cut short the traversal. */ |
1931 return FALSE; | 1986 return FALSE; |
1932 } | 1987 } |
1933 } | 1988 } |
1934 return TRUE; | 1989 return TRUE; |
1935 } | 1990 } |
1936 | 1991 |
1937 /* Set the sizes of the dynamic sections. */ | 1992 /* Set the sizes of the dynamic sections. */ |
1938 | 1993 |
1939 static bfd_boolean | 1994 static bfd_boolean |
1940 elf_s390_size_dynamic_sections (output_bfd, info) | 1995 elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, |
1941 bfd *output_bfd ATTRIBUTE_UNUSED; | 1996 » » » » struct bfd_link_info *info) |
1942 struct bfd_link_info *info; | |
1943 { | 1997 { |
1944 struct elf_s390_link_hash_table *htab; | 1998 struct elf_s390_link_hash_table *htab; |
1945 bfd *dynobj; | 1999 bfd *dynobj; |
1946 asection *s; | 2000 asection *s; |
1947 bfd_boolean relocs; | 2001 bfd_boolean relocs; |
1948 bfd *ibfd; | 2002 bfd *ibfd; |
1949 | 2003 |
1950 htab = elf_s390_hash_table (info); | 2004 htab = elf_s390_hash_table (info); |
1951 dynobj = htab->elf.dynobj; | 2005 dynobj = htab->elf.dynobj; |
1952 if (dynobj == NULL) | 2006 if (dynobj == NULL) |
1953 abort (); | 2007 abort (); |
1954 | 2008 |
1955 if (htab->elf.dynamic_sections_created) | 2009 if (htab->elf.dynamic_sections_created) |
1956 { | 2010 { |
1957 /* Set the contents of the .interp section to the interpreter. */ | 2011 /* Set the contents of the .interp section to the interpreter. */ |
1958 if (info->executable) | 2012 if (info->executable) |
1959 { | 2013 { |
1960 » s = bfd_get_section_by_name (dynobj, ".interp"); | 2014 » s = bfd_get_linker_section (dynobj, ".interp"); |
1961 if (s == NULL) | 2015 if (s == NULL) |
1962 abort (); | 2016 abort (); |
1963 s->size = sizeof ELF_DYNAMIC_INTERPRETER; | 2017 s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
1964 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; | 2018 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
1965 } | 2019 } |
1966 } | 2020 } |
1967 | 2021 |
1968 /* Set up .got offsets for local syms, and space for local dynamic | 2022 /* Set up .got offsets for local syms, and space for local dynamic |
1969 relocs. */ | 2023 relocs. */ |
1970 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) | 2024 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
1971 { | 2025 { |
1972 bfd_signed_vma *local_got; | 2026 bfd_signed_vma *local_got; |
1973 bfd_signed_vma *end_local_got; | 2027 bfd_signed_vma *end_local_got; |
1974 char *local_tls_type; | 2028 char *local_tls_type; |
1975 bfd_size_type locsymcount; | 2029 bfd_size_type locsymcount; |
1976 Elf_Internal_Shdr *symtab_hdr; | 2030 Elf_Internal_Shdr *symtab_hdr; |
1977 asection *srela; | 2031 asection *srela; |
| 2032 struct plt_entry *local_plt; |
| 2033 unsigned int i; |
1978 | 2034 |
1979 if (! is_s390_elf (ibfd)) | 2035 if (! is_s390_elf (ibfd)) |
1980 continue; | 2036 continue; |
1981 | 2037 |
1982 for (s = ibfd->sections; s != NULL; s = s->next) | 2038 for (s = ibfd->sections; s != NULL; s = s->next) |
1983 { | 2039 { |
1984 » struct elf_s390_dyn_relocs *p; | 2040 » struct elf_dyn_relocs *p; |
1985 | 2041 |
1986 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) | 2042 for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next) |
1987 { | 2043 { |
1988 if (!bfd_is_abs_section (p->sec) | 2044 if (!bfd_is_abs_section (p->sec) |
1989 && bfd_is_abs_section (p->sec->output_section)) | 2045 && bfd_is_abs_section (p->sec->output_section)) |
1990 { | 2046 { |
1991 /* Input section has been discarded, either because | 2047 /* Input section has been discarded, either because |
1992 it is a copy of a linkonce section or due to | 2048 it is a copy of a linkonce section or due to |
1993 linker script /DISCARD/, so we'll be discarding | 2049 linker script /DISCARD/, so we'll be discarding |
1994 the relocs too. */ | 2050 the relocs too. */ |
1995 } | 2051 } |
1996 else if (p->count != 0) | 2052 else if (p->count != 0) |
1997 { | 2053 { |
1998 srela = elf_section_data (p->sec)->sreloc; | 2054 srela = elf_section_data (p->sec)->sreloc; |
1999 srela->size += p->count * sizeof (Elf32_External_Rela); | 2055 srela->size += p->count * sizeof (Elf32_External_Rela); |
2000 if ((p->sec->output_section->flags & SEC_READONLY) != 0) | 2056 if ((p->sec->output_section->flags & SEC_READONLY) != 0) |
2001 info->flags |= DF_TEXTREL; | 2057 info->flags |= DF_TEXTREL; |
2002 } | 2058 } |
2003 } | 2059 } |
2004 } | 2060 } |
2005 | 2061 |
2006 local_got = elf_local_got_refcounts (ibfd); | 2062 local_got = elf_local_got_refcounts (ibfd); |
2007 if (!local_got) | 2063 if (!local_got) |
2008 continue; | 2064 continue; |
2009 | 2065 |
2010 symtab_hdr = &elf_symtab_hdr (ibfd); | 2066 symtab_hdr = &elf_symtab_hdr (ibfd); |
2011 locsymcount = symtab_hdr->sh_info; | 2067 locsymcount = symtab_hdr->sh_info; |
2012 end_local_got = local_got + locsymcount; | 2068 end_local_got = local_got + locsymcount; |
2013 local_tls_type = elf_s390_local_got_tls_type (ibfd); | 2069 local_tls_type = elf_s390_local_got_tls_type (ibfd); |
2014 s = htab->sgot; | 2070 s = htab->elf.sgot; |
2015 srela = htab->srelgot; | 2071 srela = htab->elf.srelgot; |
2016 for (; local_got < end_local_got; ++local_got, ++local_tls_type) | 2072 for (; local_got < end_local_got; ++local_got, ++local_tls_type) |
2017 { | 2073 { |
2018 if (*local_got > 0) | 2074 if (*local_got > 0) |
2019 { | 2075 { |
2020 *local_got = s->size; | 2076 *local_got = s->size; |
2021 s->size += GOT_ENTRY_SIZE; | 2077 s->size += GOT_ENTRY_SIZE; |
2022 if (*local_tls_type == GOT_TLS_GD) | 2078 if (*local_tls_type == GOT_TLS_GD) |
2023 s->size += GOT_ENTRY_SIZE; | 2079 s->size += GOT_ENTRY_SIZE; |
2024 if (info->shared) | 2080 if (info->shared) |
2025 srela->size += sizeof (Elf32_External_Rela); | 2081 srela->size += sizeof (Elf32_External_Rela); |
2026 } | 2082 } |
2027 else | 2083 else |
2028 *local_got = (bfd_vma) -1; | 2084 *local_got = (bfd_vma) -1; |
2029 } | 2085 } |
| 2086 local_plt = elf_s390_local_plt (ibfd); |
| 2087 for (i = 0; i < symtab_hdr->sh_info; i++) |
| 2088 { |
| 2089 if (local_plt[i].plt.refcount > 0) |
| 2090 { |
| 2091 local_plt[i].plt.offset = htab->elf.iplt->size; |
| 2092 htab->elf.iplt->size += PLT_ENTRY_SIZE; |
| 2093 htab->elf.igotplt->size += GOT_ENTRY_SIZE; |
| 2094 htab->elf.irelplt->size += RELA_ENTRY_SIZE; |
| 2095 } |
| 2096 else |
| 2097 local_plt[i].plt.offset = (bfd_vma) -1; |
| 2098 } |
2030 } | 2099 } |
2031 | 2100 |
2032 if (htab->tls_ldm_got.refcount > 0) | 2101 if (htab->tls_ldm_got.refcount > 0) |
2033 { | 2102 { |
2034 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32 | 2103 /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM32 |
2035 relocs. */ | 2104 relocs. */ |
2036 htab->tls_ldm_got.offset = htab->sgot->size; | 2105 htab->tls_ldm_got.offset = htab->elf.sgot->size; |
2037 htab->sgot->size += 2 * GOT_ENTRY_SIZE; | 2106 htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE; |
2038 htab->srelgot->size += sizeof (Elf32_External_Rela); | 2107 htab->elf.srelgot->size += sizeof (Elf32_External_Rela); |
2039 } | 2108 } |
2040 else | 2109 else |
2041 htab->tls_ldm_got.offset = -1; | 2110 htab->tls_ldm_got.offset = -1; |
2042 | 2111 |
2043 /* Allocate global sym .plt and .got entries, and space for global | 2112 /* Allocate global sym .plt and .got entries, and space for global |
2044 sym dynamic relocs. */ | 2113 sym dynamic relocs. */ |
2045 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); | 2114 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info); |
2046 | 2115 |
2047 /* We now have determined the sizes of the various dynamic sections. | 2116 /* We now have determined the sizes of the various dynamic sections. |
2048 Allocate memory for them. */ | 2117 Allocate memory for them. */ |
2049 relocs = FALSE; | 2118 relocs = FALSE; |
2050 for (s = dynobj->sections; s != NULL; s = s->next) | 2119 for (s = dynobj->sections; s != NULL; s = s->next) |
2051 { | 2120 { |
2052 if ((s->flags & SEC_LINKER_CREATED) == 0) | 2121 if ((s->flags & SEC_LINKER_CREATED) == 0) |
2053 continue; | 2122 continue; |
2054 | 2123 |
2055 if (s == htab->splt | 2124 if (s == htab->elf.splt |
2056 » || s == htab->sgot | 2125 » || s == htab->elf.sgot |
2057 » || s == htab->sgotplt | 2126 » || s == htab->elf.sgotplt |
2058 » || s == htab->sdynbss) | 2127 » || s == htab->sdynbss |
| 2128 » || s == htab->elf.iplt |
| 2129 » || s == htab->elf.igotplt |
| 2130 » || s == htab->irelifunc) |
2059 { | 2131 { |
2060 /* Strip this section if we don't need it; see the | 2132 /* Strip this section if we don't need it; see the |
2061 comment below. */ | 2133 comment below. */ |
2062 } | 2134 } |
2063 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) | 2135 else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) |
2064 { | 2136 { |
2065 if (s->size != 0) | 2137 if (s->size != 0) |
2066 relocs = TRUE; | 2138 relocs = TRUE; |
2067 | 2139 |
2068 /* We use the reloc_count field as a counter if we need | 2140 /* We use the reloc_count field as a counter if we need |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2113 dynamic linker and used by the debugger. */ | 2185 dynamic linker and used by the debugger. */ |
2114 #define add_dynamic_entry(TAG, VAL) \ | 2186 #define add_dynamic_entry(TAG, VAL) \ |
2115 _bfd_elf_add_dynamic_entry (info, TAG, VAL) | 2187 _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
2116 | 2188 |
2117 if (info->executable) | 2189 if (info->executable) |
2118 { | 2190 { |
2119 if (!add_dynamic_entry (DT_DEBUG, 0)) | 2191 if (!add_dynamic_entry (DT_DEBUG, 0)) |
2120 return FALSE; | 2192 return FALSE; |
2121 } | 2193 } |
2122 | 2194 |
2123 if (htab->splt->size != 0) | 2195 if (htab->elf.splt->size != 0) |
2124 { | 2196 { |
2125 if (!add_dynamic_entry (DT_PLTGOT, 0) | 2197 if (!add_dynamic_entry (DT_PLTGOT, 0) |
2126 || !add_dynamic_entry (DT_PLTRELSZ, 0) | 2198 || !add_dynamic_entry (DT_PLTRELSZ, 0) |
2127 || !add_dynamic_entry (DT_PLTREL, DT_RELA) | 2199 || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
2128 || !add_dynamic_entry (DT_JMPREL, 0)) | 2200 || !add_dynamic_entry (DT_JMPREL, 0)) |
2129 return FALSE; | 2201 return FALSE; |
2130 } | 2202 } |
2131 | 2203 |
2132 if (relocs) | 2204 if (relocs) |
2133 { | 2205 { |
2134 if (!add_dynamic_entry (DT_RELA, 0) | 2206 if (!add_dynamic_entry (DT_RELA, 0) |
2135 || !add_dynamic_entry (DT_RELASZ, 0) | 2207 || !add_dynamic_entry (DT_RELASZ, 0) |
2136 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) | 2208 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) |
2137 return FALSE; | 2209 return FALSE; |
2138 | 2210 |
2139 /* If any dynamic relocs apply to a read-only section, | 2211 /* If any dynamic relocs apply to a read-only section, |
2140 then we need a DT_TEXTREL entry. */ | 2212 then we need a DT_TEXTREL entry. */ |
2141 if ((info->flags & DF_TEXTREL) == 0) | 2213 if ((info->flags & DF_TEXTREL) == 0) |
2142 » elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, | 2214 » elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, info); |
2143 » » » » (PTR) info); | |
2144 | 2215 |
2145 if ((info->flags & DF_TEXTREL) != 0) | 2216 if ((info->flags & DF_TEXTREL) != 0) |
2146 { | 2217 { |
2147 if (!add_dynamic_entry (DT_TEXTREL, 0)) | 2218 if (!add_dynamic_entry (DT_TEXTREL, 0)) |
2148 return FALSE; | 2219 return FALSE; |
2149 } | 2220 } |
2150 } | 2221 } |
2151 } | 2222 } |
2152 #undef add_dynamic_entry | 2223 #undef add_dynamic_entry |
2153 | 2224 |
2154 return TRUE; | 2225 return TRUE; |
2155 } | 2226 } |
2156 | 2227 |
2157 /* Return the base VMA address which should be subtracted from real addresses | 2228 /* Return the base VMA address which should be subtracted from real addresses |
2158 when resolving @dtpoff relocation. | 2229 when resolving @dtpoff relocation. |
2159 This is PT_TLS segment p_vaddr. */ | 2230 This is PT_TLS segment p_vaddr. */ |
2160 | 2231 |
2161 static bfd_vma | 2232 static bfd_vma |
2162 dtpoff_base (info) | 2233 dtpoff_base (struct bfd_link_info *info) |
2163 struct bfd_link_info *info; | |
2164 { | 2234 { |
2165 /* If tls_sec is NULL, we should have signalled an error already. */ | 2235 /* If tls_sec is NULL, we should have signalled an error already. */ |
2166 if (elf_hash_table (info)->tls_sec == NULL) | 2236 if (elf_hash_table (info)->tls_sec == NULL) |
2167 return 0; | 2237 return 0; |
2168 return elf_hash_table (info)->tls_sec->vma; | 2238 return elf_hash_table (info)->tls_sec->vma; |
2169 } | 2239 } |
2170 | 2240 |
2171 /* Return the relocation value for @tpoff relocation | 2241 /* Return the relocation value for @tpoff relocation |
2172 if STT_TLS virtual address is ADDRESS. */ | 2242 if STT_TLS virtual address is ADDRESS. */ |
2173 | 2243 |
2174 static bfd_vma | 2244 static bfd_vma |
2175 tpoff (info, address) | 2245 tpoff (struct bfd_link_info *info, bfd_vma address) |
2176 struct bfd_link_info *info; | |
2177 bfd_vma address; | |
2178 { | 2246 { |
2179 struct elf_link_hash_table *htab = elf_hash_table (info); | 2247 struct elf_link_hash_table *htab = elf_hash_table (info); |
2180 | 2248 |
2181 /* If tls_sec is NULL, we should have signalled an error already. */ | 2249 /* If tls_sec is NULL, we should have signalled an error already. */ |
2182 if (htab->tls_sec == NULL) | 2250 if (htab->tls_sec == NULL) |
2183 return 0; | 2251 return 0; |
2184 return htab->tls_size + htab->tls_sec->vma - address; | 2252 return htab->tls_size + htab->tls_sec->vma - address; |
2185 } | 2253 } |
2186 | 2254 |
2187 /* Complain if TLS instruction relocation is against an invalid | 2255 /* Complain if TLS instruction relocation is against an invalid |
2188 instruction. */ | 2256 instruction. */ |
2189 | 2257 |
2190 static void | 2258 static void |
2191 invalid_tls_insn (input_bfd, input_section, rel) | 2259 invalid_tls_insn (bfd *input_bfd, |
2192 bfd *input_bfd; | 2260 » » asection *input_section, |
2193 asection *input_section; | 2261 » » Elf_Internal_Rela *rel) |
2194 Elf_Internal_Rela *rel; | |
2195 { | 2262 { |
2196 reloc_howto_type *howto; | 2263 reloc_howto_type *howto; |
2197 | 2264 |
2198 howto = elf_howto_table + ELF32_R_TYPE (rel->r_info); | 2265 howto = elf_howto_table + ELF32_R_TYPE (rel->r_info); |
2199 (*_bfd_error_handler) | 2266 (*_bfd_error_handler) |
2200 (_("%B(%A+0x%lx): invalid instruction for TLS relocation %s"), | 2267 (_("%B(%A+0x%lx): invalid instruction for TLS relocation %s"), |
2201 input_bfd, | 2268 input_bfd, |
2202 input_section, | 2269 input_section, |
2203 (long) rel->r_offset, | 2270 (long) rel->r_offset, |
2204 howto->name); | 2271 howto->name); |
2205 bfd_set_error (bfd_error_bad_value); | 2272 bfd_set_error (bfd_error_bad_value); |
2206 } | 2273 } |
2207 | 2274 |
2208 /* Relocate a 390 ELF section. */ | 2275 /* Relocate a 390 ELF section. */ |
2209 | 2276 |
2210 static bfd_boolean | 2277 static bfd_boolean |
2211 elf_s390_relocate_section (output_bfd, info, input_bfd, input_section, | 2278 elf_s390_relocate_section (bfd *output_bfd, |
2212 » » » contents, relocs, local_syms, local_sections) | 2279 » » » struct bfd_link_info *info, |
2213 bfd *output_bfd; | 2280 » » » bfd *input_bfd, |
2214 struct bfd_link_info *info; | 2281 » » » asection *input_section, |
2215 bfd *input_bfd; | 2282 » » » bfd_byte *contents, |
2216 asection *input_section; | 2283 » » » Elf_Internal_Rela *relocs, |
2217 bfd_byte *contents; | 2284 » » » Elf_Internal_Sym *local_syms, |
2218 Elf_Internal_Rela *relocs; | 2285 » » » asection **local_sections) |
2219 Elf_Internal_Sym *local_syms; | |
2220 asection **local_sections; | |
2221 { | 2286 { |
2222 struct elf_s390_link_hash_table *htab; | 2287 struct elf_s390_link_hash_table *htab; |
2223 Elf_Internal_Shdr *symtab_hdr; | 2288 Elf_Internal_Shdr *symtab_hdr; |
2224 struct elf_link_hash_entry **sym_hashes; | 2289 struct elf_link_hash_entry **sym_hashes; |
2225 bfd_vma *local_got_offsets; | 2290 bfd_vma *local_got_offsets; |
2226 Elf_Internal_Rela *rel; | 2291 Elf_Internal_Rela *rel; |
2227 Elf_Internal_Rela *relend; | 2292 Elf_Internal_Rela *relend; |
2228 | 2293 |
2229 BFD_ASSERT (is_s390_elf (input_bfd)); | 2294 BFD_ASSERT (is_s390_elf (input_bfd)); |
2230 | 2295 |
(...skipping 10 matching lines...) Expand all Loading... |
2241 reloc_howto_type *howto; | 2306 reloc_howto_type *howto; |
2242 unsigned long r_symndx; | 2307 unsigned long r_symndx; |
2243 struct elf_link_hash_entry *h; | 2308 struct elf_link_hash_entry *h; |
2244 Elf_Internal_Sym *sym; | 2309 Elf_Internal_Sym *sym; |
2245 asection *sec; | 2310 asection *sec; |
2246 bfd_vma off; | 2311 bfd_vma off; |
2247 bfd_vma relocation; | 2312 bfd_vma relocation; |
2248 bfd_boolean unresolved_reloc; | 2313 bfd_boolean unresolved_reloc; |
2249 bfd_reloc_status_type r; | 2314 bfd_reloc_status_type r; |
2250 int tls_type; | 2315 int tls_type; |
| 2316 asection *base_got = htab->elf.sgot; |
2251 | 2317 |
2252 r_type = ELF32_R_TYPE (rel->r_info); | 2318 r_type = ELF32_R_TYPE (rel->r_info); |
2253 if (r_type == (int) R_390_GNU_VTINHERIT | 2319 if (r_type == (int) R_390_GNU_VTINHERIT |
2254 || r_type == (int) R_390_GNU_VTENTRY) | 2320 || r_type == (int) R_390_GNU_VTENTRY) |
2255 continue; | 2321 continue; |
2256 if (r_type >= (int) R_390_max) | 2322 if (r_type >= (int) R_390_max) |
2257 { | 2323 { |
2258 bfd_set_error (bfd_error_bad_value); | 2324 bfd_set_error (bfd_error_bad_value); |
2259 return FALSE; | 2325 return FALSE; |
2260 } | 2326 } |
2261 | 2327 |
2262 howto = elf_howto_table + r_type; | 2328 howto = elf_howto_table + r_type; |
2263 r_symndx = ELF32_R_SYM (rel->r_info); | 2329 r_symndx = ELF32_R_SYM (rel->r_info); |
2264 | 2330 |
2265 h = NULL; | 2331 h = NULL; |
2266 sym = NULL; | 2332 sym = NULL; |
2267 sec = NULL; | 2333 sec = NULL; |
2268 unresolved_reloc = FALSE; | 2334 unresolved_reloc = FALSE; |
2269 if (r_symndx < symtab_hdr->sh_info) | 2335 if (r_symndx < symtab_hdr->sh_info) |
2270 { | 2336 { |
2271 sym = local_syms + r_symndx; | 2337 sym = local_syms + r_symndx; |
2272 sec = local_sections[r_symndx]; | 2338 sec = local_sections[r_symndx]; |
2273 » relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); | 2339 » if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC) |
| 2340 » { |
| 2341 » struct plt_entry *local_plt = elf_s390_local_plt (input_bfd); |
| 2342 » if (local_plt == NULL) |
| 2343 » » return FALSE; |
| 2344 |
| 2345 » /* Address of the PLT slot. */ |
| 2346 » relocation = (htab->elf.iplt->output_section->vma |
| 2347 » » » + htab->elf.iplt->output_offset |
| 2348 » » » + local_plt[r_symndx].plt.offset); |
| 2349 |
| 2350 » switch (r_type) |
| 2351 » » { |
| 2352 » » case R_390_GOTPLT12: |
| 2353 » » case R_390_GOTPLT16: |
| 2354 » » case R_390_GOTPLT20: |
| 2355 » » case R_390_GOTPLT32: |
| 2356 » » case R_390_GOTPLTENT: |
| 2357 » » case R_390_GOT12: |
| 2358 » » case R_390_GOT16: |
| 2359 » » case R_390_GOT20: |
| 2360 » » case R_390_GOT32: |
| 2361 » » case R_390_GOTENT: |
| 2362 » » { |
| 2363 » » /* Write the PLT slot address into the GOT slot. */ |
| 2364 » » bfd_put_32 (output_bfd, relocation, |
| 2365 » » » » htab->elf.sgot->contents + |
| 2366 » » » » local_got_offsets[r_symndx]); |
| 2367 » » relocation = (local_got_offsets[r_symndx] + |
| 2368 » » » » htab->elf.sgot->output_offset); |
| 2369 |
| 2370 » » if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT) |
| 2371 » » relocation += htab->elf.sgot->output_section->vma; |
| 2372 » » break; |
| 2373 » » } |
| 2374 » » default: |
| 2375 » » break; |
| 2376 » » } |
| 2377 » /* The output section is needed later in |
| 2378 » » finish_dynamic_section when creating the dynamic |
| 2379 » » relocation. */ |
| 2380 » local_plt[r_symndx].sec = sec; |
| 2381 » goto do_relocation; |
| 2382 » } |
| 2383 » else |
| 2384 » relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
2274 } | 2385 } |
2275 else | 2386 else |
2276 { | 2387 { |
2277 bfd_boolean warned ATTRIBUTE_UNUSED; | 2388 bfd_boolean warned ATTRIBUTE_UNUSED; |
2278 | 2389 |
2279 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, | 2390 RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
2280 r_symndx, symtab_hdr, sym_hashes, | 2391 r_symndx, symtab_hdr, sym_hashes, |
2281 h, sec, relocation, | 2392 h, sec, relocation, |
2282 unresolved_reloc, warned); | 2393 unresolved_reloc, warned); |
2283 } | 2394 } |
2284 | 2395 |
2285 if (sec != NULL && elf_discarded_section (sec)) | 2396 if (sec != NULL && discarded_section (sec)) |
2286 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, | 2397 RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, |
2287 » » » » » rel, relend, howto, contents); | 2398 » » » » » rel, 1, relend, howto, 0, contents); |
2288 | 2399 |
2289 if (info->relocatable) | 2400 if (info->relocatable) |
2290 continue; | 2401 continue; |
2291 | 2402 |
2292 switch (r_type) | 2403 switch (r_type) |
2293 { | 2404 { |
2294 case R_390_GOTPLT12: | 2405 case R_390_GOTPLT12: |
2295 case R_390_GOTPLT16: | 2406 case R_390_GOTPLT16: |
2296 case R_390_GOTPLT20: | 2407 case R_390_GOTPLT20: |
2297 case R_390_GOTPLT32: | 2408 case R_390_GOTPLT32: |
2298 case R_390_GOTPLTENT: | 2409 case R_390_GOTPLTENT: |
2299 /* There are three cases for a GOTPLT relocation. 1) The | 2410 /* There are three cases for a GOTPLT relocation. 1) The |
2300 relocation is against the jump slot entry of a plt that | 2411 relocation is against the jump slot entry of a plt that |
2301 will get emitted to the output file. 2) The relocation | 2412 will get emitted to the output file. 2) The relocation |
2302 is against the jump slot of a plt entry that has been | 2413 is against the jump slot of a plt entry that has been |
2303 removed. elf_s390_adjust_gotplt has created a GOT entry | 2414 removed. elf_s390_adjust_gotplt has created a GOT entry |
2304 as replacement. 3) The relocation is against a local symbol. | 2415 as replacement. 3) The relocation is against a local symbol. |
2305 Cases 2) and 3) are the same as the GOT relocation code | 2416 Cases 2) and 3) are the same as the GOT relocation code |
2306 so we just have to test for case 1 and fall through for | 2417 so we just have to test for case 1 and fall through for |
2307 the other two. */ | 2418 the other two. */ |
2308 if (h != NULL && h->plt.offset != (bfd_vma) -1) | 2419 if (h != NULL && h->plt.offset != (bfd_vma) -1) |
2309 { | 2420 { |
2310 bfd_vma plt_index; | 2421 bfd_vma plt_index; |
2311 | 2422 |
2312 » /* Calc. index no. | 2423 » if (s390_is_ifunc_symbol_p (h)) |
2313 » » Current offset - size first entry / entry size. */ | 2424 » » { |
2314 » plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / | 2425 » » plt_index = h->plt.offset / PLT_ENTRY_SIZE; |
2315 » » PLT_ENTRY_SIZE; | 2426 » » relocation = (plt_index * GOT_ENTRY_SIZE + |
| 2427 » » » » htab->elf.igotplt->output_offset); |
| 2428 » » if (r_type == R_390_GOTPLTENT) |
| 2429 » » relocation += htab->elf.igotplt->output_section->vma; |
| 2430 » » } |
| 2431 » else |
| 2432 » » { |
| 2433 » » /* Calc. index no. |
| 2434 » » Current offset - size first entry / entry size. */ |
| 2435 » » plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / |
| 2436 » » PLT_ENTRY_SIZE; |
2316 | 2437 |
2317 » /* Offset in GOT is PLT index plus GOT headers(3) times 4, | 2438 » » /* Offset in GOT is PLT index plus GOT headers(3) |
2318 » » addr & GOT addr. */ | 2439 » » times 4, addr & GOT addr. */ |
2319 » relocation = (plt_index + 3) * GOT_ENTRY_SIZE; | 2440 » » relocation = (plt_index + 3) * GOT_ENTRY_SIZE; |
| 2441 » » if (r_type == R_390_GOTPLTENT) |
| 2442 » » relocation += htab->elf.sgot->output_section->vma; |
| 2443 » » } |
2320 unresolved_reloc = FALSE; | 2444 unresolved_reloc = FALSE; |
2321 | 2445 |
2322 if (r_type == R_390_GOTPLTENT) | |
2323 relocation += htab->sgot->output_section->vma; | |
2324 break; | |
2325 } | 2446 } |
2326 /* Fall through. */ | 2447 /* Fall through. */ |
2327 | 2448 |
2328 case R_390_GOT12: | 2449 case R_390_GOT12: |
2329 case R_390_GOT16: | 2450 case R_390_GOT16: |
2330 case R_390_GOT20: | 2451 case R_390_GOT20: |
2331 case R_390_GOT32: | 2452 case R_390_GOT32: |
2332 case R_390_GOTENT: | 2453 case R_390_GOTENT: |
2333 /* Relocation is to the entry for this symbol in the global | 2454 /* Relocation is to the entry for this symbol in the global |
2334 offset table. */ | 2455 offset table. */ |
2335 » if (htab->sgot == NULL) | 2456 » if (base_got == NULL) |
2336 abort (); | 2457 abort (); |
2337 | 2458 |
2338 if (h != NULL) | 2459 if (h != NULL) |
2339 { | 2460 { |
2340 bfd_boolean dyn; | 2461 bfd_boolean dyn; |
2341 | 2462 |
2342 off = h->got.offset; | 2463 off = h->got.offset; |
2343 dyn = htab->elf.dynamic_sections_created; | 2464 dyn = htab->elf.dynamic_sections_created; |
2344 » if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) | 2465 |
2345 » » || (info->shared | 2466 » if (s390_is_ifunc_symbol_p (h)) |
2346 » » && SYMBOL_REFERENCES_LOCAL (info, h)) | 2467 » » { |
2347 » » || (ELF_ST_VISIBILITY (h->other) | 2468 » » BFD_ASSERT (h->plt.offset != (bfd_vma) -1); |
2348 » » && h->root.type == bfd_link_hash_undefweak)) | 2469 » » if (off == (bfd_vma)-1) |
| 2470 » » { |
| 2471 » » /* No explicit GOT usage so redirect to the |
| 2472 » » » got.iplt slot. */ |
| 2473 » » base_got = htab->elf.igotplt; |
| 2474 » » off = h->plt.offset / PLT_ENTRY_SIZE * GOT_ENTRY_SIZE; |
| 2475 » » } |
| 2476 » » else |
| 2477 » » { |
| 2478 » » /* Explicit GOT slots must contain the address |
| 2479 » » » of the PLT slot. This will be handled in |
| 2480 » » » finish_dynamic_symbol. */ |
| 2481 » » } |
| 2482 » » } |
| 2483 » else if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 2484 » » || (info->shared |
| 2485 » » » && SYMBOL_REFERENCES_LOCAL (info, h)) |
| 2486 » » || (ELF_ST_VISIBILITY (h->other) |
| 2487 » » » && h->root.type == bfd_link_hash_undefweak)) |
| 2488 |
2349 { | 2489 { |
2350 /* This is actually a static link, or it is a | 2490 /* This is actually a static link, or it is a |
2351 -Bsymbolic link and the symbol is defined | 2491 -Bsymbolic link and the symbol is defined |
2352 locally, or the symbol was forced to be local | 2492 locally, or the symbol was forced to be local |
2353 because of a version file. We must initialize | 2493 because of a version file. We must initialize |
2354 this entry in the global offset table. Since the | 2494 this entry in the global offset table. Since the |
2355 offset must always be a multiple of 2, we use the | 2495 offset must always be a multiple of 2, we use the |
2356 least significant bit to record whether we have | 2496 least significant bit to record whether we have |
2357 initialized it already. | 2497 initialized it already. |
2358 | 2498 |
2359 When doing a dynamic link, we create a .rel.got | 2499 When doing a dynamic link, we create a .rel.got |
2360 relocation entry to initialize the value. This | 2500 relocation entry to initialize the value. This |
2361 is done in the finish_dynamic_symbol routine. */ | 2501 is done in the finish_dynamic_symbol routine. */ |
2362 if ((off & 1) != 0) | 2502 if ((off & 1) != 0) |
2363 off &= ~1; | 2503 off &= ~1; |
2364 else | 2504 else |
2365 { | 2505 { |
2366 bfd_put_32 (output_bfd, relocation, | 2506 bfd_put_32 (output_bfd, relocation, |
2367 » » » » htab->sgot->contents + off); | 2507 » » » » base_got->contents + off); |
2368 h->got.offset |= 1; | 2508 h->got.offset |= 1; |
2369 } | 2509 } |
2370 } | 2510 } |
2371 else | 2511 else |
2372 unresolved_reloc = FALSE; | 2512 unresolved_reloc = FALSE; |
2373 } | 2513 } |
2374 else | 2514 else |
2375 { | 2515 { |
2376 if (local_got_offsets == NULL) | 2516 if (local_got_offsets == NULL) |
2377 abort (); | 2517 abort (); |
2378 | 2518 |
2379 off = local_got_offsets[r_symndx]; | 2519 off = local_got_offsets[r_symndx]; |
2380 | 2520 |
2381 /* The offset must always be a multiple of 4. We use | 2521 /* The offset must always be a multiple of 4. We use |
2382 the least significant bit to record whether we have | 2522 the least significant bit to record whether we have |
2383 already generated the necessary reloc. */ | 2523 already generated the necessary reloc. */ |
2384 if ((off & 1) != 0) | 2524 if ((off & 1) != 0) |
2385 off &= ~1; | 2525 off &= ~1; |
2386 else | 2526 else |
2387 { | 2527 { |
2388 bfd_put_32 (output_bfd, relocation, | 2528 bfd_put_32 (output_bfd, relocation, |
2389 » » » htab->sgot->contents + off); | 2529 » » » htab->elf.sgot->contents + off); |
2390 | 2530 |
2391 if (info->shared) | 2531 if (info->shared) |
2392 { | 2532 { |
2393 asection *srelgot; | 2533 asection *srelgot; |
2394 Elf_Internal_Rela outrel; | 2534 Elf_Internal_Rela outrel; |
2395 bfd_byte *loc; | 2535 bfd_byte *loc; |
2396 | 2536 |
2397 » » srelgot = htab->srelgot; | 2537 » » srelgot = htab->elf.srelgot; |
2398 if (srelgot == NULL) | 2538 if (srelgot == NULL) |
2399 abort (); | 2539 abort (); |
2400 | 2540 |
2401 » » outrel.r_offset = (htab->sgot->output_section->vma | 2541 » » outrel.r_offset = (htab->elf.sgot->output_section->vma |
2402 » » » » » + htab->sgot->output_offset | 2542 » » » » » + htab->elf.sgot->output_offset |
2403 + off); | 2543 + off); |
2404 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); | 2544 outrel.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
2405 outrel.r_addend = relocation; | 2545 outrel.r_addend = relocation; |
2406 loc = srelgot->contents; | 2546 loc = srelgot->contents; |
2407 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel
a); | 2547 loc += srelgot->reloc_count++ * sizeof (Elf32_External_Rel
a); |
2408 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | 2548 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
2409 } | 2549 } |
2410 | 2550 |
2411 local_got_offsets[r_symndx] |= 1; | 2551 local_got_offsets[r_symndx] |= 1; |
2412 } | 2552 } |
2413 } | 2553 } |
2414 | 2554 |
2415 if (off >= (bfd_vma) -2) | 2555 if (off >= (bfd_vma) -2) |
2416 abort (); | 2556 abort (); |
2417 | 2557 |
2418 » relocation = htab->sgot->output_offset + off; | 2558 » relocation = base_got->output_offset + off; |
2419 | 2559 |
2420 /* For @GOTENT the relocation is against the offset between | 2560 /* For @GOTENT the relocation is against the offset between |
2421 the instruction and the symbols entry in the GOT and not | 2561 the instruction and the symbols entry in the GOT and not |
2422 between the start of the GOT and the symbols entry. We | 2562 between the start of the GOT and the symbols entry. We |
2423 add the vma of the GOT to get the correct value. */ | 2563 add the vma of the GOT to get the correct value. */ |
2424 if ( r_type == R_390_GOTENT | 2564 if ( r_type == R_390_GOTENT |
2425 || r_type == R_390_GOTPLTENT) | 2565 || r_type == R_390_GOTPLTENT) |
2426 » relocation += htab->sgot->output_section->vma; | 2566 » relocation += base_got->output_section->vma; |
2427 | 2567 |
2428 break; | 2568 break; |
2429 | 2569 |
2430 case R_390_GOTOFF16: | 2570 case R_390_GOTOFF16: |
2431 case R_390_GOTOFF32: | 2571 case R_390_GOTOFF32: |
2432 /* Relocation is relative to the start of the global offset | 2572 /* Relocation is relative to the start of the global offset |
2433 table. */ | 2573 table. */ |
2434 | 2574 |
2435 /* Note that sgot->output_offset is not involved in this | 2575 /* Note that sgot->output_offset is not involved in this |
2436 calculation. We always want the start of .got. If we | 2576 calculation. We always want the start of .got. If we |
2437 defined _GLOBAL_OFFSET_TABLE in a different way, as is | 2577 defined _GLOBAL_OFFSET_TABLE in a different way, as is |
2438 permitted by the ABI, we might have to change this | 2578 permitted by the ABI, we might have to change this |
2439 calculation. */ | 2579 calculation. */ |
2440 » relocation -= htab->sgot->output_section->vma; | 2580 » relocation -= htab->elf.sgot->output_section->vma; |
2441 break; | 2581 break; |
2442 | 2582 |
2443 case R_390_GOTPC: | 2583 case R_390_GOTPC: |
2444 case R_390_GOTPCDBL: | 2584 case R_390_GOTPCDBL: |
2445 /* Use global offset table as symbol value. */ | 2585 /* Use global offset table as symbol value. */ |
2446 » relocation = htab->sgot->output_section->vma; | 2586 » relocation = htab->elf.sgot->output_section->vma; |
2447 unresolved_reloc = FALSE; | 2587 unresolved_reloc = FALSE; |
2448 break; | 2588 break; |
2449 | 2589 |
2450 case R_390_PLT16DBL: | 2590 case R_390_PLT16DBL: |
2451 case R_390_PLT32DBL: | 2591 case R_390_PLT32DBL: |
2452 case R_390_PLT32: | 2592 case R_390_PLT32: |
2453 /* Relocation is to the entry for this symbol in the | 2593 /* Relocation is to the entry for this symbol in the |
2454 procedure linkage table. */ | 2594 procedure linkage table. */ |
2455 | 2595 |
2456 /* Resolve a PLT32 reloc against a local symbol directly, | 2596 /* Resolve a PLT32 reloc against a local symbol directly, |
2457 without using the procedure linkage table. */ | 2597 without using the procedure linkage table. */ |
2458 if (h == NULL) | 2598 if (h == NULL) |
2459 break; | 2599 break; |
2460 | 2600 |
2461 if (h->plt.offset == (bfd_vma) -1 | 2601 if (h->plt.offset == (bfd_vma) -1 |
2462 » || htab->splt == NULL) | 2602 » || (htab->elf.splt == NULL && htab->elf.iplt == NULL)) |
2463 { | 2603 { |
2464 /* We didn't make a PLT entry for this symbol. This | 2604 /* We didn't make a PLT entry for this symbol. This |
2465 happens when statically linking PIC code, or when | 2605 happens when statically linking PIC code, or when |
2466 using -Bsymbolic. */ | 2606 using -Bsymbolic. */ |
2467 break; | 2607 break; |
2468 } | 2608 } |
2469 | 2609 |
2470 » relocation = (htab->splt->output_section->vma | 2610 » if (s390_is_ifunc_symbol_p (h)) |
2471 » » » + htab->splt->output_offset | 2611 » relocation = (htab->elf.iplt->output_section->vma |
2472 » » » + h->plt.offset); | 2612 + htab->elf.iplt->output_offset |
| 2613 » » » + h->plt.offset); |
| 2614 » else |
| 2615 » relocation = (htab->elf.splt->output_section->vma |
| 2616 » » » + htab->elf.splt->output_offset |
| 2617 » » » + h->plt.offset); |
2473 unresolved_reloc = FALSE; | 2618 unresolved_reloc = FALSE; |
2474 break; | 2619 break; |
2475 | 2620 |
2476 case R_390_PLTOFF16: | 2621 case R_390_PLTOFF16: |
2477 case R_390_PLTOFF32: | 2622 case R_390_PLTOFF32: |
2478 /* Relocation is to the entry for this symbol in the | 2623 /* Relocation is to the entry for this symbol in the |
2479 procedure linkage table relative to the start of the GOT. */ | 2624 procedure linkage table relative to the start of the GOT. */ |
2480 | 2625 |
2481 /* For local symbols or if we didn't make a PLT entry for | 2626 /* For local symbols or if we didn't make a PLT entry for |
2482 this symbol resolve the symbol directly. */ | 2627 this symbol resolve the symbol directly. */ |
2483 if ( h == NULL | 2628 if ( h == NULL |
2484 || h->plt.offset == (bfd_vma) -1 | 2629 || h->plt.offset == (bfd_vma) -1 |
2485 » || htab->splt == NULL) | 2630 » || htab->elf.splt == NULL) |
2486 { | 2631 { |
2487 » relocation -= htab->sgot->output_section->vma; | 2632 » relocation -= htab->elf.sgot->output_section->vma; |
2488 break; | 2633 break; |
2489 } | 2634 } |
2490 | 2635 |
2491 » relocation = (htab->splt->output_section->vma | 2636 » if (s390_is_ifunc_symbol_p (h)) |
2492 » » » + htab->splt->output_offset | 2637 » relocation = (htab->elf.iplt->output_section->vma |
2493 » » » + h->plt.offset | 2638 » » » + htab->elf.iplt->output_offset |
2494 » » » - htab->sgot->output_section->vma); | 2639 » » » + h->plt.offset |
| 2640 » » » - htab->elf.sgot->output_section->vma); |
| 2641 » else |
| 2642 » relocation = (htab->elf.splt->output_section->vma |
| 2643 » » » + htab->elf.splt->output_offset |
| 2644 » » » + h->plt.offset |
| 2645 » » » - htab->elf.sgot->output_section->vma); |
2495 unresolved_reloc = FALSE; | 2646 unresolved_reloc = FALSE; |
2496 break; | 2647 break; |
2497 | 2648 |
2498 case R_390_8: | 2649 case R_390_8: |
2499 case R_390_16: | 2650 case R_390_16: |
2500 case R_390_32: | 2651 case R_390_32: |
2501 case R_390_PC16: | 2652 case R_390_PC16: |
2502 case R_390_PC16DBL: | 2653 case R_390_PC16DBL: |
2503 case R_390_PC32DBL: | 2654 case R_390_PC32DBL: |
2504 case R_390_PC32: | 2655 case R_390_PC32: |
| 2656 if (h != NULL |
| 2657 && s390_is_ifunc_symbol_p (h) |
| 2658 && h->def_regular) |
| 2659 { |
| 2660 if (!info->shared || !h->non_got_ref) |
| 2661 { |
| 2662 /* For a non-shared object STT_GNU_IFUNC symbol must |
| 2663 go through PLT. */ |
| 2664 relocation = (htab->elf.iplt->output_section->vma |
| 2665 + htab->elf.iplt->output_offset |
| 2666 + h ->plt.offset); |
| 2667 goto do_relocation; |
| 2668 } |
| 2669 else |
| 2670 { |
| 2671 /* For shared objects a runtime relocation is needed. */ |
| 2672 |
| 2673 Elf_Internal_Rela outrel; |
| 2674 asection *sreloc; |
| 2675 |
| 2676 /* Need a dynamic relocation to get the real function |
| 2677 address. */ |
| 2678 outrel.r_offset = _bfd_elf_section_offset (output_bfd, |
| 2679 info, |
| 2680 input_section, |
| 2681 rel->r_offset); |
| 2682 if (outrel.r_offset == (bfd_vma) -1 |
| 2683 || outrel.r_offset == (bfd_vma) -2) |
| 2684 abort (); |
| 2685 |
| 2686 outrel.r_offset += (input_section->output_section->vma |
| 2687 + input_section->output_offset); |
| 2688 |
| 2689 if (h->dynindx == -1 |
| 2690 || h->forced_local |
| 2691 || info->executable) |
| 2692 { |
| 2693 /* This symbol is resolved locally. */ |
| 2694 outrel.r_info = ELF32_R_INFO (0, R_390_IRELATIVE); |
| 2695 outrel.r_addend = (h->root.u.def.value |
| 2696 + h->root.u.def.section->output_section
->vma |
| 2697 + h->root.u.def.section->output_offset)
; |
| 2698 } |
| 2699 else |
| 2700 { |
| 2701 outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 2702 outrel.r_addend = 0; |
| 2703 } |
| 2704 |
| 2705 sreloc = htab->elf.irelifunc; |
| 2706 elf_append_rela (output_bfd, sreloc, &outrel); |
| 2707 |
| 2708 /* If this reloc is against an external symbol, we |
| 2709 do not want to fiddle with the addend. Otherwise, |
| 2710 we need to include the symbol value so that it |
| 2711 becomes an addend for the dynamic reloc. For an |
| 2712 internal symbol, we have updated addend. */ |
| 2713 continue; |
| 2714 } |
| 2715 } |
| 2716 |
2505 if ((input_section->flags & SEC_ALLOC) == 0) | 2717 if ((input_section->flags & SEC_ALLOC) == 0) |
2506 break; | 2718 break; |
2507 | 2719 |
2508 if ((info->shared | 2720 if ((info->shared |
2509 && (h == NULL | 2721 && (h == NULL |
2510 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT | 2722 || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
2511 || h->root.type != bfd_link_hash_undefweak) | 2723 || h->root.type != bfd_link_hash_undefweak) |
2512 && ((r_type != R_390_PC16 | 2724 && ((r_type != R_390_PC16 |
2513 && r_type != R_390_PC16DBL | 2725 && r_type != R_390_PC16DBL |
2514 && r_type != R_390_PC32DBL | 2726 && r_type != R_390_PC32DBL |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2661 if (r_type == R_390_TLS_LE32) | 2873 if (r_type == R_390_TLS_LE32) |
2662 { | 2874 { |
2663 /* This relocation gets optimized away by the local exec | 2875 /* This relocation gets optimized away by the local exec |
2664 access optimization. */ | 2876 access optimization. */ |
2665 BFD_ASSERT (! unresolved_reloc); | 2877 BFD_ASSERT (! unresolved_reloc); |
2666 bfd_put_32 (output_bfd, -tpoff (info, relocation), | 2878 bfd_put_32 (output_bfd, -tpoff (info, relocation), |
2667 contents + rel->r_offset); | 2879 contents + rel->r_offset); |
2668 continue; | 2880 continue; |
2669 } | 2881 } |
2670 | 2882 |
2671 » if (htab->sgot == NULL) | 2883 » if (htab->elf.sgot == NULL) |
2672 abort (); | 2884 abort (); |
2673 | 2885 |
2674 if (h != NULL) | 2886 if (h != NULL) |
2675 off = h->got.offset; | 2887 off = h->got.offset; |
2676 else | 2888 else |
2677 { | 2889 { |
2678 if (local_got_offsets == NULL) | 2890 if (local_got_offsets == NULL) |
2679 abort (); | 2891 abort (); |
2680 | 2892 |
2681 off = local_got_offsets[r_symndx]; | 2893 off = local_got_offsets[r_symndx]; |
2682 } | 2894 } |
2683 | 2895 |
2684 emit_tls_relocs: | 2896 emit_tls_relocs: |
2685 | 2897 |
2686 if ((off & 1) != 0) | 2898 if ((off & 1) != 0) |
2687 off &= ~1; | 2899 off &= ~1; |
2688 else | 2900 else |
2689 { | 2901 { |
2690 Elf_Internal_Rela outrel; | 2902 Elf_Internal_Rela outrel; |
2691 bfd_byte *loc; | 2903 bfd_byte *loc; |
2692 int dr_type, indx; | 2904 int dr_type, indx; |
2693 | 2905 |
2694 » if (htab->srelgot == NULL) | 2906 » if (htab->elf.srelgot == NULL) |
2695 abort (); | 2907 abort (); |
2696 | 2908 |
2697 » outrel.r_offset = (htab->sgot->output_section->vma | 2909 » outrel.r_offset = (htab->elf.sgot->output_section->vma |
2698 » » » » + htab->sgot->output_offset + off); | 2910 » » » » + htab->elf.sgot->output_offset + off); |
2699 | 2911 |
2700 indx = h && h->dynindx != -1 ? h->dynindx : 0; | 2912 indx = h && h->dynindx != -1 ? h->dynindx : 0; |
2701 if (r_type == R_390_TLS_GD32) | 2913 if (r_type == R_390_TLS_GD32) |
2702 dr_type = R_390_TLS_DTPMOD; | 2914 dr_type = R_390_TLS_DTPMOD; |
2703 else | 2915 else |
2704 dr_type = R_390_TLS_TPOFF; | 2916 dr_type = R_390_TLS_TPOFF; |
2705 if (dr_type == R_390_TLS_TPOFF && indx == 0) | 2917 if (dr_type == R_390_TLS_TPOFF && indx == 0) |
2706 outrel.r_addend = relocation - dtpoff_base (info); | 2918 outrel.r_addend = relocation - dtpoff_base (info); |
2707 else | 2919 else |
2708 outrel.r_addend = 0; | 2920 outrel.r_addend = 0; |
2709 outrel.r_info = ELF32_R_INFO (indx, dr_type); | 2921 outrel.r_info = ELF32_R_INFO (indx, dr_type); |
2710 » loc = htab->srelgot->contents; | 2922 » loc = htab->elf.srelgot->contents; |
2711 » loc += htab->srelgot->reloc_count++ | 2923 » loc += htab->elf.srelgot->reloc_count++ |
2712 * sizeof (Elf32_External_Rela); | 2924 * sizeof (Elf32_External_Rela); |
2713 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | 2925 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
2714 | 2926 |
2715 if (r_type == R_390_TLS_GD32) | 2927 if (r_type == R_390_TLS_GD32) |
2716 { | 2928 { |
2717 if (indx == 0) | 2929 if (indx == 0) |
2718 { | 2930 { |
2719 BFD_ASSERT (! unresolved_reloc); | 2931 BFD_ASSERT (! unresolved_reloc); |
2720 bfd_put_32 (output_bfd, | 2932 bfd_put_32 (output_bfd, |
2721 relocation - dtpoff_base (info), | 2933 relocation - dtpoff_base (info), |
2722 » » » » htab->sgot->contents + off + GOT_ENTRY_SIZE); | 2934 » » » » htab->elf.sgot->contents + off + GOT_ENTRY_SIZ
E); |
2723 } | 2935 } |
2724 else | 2936 else |
2725 { | 2937 { |
2726 outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_DTPOFF); | 2938 outrel.r_info = ELF32_R_INFO (indx, R_390_TLS_DTPOFF); |
2727 outrel.r_offset += GOT_ENTRY_SIZE; | 2939 outrel.r_offset += GOT_ENTRY_SIZE; |
2728 outrel.r_addend = 0; | 2940 outrel.r_addend = 0; |
2729 » » htab->srelgot->reloc_count++; | 2941 » » htab->elf.srelgot->reloc_count++; |
2730 loc += sizeof (Elf32_External_Rela); | 2942 loc += sizeof (Elf32_External_Rela); |
2731 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | 2943 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
2732 } | 2944 } |
2733 } | 2945 } |
2734 | 2946 |
2735 if (h != NULL) | 2947 if (h != NULL) |
2736 h->got.offset |= 1; | 2948 h->got.offset |= 1; |
2737 else | 2949 else |
2738 local_got_offsets[r_symndx] |= 1; | 2950 local_got_offsets[r_symndx] |= 1; |
2739 } | 2951 } |
2740 | 2952 |
2741 if (off >= (bfd_vma) -2) | 2953 if (off >= (bfd_vma) -2) |
2742 abort (); | 2954 abort (); |
2743 if (r_type == ELF32_R_TYPE (rel->r_info)) | 2955 if (r_type == ELF32_R_TYPE (rel->r_info)) |
2744 { | 2956 { |
2745 » relocation = htab->sgot->output_offset + off; | 2957 » relocation = htab->elf.sgot->output_offset + off; |
2746 if (r_type == R_390_TLS_IE32 || r_type == R_390_TLS_IEENT) | 2958 if (r_type == R_390_TLS_IE32 || r_type == R_390_TLS_IEENT) |
2747 » » relocation += htab->sgot->output_section->vma; | 2959 » » relocation += htab->elf.sgot->output_section->vma; |
2748 unresolved_reloc = FALSE; | 2960 unresolved_reloc = FALSE; |
2749 } | 2961 } |
2750 else | 2962 else |
2751 { | 2963 { |
2752 » bfd_put_32 (output_bfd, htab->sgot->output_offset + off, | 2964 » bfd_put_32 (output_bfd, htab->elf.sgot->output_offset + off, |
2753 contents + rel->r_offset); | 2965 contents + rel->r_offset); |
2754 continue; | 2966 continue; |
2755 } | 2967 } |
2756 break; | 2968 break; |
2757 | 2969 |
2758 case R_390_TLS_GOTIE12: | 2970 case R_390_TLS_GOTIE12: |
2759 case R_390_TLS_GOTIE20: | 2971 case R_390_TLS_GOTIE20: |
2760 case R_390_TLS_IEENT: | 2972 case R_390_TLS_IEENT: |
2761 if (h == NULL) | 2973 if (h == NULL) |
2762 { | 2974 { |
2763 if (local_got_offsets == NULL) | 2975 if (local_got_offsets == NULL) |
2764 abort(); | 2976 abort(); |
2765 off = local_got_offsets[r_symndx]; | 2977 off = local_got_offsets[r_symndx]; |
2766 if (info->shared) | 2978 if (info->shared) |
2767 goto emit_tls_relocs; | 2979 goto emit_tls_relocs; |
2768 } | 2980 } |
2769 else | 2981 else |
2770 { | 2982 { |
2771 off = h->got.offset; | 2983 off = h->got.offset; |
2772 tls_type = elf_s390_hash_entry(h)->tls_type; | 2984 tls_type = elf_s390_hash_entry(h)->tls_type; |
2773 if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE) | 2985 if (info->shared || h->dynindx != -1 || tls_type < GOT_TLS_IE) |
2774 goto emit_tls_relocs; | 2986 goto emit_tls_relocs; |
2775 } | 2987 } |
2776 | 2988 |
2777 » if (htab->sgot == NULL) | 2989 » if (htab->elf.sgot == NULL) |
2778 abort (); | 2990 abort (); |
2779 | 2991 |
2780 BFD_ASSERT (! unresolved_reloc); | 2992 BFD_ASSERT (! unresolved_reloc); |
2781 bfd_put_32 (output_bfd, -tpoff (info, relocation), | 2993 bfd_put_32 (output_bfd, -tpoff (info, relocation), |
2782 » » htab->sgot->contents + off); | 2994 » » htab->elf.sgot->contents + off); |
2783 » relocation = htab->sgot->output_offset + off; | 2995 » relocation = htab->elf.sgot->output_offset + off; |
2784 if (r_type == R_390_TLS_IEENT) | 2996 if (r_type == R_390_TLS_IEENT) |
2785 » relocation += htab->sgot->output_section->vma; | 2997 » relocation += htab->elf.sgot->output_section->vma; |
2786 unresolved_reloc = FALSE; | 2998 unresolved_reloc = FALSE; |
2787 break; | 2999 break; |
2788 | 3000 |
2789 case R_390_TLS_LDM32: | 3001 case R_390_TLS_LDM32: |
2790 if (! info->shared) | 3002 if (! info->shared) |
2791 /* The literal pool entry this relocation refers to gets ignored | 3003 /* The literal pool entry this relocation refers to gets ignored |
2792 by the optimized code of the local exec model. Do nothing | 3004 by the optimized code of the local exec model. Do nothing |
2793 and the value will turn out zero. */ | 3005 and the value will turn out zero. */ |
2794 continue; | 3006 continue; |
2795 | 3007 |
2796 » if (htab->sgot == NULL) | 3008 » if (htab->elf.sgot == NULL) |
2797 abort (); | 3009 abort (); |
2798 | 3010 |
2799 off = htab->tls_ldm_got.offset; | 3011 off = htab->tls_ldm_got.offset; |
2800 if (off & 1) | 3012 if (off & 1) |
2801 off &= ~1; | 3013 off &= ~1; |
2802 else | 3014 else |
2803 { | 3015 { |
2804 Elf_Internal_Rela outrel; | 3016 Elf_Internal_Rela outrel; |
2805 bfd_byte *loc; | 3017 bfd_byte *loc; |
2806 | 3018 |
2807 » if (htab->srelgot == NULL) | 3019 » if (htab->elf.srelgot == NULL) |
2808 abort (); | 3020 abort (); |
2809 | 3021 |
2810 » outrel.r_offset = (htab->sgot->output_section->vma | 3022 » outrel.r_offset = (htab->elf.sgot->output_section->vma |
2811 » » » » + htab->sgot->output_offset + off); | 3023 » » » » + htab->elf.sgot->output_offset + off); |
2812 | 3024 |
2813 bfd_put_32 (output_bfd, 0, | 3025 bfd_put_32 (output_bfd, 0, |
2814 » » » htab->sgot->contents + off + GOT_ENTRY_SIZE); | 3026 » » » htab->elf.sgot->contents + off + GOT_ENTRY_SIZE); |
2815 outrel.r_info = ELF32_R_INFO (0, R_390_TLS_DTPMOD); | 3027 outrel.r_info = ELF32_R_INFO (0, R_390_TLS_DTPMOD); |
2816 outrel.r_addend = 0; | 3028 outrel.r_addend = 0; |
2817 » loc = htab->srelgot->contents; | 3029 » loc = htab->elf.srelgot->contents; |
2818 » loc += htab->srelgot->reloc_count++ | 3030 » loc += htab->elf.srelgot->reloc_count++ |
2819 * sizeof (Elf32_External_Rela); | 3031 * sizeof (Elf32_External_Rela); |
2820 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); | 3032 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
2821 htab->tls_ldm_got.offset |= 1; | 3033 htab->tls_ldm_got.offset |= 1; |
2822 } | 3034 } |
2823 » relocation = htab->sgot->output_offset + off; | 3035 » relocation = htab->elf.sgot->output_offset + off; |
2824 unresolved_reloc = FALSE; | 3036 unresolved_reloc = FALSE; |
2825 break; | 3037 break; |
2826 | 3038 |
2827 case R_390_TLS_LE32: | 3039 case R_390_TLS_LE32: |
2828 if (info->shared) | 3040 if (info->shared) |
2829 { | 3041 { |
2830 /* Linking a shared library with non-fpic code requires | 3042 /* Linking a shared library with non-fpic code requires |
2831 a R_390_TLS_TPOFF relocation. */ | 3043 a R_390_TLS_TPOFF relocation. */ |
2832 Elf_Internal_Rela outrel; | 3044 Elf_Internal_Rela outrel; |
2833 asection *sreloc; | 3045 asection *sreloc; |
(...skipping 21 matching lines...) Expand all Loading... |
2855 } | 3067 } |
2856 else | 3068 else |
2857 { | 3069 { |
2858 BFD_ASSERT (! unresolved_reloc); | 3070 BFD_ASSERT (! unresolved_reloc); |
2859 bfd_put_32 (output_bfd, -tpoff (info, relocation), | 3071 bfd_put_32 (output_bfd, -tpoff (info, relocation), |
2860 contents + rel->r_offset); | 3072 contents + rel->r_offset); |
2861 } | 3073 } |
2862 continue; | 3074 continue; |
2863 | 3075 |
2864 case R_390_TLS_LDO32: | 3076 case R_390_TLS_LDO32: |
2865 » if (info->shared) | 3077 » if (info->shared || (input_section->flags & SEC_DEBUGGING)) |
2866 relocation -= dtpoff_base (info); | 3078 relocation -= dtpoff_base (info); |
2867 else | 3079 else |
2868 /* When converting LDO to LE, we must negate. */ | 3080 /* When converting LDO to LE, we must negate. */ |
2869 relocation = -tpoff (info, relocation); | 3081 relocation = -tpoff (info, relocation); |
2870 break; | 3082 break; |
2871 | 3083 |
2872 /* Relocations for tls instructions. */ | 3084 /* Relocations for tls instructions. */ |
2873 case R_390_TLS_LOAD: | 3085 case R_390_TLS_LOAD: |
2874 case R_390_TLS_GDCALL: | 3086 case R_390_TLS_GDCALL: |
2875 case R_390_TLS_LDCALL: | 3087 case R_390_TLS_LDCALL: |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2912 insn = 0x18000700 | (insn & 0x00f00000) | ry; | 3124 insn = 0x18000700 | (insn & 0x00f00000) | ry; |
2913 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | 3125 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
2914 } | 3126 } |
2915 } | 3127 } |
2916 else if (r_type == R_390_TLS_GDCALL) | 3128 else if (r_type == R_390_TLS_GDCALL) |
2917 { | 3129 { |
2918 unsigned int insn; | 3130 unsigned int insn; |
2919 | 3131 |
2920 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | 3132 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); |
2921 if ((insn & 0xff000fff) != 0x4d000000 && | 3133 if ((insn & 0xff000fff) != 0x4d000000 && |
2922 » » (insn & 0xffff0000) != 0xc0e50000) | 3134 » » (insn & 0xffff0000) != 0xc0e50000 && |
| 3135 » » (insn & 0xff000000) != 0x0d000000) |
2923 invalid_tls_insn (input_bfd, input_section, rel); | 3136 invalid_tls_insn (input_bfd, input_section, rel); |
2924 if (!info->shared && (h == NULL || h->dynindx == -1)) | 3137 if (!info->shared && (h == NULL || h->dynindx == -1)) |
2925 { | 3138 { |
2926 » » if ((insn & 0xff000000) == 0x4d000000) | 3139 » » if ((insn & 0xff000000) == 0x0d000000) |
| 3140 » » { |
| 3141 » » /* GD->LE transition. |
| 3142 » » » basr rx, ry -> nopr r7 */ |
| 3143 » » insn = 0x07070000 | (insn & 0xffff); |
| 3144 » » } |
| 3145 » » else if ((insn & 0xff000000) == 0x4d000000) |
2927 { | 3146 { |
2928 /* GD->LE transition. | 3147 /* GD->LE transition. |
2929 bas %r14,0(%rx,%r13) -> bc 0,0 */ | 3148 bas %r14,0(%rx,%r13) -> bc 0,0 */ |
2930 insn = 0x47000000; | 3149 insn = 0x47000000; |
2931 } | 3150 } |
2932 else | 3151 else |
2933 { | 3152 { |
2934 /* GD->LE transition. | 3153 /* GD->LE transition. |
2935 » » » brasl %r14,_tls_get_addr@plt -> brcl 0,. */ | 3154 » » » brasl %r14,_tls_get_offset@plt -> brcl 0,. */ |
2936 insn = 0xc0040000; | 3155 insn = 0xc0040000; |
2937 bfd_put_16 (output_bfd, 0x0000, | 3156 bfd_put_16 (output_bfd, 0x0000, |
2938 contents + rel->r_offset + 4); | 3157 contents + rel->r_offset + 4); |
2939 } | 3158 } |
2940 } | 3159 } |
2941 else | 3160 else |
2942 { | 3161 { |
| 3162 /* If basr is used in the pic case to invoke |
| 3163 _tls_get_offset, something went wrong before. */ |
| 3164 if ((insn & 0xff000000) == 0x0d000000) |
| 3165 invalid_tls_insn (input_bfd, input_section, rel); |
| 3166 |
2943 if ((insn & 0xff000000) == 0x4d000000) | 3167 if ((insn & 0xff000000) == 0x4d000000) |
2944 { | 3168 { |
2945 /* GD->IE transition. | 3169 /* GD->IE transition. |
2946 bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */ | 3170 bas %r14,0(%rx,%r13) -> l %r2,0(%r2,%r12) */ |
2947 insn = 0x5822c000; | 3171 insn = 0x5822c000; |
2948 } | 3172 } |
2949 else | 3173 else |
2950 { | 3174 { |
2951 /* GD->IE transition. | 3175 /* GD->IE transition. |
2952 brasl %r14,__tls_get_addr@plt -> | 3176 brasl %r14,__tls_get_addr@plt -> |
2953 l %r2,0(%r2,%r12) ; bcr 0,0 */ | 3177 l %r2,0(%r2,%r12) ; bcr 0,0 */ |
2954 insn = 0x5822c000; | 3178 insn = 0x5822c000; |
2955 bfd_put_16 (output_bfd, 0x0700, | 3179 bfd_put_16 (output_bfd, 0x0700, |
2956 contents + rel->r_offset + 4); | 3180 contents + rel->r_offset + 4); |
2957 } | 3181 } |
2958 } | 3182 } |
2959 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | 3183 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
2960 } | 3184 } |
2961 else if (r_type == R_390_TLS_LDCALL) | 3185 else if (r_type == R_390_TLS_LDCALL) |
2962 { | 3186 { |
2963 if (!info->shared) | 3187 if (!info->shared) |
2964 { | 3188 { |
2965 unsigned int insn; | 3189 unsigned int insn; |
2966 | 3190 |
2967 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); | 3191 insn = bfd_get_32 (input_bfd, contents + rel->r_offset); |
2968 if ((insn & 0xff000fff) != 0x4d000000 && | 3192 if ((insn & 0xff000fff) != 0x4d000000 && |
2969 » » (insn & 0xffff0000) != 0xc0e50000) | 3193 » » (insn & 0xffff0000) != 0xc0e50000 && |
| 3194 » » (insn & 0xff000000) != 0x0d000000) |
2970 invalid_tls_insn (input_bfd, input_section, rel); | 3195 invalid_tls_insn (input_bfd, input_section, rel); |
2971 » » if ((insn & 0xff000000) == 0x4d000000) | 3196 |
| 3197 » » if ((insn & 0xff000000) == 0x0d000000) |
| 3198 » » { |
| 3199 » » /* LD->LE transition. |
| 3200 » » » basr rx, ry -> nopr r7 */ |
| 3201 » » insn = 0x07070000 | (insn & 0xffff); |
| 3202 » » } |
| 3203 » » else if ((insn & 0xff000000) == 0x4d000000) |
2972 { | 3204 { |
2973 /* LD->LE transition. | 3205 /* LD->LE transition. |
2974 bas %r14,0(%rx,%r13) -> bc 0,0 */ | 3206 bas %r14,0(%rx,%r13) -> bc 0,0 */ |
2975 insn = 0x47000000; | 3207 insn = 0x47000000; |
2976 } | 3208 } |
2977 else | 3209 else |
2978 { | 3210 { |
2979 /* LD->LE transition. | 3211 /* LD->LE transition. |
2980 » » » brasl %r14,__tls_get_addr@plt -> brcl 0,. */ | 3212 » » » brasl %r14,__tls_get_offset@plt -> brcl 0,. */ |
2981 insn = 0xc0040000; | 3213 insn = 0xc0040000; |
2982 bfd_put_16 (output_bfd, 0x0000, | 3214 bfd_put_16 (output_bfd, 0x0000, |
2983 contents + rel->r_offset + 4); | 3215 contents + rel->r_offset + 4); |
2984 } | 3216 } |
2985 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); | 3217 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); |
2986 } | 3218 } |
2987 } | 3219 } |
2988 continue; | 3220 continue; |
2989 | 3221 |
2990 default: | 3222 default: |
2991 break; | 3223 break; |
2992 } | 3224 } |
2993 | 3225 |
2994 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections | 3226 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
2995 because such sections are not SEC_ALLOC and thus ld.so will | 3227 because such sections are not SEC_ALLOC and thus ld.so will |
2996 not process them. */ | 3228 not process them. */ |
2997 if (unresolved_reloc | 3229 if (unresolved_reloc |
2998 && !((input_section->flags & SEC_DEBUGGING) != 0 | 3230 && !((input_section->flags & SEC_DEBUGGING) != 0 |
2999 && h->def_dynamic) | 3231 && h->def_dynamic) |
3000 && _bfd_elf_section_offset (output_bfd, info, input_section, | 3232 && _bfd_elf_section_offset (output_bfd, info, input_section, |
3001 rel->r_offset) != (bfd_vma) -1) | 3233 rel->r_offset) != (bfd_vma) -1) |
3002 (*_bfd_error_handler) | 3234 (*_bfd_error_handler) |
3003 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), | 3235 (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
3004 input_bfd, | 3236 input_bfd, |
3005 input_section, | 3237 input_section, |
3006 (long) rel->r_offset, | 3238 (long) rel->r_offset, |
3007 howto->name, | 3239 howto->name, |
3008 h->root.root.string); | 3240 h->root.root.string); |
3009 | 3241 |
| 3242 do_relocation: |
| 3243 |
3010 if (r_type == R_390_20 | 3244 if (r_type == R_390_20 |
3011 || r_type == R_390_GOT20 | 3245 || r_type == R_390_GOT20 |
3012 || r_type == R_390_GOTPLT20 | 3246 || r_type == R_390_GOTPLT20 |
3013 || r_type == R_390_TLS_GOTIE20) | 3247 || r_type == R_390_TLS_GOTIE20) |
3014 { | 3248 { |
3015 relocation += rel->r_addend; | 3249 relocation += rel->r_addend; |
3016 relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12; | 3250 relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12; |
3017 r = _bfd_final_link_relocate (howto, input_bfd, input_section, | 3251 r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
3018 contents, rel->r_offset, | 3252 contents, rel->r_offset, |
3019 relocation, 0); | 3253 relocation, 0); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3056 input_bfd, input_section, | 3290 input_bfd, input_section, |
3057 (long) rel->r_offset, name, (int) r); | 3291 (long) rel->r_offset, name, (int) r); |
3058 return FALSE; | 3292 return FALSE; |
3059 } | 3293 } |
3060 } | 3294 } |
3061 } | 3295 } |
3062 | 3296 |
3063 return TRUE; | 3297 return TRUE; |
3064 } | 3298 } |
3065 | 3299 |
| 3300 /* Generate the PLT slots together with the dynamic relocations needed |
| 3301 for IFUNC symbols. */ |
| 3302 |
| 3303 static void |
| 3304 elf_s390_finish_ifunc_symbol (bfd *output_bfd, |
| 3305 struct bfd_link_info *info, |
| 3306 struct elf_link_hash_entry *h, |
| 3307 struct elf_s390_link_hash_table *htab, |
| 3308 bfd_vma iplt_offset, |
| 3309 bfd_vma resolver_address) |
| 3310 { |
| 3311 bfd_vma iplt_index; |
| 3312 bfd_vma got_offset; |
| 3313 bfd_vma igotiplt_offset; |
| 3314 Elf_Internal_Rela rela; |
| 3315 bfd_byte *loc; |
| 3316 asection *plt, *gotplt, *relplt; |
| 3317 bfd_vma relative_offset; |
| 3318 |
| 3319 if (htab->elf.iplt == NULL |
| 3320 || htab->elf.igotplt == NULL |
| 3321 || htab->elf.irelplt == NULL) |
| 3322 abort (); |
| 3323 |
| 3324 gotplt = htab->elf.igotplt; |
| 3325 relplt = htab->elf.irelplt; |
| 3326 |
| 3327 /* Index of the PLT slot within iplt section. */ |
| 3328 iplt_index = iplt_offset / PLT_ENTRY_SIZE; |
| 3329 plt = htab->elf.iplt; |
| 3330 /* Offset into the igot.plt section. */ |
| 3331 igotiplt_offset = iplt_index * GOT_ENTRY_SIZE; |
| 3332 /* Offset into the got section. */ |
| 3333 got_offset = igotiplt_offset + gotplt->output_offset; |
| 3334 |
| 3335 /* S390 uses halfwords for relative branch calc! */ |
| 3336 relative_offset = - (plt->output_offset + |
| 3337 (PLT_ENTRY_SIZE * iplt_index) + 18) / 2; |
| 3338 /* If offset is > 32768, branch to a previous branch |
| 3339 390 can only handle +-64 K jumps. */ |
| 3340 if ( -32768 > (int) relative_offset ) |
| 3341 relative_offset |
| 3342 = -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2); |
| 3343 |
| 3344 /* Fill in the entry in the procedure linkage table. */ |
| 3345 if (!info->shared) |
| 3346 { |
| 3347 memcpy (plt->contents + iplt_offset, elf_s390_plt_entry, |
| 3348 PLT_ENTRY_SIZE); |
| 3349 |
| 3350 /* Adjust jump to the first plt entry. */ |
| 3351 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3352 plt->contents + iplt_offset + 20); |
| 3353 |
| 3354 /* Push the GOT offset field. */ |
| 3355 bfd_put_32 (output_bfd, |
| 3356 (gotplt->output_section->vma |
| 3357 + got_offset), |
| 3358 plt->contents + iplt_offset + 24); |
| 3359 } |
| 3360 else if (got_offset < 4096) |
| 3361 { |
| 3362 /* The GOT offset is small enough to be used directly as |
| 3363 displacement. */ |
| 3364 memcpy (plt->contents + iplt_offset, |
| 3365 elf_s390_plt_pic12_entry, |
| 3366 PLT_ENTRY_SIZE); |
| 3367 |
| 3368 /* Put in the GOT offset as displacement value. The 0xc000 |
| 3369 value comes from the first word of the plt entry. Look |
| 3370 at the elf_s390_plt_pic16_entry content. */ |
| 3371 bfd_put_16 (output_bfd, (bfd_vma)0xc000 | got_offset, |
| 3372 plt->contents + iplt_offset + 2); |
| 3373 |
| 3374 /* Adjust the jump to the first plt entry. */ |
| 3375 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3376 plt->contents + iplt_offset + 20); |
| 3377 } |
| 3378 else if (got_offset < 32768) |
| 3379 { |
| 3380 /* The GOT offset is too big for a displacement but small |
| 3381 enough to be a signed 16 bit immediate value as it can be |
| 3382 used in an lhi instruction. */ |
| 3383 memcpy (plt->contents + iplt_offset, |
| 3384 elf_s390_plt_pic16_entry, |
| 3385 PLT_ENTRY_SIZE); |
| 3386 |
| 3387 /* Put in the GOT offset for the lhi instruction. */ |
| 3388 bfd_put_16 (output_bfd, (bfd_vma)got_offset, |
| 3389 plt->contents + iplt_offset + 2); |
| 3390 |
| 3391 /* Adjust the jump to the first plt entry. */ |
| 3392 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3393 plt->contents + iplt_offset + 20); |
| 3394 } |
| 3395 else |
| 3396 { |
| 3397 memcpy (plt->contents + iplt_offset, |
| 3398 elf_s390_plt_pic_entry, |
| 3399 PLT_ENTRY_SIZE); |
| 3400 |
| 3401 /* Adjust the jump to the first plt entry. */ |
| 3402 bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3403 plt->contents + iplt_offset + 20); |
| 3404 |
| 3405 /* Push the GOT offset field. */ |
| 3406 bfd_put_32 (output_bfd, got_offset, |
| 3407 plt->contents + iplt_offset + 24); |
| 3408 } |
| 3409 /* Insert offset into reloc. table here. */ |
| 3410 bfd_put_32 (output_bfd, relplt->output_offset + |
| 3411 iplt_index * RELA_ENTRY_SIZE, |
| 3412 plt->contents + iplt_offset + 28); |
| 3413 |
| 3414 /* Fill in the entry in the global offset table. |
| 3415 Points to instruction after GOT offset. */ |
| 3416 bfd_put_32 (output_bfd, |
| 3417 (plt->output_section->vma |
| 3418 + plt->output_offset |
| 3419 + iplt_offset |
| 3420 + 12), |
| 3421 gotplt->contents + igotiplt_offset); |
| 3422 |
| 3423 /* Fill in the entry in the .rela.plt section. */ |
| 3424 rela.r_offset = gotplt->output_section->vma + got_offset; |
| 3425 |
| 3426 if (!h |
| 3427 || h->dynindx == -1 |
| 3428 || ((info->executable |
| 3429 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) |
| 3430 && h->def_regular)) |
| 3431 { |
| 3432 /* The symbol can be locally resolved. */ |
| 3433 rela.r_info = ELF32_R_INFO (0, R_390_IRELATIVE); |
| 3434 rela.r_addend = resolver_address; |
| 3435 } |
| 3436 else |
| 3437 { |
| 3438 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT); |
| 3439 rela.r_addend = 0; |
| 3440 } |
| 3441 |
| 3442 loc = relplt->contents + iplt_index * RELA_ENTRY_SIZE; |
| 3443 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
| 3444 } |
| 3445 |
3066 /* Finish up dynamic symbol handling. We set the contents of various | 3446 /* Finish up dynamic symbol handling. We set the contents of various |
3067 dynamic sections here. */ | 3447 dynamic sections here. */ |
3068 | 3448 |
3069 static bfd_boolean | 3449 static bfd_boolean |
3070 elf_s390_finish_dynamic_symbol (output_bfd, info, h, sym) | 3450 elf_s390_finish_dynamic_symbol (bfd *output_bfd, |
3071 bfd *output_bfd; | 3451 » » » » struct bfd_link_info *info, |
3072 struct bfd_link_info *info; | 3452 » » » » struct elf_link_hash_entry *h, |
3073 struct elf_link_hash_entry *h; | 3453 » » » » Elf_Internal_Sym *sym) |
3074 Elf_Internal_Sym *sym; | |
3075 { | 3454 { |
3076 struct elf_s390_link_hash_table *htab; | 3455 struct elf_s390_link_hash_table *htab; |
| 3456 struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h; |
3077 | 3457 |
3078 htab = elf_s390_hash_table (info); | 3458 htab = elf_s390_hash_table (info); |
3079 | 3459 |
3080 if (h->plt.offset != (bfd_vma) -1) | 3460 if (h->plt.offset != (bfd_vma) -1) |
3081 { | 3461 { |
3082 bfd_vma plt_index; | 3462 bfd_vma plt_index; |
3083 bfd_vma got_offset; | 3463 bfd_vma got_offset; |
3084 Elf_Internal_Rela rela; | 3464 Elf_Internal_Rela rela; |
3085 bfd_byte *loc; | 3465 bfd_byte *loc; |
3086 bfd_vma relative_offset; | 3466 bfd_vma relative_offset; |
3087 | 3467 |
3088 /* This symbol has an entry in the procedure linkage table. Set | 3468 /* This symbol has an entry in the procedure linkage table. Set |
3089 it up. */ | 3469 it up. */ |
3090 if (h->dynindx == -1 | 3470 if (s390_is_ifunc_symbol_p (h)) |
3091 » || htab->splt == NULL | |
3092 » || htab->sgotplt == NULL | |
3093 » || htab->srelplt == NULL) | |
3094 » abort (); | |
3095 | |
3096 /* Calc. index no. | |
3097 » Current offset - size first entry / entry size. */ | |
3098 plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE; | |
3099 | |
3100 /* Offset in GOT is PLT index plus GOT headers(3) times 4, | |
3101 » addr & GOT addr. */ | |
3102 got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; | |
3103 | |
3104 /* S390 uses halfwords for relative branch calc! */ | |
3105 relative_offset = - ((PLT_FIRST_ENTRY_SIZE + | |
3106 » » » (PLT_ENTRY_SIZE * plt_index) + 18) / 2); | |
3107 /* If offset is > 32768, branch to a previous branch | |
3108 » 390 can only handle +-64 K jumps. */ | |
3109 if ( -32768 > (int) relative_offset ) | |
3110 » relative_offset | |
3111 » = -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2); | |
3112 | |
3113 /* Fill in the entry in the procedure linkage table. */ | |
3114 if (!info->shared) | |
3115 { | 3471 { |
3116 » bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD0, | 3472 » /* If we can resolve the IFUNC symbol locally we generate an |
3117 » » htab->splt->contents + h->plt.offset); | 3473 » IRELATIVE reloc. */ |
3118 » bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD1, | 3474 » elf_s390_finish_ifunc_symbol (output_bfd, info, h, htab, h->plt.offset
, |
3119 » » htab->splt->contents + h->plt.offset + 4); | 3475 » » » » » eh->ifunc_resolver_address + |
3120 » bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2, | 3476 » » » » » eh->ifunc_resolver_section->output_offse
t + |
3121 » » htab->splt->contents + h->plt.offset + 8); | 3477 » » » » » eh->ifunc_resolver_section->output_secti
on->vma); |
3122 » bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD3, | 3478 » /* Fallthrough. Handling of explicit GOT slots of IFUNC |
3123 » » htab->splt->contents + h->plt.offset + 12); | 3479 » symbols is below. */ |
3124 » bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD4, | |
3125 » » htab->splt->contents + h->plt.offset + 16); | |
3126 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3127 » » htab->splt->contents + h->plt.offset + 20); | |
3128 » bfd_put_32 (output_bfd, | |
3129 » » (htab->sgotplt->output_section->vma | |
3130 » » + htab->sgotplt->output_offset | |
3131 » » + got_offset), | |
3132 » » htab->splt->contents + h->plt.offset + 24); | |
3133 » } | |
3134 else if (got_offset < 4096) | |
3135 » { | |
3136 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD0 + got_offset, | |
3137 » » htab->splt->contents + h->plt.offset); | |
3138 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD1, | |
3139 » » htab->splt->contents + h->plt.offset + 4); | |
3140 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD2, | |
3141 » » htab->splt->contents + h->plt.offset + 8); | |
3142 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD3, | |
3143 » » htab->splt->contents + h->plt.offset + 12); | |
3144 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC12_ENTRY_WORD4, | |
3145 » » htab->splt->contents + h->plt.offset + 16); | |
3146 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3147 » » htab->splt->contents + h->plt.offset + 20); | |
3148 » bfd_put_32 (output_bfd, (bfd_vma) 0, | |
3149 » » htab->splt->contents + h->plt.offset + 24); | |
3150 » } | |
3151 else if (got_offset < 32768) | |
3152 » { | |
3153 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD0 + got_offset, | |
3154 » » htab->splt->contents + h->plt.offset); | |
3155 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD1, | |
3156 » » htab->splt->contents + h->plt.offset + 4); | |
3157 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD2, | |
3158 » » htab->splt->contents + h->plt.offset + 8); | |
3159 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD3, | |
3160 » » htab->splt->contents + h->plt.offset + 12); | |
3161 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC16_ENTRY_WORD4, | |
3162 » » htab->splt->contents + h->plt.offset + 16); | |
3163 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3164 » » htab->splt->contents + h->plt.offset + 20); | |
3165 » bfd_put_32 (output_bfd, (bfd_vma) 0, | |
3166 » » htab->splt->contents + h->plt.offset + 24); | |
3167 } | 3480 } |
3168 else | 3481 else |
3169 { | 3482 { |
3170 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD0, | 3483 » if (h->dynindx == -1 |
3171 » » htab->splt->contents + h->plt.offset); | 3484 » || htab->elf.splt == NULL |
3172 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD1, | 3485 » || htab->elf.sgotplt == NULL |
3173 » » htab->splt->contents + h->plt.offset + 4); | 3486 » || htab->elf.srelplt == NULL) |
3174 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD2, | 3487 » abort (); |
3175 » » htab->splt->contents + h->plt.offset + 8); | |
3176 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD3, | |
3177 » » htab->splt->contents + h->plt.offset + 12); | |
3178 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_ENTRY_WORD4, | |
3179 » » htab->splt->contents + h->plt.offset + 16); | |
3180 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), | |
3181 » » htab->splt->contents + h->plt.offset + 20); | |
3182 » bfd_put_32 (output_bfd, got_offset, | |
3183 » » htab->splt->contents + h->plt.offset + 24); | |
3184 » } | |
3185 /* Insert offset into reloc. table here. */ | |
3186 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), | |
3187 » » htab->splt->contents + h->plt.offset + 28); | |
3188 | 3488 |
3189 /* Fill in the entry in the global offset table. | 3489 » /* Calc. index no. |
3190 » Points to instruction after GOT offset. */ | 3490 » Current offset - size first entry / entry size. */ |
3191 bfd_put_32 (output_bfd, | 3491 » plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE; |
3192 » » (htab->splt->output_section->vma | |
3193 » » + htab->splt->output_offset | |
3194 » » + h->plt.offset | |
3195 » » + 12), | |
3196 » » htab->sgotplt->contents + got_offset); | |
3197 | 3492 |
3198 /* Fill in the entry in the .rela.plt section. */ | 3493 » /* Offset in GOT is PLT index plus GOT headers(3) times 4, |
3199 rela.r_offset = (htab->sgotplt->output_section->vma | 3494 » addr & GOT addr. */ |
3200 » » + htab->sgotplt->output_offset | 3495 » got_offset = (plt_index + 3) * GOT_ENTRY_SIZE; |
3201 » » + got_offset); | |
3202 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT); | |
3203 rela.r_addend = 0; | |
3204 loc = htab->srelplt->contents + plt_index * sizeof (Elf32_External_Rela); | |
3205 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | |
3206 | 3496 |
3207 if (!h->def_regular) | 3497 » /* S390 uses halfwords for relative branch calc! */ |
3208 » { | 3498 » relative_offset = - ((PLT_FIRST_ENTRY_SIZE + |
3209 » /* Mark the symbol as undefined, rather than as defined in | 3499 » » » » (PLT_ENTRY_SIZE * plt_index) + 18) / 2); |
3210 » the .plt section. Leave the value alone. This is a clue | 3500 » /* If offset is > 32768, branch to a previous branch |
3211 » for the dynamic linker, to make function pointer | 3501 » 390 can only handle +-64 K jumps. */ |
3212 » comparisons work between an application and shared | 3502 » if ( -32768 > (int) relative_offset ) |
3213 » library. */ | 3503 » relative_offset |
3214 » sym->st_shndx = SHN_UNDEF; | 3504 » = -(unsigned) (((65536 / PLT_ENTRY_SIZE - 1) * PLT_ENTRY_SIZE) / 2
); |
| 3505 |
| 3506 » /* Fill in the entry in the procedure linkage table. */ |
| 3507 » if (!info->shared) |
| 3508 » { |
| 3509 » memcpy (htab->elf.splt->contents + h->plt.offset, elf_s390_plt_ent
ry, |
| 3510 » » PLT_ENTRY_SIZE); |
| 3511 |
| 3512 » /* Adjust jump to the first plt entry. */ |
| 3513 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3514 » » » htab->elf.splt->contents + h->plt.offset + 20); |
| 3515 |
| 3516 » /* Push the GOT offset field. */ |
| 3517 » bfd_put_32 (output_bfd, |
| 3518 » » » (htab->elf.sgotplt->output_section->vma |
| 3519 » » » + htab->elf.sgotplt->output_offset |
| 3520 » » » + got_offset), |
| 3521 » » » htab->elf.splt->contents + h->plt.offset + 24); |
| 3522 » } |
| 3523 » else if (got_offset < 4096) |
| 3524 » { |
| 3525 » /* The GOT offset is small enough to be used directly as |
| 3526 » » displacement. */ |
| 3527 » memcpy (htab->elf.splt->contents + h->plt.offset, |
| 3528 » » elf_s390_plt_pic12_entry, |
| 3529 » » PLT_ENTRY_SIZE); |
| 3530 |
| 3531 » /* Put in the GOT offset as displacement value. The 0xc000 |
| 3532 » » value comes from the first word of the plt entry. Look |
| 3533 » » at the elf_s390_plt_pic16_entry content. */ |
| 3534 » bfd_put_16 (output_bfd, (bfd_vma)0xc000 | got_offset, |
| 3535 » » » htab->elf.splt->contents + h->plt.offset + 2); |
| 3536 |
| 3537 » /* Adjust the jump to the first plt entry. */ |
| 3538 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3539 » » » htab->elf.splt->contents + h->plt.offset + 20); |
| 3540 » } |
| 3541 » else if (got_offset < 32768) |
| 3542 » { |
| 3543 » /* The GOT offset is too big for a displacement but small |
| 3544 » » enough to be a signed 16 bit immediate value as it can be |
| 3545 » » used in an lhi instruction. */ |
| 3546 » memcpy (htab->elf.splt->contents + h->plt.offset, |
| 3547 » » elf_s390_plt_pic16_entry, |
| 3548 » » PLT_ENTRY_SIZE); |
| 3549 |
| 3550 » /* Put in the GOT offset for the lhi instruction. */ |
| 3551 » bfd_put_16 (output_bfd, (bfd_vma)got_offset, |
| 3552 » » » htab->elf.splt->contents + h->plt.offset + 2); |
| 3553 |
| 3554 » /* Adjust the jump to the first plt entry. */ |
| 3555 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3556 » » » htab->elf.splt->contents + h->plt.offset + 20); |
| 3557 » } |
| 3558 » else |
| 3559 » { |
| 3560 » memcpy (htab->elf.splt->contents + h->plt.offset, |
| 3561 » » elf_s390_plt_pic_entry, |
| 3562 » » PLT_ENTRY_SIZE); |
| 3563 |
| 3564 » /* Adjust the jump to the first plt entry. */ |
| 3565 » bfd_put_32 (output_bfd, (bfd_vma) 0+(relative_offset << 16), |
| 3566 » » » htab->elf.splt->contents + h->plt.offset + 20); |
| 3567 |
| 3568 » /* Push the GOT offset field. */ |
| 3569 » bfd_put_32 (output_bfd, got_offset, |
| 3570 » » » htab->elf.splt->contents + h->plt.offset + 24); |
| 3571 » } |
| 3572 » /* Insert offset into reloc. table here. */ |
| 3573 » bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
| 3574 » » htab->elf.splt->contents + h->plt.offset + 28); |
| 3575 |
| 3576 » /* Fill in the entry in the global offset table. |
| 3577 » Points to instruction after GOT offset. */ |
| 3578 » bfd_put_32 (output_bfd, |
| 3579 » » (htab->elf.splt->output_section->vma |
| 3580 » » + htab->elf.splt->output_offset |
| 3581 » » + h->plt.offset |
| 3582 » » + 12), |
| 3583 » » htab->elf.sgotplt->contents + got_offset); |
| 3584 |
| 3585 » /* Fill in the entry in the .rela.plt section. */ |
| 3586 » rela.r_offset = (htab->elf.sgotplt->output_section->vma |
| 3587 » » » + htab->elf.sgotplt->output_offset |
| 3588 » » » + got_offset); |
| 3589 » rela.r_info = ELF32_R_INFO (h->dynindx, R_390_JMP_SLOT); |
| 3590 » rela.r_addend = 0; |
| 3591 » loc = htab->elf.srelplt->contents + plt_index * sizeof (Elf32_External
_Rela); |
| 3592 » bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
| 3593 |
| 3594 » if (!h->def_regular) |
| 3595 » { |
| 3596 » /* Mark the symbol as undefined, rather than as defined in |
| 3597 » » the .plt section. Leave the value alone. This is a clue |
| 3598 » » for the dynamic linker, to make function pointer |
| 3599 » » comparisons work between an application and shared |
| 3600 » » library. */ |
| 3601 » sym->st_shndx = SHN_UNDEF; |
| 3602 » } |
3215 } | 3603 } |
3216 } | 3604 } |
3217 | 3605 |
3218 if (h->got.offset != (bfd_vma) -1 | 3606 if (h->got.offset != (bfd_vma) -1 |
3219 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD | 3607 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD |
3220 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE | 3608 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE |
3221 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT) | 3609 && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT) |
3222 { | 3610 { |
3223 Elf_Internal_Rela rela; | 3611 Elf_Internal_Rela rela; |
3224 bfd_byte *loc; | 3612 bfd_byte *loc; |
3225 | 3613 |
3226 /* This symbol has an entry in the global offset table. Set it | 3614 /* This symbol has an entry in the global offset table. Set it |
3227 up. */ | 3615 up. */ |
3228 | 3616 |
3229 if (htab->sgot == NULL || htab->srelgot == NULL) | 3617 if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL) |
3230 abort (); | 3618 abort (); |
3231 | 3619 |
3232 rela.r_offset = (htab->sgot->output_section->vma | 3620 rela.r_offset = (htab->elf.sgot->output_section->vma |
3233 » » + htab->sgot->output_offset | 3621 » » + htab->elf.sgot->output_offset |
3234 + (h->got.offset &~ (bfd_vma) 1)); | 3622 + (h->got.offset &~ (bfd_vma) 1)); |
3235 | 3623 |
3236 /* If this is a static link, or it is a -Bsymbolic link and the | 3624 /* If this is a static link, or it is a -Bsymbolic link and the |
3237 symbol is defined locally or was forced to be local because | 3625 symbol is defined locally or was forced to be local because |
3238 of a version file, we just want to emit a RELATIVE reloc. | 3626 of a version file, we just want to emit a RELATIVE reloc. |
3239 The entry in the global offset table will already have been | 3627 The entry in the global offset table will already have been |
3240 initialized in the relocate_section function. */ | 3628 initialized in the relocate_section function. */ |
3241 if (info->shared | 3629 if (h->def_regular && s390_is_ifunc_symbol_p (h)) |
| 3630 » { |
| 3631 » if (info->shared) |
| 3632 » { |
| 3633 » /* An explicit GOT slot usage needs GLOB_DAT. If the |
| 3634 » » symbol references local the implicit got.iplt slot |
| 3635 » » will be used and the IRELATIVE reloc has been created |
| 3636 » » above. */ |
| 3637 » goto do_glob_dat; |
| 3638 » } |
| 3639 » else |
| 3640 » { |
| 3641 » /* For non-shared objects explicit GOT slots must be |
| 3642 » » filled with the PLT slot address for pointer |
| 3643 » » equality reasons. */ |
| 3644 » bfd_put_32 (output_bfd, (htab->elf.iplt->output_section->vma |
| 3645 » » » » + htab->elf.iplt->output_offset |
| 3646 » » » » + h->plt.offset), |
| 3647 » » » htab->elf.sgot->contents + h->got.offset); |
| 3648 » return TRUE; |
| 3649 » } |
| 3650 » } |
| 3651 else if (info->shared |
3242 && SYMBOL_REFERENCES_LOCAL (info, h)) | 3652 && SYMBOL_REFERENCES_LOCAL (info, h)) |
3243 { | 3653 { |
| 3654 /* If this is a static link, or it is a -Bsymbolic link and |
| 3655 the symbol is defined locally or was forced to be local |
| 3656 because of a version file, we just want to emit a |
| 3657 RELATIVE reloc. The entry in the global offset table |
| 3658 will already have been initialized in the |
| 3659 relocate_section function. */ |
3244 if (!h->def_regular) | 3660 if (!h->def_regular) |
3245 return FALSE; | 3661 return FALSE; |
3246 BFD_ASSERT((h->got.offset & 1) != 0); | 3662 BFD_ASSERT((h->got.offset & 1) != 0); |
3247 rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); | 3663 rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); |
3248 rela.r_addend = (h->root.u.def.value | 3664 rela.r_addend = (h->root.u.def.value |
3249 + h->root.u.def.section->output_section->vma | 3665 + h->root.u.def.section->output_section->vma |
3250 + h->root.u.def.section->output_offset); | 3666 + h->root.u.def.section->output_offset); |
3251 } | 3667 } |
3252 else | 3668 else |
3253 { | 3669 { |
3254 BFD_ASSERT((h->got.offset & 1) == 0); | 3670 BFD_ASSERT((h->got.offset & 1) == 0); |
3255 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents + h->got.off
set); | 3671 » do_glob_dat: |
| 3672 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->elf.sgot->contents + h->got
.offset); |
3256 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT); | 3673 rela.r_info = ELF32_R_INFO (h->dynindx, R_390_GLOB_DAT); |
3257 rela.r_addend = 0; | 3674 rela.r_addend = 0; |
3258 } | 3675 } |
3259 | 3676 |
3260 loc = htab->srelgot->contents; | 3677 loc = htab->elf.srelgot->contents; |
3261 loc += htab->srelgot->reloc_count++ * sizeof (Elf32_External_Rela); | 3678 loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf32_External_Rela); |
3262 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); | 3679 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
3263 } | 3680 } |
3264 | 3681 |
3265 if (h->needs_copy) | 3682 if (h->needs_copy) |
3266 { | 3683 { |
3267 Elf_Internal_Rela rela; | 3684 Elf_Internal_Rela rela; |
3268 bfd_byte *loc; | 3685 bfd_byte *loc; |
3269 | 3686 |
3270 /* This symbols needs a copy reloc. Set it up. */ | 3687 /* This symbols needs a copy reloc. Set it up. */ |
3271 | 3688 |
(...skipping 19 matching lines...) Expand all Loading... |
3291 || h == htab->elf.hplt) | 3708 || h == htab->elf.hplt) |
3292 sym->st_shndx = SHN_ABS; | 3709 sym->st_shndx = SHN_ABS; |
3293 | 3710 |
3294 return TRUE; | 3711 return TRUE; |
3295 } | 3712 } |
3296 | 3713 |
3297 /* Used to decide how to sort relocs in an optimal manner for the | 3714 /* Used to decide how to sort relocs in an optimal manner for the |
3298 dynamic linker, before writing them out. */ | 3715 dynamic linker, before writing them out. */ |
3299 | 3716 |
3300 static enum elf_reloc_type_class | 3717 static enum elf_reloc_type_class |
3301 elf_s390_reloc_type_class (rela) | 3718 elf_s390_reloc_type_class (const Elf_Internal_Rela *rela) |
3302 const Elf_Internal_Rela *rela; | |
3303 { | 3719 { |
3304 switch ((int) ELF32_R_TYPE (rela->r_info)) | 3720 switch ((int) ELF32_R_TYPE (rela->r_info)) |
3305 { | 3721 { |
3306 case R_390_RELATIVE: | 3722 case R_390_RELATIVE: |
3307 return reloc_class_relative; | 3723 return reloc_class_relative; |
3308 case R_390_JMP_SLOT: | 3724 case R_390_JMP_SLOT: |
3309 return reloc_class_plt; | 3725 return reloc_class_plt; |
3310 case R_390_COPY: | 3726 case R_390_COPY: |
3311 return reloc_class_copy; | 3727 return reloc_class_copy; |
3312 default: | 3728 default: |
3313 return reloc_class_normal; | 3729 return reloc_class_normal; |
3314 } | 3730 } |
3315 } | 3731 } |
3316 | 3732 |
3317 /* Finish up the dynamic sections. */ | 3733 /* Finish up the dynamic sections. */ |
3318 | 3734 |
3319 static bfd_boolean | 3735 static bfd_boolean |
3320 elf_s390_finish_dynamic_sections (output_bfd, info) | 3736 elf_s390_finish_dynamic_sections (bfd *output_bfd, |
3321 bfd *output_bfd; | 3737 » » » » struct bfd_link_info *info) |
3322 struct bfd_link_info *info; | |
3323 { | 3738 { |
3324 struct elf_s390_link_hash_table *htab; | 3739 struct elf_s390_link_hash_table *htab; |
3325 bfd *dynobj; | 3740 bfd *dynobj; |
3326 asection *sdyn; | 3741 asection *sdyn; |
| 3742 bfd *ibfd; |
| 3743 unsigned int i; |
3327 | 3744 |
3328 htab = elf_s390_hash_table (info); | 3745 htab = elf_s390_hash_table (info); |
3329 dynobj = htab->elf.dynobj; | 3746 dynobj = htab->elf.dynobj; |
3330 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); | 3747 sdyn = bfd_get_linker_section (dynobj, ".dynamic"); |
3331 | 3748 |
3332 if (htab->elf.dynamic_sections_created) | 3749 if (htab->elf.dynamic_sections_created) |
3333 { | 3750 { |
3334 Elf32_External_Dyn *dyncon, *dynconend; | 3751 Elf32_External_Dyn *dyncon, *dynconend; |
3335 | 3752 |
3336 if (sdyn == NULL || htab->sgot == NULL) | 3753 if (sdyn == NULL || htab->elf.sgot == NULL) |
3337 abort (); | 3754 abort (); |
3338 | 3755 |
3339 dyncon = (Elf32_External_Dyn *) sdyn->contents; | 3756 dyncon = (Elf32_External_Dyn *) sdyn->contents; |
3340 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); | 3757 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
3341 for (; dyncon < dynconend; dyncon++) | 3758 for (; dyncon < dynconend; dyncon++) |
3342 { | 3759 { |
3343 Elf_Internal_Dyn dyn; | 3760 Elf_Internal_Dyn dyn; |
3344 asection *s; | 3761 asection *s; |
3345 | 3762 |
3346 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); | 3763 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
3347 | 3764 |
3348 switch (dyn.d_tag) | 3765 switch (dyn.d_tag) |
3349 { | 3766 { |
3350 default: | 3767 default: |
3351 continue; | 3768 continue; |
3352 | 3769 |
3353 case DT_PLTGOT: | 3770 case DT_PLTGOT: |
3354 » dyn.d_un.d_ptr = htab->sgot->output_section->vma; | 3771 » dyn.d_un.d_ptr = htab->elf.sgot->output_section->vma; |
3355 break; | 3772 break; |
3356 | 3773 |
3357 case DT_JMPREL: | 3774 case DT_JMPREL: |
3358 » dyn.d_un.d_ptr = htab->srelplt->output_section->vma; | 3775 » dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma; |
3359 break; | 3776 break; |
3360 | 3777 |
3361 case DT_PLTRELSZ: | 3778 case DT_PLTRELSZ: |
3362 » s = htab->srelplt->output_section; | 3779 » s = htab->elf.srelplt->output_section; |
3363 dyn.d_un.d_val = s->size; | 3780 dyn.d_un.d_val = s->size; |
3364 break; | 3781 break; |
3365 } | 3782 } |
3366 | 3783 |
3367 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); | 3784 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
3368 } | 3785 } |
3369 | 3786 |
3370 /* Fill in the special first entry in the procedure linkage table. */ | 3787 /* Fill in the special first entry in the procedure linkage table. */ |
3371 if (htab->splt && htab->splt->size > 0) | 3788 if (htab->elf.splt && htab->elf.splt->size > 0) |
3372 { | 3789 { |
3373 » memset (htab->splt->contents, 0, PLT_FIRST_ENTRY_SIZE); | 3790 » memset (htab->elf.splt->contents, 0, PLT_FIRST_ENTRY_SIZE); |
3374 if (info->shared) | 3791 if (info->shared) |
3375 { | 3792 { |
3376 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD0, | 3793 » memcpy (htab->elf.splt->contents, elf_s390_plt_pic_first_entry, |
3377 » » » htab->splt->contents ); | 3794 » » PLT_FIRST_ENTRY_SIZE); |
3378 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD1, | 3795 » } |
3379 » » » htab->splt->contents +4 ); | 3796 » else |
3380 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD2, | 3797 » { |
3381 » » » htab->splt->contents +8 ); | 3798 » memcpy (htab->elf.splt->contents, elf_s390_plt_first_entry, |
3382 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD3, | 3799 » » PLT_FIRST_ENTRY_SIZE); |
3383 » » » htab->splt->contents +12 ); | 3800 » bfd_put_32 (output_bfd, |
3384 » bfd_put_32 (output_bfd, (bfd_vma) PLT_PIC_FIRST_ENTRY_WORD4, | 3801 » » » htab->elf.sgotplt->output_section->vma |
3385 » » » htab->splt->contents +16 ); | 3802 » » » + htab->elf.sgotplt->output_offset, |
| 3803 » » » htab->elf.splt->contents + 24); |
3386 } | 3804 } |
3387 » else | 3805 » elf_section_data (htab->elf.splt->output_section) |
3388 » { | |
3389 » bfd_put_32 (output_bfd, (bfd_vma)PLT_FIRST_ENTRY_WORD0, | |
3390 » » » htab->splt->contents ); | |
3391 » bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD1, | |
3392 » » » htab->splt->contents +4 ); | |
3393 » bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD2, | |
3394 » » » htab->splt->contents +8 ); | |
3395 » bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD3, | |
3396 » » » htab->splt->contents +12 ); | |
3397 » bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD4, | |
3398 » » » htab->splt->contents +16 ); | |
3399 » bfd_put_32 (output_bfd, (bfd_vma) PLT_FIRST_ENTRY_WORD5, | |
3400 » » » htab->splt->contents +20 ); | |
3401 » bfd_put_32 (output_bfd, | |
3402 » » » htab->sgotplt->output_section->vma | |
3403 » » » + htab->sgotplt->output_offset, | |
3404 » » » htab->splt->contents + 24); | |
3405 » } | |
3406 » elf_section_data (htab->splt->output_section) | |
3407 ->this_hdr.sh_entsize = 4; | 3806 ->this_hdr.sh_entsize = 4; |
3408 } | 3807 } |
3409 | 3808 |
3410 } | 3809 } |
3411 | 3810 |
3412 if (htab->sgotplt) | 3811 if (htab->elf.sgotplt) |
3413 { | 3812 { |
3414 /* Fill in the first three entries in the global offset table. */ | 3813 /* Fill in the first three entries in the global offset table. */ |
3415 if (htab->sgotplt->size > 0) | 3814 if (htab->elf.sgotplt->size > 0) |
3416 { | 3815 { |
3417 bfd_put_32 (output_bfd, | 3816 bfd_put_32 (output_bfd, |
3418 (sdyn == NULL ? (bfd_vma) 0 | 3817 (sdyn == NULL ? (bfd_vma) 0 |
3419 : sdyn->output_section->vma + sdyn->output_offset), | 3818 : sdyn->output_section->vma + sdyn->output_offset), |
3420 » » htab->sgotplt->contents); | 3819 » » htab->elf.sgotplt->contents); |
3421 /* One entry for shared object struct ptr. */ | 3820 /* One entry for shared object struct ptr. */ |
3422 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 4); | 3821 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + 4); |
3423 /* One entry for _dl_runtime_resolve. */ | 3822 /* One entry for _dl_runtime_resolve. */ |
3424 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgotplt->contents + 8); | 3823 » bfd_put_32 (output_bfd, (bfd_vma) 0, htab->elf.sgotplt->contents + 8); |
3425 } | 3824 } |
3426 | 3825 |
3427 elf_section_data (htab->sgotplt->output_section) | 3826 elf_section_data (htab->elf.sgotplt->output_section) |
3428 ->this_hdr.sh_entsize = 4; | 3827 ->this_hdr.sh_entsize = 4; |
3429 } | 3828 } |
| 3829 /* Finish dynamic symbol for local IFUNC symbols. */ |
| 3830 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) |
| 3831 { |
| 3832 struct plt_entry *local_plt; |
| 3833 Elf_Internal_Sym *isym; |
| 3834 Elf_Internal_Shdr *symtab_hdr; |
| 3835 |
| 3836 symtab_hdr = &elf_symtab_hdr (ibfd); |
| 3837 |
| 3838 local_plt = elf_s390_local_plt (ibfd); |
| 3839 if (local_plt != NULL) |
| 3840 for (i = 0; i < symtab_hdr->sh_info; i++) |
| 3841 { |
| 3842 if (local_plt[i].plt.offset != (bfd_vma) -1) |
| 3843 { |
| 3844 asection *sec = local_plt[i].sec; |
| 3845 isym = bfd_sym_from_r_symndx (&htab->sym_cache, ibfd, i); |
| 3846 if (isym == NULL) |
| 3847 return FALSE; |
| 3848 |
| 3849 if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC) |
| 3850 elf_s390_finish_ifunc_symbol (output_bfd, info, NULL, htab, |
| 3851 local_plt[i].plt.offset, |
| 3852 isym->st_value |
| 3853 + sec->output_section->vma |
| 3854 + sec->output_offset); |
| 3855 |
| 3856 } |
| 3857 } |
| 3858 } |
3430 return TRUE; | 3859 return TRUE; |
3431 } | 3860 } |
3432 | 3861 |
3433 static bfd_boolean | 3862 static bfd_boolean |
3434 elf_s390_grok_prstatus (abfd, note) | 3863 elf_s390_grok_prstatus (bfd * abfd, Elf_Internal_Note * note) |
3435 bfd * abfd; | |
3436 Elf_Internal_Note * note; | |
3437 { | 3864 { |
3438 int offset; | 3865 int offset; |
3439 unsigned int size; | 3866 unsigned int size; |
3440 | 3867 |
3441 switch (note->descsz) | 3868 switch (note->descsz) |
3442 { | 3869 { |
3443 default: | 3870 default: |
3444 return FALSE; | 3871 return FALSE; |
3445 | 3872 |
3446 case 224: /* S/390 Linux. */ | 3873 case 224: /* S/390 Linux. */ |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3512 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol | 3939 #define elf_backend_finish_dynamic_symbol elf_s390_finish_dynamic_symbol |
3513 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook | 3940 #define elf_backend_gc_mark_hook elf_s390_gc_mark_hook |
3514 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook | 3941 #define elf_backend_gc_sweep_hook elf_s390_gc_sweep_hook |
3515 #define elf_backend_reloc_type_class elf_s390_reloc_type_class | 3942 #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
3516 #define elf_backend_relocate_section elf_s390_relocate_section | 3943 #define elf_backend_relocate_section elf_s390_relocate_section |
3517 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections | 3944 #define elf_backend_size_dynamic_sections elf_s390_size_dynamic_sections |
3518 #define elf_backend_init_index_section _bfd_elf_init_1_index_section | 3945 #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
3519 #define elf_backend_reloc_type_class elf_s390_reloc_type_class | 3946 #define elf_backend_reloc_type_class elf_s390_reloc_type_class |
3520 #define elf_backend_grok_prstatus elf_s390_grok_prstatus | 3947 #define elf_backend_grok_prstatus elf_s390_grok_prstatus |
3521 #define elf_backend_plt_sym_val elf_s390_plt_sym_val | 3948 #define elf_backend_plt_sym_val elf_s390_plt_sym_val |
| 3949 #define elf_backend_add_symbol_hook elf_s390_add_symbol_hook |
3522 | 3950 |
3523 #define bfd_elf32_mkobject elf_s390_mkobject | 3951 #define bfd_elf32_mkobject elf_s390_mkobject |
3524 #define elf_backend_object_p elf_s390_object_p | 3952 #define elf_backend_object_p elf_s390_object_p |
3525 | 3953 |
3526 #include "elf32-target.h" | 3954 #include "elf32-target.h" |
OLD | NEW |