1 /* x86 specific support for ELF
2 Copyright (C) 2017-2020 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 bfd_boolean 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
,
135 &htab
->readonly_dynrelocs_against_ifunc
,
139 htab
->got_entry_size
,
142 asection
*s
= htab
->plt_second
;
143 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
145 /* Use the second PLT section if it is created. */
146 eh
->plt_second
.offset
= s
->size
;
148 /* Make room for this entry in the second PLT section. */
149 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
157 /* Don't create the PLT entry if there are only function pointer
158 relocations which can be resolved at run-time. */
159 else if (htab
->elf
.dynamic_sections_created
160 && (h
->plt
.refcount
> 0
161 || eh
->plt_got
.refcount
> 0))
163 bfd_boolean use_plt_got
= eh
->plt_got
.refcount
> 0;
165 /* Make sure this symbol is output as a dynamic symbol.
166 Undefined weak syms won't yet be marked as dynamic. */
170 && h
->root
.type
== bfd_link_hash_undefweak
)
172 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
176 if (bfd_link_pic (info
)
177 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
179 asection
*s
= htab
->elf
.splt
;
180 asection
*second_s
= htab
->plt_second
;
181 asection
*got_s
= htab
->plt_got
;
184 /* If this is the first .plt entry, make room for the special
185 first entry. The .plt section is used by prelink to undo
186 prelinking for dynamic relocations. */
188 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
191 eh
->plt_got
.offset
= got_s
->size
;
194 h
->plt
.offset
= s
->size
;
196 eh
->plt_second
.offset
= second_s
->size
;
199 /* If this symbol is not defined in a regular file, and we are
200 generating PDE, then set the symbol to this location in the
201 .plt. This is required to make function pointers compare
202 as equal between PDE and the shared library.
204 NB: If PLT is PC-relative, we can use the .plt in PIE for
208 else if (htab
->pcrel_plt
)
209 use_plt
= ! bfd_link_dll (info
);
211 use_plt
= bfd_link_pde (info
);
216 /* We need to make a call to the entry of the GOT PLT
217 instead of regular PLT entry. */
218 h
->root
.u
.def
.section
= got_s
;
219 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
225 /* We need to make a call to the entry of the
226 second PLT instead of regular PLT entry. */
227 h
->root
.u
.def
.section
= second_s
;
228 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
232 h
->root
.u
.def
.section
= s
;
233 h
->root
.u
.def
.value
= h
->plt
.offset
;
238 /* Make room for this entry. */
240 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
243 s
->size
+= plt_entry_size
;
245 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
247 /* We also need to make an entry in the .got.plt section,
248 which will be placed in the .got section by the linker
250 htab
->elf
.sgotplt
->size
+= htab
->got_entry_size
;
252 /* There should be no PLT relocation against resolved
253 undefined weak symbol in executable. */
254 if (!resolved_to_zero
)
256 /* We also need to make an entry in the .rel.plt
258 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
259 htab
->elf
.srelplt
->reloc_count
++;
263 if (htab
->target_os
== is_vxworks
&& !bfd_link_pic (info
))
265 /* VxWorks has a second set of relocations for each PLT entry
266 in executables. They go in a separate relocation section,
267 which is processed by the kernel loader. */
269 /* There are two relocations for the initial PLT entry: an
270 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
271 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
273 asection
*srelplt2
= htab
->srelplt2
;
274 if (h
->plt
.offset
== plt_entry_size
)
275 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
277 /* There are two extra relocations for each subsequent PLT entry:
278 an R_386_32 relocation for the GOT entry, and an R_386_32
279 relocation for the PLT entry. */
281 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
286 eh
->plt_got
.offset
= (bfd_vma
) -1;
287 h
->plt
.offset
= (bfd_vma
) -1;
293 eh
->plt_got
.offset
= (bfd_vma
) -1;
294 h
->plt
.offset
= (bfd_vma
) -1;
298 eh
->tlsdesc_got
= (bfd_vma
) -1;
300 /* For i386, if R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the
301 binary, make it a R_386_TLS_LE_32 requiring no TLS entry. For
302 x86-64, if R_X86_64_GOTTPOFF symbol is now local to the binary,
303 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
304 if (h
->got
.refcount
> 0
305 && bfd_link_executable (info
)
307 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
308 h
->got
.offset
= (bfd_vma
) -1;
309 else if (h
->got
.refcount
> 0)
313 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
315 /* Make sure this symbol is output as a dynamic symbol.
316 Undefined weak syms won't yet be marked as dynamic. */
320 && h
->root
.type
== bfd_link_hash_undefweak
)
322 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
327 if (GOT_TLS_GDESC_P (tls_type
))
329 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
330 - elf_x86_compute_jump_table_size (htab
);
331 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
332 h
->got
.offset
= (bfd_vma
) -2;
334 if (! GOT_TLS_GDESC_P (tls_type
)
335 || GOT_TLS_GD_P (tls_type
))
337 h
->got
.offset
= s
->size
;
338 s
->size
+= htab
->got_entry_size
;
339 /* R_386_TLS_GD and R_X86_64_TLSGD need 2 consecutive GOT
341 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
342 s
->size
+= htab
->got_entry_size
;
344 dyn
= htab
->elf
.dynamic_sections_created
;
345 /* R_386_TLS_IE_32 needs one dynamic relocation,
346 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
347 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
348 need two), R_386_TLS_GD and R_X86_64_TLSGD need one if local
349 symbol and two if global. No dynamic relocation against
350 resolved undefined weak symbol in executable. No dynamic
351 relocation against non-preemptible absolute symbol. */
352 if (tls_type
== GOT_TLS_IE_BOTH
)
353 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
354 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
355 || (tls_type
& GOT_TLS_IE
))
356 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
357 else if (GOT_TLS_GD_P (tls_type
))
358 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
359 else if (! GOT_TLS_GDESC_P (tls_type
)
360 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
361 && !resolved_to_zero
)
362 || h
->root
.type
!= bfd_link_hash_undefweak
)
363 && ((bfd_link_pic (info
)
364 && !(h
->dynindx
== -1
365 && ABS_SYMBOL_P (h
)))
366 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
367 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
368 if (GOT_TLS_GDESC_P (tls_type
))
370 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
371 if (bed
->target_id
== X86_64_ELF_DATA
)
372 htab
->tlsdesc_plt
= (bfd_vma
) -1;
376 h
->got
.offset
= (bfd_vma
) -1;
378 if (h
->dyn_relocs
== NULL
)
381 /* In the shared -Bsymbolic case, discard space allocated for
382 dynamic pc-relative relocs against symbols which turn out to be
383 defined in regular objects. For the normal shared case, discard
384 space for pc-relative relocs that have become local due to symbol
385 visibility changes. */
387 if (bfd_link_pic (info
))
389 /* Relocs that use pc_count are those that appear on a call
390 insn, or certain REL relocs that can generated via assembly.
391 We want calls to protected symbols to resolve directly to the
392 function rather than going via the plt. If people want
393 function pointer comparisons to work as expected then they
394 should avoid writing weird assembly. */
395 if (SYMBOL_CALLS_LOCAL (info
, h
))
397 struct elf_dyn_relocs
**pp
;
399 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
401 p
->count
-= p
->pc_count
;
410 if (htab
->target_os
== is_vxworks
)
412 struct elf_dyn_relocs
**pp
;
413 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
415 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
422 /* Also discard relocs on undefined weak syms with non-default
423 visibility or in PIE. */
424 if (h
->dyn_relocs
!= NULL
)
426 if (h
->root
.type
== bfd_link_hash_undefweak
)
428 /* Undefined weak symbol is never bound locally in shared
430 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
433 if (bed
->target_id
== I386_ELF_DATA
436 /* Keep dynamic non-GOT/non-PLT relocation so
437 that we can branch to 0 without PLT. */
438 struct elf_dyn_relocs
**pp
;
440 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
441 if (p
->pc_count
== 0)
445 /* Remove non-R_386_PC32 relocation. */
446 p
->count
= p
->pc_count
;
450 /* Make sure undefined weak symbols are output
451 as dynamic symbols in PIEs for dynamic non-GOT
452 non-PLT reloations. */
453 if (h
->dyn_relocs
!= NULL
454 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
458 h
->dyn_relocs
= NULL
;
460 else if (h
->dynindx
== -1
462 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
465 else if (bfd_link_executable (info
)
466 && (h
->needs_copy
|| eh
->needs_copy
)
470 /* NB: needs_copy is set only for x86-64. For PIE,
471 discard space for pc-relative relocs against symbols
472 which turn out to need copy relocs. */
473 struct elf_dyn_relocs
**pp
;
475 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
477 if (p
->pc_count
!= 0)
485 else if (ELIMINATE_COPY_RELOCS
)
487 /* For the non-shared case, discard space for relocs against
488 symbols which turn out to need copy relocs or are not
489 dynamic. Keep dynamic relocations for run-time function
490 pointer initialization. */
493 || (h
->root
.type
== bfd_link_hash_undefweak
494 && !resolved_to_zero
))
497 || (htab
->elf
.dynamic_sections_created
498 && (h
->root
.type
== bfd_link_hash_undefweak
499 || h
->root
.type
== bfd_link_hash_undefined
))))
501 /* Make sure this symbol is output as a dynamic symbol.
502 Undefined weak syms won't yet be marked as dynamic. */
506 && h
->root
.type
== bfd_link_hash_undefweak
507 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
510 /* If that succeeded, we know we'll be keeping all the
512 if (h
->dynindx
!= -1)
516 h
->dyn_relocs
= NULL
;
521 /* Finally, allocate space. */
522 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
526 sreloc
= elf_section_data (p
->sec
)->sreloc
;
528 BFD_ASSERT (sreloc
!= NULL
);
529 sreloc
->size
+= p
->count
* htab
->sizeof_reloc
;
535 /* Set DF_TEXTREL if we find any dynamic relocs that apply to
536 read-only sections. */
539 maybe_set_textrel (struct elf_link_hash_entry
*h
, void *inf
)
543 if (h
->root
.type
== bfd_link_hash_indirect
)
546 /* Skip local IFUNC symbols. */
547 if (h
->forced_local
&& h
->type
== STT_GNU_IFUNC
)
550 sec
= _bfd_elf_readonly_dynrelocs (h
);
553 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
555 info
->flags
|= DF_TEXTREL
;
556 /* xgettext:c-format */
557 info
->callbacks
->minfo (_("%pB: dynamic relocation against `%pT' "
558 "in read-only section `%pA'\n"),
559 sec
->owner
, h
->root
.root
.string
, sec
);
561 if (bfd_link_textrel_check (info
))
562 /* xgettext:c-format */
563 info
->callbacks
->einfo (_("%P: %pB: warning: relocation against `%s' "
564 "in read-only section `%pA'\n"),
565 sec
->owner
, h
->root
.root
.string
, sec
);
567 /* Not an error, just cut short the traversal. */
573 /* Allocate space in .plt, .got and associated reloc sections for
574 local dynamic relocs. */
577 elf_x86_allocate_local_dynreloc (void **slot
, void *inf
)
579 struct elf_link_hash_entry
*h
580 = (struct elf_link_hash_entry
*) *slot
;
582 if (h
->type
!= STT_GNU_IFUNC
586 || h
->root
.type
!= bfd_link_hash_defined
)
589 return elf_x86_allocate_dynrelocs (h
, inf
);
592 /* Find and/or create a hash entry for local symbol. */
594 struct elf_link_hash_entry
*
595 _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table
*htab
,
596 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
599 struct elf_x86_link_hash_entry e
, *ret
;
600 asection
*sec
= abfd
->sections
;
601 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
602 htab
->r_sym (rel
->r_info
));
605 e
.elf
.indx
= sec
->id
;
606 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
607 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
608 create
? INSERT
: NO_INSERT
);
615 ret
= (struct elf_x86_link_hash_entry
*) *slot
;
619 ret
= (struct elf_x86_link_hash_entry
*)
620 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
621 sizeof (struct elf_x86_link_hash_entry
));
624 memset (ret
, 0, sizeof (*ret
));
625 ret
->elf
.indx
= sec
->id
;
626 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
627 ret
->elf
.dynindx
= -1;
628 ret
->plt_got
.offset
= (bfd_vma
) -1;
634 /* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
635 SYNC WITH _bfd_elf_link_hash_newfunc. */
637 struct bfd_hash_entry
*
638 _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
639 struct bfd_hash_table
*table
,
642 /* Allocate the structure if it has not already been allocated by a
646 entry
= (struct bfd_hash_entry
*)
647 bfd_hash_allocate (table
,
648 sizeof (struct elf_x86_link_hash_entry
));
653 /* Call the allocation method of the superclass. */
654 entry
= _bfd_link_hash_newfunc (entry
, table
, string
);
657 struct elf_x86_link_hash_entry
*eh
658 = (struct elf_x86_link_hash_entry
*) entry
;
659 struct elf_link_hash_table
*htab
660 = (struct elf_link_hash_table
*) table
;
662 memset (&eh
->elf
.size
, 0,
663 (sizeof (struct elf_x86_link_hash_entry
)
664 - offsetof (struct elf_link_hash_entry
, size
)));
665 /* Set local fields. */
667 eh
->elf
.dynindx
= -1;
668 eh
->elf
.got
= htab
->init_got_refcount
;
669 eh
->elf
.plt
= htab
->init_plt_refcount
;
670 /* Assume that we have been called by a non-ELF symbol reader.
671 This flag is then reset by the code which reads an ELF input
672 file. This ensures that a symbol created by a non-ELF symbol
673 reader will have the flag set correctly. */
675 eh
->plt_second
.offset
= (bfd_vma
) -1;
676 eh
->plt_got
.offset
= (bfd_vma
) -1;
677 eh
->tlsdesc_got
= (bfd_vma
) -1;
678 eh
->zero_undefweak
= 1;
684 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
685 for local symbol so that we can handle local STT_GNU_IFUNC symbols
686 as global symbol. We reuse indx and dynstr_index for local symbol
687 hash since they aren't used by global symbols in this backend. */
690 _bfd_x86_elf_local_htab_hash (const void *ptr
)
692 struct elf_link_hash_entry
*h
693 = (struct elf_link_hash_entry
*) ptr
;
694 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
697 /* Compare local hash entries. */
700 _bfd_x86_elf_local_htab_eq (const void *ptr1
, const void *ptr2
)
702 struct elf_link_hash_entry
*h1
703 = (struct elf_link_hash_entry
*) ptr1
;
704 struct elf_link_hash_entry
*h2
705 = (struct elf_link_hash_entry
*) ptr2
;
707 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
710 /* Destroy an x86 ELF linker hash table. */
713 elf_x86_link_hash_table_free (bfd
*obfd
)
715 struct elf_x86_link_hash_table
*htab
716 = (struct elf_x86_link_hash_table
*) obfd
->link
.hash
;
718 if (htab
->loc_hash_table
)
719 htab_delete (htab
->loc_hash_table
);
720 if (htab
->loc_hash_memory
)
721 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
722 _bfd_elf_link_hash_table_free (obfd
);
726 elf_i386_is_reloc_section (const char *secname
)
728 return CONST_STRNEQ (secname
, ".rel");
732 elf_x86_64_is_reloc_section (const char *secname
)
734 return CONST_STRNEQ (secname
, ".rela");
737 /* Create an x86 ELF linker hash table. */
739 struct bfd_link_hash_table
*
740 _bfd_x86_elf_link_hash_table_create (bfd
*abfd
)
742 struct elf_x86_link_hash_table
*ret
;
743 const struct elf_backend_data
*bed
;
744 size_t amt
= sizeof (struct elf_x86_link_hash_table
);
746 ret
= (struct elf_x86_link_hash_table
*) bfd_zmalloc (amt
);
750 bed
= get_elf_backend_data (abfd
);
751 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
752 _bfd_x86_elf_link_hash_newfunc
,
753 sizeof (struct elf_x86_link_hash_entry
),
760 if (bed
->target_id
== X86_64_ELF_DATA
)
762 ret
->is_reloc_section
= elf_x86_64_is_reloc_section
;
763 ret
->dt_reloc
= DT_RELA
;
764 ret
->dt_reloc_sz
= DT_RELASZ
;
765 ret
->dt_reloc_ent
= DT_RELAENT
;
766 ret
->got_entry_size
= 8;
767 ret
->pcrel_plt
= TRUE
;
768 ret
->tls_get_addr
= "__tls_get_addr";
772 ret
->sizeof_reloc
= sizeof (Elf64_External_Rela
);
773 ret
->pointer_r_type
= R_X86_64_64
;
774 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
775 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
779 if (bed
->target_id
== X86_64_ELF_DATA
)
781 ret
->sizeof_reloc
= sizeof (Elf32_External_Rela
);
782 ret
->pointer_r_type
= R_X86_64_32
;
783 ret
->dynamic_interpreter
= ELFX32_DYNAMIC_INTERPRETER
;
784 ret
->dynamic_interpreter_size
785 = sizeof ELFX32_DYNAMIC_INTERPRETER
;
789 ret
->is_reloc_section
= elf_i386_is_reloc_section
;
790 ret
->dt_reloc
= DT_REL
;
791 ret
->dt_reloc_sz
= DT_RELSZ
;
792 ret
->dt_reloc_ent
= DT_RELENT
;
793 ret
->sizeof_reloc
= sizeof (Elf32_External_Rel
);
794 ret
->got_entry_size
= 4;
795 ret
->pcrel_plt
= FALSE
;
796 ret
->pointer_r_type
= R_386_32
;
797 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
798 ret
->dynamic_interpreter_size
799 = sizeof ELF32_DYNAMIC_INTERPRETER
;
800 ret
->tls_get_addr
= "___tls_get_addr";
803 ret
->target_id
= bed
->target_id
;
804 ret
->target_os
= get_elf_x86_backend_data (abfd
)->target_os
;
806 ret
->loc_hash_table
= htab_try_create (1024,
807 _bfd_x86_elf_local_htab_hash
,
808 _bfd_x86_elf_local_htab_eq
,
810 ret
->loc_hash_memory
= objalloc_create ();
811 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
813 elf_x86_link_hash_table_free (abfd
);
816 ret
->elf
.root
.hash_table_free
= elf_x86_link_hash_table_free
;
818 return &ret
->elf
.root
;
821 /* Sort relocs into address order. */
824 _bfd_x86_elf_compare_relocs (const void *ap
, const void *bp
)
826 const arelent
*a
= * (const arelent
**) ap
;
827 const arelent
*b
= * (const arelent
**) bp
;
829 if (a
->address
> b
->address
)
831 else if (a
->address
< b
->address
)
837 /* Mark symbol, NAME, as locally defined by linker if it is referenced
838 and not defined in a relocatable object file. */
841 elf_x86_linker_defined (struct bfd_link_info
*info
, const char *name
)
843 struct elf_link_hash_entry
*h
;
845 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
846 FALSE
, FALSE
, FALSE
);
850 while (h
->root
.type
== bfd_link_hash_indirect
)
851 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
853 if (h
->root
.type
== bfd_link_hash_new
854 || h
->root
.type
== bfd_link_hash_undefined
855 || h
->root
.type
== bfd_link_hash_undefweak
856 || h
->root
.type
== bfd_link_hash_common
857 || (!h
->def_regular
&& h
->def_dynamic
))
859 elf_x86_hash_entry (h
)->local_ref
= 2;
860 elf_x86_hash_entry (h
)->linker_def
= 1;
864 /* Hide a linker-defined symbol, NAME, with hidden visibility. */
867 elf_x86_hide_linker_defined (struct bfd_link_info
*info
,
870 struct elf_link_hash_entry
*h
;
872 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
873 FALSE
, FALSE
, FALSE
);
877 while (h
->root
.type
== bfd_link_hash_indirect
)
878 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
880 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
881 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
882 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
886 _bfd_x86_elf_link_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
)
888 if (!bfd_link_relocatable (info
))
890 /* Check for __tls_get_addr reference. */
891 struct elf_x86_link_hash_table
*htab
;
892 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
893 htab
= elf_x86_hash_table (info
, bed
->target_id
);
896 struct elf_link_hash_entry
*h
;
898 h
= elf_link_hash_lookup (elf_hash_table (info
),
900 FALSE
, FALSE
, FALSE
);
903 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
905 /* Check the versioned __tls_get_addr symbol. */
906 while (h
->root
.type
== bfd_link_hash_indirect
)
908 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
909 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
913 /* "__ehdr_start" will be defined by linker as a hidden symbol
914 later if it is referenced and not defined. */
915 elf_x86_linker_defined (info
, "__ehdr_start");
917 if (bfd_link_executable (info
))
919 /* References to __bss_start, _end and _edata should be
920 locally resolved within executables. */
921 elf_x86_linker_defined (info
, "__bss_start");
922 elf_x86_linker_defined (info
, "_end");
923 elf_x86_linker_defined (info
, "_edata");
927 /* Hide hidden __bss_start, _end and _edata in shared
929 elf_x86_hide_linker_defined (info
, "__bss_start");
930 elf_x86_hide_linker_defined (info
, "_end");
931 elf_x86_hide_linker_defined (info
, "_edata");
936 /* Invoke the regular ELF backend linker to do all the work. */
937 return _bfd_elf_link_check_relocs (abfd
, info
);
941 _bfd_elf_x86_valid_reloc_p (asection
*input_section
,
942 struct bfd_link_info
*info
,
943 struct elf_x86_link_hash_table
*htab
,
944 const Elf_Internal_Rela
*rel
,
945 struct elf_link_hash_entry
*h
,
946 Elf_Internal_Sym
*sym
,
947 Elf_Internal_Shdr
*symtab_hdr
,
948 bfd_boolean
*no_dynreloc_p
)
950 bfd_boolean valid_p
= TRUE
;
952 *no_dynreloc_p
= FALSE
;
954 /* Check If relocation against non-preemptible absolute symbol is
955 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
956 it may call _bfd_elf_link_hide_sym_by_version and result in
957 ld-elfvers/ vers21 test failure. */
958 if (bfd_link_pic (info
)
959 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
961 const struct elf_backend_data
*bed
;
963 Elf_Internal_Rela irel
;
965 /* Skip non-absolute symbol. */
968 if (!ABS_SYMBOL_P (h
))
971 else if (sym
->st_shndx
!= SHN_ABS
)
974 bed
= get_elf_backend_data (input_section
->owner
);
975 r_type
= ELF32_R_TYPE (rel
->r_info
);
978 /* Only allow relocations against absolute symbol, which can be
979 resolved as absolute value + addend. GOTPCREL relocations
980 are allowed since absolute value + addend is stored in the
982 if (bed
->target_id
== X86_64_ELF_DATA
)
984 r_type
&= ~R_X86_64_converted_reloc_bit
;
985 valid_p
= (r_type
== R_X86_64_64
986 || r_type
== R_X86_64_32
987 || r_type
== R_X86_64_32S
988 || r_type
== R_X86_64_16
989 || r_type
== R_X86_64_8
990 || r_type
== R_X86_64_GOTPCREL
991 || r_type
== R_X86_64_GOTPCRELX
992 || r_type
== R_X86_64_REX_GOTPCRELX
);
995 unsigned int r_symndx
= htab
->r_sym (rel
->r_info
);
996 irel
.r_info
= htab
->r_info (r_symndx
, r_type
);
1000 valid_p
= (r_type
== R_386_32
1001 || r_type
== R_386_16
1002 || r_type
== R_386_8
);
1005 *no_dynreloc_p
= TRUE
;
1009 arelent internal_reloc
;
1011 if (!bed
->elf_info_to_howto (input_section
->owner
,
1012 &internal_reloc
, &irel
)
1013 || internal_reloc
.howto
== NULL
)
1017 name
= h
->root
.root
.string
;
1019 name
= bfd_elf_sym_name (input_section
->owner
, symtab_hdr
,
1021 info
->callbacks
->einfo
1022 /* xgettext:c-format */
1023 (_("%F%P: %pB: relocation %s against absolute symbol "
1024 "`%s' in section `%pA' is disallowed\n"),
1025 input_section
->owner
, internal_reloc
.howto
->name
, name
,
1027 bfd_set_error (bfd_error_bad_value
);
1034 /* Set the sizes of the dynamic sections. */
1037 _bfd_x86_elf_size_dynamic_sections (bfd
*output_bfd
,
1038 struct bfd_link_info
*info
)
1040 struct elf_x86_link_hash_table
*htab
;
1045 const struct elf_backend_data
*bed
1046 = get_elf_backend_data (output_bfd
);
1048 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1051 dynobj
= htab
->elf
.dynobj
;
1055 /* Set up .got offsets for local syms, and space for local dynamic
1057 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1059 bfd_signed_vma
*local_got
;
1060 bfd_signed_vma
*end_local_got
;
1061 char *local_tls_type
;
1062 bfd_vma
*local_tlsdesc_gotent
;
1063 bfd_size_type locsymcount
;
1064 Elf_Internal_Shdr
*symtab_hdr
;
1067 if (! is_x86_elf (ibfd
, htab
))
1070 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1072 struct elf_dyn_relocs
*p
;
1074 for (p
= ((struct elf_dyn_relocs
*)
1075 elf_section_data (s
)->local_dynrel
);
1079 if (!bfd_is_abs_section (p
->sec
)
1080 && bfd_is_abs_section (p
->sec
->output_section
))
1082 /* Input section has been discarded, either because
1083 it is a copy of a linkonce section or due to
1084 linker script /DISCARD/, so we'll be discarding
1087 else if (htab
->target_os
== is_vxworks
1088 && strcmp (p
->sec
->output_section
->name
,
1091 /* Relocations in vxworks .tls_vars sections are
1092 handled specially by the loader. */
1094 else if (p
->count
!= 0)
1096 srel
= elf_section_data (p
->sec
)->sreloc
;
1097 srel
->size
+= p
->count
* htab
->sizeof_reloc
;
1098 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
1099 && (info
->flags
& DF_TEXTREL
) == 0)
1101 info
->flags
|= DF_TEXTREL
;
1102 if (bfd_link_textrel_check (info
))
1103 /* xgettext:c-format */
1104 info
->callbacks
->einfo
1105 (_("%P: %pB: warning: relocation "
1106 "in read-only section `%pA'\n"),
1107 p
->sec
->owner
, p
->sec
);
1113 local_got
= elf_local_got_refcounts (ibfd
);
1117 symtab_hdr
= &elf_symtab_hdr (ibfd
);
1118 locsymcount
= symtab_hdr
->sh_info
;
1119 end_local_got
= local_got
+ locsymcount
;
1120 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
1121 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
1123 srel
= htab
->elf
.srelgot
;
1124 for (; local_got
< end_local_got
;
1125 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1127 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1130 if (GOT_TLS_GDESC_P (*local_tls_type
))
1132 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
1133 - elf_x86_compute_jump_table_size (htab
);
1134 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
1135 *local_got
= (bfd_vma
) -2;
1137 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1138 || GOT_TLS_GD_P (*local_tls_type
))
1140 *local_got
= s
->size
;
1141 s
->size
+= htab
->got_entry_size
;
1142 if (GOT_TLS_GD_P (*local_tls_type
)
1143 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1144 s
->size
+= htab
->got_entry_size
;
1146 if ((bfd_link_pic (info
) && *local_tls_type
!= GOT_ABS
)
1147 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1148 || (*local_tls_type
& GOT_TLS_IE
))
1150 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1151 srel
->size
+= 2 * htab
->sizeof_reloc
;
1152 else if (GOT_TLS_GD_P (*local_tls_type
)
1153 || ! GOT_TLS_GDESC_P (*local_tls_type
))
1154 srel
->size
+= htab
->sizeof_reloc
;
1155 if (GOT_TLS_GDESC_P (*local_tls_type
))
1157 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
1158 if (bed
->target_id
== X86_64_ELF_DATA
)
1159 htab
->tlsdesc_plt
= (bfd_vma
) -1;
1164 *local_got
= (bfd_vma
) -1;
1168 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
1170 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1171 or R_X86_64_TLSLD relocs. */
1172 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
1173 htab
->elf
.sgot
->size
+= 2 * htab
->got_entry_size
;
1174 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
1177 htab
->tls_ld_or_ldm_got
.offset
= -1;
1179 /* Allocate global sym .plt and .got entries, and space for global
1180 sym dynamic relocs. */
1181 elf_link_hash_traverse (&htab
->elf
, elf_x86_allocate_dynrelocs
,
1184 /* Allocate .plt and .got entries, and space for local symbols. */
1185 htab_traverse (htab
->loc_hash_table
, elf_x86_allocate_local_dynreloc
,
1188 /* For every jump slot reserved in the sgotplt, reloc_count is
1189 incremented. However, when we reserve space for TLS descriptors,
1190 it's not incremented, so in order to compute the space reserved
1191 for them, it suffices to multiply the reloc count by the jump
1194 PR ld/13302: We start next_irelative_index at the end of .rela.plt
1195 so that R_{386,X86_64}_IRELATIVE entries come last. */
1196 if (htab
->elf
.srelplt
)
1198 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
1199 htab
->sgotplt_jump_table_size
1200 = elf_x86_compute_jump_table_size (htab
);
1201 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
1203 else if (htab
->elf
.irelplt
)
1204 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
1206 if (htab
->tlsdesc_plt
)
1208 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
1209 lazy TLS relocations, don't generate the PLT and GOT entries
1211 if ((info
->flags
& DF_BIND_NOW
))
1212 htab
->tlsdesc_plt
= 0;
1215 htab
->tlsdesc_got
= htab
->elf
.sgot
->size
;
1216 htab
->elf
.sgot
->size
+= htab
->got_entry_size
;
1217 /* Reserve room for the initial entry.
1218 FIXME: we could probably do away with it in this case. */
1219 if (htab
->elf
.splt
->size
== 0)
1220 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
1221 htab
->tlsdesc_plt
= htab
->elf
.splt
->size
;
1222 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
1226 if (htab
->elf
.sgotplt
)
1228 /* Don't allocate .got.plt section if there are no GOT nor PLT
1229 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
1230 if ((htab
->elf
.hgot
== NULL
1231 || !htab
->got_referenced
)
1232 && (htab
->elf
.sgotplt
->size
== bed
->got_header_size
)
1233 && (htab
->elf
.splt
== NULL
1234 || htab
->elf
.splt
->size
== 0)
1235 && (htab
->elf
.sgot
== NULL
1236 || htab
->elf
.sgot
->size
== 0)
1237 && (htab
->elf
.iplt
== NULL
1238 || htab
->elf
.iplt
->size
== 0)
1239 && (htab
->elf
.igotplt
== NULL
1240 || htab
->elf
.igotplt
->size
== 0))
1242 htab
->elf
.sgotplt
->size
= 0;
1243 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
1245 if (htab
->elf
.hgot
!= NULL
&& htab
->target_os
!= is_solaris
)
1247 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
1249 htab
->elf
.hgot
->root
.type
= bfd_link_hash_undefined
;
1250 htab
->elf
.hgot
->root
.u
.undef
.abfd
1251 = htab
->elf
.hgot
->root
.u
.def
.section
->owner
;
1252 htab
->elf
.hgot
->root
.linker_def
= 0;
1253 htab
->elf
.hgot
->ref_regular
= 0;
1254 htab
->elf
.hgot
->def_regular
= 0;
1259 if (_bfd_elf_eh_frame_present (info
))
1261 if (htab
->plt_eh_frame
!= NULL
1262 && htab
->elf
.splt
!= NULL
1263 && htab
->elf
.splt
->size
!= 0
1264 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
1265 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
1267 if (htab
->plt_got_eh_frame
!= NULL
1268 && htab
->plt_got
!= NULL
1269 && htab
->plt_got
->size
!= 0
1270 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
1271 htab
->plt_got_eh_frame
->size
1272 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1274 /* Unwind info for the second PLT and .plt.got sections are
1276 if (htab
->plt_second_eh_frame
!= NULL
1277 && htab
->plt_second
!= NULL
1278 && htab
->plt_second
->size
!= 0
1279 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
1280 htab
->plt_second_eh_frame
->size
1281 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1284 /* We now have determined the sizes of the various dynamic sections.
1285 Allocate memory for them. */
1287 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1289 bfd_boolean strip_section
= TRUE
;
1291 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1294 if (s
== htab
->elf
.splt
1295 || s
== htab
->elf
.sgot
)
1297 /* Strip this section if we don't need it; see the
1299 /* We'd like to strip these sections if they aren't needed, but if
1300 we've exported dynamic symbols from them we must leave them.
1301 It's too late to tell BFD to get rid of the symbols. */
1303 if (htab
->elf
.hplt
!= NULL
)
1304 strip_section
= FALSE
;
1306 else if (s
== htab
->elf
.sgotplt
1307 || s
== htab
->elf
.iplt
1308 || s
== htab
->elf
.igotplt
1309 || s
== htab
->plt_second
1310 || s
== htab
->plt_got
1311 || s
== htab
->plt_eh_frame
1312 || s
== htab
->plt_got_eh_frame
1313 || s
== htab
->plt_second_eh_frame
1314 || s
== htab
->elf
.sdynbss
1315 || s
== htab
->elf
.sdynrelro
)
1317 /* Strip these too. */
1319 else if (htab
->is_reloc_section (bfd_section_name (s
)))
1322 && s
!= htab
->elf
.srelplt
1323 && s
!= htab
->srelplt2
)
1326 /* We use the reloc_count field as a counter if we need
1327 to copy relocs into the output file. */
1328 if (s
!= htab
->elf
.srelplt
)
1333 /* It's not one of our sections, so don't allocate space. */
1339 /* If we don't need this section, strip it from the
1340 output file. This is mostly to handle .rel.bss and
1341 .rel.plt. We must create both sections in
1342 create_dynamic_sections, because they must be created
1343 before the linker maps input sections to output
1344 sections. The linker does that before
1345 adjust_dynamic_symbol is called, and it is that
1346 function which decides whether anything needs to go
1347 into these sections. */
1349 s
->flags
|= SEC_EXCLUDE
;
1353 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1356 /* NB: Initially, the iplt section has minimal alignment to
1357 avoid moving dot of the following section backwards when
1358 it is empty. Update its section alignment now since it
1360 if (s
== htab
->elf
.iplt
)
1361 bfd_set_section_alignment (s
, htab
->plt
.iplt_alignment
);
1363 /* Allocate memory for the section contents. We use bfd_zalloc
1364 here in case unused entries are not reclaimed before the
1365 section's contents are written out. This should not happen,
1366 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
1367 reloc instead of garbage. */
1368 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
1369 if (s
->contents
== NULL
)
1373 if (htab
->plt_eh_frame
!= NULL
1374 && htab
->plt_eh_frame
->contents
!= NULL
)
1376 memcpy (htab
->plt_eh_frame
->contents
,
1377 htab
->plt
.eh_frame_plt
,
1378 htab
->plt_eh_frame
->size
);
1379 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
1380 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
1383 if (htab
->plt_got_eh_frame
!= NULL
1384 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1386 memcpy (htab
->plt_got_eh_frame
->contents
,
1387 htab
->non_lazy_plt
->eh_frame_plt
,
1388 htab
->plt_got_eh_frame
->size
);
1389 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
1390 (htab
->plt_got_eh_frame
->contents
1391 + PLT_FDE_LEN_OFFSET
));
1394 if (htab
->plt_second_eh_frame
!= NULL
1395 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1397 memcpy (htab
->plt_second_eh_frame
->contents
,
1398 htab
->non_lazy_plt
->eh_frame_plt
,
1399 htab
->plt_second_eh_frame
->size
);
1400 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
1401 (htab
->plt_second_eh_frame
->contents
1402 + PLT_FDE_LEN_OFFSET
));
1405 if (htab
->elf
.dynamic_sections_created
)
1407 /* Add some entries to the .dynamic section. We fill in the
1408 values later, in elf_{i386,x86_64}_finish_dynamic_sections,
1409 but we must add the entries now so that we get the correct
1410 size for the .dynamic section. The DT_DEBUG entry is filled
1411 in by the dynamic linker and used by the debugger. */
1412 #define add_dynamic_entry(TAG, VAL) \
1413 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1415 if (bfd_link_executable (info
))
1417 if (!add_dynamic_entry (DT_DEBUG
, 0))
1421 if (htab
->elf
.splt
->size
!= 0)
1423 /* DT_PLTGOT is used by prelink even if there is no PLT
1425 if (!add_dynamic_entry (DT_PLTGOT
, 0))
1429 if (htab
->elf
.srelplt
->size
!= 0)
1431 if (!add_dynamic_entry (DT_PLTRELSZ
, 0)
1432 || !add_dynamic_entry (DT_PLTREL
, htab
->dt_reloc
)
1433 || !add_dynamic_entry (DT_JMPREL
, 0))
1437 if (htab
->tlsdesc_plt
1438 && (!add_dynamic_entry (DT_TLSDESC_PLT
, 0)
1439 || !add_dynamic_entry (DT_TLSDESC_GOT
, 0)))
1444 if (!add_dynamic_entry (htab
->dt_reloc
, 0)
1445 || !add_dynamic_entry (htab
->dt_reloc_sz
, 0)
1446 || !add_dynamic_entry (htab
->dt_reloc_ent
,
1447 htab
->sizeof_reloc
))
1450 /* If any dynamic relocs apply to a read-only section,
1451 then we need a DT_TEXTREL entry. */
1452 if ((info
->flags
& DF_TEXTREL
) == 0)
1453 elf_link_hash_traverse (&htab
->elf
, maybe_set_textrel
, info
);
1455 if ((info
->flags
& DF_TEXTREL
) != 0)
1457 if (htab
->readonly_dynrelocs_against_ifunc
)
1459 info
->callbacks
->einfo
1460 (_("%P%X: read-only segment has dynamic IFUNC relocations;"
1461 " recompile with %s\n"),
1462 bfd_link_dll (info
) ? "-fPIC" : "-fPIE");
1463 bfd_set_error (bfd_error_bad_value
);
1467 if (!add_dynamic_entry (DT_TEXTREL
, 0))
1471 if (htab
->target_os
== is_vxworks
1472 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
1475 #undef add_dynamic_entry
1480 /* Finish up the x86 dynamic sections. */
1482 struct elf_x86_link_hash_table
*
1483 _bfd_x86_elf_finish_dynamic_sections (bfd
*output_bfd
,
1484 struct bfd_link_info
*info
)
1486 struct elf_x86_link_hash_table
*htab
;
1487 const struct elf_backend_data
*bed
;
1490 bfd_byte
*dyncon
, *dynconend
;
1491 bfd_size_type sizeof_dyn
;
1493 bed
= get_elf_backend_data (output_bfd
);
1494 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1498 dynobj
= htab
->elf
.dynobj
;
1499 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
1501 /* GOT is always created in setup_gnu_properties. But it may not be
1502 needed. .got.plt section may be needed for static IFUNC. */
1503 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
1505 bfd_vma dynamic_addr
;
1507 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
1510 (_("discarded output section: `%pA'"), htab
->elf
.sgotplt
);
1514 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
1515 = htab
->got_entry_size
;
1517 dynamic_addr
= (sdyn
== NULL
1519 : sdyn
->output_section
->vma
+ sdyn
->output_offset
);
1521 /* Set the first entry in the global offset table to the address
1522 of the dynamic section. Write GOT[1] and GOT[2], needed for
1523 the dynamic linker. */
1524 if (htab
->got_entry_size
== 8)
1526 bfd_put_64 (output_bfd
, dynamic_addr
,
1527 htab
->elf
.sgotplt
->contents
);
1528 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1529 htab
->elf
.sgotplt
->contents
+ 8);
1530 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1531 htab
->elf
.sgotplt
->contents
+ 8*2);
1535 bfd_put_32 (output_bfd
, dynamic_addr
,
1536 htab
->elf
.sgotplt
->contents
);
1537 bfd_put_32 (output_bfd
, 0,
1538 htab
->elf
.sgotplt
->contents
+ 4);
1539 bfd_put_32 (output_bfd
, 0,
1540 htab
->elf
.sgotplt
->contents
+ 4*2);
1544 if (!htab
->elf
.dynamic_sections_created
)
1547 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
1550 sizeof_dyn
= bed
->s
->sizeof_dyn
;
1551 dyncon
= sdyn
->contents
;
1552 dynconend
= sdyn
->contents
+ sdyn
->size
;
1553 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
1555 Elf_Internal_Dyn dyn
;
1558 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
1563 if (htab
->target_os
== is_vxworks
1564 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
1569 s
= htab
->elf
.sgotplt
;
1570 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
1574 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
1578 s
= htab
->elf
.srelplt
->output_section
;
1579 dyn
.d_un
.d_val
= s
->size
;
1582 case DT_TLSDESC_PLT
:
1584 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1585 + htab
->tlsdesc_plt
;
1588 case DT_TLSDESC_GOT
:
1590 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1591 + htab
->tlsdesc_got
;
1595 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
1598 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
1599 elf_section_data (htab
->plt_got
->output_section
)
1600 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1602 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
1603 elf_section_data (htab
->plt_second
->output_section
)
1604 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1606 /* Adjust .eh_frame for .plt section. */
1607 if (htab
->plt_eh_frame
!= NULL
1608 && htab
->plt_eh_frame
->contents
!= NULL
)
1610 if (htab
->elf
.splt
!= NULL
1611 && htab
->elf
.splt
->size
!= 0
1612 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
1613 && htab
->elf
.splt
->output_section
!= NULL
1614 && htab
->plt_eh_frame
->output_section
!= NULL
)
1616 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
1617 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
1618 + htab
->plt_eh_frame
->output_offset
1619 + PLT_FDE_START_OFFSET
;
1620 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1621 htab
->plt_eh_frame
->contents
1622 + PLT_FDE_START_OFFSET
);
1625 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1627 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1629 htab
->plt_eh_frame
->contents
))
1634 /* Adjust .eh_frame for .plt.got section. */
1635 if (htab
->plt_got_eh_frame
!= NULL
1636 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1638 if (htab
->plt_got
!= NULL
1639 && htab
->plt_got
->size
!= 0
1640 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
1641 && htab
->plt_got
->output_section
!= NULL
1642 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
1644 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
1645 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
1646 + htab
->plt_got_eh_frame
->output_offset
1647 + PLT_FDE_START_OFFSET
;
1648 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1649 htab
->plt_got_eh_frame
->contents
1650 + PLT_FDE_START_OFFSET
);
1652 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1654 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1655 htab
->plt_got_eh_frame
,
1656 htab
->plt_got_eh_frame
->contents
))
1661 /* Adjust .eh_frame for the second PLT section. */
1662 if (htab
->plt_second_eh_frame
!= NULL
1663 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1665 if (htab
->plt_second
!= NULL
1666 && htab
->plt_second
->size
!= 0
1667 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
1668 && htab
->plt_second
->output_section
!= NULL
1669 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
1671 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
1672 bfd_vma eh_frame_start
1673 = (htab
->plt_second_eh_frame
->output_section
->vma
1674 + htab
->plt_second_eh_frame
->output_offset
1675 + PLT_FDE_START_OFFSET
);
1676 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1677 htab
->plt_second_eh_frame
->contents
1678 + PLT_FDE_START_OFFSET
);
1680 if (htab
->plt_second_eh_frame
->sec_info_type
1681 == SEC_INFO_TYPE_EH_FRAME
)
1683 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1684 htab
->plt_second_eh_frame
,
1685 htab
->plt_second_eh_frame
->contents
))
1690 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
1691 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
1692 = htab
->got_entry_size
;
1699 _bfd_x86_elf_always_size_sections (bfd
*output_bfd
,
1700 struct bfd_link_info
*info
)
1702 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
1706 struct elf_link_hash_entry
*tlsbase
;
1708 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
1709 "_TLS_MODULE_BASE_",
1710 FALSE
, FALSE
, FALSE
);
1712 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
1714 struct elf_x86_link_hash_table
*htab
;
1715 struct bfd_link_hash_entry
*bh
= NULL
;
1716 const struct elf_backend_data
*bed
1717 = get_elf_backend_data (output_bfd
);
1719 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1723 if (!(_bfd_generic_link_add_one_symbol
1724 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
1725 tls_sec
, 0, NULL
, FALSE
,
1726 bed
->collect
, &bh
)))
1729 htab
->tls_module_base
= bh
;
1731 tlsbase
= (struct elf_link_hash_entry
*)bh
;
1732 tlsbase
->def_regular
= 1;
1733 tlsbase
->other
= STV_HIDDEN
;
1734 tlsbase
->root
.linker_def
= 1;
1735 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, TRUE
);
1743 _bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
1744 const Elf_Internal_Sym
*isym
,
1745 bfd_boolean definition
,
1746 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
1750 struct elf_x86_link_hash_entry
*eh
1751 = (struct elf_x86_link_hash_entry
*) h
;
1752 eh
->def_protected
= (ELF_ST_VISIBILITY (isym
->st_other
)
1757 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1760 _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
1761 struct elf_link_hash_entry
*dir
,
1762 struct elf_link_hash_entry
*ind
)
1764 struct elf_x86_link_hash_entry
*edir
, *eind
;
1766 edir
= (struct elf_x86_link_hash_entry
*) dir
;
1767 eind
= (struct elf_x86_link_hash_entry
*) ind
;
1769 if (ind
->root
.type
== bfd_link_hash_indirect
1770 && dir
->got
.refcount
<= 0)
1772 edir
->tls_type
= eind
->tls_type
;
1773 eind
->tls_type
= GOT_UNKNOWN
;
1776 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1777 generate a R_386_COPY reloc. */
1778 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1780 edir
->zero_undefweak
|= eind
->zero_undefweak
;
1782 if (ELIMINATE_COPY_RELOCS
1783 && ind
->root
.type
!= bfd_link_hash_indirect
1784 && dir
->dynamic_adjusted
)
1786 /* If called to transfer flags for a weakdef during processing
1787 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1788 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1789 if (dir
->versioned
!= versioned_hidden
)
1790 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1791 dir
->ref_regular
|= ind
->ref_regular
;
1792 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1793 dir
->needs_plt
|= ind
->needs_plt
;
1794 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1797 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1800 /* Remove undefined weak symbol from the dynamic symbol table if it
1801 is resolved to 0. */
1804 _bfd_x86_elf_fixup_symbol (struct bfd_link_info
*info
,
1805 struct elf_link_hash_entry
*h
)
1807 if (h
->dynindx
!= -1
1808 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, elf_x86_hash_entry (h
)))
1811 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1817 /* Change the STT_GNU_IFUNC symbol defined in position-dependent
1818 executable into the normal function symbol and set its address
1819 to its PLT entry, which should be resolved by R_*_IRELATIVE at
1823 _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info
*info
,
1824 struct elf_x86_link_hash_table
*htab
,
1825 struct elf_link_hash_entry
*h
,
1826 Elf_Internal_Sym
*sym
)
1828 if (bfd_link_pde (info
)
1831 && h
->plt
.offset
!= (bfd_vma
) -1
1832 && h
->type
== STT_GNU_IFUNC
1833 && h
->pointer_equality_needed
)
1837 bfd
*output_bfd
= info
->output_bfd
;
1839 if (htab
->plt_second
)
1841 struct elf_x86_link_hash_entry
*eh
1842 = (struct elf_x86_link_hash_entry
*) h
;
1844 plt_s
= htab
->plt_second
;
1845 plt_offset
= eh
->plt_second
.offset
;
1849 plt_s
= htab
->elf
.splt
;
1850 plt_offset
= h
->plt
.offset
;
1854 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
1856 = _bfd_elf_section_from_bfd_section (output_bfd
,
1857 plt_s
->output_section
);
1858 sym
->st_value
= (plt_s
->output_section
->vma
1859 + plt_s
->output_offset
+ plt_offset
);
1863 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
1866 _bfd_x86_elf_hash_symbol (struct elf_link_hash_entry
*h
)
1868 if (h
->plt
.offset
!= (bfd_vma
) -1
1870 && !h
->pointer_equality_needed
)
1873 return _bfd_elf_hash_symbol (h
);
1876 /* Adjust a symbol defined by a dynamic object and referenced by a
1877 regular object. The current definition is in some section of the
1878 dynamic object, but we're not including those sections. We have to
1879 change the definition to something the rest of the link can
1883 _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1884 struct elf_link_hash_entry
*h
)
1886 struct elf_x86_link_hash_table
*htab
;
1888 struct elf_x86_link_hash_entry
*eh
;
1889 struct elf_dyn_relocs
*p
;
1890 const struct elf_backend_data
*bed
1891 = get_elf_backend_data (info
->output_bfd
);
1893 /* STT_GNU_IFUNC symbol must go through PLT. */
1894 if (h
->type
== STT_GNU_IFUNC
)
1896 /* All local STT_GNU_IFUNC references must be treate as local
1897 calls via local PLT. */
1899 && SYMBOL_CALLS_LOCAL (info
, h
))
1901 bfd_size_type pc_count
= 0, count
= 0;
1902 struct elf_dyn_relocs
**pp
;
1904 eh
= (struct elf_x86_link_hash_entry
*) h
;
1905 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
1907 pc_count
+= p
->pc_count
;
1908 p
->count
-= p
->pc_count
;
1917 if (pc_count
|| count
)
1922 /* Increment PLT reference count only for PC-relative
1925 if (h
->plt
.refcount
<= 0)
1926 h
->plt
.refcount
= 1;
1928 h
->plt
.refcount
+= 1;
1933 if (h
->plt
.refcount
<= 0)
1935 h
->plt
.offset
= (bfd_vma
) -1;
1941 /* If this is a function, put it in the procedure linkage table. We
1942 will fill in the contents of the procedure linkage table later,
1943 when we know the address of the .got section. */
1944 if (h
->type
== STT_FUNC
1947 if (h
->plt
.refcount
<= 0
1948 || SYMBOL_CALLS_LOCAL (info
, h
)
1949 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1950 && h
->root
.type
== bfd_link_hash_undefweak
))
1952 /* This case can occur if we saw a PLT32 reloc in an input
1953 file, but the symbol was never referred to by a dynamic
1954 object, or if all references were garbage collected. In
1955 such a case, we don't actually need to build a procedure
1956 linkage table, and we can just do a PC32 reloc instead. */
1957 h
->plt
.offset
= (bfd_vma
) -1;
1964 /* It's possible that we incorrectly decided a .plt reloc was needed
1965 * for an R_386_PC32/R_X86_64_PC32 reloc to a non-function sym in
1966 check_relocs. We can't decide accurately between function and
1967 non-function syms in check-relocs; Objects loaded later in
1968 the link may change h->type. So fix it now. */
1969 h
->plt
.offset
= (bfd_vma
) -1;
1971 eh
= (struct elf_x86_link_hash_entry
*) h
;
1973 /* If this is a weak symbol, and there is a real definition, the
1974 processor independent code will have arranged for us to see the
1975 real definition first, and we can just use the same value. */
1976 if (h
->is_weakalias
)
1978 struct elf_link_hash_entry
*def
= weakdef (h
);
1979 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1980 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1981 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1982 if (ELIMINATE_COPY_RELOCS
1983 || info
->nocopyreloc
1984 || SYMBOL_NO_COPYRELOC (info
, eh
))
1986 /* NB: needs_copy is always 0 for i386. */
1987 h
->non_got_ref
= def
->non_got_ref
;
1988 eh
->needs_copy
= def
->needs_copy
;
1993 /* This is a reference to a symbol defined by a dynamic object which
1994 is not a function. */
1996 /* If we are creating a shared library, we must presume that the
1997 only references to the symbol are via the global offset table.
1998 For such cases we need not do anything here; the relocations will
1999 be handled correctly by relocate_section. */
2000 if (!bfd_link_executable (info
))
2003 /* If there are no references to this symbol that do not use the
2004 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
2005 reloc. NB: gotoff_ref is always 0 for x86-64. */
2006 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
2009 /* If -z nocopyreloc was given, we won't generate them either. */
2010 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
2016 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2020 /* If there aren't any dynamic relocs in read-only sections nor
2021 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
2022 avoid the copy reloc. This doesn't work on VxWorks, where we can
2023 not have dynamic relocations (other than copy and jump slot
2024 relocations) in an executable. */
2025 if (ELIMINATE_COPY_RELOCS
2026 && (bed
->target_id
== X86_64_ELF_DATA
2028 && htab
->target_os
!= is_vxworks
)))
2030 /* If we don't find any dynamic relocs in read-only sections,
2031 then we'll be keeping the dynamic relocs and avoiding the copy
2033 if (!_bfd_elf_readonly_dynrelocs (h
))
2040 /* We must allocate the symbol in our .dynbss section, which will
2041 become part of the .bss section of the executable. There will be
2042 an entry for this symbol in the .dynsym section. The dynamic
2043 object will contain position independent code, so all references
2044 from the dynamic object to this symbol will go through the global
2045 offset table. The dynamic linker will use the .dynsym entry to
2046 determine the address it must put in the global offset table, so
2047 both the dynamic object and the regular object will refer to the
2048 same memory location for the variable. */
2050 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
2051 dynamic linker to copy the initial value out of the dynamic object
2052 and into the runtime process image. */
2053 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2055 s
= htab
->elf
.sdynrelro
;
2056 srel
= htab
->elf
.sreldynrelro
;
2060 s
= htab
->elf
.sdynbss
;
2061 srel
= htab
->elf
.srelbss
;
2063 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2065 srel
->size
+= htab
->sizeof_reloc
;
2069 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2073 _bfd_x86_elf_hide_symbol (struct bfd_link_info
*info
,
2074 struct elf_link_hash_entry
*h
,
2075 bfd_boolean force_local
)
2077 if (h
->root
.type
== bfd_link_hash_undefweak
2079 && bfd_link_pie (info
))
2081 /* When there is no dynamic interpreter in PIE, make the undefined
2082 weak symbol dynamic so that PC relative branch to the undefined
2083 weak symbol will land to address 0. */
2084 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2085 if (h
->plt
.refcount
> 0
2086 || eh
->plt_got
.refcount
> 0)
2090 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
2093 /* Return TRUE if a symbol is referenced locally. It is similar to
2094 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
2095 works in check_relocs. */
2098 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info
*info
,
2099 struct elf_link_hash_entry
*h
)
2101 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2102 struct elf_x86_link_hash_table
*htab
2103 = (struct elf_x86_link_hash_table
*) info
->hash
;
2105 if (eh
->local_ref
> 1)
2108 if (eh
->local_ref
== 1)
2111 /* Unversioned symbols defined in regular objects can be forced local
2112 by linker version script. A weak undefined symbol is forced local
2114 1. It has non-default visibility. Or
2115 2. When building executable, there is no dynamic linker. Or
2116 3. or "-z nodynamic-undefined-weak" is used.
2118 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
2119 || (h
->root
.type
== bfd_link_hash_undefweak
2120 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2121 || (bfd_link_executable (info
)
2122 && htab
->interp
== NULL
)
2123 || info
->dynamic_undefined_weak
== 0))
2124 || ((h
->def_regular
|| ELF_COMMON_DEF_P (h
))
2125 && info
->version_info
!= NULL
2126 && _bfd_elf_link_hide_sym_by_version (info
, h
)))
2136 /* Return the section that should be marked against GC for a given
2140 _bfd_x86_elf_gc_mark_hook (asection
*sec
,
2141 struct bfd_link_info
*info
,
2142 Elf_Internal_Rela
*rel
,
2143 struct elf_link_hash_entry
*h
,
2144 Elf_Internal_Sym
*sym
)
2146 /* Compiler should optimize this out. */
2147 if (((unsigned int) R_X86_64_GNU_VTINHERIT
2148 != (unsigned int) R_386_GNU_VTINHERIT
)
2149 || ((unsigned int) R_X86_64_GNU_VTENTRY
2150 != (unsigned int) R_386_GNU_VTENTRY
))
2154 switch (ELF32_R_TYPE (rel
->r_info
))
2156 case R_X86_64_GNU_VTINHERIT
:
2157 case R_X86_64_GNU_VTENTRY
:
2161 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2165 elf_i386_get_plt_got_vma (struct elf_x86_plt
*plt_p ATTRIBUTE_UNUSED
,
2167 bfd_vma offset ATTRIBUTE_UNUSED
,
2170 return got_addr
+ off
;
2174 elf_x86_64_get_plt_got_vma (struct elf_x86_plt
*plt_p
,
2177 bfd_vma got_addr ATTRIBUTE_UNUSED
)
2179 return plt_p
->sec
->vma
+ offset
+ off
+ plt_p
->plt_got_insn_size
;
2183 elf_i386_valid_plt_reloc_p (unsigned int type
)
2185 return (type
== R_386_JUMP_SLOT
2186 || type
== R_386_GLOB_DAT
2187 || type
== R_386_IRELATIVE
);
2191 elf_x86_64_valid_plt_reloc_p (unsigned int type
)
2193 return (type
== R_X86_64_JUMP_SLOT
2194 || type
== R_X86_64_GLOB_DAT
2195 || type
== R_X86_64_IRELATIVE
);
2199 _bfd_x86_elf_get_synthetic_symtab (bfd
*abfd
,
2203 struct elf_x86_plt plts
[],
2207 long size
, i
, n
, len
;
2209 unsigned int plt_got_offset
, plt_entry_size
;
2211 bfd_byte
*plt_contents
;
2213 arelent
**dynrelbuf
, *p
;
2215 const struct elf_backend_data
*bed
;
2216 bfd_vma (*get_plt_got_vma
) (struct elf_x86_plt
*, bfd_vma
, bfd_vma
,
2218 bfd_boolean (*valid_plt_reloc_p
) (unsigned int);
2224 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
2225 if (dynrelbuf
== NULL
)
2228 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
2230 if (dynrelcount
<= 0)
2233 /* Sort the relocs by address. */
2234 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
2235 _bfd_x86_elf_compare_relocs
);
2237 size
= count
* sizeof (asymbol
);
2239 /* Allocate space for @plt suffixes. */
2241 for (i
= 0; i
< dynrelcount
; i
++)
2244 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2246 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
2249 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
2253 bed
= get_elf_backend_data (abfd
);
2255 if (bed
->target_id
== X86_64_ELF_DATA
)
2257 get_plt_got_vma
= elf_x86_64_get_plt_got_vma
;
2258 valid_plt_reloc_p
= elf_x86_64_valid_plt_reloc_p
;
2262 get_plt_got_vma
= elf_i386_get_plt_got_vma
;
2263 valid_plt_reloc_p
= elf_i386_valid_plt_reloc_p
;
2266 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
2268 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
2270 got_addr
= sec
->vma
;
2273 sec
= bfd_get_section_by_name (abfd
, ".got");
2275 got_addr
= sec
->vma
;
2278 if (got_addr
== (bfd_vma
) -1)
2283 /* Check for each PLT section. */
2284 names
= (char *) (s
+ count
);
2287 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2288 if ((plt_contents
= plts
[j
].contents
) != NULL
)
2293 struct elf_x86_plt
*plt_p
= &plts
[j
];
2295 plt_got_offset
= plt_p
->plt_got_offset
;
2296 plt_entry_size
= plt_p
->plt_entry_size
;
2300 if ((plt_p
->type
& plt_lazy
))
2302 /* Skip PLT0 in lazy PLT. */
2304 offset
= plt_entry_size
;
2312 /* Check each PLT entry against dynamic relocations. */
2313 for (; k
< plt_p
->count
; k
++)
2319 /* Get the GOT offset for i386 or the PC-relative offset
2320 for x86-64, a signed 32-bit integer. */
2321 off
= H_GET_32 (abfd
, (plt_contents
+ offset
2323 got_vma
= get_plt_got_vma (plt_p
, off
, offset
, got_addr
);
2325 /* Binary search. */
2329 while ((min
+ 1) < max
)
2333 mid
= (min
+ max
) / 2;
2335 if (got_vma
> r
->address
)
2337 else if (got_vma
< r
->address
)
2346 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
2347 if (got_vma
== p
->address
2349 && valid_plt_reloc_p (p
->howto
->type
))
2351 *s
= **p
->sym_ptr_ptr
;
2352 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
2353 set. Since we are defining a symbol, ensure one
2355 if ((s
->flags
& BSF_LOCAL
) == 0)
2356 s
->flags
|= BSF_GLOBAL
;
2357 s
->flags
|= BSF_SYNTHETIC
;
2358 /* This is no longer a section symbol. */
2359 s
->flags
&= ~BSF_SECTION_SYM
;
2361 s
->the_bfd
= plt
->owner
;
2365 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2366 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2372 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2373 names
+= sizeof ("+0x") - 1;
2374 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
2375 for (a
= buf
; *a
== '0'; ++a
)
2378 memcpy (names
, a
, size
);
2381 memcpy (names
, "@plt", sizeof ("@plt"));
2382 names
+= sizeof ("@plt");
2385 /* There should be only one entry in PLT for a given
2386 symbol. Set howto to NULL after processing a PLT
2387 entry to guard against corrupted PLT. */
2390 offset
+= plt_entry_size
;
2394 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
2403 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2404 free (plts
[j
].contents
);
2411 /* Parse x86 GNU properties. */
2413 enum elf_property_kind
2414 _bfd_x86_elf_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
2415 bfd_byte
*ptr
, unsigned int datasz
)
2419 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2420 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2421 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2422 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2423 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2424 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
2425 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2426 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2431 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
2432 abfd
, type
, datasz
);
2433 return property_corrupt
;
2435 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
2436 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
2437 prop
->pr_kind
= property_number
;
2438 return property_number
;
2441 return property_ignored
;
2444 /* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
2445 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
2446 should be merged with ABFD. */
2449 _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info
*info
,
2450 bfd
*abfd ATTRIBUTE_UNUSED
,
2451 bfd
*bbfd ATTRIBUTE_UNUSED
,
2452 elf_property
*aprop
,
2453 elf_property
*bprop
)
2455 unsigned int number
, features
;
2456 bfd_boolean updated
= FALSE
;
2457 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
2459 if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2460 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2461 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2463 if (aprop
== NULL
|| bprop
== NULL
)
2465 /* Only one of APROP and BPROP can be NULL. */
2468 /* Remove this property since the other input file doesn't
2470 aprop
->pr_kind
= property_remove
;
2476 number
= aprop
->u
.number
;
2477 aprop
->u
.number
= number
| bprop
->u
.number
;
2478 updated
= number
!= (unsigned int) aprop
->u
.number
;
2482 else if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2483 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2484 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_HI
))
2486 if (aprop
!= NULL
&& bprop
!= NULL
)
2488 number
= aprop
->u
.number
;
2489 aprop
->u
.number
= number
| bprop
->u
.number
;
2490 /* Remove the property if all bits are empty. */
2491 if (aprop
->u
.number
== 0)
2493 aprop
->pr_kind
= property_remove
;
2497 updated
= number
!= (unsigned int) aprop
->u
.number
;
2501 /* Only one of APROP and BPROP can be NULL. */
2504 if (aprop
->u
.number
== 0)
2506 /* Remove APROP if all bits are empty. */
2507 aprop
->pr_kind
= property_remove
;
2513 /* Return TRUE if APROP is NULL and all bits of BPROP
2514 aren't empty to indicate that BPROP should be added
2516 updated
= bprop
->u
.number
!= 0;
2521 else if (pr_type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2522 && pr_type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2524 /* Only one of APROP and BPROP can be NULL:
2525 1. APROP & BPROP when both APROP and BPROP aren't NULL.
2526 2. If APROP is NULL, remove x86 feature.
2527 3. Otherwise, do nothing.
2529 const struct elf_backend_data
*bed
2530 = get_elf_backend_data (info
->output_bfd
);
2531 struct elf_x86_link_hash_table
*htab
2532 = elf_x86_hash_table (info
, bed
->target_id
);
2535 if (aprop
!= NULL
&& bprop
!= NULL
)
2538 if (htab
->params
->ibt
)
2539 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2540 if (htab
->params
->shstk
)
2541 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2542 number
= aprop
->u
.number
;
2543 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
2544 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
2545 aprop
->u
.number
= (number
& bprop
->u
.number
) | features
;
2546 updated
= number
!= (unsigned int) aprop
->u
.number
;
2547 /* Remove the property if all feature bits are cleared. */
2548 if (aprop
->u
.number
== 0)
2549 aprop
->pr_kind
= property_remove
;
2553 /* There should be no AND properties since some input doesn't
2554 have them. Set IBT and SHSTK properties for -z ibt and -z
2557 if (htab
->params
->ibt
)
2558 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2559 if (htab
->params
->shstk
)
2560 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2565 updated
= features
!= (unsigned int) aprop
->u
.number
;
2566 aprop
->u
.number
= features
;
2571 bprop
->u
.number
= features
;
2574 else if (aprop
!= NULL
)
2576 aprop
->pr_kind
= property_remove
;
2584 /* Never should happen. */
2591 /* Set up x86 GNU properties. Return the first relocatable ELF input
2592 with GNU properties if found. Otherwise, return NULL. */
2595 _bfd_x86_elf_link_setup_gnu_properties
2596 (struct bfd_link_info
*info
, struct elf_x86_init_table
*init_table
)
2598 bfd_boolean normal_target
;
2599 bfd_boolean lazy_plt
;
2600 asection
*sec
, *pltsec
;
2602 bfd_boolean use_ibt_plt
;
2603 unsigned int plt_alignment
, features
;
2604 struct elf_x86_link_hash_table
*htab
;
2608 const struct elf_backend_data
*bed
;
2609 unsigned int class_align
= ABI_64_P (info
->output_bfd
) ? 3 : 2;
2610 unsigned int got_align
;
2612 /* Find a normal input file with GNU property note. */
2613 for (pbfd
= info
->input_bfds
;
2615 pbfd
= pbfd
->link
.next
)
2616 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
2617 && bfd_count_sections (pbfd
) != 0)
2621 if (elf_properties (pbfd
) != NULL
)
2625 bed
= get_elf_backend_data (info
->output_bfd
);
2627 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2632 if (htab
->params
->ibt
)
2634 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2635 htab
->params
->cet_report
&= ~cet_report_ibt
;
2637 if (htab
->params
->shstk
)
2639 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2640 htab
->params
->cet_report
&= ~cet_report_shstk
;
2642 if (!(htab
->params
->cet_report
& (cet_report_ibt
| cet_report_shstk
)))
2643 htab
->params
->cet_report
= cet_report_none
;
2650 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
2651 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
2652 prop
= _bfd_elf_get_property (ebfd
,
2653 GNU_PROPERTY_X86_FEATURE_1_AND
,
2655 prop
->u
.number
|= features
;
2656 prop
->pr_kind
= property_number
;
2659 /* Create the GNU property note section if needed. */
2660 if (prop
!= NULL
&& pbfd
== NULL
)
2662 sec
= bfd_make_section_with_flags (ebfd
,
2663 NOTE_GNU_PROPERTY_SECTION_NAME
,
2671 info
->callbacks
->einfo (_("%F%P: failed to create GNU property section\n"));
2673 if (!bfd_set_section_alignment (sec
, class_align
))
2676 info
->callbacks
->einfo (_("%F%pA: failed to align section\n"),
2680 elf_section_type (sec
) = SHT_NOTE
;
2684 if (htab
->params
->cet_report
)
2686 /* Report missing IBT and SHSTK properties. */
2689 elf_property_list
*p
;
2690 bfd_boolean missing_ibt
, missing_shstk
;
2691 bfd_boolean check_ibt
2692 = !!(htab
->params
->cet_report
& cet_report_ibt
);
2693 bfd_boolean check_shstk
2694 = !!(htab
->params
->cet_report
& cet_report_shstk
);
2696 if ((htab
->params
->cet_report
& cet_report_warning
))
2697 msg
= _("%P: %pB: warning: missing %s\n");
2699 msg
= _("%X%P: %pB: error: missing %s\n");
2701 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
2702 if (!(abfd
->flags
& (DYNAMIC
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
2703 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
2705 for (p
= elf_properties (abfd
); p
; p
= p
->next
)
2706 if (p
->property
.pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2709 missing_ibt
= check_ibt
;
2710 missing_shstk
= check_shstk
;
2713 missing_ibt
&= !(p
->property
.u
.number
2714 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2715 missing_shstk
&= !(p
->property
.u
.number
2716 & GNU_PROPERTY_X86_FEATURE_1_SHSTK
);
2718 if (missing_ibt
|| missing_shstk
)
2720 const char *missing
;
2721 if (missing_ibt
&& missing_shstk
)
2722 missing
= _("IBT and SHSTK properties");
2723 else if (missing_ibt
)
2724 missing
= _("IBT property");
2726 missing
= _("SHSTK property");
2727 info
->callbacks
->einfo (msg
, abfd
, missing
);
2732 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
2734 htab
->r_info
= init_table
->r_info
;
2735 htab
->r_sym
= init_table
->r_sym
;
2737 if (bfd_link_relocatable (info
))
2740 htab
->plt0_pad_byte
= init_table
->plt0_pad_byte
;
2742 use_ibt_plt
= htab
->params
->ibtplt
|| htab
->params
->ibt
;
2743 if (!use_ibt_plt
&& pbfd
!= NULL
)
2745 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
2746 elf_property_list
*p
;
2748 /* The property list is sorted in order of type. */
2749 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
2751 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
2753 use_ibt_plt
= !!(p
->property
.u
.number
2754 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2757 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
2762 dynobj
= htab
->elf
.dynobj
;
2764 /* Set htab->elf.dynobj here so that there is no need to check and
2765 set it in check_relocs. */
2770 htab
->elf
.dynobj
= pbfd
;
2777 /* Find a normal input file to hold linker created
2779 for (abfd
= info
->input_bfds
;
2781 abfd
= abfd
->link
.next
)
2782 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2784 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0
2785 && bed
->relocs_compatible (abfd
->xvec
,
2786 info
->output_bfd
->xvec
))
2788 htab
->elf
.dynobj
= abfd
;
2795 /* Return if there are no normal input files. */
2799 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
2800 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
2801 canonical function address. */
2802 htab
->plt
.has_plt0
= 1;
2803 normal_target
= htab
->target_os
== is_normal
;
2809 htab
->lazy_plt
= init_table
->lazy_ibt_plt
;
2810 htab
->non_lazy_plt
= init_table
->non_lazy_ibt_plt
;
2814 htab
->lazy_plt
= init_table
->lazy_plt
;
2815 htab
->non_lazy_plt
= init_table
->non_lazy_plt
;
2820 htab
->lazy_plt
= init_table
->lazy_plt
;
2821 htab
->non_lazy_plt
= NULL
;
2824 pltsec
= htab
->elf
.splt
;
2826 /* If the non-lazy PLT is available, use it for all PLT entries if
2827 there are no PLT0 or no .plt section. */
2828 if (htab
->non_lazy_plt
!= NULL
2829 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
2832 if (bfd_link_pic (info
))
2833 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
2835 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
2836 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
2837 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
2838 htab
->plt
.plt_got_insn_size
2839 = htab
->non_lazy_plt
->plt_got_insn_size
;
2840 htab
->plt
.eh_frame_plt_size
2841 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2842 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
2847 if (bfd_link_pic (info
))
2849 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
2850 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
2854 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
2855 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
2857 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
2858 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
2859 htab
->plt
.plt_got_insn_size
2860 = htab
->lazy_plt
->plt_got_insn_size
;
2861 htab
->plt
.eh_frame_plt_size
2862 = htab
->lazy_plt
->eh_frame_plt_size
;
2863 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
2866 if (htab
->target_os
== is_vxworks
2867 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
2870 info
->callbacks
->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
2874 /* Since create_dynamic_sections isn't always called, but GOT
2875 relocations need GOT relocations, create them here so that we
2876 don't need to do it in check_relocs. */
2877 if (htab
->elf
.sgot
== NULL
2878 && !_bfd_elf_create_got_section (dynobj
, info
))
2879 info
->callbacks
->einfo (_("%F%P: failed to create GOT sections\n"));
2881 got_align
= (bed
->target_id
== X86_64_ELF_DATA
) ? 3 : 2;
2883 /* Align .got and .got.plt sections to their entry size. Do it here
2884 instead of in create_dynamic_sections so that they are always
2885 properly aligned even if create_dynamic_sections isn't called. */
2886 sec
= htab
->elf
.sgot
;
2887 if (!bfd_set_section_alignment (sec
, got_align
))
2888 goto error_alignment
;
2890 sec
= htab
->elf
.sgotplt
;
2891 if (!bfd_set_section_alignment (sec
, got_align
))
2892 goto error_alignment
;
2894 /* Create the ifunc sections here so that check_relocs can be
2896 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
2897 info
->callbacks
->einfo (_("%F%P: failed to create ifunc sections\n"));
2899 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
2903 /* Whe creating executable, set the contents of the .interp
2904 section to the interpreter. */
2905 if (bfd_link_executable (info
) && !info
->nointerp
)
2907 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
2910 s
->size
= htab
->dynamic_interpreter_size
;
2911 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
2915 /* Don't change PLT section alignment for NaCl since it uses
2916 64-byte PLT entry and sets PLT section alignment to 32
2917 bytes. Don't create additional PLT sections for NaCl. */
2920 flagword pltflags
= (bed
->dynamic_sec_flags
2925 unsigned int non_lazy_plt_alignment
2926 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
2929 if (!bfd_set_section_alignment (sec
, plt_alignment
))
2930 goto error_alignment
;
2932 /* Create the GOT procedure linkage table. */
2933 sec
= bfd_make_section_anyway_with_flags (dynobj
,
2937 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT section\n"));
2939 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
2940 goto error_alignment
;
2942 htab
->plt_got
= sec
;
2950 /* Create the second PLT for Intel IBT support. IBT
2951 PLT is supported only for non-NaCl target and is
2952 is needed only for lazy binding. */
2953 sec
= bfd_make_section_anyway_with_flags (dynobj
,
2957 info
->callbacks
->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
2959 if (!bfd_set_section_alignment (sec
, plt_alignment
))
2960 goto error_alignment
;
2962 else if (htab
->params
->bndplt
&& ABI_64_P (dynobj
))
2964 /* Create the second PLT for Intel MPX support. MPX
2965 PLT is supported only for non-NaCl target in 64-bit
2966 mode and is needed only for lazy binding. */
2967 sec
= bfd_make_section_anyway_with_flags (dynobj
,
2971 info
->callbacks
->einfo (_("%F%P: failed to create BND PLT section\n"));
2973 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
2974 goto error_alignment
;
2977 htab
->plt_second
= sec
;
2981 if (!info
->no_ld_generated_unwind_info
)
2983 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
2984 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
2985 | SEC_LINKER_CREATED
);
2987 sec
= bfd_make_section_anyway_with_flags (dynobj
,
2991 info
->callbacks
->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
2993 if (!bfd_set_section_alignment (sec
, class_align
))
2994 goto error_alignment
;
2996 htab
->plt_eh_frame
= sec
;
2998 if (htab
->plt_got
!= NULL
)
3000 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3004 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
3006 if (!bfd_set_section_alignment (sec
, class_align
))
3007 goto error_alignment
;
3009 htab
->plt_got_eh_frame
= sec
;
3012 if (htab
->plt_second
!= NULL
)
3014 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3018 info
->callbacks
->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
3020 if (!bfd_set_section_alignment (sec
, class_align
))
3021 goto error_alignment
;
3023 htab
->plt_second_eh_frame
= sec
;
3028 /* The .iplt section is used for IFUNC symbols in static
3030 sec
= htab
->elf
.iplt
;
3033 /* NB: Delay setting its alignment until we know it is non-empty.
3034 Otherwise an empty iplt section may change vma and lma of the
3035 following sections, which triggers moving dot of the following
3036 section backwards, resulting in a warning and section lma not
3037 being set properly. It later leads to a "File truncated"
3039 if (!bfd_set_section_alignment (sec
, 0))
3040 goto error_alignment
;
3042 htab
->plt
.iplt_alignment
= (normal_target
3044 : bed
->plt_alignment
);
3047 if (bfd_link_executable (info
)
3049 && !htab
->params
->has_dynamic_linker
3050 && htab
->params
->static_before_all_inputs
)
3052 /* Report error for dynamic input objects if -static is passed at
3053 command-line before all input files without --dynamic-linker
3054 unless --no-dynamic-linker is used. */
3057 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
3058 if ((abfd
->flags
& DYNAMIC
))
3059 info
->callbacks
->einfo
3060 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
3067 /* Fix up x86 GNU properties. */
3070 _bfd_x86_elf_link_fixup_gnu_properties
3071 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
3072 elf_property_list
**listp
)
3074 elf_property_list
*p
;
3076 for (p
= *listp
; p
; p
= p
->next
)
3078 unsigned int type
= p
->property
.pr_type
;
3079 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3080 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3081 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3082 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3083 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3084 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
3085 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3086 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3088 if (p
->property
.u
.number
== 0
3089 && (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3090 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3091 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3092 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3093 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)))
3095 /* Remove empty property. */
3102 else if (type
> GNU_PROPERTY_HIPROC
)
3104 /* The property list is sorted in order of type. */
3111 _bfd_elf_linker_x86_set_options (struct bfd_link_info
* info
,
3112 struct elf_linker_x86_params
*params
)
3114 const struct elf_backend_data
*bed
3115 = get_elf_backend_data (info
->output_bfd
);
3116 struct elf_x86_link_hash_table
*htab
3117 = elf_x86_hash_table (info
, bed
->target_id
);
3119 htab
->params
= params
;