1 /* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 MA 02110-1301, USA. */
28 #include "safe-ctype.h"
29 #include "libiberty.h"
32 /* Define a symbol in a dynamic linkage section. */
34 struct elf_link_hash_entry
*
35 _bfd_elf_define_linkage_sym (bfd
*abfd
,
36 struct bfd_link_info
*info
,
40 struct elf_link_hash_entry
*h
;
41 struct bfd_link_hash_entry
*bh
;
42 const struct elf_backend_data
*bed
;
44 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, FALSE
);
47 /* Zap symbol defined in an as-needed lib that wasn't linked.
48 This is a symptom of a larger problem: Absolute symbols
49 defined in shared libraries can't be overridden, because we
50 lose the link to the bfd which is via the symbol section. */
51 h
->root
.type
= bfd_link_hash_new
;
55 if (!_bfd_generic_link_add_one_symbol (info
, abfd
, name
, BSF_GLOBAL
,
57 get_elf_backend_data (abfd
)->collect
,
60 h
= (struct elf_link_hash_entry
*) bh
;
63 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
65 bed
= get_elf_backend_data (abfd
);
66 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
71 _bfd_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
75 struct elf_link_hash_entry
*h
;
76 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
79 /* This function may be called more than once. */
80 s
= bfd_get_section_by_name (abfd
, ".got");
81 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
84 switch (bed
->s
->arch_size
)
95 bfd_set_error (bfd_error_bad_value
);
99 flags
= bed
->dynamic_sec_flags
;
101 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
103 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
106 if (bed
->want_got_plt
)
108 s
= bfd_make_section_with_flags (abfd
, ".got.plt", flags
);
110 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
114 if (bed
->want_got_sym
)
116 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
117 (or .got.plt) section. We don't do this in the linker script
118 because we don't want to define the symbol if we are not creating
119 a global offset table. */
120 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
, "_GLOBAL_OFFSET_TABLE_");
121 elf_hash_table (info
)->hgot
= h
;
126 /* The first bit of the global offset table is the header. */
127 s
->size
+= bed
->got_header_size
;
132 /* Create a strtab to hold the dynamic symbol names. */
134 _bfd_elf_link_create_dynstrtab (bfd
*abfd
, struct bfd_link_info
*info
)
136 struct elf_link_hash_table
*hash_table
;
138 hash_table
= elf_hash_table (info
);
139 if (hash_table
->dynobj
== NULL
)
140 hash_table
->dynobj
= abfd
;
142 if (hash_table
->dynstr
== NULL
)
144 hash_table
->dynstr
= _bfd_elf_strtab_init ();
145 if (hash_table
->dynstr
== NULL
)
151 /* Create some sections which will be filled in with dynamic linking
152 information. ABFD is an input file which requires dynamic sections
153 to be created. The dynamic sections take up virtual memory space
154 when the final executable is run, so we need to create them before
155 addresses are assigned to the output sections. We work out the
156 actual contents and size of these sections later. */
159 _bfd_elf_link_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
162 register asection
*s
;
163 const struct elf_backend_data
*bed
;
165 if (! is_elf_hash_table (info
->hash
))
168 if (elf_hash_table (info
)->dynamic_sections_created
)
171 if (!_bfd_elf_link_create_dynstrtab (abfd
, info
))
174 abfd
= elf_hash_table (info
)->dynobj
;
175 bed
= get_elf_backend_data (abfd
);
177 flags
= bed
->dynamic_sec_flags
;
179 /* A dynamically linked executable has a .interp section, but a
180 shared library does not. */
181 if (info
->executable
)
183 s
= bfd_make_section_with_flags (abfd
, ".interp",
184 flags
| SEC_READONLY
);
189 /* Create sections to hold version informations. These are removed
190 if they are not needed. */
191 s
= bfd_make_section_with_flags (abfd
, ".gnu.version_d",
192 flags
| SEC_READONLY
);
194 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
197 s
= bfd_make_section_with_flags (abfd
, ".gnu.version",
198 flags
| SEC_READONLY
);
200 || ! bfd_set_section_alignment (abfd
, s
, 1))
203 s
= bfd_make_section_with_flags (abfd
, ".gnu.version_r",
204 flags
| SEC_READONLY
);
206 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
209 s
= bfd_make_section_with_flags (abfd
, ".dynsym",
210 flags
| SEC_READONLY
);
212 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
215 s
= bfd_make_section_with_flags (abfd
, ".dynstr",
216 flags
| SEC_READONLY
);
220 s
= bfd_make_section_with_flags (abfd
, ".dynamic", flags
);
222 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
225 /* The special symbol _DYNAMIC is always set to the start of the
226 .dynamic section. We could set _DYNAMIC in a linker script, but we
227 only want to define it if we are, in fact, creating a .dynamic
228 section. We don't want to define it if there is no .dynamic
229 section, since on some ELF platforms the start up code examines it
230 to decide how to initialize the process. */
231 if (!_bfd_elf_define_linkage_sym (abfd
, info
, s
, "_DYNAMIC"))
236 s
= bfd_make_section_with_flags (abfd
, ".hash", flags
| SEC_READONLY
);
238 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
240 elf_section_data (s
)->this_hdr
.sh_entsize
= bed
->s
->sizeof_hash_entry
;
243 if (info
->emit_gnu_hash
)
245 s
= bfd_make_section_with_flags (abfd
, ".gnu.hash",
246 flags
| SEC_READONLY
);
248 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
250 /* For 64-bit ELF, .gnu.hash is a non-uniform entity size section:
251 4 32-bit words followed by variable count of 64-bit words, then
252 variable count of 32-bit words. */
253 if (bed
->s
->arch_size
== 64)
254 elf_section_data (s
)->this_hdr
.sh_entsize
= 0;
256 elf_section_data (s
)->this_hdr
.sh_entsize
= 4;
259 /* Let the backend create the rest of the sections. This lets the
260 backend set the right flags. The backend will normally create
261 the .got and .plt sections. */
262 if (! (*bed
->elf_backend_create_dynamic_sections
) (abfd
, info
))
265 elf_hash_table (info
)->dynamic_sections_created
= TRUE
;
270 /* Create dynamic sections when linking against a dynamic object. */
273 _bfd_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
275 flagword flags
, pltflags
;
276 struct elf_link_hash_entry
*h
;
278 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
280 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
281 .rel[a].bss sections. */
282 flags
= bed
->dynamic_sec_flags
;
285 if (bed
->plt_not_loaded
)
286 /* We do not clear SEC_ALLOC here because we still want the OS to
287 allocate space for the section; it's just that there's nothing
288 to read in from the object file. */
289 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
291 pltflags
|= SEC_ALLOC
| SEC_CODE
| SEC_LOAD
;
292 if (bed
->plt_readonly
)
293 pltflags
|= SEC_READONLY
;
295 s
= bfd_make_section_with_flags (abfd
, ".plt", pltflags
);
297 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
300 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
302 if (bed
->want_plt_sym
)
304 h
= _bfd_elf_define_linkage_sym (abfd
, info
, s
,
305 "_PROCEDURE_LINKAGE_TABLE_");
306 elf_hash_table (info
)->hplt
= h
;
311 s
= bfd_make_section_with_flags (abfd
,
312 (bed
->default_use_rela_p
313 ? ".rela.plt" : ".rel.plt"),
314 flags
| SEC_READONLY
);
316 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
319 if (! _bfd_elf_create_got_section (abfd
, info
))
322 if (bed
->want_dynbss
)
324 /* The .dynbss section is a place to put symbols which are defined
325 by dynamic objects, are referenced by regular objects, and are
326 not functions. We must allocate space for them in the process
327 image and use a R_*_COPY reloc to tell the dynamic linker to
328 initialize them at run time. The linker script puts the .dynbss
329 section into the .bss section of the final image. */
330 s
= bfd_make_section_with_flags (abfd
, ".dynbss",
332 | SEC_LINKER_CREATED
));
336 /* The .rel[a].bss section holds copy relocs. This section is not
337 normally needed. We need to create it here, though, so that the
338 linker will map it to an output section. We can't just create it
339 only if we need it, because we will not know whether we need it
340 until we have seen all the input files, and the first time the
341 main linker code calls BFD after examining all the input files
342 (size_dynamic_sections) the input sections have already been
343 mapped to the output sections. If the section turns out not to
344 be needed, we can discard it later. We will never need this
345 section when generating a shared object, since they do not use
349 s
= bfd_make_section_with_flags (abfd
,
350 (bed
->default_use_rela_p
351 ? ".rela.bss" : ".rel.bss"),
352 flags
| SEC_READONLY
);
354 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
362 /* Record a new dynamic symbol. We record the dynamic symbols as we
363 read the input files, since we need to have a list of all of them
364 before we can determine the final sizes of the output sections.
365 Note that we may actually call this function even though we are not
366 going to output any dynamic symbols; in some cases we know that a
367 symbol should be in the dynamic symbol table, but only if there is
371 bfd_elf_link_record_dynamic_symbol (struct bfd_link_info
*info
,
372 struct elf_link_hash_entry
*h
)
374 if (h
->dynindx
== -1)
376 struct elf_strtab_hash
*dynstr
;
381 /* XXX: The ABI draft says the linker must turn hidden and
382 internal symbols into STB_LOCAL symbols when producing the
383 DSO. However, if ld.so honors st_other in the dynamic table,
384 this would not be necessary. */
385 switch (ELF_ST_VISIBILITY (h
->other
))
389 if (h
->root
.type
!= bfd_link_hash_undefined
390 && h
->root
.type
!= bfd_link_hash_undefweak
)
393 if (!elf_hash_table (info
)->is_relocatable_executable
)
401 h
->dynindx
= elf_hash_table (info
)->dynsymcount
;
402 ++elf_hash_table (info
)->dynsymcount
;
404 dynstr
= elf_hash_table (info
)->dynstr
;
407 /* Create a strtab to hold the dynamic symbol names. */
408 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
413 /* We don't put any version information in the dynamic string
415 name
= h
->root
.root
.string
;
416 p
= strchr (name
, ELF_VER_CHR
);
418 /* We know that the p points into writable memory. In fact,
419 there are only a few symbols that have read-only names, being
420 those like _GLOBAL_OFFSET_TABLE_ that are created specially
421 by the backends. Most symbols will have names pointing into
422 an ELF string table read from a file, or to objalloc memory. */
425 indx
= _bfd_elf_strtab_add (dynstr
, name
, p
!= NULL
);
430 if (indx
== (bfd_size_type
) -1)
432 h
->dynstr_index
= indx
;
438 /* Mark a symbol dynamic. */
441 bfd_elf_link_mark_dynamic_symbol (struct bfd_link_info
*info
,
442 struct elf_link_hash_entry
*h
,
443 Elf_Internal_Sym
*sym
)
445 struct bfd_elf_dynamic_list
*d
= info
->dynamic_list
;
447 /* It may be called more than once on the same H. */
448 if(h
->dynamic
|| info
->relocatable
)
451 if ((info
->dynamic_data
452 && (h
->type
== STT_OBJECT
454 && ELF_ST_TYPE (sym
->st_info
) == STT_OBJECT
)))
456 && h
->root
.type
== bfd_link_hash_new
457 && (*d
->match
) (&d
->head
, NULL
, h
->root
.root
.string
)))
461 /* Record an assignment to a symbol made by a linker script. We need
462 this in case some dynamic object refers to this symbol. */
465 bfd_elf_record_link_assignment (bfd
*output_bfd
,
466 struct bfd_link_info
*info
,
471 struct elf_link_hash_entry
*h
, *hv
;
472 struct elf_link_hash_table
*htab
;
473 const struct elf_backend_data
*bed
;
475 if (!is_elf_hash_table (info
->hash
))
478 htab
= elf_hash_table (info
);
479 h
= elf_link_hash_lookup (htab
, name
, !provide
, TRUE
, FALSE
);
483 switch (h
->root
.type
)
485 case bfd_link_hash_defined
:
486 case bfd_link_hash_defweak
:
487 case bfd_link_hash_common
:
489 case bfd_link_hash_undefweak
:
490 case bfd_link_hash_undefined
:
491 /* Since we're defining the symbol, don't let it seem to have not
492 been defined. record_dynamic_symbol and size_dynamic_sections
493 may depend on this. */
494 h
->root
.type
= bfd_link_hash_new
;
495 if (h
->root
.u
.undef
.next
!= NULL
|| htab
->root
.undefs_tail
== &h
->root
)
496 bfd_link_repair_undef_list (&htab
->root
);
498 case bfd_link_hash_new
:
499 bfd_elf_link_mark_dynamic_symbol (info
, h
, NULL
);
502 case bfd_link_hash_indirect
:
503 /* We had a versioned symbol in a dynamic library. We make the
504 the versioned symbol point to this one. */
505 bed
= get_elf_backend_data (output_bfd
);
507 while (hv
->root
.type
== bfd_link_hash_indirect
508 || hv
->root
.type
== bfd_link_hash_warning
)
509 hv
= (struct elf_link_hash_entry
*) hv
->root
.u
.i
.link
;
510 /* We don't need to update h->root.u since linker will set them
512 h
->root
.type
= bfd_link_hash_undefined
;
513 hv
->root
.type
= bfd_link_hash_indirect
;
514 hv
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) h
;
515 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hv
);
517 case bfd_link_hash_warning
:
522 /* If this symbol is being provided by the linker script, and it is
523 currently defined by a dynamic object, but not by a regular
524 object, then mark it as undefined so that the generic linker will
525 force the correct value. */
529 h
->root
.type
= bfd_link_hash_undefined
;
531 /* If this symbol is not being provided by the linker script, and it is
532 currently defined by a dynamic object, but not by a regular object,
533 then clear out any version information because the symbol will not be
534 associated with the dynamic object any more. */
538 h
->verinfo
.verdef
= NULL
;
542 if (provide
&& hidden
)
544 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
546 h
->other
= (h
->other
& ~ELF_ST_VISIBILITY (-1)) | STV_HIDDEN
;
547 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
550 /* STV_HIDDEN and STV_INTERNAL symbols must be STB_LOCAL in shared objects
552 if (!info
->relocatable
554 && (ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
555 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
))
561 || (info
->executable
&& elf_hash_table (info
)->is_relocatable_executable
))
564 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
567 /* If this is a weak defined symbol, and we know a corresponding
568 real symbol from the same dynamic object, make sure the real
569 symbol is also made into a dynamic symbol. */
570 if (h
->u
.weakdef
!= NULL
571 && h
->u
.weakdef
->dynindx
== -1)
573 if (! bfd_elf_link_record_dynamic_symbol (info
, h
->u
.weakdef
))
581 /* Record a new local dynamic symbol. Returns 0 on failure, 1 on
582 success, and 2 on a failure caused by attempting to record a symbol
583 in a discarded section, eg. a discarded link-once section symbol. */
586 bfd_elf_link_record_local_dynamic_symbol (struct bfd_link_info
*info
,
591 struct elf_link_local_dynamic_entry
*entry
;
592 struct elf_link_hash_table
*eht
;
593 struct elf_strtab_hash
*dynstr
;
594 unsigned long dynstr_index
;
596 Elf_External_Sym_Shndx eshndx
;
597 char esym
[sizeof (Elf64_External_Sym
)];
599 if (! is_elf_hash_table (info
->hash
))
602 /* See if the entry exists already. */
603 for (entry
= elf_hash_table (info
)->dynlocal
; entry
; entry
= entry
->next
)
604 if (entry
->input_bfd
== input_bfd
&& entry
->input_indx
== input_indx
)
607 amt
= sizeof (*entry
);
608 entry
= bfd_alloc (input_bfd
, amt
);
612 /* Go find the symbol, so that we can find it's name. */
613 if (!bfd_elf_get_elf_syms (input_bfd
, &elf_tdata (input_bfd
)->symtab_hdr
,
614 1, input_indx
, &entry
->isym
, esym
, &eshndx
))
616 bfd_release (input_bfd
, entry
);
620 if (entry
->isym
.st_shndx
!= SHN_UNDEF
621 && (entry
->isym
.st_shndx
< SHN_LORESERVE
622 || entry
->isym
.st_shndx
> SHN_HIRESERVE
))
626 s
= bfd_section_from_elf_index (input_bfd
, entry
->isym
.st_shndx
);
627 if (s
== NULL
|| bfd_is_abs_section (s
->output_section
))
629 /* We can still bfd_release here as nothing has done another
630 bfd_alloc. We can't do this later in this function. */
631 bfd_release (input_bfd
, entry
);
636 name
= (bfd_elf_string_from_elf_section
637 (input_bfd
, elf_tdata (input_bfd
)->symtab_hdr
.sh_link
,
638 entry
->isym
.st_name
));
640 dynstr
= elf_hash_table (info
)->dynstr
;
643 /* Create a strtab to hold the dynamic symbol names. */
644 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
649 dynstr_index
= _bfd_elf_strtab_add (dynstr
, name
, FALSE
);
650 if (dynstr_index
== (unsigned long) -1)
652 entry
->isym
.st_name
= dynstr_index
;
654 eht
= elf_hash_table (info
);
656 entry
->next
= eht
->dynlocal
;
657 eht
->dynlocal
= entry
;
658 entry
->input_bfd
= input_bfd
;
659 entry
->input_indx
= input_indx
;
662 /* Whatever binding the symbol had before, it's now local. */
664 = ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (entry
->isym
.st_info
));
666 /* The dynindx will be set at the end of size_dynamic_sections. */
671 /* Return the dynindex of a local dynamic symbol. */
674 _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info
*info
,
678 struct elf_link_local_dynamic_entry
*e
;
680 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
681 if (e
->input_bfd
== input_bfd
&& e
->input_indx
== input_indx
)
686 /* This function is used to renumber the dynamic symbols, if some of
687 them are removed because they are marked as local. This is called
688 via elf_link_hash_traverse. */
691 elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry
*h
,
694 size_t *count
= data
;
696 if (h
->root
.type
== bfd_link_hash_warning
)
697 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
702 if (h
->dynindx
!= -1)
703 h
->dynindx
= ++(*count
);
709 /* Like elf_link_renumber_hash_table_dynsyms, but just number symbols with
710 STB_LOCAL binding. */
713 elf_link_renumber_local_hash_table_dynsyms (struct elf_link_hash_entry
*h
,
716 size_t *count
= data
;
718 if (h
->root
.type
== bfd_link_hash_warning
)
719 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
721 if (!h
->forced_local
)
724 if (h
->dynindx
!= -1)
725 h
->dynindx
= ++(*count
);
730 /* Return true if the dynamic symbol for a given section should be
731 omitted when creating a shared library. */
733 _bfd_elf_link_omit_section_dynsym (bfd
*output_bfd ATTRIBUTE_UNUSED
,
734 struct bfd_link_info
*info
,
737 struct elf_link_hash_table
*htab
;
739 switch (elf_section_data (p
)->this_hdr
.sh_type
)
743 /* If sh_type is yet undecided, assume it could be
744 SHT_PROGBITS/SHT_NOBITS. */
746 htab
= elf_hash_table (info
);
747 if (p
== htab
->tls_sec
)
750 if (htab
->text_index_section
!= NULL
)
751 return p
!= htab
->text_index_section
&& p
!= htab
->data_index_section
;
753 if (strcmp (p
->name
, ".got") == 0
754 || strcmp (p
->name
, ".got.plt") == 0
755 || strcmp (p
->name
, ".plt") == 0)
759 if (htab
->dynobj
!= NULL
760 && (ip
= bfd_get_section_by_name (htab
->dynobj
, p
->name
)) != NULL
761 && (ip
->flags
& SEC_LINKER_CREATED
)
762 && ip
->output_section
== p
)
767 /* There shouldn't be section relative relocations
768 against any other section. */
774 /* Assign dynsym indices. In a shared library we generate a section
775 symbol for each output section, which come first. Next come symbols
776 which have been forced to local binding. Then all of the back-end
777 allocated local dynamic syms, followed by the rest of the global
781 _bfd_elf_link_renumber_dynsyms (bfd
*output_bfd
,
782 struct bfd_link_info
*info
,
783 unsigned long *section_sym_count
)
785 unsigned long dynsymcount
= 0;
787 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
789 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
791 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
792 if ((p
->flags
& SEC_EXCLUDE
) == 0
793 && (p
->flags
& SEC_ALLOC
) != 0
794 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
795 elf_section_data (p
)->dynindx
= ++dynsymcount
;
797 elf_section_data (p
)->dynindx
= 0;
799 *section_sym_count
= dynsymcount
;
801 elf_link_hash_traverse (elf_hash_table (info
),
802 elf_link_renumber_local_hash_table_dynsyms
,
805 if (elf_hash_table (info
)->dynlocal
)
807 struct elf_link_local_dynamic_entry
*p
;
808 for (p
= elf_hash_table (info
)->dynlocal
; p
; p
= p
->next
)
809 p
->dynindx
= ++dynsymcount
;
812 elf_link_hash_traverse (elf_hash_table (info
),
813 elf_link_renumber_hash_table_dynsyms
,
816 /* There is an unused NULL entry at the head of the table which
817 we must account for in our count. Unless there weren't any
818 symbols, which means we'll have no table at all. */
819 if (dynsymcount
!= 0)
822 elf_hash_table (info
)->dynsymcount
= dynsymcount
;
826 /* This function is called when we want to define a new symbol. It
827 handles the various cases which arise when we find a definition in
828 a dynamic object, or when there is already a definition in a
829 dynamic object. The new symbol is described by NAME, SYM, PSEC,
830 and PVALUE. We set SYM_HASH to the hash table entry. We set
831 OVERRIDE if the old symbol is overriding a new definition. We set
832 TYPE_CHANGE_OK if it is OK for the type to change. We set
833 SIZE_CHANGE_OK if it is OK for the size to change. By OK to
834 change, we mean that we shouldn't warn if the type or size does
835 change. We set POLD_ALIGNMENT if an old common symbol in a dynamic
836 object is overridden by a regular object. */
839 _bfd_elf_merge_symbol (bfd
*abfd
,
840 struct bfd_link_info
*info
,
842 Elf_Internal_Sym
*sym
,
845 unsigned int *pold_alignment
,
846 struct elf_link_hash_entry
**sym_hash
,
848 bfd_boolean
*override
,
849 bfd_boolean
*type_change_ok
,
850 bfd_boolean
*size_change_ok
)
852 asection
*sec
, *oldsec
;
853 struct elf_link_hash_entry
*h
;
854 struct elf_link_hash_entry
*flip
;
857 bfd_boolean newdyn
, olddyn
, olddef
, newdef
, newdyncommon
, olddyncommon
;
858 bfd_boolean newweak
, oldweak
;
859 const struct elf_backend_data
*bed
;
865 bind
= ELF_ST_BIND (sym
->st_info
);
867 /* Silently discard TLS symbols from --just-syms. There's no way to
868 combine a static TLS block with a new TLS block for this executable. */
869 if (ELF_ST_TYPE (sym
->st_info
) == STT_TLS
870 && sec
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
876 if (! bfd_is_und_section (sec
))
877 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
, FALSE
, FALSE
);
879 h
= ((struct elf_link_hash_entry
*)
880 bfd_wrapped_link_hash_lookup (abfd
, info
, name
, TRUE
, FALSE
, FALSE
));
885 /* This code is for coping with dynamic objects, and is only useful
886 if we are doing an ELF link. */
887 if (info
->hash
->creator
!= abfd
->xvec
)
890 /* For merging, we only care about real symbols. */
892 while (h
->root
.type
== bfd_link_hash_indirect
893 || h
->root
.type
== bfd_link_hash_warning
)
894 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
896 /* We have to check it for every instance since the first few may be
897 refereences and not all compilers emit symbol type for undefined
899 bfd_elf_link_mark_dynamic_symbol (info
, h
, sym
);
901 /* If we just created the symbol, mark it as being an ELF symbol.
902 Other than that, there is nothing to do--there is no merge issue
903 with a newly defined symbol--so we just return. */
905 if (h
->root
.type
== bfd_link_hash_new
)
911 /* OLDBFD and OLDSEC are a BFD and an ASECTION associated with the
914 switch (h
->root
.type
)
921 case bfd_link_hash_undefined
:
922 case bfd_link_hash_undefweak
:
923 oldbfd
= h
->root
.u
.undef
.abfd
;
927 case bfd_link_hash_defined
:
928 case bfd_link_hash_defweak
:
929 oldbfd
= h
->root
.u
.def
.section
->owner
;
930 oldsec
= h
->root
.u
.def
.section
;
933 case bfd_link_hash_common
:
934 oldbfd
= h
->root
.u
.c
.p
->section
->owner
;
935 oldsec
= h
->root
.u
.c
.p
->section
;
939 /* In cases involving weak versioned symbols, we may wind up trying
940 to merge a symbol with itself. Catch that here, to avoid the
941 confusion that results if we try to override a symbol with
942 itself. The additional tests catch cases like
943 _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
944 dynamic object, which we do want to handle here. */
946 && ((abfd
->flags
& DYNAMIC
) == 0
950 /* NEWDYN and OLDDYN indicate whether the new or old symbol,
951 respectively, is from a dynamic object. */
953 newdyn
= (abfd
->flags
& DYNAMIC
) != 0;
957 olddyn
= (oldbfd
->flags
& DYNAMIC
) != 0;
958 else if (oldsec
!= NULL
)
960 /* This handles the special SHN_MIPS_{TEXT,DATA} section
961 indices used by MIPS ELF. */
962 olddyn
= (oldsec
->symbol
->flags
& BSF_DYNAMIC
) != 0;
965 /* NEWDEF and OLDDEF indicate whether the new or old symbol,
966 respectively, appear to be a definition rather than reference. */
968 newdef
= !bfd_is_und_section (sec
) && !bfd_is_com_section (sec
);
970 olddef
= (h
->root
.type
!= bfd_link_hash_undefined
971 && h
->root
.type
!= bfd_link_hash_undefweak
972 && h
->root
.type
!= bfd_link_hash_common
);
974 bed
= get_elf_backend_data (abfd
);
975 /* When we try to create a default indirect symbol from the dynamic
976 definition with the default version, we skip it if its type and
977 the type of existing regular definition mismatch. We only do it
978 if the existing regular definition won't be dynamic. */
979 if (pold_alignment
== NULL
981 && !info
->export_dynamic
986 && (olddef
|| h
->root
.type
== bfd_link_hash_common
)
987 && ELF_ST_TYPE (sym
->st_info
) != h
->type
988 && ELF_ST_TYPE (sym
->st_info
) != STT_NOTYPE
989 && h
->type
!= STT_NOTYPE
990 && !(bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
))
991 && bed
->is_function_type (h
->type
)))
997 /* Check TLS symbol. We don't check undefined symbol introduced by
999 if ((ELF_ST_TYPE (sym
->st_info
) == STT_TLS
|| h
->type
== STT_TLS
)
1000 && ELF_ST_TYPE (sym
->st_info
) != h
->type
1004 bfd_boolean ntdef
, tdef
;
1005 asection
*ntsec
, *tsec
;
1007 if (h
->type
== STT_TLS
)
1027 (*_bfd_error_handler
)
1028 (_("%s: TLS definition in %B section %A mismatches non-TLS definition in %B section %A"),
1029 tbfd
, tsec
, ntbfd
, ntsec
, h
->root
.root
.string
);
1030 else if (!tdef
&& !ntdef
)
1031 (*_bfd_error_handler
)
1032 (_("%s: TLS reference in %B mismatches non-TLS reference in %B"),
1033 tbfd
, ntbfd
, h
->root
.root
.string
);
1035 (*_bfd_error_handler
)
1036 (_("%s: TLS definition in %B section %A mismatches non-TLS reference in %B"),
1037 tbfd
, tsec
, ntbfd
, h
->root
.root
.string
);
1039 (*_bfd_error_handler
)
1040 (_("%s: TLS reference in %B mismatches non-TLS definition in %B section %A"),
1041 tbfd
, ntbfd
, ntsec
, h
->root
.root
.string
);
1043 bfd_set_error (bfd_error_bad_value
);
1047 /* We need to remember if a symbol has a definition in a dynamic
1048 object or is weak in all dynamic objects. Internal and hidden
1049 visibility will make it unavailable to dynamic objects. */
1050 if (newdyn
&& !h
->dynamic_def
)
1052 if (!bfd_is_und_section (sec
))
1056 /* Check if this symbol is weak in all dynamic objects. If it
1057 is the first time we see it in a dynamic object, we mark
1058 if it is weak. Otherwise, we clear it. */
1059 if (!h
->ref_dynamic
)
1061 if (bind
== STB_WEAK
)
1062 h
->dynamic_weak
= 1;
1064 else if (bind
!= STB_WEAK
)
1065 h
->dynamic_weak
= 0;
1069 /* If the old symbol has non-default visibility, we ignore the new
1070 definition from a dynamic object. */
1072 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
1073 && !bfd_is_und_section (sec
))
1076 /* Make sure this symbol is dynamic. */
1078 /* A protected symbol has external availability. Make sure it is
1079 recorded as dynamic.
1081 FIXME: Should we check type and size for protected symbol? */
1082 if (ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
1083 return bfd_elf_link_record_dynamic_symbol (info
, h
);
1088 && ELF_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
1091 /* If the new symbol with non-default visibility comes from a
1092 relocatable file and the old definition comes from a dynamic
1093 object, we remove the old definition. */
1094 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1096 /* Handle the case where the old dynamic definition is
1097 default versioned. We need to copy the symbol info from
1098 the symbol with default version to the normal one if it
1099 was referenced before. */
1102 const struct elf_backend_data
*bed
1103 = get_elf_backend_data (abfd
);
1104 struct elf_link_hash_entry
*vh
= *sym_hash
;
1105 vh
->root
.type
= h
->root
.type
;
1106 h
->root
.type
= bfd_link_hash_indirect
;
1107 (*bed
->elf_backend_copy_indirect_symbol
) (info
, vh
, h
);
1108 /* Protected symbols will override the dynamic definition
1109 with default version. */
1110 if (ELF_ST_VISIBILITY (sym
->st_other
) == STV_PROTECTED
)
1112 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) vh
;
1113 vh
->dynamic_def
= 1;
1114 vh
->ref_dynamic
= 1;
1118 h
->root
.type
= vh
->root
.type
;
1119 vh
->ref_dynamic
= 0;
1120 /* We have to hide it here since it was made dynamic
1121 global with extra bits when the symbol info was
1122 copied from the old dynamic definition. */
1123 (*bed
->elf_backend_hide_symbol
) (info
, vh
, TRUE
);
1131 if ((h
->root
.u
.undef
.next
|| info
->hash
->undefs_tail
== &h
->root
)
1132 && bfd_is_und_section (sec
))
1134 /* If the new symbol is undefined and the old symbol was
1135 also undefined before, we need to make sure
1136 _bfd_generic_link_add_one_symbol doesn't mess
1137 up the linker hash table undefs list. Since the old
1138 definition came from a dynamic object, it is still on the
1140 h
->root
.type
= bfd_link_hash_undefined
;
1141 h
->root
.u
.undef
.abfd
= abfd
;
1145 h
->root
.type
= bfd_link_hash_new
;
1146 h
->root
.u
.undef
.abfd
= NULL
;
1155 /* FIXME: Should we check type and size for protected symbol? */
1161 /* Differentiate strong and weak symbols. */
1162 newweak
= bind
== STB_WEAK
;
1163 oldweak
= (h
->root
.type
== bfd_link_hash_defweak
1164 || h
->root
.type
== bfd_link_hash_undefweak
);
1166 /* If a new weak symbol definition comes from a regular file and the
1167 old symbol comes from a dynamic library, we treat the new one as
1168 strong. Similarly, an old weak symbol definition from a regular
1169 file is treated as strong when the new symbol comes from a dynamic
1170 library. Further, an old weak symbol from a dynamic library is
1171 treated as strong if the new symbol is from a dynamic library.
1172 This reflects the way glibc's ld.so works.
1174 Do this before setting *type_change_ok or *size_change_ok so that
1175 we warn properly when dynamic library symbols are overridden. */
1177 if (newdef
&& !newdyn
&& olddyn
)
1179 if (olddef
&& newdyn
)
1182 /* Allow changes between different types of funciton symbol. */
1183 if (bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
))
1184 && bed
->is_function_type (h
->type
))
1185 *type_change_ok
= TRUE
;
1187 /* It's OK to change the type if either the existing symbol or the
1188 new symbol is weak. A type change is also OK if the old symbol
1189 is undefined and the new symbol is defined. */
1194 && h
->root
.type
== bfd_link_hash_undefined
))
1195 *type_change_ok
= TRUE
;
1197 /* It's OK to change the size if either the existing symbol or the
1198 new symbol is weak, or if the old symbol is undefined. */
1201 || h
->root
.type
== bfd_link_hash_undefined
)
1202 *size_change_ok
= TRUE
;
1204 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
1205 symbol, respectively, appears to be a common symbol in a dynamic
1206 object. If a symbol appears in an uninitialized section, and is
1207 not weak, and is not a function, then it may be a common symbol
1208 which was resolved when the dynamic object was created. We want
1209 to treat such symbols specially, because they raise special
1210 considerations when setting the symbol size: if the symbol
1211 appears as a common symbol in a regular object, and the size in
1212 the regular object is larger, we must make sure that we use the
1213 larger size. This problematic case can always be avoided in C,
1214 but it must be handled correctly when using Fortran shared
1217 Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
1218 likewise for OLDDYNCOMMON and OLDDEF.
1220 Note that this test is just a heuristic, and that it is quite
1221 possible to have an uninitialized symbol in a shared object which
1222 is really a definition, rather than a common symbol. This could
1223 lead to some minor confusion when the symbol really is a common
1224 symbol in some regular object. However, I think it will be
1230 && (sec
->flags
& SEC_ALLOC
) != 0
1231 && (sec
->flags
& SEC_LOAD
) == 0
1233 && !bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
)))
1234 newdyncommon
= TRUE
;
1236 newdyncommon
= FALSE
;
1240 && h
->root
.type
== bfd_link_hash_defined
1242 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
1243 && (h
->root
.u
.def
.section
->flags
& SEC_LOAD
) == 0
1245 && !bed
->is_function_type (h
->type
))
1246 olddyncommon
= TRUE
;
1248 olddyncommon
= FALSE
;
1250 /* We now know everything about the old and new symbols. We ask the
1251 backend to check if we can merge them. */
1252 if (bed
->merge_symbol
1253 && !bed
->merge_symbol (info
, sym_hash
, h
, sym
, psec
, pvalue
,
1254 pold_alignment
, skip
, override
,
1255 type_change_ok
, size_change_ok
,
1256 &newdyn
, &newdef
, &newdyncommon
, &newweak
,
1258 &olddyn
, &olddef
, &olddyncommon
, &oldweak
,
1262 /* If both the old and the new symbols look like common symbols in a
1263 dynamic object, set the size of the symbol to the larger of the
1268 && sym
->st_size
!= h
->size
)
1270 /* Since we think we have two common symbols, issue a multiple
1271 common warning if desired. Note that we only warn if the
1272 size is different. If the size is the same, we simply let
1273 the old symbol override the new one as normally happens with
1274 symbols defined in dynamic objects. */
1276 if (! ((*info
->callbacks
->multiple_common
)
1277 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
1278 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
1281 if (sym
->st_size
> h
->size
)
1282 h
->size
= sym
->st_size
;
1284 *size_change_ok
= TRUE
;
1287 /* If we are looking at a dynamic object, and we have found a
1288 definition, we need to see if the symbol was already defined by
1289 some other object. If so, we want to use the existing
1290 definition, and we do not want to report a multiple symbol
1291 definition error; we do this by clobbering *PSEC to be
1292 bfd_und_section_ptr.
1294 We treat a common symbol as a definition if the symbol in the
1295 shared library is a function, since common symbols always
1296 represent variables; this can cause confusion in principle, but
1297 any such confusion would seem to indicate an erroneous program or
1298 shared library. We also permit a common symbol in a regular
1299 object to override a weak symbol in a shared object. */
1304 || (h
->root
.type
== bfd_link_hash_common
1306 || bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
))))))
1310 newdyncommon
= FALSE
;
1312 *psec
= sec
= bfd_und_section_ptr
;
1313 *size_change_ok
= TRUE
;
1315 /* If we get here when the old symbol is a common symbol, then
1316 we are explicitly letting it override a weak symbol or
1317 function in a dynamic object, and we don't want to warn about
1318 a type change. If the old symbol is a defined symbol, a type
1319 change warning may still be appropriate. */
1321 if (h
->root
.type
== bfd_link_hash_common
)
1322 *type_change_ok
= TRUE
;
1325 /* Handle the special case of an old common symbol merging with a
1326 new symbol which looks like a common symbol in a shared object.
1327 We change *PSEC and *PVALUE to make the new symbol look like a
1328 common symbol, and let _bfd_generic_link_add_one_symbol do the
1332 && h
->root
.type
== bfd_link_hash_common
)
1336 newdyncommon
= FALSE
;
1337 *pvalue
= sym
->st_size
;
1338 *psec
= sec
= bed
->common_section (oldsec
);
1339 *size_change_ok
= TRUE
;
1342 /* Skip weak definitions of symbols that are already defined. */
1343 if (newdef
&& olddef
&& newweak
)
1346 /* If the old symbol is from a dynamic object, and the new symbol is
1347 a definition which is not from a dynamic object, then the new
1348 symbol overrides the old symbol. Symbols from regular files
1349 always take precedence over symbols from dynamic objects, even if
1350 they are defined after the dynamic object in the link.
1352 As above, we again permit a common symbol in a regular object to
1353 override a definition in a shared object if the shared object
1354 symbol is a function or is weak. */
1359 || (bfd_is_com_section (sec
)
1361 || bed
->is_function_type (h
->type
))))
1366 /* Change the hash table entry to undefined, and let
1367 _bfd_generic_link_add_one_symbol do the right thing with the
1370 h
->root
.type
= bfd_link_hash_undefined
;
1371 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1372 *size_change_ok
= TRUE
;
1375 olddyncommon
= FALSE
;
1377 /* We again permit a type change when a common symbol may be
1378 overriding a function. */
1380 if (bfd_is_com_section (sec
))
1381 *type_change_ok
= TRUE
;
1383 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1386 /* This union may have been set to be non-NULL when this symbol
1387 was seen in a dynamic object. We must force the union to be
1388 NULL, so that it is correct for a regular symbol. */
1389 h
->verinfo
.vertree
= NULL
;
1392 /* Handle the special case of a new common symbol merging with an
1393 old symbol that looks like it might be a common symbol defined in
1394 a shared object. Note that we have already handled the case in
1395 which a new common symbol should simply override the definition
1396 in the shared library. */
1399 && bfd_is_com_section (sec
)
1402 /* It would be best if we could set the hash table entry to a
1403 common symbol, but we don't know what to use for the section
1404 or the alignment. */
1405 if (! ((*info
->callbacks
->multiple_common
)
1406 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
1407 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
1410 /* If the presumed common symbol in the dynamic object is
1411 larger, pretend that the new symbol has its size. */
1413 if (h
->size
> *pvalue
)
1416 /* We need to remember the alignment required by the symbol
1417 in the dynamic object. */
1418 BFD_ASSERT (pold_alignment
);
1419 *pold_alignment
= h
->root
.u
.def
.section
->alignment_power
;
1422 olddyncommon
= FALSE
;
1424 h
->root
.type
= bfd_link_hash_undefined
;
1425 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1427 *size_change_ok
= TRUE
;
1428 *type_change_ok
= TRUE
;
1430 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1433 h
->verinfo
.vertree
= NULL
;
1438 /* Handle the case where we had a versioned symbol in a dynamic
1439 library and now find a definition in a normal object. In this
1440 case, we make the versioned symbol point to the normal one. */
1441 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1442 flip
->root
.type
= h
->root
.type
;
1443 flip
->root
.u
.undef
.abfd
= h
->root
.u
.undef
.abfd
;
1444 h
->root
.type
= bfd_link_hash_indirect
;
1445 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) flip
;
1446 (*bed
->elf_backend_copy_indirect_symbol
) (info
, flip
, h
);
1450 flip
->ref_dynamic
= 1;
1457 /* This function is called to create an indirect symbol from the
1458 default for the symbol with the default version if needed. The
1459 symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We
1460 set DYNSYM if the new indirect symbol is dynamic. */
1463 _bfd_elf_add_default_symbol (bfd
*abfd
,
1464 struct bfd_link_info
*info
,
1465 struct elf_link_hash_entry
*h
,
1467 Elf_Internal_Sym
*sym
,
1470 bfd_boolean
*dynsym
,
1471 bfd_boolean override
)
1473 bfd_boolean type_change_ok
;
1474 bfd_boolean size_change_ok
;
1477 struct elf_link_hash_entry
*hi
;
1478 struct bfd_link_hash_entry
*bh
;
1479 const struct elf_backend_data
*bed
;
1480 bfd_boolean collect
;
1481 bfd_boolean dynamic
;
1483 size_t len
, shortlen
;
1486 /* If this symbol has a version, and it is the default version, we
1487 create an indirect symbol from the default name to the fully
1488 decorated name. This will cause external references which do not
1489 specify a version to be bound to this version of the symbol. */
1490 p
= strchr (name
, ELF_VER_CHR
);
1491 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
1496 /* We are overridden by an old definition. We need to check if we
1497 need to create the indirect symbol from the default name. */
1498 hi
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
,
1500 BFD_ASSERT (hi
!= NULL
);
1503 while (hi
->root
.type
== bfd_link_hash_indirect
1504 || hi
->root
.type
== bfd_link_hash_warning
)
1506 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1512 bed
= get_elf_backend_data (abfd
);
1513 collect
= bed
->collect
;
1514 dynamic
= (abfd
->flags
& DYNAMIC
) != 0;
1516 shortlen
= p
- name
;
1517 shortname
= bfd_hash_allocate (&info
->hash
->table
, shortlen
+ 1);
1518 if (shortname
== NULL
)
1520 memcpy (shortname
, name
, shortlen
);
1521 shortname
[shortlen
] = '\0';
1523 /* We are going to create a new symbol. Merge it with any existing
1524 symbol with this name. For the purposes of the merge, act as
1525 though we were defining the symbol we just defined, although we
1526 actually going to define an indirect symbol. */
1527 type_change_ok
= FALSE
;
1528 size_change_ok
= FALSE
;
1530 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1531 NULL
, &hi
, &skip
, &override
,
1532 &type_change_ok
, &size_change_ok
))
1541 if (! (_bfd_generic_link_add_one_symbol
1542 (info
, abfd
, shortname
, BSF_INDIRECT
, bfd_ind_section_ptr
,
1543 0, name
, FALSE
, collect
, &bh
)))
1545 hi
= (struct elf_link_hash_entry
*) bh
;
1549 /* In this case the symbol named SHORTNAME is overriding the
1550 indirect symbol we want to add. We were planning on making
1551 SHORTNAME an indirect symbol referring to NAME. SHORTNAME
1552 is the name without a version. NAME is the fully versioned
1553 name, and it is the default version.
1555 Overriding means that we already saw a definition for the
1556 symbol SHORTNAME in a regular object, and it is overriding
1557 the symbol defined in the dynamic object.
1559 When this happens, we actually want to change NAME, the
1560 symbol we just added, to refer to SHORTNAME. This will cause
1561 references to NAME in the shared object to become references
1562 to SHORTNAME in the regular object. This is what we expect
1563 when we override a function in a shared object: that the
1564 references in the shared object will be mapped to the
1565 definition in the regular object. */
1567 while (hi
->root
.type
== bfd_link_hash_indirect
1568 || hi
->root
.type
== bfd_link_hash_warning
)
1569 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1571 h
->root
.type
= bfd_link_hash_indirect
;
1572 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) hi
;
1576 hi
->ref_dynamic
= 1;
1580 if (! bfd_elf_link_record_dynamic_symbol (info
, hi
))
1585 /* Now set HI to H, so that the following code will set the
1586 other fields correctly. */
1590 /* Check if HI is a warning symbol. */
1591 if (hi
->root
.type
== bfd_link_hash_warning
)
1592 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1594 /* If there is a duplicate definition somewhere, then HI may not
1595 point to an indirect symbol. We will have reported an error to
1596 the user in that case. */
1598 if (hi
->root
.type
== bfd_link_hash_indirect
)
1600 struct elf_link_hash_entry
*ht
;
1602 ht
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1603 (*bed
->elf_backend_copy_indirect_symbol
) (info
, ht
, hi
);
1605 /* See if the new flags lead us to realize that the symbol must
1617 if (hi
->ref_regular
)
1623 /* We also need to define an indirection from the nondefault version
1627 len
= strlen (name
);
1628 shortname
= bfd_hash_allocate (&info
->hash
->table
, len
);
1629 if (shortname
== NULL
)
1631 memcpy (shortname
, name
, shortlen
);
1632 memcpy (shortname
+ shortlen
, p
+ 1, len
- shortlen
);
1634 /* Once again, merge with any existing symbol. */
1635 type_change_ok
= FALSE
;
1636 size_change_ok
= FALSE
;
1638 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1639 NULL
, &hi
, &skip
, &override
,
1640 &type_change_ok
, &size_change_ok
))
1648 /* Here SHORTNAME is a versioned name, so we don't expect to see
1649 the type of override we do in the case above unless it is
1650 overridden by a versioned definition. */
1651 if (hi
->root
.type
!= bfd_link_hash_defined
1652 && hi
->root
.type
!= bfd_link_hash_defweak
)
1653 (*_bfd_error_handler
)
1654 (_("%B: unexpected redefinition of indirect versioned symbol `%s'"),
1660 if (! (_bfd_generic_link_add_one_symbol
1661 (info
, abfd
, shortname
, BSF_INDIRECT
,
1662 bfd_ind_section_ptr
, 0, name
, FALSE
, collect
, &bh
)))
1664 hi
= (struct elf_link_hash_entry
*) bh
;
1666 /* If there is a duplicate definition somewhere, then HI may not
1667 point to an indirect symbol. We will have reported an error
1668 to the user in that case. */
1670 if (hi
->root
.type
== bfd_link_hash_indirect
)
1672 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hi
);
1674 /* See if the new flags lead us to realize that the symbol
1686 if (hi
->ref_regular
)
1696 /* This routine is used to export all defined symbols into the dynamic
1697 symbol table. It is called via elf_link_hash_traverse. */
1700 _bfd_elf_export_symbol (struct elf_link_hash_entry
*h
, void *data
)
1702 struct elf_info_failed
*eif
= data
;
1704 /* Ignore this if we won't export it. */
1705 if (!eif
->info
->export_dynamic
&& !h
->dynamic
)
1708 /* Ignore indirect symbols. These are added by the versioning code. */
1709 if (h
->root
.type
== bfd_link_hash_indirect
)
1712 if (h
->root
.type
== bfd_link_hash_warning
)
1713 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1715 if (h
->dynindx
== -1
1719 struct bfd_elf_version_tree
*t
;
1720 struct bfd_elf_version_expr
*d
;
1722 for (t
= eif
->verdefs
; t
!= NULL
; t
= t
->next
)
1724 if (t
->globals
.list
!= NULL
)
1726 d
= (*t
->match
) (&t
->globals
, NULL
, h
->root
.root
.string
);
1731 if (t
->locals
.list
!= NULL
)
1733 d
= (*t
->match
) (&t
->locals
, NULL
, h
->root
.root
.string
);
1742 if (! bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
1753 /* Look through the symbols which are defined in other shared
1754 libraries and referenced here. Update the list of version
1755 dependencies. This will be put into the .gnu.version_r section.
1756 This function is called via elf_link_hash_traverse. */
1759 _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry
*h
,
1762 struct elf_find_verdep_info
*rinfo
= data
;
1763 Elf_Internal_Verneed
*t
;
1764 Elf_Internal_Vernaux
*a
;
1767 if (h
->root
.type
== bfd_link_hash_warning
)
1768 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1770 /* We only care about symbols defined in shared objects with version
1775 || h
->verinfo
.verdef
== NULL
)
1778 /* See if we already know about this version. */
1779 for (t
= elf_tdata (rinfo
->output_bfd
)->verref
; t
!= NULL
; t
= t
->vn_nextref
)
1781 if (t
->vn_bfd
!= h
->verinfo
.verdef
->vd_bfd
)
1784 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
1785 if (a
->vna_nodename
== h
->verinfo
.verdef
->vd_nodename
)
1791 /* This is a new version. Add it to tree we are building. */
1796 t
= bfd_zalloc (rinfo
->output_bfd
, amt
);
1799 rinfo
->failed
= TRUE
;
1803 t
->vn_bfd
= h
->verinfo
.verdef
->vd_bfd
;
1804 t
->vn_nextref
= elf_tdata (rinfo
->output_bfd
)->verref
;
1805 elf_tdata (rinfo
->output_bfd
)->verref
= t
;
1809 a
= bfd_zalloc (rinfo
->output_bfd
, amt
);
1811 /* Note that we are copying a string pointer here, and testing it
1812 above. If bfd_elf_string_from_elf_section is ever changed to
1813 discard the string data when low in memory, this will have to be
1815 a
->vna_nodename
= h
->verinfo
.verdef
->vd_nodename
;
1817 a
->vna_flags
= h
->verinfo
.verdef
->vd_flags
;
1818 a
->vna_nextptr
= t
->vn_auxptr
;
1820 h
->verinfo
.verdef
->vd_exp_refno
= rinfo
->vers
;
1823 a
->vna_other
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
1830 /* Figure out appropriate versions for all the symbols. We may not
1831 have the version number script until we have read all of the input
1832 files, so until that point we don't know which symbols should be
1833 local. This function is called via elf_link_hash_traverse. */
1836 _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry
*h
, void *data
)
1838 struct elf_assign_sym_version_info
*sinfo
;
1839 struct bfd_link_info
*info
;
1840 const struct elf_backend_data
*bed
;
1841 struct elf_info_failed eif
;
1848 if (h
->root
.type
== bfd_link_hash_warning
)
1849 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1851 /* Fix the symbol flags. */
1854 if (! _bfd_elf_fix_symbol_flags (h
, &eif
))
1857 sinfo
->failed
= TRUE
;
1861 /* We only need version numbers for symbols defined in regular
1863 if (!h
->def_regular
)
1866 bed
= get_elf_backend_data (sinfo
->output_bfd
);
1867 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
1868 if (p
!= NULL
&& h
->verinfo
.vertree
== NULL
)
1870 struct bfd_elf_version_tree
*t
;
1875 /* There are two consecutive ELF_VER_CHR characters if this is
1876 not a hidden symbol. */
1878 if (*p
== ELF_VER_CHR
)
1884 /* If there is no version string, we can just return out. */
1892 /* Look for the version. If we find it, it is no longer weak. */
1893 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
1895 if (strcmp (t
->name
, p
) == 0)
1899 struct bfd_elf_version_expr
*d
;
1901 len
= p
- h
->root
.root
.string
;
1902 alc
= bfd_malloc (len
);
1905 memcpy (alc
, h
->root
.root
.string
, len
- 1);
1906 alc
[len
- 1] = '\0';
1907 if (alc
[len
- 2] == ELF_VER_CHR
)
1908 alc
[len
- 2] = '\0';
1910 h
->verinfo
.vertree
= t
;
1914 if (t
->globals
.list
!= NULL
)
1915 d
= (*t
->match
) (&t
->globals
, NULL
, alc
);
1917 /* See if there is anything to force this symbol to
1919 if (d
== NULL
&& t
->locals
.list
!= NULL
)
1921 d
= (*t
->match
) (&t
->locals
, NULL
, alc
);
1924 && ! info
->export_dynamic
)
1925 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1933 /* If we are building an application, we need to create a
1934 version node for this version. */
1935 if (t
== NULL
&& info
->executable
)
1937 struct bfd_elf_version_tree
**pp
;
1940 /* If we aren't going to export this symbol, we don't need
1941 to worry about it. */
1942 if (h
->dynindx
== -1)
1946 t
= bfd_zalloc (sinfo
->output_bfd
, amt
);
1949 sinfo
->failed
= TRUE
;
1954 t
->name_indx
= (unsigned int) -1;
1958 /* Don't count anonymous version tag. */
1959 if (sinfo
->verdefs
!= NULL
&& sinfo
->verdefs
->vernum
== 0)
1961 for (pp
= &sinfo
->verdefs
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1963 t
->vernum
= version_index
;
1967 h
->verinfo
.vertree
= t
;
1971 /* We could not find the version for a symbol when
1972 generating a shared archive. Return an error. */
1973 (*_bfd_error_handler
)
1974 (_("%B: version node not found for symbol %s"),
1975 sinfo
->output_bfd
, h
->root
.root
.string
);
1976 bfd_set_error (bfd_error_bad_value
);
1977 sinfo
->failed
= TRUE
;
1985 /* If we don't have a version for this symbol, see if we can find
1987 if (h
->verinfo
.vertree
== NULL
&& sinfo
->verdefs
!= NULL
)
1989 struct bfd_elf_version_tree
*t
;
1990 struct bfd_elf_version_tree
*local_ver
;
1991 struct bfd_elf_version_expr
*d
;
1993 /* See if can find what version this symbol is in. If the
1994 symbol is supposed to be local, then don't actually register
1997 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
1999 if (t
->globals
.list
!= NULL
)
2001 bfd_boolean matched
;
2005 while ((d
= (*t
->match
) (&t
->globals
, d
,
2006 h
->root
.root
.string
)) != NULL
)
2011 /* There is a version without definition. Make
2012 the symbol the default definition for this
2014 h
->verinfo
.vertree
= t
;
2022 /* There is no undefined version for this symbol. Hide the
2024 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
2027 if (t
->locals
.list
!= NULL
)
2030 while ((d
= (*t
->match
) (&t
->locals
, d
,
2031 h
->root
.root
.string
)) != NULL
)
2034 /* If the match is "*", keep looking for a more
2035 explicit, perhaps even global, match.
2036 XXX: Shouldn't this be !d->wildcard instead? */
2037 if (d
->pattern
[0] != '*' || d
->pattern
[1] != '\0')
2046 if (local_ver
!= NULL
)
2048 h
->verinfo
.vertree
= local_ver
;
2049 if (h
->dynindx
!= -1
2050 && ! info
->export_dynamic
)
2052 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
2060 /* Read and swap the relocs from the section indicated by SHDR. This
2061 may be either a REL or a RELA section. The relocations are
2062 translated into RELA relocations and stored in INTERNAL_RELOCS,
2063 which should have already been allocated to contain enough space.
2064 The EXTERNAL_RELOCS are a buffer where the external form of the
2065 relocations should be stored.
2067 Returns FALSE if something goes wrong. */
2070 elf_link_read_relocs_from_section (bfd
*abfd
,
2072 Elf_Internal_Shdr
*shdr
,
2073 void *external_relocs
,
2074 Elf_Internal_Rela
*internal_relocs
)
2076 const struct elf_backend_data
*bed
;
2077 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
2078 const bfd_byte
*erela
;
2079 const bfd_byte
*erelaend
;
2080 Elf_Internal_Rela
*irela
;
2081 Elf_Internal_Shdr
*symtab_hdr
;
2084 /* Position ourselves at the start of the section. */
2085 if (bfd_seek (abfd
, shdr
->sh_offset
, SEEK_SET
) != 0)
2088 /* Read the relocations. */
2089 if (bfd_bread (external_relocs
, shdr
->sh_size
, abfd
) != shdr
->sh_size
)
2092 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2093 nsyms
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
2095 bed
= get_elf_backend_data (abfd
);
2097 /* Convert the external relocations to the internal format. */
2098 if (shdr
->sh_entsize
== bed
->s
->sizeof_rel
)
2099 swap_in
= bed
->s
->swap_reloc_in
;
2100 else if (shdr
->sh_entsize
== bed
->s
->sizeof_rela
)
2101 swap_in
= bed
->s
->swap_reloca_in
;
2104 bfd_set_error (bfd_error_wrong_format
);
2108 erela
= external_relocs
;
2109 erelaend
= erela
+ shdr
->sh_size
;
2110 irela
= internal_relocs
;
2111 while (erela
< erelaend
)
2115 (*swap_in
) (abfd
, erela
, irela
);
2116 r_symndx
= ELF32_R_SYM (irela
->r_info
);
2117 if (bed
->s
->arch_size
== 64)
2119 if ((size_t) r_symndx
>= nsyms
)
2121 (*_bfd_error_handler
)
2122 (_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
2123 " for offset 0x%lx in section `%A'"),
2125 (unsigned long) r_symndx
, (unsigned long) nsyms
, irela
->r_offset
);
2126 bfd_set_error (bfd_error_bad_value
);
2129 irela
+= bed
->s
->int_rels_per_ext_rel
;
2130 erela
+= shdr
->sh_entsize
;
2136 /* Read and swap the relocs for a section O. They may have been
2137 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
2138 not NULL, they are used as buffers to read into. They are known to
2139 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
2140 the return value is allocated using either malloc or bfd_alloc,
2141 according to the KEEP_MEMORY argument. If O has two relocation
2142 sections (both REL and RELA relocations), then the REL_HDR
2143 relocations will appear first in INTERNAL_RELOCS, followed by the
2144 REL_HDR2 relocations. */
2147 _bfd_elf_link_read_relocs (bfd
*abfd
,
2149 void *external_relocs
,
2150 Elf_Internal_Rela
*internal_relocs
,
2151 bfd_boolean keep_memory
)
2153 Elf_Internal_Shdr
*rel_hdr
;
2154 void *alloc1
= NULL
;
2155 Elf_Internal_Rela
*alloc2
= NULL
;
2156 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2158 if (elf_section_data (o
)->relocs
!= NULL
)
2159 return elf_section_data (o
)->relocs
;
2161 if (o
->reloc_count
== 0)
2164 rel_hdr
= &elf_section_data (o
)->rel_hdr
;
2166 if (internal_relocs
== NULL
)
2170 size
= o
->reloc_count
;
2171 size
*= bed
->s
->int_rels_per_ext_rel
* sizeof (Elf_Internal_Rela
);
2173 internal_relocs
= bfd_alloc (abfd
, size
);
2175 internal_relocs
= alloc2
= bfd_malloc (size
);
2176 if (internal_relocs
== NULL
)
2180 if (external_relocs
== NULL
)
2182 bfd_size_type size
= rel_hdr
->sh_size
;
2184 if (elf_section_data (o
)->rel_hdr2
)
2185 size
+= elf_section_data (o
)->rel_hdr2
->sh_size
;
2186 alloc1
= bfd_malloc (size
);
2189 external_relocs
= alloc1
;
2192 if (!elf_link_read_relocs_from_section (abfd
, o
, rel_hdr
,
2196 if (elf_section_data (o
)->rel_hdr2
2197 && (!elf_link_read_relocs_from_section
2199 elf_section_data (o
)->rel_hdr2
,
2200 ((bfd_byte
*) external_relocs
) + rel_hdr
->sh_size
,
2201 internal_relocs
+ (NUM_SHDR_ENTRIES (rel_hdr
)
2202 * bed
->s
->int_rels_per_ext_rel
))))
2205 /* Cache the results for next time, if we can. */
2207 elf_section_data (o
)->relocs
= internal_relocs
;
2212 /* Don't free alloc2, since if it was allocated we are passing it
2213 back (under the name of internal_relocs). */
2215 return internal_relocs
;
2225 /* Compute the size of, and allocate space for, REL_HDR which is the
2226 section header for a section containing relocations for O. */
2229 _bfd_elf_link_size_reloc_section (bfd
*abfd
,
2230 Elf_Internal_Shdr
*rel_hdr
,
2233 bfd_size_type reloc_count
;
2234 bfd_size_type num_rel_hashes
;
2236 /* Figure out how many relocations there will be. */
2237 if (rel_hdr
== &elf_section_data (o
)->rel_hdr
)
2238 reloc_count
= elf_section_data (o
)->rel_count
;
2240 reloc_count
= elf_section_data (o
)->rel_count2
;
2242 num_rel_hashes
= o
->reloc_count
;
2243 if (num_rel_hashes
< reloc_count
)
2244 num_rel_hashes
= reloc_count
;
2246 /* That allows us to calculate the size of the section. */
2247 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
* reloc_count
;
2249 /* The contents field must last into write_object_contents, so we
2250 allocate it with bfd_alloc rather than malloc. Also since we
2251 cannot be sure that the contents will actually be filled in,
2252 we zero the allocated space. */
2253 rel_hdr
->contents
= bfd_zalloc (abfd
, rel_hdr
->sh_size
);
2254 if (rel_hdr
->contents
== NULL
&& rel_hdr
->sh_size
!= 0)
2257 /* We only allocate one set of hash entries, so we only do it the
2258 first time we are called. */
2259 if (elf_section_data (o
)->rel_hashes
== NULL
2262 struct elf_link_hash_entry
**p
;
2264 p
= bfd_zmalloc (num_rel_hashes
* sizeof (struct elf_link_hash_entry
*));
2268 elf_section_data (o
)->rel_hashes
= p
;
2274 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
2275 originated from the section given by INPUT_REL_HDR) to the
2279 _bfd_elf_link_output_relocs (bfd
*output_bfd
,
2280 asection
*input_section
,
2281 Elf_Internal_Shdr
*input_rel_hdr
,
2282 Elf_Internal_Rela
*internal_relocs
,
2283 struct elf_link_hash_entry
**rel_hash
2286 Elf_Internal_Rela
*irela
;
2287 Elf_Internal_Rela
*irelaend
;
2289 Elf_Internal_Shdr
*output_rel_hdr
;
2290 asection
*output_section
;
2291 unsigned int *rel_countp
= NULL
;
2292 const struct elf_backend_data
*bed
;
2293 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
2295 output_section
= input_section
->output_section
;
2296 output_rel_hdr
= NULL
;
2298 if (elf_section_data (output_section
)->rel_hdr
.sh_entsize
2299 == input_rel_hdr
->sh_entsize
)
2301 output_rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
2302 rel_countp
= &elf_section_data (output_section
)->rel_count
;
2304 else if (elf_section_data (output_section
)->rel_hdr2
2305 && (elf_section_data (output_section
)->rel_hdr2
->sh_entsize
2306 == input_rel_hdr
->sh_entsize
))
2308 output_rel_hdr
= elf_section_data (output_section
)->rel_hdr2
;
2309 rel_countp
= &elf_section_data (output_section
)->rel_count2
;
2313 (*_bfd_error_handler
)
2314 (_("%B: relocation size mismatch in %B section %A"),
2315 output_bfd
, input_section
->owner
, input_section
);
2316 bfd_set_error (bfd_error_wrong_object_format
);
2320 bed
= get_elf_backend_data (output_bfd
);
2321 if (input_rel_hdr
->sh_entsize
== bed
->s
->sizeof_rel
)
2322 swap_out
= bed
->s
->swap_reloc_out
;
2323 else if (input_rel_hdr
->sh_entsize
== bed
->s
->sizeof_rela
)
2324 swap_out
= bed
->s
->swap_reloca_out
;
2328 erel
= output_rel_hdr
->contents
;
2329 erel
+= *rel_countp
* input_rel_hdr
->sh_entsize
;
2330 irela
= internal_relocs
;
2331 irelaend
= irela
+ (NUM_SHDR_ENTRIES (input_rel_hdr
)
2332 * bed
->s
->int_rels_per_ext_rel
);
2333 while (irela
< irelaend
)
2335 (*swap_out
) (output_bfd
, irela
, erel
);
2336 irela
+= bed
->s
->int_rels_per_ext_rel
;
2337 erel
+= input_rel_hdr
->sh_entsize
;
2340 /* Bump the counter, so that we know where to add the next set of
2342 *rel_countp
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
2347 /* Make weak undefined symbols in PIE dynamic. */
2350 _bfd_elf_link_hash_fixup_symbol (struct bfd_link_info
*info
,
2351 struct elf_link_hash_entry
*h
)
2355 && h
->root
.type
== bfd_link_hash_undefweak
)
2356 return bfd_elf_link_record_dynamic_symbol (info
, h
);
2361 /* Fix up the flags for a symbol. This handles various cases which
2362 can only be fixed after all the input files are seen. This is
2363 currently called by both adjust_dynamic_symbol and
2364 assign_sym_version, which is unnecessary but perhaps more robust in
2365 the face of future changes. */
2368 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry
*h
,
2369 struct elf_info_failed
*eif
)
2371 const struct elf_backend_data
*bed
= NULL
;
2373 /* If this symbol was mentioned in a non-ELF file, try to set
2374 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
2375 permit a non-ELF file to correctly refer to a symbol defined in
2376 an ELF dynamic object. */
2379 while (h
->root
.type
== bfd_link_hash_indirect
)
2380 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2382 if (h
->root
.type
!= bfd_link_hash_defined
2383 && h
->root
.type
!= bfd_link_hash_defweak
)
2386 h
->ref_regular_nonweak
= 1;
2390 if (h
->root
.u
.def
.section
->owner
!= NULL
2391 && (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2392 == bfd_target_elf_flavour
))
2395 h
->ref_regular_nonweak
= 1;
2401 if (h
->dynindx
== -1
2405 if (! bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
2414 /* Unfortunately, NON_ELF is only correct if the symbol
2415 was first seen in a non-ELF file. Fortunately, if the symbol
2416 was first seen in an ELF file, we're probably OK unless the
2417 symbol was defined in a non-ELF file. Catch that case here.
2418 FIXME: We're still in trouble if the symbol was first seen in
2419 a dynamic object, and then later in a non-ELF regular object. */
2420 if ((h
->root
.type
== bfd_link_hash_defined
2421 || h
->root
.type
== bfd_link_hash_defweak
)
2423 && (h
->root
.u
.def
.section
->owner
!= NULL
2424 ? (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2425 != bfd_target_elf_flavour
)
2426 : (bfd_is_abs_section (h
->root
.u
.def
.section
)
2427 && !h
->def_dynamic
)))
2431 /* Backend specific symbol fixup. */
2432 if (elf_hash_table (eif
->info
)->dynobj
)
2434 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2435 if (bed
->elf_backend_fixup_symbol
2436 && !(*bed
->elf_backend_fixup_symbol
) (eif
->info
, h
))
2440 /* If this is a final link, and the symbol was defined as a common
2441 symbol in a regular object file, and there was no definition in
2442 any dynamic object, then the linker will have allocated space for
2443 the symbol in a common section but the DEF_REGULAR
2444 flag will not have been set. */
2445 if (h
->root
.type
== bfd_link_hash_defined
2449 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
2452 /* If -Bsymbolic was used (which means to bind references to global
2453 symbols to the definition within the shared object), and this
2454 symbol was defined in a regular object, then it actually doesn't
2455 need a PLT entry. Likewise, if the symbol has non-default
2456 visibility. If the symbol has hidden or internal visibility, we
2457 will force it local. */
2459 && eif
->info
->shared
2460 && is_elf_hash_table (eif
->info
->hash
)
2461 && (SYMBOLIC_BIND (eif
->info
, h
)
2462 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2465 bfd_boolean force_local
;
2467 force_local
= (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2468 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
);
2469 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, force_local
);
2472 /* If a weak undefined symbol has non-default visibility, we also
2473 hide it from the dynamic linker. */
2474 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2475 && h
->root
.type
== bfd_link_hash_undefweak
)
2477 const struct elf_backend_data
*bed
;
2478 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2479 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, TRUE
);
2482 /* If this is a weak defined symbol in a dynamic object, and we know
2483 the real definition in the dynamic object, copy interesting flags
2484 over to the real definition. */
2485 if (h
->u
.weakdef
!= NULL
)
2487 struct elf_link_hash_entry
*weakdef
;
2489 weakdef
= h
->u
.weakdef
;
2490 if (h
->root
.type
== bfd_link_hash_indirect
)
2491 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2493 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2494 || h
->root
.type
== bfd_link_hash_defweak
);
2495 BFD_ASSERT (weakdef
->def_dynamic
);
2497 /* If the real definition is defined by a regular object file,
2498 don't do anything special. See the longer description in
2499 _bfd_elf_adjust_dynamic_symbol, below. */
2500 if (weakdef
->def_regular
)
2501 h
->u
.weakdef
= NULL
;
2504 BFD_ASSERT (weakdef
->root
.type
== bfd_link_hash_defined
2505 || weakdef
->root
.type
== bfd_link_hash_defweak
);
2506 (*bed
->elf_backend_copy_indirect_symbol
) (eif
->info
, weakdef
, h
);
2513 /* Make the backend pick a good value for a dynamic symbol. This is
2514 called via elf_link_hash_traverse, and also calls itself
2518 _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry
*h
, void *data
)
2520 struct elf_info_failed
*eif
= data
;
2522 const struct elf_backend_data
*bed
;
2524 if (! is_elf_hash_table (eif
->info
->hash
))
2527 if (h
->root
.type
== bfd_link_hash_warning
)
2529 h
->got
= elf_hash_table (eif
->info
)->init_got_offset
;
2530 h
->plt
= elf_hash_table (eif
->info
)->init_plt_offset
;
2532 /* When warning symbols are created, they **replace** the "real"
2533 entry in the hash table, thus we never get to see the real
2534 symbol in a hash traversal. So look at it now. */
2535 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2538 /* Ignore indirect symbols. These are added by the versioning code. */
2539 if (h
->root
.type
== bfd_link_hash_indirect
)
2542 /* Fix the symbol flags. */
2543 if (! _bfd_elf_fix_symbol_flags (h
, eif
))
2546 /* If this symbol does not require a PLT entry, and it is not
2547 defined by a dynamic object, or is not referenced by a regular
2548 object, ignore it. We do have to handle a weak defined symbol,
2549 even if no regular object refers to it, if we decided to add it
2550 to the dynamic symbol table. FIXME: Do we normally need to worry
2551 about symbols which are defined by one dynamic object and
2552 referenced by another one? */
2557 && (h
->u
.weakdef
== NULL
|| h
->u
.weakdef
->dynindx
== -1))))
2559 h
->plt
= elf_hash_table (eif
->info
)->init_plt_offset
;
2563 /* If we've already adjusted this symbol, don't do it again. This
2564 can happen via a recursive call. */
2565 if (h
->dynamic_adjusted
)
2568 /* Don't look at this symbol again. Note that we must set this
2569 after checking the above conditions, because we may look at a
2570 symbol once, decide not to do anything, and then get called
2571 recursively later after REF_REGULAR is set below. */
2572 h
->dynamic_adjusted
= 1;
2574 /* If this is a weak definition, and we know a real definition, and
2575 the real symbol is not itself defined by a regular object file,
2576 then get a good value for the real definition. We handle the
2577 real symbol first, for the convenience of the backend routine.
2579 Note that there is a confusing case here. If the real definition
2580 is defined by a regular object file, we don't get the real symbol
2581 from the dynamic object, but we do get the weak symbol. If the
2582 processor backend uses a COPY reloc, then if some routine in the
2583 dynamic object changes the real symbol, we will not see that
2584 change in the corresponding weak symbol. This is the way other
2585 ELF linkers work as well, and seems to be a result of the shared
2588 I will clarify this issue. Most SVR4 shared libraries define the
2589 variable _timezone and define timezone as a weak synonym. The
2590 tzset call changes _timezone. If you write
2591 extern int timezone;
2593 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
2594 you might expect that, since timezone is a synonym for _timezone,
2595 the same number will print both times. However, if the processor
2596 backend uses a COPY reloc, then actually timezone will be copied
2597 into your process image, and, since you define _timezone
2598 yourself, _timezone will not. Thus timezone and _timezone will
2599 wind up at different memory locations. The tzset call will set
2600 _timezone, leaving timezone unchanged. */
2602 if (h
->u
.weakdef
!= NULL
)
2604 /* If we get to this point, we know there is an implicit
2605 reference by a regular object file via the weak symbol H.
2606 FIXME: Is this really true? What if the traversal finds
2607 H->U.WEAKDEF before it finds H? */
2608 h
->u
.weakdef
->ref_regular
= 1;
2610 if (! _bfd_elf_adjust_dynamic_symbol (h
->u
.weakdef
, eif
))
2614 /* If a symbol has no type and no size and does not require a PLT
2615 entry, then we are probably about to do the wrong thing here: we
2616 are probably going to create a COPY reloc for an empty object.
2617 This case can arise when a shared object is built with assembly
2618 code, and the assembly code fails to set the symbol type. */
2620 && h
->type
== STT_NOTYPE
2622 (*_bfd_error_handler
)
2623 (_("warning: type and size of dynamic symbol `%s' are not defined"),
2624 h
->root
.root
.string
);
2626 dynobj
= elf_hash_table (eif
->info
)->dynobj
;
2627 bed
= get_elf_backend_data (dynobj
);
2628 if (! (*bed
->elf_backend_adjust_dynamic_symbol
) (eif
->info
, h
))
2637 /* Adjust the dynamic symbol, H, for copy in the dynamic bss section,
2641 _bfd_elf_adjust_dynamic_copy (struct elf_link_hash_entry
*h
,
2644 unsigned int power_of_two
;
2646 asection
*sec
= h
->root
.u
.def
.section
;
2648 /* The section aligment of definition is the maximum alignment
2649 requirement of symbols defined in the section. Since we don't
2650 know the symbol alignment requirement, we start with the
2651 maximum alignment and check low bits of the symbol address
2652 for the minimum alignment. */
2653 power_of_two
= bfd_get_section_alignment (sec
->owner
, sec
);
2654 mask
= ((bfd_vma
) 1 << power_of_two
) - 1;
2655 while ((h
->root
.u
.def
.value
& mask
) != 0)
2661 if (power_of_two
> bfd_get_section_alignment (dynbss
->owner
,
2664 /* Adjust the section alignment if needed. */
2665 if (! bfd_set_section_alignment (dynbss
->owner
, dynbss
,
2670 /* We make sure that the symbol will be aligned properly. */
2671 dynbss
->size
= BFD_ALIGN (dynbss
->size
, mask
+ 1);
2673 /* Define the symbol as being at this point in DYNBSS. */
2674 h
->root
.u
.def
.section
= dynbss
;
2675 h
->root
.u
.def
.value
= dynbss
->size
;
2677 /* Increment the size of DYNBSS to make room for the symbol. */
2678 dynbss
->size
+= h
->size
;
2683 /* Adjust all external symbols pointing into SEC_MERGE sections
2684 to reflect the object merging within the sections. */
2687 _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry
*h
, void *data
)
2691 if (h
->root
.type
== bfd_link_hash_warning
)
2692 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2694 if ((h
->root
.type
== bfd_link_hash_defined
2695 || h
->root
.type
== bfd_link_hash_defweak
)
2696 && ((sec
= h
->root
.u
.def
.section
)->flags
& SEC_MERGE
)
2697 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
2699 bfd
*output_bfd
= data
;
2701 h
->root
.u
.def
.value
=
2702 _bfd_merged_section_offset (output_bfd
,
2703 &h
->root
.u
.def
.section
,
2704 elf_section_data (sec
)->sec_info
,
2705 h
->root
.u
.def
.value
);
2711 /* Returns false if the symbol referred to by H should be considered
2712 to resolve local to the current module, and true if it should be
2713 considered to bind dynamically. */
2716 _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
2717 struct bfd_link_info
*info
,
2718 bfd_boolean ignore_protected
)
2720 bfd_boolean binding_stays_local_p
;
2721 const struct elf_backend_data
*bed
;
2722 struct elf_link_hash_table
*hash_table
;
2727 while (h
->root
.type
== bfd_link_hash_indirect
2728 || h
->root
.type
== bfd_link_hash_warning
)
2729 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2731 /* If it was forced local, then clearly it's not dynamic. */
2732 if (h
->dynindx
== -1)
2734 if (h
->forced_local
)
2737 /* Identify the cases where name binding rules say that a
2738 visible symbol resolves locally. */
2739 binding_stays_local_p
= info
->executable
|| SYMBOLIC_BIND (info
, h
);
2741 switch (ELF_ST_VISIBILITY (h
->other
))
2748 hash_table
= elf_hash_table (info
);
2749 if (!is_elf_hash_table (hash_table
))
2752 bed
= get_elf_backend_data (hash_table
->dynobj
);
2754 /* Proper resolution for function pointer equality may require
2755 that these symbols perhaps be resolved dynamically, even though
2756 we should be resolving them to the current module. */
2757 if (!ignore_protected
|| !bed
->is_function_type (h
->type
))
2758 binding_stays_local_p
= TRUE
;
2765 /* If it isn't defined locally, then clearly it's dynamic. */
2766 if (!h
->def_regular
)
2769 /* Otherwise, the symbol is dynamic if binding rules don't tell
2770 us that it remains local. */
2771 return !binding_stays_local_p
;
2774 /* Return true if the symbol referred to by H should be considered
2775 to resolve local to the current module, and false otherwise. Differs
2776 from (the inverse of) _bfd_elf_dynamic_symbol_p in the treatment of
2777 undefined symbols and weak symbols. */
2780 _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry
*h
,
2781 struct bfd_link_info
*info
,
2782 bfd_boolean local_protected
)
2784 const struct elf_backend_data
*bed
;
2785 struct elf_link_hash_table
*hash_table
;
2787 /* If it's a local sym, of course we resolve locally. */
2791 /* Common symbols that become definitions don't get the DEF_REGULAR
2792 flag set, so test it first, and don't bail out. */
2793 if (ELF_COMMON_DEF_P (h
))
2795 /* If we don't have a definition in a regular file, then we can't
2796 resolve locally. The sym is either undefined or dynamic. */
2797 else if (!h
->def_regular
)
2800 /* Forced local symbols resolve locally. */
2801 if (h
->forced_local
)
2804 /* As do non-dynamic symbols. */
2805 if (h
->dynindx
== -1)
2808 /* At this point, we know the symbol is defined and dynamic. In an
2809 executable it must resolve locally, likewise when building symbolic
2810 shared libraries. */
2811 if (info
->executable
|| SYMBOLIC_BIND (info
, h
))
2814 /* Now deal with defined dynamic symbols in shared libraries. Ones
2815 with default visibility might not resolve locally. */
2816 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2819 /* However, STV_HIDDEN or STV_INTERNAL ones must be local. */
2820 if (ELF_ST_VISIBILITY (h
->other
) != STV_PROTECTED
)
2823 hash_table
= elf_hash_table (info
);
2824 if (!is_elf_hash_table (hash_table
))
2827 bed
= get_elf_backend_data (hash_table
->dynobj
);
2829 /* STV_PROTECTED non-function symbols are local. */
2830 if (!bed
->is_function_type (h
->type
))
2833 /* Function pointer equality tests may require that STV_PROTECTED
2834 symbols be treated as dynamic symbols, even when we know that the
2835 dynamic linker will resolve them locally. */
2836 return local_protected
;
2839 /* Caches some TLS segment info, and ensures that the TLS segment vma is
2840 aligned. Returns the first TLS output section. */
2842 struct bfd_section
*
2843 _bfd_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
2845 struct bfd_section
*sec
, *tls
;
2846 unsigned int align
= 0;
2848 for (sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2849 if ((sec
->flags
& SEC_THREAD_LOCAL
) != 0)
2853 for (; sec
!= NULL
&& (sec
->flags
& SEC_THREAD_LOCAL
) != 0; sec
= sec
->next
)
2854 if (sec
->alignment_power
> align
)
2855 align
= sec
->alignment_power
;
2857 elf_hash_table (info
)->tls_sec
= tls
;
2859 /* Ensure the alignment of the first section is the largest alignment,
2860 so that the tls segment starts aligned. */
2862 tls
->alignment_power
= align
;
2867 /* Return TRUE iff this is a non-common, definition of a non-function symbol. */
2869 is_global_data_symbol_definition (bfd
*abfd ATTRIBUTE_UNUSED
,
2870 Elf_Internal_Sym
*sym
)
2872 const struct elf_backend_data
*bed
;
2874 /* Local symbols do not count, but target specific ones might. */
2875 if (ELF_ST_BIND (sym
->st_info
) != STB_GLOBAL
2876 && ELF_ST_BIND (sym
->st_info
) < STB_LOOS
)
2879 bed
= get_elf_backend_data (abfd
);
2880 /* Function symbols do not count. */
2881 if (bed
->is_function_type (ELF_ST_TYPE (sym
->st_info
)))
2884 /* If the section is undefined, then so is the symbol. */
2885 if (sym
->st_shndx
== SHN_UNDEF
)
2888 /* If the symbol is defined in the common section, then
2889 it is a common definition and so does not count. */
2890 if (bed
->common_definition (sym
))
2893 /* If the symbol is in a target specific section then we
2894 must rely upon the backend to tell us what it is. */
2895 if (sym
->st_shndx
>= SHN_LORESERVE
&& sym
->st_shndx
< SHN_ABS
)
2896 /* FIXME - this function is not coded yet:
2898 return _bfd_is_global_symbol_definition (abfd, sym);
2900 Instead for now assume that the definition is not global,
2901 Even if this is wrong, at least the linker will behave
2902 in the same way that it used to do. */
2908 /* Search the symbol table of the archive element of the archive ABFD
2909 whose archive map contains a mention of SYMDEF, and determine if
2910 the symbol is defined in this element. */
2912 elf_link_is_defined_archive_symbol (bfd
* abfd
, carsym
* symdef
)
2914 Elf_Internal_Shdr
* hdr
;
2915 bfd_size_type symcount
;
2916 bfd_size_type extsymcount
;
2917 bfd_size_type extsymoff
;
2918 Elf_Internal_Sym
*isymbuf
;
2919 Elf_Internal_Sym
*isym
;
2920 Elf_Internal_Sym
*isymend
;
2923 abfd
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
2927 if (! bfd_check_format (abfd
, bfd_object
))
2930 /* If we have already included the element containing this symbol in the
2931 link then we do not need to include it again. Just claim that any symbol
2932 it contains is not a definition, so that our caller will not decide to
2933 (re)include this element. */
2934 if (abfd
->archive_pass
)
2937 /* Select the appropriate symbol table. */
2938 if ((abfd
->flags
& DYNAMIC
) == 0 || elf_dynsymtab (abfd
) == 0)
2939 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2941 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
2943 symcount
= hdr
->sh_size
/ get_elf_backend_data (abfd
)->s
->sizeof_sym
;
2945 /* The sh_info field of the symtab header tells us where the
2946 external symbols start. We don't care about the local symbols. */
2947 if (elf_bad_symtab (abfd
))
2949 extsymcount
= symcount
;
2954 extsymcount
= symcount
- hdr
->sh_info
;
2955 extsymoff
= hdr
->sh_info
;
2958 if (extsymcount
== 0)
2961 /* Read in the symbol table. */
2962 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
2964 if (isymbuf
== NULL
)
2967 /* Scan the symbol table looking for SYMDEF. */
2969 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
; isym
< isymend
; isym
++)
2973 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
2978 if (strcmp (name
, symdef
->name
) == 0)
2980 result
= is_global_data_symbol_definition (abfd
, isym
);
2990 /* Add an entry to the .dynamic table. */
2993 _bfd_elf_add_dynamic_entry (struct bfd_link_info
*info
,
2997 struct elf_link_hash_table
*hash_table
;
2998 const struct elf_backend_data
*bed
;
3000 bfd_size_type newsize
;
3001 bfd_byte
*newcontents
;
3002 Elf_Internal_Dyn dyn
;
3004 hash_table
= elf_hash_table (info
);
3005 if (! is_elf_hash_table (hash_table
))
3008 bed
= get_elf_backend_data (hash_table
->dynobj
);
3009 s
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
3010 BFD_ASSERT (s
!= NULL
);
3012 newsize
= s
->size
+ bed
->s
->sizeof_dyn
;
3013 newcontents
= bfd_realloc (s
->contents
, newsize
);
3014 if (newcontents
== NULL
)
3018 dyn
.d_un
.d_val
= val
;
3019 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
, newcontents
+ s
->size
);
3022 s
->contents
= newcontents
;
3027 /* Add a DT_NEEDED entry for this dynamic object if DO_IT is true,
3028 otherwise just check whether one already exists. Returns -1 on error,
3029 1 if a DT_NEEDED tag already exists, and 0 on success. */
3032 elf_add_dt_needed_tag (bfd
*abfd
,
3033 struct bfd_link_info
*info
,
3037 struct elf_link_hash_table
*hash_table
;
3038 bfd_size_type oldsize
;
3039 bfd_size_type strindex
;
3041 if (!_bfd_elf_link_create_dynstrtab (abfd
, info
))
3044 hash_table
= elf_hash_table (info
);
3045 oldsize
= _bfd_elf_strtab_size (hash_table
->dynstr
);
3046 strindex
= _bfd_elf_strtab_add (hash_table
->dynstr
, soname
, FALSE
);
3047 if (strindex
== (bfd_size_type
) -1)
3050 if (oldsize
== _bfd_elf_strtab_size (hash_table
->dynstr
))
3053 const struct elf_backend_data
*bed
;
3056 bed
= get_elf_backend_data (hash_table
->dynobj
);
3057 sdyn
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
3059 for (extdyn
= sdyn
->contents
;
3060 extdyn
< sdyn
->contents
+ sdyn
->size
;
3061 extdyn
+= bed
->s
->sizeof_dyn
)
3063 Elf_Internal_Dyn dyn
;
3065 bed
->s
->swap_dyn_in (hash_table
->dynobj
, extdyn
, &dyn
);
3066 if (dyn
.d_tag
== DT_NEEDED
3067 && dyn
.d_un
.d_val
== strindex
)
3069 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
3077 if (!_bfd_elf_link_create_dynamic_sections (hash_table
->dynobj
, info
))
3080 if (!_bfd_elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
3084 /* We were just checking for existence of the tag. */
3085 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
3090 /* Sort symbol by value and section. */
3092 elf_sort_symbol (const void *arg1
, const void *arg2
)
3094 const struct elf_link_hash_entry
*h1
;
3095 const struct elf_link_hash_entry
*h2
;
3096 bfd_signed_vma vdiff
;
3098 h1
= *(const struct elf_link_hash_entry
**) arg1
;
3099 h2
= *(const struct elf_link_hash_entry
**) arg2
;
3100 vdiff
= h1
->root
.u
.def
.value
- h2
->root
.u
.def
.value
;
3102 return vdiff
> 0 ? 1 : -1;
3105 long sdiff
= h1
->root
.u
.def
.section
->id
- h2
->root
.u
.def
.section
->id
;
3107 return sdiff
> 0 ? 1 : -1;
3112 /* This function is used to adjust offsets into .dynstr for
3113 dynamic symbols. This is called via elf_link_hash_traverse. */
3116 elf_adjust_dynstr_offsets (struct elf_link_hash_entry
*h
, void *data
)
3118 struct elf_strtab_hash
*dynstr
= data
;
3120 if (h
->root
.type
== bfd_link_hash_warning
)
3121 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3123 if (h
->dynindx
!= -1)
3124 h
->dynstr_index
= _bfd_elf_strtab_offset (dynstr
, h
->dynstr_index
);
3128 /* Assign string offsets in .dynstr, update all structures referencing
3132 elf_finalize_dynstr (bfd
*output_bfd
, struct bfd_link_info
*info
)
3134 struct elf_link_hash_table
*hash_table
= elf_hash_table (info
);
3135 struct elf_link_local_dynamic_entry
*entry
;
3136 struct elf_strtab_hash
*dynstr
= hash_table
->dynstr
;
3137 bfd
*dynobj
= hash_table
->dynobj
;
3140 const struct elf_backend_data
*bed
;
3143 _bfd_elf_strtab_finalize (dynstr
);
3144 size
= _bfd_elf_strtab_size (dynstr
);
3146 bed
= get_elf_backend_data (dynobj
);
3147 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
3148 BFD_ASSERT (sdyn
!= NULL
);
3150 /* Update all .dynamic entries referencing .dynstr strings. */
3151 for (extdyn
= sdyn
->contents
;
3152 extdyn
< sdyn
->contents
+ sdyn
->size
;
3153 extdyn
+= bed
->s
->sizeof_dyn
)
3155 Elf_Internal_Dyn dyn
;
3157 bed
->s
->swap_dyn_in (dynobj
, extdyn
, &dyn
);
3161 dyn
.d_un
.d_val
= size
;
3169 dyn
.d_un
.d_val
= _bfd_elf_strtab_offset (dynstr
, dyn
.d_un
.d_val
);
3174 bed
->s
->swap_dyn_out (dynobj
, &dyn
, extdyn
);
3177 /* Now update local dynamic symbols. */
3178 for (entry
= hash_table
->dynlocal
; entry
; entry
= entry
->next
)
3179 entry
->isym
.st_name
= _bfd_elf_strtab_offset (dynstr
,
3180 entry
->isym
.st_name
);
3182 /* And the rest of dynamic symbols. */
3183 elf_link_hash_traverse (hash_table
, elf_adjust_dynstr_offsets
, dynstr
);
3185 /* Adjust version definitions. */
3186 if (elf_tdata (output_bfd
)->cverdefs
)
3191 Elf_Internal_Verdef def
;
3192 Elf_Internal_Verdaux defaux
;
3194 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
3198 _bfd_elf_swap_verdef_in (output_bfd
, (Elf_External_Verdef
*) p
,
3200 p
+= sizeof (Elf_External_Verdef
);
3201 if (def
.vd_aux
!= sizeof (Elf_External_Verdef
))
3203 for (i
= 0; i
< def
.vd_cnt
; ++i
)
3205 _bfd_elf_swap_verdaux_in (output_bfd
,
3206 (Elf_External_Verdaux
*) p
, &defaux
);
3207 defaux
.vda_name
= _bfd_elf_strtab_offset (dynstr
,
3209 _bfd_elf_swap_verdaux_out (output_bfd
,
3210 &defaux
, (Elf_External_Verdaux
*) p
);
3211 p
+= sizeof (Elf_External_Verdaux
);
3214 while (def
.vd_next
);
3217 /* Adjust version references. */
3218 if (elf_tdata (output_bfd
)->verref
)
3223 Elf_Internal_Verneed need
;
3224 Elf_Internal_Vernaux needaux
;
3226 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
3230 _bfd_elf_swap_verneed_in (output_bfd
, (Elf_External_Verneed
*) p
,
3232 need
.vn_file
= _bfd_elf_strtab_offset (dynstr
, need
.vn_file
);
3233 _bfd_elf_swap_verneed_out (output_bfd
, &need
,
3234 (Elf_External_Verneed
*) p
);
3235 p
+= sizeof (Elf_External_Verneed
);
3236 for (i
= 0; i
< need
.vn_cnt
; ++i
)
3238 _bfd_elf_swap_vernaux_in (output_bfd
,
3239 (Elf_External_Vernaux
*) p
, &needaux
);
3240 needaux
.vna_name
= _bfd_elf_strtab_offset (dynstr
,
3242 _bfd_elf_swap_vernaux_out (output_bfd
,
3244 (Elf_External_Vernaux
*) p
);
3245 p
+= sizeof (Elf_External_Vernaux
);
3248 while (need
.vn_next
);
3254 /* Add symbols from an ELF object file to the linker hash table. */
3257 elf_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
3259 Elf_Internal_Shdr
*hdr
;
3260 bfd_size_type symcount
;
3261 bfd_size_type extsymcount
;
3262 bfd_size_type extsymoff
;
3263 struct elf_link_hash_entry
**sym_hash
;
3264 bfd_boolean dynamic
;
3265 Elf_External_Versym
*extversym
= NULL
;
3266 Elf_External_Versym
*ever
;
3267 struct elf_link_hash_entry
*weaks
;
3268 struct elf_link_hash_entry
**nondeflt_vers
= NULL
;
3269 bfd_size_type nondeflt_vers_cnt
= 0;
3270 Elf_Internal_Sym
*isymbuf
= NULL
;
3271 Elf_Internal_Sym
*isym
;
3272 Elf_Internal_Sym
*isymend
;
3273 const struct elf_backend_data
*bed
;
3274 bfd_boolean add_needed
;
3275 struct elf_link_hash_table
*htab
;
3277 void *alloc_mark
= NULL
;
3278 struct bfd_hash_entry
**old_table
= NULL
;
3279 unsigned int old_size
= 0;
3280 unsigned int old_count
= 0;
3281 void *old_tab
= NULL
;
3284 struct bfd_link_hash_entry
*old_undefs
= NULL
;
3285 struct bfd_link_hash_entry
*old_undefs_tail
= NULL
;
3286 long old_dynsymcount
= 0;
3288 size_t hashsize
= 0;
3290 htab
= elf_hash_table (info
);
3291 bed
= get_elf_backend_data (abfd
);
3293 if ((abfd
->flags
& DYNAMIC
) == 0)
3299 /* You can't use -r against a dynamic object. Also, there's no
3300 hope of using a dynamic object which does not exactly match
3301 the format of the output file. */
3302 if (info
->relocatable
3303 || !is_elf_hash_table (htab
)
3304 || htab
->root
.creator
!= abfd
->xvec
)
3306 if (info
->relocatable
)
3307 bfd_set_error (bfd_error_invalid_operation
);
3309 bfd_set_error (bfd_error_wrong_format
);
3314 /* As a GNU extension, any input sections which are named
3315 .gnu.warning.SYMBOL are treated as warning symbols for the given
3316 symbol. This differs from .gnu.warning sections, which generate
3317 warnings when they are included in an output file. */
3318 if (info
->executable
)
3322 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
3326 name
= bfd_get_section_name (abfd
, s
);
3327 if (CONST_STRNEQ (name
, ".gnu.warning."))
3332 name
+= sizeof ".gnu.warning." - 1;
3334 /* If this is a shared object, then look up the symbol
3335 in the hash table. If it is there, and it is already
3336 been defined, then we will not be using the entry
3337 from this shared object, so we don't need to warn.
3338 FIXME: If we see the definition in a regular object
3339 later on, we will warn, but we shouldn't. The only
3340 fix is to keep track of what warnings we are supposed
3341 to emit, and then handle them all at the end of the
3345 struct elf_link_hash_entry
*h
;
3347 h
= elf_link_hash_lookup (htab
, name
, FALSE
, FALSE
, TRUE
);
3349 /* FIXME: What about bfd_link_hash_common? */
3351 && (h
->root
.type
== bfd_link_hash_defined
3352 || h
->root
.type
== bfd_link_hash_defweak
))
3354 /* We don't want to issue this warning. Clobber
3355 the section size so that the warning does not
3356 get copied into the output file. */
3363 msg
= bfd_alloc (abfd
, sz
+ 1);
3367 if (! bfd_get_section_contents (abfd
, s
, msg
, 0, sz
))
3372 if (! (_bfd_generic_link_add_one_symbol
3373 (info
, abfd
, name
, BSF_WARNING
, s
, 0, msg
,
3374 FALSE
, bed
->collect
, NULL
)))
3377 if (! info
->relocatable
)
3379 /* Clobber the section size so that the warning does
3380 not get copied into the output file. */
3383 /* Also set SEC_EXCLUDE, so that symbols defined in
3384 the warning section don't get copied to the output. */
3385 s
->flags
|= SEC_EXCLUDE
;
3394 /* If we are creating a shared library, create all the dynamic
3395 sections immediately. We need to attach them to something,
3396 so we attach them to this BFD, provided it is the right
3397 format. FIXME: If there are no input BFD's of the same
3398 format as the output, we can't make a shared library. */
3400 && is_elf_hash_table (htab
)
3401 && htab
->root
.creator
== abfd
->xvec
3402 && !htab
->dynamic_sections_created
)
3404 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
3408 else if (!is_elf_hash_table (htab
))
3413 const char *soname
= NULL
;
3414 struct bfd_link_needed_list
*rpath
= NULL
, *runpath
= NULL
;
3417 /* ld --just-symbols and dynamic objects don't mix very well.
3418 ld shouldn't allow it. */
3419 if ((s
= abfd
->sections
) != NULL
3420 && s
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
3423 /* If this dynamic lib was specified on the command line with
3424 --as-needed in effect, then we don't want to add a DT_NEEDED
3425 tag unless the lib is actually used. Similary for libs brought
3426 in by another lib's DT_NEEDED. When --no-add-needed is used
3427 on a dynamic lib, we don't want to add a DT_NEEDED entry for
3428 any dynamic library in DT_NEEDED tags in the dynamic lib at
3430 add_needed
= (elf_dyn_lib_class (abfd
)
3431 & (DYN_AS_NEEDED
| DYN_DT_NEEDED
3432 | DYN_NO_NEEDED
)) == 0;
3434 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3440 unsigned long shlink
;
3442 if (!bfd_malloc_and_get_section (abfd
, s
, &dynbuf
))
3443 goto error_free_dyn
;
3445 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
3447 goto error_free_dyn
;
3448 shlink
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
3450 for (extdyn
= dynbuf
;
3451 extdyn
< dynbuf
+ s
->size
;
3452 extdyn
+= bed
->s
->sizeof_dyn
)
3454 Elf_Internal_Dyn dyn
;
3456 bed
->s
->swap_dyn_in (abfd
, extdyn
, &dyn
);
3457 if (dyn
.d_tag
== DT_SONAME
)
3459 unsigned int tagv
= dyn
.d_un
.d_val
;
3460 soname
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3462 goto error_free_dyn
;
3464 if (dyn
.d_tag
== DT_NEEDED
)
3466 struct bfd_link_needed_list
*n
, **pn
;
3468 unsigned int tagv
= dyn
.d_un
.d_val
;
3470 amt
= sizeof (struct bfd_link_needed_list
);
3471 n
= bfd_alloc (abfd
, amt
);
3472 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3473 if (n
== NULL
|| fnm
== NULL
)
3474 goto error_free_dyn
;
3475 amt
= strlen (fnm
) + 1;
3476 anm
= bfd_alloc (abfd
, amt
);
3478 goto error_free_dyn
;
3479 memcpy (anm
, fnm
, amt
);
3483 for (pn
= &htab
->needed
; *pn
!= NULL
; pn
= &(*pn
)->next
)
3487 if (dyn
.d_tag
== DT_RUNPATH
)
3489 struct bfd_link_needed_list
*n
, **pn
;
3491 unsigned int tagv
= dyn
.d_un
.d_val
;
3493 amt
= sizeof (struct bfd_link_needed_list
);
3494 n
= bfd_alloc (abfd
, amt
);
3495 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3496 if (n
== NULL
|| fnm
== NULL
)
3497 goto error_free_dyn
;
3498 amt
= strlen (fnm
) + 1;
3499 anm
= bfd_alloc (abfd
, amt
);
3501 goto error_free_dyn
;
3502 memcpy (anm
, fnm
, amt
);
3506 for (pn
= & runpath
;
3512 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */
3513 if (!runpath
&& dyn
.d_tag
== DT_RPATH
)
3515 struct bfd_link_needed_list
*n
, **pn
;
3517 unsigned int tagv
= dyn
.d_un
.d_val
;
3519 amt
= sizeof (struct bfd_link_needed_list
);
3520 n
= bfd_alloc (abfd
, amt
);
3521 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3522 if (n
== NULL
|| fnm
== NULL
)
3523 goto error_free_dyn
;
3524 amt
= strlen (fnm
) + 1;
3525 anm
= bfd_alloc (abfd
, amt
);
3532 memcpy (anm
, fnm
, amt
);
3547 /* DT_RUNPATH overrides DT_RPATH. Do _NOT_ bfd_release, as that
3548 frees all more recently bfd_alloc'd blocks as well. */
3554 struct bfd_link_needed_list
**pn
;
3555 for (pn
= &htab
->runpath
; *pn
!= NULL
; pn
= &(*pn
)->next
)
3560 /* We do not want to include any of the sections in a dynamic
3561 object in the output file. We hack by simply clobbering the
3562 list of sections in the BFD. This could be handled more
3563 cleanly by, say, a new section flag; the existing
3564 SEC_NEVER_LOAD flag is not the one we want, because that one
3565 still implies that the section takes up space in the output
3567 bfd_section_list_clear (abfd
);
3569 /* Find the name to use in a DT_NEEDED entry that refers to this
3570 object. If the object has a DT_SONAME entry, we use it.
3571 Otherwise, if the generic linker stuck something in
3572 elf_dt_name, we use that. Otherwise, we just use the file
3574 if (soname
== NULL
|| *soname
== '\0')
3576 soname
= elf_dt_name (abfd
);
3577 if (soname
== NULL
|| *soname
== '\0')
3578 soname
= bfd_get_filename (abfd
);
3581 /* Save the SONAME because sometimes the linker emulation code
3582 will need to know it. */
3583 elf_dt_name (abfd
) = soname
;
3585 ret
= elf_add_dt_needed_tag (abfd
, info
, soname
, add_needed
);
3589 /* If we have already included this dynamic object in the
3590 link, just ignore it. There is no reason to include a
3591 particular dynamic object more than once. */
3596 /* If this is a dynamic object, we always link against the .dynsym
3597 symbol table, not the .symtab symbol table. The dynamic linker
3598 will only see the .dynsym symbol table, so there is no reason to
3599 look at .symtab for a dynamic object. */
3601 if (! dynamic
|| elf_dynsymtab (abfd
) == 0)
3602 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3604 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
3606 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
3608 /* The sh_info field of the symtab header tells us where the
3609 external symbols start. We don't care about the local symbols at
3611 if (elf_bad_symtab (abfd
))
3613 extsymcount
= symcount
;
3618 extsymcount
= symcount
- hdr
->sh_info
;
3619 extsymoff
= hdr
->sh_info
;
3623 if (extsymcount
!= 0)
3625 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
3627 if (isymbuf
== NULL
)
3630 /* We store a pointer to the hash table entry for each external
3632 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3633 sym_hash
= bfd_alloc (abfd
, amt
);
3634 if (sym_hash
== NULL
)
3635 goto error_free_sym
;
3636 elf_sym_hashes (abfd
) = sym_hash
;
3641 /* Read in any version definitions. */
3642 if (!_bfd_elf_slurp_version_tables (abfd
,
3643 info
->default_imported_symver
))
3644 goto error_free_sym
;
3646 /* Read in the symbol versions, but don't bother to convert them
3647 to internal format. */
3648 if (elf_dynversym (abfd
) != 0)
3650 Elf_Internal_Shdr
*versymhdr
;
3652 versymhdr
= &elf_tdata (abfd
)->dynversym_hdr
;
3653 extversym
= bfd_malloc (versymhdr
->sh_size
);
3654 if (extversym
== NULL
)
3655 goto error_free_sym
;
3656 amt
= versymhdr
->sh_size
;
3657 if (bfd_seek (abfd
, versymhdr
->sh_offset
, SEEK_SET
) != 0
3658 || bfd_bread (extversym
, amt
, abfd
) != amt
)
3659 goto error_free_vers
;
3663 /* If we are loading an as-needed shared lib, save the symbol table
3664 state before we start adding symbols. If the lib turns out
3665 to be unneeded, restore the state. */
3666 if ((elf_dyn_lib_class (abfd
) & DYN_AS_NEEDED
) != 0)
3671 for (entsize
= 0, i
= 0; i
< htab
->root
.table
.size
; i
++)
3673 struct bfd_hash_entry
*p
;
3674 struct elf_link_hash_entry
*h
;
3676 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
3678 h
= (struct elf_link_hash_entry
*) p
;
3679 entsize
+= htab
->root
.table
.entsize
;
3680 if (h
->root
.type
== bfd_link_hash_warning
)
3681 entsize
+= htab
->root
.table
.entsize
;
3685 tabsize
= htab
->root
.table
.size
* sizeof (struct bfd_hash_entry
*);
3686 hashsize
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3687 old_tab
= bfd_malloc (tabsize
+ entsize
+ hashsize
);
3688 if (old_tab
== NULL
)
3689 goto error_free_vers
;
3691 /* Remember the current objalloc pointer, so that all mem for
3692 symbols added can later be reclaimed. */
3693 alloc_mark
= bfd_hash_allocate (&htab
->root
.table
, 1);
3694 if (alloc_mark
== NULL
)
3695 goto error_free_vers
;
3697 /* Make a special call to the linker "notice" function to
3698 tell it that we are about to handle an as-needed lib. */
3699 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
3701 goto error_free_vers
;
3703 /* Clone the symbol table and sym hashes. Remember some
3704 pointers into the symbol table, and dynamic symbol count. */
3705 old_hash
= (char *) old_tab
+ tabsize
;
3706 old_ent
= (char *) old_hash
+ hashsize
;
3707 memcpy (old_tab
, htab
->root
.table
.table
, tabsize
);
3708 memcpy (old_hash
, sym_hash
, hashsize
);
3709 old_undefs
= htab
->root
.undefs
;
3710 old_undefs_tail
= htab
->root
.undefs_tail
;
3711 old_table
= htab
->root
.table
.table
;
3712 old_size
= htab
->root
.table
.size
;
3713 old_count
= htab
->root
.table
.count
;
3714 old_dynsymcount
= htab
->dynsymcount
;
3716 for (i
= 0; i
< htab
->root
.table
.size
; i
++)
3718 struct bfd_hash_entry
*p
;
3719 struct elf_link_hash_entry
*h
;
3721 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
3723 memcpy (old_ent
, p
, htab
->root
.table
.entsize
);
3724 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
3725 h
= (struct elf_link_hash_entry
*) p
;
3726 if (h
->root
.type
== bfd_link_hash_warning
)
3728 memcpy (old_ent
, h
->root
.u
.i
.link
, htab
->root
.table
.entsize
);
3729 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
3736 ever
= extversym
!= NULL
? extversym
+ extsymoff
: NULL
;
3737 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
;
3739 isym
++, sym_hash
++, ever
= (ever
!= NULL
? ever
+ 1 : NULL
))
3743 asection
*sec
, *new_sec
;
3746 struct elf_link_hash_entry
*h
;
3747 bfd_boolean definition
;
3748 bfd_boolean size_change_ok
;
3749 bfd_boolean type_change_ok
;
3750 bfd_boolean new_weakdef
;
3751 bfd_boolean override
;
3753 unsigned int old_alignment
;
3758 flags
= BSF_NO_FLAGS
;
3760 value
= isym
->st_value
;
3762 common
= bed
->common_definition (isym
);
3764 bind
= ELF_ST_BIND (isym
->st_info
);
3765 if (bind
== STB_LOCAL
)
3767 /* This should be impossible, since ELF requires that all
3768 global symbols follow all local symbols, and that sh_info
3769 point to the first global symbol. Unfortunately, Irix 5
3773 else if (bind
== STB_GLOBAL
)
3775 if (isym
->st_shndx
!= SHN_UNDEF
&& !common
)
3778 else if (bind
== STB_WEAK
)
3782 /* Leave it up to the processor backend. */
3785 if (isym
->st_shndx
== SHN_UNDEF
)
3786 sec
= bfd_und_section_ptr
;
3787 else if (isym
->st_shndx
< SHN_LORESERVE
3788 || isym
->st_shndx
> SHN_HIRESERVE
)
3790 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3792 sec
= bfd_abs_section_ptr
;
3793 else if (sec
->kept_section
)
3795 /* Symbols from discarded section are undefined. We keep
3797 sec
= bfd_und_section_ptr
;
3798 isym
->st_shndx
= SHN_UNDEF
;
3800 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
3803 else if (isym
->st_shndx
== SHN_ABS
)
3804 sec
= bfd_abs_section_ptr
;
3805 else if (isym
->st_shndx
== SHN_COMMON
)
3807 sec
= bfd_com_section_ptr
;
3808 /* What ELF calls the size we call the value. What ELF
3809 calls the value we call the alignment. */
3810 value
= isym
->st_size
;
3814 /* Leave it up to the processor backend. */
3817 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
3820 goto error_free_vers
;
3822 if (isym
->st_shndx
== SHN_COMMON
3823 && ELF_ST_TYPE (isym
->st_info
) == STT_TLS
3824 && !info
->relocatable
)
3826 asection
*tcomm
= bfd_get_section_by_name (abfd
, ".tcommon");
3830 tcomm
= bfd_make_section_with_flags (abfd
, ".tcommon",
3833 | SEC_LINKER_CREATED
3834 | SEC_THREAD_LOCAL
));
3836 goto error_free_vers
;
3840 else if (bed
->elf_add_symbol_hook
)
3842 if (! (*bed
->elf_add_symbol_hook
) (abfd
, info
, isym
, &name
, &flags
,
3844 goto error_free_vers
;
3846 /* The hook function sets the name to NULL if this symbol
3847 should be skipped for some reason. */
3852 /* Sanity check that all possibilities were handled. */
3855 bfd_set_error (bfd_error_bad_value
);
3856 goto error_free_vers
;
3859 if (bfd_is_und_section (sec
)
3860 || bfd_is_com_section (sec
))
3865 size_change_ok
= FALSE
;
3866 type_change_ok
= bed
->type_change_ok
;
3871 if (is_elf_hash_table (htab
))
3873 Elf_Internal_Versym iver
;
3874 unsigned int vernum
= 0;
3879 if (info
->default_imported_symver
)
3880 /* Use the default symbol version created earlier. */
3881 iver
.vs_vers
= elf_tdata (abfd
)->cverdefs
;
3886 _bfd_elf_swap_versym_in (abfd
, ever
, &iver
);
3888 vernum
= iver
.vs_vers
& VERSYM_VERSION
;
3890 /* If this is a hidden symbol, or if it is not version
3891 1, we append the version name to the symbol name.
3892 However, we do not modify a non-hidden absolute symbol
3893 if it is not a function, because it might be the version
3894 symbol itself. FIXME: What if it isn't? */
3895 if ((iver
.vs_vers
& VERSYM_HIDDEN
) != 0
3897 && (!bfd_is_abs_section (sec
)
3898 || bed
->is_function_type (ELF_ST_TYPE (isym
->st_info
)))))
3901 size_t namelen
, verlen
, newlen
;
3904 if (isym
->st_shndx
!= SHN_UNDEF
)
3906 if (vernum
> elf_tdata (abfd
)->cverdefs
)
3908 else if (vernum
> 1)
3910 elf_tdata (abfd
)->verdef
[vernum
- 1].vd_nodename
;
3916 (*_bfd_error_handler
)
3917 (_("%B: %s: invalid version %u (max %d)"),
3919 elf_tdata (abfd
)->cverdefs
);
3920 bfd_set_error (bfd_error_bad_value
);
3921 goto error_free_vers
;
3926 /* We cannot simply test for the number of
3927 entries in the VERNEED section since the
3928 numbers for the needed versions do not start
3930 Elf_Internal_Verneed
*t
;
3933 for (t
= elf_tdata (abfd
)->verref
;
3937 Elf_Internal_Vernaux
*a
;
3939 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3941 if (a
->vna_other
== vernum
)
3943 verstr
= a
->vna_nodename
;
3952 (*_bfd_error_handler
)
3953 (_("%B: %s: invalid needed version %d"),
3954 abfd
, name
, vernum
);
3955 bfd_set_error (bfd_error_bad_value
);
3956 goto error_free_vers
;
3960 namelen
= strlen (name
);
3961 verlen
= strlen (verstr
);
3962 newlen
= namelen
+ verlen
+ 2;
3963 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
3964 && isym
->st_shndx
!= SHN_UNDEF
)
3967 newname
= bfd_hash_allocate (&htab
->root
.table
, newlen
);
3968 if (newname
== NULL
)
3969 goto error_free_vers
;
3970 memcpy (newname
, name
, namelen
);
3971 p
= newname
+ namelen
;
3973 /* If this is a defined non-hidden version symbol,
3974 we add another @ to the name. This indicates the
3975 default version of the symbol. */
3976 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
3977 && isym
->st_shndx
!= SHN_UNDEF
)
3979 memcpy (p
, verstr
, verlen
+ 1);
3984 if (!_bfd_elf_merge_symbol (abfd
, info
, name
, isym
, &sec
,
3985 &value
, &old_alignment
,
3986 sym_hash
, &skip
, &override
,
3987 &type_change_ok
, &size_change_ok
))
3988 goto error_free_vers
;
3997 while (h
->root
.type
== bfd_link_hash_indirect
3998 || h
->root
.type
== bfd_link_hash_warning
)
3999 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4001 /* Remember the old alignment if this is a common symbol, so
4002 that we don't reduce the alignment later on. We can't
4003 check later, because _bfd_generic_link_add_one_symbol
4004 will set a default for the alignment which we want to
4005 override. We also remember the old bfd where the existing
4006 definition comes from. */
4007 switch (h
->root
.type
)
4012 case bfd_link_hash_defined
:
4013 case bfd_link_hash_defweak
:
4014 old_bfd
= h
->root
.u
.def
.section
->owner
;
4017 case bfd_link_hash_common
:
4018 old_bfd
= h
->root
.u
.c
.p
->section
->owner
;
4019 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
4023 if (elf_tdata (abfd
)->verdef
!= NULL
4027 h
->verinfo
.verdef
= &elf_tdata (abfd
)->verdef
[vernum
- 1];
4030 if (! (_bfd_generic_link_add_one_symbol
4031 (info
, abfd
, name
, flags
, sec
, value
, NULL
, FALSE
, bed
->collect
,
4032 (struct bfd_link_hash_entry
**) sym_hash
)))
4033 goto error_free_vers
;
4036 while (h
->root
.type
== bfd_link_hash_indirect
4037 || h
->root
.type
== bfd_link_hash_warning
)
4038 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4041 new_weakdef
= FALSE
;
4044 && (flags
& BSF_WEAK
) != 0
4045 && !bed
->is_function_type (ELF_ST_TYPE (isym
->st_info
))
4046 && is_elf_hash_table (htab
)
4047 && h
->u
.weakdef
== NULL
)
4049 /* Keep a list of all weak defined non function symbols from
4050 a dynamic object, using the weakdef field. Later in this
4051 function we will set the weakdef field to the correct
4052 value. We only put non-function symbols from dynamic
4053 objects on this list, because that happens to be the only
4054 time we need to know the normal symbol corresponding to a
4055 weak symbol, and the information is time consuming to
4056 figure out. If the weakdef field is not already NULL,
4057 then this symbol was already defined by some previous
4058 dynamic object, and we will be using that previous
4059 definition anyhow. */
4061 h
->u
.weakdef
= weaks
;
4066 /* Set the alignment of a common symbol. */
4067 if ((common
|| bfd_is_com_section (sec
))
4068 && h
->root
.type
== bfd_link_hash_common
)
4073 align
= bfd_log2 (isym
->st_value
);
4076 /* The new symbol is a common symbol in a shared object.
4077 We need to get the alignment from the section. */
4078 align
= new_sec
->alignment_power
;
4080 if (align
> old_alignment
4081 /* Permit an alignment power of zero if an alignment of one
4082 is specified and no other alignments have been specified. */
4083 || (isym
->st_value
== 1 && old_alignment
== 0))
4084 h
->root
.u
.c
.p
->alignment_power
= align
;
4086 h
->root
.u
.c
.p
->alignment_power
= old_alignment
;
4089 if (is_elf_hash_table (htab
))
4093 /* Check the alignment when a common symbol is involved. This
4094 can change when a common symbol is overridden by a normal
4095 definition or a common symbol is ignored due to the old
4096 normal definition. We need to make sure the maximum
4097 alignment is maintained. */
4098 if ((old_alignment
|| common
)
4099 && h
->root
.type
!= bfd_link_hash_common
)
4101 unsigned int common_align
;
4102 unsigned int normal_align
;
4103 unsigned int symbol_align
;
4107 symbol_align
= ffs (h
->root
.u
.def
.value
) - 1;
4108 if (h
->root
.u
.def
.section
->owner
!= NULL
4109 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
4111 normal_align
= h
->root
.u
.def
.section
->alignment_power
;
4112 if (normal_align
> symbol_align
)
4113 normal_align
= symbol_align
;
4116 normal_align
= symbol_align
;
4120 common_align
= old_alignment
;
4121 common_bfd
= old_bfd
;
4126 common_align
= bfd_log2 (isym
->st_value
);
4128 normal_bfd
= old_bfd
;
4131 if (normal_align
< common_align
)
4133 /* PR binutils/2735 */
4134 if (normal_bfd
== NULL
)
4135 (*_bfd_error_handler
)
4136 (_("Warning: alignment %u of common symbol `%s' in %B"
4137 " is greater than the alignment (%u) of its section %A"),
4138 common_bfd
, h
->root
.u
.def
.section
,
4139 1 << common_align
, name
, 1 << normal_align
);
4141 (*_bfd_error_handler
)
4142 (_("Warning: alignment %u of symbol `%s' in %B"
4143 " is smaller than %u in %B"),
4144 normal_bfd
, common_bfd
,
4145 1 << normal_align
, name
, 1 << common_align
);
4149 /* Remember the symbol size if it isn't undefined. */
4150 if ((isym
->st_size
!= 0 && isym
->st_shndx
!= SHN_UNDEF
)
4151 && (definition
|| h
->size
== 0))
4154 && h
->size
!= isym
->st_size
4155 && ! size_change_ok
)
4156 (*_bfd_error_handler
)
4157 (_("Warning: size of symbol `%s' changed"
4158 " from %lu in %B to %lu in %B"),
4160 name
, (unsigned long) h
->size
,
4161 (unsigned long) isym
->st_size
);
4163 h
->size
= isym
->st_size
;
4166 /* If this is a common symbol, then we always want H->SIZE
4167 to be the size of the common symbol. The code just above
4168 won't fix the size if a common symbol becomes larger. We
4169 don't warn about a size change here, because that is
4170 covered by --warn-common. Allow changed between different
4172 if (h
->root
.type
== bfd_link_hash_common
)
4173 h
->size
= h
->root
.u
.c
.size
;
4175 if (ELF_ST_TYPE (isym
->st_info
) != STT_NOTYPE
4176 && (definition
|| h
->type
== STT_NOTYPE
))
4178 if (h
->type
!= STT_NOTYPE
4179 && h
->type
!= ELF_ST_TYPE (isym
->st_info
)
4180 && ! type_change_ok
)
4181 (*_bfd_error_handler
)
4182 (_("Warning: type of symbol `%s' changed"
4183 " from %d to %d in %B"),
4184 abfd
, name
, h
->type
, ELF_ST_TYPE (isym
->st_info
));
4186 h
->type
= ELF_ST_TYPE (isym
->st_info
);
4189 /* If st_other has a processor-specific meaning, specific
4190 code might be needed here. We never merge the visibility
4191 attribute with the one from a dynamic object. */
4192 if (bed
->elf_backend_merge_symbol_attribute
)
4193 (*bed
->elf_backend_merge_symbol_attribute
) (h
, isym
, definition
,
4196 /* If this symbol has default visibility and the user has requested
4197 we not re-export it, then mark it as hidden. */
4198 if (definition
&& !dynamic
4200 || (abfd
->my_archive
&& abfd
->my_archive
->no_export
))
4201 && ELF_ST_VISIBILITY (isym
->st_other
) != STV_INTERNAL
)
4202 isym
->st_other
= (STV_HIDDEN
4203 | (isym
->st_other
& ~ELF_ST_VISIBILITY (-1)));
4205 if (ELF_ST_VISIBILITY (isym
->st_other
) != 0 && !dynamic
)
4207 unsigned char hvis
, symvis
, other
, nvis
;
4209 /* Only merge the visibility. Leave the remainder of the
4210 st_other field to elf_backend_merge_symbol_attribute. */
4211 other
= h
->other
& ~ELF_ST_VISIBILITY (-1);
4213 /* Combine visibilities, using the most constraining one. */
4214 hvis
= ELF_ST_VISIBILITY (h
->other
);
4215 symvis
= ELF_ST_VISIBILITY (isym
->st_other
);
4221 nvis
= hvis
< symvis
? hvis
: symvis
;
4223 h
->other
= other
| nvis
;
4226 /* Set a flag in the hash table entry indicating the type of
4227 reference or definition we just found. Keep a count of
4228 the number of dynamic symbols we find. A dynamic symbol
4229 is one which is referenced or defined by both a regular
4230 object and a shared object. */
4237 if (bind
!= STB_WEAK
)
4238 h
->ref_regular_nonweak
= 1;
4242 if (! info
->executable
4255 || (h
->u
.weakdef
!= NULL
4257 && h
->u
.weakdef
->dynindx
!= -1))
4261 if (definition
&& (sec
->flags
& SEC_DEBUGGING
))
4263 /* We don't want to make debug symbol dynamic. */
4264 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
4268 /* Check to see if we need to add an indirect symbol for
4269 the default name. */
4270 if (definition
|| h
->root
.type
== bfd_link_hash_common
)
4271 if (!_bfd_elf_add_default_symbol (abfd
, info
, h
, name
, isym
,
4272 &sec
, &value
, &dynsym
,
4274 goto error_free_vers
;
4276 if (definition
&& !dynamic
)
4278 char *p
= strchr (name
, ELF_VER_CHR
);
4279 if (p
!= NULL
&& p
[1] != ELF_VER_CHR
)
4281 /* Queue non-default versions so that .symver x, x@FOO
4282 aliases can be checked. */
4285 amt
= ((isymend
- isym
+ 1)
4286 * sizeof (struct elf_link_hash_entry
*));
4287 nondeflt_vers
= bfd_malloc (amt
);
4289 nondeflt_vers
[nondeflt_vers_cnt
++] = h
;
4293 if (dynsym
&& h
->dynindx
== -1)
4295 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4296 goto error_free_vers
;
4297 if (h
->u
.weakdef
!= NULL
4299 && h
->u
.weakdef
->dynindx
== -1)
4301 if (!bfd_elf_link_record_dynamic_symbol (info
, h
->u
.weakdef
))
4302 goto error_free_vers
;
4305 else if (dynsym
&& h
->dynindx
!= -1)
4306 /* If the symbol already has a dynamic index, but
4307 visibility says it should not be visible, turn it into
4309 switch (ELF_ST_VISIBILITY (h
->other
))
4313 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
4324 const char *soname
= elf_dt_name (abfd
);
4326 /* A symbol from a library loaded via DT_NEEDED of some
4327 other library is referenced by a regular object.
4328 Add a DT_NEEDED entry for it. Issue an error if
4329 --no-add-needed is used. */
4330 if ((elf_dyn_lib_class (abfd
) & DYN_NO_NEEDED
) != 0)
4332 (*_bfd_error_handler
)
4333 (_("%s: invalid DSO for symbol `%s' definition"),
4335 bfd_set_error (bfd_error_bad_value
);
4336 goto error_free_vers
;
4339 elf_dyn_lib_class (abfd
) &= ~DYN_AS_NEEDED
;
4342 ret
= elf_add_dt_needed_tag (abfd
, info
, soname
, add_needed
);
4344 goto error_free_vers
;
4346 BFD_ASSERT (ret
== 0);
4351 if (extversym
!= NULL
)
4357 if (isymbuf
!= NULL
)
4363 if ((elf_dyn_lib_class (abfd
) & DYN_AS_NEEDED
) != 0)
4367 /* Restore the symbol table. */
4368 if (bed
->as_needed_cleanup
)
4369 (*bed
->as_needed_cleanup
) (abfd
, info
);
4370 old_hash
= (char *) old_tab
+ tabsize
;
4371 old_ent
= (char *) old_hash
+ hashsize
;
4372 sym_hash
= elf_sym_hashes (abfd
);
4373 htab
->root
.table
.table
= old_table
;
4374 htab
->root
.table
.size
= old_size
;
4375 htab
->root
.table
.count
= old_count
;
4376 memcpy (htab
->root
.table
.table
, old_tab
, tabsize
);
4377 memcpy (sym_hash
, old_hash
, hashsize
);
4378 htab
->root
.undefs
= old_undefs
;
4379 htab
->root
.undefs_tail
= old_undefs_tail
;
4380 for (i
= 0; i
< htab
->root
.table
.size
; i
++)
4382 struct bfd_hash_entry
*p
;
4383 struct elf_link_hash_entry
*h
;
4385 for (p
= htab
->root
.table
.table
[i
]; p
!= NULL
; p
= p
->next
)
4387 h
= (struct elf_link_hash_entry
*) p
;
4388 if (h
->root
.type
== bfd_link_hash_warning
)
4389 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4390 if (h
->dynindx
>= old_dynsymcount
)
4391 _bfd_elf_strtab_delref (htab
->dynstr
, h
->dynstr_index
);
4393 memcpy (p
, old_ent
, htab
->root
.table
.entsize
);
4394 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
4395 h
= (struct elf_link_hash_entry
*) p
;
4396 if (h
->root
.type
== bfd_link_hash_warning
)
4398 memcpy (h
->root
.u
.i
.link
, old_ent
, htab
->root
.table
.entsize
);
4399 old_ent
= (char *) old_ent
+ htab
->root
.table
.entsize
;
4404 /* Make a special call to the linker "notice" function to
4405 tell it that symbols added for crefs may need to be removed. */
4406 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
4408 goto error_free_vers
;
4411 objalloc_free_block ((struct objalloc
*) htab
->root
.table
.memory
,
4413 if (nondeflt_vers
!= NULL
)
4414 free (nondeflt_vers
);
4418 if (old_tab
!= NULL
)
4420 if (!(*info
->callbacks
->notice
) (info
, NULL
, abfd
, NULL
,
4422 goto error_free_vers
;
4427 /* Now that all the symbols from this input file are created, handle
4428 .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */
4429 if (nondeflt_vers
!= NULL
)
4431 bfd_size_type cnt
, symidx
;
4433 for (cnt
= 0; cnt
< nondeflt_vers_cnt
; ++cnt
)
4435 struct elf_link_hash_entry
*h
= nondeflt_vers
[cnt
], *hi
;
4436 char *shortname
, *p
;
4438 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
4440 || (h
->root
.type
!= bfd_link_hash_defined
4441 && h
->root
.type
!= bfd_link_hash_defweak
))
4444 amt
= p
- h
->root
.root
.string
;
4445 shortname
= bfd_malloc (amt
+ 1);
4446 memcpy (shortname
, h
->root
.root
.string
, amt
);
4447 shortname
[amt
] = '\0';
4449 hi
= (struct elf_link_hash_entry
*)
4450 bfd_link_hash_lookup (&htab
->root
, shortname
,
4451 FALSE
, FALSE
, FALSE
);
4453 && hi
->root
.type
== h
->root
.type
4454 && hi
->root
.u
.def
.value
== h
->root
.u
.def
.value
4455 && hi
->root
.u
.def
.section
== h
->root
.u
.def
.section
)
4457 (*bed
->elf_backend_hide_symbol
) (info
, hi
, TRUE
);
4458 hi
->root
.type
= bfd_link_hash_indirect
;
4459 hi
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) h
;
4460 (*bed
->elf_backend_copy_indirect_symbol
) (info
, h
, hi
);
4461 sym_hash
= elf_sym_hashes (abfd
);
4463 for (symidx
= 0; symidx
< extsymcount
; ++symidx
)
4464 if (sym_hash
[symidx
] == hi
)
4466 sym_hash
[symidx
] = h
;
4472 free (nondeflt_vers
);
4473 nondeflt_vers
= NULL
;
4476 /* Now set the weakdefs field correctly for all the weak defined
4477 symbols we found. The only way to do this is to search all the
4478 symbols. Since we only need the information for non functions in
4479 dynamic objects, that's the only time we actually put anything on
4480 the list WEAKS. We need this information so that if a regular
4481 object refers to a symbol defined weakly in a dynamic object, the
4482 real symbol in the dynamic object is also put in the dynamic
4483 symbols; we also must arrange for both symbols to point to the
4484 same memory location. We could handle the general case of symbol
4485 aliasing, but a general symbol alias can only be generated in
4486 assembler code, handling it correctly would be very time
4487 consuming, and other ELF linkers don't handle general aliasing
4491 struct elf_link_hash_entry
**hpp
;
4492 struct elf_link_hash_entry
**hppend
;
4493 struct elf_link_hash_entry
**sorted_sym_hash
;
4494 struct elf_link_hash_entry
*h
;
4497 /* Since we have to search the whole symbol list for each weak
4498 defined symbol, search time for N weak defined symbols will be
4499 O(N^2). Binary search will cut it down to O(NlogN). */
4500 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
4501 sorted_sym_hash
= bfd_malloc (amt
);
4502 if (sorted_sym_hash
== NULL
)
4504 sym_hash
= sorted_sym_hash
;
4505 hpp
= elf_sym_hashes (abfd
);
4506 hppend
= hpp
+ extsymcount
;
4508 for (; hpp
< hppend
; hpp
++)
4512 && h
->root
.type
== bfd_link_hash_defined
4513 && !bed
->is_function_type (h
->type
))
4521 qsort (sorted_sym_hash
, sym_count
,
4522 sizeof (struct elf_link_hash_entry
*),
4525 while (weaks
!= NULL
)
4527 struct elf_link_hash_entry
*hlook
;
4534 weaks
= hlook
->u
.weakdef
;
4535 hlook
->u
.weakdef
= NULL
;
4537 BFD_ASSERT (hlook
->root
.type
== bfd_link_hash_defined
4538 || hlook
->root
.type
== bfd_link_hash_defweak
4539 || hlook
->root
.type
== bfd_link_hash_common
4540 || hlook
->root
.type
== bfd_link_hash_indirect
);
4541 slook
= hlook
->root
.u
.def
.section
;
4542 vlook
= hlook
->root
.u
.def
.value
;
4549 bfd_signed_vma vdiff
;
4551 h
= sorted_sym_hash
[idx
];
4552 vdiff
= vlook
- h
->root
.u
.def
.value
;
4559 long sdiff
= slook
->id
- h
->root
.u
.def
.section
->id
;
4572 /* We didn't find a value/section match. */
4576 for (i
= ilook
; i
< sym_count
; i
++)
4578 h
= sorted_sym_hash
[i
];
4580 /* Stop if value or section doesn't match. */
4581 if (h
->root
.u
.def
.value
!= vlook
4582 || h
->root
.u
.def
.section
!= slook
)
4584 else if (h
!= hlook
)
4586 hlook
->u
.weakdef
= h
;
4588 /* If the weak definition is in the list of dynamic
4589 symbols, make sure the real definition is put
4591 if (hlook
->dynindx
!= -1 && h
->dynindx
== -1)
4593 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
4597 /* If the real definition is in the list of dynamic
4598 symbols, make sure the weak definition is put
4599 there as well. If we don't do this, then the
4600 dynamic loader might not merge the entries for the
4601 real definition and the weak definition. */
4602 if (h
->dynindx
!= -1 && hlook
->dynindx
== -1)
4604 if (! bfd_elf_link_record_dynamic_symbol (info
, hlook
))
4612 free (sorted_sym_hash
);
4615 if (bed
->check_directives
)
4616 (*bed
->check_directives
) (abfd
, info
);
4618 /* If this object is the same format as the output object, and it is
4619 not a shared library, then let the backend look through the
4622 This is required to build global offset table entries and to
4623 arrange for dynamic relocs. It is not required for the
4624 particular common case of linking non PIC code, even when linking
4625 against shared libraries, but unfortunately there is no way of
4626 knowing whether an object file has been compiled PIC or not.
4627 Looking through the relocs is not particularly time consuming.
4628 The problem is that we must either (1) keep the relocs in memory,
4629 which causes the linker to require additional runtime memory or
4630 (2) read the relocs twice from the input file, which wastes time.
4631 This would be a good case for using mmap.
4633 I have no idea how to handle linking PIC code into a file of a
4634 different format. It probably can't be done. */
4636 && is_elf_hash_table (htab
)
4637 && htab
->root
.creator
== abfd
->xvec
4638 && bed
->check_relocs
!= NULL
)
4642 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4644 Elf_Internal_Rela
*internal_relocs
;
4647 if ((o
->flags
& SEC_RELOC
) == 0
4648 || o
->reloc_count
== 0
4649 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
4650 && (o
->flags
& SEC_DEBUGGING
) != 0)
4651 || bfd_is_abs_section (o
->output_section
))
4654 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
4656 if (internal_relocs
== NULL
)
4659 ok
= (*bed
->check_relocs
) (abfd
, info
, o
, internal_relocs
);
4661 if (elf_section_data (o
)->relocs
!= internal_relocs
)
4662 free (internal_relocs
);
4669 /* If this is a non-traditional link, try to optimize the handling
4670 of the .stab/.stabstr sections. */
4672 && ! info
->traditional_format
4673 && is_elf_hash_table (htab
)
4674 && (info
->strip
!= strip_all
&& info
->strip
!= strip_debugger
))
4678 stabstr
= bfd_get_section_by_name (abfd
, ".stabstr");
4679 if (stabstr
!= NULL
)
4681 bfd_size_type string_offset
= 0;
4684 for (stab
= abfd
->sections
; stab
; stab
= stab
->next
)
4685 if (CONST_STRNEQ (stab
->name
, ".stab")
4686 && (!stab
->name
[5] ||
4687 (stab
->name
[5] == '.' && ISDIGIT (stab
->name
[6])))
4688 && (stab
->flags
& SEC_MERGE
) == 0
4689 && !bfd_is_abs_section (stab
->output_section
))
4691 struct bfd_elf_section_data
*secdata
;
4693 secdata
= elf_section_data (stab
);
4694 if (! _bfd_link_section_stabs (abfd
, &htab
->stab_info
, stab
,
4695 stabstr
, &secdata
->sec_info
,
4698 if (secdata
->sec_info
)
4699 stab
->sec_info_type
= ELF_INFO_TYPE_STABS
;
4704 if (is_elf_hash_table (htab
) && add_needed
)
4706 /* Add this bfd to the loaded list. */
4707 struct elf_link_loaded_list
*n
;
4709 n
= bfd_alloc (abfd
, sizeof (struct elf_link_loaded_list
));
4713 n
->next
= htab
->loaded
;
4720 if (old_tab
!= NULL
)
4722 if (nondeflt_vers
!= NULL
)
4723 free (nondeflt_vers
);
4724 if (extversym
!= NULL
)
4727 if (isymbuf
!= NULL
)
4733 /* Return the linker hash table entry of a symbol that might be
4734 satisfied by an archive symbol. Return -1 on error. */
4736 struct elf_link_hash_entry
*
4737 _bfd_elf_archive_symbol_lookup (bfd
*abfd
,
4738 struct bfd_link_info
*info
,
4741 struct elf_link_hash_entry
*h
;
4745 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, FALSE
, FALSE
, FALSE
);
4749 /* If this is a default version (the name contains @@), look up the
4750 symbol again with only one `@' as well as without the version.
4751 The effect is that references to the symbol with and without the
4752 version will be matched by the default symbol in the archive. */
4754 p
= strchr (name
, ELF_VER_CHR
);
4755 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
4758 /* First check with only one `@'. */
4759 len
= strlen (name
);
4760 copy
= bfd_alloc (abfd
, len
);
4762 return (struct elf_link_hash_entry
*) 0 - 1;
4764 first
= p
- name
+ 1;
4765 memcpy (copy
, name
, first
);
4766 memcpy (copy
+ first
, name
+ first
+ 1, len
- first
);
4768 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
, FALSE
, FALSE
, FALSE
);
4771 /* We also need to check references to the symbol without the
4773 copy
[first
- 1] = '\0';
4774 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
,
4775 FALSE
, FALSE
, FALSE
);
4778 bfd_release (abfd
, copy
);
4782 /* Add symbols from an ELF archive file to the linker hash table. We
4783 don't use _bfd_generic_link_add_archive_symbols because of a
4784 problem which arises on UnixWare. The UnixWare libc.so is an
4785 archive which includes an entry libc.so.1 which defines a bunch of
4786 symbols. The libc.so archive also includes a number of other
4787 object files, which also define symbols, some of which are the same
4788 as those defined in libc.so.1. Correct linking requires that we
4789 consider each object file in turn, and include it if it defines any
4790 symbols we need. _bfd_generic_link_add_archive_symbols does not do
4791 this; it looks through the list of undefined symbols, and includes
4792 any object file which defines them. When this algorithm is used on
4793 UnixWare, it winds up pulling in libc.so.1 early and defining a
4794 bunch of symbols. This means that some of the other objects in the
4795 archive are not included in the link, which is incorrect since they
4796 precede libc.so.1 in the archive.
4798 Fortunately, ELF archive handling is simpler than that done by
4799 _bfd_generic_link_add_archive_symbols, which has to allow for a.out
4800 oddities. In ELF, if we find a symbol in the archive map, and the
4801 symbol is currently undefined, we know that we must pull in that
4804 Unfortunately, we do have to make multiple passes over the symbol
4805 table until nothing further is resolved. */
4808 elf_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4811 bfd_boolean
*defined
= NULL
;
4812 bfd_boolean
*included
= NULL
;
4816 const struct elf_backend_data
*bed
;
4817 struct elf_link_hash_entry
* (*archive_symbol_lookup
)
4818 (bfd
*, struct bfd_link_info
*, const char *);
4820 if (! bfd_has_map (abfd
))
4822 /* An empty archive is a special case. */
4823 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
4825 bfd_set_error (bfd_error_no_armap
);
4829 /* Keep track of all symbols we know to be already defined, and all
4830 files we know to be already included. This is to speed up the
4831 second and subsequent passes. */
4832 c
= bfd_ardata (abfd
)->symdef_count
;
4836 amt
*= sizeof (bfd_boolean
);
4837 defined
= bfd_zmalloc (amt
);
4838 included
= bfd_zmalloc (amt
);
4839 if (defined
== NULL
|| included
== NULL
)
4842 symdefs
= bfd_ardata (abfd
)->symdefs
;
4843 bed
= get_elf_backend_data (abfd
);
4844 archive_symbol_lookup
= bed
->elf_backend_archive_symbol_lookup
;
4857 symdefend
= symdef
+ c
;
4858 for (i
= 0; symdef
< symdefend
; symdef
++, i
++)
4860 struct elf_link_hash_entry
*h
;
4862 struct bfd_link_hash_entry
*undefs_tail
;
4865 if (defined
[i
] || included
[i
])
4867 if (symdef
->file_offset
== last
)
4873 h
= archive_symbol_lookup (abfd
, info
, symdef
->name
);
4874 if (h
== (struct elf_link_hash_entry
*) 0 - 1)
4880 if (h
->root
.type
== bfd_link_hash_common
)
4882 /* We currently have a common symbol. The archive map contains
4883 a reference to this symbol, so we may want to include it. We
4884 only want to include it however, if this archive element
4885 contains a definition of the symbol, not just another common
4888 Unfortunately some archivers (including GNU ar) will put
4889 declarations of common symbols into their archive maps, as
4890 well as real definitions, so we cannot just go by the archive
4891 map alone. Instead we must read in the element's symbol
4892 table and check that to see what kind of symbol definition
4894 if (! elf_link_is_defined_archive_symbol (abfd
, symdef
))
4897 else if (h
->root
.type
!= bfd_link_hash_undefined
)
4899 if (h
->root
.type
!= bfd_link_hash_undefweak
)
4904 /* We need to include this archive member. */
4905 element
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
4906 if (element
== NULL
)
4909 if (! bfd_check_format (element
, bfd_object
))
4912 /* Doublecheck that we have not included this object
4913 already--it should be impossible, but there may be
4914 something wrong with the archive. */
4915 if (element
->archive_pass
!= 0)
4917 bfd_set_error (bfd_error_bad_value
);
4920 element
->archive_pass
= 1;
4922 undefs_tail
= info
->hash
->undefs_tail
;
4924 if (! (*info
->callbacks
->add_archive_element
) (info
, element
,
4927 if (! bfd_link_add_symbols (element
, info
))
4930 /* If there are any new undefined symbols, we need to make
4931 another pass through the archive in order to see whether
4932 they can be defined. FIXME: This isn't perfect, because
4933 common symbols wind up on undefs_tail and because an
4934 undefined symbol which is defined later on in this pass
4935 does not require another pass. This isn't a bug, but it
4936 does make the code less efficient than it could be. */
4937 if (undefs_tail
!= info
->hash
->undefs_tail
)
4940 /* Look backward to mark all symbols from this object file
4941 which we have already seen in this pass. */
4945 included
[mark
] = TRUE
;
4950 while (symdefs
[mark
].file_offset
== symdef
->file_offset
);
4952 /* We mark subsequent symbols from this object file as we go
4953 on through the loop. */
4954 last
= symdef
->file_offset
;
4965 if (defined
!= NULL
)
4967 if (included
!= NULL
)
4972 /* Given an ELF BFD, add symbols to the global hash table as
4976 bfd_elf_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4978 switch (bfd_get_format (abfd
))
4981 return elf_link_add_object_symbols (abfd
, info
);
4983 return elf_link_add_archive_symbols (abfd
, info
);
4985 bfd_set_error (bfd_error_wrong_format
);
4990 /* This function will be called though elf_link_hash_traverse to store
4991 all hash value of the exported symbols in an array. */
4994 elf_collect_hash_codes (struct elf_link_hash_entry
*h
, void *data
)
4996 unsigned long **valuep
= data
;
5002 if (h
->root
.type
== bfd_link_hash_warning
)
5003 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5005 /* Ignore indirect symbols. These are added by the versioning code. */
5006 if (h
->dynindx
== -1)
5009 name
= h
->root
.root
.string
;
5010 p
= strchr (name
, ELF_VER_CHR
);
5013 alc
= bfd_malloc (p
- name
+ 1);
5014 memcpy (alc
, name
, p
- name
);
5015 alc
[p
- name
] = '\0';
5019 /* Compute the hash value. */
5020 ha
= bfd_elf_hash (name
);
5022 /* Store the found hash value in the array given as the argument. */
5025 /* And store it in the struct so that we can put it in the hash table
5027 h
->u
.elf_hash_value
= ha
;
5035 struct collect_gnu_hash_codes
5038 const struct elf_backend_data
*bed
;
5039 unsigned long int nsyms
;
5040 unsigned long int maskbits
;
5041 unsigned long int *hashcodes
;
5042 unsigned long int *hashval
;
5043 unsigned long int *indx
;
5044 unsigned long int *counts
;
5047 long int min_dynindx
;
5048 unsigned long int bucketcount
;
5049 unsigned long int symindx
;
5050 long int local_indx
;
5051 long int shift1
, shift2
;
5052 unsigned long int mask
;
5055 /* This function will be called though elf_link_hash_traverse to store
5056 all hash value of the exported symbols in an array. */
5059 elf_collect_gnu_hash_codes (struct elf_link_hash_entry
*h
, void *data
)
5061 struct collect_gnu_hash_codes
*s
= data
;
5067 if (h
->root
.type
== bfd_link_hash_warning
)
5068 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5070 /* Ignore indirect symbols. These are added by the versioning code. */
5071 if (h
->dynindx
== -1)
5074 /* Ignore also local symbols and undefined symbols. */
5075 if (! (*s
->bed
->elf_hash_symbol
) (h
))
5078 name
= h
->root
.root
.string
;
5079 p
= strchr (name
, ELF_VER_CHR
);
5082 alc
= bfd_malloc (p
- name
+ 1);
5083 memcpy (alc
, name
, p
- name
);
5084 alc
[p
- name
] = '\0';
5088 /* Compute the hash value. */
5089 ha
= bfd_elf_gnu_hash (name
);
5091 /* Store the found hash value in the array for compute_bucket_count,
5092 and also for .dynsym reordering purposes. */
5093 s
->hashcodes
[s
->nsyms
] = ha
;
5094 s
->hashval
[h
->dynindx
] = ha
;
5096 if (s
->min_dynindx
< 0 || s
->min_dynindx
> h
->dynindx
)
5097 s
->min_dynindx
= h
->dynindx
;
5105 /* This function will be called though elf_link_hash_traverse to do
5106 final dynaminc symbol renumbering. */
5109 elf_renumber_gnu_hash_syms (struct elf_link_hash_entry
*h
, void *data
)
5111 struct collect_gnu_hash_codes
*s
= data
;
5112 unsigned long int bucket
;
5113 unsigned long int val
;
5115 if (h
->root
.type
== bfd_link_hash_warning
)
5116 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
5118 /* Ignore indirect symbols. */
5119 if (h
->dynindx
== -1)
5122 /* Ignore also local symbols and undefined symbols. */
5123 if (! (*s
->bed
->elf_hash_symbol
) (h
))
5125 if (h
->dynindx
>= s
->min_dynindx
)
5126 h
->dynindx
= s
->local_indx
++;
5130 bucket
= s
->hashval
[h
->dynindx
] % s
->bucketcount
;
5131 val
= (s
->hashval
[h
->dynindx
] >> s
->shift1
)
5132 & ((s
->maskbits
>> s
->shift1
) - 1);
5133 s
->bitmask
[val
] |= ((bfd_vma
) 1) << (s
->hashval
[h
->dynindx
] & s
->mask
);
5135 |= ((bfd_vma
) 1) << ((s
->hashval
[h
->dynindx
] >> s
->shift2
) & s
->mask
);
5136 val
= s
->hashval
[h
->dynindx
] & ~(unsigned long int) 1;
5137 if (s
->counts
[bucket
] == 1)
5138 /* Last element terminates the chain. */
5140 bfd_put_32 (s
->output_bfd
, val
,
5141 s
->contents
+ (s
->indx
[bucket
] - s
->symindx
) * 4);
5142 --s
->counts
[bucket
];
5143 h
->dynindx
= s
->indx
[bucket
]++;
5147 /* Return TRUE if symbol should be hashed in the `.gnu.hash' section. */
5150 _bfd_elf_hash_symbol (struct elf_link_hash_entry
*h
)
5152 return !(h
->forced_local
5153 || h
->root
.type
== bfd_link_hash_undefined
5154 || h
->root
.type
== bfd_link_hash_undefweak
5155 || ((h
->root
.type
== bfd_link_hash_defined
5156 || h
->root
.type
== bfd_link_hash_defweak
)
5157 && h
->root
.u
.def
.section
->output_section
== NULL
));
5160 /* Array used to determine the number of hash table buckets to use
5161 based on the number of symbols there are. If there are fewer than
5162 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
5163 fewer than 37 we use 17 buckets, and so forth. We never use more
5164 than 32771 buckets. */
5166 static const size_t elf_buckets
[] =
5168 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
5172 /* Compute bucket count for hashing table. We do not use a static set
5173 of possible tables sizes anymore. Instead we determine for all
5174 possible reasonable sizes of the table the outcome (i.e., the
5175 number of collisions etc) and choose the best solution. The
5176 weighting functions are not too simple to allow the table to grow
5177 without bounds. Instead one of the weighting factors is the size.
5178 Therefore the result is always a good payoff between few collisions
5179 (= short chain lengths) and table size. */
5181 compute_bucket_count (struct bfd_link_info
*info
, unsigned long int *hashcodes
,
5182 unsigned long int nsyms
, int gnu_hash
)
5184 size_t dynsymcount
= elf_hash_table (info
)->dynsymcount
;
5185 size_t best_size
= 0;
5186 unsigned long int i
;
5189 /* We have a problem here. The following code to optimize the table
5190 size requires an integer type with more the 32 bits. If
5191 BFD_HOST_U_64_BIT is set we know about such a type. */
5192 #ifdef BFD_HOST_U_64_BIT
5197 BFD_HOST_U_64_BIT best_chlen
= ~((BFD_HOST_U_64_BIT
) 0);
5198 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
5199 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
5200 unsigned long int *counts
;
5202 /* Possible optimization parameters: if we have NSYMS symbols we say
5203 that the hashing table must at least have NSYMS/4 and at most
5205 minsize
= nsyms
/ 4;
5208 best_size
= maxsize
= nsyms
* 2;
5213 if ((best_size
& 31) == 0)
5217 /* Create array where we count the collisions in. We must use bfd_malloc
5218 since the size could be large. */
5220 amt
*= sizeof (unsigned long int);
5221 counts
= bfd_malloc (amt
);
5225 /* Compute the "optimal" size for the hash table. The criteria is a
5226 minimal chain length. The minor criteria is (of course) the size
5228 for (i
= minsize
; i
< maxsize
; ++i
)
5230 /* Walk through the array of hashcodes and count the collisions. */
5231 BFD_HOST_U_64_BIT max
;
5232 unsigned long int j
;
5233 unsigned long int fact
;
5235 if (gnu_hash
&& (i
& 31) == 0)
5238 memset (counts
, '\0', i
* sizeof (unsigned long int));
5240 /* Determine how often each hash bucket is used. */
5241 for (j
= 0; j
< nsyms
; ++j
)
5242 ++counts
[hashcodes
[j
] % i
];
5244 /* For the weight function we need some information about the
5245 pagesize on the target. This is information need not be 100%
5246 accurate. Since this information is not available (so far) we
5247 define it here to a reasonable default value. If it is crucial
5248 to have a better value some day simply define this value. */
5249 # ifndef BFD_TARGET_PAGESIZE
5250 # define BFD_TARGET_PAGESIZE (4096)
5253 /* We in any case need 2 + DYNSYMCOUNT entries for the size values
5255 max
= (2 + dynsymcount
) * bed
->s
->sizeof_hash_entry
;
5258 /* Variant 1: optimize for short chains. We add the squares
5259 of all the chain lengths (which favors many small chain
5260 over a few long chains). */
5261 for (j
= 0; j
< i
; ++j
)
5262 max
+= counts
[j
] * counts
[j
];
5264 /* This adds penalties for the overall size of the table. */
5265 fact
= i
/ (BFD_TARGET_PAGESIZE
/ bed
->s
->sizeof_hash_entry
) + 1;
5268 /* Variant 2: Optimize a lot more for small table. Here we
5269 also add squares of the size but we also add penalties for
5270 empty slots (the +1 term). */
5271 for (j
= 0; j
< i
; ++j
)
5272 max
+= (1 + counts
[j
]) * (1 + counts
[j
]);
5274 /* The overall size of the table is considered, but not as
5275 strong as in variant 1, where it is squared. */
5276 fact
= i
/ (BFD_TARGET_PAGESIZE
/ bed
->s
->sizeof_hash_entry
) + 1;
5280 /* Compare with current best results. */
5281 if (max
< best_chlen
)
5291 #endif /* defined (BFD_HOST_U_64_BIT) */
5293 /* This is the fallback solution if no 64bit type is available or if we
5294 are not supposed to spend much time on optimizations. We select the
5295 bucket count using a fixed set of numbers. */
5296 for (i
= 0; elf_buckets
[i
] != 0; i
++)
5298 best_size
= elf_buckets
[i
];
5299 if (nsyms
< elf_buckets
[i
+ 1])
5302 if (gnu_hash
&& best_size
< 2)
5309 /* Set up the sizes and contents of the ELF dynamic sections. This is
5310 called by the ELF linker emulation before_allocation routine. We
5311 must set the sizes of the sections before the linker sets the
5312 addresses of the various sections. */
5315 bfd_elf_size_dynamic_sections (bfd
*output_bfd
,
5318 const char *filter_shlib
,
5319 const char * const *auxiliary_filters
,
5320 struct bfd_link_info
*info
,
5321 asection
**sinterpptr
,
5322 struct bfd_elf_version_tree
*verdefs
)
5324 bfd_size_type soname_indx
;
5326 const struct elf_backend_data
*bed
;
5327 struct elf_assign_sym_version_info asvinfo
;
5331 soname_indx
= (bfd_size_type
) -1;
5333 if (!is_elf_hash_table (info
->hash
))
5336 bed
= get_elf_backend_data (output_bfd
);
5337 elf_tdata (output_bfd
)->relro
= info
->relro
;
5338 if (info
->execstack
)
5339 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
5340 else if (info
->noexecstack
)
5341 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
;
5345 asection
*notesec
= NULL
;
5348 for (inputobj
= info
->input_bfds
;
5350 inputobj
= inputobj
->link_next
)
5354 if (inputobj
->flags
& (DYNAMIC
| BFD_LINKER_CREATED
))
5356 s
= bfd_get_section_by_name (inputobj
, ".note.GNU-stack");
5359 if (s
->flags
& SEC_CODE
)
5363 else if (bed
->default_execstack
)
5368 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| exec
;
5369 if (exec
&& info
->relocatable
5370 && notesec
->output_section
!= bfd_abs_section_ptr
)
5371 notesec
->output_section
->flags
|= SEC_CODE
;
5375 /* Any syms created from now on start with -1 in
5376 got.refcount/offset and plt.refcount/offset. */
5377 elf_hash_table (info
)->init_got_refcount
5378 = elf_hash_table (info
)->init_got_offset
;
5379 elf_hash_table (info
)->init_plt_refcount
5380 = elf_hash_table (info
)->init_plt_offset
;
5382 /* The backend may have to create some sections regardless of whether
5383 we're dynamic or not. */
5384 if (bed
->elf_backend_always_size_sections
5385 && ! (*bed
->elf_backend_always_size_sections
) (output_bfd
, info
))
5388 if (! _bfd_elf_maybe_strip_eh_frame_hdr (info
))
5391 dynobj
= elf_hash_table (info
)->dynobj
;
5393 /* If there were no dynamic objects in the link, there is nothing to
5398 if (elf_hash_table (info
)->dynamic_sections_created
)
5400 struct elf_info_failed eif
;
5401 struct elf_link_hash_entry
*h
;
5403 struct bfd_elf_version_tree
*t
;
5404 struct bfd_elf_version_expr
*d
;
5406 bfd_boolean all_defined
;
5408 *sinterpptr
= bfd_get_section_by_name (dynobj
, ".interp");
5409 BFD_ASSERT (*sinterpptr
!= NULL
|| !info
->executable
);
5413 soname_indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5415 if (soname_indx
== (bfd_size_type
) -1
5416 || !_bfd_elf_add_dynamic_entry (info
, DT_SONAME
, soname_indx
))
5422 if (!_bfd_elf_add_dynamic_entry (info
, DT_SYMBOLIC
, 0))
5424 info
->flags
|= DF_SYMBOLIC
;
5431 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
, rpath
,
5433 if (indx
== (bfd_size_type
) -1
5434 || !_bfd_elf_add_dynamic_entry (info
, DT_RPATH
, indx
))
5437 if (info
->new_dtags
)
5439 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
, indx
);
5440 if (!_bfd_elf_add_dynamic_entry (info
, DT_RUNPATH
, indx
))
5445 if (filter_shlib
!= NULL
)
5449 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5450 filter_shlib
, TRUE
);
5451 if (indx
== (bfd_size_type
) -1
5452 || !_bfd_elf_add_dynamic_entry (info
, DT_FILTER
, indx
))
5456 if (auxiliary_filters
!= NULL
)
5458 const char * const *p
;
5460 for (p
= auxiliary_filters
; *p
!= NULL
; p
++)
5464 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5466 if (indx
== (bfd_size_type
) -1
5467 || !_bfd_elf_add_dynamic_entry (info
, DT_AUXILIARY
, indx
))
5473 eif
.verdefs
= verdefs
;
5476 /* If we are supposed to export all symbols into the dynamic symbol
5477 table (this is not the normal case), then do so. */
5478 if (info
->export_dynamic
5479 || (info
->executable
&& info
->dynamic
))
5481 elf_link_hash_traverse (elf_hash_table (info
),
5482 _bfd_elf_export_symbol
,
5488 /* Make all global versions with definition. */
5489 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5490 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
5491 if (!d
->symver
&& d
->symbol
)
5493 const char *verstr
, *name
;
5494 size_t namelen
, verlen
, newlen
;
5496 struct elf_link_hash_entry
*newh
;
5499 namelen
= strlen (name
);
5501 verlen
= strlen (verstr
);
5502 newlen
= namelen
+ verlen
+ 3;
5504 newname
= bfd_malloc (newlen
);
5505 if (newname
== NULL
)
5507 memcpy (newname
, name
, namelen
);
5509 /* Check the hidden versioned definition. */
5510 p
= newname
+ namelen
;
5512 memcpy (p
, verstr
, verlen
+ 1);
5513 newh
= elf_link_hash_lookup (elf_hash_table (info
),
5514 newname
, FALSE
, FALSE
,
5517 || (newh
->root
.type
!= bfd_link_hash_defined
5518 && newh
->root
.type
!= bfd_link_hash_defweak
))
5520 /* Check the default versioned definition. */
5522 memcpy (p
, verstr
, verlen
+ 1);
5523 newh
= elf_link_hash_lookup (elf_hash_table (info
),
5524 newname
, FALSE
, FALSE
,
5529 /* Mark this version if there is a definition and it is
5530 not defined in a shared object. */
5532 && !newh
->def_dynamic
5533 && (newh
->root
.type
== bfd_link_hash_defined
5534 || newh
->root
.type
== bfd_link_hash_defweak
))
5538 /* Attach all the symbols to their version information. */
5539 asvinfo
.output_bfd
= output_bfd
;
5540 asvinfo
.info
= info
;
5541 asvinfo
.verdefs
= verdefs
;
5542 asvinfo
.failed
= FALSE
;
5544 elf_link_hash_traverse (elf_hash_table (info
),
5545 _bfd_elf_link_assign_sym_version
,
5550 if (!info
->allow_undefined_version
)
5552 /* Check if all global versions have a definition. */
5554 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5555 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
5556 if (!d
->symver
&& !d
->script
)
5558 (*_bfd_error_handler
)
5559 (_("%s: undefined version: %s"),
5560 d
->pattern
, t
->name
);
5561 all_defined
= FALSE
;
5566 bfd_set_error (bfd_error_bad_value
);
5571 /* Find all symbols which were defined in a dynamic object and make
5572 the backend pick a reasonable value for them. */
5573 elf_link_hash_traverse (elf_hash_table (info
),
5574 _bfd_elf_adjust_dynamic_symbol
,
5579 /* Add some entries to the .dynamic section. We fill in some of the
5580 values later, in bfd_elf_final_link, but we must add the entries
5581 now so that we know the final size of the .dynamic section. */
5583 /* If there are initialization and/or finalization functions to
5584 call then add the corresponding DT_INIT/DT_FINI entries. */
5585 h
= (info
->init_function
5586 ? elf_link_hash_lookup (elf_hash_table (info
),
5587 info
->init_function
, FALSE
,
5594 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT
, 0))
5597 h
= (info
->fini_function
5598 ? elf_link_hash_lookup (elf_hash_table (info
),
5599 info
->fini_function
, FALSE
,
5606 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI
, 0))
5610 s
= bfd_get_section_by_name (output_bfd
, ".preinit_array");
5611 if (s
!= NULL
&& s
->linker_has_input
)
5613 /* DT_PREINIT_ARRAY is not allowed in shared library. */
5614 if (! info
->executable
)
5619 for (sub
= info
->input_bfds
; sub
!= NULL
;
5620 sub
= sub
->link_next
)
5621 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
)
5622 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
5623 if (elf_section_data (o
)->this_hdr
.sh_type
5624 == SHT_PREINIT_ARRAY
)
5626 (*_bfd_error_handler
)
5627 (_("%B: .preinit_array section is not allowed in DSO"),
5632 bfd_set_error (bfd_error_nonrepresentable_section
);
5636 if (!_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAY
, 0)
5637 || !_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAYSZ
, 0))
5640 s
= bfd_get_section_by_name (output_bfd
, ".init_array");
5641 if (s
!= NULL
&& s
->linker_has_input
)
5643 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAY
, 0)
5644 || !_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAYSZ
, 0))
5647 s
= bfd_get_section_by_name (output_bfd
, ".fini_array");
5648 if (s
!= NULL
&& s
->linker_has_input
)
5650 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAY
, 0)
5651 || !_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAYSZ
, 0))
5655 dynstr
= bfd_get_section_by_name (dynobj
, ".dynstr");
5656 /* If .dynstr is excluded from the link, we don't want any of
5657 these tags. Strictly, we should be checking each section
5658 individually; This quick check covers for the case where
5659 someone does a /DISCARD/ : { *(*) }. */
5660 if (dynstr
!= NULL
&& dynstr
->output_section
!= bfd_abs_section_ptr
)
5662 bfd_size_type strsize
;
5664 strsize
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5665 if ((info
->emit_hash
5666 && !_bfd_elf_add_dynamic_entry (info
, DT_HASH
, 0))
5667 || (info
->emit_gnu_hash
5668 && !_bfd_elf_add_dynamic_entry (info
, DT_GNU_HASH
, 0))
5669 || !_bfd_elf_add_dynamic_entry (info
, DT_STRTAB
, 0)
5670 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMTAB
, 0)
5671 || !_bfd_elf_add_dynamic_entry (info
, DT_STRSZ
, strsize
)
5672 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMENT
,
5673 bed
->s
->sizeof_sym
))
5678 /* The backend must work out the sizes of all the other dynamic
5680 if (bed
->elf_backend_size_dynamic_sections
5681 && ! (*bed
->elf_backend_size_dynamic_sections
) (output_bfd
, info
))
5684 if (elf_hash_table (info
)->dynamic_sections_created
)
5686 unsigned long section_sym_count
;
5689 /* Set up the version definition section. */
5690 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
5691 BFD_ASSERT (s
!= NULL
);
5693 /* We may have created additional version definitions if we are
5694 just linking a regular application. */
5695 verdefs
= asvinfo
.verdefs
;
5697 /* Skip anonymous version tag. */
5698 if (verdefs
!= NULL
&& verdefs
->vernum
== 0)
5699 verdefs
= verdefs
->next
;
5701 if (verdefs
== NULL
&& !info
->create_default_symver
)
5702 s
->flags
|= SEC_EXCLUDE
;
5707 struct bfd_elf_version_tree
*t
;
5709 Elf_Internal_Verdef def
;
5710 Elf_Internal_Verdaux defaux
;
5711 struct bfd_link_hash_entry
*bh
;
5712 struct elf_link_hash_entry
*h
;
5718 /* Make space for the base version. */
5719 size
+= sizeof (Elf_External_Verdef
);
5720 size
+= sizeof (Elf_External_Verdaux
);
5723 /* Make space for the default version. */
5724 if (info
->create_default_symver
)
5726 size
+= sizeof (Elf_External_Verdef
);
5730 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5732 struct bfd_elf_version_deps
*n
;
5734 size
+= sizeof (Elf_External_Verdef
);
5735 size
+= sizeof (Elf_External_Verdaux
);
5738 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5739 size
+= sizeof (Elf_External_Verdaux
);
5743 s
->contents
= bfd_alloc (output_bfd
, s
->size
);
5744 if (s
->contents
== NULL
&& s
->size
!= 0)
5747 /* Fill in the version definition section. */
5751 def
.vd_version
= VER_DEF_CURRENT
;
5752 def
.vd_flags
= VER_FLG_BASE
;
5755 if (info
->create_default_symver
)
5757 def
.vd_aux
= 2 * sizeof (Elf_External_Verdef
);
5758 def
.vd_next
= sizeof (Elf_External_Verdef
);
5762 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5763 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5764 + sizeof (Elf_External_Verdaux
));
5767 if (soname_indx
!= (bfd_size_type
) -1)
5769 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5771 def
.vd_hash
= bfd_elf_hash (soname
);
5772 defaux
.vda_name
= soname_indx
;
5779 name
= lbasename (output_bfd
->filename
);
5780 def
.vd_hash
= bfd_elf_hash (name
);
5781 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5783 if (indx
== (bfd_size_type
) -1)
5785 defaux
.vda_name
= indx
;
5787 defaux
.vda_next
= 0;
5789 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
5790 (Elf_External_Verdef
*) p
);
5791 p
+= sizeof (Elf_External_Verdef
);
5792 if (info
->create_default_symver
)
5794 /* Add a symbol representing this version. */
5796 if (! (_bfd_generic_link_add_one_symbol
5797 (info
, dynobj
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
5799 get_elf_backend_data (dynobj
)->collect
, &bh
)))
5801 h
= (struct elf_link_hash_entry
*) bh
;
5804 h
->type
= STT_OBJECT
;
5805 h
->verinfo
.vertree
= NULL
;
5807 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5810 /* Create a duplicate of the base version with the same
5811 aux block, but different flags. */
5814 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5816 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5817 + sizeof (Elf_External_Verdaux
));
5820 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
5821 (Elf_External_Verdef
*) p
);
5822 p
+= sizeof (Elf_External_Verdef
);
5824 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5825 (Elf_External_Verdaux
*) p
);
5826 p
+= sizeof (Elf_External_Verdaux
);
5828 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5831 struct bfd_elf_version_deps
*n
;
5834 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5837 /* Add a symbol representing this version. */
5839 if (! (_bfd_generic_link_add_one_symbol
5840 (info
, dynobj
, t
->name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
5842 get_elf_backend_data (dynobj
)->collect
, &bh
)))
5844 h
= (struct elf_link_hash_entry
*) bh
;
5847 h
->type
= STT_OBJECT
;
5848 h
->verinfo
.vertree
= t
;
5850 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
5853 def
.vd_version
= VER_DEF_CURRENT
;
5855 if (t
->globals
.list
== NULL
5856 && t
->locals
.list
== NULL
5858 def
.vd_flags
|= VER_FLG_WEAK
;
5859 def
.vd_ndx
= t
->vernum
+ (info
->create_default_symver
? 2 : 1);
5860 def
.vd_cnt
= cdeps
+ 1;
5861 def
.vd_hash
= bfd_elf_hash (t
->name
);
5862 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5864 if (t
->next
!= NULL
)
5865 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5866 + (cdeps
+ 1) * sizeof (Elf_External_Verdaux
));
5868 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
5869 (Elf_External_Verdef
*) p
);
5870 p
+= sizeof (Elf_External_Verdef
);
5872 defaux
.vda_name
= h
->dynstr_index
;
5873 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5875 defaux
.vda_next
= 0;
5876 if (t
->deps
!= NULL
)
5877 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
5878 t
->name_indx
= defaux
.vda_name
;
5880 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5881 (Elf_External_Verdaux
*) p
);
5882 p
+= sizeof (Elf_External_Verdaux
);
5884 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5886 if (n
->version_needed
== NULL
)
5888 /* This can happen if there was an error in the
5890 defaux
.vda_name
= 0;
5894 defaux
.vda_name
= n
->version_needed
->name_indx
;
5895 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5898 if (n
->next
== NULL
)
5899 defaux
.vda_next
= 0;
5901 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
5903 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5904 (Elf_External_Verdaux
*) p
);
5905 p
+= sizeof (Elf_External_Verdaux
);
5909 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERDEF
, 0)
5910 || !_bfd_elf_add_dynamic_entry (info
, DT_VERDEFNUM
, cdefs
))
5913 elf_tdata (output_bfd
)->cverdefs
= cdefs
;
5916 if ((info
->new_dtags
&& info
->flags
) || (info
->flags
& DF_STATIC_TLS
))
5918 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS
, info
->flags
))
5921 else if (info
->flags
& DF_BIND_NOW
)
5923 if (!_bfd_elf_add_dynamic_entry (info
, DT_BIND_NOW
, 0))
5929 if (info
->executable
)
5930 info
->flags_1
&= ~ (DF_1_INITFIRST
5933 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS_1
, info
->flags_1
))
5937 /* Work out the size of the version reference section. */
5939 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
5940 BFD_ASSERT (s
!= NULL
);
5942 struct elf_find_verdep_info sinfo
;
5944 sinfo
.output_bfd
= output_bfd
;
5946 sinfo
.vers
= elf_tdata (output_bfd
)->cverdefs
;
5947 if (sinfo
.vers
== 0)
5949 sinfo
.failed
= FALSE
;
5951 elf_link_hash_traverse (elf_hash_table (info
),
5952 _bfd_elf_link_find_version_dependencies
,
5955 if (elf_tdata (output_bfd
)->verref
== NULL
)
5956 s
->flags
|= SEC_EXCLUDE
;
5959 Elf_Internal_Verneed
*t
;
5964 /* Build the version definition section. */
5967 for (t
= elf_tdata (output_bfd
)->verref
;
5971 Elf_Internal_Vernaux
*a
;
5973 size
+= sizeof (Elf_External_Verneed
);
5975 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
5976 size
+= sizeof (Elf_External_Vernaux
);
5980 s
->contents
= bfd_alloc (output_bfd
, s
->size
);
5981 if (s
->contents
== NULL
)
5985 for (t
= elf_tdata (output_bfd
)->verref
;
5990 Elf_Internal_Vernaux
*a
;
5994 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
5997 t
->vn_version
= VER_NEED_CURRENT
;
5999 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
6000 elf_dt_name (t
->vn_bfd
) != NULL
6001 ? elf_dt_name (t
->vn_bfd
)
6002 : lbasename (t
->vn_bfd
->filename
),
6004 if (indx
== (bfd_size_type
) -1)
6007 t
->vn_aux
= sizeof (Elf_External_Verneed
);
6008 if (t
->vn_nextref
== NULL
)
6011 t
->vn_next
= (sizeof (Elf_External_Verneed
)
6012 + caux
* sizeof (Elf_External_Vernaux
));
6014 _bfd_elf_swap_verneed_out (output_bfd
, t
,
6015 (Elf_External_Verneed
*) p
);
6016 p
+= sizeof (Elf_External_Verneed
);
6018 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
6020 a
->vna_hash
= bfd_elf_hash (a
->vna_nodename
);
6021 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
6022 a
->vna_nodename
, FALSE
);
6023 if (indx
== (bfd_size_type
) -1)
6026 if (a
->vna_nextptr
== NULL
)
6029 a
->vna_next
= sizeof (Elf_External_Vernaux
);
6031 _bfd_elf_swap_vernaux_out (output_bfd
, a
,
6032 (Elf_External_Vernaux
*) p
);
6033 p
+= sizeof (Elf_External_Vernaux
);
6037 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERNEED
, 0)
6038 || !_bfd_elf_add_dynamic_entry (info
, DT_VERNEEDNUM
, crefs
))
6041 elf_tdata (output_bfd
)->cverrefs
= crefs
;
6045 if ((elf_tdata (output_bfd
)->cverrefs
== 0
6046 && elf_tdata (output_bfd
)->cverdefs
== 0)
6047 || _bfd_elf_link_renumber_dynsyms (output_bfd
, info
,
6048 §ion_sym_count
) == 0)
6050 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
6051 s
->flags
|= SEC_EXCLUDE
;
6057 /* Find the first non-excluded output section. We'll use its
6058 section symbol for some emitted relocs. */
6060 _bfd_elf_init_1_index_section (bfd
*output_bfd
, struct bfd_link_info
*info
)
6064 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6065 if ((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
)) == SEC_ALLOC
6066 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6068 elf_hash_table (info
)->text_index_section
= s
;
6073 /* Find two non-excluded output sections, one for code, one for data.
6074 We'll use their section symbols for some emitted relocs. */
6076 _bfd_elf_init_2_index_sections (bfd
*output_bfd
, struct bfd_link_info
*info
)
6080 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6081 if (((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
| SEC_READONLY
))
6082 == (SEC_ALLOC
| SEC_READONLY
))
6083 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6085 elf_hash_table (info
)->text_index_section
= s
;
6089 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
6090 if (((s
->flags
& (SEC_EXCLUDE
| SEC_ALLOC
| SEC_READONLY
)) == SEC_ALLOC
)
6091 && !_bfd_elf_link_omit_section_dynsym (output_bfd
, info
, s
))
6093 elf_hash_table (info
)->data_index_section
= s
;
6097 if (elf_hash_table (info
)->text_index_section
== NULL
)
6098 elf_hash_table (info
)->text_index_section
6099 = elf_hash_table (info
)->data_index_section
;
6103 bfd_elf_size_dynsym_hash_dynstr (bfd
*output_bfd
, struct bfd_link_info
*info
)
6105 const struct elf_backend_data
*bed
;
6107 if (!is_elf_hash_table (info
->hash
))
6110 bed
= get_elf_backend_data (output_bfd
);
6111 (*bed
->elf_backend_init_index_section
) (output_bfd
, info
);
6113 if (elf_hash_table (info
)->dynamic_sections_created
)
6117 bfd_size_type dynsymcount
;
6118 unsigned long section_sym_count
;
6119 unsigned int dtagcount
;
6121 dynobj
= elf_hash_table (info
)->dynobj
;
6123 /* Assign dynsym indicies. In a shared library we generate a
6124 section symbol for each output section, which come first.
6125 Next come all of the back-end allocated local dynamic syms,
6126 followed by the rest of the global symbols. */
6128 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
,
6129 §ion_sym_count
);
6131 /* Work out the size of the symbol version section. */
6132 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
6133 BFD_ASSERT (s
!= NULL
);
6134 if (dynsymcount
!= 0
6135 && (s
->flags
& SEC_EXCLUDE
) == 0)
6137 s
->size
= dynsymcount
* sizeof (Elf_External_Versym
);
6138 s
->contents
= bfd_zalloc (output_bfd
, s
->size
);
6139 if (s
->contents
== NULL
)
6142 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERSYM
, 0))
6146 /* Set the size of the .dynsym and .hash sections. We counted
6147 the number of dynamic symbols in elf_link_add_object_symbols.
6148 We will build the contents of .dynsym and .hash when we build
6149 the final symbol table, because until then we do not know the
6150 correct value to give the symbols. We built the .dynstr
6151 section as we went along in elf_link_add_object_symbols. */
6152 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
6153 BFD_ASSERT (s
!= NULL
);
6154 s
->size
= dynsymcount
* bed
->s
->sizeof_sym
;
6156 if (dynsymcount
!= 0)
6158 s
->contents
= bfd_alloc (output_bfd
, s
->size
);
6159 if (s
->contents
== NULL
)
6162 /* The first entry in .dynsym is a dummy symbol.
6163 Clear all the section syms, in case we don't output them all. */
6164 ++section_sym_count
;
6165 memset (s
->contents
, 0, section_sym_count
* bed
->s
->sizeof_sym
);
6168 elf_hash_table (info
)->bucketcount
= 0;
6170 /* Compute the size of the hashing table. As a side effect this
6171 computes the hash values for all the names we export. */
6172 if (info
->emit_hash
)
6174 unsigned long int *hashcodes
;
6175 unsigned long int *hashcodesp
;
6177 unsigned long int nsyms
;
6179 size_t hash_entry_size
;
6181 /* Compute the hash values for all exported symbols. At the same
6182 time store the values in an array so that we could use them for
6184 amt
= dynsymcount
* sizeof (unsigned long int);
6185 hashcodes
= bfd_malloc (amt
);
6186 if (hashcodes
== NULL
)
6188 hashcodesp
= hashcodes
;
6190 /* Put all hash values in HASHCODES. */
6191 elf_link_hash_traverse (elf_hash_table (info
),
6192 elf_collect_hash_codes
, &hashcodesp
);
6194 nsyms
= hashcodesp
- hashcodes
;
6196 = compute_bucket_count (info
, hashcodes
, nsyms
, 0);
6199 if (bucketcount
== 0)
6202 elf_hash_table (info
)->bucketcount
= bucketcount
;
6204 s
= bfd_get_section_by_name (dynobj
, ".hash");
6205 BFD_ASSERT (s
!= NULL
);
6206 hash_entry_size
= elf_section_data (s
)->this_hdr
.sh_entsize
;
6207 s
->size
= ((2 + bucketcount
+ dynsymcount
) * hash_entry_size
);
6208 s
->contents
= bfd_zalloc (output_bfd
, s
->size
);
6209 if (s
->contents
== NULL
)
6212 bfd_put (8 * hash_entry_size
, output_bfd
, bucketcount
, s
->contents
);
6213 bfd_put (8 * hash_entry_size
, output_bfd
, dynsymcount
,
6214 s
->contents
+ hash_entry_size
);
6217 if (info
->emit_gnu_hash
)
6220 unsigned char *contents
;
6221 struct collect_gnu_hash_codes cinfo
;
6225 memset (&cinfo
, 0, sizeof (cinfo
));
6227 /* Compute the hash values for all exported symbols. At the same
6228 time store the values in an array so that we could use them for
6230 amt
= dynsymcount
* 2 * sizeof (unsigned long int);
6231 cinfo
.hashcodes
= bfd_malloc (amt
);
6232 if (cinfo
.hashcodes
== NULL
)
6235 cinfo
.hashval
= cinfo
.hashcodes
+ dynsymcount
;
6236 cinfo
.min_dynindx
= -1;
6237 cinfo
.output_bfd
= output_bfd
;
6240 /* Put all hash values in HASHCODES. */
6241 elf_link_hash_traverse (elf_hash_table (info
),
6242 elf_collect_gnu_hash_codes
, &cinfo
);
6245 = compute_bucket_count (info
, cinfo
.hashcodes
, cinfo
.nsyms
, 1);
6247 if (bucketcount
== 0)
6249 free (cinfo
.hashcodes
);
6253 s
= bfd_get_section_by_name (dynobj
, ".gnu.hash");
6254 BFD_ASSERT (s
!= NULL
);
6256 if (cinfo
.nsyms
== 0)
6258 /* Empty .gnu.hash section is special. */
6259 BFD_ASSERT (cinfo
.min_dynindx
== -1);
6260 free (cinfo
.hashcodes
);
6261 s
->size
= 5 * 4 + bed
->s
->arch_size
/ 8;
6262 contents
= bfd_zalloc (output_bfd
, s
->size
);
6263 if (contents
== NULL
)
6265 s
->contents
= contents
;
6266 /* 1 empty bucket. */
6267 bfd_put_32 (output_bfd
, 1, contents
);
6268 /* SYMIDX above the special symbol 0. */
6269 bfd_put_32 (output_bfd
, 1, contents
+ 4);
6270 /* Just one word for bitmask. */
6271 bfd_put_32 (output_bfd
, 1, contents
+ 8);
6272 /* Only hash fn bloom filter. */
6273 bfd_put_32 (output_bfd
, 0, contents
+ 12);
6274 /* No hashes are valid - empty bitmask. */
6275 bfd_put (bed
->s
->arch_size
, output_bfd
, 0, contents
+ 16);
6276 /* No hashes in the only bucket. */
6277 bfd_put_32 (output_bfd
, 0,
6278 contents
+ 16 + bed
->s
->arch_size
/ 8);
6282 unsigned long int maskwords
, maskbitslog2
;
6283 BFD_ASSERT (cinfo
.min_dynindx
!= -1);
6285 maskbitslog2
= bfd_log2 (cinfo
.nsyms
) + 1;
6286 if (maskbitslog2
< 3)
6288 else if ((1 << (maskbitslog2
- 2)) & cinfo
.nsyms
)
6289 maskbitslog2
= maskbitslog2
+ 3;
6291 maskbitslog2
= maskbitslog2
+ 2;
6292 if (bed
->s
->arch_size
== 64)
6294 if (maskbitslog2
== 5)
6300 cinfo
.mask
= (1 << cinfo
.shift1
) - 1;
6301 cinfo
.shift2
= maskbitslog2
;
6302 cinfo
.maskbits
= 1 << maskbitslog2
;
6303 maskwords
= 1 << (maskbitslog2
- cinfo
.shift1
);
6304 amt
= bucketcount
* sizeof (unsigned long int) * 2;
6305 amt
+= maskwords
* sizeof (bfd_vma
);
6306 cinfo
.bitmask
= bfd_malloc (amt
);
6307 if (cinfo
.bitmask
== NULL
)
6309 free (cinfo
.hashcodes
);
6313 cinfo
.counts
= (void *) (cinfo
.bitmask
+ maskwords
);
6314 cinfo
.indx
= cinfo
.counts
+ bucketcount
;
6315 cinfo
.symindx
= dynsymcount
- cinfo
.nsyms
;
6316 memset (cinfo
.bitmask
, 0, maskwords
* sizeof (bfd_vma
));
6318 /* Determine how often each hash bucket is used. */
6319 memset (cinfo
.counts
, 0, bucketcount
* sizeof (cinfo
.counts
[0]));
6320 for (i
= 0; i
< cinfo
.nsyms
; ++i
)
6321 ++cinfo
.counts
[cinfo
.hashcodes
[i
] % bucketcount
];
6323 for (i
= 0, cnt
= cinfo
.symindx
; i
< bucketcount
; ++i
)
6324 if (cinfo
.counts
[i
] != 0)
6326 cinfo
.indx
[i
] = cnt
;
6327 cnt
+= cinfo
.counts
[i
];
6329 BFD_ASSERT (cnt
== dynsymcount
);
6330 cinfo
.bucketcount
= bucketcount
;
6331 cinfo
.local_indx
= cinfo
.min_dynindx
;
6333 s
->size
= (4 + bucketcount
+ cinfo
.nsyms
) * 4;
6334 s
->size
+= cinfo
.maskbits
/ 8;
6335 contents
= bfd_zalloc (output_bfd
, s
->size
);
6336 if (contents
== NULL
)
6338 free (cinfo
.bitmask
);
6339 free (cinfo
.hashcodes
);
6343 s
->contents
= contents
;
6344 bfd_put_32 (output_bfd
, bucketcount
, contents
);
6345 bfd_put_32 (output_bfd
, cinfo
.symindx
, contents
+ 4);
6346 bfd_put_32 (output_bfd
, maskwords
, contents
+ 8);
6347 bfd_put_32 (output_bfd
, cinfo
.shift2
, contents
+ 12);
6348 contents
+= 16 + cinfo
.maskbits
/ 8;
6350 for (i
= 0; i
< bucketcount
; ++i
)
6352 if (cinfo
.counts
[i
] == 0)
6353 bfd_put_32 (output_bfd
, 0, contents
);
6355 bfd_put_32 (output_bfd
, cinfo
.indx
[i
], contents
);
6359 cinfo
.contents
= contents
;
6361 /* Renumber dynamic symbols, populate .gnu.hash section. */
6362 elf_link_hash_traverse (elf_hash_table (info
),
6363 elf_renumber_gnu_hash_syms
, &cinfo
);
6365 contents
= s
->contents
+ 16;
6366 for (i
= 0; i
< maskwords
; ++i
)
6368 bfd_put (bed
->s
->arch_size
, output_bfd
, cinfo
.bitmask
[i
],
6370 contents
+= bed
->s
->arch_size
/ 8;
6373 free (cinfo
.bitmask
);
6374 free (cinfo
.hashcodes
);
6378 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
6379 BFD_ASSERT (s
!= NULL
);
6381 elf_finalize_dynstr (output_bfd
, info
);
6383 s
->size
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
6385 for (dtagcount
= 0; dtagcount
<= info
->spare_dynamic_tags
; ++dtagcount
)
6386 if (!_bfd_elf_add_dynamic_entry (info
, DT_NULL
, 0))
6393 /* Final phase of ELF linker. */
6395 /* A structure we use to avoid passing large numbers of arguments. */
6397 struct elf_final_link_info
6399 /* General link information. */
6400 struct bfd_link_info
*info
;
6403 /* Symbol string table. */
6404 struct bfd_strtab_hash
*symstrtab
;
6405 /* .dynsym section. */
6406 asection
*dynsym_sec
;
6407 /* .hash section. */
6409 /* symbol version section (.gnu.version). */
6410 asection
*symver_sec
;
6411 /* Buffer large enough to hold contents of any section. */
6413 /* Buffer large enough to hold external relocs of any section. */
6414 void *external_relocs
;
6415 /* Buffer large enough to hold internal relocs of any section. */
6416 Elf_Internal_Rela
*internal_relocs
;
6417 /* Buffer large enough to hold external local symbols of any input
6419 bfd_byte
*external_syms
;
6420 /* And a buffer for symbol section indices. */
6421 Elf_External_Sym_Shndx
*locsym_shndx
;
6422 /* Buffer large enough to hold internal local symbols of any input
6424 Elf_Internal_Sym
*internal_syms
;
6425 /* Array large enough to hold a symbol index for each local symbol
6426 of any input BFD. */
6428 /* Array large enough to hold a section pointer for each local
6429 symbol of any input BFD. */
6430 asection
**sections
;
6431 /* Buffer to hold swapped out symbols. */
6433 /* And one for symbol section indices. */
6434 Elf_External_Sym_Shndx
*symshndxbuf
;
6435 /* Number of swapped out symbols in buffer. */
6436 size_t symbuf_count
;
6437 /* Number of symbols which fit in symbuf. */
6439 /* And same for symshndxbuf. */
6440 size_t shndxbuf_size
;
6443 /* This struct is used to pass information to elf_link_output_extsym. */
6445 struct elf_outext_info
6448 bfd_boolean localsyms
;
6449 struct elf_final_link_info
*finfo
;
6453 /* Support for evaluating a complex relocation.
6455 Complex relocations are generalized, self-describing relocations. The
6456 implementation of them consists of two parts: complex symbols, and the
6457 relocations themselves.
6459 The relocations are use a reserved elf-wide relocation type code (R_RELC
6460 external / BFD_RELOC_RELC internal) and an encoding of relocation field
6461 information (start bit, end bit, word width, etc) into the addend. This
6462 information is extracted from CGEN-generated operand tables within gas.
6464 Complex symbols are mangled symbols (BSF_RELC external / STT_RELC
6465 internal) representing prefix-notation expressions, including but not
6466 limited to those sorts of expressions normally encoded as addends in the
6467 addend field. The symbol mangling format is:
6470 | <unary-operator> ':' <node>
6471 | <binary-operator> ':' <node> ':' <node>
6474 <literal> := 's' <digits=N> ':' <N character symbol name>
6475 | 'S' <digits=N> ':' <N character section name>
6479 <binary-operator> := as in C
6480 <unary-operator> := as in C, plus "0-" for unambiguous negation. */
6483 set_symbol_value (bfd
* bfd_with_globals
,
6484 struct elf_final_link_info
* finfo
,
6488 bfd_boolean is_local
;
6489 Elf_Internal_Sym
* sym
;
6490 struct elf_link_hash_entry
** sym_hashes
;
6491 struct elf_link_hash_entry
* h
;
6493 sym_hashes
= elf_sym_hashes (bfd_with_globals
);
6494 sym
= finfo
->internal_syms
+ symidx
;
6495 is_local
= ELF_ST_BIND(sym
->st_info
) == STB_LOCAL
;
6499 /* It is a local symbol: move it to the
6500 "absolute" section and give it a value. */
6501 sym
->st_shndx
= SHN_ABS
;
6502 sym
->st_value
= val
;
6506 /* It is a global symbol: set its link type
6507 to "defined" and give it a value. */
6508 h
= sym_hashes
[symidx
];
6509 while (h
->root
.type
== bfd_link_hash_indirect
6510 || h
->root
.type
== bfd_link_hash_warning
)
6511 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6512 h
->root
.type
= bfd_link_hash_defined
;
6513 h
->root
.u
.def
.value
= val
;
6514 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
6519 resolve_symbol (const char * name
,
6521 struct elf_final_link_info
* finfo
,
6525 Elf_Internal_Sym
* sym
;
6526 struct bfd_link_hash_entry
* global_entry
;
6527 const char * candidate
= NULL
;
6528 Elf_Internal_Shdr
* symtab_hdr
;
6529 asection
* sec
= NULL
;
6532 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
6534 for (i
= 0; i
< locsymcount
; ++ i
)
6536 sym
= finfo
->internal_syms
+ i
;
6537 sec
= finfo
->sections
[i
];
6539 if (ELF_ST_BIND (sym
->st_info
) != STB_LOCAL
)
6542 candidate
= bfd_elf_string_from_elf_section (input_bfd
,
6543 symtab_hdr
->sh_link
,
6546 printf ("Comparing string: '%s' vs. '%s' = 0x%x\n",
6547 name
, candidate
, (unsigned int)sym
->st_value
);
6549 if (candidate
&& strcmp (candidate
, name
) == 0)
6551 * result
= sym
->st_value
;
6553 if (sym
->st_shndx
> SHN_UNDEF
&&
6554 sym
->st_shndx
< SHN_LORESERVE
)
6557 printf ("adjusting for sec '%s' @ 0x%x + 0x%x\n",
6558 sec
->output_section
->name
,
6559 (unsigned int)sec
->output_section
->vma
,
6560 (unsigned int)sec
->output_offset
);
6562 * result
+= sec
->output_offset
+ sec
->output_section
->vma
;
6565 printf ("Found symbol with effective value %8.8x\n", (unsigned int)* result
);
6571 /* Hmm, haven't found it yet. perhaps it is a global. */
6572 global_entry
= bfd_link_hash_lookup (finfo
->info
->hash
, name
, FALSE
, FALSE
, TRUE
);
6576 if (global_entry
->type
== bfd_link_hash_defined
6577 || global_entry
->type
== bfd_link_hash_defweak
)
6579 * result
= global_entry
->u
.def
.value
6580 + global_entry
->u
.def
.section
->output_section
->vma
6581 + global_entry
->u
.def
.section
->output_offset
;
6583 printf ("Found GLOBAL symbol '%s' with value %8.8x\n",
6584 global_entry
->root
.string
, (unsigned int)*result
);
6589 if (global_entry
->type
== bfd_link_hash_common
)
6591 *result
= global_entry
->u
.def
.value
+
6592 bfd_com_section_ptr
->output_section
->vma
+
6593 bfd_com_section_ptr
->output_offset
;
6595 printf ("Found COMMON symbol '%s' with value %8.8x\n",
6596 global_entry
->root
.string
, (unsigned int)*result
);
6605 resolve_section (const char * name
,
6606 asection
* sections
,
6612 for (curr
= sections
; curr
; curr
= curr
->next
)
6613 if (strcmp (curr
->name
, name
) == 0)
6615 *result
= curr
->vma
;
6619 /* Hmm. still haven't found it. try pseudo-section names. */
6620 for (curr
= sections
; curr
; curr
= curr
->next
)
6622 len
= strlen (curr
->name
);
6623 if (len
> strlen (name
))
6626 if (strncmp (curr
->name
, name
, len
) == 0)
6628 if (strncmp (".end", name
+ len
, 4) == 0)
6630 *result
= curr
->vma
+ curr
->size
;
6634 /* Insert more pseudo-section names here, if you like. */
6642 undefined_reference (const char * reftype
,
6645 _bfd_error_handler (_("undefined %s reference in complex symbol: %s"), reftype
, name
);
6649 eval_symbol (bfd_vma
* result
,
6653 struct elf_final_link_info
* finfo
,
6655 bfd_vma section_offset
,
6663 const int bufsz
= 4096;
6664 char symbuf
[bufsz
];
6665 const char * symend
;
6666 bfd_boolean symbol_is_section
= FALSE
;
6671 if (len
< 1 || len
> bufsz
)
6673 bfd_set_error (bfd_error_invalid_operation
);
6680 * result
= addr
+ section_offset
;
6681 * advanced
= sym
+ 1;
6686 * result
= strtoul (sym
, advanced
, 16);
6690 symbol_is_section
= TRUE
;
6693 symlen
= strtol (sym
, &sym
, 10);
6694 ++ sym
; /* Skip the trailing ':'. */
6696 if ((symend
< sym
) || ((symlen
+ 1) > bufsz
))
6698 bfd_set_error (bfd_error_invalid_operation
);
6702 memcpy (symbuf
, sym
, symlen
);
6703 symbuf
[symlen
] = '\0';
6704 * advanced
= sym
+ symlen
;
6706 /* Is it always possible, with complex symbols, that gas "mis-guessed"
6707 the symbol as a section, or vice-versa. so we're pretty liberal in our
6708 interpretation here; section means "try section first", not "must be a
6709 section", and likewise with symbol. */
6711 if (symbol_is_section
)
6713 if ((resolve_section (symbuf
, finfo
->output_bfd
->sections
, result
) != TRUE
)
6714 && (resolve_symbol (symbuf
, input_bfd
, finfo
, result
, locsymcount
) != TRUE
))
6716 undefined_reference ("section", symbuf
);
6722 if ((resolve_symbol (symbuf
, input_bfd
, finfo
, result
, locsymcount
) != TRUE
)
6723 && (resolve_section (symbuf
, finfo
->output_bfd
->sections
,
6726 undefined_reference ("symbol", symbuf
);
6733 /* All that remains are operators. */
6735 #define UNARY_OP(op) \
6736 if (strncmp (sym, #op, strlen (#op)) == 0) \
6738 sym += strlen (#op); \
6741 if (eval_symbol (& a, sym, & sym, input_bfd, finfo, addr, \
6742 section_offset, locsymcount, signed_p) \
6746 * result = op ((signed)a); \
6753 #define BINARY_OP(op) \
6754 if (strncmp (sym, #op, strlen (#op)) == 0) \
6756 sym += strlen (#op); \
6759 if (eval_symbol (& a, sym, & sym, input_bfd, finfo, addr, \
6760 section_offset, locsymcount, signed_p) \
6764 if (eval_symbol (& b, sym, & sym, input_bfd, finfo, addr, \
6765 section_offset, locsymcount, signed_p) \
6769 * result = ((signed) a) op ((signed) b); \
6771 * result = a op b; \
6800 _bfd_error_handler (_("unknown operator '%c' in complex symbol"), * sym
);
6801 bfd_set_error (bfd_error_invalid_operation
);
6806 /* Entry point to evaluator, called from elf_link_input_bfd. */
6809 evaluate_complex_relocation_symbols (bfd
* input_bfd
,
6810 struct elf_final_link_info
* finfo
,
6813 const struct elf_backend_data
* bed
;
6814 Elf_Internal_Shdr
* symtab_hdr
;
6815 struct elf_link_hash_entry
** sym_hashes
;
6816 asection
* reloc_sec
;
6817 bfd_boolean result
= TRUE
;
6819 /* For each section, we're going to check and see if it has any
6820 complex relocations, and we're going to evaluate any of them
6823 if (finfo
->info
->relocatable
)
6826 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
6827 sym_hashes
= elf_sym_hashes (input_bfd
);
6828 bed
= get_elf_backend_data (input_bfd
);
6830 for (reloc_sec
= input_bfd
->sections
; reloc_sec
; reloc_sec
= reloc_sec
->next
)
6832 Elf_Internal_Rela
* internal_relocs
;
6835 /* This section was omitted from the link. */
6836 if (! reloc_sec
->linker_mark
)
6839 /* Only process sections containing relocs. */
6840 if ((reloc_sec
->flags
& SEC_RELOC
) == 0)
6843 if (reloc_sec
->reloc_count
== 0)
6846 /* Read in the relocs for this section. */
6848 = _bfd_elf_link_read_relocs (input_bfd
, reloc_sec
, NULL
,
6849 (Elf_Internal_Rela
*) NULL
,
6851 if (internal_relocs
== NULL
)
6854 for (i
= reloc_sec
->reloc_count
; i
--;)
6856 Elf_Internal_Rela
* rel
;
6859 Elf_Internal_Sym
* sym
;
6861 bfd_vma section_offset
;
6865 rel
= internal_relocs
+ i
;
6866 section_offset
= reloc_sec
->output_section
->vma
6867 + reloc_sec
->output_offset
;
6868 addr
= rel
->r_offset
;
6870 index
= ELF32_R_SYM (rel
->r_info
);
6871 if (bed
->s
->arch_size
== 64)
6874 if (index
== STN_UNDEF
)
6877 if (index
< locsymcount
)
6879 /* The symbol is local. */
6880 sym
= finfo
->internal_syms
+ index
;
6882 /* We're only processing STT_RELC or STT_SRELC type symbols. */
6883 if ((ELF_ST_TYPE (sym
->st_info
) != STT_RELC
) &&
6884 (ELF_ST_TYPE (sym
->st_info
) != STT_SRELC
))
6887 sym_name
= bfd_elf_string_from_elf_section
6888 (input_bfd
, symtab_hdr
->sh_link
, sym
->st_name
);
6890 signed_p
= (ELF_ST_TYPE (sym
->st_info
) == STT_SRELC
);
6894 /* The symbol is global. */
6895 struct elf_link_hash_entry
* h
;
6897 if (elf_bad_symtab (input_bfd
))
6900 h
= sym_hashes
[index
- locsymcount
];
6901 while ( h
->root
.type
== bfd_link_hash_indirect
6902 || h
->root
.type
== bfd_link_hash_warning
)
6903 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
6905 if (h
->type
!= STT_RELC
&& h
->type
!= STT_SRELC
)
6908 signed_p
= (h
->type
== STT_SRELC
);
6909 sym_name
= (char *) h
->root
.root
.string
;
6912 printf ("Encountered a complex symbol!");
6913 printf (" (input_bfd %s, section %s, reloc %ld\n",
6914 input_bfd
->filename
, reloc_sec
->name
, i
);
6915 printf (" symbol: idx %8.8lx, name %s\n",
6917 printf (" reloc : info %8.8lx, addr %8.8lx\n",
6919 printf (" Evaluating '%s' ...\n ", sym_name
);
6921 if (eval_symbol (& result
, sym_name
, & sym_name
, input_bfd
,
6922 finfo
, addr
, section_offset
, locsymcount
,
6924 /* Symbol evaluated OK. Update to absolute value. */
6925 set_symbol_value (input_bfd
, finfo
, index
, result
);
6931 if (internal_relocs
!= elf_section_data (reloc_sec
)->relocs
)
6932 free (internal_relocs
);
6935 /* If nothing went wrong, then we adjusted
6936 everything we wanted to adjust. */
6941 put_value (bfd_vma size
,
6942 unsigned long chunksz
,
6945 bfd_byte
* location
)
6947 location
+= (size
- chunksz
);
6949 for (; size
; size
-= chunksz
, location
-= chunksz
, x
>>= (chunksz
* 8))
6957 bfd_put_8 (input_bfd
, x
, location
);
6960 bfd_put_16 (input_bfd
, x
, location
);
6963 bfd_put_32 (input_bfd
, x
, location
);
6967 bfd_put_64 (input_bfd
, x
, location
);
6977 get_value (bfd_vma size
,
6978 unsigned long chunksz
,
6980 bfd_byte
* location
)
6984 for (; size
; size
-= chunksz
, location
+= chunksz
)
6992 x
= (x
<< (8 * chunksz
)) | bfd_get_8 (input_bfd
, location
);
6995 x
= (x
<< (8 * chunksz
)) | bfd_get_16 (input_bfd
, location
);
6998 x
= (x
<< (8 * chunksz
)) | bfd_get_32 (input_bfd
, location
);
7002 x
= (x
<< (8 * chunksz
)) | bfd_get_64 (input_bfd
, location
);
7013 decode_complex_addend
7014 (unsigned long * start
, /* in bits */
7015 unsigned long * oplen
, /* in bits */
7016 unsigned long * len
, /* in bits */
7017 unsigned long * wordsz
, /* in bytes */
7018 unsigned long * chunksz
, /* in bytes */
7019 unsigned long * lsb0_p
,
7020 unsigned long * signed_p
,
7021 unsigned long * trunc_p
,
7022 unsigned long encoded
)
7024 * start
= encoded
& 0x3F;
7025 * len
= (encoded
>> 6) & 0x3F;
7026 * oplen
= (encoded
>> 12) & 0x3F;
7027 * wordsz
= (encoded
>> 18) & 0xF;
7028 * chunksz
= (encoded
>> 22) & 0xF;
7029 * lsb0_p
= (encoded
>> 27) & 1;
7030 * signed_p
= (encoded
>> 28) & 1;
7031 * trunc_p
= (encoded
>> 29) & 1;
7035 bfd_elf_perform_complex_relocation
7036 (bfd
* output_bfd ATTRIBUTE_UNUSED
,
7037 struct bfd_link_info
* info
,
7039 asection
* input_section
,
7040 bfd_byte
* contents
,
7041 Elf_Internal_Rela
* rel
,
7042 Elf_Internal_Sym
* local_syms
,
7043 asection
** local_sections
)
7045 const struct elf_backend_data
* bed
;
7046 Elf_Internal_Shdr
* symtab_hdr
;
7048 bfd_vma relocation
= 0, shift
, x
;
7051 unsigned long start
, oplen
, len
, wordsz
,
7052 chunksz
, lsb0_p
, signed_p
, trunc_p
;
7054 /* Perform this reloc, since it is complex.
7055 (this is not to say that it necessarily refers to a complex
7056 symbol; merely that it is a self-describing CGEN based reloc.
7057 i.e. the addend has the complete reloc information (bit start, end,
7058 word size, etc) encoded within it.). */
7059 r_symndx
= ELF32_R_SYM (rel
->r_info
);
7060 bed
= get_elf_backend_data (input_bfd
);
7061 if (bed
->s
->arch_size
== 64)
7065 printf ("Performing complex relocation %ld...\n", r_symndx
);
7068 symtab_hdr
= & elf_tdata (input_bfd
)->symtab_hdr
;
7069 if (r_symndx
< symtab_hdr
->sh_info
)
7071 /* The symbol is local. */
7072 Elf_Internal_Sym
* sym
;
7074 sym
= local_syms
+ r_symndx
;
7075 sec
= local_sections
[r_symndx
];
7076 relocation
= sym
->st_value
;
7077 if (sym
->st_shndx
> SHN_UNDEF
&&
7078 sym
->st_shndx
< SHN_LORESERVE
)
7079 relocation
+= (sec
->output_offset
+
7080 sec
->output_section
->vma
);
7084 /* The symbol is global. */
7085 struct elf_link_hash_entry
**sym_hashes
;
7086 struct elf_link_hash_entry
* h
;
7088 sym_hashes
= elf_sym_hashes (input_bfd
);
7089 h
= sym_hashes
[r_symndx
];
7091 while (h
->root
.type
== bfd_link_hash_indirect
7092 || h
->root
.type
== bfd_link_hash_warning
)
7093 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7095 if (h
->root
.type
== bfd_link_hash_defined
7096 || h
->root
.type
== bfd_link_hash_defweak
)
7098 sec
= h
->root
.u
.def
.section
;
7099 relocation
= h
->root
.u
.def
.value
;
7101 if (! bfd_is_abs_section (sec
))
7102 relocation
+= (sec
->output_section
->vma
7103 + sec
->output_offset
);
7105 if (h
->root
.type
== bfd_link_hash_undefined
7106 && !((*info
->callbacks
->undefined_symbol
)
7107 (info
, h
->root
.root
.string
, input_bfd
,
7108 input_section
, rel
->r_offset
,
7109 info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
7110 || ELF_ST_VISIBILITY (h
->other
))))
7114 decode_complex_addend (& start
, & oplen
, & len
, & wordsz
,
7115 & chunksz
, & lsb0_p
, & signed_p
,
7116 & trunc_p
, rel
->r_addend
);
7118 mask
= (((1L << (len
- 1)) - 1) << 1) | 1;
7121 shift
= (start
+ 1) - len
;
7123 shift
= (8 * wordsz
) - (start
+ len
);
7125 x
= get_value (wordsz
, chunksz
, input_bfd
, contents
+ rel
->r_offset
);
7128 printf ("Doing complex reloc: "
7129 "lsb0? %ld, signed? %ld, trunc? %ld, wordsz %ld, "
7130 "chunksz %ld, start %ld, len %ld, oplen %ld\n"
7131 " dest: %8.8lx, mask: %8.8lx, reloc: %8.8lx\n",
7132 lsb0_p
, signed_p
, trunc_p
, wordsz
, chunksz
, start
, len
,
7133 oplen
, x
, mask
, relocation
);
7138 /* Now do an overflow check. */
7139 if (bfd_check_overflow ((signed_p
?
7140 complain_overflow_signed
:
7141 complain_overflow_unsigned
),
7142 len
, 0, (8 * wordsz
),
7143 relocation
) == bfd_reloc_overflow
)
7144 (*_bfd_error_handler
)
7145 ("%s (%s + 0x%lx): relocation overflow: 0x%lx %sdoes not fit "
7147 input_bfd
->filename
, input_section
->name
, rel
->r_offset
,
7148 relocation
, (signed_p
? "(signed) " : ""), mask
);
7152 x
= (x
& ~(mask
<< shift
)) | ((relocation
& mask
) << shift
);
7155 printf (" relocation: %8.8lx\n"
7156 " shifted mask: %8.8lx\n"
7157 " shifted/masked reloc: %8.8lx\n"
7158 " result: %8.8lx\n",
7159 relocation
, (mask
<< shift
),
7160 ((relocation
& mask
) << shift
), x
);
7162 put_value (wordsz
, chunksz
, input_bfd
, x
, contents
+ rel
->r_offset
);
7165 /* When performing a relocatable link, the input relocations are
7166 preserved. But, if they reference global symbols, the indices
7167 referenced must be updated. Update all the relocations in
7168 REL_HDR (there are COUNT of them), using the data in REL_HASH. */
7171 elf_link_adjust_relocs (bfd
*abfd
,
7172 Elf_Internal_Shdr
*rel_hdr
,
7174 struct elf_link_hash_entry
**rel_hash
)
7177 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7179 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
7180 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
7181 bfd_vma r_type_mask
;
7184 if (rel_hdr
->sh_entsize
== bed
->s
->sizeof_rel
)
7186 swap_in
= bed
->s
->swap_reloc_in
;
7187 swap_out
= bed
->s
->swap_reloc_out
;
7189 else if (rel_hdr
->sh_entsize
== bed
->s
->sizeof_rela
)
7191 swap_in
= bed
->s
->swap_reloca_in
;
7192 swap_out
= bed
->s
->swap_reloca_out
;
7197 if (bed
->s
->int_rels_per_ext_rel
> MAX_INT_RELS_PER_EXT_REL
)
7200 if (bed
->s
->arch_size
== 32)
7207 r_type_mask
= 0xffffffff;
7211 erela
= rel_hdr
->contents
;
7212 for (i
= 0; i
< count
; i
++, rel_hash
++, erela
+= rel_hdr
->sh_entsize
)
7214 Elf_Internal_Rela irela
[MAX_INT_RELS_PER_EXT_REL
];
7217 if (*rel_hash
== NULL
)
7220 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
7222 (*swap_in
) (abfd
, erela
, irela
);
7223 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
7224 irela
[j
].r_info
= ((bfd_vma
) (*rel_hash
)->indx
<< r_sym_shift
7225 | (irela
[j
].r_info
& r_type_mask
));
7226 (*swap_out
) (abfd
, irela
, erela
);
7230 struct elf_link_sort_rela
7236 enum elf_reloc_type_class type
;
7237 /* We use this as an array of size int_rels_per_ext_rel. */
7238 Elf_Internal_Rela rela
[1];
7242 elf_link_sort_cmp1 (const void *A
, const void *B
)
7244 const struct elf_link_sort_rela
*a
= A
;
7245 const struct elf_link_sort_rela
*b
= B
;
7246 int relativea
, relativeb
;
7248 relativea
= a
->type
== reloc_class_relative
;
7249 relativeb
= b
->type
== reloc_class_relative
;
7251 if (relativea
< relativeb
)
7253 if (relativea
> relativeb
)
7255 if ((a
->rela
->r_info
& a
->u
.sym_mask
) < (b
->rela
->r_info
& b
->u
.sym_mask
))
7257 if ((a
->rela
->r_info
& a
->u
.sym_mask
) > (b
->rela
->r_info
& b
->u
.sym_mask
))
7259 if (a
->rela
->r_offset
< b
->rela
->r_offset
)
7261 if (a
->rela
->r_offset
> b
->rela
->r_offset
)
7267 elf_link_sort_cmp2 (const void *A
, const void *B
)
7269 const struct elf_link_sort_rela
*a
= A
;
7270 const struct elf_link_sort_rela
*b
= B
;
7273 if (a
->u
.offset
< b
->u
.offset
)
7275 if (a
->u
.offset
> b
->u
.offset
)
7277 copya
= (a
->type
== reloc_class_copy
) * 2 + (a
->type
== reloc_class_plt
);
7278 copyb
= (b
->type
== reloc_class_copy
) * 2 + (b
->type
== reloc_class_plt
);
7283 if (a
->rela
->r_offset
< b
->rela
->r_offset
)
7285 if (a
->rela
->r_offset
> b
->rela
->r_offset
)
7291 elf_link_sort_relocs (bfd
*abfd
, struct bfd_link_info
*info
, asection
**psec
)
7293 asection
*dynamic_relocs
;
7296 bfd_size_type count
, size
;
7297 size_t i
, ret
, sort_elt
, ext_size
;
7298 bfd_byte
*sort
, *s_non_relative
, *p
;
7299 struct elf_link_sort_rela
*sq
;
7300 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7301 int i2e
= bed
->s
->int_rels_per_ext_rel
;
7302 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
7303 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
7304 struct bfd_link_order
*lo
;
7306 bfd_boolean use_rela
;
7308 /* Find a dynamic reloc section. */
7309 rela_dyn
= bfd_get_section_by_name (abfd
, ".rela.dyn");
7310 rel_dyn
= bfd_get_section_by_name (abfd
, ".rel.dyn");
7311 if (rela_dyn
!= NULL
&& rela_dyn
->size
> 0
7312 && rel_dyn
!= NULL
&& rel_dyn
->size
> 0)
7314 bfd_boolean use_rela_initialised
= FALSE
;
7316 /* This is just here to stop gcc from complaining.
7317 It's initialization checking code is not perfect. */
7320 /* Both sections are present. Examine the sizes
7321 of the indirect sections to help us choose. */
7322 for (lo
= rela_dyn
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
7323 if (lo
->type
== bfd_indirect_link_order
)
7325 asection
*o
= lo
->u
.indirect
.section
;
7327 if ((o
->size
% bed
->s
->sizeof_rela
) == 0)
7329 if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
7330 /* Section size is divisible by both rel and rela sizes.
7331 It is of no help to us. */
7335 /* Section size is only divisible by rela. */
7336 if (use_rela_initialised
&& (use_rela
== FALSE
))
7339 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
7340 bfd_set_error (bfd_error_invalid_operation
);
7346 use_rela_initialised
= TRUE
;
7350 else if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
7352 /* Section size is only divisible by rel. */
7353 if (use_rela_initialised
&& (use_rela
== TRUE
))
7356 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
7357 bfd_set_error (bfd_error_invalid_operation
);
7363 use_rela_initialised
= TRUE
;
7368 /* The section size is not divisible by either - something is wrong. */
7370 (_("%B: Unable to sort relocs - they are of an unknown size"), abfd
);
7371 bfd_set_error (bfd_error_invalid_operation
);
7376 for (lo
= rel_dyn
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
7377 if (lo
->type
== bfd_indirect_link_order
)
7379 asection
*o
= lo
->u
.indirect
.section
;
7381 if ((o
->size
% bed
->s
->sizeof_rela
) == 0)
7383 if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
7384 /* Section size is divisible by both rel and rela sizes.
7385 It is of no help to us. */
7389 /* Section size is only divisible by rela. */
7390 if (use_rela_initialised
&& (use_rela
== FALSE
))
7393 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
7394 bfd_set_error (bfd_error_invalid_operation
);
7400 use_rela_initialised
= TRUE
;
7404 else if ((o
->size
% bed
->s
->sizeof_rel
) == 0)
7406 /* Section size is only divisible by rel. */
7407 if (use_rela_initialised
&& (use_rela
== TRUE
))
7410 (_("%B: Unable to sort relocs - they are in more than one size"), abfd
);
7411 bfd_set_error (bfd_error_invalid_operation
);
7417 use_rela_initialised
= TRUE
;
7422 /* The section size is not divisible by either - something is wrong. */
7424 (_("%B: Unable to sort relocs - they are of an unknown size"), abfd
);
7425 bfd_set_error (bfd_error_invalid_operation
);
7430 if (! use_rela_initialised
)
7434 else if (rela_dyn
!= NULL
&& rela_dyn
->size
> 0)
7436 else if (rel_dyn
!= NULL
&& rel_dyn
->size
> 0)
7443 dynamic_relocs
= rela_dyn
;
7444 ext_size
= bed
->s
->sizeof_rela
;
7445 swap_in
= bed
->s
->swap_reloca_in
;
7446 swap_out
= bed
->s
->swap_reloca_out
;
7450 dynamic_relocs
= rel_dyn
;
7451 ext_size
= bed
->s
->sizeof_rel
;
7452 swap_in
= bed
->s
->swap_reloc_in
;
7453 swap_out
= bed
->s
->swap_reloc_out
;
7457 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
7458 if (lo
->type
== bfd_indirect_link_order
)
7459 size
+= lo
->u
.indirect
.section
->size
;
7461 if (size
!= dynamic_relocs
->size
)
7464 sort_elt
= (sizeof (struct elf_link_sort_rela
)
7465 + (i2e
- 1) * sizeof (Elf_Internal_Rela
));
7467 count
= dynamic_relocs
->size
/ ext_size
;
7468 sort
= bfd_zmalloc (sort_elt
* count
);
7472 (*info
->callbacks
->warning
)
7473 (info
, _("Not enough memory to sort relocations"), 0, abfd
, 0, 0);
7477 if (bed
->s
->arch_size
== 32)
7478 r_sym_mask
= ~(bfd_vma
) 0xff;
7480 r_sym_mask
= ~(bfd_vma
) 0xffffffff;
7482 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
7483 if (lo
->type
== bfd_indirect_link_order
)
7485 bfd_byte
*erel
, *erelend
;
7486 asection
*o
= lo
->u
.indirect
.section
;
7488 if (o
->contents
== NULL
&& o
->size
!= 0)
7490 /* This is a reloc section that is being handled as a normal
7491 section. See bfd_section_from_shdr. We can't combine
7492 relocs in this case. */
7497 erelend
= o
->contents
+ o
->size
;
7498 p
= sort
+ o
->output_offset
/ ext_size
* sort_elt
;
7500 while (erel
< erelend
)
7502 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
7504 (*swap_in
) (abfd
, erel
, s
->rela
);
7505 s
->type
= (*bed
->elf_backend_reloc_type_class
) (s
->rela
);
7506 s
->u
.sym_mask
= r_sym_mask
;
7512 qsort (sort
, count
, sort_elt
, elf_link_sort_cmp1
);
7514 for (i
= 0, p
= sort
; i
< count
; i
++, p
+= sort_elt
)
7516 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
7517 if (s
->type
!= reloc_class_relative
)
7523 sq
= (struct elf_link_sort_rela
*) s_non_relative
;
7524 for (; i
< count
; i
++, p
+= sort_elt
)
7526 struct elf_link_sort_rela
*sp
= (struct elf_link_sort_rela
*) p
;
7527 if (((sp
->rela
->r_info
^ sq
->rela
->r_info
) & r_sym_mask
) != 0)
7529 sp
->u
.offset
= sq
->rela
->r_offset
;
7532 qsort (s_non_relative
, count
- ret
, sort_elt
, elf_link_sort_cmp2
);
7534 for (lo
= dynamic_relocs
->map_head
.link_order
; lo
!= NULL
; lo
= lo
->next
)
7535 if (lo
->type
== bfd_indirect_link_order
)
7537 bfd_byte
*erel
, *erelend
;
7538 asection
*o
= lo
->u
.indirect
.section
;
7541 erelend
= o
->contents
+ o
->size
;
7542 p
= sort
+ o
->output_offset
/ ext_size
* sort_elt
;
7543 while (erel
< erelend
)
7545 struct elf_link_sort_rela
*s
= (struct elf_link_sort_rela
*) p
;
7546 (*swap_out
) (abfd
, s
->rela
, erel
);
7553 *psec
= dynamic_relocs
;
7557 /* Flush the output symbols to the file. */
7560 elf_link_flush_output_syms (struct elf_final_link_info
*finfo
,
7561 const struct elf_backend_data
*bed
)
7563 if (finfo
->symbuf_count
> 0)
7565 Elf_Internal_Shdr
*hdr
;
7569 hdr
= &elf_tdata (finfo
->output_bfd
)->symtab_hdr
;
7570 pos
= hdr
->sh_offset
+ hdr
->sh_size
;
7571 amt
= finfo
->symbuf_count
* bed
->s
->sizeof_sym
;
7572 if (bfd_seek (finfo
->output_bfd
, pos
, SEEK_SET
) != 0
7573 || bfd_bwrite (finfo
->symbuf
, amt
, finfo
->output_bfd
) != amt
)
7576 hdr
->sh_size
+= amt
;
7577 finfo
->symbuf_count
= 0;
7583 /* Add a symbol to the output symbol table. */
7586 elf_link_output_sym (struct elf_final_link_info
*finfo
,
7588 Elf_Internal_Sym
*elfsym
,
7589 asection
*input_sec
,
7590 struct elf_link_hash_entry
*h
)
7593 Elf_External_Sym_Shndx
*destshndx
;
7594 bfd_boolean (*output_symbol_hook
)
7595 (struct bfd_link_info
*, const char *, Elf_Internal_Sym
*, asection
*,
7596 struct elf_link_hash_entry
*);
7597 const struct elf_backend_data
*bed
;
7599 bed
= get_elf_backend_data (finfo
->output_bfd
);
7600 output_symbol_hook
= bed
->elf_backend_link_output_symbol_hook
;
7601 if (output_symbol_hook
!= NULL
)
7603 if (! (*output_symbol_hook
) (finfo
->info
, name
, elfsym
, input_sec
, h
))
7607 if (name
== NULL
|| *name
== '\0')
7608 elfsym
->st_name
= 0;
7609 else if (input_sec
->flags
& SEC_EXCLUDE
)
7610 elfsym
->st_name
= 0;
7613 elfsym
->st_name
= (unsigned long) _bfd_stringtab_add (finfo
->symstrtab
,
7615 if (elfsym
->st_name
== (unsigned long) -1)
7619 if (finfo
->symbuf_count
>= finfo
->symbuf_size
)
7621 if (! elf_link_flush_output_syms (finfo
, bed
))
7625 dest
= finfo
->symbuf
+ finfo
->symbuf_count
* bed
->s
->sizeof_sym
;
7626 destshndx
= finfo
->symshndxbuf
;
7627 if (destshndx
!= NULL
)
7629 if (bfd_get_symcount (finfo
->output_bfd
) >= finfo
->shndxbuf_size
)
7633 amt
= finfo
->shndxbuf_size
* sizeof (Elf_External_Sym_Shndx
);
7634 finfo
->symshndxbuf
= destshndx
= bfd_realloc (destshndx
, amt
* 2);
7635 if (destshndx
== NULL
)
7637 memset ((char *) destshndx
+ amt
, 0, amt
);
7638 finfo
->shndxbuf_size
*= 2;
7640 destshndx
+= bfd_get_symcount (finfo
->output_bfd
);
7643 bed
->s
->swap_symbol_out (finfo
->output_bfd
, elfsym
, dest
, destshndx
);
7644 finfo
->symbuf_count
+= 1;
7645 bfd_get_symcount (finfo
->output_bfd
) += 1;
7650 /* Return TRUE if the dynamic symbol SYM in ABFD is supported. */
7653 check_dynsym (bfd
*abfd
, Elf_Internal_Sym
*sym
)
7655 if (sym
->st_shndx
> SHN_HIRESERVE
)
7657 /* The gABI doesn't support dynamic symbols in output sections
7659 (*_bfd_error_handler
)
7660 (_("%B: Too many sections: %d (>= %d)"),
7661 abfd
, bfd_count_sections (abfd
), SHN_LORESERVE
);
7662 bfd_set_error (bfd_error_nonrepresentable_section
);
7668 /* For DSOs loaded in via a DT_NEEDED entry, emulate ld.so in
7669 allowing an unsatisfied unversioned symbol in the DSO to match a
7670 versioned symbol that would normally require an explicit version.
7671 We also handle the case that a DSO references a hidden symbol
7672 which may be satisfied by a versioned symbol in another DSO. */
7675 elf_link_check_versioned_symbol (struct bfd_link_info
*info
,
7676 const struct elf_backend_data
*bed
,
7677 struct elf_link_hash_entry
*h
)
7680 struct elf_link_loaded_list
*loaded
;
7682 if (!is_elf_hash_table (info
->hash
))
7685 switch (h
->root
.type
)
7691 case bfd_link_hash_undefined
:
7692 case bfd_link_hash_undefweak
:
7693 abfd
= h
->root
.u
.undef
.abfd
;
7694 if ((abfd
->flags
& DYNAMIC
) == 0
7695 || (elf_dyn_lib_class (abfd
) & DYN_DT_NEEDED
) == 0)
7699 case bfd_link_hash_defined
:
7700 case bfd_link_hash_defweak
:
7701 abfd
= h
->root
.u
.def
.section
->owner
;
7704 case bfd_link_hash_common
:
7705 abfd
= h
->root
.u
.c
.p
->section
->owner
;
7708 BFD_ASSERT (abfd
!= NULL
);
7710 for (loaded
= elf_hash_table (info
)->loaded
;
7712 loaded
= loaded
->next
)
7715 Elf_Internal_Shdr
*hdr
;
7716 bfd_size_type symcount
;
7717 bfd_size_type extsymcount
;
7718 bfd_size_type extsymoff
;
7719 Elf_Internal_Shdr
*versymhdr
;
7720 Elf_Internal_Sym
*isym
;
7721 Elf_Internal_Sym
*isymend
;
7722 Elf_Internal_Sym
*isymbuf
;
7723 Elf_External_Versym
*ever
;
7724 Elf_External_Versym
*extversym
;
7726 input
= loaded
->abfd
;
7728 /* We check each DSO for a possible hidden versioned definition. */
7730 || (input
->flags
& DYNAMIC
) == 0
7731 || elf_dynversym (input
) == 0)
7734 hdr
= &elf_tdata (input
)->dynsymtab_hdr
;
7736 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
7737 if (elf_bad_symtab (input
))
7739 extsymcount
= symcount
;
7744 extsymcount
= symcount
- hdr
->sh_info
;
7745 extsymoff
= hdr
->sh_info
;
7748 if (extsymcount
== 0)
7751 isymbuf
= bfd_elf_get_elf_syms (input
, hdr
, extsymcount
, extsymoff
,
7753 if (isymbuf
== NULL
)
7756 /* Read in any version definitions. */
7757 versymhdr
= &elf_tdata (input
)->dynversym_hdr
;
7758 extversym
= bfd_malloc (versymhdr
->sh_size
);
7759 if (extversym
== NULL
)
7762 if (bfd_seek (input
, versymhdr
->sh_offset
, SEEK_SET
) != 0
7763 || (bfd_bread (extversym
, versymhdr
->sh_size
, input
)
7764 != versymhdr
->sh_size
))
7772 ever
= extversym
+ extsymoff
;
7773 isymend
= isymbuf
+ extsymcount
;
7774 for (isym
= isymbuf
; isym
< isymend
; isym
++, ever
++)
7777 Elf_Internal_Versym iver
;
7778 unsigned short version_index
;
7780 if (ELF_ST_BIND (isym
->st_info
) == STB_LOCAL
7781 || isym
->st_shndx
== SHN_UNDEF
)
7784 name
= bfd_elf_string_from_elf_section (input
,
7787 if (strcmp (name
, h
->root
.root
.string
) != 0)
7790 _bfd_elf_swap_versym_in (input
, ever
, &iver
);
7792 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0)
7794 /* If we have a non-hidden versioned sym, then it should
7795 have provided a definition for the undefined sym. */
7799 version_index
= iver
.vs_vers
& VERSYM_VERSION
;
7800 if (version_index
== 1 || version_index
== 2)
7802 /* This is the base or first version. We can use it. */
7816 /* Add an external symbol to the symbol table. This is called from
7817 the hash table traversal routine. When generating a shared object,
7818 we go through the symbol table twice. The first time we output
7819 anything that might have been forced to local scope in a version
7820 script. The second time we output the symbols that are still
7824 elf_link_output_extsym (struct elf_link_hash_entry
*h
, void *data
)
7826 struct elf_outext_info
*eoinfo
= data
;
7827 struct elf_final_link_info
*finfo
= eoinfo
->finfo
;
7829 Elf_Internal_Sym sym
;
7830 asection
*input_sec
;
7831 const struct elf_backend_data
*bed
;
7833 if (h
->root
.type
== bfd_link_hash_warning
)
7835 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7836 if (h
->root
.type
== bfd_link_hash_new
)
7840 /* Decide whether to output this symbol in this pass. */
7841 if (eoinfo
->localsyms
)
7843 if (!h
->forced_local
)
7848 if (h
->forced_local
)
7852 bed
= get_elf_backend_data (finfo
->output_bfd
);
7854 if (h
->root
.type
== bfd_link_hash_undefined
)
7856 /* If we have an undefined symbol reference here then it must have
7857 come from a shared library that is being linked in. (Undefined
7858 references in regular files have already been handled). */
7859 bfd_boolean ignore_undef
= FALSE
;
7861 /* Some symbols may be special in that the fact that they're
7862 undefined can be safely ignored - let backend determine that. */
7863 if (bed
->elf_backend_ignore_undef_symbol
)
7864 ignore_undef
= bed
->elf_backend_ignore_undef_symbol (h
);
7866 /* If we are reporting errors for this situation then do so now. */
7867 if (ignore_undef
== FALSE
7870 && ! elf_link_check_versioned_symbol (finfo
->info
, bed
, h
)
7871 && finfo
->info
->unresolved_syms_in_shared_libs
!= RM_IGNORE
)
7873 if (! (finfo
->info
->callbacks
->undefined_symbol
7874 (finfo
->info
, h
->root
.root
.string
, h
->root
.u
.undef
.abfd
,
7875 NULL
, 0, finfo
->info
->unresolved_syms_in_shared_libs
== RM_GENERATE_ERROR
)))
7877 eoinfo
->failed
= TRUE
;
7883 /* We should also warn if a forced local symbol is referenced from
7884 shared libraries. */
7885 if (! finfo
->info
->relocatable
7886 && (! finfo
->info
->shared
)
7891 && ! elf_link_check_versioned_symbol (finfo
->info
, bed
, h
))
7893 (*_bfd_error_handler
)
7894 (_("%B: %s symbol `%s' in %B is referenced by DSO"),
7896 h
->root
.u
.def
.section
== bfd_abs_section_ptr
7897 ? finfo
->output_bfd
: h
->root
.u
.def
.section
->owner
,
7898 ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
7900 : ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
7901 ? "hidden" : "local",
7902 h
->root
.root
.string
);
7903 eoinfo
->failed
= TRUE
;
7907 /* We don't want to output symbols that have never been mentioned by
7908 a regular file, or that we have been told to strip. However, if
7909 h->indx is set to -2, the symbol is used by a reloc and we must
7913 else if ((h
->def_dynamic
7915 || h
->root
.type
== bfd_link_hash_new
)
7919 else if (finfo
->info
->strip
== strip_all
)
7921 else if (finfo
->info
->strip
== strip_some
7922 && bfd_hash_lookup (finfo
->info
->keep_hash
,
7923 h
->root
.root
.string
, FALSE
, FALSE
) == NULL
)
7925 else if (finfo
->info
->strip_discarded
7926 && (h
->root
.type
== bfd_link_hash_defined
7927 || h
->root
.type
== bfd_link_hash_defweak
)
7928 && elf_discarded_section (h
->root
.u
.def
.section
))
7933 /* If we're stripping it, and it's not a dynamic symbol, there's
7934 nothing else to do unless it is a forced local symbol. */
7937 && !h
->forced_local
)
7941 sym
.st_size
= h
->size
;
7942 sym
.st_other
= h
->other
;
7943 if (h
->forced_local
)
7944 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, h
->type
);
7945 else if (h
->root
.type
== bfd_link_hash_undefweak
7946 || h
->root
.type
== bfd_link_hash_defweak
)
7947 sym
.st_info
= ELF_ST_INFO (STB_WEAK
, h
->type
);
7949 sym
.st_info
= ELF_ST_INFO (STB_GLOBAL
, h
->type
);
7951 switch (h
->root
.type
)
7954 case bfd_link_hash_new
:
7955 case bfd_link_hash_warning
:
7959 case bfd_link_hash_undefined
:
7960 case bfd_link_hash_undefweak
:
7961 input_sec
= bfd_und_section_ptr
;
7962 sym
.st_shndx
= SHN_UNDEF
;
7965 case bfd_link_hash_defined
:
7966 case bfd_link_hash_defweak
:
7968 input_sec
= h
->root
.u
.def
.section
;
7969 if (input_sec
->output_section
!= NULL
)
7972 _bfd_elf_section_from_bfd_section (finfo
->output_bfd
,
7973 input_sec
->output_section
);
7974 if (sym
.st_shndx
== SHN_BAD
)
7976 (*_bfd_error_handler
)
7977 (_("%B: could not find output section %A for input section %A"),
7978 finfo
->output_bfd
, input_sec
->output_section
, input_sec
);
7979 eoinfo
->failed
= TRUE
;
7983 /* ELF symbols in relocatable files are section relative,
7984 but in nonrelocatable files they are virtual
7986 sym
.st_value
= h
->root
.u
.def
.value
+ input_sec
->output_offset
;
7987 if (! finfo
->info
->relocatable
)
7989 sym
.st_value
+= input_sec
->output_section
->vma
;
7990 if (h
->type
== STT_TLS
)
7992 /* STT_TLS symbols are relative to PT_TLS segment
7994 BFD_ASSERT (elf_hash_table (finfo
->info
)->tls_sec
!= NULL
);
7995 sym
.st_value
-= elf_hash_table (finfo
->info
)->tls_sec
->vma
;
8001 BFD_ASSERT (input_sec
->owner
== NULL
8002 || (input_sec
->owner
->flags
& DYNAMIC
) != 0);
8003 sym
.st_shndx
= SHN_UNDEF
;
8004 input_sec
= bfd_und_section_ptr
;
8009 case bfd_link_hash_common
:
8010 input_sec
= h
->root
.u
.c
.p
->section
;
8011 sym
.st_shndx
= bed
->common_section_index (input_sec
);
8012 sym
.st_value
= 1 << h
->root
.u
.c
.p
->alignment_power
;
8015 case bfd_link_hash_indirect
:
8016 /* These symbols are created by symbol versioning. They point
8017 to the decorated version of the name. For example, if the
8018 symbol foo@@GNU_1.2 is the default, which should be used when
8019 foo is used with no version, then we add an indirect symbol
8020 foo which points to foo@@GNU_1.2. We ignore these symbols,
8021 since the indirected symbol is already in the hash table. */
8025 /* Give the processor backend a chance to tweak the symbol value,
8026 and also to finish up anything that needs to be done for this
8027 symbol. FIXME: Not calling elf_backend_finish_dynamic_symbol for
8028 forced local syms when non-shared is due to a historical quirk. */
8029 if ((h
->dynindx
!= -1
8031 && ((finfo
->info
->shared
8032 && (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
8033 || h
->root
.type
!= bfd_link_hash_undefweak
))
8034 || !h
->forced_local
)
8035 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
8037 if (! ((*bed
->elf_backend_finish_dynamic_symbol
)
8038 (finfo
->output_bfd
, finfo
->info
, h
, &sym
)))
8040 eoinfo
->failed
= TRUE
;
8045 /* If we are marking the symbol as undefined, and there are no
8046 non-weak references to this symbol from a regular object, then
8047 mark the symbol as weak undefined; if there are non-weak
8048 references, mark the symbol as strong. We can't do this earlier,
8049 because it might not be marked as undefined until the
8050 finish_dynamic_symbol routine gets through with it. */
8051 if (sym
.st_shndx
== SHN_UNDEF
8053 && (ELF_ST_BIND (sym
.st_info
) == STB_GLOBAL
8054 || ELF_ST_BIND (sym
.st_info
) == STB_WEAK
))
8058 if (h
->ref_regular_nonweak
)
8059 bindtype
= STB_GLOBAL
;
8061 bindtype
= STB_WEAK
;
8062 sym
.st_info
= ELF_ST_INFO (bindtype
, ELF_ST_TYPE (sym
.st_info
));
8065 /* If a non-weak symbol with non-default visibility is not defined
8066 locally, it is a fatal error. */
8067 if (! finfo
->info
->relocatable
8068 && ELF_ST_VISIBILITY (sym
.st_other
) != STV_DEFAULT
8069 && ELF_ST_BIND (sym
.st_info
) != STB_WEAK
8070 && h
->root
.type
== bfd_link_hash_undefined
8073 (*_bfd_error_handler
)
8074 (_("%B: %s symbol `%s' isn't defined"),
8076 ELF_ST_VISIBILITY (sym
.st_other
) == STV_PROTECTED
8078 : ELF_ST_VISIBILITY (sym
.st_other
) == STV_INTERNAL
8079 ? "internal" : "hidden",
8080 h
->root
.root
.string
);
8081 eoinfo
->failed
= TRUE
;
8085 /* If this symbol should be put in the .dynsym section, then put it
8086 there now. We already know the symbol index. We also fill in
8087 the entry in the .hash section. */
8088 if (h
->dynindx
!= -1
8089 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
8093 sym
.st_name
= h
->dynstr_index
;
8094 esym
= finfo
->dynsym_sec
->contents
+ h
->dynindx
* bed
->s
->sizeof_sym
;
8095 if (! check_dynsym (finfo
->output_bfd
, &sym
))
8097 eoinfo
->failed
= TRUE
;
8100 bed
->s
->swap_symbol_out (finfo
->output_bfd
, &sym
, esym
, 0);
8102 if (finfo
->hash_sec
!= NULL
)
8104 size_t hash_entry_size
;
8105 bfd_byte
*bucketpos
;
8110 bucketcount
= elf_hash_table (finfo
->info
)->bucketcount
;
8111 bucket
= h
->u
.elf_hash_value
% bucketcount
;
8114 = elf_section_data (finfo
->hash_sec
)->this_hdr
.sh_entsize
;
8115 bucketpos
= ((bfd_byte
*) finfo
->hash_sec
->contents
8116 + (bucket
+ 2) * hash_entry_size
);
8117 chain
= bfd_get (8 * hash_entry_size
, finfo
->output_bfd
, bucketpos
);
8118 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, h
->dynindx
, bucketpos
);
8119 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, chain
,
8120 ((bfd_byte
*) finfo
->hash_sec
->contents
8121 + (bucketcount
+ 2 + h
->dynindx
) * hash_entry_size
));
8124 if (finfo
->symver_sec
!= NULL
&& finfo
->symver_sec
->contents
!= NULL
)
8126 Elf_Internal_Versym iversym
;
8127 Elf_External_Versym
*eversym
;
8129 if (!h
->def_regular
)
8131 if (h
->verinfo
.verdef
== NULL
)
8132 iversym
.vs_vers
= 0;
8134 iversym
.vs_vers
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
8138 if (h
->verinfo
.vertree
== NULL
)
8139 iversym
.vs_vers
= 1;
8141 iversym
.vs_vers
= h
->verinfo
.vertree
->vernum
+ 1;
8142 if (finfo
->info
->create_default_symver
)
8147 iversym
.vs_vers
|= VERSYM_HIDDEN
;
8149 eversym
= (Elf_External_Versym
*) finfo
->symver_sec
->contents
;
8150 eversym
+= h
->dynindx
;
8151 _bfd_elf_swap_versym_out (finfo
->output_bfd
, &iversym
, eversym
);
8155 /* If we're stripping it, then it was just a dynamic symbol, and
8156 there's nothing else to do. */
8157 if (strip
|| (input_sec
->flags
& SEC_EXCLUDE
) != 0)
8160 h
->indx
= bfd_get_symcount (finfo
->output_bfd
);
8162 if (! elf_link_output_sym (finfo
, h
->root
.root
.string
, &sym
, input_sec
, h
))
8164 eoinfo
->failed
= TRUE
;
8171 /* Return TRUE if special handling is done for relocs in SEC against
8172 symbols defined in discarded sections. */
8175 elf_section_ignore_discarded_relocs (asection
*sec
)
8177 const struct elf_backend_data
*bed
;
8179 switch (sec
->sec_info_type
)
8181 case ELF_INFO_TYPE_STABS
:
8182 case ELF_INFO_TYPE_EH_FRAME
:
8188 bed
= get_elf_backend_data (sec
->owner
);
8189 if (bed
->elf_backend_ignore_discarded_relocs
!= NULL
8190 && (*bed
->elf_backend_ignore_discarded_relocs
) (sec
))
8196 /* Return a mask saying how ld should treat relocations in SEC against
8197 symbols defined in discarded sections. If this function returns
8198 COMPLAIN set, ld will issue a warning message. If this function
8199 returns PRETEND set, and the discarded section was link-once and the
8200 same size as the kept link-once section, ld will pretend that the
8201 symbol was actually defined in the kept section. Otherwise ld will
8202 zero the reloc (at least that is the intent, but some cooperation by
8203 the target dependent code is needed, particularly for REL targets). */
8206 _bfd_elf_default_action_discarded (asection
*sec
)
8208 if (sec
->flags
& SEC_DEBUGGING
)
8211 if (strcmp (".eh_frame", sec
->name
) == 0)
8214 if (strcmp (".gcc_except_table", sec
->name
) == 0)
8217 return COMPLAIN
| PRETEND
;
8220 /* Find a match between a section and a member of a section group. */
8223 match_group_member (asection
*sec
, asection
*group
,
8224 struct bfd_link_info
*info
)
8226 asection
*first
= elf_next_in_group (group
);
8227 asection
*s
= first
;
8231 if (bfd_elf_match_symbols_in_sections (s
, sec
, info
))
8234 s
= elf_next_in_group (s
);
8242 /* Check if the kept section of a discarded section SEC can be used
8243 to replace it. Return the replacement if it is OK. Otherwise return
8247 _bfd_elf_check_kept_section (asection
*sec
, struct bfd_link_info
*info
)
8251 kept
= sec
->kept_section
;
8254 if ((kept
->flags
& SEC_GROUP
) != 0)
8255 kept
= match_group_member (sec
, kept
, info
);
8256 if (kept
!= NULL
&& sec
->size
!= kept
->size
)
8258 sec
->kept_section
= kept
;
8263 /* Link an input file into the linker output file. This function
8264 handles all the sections and relocations of the input file at once.
8265 This is so that we only have to read the local symbols once, and
8266 don't have to keep them in memory. */
8269 elf_link_input_bfd (struct elf_final_link_info
*finfo
, bfd
*input_bfd
)
8271 int (*relocate_section
)
8272 (bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
8273 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**);
8275 Elf_Internal_Shdr
*symtab_hdr
;
8278 Elf_Internal_Sym
*isymbuf
;
8279 Elf_Internal_Sym
*isym
;
8280 Elf_Internal_Sym
*isymend
;
8282 asection
**ppsection
;
8284 const struct elf_backend_data
*bed
;
8285 struct elf_link_hash_entry
**sym_hashes
;
8287 output_bfd
= finfo
->output_bfd
;
8288 bed
= get_elf_backend_data (output_bfd
);
8289 relocate_section
= bed
->elf_backend_relocate_section
;
8291 /* If this is a dynamic object, we don't want to do anything here:
8292 we don't want the local symbols, and we don't want the section
8294 if ((input_bfd
->flags
& DYNAMIC
) != 0)
8297 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8298 if (elf_bad_symtab (input_bfd
))
8300 locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
8305 locsymcount
= symtab_hdr
->sh_info
;
8306 extsymoff
= symtab_hdr
->sh_info
;
8309 /* Read the local symbols. */
8310 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8311 if (isymbuf
== NULL
&& locsymcount
!= 0)
8313 isymbuf
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
, locsymcount
, 0,
8314 finfo
->internal_syms
,
8315 finfo
->external_syms
,
8316 finfo
->locsym_shndx
);
8317 if (isymbuf
== NULL
)
8320 /* evaluate_complex_relocation_symbols looks for symbols in
8321 finfo->internal_syms. */
8322 else if (isymbuf
!= NULL
&& locsymcount
!= 0)
8324 bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
, locsymcount
, 0,
8325 finfo
->internal_syms
,
8326 finfo
->external_syms
,
8327 finfo
->locsym_shndx
);
8330 /* Find local symbol sections and adjust values of symbols in
8331 SEC_MERGE sections. Write out those local symbols we know are
8332 going into the output file. */
8333 isymend
= isymbuf
+ locsymcount
;
8334 for (isym
= isymbuf
, pindex
= finfo
->indices
, ppsection
= finfo
->sections
;
8336 isym
++, pindex
++, ppsection
++)
8340 Elf_Internal_Sym osym
;
8344 if (elf_bad_symtab (input_bfd
))
8346 if (ELF_ST_BIND (isym
->st_info
) != STB_LOCAL
)
8353 if (isym
->st_shndx
== SHN_UNDEF
)
8354 isec
= bfd_und_section_ptr
;
8355 else if (isym
->st_shndx
< SHN_LORESERVE
8356 || isym
->st_shndx
> SHN_HIRESERVE
)
8358 isec
= bfd_section_from_elf_index (input_bfd
, isym
->st_shndx
);
8360 && isec
->sec_info_type
== ELF_INFO_TYPE_MERGE
8361 && ELF_ST_TYPE (isym
->st_info
) != STT_SECTION
)
8363 _bfd_merged_section_offset (output_bfd
, &isec
,
8364 elf_section_data (isec
)->sec_info
,
8367 else if (isym
->st_shndx
== SHN_ABS
)
8368 isec
= bfd_abs_section_ptr
;
8369 else if (isym
->st_shndx
== SHN_COMMON
)
8370 isec
= bfd_com_section_ptr
;
8373 /* Don't attempt to output symbols with st_shnx in the
8374 reserved range other than SHN_ABS and SHN_COMMON. */
8381 /* Don't output the first, undefined, symbol. */
8382 if (ppsection
== finfo
->sections
)
8385 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
8387 /* We never output section symbols. Instead, we use the
8388 section symbol of the corresponding section in the output
8393 /* If we are stripping all symbols, we don't want to output this
8395 if (finfo
->info
->strip
== strip_all
)
8398 /* If we are discarding all local symbols, we don't want to
8399 output this one. If we are generating a relocatable output
8400 file, then some of the local symbols may be required by
8401 relocs; we output them below as we discover that they are
8403 if (finfo
->info
->discard
== discard_all
)
8406 /* If this symbol is defined in a section which we are
8407 discarding, we don't need to keep it. */
8408 if (isym
->st_shndx
!= SHN_UNDEF
8409 && (isym
->st_shndx
< SHN_LORESERVE
|| isym
->st_shndx
> SHN_HIRESERVE
)
8411 || bfd_section_removed_from_list (output_bfd
,
8412 isec
->output_section
)))
8415 /* Get the name of the symbol. */
8416 name
= bfd_elf_string_from_elf_section (input_bfd
, symtab_hdr
->sh_link
,
8421 /* See if we are discarding symbols with this name. */
8422 if ((finfo
->info
->strip
== strip_some
8423 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, FALSE
, FALSE
)
8425 || (((finfo
->info
->discard
== discard_sec_merge
8426 && (isec
->flags
& SEC_MERGE
) && ! finfo
->info
->relocatable
)
8427 || finfo
->info
->discard
== discard_l
)
8428 && bfd_is_local_label_name (input_bfd
, name
)))
8431 /* If we get here, we are going to output this symbol. */
8435 /* Adjust the section index for the output file. */
8436 osym
.st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
8437 isec
->output_section
);
8438 if (osym
.st_shndx
== SHN_BAD
)
8441 *pindex
= bfd_get_symcount (output_bfd
);
8443 /* ELF symbols in relocatable files are section relative, but
8444 in executable files they are virtual addresses. Note that
8445 this code assumes that all ELF sections have an associated
8446 BFD section with a reasonable value for output_offset; below
8447 we assume that they also have a reasonable value for
8448 output_section. Any special sections must be set up to meet
8449 these requirements. */
8450 osym
.st_value
+= isec
->output_offset
;
8451 if (! finfo
->info
->relocatable
)
8453 osym
.st_value
+= isec
->output_section
->vma
;
8454 if (ELF_ST_TYPE (osym
.st_info
) == STT_TLS
)
8456 /* STT_TLS symbols are relative to PT_TLS segment base. */
8457 BFD_ASSERT (elf_hash_table (finfo
->info
)->tls_sec
!= NULL
);
8458 osym
.st_value
-= elf_hash_table (finfo
->info
)->tls_sec
->vma
;
8462 if (! elf_link_output_sym (finfo
, name
, &osym
, isec
, NULL
))
8466 if (! evaluate_complex_relocation_symbols (input_bfd
, finfo
, locsymcount
))
8469 /* Relocate the contents of each section. */
8470 sym_hashes
= elf_sym_hashes (input_bfd
);
8471 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
8475 if (! o
->linker_mark
)
8477 /* This section was omitted from the link. */
8481 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
8482 || (o
->size
== 0 && (o
->flags
& SEC_RELOC
) == 0))
8485 if ((o
->flags
& SEC_LINKER_CREATED
) != 0)
8487 /* Section was created by _bfd_elf_link_create_dynamic_sections
8492 /* Get the contents of the section. They have been cached by a
8493 relaxation routine. Note that o is a section in an input
8494 file, so the contents field will not have been set by any of
8495 the routines which work on output files. */
8496 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
8497 contents
= elf_section_data (o
)->this_hdr
.contents
;
8500 bfd_size_type amt
= o
->rawsize
? o
->rawsize
: o
->size
;
8502 contents
= finfo
->contents
;
8503 if (! bfd_get_section_contents (input_bfd
, o
, contents
, 0, amt
))
8507 if ((o
->flags
& SEC_RELOC
) != 0)
8509 Elf_Internal_Rela
*internal_relocs
;
8510 bfd_vma r_type_mask
;
8514 /* Get the swapped relocs. */
8516 = _bfd_elf_link_read_relocs (input_bfd
, o
, finfo
->external_relocs
,
8517 finfo
->internal_relocs
, FALSE
);
8518 if (internal_relocs
== NULL
8519 && o
->reloc_count
> 0)
8522 if (bed
->s
->arch_size
== 32)
8529 r_type_mask
= 0xffffffff;
8533 /* Run through the relocs looking for any against symbols
8534 from discarded sections and section symbols from
8535 removed link-once sections. Complain about relocs
8536 against discarded sections. Zero relocs against removed
8537 link-once sections. */
8538 if (!elf_section_ignore_discarded_relocs (o
))
8540 Elf_Internal_Rela
*rel
, *relend
;
8541 unsigned int action
= (*bed
->action_discarded
) (o
);
8543 rel
= internal_relocs
;
8544 relend
= rel
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8545 for ( ; rel
< relend
; rel
++)
8547 unsigned long r_symndx
= rel
->r_info
>> r_sym_shift
;
8548 asection
**ps
, *sec
;
8549 struct elf_link_hash_entry
*h
= NULL
;
8550 const char *sym_name
;
8552 if (r_symndx
== STN_UNDEF
)
8555 if (r_symndx
>= locsymcount
8556 || (elf_bad_symtab (input_bfd
)
8557 && finfo
->sections
[r_symndx
] == NULL
))
8559 h
= sym_hashes
[r_symndx
- extsymoff
];
8561 /* Badly formatted input files can contain relocs that
8562 reference non-existant symbols. Check here so that
8563 we do not seg fault. */
8568 sprintf_vma (buffer
, rel
->r_info
);
8569 (*_bfd_error_handler
)
8570 (_("error: %B contains a reloc (0x%s) for section %A "
8571 "that references a non-existent global symbol"),
8572 input_bfd
, o
, buffer
);
8573 bfd_set_error (bfd_error_bad_value
);
8577 while (h
->root
.type
== bfd_link_hash_indirect
8578 || h
->root
.type
== bfd_link_hash_warning
)
8579 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8581 if (h
->root
.type
!= bfd_link_hash_defined
8582 && h
->root
.type
!= bfd_link_hash_defweak
)
8585 ps
= &h
->root
.u
.def
.section
;
8586 sym_name
= h
->root
.root
.string
;
8590 Elf_Internal_Sym
*sym
= isymbuf
+ r_symndx
;
8591 ps
= &finfo
->sections
[r_symndx
];
8592 sym_name
= bfd_elf_sym_name (input_bfd
,
8597 /* Complain if the definition comes from a
8598 discarded section. */
8599 if ((sec
= *ps
) != NULL
&& elf_discarded_section (sec
))
8601 BFD_ASSERT (r_symndx
!= 0);
8602 if (action
& COMPLAIN
)
8603 (*finfo
->info
->callbacks
->einfo
)
8604 (_("%X`%s' referenced in section `%A' of %B: "
8605 "defined in discarded section `%A' of %B\n"),
8606 sym_name
, o
, input_bfd
, sec
, sec
->owner
);
8608 /* Try to do the best we can to support buggy old
8609 versions of gcc. Pretend that the symbol is
8610 really defined in the kept linkonce section.
8611 FIXME: This is quite broken. Modifying the
8612 symbol here means we will be changing all later
8613 uses of the symbol, not just in this section. */
8614 if (action
& PRETEND
)
8618 kept
= _bfd_elf_check_kept_section (sec
,
8630 /* Relocate the section by invoking a back end routine.
8632 The back end routine is responsible for adjusting the
8633 section contents as necessary, and (if using Rela relocs
8634 and generating a relocatable output file) adjusting the
8635 reloc addend as necessary.
8637 The back end routine does not have to worry about setting
8638 the reloc address or the reloc symbol index.
8640 The back end routine is given a pointer to the swapped in
8641 internal symbols, and can access the hash table entries
8642 for the external symbols via elf_sym_hashes (input_bfd).
8644 When generating relocatable output, the back end routine
8645 must handle STB_LOCAL/STT_SECTION symbols specially. The
8646 output symbol is going to be a section symbol
8647 corresponding to the output section, which will require
8648 the addend to be adjusted. */
8650 ret
= (*relocate_section
) (output_bfd
, finfo
->info
,
8651 input_bfd
, o
, contents
,
8659 || finfo
->info
->relocatable
8660 || finfo
->info
->emitrelocations
)
8662 Elf_Internal_Rela
*irela
;
8663 Elf_Internal_Rela
*irelaend
;
8664 bfd_vma last_offset
;
8665 struct elf_link_hash_entry
**rel_hash
;
8666 struct elf_link_hash_entry
**rel_hash_list
;
8667 Elf_Internal_Shdr
*input_rel_hdr
, *input_rel_hdr2
;
8668 unsigned int next_erel
;
8669 bfd_boolean rela_normal
;
8671 input_rel_hdr
= &elf_section_data (o
)->rel_hdr
;
8672 rela_normal
= (bed
->rela_normal
8673 && (input_rel_hdr
->sh_entsize
8674 == bed
->s
->sizeof_rela
));
8676 /* Adjust the reloc addresses and symbol indices. */
8678 irela
= internal_relocs
;
8679 irelaend
= irela
+ o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8680 rel_hash
= (elf_section_data (o
->output_section
)->rel_hashes
8681 + elf_section_data (o
->output_section
)->rel_count
8682 + elf_section_data (o
->output_section
)->rel_count2
);
8683 rel_hash_list
= rel_hash
;
8684 last_offset
= o
->output_offset
;
8685 if (!finfo
->info
->relocatable
)
8686 last_offset
+= o
->output_section
->vma
;
8687 for (next_erel
= 0; irela
< irelaend
; irela
++, next_erel
++)
8689 unsigned long r_symndx
;
8691 Elf_Internal_Sym sym
;
8693 if (next_erel
== bed
->s
->int_rels_per_ext_rel
)
8699 irela
->r_offset
= _bfd_elf_section_offset (output_bfd
,
8702 if (irela
->r_offset
>= (bfd_vma
) -2)
8704 /* This is a reloc for a deleted entry or somesuch.
8705 Turn it into an R_*_NONE reloc, at the same
8706 offset as the last reloc. elf_eh_frame.c and
8707 bfd_elf_discard_info rely on reloc offsets
8709 irela
->r_offset
= last_offset
;
8711 irela
->r_addend
= 0;
8715 irela
->r_offset
+= o
->output_offset
;
8717 /* Relocs in an executable have to be virtual addresses. */
8718 if (!finfo
->info
->relocatable
)
8719 irela
->r_offset
+= o
->output_section
->vma
;
8721 last_offset
= irela
->r_offset
;
8723 r_symndx
= irela
->r_info
>> r_sym_shift
;
8724 if (r_symndx
== STN_UNDEF
)
8727 if (r_symndx
>= locsymcount
8728 || (elf_bad_symtab (input_bfd
)
8729 && finfo
->sections
[r_symndx
] == NULL
))
8731 struct elf_link_hash_entry
*rh
;
8734 /* This is a reloc against a global symbol. We
8735 have not yet output all the local symbols, so
8736 we do not know the symbol index of any global
8737 symbol. We set the rel_hash entry for this
8738 reloc to point to the global hash table entry
8739 for this symbol. The symbol index is then
8740 set at the end of bfd_elf_final_link. */
8741 indx
= r_symndx
- extsymoff
;
8742 rh
= elf_sym_hashes (input_bfd
)[indx
];
8743 while (rh
->root
.type
== bfd_link_hash_indirect
8744 || rh
->root
.type
== bfd_link_hash_warning
)
8745 rh
= (struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
;
8747 /* Setting the index to -2 tells
8748 elf_link_output_extsym that this symbol is
8750 BFD_ASSERT (rh
->indx
< 0);
8758 /* This is a reloc against a local symbol. */
8761 sym
= isymbuf
[r_symndx
];
8762 sec
= finfo
->sections
[r_symndx
];
8763 if (ELF_ST_TYPE (sym
.st_info
) == STT_SECTION
)
8765 /* I suppose the backend ought to fill in the
8766 section of any STT_SECTION symbol against a
8767 processor specific section. */
8769 if (bfd_is_abs_section (sec
))
8771 else if (sec
== NULL
|| sec
->owner
== NULL
)
8773 bfd_set_error (bfd_error_bad_value
);
8778 asection
*osec
= sec
->output_section
;
8780 /* If we have discarded a section, the output
8781 section will be the absolute section. In
8782 case of discarded SEC_MERGE sections, use
8783 the kept section. relocate_section should
8784 have already handled discarded linkonce
8786 if (bfd_is_abs_section (osec
)
8787 && sec
->kept_section
!= NULL
8788 && sec
->kept_section
->output_section
!= NULL
)
8790 osec
= sec
->kept_section
->output_section
;
8791 irela
->r_addend
-= osec
->vma
;
8794 if (!bfd_is_abs_section (osec
))
8796 r_symndx
= osec
->target_index
;
8799 struct elf_link_hash_table
*htab
;
8802 htab
= elf_hash_table (finfo
->info
);
8803 oi
= htab
->text_index_section
;
8804 if ((osec
->flags
& SEC_READONLY
) == 0
8805 && htab
->data_index_section
!= NULL
)
8806 oi
= htab
->data_index_section
;
8810 irela
->r_addend
+= osec
->vma
- oi
->vma
;
8811 r_symndx
= oi
->target_index
;
8815 BFD_ASSERT (r_symndx
!= 0);
8819 /* Adjust the addend according to where the
8820 section winds up in the output section. */
8822 irela
->r_addend
+= sec
->output_offset
;
8826 if (finfo
->indices
[r_symndx
] == -1)
8828 unsigned long shlink
;
8832 if (finfo
->info
->strip
== strip_all
)
8834 /* You can't do ld -r -s. */
8835 bfd_set_error (bfd_error_invalid_operation
);
8839 /* This symbol was skipped earlier, but
8840 since it is needed by a reloc, we
8841 must output it now. */
8842 shlink
= symtab_hdr
->sh_link
;
8843 name
= (bfd_elf_string_from_elf_section
8844 (input_bfd
, shlink
, sym
.st_name
));
8848 osec
= sec
->output_section
;
8850 _bfd_elf_section_from_bfd_section (output_bfd
,
8852 if (sym
.st_shndx
== SHN_BAD
)
8855 sym
.st_value
+= sec
->output_offset
;
8856 if (! finfo
->info
->relocatable
)
8858 sym
.st_value
+= osec
->vma
;
8859 if (ELF_ST_TYPE (sym
.st_info
) == STT_TLS
)
8861 /* STT_TLS symbols are relative to PT_TLS
8863 BFD_ASSERT (elf_hash_table (finfo
->info
)
8865 sym
.st_value
-= (elf_hash_table (finfo
->info
)
8870 finfo
->indices
[r_symndx
]
8871 = bfd_get_symcount (output_bfd
);
8873 if (! elf_link_output_sym (finfo
, name
, &sym
, sec
,
8878 r_symndx
= finfo
->indices
[r_symndx
];
8881 irela
->r_info
= ((bfd_vma
) r_symndx
<< r_sym_shift
8882 | (irela
->r_info
& r_type_mask
));
8885 /* Swap out the relocs. */
8886 if (input_rel_hdr
->sh_size
!= 0
8887 && !bed
->elf_backend_emit_relocs (output_bfd
, o
,
8893 input_rel_hdr2
= elf_section_data (o
)->rel_hdr2
;
8894 if (input_rel_hdr2
&& input_rel_hdr2
->sh_size
!= 0)
8896 internal_relocs
+= (NUM_SHDR_ENTRIES (input_rel_hdr
)
8897 * bed
->s
->int_rels_per_ext_rel
);
8898 rel_hash_list
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
8899 if (!bed
->elf_backend_emit_relocs (output_bfd
, o
,
8908 /* Write out the modified section contents. */
8909 if (bed
->elf_backend_write_section
8910 && (*bed
->elf_backend_write_section
) (output_bfd
, finfo
->info
, o
,
8913 /* Section written out. */
8915 else switch (o
->sec_info_type
)
8917 case ELF_INFO_TYPE_STABS
:
8918 if (! (_bfd_write_section_stabs
8920 &elf_hash_table (finfo
->info
)->stab_info
,
8921 o
, &elf_section_data (o
)->sec_info
, contents
)))
8924 case ELF_INFO_TYPE_MERGE
:
8925 if (! _bfd_write_merged_section (output_bfd
, o
,
8926 elf_section_data (o
)->sec_info
))
8929 case ELF_INFO_TYPE_EH_FRAME
:
8931 if (! _bfd_elf_write_section_eh_frame (output_bfd
, finfo
->info
,
8938 if (! (o
->flags
& SEC_EXCLUDE
)
8939 && ! bfd_set_section_contents (output_bfd
, o
->output_section
,
8941 (file_ptr
) o
->output_offset
,
8952 /* Generate a reloc when linking an ELF file. This is a reloc
8953 requested by the linker, and does not come from any input file. This
8954 is used to build constructor and destructor tables when linking
8958 elf_reloc_link_order (bfd
*output_bfd
,
8959 struct bfd_link_info
*info
,
8960 asection
*output_section
,
8961 struct bfd_link_order
*link_order
)
8963 reloc_howto_type
*howto
;
8967 struct elf_link_hash_entry
**rel_hash_ptr
;
8968 Elf_Internal_Shdr
*rel_hdr
;
8969 const struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
8970 Elf_Internal_Rela irel
[MAX_INT_RELS_PER_EXT_REL
];
8974 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
8977 bfd_set_error (bfd_error_bad_value
);
8981 addend
= link_order
->u
.reloc
.p
->addend
;
8983 /* Figure out the symbol index. */
8984 rel_hash_ptr
= (elf_section_data (output_section
)->rel_hashes
8985 + elf_section_data (output_section
)->rel_count
8986 + elf_section_data (output_section
)->rel_count2
);
8987 if (link_order
->type
== bfd_section_reloc_link_order
)
8989 indx
= link_order
->u
.reloc
.p
->u
.section
->target_index
;
8990 BFD_ASSERT (indx
!= 0);
8991 *rel_hash_ptr
= NULL
;
8995 struct elf_link_hash_entry
*h
;
8997 /* Treat a reloc against a defined symbol as though it were
8998 actually against the section. */
8999 h
= ((struct elf_link_hash_entry
*)
9000 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
9001 link_order
->u
.reloc
.p
->u
.name
,
9002 FALSE
, FALSE
, TRUE
));
9004 && (h
->root
.type
== bfd_link_hash_defined
9005 || h
->root
.type
== bfd_link_hash_defweak
))
9009 section
= h
->root
.u
.def
.section
;
9010 indx
= section
->output_section
->target_index
;
9011 *rel_hash_ptr
= NULL
;
9012 /* It seems that we ought to add the symbol value to the
9013 addend here, but in practice it has already been added
9014 because it was passed to constructor_callback. */
9015 addend
+= section
->output_section
->vma
+ section
->output_offset
;
9019 /* Setting the index to -2 tells elf_link_output_extsym that
9020 this symbol is used by a reloc. */
9027 if (! ((*info
->callbacks
->unattached_reloc
)
9028 (info
, link_order
->u
.reloc
.p
->u
.name
, NULL
, NULL
, 0)))
9034 /* If this is an inplace reloc, we must write the addend into the
9036 if (howto
->partial_inplace
&& addend
!= 0)
9039 bfd_reloc_status_type rstat
;
9042 const char *sym_name
;
9044 size
= bfd_get_reloc_size (howto
);
9045 buf
= bfd_zmalloc (size
);
9048 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
9055 case bfd_reloc_outofrange
:
9058 case bfd_reloc_overflow
:
9059 if (link_order
->type
== bfd_section_reloc_link_order
)
9060 sym_name
= bfd_section_name (output_bfd
,
9061 link_order
->u
.reloc
.p
->u
.section
);
9063 sym_name
= link_order
->u
.reloc
.p
->u
.name
;
9064 if (! ((*info
->callbacks
->reloc_overflow
)
9065 (info
, NULL
, sym_name
, howto
->name
, addend
, NULL
,
9066 NULL
, (bfd_vma
) 0)))
9073 ok
= bfd_set_section_contents (output_bfd
, output_section
, buf
,
9074 link_order
->offset
, size
);
9080 /* The address of a reloc is relative to the section in a
9081 relocatable file, and is a virtual address in an executable
9083 offset
= link_order
->offset
;
9084 if (! info
->relocatable
)
9085 offset
+= output_section
->vma
;
9087 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
9089 irel
[i
].r_offset
= offset
;
9091 irel
[i
].r_addend
= 0;
9093 if (bed
->s
->arch_size
== 32)
9094 irel
[0].r_info
= ELF32_R_INFO (indx
, howto
->type
);
9096 irel
[0].r_info
= ELF64_R_INFO (indx
, howto
->type
);
9098 rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
9099 erel
= rel_hdr
->contents
;
9100 if (rel_hdr
->sh_type
== SHT_REL
)
9102 erel
+= (elf_section_data (output_section
)->rel_count
9103 * bed
->s
->sizeof_rel
);
9104 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, erel
);
9108 irel
[0].r_addend
= addend
;
9109 erel
+= (elf_section_data (output_section
)->rel_count
9110 * bed
->s
->sizeof_rela
);
9111 (*bed
->s
->swap_reloca_out
) (output_bfd
, irel
, erel
);
9114 ++elf_section_data (output_section
)->rel_count
;
9120 /* Get the output vma of the section pointed to by the sh_link field. */
9123 elf_get_linked_section_vma (struct bfd_link_order
*p
)
9125 Elf_Internal_Shdr
**elf_shdrp
;
9129 s
= p
->u
.indirect
.section
;
9130 elf_shdrp
= elf_elfsections (s
->owner
);
9131 elfsec
= _bfd_elf_section_from_bfd_section (s
->owner
, s
);
9132 elfsec
= elf_shdrp
[elfsec
]->sh_link
;
9134 The Intel C compiler generates SHT_IA_64_UNWIND with
9135 SHF_LINK_ORDER. But it doesn't set the sh_link or
9136 sh_info fields. Hence we could get the situation
9137 where elfsec is 0. */
9140 const struct elf_backend_data
*bed
9141 = get_elf_backend_data (s
->owner
);
9142 if (bed
->link_order_error_handler
)
9143 bed
->link_order_error_handler
9144 (_("%B: warning: sh_link not set for section `%A'"), s
->owner
, s
);
9149 s
= elf_shdrp
[elfsec
]->bfd_section
;
9150 return s
->output_section
->vma
+ s
->output_offset
;
9155 /* Compare two sections based on the locations of the sections they are
9156 linked to. Used by elf_fixup_link_order. */
9159 compare_link_order (const void * a
, const void * b
)
9164 apos
= elf_get_linked_section_vma (*(struct bfd_link_order
**)a
);
9165 bpos
= elf_get_linked_section_vma (*(struct bfd_link_order
**)b
);
9172 /* Looks for sections with SHF_LINK_ORDER set. Rearranges them into the same
9173 order as their linked sections. Returns false if this could not be done
9174 because an output section includes both ordered and unordered
9175 sections. Ideally we'd do this in the linker proper. */
9178 elf_fixup_link_order (bfd
*abfd
, asection
*o
)
9183 struct bfd_link_order
*p
;
9185 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
9187 struct bfd_link_order
**sections
;
9188 asection
*s
, *other_sec
, *linkorder_sec
;
9192 linkorder_sec
= NULL
;
9195 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9197 if (p
->type
== bfd_indirect_link_order
)
9199 s
= p
->u
.indirect
.section
;
9201 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
9202 && elf_elfheader (sub
)->e_ident
[EI_CLASS
] == bed
->s
->elfclass
9203 && (elfsec
= _bfd_elf_section_from_bfd_section (sub
, s
))
9204 && elfsec
< elf_numsections (sub
)
9205 && elf_elfsections (sub
)[elfsec
]->sh_flags
& SHF_LINK_ORDER
)
9219 if (seen_other
&& seen_linkorder
)
9221 if (other_sec
&& linkorder_sec
)
9222 (*_bfd_error_handler
) (_("%A has both ordered [`%A' in %B] and unordered [`%A' in %B] sections"),
9224 linkorder_sec
->owner
, other_sec
,
9227 (*_bfd_error_handler
) (_("%A has both ordered and unordered sections"),
9229 bfd_set_error (bfd_error_bad_value
);
9234 if (!seen_linkorder
)
9237 sections
= (struct bfd_link_order
**)
9238 xmalloc (seen_linkorder
* sizeof (struct bfd_link_order
*));
9241 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9243 sections
[seen_linkorder
++] = p
;
9245 /* Sort the input sections in the order of their linked section. */
9246 qsort (sections
, seen_linkorder
, sizeof (struct bfd_link_order
*),
9247 compare_link_order
);
9249 /* Change the offsets of the sections. */
9251 for (n
= 0; n
< seen_linkorder
; n
++)
9253 s
= sections
[n
]->u
.indirect
.section
;
9254 offset
&= ~(bfd_vma
)((1 << s
->alignment_power
) - 1);
9255 s
->output_offset
= offset
;
9256 sections
[n
]->offset
= offset
;
9257 offset
+= sections
[n
]->size
;
9264 /* Do the final step of an ELF link. */
9267 bfd_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
9269 bfd_boolean dynamic
;
9270 bfd_boolean emit_relocs
;
9272 struct elf_final_link_info finfo
;
9273 register asection
*o
;
9274 register struct bfd_link_order
*p
;
9276 bfd_size_type max_contents_size
;
9277 bfd_size_type max_external_reloc_size
;
9278 bfd_size_type max_internal_reloc_count
;
9279 bfd_size_type max_sym_count
;
9280 bfd_size_type max_sym_shndx_count
;
9282 Elf_Internal_Sym elfsym
;
9284 Elf_Internal_Shdr
*symtab_hdr
;
9285 Elf_Internal_Shdr
*symtab_shndx_hdr
;
9286 Elf_Internal_Shdr
*symstrtab_hdr
;
9287 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
9288 struct elf_outext_info eoinfo
;
9290 size_t relativecount
= 0;
9291 asection
*reldyn
= 0;
9293 asection
*attr_section
= NULL
;
9294 bfd_vma attr_size
= 0;
9295 const char *std_attrs_section
;
9297 if (! is_elf_hash_table (info
->hash
))
9301 abfd
->flags
|= DYNAMIC
;
9303 dynamic
= elf_hash_table (info
)->dynamic_sections_created
;
9304 dynobj
= elf_hash_table (info
)->dynobj
;
9306 emit_relocs
= (info
->relocatable
9307 || info
->emitrelocations
);
9310 finfo
.output_bfd
= abfd
;
9311 finfo
.symstrtab
= _bfd_elf_stringtab_init ();
9312 if (finfo
.symstrtab
== NULL
)
9317 finfo
.dynsym_sec
= NULL
;
9318 finfo
.hash_sec
= NULL
;
9319 finfo
.symver_sec
= NULL
;
9323 finfo
.dynsym_sec
= bfd_get_section_by_name (dynobj
, ".dynsym");
9324 finfo
.hash_sec
= bfd_get_section_by_name (dynobj
, ".hash");
9325 BFD_ASSERT (finfo
.dynsym_sec
!= NULL
);
9326 finfo
.symver_sec
= bfd_get_section_by_name (dynobj
, ".gnu.version");
9327 /* Note that it is OK if symver_sec is NULL. */
9330 finfo
.contents
= NULL
;
9331 finfo
.external_relocs
= NULL
;
9332 finfo
.internal_relocs
= NULL
;
9333 finfo
.external_syms
= NULL
;
9334 finfo
.locsym_shndx
= NULL
;
9335 finfo
.internal_syms
= NULL
;
9336 finfo
.indices
= NULL
;
9337 finfo
.sections
= NULL
;
9338 finfo
.symbuf
= NULL
;
9339 finfo
.symshndxbuf
= NULL
;
9340 finfo
.symbuf_count
= 0;
9341 finfo
.shndxbuf_size
= 0;
9343 /* The object attributes have been merged. Remove the input
9344 sections from the link, and set the contents of the output
9346 std_attrs_section
= get_elf_backend_data (abfd
)->obj_attrs_section
;
9347 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9349 if ((std_attrs_section
&& strcmp (o
->name
, std_attrs_section
) == 0)
9350 || strcmp (o
->name
, ".gnu.attributes") == 0)
9352 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9354 asection
*input_section
;
9356 if (p
->type
!= bfd_indirect_link_order
)
9358 input_section
= p
->u
.indirect
.section
;
9359 /* Hack: reset the SEC_HAS_CONTENTS flag so that
9360 elf_link_input_bfd ignores this section. */
9361 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
9364 attr_size
= bfd_elf_obj_attr_size (abfd
);
9367 bfd_set_section_size (abfd
, o
, attr_size
);
9369 /* Skip this section later on. */
9370 o
->map_head
.link_order
= NULL
;
9373 o
->flags
|= SEC_EXCLUDE
;
9377 /* Count up the number of relocations we will output for each output
9378 section, so that we know the sizes of the reloc sections. We
9379 also figure out some maximum sizes. */
9380 max_contents_size
= 0;
9381 max_external_reloc_size
= 0;
9382 max_internal_reloc_count
= 0;
9384 max_sym_shndx_count
= 0;
9386 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9388 struct bfd_elf_section_data
*esdo
= elf_section_data (o
);
9391 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9393 unsigned int reloc_count
= 0;
9394 struct bfd_elf_section_data
*esdi
= NULL
;
9395 unsigned int *rel_count1
;
9397 if (p
->type
== bfd_section_reloc_link_order
9398 || p
->type
== bfd_symbol_reloc_link_order
)
9400 else if (p
->type
== bfd_indirect_link_order
)
9404 sec
= p
->u
.indirect
.section
;
9405 esdi
= elf_section_data (sec
);
9407 /* Mark all sections which are to be included in the
9408 link. This will normally be every section. We need
9409 to do this so that we can identify any sections which
9410 the linker has decided to not include. */
9411 sec
->linker_mark
= TRUE
;
9413 if (sec
->flags
& SEC_MERGE
)
9416 if (info
->relocatable
|| info
->emitrelocations
)
9417 reloc_count
= sec
->reloc_count
;
9418 else if (bed
->elf_backend_count_relocs
)
9420 Elf_Internal_Rela
* relocs
;
9422 relocs
= _bfd_elf_link_read_relocs (sec
->owner
, sec
,
9429 = (*bed
->elf_backend_count_relocs
) (sec
, relocs
);
9431 if (elf_section_data (sec
)->relocs
!= relocs
)
9436 if (sec
->rawsize
> max_contents_size
)
9437 max_contents_size
= sec
->rawsize
;
9438 if (sec
->size
> max_contents_size
)
9439 max_contents_size
= sec
->size
;
9441 /* We are interested in just local symbols, not all
9443 if (bfd_get_flavour (sec
->owner
) == bfd_target_elf_flavour
9444 && (sec
->owner
->flags
& DYNAMIC
) == 0)
9448 if (elf_bad_symtab (sec
->owner
))
9449 sym_count
= (elf_tdata (sec
->owner
)->symtab_hdr
.sh_size
9450 / bed
->s
->sizeof_sym
);
9452 sym_count
= elf_tdata (sec
->owner
)->symtab_hdr
.sh_info
;
9454 if (sym_count
> max_sym_count
)
9455 max_sym_count
= sym_count
;
9457 if (sym_count
> max_sym_shndx_count
9458 && elf_symtab_shndx (sec
->owner
) != 0)
9459 max_sym_shndx_count
= sym_count
;
9461 if ((sec
->flags
& SEC_RELOC
) != 0)
9465 ext_size
= elf_section_data (sec
)->rel_hdr
.sh_size
;
9466 if (ext_size
> max_external_reloc_size
)
9467 max_external_reloc_size
= ext_size
;
9468 if (sec
->reloc_count
> max_internal_reloc_count
)
9469 max_internal_reloc_count
= sec
->reloc_count
;
9474 if (reloc_count
== 0)
9477 o
->reloc_count
+= reloc_count
;
9479 /* MIPS may have a mix of REL and RELA relocs on sections.
9480 To support this curious ABI we keep reloc counts in
9481 elf_section_data too. We must be careful to add the
9482 relocations from the input section to the right output
9483 count. FIXME: Get rid of one count. We have
9484 o->reloc_count == esdo->rel_count + esdo->rel_count2. */
9485 rel_count1
= &esdo
->rel_count
;
9488 bfd_boolean same_size
;
9489 bfd_size_type entsize1
;
9491 entsize1
= esdi
->rel_hdr
.sh_entsize
;
9492 BFD_ASSERT (entsize1
== bed
->s
->sizeof_rel
9493 || entsize1
== bed
->s
->sizeof_rela
);
9494 same_size
= !o
->use_rela_p
== (entsize1
== bed
->s
->sizeof_rel
);
9497 rel_count1
= &esdo
->rel_count2
;
9499 if (esdi
->rel_hdr2
!= NULL
)
9501 bfd_size_type entsize2
= esdi
->rel_hdr2
->sh_entsize
;
9502 unsigned int alt_count
;
9503 unsigned int *rel_count2
;
9505 BFD_ASSERT (entsize2
!= entsize1
9506 && (entsize2
== bed
->s
->sizeof_rel
9507 || entsize2
== bed
->s
->sizeof_rela
));
9509 rel_count2
= &esdo
->rel_count2
;
9511 rel_count2
= &esdo
->rel_count
;
9513 /* The following is probably too simplistic if the
9514 backend counts output relocs unusually. */
9515 BFD_ASSERT (bed
->elf_backend_count_relocs
== NULL
);
9516 alt_count
= NUM_SHDR_ENTRIES (esdi
->rel_hdr2
);
9517 *rel_count2
+= alt_count
;
9518 reloc_count
-= alt_count
;
9521 *rel_count1
+= reloc_count
;
9524 if (o
->reloc_count
> 0)
9525 o
->flags
|= SEC_RELOC
;
9528 /* Explicitly clear the SEC_RELOC flag. The linker tends to
9529 set it (this is probably a bug) and if it is set
9530 assign_section_numbers will create a reloc section. */
9531 o
->flags
&=~ SEC_RELOC
;
9534 /* If the SEC_ALLOC flag is not set, force the section VMA to
9535 zero. This is done in elf_fake_sections as well, but forcing
9536 the VMA to 0 here will ensure that relocs against these
9537 sections are handled correctly. */
9538 if ((o
->flags
& SEC_ALLOC
) == 0
9539 && ! o
->user_set_vma
)
9543 if (! info
->relocatable
&& merged
)
9544 elf_link_hash_traverse (elf_hash_table (info
),
9545 _bfd_elf_link_sec_merge_syms
, abfd
);
9547 /* Figure out the file positions for everything but the symbol table
9548 and the relocs. We set symcount to force assign_section_numbers
9549 to create a symbol table. */
9550 bfd_get_symcount (abfd
) = info
->strip
== strip_all
? 0 : 1;
9551 BFD_ASSERT (! abfd
->output_has_begun
);
9552 if (! _bfd_elf_compute_section_file_positions (abfd
, info
))
9555 /* Set sizes, and assign file positions for reloc sections. */
9556 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9558 if ((o
->flags
& SEC_RELOC
) != 0)
9560 if (!(_bfd_elf_link_size_reloc_section
9561 (abfd
, &elf_section_data (o
)->rel_hdr
, o
)))
9564 if (elf_section_data (o
)->rel_hdr2
9565 && !(_bfd_elf_link_size_reloc_section
9566 (abfd
, elf_section_data (o
)->rel_hdr2
, o
)))
9570 /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
9571 to count upwards while actually outputting the relocations. */
9572 elf_section_data (o
)->rel_count
= 0;
9573 elf_section_data (o
)->rel_count2
= 0;
9576 _bfd_elf_assign_file_positions_for_relocs (abfd
);
9578 /* We have now assigned file positions for all the sections except
9579 .symtab and .strtab. We start the .symtab section at the current
9580 file position, and write directly to it. We build the .strtab
9581 section in memory. */
9582 bfd_get_symcount (abfd
) = 0;
9583 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
9584 /* sh_name is set in prep_headers. */
9585 symtab_hdr
->sh_type
= SHT_SYMTAB
;
9586 /* sh_flags, sh_addr and sh_size all start off zero. */
9587 symtab_hdr
->sh_entsize
= bed
->s
->sizeof_sym
;
9588 /* sh_link is set in assign_section_numbers. */
9589 /* sh_info is set below. */
9590 /* sh_offset is set just below. */
9591 symtab_hdr
->sh_addralign
= 1 << bed
->s
->log_file_align
;
9593 off
= elf_tdata (abfd
)->next_file_pos
;
9594 off
= _bfd_elf_assign_file_position_for_section (symtab_hdr
, off
, TRUE
);
9596 /* Note that at this point elf_tdata (abfd)->next_file_pos is
9597 incorrect. We do not yet know the size of the .symtab section.
9598 We correct next_file_pos below, after we do know the size. */
9600 /* Allocate a buffer to hold swapped out symbols. This is to avoid
9601 continuously seeking to the right position in the file. */
9602 if (! info
->keep_memory
|| max_sym_count
< 20)
9603 finfo
.symbuf_size
= 20;
9605 finfo
.symbuf_size
= max_sym_count
;
9606 amt
= finfo
.symbuf_size
;
9607 amt
*= bed
->s
->sizeof_sym
;
9608 finfo
.symbuf
= bfd_malloc (amt
);
9609 if (finfo
.symbuf
== NULL
)
9611 if (elf_numsections (abfd
) > SHN_LORESERVE
)
9613 /* Wild guess at number of output symbols. realloc'd as needed. */
9614 amt
= 2 * max_sym_count
+ elf_numsections (abfd
) + 1000;
9615 finfo
.shndxbuf_size
= amt
;
9616 amt
*= sizeof (Elf_External_Sym_Shndx
);
9617 finfo
.symshndxbuf
= bfd_zmalloc (amt
);
9618 if (finfo
.symshndxbuf
== NULL
)
9622 /* Start writing out the symbol table. The first symbol is always a
9624 if (info
->strip
!= strip_all
9627 elfsym
.st_value
= 0;
9630 elfsym
.st_other
= 0;
9631 elfsym
.st_shndx
= SHN_UNDEF
;
9632 if (! elf_link_output_sym (&finfo
, NULL
, &elfsym
, bfd_und_section_ptr
,
9637 /* Output a symbol for each section. We output these even if we are
9638 discarding local symbols, since they are used for relocs. These
9639 symbols have no names. We store the index of each one in the
9640 index field of the section, so that we can find it again when
9641 outputting relocs. */
9642 if (info
->strip
!= strip_all
9646 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
9647 elfsym
.st_other
= 0;
9648 elfsym
.st_value
= 0;
9649 for (i
= 1; i
< elf_numsections (abfd
); i
++)
9651 o
= bfd_section_from_elf_index (abfd
, i
);
9654 o
->target_index
= bfd_get_symcount (abfd
);
9655 elfsym
.st_shndx
= i
;
9656 if (!info
->relocatable
)
9657 elfsym
.st_value
= o
->vma
;
9658 if (!elf_link_output_sym (&finfo
, NULL
, &elfsym
, o
, NULL
))
9661 if (i
== SHN_LORESERVE
- 1)
9662 i
+= SHN_HIRESERVE
+ 1 - SHN_LORESERVE
;
9666 /* Allocate some memory to hold information read in from the input
9668 if (max_contents_size
!= 0)
9670 finfo
.contents
= bfd_malloc (max_contents_size
);
9671 if (finfo
.contents
== NULL
)
9675 if (max_external_reloc_size
!= 0)
9677 finfo
.external_relocs
= bfd_malloc (max_external_reloc_size
);
9678 if (finfo
.external_relocs
== NULL
)
9682 if (max_internal_reloc_count
!= 0)
9684 amt
= max_internal_reloc_count
* bed
->s
->int_rels_per_ext_rel
;
9685 amt
*= sizeof (Elf_Internal_Rela
);
9686 finfo
.internal_relocs
= bfd_malloc (amt
);
9687 if (finfo
.internal_relocs
== NULL
)
9691 if (max_sym_count
!= 0)
9693 amt
= max_sym_count
* bed
->s
->sizeof_sym
;
9694 finfo
.external_syms
= bfd_malloc (amt
);
9695 if (finfo
.external_syms
== NULL
)
9698 amt
= max_sym_count
* sizeof (Elf_Internal_Sym
);
9699 finfo
.internal_syms
= bfd_malloc (amt
);
9700 if (finfo
.internal_syms
== NULL
)
9703 amt
= max_sym_count
* sizeof (long);
9704 finfo
.indices
= bfd_malloc (amt
);
9705 if (finfo
.indices
== NULL
)
9708 amt
= max_sym_count
* sizeof (asection
*);
9709 finfo
.sections
= bfd_malloc (amt
);
9710 if (finfo
.sections
== NULL
)
9714 if (max_sym_shndx_count
!= 0)
9716 amt
= max_sym_shndx_count
* sizeof (Elf_External_Sym_Shndx
);
9717 finfo
.locsym_shndx
= bfd_malloc (amt
);
9718 if (finfo
.locsym_shndx
== NULL
)
9722 if (elf_hash_table (info
)->tls_sec
)
9724 bfd_vma base
, end
= 0;
9727 for (sec
= elf_hash_table (info
)->tls_sec
;
9728 sec
&& (sec
->flags
& SEC_THREAD_LOCAL
);
9731 bfd_size_type size
= sec
->size
;
9734 && (sec
->flags
& SEC_HAS_CONTENTS
) == 0)
9736 struct bfd_link_order
*o
= sec
->map_tail
.link_order
;
9738 size
= o
->offset
+ o
->size
;
9740 end
= sec
->vma
+ size
;
9742 base
= elf_hash_table (info
)->tls_sec
->vma
;
9743 end
= align_power (end
, elf_hash_table (info
)->tls_sec
->alignment_power
);
9744 elf_hash_table (info
)->tls_size
= end
- base
;
9747 /* Reorder SHF_LINK_ORDER sections. */
9748 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9750 if (!elf_fixup_link_order (abfd
, o
))
9754 /* Since ELF permits relocations to be against local symbols, we
9755 must have the local symbols available when we do the relocations.
9756 Since we would rather only read the local symbols once, and we
9757 would rather not keep them in memory, we handle all the
9758 relocations for a single input file at the same time.
9760 Unfortunately, there is no way to know the total number of local
9761 symbols until we have seen all of them, and the local symbol
9762 indices precede the global symbol indices. This means that when
9763 we are generating relocatable output, and we see a reloc against
9764 a global symbol, we can not know the symbol index until we have
9765 finished examining all the local symbols to see which ones we are
9766 going to output. To deal with this, we keep the relocations in
9767 memory, and don't output them until the end of the link. This is
9768 an unfortunate waste of memory, but I don't see a good way around
9769 it. Fortunately, it only happens when performing a relocatable
9770 link, which is not the common case. FIXME: If keep_memory is set
9771 we could write the relocs out and then read them again; I don't
9772 know how bad the memory loss will be. */
9774 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
9775 sub
->output_has_begun
= FALSE
;
9776 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
9778 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
9780 if (p
->type
== bfd_indirect_link_order
9781 && (bfd_get_flavour ((sub
= p
->u
.indirect
.section
->owner
))
9782 == bfd_target_elf_flavour
)
9783 && elf_elfheader (sub
)->e_ident
[EI_CLASS
] == bed
->s
->elfclass
)
9785 if (! sub
->output_has_begun
)
9787 if (! elf_link_input_bfd (&finfo
, sub
))
9789 sub
->output_has_begun
= TRUE
;
9792 else if (p
->type
== bfd_section_reloc_link_order
9793 || p
->type
== bfd_symbol_reloc_link_order
)
9795 if (! elf_reloc_link_order (abfd
, info
, o
, p
))
9800 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
9806 /* Free symbol buffer if needed. */
9807 if (!info
->reduce_memory_overheads
)
9809 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
9810 if (bfd_get_flavour (sub
) == bfd_target_elf_flavour
9811 && elf_tdata (sub
)->symbuf
)
9813 free (elf_tdata (sub
)->symbuf
);
9814 elf_tdata (sub
)->symbuf
= NULL
;
9818 /* Output any global symbols that got converted to local in a
9819 version script or due to symbol visibility. We do this in a
9820 separate step since ELF requires all local symbols to appear
9821 prior to any global symbols. FIXME: We should only do this if
9822 some global symbols were, in fact, converted to become local.
9823 FIXME: Will this work correctly with the Irix 5 linker? */
9824 eoinfo
.failed
= FALSE
;
9825 eoinfo
.finfo
= &finfo
;
9826 eoinfo
.localsyms
= TRUE
;
9827 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
9832 /* If backend needs to output some local symbols not present in the hash
9833 table, do it now. */
9834 if (bed
->elf_backend_output_arch_local_syms
)
9836 typedef bfd_boolean (*out_sym_func
)
9837 (void *, const char *, Elf_Internal_Sym
*, asection
*,
9838 struct elf_link_hash_entry
*);
9840 if (! ((*bed
->elf_backend_output_arch_local_syms
)
9841 (abfd
, info
, &finfo
, (out_sym_func
) elf_link_output_sym
)))
9845 /* That wrote out all the local symbols. Finish up the symbol table
9846 with the global symbols. Even if we want to strip everything we
9847 can, we still need to deal with those global symbols that got
9848 converted to local in a version script. */
9850 /* The sh_info field records the index of the first non local symbol. */
9851 symtab_hdr
->sh_info
= bfd_get_symcount (abfd
);
9854 && finfo
.dynsym_sec
->output_section
!= bfd_abs_section_ptr
)
9856 Elf_Internal_Sym sym
;
9857 bfd_byte
*dynsym
= finfo
.dynsym_sec
->contents
;
9858 long last_local
= 0;
9860 /* Write out the section symbols for the output sections. */
9861 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
9867 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
9870 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
9876 dynindx
= elf_section_data (s
)->dynindx
;
9879 indx
= elf_section_data (s
)->this_idx
;
9880 BFD_ASSERT (indx
> 0);
9881 sym
.st_shndx
= indx
;
9882 if (! check_dynsym (abfd
, &sym
))
9884 sym
.st_value
= s
->vma
;
9885 dest
= dynsym
+ dynindx
* bed
->s
->sizeof_sym
;
9886 if (last_local
< dynindx
)
9887 last_local
= dynindx
;
9888 bed
->s
->swap_symbol_out (abfd
, &sym
, dest
, 0);
9892 /* Write out the local dynsyms. */
9893 if (elf_hash_table (info
)->dynlocal
)
9895 struct elf_link_local_dynamic_entry
*e
;
9896 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
9901 sym
.st_size
= e
->isym
.st_size
;
9902 sym
.st_other
= e
->isym
.st_other
;
9904 /* Copy the internal symbol as is.
9905 Note that we saved a word of storage and overwrote
9906 the original st_name with the dynstr_index. */
9909 if (e
->isym
.st_shndx
!= SHN_UNDEF
9910 && (e
->isym
.st_shndx
< SHN_LORESERVE
9911 || e
->isym
.st_shndx
> SHN_HIRESERVE
))
9913 s
= bfd_section_from_elf_index (e
->input_bfd
,
9917 elf_section_data (s
->output_section
)->this_idx
;
9918 if (! check_dynsym (abfd
, &sym
))
9920 sym
.st_value
= (s
->output_section
->vma
9922 + e
->isym
.st_value
);
9925 if (last_local
< e
->dynindx
)
9926 last_local
= e
->dynindx
;
9928 dest
= dynsym
+ e
->dynindx
* bed
->s
->sizeof_sym
;
9929 bed
->s
->swap_symbol_out (abfd
, &sym
, dest
, 0);
9933 elf_section_data (finfo
.dynsym_sec
->output_section
)->this_hdr
.sh_info
=
9937 /* We get the global symbols from the hash table. */
9938 eoinfo
.failed
= FALSE
;
9939 eoinfo
.localsyms
= FALSE
;
9940 eoinfo
.finfo
= &finfo
;
9941 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
9946 /* If backend needs to output some symbols not present in the hash
9947 table, do it now. */
9948 if (bed
->elf_backend_output_arch_syms
)
9950 typedef bfd_boolean (*out_sym_func
)
9951 (void *, const char *, Elf_Internal_Sym
*, asection
*,
9952 struct elf_link_hash_entry
*);
9954 if (! ((*bed
->elf_backend_output_arch_syms
)
9955 (abfd
, info
, &finfo
, (out_sym_func
) elf_link_output_sym
)))
9959 /* Flush all symbols to the file. */
9960 if (! elf_link_flush_output_syms (&finfo
, bed
))
9963 /* Now we know the size of the symtab section. */
9964 off
+= symtab_hdr
->sh_size
;
9966 symtab_shndx_hdr
= &elf_tdata (abfd
)->symtab_shndx_hdr
;
9967 if (symtab_shndx_hdr
->sh_name
!= 0)
9969 symtab_shndx_hdr
->sh_type
= SHT_SYMTAB_SHNDX
;
9970 symtab_shndx_hdr
->sh_entsize
= sizeof (Elf_External_Sym_Shndx
);
9971 symtab_shndx_hdr
->sh_addralign
= sizeof (Elf_External_Sym_Shndx
);
9972 amt
= bfd_get_symcount (abfd
) * sizeof (Elf_External_Sym_Shndx
);
9973 symtab_shndx_hdr
->sh_size
= amt
;
9975 off
= _bfd_elf_assign_file_position_for_section (symtab_shndx_hdr
,
9978 if (bfd_seek (abfd
, symtab_shndx_hdr
->sh_offset
, SEEK_SET
) != 0
9979 || (bfd_bwrite (finfo
.symshndxbuf
, amt
, abfd
) != amt
))
9984 /* Finish up and write out the symbol string table (.strtab)
9986 symstrtab_hdr
= &elf_tdata (abfd
)->strtab_hdr
;
9987 /* sh_name was set in prep_headers. */
9988 symstrtab_hdr
->sh_type
= SHT_STRTAB
;
9989 symstrtab_hdr
->sh_flags
= 0;
9990 symstrtab_hdr
->sh_addr
= 0;
9991 symstrtab_hdr
->sh_size
= _bfd_stringtab_size (finfo
.symstrtab
);
9992 symstrtab_hdr
->sh_entsize
= 0;
9993 symstrtab_hdr
->sh_link
= 0;
9994 symstrtab_hdr
->sh_info
= 0;
9995 /* sh_offset is set just below. */
9996 symstrtab_hdr
->sh_addralign
= 1;
9998 off
= _bfd_elf_assign_file_position_for_section (symstrtab_hdr
, off
, TRUE
);
9999 elf_tdata (abfd
)->next_file_pos
= off
;
10001 if (bfd_get_symcount (abfd
) > 0)
10003 if (bfd_seek (abfd
, symstrtab_hdr
->sh_offset
, SEEK_SET
) != 0
10004 || ! _bfd_stringtab_emit (abfd
, finfo
.symstrtab
))
10008 /* Adjust the relocs to have the correct symbol indices. */
10009 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10011 if ((o
->flags
& SEC_RELOC
) == 0)
10014 elf_link_adjust_relocs (abfd
, &elf_section_data (o
)->rel_hdr
,
10015 elf_section_data (o
)->rel_count
,
10016 elf_section_data (o
)->rel_hashes
);
10017 if (elf_section_data (o
)->rel_hdr2
!= NULL
)
10018 elf_link_adjust_relocs (abfd
, elf_section_data (o
)->rel_hdr2
,
10019 elf_section_data (o
)->rel_count2
,
10020 (elf_section_data (o
)->rel_hashes
10021 + elf_section_data (o
)->rel_count
));
10023 /* Set the reloc_count field to 0 to prevent write_relocs from
10024 trying to swap the relocs out itself. */
10025 o
->reloc_count
= 0;
10028 if (dynamic
&& info
->combreloc
&& dynobj
!= NULL
)
10029 relativecount
= elf_link_sort_relocs (abfd
, info
, &reldyn
);
10031 /* If we are linking against a dynamic object, or generating a
10032 shared library, finish up the dynamic linking information. */
10035 bfd_byte
*dyncon
, *dynconend
;
10037 /* Fix up .dynamic entries. */
10038 o
= bfd_get_section_by_name (dynobj
, ".dynamic");
10039 BFD_ASSERT (o
!= NULL
);
10041 dyncon
= o
->contents
;
10042 dynconend
= o
->contents
+ o
->size
;
10043 for (; dyncon
< dynconend
; dyncon
+= bed
->s
->sizeof_dyn
)
10045 Elf_Internal_Dyn dyn
;
10049 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
10056 if (relativecount
> 0 && dyncon
+ bed
->s
->sizeof_dyn
< dynconend
)
10058 switch (elf_section_data (reldyn
)->this_hdr
.sh_type
)
10060 case SHT_REL
: dyn
.d_tag
= DT_RELCOUNT
; break;
10061 case SHT_RELA
: dyn
.d_tag
= DT_RELACOUNT
; break;
10064 dyn
.d_un
.d_val
= relativecount
;
10071 name
= info
->init_function
;
10074 name
= info
->fini_function
;
10077 struct elf_link_hash_entry
*h
;
10079 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
10080 FALSE
, FALSE
, TRUE
);
10082 && (h
->root
.type
== bfd_link_hash_defined
10083 || h
->root
.type
== bfd_link_hash_defweak
))
10085 dyn
.d_un
.d_val
= h
->root
.u
.def
.value
;
10086 o
= h
->root
.u
.def
.section
;
10087 if (o
->output_section
!= NULL
)
10088 dyn
.d_un
.d_val
+= (o
->output_section
->vma
10089 + o
->output_offset
);
10092 /* The symbol is imported from another shared
10093 library and does not apply to this one. */
10094 dyn
.d_un
.d_val
= 0;
10101 case DT_PREINIT_ARRAYSZ
:
10102 name
= ".preinit_array";
10104 case DT_INIT_ARRAYSZ
:
10105 name
= ".init_array";
10107 case DT_FINI_ARRAYSZ
:
10108 name
= ".fini_array";
10110 o
= bfd_get_section_by_name (abfd
, name
);
10113 (*_bfd_error_handler
)
10114 (_("%B: could not find output section %s"), abfd
, name
);
10118 (*_bfd_error_handler
)
10119 (_("warning: %s section has zero size"), name
);
10120 dyn
.d_un
.d_val
= o
->size
;
10123 case DT_PREINIT_ARRAY
:
10124 name
= ".preinit_array";
10126 case DT_INIT_ARRAY
:
10127 name
= ".init_array";
10129 case DT_FINI_ARRAY
:
10130 name
= ".fini_array";
10137 name
= ".gnu.hash";
10146 name
= ".gnu.version_d";
10149 name
= ".gnu.version_r";
10152 name
= ".gnu.version";
10154 o
= bfd_get_section_by_name (abfd
, name
);
10157 (*_bfd_error_handler
)
10158 (_("%B: could not find output section %s"), abfd
, name
);
10161 dyn
.d_un
.d_ptr
= o
->vma
;
10168 if (dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
10172 dyn
.d_un
.d_val
= 0;
10173 for (i
= 1; i
< elf_numsections (abfd
); i
++)
10175 Elf_Internal_Shdr
*hdr
;
10177 hdr
= elf_elfsections (abfd
)[i
];
10178 if (hdr
->sh_type
== type
10179 && (hdr
->sh_flags
& SHF_ALLOC
) != 0)
10181 if (dyn
.d_tag
== DT_RELSZ
|| dyn
.d_tag
== DT_RELASZ
)
10182 dyn
.d_un
.d_val
+= hdr
->sh_size
;
10185 if (dyn
.d_un
.d_val
== 0
10186 || hdr
->sh_addr
< dyn
.d_un
.d_val
)
10187 dyn
.d_un
.d_val
= hdr
->sh_addr
;
10193 bed
->s
->swap_dyn_out (dynobj
, &dyn
, dyncon
);
10197 /* If we have created any dynamic sections, then output them. */
10198 if (dynobj
!= NULL
)
10200 if (! (*bed
->elf_backend_finish_dynamic_sections
) (abfd
, info
))
10203 /* Check for DT_TEXTREL (late, in case the backend removes it). */
10204 if (info
->warn_shared_textrel
&& info
->shared
)
10206 bfd_byte
*dyncon
, *dynconend
;
10208 /* Fix up .dynamic entries. */
10209 o
= bfd_get_section_by_name (dynobj
, ".dynamic");
10210 BFD_ASSERT (o
!= NULL
);
10212 dyncon
= o
->contents
;
10213 dynconend
= o
->contents
+ o
->size
;
10214 for (; dyncon
< dynconend
; dyncon
+= bed
->s
->sizeof_dyn
)
10216 Elf_Internal_Dyn dyn
;
10218 bed
->s
->swap_dyn_in (dynobj
, dyncon
, &dyn
);
10220 if (dyn
.d_tag
== DT_TEXTREL
)
10222 info
->callbacks
->einfo
10223 (_("%P: warning: creating a DT_TEXTREL in a shared object.\n"));
10229 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
10231 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
10233 || o
->output_section
== bfd_abs_section_ptr
)
10235 if ((o
->flags
& SEC_LINKER_CREATED
) == 0)
10237 /* At this point, we are only interested in sections
10238 created by _bfd_elf_link_create_dynamic_sections. */
10241 if (elf_hash_table (info
)->stab_info
.stabstr
== o
)
10243 if (elf_hash_table (info
)->eh_info
.hdr_sec
== o
)
10245 if ((elf_section_data (o
->output_section
)->this_hdr
.sh_type
10247 || strcmp (bfd_get_section_name (abfd
, o
), ".dynstr") != 0)
10249 if (! bfd_set_section_contents (abfd
, o
->output_section
,
10251 (file_ptr
) o
->output_offset
,
10257 /* The contents of the .dynstr section are actually in a
10259 off
= elf_section_data (o
->output_section
)->this_hdr
.sh_offset
;
10260 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0
10261 || ! _bfd_elf_strtab_emit (abfd
,
10262 elf_hash_table (info
)->dynstr
))
10268 if (info
->relocatable
)
10270 bfd_boolean failed
= FALSE
;
10272 bfd_map_over_sections (abfd
, bfd_elf_set_group_contents
, &failed
);
10277 /* If we have optimized stabs strings, output them. */
10278 if (elf_hash_table (info
)->stab_info
.stabstr
!= NULL
)
10280 if (! _bfd_write_stab_strings (abfd
, &elf_hash_table (info
)->stab_info
))
10284 if (info
->eh_frame_hdr
)
10286 if (! _bfd_elf_write_section_eh_frame_hdr (abfd
, info
))
10290 if (finfo
.symstrtab
!= NULL
)
10291 _bfd_stringtab_free (finfo
.symstrtab
);
10292 if (finfo
.contents
!= NULL
)
10293 free (finfo
.contents
);
10294 if (finfo
.external_relocs
!= NULL
)
10295 free (finfo
.external_relocs
);
10296 if (finfo
.internal_relocs
!= NULL
)
10297 free (finfo
.internal_relocs
);
10298 if (finfo
.external_syms
!= NULL
)
10299 free (finfo
.external_syms
);
10300 if (finfo
.locsym_shndx
!= NULL
)
10301 free (finfo
.locsym_shndx
);
10302 if (finfo
.internal_syms
!= NULL
)
10303 free (finfo
.internal_syms
);
10304 if (finfo
.indices
!= NULL
)
10305 free (finfo
.indices
);
10306 if (finfo
.sections
!= NULL
)
10307 free (finfo
.sections
);
10308 if (finfo
.symbuf
!= NULL
)
10309 free (finfo
.symbuf
);
10310 if (finfo
.symshndxbuf
!= NULL
)
10311 free (finfo
.symshndxbuf
);
10312 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10314 if ((o
->flags
& SEC_RELOC
) != 0
10315 && elf_section_data (o
)->rel_hashes
!= NULL
)
10316 free (elf_section_data (o
)->rel_hashes
);
10319 elf_tdata (abfd
)->linker
= TRUE
;
10323 bfd_byte
*contents
= bfd_malloc (attr_size
);
10324 if (contents
== NULL
)
10326 bfd_elf_set_obj_attr_contents (abfd
, contents
, attr_size
);
10327 bfd_set_section_contents (abfd
, attr_section
, contents
, 0, attr_size
);
10334 if (finfo
.symstrtab
!= NULL
)
10335 _bfd_stringtab_free (finfo
.symstrtab
);
10336 if (finfo
.contents
!= NULL
)
10337 free (finfo
.contents
);
10338 if (finfo
.external_relocs
!= NULL
)
10339 free (finfo
.external_relocs
);
10340 if (finfo
.internal_relocs
!= NULL
)
10341 free (finfo
.internal_relocs
);
10342 if (finfo
.external_syms
!= NULL
)
10343 free (finfo
.external_syms
);
10344 if (finfo
.locsym_shndx
!= NULL
)
10345 free (finfo
.locsym_shndx
);
10346 if (finfo
.internal_syms
!= NULL
)
10347 free (finfo
.internal_syms
);
10348 if (finfo
.indices
!= NULL
)
10349 free (finfo
.indices
);
10350 if (finfo
.sections
!= NULL
)
10351 free (finfo
.sections
);
10352 if (finfo
.symbuf
!= NULL
)
10353 free (finfo
.symbuf
);
10354 if (finfo
.symshndxbuf
!= NULL
)
10355 free (finfo
.symshndxbuf
);
10356 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
10358 if ((o
->flags
& SEC_RELOC
) != 0
10359 && elf_section_data (o
)->rel_hashes
!= NULL
)
10360 free (elf_section_data (o
)->rel_hashes
);
10366 /* Garbage collect unused sections. */
10368 /* Default gc_mark_hook. */
10371 _bfd_elf_gc_mark_hook (asection
*sec
,
10372 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10373 Elf_Internal_Rela
*rel ATTRIBUTE_UNUSED
,
10374 struct elf_link_hash_entry
*h
,
10375 Elf_Internal_Sym
*sym
)
10379 switch (h
->root
.type
)
10381 case bfd_link_hash_defined
:
10382 case bfd_link_hash_defweak
:
10383 return h
->root
.u
.def
.section
;
10385 case bfd_link_hash_common
:
10386 return h
->root
.u
.c
.p
->section
;
10393 return bfd_section_from_elf_index (sec
->owner
, sym
->st_shndx
);
10398 /* The mark phase of garbage collection. For a given section, mark
10399 it and any sections in this section's group, and all the sections
10400 which define symbols to which it refers. */
10403 _bfd_elf_gc_mark (struct bfd_link_info
*info
,
10405 elf_gc_mark_hook_fn gc_mark_hook
)
10409 asection
*group_sec
;
10413 /* Mark all the sections in the group. */
10414 group_sec
= elf_section_data (sec
)->next_in_group
;
10415 if (group_sec
&& !group_sec
->gc_mark
)
10416 if (!_bfd_elf_gc_mark (info
, group_sec
, gc_mark_hook
))
10419 /* Look through the section relocs. */
10421 is_eh
= strcmp (sec
->name
, ".eh_frame") == 0;
10422 if ((sec
->flags
& SEC_RELOC
) != 0 && sec
->reloc_count
> 0)
10424 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
10425 Elf_Internal_Shdr
*symtab_hdr
;
10426 struct elf_link_hash_entry
**sym_hashes
;
10429 bfd
*input_bfd
= sec
->owner
;
10430 const struct elf_backend_data
*bed
= get_elf_backend_data (input_bfd
);
10431 Elf_Internal_Sym
*isym
= NULL
;
10434 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
10435 sym_hashes
= elf_sym_hashes (input_bfd
);
10437 /* Read the local symbols. */
10438 if (elf_bad_symtab (input_bfd
))
10440 nlocsyms
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
10444 extsymoff
= nlocsyms
= symtab_hdr
->sh_info
;
10446 isym
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
10447 if (isym
== NULL
&& nlocsyms
!= 0)
10449 isym
= bfd_elf_get_elf_syms (input_bfd
, symtab_hdr
, nlocsyms
, 0,
10455 /* Read the relocations. */
10456 relstart
= _bfd_elf_link_read_relocs (input_bfd
, sec
, NULL
, NULL
,
10457 info
->keep_memory
);
10458 if (relstart
== NULL
)
10463 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
10465 if (bed
->s
->arch_size
== 32)
10470 for (rel
= relstart
; rel
< relend
; rel
++)
10472 unsigned long r_symndx
;
10474 struct elf_link_hash_entry
*h
;
10476 r_symndx
= rel
->r_info
>> r_sym_shift
;
10480 if (r_symndx
>= nlocsyms
10481 || ELF_ST_BIND (isym
[r_symndx
].st_info
) != STB_LOCAL
)
10483 h
= sym_hashes
[r_symndx
- extsymoff
];
10484 while (h
->root
.type
== bfd_link_hash_indirect
10485 || h
->root
.type
== bfd_link_hash_warning
)
10486 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10487 rsec
= (*gc_mark_hook
) (sec
, info
, rel
, h
, NULL
);
10491 rsec
= (*gc_mark_hook
) (sec
, info
, rel
, NULL
, &isym
[r_symndx
]);
10494 if (rsec
&& !rsec
->gc_mark
)
10496 if (bfd_get_flavour (rsec
->owner
) != bfd_target_elf_flavour
)
10499 rsec
->gc_mark_from_eh
= 1;
10500 else if (!_bfd_elf_gc_mark (info
, rsec
, gc_mark_hook
))
10509 if (elf_section_data (sec
)->relocs
!= relstart
)
10512 if (isym
!= NULL
&& symtab_hdr
->contents
!= (unsigned char *) isym
)
10514 if (! info
->keep_memory
)
10517 symtab_hdr
->contents
= (unsigned char *) isym
;
10524 /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */
10526 struct elf_gc_sweep_symbol_info
10528 struct bfd_link_info
*info
;
10529 void (*hide_symbol
) (struct bfd_link_info
*, struct elf_link_hash_entry
*,
10534 elf_gc_sweep_symbol (struct elf_link_hash_entry
*h
, void *data
)
10536 if (h
->root
.type
== bfd_link_hash_warning
)
10537 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10539 if ((h
->root
.type
== bfd_link_hash_defined
10540 || h
->root
.type
== bfd_link_hash_defweak
)
10541 && !h
->root
.u
.def
.section
->gc_mark
10542 && !(h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
))
10544 struct elf_gc_sweep_symbol_info
*inf
= data
;
10545 (*inf
->hide_symbol
) (inf
->info
, h
, TRUE
);
10551 /* The sweep phase of garbage collection. Remove all garbage sections. */
10553 typedef bfd_boolean (*gc_sweep_hook_fn
)
10554 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
10557 elf_gc_sweep (bfd
*abfd
, struct bfd_link_info
*info
)
10560 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10561 gc_sweep_hook_fn gc_sweep_hook
= bed
->gc_sweep_hook
;
10562 unsigned long section_sym_count
;
10563 struct elf_gc_sweep_symbol_info sweep_info
;
10565 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10569 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
10572 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
10574 /* Keep debug and special sections. */
10575 if ((o
->flags
& (SEC_DEBUGGING
| SEC_LINKER_CREATED
)) != 0
10576 || (o
->flags
& (SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
)) == 0)
10582 /* Skip sweeping sections already excluded. */
10583 if (o
->flags
& SEC_EXCLUDE
)
10586 /* Since this is early in the link process, it is simple
10587 to remove a section from the output. */
10588 o
->flags
|= SEC_EXCLUDE
;
10590 if (info
->print_gc_sections
&& o
->size
!= 0)
10591 _bfd_error_handler (_("Removing unused section '%s' in file '%B'"), sub
, o
->name
);
10593 /* But we also have to update some of the relocation
10594 info we collected before. */
10596 && (o
->flags
& SEC_RELOC
) != 0
10597 && o
->reloc_count
> 0
10598 && !bfd_is_abs_section (o
->output_section
))
10600 Elf_Internal_Rela
*internal_relocs
;
10604 = _bfd_elf_link_read_relocs (o
->owner
, o
, NULL
, NULL
,
10605 info
->keep_memory
);
10606 if (internal_relocs
== NULL
)
10609 r
= (*gc_sweep_hook
) (o
->owner
, info
, o
, internal_relocs
);
10611 if (elf_section_data (o
)->relocs
!= internal_relocs
)
10612 free (internal_relocs
);
10620 /* Remove the symbols that were in the swept sections from the dynamic
10621 symbol table. GCFIXME: Anyone know how to get them out of the
10622 static symbol table as well? */
10623 sweep_info
.info
= info
;
10624 sweep_info
.hide_symbol
= bed
->elf_backend_hide_symbol
;
10625 elf_link_hash_traverse (elf_hash_table (info
), elf_gc_sweep_symbol
,
10628 _bfd_elf_link_renumber_dynsyms (abfd
, info
, §ion_sym_count
);
10632 /* Propagate collected vtable information. This is called through
10633 elf_link_hash_traverse. */
10636 elf_gc_propagate_vtable_entries_used (struct elf_link_hash_entry
*h
, void *okp
)
10638 if (h
->root
.type
== bfd_link_hash_warning
)
10639 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10641 /* Those that are not vtables. */
10642 if (h
->vtable
== NULL
|| h
->vtable
->parent
== NULL
)
10645 /* Those vtables that do not have parents, we cannot merge. */
10646 if (h
->vtable
->parent
== (struct elf_link_hash_entry
*) -1)
10649 /* If we've already been done, exit. */
10650 if (h
->vtable
->used
&& h
->vtable
->used
[-1])
10653 /* Make sure the parent's table is up to date. */
10654 elf_gc_propagate_vtable_entries_used (h
->vtable
->parent
, okp
);
10656 if (h
->vtable
->used
== NULL
)
10658 /* None of this table's entries were referenced. Re-use the
10660 h
->vtable
->used
= h
->vtable
->parent
->vtable
->used
;
10661 h
->vtable
->size
= h
->vtable
->parent
->vtable
->size
;
10666 bfd_boolean
*cu
, *pu
;
10668 /* Or the parent's entries into ours. */
10669 cu
= h
->vtable
->used
;
10671 pu
= h
->vtable
->parent
->vtable
->used
;
10674 const struct elf_backend_data
*bed
;
10675 unsigned int log_file_align
;
10677 bed
= get_elf_backend_data (h
->root
.u
.def
.section
->owner
);
10678 log_file_align
= bed
->s
->log_file_align
;
10679 n
= h
->vtable
->parent
->vtable
->size
>> log_file_align
;
10694 elf_gc_smash_unused_vtentry_relocs (struct elf_link_hash_entry
*h
, void *okp
)
10697 bfd_vma hstart
, hend
;
10698 Elf_Internal_Rela
*relstart
, *relend
, *rel
;
10699 const struct elf_backend_data
*bed
;
10700 unsigned int log_file_align
;
10702 if (h
->root
.type
== bfd_link_hash_warning
)
10703 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10705 /* Take care of both those symbols that do not describe vtables as
10706 well as those that are not loaded. */
10707 if (h
->vtable
== NULL
|| h
->vtable
->parent
== NULL
)
10710 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
10711 || h
->root
.type
== bfd_link_hash_defweak
);
10713 sec
= h
->root
.u
.def
.section
;
10714 hstart
= h
->root
.u
.def
.value
;
10715 hend
= hstart
+ h
->size
;
10717 relstart
= _bfd_elf_link_read_relocs (sec
->owner
, sec
, NULL
, NULL
, TRUE
);
10719 return *(bfd_boolean
*) okp
= FALSE
;
10720 bed
= get_elf_backend_data (sec
->owner
);
10721 log_file_align
= bed
->s
->log_file_align
;
10723 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
10725 for (rel
= relstart
; rel
< relend
; ++rel
)
10726 if (rel
->r_offset
>= hstart
&& rel
->r_offset
< hend
)
10728 /* If the entry is in use, do nothing. */
10729 if (h
->vtable
->used
10730 && (rel
->r_offset
- hstart
) < h
->vtable
->size
)
10732 bfd_vma entry
= (rel
->r_offset
- hstart
) >> log_file_align
;
10733 if (h
->vtable
->used
[entry
])
10736 /* Otherwise, kill it. */
10737 rel
->r_offset
= rel
->r_info
= rel
->r_addend
= 0;
10743 /* Mark sections containing dynamically referenced symbols. When
10744 building shared libraries, we must assume that any visible symbol is
10748 bfd_elf_gc_mark_dynamic_ref_symbol (struct elf_link_hash_entry
*h
, void *inf
)
10750 struct bfd_link_info
*info
= (struct bfd_link_info
*) inf
;
10752 if (h
->root
.type
== bfd_link_hash_warning
)
10753 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
10755 if ((h
->root
.type
== bfd_link_hash_defined
10756 || h
->root
.type
== bfd_link_hash_defweak
)
10758 || (!info
->executable
10760 && ELF_ST_VISIBILITY (h
->other
) != STV_INTERNAL
10761 && ELF_ST_VISIBILITY (h
->other
) != STV_HIDDEN
)))
10762 h
->root
.u
.def
.section
->flags
|= SEC_KEEP
;
10767 /* Do mark and sweep of unused sections. */
10770 bfd_elf_gc_sections (bfd
*abfd
, struct bfd_link_info
*info
)
10772 bfd_boolean ok
= TRUE
;
10774 elf_gc_mark_hook_fn gc_mark_hook
;
10775 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10777 if (!bed
->can_gc_sections
10778 || info
->relocatable
10779 || info
->emitrelocations
10780 || !is_elf_hash_table (info
->hash
))
10782 (*_bfd_error_handler
)(_("Warning: gc-sections option ignored"));
10786 /* Apply transitive closure to the vtable entry usage info. */
10787 elf_link_hash_traverse (elf_hash_table (info
),
10788 elf_gc_propagate_vtable_entries_used
,
10793 /* Kill the vtable relocations that were not used. */
10794 elf_link_hash_traverse (elf_hash_table (info
),
10795 elf_gc_smash_unused_vtentry_relocs
,
10800 /* Mark dynamically referenced symbols. */
10801 if (elf_hash_table (info
)->dynamic_sections_created
)
10802 elf_link_hash_traverse (elf_hash_table (info
),
10803 bed
->gc_mark_dynamic_ref
,
10806 /* Grovel through relocs to find out who stays ... */
10807 gc_mark_hook
= bed
->gc_mark_hook
;
10808 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10812 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
10815 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
10816 if ((o
->flags
& (SEC_EXCLUDE
| SEC_KEEP
)) == SEC_KEEP
&& !o
->gc_mark
)
10817 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
10821 /* Allow the backend to mark additional target specific sections. */
10822 if (bed
->gc_mark_extra_sections
)
10823 bed
->gc_mark_extra_sections(info
, gc_mark_hook
);
10825 /* ... again for sections marked from eh_frame. */
10826 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
10830 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
10833 /* Keep .gcc_except_table.* if the associated .text.* (or the
10834 associated .gnu.linkonce.t.* if .text.* doesn't exist) is
10835 marked. This isn't very nice, but the proper solution,
10836 splitting .eh_frame up and using comdat doesn't pan out
10837 easily due to needing special relocs to handle the
10838 difference of two symbols in separate sections.
10839 Don't keep code sections referenced by .eh_frame. */
10840 #define TEXT_PREFIX ".text."
10841 #define TEXT_PREFIX2 ".gnu.linkonce.t."
10842 #define GCC_EXCEPT_TABLE_PREFIX ".gcc_except_table."
10843 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
10844 if (!o
->gc_mark
&& o
->gc_mark_from_eh
&& (o
->flags
& SEC_CODE
) == 0)
10846 if (CONST_STRNEQ (o
->name
, GCC_EXCEPT_TABLE_PREFIX
))
10849 const char *sec_name
;
10851 unsigned o_name_prefix_len
, fn_name_prefix_len
, tmp
;
10853 o_name_prefix_len
= strlen (GCC_EXCEPT_TABLE_PREFIX
);
10854 sec_name
= o
->name
+ o_name_prefix_len
;
10855 fn_name_prefix_len
= strlen (TEXT_PREFIX
);
10856 tmp
= strlen (TEXT_PREFIX2
);
10857 if (tmp
> fn_name_prefix_len
)
10858 fn_name_prefix_len
= tmp
;
10860 = bfd_malloc (fn_name_prefix_len
+ strlen (sec_name
) + 1);
10861 if (fn_name
== NULL
)
10864 /* Try the first prefix. */
10865 sprintf (fn_name
, "%s%s", TEXT_PREFIX
, sec_name
);
10866 fn_text
= bfd_get_section_by_name (sub
, fn_name
);
10868 /* Try the second prefix. */
10869 if (fn_text
== NULL
)
10871 sprintf (fn_name
, "%s%s", TEXT_PREFIX2
, sec_name
);
10872 fn_text
= bfd_get_section_by_name (sub
, fn_name
);
10876 if (fn_text
== NULL
|| !fn_text
->gc_mark
)
10880 /* If not using specially named exception table section,
10881 then keep whatever we are using. */
10882 if (!_bfd_elf_gc_mark (info
, o
, gc_mark_hook
))
10887 /* ... and mark SEC_EXCLUDE for those that go. */
10888 return elf_gc_sweep (abfd
, info
);
10891 /* Called from check_relocs to record the existence of a VTINHERIT reloc. */
10894 bfd_elf_gc_record_vtinherit (bfd
*abfd
,
10896 struct elf_link_hash_entry
*h
,
10899 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
10900 struct elf_link_hash_entry
**search
, *child
;
10901 bfd_size_type extsymcount
;
10902 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10904 /* The sh_info field of the symtab header tells us where the
10905 external symbols start. We don't care about the local symbols at
10907 extsymcount
= elf_tdata (abfd
)->symtab_hdr
.sh_size
/ bed
->s
->sizeof_sym
;
10908 if (!elf_bad_symtab (abfd
))
10909 extsymcount
-= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
10911 sym_hashes
= elf_sym_hashes (abfd
);
10912 sym_hashes_end
= sym_hashes
+ extsymcount
;
10914 /* Hunt down the child symbol, which is in this section at the same
10915 offset as the relocation. */
10916 for (search
= sym_hashes
; search
!= sym_hashes_end
; ++search
)
10918 if ((child
= *search
) != NULL
10919 && (child
->root
.type
== bfd_link_hash_defined
10920 || child
->root
.type
== bfd_link_hash_defweak
)
10921 && child
->root
.u
.def
.section
== sec
10922 && child
->root
.u
.def
.value
== offset
)
10926 (*_bfd_error_handler
) ("%B: %A+%lu: No symbol found for INHERIT",
10927 abfd
, sec
, (unsigned long) offset
);
10928 bfd_set_error (bfd_error_invalid_operation
);
10932 if (!child
->vtable
)
10934 child
->vtable
= bfd_zalloc (abfd
, sizeof (*child
->vtable
));
10935 if (!child
->vtable
)
10940 /* This *should* only be the absolute section. It could potentially
10941 be that someone has defined a non-global vtable though, which
10942 would be bad. It isn't worth paging in the local symbols to be
10943 sure though; that case should simply be handled by the assembler. */
10945 child
->vtable
->parent
= (struct elf_link_hash_entry
*) -1;
10948 child
->vtable
->parent
= h
;
10953 /* Called from check_relocs to record the existence of a VTENTRY reloc. */
10956 bfd_elf_gc_record_vtentry (bfd
*abfd ATTRIBUTE_UNUSED
,
10957 asection
*sec ATTRIBUTE_UNUSED
,
10958 struct elf_link_hash_entry
*h
,
10961 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
10962 unsigned int log_file_align
= bed
->s
->log_file_align
;
10966 h
->vtable
= bfd_zalloc (abfd
, sizeof (*h
->vtable
));
10971 if (addend
>= h
->vtable
->size
)
10973 size_t size
, bytes
, file_align
;
10974 bfd_boolean
*ptr
= h
->vtable
->used
;
10976 /* While the symbol is undefined, we have to be prepared to handle
10978 file_align
= 1 << log_file_align
;
10979 if (h
->root
.type
== bfd_link_hash_undefined
)
10980 size
= addend
+ file_align
;
10984 if (addend
>= size
)
10986 /* Oops! We've got a reference past the defined end of
10987 the table. This is probably a bug -- shall we warn? */
10988 size
= addend
+ file_align
;
10991 size
= (size
+ file_align
- 1) & -file_align
;
10993 /* Allocate one extra entry for use as a "done" flag for the
10994 consolidation pass. */
10995 bytes
= ((size
>> log_file_align
) + 1) * sizeof (bfd_boolean
);
10999 ptr
= bfd_realloc (ptr
- 1, bytes
);
11005 oldbytes
= (((h
->vtable
->size
>> log_file_align
) + 1)
11006 * sizeof (bfd_boolean
));
11007 memset (((char *) ptr
) + oldbytes
, 0, bytes
- oldbytes
);
11011 ptr
= bfd_zmalloc (bytes
);
11016 /* And arrange for that done flag to be at index -1. */
11017 h
->vtable
->used
= ptr
+ 1;
11018 h
->vtable
->size
= size
;
11021 h
->vtable
->used
[addend
>> log_file_align
] = TRUE
;
11026 struct alloc_got_off_arg
{
11028 unsigned int got_elt_size
;
11031 /* We need a special top-level link routine to convert got reference counts
11032 to real got offsets. */
11035 elf_gc_allocate_got_offsets (struct elf_link_hash_entry
*h
, void *arg
)
11037 struct alloc_got_off_arg
*gofarg
= arg
;
11039 if (h
->root
.type
== bfd_link_hash_warning
)
11040 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11042 if (h
->got
.refcount
> 0)
11044 h
->got
.offset
= gofarg
->gotoff
;
11045 gofarg
->gotoff
+= gofarg
->got_elt_size
;
11048 h
->got
.offset
= (bfd_vma
) -1;
11053 /* And an accompanying bit to work out final got entry offsets once
11054 we're done. Should be called from final_link. */
11057 bfd_elf_gc_common_finalize_got_offsets (bfd
*abfd
,
11058 struct bfd_link_info
*info
)
11061 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11063 unsigned int got_elt_size
= bed
->s
->arch_size
/ 8;
11064 struct alloc_got_off_arg gofarg
;
11066 if (! is_elf_hash_table (info
->hash
))
11069 /* The GOT offset is relative to the .got section, but the GOT header is
11070 put into the .got.plt section, if the backend uses it. */
11071 if (bed
->want_got_plt
)
11074 gotoff
= bed
->got_header_size
;
11076 /* Do the local .got entries first. */
11077 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
11079 bfd_signed_vma
*local_got
;
11080 bfd_size_type j
, locsymcount
;
11081 Elf_Internal_Shdr
*symtab_hdr
;
11083 if (bfd_get_flavour (i
) != bfd_target_elf_flavour
)
11086 local_got
= elf_local_got_refcounts (i
);
11090 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
11091 if (elf_bad_symtab (i
))
11092 locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
11094 locsymcount
= symtab_hdr
->sh_info
;
11096 for (j
= 0; j
< locsymcount
; ++j
)
11098 if (local_got
[j
] > 0)
11100 local_got
[j
] = gotoff
;
11101 gotoff
+= got_elt_size
;
11104 local_got
[j
] = (bfd_vma
) -1;
11108 /* Then the global .got entries. .plt refcounts are handled by
11109 adjust_dynamic_symbol */
11110 gofarg
.gotoff
= gotoff
;
11111 gofarg
.got_elt_size
= got_elt_size
;
11112 elf_link_hash_traverse (elf_hash_table (info
),
11113 elf_gc_allocate_got_offsets
,
11118 /* Many folk need no more in the way of final link than this, once
11119 got entry reference counting is enabled. */
11122 bfd_elf_gc_common_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11124 if (!bfd_elf_gc_common_finalize_got_offsets (abfd
, info
))
11127 /* Invoke the regular ELF backend linker to do all the work. */
11128 return bfd_elf_final_link (abfd
, info
);
11132 bfd_elf_reloc_symbol_deleted_p (bfd_vma offset
, void *cookie
)
11134 struct elf_reloc_cookie
*rcookie
= cookie
;
11136 if (rcookie
->bad_symtab
)
11137 rcookie
->rel
= rcookie
->rels
;
11139 for (; rcookie
->rel
< rcookie
->relend
; rcookie
->rel
++)
11141 unsigned long r_symndx
;
11143 if (! rcookie
->bad_symtab
)
11144 if (rcookie
->rel
->r_offset
> offset
)
11146 if (rcookie
->rel
->r_offset
!= offset
)
11149 r_symndx
= rcookie
->rel
->r_info
>> rcookie
->r_sym_shift
;
11150 if (r_symndx
== SHN_UNDEF
)
11153 if (r_symndx
>= rcookie
->locsymcount
11154 || ELF_ST_BIND (rcookie
->locsyms
[r_symndx
].st_info
) != STB_LOCAL
)
11156 struct elf_link_hash_entry
*h
;
11158 h
= rcookie
->sym_hashes
[r_symndx
- rcookie
->extsymoff
];
11160 while (h
->root
.type
== bfd_link_hash_indirect
11161 || h
->root
.type
== bfd_link_hash_warning
)
11162 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
11164 if ((h
->root
.type
== bfd_link_hash_defined
11165 || h
->root
.type
== bfd_link_hash_defweak
)
11166 && elf_discarded_section (h
->root
.u
.def
.section
))
11173 /* It's not a relocation against a global symbol,
11174 but it could be a relocation against a local
11175 symbol for a discarded section. */
11177 Elf_Internal_Sym
*isym
;
11179 /* Need to: get the symbol; get the section. */
11180 isym
= &rcookie
->locsyms
[r_symndx
];
11181 if (isym
->st_shndx
< SHN_LORESERVE
|| isym
->st_shndx
> SHN_HIRESERVE
)
11183 isec
= bfd_section_from_elf_index (rcookie
->abfd
, isym
->st_shndx
);
11184 if (isec
!= NULL
&& elf_discarded_section (isec
))
11193 /* Discard unneeded references to discarded sections.
11194 Returns TRUE if any section's size was changed. */
11195 /* This function assumes that the relocations are in sorted order,
11196 which is true for all known assemblers. */
11199 bfd_elf_discard_info (bfd
*output_bfd
, struct bfd_link_info
*info
)
11201 struct elf_reloc_cookie cookie
;
11202 asection
*stab
, *eh
;
11203 Elf_Internal_Shdr
*symtab_hdr
;
11204 const struct elf_backend_data
*bed
;
11206 unsigned int count
;
11207 bfd_boolean ret
= FALSE
;
11209 if (info
->traditional_format
11210 || !is_elf_hash_table (info
->hash
))
11213 for (abfd
= info
->input_bfds
; abfd
!= NULL
; abfd
= abfd
->link_next
)
11215 if (bfd_get_flavour (abfd
) != bfd_target_elf_flavour
)
11218 bed
= get_elf_backend_data (abfd
);
11220 if ((abfd
->flags
& DYNAMIC
) != 0)
11224 if (!info
->relocatable
)
11226 eh
= bfd_get_section_by_name (abfd
, ".eh_frame");
11229 || bfd_is_abs_section (eh
->output_section
)))
11233 stab
= bfd_get_section_by_name (abfd
, ".stab");
11235 && (stab
->size
== 0
11236 || bfd_is_abs_section (stab
->output_section
)
11237 || stab
->sec_info_type
!= ELF_INFO_TYPE_STABS
))
11242 && bed
->elf_backend_discard_info
== NULL
)
11245 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11246 cookie
.abfd
= abfd
;
11247 cookie
.sym_hashes
= elf_sym_hashes (abfd
);
11248 cookie
.bad_symtab
= elf_bad_symtab (abfd
);
11249 if (cookie
.bad_symtab
)
11251 cookie
.locsymcount
= symtab_hdr
->sh_size
/ bed
->s
->sizeof_sym
;
11252 cookie
.extsymoff
= 0;
11256 cookie
.locsymcount
= symtab_hdr
->sh_info
;
11257 cookie
.extsymoff
= symtab_hdr
->sh_info
;
11260 if (bed
->s
->arch_size
== 32)
11261 cookie
.r_sym_shift
= 8;
11263 cookie
.r_sym_shift
= 32;
11265 cookie
.locsyms
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
11266 if (cookie
.locsyms
== NULL
&& cookie
.locsymcount
!= 0)
11268 cookie
.locsyms
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
11269 cookie
.locsymcount
, 0,
11271 if (cookie
.locsyms
== NULL
)
11273 info
->callbacks
->einfo (_("%P%X: can not read symbols: %E\n"));
11280 cookie
.rels
= NULL
;
11281 count
= stab
->reloc_count
;
11283 cookie
.rels
= _bfd_elf_link_read_relocs (abfd
, stab
, NULL
, NULL
,
11284 info
->keep_memory
);
11285 if (cookie
.rels
!= NULL
)
11287 cookie
.rel
= cookie
.rels
;
11288 cookie
.relend
= cookie
.rels
;
11289 cookie
.relend
+= count
* bed
->s
->int_rels_per_ext_rel
;
11290 if (_bfd_discard_section_stabs (abfd
, stab
,
11291 elf_section_data (stab
)->sec_info
,
11292 bfd_elf_reloc_symbol_deleted_p
,
11295 if (elf_section_data (stab
)->relocs
!= cookie
.rels
)
11296 free (cookie
.rels
);
11302 cookie
.rels
= NULL
;
11303 count
= eh
->reloc_count
;
11305 cookie
.rels
= _bfd_elf_link_read_relocs (abfd
, eh
, NULL
, NULL
,
11306 info
->keep_memory
);
11307 cookie
.rel
= cookie
.rels
;
11308 cookie
.relend
= cookie
.rels
;
11309 if (cookie
.rels
!= NULL
)
11310 cookie
.relend
+= count
* bed
->s
->int_rels_per_ext_rel
;
11312 if (_bfd_elf_discard_section_eh_frame (abfd
, info
, eh
,
11313 bfd_elf_reloc_symbol_deleted_p
,
11317 if (cookie
.rels
!= NULL
11318 && elf_section_data (eh
)->relocs
!= cookie
.rels
)
11319 free (cookie
.rels
);
11322 if (bed
->elf_backend_discard_info
!= NULL
11323 && (*bed
->elf_backend_discard_info
) (abfd
, &cookie
, info
))
11326 if (cookie
.locsyms
!= NULL
11327 && symtab_hdr
->contents
!= (unsigned char *) cookie
.locsyms
)
11329 if (! info
->keep_memory
)
11330 free (cookie
.locsyms
);
11332 symtab_hdr
->contents
= (unsigned char *) cookie
.locsyms
;
11336 if (info
->eh_frame_hdr
11337 && !info
->relocatable
11338 && _bfd_elf_discard_section_eh_frame_hdr (output_bfd
, info
))
11345 _bfd_elf_section_already_linked (bfd
*abfd
, struct bfd_section
*sec
,
11346 struct bfd_link_info
*info
)
11349 const char *name
, *p
;
11350 struct bfd_section_already_linked
*l
;
11351 struct bfd_section_already_linked_hash_entry
*already_linked_list
;
11353 if (sec
->output_section
== bfd_abs_section_ptr
)
11356 flags
= sec
->flags
;
11358 /* Return if it isn't a linkonce section. A comdat group section
11359 also has SEC_LINK_ONCE set. */
11360 if ((flags
& SEC_LINK_ONCE
) == 0)
11363 /* Don't put group member sections on our list of already linked
11364 sections. They are handled as a group via their group section. */
11365 if (elf_sec_group (sec
) != NULL
)
11368 /* FIXME: When doing a relocatable link, we may have trouble
11369 copying relocations in other sections that refer to local symbols
11370 in the section being discarded. Those relocations will have to
11371 be converted somehow; as of this writing I'm not sure that any of
11372 the backends handle that correctly.
11374 It is tempting to instead not discard link once sections when
11375 doing a relocatable link (technically, they should be discarded
11376 whenever we are building constructors). However, that fails,
11377 because the linker winds up combining all the link once sections
11378 into a single large link once section, which defeats the purpose
11379 of having link once sections in the first place.
11381 Also, not merging link once sections in a relocatable link
11382 causes trouble for MIPS ELF, which relies on link once semantics
11383 to handle the .reginfo section correctly. */
11385 name
= bfd_get_section_name (abfd
, sec
);
11387 if (CONST_STRNEQ (name
, ".gnu.linkonce.")
11388 && (p
= strchr (name
+ sizeof (".gnu.linkonce.") - 1, '.')) != NULL
)
11393 already_linked_list
= bfd_section_already_linked_table_lookup (p
);
11395 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
11397 /* We may have 2 different types of sections on the list: group
11398 sections and linkonce sections. Match like sections. */
11399 if ((flags
& SEC_GROUP
) == (l
->sec
->flags
& SEC_GROUP
)
11400 && strcmp (name
, l
->sec
->name
) == 0
11401 && bfd_coff_get_comdat_section (l
->sec
->owner
, l
->sec
) == NULL
)
11403 /* The section has already been linked. See if we should
11404 issue a warning. */
11405 switch (flags
& SEC_LINK_DUPLICATES
)
11410 case SEC_LINK_DUPLICATES_DISCARD
:
11413 case SEC_LINK_DUPLICATES_ONE_ONLY
:
11414 (*_bfd_error_handler
)
11415 (_("%B: ignoring duplicate section `%A'"),
11419 case SEC_LINK_DUPLICATES_SAME_SIZE
:
11420 if (sec
->size
!= l
->sec
->size
)
11421 (*_bfd_error_handler
)
11422 (_("%B: duplicate section `%A' has different size"),
11426 case SEC_LINK_DUPLICATES_SAME_CONTENTS
:
11427 if (sec
->size
!= l
->sec
->size
)
11428 (*_bfd_error_handler
)
11429 (_("%B: duplicate section `%A' has different size"),
11431 else if (sec
->size
!= 0)
11433 bfd_byte
*sec_contents
, *l_sec_contents
;
11435 if (!bfd_malloc_and_get_section (abfd
, sec
, &sec_contents
))
11436 (*_bfd_error_handler
)
11437 (_("%B: warning: could not read contents of section `%A'"),
11439 else if (!bfd_malloc_and_get_section (l
->sec
->owner
, l
->sec
,
11441 (*_bfd_error_handler
)
11442 (_("%B: warning: could not read contents of section `%A'"),
11443 l
->sec
->owner
, l
->sec
);
11444 else if (memcmp (sec_contents
, l_sec_contents
, sec
->size
) != 0)
11445 (*_bfd_error_handler
)
11446 (_("%B: warning: duplicate section `%A' has different contents"),
11450 free (sec_contents
);
11451 if (l_sec_contents
)
11452 free (l_sec_contents
);
11457 /* Set the output_section field so that lang_add_section
11458 does not create a lang_input_section structure for this
11459 section. Since there might be a symbol in the section
11460 being discarded, we must retain a pointer to the section
11461 which we are really going to use. */
11462 sec
->output_section
= bfd_abs_section_ptr
;
11463 sec
->kept_section
= l
->sec
;
11465 if (flags
& SEC_GROUP
)
11467 asection
*first
= elf_next_in_group (sec
);
11468 asection
*s
= first
;
11472 s
->output_section
= bfd_abs_section_ptr
;
11473 /* Record which group discards it. */
11474 s
->kept_section
= l
->sec
;
11475 s
= elf_next_in_group (s
);
11476 /* These lists are circular. */
11486 /* A single member comdat group section may be discarded by a
11487 linkonce section and vice versa. */
11489 if ((flags
& SEC_GROUP
) != 0)
11491 asection
*first
= elf_next_in_group (sec
);
11493 if (first
!= NULL
&& elf_next_in_group (first
) == first
)
11494 /* Check this single member group against linkonce sections. */
11495 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
11496 if ((l
->sec
->flags
& SEC_GROUP
) == 0
11497 && bfd_coff_get_comdat_section (l
->sec
->owner
, l
->sec
) == NULL
11498 && bfd_elf_match_symbols_in_sections (l
->sec
, first
, info
))
11500 first
->output_section
= bfd_abs_section_ptr
;
11501 first
->kept_section
= l
->sec
;
11502 sec
->output_section
= bfd_abs_section_ptr
;
11507 /* Check this linkonce section against single member groups. */
11508 for (l
= already_linked_list
->entry
; l
!= NULL
; l
= l
->next
)
11509 if (l
->sec
->flags
& SEC_GROUP
)
11511 asection
*first
= elf_next_in_group (l
->sec
);
11514 && elf_next_in_group (first
) == first
11515 && bfd_elf_match_symbols_in_sections (first
, sec
, info
))
11517 sec
->output_section
= bfd_abs_section_ptr
;
11518 sec
->kept_section
= first
;
11523 /* This is the first section with this name. Record it. */
11524 bfd_section_already_linked_table_insert (already_linked_list
, sec
);
11528 _bfd_elf_common_definition (Elf_Internal_Sym
*sym
)
11530 return sym
->st_shndx
== SHN_COMMON
;
11534 _bfd_elf_common_section_index (asection
*sec ATTRIBUTE_UNUSED
)
11540 _bfd_elf_common_section (asection
*sec ATTRIBUTE_UNUSED
)
11542 return bfd_com_section_ptr
;