1 /* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
3 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
27 #include "safe-ctype.h"
30 _bfd_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
34 struct elf_link_hash_entry
*h
;
35 struct bfd_link_hash_entry
*bh
;
36 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
39 /* This function may be called more than once. */
40 s
= bfd_get_section_by_name (abfd
, ".got");
41 if (s
!= NULL
&& (s
->flags
& SEC_LINKER_CREATED
) != 0)
44 switch (bed
->s
->arch_size
)
55 bfd_set_error (bfd_error_bad_value
);
59 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
60 | SEC_LINKER_CREATED
);
62 s
= bfd_make_section (abfd
, ".got");
64 || !bfd_set_section_flags (abfd
, s
, flags
)
65 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
68 if (bed
->want_got_plt
)
70 s
= bfd_make_section (abfd
, ".got.plt");
72 || !bfd_set_section_flags (abfd
, s
, flags
)
73 || !bfd_set_section_alignment (abfd
, s
, ptralign
))
77 if (bed
->want_got_sym
)
79 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
80 (or .got.plt) section. We don't do this in the linker script
81 because we don't want to define the symbol if we are not creating
82 a global offset table. */
84 if (!(_bfd_generic_link_add_one_symbol
85 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
86 bed
->got_symbol_offset
, NULL
, FALSE
, bed
->collect
, &bh
)))
88 h
= (struct elf_link_hash_entry
*) bh
;
89 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
92 if (! info
->executable
93 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
96 elf_hash_table (info
)->hgot
= h
;
99 /* The first bit of the global offset table is the header. */
100 s
->_raw_size
+= bed
->got_header_size
+ bed
->got_symbol_offset
;
105 /* Create some sections which will be filled in with dynamic linking
106 information. ABFD is an input file which requires dynamic sections
107 to be created. The dynamic sections take up virtual memory space
108 when the final executable is run, so we need to create them before
109 addresses are assigned to the output sections. We work out the
110 actual contents and size of these sections later. */
113 _bfd_elf_link_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
116 register asection
*s
;
117 struct elf_link_hash_entry
*h
;
118 struct bfd_link_hash_entry
*bh
;
119 const struct elf_backend_data
*bed
;
121 if (! is_elf_hash_table (info
->hash
))
124 if (elf_hash_table (info
)->dynamic_sections_created
)
127 /* Make sure that all dynamic sections use the same input BFD. */
128 if (elf_hash_table (info
)->dynobj
== NULL
)
129 elf_hash_table (info
)->dynobj
= abfd
;
131 abfd
= elf_hash_table (info
)->dynobj
;
133 /* Note that we set the SEC_IN_MEMORY flag for all of these
135 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
136 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
138 /* A dynamically linked executable has a .interp section, but a
139 shared library does not. */
140 if (info
->executable
)
142 s
= bfd_make_section (abfd
, ".interp");
144 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
148 if (! info
->traditional_format
)
150 s
= bfd_make_section (abfd
, ".eh_frame_hdr");
152 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
153 || ! bfd_set_section_alignment (abfd
, s
, 2))
155 elf_hash_table (info
)->eh_info
.hdr_sec
= s
;
158 bed
= get_elf_backend_data (abfd
);
160 /* Create sections to hold version informations. These are removed
161 if they are not needed. */
162 s
= bfd_make_section (abfd
, ".gnu.version_d");
164 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
165 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
168 s
= bfd_make_section (abfd
, ".gnu.version");
170 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
171 || ! bfd_set_section_alignment (abfd
, s
, 1))
174 s
= bfd_make_section (abfd
, ".gnu.version_r");
176 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
177 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
180 s
= bfd_make_section (abfd
, ".dynsym");
182 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
183 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
186 s
= bfd_make_section (abfd
, ".dynstr");
188 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
191 /* Create a strtab to hold the dynamic symbol names. */
192 if (elf_hash_table (info
)->dynstr
== NULL
)
194 elf_hash_table (info
)->dynstr
= _bfd_elf_strtab_init ();
195 if (elf_hash_table (info
)->dynstr
== NULL
)
199 s
= bfd_make_section (abfd
, ".dynamic");
201 || ! bfd_set_section_flags (abfd
, s
, flags
)
202 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
205 /* The special symbol _DYNAMIC is always set to the start of the
206 .dynamic section. This call occurs before we have processed the
207 symbols for any dynamic object, so we don't have to worry about
208 overriding a dynamic definition. We could set _DYNAMIC in a
209 linker script, but we only want to define it if we are, in fact,
210 creating a .dynamic section. We don't want to define it if there
211 is no .dynamic section, since on some ELF platforms the start up
212 code examines it to decide how to initialize the process. */
214 if (! (_bfd_generic_link_add_one_symbol
215 (info
, abfd
, "_DYNAMIC", BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
216 get_elf_backend_data (abfd
)->collect
, &bh
)))
218 h
= (struct elf_link_hash_entry
*) bh
;
219 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
220 h
->type
= STT_OBJECT
;
222 if (! info
->executable
223 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
226 s
= bfd_make_section (abfd
, ".hash");
228 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
229 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
231 elf_section_data (s
)->this_hdr
.sh_entsize
= bed
->s
->sizeof_hash_entry
;
233 /* Let the backend create the rest of the sections. This lets the
234 backend set the right flags. The backend will normally create
235 the .got and .plt sections. */
236 if (! (*bed
->elf_backend_create_dynamic_sections
) (abfd
, info
))
239 elf_hash_table (info
)->dynamic_sections_created
= TRUE
;
244 /* Create dynamic sections when linking against a dynamic object. */
247 _bfd_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
249 flagword flags
, pltflags
;
251 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
253 /* We need to create .plt, .rel[a].plt, .got, .got.plt, .dynbss, and
254 .rel[a].bss sections. */
256 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
257 | SEC_LINKER_CREATED
);
260 pltflags
|= SEC_CODE
;
261 if (bed
->plt_not_loaded
)
262 pltflags
&= ~ (SEC_CODE
| SEC_LOAD
| SEC_HAS_CONTENTS
);
263 if (bed
->plt_readonly
)
264 pltflags
|= SEC_READONLY
;
266 s
= bfd_make_section (abfd
, ".plt");
268 || ! bfd_set_section_flags (abfd
, s
, pltflags
)
269 || ! bfd_set_section_alignment (abfd
, s
, bed
->plt_alignment
))
272 if (bed
->want_plt_sym
)
274 /* Define the symbol _PROCEDURE_LINKAGE_TABLE_ at the start of the
276 struct elf_link_hash_entry
*h
;
277 struct bfd_link_hash_entry
*bh
= NULL
;
279 if (! (_bfd_generic_link_add_one_symbol
280 (info
, abfd
, "_PROCEDURE_LINKAGE_TABLE_", BSF_GLOBAL
, s
, 0, NULL
,
281 FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
283 h
= (struct elf_link_hash_entry
*) bh
;
284 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
285 h
->type
= STT_OBJECT
;
287 if (! info
->executable
288 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
292 s
= bfd_make_section (abfd
,
293 bed
->default_use_rela_p
? ".rela.plt" : ".rel.plt");
295 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
296 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
299 if (! _bfd_elf_create_got_section (abfd
, info
))
302 if (bed
->want_dynbss
)
304 /* The .dynbss section is a place to put symbols which are defined
305 by dynamic objects, are referenced by regular objects, and are
306 not functions. We must allocate space for them in the process
307 image and use a R_*_COPY reloc to tell the dynamic linker to
308 initialize them at run time. The linker script puts the .dynbss
309 section into the .bss section of the final image. */
310 s
= bfd_make_section (abfd
, ".dynbss");
312 || ! bfd_set_section_flags (abfd
, s
, SEC_ALLOC
| SEC_LINKER_CREATED
))
315 /* The .rel[a].bss section holds copy relocs. This section is not
316 normally needed. We need to create it here, though, so that the
317 linker will map it to an output section. We can't just create it
318 only if we need it, because we will not know whether we need it
319 until we have seen all the input files, and the first time the
320 main linker code calls BFD after examining all the input files
321 (size_dynamic_sections) the input sections have already been
322 mapped to the output sections. If the section turns out not to
323 be needed, we can discard it later. We will never need this
324 section when generating a shared object, since they do not use
328 s
= bfd_make_section (abfd
,
329 (bed
->default_use_rela_p
330 ? ".rela.bss" : ".rel.bss"));
332 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
333 || ! bfd_set_section_alignment (abfd
, s
, bed
->s
->log_file_align
))
341 /* Record a new dynamic symbol. We record the dynamic symbols as we
342 read the input files, since we need to have a list of all of them
343 before we can determine the final sizes of the output sections.
344 Note that we may actually call this function even though we are not
345 going to output any dynamic symbols; in some cases we know that a
346 symbol should be in the dynamic symbol table, but only if there is
350 _bfd_elf_link_record_dynamic_symbol (struct bfd_link_info
*info
,
351 struct elf_link_hash_entry
*h
)
353 if (h
->dynindx
== -1)
355 struct elf_strtab_hash
*dynstr
;
360 /* XXX: The ABI draft says the linker must turn hidden and
361 internal symbols into STB_LOCAL symbols when producing the
362 DSO. However, if ld.so honors st_other in the dynamic table,
363 this would not be necessary. */
364 switch (ELF_ST_VISIBILITY (h
->other
))
368 if (h
->root
.type
!= bfd_link_hash_undefined
369 && h
->root
.type
!= bfd_link_hash_undefweak
)
371 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
379 h
->dynindx
= elf_hash_table (info
)->dynsymcount
;
380 ++elf_hash_table (info
)->dynsymcount
;
382 dynstr
= elf_hash_table (info
)->dynstr
;
385 /* Create a strtab to hold the dynamic symbol names. */
386 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
391 /* We don't put any version information in the dynamic string
393 name
= h
->root
.root
.string
;
394 p
= strchr (name
, ELF_VER_CHR
);
396 /* We know that the p points into writable memory. In fact,
397 there are only a few symbols that have read-only names, being
398 those like _GLOBAL_OFFSET_TABLE_ that are created specially
399 by the backends. Most symbols will have names pointing into
400 an ELF string table read from a file, or to objalloc memory. */
403 indx
= _bfd_elf_strtab_add (dynstr
, name
, p
!= NULL
);
408 if (indx
== (bfd_size_type
) -1)
410 h
->dynstr_index
= indx
;
416 /* Record an assignment to a symbol made by a linker script. We need
417 this in case some dynamic object refers to this symbol. */
420 bfd_elf_record_link_assignment (bfd
*output_bfd ATTRIBUTE_UNUSED
,
421 struct bfd_link_info
*info
,
425 struct elf_link_hash_entry
*h
;
427 if (!is_elf_hash_table (info
->hash
))
430 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
, TRUE
, FALSE
);
434 /* Since we're defining the symbol, don't let it seem to have not
435 been defined. record_dynamic_symbol and size_dynamic_sections
436 may depend on this. */
437 if (h
->root
.type
== bfd_link_hash_undefweak
438 || h
->root
.type
== bfd_link_hash_undefined
)
439 h
->root
.type
= bfd_link_hash_new
;
441 if (h
->root
.type
== bfd_link_hash_new
)
442 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
444 /* If this symbol is being provided by the linker script, and it is
445 currently defined by a dynamic object, but not by a regular
446 object, then mark it as undefined so that the generic linker will
447 force the correct value. */
449 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
450 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
451 h
->root
.type
= bfd_link_hash_undefined
;
453 /* If this symbol is not being provided by the linker script, and it is
454 currently defined by a dynamic object, but not by a regular object,
455 then clear out any version information because the symbol will not be
456 associated with the dynamic object any more. */
458 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
459 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
460 h
->verinfo
.verdef
= NULL
;
462 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
464 if (((h
->elf_link_hash_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
465 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0
469 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
472 /* If this is a weak defined symbol, and we know a corresponding
473 real symbol from the same dynamic object, make sure the real
474 symbol is also made into a dynamic symbol. */
475 if (h
->weakdef
!= NULL
476 && h
->weakdef
->dynindx
== -1)
478 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
486 /* Record a new local dynamic symbol. Returns 0 on failure, 1 on
487 success, and 2 on a failure caused by attempting to record a symbol
488 in a discarded section, eg. a discarded link-once section symbol. */
491 elf_link_record_local_dynamic_symbol (struct bfd_link_info
*info
,
496 struct elf_link_local_dynamic_entry
*entry
;
497 struct elf_link_hash_table
*eht
;
498 struct elf_strtab_hash
*dynstr
;
499 unsigned long dynstr_index
;
501 Elf_External_Sym_Shndx eshndx
;
502 char esym
[sizeof (Elf64_External_Sym
)];
504 if (! is_elf_hash_table (info
->hash
))
507 /* See if the entry exists already. */
508 for (entry
= elf_hash_table (info
)->dynlocal
; entry
; entry
= entry
->next
)
509 if (entry
->input_bfd
== input_bfd
&& entry
->input_indx
== input_indx
)
512 amt
= sizeof (*entry
);
513 entry
= bfd_alloc (input_bfd
, amt
);
517 /* Go find the symbol, so that we can find it's name. */
518 if (!bfd_elf_get_elf_syms (input_bfd
, &elf_tdata (input_bfd
)->symtab_hdr
,
519 1, input_indx
, &entry
->isym
, esym
, &eshndx
))
521 bfd_release (input_bfd
, entry
);
525 if (entry
->isym
.st_shndx
!= SHN_UNDEF
526 && (entry
->isym
.st_shndx
< SHN_LORESERVE
527 || entry
->isym
.st_shndx
> SHN_HIRESERVE
))
531 s
= bfd_section_from_elf_index (input_bfd
, entry
->isym
.st_shndx
);
532 if (s
== NULL
|| bfd_is_abs_section (s
->output_section
))
534 /* We can still bfd_release here as nothing has done another
535 bfd_alloc. We can't do this later in this function. */
536 bfd_release (input_bfd
, entry
);
541 name
= (bfd_elf_string_from_elf_section
542 (input_bfd
, elf_tdata (input_bfd
)->symtab_hdr
.sh_link
,
543 entry
->isym
.st_name
));
545 dynstr
= elf_hash_table (info
)->dynstr
;
548 /* Create a strtab to hold the dynamic symbol names. */
549 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_strtab_init ();
554 dynstr_index
= _bfd_elf_strtab_add (dynstr
, name
, FALSE
);
555 if (dynstr_index
== (unsigned long) -1)
557 entry
->isym
.st_name
= dynstr_index
;
559 eht
= elf_hash_table (info
);
561 entry
->next
= eht
->dynlocal
;
562 eht
->dynlocal
= entry
;
563 entry
->input_bfd
= input_bfd
;
564 entry
->input_indx
= input_indx
;
567 /* Whatever binding the symbol had before, it's now local. */
569 = ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (entry
->isym
.st_info
));
571 /* The dynindx will be set at the end of size_dynamic_sections. */
576 /* Return the dynindex of a local dynamic symbol. */
579 _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info
*info
,
583 struct elf_link_local_dynamic_entry
*e
;
585 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
586 if (e
->input_bfd
== input_bfd
&& e
->input_indx
== input_indx
)
591 /* This function is used to renumber the dynamic symbols, if some of
592 them are removed because they are marked as local. This is called
593 via elf_link_hash_traverse. */
596 elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry
*h
,
599 size_t *count
= data
;
601 if (h
->root
.type
== bfd_link_hash_warning
)
602 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
604 if (h
->dynindx
!= -1)
605 h
->dynindx
= ++(*count
);
610 /* Assign dynsym indices. In a shared library we generate a section
611 symbol for each output section, which come first. Next come all of
612 the back-end allocated local dynamic syms, followed by the rest of
613 the global symbols. */
616 _bfd_elf_link_renumber_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
618 unsigned long dynsymcount
= 0;
623 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
624 if ((p
->flags
& SEC_EXCLUDE
) == 0)
625 elf_section_data (p
)->dynindx
= ++dynsymcount
;
628 if (elf_hash_table (info
)->dynlocal
)
630 struct elf_link_local_dynamic_entry
*p
;
631 for (p
= elf_hash_table (info
)->dynlocal
; p
; p
= p
->next
)
632 p
->dynindx
= ++dynsymcount
;
635 elf_link_hash_traverse (elf_hash_table (info
),
636 elf_link_renumber_hash_table_dynsyms
,
639 /* There is an unused NULL entry at the head of the table which
640 we must account for in our count. Unless there weren't any
641 symbols, which means we'll have no table at all. */
642 if (dynsymcount
!= 0)
645 return elf_hash_table (info
)->dynsymcount
= dynsymcount
;
648 /* This function is called when we want to define a new symbol. It
649 handles the various cases which arise when we find a definition in
650 a dynamic object, or when there is already a definition in a
651 dynamic object. The new symbol is described by NAME, SYM, PSEC,
652 and PVALUE. We set SYM_HASH to the hash table entry. We set
653 OVERRIDE if the old symbol is overriding a new definition. We set
654 TYPE_CHANGE_OK if it is OK for the type to change. We set
655 SIZE_CHANGE_OK if it is OK for the size to change. By OK to
656 change, we mean that we shouldn't warn if the type or size does
660 _bfd_elf_merge_symbol (bfd
*abfd
,
661 struct bfd_link_info
*info
,
663 Elf_Internal_Sym
*sym
,
666 struct elf_link_hash_entry
**sym_hash
,
668 bfd_boolean
*override
,
669 bfd_boolean
*type_change_ok
,
670 bfd_boolean
*size_change_ok
)
673 struct elf_link_hash_entry
*h
;
674 struct elf_link_hash_entry
*flip
;
677 bfd_boolean newdyn
, olddyn
, olddef
, newdef
, newdyncommon
, olddyncommon
;
678 bfd_boolean newweak
, oldweak
;
684 bind
= ELF_ST_BIND (sym
->st_info
);
686 if (! bfd_is_und_section (sec
))
687 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
, FALSE
, FALSE
);
689 h
= ((struct elf_link_hash_entry
*)
690 bfd_wrapped_link_hash_lookup (abfd
, info
, name
, TRUE
, FALSE
, FALSE
));
695 /* This code is for coping with dynamic objects, and is only useful
696 if we are doing an ELF link. */
697 if (info
->hash
->creator
!= abfd
->xvec
)
700 /* For merging, we only care about real symbols. */
702 while (h
->root
.type
== bfd_link_hash_indirect
703 || h
->root
.type
== bfd_link_hash_warning
)
704 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
706 /* If we just created the symbol, mark it as being an ELF symbol.
707 Other than that, there is nothing to do--there is no merge issue
708 with a newly defined symbol--so we just return. */
710 if (h
->root
.type
== bfd_link_hash_new
)
712 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
716 /* OLDBFD is a BFD associated with the existing symbol. */
718 switch (h
->root
.type
)
724 case bfd_link_hash_undefined
:
725 case bfd_link_hash_undefweak
:
726 oldbfd
= h
->root
.u
.undef
.abfd
;
729 case bfd_link_hash_defined
:
730 case bfd_link_hash_defweak
:
731 oldbfd
= h
->root
.u
.def
.section
->owner
;
734 case bfd_link_hash_common
:
735 oldbfd
= h
->root
.u
.c
.p
->section
->owner
;
739 /* In cases involving weak versioned symbols, we may wind up trying
740 to merge a symbol with itself. Catch that here, to avoid the
741 confusion that results if we try to override a symbol with
742 itself. The additional tests catch cases like
743 _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
744 dynamic object, which we do want to handle here. */
746 && ((abfd
->flags
& DYNAMIC
) == 0
747 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
750 /* NEWDYN and OLDDYN indicate whether the new or old symbol,
751 respectively, is from a dynamic object. */
753 if ((abfd
->flags
& DYNAMIC
) != 0)
759 olddyn
= (oldbfd
->flags
& DYNAMIC
) != 0;
764 /* This code handles the special SHN_MIPS_{TEXT,DATA} section
765 indices used by MIPS ELF. */
766 switch (h
->root
.type
)
772 case bfd_link_hash_defined
:
773 case bfd_link_hash_defweak
:
774 hsec
= h
->root
.u
.def
.section
;
777 case bfd_link_hash_common
:
778 hsec
= h
->root
.u
.c
.p
->section
;
785 olddyn
= (hsec
->symbol
->flags
& BSF_DYNAMIC
) != 0;
788 /* NEWDEF and OLDDEF indicate whether the new or old symbol,
789 respectively, appear to be a definition rather than reference. */
791 if (bfd_is_und_section (sec
) || bfd_is_com_section (sec
))
796 if (h
->root
.type
== bfd_link_hash_undefined
797 || h
->root
.type
== bfd_link_hash_undefweak
798 || h
->root
.type
== bfd_link_hash_common
)
803 /* We need to remember if a symbol has a definition in a dynamic
804 object or is weak in all dynamic objects. Internal and hidden
805 visibility will make it unavailable to dynamic objects. */
806 if (newdyn
&& (h
->elf_link_hash_flags
& ELF_LINK_DYNAMIC_DEF
) == 0)
808 if (!bfd_is_und_section (sec
))
809 h
->elf_link_hash_flags
|= ELF_LINK_DYNAMIC_DEF
;
812 /* Check if this symbol is weak in all dynamic objects. If it
813 is the first time we see it in a dynamic object, we mark
814 if it is weak. Otherwise, we clear it. */
815 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0)
817 if (bind
== STB_WEAK
)
818 h
->elf_link_hash_flags
|= ELF_LINK_DYNAMIC_WEAK
;
820 else if (bind
!= STB_WEAK
)
821 h
->elf_link_hash_flags
&= ~ELF_LINK_DYNAMIC_WEAK
;
825 /* If the old symbol has non-default visibility, we ignore the new
826 definition from a dynamic object. */
828 && ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
829 && !bfd_is_und_section (sec
))
832 /* Make sure this symbol is dynamic. */
833 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
834 /* A protected symbol has external availability. Make sure it is
837 FIXME: Should we check type and size for protected symbol? */
838 if (ELF_ST_VISIBILITY (h
->other
) == STV_PROTECTED
)
839 return _bfd_elf_link_record_dynamic_symbol (info
, h
);
844 && ELF_ST_VISIBILITY (sym
->st_other
) != STV_DEFAULT
845 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
847 /* If the new symbol with non-default visibility comes from a
848 relocatable file and the old definition comes from a dynamic
849 object, we remove the old definition. */
850 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
853 if ((h
->root
.und_next
|| info
->hash
->undefs_tail
== &h
->root
)
854 && bfd_is_und_section (sec
))
856 /* If the new symbol is undefined and the old symbol was
857 also undefined before, we need to make sure
858 _bfd_generic_link_add_one_symbol doesn't mess
859 up the linker hash table undefs list. Since the old
860 definition came from a dynamic object, it is still on the
862 h
->root
.type
= bfd_link_hash_undefined
;
863 /* FIXME: What if the new symbol is weak undefined? */
864 h
->root
.u
.undef
.abfd
= abfd
;
868 h
->root
.type
= bfd_link_hash_new
;
869 h
->root
.u
.undef
.abfd
= NULL
;
872 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
874 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_DEF_DYNAMIC
;
875 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_DYNAMIC
876 | ELF_LINK_DYNAMIC_DEF
);
878 /* FIXME: Should we check type and size for protected symbol? */
884 /* Differentiate strong and weak symbols. */
885 newweak
= bind
== STB_WEAK
;
886 oldweak
= (h
->root
.type
== bfd_link_hash_defweak
887 || h
->root
.type
== bfd_link_hash_undefweak
);
889 /* If a new weak symbol comes from a regular file and the old symbol
890 comes from a dynamic library, we treat the new one as strong.
891 Similarly, an old weak symbol from a regular file is treated as
892 strong when the new symbol comes from a dynamic library. Further,
893 an old weak symbol from a dynamic library is treated as strong if
894 the new symbol is from a dynamic library. This reflects the way
895 glibc's ld.so works. */
896 if (!newdyn
&& olddyn
)
901 /* It's OK to change the type if either the existing symbol or the
902 new symbol is weak. A type change is also OK if the old symbol
903 is undefined and the new symbol is defined. */
908 && h
->root
.type
== bfd_link_hash_undefined
))
909 *type_change_ok
= TRUE
;
911 /* It's OK to change the size if either the existing symbol or the
912 new symbol is weak, or if the old symbol is undefined. */
915 || h
->root
.type
== bfd_link_hash_undefined
)
916 *size_change_ok
= TRUE
;
918 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
919 symbol, respectively, appears to be a common symbol in a dynamic
920 object. If a symbol appears in an uninitialized section, and is
921 not weak, and is not a function, then it may be a common symbol
922 which was resolved when the dynamic object was created. We want
923 to treat such symbols specially, because they raise special
924 considerations when setting the symbol size: if the symbol
925 appears as a common symbol in a regular object, and the size in
926 the regular object is larger, we must make sure that we use the
927 larger size. This problematic case can always be avoided in C,
928 but it must be handled correctly when using Fortran shared
931 Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
932 likewise for OLDDYNCOMMON and OLDDEF.
934 Note that this test is just a heuristic, and that it is quite
935 possible to have an uninitialized symbol in a shared object which
936 is really a definition, rather than a common symbol. This could
937 lead to some minor confusion when the symbol really is a common
938 symbol in some regular object. However, I think it will be
944 && (sec
->flags
& SEC_ALLOC
) != 0
945 && (sec
->flags
& SEC_LOAD
) == 0
947 && ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
950 newdyncommon
= FALSE
;
954 && h
->root
.type
== bfd_link_hash_defined
955 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
956 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
957 && (h
->root
.u
.def
.section
->flags
& SEC_LOAD
) == 0
959 && h
->type
!= STT_FUNC
)
962 olddyncommon
= FALSE
;
964 /* If both the old and the new symbols look like common symbols in a
965 dynamic object, set the size of the symbol to the larger of the
970 && sym
->st_size
!= h
->size
)
972 /* Since we think we have two common symbols, issue a multiple
973 common warning if desired. Note that we only warn if the
974 size is different. If the size is the same, we simply let
975 the old symbol override the new one as normally happens with
976 symbols defined in dynamic objects. */
978 if (! ((*info
->callbacks
->multiple_common
)
979 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
980 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
983 if (sym
->st_size
> h
->size
)
984 h
->size
= sym
->st_size
;
986 *size_change_ok
= TRUE
;
989 /* If we are looking at a dynamic object, and we have found a
990 definition, we need to see if the symbol was already defined by
991 some other object. If so, we want to use the existing
992 definition, and we do not want to report a multiple symbol
993 definition error; we do this by clobbering *PSEC to be
996 We treat a common symbol as a definition if the symbol in the
997 shared library is a function, since common symbols always
998 represent variables; this can cause confusion in principle, but
999 any such confusion would seem to indicate an erroneous program or
1000 shared library. We also permit a common symbol in a regular
1001 object to override a weak symbol in a shared object. */
1006 || (h
->root
.type
== bfd_link_hash_common
1008 || ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
))))
1012 newdyncommon
= FALSE
;
1014 *psec
= sec
= bfd_und_section_ptr
;
1015 *size_change_ok
= TRUE
;
1017 /* If we get here when the old symbol is a common symbol, then
1018 we are explicitly letting it override a weak symbol or
1019 function in a dynamic object, and we don't want to warn about
1020 a type change. If the old symbol is a defined symbol, a type
1021 change warning may still be appropriate. */
1023 if (h
->root
.type
== bfd_link_hash_common
)
1024 *type_change_ok
= TRUE
;
1027 /* Handle the special case of an old common symbol merging with a
1028 new symbol which looks like a common symbol in a shared object.
1029 We change *PSEC and *PVALUE to make the new symbol look like a
1030 common symbol, and let _bfd_generic_link_add_one_symbol will do
1034 && h
->root
.type
== bfd_link_hash_common
)
1038 newdyncommon
= FALSE
;
1039 *pvalue
= sym
->st_size
;
1040 *psec
= sec
= bfd_com_section_ptr
;
1041 *size_change_ok
= TRUE
;
1044 /* If the old symbol is from a dynamic object, and the new symbol is
1045 a definition which is not from a dynamic object, then the new
1046 symbol overrides the old symbol. Symbols from regular files
1047 always take precedence over symbols from dynamic objects, even if
1048 they are defined after the dynamic object in the link.
1050 As above, we again permit a common symbol in a regular object to
1051 override a definition in a shared object if the shared object
1052 symbol is a function or is weak. */
1057 || (bfd_is_com_section (sec
)
1059 || h
->type
== STT_FUNC
)))
1062 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
1064 /* Change the hash table entry to undefined, and let
1065 _bfd_generic_link_add_one_symbol do the right thing with the
1068 h
->root
.type
= bfd_link_hash_undefined
;
1069 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1070 *size_change_ok
= TRUE
;
1073 olddyncommon
= FALSE
;
1075 /* We again permit a type change when a common symbol may be
1076 overriding a function. */
1078 if (bfd_is_com_section (sec
))
1079 *type_change_ok
= TRUE
;
1081 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1084 /* This union may have been set to be non-NULL when this symbol
1085 was seen in a dynamic object. We must force the union to be
1086 NULL, so that it is correct for a regular symbol. */
1087 h
->verinfo
.vertree
= NULL
;
1090 /* Handle the special case of a new common symbol merging with an
1091 old symbol that looks like it might be a common symbol defined in
1092 a shared object. Note that we have already handled the case in
1093 which a new common symbol should simply override the definition
1094 in the shared library. */
1097 && bfd_is_com_section (sec
)
1100 /* It would be best if we could set the hash table entry to a
1101 common symbol, but we don't know what to use for the section
1102 or the alignment. */
1103 if (! ((*info
->callbacks
->multiple_common
)
1104 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
1105 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
1108 /* If the presumed common symbol in the dynamic object is
1109 larger, pretend that the new symbol has its size. */
1111 if (h
->size
> *pvalue
)
1114 /* FIXME: We no longer know the alignment required by the symbol
1115 in the dynamic object, so we just wind up using the one from
1116 the regular object. */
1119 olddyncommon
= FALSE
;
1121 h
->root
.type
= bfd_link_hash_undefined
;
1122 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
1124 *size_change_ok
= TRUE
;
1125 *type_change_ok
= TRUE
;
1127 if ((*sym_hash
)->root
.type
== bfd_link_hash_indirect
)
1130 h
->verinfo
.vertree
= NULL
;
1135 /* Handle the case where we had a versioned symbol in a dynamic
1136 library and now find a definition in a normal object. In this
1137 case, we make the versioned symbol point to the normal one. */
1138 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1139 flip
->root
.type
= h
->root
.type
;
1140 h
->root
.type
= bfd_link_hash_indirect
;
1141 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) flip
;
1142 (*bed
->elf_backend_copy_indirect_symbol
) (bed
, flip
, h
);
1143 flip
->root
.u
.undef
.abfd
= h
->root
.u
.undef
.abfd
;
1144 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
1146 h
->elf_link_hash_flags
&= ~ELF_LINK_HASH_DEF_DYNAMIC
;
1147 flip
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
1154 /* This function is called to create an indirect symbol from the
1155 default for the symbol with the default version if needed. The
1156 symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We
1157 set DYNSYM if the new indirect symbol is dynamic. */
1160 _bfd_elf_add_default_symbol (bfd
*abfd
,
1161 struct bfd_link_info
*info
,
1162 struct elf_link_hash_entry
*h
,
1164 Elf_Internal_Sym
*sym
,
1167 bfd_boolean
*dynsym
,
1168 bfd_boolean override
)
1170 bfd_boolean type_change_ok
;
1171 bfd_boolean size_change_ok
;
1174 struct elf_link_hash_entry
*hi
;
1175 struct bfd_link_hash_entry
*bh
;
1176 const struct elf_backend_data
*bed
;
1177 bfd_boolean collect
;
1178 bfd_boolean dynamic
;
1180 size_t len
, shortlen
;
1183 /* If this symbol has a version, and it is the default version, we
1184 create an indirect symbol from the default name to the fully
1185 decorated name. This will cause external references which do not
1186 specify a version to be bound to this version of the symbol. */
1187 p
= strchr (name
, ELF_VER_CHR
);
1188 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
1193 /* We are overridden by an old definition. We need to check if we
1194 need to create the indirect symbol from the default name. */
1195 hi
= elf_link_hash_lookup (elf_hash_table (info
), name
, TRUE
,
1197 BFD_ASSERT (hi
!= NULL
);
1200 while (hi
->root
.type
== bfd_link_hash_indirect
1201 || hi
->root
.type
== bfd_link_hash_warning
)
1203 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1209 bed
= get_elf_backend_data (abfd
);
1210 collect
= bed
->collect
;
1211 dynamic
= (abfd
->flags
& DYNAMIC
) != 0;
1213 shortlen
= p
- name
;
1214 shortname
= bfd_hash_allocate (&info
->hash
->table
, shortlen
+ 1);
1215 if (shortname
== NULL
)
1217 memcpy (shortname
, name
, shortlen
);
1218 shortname
[shortlen
] = '\0';
1220 /* We are going to create a new symbol. Merge it with any existing
1221 symbol with this name. For the purposes of the merge, act as
1222 though we were defining the symbol we just defined, although we
1223 actually going to define an indirect symbol. */
1224 type_change_ok
= FALSE
;
1225 size_change_ok
= FALSE
;
1227 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1228 &hi
, &skip
, &override
, &type_change_ok
,
1238 if (! (_bfd_generic_link_add_one_symbol
1239 (info
, abfd
, shortname
, BSF_INDIRECT
, bfd_ind_section_ptr
,
1240 0, name
, FALSE
, collect
, &bh
)))
1242 hi
= (struct elf_link_hash_entry
*) bh
;
1246 /* In this case the symbol named SHORTNAME is overriding the
1247 indirect symbol we want to add. We were planning on making
1248 SHORTNAME an indirect symbol referring to NAME. SHORTNAME
1249 is the name without a version. NAME is the fully versioned
1250 name, and it is the default version.
1252 Overriding means that we already saw a definition for the
1253 symbol SHORTNAME in a regular object, and it is overriding
1254 the symbol defined in the dynamic object.
1256 When this happens, we actually want to change NAME, the
1257 symbol we just added, to refer to SHORTNAME. This will cause
1258 references to NAME in the shared object to become references
1259 to SHORTNAME in the regular object. This is what we expect
1260 when we override a function in a shared object: that the
1261 references in the shared object will be mapped to the
1262 definition in the regular object. */
1264 while (hi
->root
.type
== bfd_link_hash_indirect
1265 || hi
->root
.type
== bfd_link_hash_warning
)
1266 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1268 h
->root
.type
= bfd_link_hash_indirect
;
1269 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) hi
;
1270 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
1272 h
->elf_link_hash_flags
&=~ ELF_LINK_HASH_DEF_DYNAMIC
;
1273 hi
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
1274 if (hi
->elf_link_hash_flags
1275 & (ELF_LINK_HASH_REF_REGULAR
1276 | ELF_LINK_HASH_DEF_REGULAR
))
1278 if (! _bfd_elf_link_record_dynamic_symbol (info
, hi
))
1283 /* Now set HI to H, so that the following code will set the
1284 other fields correctly. */
1288 /* If there is a duplicate definition somewhere, then HI may not
1289 point to an indirect symbol. We will have reported an error to
1290 the user in that case. */
1292 if (hi
->root
.type
== bfd_link_hash_indirect
)
1294 struct elf_link_hash_entry
*ht
;
1296 ht
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1297 (*bed
->elf_backend_copy_indirect_symbol
) (bed
, ht
, hi
);
1299 /* See if the new flags lead us to realize that the symbol must
1306 || ((hi
->elf_link_hash_flags
1307 & ELF_LINK_HASH_REF_DYNAMIC
) != 0))
1312 if ((hi
->elf_link_hash_flags
1313 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1319 /* We also need to define an indirection from the nondefault version
1323 len
= strlen (name
);
1324 shortname
= bfd_hash_allocate (&info
->hash
->table
, len
);
1325 if (shortname
== NULL
)
1327 memcpy (shortname
, name
, shortlen
);
1328 memcpy (shortname
+ shortlen
, p
+ 1, len
- shortlen
);
1330 /* Once again, merge with any existing symbol. */
1331 type_change_ok
= FALSE
;
1332 size_change_ok
= FALSE
;
1334 if (!_bfd_elf_merge_symbol (abfd
, info
, shortname
, sym
, &sec
, value
,
1335 &hi
, &skip
, &override
, &type_change_ok
,
1344 /* Here SHORTNAME is a versioned name, so we don't expect to see
1345 the type of override we do in the case above unless it is
1346 overridden by a versioned definition. */
1347 if (hi
->root
.type
!= bfd_link_hash_defined
1348 && hi
->root
.type
!= bfd_link_hash_defweak
)
1349 (*_bfd_error_handler
)
1350 (_("%s: warning: unexpected redefinition of indirect versioned symbol `%s'"),
1351 bfd_archive_filename (abfd
), shortname
);
1356 if (! (_bfd_generic_link_add_one_symbol
1357 (info
, abfd
, shortname
, BSF_INDIRECT
,
1358 bfd_ind_section_ptr
, 0, name
, FALSE
, collect
, &bh
)))
1360 hi
= (struct elf_link_hash_entry
*) bh
;
1362 /* If there is a duplicate definition somewhere, then HI may not
1363 point to an indirect symbol. We will have reported an error
1364 to the user in that case. */
1366 if (hi
->root
.type
== bfd_link_hash_indirect
)
1368 (*bed
->elf_backend_copy_indirect_symbol
) (bed
, h
, hi
);
1370 /* See if the new flags lead us to realize that the symbol
1377 || ((hi
->elf_link_hash_flags
1378 & ELF_LINK_HASH_REF_DYNAMIC
) != 0))
1383 if ((hi
->elf_link_hash_flags
1384 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1394 /* This routine is used to export all defined symbols into the dynamic
1395 symbol table. It is called via elf_link_hash_traverse. */
1398 _bfd_elf_export_symbol (struct elf_link_hash_entry
*h
, void *data
)
1400 struct elf_info_failed
*eif
= data
;
1402 /* Ignore indirect symbols. These are added by the versioning code. */
1403 if (h
->root
.type
== bfd_link_hash_indirect
)
1406 if (h
->root
.type
== bfd_link_hash_warning
)
1407 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1409 if (h
->dynindx
== -1
1410 && (h
->elf_link_hash_flags
1411 & (ELF_LINK_HASH_DEF_REGULAR
| ELF_LINK_HASH_REF_REGULAR
)) != 0)
1413 struct bfd_elf_version_tree
*t
;
1414 struct bfd_elf_version_expr
*d
;
1416 for (t
= eif
->verdefs
; t
!= NULL
; t
= t
->next
)
1418 if (t
->globals
.list
!= NULL
)
1420 d
= (*t
->match
) (&t
->globals
, NULL
, h
->root
.root
.string
);
1425 if (t
->locals
.list
!= NULL
)
1427 d
= (*t
->match
) (&t
->locals
, NULL
, h
->root
.root
.string
);
1436 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
1447 /* Look through the symbols which are defined in other shared
1448 libraries and referenced here. Update the list of version
1449 dependencies. This will be put into the .gnu.version_r section.
1450 This function is called via elf_link_hash_traverse. */
1453 _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry
*h
,
1456 struct elf_find_verdep_info
*rinfo
= data
;
1457 Elf_Internal_Verneed
*t
;
1458 Elf_Internal_Vernaux
*a
;
1461 if (h
->root
.type
== bfd_link_hash_warning
)
1462 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1464 /* We only care about symbols defined in shared objects with version
1466 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
1467 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
1469 || h
->verinfo
.verdef
== NULL
)
1472 /* See if we already know about this version. */
1473 for (t
= elf_tdata (rinfo
->output_bfd
)->verref
; t
!= NULL
; t
= t
->vn_nextref
)
1475 if (t
->vn_bfd
!= h
->verinfo
.verdef
->vd_bfd
)
1478 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
1479 if (a
->vna_nodename
== h
->verinfo
.verdef
->vd_nodename
)
1485 /* This is a new version. Add it to tree we are building. */
1490 t
= bfd_zalloc (rinfo
->output_bfd
, amt
);
1493 rinfo
->failed
= TRUE
;
1497 t
->vn_bfd
= h
->verinfo
.verdef
->vd_bfd
;
1498 t
->vn_nextref
= elf_tdata (rinfo
->output_bfd
)->verref
;
1499 elf_tdata (rinfo
->output_bfd
)->verref
= t
;
1503 a
= bfd_zalloc (rinfo
->output_bfd
, amt
);
1505 /* Note that we are copying a string pointer here, and testing it
1506 above. If bfd_elf_string_from_elf_section is ever changed to
1507 discard the string data when low in memory, this will have to be
1509 a
->vna_nodename
= h
->verinfo
.verdef
->vd_nodename
;
1511 a
->vna_flags
= h
->verinfo
.verdef
->vd_flags
;
1512 a
->vna_nextptr
= t
->vn_auxptr
;
1514 h
->verinfo
.verdef
->vd_exp_refno
= rinfo
->vers
;
1517 a
->vna_other
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
1524 /* Figure out appropriate versions for all the symbols. We may not
1525 have the version number script until we have read all of the input
1526 files, so until that point we don't know which symbols should be
1527 local. This function is called via elf_link_hash_traverse. */
1530 _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry
*h
, void *data
)
1532 struct elf_assign_sym_version_info
*sinfo
;
1533 struct bfd_link_info
*info
;
1534 const struct elf_backend_data
*bed
;
1535 struct elf_info_failed eif
;
1542 if (h
->root
.type
== bfd_link_hash_warning
)
1543 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1545 /* Fix the symbol flags. */
1548 if (! _bfd_elf_fix_symbol_flags (h
, &eif
))
1551 sinfo
->failed
= TRUE
;
1555 /* We only need version numbers for symbols defined in regular
1557 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1560 bed
= get_elf_backend_data (sinfo
->output_bfd
);
1561 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
1562 if (p
!= NULL
&& h
->verinfo
.vertree
== NULL
)
1564 struct bfd_elf_version_tree
*t
;
1569 /* There are two consecutive ELF_VER_CHR characters if this is
1570 not a hidden symbol. */
1572 if (*p
== ELF_VER_CHR
)
1578 /* If there is no version string, we can just return out. */
1582 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
1586 /* Look for the version. If we find it, it is no longer weak. */
1587 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
1589 if (strcmp (t
->name
, p
) == 0)
1593 struct bfd_elf_version_expr
*d
;
1595 len
= p
- h
->root
.root
.string
;
1596 alc
= bfd_malloc (len
);
1599 memcpy (alc
, h
->root
.root
.string
, len
- 1);
1600 alc
[len
- 1] = '\0';
1601 if (alc
[len
- 2] == ELF_VER_CHR
)
1602 alc
[len
- 2] = '\0';
1604 h
->verinfo
.vertree
= t
;
1608 if (t
->globals
.list
!= NULL
)
1609 d
= (*t
->match
) (&t
->globals
, NULL
, alc
);
1611 /* See if there is anything to force this symbol to
1613 if (d
== NULL
&& t
->locals
.list
!= NULL
)
1615 d
= (*t
->match
) (&t
->locals
, NULL
, alc
);
1619 && ! info
->export_dynamic
)
1620 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1628 /* If we are building an application, we need to create a
1629 version node for this version. */
1630 if (t
== NULL
&& info
->executable
)
1632 struct bfd_elf_version_tree
**pp
;
1635 /* If we aren't going to export this symbol, we don't need
1636 to worry about it. */
1637 if (h
->dynindx
== -1)
1641 t
= bfd_zalloc (sinfo
->output_bfd
, amt
);
1644 sinfo
->failed
= TRUE
;
1649 t
->name_indx
= (unsigned int) -1;
1653 /* Don't count anonymous version tag. */
1654 if (sinfo
->verdefs
!= NULL
&& sinfo
->verdefs
->vernum
== 0)
1656 for (pp
= &sinfo
->verdefs
; *pp
!= NULL
; pp
= &(*pp
)->next
)
1658 t
->vernum
= version_index
;
1662 h
->verinfo
.vertree
= t
;
1666 /* We could not find the version for a symbol when
1667 generating a shared archive. Return an error. */
1668 (*_bfd_error_handler
)
1669 (_("%s: undefined versioned symbol name %s"),
1670 bfd_get_filename (sinfo
->output_bfd
), h
->root
.root
.string
);
1671 bfd_set_error (bfd_error_bad_value
);
1672 sinfo
->failed
= TRUE
;
1677 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
1680 /* If we don't have a version for this symbol, see if we can find
1682 if (h
->verinfo
.vertree
== NULL
&& sinfo
->verdefs
!= NULL
)
1684 struct bfd_elf_version_tree
*t
;
1685 struct bfd_elf_version_tree
*local_ver
;
1686 struct bfd_elf_version_expr
*d
;
1688 /* See if can find what version this symbol is in. If the
1689 symbol is supposed to be local, then don't actually register
1692 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
1694 if (t
->globals
.list
!= NULL
)
1696 bfd_boolean matched
;
1700 while ((d
= (*t
->match
) (&t
->globals
, d
,
1701 h
->root
.root
.string
)) != NULL
)
1706 /* There is a version without definition. Make
1707 the symbol the default definition for this
1709 h
->verinfo
.vertree
= t
;
1717 /* There is no undefined version for this symbol. Hide the
1719 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1722 if (t
->locals
.list
!= NULL
)
1725 while ((d
= (*t
->match
) (&t
->locals
, d
,
1726 h
->root
.root
.string
)) != NULL
)
1729 /* If the match is "*", keep looking for a more
1730 explicit, perhaps even global, match.
1731 XXX: Shouldn't this be !d->wildcard instead? */
1732 if (d
->pattern
[0] != '*' || d
->pattern
[1] != '\0')
1741 if (local_ver
!= NULL
)
1743 h
->verinfo
.vertree
= local_ver
;
1744 if (h
->dynindx
!= -1
1746 && ! info
->export_dynamic
)
1748 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
1756 /* Read and swap the relocs from the section indicated by SHDR. This
1757 may be either a REL or a RELA section. The relocations are
1758 translated into RELA relocations and stored in INTERNAL_RELOCS,
1759 which should have already been allocated to contain enough space.
1760 The EXTERNAL_RELOCS are a buffer where the external form of the
1761 relocations should be stored.
1763 Returns FALSE if something goes wrong. */
1766 elf_link_read_relocs_from_section (bfd
*abfd
,
1768 Elf_Internal_Shdr
*shdr
,
1769 void *external_relocs
,
1770 Elf_Internal_Rela
*internal_relocs
)
1772 const struct elf_backend_data
*bed
;
1773 void (*swap_in
) (bfd
*, const bfd_byte
*, Elf_Internal_Rela
*);
1774 const bfd_byte
*erela
;
1775 const bfd_byte
*erelaend
;
1776 Elf_Internal_Rela
*irela
;
1777 Elf_Internal_Shdr
*symtab_hdr
;
1780 /* Position ourselves at the start of the section. */
1781 if (bfd_seek (abfd
, shdr
->sh_offset
, SEEK_SET
) != 0)
1784 /* Read the relocations. */
1785 if (bfd_bread (external_relocs
, shdr
->sh_size
, abfd
) != shdr
->sh_size
)
1788 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1789 nsyms
= symtab_hdr
->sh_size
/ symtab_hdr
->sh_entsize
;
1791 bed
= get_elf_backend_data (abfd
);
1793 /* Convert the external relocations to the internal format. */
1794 if (shdr
->sh_entsize
== bed
->s
->sizeof_rel
)
1795 swap_in
= bed
->s
->swap_reloc_in
;
1796 else if (shdr
->sh_entsize
== bed
->s
->sizeof_rela
)
1797 swap_in
= bed
->s
->swap_reloca_in
;
1800 bfd_set_error (bfd_error_wrong_format
);
1804 erela
= external_relocs
;
1805 erelaend
= erela
+ shdr
->sh_size
;
1806 irela
= internal_relocs
;
1807 while (erela
< erelaend
)
1811 (*swap_in
) (abfd
, erela
, irela
);
1812 r_symndx
= ELF32_R_SYM (irela
->r_info
);
1813 if (bed
->s
->arch_size
== 64)
1815 if ((size_t) r_symndx
>= nsyms
)
1817 (*_bfd_error_handler
)
1818 (_("%s: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%s'"),
1819 bfd_archive_filename (abfd
), (unsigned long) r_symndx
,
1820 (unsigned long) nsyms
, irela
->r_offset
, sec
->name
);
1821 bfd_set_error (bfd_error_bad_value
);
1824 irela
+= bed
->s
->int_rels_per_ext_rel
;
1825 erela
+= shdr
->sh_entsize
;
1831 /* Read and swap the relocs for a section O. They may have been
1832 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
1833 not NULL, they are used as buffers to read into. They are known to
1834 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
1835 the return value is allocated using either malloc or bfd_alloc,
1836 according to the KEEP_MEMORY argument. If O has two relocation
1837 sections (both REL and RELA relocations), then the REL_HDR
1838 relocations will appear first in INTERNAL_RELOCS, followed by the
1839 REL_HDR2 relocations. */
1842 _bfd_elf_link_read_relocs (bfd
*abfd
,
1844 void *external_relocs
,
1845 Elf_Internal_Rela
*internal_relocs
,
1846 bfd_boolean keep_memory
)
1848 Elf_Internal_Shdr
*rel_hdr
;
1849 void *alloc1
= NULL
;
1850 Elf_Internal_Rela
*alloc2
= NULL
;
1851 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
1853 if (elf_section_data (o
)->relocs
!= NULL
)
1854 return elf_section_data (o
)->relocs
;
1856 if (o
->reloc_count
== 0)
1859 rel_hdr
= &elf_section_data (o
)->rel_hdr
;
1861 if (internal_relocs
== NULL
)
1865 size
= o
->reloc_count
;
1866 size
*= bed
->s
->int_rels_per_ext_rel
* sizeof (Elf_Internal_Rela
);
1868 internal_relocs
= bfd_alloc (abfd
, size
);
1870 internal_relocs
= alloc2
= bfd_malloc (size
);
1871 if (internal_relocs
== NULL
)
1875 if (external_relocs
== NULL
)
1877 bfd_size_type size
= rel_hdr
->sh_size
;
1879 if (elf_section_data (o
)->rel_hdr2
)
1880 size
+= elf_section_data (o
)->rel_hdr2
->sh_size
;
1881 alloc1
= bfd_malloc (size
);
1884 external_relocs
= alloc1
;
1887 if (!elf_link_read_relocs_from_section (abfd
, o
, rel_hdr
,
1891 if (elf_section_data (o
)->rel_hdr2
1892 && (!elf_link_read_relocs_from_section
1894 elf_section_data (o
)->rel_hdr2
,
1895 ((bfd_byte
*) external_relocs
) + rel_hdr
->sh_size
,
1896 internal_relocs
+ (NUM_SHDR_ENTRIES (rel_hdr
)
1897 * bed
->s
->int_rels_per_ext_rel
))))
1900 /* Cache the results for next time, if we can. */
1902 elf_section_data (o
)->relocs
= internal_relocs
;
1907 /* Don't free alloc2, since if it was allocated we are passing it
1908 back (under the name of internal_relocs). */
1910 return internal_relocs
;
1920 /* Compute the size of, and allocate space for, REL_HDR which is the
1921 section header for a section containing relocations for O. */
1924 _bfd_elf_link_size_reloc_section (bfd
*abfd
,
1925 Elf_Internal_Shdr
*rel_hdr
,
1928 bfd_size_type reloc_count
;
1929 bfd_size_type num_rel_hashes
;
1931 /* Figure out how many relocations there will be. */
1932 if (rel_hdr
== &elf_section_data (o
)->rel_hdr
)
1933 reloc_count
= elf_section_data (o
)->rel_count
;
1935 reloc_count
= elf_section_data (o
)->rel_count2
;
1937 num_rel_hashes
= o
->reloc_count
;
1938 if (num_rel_hashes
< reloc_count
)
1939 num_rel_hashes
= reloc_count
;
1941 /* That allows us to calculate the size of the section. */
1942 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
* reloc_count
;
1944 /* The contents field must last into write_object_contents, so we
1945 allocate it with bfd_alloc rather than malloc. Also since we
1946 cannot be sure that the contents will actually be filled in,
1947 we zero the allocated space. */
1948 rel_hdr
->contents
= bfd_zalloc (abfd
, rel_hdr
->sh_size
);
1949 if (rel_hdr
->contents
== NULL
&& rel_hdr
->sh_size
!= 0)
1952 /* We only allocate one set of hash entries, so we only do it the
1953 first time we are called. */
1954 if (elf_section_data (o
)->rel_hashes
== NULL
1957 struct elf_link_hash_entry
**p
;
1959 p
= bfd_zmalloc (num_rel_hashes
* sizeof (struct elf_link_hash_entry
*));
1963 elf_section_data (o
)->rel_hashes
= p
;
1969 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
1970 originated from the section given by INPUT_REL_HDR) to the
1974 _bfd_elf_link_output_relocs (bfd
*output_bfd
,
1975 asection
*input_section
,
1976 Elf_Internal_Shdr
*input_rel_hdr
,
1977 Elf_Internal_Rela
*internal_relocs
)
1979 Elf_Internal_Rela
*irela
;
1980 Elf_Internal_Rela
*irelaend
;
1982 Elf_Internal_Shdr
*output_rel_hdr
;
1983 asection
*output_section
;
1984 unsigned int *rel_countp
= NULL
;
1985 const struct elf_backend_data
*bed
;
1986 void (*swap_out
) (bfd
*, const Elf_Internal_Rela
*, bfd_byte
*);
1988 output_section
= input_section
->output_section
;
1989 output_rel_hdr
= NULL
;
1991 if (elf_section_data (output_section
)->rel_hdr
.sh_entsize
1992 == input_rel_hdr
->sh_entsize
)
1994 output_rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
1995 rel_countp
= &elf_section_data (output_section
)->rel_count
;
1997 else if (elf_section_data (output_section
)->rel_hdr2
1998 && (elf_section_data (output_section
)->rel_hdr2
->sh_entsize
1999 == input_rel_hdr
->sh_entsize
))
2001 output_rel_hdr
= elf_section_data (output_section
)->rel_hdr2
;
2002 rel_countp
= &elf_section_data (output_section
)->rel_count2
;
2006 (*_bfd_error_handler
)
2007 (_("%s: relocation size mismatch in %s section %s"),
2008 bfd_get_filename (output_bfd
),
2009 bfd_archive_filename (input_section
->owner
),
2010 input_section
->name
);
2011 bfd_set_error (bfd_error_wrong_object_format
);
2015 bed
= get_elf_backend_data (output_bfd
);
2016 if (input_rel_hdr
->sh_entsize
== bed
->s
->sizeof_rel
)
2017 swap_out
= bed
->s
->swap_reloc_out
;
2018 else if (input_rel_hdr
->sh_entsize
== bed
->s
->sizeof_rela
)
2019 swap_out
= bed
->s
->swap_reloca_out
;
2023 erel
= output_rel_hdr
->contents
;
2024 erel
+= *rel_countp
* input_rel_hdr
->sh_entsize
;
2025 irela
= internal_relocs
;
2026 irelaend
= irela
+ (NUM_SHDR_ENTRIES (input_rel_hdr
)
2027 * bed
->s
->int_rels_per_ext_rel
);
2028 while (irela
< irelaend
)
2030 (*swap_out
) (output_bfd
, irela
, erel
);
2031 irela
+= bed
->s
->int_rels_per_ext_rel
;
2032 erel
+= input_rel_hdr
->sh_entsize
;
2035 /* Bump the counter, so that we know where to add the next set of
2037 *rel_countp
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
2042 /* Fix up the flags for a symbol. This handles various cases which
2043 can only be fixed after all the input files are seen. This is
2044 currently called by both adjust_dynamic_symbol and
2045 assign_sym_version, which is unnecessary but perhaps more robust in
2046 the face of future changes. */
2049 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry
*h
,
2050 struct elf_info_failed
*eif
)
2052 /* If this symbol was mentioned in a non-ELF file, try to set
2053 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
2054 permit a non-ELF file to correctly refer to a symbol defined in
2055 an ELF dynamic object. */
2056 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_ELF
) != 0)
2058 while (h
->root
.type
== bfd_link_hash_indirect
)
2059 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2061 if (h
->root
.type
!= bfd_link_hash_defined
2062 && h
->root
.type
!= bfd_link_hash_defweak
)
2063 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
2064 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
2067 if (h
->root
.u
.def
.section
->owner
!= NULL
2068 && (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2069 == bfd_target_elf_flavour
))
2070 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
2071 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
2073 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2076 if (h
->dynindx
== -1
2077 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2078 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
2080 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
2089 /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol
2090 was first seen in a non-ELF file. Fortunately, if the symbol
2091 was first seen in an ELF file, we're probably OK unless the
2092 symbol was defined in a non-ELF file. Catch that case here.
2093 FIXME: We're still in trouble if the symbol was first seen in
2094 a dynamic object, and then later in a non-ELF regular object. */
2095 if ((h
->root
.type
== bfd_link_hash_defined
2096 || h
->root
.type
== bfd_link_hash_defweak
)
2097 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2098 && (h
->root
.u
.def
.section
->owner
!= NULL
2099 ? (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
2100 != bfd_target_elf_flavour
)
2101 : (bfd_is_abs_section (h
->root
.u
.def
.section
)
2102 && (h
->elf_link_hash_flags
2103 & ELF_LINK_HASH_DEF_DYNAMIC
) == 0)))
2104 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2107 /* If this is a final link, and the symbol was defined as a common
2108 symbol in a regular object file, and there was no definition in
2109 any dynamic object, then the linker will have allocated space for
2110 the symbol in a common section but the ELF_LINK_HASH_DEF_REGULAR
2111 flag will not have been set. */
2112 if (h
->root
.type
== bfd_link_hash_defined
2113 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
2114 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) != 0
2115 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
2116 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
2117 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2119 /* If -Bsymbolic was used (which means to bind references to global
2120 symbols to the definition within the shared object), and this
2121 symbol was defined in a regular object, then it actually doesn't
2122 need a PLT entry. Likewise, if the symbol has non-default
2123 visibility. If the symbol has hidden or internal visibility, we
2124 will force it local. */
2125 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
2126 && eif
->info
->shared
2127 && is_elf_hash_table (eif
->info
->hash
)
2128 && (eif
->info
->symbolic
2129 || ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
2130 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
2132 const struct elf_backend_data
*bed
;
2133 bfd_boolean force_local
;
2135 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2137 force_local
= (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
2138 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
);
2139 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, force_local
);
2142 /* If a weak undefined symbol has non-default visibility, we also
2143 hide it from the dynamic linker. */
2144 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
2145 && h
->root
.type
== bfd_link_hash_undefweak
)
2147 const struct elf_backend_data
*bed
;
2148 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2149 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
, TRUE
);
2152 /* If this is a weak defined symbol in a dynamic object, and we know
2153 the real definition in the dynamic object, copy interesting flags
2154 over to the real definition. */
2155 if (h
->weakdef
!= NULL
)
2157 struct elf_link_hash_entry
*weakdef
;
2159 weakdef
= h
->weakdef
;
2160 if (h
->root
.type
== bfd_link_hash_indirect
)
2161 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2163 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
2164 || h
->root
.type
== bfd_link_hash_defweak
);
2165 BFD_ASSERT (weakdef
->root
.type
== bfd_link_hash_defined
2166 || weakdef
->root
.type
== bfd_link_hash_defweak
);
2167 BFD_ASSERT (weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
);
2169 /* If the real definition is defined by a regular object file,
2170 don't do anything special. See the longer description in
2171 _bfd_elf_adjust_dynamic_symbol, below. */
2172 if ((weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
2176 const struct elf_backend_data
*bed
;
2178 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
2179 (*bed
->elf_backend_copy_indirect_symbol
) (bed
, weakdef
, h
);
2186 /* Make the backend pick a good value for a dynamic symbol. This is
2187 called via elf_link_hash_traverse, and also calls itself
2191 _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry
*h
, void *data
)
2193 struct elf_info_failed
*eif
= data
;
2195 const struct elf_backend_data
*bed
;
2197 if (! is_elf_hash_table (eif
->info
->hash
))
2200 if (h
->root
.type
== bfd_link_hash_warning
)
2202 h
->plt
= elf_hash_table (eif
->info
)->init_offset
;
2203 h
->got
= elf_hash_table (eif
->info
)->init_offset
;
2205 /* When warning symbols are created, they **replace** the "real"
2206 entry in the hash table, thus we never get to see the real
2207 symbol in a hash traversal. So look at it now. */
2208 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2211 /* Ignore indirect symbols. These are added by the versioning code. */
2212 if (h
->root
.type
== bfd_link_hash_indirect
)
2215 /* Fix the symbol flags. */
2216 if (! _bfd_elf_fix_symbol_flags (h
, eif
))
2219 /* If this symbol does not require a PLT entry, and it is not
2220 defined by a dynamic object, or is not referenced by a regular
2221 object, ignore it. We do have to handle a weak defined symbol,
2222 even if no regular object refers to it, if we decided to add it
2223 to the dynamic symbol table. FIXME: Do we normally need to worry
2224 about symbols which are defined by one dynamic object and
2225 referenced by another one? */
2226 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0
2227 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
2228 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
2229 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0
2230 && (h
->weakdef
== NULL
|| h
->weakdef
->dynindx
== -1))))
2232 h
->plt
= elf_hash_table (eif
->info
)->init_offset
;
2236 /* If we've already adjusted this symbol, don't do it again. This
2237 can happen via a recursive call. */
2238 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
2241 /* Don't look at this symbol again. Note that we must set this
2242 after checking the above conditions, because we may look at a
2243 symbol once, decide not to do anything, and then get called
2244 recursively later after REF_REGULAR is set below. */
2245 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DYNAMIC_ADJUSTED
;
2247 /* If this is a weak definition, and we know a real definition, and
2248 the real symbol is not itself defined by a regular object file,
2249 then get a good value for the real definition. We handle the
2250 real symbol first, for the convenience of the backend routine.
2252 Note that there is a confusing case here. If the real definition
2253 is defined by a regular object file, we don't get the real symbol
2254 from the dynamic object, but we do get the weak symbol. If the
2255 processor backend uses a COPY reloc, then if some routine in the
2256 dynamic object changes the real symbol, we will not see that
2257 change in the corresponding weak symbol. This is the way other
2258 ELF linkers work as well, and seems to be a result of the shared
2261 I will clarify this issue. Most SVR4 shared libraries define the
2262 variable _timezone and define timezone as a weak synonym. The
2263 tzset call changes _timezone. If you write
2264 extern int timezone;
2266 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
2267 you might expect that, since timezone is a synonym for _timezone,
2268 the same number will print both times. However, if the processor
2269 backend uses a COPY reloc, then actually timezone will be copied
2270 into your process image, and, since you define _timezone
2271 yourself, _timezone will not. Thus timezone and _timezone will
2272 wind up at different memory locations. The tzset call will set
2273 _timezone, leaving timezone unchanged. */
2275 if (h
->weakdef
!= NULL
)
2277 /* If we get to this point, we know there is an implicit
2278 reference by a regular object file via the weak symbol H.
2279 FIXME: Is this really true? What if the traversal finds
2280 H->WEAKDEF before it finds H? */
2281 h
->weakdef
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
2283 if (! _bfd_elf_adjust_dynamic_symbol (h
->weakdef
, eif
))
2287 /* If a symbol has no type and no size and does not require a PLT
2288 entry, then we are probably about to do the wrong thing here: we
2289 are probably going to create a COPY reloc for an empty object.
2290 This case can arise when a shared object is built with assembly
2291 code, and the assembly code fails to set the symbol type. */
2293 && h
->type
== STT_NOTYPE
2294 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
2295 (*_bfd_error_handler
)
2296 (_("warning: type and size of dynamic symbol `%s' are not defined"),
2297 h
->root
.root
.string
);
2299 dynobj
= elf_hash_table (eif
->info
)->dynobj
;
2300 bed
= get_elf_backend_data (dynobj
);
2301 if (! (*bed
->elf_backend_adjust_dynamic_symbol
) (eif
->info
, h
))
2310 /* Adjust all external symbols pointing into SEC_MERGE sections
2311 to reflect the object merging within the sections. */
2314 _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry
*h
, void *data
)
2318 if (h
->root
.type
== bfd_link_hash_warning
)
2319 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2321 if ((h
->root
.type
== bfd_link_hash_defined
2322 || h
->root
.type
== bfd_link_hash_defweak
)
2323 && ((sec
= h
->root
.u
.def
.section
)->flags
& SEC_MERGE
)
2324 && sec
->sec_info_type
== ELF_INFO_TYPE_MERGE
)
2326 bfd
*output_bfd
= data
;
2328 h
->root
.u
.def
.value
=
2329 _bfd_merged_section_offset (output_bfd
,
2330 &h
->root
.u
.def
.section
,
2331 elf_section_data (sec
)->sec_info
,
2332 h
->root
.u
.def
.value
, 0);
2338 /* Returns false if the symbol referred to by H should be considered
2339 to resolve local to the current module, and true if it should be
2340 considered to bind dynamically. */
2343 _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry
*h
,
2344 struct bfd_link_info
*info
,
2345 bfd_boolean ignore_protected
)
2347 bfd_boolean binding_stays_local_p
;
2352 while (h
->root
.type
== bfd_link_hash_indirect
2353 || h
->root
.type
== bfd_link_hash_warning
)
2354 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2356 /* If it was forced local, then clearly it's not dynamic. */
2357 if (h
->dynindx
== -1)
2359 if (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
)
2362 /* Identify the cases where name binding rules say that a
2363 visible symbol resolves locally. */
2364 binding_stays_local_p
= info
->executable
|| info
->symbolic
;
2366 switch (ELF_ST_VISIBILITY (h
->other
))
2373 /* Proper resolution for function pointer equality may require
2374 that these symbols perhaps be resolved dynamically, even though
2375 we should be resolving them to the current module. */
2376 if (!ignore_protected
)
2377 binding_stays_local_p
= TRUE
;
2384 /* If it isn't defined locally, then clearly it's dynamic. */
2385 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2388 /* Otherwise, the symbol is dynamic if binding rules don't tell
2389 us that it remains local. */
2390 return !binding_stays_local_p
;
2393 /* Return true if the symbol referred to by H should be considered
2394 to resolve local to the current module, and false otherwise. Differs
2395 from (the inverse of) _bfd_elf_dynamic_symbol_p in the treatment of
2396 undefined symbols and weak symbols. */
2399 _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry
*h
,
2400 struct bfd_link_info
*info
,
2401 bfd_boolean local_protected
)
2403 /* If it's a local sym, of course we resolve locally. */
2407 /* If we don't have a definition in a regular file, then we can't
2408 resolve locally. The sym is either undefined or dynamic. */
2409 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2412 /* Forced local symbols resolve locally. */
2413 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
2416 /* As do non-dynamic symbols. */
2417 if (h
->dynindx
== -1)
2420 /* At this point, we know the symbol is defined and dynamic. In an
2421 executable it must resolve locally, likewise when building symbolic
2422 shared libraries. */
2423 if (info
->executable
|| info
->symbolic
)
2426 /* Now deal with defined dynamic symbols in shared libraries. Ones
2427 with default visibility might not resolve locally. */
2428 if (ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
)
2431 /* However, STV_HIDDEN or STV_INTERNAL ones must be local. */
2432 if (ELF_ST_VISIBILITY (h
->other
) != STV_PROTECTED
)
2435 /* Function pointer equality tests may require that STV_PROTECTED
2436 symbols be treated as dynamic symbols, even when we know that the
2437 dynamic linker will resolve them locally. */
2438 return local_protected
;
2441 /* Caches some TLS segment info, and ensures that the TLS segment vma is
2442 aligned. Returns the first TLS output section. */
2444 struct bfd_section
*
2445 _bfd_elf_tls_setup (bfd
*obfd
, struct bfd_link_info
*info
)
2447 struct bfd_section
*sec
, *tls
;
2448 unsigned int align
= 0;
2450 for (sec
= obfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
2451 if ((sec
->flags
& SEC_THREAD_LOCAL
) != 0)
2455 for (; sec
!= NULL
&& (sec
->flags
& SEC_THREAD_LOCAL
) != 0; sec
= sec
->next
)
2456 if (sec
->alignment_power
> align
)
2457 align
= sec
->alignment_power
;
2459 elf_hash_table (info
)->tls_sec
= tls
;
2461 /* Ensure the alignment of the first section is the largest alignment,
2462 so that the tls segment starts aligned. */
2464 tls
->alignment_power
= align
;
2469 /* Return TRUE iff this is a non-common, definition of a non-function symbol. */
2471 is_global_data_symbol_definition (bfd
*abfd ATTRIBUTE_UNUSED
,
2472 Elf_Internal_Sym
*sym
)
2474 /* Local symbols do not count, but target specific ones might. */
2475 if (ELF_ST_BIND (sym
->st_info
) != STB_GLOBAL
2476 && ELF_ST_BIND (sym
->st_info
) < STB_LOOS
)
2479 /* Function symbols do not count. */
2480 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
)
2483 /* If the section is undefined, then so is the symbol. */
2484 if (sym
->st_shndx
== SHN_UNDEF
)
2487 /* If the symbol is defined in the common section, then
2488 it is a common definition and so does not count. */
2489 if (sym
->st_shndx
== SHN_COMMON
)
2492 /* If the symbol is in a target specific section then we
2493 must rely upon the backend to tell us what it is. */
2494 if (sym
->st_shndx
>= SHN_LORESERVE
&& sym
->st_shndx
< SHN_ABS
)
2495 /* FIXME - this function is not coded yet:
2497 return _bfd_is_global_symbol_definition (abfd, sym);
2499 Instead for now assume that the definition is not global,
2500 Even if this is wrong, at least the linker will behave
2501 in the same way that it used to do. */
2507 /* Search the symbol table of the archive element of the archive ABFD
2508 whose archive map contains a mention of SYMDEF, and determine if
2509 the symbol is defined in this element. */
2511 elf_link_is_defined_archive_symbol (bfd
* abfd
, carsym
* symdef
)
2513 Elf_Internal_Shdr
* hdr
;
2514 bfd_size_type symcount
;
2515 bfd_size_type extsymcount
;
2516 bfd_size_type extsymoff
;
2517 Elf_Internal_Sym
*isymbuf
;
2518 Elf_Internal_Sym
*isym
;
2519 Elf_Internal_Sym
*isymend
;
2522 abfd
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
2526 if (! bfd_check_format (abfd
, bfd_object
))
2529 /* If we have already included the element containing this symbol in the
2530 link then we do not need to include it again. Just claim that any symbol
2531 it contains is not a definition, so that our caller will not decide to
2532 (re)include this element. */
2533 if (abfd
->archive_pass
)
2536 /* Select the appropriate symbol table. */
2537 if ((abfd
->flags
& DYNAMIC
) == 0 || elf_dynsymtab (abfd
) == 0)
2538 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
2540 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
2542 symcount
= hdr
->sh_size
/ get_elf_backend_data (abfd
)->s
->sizeof_sym
;
2544 /* The sh_info field of the symtab header tells us where the
2545 external symbols start. We don't care about the local symbols. */
2546 if (elf_bad_symtab (abfd
))
2548 extsymcount
= symcount
;
2553 extsymcount
= symcount
- hdr
->sh_info
;
2554 extsymoff
= hdr
->sh_info
;
2557 if (extsymcount
== 0)
2560 /* Read in the symbol table. */
2561 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
2563 if (isymbuf
== NULL
)
2566 /* Scan the symbol table looking for SYMDEF. */
2568 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
; isym
< isymend
; isym
++)
2572 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
2577 if (strcmp (name
, symdef
->name
) == 0)
2579 result
= is_global_data_symbol_definition (abfd
, isym
);
2589 /* Add an entry to the .dynamic table. */
2592 _bfd_elf_add_dynamic_entry (struct bfd_link_info
*info
,
2596 struct elf_link_hash_table
*hash_table
;
2597 const struct elf_backend_data
*bed
;
2599 bfd_size_type newsize
;
2600 bfd_byte
*newcontents
;
2601 Elf_Internal_Dyn dyn
;
2603 hash_table
= elf_hash_table (info
);
2604 if (! is_elf_hash_table (hash_table
))
2607 bed
= get_elf_backend_data (hash_table
->dynobj
);
2608 s
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
2609 BFD_ASSERT (s
!= NULL
);
2611 newsize
= s
->_raw_size
+ bed
->s
->sizeof_dyn
;
2612 newcontents
= bfd_realloc (s
->contents
, newsize
);
2613 if (newcontents
== NULL
)
2617 dyn
.d_un
.d_val
= val
;
2618 bed
->s
->swap_dyn_out (hash_table
->dynobj
, &dyn
, newcontents
+ s
->_raw_size
);
2620 s
->_raw_size
= newsize
;
2621 s
->contents
= newcontents
;
2626 /* Add a DT_NEEDED entry for this dynamic object if DO_IT is true,
2627 otherwise just check whether one already exists. Returns -1 on error,
2628 1 if a DT_NEEDED tag already exists, and 0 on success. */
2631 elf_add_dt_needed_tag (struct bfd_link_info
*info
,
2635 struct elf_link_hash_table
*hash_table
;
2636 bfd_size_type oldsize
;
2637 bfd_size_type strindex
;
2639 hash_table
= elf_hash_table (info
);
2640 oldsize
= _bfd_elf_strtab_size (hash_table
->dynstr
);
2641 strindex
= _bfd_elf_strtab_add (hash_table
->dynstr
, soname
, FALSE
);
2642 if (strindex
== (bfd_size_type
) -1)
2645 if (oldsize
== _bfd_elf_strtab_size (hash_table
->dynstr
))
2648 const struct elf_backend_data
*bed
;
2651 bed
= get_elf_backend_data (hash_table
->dynobj
);
2652 sdyn
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
2653 BFD_ASSERT (sdyn
!= NULL
);
2655 for (extdyn
= sdyn
->contents
;
2656 extdyn
< sdyn
->contents
+ sdyn
->_raw_size
;
2657 extdyn
+= bed
->s
->sizeof_dyn
)
2659 Elf_Internal_Dyn dyn
;
2661 bed
->s
->swap_dyn_in (hash_table
->dynobj
, extdyn
, &dyn
);
2662 if (dyn
.d_tag
== DT_NEEDED
2663 && dyn
.d_un
.d_val
== strindex
)
2665 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
2673 if (!_bfd_elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
2677 /* We were just checking for existence of the tag. */
2678 _bfd_elf_strtab_delref (hash_table
->dynstr
, strindex
);
2683 /* Sort symbol by value and section. */
2685 elf_sort_symbol (const void *arg1
, const void *arg2
)
2687 const struct elf_link_hash_entry
*h1
;
2688 const struct elf_link_hash_entry
*h2
;
2689 bfd_signed_vma vdiff
;
2691 h1
= *(const struct elf_link_hash_entry
**) arg1
;
2692 h2
= *(const struct elf_link_hash_entry
**) arg2
;
2693 vdiff
= h1
->root
.u
.def
.value
- h2
->root
.u
.def
.value
;
2695 return vdiff
> 0 ? 1 : -1;
2698 long sdiff
= h1
->root
.u
.def
.section
- h2
->root
.u
.def
.section
;
2700 return sdiff
> 0 ? 1 : -1;
2705 /* This function is used to adjust offsets into .dynstr for
2706 dynamic symbols. This is called via elf_link_hash_traverse. */
2709 elf_adjust_dynstr_offsets (struct elf_link_hash_entry
*h
, void *data
)
2711 struct elf_strtab_hash
*dynstr
= data
;
2713 if (h
->root
.type
== bfd_link_hash_warning
)
2714 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
2716 if (h
->dynindx
!= -1)
2717 h
->dynstr_index
= _bfd_elf_strtab_offset (dynstr
, h
->dynstr_index
);
2721 /* Assign string offsets in .dynstr, update all structures referencing
2725 elf_finalize_dynstr (bfd
*output_bfd
, struct bfd_link_info
*info
)
2727 struct elf_link_hash_table
*hash_table
= elf_hash_table (info
);
2728 struct elf_link_local_dynamic_entry
*entry
;
2729 struct elf_strtab_hash
*dynstr
= hash_table
->dynstr
;
2730 bfd
*dynobj
= hash_table
->dynobj
;
2733 const struct elf_backend_data
*bed
;
2736 _bfd_elf_strtab_finalize (dynstr
);
2737 size
= _bfd_elf_strtab_size (dynstr
);
2739 bed
= get_elf_backend_data (dynobj
);
2740 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
2741 BFD_ASSERT (sdyn
!= NULL
);
2743 /* Update all .dynamic entries referencing .dynstr strings. */
2744 for (extdyn
= sdyn
->contents
;
2745 extdyn
< sdyn
->contents
+ sdyn
->_raw_size
;
2746 extdyn
+= bed
->s
->sizeof_dyn
)
2748 Elf_Internal_Dyn dyn
;
2750 bed
->s
->swap_dyn_in (dynobj
, extdyn
, &dyn
);
2754 dyn
.d_un
.d_val
= size
;
2762 dyn
.d_un
.d_val
= _bfd_elf_strtab_offset (dynstr
, dyn
.d_un
.d_val
);
2767 bed
->s
->swap_dyn_out (dynobj
, &dyn
, extdyn
);
2770 /* Now update local dynamic symbols. */
2771 for (entry
= hash_table
->dynlocal
; entry
; entry
= entry
->next
)
2772 entry
->isym
.st_name
= _bfd_elf_strtab_offset (dynstr
,
2773 entry
->isym
.st_name
);
2775 /* And the rest of dynamic symbols. */
2776 elf_link_hash_traverse (hash_table
, elf_adjust_dynstr_offsets
, dynstr
);
2778 /* Adjust version definitions. */
2779 if (elf_tdata (output_bfd
)->cverdefs
)
2784 Elf_Internal_Verdef def
;
2785 Elf_Internal_Verdaux defaux
;
2787 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
2791 _bfd_elf_swap_verdef_in (output_bfd
, (Elf_External_Verdef
*) p
,
2793 p
+= sizeof (Elf_External_Verdef
);
2794 for (i
= 0; i
< def
.vd_cnt
; ++i
)
2796 _bfd_elf_swap_verdaux_in (output_bfd
,
2797 (Elf_External_Verdaux
*) p
, &defaux
);
2798 defaux
.vda_name
= _bfd_elf_strtab_offset (dynstr
,
2800 _bfd_elf_swap_verdaux_out (output_bfd
,
2801 &defaux
, (Elf_External_Verdaux
*) p
);
2802 p
+= sizeof (Elf_External_Verdaux
);
2805 while (def
.vd_next
);
2808 /* Adjust version references. */
2809 if (elf_tdata (output_bfd
)->verref
)
2814 Elf_Internal_Verneed need
;
2815 Elf_Internal_Vernaux needaux
;
2817 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
2821 _bfd_elf_swap_verneed_in (output_bfd
, (Elf_External_Verneed
*) p
,
2823 need
.vn_file
= _bfd_elf_strtab_offset (dynstr
, need
.vn_file
);
2824 _bfd_elf_swap_verneed_out (output_bfd
, &need
,
2825 (Elf_External_Verneed
*) p
);
2826 p
+= sizeof (Elf_External_Verneed
);
2827 for (i
= 0; i
< need
.vn_cnt
; ++i
)
2829 _bfd_elf_swap_vernaux_in (output_bfd
,
2830 (Elf_External_Vernaux
*) p
, &needaux
);
2831 needaux
.vna_name
= _bfd_elf_strtab_offset (dynstr
,
2833 _bfd_elf_swap_vernaux_out (output_bfd
,
2835 (Elf_External_Vernaux
*) p
);
2836 p
+= sizeof (Elf_External_Vernaux
);
2839 while (need
.vn_next
);
2845 /* Add symbols from an ELF object file to the linker hash table. */
2848 elf_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
2850 bfd_boolean (*add_symbol_hook
)
2851 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Sym
*,
2852 const char **, flagword
*, asection
**, bfd_vma
*);
2853 bfd_boolean (*check_relocs
)
2854 (bfd
*, struct bfd_link_info
*, asection
*, const Elf_Internal_Rela
*);
2855 bfd_boolean collect
;
2856 Elf_Internal_Shdr
*hdr
;
2857 bfd_size_type symcount
;
2858 bfd_size_type extsymcount
;
2859 bfd_size_type extsymoff
;
2860 struct elf_link_hash_entry
**sym_hash
;
2861 bfd_boolean dynamic
;
2862 Elf_External_Versym
*extversym
= NULL
;
2863 Elf_External_Versym
*ever
;
2864 struct elf_link_hash_entry
*weaks
;
2865 struct elf_link_hash_entry
**nondeflt_vers
= NULL
;
2866 bfd_size_type nondeflt_vers_cnt
= 0;
2867 Elf_Internal_Sym
*isymbuf
= NULL
;
2868 Elf_Internal_Sym
*isym
;
2869 Elf_Internal_Sym
*isymend
;
2870 const struct elf_backend_data
*bed
;
2871 bfd_boolean add_needed
;
2872 struct elf_link_hash_table
* hash_table
;
2875 hash_table
= elf_hash_table (info
);
2877 bed
= get_elf_backend_data (abfd
);
2878 add_symbol_hook
= bed
->elf_add_symbol_hook
;
2879 collect
= bed
->collect
;
2881 if ((abfd
->flags
& DYNAMIC
) == 0)
2887 /* You can't use -r against a dynamic object. Also, there's no
2888 hope of using a dynamic object which does not exactly match
2889 the format of the output file. */
2890 if (info
->relocatable
2891 || !is_elf_hash_table (hash_table
)
2892 || hash_table
->root
.creator
!= abfd
->xvec
)
2894 bfd_set_error (bfd_error_invalid_operation
);
2899 /* As a GNU extension, any input sections which are named
2900 .gnu.warning.SYMBOL are treated as warning symbols for the given
2901 symbol. This differs from .gnu.warning sections, which generate
2902 warnings when they are included in an output file. */
2903 if (info
->executable
)
2907 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2911 name
= bfd_get_section_name (abfd
, s
);
2912 if (strncmp (name
, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0)
2916 bfd_size_type prefix_len
;
2917 const char * gnu_warning_prefix
= _("warning: ");
2919 name
+= sizeof ".gnu.warning." - 1;
2921 /* If this is a shared object, then look up the symbol
2922 in the hash table. If it is there, and it is already
2923 been defined, then we will not be using the entry
2924 from this shared object, so we don't need to warn.
2925 FIXME: If we see the definition in a regular object
2926 later on, we will warn, but we shouldn't. The only
2927 fix is to keep track of what warnings we are supposed
2928 to emit, and then handle them all at the end of the
2932 struct elf_link_hash_entry
*h
;
2934 h
= elf_link_hash_lookup (hash_table
, name
,
2935 FALSE
, FALSE
, TRUE
);
2937 /* FIXME: What about bfd_link_hash_common? */
2939 && (h
->root
.type
== bfd_link_hash_defined
2940 || h
->root
.type
== bfd_link_hash_defweak
))
2942 /* We don't want to issue this warning. Clobber
2943 the section size so that the warning does not
2944 get copied into the output file. */
2950 sz
= bfd_section_size (abfd
, s
);
2951 prefix_len
= strlen (gnu_warning_prefix
);
2952 msg
= bfd_alloc (abfd
, prefix_len
+ sz
+ 1);
2956 strcpy (msg
, gnu_warning_prefix
);
2957 if (! bfd_get_section_contents (abfd
, s
, msg
+ prefix_len
, 0, sz
))
2960 msg
[prefix_len
+ sz
] = '\0';
2962 if (! (_bfd_generic_link_add_one_symbol
2963 (info
, abfd
, name
, BSF_WARNING
, s
, 0, msg
,
2964 FALSE
, collect
, NULL
)))
2967 if (! info
->relocatable
)
2969 /* Clobber the section size so that the warning does
2970 not get copied into the output file. */
2980 /* If we are creating a shared library, create all the dynamic
2981 sections immediately. We need to attach them to something,
2982 so we attach them to this BFD, provided it is the right
2983 format. FIXME: If there are no input BFD's of the same
2984 format as the output, we can't make a shared library. */
2986 && is_elf_hash_table (hash_table
)
2987 && hash_table
->root
.creator
== abfd
->xvec
2988 && ! hash_table
->dynamic_sections_created
)
2990 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
2994 else if (!is_elf_hash_table (hash_table
))
2999 const char *soname
= NULL
;
3000 struct bfd_link_needed_list
*rpath
= NULL
, *runpath
= NULL
;
3003 /* ld --just-symbols and dynamic objects don't mix very well.
3004 Test for --just-symbols by looking at info set up by
3005 _bfd_elf_link_just_syms. */
3006 if ((s
= abfd
->sections
) != NULL
3007 && s
->sec_info_type
== ELF_INFO_TYPE_JUST_SYMS
)
3010 /* If this dynamic lib was specified on the command line with
3011 --as-needed in effect, then we don't want to add a DT_NEEDED
3012 tag unless the lib is actually used. Similary for libs brought
3013 in by another lib's DT_NEEDED. */
3014 add_needed
= elf_dyn_lib_class (abfd
) == DYN_NORMAL
;
3016 s
= bfd_get_section_by_name (abfd
, ".dynamic");
3022 unsigned long shlink
;
3024 dynbuf
= bfd_malloc (s
->_raw_size
);
3028 if (! bfd_get_section_contents (abfd
, s
, dynbuf
, 0, s
->_raw_size
))
3029 goto error_free_dyn
;
3031 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
3033 goto error_free_dyn
;
3034 shlink
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
3036 for (extdyn
= dynbuf
;
3037 extdyn
< dynbuf
+ s
->_raw_size
;
3038 extdyn
+= bed
->s
->sizeof_dyn
)
3040 Elf_Internal_Dyn dyn
;
3042 bed
->s
->swap_dyn_in (abfd
, extdyn
, &dyn
);
3043 if (dyn
.d_tag
== DT_SONAME
)
3045 unsigned int tagv
= dyn
.d_un
.d_val
;
3046 soname
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3048 goto error_free_dyn
;
3050 if (dyn
.d_tag
== DT_NEEDED
)
3052 struct bfd_link_needed_list
*n
, **pn
;
3054 unsigned int tagv
= dyn
.d_un
.d_val
;
3056 amt
= sizeof (struct bfd_link_needed_list
);
3057 n
= bfd_alloc (abfd
, amt
);
3058 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3059 if (n
== NULL
|| fnm
== NULL
)
3060 goto error_free_dyn
;
3061 amt
= strlen (fnm
) + 1;
3062 anm
= bfd_alloc (abfd
, amt
);
3064 goto error_free_dyn
;
3065 memcpy (anm
, fnm
, amt
);
3069 for (pn
= & hash_table
->needed
;
3075 if (dyn
.d_tag
== DT_RUNPATH
)
3077 struct bfd_link_needed_list
*n
, **pn
;
3079 unsigned int tagv
= dyn
.d_un
.d_val
;
3081 amt
= sizeof (struct bfd_link_needed_list
);
3082 n
= bfd_alloc (abfd
, amt
);
3083 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3084 if (n
== NULL
|| fnm
== NULL
)
3085 goto error_free_dyn
;
3086 amt
= strlen (fnm
) + 1;
3087 anm
= bfd_alloc (abfd
, amt
);
3089 goto error_free_dyn
;
3090 memcpy (anm
, fnm
, amt
);
3094 for (pn
= & runpath
;
3100 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */
3101 if (!runpath
&& dyn
.d_tag
== DT_RPATH
)
3103 struct bfd_link_needed_list
*n
, **pn
;
3105 unsigned int tagv
= dyn
.d_un
.d_val
;
3107 amt
= sizeof (struct bfd_link_needed_list
);
3108 n
= bfd_alloc (abfd
, amt
);
3109 fnm
= bfd_elf_string_from_elf_section (abfd
, shlink
, tagv
);
3110 if (n
== NULL
|| fnm
== NULL
)
3111 goto error_free_dyn
;
3112 amt
= strlen (fnm
) + 1;
3113 anm
= bfd_alloc (abfd
, amt
);
3120 memcpy (anm
, fnm
, amt
);
3135 /* DT_RUNPATH overrides DT_RPATH. Do _NOT_ bfd_release, as that
3136 frees all more recently bfd_alloc'd blocks as well. */
3142 struct bfd_link_needed_list
**pn
;
3143 for (pn
= & hash_table
->runpath
;
3150 /* We do not want to include any of the sections in a dynamic
3151 object in the output file. We hack by simply clobbering the
3152 list of sections in the BFD. This could be handled more
3153 cleanly by, say, a new section flag; the existing
3154 SEC_NEVER_LOAD flag is not the one we want, because that one
3155 still implies that the section takes up space in the output
3157 bfd_section_list_clear (abfd
);
3159 /* If this is the first dynamic object found in the link, create
3160 the special sections required for dynamic linking. */
3161 if (! _bfd_elf_link_create_dynamic_sections (abfd
, info
))
3164 /* Find the name to use in a DT_NEEDED entry that refers to this
3165 object. If the object has a DT_SONAME entry, we use it.
3166 Otherwise, if the generic linker stuck something in
3167 elf_dt_name, we use that. Otherwise, we just use the file
3169 if (soname
== NULL
|| *soname
== '\0')
3171 soname
= elf_dt_name (abfd
);
3172 if (soname
== NULL
|| *soname
== '\0')
3173 soname
= bfd_get_filename (abfd
);
3176 /* Save the SONAME because sometimes the linker emulation code
3177 will need to know it. */
3178 elf_dt_name (abfd
) = soname
;
3180 ret
= elf_add_dt_needed_tag (info
, soname
, add_needed
);
3184 /* If we have already included this dynamic object in the
3185 link, just ignore it. There is no reason to include a
3186 particular dynamic object more than once. */
3191 /* If this is a dynamic object, we always link against the .dynsym
3192 symbol table, not the .symtab symbol table. The dynamic linker
3193 will only see the .dynsym symbol table, so there is no reason to
3194 look at .symtab for a dynamic object. */
3196 if (! dynamic
|| elf_dynsymtab (abfd
) == 0)
3197 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
3199 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
3201 symcount
= hdr
->sh_size
/ bed
->s
->sizeof_sym
;
3203 /* The sh_info field of the symtab header tells us where the
3204 external symbols start. We don't care about the local symbols at
3206 if (elf_bad_symtab (abfd
))
3208 extsymcount
= symcount
;
3213 extsymcount
= symcount
- hdr
->sh_info
;
3214 extsymoff
= hdr
->sh_info
;
3218 if (extsymcount
!= 0)
3220 isymbuf
= bfd_elf_get_elf_syms (abfd
, hdr
, extsymcount
, extsymoff
,
3222 if (isymbuf
== NULL
)
3225 /* We store a pointer to the hash table entry for each external
3227 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3228 sym_hash
= bfd_alloc (abfd
, amt
);
3229 if (sym_hash
== NULL
)
3230 goto error_free_sym
;
3231 elf_sym_hashes (abfd
) = sym_hash
;
3236 /* Read in any version definitions. */
3237 if (! _bfd_elf_slurp_version_tables (abfd
))
3238 goto error_free_sym
;
3240 /* Read in the symbol versions, but don't bother to convert them
3241 to internal format. */
3242 if (elf_dynversym (abfd
) != 0)
3244 Elf_Internal_Shdr
*versymhdr
;
3246 versymhdr
= &elf_tdata (abfd
)->dynversym_hdr
;
3247 extversym
= bfd_malloc (versymhdr
->sh_size
);
3248 if (extversym
== NULL
)
3249 goto error_free_sym
;
3250 amt
= versymhdr
->sh_size
;
3251 if (bfd_seek (abfd
, versymhdr
->sh_offset
, SEEK_SET
) != 0
3252 || bfd_bread (extversym
, amt
, abfd
) != amt
)
3253 goto error_free_vers
;
3259 ever
= extversym
!= NULL
? extversym
+ extsymoff
: NULL
;
3260 for (isym
= isymbuf
, isymend
= isymbuf
+ extsymcount
;
3262 isym
++, sym_hash
++, ever
= (ever
!= NULL
? ever
+ 1 : NULL
))
3269 struct elf_link_hash_entry
*h
;
3270 bfd_boolean definition
;
3271 bfd_boolean size_change_ok
;
3272 bfd_boolean type_change_ok
;
3273 bfd_boolean new_weakdef
;
3274 bfd_boolean override
;
3275 unsigned int old_alignment
;
3280 flags
= BSF_NO_FLAGS
;
3282 value
= isym
->st_value
;
3285 bind
= ELF_ST_BIND (isym
->st_info
);
3286 if (bind
== STB_LOCAL
)
3288 /* This should be impossible, since ELF requires that all
3289 global symbols follow all local symbols, and that sh_info
3290 point to the first global symbol. Unfortunately, Irix 5
3294 else if (bind
== STB_GLOBAL
)
3296 if (isym
->st_shndx
!= SHN_UNDEF
3297 && isym
->st_shndx
!= SHN_COMMON
)
3300 else if (bind
== STB_WEAK
)
3304 /* Leave it up to the processor backend. */
3307 if (isym
->st_shndx
== SHN_UNDEF
)
3308 sec
= bfd_und_section_ptr
;
3309 else if (isym
->st_shndx
< SHN_LORESERVE
|| isym
->st_shndx
> SHN_HIRESERVE
)
3311 sec
= bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
3313 sec
= bfd_abs_section_ptr
;
3314 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
3317 else if (isym
->st_shndx
== SHN_ABS
)
3318 sec
= bfd_abs_section_ptr
;
3319 else if (isym
->st_shndx
== SHN_COMMON
)
3321 sec
= bfd_com_section_ptr
;
3322 /* What ELF calls the size we call the value. What ELF
3323 calls the value we call the alignment. */
3324 value
= isym
->st_size
;
3328 /* Leave it up to the processor backend. */
3331 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
,
3334 goto error_free_vers
;
3336 if (isym
->st_shndx
== SHN_COMMON
3337 && ELF_ST_TYPE (isym
->st_info
) == STT_TLS
)
3339 asection
*tcomm
= bfd_get_section_by_name (abfd
, ".tcommon");
3343 tcomm
= bfd_make_section (abfd
, ".tcommon");
3345 || !bfd_set_section_flags (abfd
, tcomm
, (SEC_ALLOC
3347 | SEC_LINKER_CREATED
3348 | SEC_THREAD_LOCAL
)))
3349 goto error_free_vers
;
3353 else if (add_symbol_hook
)
3355 if (! (*add_symbol_hook
) (abfd
, info
, isym
, &name
, &flags
, &sec
,
3357 goto error_free_vers
;
3359 /* The hook function sets the name to NULL if this symbol
3360 should be skipped for some reason. */
3365 /* Sanity check that all possibilities were handled. */
3368 bfd_set_error (bfd_error_bad_value
);
3369 goto error_free_vers
;
3372 if (bfd_is_und_section (sec
)
3373 || bfd_is_com_section (sec
))
3378 size_change_ok
= FALSE
;
3379 type_change_ok
= get_elf_backend_data (abfd
)->type_change_ok
;
3383 if (is_elf_hash_table (hash_table
))
3385 Elf_Internal_Versym iver
;
3386 unsigned int vernum
= 0;
3391 _bfd_elf_swap_versym_in (abfd
, ever
, &iver
);
3392 vernum
= iver
.vs_vers
& VERSYM_VERSION
;
3394 /* If this is a hidden symbol, or if it is not version
3395 1, we append the version name to the symbol name.
3396 However, we do not modify a non-hidden absolute
3397 symbol, because it might be the version symbol
3398 itself. FIXME: What if it isn't? */
3399 if ((iver
.vs_vers
& VERSYM_HIDDEN
) != 0
3400 || (vernum
> 1 && ! bfd_is_abs_section (sec
)))
3403 size_t namelen
, verlen
, newlen
;
3406 if (isym
->st_shndx
!= SHN_UNDEF
)
3408 if (vernum
> elf_tdata (abfd
)->dynverdef_hdr
.sh_info
)
3410 (*_bfd_error_handler
)
3411 (_("%s: %s: invalid version %u (max %d)"),
3412 bfd_archive_filename (abfd
), name
, vernum
,
3413 elf_tdata (abfd
)->dynverdef_hdr
.sh_info
);
3414 bfd_set_error (bfd_error_bad_value
);
3415 goto error_free_vers
;
3417 else if (vernum
> 1)
3419 elf_tdata (abfd
)->verdef
[vernum
- 1].vd_nodename
;
3425 /* We cannot simply test for the number of
3426 entries in the VERNEED section since the
3427 numbers for the needed versions do not start
3429 Elf_Internal_Verneed
*t
;
3432 for (t
= elf_tdata (abfd
)->verref
;
3436 Elf_Internal_Vernaux
*a
;
3438 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3440 if (a
->vna_other
== vernum
)
3442 verstr
= a
->vna_nodename
;
3451 (*_bfd_error_handler
)
3452 (_("%s: %s: invalid needed version %d"),
3453 bfd_archive_filename (abfd
), name
, vernum
);
3454 bfd_set_error (bfd_error_bad_value
);
3455 goto error_free_vers
;
3459 namelen
= strlen (name
);
3460 verlen
= strlen (verstr
);
3461 newlen
= namelen
+ verlen
+ 2;
3462 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
3463 && isym
->st_shndx
!= SHN_UNDEF
)
3466 newname
= bfd_alloc (abfd
, newlen
);
3467 if (newname
== NULL
)
3468 goto error_free_vers
;
3469 memcpy (newname
, name
, namelen
);
3470 p
= newname
+ namelen
;
3472 /* If this is a defined non-hidden version symbol,
3473 we add another @ to the name. This indicates the
3474 default version of the symbol. */
3475 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
3476 && isym
->st_shndx
!= SHN_UNDEF
)
3478 memcpy (p
, verstr
, verlen
+ 1);
3484 if (!_bfd_elf_merge_symbol (abfd
, info
, name
, isym
, &sec
, &value
,
3485 sym_hash
, &skip
, &override
,
3486 &type_change_ok
, &size_change_ok
))
3487 goto error_free_vers
;
3496 while (h
->root
.type
== bfd_link_hash_indirect
3497 || h
->root
.type
== bfd_link_hash_warning
)
3498 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3500 /* Remember the old alignment if this is a common symbol, so
3501 that we don't reduce the alignment later on. We can't
3502 check later, because _bfd_generic_link_add_one_symbol
3503 will set a default for the alignment which we want to
3504 override. We also remember the old bfd where the existing
3505 definition comes from. */
3506 switch (h
->root
.type
)
3511 case bfd_link_hash_defined
:
3512 case bfd_link_hash_defweak
:
3513 old_bfd
= h
->root
.u
.def
.section
->owner
;
3516 case bfd_link_hash_common
:
3517 old_bfd
= h
->root
.u
.c
.p
->section
->owner
;
3518 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
3522 if (elf_tdata (abfd
)->verdef
!= NULL
3526 h
->verinfo
.verdef
= &elf_tdata (abfd
)->verdef
[vernum
- 1];
3529 if (! (_bfd_generic_link_add_one_symbol
3530 (info
, abfd
, name
, flags
, sec
, value
, NULL
, FALSE
, collect
,
3531 (struct bfd_link_hash_entry
**) sym_hash
)))
3532 goto error_free_vers
;
3535 while (h
->root
.type
== bfd_link_hash_indirect
3536 || h
->root
.type
== bfd_link_hash_warning
)
3537 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3540 new_weakdef
= FALSE
;
3543 && (flags
& BSF_WEAK
) != 0
3544 && ELF_ST_TYPE (isym
->st_info
) != STT_FUNC
3545 && is_elf_hash_table (hash_table
)
3546 && h
->weakdef
== NULL
)
3548 /* Keep a list of all weak defined non function symbols from
3549 a dynamic object, using the weakdef field. Later in this
3550 function we will set the weakdef field to the correct
3551 value. We only put non-function symbols from dynamic
3552 objects on this list, because that happens to be the only
3553 time we need to know the normal symbol corresponding to a
3554 weak symbol, and the information is time consuming to
3555 figure out. If the weakdef field is not already NULL,
3556 then this symbol was already defined by some previous
3557 dynamic object, and we will be using that previous
3558 definition anyhow. */
3565 /* Set the alignment of a common symbol. */
3566 if (isym
->st_shndx
== SHN_COMMON
3567 && h
->root
.type
== bfd_link_hash_common
)
3571 align
= bfd_log2 (isym
->st_value
);
3572 if (align
> old_alignment
3573 /* Permit an alignment power of zero if an alignment of one
3574 is specified and no other alignments have been specified. */
3575 || (isym
->st_value
== 1 && old_alignment
== 0))
3576 h
->root
.u
.c
.p
->alignment_power
= align
;
3578 h
->root
.u
.c
.p
->alignment_power
= old_alignment
;
3581 if (is_elf_hash_table (hash_table
))
3587 /* Check the alignment when a common symbol is involved. This
3588 can change when a common symbol is overridden by a normal
3589 definition or a common symbol is ignored due to the old
3590 normal definition. We need to make sure the maximum
3591 alignment is maintained. */
3592 if ((old_alignment
|| isym
->st_shndx
== SHN_COMMON
)
3593 && h
->root
.type
!= bfd_link_hash_common
)
3595 unsigned int common_align
;
3596 unsigned int normal_align
;
3597 unsigned int symbol_align
;
3601 symbol_align
= ffs (h
->root
.u
.def
.value
) - 1;
3602 if (h
->root
.u
.def
.section
->owner
!= NULL
3603 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
3605 normal_align
= h
->root
.u
.def
.section
->alignment_power
;
3606 if (normal_align
> symbol_align
)
3607 normal_align
= symbol_align
;
3610 normal_align
= symbol_align
;
3614 common_align
= old_alignment
;
3615 common_bfd
= old_bfd
;
3620 common_align
= bfd_log2 (isym
->st_value
);
3622 normal_bfd
= old_bfd
;
3625 if (normal_align
< common_align
)
3626 (*_bfd_error_handler
)
3627 (_("Warning: alignment %u of symbol `%s' in %s is smaller than %u in %s"),
3630 bfd_archive_filename (normal_bfd
),
3632 bfd_archive_filename (common_bfd
));
3635 /* Remember the symbol size and type. */
3636 if (isym
->st_size
!= 0
3637 && (definition
|| h
->size
== 0))
3639 if (h
->size
!= 0 && h
->size
!= isym
->st_size
&& ! size_change_ok
)
3640 (*_bfd_error_handler
)
3641 (_("Warning: size of symbol `%s' changed from %lu in %s to %lu in %s"),
3642 name
, (unsigned long) h
->size
,
3643 bfd_archive_filename (old_bfd
),
3644 (unsigned long) isym
->st_size
,
3645 bfd_archive_filename (abfd
));
3647 h
->size
= isym
->st_size
;
3650 /* If this is a common symbol, then we always want H->SIZE
3651 to be the size of the common symbol. The code just above
3652 won't fix the size if a common symbol becomes larger. We
3653 don't warn about a size change here, because that is
3654 covered by --warn-common. */
3655 if (h
->root
.type
== bfd_link_hash_common
)
3656 h
->size
= h
->root
.u
.c
.size
;
3658 if (ELF_ST_TYPE (isym
->st_info
) != STT_NOTYPE
3659 && (definition
|| h
->type
== STT_NOTYPE
))
3661 if (h
->type
!= STT_NOTYPE
3662 && h
->type
!= ELF_ST_TYPE (isym
->st_info
)
3663 && ! type_change_ok
)
3664 (*_bfd_error_handler
)
3665 (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
3666 name
, h
->type
, ELF_ST_TYPE (isym
->st_info
),
3667 bfd_archive_filename (abfd
));
3669 h
->type
= ELF_ST_TYPE (isym
->st_info
);
3672 /* If st_other has a processor-specific meaning, specific
3673 code might be needed here. We never merge the visibility
3674 attribute with the one from a dynamic object. */
3675 if (bed
->elf_backend_merge_symbol_attribute
)
3676 (*bed
->elf_backend_merge_symbol_attribute
) (h
, isym
, definition
,
3679 if (isym
->st_other
!= 0 && !dynamic
)
3681 unsigned char hvis
, symvis
, other
, nvis
;
3683 /* Take the balance of OTHER from the definition. */
3684 other
= (definition
? isym
->st_other
: h
->other
);
3685 other
&= ~ ELF_ST_VISIBILITY (-1);
3687 /* Combine visibilities, using the most constraining one. */
3688 hvis
= ELF_ST_VISIBILITY (h
->other
);
3689 symvis
= ELF_ST_VISIBILITY (isym
->st_other
);
3695 nvis
= hvis
< symvis
? hvis
: symvis
;
3697 h
->other
= other
| nvis
;
3700 /* Set a flag in the hash table entry indicating the type of
3701 reference or definition we just found. Keep a count of
3702 the number of dynamic symbols we find. A dynamic symbol
3703 is one which is referenced or defined by both a regular
3704 object and a shared object. */
3705 old_flags
= h
->elf_link_hash_flags
;
3711 new_flag
= ELF_LINK_HASH_REF_REGULAR
;
3712 if (bind
!= STB_WEAK
)
3713 new_flag
|= ELF_LINK_HASH_REF_REGULAR_NONWEAK
;
3716 new_flag
= ELF_LINK_HASH_DEF_REGULAR
;
3717 if (! info
->executable
3718 || (old_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
3719 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0)
3725 new_flag
= ELF_LINK_HASH_REF_DYNAMIC
;
3727 new_flag
= ELF_LINK_HASH_DEF_DYNAMIC
;
3728 if ((old_flags
& (ELF_LINK_HASH_DEF_REGULAR
3729 | ELF_LINK_HASH_REF_REGULAR
)) != 0
3730 || (h
->weakdef
!= NULL
3732 && h
->weakdef
->dynindx
!= -1))
3736 h
->elf_link_hash_flags
|= new_flag
;
3738 /* Check to see if we need to add an indirect symbol for
3739 the default name. */
3740 if (definition
|| h
->root
.type
== bfd_link_hash_common
)
3741 if (!_bfd_elf_add_default_symbol (abfd
, info
, h
, name
, isym
,
3742 &sec
, &value
, &dynsym
,
3744 goto error_free_vers
;
3746 if (definition
&& !dynamic
)
3748 char *p
= strchr (name
, ELF_VER_CHR
);
3749 if (p
!= NULL
&& p
[1] != ELF_VER_CHR
)
3751 /* Queue non-default versions so that .symver x, x@FOO
3752 aliases can be checked. */
3753 if (! nondeflt_vers
)
3755 amt
= (isymend
- isym
+ 1)
3756 * sizeof (struct elf_link_hash_entry
*);
3757 nondeflt_vers
= bfd_malloc (amt
);
3759 nondeflt_vers
[nondeflt_vers_cnt
++] = h
;
3763 if (dynsym
&& h
->dynindx
== -1)
3765 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3766 goto error_free_vers
;
3767 if (h
->weakdef
!= NULL
3769 && h
->weakdef
->dynindx
== -1)
3771 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
3772 goto error_free_vers
;
3775 else if (dynsym
&& h
->dynindx
!= -1)
3776 /* If the symbol already has a dynamic index, but
3777 visibility says it should not be visible, turn it into
3779 switch (ELF_ST_VISIBILITY (h
->other
))
3783 (*bed
->elf_backend_hide_symbol
) (info
, h
, TRUE
);
3791 && (h
->elf_link_hash_flags
3792 & ELF_LINK_HASH_REF_REGULAR
) != 0)
3795 const char *soname
= elf_dt_name (abfd
);
3797 /* A symbol from a library loaded via DT_NEEDED of some
3798 other library is referenced by a regular object.
3799 Add a DT_NEEDED entry for it. */
3801 ret
= elf_add_dt_needed_tag (info
, soname
, add_needed
);
3803 goto error_free_vers
;
3805 BFD_ASSERT (ret
== 0);
3810 /* Now that all the symbols from this input file are created, handle
3811 .symver foo, foo@BAR such that any relocs against foo become foo@BAR. */
3812 if (nondeflt_vers
!= NULL
)
3814 bfd_size_type cnt
, symidx
;
3816 for (cnt
= 0; cnt
< nondeflt_vers_cnt
; ++cnt
)
3818 struct elf_link_hash_entry
*h
= nondeflt_vers
[cnt
], *hi
;
3819 char *shortname
, *p
;
3821 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
3823 || (h
->root
.type
!= bfd_link_hash_defined
3824 && h
->root
.type
!= bfd_link_hash_defweak
))
3827 amt
= p
- h
->root
.root
.string
;
3828 shortname
= bfd_malloc (amt
+ 1);
3829 memcpy (shortname
, h
->root
.root
.string
, amt
);
3830 shortname
[amt
] = '\0';
3832 hi
= (struct elf_link_hash_entry
*)
3833 bfd_link_hash_lookup (&hash_table
->root
, shortname
,
3834 FALSE
, FALSE
, FALSE
);
3836 && hi
->root
.type
== h
->root
.type
3837 && hi
->root
.u
.def
.value
== h
->root
.u
.def
.value
3838 && hi
->root
.u
.def
.section
== h
->root
.u
.def
.section
)
3840 (*bed
->elf_backend_hide_symbol
) (info
, hi
, TRUE
);
3841 hi
->root
.type
= bfd_link_hash_indirect
;
3842 hi
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) h
;
3843 (*bed
->elf_backend_copy_indirect_symbol
) (bed
, h
, hi
);
3844 sym_hash
= elf_sym_hashes (abfd
);
3846 for (symidx
= 0; symidx
< extsymcount
; ++symidx
)
3847 if (sym_hash
[symidx
] == hi
)
3849 sym_hash
[symidx
] = h
;
3855 free (nondeflt_vers
);
3856 nondeflt_vers
= NULL
;
3859 if (extversym
!= NULL
)
3865 if (isymbuf
!= NULL
)
3869 /* Now set the weakdefs field correctly for all the weak defined
3870 symbols we found. The only way to do this is to search all the
3871 symbols. Since we only need the information for non functions in
3872 dynamic objects, that's the only time we actually put anything on
3873 the list WEAKS. We need this information so that if a regular
3874 object refers to a symbol defined weakly in a dynamic object, the
3875 real symbol in the dynamic object is also put in the dynamic
3876 symbols; we also must arrange for both symbols to point to the
3877 same memory location. We could handle the general case of symbol
3878 aliasing, but a general symbol alias can only be generated in
3879 assembler code, handling it correctly would be very time
3880 consuming, and other ELF linkers don't handle general aliasing
3884 struct elf_link_hash_entry
**hpp
;
3885 struct elf_link_hash_entry
**hppend
;
3886 struct elf_link_hash_entry
**sorted_sym_hash
;
3887 struct elf_link_hash_entry
*h
;
3890 /* Since we have to search the whole symbol list for each weak
3891 defined symbol, search time for N weak defined symbols will be
3892 O(N^2). Binary search will cut it down to O(NlogN). */
3893 amt
= extsymcount
* sizeof (struct elf_link_hash_entry
*);
3894 sorted_sym_hash
= bfd_malloc (amt
);
3895 if (sorted_sym_hash
== NULL
)
3897 sym_hash
= sorted_sym_hash
;
3898 hpp
= elf_sym_hashes (abfd
);
3899 hppend
= hpp
+ extsymcount
;
3901 for (; hpp
< hppend
; hpp
++)
3905 && h
->root
.type
== bfd_link_hash_defined
3906 && h
->type
!= STT_FUNC
)
3914 qsort (sorted_sym_hash
, sym_count
,
3915 sizeof (struct elf_link_hash_entry
*),
3918 while (weaks
!= NULL
)
3920 struct elf_link_hash_entry
*hlook
;
3927 weaks
= hlook
->weakdef
;
3928 hlook
->weakdef
= NULL
;
3930 BFD_ASSERT (hlook
->root
.type
== bfd_link_hash_defined
3931 || hlook
->root
.type
== bfd_link_hash_defweak
3932 || hlook
->root
.type
== bfd_link_hash_common
3933 || hlook
->root
.type
== bfd_link_hash_indirect
);
3934 slook
= hlook
->root
.u
.def
.section
;
3935 vlook
= hlook
->root
.u
.def
.value
;
3942 bfd_signed_vma vdiff
;
3944 h
= sorted_sym_hash
[idx
];
3945 vdiff
= vlook
- h
->root
.u
.def
.value
;
3952 long sdiff
= slook
- h
->root
.u
.def
.section
;
3965 /* We didn't find a value/section match. */
3969 for (i
= ilook
; i
< sym_count
; i
++)
3971 h
= sorted_sym_hash
[i
];
3973 /* Stop if value or section doesn't match. */
3974 if (h
->root
.u
.def
.value
!= vlook
3975 || h
->root
.u
.def
.section
!= slook
)
3977 else if (h
!= hlook
)
3981 /* If the weak definition is in the list of dynamic
3982 symbols, make sure the real definition is put
3984 if (hlook
->dynindx
!= -1 && h
->dynindx
== -1)
3986 if (! _bfd_elf_link_record_dynamic_symbol (info
,
3991 /* If the real definition is in the list of dynamic
3992 symbols, make sure the weak definition is put
3993 there as well. If we don't do this, then the
3994 dynamic loader might not merge the entries for the
3995 real definition and the weak definition. */
3996 if (h
->dynindx
!= -1 && hlook
->dynindx
== -1)
3998 if (! _bfd_elf_link_record_dynamic_symbol (info
,
4007 free (sorted_sym_hash
);
4010 /* If this object is the same format as the output object, and it is
4011 not a shared library, then let the backend look through the
4014 This is required to build global offset table entries and to
4015 arrange for dynamic relocs. It is not required for the
4016 particular common case of linking non PIC code, even when linking
4017 against shared libraries, but unfortunately there is no way of
4018 knowing whether an object file has been compiled PIC or not.
4019 Looking through the relocs is not particularly time consuming.
4020 The problem is that we must either (1) keep the relocs in memory,
4021 which causes the linker to require additional runtime memory or
4022 (2) read the relocs twice from the input file, which wastes time.
4023 This would be a good case for using mmap.
4025 I have no idea how to handle linking PIC code into a file of a
4026 different format. It probably can't be done. */
4027 check_relocs
= get_elf_backend_data (abfd
)->check_relocs
;
4029 && is_elf_hash_table (hash_table
)
4030 && hash_table
->root
.creator
== abfd
->xvec
4031 && check_relocs
!= NULL
)
4035 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4037 Elf_Internal_Rela
*internal_relocs
;
4040 if ((o
->flags
& SEC_RELOC
) == 0
4041 || o
->reloc_count
== 0
4042 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
4043 && (o
->flags
& SEC_DEBUGGING
) != 0)
4044 || bfd_is_abs_section (o
->output_section
))
4047 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
4049 if (internal_relocs
== NULL
)
4052 ok
= (*check_relocs
) (abfd
, info
, o
, internal_relocs
);
4054 if (elf_section_data (o
)->relocs
!= internal_relocs
)
4055 free (internal_relocs
);
4062 /* If this is a non-traditional link, try to optimize the handling
4063 of the .stab/.stabstr sections. */
4065 && ! info
->traditional_format
4066 && is_elf_hash_table (hash_table
)
4067 && (info
->strip
!= strip_all
&& info
->strip
!= strip_debugger
))
4071 stabstr
= bfd_get_section_by_name (abfd
, ".stabstr");
4072 if (stabstr
!= NULL
)
4074 bfd_size_type string_offset
= 0;
4077 for (stab
= abfd
->sections
; stab
; stab
= stab
->next
)
4078 if (strncmp (".stab", stab
->name
, 5) == 0
4079 && (!stab
->name
[5] ||
4080 (stab
->name
[5] == '.' && ISDIGIT (stab
->name
[6])))
4081 && (stab
->flags
& SEC_MERGE
) == 0
4082 && !bfd_is_abs_section (stab
->output_section
))
4084 struct bfd_elf_section_data
*secdata
;
4086 secdata
= elf_section_data (stab
);
4087 if (! _bfd_link_section_stabs (abfd
,
4088 & hash_table
->stab_info
,
4093 if (secdata
->sec_info
)
4094 stab
->sec_info_type
= ELF_INFO_TYPE_STABS
;
4099 if (! info
->relocatable
4101 && is_elf_hash_table (hash_table
))
4105 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4106 if ((s
->flags
& SEC_MERGE
) != 0
4107 && !bfd_is_abs_section (s
->output_section
))
4109 struct bfd_elf_section_data
*secdata
;
4111 secdata
= elf_section_data (s
);
4112 if (! _bfd_merge_section (abfd
,
4113 & hash_table
->merge_info
,
4114 s
, &secdata
->sec_info
))
4116 else if (secdata
->sec_info
)
4117 s
->sec_info_type
= ELF_INFO_TYPE_MERGE
;
4121 if (is_elf_hash_table (hash_table
))
4123 /* Add this bfd to the loaded list. */
4124 struct elf_link_loaded_list
*n
;
4126 n
= bfd_alloc (abfd
, sizeof (struct elf_link_loaded_list
));
4130 n
->next
= hash_table
->loaded
;
4131 hash_table
->loaded
= n
;
4137 if (nondeflt_vers
!= NULL
)
4138 free (nondeflt_vers
);
4139 if (extversym
!= NULL
)
4142 if (isymbuf
!= NULL
)
4148 /* Add symbols from an ELF archive file to the linker hash table. We
4149 don't use _bfd_generic_link_add_archive_symbols because of a
4150 problem which arises on UnixWare. The UnixWare libc.so is an
4151 archive which includes an entry libc.so.1 which defines a bunch of
4152 symbols. The libc.so archive also includes a number of other
4153 object files, which also define symbols, some of which are the same
4154 as those defined in libc.so.1. Correct linking requires that we
4155 consider each object file in turn, and include it if it defines any
4156 symbols we need. _bfd_generic_link_add_archive_symbols does not do
4157 this; it looks through the list of undefined symbols, and includes
4158 any object file which defines them. When this algorithm is used on
4159 UnixWare, it winds up pulling in libc.so.1 early and defining a
4160 bunch of symbols. This means that some of the other objects in the
4161 archive are not included in the link, which is incorrect since they
4162 precede libc.so.1 in the archive.
4164 Fortunately, ELF archive handling is simpler than that done by
4165 _bfd_generic_link_add_archive_symbols, which has to allow for a.out
4166 oddities. In ELF, if we find a symbol in the archive map, and the
4167 symbol is currently undefined, we know that we must pull in that
4170 Unfortunately, we do have to make multiple passes over the symbol
4171 table until nothing further is resolved. */
4174 elf_link_add_archive_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4177 bfd_boolean
*defined
= NULL
;
4178 bfd_boolean
*included
= NULL
;
4183 if (! bfd_has_map (abfd
))
4185 /* An empty archive is a special case. */
4186 if (bfd_openr_next_archived_file (abfd
, NULL
) == NULL
)
4188 bfd_set_error (bfd_error_no_armap
);
4192 /* Keep track of all symbols we know to be already defined, and all
4193 files we know to be already included. This is to speed up the
4194 second and subsequent passes. */
4195 c
= bfd_ardata (abfd
)->symdef_count
;
4199 amt
*= sizeof (bfd_boolean
);
4200 defined
= bfd_zmalloc (amt
);
4201 included
= bfd_zmalloc (amt
);
4202 if (defined
== NULL
|| included
== NULL
)
4205 symdefs
= bfd_ardata (abfd
)->symdefs
;
4218 symdefend
= symdef
+ c
;
4219 for (i
= 0; symdef
< symdefend
; symdef
++, i
++)
4221 struct elf_link_hash_entry
*h
;
4223 struct bfd_link_hash_entry
*undefs_tail
;
4226 if (defined
[i
] || included
[i
])
4228 if (symdef
->file_offset
== last
)
4234 h
= elf_link_hash_lookup (elf_hash_table (info
), symdef
->name
,
4235 FALSE
, FALSE
, FALSE
);
4242 /* If this is a default version (the name contains @@),
4243 look up the symbol again with only one `@' as well
4244 as without the version. The effect is that references
4245 to the symbol with and without the version will be
4246 matched by the default symbol in the archive. */
4248 p
= strchr (symdef
->name
, ELF_VER_CHR
);
4249 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
4252 /* First check with only one `@'. */
4253 len
= strlen (symdef
->name
);
4254 copy
= bfd_alloc (abfd
, len
);
4257 first
= p
- symdef
->name
+ 1;
4258 memcpy (copy
, symdef
->name
, first
);
4259 memcpy (copy
+ first
, symdef
->name
+ first
+ 1, len
- first
);
4261 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
,
4262 FALSE
, FALSE
, FALSE
);
4266 /* We also need to check references to the symbol
4267 without the version. */
4269 copy
[first
- 1] = '\0';
4270 h
= elf_link_hash_lookup (elf_hash_table (info
),
4271 copy
, FALSE
, FALSE
, FALSE
);
4274 bfd_release (abfd
, copy
);
4280 if (h
->root
.type
== bfd_link_hash_common
)
4282 /* We currently have a common symbol. The archive map contains
4283 a reference to this symbol, so we may want to include it. We
4284 only want to include it however, if this archive element
4285 contains a definition of the symbol, not just another common
4288 Unfortunately some archivers (including GNU ar) will put
4289 declarations of common symbols into their archive maps, as
4290 well as real definitions, so we cannot just go by the archive
4291 map alone. Instead we must read in the element's symbol
4292 table and check that to see what kind of symbol definition
4294 if (! elf_link_is_defined_archive_symbol (abfd
, symdef
))
4297 else if (h
->root
.type
!= bfd_link_hash_undefined
)
4299 if (h
->root
.type
!= bfd_link_hash_undefweak
)
4304 /* We need to include this archive member. */
4305 element
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
4306 if (element
== NULL
)
4309 if (! bfd_check_format (element
, bfd_object
))
4312 /* Doublecheck that we have not included this object
4313 already--it should be impossible, but there may be
4314 something wrong with the archive. */
4315 if (element
->archive_pass
!= 0)
4317 bfd_set_error (bfd_error_bad_value
);
4320 element
->archive_pass
= 1;
4322 undefs_tail
= info
->hash
->undefs_tail
;
4324 if (! (*info
->callbacks
->add_archive_element
) (info
, element
,
4327 if (! bfd_link_add_symbols (element
, info
))
4330 /* If there are any new undefined symbols, we need to make
4331 another pass through the archive in order to see whether
4332 they can be defined. FIXME: This isn't perfect, because
4333 common symbols wind up on undefs_tail and because an
4334 undefined symbol which is defined later on in this pass
4335 does not require another pass. This isn't a bug, but it
4336 does make the code less efficient than it could be. */
4337 if (undefs_tail
!= info
->hash
->undefs_tail
)
4340 /* Look backward to mark all symbols from this object file
4341 which we have already seen in this pass. */
4345 included
[mark
] = TRUE
;
4350 while (symdefs
[mark
].file_offset
== symdef
->file_offset
);
4352 /* We mark subsequent symbols from this object file as we go
4353 on through the loop. */
4354 last
= symdef
->file_offset
;
4365 if (defined
!= NULL
)
4367 if (included
!= NULL
)
4372 /* Given an ELF BFD, add symbols to the global hash table as
4376 bfd_elf_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
4378 switch (bfd_get_format (abfd
))
4381 return elf_link_add_object_symbols (abfd
, info
);
4383 return elf_link_add_archive_symbols (abfd
, info
);
4385 bfd_set_error (bfd_error_wrong_format
);
4390 /* This function will be called though elf_link_hash_traverse to store
4391 all hash value of the exported symbols in an array. */
4394 elf_collect_hash_codes (struct elf_link_hash_entry
*h
, void *data
)
4396 unsigned long **valuep
= data
;
4402 if (h
->root
.type
== bfd_link_hash_warning
)
4403 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
4405 /* Ignore indirect symbols. These are added by the versioning code. */
4406 if (h
->dynindx
== -1)
4409 name
= h
->root
.root
.string
;
4410 p
= strchr (name
, ELF_VER_CHR
);
4413 alc
= bfd_malloc (p
- name
+ 1);
4414 memcpy (alc
, name
, p
- name
);
4415 alc
[p
- name
] = '\0';
4419 /* Compute the hash value. */
4420 ha
= bfd_elf_hash (name
);
4422 /* Store the found hash value in the array given as the argument. */
4425 /* And store it in the struct so that we can put it in the hash table
4427 h
->elf_hash_value
= ha
;
4435 /* Array used to determine the number of hash table buckets to use
4436 based on the number of symbols there are. If there are fewer than
4437 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
4438 fewer than 37 we use 17 buckets, and so forth. We never use more
4439 than 32771 buckets. */
4441 static const size_t elf_buckets
[] =
4443 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
4447 /* Compute bucket count for hashing table. We do not use a static set
4448 of possible tables sizes anymore. Instead we determine for all
4449 possible reasonable sizes of the table the outcome (i.e., the
4450 number of collisions etc) and choose the best solution. The
4451 weighting functions are not too simple to allow the table to grow
4452 without bounds. Instead one of the weighting factors is the size.
4453 Therefore the result is always a good payoff between few collisions
4454 (= short chain lengths) and table size. */
4456 compute_bucket_count (struct bfd_link_info
*info
)
4458 size_t dynsymcount
= elf_hash_table (info
)->dynsymcount
;
4459 size_t best_size
= 0;
4460 unsigned long int *hashcodes
;
4461 unsigned long int *hashcodesp
;
4462 unsigned long int i
;
4465 /* Compute the hash values for all exported symbols. At the same
4466 time store the values in an array so that we could use them for
4469 amt
*= sizeof (unsigned long int);
4470 hashcodes
= bfd_malloc (amt
);
4471 if (hashcodes
== NULL
)
4473 hashcodesp
= hashcodes
;
4475 /* Put all hash values in HASHCODES. */
4476 elf_link_hash_traverse (elf_hash_table (info
),
4477 elf_collect_hash_codes
, &hashcodesp
);
4479 /* We have a problem here. The following code to optimize the table
4480 size requires an integer type with more the 32 bits. If
4481 BFD_HOST_U_64_BIT is set we know about such a type. */
4482 #ifdef BFD_HOST_U_64_BIT
4485 unsigned long int nsyms
= hashcodesp
- hashcodes
;
4488 BFD_HOST_U_64_BIT best_chlen
= ~((BFD_HOST_U_64_BIT
) 0);
4489 unsigned long int *counts
;
4490 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
4491 const struct elf_backend_data
*bed
= get_elf_backend_data (dynobj
);
4493 /* Possible optimization parameters: if we have NSYMS symbols we say
4494 that the hashing table must at least have NSYMS/4 and at most
4496 minsize
= nsyms
/ 4;
4499 best_size
= maxsize
= nsyms
* 2;
4501 /* Create array where we count the collisions in. We must use bfd_malloc
4502 since the size could be large. */
4504 amt
*= sizeof (unsigned long int);
4505 counts
= bfd_malloc (amt
);
4512 /* Compute the "optimal" size for the hash table. The criteria is a
4513 minimal chain length. The minor criteria is (of course) the size
4515 for (i
= minsize
; i
< maxsize
; ++i
)
4517 /* Walk through the array of hashcodes and count the collisions. */
4518 BFD_HOST_U_64_BIT max
;
4519 unsigned long int j
;
4520 unsigned long int fact
;
4522 memset (counts
, '\0', i
* sizeof (unsigned long int));
4524 /* Determine how often each hash bucket is used. */
4525 for (j
= 0; j
< nsyms
; ++j
)
4526 ++counts
[hashcodes
[j
] % i
];
4528 /* For the weight function we need some information about the
4529 pagesize on the target. This is information need not be 100%
4530 accurate. Since this information is not available (so far) we
4531 define it here to a reasonable default value. If it is crucial
4532 to have a better value some day simply define this value. */
4533 # ifndef BFD_TARGET_PAGESIZE
4534 # define BFD_TARGET_PAGESIZE (4096)
4537 /* We in any case need 2 + NSYMS entries for the size values and
4539 max
= (2 + nsyms
) * (bed
->s
->arch_size
/ 8);
4542 /* Variant 1: optimize for short chains. We add the squares
4543 of all the chain lengths (which favors many small chain
4544 over a few long chains). */
4545 for (j
= 0; j
< i
; ++j
)
4546 max
+= counts
[j
] * counts
[j
];
4548 /* This adds penalties for the overall size of the table. */
4549 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (bed
->s
->arch_size
/ 8)) + 1;
4552 /* Variant 2: Optimize a lot more for small table. Here we
4553 also add squares of the size but we also add penalties for
4554 empty slots (the +1 term). */
4555 for (j
= 0; j
< i
; ++j
)
4556 max
+= (1 + counts
[j
]) * (1 + counts
[j
]);
4558 /* The overall size of the table is considered, but not as
4559 strong as in variant 1, where it is squared. */
4560 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (bed
->s
->arch_size
/ 8)) + 1;
4564 /* Compare with current best results. */
4565 if (max
< best_chlen
)
4575 #endif /* defined (BFD_HOST_U_64_BIT) */
4577 /* This is the fallback solution if no 64bit type is available or if we
4578 are not supposed to spend much time on optimizations. We select the
4579 bucket count using a fixed set of numbers. */
4580 for (i
= 0; elf_buckets
[i
] != 0; i
++)
4582 best_size
= elf_buckets
[i
];
4583 if (dynsymcount
< elf_buckets
[i
+ 1])
4588 /* Free the arrays we needed. */
4594 /* Set up the sizes and contents of the ELF dynamic sections. This is
4595 called by the ELF linker emulation before_allocation routine. We
4596 must set the sizes of the sections before the linker sets the
4597 addresses of the various sections. */
4600 bfd_elf_size_dynamic_sections (bfd
*output_bfd
,
4603 const char *filter_shlib
,
4604 const char * const *auxiliary_filters
,
4605 struct bfd_link_info
*info
,
4606 asection
**sinterpptr
,
4607 struct bfd_elf_version_tree
*verdefs
)
4609 bfd_size_type soname_indx
;
4611 const struct elf_backend_data
*bed
;
4612 struct elf_assign_sym_version_info asvinfo
;
4616 soname_indx
= (bfd_size_type
) -1;
4618 if (!is_elf_hash_table (info
->hash
))
4621 if (info
->execstack
)
4622 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| PF_X
;
4623 else if (info
->noexecstack
)
4624 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
;
4628 asection
*notesec
= NULL
;
4631 for (inputobj
= info
->input_bfds
;
4633 inputobj
= inputobj
->link_next
)
4637 if (inputobj
->flags
& DYNAMIC
)
4639 s
= bfd_get_section_by_name (inputobj
, ".note.GNU-stack");
4642 if (s
->flags
& SEC_CODE
)
4651 elf_tdata (output_bfd
)->stack_flags
= PF_R
| PF_W
| exec
;
4652 if (exec
&& info
->relocatable
4653 && notesec
->output_section
!= bfd_abs_section_ptr
)
4654 notesec
->output_section
->flags
|= SEC_CODE
;
4658 /* Any syms created from now on start with -1 in
4659 got.refcount/offset and plt.refcount/offset. */
4660 elf_hash_table (info
)->init_refcount
= elf_hash_table (info
)->init_offset
;
4662 /* The backend may have to create some sections regardless of whether
4663 we're dynamic or not. */
4664 bed
= get_elf_backend_data (output_bfd
);
4665 if (bed
->elf_backend_always_size_sections
4666 && ! (*bed
->elf_backend_always_size_sections
) (output_bfd
, info
))
4669 dynobj
= elf_hash_table (info
)->dynobj
;
4671 /* If there were no dynamic objects in the link, there is nothing to
4676 if (! _bfd_elf_maybe_strip_eh_frame_hdr (info
))
4679 if (elf_hash_table (info
)->dynamic_sections_created
)
4681 struct elf_info_failed eif
;
4682 struct elf_link_hash_entry
*h
;
4684 struct bfd_elf_version_tree
*t
;
4685 struct bfd_elf_version_expr
*d
;
4686 bfd_boolean all_defined
;
4688 *sinterpptr
= bfd_get_section_by_name (dynobj
, ".interp");
4689 BFD_ASSERT (*sinterpptr
!= NULL
|| !info
->executable
);
4693 soname_indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
4695 if (soname_indx
== (bfd_size_type
) -1
4696 || !_bfd_elf_add_dynamic_entry (info
, DT_SONAME
, soname_indx
))
4702 if (!_bfd_elf_add_dynamic_entry (info
, DT_SYMBOLIC
, 0))
4704 info
->flags
|= DF_SYMBOLIC
;
4711 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
, rpath
,
4713 if (indx
== (bfd_size_type
) -1
4714 || !_bfd_elf_add_dynamic_entry (info
, DT_RPATH
, indx
))
4717 if (info
->new_dtags
)
4719 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
, indx
);
4720 if (!_bfd_elf_add_dynamic_entry (info
, DT_RUNPATH
, indx
))
4725 if (filter_shlib
!= NULL
)
4729 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
4730 filter_shlib
, TRUE
);
4731 if (indx
== (bfd_size_type
) -1
4732 || !_bfd_elf_add_dynamic_entry (info
, DT_FILTER
, indx
))
4736 if (auxiliary_filters
!= NULL
)
4738 const char * const *p
;
4740 for (p
= auxiliary_filters
; *p
!= NULL
; p
++)
4744 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
4746 if (indx
== (bfd_size_type
) -1
4747 || !_bfd_elf_add_dynamic_entry (info
, DT_AUXILIARY
, indx
))
4753 eif
.verdefs
= verdefs
;
4756 /* If we are supposed to export all symbols into the dynamic symbol
4757 table (this is not the normal case), then do so. */
4758 if (info
->export_dynamic
)
4760 elf_link_hash_traverse (elf_hash_table (info
),
4761 _bfd_elf_export_symbol
,
4767 /* Make all global versions with definition. */
4768 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
4769 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
4770 if (!d
->symver
&& d
->symbol
)
4772 const char *verstr
, *name
;
4773 size_t namelen
, verlen
, newlen
;
4775 struct elf_link_hash_entry
*newh
;
4778 namelen
= strlen (name
);
4780 verlen
= strlen (verstr
);
4781 newlen
= namelen
+ verlen
+ 3;
4783 newname
= bfd_malloc (newlen
);
4784 if (newname
== NULL
)
4786 memcpy (newname
, name
, namelen
);
4788 /* Check the hidden versioned definition. */
4789 p
= newname
+ namelen
;
4791 memcpy (p
, verstr
, verlen
+ 1);
4792 newh
= elf_link_hash_lookup (elf_hash_table (info
),
4793 newname
, FALSE
, FALSE
,
4796 || (newh
->root
.type
!= bfd_link_hash_defined
4797 && newh
->root
.type
!= bfd_link_hash_defweak
))
4799 /* Check the default versioned definition. */
4801 memcpy (p
, verstr
, verlen
+ 1);
4802 newh
= elf_link_hash_lookup (elf_hash_table (info
),
4803 newname
, FALSE
, FALSE
,
4808 /* Mark this version if there is a definition and it is
4809 not defined in a shared object. */
4811 && ((newh
->elf_link_hash_flags
4812 & ELF_LINK_HASH_DEF_DYNAMIC
) == 0)
4813 && (newh
->root
.type
== bfd_link_hash_defined
4814 || newh
->root
.type
== bfd_link_hash_defweak
))
4818 /* Attach all the symbols to their version information. */
4819 asvinfo
.output_bfd
= output_bfd
;
4820 asvinfo
.info
= info
;
4821 asvinfo
.verdefs
= verdefs
;
4822 asvinfo
.failed
= FALSE
;
4824 elf_link_hash_traverse (elf_hash_table (info
),
4825 _bfd_elf_link_assign_sym_version
,
4830 if (!info
->allow_undefined_version
)
4832 /* Check if all global versions have a definition. */
4834 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
4835 for (d
= t
->globals
.list
; d
!= NULL
; d
= d
->next
)
4836 if (!d
->symver
&& !d
->script
)
4838 (*_bfd_error_handler
)
4839 (_("%s: undefined version: %s"),
4840 d
->pattern
, t
->name
);
4841 all_defined
= FALSE
;
4846 bfd_set_error (bfd_error_bad_value
);
4851 /* Find all symbols which were defined in a dynamic object and make
4852 the backend pick a reasonable value for them. */
4853 elf_link_hash_traverse (elf_hash_table (info
),
4854 _bfd_elf_adjust_dynamic_symbol
,
4859 /* Add some entries to the .dynamic section. We fill in some of the
4860 values later, in elf_bfd_final_link, but we must add the entries
4861 now so that we know the final size of the .dynamic section. */
4863 /* If there are initialization and/or finalization functions to
4864 call then add the corresponding DT_INIT/DT_FINI entries. */
4865 h
= (info
->init_function
4866 ? elf_link_hash_lookup (elf_hash_table (info
),
4867 info
->init_function
, FALSE
,
4871 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
4872 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
4874 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT
, 0))
4877 h
= (info
->fini_function
4878 ? elf_link_hash_lookup (elf_hash_table (info
),
4879 info
->fini_function
, FALSE
,
4883 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
4884 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
4886 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI
, 0))
4890 if (bfd_get_section_by_name (output_bfd
, ".preinit_array") != NULL
)
4892 /* DT_PREINIT_ARRAY is not allowed in shared library. */
4893 if (! info
->executable
)
4898 for (sub
= info
->input_bfds
; sub
!= NULL
;
4899 sub
= sub
->link_next
)
4900 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
4901 if (elf_section_data (o
)->this_hdr
.sh_type
4902 == SHT_PREINIT_ARRAY
)
4904 (*_bfd_error_handler
)
4905 (_("%s: .preinit_array section is not allowed in DSO"),
4906 bfd_archive_filename (sub
));
4910 bfd_set_error (bfd_error_nonrepresentable_section
);
4914 if (!_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAY
, 0)
4915 || !_bfd_elf_add_dynamic_entry (info
, DT_PREINIT_ARRAYSZ
, 0))
4918 if (bfd_get_section_by_name (output_bfd
, ".init_array") != NULL
)
4920 if (!_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAY
, 0)
4921 || !_bfd_elf_add_dynamic_entry (info
, DT_INIT_ARRAYSZ
, 0))
4924 if (bfd_get_section_by_name (output_bfd
, ".fini_array") != NULL
)
4926 if (!_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAY
, 0)
4927 || !_bfd_elf_add_dynamic_entry (info
, DT_FINI_ARRAYSZ
, 0))
4931 dynstr
= bfd_get_section_by_name (dynobj
, ".dynstr");
4932 /* If .dynstr is excluded from the link, we don't want any of
4933 these tags. Strictly, we should be checking each section
4934 individually; This quick check covers for the case where
4935 someone does a /DISCARD/ : { *(*) }. */
4936 if (dynstr
!= NULL
&& dynstr
->output_section
!= bfd_abs_section_ptr
)
4938 bfd_size_type strsize
;
4940 strsize
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
4941 if (!_bfd_elf_add_dynamic_entry (info
, DT_HASH
, 0)
4942 || !_bfd_elf_add_dynamic_entry (info
, DT_STRTAB
, 0)
4943 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMTAB
, 0)
4944 || !_bfd_elf_add_dynamic_entry (info
, DT_STRSZ
, strsize
)
4945 || !_bfd_elf_add_dynamic_entry (info
, DT_SYMENT
,
4946 bed
->s
->sizeof_sym
))
4951 /* The backend must work out the sizes of all the other dynamic
4953 if (bed
->elf_backend_size_dynamic_sections
4954 && ! (*bed
->elf_backend_size_dynamic_sections
) (output_bfd
, info
))
4957 if (elf_hash_table (info
)->dynamic_sections_created
)
4959 bfd_size_type dynsymcount
;
4961 size_t bucketcount
= 0;
4962 size_t hash_entry_size
;
4963 unsigned int dtagcount
;
4965 /* Set up the version definition section. */
4966 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
4967 BFD_ASSERT (s
!= NULL
);
4969 /* We may have created additional version definitions if we are
4970 just linking a regular application. */
4971 verdefs
= asvinfo
.verdefs
;
4973 /* Skip anonymous version tag. */
4974 if (verdefs
!= NULL
&& verdefs
->vernum
== 0)
4975 verdefs
= verdefs
->next
;
4977 if (verdefs
== NULL
)
4978 _bfd_strip_section_from_output (info
, s
);
4983 struct bfd_elf_version_tree
*t
;
4985 Elf_Internal_Verdef def
;
4986 Elf_Internal_Verdaux defaux
;
4991 /* Make space for the base version. */
4992 size
+= sizeof (Elf_External_Verdef
);
4993 size
+= sizeof (Elf_External_Verdaux
);
4996 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
4998 struct bfd_elf_version_deps
*n
;
5000 size
+= sizeof (Elf_External_Verdef
);
5001 size
+= sizeof (Elf_External_Verdaux
);
5004 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5005 size
+= sizeof (Elf_External_Verdaux
);
5008 s
->_raw_size
= size
;
5009 s
->contents
= bfd_alloc (output_bfd
, s
->_raw_size
);
5010 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5013 /* Fill in the version definition section. */
5017 def
.vd_version
= VER_DEF_CURRENT
;
5018 def
.vd_flags
= VER_FLG_BASE
;
5021 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5022 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5023 + sizeof (Elf_External_Verdaux
));
5025 if (soname_indx
!= (bfd_size_type
) -1)
5027 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5029 def
.vd_hash
= bfd_elf_hash (soname
);
5030 defaux
.vda_name
= soname_indx
;
5037 name
= basename (output_bfd
->filename
);
5038 def
.vd_hash
= bfd_elf_hash (name
);
5039 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5041 if (indx
== (bfd_size_type
) -1)
5043 defaux
.vda_name
= indx
;
5045 defaux
.vda_next
= 0;
5047 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
5048 (Elf_External_Verdef
*) p
);
5049 p
+= sizeof (Elf_External_Verdef
);
5050 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5051 (Elf_External_Verdaux
*) p
);
5052 p
+= sizeof (Elf_External_Verdaux
);
5054 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
5057 struct bfd_elf_version_deps
*n
;
5058 struct elf_link_hash_entry
*h
;
5059 struct bfd_link_hash_entry
*bh
;
5062 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5065 /* Add a symbol representing this version. */
5067 if (! (_bfd_generic_link_add_one_symbol
5068 (info
, dynobj
, t
->name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
5070 get_elf_backend_data (dynobj
)->collect
, &bh
)))
5072 h
= (struct elf_link_hash_entry
*) bh
;
5073 h
->elf_link_hash_flags
&= ~ ELF_LINK_NON_ELF
;
5074 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
5075 h
->type
= STT_OBJECT
;
5076 h
->verinfo
.vertree
= t
;
5078 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
5081 def
.vd_version
= VER_DEF_CURRENT
;
5083 if (t
->globals
.list
== NULL
5084 && t
->locals
.list
== NULL
5086 def
.vd_flags
|= VER_FLG_WEAK
;
5087 def
.vd_ndx
= t
->vernum
+ 1;
5088 def
.vd_cnt
= cdeps
+ 1;
5089 def
.vd_hash
= bfd_elf_hash (t
->name
);
5090 def
.vd_aux
= sizeof (Elf_External_Verdef
);
5092 if (t
->next
!= NULL
)
5093 def
.vd_next
= (sizeof (Elf_External_Verdef
)
5094 + (cdeps
+ 1) * sizeof (Elf_External_Verdaux
));
5096 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
5097 (Elf_External_Verdef
*) p
);
5098 p
+= sizeof (Elf_External_Verdef
);
5100 defaux
.vda_name
= h
->dynstr_index
;
5101 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5103 defaux
.vda_next
= 0;
5104 if (t
->deps
!= NULL
)
5105 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
5106 t
->name_indx
= defaux
.vda_name
;
5108 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5109 (Elf_External_Verdaux
*) p
);
5110 p
+= sizeof (Elf_External_Verdaux
);
5112 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
5114 if (n
->version_needed
== NULL
)
5116 /* This can happen if there was an error in the
5118 defaux
.vda_name
= 0;
5122 defaux
.vda_name
= n
->version_needed
->name_indx
;
5123 _bfd_elf_strtab_addref (elf_hash_table (info
)->dynstr
,
5126 if (n
->next
== NULL
)
5127 defaux
.vda_next
= 0;
5129 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
5131 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
5132 (Elf_External_Verdaux
*) p
);
5133 p
+= sizeof (Elf_External_Verdaux
);
5137 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERDEF
, 0)
5138 || !_bfd_elf_add_dynamic_entry (info
, DT_VERDEFNUM
, cdefs
))
5141 elf_tdata (output_bfd
)->cverdefs
= cdefs
;
5144 if ((info
->new_dtags
&& info
->flags
) || (info
->flags
& DF_STATIC_TLS
))
5146 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS
, info
->flags
))
5149 else if (info
->flags
& DF_BIND_NOW
)
5151 if (!_bfd_elf_add_dynamic_entry (info
, DT_BIND_NOW
, 0))
5157 if (info
->executable
)
5158 info
->flags_1
&= ~ (DF_1_INITFIRST
5161 if (!_bfd_elf_add_dynamic_entry (info
, DT_FLAGS_1
, info
->flags_1
))
5165 /* Work out the size of the version reference section. */
5167 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
5168 BFD_ASSERT (s
!= NULL
);
5170 struct elf_find_verdep_info sinfo
;
5172 sinfo
.output_bfd
= output_bfd
;
5174 sinfo
.vers
= elf_tdata (output_bfd
)->cverdefs
;
5175 if (sinfo
.vers
== 0)
5177 sinfo
.failed
= FALSE
;
5179 elf_link_hash_traverse (elf_hash_table (info
),
5180 _bfd_elf_link_find_version_dependencies
,
5183 if (elf_tdata (output_bfd
)->verref
== NULL
)
5184 _bfd_strip_section_from_output (info
, s
);
5187 Elf_Internal_Verneed
*t
;
5192 /* Build the version definition section. */
5195 for (t
= elf_tdata (output_bfd
)->verref
;
5199 Elf_Internal_Vernaux
*a
;
5201 size
+= sizeof (Elf_External_Verneed
);
5203 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
5204 size
+= sizeof (Elf_External_Vernaux
);
5207 s
->_raw_size
= size
;
5208 s
->contents
= bfd_alloc (output_bfd
, s
->_raw_size
);
5209 if (s
->contents
== NULL
)
5213 for (t
= elf_tdata (output_bfd
)->verref
;
5218 Elf_Internal_Vernaux
*a
;
5222 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
5225 t
->vn_version
= VER_NEED_CURRENT
;
5227 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5228 elf_dt_name (t
->vn_bfd
) != NULL
5229 ? elf_dt_name (t
->vn_bfd
)
5230 : basename (t
->vn_bfd
->filename
),
5232 if (indx
== (bfd_size_type
) -1)
5235 t
->vn_aux
= sizeof (Elf_External_Verneed
);
5236 if (t
->vn_nextref
== NULL
)
5239 t
->vn_next
= (sizeof (Elf_External_Verneed
)
5240 + caux
* sizeof (Elf_External_Vernaux
));
5242 _bfd_elf_swap_verneed_out (output_bfd
, t
,
5243 (Elf_External_Verneed
*) p
);
5244 p
+= sizeof (Elf_External_Verneed
);
5246 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
5248 a
->vna_hash
= bfd_elf_hash (a
->vna_nodename
);
5249 indx
= _bfd_elf_strtab_add (elf_hash_table (info
)->dynstr
,
5250 a
->vna_nodename
, FALSE
);
5251 if (indx
== (bfd_size_type
) -1)
5254 if (a
->vna_nextptr
== NULL
)
5257 a
->vna_next
= sizeof (Elf_External_Vernaux
);
5259 _bfd_elf_swap_vernaux_out (output_bfd
, a
,
5260 (Elf_External_Vernaux
*) p
);
5261 p
+= sizeof (Elf_External_Vernaux
);
5265 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERNEED
, 0)
5266 || !_bfd_elf_add_dynamic_entry (info
, DT_VERNEEDNUM
, crefs
))
5269 elf_tdata (output_bfd
)->cverrefs
= crefs
;
5273 /* Assign dynsym indicies. In a shared library we generate a
5274 section symbol for each output section, which come first.
5275 Next come all of the back-end allocated local dynamic syms,
5276 followed by the rest of the global symbols. */
5278 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
5280 /* Work out the size of the symbol version section. */
5281 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
5282 BFD_ASSERT (s
!= NULL
);
5283 if (dynsymcount
== 0
5284 || (verdefs
== NULL
&& elf_tdata (output_bfd
)->verref
== NULL
))
5286 _bfd_strip_section_from_output (info
, s
);
5287 /* The DYNSYMCOUNT might have changed if we were going to
5288 output a dynamic symbol table entry for S. */
5289 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
5293 s
->_raw_size
= dynsymcount
* sizeof (Elf_External_Versym
);
5294 s
->contents
= bfd_zalloc (output_bfd
, s
->_raw_size
);
5295 if (s
->contents
== NULL
)
5298 if (!_bfd_elf_add_dynamic_entry (info
, DT_VERSYM
, 0))
5302 /* Set the size of the .dynsym and .hash sections. We counted
5303 the number of dynamic symbols in elf_link_add_object_symbols.
5304 We will build the contents of .dynsym and .hash when we build
5305 the final symbol table, because until then we do not know the
5306 correct value to give the symbols. We built the .dynstr
5307 section as we went along in elf_link_add_object_symbols. */
5308 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
5309 BFD_ASSERT (s
!= NULL
);
5310 s
->_raw_size
= dynsymcount
* bed
->s
->sizeof_sym
;
5311 s
->contents
= bfd_alloc (output_bfd
, s
->_raw_size
);
5312 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
5315 if (dynsymcount
!= 0)
5317 Elf_Internal_Sym isym
;
5319 /* The first entry in .dynsym is a dummy symbol. */
5326 bed
->s
->swap_symbol_out (output_bfd
, &isym
, s
->contents
, 0);
5329 /* Compute the size of the hashing table. As a side effect this
5330 computes the hash values for all the names we export. */
5331 bucketcount
= compute_bucket_count (info
);
5333 s
= bfd_get_section_by_name (dynobj
, ".hash");
5334 BFD_ASSERT (s
!= NULL
);
5335 hash_entry_size
= elf_section_data (s
)->this_hdr
.sh_entsize
;
5336 s
->_raw_size
= ((2 + bucketcount
+ dynsymcount
) * hash_entry_size
);
5337 s
->contents
= bfd_zalloc (output_bfd
, s
->_raw_size
);
5338 if (s
->contents
== NULL
)
5341 bfd_put (8 * hash_entry_size
, output_bfd
, bucketcount
, s
->contents
);
5342 bfd_put (8 * hash_entry_size
, output_bfd
, dynsymcount
,
5343 s
->contents
+ hash_entry_size
);
5345 elf_hash_table (info
)->bucketcount
= bucketcount
;
5347 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
5348 BFD_ASSERT (s
!= NULL
);
5350 elf_finalize_dynstr (output_bfd
, info
);
5352 s
->_raw_size
= _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
5354 for (dtagcount
= 0; dtagcount
<= info
->spare_dynamic_tags
; ++dtagcount
)
5355 if (!_bfd_elf_add_dynamic_entry (info
, DT_NULL
, 0))