RISC-V: Don't assume the priv attributes are in order when handling them.
[deliverable/binutils-gdb.git] / bfd / elfxx-x86.c
CommitLineData
0afcef53 1/* x86 specific support for ELF
b3adc24a 2 Copyright (C) 2017-2020 Free Software Foundation, Inc.
0afcef53
L
3
4 This file is part of BFD, the Binary File Descriptor library.
5
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.
10
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.
15
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. */
20
21#include "elfxx-x86.h"
a6798bab 22#include "elf-vxworks.h"
765e526c
L
23#include "objalloc.h"
24#include "elf/i386.h"
25#include "elf/x86-64.h"
26
27/* The name of the dynamic interpreter. This is put in the .interp
28 section. */
29
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"
0afcef53 33
39946cc2
L
34bfd_boolean
35_bfd_x86_elf_mkobject (bfd *abfd)
36{
37 return bfd_elf_allocate_object (abfd,
38 sizeof (struct elf_x86_obj_tdata),
39 get_elf_backend_data (abfd)->target_id);
40}
41
0afcef53
L
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. */
46
47void
48_bfd_x86_elf_set_tls_module_base (struct bfd_link_info *info)
49{
50 struct elf_x86_link_hash_table *htab;
51 struct bfd_link_hash_entry *base;
52 const struct elf_backend_data *bed;
53
54 if (!bfd_link_executable (info))
55 return;
56
57 bed = get_elf_backend_data (info->output_bfd);
58 htab = elf_x86_hash_table (info, bed->target_id);
59 if (htab == NULL)
60 return;
61
62 base = htab->tls_module_base;
63 if (base == NULL)
64 return;
65
66 base->u.def.value = htab->elf.tls_size;
67}
68
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. */
72
73bfd_vma
74_bfd_x86_elf_dtpoff_base (struct bfd_link_info *info)
75{
76 /* If tls_sec is NULL, we should have signalled an error already. */
77 if (elf_hash_table (info)->tls_sec == NULL)
78 return 0;
79 return elf_hash_table (info)->tls_sec->vma;
80}
81
b9ce864c
L
82/* Allocate space in .plt, .got and associated reloc sections for
83 dynamic relocs. */
84
5e2ac45d 85static bfd_boolean
70090aa5 86elf_x86_allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf)
b9ce864c
L
87{
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;
95
96 if (h->root.type == bfd_link_hash_indirect)
97 return TRUE;
98
99 eh = (struct elf_x86_link_hash_entry *) h;
100
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);
104 if (htab == NULL)
105 return FALSE;
106
107 plt_entry_size = htab->plt.plt_entry_size;
108
c5bce5c6 109 resolved_to_zero = UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, eh);
b9ce864c 110
b9ce864c
L
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
114 loop at run-time. */
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)
120 {
121 /* Don't use the regular PLT if there are both GOT and GOTPLT
07d6d2b8 122 reloctions. */
b9ce864c
L
123 h->plt.offset = (bfd_vma) -1;
124
125 /* Use the GOT PLT. */
126 eh->plt_got.refcount = 1;
127 }
128
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
132 && h->def_regular)
133 {
190eb1dd 134 if (_bfd_elf_allocate_ifunc_dyn_relocs (info, h, &h->dyn_relocs,
b9ce864c
L
135 plt_entry_size,
136 (htab->plt.has_plt0
137 * plt_entry_size),
138 htab->got_entry_size,
139 TRUE))
140 {
141 asection *s = htab->plt_second;
142 if (h->plt.offset != (bfd_vma) -1 && s != NULL)
143 {
144 /* Use the second PLT section if it is created. */
145 eh->plt_second.offset = s->size;
146
147 /* Make room for this entry in the second PLT section. */
148 s->size += htab->non_lazy_plt->plt_entry_size;
149 }
150
151 return TRUE;
152 }
153 else
154 return FALSE;
155 }
156 /* Don't create the PLT entry if there are only function pointer
157 relocations which can be resolved at run-time. */
158 else if (htab->elf.dynamic_sections_created
79b0c981 159 && (h->plt.refcount > 0
b9ce864c
L
160 || eh->plt_got.refcount > 0))
161 {
162 bfd_boolean use_plt_got = eh->plt_got.refcount > 0;
163
b9ce864c
L
164 /* Make sure this symbol is output as a dynamic symbol.
165 Undefined weak syms won't yet be marked as dynamic. */
166 if (h->dynindx == -1
167 && !h->forced_local
168 && !resolved_to_zero
169 && h->root.type == bfd_link_hash_undefweak)
170 {
171 if (! bfd_elf_link_record_dynamic_symbol (info, h))
172 return FALSE;
173 }
174
175 if (bfd_link_pic (info)
176 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
177 {
178 asection *s = htab->elf.splt;
179 asection *second_s = htab->plt_second;
180 asection *got_s = htab->plt_got;
451875b4 181 bfd_boolean use_plt;
b9ce864c
L
182
183 /* If this is the first .plt entry, make room for the special
184 first entry. The .plt section is used by prelink to undo
185 prelinking for dynamic relocations. */
186 if (s->size == 0)
187 s->size = htab->plt.has_plt0 * plt_entry_size;
188
189 if (use_plt_got)
190 eh->plt_got.offset = got_s->size;
191 else
192 {
193 h->plt.offset = s->size;
194 if (second_s)
195 eh->plt_second.offset = second_s->size;
196 }
197
198 /* If this symbol is not defined in a regular file, and we are
451875b4
L
199 generating PDE, then set the symbol to this location in the
200 .plt. This is required to make function pointers compare
201 as equal between PDE and the shared library.
202
203 NB: If PLT is PC-relative, we can use the .plt in PIE for
204 function address. */
205 if (h->def_regular)
206 use_plt = FALSE;
207 else if (htab->pcrel_plt)
208 use_plt = ! bfd_link_dll (info);
209 else
210 use_plt = bfd_link_pde (info);
211 if (use_plt)
b9ce864c
L
212 {
213 if (use_plt_got)
214 {
215 /* We need to make a call to the entry of the GOT PLT
216 instead of regular PLT entry. */
217 h->root.u.def.section = got_s;
218 h->root.u.def.value = eh->plt_got.offset;
219 }
220 else
221 {
222 if (second_s)
223 {
224 /* We need to make a call to the entry of the
225 second PLT instead of regular PLT entry. */
226 h->root.u.def.section = second_s;
227 h->root.u.def.value = eh->plt_second.offset;
228 }
229 else
230 {
231 h->root.u.def.section = s;
232 h->root.u.def.value = h->plt.offset;
233 }
234 }
235 }
236
237 /* Make room for this entry. */
238 if (use_plt_got)
239 got_s->size += htab->non_lazy_plt->plt_entry_size;
240 else
241 {
242 s->size += plt_entry_size;
243 if (second_s)
244 second_s->size += htab->non_lazy_plt->plt_entry_size;
245
246 /* We also need to make an entry in the .got.plt section,
247 which will be placed in the .got section by the linker
248 script. */
249 htab->elf.sgotplt->size += htab->got_entry_size;
250
251 /* There should be no PLT relocation against resolved
252 undefined weak symbol in executable. */
253 if (!resolved_to_zero)
254 {
255 /* We also need to make an entry in the .rel.plt
256 section. */
257 htab->elf.srelplt->size += htab->sizeof_reloc;
258 htab->elf.srelplt->reloc_count++;
259 }
260 }
261
90c14f0c 262 if (htab->elf.target_os == is_vxworks && !bfd_link_pic (info))
b9ce864c
L
263 {
264 /* VxWorks has a second set of relocations for each PLT entry
265 in executables. They go in a separate relocation section,
266 which is processed by the kernel loader. */
267
268 /* There are two relocations for the initial PLT entry: an
269 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 4 and an
270 R_386_32 relocation for _GLOBAL_OFFSET_TABLE_ + 8. */
271
272 asection *srelplt2 = htab->srelplt2;
273 if (h->plt.offset == plt_entry_size)
274 srelplt2->size += (htab->sizeof_reloc * 2);
275
276 /* There are two extra relocations for each subsequent PLT entry:
277 an R_386_32 relocation for the GOT entry, and an R_386_32
278 relocation for the PLT entry. */
279
280 srelplt2->size += (htab->sizeof_reloc * 2);
281 }
282 }
283 else
284 {
285 eh->plt_got.offset = (bfd_vma) -1;
286 h->plt.offset = (bfd_vma) -1;
287 h->needs_plt = 0;
288 }
289 }
290 else
291 {
292 eh->plt_got.offset = (bfd_vma) -1;
293 h->plt.offset = (bfd_vma) -1;
294 h->needs_plt = 0;
295 }
296
297 eh->tlsdesc_got = (bfd_vma) -1;
298
299 /* For i386, if R_386_TLS_{IE_32,IE,GOTIE} symbol is now local to the
300 binary, make it a R_386_TLS_LE_32 requiring no TLS entry. For
301 x86-64, if R_X86_64_GOTTPOFF symbol is now local to the binary,
302 make it a R_X86_64_TPOFF32 requiring no GOT entry. */
303 if (h->got.refcount > 0
304 && bfd_link_executable (info)
305 && h->dynindx == -1
306 && (elf_x86_hash_entry (h)->tls_type & GOT_TLS_IE))
307 h->got.offset = (bfd_vma) -1;
308 else if (h->got.refcount > 0)
309 {
310 asection *s;
311 bfd_boolean dyn;
312 int tls_type = elf_x86_hash_entry (h)->tls_type;
313
314 /* Make sure this symbol is output as a dynamic symbol.
315 Undefined weak syms won't yet be marked as dynamic. */
316 if (h->dynindx == -1
317 && !h->forced_local
318 && !resolved_to_zero
319 && h->root.type == bfd_link_hash_undefweak)
320 {
321 if (! bfd_elf_link_record_dynamic_symbol (info, h))
322 return FALSE;
323 }
324
325 s = htab->elf.sgot;
326 if (GOT_TLS_GDESC_P (tls_type))
327 {
328 eh->tlsdesc_got = htab->elf.sgotplt->size
329 - elf_x86_compute_jump_table_size (htab);
330 htab->elf.sgotplt->size += 2 * htab->got_entry_size;
331 h->got.offset = (bfd_vma) -2;
332 }
333 if (! GOT_TLS_GDESC_P (tls_type)
334 || GOT_TLS_GD_P (tls_type))
335 {
336 h->got.offset = s->size;
337 s->size += htab->got_entry_size;
338 /* R_386_TLS_GD and R_X86_64_TLSGD need 2 consecutive GOT
339 slots. */
340 if (GOT_TLS_GD_P (tls_type) || tls_type == GOT_TLS_IE_BOTH)
341 s->size += htab->got_entry_size;
342 }
343 dyn = htab->elf.dynamic_sections_created;
344 /* R_386_TLS_IE_32 needs one dynamic relocation,
345 R_386_TLS_IE resp. R_386_TLS_GOTIE needs one dynamic relocation,
346 (but if both R_386_TLS_IE_32 and R_386_TLS_IE is present, we
347 need two), R_386_TLS_GD and R_X86_64_TLSGD need one if local
348 symbol and two if global. No dynamic relocation against
382aae06
L
349 resolved undefined weak symbol in executable. No dynamic
350 relocation against non-preemptible absolute symbol. */
b9ce864c
L
351 if (tls_type == GOT_TLS_IE_BOTH)
352 htab->elf.srelgot->size += 2 * htab->sizeof_reloc;
353 else if ((GOT_TLS_GD_P (tls_type) && h->dynindx == -1)
354 || (tls_type & GOT_TLS_IE))
355 htab->elf.srelgot->size += htab->sizeof_reloc;
356 else if (GOT_TLS_GD_P (tls_type))
357 htab->elf.srelgot->size += 2 * htab->sizeof_reloc;
358 else if (! GOT_TLS_GDESC_P (tls_type)
359 && ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
360 && !resolved_to_zero)
361 || h->root.type != bfd_link_hash_undefweak)
382aae06
L
362 && ((bfd_link_pic (info)
363 && !(h->dynindx == -1
364 && ABS_SYMBOL_P (h)))
b9ce864c
L
365 || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
366 htab->elf.srelgot->size += htab->sizeof_reloc;
367 if (GOT_TLS_GDESC_P (tls_type))
0e30d991
L
368 {
369 htab->elf.srelplt->size += htab->sizeof_reloc;
370 if (bed->target_id == X86_64_ELF_DATA)
9bcc30e4 371 htab->elf.tlsdesc_plt = (bfd_vma) -1;
0e30d991 372 }
b9ce864c
L
373 }
374 else
375 h->got.offset = (bfd_vma) -1;
376
190eb1dd 377 if (h->dyn_relocs == NULL)
b9ce864c
L
378 return TRUE;
379
380 /* In the shared -Bsymbolic case, discard space allocated for
381 dynamic pc-relative relocs against symbols which turn out to be
382 defined in regular objects. For the normal shared case, discard
383 space for pc-relative relocs that have become local due to symbol
384 visibility changes. */
385
386 if (bfd_link_pic (info))
387 {
388 /* Relocs that use pc_count are those that appear on a call
389 insn, or certain REL relocs that can generated via assembly.
390 We want calls to protected symbols to resolve directly to the
391 function rather than going via the plt. If people want
392 function pointer comparisons to work as expected then they
393 should avoid writing weird assembly. */
394 if (SYMBOL_CALLS_LOCAL (info, h))
395 {
396 struct elf_dyn_relocs **pp;
397
190eb1dd 398 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
b9ce864c
L
399 {
400 p->count -= p->pc_count;
401 p->pc_count = 0;
402 if (p->count == 0)
403 *pp = p->next;
404 else
405 pp = &p->next;
406 }
407 }
408
90c14f0c 409 if (htab->elf.target_os == is_vxworks)
b9ce864c
L
410 {
411 struct elf_dyn_relocs **pp;
190eb1dd 412 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
b9ce864c
L
413 {
414 if (strcmp (p->sec->output_section->name, ".tls_vars") == 0)
415 *pp = p->next;
416 else
417 pp = &p->next;
418 }
419 }
420
421 /* Also discard relocs on undefined weak syms with non-default
422 visibility or in PIE. */
190eb1dd 423 if (h->dyn_relocs != NULL)
b9ce864c
L
424 {
425 if (h->root.type == bfd_link_hash_undefweak)
426 {
427 /* Undefined weak symbol is never bound locally in shared
428 library. */
429 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
430 || resolved_to_zero)
431 {
432 if (bed->target_id == I386_ELF_DATA
433 && h->non_got_ref)
434 {
435 /* Keep dynamic non-GOT/non-PLT relocation so
436 that we can branch to 0 without PLT. */
437 struct elf_dyn_relocs **pp;
438
190eb1dd 439 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
b9ce864c
L
440 if (p->pc_count == 0)
441 *pp = p->next;
442 else
443 {
444 /* Remove non-R_386_PC32 relocation. */
445 p->count = p->pc_count;
446 pp = &p->next;
447 }
448
449 /* Make sure undefined weak symbols are output
450 as dynamic symbols in PIEs for dynamic non-GOT
451 non-PLT reloations. */
190eb1dd 452 if (h->dyn_relocs != NULL
b9ce864c
L
453 && !bfd_elf_link_record_dynamic_symbol (info, h))
454 return FALSE;
455 }
456 else
190eb1dd 457 h->dyn_relocs = NULL;
b9ce864c
L
458 }
459 else if (h->dynindx == -1
460 && !h->forced_local
461 && !bfd_elf_link_record_dynamic_symbol (info, h))
462 return FALSE;
463 }
464 else if (bfd_link_executable (info)
465 && (h->needs_copy || eh->needs_copy)
466 && h->def_dynamic
467 && !h->def_regular)
468 {
469 /* NB: needs_copy is set only for x86-64. For PIE,
470 discard space for pc-relative relocs against symbols
471 which turn out to need copy relocs. */
472 struct elf_dyn_relocs **pp;
473
190eb1dd 474 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
b9ce864c
L
475 {
476 if (p->pc_count != 0)
477 *pp = p->next;
478 else
479 pp = &p->next;
480 }
481 }
482 }
483 }
484 else if (ELIMINATE_COPY_RELOCS)
485 {
486 /* For the non-shared case, discard space for relocs against
487 symbols which turn out to need copy relocs or are not
488 dynamic. Keep dynamic relocations for run-time function
489 pointer initialization. */
490
491 if ((!h->non_got_ref
b9ce864c
L
492 || (h->root.type == bfd_link_hash_undefweak
493 && !resolved_to_zero))
494 && ((h->def_dynamic
495 && !h->def_regular)
496 || (htab->elf.dynamic_sections_created
497 && (h->root.type == bfd_link_hash_undefweak
498 || h->root.type == bfd_link_hash_undefined))))
499 {
500 /* Make sure this symbol is output as a dynamic symbol.
501 Undefined weak syms won't yet be marked as dynamic. */
502 if (h->dynindx == -1
503 && !h->forced_local
504 && !resolved_to_zero
505 && h->root.type == bfd_link_hash_undefweak
506 && ! bfd_elf_link_record_dynamic_symbol (info, h))
507 return FALSE;
508
509 /* If that succeeded, we know we'll be keeping all the
510 relocs. */
511 if (h->dynindx != -1)
512 goto keep;
513 }
514
190eb1dd 515 h->dyn_relocs = NULL;
b9ce864c
L
516
517 keep: ;
518 }
519
520 /* Finally, allocate space. */
190eb1dd 521 for (p = h->dyn_relocs; p != NULL; p = p->next)
b9ce864c
L
522 {
523 asection *sreloc;
524
525 sreloc = elf_section_data (p->sec)->sreloc;
526
527 BFD_ASSERT (sreloc != NULL);
528 sreloc->size += p->count * htab->sizeof_reloc;
529 }
530
531 return TRUE;
532}
533
b9ce864c
L
534/* Allocate space in .plt, .got and associated reloc sections for
535 local dynamic relocs. */
536
5e2ac45d
L
537static bfd_boolean
538elf_x86_allocate_local_dynreloc (void **slot, void *inf)
b9ce864c
L
539{
540 struct elf_link_hash_entry *h
541 = (struct elf_link_hash_entry *) *slot;
542
543 if (h->type != STT_GNU_IFUNC
544 || !h->def_regular
545 || !h->ref_regular
546 || !h->forced_local
547 || h->root.type != bfd_link_hash_defined)
548 abort ();
549
5e2ac45d 550 return elf_x86_allocate_dynrelocs (h, inf);
b9ce864c
L
551}
552
0afcef53
L
553/* Find and/or create a hash entry for local symbol. */
554
555struct elf_link_hash_entry *
556_bfd_elf_x86_get_local_sym_hash (struct elf_x86_link_hash_table *htab,
557 bfd *abfd, const Elf_Internal_Rela *rel,
558 bfd_boolean create)
559{
560 struct elf_x86_link_hash_entry e, *ret;
561 asection *sec = abfd->sections;
562 hashval_t h = ELF_LOCAL_SYMBOL_HASH (sec->id,
563 htab->r_sym (rel->r_info));
564 void **slot;
565
566 e.elf.indx = sec->id;
567 e.elf.dynstr_index = htab->r_sym (rel->r_info);
568 slot = htab_find_slot_with_hash (htab->loc_hash_table, &e, h,
569 create ? INSERT : NO_INSERT);
570
571 if (!slot)
572 return NULL;
573
574 if (*slot)
575 {
576 ret = (struct elf_x86_link_hash_entry *) *slot;
577 return &ret->elf;
578 }
579
580 ret = (struct elf_x86_link_hash_entry *)
581 objalloc_alloc ((struct objalloc *) htab->loc_hash_memory,
582 sizeof (struct elf_x86_link_hash_entry));
583 if (ret)
584 {
585 memset (ret, 0, sizeof (*ret));
586 ret->elf.indx = sec->id;
587 ret->elf.dynstr_index = htab->r_sym (rel->r_info);
588 ret->elf.dynindx = -1;
589 ret->plt_got.offset = (bfd_vma) -1;
590 *slot = ret;
591 }
592 return &ret->elf;
593}
594
595/* Create an entry in a x86 ELF linker hash table. NB: THIS MUST BE IN
596 SYNC WITH _bfd_elf_link_hash_newfunc. */
597
598struct bfd_hash_entry *
599_bfd_x86_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
600 struct bfd_hash_table *table,
601 const char *string)
602{
603 /* Allocate the structure if it has not already been allocated by a
604 subclass. */
605 if (entry == NULL)
606 {
607 entry = (struct bfd_hash_entry *)
608 bfd_hash_allocate (table,
609 sizeof (struct elf_x86_link_hash_entry));
610 if (entry == NULL)
611 return entry;
612 }
613
614 /* Call the allocation method of the superclass. */
615 entry = _bfd_link_hash_newfunc (entry, table, string);
616 if (entry != NULL)
617 {
618 struct elf_x86_link_hash_entry *eh
619 = (struct elf_x86_link_hash_entry *) entry;
620 struct elf_link_hash_table *htab
621 = (struct elf_link_hash_table *) table;
622
623 memset (&eh->elf.size, 0,
624 (sizeof (struct elf_x86_link_hash_entry)
625 - offsetof (struct elf_link_hash_entry, size)));
626 /* Set local fields. */
627 eh->elf.indx = -1;
628 eh->elf.dynindx = -1;
629 eh->elf.got = htab->init_got_refcount;
630 eh->elf.plt = htab->init_plt_refcount;
631 /* Assume that we have been called by a non-ELF symbol reader.
632 This flag is then reset by the code which reads an ELF input
633 file. This ensures that a symbol created by a non-ELF symbol
634 reader will have the flag set correctly. */
635 eh->elf.non_elf = 1;
636 eh->plt_second.offset = (bfd_vma) -1;
637 eh->plt_got.offset = (bfd_vma) -1;
638 eh->tlsdesc_got = (bfd_vma) -1;
98b273dc 639 eh->zero_undefweak = 1;
0afcef53
L
640 }
641
642 return entry;
643}
644
645/* Compute a hash of a local hash entry. We use elf_link_hash_entry
646 for local symbol so that we can handle local STT_GNU_IFUNC symbols
647 as global symbol. We reuse indx and dynstr_index for local symbol
648 hash since they aren't used by global symbols in this backend. */
649
650hashval_t
651_bfd_x86_elf_local_htab_hash (const void *ptr)
652{
653 struct elf_link_hash_entry *h
654 = (struct elf_link_hash_entry *) ptr;
655 return ELF_LOCAL_SYMBOL_HASH (h->indx, h->dynstr_index);
656}
657
658/* Compare local hash entries. */
659
660int
661_bfd_x86_elf_local_htab_eq (const void *ptr1, const void *ptr2)
662{
663 struct elf_link_hash_entry *h1
664 = (struct elf_link_hash_entry *) ptr1;
665 struct elf_link_hash_entry *h2
666 = (struct elf_link_hash_entry *) ptr2;
667
668 return h1->indx == h2->indx && h1->dynstr_index == h2->dynstr_index;
669}
670
671/* Destroy an x86 ELF linker hash table. */
672
765e526c
L
673static void
674elf_x86_link_hash_table_free (bfd *obfd)
0afcef53
L
675{
676 struct elf_x86_link_hash_table *htab
677 = (struct elf_x86_link_hash_table *) obfd->link.hash;
678
679 if (htab->loc_hash_table)
680 htab_delete (htab->loc_hash_table);
681 if (htab->loc_hash_memory)
682 objalloc_free ((struct objalloc *) htab->loc_hash_memory);
683 _bfd_elf_link_hash_table_free (obfd);
684}
685
5e2ac45d
L
686static bfd_boolean
687elf_i386_is_reloc_section (const char *secname)
688{
689 return CONST_STRNEQ (secname, ".rel");
690}
691
5e2ac45d
L
692static bfd_boolean
693elf_x86_64_is_reloc_section (const char *secname)
694{
695 return CONST_STRNEQ (secname, ".rela");
696}
5e2ac45d 697
765e526c
L
698/* Create an x86 ELF linker hash table. */
699
700struct bfd_link_hash_table *
701_bfd_x86_elf_link_hash_table_create (bfd *abfd)
702{
703 struct elf_x86_link_hash_table *ret;
704 const struct elf_backend_data *bed;
986f0783 705 size_t amt = sizeof (struct elf_x86_link_hash_table);
765e526c
L
706
707 ret = (struct elf_x86_link_hash_table *) bfd_zmalloc (amt);
708 if (ret == NULL)
709 return NULL;
710
711 bed = get_elf_backend_data (abfd);
712 if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd,
713 _bfd_x86_elf_link_hash_newfunc,
714 sizeof (struct elf_x86_link_hash_entry),
715 bed->target_id))
716 {
717 free (ret);
718 return NULL;
719 }
720
5e2ac45d
L
721 if (bed->target_id == X86_64_ELF_DATA)
722 {
5e2ac45d
L
723 ret->is_reloc_section = elf_x86_64_is_reloc_section;
724 ret->dt_reloc = DT_RELA;
725 ret->dt_reloc_sz = DT_RELASZ;
726 ret->dt_reloc_ent = DT_RELAENT;
727 ret->got_entry_size = 8;
451875b4 728 ret->pcrel_plt = TRUE;
f04bdfa7 729 ret->tls_get_addr = "__tls_get_addr";
5e2ac45d 730 }
765e526c
L
731 if (ABI_64_P (abfd))
732 {
503294e7 733 ret->sizeof_reloc = sizeof (Elf64_External_Rela);
765e526c
L
734 ret->pointer_r_type = R_X86_64_64;
735 ret->dynamic_interpreter = ELF64_DYNAMIC_INTERPRETER;
736 ret->dynamic_interpreter_size = sizeof ELF64_DYNAMIC_INTERPRETER;
765e526c
L
737 }
738 else
765e526c 739 {
5b86dbf4 740 if (bed->target_id == X86_64_ELF_DATA)
765e526c 741 {
503294e7 742 ret->sizeof_reloc = sizeof (Elf32_External_Rela);
765e526c
L
743 ret->pointer_r_type = R_X86_64_32;
744 ret->dynamic_interpreter = ELFX32_DYNAMIC_INTERPRETER;
745 ret->dynamic_interpreter_size
746 = sizeof ELFX32_DYNAMIC_INTERPRETER;
765e526c
L
747 }
748 else
749 {
5e2ac45d
L
750 ret->is_reloc_section = elf_i386_is_reloc_section;
751 ret->dt_reloc = DT_REL;
752 ret->dt_reloc_sz = DT_RELSZ;
753 ret->dt_reloc_ent = DT_RELENT;
503294e7 754 ret->sizeof_reloc = sizeof (Elf32_External_Rel);
9ff114ca 755 ret->got_entry_size = 4;
451875b4 756 ret->pcrel_plt = FALSE;
765e526c
L
757 ret->pointer_r_type = R_386_32;
758 ret->dynamic_interpreter = ELF32_DYNAMIC_INTERPRETER;
759 ret->dynamic_interpreter_size
760 = sizeof ELF32_DYNAMIC_INTERPRETER;
761 ret->tls_get_addr = "___tls_get_addr";
762 }
763 }
764
765 ret->loc_hash_table = htab_try_create (1024,
766 _bfd_x86_elf_local_htab_hash,
767 _bfd_x86_elf_local_htab_eq,
768 NULL);
769 ret->loc_hash_memory = objalloc_create ();
770 if (!ret->loc_hash_table || !ret->loc_hash_memory)
771 {
772 elf_x86_link_hash_table_free (abfd);
773 return NULL;
774 }
775 ret->elf.root.hash_table_free = elf_x86_link_hash_table_free;
776
777 return &ret->elf.root;
778}
779
0afcef53
L
780/* Sort relocs into address order. */
781
782int
783_bfd_x86_elf_compare_relocs (const void *ap, const void *bp)
784{
785 const arelent *a = * (const arelent **) ap;
786 const arelent *b = * (const arelent **) bp;
787
788 if (a->address > b->address)
789 return 1;
790 else if (a->address < b->address)
791 return -1;
792 else
793 return 0;
794}
795
9bc935ef
L
796/* Mark symbol, NAME, as locally defined by linker if it is referenced
797 and not defined in a relocatable object file. */
798
799static void
800elf_x86_linker_defined (struct bfd_link_info *info, const char *name)
801{
802 struct elf_link_hash_entry *h;
803
804 h = elf_link_hash_lookup (elf_hash_table (info), name,
805 FALSE, FALSE, FALSE);
806 if (h == NULL)
807 return;
808
809 while (h->root.type == bfd_link_hash_indirect)
810 h = (struct elf_link_hash_entry *) h->root.u.i.link;
811
812 if (h->root.type == bfd_link_hash_new
813 || h->root.type == bfd_link_hash_undefined
814 || h->root.type == bfd_link_hash_undefweak
815 || h->root.type == bfd_link_hash_common
816 || (!h->def_regular && h->def_dynamic))
817 {
818 elf_x86_hash_entry (h)->local_ref = 2;
819 elf_x86_hash_entry (h)->linker_def = 1;
820 }
821}
822
ecf99cc0
L
823/* Hide a linker-defined symbol, NAME, with hidden visibility. */
824
825static void
826elf_x86_hide_linker_defined (struct bfd_link_info *info,
827 const char *name)
828{
829 struct elf_link_hash_entry *h;
830
831 h = elf_link_hash_lookup (elf_hash_table (info), name,
832 FALSE, FALSE, FALSE);
833 if (h == NULL)
834 return;
835
836 while (h->root.type == bfd_link_hash_indirect)
837 h = (struct elf_link_hash_entry *) h->root.u.i.link;
838
839 if (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
840 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN)
841 _bfd_elf_link_hash_hide_symbol (info, h, TRUE);
842}
843
0afcef53
L
844bfd_boolean
845_bfd_x86_elf_link_check_relocs (bfd *abfd, struct bfd_link_info *info)
846{
847 if (!bfd_link_relocatable (info))
848 {
849 /* Check for __tls_get_addr reference. */
850 struct elf_x86_link_hash_table *htab;
851 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
852 htab = elf_x86_hash_table (info, bed->target_id);
853 if (htab)
854 {
0a27fed7
L
855 struct elf_link_hash_entry *h;
856
857 h = elf_link_hash_lookup (elf_hash_table (info),
0afcef53
L
858 htab->tls_get_addr,
859 FALSE, FALSE, FALSE);
860 if (h != NULL)
8a1b824a
L
861 {
862 elf_x86_hash_entry (h)->tls_get_addr = 1;
863
864 /* Check the versioned __tls_get_addr symbol. */
865 while (h->root.type == bfd_link_hash_indirect)
866 {
867 h = (struct elf_link_hash_entry *) h->root.u.i.link;
868 elf_x86_hash_entry (h)->tls_get_addr = 1;
869 }
870 }
0a27fed7
L
871
872 /* "__ehdr_start" will be defined by linker as a hidden symbol
873 later if it is referenced and not defined. */
9bc935ef
L
874 elf_x86_linker_defined (info, "__ehdr_start");
875
876 if (bfd_link_executable (info))
0a27fed7 877 {
9bc935ef
L
878 /* References to __bss_start, _end and _edata should be
879 locally resolved within executables. */
880 elf_x86_linker_defined (info, "__bss_start");
881 elf_x86_linker_defined (info, "_end");
882 elf_x86_linker_defined (info, "_edata");
ecf99cc0
L
883 }
884 else
885 {
886 /* Hide hidden __bss_start, _end and _edata in shared
887 libraries. */
888 elf_x86_hide_linker_defined (info, "__bss_start");
889 elf_x86_hide_linker_defined (info, "_end");
890 elf_x86_hide_linker_defined (info, "_edata");
0a27fed7 891 }
0afcef53
L
892 }
893 }
894
895 /* Invoke the regular ELF backend linker to do all the work. */
896 return _bfd_elf_link_check_relocs (abfd, info);
897}
898
382aae06
L
899bfd_boolean
900_bfd_elf_x86_valid_reloc_p (asection *input_section,
901 struct bfd_link_info *info,
902 struct elf_x86_link_hash_table *htab,
903 const Elf_Internal_Rela *rel,
904 struct elf_link_hash_entry *h,
905 Elf_Internal_Sym *sym,
906 Elf_Internal_Shdr *symtab_hdr,
907 bfd_boolean *no_dynreloc_p)
908{
909 bfd_boolean valid_p = TRUE;
910
911 *no_dynreloc_p = FALSE;
912
913 /* Check If relocation against non-preemptible absolute symbol is
914 valid in PIC. FIXME: Can't use SYMBOL_REFERENCES_LOCAL_P since
915 it may call _bfd_elf_link_hide_sym_by_version and result in
916 ld-elfvers/ vers21 test failure. */
917 if (bfd_link_pic (info)
918 && (h == NULL || SYMBOL_REFERENCES_LOCAL (info, h)))
919 {
920 const struct elf_backend_data *bed;
921 unsigned int r_type;
922 Elf_Internal_Rela irel;
923
924 /* Skip non-absolute symbol. */
925 if (h)
926 {
927 if (!ABS_SYMBOL_P (h))
928 return valid_p;
929 }
930 else if (sym->st_shndx != SHN_ABS)
931 return valid_p;
932
933 bed = get_elf_backend_data (input_section->owner);
934 r_type = ELF32_R_TYPE (rel->r_info);
935 irel = *rel;
936
937 /* Only allow relocations against absolute symbol, which can be
938 resolved as absolute value + addend. GOTPCREL relocations
939 are allowed since absolute value + addend is stored in the
940 GOT slot. */
941 if (bed->target_id == X86_64_ELF_DATA)
942 {
943 r_type &= ~R_X86_64_converted_reloc_bit;
944 valid_p = (r_type == R_X86_64_64
945 || r_type == R_X86_64_32
946 || r_type == R_X86_64_32S
947 || r_type == R_X86_64_16
948 || r_type == R_X86_64_8
949 || r_type == R_X86_64_GOTPCREL
950 || r_type == R_X86_64_GOTPCRELX
951 || r_type == R_X86_64_REX_GOTPCRELX);
952 if (!valid_p)
953 {
954 unsigned int r_symndx = htab->r_sym (rel->r_info);
955 irel.r_info = htab->r_info (r_symndx, r_type);
956 }
957 }
958 else
959 valid_p = (r_type == R_386_32
960 || r_type == R_386_16
961 || r_type == R_386_8);
962
963 if (valid_p)
964 *no_dynreloc_p = TRUE;
965 else
966 {
967 const char *name;
968 arelent internal_reloc;
969
970 if (!bed->elf_info_to_howto (input_section->owner,
971 &internal_reloc, &irel)
972 || internal_reloc.howto == NULL)
973 abort ();
974
975 if (h)
976 name = h->root.root.string;
977 else
978 name = bfd_elf_sym_name (input_section->owner, symtab_hdr,
979 sym, NULL);
980 info->callbacks->einfo
981 /* xgettext:c-format */
982 (_("%F%P: %pB: relocation %s against absolute symbol "
983 "`%s' in section `%pA' is disallowed\n"),
984 input_section->owner, internal_reloc.howto->name, name,
985 input_section);
986 bfd_set_error (bfd_error_bad_value);
987 }
988 }
989
990 return valid_p;
991}
992
5e2ac45d
L
993/* Set the sizes of the dynamic sections. */
994
995bfd_boolean
996_bfd_x86_elf_size_dynamic_sections (bfd *output_bfd,
997 struct bfd_link_info *info)
998{
999 struct elf_x86_link_hash_table *htab;
1000 bfd *dynobj;
1001 asection *s;
1002 bfd_boolean relocs;
1003 bfd *ibfd;
1004 const struct elf_backend_data *bed
1005 = get_elf_backend_data (output_bfd);
1006
1007 htab = elf_x86_hash_table (info, bed->target_id);
1008 if (htab == NULL)
1009 return FALSE;
1010 dynobj = htab->elf.dynobj;
1011 if (dynobj == NULL)
1012 abort ();
1013
1014 /* Set up .got offsets for local syms, and space for local dynamic
1015 relocs. */
1016 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
1017 {
1018 bfd_signed_vma *local_got;
1019 bfd_signed_vma *end_local_got;
1020 char *local_tls_type;
1021 bfd_vma *local_tlsdesc_gotent;
1022 bfd_size_type locsymcount;
1023 Elf_Internal_Shdr *symtab_hdr;
1024 asection *srel;
1025
1026 if (! is_x86_elf (ibfd, htab))
1027 continue;
1028
1029 for (s = ibfd->sections; s != NULL; s = s->next)
1030 {
1031 struct elf_dyn_relocs *p;
1032
5e2ac45d
L
1033 for (p = ((struct elf_dyn_relocs *)
1034 elf_section_data (s)->local_dynrel);
1035 p != NULL;
1036 p = p->next)
1037 {
1038 if (!bfd_is_abs_section (p->sec)
1039 && bfd_is_abs_section (p->sec->output_section))
1040 {
1041 /* Input section has been discarded, either because
1042 it is a copy of a linkonce section or due to
1043 linker script /DISCARD/, so we'll be discarding
1044 the relocs too. */
1045 }
90c14f0c 1046 else if (htab->elf.target_os == is_vxworks
5e2ac45d
L
1047 && strcmp (p->sec->output_section->name,
1048 ".tls_vars") == 0)
1049 {
1050 /* Relocations in vxworks .tls_vars sections are
1051 handled specially by the loader. */
1052 }
1053 else if (p->count != 0)
1054 {
1055 srel = elf_section_data (p->sec)->sreloc;
1056 srel->size += p->count * htab->sizeof_reloc;
1057 if ((p->sec->output_section->flags & SEC_READONLY) != 0
1058 && (info->flags & DF_TEXTREL) == 0)
1059 {
1060 info->flags |= DF_TEXTREL;
a6dbf402 1061 if (bfd_link_textrel_check (info))
5e2ac45d 1062 /* xgettext:c-format */
826c3f1e 1063 info->callbacks->einfo
871b3ab2
AM
1064 (_("%P: %pB: warning: relocation "
1065 "in read-only section `%pA'\n"),
826c3f1e 1066 p->sec->owner, p->sec);
5e2ac45d
L
1067 }
1068 }
1069 }
1070 }
1071
1072 local_got = elf_local_got_refcounts (ibfd);
1073 if (!local_got)
1074 continue;
1075
1076 symtab_hdr = &elf_symtab_hdr (ibfd);
1077 locsymcount = symtab_hdr->sh_info;
1078 end_local_got = local_got + locsymcount;
1079 local_tls_type = elf_x86_local_got_tls_type (ibfd);
1080 local_tlsdesc_gotent = elf_x86_local_tlsdesc_gotent (ibfd);
1081 s = htab->elf.sgot;
1082 srel = htab->elf.srelgot;
1083 for (; local_got < end_local_got;
1084 ++local_got, ++local_tls_type, ++local_tlsdesc_gotent)
1085 {
1086 *local_tlsdesc_gotent = (bfd_vma) -1;
1087 if (*local_got > 0)
1088 {
1089 if (GOT_TLS_GDESC_P (*local_tls_type))
1090 {
1091 *local_tlsdesc_gotent = htab->elf.sgotplt->size
1092 - elf_x86_compute_jump_table_size (htab);
1093 htab->elf.sgotplt->size += 2 * htab->got_entry_size;
1094 *local_got = (bfd_vma) -2;
1095 }
1096 if (! GOT_TLS_GDESC_P (*local_tls_type)
1097 || GOT_TLS_GD_P (*local_tls_type))
1098 {
1099 *local_got = s->size;
1100 s->size += htab->got_entry_size;
1101 if (GOT_TLS_GD_P (*local_tls_type)
1102 || *local_tls_type == GOT_TLS_IE_BOTH)
1103 s->size += htab->got_entry_size;
1104 }
382aae06 1105 if ((bfd_link_pic (info) && *local_tls_type != GOT_ABS)
5e2ac45d
L
1106 || GOT_TLS_GD_ANY_P (*local_tls_type)
1107 || (*local_tls_type & GOT_TLS_IE))
1108 {
1109 if (*local_tls_type == GOT_TLS_IE_BOTH)
1110 srel->size += 2 * htab->sizeof_reloc;
1111 else if (GOT_TLS_GD_P (*local_tls_type)
1112 || ! GOT_TLS_GDESC_P (*local_tls_type))
1113 srel->size += htab->sizeof_reloc;
1114 if (GOT_TLS_GDESC_P (*local_tls_type))
1115 {
1116 htab->elf.srelplt->size += htab->sizeof_reloc;
1117 if (bed->target_id == X86_64_ELF_DATA)
9bcc30e4 1118 htab->elf.tlsdesc_plt = (bfd_vma) -1;
5e2ac45d
L
1119 }
1120 }
1121 }
1122 else
1123 *local_got = (bfd_vma) -1;
1124 }
1125 }
1126
1127 if (htab->tls_ld_or_ldm_got.refcount > 0)
1128 {
1129 /* Allocate 2 got entries and 1 dynamic reloc for R_386_TLS_LDM
07d6d2b8 1130 or R_X86_64_TLSLD relocs. */
5e2ac45d
L
1131 htab->tls_ld_or_ldm_got.offset = htab->elf.sgot->size;
1132 htab->elf.sgot->size += 2 * htab->got_entry_size;
1133 htab->elf.srelgot->size += htab->sizeof_reloc;
1134 }
1135 else
1136 htab->tls_ld_or_ldm_got.offset = -1;
1137
1138 /* Allocate global sym .plt and .got entries, and space for global
1139 sym dynamic relocs. */
1140 elf_link_hash_traverse (&htab->elf, elf_x86_allocate_dynrelocs,
1141 info);
1142
1143 /* Allocate .plt and .got entries, and space for local symbols. */
1144 htab_traverse (htab->loc_hash_table, elf_x86_allocate_local_dynreloc,
1145 info);
1146
1147 /* For every jump slot reserved in the sgotplt, reloc_count is
1148 incremented. However, when we reserve space for TLS descriptors,
1149 it's not incremented, so in order to compute the space reserved
1150 for them, it suffices to multiply the reloc count by the jump
1151 slot size.
1152
1153 PR ld/13302: We start next_irelative_index at the end of .rela.plt
1154 so that R_{386,X86_64}_IRELATIVE entries come last. */
1155 if (htab->elf.srelplt)
1156 {
1157 htab->next_tls_desc_index = htab->elf.srelplt->reloc_count;
1158 htab->sgotplt_jump_table_size
1159 = elf_x86_compute_jump_table_size (htab);
1160 htab->next_irelative_index = htab->elf.srelplt->reloc_count - 1;
1161 }
1162 else if (htab->elf.irelplt)
1163 htab->next_irelative_index = htab->elf.irelplt->reloc_count - 1;
1164
9bcc30e4 1165 if (htab->elf.tlsdesc_plt)
5e2ac45d
L
1166 {
1167 /* NB: tlsdesc_plt is set only for x86-64. If we're not using
1168 lazy TLS relocations, don't generate the PLT and GOT entries
1169 they require. */
1170 if ((info->flags & DF_BIND_NOW))
9bcc30e4 1171 htab->elf.tlsdesc_plt = 0;
5e2ac45d
L
1172 else
1173 {
9bcc30e4 1174 htab->elf.tlsdesc_got = htab->elf.sgot->size;
5e2ac45d
L
1175 htab->elf.sgot->size += htab->got_entry_size;
1176 /* Reserve room for the initial entry.
1177 FIXME: we could probably do away with it in this case. */
1178 if (htab->elf.splt->size == 0)
1179 htab->elf.splt->size = htab->plt.plt_entry_size;
9bcc30e4 1180 htab->elf.tlsdesc_plt = htab->elf.splt->size;
5e2ac45d
L
1181 htab->elf.splt->size += htab->plt.plt_entry_size;
1182 }
1183 }
1184
1185 if (htab->elf.sgotplt)
1186 {
1187 /* Don't allocate .got.plt section if there are no GOT nor PLT
1188 entries and there is no reference to _GLOBAL_OFFSET_TABLE_. */
1189 if ((htab->elf.hgot == NULL
cd048363 1190 || !htab->got_referenced)
5e2ac45d
L
1191 && (htab->elf.sgotplt->size == bed->got_header_size)
1192 && (htab->elf.splt == NULL
1193 || htab->elf.splt->size == 0)
1194 && (htab->elf.sgot == NULL
1195 || htab->elf.sgot->size == 0)
1196 && (htab->elf.iplt == NULL
1197 || htab->elf.iplt->size == 0)
1198 && (htab->elf.igotplt == NULL
1199 || htab->elf.igotplt->size == 0))
cd048363
L
1200 {
1201 htab->elf.sgotplt->size = 0;
3b4c3844
L
1202 /* Solaris requires to keep _GLOBAL_OFFSET_TABLE_ even if it
1203 isn't used. */
90c14f0c
L
1204 if (htab->elf.hgot != NULL
1205 && htab->elf.target_os != is_solaris)
cd048363
L
1206 {
1207 /* Remove the unused _GLOBAL_OFFSET_TABLE_ from symbol
1208 table. */
1209 htab->elf.hgot->root.type = bfd_link_hash_undefined;
1210 htab->elf.hgot->root.u.undef.abfd
1211 = htab->elf.hgot->root.u.def.section->owner;
1212 htab->elf.hgot->root.linker_def = 0;
1213 htab->elf.hgot->ref_regular = 0;
1214 htab->elf.hgot->def_regular = 0;
1215 }
1216 }
5e2ac45d
L
1217 }
1218
1219 if (_bfd_elf_eh_frame_present (info))
1220 {
1221 if (htab->plt_eh_frame != NULL
1222 && htab->elf.splt != NULL
1223 && htab->elf.splt->size != 0
1224 && !bfd_is_abs_section (htab->elf.splt->output_section))
1225 htab->plt_eh_frame->size = htab->plt.eh_frame_plt_size;
1226
1227 if (htab->plt_got_eh_frame != NULL
1228 && htab->plt_got != NULL
1229 && htab->plt_got->size != 0
1230 && !bfd_is_abs_section (htab->plt_got->output_section))
1231 htab->plt_got_eh_frame->size
1232 = htab->non_lazy_plt->eh_frame_plt_size;
1233
1234 /* Unwind info for the second PLT and .plt.got sections are
1235 identical. */
1236 if (htab->plt_second_eh_frame != NULL
1237 && htab->plt_second != NULL
1238 && htab->plt_second->size != 0
1239 && !bfd_is_abs_section (htab->plt_second->output_section))
1240 htab->plt_second_eh_frame->size
1241 = htab->non_lazy_plt->eh_frame_plt_size;
1242 }
1243
1244 /* We now have determined the sizes of the various dynamic sections.
1245 Allocate memory for them. */
1246 relocs = FALSE;
1247 for (s = dynobj->sections; s != NULL; s = s->next)
1248 {
1249 bfd_boolean strip_section = TRUE;
1250
1251 if ((s->flags & SEC_LINKER_CREATED) == 0)
1252 continue;
1253
1254 if (s == htab->elf.splt
1255 || s == htab->elf.sgot)
1256 {
1257 /* Strip this section if we don't need it; see the
1258 comment below. */
1259 /* We'd like to strip these sections if they aren't needed, but if
1260 we've exported dynamic symbols from them we must leave them.
1261 It's too late to tell BFD to get rid of the symbols. */
1262
1263 if (htab->elf.hplt != NULL)
1264 strip_section = FALSE;
1265 }
1266 else if (s == htab->elf.sgotplt
1267 || s == htab->elf.iplt
1268 || s == htab->elf.igotplt
1269 || s == htab->plt_second
1270 || s == htab->plt_got
1271 || s == htab->plt_eh_frame
1272 || s == htab->plt_got_eh_frame
1273 || s == htab->plt_second_eh_frame
1274 || s == htab->elf.sdynbss
1275 || s == htab->elf.sdynrelro)
1276 {
1277 /* Strip these too. */
1278 }
fd361982 1279 else if (htab->is_reloc_section (bfd_section_name (s)))
5e2ac45d
L
1280 {
1281 if (s->size != 0
1282 && s != htab->elf.srelplt
1283 && s != htab->srelplt2)
1284 relocs = TRUE;
1285
1286 /* We use the reloc_count field as a counter if we need
1287 to copy relocs into the output file. */
1288 if (s != htab->elf.srelplt)
1289 s->reloc_count = 0;
1290 }
1291 else
1292 {
1293 /* It's not one of our sections, so don't allocate space. */
1294 continue;
1295 }
1296
1297 if (s->size == 0)
1298 {
1299 /* If we don't need this section, strip it from the
1300 output file. This is mostly to handle .rel.bss and
1301 .rel.plt. We must create both sections in
1302 create_dynamic_sections, because they must be created
1303 before the linker maps input sections to output
1304 sections. The linker does that before
1305 adjust_dynamic_symbol is called, and it is that
1306 function which decides whether anything needs to go
1307 into these sections. */
1308 if (strip_section)
1309 s->flags |= SEC_EXCLUDE;
1310 continue;
1311 }
1312
1313 if ((s->flags & SEC_HAS_CONTENTS) == 0)
1314 continue;
1315
b44ee3a8
L
1316 /* NB: Initially, the iplt section has minimal alignment to
1317 avoid moving dot of the following section backwards when
1318 it is empty. Update its section alignment now since it
1319 is non-empty. */
1320 if (s == htab->elf.iplt)
fd361982 1321 bfd_set_section_alignment (s, htab->plt.iplt_alignment);
b44ee3a8 1322
5e2ac45d
L
1323 /* Allocate memory for the section contents. We use bfd_zalloc
1324 here in case unused entries are not reclaimed before the
1325 section's contents are written out. This should not happen,
1326 but this way if it does, we get a R_386_NONE or R_X86_64_NONE
1327 reloc instead of garbage. */
1328 s->contents = (unsigned char *) bfd_zalloc (dynobj, s->size);
1329 if (s->contents == NULL)
1330 return FALSE;
1331 }
1332
1333 if (htab->plt_eh_frame != NULL
1334 && htab->plt_eh_frame->contents != NULL)
1335 {
1336 memcpy (htab->plt_eh_frame->contents,
1337 htab->plt.eh_frame_plt,
1338 htab->plt_eh_frame->size);
1339 bfd_put_32 (dynobj, htab->elf.splt->size,
1340 htab->plt_eh_frame->contents + PLT_FDE_LEN_OFFSET);
1341 }
1342
1343 if (htab->plt_got_eh_frame != NULL
1344 && htab->plt_got_eh_frame->contents != NULL)
1345 {
1346 memcpy (htab->plt_got_eh_frame->contents,
1347 htab->non_lazy_plt->eh_frame_plt,
1348 htab->plt_got_eh_frame->size);
1349 bfd_put_32 (dynobj, htab->plt_got->size,
1350 (htab->plt_got_eh_frame->contents
1351 + PLT_FDE_LEN_OFFSET));
1352 }
1353
1354 if (htab->plt_second_eh_frame != NULL
1355 && htab->plt_second_eh_frame->contents != NULL)
1356 {
1357 memcpy (htab->plt_second_eh_frame->contents,
1358 htab->non_lazy_plt->eh_frame_plt,
1359 htab->plt_second_eh_frame->size);
1360 bfd_put_32 (dynobj, htab->plt_second->size,
1361 (htab->plt_second_eh_frame->contents
1362 + PLT_FDE_LEN_OFFSET));
1363 }
1364
1365 if (htab->elf.dynamic_sections_created)
1366 {
1367 /* Add some entries to the .dynamic section. We fill in the
1368 values later, in elf_{i386,x86_64}_finish_dynamic_sections,
1369 but we must add the entries now so that we get the correct
1370 size for the .dynamic section. The DT_DEBUG entry is filled
1371 in by the dynamic linker and used by the debugger. */
1372#define add_dynamic_entry(TAG, VAL) \
1373 _bfd_elf_add_dynamic_entry (info, TAG, VAL)
1374
1375 if (bfd_link_executable (info))
1376 {
1377 if (!add_dynamic_entry (DT_DEBUG, 0))
1378 return FALSE;
1379 }
1380
1381 if (htab->elf.splt->size != 0)
1382 {
1383 /* DT_PLTGOT is used by prelink even if there is no PLT
1384 relocation. */
1385 if (!add_dynamic_entry (DT_PLTGOT, 0))
1386 return FALSE;
1387 }
1388
1389 if (htab->elf.srelplt->size != 0)
1390 {
1391 if (!add_dynamic_entry (DT_PLTRELSZ, 0)
1392 || !add_dynamic_entry (DT_PLTREL, htab->dt_reloc)
1393 || !add_dynamic_entry (DT_JMPREL, 0))
1394 return FALSE;
1395 }
1396
9bcc30e4 1397 if (htab->elf.tlsdesc_plt
5e2ac45d
L
1398 && (!add_dynamic_entry (DT_TLSDESC_PLT, 0)
1399 || !add_dynamic_entry (DT_TLSDESC_GOT, 0)))
1400 return FALSE;
1401
1402 if (relocs)
1403 {
1404 if (!add_dynamic_entry (htab->dt_reloc, 0)
1405 || !add_dynamic_entry (htab->dt_reloc_sz, 0)
1406 || !add_dynamic_entry (htab->dt_reloc_ent,
1407 htab->sizeof_reloc))
1408 return FALSE;
1409
1410 /* If any dynamic relocs apply to a read-only section,
1411 then we need a DT_TEXTREL entry. */
1412 if ((info->flags & DF_TEXTREL) == 0)
d49e5065
L
1413 elf_link_hash_traverse (&htab->elf,
1414 _bfd_elf_maybe_set_textrel, info);
5e2ac45d
L
1415
1416 if ((info->flags & DF_TEXTREL) != 0)
1417 {
cebd6b8a
L
1418 if (htab->elf.ifunc_resolvers)
1419 info->callbacks->einfo
1420 (_("%P: warning: GNU indirect functions with DT_TEXTREL "
1421 "may result in a segfault at runtime; recompile with %s\n"),
1422 bfd_link_dll (info) ? "-fPIC" : "-fPIE");
5e2ac45d
L
1423
1424 if (!add_dynamic_entry (DT_TEXTREL, 0))
1425 return FALSE;
1426 }
1427 }
90c14f0c 1428 if (htab->elf.target_os == is_vxworks
5e2ac45d
L
1429 && !elf_vxworks_add_dynamic_entries (output_bfd, info))
1430 return FALSE;
1431 }
1432#undef add_dynamic_entry
1433
1434 return TRUE;
1435}
1436
9577f60b
L
1437/* Finish up the x86 dynamic sections. */
1438
1439struct elf_x86_link_hash_table *
1440_bfd_x86_elf_finish_dynamic_sections (bfd *output_bfd,
1441 struct bfd_link_info *info)
1442{
1443 struct elf_x86_link_hash_table *htab;
1444 const struct elf_backend_data *bed;
1445 bfd *dynobj;
1446 asection *sdyn;
1447 bfd_byte *dyncon, *dynconend;
1448 bfd_size_type sizeof_dyn;
1449
1450 bed = get_elf_backend_data (output_bfd);
1451 htab = elf_x86_hash_table (info, bed->target_id);
1452 if (htab == NULL)
1453 return htab;
1454
1455 dynobj = htab->elf.dynobj;
1456 sdyn = bfd_get_linker_section (dynobj, ".dynamic");
1457
1458 /* GOT is always created in setup_gnu_properties. But it may not be
1459 needed. .got.plt section may be needed for static IFUNC. */
1460 if (htab->elf.sgotplt && htab->elf.sgotplt->size > 0)
1461 {
1462 bfd_vma dynamic_addr;
1463
1464 if (bfd_is_abs_section (htab->elf.sgotplt->output_section))
1465 {
1466 _bfd_error_handler
871b3ab2 1467 (_("discarded output section: `%pA'"), htab->elf.sgotplt);
9577f60b
L
1468 return NULL;
1469 }
1470
1471 elf_section_data (htab->elf.sgotplt->output_section)->this_hdr.sh_entsize
1472 = htab->got_entry_size;
1473
1474 dynamic_addr = (sdyn == NULL
1475 ? (bfd_vma) 0
1476 : sdyn->output_section->vma + sdyn->output_offset);
1477
1478 /* Set the first entry in the global offset table to the address
07d6d2b8 1479 of the dynamic section. Write GOT[1] and GOT[2], needed for
9577f60b
L
1480 the dynamic linker. */
1481 if (htab->got_entry_size == 8)
1482 {
1483 bfd_put_64 (output_bfd, dynamic_addr,
1484 htab->elf.sgotplt->contents);
1485 bfd_put_64 (output_bfd, (bfd_vma) 0,
1486 htab->elf.sgotplt->contents + 8);
1487 bfd_put_64 (output_bfd, (bfd_vma) 0,
1488 htab->elf.sgotplt->contents + 8*2);
1489 }
1490 else
1491 {
1492 bfd_put_32 (output_bfd, dynamic_addr,
1493 htab->elf.sgotplt->contents);
1494 bfd_put_32 (output_bfd, 0,
1495 htab->elf.sgotplt->contents + 4);
1496 bfd_put_32 (output_bfd, 0,
1497 htab->elf.sgotplt->contents + 4*2);
1498 }
1499 }
1500
1501 if (!htab->elf.dynamic_sections_created)
1502 return htab;
1503
1504 if (sdyn == NULL || htab->elf.sgot == NULL)
1505 abort ();
1506
1507 sizeof_dyn = bed->s->sizeof_dyn;
1508 dyncon = sdyn->contents;
1509 dynconend = sdyn->contents + sdyn->size;
1510 for (; dyncon < dynconend; dyncon += sizeof_dyn)
1511 {
1512 Elf_Internal_Dyn dyn;
1513 asection *s;
1514
1515 (*bed->s->swap_dyn_in) (dynobj, dyncon, &dyn);
1516
1517 switch (dyn.d_tag)
1518 {
1519 default:
90c14f0c 1520 if (htab->elf.target_os == is_vxworks
9577f60b
L
1521 && elf_vxworks_finish_dynamic_entry (output_bfd, &dyn))
1522 break;
1523 continue;
1524
1525 case DT_PLTGOT:
1526 s = htab->elf.sgotplt;
1527 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
1528 break;
1529
1530 case DT_JMPREL:
1531 dyn.d_un.d_ptr = htab->elf.srelplt->output_section->vma;
1532 break;
1533
1534 case DT_PLTRELSZ:
1535 s = htab->elf.srelplt->output_section;
1536 dyn.d_un.d_val = s->size;
1537 break;
1538
1539 case DT_TLSDESC_PLT:
1540 s = htab->elf.splt;
1541 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9bcc30e4 1542 + htab->elf.tlsdesc_plt;
9577f60b
L
1543 break;
1544
1545 case DT_TLSDESC_GOT:
1546 s = htab->elf.sgot;
1547 dyn.d_un.d_ptr = s->output_section->vma + s->output_offset
9bcc30e4 1548 + htab->elf.tlsdesc_got;
9577f60b
L
1549 break;
1550 }
1551
1552 (*bed->s->swap_dyn_out) (output_bfd, &dyn, dyncon);
1553 }
1554
1555 if (htab->plt_got != NULL && htab->plt_got->size > 0)
1556 elf_section_data (htab->plt_got->output_section)
1557 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
1558
1559 if (htab->plt_second != NULL && htab->plt_second->size > 0)
1560 elf_section_data (htab->plt_second->output_section)
1561 ->this_hdr.sh_entsize = htab->non_lazy_plt->plt_entry_size;
1562
1563 /* Adjust .eh_frame for .plt section. */
1564 if (htab->plt_eh_frame != NULL
1565 && htab->plt_eh_frame->contents != NULL)
1566 {
1567 if (htab->elf.splt != NULL
1568 && htab->elf.splt->size != 0
1569 && (htab->elf.splt->flags & SEC_EXCLUDE) == 0
1570 && htab->elf.splt->output_section != NULL
1571 && htab->plt_eh_frame->output_section != NULL)
1572 {
1573 bfd_vma plt_start = htab->elf.splt->output_section->vma;
1574 bfd_vma eh_frame_start = htab->plt_eh_frame->output_section->vma
1575 + htab->plt_eh_frame->output_offset
1576 + PLT_FDE_START_OFFSET;
1577 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
1578 htab->plt_eh_frame->contents
1579 + PLT_FDE_START_OFFSET);
1580 }
1581
1582 if (htab->plt_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
1583 {
1584 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
1585 htab->plt_eh_frame,
1586 htab->plt_eh_frame->contents))
1587 return NULL;
1588 }
1589 }
1590
1591 /* Adjust .eh_frame for .plt.got section. */
1592 if (htab->plt_got_eh_frame != NULL
1593 && htab->plt_got_eh_frame->contents != NULL)
1594 {
1595 if (htab->plt_got != NULL
1596 && htab->plt_got->size != 0
1597 && (htab->plt_got->flags & SEC_EXCLUDE) == 0
1598 && htab->plt_got->output_section != NULL
1599 && htab->plt_got_eh_frame->output_section != NULL)
1600 {
1601 bfd_vma plt_start = htab->plt_got->output_section->vma;
1602 bfd_vma eh_frame_start = htab->plt_got_eh_frame->output_section->vma
1603 + htab->plt_got_eh_frame->output_offset
1604 + PLT_FDE_START_OFFSET;
1605 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
1606 htab->plt_got_eh_frame->contents
1607 + PLT_FDE_START_OFFSET);
1608 }
1609 if (htab->plt_got_eh_frame->sec_info_type == SEC_INFO_TYPE_EH_FRAME)
1610 {
1611 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
1612 htab->plt_got_eh_frame,
1613 htab->plt_got_eh_frame->contents))
1614 return NULL;
1615 }
1616 }
1617
1618 /* Adjust .eh_frame for the second PLT section. */
1619 if (htab->plt_second_eh_frame != NULL
1620 && htab->plt_second_eh_frame->contents != NULL)
1621 {
1622 if (htab->plt_second != NULL
1623 && htab->plt_second->size != 0
1624 && (htab->plt_second->flags & SEC_EXCLUDE) == 0
1625 && htab->plt_second->output_section != NULL
1626 && htab->plt_second_eh_frame->output_section != NULL)
1627 {
1628 bfd_vma plt_start = htab->plt_second->output_section->vma;
1629 bfd_vma eh_frame_start
1630 = (htab->plt_second_eh_frame->output_section->vma
1631 + htab->plt_second_eh_frame->output_offset
1632 + PLT_FDE_START_OFFSET);
1633 bfd_put_signed_32 (dynobj, plt_start - eh_frame_start,
1634 htab->plt_second_eh_frame->contents
1635 + PLT_FDE_START_OFFSET);
1636 }
1637 if (htab->plt_second_eh_frame->sec_info_type
1638 == SEC_INFO_TYPE_EH_FRAME)
1639 {
1640 if (! _bfd_elf_write_section_eh_frame (output_bfd, info,
1641 htab->plt_second_eh_frame,
1642 htab->plt_second_eh_frame->contents))
1643 return NULL;
1644 }
1645 }
1646
1647 if (htab->elf.sgot && htab->elf.sgot->size > 0)
1648 elf_section_data (htab->elf.sgot->output_section)->this_hdr.sh_entsize
1649 = htab->got_entry_size;
1650
1651 return htab;
1652}
1653
1654
0afcef53
L
1655bfd_boolean
1656_bfd_x86_elf_always_size_sections (bfd *output_bfd,
1657 struct bfd_link_info *info)
1658{
1659 asection *tls_sec = elf_hash_table (info)->tls_sec;
1660
1661 if (tls_sec)
1662 {
1663 struct elf_link_hash_entry *tlsbase;
1664
1665 tlsbase = elf_link_hash_lookup (elf_hash_table (info),
1666 "_TLS_MODULE_BASE_",
1667 FALSE, FALSE, FALSE);
1668
1669 if (tlsbase && tlsbase->type == STT_TLS)
1670 {
1671 struct elf_x86_link_hash_table *htab;
1672 struct bfd_link_hash_entry *bh = NULL;
1673 const struct elf_backend_data *bed
1674 = get_elf_backend_data (output_bfd);
1675
1676 htab = elf_x86_hash_table (info, bed->target_id);
1677 if (htab == NULL)
1678 return FALSE;
1679
1680 if (!(_bfd_generic_link_add_one_symbol
1681 (info, output_bfd, "_TLS_MODULE_BASE_", BSF_LOCAL,
1682 tls_sec, 0, NULL, FALSE,
1683 bed->collect, &bh)))
1684 return FALSE;
1685
1686 htab->tls_module_base = bh;
1687
1688 tlsbase = (struct elf_link_hash_entry *)bh;
1689 tlsbase->def_regular = 1;
1690 tlsbase->other = STV_HIDDEN;
1691 tlsbase->root.linker_def = 1;
1692 (*bed->elf_backend_hide_symbol) (info, tlsbase, TRUE);
1693 }
1694 }
1695
1696 return TRUE;
1697}
1698
1699void
1700_bfd_x86_elf_merge_symbol_attribute (struct elf_link_hash_entry *h,
1701 const Elf_Internal_Sym *isym,
1702 bfd_boolean definition,
1703 bfd_boolean dynamic ATTRIBUTE_UNUSED)
1704{
1705 if (definition)
1706 {
1707 struct elf_x86_link_hash_entry *eh
1708 = (struct elf_x86_link_hash_entry *) h;
1709 eh->def_protected = (ELF_ST_VISIBILITY (isym->st_other)
1710 == STV_PROTECTED);
1711 }
1712}
1713
1714/* Copy the extra info we tack onto an elf_link_hash_entry. */
1715
1716void
1717_bfd_x86_elf_copy_indirect_symbol (struct bfd_link_info *info,
1718 struct elf_link_hash_entry *dir,
1719 struct elf_link_hash_entry *ind)
1720{
1721 struct elf_x86_link_hash_entry *edir, *eind;
1722
1723 edir = (struct elf_x86_link_hash_entry *) dir;
1724 eind = (struct elf_x86_link_hash_entry *) ind;
1725
0afcef53
L
1726 if (ind->root.type == bfd_link_hash_indirect
1727 && dir->got.refcount <= 0)
1728 {
1729 edir->tls_type = eind->tls_type;
1730 eind->tls_type = GOT_UNKNOWN;
1731 }
1732
1733 /* Copy gotoff_ref so that elf_i386_adjust_dynamic_symbol will
1734 generate a R_386_COPY reloc. */
1735 edir->gotoff_ref |= eind->gotoff_ref;
1736
98b273dc 1737 edir->zero_undefweak |= eind->zero_undefweak;
0afcef53
L
1738
1739 if (ELIMINATE_COPY_RELOCS
1740 && ind->root.type != bfd_link_hash_indirect
1741 && dir->dynamic_adjusted)
1742 {
1743 /* If called to transfer flags for a weakdef during processing
1744 of elf_adjust_dynamic_symbol, don't copy non_got_ref.
1745 We clear it ourselves for ELIMINATE_COPY_RELOCS. */
1746 if (dir->versioned != versioned_hidden)
1747 dir->ref_dynamic |= ind->ref_dynamic;
1748 dir->ref_regular |= ind->ref_regular;
1749 dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
1750 dir->needs_plt |= ind->needs_plt;
1751 dir->pointer_equality_needed |= ind->pointer_equality_needed;
1752 }
1753 else
79b0c981 1754 _bfd_elf_link_hash_copy_indirect (info, dir, ind);
0afcef53
L
1755}
1756
1757/* Remove undefined weak symbol from the dynamic symbol table if it
1758 is resolved to 0. */
1759
1760bfd_boolean
1761_bfd_x86_elf_fixup_symbol (struct bfd_link_info *info,
1762 struct elf_link_hash_entry *h)
1763{
c5bce5c6
L
1764 if (h->dynindx != -1
1765 && UNDEFINED_WEAK_RESOLVED_TO_ZERO (info, elf_x86_hash_entry (h)))
0afcef53 1766 {
c5bce5c6
L
1767 h->dynindx = -1;
1768 _bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
1769 h->dynstr_index);
0afcef53
L
1770 }
1771 return TRUE;
1772}
1773
4ec09950
L
1774/* Change the STT_GNU_IFUNC symbol defined in position-dependent
1775 executable into the normal function symbol and set its address
1776 to its PLT entry, which should be resolved by R_*_IRELATIVE at
1777 run-time. */
1778
1779void
1780_bfd_x86_elf_link_fixup_ifunc_symbol (struct bfd_link_info *info,
1781 struct elf_x86_link_hash_table *htab,
1782 struct elf_link_hash_entry *h,
1783 Elf_Internal_Sym *sym)
1784{
1785 if (bfd_link_pde (info)
1786 && h->def_regular
1787 && h->dynindx != -1
1788 && h->plt.offset != (bfd_vma) -1
1789 && h->type == STT_GNU_IFUNC
1790 && h->pointer_equality_needed)
1791 {
1792 asection *plt_s;
1793 bfd_vma plt_offset;
1794 bfd *output_bfd = info->output_bfd;
1795
1796 if (htab->plt_second)
1797 {
1798 struct elf_x86_link_hash_entry *eh
1799 = (struct elf_x86_link_hash_entry *) h;
1800
1801 plt_s = htab->plt_second;
1802 plt_offset = eh->plt_second.offset;
1803 }
1804 else
1805 {
1806 plt_s = htab->elf.splt;
1807 plt_offset = h->plt.offset;
1808 }
1809
1810 sym->st_size = 0;
1811 sym->st_info = ELF_ST_INFO (ELF_ST_BIND (sym->st_info), STT_FUNC);
1812 sym->st_shndx
1813 = _bfd_elf_section_from_bfd_section (output_bfd,
1814 plt_s->output_section);
1815 sym->st_value = (plt_s->output_section->vma
1816 + plt_s->output_offset + plt_offset);
1817 }
1818}
1819
0afcef53
L
1820/* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
1821
1822bfd_boolean
1823_bfd_x86_elf_hash_symbol (struct elf_link_hash_entry *h)
1824{
1825 if (h->plt.offset != (bfd_vma) -1
1826 && !h->def_regular
1827 && !h->pointer_equality_needed)
1828 return FALSE;
1829
1830 return _bfd_elf_hash_symbol (h);
1831}
1832
eeb2f20a
L
1833/* Adjust a symbol defined by a dynamic object and referenced by a
1834 regular object. The current definition is in some section of the
1835 dynamic object, but we're not including those sections. We have to
1836 change the definition to something the rest of the link can
1837 understand. */
1838
1839bfd_boolean
1840_bfd_x86_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
1841 struct elf_link_hash_entry *h)
1842{
1843 struct elf_x86_link_hash_table *htab;
1844 asection *s, *srel;
1845 struct elf_x86_link_hash_entry *eh;
1846 struct elf_dyn_relocs *p;
1847 const struct elf_backend_data *bed
1848 = get_elf_backend_data (info->output_bfd);
1849
1850 /* STT_GNU_IFUNC symbol must go through PLT. */
1851 if (h->type == STT_GNU_IFUNC)
1852 {
1853 /* All local STT_GNU_IFUNC references must be treate as local
1854 calls via local PLT. */
1855 if (h->ref_regular
1856 && SYMBOL_CALLS_LOCAL (info, h))
1857 {
1858 bfd_size_type pc_count = 0, count = 0;
1859 struct elf_dyn_relocs **pp;
1860
1861 eh = (struct elf_x86_link_hash_entry *) h;
190eb1dd 1862 for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
eeb2f20a
L
1863 {
1864 pc_count += p->pc_count;
1865 p->count -= p->pc_count;
1866 p->pc_count = 0;
1867 count += p->count;
1868 if (p->count == 0)
1869 *pp = p->next;
1870 else
1871 pp = &p->next;
1872 }
1873
1874 if (pc_count || count)
1875 {
1876 h->non_got_ref = 1;
1877 if (pc_count)
1878 {
1879 /* Increment PLT reference count only for PC-relative
1880 references. */
1881 h->needs_plt = 1;
1882 if (h->plt.refcount <= 0)
1883 h->plt.refcount = 1;
1884 else
1885 h->plt.refcount += 1;
1886 }
1887 }
1888 }
1889
1890 if (h->plt.refcount <= 0)
1891 {
1892 h->plt.offset = (bfd_vma) -1;
1893 h->needs_plt = 0;
1894 }
1895 return TRUE;
1896 }
1897
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
1902 || h->needs_plt)
1903 {
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))
1908 {
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;
1915 h->needs_plt = 0;
1916 }
1917
1918 return TRUE;
1919 }
1920 else
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;
1927
1928 eh = (struct elf_x86_link_hash_entry *) h;
1929
1930 /* If this is a weak symbol, and there is a real definition, the
1931 processor independent code will have arranged for us to see the
1932 real definition first, and we can just use the same value. */
60d67dc8 1933 if (h->is_weakalias)
eeb2f20a 1934 {
60d67dc8
AM
1935 struct elf_link_hash_entry *def = weakdef (h);
1936 BFD_ASSERT (def->root.type == bfd_link_hash_defined);
1937 h->root.u.def.section = def->root.u.def.section;
1938 h->root.u.def.value = def->root.u.def.value;
eeb2f20a
L
1939 if (ELIMINATE_COPY_RELOCS
1940 || info->nocopyreloc
1941 || SYMBOL_NO_COPYRELOC (info, eh))
1942 {
1943 /* NB: needs_copy is always 0 for i386. */
60d67dc8
AM
1944 h->non_got_ref = def->non_got_ref;
1945 eh->needs_copy = def->needs_copy;
eeb2f20a
L
1946 }
1947 return TRUE;
1948 }
1949
1950 /* This is a reference to a symbol defined by a dynamic object which
1951 is not a function. */
1952
1953 /* If we are creating a shared library, we must presume that the
1954 only references to the symbol are via the global offset table.
1955 For such cases we need not do anything here; the relocations will
1956 be handled correctly by relocate_section. */
1957 if (!bfd_link_executable (info))
1958 return TRUE;
1959
1960 /* If there are no references to this symbol that do not use the
1961 GOT nor R_386_GOTOFF relocation, we don't need to generate a copy
1962 reloc. NB: gotoff_ref is always 0 for x86-64. */
1963 if (!h->non_got_ref && !eh->gotoff_ref)
1964 return TRUE;
1965
1966 /* If -z nocopyreloc was given, we won't generate them either. */
1967 if (info->nocopyreloc || SYMBOL_NO_COPYRELOC (info, eh))
1968 {
1969 h->non_got_ref = 0;
1970 return TRUE;
1971 }
1972
1973 htab = elf_x86_hash_table (info, bed->target_id);
1974 if (htab == NULL)
1975 return FALSE;
1976
1977 /* If there aren't any dynamic relocs in read-only sections nor
1978 R_386_GOTOFF relocation, then we can keep the dynamic relocs and
1979 avoid the copy reloc. This doesn't work on VxWorks, where we can
1980 not have dynamic relocations (other than copy and jump slot
1981 relocations) in an executable. */
1982 if (ELIMINATE_COPY_RELOCS
1983 && (bed->target_id == X86_64_ELF_DATA
1984 || (!eh->gotoff_ref
90c14f0c 1985 && htab->elf.target_os != is_vxworks)))
eeb2f20a 1986 {
826c3f1e 1987 /* If we don't find any dynamic relocs in read-only sections,
eeb2f20a
L
1988 then we'll be keeping the dynamic relocs and avoiding the copy
1989 reloc. */
5dbc8b37 1990 if (!_bfd_elf_readonly_dynrelocs (h))
eeb2f20a
L
1991 {
1992 h->non_got_ref = 0;
1993 return TRUE;
1994 }
1995 }
1996
1997 /* We must allocate the symbol in our .dynbss section, which will
1998 become part of the .bss section of the executable. There will be
1999 an entry for this symbol in the .dynsym section. The dynamic
2000 object will contain position independent code, so all references
2001 from the dynamic object to this symbol will go through the global
2002 offset table. The dynamic linker will use the .dynsym entry to
2003 determine the address it must put in the global offset table, so
2004 both the dynamic object and the regular object will refer to the
2005 same memory location for the variable. */
2006
2007 /* We must generate a R_386_COPY/R_X86_64_COPY reloc to tell the
2008 dynamic linker to copy the initial value out of the dynamic object
2009 and into the runtime process image. */
2010 if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
2011 {
2012 s = htab->elf.sdynrelro;
2013 srel = htab->elf.sreldynrelro;
2014 }
2015 else
2016 {
2017 s = htab->elf.sdynbss;
2018 srel = htab->elf.srelbss;
2019 }
2020 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
2021 {
503294e7 2022 srel->size += htab->sizeof_reloc;
eeb2f20a
L
2023 h->needs_copy = 1;
2024 }
2025
2026 return _bfd_elf_adjust_dynamic_copy (info, h, s);
2027}
2028
9f857535
L
2029void
2030_bfd_x86_elf_hide_symbol (struct bfd_link_info *info,
2031 struct elf_link_hash_entry *h,
2032 bfd_boolean force_local)
2033{
2034 if (h->root.type == bfd_link_hash_undefweak
2035 && info->nointerp
2036 && bfd_link_pie (info))
2037 {
2038 /* When there is no dynamic interpreter in PIE, make the undefined
2039 weak symbol dynamic so that PC relative branch to the undefined
2040 weak symbol will land to address 0. */
2041 struct elf_x86_link_hash_entry *eh = elf_x86_hash_entry (h);
79b0c981 2042 if (h->plt.refcount > 0
9f857535
L
2043 || eh->plt_got.refcount > 0)
2044 return;
2045 }
2046
2047 _bfd_elf_link_hash_hide_symbol (info, h, force_local);
2048}
2049
6999821f
L
2050/* Return TRUE if a symbol is referenced locally. It is similar to
2051 SYMBOL_REFERENCES_LOCAL, but it also checks version script. It
2052 works in check_relocs. */
2053
2054bfd_boolean
2055_bfd_x86_elf_link_symbol_references_local (struct bfd_link_info *info,
2056 struct elf_link_hash_entry *h)
2057{
0a27fed7
L
2058 struct elf_x86_link_hash_entry *eh = elf_x86_hash_entry (h);
2059 struct elf_x86_link_hash_table *htab
2060 = (struct elf_x86_link_hash_table *) info->hash;
6999821f
L
2061
2062 if (eh->local_ref > 1)
2063 return TRUE;
2064
2065 if (eh->local_ref == 1)
2066 return FALSE;
2067
2068 /* Unversioned symbols defined in regular objects can be forced local
0a27fed7
L
2069 by linker version script. A weak undefined symbol is forced local
2070 if
2071 1. It has non-default visibility. Or
8fbf0ba1 2072 2. When building executable, there is no dynamic linker. Or
0a27fed7
L
2073 3. or "-z nodynamic-undefined-weak" is used.
2074 */
6999821f 2075 if (SYMBOL_REFERENCES_LOCAL (info, h)
0a27fed7
L
2076 || (h->root.type == bfd_link_hash_undefweak
2077 && (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2078 || (bfd_link_executable (info)
8fbf0ba1 2079 && htab->interp == NULL)
0a27fed7 2080 || info->dynamic_undefined_weak == 0))
6999821f 2081 || ((h->def_regular || ELF_COMMON_DEF_P (h))
6999821f 2082 && info->version_info != NULL
099bb8fb 2083 && _bfd_elf_link_hide_sym_by_version (info, h)))
6999821f
L
2084 {
2085 eh->local_ref = 2;
2086 return TRUE;
2087 }
2088
099bb8fb 2089 eh->local_ref = 1;
6999821f
L
2090 return FALSE;
2091}
2092
4f501a24
L
2093/* Return the section that should be marked against GC for a given
2094 relocation. */
2095
2096asection *
2097_bfd_x86_elf_gc_mark_hook (asection *sec,
2098 struct bfd_link_info *info,
2099 Elf_Internal_Rela *rel,
2100 struct elf_link_hash_entry *h,
2101 Elf_Internal_Sym *sym)
2102{
2103 /* Compiler should optimize this out. */
2104 if (((unsigned int) R_X86_64_GNU_VTINHERIT
2105 != (unsigned int) R_386_GNU_VTINHERIT)
2106 || ((unsigned int) R_X86_64_GNU_VTENTRY
2107 != (unsigned int) R_386_GNU_VTENTRY))
2108 abort ();
2109
2110 if (h != NULL)
2111 switch (ELF32_R_TYPE (rel->r_info))
2112 {
2113 case R_X86_64_GNU_VTINHERIT:
2114 case R_X86_64_GNU_VTENTRY:
2115 return NULL;
2116 }
2117
2118 return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2119}
2120
f493882d
L
2121static bfd_vma
2122elf_i386_get_plt_got_vma (struct elf_x86_plt *plt_p ATTRIBUTE_UNUSED,
2123 bfd_vma off,
2124 bfd_vma offset ATTRIBUTE_UNUSED,
2125 bfd_vma got_addr)
2126{
2127 return got_addr + off;
2128}
2129
2130static bfd_vma
2131elf_x86_64_get_plt_got_vma (struct elf_x86_plt *plt_p,
2132 bfd_vma off,
2133 bfd_vma offset,
2134 bfd_vma got_addr ATTRIBUTE_UNUSED)
2135{
2136 return plt_p->sec->vma + offset + off + plt_p->plt_got_insn_size;
2137}
2138
2139static bfd_boolean
2140elf_i386_valid_plt_reloc_p (unsigned int type)
2141{
2142 return (type == R_386_JUMP_SLOT
2143 || type == R_386_GLOB_DAT
2144 || type == R_386_IRELATIVE);
2145}
2146
2147static bfd_boolean
2148elf_x86_64_valid_plt_reloc_p (unsigned int type)
2149{
2150 return (type == R_X86_64_JUMP_SLOT
2151 || type == R_X86_64_GLOB_DAT
2152 || type == R_X86_64_IRELATIVE);
2153}
2154
2155long
2156_bfd_x86_elf_get_synthetic_symtab (bfd *abfd,
2157 long count,
2158 long relsize,
2159 bfd_vma got_addr,
2160 struct elf_x86_plt plts[],
2161 asymbol **dynsyms,
2162 asymbol **ret)
2163{
2164 long size, i, n, len;
2165 int j;
2166 unsigned int plt_got_offset, plt_entry_size;
2167 asymbol *s;
2168 bfd_byte *plt_contents;
2169 long dynrelcount;
2170 arelent **dynrelbuf, *p;
2171 char *names;
2172 const struct elf_backend_data *bed;
2173 bfd_vma (*get_plt_got_vma) (struct elf_x86_plt *, bfd_vma, bfd_vma,
2174 bfd_vma);
2175 bfd_boolean (*valid_plt_reloc_p) (unsigned int);
2176
2600d80c 2177 dynrelbuf = NULL;
f493882d 2178 if (count == 0)
2600d80c 2179 goto bad_return;
f493882d
L
2180
2181 dynrelbuf = (arelent **) bfd_malloc (relsize);
2182 if (dynrelbuf == NULL)
2600d80c 2183 goto bad_return;
f493882d
L
2184
2185 dynrelcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf,
2186 dynsyms);
b69e9267 2187 if (dynrelcount <= 0)
2600d80c 2188 goto bad_return;
f493882d
L
2189
2190 /* Sort the relocs by address. */
2191 qsort (dynrelbuf, dynrelcount, sizeof (arelent *),
2192 _bfd_x86_elf_compare_relocs);
2193
2194 size = count * sizeof (asymbol);
2195
2196 /* Allocate space for @plt suffixes. */
2197 n = 0;
2198 for (i = 0; i < dynrelcount; i++)
2199 {
2200 p = dynrelbuf[i];
2201 size += strlen ((*p->sym_ptr_ptr)->name) + sizeof ("@plt");
2202 if (p->addend != 0)
2203 size += sizeof ("+0x") - 1 + 8 + 8 * ABI_64_P (abfd);
2204 }
2205
2206 s = *ret = (asymbol *) bfd_zmalloc (size);
2207 if (s == NULL)
2208 goto bad_return;
2209
2210 bed = get_elf_backend_data (abfd);
2211
2212 if (bed->target_id == X86_64_ELF_DATA)
2213 {
2214 get_plt_got_vma = elf_x86_64_get_plt_got_vma;
2215 valid_plt_reloc_p = elf_x86_64_valid_plt_reloc_p;
2216 }
2217 else
2218 {
2219 get_plt_got_vma = elf_i386_get_plt_got_vma;
2220 valid_plt_reloc_p = elf_i386_valid_plt_reloc_p;
2221 if (got_addr)
2222 {
2223 /* Check .got.plt and then .got to get the _GLOBAL_OFFSET_TABLE_
2224 address. */
2225 asection *sec = bfd_get_section_by_name (abfd, ".got.plt");
2226 if (sec != NULL)
2227 got_addr = sec->vma;
2228 else
2229 {
2230 sec = bfd_get_section_by_name (abfd, ".got");
2231 if (sec != NULL)
2232 got_addr = sec->vma;
2233 }
2234
2235 if (got_addr == (bfd_vma) -1)
2236 goto bad_return;
2237 }
2238 }
2239
2240 /* Check for each PLT section. */
2241 names = (char *) (s + count);
2242 size = 0;
2243 n = 0;
2244 for (j = 0; plts[j].name != NULL; j++)
2245 if ((plt_contents = plts[j].contents) != NULL)
2246 {
2247 long k;
2248 bfd_vma offset;
2249 asection *plt;
2250 struct elf_x86_plt *plt_p = &plts[j];
2251
2252 plt_got_offset = plt_p->plt_got_offset;
2253 plt_entry_size = plt_p->plt_entry_size;
2254
2255 plt = plt_p->sec;
2256
2257 if ((plt_p->type & plt_lazy))
2258 {
2259 /* Skip PLT0 in lazy PLT. */
2260 k = 1;
2261 offset = plt_entry_size;
2262 }
2263 else
2264 {
2265 k = 0;
2266 offset = 0;
2267 }
2268
2269 /* Check each PLT entry against dynamic relocations. */
2270 for (; k < plt_p->count; k++)
2271 {
2272 int off;
2273 bfd_vma got_vma;
2274 long min, max, mid;
2275
2276 /* Get the GOT offset for i386 or the PC-relative offset
2277 for x86-64, a signed 32-bit integer. */
2278 off = H_GET_32 (abfd, (plt_contents + offset
2279 + plt_got_offset));
2280 got_vma = get_plt_got_vma (plt_p, off, offset, got_addr);
2281
2282 /* Binary search. */
2283 p = dynrelbuf[0];
2284 min = 0;
2285 max = dynrelcount;
2286 while ((min + 1) < max)
2287 {
2288 arelent *r;
2289
2290 mid = (min + max) / 2;
2291 r = dynrelbuf[mid];
2292 if (got_vma > r->address)
2293 min = mid;
2294 else if (got_vma < r->address)
2295 max = mid;
2296 else
2297 {
2298 p = r;
2299 break;
2300 }
2301 }
2302
2303 /* Skip unknown relocation. PR 17512: file: bc9d6cf5. */
2304 if (got_vma == p->address
2305 && p->howto != NULL
2306 && valid_plt_reloc_p (p->howto->type))
2307 {
2308 *s = **p->sym_ptr_ptr;
2309 /* Undefined syms won't have BSF_LOCAL or BSF_GLOBAL
2310 set. Since we are defining a symbol, ensure one
2311 of them is set. */
2312 if ((s->flags & BSF_LOCAL) == 0)
2313 s->flags |= BSF_GLOBAL;
2314 s->flags |= BSF_SYNTHETIC;
2315 /* This is no longer a section symbol. */
2316 s->flags &= ~BSF_SECTION_SYM;
2317 s->section = plt;
2318 s->the_bfd = plt->owner;
2319 s->value = offset;
2320 s->udata.p = NULL;
2321 s->name = names;
2322 len = strlen ((*p->sym_ptr_ptr)->name);
2323 memcpy (names, (*p->sym_ptr_ptr)->name, len);
2324 names += len;
2325 if (p->addend != 0)
2326 {
2327 char buf[30], *a;
2328
2329 memcpy (names, "+0x", sizeof ("+0x") - 1);
2330 names += sizeof ("+0x") - 1;
2331 bfd_sprintf_vma (abfd, buf, p->addend);
2332 for (a = buf; *a == '0'; ++a)
2333 ;
2334 size = strlen (a);
2335 memcpy (names, a, size);
2336 names += size;
2337 }
2338 memcpy (names, "@plt", sizeof ("@plt"));
2339 names += sizeof ("@plt");
2340 n++;
2341 s++;
61e3bf5f
L
2342 /* There should be only one entry in PLT for a given
2343 symbol. Set howto to NULL after processing a PLT
2344 entry to guard against corrupted PLT. */
2345 p->howto = NULL;
f493882d
L
2346 }
2347 offset += plt_entry_size;
2348 }
2349 }
2350
2351 /* PLT entries with R_386_TLS_DESC relocations are skipped. */
2352 if (n == 0)
2353 {
dc1e8a47 2354 bad_return:
f493882d
L
2355 count = -1;
2356 }
2357 else
2358 count = n;
2359
2360 for (j = 0; plts[j].name != NULL; j++)
c9594989 2361 free (plts[j].contents);
f493882d
L
2362
2363 free (dynrelbuf);
2364
2365 return count;
2366}
2367
0afcef53
L
2368/* Parse x86 GNU properties. */
2369
2370enum elf_property_kind
2371_bfd_x86_elf_parse_gnu_properties (bfd *abfd, unsigned int type,
2372 bfd_byte *ptr, unsigned int datasz)
2373{
2374 elf_property *prop;
2375
a9eafb08
L
2376 if (type == GNU_PROPERTY_X86_COMPAT_ISA_1_USED
2377 || type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
2378 || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
2379 && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
2380 || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
2381 && type <= GNU_PROPERTY_X86_UINT32_OR_HI)
2382 || (type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
2383 && type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
0afcef53 2384 {
0afcef53
L
2385 if (datasz != 4)
2386 {
2387 _bfd_error_handler
a9eafb08
L
2388 (_("error: %pB: <corrupt x86 property (0x%x) size: 0x%x>"),
2389 abfd, type, datasz);
0afcef53
L
2390 return property_corrupt;
2391 }
2392 prop = _bfd_elf_get_property (abfd, type, datasz);
90c745dc 2393 prop->u.number |= bfd_h_get_32 (abfd, ptr);
0afcef53 2394 prop->pr_kind = property_number;
a9eafb08 2395 return property_number;
0afcef53
L
2396 }
2397
a9eafb08 2398 return property_ignored;
0afcef53
L
2399}
2400
2401/* Merge x86 GNU property BPROP with APROP. If APROP isn't NULL,
2402 return TRUE if APROP is updated. Otherwise, return TRUE if BPROP
2403 should be merged with ABFD. */
2404
2405bfd_boolean
2406_bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
2407 bfd *abfd ATTRIBUTE_UNUSED,
4e539114 2408 bfd *bbfd ATTRIBUTE_UNUSED,
0afcef53
L
2409 elf_property *aprop,
2410 elf_property *bprop)
2411{
2412 unsigned int number, features;
2413 bfd_boolean updated = FALSE;
2414 unsigned int pr_type = aprop != NULL ? aprop->pr_type : bprop->pr_type;
2415
a9eafb08
L
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))
0afcef53 2419 {
f7309df2
L
2420 if (aprop == NULL || bprop == NULL)
2421 {
2422 /* Only one of APROP and BPROP can be NULL. */
2423 if (aprop != NULL)
2424 {
2425 /* Remove this property since the other input file doesn't
2426 have it. */
2427 aprop->pr_kind = property_remove;
2428 updated = TRUE;
2429 }
f7309df2 2430 }
fde51dd1
L
2431 else
2432 {
2433 number = aprop->u.number;
2434 aprop->u.number = number | bprop->u.number;
2435 updated = number != (unsigned int) aprop->u.number;
2436 }
2437 return updated;
a9eafb08
L
2438 }
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))
2442 {
0afcef53
L
2443 if (aprop != NULL && bprop != NULL)
2444 {
2445 number = aprop->u.number;
2446 aprop->u.number = number | bprop->u.number;
f7309df2 2447 /* Remove the property if all bits are empty. */
56ad703d
L
2448 if (aprop->u.number == 0)
2449 {
2450 aprop->pr_kind = property_remove;
2451 updated = TRUE;
2452 }
2453 else
2454 updated = number != (unsigned int) aprop->u.number;
0afcef53
L
2455 }
2456 else
2457 {
56ad703d
L
2458 /* Only one of APROP and BPROP can be NULL. */
2459 if (aprop != NULL)
2460 {
2461 if (aprop->u.number == 0)
2462 {
f7309df2 2463 /* Remove APROP if all bits are empty. */
56ad703d
L
2464 aprop->pr_kind = property_remove;
2465 updated = TRUE;
2466 }
2467 }
2468 else
2469 {
f7309df2 2470 /* Return TRUE if APROP is NULL and all bits of BPROP
56ad703d
L
2471 aren't empty to indicate that BPROP should be added
2472 to ABFD. */
2473 updated = bprop->u.number != 0;
2474 }
0afcef53 2475 }
a9eafb08
L
2476 return updated;
2477 }
2478 else if (pr_type >= GNU_PROPERTY_X86_UINT32_AND_LO
2479 && pr_type <= GNU_PROPERTY_X86_UINT32_AND_HI)
2480 {
0afcef53
L
2481 /* Only one of APROP and BPROP can be NULL:
2482 1. APROP & BPROP when both APROP and BPROP aren't NULL.
2483 2. If APROP is NULL, remove x86 feature.
2484 3. Otherwise, do nothing.
2485 */
5b9c07b2
L
2486 const struct elf_backend_data *bed
2487 = get_elf_backend_data (info->output_bfd);
2488 struct elf_x86_link_hash_table *htab
2489 = elf_x86_hash_table (info, bed->target_id);
2490 if (!htab)
2491 abort ();
0afcef53
L
2492 if (aprop != NULL && bprop != NULL)
2493 {
2494 features = 0;
5b9c07b2 2495 if (htab->params->ibt)
0afcef53 2496 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
5b9c07b2 2497 if (htab->params->shstk)
0afcef53
L
2498 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
2499 number = aprop->u.number;
2500 /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
2501 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
2502 aprop->u.number = (number & bprop->u.number) | features;
2503 updated = number != (unsigned int) aprop->u.number;
2504 /* Remove the property if all feature bits are cleared. */
2505 if (aprop->u.number == 0)
2506 aprop->pr_kind = property_remove;
2507 }
2508 else
2509 {
44b27f95
L
2510 /* There should be no AND properties since some input doesn't
2511 have them. Set IBT and SHSTK properties for -z ibt and -z
2512 shstk if needed. */
0afcef53 2513 features = 0;
5b9c07b2 2514 if (htab->params->ibt)
0afcef53 2515 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
5b9c07b2 2516 if (htab->params->shstk)
0afcef53
L
2517 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
2518 if (features)
2519 {
0afcef53
L
2520 if (aprop != NULL)
2521 {
44b27f95
L
2522 updated = features != (unsigned int) aprop->u.number;
2523 aprop->u.number = features;
0afcef53
L
2524 }
2525 else
2526 {
0afcef53 2527 updated = TRUE;
44b27f95 2528 bprop->u.number = features;
0afcef53
L
2529 }
2530 }
2531 else if (aprop != NULL)
2532 {
2533 aprop->pr_kind = property_remove;
2534 updated = TRUE;
2535 }
2536 }
a9eafb08
L
2537 return updated;
2538 }
2539 else
2540 {
0afcef53
L
2541 /* Never should happen. */
2542 abort ();
2543 }
2544
2545 return updated;
2546}
a6798bab
L
2547
2548/* Set up x86 GNU properties. Return the first relocatable ELF input
2549 with GNU properties if found. Otherwise, return NULL. */
2550
2551bfd *
2552_bfd_x86_elf_link_setup_gnu_properties
1de031c8 2553 (struct bfd_link_info *info, struct elf_x86_init_table *init_table)
a6798bab
L
2554{
2555 bfd_boolean normal_target;
2556 bfd_boolean lazy_plt;
2557 asection *sec, *pltsec;
2558 bfd *dynobj;
2559 bfd_boolean use_ibt_plt;
2560 unsigned int plt_alignment, features;
2561 struct elf_x86_link_hash_table *htab;
2562 bfd *pbfd;
2563 bfd *ebfd = NULL;
2564 elf_property *prop;
2565 const struct elf_backend_data *bed;
2566 unsigned int class_align = ABI_64_P (info->output_bfd) ? 3 : 2;
2567 unsigned int got_align;
2568
a6798bab
L
2569 /* Find a normal input file with GNU property note. */
2570 for (pbfd = info->input_bfds;
2571 pbfd != NULL;
2572 pbfd = pbfd->link.next)
2573 if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
2574 && bfd_count_sections (pbfd) != 0)
2575 {
2576 ebfd = pbfd;
2577
2578 if (elf_properties (pbfd) != NULL)
2579 break;
2580 }
2581
241e64e3
L
2582 bed = get_elf_backend_data (info->output_bfd);
2583
2584 htab = elf_x86_hash_table (info, bed->target_id);
2585 if (htab == NULL)
2586 return pbfd;
2587
5b9c07b2
L
2588 features = 0;
2589 if (htab->params->ibt)
233a0083
L
2590 {
2591 features = GNU_PROPERTY_X86_FEATURE_1_IBT;
2592 htab->params->cet_report &= ~cet_report_ibt;
2593 }
5b9c07b2 2594 if (htab->params->shstk)
233a0083
L
2595 {
2596 features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
2597 htab->params->cet_report &= ~cet_report_shstk;
2598 }
2599 if (!(htab->params->cet_report & (cet_report_ibt | cet_report_shstk)))
2600 htab->params->cet_report = cet_report_none;
5b9c07b2 2601
241e64e3 2602 if (ebfd != NULL)
a6798bab 2603 {
241e64e3
L
2604 prop = NULL;
2605 if (features)
2606 {
2607 /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
2608 GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
2609 prop = _bfd_elf_get_property (ebfd,
2610 GNU_PROPERTY_X86_FEATURE_1_AND,
2611 4);
2612 prop->u.number |= features;
2613 prop->pr_kind = property_number;
2614 }
a6798bab
L
2615
2616 /* Create the GNU property note section if needed. */
241e64e3 2617 if (prop != NULL && pbfd == NULL)
a6798bab
L
2618 {
2619 sec = bfd_make_section_with_flags (ebfd,
2620 NOTE_GNU_PROPERTY_SECTION_NAME,
2621 (SEC_ALLOC
2622 | SEC_LOAD
2623 | SEC_IN_MEMORY
2624 | SEC_READONLY
2625 | SEC_HAS_CONTENTS
2626 | SEC_DATA));
2627 if (sec == NULL)
2c244f9b 2628 info->callbacks->einfo (_("%F%P: failed to create GNU property section\n"));
a6798bab 2629
fd361982 2630 if (!bfd_set_section_alignment (sec, class_align))
a6798bab 2631 {
dc1e8a47 2632 error_alignment:
871b3ab2 2633 info->callbacks->einfo (_("%F%pA: failed to align section\n"),
a6798bab
L
2634 sec);
2635 }
2636
2637 elf_section_type (sec) = SHT_NOTE;
2638 }
2639 }
2640
233a0083
L
2641 if (htab->params->cet_report)
2642 {
2643 /* Report missing IBT and SHSTK properties. */
2644 bfd *abfd;
2645 const char *msg;
2646 elf_property_list *p;
2647 bfd_boolean missing_ibt, missing_shstk;
2648 bfd_boolean check_ibt
2649 = !!(htab->params->cet_report & cet_report_ibt);
2650 bfd_boolean check_shstk
2651 = !!(htab->params->cet_report & cet_report_shstk);
2652
2653 if ((htab->params->cet_report & cet_report_warning))
2654 msg = _("%P: %pB: warning: missing %s\n");
2655 else
2656 msg = _("%X%P: %pB: error: missing %s\n");
2657
2658 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
2659 if (!(abfd->flags & (DYNAMIC | BFD_PLUGIN | BFD_LINKER_CREATED))
2660 && bfd_get_flavour (abfd) == bfd_target_elf_flavour)
2661 {
2662 for (p = elf_properties (abfd); p; p = p->next)
2663 if (p->property.pr_type == GNU_PROPERTY_X86_FEATURE_1_AND)
2664 break;
2665
2666 missing_ibt = check_ibt;
2667 missing_shstk = check_shstk;
2668 if (p)
2669 {
2670 missing_ibt &= !(p->property.u.number
2671 & GNU_PROPERTY_X86_FEATURE_1_IBT);
2672 missing_shstk &= !(p->property.u.number
2673 & GNU_PROPERTY_X86_FEATURE_1_SHSTK);
2674 }
2675 if (missing_ibt || missing_shstk)
2676 {
2677 const char *missing;
2678 if (missing_ibt && missing_shstk)
2679 missing = _("IBT and SHSTK properties");
2680 else if (missing_ibt)
2681 missing = _("IBT property");
2682 else
2683 missing = _("SHSTK property");
2684 info->callbacks->einfo (msg, abfd, missing);
2685 }
2686 }
2687 }
2688
a6798bab
L
2689 pbfd = _bfd_elf_link_setup_gnu_properties (info);
2690
1de031c8
L
2691 htab->r_info = init_table->r_info;
2692 htab->r_sym = init_table->r_sym;
7a382c1c
L
2693
2694 if (bfd_link_relocatable (info))
2695 return pbfd;
eeb2f20a 2696
851b6fa1
L
2697 htab->plt0_pad_byte = init_table->plt0_pad_byte;
2698
5b9c07b2 2699 use_ibt_plt = htab->params->ibtplt || htab->params->ibt;
a6798bab
L
2700 if (!use_ibt_plt && pbfd != NULL)
2701 {
2702 /* Check if GNU_PROPERTY_X86_FEATURE_1_IBT is on. */
2703 elf_property_list *p;
2704
2705 /* The property list is sorted in order of type. */
2706 for (p = elf_properties (pbfd); p; p = p->next)
2707 {
2708 if (GNU_PROPERTY_X86_FEATURE_1_AND == p->property.pr_type)
2709 {
2710 use_ibt_plt = !!(p->property.u.number
2711 & GNU_PROPERTY_X86_FEATURE_1_IBT);
2712 break;
2713 }
2714 else if (GNU_PROPERTY_X86_FEATURE_1_AND < p->property.pr_type)
2715 break;
2716 }
2717 }
2718
2719 dynobj = htab->elf.dynobj;
2720
2721 /* Set htab->elf.dynobj here so that there is no need to check and
2722 set it in check_relocs. */
2723 if (dynobj == NULL)
2724 {
2725 if (pbfd != NULL)
2726 {
2727 htab->elf.dynobj = pbfd;
2728 dynobj = pbfd;
2729 }
2730 else
2731 {
2732 bfd *abfd;
2733
2734 /* Find a normal input file to hold linker created
2735 sections. */
2736 for (abfd = info->input_bfds;
2737 abfd != NULL;
2738 abfd = abfd->link.next)
2739 if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
2740 && (abfd->flags
e4e6a73d
L
2741 & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0
2742 && bed->relocs_compatible (abfd->xvec,
2743 info->output_bfd->xvec))
a6798bab
L
2744 {
2745 htab->elf.dynobj = abfd;
2746 dynobj = abfd;
2747 break;
2748 }
2749 }
2750 }
2751
851b6fa1
L
2752 /* Return if there are no normal input files. */
2753 if (dynobj == NULL)
2754 return pbfd;
2755
a6798bab
L
2756 /* Even when lazy binding is disabled by "-z now", the PLT0 entry may
2757 still be used with LD_AUDIT or LD_PROFILE if PLT entry is used for
2758 canonical function address. */
2759 htab->plt.has_plt0 = 1;
90c14f0c 2760 normal_target = htab->elf.target_os == is_normal;
a6798bab
L
2761
2762 if (normal_target)
2763 {
2764 if (use_ibt_plt)
2765 {
1de031c8
L
2766 htab->lazy_plt = init_table->lazy_ibt_plt;
2767 htab->non_lazy_plt = init_table->non_lazy_ibt_plt;
a6798bab
L
2768 }
2769 else
2770 {
1de031c8
L
2771 htab->lazy_plt = init_table->lazy_plt;
2772 htab->non_lazy_plt = init_table->non_lazy_plt;
a6798bab
L
2773 }
2774 }
2775 else
2776 {
1de031c8 2777 htab->lazy_plt = init_table->lazy_plt;
a6798bab
L
2778 htab->non_lazy_plt = NULL;
2779 }
2780
2781 pltsec = htab->elf.splt;
2782
2783 /* If the non-lazy PLT is available, use it for all PLT entries if
2784 there are no PLT0 or no .plt section. */
2785 if (htab->non_lazy_plt != NULL
2786 && (!htab->plt.has_plt0 || pltsec == NULL))
2787 {
2788 lazy_plt = FALSE;
2789 if (bfd_link_pic (info))
2790 htab->plt.plt_entry = htab->non_lazy_plt->pic_plt_entry;
2791 else
2792 htab->plt.plt_entry = htab->non_lazy_plt->plt_entry;
2793 htab->plt.plt_entry_size = htab->non_lazy_plt->plt_entry_size;
2794 htab->plt.plt_got_offset = htab->non_lazy_plt->plt_got_offset;
2795 htab->plt.plt_got_insn_size
2796 = htab->non_lazy_plt->plt_got_insn_size;
2797 htab->plt.eh_frame_plt_size
2798 = htab->non_lazy_plt->eh_frame_plt_size;
2799 htab->plt.eh_frame_plt = htab->non_lazy_plt->eh_frame_plt;
2800 }
2801 else
2802 {
2803 lazy_plt = TRUE;
2804 if (bfd_link_pic (info))
2805 {
2806 htab->plt.plt0_entry = htab->lazy_plt->pic_plt0_entry;
2807 htab->plt.plt_entry = htab->lazy_plt->pic_plt_entry;
2808 }
2809 else
2810 {
2811 htab->plt.plt0_entry = htab->lazy_plt->plt0_entry;
2812 htab->plt.plt_entry = htab->lazy_plt->plt_entry;
2813 }
2814 htab->plt.plt_entry_size = htab->lazy_plt->plt_entry_size;
2815 htab->plt.plt_got_offset = htab->lazy_plt->plt_got_offset;
2816 htab->plt.plt_got_insn_size
2817 = htab->lazy_plt->plt_got_insn_size;
2818 htab->plt.eh_frame_plt_size
2819 = htab->lazy_plt->eh_frame_plt_size;
2820 htab->plt.eh_frame_plt = htab->lazy_plt->eh_frame_plt;
2821 }
2822
90c14f0c 2823 if (htab->elf.target_os == is_vxworks
a6798bab
L
2824 && !elf_vxworks_create_dynamic_sections (dynobj, info,
2825 &htab->srelplt2))
2826 {
2c244f9b 2827 info->callbacks->einfo (_("%F%P: failed to create VxWorks dynamic sections\n"));
a6798bab
L
2828 return pbfd;
2829 }
2830
2831 /* Since create_dynamic_sections isn't always called, but GOT
2832 relocations need GOT relocations, create them here so that we
2833 don't need to do it in check_relocs. */
2834 if (htab->elf.sgot == NULL
2835 && !_bfd_elf_create_got_section (dynobj, info))
2c244f9b 2836 info->callbacks->einfo (_("%F%P: failed to create GOT sections\n"));
a6798bab
L
2837
2838 got_align = (bed->target_id == X86_64_ELF_DATA) ? 3 : 2;
2839
2840 /* Align .got and .got.plt sections to their entry size. Do it here
2841 instead of in create_dynamic_sections so that they are always
2842 properly aligned even if create_dynamic_sections isn't called. */
2843 sec = htab->elf.sgot;
fd361982 2844 if (!bfd_set_section_alignment (sec, got_align))
a6798bab
L
2845 goto error_alignment;
2846
2847 sec = htab->elf.sgotplt;
fd361982 2848 if (!bfd_set_section_alignment (sec, got_align))
a6798bab
L
2849 goto error_alignment;
2850
2851 /* Create the ifunc sections here so that check_relocs can be
2852 simplified. */
2853 if (!_bfd_elf_create_ifunc_sections (dynobj, info))
2c244f9b 2854 info->callbacks->einfo (_("%F%P: failed to create ifunc sections\n"));
a6798bab
L
2855
2856 plt_alignment = bfd_log2 (htab->plt.plt_entry_size);
2857
2858 if (pltsec != NULL)
2859 {
2860 /* Whe creating executable, set the contents of the .interp
2861 section to the interpreter. */
2862 if (bfd_link_executable (info) && !info->nointerp)
2863 {
2864 asection *s = bfd_get_linker_section (dynobj, ".interp");
2865 if (s == NULL)
2866 abort ();
2867 s->size = htab->dynamic_interpreter_size;
2868 s->contents = (unsigned char *) htab->dynamic_interpreter;
2869 htab->interp = s;
2870 }
2871
2872 /* Don't change PLT section alignment for NaCl since it uses
2873 64-byte PLT entry and sets PLT section alignment to 32
2874 bytes. Don't create additional PLT sections for NaCl. */
2875 if (normal_target)
2876 {
2877 flagword pltflags = (bed->dynamic_sec_flags
2878 | SEC_ALLOC
2879 | SEC_CODE
2880 | SEC_LOAD
2881 | SEC_READONLY);
2882 unsigned int non_lazy_plt_alignment
2883 = bfd_log2 (htab->non_lazy_plt->plt_entry_size);
2884
2885 sec = pltsec;
fd361982 2886 if (!bfd_set_section_alignment (sec, plt_alignment))
a6798bab
L
2887 goto error_alignment;
2888
2889 /* Create the GOT procedure linkage table. */
2890 sec = bfd_make_section_anyway_with_flags (dynobj,
2891 ".plt.got",
2892 pltflags);
2893 if (sec == NULL)
2c244f9b 2894 info->callbacks->einfo (_("%F%P: failed to create GOT PLT section\n"));
a6798bab 2895
fd361982 2896 if (!bfd_set_section_alignment (sec, non_lazy_plt_alignment))
a6798bab
L
2897 goto error_alignment;
2898
2899 htab->plt_got = sec;
2900
2901 if (lazy_plt)
2902 {
2903 sec = NULL;
2904
2905 if (use_ibt_plt)
2906 {
2907 /* Create the second PLT for Intel IBT support. IBT
2908 PLT is supported only for non-NaCl target and is
2909 is needed only for lazy binding. */
2910 sec = bfd_make_section_anyway_with_flags (dynobj,
2911 ".plt.sec",
2912 pltflags);
2913 if (sec == NULL)
2c244f9b 2914 info->callbacks->einfo (_("%F%P: failed to create IBT-enabled PLT section\n"));
a6798bab 2915
fd361982 2916 if (!bfd_set_section_alignment (sec, plt_alignment))
a6798bab
L
2917 goto error_alignment;
2918 }
5b9c07b2 2919 else if (htab->params->bndplt && ABI_64_P (dynobj))
a6798bab
L
2920 {
2921 /* Create the second PLT for Intel MPX support. MPX
2922 PLT is supported only for non-NaCl target in 64-bit
2923 mode and is needed only for lazy binding. */
2924 sec = bfd_make_section_anyway_with_flags (dynobj,
2925 ".plt.sec",
2926 pltflags);
2927 if (sec == NULL)
2c244f9b 2928 info->callbacks->einfo (_("%F%P: failed to create BND PLT section\n"));
a6798bab 2929
fd361982 2930 if (!bfd_set_section_alignment (sec, non_lazy_plt_alignment))
a6798bab
L
2931 goto error_alignment;
2932 }
2933
2934 htab->plt_second = sec;
2935 }
2936 }
2937
2938 if (!info->no_ld_generated_unwind_info)
2939 {
2940 flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_READONLY
2941 | SEC_HAS_CONTENTS | SEC_IN_MEMORY
2942 | SEC_LINKER_CREATED);
2943
2944 sec = bfd_make_section_anyway_with_flags (dynobj,
2945 ".eh_frame",
2946 flags);
2947 if (sec == NULL)
2c244f9b 2948 info->callbacks->einfo (_("%F%P: failed to create PLT .eh_frame section\n"));
a6798bab 2949
fd361982 2950 if (!bfd_set_section_alignment (sec, class_align))
a6798bab
L
2951 goto error_alignment;
2952
2953 htab->plt_eh_frame = sec;
2954
2955 if (htab->plt_got != NULL)
2956 {
2957 sec = bfd_make_section_anyway_with_flags (dynobj,
2958 ".eh_frame",
2959 flags);
2960 if (sec == NULL)
2c244f9b 2961 info->callbacks->einfo (_("%F%P: failed to create GOT PLT .eh_frame section\n"));
a6798bab 2962
fd361982 2963 if (!bfd_set_section_alignment (sec, class_align))
a6798bab
L
2964 goto error_alignment;
2965
2966 htab->plt_got_eh_frame = sec;
2967 }
2968
2969 if (htab->plt_second != NULL)
2970 {
2971 sec = bfd_make_section_anyway_with_flags (dynobj,
2972 ".eh_frame",
2973 flags);
2974 if (sec == NULL)
2c244f9b 2975 info->callbacks->einfo (_("%F%P: failed to create the second PLT .eh_frame section\n"));
a6798bab 2976
fd361982 2977 if (!bfd_set_section_alignment (sec, class_align))
a6798bab
L
2978 goto error_alignment;
2979
2980 htab->plt_second_eh_frame = sec;
2981 }
2982 }
2983 }
2984
b44ee3a8
L
2985 /* The .iplt section is used for IFUNC symbols in static
2986 executables. */
2987 sec = htab->elf.iplt;
2988 if (sec != NULL)
a6798bab 2989 {
b44ee3a8
L
2990 /* NB: Delay setting its alignment until we know it is non-empty.
2991 Otherwise an empty iplt section may change vma and lma of the
2992 following sections, which triggers moving dot of the following
2993 section backwards, resulting in a warning and section lma not
2994 being set properly. It later leads to a "File truncated"
2995 error. */
fd361982 2996 if (!bfd_set_section_alignment (sec, 0))
a6798bab 2997 goto error_alignment;
b44ee3a8
L
2998
2999 htab->plt.iplt_alignment = (normal_target
3000 ? plt_alignment
3001 : bed->plt_alignment);
a6798bab
L
3002 }
3003
74e10d17
L
3004 if (bfd_link_executable (info)
3005 && !info->nointerp
3006 && !htab->params->has_dynamic_linker
3007 && htab->params->static_before_all_inputs)
3008 {
3009 /* Report error for dynamic input objects if -static is passed at
3010 command-line before all input files without --dynamic-linker
3011 unless --no-dynamic-linker is used. */
3012 bfd *abfd;
3013
3014 for (abfd = info->input_bfds; abfd != NULL; abfd = abfd->link.next)
3015 if ((abfd->flags & DYNAMIC))
3016 info->callbacks->einfo
3017 (_("%X%P: attempted static link of dynamic object `%pB'\n"),
3018 abfd);
3019 }
3020
a6798bab
L
3021 return pbfd;
3022}
bfb1e8c1
L
3023
3024/* Fix up x86 GNU properties. */
3025
3026void
0a59decb
L
3027_bfd_x86_elf_link_fixup_gnu_properties
3028 (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3029 elf_property_list **listp)
bfb1e8c1
L
3030{
3031 elf_property_list *p;
3032
3033 for (p = *listp; p; p = p->next)
a9eafb08
L
3034 {
3035 unsigned int type = p->property.pr_type;
3036 if (type == GNU_PROPERTY_X86_COMPAT_ISA_1_USED
3037 || type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3038 || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
3039 && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
3040 || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
3041 && type <= GNU_PROPERTY_X86_UINT32_OR_HI)
3042 || (type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
3043 && type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
3044 {
fde51dd1
L
3045 if (p->property.u.number == 0
3046 && (type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
3047 || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
3048 && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
3049 || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
3050 && type <= GNU_PROPERTY_X86_UINT32_OR_HI)))
a9eafb08
L
3051 {
3052 /* Remove empty property. */
3053 *listp = p->next;
3054 continue;
3055 }
aa7bca9b 3056
a9eafb08
L
3057 listp = &p->next;
3058 }
3059 else if (type > GNU_PROPERTY_HIPROC)
3060 {
3061 /* The property list is sorted in order of type. */
3062 break;
3063 }
3064 }
bfb1e8c1 3065}
5b9c07b2
L
3066
3067void
3068_bfd_elf_linker_x86_set_options (struct bfd_link_info * info,
3069 struct elf_linker_x86_params *params)
3070{
3071 const struct elf_backend_data *bed
3072 = get_elf_backend_data (info->output_bfd);
3073 struct elf_x86_link_hash_table *htab
3074 = elf_x86_hash_table (info, bed->target_id);
3075 if (htab != NULL)
3076 htab->params = params;
3077}
This page took 0.335605 seconds and 4 git commands to generate.