1 /* x86 specific support for ELF
2 Copyright (C) 2017-2021 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 #include "elf/x86-64.h"
27 /* The name of the dynamic interpreter. This is put in the .interp
30 #define ELF32_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
31 #define ELF64_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
32 #define ELFX32_DYNAMIC_INTERPRETER "/lib/ldx32.so.1"
35 _bfd_x86_elf_mkobject (bfd
*abfd
)
37 return bfd_elf_allocate_object (abfd
,
38 sizeof (struct elf_x86_obj_tdata
),
39 get_elf_backend_data (abfd
)->target_id
);
42 /* _TLS_MODULE_BASE_ needs to be treated especially when linking
43 executables. Rather than setting it to the beginning of the TLS
44 section, we have to set it to the end. This function may be called
45 multiple times, it is idempotent. */
48 _bfd_x86_elf_set_tls_module_base (struct bfd_link_info
*info
)
50 struct elf_x86_link_hash_table
*htab
;
51 struct bfd_link_hash_entry
*base
;
52 const struct elf_backend_data
*bed
;
54 if (!bfd_link_executable (info
))
57 bed
= get_elf_backend_data (info
->output_bfd
);
58 htab
= elf_x86_hash_table (info
, bed
->target_id
);
62 base
= htab
->tls_module_base
;
66 base
->u
.def
.value
= htab
->elf
.tls_size
;
69 /* Return the base VMA address which should be subtracted from real addresses
70 when resolving @dtpoff relocation.
71 This is PT_TLS segment p_vaddr. */
74 _bfd_x86_elf_dtpoff_base (struct bfd_link_info
*info
)
76 /* If tls_sec is NULL, we should have signalled an error already. */
77 if (elf_hash_table (info
)->tls_sec
== NULL
)
79 return elf_hash_table (info
)->tls_sec
->vma
;
82 /* Allocate space in .plt, .got and associated reloc sections for
86 elf_x86_allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
88 struct bfd_link_info
*info
;
89 struct elf_x86_link_hash_table
*htab
;
90 struct elf_x86_link_hash_entry
*eh
;
91 struct elf_dyn_relocs
*p
;
92 unsigned int plt_entry_size
;
93 bool resolved_to_zero
;
94 const struct elf_backend_data
*bed
;
96 if (h
->root
.type
== bfd_link_hash_indirect
)
99 eh
= (struct elf_x86_link_hash_entry
*) h
;
101 info
= (struct bfd_link_info
*) inf
;
102 bed
= get_elf_backend_data (info
->output_bfd
);
103 htab
= elf_x86_hash_table (info
, bed
->target_id
);
107 plt_entry_size
= htab
->plt
.plt_entry_size
;
109 resolved_to_zero
= UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, eh
);
111 /* We can't use the GOT PLT if pointer equality is needed since
112 finish_dynamic_symbol won't clear symbol value and the dynamic
113 linker won't update the GOT slot. We will get into an infinite
115 if (htab
->plt_got
!= NULL
116 && h
->type
!= STT_GNU_IFUNC
117 && !h
->pointer_equality_needed
118 && h
->plt
.refcount
> 0
119 && h
->got
.refcount
> 0)
121 /* Don't use the regular PLT if there are both GOT and GOTPLT
123 h
->plt
.offset
= (bfd_vma
) -1;
125 /* Use the GOT PLT. */
126 eh
->plt_got
.refcount
= 1;
129 /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
130 here if it is defined and referenced in a non-shared object. */
131 if (h
->type
== STT_GNU_IFUNC
134 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &h
->dyn_relocs
,
138 htab
->got_entry_size
,
141 asection
*s
= htab
->plt_second
;
142 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
144 /* Use the second PLT section if it is created. */
145 eh
->plt_second
.offset
= s
->size
;
147 /* Make room for this entry in the second PLT section. */
148 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
156 /* Don't create the PLT entry if there are only function pointer
157 relocations which can be resolved at run-time. */
158 else if (htab
->elf
.dynamic_sections_created
159 && (h
->plt
.refcount
> 0
160 || eh
->plt_got
.refcount
> 0))
162 bool use_plt_got
= eh
->plt_got
.refcount
> 0;
164 /* Make sure this symbol is output as a dynamic symbol.
165 Undefined weak syms won't yet be marked as dynamic. */
169 && h
->root
.type
== bfd_link_hash_undefweak
)
171 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
175 if (bfd_link_pic (info
)
176 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
178 asection
*s
= htab
->elf
.splt
;
179 asection
*second_s
= htab
->plt_second
;
180 asection
*got_s
= htab
->plt_got
;
183 /* If this is the first .plt entry, make room for the special
184 first entry. The .plt section is used by prelink to undo
185 prelinking for dynamic relocations. */
187 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
190 eh
->plt_got
.offset
= got_s
->size
;
193 h
->plt
.offset
= s
->size
;
195 eh
->plt_second
.offset
= second_s
->size
;
198 /* If this symbol is not defined in a regular file, and we are
199 generating PDE, then set the symbol to this location in the
200 .plt. This is required to make function pointers compare
201 as equal between PDE and the shared library.
203 NB: If PLT is PC-relative, we can use the .plt in PIE for
207 else if (htab
->pcrel_plt
)
208 use_plt
= ! bfd_link_dll (info
);
210 use_plt
= bfd_link_pde (info
);
215 /* We need to make a call to the entry of the GOT PLT
216 instead of regular PLT entry. */
217 h
->root
.u
.def
.section
= got_s
;
218 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
224 /* We need to make a call to the entry of the
225 second PLT instead of regular PLT entry. */
226 h
->root
.u
.def
.section
= second_s
;
227 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
231 h
->root
.u
.def
.section
= s
;
232 h
->root
.u
.def
.value
= h
->plt
.offset
;
237 /* Make room for this entry. */
239 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
242 s
->size
+= plt_entry_size
;
244 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
246 /* We also need to make an entry in the .got.plt section,
247 which will be placed in the .got section by the linker
249 htab
->elf
.sgotplt
->size
+= htab
->got_entry_size
;
251 /* There should be no PLT relocation against resolved
252 undefined weak symbol in executable. */
253 if (!resolved_to_zero
)
255 /* We also need to make an entry in the .rel.plt
257 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
258 htab
->elf
.srelplt
->reloc_count
++;
262 if (htab
->elf
.target_os
== is_vxworks
&& !bfd_link_pic (info
))
264 /* VxWorks has a second set of relocations for each PLT entry
265 in executables. They go in a separate relocation section,
266 which is processed by the kernel loader. */
268 /* There are two relocations for the initial PLT entry: an
269 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
270 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
272 asection
*srelplt2
= htab
->srelplt2
;
273 if (h
->plt
.offset
== plt_entry_size
)
274 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
276 /* There are two extra relocations for each subsequent PLT entry:
277 an R_386_32 relocation for the GOT entry, and an R_386_32
278 relocation for the PLT entry. */
280 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
285 eh
->plt_got
.offset
= (bfd_vma
) -1;
286 h
->plt
.offset
= (bfd_vma
) -1;
292 eh
->plt_got
.offset
= (bfd_vma
) -1;
293 h
->plt
.offset
= (bfd_vma
) -1;
297 eh
->tlsdesc_got
= (bfd_vma
) -1;
299 /* For i386, if R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the
300 binary, make it a R_386_TLS_LE_32 requiring no TLS entry. For
301 x86-64, if R_X86_64_GOTTPOFF symbol is now local to the binary,
302 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
303 if (h
->got
.refcount
> 0
304 && bfd_link_executable (info
)
306 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
307 h
->got
.offset
= (bfd_vma
) -1;
308 else if (h
->got
.refcount
> 0)
312 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
314 /* Make sure this symbol is output as a dynamic symbol.
315 Undefined weak syms won't yet be marked as dynamic. */
319 && h
->root
.type
== bfd_link_hash_undefweak
)
321 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
326 if (GOT_TLS_GDESC_P (tls_type
))
328 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
329 - elf_x86_compute_jump_table_size (htab
);
330 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
331 h
->got
.offset
= (bfd_vma
) -2;
333 if (! GOT_TLS_GDESC_P (tls_type
)
334 || GOT_TLS_GD_P (tls_type
))
336 h
->got
.offset
= s
->size
;
337 s
->size
+= htab
->got_entry_size
;
338 /* R_386_TLS_GD and R_X86_64_TLSGD need 2 consecutive GOT
340 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
341 s
->size
+= htab
->got_entry_size
;
343 dyn
= htab
->elf
.dynamic_sections_created
;
344 /* R_386_TLS_IE_32 needs one dynamic relocation,
345 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
346 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
347 need two), R_386_TLS_GD and R_X86_64_TLSGD need one if local
348 symbol and two if global. No dynamic relocation against
349 resolved undefined weak symbol in executable. No dynamic
350 relocation against non-preemptible absolute symbol. */
351 if (tls_type
== GOT_TLS_IE_BOTH
)
352 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
353 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
354 || (tls_type
& GOT_TLS_IE
))
355 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
356 else if (GOT_TLS_GD_P (tls_type
))
357 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
358 else if (! GOT_TLS_GDESC_P (tls_type
)
359 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
360 && !resolved_to_zero
)
361 || h
->root
.type
!= bfd_link_hash_undefweak
)
362 && ((bfd_link_pic (info
)
363 && !(h
->dynindx
== -1
364 && ABS_SYMBOL_P (h
)))
365 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
366 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
367 if (GOT_TLS_GDESC_P (tls_type
))
369 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
370 if (bed
->target_id
== X86_64_ELF_DATA
)
371 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
375 h
->got
.offset
= (bfd_vma
) -1;
377 if (h
->dyn_relocs
== NULL
)
380 /* In the shared -Bsymbolic case, discard space allocated for
381 dynamic pc-relative relocs against symbols which turn out to be
382 defined in regular objects. For the normal shared case, discard
383 space for pc-relative relocs that have become local due to symbol
384 visibility changes. */
386 if (bfd_link_pic (info
))
388 /* Relocs that use pc_count are those that appear on a call
389 insn, or certain REL relocs that can generated via assembly.
390 We want calls to protected symbols to resolve directly to the
391 function rather than going via the plt. If people want
392 function pointer comparisons to work as expected then they
393 should avoid writing weird assembly. */
394 if (SYMBOL_CALLS_LOCAL (info
, h
))
396 struct elf_dyn_relocs
**pp
;
398 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
400 p
->count
-= p
->pc_count
;
409 if (htab
->elf
.target_os
== is_vxworks
)
411 struct elf_dyn_relocs
**pp
;
412 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
414 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
421 /* Also discard relocs on undefined weak syms with non-default
422 visibility or in PIE. */
423 if (h
->dyn_relocs
!= NULL
)
425 if (h
->root
.type
== bfd_link_hash_undefweak
)
427 /* Undefined weak symbol is never bound locally in shared
429 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
432 if (bed
->target_id
== I386_ELF_DATA
435 /* Keep dynamic non-GOT/non-PLT relocation so
436 that we can branch to 0 without PLT. */
437 struct elf_dyn_relocs
**pp
;
439 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
440 if (p
->pc_count
== 0)
444 /* Remove non-R_386_PC32 relocation. */
445 p
->count
= p
->pc_count
;
449 /* Make sure undefined weak symbols are output
450 as dynamic symbols in PIEs for dynamic non-GOT
451 non-PLT reloations. */
452 if (h
->dyn_relocs
!= NULL
453 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
457 h
->dyn_relocs
= NULL
;
459 else if (h
->dynindx
== -1
461 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
464 else if (bfd_link_executable (info
)
465 && (h
->needs_copy
|| eh
->needs_copy
)
469 /* NB: needs_copy is set only for x86-64. For PIE,
470 discard space for pc-relative relocs against symbols
471 which turn out to need copy relocs. */
472 struct elf_dyn_relocs
**pp
;
474 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
476 if (p
->pc_count
!= 0)
484 else if (ELIMINATE_COPY_RELOCS
)
486 /* For the non-shared case, discard space for relocs against
487 symbols which turn out to need copy relocs or are not
488 dynamic. Keep dynamic relocations for run-time function
489 pointer initialization. */
492 || (h
->root
.type
== bfd_link_hash_undefweak
493 && !resolved_to_zero
))
496 || (htab
->elf
.dynamic_sections_created
497 && (h
->root
.type
== bfd_link_hash_undefweak
498 || h
->root
.type
== bfd_link_hash_undefined
))))
500 /* Make sure this symbol is output as a dynamic symbol.
501 Undefined weak syms won't yet be marked as dynamic. */
505 && h
->root
.type
== bfd_link_hash_undefweak
506 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
509 /* If that succeeded, we know we'll be keeping all the
511 if (h
->dynindx
!= -1)
515 h
->dyn_relocs
= NULL
;
520 /* Finally, allocate space. */
521 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
525 sreloc
= elf_section_data (p
->sec
)->sreloc
;
527 BFD_ASSERT (sreloc
!= NULL
);
528 sreloc
->size
+= p
->count
* htab
->sizeof_reloc
;
534 /* Allocate space in .plt, .got and associated reloc sections for
535 local dynamic relocs. */
538 elf_x86_allocate_local_dynreloc (void **slot
, void *inf
)
540 struct elf_link_hash_entry
*h
541 = (struct elf_link_hash_entry
*) *slot
;
543 if (h
->type
!= STT_GNU_IFUNC
547 || h
->root
.type
!= bfd_link_hash_defined
)
550 return elf_x86_allocate_dynrelocs (h
, inf
);
553 /* Find and/or create a hash entry for local symbol. */
555 struct elf_link_hash_entry
*
556 _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table
*htab
,
557 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
560 struct elf_x86_link_hash_entry e
, *ret
;
561 asection
*sec
= abfd
->sections
;
562 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
563 htab
->r_sym (rel
->r_info
));
566 e
.elf
.indx
= sec
->id
;
567 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
568 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
569 create
? INSERT
: NO_INSERT
);
576 ret
= (struct elf_x86_link_hash_entry
*) *slot
;
580 ret
= (struct elf_x86_link_hash_entry
*)
581 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
582 sizeof (struct elf_x86_link_hash_entry
));
585 memset (ret
, 0, sizeof (*ret
));
586 ret
->elf
.indx
= sec
->id
;
587 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
588 ret
->elf
.dynindx
= -1;
589 ret
->plt_got
.offset
= (bfd_vma
) -1;
595 /* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
596 SYNC WITH _bfd_elf_link_hash_newfunc. */
598 struct bfd_hash_entry
*
599 _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
600 struct bfd_hash_table
*table
,
603 /* Allocate the structure if it has not already been allocated by a
607 entry
= (struct bfd_hash_entry
*)
608 bfd_hash_allocate (table
,
609 sizeof (struct elf_x86_link_hash_entry
));
614 /* Call the allocation method of the superclass. */
615 entry
= _bfd_link_hash_newfunc (entry
, table
, string
);
618 struct elf_x86_link_hash_entry
*eh
619 = (struct elf_x86_link_hash_entry
*) entry
;
620 struct elf_link_hash_table
*htab
621 = (struct elf_link_hash_table
*) table
;
623 memset (&eh
->elf
.size
, 0,
624 (sizeof (struct elf_x86_link_hash_entry
)
625 - offsetof (struct elf_link_hash_entry
, size
)));
626 /* Set local fields. */
628 eh
->elf
.dynindx
= -1;
629 eh
->elf
.got
= htab
->init_got_refcount
;
630 eh
->elf
.plt
= htab
->init_plt_refcount
;
631 /* Assume that we have been called by a non-ELF symbol reader.
632 This flag is then reset by the code which reads an ELF input
633 file. This ensures that a symbol created by a non-ELF symbol
634 reader will have the flag set correctly. */
636 eh
->plt_second
.offset
= (bfd_vma
) -1;
637 eh
->plt_got
.offset
= (bfd_vma
) -1;
638 eh
->tlsdesc_got
= (bfd_vma
) -1;
639 eh
->zero_undefweak
= 1;
645 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
646 for local symbol so that we can handle local STT_GNU_IFUNC symbols
647 as global symbol. We reuse indx and dynstr_index for local symbol
648 hash since they aren't used by global symbols in this backend. */
651 _bfd_x86_elf_local_htab_hash (const void *ptr
)
653 struct elf_link_hash_entry
*h
654 = (struct elf_link_hash_entry
*) ptr
;
655 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
658 /* Compare local hash entries. */
661 _bfd_x86_elf_local_htab_eq (const void *ptr1
, const void *ptr2
)
663 struct elf_link_hash_entry
*h1
664 = (struct elf_link_hash_entry
*) ptr1
;
665 struct elf_link_hash_entry
*h2
666 = (struct elf_link_hash_entry
*) ptr2
;
668 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
671 /* Destroy an x86 ELF linker hash table. */
674 elf_x86_link_hash_table_free (bfd
*obfd
)
676 struct elf_x86_link_hash_table
*htab
677 = (struct elf_x86_link_hash_table
*) obfd
->link
.hash
;
679 if (htab
->loc_hash_table
)
680 htab_delete (htab
->loc_hash_table
);
681 if (htab
->loc_hash_memory
)
682 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
683 _bfd_elf_link_hash_table_free (obfd
);
687 elf_i386_is_reloc_section (const char *secname
)
689 return startswith (secname
, ".rel");
693 elf_x86_64_is_reloc_section (const char *secname
)
695 return startswith (secname
, ".rela");
698 /* Create an x86 ELF linker hash table. */
700 struct bfd_link_hash_table
*
701 _bfd_x86_elf_link_hash_table_create (bfd
*abfd
)
703 struct elf_x86_link_hash_table
*ret
;
704 const struct elf_backend_data
*bed
;
705 size_t amt
= sizeof (struct elf_x86_link_hash_table
);
707 ret
= (struct elf_x86_link_hash_table
*) bfd_zmalloc (amt
);
711 bed
= get_elf_backend_data (abfd
);
712 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
713 _bfd_x86_elf_link_hash_newfunc
,
714 sizeof (struct elf_x86_link_hash_entry
),
721 if (bed
->target_id
== X86_64_ELF_DATA
)
723 ret
->is_reloc_section
= elf_x86_64_is_reloc_section
;
724 ret
->got_entry_size
= 8;
725 ret
->pcrel_plt
= true;
726 ret
->tls_get_addr
= "__tls_get_addr";
730 ret
->sizeof_reloc
= sizeof (Elf64_External_Rela
);
731 ret
->pointer_r_type
= R_X86_64_64
;
732 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
733 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
737 if (bed
->target_id
== X86_64_ELF_DATA
)
739 ret
->sizeof_reloc
= sizeof (Elf32_External_Rela
);
740 ret
->pointer_r_type
= R_X86_64_32
;
741 ret
->dynamic_interpreter
= ELFX32_DYNAMIC_INTERPRETER
;
742 ret
->dynamic_interpreter_size
743 = sizeof ELFX32_DYNAMIC_INTERPRETER
;
747 ret
->is_reloc_section
= elf_i386_is_reloc_section
;
748 ret
->sizeof_reloc
= sizeof (Elf32_External_Rel
);
749 ret
->got_entry_size
= 4;
750 ret
->pcrel_plt
= false;
751 ret
->pointer_r_type
= R_386_32
;
752 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
753 ret
->dynamic_interpreter_size
754 = sizeof ELF32_DYNAMIC_INTERPRETER
;
755 ret
->tls_get_addr
= "___tls_get_addr";
759 ret
->loc_hash_table
= htab_try_create (1024,
760 _bfd_x86_elf_local_htab_hash
,
761 _bfd_x86_elf_local_htab_eq
,
763 ret
->loc_hash_memory
= objalloc_create ();
764 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
766 elf_x86_link_hash_table_free (abfd
);
769 ret
->elf
.root
.hash_table_free
= elf_x86_link_hash_table_free
;
771 return &ret
->elf
.root
;
774 /* Sort relocs into address order. */
777 _bfd_x86_elf_compare_relocs (const void *ap
, const void *bp
)
779 const arelent
*a
= * (const arelent
**) ap
;
780 const arelent
*b
= * (const arelent
**) bp
;
782 if (a
->address
> b
->address
)
784 else if (a
->address
< b
->address
)
790 /* Mark symbol, NAME, as locally defined by linker if it is referenced
791 and not defined in a relocatable object file. */
794 elf_x86_linker_defined (struct bfd_link_info
*info
, const char *name
)
796 struct elf_link_hash_entry
*h
;
798 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
799 false, false, false);
803 while (h
->root
.type
== bfd_link_hash_indirect
)
804 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
806 if (h
->root
.type
== bfd_link_hash_new
807 || h
->root
.type
== bfd_link_hash_undefined
808 || h
->root
.type
== bfd_link_hash_undefweak
809 || h
->root
.type
== bfd_link_hash_common
810 || (!h
->def_regular
&& h
->def_dynamic
))
812 elf_x86_hash_entry (h
)->local_ref
= 2;
813 elf_x86_hash_entry (h
)->linker_def
= 1;
817 /* Hide a linker-defined symbol, NAME, with hidden visibility. */
820 elf_x86_hide_linker_defined (struct bfd_link_info
*info
,
823 struct elf_link_hash_entry
*h
;
825 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
826 false, false, false);
830 while (h
->root
.type
== bfd_link_hash_indirect
)
831 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
833 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
834 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
835 _bfd_elf_link_hash_hide_symbol (info
, h
, true);
839 _bfd_x86_elf_link_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
)
841 if (!bfd_link_relocatable (info
))
843 /* Check for __tls_get_addr reference. */
844 struct elf_x86_link_hash_table
*htab
;
845 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
846 htab
= elf_x86_hash_table (info
, bed
->target_id
);
849 struct elf_link_hash_entry
*h
;
851 h
= elf_link_hash_lookup (elf_hash_table (info
),
853 false, false, false);
856 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
858 /* Check the versioned __tls_get_addr symbol. */
859 while (h
->root
.type
== bfd_link_hash_indirect
)
861 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
862 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
866 /* "__ehdr_start" will be defined by linker as a hidden symbol
867 later if it is referenced and not defined. */
868 elf_x86_linker_defined (info
, "__ehdr_start");
870 if (bfd_link_executable (info
))
872 /* References to __bss_start, _end and _edata should be
873 locally resolved within executables. */
874 elf_x86_linker_defined (info
, "__bss_start");
875 elf_x86_linker_defined (info
, "_end");
876 elf_x86_linker_defined (info
, "_edata");
880 /* Hide hidden __bss_start, _end and _edata in shared
882 elf_x86_hide_linker_defined (info
, "__bss_start");
883 elf_x86_hide_linker_defined (info
, "_end");
884 elf_x86_hide_linker_defined (info
, "_edata");
889 /* Invoke the regular ELF backend linker to do all the work. */
890 return _bfd_elf_link_check_relocs (abfd
, info
);
894 _bfd_elf_x86_valid_reloc_p (asection
*input_section
,
895 struct bfd_link_info
*info
,
896 struct elf_x86_link_hash_table
*htab
,
897 const Elf_Internal_Rela
*rel
,
898 struct elf_link_hash_entry
*h
,
899 Elf_Internal_Sym
*sym
,
900 Elf_Internal_Shdr
*symtab_hdr
,
905 *no_dynreloc_p
= false;
907 /* Check If relocation against non-preemptible absolute symbol is
908 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
909 it may call _bfd_elf_link_hide_sym_by_version and result in
910 ld-elfvers/ vers21 test failure. */
911 if (bfd_link_pic (info
)
912 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
914 const struct elf_backend_data
*bed
;
916 Elf_Internal_Rela irel
;
918 /* Skip non-absolute symbol. */
921 if (!ABS_SYMBOL_P (h
))
924 else if (sym
->st_shndx
!= SHN_ABS
)
927 bed
= get_elf_backend_data (input_section
->owner
);
928 r_type
= ELF32_R_TYPE (rel
->r_info
);
931 /* Only allow relocations against absolute symbol, which can be
932 resolved as absolute value + addend. GOTPCREL relocations
933 are allowed since absolute value + addend is stored in the
935 if (bed
->target_id
== X86_64_ELF_DATA
)
937 r_type
&= ~R_X86_64_converted_reloc_bit
;
938 valid_p
= (r_type
== R_X86_64_64
939 || r_type
== R_X86_64_32
940 || r_type
== R_X86_64_32S
941 || r_type
== R_X86_64_16
942 || r_type
== R_X86_64_8
943 || r_type
== R_X86_64_GOTPCREL
944 || r_type
== R_X86_64_GOTPCRELX
945 || r_type
== R_X86_64_REX_GOTPCRELX
);
948 unsigned int r_symndx
= htab
->r_sym (rel
->r_info
);
949 irel
.r_info
= htab
->r_info (r_symndx
, r_type
);
953 valid_p
= (r_type
== R_386_32
954 || r_type
== R_386_16
955 || r_type
== R_386_8
);
958 *no_dynreloc_p
= true;
962 arelent internal_reloc
;
964 if (!bed
->elf_info_to_howto (input_section
->owner
,
965 &internal_reloc
, &irel
)
966 || internal_reloc
.howto
== NULL
)
970 name
= h
->root
.root
.string
;
972 name
= bfd_elf_sym_name (input_section
->owner
, symtab_hdr
,
974 info
->callbacks
->einfo
975 /* xgettext:c-format */
976 (_("%F%P: %pB: relocation %s against absolute symbol "
977 "`%s' in section `%pA' is disallowed\n"),
978 input_section
->owner
, internal_reloc
.howto
->name
, name
,
980 bfd_set_error (bfd_error_bad_value
);
987 /* Set the sizes of the dynamic sections. */
990 _bfd_x86_elf_size_dynamic_sections (bfd
*output_bfd
,
991 struct bfd_link_info
*info
)
993 struct elf_x86_link_hash_table
*htab
;
998 const struct elf_backend_data
*bed
999 = get_elf_backend_data (output_bfd
);
1001 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1004 dynobj
= htab
->elf
.dynobj
;
1008 /* Set up .got offsets for local syms, and space for local dynamic
1010 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1012 bfd_signed_vma
*local_got
;
1013 bfd_signed_vma
*end_local_got
;
1014 char *local_tls_type
;
1015 bfd_vma
*local_tlsdesc_gotent
;
1016 bfd_size_type locsymcount
;
1017 Elf_Internal_Shdr
*symtab_hdr
;
1020 if (! is_x86_elf (ibfd
, htab
))
1023 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1025 struct elf_dyn_relocs
*p
;
1027 for (p
= ((struct elf_dyn_relocs
*)
1028 elf_section_data (s
)->local_dynrel
);
1032 if (!bfd_is_abs_section (p
->sec
)
1033 && bfd_is_abs_section (p
->sec
->output_section
))
1035 /* Input section has been discarded, either because
1036 it is a copy of a linkonce section or due to
1037 linker script /DISCARD/, so we'll be discarding
1040 else if (htab
->elf
.target_os
== is_vxworks
1041 && strcmp (p
->sec
->output_section
->name
,
1044 /* Relocations in vxworks .tls_vars sections are
1045 handled specially by the loader. */
1047 else if (p
->count
!= 0)
1049 srel
= elf_section_data (p
->sec
)->sreloc
;
1050 srel
->size
+= p
->count
* htab
->sizeof_reloc
;
1051 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
1052 && (info
->flags
& DF_TEXTREL
) == 0)
1054 info
->flags
|= DF_TEXTREL
;
1055 if (bfd_link_textrel_check (info
))
1056 /* xgettext:c-format */
1057 info
->callbacks
->einfo
1058 (_("%P: %pB: warning: relocation "
1059 "in read-only section `%pA'\n"),
1060 p
->sec
->owner
, p
->sec
);
1066 local_got
= elf_local_got_refcounts (ibfd
);
1070 symtab_hdr
= &elf_symtab_hdr (ibfd
);
1071 locsymcount
= symtab_hdr
->sh_info
;
1072 end_local_got
= local_got
+ locsymcount
;
1073 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
1074 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
1076 srel
= htab
->elf
.srelgot
;
1077 for (; local_got
< end_local_got
;
1078 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1080 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1083 if (GOT_TLS_GDESC_P (*local_tls_type
))
1085 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
1086 - elf_x86_compute_jump_table_size (htab
);
1087 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
1088 *local_got
= (bfd_vma
) -2;
1090 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1091 || GOT_TLS_GD_P (*local_tls_type
))
1093 *local_got
= s
->size
;
1094 s
->size
+= htab
->got_entry_size
;
1095 if (GOT_TLS_GD_P (*local_tls_type
)
1096 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1097 s
->size
+= htab
->got_entry_size
;
1099 if ((bfd_link_pic (info
) && *local_tls_type
!= GOT_ABS
)
1100 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1101 || (*local_tls_type
& GOT_TLS_IE
))
1103 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1104 srel
->size
+= 2 * htab
->sizeof_reloc
;
1105 else if (GOT_TLS_GD_P (*local_tls_type
)
1106 || ! GOT_TLS_GDESC_P (*local_tls_type
))
1107 srel
->size
+= htab
->sizeof_reloc
;
1108 if (GOT_TLS_GDESC_P (*local_tls_type
))
1110 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
1111 if (bed
->target_id
== X86_64_ELF_DATA
)
1112 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
1117 *local_got
= (bfd_vma
) -1;
1121 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
1123 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1124 or R_X86_64_TLSLD relocs. */
1125 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
1126 htab
->elf
.sgot
->size
+= 2 * htab
->got_entry_size
;
1127 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
1130 htab
->tls_ld_or_ldm_got
.offset
= -1;
1132 /* Allocate global sym .plt and .got entries, and space for global
1133 sym dynamic relocs. */
1134 elf_link_hash_traverse (&htab
->elf
, elf_x86_allocate_dynrelocs
,
1137 /* Allocate .plt and .got entries, and space for local symbols. */
1138 htab_traverse (htab
->loc_hash_table
, elf_x86_allocate_local_dynreloc
,
1141 /* For every jump slot reserved in the sgotplt, reloc_count is
1142 incremented. However, when we reserve space for TLS descriptors,
1143 it's not incremented, so in order to compute the space reserved
1144 for them, it suffices to multiply the reloc count by the jump
1147 PR ld/13302: We start next_irelative_index at the end of .rela.plt
1148 so that R_{386,X86_64}_IRELATIVE entries come last. */
1149 if (htab
->elf
.srelplt
)
1151 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
1152 htab
->sgotplt_jump_table_size
1153 = elf_x86_compute_jump_table_size (htab
);
1154 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
1156 else if (htab
->elf
.irelplt
)
1157 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
1159 if (htab
->elf
.tlsdesc_plt
)
1161 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
1162 lazy TLS relocations, don't generate the PLT and GOT entries
1164 if ((info
->flags
& DF_BIND_NOW
))
1165 htab
->elf
.tlsdesc_plt
= 0;
1168 htab
->elf
.tlsdesc_got
= htab
->elf
.sgot
->size
;
1169 htab
->elf
.sgot
->size
+= htab
->got_entry_size
;
1170 /* Reserve room for the initial entry.
1171 FIXME: we could probably do away with it in this case. */
1172 if (htab
->elf
.splt
->size
== 0)
1173 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
1174 htab
->elf
.tlsdesc_plt
= htab
->elf
.splt
->size
;
1175 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
1179 if (htab
->elf
.sgotplt
)
1181 /* Don't allocate .got.plt section if there are no GOT nor PLT
1182 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
1183 if ((htab
->elf
.hgot
== NULL
1184 || !htab
->got_referenced
)
1185 && (htab
->elf
.sgotplt
->size
== bed
->got_header_size
)
1186 && (htab
->elf
.splt
== NULL
1187 || htab
->elf
.splt
->size
== 0)
1188 && (htab
->elf
.sgot
== NULL
1189 || htab
->elf
.sgot
->size
== 0)
1190 && (htab
->elf
.iplt
== NULL
1191 || htab
->elf
.iplt
->size
== 0)
1192 && (htab
->elf
.igotplt
== NULL
1193 || htab
->elf
.igotplt
->size
== 0))
1195 htab
->elf
.sgotplt
->size
= 0;
1196 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
1198 if (htab
->elf
.hgot
!= NULL
1199 && htab
->elf
.target_os
!= is_solaris
)
1201 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
1203 htab
->elf
.hgot
->root
.type
= bfd_link_hash_undefined
;
1204 htab
->elf
.hgot
->root
.u
.undef
.abfd
1205 = htab
->elf
.hgot
->root
.u
.def
.section
->owner
;
1206 htab
->elf
.hgot
->root
.linker_def
= 0;
1207 htab
->elf
.hgot
->ref_regular
= 0;
1208 htab
->elf
.hgot
->def_regular
= 0;
1213 if (_bfd_elf_eh_frame_present (info
))
1215 if (htab
->plt_eh_frame
!= NULL
1216 && htab
->elf
.splt
!= NULL
1217 && htab
->elf
.splt
->size
!= 0
1218 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
1219 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
1221 if (htab
->plt_got_eh_frame
!= NULL
1222 && htab
->plt_got
!= NULL
1223 && htab
->plt_got
->size
!= 0
1224 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
1225 htab
->plt_got_eh_frame
->size
1226 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1228 /* Unwind info for the second PLT and .plt.got sections are
1230 if (htab
->plt_second_eh_frame
!= NULL
1231 && htab
->plt_second
!= NULL
1232 && htab
->plt_second
->size
!= 0
1233 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
1234 htab
->plt_second_eh_frame
->size
1235 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1238 /* We now have determined the sizes of the various dynamic sections.
1239 Allocate memory for them. */
1241 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1243 bool strip_section
= true;
1245 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1248 if (s
== htab
->elf
.splt
1249 || s
== htab
->elf
.sgot
)
1251 /* Strip this section if we don't need it; see the
1253 /* We'd like to strip these sections if they aren't needed, but if
1254 we've exported dynamic symbols from them we must leave them.
1255 It's too late to tell BFD to get rid of the symbols. */
1257 if (htab
->elf
.hplt
!= NULL
)
1258 strip_section
= false;
1260 else if (s
== htab
->elf
.sgotplt
1261 || s
== htab
->elf
.iplt
1262 || s
== htab
->elf
.igotplt
1263 || s
== htab
->plt_second
1264 || s
== htab
->plt_got
1265 || s
== htab
->plt_eh_frame
1266 || s
== htab
->plt_got_eh_frame
1267 || s
== htab
->plt_second_eh_frame
1268 || s
== htab
->elf
.sdynbss
1269 || s
== htab
->elf
.sdynrelro
)
1271 /* Strip these too. */
1273 else if (htab
->is_reloc_section (bfd_section_name (s
)))
1276 && s
!= htab
->elf
.srelplt
1277 && s
!= htab
->srelplt2
)
1280 /* We use the reloc_count field as a counter if we need
1281 to copy relocs into the output file. */
1282 if (s
!= htab
->elf
.srelplt
)
1287 /* It's not one of our sections, so don't allocate space. */
1293 /* If we don't need this section, strip it from the
1294 output file. This is mostly to handle .rel.bss and
1295 .rel.plt. We must create both sections in
1296 create_dynamic_sections, because they must be created
1297 before the linker maps input sections to output
1298 sections. The linker does that before
1299 adjust_dynamic_symbol is called, and it is that
1300 function which decides whether anything needs to go
1301 into these sections. */
1303 s
->flags
|= SEC_EXCLUDE
;
1307 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1310 /* NB: Initially, the iplt section has minimal alignment to
1311 avoid moving dot of the following section backwards when
1312 it is empty. Update its section alignment now since it
1314 if (s
== htab
->elf
.iplt
)
1315 bfd_set_section_alignment (s
, htab
->plt
.iplt_alignment
);
1317 /* Allocate memory for the section contents. We use bfd_zalloc
1318 here in case unused entries are not reclaimed before the
1319 section's contents are written out. This should not happen,
1320 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
1321 reloc instead of garbage. */
1322 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
1323 if (s
->contents
== NULL
)
1327 if (htab
->plt_eh_frame
!= NULL
1328 && htab
->plt_eh_frame
->contents
!= NULL
)
1330 memcpy (htab
->plt_eh_frame
->contents
,
1331 htab
->plt
.eh_frame_plt
,
1332 htab
->plt_eh_frame
->size
);
1333 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
1334 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
1337 if (htab
->plt_got_eh_frame
!= NULL
1338 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1340 memcpy (htab
->plt_got_eh_frame
->contents
,
1341 htab
->non_lazy_plt
->eh_frame_plt
,
1342 htab
->plt_got_eh_frame
->size
);
1343 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
1344 (htab
->plt_got_eh_frame
->contents
1345 + PLT_FDE_LEN_OFFSET
));
1348 if (htab
->plt_second_eh_frame
!= NULL
1349 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1351 memcpy (htab
->plt_second_eh_frame
->contents
,
1352 htab
->non_lazy_plt
->eh_frame_plt
,
1353 htab
->plt_second_eh_frame
->size
);
1354 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
1355 (htab
->plt_second_eh_frame
->contents
1356 + PLT_FDE_LEN_OFFSET
));
1359 return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd
, info
,
1363 /* Finish up the x86 dynamic sections. */
1365 struct elf_x86_link_hash_table
*
1366 _bfd_x86_elf_finish_dynamic_sections (bfd
*output_bfd
,
1367 struct bfd_link_info
*info
)
1369 struct elf_x86_link_hash_table
*htab
;
1370 const struct elf_backend_data
*bed
;
1373 bfd_byte
*dyncon
, *dynconend
;
1374 bfd_size_type sizeof_dyn
;
1376 bed
= get_elf_backend_data (output_bfd
);
1377 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1381 dynobj
= htab
->elf
.dynobj
;
1382 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
1384 /* GOT is always created in setup_gnu_properties. But it may not be
1385 needed. .got.plt section may be needed for static IFUNC. */
1386 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
1388 bfd_vma dynamic_addr
;
1390 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
1393 (_("discarded output section: `%pA'"), htab
->elf
.sgotplt
);
1397 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
1398 = htab
->got_entry_size
;
1400 dynamic_addr
= (sdyn
== NULL
1402 : sdyn
->output_section
->vma
+ sdyn
->output_offset
);
1404 /* Set the first entry in the global offset table to the address
1405 of the dynamic section. Write GOT[1] and GOT[2], needed for
1406 the dynamic linker. */
1407 if (htab
->got_entry_size
== 8)
1409 bfd_put_64 (output_bfd
, dynamic_addr
,
1410 htab
->elf
.sgotplt
->contents
);
1411 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1412 htab
->elf
.sgotplt
->contents
+ 8);
1413 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1414 htab
->elf
.sgotplt
->contents
+ 8*2);
1418 bfd_put_32 (output_bfd
, dynamic_addr
,
1419 htab
->elf
.sgotplt
->contents
);
1420 bfd_put_32 (output_bfd
, 0,
1421 htab
->elf
.sgotplt
->contents
+ 4);
1422 bfd_put_32 (output_bfd
, 0,
1423 htab
->elf
.sgotplt
->contents
+ 4*2);
1427 if (!htab
->elf
.dynamic_sections_created
)
1430 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
1433 sizeof_dyn
= bed
->s
->sizeof_dyn
;
1434 dyncon
= sdyn
->contents
;
1435 dynconend
= sdyn
->contents
+ sdyn
->size
;
1436 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
1438 Elf_Internal_Dyn dyn
;
1441 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
1446 if (htab
->elf
.target_os
== is_vxworks
1447 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
1452 s
= htab
->elf
.sgotplt
;
1453 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
1457 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
1461 s
= htab
->elf
.srelplt
->output_section
;
1462 dyn
.d_un
.d_val
= s
->size
;
1465 case DT_TLSDESC_PLT
:
1467 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1468 + htab
->elf
.tlsdesc_plt
;
1471 case DT_TLSDESC_GOT
:
1473 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1474 + htab
->elf
.tlsdesc_got
;
1478 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
1481 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
1482 elf_section_data (htab
->plt_got
->output_section
)
1483 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1485 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
1486 elf_section_data (htab
->plt_second
->output_section
)
1487 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1489 /* Adjust .eh_frame for .plt section. */
1490 if (htab
->plt_eh_frame
!= NULL
1491 && htab
->plt_eh_frame
->contents
!= NULL
)
1493 if (htab
->elf
.splt
!= NULL
1494 && htab
->elf
.splt
->size
!= 0
1495 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
1496 && htab
->elf
.splt
->output_section
!= NULL
1497 && htab
->plt_eh_frame
->output_section
!= NULL
)
1499 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
1500 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
1501 + htab
->plt_eh_frame
->output_offset
1502 + PLT_FDE_START_OFFSET
;
1503 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1504 htab
->plt_eh_frame
->contents
1505 + PLT_FDE_START_OFFSET
);
1508 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1510 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1512 htab
->plt_eh_frame
->contents
))
1517 /* Adjust .eh_frame for .plt.got section. */
1518 if (htab
->plt_got_eh_frame
!= NULL
1519 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1521 if (htab
->plt_got
!= NULL
1522 && htab
->plt_got
->size
!= 0
1523 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
1524 && htab
->plt_got
->output_section
!= NULL
1525 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
1527 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
1528 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
1529 + htab
->plt_got_eh_frame
->output_offset
1530 + PLT_FDE_START_OFFSET
;
1531 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1532 htab
->plt_got_eh_frame
->contents
1533 + PLT_FDE_START_OFFSET
);
1535 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1537 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1538 htab
->plt_got_eh_frame
,
1539 htab
->plt_got_eh_frame
->contents
))
1544 /* Adjust .eh_frame for the second PLT section. */
1545 if (htab
->plt_second_eh_frame
!= NULL
1546 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1548 if (htab
->plt_second
!= NULL
1549 && htab
->plt_second
->size
!= 0
1550 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
1551 && htab
->plt_second
->output_section
!= NULL
1552 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
1554 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
1555 bfd_vma eh_frame_start
1556 = (htab
->plt_second_eh_frame
->output_section
->vma
1557 + htab
->plt_second_eh_frame
->output_offset
1558 + PLT_FDE_START_OFFSET
);
1559 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1560 htab
->plt_second_eh_frame
->contents
1561 + PLT_FDE_START_OFFSET
);
1563 if (htab
->plt_second_eh_frame
->sec_info_type
1564 == SEC_INFO_TYPE_EH_FRAME
)
1566 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1567 htab
->plt_second_eh_frame
,
1568 htab
->plt_second_eh_frame
->contents
))
1573 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
1574 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
1575 = htab
->got_entry_size
;
1582 _bfd_x86_elf_always_size_sections (bfd
*output_bfd
,
1583 struct bfd_link_info
*info
)
1585 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
1589 struct elf_link_hash_entry
*tlsbase
;
1591 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
1592 "_TLS_MODULE_BASE_",
1593 false, false, false);
1595 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
1597 struct elf_x86_link_hash_table
*htab
;
1598 struct bfd_link_hash_entry
*bh
= NULL
;
1599 const struct elf_backend_data
*bed
1600 = get_elf_backend_data (output_bfd
);
1602 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1606 if (!(_bfd_generic_link_add_one_symbol
1607 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
1608 tls_sec
, 0, NULL
, false,
1609 bed
->collect
, &bh
)))
1612 htab
->tls_module_base
= bh
;
1614 tlsbase
= (struct elf_link_hash_entry
*)bh
;
1615 tlsbase
->def_regular
= 1;
1616 tlsbase
->other
= STV_HIDDEN
;
1617 tlsbase
->root
.linker_def
= 1;
1618 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, true);
1626 _bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
1627 unsigned int st_other
,
1629 bool dynamic ATTRIBUTE_UNUSED
)
1633 struct elf_x86_link_hash_entry
*eh
1634 = (struct elf_x86_link_hash_entry
*) h
;
1635 eh
->def_protected
= ELF_ST_VISIBILITY (st_other
) == STV_PROTECTED
;
1639 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1642 _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
1643 struct elf_link_hash_entry
*dir
,
1644 struct elf_link_hash_entry
*ind
)
1646 struct elf_x86_link_hash_entry
*edir
, *eind
;
1648 edir
= (struct elf_x86_link_hash_entry
*) dir
;
1649 eind
= (struct elf_x86_link_hash_entry
*) ind
;
1651 if (ind
->root
.type
== bfd_link_hash_indirect
1652 && dir
->got
.refcount
<= 0)
1654 edir
->tls_type
= eind
->tls_type
;
1655 eind
->tls_type
= GOT_UNKNOWN
;
1658 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1659 generate a R_386_COPY reloc. */
1660 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1662 edir
->zero_undefweak
|= eind
->zero_undefweak
;
1664 if (ELIMINATE_COPY_RELOCS
1665 && ind
->root
.type
!= bfd_link_hash_indirect
1666 && dir
->dynamic_adjusted
)
1668 /* If called to transfer flags for a weakdef during processing
1669 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1670 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1671 if (dir
->versioned
!= versioned_hidden
)
1672 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1673 dir
->ref_regular
|= ind
->ref_regular
;
1674 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1675 dir
->needs_plt
|= ind
->needs_plt
;
1676 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1679 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1682 /* Remove undefined weak symbol from the dynamic symbol table if it
1683 is resolved to 0. */
1686 _bfd_x86_elf_fixup_symbol (struct bfd_link_info
*info
,
1687 struct elf_link_hash_entry
*h
)
1689 if (h
->dynindx
!= -1
1690 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, elf_x86_hash_entry (h
)))
1693 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1699 /* Change the STT_GNU_IFUNC symbol defined in position-dependent
1700 executable into the normal function symbol and set its address
1701 to its PLT entry, which should be resolved by R_*_IRELATIVE at
1705 _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info
*info
,
1706 struct elf_x86_link_hash_table
*htab
,
1707 struct elf_link_hash_entry
*h
,
1708 Elf_Internal_Sym
*sym
)
1710 if (bfd_link_pde (info
)
1713 && h
->plt
.offset
!= (bfd_vma
) -1
1714 && h
->type
== STT_GNU_IFUNC
)
1718 bfd
*output_bfd
= info
->output_bfd
;
1720 if (htab
->plt_second
)
1722 struct elf_x86_link_hash_entry
*eh
1723 = (struct elf_x86_link_hash_entry
*) h
;
1725 plt_s
= htab
->plt_second
;
1726 plt_offset
= eh
->plt_second
.offset
;
1730 plt_s
= htab
->elf
.splt
;
1731 plt_offset
= h
->plt
.offset
;
1735 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
1737 = _bfd_elf_section_from_bfd_section (output_bfd
,
1738 plt_s
->output_section
);
1739 sym
->st_value
= (plt_s
->output_section
->vma
1740 + plt_s
->output_offset
+ plt_offset
);
1744 /* Report relative relocation. */
1747 _bfd_x86_elf_link_report_relative_reloc
1748 (struct bfd_link_info
*info
, asection
*asect
,
1749 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
,
1750 const char *reloc_name
, const void *reloc
)
1754 const Elf_Internal_Rela
*rel
= (const Elf_Internal_Rela
*) reloc
;
1755 char r_offset
[30], r_info
[30];
1757 /* Use the output BFD for linker created sections. */
1758 if ((asect
->flags
& SEC_LINKER_CREATED
) != 0)
1759 abfd
= info
->output_bfd
;
1761 abfd
= asect
->owner
;
1763 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1764 name
= h
->root
.root
.string
;
1766 name
= bfd_elf_sym_name (abfd
, &elf_symtab_hdr (abfd
), sym
, NULL
);
1768 bfd_sprintf_vma (abfd
, r_offset
, rel
->r_offset
);
1769 bfd_sprintf_vma (abfd
, r_info
, rel
->r_info
);
1771 if (asect
->use_rela_p
)
1775 bfd_sprintf_vma (abfd
, r_addend
, rel
->r_addend
);
1777 info
->callbacks
->einfo
1778 (_("%pB: %s (offset: 0x%s, info: 0x%s, addend: 0x%s) against "
1779 "'%s' " "for section '%pA' in %pB\n"),
1780 info
->output_bfd
, reloc_name
, r_offset
, r_info
, r_addend
,
1784 info
->callbacks
->einfo
1785 (_("%pB: %s (offset: 0x%s, info: 0x%s) against '%s' for section "
1787 info
->output_bfd
, reloc_name
, r_offset
, r_info
, name
,
1791 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
1794 _bfd_x86_elf_hash_symbol (struct elf_link_hash_entry
*h
)
1796 if (h
->plt
.offset
!= (bfd_vma
) -1
1798 && !h
->pointer_equality_needed
)
1801 return _bfd_elf_hash_symbol (h
);
1804 /* Adjust a symbol defined by a dynamic object and referenced by a
1805 regular object. The current definition is in some section of the
1806 dynamic object, but we're not including those sections. We have to
1807 change the definition to something the rest of the link can
1811 _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1812 struct elf_link_hash_entry
*h
)
1814 struct elf_x86_link_hash_table
*htab
;
1816 struct elf_x86_link_hash_entry
*eh
;
1817 struct elf_dyn_relocs
*p
;
1818 const struct elf_backend_data
*bed
1819 = get_elf_backend_data (info
->output_bfd
);
1821 /* STT_GNU_IFUNC symbol must go through PLT. */
1822 if (h
->type
== STT_GNU_IFUNC
)
1824 /* All local STT_GNU_IFUNC references must be treate as local
1825 calls via local PLT. */
1827 && SYMBOL_CALLS_LOCAL (info
, h
))
1829 bfd_size_type pc_count
= 0, count
= 0;
1830 struct elf_dyn_relocs
**pp
;
1832 eh
= (struct elf_x86_link_hash_entry
*) h
;
1833 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
1835 pc_count
+= p
->pc_count
;
1836 p
->count
-= p
->pc_count
;
1845 if (pc_count
|| count
)
1850 /* Increment PLT reference count only for PC-relative
1853 if (h
->plt
.refcount
<= 0)
1854 h
->plt
.refcount
= 1;
1856 h
->plt
.refcount
+= 1;
1861 if (h
->plt
.refcount
<= 0)
1863 h
->plt
.offset
= (bfd_vma
) -1;
1869 /* If this is a function, put it in the procedure linkage table. We
1870 will fill in the contents of the procedure linkage table later,
1871 when we know the address of the .got section. */
1872 if (h
->type
== STT_FUNC
1875 if (h
->plt
.refcount
<= 0
1876 || SYMBOL_CALLS_LOCAL (info
, h
)
1877 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1878 && h
->root
.type
== bfd_link_hash_undefweak
))
1880 /* This case can occur if we saw a PLT32 reloc in an input
1881 file, but the symbol was never referred to by a dynamic
1882 object, or if all references were garbage collected. In
1883 such a case, we don't actually need to build a procedure
1884 linkage table, and we can just do a PC32 reloc instead. */
1885 h
->plt
.offset
= (bfd_vma
) -1;
1892 /* It's possible that we incorrectly decided a .plt reloc was needed
1893 * for an R_386_PC32/R_X86_64_PC32 reloc to a non-function sym in
1894 check_relocs. We can't decide accurately between function and
1895 non-function syms in check-relocs; Objects loaded later in
1896 the link may change h->type. So fix it now. */
1897 h
->plt
.offset
= (bfd_vma
) -1;
1899 eh
= (struct elf_x86_link_hash_entry
*) h
;
1901 /* If this is a weak symbol, and there is a real definition, the
1902 processor independent code will have arranged for us to see the
1903 real definition first, and we can just use the same value. */
1904 if (h
->is_weakalias
)
1906 struct elf_link_hash_entry
*def
= weakdef (h
);
1907 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1908 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1909 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1910 if (ELIMINATE_COPY_RELOCS
1911 || info
->nocopyreloc
1912 || SYMBOL_NO_COPYRELOC (info
, eh
))
1914 /* NB: needs_copy is always 0 for i386. */
1915 h
->non_got_ref
= def
->non_got_ref
;
1916 eh
->needs_copy
= def
->needs_copy
;
1921 /* This is a reference to a symbol defined by a dynamic object which
1922 is not a function. */
1924 /* If we are creating a shared library, we must presume that the
1925 only references to the symbol are via the global offset table.
1926 For such cases we need not do anything here; the relocations will
1927 be handled correctly by relocate_section. */
1928 if (!bfd_link_executable (info
))
1931 /* If there are no references to this symbol that do not use the
1932 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
1933 reloc. NB: gotoff_ref is always 0 for x86-64. */
1934 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
1937 /* If -z nocopyreloc was given, we won't generate them either. */
1938 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
1944 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1948 /* If there aren't any dynamic relocs in read-only sections nor
1949 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
1950 avoid the copy reloc. This doesn't work on VxWorks, where we can
1951 not have dynamic relocations (other than copy and jump slot
1952 relocations) in an executable. */
1953 if (ELIMINATE_COPY_RELOCS
1954 && (bed
->target_id
== X86_64_ELF_DATA
1956 && htab
->elf
.target_os
!= is_vxworks
)))
1958 /* If we don't find any dynamic relocs in read-only sections,
1959 then we'll be keeping the dynamic relocs and avoiding the copy
1961 if (!_bfd_elf_readonly_dynrelocs (h
))
1968 /* We must allocate the symbol in our .dynbss section, which will
1969 become part of the .bss section of the executable. There will be
1970 an entry for this symbol in the .dynsym section. The dynamic
1971 object will contain position independent code, so all references
1972 from the dynamic object to this symbol will go through the global
1973 offset table. The dynamic linker will use the .dynsym entry to
1974 determine the address it must put in the global offset table, so
1975 both the dynamic object and the regular object will refer to the
1976 same memory location for the variable. */
1978 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
1979 dynamic linker to copy the initial value out of the dynamic object
1980 and into the runtime process image. */
1981 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
1983 s
= htab
->elf
.sdynrelro
;
1984 srel
= htab
->elf
.sreldynrelro
;
1988 s
= htab
->elf
.sdynbss
;
1989 srel
= htab
->elf
.srelbss
;
1991 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
1993 srel
->size
+= htab
->sizeof_reloc
;
1997 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2001 _bfd_x86_elf_hide_symbol (struct bfd_link_info
*info
,
2002 struct elf_link_hash_entry
*h
,
2005 if (h
->root
.type
== bfd_link_hash_undefweak
2007 && bfd_link_pie (info
))
2009 /* When there is no dynamic interpreter in PIE, make the undefined
2010 weak symbol dynamic so that PC relative branch to the undefined
2011 weak symbol will land to address 0. */
2012 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2013 if (h
->plt
.refcount
> 0
2014 || eh
->plt_got
.refcount
> 0)
2018 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
2021 /* Return TRUE if a symbol is referenced locally. It is similar to
2022 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
2023 works in check_relocs. */
2026 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info
*info
,
2027 struct elf_link_hash_entry
*h
)
2029 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2030 struct elf_x86_link_hash_table
*htab
2031 = (struct elf_x86_link_hash_table
*) info
->hash
;
2033 if (eh
->local_ref
> 1)
2036 if (eh
->local_ref
== 1)
2039 /* Unversioned symbols defined in regular objects can be forced local
2040 by linker version script. A weak undefined symbol is forced local
2042 1. It has non-default visibility. Or
2043 2. When building executable, there is no dynamic linker. Or
2044 3. or "-z nodynamic-undefined-weak" is used.
2046 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
2047 || (h
->root
.type
== bfd_link_hash_undefweak
2048 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2049 || (bfd_link_executable (info
)
2050 && htab
->interp
== NULL
)
2051 || info
->dynamic_undefined_weak
== 0))
2052 || ((h
->def_regular
|| ELF_COMMON_DEF_P (h
))
2053 && info
->version_info
!= NULL
2054 && _bfd_elf_link_hide_sym_by_version (info
, h
)))
2064 /* Return the section that should be marked against GC for a given
2068 _bfd_x86_elf_gc_mark_hook (asection
*sec
,
2069 struct bfd_link_info
*info
,
2070 Elf_Internal_Rela
*rel
,
2071 struct elf_link_hash_entry
*h
,
2072 Elf_Internal_Sym
*sym
)
2074 /* Compiler should optimize this out. */
2075 if (((unsigned int) R_X86_64_GNU_VTINHERIT
2076 != (unsigned int) R_386_GNU_VTINHERIT
)
2077 || ((unsigned int) R_X86_64_GNU_VTENTRY
2078 != (unsigned int) R_386_GNU_VTENTRY
))
2082 switch (ELF32_R_TYPE (rel
->r_info
))
2084 case R_X86_64_GNU_VTINHERIT
:
2085 case R_X86_64_GNU_VTENTRY
:
2089 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2093 elf_i386_get_plt_got_vma (struct elf_x86_plt
*plt_p ATTRIBUTE_UNUSED
,
2095 bfd_vma offset ATTRIBUTE_UNUSED
,
2098 return got_addr
+ off
;
2102 elf_x86_64_get_plt_got_vma (struct elf_x86_plt
*plt_p
,
2105 bfd_vma got_addr ATTRIBUTE_UNUSED
)
2107 return plt_p
->sec
->vma
+ offset
+ off
+ plt_p
->plt_got_insn_size
;
2111 elf_i386_valid_plt_reloc_p (unsigned int type
)
2113 return (type
== R_386_JUMP_SLOT
2114 || type
== R_386_GLOB_DAT
2115 || type
== R_386_IRELATIVE
);
2119 elf_x86_64_valid_plt_reloc_p (unsigned int type
)
2121 return (type
== R_X86_64_JUMP_SLOT
2122 || type
== R_X86_64_GLOB_DAT
2123 || type
== R_X86_64_IRELATIVE
);
2127 _bfd_x86_elf_get_synthetic_symtab (bfd
*abfd
,
2131 struct elf_x86_plt plts
[],
2135 long size
, i
, n
, len
;
2137 unsigned int plt_got_offset
, plt_entry_size
;
2139 bfd_byte
*plt_contents
;
2141 arelent
**dynrelbuf
, *p
;
2143 const struct elf_backend_data
*bed
;
2144 bfd_vma (*get_plt_got_vma
) (struct elf_x86_plt
*, bfd_vma
, bfd_vma
,
2146 bool (*valid_plt_reloc_p
) (unsigned int);
2152 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
2153 if (dynrelbuf
== NULL
)
2156 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
2158 if (dynrelcount
<= 0)
2161 /* Sort the relocs by address. */
2162 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
2163 _bfd_x86_elf_compare_relocs
);
2165 size
= count
* sizeof (asymbol
);
2167 /* Allocate space for @plt suffixes. */
2169 for (i
= 0; i
< dynrelcount
; i
++)
2172 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2174 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
2177 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
2181 bed
= get_elf_backend_data (abfd
);
2183 if (bed
->target_id
== X86_64_ELF_DATA
)
2185 get_plt_got_vma
= elf_x86_64_get_plt_got_vma
;
2186 valid_plt_reloc_p
= elf_x86_64_valid_plt_reloc_p
;
2190 get_plt_got_vma
= elf_i386_get_plt_got_vma
;
2191 valid_plt_reloc_p
= elf_i386_valid_plt_reloc_p
;
2194 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
2196 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
2198 got_addr
= sec
->vma
;
2201 sec
= bfd_get_section_by_name (abfd
, ".got");
2203 got_addr
= sec
->vma
;
2206 if (got_addr
== (bfd_vma
) -1)
2211 /* Check for each PLT section. */
2212 names
= (char *) (s
+ count
);
2215 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2216 if ((plt_contents
= plts
[j
].contents
) != NULL
)
2221 struct elf_x86_plt
*plt_p
= &plts
[j
];
2223 plt_got_offset
= plt_p
->plt_got_offset
;
2224 plt_entry_size
= plt_p
->plt_entry_size
;
2228 if ((plt_p
->type
& plt_lazy
))
2230 /* Skip PLT0 in lazy PLT. */
2232 offset
= plt_entry_size
;
2240 /* Check each PLT entry against dynamic relocations. */
2241 for (; k
< plt_p
->count
; k
++)
2247 /* Get the GOT offset for i386 or the PC-relative offset
2248 for x86-64, a signed 32-bit integer. */
2249 off
= H_GET_32 (abfd
, (plt_contents
+ offset
2251 got_vma
= get_plt_got_vma (plt_p
, off
, offset
, got_addr
);
2253 /* Binary search. */
2257 while ((min
+ 1) < max
)
2261 mid
= (min
+ max
) / 2;
2263 if (got_vma
> r
->address
)
2265 else if (got_vma
< r
->address
)
2274 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
2275 if (got_vma
== p
->address
2277 && valid_plt_reloc_p (p
->howto
->type
))
2279 *s
= **p
->sym_ptr_ptr
;
2280 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
2281 set. Since we are defining a symbol, ensure one
2283 if ((s
->flags
& BSF_LOCAL
) == 0)
2284 s
->flags
|= BSF_GLOBAL
;
2285 s
->flags
|= BSF_SYNTHETIC
;
2286 /* This is no longer a section symbol. */
2287 s
->flags
&= ~BSF_SECTION_SYM
;
2289 s
->the_bfd
= plt
->owner
;
2293 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2294 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2300 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2301 names
+= sizeof ("+0x") - 1;
2302 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
2303 for (a
= buf
; *a
== '0'; ++a
)
2306 memcpy (names
, a
, size
);
2309 memcpy (names
, "@plt", sizeof ("@plt"));
2310 names
+= sizeof ("@plt");
2313 /* There should be only one entry in PLT for a given
2314 symbol. Set howto to NULL after processing a PLT
2315 entry to guard against corrupted PLT. */
2318 offset
+= plt_entry_size
;
2322 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
2331 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2332 free (plts
[j
].contents
);
2339 /* Parse x86 GNU properties. */
2341 enum elf_property_kind
2342 _bfd_x86_elf_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
2343 bfd_byte
*ptr
, unsigned int datasz
)
2347 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2348 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2349 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2350 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2351 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2352 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
2353 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2354 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2359 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
2360 abfd
, type
, datasz
);
2361 return property_corrupt
;
2363 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
2364 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
2365 prop
->pr_kind
= property_number
;
2366 return property_number
;
2369 return property_ignored
;
2372 /* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
2373 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
2374 should be merged with ABFD. */
2377 _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info
*info
,
2378 bfd
*abfd ATTRIBUTE_UNUSED
,
2379 bfd
*bbfd ATTRIBUTE_UNUSED
,
2380 elf_property
*aprop
,
2381 elf_property
*bprop
)
2383 unsigned int number
, features
;
2384 bool updated
= false;
2385 const struct elf_backend_data
*bed
;
2386 struct elf_x86_link_hash_table
*htab
;
2387 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
2389 if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2390 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2391 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2393 if (aprop
== NULL
|| bprop
== NULL
)
2395 /* Only one of APROP and BPROP can be NULL. */
2398 /* Remove this property since the other input file doesn't
2400 aprop
->pr_kind
= property_remove
;
2406 number
= aprop
->u
.number
;
2407 aprop
->u
.number
= number
| bprop
->u
.number
;
2408 updated
= number
!= (unsigned int) aprop
->u
.number
;
2412 else if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2413 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2414 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_HI
))
2417 if (pr_type
== GNU_PROPERTY_X86_ISA_1_NEEDED
)
2419 bed
= get_elf_backend_data (info
->output_bfd
);
2420 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2421 switch (htab
->params
->isa_level
)
2426 features
= GNU_PROPERTY_X86_ISA_1_V2
;
2429 features
= GNU_PROPERTY_X86_ISA_1_V3
;
2432 features
= GNU_PROPERTY_X86_ISA_1_V4
;
2438 if (aprop
!= NULL
&& bprop
!= NULL
)
2440 number
= aprop
->u
.number
;
2441 aprop
->u
.number
= number
| bprop
->u
.number
| features
;
2442 /* Remove the property if all bits are empty. */
2443 if (aprop
->u
.number
== 0)
2445 aprop
->pr_kind
= property_remove
;
2449 updated
= number
!= (unsigned int) aprop
->u
.number
;
2453 /* Only one of APROP and BPROP can be NULL. */
2456 aprop
->u
.number
|= features
;
2457 if (aprop
->u
.number
== 0)
2459 /* Remove APROP if all bits are empty. */
2460 aprop
->pr_kind
= property_remove
;
2466 /* Return TRUE if APROP is NULL and all bits of BPROP
2467 aren't empty to indicate that BPROP should be added
2469 bprop
->u
.number
|= features
;
2470 updated
= bprop
->u
.number
!= 0;
2475 else if (pr_type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2476 && pr_type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2478 /* Only one of APROP and BPROP can be NULL:
2479 1. APROP & BPROP when both APROP and BPROP aren't NULL.
2480 2. If APROP is NULL, remove x86 feature.
2481 3. Otherwise, do nothing.
2483 bed
= get_elf_backend_data (info
->output_bfd
);
2484 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2487 if (aprop
!= NULL
&& bprop
!= NULL
)
2489 number
= aprop
->u
.number
;
2490 aprop
->u
.number
= number
& bprop
->u
.number
;
2491 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2494 if (htab
->params
->ibt
)
2495 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2496 if (htab
->params
->shstk
)
2497 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2498 if (htab
->params
->lam_u48
)
2499 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2500 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2501 else if (htab
->params
->lam_u57
)
2502 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2503 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT,
2504 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2505 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
2506 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
2507 aprop
->u
.number
|= features
;
2509 updated
= number
!= (unsigned int) aprop
->u
.number
;
2510 /* Remove the property if all feature bits are cleared. */
2511 if (aprop
->u
.number
== 0)
2512 aprop
->pr_kind
= property_remove
;
2516 /* There should be no AND properties since some input doesn't
2517 have them. Set IBT and SHSTK properties for -z ibt and -z
2520 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2522 if (htab
->params
->ibt
)
2523 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2524 if (htab
->params
->shstk
)
2525 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2526 if (htab
->params
->lam_u48
)
2527 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2528 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2529 else if (htab
->params
->lam_u57
)
2530 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2536 updated
= features
!= (unsigned int) aprop
->u
.number
;
2537 aprop
->u
.number
= features
;
2542 bprop
->u
.number
= features
;
2545 else if (aprop
!= NULL
)
2547 aprop
->pr_kind
= property_remove
;
2555 /* Never should happen. */
2562 /* Set up x86 GNU properties. Return the first relocatable ELF input
2563 with GNU properties if found. Otherwise, return NULL. */
2566 _bfd_x86_elf_link_setup_gnu_properties
2567 (struct bfd_link_info
*info
, struct elf_x86_init_table
*init_table
)
2571 asection
*sec
, *pltsec
;
2574 unsigned int plt_alignment
, features
, isa_level
;
2575 struct elf_x86_link_hash_table
*htab
;
2579 const struct elf_backend_data
*bed
;
2580 unsigned int class_align
= ABI_64_P (info
->output_bfd
) ? 3 : 2;
2581 unsigned int got_align
;
2583 /* Find a normal input file with GNU property note. */
2584 for (pbfd
= info
->input_bfds
;
2586 pbfd
= pbfd
->link
.next
)
2587 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
2588 && bfd_count_sections (pbfd
) != 0)
2592 if (elf_properties (pbfd
) != NULL
)
2596 bed
= get_elf_backend_data (info
->output_bfd
);
2598 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2603 if (htab
->params
->ibt
)
2605 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2606 htab
->params
->cet_report
&= ~prop_report_ibt
;
2608 if (htab
->params
->shstk
)
2610 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2611 htab
->params
->cet_report
&= ~prop_report_shstk
;
2613 if (!(htab
->params
->cet_report
& (prop_report_ibt
| prop_report_shstk
)))
2614 htab
->params
->cet_report
= prop_report_none
;
2615 if (htab
->params
->lam_u48
)
2617 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2618 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2619 htab
->params
->lam_u48_report
= prop_report_none
;
2620 htab
->params
->lam_u57_report
= prop_report_none
;
2622 else if (htab
->params
->lam_u57
)
2624 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2625 htab
->params
->lam_u57_report
= prop_report_none
;
2628 switch (htab
->params
->isa_level
)
2634 isa_level
= GNU_PROPERTY_X86_ISA_1_BASELINE
;
2637 isa_level
= GNU_PROPERTY_X86_ISA_1_V2
;
2640 isa_level
= GNU_PROPERTY_X86_ISA_1_V3
;
2643 isa_level
= GNU_PROPERTY_X86_ISA_1_V4
;
2654 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT,
2655 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2656 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
2657 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
2658 prop
= _bfd_elf_get_property (ebfd
,
2659 GNU_PROPERTY_X86_FEATURE_1_AND
,
2661 prop
->u
.number
|= features
;
2662 prop
->pr_kind
= property_number
;
2667 /* If ISA level is set, add GNU_PROPERTY_X86_ISA_1_NEEDED. */
2668 prop
= _bfd_elf_get_property (ebfd
,
2669 GNU_PROPERTY_X86_ISA_1_NEEDED
,
2671 prop
->u
.number
|= isa_level
;
2672 prop
->pr_kind
= property_number
;
2675 /* Create the GNU property note section if needed. */
2676 if (prop
!= NULL
&& pbfd
== NULL
)
2678 sec
= bfd_make_section_with_flags (ebfd
,
2679 NOTE_GNU_PROPERTY_SECTION_NAME
,
2687 info
->callbacks
->einfo (_("%F%P: failed to create GNU property section\n"));
2689 if (!bfd_set_section_alignment (sec
, class_align
))
2692 info
->callbacks
->einfo (_("%F%pA: failed to align section\n"),
2696 elf_section_type (sec
) = SHT_NOTE
;
2700 if (htab
->params
->cet_report
2701 || htab
->params
->lam_u48_report
2702 || htab
->params
->lam_u57_report
)
2704 /* Report missing IBT, SHSTK and LAM properties. */
2706 const char *warning_msg
= _("%P: %pB: warning: missing %s\n");
2707 const char *error_msg
= _("%X%P: %pB: error: missing %s\n");
2708 const char *cet_msg
= NULL
;
2709 const char *lam_u48_msg
= NULL
;
2710 const char *lam_u57_msg
= NULL
;
2711 const char *missing
;
2712 elf_property_list
*p
;
2713 bool missing_ibt
, missing_shstk
;
2714 bool missing_lam_u48
, missing_lam_u57
;
2716 = (htab
->params
->cet_report
2717 && (htab
->params
->cet_report
& prop_report_ibt
));
2719 = (htab
->params
->cet_report
2720 && (htab
->params
->cet_report
& prop_report_shstk
));
2722 if (htab
->params
->cet_report
)
2724 if ((htab
->params
->cet_report
& prop_report_warning
))
2725 cet_msg
= warning_msg
;
2727 cet_msg
= error_msg
;
2729 if (htab
->params
->lam_u48_report
)
2731 if ((htab
->params
->lam_u48_report
& prop_report_warning
))
2732 lam_u48_msg
= warning_msg
;
2734 lam_u48_msg
= error_msg
;
2736 if (htab
->params
->lam_u57_report
)
2738 if ((htab
->params
->lam_u57_report
& prop_report_warning
))
2739 lam_u57_msg
= warning_msg
;
2741 lam_u57_msg
= error_msg
;
2744 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
2745 if (!(abfd
->flags
& (DYNAMIC
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
2746 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
2748 for (p
= elf_properties (abfd
); p
; p
= p
->next
)
2749 if (p
->property
.pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2752 missing_ibt
= check_ibt
;
2753 missing_shstk
= check_shstk
;
2754 missing_lam_u48
= !!lam_u48_msg
;
2755 missing_lam_u57
= !!lam_u57_msg
;
2758 missing_ibt
&= !(p
->property
.u
.number
2759 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2760 missing_shstk
&= !(p
->property
.u
.number
2761 & GNU_PROPERTY_X86_FEATURE_1_SHSTK
);
2762 missing_lam_u48
&= !(p
->property
.u
.number
2763 & GNU_PROPERTY_X86_FEATURE_1_LAM_U48
);
2764 missing_lam_u57
&= !(p
->property
.u
.number
2765 & GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2767 if (missing_ibt
|| missing_shstk
)
2769 if (missing_ibt
&& missing_shstk
)
2770 missing
= _("IBT and SHSTK properties");
2771 else if (missing_ibt
)
2772 missing
= _("IBT property");
2774 missing
= _("SHSTK property");
2775 info
->callbacks
->einfo (cet_msg
, abfd
, missing
);
2777 if (missing_lam_u48
)
2779 missing
= _("LAM_U48 property");
2780 info
->callbacks
->einfo (lam_u48_msg
, abfd
, missing
);
2782 if (missing_lam_u57
)
2784 missing
= _("LAM_U57 property");
2785 info
->callbacks
->einfo (lam_u57_msg
, abfd
, missing
);
2790 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
2792 htab
->r_info
= init_table
->r_info
;
2793 htab
->r_sym
= init_table
->r_sym
;
2795 if (bfd_link_relocatable (info
))
2798 htab
->plt0_pad_byte
= init_table
->plt0_pad_byte
;
2800 use_ibt_plt
= htab
->params
->ibtplt
|| htab
->params
->ibt
;
2801 if (!use_ibt_plt
&& pbfd
!= NULL
)
2803 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
2804 elf_property_list
*p
;
2806 /* The property list is sorted in order of type. */
2807 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
2809 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
2811 use_ibt_plt
= !!(p
->property
.u
.number
2812 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2815 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
2820 dynobj
= htab
->elf
.dynobj
;
2822 /* Set htab->elf.dynobj here so that there is no need to check and
2823 set it in check_relocs. */
2828 htab
->elf
.dynobj
= pbfd
;
2835 /* Find a normal input file to hold linker created
2837 for (abfd
= info
->input_bfds
;
2839 abfd
= abfd
->link
.next
)
2840 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2842 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0
2843 && bed
->relocs_compatible (abfd
->xvec
,
2844 info
->output_bfd
->xvec
))
2846 htab
->elf
.dynobj
= abfd
;
2853 /* Return if there are no normal input files. */
2857 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
2858 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
2859 canonical function address. */
2860 htab
->plt
.has_plt0
= 1;
2861 normal_target
= htab
->elf
.target_os
== is_normal
;
2867 htab
->lazy_plt
= init_table
->lazy_ibt_plt
;
2868 htab
->non_lazy_plt
= init_table
->non_lazy_ibt_plt
;
2872 htab
->lazy_plt
= init_table
->lazy_plt
;
2873 htab
->non_lazy_plt
= init_table
->non_lazy_plt
;
2878 htab
->lazy_plt
= init_table
->lazy_plt
;
2879 htab
->non_lazy_plt
= NULL
;
2882 pltsec
= htab
->elf
.splt
;
2884 /* If the non-lazy PLT is available, use it for all PLT entries if
2885 there are no PLT0 or no .plt section. */
2886 if (htab
->non_lazy_plt
!= NULL
2887 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
2890 if (bfd_link_pic (info
))
2891 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
2893 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
2894 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
2895 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
2896 htab
->plt
.plt_got_insn_size
2897 = htab
->non_lazy_plt
->plt_got_insn_size
;
2898 htab
->plt
.eh_frame_plt_size
2899 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2900 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
2905 if (bfd_link_pic (info
))
2907 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
2908 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
2912 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
2913 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
2915 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
2916 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
2917 htab
->plt
.plt_got_insn_size
2918 = htab
->lazy_plt
->plt_got_insn_size
;
2919 htab
->plt
.eh_frame_plt_size
2920 = htab
->lazy_plt
->eh_frame_plt_size
;
2921 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
2924 if (htab
->elf
.target_os
== is_vxworks
2925 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
2928 info
->callbacks
->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
2932 /* Since create_dynamic_sections isn't always called, but GOT
2933 relocations need GOT relocations, create them here so that we
2934 don't need to do it in check_relocs. */
2935 if (htab
->elf
.sgot
== NULL
2936 && !_bfd_elf_create_got_section (dynobj
, info
))
2937 info
->callbacks
->einfo (_("%F%P: failed to create GOT sections\n"));
2939 got_align
= (bed
->target_id
== X86_64_ELF_DATA
) ? 3 : 2;
2941 /* Align .got and .got.plt sections to their entry size. Do it here
2942 instead of in create_dynamic_sections so that they are always
2943 properly aligned even if create_dynamic_sections isn't called. */
2944 sec
= htab
->elf
.sgot
;
2945 if (!bfd_set_section_alignment (sec
, got_align
))
2946 goto error_alignment
;
2948 sec
= htab
->elf
.sgotplt
;
2949 if (!bfd_set_section_alignment (sec
, got_align
))
2950 goto error_alignment
;
2952 /* Create the ifunc sections here so that check_relocs can be
2954 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
2955 info
->callbacks
->einfo (_("%F%P: failed to create ifunc sections\n"));
2957 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
2961 /* Whe creating executable, set the contents of the .interp
2962 section to the interpreter. */
2963 if (bfd_link_executable (info
) && !info
->nointerp
)
2965 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
2968 s
->size
= htab
->dynamic_interpreter_size
;
2969 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2975 flagword pltflags
= (bed
->dynamic_sec_flags
2980 unsigned int non_lazy_plt_alignment
2981 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
2984 if (!bfd_set_section_alignment (sec
, plt_alignment
))
2985 goto error_alignment
;
2987 /* Create the GOT procedure linkage table. */
2988 sec
= bfd_make_section_anyway_with_flags (dynobj
,
2992 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT section\n"));
2994 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
2995 goto error_alignment
;
2997 htab
->plt_got
= sec
;
3005 /* Create the second PLT for Intel IBT support. IBT
3006 PLT is needed only for lazy binding. */
3007 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3011 info
->callbacks
->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
3013 if (!bfd_set_section_alignment (sec
, plt_alignment
))
3014 goto error_alignment
;
3016 else if (htab
->params
->bndplt
&& ABI_64_P (dynobj
))
3018 /* Create the second PLT for Intel MPX support. MPX
3019 PLT is supported only in 64-bit mode and is needed
3020 only for lazy binding. */
3021 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3025 info
->callbacks
->einfo (_("%F%P: failed to create BND PLT section\n"));
3027 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
3028 goto error_alignment
;
3031 htab
->plt_second
= sec
;
3035 if (!info
->no_ld_generated_unwind_info
)
3037 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3038 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3039 | SEC_LINKER_CREATED
);
3041 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3045 info
->callbacks
->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
3047 if (!bfd_set_section_alignment (sec
, class_align
))
3048 goto error_alignment
;
3050 htab
->plt_eh_frame
= sec
;
3052 if (htab
->plt_got
!= NULL
)
3054 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3058 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
3060 if (!bfd_set_section_alignment (sec
, class_align
))
3061 goto error_alignment
;
3063 htab
->plt_got_eh_frame
= sec
;
3066 if (htab
->plt_second
!= NULL
)
3068 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3072 info
->callbacks
->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
3074 if (!bfd_set_section_alignment (sec
, class_align
))
3075 goto error_alignment
;
3077 htab
->plt_second_eh_frame
= sec
;
3082 /* The .iplt section is used for IFUNC symbols in static
3084 sec
= htab
->elf
.iplt
;
3087 /* NB: Delay setting its alignment until we know it is non-empty.
3088 Otherwise an empty iplt section may change vma and lma of the
3089 following sections, which triggers moving dot of the following
3090 section backwards, resulting in a warning and section lma not
3091 being set properly. It later leads to a "File truncated"
3093 if (!bfd_set_section_alignment (sec
, 0))
3094 goto error_alignment
;
3096 htab
->plt
.iplt_alignment
= (normal_target
3098 : bed
->plt_alignment
);
3101 if (bfd_link_executable (info
)
3103 && !htab
->params
->has_dynamic_linker
3104 && htab
->params
->static_before_all_inputs
)
3106 /* Report error for dynamic input objects if -static is passed at
3107 command-line before all input files without --dynamic-linker
3108 unless --no-dynamic-linker is used. */
3111 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
3112 if ((abfd
->flags
& DYNAMIC
))
3113 info
->callbacks
->einfo
3114 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
3121 /* Fix up x86 GNU properties. */
3124 _bfd_x86_elf_link_fixup_gnu_properties
3125 (struct bfd_link_info
*info
, elf_property_list
**listp
)
3127 elf_property_list
*p
;
3129 for (p
= *listp
; p
; p
= p
->next
)
3131 unsigned int type
= p
->property
.pr_type
;
3132 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3133 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3134 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3135 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3136 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3137 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
3138 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3139 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3141 if (p
->property
.u
.number
== 0
3142 && (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3143 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3144 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3145 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3146 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)))
3148 /* Remove empty property. */
3153 /* Keep LAM features only for 64-bit output. */
3154 if (type
== GNU_PROPERTY_X86_FEATURE_1_AND
3155 && !ABI_64_P (info
->output_bfd
))
3156 p
->property
.u
.number
&= ~(GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3157 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3161 else if (type
> GNU_PROPERTY_HIPROC
)
3163 /* The property list is sorted in order of type. */
3170 _bfd_elf_linker_x86_set_options (struct bfd_link_info
* info
,
3171 struct elf_linker_x86_params
*params
)
3173 const struct elf_backend_data
*bed
3174 = get_elf_backend_data (info
->output_bfd
);
3175 struct elf_x86_link_hash_table
*htab
3176 = elf_x86_hash_table (info
, bed
->target_id
);
3178 htab
->params
= params
;