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 /* GOTOFF relocation needs PLT. */
138 if (_bfd_elf_allocate_ifunc_dyn_relocs (info
, h
, &h
->dyn_relocs
,
142 htab
->got_entry_size
,
145 asection
*s
= htab
->plt_second
;
146 if (h
->plt
.offset
!= (bfd_vma
) -1 && s
!= NULL
)
148 /* Use the second PLT section if it is created. */
149 eh
->plt_second
.offset
= s
->size
;
151 /* Make room for this entry in the second PLT section. */
152 s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
160 /* Don't create the PLT entry if there are only function pointer
161 relocations which can be resolved at run-time. */
162 else if (htab
->elf
.dynamic_sections_created
163 && (h
->plt
.refcount
> 0
164 || eh
->plt_got
.refcount
> 0))
166 bool use_plt_got
= eh
->plt_got
.refcount
> 0;
168 /* Make sure this symbol is output as a dynamic symbol.
169 Undefined weak syms won't yet be marked as dynamic. */
173 && h
->root
.type
== bfd_link_hash_undefweak
)
175 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
179 if (bfd_link_pic (info
)
180 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h
))
182 asection
*s
= htab
->elf
.splt
;
183 asection
*second_s
= htab
->plt_second
;
184 asection
*got_s
= htab
->plt_got
;
187 /* If this is the first .plt entry, make room for the special
188 first entry. The .plt section is used by prelink to undo
189 prelinking for dynamic relocations. */
191 s
->size
= htab
->plt
.has_plt0
* plt_entry_size
;
194 eh
->plt_got
.offset
= got_s
->size
;
197 h
->plt
.offset
= s
->size
;
199 eh
->plt_second
.offset
= second_s
->size
;
202 /* If this symbol is not defined in a regular file, and we are
203 generating PDE, then set the symbol to this location in the
204 .plt. This is required to make function pointers compare
205 as equal between PDE and the shared library.
207 NB: If PLT is PC-relative, we can use the .plt in PIE for
211 else if (htab
->pcrel_plt
)
212 use_plt
= ! bfd_link_dll (info
);
214 use_plt
= bfd_link_pde (info
);
219 /* We need to make a call to the entry of the GOT PLT
220 instead of regular PLT entry. */
221 h
->root
.u
.def
.section
= got_s
;
222 h
->root
.u
.def
.value
= eh
->plt_got
.offset
;
228 /* We need to make a call to the entry of the
229 second PLT instead of regular PLT entry. */
230 h
->root
.u
.def
.section
= second_s
;
231 h
->root
.u
.def
.value
= eh
->plt_second
.offset
;
235 h
->root
.u
.def
.section
= s
;
236 h
->root
.u
.def
.value
= h
->plt
.offset
;
241 /* Make room for this entry. */
243 got_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
246 s
->size
+= plt_entry_size
;
248 second_s
->size
+= htab
->non_lazy_plt
->plt_entry_size
;
250 /* We also need to make an entry in the .got.plt section,
251 which will be placed in the .got section by the linker
253 htab
->elf
.sgotplt
->size
+= htab
->got_entry_size
;
255 /* There should be no PLT relocation against resolved
256 undefined weak symbol in executable. */
257 if (!resolved_to_zero
)
259 /* We also need to make an entry in the .rel.plt
261 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
262 htab
->elf
.srelplt
->reloc_count
++;
266 if (htab
->elf
.target_os
== is_vxworks
&& !bfd_link_pic (info
))
268 /* VxWorks has a second set of relocations for each PLT entry
269 in executables. They go in a separate relocation section,
270 which is processed by the kernel loader. */
272 /* There are two relocations for the initial PLT entry: an
273 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
274 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
276 asection
*srelplt2
= htab
->srelplt2
;
277 if (h
->plt
.offset
== plt_entry_size
)
278 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
280 /* There are two extra relocations for each subsequent PLT entry:
281 an R_386_32 relocation for the GOT entry, and an R_386_32
282 relocation for the PLT entry. */
284 srelplt2
->size
+= (htab
->sizeof_reloc
* 2);
289 eh
->plt_got
.offset
= (bfd_vma
) -1;
290 h
->plt
.offset
= (bfd_vma
) -1;
296 eh
->plt_got
.offset
= (bfd_vma
) -1;
297 h
->plt
.offset
= (bfd_vma
) -1;
301 eh
->tlsdesc_got
= (bfd_vma
) -1;
303 /* For i386, if R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the
304 binary, make it a R_386_TLS_LE_32 requiring no TLS entry. For
305 x86-64, if R_X86_64_GOTTPOFF symbol is now local to the binary,
306 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
307 if (h
->got
.refcount
> 0
308 && bfd_link_executable (info
)
310 && (elf_x86_hash_entry (h
)->tls_type
& GOT_TLS_IE
))
311 h
->got
.offset
= (bfd_vma
) -1;
312 else if (h
->got
.refcount
> 0)
316 int tls_type
= elf_x86_hash_entry (h
)->tls_type
;
318 /* Make sure this symbol is output as a dynamic symbol.
319 Undefined weak syms won't yet be marked as dynamic. */
323 && h
->root
.type
== bfd_link_hash_undefweak
)
325 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
330 if (GOT_TLS_GDESC_P (tls_type
))
332 eh
->tlsdesc_got
= htab
->elf
.sgotplt
->size
333 - elf_x86_compute_jump_table_size (htab
);
334 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
335 h
->got
.offset
= (bfd_vma
) -2;
337 if (! GOT_TLS_GDESC_P (tls_type
)
338 || GOT_TLS_GD_P (tls_type
))
340 h
->got
.offset
= s
->size
;
341 s
->size
+= htab
->got_entry_size
;
342 /* R_386_TLS_GD and R_X86_64_TLSGD need 2 consecutive GOT
344 if (GOT_TLS_GD_P (tls_type
) || tls_type
== GOT_TLS_IE_BOTH
)
345 s
->size
+= htab
->got_entry_size
;
347 dyn
= htab
->elf
.dynamic_sections_created
;
348 /* R_386_TLS_IE_32 needs one dynamic relocation,
349 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
350 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
351 need two), R_386_TLS_GD and R_X86_64_TLSGD need one if local
352 symbol and two if global. No dynamic relocation against
353 resolved undefined weak symbol in executable. No dynamic
354 relocation against non-preemptible absolute symbol. */
355 if (tls_type
== GOT_TLS_IE_BOTH
)
356 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
357 else if ((GOT_TLS_GD_P (tls_type
) && h
->dynindx
== -1)
358 || (tls_type
& GOT_TLS_IE
))
359 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
360 else if (GOT_TLS_GD_P (tls_type
))
361 htab
->elf
.srelgot
->size
+= 2 * htab
->sizeof_reloc
;
362 else if (! GOT_TLS_GDESC_P (tls_type
)
363 && ((ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
364 && !resolved_to_zero
)
365 || h
->root
.type
!= bfd_link_hash_undefweak
)
366 && ((bfd_link_pic (info
)
367 && !(h
->dynindx
== -1
368 && ABS_SYMBOL_P (h
)))
369 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, 0, h
)))
370 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
371 if (GOT_TLS_GDESC_P (tls_type
))
373 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
374 if (bed
->target_id
== X86_64_ELF_DATA
)
375 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
379 h
->got
.offset
= (bfd_vma
) -1;
381 if (h
->dyn_relocs
== NULL
)
384 /* In the shared -Bsymbolic case, discard space allocated for
385 dynamic pc-relative relocs against symbols which turn out to be
386 defined in regular objects. For the normal shared case, discard
387 space for pc-relative relocs that have become local due to symbol
388 visibility changes. */
390 if (bfd_link_pic (info
))
392 /* Relocs that use pc_count are those that appear on a call
393 insn, or certain REL relocs that can generated via assembly.
394 We want calls to protected symbols to resolve directly to the
395 function rather than going via the plt. If people want
396 function pointer comparisons to work as expected then they
397 should avoid writing weird assembly. */
398 if (SYMBOL_CALLS_LOCAL (info
, h
))
400 struct elf_dyn_relocs
**pp
;
402 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
404 p
->count
-= p
->pc_count
;
413 if (htab
->elf
.target_os
== is_vxworks
)
415 struct elf_dyn_relocs
**pp
;
416 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
418 if (strcmp (p
->sec
->output_section
->name
, ".tls_vars") == 0)
425 /* Also discard relocs on undefined weak syms with non-default
426 visibility or in PIE. */
427 if (h
->dyn_relocs
!= NULL
)
429 if (h
->root
.type
== bfd_link_hash_undefweak
)
431 /* Undefined weak symbol is never bound locally in shared
433 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
436 if (bed
->target_id
== I386_ELF_DATA
439 /* Keep dynamic non-GOT/non-PLT relocation so
440 that we can branch to 0 without PLT. */
441 struct elf_dyn_relocs
**pp
;
443 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
444 if (p
->pc_count
== 0)
448 /* Remove non-R_386_PC32 relocation. */
449 p
->count
= p
->pc_count
;
453 /* Make sure undefined weak symbols are output
454 as dynamic symbols in PIEs for dynamic non-GOT
455 non-PLT reloations. */
456 if (h
->dyn_relocs
!= NULL
457 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
461 h
->dyn_relocs
= NULL
;
463 else if (h
->dynindx
== -1
465 && !bfd_elf_link_record_dynamic_symbol (info
, h
))
468 else if (bfd_link_executable (info
)
469 && (h
->needs_copy
|| eh
->needs_copy
)
473 /* NB: needs_copy is set only for x86-64. For PIE,
474 discard space for pc-relative relocs against symbols
475 which turn out to need copy relocs. */
476 struct elf_dyn_relocs
**pp
;
478 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
480 if (p
->pc_count
!= 0)
488 else if (ELIMINATE_COPY_RELOCS
)
490 /* For the non-shared case, discard space for relocs against
491 symbols which turn out to need copy relocs or are not
492 dynamic. Keep dynamic relocations for run-time function
493 pointer initialization. */
496 || (h
->root
.type
== bfd_link_hash_undefweak
497 && !resolved_to_zero
))
500 || (htab
->elf
.dynamic_sections_created
501 && (h
->root
.type
== bfd_link_hash_undefweak
502 || h
->root
.type
== bfd_link_hash_undefined
))))
504 /* Make sure this symbol is output as a dynamic symbol.
505 Undefined weak syms won't yet be marked as dynamic. */
509 && h
->root
.type
== bfd_link_hash_undefweak
510 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
513 /* If that succeeded, we know we'll be keeping all the
515 if (h
->dynindx
!= -1)
519 h
->dyn_relocs
= NULL
;
524 /* Finally, allocate space. */
525 for (p
= h
->dyn_relocs
; p
!= NULL
; p
= p
->next
)
529 sreloc
= elf_section_data (p
->sec
)->sreloc
;
531 BFD_ASSERT (sreloc
!= NULL
);
532 sreloc
->size
+= p
->count
* htab
->sizeof_reloc
;
538 /* Allocate space in .plt, .got and associated reloc sections for
539 local dynamic relocs. */
542 elf_x86_allocate_local_dynreloc (void **slot
, void *inf
)
544 struct elf_link_hash_entry
*h
545 = (struct elf_link_hash_entry
*) *slot
;
547 if (h
->type
!= STT_GNU_IFUNC
551 || h
->root
.type
!= bfd_link_hash_defined
)
554 return elf_x86_allocate_dynrelocs (h
, inf
);
557 /* Find and/or create a hash entry for local symbol. */
559 struct elf_link_hash_entry
*
560 _bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table
*htab
,
561 bfd
*abfd
, const Elf_Internal_Rela
*rel
,
564 struct elf_x86_link_hash_entry e
, *ret
;
565 asection
*sec
= abfd
->sections
;
566 hashval_t h
= ELF_LOCAL_SYMBOL_HASH (sec
->id
,
567 htab
->r_sym (rel
->r_info
));
570 e
.elf
.indx
= sec
->id
;
571 e
.elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
572 slot
= htab_find_slot_with_hash (htab
->loc_hash_table
, &e
, h
,
573 create
? INSERT
: NO_INSERT
);
580 ret
= (struct elf_x86_link_hash_entry
*) *slot
;
584 ret
= (struct elf_x86_link_hash_entry
*)
585 objalloc_alloc ((struct objalloc
*) htab
->loc_hash_memory
,
586 sizeof (struct elf_x86_link_hash_entry
));
589 memset (ret
, 0, sizeof (*ret
));
590 ret
->elf
.indx
= sec
->id
;
591 ret
->elf
.dynstr_index
= htab
->r_sym (rel
->r_info
);
592 ret
->elf
.dynindx
= -1;
593 ret
->plt_got
.offset
= (bfd_vma
) -1;
599 /* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
600 SYNC WITH _bfd_elf_link_hash_newfunc. */
602 struct bfd_hash_entry
*
603 _bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
604 struct bfd_hash_table
*table
,
607 /* Allocate the structure if it has not already been allocated by a
611 entry
= (struct bfd_hash_entry
*)
612 bfd_hash_allocate (table
,
613 sizeof (struct elf_x86_link_hash_entry
));
618 /* Call the allocation method of the superclass. */
619 entry
= _bfd_link_hash_newfunc (entry
, table
, string
);
622 struct elf_x86_link_hash_entry
*eh
623 = (struct elf_x86_link_hash_entry
*) entry
;
624 struct elf_link_hash_table
*htab
625 = (struct elf_link_hash_table
*) table
;
627 memset (&eh
->elf
.size
, 0,
628 (sizeof (struct elf_x86_link_hash_entry
)
629 - offsetof (struct elf_link_hash_entry
, size
)));
630 /* Set local fields. */
632 eh
->elf
.dynindx
= -1;
633 eh
->elf
.got
= htab
->init_got_refcount
;
634 eh
->elf
.plt
= htab
->init_plt_refcount
;
635 /* Assume that we have been called by a non-ELF symbol reader.
636 This flag is then reset by the code which reads an ELF input
637 file. This ensures that a symbol created by a non-ELF symbol
638 reader will have the flag set correctly. */
640 eh
->plt_second
.offset
= (bfd_vma
) -1;
641 eh
->plt_got
.offset
= (bfd_vma
) -1;
642 eh
->tlsdesc_got
= (bfd_vma
) -1;
643 eh
->zero_undefweak
= 1;
649 /* Compute a hash of a local hash entry. We use elf_link_hash_entry
650 for local symbol so that we can handle local STT_GNU_IFUNC symbols
651 as global symbol. We reuse indx and dynstr_index for local symbol
652 hash since they aren't used by global symbols in this backend. */
655 _bfd_x86_elf_local_htab_hash (const void *ptr
)
657 struct elf_link_hash_entry
*h
658 = (struct elf_link_hash_entry
*) ptr
;
659 return ELF_LOCAL_SYMBOL_HASH (h
->indx
, h
->dynstr_index
);
662 /* Compare local hash entries. */
665 _bfd_x86_elf_local_htab_eq (const void *ptr1
, const void *ptr2
)
667 struct elf_link_hash_entry
*h1
668 = (struct elf_link_hash_entry
*) ptr1
;
669 struct elf_link_hash_entry
*h2
670 = (struct elf_link_hash_entry
*) ptr2
;
672 return h1
->indx
== h2
->indx
&& h1
->dynstr_index
== h2
->dynstr_index
;
675 /* Destroy an x86 ELF linker hash table. */
678 elf_x86_link_hash_table_free (bfd
*obfd
)
680 struct elf_x86_link_hash_table
*htab
681 = (struct elf_x86_link_hash_table
*) obfd
->link
.hash
;
683 if (htab
->loc_hash_table
)
684 htab_delete (htab
->loc_hash_table
);
685 if (htab
->loc_hash_memory
)
686 objalloc_free ((struct objalloc
*) htab
->loc_hash_memory
);
687 _bfd_elf_link_hash_table_free (obfd
);
691 elf_i386_is_reloc_section (const char *secname
)
693 return startswith (secname
, ".rel");
697 elf_x86_64_is_reloc_section (const char *secname
)
699 return startswith (secname
, ".rela");
702 /* Create an x86 ELF linker hash table. */
704 struct bfd_link_hash_table
*
705 _bfd_x86_elf_link_hash_table_create (bfd
*abfd
)
707 struct elf_x86_link_hash_table
*ret
;
708 const struct elf_backend_data
*bed
;
709 size_t amt
= sizeof (struct elf_x86_link_hash_table
);
711 ret
= (struct elf_x86_link_hash_table
*) bfd_zmalloc (amt
);
715 bed
= get_elf_backend_data (abfd
);
716 if (!_bfd_elf_link_hash_table_init (&ret
->elf
, abfd
,
717 _bfd_x86_elf_link_hash_newfunc
,
718 sizeof (struct elf_x86_link_hash_entry
),
725 if (bed
->target_id
== X86_64_ELF_DATA
)
727 ret
->is_reloc_section
= elf_x86_64_is_reloc_section
;
728 ret
->got_entry_size
= 8;
729 ret
->pcrel_plt
= true;
730 ret
->tls_get_addr
= "__tls_get_addr";
734 ret
->sizeof_reloc
= sizeof (Elf64_External_Rela
);
735 ret
->pointer_r_type
= R_X86_64_64
;
736 ret
->dynamic_interpreter
= ELF64_DYNAMIC_INTERPRETER
;
737 ret
->dynamic_interpreter_size
= sizeof ELF64_DYNAMIC_INTERPRETER
;
741 if (bed
->target_id
== X86_64_ELF_DATA
)
743 ret
->sizeof_reloc
= sizeof (Elf32_External_Rela
);
744 ret
->pointer_r_type
= R_X86_64_32
;
745 ret
->dynamic_interpreter
= ELFX32_DYNAMIC_INTERPRETER
;
746 ret
->dynamic_interpreter_size
747 = sizeof ELFX32_DYNAMIC_INTERPRETER
;
751 ret
->is_reloc_section
= elf_i386_is_reloc_section
;
752 ret
->sizeof_reloc
= sizeof (Elf32_External_Rel
);
753 ret
->got_entry_size
= 4;
754 ret
->pcrel_plt
= false;
755 ret
->pointer_r_type
= R_386_32
;
756 ret
->dynamic_interpreter
= ELF32_DYNAMIC_INTERPRETER
;
757 ret
->dynamic_interpreter_size
758 = sizeof ELF32_DYNAMIC_INTERPRETER
;
759 ret
->tls_get_addr
= "___tls_get_addr";
763 ret
->loc_hash_table
= htab_try_create (1024,
764 _bfd_x86_elf_local_htab_hash
,
765 _bfd_x86_elf_local_htab_eq
,
767 ret
->loc_hash_memory
= objalloc_create ();
768 if (!ret
->loc_hash_table
|| !ret
->loc_hash_memory
)
770 elf_x86_link_hash_table_free (abfd
);
773 ret
->elf
.root
.hash_table_free
= elf_x86_link_hash_table_free
;
775 return &ret
->elf
.root
;
778 /* Sort relocs into address order. */
781 _bfd_x86_elf_compare_relocs (const void *ap
, const void *bp
)
783 const arelent
*a
= * (const arelent
**) ap
;
784 const arelent
*b
= * (const arelent
**) bp
;
786 if (a
->address
> b
->address
)
788 else if (a
->address
< b
->address
)
794 /* Mark symbol, NAME, as locally defined by linker if it is referenced
795 and not defined in a relocatable object file. */
798 elf_x86_linker_defined (struct bfd_link_info
*info
, const char *name
)
800 struct elf_link_hash_entry
*h
;
802 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
803 false, false, false);
807 while (h
->root
.type
== bfd_link_hash_indirect
)
808 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
810 if (h
->root
.type
== bfd_link_hash_new
811 || h
->root
.type
== bfd_link_hash_undefined
812 || h
->root
.type
== bfd_link_hash_undefweak
813 || h
->root
.type
== bfd_link_hash_common
814 || (!h
->def_regular
&& h
->def_dynamic
))
816 elf_x86_hash_entry (h
)->local_ref
= 2;
817 elf_x86_hash_entry (h
)->linker_def
= 1;
821 /* Hide a linker-defined symbol, NAME, with hidden visibility. */
824 elf_x86_hide_linker_defined (struct bfd_link_info
*info
,
827 struct elf_link_hash_entry
*h
;
829 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
830 false, false, false);
834 while (h
->root
.type
== bfd_link_hash_indirect
)
835 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
837 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
838 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
839 _bfd_elf_link_hash_hide_symbol (info
, h
, true);
843 _bfd_x86_elf_link_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
)
845 if (!bfd_link_relocatable (info
))
847 /* Check for __tls_get_addr reference. */
848 struct elf_x86_link_hash_table
*htab
;
849 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
850 htab
= elf_x86_hash_table (info
, bed
->target_id
);
853 struct elf_link_hash_entry
*h
;
855 h
= elf_link_hash_lookup (elf_hash_table (info
),
857 false, false, false);
860 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
862 /* Check the versioned __tls_get_addr symbol. */
863 while (h
->root
.type
== bfd_link_hash_indirect
)
865 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
866 elf_x86_hash_entry (h
)->tls_get_addr
= 1;
870 /* "__ehdr_start" will be defined by linker as a hidden symbol
871 later if it is referenced and not defined. */
872 elf_x86_linker_defined (info
, "__ehdr_start");
874 if (bfd_link_executable (info
))
876 /* References to __bss_start, _end and _edata should be
877 locally resolved within executables. */
878 elf_x86_linker_defined (info
, "__bss_start");
879 elf_x86_linker_defined (info
, "_end");
880 elf_x86_linker_defined (info
, "_edata");
884 /* Hide hidden __bss_start, _end and _edata in shared
886 elf_x86_hide_linker_defined (info
, "__bss_start");
887 elf_x86_hide_linker_defined (info
, "_end");
888 elf_x86_hide_linker_defined (info
, "_edata");
893 /* Invoke the regular ELF backend linker to do all the work. */
894 return _bfd_elf_link_check_relocs (abfd
, info
);
898 _bfd_elf_x86_valid_reloc_p (asection
*input_section
,
899 struct bfd_link_info
*info
,
900 struct elf_x86_link_hash_table
*htab
,
901 const Elf_Internal_Rela
*rel
,
902 struct elf_link_hash_entry
*h
,
903 Elf_Internal_Sym
*sym
,
904 Elf_Internal_Shdr
*symtab_hdr
,
909 *no_dynreloc_p
= false;
911 /* Check If relocation against non-preemptible absolute symbol is
912 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
913 it may call _bfd_elf_link_hide_sym_by_version and result in
914 ld-elfvers/ vers21 test failure. */
915 if (bfd_link_pic (info
)
916 && (h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, h
)))
918 const struct elf_backend_data
*bed
;
920 Elf_Internal_Rela irel
;
922 /* Skip non-absolute symbol. */
925 if (!ABS_SYMBOL_P (h
))
928 else if (sym
->st_shndx
!= SHN_ABS
)
931 bed
= get_elf_backend_data (input_section
->owner
);
932 r_type
= ELF32_R_TYPE (rel
->r_info
);
935 /* Only allow relocations against absolute symbol, which can be
936 resolved as absolute value + addend. GOTPCREL relocations
937 are allowed since absolute value + addend is stored in the
939 if (bed
->target_id
== X86_64_ELF_DATA
)
941 r_type
&= ~R_X86_64_converted_reloc_bit
;
942 valid_p
= (r_type
== R_X86_64_64
943 || r_type
== R_X86_64_32
944 || r_type
== R_X86_64_32S
945 || r_type
== R_X86_64_16
946 || r_type
== R_X86_64_8
947 || r_type
== R_X86_64_GOTPCREL
948 || r_type
== R_X86_64_GOTPCRELX
949 || r_type
== R_X86_64_REX_GOTPCRELX
);
952 unsigned int r_symndx
= htab
->r_sym (rel
->r_info
);
953 irel
.r_info
= htab
->r_info (r_symndx
, r_type
);
957 valid_p
= (r_type
== R_386_32
958 || r_type
== R_386_16
959 || r_type
== R_386_8
);
962 *no_dynreloc_p
= true;
966 arelent internal_reloc
;
968 if (!bed
->elf_info_to_howto (input_section
->owner
,
969 &internal_reloc
, &irel
)
970 || internal_reloc
.howto
== NULL
)
974 name
= h
->root
.root
.string
;
976 name
= bfd_elf_sym_name (input_section
->owner
, symtab_hdr
,
978 info
->callbacks
->einfo
979 /* xgettext:c-format */
980 (_("%F%P: %pB: relocation %s against absolute symbol "
981 "`%s' in section `%pA' is disallowed\n"),
982 input_section
->owner
, internal_reloc
.howto
->name
, name
,
984 bfd_set_error (bfd_error_bad_value
);
991 /* Set the sizes of the dynamic sections. */
994 _bfd_x86_elf_size_dynamic_sections (bfd
*output_bfd
,
995 struct bfd_link_info
*info
)
997 struct elf_x86_link_hash_table
*htab
;
1002 const struct elf_backend_data
*bed
1003 = get_elf_backend_data (output_bfd
);
1005 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1008 dynobj
= htab
->elf
.dynobj
;
1012 /* Set up .got offsets for local syms, and space for local dynamic
1014 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link
.next
)
1016 bfd_signed_vma
*local_got
;
1017 bfd_signed_vma
*end_local_got
;
1018 char *local_tls_type
;
1019 bfd_vma
*local_tlsdesc_gotent
;
1020 bfd_size_type locsymcount
;
1021 Elf_Internal_Shdr
*symtab_hdr
;
1024 if (! is_x86_elf (ibfd
, htab
))
1027 for (s
= ibfd
->sections
; s
!= NULL
; s
= s
->next
)
1029 struct elf_dyn_relocs
*p
;
1031 for (p
= ((struct elf_dyn_relocs
*)
1032 elf_section_data (s
)->local_dynrel
);
1036 if (!bfd_is_abs_section (p
->sec
)
1037 && bfd_is_abs_section (p
->sec
->output_section
))
1039 /* Input section has been discarded, either because
1040 it is a copy of a linkonce section or due to
1041 linker script /DISCARD/, so we'll be discarding
1044 else if (htab
->elf
.target_os
== is_vxworks
1045 && strcmp (p
->sec
->output_section
->name
,
1048 /* Relocations in vxworks .tls_vars sections are
1049 handled specially by the loader. */
1051 else if (p
->count
!= 0)
1053 srel
= elf_section_data (p
->sec
)->sreloc
;
1054 srel
->size
+= p
->count
* htab
->sizeof_reloc
;
1055 if ((p
->sec
->output_section
->flags
& SEC_READONLY
) != 0
1056 && (info
->flags
& DF_TEXTREL
) == 0)
1058 info
->flags
|= DF_TEXTREL
;
1059 if (bfd_link_textrel_check (info
))
1060 /* xgettext:c-format */
1061 info
->callbacks
->einfo
1062 (_("%P: %pB: warning: relocation "
1063 "in read-only section `%pA'\n"),
1064 p
->sec
->owner
, p
->sec
);
1070 local_got
= elf_local_got_refcounts (ibfd
);
1074 symtab_hdr
= &elf_symtab_hdr (ibfd
);
1075 locsymcount
= symtab_hdr
->sh_info
;
1076 end_local_got
= local_got
+ locsymcount
;
1077 local_tls_type
= elf_x86_local_got_tls_type (ibfd
);
1078 local_tlsdesc_gotent
= elf_x86_local_tlsdesc_gotent (ibfd
);
1080 srel
= htab
->elf
.srelgot
;
1081 for (; local_got
< end_local_got
;
1082 ++local_got
, ++local_tls_type
, ++local_tlsdesc_gotent
)
1084 *local_tlsdesc_gotent
= (bfd_vma
) -1;
1087 if (GOT_TLS_GDESC_P (*local_tls_type
))
1089 *local_tlsdesc_gotent
= htab
->elf
.sgotplt
->size
1090 - elf_x86_compute_jump_table_size (htab
);
1091 htab
->elf
.sgotplt
->size
+= 2 * htab
->got_entry_size
;
1092 *local_got
= (bfd_vma
) -2;
1094 if (! GOT_TLS_GDESC_P (*local_tls_type
)
1095 || GOT_TLS_GD_P (*local_tls_type
))
1097 *local_got
= s
->size
;
1098 s
->size
+= htab
->got_entry_size
;
1099 if (GOT_TLS_GD_P (*local_tls_type
)
1100 || *local_tls_type
== GOT_TLS_IE_BOTH
)
1101 s
->size
+= htab
->got_entry_size
;
1103 if ((bfd_link_pic (info
) && *local_tls_type
!= GOT_ABS
)
1104 || GOT_TLS_GD_ANY_P (*local_tls_type
)
1105 || (*local_tls_type
& GOT_TLS_IE
))
1107 if (*local_tls_type
== GOT_TLS_IE_BOTH
)
1108 srel
->size
+= 2 * htab
->sizeof_reloc
;
1109 else if (GOT_TLS_GD_P (*local_tls_type
)
1110 || ! GOT_TLS_GDESC_P (*local_tls_type
))
1111 srel
->size
+= htab
->sizeof_reloc
;
1112 if (GOT_TLS_GDESC_P (*local_tls_type
))
1114 htab
->elf
.srelplt
->size
+= htab
->sizeof_reloc
;
1115 if (bed
->target_id
== X86_64_ELF_DATA
)
1116 htab
->elf
.tlsdesc_plt
= (bfd_vma
) -1;
1121 *local_got
= (bfd_vma
) -1;
1125 if (htab
->tls_ld_or_ldm_got
.refcount
> 0)
1127 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
1128 or R_X86_64_TLSLD relocs. */
1129 htab
->tls_ld_or_ldm_got
.offset
= htab
->elf
.sgot
->size
;
1130 htab
->elf
.sgot
->size
+= 2 * htab
->got_entry_size
;
1131 htab
->elf
.srelgot
->size
+= htab
->sizeof_reloc
;
1134 htab
->tls_ld_or_ldm_got
.offset
= -1;
1136 /* Allocate global sym .plt and .got entries, and space for global
1137 sym dynamic relocs. */
1138 elf_link_hash_traverse (&htab
->elf
, elf_x86_allocate_dynrelocs
,
1141 /* Allocate .plt and .got entries, and space for local symbols. */
1142 htab_traverse (htab
->loc_hash_table
, elf_x86_allocate_local_dynreloc
,
1145 /* For every jump slot reserved in the sgotplt, reloc_count is
1146 incremented. However, when we reserve space for TLS descriptors,
1147 it's not incremented, so in order to compute the space reserved
1148 for them, it suffices to multiply the reloc count by the jump
1151 PR ld/13302: We start next_irelative_index at the end of .rela.plt
1152 so that R_{386,X86_64}_IRELATIVE entries come last. */
1153 if (htab
->elf
.srelplt
)
1155 htab
->next_tls_desc_index
= htab
->elf
.srelplt
->reloc_count
;
1156 htab
->sgotplt_jump_table_size
1157 = elf_x86_compute_jump_table_size (htab
);
1158 htab
->next_irelative_index
= htab
->elf
.srelplt
->reloc_count
- 1;
1160 else if (htab
->elf
.irelplt
)
1161 htab
->next_irelative_index
= htab
->elf
.irelplt
->reloc_count
- 1;
1163 if (htab
->elf
.tlsdesc_plt
)
1165 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
1166 lazy TLS relocations, don't generate the PLT and GOT entries
1168 if ((info
->flags
& DF_BIND_NOW
))
1169 htab
->elf
.tlsdesc_plt
= 0;
1172 htab
->elf
.tlsdesc_got
= htab
->elf
.sgot
->size
;
1173 htab
->elf
.sgot
->size
+= htab
->got_entry_size
;
1174 /* Reserve room for the initial entry.
1175 FIXME: we could probably do away with it in this case. */
1176 if (htab
->elf
.splt
->size
== 0)
1177 htab
->elf
.splt
->size
= htab
->plt
.plt_entry_size
;
1178 htab
->elf
.tlsdesc_plt
= htab
->elf
.splt
->size
;
1179 htab
->elf
.splt
->size
+= htab
->plt
.plt_entry_size
;
1183 if (htab
->elf
.sgotplt
)
1185 /* Don't allocate .got.plt section if there are no GOT nor PLT
1186 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
1187 if ((htab
->elf
.hgot
== NULL
1188 || !htab
->got_referenced
)
1189 && (htab
->elf
.sgotplt
->size
== bed
->got_header_size
)
1190 && (htab
->elf
.splt
== NULL
1191 || htab
->elf
.splt
->size
== 0)
1192 && (htab
->elf
.sgot
== NULL
1193 || htab
->elf
.sgot
->size
== 0)
1194 && (htab
->elf
.iplt
== NULL
1195 || htab
->elf
.iplt
->size
== 0)
1196 && (htab
->elf
.igotplt
== NULL
1197 || htab
->elf
.igotplt
->size
== 0))
1199 htab
->elf
.sgotplt
->size
= 0;
1200 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
1202 if (htab
->elf
.hgot
!= NULL
1203 && htab
->elf
.target_os
!= is_solaris
)
1205 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
1207 htab
->elf
.hgot
->root
.type
= bfd_link_hash_undefined
;
1208 htab
->elf
.hgot
->root
.u
.undef
.abfd
1209 = htab
->elf
.hgot
->root
.u
.def
.section
->owner
;
1210 htab
->elf
.hgot
->root
.linker_def
= 0;
1211 htab
->elf
.hgot
->ref_regular
= 0;
1212 htab
->elf
.hgot
->def_regular
= 0;
1217 if (_bfd_elf_eh_frame_present (info
))
1219 if (htab
->plt_eh_frame
!= NULL
1220 && htab
->elf
.splt
!= NULL
1221 && htab
->elf
.splt
->size
!= 0
1222 && !bfd_is_abs_section (htab
->elf
.splt
->output_section
))
1223 htab
->plt_eh_frame
->size
= htab
->plt
.eh_frame_plt_size
;
1225 if (htab
->plt_got_eh_frame
!= NULL
1226 && htab
->plt_got
!= NULL
1227 && htab
->plt_got
->size
!= 0
1228 && !bfd_is_abs_section (htab
->plt_got
->output_section
))
1229 htab
->plt_got_eh_frame
->size
1230 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1232 /* Unwind info for the second PLT and .plt.got sections are
1234 if (htab
->plt_second_eh_frame
!= NULL
1235 && htab
->plt_second
!= NULL
1236 && htab
->plt_second
->size
!= 0
1237 && !bfd_is_abs_section (htab
->plt_second
->output_section
))
1238 htab
->plt_second_eh_frame
->size
1239 = htab
->non_lazy_plt
->eh_frame_plt_size
;
1242 /* We now have determined the sizes of the various dynamic sections.
1243 Allocate memory for them. */
1245 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
1247 bool strip_section
= true;
1249 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
1252 if (s
== htab
->elf
.splt
1253 || s
== htab
->elf
.sgot
)
1255 /* Strip this section if we don't need it; see the
1257 /* We'd like to strip these sections if they aren't needed, but if
1258 we've exported dynamic symbols from them we must leave them.
1259 It's too late to tell BFD to get rid of the symbols. */
1261 if (htab
->elf
.hplt
!= NULL
)
1262 strip_section
= false;
1264 else if (s
== htab
->elf
.sgotplt
1265 || s
== htab
->elf
.iplt
1266 || s
== htab
->elf
.igotplt
1267 || s
== htab
->plt_second
1268 || s
== htab
->plt_got
1269 || s
== htab
->plt_eh_frame
1270 || s
== htab
->plt_got_eh_frame
1271 || s
== htab
->plt_second_eh_frame
1272 || s
== htab
->elf
.sdynbss
1273 || s
== htab
->elf
.sdynrelro
)
1275 /* Strip these too. */
1277 else if (htab
->is_reloc_section (bfd_section_name (s
)))
1280 && s
!= htab
->elf
.srelplt
1281 && s
!= htab
->srelplt2
)
1284 /* We use the reloc_count field as a counter if we need
1285 to copy relocs into the output file. */
1286 if (s
!= htab
->elf
.srelplt
)
1291 /* It's not one of our sections, so don't allocate space. */
1297 /* If we don't need this section, strip it from the
1298 output file. This is mostly to handle .rel.bss and
1299 .rel.plt. We must create both sections in
1300 create_dynamic_sections, because they must be created
1301 before the linker maps input sections to output
1302 sections. The linker does that before
1303 adjust_dynamic_symbol is called, and it is that
1304 function which decides whether anything needs to go
1305 into these sections. */
1307 s
->flags
|= SEC_EXCLUDE
;
1311 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
1314 /* NB: Initially, the iplt section has minimal alignment to
1315 avoid moving dot of the following section backwards when
1316 it is empty. Update its section alignment now since it
1318 if (s
== htab
->elf
.iplt
)
1319 bfd_set_section_alignment (s
, htab
->plt
.iplt_alignment
);
1321 /* Allocate memory for the section contents. We use bfd_zalloc
1322 here in case unused entries are not reclaimed before the
1323 section's contents are written out. This should not happen,
1324 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
1325 reloc instead of garbage. */
1326 s
->contents
= (unsigned char *) bfd_zalloc (dynobj
, s
->size
);
1327 if (s
->contents
== NULL
)
1331 if (htab
->plt_eh_frame
!= NULL
1332 && htab
->plt_eh_frame
->contents
!= NULL
)
1334 memcpy (htab
->plt_eh_frame
->contents
,
1335 htab
->plt
.eh_frame_plt
,
1336 htab
->plt_eh_frame
->size
);
1337 bfd_put_32 (dynobj
, htab
->elf
.splt
->size
,
1338 htab
->plt_eh_frame
->contents
+ PLT_FDE_LEN_OFFSET
);
1341 if (htab
->plt_got_eh_frame
!= NULL
1342 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1344 memcpy (htab
->plt_got_eh_frame
->contents
,
1345 htab
->non_lazy_plt
->eh_frame_plt
,
1346 htab
->plt_got_eh_frame
->size
);
1347 bfd_put_32 (dynobj
, htab
->plt_got
->size
,
1348 (htab
->plt_got_eh_frame
->contents
1349 + PLT_FDE_LEN_OFFSET
));
1352 if (htab
->plt_second_eh_frame
!= NULL
1353 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1355 memcpy (htab
->plt_second_eh_frame
->contents
,
1356 htab
->non_lazy_plt
->eh_frame_plt
,
1357 htab
->plt_second_eh_frame
->size
);
1358 bfd_put_32 (dynobj
, htab
->plt_second
->size
,
1359 (htab
->plt_second_eh_frame
->contents
1360 + PLT_FDE_LEN_OFFSET
));
1363 return _bfd_elf_maybe_vxworks_add_dynamic_tags (output_bfd
, info
,
1367 /* Finish up the x86 dynamic sections. */
1369 struct elf_x86_link_hash_table
*
1370 _bfd_x86_elf_finish_dynamic_sections (bfd
*output_bfd
,
1371 struct bfd_link_info
*info
)
1373 struct elf_x86_link_hash_table
*htab
;
1374 const struct elf_backend_data
*bed
;
1377 bfd_byte
*dyncon
, *dynconend
;
1378 bfd_size_type sizeof_dyn
;
1380 bed
= get_elf_backend_data (output_bfd
);
1381 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1385 dynobj
= htab
->elf
.dynobj
;
1386 sdyn
= bfd_get_linker_section (dynobj
, ".dynamic");
1388 /* GOT is always created in setup_gnu_properties. But it may not be
1389 needed. .got.plt section may be needed for static IFUNC. */
1390 if (htab
->elf
.sgotplt
&& htab
->elf
.sgotplt
->size
> 0)
1392 bfd_vma dynamic_addr
;
1394 if (bfd_is_abs_section (htab
->elf
.sgotplt
->output_section
))
1397 (_("discarded output section: `%pA'"), htab
->elf
.sgotplt
);
1401 elf_section_data (htab
->elf
.sgotplt
->output_section
)->this_hdr
.sh_entsize
1402 = htab
->got_entry_size
;
1404 dynamic_addr
= (sdyn
== NULL
1406 : sdyn
->output_section
->vma
+ sdyn
->output_offset
);
1408 /* Set the first entry in the global offset table to the address
1409 of the dynamic section. Write GOT[1] and GOT[2], needed for
1410 the dynamic linker. */
1411 if (htab
->got_entry_size
== 8)
1413 bfd_put_64 (output_bfd
, dynamic_addr
,
1414 htab
->elf
.sgotplt
->contents
);
1415 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1416 htab
->elf
.sgotplt
->contents
+ 8);
1417 bfd_put_64 (output_bfd
, (bfd_vma
) 0,
1418 htab
->elf
.sgotplt
->contents
+ 8*2);
1422 bfd_put_32 (output_bfd
, dynamic_addr
,
1423 htab
->elf
.sgotplt
->contents
);
1424 bfd_put_32 (output_bfd
, 0,
1425 htab
->elf
.sgotplt
->contents
+ 4);
1426 bfd_put_32 (output_bfd
, 0,
1427 htab
->elf
.sgotplt
->contents
+ 4*2);
1431 if (!htab
->elf
.dynamic_sections_created
)
1434 if (sdyn
== NULL
|| htab
->elf
.sgot
== NULL
)
1437 sizeof_dyn
= bed
->s
->sizeof_dyn
;
1438 dyncon
= sdyn
->contents
;
1439 dynconend
= sdyn
->contents
+ sdyn
->size
;
1440 for (; dyncon
< dynconend
; dyncon
+= sizeof_dyn
)
1442 Elf_Internal_Dyn dyn
;
1445 (*bed
->s
->swap_dyn_in
) (dynobj
, dyncon
, &dyn
);
1450 if (htab
->elf
.target_os
== is_vxworks
1451 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
1456 s
= htab
->elf
.sgotplt
;
1457 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
1461 dyn
.d_un
.d_ptr
= htab
->elf
.srelplt
->output_section
->vma
;
1465 s
= htab
->elf
.srelplt
->output_section
;
1466 dyn
.d_un
.d_val
= s
->size
;
1469 case DT_TLSDESC_PLT
:
1471 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1472 + htab
->elf
.tlsdesc_plt
;
1475 case DT_TLSDESC_GOT
:
1477 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
1478 + htab
->elf
.tlsdesc_got
;
1482 (*bed
->s
->swap_dyn_out
) (output_bfd
, &dyn
, dyncon
);
1485 if (htab
->plt_got
!= NULL
&& htab
->plt_got
->size
> 0)
1486 elf_section_data (htab
->plt_got
->output_section
)
1487 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1489 if (htab
->plt_second
!= NULL
&& htab
->plt_second
->size
> 0)
1490 elf_section_data (htab
->plt_second
->output_section
)
1491 ->this_hdr
.sh_entsize
= htab
->non_lazy_plt
->plt_entry_size
;
1493 /* Adjust .eh_frame for .plt section. */
1494 if (htab
->plt_eh_frame
!= NULL
1495 && htab
->plt_eh_frame
->contents
!= NULL
)
1497 if (htab
->elf
.splt
!= NULL
1498 && htab
->elf
.splt
->size
!= 0
1499 && (htab
->elf
.splt
->flags
& SEC_EXCLUDE
) == 0
1500 && htab
->elf
.splt
->output_section
!= NULL
1501 && htab
->plt_eh_frame
->output_section
!= NULL
)
1503 bfd_vma plt_start
= htab
->elf
.splt
->output_section
->vma
;
1504 bfd_vma eh_frame_start
= htab
->plt_eh_frame
->output_section
->vma
1505 + htab
->plt_eh_frame
->output_offset
1506 + PLT_FDE_START_OFFSET
;
1507 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1508 htab
->plt_eh_frame
->contents
1509 + PLT_FDE_START_OFFSET
);
1512 if (htab
->plt_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1514 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1516 htab
->plt_eh_frame
->contents
))
1521 /* Adjust .eh_frame for .plt.got section. */
1522 if (htab
->plt_got_eh_frame
!= NULL
1523 && htab
->plt_got_eh_frame
->contents
!= NULL
)
1525 if (htab
->plt_got
!= NULL
1526 && htab
->plt_got
->size
!= 0
1527 && (htab
->plt_got
->flags
& SEC_EXCLUDE
) == 0
1528 && htab
->plt_got
->output_section
!= NULL
1529 && htab
->plt_got_eh_frame
->output_section
!= NULL
)
1531 bfd_vma plt_start
= htab
->plt_got
->output_section
->vma
;
1532 bfd_vma eh_frame_start
= htab
->plt_got_eh_frame
->output_section
->vma
1533 + htab
->plt_got_eh_frame
->output_offset
1534 + PLT_FDE_START_OFFSET
;
1535 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1536 htab
->plt_got_eh_frame
->contents
1537 + PLT_FDE_START_OFFSET
);
1539 if (htab
->plt_got_eh_frame
->sec_info_type
== SEC_INFO_TYPE_EH_FRAME
)
1541 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1542 htab
->plt_got_eh_frame
,
1543 htab
->plt_got_eh_frame
->contents
))
1548 /* Adjust .eh_frame for the second PLT section. */
1549 if (htab
->plt_second_eh_frame
!= NULL
1550 && htab
->plt_second_eh_frame
->contents
!= NULL
)
1552 if (htab
->plt_second
!= NULL
1553 && htab
->plt_second
->size
!= 0
1554 && (htab
->plt_second
->flags
& SEC_EXCLUDE
) == 0
1555 && htab
->plt_second
->output_section
!= NULL
1556 && htab
->plt_second_eh_frame
->output_section
!= NULL
)
1558 bfd_vma plt_start
= htab
->plt_second
->output_section
->vma
;
1559 bfd_vma eh_frame_start
1560 = (htab
->plt_second_eh_frame
->output_section
->vma
1561 + htab
->plt_second_eh_frame
->output_offset
1562 + PLT_FDE_START_OFFSET
);
1563 bfd_put_signed_32 (dynobj
, plt_start
- eh_frame_start
,
1564 htab
->plt_second_eh_frame
->contents
1565 + PLT_FDE_START_OFFSET
);
1567 if (htab
->plt_second_eh_frame
->sec_info_type
1568 == SEC_INFO_TYPE_EH_FRAME
)
1570 if (! _bfd_elf_write_section_eh_frame (output_bfd
, info
,
1571 htab
->plt_second_eh_frame
,
1572 htab
->plt_second_eh_frame
->contents
))
1577 if (htab
->elf
.sgot
&& htab
->elf
.sgot
->size
> 0)
1578 elf_section_data (htab
->elf
.sgot
->output_section
)->this_hdr
.sh_entsize
1579 = htab
->got_entry_size
;
1586 _bfd_x86_elf_always_size_sections (bfd
*output_bfd
,
1587 struct bfd_link_info
*info
)
1589 asection
*tls_sec
= elf_hash_table (info
)->tls_sec
;
1593 struct elf_link_hash_entry
*tlsbase
;
1595 tlsbase
= elf_link_hash_lookup (elf_hash_table (info
),
1596 "_TLS_MODULE_BASE_",
1597 false, false, false);
1599 if (tlsbase
&& tlsbase
->type
== STT_TLS
)
1601 struct elf_x86_link_hash_table
*htab
;
1602 struct bfd_link_hash_entry
*bh
= NULL
;
1603 const struct elf_backend_data
*bed
1604 = get_elf_backend_data (output_bfd
);
1606 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1610 if (!(_bfd_generic_link_add_one_symbol
1611 (info
, output_bfd
, "_TLS_MODULE_BASE_", BSF_LOCAL
,
1612 tls_sec
, 0, NULL
, false,
1613 bed
->collect
, &bh
)))
1616 htab
->tls_module_base
= bh
;
1618 tlsbase
= (struct elf_link_hash_entry
*)bh
;
1619 tlsbase
->def_regular
= 1;
1620 tlsbase
->other
= STV_HIDDEN
;
1621 tlsbase
->root
.linker_def
= 1;
1622 (*bed
->elf_backend_hide_symbol
) (info
, tlsbase
, true);
1630 _bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
1631 unsigned int st_other
,
1633 bool dynamic ATTRIBUTE_UNUSED
)
1637 struct elf_x86_link_hash_entry
*eh
1638 = (struct elf_x86_link_hash_entry
*) h
;
1639 eh
->def_protected
= ELF_ST_VISIBILITY (st_other
) == STV_PROTECTED
;
1643 /* Copy the extra info we tack onto an elf_link_hash_entry. */
1646 _bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
1647 struct elf_link_hash_entry
*dir
,
1648 struct elf_link_hash_entry
*ind
)
1650 struct elf_x86_link_hash_entry
*edir
, *eind
;
1652 edir
= (struct elf_x86_link_hash_entry
*) dir
;
1653 eind
= (struct elf_x86_link_hash_entry
*) ind
;
1655 if (ind
->root
.type
== bfd_link_hash_indirect
1656 && dir
->got
.refcount
<= 0)
1658 edir
->tls_type
= eind
->tls_type
;
1659 eind
->tls_type
= GOT_UNKNOWN
;
1662 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1663 generate a R_386_COPY reloc. */
1664 edir
->gotoff_ref
|= eind
->gotoff_ref
;
1666 edir
->zero_undefweak
|= eind
->zero_undefweak
;
1668 if (ELIMINATE_COPY_RELOCS
1669 && ind
->root
.type
!= bfd_link_hash_indirect
1670 && dir
->dynamic_adjusted
)
1672 /* If called to transfer flags for a weakdef during processing
1673 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1674 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1675 if (dir
->versioned
!= versioned_hidden
)
1676 dir
->ref_dynamic
|= ind
->ref_dynamic
;
1677 dir
->ref_regular
|= ind
->ref_regular
;
1678 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
1679 dir
->needs_plt
|= ind
->needs_plt
;
1680 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
1683 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
1686 /* Remove undefined weak symbol from the dynamic symbol table if it
1687 is resolved to 0. */
1690 _bfd_x86_elf_fixup_symbol (struct bfd_link_info
*info
,
1691 struct elf_link_hash_entry
*h
)
1693 if (h
->dynindx
!= -1
1694 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info
, elf_x86_hash_entry (h
)))
1697 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
1703 /* Change the STT_GNU_IFUNC symbol defined in position-dependent
1704 executable into the normal function symbol and set its address
1705 to its PLT entry, which should be resolved by R_*_IRELATIVE at
1709 _bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info
*info
,
1710 struct elf_x86_link_hash_table
*htab
,
1711 struct elf_link_hash_entry
*h
,
1712 Elf_Internal_Sym
*sym
)
1714 if (bfd_link_pde (info
)
1717 && h
->plt
.offset
!= (bfd_vma
) -1
1718 && h
->type
== STT_GNU_IFUNC
)
1722 bfd
*output_bfd
= info
->output_bfd
;
1724 if (htab
->plt_second
)
1726 struct elf_x86_link_hash_entry
*eh
1727 = (struct elf_x86_link_hash_entry
*) h
;
1729 plt_s
= htab
->plt_second
;
1730 plt_offset
= eh
->plt_second
.offset
;
1734 plt_s
= htab
->elf
.splt
;
1735 plt_offset
= h
->plt
.offset
;
1739 sym
->st_info
= ELF_ST_INFO (ELF_ST_BIND (sym
->st_info
), STT_FUNC
);
1741 = _bfd_elf_section_from_bfd_section (output_bfd
,
1742 plt_s
->output_section
);
1743 sym
->st_value
= (plt_s
->output_section
->vma
1744 + plt_s
->output_offset
+ plt_offset
);
1748 /* Report relative relocation. */
1751 _bfd_x86_elf_link_report_relative_reloc
1752 (struct bfd_link_info
*info
, asection
*asect
,
1753 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*sym
,
1754 const char *reloc_name
, const void *reloc
)
1758 const Elf_Internal_Rela
*rel
= (const Elf_Internal_Rela
*) reloc
;
1759 char r_offset
[30], r_info
[30];
1761 /* Use the output BFD for linker created sections. */
1762 if ((asect
->flags
& SEC_LINKER_CREATED
) != 0)
1763 abfd
= info
->output_bfd
;
1765 abfd
= asect
->owner
;
1767 if (h
!= NULL
&& h
->root
.root
.string
!= NULL
)
1768 name
= h
->root
.root
.string
;
1770 name
= bfd_elf_sym_name (abfd
, &elf_symtab_hdr (abfd
), sym
, NULL
);
1772 bfd_sprintf_vma (abfd
, r_offset
, rel
->r_offset
);
1773 bfd_sprintf_vma (abfd
, r_info
, rel
->r_info
);
1775 if (asect
->use_rela_p
)
1779 bfd_sprintf_vma (abfd
, r_addend
, rel
->r_addend
);
1781 info
->callbacks
->einfo
1782 (_("%pB: %s (offset: 0x%s, info: 0x%s, addend: 0x%s) against "
1783 "'%s' " "for section '%pA' in %pB\n"),
1784 info
->output_bfd
, reloc_name
, r_offset
, r_info
, r_addend
,
1788 info
->callbacks
->einfo
1789 (_("%pB: %s (offset: 0x%s, info: 0x%s) against '%s' for section "
1791 info
->output_bfd
, reloc_name
, r_offset
, r_info
, name
,
1795 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
1798 _bfd_x86_elf_hash_symbol (struct elf_link_hash_entry
*h
)
1800 if (h
->plt
.offset
!= (bfd_vma
) -1
1802 && !h
->pointer_equality_needed
)
1805 return _bfd_elf_hash_symbol (h
);
1808 /* Adjust a symbol defined by a dynamic object and referenced by a
1809 regular object. The current definition is in some section of the
1810 dynamic object, but we're not including those sections. We have to
1811 change the definition to something the rest of the link can
1815 _bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
1816 struct elf_link_hash_entry
*h
)
1818 struct elf_x86_link_hash_table
*htab
;
1820 struct elf_x86_link_hash_entry
*eh
;
1821 struct elf_dyn_relocs
*p
;
1822 const struct elf_backend_data
*bed
1823 = get_elf_backend_data (info
->output_bfd
);
1825 eh
= (struct elf_x86_link_hash_entry
*) h
;
1827 /* Clear GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS if it is turned
1828 on by an input relocatable file and there is a non-GOT/non-PLT
1829 reference from another relocatable file without it.
1830 NB: There can be non-GOT reference in data sections in input with
1831 GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS. */
1832 if (eh
->non_got_ref_without_indirect_extern_access
1833 && info
->indirect_extern_access
== 1
1834 && bfd_link_executable (info
))
1836 unsigned int needed_1
;
1837 info
->indirect_extern_access
= 0;
1838 /* Turn off nocopyreloc if implied by indirect_extern_access. */
1839 if (info
->nocopyreloc
== 2)
1840 info
->nocopyreloc
= 0;
1841 needed_1
= bfd_h_get_32 (info
->output_bfd
, info
->needed_1_p
);
1842 needed_1
&= ~GNU_PROPERTY_1_NEEDED_INDIRECT_EXTERN_ACCESS
;
1843 bfd_h_put_32 (info
->output_bfd
, needed_1
, info
->needed_1_p
);
1846 /* STT_GNU_IFUNC symbol must go through PLT. */
1847 if (h
->type
== STT_GNU_IFUNC
)
1849 /* All local STT_GNU_IFUNC references must be treate as local
1850 calls via local PLT. */
1852 && SYMBOL_CALLS_LOCAL (info
, h
))
1854 bfd_size_type pc_count
= 0, count
= 0;
1855 struct elf_dyn_relocs
**pp
;
1857 eh
= (struct elf_x86_link_hash_entry
*) h
;
1858 for (pp
= &h
->dyn_relocs
; (p
= *pp
) != NULL
; )
1860 pc_count
+= p
->pc_count
;
1861 p
->count
-= p
->pc_count
;
1870 if (pc_count
|| count
)
1875 /* Increment PLT reference count only for PC-relative
1878 if (h
->plt
.refcount
<= 0)
1879 h
->plt
.refcount
= 1;
1881 h
->plt
.refcount
+= 1;
1885 /* GOTOFF relocation needs PLT. */
1887 h
->plt
.refcount
= 1;
1890 if (h
->plt
.refcount
<= 0)
1892 h
->plt
.offset
= (bfd_vma
) -1;
1898 /* If this is a function, put it in the procedure linkage table. We
1899 will fill in the contents of the procedure linkage table later,
1900 when we know the address of the .got section. */
1901 if (h
->type
== STT_FUNC
1904 if (h
->plt
.refcount
<= 0
1905 || SYMBOL_CALLS_LOCAL (info
, h
)
1906 || (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1907 && h
->root
.type
== bfd_link_hash_undefweak
))
1909 /* This case can occur if we saw a PLT32 reloc in an input
1910 file, but the symbol was never referred to by a dynamic
1911 object, or if all references were garbage collected. In
1912 such a case, we don't actually need to build a procedure
1913 linkage table, and we can just do a PC32 reloc instead. */
1914 h
->plt
.offset
= (bfd_vma
) -1;
1921 /* It's possible that we incorrectly decided a .plt reloc was needed
1922 * for an R_386_PC32/R_X86_64_PC32 reloc to a non-function sym in
1923 check_relocs. We can't decide accurately between function and
1924 non-function syms in check-relocs; Objects loaded later in
1925 the link may change h->type. So fix it now. */
1926 h
->plt
.offset
= (bfd_vma
) -1;
1928 /* If this is a weak symbol, and there is a real definition, the
1929 processor independent code will have arranged for us to see the
1930 real definition first, and we can just use the same value. */
1931 if (h
->is_weakalias
)
1933 struct elf_link_hash_entry
*def
= weakdef (h
);
1934 BFD_ASSERT (def
->root
.type
== bfd_link_hash_defined
);
1935 h
->root
.u
.def
.section
= def
->root
.u
.def
.section
;
1936 h
->root
.u
.def
.value
= def
->root
.u
.def
.value
;
1937 if (ELIMINATE_COPY_RELOCS
1938 || info
->nocopyreloc
1939 || SYMBOL_NO_COPYRELOC (info
, eh
))
1941 /* NB: needs_copy is always 0 for i386. */
1942 h
->non_got_ref
= def
->non_got_ref
;
1943 eh
->needs_copy
= def
->needs_copy
;
1948 /* This is a reference to a symbol defined by a dynamic object which
1949 is not a function. */
1951 /* If we are creating a shared library, we must presume that the
1952 only references to the symbol are via the global offset table.
1953 For such cases we need not do anything here; the relocations will
1954 be handled correctly by relocate_section. */
1955 if (!bfd_link_executable (info
))
1958 /* If there are no references to this symbol that do not use the
1959 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
1960 reloc. NB: gotoff_ref is always 0 for x86-64. */
1961 if (!h
->non_got_ref
&& !eh
->gotoff_ref
)
1964 /* If -z nocopyreloc was given, we won't generate them either. */
1965 if (info
->nocopyreloc
|| SYMBOL_NO_COPYRELOC (info
, eh
))
1971 htab
= elf_x86_hash_table (info
, bed
->target_id
);
1975 /* If there aren't any dynamic relocs in read-only sections nor
1976 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
1977 avoid the copy reloc. This doesn't work on VxWorks, where we can
1978 not have dynamic relocations (other than copy and jump slot
1979 relocations) in an executable. */
1980 if (ELIMINATE_COPY_RELOCS
1981 && (bed
->target_id
== X86_64_ELF_DATA
1983 && htab
->elf
.target_os
!= is_vxworks
)))
1985 /* If we don't find any dynamic relocs in read-only sections,
1986 then we'll be keeping the dynamic relocs and avoiding the copy
1988 if (!_bfd_elf_readonly_dynrelocs (h
))
1995 /* We must allocate the symbol in our .dynbss section, which will
1996 become part of the .bss section of the executable. There will be
1997 an entry for this symbol in the .dynsym section. The dynamic
1998 object will contain position independent code, so all references
1999 from the dynamic object to this symbol will go through the global
2000 offset table. The dynamic linker will use the .dynsym entry to
2001 determine the address it must put in the global offset table, so
2002 both the dynamic object and the regular object will refer to the
2003 same memory location for the variable. */
2005 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
2006 dynamic linker to copy the initial value out of the dynamic object
2007 and into the runtime process image. */
2008 if ((h
->root
.u
.def
.section
->flags
& SEC_READONLY
) != 0)
2010 s
= htab
->elf
.sdynrelro
;
2011 srel
= htab
->elf
.sreldynrelro
;
2015 s
= htab
->elf
.sdynbss
;
2016 srel
= htab
->elf
.srelbss
;
2018 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0 && h
->size
!= 0)
2020 srel
->size
+= htab
->sizeof_reloc
;
2024 return _bfd_elf_adjust_dynamic_copy (info
, h
, s
);
2028 _bfd_x86_elf_hide_symbol (struct bfd_link_info
*info
,
2029 struct elf_link_hash_entry
*h
,
2032 if (h
->root
.type
== bfd_link_hash_undefweak
2034 && bfd_link_pie (info
))
2036 /* When there is no dynamic interpreter in PIE, make the undefined
2037 weak symbol dynamic so that PC relative branch to the undefined
2038 weak symbol will land to address 0. */
2039 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2040 if (h
->plt
.refcount
> 0
2041 || eh
->plt_got
.refcount
> 0)
2045 _bfd_elf_link_hash_hide_symbol (info
, h
, force_local
);
2048 /* Return TRUE if a symbol is referenced locally. It is similar to
2049 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
2050 works in check_relocs. */
2053 _bfd_x86_elf_link_symbol_references_local (struct bfd_link_info
*info
,
2054 struct elf_link_hash_entry
*h
)
2056 struct elf_x86_link_hash_entry
*eh
= elf_x86_hash_entry (h
);
2057 struct elf_x86_link_hash_table
*htab
2058 = (struct elf_x86_link_hash_table
*) info
->hash
;
2060 if (eh
->local_ref
> 1)
2063 if (eh
->local_ref
== 1)
2066 /* Unversioned symbols defined in regular objects can be forced local
2067 by linker version script. A weak undefined symbol is forced local
2069 1. It has non-default visibility. Or
2070 2. When building executable, there is no dynamic linker. Or
2071 3. or "-z nodynamic-undefined-weak" is used.
2073 if (SYMBOL_REFERENCES_LOCAL (info
, h
)
2074 || (h
->root
.type
== bfd_link_hash_undefweak
2075 && (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2076 || (bfd_link_executable (info
)
2077 && htab
->interp
== NULL
)
2078 || info
->dynamic_undefined_weak
== 0))
2079 || ((h
->def_regular
|| ELF_COMMON_DEF_P (h
))
2080 && info
->version_info
!= NULL
2081 && _bfd_elf_link_hide_sym_by_version (info
, h
)))
2091 /* Return the section that should be marked against GC for a given
2095 _bfd_x86_elf_gc_mark_hook (asection
*sec
,
2096 struct bfd_link_info
*info
,
2097 Elf_Internal_Rela
*rel
,
2098 struct elf_link_hash_entry
*h
,
2099 Elf_Internal_Sym
*sym
)
2101 /* Compiler should optimize this out. */
2102 if (((unsigned int) R_X86_64_GNU_VTINHERIT
2103 != (unsigned int) R_386_GNU_VTINHERIT
)
2104 || ((unsigned int) R_X86_64_GNU_VTENTRY
2105 != (unsigned int) R_386_GNU_VTENTRY
))
2109 switch (ELF32_R_TYPE (rel
->r_info
))
2111 case R_X86_64_GNU_VTINHERIT
:
2112 case R_X86_64_GNU_VTENTRY
:
2116 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
2120 elf_i386_get_plt_got_vma (struct elf_x86_plt
*plt_p ATTRIBUTE_UNUSED
,
2122 bfd_vma offset ATTRIBUTE_UNUSED
,
2125 return got_addr
+ off
;
2129 elf_x86_64_get_plt_got_vma (struct elf_x86_plt
*plt_p
,
2132 bfd_vma got_addr ATTRIBUTE_UNUSED
)
2134 return plt_p
->sec
->vma
+ offset
+ off
+ plt_p
->plt_got_insn_size
;
2138 elf_i386_valid_plt_reloc_p (unsigned int type
)
2140 return (type
== R_386_JUMP_SLOT
2141 || type
== R_386_GLOB_DAT
2142 || type
== R_386_IRELATIVE
);
2146 elf_x86_64_valid_plt_reloc_p (unsigned int type
)
2148 return (type
== R_X86_64_JUMP_SLOT
2149 || type
== R_X86_64_GLOB_DAT
2150 || type
== R_X86_64_IRELATIVE
);
2154 _bfd_x86_elf_get_synthetic_symtab (bfd
*abfd
,
2158 struct elf_x86_plt plts
[],
2162 long size
, i
, n
, len
;
2164 unsigned int plt_got_offset
, plt_entry_size
;
2166 bfd_byte
*plt_contents
;
2168 arelent
**dynrelbuf
, *p
;
2170 const struct elf_backend_data
*bed
;
2171 bfd_vma (*get_plt_got_vma
) (struct elf_x86_plt
*, bfd_vma
, bfd_vma
,
2173 bool (*valid_plt_reloc_p
) (unsigned int);
2179 dynrelbuf
= (arelent
**) bfd_malloc (relsize
);
2180 if (dynrelbuf
== NULL
)
2183 dynrelcount
= bfd_canonicalize_dynamic_reloc (abfd
, dynrelbuf
,
2185 if (dynrelcount
<= 0)
2188 /* Sort the relocs by address. */
2189 qsort (dynrelbuf
, dynrelcount
, sizeof (arelent
*),
2190 _bfd_x86_elf_compare_relocs
);
2192 size
= count
* sizeof (asymbol
);
2194 /* Allocate space for @plt suffixes. */
2196 for (i
= 0; i
< dynrelcount
; i
++)
2199 size
+= strlen ((*p
->sym_ptr_ptr
)->name
) + sizeof ("@plt");
2201 size
+= sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd
);
2204 s
= *ret
= (asymbol
*) bfd_zmalloc (size
);
2208 bed
= get_elf_backend_data (abfd
);
2210 if (bed
->target_id
== X86_64_ELF_DATA
)
2212 get_plt_got_vma
= elf_x86_64_get_plt_got_vma
;
2213 valid_plt_reloc_p
= elf_x86_64_valid_plt_reloc_p
;
2217 get_plt_got_vma
= elf_i386_get_plt_got_vma
;
2218 valid_plt_reloc_p
= elf_i386_valid_plt_reloc_p
;
2221 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
2223 asection
*sec
= bfd_get_section_by_name (abfd
, ".got.plt");
2225 got_addr
= sec
->vma
;
2228 sec
= bfd_get_section_by_name (abfd
, ".got");
2230 got_addr
= sec
->vma
;
2233 if (got_addr
== (bfd_vma
) -1)
2238 /* Check for each PLT section. */
2239 names
= (char *) (s
+ count
);
2242 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2243 if ((plt_contents
= plts
[j
].contents
) != NULL
)
2248 struct elf_x86_plt
*plt_p
= &plts
[j
];
2250 plt_got_offset
= plt_p
->plt_got_offset
;
2251 plt_entry_size
= plt_p
->plt_entry_size
;
2255 if ((plt_p
->type
& plt_lazy
))
2257 /* Skip PLT0 in lazy PLT. */
2259 offset
= plt_entry_size
;
2267 /* Check each PLT entry against dynamic relocations. */
2268 for (; k
< plt_p
->count
; k
++)
2274 /* Get the GOT offset for i386 or the PC-relative offset
2275 for x86-64, a signed 32-bit integer. */
2276 off
= H_GET_32 (abfd
, (plt_contents
+ offset
2278 got_vma
= get_plt_got_vma (plt_p
, off
, offset
, got_addr
);
2280 /* Binary search. */
2284 while ((min
+ 1) < max
)
2288 mid
= (min
+ max
) / 2;
2290 if (got_vma
> r
->address
)
2292 else if (got_vma
< r
->address
)
2301 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
2302 if (got_vma
== p
->address
2304 && valid_plt_reloc_p (p
->howto
->type
))
2306 *s
= **p
->sym_ptr_ptr
;
2307 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
2308 set. Since we are defining a symbol, ensure one
2310 if ((s
->flags
& BSF_LOCAL
) == 0)
2311 s
->flags
|= BSF_GLOBAL
;
2312 s
->flags
|= BSF_SYNTHETIC
;
2313 /* This is no longer a section symbol. */
2314 s
->flags
&= ~BSF_SECTION_SYM
;
2316 s
->the_bfd
= plt
->owner
;
2320 len
= strlen ((*p
->sym_ptr_ptr
)->name
);
2321 memcpy (names
, (*p
->sym_ptr_ptr
)->name
, len
);
2327 memcpy (names
, "+0x", sizeof ("+0x") - 1);
2328 names
+= sizeof ("+0x") - 1;
2329 bfd_sprintf_vma (abfd
, buf
, p
->addend
);
2330 for (a
= buf
; *a
== '0'; ++a
)
2333 memcpy (names
, a
, size
);
2336 memcpy (names
, "@plt", sizeof ("@plt"));
2337 names
+= sizeof ("@plt");
2340 /* There should be only one entry in PLT for a given
2341 symbol. Set howto to NULL after processing a PLT
2342 entry to guard against corrupted PLT. */
2345 offset
+= plt_entry_size
;
2349 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
2358 for (j
= 0; plts
[j
].name
!= NULL
; j
++)
2359 free (plts
[j
].contents
);
2366 /* Parse x86 GNU properties. */
2368 enum elf_property_kind
2369 _bfd_x86_elf_parse_gnu_properties (bfd
*abfd
, unsigned int type
,
2370 bfd_byte
*ptr
, unsigned int datasz
)
2374 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2375 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2376 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2377 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2378 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2379 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
2380 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2381 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2386 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
2387 abfd
, type
, datasz
);
2388 return property_corrupt
;
2390 prop
= _bfd_elf_get_property (abfd
, type
, datasz
);
2391 prop
->u
.number
|= bfd_h_get_32 (abfd
, ptr
);
2392 prop
->pr_kind
= property_number
;
2393 return property_number
;
2396 return property_ignored
;
2399 /* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
2400 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
2401 should be merged with ABFD. */
2404 _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info
*info
,
2405 bfd
*abfd ATTRIBUTE_UNUSED
,
2406 bfd
*bbfd ATTRIBUTE_UNUSED
,
2407 elf_property
*aprop
,
2408 elf_property
*bprop
)
2410 unsigned int number
, features
;
2411 bool updated
= false;
2412 const struct elf_backend_data
*bed
;
2413 struct elf_x86_link_hash_table
*htab
;
2414 unsigned int pr_type
= aprop
!= NULL
? aprop
->pr_type
: bprop
->pr_type
;
2416 if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2417 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2418 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
2420 if (aprop
== NULL
|| bprop
== NULL
)
2422 /* Only one of APROP and BPROP can be NULL. */
2425 /* Remove this property since the other input file doesn't
2427 aprop
->pr_kind
= property_remove
;
2433 number
= aprop
->u
.number
;
2434 aprop
->u
.number
= number
| bprop
->u
.number
;
2435 updated
= number
!= (unsigned int) aprop
->u
.number
;
2439 else if (pr_type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2440 || (pr_type
>= GNU_PROPERTY_X86_UINT32_OR_LO
2441 && pr_type
<= GNU_PROPERTY_X86_UINT32_OR_HI
))
2444 if (pr_type
== GNU_PROPERTY_X86_ISA_1_NEEDED
)
2446 bed
= get_elf_backend_data (info
->output_bfd
);
2447 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2448 switch (htab
->params
->isa_level
)
2453 features
= GNU_PROPERTY_X86_ISA_1_V2
;
2456 features
= GNU_PROPERTY_X86_ISA_1_V3
;
2459 features
= GNU_PROPERTY_X86_ISA_1_V4
;
2465 if (aprop
!= NULL
&& bprop
!= NULL
)
2467 number
= aprop
->u
.number
;
2468 aprop
->u
.number
= number
| bprop
->u
.number
| features
;
2469 /* Remove the property if all bits are empty. */
2470 if (aprop
->u
.number
== 0)
2472 aprop
->pr_kind
= property_remove
;
2476 updated
= number
!= (unsigned int) aprop
->u
.number
;
2480 /* Only one of APROP and BPROP can be NULL. */
2483 aprop
->u
.number
|= features
;
2484 if (aprop
->u
.number
== 0)
2486 /* Remove APROP if all bits are empty. */
2487 aprop
->pr_kind
= property_remove
;
2493 /* Return TRUE if APROP is NULL and all bits of BPROP
2494 aren't empty to indicate that BPROP should be added
2496 bprop
->u
.number
|= features
;
2497 updated
= bprop
->u
.number
!= 0;
2502 else if (pr_type
>= GNU_PROPERTY_X86_UINT32_AND_LO
2503 && pr_type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
2505 /* Only one of APROP and BPROP can be NULL:
2506 1. APROP & BPROP when both APROP and BPROP aren't NULL.
2507 2. If APROP is NULL, remove x86 feature.
2508 3. Otherwise, do nothing.
2510 bed
= get_elf_backend_data (info
->output_bfd
);
2511 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2514 if (aprop
!= NULL
&& bprop
!= NULL
)
2516 number
= aprop
->u
.number
;
2517 aprop
->u
.number
= number
& bprop
->u
.number
;
2518 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2521 if (htab
->params
->ibt
)
2522 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2523 if (htab
->params
->shstk
)
2524 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2525 if (htab
->params
->lam_u48
)
2526 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2527 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2528 else if (htab
->params
->lam_u57
)
2529 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2530 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT,
2531 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2532 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
2533 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
2534 aprop
->u
.number
|= features
;
2536 updated
= number
!= (unsigned int) aprop
->u
.number
;
2537 /* Remove the property if all feature bits are cleared. */
2538 if (aprop
->u
.number
== 0)
2539 aprop
->pr_kind
= property_remove
;
2543 /* There should be no AND properties since some input doesn't
2544 have them. Set IBT and SHSTK properties for -z ibt and -z
2547 if (pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2549 if (htab
->params
->ibt
)
2550 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2551 if (htab
->params
->shstk
)
2552 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2553 if (htab
->params
->lam_u48
)
2554 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2555 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2556 else if (htab
->params
->lam_u57
)
2557 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2563 updated
= features
!= (unsigned int) aprop
->u
.number
;
2564 aprop
->u
.number
= features
;
2569 bprop
->u
.number
= features
;
2572 else if (aprop
!= NULL
)
2574 aprop
->pr_kind
= property_remove
;
2582 /* Never should happen. */
2589 /* Set up x86 GNU properties. Return the first relocatable ELF input
2590 with GNU properties if found. Otherwise, return NULL. */
2593 _bfd_x86_elf_link_setup_gnu_properties
2594 (struct bfd_link_info
*info
, struct elf_x86_init_table
*init_table
)
2598 asection
*sec
, *pltsec
;
2601 unsigned int plt_alignment
, features
, isa_level
;
2602 struct elf_x86_link_hash_table
*htab
;
2606 const struct elf_backend_data
*bed
;
2607 unsigned int class_align
= ABI_64_P (info
->output_bfd
) ? 3 : 2;
2608 unsigned int got_align
;
2610 /* Find a normal input file with GNU property note. */
2611 for (pbfd
= info
->input_bfds
;
2613 pbfd
= pbfd
->link
.next
)
2614 if (bfd_get_flavour (pbfd
) == bfd_target_elf_flavour
2615 && bfd_count_sections (pbfd
) != 0)
2619 if (elf_properties (pbfd
) != NULL
)
2623 bed
= get_elf_backend_data (info
->output_bfd
);
2625 htab
= elf_x86_hash_table (info
, bed
->target_id
);
2630 if (htab
->params
->ibt
)
2632 features
= GNU_PROPERTY_X86_FEATURE_1_IBT
;
2633 htab
->params
->cet_report
&= ~prop_report_ibt
;
2635 if (htab
->params
->shstk
)
2637 features
|= GNU_PROPERTY_X86_FEATURE_1_SHSTK
;
2638 htab
->params
->cet_report
&= ~prop_report_shstk
;
2640 if (!(htab
->params
->cet_report
& (prop_report_ibt
| prop_report_shstk
)))
2641 htab
->params
->cet_report
= prop_report_none
;
2642 if (htab
->params
->lam_u48
)
2644 features
|= (GNU_PROPERTY_X86_FEATURE_1_LAM_U48
2645 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2646 htab
->params
->lam_u48_report
= prop_report_none
;
2647 htab
->params
->lam_u57_report
= prop_report_none
;
2649 else if (htab
->params
->lam_u57
)
2651 features
|= GNU_PROPERTY_X86_FEATURE_1_LAM_U57
;
2652 htab
->params
->lam_u57_report
= prop_report_none
;
2655 switch (htab
->params
->isa_level
)
2661 isa_level
= GNU_PROPERTY_X86_ISA_1_BASELINE
;
2664 isa_level
= GNU_PROPERTY_X86_ISA_1_V2
;
2667 isa_level
= GNU_PROPERTY_X86_ISA_1_V3
;
2670 isa_level
= GNU_PROPERTY_X86_ISA_1_V4
;
2681 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT,
2682 GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2683 GNU_PROPERTY_X86_FEATURE_1_LAM_U48 and
2684 GNU_PROPERTY_X86_FEATURE_1_LAM_U57. */
2685 prop
= _bfd_elf_get_property (ebfd
,
2686 GNU_PROPERTY_X86_FEATURE_1_AND
,
2688 prop
->u
.number
|= features
;
2689 prop
->pr_kind
= property_number
;
2694 /* If ISA level is set, add GNU_PROPERTY_X86_ISA_1_NEEDED. */
2695 prop
= _bfd_elf_get_property (ebfd
,
2696 GNU_PROPERTY_X86_ISA_1_NEEDED
,
2698 prop
->u
.number
|= isa_level
;
2699 prop
->pr_kind
= property_number
;
2702 /* Create the GNU property note section if needed. */
2703 if (prop
!= NULL
&& pbfd
== NULL
)
2705 sec
= bfd_make_section_with_flags (ebfd
,
2706 NOTE_GNU_PROPERTY_SECTION_NAME
,
2714 info
->callbacks
->einfo (_("%F%P: failed to create GNU property section\n"));
2716 if (!bfd_set_section_alignment (sec
, class_align
))
2719 info
->callbacks
->einfo (_("%F%pA: failed to align section\n"),
2723 elf_section_type (sec
) = SHT_NOTE
;
2727 if (htab
->params
->cet_report
2728 || htab
->params
->lam_u48_report
2729 || htab
->params
->lam_u57_report
)
2731 /* Report missing IBT, SHSTK and LAM properties. */
2733 const char *warning_msg
= _("%P: %pB: warning: missing %s\n");
2734 const char *error_msg
= _("%X%P: %pB: error: missing %s\n");
2735 const char *cet_msg
= NULL
;
2736 const char *lam_u48_msg
= NULL
;
2737 const char *lam_u57_msg
= NULL
;
2738 const char *missing
;
2739 elf_property_list
*p
;
2740 bool missing_ibt
, missing_shstk
;
2741 bool missing_lam_u48
, missing_lam_u57
;
2743 = (htab
->params
->cet_report
2744 && (htab
->params
->cet_report
& prop_report_ibt
));
2746 = (htab
->params
->cet_report
2747 && (htab
->params
->cet_report
& prop_report_shstk
));
2749 if (htab
->params
->cet_report
)
2751 if ((htab
->params
->cet_report
& prop_report_warning
))
2752 cet_msg
= warning_msg
;
2754 cet_msg
= error_msg
;
2756 if (htab
->params
->lam_u48_report
)
2758 if ((htab
->params
->lam_u48_report
& prop_report_warning
))
2759 lam_u48_msg
= warning_msg
;
2761 lam_u48_msg
= error_msg
;
2763 if (htab
->params
->lam_u57_report
)
2765 if ((htab
->params
->lam_u57_report
& prop_report_warning
))
2766 lam_u57_msg
= warning_msg
;
2768 lam_u57_msg
= error_msg
;
2771 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
2772 if (!(abfd
->flags
& (DYNAMIC
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
2773 && bfd_get_flavour (abfd
) == bfd_target_elf_flavour
)
2775 for (p
= elf_properties (abfd
); p
; p
= p
->next
)
2776 if (p
->property
.pr_type
== GNU_PROPERTY_X86_FEATURE_1_AND
)
2779 missing_ibt
= check_ibt
;
2780 missing_shstk
= check_shstk
;
2781 missing_lam_u48
= !!lam_u48_msg
;
2782 missing_lam_u57
= !!lam_u57_msg
;
2785 missing_ibt
&= !(p
->property
.u
.number
2786 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2787 missing_shstk
&= !(p
->property
.u
.number
2788 & GNU_PROPERTY_X86_FEATURE_1_SHSTK
);
2789 missing_lam_u48
&= !(p
->property
.u
.number
2790 & GNU_PROPERTY_X86_FEATURE_1_LAM_U48
);
2791 missing_lam_u57
&= !(p
->property
.u
.number
2792 & GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
2794 if (missing_ibt
|| missing_shstk
)
2796 if (missing_ibt
&& missing_shstk
)
2797 missing
= _("IBT and SHSTK properties");
2798 else if (missing_ibt
)
2799 missing
= _("IBT property");
2801 missing
= _("SHSTK property");
2802 info
->callbacks
->einfo (cet_msg
, abfd
, missing
);
2804 if (missing_lam_u48
)
2806 missing
= _("LAM_U48 property");
2807 info
->callbacks
->einfo (lam_u48_msg
, abfd
, missing
);
2809 if (missing_lam_u57
)
2811 missing
= _("LAM_U57 property");
2812 info
->callbacks
->einfo (lam_u57_msg
, abfd
, missing
);
2817 pbfd
= _bfd_elf_link_setup_gnu_properties (info
);
2819 htab
->r_info
= init_table
->r_info
;
2820 htab
->r_sym
= init_table
->r_sym
;
2822 if (bfd_link_relocatable (info
))
2825 htab
->plt0_pad_byte
= init_table
->plt0_pad_byte
;
2827 use_ibt_plt
= htab
->params
->ibtplt
|| htab
->params
->ibt
;
2828 if (!use_ibt_plt
&& pbfd
!= NULL
)
2830 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
2831 elf_property_list
*p
;
2833 /* The property list is sorted in order of type. */
2834 for (p
= elf_properties (pbfd
); p
; p
= p
->next
)
2836 if (GNU_PROPERTY_X86_FEATURE_1_AND
== p
->property
.pr_type
)
2838 use_ibt_plt
= !!(p
->property
.u
.number
2839 & GNU_PROPERTY_X86_FEATURE_1_IBT
);
2842 else if (GNU_PROPERTY_X86_FEATURE_1_AND
< p
->property
.pr_type
)
2847 dynobj
= htab
->elf
.dynobj
;
2849 /* Set htab->elf.dynobj here so that there is no need to check and
2850 set it in check_relocs. */
2855 htab
->elf
.dynobj
= pbfd
;
2862 /* Find a normal input file to hold linker created
2864 for (abfd
= info
->input_bfds
;
2866 abfd
= abfd
->link
.next
)
2867 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
2869 & (DYNAMIC
| BFD_LINKER_CREATED
| BFD_PLUGIN
)) == 0
2870 && bed
->relocs_compatible (abfd
->xvec
,
2871 info
->output_bfd
->xvec
))
2873 htab
->elf
.dynobj
= abfd
;
2880 /* Return if there are no normal input files. */
2884 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
2885 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
2886 canonical function address. */
2887 htab
->plt
.has_plt0
= 1;
2888 normal_target
= htab
->elf
.target_os
== is_normal
;
2894 htab
->lazy_plt
= init_table
->lazy_ibt_plt
;
2895 htab
->non_lazy_plt
= init_table
->non_lazy_ibt_plt
;
2899 htab
->lazy_plt
= init_table
->lazy_plt
;
2900 htab
->non_lazy_plt
= init_table
->non_lazy_plt
;
2905 htab
->lazy_plt
= init_table
->lazy_plt
;
2906 htab
->non_lazy_plt
= NULL
;
2909 pltsec
= htab
->elf
.splt
;
2911 /* If the non-lazy PLT is available, use it for all PLT entries if
2912 there are no PLT0 or no .plt section. */
2913 if (htab
->non_lazy_plt
!= NULL
2914 && (!htab
->plt
.has_plt0
|| pltsec
== NULL
))
2917 if (bfd_link_pic (info
))
2918 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->pic_plt_entry
;
2920 htab
->plt
.plt_entry
= htab
->non_lazy_plt
->plt_entry
;
2921 htab
->plt
.plt_entry_size
= htab
->non_lazy_plt
->plt_entry_size
;
2922 htab
->plt
.plt_got_offset
= htab
->non_lazy_plt
->plt_got_offset
;
2923 htab
->plt
.plt_got_insn_size
2924 = htab
->non_lazy_plt
->plt_got_insn_size
;
2925 htab
->plt
.eh_frame_plt_size
2926 = htab
->non_lazy_plt
->eh_frame_plt_size
;
2927 htab
->plt
.eh_frame_plt
= htab
->non_lazy_plt
->eh_frame_plt
;
2932 if (bfd_link_pic (info
))
2934 htab
->plt
.plt0_entry
= htab
->lazy_plt
->pic_plt0_entry
;
2935 htab
->plt
.plt_entry
= htab
->lazy_plt
->pic_plt_entry
;
2939 htab
->plt
.plt0_entry
= htab
->lazy_plt
->plt0_entry
;
2940 htab
->plt
.plt_entry
= htab
->lazy_plt
->plt_entry
;
2942 htab
->plt
.plt_entry_size
= htab
->lazy_plt
->plt_entry_size
;
2943 htab
->plt
.plt_got_offset
= htab
->lazy_plt
->plt_got_offset
;
2944 htab
->plt
.plt_got_insn_size
2945 = htab
->lazy_plt
->plt_got_insn_size
;
2946 htab
->plt
.eh_frame_plt_size
2947 = htab
->lazy_plt
->eh_frame_plt_size
;
2948 htab
->plt
.eh_frame_plt
= htab
->lazy_plt
->eh_frame_plt
;
2951 if (htab
->elf
.target_os
== is_vxworks
2952 && !elf_vxworks_create_dynamic_sections (dynobj
, info
,
2955 info
->callbacks
->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
2959 /* Since create_dynamic_sections isn't always called, but GOT
2960 relocations need GOT relocations, create them here so that we
2961 don't need to do it in check_relocs. */
2962 if (htab
->elf
.sgot
== NULL
2963 && !_bfd_elf_create_got_section (dynobj
, info
))
2964 info
->callbacks
->einfo (_("%F%P: failed to create GOT sections\n"));
2966 got_align
= (bed
->target_id
== X86_64_ELF_DATA
) ? 3 : 2;
2968 /* Align .got and .got.plt sections to their entry size. Do it here
2969 instead of in create_dynamic_sections so that they are always
2970 properly aligned even if create_dynamic_sections isn't called. */
2971 sec
= htab
->elf
.sgot
;
2972 if (!bfd_set_section_alignment (sec
, got_align
))
2973 goto error_alignment
;
2975 sec
= htab
->elf
.sgotplt
;
2976 if (!bfd_set_section_alignment (sec
, got_align
))
2977 goto error_alignment
;
2979 /* Create the ifunc sections here so that check_relocs can be
2981 if (!_bfd_elf_create_ifunc_sections (dynobj
, info
))
2982 info
->callbacks
->einfo (_("%F%P: failed to create ifunc sections\n"));
2984 plt_alignment
= bfd_log2 (htab
->plt
.plt_entry_size
);
2988 /* Whe creating executable, set the contents of the .interp
2989 section to the interpreter. */
2990 if (bfd_link_executable (info
) && !info
->nointerp
)
2992 asection
*s
= bfd_get_linker_section (dynobj
, ".interp");
2995 s
->size
= htab
->dynamic_interpreter_size
;
2996 s
->contents
= (unsigned char *) htab
->dynamic_interpreter
;
3002 flagword pltflags
= (bed
->dynamic_sec_flags
3007 unsigned int non_lazy_plt_alignment
3008 = bfd_log2 (htab
->non_lazy_plt
->plt_entry_size
);
3011 if (!bfd_set_section_alignment (sec
, plt_alignment
))
3012 goto error_alignment
;
3014 /* Create the GOT procedure linkage table. */
3015 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3019 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT section\n"));
3021 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
3022 goto error_alignment
;
3024 htab
->plt_got
= sec
;
3032 /* Create the second PLT for Intel IBT support. IBT
3033 PLT is needed only for lazy binding. */
3034 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3038 info
->callbacks
->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
3040 if (!bfd_set_section_alignment (sec
, plt_alignment
))
3041 goto error_alignment
;
3043 else if (htab
->params
->bndplt
&& ABI_64_P (dynobj
))
3045 /* Create the second PLT for Intel MPX support. MPX
3046 PLT is supported only in 64-bit mode and is needed
3047 only for lazy binding. */
3048 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3052 info
->callbacks
->einfo (_("%F%P: failed to create BND PLT section\n"));
3054 if (!bfd_set_section_alignment (sec
, non_lazy_plt_alignment
))
3055 goto error_alignment
;
3058 htab
->plt_second
= sec
;
3062 if (!info
->no_ld_generated_unwind_info
)
3064 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
3065 | SEC_HAS_CONTENTS
| SEC_IN_MEMORY
3066 | SEC_LINKER_CREATED
);
3068 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3072 info
->callbacks
->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
3074 if (!bfd_set_section_alignment (sec
, class_align
))
3075 goto error_alignment
;
3077 htab
->plt_eh_frame
= sec
;
3079 if (htab
->plt_got
!= NULL
)
3081 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3085 info
->callbacks
->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
3087 if (!bfd_set_section_alignment (sec
, class_align
))
3088 goto error_alignment
;
3090 htab
->plt_got_eh_frame
= sec
;
3093 if (htab
->plt_second
!= NULL
)
3095 sec
= bfd_make_section_anyway_with_flags (dynobj
,
3099 info
->callbacks
->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
3101 if (!bfd_set_section_alignment (sec
, class_align
))
3102 goto error_alignment
;
3104 htab
->plt_second_eh_frame
= sec
;
3109 /* The .iplt section is used for IFUNC symbols in static
3111 sec
= htab
->elf
.iplt
;
3114 /* NB: Delay setting its alignment until we know it is non-empty.
3115 Otherwise an empty iplt section may change vma and lma of the
3116 following sections, which triggers moving dot of the following
3117 section backwards, resulting in a warning and section lma not
3118 being set properly. It later leads to a "File truncated"
3120 if (!bfd_set_section_alignment (sec
, 0))
3121 goto error_alignment
;
3123 htab
->plt
.iplt_alignment
= (normal_target
3125 : bed
->plt_alignment
);
3128 if (bfd_link_executable (info
)
3130 && !htab
->params
->has_dynamic_linker
3131 && htab
->params
->static_before_all_inputs
)
3133 /* Report error for dynamic input objects if -static is passed at
3134 command-line before all input files without --dynamic-linker
3135 unless --no-dynamic-linker is used. */
3138 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link
.next
)
3139 if ((abfd
->flags
& DYNAMIC
))
3140 info
->callbacks
->einfo
3141 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
3148 /* Fix up x86 GNU properties. */
3151 _bfd_x86_elf_link_fixup_gnu_properties
3152 (struct bfd_link_info
*info
, elf_property_list
**listp
)
3154 elf_property_list
*p
;
3156 for (p
= *listp
; p
; p
= p
->next
)
3158 unsigned int type
= p
->property
.pr_type
;
3159 if (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3160 || type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3161 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3162 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3163 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3164 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)
3165 || (type
>= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3166 && type
<= GNU_PROPERTY_X86_UINT32_OR_AND_HI
))
3168 if (p
->property
.u
.number
== 0
3169 && (type
== GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3170 || (type
>= GNU_PROPERTY_X86_UINT32_AND_LO
3171 && type
<= GNU_PROPERTY_X86_UINT32_AND_HI
)
3172 || (type
>= GNU_PROPERTY_X86_UINT32_OR_LO
3173 && type
<= GNU_PROPERTY_X86_UINT32_OR_HI
)))
3175 /* Remove empty property. */
3180 /* Keep LAM features only for 64-bit output. */
3181 if (type
== GNU_PROPERTY_X86_FEATURE_1_AND
3182 && !ABI_64_P (info
->output_bfd
))
3183 p
->property
.u
.number
&= ~(GNU_PROPERTY_X86_FEATURE_1_LAM_U48
3184 | GNU_PROPERTY_X86_FEATURE_1_LAM_U57
);
3188 else if (type
> GNU_PROPERTY_HIPROC
)
3190 /* The property list is sorted in order of type. */
3197 _bfd_elf_linker_x86_set_options (struct bfd_link_info
* info
,
3198 struct elf_linker_x86_params
*params
)
3200 const struct elf_backend_data
*bed
3201 = get_elf_backend_data (info
->output_bfd
);
3202 struct elf_x86_link_hash_table
*htab
3203 = elf_x86_hash_table (info
, bed
->target_id
);
3205 htab
->params
= params
;