1 /* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
4 Free Software Foundation, Inc.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
29 #include "safe-ctype.h"
30 #include "libiberty.h"
33 /* This struct is used to pass information to routines called via
34 elf_link_hash_traverse which must return failure. */
36 struct elf_info_failed
38 struct bfd_link_info
*info
;
42 /* This structure is used to pass information to
43 _bfd_elf_link_find_version_dependencies. */
45 struct elf_find_verdep_info
47 /* General link information. */
48 struct bfd_link_info
*info
;
49 /* The number of dependencies. */
51 /* Whether we had a failure. */
55 static bfd_boolean _bfd_elf_fix_symbol_flags
56 (struct elf_link_hash_entry
*, struct elf_info_failed
*);
58 /* Define a symbol in a dynamic linkage section. */
60 struct elf_link_hash_entry
*
61 _bfd_elf_define_linkage_sym (bfd
*abfd
,
62 struct bfd_link_info
*info
,
66 struct elf_link_hash_entry
*h
;
67 struct bfd_link_hash_entry
*bh
;
68 const struct elf_backend_data
*bed
;
70 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, FALSE
);
73 /* Zap symbol defined in an as-needed lib that wasn't linked.
74 This is a symptom of a larger problem: Absolute symbols
75 defined in shared libraries can't be overridden, because we
76 lose the link to the bfd which is via the symbol section. */
77 h
->root
.type
= bfd_link_hash_new
;
81 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, name
, BSF_GLOBAL
,
83 get_elf_backend_data (abfd
)->collect
,
86 h
= (struct elf_link_hash_entry
*) bh
;
90 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
92 bed
= get_elf_backend_data (abfd
);
93 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
98 _bfd_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
102 struct elf_link_hash_entry
*h
;
103 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
104 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
106 /* This function may be called more than once. */
107 s
= bfd_get_section_by_name (abfd
, ".got");
108 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
111 flags
= bed
->dynamic_sec_flags
;
113 s
= bfd_make_section_anyway_with_flags (abfd
,
114 (bed
->rela_plts_and_copies_p
115 ? ".rela.got" : ".rel.got"),
116 (bed
->dynamic_sec_flags
119 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
123 s
= bfd_make_section_anyway_with_flags (abfd
, ".got", flags
);
125 || !bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
129 if (bed
->want_got_plt
)
131 s
= bfd_make_section_anyway_with_flags (abfd
, ".got.plt", flags
);
133 || !bfd_set_section_alignment (abfd
, s
,
134 bed
->s
->log_file_align
))
139 /* The first bit of the global offset table is the header. */
140 s
->size
+= bed
->got_header_size
;
142 if (bed
->want_got_sym
)
144 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
145 (or .got.plt) section. We don't do this in the linker script
146 because we don't want to define the symbol if we are not creating
147 a global offset table. */
148 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
149 "_GLOBAL_OFFSET_TABLE_");
150 elf_hash_table (info
)->hgot
= h
;
158 /* Create a strtab to hold the dynamic symbol names. */
160 _bfd_elf_link_create_dynstrtab (bfd
*abfd
, struct bfd_link_info
*info
)
162 struct elf_link_hash_table
*hash_table
;
164 hash_table
= elf_hash_table (info
);
165 if (hash_table
->dynobj
== NULL
)
166 hash_table
->dynobj
= abfd
;
168 if (hash_table
->dynstr
== NULL
)
170 hash_table
->dynstr
= _bfd_elf_strtab_init ();
171 if (hash_table
->dynstr
== NULL
)
177 /* Create some sections which will be filled in with dynamic linking
178 information. ABFD is an input file which requires dynamic sections
179 to be created. The dynamic sections take up virtual memory space
180 when the final executable is run, so we need to create them before
181 addresses are assigned to the output sections. We work out the
182 actual contents and size of these sections later. */
185 _bfd_elf_link_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
189 const struct elf_backend_data
*bed
;
191 if (! is_elf_hash_table (info
->hash
))
194 if (elf_hash_table (info
)->dynamic_sections_created
)
197 if (!_bfd_elf_link_create_dynstrtab (abfd
, info
))
200 abfd
= elf_hash_table (info
)->dynobj
;
201 bed
= get_elf_backend_data (abfd
);
203 flags
= bed
->dynamic_sec_flags
;
205 /* A dynamically linked executable has a .interp section, but a
206 shared library does not. */
207 if (info
->executable
)
209 s
= bfd_make_section_anyway_with_flags (abfd
, ".interp",
210 flags
| SEC_READONLY
);
215 /* Create sections to hold version informations. These are removed
216 if they are not needed. */
217 s
= bfd_make_section_anyway_with_flags (abfd
, ".gnu.version_d",
218 flags
| SEC_READONLY
);
220 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
223 s
= bfd_make_section_anyway_with_flags (abfd
, ".gnu.version",
224 flags
| SEC_READONLY
);
226 || ! bfd_set_section_alignment (abfd
, s
, 1))
229 s
= bfd_make_section_anyway_with_flags (abfd
, ".gnu.version_r",
230 flags
| SEC_READONLY
);
232 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
235 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynsym",
236 flags
| SEC_READONLY
);
238 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
241 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynstr",
242 flags
| SEC_READONLY
);
246 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynamic", flags
);
248 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
251 /* The special symbol _DYNAMIC is always set to the start of the
252 .dynamic section. We could set _DYNAMIC in a linker script, but we
253 only want to define it if we are, in fact, creating a .dynamic
254 section. We don't want to define it if there is no .dynamic
255 section, since on some ELF platforms the start up code examines it
256 to decide how to initialize the process. */
257 if (!_bfd_elf_define_linkage_sym (abfd
, info
, s
, "_DYNAMIC"))
262 s
= bfd_make_section_anyway_with_flags (abfd
, ".hash",
263 flags
| SEC_READONLY
);
265 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
267 elf_section_data (s
)->this_hdr
.sh_entsize
= bed
->s
->sizeof_hash_entry
;
270 if (info
->emit_gnu_hash
)
272 s
= bfd_make_section_anyway_with_flags (abfd
, ".gnu.hash",
273 flags
| SEC_READONLY
);
275 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
277 /* For 64-bit ELF, .gnu.hash is a non-uniform entity size section:
278 4 32-bit words followed by variable count of 64-bit words, then
279 variable count of 32-bit words. */
280 if (bed
->s
->arch_size
== 64)
281 elf_section_data (s
)->this_hdr
.sh_entsize
= 0;
283 elf_section_data (s
)->this_hdr
.sh_entsize
= 4;
286 /* Let the backend create the rest of the sections. This lets the
287 backend set the right flags. The backend will normally create
288 the .got and .plt sections. */
289 if (bed
->elf_backend_create_dynamic_sections
== NULL
290 || ! (*bed
->elf_backend_create_dynamic_sections
) (abfd
, info
))
293 elf_hash_table (info
)->dynamic_sections_created
= TRUE
;
298 /* Create dynamic sections when linking against a dynamic object. */
301 _bfd_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
303 flagword flags
, pltflags
;
304 struct elf_link_hash_entry
*h
;
306 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
307 struct elf_link_hash_table
*htab
= elf_hash_table (info
);
309 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
310 .rel[a].bss sections. */
311 flags
= bed
->dynamic_sec_flags
;
314 if (bed
->plt_not_loaded
)
315 /* We do not clear SEC_ALLOC here because we still want the OS to
316 allocate space for the section; it's just that there's nothing
317 to read in from the object file. */
318 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
320 pltflags
|= SEC_ALLOC
| SEC_CODE
| SEC_LOAD
;
321 if (bed
->plt_readonly
)
322 pltflags
|= SEC_READONLY
;
324 s
= bfd_make_section_anyway_with_flags (abfd
, ".plt", pltflags
);
326 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
330 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
332 if (bed
->want_plt_sym
)
334 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
335 "_PROCEDURE_LINKAGE_TABLE_");
336 elf_hash_table (info
)->hplt
= h
;
341 s
= bfd_make_section_anyway_with_flags (abfd
,
342 (bed
->rela_plts_and_copies_p
343 ? ".rela.plt" : ".rel.plt"),
344 flags
| SEC_READONLY
);
346 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
350 if (! _bfd_elf_create_got_section (abfd
, info
))
353 if (bed
->want_dynbss
)
355 /* The .dynbss section is a place to put symbols which are defined
356 by dynamic objects, are referenced by regular objects, and are
357 not functions. We must allocate space for them in the process
358 image and use a R_*_COPY reloc to tell the dynamic linker to
359 initialize them at run time. The linker script puts the .dynbss
360 section into the .bss section of the final image. */
361 s
= bfd_make_section_anyway_with_flags (abfd
, ".dynbss",
362 (SEC_ALLOC
| SEC_LINKER_CREATED
));
366 /* The .rel[a].bss section holds copy relocs. This section is not
367 normally needed. We need to create it here, though, so that the
368 linker will map it to an output section. We can't just create it
369 only if we need it, because we will not know whether we need it
370 until we have seen all the input files, and the first time the
371 main linker code calls BFD after examining all the input files
372 (size_dynamic_sections) the input sections have already been
373 mapped to the output sections. If the section turns out not to
374 be needed, we can discard it later. We will never need this
375 section when generating a shared object, since they do not use
379 s
= bfd_make_section_anyway_with_flags (abfd
,
380 (bed
->rela_plts_and_copies_p
381 ? ".rela.bss" : ".rel.bss"),
382 flags
| SEC_READONLY
);
384 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
392 /* Record a new dynamic symbol. We record the dynamic symbols as we
393 read the input files, since we need to have a list of all of them
394 before we can determine the final sizes of the output sections.
395 Note that we may actually call this function even though we are not
396 going to output any dynamic symbols; in some cases we know that a
397 symbol should be in the dynamic symbol table, but only if there is
401 bfd_elf_link_record_dynamic_symbol (struct bfd_link_info
*info
,
402 struct elf_link_hash_entry
*h
)
404 if (h
->dynindx
== -1)
406 struct elf_strtab_hash
*dynstr
;
411 /* XXX: The ABI draft says the linker must turn hidden and
412 internal symbols into STB_LOCAL symbols when producing the
413 DSO. However, if ld.so honors st_other in the dynamic table,
414 this would not be necessary. */
415 switch (ELF_ST_VISIBILITY (h
->other
))
419 if (h
->root
.type
!= bfd_link_hash_undefined
420 && h
->root
.type
!= bfd_link_hash_undefweak
)
423 if (!elf_hash_table (info
)->is_relocatable_executable
)
431 h
->dynindx
= elf_hash_table (info
)->dynsymcount
;
432 ++elf_hash_table (info
)->dynsymcount
;
434 dynstr
= elf_hash_table (info
)->dynstr
;
437 /* Create a strtab to hold the dynamic symbol names. */
438 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
443 /* We don't put any version information in the dynamic string
445 name
= h
->root
.root
.string
;
446 p
= strchr (name
, ELF_VER_CHR
);
448 /* We know that the p points into writable memory. In fact,
449 there are only a few symbols that have read-only names, being
450 those like _GLOBAL_OFFSET_TABLE_ that are created specially
451 by the backends. Most symbols will have names pointing into
452 an ELF string table read from a file, or to objalloc memory. */
455 indx
= _bfd_elf_strtab_add (dynstr
, name
, p
!= NULL
);
460 if (indx
== (bfd_size_type
) -1)
462 h
->dynstr_index
= indx
;
468 /* Mark a symbol dynamic. */
471 bfd_elf_link_mark_dynamic_symbol (struct bfd_link_info
*info
,
472 struct elf_link_hash_entry
*h
,
473 Elf_Internal_Sym
*sym
)
475 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
477 /* It may be called more than once on the same H. */
478 if(h
->dynamic
|| info
->relocatable
)
481 if ((info
->dynamic_data
482 && (h
->type
== STT_OBJECT
484 && ELF_ST_TYPE (sym
->st_info
) == STT_OBJECT
)))
486 && h
->root
.type
== bfd_link_hash_new
487 && (*d
->match
) (&d
->head
, NULL
, h
->root
.root
.string
)))
491 /* Record an assignment to a symbol made by a linker script. We need
492 this in case some dynamic object refers to this symbol. */
495 bfd_elf_record_link_assignment (bfd
*output_bfd
,
496 struct bfd_link_info
*info
,
501 struct elf_link_hash_entry
*h
, *hv
;
502 struct elf_link_hash_table
*htab
;
503 const struct elf_backend_data
*bed
;
505 if (!is_elf_hash_table (info
->hash
))
508 htab
= elf_hash_table (info
);
509 h
= elf_link_hash_lookup (htab
, name
, !provide
, TRUE
, FALSE
);
513 switch (h
->root
.type
)
515 case bfd_link_hash_defined
:
516 case bfd_link_hash_defweak
:
517 case bfd_link_hash_common
:
519 case bfd_link_hash_undefweak
:
520 case bfd_link_hash_undefined
:
521 /* Since we're defining the symbol, don't let it seem to have not
522 been defined. record_dynamic_symbol and size_dynamic_sections
523 may depend on this. */
524 h
->root
.type
= bfd_link_hash_new
;
525 if (h
->root
.u
.undef
.next
!= NULL
|| htab
->root
.undefs_tail
== &h
->root
)
526 bfd_link_repair_undef_list (&htab
->root
);
528 case bfd_link_hash_new
:
529 bfd_elf_link_mark_dynamic_symbol (info
, h
, NULL
);
532 case bfd_link_hash_indirect
:
533 /* We had a versioned symbol in a dynamic library. We make the
534 the versioned symbol point to this one. */
535 bed
= get_elf_backend_data (output_bfd
);
537 while (hv
->root
.type
== bfd_link_hash_indirect
538 || hv
->root
.type
== bfd_link_hash_warning
)
539 hv
= (struct elf_link_hash_entry
*) hv
->root
.u
.i
.link
;
540 /* We don't need to update h->root.u since linker will set them
542 h
->root
.type
= bfd_link_hash_undefined
;
543 hv
->root
.type
= bfd_link_hash_indirect
;
544 hv
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) h
;
545 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hv
);
547 case bfd_link_hash_warning
:
552 /* If this symbol is being provided by the linker script, and it is
553 currently defined by a dynamic object, but not by a regular
554 object, then mark it as undefined so that the generic linker will
555 force the correct value. */
559 h
->root
.type
= bfd_link_hash_undefined
;
561 /* If this symbol is not being provided by the linker script, and it is
562 currently defined by a dynamic object, but not by a regular object,
563 then clear out any version information because the symbol will not be
564 associated with the dynamic object any more. */
568 h
->verinfo
.verdef
= NULL
;
572 if (provide
&& hidden
)
574 bed
= get_elf_backend_data (output_bfd
);
575 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
576 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
579 /* STV_HIDDEN and STV_INTERNAL symbols must be STB_LOCAL in shared objects
581 if (!info
->relocatable
583 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
584 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
590 || (info
->executable
&& elf_hash_table (info
)->is_relocatable_executable
))
593 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
596 /* If this is a weak defined symbol, and we know a corresponding
597 real symbol from the same dynamic object, make sure the real
598 symbol is also made into a dynamic symbol. */
599 if (h
->u
.weakdef
!= NULL
600 && h
->u
.weakdef
->dynindx
== -1)
602 if (! bfd_elf_link_record_dynamic_symbol (info
, h
->u
.weakdef
))
610 /* Record a new local dynamic symbol. Returns 0 on failure, 1 on
611 success, and 2 on a failure caused by attempting to record a symbol
612 in a discarded section, eg. a discarded link-once section symbol. */
615 bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info
*info
,
620 struct elf_link_local_dynamic_entry
*entry
;
621 struct elf_link_hash_table
*eht
;
622 struct elf_strtab_hash
*dynstr
;
623 unsigned long dynstr_index
;
625 Elf_External_Sym_Shndx eshndx
;
626 char esym
[sizeof (Elf64_External_Sym
)];
628 if (! is_elf_hash_table (info
->hash
))
631 /* See if the entry exists already. */
632 for (entry
= elf_hash_table (info
)->dynlocal
; entry
; entry
= entry
->next
)
633 if (entry
->input_bfd
== input_bfd
&& entry
->input_indx
== input_indx
)
636 amt
= sizeof (*entry
);
637 entry
= (struct elf_link_local_dynamic_entry
*) bfd_alloc (input_bfd
, amt
);
641 /* Go find the symbol, so that we can find it's name. */
642 if (!bfd_elf_get_elf_syms (input_bfd
, &elf_tdata (input_bfd
)->symtab_hdr
,
643 1, input_indx
, &entry
->isym
, esym
, &eshndx
))
645 bfd_release (input_bfd
, entry
);
649 if (entry
->isym
.st_shndx
!= SHN_UNDEF
650 && entry
->isym
.st_shndx
< SHN_LORESERVE
)
654 s
= bfd_section_from_elf_index (input_bfd
, entry
->isym
.st_shndx
);
655 if (s
== NULL
|| bfd_is_abs_section (s
->output_section
))
657 /* We can still bfd_release here as nothing has done another
658 bfd_alloc. We can't do this later in this function. */
659 bfd_release (input_bfd
, entry
);
664 name
= (bfd_elf_string_from_elf_section
665 (input_bfd
, elf_tdata (input_bfd
)->symtab_hdr
.sh_link
,
666 entry
->isym
.st_name
));
668 dynstr
= elf_hash_table (info
)->dynstr
;
671 /* Create a strtab to hold the dynamic symbol names. */
672 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
677 dynstr_index
= _bfd_elf_strtab_add (dynstr
, name
, FALSE
);
678 if (dynstr_index
== (unsigned long) -1)
680 entry
->isym
.st_name
= dynstr_index
;
682 eht
= elf_hash_table (info
);
684 entry
->next
= eht
->dynlocal
;
685 eht
->dynlocal
= entry
;
686 entry
->input_bfd
= input_bfd
;
687 entry
->input_indx
= input_indx
;
690 /* Whatever binding the symbol had before, it's now local. */
692 = ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (entry
->isym
.st_info
));
694 /* The dynindx will be set at the end of size_dynamic_sections. */
699 /* Return the dynindex of a local dynamic symbol. */
702 _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info
*info
,
706 struct elf_link_local_dynamic_entry
*e
;
708 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
709 if (e
->input_bfd
== input_bfd
&& e
->input_indx
== input_indx
)
714 /* This function is used to renumber the dynamic symbols, if some of
715 them are removed because they are marked as local. This is called
716 via elf_link_hash_traverse. */
719 elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry
*h
,
722 size_t *count
= (size_t *) data
;
727 if (h
->dynindx
!= -1)
728 h
->dynindx
= ++(*count
);
734 /* Like elf_link_renumber_hash_table_dynsyms, but just number symbols with
735 STB_LOCAL binding. */
738 elf_link_renumber_local_hash_table_dynsyms (struct elf_link_hash_entry
*h
,
741 size_t *count
= (size_t *) data
;
743 if (!h
->forced_local
)
746 if (h
->dynindx
!= -1)
747 h
->dynindx
= ++(*count
);
752 /* Return true if the dynamic symbol for a given section should be
753 omitted when creating a shared library. */
755 _bfd_elf_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
756 struct bfd_link_info
*info
,
759 struct elf_link_hash_table
*htab
;
761 switch (elf_section_data (p
)->this_hdr
.sh_type
)
765 /* If sh_type is yet undecided, assume it could be
766 SHT_PROGBITS/SHT_NOBITS. */
768 htab
= elf_hash_table (info
);
769 if (p
== htab
->tls_sec
)
772 if (htab
->text_index_section
!= NULL
)
773 return p
!= htab
->text_index_section
&& p
!= htab
->data_index_section
;
775 if (strcmp (p
->name
, ".got") == 0
776 || strcmp (p
->name
, ".got.plt") == 0
777 || strcmp (p
->name
, ".plt") == 0)
781 if (htab
->dynobj
!= NULL
782 && (ip
= bfd_get_section_by_name (htab
->dynobj
, p
->name
)) != NULL
783 && (ip
->flags
& SEC_LINKER_CREATED
)
784 && ip
->output_section
== p
)
789 /* There shouldn't be section relative relocations
790 against any other section. */
796 /* Assign dynsym indices. In a shared library we generate a section
797 symbol for each output section, which come first. Next come symbols
798 which have been forced to local binding. Then all of the back-end
799 allocated local dynamic syms, followed by the rest of the global
803 _bfd_elf_link_renumber_dynsyms (bfd
*output_bfd
,
804 struct bfd_link_info
*info
,
805 unsigned long *section_sym_count
)
807 unsigned long dynsymcount
= 0;
809 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
811 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
813 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
814 if ((p
->flags
& SEC_EXCLUDE
) == 0
815 && (p
->flags
& SEC_ALLOC
) != 0
816 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
817 elf_section_data (p
)->dynindx
= ++dynsymcount
;
819 elf_section_data (p
)->dynindx
= 0;
821 *section_sym_count
= dynsymcount
;
823 elf_link_hash_traverse (elf_hash_table (info
),
824 elf_link_renumber_local_hash_table_dynsyms
,
827 if (elf_hash_table (info
)->dynlocal
)
829 struct elf_link_local_dynamic_entry
*p
;
830 for (p
= elf_hash_table (info
)->dynlocal
; p
; p
= p
->next
)
831 p
->dynindx
= ++dynsymcount
;
834 elf_link_hash_traverse (elf_hash_table (info
),
835 elf_link_renumber_hash_table_dynsyms
,
838 /* There is an unused NULL entry at the head of the table which
839 we must account for in our count. Unless there weren't any
840 symbols, which means we'll have no table at all. */
841 if (dynsymcount
!= 0)
844 elf_hash_table (info
)->dynsymcount
= dynsymcount
;
848 /* Merge st_other field. */
851 elf_merge_st_other (bfd
*abfd
, struct elf_link_hash_entry
*h
,
852 Elf_Internal_Sym
*isym
, bfd_boolean definition
,
855 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
857 /* If st_other has a processor-specific meaning, specific
858 code might be needed here. We never merge the visibility
859 attribute with the one from a dynamic object. */
860 if (bed
->elf_backend_merge_symbol_attribute
)
861 (*bed
->elf_backend_merge_symbol_attribute
) (h
, isym
, definition
,
864 /* If this symbol has default visibility and the user has requested
865 we not re-export it, then mark it as hidden. */
869 || (abfd
->my_archive
&& abfd
->my_archive
->no_export
))
870 && ELF_ST_VISIBILITY (isym
->st_other
) != STV_INTERNAL
)
871 isym
->st_other
= (STV_HIDDEN
872 | (isym
->st_other
& ~ELF_ST_VISIBILITY (-1)));
874 if (!dynamic
&& ELF_ST_VISIBILITY (isym
->st_other
) != 0)
876 unsigned char hvis
, symvis
, other
, nvis
;
878 /* Only merge the visibility. Leave the remainder of the
879 st_other field to elf_backend_merge_symbol_attribute. */
880 other
= h
->other
& ~ELF_ST_VISIBILITY (-1);
882 /* Combine visibilities, using the most constraining one. */
883 hvis
= ELF_ST_VISIBILITY (h
->other
);
884 symvis
= ELF_ST_VISIBILITY (isym
->st_other
);
890 nvis
= hvis
< symvis
? hvis
: symvis
;
892 h
->other
= other
| nvis
;
896 /* This function is called when we want to define a new symbol. It
897 handles the various cases which arise when we find a definition in
898 a dynamic object, or when there is already a definition in a
899 dynamic object. The new symbol is described by NAME, SYM, PSEC,
900 and PVALUE. We set SYM_HASH to the hash table entry. We set
901 OVERRIDE if the old symbol is overriding a new definition. We set
902 TYPE_CHANGE_OK if it is OK for the type to change. We set
903 SIZE_CHANGE_OK if it is OK for the size to change. By OK to
904 change, we mean that we shouldn't warn if the type or size does
905 change. We set POLD_ALIGNMENT if an old common symbol in a dynamic
906 object is overridden by a regular object. */
909 _bfd_elf_merge_symbol (bfd
*abfd
,
910 struct bfd_link_info
*info
,
912 Elf_Internal_Sym
*sym
,
915 unsigned int *pold_alignment
,
916 struct elf_link_hash_entry
**sym_hash
,
918 bfd_boolean
*override
,
919 bfd_boolean
*type_change_ok
,
920 bfd_boolean
*size_change_ok
)
922 asection
*sec
, *oldsec
;
923 struct elf_link_hash_entry
*h
;
924 struct elf_link_hash_entry
*flip
;
927 bfd_boolean newdyn
, olddyn
, olddef
, newdef
, newdyncommon
, olddyncommon
;
928 bfd_boolean newweak
, oldweak
, newfunc
, oldfunc
;
929 const struct elf_backend_data
*bed
;
935 bind
= ELF_ST_BIND (sym
->st_info
);
937 /* Silently discard TLS symbols from --just-syms. There's no way to
938 combine a static TLS block with a new TLS block for this executable. */
939 if (ELF_ST_TYPE (sym
->st_info
) == STT_TLS
940 && sec
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
946 if (! bfd_is_und_section (sec
))
947 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
, FALSE
, FALSE
);
949 h
= ((struct elf_link_hash_entry
*)
950 bfd_wrapped_link_hash_lookup (abfd
, info
, name
, TRUE
, FALSE
, FALSE
));
955 bed
= get_elf_backend_data (abfd
);
957 /* This code is for coping with dynamic objects, and is only useful
958 if we are doing an ELF link. */
959 if (!(*bed
->relocs_compatible
) (abfd
->xvec
, info
->output_bfd
->xvec
))
962 /* For merging, we only care about real symbols. */
964 while (h
->root
.type
== bfd_link_hash_indirect
965 || h
->root
.type
== bfd_link_hash_warning
)
966 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
968 /* We have to check it for every instance since the first few may be
969 refereences and not all compilers emit symbol type for undefined
971 bfd_elf_link_mark_dynamic_symbol (info
, h
, sym
);
973 /* If we just created the symbol, mark it as being an ELF symbol.
974 Other than that, there is nothing to do--there is no merge issue
975 with a newly defined symbol--so we just return. */
977 if (h
->root
.type
== bfd_link_hash_new
)
983 /* OLDBFD and OLDSEC are a BFD and an ASECTION associated with the
986 switch (h
->root
.type
)
993 case bfd_link_hash_undefined
:
994 case bfd_link_hash_undefweak
:
995 oldbfd
= h
->root
.u
.undef
.abfd
;
999 case bfd_link_hash_defined
:
1000 case bfd_link_hash_defweak
:
1001 oldbfd
= h
->root
.u
.def
.section
->owner
;
1002 oldsec
= h
->root
.u
.def
.section
;
1005 case bfd_link_hash_common
:
1006 oldbfd
= h
->root
.u
.c
.p
->section
->owner
;
1007 oldsec
= h
->root
.u
.c
.p
->section
;
1011 /* Differentiate strong and weak symbols. */
1012 newweak
= bind
== STB_WEAK
;
1013 oldweak
= (h
->root
.type
== bfd_link_hash_defweak
1014 || h
->root
.type
== bfd_link_hash_undefweak
);
1016 /* In cases involving weak versioned symbols, we may wind up trying
1017 to merge a symbol with itself. Catch that here, to avoid the
1018 confusion that results if we try to override a symbol with
1019 itself. The additional tests catch cases like
1020 _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
1021 dynamic object, which we do want to handle here. */
1023 && (newweak
|| oldweak
)
1024 && ((abfd
->flags
& DYNAMIC
) == 0
1025 || !h
->def_regular
))
1028 /* NEWDYN and OLDDYN indicate whether the new or old symbol,
1029 respectively, is from a dynamic object. */
1031 newdyn
= (abfd
->flags
& DYNAMIC
) != 0;
1035 olddyn
= (oldbfd
->flags
& DYNAMIC
) != 0;
1036 else if (oldsec
!= NULL
)
1038 /* This handles the special SHN_MIPS_{TEXT,DATA} section
1039 indices used by MIPS ELF. */
1040 olddyn
= (oldsec
->symbol
->flags
& BSF_DYNAMIC
) != 0;
1043 /* NEWDEF and OLDDEF indicate whether the new or old symbol,
1044 respectively, appear to be a definition rather than reference. */
1046 newdef
= !bfd_is_und_section (sec
) && !bfd_is_com_section (sec
);
1048 olddef
= (h
->root
.type
!= bfd_link_hash_undefined
1049 && h
->root
.type
!= bfd_link_hash_undefweak
1050 && h
->root
.type
!= bfd_link_hash_common
);
1052 /* NEWFUNC and OLDFUNC indicate whether the new or old symbol,
1053 respectively, appear to be a function. */
1055 newfunc
= (ELF_ST_TYPE (sym
->st_info
) != STT_NOTYPE
1056 && bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
)));
1058 oldfunc
= (h
->type
!= STT_NOTYPE
1059 && bed
->is_function_type (h
->type
));
1061 /* When we try to create a default indirect symbol from the dynamic
1062 definition with the default version, we skip it if its type and
1063 the type of existing regular definition mismatch. We only do it
1064 if the existing regular definition won't be dynamic. */
1065 if (pold_alignment
== NULL
1067 && !info
->export_dynamic
1072 && (olddef
|| h
->root
.type
== bfd_link_hash_common
)
1073 && ELF_ST_TYPE (sym
->st_info
) != h
->type
1074 && ELF_ST_TYPE (sym
->st_info
) != STT_NOTYPE
1075 && h
->type
!= STT_NOTYPE
1076 && !(newfunc
&& oldfunc
))
1082 /* Plugin symbol type isn't currently set. Stop bogus errors. */
1083 if (oldbfd
!= NULL
&& (oldbfd
->flags
& BFD_PLUGIN
) != 0)
1084 *type_change_ok
= TRUE
;
1086 /* Check TLS symbol. We don't check undefined symbol introduced by
1088 else if (oldbfd
!= NULL
1089 && ELF_ST_TYPE (sym
->st_info
) != h
->type
1090 && (ELF_ST_TYPE (sym
->st_info
) == STT_TLS
|| h
->type
== STT_TLS
))
1093 bfd_boolean ntdef
, tdef
;
1094 asection
*ntsec
, *tsec
;
1096 if (h
->type
== STT_TLS
)
1116 (*_bfd_error_handler
)
1117 (_("%s: TLS definition in %B section %A mismatches non-TLS definition in %B section %A"),
1118 tbfd
, tsec
, ntbfd
, ntsec
, h
->root
.root
.string
);
1119 else if (!tdef
&& !ntdef
)
1120 (*_bfd_error_handler
)
1121 (_("%s: TLS reference in %B mismatches non-TLS reference in %B"),
1122 tbfd
, ntbfd
, h
->root
.root
.string
);
1124 (*_bfd_error_handler
)
1125 (_("%s: TLS definition in %B section %A mismatches non-TLS reference in %B"),
1126 tbfd
, tsec
, ntbfd
, h
->root
.root
.string
);
1128 (*_bfd_error_handler
)
1129 (_("%s: TLS reference in %B mismatches non-TLS definition in %B section %A"),
1130 tbfd
, ntbfd
, ntsec
, h
->root
.root
.string
);
1132 bfd_set_error (bfd_error_bad_value
);
1136 /* We need to remember if a symbol has a definition in a dynamic
1137 object or is weak in all dynamic objects. Internal and hidden
1138 visibility will make it unavailable to dynamic objects. */
1139 if (newdyn
&& !h
->dynamic_def
)
1141 if (!bfd_is_und_section (sec
))
1145 /* Check if this symbol is weak in all dynamic objects. If it
1146 is the first time we see it in a dynamic object, we mark
1147 if it is weak. Otherwise, we clear it. */
1148 if (!h
->ref_dynamic
)
1150 if (bind
== STB_WEAK
)
1151 h
->dynamic_weak
= 1;
1153 else if (bind
!= STB_WEAK
)
1154 h
->dynamic_weak
= 0;
1158 /* If the old symbol has non-default visibility, we ignore the new
1159 definition from a dynamic object. */
1161 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1162 && !bfd_is_und_section (sec
))
1165 /* Make sure this symbol is dynamic. */
1167 /* A protected symbol has external availability. Make sure it is
1168 recorded as dynamic.
1170 FIXME: Should we check type and size for protected symbol? */
1171 if (ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
1172 return bfd_elf_link_record_dynamic_symbol (info
, h
);
1177 && ELF_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
1180 /* If the new symbol with non-default visibility comes from a
1181 relocatable file and the old definition comes from a dynamic
1182 object, we remove the old definition. */
1183 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1185 /* Handle the case where the old dynamic definition is
1186 default versioned. We need to copy the symbol info from
1187 the symbol with default version to the normal one if it
1188 was referenced before. */
1191 struct elf_link_hash_entry
*vh
= *sym_hash
;
1193 vh
->root
.type
= h
->root
.type
;
1194 h
->root
.type
= bfd_link_hash_indirect
;
1195 (*bed
->elf_backend_copy_indirect_symbol
) (info
, vh
, h
);
1196 /* Protected symbols will override the dynamic definition
1197 with default version. */
1198 if (ELF_ST_VISIBILITY (sym
->st_other
) == STV_PROTECTED
)
1200 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) vh
;
1201 vh
->dynamic_def
= 1;
1202 vh
->ref_dynamic
= 1;
1206 h
->root
.type
= vh
->root
.type
;
1207 vh
->ref_dynamic
= 0;
1208 /* We have to hide it here since it was made dynamic
1209 global with extra bits when the symbol info was
1210 copied from the old dynamic definition. */
1211 (*bed
->elf_backend_hide_symbol
) (info
, vh
, TRUE
);
1219 /* If the old symbol was undefined before, then it will still be
1220 on the undefs list. If the new symbol is undefined or
1221 common, we can't make it bfd_link_hash_new here, because new
1222 undefined or common symbols will be added to the undefs list
1223 by _bfd_generic_link_add_one_symbol. Symbols may not be
1224 added twice to the undefs list. Also, if the new symbol is
1225 undefweak then we don't want to lose the strong undef. */
1226 if (h
->root
.u
.undef
.next
|| info
->hash
->undefs_tail
== &h
->root
)
1228 h
->root
.type
= bfd_link_hash_undefined
;
1229 h
->root
.u
.undef
.abfd
= abfd
;
1233 h
->root
.type
= bfd_link_hash_new
;
1234 h
->root
.u
.undef
.abfd
= NULL
;
1237 if (ELF_ST_VISIBILITY (sym
->st_other
) != STV_PROTECTED
)
1239 /* If the new symbol is hidden or internal, completely undo
1240 any dynamic link state. */
1241 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1242 h
->forced_local
= 0;
1249 /* FIXME: Should we check type and size for protected symbol? */
1255 if (bind
== STB_GNU_UNIQUE
)
1256 h
->unique_global
= 1;
1258 /* If a new weak symbol definition comes from a regular file and the
1259 old symbol comes from a dynamic library, we treat the new one as
1260 strong. Similarly, an old weak symbol definition from a regular
1261 file is treated as strong when the new symbol comes from a dynamic
1262 library. Further, an old weak symbol from a dynamic library is
1263 treated as strong if the new symbol is from a dynamic library.
1264 This reflects the way glibc's ld.so works.
1266 Do this before setting *type_change_ok or *size_change_ok so that
1267 we warn properly when dynamic library symbols are overridden. */
1269 if (newdef
&& !newdyn
&& olddyn
)
1271 if (olddef
&& newdyn
)
1274 /* Allow changes between different types of function symbol. */
1275 if (newfunc
&& oldfunc
)
1276 *type_change_ok
= TRUE
;
1278 /* It's OK to change the type if either the existing symbol or the
1279 new symbol is weak. A type change is also OK if the old symbol
1280 is undefined and the new symbol is defined. */
1285 && h
->root
.type
== bfd_link_hash_undefined
))
1286 *type_change_ok
= TRUE
;
1288 /* It's OK to change the size if either the existing symbol or the
1289 new symbol is weak, or if the old symbol is undefined. */
1292 || h
->root
.type
== bfd_link_hash_undefined
)
1293 *size_change_ok
= TRUE
;
1295 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
1296 symbol, respectively, appears to be a common symbol in a dynamic
1297 object. If a symbol appears in an uninitialized section, and is
1298 not weak, and is not a function, then it may be a common symbol
1299 which was resolved when the dynamic object was created. We want
1300 to treat such symbols specially, because they raise special
1301 considerations when setting the symbol size: if the symbol
1302 appears as a common symbol in a regular object, and the size in
1303 the regular object is larger, we must make sure that we use the
1304 larger size. This problematic case can always be avoided in C,
1305 but it must be handled correctly when using Fortran shared
1308 Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
1309 likewise for OLDDYNCOMMON and OLDDEF.
1311 Note that this test is just a heuristic, and that it is quite
1312 possible to have an uninitialized symbol in a shared object which
1313 is really a definition, rather than a common symbol. This could
1314 lead to some minor confusion when the symbol really is a common
1315 symbol in some regular object. However, I think it will be
1321 && (sec
->flags
& SEC_ALLOC
) != 0
1322 && (sec
->flags
& SEC_LOAD
) == 0
1325 newdyncommon
= TRUE
;
1327 newdyncommon
= FALSE
;
1331 && h
->root
.type
== bfd_link_hash_defined
1333 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
1334 && (h
->root
.u
.def
.section
->flags
& SEC_LOAD
) == 0
1337 olddyncommon
= TRUE
;
1339 olddyncommon
= FALSE
;
1341 /* We now know everything about the old and new symbols. We ask the
1342 backend to check if we can merge them. */
1343 if (bed
->merge_symbol
1344 && !bed
->merge_symbol (info
, sym_hash
, h
, sym
, psec
, pvalue
,
1345 pold_alignment
, skip
, override
,
1346 type_change_ok
, size_change_ok
,
1347 &newdyn
, &newdef
, &newdyncommon
, &newweak
,
1349 &olddyn
, &olddef
, &olddyncommon
, &oldweak
,
1353 /* If both the old and the new symbols look like common symbols in a
1354 dynamic object, set the size of the symbol to the larger of the
1359 && sym
->st_size
!= h
->size
)
1361 /* Since we think we have two common symbols, issue a multiple
1362 common warning if desired. Note that we only warn if the
1363 size is different. If the size is the same, we simply let
1364 the old symbol override the new one as normally happens with
1365 symbols defined in dynamic objects. */
1367 if (! ((*info
->callbacks
->multiple_common
)
1368 (info
, &h
->root
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
1371 if (sym
->st_size
> h
->size
)
1372 h
->size
= sym
->st_size
;
1374 *size_change_ok
= TRUE
;
1377 /* If we are looking at a dynamic object, and we have found a
1378 definition, we need to see if the symbol was already defined by
1379 some other object. If so, we want to use the existing
1380 definition, and we do not want to report a multiple symbol
1381 definition error; we do this by clobbering *PSEC to be
1382 bfd_und_section_ptr.
1384 We treat a common symbol as a definition if the symbol in the
1385 shared library is a function, since common symbols always
1386 represent variables; this can cause confusion in principle, but
1387 any such confusion would seem to indicate an erroneous program or
1388 shared library. We also permit a common symbol in a regular
1389 object to override a weak symbol in a shared object. */
1394 || (h
->root
.type
== bfd_link_hash_common
1395 && (newweak
|| newfunc
))))
1399 newdyncommon
= FALSE
;
1401 *psec
= sec
= bfd_und_section_ptr
;
1402 *size_change_ok
= TRUE
;
1404 /* If we get here when the old symbol is a common symbol, then
1405 we are explicitly letting it override a weak symbol or
1406 function in a dynamic object, and we don't want to warn about
1407 a type change. If the old symbol is a defined symbol, a type
1408 change warning may still be appropriate. */
1410 if (h
->root
.type
== bfd_link_hash_common
)
1411 *type_change_ok
= TRUE
;
1414 /* Handle the special case of an old common symbol merging with a
1415 new symbol which looks like a common symbol in a shared object.
1416 We change *PSEC and *PVALUE to make the new symbol look like a
1417 common symbol, and let _bfd_generic_link_add_one_symbol do the
1421 && h
->root
.type
== bfd_link_hash_common
)
1425 newdyncommon
= FALSE
;
1426 *pvalue
= sym
->st_size
;
1427 *psec
= sec
= bed
->common_section (oldsec
);
1428 *size_change_ok
= TRUE
;
1431 /* Skip weak definitions of symbols that are already defined. */
1432 if (newdef
&& olddef
&& newweak
)
1434 /* Don't skip new non-IR weak syms. */
1435 if (!(oldbfd
!= NULL
1436 && (oldbfd
->flags
& BFD_PLUGIN
) != 0
1437 && (abfd
->flags
& BFD_PLUGIN
) == 0))
1440 /* Merge st_other. If the symbol already has a dynamic index,
1441 but visibility says it should not be visible, turn it into a
1443 elf_merge_st_other (abfd
, h
, sym
, newdef
, newdyn
);
1444 if (h
->dynindx
!= -1)
1445 switch (ELF_ST_VISIBILITY (h
->other
))
1449 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1454 /* If the old symbol is from a dynamic object, and the new symbol is
1455 a definition which is not from a dynamic object, then the new
1456 symbol overrides the old symbol. Symbols from regular files
1457 always take precedence over symbols from dynamic objects, even if
1458 they are defined after the dynamic object in the link.
1460 As above, we again permit a common symbol in a regular object to
1461 override a definition in a shared object if the shared object
1462 symbol is a function or is weak. */
1467 || (bfd_is_com_section (sec
)
1468 && (oldweak
|| oldfunc
)))
1473 /* Change the hash table entry to undefined, and let
1474 _bfd_generic_link_add_one_symbol do the right thing with the
1477 h
->root
.type
= bfd_link_hash_undefined
;
1478 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1479 *size_change_ok
= TRUE
;
1482 olddyncommon
= FALSE
;
1484 /* We again permit a type change when a common symbol may be
1485 overriding a function. */
1487 if (bfd_is_com_section (sec
))
1491 /* If a common symbol overrides a function, make sure
1492 that it isn't defined dynamically nor has type
1495 h
->type
= STT_NOTYPE
;
1497 *type_change_ok
= TRUE
;
1500 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1503 /* This union may have been set to be non-NULL when this symbol
1504 was seen in a dynamic object. We must force the union to be
1505 NULL, so that it is correct for a regular symbol. */
1506 h
->verinfo
.vertree
= NULL
;
1509 /* Handle the special case of a new common symbol merging with an
1510 old symbol that looks like it might be a common symbol defined in
1511 a shared object. Note that we have already handled the case in
1512 which a new common symbol should simply override the definition
1513 in the shared library. */
1516 && bfd_is_com_section (sec
)
1519 /* It would be best if we could set the hash table entry to a
1520 common symbol, but we don't know what to use for the section
1521 or the alignment. */
1522 if (! ((*info
->callbacks
->multiple_common
)
1523 (info
, &h
->root
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
1526 /* If the presumed common symbol in the dynamic object is
1527 larger, pretend that the new symbol has its size. */
1529 if (h
->size
> *pvalue
)
1532 /* We need to remember the alignment required by the symbol
1533 in the dynamic object. */
1534 BFD_ASSERT (pold_alignment
);
1535 *pold_alignment
= h
->root
.u
.def
.section
->alignment_power
;
1538 olddyncommon
= FALSE
;
1540 h
->root
.type
= bfd_link_hash_undefined
;
1541 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1543 *size_change_ok
= TRUE
;
1544 *type_change_ok
= TRUE
;
1546 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1549 h
->verinfo
.vertree
= NULL
;
1554 /* Handle the case where we had a versioned symbol in a dynamic
1555 library and now find a definition in a normal object. In this
1556 case, we make the versioned symbol point to the normal one. */
1557 flip
->root
.type
= h
->root
.type
;
1558 flip
->root
.u
.undef
.abfd
= h
->root
.u
.undef
.abfd
;
1559 h
->root
.type
= bfd_link_hash_indirect
;
1560 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) flip
;
1561 (*bed
->elf_backend_copy_indirect_symbol
) (info
, flip
, h
);
1565 flip
->ref_dynamic
= 1;
1572 /* This function is called to create an indirect symbol from the
1573 default for the symbol with the default version if needed. The
1574 symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We
1575 set DYNSYM if the new indirect symbol is dynamic. */
1578 _bfd_elf_add_default_symbol (bfd
*abfd
,
1579 struct bfd_link_info
*info
,
1580 struct elf_link_hash_entry
*h
,
1582 Elf_Internal_Sym
*sym
,
1585 bfd_boolean
*dynsym
,
1586 bfd_boolean override
)
1588 bfd_boolean type_change_ok
;
1589 bfd_boolean size_change_ok
;
1592 struct elf_link_hash_entry
*hi
;
1593 struct bfd_link_hash_entry
*bh
;
1594 const struct elf_backend_data
*bed
;
1595 bfd_boolean collect
;
1596 bfd_boolean dynamic
;
1598 size_t len
, shortlen
;
1601 /* If this symbol has a version, and it is the default version, we
1602 create an indirect symbol from the default name to the fully
1603 decorated name. This will cause external references which do not
1604 specify a version to be bound to this version of the symbol. */
1605 p
= strchr (name
, ELF_VER_CHR
);
1606 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
1611 /* We are overridden by an old definition. We need to check if we
1612 need to create the indirect symbol from the default name. */
1613 hi
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
,
1615 BFD_ASSERT (hi
!= NULL
);
1618 while (hi
->root
.type
== bfd_link_hash_indirect
1619 || hi
->root
.type
== bfd_link_hash_warning
)
1621 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1627 bed
= get_elf_backend_data (abfd
);
1628 collect
= bed
->collect
;
1629 dynamic
= (abfd
->flags
& DYNAMIC
) != 0;
1631 shortlen
= p
- name
;
1632 shortname
= (char *) bfd_hash_allocate (&info
->hash
->table
, shortlen
+ 1);
1633 if (shortname
== NULL
)
1635 memcpy (shortname
, name
, shortlen
);
1636 shortname
[shortlen
] = '\0';
1638 /* We are going to create a new symbol. Merge it with any existing
1639 symbol with this name. For the purposes of the merge, act as
1640 though we were defining the symbol we just defined, although we
1641 actually going to define an indirect symbol. */
1642 type_change_ok
= FALSE
;
1643 size_change_ok
= FALSE
;
1645 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1646 NULL
, &hi
, &skip
, &override
,
1647 &type_change_ok
, &size_change_ok
))
1656 if (! (_bfd_generic_link_add_one_symbol
1657 (info
, abfd
, shortname
, BSF_INDIRECT
, bfd_ind_section_ptr
,
1658 0, name
, FALSE
, collect
, &bh
)))
1660 hi
= (struct elf_link_hash_entry
*) bh
;
1664 /* In this case the symbol named SHORTNAME is overriding the
1665 indirect symbol we want to add. We were planning on making
1666 SHORTNAME an indirect symbol referring to NAME. SHORTNAME
1667 is the name without a version. NAME is the fully versioned
1668 name, and it is the default version.
1670 Overriding means that we already saw a definition for the
1671 symbol SHORTNAME in a regular object, and it is overriding
1672 the symbol defined in the dynamic object.
1674 When this happens, we actually want to change NAME, the
1675 symbol we just added, to refer to SHORTNAME. This will cause
1676 references to NAME in the shared object to become references
1677 to SHORTNAME in the regular object. This is what we expect
1678 when we override a function in a shared object: that the
1679 references in the shared object will be mapped to the
1680 definition in the regular object. */
1682 while (hi
->root
.type
== bfd_link_hash_indirect
1683 || hi
->root
.type
== bfd_link_hash_warning
)
1684 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1686 h
->root
.type
= bfd_link_hash_indirect
;
1687 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) hi
;
1691 hi
->ref_dynamic
= 1;
1695 if (! bfd_elf_link_record_dynamic_symbol (info
, hi
))
1700 /* Now set HI to H, so that the following code will set the
1701 other fields correctly. */
1705 /* Check if HI is a warning symbol. */
1706 if (hi
->root
.type
== bfd_link_hash_warning
)
1707 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1709 /* If there is a duplicate definition somewhere, then HI may not
1710 point to an indirect symbol. We will have reported an error to
1711 the user in that case. */
1713 if (hi
->root
.type
== bfd_link_hash_indirect
)
1715 struct elf_link_hash_entry
*ht
;
1717 ht
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1718 (*bed
->elf_backend_copy_indirect_symbol
) (info
, ht
, hi
);
1720 /* See if the new flags lead us to realize that the symbol must
1726 if (! info
->executable
1732 if (hi
->ref_regular
)
1738 /* We also need to define an indirection from the nondefault version
1742 len
= strlen (name
);
1743 shortname
= (char *) bfd_hash_allocate (&info
->hash
->table
, len
);
1744 if (shortname
== NULL
)
1746 memcpy (shortname
, name
, shortlen
);
1747 memcpy (shortname
+ shortlen
, p
+ 1, len
- shortlen
);
1749 /* Once again, merge with any existing symbol. */
1750 type_change_ok
= FALSE
;
1751 size_change_ok
= FALSE
;
1753 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1754 NULL
, &hi
, &skip
, &override
,
1755 &type_change_ok
, &size_change_ok
))
1763 /* Here SHORTNAME is a versioned name, so we don't expect to see
1764 the type of override we do in the case above unless it is
1765 overridden by a versioned definition. */
1766 if (hi
->root
.type
!= bfd_link_hash_defined
1767 && hi
->root
.type
!= bfd_link_hash_defweak
)
1768 (*_bfd_error_handler
)
1769 (_("%B: unexpected redefinition of indirect versioned symbol `%s'"),
1775 if (! (_bfd_generic_link_add_one_symbol
1776 (info
, abfd
, shortname
, BSF_INDIRECT
,
1777 bfd_ind_section_ptr
, 0, name
, FALSE
, collect
, &bh
)))
1779 hi
= (struct elf_link_hash_entry
*) bh
;
1781 /* If there is a duplicate definition somewhere, then HI may not
1782 point to an indirect symbol. We will have reported an error
1783 to the user in that case. */
1785 if (hi
->root
.type
== bfd_link_hash_indirect
)
1787 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hi
);
1789 /* See if the new flags lead us to realize that the symbol
1795 if (! info
->executable
1801 if (hi
->ref_regular
)
1811 /* This routine is used to export all defined symbols into the dynamic
1812 symbol table. It is called via elf_link_hash_traverse. */
1815 _bfd_elf_export_symbol (struct elf_link_hash_entry
*h
, void *data
)
1817 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
1819 /* Ignore indirect symbols. These are added by the versioning code. */
1820 if (h
->root
.type
== bfd_link_hash_indirect
)
1823 /* Ignore this if we won't export it. */
1824 if (!eif
->info
->export_dynamic
&& !h
->dynamic
)
1827 if (h
->dynindx
== -1
1828 && (h
->def_regular
|| h
->ref_regular
)
1829 && ! bfd_hide_sym_by_version (eif
->info
->version_info
,
1830 h
->root
.root
.string
))
1832 if (! bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
1842 /* Look through the symbols which are defined in other shared
1843 libraries and referenced here. Update the list of version
1844 dependencies. This will be put into the .gnu.version_r section.
1845 This function is called via elf_link_hash_traverse. */
1848 _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry
*h
,
1851 struct elf_find_verdep_info
*rinfo
= (struct elf_find_verdep_info
*) data
;
1852 Elf_Internal_Verneed
*t
;
1853 Elf_Internal_Vernaux
*a
;
1856 /* We only care about symbols defined in shared objects with version
1861 || h
->verinfo
.verdef
== NULL
)
1864 /* See if we already know about this version. */
1865 for (t
= elf_tdata (rinfo
->info
->output_bfd
)->verref
;
1869 if (t
->vn_bfd
!= h
->verinfo
.verdef
->vd_bfd
)
1872 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
1873 if (a
->vna_nodename
== h
->verinfo
.verdef
->vd_nodename
)
1879 /* This is a new version. Add it to tree we are building. */
1884 t
= (Elf_Internal_Verneed
*) bfd_zalloc (rinfo
->info
->output_bfd
, amt
);
1887 rinfo
->failed
= TRUE
;
1891 t
->vn_bfd
= h
->verinfo
.verdef
->vd_bfd
;
1892 t
->vn_nextref
= elf_tdata (rinfo
->info
->output_bfd
)->verref
;
1893 elf_tdata (rinfo
->info
->output_bfd
)->verref
= t
;
1897 a
= (Elf_Internal_Vernaux
*) bfd_zalloc (rinfo
->info
->output_bfd
, amt
);
1900 rinfo
->failed
= TRUE
;
1904 /* Note that we are copying a string pointer here, and testing it
1905 above. If bfd_elf_string_from_elf_section is ever changed to
1906 discard the string data when low in memory, this will have to be
1908 a
->vna_nodename
= h
->verinfo
.verdef
->vd_nodename
;
1910 a
->vna_flags
= h
->verinfo
.verdef
->vd_flags
;
1911 a
->vna_nextptr
= t
->vn_auxptr
;
1913 h
->verinfo
.verdef
->vd_exp_refno
= rinfo
->vers
;
1916 a
->vna_other
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
1923 /* Figure out appropriate versions for all the symbols. We may not
1924 have the version number script until we have read all of the input
1925 files, so until that point we don't know which symbols should be
1926 local. This function is called via elf_link_hash_traverse. */
1929 _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry
*h
, void *data
)
1931 struct elf_info_failed
*sinfo
;
1932 struct bfd_link_info
*info
;
1933 const struct elf_backend_data
*bed
;
1934 struct elf_info_failed eif
;
1938 sinfo
= (struct elf_info_failed
*) data
;
1941 /* Fix the symbol flags. */
1944 if (! _bfd_elf_fix_symbol_flags (h
, &eif
))
1947 sinfo
->failed
= TRUE
;
1951 /* We only need version numbers for symbols defined in regular
1953 if (!h
->def_regular
)
1956 bed
= get_elf_backend_data (info
->output_bfd
);
1957 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
1958 if (p
!= NULL
&& h
->verinfo
.vertree
== NULL
)
1960 struct bfd_elf_version_tree
*t
;
1965 /* There are two consecutive ELF_VER_CHR characters if this is
1966 not a hidden symbol. */
1968 if (*p
== ELF_VER_CHR
)
1974 /* If there is no version string, we can just return out. */
1982 /* Look for the version. If we find it, it is no longer weak. */
1983 for (t
= sinfo
->info
->version_info
; t
!= NULL
; t
= t
->next
)
1985 if (strcmp (t
->name
, p
) == 0)
1989 struct bfd_elf_version_expr
*d
;
1991 len
= p
- h
->root
.root
.string
;
1992 alc
= (char *) bfd_malloc (len
);
1995 sinfo
->failed
= TRUE
;
1998 memcpy (alc
, h
->root
.root
.string
, len
- 1);
1999 alc
[len
- 1] = '\0';
2000 if (alc
[len
- 2] == ELF_VER_CHR
)
2001 alc
[len
- 2] = '\0';
2003 h
->verinfo
.vertree
= t
;
2007 if (t
->globals
.list
!= NULL
)
2008 d
= (*t
->match
) (&t
->globals
, NULL
, alc
);
2010 /* See if there is anything to force this symbol to
2012 if (d
== NULL
&& t
->locals
.list
!= NULL
)
2014 d
= (*t
->match
) (&t
->locals
, NULL
, alc
);
2017 && ! info
->export_dynamic
)
2018 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
2026 /* If we are building an application, we need to create a
2027 version node for this version. */
2028 if (t
== NULL
&& info
->executable
)
2030 struct bfd_elf_version_tree
**pp
;
2033 /* If we aren't going to export this symbol, we don't need
2034 to worry about it. */
2035 if (h
->dynindx
== -1)
2039 t
= (struct bfd_elf_version_tree
*) bfd_zalloc (info
->output_bfd
, amt
);
2042 sinfo
->failed
= TRUE
;
2047 t
->name_indx
= (unsigned int) -1;
2051 /* Don't count anonymous version tag. */
2052 if (sinfo
->info
->version_info
!= NULL
2053 && sinfo
->info
->version_info
->vernum
== 0)
2055 for (pp
= &sinfo
->info
->version_info
;
2059 t
->vernum
= version_index
;
2063 h
->verinfo
.vertree
= t
;
2067 /* We could not find the version for a symbol when
2068 generating a shared archive. Return an error. */
2069 (*_bfd_error_handler
)
2070 (_("%B: version node not found for symbol %s"),
2071 info
->output_bfd
, h
->root
.root
.string
);
2072 bfd_set_error (bfd_error_bad_value
);
2073 sinfo
->failed
= TRUE
;
2081 /* If we don't have a version for this symbol, see if we can find
2083 if (h
->verinfo
.vertree
== NULL
&& sinfo
->info
->version_info
!= NULL
)
2088 = bfd_find_version_for_sym (sinfo
->info
->version_info
,
2089 h
->root
.root
.string
, &hide
);
2090 if (h
->verinfo
.vertree
!= NULL
&& hide
)
2091 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
2097 /* Read and swap the relocs from the section indicated by SHDR. This
2098 may be either a REL or a RELA section. The relocations are
2099 translated into RELA relocations and stored in INTERNAL_RELOCS,
2100 which should have already been allocated to contain enough space.
2101 The EXTERNAL_RELOCS are a buffer where the external form of the
2102 relocations should be stored.
2104 Returns FALSE if something goes wrong. */
2107 elf_link_read_relocs_from_section (bfd
*abfd
,
2109 Elf_Internal_Shdr
*shdr
,
2110 void *external_relocs
,
2111 Elf_Internal_Rela
*internal_relocs
)
2113 const struct elf_backend_data
*bed
;
2114 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
2115 const bfd_byte
*erela
;
2116 const bfd_byte
*erelaend
;
2117 Elf_Internal_Rela
*irela
;
2118 Elf_Internal_Shdr
*symtab_hdr
;
2121 /* Position ourselves at the start of the section. */
2122 if (bfd_seek (abfd
, shdr
->sh_offset
, SEEK_SET
) != 0)
2125 /* Read the relocations. */
2126 if (bfd_bread (external_relocs
, shdr
->sh_size
, abfd
) != shdr
->sh_size
)
2129 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2130 nsyms
= NUM_SHDR_ENTRIES (symtab_hdr
);
2132 bed
= get_elf_backend_data (abfd
);
2134 /* Convert the external relocations to the internal format. */
2135 if (shdr
->sh_entsize
== bed
->s
->sizeof_rel
)
2136 swap_in
= bed
->s
->swap_reloc_in
;
2137 else if (shdr
->sh_entsize
== bed
->s
->sizeof_rela
)
2138 swap_in
= bed
->s
->swap_reloca_in
;
2141 bfd_set_error (bfd_error_wrong_format
);
2145 erela
= (const bfd_byte
*) external_relocs
;
2146 erelaend
= erela
+ shdr
->sh_size
;
2147 irela
= internal_relocs
;
2148 while (erela
< erelaend
)
2152 (*swap_in
) (abfd
, erela
, irela
);
2153 r_symndx
= ELF32_R_SYM (irela
->r_info
);
2154 if (bed
->s
->arch_size
== 64)
2158 if ((size_t) r_symndx
>= nsyms
)
2160 (*_bfd_error_handler
)
2161 (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
2162 " for offset 0x%lx in section `%A'"),
2164 (unsigned long) r_symndx
, (unsigned long) nsyms
, irela
->r_offset
);
2165 bfd_set_error (bfd_error_bad_value
);
2169 else if (r_symndx
!= STN_UNDEF
)
2171 (*_bfd_error_handler
)
2172 (_("%B: non-zero symbol index (0x%lx) for offset 0x%lx in section `%A'"
2173 " when the object file has no symbol table"),
2175 (unsigned long) r_symndx
, (unsigned long) nsyms
, irela
->r_offset
);
2176 bfd_set_error (bfd_error_bad_value
);
2179 irela
+= bed
->s
->int_rels_per_ext_rel
;
2180 erela
+= shdr
->sh_entsize
;
2186 /* Read and swap the relocs for a section O. They may have been
2187 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
2188 not NULL, they are used as buffers to read into. They are known to
2189 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
2190 the return value is allocated using either malloc or bfd_alloc,
2191 according to the KEEP_MEMORY argument. If O has two relocation
2192 sections (both REL and RELA relocations), then the REL_HDR
2193 relocations will appear first in INTERNAL_RELOCS, followed by the
2194 RELA_HDR relocations. */
2197 _bfd_elf_link_read_relocs (bfd
*abfd
,
2199 void *external_relocs
,
2200 Elf_Internal_Rela
*internal_relocs
,
2201 bfd_boolean keep_memory
)
2203 void *alloc1
= NULL
;
2204 Elf_Internal_Rela
*alloc2
= NULL
;
2205 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2206 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
2207 Elf_Internal_Rela
*internal_rela_relocs
;
2209 if (esdo
->relocs
!= NULL
)
2210 return esdo
->relocs
;
2212 if (o
->reloc_count
== 0)
2215 if (internal_relocs
== NULL
)
2219 size
= o
->reloc_count
;
2220 size
*= bed
->s
->int_rels_per_ext_rel
* sizeof (Elf_Internal_Rela
);
2222 internal_relocs
= alloc2
= (Elf_Internal_Rela
*) bfd_alloc (abfd
, size
);
2224 internal_relocs
= alloc2
= (Elf_Internal_Rela
*) bfd_malloc (size
);
2225 if (internal_relocs
== NULL
)
2229 if (external_relocs
== NULL
)
2231 bfd_size_type size
= 0;
2234 size
+= esdo
->rel
.hdr
->sh_size
;
2236 size
+= esdo
->rela
.hdr
->sh_size
;
2238 alloc1
= bfd_malloc (size
);
2241 external_relocs
= alloc1
;
2244 internal_rela_relocs
= internal_relocs
;
2247 if (!elf_link_read_relocs_from_section (abfd
, o
, esdo
->rel
.hdr
,
2251 external_relocs
= (((bfd_byte
*) external_relocs
)
2252 + esdo
->rel
.hdr
->sh_size
);
2253 internal_rela_relocs
+= (NUM_SHDR_ENTRIES (esdo
->rel
.hdr
)
2254 * bed
->s
->int_rels_per_ext_rel
);
2258 && (!elf_link_read_relocs_from_section (abfd
, o
, esdo
->rela
.hdr
,
2260 internal_rela_relocs
)))
2263 /* Cache the results for next time, if we can. */
2265 esdo
->relocs
= internal_relocs
;
2270 /* Don't free alloc2, since if it was allocated we are passing it
2271 back (under the name of internal_relocs). */
2273 return internal_relocs
;
2281 bfd_release (abfd
, alloc2
);
2288 /* Compute the size of, and allocate space for, REL_HDR which is the
2289 section header for a section containing relocations for O. */
2292 _bfd_elf_link_size_reloc_section (bfd
*abfd
,
2293 struct bfd_elf_section_reloc_data
*reldata
)
2295 Elf_Internal_Shdr
*rel_hdr
= reldata
->hdr
;
2297 /* That allows us to calculate the size of the section. */
2298 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
* reldata
->count
;
2300 /* The contents field must last into write_object_contents, so we
2301 allocate it with bfd_alloc rather than malloc. Also since we
2302 cannot be sure that the contents will actually be filled in,
2303 we zero the allocated space. */
2304 rel_hdr
->contents
= (unsigned char *) bfd_zalloc (abfd
, rel_hdr
->sh_size
);
2305 if (rel_hdr
->contents
== NULL
&& rel_hdr
->sh_size
!= 0)
2308 if (reldata
->hashes
== NULL
&& reldata
->count
)
2310 struct elf_link_hash_entry
**p
;
2312 p
= (struct elf_link_hash_entry
**)
2313 bfd_zmalloc (reldata
->count
* sizeof (struct elf_link_hash_entry
*));
2317 reldata
->hashes
= p
;
2323 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
2324 originated from the section given by INPUT_REL_HDR) to the
2328 _bfd_elf_link_output_relocs (bfd
*output_bfd
,
2329 asection
*input_section
,
2330 Elf_Internal_Shdr
*input_rel_hdr
,
2331 Elf_Internal_Rela
*internal_relocs
,
2332 struct elf_link_hash_entry
**rel_hash
2335 Elf_Internal_Rela
*irela
;
2336 Elf_Internal_Rela
*irelaend
;
2338 struct bfd_elf_section_reloc_data
*output_reldata
;
2339 asection
*output_section
;
2340 const struct elf_backend_data
*bed
;
2341 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
2342 struct bfd_elf_section_data
*esdo
;
2344 output_section
= input_section
->output_section
;
2346 bed
= get_elf_backend_data (output_bfd
);
2347 esdo
= elf_section_data (output_section
);
2348 if (esdo
->rel
.hdr
&& esdo
->rel
.hdr
->sh_entsize
== input_rel_hdr
->sh_entsize
)
2350 output_reldata
= &esdo
->rel
;
2351 swap_out
= bed
->s
->swap_reloc_out
;
2353 else if (esdo
->rela
.hdr
2354 && esdo
->rela
.hdr
->sh_entsize
== input_rel_hdr
->sh_entsize
)
2356 output_reldata
= &esdo
->rela
;
2357 swap_out
= bed
->s
->swap_reloca_out
;
2361 (*_bfd_error_handler
)
2362 (_("%B: relocation size mismatch in %B section %A"),
2363 output_bfd
, input_section
->owner
, input_section
);
2364 bfd_set_error (bfd_error_wrong_format
);
2368 erel
= output_reldata
->hdr
->contents
;
2369 erel
+= output_reldata
->count
* input_rel_hdr
->sh_entsize
;
2370 irela
= internal_relocs
;
2371 irelaend
= irela
+ (NUM_SHDR_ENTRIES (input_rel_hdr
)
2372 * bed
->s
->int_rels_per_ext_rel
);
2373 while (irela
< irelaend
)
2375 (*swap_out
) (output_bfd
, irela
, erel
);
2376 irela
+= bed
->s
->int_rels_per_ext_rel
;
2377 erel
+= input_rel_hdr
->sh_entsize
;
2380 /* Bump the counter, so that we know where to add the next set of
2382 output_reldata
->count
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
2387 /* Make weak undefined symbols in PIE dynamic. */
2390 _bfd_elf_link_hash_fixup_symbol (struct bfd_link_info
*info
,
2391 struct elf_link_hash_entry
*h
)
2395 && h
->root
.type
== bfd_link_hash_undefweak
)
2396 return bfd_elf_link_record_dynamic_symbol (info
, h
);
2401 /* Fix up the flags for a symbol. This handles various cases which
2402 can only be fixed after all the input files are seen. This is
2403 currently called by both adjust_dynamic_symbol and
2404 assign_sym_version, which is unnecessary but perhaps more robust in
2405 the face of future changes. */
2408 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry
*h
,
2409 struct elf_info_failed
*eif
)
2411 const struct elf_backend_data
*bed
;
2413 /* If this symbol was mentioned in a non-ELF file, try to set
2414 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
2415 permit a non-ELF file to correctly refer to a symbol defined in
2416 an ELF dynamic object. */
2419 while (h
->root
.type
== bfd_link_hash_indirect
)
2420 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2422 if (h
->root
.type
!= bfd_link_hash_defined
2423 && h
->root
.type
!= bfd_link_hash_defweak
)
2426 h
->ref_regular_nonweak
= 1;
2430 if (h
->root
.u
.def
.section
->owner
!= NULL
2431 && (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2432 == bfd_target_elf_flavour
))
2435 h
->ref_regular_nonweak
= 1;
2441 if (h
->dynindx
== -1
2445 if (! bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
2454 /* Unfortunately, NON_ELF is only correct if the symbol
2455 was first seen in a non-ELF file. Fortunately, if the symbol
2456 was first seen in an ELF file, we're probably OK unless the
2457 symbol was defined in a non-ELF file. Catch that case here.
2458 FIXME: We're still in trouble if the symbol was first seen in
2459 a dynamic object, and then later in a non-ELF regular object. */
2460 if ((h
->root
.type
== bfd_link_hash_defined
2461 || h
->root
.type
== bfd_link_hash_defweak
)
2463 && (h
->root
.u
.def
.section
->owner
!= NULL
2464 ? (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2465 != bfd_target_elf_flavour
)
2466 : (bfd_is_abs_section (h
->root
.u
.def
.section
)
2467 && !h
->def_dynamic
)))
2471 /* Backend specific symbol fixup. */
2472 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2473 if (bed
->elf_backend_fixup_symbol
2474 && !(*bed
->elf_backend_fixup_symbol
) (eif
->info
, h
))
2477 /* If this is a final link, and the symbol was defined as a common
2478 symbol in a regular object file, and there was no definition in
2479 any dynamic object, then the linker will have allocated space for
2480 the symbol in a common section but the DEF_REGULAR
2481 flag will not have been set. */
2482 if (h
->root
.type
== bfd_link_hash_defined
2486 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
2489 /* If -Bsymbolic was used (which means to bind references to global
2490 symbols to the definition within the shared object), and this
2491 symbol was defined in a regular object, then it actually doesn't
2492 need a PLT entry. Likewise, if the symbol has non-default
2493 visibility. If the symbol has hidden or internal visibility, we
2494 will force it local. */
2496 && eif
->info
->shared
2497 && is_elf_hash_table (eif
->info
->hash
)
2498 && (SYMBOLIC_BIND (eif
->info
, h
)
2499 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2502 bfd_boolean force_local
;
2504 force_local
= (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2505 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
);
2506 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, force_local
);
2509 /* If a weak undefined symbol has non-default visibility, we also
2510 hide it from the dynamic linker. */
2511 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2512 && h
->root
.type
== bfd_link_hash_undefweak
)
2513 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, TRUE
);
2515 /* If this is a weak defined symbol in a dynamic object, and we know
2516 the real definition in the dynamic object, copy interesting flags
2517 over to the real definition. */
2518 if (h
->u
.weakdef
!= NULL
)
2520 /* If the real definition is defined by a regular object file,
2521 don't do anything special. See the longer description in
2522 _bfd_elf_adjust_dynamic_symbol, below. */
2523 if (h
->u
.weakdef
->def_regular
)
2524 h
->u
.weakdef
= NULL
;
2527 struct elf_link_hash_entry
*weakdef
= h
->u
.weakdef
;
2529 while (h
->root
.type
== bfd_link_hash_indirect
)
2530 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2532 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2533 || h
->root
.type
== bfd_link_hash_defweak
);
2534 BFD_ASSERT (weakdef
->def_dynamic
);
2535 BFD_ASSERT (weakdef
->root
.type
== bfd_link_hash_defined
2536 || weakdef
->root
.type
== bfd_link_hash_defweak
);
2537 (*bed
->elf_backend_copy_indirect_symbol
) (eif
->info
, weakdef
, h
);
2544 /* Make the backend pick a good value for a dynamic symbol. This is
2545 called via elf_link_hash_traverse, and also calls itself
2549 _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry
*h
, void *data
)
2551 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
2553 const struct elf_backend_data
*bed
;
2555 if (! is_elf_hash_table (eif
->info
->hash
))
2558 /* Ignore indirect symbols. These are added by the versioning code. */
2559 if (h
->root
.type
== bfd_link_hash_indirect
)
2562 /* Fix the symbol flags. */
2563 if (! _bfd_elf_fix_symbol_flags (h
, eif
))
2566 /* If this symbol does not require a PLT entry, and it is not
2567 defined by a dynamic object, or is not referenced by a regular
2568 object, ignore it. We do have to handle a weak defined symbol,
2569 even if no regular object refers to it, if we decided to add it
2570 to the dynamic symbol table. FIXME: Do we normally need to worry
2571 about symbols which are defined by one dynamic object and
2572 referenced by another one? */
2574 && h
->type
!= STT_GNU_IFUNC
2578 && (h
->u
.weakdef
== NULL
|| h
->u
.weakdef
->dynindx
== -1))))
2580 h
->plt
= elf_hash_table (eif
->info
)->init_plt_offset
;
2584 /* If we've already adjusted this symbol, don't do it again. This
2585 can happen via a recursive call. */
2586 if (h
->dynamic_adjusted
)
2589 /* Don't look at this symbol again. Note that we must set this
2590 after checking the above conditions, because we may look at a
2591 symbol once, decide not to do anything, and then get called
2592 recursively later after REF_REGULAR is set below. */
2593 h
->dynamic_adjusted
= 1;
2595 /* If this is a weak definition, and we know a real definition, and
2596 the real symbol is not itself defined by a regular object file,
2597 then get a good value for the real definition. We handle the
2598 real symbol first, for the convenience of the backend routine.
2600 Note that there is a confusing case here. If the real definition
2601 is defined by a regular object file, we don't get the real symbol
2602 from the dynamic object, but we do get the weak symbol. If the
2603 processor backend uses a COPY reloc, then if some routine in the
2604 dynamic object changes the real symbol, we will not see that
2605 change in the corresponding weak symbol. This is the way other
2606 ELF linkers work as well, and seems to be a result of the shared
2609 I will clarify this issue. Most SVR4 shared libraries define the
2610 variable _timezone and define timezone as a weak synonym. The
2611 tzset call changes _timezone. If you write
2612 extern int timezone;
2614 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
2615 you might expect that, since timezone is a synonym for _timezone,
2616 the same number will print both times. However, if the processor
2617 backend uses a COPY reloc, then actually timezone will be copied
2618 into your process image, and, since you define _timezone
2619 yourself, _timezone will not. Thus timezone and _timezone will
2620 wind up at different memory locations. The tzset call will set
2621 _timezone, leaving timezone unchanged. */
2623 if (h
->u
.weakdef
!= NULL
)
2625 /* If we get to this point, there is an implicit reference to
2626 H->U.WEAKDEF by a regular object file via the weak symbol H. */
2627 h
->u
.weakdef
->ref_regular
= 1;
2629 /* Ensure that the backend adjust_dynamic_symbol function sees
2630 H->U.WEAKDEF before H by recursively calling ourselves. */
2631 if (! _bfd_elf_adjust_dynamic_symbol (h
->u
.weakdef
, eif
))
2635 /* If a symbol has no type and no size and does not require a PLT
2636 entry, then we are probably about to do the wrong thing here: we
2637 are probably going to create a COPY reloc for an empty object.
2638 This case can arise when a shared object is built with assembly
2639 code, and the assembly code fails to set the symbol type. */
2641 && h
->type
== STT_NOTYPE
2643 (*_bfd_error_handler
)
2644 (_("warning: type and size of dynamic symbol `%s' are not defined"),
2645 h
->root
.root
.string
);
2647 dynobj
= elf_hash_table (eif
->info
)->dynobj
;
2648 bed
= get_elf_backend_data (dynobj
);
2650 if (! (*bed
->elf_backend_adjust_dynamic_symbol
) (eif
->info
, h
))
2659 /* Adjust the dynamic symbol, H, for copy in the dynamic bss section,
2663 _bfd_elf_adjust_dynamic_copy (struct elf_link_hash_entry
*h
,
2666 unsigned int power_of_two
;
2668 asection
*sec
= h
->root
.u
.def
.section
;
2670 /* The section aligment of definition is the maximum alignment
2671 requirement of symbols defined in the section. Since we don't
2672 know the symbol alignment requirement, we start with the
2673 maximum alignment and check low bits of the symbol address
2674 for the minimum alignment. */
2675 power_of_two
= bfd_get_section_alignment (sec
->owner
, sec
);
2676 mask
= ((bfd_vma
) 1 << power_of_two
) - 1;
2677 while ((h
->root
.u
.def
.value
& mask
) != 0)
2683 if (power_of_two
> bfd_get_section_alignment (dynbss
->owner
,
2686 /* Adjust the section alignment if needed. */
2687 if (! bfd_set_section_alignment (dynbss
->owner
, dynbss
,
2692 /* We make sure that the symbol will be aligned properly. */
2693 dynbss
->size
= BFD_ALIGN (dynbss
->size
, mask
+ 1);
2695 /* Define the symbol as being at this point in DYNBSS. */
2696 h
->root
.u
.def
.section
= dynbss
;
2697 h
->root
.u
.def
.value
= dynbss
->size
;
2699 /* Increment the size of DYNBSS to make room for the symbol. */
2700 dynbss
->size
+= h
->size
;
2705 /* Adjust all external symbols pointing into SEC_MERGE sections
2706 to reflect the object merging within the sections. */
2709 _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry
*h
, void *data
)
2713 if ((h
->root
.type
== bfd_link_hash_defined
2714 || h
->root
.type
== bfd_link_hash_defweak
)
2715 && ((sec
= h
->root
.u
.def
.section
)->flags
& SEC_MERGE
)
2716 && sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
)
2718 bfd
*output_bfd
= (bfd
*) data
;
2720 h
->root
.u
.def
.value
=
2721 _bfd_merged_section_offset (output_bfd
,
2722 &h
->root
.u
.def
.section
,
2723 elf_section_data (sec
)->sec_info
,
2724 h
->root
.u
.def
.value
);
2730 /* Returns false if the symbol referred to by H should be considered
2731 to resolve local to the current module, and true if it should be
2732 considered to bind dynamically. */
2735 _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
2736 struct bfd_link_info
*info
,
2737 bfd_boolean not_local_protected
)
2739 bfd_boolean binding_stays_local_p
;
2740 const struct elf_backend_data
*bed
;
2741 struct elf_link_hash_table
*hash_table
;
2746 while (h
->root
.type
== bfd_link_hash_indirect
2747 || h
->root
.type
== bfd_link_hash_warning
)
2748 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2750 /* If it was forced local, then clearly it's not dynamic. */
2751 if (h
->dynindx
== -1)
2753 if (h
->forced_local
)
2756 /* Identify the cases where name binding rules say that a
2757 visible symbol resolves locally. */
2758 binding_stays_local_p
= info
->executable
|| SYMBOLIC_BIND (info
, h
);
2760 switch (ELF_ST_VISIBILITY (h
->other
))
2767 hash_table
= elf_hash_table (info
);
2768 if (!is_elf_hash_table (hash_table
))
2771 bed
= get_elf_backend_data (hash_table
->dynobj
);
2773 /* Proper resolution for function pointer equality may require
2774 that these symbols perhaps be resolved dynamically, even though
2775 we should be resolving them to the current module. */
2776 if (!not_local_protected
|| !bed
->is_function_type (h
->type
))
2777 binding_stays_local_p
= TRUE
;
2784 /* If it isn't defined locally, then clearly it's dynamic. */
2785 if (!h
->def_regular
&& !ELF_COMMON_DEF_P (h
))
2788 /* Otherwise, the symbol is dynamic if binding rules don't tell
2789 us that it remains local. */
2790 return !binding_stays_local_p
;
2793 /* Return true if the symbol referred to by H should be considered
2794 to resolve local to the current module, and false otherwise. Differs
2795 from (the inverse of) _bfd_elf_dynamic_symbol_p in the treatment of
2796 undefined symbols. The two functions are virtually identical except
2797 for the place where forced_local and dynindx == -1 are tested. If
2798 either of those tests are true, _bfd_elf_dynamic_symbol_p will say
2799 the symbol is local, while _bfd_elf_symbol_refs_local_p will say
2800 the symbol is local only for defined symbols.
2801 It might seem that _bfd_elf_dynamic_symbol_p could be rewritten as
2802 !_bfd_elf_symbol_refs_local_p, except that targets differ in their
2803 treatment of undefined weak symbols. For those that do not make
2804 undefined weak symbols dynamic, both functions may return false. */
2807 _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry
*h
,
2808 struct bfd_link_info
*info
,
2809 bfd_boolean local_protected
)
2811 const struct elf_backend_data
*bed
;
2812 struct elf_link_hash_table
*hash_table
;
2814 /* If it's a local sym, of course we resolve locally. */
2818 /* STV_HIDDEN or STV_INTERNAL ones must be local. */
2819 if (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
2820 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
)
2823 /* Common symbols that become definitions don't get the DEF_REGULAR
2824 flag set, so test it first, and don't bail out. */
2825 if (ELF_COMMON_DEF_P (h
))
2827 /* If we don't have a definition in a regular file, then we can't
2828 resolve locally. The sym is either undefined or dynamic. */
2829 else if (!h
->def_regular
)
2832 /* Forced local symbols resolve locally. */
2833 if (h
->forced_local
)
2836 /* As do non-dynamic symbols. */
2837 if (h
->dynindx
== -1)
2840 /* At this point, we know the symbol is defined and dynamic. In an
2841 executable it must resolve locally, likewise when building symbolic
2842 shared libraries. */
2843 if (info
->executable
|| SYMBOLIC_BIND (info
, h
))
2846 /* Now deal with defined dynamic symbols in shared libraries. Ones
2847 with default visibility might not resolve locally. */
2848 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2851 hash_table
= elf_hash_table (info
);
2852 if (!is_elf_hash_table (hash_table
))
2855 bed
= get_elf_backend_data (hash_table
->dynobj
);
2857 /* STV_PROTECTED non-function symbols are local. */
2858 if (!bed
->is_function_type (h
->type
))
2861 /* Function pointer equality tests may require that STV_PROTECTED
2862 symbols be treated as dynamic symbols. If the address of a
2863 function not defined in an executable is set to that function's
2864 plt entry in the executable, then the address of the function in
2865 a shared library must also be the plt entry in the executable. */
2866 return local_protected
;
2869 /* Caches some TLS segment info, and ensures that the TLS segment vma is
2870 aligned. Returns the first TLS output section. */
2872 struct bfd_section
*
2873 _bfd_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
2875 struct bfd_section
*sec
, *tls
;
2876 unsigned int align
= 0;
2878 for (sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2879 if ((sec
->flags
& SEC_THREAD_LOCAL
) != 0)
2883 for (; sec
!= NULL
&& (sec
->flags
& SEC_THREAD_LOCAL
) != 0; sec
= sec
->next
)
2884 if (sec
->alignment_power
> align
)
2885 align
= sec
->alignment_power
;
2887 elf_hash_table (info
)->tls_sec
= tls
;
2889 /* Ensure the alignment of the first section is the largest alignment,
2890 so that the tls segment starts aligned. */
2892 tls
->alignment_power
= align
;
2897 /* Return TRUE iff this is a non-common, definition of a non-function symbol. */
2899 is_global_data_symbol_definition (bfd
*abfd ATTRIBUTE_UNUSED
,
2900 Elf_Internal_Sym
*sym
)
2902 const struct elf_backend_data
*bed
;
2904 /* Local symbols do not count, but target specific ones might. */
2905 if (ELF_ST_BIND (sym
->st_info
) != STB_GLOBAL
2906 && ELF_ST_BIND (sym
->st_info
) < STB_LOOS
)
2909 bed
= get_elf_backend_data (abfd
);
2910 /* Function symbols do not count. */
2911 if (bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
)))
2914 /* If the section is undefined, then so is the symbol. */
2915 if (sym
->st_shndx
== SHN_UNDEF
)
2918 /* If the symbol is defined in the common section, then
2919 it is a common definition and so does not count. */
2920 if (bed
->common_definition (sym
))
2923 /* If the symbol is in a target specific section then we
2924 must rely upon the backend to tell us what it is. */
2925 if (sym
->st_shndx
>= SHN_LORESERVE
&& sym
->st_shndx
< SHN_ABS
)
2926 /* FIXME - this function is not coded yet:
2928 return _bfd_is_global_symbol_definition (abfd, sym);
2930 Instead for now assume that the definition is not global,
2931 Even if this is wrong, at least the linker will behave
2932 in the same way that it used to do. */
2938 /* Search the symbol table of the archive element of the archive ABFD
2939 whose archive map contains a mention of SYMDEF, and determine if
2940 the symbol is defined in this element. */
2942 elf_link_is_defined_archive_symbol (bfd
* abfd
, carsym
* symdef
)
2944 Elf_Internal_Shdr
* hdr
;
2945 bfd_size_type symcount
;
2946 bfd_size_type extsymcount
;
2947 bfd_size_type extsymoff
;
2948 Elf_Internal_Sym
*isymbuf
;
2949 Elf_Internal_Sym
*isym
;
2950 Elf_Internal_Sym
*isymend
;
2953 abfd
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
2957 if (! bfd_check_format (abfd
, bfd_object
))
2960 /* If we have already included the element containing this symbol in the
2961 link then we do not need to include it again. Just claim that any symbol
2962 it contains is not a definition, so that our caller will not decide to
2963 (re)include this element. */
2964 if (abfd
->archive_pass
)
2967 /* Select the appropriate symbol table. */
2968 if ((abfd
->flags
& DYNAMIC
) == 0 || elf_dynsymtab (abfd
) == 0)
2969 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2971 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
2973 symcount
= hdr
->sh_size
/ get_elf_backend_data (abfd
)->s
->sizeof_sym
;
2975 /* The sh_info field of the symtab header tells us where the
2976 external symbols start. We don't care about the local symbols. */
2977 if (elf_bad_symtab (abfd
))
2979 extsymcount
= symcount
;
2984 extsymcount
= symcount
- hdr
->sh_info
;
2985 extsymoff
= hdr
->sh_info
;
2988 if (extsymcount
== 0)
2991 /* Read in the symbol table. */
2992 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
2994 if (isymbuf
== NULL
)
2997 /* Scan the symbol table looking for SYMDEF. */
2999 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
; isym
< isymend
; isym
++)
3003 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
3008 if (strcmp (name
, symdef
->name
) == 0)
3010 result
= is_global_data_symbol_definition (abfd
, isym
);
3020 /* Add an entry to the .dynamic table. */
3023 _bfd_elf_add_dynamic_entry (struct bfd_link_info
*info
,
3027 struct elf_link_hash_table
*hash_table
;
3028 const struct elf_backend_data
*bed
;
3030 bfd_size_type newsize
;
3031 bfd_byte
*newcontents
;
3032 Elf_Internal_Dyn dyn
;
3034 hash_table
= elf_hash_table (info
);
3035 if (! is_elf_hash_table (hash_table
))
3038 bed
= get_elf_backend_data (hash_table
->dynobj
);
3039 s
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
3040 BFD_ASSERT (s
!= NULL
);
3042 newsize
= s
->size
+ bed
->s
->sizeof_dyn
;
3043 newcontents
= (bfd_byte
*) bfd_realloc (s
->contents
, newsize
);
3044 if (newcontents
== NULL
)
3048 dyn
.d_un
.d_val
= val
;
3049 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
, newcontents
+ s
->size
);
3052 s
->contents
= newcontents
;
3057 /* Add a DT_NEEDED entry for this dynamic object if DO_IT is true,
3058 otherwise just check whether one already exists. Returns -1 on error,
3059 1 if a DT_NEEDED tag already exists, and 0 on success. */
3062 elf_add_dt_needed_tag (bfd
*abfd
,
3063 struct bfd_link_info
*info
,
3067 struct elf_link_hash_table
*hash_table
;
3068 bfd_size_type oldsize
;
3069 bfd_size_type strindex
;
3071 if (!_bfd_elf_link_create_dynstrtab (abfd
, info
))
3074 hash_table
= elf_hash_table (info
);
3075 oldsize
= _bfd_elf_strtab_size (hash_table
->dynstr
);
3076 strindex
= _bfd_elf_strtab_add (hash_table
->dynstr
, soname
, FALSE
);
3077 if (strindex
== (bfd_size_type
) -1)
3080 if (oldsize
== _bfd_elf_strtab_size (hash_table
->dynstr
))
3083 const struct elf_backend_data
*bed
;
3086 bed
= get_elf_backend_data (hash_table
->dynobj
);
3087 sdyn
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
3089 for (extdyn
= sdyn
->contents
;
3090 extdyn
< sdyn
->contents
+ sdyn
->size
;
3091 extdyn
+= bed
->s
->sizeof_dyn
)
3093 Elf_Internal_Dyn dyn
;
3095 bed
->s
->swap_dyn_in (hash_table
->dynobj
, extdyn
, &dyn
);
3096 if (dyn
.d_tag
== DT_NEEDED
3097 && dyn
.d_un
.d_val
== strindex
)
3099 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
3107 if (!_bfd_elf_link_create_dynamic_sections (hash_table
->dynobj
, info
))
3110 if (!_bfd_elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
3114 /* We were just checking for existence of the tag. */
3115 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
3121 on_needed_list (const char *soname
, struct bfd_link_needed_list
*needed
)
3123 for (; needed
!= NULL
; needed
= needed
->next
)
3124 if (strcmp (soname
, needed
->name
) == 0)
3130 /* Sort symbol by value and section. */
3132 elf_sort_symbol (const void *arg1
, const void *arg2
)
3134 const struct elf_link_hash_entry
*h1
;
3135 const struct elf_link_hash_entry
*h2
;
3136 bfd_signed_vma vdiff
;
3138 h1
= *(const struct elf_link_hash_entry
**) arg1
;
3139 h2
= *(const struct elf_link_hash_entry
**) arg2
;
3140 vdiff
= h1
->root
.u
.def
.value
- h2
->root
.u
.def
.value
;
3142 return vdiff
> 0 ? 1 : -1;
3145 long sdiff
= h1
->root
.u
.def
.section
->id
- h2
->root
.u
.def
.section
->id
;
3147 return sdiff
> 0 ? 1 : -1;
3152 /* This function is used to adjust offsets into .dynstr for
3153 dynamic symbols. This is called via elf_link_hash_traverse. */
3156 elf_adjust_dynstr_offsets (struct elf_link_hash_entry
*h
, void *data
)
3158 struct elf_strtab_hash
*dynstr
= (struct elf_strtab_hash
*) data
;
3160 if (h
->dynindx
!= -1)
3161 h
->dynstr_index
= _bfd_elf_strtab_offset (dynstr
, h
->dynstr_index
);
3165 /* Assign string offsets in .dynstr, update all structures referencing
3169 elf_finalize_dynstr (bfd
*output_bfd
, struct bfd_link_info
*info
)
3171 struct elf_link_hash_table
*hash_table
= elf_hash_table (info
);
3172 struct elf_link_local_dynamic_entry
*entry
;
3173 struct elf_strtab_hash
*dynstr
= hash_table
->dynstr
;
3174 bfd
*dynobj
= hash_table
->dynobj
;
3177 const struct elf_backend_data
*bed
;
3180 _bfd_elf_strtab_finalize (dynstr
);
3181 size
= _bfd_elf_strtab_size (dynstr
);
3183 bed
= get_elf_backend_data (dynobj
);
3184 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3185 BFD_ASSERT (sdyn
!= NULL
);
3187 /* Update all .dynamic entries referencing .dynstr strings. */
3188 for (extdyn
= sdyn
->contents
;
3189 extdyn
< sdyn
->contents
+ sdyn
->size
;
3190 extdyn
+= bed
->s
->sizeof_dyn
)
3192 Elf_Internal_Dyn dyn
;
3194 bed
->s
->swap_dyn_in (dynobj
, extdyn
, &dyn
);
3198 dyn
.d_un
.d_val
= size
;
3208 dyn
.d_un
.d_val
= _bfd_elf_strtab_offset (dynstr
, dyn
.d_un
.d_val
);
3213 bed
->s
->swap_dyn_out (dynobj
, &dyn
, extdyn
);
3216 /* Now update local dynamic symbols. */
3217 for (entry
= hash_table
->dynlocal
; entry
; entry
= entry
->next
)
3218 entry
->isym
.st_name
= _bfd_elf_strtab_offset (dynstr
,
3219 entry
->isym
.st_name
);
3221 /* And the rest of dynamic symbols. */
3222 elf_link_hash_traverse (hash_table
, elf_adjust_dynstr_offsets
, dynstr
);
3224 /* Adjust version definitions. */
3225 if (elf_tdata (output_bfd
)->cverdefs
)
3230 Elf_Internal_Verdef def
;
3231 Elf_Internal_Verdaux defaux
;
3233 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
3237 _bfd_elf_swap_verdef_in (output_bfd
, (Elf_External_Verdef
*) p
,
3239 p
+= sizeof (Elf_External_Verdef
);
3240 if (def
.vd_aux
!= sizeof (Elf_External_Verdef
))
3242 for (i
= 0; i
< def
.vd_cnt
; ++i
)
3244 _bfd_elf_swap_verdaux_in (output_bfd
,
3245 (Elf_External_Verdaux
*) p
, &defaux
);
3246 defaux
.vda_name
= _bfd_elf_strtab_offset (dynstr
,
3248 _bfd_elf_swap_verdaux_out (output_bfd
,
3249 &defaux
, (Elf_External_Verdaux
*) p
);
3250 p
+= sizeof (Elf_External_Verdaux
);
3253 while (def
.vd_next
);
3256 /* Adjust version references. */
3257 if (elf_tdata (output_bfd
)->verref
)
3262 Elf_Internal_Verneed need
;
3263 Elf_Internal_Vernaux needaux
;
3265 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
3269 _bfd_elf_swap_verneed_in (output_bfd
, (Elf_External_Verneed
*) p
,
3271 need
.vn_file
= _bfd_elf_strtab_offset (dynstr
, need
.vn_file
);
3272 _bfd_elf_swap_verneed_out (output_bfd
, &need
,
3273 (Elf_External_Verneed
*) p
);
3274 p
+= sizeof (Elf_External_Verneed
);
3275 for (i
= 0; i
< need
.vn_cnt
; ++i
)
3277 _bfd_elf_swap_vernaux_in (output_bfd
,
3278 (Elf_External_Vernaux
*) p
, &needaux
);
3279 needaux
.vna_name
= _bfd_elf_strtab_offset (dynstr
,
3281 _bfd_elf_swap_vernaux_out (output_bfd
,
3283 (Elf_External_Vernaux
*) p
);
3284 p
+= sizeof (Elf_External_Vernaux
);
3287 while (need
.vn_next
);
3293 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT.
3294 The default is to only match when the INPUT and OUTPUT are exactly
3298 _bfd_elf_default_relocs_compatible (const bfd_target
*input
,
3299 const bfd_target
*output
)
3301 return input
== output
;
3304 /* Return TRUE iff relocations for INPUT are compatible with OUTPUT.
3305 This version is used when different targets for the same architecture
3306 are virtually identical. */
3309 _bfd_elf_relocs_compatible (const bfd_target
*input
,
3310 const bfd_target
*output
)
3312 const struct elf_backend_data
*obed
, *ibed
;
3314 if (input
== output
)
3317 ibed
= xvec_get_elf_backend_data (input
);
3318 obed
= xvec_get_elf_backend_data (output
);
3320 if (ibed
->arch
!= obed
->arch
)
3323 /* If both backends are using this function, deem them compatible. */
3324 return ibed
->relocs_compatible
== obed
->relocs_compatible
;
3327 /* Add symbols from an ELF object file to the linker hash table. */
3330 elf_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3332 Elf_Internal_Ehdr
*ehdr
;
3333 Elf_Internal_Shdr
*hdr
;
3334 bfd_size_type symcount
;
3335 bfd_size_type extsymcount
;
3336 bfd_size_type extsymoff
;
3337 struct elf_link_hash_entry
**sym_hash
;
3338 bfd_boolean dynamic
;
3339 Elf_External_Versym
*extversym
= NULL
;
3340 Elf_External_Versym
*ever
;
3341 struct elf_link_hash_entry
*weaks
;
3342 struct elf_link_hash_entry
**nondeflt_vers
= NULL
;
3343 bfd_size_type nondeflt_vers_cnt
= 0;
3344 Elf_Internal_Sym
*isymbuf
= NULL
;
3345 Elf_Internal_Sym
*isym
;
3346 Elf_Internal_Sym
*isymend
;
3347 const struct elf_backend_data
*bed
;
3348 bfd_boolean add_needed
;
3349 struct elf_link_hash_table
*htab
;
3351 void *alloc_mark
= NULL
;
3352 struct bfd_hash_entry
**old_table
= NULL
;
3353 unsigned int old_size
= 0;
3354 unsigned int old_count
= 0;
3355 void *old_tab
= NULL
;
3358 struct bfd_link_hash_entry
*old_undefs
= NULL
;
3359 struct bfd_link_hash_entry
*old_undefs_tail
= NULL
;
3360 long old_dynsymcount
= 0;
3362 size_t hashsize
= 0;
3364 htab
= elf_hash_table (info
);
3365 bed
= get_elf_backend_data (abfd
);
3367 if ((abfd
->flags
& DYNAMIC
) == 0)
3373 /* You can't use -r against a dynamic object. Also, there's no
3374 hope of using a dynamic object which does not exactly match
3375 the format of the output file. */
3376 if (info
->relocatable
3377 || !is_elf_hash_table (htab
)
3378 || info
->output_bfd
->xvec
!= abfd
->xvec
)
3380 if (info
->relocatable
)
3381 bfd_set_error (bfd_error_invalid_operation
);
3383 bfd_set_error (bfd_error_wrong_format
);
3388 ehdr
= elf_elfheader (abfd
);
3389 if (info
->warn_alternate_em
3390 && bed
->elf_machine_code
!= ehdr
->e_machine
3391 && ((bed
->elf_machine_alt1
!= 0
3392 && ehdr
->e_machine
== bed
->elf_machine_alt1
)
3393 || (bed
->elf_machine_alt2
!= 0
3394 && ehdr
->e_machine
== bed
->elf_machine_alt2
)))
3395 info
->callbacks
->einfo
3396 (_("%P: alternate ELF machine code found (%d) in %B, expecting %d\n"),
3397 ehdr
->e_machine
, abfd
, bed
->elf_machine_code
);
3399 /* As a GNU extension, any input sections which are named
3400 .gnu.warning.SYMBOL are treated as warning symbols for the given
3401 symbol. This differs from .gnu.warning sections, which generate
3402 warnings when they are included in an output file. */
3403 /* PR 12761: Also generate this warning when building shared libraries. */
3404 if (info
->executable
|| info
->shared
)
3408 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3412 name
= bfd_get_section_name (abfd
, s
);
3413 if (CONST_STRNEQ (name
, ".gnu.warning."))
3418 name
+= sizeof ".gnu.warning." - 1;
3420 /* If this is a shared object, then look up the symbol
3421 in the hash table. If it is there, and it is already
3422 been defined, then we will not be using the entry
3423 from this shared object, so we don't need to warn.
3424 FIXME: If we see the definition in a regular object
3425 later on, we will warn, but we shouldn't. The only
3426 fix is to keep track of what warnings we are supposed
3427 to emit, and then handle them all at the end of the
3431 struct elf_link_hash_entry
*h
;
3433 h
= elf_link_hash_lookup (htab
, name
, FALSE
, FALSE
, TRUE
);
3435 /* FIXME: What about bfd_link_hash_common? */
3437 && (h
->root
.type
== bfd_link_hash_defined
3438 || h
->root
.type
== bfd_link_hash_defweak
))
3440 /* We don't want to issue this warning. Clobber
3441 the section size so that the warning does not
3442 get copied into the output file. */
3449 msg
= (char *) bfd_alloc (abfd
, sz
+ 1);
3453 if (! bfd_get_section_contents (abfd
, s
, msg
, 0, sz
))
3458 if (! (_bfd_generic_link_add_one_symbol
3459 (info
, abfd
, name
, BSF_WARNING
, s
, 0, msg
,
3460 FALSE
, bed
->collect
, NULL
)))
3463 if (! info
->relocatable
)
3465 /* Clobber the section size so that the warning does
3466 not get copied into the output file. */
3469 /* Also set SEC_EXCLUDE, so that symbols defined in
3470 the warning section don't get copied to the output. */
3471 s
->flags
|= SEC_EXCLUDE
;
3480 /* If we are creating a shared library, create all the dynamic
3481 sections immediately. We need to attach them to something,
3482 so we attach them to this BFD, provided it is the right
3483 format. FIXME: If there are no input BFD's of the same
3484 format as the output, we can't make a shared library. */
3486 && is_elf_hash_table (htab
)
3487 && info
->output_bfd
->xvec
== abfd
->xvec
3488 && !htab
->dynamic_sections_created
)
3490 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
3494 else if (!is_elf_hash_table (htab
))
3499 const char *soname
= NULL
;
3501 struct bfd_link_needed_list
*rpath
= NULL
, *runpath
= NULL
;
3504 /* ld --just-symbols and dynamic objects don't mix very well.
3505 ld shouldn't allow it. */
3506 if ((s
= abfd
->sections
) != NULL
3507 && s
->sec_info_type
== SEC_INFO_TYPE_JUST_SYMS
)
3510 /* If this dynamic lib was specified on the command line with
3511 --as-needed in effect, then we don't want to add a DT_NEEDED
3512 tag unless the lib is actually used. Similary for libs brought
3513 in by another lib's DT_NEEDED. When --no-add-needed is used
3514 on a dynamic lib, we don't want to add a DT_NEEDED entry for
3515 any dynamic library in DT_NEEDED tags in the dynamic lib at
3517 add_needed
= (elf_dyn_lib_class (abfd
)
3518 & (DYN_AS_NEEDED
| DYN_DT_NEEDED
3519 | DYN_NO_NEEDED
)) == 0;
3521 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3526 unsigned int elfsec
;
3527 unsigned long shlink
;
3529 if (!bfd_malloc_and_get_section (abfd
, s
, &dynbuf
))
3536 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
3537 if (elfsec
== SHN_BAD
)
3538 goto error_free_dyn
;
3539 shlink
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
3541 for (extdyn
= dynbuf
;
3542 extdyn
< dynbuf
+ s
->size
;
3543 extdyn
+= bed
->s
->sizeof_dyn
)
3545 Elf_Internal_Dyn dyn
;
3547 bed
->s
->swap_dyn_in (abfd
, extdyn
, &dyn
);
3548 if (dyn
.d_tag
== DT_SONAME
)
3550 unsigned int tagv
= dyn
.d_un
.d_val
;
3551 soname
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3553 goto error_free_dyn
;
3555 if (dyn
.d_tag
== DT_NEEDED
)
3557 struct bfd_link_needed_list
*n
, **pn
;
3559 unsigned int tagv
= dyn
.d_un
.d_val
;
3561 amt
= sizeof (struct bfd_link_needed_list
);
3562 n
= (struct bfd_link_needed_list
*) bfd_alloc (abfd
, amt
);
3563 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3564 if (n
== NULL
|| fnm
== NULL
)
3565 goto error_free_dyn
;
3566 amt
= strlen (fnm
) + 1;
3567 anm
= (char *) bfd_alloc (abfd
, amt
);
3569 goto error_free_dyn
;
3570 memcpy (anm
, fnm
, amt
);
3574 for (pn
= &htab
->needed
; *pn
!= NULL
; pn
= &(*pn
)->next
)
3578 if (dyn
.d_tag
== DT_RUNPATH
)
3580 struct bfd_link_needed_list
*n
, **pn
;
3582 unsigned int tagv
= dyn
.d_un
.d_val
;
3584 amt
= sizeof (struct bfd_link_needed_list
);
3585 n
= (struct bfd_link_needed_list
*) bfd_alloc (abfd
, amt
);
3586 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3587 if (n
== NULL
|| fnm
== NULL
)
3588 goto error_free_dyn
;
3589 amt
= strlen (fnm
) + 1;
3590 anm
= (char *) bfd_alloc (abfd
, amt
);
3592 goto error_free_dyn
;
3593 memcpy (anm
, fnm
, amt
);
3597 for (pn
= & runpath
;
3603 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */
3604 if (!runpath
&& dyn
.d_tag
== DT_RPATH
)
3606 struct bfd_link_needed_list
*n
, **pn
;
3608 unsigned int tagv
= dyn
.d_un
.d_val
;
3610 amt
= sizeof (struct bfd_link_needed_list
);
3611 n
= (struct bfd_link_needed_list
*) bfd_alloc (abfd
, amt
);
3612 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3613 if (n
== NULL
|| fnm
== NULL
)
3614 goto error_free_dyn
;
3615 amt
= strlen (fnm
) + 1;
3616 anm
= (char *) bfd_alloc (abfd
, amt
);
3618 goto error_free_dyn
;
3619 memcpy (anm
, fnm
, amt
);
3629 if (dyn
.d_tag
== DT_AUDIT
)
3631 unsigned int tagv
= dyn
.d_un
.d_val
;
3632 audit
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3639 /* DT_RUNPATH overrides DT_RPATH. Do _NOT_ bfd_release, as that
3640 frees all more recently bfd_alloc'd blocks as well. */
3646 struct bfd_link_needed_list
**pn
;
3647 for (pn
= &htab
->runpath
; *pn
!= NULL
; pn
= &(*pn
)->next
)
3652 /* We do not want to include any of the sections in a dynamic
3653 object in the output file. We hack by simply clobbering the
3654 list of sections in the BFD. This could be handled more
3655 cleanly by, say, a new section flag; the existing
3656 SEC_NEVER_LOAD flag is not the one we want, because that one
3657 still implies that the section takes up space in the output
3659 bfd_section_list_clear (abfd
);
3661 /* Find the name to use in a DT_NEEDED entry that refers to this
3662 object. If the object has a DT_SONAME entry, we use it.
3663 Otherwise, if the generic linker stuck something in
3664 elf_dt_name, we use that. Otherwise, we just use the file
3666 if (soname
== NULL
|| *soname
== '\0')
3668 soname
= elf_dt_name (abfd
);
3669 if (soname
== NULL
|| *soname
== '\0')
3670 soname
= bfd_get_filename (abfd
);
3673 /* Save the SONAME because sometimes the linker emulation code
3674 will need to know it. */
3675 elf_dt_name (abfd
) = soname
;
3677 ret
= elf_add_dt_needed_tag (abfd
, info
, soname
, add_needed
);
3681 /* If we have already included this dynamic object in the
3682 link, just ignore it. There is no reason to include a
3683 particular dynamic object more than once. */
3687 /* Save the DT_AUDIT entry for the linker emulation code. */
3688 elf_dt_audit (abfd
) = audit
;
3691 /* If this is a dynamic object, we always link against the .dynsym
3692 symbol table, not the .symtab symbol table. The dynamic linker
3693 will only see the .dynsym symbol table, so there is no reason to
3694 look at .symtab for a dynamic object. */
3696 if (! dynamic
|| elf_dynsymtab (abfd
) == 0)
3697 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3699 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
3701 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
3703 /* The sh_info field of the symtab header tells us where the
3704 external symbols start. We don't care about the local symbols at
3706 if (elf_bad_symtab (abfd
))
3708 extsymcount
= symcount
;
3713 extsymcount
= symcount
- hdr
->sh_info
;
3714 extsymoff
= hdr
->sh_info
;
3718 if (extsymcount
!= 0)
3720 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
3722 if (isymbuf
== NULL
)
3725 /* We store a pointer to the hash table entry for each external
3727 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3728 sym_hash
= (struct elf_link_hash_entry
**) bfd_alloc (abfd
, amt
);
3729 if (sym_hash
== NULL
)
3730 goto error_free_sym
;
3731 elf_sym_hashes (abfd
) = sym_hash
;
3736 /* Read in any version definitions. */
3737 if (!_bfd_elf_slurp_version_tables (abfd
,
3738 info
->default_imported_symver
))
3739 goto error_free_sym
;
3741 /* Read in the symbol versions, but don't bother to convert them
3742 to internal format. */
3743 if (elf_dynversym (abfd
) != 0)
3745 Elf_Internal_Shdr
*versymhdr
;
3747 versymhdr
= &elf_tdata (abfd
)->dynversym_hdr
;
3748 extversym
= (Elf_External_Versym
*) bfd_malloc (versymhdr
->sh_size
);
3749 if (extversym
== NULL
)
3750 goto error_free_sym
;
3751 amt
= versymhdr
->sh_size
;
3752 if (bfd_seek (abfd
, versymhdr
->sh_offset
, SEEK_SET
) != 0
3753 || bfd_bread (extversym
, amt
, abfd
) != amt
)
3754 goto error_free_vers
;
3758 /* If we are loading an as-needed shared lib, save the symbol table
3759 state before we start adding symbols. If the lib turns out
3760 to be unneeded, restore the state. */
3761 if ((elf_dyn_lib_class (abfd
) & DYN_AS_NEEDED
) != 0)
3766 for (entsize
= 0, i
= 0; i
< htab
->root
.table
.size
; i
++)
3768 struct bfd_hash_entry
*p
;
3769 struct elf_link_hash_entry
*h
;
3771 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
3773 h
= (struct elf_link_hash_entry
*) p
;
3774 entsize
+= htab
->root
.table
.entsize
;
3775 if (h
->root
.type
== bfd_link_hash_warning
)
3776 entsize
+= htab
->root
.table
.entsize
;
3780 tabsize
= htab
->root
.table
.size
* sizeof (struct bfd_hash_entry
*);
3781 hashsize
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3782 old_tab
= bfd_malloc (tabsize
+ entsize
+ hashsize
);
3783 if (old_tab
== NULL
)
3784 goto error_free_vers
;
3786 /* Remember the current objalloc pointer, so that all mem for
3787 symbols added can later be reclaimed. */
3788 alloc_mark
= bfd_hash_allocate (&htab
->root
.table
, 1);
3789 if (alloc_mark
== NULL
)
3790 goto error_free_vers
;
3792 /* Make a special call to the linker "notice" function to
3793 tell it that we are about to handle an as-needed lib. */
3794 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
3795 notice_as_needed
, 0, NULL
))
3796 goto error_free_vers
;
3798 /* Clone the symbol table and sym hashes. Remember some
3799 pointers into the symbol table, and dynamic symbol count. */
3800 old_hash
= (char *) old_tab
+ tabsize
;
3801 old_ent
= (char *) old_hash
+ hashsize
;
3802 memcpy (old_tab
, htab
->root
.table
.table
, tabsize
);
3803 memcpy (old_hash
, sym_hash
, hashsize
);
3804 old_undefs
= htab
->root
.undefs
;
3805 old_undefs_tail
= htab
->root
.undefs_tail
;
3806 old_table
= htab
->root
.table
.table
;
3807 old_size
= htab
->root
.table
.size
;
3808 old_count
= htab
->root
.table
.count
;
3809 old_dynsymcount
= htab
->dynsymcount
;
3811 for (i
= 0; i
< htab
->root
.table
.size
; i
++)
3813 struct bfd_hash_entry
*p
;
3814 struct elf_link_hash_entry
*h
;
3816 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
3818 memcpy (old_ent
, p
, htab
->root
.table
.entsize
);
3819 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
3820 h
= (struct elf_link_hash_entry
*) p
;
3821 if (h
->root
.type
== bfd_link_hash_warning
)
3823 memcpy (old_ent
, h
->root
.u
.i
.link
, htab
->root
.table
.entsize
);
3824 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
3831 ever
= extversym
!= NULL
? extversym
+ extsymoff
: NULL
;
3832 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
;
3834 isym
++, sym_hash
++, ever
= (ever
!= NULL
? ever
+ 1 : NULL
))
3838 asection
*sec
, *new_sec
;
3841 struct elf_link_hash_entry
*h
;
3842 bfd_boolean definition
;
3843 bfd_boolean size_change_ok
;
3844 bfd_boolean type_change_ok
;
3845 bfd_boolean new_weakdef
;
3846 bfd_boolean override
;
3848 unsigned int old_alignment
;
3850 bfd
* undef_bfd
= NULL
;
3854 flags
= BSF_NO_FLAGS
;
3856 value
= isym
->st_value
;
3858 common
= bed
->common_definition (isym
);
3860 bind
= ELF_ST_BIND (isym
->st_info
);
3864 /* This should be impossible, since ELF requires that all
3865 global symbols follow all local symbols, and that sh_info
3866 point to the first global symbol. Unfortunately, Irix 5
3871 if (isym
->st_shndx
!= SHN_UNDEF
&& !common
)
3879 case STB_GNU_UNIQUE
:
3880 flags
= BSF_GNU_UNIQUE
;
3884 /* Leave it up to the processor backend. */
3888 if (isym
->st_shndx
== SHN_UNDEF
)
3889 sec
= bfd_und_section_ptr
;
3890 else if (isym
->st_shndx
== SHN_ABS
)
3891 sec
= bfd_abs_section_ptr
;
3892 else if (isym
->st_shndx
== SHN_COMMON
)
3894 sec
= bfd_com_section_ptr
;
3895 /* What ELF calls the size we call the value. What ELF
3896 calls the value we call the alignment. */
3897 value
= isym
->st_size
;
3901 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3903 sec
= bfd_abs_section_ptr
;
3904 else if (discarded_section (sec
))
3906 /* Symbols from discarded section are undefined. We keep
3908 sec
= bfd_und_section_ptr
;
3909 isym
->st_shndx
= SHN_UNDEF
;
3911 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
3915 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
3918 goto error_free_vers
;
3920 if (isym
->st_shndx
== SHN_COMMON
3921 && (abfd
->flags
& BFD_PLUGIN
) != 0)
3923 asection
*xc
= bfd_get_section_by_name (abfd
, "COMMON");
3927 flagword sflags
= (SEC_ALLOC
| SEC_IS_COMMON
| SEC_KEEP
3929 xc
= bfd_make_section_with_flags (abfd
, "COMMON", sflags
);
3931 goto error_free_vers
;
3935 else if (isym
->st_shndx
== SHN_COMMON
3936 && ELF_ST_TYPE (isym
->st_info
) == STT_TLS
3937 && !info
->relocatable
)
3939 asection
*tcomm
= bfd_get_section_by_name (abfd
, ".tcommon");
3943 flagword sflags
= (SEC_ALLOC
| SEC_THREAD_LOCAL
| SEC_IS_COMMON
3944 | SEC_LINKER_CREATED
);
3945 tcomm
= bfd_make_section_with_flags (abfd
, ".tcommon", sflags
);
3947 goto error_free_vers
;
3951 else if (bed
->elf_add_symbol_hook
)
3953 if (! (*bed
->elf_add_symbol_hook
) (abfd
, info
, isym
, &name
, &flags
,
3955 goto error_free_vers
;
3957 /* The hook function sets the name to NULL if this symbol
3958 should be skipped for some reason. */
3963 /* Sanity check that all possibilities were handled. */
3966 bfd_set_error (bfd_error_bad_value
);
3967 goto error_free_vers
;
3970 if (bfd_is_und_section (sec
)
3971 || bfd_is_com_section (sec
))
3976 size_change_ok
= FALSE
;
3977 type_change_ok
= bed
->type_change_ok
;
3982 if (is_elf_hash_table (htab
))
3984 Elf_Internal_Versym iver
;
3985 unsigned int vernum
= 0;
3988 /* If this is a definition of a symbol which was previously
3989 referenced in a non-weak manner then make a note of the bfd
3990 that contained the reference. This is used if we need to
3991 refer to the source of the reference later on. */
3992 if (! bfd_is_und_section (sec
))
3994 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, FALSE
);
3997 && h
->root
.type
== bfd_link_hash_undefined
3998 && h
->root
.u
.undef
.abfd
)
3999 undef_bfd
= h
->root
.u
.undef
.abfd
;
4004 if (info
->default_imported_symver
)
4005 /* Use the default symbol version created earlier. */
4006 iver
.vs_vers
= elf_tdata (abfd
)->cverdefs
;
4011 _bfd_elf_swap_versym_in (abfd
, ever
, &iver
);
4013 vernum
= iver
.vs_vers
& VERSYM_VERSION
;
4015 /* If this is a hidden symbol, or if it is not version
4016 1, we append the version name to the symbol name.
4017 However, we do not modify a non-hidden absolute symbol
4018 if it is not a function, because it might be the version
4019 symbol itself. FIXME: What if it isn't? */
4020 if ((iver
.vs_vers
& VERSYM_HIDDEN
) != 0
4022 && (!bfd_is_abs_section (sec
)
4023 || bed
->is_function_type (ELF_ST_TYPE (isym
->st_info
)))))
4026 size_t namelen
, verlen
, newlen
;
4029 if (isym
->st_shndx
!= SHN_UNDEF
)
4031 if (vernum
> elf_tdata (abfd
)->cverdefs
)
4033 else if (vernum
> 1)
4035 elf_tdata (abfd
)->verdef
[vernum
- 1].vd_nodename
;
4041 (*_bfd_error_handler
)
4042 (_("%B: %s: invalid version %u (max %d)"),
4044 elf_tdata (abfd
)->cverdefs
);
4045 bfd_set_error (bfd_error_bad_value
);
4046 goto error_free_vers
;
4051 /* We cannot simply test for the number of
4052 entries in the VERNEED section since the
4053 numbers for the needed versions do not start
4055 Elf_Internal_Verneed
*t
;
4058 for (t
= elf_tdata (abfd
)->verref
;
4062 Elf_Internal_Vernaux
*a
;
4064 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
4066 if (a
->vna_other
== vernum
)
4068 verstr
= a
->vna_nodename
;
4077 (*_bfd_error_handler
)
4078 (_("%B: %s: invalid needed version %d"),
4079 abfd
, name
, vernum
);
4080 bfd_set_error (bfd_error_bad_value
);
4081 goto error_free_vers
;
4085 namelen
= strlen (name
);
4086 verlen
= strlen (verstr
);
4087 newlen
= namelen
+ verlen
+ 2;
4088 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
4089 && isym
->st_shndx
!= SHN_UNDEF
)
4092 newname
= (char *) bfd_hash_allocate (&htab
->root
.table
, newlen
);
4093 if (newname
== NULL
)
4094 goto error_free_vers
;
4095 memcpy (newname
, name
, namelen
);
4096 p
= newname
+ namelen
;
4098 /* If this is a defined non-hidden version symbol,
4099 we add another @ to the name. This indicates the
4100 default version of the symbol. */
4101 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
4102 && isym
->st_shndx
!= SHN_UNDEF
)
4104 memcpy (p
, verstr
, verlen
+ 1);
4109 /* If necessary, make a second attempt to locate the bfd
4110 containing an unresolved, non-weak reference to the
4112 if (! bfd_is_und_section (sec
) && undef_bfd
== NULL
)
4114 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, FALSE
);
4117 && h
->root
.type
== bfd_link_hash_undefined
4118 && h
->root
.u
.undef
.abfd
)
4119 undef_bfd
= h
->root
.u
.undef
.abfd
;
4122 if (!_bfd_elf_merge_symbol (abfd
, info
, name
, isym
, &sec
,
4123 &value
, &old_alignment
,
4124 sym_hash
, &skip
, &override
,
4125 &type_change_ok
, &size_change_ok
))
4126 goto error_free_vers
;
4135 while (h
->root
.type
== bfd_link_hash_indirect
4136 || h
->root
.type
== bfd_link_hash_warning
)
4137 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4139 /* Remember the old alignment if this is a common symbol, so
4140 that we don't reduce the alignment later on. We can't
4141 check later, because _bfd_generic_link_add_one_symbol
4142 will set a default for the alignment which we want to
4143 override. We also remember the old bfd where the existing
4144 definition comes from. */
4145 switch (h
->root
.type
)
4150 case bfd_link_hash_defined
:
4151 case bfd_link_hash_defweak
:
4152 old_bfd
= h
->root
.u
.def
.section
->owner
;
4155 case bfd_link_hash_common
:
4156 old_bfd
= h
->root
.u
.c
.p
->section
->owner
;
4157 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
4161 if (elf_tdata (abfd
)->verdef
!= NULL
4165 h
->verinfo
.verdef
= &elf_tdata (abfd
)->verdef
[vernum
- 1];
4168 if (! (_bfd_generic_link_add_one_symbol
4169 (info
, abfd
, name
, flags
, sec
, value
, NULL
, FALSE
, bed
->collect
,
4170 (struct bfd_link_hash_entry
**) sym_hash
)))
4171 goto error_free_vers
;
4174 while (h
->root
.type
== bfd_link_hash_indirect
4175 || h
->root
.type
== bfd_link_hash_warning
)
4176 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4179 if (is_elf_hash_table (htab
))
4180 h
->unique_global
= (flags
& BSF_GNU_UNIQUE
) != 0;
4182 new_weakdef
= FALSE
;
4185 && (flags
& BSF_WEAK
) != 0
4186 && !bed
->is_function_type (ELF_ST_TYPE (isym
->st_info
))
4187 && is_elf_hash_table (htab
)
4188 && h
->u
.weakdef
== NULL
)
4190 /* Keep a list of all weak defined non function symbols from
4191 a dynamic object, using the weakdef field. Later in this
4192 function we will set the weakdef field to the correct
4193 value. We only put non-function symbols from dynamic
4194 objects on this list, because that happens to be the only
4195 time we need to know the normal symbol corresponding to a
4196 weak symbol, and the information is time consuming to
4197 figure out. If the weakdef field is not already NULL,
4198 then this symbol was already defined by some previous
4199 dynamic object, and we will be using that previous
4200 definition anyhow. */
4202 h
->u
.weakdef
= weaks
;
4207 /* Set the alignment of a common symbol. */
4208 if ((common
|| bfd_is_com_section (sec
))
4209 && h
->root
.type
== bfd_link_hash_common
)
4214 align
= bfd_log2 (isym
->st_value
);
4217 /* The new symbol is a common symbol in a shared object.
4218 We need to get the alignment from the section. */
4219 align
= new_sec
->alignment_power
;
4221 if (align
> old_alignment
)
4222 h
->root
.u
.c
.p
->alignment_power
= align
;
4224 h
->root
.u
.c
.p
->alignment_power
= old_alignment
;
4227 if (is_elf_hash_table (htab
))
4231 /* Check the alignment when a common symbol is involved. This
4232 can change when a common symbol is overridden by a normal
4233 definition or a common symbol is ignored due to the old
4234 normal definition. We need to make sure the maximum
4235 alignment is maintained. */
4236 if ((old_alignment
|| common
)
4237 && h
->root
.type
!= bfd_link_hash_common
)
4239 unsigned int common_align
;
4240 unsigned int normal_align
;
4241 unsigned int symbol_align
;
4245 symbol_align
= ffs (h
->root
.u
.def
.value
) - 1;
4246 if (h
->root
.u
.def
.section
->owner
!= NULL
4247 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
4249 normal_align
= h
->root
.u
.def
.section
->alignment_power
;
4250 if (normal_align
> symbol_align
)
4251 normal_align
= symbol_align
;
4254 normal_align
= symbol_align
;
4258 common_align
= old_alignment
;
4259 common_bfd
= old_bfd
;
4264 common_align
= bfd_log2 (isym
->st_value
);
4266 normal_bfd
= old_bfd
;
4269 if (normal_align
< common_align
)
4271 /* PR binutils/2735 */
4272 if (normal_bfd
== NULL
)
4273 (*_bfd_error_handler
)
4274 (_("Warning: alignment %u of common symbol `%s' in %B"
4275 " is greater than the alignment (%u) of its section %A"),
4276 common_bfd
, h
->root
.u
.def
.section
,
4277 1 << common_align
, name
, 1 << normal_align
);
4279 (*_bfd_error_handler
)
4280 (_("Warning: alignment %u of symbol `%s' in %B"
4281 " is smaller than %u in %B"),
4282 normal_bfd
, common_bfd
,
4283 1 << normal_align
, name
, 1 << common_align
);
4287 /* Remember the symbol size if it isn't undefined. */
4288 if ((isym
->st_size
!= 0 && isym
->st_shndx
!= SHN_UNDEF
)
4289 && (definition
|| h
->size
== 0))
4292 && h
->size
!= isym
->st_size
4293 && ! size_change_ok
)
4294 (*_bfd_error_handler
)
4295 (_("Warning: size of symbol `%s' changed"
4296 " from %lu in %B to %lu in %B"),
4298 name
, (unsigned long) h
->size
,
4299 (unsigned long) isym
->st_size
);
4301 h
->size
= isym
->st_size
;
4304 /* If this is a common symbol, then we always want H->SIZE
4305 to be the size of the common symbol. The code just above
4306 won't fix the size if a common symbol becomes larger. We
4307 don't warn about a size change here, because that is
4308 covered by --warn-common. Allow changed between different
4310 if (h
->root
.type
== bfd_link_hash_common
)
4311 h
->size
= h
->root
.u
.c
.size
;
4313 if (ELF_ST_TYPE (isym
->st_info
) != STT_NOTYPE
4314 && (definition
|| h
->type
== STT_NOTYPE
))
4316 unsigned int type
= ELF_ST_TYPE (isym
->st_info
);
4318 /* Turn an IFUNC symbol from a DSO into a normal FUNC
4320 if (type
== STT_GNU_IFUNC
4321 && (abfd
->flags
& DYNAMIC
) != 0)
4324 if (h
->type
!= type
)
4326 if (h
->type
!= STT_NOTYPE
&& ! type_change_ok
)
4327 (*_bfd_error_handler
)
4328 (_("Warning: type of symbol `%s' changed"
4329 " from %d to %d in %B"),
4330 abfd
, name
, h
->type
, type
);
4336 /* Merge st_other field. */
4337 elf_merge_st_other (abfd
, h
, isym
, definition
, dynamic
);
4339 /* Set a flag in the hash table entry indicating the type of
4340 reference or definition we just found. Keep a count of
4341 the number of dynamic symbols we find. A dynamic symbol
4342 is one which is referenced or defined by both a regular
4343 object and a shared object. */
4350 if (bind
!= STB_WEAK
)
4351 h
->ref_regular_nonweak
= 1;
4362 if (! info
->executable
4378 || (h
->u
.weakdef
!= NULL
4380 && h
->u
.weakdef
->dynindx
!= -1))
4384 /* We don't want to make debug symbol dynamic. */
4385 if (definition
&& (sec
->flags
& SEC_DEBUGGING
) && !info
->relocatable
)
4388 /* Nor should we make plugin symbols dynamic. */
4389 if ((abfd
->flags
& BFD_PLUGIN
) != 0)
4393 h
->target_internal
= isym
->st_target_internal
;
4395 /* Check to see if we need to add an indirect symbol for
4396 the default name. */
4397 if (definition
|| h
->root
.type
== bfd_link_hash_common
)
4398 if (!_bfd_elf_add_default_symbol (abfd
, info
, h
, name
, isym
,
4399 &sec
, &value
, &dynsym
,
4401 goto error_free_vers
;
4403 if (definition
&& !dynamic
)
4405 char *p
= strchr (name
, ELF_VER_CHR
);
4406 if (p
!= NULL
&& p
[1] != ELF_VER_CHR
)
4408 /* Queue non-default versions so that .symver x, x@FOO
4409 aliases can be checked. */
4412 amt
= ((isymend
- isym
+ 1)
4413 * sizeof (struct elf_link_hash_entry
*));
4415 (struct elf_link_hash_entry
**) bfd_malloc (amt
);
4417 goto error_free_vers
;
4419 nondeflt_vers
[nondeflt_vers_cnt
++] = h
;
4423 if (dynsym
&& h
->dynindx
== -1)
4425 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4426 goto error_free_vers
;
4427 if (h
->u
.weakdef
!= NULL
4429 && h
->u
.weakdef
->dynindx
== -1)
4431 if (!bfd_elf_link_record_dynamic_symbol (info
, h
->u
.weakdef
))
4432 goto error_free_vers
;
4435 else if (dynsym
&& h
->dynindx
!= -1)
4436 /* If the symbol already has a dynamic index, but
4437 visibility says it should not be visible, turn it into
4439 switch (ELF_ST_VISIBILITY (h
->other
))
4443 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
4453 && (elf_dyn_lib_class (abfd
) & DYN_AS_NEEDED
) != 0
4454 && !on_needed_list (elf_dt_name (abfd
), htab
->needed
))))
4457 const char *soname
= elf_dt_name (abfd
);
4459 /* A symbol from a library loaded via DT_NEEDED of some
4460 other library is referenced by a regular object.
4461 Add a DT_NEEDED entry for it. Issue an error if
4462 --no-add-needed is used and the reference was not
4464 if (undef_bfd
!= NULL
4465 && (elf_dyn_lib_class (abfd
) & DYN_NO_NEEDED
) != 0)
4467 (*_bfd_error_handler
)
4468 (_("%B: undefined reference to symbol '%s'"),
4470 (*_bfd_error_handler
)
4471 (_("note: '%s' is defined in DSO %B so try adding it to the linker command line"),
4473 bfd_set_error (bfd_error_invalid_operation
);
4474 goto error_free_vers
;
4477 elf_dyn_lib_class (abfd
) = (enum dynamic_lib_link_class
)
4478 (elf_dyn_lib_class (abfd
) & ~DYN_AS_NEEDED
);
4481 ret
= elf_add_dt_needed_tag (abfd
, info
, soname
, add_needed
);
4483 goto error_free_vers
;
4485 BFD_ASSERT (ret
== 0);
4490 if (extversym
!= NULL
)
4496 if (isymbuf
!= NULL
)
4502 if ((elf_dyn_lib_class (abfd
) & DYN_AS_NEEDED
) != 0)
4506 /* Restore the symbol table. */
4507 if (bed
->as_needed_cleanup
)
4508 (*bed
->as_needed_cleanup
) (abfd
, info
);
4509 old_hash
= (char *) old_tab
+ tabsize
;
4510 old_ent
= (char *) old_hash
+ hashsize
;
4511 sym_hash
= elf_sym_hashes (abfd
);
4512 htab
->root
.table
.table
= old_table
;
4513 htab
->root
.table
.size
= old_size
;
4514 htab
->root
.table
.count
= old_count
;
4515 memcpy (htab
->root
.table
.table
, old_tab
, tabsize
);
4516 memcpy (sym_hash
, old_hash
, hashsize
);
4517 htab
->root
.undefs
= old_undefs
;
4518 htab
->root
.undefs_tail
= old_undefs_tail
;
4519 for (i
= 0; i
< htab
->root
.table
.size
; i
++)
4521 struct bfd_hash_entry
*p
;
4522 struct elf_link_hash_entry
*h
;
4524 unsigned int alignment_power
;
4526 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
4528 h
= (struct elf_link_hash_entry
*) p
;
4529 if (h
->root
.type
== bfd_link_hash_warning
)
4530 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4531 if (h
->dynindx
>= old_dynsymcount
)
4532 _bfd_elf_strtab_delref (htab
->dynstr
, h
->dynstr_index
);
4534 /* Preserve the maximum alignment and size for common
4535 symbols even if this dynamic lib isn't on DT_NEEDED
4536 since it can still be loaded at the run-time by another
4538 if (h
->root
.type
== bfd_link_hash_common
)
4540 size
= h
->root
.u
.c
.size
;
4541 alignment_power
= h
->root
.u
.c
.p
->alignment_power
;
4546 alignment_power
= 0;
4548 memcpy (p
, old_ent
, htab
->root
.table
.entsize
);
4549 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
4550 h
= (struct elf_link_hash_entry
*) p
;
4551 if (h
->root
.type
== bfd_link_hash_warning
)
4553 memcpy (h
->root
.u
.i
.link
, old_ent
, htab
->root
.table
.entsize
);
4554 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
4556 else if (h
->root
.type
== bfd_link_hash_common
)
4558 if (size
> h
->root
.u
.c
.size
)
4559 h
->root
.u
.c
.size
= size
;
4560 if (alignment_power
> h
->root
.u
.c
.p
->alignment_power
)
4561 h
->root
.u
.c
.p
->alignment_power
= alignment_power
;
4566 /* Make a special call to the linker "notice" function to
4567 tell it that symbols added for crefs may need to be removed. */
4568 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
4569 notice_not_needed
, 0, NULL
))
4570 goto error_free_vers
;
4573 objalloc_free_block ((struct objalloc
*) htab
->root
.table
.memory
,
4575 if (nondeflt_vers
!= NULL
)
4576 free (nondeflt_vers
);
4580 if (old_tab
!= NULL
)
4582 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
4583 notice_needed
, 0, NULL
))
4584 goto error_free_vers
;
4589 /* Now that all the symbols from this input file are created, handle
4590 .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */
4591 if (nondeflt_vers
!= NULL
)
4593 bfd_size_type cnt
, symidx
;
4595 for (cnt
= 0; cnt
< nondeflt_vers_cnt
; ++cnt
)
4597 struct elf_link_hash_entry
*h
= nondeflt_vers
[cnt
], *hi
;
4598 char *shortname
, *p
;
4600 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
4602 || (h
->root
.type
!= bfd_link_hash_defined
4603 && h
->root
.type
!= bfd_link_hash_defweak
))
4606 amt
= p
- h
->root
.root
.string
;
4607 shortname
= (char *) bfd_malloc (amt
+ 1);
4609 goto error_free_vers
;
4610 memcpy (shortname
, h
->root
.root
.string
, amt
);
4611 shortname
[amt
] = '\0';
4613 hi
= (struct elf_link_hash_entry
*)
4614 bfd_link_hash_lookup (&htab
->root
, shortname
,
4615 FALSE
, FALSE
, FALSE
);
4617 && hi
->root
.type
== h
->root
.type
4618 && hi
->root
.u
.def
.value
== h
->root
.u
.def
.value
4619 && hi
->root
.u
.def
.section
== h
->root
.u
.def
.section
)
4621 (*bed
->elf_backend_hide_symbol
) (info
, hi
, TRUE
);
4622 hi
->root
.type
= bfd_link_hash_indirect
;
4623 hi
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) h
;
4624 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hi
);
4625 sym_hash
= elf_sym_hashes (abfd
);
4627 for (symidx
= 0; symidx
< extsymcount
; ++symidx
)
4628 if (sym_hash
[symidx
] == hi
)
4630 sym_hash
[symidx
] = h
;
4636 free (nondeflt_vers
);
4637 nondeflt_vers
= NULL
;
4640 /* Now set the weakdefs field correctly for all the weak defined
4641 symbols we found. The only way to do this is to search all the
4642 symbols. Since we only need the information for non functions in
4643 dynamic objects, that's the only time we actually put anything on
4644 the list WEAKS. We need this information so that if a regular
4645 object refers to a symbol defined weakly in a dynamic object, the
4646 real symbol in the dynamic object is also put in the dynamic
4647 symbols; we also must arrange for both symbols to point to the
4648 same memory location. We could handle the general case of symbol
4649 aliasing, but a general symbol alias can only be generated in
4650 assembler code, handling it correctly would be very time
4651 consuming, and other ELF linkers don't handle general aliasing
4655 struct elf_link_hash_entry
**hpp
;
4656 struct elf_link_hash_entry
**hppend
;
4657 struct elf_link_hash_entry
**sorted_sym_hash
;
4658 struct elf_link_hash_entry
*h
;
4661 /* Since we have to search the whole symbol list for each weak
4662 defined symbol, search time for N weak defined symbols will be
4663 O(N^2). Binary search will cut it down to O(NlogN). */
4664 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
4665 sorted_sym_hash
= (struct elf_link_hash_entry
**) bfd_malloc (amt
);
4666 if (sorted_sym_hash
== NULL
)
4668 sym_hash
= sorted_sym_hash
;
4669 hpp
= elf_sym_hashes (abfd
);
4670 hppend
= hpp
+ extsymcount
;
4672 for (; hpp
< hppend
; hpp
++)
4676 && h
->root
.type
== bfd_link_hash_defined
4677 && !bed
->is_function_type (h
->type
))
4685 qsort (sorted_sym_hash
, sym_count
,
4686 sizeof (struct elf_link_hash_entry
*),
4689 while (weaks
!= NULL
)
4691 struct elf_link_hash_entry
*hlook
;
4698 weaks
= hlook
->u
.weakdef
;
4699 hlook
->u
.weakdef
= NULL
;
4701 BFD_ASSERT (hlook
->root
.type
== bfd_link_hash_defined
4702 || hlook
->root
.type
== bfd_link_hash_defweak
4703 || hlook
->root
.type
== bfd_link_hash_common
4704 || hlook
->root
.type
== bfd_link_hash_indirect
);
4705 slook
= hlook
->root
.u
.def
.section
;
4706 vlook
= hlook
->root
.u
.def
.value
;
4713 bfd_signed_vma vdiff
;
4715 h
= sorted_sym_hash
[idx
];
4716 vdiff
= vlook
- h
->root
.u
.def
.value
;
4723 long sdiff
= slook
->id
- h
->root
.u
.def
.section
->id
;
4736 /* We didn't find a value/section match. */
4740 for (i
= ilook
; i
< sym_count
; i
++)
4742 h
= sorted_sym_hash
[i
];
4744 /* Stop if value or section doesn't match. */
4745 if (h
->root
.u
.def
.value
!= vlook
4746 || h
->root
.u
.def
.section
!= slook
)
4748 else if (h
!= hlook
)
4750 hlook
->u
.weakdef
= h
;
4752 /* If the weak definition is in the list of dynamic
4753 symbols, make sure the real definition is put
4755 if (hlook
->dynindx
!= -1 && h
->dynindx
== -1)
4757 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4760 free (sorted_sym_hash
);
4765 /* If the real definition is in the list of dynamic
4766 symbols, make sure the weak definition is put
4767 there as well. If we don't do this, then the
4768 dynamic loader might not merge the entries for the
4769 real definition and the weak definition. */
4770 if (h
->dynindx
!= -1 && hlook
->dynindx
== -1)
4772 if (! bfd_elf_link_record_dynamic_symbol (info
, hlook
))
4773 goto err_free_sym_hash
;
4780 free (sorted_sym_hash
);
4783 if (bed
->check_directives
4784 && !(*bed
->check_directives
) (abfd
, info
))
4787 /* If this object is the same format as the output object, and it is
4788 not a shared library, then let the backend look through the
4791 This is required to build global offset table entries and to
4792 arrange for dynamic relocs. It is not required for the
4793 particular common case of linking non PIC code, even when linking
4794 against shared libraries, but unfortunately there is no way of
4795 knowing whether an object file has been compiled PIC or not.
4796 Looking through the relocs is not particularly time consuming.
4797 The problem is that we must either (1) keep the relocs in memory,
4798 which causes the linker to require additional runtime memory or
4799 (2) read the relocs twice from the input file, which wastes time.
4800 This would be a good case for using mmap.
4802 I have no idea how to handle linking PIC code into a file of a
4803 different format. It probably can't be done. */
4805 && is_elf_hash_table (htab
)
4806 && bed
->check_relocs
!= NULL
4807 && elf_object_id (abfd
) == elf_hash_table_id (htab
)
4808 && (*bed
->relocs_compatible
) (abfd
->xvec
, info
->output_bfd
->xvec
))
4812 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4814 Elf_Internal_Rela
*internal_relocs
;
4817 if ((o
->flags
& SEC_RELOC
) == 0
4818 || o
->reloc_count
== 0
4819 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
4820 && (o
->flags
& SEC_DEBUGGING
) != 0)
4821 || bfd_is_abs_section (o
->output_section
))
4824 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
4826 if (internal_relocs
== NULL
)
4829 ok
= (*bed
->check_relocs
) (abfd
, info
, o
, internal_relocs
);
4831 if (elf_section_data (o
)->relocs
!= internal_relocs
)
4832 free (internal_relocs
);
4839 /* If this is a non-traditional link, try to optimize the handling
4840 of the .stab/.stabstr sections. */
4842 && ! info
->traditional_format
4843 && is_elf_hash_table (htab
)
4844 && (info
->strip
!= strip_all
&& info
->strip
!= strip_debugger
))
4848 stabstr
= bfd_get_section_by_name (abfd
, ".stabstr");
4849 if (stabstr
!= NULL
)
4851 bfd_size_type string_offset
= 0;
4854 for (stab
= abfd
->sections
; stab
; stab
= stab
->next
)
4855 if (CONST_STRNEQ (stab
->name
, ".stab")
4856 && (!stab
->name
[5] ||
4857 (stab
->name
[5] == '.' && ISDIGIT (stab
->name
[6])))
4858 && (stab
->flags
& SEC_MERGE
) == 0
4859 && !bfd_is_abs_section (stab
->output_section
))
4861 struct bfd_elf_section_data
*secdata
;
4863 secdata
= elf_section_data (stab
);
4864 if (! _bfd_link_section_stabs (abfd
, &htab
->stab_info
, stab
,
4865 stabstr
, &secdata
->sec_info
,
4868 if (secdata
->sec_info
)
4869 stab
->sec_info_type
= SEC_INFO_TYPE_STABS
;
4874 if (is_elf_hash_table (htab
) && add_needed
)
4876 /* Add this bfd to the loaded list. */
4877 struct elf_link_loaded_list
*n
;
4879 n
= (struct elf_link_loaded_list
*)
4880 bfd_alloc (abfd
, sizeof (struct elf_link_loaded_list
));
4884 n
->next
= htab
->loaded
;
4891 if (old_tab
!= NULL
)
4893 if (nondeflt_vers
!= NULL
)
4894 free (nondeflt_vers
);
4895 if (extversym
!= NULL
)
4898 if (isymbuf
!= NULL
)
4904 /* Return the linker hash table entry of a symbol that might be
4905 satisfied by an archive symbol. Return -1 on error. */
4907 struct elf_link_hash_entry
*
4908 _bfd_elf_archive_symbol_lookup (bfd
*abfd
,
4909 struct bfd_link_info
*info
,
4912 struct elf_link_hash_entry
*h
;
4916 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, TRUE
);
4920 /* If this is a default version (the name contains @@), look up the
4921 symbol again with only one `@' as well as without the version.
4922 The effect is that references to the symbol with and without the
4923 version will be matched by the default symbol in the archive. */
4925 p
= strchr (name
, ELF_VER_CHR
);
4926 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
4929 /* First check with only one `@'. */
4930 len
= strlen (name
);
4931 copy
= (char *) bfd_alloc (abfd
, len
);
4933 return (struct elf_link_hash_entry
*) 0 - 1;
4935 first
= p
- name
+ 1;
4936 memcpy (copy
, name
, first
);
4937 memcpy (copy
+ first
, name
+ first
+ 1, len
- first
);
4939 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
, FALSE
, FALSE
, TRUE
);
4942 /* We also need to check references to the symbol without the
4944 copy
[first
- 1] = '\0';
4945 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
,
4946 FALSE
, FALSE
, TRUE
);
4949 bfd_release (abfd
, copy
);
4953 /* Add symbols from an ELF archive file to the linker hash table. We
4954 don't use _bfd_generic_link_add_archive_symbols because of a
4955 problem which arises on UnixWare. The UnixWare libc.so is an
4956 archive which includes an entry libc.so.1 which defines a bunch of
4957 symbols. The libc.so archive also includes a number of other
4958 object files, which also define symbols, some of which are the same
4959 as those defined in libc.so.1. Correct linking requires that we
4960 consider each object file in turn, and include it if it defines any
4961 symbols we need. _bfd_generic_link_add_archive_symbols does not do
4962 this; it looks through the list of undefined symbols, and includes
4963 any object file which defines them. When this algorithm is used on
4964 UnixWare, it winds up pulling in libc.so.1 early and defining a
4965 bunch of symbols. This means that some of the other objects in the
4966 archive are not included in the link, which is incorrect since they
4967 precede libc.so.1 in the archive.
4969 Fortunately, ELF archive handling is simpler than that done by
4970 _bfd_generic_link_add_archive_symbols, which has to allow for a.out
4971 oddities. In ELF, if we find a symbol in the archive map, and the
4972 symbol is currently undefined, we know that we must pull in that
4975 Unfortunately, we do have to make multiple passes over the symbol
4976 table until nothing further is resolved. */
4979 elf_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4982 bfd_boolean
*defined
= NULL
;
4983 bfd_boolean
*included
= NULL
;
4987 const struct elf_backend_data
*bed
;
4988 struct elf_link_hash_entry
* (*archive_symbol_lookup
)
4989 (bfd
*, struct bfd_link_info
*, const char *);
4991 if (! bfd_has_map (abfd
))
4993 /* An empty archive is a special case. */
4994 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
4996 bfd_set_error (bfd_error_no_armap
);
5000 /* Keep track of all symbols we know to be already defined, and all
5001 files we know to be already included. This is to speed up the
5002 second and subsequent passes. */
5003 c
= bfd_ardata (abfd
)->symdef_count
;
5007 amt
*= sizeof (bfd_boolean
);
5008 defined
= (bfd_boolean
*) bfd_zmalloc (amt
);
5009 included
= (bfd_boolean
*) bfd_zmalloc (amt
);
5010 if (defined
== NULL
|| included
== NULL
)
5013 symdefs
= bfd_ardata (abfd
)->symdefs
;
5014 bed
= get_elf_backend_data (abfd
);
5015 archive_symbol_lookup
= bed
->elf_backend_archive_symbol_lookup
;
5028 symdefend
= symdef
+ c
;
5029 for (i
= 0; symdef
< symdefend
; symdef
++, i
++)
5031 struct elf_link_hash_entry
*h
;
5033 struct bfd_link_hash_entry
*undefs_tail
;
5036 if (defined
[i
] || included
[i
])
5038 if (symdef
->file_offset
== last
)
5044 h
= archive_symbol_lookup (abfd
, info
, symdef
->name
);
5045 if (h
== (struct elf_link_hash_entry
*) 0 - 1)
5051 if (h
->root
.type
== bfd_link_hash_common
)
5053 /* We currently have a common symbol. The archive map contains
5054 a reference to this symbol, so we may want to include it. We
5055 only want to include it however, if this archive element
5056 contains a definition of the symbol, not just another common
5059 Unfortunately some archivers (including GNU ar) will put
5060 declarations of common symbols into their archive maps, as
5061 well as real definitions, so we cannot just go by the archive
5062 map alone. Instead we must read in the element's symbol
5063 table and check that to see what kind of symbol definition
5065 if (! elf_link_is_defined_archive_symbol (abfd
, symdef
))
5068 else if (h
->root
.type
!= bfd_link_hash_undefined
)
5070 if (h
->root
.type
!= bfd_link_hash_undefweak
)
5075 /* We need to include this archive member. */
5076 element
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
5077 if (element
== NULL
)
5080 if (! bfd_check_format (element
, bfd_object
))
5083 /* Doublecheck that we have not included this object
5084 already--it should be impossible, but there may be
5085 something wrong with the archive. */
5086 if (element
->archive_pass
!= 0)
5088 bfd_set_error (bfd_error_bad_value
);
5091 element
->archive_pass
= 1;
5093 undefs_tail
= info
->hash
->undefs_tail
;
5095 if (!(*info
->callbacks
5096 ->add_archive_element
) (info
, element
, symdef
->name
, &element
))
5098 if (!bfd_link_add_symbols (element
, info
))
5101 /* If there are any new undefined symbols, we need to make
5102 another pass through the archive in order to see whether
5103 they can be defined. FIXME: This isn't perfect, because
5104 common symbols wind up on undefs_tail and because an
5105 undefined symbol which is defined later on in this pass
5106 does not require another pass. This isn't a bug, but it
5107 does make the code less efficient than it could be. */
5108 if (undefs_tail
!= info
->hash
->undefs_tail
)
5111 /* Look backward to mark all symbols from this object file
5112 which we have already seen in this pass. */
5116 included
[mark
] = TRUE
;
5121 while (symdefs
[mark
].file_offset
== symdef
->file_offset
);
5123 /* We mark subsequent symbols from this object file as we go
5124 on through the loop. */
5125 last
= symdef
->file_offset
;
5136 if (defined
!= NULL
)
5138 if (included
!= NULL
)
5143 /* Given an ELF BFD, add symbols to the global hash table as
5147 bfd_elf_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
5149 switch (bfd_get_format (abfd
))
5152 return elf_link_add_object_symbols (abfd
, info
);
5154 return elf_link_add_archive_symbols (abfd
, info
);
5156 bfd_set_error (bfd_error_wrong_format
);
5161 struct hash_codes_info
5163 unsigned long *hashcodes
;
5167 /* This function will be called though elf_link_hash_traverse to store
5168 all hash value of the exported symbols in an array. */
5171 elf_collect_hash_codes (struct elf_link_hash_entry
*h
, void *data
)
5173 struct hash_codes_info
*inf
= (struct hash_codes_info
*) data
;
5179 /* Ignore indirect symbols. These are added by the versioning code. */
5180 if (h
->dynindx
== -1)
5183 name
= h
->root
.root
.string
;
5184 p
= strchr (name
, ELF_VER_CHR
);
5187 alc
= (char *) bfd_malloc (p
- name
+ 1);
5193 memcpy (alc
, name
, p
- name
);
5194 alc
[p
- name
] = '\0';
5198 /* Compute the hash value. */
5199 ha
= bfd_elf_hash (name
);
5201 /* Store the found hash value in the array given as the argument. */
5202 *(inf
->hashcodes
)++ = ha
;
5204 /* And store it in the struct so that we can put it in the hash table
5206 h
->u
.elf_hash_value
= ha
;
5214 struct collect_gnu_hash_codes
5217 const struct elf_backend_data
*bed
;
5218 unsigned long int nsyms
;
5219 unsigned long int maskbits
;
5220 unsigned long int *hashcodes
;
5221 unsigned long int *hashval
;
5222 unsigned long int *indx
;
5223 unsigned long int *counts
;
5226 long int min_dynindx
;
5227 unsigned long int bucketcount
;
5228 unsigned long int symindx
;
5229 long int local_indx
;
5230 long int shift1
, shift2
;
5231 unsigned long int mask
;
5235 /* This function will be called though elf_link_hash_traverse to store
5236 all hash value of the exported symbols in an array. */
5239 elf_collect_gnu_hash_codes (struct elf_link_hash_entry
*h
, void *data
)
5241 struct collect_gnu_hash_codes
*s
= (struct collect_gnu_hash_codes
*) data
;
5247 /* Ignore indirect symbols. These are added by the versioning code. */
5248 if (h
->dynindx
== -1)
5251 /* Ignore also local symbols and undefined symbols. */
5252 if (! (*s
->bed
->elf_hash_symbol
) (h
))
5255 name
= h
->root
.root
.string
;
5256 p
= strchr (name
, ELF_VER_CHR
);
5259 alc
= (char *) bfd_malloc (p
- name
+ 1);
5265 memcpy (alc
, name
, p
- name
);
5266 alc
[p
- name
] = '\0';
5270 /* Compute the hash value. */
5271 ha
= bfd_elf_gnu_hash (name
);
5273 /* Store the found hash value in the array for compute_bucket_count,
5274 and also for .dynsym reordering purposes. */
5275 s
->hashcodes
[s
->nsyms
] = ha
;
5276 s
->hashval
[h
->dynindx
] = ha
;
5278 if (s
->min_dynindx
< 0 || s
->min_dynindx
> h
->dynindx
)
5279 s
->min_dynindx
= h
->dynindx
;
5287 /* This function will be called though elf_link_hash_traverse to do
5288 final dynaminc symbol renumbering. */
5291 elf_renumber_gnu_hash_syms (struct elf_link_hash_entry
*h
, void *data
)
5293 struct collect_gnu_hash_codes
*s
= (struct collect_gnu_hash_codes
*) data
;
5294 unsigned long int bucket
;
5295 unsigned long int val
;
5297 /* Ignore indirect symbols. */
5298 if (h
->dynindx
== -1)
5301 /* Ignore also local symbols and undefined symbols. */
5302 if (! (*s
->bed
->elf_hash_symbol
) (h
))
5304 if (h
->dynindx
>= s
->min_dynindx
)
5305 h
->dynindx
= s
->local_indx
++;
5309 bucket
= s
->hashval
[h
->dynindx
] % s
->bucketcount
;
5310 val
= (s
->hashval
[h
->dynindx
] >> s
->shift1
)
5311 & ((s
->maskbits
>> s
->shift1
) - 1);
5312 s
->bitmask
[val
] |= ((bfd_vma
) 1) << (s
->hashval
[h
->dynindx
] & s
->mask
);
5314 |= ((bfd_vma
) 1) << ((s
->hashval
[h
->dynindx
] >> s
->shift2
) & s
->mask
);
5315 val
= s
->hashval
[h
->dynindx
] & ~(unsigned long int) 1;
5316 if (s
->counts
[bucket
] == 1)
5317 /* Last element terminates the chain. */
5319 bfd_put_32 (s
->output_bfd
, val
,
5320 s
->contents
+ (s
->indx
[bucket
] - s
->symindx
) * 4);
5321 --s
->counts
[bucket
];
5322 h
->dynindx
= s
->indx
[bucket
]++;
5326 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5329 _bfd_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5331 return !(h
->forced_local
5332 || h
->root
.type
== bfd_link_hash_undefined
5333 || h
->root
.type
== bfd_link_hash_undefweak
5334 || ((h
->root
.type
== bfd_link_hash_defined
5335 || h
->root
.type
== bfd_link_hash_defweak
)
5336 && h
->root
.u
.def
.section
->output_section
== NULL
));
5339 /* Array used to determine the number of hash table buckets to use
5340 based on the number of symbols there are. If there are fewer than
5341 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
5342 fewer than 37 we use 17 buckets, and so forth. We never use more
5343 than 32771 buckets. */
5345 static const size_t elf_buckets
[] =
5347 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
5351 /* Compute bucket count for hashing table. We do not use a static set
5352 of possible tables sizes anymore. Instead we determine for all
5353 possible reasonable sizes of the table the outcome (i.e., the
5354 number of collisions etc) and choose the best solution. The
5355 weighting functions are not too simple to allow the table to grow
5356 without bounds. Instead one of the weighting factors is the size.
5357 Therefore the result is always a good payoff between few collisions
5358 (= short chain lengths) and table size. */
5360 compute_bucket_count (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
5361 unsigned long int *hashcodes ATTRIBUTE_UNUSED
,
5362 unsigned long int nsyms
,
5365 size_t best_size
= 0;
5366 unsigned long int i
;
5368 /* We have a problem here. The following code to optimize the table
5369 size requires an integer type with more the 32 bits. If
5370 BFD_HOST_U_64_BIT is set we know about such a type. */
5371 #ifdef BFD_HOST_U_64_BIT
5376 BFD_HOST_U_64_BIT best_chlen
= ~((BFD_HOST_U_64_BIT
) 0);
5377 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5378 size_t dynsymcount
= elf_hash_table (info
)->dynsymcount
;
5379 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
5380 unsigned long int *counts
;
5382 unsigned int no_improvement_count
= 0;
5384 /* Possible optimization parameters: if we have NSYMS symbols we say
5385 that the hashing table must at least have NSYMS/4 and at most
5387 minsize
= nsyms
/ 4;
5390 best_size
= maxsize
= nsyms
* 2;
5395 if ((best_size
& 31) == 0)
5399 /* Create array where we count the collisions in. We must use bfd_malloc
5400 since the size could be large. */
5402 amt
*= sizeof (unsigned long int);
5403 counts
= (unsigned long int *) bfd_malloc (amt
);
5407 /* Compute the "optimal" size for the hash table. The criteria is a
5408 minimal chain length. The minor criteria is (of course) the size
5410 for (i
= minsize
; i
< maxsize
; ++i
)
5412 /* Walk through the array of hashcodes and count the collisions. */
5413 BFD_HOST_U_64_BIT max
;
5414 unsigned long int j
;
5415 unsigned long int fact
;
5417 if (gnu_hash
&& (i
& 31) == 0)
5420 memset (counts
, '\0', i
* sizeof (unsigned long int));
5422 /* Determine how often each hash bucket is used. */
5423 for (j
= 0; j
< nsyms
; ++j
)
5424 ++counts
[hashcodes
[j
] % i
];
5426 /* For the weight function we need some information about the
5427 pagesize on the target. This is information need not be 100%
5428 accurate. Since this information is not available (so far) we
5429 define it here to a reasonable default value. If it is crucial
5430 to have a better value some day simply define this value. */
5431 # ifndef BFD_TARGET_PAGESIZE
5432 # define BFD_TARGET_PAGESIZE (4096)
5435 /* We in any case need 2 + DYNSYMCOUNT entries for the size values
5437 max
= (2 + dynsymcount
) * bed
->s
->sizeof_hash_entry
;
5440 /* Variant 1: optimize for short chains. We add the squares
5441 of all the chain lengths (which favors many small chain
5442 over a few long chains). */
5443 for (j
= 0; j
< i
; ++j
)
5444 max
+= counts
[j
] * counts
[j
];
5446 /* This adds penalties for the overall size of the table. */
5447 fact
= i
/ (BFD_TARGET_PAGESIZE
/ bed
->s
->sizeof_hash_entry
) + 1;
5450 /* Variant 2: Optimize a lot more for small table. Here we
5451 also add squares of the size but we also add penalties for
5452 empty slots (the +1 term). */
5453 for (j
= 0; j
< i
; ++j
)
5454 max
+= (1 + counts
[j
]) * (1 + counts
[j
]);
5456 /* The overall size of the table is considered, but not as
5457 strong as in variant 1, where it is squared. */
5458 fact
= i
/ (BFD_TARGET_PAGESIZE
/ bed
->s
->sizeof_hash_entry
) + 1;
5462 /* Compare with current best results. */
5463 if (max
< best_chlen
)
5467 no_improvement_count
= 0;
5469 /* PR 11843: Avoid futile long searches for the best bucket size
5470 when there are a large number of symbols. */
5471 else if (++no_improvement_count
== 100)
5478 #endif /* defined (BFD_HOST_U_64_BIT) */
5480 /* This is the fallback solution if no 64bit type is available or if we
5481 are not supposed to spend much time on optimizations. We select the
5482 bucket count using a fixed set of numbers. */
5483 for (i
= 0; elf_buckets
[i
] != 0; i
++)
5485 best_size
= elf_buckets
[i
];
5486 if (nsyms
< elf_buckets
[i
+ 1])
5489 if (gnu_hash
&& best_size
< 2)
5496 /* Size any SHT_GROUP section for ld -r. */
5499 _bfd_elf_size_group_sections (struct bfd_link_info
*info
)
5503 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
5504 if (bfd_get_flavour (ibfd
) == bfd_target_elf_flavour
5505 && !_bfd_elf_fixup_group_sections (ibfd
, bfd_abs_section_ptr
))
5510 /* Set up the sizes and contents of the ELF dynamic sections. This is
5511 called by the ELF linker emulation before_allocation routine. We
5512 must set the sizes of the sections before the linker sets the
5513 addresses of the various sections. */
5516 bfd_elf_size_dynamic_sections (bfd
*output_bfd
,
5519 const char *filter_shlib
,
5521 const char *depaudit
,
5522 const char * const *auxiliary_filters
,
5523 struct bfd_link_info
*info
,
5524 asection
**sinterpptr
)
5526 bfd_size_type soname_indx
;
5528 const struct elf_backend_data
*bed
;
5529 struct elf_info_failed asvinfo
;
5533 soname_indx
= (bfd_size_type
) -1;
5535 if (!is_elf_hash_table (info
->hash
))
5538 bed
= get_elf_backend_data (output_bfd
);
5539 if (info
->execstack
)
5540 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5541 else if (info
->noexecstack
)
5542 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
;
5546 asection
*notesec
= NULL
;
5549 for (inputobj
= info
->input_bfds
;
5551 inputobj
= inputobj
->link_next
)
5556 & (DYNAMIC
| EXEC_P
| BFD_PLUGIN
| BFD_LINKER_CREATED
))
5558 s
= bfd_get_section_by_name (inputobj
, ".note.GNU-stack");
5561 if (s
->flags
& SEC_CODE
)
5565 else if (bed
->default_execstack
)
5570 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| exec
;
5571 if (exec
&& info
->relocatable
5572 && notesec
->output_section
!= bfd_abs_section_ptr
)
5573 notesec
->output_section
->flags
|= SEC_CODE
;
5577 /* Any syms created from now on start with -1 in
5578 got.refcount/offset and plt.refcount/offset. */
5579 elf_hash_table (info
)->init_got_refcount
5580 = elf_hash_table (info
)->init_got_offset
;
5581 elf_hash_table (info
)->init_plt_refcount
5582 = elf_hash_table (info
)->init_plt_offset
;
5584 if (info
->relocatable
5585 && !_bfd_elf_size_group_sections (info
))
5588 /* The backend may have to create some sections regardless of whether
5589 we're dynamic or not. */
5590 if (bed
->elf_backend_always_size_sections
5591 && ! (*bed
->elf_backend_always_size_sections
) (output_bfd
, info
))
5594 dynobj
= elf_hash_table (info
)->dynobj
;
5596 if (dynobj
!= NULL
&& elf_hash_table (info
)->dynamic_sections_created
)
5598 struct elf_info_failed eif
;
5599 struct elf_link_hash_entry
*h
;
5601 struct bfd_elf_version_tree
*t
;
5602 struct bfd_elf_version_expr
*d
;
5604 bfd_boolean all_defined
;
5606 *sinterpptr
= bfd_get_section_by_name (dynobj
, ".interp");
5607 BFD_ASSERT (*sinterpptr
!= NULL
|| !info
->executable
);
5611 soname_indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5613 if (soname_indx
== (bfd_size_type
) -1
5614 || !_bfd_elf_add_dynamic_entry (info
, DT_SONAME
, soname_indx
))
5620 if (!_bfd_elf_add_dynamic_entry (info
, DT_SYMBOLIC
, 0))
5622 info
->flags
|= DF_SYMBOLIC
;
5629 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
, rpath
,
5631 if (indx
== (bfd_size_type
) -1
5632 || !_bfd_elf_add_dynamic_entry (info
, DT_RPATH
, indx
))
5635 if (info
->new_dtags
)
5637 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
, indx
);
5638 if (!_bfd_elf_add_dynamic_entry (info
, DT_RUNPATH
, indx
))
5643 if (filter_shlib
!= NULL
)
5647 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5648 filter_shlib
, TRUE
);
5649 if (indx
== (bfd_size_type
) -1
5650 || !_bfd_elf_add_dynamic_entry (info
, DT_FILTER
, indx
))
5654 if (auxiliary_filters
!= NULL
)
5656 const char * const *p
;
5658 for (p
= auxiliary_filters
; *p
!= NULL
; p
++)
5662 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5664 if (indx
== (bfd_size_type
) -1
5665 || !_bfd_elf_add_dynamic_entry (info
, DT_AUXILIARY
, indx
))
5674 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
, audit
,
5676 if (indx
== (bfd_size_type
) -1
5677 || !_bfd_elf_add_dynamic_entry (info
, DT_AUDIT
, indx
))
5681 if (depaudit
!= NULL
)
5685 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
, depaudit
,
5687 if (indx
== (bfd_size_type
) -1
5688 || !_bfd_elf_add_dynamic_entry (info
, DT_DEPAUDIT
, indx
))
5695 /* If we are supposed to export all symbols into the dynamic symbol
5696 table (this is not the normal case), then do so. */
5697 if (info
->export_dynamic
5698 || (info
->executable
&& info
->dynamic
))
5700 elf_link_hash_traverse (elf_hash_table (info
),
5701 _bfd_elf_export_symbol
,
5707 /* Make all global versions with definition. */
5708 for (t
= info
->version_info
; t
!= NULL
; t
= t
->next
)
5709 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
5710 if (!d
->symver
&& d
->literal
)
5712 const char *verstr
, *name
;
5713 size_t namelen
, verlen
, newlen
;
5714 char *newname
, *p
, leading_char
;
5715 struct elf_link_hash_entry
*newh
;
5717 leading_char
= bfd_get_symbol_leading_char (output_bfd
);
5719 namelen
= strlen (name
) + (leading_char
!= '\0');
5721 verlen
= strlen (verstr
);
5722 newlen
= namelen
+ verlen
+ 3;
5724 newname
= (char *) bfd_malloc (newlen
);
5725 if (newname
== NULL
)
5727 newname
[0] = leading_char
;
5728 memcpy (newname
+ (leading_char
!= '\0'), name
, namelen
);
5730 /* Check the hidden versioned definition. */
5731 p
= newname
+ namelen
;
5733 memcpy (p
, verstr
, verlen
+ 1);
5734 newh
= elf_link_hash_lookup (elf_hash_table (info
),
5735 newname
, FALSE
, FALSE
,
5738 || (newh
->root
.type
!= bfd_link_hash_defined
5739 && newh
->root
.type
!= bfd_link_hash_defweak
))
5741 /* Check the default versioned definition. */
5743 memcpy (p
, verstr
, verlen
+ 1);
5744 newh
= elf_link_hash_lookup (elf_hash_table (info
),
5745 newname
, FALSE
, FALSE
,
5750 /* Mark this version if there is a definition and it is
5751 not defined in a shared object. */
5753 && !newh
->def_dynamic
5754 && (newh
->root
.type
== bfd_link_hash_defined
5755 || newh
->root
.type
== bfd_link_hash_defweak
))
5759 /* Attach all the symbols to their version information. */
5760 asvinfo
.info
= info
;
5761 asvinfo
.failed
= FALSE
;
5763 elf_link_hash_traverse (elf_hash_table (info
),
5764 _bfd_elf_link_assign_sym_version
,
5769 if (!info
->allow_undefined_version
)
5771 /* Check if all global versions have a definition. */
5773 for (t
= info
->version_info
; t
!= NULL
; t
= t
->next
)
5774 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
5775 if (d
->literal
&& !d
->symver
&& !d
->script
)
5777 (*_bfd_error_handler
)
5778 (_("%s: undefined version: %s"),
5779 d
->pattern
, t
->name
);
5780 all_defined
= FALSE
;
5785 bfd_set_error (bfd_error_bad_value
);
5790 /* Find all symbols which were defined in a dynamic object and make
5791 the backend pick a reasonable value for them. */
5792 elf_link_hash_traverse (elf_hash_table (info
),
5793 _bfd_elf_adjust_dynamic_symbol
,
5798 /* Add some entries to the .dynamic section. We fill in some of the
5799 values later, in bfd_elf_final_link, but we must add the entries
5800 now so that we know the final size of the .dynamic section. */
5802 /* If there are initialization and/or finalization functions to
5803 call then add the corresponding DT_INIT/DT_FINI entries. */
5804 h
= (info
->init_function
5805 ? elf_link_hash_lookup (elf_hash_table (info
),
5806 info
->init_function
, FALSE
,
5813 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT
, 0))
5816 h
= (info
->fini_function
5817 ? elf_link_hash_lookup (elf_hash_table (info
),
5818 info
->fini_function
, FALSE
,
5825 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI
, 0))
5829 s
= bfd_get_section_by_name (output_bfd
, ".preinit_array");
5830 if (s
!= NULL
&& s
->linker_has_input
)
5832 /* DT_PREINIT_ARRAY is not allowed in shared library. */
5833 if (! info
->executable
)
5838 for (sub
= info
->input_bfds
; sub
!= NULL
;
5839 sub
= sub
->link_next
)
5840 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
)
5841 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
5842 if (elf_section_data (o
)->this_hdr
.sh_type
5843 == SHT_PREINIT_ARRAY
)
5845 (*_bfd_error_handler
)
5846 (_("%B: .preinit_array section is not allowed in DSO"),
5851 bfd_set_error (bfd_error_nonrepresentable_section
);
5855 if (!_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAY
, 0)
5856 || !_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAYSZ
, 0))
5859 s
= bfd_get_section_by_name (output_bfd
, ".init_array");
5860 if (s
!= NULL
&& s
->linker_has_input
)
5862 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAY
, 0)
5863 || !_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAYSZ
, 0))
5866 s
= bfd_get_section_by_name (output_bfd
, ".fini_array");
5867 if (s
!= NULL
&& s
->linker_has_input
)
5869 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAY
, 0)
5870 || !_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAYSZ
, 0))
5874 dynstr
= bfd_get_section_by_name (dynobj
, ".dynstr");
5875 /* If .dynstr is excluded from the link, we don't want any of
5876 these tags. Strictly, we should be checking each section
5877 individually; This quick check covers for the case where
5878 someone does a /DISCARD/ : { *(*) }. */
5879 if (dynstr
!= NULL
&& dynstr
->output_section
!= bfd_abs_section_ptr
)
5881 bfd_size_type strsize
;
5883 strsize
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5884 if ((info
->emit_hash
5885 && !_bfd_elf_add_dynamic_entry (info
, DT_HASH
, 0))
5886 || (info
->emit_gnu_hash
5887 && !_bfd_elf_add_dynamic_entry (info
, DT_GNU_HASH
, 0))
5888 || !_bfd_elf_add_dynamic_entry (info
, DT_STRTAB
, 0)
5889 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMTAB
, 0)
5890 || !_bfd_elf_add_dynamic_entry (info
, DT_STRSZ
, strsize
)
5891 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMENT
,
5892 bed
->s
->sizeof_sym
))
5897 /* The backend must work out the sizes of all the other dynamic
5900 && bed
->elf_backend_size_dynamic_sections
!= NULL
5901 && ! (*bed
->elf_backend_size_dynamic_sections
) (output_bfd
, info
))
5904 if (! _bfd_elf_maybe_strip_eh_frame_hdr (info
))
5907 if (dynobj
!= NULL
&& elf_hash_table (info
)->dynamic_sections_created
)
5909 unsigned long section_sym_count
;
5910 struct bfd_elf_version_tree
*verdefs
;
5913 /* Set up the version definition section. */
5914 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
5915 BFD_ASSERT (s
!= NULL
);
5917 /* We may have created additional version definitions if we are
5918 just linking a regular application. */
5919 verdefs
= info
->version_info
;
5921 /* Skip anonymous version tag. */
5922 if (verdefs
!= NULL
&& verdefs
->vernum
== 0)
5923 verdefs
= verdefs
->next
;
5925 if (verdefs
== NULL
&& !info
->create_default_symver
)
5926 s
->flags
|= SEC_EXCLUDE
;
5931 struct bfd_elf_version_tree
*t
;
5933 Elf_Internal_Verdef def
;
5934 Elf_Internal_Verdaux defaux
;
5935 struct bfd_link_hash_entry
*bh
;
5936 struct elf_link_hash_entry
*h
;
5942 /* Make space for the base version. */
5943 size
+= sizeof (Elf_External_Verdef
);
5944 size
+= sizeof (Elf_External_Verdaux
);
5947 /* Make space for the default version. */
5948 if (info
->create_default_symver
)
5950 size
+= sizeof (Elf_External_Verdef
);
5954 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5956 struct bfd_elf_version_deps
*n
;
5958 /* Don't emit base version twice. */
5962 size
+= sizeof (Elf_External_Verdef
);
5963 size
+= sizeof (Elf_External_Verdaux
);
5966 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5967 size
+= sizeof (Elf_External_Verdaux
);
5971 s
->contents
= (unsigned char *) bfd_alloc (output_bfd
, s
->size
);
5972 if (s
->contents
== NULL
&& s
->size
!= 0)
5975 /* Fill in the version definition section. */
5979 def
.vd_version
= VER_DEF_CURRENT
;
5980 def
.vd_flags
= VER_FLG_BASE
;
5983 if (info
->create_default_symver
)
5985 def
.vd_aux
= 2 * sizeof (Elf_External_Verdef
);
5986 def
.vd_next
= sizeof (Elf_External_Verdef
);
5990 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5991 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5992 + sizeof (Elf_External_Verdaux
));
5995 if (soname_indx
!= (bfd_size_type
) -1)
5997 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5999 def
.vd_hash
= bfd_elf_hash (soname
);
6000 defaux
.vda_name
= soname_indx
;
6007 name
= lbasename (output_bfd
->filename
);
6008 def
.vd_hash
= bfd_elf_hash (name
);
6009 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
6011 if (indx
== (bfd_size_type
) -1)
6013 defaux
.vda_name
= indx
;
6015 defaux
.vda_next
= 0;
6017 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
6018 (Elf_External_Verdef
*) p
);
6019 p
+= sizeof (Elf_External_Verdef
);
6020 if (info
->create_default_symver
)
6022 /* Add a symbol representing this version. */
6024 if (! (_bfd_generic_link_add_one_symbol
6025 (info
, dynobj
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
6027 get_elf_backend_data (dynobj
)->collect
, &bh
)))
6029 h
= (struct elf_link_hash_entry
*) bh
;
6032 h
->type
= STT_OBJECT
;
6033 h
->verinfo
.vertree
= NULL
;
6035 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6038 /* Create a duplicate of the base version with the same
6039 aux block, but different flags. */
6042 def
.vd_aux
= sizeof (Elf_External_Verdef
);
6044 def
.vd_next
= (sizeof (Elf_External_Verdef
)
6045 + sizeof (Elf_External_Verdaux
));
6048 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
6049 (Elf_External_Verdef
*) p
);
6050 p
+= sizeof (Elf_External_Verdef
);
6052 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
6053 (Elf_External_Verdaux
*) p
);
6054 p
+= sizeof (Elf_External_Verdaux
);
6056 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
6059 struct bfd_elf_version_deps
*n
;
6061 /* Don't emit the base version twice. */
6066 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
6069 /* Add a symbol representing this version. */
6071 if (! (_bfd_generic_link_add_one_symbol
6072 (info
, dynobj
, t
->name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
6074 get_elf_backend_data (dynobj
)->collect
, &bh
)))
6076 h
= (struct elf_link_hash_entry
*) bh
;
6079 h
->type
= STT_OBJECT
;
6080 h
->verinfo
.vertree
= t
;
6082 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6085 def
.vd_version
= VER_DEF_CURRENT
;
6087 if (t
->globals
.list
== NULL
6088 && t
->locals
.list
== NULL
6090 def
.vd_flags
|= VER_FLG_WEAK
;
6091 def
.vd_ndx
= t
->vernum
+ (info
->create_default_symver
? 2 : 1);
6092 def
.vd_cnt
= cdeps
+ 1;
6093 def
.vd_hash
= bfd_elf_hash (t
->name
);
6094 def
.vd_aux
= sizeof (Elf_External_Verdef
);
6097 /* If a basever node is next, it *must* be the last node in
6098 the chain, otherwise Verdef construction breaks. */
6099 if (t
->next
!= NULL
&& t
->next
->vernum
== 0)
6100 BFD_ASSERT (t
->next
->next
== NULL
);
6102 if (t
->next
!= NULL
&& t
->next
->vernum
!= 0)
6103 def
.vd_next
= (sizeof (Elf_External_Verdef
)
6104 + (cdeps
+ 1) * sizeof (Elf_External_Verdaux
));
6106 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
6107 (Elf_External_Verdef
*) p
);
6108 p
+= sizeof (Elf_External_Verdef
);
6110 defaux
.vda_name
= h
->dynstr_index
;
6111 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
6113 defaux
.vda_next
= 0;
6114 if (t
->deps
!= NULL
)
6115 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
6116 t
->name_indx
= defaux
.vda_name
;
6118 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
6119 (Elf_External_Verdaux
*) p
);
6120 p
+= sizeof (Elf_External_Verdaux
);
6122 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
6124 if (n
->version_needed
== NULL
)
6126 /* This can happen if there was an error in the
6128 defaux
.vda_name
= 0;
6132 defaux
.vda_name
= n
->version_needed
->name_indx
;
6133 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
6136 if (n
->next
== NULL
)
6137 defaux
.vda_next
= 0;
6139 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
6141 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
6142 (Elf_External_Verdaux
*) p
);
6143 p
+= sizeof (Elf_External_Verdaux
);
6147 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERDEF
, 0)
6148 || !_bfd_elf_add_dynamic_entry (info
, DT_VERDEFNUM
, cdefs
))
6151 elf_tdata (output_bfd
)->cverdefs
= cdefs
;
6154 if ((info
->new_dtags
&& info
->flags
) || (info
->flags
& DF_STATIC_TLS
))
6156 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS
, info
->flags
))
6159 else if (info
->flags
& DF_BIND_NOW
)
6161 if (!_bfd_elf_add_dynamic_entry (info
, DT_BIND_NOW
, 0))
6167 if (info
->executable
)
6168 info
->flags_1
&= ~ (DF_1_INITFIRST
6171 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS_1
, info
->flags_1
))
6175 /* Work out the size of the version reference section. */
6177 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
6178 BFD_ASSERT (s
!= NULL
);
6180 struct elf_find_verdep_info sinfo
;
6183 sinfo
.vers
= elf_tdata (output_bfd
)->cverdefs
;
6184 if (sinfo
.vers
== 0)
6186 sinfo
.failed
= FALSE
;
6188 elf_link_hash_traverse (elf_hash_table (info
),
6189 _bfd_elf_link_find_version_dependencies
,
6194 if (elf_tdata (output_bfd
)->verref
== NULL
)
6195 s
->flags
|= SEC_EXCLUDE
;
6198 Elf_Internal_Verneed
*t
;
6203 /* Build the version dependency section. */
6206 for (t
= elf_tdata (output_bfd
)->verref
;
6210 Elf_Internal_Vernaux
*a
;
6212 size
+= sizeof (Elf_External_Verneed
);
6214 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
6215 size
+= sizeof (Elf_External_Vernaux
);
6219 s
->contents
= (unsigned char *) bfd_alloc (output_bfd
, s
->size
);
6220 if (s
->contents
== NULL
)
6224 for (t
= elf_tdata (output_bfd
)->verref
;
6229 Elf_Internal_Vernaux
*a
;
6233 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
6236 t
->vn_version
= VER_NEED_CURRENT
;
6238 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
6239 elf_dt_name (t
->vn_bfd
) != NULL
6240 ? elf_dt_name (t
->vn_bfd
)
6241 : lbasename (t
->vn_bfd
->filename
),
6243 if (indx
== (bfd_size_type
) -1)
6246 t
->vn_aux
= sizeof (Elf_External_Verneed
);
6247 if (t
->vn_nextref
== NULL
)
6250 t
->vn_next
= (sizeof (Elf_External_Verneed
)
6251 + caux
* sizeof (Elf_External_Vernaux
));
6253 _bfd_elf_swap_verneed_out (output_bfd
, t
,
6254 (Elf_External_Verneed
*) p
);
6255 p
+= sizeof (Elf_External_Verneed
);
6257 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
6259 a
->vna_hash
= bfd_elf_hash (a
->vna_nodename
);
6260 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
6261 a
->vna_nodename
, FALSE
);
6262 if (indx
== (bfd_size_type
) -1)
6265 if (a
->vna_nextptr
== NULL
)
6268 a
->vna_next
= sizeof (Elf_External_Vernaux
);
6270 _bfd_elf_swap_vernaux_out (output_bfd
, a
,
6271 (Elf_External_Vernaux
*) p
);
6272 p
+= sizeof (Elf_External_Vernaux
);
6276 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERNEED
, 0)
6277 || !_bfd_elf_add_dynamic_entry (info
, DT_VERNEEDNUM
, crefs
))
6280 elf_tdata (output_bfd
)->cverrefs
= crefs
;
6284 if ((elf_tdata (output_bfd
)->cverrefs
== 0
6285 && elf_tdata (output_bfd
)->cverdefs
== 0)
6286 || _bfd_elf_link_renumber_dynsyms (output_bfd
, info
,
6287 §ion_sym_count
) == 0)
6289 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
6290 s
->flags
|= SEC_EXCLUDE
;
6296 /* Find the first non-excluded output section. We'll use its
6297 section symbol for some emitted relocs. */
6299 _bfd_elf_init_1_index_section (bfd
*output_bfd
, struct bfd_link_info
*info
)
6303 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6304 if ((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
)) == SEC_ALLOC
6305 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6307 elf_hash_table (info
)->text_index_section
= s
;
6312 /* Find two non-excluded output sections, one for code, one for data.
6313 We'll use their section symbols for some emitted relocs. */
6315 _bfd_elf_init_2_index_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
6319 /* Data first, since setting text_index_section changes
6320 _bfd_elf_link_omit_section_dynsym. */
6321 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6322 if (((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
6323 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6325 elf_hash_table (info
)->data_index_section
= s
;
6329 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6330 if (((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
| SEC_READONLY
))
6331 == (SEC_ALLOC
| SEC_READONLY
))
6332 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6334 elf_hash_table (info
)->text_index_section
= s
;
6338 if (elf_hash_table (info
)->text_index_section
== NULL
)
6339 elf_hash_table (info
)->text_index_section
6340 = elf_hash_table (info
)->data_index_section
;
6344 bfd_elf_size_dynsym_hash_dynstr (bfd
*output_bfd
, struct bfd_link_info
*info
)
6346 const struct elf_backend_data
*bed
;
6348 if (!is_elf_hash_table (info
->hash
))
6351 bed
= get_elf_backend_data (output_bfd
);
6352 (*bed
->elf_backend_init_index_section
) (output_bfd
, info
);
6354 if (elf_hash_table (info
)->dynamic_sections_created
)
6358 bfd_size_type dynsymcount
;
6359 unsigned long section_sym_count
;
6360 unsigned int dtagcount
;
6362 dynobj
= elf_hash_table (info
)->dynobj
;
6364 /* Assign dynsym indicies. In a shared library we generate a
6365 section symbol for each output section, which come first.
6366 Next come all of the back-end allocated local dynamic syms,
6367 followed by the rest of the global symbols. */
6369 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
,
6370 §ion_sym_count
);
6372 /* Work out the size of the symbol version section. */
6373 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
6374 BFD_ASSERT (s
!= NULL
);
6375 if (dynsymcount
!= 0
6376 && (s
->flags
& SEC_EXCLUDE
) == 0)
6378 s
->size
= dynsymcount
* sizeof (Elf_External_Versym
);
6379 s
->contents
= (unsigned char *) bfd_zalloc (output_bfd
, s
->size
);
6380 if (s
->contents
== NULL
)
6383 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERSYM
, 0))
6387 /* Set the size of the .dynsym and .hash sections. We counted
6388 the number of dynamic symbols in elf_link_add_object_symbols.
6389 We will build the contents of .dynsym and .hash when we build
6390 the final symbol table, because until then we do not know the
6391 correct value to give the symbols. We built the .dynstr
6392 section as we went along in elf_link_add_object_symbols. */
6393 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
6394 BFD_ASSERT (s
!= NULL
);
6395 s
->size
= dynsymcount
* bed
->s
->sizeof_sym
;
6397 if (dynsymcount
!= 0)
6399 s
->contents
= (unsigned char *) bfd_alloc (output_bfd
, s
->size
);
6400 if (s
->contents
== NULL
)
6403 /* The first entry in .dynsym is a dummy symbol.
6404 Clear all the section syms, in case we don't output them all. */
6405 ++section_sym_count
;
6406 memset (s
->contents
, 0, section_sym_count
* bed
->s
->sizeof_sym
);
6409 elf_hash_table (info
)->bucketcount
= 0;
6411 /* Compute the size of the hashing table. As a side effect this
6412 computes the hash values for all the names we export. */
6413 if (info
->emit_hash
)
6415 unsigned long int *hashcodes
;
6416 struct hash_codes_info hashinf
;
6418 unsigned long int nsyms
;
6420 size_t hash_entry_size
;
6422 /* Compute the hash values for all exported symbols. At the same
6423 time store the values in an array so that we could use them for
6425 amt
= dynsymcount
* sizeof (unsigned long int);
6426 hashcodes
= (unsigned long int *) bfd_malloc (amt
);
6427 if (hashcodes
== NULL
)
6429 hashinf
.hashcodes
= hashcodes
;
6430 hashinf
.error
= FALSE
;
6432 /* Put all hash values in HASHCODES. */
6433 elf_link_hash_traverse (elf_hash_table (info
),
6434 elf_collect_hash_codes
, &hashinf
);
6441 nsyms
= hashinf
.hashcodes
- hashcodes
;
6443 = compute_bucket_count (info
, hashcodes
, nsyms
, 0);
6446 if (bucketcount
== 0)
6449 elf_hash_table (info
)->bucketcount
= bucketcount
;
6451 s
= bfd_get_section_by_name (dynobj
, ".hash");
6452 BFD_ASSERT (s
!= NULL
);
6453 hash_entry_size
= elf_section_data (s
)->this_hdr
.sh_entsize
;
6454 s
->size
= ((2 + bucketcount
+ dynsymcount
) * hash_entry_size
);
6455 s
->contents
= (unsigned char *) bfd_zalloc (output_bfd
, s
->size
);
6456 if (s
->contents
== NULL
)
6459 bfd_put (8 * hash_entry_size
, output_bfd
, bucketcount
, s
->contents
);
6460 bfd_put (8 * hash_entry_size
, output_bfd
, dynsymcount
,
6461 s
->contents
+ hash_entry_size
);
6464 if (info
->emit_gnu_hash
)
6467 unsigned char *contents
;
6468 struct collect_gnu_hash_codes cinfo
;
6472 memset (&cinfo
, 0, sizeof (cinfo
));
6474 /* Compute the hash values for all exported symbols. At the same
6475 time store the values in an array so that we could use them for
6477 amt
= dynsymcount
* 2 * sizeof (unsigned long int);
6478 cinfo
.hashcodes
= (long unsigned int *) bfd_malloc (amt
);
6479 if (cinfo
.hashcodes
== NULL
)
6482 cinfo
.hashval
= cinfo
.hashcodes
+ dynsymcount
;
6483 cinfo
.min_dynindx
= -1;
6484 cinfo
.output_bfd
= output_bfd
;
6487 /* Put all hash values in HASHCODES. */
6488 elf_link_hash_traverse (elf_hash_table (info
),
6489 elf_collect_gnu_hash_codes
, &cinfo
);
6492 free (cinfo
.hashcodes
);
6497 = compute_bucket_count (info
, cinfo
.hashcodes
, cinfo
.nsyms
, 1);
6499 if (bucketcount
== 0)
6501 free (cinfo
.hashcodes
);
6505 s
= bfd_get_section_by_name (dynobj
, ".gnu.hash");
6506 BFD_ASSERT (s
!= NULL
);
6508 if (cinfo
.nsyms
== 0)
6510 /* Empty .gnu.hash section is special. */
6511 BFD_ASSERT (cinfo
.min_dynindx
== -1);
6512 free (cinfo
.hashcodes
);
6513 s
->size
= 5 * 4 + bed
->s
->arch_size
/ 8;
6514 contents
= (unsigned char *) bfd_zalloc (output_bfd
, s
->size
);
6515 if (contents
== NULL
)
6517 s
->contents
= contents
;
6518 /* 1 empty bucket. */
6519 bfd_put_32 (output_bfd
, 1, contents
);
6520 /* SYMIDX above the special symbol 0. */
6521 bfd_put_32 (output_bfd
, 1, contents
+ 4);
6522 /* Just one word for bitmask. */
6523 bfd_put_32 (output_bfd
, 1, contents
+ 8);
6524 /* Only hash fn bloom filter. */
6525 bfd_put_32 (output_bfd
, 0, contents
+ 12);
6526 /* No hashes are valid - empty bitmask. */
6527 bfd_put (bed
->s
->arch_size
, output_bfd
, 0, contents
+ 16);
6528 /* No hashes in the only bucket. */
6529 bfd_put_32 (output_bfd
, 0,
6530 contents
+ 16 + bed
->s
->arch_size
/ 8);
6534 unsigned long int maskwords
, maskbitslog2
, x
;
6535 BFD_ASSERT (cinfo
.min_dynindx
!= -1);
6539 while ((x
>>= 1) != 0)
6541 if (maskbitslog2
< 3)
6543 else if ((1 << (maskbitslog2
- 2)) & cinfo
.nsyms
)
6544 maskbitslog2
= maskbitslog2
+ 3;
6546 maskbitslog2
= maskbitslog2
+ 2;
6547 if (bed
->s
->arch_size
== 64)
6549 if (maskbitslog2
== 5)
6555 cinfo
.mask
= (1 << cinfo
.shift1
) - 1;
6556 cinfo
.shift2
= maskbitslog2
;
6557 cinfo
.maskbits
= 1 << maskbitslog2
;
6558 maskwords
= 1 << (maskbitslog2
- cinfo
.shift1
);
6559 amt
= bucketcount
* sizeof (unsigned long int) * 2;
6560 amt
+= maskwords
* sizeof (bfd_vma
);
6561 cinfo
.bitmask
= (bfd_vma
*) bfd_malloc (amt
);
6562 if (cinfo
.bitmask
== NULL
)
6564 free (cinfo
.hashcodes
);
6568 cinfo
.counts
= (long unsigned int *) (cinfo
.bitmask
+ maskwords
);
6569 cinfo
.indx
= cinfo
.counts
+ bucketcount
;
6570 cinfo
.symindx
= dynsymcount
- cinfo
.nsyms
;
6571 memset (cinfo
.bitmask
, 0, maskwords
* sizeof (bfd_vma
));
6573 /* Determine how often each hash bucket is used. */
6574 memset (cinfo
.counts
, 0, bucketcount
* sizeof (cinfo
.counts
[0]));
6575 for (i
= 0; i
< cinfo
.nsyms
; ++i
)
6576 ++cinfo
.counts
[cinfo
.hashcodes
[i
] % bucketcount
];
6578 for (i
= 0, cnt
= cinfo
.symindx
; i
< bucketcount
; ++i
)
6579 if (cinfo
.counts
[i
] != 0)
6581 cinfo
.indx
[i
] = cnt
;
6582 cnt
+= cinfo
.counts
[i
];
6584 BFD_ASSERT (cnt
== dynsymcount
);
6585 cinfo
.bucketcount
= bucketcount
;
6586 cinfo
.local_indx
= cinfo
.min_dynindx
;
6588 s
->size
= (4 + bucketcount
+ cinfo
.nsyms
) * 4;
6589 s
->size
+= cinfo
.maskbits
/ 8;
6590 contents
= (unsigned char *) bfd_zalloc (output_bfd
, s
->size
);
6591 if (contents
== NULL
)
6593 free (cinfo
.bitmask
);
6594 free (cinfo
.hashcodes
);
6598 s
->contents
= contents
;
6599 bfd_put_32 (output_bfd
, bucketcount
, contents
);
6600 bfd_put_32 (output_bfd
, cinfo
.symindx
, contents
+ 4);
6601 bfd_put_32 (output_bfd
, maskwords
, contents
+ 8);
6602 bfd_put_32 (output_bfd
, cinfo
.shift2
, contents
+ 12);
6603 contents
+= 16 + cinfo
.maskbits
/ 8;
6605 for (i
= 0; i
< bucketcount
; ++i
)
6607 if (cinfo
.counts
[i
] == 0)
6608 bfd_put_32 (output_bfd
, 0, contents
);
6610 bfd_put_32 (output_bfd
, cinfo
.indx
[i
], contents
);
6614 cinfo
.contents
= contents
;
6616 /* Renumber dynamic symbols, populate .gnu.hash section. */
6617 elf_link_hash_traverse (elf_hash_table (info
),
6618 elf_renumber_gnu_hash_syms
, &cinfo
);
6620 contents
= s
->contents
+ 16;
6621 for (i
= 0; i
< maskwords
; ++i
)
6623 bfd_put (bed
->s
->arch_size
, output_bfd
, cinfo
.bitmask
[i
],
6625 contents
+= bed
->s
->arch_size
/ 8;
6628 free (cinfo
.bitmask
);
6629 free (cinfo
.hashcodes
);
6633 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
6634 BFD_ASSERT (s
!= NULL
);
6636 elf_finalize_dynstr (output_bfd
, info
);
6638 s
->size
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
6640 for (dtagcount
= 0; dtagcount
<= info
->spare_dynamic_tags
; ++dtagcount
)
6641 if (!_bfd_elf_add_dynamic_entry (info
, DT_NULL
, 0))
6648 /* Make sure sec_info_type is cleared if sec_info is cleared too. */
6651 merge_sections_remove_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
6654 BFD_ASSERT (sec
->sec_info_type
== SEC_INFO_TYPE_MERGE
);
6655 sec
->sec_info_type
= SEC_INFO_TYPE_NONE
;
6658 /* Finish SHF_MERGE section merging. */
6661 _bfd_elf_merge_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6666 if (!is_elf_hash_table (info
->hash
))
6669 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
6670 if ((ibfd
->flags
& DYNAMIC
) == 0)
6671 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
6672 if ((sec
->flags
& SEC_MERGE
) != 0
6673 && !bfd_is_abs_section (sec
->output_section
))
6675 struct bfd_elf_section_data
*secdata
;
6677 secdata
= elf_section_data (sec
);
6678 if (! _bfd_add_merge_section (abfd
,
6679 &elf_hash_table (info
)->merge_info
,
6680 sec
, &secdata
->sec_info
))
6682 else if (secdata
->sec_info
)
6683 sec
->sec_info_type
= SEC_INFO_TYPE_MERGE
;
6686 if (elf_hash_table (info
)->merge_info
!= NULL
)
6687 _bfd_merge_sections (abfd
, info
, elf_hash_table (info
)->merge_info
,
6688 merge_sections_remove_hook
);
6692 /* Create an entry in an ELF linker hash table. */
6694 struct bfd_hash_entry
*
6695 _bfd_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
6696 struct bfd_hash_table
*table
,
6699 /* Allocate the structure if it has not already been allocated by a
6703 entry
= (struct bfd_hash_entry
*)
6704 bfd_hash_allocate (table
, sizeof (struct elf_link_hash_entry
));
6709 /* Call the allocation method of the superclass. */
6710 entry
= _bfd_link_hash_newfunc (entry
, table
, string
);
6713 struct elf_link_hash_entry
*ret
= (struct elf_link_hash_entry
*) entry
;
6714 struct elf_link_hash_table
*htab
= (struct elf_link_hash_table
*) table
;
6716 /* Set local fields. */
6719 ret
->got
= htab
->init_got_refcount
;
6720 ret
->plt
= htab
->init_plt_refcount
;
6721 memset (&ret
->size
, 0, (sizeof (struct elf_link_hash_entry
)
6722 - offsetof (struct elf_link_hash_entry
, size
)));
6723 /* Assume that we have been called by a non-ELF symbol reader.
6724 This flag is then reset by the code which reads an ELF input
6725 file. This ensures that a symbol created by a non-ELF symbol
6726 reader will have the flag set correctly. */
6733 /* Copy data from an indirect symbol to its direct symbol, hiding the
6734 old indirect symbol. Also used for copying flags to a weakdef. */
6737 _bfd_elf_link_hash_copy_indirect (struct bfd_link_info
*info
,
6738 struct elf_link_hash_entry
*dir
,
6739 struct elf_link_hash_entry
*ind
)
6741 struct elf_link_hash_table
*htab
;
6743 /* Copy down any references that we may have already seen to the
6744 symbol which just became indirect. */
6746 dir
->ref_dynamic
|= ind
->ref_dynamic
;
6747 dir
->ref_regular
|= ind
->ref_regular
;
6748 dir
->ref_regular_nonweak
|= ind
->ref_regular_nonweak
;
6749 dir
->non_got_ref
|= ind
->non_got_ref
;
6750 dir
->needs_plt
|= ind
->needs_plt
;
6751 dir
->pointer_equality_needed
|= ind
->pointer_equality_needed
;
6753 if (ind
->root
.type
!= bfd_link_hash_indirect
)
6756 /* Copy over the global and procedure linkage table refcount entries.
6757 These may have been already set up by a check_relocs routine. */
6758 htab
= elf_hash_table (info
);
6759 if (ind
->got
.refcount
> htab
->init_got_refcount
.refcount
)
6761 if (dir
->got
.refcount
< 0)
6762 dir
->got
.refcount
= 0;
6763 dir
->got
.refcount
+= ind
->got
.refcount
;
6764 ind
->got
.refcount
= htab
->init_got_refcount
.refcount
;
6767 if (ind
->plt
.refcount
> htab
->init_plt_refcount
.refcount
)
6769 if (dir
->plt
.refcount
< 0)
6770 dir
->plt
.refcount
= 0;
6771 dir
->plt
.refcount
+= ind
->plt
.refcount
;
6772 ind
->plt
.refcount
= htab
->init_plt_refcount
.refcount
;
6775 if (ind
->dynindx
!= -1)
6777 if (dir
->dynindx
!= -1)
6778 _bfd_elf_strtab_delref (htab
->dynstr
, dir
->dynstr_index
);
6779 dir
->dynindx
= ind
->dynindx
;
6780 dir
->dynstr_index
= ind
->dynstr_index
;
6782 ind
->dynstr_index
= 0;
6787 _bfd_elf_link_hash_hide_symbol (struct bfd_link_info
*info
,
6788 struct elf_link_hash_entry
*h
,
6789 bfd_boolean force_local
)
6791 /* STT_GNU_IFUNC symbol must go through PLT. */
6792 if (h
->type
!= STT_GNU_IFUNC
)
6794 h
->plt
= elf_hash_table (info
)->init_plt_offset
;
6799 h
->forced_local
= 1;
6800 if (h
->dynindx
!= -1)
6803 _bfd_elf_strtab_delref (elf_hash_table (info
)->dynstr
,
6809 /* Initialize an ELF linker hash table. */
6812 _bfd_elf_link_hash_table_init
6813 (struct elf_link_hash_table
*table
,
6815 struct bfd_hash_entry
*(*newfunc
) (struct bfd_hash_entry
*,
6816 struct bfd_hash_table
*,
6818 unsigned int entsize
,
6819 enum elf_target_id target_id
)
6822 int can_refcount
= get_elf_backend_data (abfd
)->can_refcount
;
6824 memset (table
, 0, sizeof * table
);
6825 table
->init_got_refcount
.refcount
= can_refcount
- 1;
6826 table
->init_plt_refcount
.refcount
= can_refcount
- 1;
6827 table
->init_got_offset
.offset
= -(bfd_vma
) 1;
6828 table
->init_plt_offset
.offset
= -(bfd_vma
) 1;
6829 /* The first dynamic symbol is a dummy. */
6830 table
->dynsymcount
= 1;
6832 ret
= _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
, entsize
);
6834 table
->root
.type
= bfd_link_elf_hash_table
;
6835 table
->hash_table_id
= target_id
;
6840 /* Create an ELF linker hash table. */
6842 struct bfd_link_hash_table
*
6843 _bfd_elf_link_hash_table_create (bfd
*abfd
)
6845 struct elf_link_hash_table
*ret
;
6846 bfd_size_type amt
= sizeof (struct elf_link_hash_table
);
6848 ret
= (struct elf_link_hash_table
*) bfd_malloc (amt
);
6852 if (! _bfd_elf_link_hash_table_init (ret
, abfd
, _bfd_elf_link_hash_newfunc
,
6853 sizeof (struct elf_link_hash_entry
),
6863 /* This is a hook for the ELF emulation code in the generic linker to
6864 tell the backend linker what file name to use for the DT_NEEDED
6865 entry for a dynamic object. */
6868 bfd_elf_set_dt_needed_name (bfd
*abfd
, const char *name
)
6870 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
6871 && bfd_get_format (abfd
) == bfd_object
)
6872 elf_dt_name (abfd
) = name
;
6876 bfd_elf_get_dyn_lib_class (bfd
*abfd
)
6879 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
6880 && bfd_get_format (abfd
) == bfd_object
)
6881 lib_class
= elf_dyn_lib_class (abfd
);
6888 bfd_elf_set_dyn_lib_class (bfd
*abfd
, enum dynamic_lib_link_class lib_class
)
6890 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
6891 && bfd_get_format (abfd
) == bfd_object
)
6892 elf_dyn_lib_class (abfd
) = lib_class
;
6895 /* Get the list of DT_NEEDED entries for a link. This is a hook for
6896 the linker ELF emulation code. */
6898 struct bfd_link_needed_list
*
6899 bfd_elf_get_needed_list (bfd
*abfd ATTRIBUTE_UNUSED
,
6900 struct bfd_link_info
*info
)
6902 if (! is_elf_hash_table (info
->hash
))
6904 return elf_hash_table (info
)->needed
;
6907 /* Get the list of DT_RPATH/DT_RUNPATH entries for a link. This is a
6908 hook for the linker ELF emulation code. */
6910 struct bfd_link_needed_list
*
6911 bfd_elf_get_runpath_list (bfd
*abfd ATTRIBUTE_UNUSED
,
6912 struct bfd_link_info
*info
)
6914 if (! is_elf_hash_table (info
->hash
))
6916 return elf_hash_table (info
)->runpath
;
6919 /* Get the name actually used for a dynamic object for a link. This
6920 is the SONAME entry if there is one. Otherwise, it is the string
6921 passed to bfd_elf_set_dt_needed_name, or it is the filename. */
6924 bfd_elf_get_dt_soname (bfd
*abfd
)
6926 if (bfd_get_flavour (abfd
) == bfd_target_elf_flavour
6927 && bfd_get_format (abfd
) == bfd_object
)
6928 return elf_dt_name (abfd
);
6932 /* Get the list of DT_NEEDED entries from a BFD. This is a hook for
6933 the ELF linker emulation code. */
6936 bfd_elf_get_bfd_needed_list (bfd
*abfd
,
6937 struct bfd_link_needed_list
**pneeded
)
6940 bfd_byte
*dynbuf
= NULL
;
6941 unsigned int elfsec
;
6942 unsigned long shlink
;
6943 bfd_byte
*extdyn
, *extdynend
;
6945 void (*swap_dyn_in
) (bfd
*, const void *, Elf_Internal_Dyn
*);
6949 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
6950 || bfd_get_format (abfd
) != bfd_object
)
6953 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6954 if (s
== NULL
|| s
->size
== 0)
6957 if (!bfd_malloc_and_get_section (abfd
, s
, &dynbuf
))
6960 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
6961 if (elfsec
== SHN_BAD
)
6964 shlink
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
6966 extdynsize
= get_elf_backend_data (abfd
)->s
->sizeof_dyn
;
6967 swap_dyn_in
= get_elf_backend_data (abfd
)->s
->swap_dyn_in
;
6970 extdynend
= extdyn
+ s
->size
;
6971 for (; extdyn
< extdynend
; extdyn
+= extdynsize
)
6973 Elf_Internal_Dyn dyn
;
6975 (*swap_dyn_in
) (abfd
, extdyn
, &dyn
);
6977 if (dyn
.d_tag
== DT_NULL
)
6980 if (dyn
.d_tag
== DT_NEEDED
)
6983 struct bfd_link_needed_list
*l
;
6984 unsigned int tagv
= dyn
.d_un
.d_val
;
6987 string
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
6992 l
= (struct bfd_link_needed_list
*) bfd_alloc (abfd
, amt
);
7013 struct elf_symbuf_symbol
7015 unsigned long st_name
; /* Symbol name, index in string tbl */
7016 unsigned char st_info
; /* Type and binding attributes */
7017 unsigned char st_other
; /* Visibilty, and target specific */
7020 struct elf_symbuf_head
7022 struct elf_symbuf_symbol
*ssym
;
7023 bfd_size_type count
;
7024 unsigned int st_shndx
;
7031 Elf_Internal_Sym
*isym
;
7032 struct elf_symbuf_symbol
*ssym
;
7037 /* Sort references to symbols by ascending section number. */
7040 elf_sort_elf_symbol (const void *arg1
, const void *arg2
)
7042 const Elf_Internal_Sym
*s1
= *(const Elf_Internal_Sym
**) arg1
;
7043 const Elf_Internal_Sym
*s2
= *(const Elf_Internal_Sym
**) arg2
;
7045 return s1
->st_shndx
- s2
->st_shndx
;
7049 elf_sym_name_compare (const void *arg1
, const void *arg2
)
7051 const struct elf_symbol
*s1
= (const struct elf_symbol
*) arg1
;
7052 const struct elf_symbol
*s2
= (const struct elf_symbol
*) arg2
;
7053 return strcmp (s1
->name
, s2
->name
);
7056 static struct elf_symbuf_head
*
7057 elf_create_symbuf (bfd_size_type symcount
, Elf_Internal_Sym
*isymbuf
)
7059 Elf_Internal_Sym
**ind
, **indbufend
, **indbuf
;
7060 struct elf_symbuf_symbol
*ssym
;
7061 struct elf_symbuf_head
*ssymbuf
, *ssymhead
;
7062 bfd_size_type i
, shndx_count
, total_size
;
7064 indbuf
= (Elf_Internal_Sym
**) bfd_malloc2 (symcount
, sizeof (*indbuf
));
7068 for (ind
= indbuf
, i
= 0; i
< symcount
; i
++)
7069 if (isymbuf
[i
].st_shndx
!= SHN_UNDEF
)
7070 *ind
++ = &isymbuf
[i
];
7073 qsort (indbuf
, indbufend
- indbuf
, sizeof (Elf_Internal_Sym
*),
7074 elf_sort_elf_symbol
);
7077 if (indbufend
> indbuf
)
7078 for (ind
= indbuf
, shndx_count
++; ind
< indbufend
- 1; ind
++)
7079 if (ind
[0]->st_shndx
!= ind
[1]->st_shndx
)
7082 total_size
= ((shndx_count
+ 1) * sizeof (*ssymbuf
)
7083 + (indbufend
- indbuf
) * sizeof (*ssym
));
7084 ssymbuf
= (struct elf_symbuf_head
*) bfd_malloc (total_size
);
7085 if (ssymbuf
== NULL
)
7091 ssym
= (struct elf_symbuf_symbol
*) (ssymbuf
+ shndx_count
+ 1);
7092 ssymbuf
->ssym
= NULL
;
7093 ssymbuf
->count
= shndx_count
;
7094 ssymbuf
->st_shndx
= 0;
7095 for (ssymhead
= ssymbuf
, ind
= indbuf
; ind
< indbufend
; ssym
++, ind
++)
7097 if (ind
== indbuf
|| ssymhead
->st_shndx
!= (*ind
)->st_shndx
)
7100 ssymhead
->ssym
= ssym
;
7101 ssymhead
->count
= 0;
7102 ssymhead
->st_shndx
= (*ind
)->st_shndx
;
7104 ssym
->st_name
= (*ind
)->st_name
;
7105 ssym
->st_info
= (*ind
)->st_info
;
7106 ssym
->st_other
= (*ind
)->st_other
;
7109 BFD_ASSERT ((bfd_size_type
) (ssymhead
- ssymbuf
) == shndx_count
7110 && (((bfd_hostptr_t
) ssym
- (bfd_hostptr_t
) ssymbuf
)
7117 /* Check if 2 sections define the same set of local and global
7121 bfd_elf_match_symbols_in_sections (asection
*sec1
, asection
*sec2
,
7122 struct bfd_link_info
*info
)
7125 const struct elf_backend_data
*bed1
, *bed2
;
7126 Elf_Internal_Shdr
*hdr1
, *hdr2
;
7127 bfd_size_type symcount1
, symcount2
;
7128 Elf_Internal_Sym
*isymbuf1
, *isymbuf2
;
7129 struct elf_symbuf_head
*ssymbuf1
, *ssymbuf2
;
7130 Elf_Internal_Sym
*isym
, *isymend
;
7131 struct elf_symbol
*symtable1
= NULL
, *symtable2
= NULL
;
7132 bfd_size_type count1
, count2
, i
;
7133 unsigned int shndx1
, shndx2
;
7139 /* Both sections have to be in ELF. */
7140 if (bfd_get_flavour (bfd1
) != bfd_target_elf_flavour
7141 || bfd_get_flavour (bfd2
) != bfd_target_elf_flavour
)
7144 if (elf_section_type (sec1
) != elf_section_type (sec2
))
7147 shndx1
= _bfd_elf_section_from_bfd_section (bfd1
, sec1
);
7148 shndx2
= _bfd_elf_section_from_bfd_section (bfd2
, sec2
);
7149 if (shndx1
== SHN_BAD
|| shndx2
== SHN_BAD
)
7152 bed1
= get_elf_backend_data (bfd1
);
7153 bed2
= get_elf_backend_data (bfd2
);
7154 hdr1
= &elf_tdata (bfd1
)->symtab_hdr
;
7155 symcount1
= hdr1
->sh_size
/ bed1
->s
->sizeof_sym
;
7156 hdr2
= &elf_tdata (bfd2
)->symtab_hdr
;
7157 symcount2
= hdr2
->sh_size
/ bed2
->s
->sizeof_sym
;
7159 if (symcount1
== 0 || symcount2
== 0)
7165 ssymbuf1
= (struct elf_symbuf_head
*) elf_tdata (bfd1
)->symbuf
;
7166 ssymbuf2
= (struct elf_symbuf_head
*) elf_tdata (bfd2
)->symbuf
;
7168 if (ssymbuf1
== NULL
)
7170 isymbuf1
= bfd_elf_get_elf_syms (bfd1
, hdr1
, symcount1
, 0,
7172 if (isymbuf1
== NULL
)
7175 if (!info
->reduce_memory_overheads
)
7176 elf_tdata (bfd1
)->symbuf
= ssymbuf1
7177 = elf_create_symbuf (symcount1
, isymbuf1
);
7180 if (ssymbuf1
== NULL
|| ssymbuf2
== NULL
)
7182 isymbuf2
= bfd_elf_get_elf_syms (bfd2
, hdr2
, symcount2
, 0,
7184 if (isymbuf2
== NULL
)
7187 if (ssymbuf1
!= NULL
&& !info
->reduce_memory_overheads
)
7188 elf_tdata (bfd2
)->symbuf
= ssymbuf2
7189 = elf_create_symbuf (symcount2
, isymbuf2
);
7192 if (ssymbuf1
!= NULL
&& ssymbuf2
!= NULL
)
7194 /* Optimized faster version. */
7195 bfd_size_type lo
, hi
, mid
;
7196 struct elf_symbol
*symp
;
7197 struct elf_symbuf_symbol
*ssym
, *ssymend
;
7200 hi
= ssymbuf1
->count
;
7205 mid
= (lo
+ hi
) / 2;
7206 if (shndx1
< ssymbuf1
[mid
].st_shndx
)
7208 else if (shndx1
> ssymbuf1
[mid
].st_shndx
)
7212 count1
= ssymbuf1
[mid
].count
;
7219 hi
= ssymbuf2
->count
;
7224 mid
= (lo
+ hi
) / 2;
7225 if (shndx2
< ssymbuf2
[mid
].st_shndx
)
7227 else if (shndx2
> ssymbuf2
[mid
].st_shndx
)
7231 count2
= ssymbuf2
[mid
].count
;
7237 if (count1
== 0 || count2
== 0 || count1
!= count2
)
7240 symtable1
= (struct elf_symbol
*)
7241 bfd_malloc (count1
* sizeof (struct elf_symbol
));
7242 symtable2
= (struct elf_symbol
*)
7243 bfd_malloc (count2
* sizeof (struct elf_symbol
));
7244 if (symtable1
== NULL
|| symtable2
== NULL
)
7248 for (ssym
= ssymbuf1
->ssym
, ssymend
= ssym
+ count1
;
7249 ssym
< ssymend
; ssym
++, symp
++)
7251 symp
->u
.ssym
= ssym
;
7252 symp
->name
= bfd_elf_string_from_elf_section (bfd1
,
7258 for (ssym
= ssymbuf2
->ssym
, ssymend
= ssym
+ count2
;
7259 ssym
< ssymend
; ssym
++, symp
++)
7261 symp
->u
.ssym
= ssym
;
7262 symp
->name
= bfd_elf_string_from_elf_section (bfd2
,
7267 /* Sort symbol by name. */
7268 qsort (symtable1
, count1
, sizeof (struct elf_symbol
),
7269 elf_sym_name_compare
);
7270 qsort (symtable2
, count1
, sizeof (struct elf_symbol
),
7271 elf_sym_name_compare
);
7273 for (i
= 0; i
< count1
; i
++)
7274 /* Two symbols must have the same binding, type and name. */
7275 if (symtable1
[i
].u
.ssym
->st_info
!= symtable2
[i
].u
.ssym
->st_info
7276 || symtable1
[i
].u
.ssym
->st_other
!= symtable2
[i
].u
.ssym
->st_other
7277 || strcmp (symtable1
[i
].name
, symtable2
[i
].name
) != 0)
7284 symtable1
= (struct elf_symbol
*)
7285 bfd_malloc (symcount1
* sizeof (struct elf_symbol
));
7286 symtable2
= (struct elf_symbol
*)
7287 bfd_malloc (symcount2
* sizeof (struct elf_symbol
));
7288 if (symtable1
== NULL
|| symtable2
== NULL
)
7291 /* Count definitions in the section. */
7293 for (isym
= isymbuf1
, isymend
= isym
+ symcount1
; isym
< isymend
; isym
++)
7294 if (isym
->st_shndx
== shndx1
)
7295 symtable1
[count1
++].u
.isym
= isym
;
7298 for (isym
= isymbuf2
, isymend
= isym
+ symcount2
; isym
< isymend
; isym
++)
7299 if (isym
->st_shndx
== shndx2
)
7300 symtable2
[count2
++].u
.isym
= isym
;
7302 if (count1
== 0 || count2
== 0 || count1
!= count2
)
7305 for (i
= 0; i
< count1
; i
++)
7307 = bfd_elf_string_from_elf_section (bfd1
, hdr1
->sh_link
,
7308 symtable1
[i
].u
.isym
->st_name
);
7310 for (i
= 0; i
< count2
; i
++)
7312 = bfd_elf_string_from_elf_section (bfd2
, hdr2
->sh_link
,
7313 symtable2
[i
].u
.isym
->st_name
);
7315 /* Sort symbol by name. */
7316 qsort (symtable1
, count1
, sizeof (struct elf_symbol
),
7317 elf_sym_name_compare
);
7318 qsort (symtable2
, count1
, sizeof (struct elf_symbol
),
7319 elf_sym_name_compare
);
7321 for (i
= 0; i
< count1
; i
++)
7322 /* Two symbols must have the same binding, type and name. */
7323 if (symtable1
[i
].u
.isym
->st_info
!= symtable2
[i
].u
.isym
->st_info
7324 || symtable1
[i
].u
.isym
->st_other
!= symtable2
[i
].u
.isym
->st_other
7325 || strcmp (symtable1
[i
].name
, symtable2
[i
].name
) != 0)
7343 /* Return TRUE if 2 section types are compatible. */
7346 _bfd_elf_match_sections_by_type (bfd
*abfd
, const asection
*asec
,
7347 bfd
*bbfd
, const asection
*bsec
)
7351 || abfd
->xvec
->flavour
!= bfd_target_elf_flavour
7352 || bbfd
->xvec
->flavour
!= bfd_target_elf_flavour
)
7355 return elf_section_type (asec
) == elf_section_type (bsec
);
7358 /* Final phase of ELF linker. */
7360 /* A structure we use to avoid passing large numbers of arguments. */
7362 struct elf_final_link_info
7364 /* General link information. */
7365 struct bfd_link_info
*info
;
7368 /* Symbol string table. */
7369 struct bfd_strtab_hash
*symstrtab
;
7370 /* .dynsym section. */
7371 asection
*dynsym_sec
;
7372 /* .hash section. */
7374 /* symbol version section (.gnu.version). */
7375 asection
*symver_sec
;
7376 /* Buffer large enough to hold contents of any section. */
7378 /* Buffer large enough to hold external relocs of any section. */
7379 void *external_relocs
;
7380 /* Buffer large enough to hold internal relocs of any section. */
7381 Elf_Internal_Rela
*internal_relocs
;
7382 /* Buffer large enough to hold external local symbols of any input
7384 bfd_byte
*external_syms
;
7385 /* And a buffer for symbol section indices. */
7386 Elf_External_Sym_Shndx
*locsym_shndx
;
7387 /* Buffer large enough to hold internal local symbols of any input
7389 Elf_Internal_Sym
*internal_syms
;
7390 /* Array large enough to hold a symbol index for each local symbol
7391 of any input BFD. */
7393 /* Array large enough to hold a section pointer for each local
7394 symbol of any input BFD. */
7395 asection
**sections
;
7396 /* Buffer to hold swapped out symbols. */
7398 /* And one for symbol section indices. */
7399 Elf_External_Sym_Shndx
*symshndxbuf
;
7400 /* Number of swapped out symbols in buffer. */
7401 size_t symbuf_count
;
7402 /* Number of symbols which fit in symbuf. */
7404 /* And same for symshndxbuf. */
7405 size_t shndxbuf_size
;
7406 /* Number of STT_FILE syms seen. */
7407 size_t filesym_count
;
7410 /* This struct is used to pass information to elf_link_output_extsym. */
7412 struct elf_outext_info
7415 bfd_boolean localsyms
;
7416 bfd_boolean need_second_pass
;
7417 bfd_boolean second_pass
;
7418 struct elf_final_link_info
*flinfo
;
7422 /* Support for evaluating a complex relocation.
7424 Complex relocations are generalized, self-describing relocations. The
7425 implementation of them consists of two parts: complex symbols, and the
7426 relocations themselves.
7428 The relocations are use a reserved elf-wide relocation type code (R_RELC
7429 external / BFD_RELOC_RELC internal) and an encoding of relocation field
7430 information (start bit, end bit, word width, etc) into the addend. This
7431 information is extracted from CGEN-generated operand tables within gas.
7433 Complex symbols are mangled symbols (BSF_RELC external / STT_RELC
7434 internal) representing prefix-notation expressions, including but not
7435 limited to those sorts of expressions normally encoded as addends in the
7436 addend field. The symbol mangling format is:
7439 | <unary-operator> ':' <node>
7440 | <binary-operator> ':' <node> ':' <node>
7443 <literal> := 's' <digits=N> ':' <N character symbol name>
7444 | 'S' <digits=N> ':' <N character section name>
7448 <binary-operator> := as in C
7449 <unary-operator> := as in C, plus "0-" for unambiguous negation. */
7452 set_symbol_value (bfd
*bfd_with_globals
,
7453 Elf_Internal_Sym
*isymbuf
,
7458 struct elf_link_hash_entry
**sym_hashes
;
7459 struct elf_link_hash_entry
*h
;
7460 size_t extsymoff
= locsymcount
;
7462 if (symidx
< locsymcount
)
7464 Elf_Internal_Sym
*sym
;
7466 sym
= isymbuf
+ symidx
;
7467 if (ELF_ST_BIND (sym
->st_info
) == STB_LOCAL
)
7469 /* It is a local symbol: move it to the
7470 "absolute" section and give it a value. */
7471 sym
->st_shndx
= SHN_ABS
;
7472 sym
->st_value
= val
;
7475 BFD_ASSERT (elf_bad_symtab (bfd_with_globals
));
7479 /* It is a global symbol: set its link type
7480 to "defined" and give it a value. */
7482 sym_hashes
= elf_sym_hashes (bfd_with_globals
);
7483 h
= sym_hashes
[symidx
- extsymoff
];
7484 while (h
->root
.type
== bfd_link_hash_indirect
7485 || h
->root
.type
== bfd_link_hash_warning
)
7486 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7487 h
->root
.type
= bfd_link_hash_defined
;
7488 h
->root
.u
.def
.value
= val
;
7489 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
7493 resolve_symbol (const char *name
,
7495 struct elf_final_link_info
*flinfo
,
7497 Elf_Internal_Sym
*isymbuf
,
7500 Elf_Internal_Sym
*sym
;
7501 struct bfd_link_hash_entry
*global_entry
;
7502 const char *candidate
= NULL
;
7503 Elf_Internal_Shdr
*symtab_hdr
;
7506 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
7508 for (i
= 0; i
< locsymcount
; ++ i
)
7512 if (ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
7515 candidate
= bfd_elf_string_from_elf_section (input_bfd
,
7516 symtab_hdr
->sh_link
,
7519 printf ("Comparing string: '%s' vs. '%s' = 0x%lx\n",
7520 name
, candidate
, (unsigned long) sym
->st_value
);
7522 if (candidate
&& strcmp (candidate
, name
) == 0)
7524 asection
*sec
= flinfo
->sections
[i
];
7526 *result
= _bfd_elf_rel_local_sym (input_bfd
, sym
, &sec
, 0);
7527 *result
+= sec
->output_offset
+ sec
->output_section
->vma
;
7529 printf ("Found symbol with value %8.8lx\n",
7530 (unsigned long) *result
);
7536 /* Hmm, haven't found it yet. perhaps it is a global. */
7537 global_entry
= bfd_link_hash_lookup (flinfo
->info
->hash
, name
,
7538 FALSE
, FALSE
, TRUE
);
7542 if (global_entry
->type
== bfd_link_hash_defined
7543 || global_entry
->type
== bfd_link_hash_defweak
)
7545 *result
= (global_entry
->u
.def
.value
7546 + global_entry
->u
.def
.section
->output_section
->vma
7547 + global_entry
->u
.def
.section
->output_offset
);
7549 printf ("Found GLOBAL symbol '%s' with value %8.8lx\n",
7550 global_entry
->root
.string
, (unsigned long) *result
);
7559 resolve_section (const char *name
,
7566 for (curr
= sections
; curr
; curr
= curr
->next
)
7567 if (strcmp (curr
->name
, name
) == 0)
7569 *result
= curr
->vma
;
7573 /* Hmm. still haven't found it. try pseudo-section names. */
7574 for (curr
= sections
; curr
; curr
= curr
->next
)
7576 len
= strlen (curr
->name
);
7577 if (len
> strlen (name
))
7580 if (strncmp (curr
->name
, name
, len
) == 0)
7582 if (strncmp (".end", name
+ len
, 4) == 0)
7584 *result
= curr
->vma
+ curr
->size
;
7588 /* Insert more pseudo-section names here, if you like. */
7596 undefined_reference (const char *reftype
, const char *name
)
7598 _bfd_error_handler (_("undefined %s reference in complex symbol: %s"),
7603 eval_symbol (bfd_vma
*result
,
7606 struct elf_final_link_info
*flinfo
,
7608 Elf_Internal_Sym
*isymbuf
,
7617 const char *sym
= *symp
;
7619 bfd_boolean symbol_is_section
= FALSE
;
7624 if (len
< 1 || len
> sizeof (symbuf
))
7626 bfd_set_error (bfd_error_invalid_operation
);
7639 *result
= strtoul (sym
, (char **) symp
, 16);
7643 symbol_is_section
= TRUE
;
7646 symlen
= strtol (sym
, (char **) symp
, 10);
7647 sym
= *symp
+ 1; /* Skip the trailing ':'. */
7649 if (symend
< sym
|| symlen
+ 1 > sizeof (symbuf
))
7651 bfd_set_error (bfd_error_invalid_operation
);
7655 memcpy (symbuf
, sym
, symlen
);
7656 symbuf
[symlen
] = '\0';
7657 *symp
= sym
+ symlen
;
7659 /* Is it always possible, with complex symbols, that gas "mis-guessed"
7660 the symbol as a section, or vice-versa. so we're pretty liberal in our
7661 interpretation here; section means "try section first", not "must be a
7662 section", and likewise with symbol. */
7664 if (symbol_is_section
)
7666 if (!resolve_section (symbuf
, flinfo
->output_bfd
->sections
, result
)
7667 && !resolve_symbol (symbuf
, input_bfd
, flinfo
, result
,
7668 isymbuf
, locsymcount
))
7670 undefined_reference ("section", symbuf
);
7676 if (!resolve_symbol (symbuf
, input_bfd
, flinfo
, result
,
7677 isymbuf
, locsymcount
)
7678 && !resolve_section (symbuf
, flinfo
->output_bfd
->sections
,
7681 undefined_reference ("symbol", symbuf
);
7688 /* All that remains are operators. */
7690 #define UNARY_OP(op) \
7691 if (strncmp (sym, #op, strlen (#op)) == 0) \
7693 sym += strlen (#op); \
7697 if (!eval_symbol (&a, symp, input_bfd, flinfo, dot, \
7698 isymbuf, locsymcount, signed_p)) \
7701 *result = op ((bfd_signed_vma) a); \
7707 #define BINARY_OP(op) \
7708 if (strncmp (sym, #op, strlen (#op)) == 0) \
7710 sym += strlen (#op); \
7714 if (!eval_symbol (&a, symp, input_bfd, flinfo, dot, \
7715 isymbuf, locsymcount, signed_p)) \
7718 if (!eval_symbol (&b, symp, input_bfd, flinfo, dot, \
7719 isymbuf, locsymcount, signed_p)) \
7722 *result = ((bfd_signed_vma) a) op ((bfd_signed_vma) b); \
7752 _bfd_error_handler (_("unknown operator '%c' in complex symbol"), * sym
);
7753 bfd_set_error (bfd_error_invalid_operation
);
7759 put_value (bfd_vma size
,
7760 unsigned long chunksz
,
7765 location
+= (size
- chunksz
);
7767 for (; size
; size
-= chunksz
, location
-= chunksz
, x
>>= (chunksz
* 8))
7775 bfd_put_8 (input_bfd
, x
, location
);
7778 bfd_put_16 (input_bfd
, x
, location
);
7781 bfd_put_32 (input_bfd
, x
, location
);
7785 bfd_put_64 (input_bfd
, x
, location
);
7795 get_value (bfd_vma size
,
7796 unsigned long chunksz
,
7802 for (; size
; size
-= chunksz
, location
+= chunksz
)
7810 x
= (x
<< (8 * chunksz
)) | bfd_get_8 (input_bfd
, location
);
7813 x
= (x
<< (8 * chunksz
)) | bfd_get_16 (input_bfd
, location
);
7816 x
= (x
<< (8 * chunksz
)) | bfd_get_32 (input_bfd
, location
);
7820 x
= (x
<< (8 * chunksz
)) | bfd_get_64 (input_bfd
, location
);
7831 decode_complex_addend (unsigned long *start
, /* in bits */
7832 unsigned long *oplen
, /* in bits */
7833 unsigned long *len
, /* in bits */
7834 unsigned long *wordsz
, /* in bytes */
7835 unsigned long *chunksz
, /* in bytes */
7836 unsigned long *lsb0_p
,
7837 unsigned long *signed_p
,
7838 unsigned long *trunc_p
,
7839 unsigned long encoded
)
7841 * start
= encoded
& 0x3F;
7842 * len
= (encoded
>> 6) & 0x3F;
7843 * oplen
= (encoded
>> 12) & 0x3F;
7844 * wordsz
= (encoded
>> 18) & 0xF;
7845 * chunksz
= (encoded
>> 22) & 0xF;
7846 * lsb0_p
= (encoded
>> 27) & 1;
7847 * signed_p
= (encoded
>> 28) & 1;
7848 * trunc_p
= (encoded
>> 29) & 1;
7851 bfd_reloc_status_type
7852 bfd_elf_perform_complex_relocation (bfd
*input_bfd
,
7853 asection
*input_section ATTRIBUTE_UNUSED
,
7855 Elf_Internal_Rela
*rel
,
7858 bfd_vma shift
, x
, mask
;
7859 unsigned long start
, oplen
, len
, wordsz
, chunksz
, lsb0_p
, signed_p
, trunc_p
;
7860 bfd_reloc_status_type r
;
7862 /* Perform this reloc, since it is complex.
7863 (this is not to say that it necessarily refers to a complex
7864 symbol; merely that it is a self-describing CGEN based reloc.
7865 i.e. the addend has the complete reloc information (bit start, end,
7866 word size, etc) encoded within it.). */
7868 decode_complex_addend (&start
, &oplen
, &len
, &wordsz
,
7869 &chunksz
, &lsb0_p
, &signed_p
,
7870 &trunc_p
, rel
->r_addend
);
7872 mask
= (((1L << (len
- 1)) - 1) << 1) | 1;
7875 shift
= (start
+ 1) - len
;
7877 shift
= (8 * wordsz
) - (start
+ len
);
7879 /* FIXME: octets_per_byte. */
7880 x
= get_value (wordsz
, chunksz
, input_bfd
, contents
+ rel
->r_offset
);
7883 printf ("Doing complex reloc: "
7884 "lsb0? %ld, signed? %ld, trunc? %ld, wordsz %ld, "
7885 "chunksz %ld, start %ld, len %ld, oplen %ld\n"
7886 " dest: %8.8lx, mask: %8.8lx, reloc: %8.8lx\n",
7887 lsb0_p
, signed_p
, trunc_p
, wordsz
, chunksz
, start
, len
,
7888 oplen
, (unsigned long) x
, (unsigned long) mask
,
7889 (unsigned long) relocation
);
7894 /* Now do an overflow check. */
7895 r
= bfd_check_overflow ((signed_p
7896 ? complain_overflow_signed
7897 : complain_overflow_unsigned
),
7898 len
, 0, (8 * wordsz
),
7902 x
= (x
& ~(mask
<< shift
)) | ((relocation
& mask
) << shift
);
7905 printf (" relocation: %8.8lx\n"
7906 " shifted mask: %8.8lx\n"
7907 " shifted/masked reloc: %8.8lx\n"
7908 " result: %8.8lx\n",
7909 (unsigned long) relocation
, (unsigned long) (mask
<< shift
),
7910 (unsigned long) ((relocation
& mask
) << shift
), (unsigned long) x
);
7912 /* FIXME: octets_per_byte. */
7913 put_value (wordsz
, chunksz
, input_bfd
, x
, contents
+ rel
->r_offset
);
7917 /* When performing a relocatable link, the input relocations are
7918 preserved. But, if they reference global symbols, the indices
7919 referenced must be updated. Update all the relocations found in
7923 elf_link_adjust_relocs (bfd
*abfd
,
7924 struct bfd_elf_section_reloc_data
*reldata
)
7927 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7929 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
7930 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
7931 bfd_vma r_type_mask
;
7933 unsigned int count
= reldata
->count
;
7934 struct elf_link_hash_entry
**rel_hash
= reldata
->hashes
;
7936 if (reldata
->hdr
->sh_entsize
== bed
->s
->sizeof_rel
)
7938 swap_in
= bed
->s
->swap_reloc_in
;
7939 swap_out
= bed
->s
->swap_reloc_out
;
7941 else if (reldata
->hdr
->sh_entsize
== bed
->s
->sizeof_rela
)
7943 swap_in
= bed
->s
->swap_reloca_in
;
7944 swap_out
= bed
->s
->swap_reloca_out
;
7949 if (bed
->s
->int_rels_per_ext_rel
> MAX_INT_RELS_PER_EXT_REL
)
7952 if (bed
->s
->arch_size
== 32)
7959 r_type_mask
= 0xffffffff;
7963 erela
= reldata
->hdr
->contents
;
7964 for (i
= 0; i
< count
; i
++, rel_hash
++, erela
+= reldata
->hdr
->sh_entsize
)
7966 Elf_Internal_Rela irela
[MAX_INT_RELS_PER_EXT_REL
];
7969 if (*rel_hash
== NULL
)
7972 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
7974 (*swap_in
) (abfd
, erela
, irela
);
7975 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
7976 irela
[j
].r_info
= ((bfd_vma
) (*rel_hash
)->indx
<< r_sym_shift
7977 | (irela
[j
].r_info
& r_type_mask
));
7978 (*swap_out
) (abfd
, irela
, erela
);
7982 struct elf_link_sort_rela
7988 enum elf_reloc_type_class type
;
7989 /* We use this as an array of size int_rels_per_ext_rel. */
7990 Elf_Internal_Rela rela
[1];
7994 elf_link_sort_cmp1 (const void *A
, const void *B
)
7996 const struct elf_link_sort_rela
*a
= (const struct elf_link_sort_rela
*) A
;
7997 const struct elf_link_sort_rela
*b
= (const struct elf_link_sort_rela
*) B
;
7998 int relativea
, relativeb
;
8000 relativea
= a
->type
== reloc_class_relative
;
8001 relativeb
= b
->type
== reloc_class_relative
;
8003 if (relativea
< relativeb
)
8005 if (relativea
> relativeb
)
8007 if ((a
->rela
->r_info
& a
->u
.sym_mask
) < (b
->rela
->r_info
& b
->u
.sym_mask
))
8009 if ((a
->rela
->r_info
& a
->u
.sym_mask
) > (b
->rela
->r_info
& b
->u
.sym_mask
))
8011 if (a
->rela
->r_offset
< b
->rela
->r_offset
)
8013 if (a
->rela
->r_offset
> b
->rela
->r_offset
)
8019 elf_link_sort_cmp2 (const void *A
, const void *B
)
8021 const struct elf_link_sort_rela
*a
= (const struct elf_link_sort_rela
*) A
;
8022 const struct elf_link_sort_rela
*b
= (const struct elf_link_sort_rela
*) B
;
8025 if (a
->u
.offset
< b
->u
.offset
)
8027 if (a
->u
.offset
> b
->u
.offset
)
8029 copya
= (a
->type
== reloc_class_copy
) * 2 + (a
->type
== reloc_class_plt
);
8030 copyb
= (b
->type
== reloc_class_copy
) * 2 + (b
->type
== reloc_class_plt
);
8035 if (a
->rela
->r_offset
< b
->rela
->r_offset
)
8037 if (a
->rela
->r_offset
> b
->rela
->r_offset
)
8043 elf_link_sort_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
**psec
)
8045 asection
*dynamic_relocs
;
8048 bfd_size_type count
, size
;
8049 size_t i
, ret
, sort_elt
, ext_size
;
8050 bfd_byte
*sort
, *s_non_relative
, *p
;
8051 struct elf_link_sort_rela
*sq
;
8052 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
8053 int i2e
= bed
->s
->int_rels_per_ext_rel
;
8054 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
8055 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
8056 struct bfd_link_order
*lo
;
8058 bfd_boolean use_rela
;
8060 /* Find a dynamic reloc section. */
8061 rela_dyn
= bfd_get_section_by_name (abfd
, ".rela.dyn");
8062 rel_dyn
= bfd_get_section_by_name (abfd
, ".rel.dyn");
8063 if (rela_dyn
!= NULL
&& rela_dyn
->size
> 0
8064 && rel_dyn
!= NULL
&& rel_dyn
->size
> 0)
8066 bfd_boolean use_rela_initialised
= FALSE
;
8068 /* This is just here to stop gcc from complaining.
8069 It's initialization checking code is not perfect. */
8072 /* Both sections are present. Examine the sizes
8073 of the indirect sections to help us choose. */
8074 for (lo
= rela_dyn
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
8075 if (lo
->type
== bfd_indirect_link_order
)
8077 asection
*o
= lo
->u
.indirect
.section
;
8079 if ((o
->size
% bed
->s
->sizeof_rela
) == 0)
8081 if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
8082 /* Section size is divisible by both rel and rela sizes.
8083 It is of no help to us. */
8087 /* Section size is only divisible by rela. */
8088 if (use_rela_initialised
&& (use_rela
== FALSE
))
8091 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
8092 bfd_set_error (bfd_error_invalid_operation
);
8098 use_rela_initialised
= TRUE
;
8102 else if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
8104 /* Section size is only divisible by rel. */
8105 if (use_rela_initialised
&& (use_rela
== TRUE
))
8108 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
8109 bfd_set_error (bfd_error_invalid_operation
);
8115 use_rela_initialised
= TRUE
;
8120 /* The section size is not divisible by either - something is wrong. */
8122 (_("%B: Unable to sort relocs - they are of an unknown size"), abfd
);
8123 bfd_set_error (bfd_error_invalid_operation
);
8128 for (lo
= rel_dyn
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
8129 if (lo
->type
== bfd_indirect_link_order
)
8131 asection
*o
= lo
->u
.indirect
.section
;
8133 if ((o
->size
% bed
->s
->sizeof_rela
) == 0)
8135 if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
8136 /* Section size is divisible by both rel and rela sizes.
8137 It is of no help to us. */
8141 /* Section size is only divisible by rela. */
8142 if (use_rela_initialised
&& (use_rela
== FALSE
))
8145 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
8146 bfd_set_error (bfd_error_invalid_operation
);
8152 use_rela_initialised
= TRUE
;
8156 else if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
8158 /* Section size is only divisible by rel. */
8159 if (use_rela_initialised
&& (use_rela
== TRUE
))
8162 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
8163 bfd_set_error (bfd_error_invalid_operation
);
8169 use_rela_initialised
= TRUE
;
8174 /* The section size is not divisible by either - something is wrong. */
8176 (_("%B: Unable to sort relocs - they are of an unknown size"), abfd
);
8177 bfd_set_error (bfd_error_invalid_operation
);
8182 if (! use_rela_initialised
)
8186 else if (rela_dyn
!= NULL
&& rela_dyn
->size
> 0)
8188 else if (rel_dyn
!= NULL
&& rel_dyn
->size
> 0)
8195 dynamic_relocs
= rela_dyn
;
8196 ext_size
= bed
->s
->sizeof_rela
;
8197 swap_in
= bed
->s
->swap_reloca_in
;
8198 swap_out
= bed
->s
->swap_reloca_out
;
8202 dynamic_relocs
= rel_dyn
;
8203 ext_size
= bed
->s
->sizeof_rel
;
8204 swap_in
= bed
->s
->swap_reloc_in
;
8205 swap_out
= bed
->s
->swap_reloc_out
;
8209 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
8210 if (lo
->type
== bfd_indirect_link_order
)
8211 size
+= lo
->u
.indirect
.section
->size
;
8213 if (size
!= dynamic_relocs
->size
)
8216 sort_elt
= (sizeof (struct elf_link_sort_rela
)
8217 + (i2e
- 1) * sizeof (Elf_Internal_Rela
));
8219 count
= dynamic_relocs
->size
/ ext_size
;
8222 sort
= (bfd_byte
*) bfd_zmalloc (sort_elt
* count
);
8226 (*info
->callbacks
->warning
)
8227 (info
, _("Not enough memory to sort relocations"), 0, abfd
, 0, 0);
8231 if (bed
->s
->arch_size
== 32)
8232 r_sym_mask
= ~(bfd_vma
) 0xff;
8234 r_sym_mask
= ~(bfd_vma
) 0xffffffff;
8236 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
8237 if (lo
->type
== bfd_indirect_link_order
)
8239 bfd_byte
*erel
, *erelend
;
8240 asection
*o
= lo
->u
.indirect
.section
;
8242 if (o
->contents
== NULL
&& o
->size
!= 0)
8244 /* This is a reloc section that is being handled as a normal
8245 section. See bfd_section_from_shdr. We can't combine
8246 relocs in this case. */
8251 erelend
= o
->contents
+ o
->size
;
8252 /* FIXME: octets_per_byte. */
8253 p
= sort
+ o
->output_offset
/ ext_size
* sort_elt
;
8255 while (erel
< erelend
)
8257 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
8259 (*swap_in
) (abfd
, erel
, s
->rela
);
8260 s
->type
= (*bed
->elf_backend_reloc_type_class
) (s
->rela
);
8261 s
->u
.sym_mask
= r_sym_mask
;
8267 qsort (sort
, count
, sort_elt
, elf_link_sort_cmp1
);
8269 for (i
= 0, p
= sort
; i
< count
; i
++, p
+= sort_elt
)
8271 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
8272 if (s
->type
!= reloc_class_relative
)
8278 sq
= (struct elf_link_sort_rela
*) s_non_relative
;
8279 for (; i
< count
; i
++, p
+= sort_elt
)
8281 struct elf_link_sort_rela
*sp
= (struct elf_link_sort_rela
*) p
;
8282 if (((sp
->rela
->r_info
^ sq
->rela
->r_info
) & r_sym_mask
) != 0)
8284 sp
->u
.offset
= sq
->rela
->r_offset
;
8287 qsort (s_non_relative
, count
- ret
, sort_elt
, elf_link_sort_cmp2
);
8289 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
8290 if (lo
->type
== bfd_indirect_link_order
)
8292 bfd_byte
*erel
, *erelend
;
8293 asection
*o
= lo
->u
.indirect
.section
;
8296 erelend
= o
->contents
+ o
->size
;
8297 /* FIXME: octets_per_byte. */
8298 p
= sort
+ o
->output_offset
/ ext_size
* sort_elt
;
8299 while (erel
< erelend
)
8301 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
8302 (*swap_out
) (abfd
, s
->rela
, erel
);
8309 *psec
= dynamic_relocs
;
8313 /* Flush the output symbols to the file. */
8316 elf_link_flush_output_syms (struct elf_final_link_info
*flinfo
,
8317 const struct elf_backend_data
*bed
)
8319 if (flinfo
->symbuf_count
> 0)
8321 Elf_Internal_Shdr
*hdr
;
8325 hdr
= &elf_tdata (flinfo
->output_bfd
)->symtab_hdr
;
8326 pos
= hdr
->sh_offset
+ hdr
->sh_size
;
8327 amt
= flinfo
->symbuf_count
* bed
->s
->sizeof_sym
;
8328 if (bfd_seek (flinfo
->output_bfd
, pos
, SEEK_SET
) != 0
8329 || bfd_bwrite (flinfo
->symbuf
, amt
, flinfo
->output_bfd
) != amt
)
8332 hdr
->sh_size
+= amt
;
8333 flinfo
->symbuf_count
= 0;
8339 /* Add a symbol to the output symbol table. */
8342 elf_link_output_sym (struct elf_final_link_info
*flinfo
,
8344 Elf_Internal_Sym
*elfsym
,
8345 asection
*input_sec
,
8346 struct elf_link_hash_entry
*h
)
8349 Elf_External_Sym_Shndx
*destshndx
;
8350 int (*output_symbol_hook
)
8351 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*, asection
*,
8352 struct elf_link_hash_entry
*);
8353 const struct elf_backend_data
*bed
;
8355 bed
= get_elf_backend_data (flinfo
->output_bfd
);
8356 output_symbol_hook
= bed
->elf_backend_link_output_symbol_hook
;
8357 if (output_symbol_hook
!= NULL
)
8359 int ret
= (*output_symbol_hook
) (flinfo
->info
, name
, elfsym
, input_sec
, h
);
8364 if (name
== NULL
|| *name
== '\0')
8365 elfsym
->st_name
= 0;
8366 else if (input_sec
->flags
& SEC_EXCLUDE
)
8367 elfsym
->st_name
= 0;
8370 elfsym
->st_name
= (unsigned long) _bfd_stringtab_add (flinfo
->symstrtab
,
8372 if (elfsym
->st_name
== (unsigned long) -1)
8376 if (flinfo
->symbuf_count
>= flinfo
->symbuf_size
)
8378 if (! elf_link_flush_output_syms (flinfo
, bed
))
8382 dest
= flinfo
->symbuf
+ flinfo
->symbuf_count
* bed
->s
->sizeof_sym
;
8383 destshndx
= flinfo
->symshndxbuf
;
8384 if (destshndx
!= NULL
)
8386 if (bfd_get_symcount (flinfo
->output_bfd
) >= flinfo
->shndxbuf_size
)
8390 amt
= flinfo
->shndxbuf_size
* sizeof (Elf_External_Sym_Shndx
);
8391 destshndx
= (Elf_External_Sym_Shndx
*) bfd_realloc (destshndx
,
8393 if (destshndx
== NULL
)
8395 flinfo
->symshndxbuf
= destshndx
;
8396 memset ((char *) destshndx
+ amt
, 0, amt
);
8397 flinfo
->shndxbuf_size
*= 2;
8399 destshndx
+= bfd_get_symcount (flinfo
->output_bfd
);
8402 bed
->s
->swap_symbol_out (flinfo
->output_bfd
, elfsym
, dest
, destshndx
);
8403 flinfo
->symbuf_count
+= 1;
8404 bfd_get_symcount (flinfo
->output_bfd
) += 1;
8409 /* Return TRUE if the dynamic symbol SYM in ABFD is supported. */
8412 check_dynsym (bfd
*abfd
, Elf_Internal_Sym
*sym
)
8414 if (sym
->st_shndx
>= (SHN_LORESERVE
& 0xffff)
8415 && sym
->st_shndx
< SHN_LORESERVE
)
8417 /* The gABI doesn't support dynamic symbols in output sections
8419 (*_bfd_error_handler
)
8420 (_("%B: Too many sections: %d (>= %d)"),
8421 abfd
, bfd_count_sections (abfd
), SHN_LORESERVE
& 0xffff);
8422 bfd_set_error (bfd_error_nonrepresentable_section
);
8428 /* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
8429 allowing an unsatisfied unversioned symbol in the DSO to match a
8430 versioned symbol that would normally require an explicit version.
8431 We also handle the case that a DSO references a hidden symbol
8432 which may be satisfied by a versioned symbol in another DSO. */
8435 elf_link_check_versioned_symbol (struct bfd_link_info
*info
,
8436 const struct elf_backend_data
*bed
,
8437 struct elf_link_hash_entry
*h
)
8440 struct elf_link_loaded_list
*loaded
;
8442 if (!is_elf_hash_table (info
->hash
))
8445 switch (h
->root
.type
)
8451 case bfd_link_hash_undefined
:
8452 case bfd_link_hash_undefweak
:
8453 abfd
= h
->root
.u
.undef
.abfd
;
8454 if ((abfd
->flags
& DYNAMIC
) == 0
8455 || (elf_dyn_lib_class (abfd
) & DYN_DT_NEEDED
) == 0)
8459 case bfd_link_hash_defined
:
8460 case bfd_link_hash_defweak
:
8461 abfd
= h
->root
.u
.def
.section
->owner
;
8464 case bfd_link_hash_common
:
8465 abfd
= h
->root
.u
.c
.p
->section
->owner
;
8468 BFD_ASSERT (abfd
!= NULL
);
8470 for (loaded
= elf_hash_table (info
)->loaded
;
8472 loaded
= loaded
->next
)
8475 Elf_Internal_Shdr
*hdr
;
8476 bfd_size_type symcount
;
8477 bfd_size_type extsymcount
;
8478 bfd_size_type extsymoff
;
8479 Elf_Internal_Shdr
*versymhdr
;
8480 Elf_Internal_Sym
*isym
;
8481 Elf_Internal_Sym
*isymend
;
8482 Elf_Internal_Sym
*isymbuf
;
8483 Elf_External_Versym
*ever
;
8484 Elf_External_Versym
*extversym
;
8486 input
= loaded
->abfd
;
8488 /* We check each DSO for a possible hidden versioned definition. */
8490 || (input
->flags
& DYNAMIC
) == 0
8491 || elf_dynversym (input
) == 0)
8494 hdr
= &elf_tdata (input
)->dynsymtab_hdr
;
8496 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
8497 if (elf_bad_symtab (input
))
8499 extsymcount
= symcount
;
8504 extsymcount
= symcount
- hdr
->sh_info
;
8505 extsymoff
= hdr
->sh_info
;
8508 if (extsymcount
== 0)
8511 isymbuf
= bfd_elf_get_elf_syms (input
, hdr
, extsymcount
, extsymoff
,
8513 if (isymbuf
== NULL
)
8516 /* Read in any version definitions. */
8517 versymhdr
= &elf_tdata (input
)->dynversym_hdr
;
8518 extversym
= (Elf_External_Versym
*) bfd_malloc (versymhdr
->sh_size
);
8519 if (extversym
== NULL
)
8522 if (bfd_seek (input
, versymhdr
->sh_offset
, SEEK_SET
) != 0
8523 || (bfd_bread (extversym
, versymhdr
->sh_size
, input
)
8524 != versymhdr
->sh_size
))
8532 ever
= extversym
+ extsymoff
;
8533 isymend
= isymbuf
+ extsymcount
;
8534 for (isym
= isymbuf
; isym
< isymend
; isym
++, ever
++)
8537 Elf_Internal_Versym iver
;
8538 unsigned short version_index
;
8540 if (ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
8541 || isym
->st_shndx
== SHN_UNDEF
)
8544 name
= bfd_elf_string_from_elf_section (input
,
8547 if (strcmp (name
, h
->root
.root
.string
) != 0)
8550 _bfd_elf_swap_versym_in (input
, ever
, &iver
);
8552 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
8554 && h
->forced_local
))
8556 /* If we have a non-hidden versioned sym, then it should
8557 have provided a definition for the undefined sym unless
8558 it is defined in a non-shared object and forced local.
8563 version_index
= iver
.vs_vers
& VERSYM_VERSION
;
8564 if (version_index
== 1 || version_index
== 2)
8566 /* This is the base or first version. We can use it. */
8580 /* Add an external symbol to the symbol table. This is called from
8581 the hash table traversal routine. When generating a shared object,
8582 we go through the symbol table twice. The first time we output
8583 anything that might have been forced to local scope in a version
8584 script. The second time we output the symbols that are still
8588 elf_link_output_extsym (struct bfd_hash_entry
*bh
, void *data
)
8590 struct elf_link_hash_entry
*h
= (struct elf_link_hash_entry
*) bh
;
8591 struct elf_outext_info
*eoinfo
= (struct elf_outext_info
*) data
;
8592 struct elf_final_link_info
*flinfo
= eoinfo
->flinfo
;
8594 Elf_Internal_Sym sym
;
8595 asection
*input_sec
;
8596 const struct elf_backend_data
*bed
;
8600 if (h
->root
.type
== bfd_link_hash_warning
)
8602 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8603 if (h
->root
.type
== bfd_link_hash_new
)
8607 /* Decide whether to output this symbol in this pass. */
8608 if (eoinfo
->localsyms
)
8610 if (!h
->forced_local
)
8612 if (eoinfo
->second_pass
8613 && !((h
->root
.type
== bfd_link_hash_defined
8614 || h
->root
.type
== bfd_link_hash_defweak
)
8615 && h
->root
.u
.def
.section
->output_section
!= NULL
))
8620 if (h
->forced_local
)
8624 bed
= get_elf_backend_data (flinfo
->output_bfd
);
8626 if (h
->root
.type
== bfd_link_hash_undefined
)
8628 /* If we have an undefined symbol reference here then it must have
8629 come from a shared library that is being linked in. (Undefined
8630 references in regular files have already been handled unless
8631 they are in unreferenced sections which are removed by garbage
8633 bfd_boolean ignore_undef
= FALSE
;
8635 /* Some symbols may be special in that the fact that they're
8636 undefined can be safely ignored - let backend determine that. */
8637 if (bed
->elf_backend_ignore_undef_symbol
)
8638 ignore_undef
= bed
->elf_backend_ignore_undef_symbol (h
);
8640 /* If we are reporting errors for this situation then do so now. */
8643 && (!h
->ref_regular
|| flinfo
->info
->gc_sections
)
8644 && !elf_link_check_versioned_symbol (flinfo
->info
, bed
, h
)
8645 && flinfo
->info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
)
8647 if (!(flinfo
->info
->callbacks
->undefined_symbol
8648 (flinfo
->info
, h
->root
.root
.string
,
8649 h
->ref_regular
? NULL
: h
->root
.u
.undef
.abfd
,
8651 (flinfo
->info
->unresolved_syms_in_shared_libs
8652 == RM_GENERATE_ERROR
))))
8654 bfd_set_error (bfd_error_bad_value
);
8655 eoinfo
->failed
= TRUE
;
8661 /* We should also warn if a forced local symbol is referenced from
8662 shared libraries. */
8663 if (!flinfo
->info
->relocatable
8664 && flinfo
->info
->executable
8670 && !elf_link_check_versioned_symbol (flinfo
->info
, bed
, h
))
8675 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
)
8676 msg
= _("%B: internal symbol `%s' in %B is referenced by DSO");
8677 else if (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
8678 msg
= _("%B: hidden symbol `%s' in %B is referenced by DSO");
8680 msg
= _("%B: local symbol `%s' in %B is referenced by DSO");
8681 def_bfd
= flinfo
->output_bfd
;
8682 if (h
->root
.u
.def
.section
!= bfd_abs_section_ptr
)
8683 def_bfd
= h
->root
.u
.def
.section
->owner
;
8684 (*_bfd_error_handler
) (msg
, flinfo
->output_bfd
, def_bfd
,
8685 h
->root
.root
.string
);
8686 bfd_set_error (bfd_error_bad_value
);
8687 eoinfo
->failed
= TRUE
;
8691 /* We don't want to output symbols that have never been mentioned by
8692 a regular file, or that we have been told to strip. However, if
8693 h->indx is set to -2, the symbol is used by a reloc and we must
8697 else if ((h
->def_dynamic
8699 || h
->root
.type
== bfd_link_hash_new
)
8703 else if (flinfo
->info
->strip
== strip_all
)
8705 else if (flinfo
->info
->strip
== strip_some
8706 && bfd_hash_lookup (flinfo
->info
->keep_hash
,
8707 h
->root
.root
.string
, FALSE
, FALSE
) == NULL
)
8709 else if ((h
->root
.type
== bfd_link_hash_defined
8710 || h
->root
.type
== bfd_link_hash_defweak
)
8711 && ((flinfo
->info
->strip_discarded
8712 && discarded_section (h
->root
.u
.def
.section
))
8713 || (h
->root
.u
.def
.section
->owner
!= NULL
8714 && (h
->root
.u
.def
.section
->owner
->flags
& BFD_PLUGIN
) != 0)))
8716 else if ((h
->root
.type
== bfd_link_hash_undefined
8717 || h
->root
.type
== bfd_link_hash_undefweak
)
8718 && h
->root
.u
.undef
.abfd
!= NULL
8719 && (h
->root
.u
.undef
.abfd
->flags
& BFD_PLUGIN
) != 0)
8724 /* If we're stripping it, and it's not a dynamic symbol, there's
8725 nothing else to do unless it is a forced local symbol or a
8726 STT_GNU_IFUNC symbol. */
8729 && h
->type
!= STT_GNU_IFUNC
8730 && !h
->forced_local
)
8734 sym
.st_size
= h
->size
;
8735 sym
.st_other
= h
->other
;
8736 if (h
->forced_local
)
8738 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, h
->type
);
8739 /* Turn off visibility on local symbol. */
8740 sym
.st_other
&= ~ELF_ST_VISIBILITY (-1);
8742 else if (h
->unique_global
)
8743 sym
.st_info
= ELF_ST_INFO (STB_GNU_UNIQUE
, h
->type
);
8744 else if (h
->root
.type
== bfd_link_hash_undefweak
8745 || h
->root
.type
== bfd_link_hash_defweak
)
8746 sym
.st_info
= ELF_ST_INFO (STB_WEAK
, h
->type
);
8748 sym
.st_info
= ELF_ST_INFO (STB_GLOBAL
, h
->type
);
8749 sym
.st_target_internal
= h
->target_internal
;
8751 switch (h
->root
.type
)
8754 case bfd_link_hash_new
:
8755 case bfd_link_hash_warning
:
8759 case bfd_link_hash_undefined
:
8760 case bfd_link_hash_undefweak
:
8761 input_sec
= bfd_und_section_ptr
;
8762 sym
.st_shndx
= SHN_UNDEF
;
8765 case bfd_link_hash_defined
:
8766 case bfd_link_hash_defweak
:
8768 input_sec
= h
->root
.u
.def
.section
;
8769 if (input_sec
->output_section
!= NULL
)
8771 if (eoinfo
->localsyms
&& flinfo
->filesym_count
== 1)
8773 bfd_boolean second_pass_sym
8774 = (input_sec
->owner
== flinfo
->output_bfd
8775 || input_sec
->owner
== NULL
8776 || (input_sec
->flags
& SEC_LINKER_CREATED
) != 0
8777 || (input_sec
->owner
->flags
& BFD_LINKER_CREATED
) != 0);
8779 eoinfo
->need_second_pass
|= second_pass_sym
;
8780 if (eoinfo
->second_pass
!= second_pass_sym
)
8785 _bfd_elf_section_from_bfd_section (flinfo
->output_bfd
,
8786 input_sec
->output_section
);
8787 if (sym
.st_shndx
== SHN_BAD
)
8789 (*_bfd_error_handler
)
8790 (_("%B: could not find output section %A for input section %A"),
8791 flinfo
->output_bfd
, input_sec
->output_section
, input_sec
);
8792 bfd_set_error (bfd_error_nonrepresentable_section
);
8793 eoinfo
->failed
= TRUE
;
8797 /* ELF symbols in relocatable files are section relative,
8798 but in nonrelocatable files they are virtual
8800 sym
.st_value
= h
->root
.u
.def
.value
+ input_sec
->output_offset
;
8801 if (!flinfo
->info
->relocatable
)
8803 sym
.st_value
+= input_sec
->output_section
->vma
;
8804 if (h
->type
== STT_TLS
)
8806 asection
*tls_sec
= elf_hash_table (flinfo
->info
)->tls_sec
;
8807 if (tls_sec
!= NULL
)
8808 sym
.st_value
-= tls_sec
->vma
;
8811 /* The TLS section may have been garbage collected. */
8812 BFD_ASSERT (flinfo
->info
->gc_sections
8813 && !input_sec
->gc_mark
);
8820 BFD_ASSERT (input_sec
->owner
== NULL
8821 || (input_sec
->owner
->flags
& DYNAMIC
) != 0);
8822 sym
.st_shndx
= SHN_UNDEF
;
8823 input_sec
= bfd_und_section_ptr
;
8828 case bfd_link_hash_common
:
8829 input_sec
= h
->root
.u
.c
.p
->section
;
8830 sym
.st_shndx
= bed
->common_section_index (input_sec
);
8831 sym
.st_value
= 1 << h
->root
.u
.c
.p
->alignment_power
;
8834 case bfd_link_hash_indirect
:
8835 /* These symbols are created by symbol versioning. They point
8836 to the decorated version of the name. For example, if the
8837 symbol foo@@GNU_1.2 is the default, which should be used when
8838 foo is used with no version, then we add an indirect symbol
8839 foo which points to foo@@GNU_1.2. We ignore these symbols,
8840 since the indirected symbol is already in the hash table. */
8844 /* Give the processor backend a chance to tweak the symbol value,
8845 and also to finish up anything that needs to be done for this
8846 symbol. FIXME: Not calling elf_backend_finish_dynamic_symbol for
8847 forced local syms when non-shared is due to a historical quirk.
8848 STT_GNU_IFUNC symbol must go through PLT. */
8849 if ((h
->type
== STT_GNU_IFUNC
8851 && !flinfo
->info
->relocatable
)
8852 || ((h
->dynindx
!= -1
8854 && ((flinfo
->info
->shared
8855 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8856 || h
->root
.type
!= bfd_link_hash_undefweak
))
8857 || !h
->forced_local
)
8858 && elf_hash_table (flinfo
->info
)->dynamic_sections_created
))
8860 if (! ((*bed
->elf_backend_finish_dynamic_symbol
)
8861 (flinfo
->output_bfd
, flinfo
->info
, h
, &sym
)))
8863 eoinfo
->failed
= TRUE
;
8868 /* If we are marking the symbol as undefined, and there are no
8869 non-weak references to this symbol from a regular object, then
8870 mark the symbol as weak undefined; if there are non-weak
8871 references, mark the symbol as strong. We can't do this earlier,
8872 because it might not be marked as undefined until the
8873 finish_dynamic_symbol routine gets through with it. */
8874 if (sym
.st_shndx
== SHN_UNDEF
8876 && (ELF_ST_BIND (sym
.st_info
) == STB_GLOBAL
8877 || ELF_ST_BIND (sym
.st_info
) == STB_WEAK
))
8880 unsigned int type
= ELF_ST_TYPE (sym
.st_info
);
8882 /* Turn an undefined IFUNC symbol into a normal FUNC symbol. */
8883 if (type
== STT_GNU_IFUNC
)
8886 if (h
->ref_regular_nonweak
)
8887 bindtype
= STB_GLOBAL
;
8889 bindtype
= STB_WEAK
;
8890 sym
.st_info
= ELF_ST_INFO (bindtype
, type
);
8893 /* If this is a symbol defined in a dynamic library, don't use the
8894 symbol size from the dynamic library. Relinking an executable
8895 against a new library may introduce gratuitous changes in the
8896 executable's symbols if we keep the size. */
8897 if (sym
.st_shndx
== SHN_UNDEF
8902 /* If a non-weak symbol with non-default visibility is not defined
8903 locally, it is a fatal error. */
8904 if (!flinfo
->info
->relocatable
8905 && ELF_ST_VISIBILITY (sym
.st_other
) != STV_DEFAULT
8906 && ELF_ST_BIND (sym
.st_info
) != STB_WEAK
8907 && h
->root
.type
== bfd_link_hash_undefined
8912 if (ELF_ST_VISIBILITY (sym
.st_other
) == STV_PROTECTED
)
8913 msg
= _("%B: protected symbol `%s' isn't defined");
8914 else if (ELF_ST_VISIBILITY (sym
.st_other
) == STV_INTERNAL
)
8915 msg
= _("%B: internal symbol `%s' isn't defined");
8917 msg
= _("%B: hidden symbol `%s' isn't defined");
8918 (*_bfd_error_handler
) (msg
, flinfo
->output_bfd
, h
->root
.root
.string
);
8919 bfd_set_error (bfd_error_bad_value
);
8920 eoinfo
->failed
= TRUE
;
8924 /* If this symbol should be put in the .dynsym section, then put it
8925 there now. We already know the symbol index. We also fill in
8926 the entry in the .hash section. */
8927 if (flinfo
->dynsym_sec
!= NULL
8929 && elf_hash_table (flinfo
->info
)->dynamic_sections_created
)
8933 sym
.st_name
= h
->dynstr_index
;
8934 esym
= flinfo
->dynsym_sec
->contents
+ h
->dynindx
* bed
->s
->sizeof_sym
;
8935 if (!check_dynsym (flinfo
->output_bfd
, &sym
))
8937 eoinfo
->failed
= TRUE
;
8940 bed
->s
->swap_symbol_out (flinfo
->output_bfd
, &sym
, esym
, 0);
8942 if (flinfo
->hash_sec
!= NULL
)
8944 size_t hash_entry_size
;
8945 bfd_byte
*bucketpos
;
8950 bucketcount
= elf_hash_table (flinfo
->info
)->bucketcount
;
8951 bucket
= h
->u
.elf_hash_value
% bucketcount
;
8954 = elf_section_data (flinfo
->hash_sec
)->this_hdr
.sh_entsize
;
8955 bucketpos
= ((bfd_byte
*) flinfo
->hash_sec
->contents
8956 + (bucket
+ 2) * hash_entry_size
);
8957 chain
= bfd_get (8 * hash_entry_size
, flinfo
->output_bfd
, bucketpos
);
8958 bfd_put (8 * hash_entry_size
, flinfo
->output_bfd
, h
->dynindx
,
8960 bfd_put (8 * hash_entry_size
, flinfo
->output_bfd
, chain
,
8961 ((bfd_byte
*) flinfo
->hash_sec
->contents
8962 + (bucketcount
+ 2 + h
->dynindx
) * hash_entry_size
));
8965 if (flinfo
->symver_sec
!= NULL
&& flinfo
->symver_sec
->contents
!= NULL
)
8967 Elf_Internal_Versym iversym
;
8968 Elf_External_Versym
*eversym
;
8970 if (!h
->def_regular
)
8972 if (h
->verinfo
.verdef
== NULL
)
8973 iversym
.vs_vers
= 0;
8975 iversym
.vs_vers
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
8979 if (h
->verinfo
.vertree
== NULL
)
8980 iversym
.vs_vers
= 1;
8982 iversym
.vs_vers
= h
->verinfo
.vertree
->vernum
+ 1;
8983 if (flinfo
->info
->create_default_symver
)
8988 iversym
.vs_vers
|= VERSYM_HIDDEN
;
8990 eversym
= (Elf_External_Versym
*) flinfo
->symver_sec
->contents
;
8991 eversym
+= h
->dynindx
;
8992 _bfd_elf_swap_versym_out (flinfo
->output_bfd
, &iversym
, eversym
);
8996 /* If we're stripping it, then it was just a dynamic symbol, and
8997 there's nothing else to do. */
8998 if (strip
|| (input_sec
->flags
& SEC_EXCLUDE
) != 0)
9001 indx
= bfd_get_symcount (flinfo
->output_bfd
);
9002 ret
= elf_link_output_sym (flinfo
, h
->root
.root
.string
, &sym
, input_sec
, h
);
9005 eoinfo
->failed
= TRUE
;
9010 else if (h
->indx
== -2)
9016 /* Return TRUE if special handling is done for relocs in SEC against
9017 symbols defined in discarded sections. */
9020 elf_section_ignore_discarded_relocs (asection
*sec
)
9022 const struct elf_backend_data
*bed
;
9024 switch (sec
->sec_info_type
)
9026 case SEC_INFO_TYPE_STABS
:
9027 case SEC_INFO_TYPE_EH_FRAME
:
9033 bed
= get_elf_backend_data (sec
->owner
);
9034 if (bed
->elf_backend_ignore_discarded_relocs
!= NULL
9035 && (*bed
->elf_backend_ignore_discarded_relocs
) (sec
))
9041 /* Return a mask saying how ld should treat relocations in SEC against
9042 symbols defined in discarded sections. If this function returns
9043 COMPLAIN set, ld will issue a warning message. If this function
9044 returns PRETEND set, and the discarded section was link-once and the
9045 same size as the kept link-once section, ld will pretend that the
9046 symbol was actually defined in the kept section. Otherwise ld will
9047 zero the reloc (at least that is the intent, but some cooperation by
9048 the target dependent code is needed, particularly for REL targets). */
9051 _bfd_elf_default_action_discarded (asection
*sec
)
9053 if (sec
->flags
& SEC_DEBUGGING
)
9056 if (strcmp (".eh_frame", sec
->name
) == 0)
9059 if (strcmp (".gcc_except_table", sec
->name
) == 0)
9062 return COMPLAIN
| PRETEND
;
9065 /* Find a match between a section and a member of a section group. */
9068 match_group_member (asection
*sec
, asection
*group
,
9069 struct bfd_link_info
*info
)
9071 asection
*first
= elf_next_in_group (group
);
9072 asection
*s
= first
;
9076 if (bfd_elf_match_symbols_in_sections (s
, sec
, info
))
9079 s
= elf_next_in_group (s
);
9087 /* Check if the kept section of a discarded section SEC can be used
9088 to replace it. Return the replacement if it is OK. Otherwise return
9092 _bfd_elf_check_kept_section (asection
*sec
, struct bfd_link_info
*info
)
9096 kept
= sec
->kept_section
;
9099 if ((kept
->flags
& SEC_GROUP
) != 0)
9100 kept
= match_group_member (sec
, kept
, info
);
9102 && ((sec
->rawsize
!= 0 ? sec
->rawsize
: sec
->size
)
9103 != (kept
->rawsize
!= 0 ? kept
->rawsize
: kept
->size
)))
9105 sec
->kept_section
= kept
;
9110 /* Link an input file into the linker output file. This function
9111 handles all the sections and relocations of the input file at once.
9112 This is so that we only have to read the local symbols once, and
9113 don't have to keep them in memory. */
9116 elf_link_input_bfd (struct elf_final_link_info
*flinfo
, bfd
*input_bfd
)
9118 int (*relocate_section
)
9119 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
9120 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**);
9122 Elf_Internal_Shdr
*symtab_hdr
;
9125 Elf_Internal_Sym
*isymbuf
;
9126 Elf_Internal_Sym
*isym
;
9127 Elf_Internal_Sym
*isymend
;
9129 asection
**ppsection
;
9131 const struct elf_backend_data
*bed
;
9132 struct elf_link_hash_entry
**sym_hashes
;
9133 bfd_size_type address_size
;
9134 bfd_vma r_type_mask
;
9136 bfd_boolean have_file_sym
= FALSE
;
9138 output_bfd
= flinfo
->output_bfd
;
9139 bed
= get_elf_backend_data (output_bfd
);
9140 relocate_section
= bed
->elf_backend_relocate_section
;
9142 /* If this is a dynamic object, we don't want to do anything here:
9143 we don't want the local symbols, and we don't want the section
9145 if ((input_bfd
->flags
& DYNAMIC
) != 0)
9148 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9149 if (elf_bad_symtab (input_bfd
))
9151 locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
9156 locsymcount
= symtab_hdr
->sh_info
;
9157 extsymoff
= symtab_hdr
->sh_info
;
9160 /* Read the local symbols. */
9161 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
9162 if (isymbuf
== NULL
&& locsymcount
!= 0)
9164 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
, locsymcount
, 0,
9165 flinfo
->internal_syms
,
9166 flinfo
->external_syms
,
9167 flinfo
->locsym_shndx
);
9168 if (isymbuf
== NULL
)
9172 /* Find local symbol sections and adjust values of symbols in
9173 SEC_MERGE sections. Write out those local symbols we know are
9174 going into the output file. */
9175 isymend
= isymbuf
+ locsymcount
;
9176 for (isym
= isymbuf
, pindex
= flinfo
->indices
, ppsection
= flinfo
->sections
;
9178 isym
++, pindex
++, ppsection
++)
9182 Elf_Internal_Sym osym
;
9188 if (elf_bad_symtab (input_bfd
))
9190 if (ELF_ST_BIND (isym
->st_info
) != STB_LOCAL
)
9197 if (isym
->st_shndx
== SHN_UNDEF
)
9198 isec
= bfd_und_section_ptr
;
9199 else if (isym
->st_shndx
== SHN_ABS
)
9200 isec
= bfd_abs_section_ptr
;
9201 else if (isym
->st_shndx
== SHN_COMMON
)
9202 isec
= bfd_com_section_ptr
;
9205 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
9208 /* Don't attempt to output symbols with st_shnx in the
9209 reserved range other than SHN_ABS and SHN_COMMON. */
9213 else if (isec
->sec_info_type
== SEC_INFO_TYPE_MERGE
9214 && ELF_ST_TYPE (isym
->st_info
) != STT_SECTION
)
9216 _bfd_merged_section_offset (output_bfd
, &isec
,
9217 elf_section_data (isec
)->sec_info
,
9223 /* Don't output the first, undefined, symbol. */
9224 if (ppsection
== flinfo
->sections
)
9227 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
9229 /* We never output section symbols. Instead, we use the
9230 section symbol of the corresponding section in the output
9235 /* If we are stripping all symbols, we don't want to output this
9237 if (flinfo
->info
->strip
== strip_all
)
9240 /* If we are discarding all local symbols, we don't want to
9241 output this one. If we are generating a relocatable output
9242 file, then some of the local symbols may be required by
9243 relocs; we output them below as we discover that they are
9245 if (flinfo
->info
->discard
== discard_all
)
9248 /* If this symbol is defined in a section which we are
9249 discarding, we don't need to keep it. */
9250 if (isym
->st_shndx
!= SHN_UNDEF
9251 && isym
->st_shndx
< SHN_LORESERVE
9252 && bfd_section_removed_from_list (output_bfd
,
9253 isec
->output_section
))
9256 /* Get the name of the symbol. */
9257 name
= bfd_elf_string_from_elf_section (input_bfd
, symtab_hdr
->sh_link
,
9262 /* See if we are discarding symbols with this name. */
9263 if ((flinfo
->info
->strip
== strip_some
9264 && (bfd_hash_lookup (flinfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
9266 || (((flinfo
->info
->discard
== discard_sec_merge
9267 && (isec
->flags
& SEC_MERGE
) && !flinfo
->info
->relocatable
)
9268 || flinfo
->info
->discard
== discard_l
)
9269 && bfd_is_local_label_name (input_bfd
, name
)))
9272 if (ELF_ST_TYPE (isym
->st_info
) == STT_FILE
)
9274 have_file_sym
= TRUE
;
9275 flinfo
->filesym_count
+= 1;
9279 /* In the absence of debug info, bfd_find_nearest_line uses
9280 FILE symbols to determine the source file for local
9281 function symbols. Provide a FILE symbol here if input
9282 files lack such, so that their symbols won't be
9283 associated with a previous input file. It's not the
9284 source file, but the best we can do. */
9285 have_file_sym
= TRUE
;
9286 flinfo
->filesym_count
+= 1;
9287 memset (&osym
, 0, sizeof (osym
));
9288 osym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FILE
);
9289 osym
.st_shndx
= SHN_ABS
;
9290 if (!elf_link_output_sym (flinfo
, input_bfd
->filename
, &osym
,
9291 bfd_abs_section_ptr
, NULL
))
9297 /* Adjust the section index for the output file. */
9298 osym
.st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
9299 isec
->output_section
);
9300 if (osym
.st_shndx
== SHN_BAD
)
9303 /* ELF symbols in relocatable files are section relative, but
9304 in executable files they are virtual addresses. Note that
9305 this code assumes that all ELF sections have an associated
9306 BFD section with a reasonable value for output_offset; below
9307 we assume that they also have a reasonable value for
9308 output_section. Any special sections must be set up to meet
9309 these requirements. */
9310 osym
.st_value
+= isec
->output_offset
;
9311 if (!flinfo
->info
->relocatable
)
9313 osym
.st_value
+= isec
->output_section
->vma
;
9314 if (ELF_ST_TYPE (osym
.st_info
) == STT_TLS
)
9316 /* STT_TLS symbols are relative to PT_TLS segment base. */
9317 BFD_ASSERT (elf_hash_table (flinfo
->info
)->tls_sec
!= NULL
);
9318 osym
.st_value
-= elf_hash_table (flinfo
->info
)->tls_sec
->vma
;
9322 indx
= bfd_get_symcount (output_bfd
);
9323 ret
= elf_link_output_sym (flinfo
, name
, &osym
, isec
, NULL
);
9330 if (bed
->s
->arch_size
== 32)
9338 r_type_mask
= 0xffffffff;
9343 /* Relocate the contents of each section. */
9344 sym_hashes
= elf_sym_hashes (input_bfd
);
9345 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
9349 if (! o
->linker_mark
)
9351 /* This section was omitted from the link. */
9355 if (flinfo
->info
->relocatable
9356 && (o
->flags
& (SEC_LINKER_CREATED
| SEC_GROUP
)) == SEC_GROUP
)
9358 /* Deal with the group signature symbol. */
9359 struct bfd_elf_section_data
*sec_data
= elf_section_data (o
);
9360 unsigned long symndx
= sec_data
->this_hdr
.sh_info
;
9361 asection
*osec
= o
->output_section
;
9363 if (symndx
>= locsymcount
9364 || (elf_bad_symtab (input_bfd
)
9365 && flinfo
->sections
[symndx
] == NULL
))
9367 struct elf_link_hash_entry
*h
= sym_hashes
[symndx
- extsymoff
];
9368 while (h
->root
.type
== bfd_link_hash_indirect
9369 || h
->root
.type
== bfd_link_hash_warning
)
9370 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9371 /* Arrange for symbol to be output. */
9373 elf_section_data (osec
)->this_hdr
.sh_info
= -2;
9375 else if (ELF_ST_TYPE (isymbuf
[symndx
].st_info
) == STT_SECTION
)
9377 /* We'll use the output section target_index. */
9378 asection
*sec
= flinfo
->sections
[symndx
]->output_section
;
9379 elf_section_data (osec
)->this_hdr
.sh_info
= sec
->target_index
;
9383 if (flinfo
->indices
[symndx
] == -1)
9385 /* Otherwise output the local symbol now. */
9386 Elf_Internal_Sym sym
= isymbuf
[symndx
];
9387 asection
*sec
= flinfo
->sections
[symndx
]->output_section
;
9392 name
= bfd_elf_string_from_elf_section (input_bfd
,
9393 symtab_hdr
->sh_link
,
9398 sym
.st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
9400 if (sym
.st_shndx
== SHN_BAD
)
9403 sym
.st_value
+= o
->output_offset
;
9405 indx
= bfd_get_symcount (output_bfd
);
9406 ret
= elf_link_output_sym (flinfo
, name
, &sym
, o
, NULL
);
9410 flinfo
->indices
[symndx
] = indx
;
9414 elf_section_data (osec
)->this_hdr
.sh_info
9415 = flinfo
->indices
[symndx
];
9419 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
9420 || (o
->size
== 0 && (o
->flags
& SEC_RELOC
) == 0))
9423 if ((o
->flags
& SEC_LINKER_CREATED
) != 0)
9425 /* Section was created by _bfd_elf_link_create_dynamic_sections
9430 /* Get the contents of the section. They have been cached by a
9431 relaxation routine. Note that o is a section in an input
9432 file, so the contents field will not have been set by any of
9433 the routines which work on output files. */
9434 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
9435 contents
= elf_section_data (o
)->this_hdr
.contents
;
9438 contents
= flinfo
->contents
;
9439 if (! bfd_get_full_section_contents (input_bfd
, o
, &contents
))
9443 if ((o
->flags
& SEC_RELOC
) != 0)
9445 Elf_Internal_Rela
*internal_relocs
;
9446 Elf_Internal_Rela
*rel
, *relend
;
9447 int action_discarded
;
9450 /* Get the swapped relocs. */
9452 = _bfd_elf_link_read_relocs (input_bfd
, o
, flinfo
->external_relocs
,
9453 flinfo
->internal_relocs
, FALSE
);
9454 if (internal_relocs
== NULL
9455 && o
->reloc_count
> 0)
9458 /* We need to reverse-copy input .ctors/.dtors sections if
9459 they are placed in .init_array/.finit_array for output. */
9460 if (o
->size
> address_size
9461 && ((strncmp (o
->name
, ".ctors", 6) == 0
9462 && strcmp (o
->output_section
->name
,
9463 ".init_array") == 0)
9464 || (strncmp (o
->name
, ".dtors", 6) == 0
9465 && strcmp (o
->output_section
->name
,
9466 ".fini_array") == 0))
9467 && (o
->name
[6] == 0 || o
->name
[6] == '.'))
9469 if (o
->size
!= o
->reloc_count
* address_size
)
9471 (*_bfd_error_handler
)
9472 (_("error: %B: size of section %A is not "
9473 "multiple of address size"),
9475 bfd_set_error (bfd_error_on_input
);
9478 o
->flags
|= SEC_ELF_REVERSE_COPY
;
9481 action_discarded
= -1;
9482 if (!elf_section_ignore_discarded_relocs (o
))
9483 action_discarded
= (*bed
->action_discarded
) (o
);
9485 /* Run through the relocs evaluating complex reloc symbols and
9486 looking for relocs against symbols from discarded sections
9487 or section symbols from removed link-once sections.
9488 Complain about relocs against discarded sections. Zero
9489 relocs against removed link-once sections. */
9491 rel
= internal_relocs
;
9492 relend
= rel
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9493 for ( ; rel
< relend
; rel
++)
9495 unsigned long r_symndx
= rel
->r_info
>> r_sym_shift
;
9496 unsigned int s_type
;
9497 asection
**ps
, *sec
;
9498 struct elf_link_hash_entry
*h
= NULL
;
9499 const char *sym_name
;
9501 if (r_symndx
== STN_UNDEF
)
9504 if (r_symndx
>= locsymcount
9505 || (elf_bad_symtab (input_bfd
)
9506 && flinfo
->sections
[r_symndx
] == NULL
))
9508 h
= sym_hashes
[r_symndx
- extsymoff
];
9510 /* Badly formatted input files can contain relocs that
9511 reference non-existant symbols. Check here so that
9512 we do not seg fault. */
9517 sprintf_vma (buffer
, rel
->r_info
);
9518 (*_bfd_error_handler
)
9519 (_("error: %B contains a reloc (0x%s) for section %A "
9520 "that references a non-existent global symbol"),
9521 input_bfd
, o
, buffer
);
9522 bfd_set_error (bfd_error_bad_value
);
9526 while (h
->root
.type
== bfd_link_hash_indirect
9527 || h
->root
.type
== bfd_link_hash_warning
)
9528 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9533 if (h
->root
.type
== bfd_link_hash_defined
9534 || h
->root
.type
== bfd_link_hash_defweak
)
9535 ps
= &h
->root
.u
.def
.section
;
9537 sym_name
= h
->root
.root
.string
;
9541 Elf_Internal_Sym
*sym
= isymbuf
+ r_symndx
;
9543 s_type
= ELF_ST_TYPE (sym
->st_info
);
9544 ps
= &flinfo
->sections
[r_symndx
];
9545 sym_name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
9549 if ((s_type
== STT_RELC
|| s_type
== STT_SRELC
)
9550 && !flinfo
->info
->relocatable
)
9553 bfd_vma dot
= (rel
->r_offset
9554 + o
->output_offset
+ o
->output_section
->vma
);
9556 printf ("Encountered a complex symbol!");
9557 printf (" (input_bfd %s, section %s, reloc %ld\n",
9558 input_bfd
->filename
, o
->name
,
9559 (long) (rel
- internal_relocs
));
9560 printf (" symbol: idx %8.8lx, name %s\n",
9561 r_symndx
, sym_name
);
9562 printf (" reloc : info %8.8lx, addr %8.8lx\n",
9563 (unsigned long) rel
->r_info
,
9564 (unsigned long) rel
->r_offset
);
9566 if (!eval_symbol (&val
, &sym_name
, input_bfd
, flinfo
, dot
,
9567 isymbuf
, locsymcount
, s_type
== STT_SRELC
))
9570 /* Symbol evaluated OK. Update to absolute value. */
9571 set_symbol_value (input_bfd
, isymbuf
, locsymcount
,
9576 if (action_discarded
!= -1 && ps
!= NULL
)
9578 /* Complain if the definition comes from a
9579 discarded section. */
9580 if ((sec
= *ps
) != NULL
&& discarded_section (sec
))
9582 BFD_ASSERT (r_symndx
!= STN_UNDEF
);
9583 if (action_discarded
& COMPLAIN
)
9584 (*flinfo
->info
->callbacks
->einfo
)
9585 (_("%X`%s' referenced in section `%A' of %B: "
9586 "defined in discarded section `%A' of %B\n"),
9587 sym_name
, o
, input_bfd
, sec
, sec
->owner
);
9589 /* Try to do the best we can to support buggy old
9590 versions of gcc. Pretend that the symbol is
9591 really defined in the kept linkonce section.
9592 FIXME: This is quite broken. Modifying the
9593 symbol here means we will be changing all later
9594 uses of the symbol, not just in this section. */
9595 if (action_discarded
& PRETEND
)
9599 kept
= _bfd_elf_check_kept_section (sec
,
9611 /* Relocate the section by invoking a back end routine.
9613 The back end routine is responsible for adjusting the
9614 section contents as necessary, and (if using Rela relocs
9615 and generating a relocatable output file) adjusting the
9616 reloc addend as necessary.
9618 The back end routine does not have to worry about setting
9619 the reloc address or the reloc symbol index.
9621 The back end routine is given a pointer to the swapped in
9622 internal symbols, and can access the hash table entries
9623 for the external symbols via elf_sym_hashes (input_bfd).
9625 When generating relocatable output, the back end routine
9626 must handle STB_LOCAL/STT_SECTION symbols specially. The
9627 output symbol is going to be a section symbol
9628 corresponding to the output section, which will require
9629 the addend to be adjusted. */
9631 ret
= (*relocate_section
) (output_bfd
, flinfo
->info
,
9632 input_bfd
, o
, contents
,
9640 || flinfo
->info
->relocatable
9641 || flinfo
->info
->emitrelocations
)
9643 Elf_Internal_Rela
*irela
;
9644 Elf_Internal_Rela
*irelaend
, *irelamid
;
9645 bfd_vma last_offset
;
9646 struct elf_link_hash_entry
**rel_hash
;
9647 struct elf_link_hash_entry
**rel_hash_list
, **rela_hash_list
;
9648 Elf_Internal_Shdr
*input_rel_hdr
, *input_rela_hdr
;
9649 unsigned int next_erel
;
9650 bfd_boolean rela_normal
;
9651 struct bfd_elf_section_data
*esdi
, *esdo
;
9653 esdi
= elf_section_data (o
);
9654 esdo
= elf_section_data (o
->output_section
);
9655 rela_normal
= FALSE
;
9657 /* Adjust the reloc addresses and symbol indices. */
9659 irela
= internal_relocs
;
9660 irelaend
= irela
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9661 rel_hash
= esdo
->rel
.hashes
+ esdo
->rel
.count
;
9662 /* We start processing the REL relocs, if any. When we reach
9663 IRELAMID in the loop, we switch to the RELA relocs. */
9665 if (esdi
->rel
.hdr
!= NULL
)
9666 irelamid
+= (NUM_SHDR_ENTRIES (esdi
->rel
.hdr
)
9667 * bed
->s
->int_rels_per_ext_rel
);
9668 rel_hash_list
= rel_hash
;
9669 rela_hash_list
= NULL
;
9670 last_offset
= o
->output_offset
;
9671 if (!flinfo
->info
->relocatable
)
9672 last_offset
+= o
->output_section
->vma
;
9673 for (next_erel
= 0; irela
< irelaend
; irela
++, next_erel
++)
9675 unsigned long r_symndx
;
9677 Elf_Internal_Sym sym
;
9679 if (next_erel
== bed
->s
->int_rels_per_ext_rel
)
9685 if (irela
== irelamid
)
9687 rel_hash
= esdo
->rela
.hashes
+ esdo
->rela
.count
;
9688 rela_hash_list
= rel_hash
;
9689 rela_normal
= bed
->rela_normal
;
9692 irela
->r_offset
= _bfd_elf_section_offset (output_bfd
,
9695 if (irela
->r_offset
>= (bfd_vma
) -2)
9697 /* This is a reloc for a deleted entry or somesuch.
9698 Turn it into an R_*_NONE reloc, at the same
9699 offset as the last reloc. elf_eh_frame.c and
9700 bfd_elf_discard_info rely on reloc offsets
9702 irela
->r_offset
= last_offset
;
9704 irela
->r_addend
= 0;
9708 irela
->r_offset
+= o
->output_offset
;
9710 /* Relocs in an executable have to be virtual addresses. */
9711 if (!flinfo
->info
->relocatable
)
9712 irela
->r_offset
+= o
->output_section
->vma
;
9714 last_offset
= irela
->r_offset
;
9716 r_symndx
= irela
->r_info
>> r_sym_shift
;
9717 if (r_symndx
== STN_UNDEF
)
9720 if (r_symndx
>= locsymcount
9721 || (elf_bad_symtab (input_bfd
)
9722 && flinfo
->sections
[r_symndx
] == NULL
))
9724 struct elf_link_hash_entry
*rh
;
9727 /* This is a reloc against a global symbol. We
9728 have not yet output all the local symbols, so
9729 we do not know the symbol index of any global
9730 symbol. We set the rel_hash entry for this
9731 reloc to point to the global hash table entry
9732 for this symbol. The symbol index is then
9733 set at the end of bfd_elf_final_link. */
9734 indx
= r_symndx
- extsymoff
;
9735 rh
= elf_sym_hashes (input_bfd
)[indx
];
9736 while (rh
->root
.type
== bfd_link_hash_indirect
9737 || rh
->root
.type
== bfd_link_hash_warning
)
9738 rh
= (struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
;
9740 /* Setting the index to -2 tells
9741 elf_link_output_extsym that this symbol is
9743 BFD_ASSERT (rh
->indx
< 0);
9751 /* This is a reloc against a local symbol. */
9754 sym
= isymbuf
[r_symndx
];
9755 sec
= flinfo
->sections
[r_symndx
];
9756 if (ELF_ST_TYPE (sym
.st_info
) == STT_SECTION
)
9758 /* I suppose the backend ought to fill in the
9759 section of any STT_SECTION symbol against a
9760 processor specific section. */
9761 r_symndx
= STN_UNDEF
;
9762 if (bfd_is_abs_section (sec
))
9764 else if (sec
== NULL
|| sec
->owner
== NULL
)
9766 bfd_set_error (bfd_error_bad_value
);
9771 asection
*osec
= sec
->output_section
;
9773 /* If we have discarded a section, the output
9774 section will be the absolute section. In
9775 case of discarded SEC_MERGE sections, use
9776 the kept section. relocate_section should
9777 have already handled discarded linkonce
9779 if (bfd_is_abs_section (osec
)
9780 && sec
->kept_section
!= NULL
9781 && sec
->kept_section
->output_section
!= NULL
)
9783 osec
= sec
->kept_section
->output_section
;
9784 irela
->r_addend
-= osec
->vma
;
9787 if (!bfd_is_abs_section (osec
))
9789 r_symndx
= osec
->target_index
;
9790 if (r_symndx
== STN_UNDEF
)
9792 irela
->r_addend
+= osec
->vma
;
9793 osec
= _bfd_nearby_section (output_bfd
, osec
,
9795 irela
->r_addend
-= osec
->vma
;
9796 r_symndx
= osec
->target_index
;
9801 /* Adjust the addend according to where the
9802 section winds up in the output section. */
9804 irela
->r_addend
+= sec
->output_offset
;
9808 if (flinfo
->indices
[r_symndx
] == -1)
9810 unsigned long shlink
;
9815 if (flinfo
->info
->strip
== strip_all
)
9817 /* You can't do ld -r -s. */
9818 bfd_set_error (bfd_error_invalid_operation
);
9822 /* This symbol was skipped earlier, but
9823 since it is needed by a reloc, we
9824 must output it now. */
9825 shlink
= symtab_hdr
->sh_link
;
9826 name
= (bfd_elf_string_from_elf_section
9827 (input_bfd
, shlink
, sym
.st_name
));
9831 osec
= sec
->output_section
;
9833 _bfd_elf_section_from_bfd_section (output_bfd
,
9835 if (sym
.st_shndx
== SHN_BAD
)
9838 sym
.st_value
+= sec
->output_offset
;
9839 if (!flinfo
->info
->relocatable
)
9841 sym
.st_value
+= osec
->vma
;
9842 if (ELF_ST_TYPE (sym
.st_info
) == STT_TLS
)
9844 /* STT_TLS symbols are relative to PT_TLS
9846 BFD_ASSERT (elf_hash_table (flinfo
->info
)
9848 sym
.st_value
-= (elf_hash_table (flinfo
->info
)
9853 indx
= bfd_get_symcount (output_bfd
);
9854 ret
= elf_link_output_sym (flinfo
, name
, &sym
, sec
,
9859 flinfo
->indices
[r_symndx
] = indx
;
9864 r_symndx
= flinfo
->indices
[r_symndx
];
9867 irela
->r_info
= ((bfd_vma
) r_symndx
<< r_sym_shift
9868 | (irela
->r_info
& r_type_mask
));
9871 /* Swap out the relocs. */
9872 input_rel_hdr
= esdi
->rel
.hdr
;
9873 if (input_rel_hdr
&& input_rel_hdr
->sh_size
!= 0)
9875 if (!bed
->elf_backend_emit_relocs (output_bfd
, o
,
9880 internal_relocs
+= (NUM_SHDR_ENTRIES (input_rel_hdr
)
9881 * bed
->s
->int_rels_per_ext_rel
);
9882 rel_hash_list
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
9885 input_rela_hdr
= esdi
->rela
.hdr
;
9886 if (input_rela_hdr
&& input_rela_hdr
->sh_size
!= 0)
9888 if (!bed
->elf_backend_emit_relocs (output_bfd
, o
,
9897 /* Write out the modified section contents. */
9898 if (bed
->elf_backend_write_section
9899 && (*bed
->elf_backend_write_section
) (output_bfd
, flinfo
->info
, o
,
9902 /* Section written out. */
9904 else switch (o
->sec_info_type
)
9906 case SEC_INFO_TYPE_STABS
:
9907 if (! (_bfd_write_section_stabs
9909 &elf_hash_table (flinfo
->info
)->stab_info
,
9910 o
, &elf_section_data (o
)->sec_info
, contents
)))
9913 case SEC_INFO_TYPE_MERGE
:
9914 if (! _bfd_write_merged_section (output_bfd
, o
,
9915 elf_section_data (o
)->sec_info
))
9918 case SEC_INFO_TYPE_EH_FRAME
:
9920 if (! _bfd_elf_write_section_eh_frame (output_bfd
, flinfo
->info
,
9927 /* FIXME: octets_per_byte. */
9928 if (! (o
->flags
& SEC_EXCLUDE
))
9930 file_ptr offset
= (file_ptr
) o
->output_offset
;
9931 bfd_size_type todo
= o
->size
;
9932 if ((o
->flags
& SEC_ELF_REVERSE_COPY
))
9934 /* Reverse-copy input section to output. */
9937 todo
-= address_size
;
9938 if (! bfd_set_section_contents (output_bfd
,
9946 offset
+= address_size
;
9950 else if (! bfd_set_section_contents (output_bfd
,
9964 /* Generate a reloc when linking an ELF file. This is a reloc
9965 requested by the linker, and does not come from any input file. This
9966 is used to build constructor and destructor tables when linking
9970 elf_reloc_link_order (bfd
*output_bfd
,
9971 struct bfd_link_info
*info
,
9972 asection
*output_section
,
9973 struct bfd_link_order
*link_order
)
9975 reloc_howto_type
*howto
;
9979 struct bfd_elf_section_reloc_data
*reldata
;
9980 struct elf_link_hash_entry
**rel_hash_ptr
;
9981 Elf_Internal_Shdr
*rel_hdr
;
9982 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
9983 Elf_Internal_Rela irel
[MAX_INT_RELS_PER_EXT_REL
];
9986 struct bfd_elf_section_data
*esdo
= elf_section_data (output_section
);
9988 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
9991 bfd_set_error (bfd_error_bad_value
);
9995 addend
= link_order
->u
.reloc
.p
->addend
;
9998 reldata
= &esdo
->rel
;
9999 else if (esdo
->rela
.hdr
)
10000 reldata
= &esdo
->rela
;
10007 /* Figure out the symbol index. */
10008 rel_hash_ptr
= reldata
->hashes
+ reldata
->count
;
10009 if (link_order
->type
== bfd_section_reloc_link_order
)
10011 indx
= link_order
->u
.reloc
.p
->u
.section
->target_index
;
10012 BFD_ASSERT (indx
!= 0);
10013 *rel_hash_ptr
= NULL
;
10017 struct elf_link_hash_entry
*h
;
10019 /* Treat a reloc against a defined symbol as though it were
10020 actually against the section. */
10021 h
= ((struct elf_link_hash_entry
*)
10022 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
10023 link_order
->u
.reloc
.p
->u
.name
,
10024 FALSE
, FALSE
, TRUE
));
10026 && (h
->root
.type
== bfd_link_hash_defined
10027 || h
->root
.type
== bfd_link_hash_defweak
))
10031 section
= h
->root
.u
.def
.section
;
10032 indx
= section
->output_section
->target_index
;
10033 *rel_hash_ptr
= NULL
;
10034 /* It seems that we ought to add the symbol value to the
10035 addend here, but in practice it has already been added
10036 because it was passed to constructor_callback. */
10037 addend
+= section
->output_section
->vma
+ section
->output_offset
;
10039 else if (h
!= NULL
)
10041 /* Setting the index to -2 tells elf_link_output_extsym that
10042 this symbol is used by a reloc. */
10049 if (! ((*info
->callbacks
->unattached_reloc
)
10050 (info
, link_order
->u
.reloc
.p
->u
.name
, NULL
, NULL
, 0)))
10056 /* If this is an inplace reloc, we must write the addend into the
10058 if (howto
->partial_inplace
&& addend
!= 0)
10060 bfd_size_type size
;
10061 bfd_reloc_status_type rstat
;
10064 const char *sym_name
;
10066 size
= (bfd_size_type
) bfd_get_reloc_size (howto
);
10067 buf
= (bfd_byte
*) bfd_zmalloc (size
);
10070 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
10077 case bfd_reloc_outofrange
:
10080 case bfd_reloc_overflow
:
10081 if (link_order
->type
== bfd_section_reloc_link_order
)
10082 sym_name
= bfd_section_name (output_bfd
,
10083 link_order
->u
.reloc
.p
->u
.section
);
10085 sym_name
= link_order
->u
.reloc
.p
->u
.name
;
10086 if (! ((*info
->callbacks
->reloc_overflow
)
10087 (info
, NULL
, sym_name
, howto
->name
, addend
, NULL
,
10088 NULL
, (bfd_vma
) 0)))
10095 ok
= bfd_set_section_contents (output_bfd
, output_section
, buf
,
10096 link_order
->offset
, size
);
10102 /* The address of a reloc is relative to the section in a
10103 relocatable file, and is a virtual address in an executable
10105 offset
= link_order
->offset
;
10106 if (! info
->relocatable
)
10107 offset
+= output_section
->vma
;
10109 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
10111 irel
[i
].r_offset
= offset
;
10112 irel
[i
].r_info
= 0;
10113 irel
[i
].r_addend
= 0;
10115 if (bed
->s
->arch_size
== 32)
10116 irel
[0].r_info
= ELF32_R_INFO (indx
, howto
->type
);
10118 irel
[0].r_info
= ELF64_R_INFO (indx
, howto
->type
);
10120 rel_hdr
= reldata
->hdr
;
10121 erel
= rel_hdr
->contents
;
10122 if (rel_hdr
->sh_type
== SHT_REL
)
10124 erel
+= reldata
->count
* bed
->s
->sizeof_rel
;
10125 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, erel
);
10129 irel
[0].r_addend
= addend
;
10130 erel
+= reldata
->count
* bed
->s
->sizeof_rela
;
10131 (*bed
->s
->swap_reloca_out
) (output_bfd
, irel
, erel
);
10140 /* Get the output vma of the section pointed to by the sh_link field. */
10143 elf_get_linked_section_vma (struct bfd_link_order
*p
)
10145 Elf_Internal_Shdr
**elf_shdrp
;
10149 s
= p
->u
.indirect
.section
;
10150 elf_shdrp
= elf_elfsections (s
->owner
);
10151 elfsec
= _bfd_elf_section_from_bfd_section (s
->owner
, s
);
10152 elfsec
= elf_shdrp
[elfsec
]->sh_link
;
10154 The Intel C compiler generates SHT_IA_64_UNWIND with
10155 SHF_LINK_ORDER. But it doesn't set the sh_link or
10156 sh_info fields. Hence we could get the situation
10157 where elfsec is 0. */
10160 const struct elf_backend_data
*bed
10161 = get_elf_backend_data (s
->owner
);
10162 if (bed
->link_order_error_handler
)
10163 bed
->link_order_error_handler
10164 (_("%B: warning: sh_link not set for section `%A'"), s
->owner
, s
);
10169 s
= elf_shdrp
[elfsec
]->bfd_section
;
10170 return s
->output_section
->vma
+ s
->output_offset
;
10175 /* Compare two sections based on the locations of the sections they are
10176 linked to. Used by elf_fixup_link_order. */
10179 compare_link_order (const void * a
, const void * b
)
10184 apos
= elf_get_linked_section_vma (*(struct bfd_link_order
**)a
);
10185 bpos
= elf_get_linked_section_vma (*(struct bfd_link_order
**)b
);
10188 return apos
> bpos
;
10192 /* Looks for sections with SHF_LINK_ORDER set. Rearranges them into the same
10193 order as their linked sections. Returns false if this could not be done
10194 because an output section includes both ordered and unordered
10195 sections. Ideally we'd do this in the linker proper. */
10198 elf_fixup_link_order (bfd
*abfd
, asection
*o
)
10200 int seen_linkorder
;
10203 struct bfd_link_order
*p
;
10205 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10207 struct bfd_link_order
**sections
;
10208 asection
*s
, *other_sec
, *linkorder_sec
;
10212 linkorder_sec
= NULL
;
10214 seen_linkorder
= 0;
10215 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10217 if (p
->type
== bfd_indirect_link_order
)
10219 s
= p
->u
.indirect
.section
;
10221 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
10222 && elf_elfheader (sub
)->e_ident
[EI_CLASS
] == bed
->s
->elfclass
10223 && (elfsec
= _bfd_elf_section_from_bfd_section (sub
, s
))
10224 && elfsec
< elf_numsections (sub
)
10225 && elf_elfsections (sub
)[elfsec
]->sh_flags
& SHF_LINK_ORDER
10226 && elf_elfsections (sub
)[elfsec
]->sh_link
< elf_numsections (sub
))
10240 if (seen_other
&& seen_linkorder
)
10242 if (other_sec
&& linkorder_sec
)
10243 (*_bfd_error_handler
) (_("%A has both ordered [`%A' in %B] and unordered [`%A' in %B] sections"),
10245 linkorder_sec
->owner
, other_sec
,
10248 (*_bfd_error_handler
) (_("%A has both ordered and unordered sections"),
10250 bfd_set_error (bfd_error_bad_value
);
10255 if (!seen_linkorder
)
10258 sections
= (struct bfd_link_order
**)
10259 bfd_malloc (seen_linkorder
* sizeof (struct bfd_link_order
*));
10260 if (sections
== NULL
)
10262 seen_linkorder
= 0;
10264 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10266 sections
[seen_linkorder
++] = p
;
10268 /* Sort the input sections in the order of their linked section. */
10269 qsort (sections
, seen_linkorder
, sizeof (struct bfd_link_order
*),
10270 compare_link_order
);
10272 /* Change the offsets of the sections. */
10274 for (n
= 0; n
< seen_linkorder
; n
++)
10276 s
= sections
[n
]->u
.indirect
.section
;
10277 offset
&= ~(bfd_vma
) 0 << s
->alignment_power
;
10278 s
->output_offset
= offset
;
10279 sections
[n
]->offset
= offset
;
10280 /* FIXME: octets_per_byte. */
10281 offset
+= sections
[n
]->size
;
10289 /* Do the final step of an ELF link. */
10292 bfd_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
10294 bfd_boolean dynamic
;
10295 bfd_boolean emit_relocs
;
10297 struct elf_final_link_info flinfo
;
10299 struct bfd_link_order
*p
;
10301 bfd_size_type max_contents_size
;
10302 bfd_size_type max_external_reloc_size
;
10303 bfd_size_type max_internal_reloc_count
;
10304 bfd_size_type max_sym_count
;
10305 bfd_size_type max_sym_shndx_count
;
10307 Elf_Internal_Sym elfsym
;
10309 Elf_Internal_Shdr
*symtab_hdr
;
10310 Elf_Internal_Shdr
*symtab_shndx_hdr
;
10311 Elf_Internal_Shdr
*symstrtab_hdr
;
10312 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10313 struct elf_outext_info eoinfo
;
10314 bfd_boolean merged
;
10315 size_t relativecount
= 0;
10316 asection
*reldyn
= 0;
10318 asection
*attr_section
= NULL
;
10319 bfd_vma attr_size
= 0;
10320 const char *std_attrs_section
;
10322 if (! is_elf_hash_table (info
->hash
))
10326 abfd
->flags
|= DYNAMIC
;
10328 dynamic
= elf_hash_table (info
)->dynamic_sections_created
;
10329 dynobj
= elf_hash_table (info
)->dynobj
;
10331 emit_relocs
= (info
->relocatable
10332 || info
->emitrelocations
);
10334 flinfo
.info
= info
;
10335 flinfo
.output_bfd
= abfd
;
10336 flinfo
.symstrtab
= _bfd_elf_stringtab_init ();
10337 if (flinfo
.symstrtab
== NULL
)
10342 flinfo
.dynsym_sec
= NULL
;
10343 flinfo
.hash_sec
= NULL
;
10344 flinfo
.symver_sec
= NULL
;
10348 flinfo
.dynsym_sec
= bfd_get_section_by_name (dynobj
, ".dynsym");
10349 flinfo
.hash_sec
= bfd_get_section_by_name (dynobj
, ".hash");
10350 /* Note that dynsym_sec can be NULL (on VMS). */
10351 flinfo
.symver_sec
= bfd_get_section_by_name (dynobj
, ".gnu.version");
10352 /* Note that it is OK if symver_sec is NULL. */
10355 flinfo
.contents
= NULL
;
10356 flinfo
.external_relocs
= NULL
;
10357 flinfo
.internal_relocs
= NULL
;
10358 flinfo
.external_syms
= NULL
;
10359 flinfo
.locsym_shndx
= NULL
;
10360 flinfo
.internal_syms
= NULL
;
10361 flinfo
.indices
= NULL
;
10362 flinfo
.sections
= NULL
;
10363 flinfo
.symbuf
= NULL
;
10364 flinfo
.symshndxbuf
= NULL
;
10365 flinfo
.symbuf_count
= 0;
10366 flinfo
.shndxbuf_size
= 0;
10367 flinfo
.filesym_count
= 0;
10369 /* The object attributes have been merged. Remove the input
10370 sections from the link, and set the contents of the output
10372 std_attrs_section
= get_elf_backend_data (abfd
)->obj_attrs_section
;
10373 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10375 if ((std_attrs_section
&& strcmp (o
->name
, std_attrs_section
) == 0)
10376 || strcmp (o
->name
, ".gnu.attributes") == 0)
10378 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10380 asection
*input_section
;
10382 if (p
->type
!= bfd_indirect_link_order
)
10384 input_section
= p
->u
.indirect
.section
;
10385 /* Hack: reset the SEC_HAS_CONTENTS flag so that
10386 elf_link_input_bfd ignores this section. */
10387 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
10390 attr_size
= bfd_elf_obj_attr_size (abfd
);
10393 bfd_set_section_size (abfd
, o
, attr_size
);
10395 /* Skip this section later on. */
10396 o
->map_head
.link_order
= NULL
;
10399 o
->flags
|= SEC_EXCLUDE
;
10403 /* Count up the number of relocations we will output for each output
10404 section, so that we know the sizes of the reloc sections. We
10405 also figure out some maximum sizes. */
10406 max_contents_size
= 0;
10407 max_external_reloc_size
= 0;
10408 max_internal_reloc_count
= 0;
10410 max_sym_shndx_count
= 0;
10412 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10414 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
10415 o
->reloc_count
= 0;
10417 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10419 unsigned int reloc_count
= 0;
10420 struct bfd_elf_section_data
*esdi
= NULL
;
10422 if (p
->type
== bfd_section_reloc_link_order
10423 || p
->type
== bfd_symbol_reloc_link_order
)
10425 else if (p
->type
== bfd_indirect_link_order
)
10429 sec
= p
->u
.indirect
.section
;
10430 esdi
= elf_section_data (sec
);
10432 /* Mark all sections which are to be included in the
10433 link. This will normally be every section. We need
10434 to do this so that we can identify any sections which
10435 the linker has decided to not include. */
10436 sec
->linker_mark
= TRUE
;
10438 if (sec
->flags
& SEC_MERGE
)
10441 if (esdo
->this_hdr
.sh_type
== SHT_REL
10442 || esdo
->this_hdr
.sh_type
== SHT_RELA
)
10443 /* Some backends use reloc_count in relocation sections
10444 to count particular types of relocs. Of course,
10445 reloc sections themselves can't have relocations. */
10447 else if (info
->relocatable
|| info
->emitrelocations
)
10448 reloc_count
= sec
->reloc_count
;
10449 else if (bed
->elf_backend_count_relocs
)
10450 reloc_count
= (*bed
->elf_backend_count_relocs
) (info
, sec
);
10452 if (sec
->rawsize
> max_contents_size
)
10453 max_contents_size
= sec
->rawsize
;
10454 if (sec
->size
> max_contents_size
)
10455 max_contents_size
= sec
->size
;
10457 /* We are interested in just local symbols, not all
10459 if (bfd_get_flavour (sec
->owner
) == bfd_target_elf_flavour
10460 && (sec
->owner
->flags
& DYNAMIC
) == 0)
10464 if (elf_bad_symtab (sec
->owner
))
10465 sym_count
= (elf_tdata (sec
->owner
)->symtab_hdr
.sh_size
10466 / bed
->s
->sizeof_sym
);
10468 sym_count
= elf_tdata (sec
->owner
)->symtab_hdr
.sh_info
;
10470 if (sym_count
> max_sym_count
)
10471 max_sym_count
= sym_count
;
10473 if (sym_count
> max_sym_shndx_count
10474 && elf_symtab_shndx (sec
->owner
) != 0)
10475 max_sym_shndx_count
= sym_count
;
10477 if ((sec
->flags
& SEC_RELOC
) != 0)
10479 size_t ext_size
= 0;
10481 if (esdi
->rel
.hdr
!= NULL
)
10482 ext_size
= esdi
->rel
.hdr
->sh_size
;
10483 if (esdi
->rela
.hdr
!= NULL
)
10484 ext_size
+= esdi
->rela
.hdr
->sh_size
;
10486 if (ext_size
> max_external_reloc_size
)
10487 max_external_reloc_size
= ext_size
;
10488 if (sec
->reloc_count
> max_internal_reloc_count
)
10489 max_internal_reloc_count
= sec
->reloc_count
;
10494 if (reloc_count
== 0)
10497 o
->reloc_count
+= reloc_count
;
10499 if (p
->type
== bfd_indirect_link_order
10500 && (info
->relocatable
|| info
->emitrelocations
))
10503 esdo
->rel
.count
+= NUM_SHDR_ENTRIES (esdi
->rel
.hdr
);
10504 if (esdi
->rela
.hdr
)
10505 esdo
->rela
.count
+= NUM_SHDR_ENTRIES (esdi
->rela
.hdr
);
10510 esdo
->rela
.count
+= reloc_count
;
10512 esdo
->rel
.count
+= reloc_count
;
10516 if (o
->reloc_count
> 0)
10517 o
->flags
|= SEC_RELOC
;
10520 /* Explicitly clear the SEC_RELOC flag. The linker tends to
10521 set it (this is probably a bug) and if it is set
10522 assign_section_numbers will create a reloc section. */
10523 o
->flags
&=~ SEC_RELOC
;
10526 /* If the SEC_ALLOC flag is not set, force the section VMA to
10527 zero. This is done in elf_fake_sections as well, but forcing
10528 the VMA to 0 here will ensure that relocs against these
10529 sections are handled correctly. */
10530 if ((o
->flags
& SEC_ALLOC
) == 0
10531 && ! o
->user_set_vma
)
10535 if (! info
->relocatable
&& merged
)
10536 elf_link_hash_traverse (elf_hash_table (info
),
10537 _bfd_elf_link_sec_merge_syms
, abfd
);
10539 /* Figure out the file positions for everything but the symbol table
10540 and the relocs. We set symcount to force assign_section_numbers
10541 to create a symbol table. */
10542 bfd_get_symcount (abfd
) = info
->strip
== strip_all
? 0 : 1;
10543 BFD_ASSERT (! abfd
->output_has_begun
);
10544 if (! _bfd_elf_compute_section_file_positions (abfd
, info
))
10547 /* Set sizes, and assign file positions for reloc sections. */
10548 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10550 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
10551 if ((o
->flags
& SEC_RELOC
) != 0)
10554 && !(_bfd_elf_link_size_reloc_section (abfd
, &esdo
->rel
)))
10558 && !(_bfd_elf_link_size_reloc_section (abfd
, &esdo
->rela
)))
10562 /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
10563 to count upwards while actually outputting the relocations. */
10564 esdo
->rel
.count
= 0;
10565 esdo
->rela
.count
= 0;
10568 _bfd_elf_assign_file_positions_for_relocs (abfd
);
10570 /* We have now assigned file positions for all the sections except
10571 .symtab and .strtab. We start the .symtab section at the current
10572 file position, and write directly to it. We build the .strtab
10573 section in memory. */
10574 bfd_get_symcount (abfd
) = 0;
10575 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10576 /* sh_name is set in prep_headers. */
10577 symtab_hdr
->sh_type
= SHT_SYMTAB
;
10578 /* sh_flags, sh_addr and sh_size all start off zero. */
10579 symtab_hdr
->sh_entsize
= bed
->s
->sizeof_sym
;
10580 /* sh_link is set in assign_section_numbers. */
10581 /* sh_info is set below. */
10582 /* sh_offset is set just below. */
10583 symtab_hdr
->sh_addralign
= (bfd_vma
) 1 << bed
->s
->log_file_align
;
10585 off
= elf_tdata (abfd
)->next_file_pos
;
10586 off
= _bfd_elf_assign_file_position_for_section (symtab_hdr
, off
, TRUE
);
10588 /* Note that at this point elf_tdata (abfd)->next_file_pos is
10589 incorrect. We do not yet know the size of the .symtab section.
10590 We correct next_file_pos below, after we do know the size. */
10592 /* Allocate a buffer to hold swapped out symbols. This is to avoid
10593 continuously seeking to the right position in the file. */
10594 if (! info
->keep_memory
|| max_sym_count
< 20)
10595 flinfo
.symbuf_size
= 20;
10597 flinfo
.symbuf_size
= max_sym_count
;
10598 amt
= flinfo
.symbuf_size
;
10599 amt
*= bed
->s
->sizeof_sym
;
10600 flinfo
.symbuf
= (bfd_byte
*) bfd_malloc (amt
);
10601 if (flinfo
.symbuf
== NULL
)
10603 if (elf_numsections (abfd
) > (SHN_LORESERVE
& 0xFFFF))
10605 /* Wild guess at number of output symbols. realloc'd as needed. */
10606 amt
= 2 * max_sym_count
+ elf_numsections (abfd
) + 1000;
10607 flinfo
.shndxbuf_size
= amt
;
10608 amt
*= sizeof (Elf_External_Sym_Shndx
);
10609 flinfo
.symshndxbuf
= (Elf_External_Sym_Shndx
*) bfd_zmalloc (amt
);
10610 if (flinfo
.symshndxbuf
== NULL
)
10614 /* Start writing out the symbol table. The first symbol is always a
10616 if (info
->strip
!= strip_all
10619 elfsym
.st_value
= 0;
10620 elfsym
.st_size
= 0;
10621 elfsym
.st_info
= 0;
10622 elfsym
.st_other
= 0;
10623 elfsym
.st_shndx
= SHN_UNDEF
;
10624 elfsym
.st_target_internal
= 0;
10625 if (elf_link_output_sym (&flinfo
, NULL
, &elfsym
, bfd_und_section_ptr
,
10630 /* Output a symbol for each section. We output these even if we are
10631 discarding local symbols, since they are used for relocs. These
10632 symbols have no names. We store the index of each one in the
10633 index field of the section, so that we can find it again when
10634 outputting relocs. */
10635 if (info
->strip
!= strip_all
10638 elfsym
.st_size
= 0;
10639 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
10640 elfsym
.st_other
= 0;
10641 elfsym
.st_value
= 0;
10642 elfsym
.st_target_internal
= 0;
10643 for (i
= 1; i
< elf_numsections (abfd
); i
++)
10645 o
= bfd_section_from_elf_index (abfd
, i
);
10648 o
->target_index
= bfd_get_symcount (abfd
);
10649 elfsym
.st_shndx
= i
;
10650 if (!info
->relocatable
)
10651 elfsym
.st_value
= o
->vma
;
10652 if (elf_link_output_sym (&flinfo
, NULL
, &elfsym
, o
, NULL
) != 1)
10658 /* Allocate some memory to hold information read in from the input
10660 if (max_contents_size
!= 0)
10662 flinfo
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
10663 if (flinfo
.contents
== NULL
)
10667 if (max_external_reloc_size
!= 0)
10669 flinfo
.external_relocs
= bfd_malloc (max_external_reloc_size
);
10670 if (flinfo
.external_relocs
== NULL
)
10674 if (max_internal_reloc_count
!= 0)
10676 amt
= max_internal_reloc_count
* bed
->s
->int_rels_per_ext_rel
;
10677 amt
*= sizeof (Elf_Internal_Rela
);
10678 flinfo
.internal_relocs
= (Elf_Internal_Rela
*) bfd_malloc (amt
);
10679 if (flinfo
.internal_relocs
== NULL
)
10683 if (max_sym_count
!= 0)
10685 amt
= max_sym_count
* bed
->s
->sizeof_sym
;
10686 flinfo
.external_syms
= (bfd_byte
*) bfd_malloc (amt
);
10687 if (flinfo
.external_syms
== NULL
)
10690 amt
= max_sym_count
* sizeof (Elf_Internal_Sym
);
10691 flinfo
.internal_syms
= (Elf_Internal_Sym
*) bfd_malloc (amt
);
10692 if (flinfo
.internal_syms
== NULL
)
10695 amt
= max_sym_count
* sizeof (long);
10696 flinfo
.indices
= (long int *) bfd_malloc (amt
);
10697 if (flinfo
.indices
== NULL
)
10700 amt
= max_sym_count
* sizeof (asection
*);
10701 flinfo
.sections
= (asection
**) bfd_malloc (amt
);
10702 if (flinfo
.sections
== NULL
)
10706 if (max_sym_shndx_count
!= 0)
10708 amt
= max_sym_shndx_count
* sizeof (Elf_External_Sym_Shndx
);
10709 flinfo
.locsym_shndx
= (Elf_External_Sym_Shndx
*) bfd_malloc (amt
);
10710 if (flinfo
.locsym_shndx
== NULL
)
10714 if (elf_hash_table (info
)->tls_sec
)
10716 bfd_vma base
, end
= 0;
10719 for (sec
= elf_hash_table (info
)->tls_sec
;
10720 sec
&& (sec
->flags
& SEC_THREAD_LOCAL
);
10723 bfd_size_type size
= sec
->size
;
10726 && (sec
->flags
& SEC_HAS_CONTENTS
) == 0)
10728 struct bfd_link_order
*ord
= sec
->map_tail
.link_order
;
10731 size
= ord
->offset
+ ord
->size
;
10733 end
= sec
->vma
+ size
;
10735 base
= elf_hash_table (info
)->tls_sec
->vma
;
10736 /* Only align end of TLS section if static TLS doesn't have special
10737 alignment requirements. */
10738 if (bed
->static_tls_alignment
== 1)
10739 end
= align_power (end
,
10740 elf_hash_table (info
)->tls_sec
->alignment_power
);
10741 elf_hash_table (info
)->tls_size
= end
- base
;
10744 /* Reorder SHF_LINK_ORDER sections. */
10745 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10747 if (!elf_fixup_link_order (abfd
, o
))
10751 /* Since ELF permits relocations to be against local symbols, we
10752 must have the local symbols available when we do the relocations.
10753 Since we would rather only read the local symbols once, and we
10754 would rather not keep them in memory, we handle all the
10755 relocations for a single input file at the same time.
10757 Unfortunately, there is no way to know the total number of local
10758 symbols until we have seen all of them, and the local symbol
10759 indices precede the global symbol indices. This means that when
10760 we are generating relocatable output, and we see a reloc against
10761 a global symbol, we can not know the symbol index until we have
10762 finished examining all the local symbols to see which ones we are
10763 going to output. To deal with this, we keep the relocations in
10764 memory, and don't output them until the end of the link. This is
10765 an unfortunate waste of memory, but I don't see a good way around
10766 it. Fortunately, it only happens when performing a relocatable
10767 link, which is not the common case. FIXME: If keep_memory is set
10768 we could write the relocs out and then read them again; I don't
10769 know how bad the memory loss will be. */
10771 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10772 sub
->output_has_begun
= FALSE
;
10773 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10775 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
10777 if (p
->type
== bfd_indirect_link_order
10778 && (bfd_get_flavour ((sub
= p
->u
.indirect
.section
->owner
))
10779 == bfd_target_elf_flavour
)
10780 && elf_elfheader (sub
)->e_ident
[EI_CLASS
] == bed
->s
->elfclass
)
10782 if (! sub
->output_has_begun
)
10784 if (! elf_link_input_bfd (&flinfo
, sub
))
10786 sub
->output_has_begun
= TRUE
;
10789 else if (p
->type
== bfd_section_reloc_link_order
10790 || p
->type
== bfd_symbol_reloc_link_order
)
10792 if (! elf_reloc_link_order (abfd
, info
, o
, p
))
10797 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
10799 if (p
->type
== bfd_indirect_link_order
10800 && (bfd_get_flavour (sub
)
10801 == bfd_target_elf_flavour
)
10802 && (elf_elfheader (sub
)->e_ident
[EI_CLASS
]
10803 != bed
->s
->elfclass
))
10805 const char *iclass
, *oclass
;
10807 if (bed
->s
->elfclass
== ELFCLASS64
)
10809 iclass
= "ELFCLASS32";
10810 oclass
= "ELFCLASS64";
10814 iclass
= "ELFCLASS64";
10815 oclass
= "ELFCLASS32";
10818 bfd_set_error (bfd_error_wrong_format
);
10819 (*_bfd_error_handler
)
10820 (_("%B: file class %s incompatible with %s"),
10821 sub
, iclass
, oclass
);
10830 /* Free symbol buffer if needed. */
10831 if (!info
->reduce_memory_overheads
)
10833 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10834 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
10835 && elf_tdata (sub
)->symbuf
)
10837 free (elf_tdata (sub
)->symbuf
);
10838 elf_tdata (sub
)->symbuf
= NULL
;
10842 /* Output a FILE symbol so that following locals are not associated
10843 with the wrong input file. */
10844 memset (&elfsym
, 0, sizeof (elfsym
));
10845 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FILE
);
10846 elfsym
.st_shndx
= SHN_ABS
;
10848 if (flinfo
.filesym_count
> 1
10849 && !elf_link_output_sym (&flinfo
, NULL
, &elfsym
,
10850 bfd_und_section_ptr
, NULL
))
10853 /* Output any global symbols that got converted to local in a
10854 version script or due to symbol visibility. We do this in a
10855 separate step since ELF requires all local symbols to appear
10856 prior to any global symbols. FIXME: We should only do this if
10857 some global symbols were, in fact, converted to become local.
10858 FIXME: Will this work correctly with the Irix 5 linker? */
10859 eoinfo
.failed
= FALSE
;
10860 eoinfo
.flinfo
= &flinfo
;
10861 eoinfo
.localsyms
= TRUE
;
10862 eoinfo
.need_second_pass
= FALSE
;
10863 eoinfo
.second_pass
= FALSE
;
10864 bfd_hash_traverse (&info
->hash
->table
, elf_link_output_extsym
, &eoinfo
);
10868 if (flinfo
.filesym_count
== 1
10869 && !elf_link_output_sym (&flinfo
, NULL
, &elfsym
,
10870 bfd_und_section_ptr
, NULL
))
10873 if (eoinfo
.need_second_pass
)
10875 eoinfo
.second_pass
= TRUE
;
10876 bfd_hash_traverse (&info
->hash
->table
, elf_link_output_extsym
, &eoinfo
);
10881 /* If backend needs to output some local symbols not present in the hash
10882 table, do it now. */
10883 if (bed
->elf_backend_output_arch_local_syms
)
10885 typedef int (*out_sym_func
)
10886 (void *, const char *, Elf_Internal_Sym
*, asection
*,
10887 struct elf_link_hash_entry
*);
10889 if (! ((*bed
->elf_backend_output_arch_local_syms
)
10890 (abfd
, info
, &flinfo
, (out_sym_func
) elf_link_output_sym
)))
10894 /* That wrote out all the local symbols. Finish up the symbol table
10895 with the global symbols. Even if we want to strip everything we
10896 can, we still need to deal with those global symbols that got
10897 converted to local in a version script. */
10899 /* The sh_info field records the index of the first non local symbol. */
10900 symtab_hdr
->sh_info
= bfd_get_symcount (abfd
);
10903 && flinfo
.dynsym_sec
!= NULL
10904 && flinfo
.dynsym_sec
->output_section
!= bfd_abs_section_ptr
)
10906 Elf_Internal_Sym sym
;
10907 bfd_byte
*dynsym
= flinfo
.dynsym_sec
->contents
;
10908 long last_local
= 0;
10910 /* Write out the section symbols for the output sections. */
10911 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
10917 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
10919 sym
.st_target_internal
= 0;
10921 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10927 dynindx
= elf_section_data (s
)->dynindx
;
10930 indx
= elf_section_data (s
)->this_idx
;
10931 BFD_ASSERT (indx
> 0);
10932 sym
.st_shndx
= indx
;
10933 if (! check_dynsym (abfd
, &sym
))
10935 sym
.st_value
= s
->vma
;
10936 dest
= dynsym
+ dynindx
* bed
->s
->sizeof_sym
;
10937 if (last_local
< dynindx
)
10938 last_local
= dynindx
;
10939 bed
->s
->swap_symbol_out (abfd
, &sym
, dest
, 0);
10943 /* Write out the local dynsyms. */
10944 if (elf_hash_table (info
)->dynlocal
)
10946 struct elf_link_local_dynamic_entry
*e
;
10947 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
10952 /* Copy the internal symbol and turn off visibility.
10953 Note that we saved a word of storage and overwrote
10954 the original st_name with the dynstr_index. */
10956 sym
.st_other
&= ~ELF_ST_VISIBILITY (-1);
10958 s
= bfd_section_from_elf_index (e
->input_bfd
,
10963 elf_section_data (s
->output_section
)->this_idx
;
10964 if (! check_dynsym (abfd
, &sym
))
10966 sym
.st_value
= (s
->output_section
->vma
10968 + e
->isym
.st_value
);
10971 if (last_local
< e
->dynindx
)
10972 last_local
= e
->dynindx
;
10974 dest
= dynsym
+ e
->dynindx
* bed
->s
->sizeof_sym
;
10975 bed
->s
->swap_symbol_out (abfd
, &sym
, dest
, 0);
10979 elf_section_data (flinfo
.dynsym_sec
->output_section
)->this_hdr
.sh_info
=
10983 /* We get the global symbols from the hash table. */
10984 eoinfo
.failed
= FALSE
;
10985 eoinfo
.localsyms
= FALSE
;
10986 eoinfo
.flinfo
= &flinfo
;
10987 bfd_hash_traverse (&info
->hash
->table
, elf_link_output_extsym
, &eoinfo
);
10991 /* If backend needs to output some symbols not present in the hash
10992 table, do it now. */
10993 if (bed
->elf_backend_output_arch_syms
)
10995 typedef int (*out_sym_func
)
10996 (void *, const char *, Elf_Internal_Sym
*, asection
*,
10997 struct elf_link_hash_entry
*);
10999 if (! ((*bed
->elf_backend_output_arch_syms
)
11000 (abfd
, info
, &flinfo
, (out_sym_func
) elf_link_output_sym
)))
11004 /* Flush all symbols to the file. */
11005 if (! elf_link_flush_output_syms (&flinfo
, bed
))
11008 /* Now we know the size of the symtab section. */
11009 off
+= symtab_hdr
->sh_size
;
11011 symtab_shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
11012 if (symtab_shndx_hdr
->sh_name
!= 0)
11014 symtab_shndx_hdr
->sh_type
= SHT_SYMTAB_SHNDX
;
11015 symtab_shndx_hdr
->sh_entsize
= sizeof (Elf_External_Sym_Shndx
);
11016 symtab_shndx_hdr
->sh_addralign
= sizeof (Elf_External_Sym_Shndx
);
11017 amt
= bfd_get_symcount (abfd
) * sizeof (Elf_External_Sym_Shndx
);
11018 symtab_shndx_hdr
->sh_size
= amt
;
11020 off
= _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr
,
11023 if (bfd_seek (abfd
, symtab_shndx_hdr
->sh_offset
, SEEK_SET
) != 0
11024 || (bfd_bwrite (flinfo
.symshndxbuf
, amt
, abfd
) != amt
))
11029 /* Finish up and write out the symbol string table (.strtab)
11031 symstrtab_hdr
= &elf_tdata (abfd
)->strtab_hdr
;
11032 /* sh_name was set in prep_headers. */
11033 symstrtab_hdr
->sh_type
= SHT_STRTAB
;
11034 symstrtab_hdr
->sh_flags
= 0;
11035 symstrtab_hdr
->sh_addr
= 0;
11036 symstrtab_hdr
->sh_size
= _bfd_stringtab_size (flinfo
.symstrtab
);
11037 symstrtab_hdr
->sh_entsize
= 0;
11038 symstrtab_hdr
->sh_link
= 0;
11039 symstrtab_hdr
->sh_info
= 0;
11040 /* sh_offset is set just below. */
11041 symstrtab_hdr
->sh_addralign
= 1;
11043 off
= _bfd_elf_assign_file_position_for_section (symstrtab_hdr
, off
, TRUE
);
11044 elf_tdata (abfd
)->next_file_pos
= off
;
11046 if (bfd_get_symcount (abfd
) > 0)
11048 if (bfd_seek (abfd
, symstrtab_hdr
->sh_offset
, SEEK_SET
) != 0
11049 || ! _bfd_stringtab_emit (abfd
, flinfo
.symstrtab
))
11053 /* Adjust the relocs to have the correct symbol indices. */
11054 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11056 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
11057 if ((o
->flags
& SEC_RELOC
) == 0)
11060 if (esdo
->rel
.hdr
!= NULL
)
11061 elf_link_adjust_relocs (abfd
, &esdo
->rel
);
11062 if (esdo
->rela
.hdr
!= NULL
)
11063 elf_link_adjust_relocs (abfd
, &esdo
->rela
);
11065 /* Set the reloc_count field to 0 to prevent write_relocs from
11066 trying to swap the relocs out itself. */
11067 o
->reloc_count
= 0;
11070 if (dynamic
&& info
->combreloc
&& dynobj
!= NULL
)
11071 relativecount
= elf_link_sort_relocs (abfd
, info
, &reldyn
);
11073 /* If we are linking against a dynamic object, or generating a
11074 shared library, finish up the dynamic linking information. */
11077 bfd_byte
*dyncon
, *dynconend
;
11079 /* Fix up .dynamic entries. */
11080 o
= bfd_get_section_by_name (dynobj
, ".dynamic");
11081 BFD_ASSERT (o
!= NULL
);
11083 dyncon
= o
->contents
;
11084 dynconend
= o
->contents
+ o
->size
;
11085 for (; dyncon
< dynconend
; dyncon
+= bed
->s
->sizeof_dyn
)
11087 Elf_Internal_Dyn dyn
;
11091 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
11098 if (relativecount
> 0 && dyncon
+ bed
->s
->sizeof_dyn
< dynconend
)
11100 switch (elf_section_data (reldyn
)->this_hdr
.sh_type
)
11102 case SHT_REL
: dyn
.d_tag
= DT_RELCOUNT
; break;
11103 case SHT_RELA
: dyn
.d_tag
= DT_RELACOUNT
; break;
11106 dyn
.d_un
.d_val
= relativecount
;
11113 name
= info
->init_function
;
11116 name
= info
->fini_function
;
11119 struct elf_link_hash_entry
*h
;
11121 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
11122 FALSE
, FALSE
, TRUE
);
11124 && (h
->root
.type
== bfd_link_hash_defined
11125 || h
->root
.type
== bfd_link_hash_defweak
))
11127 dyn
.d_un
.d_ptr
= h
->root
.u
.def
.value
;
11128 o
= h
->root
.u
.def
.section
;
11129 if (o
->output_section
!= NULL
)
11130 dyn
.d_un
.d_ptr
+= (o
->output_section
->vma
11131 + o
->output_offset
);
11134 /* The symbol is imported from another shared
11135 library and does not apply to this one. */
11136 dyn
.d_un
.d_ptr
= 0;
11143 case DT_PREINIT_ARRAYSZ
:
11144 name
= ".preinit_array";
11146 case DT_INIT_ARRAYSZ
:
11147 name
= ".init_array";
11149 case DT_FINI_ARRAYSZ
:
11150 name
= ".fini_array";
11152 o
= bfd_get_section_by_name (abfd
, name
);
11155 (*_bfd_error_handler
)
11156 (_("%B: could not find output section %s"), abfd
, name
);
11160 (*_bfd_error_handler
)
11161 (_("warning: %s section has zero size"), name
);
11162 dyn
.d_un
.d_val
= o
->size
;
11165 case DT_PREINIT_ARRAY
:
11166 name
= ".preinit_array";
11168 case DT_INIT_ARRAY
:
11169 name
= ".init_array";
11171 case DT_FINI_ARRAY
:
11172 name
= ".fini_array";
11179 name
= ".gnu.hash";
11188 name
= ".gnu.version_d";
11191 name
= ".gnu.version_r";
11194 name
= ".gnu.version";
11196 o
= bfd_get_section_by_name (abfd
, name
);
11199 (*_bfd_error_handler
)
11200 (_("%B: could not find output section %s"), abfd
, name
);
11203 if (elf_section_data (o
->output_section
)->this_hdr
.sh_type
== SHT_NOTE
)
11205 (*_bfd_error_handler
)
11206 (_("warning: section '%s' is being made into a note"), name
);
11207 bfd_set_error (bfd_error_nonrepresentable_section
);
11210 dyn
.d_un
.d_ptr
= o
->vma
;
11217 if (dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
11221 dyn
.d_un
.d_val
= 0;
11222 dyn
.d_un
.d_ptr
= 0;
11223 for (i
= 1; i
< elf_numsections (abfd
); i
++)
11225 Elf_Internal_Shdr
*hdr
;
11227 hdr
= elf_elfsections (abfd
)[i
];
11228 if (hdr
->sh_type
== type
11229 && (hdr
->sh_flags
& SHF_ALLOC
) != 0)
11231 if (dyn
.d_tag
== DT_RELSZ
|| dyn
.d_tag
== DT_RELASZ
)
11232 dyn
.d_un
.d_val
+= hdr
->sh_size
;
11235 if (dyn
.d_un
.d_ptr
== 0
11236 || hdr
->sh_addr
< dyn
.d_un
.d_ptr
)
11237 dyn
.d_un
.d_ptr
= hdr
->sh_addr
;
11243 bed
->s
->swap_dyn_out (dynobj
, &dyn
, dyncon
);
11247 /* If we have created any dynamic sections, then output them. */
11248 if (dynobj
!= NULL
)
11250 if (! (*bed
->elf_backend_finish_dynamic_sections
) (abfd
, info
))
11253 /* Check for DT_TEXTREL (late, in case the backend removes it). */
11254 if (((info
->warn_shared_textrel
&& info
->shared
)
11255 || info
->error_textrel
)
11256 && (o
= bfd_get_section_by_name (dynobj
, ".dynamic")) != NULL
)
11258 bfd_byte
*dyncon
, *dynconend
;
11260 dyncon
= o
->contents
;
11261 dynconend
= o
->contents
+ o
->size
;
11262 for (; dyncon
< dynconend
; dyncon
+= bed
->s
->sizeof_dyn
)
11264 Elf_Internal_Dyn dyn
;
11266 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
11268 if (dyn
.d_tag
== DT_TEXTREL
)
11270 if (info
->error_textrel
)
11271 info
->callbacks
->einfo
11272 (_("%P%X: read-only segment has dynamic relocations.\n"));
11274 info
->callbacks
->einfo
11275 (_("%P: warning: creating a DT_TEXTREL in a shared object.\n"));
11281 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
11283 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
11285 || o
->output_section
== bfd_abs_section_ptr
)
11287 if ((o
->flags
& SEC_LINKER_CREATED
) == 0)
11289 /* At this point, we are only interested in sections
11290 created by _bfd_elf_link_create_dynamic_sections. */
11293 if (elf_hash_table (info
)->stab_info
.stabstr
== o
)
11295 if (elf_hash_table (info
)->eh_info
.hdr_sec
== o
)
11297 if ((elf_section_data (o
->output_section
)->this_hdr
.sh_type
11299 && (strcmp (bfd_get_section_name (abfd
, o
), ".dynstr") != 0))
11301 /* FIXME: octets_per_byte. */
11302 if (! bfd_set_section_contents (abfd
, o
->output_section
,
11304 (file_ptr
) o
->output_offset
,
11310 /* The contents of the .dynstr section are actually in a
11312 off
= elf_section_data (o
->output_section
)->this_hdr
.sh_offset
;
11313 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0
11314 || ! _bfd_elf_strtab_emit (abfd
,
11315 elf_hash_table (info
)->dynstr
))
11321 if (info
->relocatable
)
11323 bfd_boolean failed
= FALSE
;
11325 bfd_map_over_sections (abfd
, bfd_elf_set_group_contents
, &failed
);
11330 /* If we have optimized stabs strings, output them. */
11331 if (elf_hash_table (info
)->stab_info
.stabstr
!= NULL
)
11333 if (! _bfd_write_stab_strings (abfd
, &elf_hash_table (info
)->stab_info
))
11337 if (info
->eh_frame_hdr
)
11339 if (! _bfd_elf_write_section_eh_frame_hdr (abfd
, info
))
11343 if (flinfo
.symstrtab
!= NULL
)
11344 _bfd_stringtab_free (flinfo
.symstrtab
);
11345 if (flinfo
.contents
!= NULL
)
11346 free (flinfo
.contents
);
11347 if (flinfo
.external_relocs
!= NULL
)
11348 free (flinfo
.external_relocs
);
11349 if (flinfo
.internal_relocs
!= NULL
)
11350 free (flinfo
.internal_relocs
);
11351 if (flinfo
.external_syms
!= NULL
)
11352 free (flinfo
.external_syms
);
11353 if (flinfo
.locsym_shndx
!= NULL
)
11354 free (flinfo
.locsym_shndx
);
11355 if (flinfo
.internal_syms
!= NULL
)
11356 free (flinfo
.internal_syms
);
11357 if (flinfo
.indices
!= NULL
)
11358 free (flinfo
.indices
);
11359 if (flinfo
.sections
!= NULL
)
11360 free (flinfo
.sections
);
11361 if (flinfo
.symbuf
!= NULL
)
11362 free (flinfo
.symbuf
);
11363 if (flinfo
.symshndxbuf
!= NULL
)
11364 free (flinfo
.symshndxbuf
);
11365 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11367 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
11368 if ((o
->flags
& SEC_RELOC
) != 0 && esdo
->rel
.hashes
!= NULL
)
11369 free (esdo
->rel
.hashes
);
11370 if ((o
->flags
& SEC_RELOC
) != 0 && esdo
->rela
.hashes
!= NULL
)
11371 free (esdo
->rela
.hashes
);
11374 elf_tdata (abfd
)->linker
= TRUE
;
11378 bfd_byte
*contents
= (bfd_byte
*) bfd_malloc (attr_size
);
11379 if (contents
== NULL
)
11380 return FALSE
; /* Bail out and fail. */
11381 bfd_elf_set_obj_attr_contents (abfd
, contents
, attr_size
);
11382 bfd_set_section_contents (abfd
, attr_section
, contents
, 0, attr_size
);
11389 if (flinfo
.symstrtab
!= NULL
)
11390 _bfd_stringtab_free (flinfo
.symstrtab
);
11391 if (flinfo
.contents
!= NULL
)
11392 free (flinfo
.contents
);
11393 if (flinfo
.external_relocs
!= NULL
)
11394 free (flinfo
.external_relocs
);
11395 if (flinfo
.internal_relocs
!= NULL
)
11396 free (flinfo
.internal_relocs
);
11397 if (flinfo
.external_syms
!= NULL
)
11398 free (flinfo
.external_syms
);
11399 if (flinfo
.locsym_shndx
!= NULL
)
11400 free (flinfo
.locsym_shndx
);
11401 if (flinfo
.internal_syms
!= NULL
)
11402 free (flinfo
.internal_syms
);
11403 if (flinfo
.indices
!= NULL
)
11404 free (flinfo
.indices
);
11405 if (flinfo
.sections
!= NULL
)
11406 free (flinfo
.sections
);
11407 if (flinfo
.symbuf
!= NULL
)
11408 free (flinfo
.symbuf
);
11409 if (flinfo
.symshndxbuf
!= NULL
)
11410 free (flinfo
.symshndxbuf
);
11411 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11413 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
11414 if ((o
->flags
& SEC_RELOC
) != 0 && esdo
->rel
.hashes
!= NULL
)
11415 free (esdo
->rel
.hashes
);
11416 if ((o
->flags
& SEC_RELOC
) != 0 && esdo
->rela
.hashes
!= NULL
)
11417 free (esdo
->rela
.hashes
);
11423 /* Initialize COOKIE for input bfd ABFD. */
11426 init_reloc_cookie (struct elf_reloc_cookie
*cookie
,
11427 struct bfd_link_info
*info
, bfd
*abfd
)
11429 Elf_Internal_Shdr
*symtab_hdr
;
11430 const struct elf_backend_data
*bed
;
11432 bed
= get_elf_backend_data (abfd
);
11433 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11435 cookie
->abfd
= abfd
;
11436 cookie
->sym_hashes
= elf_sym_hashes (abfd
);
11437 cookie
->bad_symtab
= elf_bad_symtab (abfd
);
11438 if (cookie
->bad_symtab
)
11440 cookie
->locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
11441 cookie
->extsymoff
= 0;
11445 cookie
->locsymcount
= symtab_hdr
->sh_info
;
11446 cookie
->extsymoff
= symtab_hdr
->sh_info
;
11449 if (bed
->s
->arch_size
== 32)
11450 cookie
->r_sym_shift
= 8;
11452 cookie
->r_sym_shift
= 32;
11454 cookie
->locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
11455 if (cookie
->locsyms
== NULL
&& cookie
->locsymcount
!= 0)
11457 cookie
->locsyms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
11458 cookie
->locsymcount
, 0,
11460 if (cookie
->locsyms
== NULL
)
11462 info
->callbacks
->einfo (_("%P%X: can not read symbols: %E\n"));
11465 if (info
->keep_memory
)
11466 symtab_hdr
->contents
= (bfd_byte
*) cookie
->locsyms
;
11471 /* Free the memory allocated by init_reloc_cookie, if appropriate. */
11474 fini_reloc_cookie (struct elf_reloc_cookie
*cookie
, bfd
*abfd
)
11476 Elf_Internal_Shdr
*symtab_hdr
;
11478 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11479 if (cookie
->locsyms
!= NULL
11480 && symtab_hdr
->contents
!= (unsigned char *) cookie
->locsyms
)
11481 free (cookie
->locsyms
);
11484 /* Initialize the relocation information in COOKIE for input section SEC
11485 of input bfd ABFD. */
11488 init_reloc_cookie_rels (struct elf_reloc_cookie
*cookie
,
11489 struct bfd_link_info
*info
, bfd
*abfd
,
11492 const struct elf_backend_data
*bed
;
11494 if (sec
->reloc_count
== 0)
11496 cookie
->rels
= NULL
;
11497 cookie
->relend
= NULL
;
11501 bed
= get_elf_backend_data (abfd
);
11503 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
11504 info
->keep_memory
);
11505 if (cookie
->rels
== NULL
)
11507 cookie
->rel
= cookie
->rels
;
11508 cookie
->relend
= (cookie
->rels
11509 + sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
);
11511 cookie
->rel
= cookie
->rels
;
11515 /* Free the memory allocated by init_reloc_cookie_rels,
11519 fini_reloc_cookie_rels (struct elf_reloc_cookie
*cookie
,
11522 if (cookie
->rels
&& elf_section_data (sec
)->relocs
!= cookie
->rels
)
11523 free (cookie
->rels
);
11526 /* Initialize the whole of COOKIE for input section SEC. */
11529 init_reloc_cookie_for_section (struct elf_reloc_cookie
*cookie
,
11530 struct bfd_link_info
*info
,
11533 if (!init_reloc_cookie (cookie
, info
, sec
->owner
))
11535 if (!init_reloc_cookie_rels (cookie
, info
, sec
->owner
, sec
))
11540 fini_reloc_cookie (cookie
, sec
->owner
);
11545 /* Free the memory allocated by init_reloc_cookie_for_section,
11549 fini_reloc_cookie_for_section (struct elf_reloc_cookie
*cookie
,
11552 fini_reloc_cookie_rels (cookie
, sec
);
11553 fini_reloc_cookie (cookie
, sec
->owner
);
11556 /* Garbage collect unused sections. */
11558 /* Default gc_mark_hook. */
11561 _bfd_elf_gc_mark_hook (asection
*sec
,
11562 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
11563 Elf_Internal_Rela
*rel ATTRIBUTE_UNUSED
,
11564 struct elf_link_hash_entry
*h
,
11565 Elf_Internal_Sym
*sym
)
11567 const char *sec_name
;
11571 switch (h
->root
.type
)
11573 case bfd_link_hash_defined
:
11574 case bfd_link_hash_defweak
:
11575 return h
->root
.u
.def
.section
;
11577 case bfd_link_hash_common
:
11578 return h
->root
.u
.c
.p
->section
;
11580 case bfd_link_hash_undefined
:
11581 case bfd_link_hash_undefweak
:
11582 /* To work around a glibc bug, keep all XXX input sections
11583 when there is an as yet undefined reference to __start_XXX
11584 or __stop_XXX symbols. The linker will later define such
11585 symbols for orphan input sections that have a name
11586 representable as a C identifier. */
11587 if (strncmp (h
->root
.root
.string
, "__start_", 8) == 0)
11588 sec_name
= h
->root
.root
.string
+ 8;
11589 else if (strncmp (h
->root
.root
.string
, "__stop_", 7) == 0)
11590 sec_name
= h
->root
.root
.string
+ 7;
11594 if (sec_name
&& *sec_name
!= '\0')
11598 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
11600 sec
= bfd_get_section_by_name (i
, sec_name
);
11602 sec
->flags
|= SEC_KEEP
;
11612 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
11617 /* COOKIE->rel describes a relocation against section SEC, which is
11618 a section we've decided to keep. Return the section that contains
11619 the relocation symbol, or NULL if no section contains it. */
11622 _bfd_elf_gc_mark_rsec (struct bfd_link_info
*info
, asection
*sec
,
11623 elf_gc_mark_hook_fn gc_mark_hook
,
11624 struct elf_reloc_cookie
*cookie
)
11626 unsigned long r_symndx
;
11627 struct elf_link_hash_entry
*h
;
11629 r_symndx
= cookie
->rel
->r_info
>> cookie
->r_sym_shift
;
11630 if (r_symndx
== STN_UNDEF
)
11633 if (r_symndx
>= cookie
->locsymcount
11634 || ELF_ST_BIND (cookie
->locsyms
[r_symndx
].st_info
) != STB_LOCAL
)
11636 h
= cookie
->sym_hashes
[r_symndx
- cookie
->extsymoff
];
11637 while (h
->root
.type
== bfd_link_hash_indirect
11638 || h
->root
.type
== bfd_link_hash_warning
)
11639 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11641 /* If this symbol is weak and there is a non-weak definition, we
11642 keep the non-weak definition because many backends put
11643 dynamic reloc info on the non-weak definition for code
11644 handling copy relocs. */
11645 if (h
->u
.weakdef
!= NULL
)
11646 h
->u
.weakdef
->mark
= 1;
11647 return (*gc_mark_hook
) (sec
, info
, cookie
->rel
, h
, NULL
);
11650 return (*gc_mark_hook
) (sec
, info
, cookie
->rel
, NULL
,
11651 &cookie
->locsyms
[r_symndx
]);
11654 /* COOKIE->rel describes a relocation against section SEC, which is
11655 a section we've decided to keep. Mark the section that contains
11656 the relocation symbol. */
11659 _bfd_elf_gc_mark_reloc (struct bfd_link_info
*info
,
11661 elf_gc_mark_hook_fn gc_mark_hook
,
11662 struct elf_reloc_cookie
*cookie
)
11666 rsec
= _bfd_elf_gc_mark_rsec (info
, sec
, gc_mark_hook
, cookie
);
11667 if (rsec
&& !rsec
->gc_mark
)
11669 if (bfd_get_flavour (rsec
->owner
) != bfd_target_elf_flavour
11670 || (rsec
->owner
->flags
& DYNAMIC
) != 0)
11672 else if (!_bfd_elf_gc_mark (info
, rsec
, gc_mark_hook
))
11678 /* The mark phase of garbage collection. For a given section, mark
11679 it and any sections in this section's group, and all the sections
11680 which define symbols to which it refers. */
11683 _bfd_elf_gc_mark (struct bfd_link_info
*info
,
11685 elf_gc_mark_hook_fn gc_mark_hook
)
11688 asection
*group_sec
, *eh_frame
;
11692 /* Mark all the sections in the group. */
11693 group_sec
= elf_section_data (sec
)->next_in_group
;
11694 if (group_sec
&& !group_sec
->gc_mark
)
11695 if (!_bfd_elf_gc_mark (info
, group_sec
, gc_mark_hook
))
11698 /* Look through the section relocs. */
11700 eh_frame
= elf_eh_frame_section (sec
->owner
);
11701 if ((sec
->flags
& SEC_RELOC
) != 0
11702 && sec
->reloc_count
> 0
11703 && sec
!= eh_frame
)
11705 struct elf_reloc_cookie cookie
;
11707 if (!init_reloc_cookie_for_section (&cookie
, info
, sec
))
11711 for (; cookie
.rel
< cookie
.relend
; cookie
.rel
++)
11712 if (!_bfd_elf_gc_mark_reloc (info
, sec
, gc_mark_hook
, &cookie
))
11717 fini_reloc_cookie_for_section (&cookie
, sec
);
11721 if (ret
&& eh_frame
&& elf_fde_list (sec
))
11723 struct elf_reloc_cookie cookie
;
11725 if (!init_reloc_cookie_for_section (&cookie
, info
, eh_frame
))
11729 if (!_bfd_elf_gc_mark_fdes (info
, sec
, eh_frame
,
11730 gc_mark_hook
, &cookie
))
11732 fini_reloc_cookie_for_section (&cookie
, eh_frame
);
11739 /* Keep debug and special sections. */
11742 _bfd_elf_gc_mark_extra_sections (struct bfd_link_info
*info
,
11743 elf_gc_mark_hook_fn mark_hook ATTRIBUTE_UNUSED
)
11747 for (ibfd
= info
->input_bfds
; ibfd
!= NULL
; ibfd
= ibfd
->link_next
)
11750 bfd_boolean some_kept
;
11752 if (bfd_get_flavour (ibfd
) != bfd_target_elf_flavour
)
11755 /* Ensure all linker created sections are kept, and see whether
11756 any other section is already marked. */
11758 for (isec
= ibfd
->sections
; isec
!= NULL
; isec
= isec
->next
)
11760 if ((isec
->flags
& SEC_LINKER_CREATED
) != 0)
11762 else if (isec
->gc_mark
)
11766 /* If no section in this file will be kept, then we can
11767 toss out debug sections. */
11771 /* Keep debug and special sections like .comment when they are
11772 not part of a group, or when we have single-member groups. */
11773 for (isec
= ibfd
->sections
; isec
!= NULL
; isec
= isec
->next
)
11774 if ((elf_next_in_group (isec
) == NULL
11775 || elf_next_in_group (isec
) == isec
)
11776 && ((isec
->flags
& SEC_DEBUGGING
) != 0
11777 || (isec
->flags
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
)) == 0))
11783 /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */
11785 struct elf_gc_sweep_symbol_info
11787 struct bfd_link_info
*info
;
11788 void (*hide_symbol
) (struct bfd_link_info
*, struct elf_link_hash_entry
*,
11793 elf_gc_sweep_symbol (struct elf_link_hash_entry
*h
, void *data
)
11796 && (((h
->root
.type
== bfd_link_hash_defined
11797 || h
->root
.type
== bfd_link_hash_defweak
)
11798 && !(h
->def_regular
11799 && h
->root
.u
.def
.section
->gc_mark
))
11800 || h
->root
.type
== bfd_link_hash_undefined
11801 || h
->root
.type
== bfd_link_hash_undefweak
))
11803 struct elf_gc_sweep_symbol_info
*inf
;
11805 inf
= (struct elf_gc_sweep_symbol_info
*) data
;
11806 (*inf
->hide_symbol
) (inf
->info
, h
, TRUE
);
11807 h
->def_regular
= 0;
11808 h
->ref_regular
= 0;
11809 h
->ref_regular_nonweak
= 0;
11815 /* The sweep phase of garbage collection. Remove all garbage sections. */
11817 typedef bfd_boolean (*gc_sweep_hook_fn
)
11818 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
11821 elf_gc_sweep (bfd
*abfd
, struct bfd_link_info
*info
)
11824 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11825 gc_sweep_hook_fn gc_sweep_hook
= bed
->gc_sweep_hook
;
11826 unsigned long section_sym_count
;
11827 struct elf_gc_sweep_symbol_info sweep_info
;
11829 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
11833 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
11836 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
11838 /* When any section in a section group is kept, we keep all
11839 sections in the section group. If the first member of
11840 the section group is excluded, we will also exclude the
11842 if (o
->flags
& SEC_GROUP
)
11844 asection
*first
= elf_next_in_group (o
);
11845 o
->gc_mark
= first
->gc_mark
;
11851 /* Skip sweeping sections already excluded. */
11852 if (o
->flags
& SEC_EXCLUDE
)
11855 /* Since this is early in the link process, it is simple
11856 to remove a section from the output. */
11857 o
->flags
|= SEC_EXCLUDE
;
11859 if (info
->print_gc_sections
&& o
->size
!= 0)
11860 _bfd_error_handler (_("Removing unused section '%s' in file '%B'"), sub
, o
->name
);
11862 /* But we also have to update some of the relocation
11863 info we collected before. */
11865 && (o
->flags
& SEC_RELOC
) != 0
11866 && o
->reloc_count
> 0
11867 && !bfd_is_abs_section (o
->output_section
))
11869 Elf_Internal_Rela
*internal_relocs
;
11873 = _bfd_elf_link_read_relocs (o
->owner
, o
, NULL
, NULL
,
11874 info
->keep_memory
);
11875 if (internal_relocs
== NULL
)
11878 r
= (*gc_sweep_hook
) (o
->owner
, info
, o
, internal_relocs
);
11880 if (elf_section_data (o
)->relocs
!= internal_relocs
)
11881 free (internal_relocs
);
11889 /* Remove the symbols that were in the swept sections from the dynamic
11890 symbol table. GCFIXME: Anyone know how to get them out of the
11891 static symbol table as well? */
11892 sweep_info
.info
= info
;
11893 sweep_info
.hide_symbol
= bed
->elf_backend_hide_symbol
;
11894 elf_link_hash_traverse (elf_hash_table (info
), elf_gc_sweep_symbol
,
11897 _bfd_elf_link_renumber_dynsyms (abfd
, info
, §ion_sym_count
);
11901 /* Propagate collected vtable information. This is called through
11902 elf_link_hash_traverse. */
11905 elf_gc_propagate_vtable_entries_used (struct elf_link_hash_entry
*h
, void *okp
)
11907 /* Those that are not vtables. */
11908 if (h
->vtable
== NULL
|| h
->vtable
->parent
== NULL
)
11911 /* Those vtables that do not have parents, we cannot merge. */
11912 if (h
->vtable
->parent
== (struct elf_link_hash_entry
*) -1)
11915 /* If we've already been done, exit. */
11916 if (h
->vtable
->used
&& h
->vtable
->used
[-1])
11919 /* Make sure the parent's table is up to date. */
11920 elf_gc_propagate_vtable_entries_used (h
->vtable
->parent
, okp
);
11922 if (h
->vtable
->used
== NULL
)
11924 /* None of this table's entries were referenced. Re-use the
11926 h
->vtable
->used
= h
->vtable
->parent
->vtable
->used
;
11927 h
->vtable
->size
= h
->vtable
->parent
->vtable
->size
;
11932 bfd_boolean
*cu
, *pu
;
11934 /* Or the parent's entries into ours. */
11935 cu
= h
->vtable
->used
;
11937 pu
= h
->vtable
->parent
->vtable
->used
;
11940 const struct elf_backend_data
*bed
;
11941 unsigned int log_file_align
;
11943 bed
= get_elf_backend_data (h
->root
.u
.def
.section
->owner
);
11944 log_file_align
= bed
->s
->log_file_align
;
11945 n
= h
->vtable
->parent
->vtable
->size
>> log_file_align
;
11960 elf_gc_smash_unused_vtentry_relocs (struct elf_link_hash_entry
*h
, void *okp
)
11963 bfd_vma hstart
, hend
;
11964 Elf_Internal_Rela
*relstart
, *relend
, *rel
;
11965 const struct elf_backend_data
*bed
;
11966 unsigned int log_file_align
;
11968 /* Take care of both those symbols that do not describe vtables as
11969 well as those that are not loaded. */
11970 if (h
->vtable
== NULL
|| h
->vtable
->parent
== NULL
)
11973 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
11974 || h
->root
.type
== bfd_link_hash_defweak
);
11976 sec
= h
->root
.u
.def
.section
;
11977 hstart
= h
->root
.u
.def
.value
;
11978 hend
= hstart
+ h
->size
;
11980 relstart
= _bfd_elf_link_read_relocs (sec
->owner
, sec
, NULL
, NULL
, TRUE
);
11982 return *(bfd_boolean
*) okp
= FALSE
;
11983 bed
= get_elf_backend_data (sec
->owner
);
11984 log_file_align
= bed
->s
->log_file_align
;
11986 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
11988 for (rel
= relstart
; rel
< relend
; ++rel
)
11989 if (rel
->r_offset
>= hstart
&& rel
->r_offset
< hend
)
11991 /* If the entry is in use, do nothing. */
11992 if (h
->vtable
->used
11993 && (rel
->r_offset
- hstart
) < h
->vtable
->size
)
11995 bfd_vma entry
= (rel
->r_offset
- hstart
) >> log_file_align
;
11996 if (h
->vtable
->used
[entry
])
11999 /* Otherwise, kill it. */
12000 rel
->r_offset
= rel
->r_info
= rel
->r_addend
= 0;
12006 /* Mark sections containing dynamically referenced symbols. When
12007 building shared libraries, we must assume that any visible symbol is
12011 bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry
*h
, void *inf
)
12013 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
12015 if ((h
->root
.type
== bfd_link_hash_defined
12016 || h
->root
.type
== bfd_link_hash_defweak
)
12018 || ((!info
->executable
|| info
->export_dynamic
)
12020 && ELF_ST_VISIBILITY (h
->other
) != STV_INTERNAL
12021 && ELF_ST_VISIBILITY (h
->other
) != STV_HIDDEN
12022 && (strchr (h
->root
.root
.string
, ELF_VER_CHR
) != NULL
12023 || !bfd_hide_sym_by_version (info
->version_info
,
12024 h
->root
.root
.string
)))))
12025 h
->root
.u
.def
.section
->flags
|= SEC_KEEP
;
12030 /* Keep all sections containing symbols undefined on the command-line,
12031 and the section containing the entry symbol. */
12034 _bfd_elf_gc_keep (struct bfd_link_info
*info
)
12036 struct bfd_sym_chain
*sym
;
12038 for (sym
= info
->gc_sym_list
; sym
!= NULL
; sym
= sym
->next
)
12040 struct elf_link_hash_entry
*h
;
12042 h
= elf_link_hash_lookup (elf_hash_table (info
), sym
->name
,
12043 FALSE
, FALSE
, FALSE
);
12046 && (h
->root
.type
== bfd_link_hash_defined
12047 || h
->root
.type
== bfd_link_hash_defweak
)
12048 && !bfd_is_abs_section (h
->root
.u
.def
.section
))
12049 h
->root
.u
.def
.section
->flags
|= SEC_KEEP
;
12053 /* Do mark and sweep of unused sections. */
12056 bfd_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
12058 bfd_boolean ok
= TRUE
;
12060 elf_gc_mark_hook_fn gc_mark_hook
;
12061 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12063 if (!bed
->can_gc_sections
12064 || !is_elf_hash_table (info
->hash
))
12066 (*_bfd_error_handler
)(_("Warning: gc-sections option ignored"));
12070 bed
->gc_keep (info
);
12072 /* Try to parse each bfd's .eh_frame section. Point elf_eh_frame_section
12073 at the .eh_frame section if we can mark the FDEs individually. */
12074 _bfd_elf_begin_eh_frame_parsing (info
);
12075 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
12078 struct elf_reloc_cookie cookie
;
12080 sec
= bfd_get_section_by_name (sub
, ".eh_frame");
12081 while (sec
&& init_reloc_cookie_for_section (&cookie
, info
, sec
))
12083 _bfd_elf_parse_eh_frame (sub
, info
, sec
, &cookie
);
12084 if (elf_section_data (sec
)->sec_info
12085 && (sec
->flags
& SEC_LINKER_CREATED
) == 0)
12086 elf_eh_frame_section (sub
) = sec
;
12087 fini_reloc_cookie_for_section (&cookie
, sec
);
12088 sec
= bfd_get_next_section_by_name (sec
);
12091 _bfd_elf_end_eh_frame_parsing (info
);
12093 /* Apply transitive closure to the vtable entry usage info. */
12094 elf_link_hash_traverse (elf_hash_table (info
),
12095 elf_gc_propagate_vtable_entries_used
,
12100 /* Kill the vtable relocations that were not used. */
12101 elf_link_hash_traverse (elf_hash_table (info
),
12102 elf_gc_smash_unused_vtentry_relocs
,
12107 /* Mark dynamically referenced symbols. */
12108 if (elf_hash_table (info
)->dynamic_sections_created
)
12109 elf_link_hash_traverse (elf_hash_table (info
),
12110 bed
->gc_mark_dynamic_ref
,
12113 /* Grovel through relocs to find out who stays ... */
12114 gc_mark_hook
= bed
->gc_mark_hook
;
12115 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
12119 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
12122 /* Start at sections marked with SEC_KEEP (ref _bfd_elf_gc_keep).
12123 Also treat note sections as a root, if the section is not part
12125 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
12127 && (o
->flags
& SEC_EXCLUDE
) == 0
12128 && ((o
->flags
& SEC_KEEP
) != 0
12129 || (elf_section_data (o
)->this_hdr
.sh_type
== SHT_NOTE
12130 && elf_next_in_group (o
) == NULL
)))
12132 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
12137 /* Allow the backend to mark additional target specific sections. */
12138 bed
->gc_mark_extra_sections (info
, gc_mark_hook
);
12140 /* ... and mark SEC_EXCLUDE for those that go. */
12141 return elf_gc_sweep (abfd
, info
);
12144 /* Called from check_relocs to record the existence of a VTINHERIT reloc. */
12147 bfd_elf_gc_record_vtinherit (bfd
*abfd
,
12149 struct elf_link_hash_entry
*h
,
12152 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
12153 struct elf_link_hash_entry
**search
, *child
;
12154 bfd_size_type extsymcount
;
12155 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12157 /* The sh_info field of the symtab header tells us where the
12158 external symbols start. We don't care about the local symbols at
12160 extsymcount
= elf_tdata (abfd
)->symtab_hdr
.sh_size
/ bed
->s
->sizeof_sym
;
12161 if (!elf_bad_symtab (abfd
))
12162 extsymcount
-= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
12164 sym_hashes
= elf_sym_hashes (abfd
);
12165 sym_hashes_end
= sym_hashes
+ extsymcount
;
12167 /* Hunt down the child symbol, which is in this section at the same
12168 offset as the relocation. */
12169 for (search
= sym_hashes
; search
!= sym_hashes_end
; ++search
)
12171 if ((child
= *search
) != NULL
12172 && (child
->root
.type
== bfd_link_hash_defined
12173 || child
->root
.type
== bfd_link_hash_defweak
)
12174 && child
->root
.u
.def
.section
== sec
12175 && child
->root
.u
.def
.value
== offset
)
12179 (*_bfd_error_handler
) ("%B: %A+%lu: No symbol found for INHERIT",
12180 abfd
, sec
, (unsigned long) offset
);
12181 bfd_set_error (bfd_error_invalid_operation
);
12185 if (!child
->vtable
)
12187 child
->vtable
= (struct elf_link_virtual_table_entry
*)
12188 bfd_zalloc (abfd
, sizeof (*child
->vtable
));
12189 if (!child
->vtable
)
12194 /* This *should* only be the absolute section. It could potentially
12195 be that someone has defined a non-global vtable though, which
12196 would be bad. It isn't worth paging in the local symbols to be
12197 sure though; that case should simply be handled by the assembler. */
12199 child
->vtable
->parent
= (struct elf_link_hash_entry
*) -1;
12202 child
->vtable
->parent
= h
;
12207 /* Called from check_relocs to record the existence of a VTENTRY reloc. */
12210 bfd_elf_gc_record_vtentry (bfd
*abfd ATTRIBUTE_UNUSED
,
12211 asection
*sec ATTRIBUTE_UNUSED
,
12212 struct elf_link_hash_entry
*h
,
12215 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12216 unsigned int log_file_align
= bed
->s
->log_file_align
;
12220 h
->vtable
= (struct elf_link_virtual_table_entry
*)
12221 bfd_zalloc (abfd
, sizeof (*h
->vtable
));
12226 if (addend
>= h
->vtable
->size
)
12228 size_t size
, bytes
, file_align
;
12229 bfd_boolean
*ptr
= h
->vtable
->used
;
12231 /* While the symbol is undefined, we have to be prepared to handle
12233 file_align
= 1 << log_file_align
;
12234 if (h
->root
.type
== bfd_link_hash_undefined
)
12235 size
= addend
+ file_align
;
12239 if (addend
>= size
)
12241 /* Oops! We've got a reference past the defined end of
12242 the table. This is probably a bug -- shall we warn? */
12243 size
= addend
+ file_align
;
12246 size
= (size
+ file_align
- 1) & -file_align
;
12248 /* Allocate one extra entry for use as a "done" flag for the
12249 consolidation pass. */
12250 bytes
= ((size
>> log_file_align
) + 1) * sizeof (bfd_boolean
);
12254 ptr
= (bfd_boolean
*) bfd_realloc (ptr
- 1, bytes
);
12260 oldbytes
= (((h
->vtable
->size
>> log_file_align
) + 1)
12261 * sizeof (bfd_boolean
));
12262 memset (((char *) ptr
) + oldbytes
, 0, bytes
- oldbytes
);
12266 ptr
= (bfd_boolean
*) bfd_zmalloc (bytes
);
12271 /* And arrange for that done flag to be at index -1. */
12272 h
->vtable
->used
= ptr
+ 1;
12273 h
->vtable
->size
= size
;
12276 h
->vtable
->used
[addend
>> log_file_align
] = TRUE
;
12281 /* Map an ELF section header flag to its corresponding string. */
12285 flagword flag_value
;
12286 } elf_flags_to_name_table
;
12288 static elf_flags_to_name_table elf_flags_to_names
[] =
12290 { "SHF_WRITE", SHF_WRITE
},
12291 { "SHF_ALLOC", SHF_ALLOC
},
12292 { "SHF_EXECINSTR", SHF_EXECINSTR
},
12293 { "SHF_MERGE", SHF_MERGE
},
12294 { "SHF_STRINGS", SHF_STRINGS
},
12295 { "SHF_INFO_LINK", SHF_INFO_LINK
},
12296 { "SHF_LINK_ORDER", SHF_LINK_ORDER
},
12297 { "SHF_OS_NONCONFORMING", SHF_OS_NONCONFORMING
},
12298 { "SHF_GROUP", SHF_GROUP
},
12299 { "SHF_TLS", SHF_TLS
},
12300 { "SHF_MASKOS", SHF_MASKOS
},
12301 { "SHF_EXCLUDE", SHF_EXCLUDE
},
12304 /* Returns TRUE if the section is to be included, otherwise FALSE. */
12306 bfd_elf_lookup_section_flags (struct bfd_link_info
*info
,
12307 struct flag_info
*flaginfo
,
12310 const bfd_vma sh_flags
= elf_section_flags (section
);
12312 if (!flaginfo
->flags_initialized
)
12314 bfd
*obfd
= info
->output_bfd
;
12315 const struct elf_backend_data
*bed
= get_elf_backend_data (obfd
);
12316 struct flag_info_list
*tf
= flaginfo
->flag_list
;
12318 int without_hex
= 0;
12320 for (tf
= flaginfo
->flag_list
; tf
!= NULL
; tf
= tf
->next
)
12323 flagword (*lookup
) (char *);
12325 lookup
= bed
->elf_backend_lookup_section_flags_hook
;
12326 if (lookup
!= NULL
)
12328 flagword hexval
= (*lookup
) ((char *) tf
->name
);
12332 if (tf
->with
== with_flags
)
12333 with_hex
|= hexval
;
12334 else if (tf
->with
== without_flags
)
12335 without_hex
|= hexval
;
12340 for (i
= 0; i
< ARRAY_SIZE (elf_flags_to_names
); ++i
)
12342 if (strcmp (tf
->name
, elf_flags_to_names
[i
].flag_name
) == 0)
12344 if (tf
->with
== with_flags
)
12345 with_hex
|= elf_flags_to_names
[i
].flag_value
;
12346 else if (tf
->with
== without_flags
)
12347 without_hex
|= elf_flags_to_names
[i
].flag_value
;
12354 info
->callbacks
->einfo
12355 (_("Unrecognized INPUT_SECTION_FLAG %s\n"), tf
->name
);
12359 flaginfo
->flags_initialized
= TRUE
;
12360 flaginfo
->only_with_flags
|= with_hex
;
12361 flaginfo
->not_with_flags
|= without_hex
;
12364 if ((flaginfo
->only_with_flags
& sh_flags
) != flaginfo
->only_with_flags
)
12367 if ((flaginfo
->not_with_flags
& sh_flags
) != 0)
12373 struct alloc_got_off_arg
{
12375 struct bfd_link_info
*info
;
12378 /* We need a special top-level link routine to convert got reference counts
12379 to real got offsets. */
12382 elf_gc_allocate_got_offsets (struct elf_link_hash_entry
*h
, void *arg
)
12384 struct alloc_got_off_arg
*gofarg
= (struct alloc_got_off_arg
*) arg
;
12385 bfd
*obfd
= gofarg
->info
->output_bfd
;
12386 const struct elf_backend_data
*bed
= get_elf_backend_data (obfd
);
12388 if (h
->got
.refcount
> 0)
12390 h
->got
.offset
= gofarg
->gotoff
;
12391 gofarg
->gotoff
+= bed
->got_elt_size (obfd
, gofarg
->info
, h
, NULL
, 0);
12394 h
->got
.offset
= (bfd_vma
) -1;
12399 /* And an accompanying bit to work out final got entry offsets once
12400 we're done. Should be called from final_link. */
12403 bfd_elf_gc_common_finalize_got_offsets (bfd
*abfd
,
12404 struct bfd_link_info
*info
)
12407 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12409 struct alloc_got_off_arg gofarg
;
12411 BFD_ASSERT (abfd
== info
->output_bfd
);
12413 if (! is_elf_hash_table (info
->hash
))
12416 /* The GOT offset is relative to the .got section, but the GOT header is
12417 put into the .got.plt section, if the backend uses it. */
12418 if (bed
->want_got_plt
)
12421 gotoff
= bed
->got_header_size
;
12423 /* Do the local .got entries first. */
12424 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
12426 bfd_signed_vma
*local_got
;
12427 bfd_size_type j
, locsymcount
;
12428 Elf_Internal_Shdr
*symtab_hdr
;
12430 if (bfd_get_flavour (i
) != bfd_target_elf_flavour
)
12433 local_got
= elf_local_got_refcounts (i
);
12437 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
12438 if (elf_bad_symtab (i
))
12439 locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
12441 locsymcount
= symtab_hdr
->sh_info
;
12443 for (j
= 0; j
< locsymcount
; ++j
)
12445 if (local_got
[j
] > 0)
12447 local_got
[j
] = gotoff
;
12448 gotoff
+= bed
->got_elt_size (abfd
, info
, NULL
, i
, j
);
12451 local_got
[j
] = (bfd_vma
) -1;
12455 /* Then the global .got entries. .plt refcounts are handled by
12456 adjust_dynamic_symbol */
12457 gofarg
.gotoff
= gotoff
;
12458 gofarg
.info
= info
;
12459 elf_link_hash_traverse (elf_hash_table (info
),
12460 elf_gc_allocate_got_offsets
,
12465 /* Many folk need no more in the way of final link than this, once
12466 got entry reference counting is enabled. */
12469 bfd_elf_gc_common_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
12471 if (!bfd_elf_gc_common_finalize_got_offsets (abfd
, info
))
12474 /* Invoke the regular ELF backend linker to do all the work. */
12475 return bfd_elf_final_link (abfd
, info
);
12479 bfd_elf_reloc_symbol_deleted_p (bfd_vma offset
, void *cookie
)
12481 struct elf_reloc_cookie
*rcookie
= (struct elf_reloc_cookie
*) cookie
;
12483 if (rcookie
->bad_symtab
)
12484 rcookie
->rel
= rcookie
->rels
;
12486 for (; rcookie
->rel
< rcookie
->relend
; rcookie
->rel
++)
12488 unsigned long r_symndx
;
12490 if (! rcookie
->bad_symtab
)
12491 if (rcookie
->rel
->r_offset
> offset
)
12493 if (rcookie
->rel
->r_offset
!= offset
)
12496 r_symndx
= rcookie
->rel
->r_info
>> rcookie
->r_sym_shift
;
12497 if (r_symndx
== STN_UNDEF
)
12500 if (r_symndx
>= rcookie
->locsymcount
12501 || ELF_ST_BIND (rcookie
->locsyms
[r_symndx
].st_info
) != STB_LOCAL
)
12503 struct elf_link_hash_entry
*h
;
12505 h
= rcookie
->sym_hashes
[r_symndx
- rcookie
->extsymoff
];
12507 while (h
->root
.type
== bfd_link_hash_indirect
12508 || h
->root
.type
== bfd_link_hash_warning
)
12509 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
12511 if ((h
->root
.type
== bfd_link_hash_defined
12512 || h
->root
.type
== bfd_link_hash_defweak
)
12513 && discarded_section (h
->root
.u
.def
.section
))
12520 /* It's not a relocation against a global symbol,
12521 but it could be a relocation against a local
12522 symbol for a discarded section. */
12524 Elf_Internal_Sym
*isym
;
12526 /* Need to: get the symbol; get the section. */
12527 isym
= &rcookie
->locsyms
[r_symndx
];
12528 isec
= bfd_section_from_elf_index (rcookie
->abfd
, isym
->st_shndx
);
12529 if (isec
!= NULL
&& discarded_section (isec
))
12537 /* Discard unneeded references to discarded sections.
12538 Returns TRUE if any section's size was changed. */
12539 /* This function assumes that the relocations are in sorted order,
12540 which is true for all known assemblers. */
12543 bfd_elf_discard_info (bfd
*output_bfd
, struct bfd_link_info
*info
)
12545 struct elf_reloc_cookie cookie
;
12546 asection
*stab
, *eh
;
12547 const struct elf_backend_data
*bed
;
12549 bfd_boolean ret
= FALSE
;
12551 if (info
->traditional_format
12552 || !is_elf_hash_table (info
->hash
))
12555 _bfd_elf_begin_eh_frame_parsing (info
);
12556 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
12558 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
12561 bed
= get_elf_backend_data (abfd
);
12564 if (!info
->relocatable
)
12566 eh
= bfd_get_section_by_name (abfd
, ".eh_frame");
12569 || bfd_is_abs_section (eh
->output_section
)))
12570 eh
= bfd_get_next_section_by_name (eh
);
12573 stab
= bfd_get_section_by_name (abfd
, ".stab");
12575 && (stab
->size
== 0
12576 || bfd_is_abs_section (stab
->output_section
)
12577 || stab
->sec_info_type
!= SEC_INFO_TYPE_STABS
))
12582 && bed
->elf_backend_discard_info
== NULL
)
12585 if (!init_reloc_cookie (&cookie
, info
, abfd
))
12589 && stab
->reloc_count
> 0
12590 && init_reloc_cookie_rels (&cookie
, info
, abfd
, stab
))
12592 if (_bfd_discard_section_stabs (abfd
, stab
,
12593 elf_section_data (stab
)->sec_info
,
12594 bfd_elf_reloc_symbol_deleted_p
,
12597 fini_reloc_cookie_rels (&cookie
, stab
);
12601 && init_reloc_cookie_rels (&cookie
, info
, abfd
, eh
))
12603 _bfd_elf_parse_eh_frame (abfd
, info
, eh
, &cookie
);
12604 if (_bfd_elf_discard_section_eh_frame (abfd
, info
, eh
,
12605 bfd_elf_reloc_symbol_deleted_p
,
12608 fini_reloc_cookie_rels (&cookie
, eh
);
12609 eh
= bfd_get_next_section_by_name (eh
);
12612 if (bed
->elf_backend_discard_info
!= NULL
12613 && (*bed
->elf_backend_discard_info
) (abfd
, &cookie
, info
))
12616 fini_reloc_cookie (&cookie
, abfd
);
12618 _bfd_elf_end_eh_frame_parsing (info
);
12620 if (info
->eh_frame_hdr
12621 && !info
->relocatable
12622 && _bfd_elf_discard_section_eh_frame_hdr (output_bfd
, info
))
12629 _bfd_elf_section_already_linked (bfd
*abfd
,
12631 struct bfd_link_info
*info
)
12634 const char *name
, *key
;
12635 struct bfd_section_already_linked
*l
;
12636 struct bfd_section_already_linked_hash_entry
*already_linked_list
;
12638 if (sec
->output_section
== bfd_abs_section_ptr
)
12641 flags
= sec
->flags
;
12643 /* Return if it isn't a linkonce section. A comdat group section
12644 also has SEC_LINK_ONCE set. */
12645 if ((flags
& SEC_LINK_ONCE
) == 0)
12648 /* Don't put group member sections on our list of already linked
12649 sections. They are handled as a group via their group section. */
12650 if (elf_sec_group (sec
) != NULL
)
12653 /* For a SHT_GROUP section, use the group signature as the key. */
12655 if ((flags
& SEC_GROUP
) != 0
12656 && elf_next_in_group (sec
) != NULL
12657 && elf_group_name (elf_next_in_group (sec
)) != NULL
)
12658 key
= elf_group_name (elf_next_in_group (sec
));
12661 /* Otherwise we should have a .gnu.linkonce.<type>.<key> section. */
12662 if (CONST_STRNEQ (name
, ".gnu.linkonce.")
12663 && (key
= strchr (name
+ sizeof (".gnu.linkonce.") - 1, '.')) != NULL
)
12666 /* Must be a user linkonce section that doesn't follow gcc's
12667 naming convention. In this case we won't be matching
12668 single member groups. */
12672 already_linked_list
= bfd_section_already_linked_table_lookup (key
);
12674 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
12676 /* We may have 2 different types of sections on the list: group
12677 sections with a signature of <key> (<key> is some string),
12678 and linkonce sections named .gnu.linkonce.<type>.<key>.
12679 Match like sections. LTO plugin sections are an exception.
12680 They are always named .gnu.linkonce.t.<key> and match either
12681 type of section. */
12682 if (((flags
& SEC_GROUP
) == (l
->sec
->flags
& SEC_GROUP
)
12683 && ((flags
& SEC_GROUP
) != 0
12684 || strcmp (name
, l
->sec
->name
) == 0))
12685 || (l
->sec
->owner
->flags
& BFD_PLUGIN
) != 0)
12687 /* The section has already been linked. See if we should
12688 issue a warning. */
12689 if (!_bfd_handle_already_linked (sec
, l
, info
))
12692 if (flags
& SEC_GROUP
)
12694 asection
*first
= elf_next_in_group (sec
);
12695 asection
*s
= first
;
12699 s
->output_section
= bfd_abs_section_ptr
;
12700 /* Record which group discards it. */
12701 s
->kept_section
= l
->sec
;
12702 s
= elf_next_in_group (s
);
12703 /* These lists are circular. */
12713 /* A single member comdat group section may be discarded by a
12714 linkonce section and vice versa. */
12715 if ((flags
& SEC_GROUP
) != 0)
12717 asection
*first
= elf_next_in_group (sec
);
12719 if (first
!= NULL
&& elf_next_in_group (first
) == first
)
12720 /* Check this single member group against linkonce sections. */
12721 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
12722 if ((l
->sec
->flags
& SEC_GROUP
) == 0
12723 && bfd_elf_match_symbols_in_sections (l
->sec
, first
, info
))
12725 first
->output_section
= bfd_abs_section_ptr
;
12726 first
->kept_section
= l
->sec
;
12727 sec
->output_section
= bfd_abs_section_ptr
;
12732 /* Check this linkonce section against single member groups. */
12733 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
12734 if (l
->sec
->flags
& SEC_GROUP
)
12736 asection
*first
= elf_next_in_group (l
->sec
);
12739 && elf_next_in_group (first
) == first
12740 && bfd_elf_match_symbols_in_sections (first
, sec
, info
))
12742 sec
->output_section
= bfd_abs_section_ptr
;
12743 sec
->kept_section
= first
;
12748 /* Do not complain on unresolved relocations in `.gnu.linkonce.r.F'
12749 referencing its discarded `.gnu.linkonce.t.F' counterpart - g++-3.4
12750 specific as g++-4.x is using COMDAT groups (without the `.gnu.linkonce'
12751 prefix) instead. `.gnu.linkonce.r.*' were the `.rodata' part of its
12752 matching `.gnu.linkonce.t.*'. If `.gnu.linkonce.r.F' is not discarded
12753 but its `.gnu.linkonce.t.F' is discarded means we chose one-only
12754 `.gnu.linkonce.t.F' section from a different bfd not requiring any
12755 `.gnu.linkonce.r.F'. Thus `.gnu.linkonce.r.F' should be discarded.
12756 The reverse order cannot happen as there is never a bfd with only the
12757 `.gnu.linkonce.r.F' section. The order of sections in a bfd does not
12758 matter as here were are looking only for cross-bfd sections. */
12760 if ((flags
& SEC_GROUP
) == 0 && CONST_STRNEQ (name
, ".gnu.linkonce.r."))
12761 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
12762 if ((l
->sec
->flags
& SEC_GROUP
) == 0
12763 && CONST_STRNEQ (l
->sec
->name
, ".gnu.linkonce.t."))
12765 if (abfd
!= l
->sec
->owner
)
12766 sec
->output_section
= bfd_abs_section_ptr
;
12770 /* This is the first section with this name. Record it. */
12771 if (!bfd_section_already_linked_table_insert (already_linked_list
, sec
))
12772 info
->callbacks
->einfo (_("%F%P: already_linked_table: %E\n"));
12773 return sec
->output_section
== bfd_abs_section_ptr
;
12777 _bfd_elf_common_definition (Elf_Internal_Sym
*sym
)
12779 return sym
->st_shndx
== SHN_COMMON
;
12783 _bfd_elf_common_section_index (asection
*sec ATTRIBUTE_UNUSED
)
12789 _bfd_elf_common_section (asection
*sec ATTRIBUTE_UNUSED
)
12791 return bfd_com_section_ptr
;
12795 _bfd_elf_default_got_elt_size (bfd
*abfd
,
12796 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
12797 struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
,
12798 bfd
*ibfd ATTRIBUTE_UNUSED
,
12799 unsigned long symndx ATTRIBUTE_UNUSED
)
12801 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12802 return bed
->s
->arch_size
/ 8;
12805 /* Routines to support the creation of dynamic relocs. */
12807 /* Returns the name of the dynamic reloc section associated with SEC. */
12809 static const char *
12810 get_dynamic_reloc_section_name (bfd
* abfd
,
12812 bfd_boolean is_rela
)
12815 const char *old_name
= bfd_get_section_name (NULL
, sec
);
12816 const char *prefix
= is_rela
? ".rela" : ".rel";
12818 if (old_name
== NULL
)
12821 name
= bfd_alloc (abfd
, strlen (prefix
) + strlen (old_name
) + 1);
12822 sprintf (name
, "%s%s", prefix
, old_name
);
12827 /* Returns the dynamic reloc section associated with SEC.
12828 If necessary compute the name of the dynamic reloc section based
12829 on SEC's name (looked up in ABFD's string table) and the setting
12833 _bfd_elf_get_dynamic_reloc_section (bfd
* abfd
,
12835 bfd_boolean is_rela
)
12837 asection
* reloc_sec
= elf_section_data (sec
)->sreloc
;
12839 if (reloc_sec
== NULL
)
12841 const char * name
= get_dynamic_reloc_section_name (abfd
, sec
, is_rela
);
12845 reloc_sec
= bfd_get_section_by_name (abfd
, name
);
12847 if (reloc_sec
!= NULL
)
12848 elf_section_data (sec
)->sreloc
= reloc_sec
;
12855 /* Returns the dynamic reloc section associated with SEC. If the
12856 section does not exist it is created and attached to the DYNOBJ
12857 bfd and stored in the SRELOC field of SEC's elf_section_data
12860 ALIGNMENT is the alignment for the newly created section and
12861 IS_RELA defines whether the name should be .rela.<SEC's name>
12862 or .rel.<SEC's name>. The section name is looked up in the
12863 string table associated with ABFD. */
12866 _bfd_elf_make_dynamic_reloc_section (asection
* sec
,
12868 unsigned int alignment
,
12870 bfd_boolean is_rela
)
12872 asection
* reloc_sec
= elf_section_data (sec
)->sreloc
;
12874 if (reloc_sec
== NULL
)
12876 const char * name
= get_dynamic_reloc_section_name (abfd
, sec
, is_rela
);
12881 reloc_sec
= bfd_get_section_by_name (dynobj
, name
);
12883 if (reloc_sec
== NULL
)
12887 flags
= (SEC_HAS_CONTENTS
| SEC_READONLY
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
12888 if ((sec
->flags
& SEC_ALLOC
) != 0)
12889 flags
|= SEC_ALLOC
| SEC_LOAD
;
12891 reloc_sec
= bfd_make_section_with_flags (dynobj
, name
, flags
);
12892 if (reloc_sec
!= NULL
)
12894 if (! bfd_set_section_alignment (dynobj
, reloc_sec
, alignment
))
12899 elf_section_data (sec
)->sreloc
= reloc_sec
;
12905 /* Copy the ELF symbol type associated with a linker hash entry. */
12907 _bfd_elf_copy_link_hash_symbol_type (bfd
*abfd ATTRIBUTE_UNUSED
,
12908 struct bfd_link_hash_entry
* hdest
,
12909 struct bfd_link_hash_entry
* hsrc
)
12911 struct elf_link_hash_entry
*ehdest
= (struct elf_link_hash_entry
*)hdest
;
12912 struct elf_link_hash_entry
*ehsrc
= (struct elf_link_hash_entry
*)hsrc
;
12914 ehdest
->type
= ehsrc
->type
;
12915 ehdest
->target_internal
= ehsrc
->target_internal
;
12918 /* Append a RELA relocation REL to section S in BFD. */
12921 elf_append_rela (bfd
*abfd
, asection
*s
, Elf_Internal_Rela
*rel
)
12923 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12924 bfd_byte
*loc
= s
->contents
+ (s
->reloc_count
++ * bed
->s
->sizeof_rela
);
12925 BFD_ASSERT (loc
+ bed
->s
->sizeof_rela
<= s
->contents
+ s
->size
);
12926 bed
->s
->swap_reloca_out (abfd
, rel
, loc
);
12929 /* Append a REL relocation REL to section S in BFD. */
12932 elf_append_rel (bfd
*abfd
, asection
*s
, Elf_Internal_Rela
*rel
)
12934 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
12935 bfd_byte
*loc
= s
->contents
+ (s
->reloc_count
++ * bed
->s
->sizeof_rel
);
12936 BFD_ASSERT (loc
+ bed
->s
->sizeof_rel
<= s
->contents
+ s
->size
);
12937 bed
->s
->swap_reloca_out (abfd
, rel
, loc
);