1 /* x86 specific support for ELF
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
21 #include "elfxx-x86.h"
22 #include "elf-vxworks.h"
25 /* The name of the dynamic interpreter. This is put in the .interp
28 #define ELF32_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
29 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
30 #define ELFX32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
33 _bfd_x86_elf_mkobject (bfd
*abfd
)
35 return bfd_elf_allocate_object (abfd
,
36 sizeof (struct elf_x86_obj_tdata
),
37 get_elf_backend_data (abfd
)->target_id
);
40 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
41 executables. Rather than setting it to the beginning of the TLS
42 section, we have to set it to the end. This function may be called
43 multiple times, it is idempotent. */
46 _bfd_x86_elf_set_tls_module_base (struct bfd_link_info
*info
)
48 struct elf_x86_link_hash_table
*htab
;
49 struct bfd_link_hash_entry
*base
;
50 const struct elf_backend_data
*bed
;
52 if (!bfd_link_executable (info
))
55 bed
= get_elf_backend_data (info
->output_bfd
);
56 htab
= elf_x86_hash_table (info
, bed
->target_id
);
60 base
= htab
->tls_module_base
;
64 base
->u
.def
.value
= htab
->elf
.tls_size
;
67 /* Return the base VMA address which should be subtracted from real addresses
68 when resolving @dtpoff relocation.
69 This is PT_TLS segment p_vaddr. */
72 _bfd_x86_elf_dtpoff_base (struct bfd_link_info
*info
)
74 /* If tls_sec is NULL, we should have signalled an error already. */
75 if (elf_hash_table (info
)->tls_sec
== NULL
)
77 return elf_hash_table (info
)->tls_sec
->vma
;
80 /* Allocate space in .plt, .got and associated reloc sections for
84 elf_x86_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
86 struct bfd_link_info
*info
;
87 struct elf_x86_link_hash_table
*htab
;
88 struct elf_x86_link_hash_entry
*eh
;
89 struct elf_dyn_relocs
*p
;
90 unsigned int plt_entry_size
;
91 bool resolved_to_zero
;
92 const struct elf_backend_data
*bed
;
94 if (h
->root
.type
== bfd_link_hash_indirect
)
97 eh
= (struct elf_x86_link_hash_entry
*) h
;
99 info
= (struct bfd_link_info
*) inf
;
100 bed
= get_elf_backend_data (info
->output_bfd
);
101 htab
= elf_x86_hash_table (info
, bed
->target_id
);
105 plt_entry_size
= htab
->plt
.plt_entry_size
;
107 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
109 /* We can't use the GOT PLT if pointer equality is needed since
110 finish_dynamic_symbol won't clear symbol value and the dynamic
111 linker won't update the GOT slot. We will get into an infinite
113 if (htab
->plt_got
!= NULL
114 && h
->type
!= STT_GNU_IFUNC
115 && !h
->pointer_equality_needed
116 && h
->plt
.refcount
> 0
117 && h
->got
.refcount
> 0)
119 /* Don't use the regular PLT if there are both GOT and GOTPLT
121 h
->plt
.offset
= (bfd_vma
) -1;
123 /* Use the GOT PLT. */
124 eh
->plt_got
.refcount
= 1;
127 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
128 here if it is defined and referenced in a non-shared object. */
129 if (h
->type
== STT_GNU_IFUNC
132 /* GOTOFF relocation needs PLT. */
136 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &h
->dyn_relocs
,
140 htab
->got_entry_size
,
143 asection
*s
= htab
->plt_second
;
144 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
146 /* Use the second PLT section if it is created. */
147 eh
->plt_second
.offset
= s
->size
;
149 /* Make room for this entry in the second PLT section. */
150 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
158 /* Don't create the PLT entry if there are only function pointer
159 relocations which can be resolved at run-time. */
160 else if (htab
->elf
.dynamic_sections_created
161 && (h
->plt
.refcount
> 0
162 || eh
->plt_got
.refcount
> 0))
164 bool use_plt_got
= eh
->plt_got
.refcount
> 0;
166 /* Make sure this symbol is output as a dynamic symbol.
167 Undefined weak syms won't yet be marked as dynamic. */
171 && h
->root
.type
== bfd_link_hash_undefweak
)
173 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
177 if (bfd_link_pic (info
)
178 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
180 asection
*s
= htab
->elf
.splt
;
181 asection
*second_s
= htab
->plt_second
;
182 asection
*got_s
= htab
->plt_got
;
185 /* If this is the first .plt entry, make room for the special
186 first entry. The .plt section is used by prelink to undo
187 prelinking for dynamic relocations. */
189 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
192 eh
->plt_got
.offset
= got_s
->size
;
195 h
->plt
.offset
= s
->size
;
197 eh
->plt_second
.offset
= second_s
->size
;
200 /* If this symbol is not defined in a regular file, and we are
201 generating PDE, then set the symbol to this location in the
202 .plt. This is required to make function pointers compare
203 as equal between PDE and the shared library.
205 NB: If PLT is PC-relative, we can use the .plt in PIE for
209 else if (htab
->pcrel_plt
)
210 use_plt
= ! bfd_link_dll (info
);
212 use_plt
= bfd_link_pde (info
);
217 /* We need to make a call to the entry of the GOT PLT
218 instead of regular PLT entry. */
219 h
->root
.u
.def
.section
= got_s
;
220 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
226 /* We need to make a call to the entry of the
227 second PLT instead of regular PLT entry. */
228 h
->root
.u
.def
.section
= second_s
;
229 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
233 h
->root
.u
.def
.section
= s
;
234 h
->root
.u
.def
.value
= h
->plt
.offset
;
239 /* Make room for this entry. */
241 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
244 s
->size
+= plt_entry_size
;
246 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
248 /* We also need to make an entry in the .got.plt section,
249 which will be placed in the .got section by the linker
251 htab
->elf
.sgotplt
->size
+= htab
->got_entry_size
;
253 /* There should be no PLT relocation against resolved
254 undefined weak symbol in executable. */
255 if (!resolved_to_zero
)
257 /* We also need to make an entry in the .rel.plt
259 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
260 htab
->elf
.srelplt
->reloc_count
++;
264 if (htab
->elf
.target_os
== is_vxworks
&& !bfd_link_pic (info
))
266 /* VxWorks has a second set of relocations for each PLT entry
267 in executables. They go in a separate relocation section,
268 which is processed by the kernel loader. */
270 /* There are two relocations for the initial PLT entry: an
271 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
272 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
274 asection
*srelplt2
= htab
->srelplt2
;
275 if (h
->plt
.offset
== plt_entry_size
)
276 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
278 /* There are two extra relocations for each subsequent PLT entry:
279 an R_386_32 relocation for the GOT entry, and an R_386_32
280 relocation for the PLT entry. */
282 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
287 eh
->plt_got
.offset
= (bfd_vma
) -1;
288 h
->plt
.offset
= (bfd_vma
) -1;
294 eh
->plt_got
.offset
= (bfd_vma
) -1;
295 h
->plt
.offset
= (bfd_vma
) -1;
299 eh
->tlsdesc_got
= (bfd_vma
) -1;
301 /* For i386, if R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the
302 binary, make it a R_386_TLS_LE_32 requiring no TLS entry. For
303 x86-64, if R_X86_64_GOTTPOFF symbol is now local to the binary,
304 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
305 if (h
->got
.refcount
> 0
306 && bfd_link_executable (info
)
308 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
309 h
->got
.offset
= (bfd_vma
) -1;
310 else if (h
->got
.refcount
> 0)
314 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
316 /* Make sure this symbol is output as a dynamic symbol.
317 Undefined weak syms won't yet be marked as dynamic. */
321 && h
->root
.type
== bfd_link_hash_undefweak
)
323 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
328 if (GOT_TLS_GDESC_P (tls_type
))
330 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
331 - elf_x86_compute_jump_table_size (htab
);
332 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
333 h
->got
.offset
= (bfd_vma
) -2;
335 if (! GOT_TLS_GDESC_P (tls_type
)
336 || GOT_TLS_GD_P (tls_type
))
338 h
->got
.offset
= s
->size
;
339 s
->size
+= htab
->got_entry_size
;
340 /* R_386_TLS_GD and R_X86_64_TLSGD need 2 consecutive GOT
342 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
343 s
->size
+= htab
->got_entry_size
;
345 dyn
= htab
->elf
.dynamic_sections_created
;
346 /* R_386_TLS_IE_32 needs one dynamic relocation,
347 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
348 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
349 need two), R_386_TLS_GD and R_X86_64_TLSGD need one if local
350 symbol and two if global. No dynamic relocation against
351 resolved undefined weak symbol in executable. No dynamic
352 relocation against non-preemptible absolute symbol. */
353 if (tls_type
== GOT_TLS_IE_BOTH
)
354 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
355 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
356 || (tls_type
& GOT_TLS_IE
))
357 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
358 else if (GOT_TLS_GD_P (tls_type
))
359 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
360 else if (! GOT_TLS_GDESC_P (tls_type
)
361 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
362 && !resolved_to_zero
)
363 || h
->root
.type
!= bfd_link_hash_undefweak
)
364 && ((bfd_link_pic (info
)
365 && !(h
->dynindx
== -1
366 && ABS_SYMBOL_P (h
)))
367 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
368 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
369 if (GOT_TLS_GDESC_P (tls_type
))
371 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
372 if (bed
->target_id
== X86_64_ELF_DATA
)
373 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
377 h
->got
.offset
= (bfd_vma
) -1;
379 if (h
->dyn_relocs
== NULL
)
382 /* In the shared -Bsymbolic case, discard space allocated for
383 dynamic pc-relative relocs against symbols which turn out to be
384 defined in regular objects. For the normal shared case, discard
385 space for pc-relative relocs that have become local due to symbol
386 visibility changes. */
388 if (bfd_link_pic (info
))
390 /* Relocs that use pc_count are those that appear on a call
391 insn, or certain REL relocs that can generated via assembly.
392 We want calls to protected symbols to resolve directly to the
393 function rather than going via the plt. If people want
394 function pointer comparisons to work as expected then they
395 should avoid writing weird assembly. */
396 if (SYMBOL_CALLS_LOCAL (info
, h
))
398 struct elf_dyn_relocs
**pp
;
400 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
402 p
->count
-= p
->pc_count
;
411 if (htab
->elf
.target_os
== is_vxworks
)
413 struct elf_dyn_relocs
**pp
;
414 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
416 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
423 /* Also discard relocs on undefined weak syms with non-default
424 visibility or in PIE. */
425 if (h
->dyn_relocs
!= NULL
)
427 if (h
->root
.type
== bfd_link_hash_undefweak
)
429 /* Undefined weak symbol is never bound locally in shared
431 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
434 if (bed
->target_id
== I386_ELF_DATA
437 /* Keep dynamic non-GOT/non-PLT relocation so
438 that we can branch to 0 without PLT. */
439 struct elf_dyn_relocs
**pp
;
441 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
442 if (p
->pc_count
== 0)
446 /* Remove non-R_386_PC32 relocation. */
447 p
->count
= p
->pc_count
;
451 /* Make sure undefined weak symbols are output
452 as dynamic symbols in PIEs for dynamic non-GOT
453 non-PLT reloations. */
454 if (h
->dyn_relocs
!= NULL
455 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
459 h
->dyn_relocs
= NULL
;
461 else if (h
->dynindx
== -1
463 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
466 else if (bfd_link_executable (info
)
467 && (h
->needs_copy
|| eh
->needs_copy
)
471 /* NB: needs_copy is set only for x86-64. For PIE,
472 discard space for pc-relative relocs against symbols
473 which turn out to need copy relocs. */
474 struct elf_dyn_relocs
**pp
;
476 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
478 if (p
->pc_count
!= 0)
486 else if (ELIMINATE_COPY_RELOCS
)
488 /* For the non-shared case, discard space for relocs against
489 symbols which turn out to need copy relocs or are not
490 dynamic. Keep dynamic relocations for run-time function
491 pointer initialization. */
494 || (h
->root
.type
== bfd_link_hash_undefweak
495 && !resolved_to_zero
))
498 || (htab
->elf
.dynamic_sections_created
499 && (h
->root
.type
== bfd_link_hash_undefweak
500 || h
->root
.type
== bfd_link_hash_undefined
))))
502 /* Make sure this symbol is output as a dynamic symbol.
503 Undefined weak syms won't yet be marked as dynamic. */
507 && h
->root
.type
== bfd_link_hash_undefweak
508 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
511 /* If that succeeded, we know we'll be keeping all the
513 if (h
->dynindx
!= -1)
517 h
->dyn_relocs
= NULL
;
522 /* Finally, allocate space. */
523 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
527 if (eh
->def_protected
&& bfd_link_executable (info
))
529 /* Disallow copy relocation against non-copyable protected
531 asection
*s
= p
->sec
->output_section
;
532 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
534 info
->callbacks
->einfo
535 /* xgettext:c-format */
536 (_("%F%P: %pB: copy relocation against non-copyable "
537 "protected symbol `%s' in %pB\n"),
538 p
->sec
->owner
, h
->root
.root
.string
,
539 h
->root
.u
.def
.section
->owner
);
544 sreloc
= elf_section_data (p
->sec
)->sreloc
;
546 BFD_ASSERT (sreloc
!= NULL
);
547 sreloc
->size
+= p
->count
* htab
->sizeof_reloc
;
553 /* Allocate space in .plt, .got and associated reloc sections for
554 local dynamic relocs. */
557 elf_x86_allocate_local_dynreloc (void **slot
, void *inf
)
559 struct elf_link_hash_entry
*h
560 = (struct elf_link_hash_entry
*) *slot
;
562 if (h
->type
!= STT_GNU_IFUNC
566 || h
->root
.type
!= bfd_link_hash_defined
)
569 return elf_x86_allocate_dynrelocs (h
, inf
);
572 /* Find and/or create a hash entry for local symbol. */
574 struct elf_link_hash_entry
*
575 _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table
*htab
,
576 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
579 struct elf_x86_link_hash_entry e
, *ret
;
580 asection
*sec
= abfd
->sections
;
581 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
582 htab
->r_sym (rel
->r_info
));
585 e
.elf
.indx
= sec
->id
;
586 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
587 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
588 create
? INSERT
: NO_INSERT
);
595 ret
= (struct elf_x86_link_hash_entry
*) *slot
;
599 ret
= (struct elf_x86_link_hash_entry
*)
600 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
601 sizeof (struct elf_x86_link_hash_entry
));
604 memset (ret
, 0, sizeof (*ret
));
605 ret
->elf
.indx
= sec
->id
;
606 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
607 ret
->elf
.dynindx
= -1;
608 ret
->plt_got
.offset
= (bfd_vma
) -1;
614 /* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
615 SYNC WITH _bfd_elf_link_hash_newfunc. */
617 struct bfd_hash_entry
*
618 _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
619 struct bfd_hash_table
*table
,
622 /* Allocate the structure if it has not already been allocated by a
626 entry
= (struct bfd_hash_entry
*)
627 bfd_hash_allocate (table
,
628 sizeof (struct elf_x86_link_hash_entry
));
633 /* Call the allocation method of the superclass. */
634 entry
= _bfd_link_hash_newfunc (entry
, table
, string
);
637 struct elf_x86_link_hash_entry
*eh
638 = (struct elf_x86_link_hash_entry
*) entry
;
639 struct elf_link_hash_table
*htab
640 = (struct elf_link_hash_table
*) table
;
642 memset (&eh
->elf
.size
, 0,
643 (sizeof (struct elf_x86_link_hash_entry
)
644 - offsetof (struct elf_link_hash_entry
, size
)));
645 /* Set local fields. */
647 eh
->elf
.dynindx
= -1;
648 eh
->elf
.got
= htab
->init_got_refcount
;
649 eh
->elf
.plt
= htab
->init_plt_refcount
;
650 /* Assume that we have been called by a non-ELF symbol reader.
651 This flag is then reset by the code which reads an ELF input
652 file. This ensures that a symbol created by a non-ELF symbol
653 reader will have the flag set correctly. */
655 eh
->plt_second
.offset
= (bfd_vma
) -1;
656 eh
->plt_got
.offset
= (bfd_vma
) -1;
657 eh
->tlsdesc_got
= (bfd_vma
) -1;
658 eh
->zero_undefweak
= 1;
664 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
665 for local symbol so that we can handle local STT_GNU_IFUNC symbols
666 as global symbol. We reuse indx and dynstr_index for local symbol
667 hash since they aren't used by global symbols in this backend. */
670 _bfd_x86_elf_local_htab_hash (const void *ptr
)
672 struct elf_link_hash_entry
*h
673 = (struct elf_link_hash_entry
*) ptr
;
674 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
677 /* Compare local hash entries. */
680 _bfd_x86_elf_local_htab_eq (const void *ptr1
, const void *ptr2
)
682 struct elf_link_hash_entry
*h1
683 = (struct elf_link_hash_entry
*) ptr1
;
684 struct elf_link_hash_entry
*h2
685 = (struct elf_link_hash_entry
*) ptr2
;
687 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
690 /* Destroy an x86 ELF linker hash table. */
693 elf_x86_link_hash_table_free (bfd
*obfd
)
695 struct elf_x86_link_hash_table
*htab
696 = (struct elf_x86_link_hash_table
*) obfd
->link
.hash
;
698 if (htab
->loc_hash_table
)
699 htab_delete (htab
->loc_hash_table
);
700 if (htab
->loc_hash_memory
)
701 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
702 _bfd_elf_link_hash_table_free (obfd
);
706 elf_i386_is_reloc_section (const char *secname
)
708 return startswith (secname
, ".rel");
712 elf_x86_64_is_reloc_section (const char *secname
)
714 return startswith (secname
, ".rela");
717 /* Create an x86 ELF linker hash table. */
719 struct bfd_link_hash_table
*
720 _bfd_x86_elf_link_hash_table_create (bfd
*abfd
)
722 struct elf_x86_link_hash_table
*ret
;
723 const struct elf_backend_data
*bed
;
724 size_t amt
= sizeof (struct elf_x86_link_hash_table
);
726 ret
= (struct elf_x86_link_hash_table
*) bfd_zmalloc (amt
);
730 bed
= get_elf_backend_data (abfd
);
731 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
732 _bfd_x86_elf_link_hash_newfunc
,
733 sizeof (struct elf_x86_link_hash_entry
),
740 if (bed
->target_id
== X86_64_ELF_DATA
)
742 ret
->is_reloc_section
= elf_x86_64_is_reloc_section
;
743 ret
->got_entry_size
= 8;
744 ret
->pcrel_plt
= true;
745 ret
->tls_get_addr
= "__tls_get_addr";
746 ret
->relative_r_type
= R_X86_64_RELATIVE
;
747 ret
->relative_r_name
= "R_X86_64_RELATIVE";
748 ret
->elf_append_reloc
= elf_append_rela
;
749 ret
->elf_write_addend_in_got
= _bfd_elf64_write_addend
;
753 ret
->sizeof_reloc
= sizeof (Elf64_External_Rela
);
754 ret
->pointer_r_type
= R_X86_64_64
;
755 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
756 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
757 ret
->elf_write_addend
= _bfd_elf64_write_addend
;
761 if (bed
->target_id
== X86_64_ELF_DATA
)
763 ret
->sizeof_reloc
= sizeof (Elf32_External_Rela
);
764 ret
->pointer_r_type
= R_X86_64_32
;
765 ret
->dynamic_interpreter
= ELFX32_DYNAMIC_INTERPRETER
;
766 ret
->dynamic_interpreter_size
767 = sizeof ELFX32_DYNAMIC_INTERPRETER
;
768 ret
->elf_write_addend
= _bfd_elf32_write_addend
;
772 ret
->is_reloc_section
= elf_i386_is_reloc_section
;
773 ret
->sizeof_reloc
= sizeof (Elf32_External_Rel
);
774 ret
->got_entry_size
= 4;
775 ret
->pcrel_plt
= false;
776 ret
->pointer_r_type
= R_386_32
;
777 ret
->relative_r_type
= R_386_RELATIVE
;
778 ret
->relative_r_name
= "R_386_RELATIVE";
779 ret
->elf_append_reloc
= elf_append_rel
;
780 ret
->elf_write_addend
= _bfd_elf32_write_addend
;
781 ret
->elf_write_addend_in_got
= _bfd_elf32_write_addend
;
782 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
783 ret
->dynamic_interpreter_size
784 = sizeof ELF32_DYNAMIC_INTERPRETER
;
785 ret
->tls_get_addr
= "___tls_get_addr";
789 ret
->loc_hash_table
= htab_try_create (1024,
790 _bfd_x86_elf_local_htab_hash
,
791 _bfd_x86_elf_local_htab_eq
,
793 ret
->loc_hash_memory
= objalloc_create ();
794 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
796 elf_x86_link_hash_table_free (abfd
);
799 ret
->elf
.root
.hash_table_free
= elf_x86_link_hash_table_free
;
801 return &ret
->elf
.root
;
804 /* Sort relocs into address order. */
807 _bfd_x86_elf_compare_relocs (const void *ap
, const void *bp
)
809 const arelent
*a
= * (const arelent
**) ap
;
810 const arelent
*b
= * (const arelent
**) bp
;
812 if (a
->address
> b
->address
)
814 else if (a
->address
< b
->address
)
820 /* Mark symbol, NAME, as locally defined by linker if it is referenced
821 and not defined in a relocatable object file. */
824 elf_x86_linker_defined (struct bfd_link_info
*info
, const char *name
)
826 struct elf_link_hash_entry
*h
;
828 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
829 false, false, false);
833 while (h
->root
.type
== bfd_link_hash_indirect
)
834 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
836 if (h
->root
.type
== bfd_link_hash_new
837 || h
->root
.type
== bfd_link_hash_undefined
838 || h
->root
.type
== bfd_link_hash_undefweak
839 || h
->root
.type
== bfd_link_hash_common
840 || (!h
->def_regular
&& h
->def_dynamic
))
842 elf_x86_hash_entry (h
)->local_ref
= 2;
843 elf_x86_hash_entry (h
)->linker_def
= 1;
847 /* Hide a linker-defined symbol, NAME, with hidden visibility. */
850 elf_x86_hide_linker_defined (struct bfd_link_info
*info
,
853 struct elf_link_hash_entry
*h
;
855 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
856 false, false, false);
860 while (h
->root
.type
== bfd_link_hash_indirect
)
861 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
863 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
864 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
865 _bfd_elf_link_hash_hide_symbol (info
, h
, true);
869 _bfd_x86_elf_link_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
)
871 if (!bfd_link_relocatable (info
))
873 /* Check for __tls_get_addr reference. */
874 struct elf_x86_link_hash_table
*htab
;
875 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
876 htab
= elf_x86_hash_table (info
, bed
->target_id
);
879 struct elf_link_hash_entry
*h
;
881 h
= elf_link_hash_lookup (elf_hash_table (info
),
883 false, false, false);
886 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
888 /* Check the versioned __tls_get_addr symbol. */
889 while (h
->root
.type
== bfd_link_hash_indirect
)
891 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
892 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
896 /* "__ehdr_start" will be defined by linker as a hidden symbol
897 later if it is referenced and not defined. */
898 elf_x86_linker_defined (info
, "__ehdr_start");
900 if (bfd_link_executable (info
))
902 /* References to __bss_start, _end and _edata should be
903 locally resolved within executables. */
904 elf_x86_linker_defined (info
, "__bss_start");
905 elf_x86_linker_defined (info
, "_end");
906 elf_x86_linker_defined (info
, "_edata");
910 /* Hide hidden __bss_start, _end and _edata in shared
912 elf_x86_hide_linker_defined (info
, "__bss_start");
913 elf_x86_hide_linker_defined (info
, "_end");
914 elf_x86_hide_linker_defined (info
, "_edata");
919 /* Invoke the regular ELF backend linker to do all the work. */
920 return _bfd_elf_link_check_relocs (abfd
, info
);
923 /* Look through the relocs for a section before allocation to make the
924 dynamic reloc section. */
927 _bfd_x86_elf_check_relocs (bfd
*abfd
,
928 struct bfd_link_info
*info
,
930 const Elf_Internal_Rela
*relocs
)
932 struct elf_x86_link_hash_table
*htab
;
933 Elf_Internal_Shdr
*symtab_hdr
;
934 struct elf_link_hash_entry
**sym_hashes
;
935 const Elf_Internal_Rela
*rel
;
936 const Elf_Internal_Rela
*rel_end
;
938 const struct elf_backend_data
*bed
;
941 if (bfd_link_relocatable (info
))
944 bed
= get_elf_backend_data (abfd
);
945 htab
= elf_x86_hash_table (info
, bed
->target_id
);
948 sec
->check_relocs_failed
= 1;
952 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
954 symtab_hdr
= &elf_symtab_hdr (abfd
);
955 sym_hashes
= elf_sym_hashes (abfd
);
957 rel_end
= relocs
+ sec
->reloc_count
;
958 for (rel
= relocs
; rel
< rel_end
; rel
++)
961 unsigned int r_symndx
;
962 struct elf_link_hash_entry
*h
;
964 r_symndx
= htab
->r_sym (rel
->r_info
);
965 r_type
= ELF32_R_TYPE (rel
->r_info
);
967 if (r_symndx
>= NUM_SHDR_ENTRIES (symtab_hdr
))
969 /* xgettext:c-format */
970 _bfd_error_handler (_("%pB: bad symbol index: %d"),
975 if (r_symndx
< symtab_hdr
->sh_info
)
979 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
980 while (h
->root
.type
== bfd_link_hash_indirect
981 || h
->root
.type
== bfd_link_hash_warning
)
982 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
985 if (X86_NEED_DYNAMIC_RELOC_TYPE_P (is_x86_64
, r_type
)
986 && NEED_DYNAMIC_RELOCATION_P (is_x86_64
, info
, true, h
, sec
,
987 r_type
, htab
->pointer_r_type
))
989 /* We may copy these reloc types into the output file.
990 Create a reloc section in dynobj and make room for
992 sreloc
= _bfd_elf_make_dynamic_reloc_section
993 (sec
, htab
->elf
.dynobj
, ABI_64_P (abfd
) ? 3 : 2,
994 abfd
, sec
->use_rela_p
);
1000 sec
->check_relocs_failed
= 1;
1008 /* Add an entry to the relative reloc record. */
1011 elf_x86_relative_reloc_record_add
1012 (struct bfd_link_info
*info
,
1013 struct elf_x86_relative_reloc_data
*relative_reloc
,
1014 Elf_Internal_Rela
*rel
, asection
*sec
,
1015 asection
*sym_sec
, struct elf_link_hash_entry
*h
,
1016 Elf_Internal_Sym
*sym
, bfd_vma offset
, bool *keep_symbuf_p
)
1018 bfd_size_type newidx
;
1020 if (relative_reloc
->data
== NULL
)
1022 relative_reloc
->data
= bfd_malloc
1023 (sizeof (struct elf_x86_relative_reloc_record
));
1024 relative_reloc
->count
= 0;
1025 relative_reloc
->size
= 1;
1028 newidx
= relative_reloc
->count
++;
1030 if (relative_reloc
->count
> relative_reloc
->size
)
1032 relative_reloc
->size
<<= 1;
1033 relative_reloc
->data
= bfd_realloc
1034 (relative_reloc
->data
,
1035 (relative_reloc
->size
1036 * sizeof (struct elf_x86_relative_reloc_record
)));
1039 if (relative_reloc
->data
== NULL
)
1041 info
->callbacks
->einfo
1042 /* xgettext:c-format */
1043 (_("%F%P: %pB: failed to allocate relative reloc record\n"),
1048 relative_reloc
->data
[newidx
].rel
= *rel
;
1049 relative_reloc
->data
[newidx
].sec
= sec
;
1052 /* Set SYM to NULL to indicate a global symbol. */
1053 relative_reloc
->data
[newidx
].sym
= NULL
;
1054 relative_reloc
->data
[newidx
].u
.h
= h
;
1058 relative_reloc
->data
[newidx
].sym
= sym
;
1059 relative_reloc
->data
[newidx
].u
.sym_sec
= sym_sec
;
1060 /* We must keep the symbol buffer since SYM will be used later. */
1061 *keep_symbuf_p
= true;
1063 relative_reloc
->data
[newidx
].offset
= offset
;
1064 relative_reloc
->data
[newidx
].address
= 0;
1068 /* After input sections have been mapped to output sections and
1069 addresses of output sections are set initiallly, scan input
1070 relocations with the same logic in relocate_section to determine
1071 if a relative relocation should be generated. Save the relative
1072 relocation candidate information for sizing the DT_RELR section
1073 later after all symbols addresses can be determined. */
1076 _bfd_x86_elf_link_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
,
1077 asection
*input_section
,
1078 struct bfd_link_info
*info
,
1081 Elf_Internal_Shdr
*symtab_hdr
;
1082 Elf_Internal_Rela
*internal_relocs
;
1083 Elf_Internal_Rela
*irel
, *irelend
;
1084 Elf_Internal_Sym
*isymbuf
= NULL
;
1085 struct elf_link_hash_entry
**sym_hashes
;
1086 const struct elf_backend_data
*bed
;
1087 struct elf_x86_link_hash_table
*htab
;
1088 bfd_vma
*local_got_offsets
;
1090 bool unaligned_section
;
1091 bool return_status
= false;
1092 bool keep_symbuf
= false;
1094 if (bfd_link_relocatable (info
))
1097 /* Assume we're not going to change any sizes, and we'll only need
1101 bed
= get_elf_backend_data (abfd
);
1102 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1106 /* Nothing to do if there are no relocations or relative relocations
1107 have been packed. */
1108 if (input_section
== htab
->elf
.srelrdyn
1109 || input_section
->relative_reloc_packed
1110 || ((input_section
->flags
& (SEC_RELOC
| SEC_ALLOC
))
1111 != (SEC_RELOC
| SEC_ALLOC
))
1112 || (input_section
->flags
& SEC_DEBUGGING
) != 0
1113 || input_section
->reloc_count
== 0)
1116 /* Skip if the section isn't aligned. */
1117 unaligned_section
= input_section
->alignment_power
== 0;
1119 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
1121 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1122 sym_hashes
= elf_sym_hashes (abfd
);
1123 local_got_offsets
= elf_local_got_offsets (abfd
);
1125 /* Load the relocations for this section. */
1127 _bfd_elf_link_info_read_relocs (abfd
, info
, input_section
, NULL
,
1128 (Elf_Internal_Rela
*) NULL
,
1130 if (internal_relocs
== NULL
)
1133 irelend
= internal_relocs
+ input_section
->reloc_count
;
1134 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1136 unsigned int r_type
;
1137 unsigned int r_symndx
;
1138 Elf_Internal_Sym
*isym
;
1139 struct elf_link_hash_entry
*h
;
1140 struct elf_x86_link_hash_entry
*eh
;
1142 bool resolved_to_zero
;
1143 bool need_copy_reloc_in_pie
;
1146 /* Offset must be a multiple of 2. */
1147 bool unaligned_offset
= (irel
->r_offset
& 1) != 0;
1148 /* True if there is a relative relocation against a dynamic
1150 bool dynamic_relative_reloc_p
;
1152 /* Get the value of the symbol referred to by the reloc. */
1153 r_symndx
= htab
->r_sym (irel
->r_info
);
1155 r_type
= ELF32_R_TYPE (irel
->r_info
);
1156 /* Clear the R_X86_64_converted_reloc_bit bit. */
1157 r_type
&= ~R_X86_64_converted_reloc_bit
;
1161 dynamic_relative_reloc_p
= false;
1163 if (r_symndx
< symtab_hdr
->sh_info
)
1165 /* Read this BFD's local symbols. */
1166 if (isymbuf
== NULL
)
1168 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1169 if (isymbuf
== NULL
)
1171 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1172 symtab_hdr
->sh_info
,
1173 0, NULL
, NULL
, NULL
);
1174 if (isymbuf
== NULL
)
1179 isym
= isymbuf
+ r_symndx
;
1180 switch (isym
->st_shndx
)
1183 sec
= bfd_abs_section_ptr
;
1186 sec
= bfd_com_section_ptr
;
1188 case SHN_X86_64_LCOMMON
:
1191 sec
= &_bfd_elf_large_com_section
;
1194 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1198 /* Skip relocation against local STT_GNU_IFUNC symbol. */
1199 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1202 eh
= (struct elf_x86_link_hash_entry
*) h
;
1203 resolved_to_zero
= false;
1207 /* Get H and SEC for GENERATE_DYNAMIC_RELOCATION_P below. */
1208 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1209 while (h
->root
.type
== bfd_link_hash_indirect
1210 || h
->root
.type
== bfd_link_hash_warning
)
1211 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1213 if (h
->root
.type
== bfd_link_hash_defined
1214 || h
->root
.type
== bfd_link_hash_defweak
)
1215 sec
= h
->root
.u
.def
.section
;
1217 /* Skip relocation against STT_GNU_IFUNC symbol. */
1218 if (h
->type
== STT_GNU_IFUNC
)
1221 eh
= (struct elf_x86_link_hash_entry
*) h
;
1222 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
1224 /* NB: See how elf_backend_finish_dynamic_symbol is called
1225 from elf_link_output_extsym. */
1226 if ((h
->dynindx
!= -1 || h
->forced_local
)
1227 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1228 || h
->root
.type
!= bfd_link_hash_undefweak
)
1229 || !h
->forced_local
)
1230 && h
->got
.offset
!= (bfd_vma
) -1
1231 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
1232 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
1233 && !resolved_to_zero
1234 && SYMBOL_REFERENCES_LOCAL_P (info
, h
)
1235 && SYMBOL_DEFINED_NON_SHARED_P (h
))
1236 dynamic_relative_reloc_p
= true;
1241 if (X86_GOT_TYPE_P (is_x86_64
, r_type
))
1243 /* Pack GOT relative relocations. There should be only a
1244 single R_*_RELATIVE relocation in GOT. */
1247 if (eh
->got_relative_reloc_done
)
1250 if (!(dynamic_relative_reloc_p
1251 || (RESOLVED_LOCALLY_P (info
, h
, htab
)
1252 && GENERATE_RELATIVE_RELOC_P (info
, h
))))
1255 if (!dynamic_relative_reloc_p
)
1256 eh
->no_finish_dynamic_symbol
= 1;
1257 eh
->got_relative_reloc_done
= 1;
1258 offset
= h
->got
.offset
;
1262 if (elf_x86_relative_reloc_done (abfd
)[r_symndx
])
1265 if (!X86_LOCAL_GOT_RELATIVE_RELOC_P (is_x86_64
, info
,
1269 elf_x86_relative_reloc_done (abfd
)[r_symndx
] = 1;
1270 offset
= local_got_offsets
[r_symndx
];
1273 if (!elf_x86_relative_reloc_record_add (info
,
1274 &htab
->relative_reloc
,
1275 irel
, htab
->elf
.sgot
,
1276 sec
, h
, isym
, offset
,
1284 && irel
->r_addend
== 0
1285 && !ABI_64_P (info
->output_bfd
))
1287 /* For x32, if addend is zero, treat R_X86_64_64 like
1288 R_X86_64_32 and R_X86_64_SIZE64 like R_X86_64_SIZE32. */
1289 if (r_type
== R_X86_64_64
)
1290 r_type
= R_X86_64_32
;
1291 else if (r_type
== R_X86_64_SIZE64
)
1292 r_type
= R_X86_64_SIZE32
;
1295 if (!X86_RELATIVE_RELOC_TYPE_P (is_x86_64
, r_type
))
1298 /* Pack non-GOT relative relocations. */
1301 need_copy_reloc_in_pie
=
1302 (bfd_link_pie (info
)
1306 || (h
->root
.type
== bfd_link_hash_undefined
))
1307 && (X86_PCREL_TYPE_P (true, r_type
)
1308 || X86_SIZE_TYPE_P (true, r_type
)));
1313 need_copy_reloc_in_pie
= false;
1314 pc32_reloc
= r_type
== R_386_PC32
;
1317 if (GENERATE_DYNAMIC_RELOCATION_P (is_x86_64
, info
, eh
, r_type
,
1318 sec
, need_copy_reloc_in_pie
,
1319 resolved_to_zero
, pc32_reloc
))
1321 /* When generating a shared object, these relocations
1322 are copied into the output file to be resolved at run
1324 offset
= _bfd_elf_section_offset (info
->output_bfd
, info
,
1327 if (offset
== (bfd_vma
) -1
1328 || offset
== (bfd_vma
) -2
1329 || COPY_INPUT_RELOC_P (is_x86_64
, info
, h
, r_type
))
1332 /* This symbol is local, or marked to become local. When
1333 relocation overflow check is disabled, we convert
1334 R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
1336 && !(r_type
== htab
->pointer_r_type
1337 || (r_type
== R_X86_64_32
1338 && htab
->params
->no_reloc_overflow_check
)))
1341 if (!elf_x86_relative_reloc_record_add
1343 ((unaligned_section
|| unaligned_offset
)
1344 ? &htab
->unaligned_relative_reloc
1345 : &htab
->relative_reloc
),
1346 irel
, input_section
, sec
, h
, isym
, offset
,
1352 input_section
->relative_reloc_packed
= 1;
1354 return_status
= true;
1357 if ((unsigned char *) isymbuf
!= symtab_hdr
->contents
)
1359 /* Cache the symbol buffer if it must be kept. */
1361 symtab_hdr
->contents
= (unsigned char *) isymbuf
;
1365 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
1366 free (internal_relocs
);
1367 return return_status
;
1370 /* Add an entry to the 64-bit DT_RELR bitmap. */
1373 elf64_dt_relr_bitmap_add
1374 (struct bfd_link_info
*info
, struct elf_dt_relr_bitmap
*bitmap
,
1377 bfd_size_type newidx
;
1379 if (bitmap
->u
.elf64
== NULL
)
1381 bitmap
->u
.elf64
= bfd_malloc (sizeof (uint64_t));
1386 newidx
= bitmap
->count
++;
1388 if (bitmap
->count
> bitmap
->size
)
1391 bitmap
->u
.elf64
= bfd_realloc (bitmap
->u
.elf64
,
1392 (bitmap
->size
* sizeof (uint64_t)));
1395 if (bitmap
->u
.elf64
== NULL
)
1397 info
->callbacks
->einfo
1398 /* xgettext:c-format */
1399 (_("%F%P: %pB: failed to allocate 64-bit DT_RELR bitmap\n"),
1403 bitmap
->u
.elf64
[newidx
] = entry
;
1406 /* Add an entry to the 32-bit DT_RELR bitmap. */
1409 elf32_dt_relr_bitmap_add
1410 (struct bfd_link_info
*info
, struct elf_dt_relr_bitmap
*bitmap
,
1413 bfd_size_type newidx
;
1415 if (bitmap
->u
.elf32
== NULL
)
1417 bitmap
->u
.elf32
= bfd_malloc (sizeof (uint32_t));
1422 newidx
= bitmap
->count
++;
1424 if (bitmap
->count
> bitmap
->size
)
1427 bitmap
->u
.elf32
= bfd_realloc (bitmap
->u
.elf32
,
1428 (bitmap
->size
* sizeof (uint32_t)));
1431 if (bitmap
->u
.elf32
== NULL
)
1433 info
->callbacks
->einfo
1434 /* xgettext:c-format */
1435 (_("%F%P: %pB: failed to allocate 32-bit DT_RELR bitmap\n"),
1439 bitmap
->u
.elf32
[newidx
] = entry
;
1443 _bfd_elf32_write_addend (bfd
*abfd
, uint64_t value
, void *addr
)
1445 bfd_put_32 (abfd
, value
, addr
);
1449 _bfd_elf64_write_addend (bfd
*abfd
, uint64_t value
, void *addr
)
1451 bfd_put_64 (abfd
, value
, addr
);
1454 /* Size or finish relative relocations to determine the run-time
1455 addresses for DT_RELR bitmap computation later. OUTREL is set
1456 to NULL in the sizing phase and non-NULL in the finising phase
1457 where the regular relative relocations will be written out. */
1460 elf_x86_size_or_finish_relative_reloc
1461 (bool is_x86_64
, struct bfd_link_info
*info
,
1462 struct elf_x86_link_hash_table
*htab
, bool unaligned
,
1463 Elf_Internal_Rela
*outrel
)
1465 unsigned int align_mask
;
1466 bfd_size_type i
, count
;
1467 asection
*sec
, *srel
;
1468 struct elf_link_hash_entry
*h
;
1470 Elf_Internal_Sym
*sym
;
1472 asection
*sgot
= htab
->elf
.sgot
;
1473 asection
*srelgot
= htab
->elf
.srelgot
;
1474 struct elf_x86_relative_reloc_data
*relative_reloc
;
1479 relative_reloc
= &htab
->unaligned_relative_reloc
;
1484 relative_reloc
= &htab
->relative_reloc
;
1487 count
= relative_reloc
->count
;
1488 for (i
= 0; i
< count
; i
++)
1490 sec
= relative_reloc
->data
[i
].sec
;
1491 sym
= relative_reloc
->data
[i
].sym
;
1493 /* If SYM is NULL, it must be a global symbol. */
1495 h
= relative_reloc
->data
[i
].u
.h
;
1502 /* This function may be called more than once and REL may be
1503 updated by _bfd_elf_rela_local_sym below. */
1504 Elf_Internal_Rela rel
= relative_reloc
->data
[i
].rel
;
1508 if (h
->root
.type
== bfd_link_hash_defined
1509 || h
->root
.type
== bfd_link_hash_defweak
)
1511 sym_sec
= h
->root
.u
.def
.section
;
1512 relocation
= (h
->root
.u
.def
.value
1513 + sym_sec
->output_section
->vma
1514 + sym_sec
->output_offset
);
1518 /* Allow undefined symbol only at the sizing phase.
1519 Otherwise skip undefined symbol here. Undefined
1520 symbol will be reported by relocate_section. */
1529 sym_sec
= relative_reloc
->data
[i
].u
.sym_sec
;
1530 relocation
= _bfd_elf_rela_local_sym
1531 (info
->output_bfd
, sym
, &sym_sec
, &rel
);
1536 outrel
->r_addend
= relocation
;
1539 if (h
!= NULL
&& h
->needs_plt
)
1543 outrel
->r_addend
+= rel
.r_addend
;
1545 /* Write the implicit addend if ALIGN_MASK isn't 0. */
1550 if (relative_reloc
->data
[i
].offset
>= sec
->size
)
1552 htab
->elf_write_addend_in_got
1553 (info
->output_bfd
, outrel
->r_addend
,
1554 sec
->contents
+ relative_reloc
->data
[i
].offset
);
1560 if (rel
.r_offset
>= sec
->size
)
1563 if (elf_section_data (sec
)->this_hdr
.contents
1566 = elf_section_data (sec
)->this_hdr
.contents
;
1569 if (!bfd_malloc_and_get_section (sec
->owner
,
1572 info
->callbacks
->einfo
1573 /* xgettext:c-format */
1574 (_("%F%P: %pB: failed to allocate memory for section `%pA'\n"),
1575 info
->output_bfd
, sec
);
1577 /* Cache the section contents for
1578 elf_link_input_bfd. */
1579 elf_section_data (sec
)->this_hdr
.contents
1582 htab
->elf_write_addend
1583 (info
->output_bfd
, outrel
->r_addend
,
1584 contents
+ rel
.r_offset
);
1593 srel
= elf_section_data (sec
)->sreloc
;
1594 offset
= (sec
->output_section
->vma
+ sec
->output_offset
1595 + relative_reloc
->data
[i
].offset
);
1596 relative_reloc
->data
[i
].address
= offset
;
1599 outrel
->r_offset
= offset
;
1601 if ((outrel
->r_offset
& align_mask
) != 0)
1604 if (htab
->params
->report_relative_reloc
)
1605 _bfd_x86_elf_link_report_relative_reloc
1606 (info
, sec
, h
, sym
, htab
->relative_r_name
, outrel
);
1608 /* Generate regular relative relocation if ALIGN_MASK is 0. */
1609 if (align_mask
== 0)
1610 htab
->elf_append_reloc (info
->output_bfd
, srel
, outrel
);
1615 /* Compute the DT_RELR section size. Set NEED_PLAYOUT to true if
1616 the DT_RELR section size has been increased. */
1619 elf_x86_compute_dl_relr_bitmap
1620 (struct bfd_link_info
*info
, struct elf_x86_link_hash_table
*htab
,
1624 bfd_size_type i
, count
, new_count
;
1625 struct elf_x86_relative_reloc_data
*relative_reloc
=
1626 &htab
->relative_reloc
;
1627 /* Save the old DT_RELR bitmap count. Don't shrink the DT_RELR bitmap
1628 if the new DT_RELR bitmap count is smaller than the old one. Pad
1629 with trailing 1s which won't be decoded to more relocations. */
1630 bfd_size_type dt_relr_bitmap_count
= htab
->dt_relr_bitmap
.count
;
1632 /* Clear the DT_RELR bitmap count. */
1633 htab
->dt_relr_bitmap
.count
= 0;
1635 count
= relative_reloc
->count
;
1637 if (ABI_64_P (info
->output_bfd
))
1639 /* Compute the 64-bit DT_RELR bitmap. */
1643 if ((relative_reloc
->data
[i
].address
% 1) != 0)
1646 elf64_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1647 relative_reloc
->data
[i
].address
);
1649 base
= relative_reloc
->data
[i
].address
+ 8;
1654 uint64_t bitmap
= 0;
1655 for (; i
< count
; i
++)
1657 bfd_vma delta
= (relative_reloc
->data
[i
].address
1659 /* Stop if it is too far from base. */
1660 if (delta
>= 63 * 8)
1662 /* Stop if it isn't a multiple of 8. */
1663 if ((delta
% 8) != 0)
1665 bitmap
|= 1ULL << (delta
/ 8);
1671 elf64_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1678 new_count
= htab
->dt_relr_bitmap
.count
;
1679 if (dt_relr_bitmap_count
> new_count
)
1681 /* Don't shrink the DT_RELR section size to avoid section
1682 layout oscillation. Instead, pad the DT_RELR bitmap with
1683 1s which do not decode to more relocations. */
1685 htab
->dt_relr_bitmap
.count
= dt_relr_bitmap_count
;
1686 count
= dt_relr_bitmap_count
- new_count
;
1687 for (i
= 0; i
< count
; i
++)
1688 htab
->dt_relr_bitmap
.u
.elf64
[new_count
+ i
] = 1;
1693 /* Compute the 32-bit DT_RELR bitmap. */
1697 if ((relative_reloc
->data
[i
].address
% 1) != 0)
1700 elf32_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1701 relative_reloc
->data
[i
].address
);
1703 base
= relative_reloc
->data
[i
].address
+ 4;
1708 uint32_t bitmap
= 0;
1709 for (; i
< count
; i
++)
1711 bfd_vma delta
= (relative_reloc
->data
[i
].address
1713 /* Stop if it is too far from base. */
1714 if (delta
>= 31 * 4)
1716 /* Stop if it isn't a multiple of 4. */
1717 if ((delta
% 4) != 0)
1719 bitmap
|= 1ULL << (delta
/ 4);
1725 elf32_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1732 new_count
= htab
->dt_relr_bitmap
.count
;
1733 if (dt_relr_bitmap_count
> new_count
)
1735 /* Don't shrink the DT_RELR section size to avoid section
1736 layout oscillation. Instead, pad the DT_RELR bitmap with
1737 1s which do not decode to more relocations. */
1739 htab
->dt_relr_bitmap
.count
= dt_relr_bitmap_count
;
1740 count
= dt_relr_bitmap_count
- new_count
;
1741 for (i
= 0; i
< count
; i
++)
1742 htab
->dt_relr_bitmap
.u
.elf32
[new_count
+ i
] = 1;
1746 if (htab
->dt_relr_bitmap
.count
!= dt_relr_bitmap_count
)
1750 /* The .relr.dyn section size is changed. Update the section
1751 size and tell linker to layout sections again. */
1752 htab
->elf
.srelrdyn
->size
=
1753 (htab
->dt_relr_bitmap
.count
1754 * (ABI_64_P (info
->output_bfd
) ? 8 : 4));
1756 *need_layout
= true;
1759 info
->callbacks
->einfo
1760 /* xgettext:c-format */
1761 (_("%F%P: %pB: size of compact relative reloc section is "
1762 "changed: new (%lu) != old (%lu)\n"),
1763 info
->output_bfd
, htab
->dt_relr_bitmap
.count
,
1764 dt_relr_bitmap_count
);
1768 /* Write out the DT_RELR section. */
1771 elf_x86_write_dl_relr_bitmap (struct bfd_link_info
*info
,
1772 struct elf_x86_link_hash_table
*htab
)
1774 asection
*sec
= htab
->elf
.srelrdyn
;
1775 bfd_size_type size
= sec
->size
;
1777 unsigned char *contents
;
1779 contents
= (unsigned char *) bfd_alloc (sec
->owner
, size
);
1780 if (contents
== NULL
)
1781 info
->callbacks
->einfo
1782 /* xgettext:c-format */
1783 (_("%F%P: %pB: failed to allocate compact relative reloc section\n"),
1786 /* Cache the section contents for elf_link_input_bfd. */
1787 sec
->contents
= contents
;
1789 if (ABI_64_P (info
->output_bfd
))
1790 for (i
= 0; i
< htab
->dt_relr_bitmap
.count
; i
++, contents
+= 8)
1791 bfd_put_64 (info
->output_bfd
, htab
->dt_relr_bitmap
.u
.elf64
[i
],
1794 for (i
= 0; i
< htab
->dt_relr_bitmap
.count
; i
++, contents
+= 4)
1795 bfd_put_32 (info
->output_bfd
, htab
->dt_relr_bitmap
.u
.elf32
[i
],
1799 /* Sort relative relocations by address. */
1802 elf_x86_relative_reloc_compare (const void *pa
, const void *pb
)
1804 struct elf_x86_relative_reloc_record
*a
=
1805 (struct elf_x86_relative_reloc_record
*) pa
;
1806 struct elf_x86_relative_reloc_record
*b
=
1807 (struct elf_x86_relative_reloc_record
*) pb
;
1808 if (a
->address
< b
->address
)
1810 if (a
->address
> b
->address
)
1815 enum dynobj_sframe_plt_type
1821 /* Create SFrame stack trace info for the plt entries in the .plt section
1822 of type PLT_SEC_TYPE. */
1825 _bfd_x86_elf_create_sframe_plt (bfd
*output_bfd
,
1826 struct bfd_link_info
*info
,
1827 unsigned int plt_sec_type
)
1829 struct elf_x86_link_hash_table
*htab
;
1830 const struct elf_backend_data
*bed
;
1832 bool plt0_generated_p
;
1833 unsigned int plt0_entry_size
;
1834 unsigned char func_info
;
1836 /* The dynamic plt section for which .sframe stack trace information is being
1842 sframe_encoder_ctx
**ectx
= NULL
;
1843 unsigned plt_entry_size
= 0;
1844 unsigned int num_pltn_fres
= 0;
1845 unsigned int num_pltn_entries
= 0;
1847 bed
= get_elf_backend_data (output_bfd
);
1848 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1849 /* Whether SFrame stack trace info for plt0 is to be generated. */
1850 plt0_generated_p
= htab
->plt
.has_plt0
;
1852 = (plt0_generated_p
) ? htab
->sframe_plt
->plt0_entry_size
: 0;
1854 switch (plt_sec_type
)
1858 ectx
= &htab
->plt_cfe_ctx
;
1859 dpltsec
= htab
->elf
.splt
;
1861 plt_entry_size
= htab
->plt
.plt_entry_size
;
1862 num_pltn_fres
= htab
->sframe_plt
->pltn_num_fres
;
1864 = (htab
->elf
.splt
->size
- plt0_entry_size
) / plt_entry_size
;
1868 case SFRAME_PLT_SEC
:
1870 ectx
= &htab
->plt_second_cfe_ctx
;
1871 /* FIXME - this or htab->plt_second_sframe ? */
1872 dpltsec
= htab
->plt_second_eh_frame
;
1874 plt_entry_size
= htab
->sframe_plt
->sec_pltn_entry_size
;
1875 num_pltn_fres
= htab
->sframe_plt
->sec_pltn_num_fres
;
1877 = htab
->plt_second_eh_frame
->size
/ plt_entry_size
;
1881 /* No other value is possible. */
1886 *ectx
= sframe_encode (SFRAME_VERSION_2
,
1888 SFRAME_ABI_AMD64_ENDIAN_LITTLE
,
1889 SFRAME_CFA_FIXED_FP_INVALID
,
1890 -8, /* Fixed RA offset. */
1893 /* FRE type is dependent on the size of the function. */
1894 fre_type
= sframe_calc_fre_type (dpltsec
->size
);
1895 func_info
= sframe_fde_create_func_info (fre_type
, SFRAME_FDE_TYPE_PCINC
);
1897 /* Add SFrame FDE and the associated FREs for plt0 if plt0 has been
1899 if (plt0_generated_p
)
1901 /* Add SFrame FDE for plt0, the function start address is updated later
1902 at _bfd_elf_merge_section_sframe time. */
1903 sframe_encoder_add_funcdesc_v2 (*ectx
,
1904 0, /* func start addr. */
1909 sframe_frame_row_entry plt0_fre
;
1910 unsigned int num_plt0_fres
= htab
->sframe_plt
->plt0_num_fres
;
1911 for (unsigned int j
= 0; j
< num_plt0_fres
; j
++)
1913 plt0_fre
= *(htab
->sframe_plt
->plt0_fres
[j
]);
1914 sframe_encoder_add_fre (*ectx
, 0, &plt0_fre
);
1919 if (num_pltn_entries
)
1921 /* pltn entries use an SFrame FDE of type
1922 SFRAME_FDE_TYPE_PCMASK to exploit the repetitive
1923 pattern of the instructions in these entries. Using this SFrame FDE
1924 type helps in keeping the SFrame stack trace info for pltn entries
1926 func_info
= sframe_fde_create_func_info (fre_type
,
1927 SFRAME_FDE_TYPE_PCMASK
);
1928 /* Add the SFrame FDE for all PCs starting at the first pltn entry (hence,
1929 function start address = plt0_entry_size. As usual, this will be
1930 updated later at _bfd_elf_merge_section_sframe, by when the
1931 sections are relocated. */
1932 sframe_encoder_add_funcdesc_v2 (*ectx
,
1933 plt0_entry_size
, /* func start addr. */
1934 dpltsec
->size
- plt0_entry_size
,
1939 sframe_frame_row_entry pltn_fre
;
1940 /* Now add the FREs for pltn. Simply adding the two FREs suffices due
1941 to the usage of SFRAME_FDE_TYPE_PCMASK above. */
1942 for (unsigned int j
= 0; j
< num_pltn_fres
; j
++)
1944 pltn_fre
= *(htab
->sframe_plt
->pltn_fres
[j
]);
1945 sframe_encoder_add_fre (*ectx
, 1, &pltn_fre
);
1952 /* Put contents of the .sframe section corresponding to the specified
1956 _bfd_x86_elf_write_sframe_plt (bfd
*output_bfd
,
1957 struct bfd_link_info
*info
,
1958 unsigned int plt_sec_type
)
1960 struct elf_x86_link_hash_table
*htab
;
1961 const struct elf_backend_data
*bed
;
1962 sframe_encoder_ctx
*ectx
;
1969 bed
= get_elf_backend_data (output_bfd
);
1970 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1971 dynobj
= htab
->elf
.dynobj
;
1973 switch (plt_sec_type
)
1976 ectx
= htab
->plt_cfe_ctx
;
1977 sec
= htab
->plt_sframe
;
1979 case SFRAME_PLT_SEC
:
1980 ectx
= htab
->plt_second_cfe_ctx
;
1981 sec
= htab
->plt_second_sframe
;
1984 /* No other value is possible. */
1991 void *contents
= sframe_encoder_write (ectx
, &sec_size
, &err
);
1993 sec
->size
= (bfd_size_type
) sec_size
;
1994 sec
->contents
= (unsigned char *) bfd_zalloc (dynobj
, sec
->size
);
1995 memcpy (sec
->contents
, contents
, sec_size
);
1997 sframe_encoder_free (&ectx
);
2003 _bfd_elf_x86_size_relative_relocs (struct bfd_link_info
*info
,
2006 struct elf_x86_link_hash_table
*htab
;
2007 const struct elf_backend_data
*bed
;
2009 bfd_size_type i
, count
, unaligned_count
;
2010 asection
*sec
, *srel
;
2012 /* Do nothing for ld -r. */
2013 if (bfd_link_relocatable (info
))
2016 bed
= get_elf_backend_data (info
->output_bfd
);
2017 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2021 count
= htab
->relative_reloc
.count
;
2022 unaligned_count
= htab
->unaligned_relative_reloc
.count
;
2025 if (htab
->generate_relative_reloc_pass
== 0
2026 && htab
->elf
.srelrdyn
!= NULL
)
2028 /* Remove the empty .relr.dyn sections now. */
2029 if (!bfd_is_abs_section (htab
->elf
.srelrdyn
->output_section
))
2031 bfd_section_list_remove
2032 (info
->output_bfd
, htab
->elf
.srelrdyn
->output_section
);
2033 info
->output_bfd
->section_count
--;
2035 bfd_section_list_remove (htab
->elf
.srelrdyn
->owner
,
2036 htab
->elf
.srelrdyn
);
2037 htab
->elf
.srelrdyn
->owner
->section_count
--;
2039 if (unaligned_count
== 0)
2041 htab
->generate_relative_reloc_pass
++;
2046 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
2048 /* Size relative relocations. */
2049 if (htab
->generate_relative_reloc_pass
)
2051 /* Reset the regular relative relocation count. */
2052 for (i
= 0; i
< unaligned_count
; i
++)
2054 sec
= htab
->unaligned_relative_reloc
.data
[i
].sec
;
2055 srel
= elf_section_data (sec
)->sreloc
;
2056 srel
->reloc_count
= 0;
2061 /* Remove the reserved space for compact relative relocations. */
2064 asection
*sgot
= htab
->elf
.sgot
;
2065 asection
*srelgot
= htab
->elf
.srelgot
;
2067 for (i
= 0; i
< count
; i
++)
2069 sec
= htab
->relative_reloc
.data
[i
].sec
;
2073 srel
= elf_section_data (sec
)->sreloc
;
2074 srel
->size
-= htab
->sizeof_reloc
;
2079 /* Size unaligned relative relocations. */
2080 if (unaligned_count
)
2081 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2086 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2089 /* Sort relative relocations by addresses. We only need to
2090 sort them in the first pass since the relative positions
2092 if (htab
->generate_relative_reloc_pass
== 0)
2093 qsort (htab
->relative_reloc
.data
, count
,
2094 sizeof (struct elf_x86_relative_reloc_record
),
2095 elf_x86_relative_reloc_compare
);
2097 elf_x86_compute_dl_relr_bitmap (info
, htab
, need_layout
);
2100 htab
->generate_relative_reloc_pass
++;
2106 _bfd_elf_x86_finish_relative_relocs (struct bfd_link_info
*info
)
2108 struct elf_x86_link_hash_table
*htab
;
2109 const struct elf_backend_data
*bed
;
2110 Elf_Internal_Rela outrel
;
2112 bfd_size_type count
;
2114 /* Do nothing for ld -r. */
2115 if (bfd_link_relocatable (info
))
2118 bed
= get_elf_backend_data (info
->output_bfd
);
2119 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2123 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
2125 outrel
.r_info
= htab
->r_info (0, htab
->relative_r_type
);
2127 if (htab
->unaligned_relative_reloc
.count
)
2128 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2131 count
= htab
->relative_reloc
.count
;
2134 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2137 elf_x86_compute_dl_relr_bitmap (info
, htab
, NULL
);
2139 elf_x86_write_dl_relr_bitmap (info
, htab
);
2146 _bfd_elf_x86_valid_reloc_p (asection
*input_section
,
2147 struct bfd_link_info
*info
,
2148 struct elf_x86_link_hash_table
*htab
,
2149 const Elf_Internal_Rela
*rel
,
2150 struct elf_link_hash_entry
*h
,
2151 Elf_Internal_Sym
*sym
,
2152 Elf_Internal_Shdr
*symtab_hdr
,
2153 bool *no_dynreloc_p
)
2155 bool valid_p
= true;
2157 *no_dynreloc_p
= false;
2159 /* Check If relocation against non-preemptible absolute symbol is
2160 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
2161 it may call _bfd_elf_link_hide_sym_by_version and result in
2162 ld-elfvers/ vers21 test failure. */
2163 if (bfd_link_pic (info
)
2164 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
2166 const struct elf_backend_data
*bed
;
2167 unsigned int r_type
;
2168 Elf_Internal_Rela irel
;
2170 /* Skip non-absolute symbol. */
2173 if (!ABS_SYMBOL_P (h
))
2176 else if (sym
->st_shndx
!= SHN_ABS
)
2179 bed
= get_elf_backend_data (input_section
->owner
);
2180 r_type
= ELF32_R_TYPE (rel
->r_info
);
2183 /* Only allow relocations against absolute symbol, which can be
2184 resolved as absolute value + addend. GOTPCREL and GOT32
2185 relocations are allowed since absolute value + addend is
2186 stored in the GOT slot. */
2187 if (bed
->target_id
== X86_64_ELF_DATA
)
2189 r_type
&= ~R_X86_64_converted_reloc_bit
;
2190 valid_p
= (r_type
== R_X86_64_64
2191 || r_type
== R_X86_64_32
2192 || r_type
== R_X86_64_32S
2193 || r_type
== R_X86_64_16
2194 || r_type
== R_X86_64_8
2195 || r_type
== R_X86_64_GOTPCREL
2196 || r_type
== R_X86_64_GOTPCRELX
2197 || r_type
== R_X86_64_REX_GOTPCRELX
);
2200 unsigned int r_symndx
= htab
->r_sym (rel
->r_info
);
2201 irel
.r_info
= htab
->r_info (r_symndx
, r_type
);
2205 valid_p
= (r_type
== R_386_32
2206 || r_type
== R_386_16
2207 || r_type
== R_386_8
2208 || r_type
== R_386_GOT32
2209 || r_type
== R_386_GOT32X
);
2212 *no_dynreloc_p
= true;
2216 arelent internal_reloc
;
2218 if (!bed
->elf_info_to_howto (input_section
->owner
,
2219 &internal_reloc
, &irel
)
2220 || internal_reloc
.howto
== NULL
)
2224 name
= h
->root
.root
.string
;
2226 name
= bfd_elf_sym_name (input_section
->owner
, symtab_hdr
,
2228 info
->callbacks
->einfo
2229 /* xgettext:c-format */
2230 (_("%F%P: %pB: relocation %s against absolute symbol "
2231 "`%s' in section `%pA' is disallowed\n"),
2232 input_section
->owner
, internal_reloc
.howto
->name
, name
,
2234 bfd_set_error (bfd_error_bad_value
);
2241 /* Set the sizes of the dynamic sections. */
2244 _bfd_x86_elf_size_dynamic_sections (bfd
*output_bfd
,
2245 struct bfd_link_info
*info
)
2247 struct elf_x86_link_hash_table
*htab
;
2252 const struct elf_backend_data
*bed
2253 = get_elf_backend_data (output_bfd
);
2255 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2258 dynobj
= htab
->elf
.dynobj
;
2262 /* Set up .got offsets for local syms, and space for local dynamic
2264 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2266 bfd_signed_vma
*local_got
;
2267 bfd_signed_vma
*end_local_got
;
2268 char *local_tls_type
;
2269 bfd_vma
*local_tlsdesc_gotent
;
2270 bfd_size_type locsymcount
;
2271 Elf_Internal_Shdr
*symtab_hdr
;
2274 if (! is_x86_elf (ibfd
, htab
))
2277 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2279 struct elf_dyn_relocs
*p
;
2281 for (p
= ((struct elf_dyn_relocs
*)
2282 elf_section_data (s
)->local_dynrel
);
2286 if (!bfd_is_abs_section (p
->sec
)
2287 && bfd_is_abs_section (p
->sec
->output_section
))
2289 /* Input section has been discarded, either because
2290 it is a copy of a linkonce section or due to
2291 linker script /DISCARD/, so we'll be discarding
2294 else if (htab
->elf
.target_os
== is_vxworks
2295 && strcmp (p
->sec
->output_section
->name
,
2298 /* Relocations in vxworks .tls_vars sections are
2299 handled specially by the loader. */
2301 else if (p
->count
!= 0)
2303 srel
= elf_section_data (p
->sec
)->sreloc
;
2304 srel
->size
+= p
->count
* htab
->sizeof_reloc
;
2305 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2306 && (info
->flags
& DF_TEXTREL
) == 0)
2308 info
->flags
|= DF_TEXTREL
;
2309 if (bfd_link_textrel_check (info
))
2310 /* xgettext:c-format */
2311 info
->callbacks
->einfo
2312 (_("%P: %pB: warning: relocation "
2313 "in read-only section `%pA'\n"),
2314 p
->sec
->owner
, p
->sec
);
2320 local_got
= elf_local_got_refcounts (ibfd
);
2324 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2325 locsymcount
= symtab_hdr
->sh_info
;
2326 end_local_got
= local_got
+ locsymcount
;
2327 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
2328 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
2330 srel
= htab
->elf
.srelgot
;
2331 for (; local_got
< end_local_got
;
2332 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2334 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2337 if (GOT_TLS_GDESC_P (*local_tls_type
))
2339 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2340 - elf_x86_compute_jump_table_size (htab
);
2341 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
2342 *local_got
= (bfd_vma
) -2;
2344 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2345 || GOT_TLS_GD_P (*local_tls_type
))
2347 *local_got
= s
->size
;
2348 s
->size
+= htab
->got_entry_size
;
2349 if (GOT_TLS_GD_P (*local_tls_type
)
2350 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2351 s
->size
+= htab
->got_entry_size
;
2353 if ((bfd_link_pic (info
) && *local_tls_type
!= GOT_ABS
)
2354 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2355 || (*local_tls_type
& GOT_TLS_IE
))
2357 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2358 srel
->size
+= 2 * htab
->sizeof_reloc
;
2359 else if (GOT_TLS_GD_P (*local_tls_type
)
2360 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2361 srel
->size
+= htab
->sizeof_reloc
;
2362 if (GOT_TLS_GDESC_P (*local_tls_type
))
2364 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
2365 if (bed
->target_id
== X86_64_ELF_DATA
)
2366 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
2371 *local_got
= (bfd_vma
) -1;
2375 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
2377 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2378 or R_X86_64_TLSLD relocs. */
2379 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2380 htab
->elf
.sgot
->size
+= 2 * htab
->got_entry_size
;
2381 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
2384 htab
->tls_ld_or_ldm_got
.offset
= -1;
2386 /* Allocate global sym .plt and .got entries, and space for global
2387 sym dynamic relocs. */
2388 elf_link_hash_traverse (&htab
->elf
, elf_x86_allocate_dynrelocs
,
2391 /* Allocate .plt and .got entries, and space for local symbols. */
2392 htab_traverse (htab
->loc_hash_table
, elf_x86_allocate_local_dynreloc
,
2395 /* For every jump slot reserved in the sgotplt, reloc_count is
2396 incremented. However, when we reserve space for TLS descriptors,
2397 it's not incremented, so in order to compute the space reserved
2398 for them, it suffices to multiply the reloc count by the jump
2401 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2402 so that R_{386,X86_64}_IRELATIVE entries come last. */
2403 if (htab
->elf
.srelplt
)
2405 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2406 htab
->sgotplt_jump_table_size
2407 = elf_x86_compute_jump_table_size (htab
);
2408 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2410 else if (htab
->elf
.irelplt
)
2411 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2413 if (htab
->elf
.tlsdesc_plt
)
2415 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
2416 lazy TLS relocations, don't generate the PLT and GOT entries
2418 if ((info
->flags
& DF_BIND_NOW
))
2419 htab
->elf
.tlsdesc_plt
= 0;
2422 htab
->elf
.tlsdesc_got
= htab
->elf
.sgot
->size
;
2423 htab
->elf
.sgot
->size
+= htab
->got_entry_size
;
2424 /* Reserve room for the initial entry.
2425 FIXME: we could probably do away with it in this case. */
2426 if (htab
->elf
.splt
->size
== 0)
2427 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
2428 htab
->elf
.tlsdesc_plt
= htab
->elf
.splt
->size
;
2429 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
2433 if (htab
->elf
.sgotplt
)
2435 /* Don't allocate .got.plt section if there are no GOT nor PLT
2436 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2437 if ((htab
->elf
.hgot
== NULL
2438 || !htab
->got_referenced
)
2439 && (htab
->elf
.sgotplt
->size
== bed
->got_header_size
)
2440 && (htab
->elf
.splt
== NULL
2441 || htab
->elf
.splt
->size
== 0)
2442 && (htab
->elf
.sgot
== NULL
2443 || htab
->elf
.sgot
->size
== 0)
2444 && (htab
->elf
.iplt
== NULL
2445 || htab
->elf
.iplt
->size
== 0)
2446 && (htab
->elf
.igotplt
== NULL
2447 || htab
->elf
.igotplt
->size
== 0))
2449 htab
->elf
.sgotplt
->size
= 0;
2450 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
2452 if (htab
->elf
.hgot
!= NULL
2453 && htab
->elf
.target_os
!= is_solaris
)
2455 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
2457 htab
->elf
.hgot
->root
.type
= bfd_link_hash_undefined
;
2458 htab
->elf
.hgot
->root
.u
.undef
.abfd
2459 = htab
->elf
.hgot
->root
.u
.def
.section
->owner
;
2460 htab
->elf
.hgot
->root
.linker_def
= 0;
2461 htab
->elf
.hgot
->ref_regular
= 0;
2462 htab
->elf
.hgot
->def_regular
= 0;
2467 if (_bfd_elf_eh_frame_present (info
))
2469 if (htab
->plt_eh_frame
!= NULL
2470 && htab
->elf
.splt
!= NULL
2471 && htab
->elf
.splt
->size
!= 0
2472 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2473 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
2475 if (htab
->plt_got_eh_frame
!= NULL
2476 && htab
->plt_got
!= NULL
2477 && htab
->plt_got
->size
!= 0
2478 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
2479 htab
->plt_got_eh_frame
->size
2480 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2482 /* Unwind info for the second PLT and .plt.got sections are
2484 if (htab
->plt_second_eh_frame
!= NULL
2485 && htab
->plt_second
!= NULL
2486 && htab
->plt_second
->size
!= 0
2487 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2488 htab
->plt_second_eh_frame
->size
2489 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2492 /* No need to size the .sframe section explicitly because the write-out
2493 mechanism is different. Simply prep up the FDE/FRE for the
2495 if (_bfd_elf_sframe_present (info
))
2497 if (htab
->plt_sframe
!= NULL
2498 && htab
->elf
.splt
!= NULL
2499 && htab
->elf
.splt
->size
!= 0
2500 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2502 _bfd_x86_elf_create_sframe_plt (output_bfd
, info
, SFRAME_PLT
);
2503 /* FIXME - Dirty Hack. Set the size to something non-zero for now,
2504 so that the section does not get stripped out below. The precise
2505 size of this section is known only when the contents are
2506 serialized in _bfd_x86_elf_write_sframe_plt. */
2507 htab
->plt_sframe
->size
= sizeof (sframe_header
) + 1;
2510 /* FIXME - generate for .got.plt ? */
2512 /* Unwind info for the second PLT. */
2513 if (htab
->plt_second_sframe
!= NULL
2514 && htab
->plt_second
!= NULL
2515 && htab
->plt_second
->size
!= 0
2516 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2518 _bfd_x86_elf_create_sframe_plt (output_bfd
, info
,
2520 /* FIXME - Dirty Hack. Set the size to something non-zero for now,
2521 so that the section does not get stripped out below. The precise
2522 size of this section is known only when the contents are
2523 serialized in _bfd_x86_elf_write_sframe_plt. */
2524 htab
->plt_second_sframe
->size
= sizeof (sframe_header
) + 1;
2528 asection
*resolved_plt
= NULL
;
2530 if (htab
->params
->mark_plt
&& htab
->elf
.dynamic_sections_created
)
2532 if (htab
->plt_second
!= NULL
)
2533 resolved_plt
= htab
->plt_second
;
2535 resolved_plt
= htab
->elf
.splt
;
2537 if (resolved_plt
!= NULL
&& resolved_plt
->size
== 0)
2538 resolved_plt
= NULL
;
2541 /* We now have determined the sizes of the various dynamic sections.
2542 Allocate memory for them. */
2544 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2546 bool strip_section
= true;
2548 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2551 /* The .relr.dyn section for compact relative relocation will
2553 if (s
== htab
->elf
.srelrdyn
)
2556 if (s
== htab
->elf
.splt
2557 || s
== htab
->elf
.sgot
)
2559 /* Strip this section if we don't need it; see the
2561 /* We'd like to strip these sections if they aren't needed, but if
2562 we've exported dynamic symbols from them we must leave them.
2563 It's too late to tell BFD to get rid of the symbols. */
2565 if (htab
->elf
.hplt
!= NULL
)
2566 strip_section
= false;
2568 else if (s
== htab
->elf
.sgotplt
2569 || s
== htab
->elf
.iplt
2570 || s
== htab
->elf
.igotplt
2571 || s
== htab
->plt_second
2572 || s
== htab
->plt_got
2573 || s
== htab
->plt_eh_frame
2574 || s
== htab
->plt_got_eh_frame
2575 || s
== htab
->plt_second_eh_frame
2576 || s
== htab
->plt_sframe
2577 || s
== htab
->plt_second_sframe
2578 || s
== htab
->elf
.sdynbss
2579 || s
== htab
->elf
.sdynrelro
)
2581 /* Strip these too. */
2583 else if (htab
->is_reloc_section (bfd_section_name (s
)))
2586 && s
!= htab
->elf
.srelplt
2587 && s
!= htab
->srelplt2
)
2590 /* We use the reloc_count field as a counter if we need
2591 to copy relocs into the output file. */
2592 if (s
!= htab
->elf
.srelplt
)
2597 /* It's not one of our sections, so don't allocate space. */
2603 /* If we don't need this section, strip it from the
2604 output file. This is mostly to handle .rel.bss and
2605 .rel.plt. We must create both sections in
2606 create_dynamic_sections, because they must be created
2607 before the linker maps input sections to output
2608 sections. The linker does that before
2609 adjust_dynamic_symbol is called, and it is that
2610 function which decides whether anything needs to go
2611 into these sections. */
2613 s
->flags
|= SEC_EXCLUDE
;
2617 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2620 /* Skip allocating contents for .sframe section as it is written
2621 out differently. See below. */
2622 if ((s
== htab
->plt_sframe
) || (s
== htab
->plt_second_sframe
))
2625 /* NB: Initially, the iplt section has minimal alignment to
2626 avoid moving dot of the following section backwards when
2627 it is empty. Update its section alignment now since it
2629 if (s
== htab
->elf
.iplt
)
2630 bfd_set_section_alignment (s
, htab
->plt
.iplt_alignment
);
2632 /* Allocate memory for the section contents. We use bfd_zalloc
2633 here in case unused entries are not reclaimed before the
2634 section's contents are written out. This should not happen,
2635 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
2636 reloc instead of garbage. */
2637 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2638 if (s
->contents
== NULL
)
2642 if (htab
->plt_eh_frame
!= NULL
2643 && htab
->plt_eh_frame
->contents
!= NULL
)
2645 memcpy (htab
->plt_eh_frame
->contents
,
2646 htab
->plt
.eh_frame_plt
,
2647 htab
->plt_eh_frame
->size
);
2648 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2649 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2652 if (htab
->plt_got_eh_frame
!= NULL
2653 && htab
->plt_got_eh_frame
->contents
!= NULL
)
2655 memcpy (htab
->plt_got_eh_frame
->contents
,
2656 htab
->non_lazy_plt
->eh_frame_plt
,
2657 htab
->plt_got_eh_frame
->size
);
2658 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
2659 (htab
->plt_got_eh_frame
->contents
2660 + PLT_FDE_LEN_OFFSET
));
2663 if (htab
->plt_second_eh_frame
!= NULL
2664 && htab
->plt_second_eh_frame
->contents
!= NULL
)
2666 memcpy (htab
->plt_second_eh_frame
->contents
,
2667 htab
->non_lazy_plt
->eh_frame_plt
,
2668 htab
->plt_second_eh_frame
->size
);
2669 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
2670 (htab
->plt_second_eh_frame
->contents
2671 + PLT_FDE_LEN_OFFSET
));
2674 if (_bfd_elf_sframe_present (info
))
2676 if (htab
->plt_sframe
!= NULL
2677 && htab
->elf
.splt
!= NULL
2678 && htab
->elf
.splt
->size
!= 0
2679 && htab
->plt_sframe
->contents
== NULL
)
2680 _bfd_x86_elf_write_sframe_plt (output_bfd
, info
, SFRAME_PLT
);
2682 if (htab
->plt_second_sframe
!= NULL
2683 && htab
->elf
.splt
!= NULL
2684 && htab
->elf
.splt
->size
!= 0
2685 && htab
->plt_second_sframe
->contents
== NULL
)
2686 _bfd_x86_elf_write_sframe_plt (output_bfd
, info
, SFRAME_PLT_SEC
);
2689 if (resolved_plt
!= NULL
2690 && (!_bfd_elf_add_dynamic_entry (info
, DT_X86_64_PLT
, 0)
2691 || !_bfd_elf_add_dynamic_entry (info
, DT_X86_64_PLTSZ
, 0)
2692 || !_bfd_elf_add_dynamic_entry (info
, DT_X86_64_PLTENT
, 0)))
2695 return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd
, info
,
2699 /* Finish up the x86 dynamic sections. */
2701 struct elf_x86_link_hash_table
*
2702 _bfd_x86_elf_finish_dynamic_sections (bfd
*output_bfd
,
2703 struct bfd_link_info
*info
)
2705 struct elf_x86_link_hash_table
*htab
;
2706 const struct elf_backend_data
*bed
;
2709 bfd_byte
*dyncon
, *dynconend
;
2710 bfd_size_type sizeof_dyn
;
2712 bed
= get_elf_backend_data (output_bfd
);
2713 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2717 dynobj
= htab
->elf
.dynobj
;
2718 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
2720 /* GOT is always created in setup_gnu_properties. But it may not be
2721 needed. .got.plt section may be needed for static IFUNC. */
2722 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
2724 bfd_vma dynamic_addr
;
2726 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
2729 (_("discarded output section: `%pA'"), htab
->elf
.sgotplt
);
2733 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
2734 = htab
->got_entry_size
;
2736 dynamic_addr
= (sdyn
== NULL
2738 : sdyn
->output_section
->vma
+ sdyn
->output_offset
);
2740 /* Set the first entry in the global offset table to the address
2741 of the dynamic section. Write GOT[1] and GOT[2], needed for
2742 the dynamic linker. */
2743 if (htab
->got_entry_size
== 8)
2745 bfd_put_64 (output_bfd
, dynamic_addr
,
2746 htab
->elf
.sgotplt
->contents
);
2747 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2748 htab
->elf
.sgotplt
->contents
+ 8);
2749 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2750 htab
->elf
.sgotplt
->contents
+ 8*2);
2754 bfd_put_32 (output_bfd
, dynamic_addr
,
2755 htab
->elf
.sgotplt
->contents
);
2756 bfd_put_32 (output_bfd
, 0,
2757 htab
->elf
.sgotplt
->contents
+ 4);
2758 bfd_put_32 (output_bfd
, 0,
2759 htab
->elf
.sgotplt
->contents
+ 4*2);
2763 if (!htab
->elf
.dynamic_sections_created
)
2766 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
2769 asection
*resolved_plt
;
2770 if (htab
->plt_second
!= NULL
)
2771 resolved_plt
= htab
->plt_second
;
2773 resolved_plt
= htab
->elf
.splt
;
2775 sizeof_dyn
= bed
->s
->sizeof_dyn
;
2776 dyncon
= sdyn
->contents
;
2777 dynconend
= sdyn
->contents
+ sdyn
->size
;
2778 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
2780 Elf_Internal_Dyn dyn
;
2783 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
2788 if (htab
->elf
.target_os
== is_vxworks
2789 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
2794 s
= htab
->elf
.sgotplt
;
2795 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2799 s
= htab
->elf
.srelplt
;
2800 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2804 s
= htab
->elf
.srelplt
;
2805 dyn
.d_un
.d_val
= s
->size
;
2808 case DT_TLSDESC_PLT
:
2810 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
2811 + htab
->elf
.tlsdesc_plt
;
2814 case DT_TLSDESC_GOT
:
2816 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
2817 + htab
->elf
.tlsdesc_got
;
2821 s
= resolved_plt
->output_section
;
2822 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2825 case DT_X86_64_PLTSZ
:
2826 dyn
.d_un
.d_val
= resolved_plt
->size
;
2829 case DT_X86_64_PLTENT
:
2830 dyn
.d_un
.d_ptr
= htab
->plt
.plt_entry_size
;
2834 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
2837 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
2838 elf_section_data (htab
->plt_got
->output_section
)
2839 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
2841 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
2842 elf_section_data (htab
->plt_second
->output_section
)
2843 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
2845 /* Adjust .eh_frame for .plt section. */
2846 if (htab
->plt_eh_frame
!= NULL
2847 && htab
->plt_eh_frame
->contents
!= NULL
)
2849 if (htab
->elf
.splt
!= NULL
2850 && htab
->elf
.splt
->size
!= 0
2851 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
2852 && htab
->elf
.splt
->output_section
!= NULL
2853 && htab
->plt_eh_frame
->output_section
!= NULL
)
2855 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
2856 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
2857 + htab
->plt_eh_frame
->output_offset
2858 + PLT_FDE_START_OFFSET
;
2859 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2860 htab
->plt_eh_frame
->contents
2861 + PLT_FDE_START_OFFSET
);
2864 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
2866 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2868 htab
->plt_eh_frame
->contents
))
2873 /* Adjust .eh_frame for .plt.got section. */
2874 if (htab
->plt_got_eh_frame
!= NULL
2875 && htab
->plt_got_eh_frame
->contents
!= NULL
)
2877 if (htab
->plt_got
!= NULL
2878 && htab
->plt_got
->size
!= 0
2879 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
2880 && htab
->plt_got
->output_section
!= NULL
2881 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
2883 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
2884 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
2885 + htab
->plt_got_eh_frame
->output_offset
2886 + PLT_FDE_START_OFFSET
;
2887 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2888 htab
->plt_got_eh_frame
->contents
2889 + PLT_FDE_START_OFFSET
);
2891 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
2893 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2894 htab
->plt_got_eh_frame
,
2895 htab
->plt_got_eh_frame
->contents
))
2900 /* Adjust .eh_frame for the second PLT section. */
2901 if (htab
->plt_second_eh_frame
!= NULL
2902 && htab
->plt_second_eh_frame
->contents
!= NULL
)
2904 if (htab
->plt_second
!= NULL
2905 && htab
->plt_second
->size
!= 0
2906 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
2907 && htab
->plt_second
->output_section
!= NULL
2908 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
2910 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
2911 bfd_vma eh_frame_start
2912 = (htab
->plt_second_eh_frame
->output_section
->vma
2913 + htab
->plt_second_eh_frame
->output_offset
2914 + PLT_FDE_START_OFFSET
);
2915 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2916 htab
->plt_second_eh_frame
->contents
2917 + PLT_FDE_START_OFFSET
);
2919 if (htab
->plt_second_eh_frame
->sec_info_type
2920 == SEC_INFO_TYPE_EH_FRAME
)
2922 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2923 htab
->plt_second_eh_frame
,
2924 htab
->plt_second_eh_frame
->contents
))
2929 /* Make any adjustment if necessary and merge .sframe section to
2930 create the final .sframe section for output_bfd. */
2931 if (htab
->plt_sframe
!= NULL
2932 && htab
->plt_sframe
->contents
!= NULL
)
2934 if (htab
->elf
.splt
!= NULL
2935 && htab
->elf
.splt
->size
!= 0
2936 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
2937 && htab
->elf
.splt
->output_section
!= NULL
2938 && htab
->plt_sframe
->output_section
!= NULL
)
2940 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
2941 bfd_vma sframe_start
= htab
->plt_sframe
->output_section
->vma
2942 + htab
->plt_sframe
->output_offset
2943 + PLT_SFRAME_FDE_START_OFFSET
;
2944 #if 0 /* FIXME Testing only. Remove before review. */
2945 bfd_vma test_value
= (plt_start
- sframe_start
)
2946 + htab
->plt_sframe
->output_section
->vma
2947 + htab
->plt_sframe
->output_offset
2948 + PLT_SFRAME_FDE_START_OFFSET
;
2949 bfd_put_signed_32 (dynobj
, test_value
,
2951 bfd_put_signed_32 (dynobj
, plt_start
- sframe_start
,
2952 htab
->plt_sframe
->contents
2953 + PLT_SFRAME_FDE_START_OFFSET
);
2955 if (htab
->plt_sframe
->sec_info_type
== SEC_INFO_TYPE_SFRAME
)
2957 if (! _bfd_elf_merge_section_sframe (output_bfd
, info
,
2959 htab
->plt_sframe
->contents
))
2964 if (htab
->plt_second_sframe
!= NULL
2965 && htab
->plt_second_sframe
->contents
!= NULL
)
2967 if (htab
->plt_second
!= NULL
2968 && htab
->plt_second
->size
!= 0
2969 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
2970 && htab
->plt_second
->output_section
!= NULL
2971 && htab
->plt_second_sframe
->output_section
!= NULL
)
2973 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
2974 bfd_vma sframe_start
2975 = (htab
->plt_second_sframe
->output_section
->vma
2976 + htab
->plt_second_sframe
->output_offset
2977 + PLT_SFRAME_FDE_START_OFFSET
);
2978 #if 0 /* FIXME Testing only. Remove before review. */
2979 bfd_vma test_value
= (plt_start
- sframe_start
)
2980 + htab
->plt_second_sframe
->output_section
->vma
2981 + htab
->plt_second_sframe
->output_offset
2982 + PLT_SFRAME_FDE_START_OFFSET
;
2983 bfd_put_signed_32 (dynobj
, test_value
,
2985 bfd_put_signed_32 (dynobj
, plt_start
- sframe_start
,
2986 htab
->plt_second_sframe
->contents
2987 + PLT_SFRAME_FDE_START_OFFSET
);
2989 if (htab
->plt_second_sframe
->sec_info_type
== SEC_INFO_TYPE_SFRAME
)
2991 if (! _bfd_elf_merge_section_sframe (output_bfd
, info
,
2992 htab
->plt_second_sframe
,
2993 htab
->plt_second_sframe
->contents
))
2997 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
2998 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
2999 = htab
->got_entry_size
;
3006 _bfd_x86_elf_always_size_sections (bfd
*output_bfd
,
3007 struct bfd_link_info
*info
)
3009 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
3011 if (tls_sec
&& !bfd_link_relocatable (info
))
3013 struct elf_link_hash_entry
*tlsbase
;
3015 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
3016 "_TLS_MODULE_BASE_",
3017 false, false, false);
3019 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
3021 struct elf_x86_link_hash_table
*htab
;
3022 struct bfd_link_hash_entry
*bh
= NULL
;
3023 const struct elf_backend_data
*bed
3024 = get_elf_backend_data (output_bfd
);
3026 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3030 if (!(_bfd_generic_link_add_one_symbol
3031 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
3032 tls_sec
, 0, NULL
, false,
3033 bed
->collect
, &bh
)))
3036 htab
->tls_module_base
= bh
;
3038 tlsbase
= (struct elf_link_hash_entry
*)bh
;
3039 tlsbase
->def_regular
= 1;
3040 tlsbase
->other
= STV_HIDDEN
;
3041 tlsbase
->root
.linker_def
= 1;
3042 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, true);
3050 _bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
3051 unsigned int st_other
,
3053 bool dynamic ATTRIBUTE_UNUSED
)
3057 struct elf_x86_link_hash_entry
*eh
3058 = (struct elf_x86_link_hash_entry
*) h
;
3059 eh
->def_protected
= ELF_ST_VISIBILITY (st_other
) == STV_PROTECTED
;
3063 /* Copy the extra info we tack onto an elf_link_hash_entry. */
3066 _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
3067 struct elf_link_hash_entry
*dir
,
3068 struct elf_link_hash_entry
*ind
)
3070 struct elf_x86_link_hash_entry
*edir
, *eind
;
3072 edir
= (struct elf_x86_link_hash_entry
*) dir
;
3073 eind
= (struct elf_x86_link_hash_entry
*) ind
;
3075 if (ind
->root
.type
== bfd_link_hash_indirect
3076 && dir
->got
.refcount
<= 0)
3078 edir
->tls_type
= eind
->tls_type
;
3079 eind
->tls_type
= GOT_UNKNOWN
;
3082 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
3083 generate a R_386_COPY reloc. */
3084 edir
->gotoff_ref
|= eind
->gotoff_ref
;
3086 edir
->zero_undefweak
|= eind
->zero_undefweak
;
3088 if (ELIMINATE_COPY_RELOCS
3089 && ind
->root
.type
!= bfd_link_hash_indirect
3090 && dir
->dynamic_adjusted
)
3092 /* If called to transfer flags for a weakdef during processing
3093 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3094 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3095 if (dir
->versioned
!= versioned_hidden
)
3096 dir
->ref_dynamic
|= ind
->ref_dynamic
;
3097 dir
->ref_regular
|= ind
->ref_regular
;
3098 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
3099 dir
->needs_plt
|= ind
->needs_plt
;
3100 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
3103 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3106 /* Remove undefined weak symbol from the dynamic symbol table if it
3107 is resolved to 0. */
3110 _bfd_x86_elf_fixup_symbol (struct bfd_link_info
*info
,
3111 struct elf_link_hash_entry
*h
)
3113 if (h
->dynindx
!= -1
3114 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, elf_x86_hash_entry (h
)))
3117 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3123 /* Change the STT_GNU_IFUNC symbol defined in position-dependent
3124 executable into the normal function symbol and set its address
3125 to its PLT entry, which should be resolved by R_*_IRELATIVE at
3129 _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info
*info
,
3130 struct elf_x86_link_hash_table
*htab
,
3131 struct elf_link_hash_entry
*h
,
3132 Elf_Internal_Sym
*sym
)
3134 if (bfd_link_pde (info
)
3137 && h
->plt
.offset
!= (bfd_vma
) -1
3138 && h
->type
== STT_GNU_IFUNC
)
3142 bfd
*output_bfd
= info
->output_bfd
;
3144 if (htab
->plt_second
)
3146 struct elf_x86_link_hash_entry
*eh
3147 = (struct elf_x86_link_hash_entry
*) h
;
3149 plt_s
= htab
->plt_second
;
3150 plt_offset
= eh
->plt_second
.offset
;
3154 plt_s
= htab
->elf
.splt
;
3155 plt_offset
= h
->plt
.offset
;
3159 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
3161 = _bfd_elf_section_from_bfd_section (output_bfd
,
3162 plt_s
->output_section
);
3163 sym
->st_value
= (plt_s
->output_section
->vma
3164 + plt_s
->output_offset
+ plt_offset
);
3168 /* Report relative relocation. */
3171 _bfd_x86_elf_link_report_relative_reloc
3172 (struct bfd_link_info
*info
, asection
*asect
,
3173 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
,
3174 const char *reloc_name
, const void *reloc
)
3178 const Elf_Internal_Rela
*rel
= (const Elf_Internal_Rela
*) reloc
;
3180 /* Use the output BFD for linker created sections. */
3181 if ((asect
->flags
& SEC_LINKER_CREATED
) != 0)
3182 abfd
= info
->output_bfd
;
3184 abfd
= asect
->owner
;
3186 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
3187 name
= h
->root
.root
.string
;
3189 name
= bfd_elf_sym_name (abfd
, &elf_symtab_hdr (abfd
), sym
, NULL
);
3191 if (asect
->use_rela_p
)
3192 info
->callbacks
->einfo
3193 (_("%pB: %s (offset: 0x%v, info: 0x%v, addend: 0x%v) against "
3194 "'%s' " "for section '%pA' in %pB\n"),
3195 info
->output_bfd
, reloc_name
, rel
->r_offset
, rel
->r_info
,
3196 rel
->r_addend
, name
, asect
, abfd
);
3198 info
->callbacks
->einfo
3199 (_("%pB: %s (offset: 0x%v, info: 0x%v) against '%s' for section "
3201 info
->output_bfd
, reloc_name
, rel
->r_offset
, rel
->r_info
, name
,
3205 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3208 _bfd_x86_elf_hash_symbol (struct elf_link_hash_entry
*h
)
3210 if (h
->plt
.offset
!= (bfd_vma
) -1
3212 && !h
->pointer_equality_needed
)
3215 return _bfd_elf_hash_symbol (h
);
3218 /* Adjust a symbol defined by a dynamic object and referenced by a
3219 regular object. The current definition is in some section of the
3220 dynamic object, but we're not including those sections. We have to
3221 change the definition to something the rest of the link can
3225 _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3226 struct elf_link_hash_entry
*h
)
3228 struct elf_x86_link_hash_table
*htab
;
3230 struct elf_x86_link_hash_entry
*eh
;
3231 struct elf_dyn_relocs
*p
;
3232 const struct elf_backend_data
*bed
3233 = get_elf_backend_data (info
->output_bfd
);
3235 eh
= (struct elf_x86_link_hash_entry
*) h
;
3237 /* Clear GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS if it is turned
3238 on by an input relocatable file and there is a non-GOT/non-PLT
3239 reference from another relocatable file without it.
3240 NB: There can be non-GOT reference in data sections in input with
3241 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS. */
3242 if (eh
->non_got_ref_without_indirect_extern_access
3243 && info
->indirect_extern_access
== 1
3244 && bfd_link_executable (info
))
3246 unsigned int needed_1
;
3247 info
->indirect_extern_access
= 0;
3248 /* Turn off nocopyreloc if implied by indirect_extern_access. */
3249 if (info
->nocopyreloc
== 2)
3250 info
->nocopyreloc
= 0;
3251 needed_1
= bfd_h_get_32 (info
->output_bfd
, info
->needed_1_p
);
3252 needed_1
&= ~GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
;
3253 bfd_h_put_32 (info
->output_bfd
, needed_1
, info
->needed_1_p
);
3256 /* STT_GNU_IFUNC symbol must go through PLT. */
3257 if (h
->type
== STT_GNU_IFUNC
)
3259 /* All local STT_GNU_IFUNC references must be treate as local
3260 calls via local PLT. */
3262 && SYMBOL_CALLS_LOCAL (info
, h
))
3264 bfd_size_type pc_count
= 0, count
= 0;
3265 struct elf_dyn_relocs
**pp
;
3267 eh
= (struct elf_x86_link_hash_entry
*) h
;
3268 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
3270 pc_count
+= p
->pc_count
;
3271 p
->count
-= p
->pc_count
;
3280 if (pc_count
|| count
)
3285 /* Increment PLT reference count only for PC-relative
3288 if (h
->plt
.refcount
<= 0)
3289 h
->plt
.refcount
= 1;
3291 h
->plt
.refcount
+= 1;
3295 /* GOTOFF relocation needs PLT. */
3297 h
->plt
.refcount
= 1;
3300 if (h
->plt
.refcount
<= 0)
3302 h
->plt
.offset
= (bfd_vma
) -1;
3308 /* If this is a function, put it in the procedure linkage table. We
3309 will fill in the contents of the procedure linkage table later,
3310 when we know the address of the .got section. */
3311 if (h
->type
== STT_FUNC
3314 if (h
->plt
.refcount
<= 0
3315 || SYMBOL_CALLS_LOCAL (info
, h
)
3316 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3317 && h
->root
.type
== bfd_link_hash_undefweak
))
3319 /* This case can occur if we saw a PLT32 reloc in an input
3320 file, but the symbol was never referred to by a dynamic
3321 object, or if all references were garbage collected. In
3322 such a case, we don't actually need to build a procedure
3323 linkage table, and we can just do a PC32 reloc instead. */
3324 h
->plt
.offset
= (bfd_vma
) -1;
3331 /* It's possible that we incorrectly decided a .plt reloc was needed
3332 * for an R_386_PC32/R_X86_64_PC32 reloc to a non-function sym in
3333 check_relocs. We can't decide accurately between function and
3334 non-function syms in check-relocs; Objects loaded later in
3335 the link may change h->type. So fix it now. */
3336 h
->plt
.offset
= (bfd_vma
) -1;
3338 /* If this is a weak symbol, and there is a real definition, the
3339 processor independent code will have arranged for us to see the
3340 real definition first, and we can just use the same value. */
3341 if (h
->is_weakalias
)
3343 struct elf_link_hash_entry
*def
= weakdef (h
);
3344 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3345 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3346 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3347 if (ELIMINATE_COPY_RELOCS
3348 || info
->nocopyreloc
3349 || SYMBOL_NO_COPYRELOC (info
, eh
))
3351 /* NB: needs_copy is always 0 for i386. */
3352 h
->non_got_ref
= def
->non_got_ref
;
3353 eh
->needs_copy
= def
->needs_copy
;
3358 /* This is a reference to a symbol defined by a dynamic object which
3359 is not a function. */
3361 /* If we are creating a shared library, we must presume that the
3362 only references to the symbol are via the global offset table.
3363 For such cases we need not do anything here; the relocations will
3364 be handled correctly by relocate_section. */
3365 if (!bfd_link_executable (info
))
3368 /* If there are no references to this symbol that do not use the
3369 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
3370 reloc. NB: gotoff_ref is always 0 for x86-64. */
3371 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
3374 /* If -z nocopyreloc was given, we won't generate them either. */
3375 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
3381 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3385 /* If there aren't any dynamic relocs in read-only sections nor
3386 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
3387 avoid the copy reloc. This doesn't work on VxWorks, where we can
3388 not have dynamic relocations (other than copy and jump slot
3389 relocations) in an executable. */
3390 if (ELIMINATE_COPY_RELOCS
3391 && (bed
->target_id
== X86_64_ELF_DATA
3393 && htab
->elf
.target_os
!= is_vxworks
)))
3395 /* If we don't find any dynamic relocs in read-only sections,
3396 then we'll be keeping the dynamic relocs and avoiding the copy
3398 if (!_bfd_elf_readonly_dynrelocs (h
))
3405 /* We must allocate the symbol in our .dynbss section, which will
3406 become part of the .bss section of the executable. There will be
3407 an entry for this symbol in the .dynsym section. The dynamic
3408 object will contain position independent code, so all references
3409 from the dynamic object to this symbol will go through the global
3410 offset table. The dynamic linker will use the .dynsym entry to
3411 determine the address it must put in the global offset table, so
3412 both the dynamic object and the regular object will refer to the
3413 same memory location for the variable. */
3415 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
3416 dynamic linker to copy the initial value out of the dynamic object
3417 and into the runtime process image. */
3418 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3420 s
= htab
->elf
.sdynrelro
;
3421 srel
= htab
->elf
.sreldynrelro
;
3425 s
= htab
->elf
.sdynbss
;
3426 srel
= htab
->elf
.srelbss
;
3428 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3430 if (eh
->def_protected
&& bfd_link_executable (info
))
3431 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3433 /* Disallow copy relocation against non-copyable protected
3435 s
= p
->sec
->output_section
;
3436 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3438 info
->callbacks
->einfo
3439 /* xgettext:c-format */
3440 (_("%F%P: %pB: copy relocation against non-copyable "
3441 "protected symbol `%s' in %pB\n"),
3442 p
->sec
->owner
, h
->root
.root
.string
,
3443 h
->root
.u
.def
.section
->owner
);
3448 srel
->size
+= htab
->sizeof_reloc
;
3452 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3456 _bfd_x86_elf_hide_symbol (struct bfd_link_info
*info
,
3457 struct elf_link_hash_entry
*h
,
3460 if (h
->root
.type
== bfd_link_hash_undefweak
3462 && bfd_link_pie (info
))
3464 /* When there is no dynamic interpreter in PIE, make the undefined
3465 weak symbol dynamic so that PC relative branch to the undefined
3466 weak symbol will land to address 0. */
3467 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
3468 if (h
->plt
.refcount
> 0
3469 || eh
->plt_got
.refcount
> 0)
3473 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3476 /* Return TRUE if a symbol is referenced locally. It is similar to
3477 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
3478 works in check_relocs. */
3481 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info
*info
,
3482 struct elf_link_hash_entry
*h
)
3484 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
3485 struct elf_x86_link_hash_table
*htab
3486 = (struct elf_x86_link_hash_table
*) info
->hash
;
3488 if (eh
->local_ref
> 1)
3491 if (eh
->local_ref
== 1)
3494 /* Unversioned symbols defined in regular objects can be forced local
3495 by linker version script. A weak undefined symbol is forced local
3497 1. It has non-default visibility. Or
3498 2. When building executable, there is no dynamic linker. Or
3499 3. or "-z nodynamic-undefined-weak" is used.
3501 if (_bfd_elf_symbol_refs_local_p (h
, info
, 1)
3502 || (h
->root
.type
== bfd_link_hash_undefweak
3503 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3504 || (bfd_link_executable (info
)
3505 && htab
->interp
== NULL
)
3506 || info
->dynamic_undefined_weak
== 0))
3507 || ((h
->def_regular
|| ELF_COMMON_DEF_P (h
))
3508 && info
->version_info
!= NULL
3509 && _bfd_elf_link_hide_sym_by_version (info
, h
)))
3519 /* Return the section that should be marked against GC for a given
3523 _bfd_x86_elf_gc_mark_hook (asection
*sec
,
3524 struct bfd_link_info
*info
,
3525 Elf_Internal_Rela
*rel
,
3526 struct elf_link_hash_entry
*h
,
3527 Elf_Internal_Sym
*sym
)
3529 /* Compiler should optimize this out. */
3530 if (((unsigned int) R_X86_64_GNU_VTINHERIT
3531 != (unsigned int) R_386_GNU_VTINHERIT
)
3532 || ((unsigned int) R_X86_64_GNU_VTENTRY
3533 != (unsigned int) R_386_GNU_VTENTRY
))
3537 switch (ELF32_R_TYPE (rel
->r_info
))
3539 case R_X86_64_GNU_VTINHERIT
:
3540 case R_X86_64_GNU_VTENTRY
:
3544 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
3548 elf_i386_get_plt_got_vma (struct elf_x86_plt
*plt_p ATTRIBUTE_UNUSED
,
3550 bfd_vma offset ATTRIBUTE_UNUSED
,
3553 return got_addr
+ off
;
3557 elf_x86_64_get_plt_got_vma (struct elf_x86_plt
*plt_p
,
3560 bfd_vma got_addr ATTRIBUTE_UNUSED
)
3562 return plt_p
->sec
->vma
+ offset
+ off
+ plt_p
->plt_got_insn_size
;
3566 elf_i386_valid_plt_reloc_p (unsigned int type
)
3568 return (type
== R_386_JUMP_SLOT
3569 || type
== R_386_GLOB_DAT
3570 || type
== R_386_IRELATIVE
);
3574 elf_x86_64_valid_plt_reloc_p (unsigned int type
)
3576 return (type
== R_X86_64_JUMP_SLOT
3577 || type
== R_X86_64_GLOB_DAT
3578 || type
== R_X86_64_IRELATIVE
);
3582 _bfd_x86_elf_get_synthetic_symtab (bfd
*abfd
,
3586 struct elf_x86_plt plts
[],
3590 long size
, i
, n
, len
;
3592 unsigned int plt_got_offset
, plt_entry_size
;
3594 bfd_byte
*plt_contents
;
3596 arelent
**dynrelbuf
, *p
;
3598 const struct elf_backend_data
*bed
;
3599 bfd_vma (*get_plt_got_vma
) (struct elf_x86_plt
*, bfd_vma
, bfd_vma
,
3601 bool (*valid_plt_reloc_p
) (unsigned int);
3602 unsigned int jump_slot_reloc
;
3608 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
3609 if (dynrelbuf
== NULL
)
3612 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
3614 if (dynrelcount
<= 0)
3617 /* Sort the relocs by address. */
3618 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
3619 _bfd_x86_elf_compare_relocs
);
3621 size
= count
* sizeof (asymbol
);
3623 /* Allocate space for @plt suffixes. */
3625 for (i
= 0; i
< dynrelcount
; i
++)
3628 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3630 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
3633 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
3637 bed
= get_elf_backend_data (abfd
);
3639 if (bed
->target_id
== X86_64_ELF_DATA
)
3641 get_plt_got_vma
= elf_x86_64_get_plt_got_vma
;
3642 valid_plt_reloc_p
= elf_x86_64_valid_plt_reloc_p
;
3643 jump_slot_reloc
= R_X86_64_JUMP_SLOT
;
3647 get_plt_got_vma
= elf_i386_get_plt_got_vma
;
3648 valid_plt_reloc_p
= elf_i386_valid_plt_reloc_p
;
3649 jump_slot_reloc
= R_386_JUMP_SLOT
;
3652 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
3654 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
3656 got_addr
= sec
->vma
;
3659 sec
= bfd_get_section_by_name (abfd
, ".got");
3661 got_addr
= sec
->vma
;
3664 if (got_addr
== (bfd_vma
) -1)
3669 /* Check for each PLT section. */
3670 names
= (char *) (s
+ count
);
3673 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
3674 if ((plt_contents
= plts
[j
].contents
) != NULL
)
3679 struct elf_x86_plt
*plt_p
= &plts
[j
];
3681 plt_got_offset
= plt_p
->plt_got_offset
;
3682 plt_entry_size
= plt_p
->plt_entry_size
;
3686 if ((plt_p
->type
& plt_lazy
))
3688 /* Skip PLT0 in lazy PLT. */
3690 offset
= plt_entry_size
;
3698 /* Check each PLT entry against dynamic relocations. */
3699 for (; k
< plt_p
->count
; k
++)
3705 /* Get the GOT offset for i386 or the PC-relative offset
3706 for x86-64, a signed 32-bit integer. */
3707 off
= H_GET_32 (abfd
, (plt_contents
+ offset
3709 got_vma
= get_plt_got_vma (plt_p
, off
, offset
, got_addr
);
3711 /* Binary search. */
3715 while ((min
+ 1) < max
)
3719 mid
= (min
+ max
) / 2;
3721 if (got_vma
> r
->address
)
3723 else if (got_vma
< r
->address
)
3732 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
3733 if (got_vma
== p
->address
3735 && valid_plt_reloc_p (p
->howto
->type
))
3737 *s
= **p
->sym_ptr_ptr
;
3738 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
3739 set. Since we are defining a symbol, ensure one
3741 if ((s
->flags
& BSF_LOCAL
) == 0)
3742 s
->flags
|= BSF_GLOBAL
;
3743 s
->flags
|= BSF_SYNTHETIC
;
3744 /* This is no longer a section symbol. */
3745 s
->flags
&= ~BSF_SECTION_SYM
;
3747 s
->the_bfd
= plt
->owner
;
3751 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3752 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3754 /* There may be JUMP_SLOT and IRELATIVE relocations.
3755 JUMP_SLOT r_addend should be ignored. */
3756 if (p
->addend
!= 0 && p
->howto
->type
!= jump_slot_reloc
)
3760 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3761 names
+= sizeof ("+0x") - 1;
3762 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
3763 for (a
= buf
; *a
== '0'; ++a
)
3766 memcpy (names
, a
, size
);
3769 memcpy (names
, "@plt", sizeof ("@plt"));
3770 names
+= sizeof ("@plt");
3773 /* There should be only one entry in PLT for a given
3774 symbol. Set howto to NULL after processing a PLT
3775 entry to guard against corrupted PLT. */
3778 offset
+= plt_entry_size
;
3782 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
3791 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
3792 free (plts
[j
].contents
);
3799 /* Parse x86 GNU properties. */
3801 enum elf_property_kind
3802 _bfd_x86_elf_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
3803 bfd_byte
*ptr
, unsigned int datasz
)
3807 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3808 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3809 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3810 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3811 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3812 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
3813 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3814 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3819 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
3820 abfd
, type
, datasz
);
3821 return property_corrupt
;
3823 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
3824 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
3825 prop
->pr_kind
= property_number
;
3826 return property_number
;
3829 return property_ignored
;
3832 /* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
3833 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
3834 should be merged with ABFD. */
3837 _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info
*info
,
3838 bfd
*abfd ATTRIBUTE_UNUSED
,
3839 bfd
*bbfd ATTRIBUTE_UNUSED
,
3840 elf_property
*aprop
,
3841 elf_property
*bprop
)
3843 unsigned int number
, features
;
3844 bool updated
= false;
3845 const struct elf_backend_data
*bed
;
3846 struct elf_x86_link_hash_table
*htab
;
3847 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
3849 if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3850 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3851 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3853 if (aprop
== NULL
|| bprop
== NULL
)
3855 /* Only one of APROP and BPROP can be NULL. */
3858 /* Remove this property since the other input file doesn't
3860 aprop
->pr_kind
= property_remove
;
3866 number
= aprop
->u
.number
;
3867 aprop
->u
.number
= number
| bprop
->u
.number
;
3868 updated
= number
!= (unsigned int) aprop
->u
.number
;
3872 else if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3873 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3874 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_HI
))
3877 if (pr_type
== GNU_PROPERTY_X86_ISA_1_NEEDED
)
3879 bed
= get_elf_backend_data (info
->output_bfd
);
3880 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3881 switch (htab
->params
->isa_level
)
3886 features
= GNU_PROPERTY_X86_ISA_1_V2
;
3889 features
= GNU_PROPERTY_X86_ISA_1_V3
;
3892 features
= GNU_PROPERTY_X86_ISA_1_V4
;
3898 if (aprop
!= NULL
&& bprop
!= NULL
)
3900 number
= aprop
->u
.number
;
3901 aprop
->u
.number
= number
| bprop
->u
.number
| features
;
3902 /* Remove the property if all bits are empty. */
3903 if (aprop
->u
.number
== 0)
3905 aprop
->pr_kind
= property_remove
;
3909 updated
= number
!= (unsigned int) aprop
->u
.number
;
3913 /* Only one of APROP and BPROP can be NULL. */
3916 aprop
->u
.number
|= features
;
3917 if (aprop
->u
.number
== 0)
3919 /* Remove APROP if all bits are empty. */
3920 aprop
->pr_kind
= property_remove
;
3926 /* Return TRUE if APROP is NULL and all bits of BPROP
3927 aren't empty to indicate that BPROP should be added
3929 bprop
->u
.number
|= features
;
3930 updated
= bprop
->u
.number
!= 0;
3935 else if (pr_type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3936 && pr_type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3938 /* Only one of APROP and BPROP can be NULL:
3939 1. APROP & BPROP when both APROP and BPROP aren't NULL.
3940 2. If APROP is NULL, remove x86 feature.
3941 3. Otherwise, do nothing.
3943 bed
= get_elf_backend_data (info
->output_bfd
);
3944 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3947 if (aprop
!= NULL
&& bprop
!= NULL
)
3949 number
= aprop
->u
.number
;
3950 aprop
->u
.number
= number
& bprop
->u
.number
;
3951 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
3954 if (htab
->params
->ibt
)
3955 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
3956 if (htab
->params
->shstk
)
3957 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
3958 if (htab
->params
->lam_u48
)
3959 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3960 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3961 else if (htab
->params
->lam_u57
)
3962 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
3963 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT,
3964 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
3965 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
3966 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
3967 aprop
->u
.number
|= features
;
3969 updated
= number
!= (unsigned int) aprop
->u
.number
;
3970 /* Remove the property if all feature bits are cleared. */
3971 if (aprop
->u
.number
== 0)
3972 aprop
->pr_kind
= property_remove
;
3976 /* There should be no AND properties since some input doesn't
3977 have them. Set IBT and SHSTK properties for -z ibt and -z
3980 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
3982 if (htab
->params
->ibt
)
3983 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
3984 if (htab
->params
->shstk
)
3985 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
3986 if (htab
->params
->lam_u48
)
3987 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3988 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3989 else if (htab
->params
->lam_u57
)
3990 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
3996 updated
= features
!= (unsigned int) aprop
->u
.number
;
3997 aprop
->u
.number
= features
;
4002 bprop
->u
.number
= features
;
4005 else if (aprop
!= NULL
)
4007 aprop
->pr_kind
= property_remove
;
4015 /* Never should happen. */
4022 /* Set up x86 GNU properties. Return the first relocatable ELF input
4023 with GNU properties if found. Otherwise, return NULL. */
4026 _bfd_x86_elf_link_setup_gnu_properties
4027 (struct bfd_link_info
*info
, struct elf_x86_init_table
*init_table
)
4031 asection
*sec
, *pltsec
;
4034 unsigned int plt_alignment
, features
, isa_level
;
4035 struct elf_x86_link_hash_table
*htab
;
4039 const struct elf_backend_data
*bed
;
4040 unsigned int class_align
= ABI_64_P (info
->output_bfd
) ? 3 : 2;
4041 unsigned int got_align
;
4043 /* Find a normal input file with GNU property note. */
4044 for (pbfd
= info
->input_bfds
;
4046 pbfd
= pbfd
->link
.next
)
4047 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
4048 && bfd_count_sections (pbfd
) != 0)
4052 if (elf_properties (pbfd
) != NULL
)
4056 bed
= get_elf_backend_data (info
->output_bfd
);
4058 htab
= elf_x86_hash_table (info
, bed
->target_id
);
4063 if (htab
->params
->ibt
)
4065 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
4066 htab
->params
->cet_report
&= ~prop_report_ibt
;
4068 if (htab
->params
->shstk
)
4070 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
4071 htab
->params
->cet_report
&= ~prop_report_shstk
;
4073 if (!(htab
->params
->cet_report
& (prop_report_ibt
| prop_report_shstk
)))
4074 htab
->params
->cet_report
= prop_report_none
;
4075 if (htab
->params
->lam_u48
)
4077 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
4078 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
4079 htab
->params
->lam_u48_report
= prop_report_none
;
4080 htab
->params
->lam_u57_report
= prop_report_none
;
4082 else if (htab
->params
->lam_u57
)
4084 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
4085 htab
->params
->lam_u57_report
= prop_report_none
;
4088 switch (htab
->params
->isa_level
)
4094 isa_level
= GNU_PROPERTY_X86_ISA_1_BASELINE
;
4097 isa_level
= GNU_PROPERTY_X86_ISA_1_V2
;
4100 isa_level
= GNU_PROPERTY_X86_ISA_1_V3
;
4103 isa_level
= GNU_PROPERTY_X86_ISA_1_V4
;
4114 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT,
4115 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
4116 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
4117 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
4118 prop
= _bfd_elf_get_property (ebfd
,
4119 GNU_PROPERTY_X86_FEATURE_1_AND
,
4121 prop
->u
.number
|= features
;
4122 prop
->pr_kind
= property_number
;
4127 /* If ISA level is set, add GNU_PROPERTY_X86_ISA_1_NEEDED. */
4128 prop
= _bfd_elf_get_property (ebfd
,
4129 GNU_PROPERTY_X86_ISA_1_NEEDED
,
4131 prop
->u
.number
|= isa_level
;
4132 prop
->pr_kind
= property_number
;
4135 /* Create the GNU property note section if needed. */
4136 if (prop
!= NULL
&& pbfd
== NULL
)
4138 sec
= bfd_make_section_with_flags (ebfd
,
4139 NOTE_GNU_PROPERTY_SECTION_NAME
,
4147 info
->callbacks
->einfo (_("%F%P: failed to create GNU property section\n"));
4149 if (!bfd_set_section_alignment (sec
, class_align
))
4152 info
->callbacks
->einfo (_("%F%pA: failed to align section\n"),
4156 elf_section_type (sec
) = SHT_NOTE
;
4160 if (htab
->params
->cet_report
4161 || htab
->params
->lam_u48_report
4162 || htab
->params
->lam_u57_report
)
4164 /* Report missing IBT, SHSTK and LAM properties. */
4166 const char *warning_msg
= _("%P: %pB: warning: missing %s\n");
4167 const char *error_msg
= _("%X%P: %pB: error: missing %s\n");
4168 const char *cet_msg
= NULL
;
4169 const char *lam_u48_msg
= NULL
;
4170 const char *lam_u57_msg
= NULL
;
4171 const char *missing
;
4172 elf_property_list
*p
;
4173 bool missing_ibt
, missing_shstk
;
4174 bool missing_lam_u48
, missing_lam_u57
;
4176 = (htab
->params
->cet_report
4177 && (htab
->params
->cet_report
& prop_report_ibt
));
4179 = (htab
->params
->cet_report
4180 && (htab
->params
->cet_report
& prop_report_shstk
));
4182 if (htab
->params
->cet_report
)
4184 if ((htab
->params
->cet_report
& prop_report_warning
))
4185 cet_msg
= warning_msg
;
4187 cet_msg
= error_msg
;
4189 if (htab
->params
->lam_u48_report
)
4191 if ((htab
->params
->lam_u48_report
& prop_report_warning
))
4192 lam_u48_msg
= warning_msg
;
4194 lam_u48_msg
= error_msg
;
4196 if (htab
->params
->lam_u57_report
)
4198 if ((htab
->params
->lam_u57_report
& prop_report_warning
))
4199 lam_u57_msg
= warning_msg
;
4201 lam_u57_msg
= error_msg
;
4204 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
4205 if (!(abfd
->flags
& (DYNAMIC
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
4206 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
4208 for (p
= elf_properties (abfd
); p
; p
= p
->next
)
4209 if (p
->property
.pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
4212 missing_ibt
= check_ibt
;
4213 missing_shstk
= check_shstk
;
4214 missing_lam_u48
= !!lam_u48_msg
;
4215 missing_lam_u57
= !!lam_u57_msg
;
4218 missing_ibt
&= !(p
->property
.u
.number
4219 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
4220 missing_shstk
&= !(p
->property
.u
.number
4221 & GNU_PROPERTY_X86_FEATURE_1_SHSTK
);
4222 missing_lam_u48
&= !(p
->property
.u
.number
4223 & GNU_PROPERTY_X86_FEATURE_1_LAM_U48
);
4224 missing_lam_u57
&= !(p
->property
.u
.number
4225 & GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
4227 if (missing_ibt
|| missing_shstk
)
4229 if (missing_ibt
&& missing_shstk
)
4230 missing
= _("IBT and SHSTK properties");
4231 else if (missing_ibt
)
4232 missing
= _("IBT property");
4234 missing
= _("SHSTK property");
4235 info
->callbacks
->einfo (cet_msg
, abfd
, missing
);
4237 if (missing_lam_u48
)
4239 missing
= _("LAM_U48 property");
4240 info
->callbacks
->einfo (lam_u48_msg
, abfd
, missing
);
4242 if (missing_lam_u57
)
4244 missing
= _("LAM_U57 property");
4245 info
->callbacks
->einfo (lam_u57_msg
, abfd
, missing
);
4250 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
4252 htab
->r_info
= init_table
->r_info
;
4253 htab
->r_sym
= init_table
->r_sym
;
4255 if (bfd_link_relocatable (info
))
4258 htab
->plt0_pad_byte
= init_table
->plt0_pad_byte
;
4260 use_ibt_plt
= htab
->params
->ibtplt
|| htab
->params
->ibt
;
4261 if (!use_ibt_plt
&& pbfd
!= NULL
)
4263 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
4264 elf_property_list
*p
;
4266 /* The property list is sorted in order of type. */
4267 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
4269 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
4271 use_ibt_plt
= !!(p
->property
.u
.number
4272 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
4275 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
4280 dynobj
= htab
->elf
.dynobj
;
4282 /* Set htab->elf.dynobj here so that there is no need to check and
4283 set it in check_relocs. */
4288 htab
->elf
.dynobj
= pbfd
;
4295 /* Find a normal input file to hold linker created
4297 for (abfd
= info
->input_bfds
;
4299 abfd
= abfd
->link
.next
)
4300 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4302 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0
4303 && bed
->relocs_compatible (abfd
->xvec
,
4304 info
->output_bfd
->xvec
))
4306 htab
->elf
.dynobj
= abfd
;
4313 /* Return if there are no normal input files. */
4317 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
4318 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
4319 canonical function address. */
4320 htab
->plt
.has_plt0
= 1;
4321 htab
->plt
.plt_indirect_branch_offset
= 0;
4322 normal_target
= htab
->elf
.target_os
== is_normal
;
4328 htab
->lazy_plt
= init_table
->lazy_ibt_plt
;
4329 htab
->non_lazy_plt
= init_table
->non_lazy_ibt_plt
;
4330 htab
->plt
.plt_indirect_branch_offset
= 4;
4334 htab
->lazy_plt
= init_table
->lazy_plt
;
4335 htab
->non_lazy_plt
= init_table
->non_lazy_plt
;
4340 htab
->lazy_plt
= init_table
->lazy_plt
;
4341 htab
->non_lazy_plt
= NULL
;
4344 pltsec
= htab
->elf
.splt
;
4346 if (htab
->non_lazy_plt
!= NULL
4347 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
4357 htab
->sframe_plt
= init_table
->sframe_lazy_ibt_plt
;
4359 htab
->sframe_plt
= init_table
->sframe_non_lazy_ibt_plt
;
4364 htab
->sframe_plt
= init_table
->sframe_lazy_plt
;
4366 htab
->sframe_plt
= init_table
->sframe_non_lazy_plt
;
4370 htab
->sframe_plt
= NULL
;
4372 /* If the non-lazy PLT is available, use it for all PLT entries if
4373 there are no PLT0 or no .plt section. */
4376 if (bfd_link_pic (info
))
4377 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
4379 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
4380 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
4381 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
4382 htab
->plt
.plt_got_insn_size
4383 = htab
->non_lazy_plt
->plt_got_insn_size
;
4384 htab
->plt
.eh_frame_plt_size
4385 = htab
->non_lazy_plt
->eh_frame_plt_size
;
4386 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
4390 if (bfd_link_pic (info
))
4392 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
4393 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
4397 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
4398 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
4400 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
4401 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
4402 htab
->plt
.plt_got_insn_size
4403 = htab
->lazy_plt
->plt_got_insn_size
;
4404 htab
->plt
.eh_frame_plt_size
4405 = htab
->lazy_plt
->eh_frame_plt_size
;
4406 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
4409 if (htab
->elf
.target_os
== is_vxworks
4410 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
4413 info
->callbacks
->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
4417 /* Since create_dynamic_sections isn't always called, but GOT
4418 relocations need GOT relocations, create them here so that we
4419 don't need to do it in check_relocs. */
4420 if (htab
->elf
.sgot
== NULL
4421 && !_bfd_elf_create_got_section (dynobj
, info
))
4422 info
->callbacks
->einfo (_("%F%P: failed to create GOT sections\n"));
4424 got_align
= (bed
->target_id
== X86_64_ELF_DATA
) ? 3 : 2;
4426 /* Align .got and .got.plt sections to their entry size. Do it here
4427 instead of in create_dynamic_sections so that they are always
4428 properly aligned even if create_dynamic_sections isn't called. */
4429 sec
= htab
->elf
.sgot
;
4430 if (!bfd_set_section_alignment (sec
, got_align
))
4431 goto error_alignment
;
4433 sec
= htab
->elf
.sgotplt
;
4434 if (!bfd_set_section_alignment (sec
, got_align
))
4435 goto error_alignment
;
4437 /* Create the ifunc sections here so that check_relocs can be
4439 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
4440 info
->callbacks
->einfo (_("%F%P: failed to create ifunc sections\n"));
4442 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
4446 /* Whe creating executable, set the contents of the .interp
4447 section to the interpreter. */
4448 if (bfd_link_executable (info
) && !info
->nointerp
)
4450 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
4453 s
->size
= htab
->dynamic_interpreter_size
;
4454 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
4460 flagword pltflags
= (bed
->dynamic_sec_flags
4465 unsigned int non_lazy_plt_alignment
4466 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
4469 if (!bfd_set_section_alignment (sec
, plt_alignment
))
4470 goto error_alignment
;
4472 /* Create the GOT procedure linkage table. */
4473 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4477 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT section\n"));
4479 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
4480 goto error_alignment
;
4482 htab
->plt_got
= sec
;
4490 /* Create the second PLT for Intel IBT support. IBT
4491 PLT is needed only for lazy binding. */
4492 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4496 info
->callbacks
->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
4498 if (!bfd_set_section_alignment (sec
, plt_alignment
))
4499 goto error_alignment
;
4502 htab
->plt_second
= sec
;
4506 if (!info
->no_ld_generated_unwind_info
)
4508 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4509 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4510 | SEC_LINKER_CREATED
);
4512 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4516 info
->callbacks
->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
4518 if (!bfd_set_section_alignment (sec
, class_align
))
4519 goto error_alignment
;
4521 htab
->plt_eh_frame
= sec
;
4523 if (htab
->plt_got
!= NULL
)
4525 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4529 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
4531 if (!bfd_set_section_alignment (sec
, class_align
))
4532 goto error_alignment
;
4534 htab
->plt_got_eh_frame
= sec
;
4537 if (htab
->plt_second
!= NULL
)
4539 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4543 info
->callbacks
->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
4545 if (!bfd_set_section_alignment (sec
, class_align
))
4546 goto error_alignment
;
4548 htab
->plt_second_eh_frame
= sec
;
4552 /* .sframe sections are emitted for AMD64 ABI only. */
4553 if (ABI_64_P (info
->output_bfd
) && !info
->no_ld_generated_unwind_info
)
4555 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4556 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4557 | SEC_LINKER_CREATED
);
4559 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4563 info
->callbacks
->einfo (_("%F%P: failed to create PLT .sframe section\n"));
4566 // if (!bfd_set_section_alignment (sec, class_align))
4567 // goto error_alignment;
4569 htab
->plt_sframe
= sec
;
4571 /* Second PLT is generated for Intel IBT + lazy plt. */
4572 if (htab
->plt_second
!= NULL
)
4574 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4578 info
->callbacks
->einfo (_("%F%P: failed to create second PLT .sframe section\n"));
4580 htab
->plt_second_sframe
= sec
;
4582 /* FIXME - add later for plt_got. */
4586 /* The .iplt section is used for IFUNC symbols in static
4588 sec
= htab
->elf
.iplt
;
4591 /* NB: Delay setting its alignment until we know it is non-empty.
4592 Otherwise an empty iplt section may change vma and lma of the
4593 following sections, which triggers moving dot of the following
4594 section backwards, resulting in a warning and section lma not
4595 being set properly. It later leads to a "File truncated"
4597 if (!bfd_set_section_alignment (sec
, 0))
4598 goto error_alignment
;
4600 htab
->plt
.iplt_alignment
= (normal_target
4602 : bed
->plt_alignment
);
4605 if (bfd_link_executable (info
)
4607 && !htab
->params
->has_dynamic_linker
4608 && htab
->params
->static_before_all_inputs
)
4610 /* Report error for dynamic input objects if -static is passed at
4611 command-line before all input files without --dynamic-linker
4612 unless --no-dynamic-linker is used. */
4615 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
4616 if ((abfd
->flags
& DYNAMIC
))
4617 info
->callbacks
->einfo
4618 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
4625 /* Fix up x86 GNU properties. */
4628 _bfd_x86_elf_link_fixup_gnu_properties
4629 (struct bfd_link_info
*info
, elf_property_list
**listp
)
4631 elf_property_list
*p
;
4633 for (p
= *listp
; p
; p
= p
->next
)
4635 unsigned int type
= p
->property
.pr_type
;
4636 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
4637 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
4638 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
4639 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
4640 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
4641 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
4642 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
4643 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
4645 if (p
->property
.u
.number
== 0
4646 && (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
4647 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
4648 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
4649 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
4650 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)))
4652 /* Remove empty property. */
4657 /* Keep LAM features only for 64-bit output. */
4658 if (type
== GNU_PROPERTY_X86_FEATURE_1_AND
4659 && !ABI_64_P (info
->output_bfd
))
4660 p
->property
.u
.number
&= ~(GNU_PROPERTY_X86_FEATURE_1_LAM_U48
4661 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
4665 else if (type
> GNU_PROPERTY_HIPROC
)
4667 /* The property list is sorted in order of type. */
4674 _bfd_elf_linker_x86_set_options (struct bfd_link_info
* info
,
4675 struct elf_linker_x86_params
*params
)
4677 const struct elf_backend_data
*bed
4678 = get_elf_backend_data (info
->output_bfd
);
4679 struct elf_x86_link_hash_table
*htab
4680 = elf_x86_hash_table (info
, bed
->target_id
);
4682 htab
->params
= params
;