2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
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. */
21 /* ELF linker code. */
23 /* This struct is used to pass information to routines called via
24 elf_link_hash_traverse which must return failure. */
26 struct elf_info_failed
29 struct bfd_link_info
*info
;
30 struct bfd_elf_version_tree
*verdefs
;
33 static boolean is_global_data_symbol_definition
34 PARAMS ((bfd
*, Elf_Internal_Sym
*));
35 static boolean elf_link_is_defined_archive_symbol
36 PARAMS ((bfd
*, carsym
*));
37 static boolean elf_link_add_object_symbols
38 PARAMS ((bfd
*, struct bfd_link_info
*));
39 static boolean elf_link_add_archive_symbols
40 PARAMS ((bfd
*, struct bfd_link_info
*));
41 static boolean elf_merge_symbol
42 PARAMS ((bfd
*, struct bfd_link_info
*, const char *, Elf_Internal_Sym
*,
43 asection
**, bfd_vma
*, struct elf_link_hash_entry
**,
44 boolean
*, boolean
*, boolean
*, boolean
));
45 static boolean elf_export_symbol
46 PARAMS ((struct elf_link_hash_entry
*, PTR
));
47 static boolean elf_fix_symbol_flags
48 PARAMS ((struct elf_link_hash_entry
*, struct elf_info_failed
*));
49 static boolean elf_adjust_dynamic_symbol
50 PARAMS ((struct elf_link_hash_entry
*, PTR
));
51 static boolean elf_link_find_version_dependencies
52 PARAMS ((struct elf_link_hash_entry
*, PTR
));
53 static boolean elf_link_find_version_dependencies
54 PARAMS ((struct elf_link_hash_entry
*, PTR
));
55 static boolean elf_link_assign_sym_version
56 PARAMS ((struct elf_link_hash_entry
*, PTR
));
57 static boolean elf_collect_hash_codes
58 PARAMS ((struct elf_link_hash_entry
*, PTR
));
59 static boolean elf_link_read_relocs_from_section
60 PARAMS ((bfd
*, Elf_Internal_Shdr
*, PTR
, Elf_Internal_Rela
*));
61 static size_t compute_bucket_count
62 PARAMS ((struct bfd_link_info
*));
63 static void elf_link_output_relocs
64 PARAMS ((bfd
*, asection
*, Elf_Internal_Shdr
*, Elf_Internal_Rela
*));
65 static boolean elf_link_size_reloc_section
66 PARAMS ((bfd
*, Elf_Internal_Shdr
*, asection
*));
67 static void elf_link_adjust_relocs
68 PARAMS ((bfd
*, Elf_Internal_Shdr
*, unsigned int,
69 struct elf_link_hash_entry
**));
70 static int elf_link_sort_cmp1
71 PARAMS ((const void *, const void *));
72 static int elf_link_sort_cmp2
73 PARAMS ((const void *, const void *));
74 static size_t elf_link_sort_relocs
75 PARAMS ((bfd
*, struct bfd_link_info
*, asection
**));
77 /* Given an ELF BFD, add symbols to the global hash table as
81 elf_bfd_link_add_symbols (abfd
, info
)
83 struct bfd_link_info
*info
;
85 switch (bfd_get_format (abfd
))
88 return elf_link_add_object_symbols (abfd
, info
);
90 return elf_link_add_archive_symbols (abfd
, info
);
92 bfd_set_error (bfd_error_wrong_format
);
97 /* Return true iff this is a non-common, definition of a non-function symbol. */
99 is_global_data_symbol_definition (abfd
, sym
)
100 bfd
* abfd ATTRIBUTE_UNUSED
;
101 Elf_Internal_Sym
* sym
;
103 /* Local symbols do not count, but target specific ones might. */
104 if (ELF_ST_BIND (sym
->st_info
) != STB_GLOBAL
105 && ELF_ST_BIND (sym
->st_info
) < STB_LOOS
)
108 /* Function symbols do not count. */
109 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
)
112 /* If the section is undefined, then so is the symbol. */
113 if (sym
->st_shndx
== SHN_UNDEF
)
116 /* If the symbol is defined in the common section, then
117 it is a common definition and so does not count. */
118 if (sym
->st_shndx
== SHN_COMMON
)
121 /* If the symbol is in a target specific section then we
122 must rely upon the backend to tell us what it is. */
123 if (sym
->st_shndx
>= SHN_LORESERVE
&& sym
->st_shndx
< SHN_ABS
)
124 /* FIXME - this function is not coded yet:
126 return _bfd_is_global_symbol_definition (abfd, sym);
128 Instead for now assume that the definition is not global,
129 Even if this is wrong, at least the linker will behave
130 in the same way that it used to do. */
136 /* Search the symbol table of the archive element of the archive ABFD
137 whose archive map contains a mention of SYMDEF, and determine if
138 the symbol is defined in this element. */
140 elf_link_is_defined_archive_symbol (abfd
, symdef
)
144 Elf_Internal_Shdr
* hdr
;
145 Elf_External_Sym
* esym
;
146 Elf_External_Sym
* esymend
;
147 Elf_External_Sym
* buf
= NULL
;
151 boolean result
= false;
153 abfd
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
154 if (abfd
== (bfd
*) NULL
)
157 if (! bfd_check_format (abfd
, bfd_object
))
160 /* If we have already included the element containing this symbol in the
161 link then we do not need to include it again. Just claim that any symbol
162 it contains is not a definition, so that our caller will not decide to
163 (re)include this element. */
164 if (abfd
->archive_pass
)
167 /* Select the appropriate symbol table. */
168 if ((abfd
->flags
& DYNAMIC
) == 0 || elf_dynsymtab (abfd
) == 0)
169 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
171 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
173 symcount
= hdr
->sh_size
/ sizeof (Elf_External_Sym
);
175 /* The sh_info field of the symtab header tells us where the
176 external symbols start. We don't care about the local symbols. */
177 if (elf_bad_symtab (abfd
))
179 extsymcount
= symcount
;
184 extsymcount
= symcount
- hdr
->sh_info
;
185 extsymoff
= hdr
->sh_info
;
188 buf
= ((Elf_External_Sym
*)
189 bfd_malloc (extsymcount
* sizeof (Elf_External_Sym
)));
190 if (buf
== NULL
&& extsymcount
!= 0)
193 /* Read in the symbol table.
194 FIXME: This ought to be cached somewhere. */
196 hdr
->sh_offset
+ extsymoff
* sizeof (Elf_External_Sym
),
198 || (bfd_read ((PTR
) buf
, sizeof (Elf_External_Sym
), extsymcount
, abfd
)
199 != extsymcount
* sizeof (Elf_External_Sym
)))
205 /* Scan the symbol table looking for SYMDEF. */
206 esymend
= buf
+ extsymcount
;
211 Elf_Internal_Sym sym
;
214 elf_swap_symbol_in (abfd
, esym
, & sym
);
216 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
, sym
.st_name
);
217 if (name
== (const char *) NULL
)
220 if (strcmp (name
, symdef
->name
) == 0)
222 result
= is_global_data_symbol_definition (abfd
, & sym
);
232 /* Add symbols from an ELF archive file to the linker hash table. We
233 don't use _bfd_generic_link_add_archive_symbols because of a
234 problem which arises on UnixWare. The UnixWare libc.so is an
235 archive which includes an entry libc.so.1 which defines a bunch of
236 symbols. The libc.so archive also includes a number of other
237 object files, which also define symbols, some of which are the same
238 as those defined in libc.so.1. Correct linking requires that we
239 consider each object file in turn, and include it if it defines any
240 symbols we need. _bfd_generic_link_add_archive_symbols does not do
241 this; it looks through the list of undefined symbols, and includes
242 any object file which defines them. When this algorithm is used on
243 UnixWare, it winds up pulling in libc.so.1 early and defining a
244 bunch of symbols. This means that some of the other objects in the
245 archive are not included in the link, which is incorrect since they
246 precede libc.so.1 in the archive.
248 Fortunately, ELF archive handling is simpler than that done by
249 _bfd_generic_link_add_archive_symbols, which has to allow for a.out
250 oddities. In ELF, if we find a symbol in the archive map, and the
251 symbol is currently undefined, we know that we must pull in that
254 Unfortunately, we do have to make multiple passes over the symbol
255 table until nothing further is resolved. */
258 elf_link_add_archive_symbols (abfd
, info
)
260 struct bfd_link_info
*info
;
263 boolean
*defined
= NULL
;
264 boolean
*included
= NULL
;
268 if (! bfd_has_map (abfd
))
270 /* An empty archive is a special case. */
271 if (bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
) == NULL
)
273 bfd_set_error (bfd_error_no_armap
);
277 /* Keep track of all symbols we know to be already defined, and all
278 files we know to be already included. This is to speed up the
279 second and subsequent passes. */
280 c
= bfd_ardata (abfd
)->symdef_count
;
283 defined
= (boolean
*) bfd_malloc (c
* sizeof (boolean
));
284 included
= (boolean
*) bfd_malloc (c
* sizeof (boolean
));
285 if (defined
== (boolean
*) NULL
|| included
== (boolean
*) NULL
)
287 memset (defined
, 0, c
* sizeof (boolean
));
288 memset (included
, 0, c
* sizeof (boolean
));
290 symdefs
= bfd_ardata (abfd
)->symdefs
;
303 symdefend
= symdef
+ c
;
304 for (i
= 0; symdef
< symdefend
; symdef
++, i
++)
306 struct elf_link_hash_entry
*h
;
308 struct bfd_link_hash_entry
*undefs_tail
;
311 if (defined
[i
] || included
[i
])
313 if (symdef
->file_offset
== last
)
319 h
= elf_link_hash_lookup (elf_hash_table (info
), symdef
->name
,
320 false, false, false);
326 /* If this is a default version (the name contains @@),
327 look up the symbol again without the version. The
328 effect is that references to the symbol without the
329 version will be matched by the default symbol in the
332 p
= strchr (symdef
->name
, ELF_VER_CHR
);
333 if (p
== NULL
|| p
[1] != ELF_VER_CHR
)
336 copy
= bfd_alloc (abfd
, p
- symdef
->name
+ 1);
339 memcpy (copy
, symdef
->name
, p
- symdef
->name
);
340 copy
[p
- symdef
->name
] = '\0';
342 h
= elf_link_hash_lookup (elf_hash_table (info
), copy
,
343 false, false, false);
345 bfd_release (abfd
, copy
);
351 if (h
->root
.type
== bfd_link_hash_common
)
353 /* We currently have a common symbol. The archive map contains
354 a reference to this symbol, so we may want to include it. We
355 only want to include it however, if this archive element
356 contains a definition of the symbol, not just another common
359 Unfortunately some archivers (including GNU ar) will put
360 declarations of common symbols into their archive maps, as
361 well as real definitions, so we cannot just go by the archive
362 map alone. Instead we must read in the element's symbol
363 table and check that to see what kind of symbol definition
365 if (! elf_link_is_defined_archive_symbol (abfd
, symdef
))
368 else if (h
->root
.type
!= bfd_link_hash_undefined
)
370 if (h
->root
.type
!= bfd_link_hash_undefweak
)
375 /* We need to include this archive member. */
376 element
= _bfd_get_elt_at_filepos (abfd
, symdef
->file_offset
);
377 if (element
== (bfd
*) NULL
)
380 if (! bfd_check_format (element
, bfd_object
))
383 /* Doublecheck that we have not included this object
384 already--it should be impossible, but there may be
385 something wrong with the archive. */
386 if (element
->archive_pass
!= 0)
388 bfd_set_error (bfd_error_bad_value
);
391 element
->archive_pass
= 1;
393 undefs_tail
= info
->hash
->undefs_tail
;
395 if (! (*info
->callbacks
->add_archive_element
) (info
, element
,
398 if (! elf_link_add_object_symbols (element
, info
))
401 /* If there are any new undefined symbols, we need to make
402 another pass through the archive in order to see whether
403 they can be defined. FIXME: This isn't perfect, because
404 common symbols wind up on undefs_tail and because an
405 undefined symbol which is defined later on in this pass
406 does not require another pass. This isn't a bug, but it
407 does make the code less efficient than it could be. */
408 if (undefs_tail
!= info
->hash
->undefs_tail
)
411 /* Look backward to mark all symbols from this object file
412 which we have already seen in this pass. */
416 included
[mark
] = true;
421 while (symdefs
[mark
].file_offset
== symdef
->file_offset
);
423 /* We mark subsequent symbols from this object file as we go
424 on through the loop. */
425 last
= symdef
->file_offset
;
436 if (defined
!= (boolean
*) NULL
)
438 if (included
!= (boolean
*) NULL
)
443 /* This function is called when we want to define a new symbol. It
444 handles the various cases which arise when we find a definition in
445 a dynamic object, or when there is already a definition in a
446 dynamic object. The new symbol is described by NAME, SYM, PSEC,
447 and PVALUE. We set SYM_HASH to the hash table entry. We set
448 OVERRIDE if the old symbol is overriding a new definition. We set
449 TYPE_CHANGE_OK if it is OK for the type to change. We set
450 SIZE_CHANGE_OK if it is OK for the size to change. By OK to
451 change, we mean that we shouldn't warn if the type or size does
452 change. DT_NEEDED indicates if it comes from a DT_NEEDED entry of
456 elf_merge_symbol (abfd
, info
, name
, sym
, psec
, pvalue
, sym_hash
,
457 override
, type_change_ok
, size_change_ok
, dt_needed
)
459 struct bfd_link_info
*info
;
461 Elf_Internal_Sym
*sym
;
464 struct elf_link_hash_entry
**sym_hash
;
466 boolean
*type_change_ok
;
467 boolean
*size_change_ok
;
471 struct elf_link_hash_entry
*h
;
474 boolean newdyn
, olddyn
, olddef
, newdef
, newdyncommon
, olddyncommon
;
479 bind
= ELF_ST_BIND (sym
->st_info
);
481 if (! bfd_is_und_section (sec
))
482 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, true, false, false);
484 h
= ((struct elf_link_hash_entry
*)
485 bfd_wrapped_link_hash_lookup (abfd
, info
, name
, true, false, false));
490 /* This code is for coping with dynamic objects, and is only useful
491 if we are doing an ELF link. */
492 if (info
->hash
->creator
!= abfd
->xvec
)
495 /* For merging, we only care about real symbols. */
497 while (h
->root
.type
== bfd_link_hash_indirect
498 || h
->root
.type
== bfd_link_hash_warning
)
499 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
501 /* If we just created the symbol, mark it as being an ELF symbol.
502 Other than that, there is nothing to do--there is no merge issue
503 with a newly defined symbol--so we just return. */
505 if (h
->root
.type
== bfd_link_hash_new
)
507 h
->elf_link_hash_flags
&=~ ELF_LINK_NON_ELF
;
511 /* OLDBFD is a BFD associated with the existing symbol. */
513 switch (h
->root
.type
)
519 case bfd_link_hash_undefined
:
520 case bfd_link_hash_undefweak
:
521 oldbfd
= h
->root
.u
.undef
.abfd
;
524 case bfd_link_hash_defined
:
525 case bfd_link_hash_defweak
:
526 oldbfd
= h
->root
.u
.def
.section
->owner
;
529 case bfd_link_hash_common
:
530 oldbfd
= h
->root
.u
.c
.p
->section
->owner
;
534 /* In cases involving weak versioned symbols, we may wind up trying
535 to merge a symbol with itself. Catch that here, to avoid the
536 confusion that results if we try to override a symbol with
537 itself. The additional tests catch cases like
538 _GLOBAL_OFFSET_TABLE_, which are regular symbols defined in a
539 dynamic object, which we do want to handle here. */
541 && ((abfd
->flags
& DYNAMIC
) == 0
542 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0))
545 /* NEWDYN and OLDDYN indicate whether the new or old symbol,
546 respectively, is from a dynamic object. */
548 if ((abfd
->flags
& DYNAMIC
) != 0)
554 olddyn
= (oldbfd
->flags
& DYNAMIC
) != 0;
559 /* This code handles the special SHN_MIPS_{TEXT,DATA} section
560 indices used by MIPS ELF. */
561 switch (h
->root
.type
)
567 case bfd_link_hash_defined
:
568 case bfd_link_hash_defweak
:
569 hsec
= h
->root
.u
.def
.section
;
572 case bfd_link_hash_common
:
573 hsec
= h
->root
.u
.c
.p
->section
;
580 olddyn
= (hsec
->symbol
->flags
& BSF_DYNAMIC
) != 0;
583 /* NEWDEF and OLDDEF indicate whether the new or old symbol,
584 respectively, appear to be a definition rather than reference. */
586 if (bfd_is_und_section (sec
) || bfd_is_com_section (sec
))
591 if (h
->root
.type
== bfd_link_hash_undefined
592 || h
->root
.type
== bfd_link_hash_undefweak
593 || h
->root
.type
== bfd_link_hash_common
)
598 /* NEWDYNCOMMON and OLDDYNCOMMON indicate whether the new or old
599 symbol, respectively, appears to be a common symbol in a dynamic
600 object. If a symbol appears in an uninitialized section, and is
601 not weak, and is not a function, then it may be a common symbol
602 which was resolved when the dynamic object was created. We want
603 to treat such symbols specially, because they raise special
604 considerations when setting the symbol size: if the symbol
605 appears as a common symbol in a regular object, and the size in
606 the regular object is larger, we must make sure that we use the
607 larger size. This problematic case can always be avoided in C,
608 but it must be handled correctly when using Fortran shared
611 Note that if NEWDYNCOMMON is set, NEWDEF will be set, and
612 likewise for OLDDYNCOMMON and OLDDEF.
614 Note that this test is just a heuristic, and that it is quite
615 possible to have an uninitialized symbol in a shared object which
616 is really a definition, rather than a common symbol. This could
617 lead to some minor confusion when the symbol really is a common
618 symbol in some regular object. However, I think it will be
623 && (sec
->flags
& SEC_ALLOC
) != 0
624 && (sec
->flags
& SEC_LOAD
) == 0
627 && ELF_ST_TYPE (sym
->st_info
) != STT_FUNC
)
630 newdyncommon
= false;
634 && h
->root
.type
== bfd_link_hash_defined
635 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
636 && (h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0
637 && (h
->root
.u
.def
.section
->flags
& SEC_LOAD
) == 0
639 && h
->type
!= STT_FUNC
)
642 olddyncommon
= false;
644 /* It's OK to change the type if either the existing symbol or the
645 new symbol is weak unless it comes from a DT_NEEDED entry of
646 a shared object, in which case, the DT_NEEDED entry may not be
647 required at the run time. */
649 if ((! dt_needed
&& h
->root
.type
== bfd_link_hash_defweak
)
650 || h
->root
.type
== bfd_link_hash_undefweak
652 *type_change_ok
= true;
654 /* It's OK to change the size if either the existing symbol or the
655 new symbol is weak, or if the old symbol is undefined. */
658 || h
->root
.type
== bfd_link_hash_undefined
)
659 *size_change_ok
= true;
661 /* If both the old and the new symbols look like common symbols in a
662 dynamic object, set the size of the symbol to the larger of the
667 && sym
->st_size
!= h
->size
)
669 /* Since we think we have two common symbols, issue a multiple
670 common warning if desired. Note that we only warn if the
671 size is different. If the size is the same, we simply let
672 the old symbol override the new one as normally happens with
673 symbols defined in dynamic objects. */
675 if (! ((*info
->callbacks
->multiple_common
)
676 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
677 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
680 if (sym
->st_size
> h
->size
)
681 h
->size
= sym
->st_size
;
683 *size_change_ok
= true;
686 /* If we are looking at a dynamic object, and we have found a
687 definition, we need to see if the symbol was already defined by
688 some other object. If so, we want to use the existing
689 definition, and we do not want to report a multiple symbol
690 definition error; we do this by clobbering *PSEC to be
693 We treat a common symbol as a definition if the symbol in the
694 shared library is a function, since common symbols always
695 represent variables; this can cause confusion in principle, but
696 any such confusion would seem to indicate an erroneous program or
697 shared library. We also permit a common symbol in a regular
698 object to override a weak symbol in a shared object.
700 We prefer a non-weak definition in a shared library to a weak
701 definition in the executable unless it comes from a DT_NEEDED
702 entry of a shared object, in which case, the DT_NEEDED entry
703 may not be required at the run time. */
708 || (h
->root
.type
== bfd_link_hash_common
710 || ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
)))
711 && (h
->root
.type
!= bfd_link_hash_defweak
713 || bind
== STB_WEAK
))
717 newdyncommon
= false;
719 *psec
= sec
= bfd_und_section_ptr
;
720 *size_change_ok
= true;
722 /* If we get here when the old symbol is a common symbol, then
723 we are explicitly letting it override a weak symbol or
724 function in a dynamic object, and we don't want to warn about
725 a type change. If the old symbol is a defined symbol, a type
726 change warning may still be appropriate. */
728 if (h
->root
.type
== bfd_link_hash_common
)
729 *type_change_ok
= true;
732 /* Handle the special case of an old common symbol merging with a
733 new symbol which looks like a common symbol in a shared object.
734 We change *PSEC and *PVALUE to make the new symbol look like a
735 common symbol, and let _bfd_generic_link_add_one_symbol will do
739 && h
->root
.type
== bfd_link_hash_common
)
743 newdyncommon
= false;
744 *pvalue
= sym
->st_size
;
745 *psec
= sec
= bfd_com_section_ptr
;
746 *size_change_ok
= true;
749 /* If the old symbol is from a dynamic object, and the new symbol is
750 a definition which is not from a dynamic object, then the new
751 symbol overrides the old symbol. Symbols from regular files
752 always take precedence over symbols from dynamic objects, even if
753 they are defined after the dynamic object in the link.
755 As above, we again permit a common symbol in a regular object to
756 override a definition in a shared object if the shared object
757 symbol is a function or is weak.
759 As above, we permit a non-weak definition in a shared object to
760 override a weak definition in a regular object. */
764 || (bfd_is_com_section (sec
)
765 && (h
->root
.type
== bfd_link_hash_defweak
766 || h
->type
== STT_FUNC
)))
769 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
771 || h
->root
.type
== bfd_link_hash_defweak
))
773 /* Change the hash table entry to undefined, and let
774 _bfd_generic_link_add_one_symbol do the right thing with the
777 h
->root
.type
= bfd_link_hash_undefined
;
778 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
779 *size_change_ok
= true;
782 olddyncommon
= false;
784 /* We again permit a type change when a common symbol may be
785 overriding a function. */
787 if (bfd_is_com_section (sec
))
788 *type_change_ok
= true;
790 /* This union may have been set to be non-NULL when this symbol
791 was seen in a dynamic object. We must force the union to be
792 NULL, so that it is correct for a regular symbol. */
794 h
->verinfo
.vertree
= NULL
;
796 /* In this special case, if H is the target of an indirection,
797 we want the caller to frob with H rather than with the
798 indirect symbol. That will permit the caller to redefine the
799 target of the indirection, rather than the indirect symbol
800 itself. FIXME: This will break the -y option if we store a
801 symbol with a different name. */
805 /* Handle the special case of a new common symbol merging with an
806 old symbol that looks like it might be a common symbol defined in
807 a shared object. Note that we have already handled the case in
808 which a new common symbol should simply override the definition
809 in the shared library. */
812 && bfd_is_com_section (sec
)
815 /* It would be best if we could set the hash table entry to a
816 common symbol, but we don't know what to use for the section
818 if (! ((*info
->callbacks
->multiple_common
)
819 (info
, h
->root
.root
.string
, oldbfd
, bfd_link_hash_common
,
820 h
->size
, abfd
, bfd_link_hash_common
, sym
->st_size
)))
823 /* If the predumed common symbol in the dynamic object is
824 larger, pretend that the new symbol has its size. */
826 if (h
->size
> *pvalue
)
829 /* FIXME: We no longer know the alignment required by the symbol
830 in the dynamic object, so we just wind up using the one from
831 the regular object. */
834 olddyncommon
= false;
836 h
->root
.type
= bfd_link_hash_undefined
;
837 h
->root
.u
.undef
.abfd
= h
->root
.u
.def
.section
->owner
;
839 *size_change_ok
= true;
840 *type_change_ok
= true;
842 h
->verinfo
.vertree
= NULL
;
845 /* Handle the special case of a weak definition in a regular object
846 followed by a non-weak definition in a shared object. In this
847 case, we prefer the definition in the shared object unless it
848 comes from a DT_NEEDED entry of a shared object, in which case,
849 the DT_NEEDED entry may not be required at the run time. */
852 && h
->root
.type
== bfd_link_hash_defweak
857 /* To make this work we have to frob the flags so that the rest
858 of the code does not think we are using the regular
860 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
861 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
862 else if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0)
863 h
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
864 h
->elf_link_hash_flags
&= ~ (ELF_LINK_HASH_DEF_REGULAR
865 | ELF_LINK_HASH_DEF_DYNAMIC
);
867 /* If H is the target of an indirection, we want the caller to
868 use H rather than the indirect symbol. Otherwise if we are
869 defining a new indirect symbol we will wind up attaching it
870 to the entry we are overriding. */
874 /* Handle the special case of a non-weak definition in a shared
875 object followed by a weak definition in a regular object. In
876 this case we prefer to definition in the shared object. To make
877 this work we have to tell the caller to not treat the new symbol
881 && h
->root
.type
!= bfd_link_hash_defweak
890 /* Add symbols from an ELF object file to the linker hash table. */
893 elf_link_add_object_symbols (abfd
, info
)
895 struct bfd_link_info
*info
;
897 boolean (*add_symbol_hook
) PARAMS ((bfd
*, struct bfd_link_info
*,
898 const Elf_Internal_Sym
*,
899 const char **, flagword
*,
900 asection
**, bfd_vma
*));
901 boolean (*check_relocs
) PARAMS ((bfd
*, struct bfd_link_info
*,
902 asection
*, const Elf_Internal_Rela
*));
904 Elf_Internal_Shdr
*hdr
;
908 Elf_External_Sym
*buf
= NULL
;
909 struct elf_link_hash_entry
**sym_hash
;
911 Elf_External_Versym
*extversym
= NULL
;
912 Elf_External_Versym
*ever
;
913 Elf_External_Dyn
*dynbuf
= NULL
;
914 struct elf_link_hash_entry
*weaks
;
915 Elf_External_Sym
*esym
;
916 Elf_External_Sym
*esymend
;
917 struct elf_backend_data
*bed
;
919 struct elf_link_hash_table
* hash_table
;
921 hash_table
= elf_hash_table (info
);
923 bed
= get_elf_backend_data (abfd
);
924 add_symbol_hook
= bed
->elf_add_symbol_hook
;
925 collect
= bed
->collect
;
927 if ((abfd
->flags
& DYNAMIC
) == 0)
933 /* You can't use -r against a dynamic object. Also, there's no
934 hope of using a dynamic object which does not exactly match
935 the format of the output file. */
936 if (info
->relocateable
|| info
->hash
->creator
!= abfd
->xvec
)
938 bfd_set_error (bfd_error_invalid_operation
);
943 /* As a GNU extension, any input sections which are named
944 .gnu.warning.SYMBOL are treated as warning symbols for the given
945 symbol. This differs from .gnu.warning sections, which generate
946 warnings when they are included in an output file. */
951 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
955 name
= bfd_get_section_name (abfd
, s
);
956 if (strncmp (name
, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0)
961 name
+= sizeof ".gnu.warning." - 1;
963 /* If this is a shared object, then look up the symbol
964 in the hash table. If it is there, and it is already
965 been defined, then we will not be using the entry
966 from this shared object, so we don't need to warn.
967 FIXME: If we see the definition in a regular object
968 later on, we will warn, but we shouldn't. The only
969 fix is to keep track of what warnings we are supposed
970 to emit, and then handle them all at the end of the
972 if (dynamic
&& abfd
->xvec
== info
->hash
->creator
)
974 struct elf_link_hash_entry
*h
;
976 h
= elf_link_hash_lookup (hash_table
, name
,
979 /* FIXME: What about bfd_link_hash_common? */
981 && (h
->root
.type
== bfd_link_hash_defined
982 || h
->root
.type
== bfd_link_hash_defweak
))
984 /* We don't want to issue this warning. Clobber
985 the section size so that the warning does not
986 get copied into the output file. */
992 sz
= bfd_section_size (abfd
, s
);
993 msg
= (char *) bfd_alloc (abfd
, sz
+ 1);
997 if (! bfd_get_section_contents (abfd
, s
, msg
, (file_ptr
) 0, sz
))
1002 if (! (_bfd_generic_link_add_one_symbol
1003 (info
, abfd
, name
, BSF_WARNING
, s
, (bfd_vma
) 0, msg
,
1004 false, collect
, (struct bfd_link_hash_entry
**) NULL
)))
1007 if (! info
->relocateable
)
1009 /* Clobber the section size so that the warning does
1010 not get copied into the output file. */
1017 /* If this is a dynamic object, we always link against the .dynsym
1018 symbol table, not the .symtab symbol table. The dynamic linker
1019 will only see the .dynsym symbol table, so there is no reason to
1020 look at .symtab for a dynamic object. */
1022 if (! dynamic
|| elf_dynsymtab (abfd
) == 0)
1023 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1025 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
1029 /* Read in any version definitions. */
1031 if (! _bfd_elf_slurp_version_tables (abfd
))
1034 /* Read in the symbol versions, but don't bother to convert them
1035 to internal format. */
1036 if (elf_dynversym (abfd
) != 0)
1038 Elf_Internal_Shdr
*versymhdr
;
1040 versymhdr
= &elf_tdata (abfd
)->dynversym_hdr
;
1041 extversym
= (Elf_External_Versym
*) bfd_malloc (versymhdr
->sh_size
);
1042 if (extversym
== NULL
)
1044 if (bfd_seek (abfd
, versymhdr
->sh_offset
, SEEK_SET
) != 0
1045 || (bfd_read ((PTR
) extversym
, 1, versymhdr
->sh_size
, abfd
)
1046 != versymhdr
->sh_size
))
1051 symcount
= hdr
->sh_size
/ sizeof (Elf_External_Sym
);
1053 /* The sh_info field of the symtab header tells us where the
1054 external symbols start. We don't care about the local symbols at
1056 if (elf_bad_symtab (abfd
))
1058 extsymcount
= symcount
;
1063 extsymcount
= symcount
- hdr
->sh_info
;
1064 extsymoff
= hdr
->sh_info
;
1067 buf
= ((Elf_External_Sym
*)
1068 bfd_malloc (extsymcount
* sizeof (Elf_External_Sym
)));
1069 if (buf
== NULL
&& extsymcount
!= 0)
1072 /* We store a pointer to the hash table entry for each external
1074 sym_hash
= ((struct elf_link_hash_entry
**)
1076 extsymcount
* sizeof (struct elf_link_hash_entry
*)));
1077 if (sym_hash
== NULL
)
1079 elf_sym_hashes (abfd
) = sym_hash
;
1085 /* If we are creating a shared library, create all the dynamic
1086 sections immediately. We need to attach them to something,
1087 so we attach them to this BFD, provided it is the right
1088 format. FIXME: If there are no input BFD's of the same
1089 format as the output, we can't make a shared library. */
1091 && is_elf_hash_table (info
)
1092 && ! hash_table
->dynamic_sections_created
1093 && abfd
->xvec
== info
->hash
->creator
)
1095 if (! elf_link_create_dynamic_sections (abfd
, info
))
1099 else if (! is_elf_hash_table (info
))
1106 bfd_size_type oldsize
;
1107 bfd_size_type strindex
;
1109 /* Find the name to use in a DT_NEEDED entry that refers to this
1110 object. If the object has a DT_SONAME entry, we use it.
1111 Otherwise, if the generic linker stuck something in
1112 elf_dt_name, we use that. Otherwise, we just use the file
1113 name. If the generic linker put a null string into
1114 elf_dt_name, we don't make a DT_NEEDED entry at all, even if
1115 there is a DT_SONAME entry. */
1117 name
= bfd_get_filename (abfd
);
1118 if (elf_dt_name (abfd
) != NULL
)
1120 name
= elf_dt_name (abfd
);
1123 if (elf_dt_soname (abfd
) != NULL
)
1129 s
= bfd_get_section_by_name (abfd
, ".dynamic");
1132 Elf_External_Dyn
*extdyn
;
1133 Elf_External_Dyn
*extdynend
;
1139 dynbuf
= (Elf_External_Dyn
*) bfd_malloc ((size_t) s
->_raw_size
);
1143 if (! bfd_get_section_contents (abfd
, s
, (PTR
) dynbuf
,
1144 (file_ptr
) 0, s
->_raw_size
))
1147 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
1150 link
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
1153 /* The shared libraries distributed with hpux11 have a bogus
1154 sh_link field for the ".dynamic" section. This code detects
1155 when LINK refers to a section that is not a string table and
1156 tries to find the string table for the ".dynsym" section
1158 Elf_Internal_Shdr
*hdr
= elf_elfsections (abfd
)[link
];
1159 if (hdr
->sh_type
!= SHT_STRTAB
)
1161 asection
*s
= bfd_get_section_by_name (abfd
, ".dynsym");
1162 int elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
1165 link
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
1170 extdynend
= extdyn
+ s
->_raw_size
/ sizeof (Elf_External_Dyn
);
1173 for (; extdyn
< extdynend
; extdyn
++)
1175 Elf_Internal_Dyn dyn
;
1177 elf_swap_dyn_in (abfd
, extdyn
, &dyn
);
1178 if (dyn
.d_tag
== DT_SONAME
)
1180 name
= bfd_elf_string_from_elf_section (abfd
, link
,
1185 if (dyn
.d_tag
== DT_NEEDED
)
1187 struct bfd_link_needed_list
*n
, **pn
;
1190 n
= ((struct bfd_link_needed_list
*)
1191 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1192 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1194 if (n
== NULL
|| fnm
== NULL
)
1196 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1203 for (pn
= & hash_table
->needed
;
1209 if (dyn
.d_tag
== DT_RUNPATH
)
1211 struct bfd_link_needed_list
*n
, **pn
;
1214 /* When we see DT_RPATH before DT_RUNPATH, we have
1215 to clear runpath. Do _NOT_ bfd_release, as that
1216 frees all more recently bfd_alloc'd blocks as
1218 if (rpath
&& hash_table
->runpath
)
1219 hash_table
->runpath
= NULL
;
1221 n
= ((struct bfd_link_needed_list
*)
1222 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1223 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1225 if (n
== NULL
|| fnm
== NULL
)
1227 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1234 for (pn
= & hash_table
->runpath
;
1242 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */
1243 if (!runpath
&& dyn
.d_tag
== DT_RPATH
)
1245 struct bfd_link_needed_list
*n
, **pn
;
1248 n
= ((struct bfd_link_needed_list
*)
1249 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1250 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1252 if (n
== NULL
|| fnm
== NULL
)
1254 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1261 for (pn
= & hash_table
->runpath
;
1274 /* We do not want to include any of the sections in a dynamic
1275 object in the output file. We hack by simply clobbering the
1276 list of sections in the BFD. This could be handled more
1277 cleanly by, say, a new section flag; the existing
1278 SEC_NEVER_LOAD flag is not the one we want, because that one
1279 still implies that the section takes up space in the output
1281 abfd
->sections
= NULL
;
1282 abfd
->section_count
= 0;
1284 /* If this is the first dynamic object found in the link, create
1285 the special sections required for dynamic linking. */
1286 if (! hash_table
->dynamic_sections_created
)
1287 if (! elf_link_create_dynamic_sections (abfd
, info
))
1292 /* Add a DT_NEEDED entry for this dynamic object. */
1293 oldsize
= _bfd_stringtab_size (hash_table
->dynstr
);
1294 strindex
= _bfd_stringtab_add (hash_table
->dynstr
, name
,
1296 if (strindex
== (bfd_size_type
) -1)
1299 if (oldsize
== _bfd_stringtab_size (hash_table
->dynstr
))
1302 Elf_External_Dyn
*dyncon
, *dynconend
;
1304 /* The hash table size did not change, which means that
1305 the dynamic object name was already entered. If we
1306 have already included this dynamic object in the
1307 link, just ignore it. There is no reason to include
1308 a particular dynamic object more than once. */
1309 sdyn
= bfd_get_section_by_name (hash_table
->dynobj
, ".dynamic");
1310 BFD_ASSERT (sdyn
!= NULL
);
1312 dyncon
= (Elf_External_Dyn
*) sdyn
->contents
;
1313 dynconend
= (Elf_External_Dyn
*) (sdyn
->contents
+
1315 for (; dyncon
< dynconend
; dyncon
++)
1317 Elf_Internal_Dyn dyn
;
1319 elf_swap_dyn_in (hash_table
->dynobj
, dyncon
, & dyn
);
1320 if (dyn
.d_tag
== DT_NEEDED
1321 && dyn
.d_un
.d_val
== strindex
)
1325 if (extversym
!= NULL
)
1332 if (! elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
1336 /* Save the SONAME, if there is one, because sometimes the
1337 linker emulation code will need to know it. */
1339 name
= basename (bfd_get_filename (abfd
));
1340 elf_dt_name (abfd
) = name
;
1344 hdr
->sh_offset
+ extsymoff
* sizeof (Elf_External_Sym
),
1346 || (bfd_read ((PTR
) buf
, sizeof (Elf_External_Sym
), extsymcount
, abfd
)
1347 != extsymcount
* sizeof (Elf_External_Sym
)))
1352 ever
= extversym
!= NULL
? extversym
+ extsymoff
: NULL
;
1353 esymend
= buf
+ extsymcount
;
1356 esym
++, sym_hash
++, ever
= (ever
!= NULL
? ever
+ 1 : NULL
))
1358 Elf_Internal_Sym sym
;
1364 struct elf_link_hash_entry
*h
;
1366 boolean size_change_ok
, type_change_ok
;
1367 boolean new_weakdef
;
1368 unsigned int old_alignment
;
1370 elf_swap_symbol_in (abfd
, esym
, &sym
);
1372 flags
= BSF_NO_FLAGS
;
1374 value
= sym
.st_value
;
1377 bind
= ELF_ST_BIND (sym
.st_info
);
1378 if (bind
== STB_LOCAL
)
1380 /* This should be impossible, since ELF requires that all
1381 global symbols follow all local symbols, and that sh_info
1382 point to the first global symbol. Unfortunatealy, Irix 5
1386 else if (bind
== STB_GLOBAL
)
1388 if (sym
.st_shndx
!= SHN_UNDEF
1389 && sym
.st_shndx
!= SHN_COMMON
)
1392 else if (bind
== STB_WEAK
)
1396 /* Leave it up to the processor backend. */
1399 if (sym
.st_shndx
== SHN_UNDEF
)
1400 sec
= bfd_und_section_ptr
;
1401 else if (sym
.st_shndx
> 0 && sym
.st_shndx
< SHN_LORESERVE
)
1403 sec
= section_from_elf_index (abfd
, sym
.st_shndx
);
1405 sec
= bfd_abs_section_ptr
;
1406 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
1409 else if (sym
.st_shndx
== SHN_ABS
)
1410 sec
= bfd_abs_section_ptr
;
1411 else if (sym
.st_shndx
== SHN_COMMON
)
1413 sec
= bfd_com_section_ptr
;
1414 /* What ELF calls the size we call the value. What ELF
1415 calls the value we call the alignment. */
1416 value
= sym
.st_size
;
1420 /* Leave it up to the processor backend. */
1423 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
, sym
.st_name
);
1424 if (name
== (const char *) NULL
)
1427 if (add_symbol_hook
)
1429 if (! (*add_symbol_hook
) (abfd
, info
, &sym
, &name
, &flags
, &sec
,
1433 /* The hook function sets the name to NULL if this symbol
1434 should be skipped for some reason. */
1435 if (name
== (const char *) NULL
)
1439 /* Sanity check that all possibilities were handled. */
1440 if (sec
== (asection
*) NULL
)
1442 bfd_set_error (bfd_error_bad_value
);
1446 if (bfd_is_und_section (sec
)
1447 || bfd_is_com_section (sec
))
1452 size_change_ok
= false;
1453 type_change_ok
= get_elf_backend_data (abfd
)->type_change_ok
;
1455 if (info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
1457 Elf_Internal_Versym iver
;
1458 unsigned int vernum
= 0;
1463 _bfd_elf_swap_versym_in (abfd
, ever
, &iver
);
1464 vernum
= iver
.vs_vers
& VERSYM_VERSION
;
1466 /* If this is a hidden symbol, or if it is not version
1467 1, we append the version name to the symbol name.
1468 However, we do not modify a non-hidden absolute
1469 symbol, because it might be the version symbol
1470 itself. FIXME: What if it isn't? */
1471 if ((iver
.vs_vers
& VERSYM_HIDDEN
) != 0
1472 || (vernum
> 1 && ! bfd_is_abs_section (sec
)))
1475 int namelen
, newlen
;
1478 if (sym
.st_shndx
!= SHN_UNDEF
)
1480 if (vernum
> elf_tdata (abfd
)->dynverdef_hdr
.sh_info
)
1482 (*_bfd_error_handler
)
1483 (_("%s: %s: invalid version %u (max %d)"),
1484 bfd_get_filename (abfd
), name
, vernum
,
1485 elf_tdata (abfd
)->dynverdef_hdr
.sh_info
);
1486 bfd_set_error (bfd_error_bad_value
);
1489 else if (vernum
> 1)
1491 elf_tdata (abfd
)->verdef
[vernum
- 1].vd_nodename
;
1497 /* We cannot simply test for the number of
1498 entries in the VERNEED section since the
1499 numbers for the needed versions do not start
1501 Elf_Internal_Verneed
*t
;
1504 for (t
= elf_tdata (abfd
)->verref
;
1508 Elf_Internal_Vernaux
*a
;
1510 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
1512 if (a
->vna_other
== vernum
)
1514 verstr
= a
->vna_nodename
;
1523 (*_bfd_error_handler
)
1524 (_("%s: %s: invalid needed version %d"),
1525 bfd_get_filename (abfd
), name
, vernum
);
1526 bfd_set_error (bfd_error_bad_value
);
1531 namelen
= strlen (name
);
1532 newlen
= namelen
+ strlen (verstr
) + 2;
1533 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0)
1536 newname
= (char *) bfd_alloc (abfd
, newlen
);
1537 if (newname
== NULL
)
1539 strcpy (newname
, name
);
1540 p
= newname
+ namelen
;
1542 /* If this is a defined non-hidden version symbol,
1543 we add another @ to the name. This indicates the
1544 default version of the symbol. */
1545 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
1546 && sym
.st_shndx
!= SHN_UNDEF
)
1554 if (! elf_merge_symbol (abfd
, info
, name
, &sym
, &sec
, &value
,
1555 sym_hash
, &override
, &type_change_ok
,
1556 &size_change_ok
, dt_needed
))
1563 while (h
->root
.type
== bfd_link_hash_indirect
1564 || h
->root
.type
== bfd_link_hash_warning
)
1565 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1567 /* Remember the old alignment if this is a common symbol, so
1568 that we don't reduce the alignment later on. We can't
1569 check later, because _bfd_generic_link_add_one_symbol
1570 will set a default for the alignment which we want to
1572 if (h
->root
.type
== bfd_link_hash_common
)
1573 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
1575 if (elf_tdata (abfd
)->verdef
!= NULL
1579 h
->verinfo
.verdef
= &elf_tdata (abfd
)->verdef
[vernum
- 1];
1582 if (! (_bfd_generic_link_add_one_symbol
1583 (info
, abfd
, name
, flags
, sec
, value
, (const char *) NULL
,
1584 false, collect
, (struct bfd_link_hash_entry
**) sym_hash
)))
1588 while (h
->root
.type
== bfd_link_hash_indirect
1589 || h
->root
.type
== bfd_link_hash_warning
)
1590 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1593 new_weakdef
= false;
1596 && (flags
& BSF_WEAK
) != 0
1597 && ELF_ST_TYPE (sym
.st_info
) != STT_FUNC
1598 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
1599 && h
->weakdef
== NULL
)
1601 /* Keep a list of all weak defined non function symbols from
1602 a dynamic object, using the weakdef field. Later in this
1603 function we will set the weakdef field to the correct
1604 value. We only put non-function symbols from dynamic
1605 objects on this list, because that happens to be the only
1606 time we need to know the normal symbol corresponding to a
1607 weak symbol, and the information is time consuming to
1608 figure out. If the weakdef field is not already NULL,
1609 then this symbol was already defined by some previous
1610 dynamic object, and we will be using that previous
1611 definition anyhow. */
1618 /* Set the alignment of a common symbol. */
1619 if (sym
.st_shndx
== SHN_COMMON
1620 && h
->root
.type
== bfd_link_hash_common
)
1624 align
= bfd_log2 (sym
.st_value
);
1625 if (align
> old_alignment
1626 /* Permit an alignment power of zero if an alignment of one
1627 is specified and no other alignments have been specified. */
1628 || (sym
.st_value
== 1 && old_alignment
== 0))
1629 h
->root
.u
.c
.p
->alignment_power
= align
;
1632 if (info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
1638 /* Remember the symbol size and type. */
1639 if (sym
.st_size
!= 0
1640 && (definition
|| h
->size
== 0))
1642 if (h
->size
!= 0 && h
->size
!= sym
.st_size
&& ! size_change_ok
)
1643 (*_bfd_error_handler
)
1644 (_("Warning: size of symbol `%s' changed from %lu to %lu in %s"),
1645 name
, (unsigned long) h
->size
, (unsigned long) sym
.st_size
,
1646 bfd_get_filename (abfd
));
1648 h
->size
= sym
.st_size
;
1651 /* If this is a common symbol, then we always want H->SIZE
1652 to be the size of the common symbol. The code just above
1653 won't fix the size if a common symbol becomes larger. We
1654 don't warn about a size change here, because that is
1655 covered by --warn-common. */
1656 if (h
->root
.type
== bfd_link_hash_common
)
1657 h
->size
= h
->root
.u
.c
.size
;
1659 if (ELF_ST_TYPE (sym
.st_info
) != STT_NOTYPE
1660 && (definition
|| h
->type
== STT_NOTYPE
))
1662 if (h
->type
!= STT_NOTYPE
1663 && h
->type
!= ELF_ST_TYPE (sym
.st_info
)
1664 && ! type_change_ok
)
1665 (*_bfd_error_handler
)
1666 (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
1667 name
, h
->type
, ELF_ST_TYPE (sym
.st_info
),
1668 bfd_get_filename (abfd
));
1670 h
->type
= ELF_ST_TYPE (sym
.st_info
);
1673 /* If st_other has a processor-specific meaning, specific code
1674 might be needed here. */
1675 if (sym
.st_other
!= 0)
1677 /* Combine visibilities, using the most constraining one. */
1678 unsigned char hvis
= ELF_ST_VISIBILITY (h
->other
);
1679 unsigned char symvis
= ELF_ST_VISIBILITY (sym
.st_other
);
1681 if (symvis
&& (hvis
> symvis
|| hvis
== 0))
1682 h
->other
= sym
.st_other
;
1684 /* If neither has visibility, use the st_other of the
1685 definition. This is an arbitrary choice, since the
1686 other bits have no general meaning. */
1687 if (!symvis
&& !hvis
1688 && (definition
|| h
->other
== 0))
1689 h
->other
= sym
.st_other
;
1692 /* Set a flag in the hash table entry indicating the type of
1693 reference or definition we just found. Keep a count of
1694 the number of dynamic symbols we find. A dynamic symbol
1695 is one which is referenced or defined by both a regular
1696 object and a shared object. */
1697 old_flags
= h
->elf_link_hash_flags
;
1703 new_flag
= ELF_LINK_HASH_REF_REGULAR
;
1704 if (bind
!= STB_WEAK
)
1705 new_flag
|= ELF_LINK_HASH_REF_REGULAR_NONWEAK
;
1708 new_flag
= ELF_LINK_HASH_DEF_REGULAR
;
1710 || (old_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
1711 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0)
1717 new_flag
= ELF_LINK_HASH_REF_DYNAMIC
;
1719 new_flag
= ELF_LINK_HASH_DEF_DYNAMIC
;
1720 if ((old_flags
& (ELF_LINK_HASH_DEF_REGULAR
1721 | ELF_LINK_HASH_REF_REGULAR
)) != 0
1722 || (h
->weakdef
!= NULL
1724 && h
->weakdef
->dynindx
!= -1))
1728 h
->elf_link_hash_flags
|= new_flag
;
1730 /* If this symbol has a version, and it is the default
1731 version, we create an indirect symbol from the default
1732 name to the fully decorated name. This will cause
1733 external references which do not specify a version to be
1734 bound to this version of the symbol. */
1735 if (definition
|| h
->root
.type
== bfd_link_hash_common
)
1739 p
= strchr (name
, ELF_VER_CHR
);
1740 if (p
!= NULL
&& p
[1] == ELF_VER_CHR
)
1743 struct elf_link_hash_entry
*hi
;
1746 shortname
= bfd_hash_allocate (&info
->hash
->table
,
1748 if (shortname
== NULL
)
1750 strncpy (shortname
, name
, p
- name
);
1751 shortname
[p
- name
] = '\0';
1753 /* We are going to create a new symbol. Merge it
1754 with any existing symbol with this name. For the
1755 purposes of the merge, act as though we were
1756 defining the symbol we just defined, although we
1757 actually going to define an indirect symbol. */
1758 type_change_ok
= false;
1759 size_change_ok
= false;
1760 if (! elf_merge_symbol (abfd
, info
, shortname
, &sym
, &sec
,
1761 &value
, &hi
, &override
,
1763 &size_change_ok
, dt_needed
))
1768 if (! (_bfd_generic_link_add_one_symbol
1769 (info
, abfd
, shortname
, BSF_INDIRECT
,
1770 bfd_ind_section_ptr
, (bfd_vma
) 0, name
, false,
1771 collect
, (struct bfd_link_hash_entry
**) &hi
)))
1776 /* In this case the symbol named SHORTNAME is
1777 overriding the indirect symbol we want to
1778 add. We were planning on making SHORTNAME an
1779 indirect symbol referring to NAME. SHORTNAME
1780 is the name without a version. NAME is the
1781 fully versioned name, and it is the default
1784 Overriding means that we already saw a
1785 definition for the symbol SHORTNAME in a
1786 regular object, and it is overriding the
1787 symbol defined in the dynamic object.
1789 When this happens, we actually want to change
1790 NAME, the symbol we just added, to refer to
1791 SHORTNAME. This will cause references to
1792 NAME in the shared object to become
1793 references to SHORTNAME in the regular
1794 object. This is what we expect when we
1795 override a function in a shared object: that
1796 the references in the shared object will be
1797 mapped to the definition in the regular
1800 while (hi
->root
.type
== bfd_link_hash_indirect
1801 || hi
->root
.type
== bfd_link_hash_warning
)
1802 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1804 h
->root
.type
= bfd_link_hash_indirect
;
1805 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) hi
;
1806 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
1808 h
->elf_link_hash_flags
&=~ ELF_LINK_HASH_DEF_DYNAMIC
;
1809 hi
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
1810 if (hi
->elf_link_hash_flags
1811 & (ELF_LINK_HASH_REF_REGULAR
1812 | ELF_LINK_HASH_DEF_REGULAR
))
1814 if (! _bfd_elf_link_record_dynamic_symbol (info
,
1820 /* Now set HI to H, so that the following code
1821 will set the other fields correctly. */
1825 /* If there is a duplicate definition somewhere,
1826 then HI may not point to an indirect symbol. We
1827 will have reported an error to the user in that
1830 if (hi
->root
.type
== bfd_link_hash_indirect
)
1832 struct elf_link_hash_entry
*ht
;
1834 /* If the symbol became indirect, then we assume
1835 that we have not seen a definition before. */
1836 BFD_ASSERT ((hi
->elf_link_hash_flags
1837 & (ELF_LINK_HASH_DEF_DYNAMIC
1838 | ELF_LINK_HASH_DEF_REGULAR
))
1841 ht
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1842 (*bed
->elf_backend_copy_indirect_symbol
) (ht
, hi
);
1844 /* See if the new flags lead us to realize that
1845 the symbol must be dynamic. */
1851 || ((hi
->elf_link_hash_flags
1852 & ELF_LINK_HASH_REF_DYNAMIC
)
1858 if ((hi
->elf_link_hash_flags
1859 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1865 /* We also need to define an indirection from the
1866 nondefault version of the symbol. */
1868 shortname
= bfd_hash_allocate (&info
->hash
->table
,
1870 if (shortname
== NULL
)
1872 strncpy (shortname
, name
, p
- name
);
1873 strcpy (shortname
+ (p
- name
), p
+ 1);
1875 /* Once again, merge with any existing symbol. */
1876 type_change_ok
= false;
1877 size_change_ok
= false;
1878 if (! elf_merge_symbol (abfd
, info
, shortname
, &sym
, &sec
,
1879 &value
, &hi
, &override
,
1881 &size_change_ok
, dt_needed
))
1886 /* Here SHORTNAME is a versioned name, so we
1887 don't expect to see the type of override we
1888 do in the case above. */
1889 (*_bfd_error_handler
)
1890 (_("%s: warning: unexpected redefinition of `%s'"),
1891 bfd_get_filename (abfd
), shortname
);
1895 if (! (_bfd_generic_link_add_one_symbol
1896 (info
, abfd
, shortname
, BSF_INDIRECT
,
1897 bfd_ind_section_ptr
, (bfd_vma
) 0, name
, false,
1898 collect
, (struct bfd_link_hash_entry
**) &hi
)))
1901 /* If there is a duplicate definition somewhere,
1902 then HI may not point to an indirect symbol.
1903 We will have reported an error to the user in
1906 if (hi
->root
.type
== bfd_link_hash_indirect
)
1908 /* If the symbol became indirect, then we
1909 assume that we have not seen a definition
1911 BFD_ASSERT ((hi
->elf_link_hash_flags
1912 & (ELF_LINK_HASH_DEF_DYNAMIC
1913 | ELF_LINK_HASH_DEF_REGULAR
))
1916 (*bed
->elf_backend_copy_indirect_symbol
) (h
, hi
);
1918 /* See if the new flags lead us to realize
1919 that the symbol must be dynamic. */
1925 || ((hi
->elf_link_hash_flags
1926 & ELF_LINK_HASH_REF_DYNAMIC
)
1932 if ((hi
->elf_link_hash_flags
1933 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1942 if (dynsym
&& h
->dynindx
== -1)
1944 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1946 if (h
->weakdef
!= NULL
1948 && h
->weakdef
->dynindx
== -1)
1950 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
1954 else if (dynsym
&& h
->dynindx
!= -1)
1955 /* If the symbol already has a dynamic index, but
1956 visibility says it should not be visible, turn it into
1958 switch (ELF_ST_VISIBILITY (h
->other
))
1962 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
1963 (*bed
->elf_backend_hide_symbol
) (info
, h
);
1967 if (dt_needed
&& definition
1968 && (h
->elf_link_hash_flags
1969 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1971 bfd_size_type oldsize
;
1972 bfd_size_type strindex
;
1974 if (! is_elf_hash_table (info
))
1977 /* The symbol from a DT_NEEDED object is referenced from
1978 the regular object to create a dynamic executable. We
1979 have to make sure there is a DT_NEEDED entry for it. */
1982 oldsize
= _bfd_stringtab_size (hash_table
->dynstr
);
1983 strindex
= _bfd_stringtab_add (hash_table
->dynstr
,
1984 elf_dt_soname (abfd
),
1986 if (strindex
== (bfd_size_type
) -1)
1990 == _bfd_stringtab_size (hash_table
->dynstr
))
1993 Elf_External_Dyn
*dyncon
, *dynconend
;
1995 sdyn
= bfd_get_section_by_name (hash_table
->dynobj
,
1997 BFD_ASSERT (sdyn
!= NULL
);
1999 dyncon
= (Elf_External_Dyn
*) sdyn
->contents
;
2000 dynconend
= (Elf_External_Dyn
*) (sdyn
->contents
+
2002 for (; dyncon
< dynconend
; dyncon
++)
2004 Elf_Internal_Dyn dyn
;
2006 elf_swap_dyn_in (hash_table
->dynobj
,
2008 BFD_ASSERT (dyn
.d_tag
!= DT_NEEDED
||
2009 dyn
.d_un
.d_val
!= strindex
);
2013 if (! elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
2019 /* Now set the weakdefs field correctly for all the weak defined
2020 symbols we found. The only way to do this is to search all the
2021 symbols. Since we only need the information for non functions in
2022 dynamic objects, that's the only time we actually put anything on
2023 the list WEAKS. We need this information so that if a regular
2024 object refers to a symbol defined weakly in a dynamic object, the
2025 real symbol in the dynamic object is also put in the dynamic
2026 symbols; we also must arrange for both symbols to point to the
2027 same memory location. We could handle the general case of symbol
2028 aliasing, but a general symbol alias can only be generated in
2029 assembler code, handling it correctly would be very time
2030 consuming, and other ELF linkers don't handle general aliasing
2032 while (weaks
!= NULL
)
2034 struct elf_link_hash_entry
*hlook
;
2037 struct elf_link_hash_entry
**hpp
;
2038 struct elf_link_hash_entry
**hppend
;
2041 weaks
= hlook
->weakdef
;
2042 hlook
->weakdef
= NULL
;
2044 BFD_ASSERT (hlook
->root
.type
== bfd_link_hash_defined
2045 || hlook
->root
.type
== bfd_link_hash_defweak
2046 || hlook
->root
.type
== bfd_link_hash_common
2047 || hlook
->root
.type
== bfd_link_hash_indirect
);
2048 slook
= hlook
->root
.u
.def
.section
;
2049 vlook
= hlook
->root
.u
.def
.value
;
2051 hpp
= elf_sym_hashes (abfd
);
2052 hppend
= hpp
+ extsymcount
;
2053 for (; hpp
< hppend
; hpp
++)
2055 struct elf_link_hash_entry
*h
;
2058 if (h
!= NULL
&& h
!= hlook
2059 && h
->root
.type
== bfd_link_hash_defined
2060 && h
->root
.u
.def
.section
== slook
2061 && h
->root
.u
.def
.value
== vlook
)
2065 /* If the weak definition is in the list of dynamic
2066 symbols, make sure the real definition is put there
2068 if (hlook
->dynindx
!= -1
2069 && h
->dynindx
== -1)
2071 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2075 /* If the real definition is in the list of dynamic
2076 symbols, make sure the weak definition is put there
2077 as well. If we don't do this, then the dynamic
2078 loader might not merge the entries for the real
2079 definition and the weak definition. */
2080 if (h
->dynindx
!= -1
2081 && hlook
->dynindx
== -1)
2083 if (! _bfd_elf_link_record_dynamic_symbol (info
, hlook
))
2098 if (extversym
!= NULL
)
2104 /* If this object is the same format as the output object, and it is
2105 not a shared library, then let the backend look through the
2108 This is required to build global offset table entries and to
2109 arrange for dynamic relocs. It is not required for the
2110 particular common case of linking non PIC code, even when linking
2111 against shared libraries, but unfortunately there is no way of
2112 knowing whether an object file has been compiled PIC or not.
2113 Looking through the relocs is not particularly time consuming.
2114 The problem is that we must either (1) keep the relocs in memory,
2115 which causes the linker to require additional runtime memory or
2116 (2) read the relocs twice from the input file, which wastes time.
2117 This would be a good case for using mmap.
2119 I have no idea how to handle linking PIC code into a file of a
2120 different format. It probably can't be done. */
2121 check_relocs
= get_elf_backend_data (abfd
)->check_relocs
;
2123 && abfd
->xvec
== info
->hash
->creator
2124 && check_relocs
!= NULL
)
2128 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2130 Elf_Internal_Rela
*internal_relocs
;
2133 if ((o
->flags
& SEC_RELOC
) == 0
2134 || o
->reloc_count
== 0
2135 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2136 && (o
->flags
& SEC_DEBUGGING
) != 0)
2137 || bfd_is_abs_section (o
->output_section
))
2140 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
2141 (abfd
, o
, (PTR
) NULL
,
2142 (Elf_Internal_Rela
*) NULL
,
2143 info
->keep_memory
));
2144 if (internal_relocs
== NULL
)
2147 ok
= (*check_relocs
) (abfd
, info
, o
, internal_relocs
);
2149 if (! info
->keep_memory
)
2150 free (internal_relocs
);
2157 /* If this is a non-traditional, non-relocateable link, try to
2158 optimize the handling of the .stab/.stabstr sections. */
2160 && ! info
->relocateable
2161 && ! info
->traditional_format
2162 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
2163 && is_elf_hash_table (info
)
2164 && (info
->strip
!= strip_all
&& info
->strip
!= strip_debugger
))
2166 asection
*stab
, *stabstr
;
2168 stab
= bfd_get_section_by_name (abfd
, ".stab");
2171 stabstr
= bfd_get_section_by_name (abfd
, ".stabstr");
2173 if (stabstr
!= NULL
)
2175 struct bfd_elf_section_data
*secdata
;
2177 secdata
= elf_section_data (stab
);
2178 if (! _bfd_link_section_stabs (abfd
,
2179 & hash_table
->stab_info
,
2181 &secdata
->stab_info
))
2187 if (! info
->relocateable
&& ! dynamic
2188 && is_elf_hash_table (info
))
2192 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2193 if ((s
->flags
& SEC_MERGE
)
2194 && ! _bfd_merge_section (abfd
, & hash_table
->merge_info
, s
,
2195 & elf_section_data (s
)->merge_info
))
2206 if (extversym
!= NULL
)
2211 /* Create some sections which will be filled in with dynamic linking
2212 information. ABFD is an input file which requires dynamic sections
2213 to be created. The dynamic sections take up virtual memory space
2214 when the final executable is run, so we need to create them before
2215 addresses are assigned to the output sections. We work out the
2216 actual contents and size of these sections later. */
2219 elf_link_create_dynamic_sections (abfd
, info
)
2221 struct bfd_link_info
*info
;
2224 register asection
*s
;
2225 struct elf_link_hash_entry
*h
;
2226 struct elf_backend_data
*bed
;
2228 if (! is_elf_hash_table (info
))
2231 if (elf_hash_table (info
)->dynamic_sections_created
)
2234 /* Make sure that all dynamic sections use the same input BFD. */
2235 if (elf_hash_table (info
)->dynobj
== NULL
)
2236 elf_hash_table (info
)->dynobj
= abfd
;
2238 abfd
= elf_hash_table (info
)->dynobj
;
2240 /* Note that we set the SEC_IN_MEMORY flag for all of these
2242 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2243 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2245 /* A dynamically linked executable has a .interp section, but a
2246 shared library does not. */
2249 s
= bfd_make_section (abfd
, ".interp");
2251 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
2255 /* Create sections to hold version informations. These are removed
2256 if they are not needed. */
2257 s
= bfd_make_section (abfd
, ".gnu.version_d");
2259 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2260 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2263 s
= bfd_make_section (abfd
, ".gnu.version");
2265 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2266 || ! bfd_set_section_alignment (abfd
, s
, 1))
2269 s
= bfd_make_section (abfd
, ".gnu.version_r");
2271 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2272 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2275 s
= bfd_make_section (abfd
, ".dynsym");
2277 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2278 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2281 s
= bfd_make_section (abfd
, ".dynstr");
2283 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
2286 /* Create a strtab to hold the dynamic symbol names. */
2287 if (elf_hash_table (info
)->dynstr
== NULL
)
2289 elf_hash_table (info
)->dynstr
= elf_stringtab_init ();
2290 if (elf_hash_table (info
)->dynstr
== NULL
)
2294 s
= bfd_make_section (abfd
, ".dynamic");
2296 || ! bfd_set_section_flags (abfd
, s
, flags
)
2297 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2300 /* The special symbol _DYNAMIC is always set to the start of the
2301 .dynamic section. This call occurs before we have processed the
2302 symbols for any dynamic object, so we don't have to worry about
2303 overriding a dynamic definition. We could set _DYNAMIC in a
2304 linker script, but we only want to define it if we are, in fact,
2305 creating a .dynamic section. We don't want to define it if there
2306 is no .dynamic section, since on some ELF platforms the start up
2307 code examines it to decide how to initialize the process. */
2309 if (! (_bfd_generic_link_add_one_symbol
2310 (info
, abfd
, "_DYNAMIC", BSF_GLOBAL
, s
, (bfd_vma
) 0,
2311 (const char *) NULL
, false, get_elf_backend_data (abfd
)->collect
,
2312 (struct bfd_link_hash_entry
**) &h
)))
2314 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2315 h
->type
= STT_OBJECT
;
2318 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2321 bed
= get_elf_backend_data (abfd
);
2323 s
= bfd_make_section (abfd
, ".hash");
2325 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2326 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2328 elf_section_data (s
)->this_hdr
.sh_entsize
= bed
->s
->sizeof_hash_entry
;
2330 /* Let the backend create the rest of the sections. This lets the
2331 backend set the right flags. The backend will normally create
2332 the .got and .plt sections. */
2333 if (! (*bed
->elf_backend_create_dynamic_sections
) (abfd
, info
))
2336 elf_hash_table (info
)->dynamic_sections_created
= true;
2341 /* Add an entry to the .dynamic table. */
2344 elf_add_dynamic_entry (info
, tag
, val
)
2345 struct bfd_link_info
*info
;
2349 Elf_Internal_Dyn dyn
;
2353 bfd_byte
*newcontents
;
2355 if (! is_elf_hash_table (info
))
2358 dynobj
= elf_hash_table (info
)->dynobj
;
2360 s
= bfd_get_section_by_name (dynobj
, ".dynamic");
2361 BFD_ASSERT (s
!= NULL
);
2363 newsize
= s
->_raw_size
+ sizeof (Elf_External_Dyn
);
2364 newcontents
= (bfd_byte
*) bfd_realloc (s
->contents
, newsize
);
2365 if (newcontents
== NULL
)
2369 dyn
.d_un
.d_val
= val
;
2370 elf_swap_dyn_out (dynobj
, &dyn
,
2371 (Elf_External_Dyn
*) (newcontents
+ s
->_raw_size
));
2373 s
->_raw_size
= newsize
;
2374 s
->contents
= newcontents
;
2379 /* Record a new local dynamic symbol. */
2382 elf_link_record_local_dynamic_symbol (info
, input_bfd
, input_indx
)
2383 struct bfd_link_info
*info
;
2387 struct elf_link_local_dynamic_entry
*entry
;
2388 struct elf_link_hash_table
*eht
;
2389 struct bfd_strtab_hash
*dynstr
;
2390 Elf_External_Sym esym
;
2391 unsigned long dynstr_index
;
2394 if (! is_elf_hash_table (info
))
2397 /* See if the entry exists already. */
2398 for (entry
= elf_hash_table (info
)->dynlocal
; entry
; entry
= entry
->next
)
2399 if (entry
->input_bfd
== input_bfd
&& entry
->input_indx
== input_indx
)
2402 entry
= (struct elf_link_local_dynamic_entry
*)
2403 bfd_alloc (input_bfd
, sizeof (*entry
));
2407 /* Go find the symbol, so that we can find it's name. */
2408 if (bfd_seek (input_bfd
,
2409 (elf_tdata (input_bfd
)->symtab_hdr
.sh_offset
2410 + input_indx
* sizeof (Elf_External_Sym
)),
2412 || (bfd_read (&esym
, sizeof (Elf_External_Sym
), 1, input_bfd
)
2413 != sizeof (Elf_External_Sym
)))
2415 elf_swap_symbol_in (input_bfd
, &esym
, &entry
->isym
);
2417 name
= (bfd_elf_string_from_elf_section
2418 (input_bfd
, elf_tdata (input_bfd
)->symtab_hdr
.sh_link
,
2419 entry
->isym
.st_name
));
2421 dynstr
= elf_hash_table (info
)->dynstr
;
2424 /* Create a strtab to hold the dynamic symbol names. */
2425 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_stringtab_init ();
2430 dynstr_index
= _bfd_stringtab_add (dynstr
, name
, true, false);
2431 if (dynstr_index
== (unsigned long) -1)
2433 entry
->isym
.st_name
= dynstr_index
;
2435 eht
= elf_hash_table (info
);
2437 entry
->next
= eht
->dynlocal
;
2438 eht
->dynlocal
= entry
;
2439 entry
->input_bfd
= input_bfd
;
2440 entry
->input_indx
= input_indx
;
2443 /* Whatever binding the symbol had before, it's now local. */
2445 = ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (entry
->isym
.st_info
));
2447 /* The dynindx will be set at the end of size_dynamic_sections. */
2452 /* Read and swap the relocs from the section indicated by SHDR. This
2453 may be either a REL or a RELA section. The relocations are
2454 translated into RELA relocations and stored in INTERNAL_RELOCS,
2455 which should have already been allocated to contain enough space.
2456 The EXTERNAL_RELOCS are a buffer where the external form of the
2457 relocations should be stored.
2459 Returns false if something goes wrong. */
2462 elf_link_read_relocs_from_section (abfd
, shdr
, external_relocs
,
2465 Elf_Internal_Shdr
*shdr
;
2466 PTR external_relocs
;
2467 Elf_Internal_Rela
*internal_relocs
;
2469 struct elf_backend_data
*bed
;
2471 /* If there aren't any relocations, that's OK. */
2475 /* Position ourselves at the start of the section. */
2476 if (bfd_seek (abfd
, shdr
->sh_offset
, SEEK_SET
) != 0)
2479 /* Read the relocations. */
2480 if (bfd_read (external_relocs
, 1, shdr
->sh_size
, abfd
)
2484 bed
= get_elf_backend_data (abfd
);
2486 /* Convert the external relocations to the internal format. */
2487 if (shdr
->sh_entsize
== sizeof (Elf_External_Rel
))
2489 Elf_External_Rel
*erel
;
2490 Elf_External_Rel
*erelend
;
2491 Elf_Internal_Rela
*irela
;
2492 Elf_Internal_Rel
*irel
;
2494 erel
= (Elf_External_Rel
*) external_relocs
;
2495 erelend
= erel
+ NUM_SHDR_ENTRIES (shdr
);
2496 irela
= internal_relocs
;
2497 irel
= bfd_alloc (abfd
, (bed
->s
->int_rels_per_ext_rel
2498 * sizeof (Elf_Internal_Rel
)));
2499 for (; erel
< erelend
; erel
++, irela
+= bed
->s
->int_rels_per_ext_rel
)
2503 if (bed
->s
->swap_reloc_in
)
2504 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, irel
);
2506 elf_swap_reloc_in (abfd
, erel
, irel
);
2508 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; ++i
)
2510 irela
[i
].r_offset
= irel
[i
].r_offset
;
2511 irela
[i
].r_info
= irel
[i
].r_info
;
2512 irela
[i
].r_addend
= 0;
2518 Elf_External_Rela
*erela
;
2519 Elf_External_Rela
*erelaend
;
2520 Elf_Internal_Rela
*irela
;
2522 BFD_ASSERT (shdr
->sh_entsize
== sizeof (Elf_External_Rela
));
2524 erela
= (Elf_External_Rela
*) external_relocs
;
2525 erelaend
= erela
+ NUM_SHDR_ENTRIES (shdr
);
2526 irela
= internal_relocs
;
2527 for (; erela
< erelaend
; erela
++, irela
+= bed
->s
->int_rels_per_ext_rel
)
2529 if (bed
->s
->swap_reloca_in
)
2530 (*bed
->s
->swap_reloca_in
) (abfd
, (bfd_byte
*) erela
, irela
);
2532 elf_swap_reloca_in (abfd
, erela
, irela
);
2539 /* Read and swap the relocs for a section O. They may have been
2540 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
2541 not NULL, they are used as buffers to read into. They are known to
2542 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
2543 the return value is allocated using either malloc or bfd_alloc,
2544 according to the KEEP_MEMORY argument. If O has two relocation
2545 sections (both REL and RELA relocations), then the REL_HDR
2546 relocations will appear first in INTERNAL_RELOCS, followed by the
2547 REL_HDR2 relocations. */
2550 NAME(_bfd_elf
,link_read_relocs
) (abfd
, o
, external_relocs
, internal_relocs
,
2554 PTR external_relocs
;
2555 Elf_Internal_Rela
*internal_relocs
;
2556 boolean keep_memory
;
2558 Elf_Internal_Shdr
*rel_hdr
;
2560 Elf_Internal_Rela
*alloc2
= NULL
;
2561 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2563 if (elf_section_data (o
)->relocs
!= NULL
)
2564 return elf_section_data (o
)->relocs
;
2566 if (o
->reloc_count
== 0)
2569 rel_hdr
= &elf_section_data (o
)->rel_hdr
;
2571 if (internal_relocs
== NULL
)
2575 size
= (o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
2576 * sizeof (Elf_Internal_Rela
));
2578 internal_relocs
= (Elf_Internal_Rela
*) bfd_alloc (abfd
, size
);
2580 internal_relocs
= alloc2
= (Elf_Internal_Rela
*) bfd_malloc (size
);
2581 if (internal_relocs
== NULL
)
2585 if (external_relocs
== NULL
)
2587 size_t size
= (size_t) rel_hdr
->sh_size
;
2589 if (elf_section_data (o
)->rel_hdr2
)
2590 size
+= (size_t) elf_section_data (o
)->rel_hdr2
->sh_size
;
2591 alloc1
= (PTR
) bfd_malloc (size
);
2594 external_relocs
= alloc1
;
2597 if (!elf_link_read_relocs_from_section (abfd
, rel_hdr
,
2601 if (!elf_link_read_relocs_from_section
2603 elf_section_data (o
)->rel_hdr2
,
2604 ((bfd_byte
*) external_relocs
) + rel_hdr
->sh_size
,
2605 internal_relocs
+ (NUM_SHDR_ENTRIES (rel_hdr
)
2606 * bed
->s
->int_rels_per_ext_rel
)))
2609 /* Cache the results for next time, if we can. */
2611 elf_section_data (o
)->relocs
= internal_relocs
;
2616 /* Don't free alloc2, since if it was allocated we are passing it
2617 back (under the name of internal_relocs). */
2619 return internal_relocs
;
2629 /* Record an assignment to a symbol made by a linker script. We need
2630 this in case some dynamic object refers to this symbol. */
2633 NAME(bfd_elf
,record_link_assignment
) (output_bfd
, info
, name
, provide
)
2634 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2635 struct bfd_link_info
*info
;
2639 struct elf_link_hash_entry
*h
;
2641 if (info
->hash
->creator
->flavour
!= bfd_target_elf_flavour
)
2644 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, true, true, false);
2648 if (h
->root
.type
== bfd_link_hash_new
)
2649 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
2651 /* If this symbol is being provided by the linker script, and it is
2652 currently defined by a dynamic object, but not by a regular
2653 object, then mark it as undefined so that the generic linker will
2654 force the correct value. */
2656 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2657 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2658 h
->root
.type
= bfd_link_hash_undefined
;
2660 /* If this symbol is not being provided by the linker script, and it is
2661 currently defined by a dynamic object, but not by a regular object,
2662 then clear out any version information because the symbol will not be
2663 associated with the dynamic object any more. */
2665 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2666 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2667 h
->verinfo
.verdef
= NULL
;
2669 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2671 /* When possible, keep the original type of the symbol. */
2672 if (h
->type
== STT_NOTYPE
)
2673 h
->type
= STT_OBJECT
;
2675 if (((h
->elf_link_hash_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
2676 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0
2678 && h
->dynindx
== -1)
2680 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2683 /* If this is a weak defined symbol, and we know a corresponding
2684 real symbol from the same dynamic object, make sure the real
2685 symbol is also made into a dynamic symbol. */
2686 if (h
->weakdef
!= NULL
2687 && h
->weakdef
->dynindx
== -1)
2689 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
2697 /* This structure is used to pass information to
2698 elf_link_assign_sym_version. */
2700 struct elf_assign_sym_version_info
2704 /* General link information. */
2705 struct bfd_link_info
*info
;
2707 struct bfd_elf_version_tree
*verdefs
;
2708 /* Whether we had a failure. */
2712 /* This structure is used to pass information to
2713 elf_link_find_version_dependencies. */
2715 struct elf_find_verdep_info
2719 /* General link information. */
2720 struct bfd_link_info
*info
;
2721 /* The number of dependencies. */
2723 /* Whether we had a failure. */
2727 /* Array used to determine the number of hash table buckets to use
2728 based on the number of symbols there are. If there are fewer than
2729 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
2730 fewer than 37 we use 17 buckets, and so forth. We never use more
2731 than 32771 buckets. */
2733 static const size_t elf_buckets
[] =
2735 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
2739 /* Compute bucket count for hashing table. We do not use a static set
2740 of possible tables sizes anymore. Instead we determine for all
2741 possible reasonable sizes of the table the outcome (i.e., the
2742 number of collisions etc) and choose the best solution. The
2743 weighting functions are not too simple to allow the table to grow
2744 without bounds. Instead one of the weighting factors is the size.
2745 Therefore the result is always a good payoff between few collisions
2746 (= short chain lengths) and table size. */
2748 compute_bucket_count (info
)
2749 struct bfd_link_info
*info
;
2751 size_t dynsymcount
= elf_hash_table (info
)->dynsymcount
;
2752 size_t best_size
= 0;
2753 unsigned long int *hashcodes
;
2754 unsigned long int *hashcodesp
;
2755 unsigned long int i
;
2757 /* Compute the hash values for all exported symbols. At the same
2758 time store the values in an array so that we could use them for
2760 hashcodes
= (unsigned long int *) bfd_malloc (dynsymcount
2761 * sizeof (unsigned long int));
2762 if (hashcodes
== NULL
)
2764 hashcodesp
= hashcodes
;
2766 /* Put all hash values in HASHCODES. */
2767 elf_link_hash_traverse (elf_hash_table (info
),
2768 elf_collect_hash_codes
, &hashcodesp
);
2770 /* We have a problem here. The following code to optimize the table
2771 size requires an integer type with more the 32 bits. If
2772 BFD_HOST_U_64_BIT is set we know about such a type. */
2773 #ifdef BFD_HOST_U_64_BIT
2774 if (info
->optimize
== true)
2776 unsigned long int nsyms
= hashcodesp
- hashcodes
;
2779 BFD_HOST_U_64_BIT best_chlen
= ~((BFD_HOST_U_64_BIT
) 0);
2780 unsigned long int *counts
;
2782 /* Possible optimization parameters: if we have NSYMS symbols we say
2783 that the hashing table must at least have NSYMS/4 and at most
2785 minsize
= nsyms
/ 4;
2788 best_size
= maxsize
= nsyms
* 2;
2790 /* Create array where we count the collisions in. We must use bfd_malloc
2791 since the size could be large. */
2792 counts
= (unsigned long int *) bfd_malloc (maxsize
2793 * sizeof (unsigned long int));
2800 /* Compute the "optimal" size for the hash table. The criteria is a
2801 minimal chain length. The minor criteria is (of course) the size
2803 for (i
= minsize
; i
< maxsize
; ++i
)
2805 /* Walk through the array of hashcodes and count the collisions. */
2806 BFD_HOST_U_64_BIT max
;
2807 unsigned long int j
;
2808 unsigned long int fact
;
2810 memset (counts
, '\0', i
* sizeof (unsigned long int));
2812 /* Determine how often each hash bucket is used. */
2813 for (j
= 0; j
< nsyms
; ++j
)
2814 ++counts
[hashcodes
[j
] % i
];
2816 /* For the weight function we need some information about the
2817 pagesize on the target. This is information need not be 100%
2818 accurate. Since this information is not available (so far) we
2819 define it here to a reasonable default value. If it is crucial
2820 to have a better value some day simply define this value. */
2821 # ifndef BFD_TARGET_PAGESIZE
2822 # define BFD_TARGET_PAGESIZE (4096)
2825 /* We in any case need 2 + NSYMS entries for the size values and
2827 max
= (2 + nsyms
) * (ARCH_SIZE
/ 8);
2830 /* Variant 1: optimize for short chains. We add the squares
2831 of all the chain lengths (which favous many small chain
2832 over a few long chains). */
2833 for (j
= 0; j
< i
; ++j
)
2834 max
+= counts
[j
] * counts
[j
];
2836 /* This adds penalties for the overall size of the table. */
2837 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (ARCH_SIZE
/ 8)) + 1;
2840 /* Variant 2: Optimize a lot more for small table. Here we
2841 also add squares of the size but we also add penalties for
2842 empty slots (the +1 term). */
2843 for (j
= 0; j
< i
; ++j
)
2844 max
+= (1 + counts
[j
]) * (1 + counts
[j
]);
2846 /* The overall size of the table is considered, but not as
2847 strong as in variant 1, where it is squared. */
2848 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (ARCH_SIZE
/ 8)) + 1;
2852 /* Compare with current best results. */
2853 if (max
< best_chlen
)
2863 #endif /* defined (BFD_HOST_U_64_BIT) */
2865 /* This is the fallback solution if no 64bit type is available or if we
2866 are not supposed to spend much time on optimizations. We select the
2867 bucket count using a fixed set of numbers. */
2868 for (i
= 0; elf_buckets
[i
] != 0; i
++)
2870 best_size
= elf_buckets
[i
];
2871 if (dynsymcount
< elf_buckets
[i
+ 1])
2876 /* Free the arrays we needed. */
2882 /* Set up the sizes and contents of the ELF dynamic sections. This is
2883 called by the ELF linker emulation before_allocation routine. We
2884 must set the sizes of the sections before the linker sets the
2885 addresses of the various sections. */
2888 NAME(bfd_elf
,size_dynamic_sections
) (output_bfd
, soname
, rpath
,
2890 auxiliary_filters
, info
, sinterpptr
,
2895 const char *filter_shlib
;
2896 const char * const *auxiliary_filters
;
2897 struct bfd_link_info
*info
;
2898 asection
**sinterpptr
;
2899 struct bfd_elf_version_tree
*verdefs
;
2901 bfd_size_type soname_indx
;
2903 struct elf_backend_data
*bed
;
2904 struct elf_assign_sym_version_info asvinfo
;
2908 soname_indx
= (bfd_size_type
) -1;
2910 if (info
->hash
->creator
->flavour
!= bfd_target_elf_flavour
)
2913 if (! is_elf_hash_table (info
))
2916 /* The backend may have to create some sections regardless of whether
2917 we're dynamic or not. */
2918 bed
= get_elf_backend_data (output_bfd
);
2919 if (bed
->elf_backend_always_size_sections
2920 && ! (*bed
->elf_backend_always_size_sections
) (output_bfd
, info
))
2923 dynobj
= elf_hash_table (info
)->dynobj
;
2925 /* If there were no dynamic objects in the link, there is nothing to
2930 if (elf_hash_table (info
)->dynamic_sections_created
)
2932 struct elf_info_failed eif
;
2933 struct elf_link_hash_entry
*h
;
2936 *sinterpptr
= bfd_get_section_by_name (dynobj
, ".interp");
2937 BFD_ASSERT (*sinterpptr
!= NULL
|| info
->shared
);
2941 soname_indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2942 soname
, true, true);
2943 if (soname_indx
== (bfd_size_type
) -1
2944 || ! elf_add_dynamic_entry (info
, DT_SONAME
, soname_indx
))
2950 if (! elf_add_dynamic_entry (info
, DT_SYMBOLIC
, 0))
2952 info
->flags
|= DF_SYMBOLIC
;
2959 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
, rpath
,
2961 if (indx
== (bfd_size_type
) -1
2962 || ! elf_add_dynamic_entry (info
, DT_RPATH
, indx
)
2964 && ! elf_add_dynamic_entry (info
, DT_RUNPATH
, indx
)))
2968 if (filter_shlib
!= NULL
)
2972 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2973 filter_shlib
, true, true);
2974 if (indx
== (bfd_size_type
) -1
2975 || ! elf_add_dynamic_entry (info
, DT_FILTER
, indx
))
2979 if (auxiliary_filters
!= NULL
)
2981 const char * const *p
;
2983 for (p
= auxiliary_filters
; *p
!= NULL
; p
++)
2987 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2989 if (indx
== (bfd_size_type
) -1
2990 || ! elf_add_dynamic_entry (info
, DT_AUXILIARY
, indx
))
2996 eif
.verdefs
= verdefs
;
2999 /* If we are supposed to export all symbols into the dynamic symbol
3000 table (this is not the normal case), then do so. */
3001 if (info
->export_dynamic
)
3003 elf_link_hash_traverse (elf_hash_table (info
), elf_export_symbol
,
3009 /* Attach all the symbols to their version information. */
3010 asvinfo
.output_bfd
= output_bfd
;
3011 asvinfo
.info
= info
;
3012 asvinfo
.verdefs
= verdefs
;
3013 asvinfo
.failed
= false;
3015 elf_link_hash_traverse (elf_hash_table (info
),
3016 elf_link_assign_sym_version
,
3021 /* Find all symbols which were defined in a dynamic object and make
3022 the backend pick a reasonable value for them. */
3023 elf_link_hash_traverse (elf_hash_table (info
),
3024 elf_adjust_dynamic_symbol
,
3029 /* Add some entries to the .dynamic section. We fill in some of the
3030 values later, in elf_bfd_final_link, but we must add the entries
3031 now so that we know the final size of the .dynamic section. */
3033 /* If there are initialization and/or finalization functions to
3034 call then add the corresponding DT_INIT/DT_FINI entries. */
3035 h
= (info
->init_function
3036 ? elf_link_hash_lookup (elf_hash_table (info
),
3037 info
->init_function
, false,
3041 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
3042 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
3044 if (! elf_add_dynamic_entry (info
, DT_INIT
, 0))
3047 h
= (info
->fini_function
3048 ? elf_link_hash_lookup (elf_hash_table (info
),
3049 info
->fini_function
, false,
3053 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
3054 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
3056 if (! elf_add_dynamic_entry (info
, DT_FINI
, 0))
3060 dynstr
= bfd_get_section_by_name (dynobj
, ".dynstr");
3061 /* If .dynstr is excluded from the link, we don't want any of
3062 these tags. Strictly, we should be checking each section
3063 individually; This quick check covers for the case where
3064 someone does a /DISCARD/ : { *(*) }. */
3065 if (dynstr
!= NULL
&& dynstr
->output_section
!= bfd_abs_section_ptr
)
3067 bfd_size_type strsize
;
3069 strsize
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
3070 if (! elf_add_dynamic_entry (info
, DT_HASH
, 0)
3071 || ! elf_add_dynamic_entry (info
, DT_STRTAB
, 0)
3072 || ! elf_add_dynamic_entry (info
, DT_SYMTAB
, 0)
3073 || ! elf_add_dynamic_entry (info
, DT_STRSZ
, strsize
)
3074 || ! elf_add_dynamic_entry (info
, DT_SYMENT
,
3075 sizeof (Elf_External_Sym
)))
3080 /* The backend must work out the sizes of all the other dynamic
3082 if (bed
->elf_backend_size_dynamic_sections
3083 && ! (*bed
->elf_backend_size_dynamic_sections
) (output_bfd
, info
))
3086 if (elf_hash_table (info
)->dynamic_sections_created
)
3090 size_t bucketcount
= 0;
3091 size_t hash_entry_size
;
3092 unsigned int dtagcount
;
3094 /* Set up the version definition section. */
3095 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
3096 BFD_ASSERT (s
!= NULL
);
3098 /* We may have created additional version definitions if we are
3099 just linking a regular application. */
3100 verdefs
= asvinfo
.verdefs
;
3102 if (verdefs
== NULL
)
3103 _bfd_strip_section_from_output (info
, s
);
3108 struct bfd_elf_version_tree
*t
;
3110 Elf_Internal_Verdef def
;
3111 Elf_Internal_Verdaux defaux
;
3116 /* Make space for the base version. */
3117 size
+= sizeof (Elf_External_Verdef
);
3118 size
+= sizeof (Elf_External_Verdaux
);
3121 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
3123 struct bfd_elf_version_deps
*n
;
3125 size
+= sizeof (Elf_External_Verdef
);
3126 size
+= sizeof (Elf_External_Verdaux
);
3129 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3130 size
+= sizeof (Elf_External_Verdaux
);
3133 s
->_raw_size
= size
;
3134 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3135 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3138 /* Fill in the version definition section. */
3142 def
.vd_version
= VER_DEF_CURRENT
;
3143 def
.vd_flags
= VER_FLG_BASE
;
3146 def
.vd_aux
= sizeof (Elf_External_Verdef
);
3147 def
.vd_next
= (sizeof (Elf_External_Verdef
)
3148 + sizeof (Elf_External_Verdaux
));
3150 if (soname_indx
!= (bfd_size_type
) -1)
3152 def
.vd_hash
= bfd_elf_hash (soname
);
3153 defaux
.vda_name
= soname_indx
;
3160 name
= basename (output_bfd
->filename
);
3161 def
.vd_hash
= bfd_elf_hash (name
);
3162 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3164 if (indx
== (bfd_size_type
) -1)
3166 defaux
.vda_name
= indx
;
3168 defaux
.vda_next
= 0;
3170 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
3171 (Elf_External_Verdef
*) p
);
3172 p
+= sizeof (Elf_External_Verdef
);
3173 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3174 (Elf_External_Verdaux
*) p
);
3175 p
+= sizeof (Elf_External_Verdaux
);
3177 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
3180 struct bfd_elf_version_deps
*n
;
3181 struct elf_link_hash_entry
*h
;
3184 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3187 /* Add a symbol representing this version. */
3189 if (! (_bfd_generic_link_add_one_symbol
3190 (info
, dynobj
, t
->name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
3191 (bfd_vma
) 0, (const char *) NULL
, false,
3192 get_elf_backend_data (dynobj
)->collect
,
3193 (struct bfd_link_hash_entry
**) &h
)))
3195 h
->elf_link_hash_flags
&= ~ ELF_LINK_NON_ELF
;
3196 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3197 h
->type
= STT_OBJECT
;
3198 h
->verinfo
.vertree
= t
;
3200 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3203 def
.vd_version
= VER_DEF_CURRENT
;
3205 if (t
->globals
== NULL
&& t
->locals
== NULL
&& ! t
->used
)
3206 def
.vd_flags
|= VER_FLG_WEAK
;
3207 def
.vd_ndx
= t
->vernum
+ 1;
3208 def
.vd_cnt
= cdeps
+ 1;
3209 def
.vd_hash
= bfd_elf_hash (t
->name
);
3210 def
.vd_aux
= sizeof (Elf_External_Verdef
);
3211 if (t
->next
!= NULL
)
3212 def
.vd_next
= (sizeof (Elf_External_Verdef
)
3213 + (cdeps
+ 1) * sizeof (Elf_External_Verdaux
));
3217 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
3218 (Elf_External_Verdef
*) p
);
3219 p
+= sizeof (Elf_External_Verdef
);
3221 defaux
.vda_name
= h
->dynstr_index
;
3222 if (t
->deps
== NULL
)
3223 defaux
.vda_next
= 0;
3225 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
3226 t
->name_indx
= defaux
.vda_name
;
3228 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3229 (Elf_External_Verdaux
*) p
);
3230 p
+= sizeof (Elf_External_Verdaux
);
3232 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3234 if (n
->version_needed
== NULL
)
3236 /* This can happen if there was an error in the
3238 defaux
.vda_name
= 0;
3241 defaux
.vda_name
= n
->version_needed
->name_indx
;
3242 if (n
->next
== NULL
)
3243 defaux
.vda_next
= 0;
3245 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
3247 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3248 (Elf_External_Verdaux
*) p
);
3249 p
+= sizeof (Elf_External_Verdaux
);
3253 if (! elf_add_dynamic_entry (info
, DT_VERDEF
, 0)
3254 || ! elf_add_dynamic_entry (info
, DT_VERDEFNUM
, cdefs
))
3257 elf_tdata (output_bfd
)->cverdefs
= cdefs
;
3260 if (info
->new_dtags
&& info
->flags
)
3262 if (! elf_add_dynamic_entry (info
, DT_FLAGS
, info
->flags
))
3269 info
->flags_1
&= ~ (DF_1_INITFIRST
3272 if (! elf_add_dynamic_entry (info
, DT_FLAGS_1
, info
->flags_1
))
3276 /* Work out the size of the version reference section. */
3278 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
3279 BFD_ASSERT (s
!= NULL
);
3281 struct elf_find_verdep_info sinfo
;
3283 sinfo
.output_bfd
= output_bfd
;
3285 sinfo
.vers
= elf_tdata (output_bfd
)->cverdefs
;
3286 if (sinfo
.vers
== 0)
3288 sinfo
.failed
= false;
3290 elf_link_hash_traverse (elf_hash_table (info
),
3291 elf_link_find_version_dependencies
,
3294 if (elf_tdata (output_bfd
)->verref
== NULL
)
3295 _bfd_strip_section_from_output (info
, s
);
3298 Elf_Internal_Verneed
*t
;
3303 /* Build the version definition section. */
3306 for (t
= elf_tdata (output_bfd
)->verref
;
3310 Elf_Internal_Vernaux
*a
;
3312 size
+= sizeof (Elf_External_Verneed
);
3314 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3315 size
+= sizeof (Elf_External_Vernaux
);
3318 s
->_raw_size
= size
;
3319 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, size
);
3320 if (s
->contents
== NULL
)
3324 for (t
= elf_tdata (output_bfd
)->verref
;
3329 Elf_Internal_Vernaux
*a
;
3333 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3336 t
->vn_version
= VER_NEED_CURRENT
;
3338 if (elf_dt_name (t
->vn_bfd
) != NULL
)
3339 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3340 elf_dt_name (t
->vn_bfd
),
3343 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3344 basename (t
->vn_bfd
->filename
),
3346 if (indx
== (bfd_size_type
) -1)
3349 t
->vn_aux
= sizeof (Elf_External_Verneed
);
3350 if (t
->vn_nextref
== NULL
)
3353 t
->vn_next
= (sizeof (Elf_External_Verneed
)
3354 + caux
* sizeof (Elf_External_Vernaux
));
3356 _bfd_elf_swap_verneed_out (output_bfd
, t
,
3357 (Elf_External_Verneed
*) p
);
3358 p
+= sizeof (Elf_External_Verneed
);
3360 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3362 a
->vna_hash
= bfd_elf_hash (a
->vna_nodename
);
3363 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3364 a
->vna_nodename
, true, false);
3365 if (indx
== (bfd_size_type
) -1)
3368 if (a
->vna_nextptr
== NULL
)
3371 a
->vna_next
= sizeof (Elf_External_Vernaux
);
3373 _bfd_elf_swap_vernaux_out (output_bfd
, a
,
3374 (Elf_External_Vernaux
*) p
);
3375 p
+= sizeof (Elf_External_Vernaux
);
3379 if (! elf_add_dynamic_entry (info
, DT_VERNEED
, 0)
3380 || ! elf_add_dynamic_entry (info
, DT_VERNEEDNUM
, crefs
))
3383 elf_tdata (output_bfd
)->cverrefs
= crefs
;
3387 /* Assign dynsym indicies. In a shared library we generate a
3388 section symbol for each output section, which come first.
3389 Next come all of the back-end allocated local dynamic syms,
3390 followed by the rest of the global symbols. */
3392 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
3394 /* Work out the size of the symbol version section. */
3395 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
3396 BFD_ASSERT (s
!= NULL
);
3397 if (dynsymcount
== 0
3398 || (verdefs
== NULL
&& elf_tdata (output_bfd
)->verref
== NULL
))
3400 _bfd_strip_section_from_output (info
, s
);
3401 /* The DYNSYMCOUNT might have changed if we were going to
3402 output a dynamic symbol table entry for S. */
3403 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
3407 s
->_raw_size
= dynsymcount
* sizeof (Elf_External_Versym
);
3408 s
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, s
->_raw_size
);
3409 if (s
->contents
== NULL
)
3412 if (! elf_add_dynamic_entry (info
, DT_VERSYM
, 0))
3416 /* Set the size of the .dynsym and .hash sections. We counted
3417 the number of dynamic symbols in elf_link_add_object_symbols.
3418 We will build the contents of .dynsym and .hash when we build
3419 the final symbol table, because until then we do not know the
3420 correct value to give the symbols. We built the .dynstr
3421 section as we went along in elf_link_add_object_symbols. */
3422 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
3423 BFD_ASSERT (s
!= NULL
);
3424 s
->_raw_size
= dynsymcount
* sizeof (Elf_External_Sym
);
3425 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3426 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3429 if (dynsymcount
!= 0)
3431 Elf_Internal_Sym isym
;
3433 /* The first entry in .dynsym is a dummy symbol. */
3440 elf_swap_symbol_out (output_bfd
, &isym
,
3441 (PTR
) (Elf_External_Sym
*) s
->contents
);
3444 /* Compute the size of the hashing table. As a side effect this
3445 computes the hash values for all the names we export. */
3446 bucketcount
= compute_bucket_count (info
);
3448 s
= bfd_get_section_by_name (dynobj
, ".hash");
3449 BFD_ASSERT (s
!= NULL
);
3450 hash_entry_size
= elf_section_data (s
)->this_hdr
.sh_entsize
;
3451 s
->_raw_size
= ((2 + bucketcount
+ dynsymcount
) * hash_entry_size
);
3452 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3453 if (s
->contents
== NULL
)
3455 memset (s
->contents
, 0, (size_t) s
->_raw_size
);
3457 bfd_put (8 * hash_entry_size
, output_bfd
, bucketcount
, s
->contents
);
3458 bfd_put (8 * hash_entry_size
, output_bfd
, dynsymcount
,
3459 s
->contents
+ hash_entry_size
);
3461 elf_hash_table (info
)->bucketcount
= bucketcount
;
3463 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
3464 BFD_ASSERT (s
!= NULL
);
3465 s
->_raw_size
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
3467 for (dtagcount
= 0; dtagcount
<= info
->spare_dynamic_tags
; ++dtagcount
)
3468 if (! elf_add_dynamic_entry (info
, DT_NULL
, 0))
3475 /* Fix up the flags for a symbol. This handles various cases which
3476 can only be fixed after all the input files are seen. This is
3477 currently called by both adjust_dynamic_symbol and
3478 assign_sym_version, which is unnecessary but perhaps more robust in
3479 the face of future changes. */
3482 elf_fix_symbol_flags (h
, eif
)
3483 struct elf_link_hash_entry
*h
;
3484 struct elf_info_failed
*eif
;
3486 /* If this symbol was mentioned in a non-ELF file, try to set
3487 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
3488 permit a non-ELF file to correctly refer to a symbol defined in
3489 an ELF dynamic object. */
3490 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_ELF
) != 0)
3492 while (h
->root
.type
== bfd_link_hash_indirect
)
3493 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3495 if (h
->root
.type
!= bfd_link_hash_defined
3496 && h
->root
.type
!= bfd_link_hash_defweak
)
3497 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
3498 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
3501 if (h
->root
.u
.def
.section
->owner
!= NULL
3502 && (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
3503 == bfd_target_elf_flavour
))
3504 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
3505 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
3507 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3510 if (h
->dynindx
== -1
3511 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3512 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3514 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
3523 /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol
3524 was first seen in a non-ELF file. Fortunately, if the symbol
3525 was first seen in an ELF file, we're probably OK unless the
3526 symbol was defined in a non-ELF file. Catch that case here.
3527 FIXME: We're still in trouble if the symbol was first seen in
3528 a dynamic object, and then later in a non-ELF regular object. */
3529 if ((h
->root
.type
== bfd_link_hash_defined
3530 || h
->root
.type
== bfd_link_hash_defweak
)
3531 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3532 && (h
->root
.u
.def
.section
->owner
!= NULL
3533 ? (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
3534 != bfd_target_elf_flavour
)
3535 : (bfd_is_abs_section (h
->root
.u
.def
.section
)
3536 && (h
->elf_link_hash_flags
3537 & ELF_LINK_HASH_DEF_DYNAMIC
) == 0)))
3538 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3541 /* If this is a final link, and the symbol was defined as a common
3542 symbol in a regular object file, and there was no definition in
3543 any dynamic object, then the linker will have allocated space for
3544 the symbol in a common section but the ELF_LINK_HASH_DEF_REGULAR
3545 flag will not have been set. */
3546 if (h
->root
.type
== bfd_link_hash_defined
3547 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3548 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) != 0
3549 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3550 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
3551 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3553 /* If -Bsymbolic was used (which means to bind references to global
3554 symbols to the definition within the shared object), and this
3555 symbol was defined in a regular object, then it actually doesn't
3556 need a PLT entry, and we can accomplish that by forcing it local.
3557 Likewise, if the symbol has hidden or internal visibility.
3558 FIXME: It might be that we also do not need a PLT for other
3559 non-hidden visibilities, but we would have to tell that to the
3560 backend specifically; we can't just clear PLT-related data here. */
3561 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
3562 && eif
->info
->shared
3563 && is_elf_hash_table (eif
->info
)
3564 && (eif
->info
->symbolic
3565 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
3566 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
3567 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
3569 struct elf_backend_data
*bed
;
3571 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
3572 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
3573 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
3574 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
3575 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
);
3578 /* If this is a weak defined symbol in a dynamic object, and we know
3579 the real definition in the dynamic object, copy interesting flags
3580 over to the real definition. */
3581 if (h
->weakdef
!= NULL
)
3583 struct elf_link_hash_entry
*weakdef
;
3585 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3586 || h
->root
.type
== bfd_link_hash_defweak
);
3587 weakdef
= h
->weakdef
;
3588 BFD_ASSERT (weakdef
->root
.type
== bfd_link_hash_defined
3589 || weakdef
->root
.type
== bfd_link_hash_defweak
);
3590 BFD_ASSERT (weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
);
3592 /* If the real definition is defined by a regular object file,
3593 don't do anything special. See the longer description in
3594 elf_adjust_dynamic_symbol, below. */
3595 if ((weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
3598 weakdef
->elf_link_hash_flags
|=
3599 (h
->elf_link_hash_flags
3600 & (ELF_LINK_HASH_REF_REGULAR
3601 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3602 | ELF_LINK_NON_GOT_REF
));
3608 /* Make the backend pick a good value for a dynamic symbol. This is
3609 called via elf_link_hash_traverse, and also calls itself
3613 elf_adjust_dynamic_symbol (h
, data
)
3614 struct elf_link_hash_entry
*h
;
3617 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
3619 struct elf_backend_data
*bed
;
3621 /* Ignore indirect symbols. These are added by the versioning code. */
3622 if (h
->root
.type
== bfd_link_hash_indirect
)
3625 if (! is_elf_hash_table (eif
->info
))
3628 /* Fix the symbol flags. */
3629 if (! elf_fix_symbol_flags (h
, eif
))
3632 /* If this symbol does not require a PLT entry, and it is not
3633 defined by a dynamic object, or is not referenced by a regular
3634 object, ignore it. We do have to handle a weak defined symbol,
3635 even if no regular object refers to it, if we decided to add it
3636 to the dynamic symbol table. FIXME: Do we normally need to worry
3637 about symbols which are defined by one dynamic object and
3638 referenced by another one? */
3639 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0
3640 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3641 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3642 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0
3643 && (h
->weakdef
== NULL
|| h
->weakdef
->dynindx
== -1))))
3645 h
->plt
.offset
= (bfd_vma
) -1;
3649 /* If we've already adjusted this symbol, don't do it again. This
3650 can happen via a recursive call. */
3651 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
3654 /* Don't look at this symbol again. Note that we must set this
3655 after checking the above conditions, because we may look at a
3656 symbol once, decide not to do anything, and then get called
3657 recursively later after REF_REGULAR is set below. */
3658 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DYNAMIC_ADJUSTED
;
3660 /* If this is a weak definition, and we know a real definition, and
3661 the real symbol is not itself defined by a regular object file,
3662 then get a good value for the real definition. We handle the
3663 real symbol first, for the convenience of the backend routine.
3665 Note that there is a confusing case here. If the real definition
3666 is defined by a regular object file, we don't get the real symbol
3667 from the dynamic object, but we do get the weak symbol. If the
3668 processor backend uses a COPY reloc, then if some routine in the
3669 dynamic object changes the real symbol, we will not see that
3670 change in the corresponding weak symbol. This is the way other
3671 ELF linkers work as well, and seems to be a result of the shared
3674 I will clarify this issue. Most SVR4 shared libraries define the
3675 variable _timezone and define timezone as a weak synonym. The
3676 tzset call changes _timezone. If you write
3677 extern int timezone;
3679 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
3680 you might expect that, since timezone is a synonym for _timezone,
3681 the same number will print both times. However, if the processor
3682 backend uses a COPY reloc, then actually timezone will be copied
3683 into your process image, and, since you define _timezone
3684 yourself, _timezone will not. Thus timezone and _timezone will
3685 wind up at different memory locations. The tzset call will set
3686 _timezone, leaving timezone unchanged. */
3688 if (h
->weakdef
!= NULL
)
3690 /* If we get to this point, we know there is an implicit
3691 reference by a regular object file via the weak symbol H.
3692 FIXME: Is this really true? What if the traversal finds
3693 H->WEAKDEF before it finds H? */
3694 h
->weakdef
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
3696 if (! elf_adjust_dynamic_symbol (h
->weakdef
, (PTR
) eif
))
3700 /* If a symbol has no type and no size and does not require a PLT
3701 entry, then we are probably about to do the wrong thing here: we
3702 are probably going to create a COPY reloc for an empty object.
3703 This case can arise when a shared object is built with assembly
3704 code, and the assembly code fails to set the symbol type. */
3706 && h
->type
== STT_NOTYPE
3707 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
3708 (*_bfd_error_handler
)
3709 (_("warning: type and size of dynamic symbol `%s' are not defined"),
3710 h
->root
.root
.string
);
3712 dynobj
= elf_hash_table (eif
->info
)->dynobj
;
3713 bed
= get_elf_backend_data (dynobj
);
3714 if (! (*bed
->elf_backend_adjust_dynamic_symbol
) (eif
->info
, h
))
3723 /* This routine is used to export all defined symbols into the dynamic
3724 symbol table. It is called via elf_link_hash_traverse. */
3727 elf_export_symbol (h
, data
)
3728 struct elf_link_hash_entry
*h
;
3731 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
3733 /* Ignore indirect symbols. These are added by the versioning code. */
3734 if (h
->root
.type
== bfd_link_hash_indirect
)
3737 if (h
->dynindx
== -1
3738 && (h
->elf_link_hash_flags
3739 & (ELF_LINK_HASH_DEF_REGULAR
| ELF_LINK_HASH_REF_REGULAR
)) != 0)
3741 struct bfd_elf_version_tree
*t
;
3742 struct bfd_elf_version_expr
*d
;
3744 for (t
= eif
->verdefs
; t
!= NULL
; t
= t
->next
)
3746 if (t
->globals
!= NULL
)
3748 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
3750 if ((*d
->match
) (d
, h
->root
.root
.string
))
3755 if (t
->locals
!= NULL
)
3757 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
3759 if ((*d
->match
) (d
, h
->root
.root
.string
))
3768 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
3779 /* Look through the symbols which are defined in other shared
3780 libraries and referenced here. Update the list of version
3781 dependencies. This will be put into the .gnu.version_r section.
3782 This function is called via elf_link_hash_traverse. */
3785 elf_link_find_version_dependencies (h
, data
)
3786 struct elf_link_hash_entry
*h
;
3789 struct elf_find_verdep_info
*rinfo
= (struct elf_find_verdep_info
*) data
;
3790 Elf_Internal_Verneed
*t
;
3791 Elf_Internal_Vernaux
*a
;
3793 /* We only care about symbols defined in shared objects with version
3795 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3796 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3798 || h
->verinfo
.verdef
== NULL
)
3801 /* See if we already know about this version. */
3802 for (t
= elf_tdata (rinfo
->output_bfd
)->verref
; t
!= NULL
; t
= t
->vn_nextref
)
3804 if (t
->vn_bfd
!= h
->verinfo
.verdef
->vd_bfd
)
3807 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3808 if (a
->vna_nodename
== h
->verinfo
.verdef
->vd_nodename
)
3814 /* This is a new version. Add it to tree we are building. */
3818 t
= (Elf_Internal_Verneed
*) bfd_zalloc (rinfo
->output_bfd
, sizeof *t
);
3821 rinfo
->failed
= true;
3825 t
->vn_bfd
= h
->verinfo
.verdef
->vd_bfd
;
3826 t
->vn_nextref
= elf_tdata (rinfo
->output_bfd
)->verref
;
3827 elf_tdata (rinfo
->output_bfd
)->verref
= t
;
3830 a
= (Elf_Internal_Vernaux
*) bfd_zalloc (rinfo
->output_bfd
, sizeof *a
);
3832 /* Note that we are copying a string pointer here, and testing it
3833 above. If bfd_elf_string_from_elf_section is ever changed to
3834 discard the string data when low in memory, this will have to be
3836 a
->vna_nodename
= h
->verinfo
.verdef
->vd_nodename
;
3838 a
->vna_flags
= h
->verinfo
.verdef
->vd_flags
;
3839 a
->vna_nextptr
= t
->vn_auxptr
;
3841 h
->verinfo
.verdef
->vd_exp_refno
= rinfo
->vers
;
3844 a
->vna_other
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
3851 /* Figure out appropriate versions for all the symbols. We may not
3852 have the version number script until we have read all of the input
3853 files, so until that point we don't know which symbols should be
3854 local. This function is called via elf_link_hash_traverse. */
3857 elf_link_assign_sym_version (h
, data
)
3858 struct elf_link_hash_entry
*h
;
3861 struct elf_assign_sym_version_info
*sinfo
=
3862 (struct elf_assign_sym_version_info
*) data
;
3863 struct bfd_link_info
*info
= sinfo
->info
;
3864 struct elf_backend_data
*bed
;
3865 struct elf_info_failed eif
;
3868 /* Fix the symbol flags. */
3871 if (! elf_fix_symbol_flags (h
, &eif
))
3874 sinfo
->failed
= true;
3878 /* We only need version numbers for symbols defined in regular
3880 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3883 bed
= get_elf_backend_data (sinfo
->output_bfd
);
3884 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
3885 if (p
!= NULL
&& h
->verinfo
.vertree
== NULL
)
3887 struct bfd_elf_version_tree
*t
;
3892 /* There are two consecutive ELF_VER_CHR characters if this is
3893 not a hidden symbol. */
3895 if (*p
== ELF_VER_CHR
)
3901 /* If there is no version string, we can just return out. */
3905 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
3909 /* Look for the version. If we find it, it is no longer weak. */
3910 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
3912 if (strcmp (t
->name
, p
) == 0)
3916 struct bfd_elf_version_expr
*d
;
3918 len
= p
- h
->root
.root
.string
;
3919 alc
= bfd_alloc (sinfo
->output_bfd
, len
);
3922 strncpy (alc
, h
->root
.root
.string
, len
- 1);
3923 alc
[len
- 1] = '\0';
3924 if (alc
[len
- 2] == ELF_VER_CHR
)
3925 alc
[len
- 2] = '\0';
3927 h
->verinfo
.vertree
= t
;
3931 if (t
->globals
!= NULL
)
3933 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
3934 if ((*d
->match
) (d
, alc
))
3938 /* See if there is anything to force this symbol to
3940 if (d
== NULL
&& t
->locals
!= NULL
)
3942 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
3944 if ((*d
->match
) (d
, alc
))
3946 if (h
->dynindx
!= -1
3948 && ! info
->export_dynamic
)
3950 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
3951 (*bed
->elf_backend_hide_symbol
) (info
, h
);
3952 /* FIXME: The name of the symbol has
3953 already been recorded in the dynamic
3954 string table section. */
3962 bfd_release (sinfo
->output_bfd
, alc
);
3967 /* If we are building an application, we need to create a
3968 version node for this version. */
3969 if (t
== NULL
&& ! info
->shared
)
3971 struct bfd_elf_version_tree
**pp
;
3974 /* If we aren't going to export this symbol, we don't need
3975 to worry about it. */
3976 if (h
->dynindx
== -1)
3979 t
= ((struct bfd_elf_version_tree
*)
3980 bfd_alloc (sinfo
->output_bfd
, sizeof *t
));
3983 sinfo
->failed
= true;
3992 t
->name_indx
= (unsigned int) -1;
3996 for (pp
= &sinfo
->verdefs
; *pp
!= NULL
; pp
= &(*pp
)->next
)
3998 t
->vernum
= version_index
;
4002 h
->verinfo
.vertree
= t
;
4006 /* We could not find the version for a symbol when
4007 generating a shared archive. Return an error. */
4008 (*_bfd_error_handler
)
4009 (_("%s: undefined versioned symbol name %s"),
4010 bfd_get_filename (sinfo
->output_bfd
), h
->root
.root
.string
);
4011 bfd_set_error (bfd_error_bad_value
);
4012 sinfo
->failed
= true;
4017 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
4020 /* If we don't have a version for this symbol, see if we can find
4022 if (h
->verinfo
.vertree
== NULL
&& sinfo
->verdefs
!= NULL
)
4024 struct bfd_elf_version_tree
*t
;
4025 struct bfd_elf_version_tree
*deflt
;
4026 struct bfd_elf_version_expr
*d
;
4028 /* See if can find what version this symbol is in. If the
4029 symbol is supposed to be local, then don't actually register
4032 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
4034 if (t
->globals
!= NULL
)
4036 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
4038 if ((*d
->match
) (d
, h
->root
.root
.string
))
4040 h
->verinfo
.vertree
= t
;
4049 if (t
->locals
!= NULL
)
4051 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
4053 if (d
->pattern
[0] == '*' && d
->pattern
[1] == '\0')
4055 else if ((*d
->match
) (d
, h
->root
.root
.string
))
4057 h
->verinfo
.vertree
= t
;
4058 if (h
->dynindx
!= -1
4060 && ! info
->export_dynamic
)
4062 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
4063 (*bed
->elf_backend_hide_symbol
) (info
, h
);
4064 /* FIXME: The name of the symbol has already
4065 been recorded in the dynamic string table
4077 if (deflt
!= NULL
&& h
->verinfo
.vertree
== NULL
)
4079 h
->verinfo
.vertree
= deflt
;
4080 if (h
->dynindx
!= -1
4082 && ! info
->export_dynamic
)
4084 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
4085 (*bed
->elf_backend_hide_symbol
) (info
, h
);
4086 /* FIXME: The name of the symbol has already been
4087 recorded in the dynamic string table section. */
4095 /* Final phase of ELF linker. */
4097 /* A structure we use to avoid passing large numbers of arguments. */
4099 struct elf_final_link_info
4101 /* General link information. */
4102 struct bfd_link_info
*info
;
4105 /* Symbol string table. */
4106 struct bfd_strtab_hash
*symstrtab
;
4107 /* .dynsym section. */
4108 asection
*dynsym_sec
;
4109 /* .hash section. */
4111 /* symbol version section (.gnu.version). */
4112 asection
*symver_sec
;
4113 /* Buffer large enough to hold contents of any section. */
4115 /* Buffer large enough to hold external relocs of any section. */
4116 PTR external_relocs
;
4117 /* Buffer large enough to hold internal relocs of any section. */
4118 Elf_Internal_Rela
*internal_relocs
;
4119 /* Buffer large enough to hold external local symbols of any input
4121 Elf_External_Sym
*external_syms
;
4122 /* Buffer large enough to hold internal local symbols of any input
4124 Elf_Internal_Sym
*internal_syms
;
4125 /* Array large enough to hold a symbol index for each local symbol
4126 of any input BFD. */
4128 /* Array large enough to hold a section pointer for each local
4129 symbol of any input BFD. */
4130 asection
**sections
;
4131 /* Buffer to hold swapped out symbols. */
4132 Elf_External_Sym
*symbuf
;
4133 /* Number of swapped out symbols in buffer. */
4134 size_t symbuf_count
;
4135 /* Number of symbols which fit in symbuf. */
4139 static boolean elf_link_output_sym
4140 PARAMS ((struct elf_final_link_info
*, const char *,
4141 Elf_Internal_Sym
*, asection
*));
4142 static boolean elf_link_flush_output_syms
4143 PARAMS ((struct elf_final_link_info
*));
4144 static boolean elf_link_output_extsym
4145 PARAMS ((struct elf_link_hash_entry
*, PTR
));
4146 static boolean elf_link_sec_merge_syms
4147 PARAMS ((struct elf_link_hash_entry
*, PTR
));
4148 static boolean elf_link_input_bfd
4149 PARAMS ((struct elf_final_link_info
*, bfd
*));
4150 static boolean elf_reloc_link_order
4151 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4152 struct bfd_link_order
*));
4154 /* This struct is used to pass information to elf_link_output_extsym. */
4156 struct elf_outext_info
4160 struct elf_final_link_info
*finfo
;
4163 /* Compute the size of, and allocate space for, REL_HDR which is the
4164 section header for a section containing relocations for O. */
4167 elf_link_size_reloc_section (abfd
, rel_hdr
, o
)
4169 Elf_Internal_Shdr
*rel_hdr
;
4172 unsigned reloc_count
;
4173 unsigned num_rel_hashes
;
4175 /* Figure out how many relocations there will be. */
4176 if (rel_hdr
== &elf_section_data (o
)->rel_hdr
)
4177 reloc_count
= elf_section_data (o
)->rel_count
;
4179 reloc_count
= elf_section_data (o
)->rel_count2
;
4181 num_rel_hashes
= o
->reloc_count
;
4182 if (num_rel_hashes
< reloc_count
)
4183 num_rel_hashes
= reloc_count
;
4185 /* That allows us to calculate the size of the section. */
4186 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
* reloc_count
;
4188 /* The contents field must last into write_object_contents, so we
4189 allocate it with bfd_alloc rather than malloc. Also since we
4190 cannot be sure that the contents will actually be filled in,
4191 we zero the allocated space. */
4192 rel_hdr
->contents
= (PTR
) bfd_zalloc (abfd
, rel_hdr
->sh_size
);
4193 if (rel_hdr
->contents
== NULL
&& rel_hdr
->sh_size
!= 0)
4196 /* We only allocate one set of hash entries, so we only do it the
4197 first time we are called. */
4198 if (elf_section_data (o
)->rel_hashes
== NULL
4201 struct elf_link_hash_entry
**p
;
4203 p
= ((struct elf_link_hash_entry
**)
4204 bfd_zmalloc (num_rel_hashes
4205 * sizeof (struct elf_link_hash_entry
*)));
4209 elf_section_data (o
)->rel_hashes
= p
;
4215 /* When performing a relocateable link, the input relocations are
4216 preserved. But, if they reference global symbols, the indices
4217 referenced must be updated. Update all the relocations in
4218 REL_HDR (there are COUNT of them), using the data in REL_HASH. */
4221 elf_link_adjust_relocs (abfd
, rel_hdr
, count
, rel_hash
)
4223 Elf_Internal_Shdr
*rel_hdr
;
4225 struct elf_link_hash_entry
**rel_hash
;
4228 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4229 Elf_Internal_Rel
*irel
;
4230 Elf_Internal_Rela
*irela
;
4232 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (sizeof (Elf_Internal_Rel
)
4233 * bed
->s
->int_rels_per_ext_rel
);
4236 (*_bfd_error_handler
) (_("Error: out of memory"));
4240 irela
= (Elf_Internal_Rela
*) bfd_zmalloc (sizeof (Elf_Internal_Rela
)
4241 * bed
->s
->int_rels_per_ext_rel
);
4244 (*_bfd_error_handler
) (_("Error: out of memory"));
4248 for (i
= 0; i
< count
; i
++, rel_hash
++)
4250 if (*rel_hash
== NULL
)
4253 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
4255 if (rel_hdr
->sh_entsize
== sizeof (Elf_External_Rel
))
4257 Elf_External_Rel
*erel
;
4260 erel
= (Elf_External_Rel
*) rel_hdr
->contents
+ i
;
4261 if (bed
->s
->swap_reloc_in
)
4262 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, irel
);
4264 elf_swap_reloc_in (abfd
, erel
, irel
);
4266 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
4267 irel
[j
].r_info
= ELF_R_INFO ((*rel_hash
)->indx
,
4268 ELF_R_TYPE (irel
[j
].r_info
));
4270 if (bed
->s
->swap_reloc_out
)
4271 (*bed
->s
->swap_reloc_out
) (abfd
, irel
, (bfd_byte
*) erel
);
4273 elf_swap_reloc_out (abfd
, irel
, erel
);
4277 Elf_External_Rela
*erela
;
4280 BFD_ASSERT (rel_hdr
->sh_entsize
4281 == sizeof (Elf_External_Rela
));
4283 erela
= (Elf_External_Rela
*) rel_hdr
->contents
+ i
;
4284 if (bed
->s
->swap_reloca_in
)
4285 (*bed
->s
->swap_reloca_in
) (abfd
, (bfd_byte
*) erela
, irela
);
4287 elf_swap_reloca_in (abfd
, erela
, irela
);
4289 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
4290 irela
[j
].r_info
= ELF_R_INFO ((*rel_hash
)->indx
,
4291 ELF_R_TYPE (irela
[j
].r_info
));
4293 if (bed
->s
->swap_reloca_out
)
4294 (*bed
->s
->swap_reloca_out
) (abfd
, irela
, (bfd_byte
*) erela
);
4296 elf_swap_reloca_out (abfd
, irela
, erela
);
4304 struct elf_link_sort_rela
{
4306 enum elf_reloc_type_class type
;
4308 Elf_Internal_Rel rel
;
4309 Elf_Internal_Rela rela
;
4314 elf_link_sort_cmp1 (A
, B
)
4318 struct elf_link_sort_rela
*a
= (struct elf_link_sort_rela
*)A
;
4319 struct elf_link_sort_rela
*b
= (struct elf_link_sort_rela
*)B
;
4320 int relativea
, relativeb
;
4322 relativea
= a
->type
== reloc_class_relative
;
4323 relativeb
= b
->type
== reloc_class_relative
;
4325 if (relativea
< relativeb
)
4327 if (relativea
> relativeb
)
4329 if (ELF_R_SYM (a
->u
.rel
.r_info
) < ELF_R_SYM (b
->u
.rel
.r_info
))
4331 if (ELF_R_SYM (a
->u
.rel
.r_info
) > ELF_R_SYM (b
->u
.rel
.r_info
))
4333 if (a
->u
.rel
.r_offset
< b
->u
.rel
.r_offset
)
4335 if (a
->u
.rel
.r_offset
> b
->u
.rel
.r_offset
)
4341 elf_link_sort_cmp2 (A
, B
)
4345 struct elf_link_sort_rela
*a
= (struct elf_link_sort_rela
*)A
;
4346 struct elf_link_sort_rela
*b
= (struct elf_link_sort_rela
*)B
;
4349 if (a
->offset
< b
->offset
)
4351 if (a
->offset
> b
->offset
)
4353 copya
= a
->type
== reloc_class_copy
;
4354 copyb
= b
->type
== reloc_class_copy
;
4359 if (a
->u
.rel
.r_offset
< b
->u
.rel
.r_offset
)
4361 if (a
->u
.rel
.r_offset
> b
->u
.rel
.r_offset
)
4367 elf_link_sort_relocs (abfd
, info
, psec
)
4369 struct bfd_link_info
*info
;
4372 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
4373 asection
*reldyn
, *o
;
4374 boolean rel
= false;
4375 size_t count
, size
, i
, j
, ret
;
4376 struct elf_link_sort_rela
*rela
;
4377 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4379 reldyn
= bfd_get_section_by_name (abfd
, ".rela.dyn");
4380 if (reldyn
== NULL
|| reldyn
->_raw_size
== 0)
4382 reldyn
= bfd_get_section_by_name (abfd
, ".rel.dyn");
4383 if (reldyn
== NULL
|| reldyn
->_raw_size
== 0)
4386 count
= reldyn
->_raw_size
/ sizeof (Elf_External_Rel
);
4389 count
= reldyn
->_raw_size
/ sizeof (Elf_External_Rela
);
4392 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4393 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4394 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4395 && o
->output_section
== reldyn
)
4396 size
+= o
->_raw_size
;
4398 if (size
!= reldyn
->_raw_size
)
4401 rela
= (struct elf_link_sort_rela
*) calloc (sizeof (*rela
), count
);
4404 (*info
->callbacks
->warning
)
4405 (info
, _("Not enough memory to sort relocations"), 0, abfd
, 0, 0);
4409 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4410 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4411 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4412 && o
->output_section
== reldyn
)
4416 Elf_External_Rel
*erel
, *erelend
;
4417 struct elf_link_sort_rela
*s
;
4419 erel
= (Elf_External_Rel
*) o
->contents
;
4420 erelend
= (Elf_External_Rel
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4421 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rel
);
4422 for (; erel
< erelend
; erel
++, s
++)
4424 if (bed
->s
->swap_reloc_in
)
4425 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, &s
->u
.rel
);
4427 elf_swap_reloc_in (abfd
, erel
, &s
->u
.rel
);
4429 s
->type
= (*bed
->elf_backend_reloc_type_class
)
4430 (ELF_R_TYPE (s
->u
.rel
.r_info
));
4435 Elf_External_Rela
*erela
, *erelaend
;
4436 struct elf_link_sort_rela
*s
;
4438 erela
= (Elf_External_Rela
*) o
->contents
;
4439 erelaend
= (Elf_External_Rela
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4440 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rela
);
4441 for (; erela
< erelaend
; erela
++, s
++)
4443 if (bed
->s
->swap_reloca_in
)
4444 (*bed
->s
->swap_reloca_in
) (dynobj
, (bfd_byte
*) erela
, &s
->u
.rela
);
4446 elf_swap_reloca_in (dynobj
, erela
, &s
->u
.rela
);
4448 s
->type
= (*bed
->elf_backend_reloc_type_class
)
4449 (ELF_R_TYPE (s
->u
.rel
.r_info
));
4454 qsort (rela
, count
, sizeof (*rela
), elf_link_sort_cmp1
);
4455 for (ret
= 0; ret
< count
&& rela
[ret
].type
== reloc_class_relative
; ret
++)
4457 for (i
= ret
, j
= ret
; i
< count
; i
++)
4459 if (ELF_R_SYM (rela
[i
].u
.rel
.r_info
) != ELF_R_SYM (rela
[j
].u
.rel
.r_info
))
4461 rela
[i
].offset
= rela
[j
].u
.rel
.r_offset
;
4463 qsort (rela
+ ret
, count
- ret
, sizeof (*rela
), elf_link_sort_cmp2
);
4465 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4466 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4467 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4468 && o
->output_section
== reldyn
)
4472 Elf_External_Rel
*erel
, *erelend
;
4473 struct elf_link_sort_rela
*s
;
4475 erel
= (Elf_External_Rel
*) o
->contents
;
4476 erelend
= (Elf_External_Rel
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4477 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rel
);
4478 for (; erel
< erelend
; erel
++, s
++)
4480 if (bed
->s
->swap_reloc_out
)
4481 (*bed
->s
->swap_reloc_out
) (abfd
, &s
->u
.rel
, (bfd_byte
*) erel
);
4483 elf_swap_reloc_out (abfd
, &s
->u
.rel
, erel
);
4488 Elf_External_Rela
*erela
, *erelaend
;
4489 struct elf_link_sort_rela
*s
;
4491 erela
= (Elf_External_Rela
*) o
->contents
;
4492 erelaend
= (Elf_External_Rela
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4493 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rela
);
4494 for (; erela
< erelaend
; erela
++, s
++)
4496 if (bed
->s
->swap_reloca_out
)
4497 (*bed
->s
->swap_reloca_out
) (dynobj
, &s
->u
.rela
, (bfd_byte
*) erela
);
4499 elf_swap_reloca_out (dynobj
, &s
->u
.rela
, erela
);
4509 /* Do the final step of an ELF link. */
4512 elf_bfd_final_link (abfd
, info
)
4514 struct bfd_link_info
*info
;
4517 boolean emit_relocs
;
4519 struct elf_final_link_info finfo
;
4520 register asection
*o
;
4521 register struct bfd_link_order
*p
;
4523 size_t max_contents_size
;
4524 size_t max_external_reloc_size
;
4525 size_t max_internal_reloc_count
;
4526 size_t max_sym_count
;
4528 Elf_Internal_Sym elfsym
;
4530 Elf_Internal_Shdr
*symtab_hdr
;
4531 Elf_Internal_Shdr
*symstrtab_hdr
;
4532 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4533 struct elf_outext_info eoinfo
;
4535 size_t relativecount
= 0;
4536 asection
*reldyn
= 0;
4538 if (! is_elf_hash_table (info
))
4542 abfd
->flags
|= DYNAMIC
;
4544 dynamic
= elf_hash_table (info
)->dynamic_sections_created
;
4545 dynobj
= elf_hash_table (info
)->dynobj
;
4547 emit_relocs
= (info
->relocateable
4548 || info
->emitrelocations
4549 || bed
->elf_backend_emit_relocs
);
4552 finfo
.output_bfd
= abfd
;
4553 finfo
.symstrtab
= elf_stringtab_init ();
4554 if (finfo
.symstrtab
== NULL
)
4559 finfo
.dynsym_sec
= NULL
;
4560 finfo
.hash_sec
= NULL
;
4561 finfo
.symver_sec
= NULL
;
4565 finfo
.dynsym_sec
= bfd_get_section_by_name (dynobj
, ".dynsym");
4566 finfo
.hash_sec
= bfd_get_section_by_name (dynobj
, ".hash");
4567 BFD_ASSERT (finfo
.dynsym_sec
!= NULL
&& finfo
.hash_sec
!= NULL
);
4568 finfo
.symver_sec
= bfd_get_section_by_name (dynobj
, ".gnu.version");
4569 /* Note that it is OK if symver_sec is NULL. */
4572 finfo
.contents
= NULL
;
4573 finfo
.external_relocs
= NULL
;
4574 finfo
.internal_relocs
= NULL
;
4575 finfo
.external_syms
= NULL
;
4576 finfo
.internal_syms
= NULL
;
4577 finfo
.indices
= NULL
;
4578 finfo
.sections
= NULL
;
4579 finfo
.symbuf
= NULL
;
4580 finfo
.symbuf_count
= 0;
4582 /* Count up the number of relocations we will output for each output
4583 section, so that we know the sizes of the reloc sections. We
4584 also figure out some maximum sizes. */
4585 max_contents_size
= 0;
4586 max_external_reloc_size
= 0;
4587 max_internal_reloc_count
= 0;
4590 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4594 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
4596 if (p
->type
== bfd_section_reloc_link_order
4597 || p
->type
== bfd_symbol_reloc_link_order
)
4599 else if (p
->type
== bfd_indirect_link_order
)
4603 sec
= p
->u
.indirect
.section
;
4605 /* Mark all sections which are to be included in the
4606 link. This will normally be every section. We need
4607 to do this so that we can identify any sections which
4608 the linker has decided to not include. */
4609 sec
->linker_mark
= true;
4611 if (sec
->flags
& SEC_MERGE
)
4614 if (info
->relocateable
|| info
->emitrelocations
)
4615 o
->reloc_count
+= sec
->reloc_count
;
4616 else if (bed
->elf_backend_count_relocs
)
4618 Elf_Internal_Rela
* relocs
;
4620 relocs
= (NAME(_bfd_elf
,link_read_relocs
)
4621 (abfd
, sec
, (PTR
) NULL
,
4622 (Elf_Internal_Rela
*) NULL
, info
->keep_memory
));
4624 o
->reloc_count
+= (*bed
->elf_backend_count_relocs
)
4627 if (!info
->keep_memory
)
4631 if (sec
->_raw_size
> max_contents_size
)
4632 max_contents_size
= sec
->_raw_size
;
4633 if (sec
->_cooked_size
> max_contents_size
)
4634 max_contents_size
= sec
->_cooked_size
;
4636 /* We are interested in just local symbols, not all
4638 if (bfd_get_flavour (sec
->owner
) == bfd_target_elf_flavour
4639 && (sec
->owner
->flags
& DYNAMIC
) == 0)
4643 if (elf_bad_symtab (sec
->owner
))
4644 sym_count
= (elf_tdata (sec
->owner
)->symtab_hdr
.sh_size
4645 / sizeof (Elf_External_Sym
));
4647 sym_count
= elf_tdata (sec
->owner
)->symtab_hdr
.sh_info
;
4649 if (sym_count
> max_sym_count
)
4650 max_sym_count
= sym_count
;
4652 if ((sec
->flags
& SEC_RELOC
) != 0)
4656 ext_size
= elf_section_data (sec
)->rel_hdr
.sh_size
;
4657 if (ext_size
> max_external_reloc_size
)
4658 max_external_reloc_size
= ext_size
;
4659 if (sec
->reloc_count
> max_internal_reloc_count
)
4660 max_internal_reloc_count
= sec
->reloc_count
;
4666 if (o
->reloc_count
> 0)
4667 o
->flags
|= SEC_RELOC
;
4670 /* Explicitly clear the SEC_RELOC flag. The linker tends to
4671 set it (this is probably a bug) and if it is set
4672 assign_section_numbers will create a reloc section. */
4673 o
->flags
&=~ SEC_RELOC
;
4676 /* If the SEC_ALLOC flag is not set, force the section VMA to
4677 zero. This is done in elf_fake_sections as well, but forcing
4678 the VMA to 0 here will ensure that relocs against these
4679 sections are handled correctly. */
4680 if ((o
->flags
& SEC_ALLOC
) == 0
4681 && ! o
->user_set_vma
)
4685 if (! info
->relocateable
&& merged
)
4686 elf_link_hash_traverse (elf_hash_table (info
),
4687 elf_link_sec_merge_syms
, (PTR
) abfd
);
4689 /* Figure out the file positions for everything but the symbol table
4690 and the relocs. We set symcount to force assign_section_numbers
4691 to create a symbol table. */
4692 bfd_get_symcount (abfd
) = info
->strip
== strip_all
? 0 : 1;
4693 BFD_ASSERT (! abfd
->output_has_begun
);
4694 if (! _bfd_elf_compute_section_file_positions (abfd
, info
))
4697 /* Figure out how many relocations we will have in each section.
4698 Just using RELOC_COUNT isn't good enough since that doesn't
4699 maintain a separate value for REL vs. RELA relocations. */
4701 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
4702 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
4704 asection
*output_section
;
4706 if (! o
->linker_mark
)
4708 /* This section was omitted from the link. */
4712 output_section
= o
->output_section
;
4714 if (output_section
!= NULL
4715 && (o
->flags
& SEC_RELOC
) != 0)
4717 struct bfd_elf_section_data
*esdi
4718 = elf_section_data (o
);
4719 struct bfd_elf_section_data
*esdo
4720 = elf_section_data (output_section
);
4721 unsigned int *rel_count
;
4722 unsigned int *rel_count2
;
4724 /* We must be careful to add the relocation froms the
4725 input section to the right output count. */
4726 if (esdi
->rel_hdr
.sh_entsize
== esdo
->rel_hdr
.sh_entsize
)
4728 rel_count
= &esdo
->rel_count
;
4729 rel_count2
= &esdo
->rel_count2
;
4733 rel_count
= &esdo
->rel_count2
;
4734 rel_count2
= &esdo
->rel_count
;
4737 *rel_count
+= NUM_SHDR_ENTRIES (& esdi
->rel_hdr
);
4739 *rel_count2
+= NUM_SHDR_ENTRIES (esdi
->rel_hdr2
);
4740 output_section
->flags
|= SEC_RELOC
;
4744 /* That created the reloc sections. Set their sizes, and assign
4745 them file positions, and allocate some buffers. */
4746 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4748 if ((o
->flags
& SEC_RELOC
) != 0)
4750 if (!elf_link_size_reloc_section (abfd
,
4751 &elf_section_data (o
)->rel_hdr
,
4755 if (elf_section_data (o
)->rel_hdr2
4756 && !elf_link_size_reloc_section (abfd
,
4757 elf_section_data (o
)->rel_hdr2
,
4762 /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
4763 to count upwards while actually outputting the relocations. */
4764 elf_section_data (o
)->rel_count
= 0;
4765 elf_section_data (o
)->rel_count2
= 0;
4768 _bfd_elf_assign_file_positions_for_relocs (abfd
);
4770 /* We have now assigned file positions for all the sections except
4771 .symtab and .strtab. We start the .symtab section at the current
4772 file position, and write directly to it. We build the .strtab
4773 section in memory. */
4774 bfd_get_symcount (abfd
) = 0;
4775 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4776 /* sh_name is set in prep_headers. */
4777 symtab_hdr
->sh_type
= SHT_SYMTAB
;
4778 symtab_hdr
->sh_flags
= 0;
4779 symtab_hdr
->sh_addr
= 0;
4780 symtab_hdr
->sh_size
= 0;
4781 symtab_hdr
->sh_entsize
= sizeof (Elf_External_Sym
);
4782 /* sh_link is set in assign_section_numbers. */
4783 /* sh_info is set below. */
4784 /* sh_offset is set just below. */
4785 symtab_hdr
->sh_addralign
= bed
->s
->file_align
;
4787 off
= elf_tdata (abfd
)->next_file_pos
;
4788 off
= _bfd_elf_assign_file_position_for_section (symtab_hdr
, off
, true);
4790 /* Note that at this point elf_tdata (abfd)->next_file_pos is
4791 incorrect. We do not yet know the size of the .symtab section.
4792 We correct next_file_pos below, after we do know the size. */
4794 /* Allocate a buffer to hold swapped out symbols. This is to avoid
4795 continuously seeking to the right position in the file. */
4796 if (! info
->keep_memory
|| max_sym_count
< 20)
4797 finfo
.symbuf_size
= 20;
4799 finfo
.symbuf_size
= max_sym_count
;
4800 finfo
.symbuf
= ((Elf_External_Sym
*)
4801 bfd_malloc (finfo
.symbuf_size
* sizeof (Elf_External_Sym
)));
4802 if (finfo
.symbuf
== NULL
)
4805 /* Start writing out the symbol table. The first symbol is always a
4807 if (info
->strip
!= strip_all
4810 elfsym
.st_value
= 0;
4813 elfsym
.st_other
= 0;
4814 elfsym
.st_shndx
= SHN_UNDEF
;
4815 if (! elf_link_output_sym (&finfo
, (const char *) NULL
,
4816 &elfsym
, bfd_und_section_ptr
))
4821 /* Some standard ELF linkers do this, but we don't because it causes
4822 bootstrap comparison failures. */
4823 /* Output a file symbol for the output file as the second symbol.
4824 We output this even if we are discarding local symbols, although
4825 I'm not sure if this is correct. */
4826 elfsym
.st_value
= 0;
4828 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FILE
);
4829 elfsym
.st_other
= 0;
4830 elfsym
.st_shndx
= SHN_ABS
;
4831 if (! elf_link_output_sym (&finfo
, bfd_get_filename (abfd
),
4832 &elfsym
, bfd_abs_section_ptr
))
4836 /* Output a symbol for each section. We output these even if we are
4837 discarding local symbols, since they are used for relocs. These
4838 symbols have no names. We store the index of each one in the
4839 index field of the section, so that we can find it again when
4840 outputting relocs. */
4841 if (info
->strip
!= strip_all
4845 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
4846 elfsym
.st_other
= 0;
4847 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
4849 o
= section_from_elf_index (abfd
, i
);
4851 o
->target_index
= bfd_get_symcount (abfd
);
4852 elfsym
.st_shndx
= i
;
4853 if (info
->relocateable
|| o
== NULL
)
4854 elfsym
.st_value
= 0;
4856 elfsym
.st_value
= o
->vma
;
4857 if (! elf_link_output_sym (&finfo
, (const char *) NULL
,
4863 /* Allocate some memory to hold information read in from the input
4865 finfo
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
4866 finfo
.external_relocs
= (PTR
) bfd_malloc (max_external_reloc_size
);
4867 finfo
.internal_relocs
= ((Elf_Internal_Rela
*)
4868 bfd_malloc (max_internal_reloc_count
4869 * sizeof (Elf_Internal_Rela
)
4870 * bed
->s
->int_rels_per_ext_rel
));
4871 finfo
.external_syms
= ((Elf_External_Sym
*)
4872 bfd_malloc (max_sym_count
4873 * sizeof (Elf_External_Sym
)));
4874 finfo
.internal_syms
= ((Elf_Internal_Sym
*)
4875 bfd_malloc (max_sym_count
4876 * sizeof (Elf_Internal_Sym
)));
4877 finfo
.indices
= (long *) bfd_malloc (max_sym_count
* sizeof (long));
4878 finfo
.sections
= ((asection
**)
4879 bfd_malloc (max_sym_count
* sizeof (asection
*)));
4880 if ((finfo
.contents
== NULL
&& max_contents_size
!= 0)
4881 || (finfo
.external_relocs
== NULL
&& max_external_reloc_size
!= 0)
4882 || (finfo
.internal_relocs
== NULL
&& max_internal_reloc_count
!= 0)
4883 || (finfo
.external_syms
== NULL
&& max_sym_count
!= 0)
4884 || (finfo
.internal_syms
== NULL
&& max_sym_count
!= 0)
4885 || (finfo
.indices
== NULL
&& max_sym_count
!= 0)
4886 || (finfo
.sections
== NULL
&& max_sym_count
!= 0))
4889 /* Since ELF permits relocations to be against local symbols, we
4890 must have the local symbols available when we do the relocations.
4891 Since we would rather only read the local symbols once, and we
4892 would rather not keep them in memory, we handle all the
4893 relocations for a single input file at the same time.
4895 Unfortunately, there is no way to know the total number of local
4896 symbols until we have seen all of them, and the local symbol
4897 indices precede the global symbol indices. This means that when
4898 we are generating relocateable output, and we see a reloc against
4899 a global symbol, we can not know the symbol index until we have
4900 finished examining all the local symbols to see which ones we are
4901 going to output. To deal with this, we keep the relocations in
4902 memory, and don't output them until the end of the link. This is
4903 an unfortunate waste of memory, but I don't see a good way around
4904 it. Fortunately, it only happens when performing a relocateable
4905 link, which is not the common case. FIXME: If keep_memory is set
4906 we could write the relocs out and then read them again; I don't
4907 know how bad the memory loss will be. */
4909 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
4910 sub
->output_has_begun
= false;
4911 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4913 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
4915 if (p
->type
== bfd_indirect_link_order
4916 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4917 == bfd_target_elf_flavour
))
4919 sub
= p
->u
.indirect
.section
->owner
;
4920 if (! sub
->output_has_begun
)
4922 if (! elf_link_input_bfd (&finfo
, sub
))
4924 sub
->output_has_begun
= true;
4927 else if (p
->type
== bfd_section_reloc_link_order
4928 || p
->type
== bfd_symbol_reloc_link_order
)
4930 if (! elf_reloc_link_order (abfd
, info
, o
, p
))
4935 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4941 /* That wrote out all the local symbols. Finish up the symbol table
4942 with the global symbols. Even if we want to strip everything we
4943 can, we still need to deal with those global symbols that got
4944 converted to local in a version script. */
4948 /* Output any global symbols that got converted to local in a
4949 version script. We do this in a separate step since ELF
4950 requires all local symbols to appear prior to any global
4951 symbols. FIXME: We should only do this if some global
4952 symbols were, in fact, converted to become local. FIXME:
4953 Will this work correctly with the Irix 5 linker? */
4954 eoinfo
.failed
= false;
4955 eoinfo
.finfo
= &finfo
;
4956 eoinfo
.localsyms
= true;
4957 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
4963 /* The sh_info field records the index of the first non local symbol. */
4964 symtab_hdr
->sh_info
= bfd_get_symcount (abfd
);
4967 && finfo
.dynsym_sec
->output_section
!= bfd_abs_section_ptr
)
4969 Elf_Internal_Sym sym
;
4970 Elf_External_Sym
*dynsym
=
4971 (Elf_External_Sym
*) finfo
.dynsym_sec
->contents
;
4972 long last_local
= 0;
4974 /* Write out the section symbols for the output sections. */
4981 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
4984 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4987 indx
= elf_section_data (s
)->this_idx
;
4988 BFD_ASSERT (indx
> 0);
4989 sym
.st_shndx
= indx
;
4990 sym
.st_value
= s
->vma
;
4992 elf_swap_symbol_out (abfd
, &sym
,
4993 dynsym
+ elf_section_data (s
)->dynindx
);
4996 last_local
= bfd_count_sections (abfd
);
4999 /* Write out the local dynsyms. */
5000 if (elf_hash_table (info
)->dynlocal
)
5002 struct elf_link_local_dynamic_entry
*e
;
5003 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
5007 sym
.st_size
= e
->isym
.st_size
;
5008 sym
.st_other
= e
->isym
.st_other
;
5010 /* Copy the internal symbol as is.
5011 Note that we saved a word of storage and overwrote
5012 the original st_name with the dynstr_index. */
5015 if (e
->isym
.st_shndx
> 0 && e
->isym
.st_shndx
< SHN_LORESERVE
)
5017 s
= bfd_section_from_elf_index (e
->input_bfd
,
5021 elf_section_data (s
->output_section
)->this_idx
;
5022 sym
.st_value
= (s
->output_section
->vma
5024 + e
->isym
.st_value
);
5027 if (last_local
< e
->dynindx
)
5028 last_local
= e
->dynindx
;
5030 elf_swap_symbol_out (abfd
, &sym
, dynsym
+ e
->dynindx
);
5034 elf_section_data (finfo
.dynsym_sec
->output_section
)->this_hdr
.sh_info
=
5038 /* We get the global symbols from the hash table. */
5039 eoinfo
.failed
= false;
5040 eoinfo
.localsyms
= false;
5041 eoinfo
.finfo
= &finfo
;
5042 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
5047 /* If backend needs to output some symbols not present in the hash
5048 table, do it now. */
5049 if (bed
->elf_backend_output_arch_syms
)
5051 if (! (*bed
->elf_backend_output_arch_syms
)
5052 (abfd
, info
, (PTR
) &finfo
,
5053 (boolean (*) PARAMS ((PTR
, const char *,
5054 Elf_Internal_Sym
*, asection
*)))
5055 elf_link_output_sym
))
5059 /* Flush all symbols to the file. */
5060 if (! elf_link_flush_output_syms (&finfo
))
5063 /* Now we know the size of the symtab section. */
5064 off
+= symtab_hdr
->sh_size
;
5066 /* Finish up and write out the symbol string table (.strtab)
5068 symstrtab_hdr
= &elf_tdata (abfd
)->strtab_hdr
;
5069 /* sh_name was set in prep_headers. */
5070 symstrtab_hdr
->sh_type
= SHT_STRTAB
;
5071 symstrtab_hdr
->sh_flags
= 0;
5072 symstrtab_hdr
->sh_addr
= 0;
5073 symstrtab_hdr
->sh_size
= _bfd_stringtab_size (finfo
.symstrtab
);
5074 symstrtab_hdr
->sh_entsize
= 0;
5075 symstrtab_hdr
->sh_link
= 0;
5076 symstrtab_hdr
->sh_info
= 0;
5077 /* sh_offset is set just below. */
5078 symstrtab_hdr
->sh_addralign
= 1;
5080 off
= _bfd_elf_assign_file_position_for_section (symstrtab_hdr
, off
, true);
5081 elf_tdata (abfd
)->next_file_pos
= off
;
5083 if (bfd_get_symcount (abfd
) > 0)
5085 if (bfd_seek (abfd
, symstrtab_hdr
->sh_offset
, SEEK_SET
) != 0
5086 || ! _bfd_stringtab_emit (abfd
, finfo
.symstrtab
))
5090 /* Adjust the relocs to have the correct symbol indices. */
5091 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5093 if ((o
->flags
& SEC_RELOC
) == 0)
5096 elf_link_adjust_relocs (abfd
, &elf_section_data (o
)->rel_hdr
,
5097 elf_section_data (o
)->rel_count
,
5098 elf_section_data (o
)->rel_hashes
);
5099 if (elf_section_data (o
)->rel_hdr2
!= NULL
)
5100 elf_link_adjust_relocs (abfd
, elf_section_data (o
)->rel_hdr2
,
5101 elf_section_data (o
)->rel_count2
,
5102 (elf_section_data (o
)->rel_hashes
5103 + elf_section_data (o
)->rel_count
));
5105 /* Set the reloc_count field to 0 to prevent write_relocs from
5106 trying to swap the relocs out itself. */
5110 if (dynamic
&& info
->combreloc
&& dynobj
!= NULL
)
5111 relativecount
= elf_link_sort_relocs (abfd
, info
, &reldyn
);
5113 /* If we are linking against a dynamic object, or generating a
5114 shared library, finish up the dynamic linking information. */
5117 Elf_External_Dyn
*dyncon
, *dynconend
;
5119 /* Fix up .dynamic entries. */
5120 o
= bfd_get_section_by_name (dynobj
, ".dynamic");
5121 BFD_ASSERT (o
!= NULL
);
5123 dyncon
= (Elf_External_Dyn
*) o
->contents
;
5124 dynconend
= (Elf_External_Dyn
*) (o
->contents
+ o
->_raw_size
);
5125 for (; dyncon
< dynconend
; dyncon
++)
5127 Elf_Internal_Dyn dyn
;
5131 elf_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5138 if (relativecount
> 0 && dyncon
+ 1 < dynconend
)
5140 switch (elf_section_data (reldyn
)->this_hdr
.sh_type
)
5142 case SHT_REL
: dyn
.d_tag
= DT_RELCOUNT
; break;
5143 case SHT_RELA
: dyn
.d_tag
= DT_RELACOUNT
; break;
5146 if (dyn
.d_tag
!= DT_NULL
)
5148 dyn
.d_un
.d_val
= relativecount
;
5149 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5155 name
= info
->init_function
;
5158 name
= info
->fini_function
;
5161 struct elf_link_hash_entry
*h
;
5163 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
5164 false, false, true);
5166 && (h
->root
.type
== bfd_link_hash_defined
5167 || h
->root
.type
== bfd_link_hash_defweak
))
5169 dyn
.d_un
.d_val
= h
->root
.u
.def
.value
;
5170 o
= h
->root
.u
.def
.section
;
5171 if (o
->output_section
!= NULL
)
5172 dyn
.d_un
.d_val
+= (o
->output_section
->vma
5173 + o
->output_offset
);
5176 /* The symbol is imported from another shared
5177 library and does not apply to this one. */
5181 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5196 name
= ".gnu.version_d";
5199 name
= ".gnu.version_r";
5202 name
= ".gnu.version";
5204 o
= bfd_get_section_by_name (abfd
, name
);
5205 BFD_ASSERT (o
!= NULL
);
5206 dyn
.d_un
.d_ptr
= o
->vma
;
5207 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5214 if (dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
5219 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
5221 Elf_Internal_Shdr
*hdr
;
5223 hdr
= elf_elfsections (abfd
)[i
];
5224 if (hdr
->sh_type
== type
5225 && (hdr
->sh_flags
& SHF_ALLOC
) != 0)
5227 if (dyn
.d_tag
== DT_RELSZ
|| dyn
.d_tag
== DT_RELASZ
)
5228 dyn
.d_un
.d_val
+= hdr
->sh_size
;
5231 if (dyn
.d_un
.d_val
== 0
5232 || hdr
->sh_addr
< dyn
.d_un
.d_val
)
5233 dyn
.d_un
.d_val
= hdr
->sh_addr
;
5237 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5243 /* If we have created any dynamic sections, then output them. */
5246 if (! (*bed
->elf_backend_finish_dynamic_sections
) (abfd
, info
))
5249 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
5251 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
5252 || o
->_raw_size
== 0
5253 || o
->output_section
== bfd_abs_section_ptr
)
5255 if ((o
->flags
& SEC_LINKER_CREATED
) == 0)
5257 /* At this point, we are only interested in sections
5258 created by elf_link_create_dynamic_sections. */
5261 if ((elf_section_data (o
->output_section
)->this_hdr
.sh_type
5263 || strcmp (bfd_get_section_name (abfd
, o
), ".dynstr") != 0)
5265 if (! bfd_set_section_contents (abfd
, o
->output_section
,
5266 o
->contents
, o
->output_offset
,
5274 /* The contents of the .dynstr section are actually in a
5276 off
= elf_section_data (o
->output_section
)->this_hdr
.sh_offset
;
5277 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0
5278 || ! _bfd_stringtab_emit (abfd
,
5279 elf_hash_table (info
)->dynstr
))
5285 /* If we have optimized stabs strings, output them. */
5286 if (elf_hash_table (info
)->stab_info
!= NULL
)
5288 if (! _bfd_write_stab_strings (abfd
, &elf_hash_table (info
)->stab_info
))
5292 if (finfo
.symstrtab
!= NULL
)
5293 _bfd_stringtab_free (finfo
.symstrtab
);
5294 if (finfo
.contents
!= NULL
)
5295 free (finfo
.contents
);
5296 if (finfo
.external_relocs
!= NULL
)
5297 free (finfo
.external_relocs
);
5298 if (finfo
.internal_relocs
!= NULL
)
5299 free (finfo
.internal_relocs
);
5300 if (finfo
.external_syms
!= NULL
)
5301 free (finfo
.external_syms
);
5302 if (finfo
.internal_syms
!= NULL
)
5303 free (finfo
.internal_syms
);
5304 if (finfo
.indices
!= NULL
)
5305 free (finfo
.indices
);
5306 if (finfo
.sections
!= NULL
)
5307 free (finfo
.sections
);
5308 if (finfo
.symbuf
!= NULL
)
5309 free (finfo
.symbuf
);
5310 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5312 if ((o
->flags
& SEC_RELOC
) != 0
5313 && elf_section_data (o
)->rel_hashes
!= NULL
)
5314 free (elf_section_data (o
)->rel_hashes
);
5317 elf_tdata (abfd
)->linker
= true;
5322 if (finfo
.symstrtab
!= NULL
)
5323 _bfd_stringtab_free (finfo
.symstrtab
);
5324 if (finfo
.contents
!= NULL
)
5325 free (finfo
.contents
);
5326 if (finfo
.external_relocs
!= NULL
)
5327 free (finfo
.external_relocs
);
5328 if (finfo
.internal_relocs
!= NULL
)
5329 free (finfo
.internal_relocs
);
5330 if (finfo
.external_syms
!= NULL
)
5331 free (finfo
.external_syms
);
5332 if (finfo
.internal_syms
!= NULL
)
5333 free (finfo
.internal_syms
);
5334 if (finfo
.indices
!= NULL
)
5335 free (finfo
.indices
);
5336 if (finfo
.sections
!= NULL
)
5337 free (finfo
.sections
);
5338 if (finfo
.symbuf
!= NULL
)
5339 free (finfo
.symbuf
);
5340 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5342 if ((o
->flags
& SEC_RELOC
) != 0
5343 && elf_section_data (o
)->rel_hashes
!= NULL
)
5344 free (elf_section_data (o
)->rel_hashes
);
5350 /* Add a symbol to the output symbol table. */
5353 elf_link_output_sym (finfo
, name
, elfsym
, input_sec
)
5354 struct elf_final_link_info
*finfo
;
5356 Elf_Internal_Sym
*elfsym
;
5357 asection
*input_sec
;
5359 boolean (*output_symbol_hook
) PARAMS ((bfd
*,
5360 struct bfd_link_info
*info
,
5365 output_symbol_hook
= get_elf_backend_data (finfo
->output_bfd
)->
5366 elf_backend_link_output_symbol_hook
;
5367 if (output_symbol_hook
!= NULL
)
5369 if (! ((*output_symbol_hook
)
5370 (finfo
->output_bfd
, finfo
->info
, name
, elfsym
, input_sec
)))
5374 if (name
== (const char *) NULL
|| *name
== '\0')
5375 elfsym
->st_name
= 0;
5376 else if (input_sec
->flags
& SEC_EXCLUDE
)
5377 elfsym
->st_name
= 0;
5380 elfsym
->st_name
= (unsigned long) _bfd_stringtab_add (finfo
->symstrtab
,
5382 if (elfsym
->st_name
== (unsigned long) -1)
5386 if (finfo
->symbuf_count
>= finfo
->symbuf_size
)
5388 if (! elf_link_flush_output_syms (finfo
))
5392 elf_swap_symbol_out (finfo
->output_bfd
, elfsym
,
5393 (PTR
) (finfo
->symbuf
+ finfo
->symbuf_count
));
5394 ++finfo
->symbuf_count
;
5396 ++ bfd_get_symcount (finfo
->output_bfd
);
5401 /* Flush the output symbols to the file. */
5404 elf_link_flush_output_syms (finfo
)
5405 struct elf_final_link_info
*finfo
;
5407 if (finfo
->symbuf_count
> 0)
5409 Elf_Internal_Shdr
*symtab
;
5411 symtab
= &elf_tdata (finfo
->output_bfd
)->symtab_hdr
;
5413 if (bfd_seek (finfo
->output_bfd
, symtab
->sh_offset
+ symtab
->sh_size
,
5415 || (bfd_write ((PTR
) finfo
->symbuf
, finfo
->symbuf_count
,
5416 sizeof (Elf_External_Sym
), finfo
->output_bfd
)
5417 != finfo
->symbuf_count
* sizeof (Elf_External_Sym
)))
5420 symtab
->sh_size
+= finfo
->symbuf_count
* sizeof (Elf_External_Sym
);
5422 finfo
->symbuf_count
= 0;
5428 /* Adjust all external symbols pointing into SEC_MERGE sections
5429 to reflect the object merging within the sections. */
5432 elf_link_sec_merge_syms (h
, data
)
5433 struct elf_link_hash_entry
*h
;
5438 if ((h
->root
.type
== bfd_link_hash_defined
5439 || h
->root
.type
== bfd_link_hash_defweak
)
5440 && ((sec
= h
->root
.u
.def
.section
)->flags
& SEC_MERGE
)
5441 && elf_section_data (sec
)->merge_info
)
5443 bfd
*output_bfd
= (bfd
*) data
;
5445 h
->root
.u
.def
.value
=
5446 _bfd_merged_section_offset (output_bfd
,
5447 &h
->root
.u
.def
.section
,
5448 elf_section_data (sec
)->merge_info
,
5449 h
->root
.u
.def
.value
, (bfd_vma
) 0);
5455 /* Add an external symbol to the symbol table. This is called from
5456 the hash table traversal routine. When generating a shared object,
5457 we go through the symbol table twice. The first time we output
5458 anything that might have been forced to local scope in a version
5459 script. The second time we output the symbols that are still
5463 elf_link_output_extsym (h
, data
)
5464 struct elf_link_hash_entry
*h
;
5467 struct elf_outext_info
*eoinfo
= (struct elf_outext_info
*) data
;
5468 struct elf_final_link_info
*finfo
= eoinfo
->finfo
;
5470 Elf_Internal_Sym sym
;
5471 asection
*input_sec
;
5473 /* Decide whether to output this symbol in this pass. */
5474 if (eoinfo
->localsyms
)
5476 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5481 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5485 /* If we are not creating a shared library, and this symbol is
5486 referenced by a shared library but is not defined anywhere, then
5487 warn that it is undefined. If we do not do this, the runtime
5488 linker will complain that the symbol is undefined when the
5489 program is run. We don't have to worry about symbols that are
5490 referenced by regular files, because we will already have issued
5491 warnings for them. */
5492 if (! finfo
->info
->relocateable
5493 && ! finfo
->info
->allow_shlib_undefined
5494 && ! finfo
->info
->shared
5495 && h
->root
.type
== bfd_link_hash_undefined
5496 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0
5497 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
5499 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5500 (finfo
->info
, h
->root
.root
.string
, h
->root
.u
.undef
.abfd
,
5501 (asection
*) NULL
, 0, true)))
5503 eoinfo
->failed
= true;
5508 /* We don't want to output symbols that have never been mentioned by
5509 a regular file, or that we have been told to strip. However, if
5510 h->indx is set to -2, the symbol is used by a reloc and we must
5514 else if (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5515 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
5516 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
5517 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
5519 else if (finfo
->info
->strip
== strip_all
5520 || (finfo
->info
->strip
== strip_some
5521 && bfd_hash_lookup (finfo
->info
->keep_hash
,
5522 h
->root
.root
.string
,
5523 false, false) == NULL
))
5528 /* If we're stripping it, and it's not a dynamic symbol, there's
5529 nothing else to do unless it is a forced local symbol. */
5532 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5536 sym
.st_size
= h
->size
;
5537 sym
.st_other
= h
->other
;
5538 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5539 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, h
->type
);
5540 else if (h
->root
.type
== bfd_link_hash_undefweak
5541 || h
->root
.type
== bfd_link_hash_defweak
)
5542 sym
.st_info
= ELF_ST_INFO (STB_WEAK
, h
->type
);
5544 sym
.st_info
= ELF_ST_INFO (STB_GLOBAL
, h
->type
);
5546 switch (h
->root
.type
)
5549 case bfd_link_hash_new
:
5553 case bfd_link_hash_undefined
:
5554 input_sec
= bfd_und_section_ptr
;
5555 sym
.st_shndx
= SHN_UNDEF
;
5558 case bfd_link_hash_undefweak
:
5559 input_sec
= bfd_und_section_ptr
;
5560 sym
.st_shndx
= SHN_UNDEF
;
5563 case bfd_link_hash_defined
:
5564 case bfd_link_hash_defweak
:
5566 input_sec
= h
->root
.u
.def
.section
;
5567 if (input_sec
->output_section
!= NULL
)
5570 _bfd_elf_section_from_bfd_section (finfo
->output_bfd
,
5571 input_sec
->output_section
);
5572 if (sym
.st_shndx
== (unsigned short) -1)
5574 (*_bfd_error_handler
)
5575 (_("%s: could not find output section %s for input section %s"),
5576 bfd_get_filename (finfo
->output_bfd
),
5577 input_sec
->output_section
->name
,
5579 eoinfo
->failed
= true;
5583 /* ELF symbols in relocateable files are section relative,
5584 but in nonrelocateable files they are virtual
5586 sym
.st_value
= h
->root
.u
.def
.value
+ input_sec
->output_offset
;
5587 if (! finfo
->info
->relocateable
)
5588 sym
.st_value
+= input_sec
->output_section
->vma
;
5592 BFD_ASSERT (input_sec
->owner
== NULL
5593 || (input_sec
->owner
->flags
& DYNAMIC
) != 0);
5594 sym
.st_shndx
= SHN_UNDEF
;
5595 input_sec
= bfd_und_section_ptr
;
5600 case bfd_link_hash_common
:
5601 input_sec
= h
->root
.u
.c
.p
->section
;
5602 sym
.st_shndx
= SHN_COMMON
;
5603 sym
.st_value
= 1 << h
->root
.u
.c
.p
->alignment_power
;
5606 case bfd_link_hash_indirect
:
5607 /* These symbols are created by symbol versioning. They point
5608 to the decorated version of the name. For example, if the
5609 symbol foo@@GNU_1.2 is the default, which should be used when
5610 foo is used with no version, then we add an indirect symbol
5611 foo which points to foo@@GNU_1.2. We ignore these symbols,
5612 since the indirected symbol is already in the hash table. */
5615 case bfd_link_hash_warning
:
5616 /* We can't represent these symbols in ELF, although a warning
5617 symbol may have come from a .gnu.warning.SYMBOL section. We
5618 just put the target symbol in the hash table. If the target
5619 symbol does not really exist, don't do anything. */
5620 if (h
->root
.u
.i
.link
->type
== bfd_link_hash_new
)
5622 return (elf_link_output_extsym
5623 ((struct elf_link_hash_entry
*) h
->root
.u
.i
.link
, data
));
5626 /* Give the processor backend a chance to tweak the symbol value,
5627 and also to finish up anything that needs to be done for this
5629 if ((h
->dynindx
!= -1
5630 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5631 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
5633 struct elf_backend_data
*bed
;
5635 bed
= get_elf_backend_data (finfo
->output_bfd
);
5636 if (! ((*bed
->elf_backend_finish_dynamic_symbol
)
5637 (finfo
->output_bfd
, finfo
->info
, h
, &sym
)))
5639 eoinfo
->failed
= true;
5644 /* If we are marking the symbol as undefined, and there are no
5645 non-weak references to this symbol from a regular object, then
5646 mark the symbol as weak undefined; if there are non-weak
5647 references, mark the symbol as strong. We can't do this earlier,
5648 because it might not be marked as undefined until the
5649 finish_dynamic_symbol routine gets through with it. */
5650 if (sym
.st_shndx
== SHN_UNDEF
5651 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) != 0
5652 && (ELF_ST_BIND (sym
.st_info
) == STB_GLOBAL
5653 || ELF_ST_BIND (sym
.st_info
) == STB_WEAK
))
5657 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
) != 0)
5658 bindtype
= STB_GLOBAL
;
5660 bindtype
= STB_WEAK
;
5661 sym
.st_info
= ELF_ST_INFO (bindtype
, ELF_ST_TYPE (sym
.st_info
));
5664 /* If a symbol is not defined locally, we clear the visibility
5666 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5667 sym
.st_other
^= ELF_ST_VISIBILITY (sym
.st_other
);
5669 /* If this symbol should be put in the .dynsym section, then put it
5670 there now. We have already know the symbol index. We also fill
5671 in the entry in the .hash section. */
5672 if (h
->dynindx
!= -1
5673 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
5677 size_t hash_entry_size
;
5678 bfd_byte
*bucketpos
;
5681 sym
.st_name
= h
->dynstr_index
;
5683 elf_swap_symbol_out (finfo
->output_bfd
, &sym
,
5684 (PTR
) (((Elf_External_Sym
*)
5685 finfo
->dynsym_sec
->contents
)
5688 bucketcount
= elf_hash_table (finfo
->info
)->bucketcount
;
5689 bucket
= h
->elf_hash_value
% bucketcount
;
5691 = elf_section_data (finfo
->hash_sec
)->this_hdr
.sh_entsize
;
5692 bucketpos
= ((bfd_byte
*) finfo
->hash_sec
->contents
5693 + (bucket
+ 2) * hash_entry_size
);
5694 chain
= bfd_get (8 * hash_entry_size
, finfo
->output_bfd
, bucketpos
);
5695 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, h
->dynindx
, bucketpos
);
5696 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, chain
,
5697 ((bfd_byte
*) finfo
->hash_sec
->contents
5698 + (bucketcount
+ 2 + h
->dynindx
) * hash_entry_size
));
5700 if (finfo
->symver_sec
!= NULL
&& finfo
->symver_sec
->contents
!= NULL
)
5702 Elf_Internal_Versym iversym
;
5704 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5706 if (h
->verinfo
.verdef
== NULL
)
5707 iversym
.vs_vers
= 0;
5709 iversym
.vs_vers
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
5713 if (h
->verinfo
.vertree
== NULL
)
5714 iversym
.vs_vers
= 1;
5716 iversym
.vs_vers
= h
->verinfo
.vertree
->vernum
+ 1;
5719 if ((h
->elf_link_hash_flags
& ELF_LINK_HIDDEN
) != 0)
5720 iversym
.vs_vers
|= VERSYM_HIDDEN
;
5722 _bfd_elf_swap_versym_out (finfo
->output_bfd
, &iversym
,
5723 (((Elf_External_Versym
*)
5724 finfo
->symver_sec
->contents
)
5729 /* If we're stripping it, then it was just a dynamic symbol, and
5730 there's nothing else to do. */
5734 h
->indx
= bfd_get_symcount (finfo
->output_bfd
);
5736 if (! elf_link_output_sym (finfo
, h
->root
.root
.string
, &sym
, input_sec
))
5738 eoinfo
->failed
= true;
5745 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
5746 originated from the section given by INPUT_REL_HDR) to the
5750 elf_link_output_relocs (output_bfd
, input_section
, input_rel_hdr
,
5753 asection
*input_section
;
5754 Elf_Internal_Shdr
*input_rel_hdr
;
5755 Elf_Internal_Rela
*internal_relocs
;
5757 Elf_Internal_Rela
*irela
;
5758 Elf_Internal_Rela
*irelaend
;
5759 Elf_Internal_Shdr
*output_rel_hdr
;
5760 asection
*output_section
;
5761 unsigned int *rel_countp
= NULL
;
5762 struct elf_backend_data
*bed
;
5764 output_section
= input_section
->output_section
;
5765 output_rel_hdr
= NULL
;
5767 if (elf_section_data (output_section
)->rel_hdr
.sh_entsize
5768 == input_rel_hdr
->sh_entsize
)
5770 output_rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
5771 rel_countp
= &elf_section_data (output_section
)->rel_count
;
5773 else if (elf_section_data (output_section
)->rel_hdr2
5774 && (elf_section_data (output_section
)->rel_hdr2
->sh_entsize
5775 == input_rel_hdr
->sh_entsize
))
5777 output_rel_hdr
= elf_section_data (output_section
)->rel_hdr2
;
5778 rel_countp
= &elf_section_data (output_section
)->rel_count2
;
5781 BFD_ASSERT (output_rel_hdr
!= NULL
);
5783 bed
= get_elf_backend_data (output_bfd
);
5784 irela
= internal_relocs
;
5785 irelaend
= irela
+ NUM_SHDR_ENTRIES (input_rel_hdr
)
5786 * bed
->s
->int_rels_per_ext_rel
;
5788 if (input_rel_hdr
->sh_entsize
== sizeof (Elf_External_Rel
))
5790 Elf_External_Rel
*erel
;
5791 Elf_Internal_Rel
*irel
;
5793 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
5794 * sizeof (Elf_Internal_Rel
));
5797 (*_bfd_error_handler
) (_("Error: out of memory"));
5801 erel
= ((Elf_External_Rel
*) output_rel_hdr
->contents
+ *rel_countp
);
5802 for (; irela
< irelaend
; irela
+= bed
->s
->int_rels_per_ext_rel
, erel
++)
5806 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
5808 irel
[i
].r_offset
= irela
[i
].r_offset
;
5809 irel
[i
].r_info
= irela
[i
].r_info
;
5810 BFD_ASSERT (irela
[i
].r_addend
== 0);
5813 if (bed
->s
->swap_reloc_out
)
5814 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, (PTR
) erel
);
5816 elf_swap_reloc_out (output_bfd
, irel
, erel
);
5823 Elf_External_Rela
*erela
;
5825 BFD_ASSERT (input_rel_hdr
->sh_entsize
== sizeof (Elf_External_Rela
));
5827 erela
= ((Elf_External_Rela
*) output_rel_hdr
->contents
+ *rel_countp
);
5828 for (; irela
< irelaend
; irela
+= bed
->s
->int_rels_per_ext_rel
, erela
++)
5829 if (bed
->s
->swap_reloca_out
)
5830 (*bed
->s
->swap_reloca_out
) (output_bfd
, irela
, (PTR
) erela
);
5832 elf_swap_reloca_out (output_bfd
, irela
, erela
);
5835 /* Bump the counter, so that we know where to add the next set of
5837 *rel_countp
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
5840 /* Link an input file into the linker output file. This function
5841 handles all the sections and relocations of the input file at once.
5842 This is so that we only have to read the local symbols once, and
5843 don't have to keep them in memory. */
5846 elf_link_input_bfd (finfo
, input_bfd
)
5847 struct elf_final_link_info
*finfo
;
5850 boolean (*relocate_section
) PARAMS ((bfd
*, struct bfd_link_info
*,
5851 bfd
*, asection
*, bfd_byte
*,
5852 Elf_Internal_Rela
*,
5853 Elf_Internal_Sym
*, asection
**));
5855 Elf_Internal_Shdr
*symtab_hdr
;
5858 Elf_External_Sym
*external_syms
;
5859 Elf_External_Sym
*esym
;
5860 Elf_External_Sym
*esymend
;
5861 Elf_Internal_Sym
*isym
;
5863 asection
**ppsection
;
5865 struct elf_backend_data
*bed
;
5866 boolean emit_relocs
;
5868 output_bfd
= finfo
->output_bfd
;
5869 bed
= get_elf_backend_data (output_bfd
);
5870 relocate_section
= bed
->elf_backend_relocate_section
;
5872 /* If this is a dynamic object, we don't want to do anything here:
5873 we don't want the local symbols, and we don't want the section
5875 if ((input_bfd
->flags
& DYNAMIC
) != 0)
5878 emit_relocs
= (finfo
->info
->relocateable
5879 || finfo
->info
->emitrelocations
5880 || bed
->elf_backend_emit_relocs
);
5882 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5883 if (elf_bad_symtab (input_bfd
))
5885 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
5890 locsymcount
= symtab_hdr
->sh_info
;
5891 extsymoff
= symtab_hdr
->sh_info
;
5894 /* Read the local symbols. */
5895 if (symtab_hdr
->contents
!= NULL
)
5896 external_syms
= (Elf_External_Sym
*) symtab_hdr
->contents
;
5897 else if (locsymcount
== 0)
5898 external_syms
= NULL
;
5901 external_syms
= finfo
->external_syms
;
5902 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
5903 || (bfd_read (external_syms
, sizeof (Elf_External_Sym
),
5904 locsymcount
, input_bfd
)
5905 != locsymcount
* sizeof (Elf_External_Sym
)))
5909 /* Swap in the local symbols and write out the ones which we know
5910 are going into the output file. */
5911 esym
= external_syms
;
5912 esymend
= esym
+ locsymcount
;
5913 isym
= finfo
->internal_syms
;
5914 pindex
= finfo
->indices
;
5915 ppsection
= finfo
->sections
;
5916 for (; esym
< esymend
; esym
++, isym
++, pindex
++, ppsection
++)
5920 Elf_Internal_Sym osym
;
5922 elf_swap_symbol_in (input_bfd
, esym
, isym
);
5925 if (elf_bad_symtab (input_bfd
))
5927 if (ELF_ST_BIND (isym
->st_info
) != STB_LOCAL
)
5935 if (isym
->st_shndx
== SHN_UNDEF
)
5937 isec
= bfd_und_section_ptr
;
5940 else if (isym
->st_shndx
> 0 && isym
->st_shndx
< SHN_LORESERVE
)
5942 isec
= section_from_elf_index (input_bfd
, isym
->st_shndx
);
5943 if (isec
&& elf_section_data (isec
)->merge_info
5944 && ELF_ST_TYPE (isym
->st_info
) != STT_SECTION
)
5946 _bfd_merged_section_offset (output_bfd
, &isec
,
5947 elf_section_data (isec
)->merge_info
,
5948 isym
->st_value
, (bfd_vma
) 0);
5950 else if (isym
->st_shndx
== SHN_ABS
)
5952 isec
= bfd_abs_section_ptr
;
5955 else if (isym
->st_shndx
== SHN_COMMON
)
5957 isec
= bfd_com_section_ptr
;
5968 /* Don't output the first, undefined, symbol. */
5969 if (esym
== external_syms
)
5972 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
5976 /* Save away all section symbol values. */
5981 if (isec
->symbol
->value
!= isym
->st_value
)
5982 (*_bfd_error_handler
)
5983 (_("%s: invalid section symbol index 0x%x (%s) ingored"),
5984 bfd_get_filename (input_bfd
), isym
->st_shndx
,
5988 isec
->symbol
->value
= isym
->st_value
;
5991 /* If this is a discarded link-once section symbol, update
5992 it's value to that of the kept section symbol. The
5993 linker will keep the first of any matching link-once
5994 sections, so we should have already seen it's section
5995 symbol. I trust no-one will have the bright idea of
5996 re-ordering the bfd list... */
5998 && (bfd_get_section_flags (input_bfd
, isec
) & SEC_LINK_ONCE
) != 0
5999 && (ksec
= isec
->kept_section
) != NULL
)
6001 isym
->st_value
= ksec
->symbol
->value
;
6003 /* That put the value right, but the section info is all
6004 wrong. I hope this works. */
6005 isec
->output_offset
= ksec
->output_offset
;
6006 isec
->output_section
= ksec
->output_section
;
6009 /* We never output section symbols. Instead, we use the
6010 section symbol of the corresponding section in the output
6015 /* If we are stripping all symbols, we don't want to output this
6017 if (finfo
->info
->strip
== strip_all
)
6020 /* If we are discarding all local symbols, we don't want to
6021 output this one. If we are generating a relocateable output
6022 file, then some of the local symbols may be required by
6023 relocs; we output them below as we discover that they are
6025 if (finfo
->info
->discard
== discard_all
)
6028 /* If this symbol is defined in a section which we are
6029 discarding, we don't need to keep it, but note that
6030 linker_mark is only reliable for sections that have contents.
6031 For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE
6032 as well as linker_mark. */
6033 if (isym
->st_shndx
> 0
6034 && isym
->st_shndx
< SHN_LORESERVE
6036 && ((! isec
->linker_mark
&& (isec
->flags
& SEC_HAS_CONTENTS
) != 0)
6037 || (! finfo
->info
->relocateable
6038 && (isec
->flags
& SEC_EXCLUDE
) != 0)))
6041 /* Get the name of the symbol. */
6042 name
= bfd_elf_string_from_elf_section (input_bfd
, symtab_hdr
->sh_link
,
6047 /* See if we are discarding symbols with this name. */
6048 if ((finfo
->info
->strip
== strip_some
6049 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false, false)
6051 || (((finfo
->info
->discard
== discard_sec_merge
6052 && (isec
->flags
& SEC_MERGE
) && ! finfo
->info
->relocateable
)
6053 || finfo
->info
->discard
== discard_l
)
6054 && bfd_is_local_label_name (input_bfd
, name
)))
6057 /* If we get here, we are going to output this symbol. */
6061 /* Adjust the section index for the output file. */
6062 osym
.st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
6063 isec
->output_section
);
6064 if (osym
.st_shndx
== (unsigned short) -1)
6067 *pindex
= bfd_get_symcount (output_bfd
);
6069 /* ELF symbols in relocateable files are section relative, but
6070 in executable files they are virtual addresses. Note that
6071 this code assumes that all ELF sections have an associated
6072 BFD section with a reasonable value for output_offset; below
6073 we assume that they also have a reasonable value for
6074 output_section. Any special sections must be set up to meet
6075 these requirements. */
6076 osym
.st_value
+= isec
->output_offset
;
6077 if (! finfo
->info
->relocateable
)
6078 osym
.st_value
+= isec
->output_section
->vma
;
6080 if (! elf_link_output_sym (finfo
, name
, &osym
, isec
))
6084 /* Relocate the contents of each section. */
6085 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6089 if (! o
->linker_mark
)
6091 /* This section was omitted from the link. */
6095 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
6096 || (o
->_raw_size
== 0 && (o
->flags
& SEC_RELOC
) == 0))
6099 if ((o
->flags
& SEC_LINKER_CREATED
) != 0)
6101 /* Section was created by elf_link_create_dynamic_sections
6106 /* Get the contents of the section. They have been cached by a
6107 relaxation routine. Note that o is a section in an input
6108 file, so the contents field will not have been set by any of
6109 the routines which work on output files. */
6110 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
6111 contents
= elf_section_data (o
)->this_hdr
.contents
;
6114 contents
= finfo
->contents
;
6115 if (! bfd_get_section_contents (input_bfd
, o
, contents
,
6116 (file_ptr
) 0, o
->_raw_size
))
6120 if ((o
->flags
& SEC_RELOC
) != 0)
6122 Elf_Internal_Rela
*internal_relocs
;
6124 /* Get the swapped relocs. */
6125 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
6126 (input_bfd
, o
, finfo
->external_relocs
,
6127 finfo
->internal_relocs
, false));
6128 if (internal_relocs
== NULL
6129 && o
->reloc_count
> 0)
6132 /* Relocate the section by invoking a back end routine.
6134 The back end routine is responsible for adjusting the
6135 section contents as necessary, and (if using Rela relocs
6136 and generating a relocateable output file) adjusting the
6137 reloc addend as necessary.
6139 The back end routine does not have to worry about setting
6140 the reloc address or the reloc symbol index.
6142 The back end routine is given a pointer to the swapped in
6143 internal symbols, and can access the hash table entries
6144 for the external symbols via elf_sym_hashes (input_bfd).
6146 When generating relocateable output, the back end routine
6147 must handle STB_LOCAL/STT_SECTION symbols specially. The
6148 output symbol is going to be a section symbol
6149 corresponding to the output section, which will require
6150 the addend to be adjusted. */
6152 if (! (*relocate_section
) (output_bfd
, finfo
->info
,
6153 input_bfd
, o
, contents
,
6155 finfo
->internal_syms
,
6161 Elf_Internal_Rela
*irela
;
6162 Elf_Internal_Rela
*irelaend
;
6163 struct elf_link_hash_entry
**rel_hash
;
6164 Elf_Internal_Shdr
*input_rel_hdr
;
6165 unsigned int next_erel
;
6166 void (* reloc_emitter
) PARAMS ((bfd
*, asection
*,
6167 Elf_Internal_Shdr
*,
6168 Elf_Internal_Rela
*));
6170 /* Adjust the reloc addresses and symbol indices. */
6172 irela
= internal_relocs
;
6174 + o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6175 rel_hash
= (elf_section_data (o
->output_section
)->rel_hashes
6176 + elf_section_data (o
->output_section
)->rel_count
6177 + elf_section_data (o
->output_section
)->rel_count2
);
6178 for (next_erel
= 0; irela
< irelaend
; irela
++, next_erel
++)
6180 unsigned long r_symndx
;
6181 Elf_Internal_Sym
*isym
;
6184 if (next_erel
== bed
->s
->int_rels_per_ext_rel
)
6190 irela
->r_offset
+= o
->output_offset
;
6192 /* Relocs in an executable have to be virtual addresses. */
6193 if (finfo
->info
->emitrelocations
)
6194 irela
->r_offset
+= o
->output_section
->vma
;
6196 r_symndx
= ELF_R_SYM (irela
->r_info
);
6201 if (r_symndx
>= locsymcount
6202 || (elf_bad_symtab (input_bfd
)
6203 && finfo
->sections
[r_symndx
] == NULL
))
6205 struct elf_link_hash_entry
*rh
;
6208 /* This is a reloc against a global symbol. We
6209 have not yet output all the local symbols, so
6210 we do not know the symbol index of any global
6211 symbol. We set the rel_hash entry for this
6212 reloc to point to the global hash table entry
6213 for this symbol. The symbol index is then
6214 set at the end of elf_bfd_final_link. */
6215 indx
= r_symndx
- extsymoff
;
6216 rh
= elf_sym_hashes (input_bfd
)[indx
];
6217 while (rh
->root
.type
== bfd_link_hash_indirect
6218 || rh
->root
.type
== bfd_link_hash_warning
)
6219 rh
= (struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
;
6221 /* Setting the index to -2 tells
6222 elf_link_output_extsym that this symbol is
6224 BFD_ASSERT (rh
->indx
< 0);
6232 /* This is a reloc against a local symbol. */
6235 isym
= finfo
->internal_syms
+ r_symndx
;
6236 sec
= finfo
->sections
[r_symndx
];
6237 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
6239 /* I suppose the backend ought to fill in the
6240 section of any STT_SECTION symbol against a
6241 processor specific section. If we have
6242 discarded a section, the output_section will
6243 be the absolute section. */
6245 && (bfd_is_abs_section (sec
)
6246 || (sec
->output_section
!= NULL
6247 && bfd_is_abs_section (sec
->output_section
))))
6249 else if (sec
== NULL
|| sec
->owner
== NULL
)
6251 bfd_set_error (bfd_error_bad_value
);
6256 r_symndx
= sec
->output_section
->target_index
;
6257 BFD_ASSERT (r_symndx
!= 0);
6262 if (finfo
->indices
[r_symndx
] == -1)
6268 if (finfo
->info
->strip
== strip_all
)
6270 /* You can't do ld -r -s. */
6271 bfd_set_error (bfd_error_invalid_operation
);
6275 /* This symbol was skipped earlier, but
6276 since it is needed by a reloc, we
6277 must output it now. */
6278 link
= symtab_hdr
->sh_link
;
6279 name
= (bfd_elf_string_from_elf_section
6280 (input_bfd
, link
, isym
->st_name
));
6284 osec
= sec
->output_section
;
6286 _bfd_elf_section_from_bfd_section (output_bfd
,
6288 if (isym
->st_shndx
== (unsigned short) -1)
6291 isym
->st_value
+= sec
->output_offset
;
6292 if (! finfo
->info
->relocateable
)
6293 isym
->st_value
+= osec
->vma
;
6295 finfo
->indices
[r_symndx
]
6296 = bfd_get_symcount (output_bfd
);
6298 if (! elf_link_output_sym (finfo
, name
, isym
, sec
))
6302 r_symndx
= finfo
->indices
[r_symndx
];
6305 irela
->r_info
= ELF_R_INFO (r_symndx
,
6306 ELF_R_TYPE (irela
->r_info
));
6309 /* Swap out the relocs. */
6310 if (bed
->elf_backend_emit_relocs
6311 && !(finfo
->info
->relocateable
6312 || finfo
->info
->emitrelocations
))
6313 reloc_emitter
= bed
->elf_backend_emit_relocs
;
6315 reloc_emitter
= elf_link_output_relocs
;
6317 input_rel_hdr
= &elf_section_data (o
)->rel_hdr
;
6318 (*reloc_emitter
) (output_bfd
, o
, input_rel_hdr
, internal_relocs
);
6320 input_rel_hdr
= elf_section_data (o
)->rel_hdr2
;
6323 internal_relocs
+= NUM_SHDR_ENTRIES (input_rel_hdr
)
6324 * bed
->s
->int_rels_per_ext_rel
;
6325 reloc_emitter (output_bfd
, o
, input_rel_hdr
, internal_relocs
);
6331 /* Write out the modified section contents. */
6332 if (elf_section_data (o
)->stab_info
)
6334 if (! (_bfd_write_section_stabs
6335 (output_bfd
, &elf_hash_table (finfo
->info
)->stab_info
,
6336 o
, &elf_section_data (o
)->stab_info
, contents
)))
6339 else if (elf_section_data (o
)->merge_info
)
6341 if (! (_bfd_write_merged_section
6342 (output_bfd
, o
, elf_section_data (o
)->merge_info
)))
6347 if (! (o
->flags
& SEC_EXCLUDE
) &&
6348 ! bfd_set_section_contents (output_bfd
, o
->output_section
,
6349 contents
, o
->output_offset
,
6350 (o
->_cooked_size
!= 0
6360 /* Generate a reloc when linking an ELF file. This is a reloc
6361 requested by the linker, and does come from any input file. This
6362 is used to build constructor and destructor tables when linking
6366 elf_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
6368 struct bfd_link_info
*info
;
6369 asection
*output_section
;
6370 struct bfd_link_order
*link_order
;
6372 reloc_howto_type
*howto
;
6376 struct elf_link_hash_entry
**rel_hash_ptr
;
6377 Elf_Internal_Shdr
*rel_hdr
;
6378 struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
6380 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
6383 bfd_set_error (bfd_error_bad_value
);
6387 addend
= link_order
->u
.reloc
.p
->addend
;
6389 /* Figure out the symbol index. */
6390 rel_hash_ptr
= (elf_section_data (output_section
)->rel_hashes
6391 + elf_section_data (output_section
)->rel_count
6392 + elf_section_data (output_section
)->rel_count2
);
6393 if (link_order
->type
== bfd_section_reloc_link_order
)
6395 indx
= link_order
->u
.reloc
.p
->u
.section
->target_index
;
6396 BFD_ASSERT (indx
!= 0);
6397 *rel_hash_ptr
= NULL
;
6401 struct elf_link_hash_entry
*h
;
6403 /* Treat a reloc against a defined symbol as though it were
6404 actually against the section. */
6405 h
= ((struct elf_link_hash_entry
*)
6406 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
6407 link_order
->u
.reloc
.p
->u
.name
,
6408 false, false, true));
6410 && (h
->root
.type
== bfd_link_hash_defined
6411 || h
->root
.type
== bfd_link_hash_defweak
))
6415 section
= h
->root
.u
.def
.section
;
6416 indx
= section
->output_section
->target_index
;
6417 *rel_hash_ptr
= NULL
;
6418 /* It seems that we ought to add the symbol value to the
6419 addend here, but in practice it has already been added
6420 because it was passed to constructor_callback. */
6421 addend
+= section
->output_section
->vma
+ section
->output_offset
;
6425 /* Setting the index to -2 tells elf_link_output_extsym that
6426 this symbol is used by a reloc. */
6433 if (! ((*info
->callbacks
->unattached_reloc
)
6434 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
6435 (asection
*) NULL
, (bfd_vma
) 0)))
6441 /* If this is an inplace reloc, we must write the addend into the
6443 if (howto
->partial_inplace
&& addend
!= 0)
6446 bfd_reloc_status_type rstat
;
6450 size
= bfd_get_reloc_size (howto
);
6451 buf
= (bfd_byte
*) bfd_zmalloc (size
);
6452 if (buf
== (bfd_byte
*) NULL
)
6454 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
6460 case bfd_reloc_outofrange
:
6462 case bfd_reloc_overflow
:
6463 if (! ((*info
->callbacks
->reloc_overflow
)
6465 (link_order
->type
== bfd_section_reloc_link_order
6466 ? bfd_section_name (output_bfd
,
6467 link_order
->u
.reloc
.p
->u
.section
)
6468 : link_order
->u
.reloc
.p
->u
.name
),
6469 howto
->name
, addend
, (bfd
*) NULL
, (asection
*) NULL
,
6477 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
6478 (file_ptr
) link_order
->offset
, size
);
6484 /* The address of a reloc is relative to the section in a
6485 relocateable file, and is a virtual address in an executable
6487 offset
= link_order
->offset
;
6488 if (! info
->relocateable
)
6489 offset
+= output_section
->vma
;
6491 rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
6493 if (rel_hdr
->sh_type
== SHT_REL
)
6495 Elf_Internal_Rel
*irel
;
6496 Elf_External_Rel
*erel
;
6499 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
6500 * sizeof (Elf_Internal_Rel
));
6504 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6505 irel
[i
].r_offset
= offset
;
6506 irel
[0].r_info
= ELF_R_INFO (indx
, howto
->type
);
6508 erel
= ((Elf_External_Rel
*) rel_hdr
->contents
6509 + elf_section_data (output_section
)->rel_count
);
6511 if (bed
->s
->swap_reloc_out
)
6512 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, (bfd_byte
*) erel
);
6514 elf_swap_reloc_out (output_bfd
, irel
, erel
);
6520 Elf_Internal_Rela
*irela
;
6521 Elf_External_Rela
*erela
;
6524 irela
= (Elf_Internal_Rela
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
6525 * sizeof (Elf_Internal_Rela
));
6529 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6530 irela
[i
].r_offset
= offset
;
6531 irela
[0].r_info
= ELF_R_INFO (indx
, howto
->type
);
6532 irela
[0].r_addend
= addend
;
6534 erela
= ((Elf_External_Rela
*) rel_hdr
->contents
6535 + elf_section_data (output_section
)->rel_count
);
6537 if (bed
->s
->swap_reloca_out
)
6538 (*bed
->s
->swap_reloca_out
) (output_bfd
, irela
, (bfd_byte
*) erela
);
6540 elf_swap_reloca_out (output_bfd
, irela
, erela
);
6543 ++elf_section_data (output_section
)->rel_count
;
6548 /* Allocate a pointer to live in a linker created section. */
6551 elf_create_pointer_linker_section (abfd
, info
, lsect
, h
, rel
)
6553 struct bfd_link_info
*info
;
6554 elf_linker_section_t
*lsect
;
6555 struct elf_link_hash_entry
*h
;
6556 const Elf_Internal_Rela
*rel
;
6558 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
6559 elf_linker_section_pointers_t
*linker_section_ptr
;
6560 unsigned long r_symndx
= ELF_R_SYM (rel
->r_info
);;
6562 BFD_ASSERT (lsect
!= NULL
);
6564 /* Is this a global symbol? */
6567 /* Has this symbol already been allocated? If so, our work is done. */
6568 if (_bfd_elf_find_pointer_linker_section (h
->linker_section_pointer
,
6573 ptr_linker_section_ptr
= &h
->linker_section_pointer
;
6574 /* Make sure this symbol is output as a dynamic symbol. */
6575 if (h
->dynindx
== -1)
6577 if (! elf_link_record_dynamic_symbol (info
, h
))
6581 if (lsect
->rel_section
)
6582 lsect
->rel_section
->_raw_size
+= sizeof (Elf_External_Rela
);
6586 /* Allocation of a pointer to a local symbol. */
6587 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
6589 /* Allocate a table to hold the local symbols if first time. */
6592 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
6593 register unsigned int i
;
6595 ptr
= (elf_linker_section_pointers_t
**)
6597 num_symbols
* sizeof (elf_linker_section_pointers_t
*));
6602 elf_local_ptr_offsets (abfd
) = ptr
;
6603 for (i
= 0; i
< num_symbols
; i
++)
6604 ptr
[i
] = (elf_linker_section_pointers_t
*) 0;
6607 /* Has this symbol already been allocated? If so, our work is done. */
6608 if (_bfd_elf_find_pointer_linker_section (ptr
[r_symndx
],
6613 ptr_linker_section_ptr
= &ptr
[r_symndx
];
6617 /* If we are generating a shared object, we need to
6618 output a R_<xxx>_RELATIVE reloc so that the
6619 dynamic linker can adjust this GOT entry. */
6620 BFD_ASSERT (lsect
->rel_section
!= NULL
);
6621 lsect
->rel_section
->_raw_size
+= sizeof (Elf_External_Rela
);
6625 /* Allocate space for a pointer in the linker section, and allocate
6626 a new pointer record from internal memory. */
6627 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
6628 linker_section_ptr
= (elf_linker_section_pointers_t
*)
6629 bfd_alloc (abfd
, sizeof (elf_linker_section_pointers_t
));
6631 if (!linker_section_ptr
)
6634 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
6635 linker_section_ptr
->addend
= rel
->r_addend
;
6636 linker_section_ptr
->which
= lsect
->which
;
6637 linker_section_ptr
->written_address_p
= false;
6638 *ptr_linker_section_ptr
= linker_section_ptr
;
6641 if (lsect
->hole_size
&& lsect
->hole_offset
< lsect
->max_hole_offset
)
6643 linker_section_ptr
->offset
= (lsect
->section
->_raw_size
6644 - lsect
->hole_size
+ (ARCH_SIZE
/ 8));
6645 lsect
->hole_offset
+= ARCH_SIZE
/ 8;
6646 lsect
->sym_offset
+= ARCH_SIZE
/ 8;
6647 if (lsect
->sym_hash
)
6649 /* Bump up symbol value if needed. */
6650 lsect
->sym_hash
->root
.u
.def
.value
+= ARCH_SIZE
/ 8;
6652 fprintf (stderr
, "Bump up %s by %ld, current value = %ld\n",
6653 lsect
->sym_hash
->root
.root
.string
,
6654 (long) ARCH_SIZE
/ 8,
6655 (long) lsect
->sym_hash
->root
.u
.def
.value
);
6661 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
6663 lsect
->section
->_raw_size
+= ARCH_SIZE
/ 8;
6667 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
6668 lsect
->name
, (long) linker_section_ptr
->offset
,
6669 (long) lsect
->section
->_raw_size
);
6676 #define bfd_put_ptr(BFD,VAL,ADDR) bfd_put_64 (BFD, VAL, ADDR)
6679 #define bfd_put_ptr(BFD,VAL,ADDR) bfd_put_32 (BFD, VAL, ADDR)
6682 /* Fill in the address for a pointer generated in a linker section. */
6685 elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
, lsect
, h
,
6686 relocation
, rel
, relative_reloc
)
6689 struct bfd_link_info
*info
;
6690 elf_linker_section_t
*lsect
;
6691 struct elf_link_hash_entry
*h
;
6693 const Elf_Internal_Rela
*rel
;
6696 elf_linker_section_pointers_t
*linker_section_ptr
;
6698 BFD_ASSERT (lsect
!= NULL
);
6702 /* Handle global symbol. */
6703 linker_section_ptr
= (_bfd_elf_find_pointer_linker_section
6704 (h
->linker_section_pointer
,
6708 BFD_ASSERT (linker_section_ptr
!= NULL
);
6710 if (! elf_hash_table (info
)->dynamic_sections_created
6713 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6715 /* This is actually a static link, or it is a
6716 -Bsymbolic link and the symbol is defined
6717 locally. We must initialize this entry in the
6720 When doing a dynamic link, we create a .rela.<xxx>
6721 relocation entry to initialize the value. This
6722 is done in the finish_dynamic_symbol routine. */
6723 if (!linker_section_ptr
->written_address_p
)
6725 linker_section_ptr
->written_address_p
= true;
6726 bfd_put_ptr (output_bfd
,
6727 relocation
+ linker_section_ptr
->addend
,
6728 (lsect
->section
->contents
6729 + linker_section_ptr
->offset
));
6735 /* Handle local symbol. */
6736 unsigned long r_symndx
= ELF_R_SYM (rel
->r_info
);
6737 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6738 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
6739 linker_section_ptr
= (_bfd_elf_find_pointer_linker_section
6740 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
6744 BFD_ASSERT (linker_section_ptr
!= NULL
);
6746 /* Write out pointer if it hasn't been rewritten out before. */
6747 if (!linker_section_ptr
->written_address_p
)
6749 linker_section_ptr
->written_address_p
= true;
6750 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
6751 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6755 asection
*srel
= lsect
->rel_section
;
6756 Elf_Internal_Rela
*outrel
;
6757 struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
6760 outrel
= (Elf_Internal_Rela
*)
6761 bfd_zmalloc (sizeof (Elf_Internal_Rela
)
6762 * bed
->s
->int_rels_per_ext_rel
);
6765 (*_bfd_error_handler
) (_("Error: out of memory"));
6769 /* We need to generate a relative reloc for the dynamic
6773 srel
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
,
6775 lsect
->rel_section
= srel
;
6778 BFD_ASSERT (srel
!= NULL
);
6780 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6781 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
6782 + lsect
->section
->output_offset
6783 + linker_section_ptr
->offset
);
6784 outrel
[0].r_info
= ELF_R_INFO (0, relative_reloc
);
6785 outrel
[0].r_addend
= 0;
6786 elf_swap_reloca_out (output_bfd
, outrel
,
6787 (((Elf_External_Rela
*)
6788 lsect
->section
->contents
)
6789 + (elf_section_data (lsect
->section
)
6791 ++elf_section_data (lsect
->section
)->rel_count
;
6798 relocation
= (lsect
->section
->output_offset
6799 + linker_section_ptr
->offset
6800 - lsect
->hole_offset
6801 - lsect
->sym_offset
);
6805 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6806 lsect
->name
, (long) relocation
, (long) relocation
);
6809 /* Subtract out the addend, because it will get added back in by the normal
6811 return relocation
- linker_section_ptr
->addend
;
6814 /* Garbage collect unused sections. */
6816 static boolean elf_gc_mark
6817 PARAMS ((struct bfd_link_info
*info
, asection
*sec
,
6818 asection
* (*gc_mark_hook
)
6819 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
6820 struct elf_link_hash_entry
*, Elf_Internal_Sym
*))));
6822 static boolean elf_gc_sweep
6823 PARAMS ((struct bfd_link_info
*info
,
6824 boolean (*gc_sweep_hook
)
6825 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*o
,
6826 const Elf_Internal_Rela
*relocs
))));
6828 static boolean elf_gc_sweep_symbol
6829 PARAMS ((struct elf_link_hash_entry
*h
, PTR idxptr
));
6831 static boolean elf_gc_allocate_got_offsets
6832 PARAMS ((struct elf_link_hash_entry
*h
, PTR offarg
));
6834 static boolean elf_gc_propagate_vtable_entries_used
6835 PARAMS ((struct elf_link_hash_entry
*h
, PTR dummy
));
6837 static boolean elf_gc_smash_unused_vtentry_relocs
6838 PARAMS ((struct elf_link_hash_entry
*h
, PTR dummy
));
6840 /* The mark phase of garbage collection. For a given section, mark
6841 it, and all the sections which define symbols to which it refers. */
6844 elf_gc_mark (info
, sec
, gc_mark_hook
)
6845 struct bfd_link_info
*info
;
6847 asection
* (*gc_mark_hook
)
6848 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
6849 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
6855 /* Look through the section relocs. */
6857 if ((sec
->flags
& SEC_RELOC
) != 0 && sec
->reloc_count
> 0)
6859 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6860 Elf_Internal_Shdr
*symtab_hdr
;
6861 struct elf_link_hash_entry
**sym_hashes
;
6864 Elf_External_Sym
*locsyms
, *freesyms
= NULL
;
6865 bfd
*input_bfd
= sec
->owner
;
6866 struct elf_backend_data
*bed
= get_elf_backend_data (input_bfd
);
6868 /* GCFIXME: how to arrange so that relocs and symbols are not
6869 reread continually? */
6871 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6872 sym_hashes
= elf_sym_hashes (input_bfd
);
6874 /* Read the local symbols. */
6875 if (elf_bad_symtab (input_bfd
))
6877 nlocsyms
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
6881 extsymoff
= nlocsyms
= symtab_hdr
->sh_info
;
6882 if (symtab_hdr
->contents
)
6883 locsyms
= (Elf_External_Sym
*) symtab_hdr
->contents
;
6884 else if (nlocsyms
== 0)
6888 locsyms
= freesyms
=
6889 bfd_malloc (nlocsyms
* sizeof (Elf_External_Sym
));
6890 if (freesyms
== NULL
6891 || bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
6892 || (bfd_read (locsyms
, sizeof (Elf_External_Sym
),
6893 nlocsyms
, input_bfd
)
6894 != nlocsyms
* sizeof (Elf_External_Sym
)))
6901 /* Read the relocations. */
6902 relstart
= (NAME(_bfd_elf
,link_read_relocs
)
6903 (sec
->owner
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
6904 info
->keep_memory
));
6905 if (relstart
== NULL
)
6910 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6912 for (rel
= relstart
; rel
< relend
; rel
++)
6914 unsigned long r_symndx
;
6916 struct elf_link_hash_entry
*h
;
6919 r_symndx
= ELF_R_SYM (rel
->r_info
);
6923 if (elf_bad_symtab (sec
->owner
))
6925 elf_swap_symbol_in (input_bfd
, &locsyms
[r_symndx
], &s
);
6926 if (ELF_ST_BIND (s
.st_info
) == STB_LOCAL
)
6927 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, NULL
, &s
);
6930 h
= sym_hashes
[r_symndx
- extsymoff
];
6931 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, h
, NULL
);
6934 else if (r_symndx
>= nlocsyms
)
6936 h
= sym_hashes
[r_symndx
- extsymoff
];
6937 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, h
, NULL
);
6941 elf_swap_symbol_in (input_bfd
, &locsyms
[r_symndx
], &s
);
6942 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, NULL
, &s
);
6945 if (rsec
&& !rsec
->gc_mark
)
6946 if (!elf_gc_mark (info
, rsec
, gc_mark_hook
))
6954 if (!info
->keep_memory
)
6964 /* The sweep phase of garbage collection. Remove all garbage sections. */
6967 elf_gc_sweep (info
, gc_sweep_hook
)
6968 struct bfd_link_info
*info
;
6969 boolean (*gc_sweep_hook
)
6970 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*o
,
6971 const Elf_Internal_Rela
*relocs
));
6975 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
6979 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
6982 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
6984 /* Keep special sections. Keep .debug sections. */
6985 if ((o
->flags
& SEC_LINKER_CREATED
)
6986 || (o
->flags
& SEC_DEBUGGING
))
6992 /* Skip sweeping sections already excluded. */
6993 if (o
->flags
& SEC_EXCLUDE
)
6996 /* Since this is early in the link process, it is simple
6997 to remove a section from the output. */
6998 o
->flags
|= SEC_EXCLUDE
;
7000 /* But we also have to update some of the relocation
7001 info we collected before. */
7003 && (o
->flags
& SEC_RELOC
) && o
->reloc_count
> 0)
7005 Elf_Internal_Rela
*internal_relocs
;
7008 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
7009 (o
->owner
, o
, NULL
, NULL
, info
->keep_memory
));
7010 if (internal_relocs
== NULL
)
7013 r
= (*gc_sweep_hook
) (o
->owner
, info
, o
, internal_relocs
);
7015 if (!info
->keep_memory
)
7016 free (internal_relocs
);
7024 /* Remove the symbols that were in the swept sections from the dynamic
7025 symbol table. GCFIXME: Anyone know how to get them out of the
7026 static symbol table as well? */
7030 elf_link_hash_traverse (elf_hash_table (info
),
7031 elf_gc_sweep_symbol
,
7034 elf_hash_table (info
)->dynsymcount
= i
;
7040 /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */
7043 elf_gc_sweep_symbol (h
, idxptr
)
7044 struct elf_link_hash_entry
*h
;
7047 int *idx
= (int *) idxptr
;
7049 if (h
->dynindx
!= -1
7050 && ((h
->root
.type
!= bfd_link_hash_defined
7051 && h
->root
.type
!= bfd_link_hash_defweak
)
7052 || h
->root
.u
.def
.section
->gc_mark
))
7053 h
->dynindx
= (*idx
)++;
7058 /* Propogate collected vtable information. This is called through
7059 elf_link_hash_traverse. */
7062 elf_gc_propagate_vtable_entries_used (h
, okp
)
7063 struct elf_link_hash_entry
*h
;
7066 /* Those that are not vtables. */
7067 if (h
->vtable_parent
== NULL
)
7070 /* Those vtables that do not have parents, we cannot merge. */
7071 if (h
->vtable_parent
== (struct elf_link_hash_entry
*) -1)
7074 /* If we've already been done, exit. */
7075 if (h
->vtable_entries_used
&& h
->vtable_entries_used
[-1])
7078 /* Make sure the parent's table is up to date. */
7079 elf_gc_propagate_vtable_entries_used (h
->vtable_parent
, okp
);
7081 if (h
->vtable_entries_used
== NULL
)
7083 /* None of this table's entries were referenced. Re-use the
7085 h
->vtable_entries_used
= h
->vtable_parent
->vtable_entries_used
;
7086 h
->vtable_entries_size
= h
->vtable_parent
->vtable_entries_size
;
7093 /* Or the parent's entries into ours. */
7094 cu
= h
->vtable_entries_used
;
7096 pu
= h
->vtable_parent
->vtable_entries_used
;
7099 asection
*sec
= h
->root
.u
.def
.section
;
7100 struct elf_backend_data
*bed
= get_elf_backend_data (sec
->owner
);
7101 int file_align
= bed
->s
->file_align
;
7103 n
= h
->vtable_parent
->vtable_entries_size
/ file_align
;
7106 if (*pu
) *cu
= true;
7116 elf_gc_smash_unused_vtentry_relocs (h
, okp
)
7117 struct elf_link_hash_entry
*h
;
7121 bfd_vma hstart
, hend
;
7122 Elf_Internal_Rela
*relstart
, *relend
, *rel
;
7123 struct elf_backend_data
*bed
;
7126 /* Take care of both those symbols that do not describe vtables as
7127 well as those that are not loaded. */
7128 if (h
->vtable_parent
== NULL
)
7131 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
7132 || h
->root
.type
== bfd_link_hash_defweak
);
7134 sec
= h
->root
.u
.def
.section
;
7135 hstart
= h
->root
.u
.def
.value
;
7136 hend
= hstart
+ h
->size
;
7138 relstart
= (NAME(_bfd_elf
,link_read_relocs
)
7139 (sec
->owner
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
, true));
7141 return *(boolean
*) okp
= false;
7142 bed
= get_elf_backend_data (sec
->owner
);
7143 file_align
= bed
->s
->file_align
;
7145 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7147 for (rel
= relstart
; rel
< relend
; ++rel
)
7148 if (rel
->r_offset
>= hstart
&& rel
->r_offset
< hend
)
7150 /* If the entry is in use, do nothing. */
7151 if (h
->vtable_entries_used
7152 && (rel
->r_offset
- hstart
) < h
->vtable_entries_size
)
7154 bfd_vma entry
= (rel
->r_offset
- hstart
) / file_align
;
7155 if (h
->vtable_entries_used
[entry
])
7158 /* Otherwise, kill it. */
7159 rel
->r_offset
= rel
->r_info
= rel
->r_addend
= 0;
7165 /* Do mark and sweep of unused sections. */
7168 elf_gc_sections (abfd
, info
)
7170 struct bfd_link_info
*info
;
7174 asection
* (*gc_mark_hook
)
7175 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, Elf_Internal_Rela
*,
7176 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*));
7178 if (!get_elf_backend_data (abfd
)->can_gc_sections
7179 || info
->relocateable
|| info
->emitrelocations
7180 || elf_hash_table (info
)->dynamic_sections_created
)
7183 /* Apply transitive closure to the vtable entry usage info. */
7184 elf_link_hash_traverse (elf_hash_table (info
),
7185 elf_gc_propagate_vtable_entries_used
,
7190 /* Kill the vtable relocations that were not used. */
7191 elf_link_hash_traverse (elf_hash_table (info
),
7192 elf_gc_smash_unused_vtentry_relocs
,
7197 /* Grovel through relocs to find out who stays ... */
7199 gc_mark_hook
= get_elf_backend_data (abfd
)->gc_mark_hook
;
7200 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
7204 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
7207 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
7209 if (o
->flags
& SEC_KEEP
)
7210 if (!elf_gc_mark (info
, o
, gc_mark_hook
))
7215 /* ... and mark SEC_EXCLUDE for those that go. */
7216 if (!elf_gc_sweep (info
, get_elf_backend_data (abfd
)->gc_sweep_hook
))
7222 /* Called from check_relocs to record the existance of a VTINHERIT reloc. */
7225 elf_gc_record_vtinherit (abfd
, sec
, h
, offset
)
7228 struct elf_link_hash_entry
*h
;
7231 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
7232 struct elf_link_hash_entry
**search
, *child
;
7233 bfd_size_type extsymcount
;
7235 /* The sh_info field of the symtab header tells us where the
7236 external symbols start. We don't care about the local symbols at
7238 extsymcount
= elf_tdata (abfd
)->symtab_hdr
.sh_size
/sizeof (Elf_External_Sym
);
7239 if (!elf_bad_symtab (abfd
))
7240 extsymcount
-= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
7242 sym_hashes
= elf_sym_hashes (abfd
);
7243 sym_hashes_end
= sym_hashes
+ extsymcount
;
7245 /* Hunt down the child symbol, which is in this section at the same
7246 offset as the relocation. */
7247 for (search
= sym_hashes
; search
!= sym_hashes_end
; ++search
)
7249 if ((child
= *search
) != NULL
7250 && (child
->root
.type
== bfd_link_hash_defined
7251 || child
->root
.type
== bfd_link_hash_defweak
)
7252 && child
->root
.u
.def
.section
== sec
7253 && child
->root
.u
.def
.value
== offset
)
7257 (*_bfd_error_handler
) ("%s: %s+%lu: No symbol found for INHERIT",
7258 bfd_get_filename (abfd
), sec
->name
,
7259 (unsigned long) offset
);
7260 bfd_set_error (bfd_error_invalid_operation
);
7266 /* This *should* only be the absolute section. It could potentially
7267 be that someone has defined a non-global vtable though, which
7268 would be bad. It isn't worth paging in the local symbols to be
7269 sure though; that case should simply be handled by the assembler. */
7271 child
->vtable_parent
= (struct elf_link_hash_entry
*) -1;
7274 child
->vtable_parent
= h
;
7279 /* Called from check_relocs to record the existance of a VTENTRY reloc. */
7282 elf_gc_record_vtentry (abfd
, sec
, h
, addend
)
7283 bfd
*abfd ATTRIBUTE_UNUSED
;
7284 asection
*sec ATTRIBUTE_UNUSED
;
7285 struct elf_link_hash_entry
*h
;
7288 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7289 int file_align
= bed
->s
->file_align
;
7291 if (addend
>= h
->vtable_entries_size
)
7294 boolean
*ptr
= h
->vtable_entries_used
;
7296 /* While the symbol is undefined, we have to be prepared to handle
7298 if (h
->root
.type
== bfd_link_hash_undefined
)
7305 /* Oops! We've got a reference past the defined end of
7306 the table. This is probably a bug -- shall we warn? */
7311 /* Allocate one extra entry for use as a "done" flag for the
7312 consolidation pass. */
7313 bytes
= (size
/ file_align
+ 1) * sizeof (boolean
);
7317 ptr
= bfd_realloc (ptr
- 1, bytes
);
7323 oldbytes
= ((h
->vtable_entries_size
/ file_align
+ 1)
7324 * sizeof (boolean
));
7325 memset (((char *) ptr
) + oldbytes
, 0, bytes
- oldbytes
);
7329 ptr
= bfd_zmalloc (bytes
);
7334 /* And arrange for that done flag to be at index -1. */
7335 h
->vtable_entries_used
= ptr
+ 1;
7336 h
->vtable_entries_size
= size
;
7339 h
->vtable_entries_used
[addend
/ file_align
] = true;
7344 /* And an accompanying bit to work out final got entry offsets once
7345 we're done. Should be called from final_link. */
7348 elf_gc_common_finalize_got_offsets (abfd
, info
)
7350 struct bfd_link_info
*info
;
7353 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7356 /* The GOT offset is relative to the .got section, but the GOT header is
7357 put into the .got.plt section, if the backend uses it. */
7358 if (bed
->want_got_plt
)
7361 gotoff
= bed
->got_header_size
;
7363 /* Do the local .got entries first. */
7364 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
7366 bfd_signed_vma
*local_got
;
7367 bfd_size_type j
, locsymcount
;
7368 Elf_Internal_Shdr
*symtab_hdr
;
7370 if (bfd_get_flavour (i
) != bfd_target_elf_flavour
)
7373 local_got
= elf_local_got_refcounts (i
);
7377 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
7378 if (elf_bad_symtab (i
))
7379 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
7381 locsymcount
= symtab_hdr
->sh_info
;
7383 for (j
= 0; j
< locsymcount
; ++j
)
7385 if (local_got
[j
] > 0)
7387 local_got
[j
] = gotoff
;
7388 gotoff
+= ARCH_SIZE
/ 8;
7391 local_got
[j
] = (bfd_vma
) -1;
7395 /* Then the global .got entries. .plt refcounts are handled by
7396 adjust_dynamic_symbol */
7397 elf_link_hash_traverse (elf_hash_table (info
),
7398 elf_gc_allocate_got_offsets
,
7403 /* We need a special top-level link routine to convert got reference counts
7404 to real got offsets. */
7407 elf_gc_allocate_got_offsets (h
, offarg
)
7408 struct elf_link_hash_entry
*h
;
7411 bfd_vma
*off
= (bfd_vma
*) offarg
;
7413 if (h
->got
.refcount
> 0)
7415 h
->got
.offset
= off
[0];
7416 off
[0] += ARCH_SIZE
/ 8;
7419 h
->got
.offset
= (bfd_vma
) -1;
7424 /* Many folk need no more in the way of final link than this, once
7425 got entry reference counting is enabled. */
7428 elf_gc_common_final_link (abfd
, info
)
7430 struct bfd_link_info
*info
;
7432 if (!elf_gc_common_finalize_got_offsets (abfd
, info
))
7435 /* Invoke the regular ELF backend linker to do all the work. */
7436 return elf_bfd_final_link (abfd
, info
);
7439 /* This function will be called though elf_link_hash_traverse to store
7440 all hash value of the exported symbols in an array. */
7443 elf_collect_hash_codes (h
, data
)
7444 struct elf_link_hash_entry
*h
;
7447 unsigned long **valuep
= (unsigned long **) data
;
7453 /* Ignore indirect symbols. These are added by the versioning code. */
7454 if (h
->dynindx
== -1)
7457 name
= h
->root
.root
.string
;
7458 p
= strchr (name
, ELF_VER_CHR
);
7461 alc
= bfd_malloc (p
- name
+ 1);
7462 memcpy (alc
, name
, p
- name
);
7463 alc
[p
- name
] = '\0';
7467 /* Compute the hash value. */
7468 ha
= bfd_elf_hash (name
);
7470 /* Store the found hash value in the array given as the argument. */
7473 /* And store it in the struct so that we can put it in the hash table
7475 h
->elf_hash_value
= ha
;