1 /* ELF linking support for BFD.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
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. */
29 _bfd_elf_create_got_section (bfd *abfd, struct bfd_link_info *info)
33 struct elf_link_hash_entry *h;
34 struct bfd_link_hash_entry *bh;
35 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
38 /* This function may be called more than once. */
39 s = bfd_get_section_by_name (abfd, ".got");
40 if (s != NULL && (s->flags & SEC_LINKER_CREATED) != 0)
43 switch (bed->s->arch_size)
54 bfd_set_error (bfd_error_bad_value);
58 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
59 | SEC_LINKER_CREATED);
61 s = bfd_make_section (abfd, ".got");
63 || !bfd_set_section_flags (abfd, s, flags)
64 || !bfd_set_section_alignment (abfd, s, ptralign))
67 if (bed->want_got_plt)
69 s = bfd_make_section (abfd, ".got.plt");
71 || !bfd_set_section_flags (abfd, s, flags)
72 || !bfd_set_section_alignment (abfd, s, ptralign))
76 if (bed->want_got_sym)
78 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
79 (or .got.plt) section. We don't do this in the linker script
80 because we don't want to define the symbol if we are not creating
81 a global offset table. */
83 if (!(_bfd_generic_link_add_one_symbol
84 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
85 bed->got_symbol_offset, NULL, FALSE, bed->collect, &bh)))
87 h = (struct elf_link_hash_entry *) bh;
88 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
91 if (! info->executable
92 && ! _bfd_elf_link_record_dynamic_symbol (info, h))
95 elf_hash_table (info)->hgot = h;
98 /* The first bit of the global offset table is the header. */
99 s->_raw_size += bed->got_header_size + bed->got_symbol_offset;
104 /* Create some sections which will be filled in with dynamic linking
105 information. ABFD is an input file which requires dynamic sections
106 to be created. The dynamic sections take up virtual memory space
107 when the final executable is run, so we need to create them before
108 addresses are assigned to the output sections. We work out the
109 actual contents and size of these sections later. */
112 _bfd_elf_link_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
115 register asection *s;
116 struct elf_link_hash_entry *h;
117 struct bfd_link_hash_entry *bh;
118 const struct elf_backend_data *bed;
120 if (! is_elf_hash_table (info))
123 if (elf_hash_table (info)->dynamic_sections_created)
126 /* Make sure that all dynamic sections use the same input BFD. */
127 if (elf_hash_table (info)->dynobj == NULL)
128 elf_hash_table (info)->dynobj = abfd;
130 abfd = elf_hash_table (info)->dynobj;
132 /* Note that we set the SEC_IN_MEMORY flag for all of these
134 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
135 | SEC_IN_MEMORY | SEC_LINKER_CREATED);
137 /* A dynamically linked executable has a .interp section, but a
138 shared library does not. */
139 if (info->executable)
141 s = bfd_make_section (abfd, ".interp");
143 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY))
147 if (! info->traditional_format
148 && info->hash->creator->flavour == bfd_target_elf_flavour)
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 (info->hash->creator->flavour != bfd_target_elf_flavour)
430 h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, TRUE, FALSE);
434 if (h->root.type == bfd_link_hash_new)
435 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF;
437 /* If this symbol is being provided by the linker script, and it is
438 currently defined by a dynamic object, but not by a regular
439 object, then mark it as undefined so that the generic linker will
440 force the correct value. */
442 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
443 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
444 h->root.type = bfd_link_hash_undefined;
446 /* If this symbol is not being provided by the linker script, and it is
447 currently defined by a dynamic object, but not by a regular object,
448 then clear out any version information because the symbol will not be
449 associated with the dynamic object any more. */
451 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
452 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
453 h->verinfo.verdef = NULL;
455 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
457 if (((h->elf_link_hash_flags & (ELF_LINK_HASH_DEF_DYNAMIC
458 | ELF_LINK_HASH_REF_DYNAMIC)) != 0
462 if (! _bfd_elf_link_record_dynamic_symbol (info, h))
465 /* If this is a weak defined symbol, and we know a corresponding
466 real symbol from the same dynamic object, make sure the real
467 symbol is also made into a dynamic symbol. */
468 if (h->weakdef != NULL
469 && h->weakdef->dynindx == -1)
471 if (! _bfd_elf_link_record_dynamic_symbol (info, h->weakdef))
479 /* Record a new local dynamic symbol. Returns 0 on failure, 1 on
480 success, and 2 on a failure caused by attempting to record a symbol
481 in a discarded section, eg. a discarded link-once section symbol. */
484 elf_link_record_local_dynamic_symbol (struct bfd_link_info *info,
489 struct elf_link_local_dynamic_entry *entry;
490 struct elf_link_hash_table *eht;
491 struct elf_strtab_hash *dynstr;
492 unsigned long dynstr_index;
494 Elf_External_Sym_Shndx eshndx;
495 char esym[sizeof (Elf64_External_Sym)];
497 if (! is_elf_hash_table (info))
500 /* See if the entry exists already. */
501 for (entry = elf_hash_table (info)->dynlocal; entry ; entry = entry->next)
502 if (entry->input_bfd == input_bfd && entry->input_indx == input_indx)
505 amt = sizeof (*entry);
506 entry = bfd_alloc (input_bfd, amt);
510 /* Go find the symbol, so that we can find it's name. */
511 if (!bfd_elf_get_elf_syms (input_bfd, &elf_tdata (input_bfd)->symtab_hdr,
512 1, input_indx, &entry->isym, esym, &eshndx))
514 bfd_release (input_bfd, entry);
518 if (entry->isym.st_shndx != SHN_UNDEF
519 && (entry->isym.st_shndx < SHN_LORESERVE
520 || entry->isym.st_shndx > SHN_HIRESERVE))
524 s = bfd_section_from_elf_index (input_bfd, entry->isym.st_shndx);
525 if (s == NULL || bfd_is_abs_section (s->output_section))
527 /* We can still bfd_release here as nothing has done another
528 bfd_alloc. We can't do this later in this function. */
529 bfd_release (input_bfd, entry);
534 name = (bfd_elf_string_from_elf_section
535 (input_bfd, elf_tdata (input_bfd)->symtab_hdr.sh_link,
536 entry->isym.st_name));
538 dynstr = elf_hash_table (info)->dynstr;
541 /* Create a strtab to hold the dynamic symbol names. */
542 elf_hash_table (info)->dynstr = dynstr = _bfd_elf_strtab_init ();
547 dynstr_index = _bfd_elf_strtab_add (dynstr, name, FALSE);
548 if (dynstr_index == (unsigned long) -1)
550 entry->isym.st_name = dynstr_index;
552 eht = elf_hash_table (info);
554 entry->next = eht->dynlocal;
555 eht->dynlocal = entry;
556 entry->input_bfd = input_bfd;
557 entry->input_indx = input_indx;
560 /* Whatever binding the symbol had before, it's now local. */
562 = ELF_ST_INFO (STB_LOCAL, ELF_ST_TYPE (entry->isym.st_info));
564 /* The dynindx will be set at the end of size_dynamic_sections. */
569 /* Return the dynindex of a local dynamic symbol. */
572 _bfd_elf_link_lookup_local_dynindx (struct bfd_link_info *info,
576 struct elf_link_local_dynamic_entry *e;
578 for (e = elf_hash_table (info)->dynlocal; e ; e = e->next)
579 if (e->input_bfd == input_bfd && e->input_indx == input_indx)
584 /* This function is used to renumber the dynamic symbols, if some of
585 them are removed because they are marked as local. This is called
586 via elf_link_hash_traverse. */
589 elf_link_renumber_hash_table_dynsyms (struct elf_link_hash_entry *h,
592 size_t *count = data;
594 if (h->root.type == bfd_link_hash_warning)
595 h = (struct elf_link_hash_entry *) h->root.u.i.link;
597 if (h->dynindx != -1)
598 h->dynindx = ++(*count);
603 /* Assign dynsym indices. In a shared library we generate a section
604 symbol for each output section, which come first. Next come all of
605 the back-end allocated local dynamic syms, followed by the rest of
606 the global symbols. */
609 _bfd_elf_link_renumber_dynsyms (bfd *output_bfd, struct bfd_link_info *info)
611 unsigned long dynsymcount = 0;
616 for (p = output_bfd->sections; p ; p = p->next)
617 if ((p->flags & SEC_EXCLUDE) == 0)
618 elf_section_data (p)->dynindx = ++dynsymcount;
621 if (elf_hash_table (info)->dynlocal)
623 struct elf_link_local_dynamic_entry *p;
624 for (p = elf_hash_table (info)->dynlocal; p ; p = p->next)
625 p->dynindx = ++dynsymcount;
628 elf_link_hash_traverse (elf_hash_table (info),
629 elf_link_renumber_hash_table_dynsyms,
632 /* There is an unused NULL entry at the head of the table which
633 we must account for in our count. Unless there weren't any
634 symbols, which means we'll have no table at all. */
635 if (dynsymcount != 0)
638 return elf_hash_table (info)->dynsymcount = dynsymcount;
641 /* This function is called when we want to define a new symbol. It
642 handles the various cases which arise when we find a definition in
643 a dynamic object, or when there is already a definition in a
644 dynamic object. The new symbol is described by NAME, SYM, PSEC,
645 and PVALUE. We set SYM_HASH to the hash table entry. We set
646 OVERRIDE if the old symbol is overriding a new definition. We set
647 TYPE_CHANGE_OK if it is OK for the type to change. We set
648 SIZE_CHANGE_OK if it is OK for the size to change. By OK to
649 change, we mean that we shouldn't warn if the type or size does
650 change. DT_NEEDED indicates if it comes from a DT_NEEDED entry of
654 _bfd_elf_merge_symbol (bfd *abfd,
655 struct bfd_link_info *info,
657 Elf_Internal_Sym *sym,
660 struct elf_link_hash_entry **sym_hash,
662 bfd_boolean *override,
663 bfd_boolean *type_change_ok,
664 bfd_boolean *size_change_ok,
665 bfd_boolean dt_needed)
668 struct elf_link_hash_entry *h;
669 struct elf_link_hash_entry *flip;
672 bfd_boolean newdyn, olddyn, olddef, newdef, newdyncommon, olddyncommon;
673 bfd_boolean newweakdef, oldweakdef, newweakundef, oldweakundef;
679 bind = ELF_ST_BIND (sym->st_info);
681 if (! bfd_is_und_section (sec))
682 h = elf_link_hash_lookup (elf_hash_table (info), name, TRUE, FALSE, FALSE);
684 h = ((struct elf_link_hash_entry *)
685 bfd_wrapped_link_hash_lookup (abfd, info, name, TRUE, FALSE, FALSE));
690 /* This code is for coping with dynamic objects, and is only useful
691 if we are doing an ELF link. */
692 if (info->hash->creator != abfd->xvec)
695 /* For merging, we only care about real symbols. */
697 while (h->root.type == bfd_link_hash_indirect
698 || h->root.type == bfd_link_hash_warning)
699 h = (struct elf_link_hash_entry *) h->root.u.i.link;
701 /* If we just created the symbol, mark it as being an ELF symbol.
702 Other than that, there is nothing to do--there is no merge issue
703 with a newly defined symbol--so we just return. */
705 if (h->root.type == bfd_link_hash_new)
707 h->elf_link_hash_flags &=~ ELF_LINK_NON_ELF;
711 /* OLDBFD is a BFD associated with the existing symbol. */
713 switch (h->root.type)
719 case bfd_link_hash_undefined:
720 case bfd_link_hash_undefweak:
721 oldbfd = h->root.u.undef.abfd;
724 case bfd_link_hash_defined:
725 case bfd_link_hash_defweak:
726 oldbfd = h->root.u.def.section->owner;
729 case bfd_link_hash_common:
730 oldbfd = h->root.u.c.p->section->owner;
734 /* In cases involving weak versioned symbols, we may wind up trying
735 to merge a symbol with itself. Catch that here, to avoid the
736 confusion that results if we try to override a symbol with
737 itself. The additional tests catch cases like
738 _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
739 dynamic object, which we do want to handle here. */
741 && ((abfd->flags & DYNAMIC) == 0
742 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0))
745 /* NEWDYN and OLDDYN indicate whether the new or old symbol,
746 respectively, is from a dynamic object. */
748 if ((abfd->flags & DYNAMIC) != 0)
754 olddyn = (oldbfd->flags & DYNAMIC) != 0;
759 /* This code handles the special SHN_MIPS_{TEXT,DATA} section
760 indices used by MIPS ELF. */
761 switch (h->root.type)
767 case bfd_link_hash_defined:
768 case bfd_link_hash_defweak:
769 hsec = h->root.u.def.section;
772 case bfd_link_hash_common:
773 hsec = h->root.u.c.p->section;
780 olddyn = (hsec->symbol->flags & BSF_DYNAMIC) != 0;
783 /* NEWDEF and OLDDEF indicate whether the new or old symbol,
784 respectively, appear to be a definition rather than reference. */
786 if (bfd_is_und_section (sec) || bfd_is_com_section (sec))
791 if (h->root.type == bfd_link_hash_undefined
792 || h->root.type == bfd_link_hash_undefweak
793 || h->root.type == bfd_link_hash_common)
798 /* We need to rememeber if a symbol has a definition in a dynamic
799 object or is weak in all dynamic objects. Internal and hidden
800 visibility will make it unavailable to dynamic objects. */
801 if (newdyn && (h->elf_link_hash_flags & ELF_LINK_DYNAMIC_DEF) == 0)
803 if (!bfd_is_und_section (sec))
804 h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_DEF;
807 /* Check if this symbol is weak in all dynamic objects. If it
808 is the first time we see it in a dynamic object, we mark
809 if it is weak. Otherwise, we clear it. */
810 if ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
812 if (bind == STB_WEAK)
813 h->elf_link_hash_flags |= ELF_LINK_DYNAMIC_WEAK;
815 else if (bind != STB_WEAK)
816 h->elf_link_hash_flags &= ~ELF_LINK_DYNAMIC_WEAK;
820 /* If the old symbol has non-default visibility, we ignore the new
821 definition from a dynamic object. */
823 && ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
824 && !bfd_is_und_section (sec))
827 /* Make sure this symbol is dynamic. */
828 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
829 /* A protected symbol has external availability. Make sure it is
832 FIXME: Should we check type and size for protected symbol? */
833 if (ELF_ST_VISIBILITY (h->other) == STV_PROTECTED)
834 return _bfd_elf_link_record_dynamic_symbol (info, h);
839 && ELF_ST_VISIBILITY (sym->st_other) != STV_DEFAULT
840 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
842 /* If the new symbol with non-default visibility comes from a
843 relocatable file and the old definition comes from a dynamic
844 object, we remove the old definition. */
845 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
847 h->root.type = bfd_link_hash_new;
848 h->root.u.undef.abfd = NULL;
849 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
851 h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC;
852 h->elf_link_hash_flags |= (ELF_LINK_HASH_REF_DYNAMIC
853 | ELF_LINK_DYNAMIC_DEF);
855 /* FIXME: Should we check type and size for protected symbol? */
861 /* We need to treat weak definiton right, depending on if there is a
862 definition from a dynamic object. */
863 if (bind == STB_WEAK)
868 newweakundef = FALSE;
877 newweakdef = newweakundef = FALSE;
879 /* If the new weak definition comes from a relocatable file and the
880 old symbol comes from a dynamic object, we treat the new one as
882 if (newweakdef && !newdyn && olddyn)
885 if (h->root.type == bfd_link_hash_defweak)
888 oldweakundef = FALSE;
890 else if (h->root.type == bfd_link_hash_undefweak)
896 oldweakdef = oldweakundef = FALSE;
898 /* If the old weak definition comes from a relocatable file and the
899 new symbol comes from a dynamic object, we treat the old one as
901 if (oldweakdef && !olddyn && newdyn)
904 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
905 symbol, respectively, appears to be a common symbol in a dynamic
906 object. If a symbol appears in an uninitialized section, and is
907 not weak, and is not a function, then it may be a common symbol
908 which was resolved when the dynamic object was created. We want
909 to treat such symbols specially, because they raise special
910 considerations when setting the symbol size: if the symbol
911 appears as a common symbol in a regular object, and the size in
912 the regular object is larger, we must make sure that we use the
913 larger size. This problematic case can always be avoided in C,
914 but it must be handled correctly when using Fortran shared
917 Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
918 likewise for OLDDYNCOMMON and OLDDEF.
920 Note that this test is just a heuristic, and that it is quite
921 possible to have an uninitialized symbol in a shared object which
922 is really a definition, rather than a common symbol. This could
923 lead to some minor confusion when the symbol really is a common
924 symbol in some regular object. However, I think it will be
929 && (sec->flags & SEC_ALLOC) != 0
930 && (sec->flags & SEC_LOAD) == 0
934 && ELF_ST_TYPE (sym->st_info) != STT_FUNC)
937 newdyncommon = FALSE;
941 && h->root.type == bfd_link_hash_defined
942 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
943 && (h->root.u.def.section->flags & SEC_ALLOC) != 0
944 && (h->root.u.def.section->flags & SEC_LOAD) == 0
946 && h->type != STT_FUNC)
949 olddyncommon = FALSE;
951 /* It's OK to change the type if either the existing symbol or the
952 new symbol is weak unless it comes from a DT_NEEDED entry of
953 a shared object, in which case, the DT_NEEDED entry may not be
954 required at the run time. The type change is also OK if the
955 old symbol is undefined and the new symbol is defined. */
957 if ((! dt_needed && oldweakdef)
962 && (h->root.type == bfd_link_hash_undefined
963 || h->root.type == bfd_link_hash_undefweak)))
964 *type_change_ok = TRUE;
966 /* It's OK to change the size if either the existing symbol or the
967 new symbol is weak, or if the old symbol is undefined. */
970 || h->root.type == bfd_link_hash_undefined)
971 *size_change_ok = TRUE;
973 /* If both the old and the new symbols look like common symbols in a
974 dynamic object, set the size of the symbol to the larger of the
979 && sym->st_size != h->size)
981 /* Since we think we have two common symbols, issue a multiple
982 common warning if desired. Note that we only warn if the
983 size is different. If the size is the same, we simply let
984 the old symbol override the new one as normally happens with
985 symbols defined in dynamic objects. */
987 if (! ((*info->callbacks->multiple_common)
988 (info, h->root.root.string, oldbfd, bfd_link_hash_common,
989 h->size, abfd, bfd_link_hash_common, sym->st_size)))
992 if (sym->st_size > h->size)
993 h->size = sym->st_size;
995 *size_change_ok = TRUE;
998 /* If we are looking at a dynamic object, and we have found a
999 definition, we need to see if the symbol was already defined by
1000 some other object. If so, we want to use the existing
1001 definition, and we do not want to report a multiple symbol
1002 definition error; we do this by clobbering *PSEC to be
1003 bfd_und_section_ptr.
1005 We treat a common symbol as a definition if the symbol in the
1006 shared library is a function, since common symbols always
1007 represent variables; this can cause confusion in principle, but
1008 any such confusion would seem to indicate an erroneous program or
1009 shared library. We also permit a common symbol in a regular
1010 object to override a weak symbol in a shared object.
1012 We prefer a non-weak definition in a shared library to a weak
1013 definition in the executable unless it comes from a DT_NEEDED
1014 entry of a shared object, in which case, the DT_NEEDED entry
1015 may not be required at the run time. */
1020 || (h->root.type == bfd_link_hash_common
1023 || ELF_ST_TYPE (sym->st_info) == STT_FUNC)))
1031 newdyncommon = FALSE;
1033 *psec = sec = bfd_und_section_ptr;
1034 *size_change_ok = TRUE;
1036 /* If we get here when the old symbol is a common symbol, then
1037 we are explicitly letting it override a weak symbol or
1038 function in a dynamic object, and we don't want to warn about
1039 a type change. If the old symbol is a defined symbol, a type
1040 change warning may still be appropriate. */
1042 if (h->root.type == bfd_link_hash_common)
1043 *type_change_ok = TRUE;
1046 /* Handle the special case of an old common symbol merging with a
1047 new symbol which looks like a common symbol in a shared object.
1048 We change *PSEC and *PVALUE to make the new symbol look like a
1049 common symbol, and let _bfd_generic_link_add_one_symbol will do
1053 && h->root.type == bfd_link_hash_common)
1057 newdyncommon = FALSE;
1058 *pvalue = sym->st_size;
1059 *psec = sec = bfd_com_section_ptr;
1060 *size_change_ok = TRUE;
1063 /* If the old symbol is from a dynamic object, and the new symbol is
1064 a definition which is not from a dynamic object, then the new
1065 symbol overrides the old symbol. Symbols from regular files
1066 always take precedence over symbols from dynamic objects, even if
1067 they are defined after the dynamic object in the link.
1069 As above, we again permit a common symbol in a regular object to
1070 override a definition in a shared object if the shared object
1071 symbol is a function or is weak.
1073 As above, we permit a non-weak definition in a shared object to
1074 override a weak definition in a regular object. */
1079 || (bfd_is_com_section (sec)
1080 && (oldweakdef || h->type == STT_FUNC)))
1083 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
1084 && ((!newweakdef && !newweakundef) || oldweakdef))
1086 /* Change the hash table entry to undefined, and let
1087 _bfd_generic_link_add_one_symbol do the right thing with the
1090 h->root.type = bfd_link_hash_undefined;
1091 h->root.u.undef.abfd = h->root.u.def.section->owner;
1092 *size_change_ok = TRUE;
1095 olddyncommon = FALSE;
1097 /* We again permit a type change when a common symbol may be
1098 overriding a function. */
1100 if (bfd_is_com_section (sec))
1101 *type_change_ok = TRUE;
1103 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
1106 /* This union may have been set to be non-NULL when this symbol
1107 was seen in a dynamic object. We must force the union to be
1108 NULL, so that it is correct for a regular symbol. */
1109 h->verinfo.vertree = NULL;
1112 /* Handle the special case of a new common symbol merging with an
1113 old symbol that looks like it might be a common symbol defined in
1114 a shared object. Note that we have already handled the case in
1115 which a new common symbol should simply override the definition
1116 in the shared library. */
1119 && bfd_is_com_section (sec)
1122 /* It would be best if we could set the hash table entry to a
1123 common symbol, but we don't know what to use for the section
1124 or the alignment. */
1125 if (! ((*info->callbacks->multiple_common)
1126 (info, h->root.root.string, oldbfd, bfd_link_hash_common,
1127 h->size, abfd, bfd_link_hash_common, sym->st_size)))
1130 /* If the predumed common symbol in the dynamic object is
1131 larger, pretend that the new symbol has its size. */
1133 if (h->size > *pvalue)
1136 /* FIXME: We no longer know the alignment required by the symbol
1137 in the dynamic object, so we just wind up using the one from
1138 the regular object. */
1141 olddyncommon = FALSE;
1143 h->root.type = bfd_link_hash_undefined;
1144 h->root.u.undef.abfd = h->root.u.def.section->owner;
1146 *size_change_ok = TRUE;
1147 *type_change_ok = TRUE;
1149 if ((*sym_hash)->root.type == bfd_link_hash_indirect)
1152 h->verinfo.vertree = NULL;
1157 /* Handle the case where we had a versioned symbol in a dynamic
1158 library and now find a definition in a normal object. In this
1159 case, we make the versioned symbol point to the normal one. */
1160 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1161 flip->root.type = h->root.type;
1162 h->root.type = bfd_link_hash_indirect;
1163 h->root.u.i.link = (struct bfd_link_hash_entry *) flip;
1164 (*bed->elf_backend_copy_indirect_symbol) (bed, flip, h);
1165 flip->root.u.undef.abfd = h->root.u.undef.abfd;
1166 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
1168 h->elf_link_hash_flags &= ~ELF_LINK_HASH_DEF_DYNAMIC;
1169 flip->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
1173 /* Handle the special case of a weak definition in a regular object
1174 followed by a non-weak definition in a shared object. In this
1175 case, we prefer the definition in the shared object unless it
1176 comes from a DT_NEEDED entry of a shared object, in which case,
1177 the DT_NEEDED entry may not be required at the run time. */
1186 /* To make this work we have to frob the flags so that the rest
1187 of the code does not think we are using the regular
1189 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
1190 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
1191 else if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)
1192 h->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
1193 h->elf_link_hash_flags &= ~ (ELF_LINK_HASH_DEF_REGULAR
1194 | ELF_LINK_HASH_DEF_DYNAMIC);
1196 /* If H is the target of an indirection, we want the caller to
1197 use H rather than the indirect symbol. Otherwise if we are
1198 defining a new indirect symbol we will wind up attaching it
1199 to the entry we are overriding. */
1203 /* Handle the special case of a non-weak definition in a shared
1204 object followed by a weak definition in a regular object. In
1205 this case we prefer the definition in the shared object. To make
1206 this work we have to tell the caller to not treat the new symbol
1213 && (newweakdef || newweakundef))
1219 /* This function is called to create an indirect symbol from the
1220 default for the symbol with the default version if needed. The
1221 symbol is described by H, NAME, SYM, PSEC, VALUE, and OVERRIDE. We
1222 set DYNSYM if the new indirect symbol is dynamic. DT_NEEDED
1223 indicates if it comes from a DT_NEEDED entry of a shared object. */
1226 _bfd_elf_add_default_symbol (bfd *abfd,
1227 struct bfd_link_info *info,
1228 struct elf_link_hash_entry *h,
1230 Elf_Internal_Sym *sym,
1233 bfd_boolean *dynsym,
1234 bfd_boolean override,
1235 bfd_boolean dt_needed)
1237 bfd_boolean type_change_ok;
1238 bfd_boolean size_change_ok;
1241 struct elf_link_hash_entry *hi;
1242 struct bfd_link_hash_entry *bh;
1243 const struct elf_backend_data *bed;
1244 bfd_boolean collect;
1245 bfd_boolean dynamic;
1247 size_t len, shortlen;
1250 /* If this symbol has a version, and it is the default version, we
1251 create an indirect symbol from the default name to the fully
1252 decorated name. This will cause external references which do not
1253 specify a version to be bound to this version of the symbol. */
1254 p = strchr (name, ELF_VER_CHR);
1255 if (p == NULL || p[1] != ELF_VER_CHR)
1260 /* We are overridden by an old defition. We need to check if we
1261 need to create the indirect symbol from the default name. */
1262 hi = elf_link_hash_lookup (elf_hash_table (info), name, TRUE,
1264 BFD_ASSERT (hi != NULL);
1267 while (hi->root.type == bfd_link_hash_indirect
1268 || hi->root.type == bfd_link_hash_warning)
1270 hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
1276 bed = get_elf_backend_data (abfd);
1277 collect = bed->collect;
1278 dynamic = (abfd->flags & DYNAMIC) != 0;
1280 shortlen = p - name;
1281 shortname = bfd_hash_allocate (&info->hash->table, shortlen + 1);
1282 if (shortname == NULL)
1284 memcpy (shortname, name, shortlen);
1285 shortname[shortlen] = '\0';
1287 /* We are going to create a new symbol. Merge it with any existing
1288 symbol with this name. For the purposes of the merge, act as
1289 though we were defining the symbol we just defined, although we
1290 actually going to define an indirect symbol. */
1291 type_change_ok = FALSE;
1292 size_change_ok = FALSE;
1294 if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
1295 &hi, &skip, &override, &type_change_ok,
1296 &size_change_ok, dt_needed))
1305 if (! (_bfd_generic_link_add_one_symbol
1306 (info, abfd, shortname, BSF_INDIRECT, bfd_ind_section_ptr,
1307 0, name, FALSE, collect, &bh)))
1309 hi = (struct elf_link_hash_entry *) bh;
1313 /* In this case the symbol named SHORTNAME is overriding the
1314 indirect symbol we want to add. We were planning on making
1315 SHORTNAME an indirect symbol referring to NAME. SHORTNAME
1316 is the name without a version. NAME is the fully versioned
1317 name, and it is the default version.
1319 Overriding means that we already saw a definition for the
1320 symbol SHORTNAME in a regular object, and it is overriding
1321 the symbol defined in the dynamic object.
1323 When this happens, we actually want to change NAME, the
1324 symbol we just added, to refer to SHORTNAME. This will cause
1325 references to NAME in the shared object to become references
1326 to SHORTNAME in the regular object. This is what we expect
1327 when we override a function in a shared object: that the
1328 references in the shared object will be mapped to the
1329 definition in the regular object. */
1331 while (hi->root.type == bfd_link_hash_indirect
1332 || hi->root.type == bfd_link_hash_warning)
1333 hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
1335 h->root.type = bfd_link_hash_indirect;
1336 h->root.u.i.link = (struct bfd_link_hash_entry *) hi;
1337 if (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC)
1339 h->elf_link_hash_flags &=~ ELF_LINK_HASH_DEF_DYNAMIC;
1340 hi->elf_link_hash_flags |= ELF_LINK_HASH_REF_DYNAMIC;
1341 if (hi->elf_link_hash_flags
1342 & (ELF_LINK_HASH_REF_REGULAR
1343 | ELF_LINK_HASH_DEF_REGULAR))
1345 if (! _bfd_elf_link_record_dynamic_symbol (info, hi))
1350 /* Now set HI to H, so that the following code will set the
1351 other fields correctly. */
1355 /* If there is a duplicate definition somewhere, then HI may not
1356 point to an indirect symbol. We will have reported an error to
1357 the user in that case. */
1359 if (hi->root.type == bfd_link_hash_indirect)
1361 struct elf_link_hash_entry *ht;
1363 /* If the symbol became indirect, then we assume that we have
1364 not seen a definition before. */
1365 BFD_ASSERT ((hi->elf_link_hash_flags
1366 & (ELF_LINK_HASH_DEF_DYNAMIC
1367 | ELF_LINK_HASH_DEF_REGULAR)) == 0);
1369 ht = (struct elf_link_hash_entry *) hi->root.u.i.link;
1370 (*bed->elf_backend_copy_indirect_symbol) (bed, ht, hi);
1372 /* See if the new flags lead us to realize that the symbol must
1379 || ((hi->elf_link_hash_flags
1380 & ELF_LINK_HASH_REF_DYNAMIC) != 0))
1385 if ((hi->elf_link_hash_flags
1386 & ELF_LINK_HASH_REF_REGULAR) != 0)
1392 /* We also need to define an indirection from the nondefault version
1396 len = strlen (name);
1397 shortname = bfd_hash_allocate (&info->hash->table, len);
1398 if (shortname == NULL)
1400 memcpy (shortname, name, shortlen);
1401 memcpy (shortname + shortlen, p + 1, len - shortlen);
1403 /* Once again, merge with any existing symbol. */
1404 type_change_ok = FALSE;
1405 size_change_ok = FALSE;
1407 if (!_bfd_elf_merge_symbol (abfd, info, shortname, sym, &sec, value,
1408 &hi, &skip, &override, &type_change_ok,
1409 &size_change_ok, dt_needed))
1417 /* Here SHORTNAME is a versioned name, so we don't expect to see
1418 the type of override we do in the case above unless it is
1419 overridden by a versioned definiton. */
1420 if (hi->root.type != bfd_link_hash_defined
1421 && hi->root.type != bfd_link_hash_defweak)
1422 (*_bfd_error_handler)
1423 (_("%s: warning: unexpected redefinition of indirect versioned symbol `%s'"),
1424 bfd_archive_filename (abfd), shortname);
1429 if (! (_bfd_generic_link_add_one_symbol
1430 (info, abfd, shortname, BSF_INDIRECT,
1431 bfd_ind_section_ptr, 0, name, FALSE, collect, &bh)))
1433 hi = (struct elf_link_hash_entry *) bh;
1435 /* If there is a duplicate definition somewhere, then HI may not
1436 point to an indirect symbol. We will have reported an error
1437 to the user in that case. */
1439 if (hi->root.type == bfd_link_hash_indirect)
1441 /* If the symbol became indirect, then we assume that we have
1442 not seen a definition before. */
1443 BFD_ASSERT ((hi->elf_link_hash_flags
1444 & (ELF_LINK_HASH_DEF_DYNAMIC
1445 | ELF_LINK_HASH_DEF_REGULAR)) == 0);
1447 (*bed->elf_backend_copy_indirect_symbol) (bed, h, hi);
1449 /* See if the new flags lead us to realize that the symbol
1456 || ((hi->elf_link_hash_flags
1457 & ELF_LINK_HASH_REF_DYNAMIC) != 0))
1462 if ((hi->elf_link_hash_flags
1463 & ELF_LINK_HASH_REF_REGULAR) != 0)
1473 /* This routine is used to export all defined symbols into the dynamic
1474 symbol table. It is called via elf_link_hash_traverse. */
1477 _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
1479 struct elf_info_failed *eif = data;
1481 /* Ignore indirect symbols. These are added by the versioning code. */
1482 if (h->root.type == bfd_link_hash_indirect)
1485 if (h->root.type == bfd_link_hash_warning)
1486 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1488 if (h->dynindx == -1
1489 && (h->elf_link_hash_flags
1490 & (ELF_LINK_HASH_DEF_REGULAR | ELF_LINK_HASH_REF_REGULAR)) != 0)
1492 struct bfd_elf_version_tree *t;
1493 struct bfd_elf_version_expr *d;
1495 for (t = eif->verdefs; t != NULL; t = t->next)
1497 if (t->globals.list != NULL)
1499 d = (*t->match) (&t->globals, NULL, h->root.root.string);
1504 if (t->locals.list != NULL)
1506 d = (*t->match) (&t->locals, NULL, h->root.root.string);
1515 if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
1526 /* Look through the symbols which are defined in other shared
1527 libraries and referenced here. Update the list of version
1528 dependencies. This will be put into the .gnu.version_r section.
1529 This function is called via elf_link_hash_traverse. */
1532 _bfd_elf_link_find_version_dependencies (struct elf_link_hash_entry *h,
1535 struct elf_find_verdep_info *rinfo = data;
1536 Elf_Internal_Verneed *t;
1537 Elf_Internal_Vernaux *a;
1540 if (h->root.type == bfd_link_hash_warning)
1541 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1543 /* We only care about symbols defined in shared objects with version
1545 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
1546 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
1548 || h->verinfo.verdef == NULL)
1551 /* See if we already know about this version. */
1552 for (t = elf_tdata (rinfo->output_bfd)->verref; t != NULL; t = t->vn_nextref)
1554 if (t->vn_bfd != h->verinfo.verdef->vd_bfd)
1557 for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
1558 if (a->vna_nodename == h->verinfo.verdef->vd_nodename)
1564 /* This is a new version. Add it to tree we are building. */
1569 t = bfd_zalloc (rinfo->output_bfd, amt);
1572 rinfo->failed = TRUE;
1576 t->vn_bfd = h->verinfo.verdef->vd_bfd;
1577 t->vn_nextref = elf_tdata (rinfo->output_bfd)->verref;
1578 elf_tdata (rinfo->output_bfd)->verref = t;
1582 a = bfd_zalloc (rinfo->output_bfd, amt);
1584 /* Note that we are copying a string pointer here, and testing it
1585 above. If bfd_elf_string_from_elf_section is ever changed to
1586 discard the string data when low in memory, this will have to be
1588 a->vna_nodename = h->verinfo.verdef->vd_nodename;
1590 a->vna_flags = h->verinfo.verdef->vd_flags;
1591 a->vna_nextptr = t->vn_auxptr;
1593 h->verinfo.verdef->vd_exp_refno = rinfo->vers;
1596 a->vna_other = h->verinfo.verdef->vd_exp_refno + 1;
1603 /* Figure out appropriate versions for all the symbols. We may not
1604 have the version number script until we have read all of the input
1605 files, so until that point we don't know which symbols should be
1606 local. This function is called via elf_link_hash_traverse. */
1609 _bfd_elf_link_assign_sym_version (struct elf_link_hash_entry *h, void *data)
1611 struct elf_assign_sym_version_info *sinfo;
1612 struct bfd_link_info *info;
1613 const struct elf_backend_data *bed;
1614 struct elf_info_failed eif;
1621 if (h->root.type == bfd_link_hash_warning)
1622 h = (struct elf_link_hash_entry *) h->root.u.i.link;
1624 /* Fix the symbol flags. */
1627 if (! _bfd_elf_fix_symbol_flags (h, &eif))
1630 sinfo->failed = TRUE;
1634 /* We only need version numbers for symbols defined in regular
1636 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
1639 bed = get_elf_backend_data (sinfo->output_bfd);
1640 p = strchr (h->root.root.string, ELF_VER_CHR);
1641 if (p != NULL && h->verinfo.vertree == NULL)
1643 struct bfd_elf_version_tree *t;
1648 /* There are two consecutive ELF_VER_CHR characters if this is
1649 not a hidden symbol. */
1651 if (*p == ELF_VER_CHR)
1657 /* If there is no version string, we can just return out. */
1661 h->elf_link_hash_flags |= ELF_LINK_HIDDEN;
1665 /* Look for the version. If we find it, it is no longer weak. */
1666 for (t = sinfo->verdefs; t != NULL; t = t->next)
1668 if (strcmp (t->name, p) == 0)
1672 struct bfd_elf_version_expr *d;
1674 len = p - h->root.root.string;
1675 alc = bfd_malloc (len);
1678 memcpy (alc, h->root.root.string, len - 1);
1679 alc[len - 1] = '\0';
1680 if (alc[len - 2] == ELF_VER_CHR)
1681 alc[len - 2] = '\0';
1683 h->verinfo.vertree = t;
1687 if (t->globals.list != NULL)
1688 d = (*t->match) (&t->globals, NULL, alc);
1690 /* See if there is anything to force this symbol to
1692 if (d == NULL && t->locals.list != NULL)
1694 d = (*t->match) (&t->locals, NULL, alc);
1698 && ! info->export_dynamic)
1699 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
1707 /* If we are building an application, we need to create a
1708 version node for this version. */
1709 if (t == NULL && info->executable)
1711 struct bfd_elf_version_tree **pp;
1714 /* If we aren't going to export this symbol, we don't need
1715 to worry about it. */
1716 if (h->dynindx == -1)
1720 t = bfd_zalloc (sinfo->output_bfd, amt);
1723 sinfo->failed = TRUE;
1728 t->name_indx = (unsigned int) -1;
1732 /* Don't count anonymous version tag. */
1733 if (sinfo->verdefs != NULL && sinfo->verdefs->vernum == 0)
1735 for (pp = &sinfo->verdefs; *pp != NULL; pp = &(*pp)->next)
1737 t->vernum = version_index;
1741 h->verinfo.vertree = t;
1745 /* We could not find the version for a symbol when
1746 generating a shared archive. Return an error. */
1747 (*_bfd_error_handler)
1748 (_("%s: undefined versioned symbol name %s"),
1749 bfd_get_filename (sinfo->output_bfd), h->root.root.string);
1750 bfd_set_error (bfd_error_bad_value);
1751 sinfo->failed = TRUE;
1756 h->elf_link_hash_flags |= ELF_LINK_HIDDEN;
1759 /* If we don't have a version for this symbol, see if we can find
1761 if (h->verinfo.vertree == NULL && sinfo->verdefs != NULL)
1763 struct bfd_elf_version_tree *t;
1764 struct bfd_elf_version_tree *local_ver;
1765 struct bfd_elf_version_expr *d;
1767 /* See if can find what version this symbol is in. If the
1768 symbol is supposed to be local, then don't actually register
1771 for (t = sinfo->verdefs; t != NULL; t = t->next)
1773 if (t->globals.list != NULL)
1775 bfd_boolean matched;
1779 while ((d = (*t->match) (&t->globals, d,
1780 h->root.root.string)) != NULL)
1785 /* There is a version without definition. Make
1786 the symbol the default definition for this
1788 h->verinfo.vertree = t;
1796 /* There is no undefined version for this symbol. Hide the
1798 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
1801 if (t->locals.list != NULL)
1804 while ((d = (*t->match) (&t->locals, d,
1805 h->root.root.string)) != NULL)
1808 /* If the match is "*", keep looking for a more
1809 explicit, perhaps even global, match.
1810 XXX: Shouldn't this be !d->wildcard instead? */
1811 if (d->pattern[0] != '*' || d->pattern[1] != '\0')
1820 if (local_ver != NULL)
1822 h->verinfo.vertree = local_ver;
1823 if (h->dynindx != -1
1825 && ! info->export_dynamic)
1827 (*bed->elf_backend_hide_symbol) (info, h, TRUE);
1835 /* Read and swap the relocs from the section indicated by SHDR. This
1836 may be either a REL or a RELA section. The relocations are
1837 translated into RELA relocations and stored in INTERNAL_RELOCS,
1838 which should have already been allocated to contain enough space.
1839 The EXTERNAL_RELOCS are a buffer where the external form of the
1840 relocations should be stored.
1842 Returns FALSE if something goes wrong. */
1845 elf_link_read_relocs_from_section (bfd *abfd,
1847 Elf_Internal_Shdr *shdr,
1848 void *external_relocs,
1849 Elf_Internal_Rela *internal_relocs)
1851 const struct elf_backend_data *bed;
1852 void (*swap_in) (bfd *, const bfd_byte *, Elf_Internal_Rela *);
1853 const bfd_byte *erela;
1854 const bfd_byte *erelaend;
1855 Elf_Internal_Rela *irela;
1856 Elf_Internal_Shdr *symtab_hdr;
1859 /* If there aren't any relocations, that's OK. */
1863 /* Position ourselves at the start of the section. */
1864 if (bfd_seek (abfd, shdr->sh_offset, SEEK_SET) != 0)
1867 /* Read the relocations. */
1868 if (bfd_bread (external_relocs, shdr->sh_size, abfd) != shdr->sh_size)
1871 symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1872 nsyms = symtab_hdr->sh_size / symtab_hdr->sh_entsize;
1874 bed = get_elf_backend_data (abfd);
1876 /* Convert the external relocations to the internal format. */
1877 if (shdr->sh_entsize == bed->s->sizeof_rel)
1878 swap_in = bed->s->swap_reloc_in;
1879 else if (shdr->sh_entsize == bed->s->sizeof_rela)
1880 swap_in = bed->s->swap_reloca_in;
1883 bfd_set_error (bfd_error_wrong_format);
1887 erela = external_relocs;
1888 erelaend = erela + NUM_SHDR_ENTRIES (shdr) * shdr->sh_entsize;
1889 irela = internal_relocs;
1890 while (erela < erelaend)
1894 (*swap_in) (abfd, erela, irela);
1895 r_symndx = ELF32_R_SYM (irela->r_info);
1896 if (bed->s->arch_size == 64)
1898 if ((size_t) r_symndx >= nsyms)
1900 (*_bfd_error_handler)
1901 (_("%s: bad reloc symbol index (0x%lx >= 0x%lx) for offset 0x%lx in section `%s'"),
1902 bfd_archive_filename (abfd), (unsigned long) r_symndx,
1903 (unsigned long) nsyms, irela->r_offset, sec->name);
1904 bfd_set_error (bfd_error_bad_value);
1907 irela += bed->s->int_rels_per_ext_rel;
1908 erela += shdr->sh_entsize;
1914 /* Read and swap the relocs for a section O. They may have been
1915 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
1916 not NULL, they are used as buffers to read into. They are known to
1917 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
1918 the return value is allocated using either malloc or bfd_alloc,
1919 according to the KEEP_MEMORY argument. If O has two relocation
1920 sections (both REL and RELA relocations), then the REL_HDR
1921 relocations will appear first in INTERNAL_RELOCS, followed by the
1922 REL_HDR2 relocations. */
1925 _bfd_elf_link_read_relocs (bfd *abfd,
1927 void *external_relocs,
1928 Elf_Internal_Rela *internal_relocs,
1929 bfd_boolean keep_memory)
1931 Elf_Internal_Shdr *rel_hdr;
1932 void *alloc1 = NULL;
1933 Elf_Internal_Rela *alloc2 = NULL;
1934 const struct elf_backend_data *bed = get_elf_backend_data (abfd);
1936 if (elf_section_data (o)->relocs != NULL)
1937 return elf_section_data (o)->relocs;
1939 if (o->reloc_count == 0)
1942 rel_hdr = &elf_section_data (o)->rel_hdr;
1944 if (internal_relocs == NULL)
1948 size = o->reloc_count;
1949 size *= bed->s->int_rels_per_ext_rel * sizeof (Elf_Internal_Rela);
1951 internal_relocs = bfd_alloc (abfd, size);
1953 internal_relocs = alloc2 = bfd_malloc (size);
1954 if (internal_relocs == NULL)
1958 if (external_relocs == NULL)
1960 bfd_size_type size = rel_hdr->sh_size;
1962 if (elf_section_data (o)->rel_hdr2)
1963 size += elf_section_data (o)->rel_hdr2->sh_size;
1964 alloc1 = bfd_malloc (size);
1967 external_relocs = alloc1;
1970 if (!elf_link_read_relocs_from_section (abfd, o, rel_hdr,
1974 if (!elf_link_read_relocs_from_section
1976 elf_section_data (o)->rel_hdr2,
1977 ((bfd_byte *) external_relocs) + rel_hdr->sh_size,
1978 internal_relocs + (NUM_SHDR_ENTRIES (rel_hdr)
1979 * bed->s->int_rels_per_ext_rel)))
1982 /* Cache the results for next time, if we can. */
1984 elf_section_data (o)->relocs = internal_relocs;
1989 /* Don't free alloc2, since if it was allocated we are passing it
1990 back (under the name of internal_relocs). */
1992 return internal_relocs;
2002 /* Compute the size of, and allocate space for, REL_HDR which is the
2003 section header for a section containing relocations for O. */
2006 _bfd_elf_link_size_reloc_section (bfd *abfd,
2007 Elf_Internal_Shdr *rel_hdr,
2010 bfd_size_type reloc_count;
2011 bfd_size_type num_rel_hashes;
2013 /* Figure out how many relocations there will be. */
2014 if (rel_hdr == &elf_section_data (o)->rel_hdr)
2015 reloc_count = elf_section_data (o)->rel_count;
2017 reloc_count = elf_section_data (o)->rel_count2;
2019 num_rel_hashes = o->reloc_count;
2020 if (num_rel_hashes < reloc_count)
2021 num_rel_hashes = reloc_count;
2023 /* That allows us to calculate the size of the section. */
2024 rel_hdr->sh_size = rel_hdr->sh_entsize * reloc_count;
2026 /* The contents field must last into write_object_contents, so we
2027 allocate it with bfd_alloc rather than malloc. Also since we
2028 cannot be sure that the contents will actually be filled in,
2029 we zero the allocated space. */
2030 rel_hdr->contents = bfd_zalloc (abfd, rel_hdr->sh_size);
2031 if (rel_hdr->contents == NULL && rel_hdr->sh_size != 0)
2034 /* We only allocate one set of hash entries, so we only do it the
2035 first time we are called. */
2036 if (elf_section_data (o)->rel_hashes == NULL
2039 struct elf_link_hash_entry **p;
2041 p = bfd_zmalloc (num_rel_hashes * sizeof (struct elf_link_hash_entry *));
2045 elf_section_data (o)->rel_hashes = p;
2051 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
2052 originated from the section given by INPUT_REL_HDR) to the
2056 _bfd_elf_link_output_relocs (bfd *output_bfd,
2057 asection *input_section,
2058 Elf_Internal_Shdr *input_rel_hdr,
2059 Elf_Internal_Rela *internal_relocs)
2061 Elf_Internal_Rela *irela;
2062 Elf_Internal_Rela *irelaend;
2064 Elf_Internal_Shdr *output_rel_hdr;
2065 asection *output_section;
2066 unsigned int *rel_countp = NULL;
2067 const struct elf_backend_data *bed;
2068 void (*swap_out) (bfd *, const Elf_Internal_Rela *, bfd_byte *);
2070 output_section = input_section->output_section;
2071 output_rel_hdr = NULL;
2073 if (elf_section_data (output_section)->rel_hdr.sh_entsize
2074 == input_rel_hdr->sh_entsize)
2076 output_rel_hdr = &elf_section_data (output_section)->rel_hdr;
2077 rel_countp = &elf_section_data (output_section)->rel_count;
2079 else if (elf_section_data (output_section)->rel_hdr2
2080 && (elf_section_data (output_section)->rel_hdr2->sh_entsize
2081 == input_rel_hdr->sh_entsize))
2083 output_rel_hdr = elf_section_data (output_section)->rel_hdr2;
2084 rel_countp = &elf_section_data (output_section)->rel_count2;
2088 (*_bfd_error_handler)
2089 (_("%s: relocation size mismatch in %s section %s"),
2090 bfd_get_filename (output_bfd),
2091 bfd_archive_filename (input_section->owner),
2092 input_section->name);
2093 bfd_set_error (bfd_error_wrong_object_format);
2097 bed = get_elf_backend_data (output_bfd);
2098 if (input_rel_hdr->sh_entsize == bed->s->sizeof_rel)
2099 swap_out = bed->s->swap_reloc_out;
2100 else if (input_rel_hdr->sh_entsize == bed->s->sizeof_rela)
2101 swap_out = bed->s->swap_reloca_out;
2105 erel = output_rel_hdr->contents;
2106 erel += *rel_countp * input_rel_hdr->sh_entsize;
2107 irela = internal_relocs;
2108 irelaend = irela + (NUM_SHDR_ENTRIES (input_rel_hdr)
2109 * bed->s->int_rels_per_ext_rel);
2110 while (irela < irelaend)
2112 (*swap_out) (output_bfd, irela, erel);
2113 irela += bed->s->int_rels_per_ext_rel;
2114 erel += input_rel_hdr->sh_entsize;
2117 /* Bump the counter, so that we know where to add the next set of
2119 *rel_countp += NUM_SHDR_ENTRIES (input_rel_hdr);
2124 /* Fix up the flags for a symbol. This handles various cases which
2125 can only be fixed after all the input files are seen. This is
2126 currently called by both adjust_dynamic_symbol and
2127 assign_sym_version, which is unnecessary but perhaps more robust in
2128 the face of future changes. */
2131 _bfd_elf_fix_symbol_flags (struct elf_link_hash_entry *h,
2132 struct elf_info_failed *eif)
2134 /* If this symbol was mentioned in a non-ELF file, try to set
2135 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
2136 permit a non-ELF file to correctly refer to a symbol defined in
2137 an ELF dynamic object. */
2138 if ((h->elf_link_hash_flags & ELF_LINK_NON_ELF) != 0)
2140 while (h->root.type == bfd_link_hash_indirect)
2141 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2143 if (h->root.type != bfd_link_hash_defined
2144 && h->root.type != bfd_link_hash_defweak)
2145 h->elf_link_hash_flags |= (ELF_LINK_HASH_REF_REGULAR
2146 | ELF_LINK_HASH_REF_REGULAR_NONWEAK);
2149 if (h->root.u.def.section->owner != NULL
2150 && (bfd_get_flavour (h->root.u.def.section->owner)
2151 == bfd_target_elf_flavour))
2152 h->elf_link_hash_flags |= (ELF_LINK_HASH_REF_REGULAR
2153 | ELF_LINK_HASH_REF_REGULAR_NONWEAK);
2155 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2158 if (h->dynindx == -1
2159 && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
2160 || (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0))
2162 if (! _bfd_elf_link_record_dynamic_symbol (eif->info, h))
2171 /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol
2172 was first seen in a non-ELF file. Fortunately, if the symbol
2173 was first seen in an ELF file, we're probably OK unless the
2174 symbol was defined in a non-ELF file. Catch that case here.
2175 FIXME: We're still in trouble if the symbol was first seen in
2176 a dynamic object, and then later in a non-ELF regular object. */
2177 if ((h->root.type == bfd_link_hash_defined
2178 || h->root.type == bfd_link_hash_defweak)
2179 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2180 && (h->root.u.def.section->owner != NULL
2181 ? (bfd_get_flavour (h->root.u.def.section->owner)
2182 != bfd_target_elf_flavour)
2183 : (bfd_is_abs_section (h->root.u.def.section)
2184 && (h->elf_link_hash_flags
2185 & ELF_LINK_HASH_DEF_DYNAMIC) == 0)))
2186 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2189 /* If this is a final link, and the symbol was defined as a common
2190 symbol in a regular object file, and there was no definition in
2191 any dynamic object, then the linker will have allocated space for
2192 the symbol in a common section but the ELF_LINK_HASH_DEF_REGULAR
2193 flag will not have been set. */
2194 if (h->root.type == bfd_link_hash_defined
2195 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
2196 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) != 0
2197 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
2198 && (h->root.u.def.section->owner->flags & DYNAMIC) == 0)
2199 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
2201 /* If -Bsymbolic was used (which means to bind references to global
2202 symbols to the definition within the shared object), and this
2203 symbol was defined in a regular object, then it actually doesn't
2204 need a PLT entry. Likewise, if the symbol has non-default
2205 visibility. If the symbol has hidden or internal visibility, we
2206 will force it local. */
2207 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0
2208 && eif->info->shared
2209 && is_elf_hash_table (eif->info)
2210 && (eif->info->symbolic
2211 || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
2212 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
2214 const struct elf_backend_data *bed;
2215 bfd_boolean force_local;
2217 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
2219 force_local = (ELF_ST_VISIBILITY (h->other) == STV_INTERNAL
2220 || ELF_ST_VISIBILITY (h->other) == STV_HIDDEN);
2221 (*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
2224 /* If a weak undefined symbol has non-default visibility, we also
2225 hide it from the dynamic linker. */
2226 if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2227 && h->root.type == bfd_link_hash_undefweak)
2229 const struct elf_backend_data *bed;
2230 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
2231 (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
2234 /* If this is a weak defined symbol in a dynamic object, and we know
2235 the real definition in the dynamic object, copy interesting flags
2236 over to the real definition. */
2237 if (h->weakdef != NULL)
2239 struct elf_link_hash_entry *weakdef;
2241 weakdef = h->weakdef;
2242 if (h->root.type == bfd_link_hash_indirect)
2243 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2245 BFD_ASSERT (h->root.type == bfd_link_hash_defined
2246 || h->root.type == bfd_link_hash_defweak);
2247 BFD_ASSERT (weakdef->root.type == bfd_link_hash_defined
2248 || weakdef->root.type == bfd_link_hash_defweak);
2249 BFD_ASSERT (weakdef->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC);
2251 /* If the real definition is defined by a regular object file,
2252 don't do anything special. See the longer description in
2253 _bfd_elf_adjust_dynamic_symbol, below. */
2254 if ((weakdef->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0)
2258 const struct elf_backend_data *bed;
2260 bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
2261 (*bed->elf_backend_copy_indirect_symbol) (bed, weakdef, h);
2268 /* Make the backend pick a good value for a dynamic symbol. This is
2269 called via elf_link_hash_traverse, and also calls itself
2273 _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data)
2275 struct elf_info_failed *eif = data;
2277 const struct elf_backend_data *bed;
2279 if (! is_elf_hash_table (eif->info))
2282 if (h->root.type == bfd_link_hash_warning)
2284 h->plt = elf_hash_table (eif->info)->init_offset;
2285 h->got = elf_hash_table (eif->info)->init_offset;
2287 /* When warning symbols are created, they **replace** the "real"
2288 entry in the hash table, thus we never get to see the real
2289 symbol in a hash traversal. So look at it now. */
2290 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2293 /* Ignore indirect symbols. These are added by the versioning code. */
2294 if (h->root.type == bfd_link_hash_indirect)
2297 /* Fix the symbol flags. */
2298 if (! _bfd_elf_fix_symbol_flags (h, eif))
2301 /* If this symbol does not require a PLT entry, and it is not
2302 defined by a dynamic object, or is not referenced by a regular
2303 object, ignore it. We do have to handle a weak defined symbol,
2304 even if no regular object refers to it, if we decided to add it
2305 to the dynamic symbol table. FIXME: Do we normally need to worry
2306 about symbols which are defined by one dynamic object and
2307 referenced by another one? */
2308 if ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0
2309 && ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
2310 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
2311 || ((h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
2312 && (h->weakdef == NULL || h->weakdef->dynindx == -1))))
2314 h->plt = elf_hash_table (eif->info)->init_offset;
2318 /* If we've already adjusted this symbol, don't do it again. This
2319 can happen via a recursive call. */
2320 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0)
2323 /* Don't look at this symbol again. Note that we must set this
2324 after checking the above conditions, because we may look at a
2325 symbol once, decide not to do anything, and then get called
2326 recursively later after REF_REGULAR is set below. */
2327 h->elf_link_hash_flags |= ELF_LINK_HASH_DYNAMIC_ADJUSTED;
2329 /* If this is a weak definition, and we know a real definition, and
2330 the real symbol is not itself defined by a regular object file,
2331 then get a good value for the real definition. We handle the
2332 real symbol first, for the convenience of the backend routine.
2334 Note that there is a confusing case here. If the real definition
2335 is defined by a regular object file, we don't get the real symbol
2336 from the dynamic object, but we do get the weak symbol. If the
2337 processor backend uses a COPY reloc, then if some routine in the
2338 dynamic object changes the real symbol, we will not see that
2339 change in the corresponding weak symbol. This is the way other
2340 ELF linkers work as well, and seems to be a result of the shared
2343 I will clarify this issue. Most SVR4 shared libraries define the
2344 variable _timezone and define timezone as a weak synonym. The
2345 tzset call changes _timezone. If you write
2346 extern int timezone;
2348 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
2349 you might expect that, since timezone is a synonym for _timezone,
2350 the same number will print both times. However, if the processor
2351 backend uses a COPY reloc, then actually timezone will be copied
2352 into your process image, and, since you define _timezone
2353 yourself, _timezone will not. Thus timezone and _timezone will
2354 wind up at different memory locations. The tzset call will set
2355 _timezone, leaving timezone unchanged. */
2357 if (h->weakdef != NULL)
2359 /* If we get to this point, we know there is an implicit
2360 reference by a regular object file via the weak symbol H.
2361 FIXME: Is this really true? What if the traversal finds
2362 H->WEAKDEF before it finds H? */
2363 h->weakdef->elf_link_hash_flags |= ELF_LINK_HASH_REF_REGULAR;
2365 if (! _bfd_elf_adjust_dynamic_symbol (h->weakdef, eif))
2369 /* If a symbol has no type and no size and does not require a PLT
2370 entry, then we are probably about to do the wrong thing here: we
2371 are probably going to create a COPY reloc for an empty object.
2372 This case can arise when a shared object is built with assembly
2373 code, and the assembly code fails to set the symbol type. */
2375 && h->type == STT_NOTYPE
2376 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0)
2377 (*_bfd_error_handler)
2378 (_("warning: type and size of dynamic symbol `%s' are not defined"),
2379 h->root.root.string);
2381 dynobj = elf_hash_table (eif->info)->dynobj;
2382 bed = get_elf_backend_data (dynobj);
2383 if (! (*bed->elf_backend_adjust_dynamic_symbol) (eif->info, h))
2392 /* Adjust all external symbols pointing into SEC_MERGE sections
2393 to reflect the object merging within the sections. */
2396 _bfd_elf_link_sec_merge_syms (struct elf_link_hash_entry *h, void *data)
2400 if (h->root.type == bfd_link_hash_warning)
2401 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2403 if ((h->root.type == bfd_link_hash_defined
2404 || h->root.type == bfd_link_hash_defweak)
2405 && ((sec = h->root.u.def.section)->flags & SEC_MERGE)
2406 && sec->sec_info_type == ELF_INFO_TYPE_MERGE)
2408 bfd *output_bfd = data;
2410 h->root.u.def.value =
2411 _bfd_merged_section_offset (output_bfd,
2412 &h->root.u.def.section,
2413 elf_section_data (sec)->sec_info,
2414 h->root.u.def.value, 0);
2420 /* Returns false if the symbol referred to by H should be considered
2421 to resolve local to the current module, and true if it should be
2422 considered to bind dynamically. */
2425 _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *h,
2426 struct bfd_link_info *info,
2427 bfd_boolean ignore_protected)
2429 bfd_boolean binding_stays_local_p;
2434 while (h->root.type == bfd_link_hash_indirect
2435 || h->root.type == bfd_link_hash_warning)
2436 h = (struct elf_link_hash_entry *) h->root.u.i.link;
2438 /* If it was forced local, then clearly it's not dynamic. */
2439 if (h->dynindx == -1)
2441 if (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)
2444 /* Identify the cases where name binding rules say that a
2445 visible symbol resolves locally. */
2446 binding_stays_local_p = info->executable || info->symbolic;
2448 switch (ELF_ST_VISIBILITY (h->other))
2455 /* Proper resolution for function pointer equality may require
2456 that these symbols perhaps be resolved dynamically, even though
2457 we should be resolving them to the current module. */
2458 if (!ignore_protected)
2459 binding_stays_local_p = TRUE;
2466 /* If it isn't defined locally, then clearly it's dynamic. */
2467 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2470 /* Otherwise, the symbol is dynamic if binding rules don't tell
2471 us that it remains local. */
2472 return !binding_stays_local_p;
2475 /* Return true if the symbol referred to by H should be considered
2476 to resolve local to the current module, and false otherwise. Differs
2477 from (the inverse of) _bfd_elf_dynamic_symbol_p in the treatment of
2478 undefined symbols and weak symbols. */
2481 _bfd_elf_symbol_refs_local_p (struct elf_link_hash_entry *h,
2482 struct bfd_link_info *info,
2483 bfd_boolean local_protected)
2485 /* If it's a local sym, of course we resolve locally. */
2489 /* If we don't have a definition in a regular file, then we can't
2490 resolve locally. The sym is either undefined or dynamic. */
2491 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)
2494 /* Forced local symbols resolve locally. */
2495 if ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
2498 /* As do non-dynamic symbols. */
2499 if (h->dynindx == -1)
2502 /* At this point, we know the symbol is defined and dynamic. In an
2503 executable it must resolve locally, likewise when building symbolic
2504 shared libraries. */
2505 if (info->executable || info->symbolic)
2508 /* Now deal with defined dynamic symbols in shared libraries. Ones
2509 with default visibility might not resolve locally. */
2510 if (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT)
2513 /* However, STV_HIDDEN or STV_INTERNAL ones must be local. */
2514 if (ELF_ST_VISIBILITY (h->other) != STV_PROTECTED)
2517 /* Function pointer equality tests may require that STV_PROTECTED
2518 symbols be treated as dynamic symbols, even when we know that the
2519 dynamic linker will resolve them locally. */
2520 return local_protected;