1 /* x86 specific support for ELF
2 Copyright (C) 2017-2022 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
)
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
;
1061 relative_reloc
->data
[newidx
].offset
= offset
;
1062 relative_reloc
->data
[newidx
].address
= 0;
1066 /* After input sections have been mapped to output sections and
1067 addresses of output sections are set initiallly, scan input
1068 relocations with the same logic in relocate_section to determine
1069 if a relative relocation should be generated. Save the relative
1070 relocation candidate information for sizing the DT_RELR section
1071 later after all symbols addresses can be determined. */
1074 _bfd_x86_elf_link_relax_section (bfd
*abfd ATTRIBUTE_UNUSED
,
1075 asection
*input_section
,
1076 struct bfd_link_info
*info
,
1079 Elf_Internal_Shdr
*symtab_hdr
;
1080 Elf_Internal_Rela
*internal_relocs
;
1081 Elf_Internal_Rela
*irel
, *irelend
;
1082 Elf_Internal_Sym
*isymbuf
= NULL
;
1083 struct elf_link_hash_entry
**sym_hashes
;
1084 const struct elf_backend_data
*bed
;
1085 struct elf_x86_link_hash_table
*htab
;
1086 bfd_vma
*local_got_offsets
;
1088 bool unaligned_section
;
1090 if (bfd_link_relocatable (info
))
1093 /* Assume we're not going to change any sizes, and we'll only need
1097 bed
= get_elf_backend_data (abfd
);
1098 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1102 /* Nothing to do if there are no relocations or relative relocations
1103 have been packed. */
1104 if (input_section
== htab
->elf
.srelrdyn
1105 || input_section
->relative_reloc_packed
1106 || ((input_section
->flags
& (SEC_RELOC
| SEC_ALLOC
))
1107 != (SEC_RELOC
| SEC_ALLOC
))
1108 || (input_section
->flags
& SEC_DEBUGGING
) != 0
1109 || input_section
->reloc_count
== 0)
1112 /* Skip if the section isn't aligned. */
1113 unaligned_section
= input_section
->alignment_power
== 0;
1115 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
1117 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1118 sym_hashes
= elf_sym_hashes (abfd
);
1119 local_got_offsets
= elf_local_got_offsets (abfd
);
1121 /* Load the relocations for this section. */
1123 _bfd_elf_link_read_relocs (abfd
, input_section
, NULL
,
1124 (Elf_Internal_Rela
*) NULL
,
1126 if (internal_relocs
== NULL
)
1129 irelend
= internal_relocs
+ input_section
->reloc_count
;
1130 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
1132 unsigned int r_type
;
1133 unsigned int r_symndx
;
1134 Elf_Internal_Sym
*isym
;
1135 struct elf_link_hash_entry
*h
;
1136 struct elf_x86_link_hash_entry
*eh
;
1138 bool resolved_to_zero
;
1139 bool need_copy_reloc_in_pie
;
1142 /* Offset must be a multiple of 2. */
1143 bool unaligned_offset
= (irel
->r_offset
& 1) != 0;
1144 /* True if there is a relative relocation against a dynamic
1146 bool dynamic_relative_reloc_p
;
1148 /* Get the value of the symbol referred to by the reloc. */
1149 r_symndx
= htab
->r_sym (irel
->r_info
);
1151 r_type
= ELF32_R_TYPE (irel
->r_info
);
1152 /* Clear the R_X86_64_converted_reloc_bit bit. */
1153 r_type
&= ~R_X86_64_converted_reloc_bit
;
1157 dynamic_relative_reloc_p
= false;
1159 if (r_symndx
< symtab_hdr
->sh_info
)
1161 /* Read this BFD's local symbols. */
1162 if (isymbuf
== NULL
)
1164 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
1165 if (isymbuf
== NULL
)
1166 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
1167 symtab_hdr
->sh_info
, 0,
1169 if (isymbuf
== NULL
)
1173 isym
= isymbuf
+ r_symndx
;
1174 switch (isym
->st_shndx
)
1177 sec
= bfd_abs_section_ptr
;
1180 sec
= bfd_com_section_ptr
;
1182 case SHN_X86_64_LCOMMON
:
1185 sec
= &_bfd_elf_large_com_section
;
1188 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
1192 /* Skip relocation against local STT_GNU_IFUNC symbol. */
1193 if (ELF32_ST_TYPE (isym
->st_info
) == STT_GNU_IFUNC
)
1196 eh
= (struct elf_x86_link_hash_entry
*) h
;
1197 resolved_to_zero
= false;
1201 /* Get H and SEC for GENERATE_DYNAMIC_RELOCATION_P below. */
1202 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1203 while (h
->root
.type
== bfd_link_hash_indirect
1204 || h
->root
.type
== bfd_link_hash_warning
)
1205 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1207 if (h
->root
.type
== bfd_link_hash_defined
1208 || h
->root
.type
== bfd_link_hash_defweak
)
1209 sec
= h
->root
.u
.def
.section
;
1211 /* Skip relocation against STT_GNU_IFUNC symbol. */
1212 if (h
->type
== STT_GNU_IFUNC
)
1215 eh
= (struct elf_x86_link_hash_entry
*) h
;
1216 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
1218 /* NB: See how elf_backend_finish_dynamic_symbol is called
1219 from elf_link_output_extsym. */
1220 if ((h
->dynindx
!= -1 || h
->forced_local
)
1221 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
1222 || h
->root
.type
!= bfd_link_hash_undefweak
)
1223 || !h
->forced_local
)
1224 && h
->got
.offset
!= (bfd_vma
) -1
1225 && ! GOT_TLS_GD_ANY_P (elf_x86_hash_entry (h
)->tls_type
)
1226 && elf_x86_hash_entry (h
)->tls_type
!= GOT_TLS_IE
1227 && !resolved_to_zero
1228 && SYMBOL_REFERENCES_LOCAL_P (info
, h
)
1229 && SYMBOL_DEFINED_NON_SHARED_P (h
))
1230 dynamic_relative_reloc_p
= true;
1235 if (X86_GOT_TYPE_P (is_x86_64
, r_type
))
1237 /* Pack GOT relative relocations. There should be only a
1238 single R_*_RELATIVE relocation in GOT. */
1241 if (eh
->got_relative_reloc_done
)
1244 if (!(dynamic_relative_reloc_p
1245 || (RESOLVED_LOCALLY_P (info
, h
, htab
)
1246 && GENERATE_RELATIVE_RELOC_P (info
, h
))))
1249 if (!dynamic_relative_reloc_p
)
1250 eh
->no_finish_dynamic_symbol
= 1;
1251 eh
->got_relative_reloc_done
= 1;
1252 offset
= h
->got
.offset
;
1256 if (elf_x86_relative_reloc_done (abfd
)[r_symndx
])
1259 if (!X86_LOCAL_GOT_RELATIVE_RELOC_P (is_x86_64
, info
,
1263 elf_x86_relative_reloc_done (abfd
)[r_symndx
] = 1;
1264 offset
= local_got_offsets
[r_symndx
];
1267 if (!elf_x86_relative_reloc_record_add (info
,
1268 &htab
->relative_reloc
,
1269 irel
, htab
->elf
.sgot
,
1270 sec
, h
, isym
, offset
))
1277 && irel
->r_addend
== 0
1278 && !ABI_64_P (info
->output_bfd
))
1280 /* For x32, if addend is zero, treat R_X86_64_64 like
1281 R_X86_64_32 and R_X86_64_SIZE64 like R_X86_64_SIZE32. */
1282 if (r_type
== R_X86_64_64
)
1283 r_type
= R_X86_64_32
;
1284 else if (r_type
== R_X86_64_SIZE64
)
1285 r_type
= R_X86_64_SIZE32
;
1288 if (!X86_RELATIVE_RELOC_TYPE_P (is_x86_64
, r_type
))
1291 /* Pack non-GOT relative relocations. */
1294 need_copy_reloc_in_pie
=
1295 (bfd_link_pie (info
)
1299 || (h
->root
.type
== bfd_link_hash_undefined
))
1300 && (X86_PCREL_TYPE_P (true, r_type
)
1301 || X86_SIZE_TYPE_P (true, r_type
)));
1306 need_copy_reloc_in_pie
= false;
1307 pc32_reloc
= r_type
== R_386_PC32
;
1310 if (GENERATE_DYNAMIC_RELOCATION_P (is_x86_64
, info
, eh
, r_type
,
1311 sec
, need_copy_reloc_in_pie
,
1312 resolved_to_zero
, pc32_reloc
))
1314 /* When generating a shared object, these relocations
1315 are copied into the output file to be resolved at run
1317 offset
= _bfd_elf_section_offset (info
->output_bfd
, info
,
1320 if (offset
== (bfd_vma
) -1
1321 || offset
== (bfd_vma
) -2
1322 || COPY_INPUT_RELOC_P (is_x86_64
, info
, h
, r_type
))
1325 /* This symbol is local, or marked to become local. When
1326 relocation overflow check is disabled, we convert
1327 R_X86_64_32 to dynamic R_X86_64_RELATIVE. */
1329 && !(r_type
== htab
->pointer_r_type
1330 || (r_type
== R_X86_64_32
1331 && htab
->params
->no_reloc_overflow_check
)))
1334 if (!elf_x86_relative_reloc_record_add
1336 ((unaligned_section
|| unaligned_offset
)
1337 ? &htab
->unaligned_relative_reloc
1338 : &htab
->relative_reloc
),
1339 irel
, input_section
, sec
, h
, isym
, offset
))
1344 input_section
->relative_reloc_packed
= 1;
1349 if ((unsigned char *) isymbuf
!= symtab_hdr
->contents
)
1351 if (elf_section_data (input_section
)->relocs
!= internal_relocs
)
1352 free (internal_relocs
);
1356 /* Add an entry to the 64-bit DT_RELR bitmap. */
1359 elf64_dt_relr_bitmap_add
1360 (struct bfd_link_info
*info
, struct elf_dt_relr_bitmap
*bitmap
,
1363 bfd_size_type newidx
;
1365 if (bitmap
->u
.elf64
== NULL
)
1367 bitmap
->u
.elf64
= bfd_malloc (sizeof (uint64_t));
1372 newidx
= bitmap
->count
++;
1374 if (bitmap
->count
> bitmap
->size
)
1377 bitmap
->u
.elf64
= bfd_realloc (bitmap
->u
.elf64
,
1378 (bitmap
->size
* sizeof (uint64_t)));
1381 if (bitmap
->u
.elf64
== NULL
)
1383 info
->callbacks
->einfo
1384 /* xgettext:c-format */
1385 (_("%F%P: %pB: failed to allocate 64-bit DT_RELR bitmap\n"),
1389 bitmap
->u
.elf64
[newidx
] = entry
;
1392 /* Add an entry to the 32-bit DT_RELR bitmap. */
1395 elf32_dt_relr_bitmap_add
1396 (struct bfd_link_info
*info
, struct elf_dt_relr_bitmap
*bitmap
,
1399 bfd_size_type newidx
;
1401 if (bitmap
->u
.elf32
== NULL
)
1403 bitmap
->u
.elf32
= bfd_malloc (sizeof (uint32_t));
1408 newidx
= bitmap
->count
++;
1410 if (bitmap
->count
> bitmap
->size
)
1413 bitmap
->u
.elf32
= bfd_realloc (bitmap
->u
.elf32
,
1414 (bitmap
->size
* sizeof (uint32_t)));
1417 if (bitmap
->u
.elf32
== NULL
)
1419 info
->callbacks
->einfo
1420 /* xgettext:c-format */
1421 (_("%F%P: %pB: failed to allocate 32-bit DT_RELR bitmap\n"),
1425 bitmap
->u
.elf32
[newidx
] = entry
;
1429 _bfd_elf32_write_addend (bfd
*abfd
, uint64_t value
, void *addr
)
1431 bfd_put_32 (abfd
, value
, addr
);
1435 _bfd_elf64_write_addend (bfd
*abfd
, uint64_t value
, void *addr
)
1437 bfd_put_64 (abfd
, value
, addr
);
1440 /* Size or finish relative relocations to determine the run-time
1441 addresses for DT_RELR bitmap computation later. OUTREL is set
1442 to NULL in the sizing phase and non-NULL in the finising phase
1443 where the regular relative relocations will be written out. */
1446 elf_x86_size_or_finish_relative_reloc
1447 (bool is_x86_64
, struct bfd_link_info
*info
,
1448 struct elf_x86_link_hash_table
*htab
, bool unaligned
,
1449 Elf_Internal_Rela
*outrel
)
1451 unsigned int align_mask
;
1452 bfd_size_type i
, count
;
1453 asection
*sec
, *srel
;
1454 struct elf_link_hash_entry
*h
;
1456 Elf_Internal_Sym
*sym
;
1458 asection
*sgot
= htab
->elf
.sgot
;
1459 asection
*srelgot
= htab
->elf
.srelgot
;
1460 struct elf_x86_relative_reloc_data
*relative_reloc
;
1465 relative_reloc
= &htab
->unaligned_relative_reloc
;
1470 relative_reloc
= &htab
->relative_reloc
;
1473 count
= relative_reloc
->count
;
1474 for (i
= 0; i
< count
; i
++)
1476 sec
= relative_reloc
->data
[i
].sec
;
1477 sym
= relative_reloc
->data
[i
].sym
;
1479 /* If SYM is NULL, it must be a global symbol. */
1481 h
= relative_reloc
->data
[i
].u
.h
;
1488 /* This function may be called more than once and REL may be
1489 updated by _bfd_elf_rela_local_sym below. */
1490 Elf_Internal_Rela rel
= relative_reloc
->data
[i
].rel
;
1494 if (h
->root
.type
== bfd_link_hash_defined
1495 || h
->root
.type
== bfd_link_hash_defweak
)
1497 sym_sec
= h
->root
.u
.def
.section
;
1498 relocation
= (h
->root
.u
.def
.value
1499 + sym_sec
->output_section
->vma
1500 + sym_sec
->output_offset
);
1504 /* Allow undefined symbol only at the sizing phase.
1505 Otherwise skip undefined symbol here. Undefined
1506 symbol will be reported by relocate_section. */
1515 sym_sec
= relative_reloc
->data
[i
].u
.sym_sec
;
1516 relocation
= _bfd_elf_rela_local_sym
1517 (info
->output_bfd
, sym
, &sym_sec
, &rel
);
1522 outrel
->r_addend
= relocation
;
1525 if (h
!= NULL
&& h
->needs_plt
)
1529 outrel
->r_addend
+= rel
.r_addend
;
1531 /* Write the implicit addend if ALIGN_MASK isn't 0. */
1536 if (relative_reloc
->data
[i
].offset
>= sec
->size
)
1538 htab
->elf_write_addend_in_got
1539 (info
->output_bfd
, outrel
->r_addend
,
1540 sec
->contents
+ relative_reloc
->data
[i
].offset
);
1544 if (rel
.r_offset
>= sec
->size
)
1546 htab
->elf_write_addend
1547 (info
->output_bfd
, outrel
->r_addend
,
1548 (elf_section_data (sec
)->this_hdr
.contents
1558 srel
= elf_section_data (sec
)->sreloc
;
1559 offset
= (sec
->output_section
->vma
+ sec
->output_offset
1560 + relative_reloc
->data
[i
].offset
);
1561 relative_reloc
->data
[i
].address
= offset
;
1564 outrel
->r_offset
= offset
;
1566 if ((outrel
->r_offset
& align_mask
) != 0)
1569 if (htab
->params
->report_relative_reloc
)
1570 _bfd_x86_elf_link_report_relative_reloc
1571 (info
, sec
, h
, sym
, htab
->relative_r_name
, outrel
);
1573 /* Generate regular relative relocation if ALIGN_MASK is 0. */
1574 if (align_mask
== 0)
1575 htab
->elf_append_reloc (info
->output_bfd
, srel
, outrel
);
1580 /* Compute the DT_RELR section size. Set NEED_PLAYOUT to true if
1581 the DT_RELR section size has been increased. */
1584 elf_x86_compute_dl_relr_bitmap
1585 (struct bfd_link_info
*info
, struct elf_x86_link_hash_table
*htab
,
1589 bfd_size_type i
, count
, new_count
;
1590 struct elf_x86_relative_reloc_data
*relative_reloc
=
1591 &htab
->relative_reloc
;
1592 /* Save the old DT_RELR bitmap count. Don't shrink the DT_RELR bitmap
1593 if the new DT_RELR bitmap count is smaller than the old one. Pad
1594 with trailing 1s which won't be decoded to more relocations. */
1595 bfd_size_type dt_relr_bitmap_count
= htab
->dt_relr_bitmap
.count
;
1597 /* Clear the DT_RELR bitmap count. */
1598 htab
->dt_relr_bitmap
.count
= 0;
1600 count
= relative_reloc
->count
;
1602 if (ABI_64_P (info
->output_bfd
))
1604 /* Compute the 64-bit DT_RELR bitmap. */
1608 if ((relative_reloc
->data
[i
].address
% 1) != 0)
1611 elf64_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1612 relative_reloc
->data
[i
].address
);
1614 base
= relative_reloc
->data
[i
].address
+ 8;
1619 uint64_t bitmap
= 0;
1620 for (; i
< count
; i
++)
1622 bfd_vma delta
= (relative_reloc
->data
[i
].address
1624 /* Stop if it is too far from base. */
1625 if (delta
>= 63 * 8)
1627 /* Stop if it isn't a multiple of 8. */
1628 if ((delta
% 8) != 0)
1630 bitmap
|= 1ULL << (delta
/ 8);
1636 elf64_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1643 new_count
= htab
->dt_relr_bitmap
.count
;
1644 if (dt_relr_bitmap_count
> new_count
)
1646 /* Don't shrink the DT_RELR section size to avoid section
1647 layout oscillation. Instead, pad the DT_RELR bitmap with
1648 1s which do not decode to more relocations. */
1650 htab
->dt_relr_bitmap
.count
= dt_relr_bitmap_count
;
1651 count
= dt_relr_bitmap_count
- new_count
;
1652 for (i
= 0; i
< count
; i
++)
1653 htab
->dt_relr_bitmap
.u
.elf64
[new_count
+ i
] = 1;
1658 /* Compute the 32-bit DT_RELR bitmap. */
1662 if ((relative_reloc
->data
[i
].address
% 1) != 0)
1665 elf32_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1666 relative_reloc
->data
[i
].address
);
1668 base
= relative_reloc
->data
[i
].address
+ 4;
1673 uint32_t bitmap
= 0;
1674 for (; i
< count
; i
++)
1676 bfd_vma delta
= (relative_reloc
->data
[i
].address
1678 /* Stop if it is too far from base. */
1679 if (delta
>= 31 * 4)
1681 /* Stop if it isn't a multiple of 4. */
1682 if ((delta
% 4) != 0)
1684 bitmap
|= 1ULL << (delta
/ 4);
1690 elf32_dt_relr_bitmap_add (info
, &htab
->dt_relr_bitmap
,
1697 new_count
= htab
->dt_relr_bitmap
.count
;
1698 if (dt_relr_bitmap_count
> new_count
)
1700 /* Don't shrink the DT_RELR section size to avoid section
1701 layout oscillation. Instead, pad the DT_RELR bitmap with
1702 1s which do not decode to more relocations. */
1704 htab
->dt_relr_bitmap
.count
= dt_relr_bitmap_count
;
1705 count
= dt_relr_bitmap_count
- new_count
;
1706 for (i
= 0; i
< count
; i
++)
1707 htab
->dt_relr_bitmap
.u
.elf32
[new_count
+ i
] = 1;
1711 if (htab
->dt_relr_bitmap
.count
!= dt_relr_bitmap_count
)
1715 /* The .relr.dyn section size is changed. Update the section
1716 size and tell linker to layout sections again. */
1717 htab
->elf
.srelrdyn
->size
=
1718 (htab
->dt_relr_bitmap
.count
1719 * (ABI_64_P (info
->output_bfd
) ? 8 : 4));
1721 *need_layout
= true;
1724 info
->callbacks
->einfo
1725 /* xgettext:c-format */
1726 (_("%F%P: %pB: size of compact relative reloc section is "
1727 "changed: new (%lu) != old (%lu)\n"),
1728 info
->output_bfd
, htab
->dt_relr_bitmap
.count
,
1729 dt_relr_bitmap_count
);
1733 /* Write out the DT_RELR section. */
1736 elf_x86_write_dl_relr_bitmap (struct bfd_link_info
*info
,
1737 struct elf_x86_link_hash_table
*htab
)
1739 asection
*sec
= htab
->elf
.srelrdyn
;
1740 bfd_size_type size
= sec
->size
;
1742 unsigned char *contents
;
1744 contents
= (unsigned char *) bfd_alloc (sec
->owner
, size
);
1745 if (contents
== NULL
)
1746 info
->callbacks
->einfo
1747 /* xgettext:c-format */
1748 (_("%F%P: %pB: failed to allocate compact relative reloc section\n"),
1751 /* Cache the section contents for elf_link_input_bfd. */
1752 sec
->contents
= contents
;
1754 if (ABI_64_P (info
->output_bfd
))
1755 for (i
= 0; i
< htab
->dt_relr_bitmap
.count
; i
++, contents
+= 8)
1756 bfd_put_64 (info
->output_bfd
, htab
->dt_relr_bitmap
.u
.elf64
[i
],
1759 for (i
= 0; i
< htab
->dt_relr_bitmap
.count
; i
++, contents
+= 4)
1760 bfd_put_32 (info
->output_bfd
, htab
->dt_relr_bitmap
.u
.elf32
[i
],
1764 /* Sort relative relocations by address. */
1767 elf_x86_relative_reloc_compare (const void *pa
, const void *pb
)
1769 struct elf_x86_relative_reloc_record
*a
=
1770 (struct elf_x86_relative_reloc_record
*) pa
;
1771 struct elf_x86_relative_reloc_record
*b
=
1772 (struct elf_x86_relative_reloc_record
*) pb
;
1773 if (a
->address
< b
->address
)
1775 if (a
->address
> b
->address
)
1780 enum dynobj_sframe_plt_type
1786 /* Create SFrame unwind info for the plt entries in the .plt section
1787 of type PLT_SEC_TYPE. */
1790 _bfd_x86_elf_create_sframe_plt (bfd
*output_bfd
,
1791 struct bfd_link_info
*info
,
1792 unsigned int plt_sec_type
)
1794 struct elf_x86_link_hash_table
*htab
;
1795 const struct elf_backend_data
*bed
;
1797 bool plt0_generated_p
;
1798 unsigned int plt0_entry_size
;
1799 unsigned char func_info
;
1800 unsigned int fre_type
;
1801 /* The dynamic plt section for which .sframe unwind information is being
1807 sframe_encoder_ctx
**ectx
= NULL
;
1808 unsigned plt_entry_size
= 0;
1809 unsigned int num_pltn_fres
= 0;
1810 unsigned int num_pltn_entries
= 0;
1812 bed
= get_elf_backend_data (output_bfd
);
1813 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1814 /* Whether SFrame unwind info for plt0 is to be generated. */
1815 plt0_generated_p
= htab
->plt
.has_plt0
;
1817 = (plt0_generated_p
) ? htab
->sframe_plt
->plt0_entry_size
: 0;
1819 switch (plt_sec_type
)
1823 ectx
= &htab
->plt_cfe_ctx
;
1824 dpltsec
= htab
->elf
.splt
;
1826 plt_entry_size
= htab
->plt
.plt_entry_size
;
1827 num_pltn_fres
= htab
->sframe_plt
->pltn_num_fres
;
1829 = (htab
->elf
.splt
->size
- plt0_entry_size
) / plt_entry_size
;
1833 case SFRAME_PLT_SEC
:
1835 ectx
= &htab
->plt_second_cfe_ctx
;
1836 /* FIXME - this or htab->plt_second_sframe ? */
1837 dpltsec
= htab
->plt_second_eh_frame
;
1839 plt_entry_size
= htab
->sframe_plt
->sec_pltn_entry_size
;
1840 num_pltn_fres
= htab
->sframe_plt
->sec_pltn_num_fres
;
1842 = htab
->plt_second_eh_frame
->size
/ plt_entry_size
;
1846 /* No other value is possible. */
1851 *ectx
= sframe_encode (SFRAME_VERSION_1
,
1853 SFRAME_ABI_AMD64_ENDIAN_LITTLE
,
1854 SFRAME_CFA_FIXED_FP_INVALID
,
1855 -8, /* Fixed RA offset. */
1858 /* FRE type is dependent on the size of the function. */
1859 fre_type
= sframe_calc_fre_type (dpltsec
->size
);
1860 func_info
= sframe_fde_func_info (fre_type
,
1861 SFRAME_FDE_TYPE_PCINC
);
1863 /* Add SFrame FDE and the associated FREs for plt0 if plt0 has been
1865 if (plt0_generated_p
)
1867 /* Add SFrame FDE for plt0, the function start address is updated later
1868 at _bfd_elf_merge_section_sframe time. */
1869 sframe_encoder_add_funcdesc (*ectx
,
1870 0, /* func start addr. */
1874 sframe_frame_row_entry plt0_fre
;
1875 unsigned int num_plt0_fres
= htab
->sframe_plt
->plt0_num_fres
;
1876 for (unsigned int j
= 0; j
< num_plt0_fres
; j
++)
1878 plt0_fre
= *(htab
->sframe_plt
->plt0_fres
[j
]);
1879 sframe_encoder_add_fre (*ectx
, 0, &plt0_fre
);
1884 if (num_pltn_entries
)
1886 /* pltn entries use an SFrame FDE of type
1887 SFRAME_FDE_TYPE_PCMASK to exploit the repetitive
1888 pattern of the instructions in these entries. Using this SFrame FDE
1889 type helps in keeping the unwind information for pltn entries
1891 func_info
= sframe_fde_func_info (fre_type
, SFRAME_FDE_TYPE_PCMASK
);
1892 /* Add the SFrame FDE for all PCs starting at the first pltn entry (hence,
1893 function start address = plt0_entry_size. As usual, this will be
1894 updated later at _bfd_elf_merge_section_sframe, by when the
1895 sections are relocated. */
1896 sframe_encoder_add_funcdesc (*ectx
,
1897 plt0_entry_size
, /* func start addr. */
1898 dpltsec
->size
- plt0_entry_size
,
1902 sframe_frame_row_entry pltn_fre
;
1903 /* Now add the FREs for pltn. Simply adding the two FREs suffices due
1904 to the usage of SFRAME_FDE_TYPE_PCMASK above. */
1905 for (unsigned int j
= 0; j
< num_pltn_fres
; j
++)
1907 pltn_fre
= *(htab
->sframe_plt
->pltn_fres
[j
]);
1908 sframe_encoder_add_fre (*ectx
, 1, &pltn_fre
);
1915 /* Put contents of the .sframe section corresponding to the specified
1919 _bfd_x86_elf_write_sframe_plt (bfd
*output_bfd
,
1920 struct bfd_link_info
*info
,
1921 unsigned int plt_sec_type
)
1923 struct elf_x86_link_hash_table
*htab
;
1924 const struct elf_backend_data
*bed
;
1925 sframe_encoder_ctx
*ectx
;
1932 bed
= get_elf_backend_data (output_bfd
);
1933 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1934 dynobj
= htab
->elf
.dynobj
;
1936 switch (plt_sec_type
)
1939 ectx
= htab
->plt_cfe_ctx
;
1940 sec
= htab
->plt_sframe
;
1942 case SFRAME_PLT_SEC
:
1943 ectx
= htab
->plt_second_cfe_ctx
;
1944 sec
= htab
->plt_second_sframe
;
1947 /* No other value is possible. */
1954 void *contents
= sframe_encoder_write (ectx
, &sec_size
, &err
);
1956 sec
->size
= (bfd_size_type
) sec_size
;
1957 sec
->contents
= (unsigned char *) bfd_zalloc (dynobj
, sec
->size
);
1958 memcpy (sec
->contents
, contents
, sec_size
);
1960 sframe_encoder_free (&ectx
);
1966 _bfd_elf_x86_size_relative_relocs (struct bfd_link_info
*info
,
1969 struct elf_x86_link_hash_table
*htab
;
1970 const struct elf_backend_data
*bed
;
1972 bfd_size_type i
, count
, unaligned_count
;
1973 asection
*sec
, *srel
;
1975 /* Do nothing for ld -r. */
1976 if (bfd_link_relocatable (info
))
1979 bed
= get_elf_backend_data (info
->output_bfd
);
1980 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1984 count
= htab
->relative_reloc
.count
;
1985 unaligned_count
= htab
->unaligned_relative_reloc
.count
;
1988 if (htab
->generate_relative_reloc_pass
== 0
1989 && htab
->elf
.srelrdyn
!= NULL
)
1991 /* Remove the empty .relr.dyn sections now. */
1992 if (!bfd_is_abs_section (htab
->elf
.srelrdyn
->output_section
))
1994 bfd_section_list_remove
1995 (info
->output_bfd
, htab
->elf
.srelrdyn
->output_section
);
1996 info
->output_bfd
->section_count
--;
1998 bfd_section_list_remove (htab
->elf
.srelrdyn
->owner
,
1999 htab
->elf
.srelrdyn
);
2000 htab
->elf
.srelrdyn
->owner
->section_count
--;
2002 if (unaligned_count
== 0)
2004 htab
->generate_relative_reloc_pass
++;
2009 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
2011 /* Size relative relocations. */
2012 if (htab
->generate_relative_reloc_pass
)
2014 /* Reset the regular relative relocation count. */
2015 for (i
= 0; i
< unaligned_count
; i
++)
2017 sec
= htab
->unaligned_relative_reloc
.data
[i
].sec
;
2018 srel
= elf_section_data (sec
)->sreloc
;
2019 srel
->reloc_count
= 0;
2024 /* Remove the reserved space for compact relative relocations. */
2027 asection
*sgot
= htab
->elf
.sgot
;
2028 asection
*srelgot
= htab
->elf
.srelgot
;
2030 for (i
= 0; i
< count
; i
++)
2032 sec
= htab
->relative_reloc
.data
[i
].sec
;
2036 srel
= elf_section_data (sec
)->sreloc
;
2037 srel
->size
-= htab
->sizeof_reloc
;
2042 /* Size unaligned relative relocations. */
2043 if (unaligned_count
)
2044 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2049 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2052 /* Sort relative relocations by addresses. We only need to
2053 sort them in the first pass since the relative positions
2055 if (htab
->generate_relative_reloc_pass
== 0)
2056 qsort (htab
->relative_reloc
.data
, count
,
2057 sizeof (struct elf_x86_relative_reloc_record
),
2058 elf_x86_relative_reloc_compare
);
2060 elf_x86_compute_dl_relr_bitmap (info
, htab
, need_layout
);
2063 htab
->generate_relative_reloc_pass
++;
2069 _bfd_elf_x86_finish_relative_relocs (struct bfd_link_info
*info
)
2071 struct elf_x86_link_hash_table
*htab
;
2072 const struct elf_backend_data
*bed
;
2073 Elf_Internal_Rela outrel
;
2075 bfd_size_type count
;
2077 /* Do nothing for ld -r. */
2078 if (bfd_link_relocatable (info
))
2081 bed
= get_elf_backend_data (info
->output_bfd
);
2082 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2086 is_x86_64
= bed
->target_id
== X86_64_ELF_DATA
;
2088 outrel
.r_info
= htab
->r_info (0, htab
->relative_r_type
);
2090 if (htab
->unaligned_relative_reloc
.count
)
2091 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2094 count
= htab
->relative_reloc
.count
;
2097 elf_x86_size_or_finish_relative_reloc (is_x86_64
, info
, htab
,
2100 elf_x86_compute_dl_relr_bitmap (info
, htab
, NULL
);
2102 elf_x86_write_dl_relr_bitmap (info
, htab
);
2109 _bfd_elf_x86_valid_reloc_p (asection
*input_section
,
2110 struct bfd_link_info
*info
,
2111 struct elf_x86_link_hash_table
*htab
,
2112 const Elf_Internal_Rela
*rel
,
2113 struct elf_link_hash_entry
*h
,
2114 Elf_Internal_Sym
*sym
,
2115 Elf_Internal_Shdr
*symtab_hdr
,
2116 bool *no_dynreloc_p
)
2118 bool valid_p
= true;
2120 *no_dynreloc_p
= false;
2122 /* Check If relocation against non-preemptible absolute symbol is
2123 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
2124 it may call _bfd_elf_link_hide_sym_by_version and result in
2125 ld-elfvers/ vers21 test failure. */
2126 if (bfd_link_pic (info
)
2127 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
2129 const struct elf_backend_data
*bed
;
2130 unsigned int r_type
;
2131 Elf_Internal_Rela irel
;
2133 /* Skip non-absolute symbol. */
2136 if (!ABS_SYMBOL_P (h
))
2139 else if (sym
->st_shndx
!= SHN_ABS
)
2142 bed
= get_elf_backend_data (input_section
->owner
);
2143 r_type
= ELF32_R_TYPE (rel
->r_info
);
2146 /* Only allow relocations against absolute symbol, which can be
2147 resolved as absolute value + addend. GOTPCREL and GOT32
2148 relocations are allowed since absolute value + addend is
2149 stored in the GOT slot. */
2150 if (bed
->target_id
== X86_64_ELF_DATA
)
2152 r_type
&= ~R_X86_64_converted_reloc_bit
;
2153 valid_p
= (r_type
== R_X86_64_64
2154 || r_type
== R_X86_64_32
2155 || r_type
== R_X86_64_32S
2156 || r_type
== R_X86_64_16
2157 || r_type
== R_X86_64_8
2158 || r_type
== R_X86_64_GOTPCREL
2159 || r_type
== R_X86_64_GOTPCRELX
2160 || r_type
== R_X86_64_REX_GOTPCRELX
);
2163 unsigned int r_symndx
= htab
->r_sym (rel
->r_info
);
2164 irel
.r_info
= htab
->r_info (r_symndx
, r_type
);
2168 valid_p
= (r_type
== R_386_32
2169 || r_type
== R_386_16
2170 || r_type
== R_386_8
2171 || r_type
== R_386_GOT32
2172 || r_type
== R_386_GOT32X
);
2175 *no_dynreloc_p
= true;
2179 arelent internal_reloc
;
2181 if (!bed
->elf_info_to_howto (input_section
->owner
,
2182 &internal_reloc
, &irel
)
2183 || internal_reloc
.howto
== NULL
)
2187 name
= h
->root
.root
.string
;
2189 name
= bfd_elf_sym_name (input_section
->owner
, symtab_hdr
,
2191 info
->callbacks
->einfo
2192 /* xgettext:c-format */
2193 (_("%F%P: %pB: relocation %s against absolute symbol "
2194 "`%s' in section `%pA' is disallowed\n"),
2195 input_section
->owner
, internal_reloc
.howto
->name
, name
,
2197 bfd_set_error (bfd_error_bad_value
);
2204 /* Set the sizes of the dynamic sections. */
2207 _bfd_x86_elf_size_dynamic_sections (bfd
*output_bfd
,
2208 struct bfd_link_info
*info
)
2210 struct elf_x86_link_hash_table
*htab
;
2215 const struct elf_backend_data
*bed
2216 = get_elf_backend_data (output_bfd
);
2218 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2221 dynobj
= htab
->elf
.dynobj
;
2225 /* Set up .got offsets for local syms, and space for local dynamic
2227 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
2229 bfd_signed_vma
*local_got
;
2230 bfd_signed_vma
*end_local_got
;
2231 char *local_tls_type
;
2232 bfd_vma
*local_tlsdesc_gotent
;
2233 bfd_size_type locsymcount
;
2234 Elf_Internal_Shdr
*symtab_hdr
;
2237 if (! is_x86_elf (ibfd
, htab
))
2240 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
2242 struct elf_dyn_relocs
*p
;
2244 for (p
= ((struct elf_dyn_relocs
*)
2245 elf_section_data (s
)->local_dynrel
);
2249 if (!bfd_is_abs_section (p
->sec
)
2250 && bfd_is_abs_section (p
->sec
->output_section
))
2252 /* Input section has been discarded, either because
2253 it is a copy of a linkonce section or due to
2254 linker script /DISCARD/, so we'll be discarding
2257 else if (htab
->elf
.target_os
== is_vxworks
2258 && strcmp (p
->sec
->output_section
->name
,
2261 /* Relocations in vxworks .tls_vars sections are
2262 handled specially by the loader. */
2264 else if (p
->count
!= 0)
2266 srel
= elf_section_data (p
->sec
)->sreloc
;
2267 srel
->size
+= p
->count
* htab
->sizeof_reloc
;
2268 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
2269 && (info
->flags
& DF_TEXTREL
) == 0)
2271 info
->flags
|= DF_TEXTREL
;
2272 if (bfd_link_textrel_check (info
))
2273 /* xgettext:c-format */
2274 info
->callbacks
->einfo
2275 (_("%P: %pB: warning: relocation "
2276 "in read-only section `%pA'\n"),
2277 p
->sec
->owner
, p
->sec
);
2283 local_got
= elf_local_got_refcounts (ibfd
);
2287 symtab_hdr
= &elf_symtab_hdr (ibfd
);
2288 locsymcount
= symtab_hdr
->sh_info
;
2289 end_local_got
= local_got
+ locsymcount
;
2290 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
2291 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
2293 srel
= htab
->elf
.srelgot
;
2294 for (; local_got
< end_local_got
;
2295 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
2297 *local_tlsdesc_gotent
= (bfd_vma
) -1;
2300 if (GOT_TLS_GDESC_P (*local_tls_type
))
2302 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
2303 - elf_x86_compute_jump_table_size (htab
);
2304 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
2305 *local_got
= (bfd_vma
) -2;
2307 if (! GOT_TLS_GDESC_P (*local_tls_type
)
2308 || GOT_TLS_GD_P (*local_tls_type
))
2310 *local_got
= s
->size
;
2311 s
->size
+= htab
->got_entry_size
;
2312 if (GOT_TLS_GD_P (*local_tls_type
)
2313 || *local_tls_type
== GOT_TLS_IE_BOTH
)
2314 s
->size
+= htab
->got_entry_size
;
2316 if ((bfd_link_pic (info
) && *local_tls_type
!= GOT_ABS
)
2317 || GOT_TLS_GD_ANY_P (*local_tls_type
)
2318 || (*local_tls_type
& GOT_TLS_IE
))
2320 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
2321 srel
->size
+= 2 * htab
->sizeof_reloc
;
2322 else if (GOT_TLS_GD_P (*local_tls_type
)
2323 || ! GOT_TLS_GDESC_P (*local_tls_type
))
2324 srel
->size
+= htab
->sizeof_reloc
;
2325 if (GOT_TLS_GDESC_P (*local_tls_type
))
2327 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
2328 if (bed
->target_id
== X86_64_ELF_DATA
)
2329 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
2334 *local_got
= (bfd_vma
) -1;
2338 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
2340 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
2341 or R_X86_64_TLSLD relocs. */
2342 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
2343 htab
->elf
.sgot
->size
+= 2 * htab
->got_entry_size
;
2344 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
2347 htab
->tls_ld_or_ldm_got
.offset
= -1;
2349 /* Allocate global sym .plt and .got entries, and space for global
2350 sym dynamic relocs. */
2351 elf_link_hash_traverse (&htab
->elf
, elf_x86_allocate_dynrelocs
,
2354 /* Allocate .plt and .got entries, and space for local symbols. */
2355 htab_traverse (htab
->loc_hash_table
, elf_x86_allocate_local_dynreloc
,
2358 /* For every jump slot reserved in the sgotplt, reloc_count is
2359 incremented. However, when we reserve space for TLS descriptors,
2360 it's not incremented, so in order to compute the space reserved
2361 for them, it suffices to multiply the reloc count by the jump
2364 PR ld/13302: We start next_irelative_index at the end of .rela.plt
2365 so that R_{386,X86_64}_IRELATIVE entries come last. */
2366 if (htab
->elf
.srelplt
)
2368 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
2369 htab
->sgotplt_jump_table_size
2370 = elf_x86_compute_jump_table_size (htab
);
2371 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
2373 else if (htab
->elf
.irelplt
)
2374 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
2376 if (htab
->elf
.tlsdesc_plt
)
2378 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
2379 lazy TLS relocations, don't generate the PLT and GOT entries
2381 if ((info
->flags
& DF_BIND_NOW
))
2382 htab
->elf
.tlsdesc_plt
= 0;
2385 htab
->elf
.tlsdesc_got
= htab
->elf
.sgot
->size
;
2386 htab
->elf
.sgot
->size
+= htab
->got_entry_size
;
2387 /* Reserve room for the initial entry.
2388 FIXME: we could probably do away with it in this case. */
2389 if (htab
->elf
.splt
->size
== 0)
2390 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
2391 htab
->elf
.tlsdesc_plt
= htab
->elf
.splt
->size
;
2392 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
2396 if (htab
->elf
.sgotplt
)
2398 /* Don't allocate .got.plt section if there are no GOT nor PLT
2399 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
2400 if ((htab
->elf
.hgot
== NULL
2401 || !htab
->got_referenced
)
2402 && (htab
->elf
.sgotplt
->size
== bed
->got_header_size
)
2403 && (htab
->elf
.splt
== NULL
2404 || htab
->elf
.splt
->size
== 0)
2405 && (htab
->elf
.sgot
== NULL
2406 || htab
->elf
.sgot
->size
== 0)
2407 && (htab
->elf
.iplt
== NULL
2408 || htab
->elf
.iplt
->size
== 0)
2409 && (htab
->elf
.igotplt
== NULL
2410 || htab
->elf
.igotplt
->size
== 0))
2412 htab
->elf
.sgotplt
->size
= 0;
2413 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
2415 if (htab
->elf
.hgot
!= NULL
2416 && htab
->elf
.target_os
!= is_solaris
)
2418 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
2420 htab
->elf
.hgot
->root
.type
= bfd_link_hash_undefined
;
2421 htab
->elf
.hgot
->root
.u
.undef
.abfd
2422 = htab
->elf
.hgot
->root
.u
.def
.section
->owner
;
2423 htab
->elf
.hgot
->root
.linker_def
= 0;
2424 htab
->elf
.hgot
->ref_regular
= 0;
2425 htab
->elf
.hgot
->def_regular
= 0;
2430 if (_bfd_elf_eh_frame_present (info
))
2432 if (htab
->plt_eh_frame
!= NULL
2433 && htab
->elf
.splt
!= NULL
2434 && htab
->elf
.splt
->size
!= 0
2435 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2436 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
2438 if (htab
->plt_got_eh_frame
!= NULL
2439 && htab
->plt_got
!= NULL
2440 && htab
->plt_got
->size
!= 0
2441 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
2442 htab
->plt_got_eh_frame
->size
2443 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2445 /* Unwind info for the second PLT and .plt.got sections are
2447 if (htab
->plt_second_eh_frame
!= NULL
2448 && htab
->plt_second
!= NULL
2449 && htab
->plt_second
->size
!= 0
2450 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2451 htab
->plt_second_eh_frame
->size
2452 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2455 /* No need to size the .sframe section explicitly because the write-out
2456 mechanism is different. Simply prep up the FDE/FRE for the
2458 if (_bfd_elf_sframe_present (info
))
2460 if (htab
->plt_sframe
!= NULL
2461 && htab
->elf
.splt
!= NULL
2462 && htab
->elf
.splt
->size
!= 0
2463 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
2465 _bfd_x86_elf_create_sframe_plt (output_bfd
, info
, SFRAME_PLT
);
2466 /* FIXME - Dirty Hack. Set the size to something non-zero for now,
2467 so that the section does not get stripped out below. The precise
2468 size of this section is known only when the contents are
2469 serialized in _bfd_x86_elf_write_sframe_plt. */
2470 htab
->plt_sframe
->size
= sizeof (sframe_header
) + 1;
2473 /* FIXME - generate for .got.plt ? */
2475 /* Unwind info for the second PLT. */
2476 if (htab
->plt_second_sframe
!= NULL
2477 && htab
->plt_second
!= NULL
2478 && htab
->plt_second
->size
!= 0
2479 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
2481 _bfd_x86_elf_create_sframe_plt (output_bfd
, info
,
2483 /* FIXME - Dirty Hack. Set the size to something non-zero for now,
2484 so that the section does not get stripped out below. The precise
2485 size of this section is known only when the contents are
2486 serialized in _bfd_x86_elf_write_sframe_plt. */
2487 htab
->plt_second_sframe
->size
= sizeof (sframe_header
) + 1;
2491 /* We now have determined the sizes of the various dynamic sections.
2492 Allocate memory for them. */
2494 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
2496 bool strip_section
= true;
2498 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
2501 /* The .relr.dyn section for compact relative relocation will
2503 if (s
== htab
->elf
.srelrdyn
)
2506 if (s
== htab
->elf
.splt
2507 || s
== htab
->elf
.sgot
)
2509 /* Strip this section if we don't need it; see the
2511 /* We'd like to strip these sections if they aren't needed, but if
2512 we've exported dynamic symbols from them we must leave them.
2513 It's too late to tell BFD to get rid of the symbols. */
2515 if (htab
->elf
.hplt
!= NULL
)
2516 strip_section
= false;
2518 else if (s
== htab
->elf
.sgotplt
2519 || s
== htab
->elf
.iplt
2520 || s
== htab
->elf
.igotplt
2521 || s
== htab
->plt_second
2522 || s
== htab
->plt_got
2523 || s
== htab
->plt_eh_frame
2524 || s
== htab
->plt_got_eh_frame
2525 || s
== htab
->plt_second_eh_frame
2526 || s
== htab
->plt_sframe
2527 || s
== htab
->plt_second_sframe
2528 || s
== htab
->elf
.sdynbss
2529 || s
== htab
->elf
.sdynrelro
)
2531 /* Strip these too. */
2533 else if (htab
->is_reloc_section (bfd_section_name (s
)))
2536 && s
!= htab
->elf
.srelplt
2537 && s
!= htab
->srelplt2
)
2540 /* We use the reloc_count field as a counter if we need
2541 to copy relocs into the output file. */
2542 if (s
!= htab
->elf
.srelplt
)
2547 /* It's not one of our sections, so don't allocate space. */
2553 /* If we don't need this section, strip it from the
2554 output file. This is mostly to handle .rel.bss and
2555 .rel.plt. We must create both sections in
2556 create_dynamic_sections, because they must be created
2557 before the linker maps input sections to output
2558 sections. The linker does that before
2559 adjust_dynamic_symbol is called, and it is that
2560 function which decides whether anything needs to go
2561 into these sections. */
2563 s
->flags
|= SEC_EXCLUDE
;
2567 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
2570 /* Skip allocating contents for .sframe section as it is written
2571 out differently. See below. */
2572 if ((s
== htab
->plt_sframe
) || (s
== htab
->plt_second_sframe
))
2575 /* NB: Initially, the iplt section has minimal alignment to
2576 avoid moving dot of the following section backwards when
2577 it is empty. Update its section alignment now since it
2579 if (s
== htab
->elf
.iplt
)
2580 bfd_set_section_alignment (s
, htab
->plt
.iplt_alignment
);
2582 /* Allocate memory for the section contents. We use bfd_zalloc
2583 here in case unused entries are not reclaimed before the
2584 section's contents are written out. This should not happen,
2585 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
2586 reloc instead of garbage. */
2587 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
2588 if (s
->contents
== NULL
)
2592 if (htab
->plt_eh_frame
!= NULL
2593 && htab
->plt_eh_frame
->contents
!= NULL
)
2595 memcpy (htab
->plt_eh_frame
->contents
,
2596 htab
->plt
.eh_frame_plt
,
2597 htab
->plt_eh_frame
->size
);
2598 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
2599 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
2602 if (htab
->plt_got_eh_frame
!= NULL
2603 && htab
->plt_got_eh_frame
->contents
!= NULL
)
2605 memcpy (htab
->plt_got_eh_frame
->contents
,
2606 htab
->non_lazy_plt
->eh_frame_plt
,
2607 htab
->plt_got_eh_frame
->size
);
2608 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
2609 (htab
->plt_got_eh_frame
->contents
2610 + PLT_FDE_LEN_OFFSET
));
2613 if (htab
->plt_second_eh_frame
!= NULL
2614 && htab
->plt_second_eh_frame
->contents
!= NULL
)
2616 memcpy (htab
->plt_second_eh_frame
->contents
,
2617 htab
->non_lazy_plt
->eh_frame_plt
,
2618 htab
->plt_second_eh_frame
->size
);
2619 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
2620 (htab
->plt_second_eh_frame
->contents
2621 + PLT_FDE_LEN_OFFSET
));
2624 if (_bfd_elf_sframe_present (info
))
2626 if (htab
->plt_sframe
!= NULL
2627 && htab
->elf
.splt
!= NULL
2628 && htab
->elf
.splt
->size
!= 0
2629 && htab
->plt_sframe
->contents
== NULL
)
2630 _bfd_x86_elf_write_sframe_plt (output_bfd
, info
, SFRAME_PLT
);
2632 if (htab
->plt_second_sframe
!= NULL
2633 && htab
->elf
.splt
!= NULL
2634 && htab
->elf
.splt
->size
!= 0
2635 && htab
->plt_second_sframe
->contents
== NULL
)
2636 _bfd_x86_elf_write_sframe_plt (output_bfd
, info
, SFRAME_PLT_SEC
);
2639 return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd
, info
,
2643 /* Finish up the x86 dynamic sections. */
2645 struct elf_x86_link_hash_table
*
2646 _bfd_x86_elf_finish_dynamic_sections (bfd
*output_bfd
,
2647 struct bfd_link_info
*info
)
2649 struct elf_x86_link_hash_table
*htab
;
2650 const struct elf_backend_data
*bed
;
2653 bfd_byte
*dyncon
, *dynconend
;
2654 bfd_size_type sizeof_dyn
;
2656 bed
= get_elf_backend_data (output_bfd
);
2657 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2661 dynobj
= htab
->elf
.dynobj
;
2662 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
2664 /* GOT is always created in setup_gnu_properties. But it may not be
2665 needed. .got.plt section may be needed for static IFUNC. */
2666 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
2668 bfd_vma dynamic_addr
;
2670 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
2673 (_("discarded output section: `%pA'"), htab
->elf
.sgotplt
);
2677 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
2678 = htab
->got_entry_size
;
2680 dynamic_addr
= (sdyn
== NULL
2682 : sdyn
->output_section
->vma
+ sdyn
->output_offset
);
2684 /* Set the first entry in the global offset table to the address
2685 of the dynamic section. Write GOT[1] and GOT[2], needed for
2686 the dynamic linker. */
2687 if (htab
->got_entry_size
== 8)
2689 bfd_put_64 (output_bfd
, dynamic_addr
,
2690 htab
->elf
.sgotplt
->contents
);
2691 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2692 htab
->elf
.sgotplt
->contents
+ 8);
2693 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
2694 htab
->elf
.sgotplt
->contents
+ 8*2);
2698 bfd_put_32 (output_bfd
, dynamic_addr
,
2699 htab
->elf
.sgotplt
->contents
);
2700 bfd_put_32 (output_bfd
, 0,
2701 htab
->elf
.sgotplt
->contents
+ 4);
2702 bfd_put_32 (output_bfd
, 0,
2703 htab
->elf
.sgotplt
->contents
+ 4*2);
2707 if (!htab
->elf
.dynamic_sections_created
)
2710 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
2713 sizeof_dyn
= bed
->s
->sizeof_dyn
;
2714 dyncon
= sdyn
->contents
;
2715 dynconend
= sdyn
->contents
+ sdyn
->size
;
2716 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
2718 Elf_Internal_Dyn dyn
;
2721 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
2726 if (htab
->elf
.target_os
== is_vxworks
2727 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
2732 s
= htab
->elf
.sgotplt
;
2733 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
2737 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
2741 s
= htab
->elf
.srelplt
->output_section
;
2742 dyn
.d_un
.d_val
= s
->size
;
2745 case DT_TLSDESC_PLT
:
2747 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
2748 + htab
->elf
.tlsdesc_plt
;
2751 case DT_TLSDESC_GOT
:
2753 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
2754 + htab
->elf
.tlsdesc_got
;
2758 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
2761 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
2762 elf_section_data (htab
->plt_got
->output_section
)
2763 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
2765 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
2766 elf_section_data (htab
->plt_second
->output_section
)
2767 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
2769 /* Adjust .eh_frame for .plt section. */
2770 if (htab
->plt_eh_frame
!= NULL
2771 && htab
->plt_eh_frame
->contents
!= NULL
)
2773 if (htab
->elf
.splt
!= NULL
2774 && htab
->elf
.splt
->size
!= 0
2775 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
2776 && htab
->elf
.splt
->output_section
!= NULL
2777 && htab
->plt_eh_frame
->output_section
!= NULL
)
2779 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
2780 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
2781 + htab
->plt_eh_frame
->output_offset
2782 + PLT_FDE_START_OFFSET
;
2783 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2784 htab
->plt_eh_frame
->contents
2785 + PLT_FDE_START_OFFSET
);
2788 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
2790 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2792 htab
->plt_eh_frame
->contents
))
2797 /* Adjust .eh_frame for .plt.got section. */
2798 if (htab
->plt_got_eh_frame
!= NULL
2799 && htab
->plt_got_eh_frame
->contents
!= NULL
)
2801 if (htab
->plt_got
!= NULL
2802 && htab
->plt_got
->size
!= 0
2803 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
2804 && htab
->plt_got
->output_section
!= NULL
2805 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
2807 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
2808 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
2809 + htab
->plt_got_eh_frame
->output_offset
2810 + PLT_FDE_START_OFFSET
;
2811 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2812 htab
->plt_got_eh_frame
->contents
2813 + PLT_FDE_START_OFFSET
);
2815 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
2817 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2818 htab
->plt_got_eh_frame
,
2819 htab
->plt_got_eh_frame
->contents
))
2824 /* Adjust .eh_frame for the second PLT section. */
2825 if (htab
->plt_second_eh_frame
!= NULL
2826 && htab
->plt_second_eh_frame
->contents
!= NULL
)
2828 if (htab
->plt_second
!= NULL
2829 && htab
->plt_second
->size
!= 0
2830 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
2831 && htab
->plt_second
->output_section
!= NULL
2832 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
2834 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
2835 bfd_vma eh_frame_start
2836 = (htab
->plt_second_eh_frame
->output_section
->vma
2837 + htab
->plt_second_eh_frame
->output_offset
2838 + PLT_FDE_START_OFFSET
);
2839 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
2840 htab
->plt_second_eh_frame
->contents
2841 + PLT_FDE_START_OFFSET
);
2843 if (htab
->plt_second_eh_frame
->sec_info_type
2844 == SEC_INFO_TYPE_EH_FRAME
)
2846 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
2847 htab
->plt_second_eh_frame
,
2848 htab
->plt_second_eh_frame
->contents
))
2853 /* Make any adjustment if necessary and merge .sframe section to
2854 create the final .sframe section for output_bfd. */
2855 if (htab
->plt_sframe
!= NULL
2856 && htab
->plt_sframe
->contents
!= NULL
)
2858 if (htab
->elf
.splt
!= NULL
2859 && htab
->elf
.splt
->size
!= 0
2860 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
2861 && htab
->elf
.splt
->output_section
!= NULL
2862 && htab
->plt_sframe
->output_section
!= NULL
)
2864 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
2865 bfd_vma sframe_start
= htab
->plt_sframe
->output_section
->vma
2866 + htab
->plt_sframe
->output_offset
2867 + PLT_SFRAME_FDE_START_OFFSET
;
2868 #if 0 /* FIXME Testing only. Remove before review. */
2869 bfd_vma test_value
= (plt_start
- sframe_start
)
2870 + htab
->plt_sframe
->output_section
->vma
2871 + htab
->plt_sframe
->output_offset
2872 + PLT_SFRAME_FDE_START_OFFSET
;
2873 bfd_put_signed_32 (dynobj
, test_value
,
2875 bfd_put_signed_32 (dynobj
, plt_start
- sframe_start
,
2876 htab
->plt_sframe
->contents
2877 + PLT_SFRAME_FDE_START_OFFSET
);
2879 if (htab
->plt_sframe
->sec_info_type
== SEC_INFO_TYPE_SFRAME
)
2881 if (! _bfd_elf_merge_section_sframe (output_bfd
, info
,
2883 htab
->plt_sframe
->contents
))
2888 if (htab
->plt_second_sframe
!= NULL
2889 && htab
->plt_second_sframe
->contents
!= NULL
)
2891 if (htab
->plt_second
!= NULL
2892 && htab
->plt_second
->size
!= 0
2893 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
2894 && htab
->plt_second
->output_section
!= NULL
2895 && htab
->plt_second_sframe
->output_section
!= NULL
)
2897 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
2898 bfd_vma sframe_start
2899 = (htab
->plt_second_sframe
->output_section
->vma
2900 + htab
->plt_second_sframe
->output_offset
2901 + PLT_SFRAME_FDE_START_OFFSET
);
2902 #if 0 /* FIXME Testing only. Remove before review. */
2903 bfd_vma test_value
= (plt_start
- sframe_start
)
2904 + htab
->plt_second_sframe
->output_section
->vma
2905 + htab
->plt_second_sframe
->output_offset
2906 + PLT_SFRAME_FDE_START_OFFSET
;
2907 bfd_put_signed_32 (dynobj
, test_value
,
2909 bfd_put_signed_32 (dynobj
, plt_start
- sframe_start
,
2910 htab
->plt_second_sframe
->contents
2911 + PLT_SFRAME_FDE_START_OFFSET
);
2913 if (htab
->plt_second_sframe
->sec_info_type
== SEC_INFO_TYPE_SFRAME
)
2915 if (! _bfd_elf_merge_section_sframe (output_bfd
, info
,
2916 htab
->plt_second_sframe
,
2917 htab
->plt_second_sframe
->contents
))
2921 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
2922 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
2923 = htab
->got_entry_size
;
2930 _bfd_x86_elf_always_size_sections (bfd
*output_bfd
,
2931 struct bfd_link_info
*info
)
2933 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
2937 struct elf_link_hash_entry
*tlsbase
;
2939 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
2940 "_TLS_MODULE_BASE_",
2941 false, false, false);
2943 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
2945 struct elf_x86_link_hash_table
*htab
;
2946 struct bfd_link_hash_entry
*bh
= NULL
;
2947 const struct elf_backend_data
*bed
2948 = get_elf_backend_data (output_bfd
);
2950 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2954 if (!(_bfd_generic_link_add_one_symbol
2955 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
2956 tls_sec
, 0, NULL
, false,
2957 bed
->collect
, &bh
)))
2960 htab
->tls_module_base
= bh
;
2962 tlsbase
= (struct elf_link_hash_entry
*)bh
;
2963 tlsbase
->def_regular
= 1;
2964 tlsbase
->other
= STV_HIDDEN
;
2965 tlsbase
->root
.linker_def
= 1;
2966 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, true);
2974 _bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
2975 unsigned int st_other
,
2977 bool dynamic ATTRIBUTE_UNUSED
)
2981 struct elf_x86_link_hash_entry
*eh
2982 = (struct elf_x86_link_hash_entry
*) h
;
2983 eh
->def_protected
= ELF_ST_VISIBILITY (st_other
) == STV_PROTECTED
;
2987 /* Copy the extra info we tack onto an elf_link_hash_entry. */
2990 _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
2991 struct elf_link_hash_entry
*dir
,
2992 struct elf_link_hash_entry
*ind
)
2994 struct elf_x86_link_hash_entry
*edir
, *eind
;
2996 edir
= (struct elf_x86_link_hash_entry
*) dir
;
2997 eind
= (struct elf_x86_link_hash_entry
*) ind
;
2999 if (ind
->root
.type
== bfd_link_hash_indirect
3000 && dir
->got
.refcount
<= 0)
3002 edir
->tls_type
= eind
->tls_type
;
3003 eind
->tls_type
= GOT_UNKNOWN
;
3006 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
3007 generate a R_386_COPY reloc. */
3008 edir
->gotoff_ref
|= eind
->gotoff_ref
;
3010 edir
->zero_undefweak
|= eind
->zero_undefweak
;
3012 if (ELIMINATE_COPY_RELOCS
3013 && ind
->root
.type
!= bfd_link_hash_indirect
3014 && dir
->dynamic_adjusted
)
3016 /* If called to transfer flags for a weakdef during processing
3017 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
3018 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
3019 if (dir
->versioned
!= versioned_hidden
)
3020 dir
->ref_dynamic
|= ind
->ref_dynamic
;
3021 dir
->ref_regular
|= ind
->ref_regular
;
3022 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
3023 dir
->needs_plt
|= ind
->needs_plt
;
3024 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
3027 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
3030 /* Remove undefined weak symbol from the dynamic symbol table if it
3031 is resolved to 0. */
3034 _bfd_x86_elf_fixup_symbol (struct bfd_link_info
*info
,
3035 struct elf_link_hash_entry
*h
)
3037 if (h
->dynindx
!= -1
3038 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, elf_x86_hash_entry (h
)))
3041 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
3047 /* Change the STT_GNU_IFUNC symbol defined in position-dependent
3048 executable into the normal function symbol and set its address
3049 to its PLT entry, which should be resolved by R_*_IRELATIVE at
3053 _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info
*info
,
3054 struct elf_x86_link_hash_table
*htab
,
3055 struct elf_link_hash_entry
*h
,
3056 Elf_Internal_Sym
*sym
)
3058 if (bfd_link_pde (info
)
3061 && h
->plt
.offset
!= (bfd_vma
) -1
3062 && h
->type
== STT_GNU_IFUNC
)
3066 bfd
*output_bfd
= info
->output_bfd
;
3068 if (htab
->plt_second
)
3070 struct elf_x86_link_hash_entry
*eh
3071 = (struct elf_x86_link_hash_entry
*) h
;
3073 plt_s
= htab
->plt_second
;
3074 plt_offset
= eh
->plt_second
.offset
;
3078 plt_s
= htab
->elf
.splt
;
3079 plt_offset
= h
->plt
.offset
;
3083 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
3085 = _bfd_elf_section_from_bfd_section (output_bfd
,
3086 plt_s
->output_section
);
3087 sym
->st_value
= (plt_s
->output_section
->vma
3088 + plt_s
->output_offset
+ plt_offset
);
3092 /* Report relative relocation. */
3095 _bfd_x86_elf_link_report_relative_reloc
3096 (struct bfd_link_info
*info
, asection
*asect
,
3097 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
,
3098 const char *reloc_name
, const void *reloc
)
3102 const Elf_Internal_Rela
*rel
= (const Elf_Internal_Rela
*) reloc
;
3104 /* Use the output BFD for linker created sections. */
3105 if ((asect
->flags
& SEC_LINKER_CREATED
) != 0)
3106 abfd
= info
->output_bfd
;
3108 abfd
= asect
->owner
;
3110 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
3111 name
= h
->root
.root
.string
;
3113 name
= bfd_elf_sym_name (abfd
, &elf_symtab_hdr (abfd
), sym
, NULL
);
3115 if (asect
->use_rela_p
)
3116 info
->callbacks
->einfo
3117 (_("%pB: %s (offset: 0x%v, info: 0x%v, addend: 0x%v) against "
3118 "'%s' " "for section '%pA' in %pB\n"),
3119 info
->output_bfd
, reloc_name
, rel
->r_offset
, rel
->r_info
,
3120 rel
->r_addend
, name
, asect
, abfd
);
3122 info
->callbacks
->einfo
3123 (_("%pB: %s (offset: 0x%v, info: 0x%v) against '%s' for section "
3125 info
->output_bfd
, reloc_name
, rel
->r_offset
, rel
->r_info
, name
,
3129 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
3132 _bfd_x86_elf_hash_symbol (struct elf_link_hash_entry
*h
)
3134 if (h
->plt
.offset
!= (bfd_vma
) -1
3136 && !h
->pointer_equality_needed
)
3139 return _bfd_elf_hash_symbol (h
);
3142 /* Adjust a symbol defined by a dynamic object and referenced by a
3143 regular object. The current definition is in some section of the
3144 dynamic object, but we're not including those sections. We have to
3145 change the definition to something the rest of the link can
3149 _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
3150 struct elf_link_hash_entry
*h
)
3152 struct elf_x86_link_hash_table
*htab
;
3154 struct elf_x86_link_hash_entry
*eh
;
3155 struct elf_dyn_relocs
*p
;
3156 const struct elf_backend_data
*bed
3157 = get_elf_backend_data (info
->output_bfd
);
3159 eh
= (struct elf_x86_link_hash_entry
*) h
;
3161 /* Clear GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS if it is turned
3162 on by an input relocatable file and there is a non-GOT/non-PLT
3163 reference from another relocatable file without it.
3164 NB: There can be non-GOT reference in data sections in input with
3165 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS. */
3166 if (eh
->non_got_ref_without_indirect_extern_access
3167 && info
->indirect_extern_access
== 1
3168 && bfd_link_executable (info
))
3170 unsigned int needed_1
;
3171 info
->indirect_extern_access
= 0;
3172 /* Turn off nocopyreloc if implied by indirect_extern_access. */
3173 if (info
->nocopyreloc
== 2)
3174 info
->nocopyreloc
= 0;
3175 needed_1
= bfd_h_get_32 (info
->output_bfd
, info
->needed_1_p
);
3176 needed_1
&= ~GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
;
3177 bfd_h_put_32 (info
->output_bfd
, needed_1
, info
->needed_1_p
);
3180 /* STT_GNU_IFUNC symbol must go through PLT. */
3181 if (h
->type
== STT_GNU_IFUNC
)
3183 /* All local STT_GNU_IFUNC references must be treate as local
3184 calls via local PLT. */
3186 && SYMBOL_CALLS_LOCAL (info
, h
))
3188 bfd_size_type pc_count
= 0, count
= 0;
3189 struct elf_dyn_relocs
**pp
;
3191 eh
= (struct elf_x86_link_hash_entry
*) h
;
3192 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
3194 pc_count
+= p
->pc_count
;
3195 p
->count
-= p
->pc_count
;
3204 if (pc_count
|| count
)
3209 /* Increment PLT reference count only for PC-relative
3212 if (h
->plt
.refcount
<= 0)
3213 h
->plt
.refcount
= 1;
3215 h
->plt
.refcount
+= 1;
3219 /* GOTOFF relocation needs PLT. */
3221 h
->plt
.refcount
= 1;
3224 if (h
->plt
.refcount
<= 0)
3226 h
->plt
.offset
= (bfd_vma
) -1;
3232 /* If this is a function, put it in the procedure linkage table. We
3233 will fill in the contents of the procedure linkage table later,
3234 when we know the address of the .got section. */
3235 if (h
->type
== STT_FUNC
3238 if (h
->plt
.refcount
<= 0
3239 || SYMBOL_CALLS_LOCAL (info
, h
)
3240 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3241 && h
->root
.type
== bfd_link_hash_undefweak
))
3243 /* This case can occur if we saw a PLT32 reloc in an input
3244 file, but the symbol was never referred to by a dynamic
3245 object, or if all references were garbage collected. In
3246 such a case, we don't actually need to build a procedure
3247 linkage table, and we can just do a PC32 reloc instead. */
3248 h
->plt
.offset
= (bfd_vma
) -1;
3255 /* It's possible that we incorrectly decided a .plt reloc was needed
3256 * for an R_386_PC32/R_X86_64_PC32 reloc to a non-function sym in
3257 check_relocs. We can't decide accurately between function and
3258 non-function syms in check-relocs; Objects loaded later in
3259 the link may change h->type. So fix it now. */
3260 h
->plt
.offset
= (bfd_vma
) -1;
3262 /* If this is a weak symbol, and there is a real definition, the
3263 processor independent code will have arranged for us to see the
3264 real definition first, and we can just use the same value. */
3265 if (h
->is_weakalias
)
3267 struct elf_link_hash_entry
*def
= weakdef (h
);
3268 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
3269 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
3270 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
3271 if (ELIMINATE_COPY_RELOCS
3272 || info
->nocopyreloc
3273 || SYMBOL_NO_COPYRELOC (info
, eh
))
3275 /* NB: needs_copy is always 0 for i386. */
3276 h
->non_got_ref
= def
->non_got_ref
;
3277 eh
->needs_copy
= def
->needs_copy
;
3282 /* This is a reference to a symbol defined by a dynamic object which
3283 is not a function. */
3285 /* If we are creating a shared library, we must presume that the
3286 only references to the symbol are via the global offset table.
3287 For such cases we need not do anything here; the relocations will
3288 be handled correctly by relocate_section. */
3289 if (!bfd_link_executable (info
))
3292 /* If there are no references to this symbol that do not use the
3293 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
3294 reloc. NB: gotoff_ref is always 0 for x86-64. */
3295 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
3298 /* If -z nocopyreloc was given, we won't generate them either. */
3299 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
3305 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3309 /* If there aren't any dynamic relocs in read-only sections nor
3310 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
3311 avoid the copy reloc. This doesn't work on VxWorks, where we can
3312 not have dynamic relocations (other than copy and jump slot
3313 relocations) in an executable. */
3314 if (ELIMINATE_COPY_RELOCS
3315 && (bed
->target_id
== X86_64_ELF_DATA
3317 && htab
->elf
.target_os
!= is_vxworks
)))
3319 /* If we don't find any dynamic relocs in read-only sections,
3320 then we'll be keeping the dynamic relocs and avoiding the copy
3322 if (!_bfd_elf_readonly_dynrelocs (h
))
3329 /* We must allocate the symbol in our .dynbss section, which will
3330 become part of the .bss section of the executable. There will be
3331 an entry for this symbol in the .dynsym section. The dynamic
3332 object will contain position independent code, so all references
3333 from the dynamic object to this symbol will go through the global
3334 offset table. The dynamic linker will use the .dynsym entry to
3335 determine the address it must put in the global offset table, so
3336 both the dynamic object and the regular object will refer to the
3337 same memory location for the variable. */
3339 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
3340 dynamic linker to copy the initial value out of the dynamic object
3341 and into the runtime process image. */
3342 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
3344 s
= htab
->elf
.sdynrelro
;
3345 srel
= htab
->elf
.sreldynrelro
;
3349 s
= htab
->elf
.sdynbss
;
3350 srel
= htab
->elf
.srelbss
;
3352 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
3354 if (eh
->def_protected
&& bfd_link_executable (info
))
3355 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
3357 /* Disallow copy relocation against non-copyable protected
3359 s
= p
->sec
->output_section
;
3360 if (s
!= NULL
&& (s
->flags
& SEC_READONLY
) != 0)
3362 info
->callbacks
->einfo
3363 /* xgettext:c-format */
3364 (_("%F%P: %pB: copy relocation against non-copyable "
3365 "protected symbol `%s' in %pB\n"),
3366 p
->sec
->owner
, h
->root
.root
.string
,
3367 h
->root
.u
.def
.section
->owner
);
3372 srel
->size
+= htab
->sizeof_reloc
;
3376 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
3380 _bfd_x86_elf_hide_symbol (struct bfd_link_info
*info
,
3381 struct elf_link_hash_entry
*h
,
3384 if (h
->root
.type
== bfd_link_hash_undefweak
3386 && bfd_link_pie (info
))
3388 /* When there is no dynamic interpreter in PIE, make the undefined
3389 weak symbol dynamic so that PC relative branch to the undefined
3390 weak symbol will land to address 0. */
3391 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
3392 if (h
->plt
.refcount
> 0
3393 || eh
->plt_got
.refcount
> 0)
3397 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
3400 /* Return TRUE if a symbol is referenced locally. It is similar to
3401 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
3402 works in check_relocs. */
3405 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info
*info
,
3406 struct elf_link_hash_entry
*h
)
3408 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
3409 struct elf_x86_link_hash_table
*htab
3410 = (struct elf_x86_link_hash_table
*) info
->hash
;
3412 if (eh
->local_ref
> 1)
3415 if (eh
->local_ref
== 1)
3418 /* Unversioned symbols defined in regular objects can be forced local
3419 by linker version script. A weak undefined symbol is forced local
3421 1. It has non-default visibility. Or
3422 2. When building executable, there is no dynamic linker. Or
3423 3. or "-z nodynamic-undefined-weak" is used.
3425 if (_bfd_elf_symbol_refs_local_p (h
, info
, 1)
3426 || (h
->root
.type
== bfd_link_hash_undefweak
3427 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
3428 || (bfd_link_executable (info
)
3429 && htab
->interp
== NULL
)
3430 || info
->dynamic_undefined_weak
== 0))
3431 || ((h
->def_regular
|| ELF_COMMON_DEF_P (h
))
3432 && info
->version_info
!= NULL
3433 && _bfd_elf_link_hide_sym_by_version (info
, h
)))
3443 /* Return the section that should be marked against GC for a given
3447 _bfd_x86_elf_gc_mark_hook (asection
*sec
,
3448 struct bfd_link_info
*info
,
3449 Elf_Internal_Rela
*rel
,
3450 struct elf_link_hash_entry
*h
,
3451 Elf_Internal_Sym
*sym
)
3453 /* Compiler should optimize this out. */
3454 if (((unsigned int) R_X86_64_GNU_VTINHERIT
3455 != (unsigned int) R_386_GNU_VTINHERIT
)
3456 || ((unsigned int) R_X86_64_GNU_VTENTRY
3457 != (unsigned int) R_386_GNU_VTENTRY
))
3461 switch (ELF32_R_TYPE (rel
->r_info
))
3463 case R_X86_64_GNU_VTINHERIT
:
3464 case R_X86_64_GNU_VTENTRY
:
3468 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
3472 elf_i386_get_plt_got_vma (struct elf_x86_plt
*plt_p ATTRIBUTE_UNUSED
,
3474 bfd_vma offset ATTRIBUTE_UNUSED
,
3477 return got_addr
+ off
;
3481 elf_x86_64_get_plt_got_vma (struct elf_x86_plt
*plt_p
,
3484 bfd_vma got_addr ATTRIBUTE_UNUSED
)
3486 return plt_p
->sec
->vma
+ offset
+ off
+ plt_p
->plt_got_insn_size
;
3490 elf_i386_valid_plt_reloc_p (unsigned int type
)
3492 return (type
== R_386_JUMP_SLOT
3493 || type
== R_386_GLOB_DAT
3494 || type
== R_386_IRELATIVE
);
3498 elf_x86_64_valid_plt_reloc_p (unsigned int type
)
3500 return (type
== R_X86_64_JUMP_SLOT
3501 || type
== R_X86_64_GLOB_DAT
3502 || type
== R_X86_64_IRELATIVE
);
3506 _bfd_x86_elf_get_synthetic_symtab (bfd
*abfd
,
3510 struct elf_x86_plt plts
[],
3514 long size
, i
, n
, len
;
3516 unsigned int plt_got_offset
, plt_entry_size
;
3518 bfd_byte
*plt_contents
;
3520 arelent
**dynrelbuf
, *p
;
3522 const struct elf_backend_data
*bed
;
3523 bfd_vma (*get_plt_got_vma
) (struct elf_x86_plt
*, bfd_vma
, bfd_vma
,
3525 bool (*valid_plt_reloc_p
) (unsigned int);
3531 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
3532 if (dynrelbuf
== NULL
)
3535 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
3537 if (dynrelcount
<= 0)
3540 /* Sort the relocs by address. */
3541 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
3542 _bfd_x86_elf_compare_relocs
);
3544 size
= count
* sizeof (asymbol
);
3546 /* Allocate space for @plt suffixes. */
3548 for (i
= 0; i
< dynrelcount
; i
++)
3551 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
3553 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
3556 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
3560 bed
= get_elf_backend_data (abfd
);
3562 if (bed
->target_id
== X86_64_ELF_DATA
)
3564 get_plt_got_vma
= elf_x86_64_get_plt_got_vma
;
3565 valid_plt_reloc_p
= elf_x86_64_valid_plt_reloc_p
;
3569 get_plt_got_vma
= elf_i386_get_plt_got_vma
;
3570 valid_plt_reloc_p
= elf_i386_valid_plt_reloc_p
;
3573 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
3575 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
3577 got_addr
= sec
->vma
;
3580 sec
= bfd_get_section_by_name (abfd
, ".got");
3582 got_addr
= sec
->vma
;
3585 if (got_addr
== (bfd_vma
) -1)
3590 /* Check for each PLT section. */
3591 names
= (char *) (s
+ count
);
3594 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
3595 if ((plt_contents
= plts
[j
].contents
) != NULL
)
3600 struct elf_x86_plt
*plt_p
= &plts
[j
];
3602 plt_got_offset
= plt_p
->plt_got_offset
;
3603 plt_entry_size
= plt_p
->plt_entry_size
;
3607 if ((plt_p
->type
& plt_lazy
))
3609 /* Skip PLT0 in lazy PLT. */
3611 offset
= plt_entry_size
;
3619 /* Check each PLT entry against dynamic relocations. */
3620 for (; k
< plt_p
->count
; k
++)
3626 /* Get the GOT offset for i386 or the PC-relative offset
3627 for x86-64, a signed 32-bit integer. */
3628 off
= H_GET_32 (abfd
, (plt_contents
+ offset
3630 got_vma
= get_plt_got_vma (plt_p
, off
, offset
, got_addr
);
3632 /* Binary search. */
3636 while ((min
+ 1) < max
)
3640 mid
= (min
+ max
) / 2;
3642 if (got_vma
> r
->address
)
3644 else if (got_vma
< r
->address
)
3653 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
3654 if (got_vma
== p
->address
3656 && valid_plt_reloc_p (p
->howto
->type
))
3658 *s
= **p
->sym_ptr_ptr
;
3659 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
3660 set. Since we are defining a symbol, ensure one
3662 if ((s
->flags
& BSF_LOCAL
) == 0)
3663 s
->flags
|= BSF_GLOBAL
;
3664 s
->flags
|= BSF_SYNTHETIC
;
3665 /* This is no longer a section symbol. */
3666 s
->flags
&= ~BSF_SECTION_SYM
;
3668 s
->the_bfd
= plt
->owner
;
3672 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
3673 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
3679 memcpy (names
, "+0x", sizeof ("+0x") - 1);
3680 names
+= sizeof ("+0x") - 1;
3681 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
3682 for (a
= buf
; *a
== '0'; ++a
)
3685 memcpy (names
, a
, size
);
3688 memcpy (names
, "@plt", sizeof ("@plt"));
3689 names
+= sizeof ("@plt");
3692 /* There should be only one entry in PLT for a given
3693 symbol. Set howto to NULL after processing a PLT
3694 entry to guard against corrupted PLT. */
3697 offset
+= plt_entry_size
;
3701 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
3710 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
3711 free (plts
[j
].contents
);
3718 /* Parse x86 GNU properties. */
3720 enum elf_property_kind
3721 _bfd_x86_elf_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
3722 bfd_byte
*ptr
, unsigned int datasz
)
3726 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3727 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3728 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3729 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3730 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3731 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
3732 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3733 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3738 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
3739 abfd
, type
, datasz
);
3740 return property_corrupt
;
3742 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
3743 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
3744 prop
->pr_kind
= property_number
;
3745 return property_number
;
3748 return property_ignored
;
3751 /* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
3752 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
3753 should be merged with ABFD. */
3756 _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info
*info
,
3757 bfd
*abfd ATTRIBUTE_UNUSED
,
3758 bfd
*bbfd ATTRIBUTE_UNUSED
,
3759 elf_property
*aprop
,
3760 elf_property
*bprop
)
3762 unsigned int number
, features
;
3763 bool updated
= false;
3764 const struct elf_backend_data
*bed
;
3765 struct elf_x86_link_hash_table
*htab
;
3766 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
3768 if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3769 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3770 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3772 if (aprop
== NULL
|| bprop
== NULL
)
3774 /* Only one of APROP and BPROP can be NULL. */
3777 /* Remove this property since the other input file doesn't
3779 aprop
->pr_kind
= property_remove
;
3785 number
= aprop
->u
.number
;
3786 aprop
->u
.number
= number
| bprop
->u
.number
;
3787 updated
= number
!= (unsigned int) aprop
->u
.number
;
3791 else if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3792 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3793 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_HI
))
3796 if (pr_type
== GNU_PROPERTY_X86_ISA_1_NEEDED
)
3798 bed
= get_elf_backend_data (info
->output_bfd
);
3799 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3800 switch (htab
->params
->isa_level
)
3805 features
= GNU_PROPERTY_X86_ISA_1_V2
;
3808 features
= GNU_PROPERTY_X86_ISA_1_V3
;
3811 features
= GNU_PROPERTY_X86_ISA_1_V4
;
3817 if (aprop
!= NULL
&& bprop
!= NULL
)
3819 number
= aprop
->u
.number
;
3820 aprop
->u
.number
= number
| bprop
->u
.number
| features
;
3821 /* Remove the property if all bits are empty. */
3822 if (aprop
->u
.number
== 0)
3824 aprop
->pr_kind
= property_remove
;
3828 updated
= number
!= (unsigned int) aprop
->u
.number
;
3832 /* Only one of APROP and BPROP can be NULL. */
3835 aprop
->u
.number
|= features
;
3836 if (aprop
->u
.number
== 0)
3838 /* Remove APROP if all bits are empty. */
3839 aprop
->pr_kind
= property_remove
;
3845 /* Return TRUE if APROP is NULL and all bits of BPROP
3846 aren't empty to indicate that BPROP should be added
3848 bprop
->u
.number
|= features
;
3849 updated
= bprop
->u
.number
!= 0;
3854 else if (pr_type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3855 && pr_type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3857 /* Only one of APROP and BPROP can be NULL:
3858 1. APROP & BPROP when both APROP and BPROP aren't NULL.
3859 2. If APROP is NULL, remove x86 feature.
3860 3. Otherwise, do nothing.
3862 bed
= get_elf_backend_data (info
->output_bfd
);
3863 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3866 if (aprop
!= NULL
&& bprop
!= NULL
)
3868 number
= aprop
->u
.number
;
3869 aprop
->u
.number
= number
& bprop
->u
.number
;
3870 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
3873 if (htab
->params
->ibt
)
3874 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
3875 if (htab
->params
->shstk
)
3876 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
3877 if (htab
->params
->lam_u48
)
3878 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3879 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3880 else if (htab
->params
->lam_u57
)
3881 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
3882 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT,
3883 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
3884 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
3885 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
3886 aprop
->u
.number
|= features
;
3888 updated
= number
!= (unsigned int) aprop
->u
.number
;
3889 /* Remove the property if all feature bits are cleared. */
3890 if (aprop
->u
.number
== 0)
3891 aprop
->pr_kind
= property_remove
;
3895 /* There should be no AND properties since some input doesn't
3896 have them. Set IBT and SHSTK properties for -z ibt and -z
3899 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
3901 if (htab
->params
->ibt
)
3902 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
3903 if (htab
->params
->shstk
)
3904 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
3905 if (htab
->params
->lam_u48
)
3906 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3907 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3908 else if (htab
->params
->lam_u57
)
3909 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
3915 updated
= features
!= (unsigned int) aprop
->u
.number
;
3916 aprop
->u
.number
= features
;
3921 bprop
->u
.number
= features
;
3924 else if (aprop
!= NULL
)
3926 aprop
->pr_kind
= property_remove
;
3934 /* Never should happen. */
3941 /* Set up x86 GNU properties. Return the first relocatable ELF input
3942 with GNU properties if found. Otherwise, return NULL. */
3945 _bfd_x86_elf_link_setup_gnu_properties
3946 (struct bfd_link_info
*info
, struct elf_x86_init_table
*init_table
)
3950 asection
*sec
, *pltsec
;
3953 unsigned int plt_alignment
, features
, isa_level
;
3954 struct elf_x86_link_hash_table
*htab
;
3958 const struct elf_backend_data
*bed
;
3959 unsigned int class_align
= ABI_64_P (info
->output_bfd
) ? 3 : 2;
3960 unsigned int got_align
;
3962 /* Find a normal input file with GNU property note. */
3963 for (pbfd
= info
->input_bfds
;
3965 pbfd
= pbfd
->link
.next
)
3966 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
3967 && bfd_count_sections (pbfd
) != 0)
3971 if (elf_properties (pbfd
) != NULL
)
3975 bed
= get_elf_backend_data (info
->output_bfd
);
3977 htab
= elf_x86_hash_table (info
, bed
->target_id
);
3982 if (htab
->params
->ibt
)
3984 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
3985 htab
->params
->cet_report
&= ~prop_report_ibt
;
3987 if (htab
->params
->shstk
)
3989 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
3990 htab
->params
->cet_report
&= ~prop_report_shstk
;
3992 if (!(htab
->params
->cet_report
& (prop_report_ibt
| prop_report_shstk
)))
3993 htab
->params
->cet_report
= prop_report_none
;
3994 if (htab
->params
->lam_u48
)
3996 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3997 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3998 htab
->params
->lam_u48_report
= prop_report_none
;
3999 htab
->params
->lam_u57_report
= prop_report_none
;
4001 else if (htab
->params
->lam_u57
)
4003 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
4004 htab
->params
->lam_u57_report
= prop_report_none
;
4007 switch (htab
->params
->isa_level
)
4013 isa_level
= GNU_PROPERTY_X86_ISA_1_BASELINE
;
4016 isa_level
= GNU_PROPERTY_X86_ISA_1_V2
;
4019 isa_level
= GNU_PROPERTY_X86_ISA_1_V3
;
4022 isa_level
= GNU_PROPERTY_X86_ISA_1_V4
;
4033 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT,
4034 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
4035 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
4036 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
4037 prop
= _bfd_elf_get_property (ebfd
,
4038 GNU_PROPERTY_X86_FEATURE_1_AND
,
4040 prop
->u
.number
|= features
;
4041 prop
->pr_kind
= property_number
;
4046 /* If ISA level is set, add GNU_PROPERTY_X86_ISA_1_NEEDED. */
4047 prop
= _bfd_elf_get_property (ebfd
,
4048 GNU_PROPERTY_X86_ISA_1_NEEDED
,
4050 prop
->u
.number
|= isa_level
;
4051 prop
->pr_kind
= property_number
;
4054 /* Create the GNU property note section if needed. */
4055 if (prop
!= NULL
&& pbfd
== NULL
)
4057 sec
= bfd_make_section_with_flags (ebfd
,
4058 NOTE_GNU_PROPERTY_SECTION_NAME
,
4066 info
->callbacks
->einfo (_("%F%P: failed to create GNU property section\n"));
4068 if (!bfd_set_section_alignment (sec
, class_align
))
4071 info
->callbacks
->einfo (_("%F%pA: failed to align section\n"),
4075 elf_section_type (sec
) = SHT_NOTE
;
4079 if (htab
->params
->cet_report
4080 || htab
->params
->lam_u48_report
4081 || htab
->params
->lam_u57_report
)
4083 /* Report missing IBT, SHSTK and LAM properties. */
4085 const char *warning_msg
= _("%P: %pB: warning: missing %s\n");
4086 const char *error_msg
= _("%X%P: %pB: error: missing %s\n");
4087 const char *cet_msg
= NULL
;
4088 const char *lam_u48_msg
= NULL
;
4089 const char *lam_u57_msg
= NULL
;
4090 const char *missing
;
4091 elf_property_list
*p
;
4092 bool missing_ibt
, missing_shstk
;
4093 bool missing_lam_u48
, missing_lam_u57
;
4095 = (htab
->params
->cet_report
4096 && (htab
->params
->cet_report
& prop_report_ibt
));
4098 = (htab
->params
->cet_report
4099 && (htab
->params
->cet_report
& prop_report_shstk
));
4101 if (htab
->params
->cet_report
)
4103 if ((htab
->params
->cet_report
& prop_report_warning
))
4104 cet_msg
= warning_msg
;
4106 cet_msg
= error_msg
;
4108 if (htab
->params
->lam_u48_report
)
4110 if ((htab
->params
->lam_u48_report
& prop_report_warning
))
4111 lam_u48_msg
= warning_msg
;
4113 lam_u48_msg
= error_msg
;
4115 if (htab
->params
->lam_u57_report
)
4117 if ((htab
->params
->lam_u57_report
& prop_report_warning
))
4118 lam_u57_msg
= warning_msg
;
4120 lam_u57_msg
= error_msg
;
4123 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
4124 if (!(abfd
->flags
& (DYNAMIC
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
4125 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
4127 for (p
= elf_properties (abfd
); p
; p
= p
->next
)
4128 if (p
->property
.pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
4131 missing_ibt
= check_ibt
;
4132 missing_shstk
= check_shstk
;
4133 missing_lam_u48
= !!lam_u48_msg
;
4134 missing_lam_u57
= !!lam_u57_msg
;
4137 missing_ibt
&= !(p
->property
.u
.number
4138 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
4139 missing_shstk
&= !(p
->property
.u
.number
4140 & GNU_PROPERTY_X86_FEATURE_1_SHSTK
);
4141 missing_lam_u48
&= !(p
->property
.u
.number
4142 & GNU_PROPERTY_X86_FEATURE_1_LAM_U48
);
4143 missing_lam_u57
&= !(p
->property
.u
.number
4144 & GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
4146 if (missing_ibt
|| missing_shstk
)
4148 if (missing_ibt
&& missing_shstk
)
4149 missing
= _("IBT and SHSTK properties");
4150 else if (missing_ibt
)
4151 missing
= _("IBT property");
4153 missing
= _("SHSTK property");
4154 info
->callbacks
->einfo (cet_msg
, abfd
, missing
);
4156 if (missing_lam_u48
)
4158 missing
= _("LAM_U48 property");
4159 info
->callbacks
->einfo (lam_u48_msg
, abfd
, missing
);
4161 if (missing_lam_u57
)
4163 missing
= _("LAM_U57 property");
4164 info
->callbacks
->einfo (lam_u57_msg
, abfd
, missing
);
4169 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
4171 htab
->r_info
= init_table
->r_info
;
4172 htab
->r_sym
= init_table
->r_sym
;
4174 if (bfd_link_relocatable (info
))
4177 htab
->plt0_pad_byte
= init_table
->plt0_pad_byte
;
4179 use_ibt_plt
= htab
->params
->ibtplt
|| htab
->params
->ibt
;
4180 if (!use_ibt_plt
&& pbfd
!= NULL
)
4182 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
4183 elf_property_list
*p
;
4185 /* The property list is sorted in order of type. */
4186 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
4188 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
4190 use_ibt_plt
= !!(p
->property
.u
.number
4191 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
4194 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
4199 dynobj
= htab
->elf
.dynobj
;
4201 /* Set htab->elf.dynobj here so that there is no need to check and
4202 set it in check_relocs. */
4207 htab
->elf
.dynobj
= pbfd
;
4214 /* Find a normal input file to hold linker created
4216 for (abfd
= info
->input_bfds
;
4218 abfd
= abfd
->link
.next
)
4219 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
4221 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0
4222 && bed
->relocs_compatible (abfd
->xvec
,
4223 info
->output_bfd
->xvec
))
4225 htab
->elf
.dynobj
= abfd
;
4232 /* Return if there are no normal input files. */
4236 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
4237 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
4238 canonical function address. */
4239 htab
->plt
.has_plt0
= 1;
4240 normal_target
= htab
->elf
.target_os
== is_normal
;
4246 htab
->lazy_plt
= init_table
->lazy_ibt_plt
;
4247 htab
->non_lazy_plt
= init_table
->non_lazy_ibt_plt
;
4251 htab
->lazy_plt
= init_table
->lazy_plt
;
4252 htab
->non_lazy_plt
= init_table
->non_lazy_plt
;
4257 htab
->lazy_plt
= init_table
->lazy_plt
;
4258 htab
->non_lazy_plt
= NULL
;
4261 pltsec
= htab
->elf
.splt
;
4263 if (htab
->non_lazy_plt
!= NULL
4264 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
4274 htab
->sframe_plt
= init_table
->sframe_lazy_ibt_plt
;
4276 htab
->sframe_plt
= init_table
->sframe_non_lazy_ibt_plt
;
4281 htab
->sframe_plt
= init_table
->sframe_lazy_plt
;
4283 htab
->sframe_plt
= init_table
->sframe_non_lazy_plt
;
4287 htab
->sframe_plt
= NULL
;
4289 /* If the non-lazy PLT is available, use it for all PLT entries if
4290 there are no PLT0 or no .plt section. */
4293 if (bfd_link_pic (info
))
4294 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
4296 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
4297 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
4298 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
4299 htab
->plt
.plt_got_insn_size
4300 = htab
->non_lazy_plt
->plt_got_insn_size
;
4301 htab
->plt
.eh_frame_plt_size
4302 = htab
->non_lazy_plt
->eh_frame_plt_size
;
4303 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
4307 if (bfd_link_pic (info
))
4309 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
4310 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
4314 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
4315 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
4317 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
4318 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
4319 htab
->plt
.plt_got_insn_size
4320 = htab
->lazy_plt
->plt_got_insn_size
;
4321 htab
->plt
.eh_frame_plt_size
4322 = htab
->lazy_plt
->eh_frame_plt_size
;
4323 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
4326 if (htab
->elf
.target_os
== is_vxworks
4327 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
4330 info
->callbacks
->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
4334 /* Since create_dynamic_sections isn't always called, but GOT
4335 relocations need GOT relocations, create them here so that we
4336 don't need to do it in check_relocs. */
4337 if (htab
->elf
.sgot
== NULL
4338 && !_bfd_elf_create_got_section (dynobj
, info
))
4339 info
->callbacks
->einfo (_("%F%P: failed to create GOT sections\n"));
4341 got_align
= (bed
->target_id
== X86_64_ELF_DATA
) ? 3 : 2;
4343 /* Align .got and .got.plt sections to their entry size. Do it here
4344 instead of in create_dynamic_sections so that they are always
4345 properly aligned even if create_dynamic_sections isn't called. */
4346 sec
= htab
->elf
.sgot
;
4347 if (!bfd_set_section_alignment (sec
, got_align
))
4348 goto error_alignment
;
4350 sec
= htab
->elf
.sgotplt
;
4351 if (!bfd_set_section_alignment (sec
, got_align
))
4352 goto error_alignment
;
4354 /* Create the ifunc sections here so that check_relocs can be
4356 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
4357 info
->callbacks
->einfo (_("%F%P: failed to create ifunc sections\n"));
4359 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
4363 /* Whe creating executable, set the contents of the .interp
4364 section to the interpreter. */
4365 if (bfd_link_executable (info
) && !info
->nointerp
)
4367 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
4370 s
->size
= htab
->dynamic_interpreter_size
;
4371 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
4377 flagword pltflags
= (bed
->dynamic_sec_flags
4382 unsigned int non_lazy_plt_alignment
4383 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
4386 if (!bfd_set_section_alignment (sec
, plt_alignment
))
4387 goto error_alignment
;
4389 /* Create the GOT procedure linkage table. */
4390 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4394 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT section\n"));
4396 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
4397 goto error_alignment
;
4399 htab
->plt_got
= sec
;
4407 /* Create the second PLT for Intel IBT support. IBT
4408 PLT is needed only for lazy binding. */
4409 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4413 info
->callbacks
->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
4415 if (!bfd_set_section_alignment (sec
, plt_alignment
))
4416 goto error_alignment
;
4418 else if (htab
->params
->bndplt
&& ABI_64_P (dynobj
))
4420 /* Create the second PLT for Intel MPX support. MPX
4421 PLT is supported only in 64-bit mode and is needed
4422 only for lazy binding. */
4423 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4427 info
->callbacks
->einfo (_("%F%P: failed to create BND PLT section\n"));
4429 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
4430 goto error_alignment
;
4433 htab
->plt_second
= sec
;
4437 if (!info
->no_ld_generated_unwind_info
)
4439 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4440 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4441 | SEC_LINKER_CREATED
);
4443 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4447 info
->callbacks
->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
4449 if (!bfd_set_section_alignment (sec
, class_align
))
4450 goto error_alignment
;
4452 htab
->plt_eh_frame
= sec
;
4454 if (htab
->plt_got
!= NULL
)
4456 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4460 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
4462 if (!bfd_set_section_alignment (sec
, class_align
))
4463 goto error_alignment
;
4465 htab
->plt_got_eh_frame
= sec
;
4468 if (htab
->plt_second
!= NULL
)
4470 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4474 info
->callbacks
->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
4476 if (!bfd_set_section_alignment (sec
, class_align
))
4477 goto error_alignment
;
4479 htab
->plt_second_eh_frame
= sec
;
4483 /* .sframe sections are emitted for AMD64 ABI only. */
4484 if (ABI_64_P (info
->output_bfd
) && !info
->no_ld_generated_unwind_info
)
4486 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
4487 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4488 | SEC_LINKER_CREATED
);
4490 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4494 info
->callbacks
->einfo (_("%F%P: failed to create PLT .sframe section\n"));
4497 // if (!bfd_set_section_alignment (sec, class_align))
4498 // goto error_alignment;
4500 htab
->plt_sframe
= sec
;
4502 /* Second PLT is generated for Intel IBT / MPX Support + lazy plt. */
4503 if (htab
->plt_second
!= NULL
)
4505 sec
= bfd_make_section_anyway_with_flags (dynobj
,
4509 info
->callbacks
->einfo (_("%F%P: failed to create second PLT .sframe section\n"));
4511 htab
->plt_second_sframe
= sec
;
4513 /* FIXME - add later for plt_got. */
4517 /* The .iplt section is used for IFUNC symbols in static
4519 sec
= htab
->elf
.iplt
;
4522 /* NB: Delay setting its alignment until we know it is non-empty.
4523 Otherwise an empty iplt section may change vma and lma of the
4524 following sections, which triggers moving dot of the following
4525 section backwards, resulting in a warning and section lma not
4526 being set properly. It later leads to a "File truncated"
4528 if (!bfd_set_section_alignment (sec
, 0))
4529 goto error_alignment
;
4531 htab
->plt
.iplt_alignment
= (normal_target
4533 : bed
->plt_alignment
);
4536 if (bfd_link_executable (info
)
4538 && !htab
->params
->has_dynamic_linker
4539 && htab
->params
->static_before_all_inputs
)
4541 /* Report error for dynamic input objects if -static is passed at
4542 command-line before all input files without --dynamic-linker
4543 unless --no-dynamic-linker is used. */
4546 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
4547 if ((abfd
->flags
& DYNAMIC
))
4548 info
->callbacks
->einfo
4549 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
4556 /* Fix up x86 GNU properties. */
4559 _bfd_x86_elf_link_fixup_gnu_properties
4560 (struct bfd_link_info
*info
, elf_property_list
**listp
)
4562 elf_property_list
*p
;
4564 for (p
= *listp
; p
; p
= p
->next
)
4566 unsigned int type
= p
->property
.pr_type
;
4567 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
4568 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
4569 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
4570 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
4571 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
4572 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
4573 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
4574 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
4576 if (p
->property
.u
.number
== 0
4577 && (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
4578 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
4579 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
4580 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
4581 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)))
4583 /* Remove empty property. */
4588 /* Keep LAM features only for 64-bit output. */
4589 if (type
== GNU_PROPERTY_X86_FEATURE_1_AND
4590 && !ABI_64_P (info
->output_bfd
))
4591 p
->property
.u
.number
&= ~(GNU_PROPERTY_X86_FEATURE_1_LAM_U48
4592 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
4596 else if (type
> GNU_PROPERTY_HIPROC
)
4598 /* The property list is sorted in order of type. */
4605 _bfd_elf_linker_x86_set_options (struct bfd_link_info
* info
,
4606 struct elf_linker_x86_params
*params
)
4608 const struct elf_backend_data
*bed
4609 = get_elf_backend_data (info
->output_bfd
);
4610 struct elf_x86_link_hash_table
*htab
4611 = elf_x86_hash_table (info
, bed
->target_id
);
4613 htab
->params
= params
;