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
;
920 bed
= get_elf_backend_data (abfd
);
921 add_symbol_hook
= bed
->elf_add_symbol_hook
;
922 collect
= bed
->collect
;
924 if ((abfd
->flags
& DYNAMIC
) == 0)
930 /* You can't use -r against a dynamic object. Also, there's no
931 hope of using a dynamic object which does not exactly match
932 the format of the output file. */
933 if (info
->relocateable
|| info
->hash
->creator
!= abfd
->xvec
)
935 bfd_set_error (bfd_error_invalid_operation
);
940 /* As a GNU extension, any input sections which are named
941 .gnu.warning.SYMBOL are treated as warning symbols for the given
942 symbol. This differs from .gnu.warning sections, which generate
943 warnings when they are included in an output file. */
948 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
952 name
= bfd_get_section_name (abfd
, s
);
953 if (strncmp (name
, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0)
958 name
+= sizeof ".gnu.warning." - 1;
960 /* If this is a shared object, then look up the symbol
961 in the hash table. If it is there, and it is already
962 been defined, then we will not be using the entry
963 from this shared object, so we don't need to warn.
964 FIXME: If we see the definition in a regular object
965 later on, we will warn, but we shouldn't. The only
966 fix is to keep track of what warnings we are supposed
967 to emit, and then handle them all at the end of the
969 if (dynamic
&& abfd
->xvec
== info
->hash
->creator
)
971 struct elf_link_hash_entry
*h
;
973 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
976 /* FIXME: What about bfd_link_hash_common? */
978 && (h
->root
.type
== bfd_link_hash_defined
979 || h
->root
.type
== bfd_link_hash_defweak
))
981 /* We don't want to issue this warning. Clobber
982 the section size so that the warning does not
983 get copied into the output file. */
989 sz
= bfd_section_size (abfd
, s
);
990 msg
= (char *) bfd_alloc (abfd
, sz
+ 1);
994 if (! bfd_get_section_contents (abfd
, s
, msg
, (file_ptr
) 0, sz
))
999 if (! (_bfd_generic_link_add_one_symbol
1000 (info
, abfd
, name
, BSF_WARNING
, s
, (bfd_vma
) 0, msg
,
1001 false, collect
, (struct bfd_link_hash_entry
**) NULL
)))
1004 if (! info
->relocateable
)
1006 /* Clobber the section size so that the warning does
1007 not get copied into the output file. */
1014 /* If this is a dynamic object, we always link against the .dynsym
1015 symbol table, not the .symtab symbol table. The dynamic linker
1016 will only see the .dynsym symbol table, so there is no reason to
1017 look at .symtab for a dynamic object. */
1019 if (! dynamic
|| elf_dynsymtab (abfd
) == 0)
1020 hdr
= &elf_tdata (abfd
)->symtab_hdr
;
1022 hdr
= &elf_tdata (abfd
)->dynsymtab_hdr
;
1026 /* Read in any version definitions. */
1028 if (! _bfd_elf_slurp_version_tables (abfd
))
1031 /* Read in the symbol versions, but don't bother to convert them
1032 to internal format. */
1033 if (elf_dynversym (abfd
) != 0)
1035 Elf_Internal_Shdr
*versymhdr
;
1037 versymhdr
= &elf_tdata (abfd
)->dynversym_hdr
;
1038 extversym
= (Elf_External_Versym
*) bfd_malloc (versymhdr
->sh_size
);
1039 if (extversym
== NULL
)
1041 if (bfd_seek (abfd
, versymhdr
->sh_offset
, SEEK_SET
) != 0
1042 || (bfd_read ((PTR
) extversym
, 1, versymhdr
->sh_size
, abfd
)
1043 != versymhdr
->sh_size
))
1048 symcount
= hdr
->sh_size
/ sizeof (Elf_External_Sym
);
1050 /* The sh_info field of the symtab header tells us where the
1051 external symbols start. We don't care about the local symbols at
1053 if (elf_bad_symtab (abfd
))
1055 extsymcount
= symcount
;
1060 extsymcount
= symcount
- hdr
->sh_info
;
1061 extsymoff
= hdr
->sh_info
;
1064 buf
= ((Elf_External_Sym
*)
1065 bfd_malloc (extsymcount
* sizeof (Elf_External_Sym
)));
1066 if (buf
== NULL
&& extsymcount
!= 0)
1069 /* We store a pointer to the hash table entry for each external
1071 sym_hash
= ((struct elf_link_hash_entry
**)
1073 extsymcount
* sizeof (struct elf_link_hash_entry
*)));
1074 if (sym_hash
== NULL
)
1076 elf_sym_hashes (abfd
) = sym_hash
;
1082 /* If we are creating a shared library, create all the dynamic
1083 sections immediately. We need to attach them to something,
1084 so we attach them to this BFD, provided it is the right
1085 format. FIXME: If there are no input BFD's of the same
1086 format as the output, we can't make a shared library. */
1088 && ! elf_hash_table (info
)->dynamic_sections_created
1089 && abfd
->xvec
== info
->hash
->creator
)
1091 if (! elf_link_create_dynamic_sections (abfd
, info
))
1100 bfd_size_type oldsize
;
1101 bfd_size_type strindex
;
1103 /* Find the name to use in a DT_NEEDED entry that refers to this
1104 object. If the object has a DT_SONAME entry, we use it.
1105 Otherwise, if the generic linker stuck something in
1106 elf_dt_name, we use that. Otherwise, we just use the file
1107 name. If the generic linker put a null string into
1108 elf_dt_name, we don't make a DT_NEEDED entry at all, even if
1109 there is a DT_SONAME entry. */
1111 name
= bfd_get_filename (abfd
);
1112 if (elf_dt_name (abfd
) != NULL
)
1114 name
= elf_dt_name (abfd
);
1117 if (elf_dt_soname (abfd
) != NULL
)
1123 s
= bfd_get_section_by_name (abfd
, ".dynamic");
1126 Elf_External_Dyn
*extdyn
;
1127 Elf_External_Dyn
*extdynend
;
1133 dynbuf
= (Elf_External_Dyn
*) bfd_malloc ((size_t) s
->_raw_size
);
1137 if (! bfd_get_section_contents (abfd
, s
, (PTR
) dynbuf
,
1138 (file_ptr
) 0, s
->_raw_size
))
1141 elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
1144 link
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
1147 /* The shared libraries distributed with hpux11 have a bogus
1148 sh_link field for the ".dynamic" section. This code detects
1149 when LINK refers to a section that is not a string table and
1150 tries to find the string table for the ".dynsym" section
1152 Elf_Internal_Shdr
*hdr
= elf_elfsections (abfd
)[link
];
1153 if (hdr
->sh_type
!= SHT_STRTAB
)
1155 asection
*s
= bfd_get_section_by_name (abfd
, ".dynsym");
1156 int elfsec
= _bfd_elf_section_from_bfd_section (abfd
, s
);
1159 link
= elf_elfsections (abfd
)[elfsec
]->sh_link
;
1164 extdynend
= extdyn
+ s
->_raw_size
/ sizeof (Elf_External_Dyn
);
1167 for (; extdyn
< extdynend
; extdyn
++)
1169 Elf_Internal_Dyn dyn
;
1171 elf_swap_dyn_in (abfd
, extdyn
, &dyn
);
1172 if (dyn
.d_tag
== DT_SONAME
)
1174 name
= bfd_elf_string_from_elf_section (abfd
, link
,
1179 if (dyn
.d_tag
== DT_NEEDED
)
1181 struct bfd_link_needed_list
*n
, **pn
;
1184 n
= ((struct bfd_link_needed_list
*)
1185 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1186 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1188 if (n
== NULL
|| fnm
== NULL
)
1190 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1197 for (pn
= &elf_hash_table (info
)->needed
;
1203 if (dyn
.d_tag
== DT_RUNPATH
)
1205 struct bfd_link_needed_list
*n
, **pn
;
1208 /* When we see DT_RPATH before DT_RUNPATH, we have
1209 to clear runpath. Do _NOT_ bfd_release, as that
1210 frees all more recently bfd_alloc'd blocks as
1212 if (rpath
&& elf_hash_table (info
)->runpath
)
1213 elf_hash_table (info
)->runpath
= NULL
;
1215 n
= ((struct bfd_link_needed_list
*)
1216 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1217 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1219 if (n
== NULL
|| fnm
== NULL
)
1221 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1228 for (pn
= &elf_hash_table (info
)->runpath
;
1236 /* Ignore DT_RPATH if we have seen DT_RUNPATH. */
1237 if (!runpath
&& dyn
.d_tag
== DT_RPATH
)
1239 struct bfd_link_needed_list
*n
, **pn
;
1242 n
= ((struct bfd_link_needed_list
*)
1243 bfd_alloc (abfd
, sizeof (struct bfd_link_needed_list
)));
1244 fnm
= bfd_elf_string_from_elf_section (abfd
, link
,
1246 if (n
== NULL
|| fnm
== NULL
)
1248 anm
= bfd_alloc (abfd
, strlen (fnm
) + 1);
1255 for (pn
= &elf_hash_table (info
)->runpath
;
1268 /* We do not want to include any of the sections in a dynamic
1269 object in the output file. We hack by simply clobbering the
1270 list of sections in the BFD. This could be handled more
1271 cleanly by, say, a new section flag; the existing
1272 SEC_NEVER_LOAD flag is not the one we want, because that one
1273 still implies that the section takes up space in the output
1275 abfd
->sections
= NULL
;
1276 abfd
->section_count
= 0;
1278 /* If this is the first dynamic object found in the link, create
1279 the special sections required for dynamic linking. */
1280 if (! elf_hash_table (info
)->dynamic_sections_created
)
1282 if (! elf_link_create_dynamic_sections (abfd
, info
))
1288 /* Add a DT_NEEDED entry for this dynamic object. */
1289 oldsize
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
1290 strindex
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
, name
,
1292 if (strindex
== (bfd_size_type
) -1)
1295 if (oldsize
== _bfd_stringtab_size (elf_hash_table (info
)->dynstr
))
1298 Elf_External_Dyn
*dyncon
, *dynconend
;
1300 /* The hash table size did not change, which means that
1301 the dynamic object name was already entered. If we
1302 have already included this dynamic object in the
1303 link, just ignore it. There is no reason to include
1304 a particular dynamic object more than once. */
1305 sdyn
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
,
1307 BFD_ASSERT (sdyn
!= NULL
);
1309 dyncon
= (Elf_External_Dyn
*) sdyn
->contents
;
1310 dynconend
= (Elf_External_Dyn
*) (sdyn
->contents
+
1312 for (; dyncon
< dynconend
; dyncon
++)
1314 Elf_Internal_Dyn dyn
;
1316 elf_swap_dyn_in (elf_hash_table (info
)->dynobj
, dyncon
,
1318 if (dyn
.d_tag
== DT_NEEDED
1319 && dyn
.d_un
.d_val
== strindex
)
1323 if (extversym
!= NULL
)
1330 if (! elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
1334 /* Save the SONAME, if there is one, because sometimes the
1335 linker emulation code will need to know it. */
1337 name
= basename (bfd_get_filename (abfd
));
1338 elf_dt_name (abfd
) = name
;
1342 hdr
->sh_offset
+ extsymoff
* sizeof (Elf_External_Sym
),
1344 || (bfd_read ((PTR
) buf
, sizeof (Elf_External_Sym
), extsymcount
, abfd
)
1345 != extsymcount
* sizeof (Elf_External_Sym
)))
1350 ever
= extversym
!= NULL
? extversym
+ extsymoff
: NULL
;
1351 esymend
= buf
+ extsymcount
;
1354 esym
++, sym_hash
++, ever
= (ever
!= NULL
? ever
+ 1 : NULL
))
1356 Elf_Internal_Sym sym
;
1362 struct elf_link_hash_entry
*h
;
1364 boolean size_change_ok
, type_change_ok
;
1365 boolean new_weakdef
;
1366 unsigned int old_alignment
;
1368 elf_swap_symbol_in (abfd
, esym
, &sym
);
1370 flags
= BSF_NO_FLAGS
;
1372 value
= sym
.st_value
;
1375 bind
= ELF_ST_BIND (sym
.st_info
);
1376 if (bind
== STB_LOCAL
)
1378 /* This should be impossible, since ELF requires that all
1379 global symbols follow all local symbols, and that sh_info
1380 point to the first global symbol. Unfortunatealy, Irix 5
1384 else if (bind
== STB_GLOBAL
)
1386 if (sym
.st_shndx
!= SHN_UNDEF
1387 && sym
.st_shndx
!= SHN_COMMON
)
1390 else if (bind
== STB_WEAK
)
1394 /* Leave it up to the processor backend. */
1397 if (sym
.st_shndx
== SHN_UNDEF
)
1398 sec
= bfd_und_section_ptr
;
1399 else if (sym
.st_shndx
> 0 && sym
.st_shndx
< SHN_LORESERVE
)
1401 sec
= section_from_elf_index (abfd
, sym
.st_shndx
);
1403 sec
= bfd_abs_section_ptr
;
1404 else if ((abfd
->flags
& (EXEC_P
| DYNAMIC
)) != 0)
1407 else if (sym
.st_shndx
== SHN_ABS
)
1408 sec
= bfd_abs_section_ptr
;
1409 else if (sym
.st_shndx
== SHN_COMMON
)
1411 sec
= bfd_com_section_ptr
;
1412 /* What ELF calls the size we call the value. What ELF
1413 calls the value we call the alignment. */
1414 value
= sym
.st_size
;
1418 /* Leave it up to the processor backend. */
1421 name
= bfd_elf_string_from_elf_section (abfd
, hdr
->sh_link
, sym
.st_name
);
1422 if (name
== (const char *) NULL
)
1425 if (add_symbol_hook
)
1427 if (! (*add_symbol_hook
) (abfd
, info
, &sym
, &name
, &flags
, &sec
,
1431 /* The hook function sets the name to NULL if this symbol
1432 should be skipped for some reason. */
1433 if (name
== (const char *) NULL
)
1437 /* Sanity check that all possibilities were handled. */
1438 if (sec
== (asection
*) NULL
)
1440 bfd_set_error (bfd_error_bad_value
);
1444 if (bfd_is_und_section (sec
)
1445 || bfd_is_com_section (sec
))
1450 size_change_ok
= false;
1451 type_change_ok
= get_elf_backend_data (abfd
)->type_change_ok
;
1453 if (info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
1455 Elf_Internal_Versym iver
;
1456 unsigned int vernum
= 0;
1461 _bfd_elf_swap_versym_in (abfd
, ever
, &iver
);
1462 vernum
= iver
.vs_vers
& VERSYM_VERSION
;
1464 /* If this is a hidden symbol, or if it is not version
1465 1, we append the version name to the symbol name.
1466 However, we do not modify a non-hidden absolute
1467 symbol, because it might be the version symbol
1468 itself. FIXME: What if it isn't? */
1469 if ((iver
.vs_vers
& VERSYM_HIDDEN
) != 0
1470 || (vernum
> 1 && ! bfd_is_abs_section (sec
)))
1473 int namelen
, newlen
;
1476 if (sym
.st_shndx
!= SHN_UNDEF
)
1478 if (vernum
> elf_tdata (abfd
)->dynverdef_hdr
.sh_info
)
1480 (*_bfd_error_handler
)
1481 (_("%s: %s: invalid version %u (max %d)"),
1482 bfd_get_filename (abfd
), name
, vernum
,
1483 elf_tdata (abfd
)->dynverdef_hdr
.sh_info
);
1484 bfd_set_error (bfd_error_bad_value
);
1487 else if (vernum
> 1)
1489 elf_tdata (abfd
)->verdef
[vernum
- 1].vd_nodename
;
1495 /* We cannot simply test for the number of
1496 entries in the VERNEED section since the
1497 numbers for the needed versions do not start
1499 Elf_Internal_Verneed
*t
;
1502 for (t
= elf_tdata (abfd
)->verref
;
1506 Elf_Internal_Vernaux
*a
;
1508 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
1510 if (a
->vna_other
== vernum
)
1512 verstr
= a
->vna_nodename
;
1521 (*_bfd_error_handler
)
1522 (_("%s: %s: invalid needed version %d"),
1523 bfd_get_filename (abfd
), name
, vernum
);
1524 bfd_set_error (bfd_error_bad_value
);
1529 namelen
= strlen (name
);
1530 newlen
= namelen
+ strlen (verstr
) + 2;
1531 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0)
1534 newname
= (char *) bfd_alloc (abfd
, newlen
);
1535 if (newname
== NULL
)
1537 strcpy (newname
, name
);
1538 p
= newname
+ namelen
;
1540 /* If this is a defined non-hidden version symbol,
1541 we add another @ to the name. This indicates the
1542 default version of the symbol. */
1543 if ((iver
.vs_vers
& VERSYM_HIDDEN
) == 0
1544 && sym
.st_shndx
!= SHN_UNDEF
)
1552 if (! elf_merge_symbol (abfd
, info
, name
, &sym
, &sec
, &value
,
1553 sym_hash
, &override
, &type_change_ok
,
1554 &size_change_ok
, dt_needed
))
1561 while (h
->root
.type
== bfd_link_hash_indirect
1562 || h
->root
.type
== bfd_link_hash_warning
)
1563 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1565 /* Remember the old alignment if this is a common symbol, so
1566 that we don't reduce the alignment later on. We can't
1567 check later, because _bfd_generic_link_add_one_symbol
1568 will set a default for the alignment which we want to
1570 if (h
->root
.type
== bfd_link_hash_common
)
1571 old_alignment
= h
->root
.u
.c
.p
->alignment_power
;
1573 if (elf_tdata (abfd
)->verdef
!= NULL
1577 h
->verinfo
.verdef
= &elf_tdata (abfd
)->verdef
[vernum
- 1];
1580 if (! (_bfd_generic_link_add_one_symbol
1581 (info
, abfd
, name
, flags
, sec
, value
, (const char *) NULL
,
1582 false, collect
, (struct bfd_link_hash_entry
**) sym_hash
)))
1586 while (h
->root
.type
== bfd_link_hash_indirect
1587 || h
->root
.type
== bfd_link_hash_warning
)
1588 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1591 new_weakdef
= false;
1594 && (flags
& BSF_WEAK
) != 0
1595 && ELF_ST_TYPE (sym
.st_info
) != STT_FUNC
1596 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
1597 && h
->weakdef
== NULL
)
1599 /* Keep a list of all weak defined non function symbols from
1600 a dynamic object, using the weakdef field. Later in this
1601 function we will set the weakdef field to the correct
1602 value. We only put non-function symbols from dynamic
1603 objects on this list, because that happens to be the only
1604 time we need to know the normal symbol corresponding to a
1605 weak symbol, and the information is time consuming to
1606 figure out. If the weakdef field is not already NULL,
1607 then this symbol was already defined by some previous
1608 dynamic object, and we will be using that previous
1609 definition anyhow. */
1616 /* Set the alignment of a common symbol. */
1617 if (sym
.st_shndx
== SHN_COMMON
1618 && h
->root
.type
== bfd_link_hash_common
)
1622 align
= bfd_log2 (sym
.st_value
);
1623 if (align
> old_alignment
1624 /* Permit an alignment power of zero if an alignment of one
1625 is specified and no other alignments have been specified. */
1626 || (sym
.st_value
== 1 && old_alignment
== 0))
1627 h
->root
.u
.c
.p
->alignment_power
= align
;
1630 if (info
->hash
->creator
->flavour
== bfd_target_elf_flavour
)
1636 /* Remember the symbol size and type. */
1637 if (sym
.st_size
!= 0
1638 && (definition
|| h
->size
== 0))
1640 if (h
->size
!= 0 && h
->size
!= sym
.st_size
&& ! size_change_ok
)
1641 (*_bfd_error_handler
)
1642 (_("Warning: size of symbol `%s' changed from %lu to %lu in %s"),
1643 name
, (unsigned long) h
->size
, (unsigned long) sym
.st_size
,
1644 bfd_get_filename (abfd
));
1646 h
->size
= sym
.st_size
;
1649 /* If this is a common symbol, then we always want H->SIZE
1650 to be the size of the common symbol. The code just above
1651 won't fix the size if a common symbol becomes larger. We
1652 don't warn about a size change here, because that is
1653 covered by --warn-common. */
1654 if (h
->root
.type
== bfd_link_hash_common
)
1655 h
->size
= h
->root
.u
.c
.size
;
1657 if (ELF_ST_TYPE (sym
.st_info
) != STT_NOTYPE
1658 && (definition
|| h
->type
== STT_NOTYPE
))
1660 if (h
->type
!= STT_NOTYPE
1661 && h
->type
!= ELF_ST_TYPE (sym
.st_info
)
1662 && ! type_change_ok
)
1663 (*_bfd_error_handler
)
1664 (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
1665 name
, h
->type
, ELF_ST_TYPE (sym
.st_info
),
1666 bfd_get_filename (abfd
));
1668 h
->type
= ELF_ST_TYPE (sym
.st_info
);
1671 /* If st_other has a processor-specific meaning, specific code
1672 might be needed here. */
1673 if (sym
.st_other
!= 0)
1675 /* Combine visibilities, using the most constraining one. */
1676 unsigned char hvis
= ELF_ST_VISIBILITY (h
->other
);
1677 unsigned char symvis
= ELF_ST_VISIBILITY (sym
.st_other
);
1679 if (symvis
&& (hvis
> symvis
|| hvis
== 0))
1680 h
->other
= sym
.st_other
;
1682 /* If neither has visibility, use the st_other of the
1683 definition. This is an arbitrary choice, since the
1684 other bits have no general meaning. */
1685 if (!symvis
&& !hvis
1686 && (definition
|| h
->other
== 0))
1687 h
->other
= sym
.st_other
;
1690 /* Set a flag in the hash table entry indicating the type of
1691 reference or definition we just found. Keep a count of
1692 the number of dynamic symbols we find. A dynamic symbol
1693 is one which is referenced or defined by both a regular
1694 object and a shared object. */
1695 old_flags
= h
->elf_link_hash_flags
;
1701 new_flag
= ELF_LINK_HASH_REF_REGULAR
;
1702 if (bind
!= STB_WEAK
)
1703 new_flag
|= ELF_LINK_HASH_REF_REGULAR_NONWEAK
;
1706 new_flag
= ELF_LINK_HASH_DEF_REGULAR
;
1708 || (old_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
1709 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0)
1715 new_flag
= ELF_LINK_HASH_REF_DYNAMIC
;
1717 new_flag
= ELF_LINK_HASH_DEF_DYNAMIC
;
1718 if ((old_flags
& (ELF_LINK_HASH_DEF_REGULAR
1719 | ELF_LINK_HASH_REF_REGULAR
)) != 0
1720 || (h
->weakdef
!= NULL
1722 && h
->weakdef
->dynindx
!= -1))
1726 h
->elf_link_hash_flags
|= new_flag
;
1728 /* If this symbol has a version, and it is the default
1729 version, we create an indirect symbol from the default
1730 name to the fully decorated name. This will cause
1731 external references which do not specify a version to be
1732 bound to this version of the symbol. */
1733 if (definition
|| h
->root
.type
== bfd_link_hash_common
)
1737 p
= strchr (name
, ELF_VER_CHR
);
1738 if (p
!= NULL
&& p
[1] == ELF_VER_CHR
)
1741 struct elf_link_hash_entry
*hi
;
1744 shortname
= bfd_hash_allocate (&info
->hash
->table
,
1746 if (shortname
== NULL
)
1748 strncpy (shortname
, name
, p
- name
);
1749 shortname
[p
- name
] = '\0';
1751 /* We are going to create a new symbol. Merge it
1752 with any existing symbol with this name. For the
1753 purposes of the merge, act as though we were
1754 defining the symbol we just defined, although we
1755 actually going to define an indirect symbol. */
1756 type_change_ok
= false;
1757 size_change_ok
= false;
1758 if (! elf_merge_symbol (abfd
, info
, shortname
, &sym
, &sec
,
1759 &value
, &hi
, &override
,
1761 &size_change_ok
, dt_needed
))
1766 if (! (_bfd_generic_link_add_one_symbol
1767 (info
, abfd
, shortname
, BSF_INDIRECT
,
1768 bfd_ind_section_ptr
, (bfd_vma
) 0, name
, false,
1769 collect
, (struct bfd_link_hash_entry
**) &hi
)))
1774 /* In this case the symbol named SHORTNAME is
1775 overriding the indirect symbol we want to
1776 add. We were planning on making SHORTNAME an
1777 indirect symbol referring to NAME. SHORTNAME
1778 is the name without a version. NAME is the
1779 fully versioned name, and it is the default
1782 Overriding means that we already saw a
1783 definition for the symbol SHORTNAME in a
1784 regular object, and it is overriding the
1785 symbol defined in the dynamic object.
1787 When this happens, we actually want to change
1788 NAME, the symbol we just added, to refer to
1789 SHORTNAME. This will cause references to
1790 NAME in the shared object to become
1791 references to SHORTNAME in the regular
1792 object. This is what we expect when we
1793 override a function in a shared object: that
1794 the references in the shared object will be
1795 mapped to the definition in the regular
1798 while (hi
->root
.type
== bfd_link_hash_indirect
1799 || hi
->root
.type
== bfd_link_hash_warning
)
1800 hi
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1802 h
->root
.type
= bfd_link_hash_indirect
;
1803 h
->root
.u
.i
.link
= (struct bfd_link_hash_entry
*) hi
;
1804 if (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
)
1806 h
->elf_link_hash_flags
&=~ ELF_LINK_HASH_DEF_DYNAMIC
;
1807 hi
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_DYNAMIC
;
1808 if (hi
->elf_link_hash_flags
1809 & (ELF_LINK_HASH_REF_REGULAR
1810 | ELF_LINK_HASH_DEF_REGULAR
))
1812 if (! _bfd_elf_link_record_dynamic_symbol (info
,
1818 /* Now set HI to H, so that the following code
1819 will set the other fields correctly. */
1823 /* If there is a duplicate definition somewhere,
1824 then HI may not point to an indirect symbol. We
1825 will have reported an error to the user in that
1828 if (hi
->root
.type
== bfd_link_hash_indirect
)
1830 struct elf_link_hash_entry
*ht
;
1832 /* If the symbol became indirect, then we assume
1833 that we have not seen a definition before. */
1834 BFD_ASSERT ((hi
->elf_link_hash_flags
1835 & (ELF_LINK_HASH_DEF_DYNAMIC
1836 | ELF_LINK_HASH_DEF_REGULAR
))
1839 ht
= (struct elf_link_hash_entry
*) hi
->root
.u
.i
.link
;
1840 (*bed
->elf_backend_copy_indirect_symbol
) (ht
, hi
);
1842 /* See if the new flags lead us to realize that
1843 the symbol must be dynamic. */
1849 || ((hi
->elf_link_hash_flags
1850 & ELF_LINK_HASH_REF_DYNAMIC
)
1856 if ((hi
->elf_link_hash_flags
1857 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1863 /* We also need to define an indirection from the
1864 nondefault version of the symbol. */
1866 shortname
= bfd_hash_allocate (&info
->hash
->table
,
1868 if (shortname
== NULL
)
1870 strncpy (shortname
, name
, p
- name
);
1871 strcpy (shortname
+ (p
- name
), p
+ 1);
1873 /* Once again, merge with any existing symbol. */
1874 type_change_ok
= false;
1875 size_change_ok
= false;
1876 if (! elf_merge_symbol (abfd
, info
, shortname
, &sym
, &sec
,
1877 &value
, &hi
, &override
,
1879 &size_change_ok
, dt_needed
))
1884 /* Here SHORTNAME is a versioned name, so we
1885 don't expect to see the type of override we
1886 do in the case above. */
1887 (*_bfd_error_handler
)
1888 (_("%s: warning: unexpected redefinition of `%s'"),
1889 bfd_get_filename (abfd
), shortname
);
1893 if (! (_bfd_generic_link_add_one_symbol
1894 (info
, abfd
, shortname
, BSF_INDIRECT
,
1895 bfd_ind_section_ptr
, (bfd_vma
) 0, name
, false,
1896 collect
, (struct bfd_link_hash_entry
**) &hi
)))
1899 /* If there is a duplicate definition somewhere,
1900 then HI may not point to an indirect symbol.
1901 We will have reported an error to the user in
1904 if (hi
->root
.type
== bfd_link_hash_indirect
)
1906 /* If the symbol became indirect, then we
1907 assume that we have not seen a definition
1909 BFD_ASSERT ((hi
->elf_link_hash_flags
1910 & (ELF_LINK_HASH_DEF_DYNAMIC
1911 | ELF_LINK_HASH_DEF_REGULAR
))
1914 (*bed
->elf_backend_copy_indirect_symbol
) (h
, hi
);
1916 /* See if the new flags lead us to realize
1917 that the symbol must be dynamic. */
1923 || ((hi
->elf_link_hash_flags
1924 & ELF_LINK_HASH_REF_DYNAMIC
)
1930 if ((hi
->elf_link_hash_flags
1931 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1940 if (dynsym
&& h
->dynindx
== -1)
1942 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
1944 if (h
->weakdef
!= NULL
1946 && h
->weakdef
->dynindx
== -1)
1948 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
1952 else if (dynsym
&& h
->dynindx
!= -1)
1953 /* If the symbol already has a dynamic index, but
1954 visibility says it should not be visible, turn it into
1956 switch (ELF_ST_VISIBILITY (h
->other
))
1960 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
1961 (*bed
->elf_backend_hide_symbol
) (info
, h
);
1965 if (dt_needed
&& definition
1966 && (h
->elf_link_hash_flags
1967 & ELF_LINK_HASH_REF_REGULAR
) != 0)
1969 bfd_size_type oldsize
;
1970 bfd_size_type strindex
;
1972 /* The symbol from a DT_NEEDED object is referenced from
1973 the regular object to create a dynamic executable. We
1974 have to make sure there is a DT_NEEDED entry for it. */
1977 oldsize
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
1978 strindex
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
1979 elf_dt_soname (abfd
),
1981 if (strindex
== (bfd_size_type
) -1)
1985 == _bfd_stringtab_size (elf_hash_table (info
)->dynstr
))
1988 Elf_External_Dyn
*dyncon
, *dynconend
;
1990 sdyn
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
,
1992 BFD_ASSERT (sdyn
!= NULL
);
1994 dyncon
= (Elf_External_Dyn
*) sdyn
->contents
;
1995 dynconend
= (Elf_External_Dyn
*) (sdyn
->contents
+
1997 for (; dyncon
< dynconend
; dyncon
++)
1999 Elf_Internal_Dyn dyn
;
2001 elf_swap_dyn_in (elf_hash_table (info
)->dynobj
,
2003 BFD_ASSERT (dyn
.d_tag
!= DT_NEEDED
||
2004 dyn
.d_un
.d_val
!= strindex
);
2008 if (! elf_add_dynamic_entry (info
, DT_NEEDED
, strindex
))
2014 /* Now set the weakdefs field correctly for all the weak defined
2015 symbols we found. The only way to do this is to search all the
2016 symbols. Since we only need the information for non functions in
2017 dynamic objects, that's the only time we actually put anything on
2018 the list WEAKS. We need this information so that if a regular
2019 object refers to a symbol defined weakly in a dynamic object, the
2020 real symbol in the dynamic object is also put in the dynamic
2021 symbols; we also must arrange for both symbols to point to the
2022 same memory location. We could handle the general case of symbol
2023 aliasing, but a general symbol alias can only be generated in
2024 assembler code, handling it correctly would be very time
2025 consuming, and other ELF linkers don't handle general aliasing
2027 while (weaks
!= NULL
)
2029 struct elf_link_hash_entry
*hlook
;
2032 struct elf_link_hash_entry
**hpp
;
2033 struct elf_link_hash_entry
**hppend
;
2036 weaks
= hlook
->weakdef
;
2037 hlook
->weakdef
= NULL
;
2039 BFD_ASSERT (hlook
->root
.type
== bfd_link_hash_defined
2040 || hlook
->root
.type
== bfd_link_hash_defweak
2041 || hlook
->root
.type
== bfd_link_hash_common
2042 || hlook
->root
.type
== bfd_link_hash_indirect
);
2043 slook
= hlook
->root
.u
.def
.section
;
2044 vlook
= hlook
->root
.u
.def
.value
;
2046 hpp
= elf_sym_hashes (abfd
);
2047 hppend
= hpp
+ extsymcount
;
2048 for (; hpp
< hppend
; hpp
++)
2050 struct elf_link_hash_entry
*h
;
2053 if (h
!= NULL
&& h
!= hlook
2054 && h
->root
.type
== bfd_link_hash_defined
2055 && h
->root
.u
.def
.section
== slook
2056 && h
->root
.u
.def
.value
== vlook
)
2060 /* If the weak definition is in the list of dynamic
2061 symbols, make sure the real definition is put there
2063 if (hlook
->dynindx
!= -1
2064 && h
->dynindx
== -1)
2066 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2070 /* If the real definition is in the list of dynamic
2071 symbols, make sure the weak definition is put there
2072 as well. If we don't do this, then the dynamic
2073 loader might not merge the entries for the real
2074 definition and the weak definition. */
2075 if (h
->dynindx
!= -1
2076 && hlook
->dynindx
== -1)
2078 if (! _bfd_elf_link_record_dynamic_symbol (info
, hlook
))
2093 if (extversym
!= NULL
)
2099 /* If this object is the same format as the output object, and it is
2100 not a shared library, then let the backend look through the
2103 This is required to build global offset table entries and to
2104 arrange for dynamic relocs. It is not required for the
2105 particular common case of linking non PIC code, even when linking
2106 against shared libraries, but unfortunately there is no way of
2107 knowing whether an object file has been compiled PIC or not.
2108 Looking through the relocs is not particularly time consuming.
2109 The problem is that we must either (1) keep the relocs in memory,
2110 which causes the linker to require additional runtime memory or
2111 (2) read the relocs twice from the input file, which wastes time.
2112 This would be a good case for using mmap.
2114 I have no idea how to handle linking PIC code into a file of a
2115 different format. It probably can't be done. */
2116 check_relocs
= get_elf_backend_data (abfd
)->check_relocs
;
2118 && abfd
->xvec
== info
->hash
->creator
2119 && check_relocs
!= NULL
)
2123 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2125 Elf_Internal_Rela
*internal_relocs
;
2128 if ((o
->flags
& SEC_RELOC
) == 0
2129 || o
->reloc_count
== 0
2130 || ((info
->strip
== strip_all
|| info
->strip
== strip_debugger
)
2131 && (o
->flags
& SEC_DEBUGGING
) != 0)
2132 || bfd_is_abs_section (o
->output_section
))
2135 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
2136 (abfd
, o
, (PTR
) NULL
,
2137 (Elf_Internal_Rela
*) NULL
,
2138 info
->keep_memory
));
2139 if (internal_relocs
== NULL
)
2142 ok
= (*check_relocs
) (abfd
, info
, o
, internal_relocs
);
2144 if (! info
->keep_memory
)
2145 free (internal_relocs
);
2152 /* If this is a non-traditional, non-relocateable link, try to
2153 optimize the handling of the .stab/.stabstr sections. */
2155 && ! info
->relocateable
2156 && ! info
->traditional_format
2157 && info
->hash
->creator
->flavour
== bfd_target_elf_flavour
2158 && (info
->strip
!= strip_all
&& info
->strip
!= strip_debugger
))
2160 asection
*stab
, *stabstr
;
2162 stab
= bfd_get_section_by_name (abfd
, ".stab");
2165 stabstr
= bfd_get_section_by_name (abfd
, ".stabstr");
2167 if (stabstr
!= NULL
)
2169 struct bfd_elf_section_data
*secdata
;
2171 secdata
= elf_section_data (stab
);
2172 if (! _bfd_link_section_stabs (abfd
,
2173 &elf_hash_table (info
)->stab_info
,
2175 &secdata
->stab_info
))
2181 if (! info
->relocateable
&& ! dynamic
)
2185 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
2186 if ((s
->flags
& SEC_MERGE
)
2187 && ! _bfd_merge_section (abfd
,
2188 &elf_hash_table (info
)->merge_info
,
2189 s
, &elf_section_data (s
)->merge_info
))
2200 if (extversym
!= NULL
)
2205 /* Create some sections which will be filled in with dynamic linking
2206 information. ABFD is an input file which requires dynamic sections
2207 to be created. The dynamic sections take up virtual memory space
2208 when the final executable is run, so we need to create them before
2209 addresses are assigned to the output sections. We work out the
2210 actual contents and size of these sections later. */
2213 elf_link_create_dynamic_sections (abfd
, info
)
2215 struct bfd_link_info
*info
;
2218 register asection
*s
;
2219 struct elf_link_hash_entry
*h
;
2220 struct elf_backend_data
*bed
;
2222 if (elf_hash_table (info
)->dynamic_sections_created
)
2225 /* Make sure that all dynamic sections use the same input BFD. */
2226 if (elf_hash_table (info
)->dynobj
== NULL
)
2227 elf_hash_table (info
)->dynobj
= abfd
;
2229 abfd
= elf_hash_table (info
)->dynobj
;
2231 /* Note that we set the SEC_IN_MEMORY flag for all of these
2233 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
2234 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
2236 /* A dynamically linked executable has a .interp section, but a
2237 shared library does not. */
2240 s
= bfd_make_section (abfd
, ".interp");
2242 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
2246 /* Create sections to hold version informations. These are removed
2247 if they are not needed. */
2248 s
= bfd_make_section (abfd
, ".gnu.version_d");
2250 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2251 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2254 s
= bfd_make_section (abfd
, ".gnu.version");
2256 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2257 || ! bfd_set_section_alignment (abfd
, s
, 1))
2260 s
= bfd_make_section (abfd
, ".gnu.version_r");
2262 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2263 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2266 s
= bfd_make_section (abfd
, ".dynsym");
2268 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2269 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2272 s
= bfd_make_section (abfd
, ".dynstr");
2274 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
))
2277 /* Create a strtab to hold the dynamic symbol names. */
2278 if (elf_hash_table (info
)->dynstr
== NULL
)
2280 elf_hash_table (info
)->dynstr
= elf_stringtab_init ();
2281 if (elf_hash_table (info
)->dynstr
== NULL
)
2285 s
= bfd_make_section (abfd
, ".dynamic");
2287 || ! bfd_set_section_flags (abfd
, s
, flags
)
2288 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2291 /* The special symbol _DYNAMIC is always set to the start of the
2292 .dynamic section. This call occurs before we have processed the
2293 symbols for any dynamic object, so we don't have to worry about
2294 overriding a dynamic definition. We could set _DYNAMIC in a
2295 linker script, but we only want to define it if we are, in fact,
2296 creating a .dynamic section. We don't want to define it if there
2297 is no .dynamic section, since on some ELF platforms the start up
2298 code examines it to decide how to initialize the process. */
2300 if (! (_bfd_generic_link_add_one_symbol
2301 (info
, abfd
, "_DYNAMIC", BSF_GLOBAL
, s
, (bfd_vma
) 0,
2302 (const char *) NULL
, false, get_elf_backend_data (abfd
)->collect
,
2303 (struct bfd_link_hash_entry
**) &h
)))
2305 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2306 h
->type
= STT_OBJECT
;
2309 && ! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2312 bed
= get_elf_backend_data (abfd
);
2314 s
= bfd_make_section (abfd
, ".hash");
2316 || ! bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
2317 || ! bfd_set_section_alignment (abfd
, s
, LOG_FILE_ALIGN
))
2319 elf_section_data (s
)->this_hdr
.sh_entsize
= bed
->s
->sizeof_hash_entry
;
2321 /* Let the backend create the rest of the sections. This lets the
2322 backend set the right flags. The backend will normally create
2323 the .got and .plt sections. */
2324 if (! (*bed
->elf_backend_create_dynamic_sections
) (abfd
, info
))
2327 elf_hash_table (info
)->dynamic_sections_created
= true;
2332 /* Add an entry to the .dynamic table. */
2335 elf_add_dynamic_entry (info
, tag
, val
)
2336 struct bfd_link_info
*info
;
2340 Elf_Internal_Dyn dyn
;
2344 bfd_byte
*newcontents
;
2346 dynobj
= elf_hash_table (info
)->dynobj
;
2348 s
= bfd_get_section_by_name (dynobj
, ".dynamic");
2349 BFD_ASSERT (s
!= NULL
);
2351 newsize
= s
->_raw_size
+ sizeof (Elf_External_Dyn
);
2352 newcontents
= (bfd_byte
*) bfd_realloc (s
->contents
, newsize
);
2353 if (newcontents
== NULL
)
2357 dyn
.d_un
.d_val
= val
;
2358 elf_swap_dyn_out (dynobj
, &dyn
,
2359 (Elf_External_Dyn
*) (newcontents
+ s
->_raw_size
));
2361 s
->_raw_size
= newsize
;
2362 s
->contents
= newcontents
;
2367 /* Record a new local dynamic symbol. */
2370 elf_link_record_local_dynamic_symbol (info
, input_bfd
, input_indx
)
2371 struct bfd_link_info
*info
;
2375 struct elf_link_local_dynamic_entry
*entry
;
2376 struct elf_link_hash_table
*eht
;
2377 struct bfd_strtab_hash
*dynstr
;
2378 Elf_External_Sym esym
;
2379 unsigned long dynstr_index
;
2382 /* See if the entry exists already. */
2383 for (entry
= elf_hash_table (info
)->dynlocal
; entry
; entry
= entry
->next
)
2384 if (entry
->input_bfd
== input_bfd
&& entry
->input_indx
== input_indx
)
2387 entry
= (struct elf_link_local_dynamic_entry
*)
2388 bfd_alloc (input_bfd
, sizeof (*entry
));
2392 /* Go find the symbol, so that we can find it's name. */
2393 if (bfd_seek (input_bfd
,
2394 (elf_tdata (input_bfd
)->symtab_hdr
.sh_offset
2395 + input_indx
* sizeof (Elf_External_Sym
)),
2397 || (bfd_read (&esym
, sizeof (Elf_External_Sym
), 1, input_bfd
)
2398 != sizeof (Elf_External_Sym
)))
2400 elf_swap_symbol_in (input_bfd
, &esym
, &entry
->isym
);
2402 name
= (bfd_elf_string_from_elf_section
2403 (input_bfd
, elf_tdata (input_bfd
)->symtab_hdr
.sh_link
,
2404 entry
->isym
.st_name
));
2406 dynstr
= elf_hash_table (info
)->dynstr
;
2409 /* Create a strtab to hold the dynamic symbol names. */
2410 elf_hash_table (info
)->dynstr
= dynstr
= _bfd_elf_stringtab_init ();
2415 dynstr_index
= _bfd_stringtab_add (dynstr
, name
, true, false);
2416 if (dynstr_index
== (unsigned long) -1)
2418 entry
->isym
.st_name
= dynstr_index
;
2420 eht
= elf_hash_table (info
);
2422 entry
->next
= eht
->dynlocal
;
2423 eht
->dynlocal
= entry
;
2424 entry
->input_bfd
= input_bfd
;
2425 entry
->input_indx
= input_indx
;
2428 /* Whatever binding the symbol had before, it's now local. */
2430 = ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (entry
->isym
.st_info
));
2432 /* The dynindx will be set at the end of size_dynamic_sections. */
2437 /* Read and swap the relocs from the section indicated by SHDR. This
2438 may be either a REL or a RELA section. The relocations are
2439 translated into RELA relocations and stored in INTERNAL_RELOCS,
2440 which should have already been allocated to contain enough space.
2441 The EXTERNAL_RELOCS are a buffer where the external form of the
2442 relocations should be stored.
2444 Returns false if something goes wrong. */
2447 elf_link_read_relocs_from_section (abfd
, shdr
, external_relocs
,
2450 Elf_Internal_Shdr
*shdr
;
2451 PTR external_relocs
;
2452 Elf_Internal_Rela
*internal_relocs
;
2454 struct elf_backend_data
*bed
;
2456 /* If there aren't any relocations, that's OK. */
2460 /* Position ourselves at the start of the section. */
2461 if (bfd_seek (abfd
, shdr
->sh_offset
, SEEK_SET
) != 0)
2464 /* Read the relocations. */
2465 if (bfd_read (external_relocs
, 1, shdr
->sh_size
, abfd
)
2469 bed
= get_elf_backend_data (abfd
);
2471 /* Convert the external relocations to the internal format. */
2472 if (shdr
->sh_entsize
== sizeof (Elf_External_Rel
))
2474 Elf_External_Rel
*erel
;
2475 Elf_External_Rel
*erelend
;
2476 Elf_Internal_Rela
*irela
;
2477 Elf_Internal_Rel
*irel
;
2479 erel
= (Elf_External_Rel
*) external_relocs
;
2480 erelend
= erel
+ NUM_SHDR_ENTRIES (shdr
);
2481 irela
= internal_relocs
;
2482 irel
= bfd_alloc (abfd
, (bed
->s
->int_rels_per_ext_rel
2483 * sizeof (Elf_Internal_Rel
)));
2484 for (; erel
< erelend
; erel
++, irela
+= bed
->s
->int_rels_per_ext_rel
)
2488 if (bed
->s
->swap_reloc_in
)
2489 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, irel
);
2491 elf_swap_reloc_in (abfd
, erel
, irel
);
2493 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; ++i
)
2495 irela
[i
].r_offset
= irel
[i
].r_offset
;
2496 irela
[i
].r_info
= irel
[i
].r_info
;
2497 irela
[i
].r_addend
= 0;
2503 Elf_External_Rela
*erela
;
2504 Elf_External_Rela
*erelaend
;
2505 Elf_Internal_Rela
*irela
;
2507 BFD_ASSERT (shdr
->sh_entsize
== sizeof (Elf_External_Rela
));
2509 erela
= (Elf_External_Rela
*) external_relocs
;
2510 erelaend
= erela
+ NUM_SHDR_ENTRIES (shdr
);
2511 irela
= internal_relocs
;
2512 for (; erela
< erelaend
; erela
++, irela
+= bed
->s
->int_rels_per_ext_rel
)
2514 if (bed
->s
->swap_reloca_in
)
2515 (*bed
->s
->swap_reloca_in
) (abfd
, (bfd_byte
*) erela
, irela
);
2517 elf_swap_reloca_in (abfd
, erela
, irela
);
2524 /* Read and swap the relocs for a section O. They may have been
2525 cached. If the EXTERNAL_RELOCS and INTERNAL_RELOCS arguments are
2526 not NULL, they are used as buffers to read into. They are known to
2527 be large enough. If the INTERNAL_RELOCS relocs argument is NULL,
2528 the return value is allocated using either malloc or bfd_alloc,
2529 according to the KEEP_MEMORY argument. If O has two relocation
2530 sections (both REL and RELA relocations), then the REL_HDR
2531 relocations will appear first in INTERNAL_RELOCS, followed by the
2532 REL_HDR2 relocations. */
2535 NAME(_bfd_elf
,link_read_relocs
) (abfd
, o
, external_relocs
, internal_relocs
,
2539 PTR external_relocs
;
2540 Elf_Internal_Rela
*internal_relocs
;
2541 boolean keep_memory
;
2543 Elf_Internal_Shdr
*rel_hdr
;
2545 Elf_Internal_Rela
*alloc2
= NULL
;
2546 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
2548 if (elf_section_data (o
)->relocs
!= NULL
)
2549 return elf_section_data (o
)->relocs
;
2551 if (o
->reloc_count
== 0)
2554 rel_hdr
= &elf_section_data (o
)->rel_hdr
;
2556 if (internal_relocs
== NULL
)
2560 size
= (o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
2561 * sizeof (Elf_Internal_Rela
));
2563 internal_relocs
= (Elf_Internal_Rela
*) bfd_alloc (abfd
, size
);
2565 internal_relocs
= alloc2
= (Elf_Internal_Rela
*) bfd_malloc (size
);
2566 if (internal_relocs
== NULL
)
2570 if (external_relocs
== NULL
)
2572 size_t size
= (size_t) rel_hdr
->sh_size
;
2574 if (elf_section_data (o
)->rel_hdr2
)
2575 size
+= (size_t) elf_section_data (o
)->rel_hdr2
->sh_size
;
2576 alloc1
= (PTR
) bfd_malloc (size
);
2579 external_relocs
= alloc1
;
2582 if (!elf_link_read_relocs_from_section (abfd
, rel_hdr
,
2586 if (!elf_link_read_relocs_from_section
2588 elf_section_data (o
)->rel_hdr2
,
2589 ((bfd_byte
*) external_relocs
) + rel_hdr
->sh_size
,
2590 internal_relocs
+ (NUM_SHDR_ENTRIES (rel_hdr
)
2591 * bed
->s
->int_rels_per_ext_rel
)))
2594 /* Cache the results for next time, if we can. */
2596 elf_section_data (o
)->relocs
= internal_relocs
;
2601 /* Don't free alloc2, since if it was allocated we are passing it
2602 back (under the name of internal_relocs). */
2604 return internal_relocs
;
2614 /* Record an assignment to a symbol made by a linker script. We need
2615 this in case some dynamic object refers to this symbol. */
2618 NAME(bfd_elf
,record_link_assignment
) (output_bfd
, info
, name
, provide
)
2619 bfd
*output_bfd ATTRIBUTE_UNUSED
;
2620 struct bfd_link_info
*info
;
2624 struct elf_link_hash_entry
*h
;
2626 if (info
->hash
->creator
->flavour
!= bfd_target_elf_flavour
)
2629 h
= elf_link_hash_lookup (elf_hash_table (info
), name
, true, true, false);
2633 if (h
->root
.type
== bfd_link_hash_new
)
2634 h
->elf_link_hash_flags
&= ~ELF_LINK_NON_ELF
;
2636 /* If this symbol is being provided by the linker script, and it is
2637 currently defined by a dynamic object, but not by a regular
2638 object, then mark it as undefined so that the generic linker will
2639 force the correct value. */
2641 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2642 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2643 h
->root
.type
= bfd_link_hash_undefined
;
2645 /* If this symbol is not being provided by the linker script, and it is
2646 currently defined by a dynamic object, but not by a regular object,
2647 then clear out any version information because the symbol will not be
2648 associated with the dynamic object any more. */
2650 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
2651 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
2652 h
->verinfo
.verdef
= NULL
;
2654 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
2656 /* When possible, keep the original type of the symbol. */
2657 if (h
->type
== STT_NOTYPE
)
2658 h
->type
= STT_OBJECT
;
2660 if (((h
->elf_link_hash_flags
& (ELF_LINK_HASH_DEF_DYNAMIC
2661 | ELF_LINK_HASH_REF_DYNAMIC
)) != 0
2663 && h
->dynindx
== -1)
2665 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
2668 /* If this is a weak defined symbol, and we know a corresponding
2669 real symbol from the same dynamic object, make sure the real
2670 symbol is also made into a dynamic symbol. */
2671 if (h
->weakdef
!= NULL
2672 && h
->weakdef
->dynindx
== -1)
2674 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
->weakdef
))
2682 /* This structure is used to pass information to
2683 elf_link_assign_sym_version. */
2685 struct elf_assign_sym_version_info
2689 /* General link information. */
2690 struct bfd_link_info
*info
;
2692 struct bfd_elf_version_tree
*verdefs
;
2693 /* Whether we had a failure. */
2697 /* This structure is used to pass information to
2698 elf_link_find_version_dependencies. */
2700 struct elf_find_verdep_info
2704 /* General link information. */
2705 struct bfd_link_info
*info
;
2706 /* The number of dependencies. */
2708 /* Whether we had a failure. */
2712 /* Array used to determine the number of hash table buckets to use
2713 based on the number of symbols there are. If there are fewer than
2714 3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
2715 fewer than 37 we use 17 buckets, and so forth. We never use more
2716 than 32771 buckets. */
2718 static const size_t elf_buckets
[] =
2720 1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
2724 /* Compute bucket count for hashing table. We do not use a static set
2725 of possible tables sizes anymore. Instead we determine for all
2726 possible reasonable sizes of the table the outcome (i.e., the
2727 number of collisions etc) and choose the best solution. The
2728 weighting functions are not too simple to allow the table to grow
2729 without bounds. Instead one of the weighting factors is the size.
2730 Therefore the result is always a good payoff between few collisions
2731 (= short chain lengths) and table size. */
2733 compute_bucket_count (info
)
2734 struct bfd_link_info
*info
;
2736 size_t dynsymcount
= elf_hash_table (info
)->dynsymcount
;
2737 size_t best_size
= 0;
2738 unsigned long int *hashcodes
;
2739 unsigned long int *hashcodesp
;
2740 unsigned long int i
;
2742 /* Compute the hash values for all exported symbols. At the same
2743 time store the values in an array so that we could use them for
2745 hashcodes
= (unsigned long int *) bfd_malloc (dynsymcount
2746 * sizeof (unsigned long int));
2747 if (hashcodes
== NULL
)
2749 hashcodesp
= hashcodes
;
2751 /* Put all hash values in HASHCODES. */
2752 elf_link_hash_traverse (elf_hash_table (info
),
2753 elf_collect_hash_codes
, &hashcodesp
);
2755 /* We have a problem here. The following code to optimize the table
2756 size requires an integer type with more the 32 bits. If
2757 BFD_HOST_U_64_BIT is set we know about such a type. */
2758 #ifdef BFD_HOST_U_64_BIT
2759 if (info
->optimize
== true)
2761 unsigned long int nsyms
= hashcodesp
- hashcodes
;
2764 BFD_HOST_U_64_BIT best_chlen
= ~((BFD_HOST_U_64_BIT
) 0);
2765 unsigned long int *counts
;
2767 /* Possible optimization parameters: if we have NSYMS symbols we say
2768 that the hashing table must at least have NSYMS/4 and at most
2770 minsize
= nsyms
/ 4;
2773 best_size
= maxsize
= nsyms
* 2;
2775 /* Create array where we count the collisions in. We must use bfd_malloc
2776 since the size could be large. */
2777 counts
= (unsigned long int *) bfd_malloc (maxsize
2778 * sizeof (unsigned long int));
2785 /* Compute the "optimal" size for the hash table. The criteria is a
2786 minimal chain length. The minor criteria is (of course) the size
2788 for (i
= minsize
; i
< maxsize
; ++i
)
2790 /* Walk through the array of hashcodes and count the collisions. */
2791 BFD_HOST_U_64_BIT max
;
2792 unsigned long int j
;
2793 unsigned long int fact
;
2795 memset (counts
, '\0', i
* sizeof (unsigned long int));
2797 /* Determine how often each hash bucket is used. */
2798 for (j
= 0; j
< nsyms
; ++j
)
2799 ++counts
[hashcodes
[j
] % i
];
2801 /* For the weight function we need some information about the
2802 pagesize on the target. This is information need not be 100%
2803 accurate. Since this information is not available (so far) we
2804 define it here to a reasonable default value. If it is crucial
2805 to have a better value some day simply define this value. */
2806 # ifndef BFD_TARGET_PAGESIZE
2807 # define BFD_TARGET_PAGESIZE (4096)
2810 /* We in any case need 2 + NSYMS entries for the size values and
2812 max
= (2 + nsyms
) * (ARCH_SIZE
/ 8);
2815 /* Variant 1: optimize for short chains. We add the squares
2816 of all the chain lengths (which favous many small chain
2817 over a few long chains). */
2818 for (j
= 0; j
< i
; ++j
)
2819 max
+= counts
[j
] * counts
[j
];
2821 /* This adds penalties for the overall size of the table. */
2822 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (ARCH_SIZE
/ 8)) + 1;
2825 /* Variant 2: Optimize a lot more for small table. Here we
2826 also add squares of the size but we also add penalties for
2827 empty slots (the +1 term). */
2828 for (j
= 0; j
< i
; ++j
)
2829 max
+= (1 + counts
[j
]) * (1 + counts
[j
]);
2831 /* The overall size of the table is considered, but not as
2832 strong as in variant 1, where it is squared. */
2833 fact
= i
/ (BFD_TARGET_PAGESIZE
/ (ARCH_SIZE
/ 8)) + 1;
2837 /* Compare with current best results. */
2838 if (max
< best_chlen
)
2848 #endif /* defined (BFD_HOST_U_64_BIT) */
2850 /* This is the fallback solution if no 64bit type is available or if we
2851 are not supposed to spend much time on optimizations. We select the
2852 bucket count using a fixed set of numbers. */
2853 for (i
= 0; elf_buckets
[i
] != 0; i
++)
2855 best_size
= elf_buckets
[i
];
2856 if (dynsymcount
< elf_buckets
[i
+ 1])
2861 /* Free the arrays we needed. */
2867 /* Set up the sizes and contents of the ELF dynamic sections. This is
2868 called by the ELF linker emulation before_allocation routine. We
2869 must set the sizes of the sections before the linker sets the
2870 addresses of the various sections. */
2873 NAME(bfd_elf
,size_dynamic_sections
) (output_bfd
, soname
, rpath
,
2875 auxiliary_filters
, info
, sinterpptr
,
2880 const char *filter_shlib
;
2881 const char * const *auxiliary_filters
;
2882 struct bfd_link_info
*info
;
2883 asection
**sinterpptr
;
2884 struct bfd_elf_version_tree
*verdefs
;
2886 bfd_size_type soname_indx
;
2888 struct elf_backend_data
*bed
;
2889 struct elf_assign_sym_version_info asvinfo
;
2893 soname_indx
= (bfd_size_type
) -1;
2895 if (info
->hash
->creator
->flavour
!= bfd_target_elf_flavour
)
2898 /* The backend may have to create some sections regardless of whether
2899 we're dynamic or not. */
2900 bed
= get_elf_backend_data (output_bfd
);
2901 if (bed
->elf_backend_always_size_sections
2902 && ! (*bed
->elf_backend_always_size_sections
) (output_bfd
, info
))
2905 dynobj
= elf_hash_table (info
)->dynobj
;
2907 /* If there were no dynamic objects in the link, there is nothing to
2912 if (elf_hash_table (info
)->dynamic_sections_created
)
2914 struct elf_info_failed eif
;
2915 struct elf_link_hash_entry
*h
;
2918 *sinterpptr
= bfd_get_section_by_name (dynobj
, ".interp");
2919 BFD_ASSERT (*sinterpptr
!= NULL
|| info
->shared
);
2923 soname_indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2924 soname
, true, true);
2925 if (soname_indx
== (bfd_size_type
) -1
2926 || ! elf_add_dynamic_entry (info
, DT_SONAME
, soname_indx
))
2932 if (! elf_add_dynamic_entry (info
, DT_SYMBOLIC
, 0))
2934 info
->flags
|= DF_SYMBOLIC
;
2941 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
, rpath
,
2943 if (indx
== (bfd_size_type
) -1
2944 || ! elf_add_dynamic_entry (info
, DT_RPATH
, indx
)
2946 && ! elf_add_dynamic_entry (info
, DT_RUNPATH
, indx
)))
2950 if (filter_shlib
!= NULL
)
2954 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2955 filter_shlib
, true, true);
2956 if (indx
== (bfd_size_type
) -1
2957 || ! elf_add_dynamic_entry (info
, DT_FILTER
, indx
))
2961 if (auxiliary_filters
!= NULL
)
2963 const char * const *p
;
2965 for (p
= auxiliary_filters
; *p
!= NULL
; p
++)
2969 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
2971 if (indx
== (bfd_size_type
) -1
2972 || ! elf_add_dynamic_entry (info
, DT_AUXILIARY
, indx
))
2978 eif
.verdefs
= verdefs
;
2981 /* If we are supposed to export all symbols into the dynamic symbol
2982 table (this is not the normal case), then do so. */
2983 if (info
->export_dynamic
)
2985 elf_link_hash_traverse (elf_hash_table (info
), elf_export_symbol
,
2991 /* Attach all the symbols to their version information. */
2992 asvinfo
.output_bfd
= output_bfd
;
2993 asvinfo
.info
= info
;
2994 asvinfo
.verdefs
= verdefs
;
2995 asvinfo
.failed
= false;
2997 elf_link_hash_traverse (elf_hash_table (info
),
2998 elf_link_assign_sym_version
,
3003 /* Find all symbols which were defined in a dynamic object and make
3004 the backend pick a reasonable value for them. */
3005 elf_link_hash_traverse (elf_hash_table (info
),
3006 elf_adjust_dynamic_symbol
,
3011 /* Add some entries to the .dynamic section. We fill in some of the
3012 values later, in elf_bfd_final_link, but we must add the entries
3013 now so that we know the final size of the .dynamic section. */
3015 /* If there are initialization and/or finalization functions to
3016 call then add the corresponding DT_INIT/DT_FINI entries. */
3017 h
= (info
->init_function
3018 ? elf_link_hash_lookup (elf_hash_table (info
),
3019 info
->init_function
, false,
3023 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
3024 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
3026 if (! elf_add_dynamic_entry (info
, DT_INIT
, 0))
3029 h
= (info
->fini_function
3030 ? elf_link_hash_lookup (elf_hash_table (info
),
3031 info
->fini_function
, false,
3035 && (h
->elf_link_hash_flags
& (ELF_LINK_HASH_REF_REGULAR
3036 | ELF_LINK_HASH_DEF_REGULAR
)) != 0)
3038 if (! elf_add_dynamic_entry (info
, DT_FINI
, 0))
3042 dynstr
= bfd_get_section_by_name (dynobj
, ".dynstr");
3043 /* If .dynstr is excluded from the link, we don't want any of
3044 these tags. Strictly, we should be checking each section
3045 individually; This quick check covers for the case where
3046 someone does a /DISCARD/ : { *(*) }. */
3047 if (dynstr
!= NULL
&& dynstr
->output_section
!= bfd_abs_section_ptr
)
3049 bfd_size_type strsize
;
3051 strsize
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
3052 if (! elf_add_dynamic_entry (info
, DT_HASH
, 0)
3053 || ! elf_add_dynamic_entry (info
, DT_STRTAB
, 0)
3054 || ! elf_add_dynamic_entry (info
, DT_SYMTAB
, 0)
3055 || ! elf_add_dynamic_entry (info
, DT_STRSZ
, strsize
)
3056 || ! elf_add_dynamic_entry (info
, DT_SYMENT
,
3057 sizeof (Elf_External_Sym
)))
3062 /* The backend must work out the sizes of all the other dynamic
3064 if (bed
->elf_backend_size_dynamic_sections
3065 && ! (*bed
->elf_backend_size_dynamic_sections
) (output_bfd
, info
))
3068 if (elf_hash_table (info
)->dynamic_sections_created
)
3072 size_t bucketcount
= 0;
3073 size_t hash_entry_size
;
3074 unsigned int dtagcount
;
3076 /* Set up the version definition section. */
3077 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_d");
3078 BFD_ASSERT (s
!= NULL
);
3080 /* We may have created additional version definitions if we are
3081 just linking a regular application. */
3082 verdefs
= asvinfo
.verdefs
;
3084 if (verdefs
== NULL
)
3085 _bfd_strip_section_from_output (info
, s
);
3090 struct bfd_elf_version_tree
*t
;
3092 Elf_Internal_Verdef def
;
3093 Elf_Internal_Verdaux defaux
;
3098 /* Make space for the base version. */
3099 size
+= sizeof (Elf_External_Verdef
);
3100 size
+= sizeof (Elf_External_Verdaux
);
3103 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
3105 struct bfd_elf_version_deps
*n
;
3107 size
+= sizeof (Elf_External_Verdef
);
3108 size
+= sizeof (Elf_External_Verdaux
);
3111 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3112 size
+= sizeof (Elf_External_Verdaux
);
3115 s
->_raw_size
= size
;
3116 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3117 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3120 /* Fill in the version definition section. */
3124 def
.vd_version
= VER_DEF_CURRENT
;
3125 def
.vd_flags
= VER_FLG_BASE
;
3128 def
.vd_aux
= sizeof (Elf_External_Verdef
);
3129 def
.vd_next
= (sizeof (Elf_External_Verdef
)
3130 + sizeof (Elf_External_Verdaux
));
3132 if (soname_indx
!= (bfd_size_type
) -1)
3134 def
.vd_hash
= bfd_elf_hash (soname
);
3135 defaux
.vda_name
= soname_indx
;
3142 name
= basename (output_bfd
->filename
);
3143 def
.vd_hash
= bfd_elf_hash (name
);
3144 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3146 if (indx
== (bfd_size_type
) -1)
3148 defaux
.vda_name
= indx
;
3150 defaux
.vda_next
= 0;
3152 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
3153 (Elf_External_Verdef
*) p
);
3154 p
+= sizeof (Elf_External_Verdef
);
3155 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3156 (Elf_External_Verdaux
*) p
);
3157 p
+= sizeof (Elf_External_Verdaux
);
3159 for (t
= verdefs
; t
!= NULL
; t
= t
->next
)
3162 struct bfd_elf_version_deps
*n
;
3163 struct elf_link_hash_entry
*h
;
3166 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3169 /* Add a symbol representing this version. */
3171 if (! (_bfd_generic_link_add_one_symbol
3172 (info
, dynobj
, t
->name
, BSF_GLOBAL
, bfd_abs_section_ptr
,
3173 (bfd_vma
) 0, (const char *) NULL
, false,
3174 get_elf_backend_data (dynobj
)->collect
,
3175 (struct bfd_link_hash_entry
**) &h
)))
3177 h
->elf_link_hash_flags
&= ~ ELF_LINK_NON_ELF
;
3178 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3179 h
->type
= STT_OBJECT
;
3180 h
->verinfo
.vertree
= t
;
3182 if (! _bfd_elf_link_record_dynamic_symbol (info
, h
))
3185 def
.vd_version
= VER_DEF_CURRENT
;
3187 if (t
->globals
== NULL
&& t
->locals
== NULL
&& ! t
->used
)
3188 def
.vd_flags
|= VER_FLG_WEAK
;
3189 def
.vd_ndx
= t
->vernum
+ 1;
3190 def
.vd_cnt
= cdeps
+ 1;
3191 def
.vd_hash
= bfd_elf_hash (t
->name
);
3192 def
.vd_aux
= sizeof (Elf_External_Verdef
);
3193 if (t
->next
!= NULL
)
3194 def
.vd_next
= (sizeof (Elf_External_Verdef
)
3195 + (cdeps
+ 1) * sizeof (Elf_External_Verdaux
));
3199 _bfd_elf_swap_verdef_out (output_bfd
, &def
,
3200 (Elf_External_Verdef
*) p
);
3201 p
+= sizeof (Elf_External_Verdef
);
3203 defaux
.vda_name
= h
->dynstr_index
;
3204 if (t
->deps
== NULL
)
3205 defaux
.vda_next
= 0;
3207 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
3208 t
->name_indx
= defaux
.vda_name
;
3210 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3211 (Elf_External_Verdaux
*) p
);
3212 p
+= sizeof (Elf_External_Verdaux
);
3214 for (n
= t
->deps
; n
!= NULL
; n
= n
->next
)
3216 if (n
->version_needed
== NULL
)
3218 /* This can happen if there was an error in the
3220 defaux
.vda_name
= 0;
3223 defaux
.vda_name
= n
->version_needed
->name_indx
;
3224 if (n
->next
== NULL
)
3225 defaux
.vda_next
= 0;
3227 defaux
.vda_next
= sizeof (Elf_External_Verdaux
);
3229 _bfd_elf_swap_verdaux_out (output_bfd
, &defaux
,
3230 (Elf_External_Verdaux
*) p
);
3231 p
+= sizeof (Elf_External_Verdaux
);
3235 if (! elf_add_dynamic_entry (info
, DT_VERDEF
, 0)
3236 || ! elf_add_dynamic_entry (info
, DT_VERDEFNUM
, cdefs
))
3239 elf_tdata (output_bfd
)->cverdefs
= cdefs
;
3242 if (info
->new_dtags
&& info
->flags
)
3244 if (! elf_add_dynamic_entry (info
, DT_FLAGS
, info
->flags
))
3251 info
->flags_1
&= ~ (DF_1_INITFIRST
3254 if (! elf_add_dynamic_entry (info
, DT_FLAGS_1
, info
->flags_1
))
3258 /* Work out the size of the version reference section. */
3260 s
= bfd_get_section_by_name (dynobj
, ".gnu.version_r");
3261 BFD_ASSERT (s
!= NULL
);
3263 struct elf_find_verdep_info sinfo
;
3265 sinfo
.output_bfd
= output_bfd
;
3267 sinfo
.vers
= elf_tdata (output_bfd
)->cverdefs
;
3268 if (sinfo
.vers
== 0)
3270 sinfo
.failed
= false;
3272 elf_link_hash_traverse (elf_hash_table (info
),
3273 elf_link_find_version_dependencies
,
3276 if (elf_tdata (output_bfd
)->verref
== NULL
)
3277 _bfd_strip_section_from_output (info
, s
);
3280 Elf_Internal_Verneed
*t
;
3285 /* Build the version definition section. */
3288 for (t
= elf_tdata (output_bfd
)->verref
;
3292 Elf_Internal_Vernaux
*a
;
3294 size
+= sizeof (Elf_External_Verneed
);
3296 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3297 size
+= sizeof (Elf_External_Vernaux
);
3300 s
->_raw_size
= size
;
3301 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, size
);
3302 if (s
->contents
== NULL
)
3306 for (t
= elf_tdata (output_bfd
)->verref
;
3311 Elf_Internal_Vernaux
*a
;
3315 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3318 t
->vn_version
= VER_NEED_CURRENT
;
3320 if (elf_dt_name (t
->vn_bfd
) != NULL
)
3321 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3322 elf_dt_name (t
->vn_bfd
),
3325 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3326 basename (t
->vn_bfd
->filename
),
3328 if (indx
== (bfd_size_type
) -1)
3331 t
->vn_aux
= sizeof (Elf_External_Verneed
);
3332 if (t
->vn_nextref
== NULL
)
3335 t
->vn_next
= (sizeof (Elf_External_Verneed
)
3336 + caux
* sizeof (Elf_External_Vernaux
));
3338 _bfd_elf_swap_verneed_out (output_bfd
, t
,
3339 (Elf_External_Verneed
*) p
);
3340 p
+= sizeof (Elf_External_Verneed
);
3342 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3344 a
->vna_hash
= bfd_elf_hash (a
->vna_nodename
);
3345 indx
= _bfd_stringtab_add (elf_hash_table (info
)->dynstr
,
3346 a
->vna_nodename
, true, false);
3347 if (indx
== (bfd_size_type
) -1)
3350 if (a
->vna_nextptr
== NULL
)
3353 a
->vna_next
= sizeof (Elf_External_Vernaux
);
3355 _bfd_elf_swap_vernaux_out (output_bfd
, a
,
3356 (Elf_External_Vernaux
*) p
);
3357 p
+= sizeof (Elf_External_Vernaux
);
3361 if (! elf_add_dynamic_entry (info
, DT_VERNEED
, 0)
3362 || ! elf_add_dynamic_entry (info
, DT_VERNEEDNUM
, crefs
))
3365 elf_tdata (output_bfd
)->cverrefs
= crefs
;
3369 /* Assign dynsym indicies. In a shared library we generate a
3370 section symbol for each output section, which come first.
3371 Next come all of the back-end allocated local dynamic syms,
3372 followed by the rest of the global symbols. */
3374 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
3376 /* Work out the size of the symbol version section. */
3377 s
= bfd_get_section_by_name (dynobj
, ".gnu.version");
3378 BFD_ASSERT (s
!= NULL
);
3379 if (dynsymcount
== 0
3380 || (verdefs
== NULL
&& elf_tdata (output_bfd
)->verref
== NULL
))
3382 _bfd_strip_section_from_output (info
, s
);
3383 /* The DYNSYMCOUNT might have changed if we were going to
3384 output a dynamic symbol table entry for S. */
3385 dynsymcount
= _bfd_elf_link_renumber_dynsyms (output_bfd
, info
);
3389 s
->_raw_size
= dynsymcount
* sizeof (Elf_External_Versym
);
3390 s
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, s
->_raw_size
);
3391 if (s
->contents
== NULL
)
3394 if (! elf_add_dynamic_entry (info
, DT_VERSYM
, 0))
3398 /* Set the size of the .dynsym and .hash sections. We counted
3399 the number of dynamic symbols in elf_link_add_object_symbols.
3400 We will build the contents of .dynsym and .hash when we build
3401 the final symbol table, because until then we do not know the
3402 correct value to give the symbols. We built the .dynstr
3403 section as we went along in elf_link_add_object_symbols. */
3404 s
= bfd_get_section_by_name (dynobj
, ".dynsym");
3405 BFD_ASSERT (s
!= NULL
);
3406 s
->_raw_size
= dynsymcount
* sizeof (Elf_External_Sym
);
3407 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3408 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
3411 if (dynsymcount
!= 0)
3413 Elf_Internal_Sym isym
;
3415 /* The first entry in .dynsym is a dummy symbol. */
3422 elf_swap_symbol_out (output_bfd
, &isym
,
3423 (PTR
) (Elf_External_Sym
*) s
->contents
);
3426 /* Compute the size of the hashing table. As a side effect this
3427 computes the hash values for all the names we export. */
3428 bucketcount
= compute_bucket_count (info
);
3430 s
= bfd_get_section_by_name (dynobj
, ".hash");
3431 BFD_ASSERT (s
!= NULL
);
3432 hash_entry_size
= elf_section_data (s
)->this_hdr
.sh_entsize
;
3433 s
->_raw_size
= ((2 + bucketcount
+ dynsymcount
) * hash_entry_size
);
3434 s
->contents
= (bfd_byte
*) bfd_alloc (output_bfd
, s
->_raw_size
);
3435 if (s
->contents
== NULL
)
3437 memset (s
->contents
, 0, (size_t) s
->_raw_size
);
3439 bfd_put (8 * hash_entry_size
, output_bfd
, bucketcount
, s
->contents
);
3440 bfd_put (8 * hash_entry_size
, output_bfd
, dynsymcount
,
3441 s
->contents
+ hash_entry_size
);
3443 elf_hash_table (info
)->bucketcount
= bucketcount
;
3445 s
= bfd_get_section_by_name (dynobj
, ".dynstr");
3446 BFD_ASSERT (s
!= NULL
);
3447 s
->_raw_size
= _bfd_stringtab_size (elf_hash_table (info
)->dynstr
);
3449 for (dtagcount
= 0; dtagcount
<= info
->spare_dynamic_tags
; ++dtagcount
)
3450 if (! elf_add_dynamic_entry (info
, DT_NULL
, 0))
3457 /* Fix up the flags for a symbol. This handles various cases which
3458 can only be fixed after all the input files are seen. This is
3459 currently called by both adjust_dynamic_symbol and
3460 assign_sym_version, which is unnecessary but perhaps more robust in
3461 the face of future changes. */
3464 elf_fix_symbol_flags (h
, eif
)
3465 struct elf_link_hash_entry
*h
;
3466 struct elf_info_failed
*eif
;
3468 /* If this symbol was mentioned in a non-ELF file, try to set
3469 DEF_REGULAR and REF_REGULAR correctly. This is the only way to
3470 permit a non-ELF file to correctly refer to a symbol defined in
3471 an ELF dynamic object. */
3472 if ((h
->elf_link_hash_flags
& ELF_LINK_NON_ELF
) != 0)
3474 while (h
->root
.type
== bfd_link_hash_indirect
)
3475 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
3477 if (h
->root
.type
!= bfd_link_hash_defined
3478 && h
->root
.type
!= bfd_link_hash_defweak
)
3479 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
3480 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
3483 if (h
->root
.u
.def
.section
->owner
!= NULL
3484 && (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
3485 == bfd_target_elf_flavour
))
3486 h
->elf_link_hash_flags
|= (ELF_LINK_HASH_REF_REGULAR
3487 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
);
3489 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3492 if (h
->dynindx
== -1
3493 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
3494 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0))
3496 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
3505 /* Unfortunately, ELF_LINK_NON_ELF is only correct if the symbol
3506 was first seen in a non-ELF file. Fortunately, if the symbol
3507 was first seen in an ELF file, we're probably OK unless the
3508 symbol was defined in a non-ELF file. Catch that case here.
3509 FIXME: We're still in trouble if the symbol was first seen in
3510 a dynamic object, and then later in a non-ELF regular object. */
3511 if ((h
->root
.type
== bfd_link_hash_defined
3512 || h
->root
.type
== bfd_link_hash_defweak
)
3513 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3514 && (h
->root
.u
.def
.section
->owner
!= NULL
3515 ? (bfd_get_flavour (h
->root
.u
.def
.section
->owner
)
3516 != bfd_target_elf_flavour
)
3517 : (bfd_is_abs_section (h
->root
.u
.def
.section
)
3518 && (h
->elf_link_hash_flags
3519 & ELF_LINK_HASH_DEF_DYNAMIC
) == 0)))
3520 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3523 /* If this is a final link, and the symbol was defined as a common
3524 symbol in a regular object file, and there was no definition in
3525 any dynamic object, then the linker will have allocated space for
3526 the symbol in a common section but the ELF_LINK_HASH_DEF_REGULAR
3527 flag will not have been set. */
3528 if (h
->root
.type
== bfd_link_hash_defined
3529 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
3530 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) != 0
3531 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3532 && (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0)
3533 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
3535 /* If -Bsymbolic was used (which means to bind references to global
3536 symbols to the definition within the shared object), and this
3537 symbol was defined in a regular object, then it actually doesn't
3538 need a PLT entry, and we can accomplish that by forcing it local.
3539 Likewise, if the symbol has hidden or internal visibility.
3540 FIXME: It might be that we also do not need a PLT for other
3541 non-hidden visibilities, but we would have to tell that to the
3542 backend specifically; we can't just clear PLT-related data here. */
3543 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0
3544 && eif
->info
->shared
3545 && (eif
->info
->symbolic
3546 || ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
3547 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
3548 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
3550 struct elf_backend_data
*bed
;
3551 bed
= get_elf_backend_data (elf_hash_table (eif
->info
)->dynobj
);
3552 if (ELF_ST_VISIBILITY (h
->other
) == STV_INTERNAL
3553 || ELF_ST_VISIBILITY (h
->other
) == STV_HIDDEN
)
3554 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
3555 (*bed
->elf_backend_hide_symbol
) (eif
->info
, h
);
3558 /* If this is a weak defined symbol in a dynamic object, and we know
3559 the real definition in the dynamic object, copy interesting flags
3560 over to the real definition. */
3561 if (h
->weakdef
!= NULL
)
3563 struct elf_link_hash_entry
*weakdef
;
3565 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
3566 || h
->root
.type
== bfd_link_hash_defweak
);
3567 weakdef
= h
->weakdef
;
3568 BFD_ASSERT (weakdef
->root
.type
== bfd_link_hash_defined
3569 || weakdef
->root
.type
== bfd_link_hash_defweak
);
3570 BFD_ASSERT (weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
);
3572 /* If the real definition is defined by a regular object file,
3573 don't do anything special. See the longer description in
3574 elf_adjust_dynamic_symbol, below. */
3575 if ((weakdef
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0)
3578 weakdef
->elf_link_hash_flags
|=
3579 (h
->elf_link_hash_flags
3580 & (ELF_LINK_HASH_REF_REGULAR
3581 | ELF_LINK_HASH_REF_REGULAR_NONWEAK
3582 | ELF_LINK_NON_GOT_REF
));
3588 /* Make the backend pick a good value for a dynamic symbol. This is
3589 called via elf_link_hash_traverse, and also calls itself
3593 elf_adjust_dynamic_symbol (h
, data
)
3594 struct elf_link_hash_entry
*h
;
3597 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
3599 struct elf_backend_data
*bed
;
3601 /* Ignore indirect symbols. These are added by the versioning code. */
3602 if (h
->root
.type
== bfd_link_hash_indirect
)
3605 /* Fix the symbol flags. */
3606 if (! elf_fix_symbol_flags (h
, eif
))
3609 /* If this symbol does not require a PLT entry, and it is not
3610 defined by a dynamic object, or is not referenced by a regular
3611 object, ignore it. We do have to handle a weak defined symbol,
3612 even if no regular object refers to it, if we decided to add it
3613 to the dynamic symbol table. FIXME: Do we normally need to worry
3614 about symbols which are defined by one dynamic object and
3615 referenced by another one? */
3616 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0
3617 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3618 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3619 || ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0
3620 && (h
->weakdef
== NULL
|| h
->weakdef
->dynindx
== -1))))
3622 h
->plt
.offset
= (bfd_vma
) -1;
3626 /* If we've already adjusted this symbol, don't do it again. This
3627 can happen via a recursive call. */
3628 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DYNAMIC_ADJUSTED
) != 0)
3631 /* Don't look at this symbol again. Note that we must set this
3632 after checking the above conditions, because we may look at a
3633 symbol once, decide not to do anything, and then get called
3634 recursively later after REF_REGULAR is set below. */
3635 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DYNAMIC_ADJUSTED
;
3637 /* If this is a weak definition, and we know a real definition, and
3638 the real symbol is not itself defined by a regular object file,
3639 then get a good value for the real definition. We handle the
3640 real symbol first, for the convenience of the backend routine.
3642 Note that there is a confusing case here. If the real definition
3643 is defined by a regular object file, we don't get the real symbol
3644 from the dynamic object, but we do get the weak symbol. If the
3645 processor backend uses a COPY reloc, then if some routine in the
3646 dynamic object changes the real symbol, we will not see that
3647 change in the corresponding weak symbol. This is the way other
3648 ELF linkers work as well, and seems to be a result of the shared
3651 I will clarify this issue. Most SVR4 shared libraries define the
3652 variable _timezone and define timezone as a weak synonym. The
3653 tzset call changes _timezone. If you write
3654 extern int timezone;
3656 int main () { tzset (); printf ("%d %d\n", timezone, _timezone); }
3657 you might expect that, since timezone is a synonym for _timezone,
3658 the same number will print both times. However, if the processor
3659 backend uses a COPY reloc, then actually timezone will be copied
3660 into your process image, and, since you define _timezone
3661 yourself, _timezone will not. Thus timezone and _timezone will
3662 wind up at different memory locations. The tzset call will set
3663 _timezone, leaving timezone unchanged. */
3665 if (h
->weakdef
!= NULL
)
3667 /* If we get to this point, we know there is an implicit
3668 reference by a regular object file via the weak symbol H.
3669 FIXME: Is this really true? What if the traversal finds
3670 H->WEAKDEF before it finds H? */
3671 h
->weakdef
->elf_link_hash_flags
|= ELF_LINK_HASH_REF_REGULAR
;
3673 if (! elf_adjust_dynamic_symbol (h
->weakdef
, (PTR
) eif
))
3677 /* If a symbol has no type and no size and does not require a PLT
3678 entry, then we are probably about to do the wrong thing here: we
3679 are probably going to create a COPY reloc for an empty object.
3680 This case can arise when a shared object is built with assembly
3681 code, and the assembly code fails to set the symbol type. */
3683 && h
->type
== STT_NOTYPE
3684 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) == 0)
3685 (*_bfd_error_handler
)
3686 (_("warning: type and size of dynamic symbol `%s' are not defined"),
3687 h
->root
.root
.string
);
3689 dynobj
= elf_hash_table (eif
->info
)->dynobj
;
3690 bed
= get_elf_backend_data (dynobj
);
3691 if (! (*bed
->elf_backend_adjust_dynamic_symbol
) (eif
->info
, h
))
3700 /* This routine is used to export all defined symbols into the dynamic
3701 symbol table. It is called via elf_link_hash_traverse. */
3704 elf_export_symbol (h
, data
)
3705 struct elf_link_hash_entry
*h
;
3708 struct elf_info_failed
*eif
= (struct elf_info_failed
*) data
;
3710 /* Ignore indirect symbols. These are added by the versioning code. */
3711 if (h
->root
.type
== bfd_link_hash_indirect
)
3714 if (h
->dynindx
== -1
3715 && (h
->elf_link_hash_flags
3716 & (ELF_LINK_HASH_DEF_REGULAR
| ELF_LINK_HASH_REF_REGULAR
)) != 0)
3718 struct bfd_elf_version_tree
*t
;
3719 struct bfd_elf_version_expr
*d
;
3721 for (t
= eif
->verdefs
; t
!= NULL
; t
= t
->next
)
3723 if (t
->globals
!= NULL
)
3725 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
3727 if ((*d
->match
) (d
, h
->root
.root
.string
))
3732 if (t
->locals
!= NULL
)
3734 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
3736 if ((*d
->match
) (d
, h
->root
.root
.string
))
3745 if (! _bfd_elf_link_record_dynamic_symbol (eif
->info
, h
))
3756 /* Look through the symbols which are defined in other shared
3757 libraries and referenced here. Update the list of version
3758 dependencies. This will be put into the .gnu.version_r section.
3759 This function is called via elf_link_hash_traverse. */
3762 elf_link_find_version_dependencies (h
, data
)
3763 struct elf_link_hash_entry
*h
;
3766 struct elf_find_verdep_info
*rinfo
= (struct elf_find_verdep_info
*) data
;
3767 Elf_Internal_Verneed
*t
;
3768 Elf_Internal_Vernaux
*a
;
3770 /* We only care about symbols defined in shared objects with version
3772 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
3773 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) != 0
3775 || h
->verinfo
.verdef
== NULL
)
3778 /* See if we already know about this version. */
3779 for (t
= elf_tdata (rinfo
->output_bfd
)->verref
; t
!= NULL
; t
= t
->vn_nextref
)
3781 if (t
->vn_bfd
!= h
->verinfo
.verdef
->vd_bfd
)
3784 for (a
= t
->vn_auxptr
; a
!= NULL
; a
= a
->vna_nextptr
)
3785 if (a
->vna_nodename
== h
->verinfo
.verdef
->vd_nodename
)
3791 /* This is a new version. Add it to tree we are building. */
3795 t
= (Elf_Internal_Verneed
*) bfd_zalloc (rinfo
->output_bfd
, sizeof *t
);
3798 rinfo
->failed
= true;
3802 t
->vn_bfd
= h
->verinfo
.verdef
->vd_bfd
;
3803 t
->vn_nextref
= elf_tdata (rinfo
->output_bfd
)->verref
;
3804 elf_tdata (rinfo
->output_bfd
)->verref
= t
;
3807 a
= (Elf_Internal_Vernaux
*) bfd_zalloc (rinfo
->output_bfd
, sizeof *a
);
3809 /* Note that we are copying a string pointer here, and testing it
3810 above. If bfd_elf_string_from_elf_section is ever changed to
3811 discard the string data when low in memory, this will have to be
3813 a
->vna_nodename
= h
->verinfo
.verdef
->vd_nodename
;
3815 a
->vna_flags
= h
->verinfo
.verdef
->vd_flags
;
3816 a
->vna_nextptr
= t
->vn_auxptr
;
3818 h
->verinfo
.verdef
->vd_exp_refno
= rinfo
->vers
;
3821 a
->vna_other
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
3828 /* Figure out appropriate versions for all the symbols. We may not
3829 have the version number script until we have read all of the input
3830 files, so until that point we don't know which symbols should be
3831 local. This function is called via elf_link_hash_traverse. */
3834 elf_link_assign_sym_version (h
, data
)
3835 struct elf_link_hash_entry
*h
;
3838 struct elf_assign_sym_version_info
*sinfo
=
3839 (struct elf_assign_sym_version_info
*) data
;
3840 struct bfd_link_info
*info
= sinfo
->info
;
3841 struct elf_backend_data
*bed
;
3842 struct elf_info_failed eif
;
3845 /* Fix the symbol flags. */
3848 if (! elf_fix_symbol_flags (h
, &eif
))
3851 sinfo
->failed
= true;
3855 /* We only need version numbers for symbols defined in regular
3857 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
3860 bed
= get_elf_backend_data (sinfo
->output_bfd
);
3861 p
= strchr (h
->root
.root
.string
, ELF_VER_CHR
);
3862 if (p
!= NULL
&& h
->verinfo
.vertree
== NULL
)
3864 struct bfd_elf_version_tree
*t
;
3869 /* There are two consecutive ELF_VER_CHR characters if this is
3870 not a hidden symbol. */
3872 if (*p
== ELF_VER_CHR
)
3878 /* If there is no version string, we can just return out. */
3882 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
3886 /* Look for the version. If we find it, it is no longer weak. */
3887 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
3889 if (strcmp (t
->name
, p
) == 0)
3893 struct bfd_elf_version_expr
*d
;
3895 len
= p
- h
->root
.root
.string
;
3896 alc
= bfd_alloc (sinfo
->output_bfd
, len
);
3899 strncpy (alc
, h
->root
.root
.string
, len
- 1);
3900 alc
[len
- 1] = '\0';
3901 if (alc
[len
- 2] == ELF_VER_CHR
)
3902 alc
[len
- 2] = '\0';
3904 h
->verinfo
.vertree
= t
;
3908 if (t
->globals
!= NULL
)
3910 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
3911 if ((*d
->match
) (d
, alc
))
3915 /* See if there is anything to force this symbol to
3917 if (d
== NULL
&& t
->locals
!= NULL
)
3919 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
3921 if ((*d
->match
) (d
, alc
))
3923 if (h
->dynindx
!= -1
3925 && ! info
->export_dynamic
)
3927 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
3928 (*bed
->elf_backend_hide_symbol
) (info
, h
);
3929 /* FIXME: The name of the symbol has
3930 already been recorded in the dynamic
3931 string table section. */
3939 bfd_release (sinfo
->output_bfd
, alc
);
3944 /* If we are building an application, we need to create a
3945 version node for this version. */
3946 if (t
== NULL
&& ! info
->shared
)
3948 struct bfd_elf_version_tree
**pp
;
3951 /* If we aren't going to export this symbol, we don't need
3952 to worry about it. */
3953 if (h
->dynindx
== -1)
3956 t
= ((struct bfd_elf_version_tree
*)
3957 bfd_alloc (sinfo
->output_bfd
, sizeof *t
));
3960 sinfo
->failed
= true;
3969 t
->name_indx
= (unsigned int) -1;
3973 for (pp
= &sinfo
->verdefs
; *pp
!= NULL
; pp
= &(*pp
)->next
)
3975 t
->vernum
= version_index
;
3979 h
->verinfo
.vertree
= t
;
3983 /* We could not find the version for a symbol when
3984 generating a shared archive. Return an error. */
3985 (*_bfd_error_handler
)
3986 (_("%s: undefined versioned symbol name %s"),
3987 bfd_get_filename (sinfo
->output_bfd
), h
->root
.root
.string
);
3988 bfd_set_error (bfd_error_bad_value
);
3989 sinfo
->failed
= true;
3994 h
->elf_link_hash_flags
|= ELF_LINK_HIDDEN
;
3997 /* If we don't have a version for this symbol, see if we can find
3999 if (h
->verinfo
.vertree
== NULL
&& sinfo
->verdefs
!= NULL
)
4001 struct bfd_elf_version_tree
*t
;
4002 struct bfd_elf_version_tree
*deflt
;
4003 struct bfd_elf_version_expr
*d
;
4005 /* See if can find what version this symbol is in. If the
4006 symbol is supposed to be local, then don't actually register
4009 for (t
= sinfo
->verdefs
; t
!= NULL
; t
= t
->next
)
4011 if (t
->globals
!= NULL
)
4013 for (d
= t
->globals
; d
!= NULL
; d
= d
->next
)
4015 if ((*d
->match
) (d
, h
->root
.root
.string
))
4017 h
->verinfo
.vertree
= t
;
4026 if (t
->locals
!= NULL
)
4028 for (d
= t
->locals
; d
!= NULL
; d
= d
->next
)
4030 if (d
->pattern
[0] == '*' && d
->pattern
[1] == '\0')
4032 else if ((*d
->match
) (d
, h
->root
.root
.string
))
4034 h
->verinfo
.vertree
= t
;
4035 if (h
->dynindx
!= -1
4037 && ! info
->export_dynamic
)
4039 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
4040 (*bed
->elf_backend_hide_symbol
) (info
, h
);
4041 /* FIXME: The name of the symbol has already
4042 been recorded in the dynamic string table
4054 if (deflt
!= NULL
&& h
->verinfo
.vertree
== NULL
)
4056 h
->verinfo
.vertree
= deflt
;
4057 if (h
->dynindx
!= -1
4059 && ! info
->export_dynamic
)
4061 h
->elf_link_hash_flags
|= ELF_LINK_FORCED_LOCAL
;
4062 (*bed
->elf_backend_hide_symbol
) (info
, h
);
4063 /* FIXME: The name of the symbol has already been
4064 recorded in the dynamic string table section. */
4072 /* Final phase of ELF linker. */
4074 /* A structure we use to avoid passing large numbers of arguments. */
4076 struct elf_final_link_info
4078 /* General link information. */
4079 struct bfd_link_info
*info
;
4082 /* Symbol string table. */
4083 struct bfd_strtab_hash
*symstrtab
;
4084 /* .dynsym section. */
4085 asection
*dynsym_sec
;
4086 /* .hash section. */
4088 /* symbol version section (.gnu.version). */
4089 asection
*symver_sec
;
4090 /* Buffer large enough to hold contents of any section. */
4092 /* Buffer large enough to hold external relocs of any section. */
4093 PTR external_relocs
;
4094 /* Buffer large enough to hold internal relocs of any section. */
4095 Elf_Internal_Rela
*internal_relocs
;
4096 /* Buffer large enough to hold external local symbols of any input
4098 Elf_External_Sym
*external_syms
;
4099 /* Buffer large enough to hold internal local symbols of any input
4101 Elf_Internal_Sym
*internal_syms
;
4102 /* Array large enough to hold a symbol index for each local symbol
4103 of any input BFD. */
4105 /* Array large enough to hold a section pointer for each local
4106 symbol of any input BFD. */
4107 asection
**sections
;
4108 /* Buffer to hold swapped out symbols. */
4109 Elf_External_Sym
*symbuf
;
4110 /* Number of swapped out symbols in buffer. */
4111 size_t symbuf_count
;
4112 /* Number of symbols which fit in symbuf. */
4116 static boolean elf_link_output_sym
4117 PARAMS ((struct elf_final_link_info
*, const char *,
4118 Elf_Internal_Sym
*, asection
*));
4119 static boolean elf_link_flush_output_syms
4120 PARAMS ((struct elf_final_link_info
*));
4121 static boolean elf_link_output_extsym
4122 PARAMS ((struct elf_link_hash_entry
*, PTR
));
4123 static boolean elf_link_sec_merge_syms
4124 PARAMS ((struct elf_link_hash_entry
*, PTR
));
4125 static boolean elf_link_input_bfd
4126 PARAMS ((struct elf_final_link_info
*, bfd
*));
4127 static boolean elf_reloc_link_order
4128 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
4129 struct bfd_link_order
*));
4131 /* This struct is used to pass information to elf_link_output_extsym. */
4133 struct elf_outext_info
4137 struct elf_final_link_info
*finfo
;
4140 /* Compute the size of, and allocate space for, REL_HDR which is the
4141 section header for a section containing relocations for O. */
4144 elf_link_size_reloc_section (abfd
, rel_hdr
, o
)
4146 Elf_Internal_Shdr
*rel_hdr
;
4149 unsigned reloc_count
;
4150 unsigned num_rel_hashes
;
4152 /* Figure out how many relocations there will be. */
4153 if (rel_hdr
== &elf_section_data (o
)->rel_hdr
)
4154 reloc_count
= elf_section_data (o
)->rel_count
;
4156 reloc_count
= elf_section_data (o
)->rel_count2
;
4158 num_rel_hashes
= o
->reloc_count
;
4159 if (num_rel_hashes
< reloc_count
)
4160 num_rel_hashes
= reloc_count
;
4162 /* That allows us to calculate the size of the section. */
4163 rel_hdr
->sh_size
= rel_hdr
->sh_entsize
* reloc_count
;
4165 /* The contents field must last into write_object_contents, so we
4166 allocate it with bfd_alloc rather than malloc. Also since we
4167 cannot be sure that the contents will actually be filled in,
4168 we zero the allocated space. */
4169 rel_hdr
->contents
= (PTR
) bfd_zalloc (abfd
, rel_hdr
->sh_size
);
4170 if (rel_hdr
->contents
== NULL
&& rel_hdr
->sh_size
!= 0)
4173 /* We only allocate one set of hash entries, so we only do it the
4174 first time we are called. */
4175 if (elf_section_data (o
)->rel_hashes
== NULL
4178 struct elf_link_hash_entry
**p
;
4180 p
= ((struct elf_link_hash_entry
**)
4181 bfd_zmalloc (num_rel_hashes
4182 * sizeof (struct elf_link_hash_entry
*)));
4186 elf_section_data (o
)->rel_hashes
= p
;
4192 /* When performing a relocateable link, the input relocations are
4193 preserved. But, if they reference global symbols, the indices
4194 referenced must be updated. Update all the relocations in
4195 REL_HDR (there are COUNT of them), using the data in REL_HASH. */
4198 elf_link_adjust_relocs (abfd
, rel_hdr
, count
, rel_hash
)
4200 Elf_Internal_Shdr
*rel_hdr
;
4202 struct elf_link_hash_entry
**rel_hash
;
4205 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4206 Elf_Internal_Rel
*irel
;
4207 Elf_Internal_Rela
*irela
;
4209 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (sizeof (Elf_Internal_Rel
)
4210 * bed
->s
->int_rels_per_ext_rel
);
4213 (*_bfd_error_handler
) (_("Error: out of memory"));
4217 irela
= (Elf_Internal_Rela
*) bfd_zmalloc (sizeof (Elf_Internal_Rela
)
4218 * bed
->s
->int_rels_per_ext_rel
);
4221 (*_bfd_error_handler
) (_("Error: out of memory"));
4225 for (i
= 0; i
< count
; i
++, rel_hash
++)
4227 if (*rel_hash
== NULL
)
4230 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
4232 if (rel_hdr
->sh_entsize
== sizeof (Elf_External_Rel
))
4234 Elf_External_Rel
*erel
;
4237 erel
= (Elf_External_Rel
*) rel_hdr
->contents
+ i
;
4238 if (bed
->s
->swap_reloc_in
)
4239 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, irel
);
4241 elf_swap_reloc_in (abfd
, erel
, irel
);
4243 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
4244 irel
[j
].r_info
= ELF_R_INFO ((*rel_hash
)->indx
,
4245 ELF_R_TYPE (irel
[j
].r_info
));
4247 if (bed
->s
->swap_reloc_out
)
4248 (*bed
->s
->swap_reloc_out
) (abfd
, irel
, (bfd_byte
*) erel
);
4250 elf_swap_reloc_out (abfd
, irel
, erel
);
4254 Elf_External_Rela
*erela
;
4257 BFD_ASSERT (rel_hdr
->sh_entsize
4258 == sizeof (Elf_External_Rela
));
4260 erela
= (Elf_External_Rela
*) rel_hdr
->contents
+ i
;
4261 if (bed
->s
->swap_reloca_in
)
4262 (*bed
->s
->swap_reloca_in
) (abfd
, (bfd_byte
*) erela
, irela
);
4264 elf_swap_reloca_in (abfd
, erela
, irela
);
4266 for (j
= 0; j
< bed
->s
->int_rels_per_ext_rel
; j
++)
4267 irela
[j
].r_info
= ELF_R_INFO ((*rel_hash
)->indx
,
4268 ELF_R_TYPE (irela
[j
].r_info
));
4270 if (bed
->s
->swap_reloca_out
)
4271 (*bed
->s
->swap_reloca_out
) (abfd
, irela
, (bfd_byte
*) erela
);
4273 elf_swap_reloca_out (abfd
, irela
, erela
);
4281 struct elf_link_sort_rela
{
4283 enum elf_reloc_type_class type
;
4285 Elf_Internal_Rel rel
;
4286 Elf_Internal_Rela rela
;
4291 elf_link_sort_cmp1 (A
, B
)
4295 struct elf_link_sort_rela
*a
= (struct elf_link_sort_rela
*)A
;
4296 struct elf_link_sort_rela
*b
= (struct elf_link_sort_rela
*)B
;
4297 int relativea
, relativeb
;
4299 relativea
= a
->type
== reloc_class_relative
;
4300 relativeb
= b
->type
== reloc_class_relative
;
4302 if (relativea
< relativeb
)
4304 if (relativea
> relativeb
)
4306 if (ELF_R_SYM (a
->u
.rel
.r_info
) < ELF_R_SYM (b
->u
.rel
.r_info
))
4308 if (ELF_R_SYM (a
->u
.rel
.r_info
) > ELF_R_SYM (b
->u
.rel
.r_info
))
4310 if (a
->u
.rel
.r_offset
< b
->u
.rel
.r_offset
)
4312 if (a
->u
.rel
.r_offset
> b
->u
.rel
.r_offset
)
4318 elf_link_sort_cmp2 (A
, B
)
4322 struct elf_link_sort_rela
*a
= (struct elf_link_sort_rela
*)A
;
4323 struct elf_link_sort_rela
*b
= (struct elf_link_sort_rela
*)B
;
4326 if (a
->offset
< b
->offset
)
4328 if (a
->offset
> b
->offset
)
4330 copya
= a
->type
== reloc_class_copy
;
4331 copyb
= b
->type
== reloc_class_copy
;
4336 if (a
->u
.rel
.r_offset
< b
->u
.rel
.r_offset
)
4338 if (a
->u
.rel
.r_offset
> b
->u
.rel
.r_offset
)
4344 elf_link_sort_relocs (abfd
, info
, psec
)
4346 struct bfd_link_info
*info
;
4349 bfd
*dynobj
= elf_hash_table (info
)->dynobj
;
4350 asection
*reldyn
, *o
;
4351 boolean rel
= false;
4352 size_t count
, size
, i
, j
, ret
;
4353 struct elf_link_sort_rela
*rela
;
4354 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4356 reldyn
= bfd_get_section_by_name (abfd
, ".rela.dyn");
4357 if (reldyn
== NULL
|| reldyn
->_raw_size
== 0)
4359 reldyn
= bfd_get_section_by_name (abfd
, ".rel.dyn");
4360 if (reldyn
== NULL
|| reldyn
->_raw_size
== 0)
4363 count
= reldyn
->_raw_size
/ sizeof (Elf_External_Rel
);
4366 count
= reldyn
->_raw_size
/ sizeof (Elf_External_Rela
);
4369 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4370 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4371 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4372 && o
->output_section
== reldyn
)
4373 size
+= o
->_raw_size
;
4375 if (size
!= reldyn
->_raw_size
)
4378 rela
= (struct elf_link_sort_rela
*) calloc (sizeof (*rela
), count
);
4381 (*info
->callbacks
->warning
)
4382 (info
, _("Not enough memory to sort relocations"), 0, abfd
, 0, 0);
4386 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4387 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4388 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4389 && o
->output_section
== reldyn
)
4393 Elf_External_Rel
*erel
, *erelend
;
4394 struct elf_link_sort_rela
*s
;
4396 erel
= (Elf_External_Rel
*) o
->contents
;
4397 erelend
= (Elf_External_Rel
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4398 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rel
);
4399 for (; erel
< erelend
; erel
++, s
++)
4401 if (bed
->s
->swap_reloc_in
)
4402 (*bed
->s
->swap_reloc_in
) (abfd
, (bfd_byte
*) erel
, &s
->u
.rel
);
4404 elf_swap_reloc_in (abfd
, erel
, &s
->u
.rel
);
4406 s
->type
= (*bed
->elf_backend_reloc_type_class
)
4407 (ELF_R_TYPE (s
->u
.rel
.r_info
));
4412 Elf_External_Rela
*erela
, *erelaend
;
4413 struct elf_link_sort_rela
*s
;
4415 erela
= (Elf_External_Rela
*) o
->contents
;
4416 erelaend
= (Elf_External_Rela
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4417 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rela
);
4418 for (; erela
< erelaend
; erela
++, s
++)
4420 if (bed
->s
->swap_reloca_in
)
4421 (*bed
->s
->swap_reloca_in
) (dynobj
, (bfd_byte
*) erela
, &s
->u
.rela
);
4423 elf_swap_reloca_in (dynobj
, erela
, &s
->u
.rela
);
4425 s
->type
= (*bed
->elf_backend_reloc_type_class
)
4426 (ELF_R_TYPE (s
->u
.rel
.r_info
));
4431 qsort (rela
, count
, sizeof (*rela
), elf_link_sort_cmp1
);
4432 for (ret
= 0; ret
< count
&& rela
[ret
].type
== reloc_class_relative
; ret
++)
4434 for (i
= ret
, j
= ret
; i
< count
; i
++)
4436 if (ELF_R_SYM (rela
[i
].u
.rel
.r_info
) != ELF_R_SYM (rela
[j
].u
.rel
.r_info
))
4438 rela
[i
].offset
= rela
[j
].u
.rel
.r_offset
;
4440 qsort (rela
+ ret
, count
- ret
, sizeof (*rela
), elf_link_sort_cmp2
);
4442 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
4443 if ((o
->flags
& (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
))
4444 == (SEC_HAS_CONTENTS
|SEC_LINKER_CREATED
)
4445 && o
->output_section
== reldyn
)
4449 Elf_External_Rel
*erel
, *erelend
;
4450 struct elf_link_sort_rela
*s
;
4452 erel
= (Elf_External_Rel
*) o
->contents
;
4453 erelend
= (Elf_External_Rel
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4454 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rel
);
4455 for (; erel
< erelend
; erel
++, s
++)
4457 if (bed
->s
->swap_reloc_out
)
4458 (*bed
->s
->swap_reloc_out
) (abfd
, &s
->u
.rel
, (bfd_byte
*) erel
);
4460 elf_swap_reloc_out (abfd
, &s
->u
.rel
, erel
);
4465 Elf_External_Rela
*erela
, *erelaend
;
4466 struct elf_link_sort_rela
*s
;
4468 erela
= (Elf_External_Rela
*) o
->contents
;
4469 erelaend
= (Elf_External_Rela
*) ((PTR
) o
->contents
+ o
->_raw_size
);
4470 s
= rela
+ o
->output_offset
/ sizeof (Elf_External_Rela
);
4471 for (; erela
< erelaend
; erela
++, s
++)
4473 if (bed
->s
->swap_reloca_out
)
4474 (*bed
->s
->swap_reloca_out
) (dynobj
, &s
->u
.rela
, (bfd_byte
*) erela
);
4476 elf_swap_reloca_out (dynobj
, &s
->u
.rela
, erela
);
4486 /* Do the final step of an ELF link. */
4489 elf_bfd_final_link (abfd
, info
)
4491 struct bfd_link_info
*info
;
4494 boolean emit_relocs
;
4496 struct elf_final_link_info finfo
;
4497 register asection
*o
;
4498 register struct bfd_link_order
*p
;
4500 size_t max_contents_size
;
4501 size_t max_external_reloc_size
;
4502 size_t max_internal_reloc_count
;
4503 size_t max_sym_count
;
4505 Elf_Internal_Sym elfsym
;
4507 Elf_Internal_Shdr
*symtab_hdr
;
4508 Elf_Internal_Shdr
*symstrtab_hdr
;
4509 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
4510 struct elf_outext_info eoinfo
;
4512 size_t relativecount
= 0;
4513 asection
*reldyn
= 0;
4516 abfd
->flags
|= DYNAMIC
;
4518 dynamic
= elf_hash_table (info
)->dynamic_sections_created
;
4519 dynobj
= elf_hash_table (info
)->dynobj
;
4521 emit_relocs
= (info
->relocateable
4522 || info
->emitrelocations
4523 || bed
->elf_backend_emit_relocs
);
4526 finfo
.output_bfd
= abfd
;
4527 finfo
.symstrtab
= elf_stringtab_init ();
4528 if (finfo
.symstrtab
== NULL
)
4533 finfo
.dynsym_sec
= NULL
;
4534 finfo
.hash_sec
= NULL
;
4535 finfo
.symver_sec
= NULL
;
4539 finfo
.dynsym_sec
= bfd_get_section_by_name (dynobj
, ".dynsym");
4540 finfo
.hash_sec
= bfd_get_section_by_name (dynobj
, ".hash");
4541 BFD_ASSERT (finfo
.dynsym_sec
!= NULL
&& finfo
.hash_sec
!= NULL
);
4542 finfo
.symver_sec
= bfd_get_section_by_name (dynobj
, ".gnu.version");
4543 /* Note that it is OK if symver_sec is NULL. */
4546 finfo
.contents
= NULL
;
4547 finfo
.external_relocs
= NULL
;
4548 finfo
.internal_relocs
= NULL
;
4549 finfo
.external_syms
= NULL
;
4550 finfo
.internal_syms
= NULL
;
4551 finfo
.indices
= NULL
;
4552 finfo
.sections
= NULL
;
4553 finfo
.symbuf
= NULL
;
4554 finfo
.symbuf_count
= 0;
4556 /* Count up the number of relocations we will output for each output
4557 section, so that we know the sizes of the reloc sections. We
4558 also figure out some maximum sizes. */
4559 max_contents_size
= 0;
4560 max_external_reloc_size
= 0;
4561 max_internal_reloc_count
= 0;
4564 for (o
= abfd
->sections
; o
!= (asection
*) NULL
; o
= o
->next
)
4568 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
4570 if (p
->type
== bfd_section_reloc_link_order
4571 || p
->type
== bfd_symbol_reloc_link_order
)
4573 else if (p
->type
== bfd_indirect_link_order
)
4577 sec
= p
->u
.indirect
.section
;
4579 /* Mark all sections which are to be included in the
4580 link. This will normally be every section. We need
4581 to do this so that we can identify any sections which
4582 the linker has decided to not include. */
4583 sec
->linker_mark
= true;
4585 if (sec
->flags
& SEC_MERGE
)
4588 if (info
->relocateable
|| info
->emitrelocations
)
4589 o
->reloc_count
+= sec
->reloc_count
;
4590 else if (bed
->elf_backend_count_relocs
)
4592 Elf_Internal_Rela
* relocs
;
4594 relocs
= (NAME(_bfd_elf
,link_read_relocs
)
4595 (abfd
, sec
, (PTR
) NULL
,
4596 (Elf_Internal_Rela
*) NULL
, info
->keep_memory
));
4598 o
->reloc_count
+= (*bed
->elf_backend_count_relocs
)
4601 if (!info
->keep_memory
)
4605 if (sec
->_raw_size
> max_contents_size
)
4606 max_contents_size
= sec
->_raw_size
;
4607 if (sec
->_cooked_size
> max_contents_size
)
4608 max_contents_size
= sec
->_cooked_size
;
4610 /* We are interested in just local symbols, not all
4612 if (bfd_get_flavour (sec
->owner
) == bfd_target_elf_flavour
4613 && (sec
->owner
->flags
& DYNAMIC
) == 0)
4617 if (elf_bad_symtab (sec
->owner
))
4618 sym_count
= (elf_tdata (sec
->owner
)->symtab_hdr
.sh_size
4619 / sizeof (Elf_External_Sym
));
4621 sym_count
= elf_tdata (sec
->owner
)->symtab_hdr
.sh_info
;
4623 if (sym_count
> max_sym_count
)
4624 max_sym_count
= sym_count
;
4626 if ((sec
->flags
& SEC_RELOC
) != 0)
4630 ext_size
= elf_section_data (sec
)->rel_hdr
.sh_size
;
4631 if (ext_size
> max_external_reloc_size
)
4632 max_external_reloc_size
= ext_size
;
4633 if (sec
->reloc_count
> max_internal_reloc_count
)
4634 max_internal_reloc_count
= sec
->reloc_count
;
4640 if (o
->reloc_count
> 0)
4641 o
->flags
|= SEC_RELOC
;
4644 /* Explicitly clear the SEC_RELOC flag. The linker tends to
4645 set it (this is probably a bug) and if it is set
4646 assign_section_numbers will create a reloc section. */
4647 o
->flags
&=~ SEC_RELOC
;
4650 /* If the SEC_ALLOC flag is not set, force the section VMA to
4651 zero. This is done in elf_fake_sections as well, but forcing
4652 the VMA to 0 here will ensure that relocs against these
4653 sections are handled correctly. */
4654 if ((o
->flags
& SEC_ALLOC
) == 0
4655 && ! o
->user_set_vma
)
4659 if (! info
->relocateable
&& merged
)
4660 elf_link_hash_traverse (elf_hash_table (info
),
4661 elf_link_sec_merge_syms
, (PTR
) abfd
);
4663 /* Figure out the file positions for everything but the symbol table
4664 and the relocs. We set symcount to force assign_section_numbers
4665 to create a symbol table. */
4666 bfd_get_symcount (abfd
) = info
->strip
== strip_all
? 0 : 1;
4667 BFD_ASSERT (! abfd
->output_has_begun
);
4668 if (! _bfd_elf_compute_section_file_positions (abfd
, info
))
4671 /* Figure out how many relocations we will have in each section.
4672 Just using RELOC_COUNT isn't good enough since that doesn't
4673 maintain a separate value for REL vs. RELA relocations. */
4675 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
4676 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
4678 asection
*output_section
;
4680 if (! o
->linker_mark
)
4682 /* This section was omitted from the link. */
4686 output_section
= o
->output_section
;
4688 if (output_section
!= NULL
4689 && (o
->flags
& SEC_RELOC
) != 0)
4691 struct bfd_elf_section_data
*esdi
4692 = elf_section_data (o
);
4693 struct bfd_elf_section_data
*esdo
4694 = elf_section_data (output_section
);
4695 unsigned int *rel_count
;
4696 unsigned int *rel_count2
;
4698 /* We must be careful to add the relocation froms the
4699 input section to the right output count. */
4700 if (esdi
->rel_hdr
.sh_entsize
== esdo
->rel_hdr
.sh_entsize
)
4702 rel_count
= &esdo
->rel_count
;
4703 rel_count2
= &esdo
->rel_count2
;
4707 rel_count
= &esdo
->rel_count2
;
4708 rel_count2
= &esdo
->rel_count
;
4711 *rel_count
+= NUM_SHDR_ENTRIES (& esdi
->rel_hdr
);
4713 *rel_count2
+= NUM_SHDR_ENTRIES (esdi
->rel_hdr2
);
4714 output_section
->flags
|= SEC_RELOC
;
4718 /* That created the reloc sections. Set their sizes, and assign
4719 them file positions, and allocate some buffers. */
4720 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4722 if ((o
->flags
& SEC_RELOC
) != 0)
4724 if (!elf_link_size_reloc_section (abfd
,
4725 &elf_section_data (o
)->rel_hdr
,
4729 if (elf_section_data (o
)->rel_hdr2
4730 && !elf_link_size_reloc_section (abfd
,
4731 elf_section_data (o
)->rel_hdr2
,
4736 /* Now, reset REL_COUNT and REL_COUNT2 so that we can use them
4737 to count upwards while actually outputting the relocations. */
4738 elf_section_data (o
)->rel_count
= 0;
4739 elf_section_data (o
)->rel_count2
= 0;
4742 _bfd_elf_assign_file_positions_for_relocs (abfd
);
4744 /* We have now assigned file positions for all the sections except
4745 .symtab and .strtab. We start the .symtab section at the current
4746 file position, and write directly to it. We build the .strtab
4747 section in memory. */
4748 bfd_get_symcount (abfd
) = 0;
4749 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
4750 /* sh_name is set in prep_headers. */
4751 symtab_hdr
->sh_type
= SHT_SYMTAB
;
4752 symtab_hdr
->sh_flags
= 0;
4753 symtab_hdr
->sh_addr
= 0;
4754 symtab_hdr
->sh_size
= 0;
4755 symtab_hdr
->sh_entsize
= sizeof (Elf_External_Sym
);
4756 /* sh_link is set in assign_section_numbers. */
4757 /* sh_info is set below. */
4758 /* sh_offset is set just below. */
4759 symtab_hdr
->sh_addralign
= bed
->s
->file_align
;
4761 off
= elf_tdata (abfd
)->next_file_pos
;
4762 off
= _bfd_elf_assign_file_position_for_section (symtab_hdr
, off
, true);
4764 /* Note that at this point elf_tdata (abfd)->next_file_pos is
4765 incorrect. We do not yet know the size of the .symtab section.
4766 We correct next_file_pos below, after we do know the size. */
4768 /* Allocate a buffer to hold swapped out symbols. This is to avoid
4769 continuously seeking to the right position in the file. */
4770 if (! info
->keep_memory
|| max_sym_count
< 20)
4771 finfo
.symbuf_size
= 20;
4773 finfo
.symbuf_size
= max_sym_count
;
4774 finfo
.symbuf
= ((Elf_External_Sym
*)
4775 bfd_malloc (finfo
.symbuf_size
* sizeof (Elf_External_Sym
)));
4776 if (finfo
.symbuf
== NULL
)
4779 /* Start writing out the symbol table. The first symbol is always a
4781 if (info
->strip
!= strip_all
4784 elfsym
.st_value
= 0;
4787 elfsym
.st_other
= 0;
4788 elfsym
.st_shndx
= SHN_UNDEF
;
4789 if (! elf_link_output_sym (&finfo
, (const char *) NULL
,
4790 &elfsym
, bfd_und_section_ptr
))
4795 /* Some standard ELF linkers do this, but we don't because it causes
4796 bootstrap comparison failures. */
4797 /* Output a file symbol for the output file as the second symbol.
4798 We output this even if we are discarding local symbols, although
4799 I'm not sure if this is correct. */
4800 elfsym
.st_value
= 0;
4802 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_FILE
);
4803 elfsym
.st_other
= 0;
4804 elfsym
.st_shndx
= SHN_ABS
;
4805 if (! elf_link_output_sym (&finfo
, bfd_get_filename (abfd
),
4806 &elfsym
, bfd_abs_section_ptr
))
4810 /* Output a symbol for each section. We output these even if we are
4811 discarding local symbols, since they are used for relocs. These
4812 symbols have no names. We store the index of each one in the
4813 index field of the section, so that we can find it again when
4814 outputting relocs. */
4815 if (info
->strip
!= strip_all
4819 elfsym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
4820 elfsym
.st_other
= 0;
4821 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
4823 o
= section_from_elf_index (abfd
, i
);
4825 o
->target_index
= bfd_get_symcount (abfd
);
4826 elfsym
.st_shndx
= i
;
4827 if (info
->relocateable
|| o
== NULL
)
4828 elfsym
.st_value
= 0;
4830 elfsym
.st_value
= o
->vma
;
4831 if (! elf_link_output_sym (&finfo
, (const char *) NULL
,
4837 /* Allocate some memory to hold information read in from the input
4839 finfo
.contents
= (bfd_byte
*) bfd_malloc (max_contents_size
);
4840 finfo
.external_relocs
= (PTR
) bfd_malloc (max_external_reloc_size
);
4841 finfo
.internal_relocs
= ((Elf_Internal_Rela
*)
4842 bfd_malloc (max_internal_reloc_count
4843 * sizeof (Elf_Internal_Rela
)
4844 * bed
->s
->int_rels_per_ext_rel
));
4845 finfo
.external_syms
= ((Elf_External_Sym
*)
4846 bfd_malloc (max_sym_count
4847 * sizeof (Elf_External_Sym
)));
4848 finfo
.internal_syms
= ((Elf_Internal_Sym
*)
4849 bfd_malloc (max_sym_count
4850 * sizeof (Elf_Internal_Sym
)));
4851 finfo
.indices
= (long *) bfd_malloc (max_sym_count
* sizeof (long));
4852 finfo
.sections
= ((asection
**)
4853 bfd_malloc (max_sym_count
* sizeof (asection
*)));
4854 if ((finfo
.contents
== NULL
&& max_contents_size
!= 0)
4855 || (finfo
.external_relocs
== NULL
&& max_external_reloc_size
!= 0)
4856 || (finfo
.internal_relocs
== NULL
&& max_internal_reloc_count
!= 0)
4857 || (finfo
.external_syms
== NULL
&& max_sym_count
!= 0)
4858 || (finfo
.internal_syms
== NULL
&& max_sym_count
!= 0)
4859 || (finfo
.indices
== NULL
&& max_sym_count
!= 0)
4860 || (finfo
.sections
== NULL
&& max_sym_count
!= 0))
4863 /* Since ELF permits relocations to be against local symbols, we
4864 must have the local symbols available when we do the relocations.
4865 Since we would rather only read the local symbols once, and we
4866 would rather not keep them in memory, we handle all the
4867 relocations for a single input file at the same time.
4869 Unfortunately, there is no way to know the total number of local
4870 symbols until we have seen all of them, and the local symbol
4871 indices precede the global symbol indices. This means that when
4872 we are generating relocateable output, and we see a reloc against
4873 a global symbol, we can not know the symbol index until we have
4874 finished examining all the local symbols to see which ones we are
4875 going to output. To deal with this, we keep the relocations in
4876 memory, and don't output them until the end of the link. This is
4877 an unfortunate waste of memory, but I don't see a good way around
4878 it. Fortunately, it only happens when performing a relocateable
4879 link, which is not the common case. FIXME: If keep_memory is set
4880 we could write the relocs out and then read them again; I don't
4881 know how bad the memory loss will be. */
4883 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
4884 sub
->output_has_begun
= false;
4885 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
4887 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
4889 if (p
->type
== bfd_indirect_link_order
4890 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
4891 == bfd_target_elf_flavour
))
4893 sub
= p
->u
.indirect
.section
->owner
;
4894 if (! sub
->output_has_begun
)
4896 if (! elf_link_input_bfd (&finfo
, sub
))
4898 sub
->output_has_begun
= true;
4901 else if (p
->type
== bfd_section_reloc_link_order
4902 || p
->type
== bfd_symbol_reloc_link_order
)
4904 if (! elf_reloc_link_order (abfd
, info
, o
, p
))
4909 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
4915 /* That wrote out all the local symbols. Finish up the symbol table
4916 with the global symbols. Even if we want to strip everything we
4917 can, we still need to deal with those global symbols that got
4918 converted to local in a version script. */
4922 /* Output any global symbols that got converted to local in a
4923 version script. We do this in a separate step since ELF
4924 requires all local symbols to appear prior to any global
4925 symbols. FIXME: We should only do this if some global
4926 symbols were, in fact, converted to become local. FIXME:
4927 Will this work correctly with the Irix 5 linker? */
4928 eoinfo
.failed
= false;
4929 eoinfo
.finfo
= &finfo
;
4930 eoinfo
.localsyms
= true;
4931 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
4937 /* The sh_info field records the index of the first non local symbol. */
4938 symtab_hdr
->sh_info
= bfd_get_symcount (abfd
);
4941 && finfo
.dynsym_sec
->output_section
!= bfd_abs_section_ptr
)
4943 Elf_Internal_Sym sym
;
4944 Elf_External_Sym
*dynsym
=
4945 (Elf_External_Sym
*) finfo
.dynsym_sec
->contents
;
4946 long last_local
= 0;
4948 /* Write out the section symbols for the output sections. */
4955 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
4958 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
4961 indx
= elf_section_data (s
)->this_idx
;
4962 BFD_ASSERT (indx
> 0);
4963 sym
.st_shndx
= indx
;
4964 sym
.st_value
= s
->vma
;
4966 elf_swap_symbol_out (abfd
, &sym
,
4967 dynsym
+ elf_section_data (s
)->dynindx
);
4970 last_local
= bfd_count_sections (abfd
);
4973 /* Write out the local dynsyms. */
4974 if (elf_hash_table (info
)->dynlocal
)
4976 struct elf_link_local_dynamic_entry
*e
;
4977 for (e
= elf_hash_table (info
)->dynlocal
; e
; e
= e
->next
)
4981 sym
.st_size
= e
->isym
.st_size
;
4982 sym
.st_other
= e
->isym
.st_other
;
4984 /* Copy the internal symbol as is.
4985 Note that we saved a word of storage and overwrote
4986 the original st_name with the dynstr_index. */
4989 if (e
->isym
.st_shndx
> 0 && e
->isym
.st_shndx
< SHN_LORESERVE
)
4991 s
= bfd_section_from_elf_index (e
->input_bfd
,
4995 elf_section_data (s
->output_section
)->this_idx
;
4996 sym
.st_value
= (s
->output_section
->vma
4998 + e
->isym
.st_value
);
5001 if (last_local
< e
->dynindx
)
5002 last_local
= e
->dynindx
;
5004 elf_swap_symbol_out (abfd
, &sym
, dynsym
+ e
->dynindx
);
5008 elf_section_data (finfo
.dynsym_sec
->output_section
)->this_hdr
.sh_info
=
5012 /* We get the global symbols from the hash table. */
5013 eoinfo
.failed
= false;
5014 eoinfo
.localsyms
= false;
5015 eoinfo
.finfo
= &finfo
;
5016 elf_link_hash_traverse (elf_hash_table (info
), elf_link_output_extsym
,
5021 /* If backend needs to output some symbols not present in the hash
5022 table, do it now. */
5023 if (bed
->elf_backend_output_arch_syms
)
5025 if (! (*bed
->elf_backend_output_arch_syms
)
5026 (abfd
, info
, (PTR
) &finfo
,
5027 (boolean (*) PARAMS ((PTR
, const char *,
5028 Elf_Internal_Sym
*, asection
*)))
5029 elf_link_output_sym
))
5033 /* Flush all symbols to the file. */
5034 if (! elf_link_flush_output_syms (&finfo
))
5037 /* Now we know the size of the symtab section. */
5038 off
+= symtab_hdr
->sh_size
;
5040 /* Finish up and write out the symbol string table (.strtab)
5042 symstrtab_hdr
= &elf_tdata (abfd
)->strtab_hdr
;
5043 /* sh_name was set in prep_headers. */
5044 symstrtab_hdr
->sh_type
= SHT_STRTAB
;
5045 symstrtab_hdr
->sh_flags
= 0;
5046 symstrtab_hdr
->sh_addr
= 0;
5047 symstrtab_hdr
->sh_size
= _bfd_stringtab_size (finfo
.symstrtab
);
5048 symstrtab_hdr
->sh_entsize
= 0;
5049 symstrtab_hdr
->sh_link
= 0;
5050 symstrtab_hdr
->sh_info
= 0;
5051 /* sh_offset is set just below. */
5052 symstrtab_hdr
->sh_addralign
= 1;
5054 off
= _bfd_elf_assign_file_position_for_section (symstrtab_hdr
, off
, true);
5055 elf_tdata (abfd
)->next_file_pos
= off
;
5057 if (bfd_get_symcount (abfd
) > 0)
5059 if (bfd_seek (abfd
, symstrtab_hdr
->sh_offset
, SEEK_SET
) != 0
5060 || ! _bfd_stringtab_emit (abfd
, finfo
.symstrtab
))
5064 /* Adjust the relocs to have the correct symbol indices. */
5065 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5067 if ((o
->flags
& SEC_RELOC
) == 0)
5070 elf_link_adjust_relocs (abfd
, &elf_section_data (o
)->rel_hdr
,
5071 elf_section_data (o
)->rel_count
,
5072 elf_section_data (o
)->rel_hashes
);
5073 if (elf_section_data (o
)->rel_hdr2
!= NULL
)
5074 elf_link_adjust_relocs (abfd
, elf_section_data (o
)->rel_hdr2
,
5075 elf_section_data (o
)->rel_count2
,
5076 (elf_section_data (o
)->rel_hashes
5077 + elf_section_data (o
)->rel_count
));
5079 /* Set the reloc_count field to 0 to prevent write_relocs from
5080 trying to swap the relocs out itself. */
5084 if (dynamic
&& info
->combreloc
&& dynobj
!= NULL
)
5085 relativecount
= elf_link_sort_relocs (abfd
, info
, &reldyn
);
5087 /* If we are linking against a dynamic object, or generating a
5088 shared library, finish up the dynamic linking information. */
5091 Elf_External_Dyn
*dyncon
, *dynconend
;
5093 /* Fix up .dynamic entries. */
5094 o
= bfd_get_section_by_name (dynobj
, ".dynamic");
5095 BFD_ASSERT (o
!= NULL
);
5097 dyncon
= (Elf_External_Dyn
*) o
->contents
;
5098 dynconend
= (Elf_External_Dyn
*) (o
->contents
+ o
->_raw_size
);
5099 for (; dyncon
< dynconend
; dyncon
++)
5101 Elf_Internal_Dyn dyn
;
5105 elf_swap_dyn_in (dynobj
, dyncon
, &dyn
);
5112 if (relativecount
> 0 && dyncon
+ 1 < dynconend
)
5114 switch (elf_section_data (reldyn
)->this_hdr
.sh_type
)
5116 case SHT_REL
: dyn
.d_tag
= DT_RELCOUNT
; break;
5117 case SHT_RELA
: dyn
.d_tag
= DT_RELACOUNT
; break;
5120 if (dyn
.d_tag
!= DT_NULL
)
5122 dyn
.d_un
.d_val
= relativecount
;
5123 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5129 name
= info
->init_function
;
5132 name
= info
->fini_function
;
5135 struct elf_link_hash_entry
*h
;
5137 h
= elf_link_hash_lookup (elf_hash_table (info
), name
,
5138 false, false, true);
5140 && (h
->root
.type
== bfd_link_hash_defined
5141 || h
->root
.type
== bfd_link_hash_defweak
))
5143 dyn
.d_un
.d_val
= h
->root
.u
.def
.value
;
5144 o
= h
->root
.u
.def
.section
;
5145 if (o
->output_section
!= NULL
)
5146 dyn
.d_un
.d_val
+= (o
->output_section
->vma
5147 + o
->output_offset
);
5150 /* The symbol is imported from another shared
5151 library and does not apply to this one. */
5155 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5170 name
= ".gnu.version_d";
5173 name
= ".gnu.version_r";
5176 name
= ".gnu.version";
5178 o
= bfd_get_section_by_name (abfd
, name
);
5179 BFD_ASSERT (o
!= NULL
);
5180 dyn
.d_un
.d_ptr
= o
->vma
;
5181 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5188 if (dyn
.d_tag
== DT_REL
|| dyn
.d_tag
== DT_RELSZ
)
5193 for (i
= 1; i
< elf_elfheader (abfd
)->e_shnum
; i
++)
5195 Elf_Internal_Shdr
*hdr
;
5197 hdr
= elf_elfsections (abfd
)[i
];
5198 if (hdr
->sh_type
== type
5199 && (hdr
->sh_flags
& SHF_ALLOC
) != 0)
5201 if (dyn
.d_tag
== DT_RELSZ
|| dyn
.d_tag
== DT_RELASZ
)
5202 dyn
.d_un
.d_val
+= hdr
->sh_size
;
5205 if (dyn
.d_un
.d_val
== 0
5206 || hdr
->sh_addr
< dyn
.d_un
.d_val
)
5207 dyn
.d_un
.d_val
= hdr
->sh_addr
;
5211 elf_swap_dyn_out (dynobj
, &dyn
, dyncon
);
5217 /* If we have created any dynamic sections, then output them. */
5220 if (! (*bed
->elf_backend_finish_dynamic_sections
) (abfd
, info
))
5223 for (o
= dynobj
->sections
; o
!= NULL
; o
= o
->next
)
5225 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
5226 || o
->_raw_size
== 0
5227 || o
->output_section
== bfd_abs_section_ptr
)
5229 if ((o
->flags
& SEC_LINKER_CREATED
) == 0)
5231 /* At this point, we are only interested in sections
5232 created by elf_link_create_dynamic_sections. */
5235 if ((elf_section_data (o
->output_section
)->this_hdr
.sh_type
5237 || strcmp (bfd_get_section_name (abfd
, o
), ".dynstr") != 0)
5239 if (! bfd_set_section_contents (abfd
, o
->output_section
,
5240 o
->contents
, o
->output_offset
,
5248 /* The contents of the .dynstr section are actually in a
5250 off
= elf_section_data (o
->output_section
)->this_hdr
.sh_offset
;
5251 if (bfd_seek (abfd
, off
, SEEK_SET
) != 0
5252 || ! _bfd_stringtab_emit (abfd
,
5253 elf_hash_table (info
)->dynstr
))
5259 /* If we have optimized stabs strings, output them. */
5260 if (elf_hash_table (info
)->stab_info
!= NULL
)
5262 if (! _bfd_write_stab_strings (abfd
, &elf_hash_table (info
)->stab_info
))
5266 if (finfo
.symstrtab
!= NULL
)
5267 _bfd_stringtab_free (finfo
.symstrtab
);
5268 if (finfo
.contents
!= NULL
)
5269 free (finfo
.contents
);
5270 if (finfo
.external_relocs
!= NULL
)
5271 free (finfo
.external_relocs
);
5272 if (finfo
.internal_relocs
!= NULL
)
5273 free (finfo
.internal_relocs
);
5274 if (finfo
.external_syms
!= NULL
)
5275 free (finfo
.external_syms
);
5276 if (finfo
.internal_syms
!= NULL
)
5277 free (finfo
.internal_syms
);
5278 if (finfo
.indices
!= NULL
)
5279 free (finfo
.indices
);
5280 if (finfo
.sections
!= NULL
)
5281 free (finfo
.sections
);
5282 if (finfo
.symbuf
!= NULL
)
5283 free (finfo
.symbuf
);
5284 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5286 if ((o
->flags
& SEC_RELOC
) != 0
5287 && elf_section_data (o
)->rel_hashes
!= NULL
)
5288 free (elf_section_data (o
)->rel_hashes
);
5291 elf_tdata (abfd
)->linker
= true;
5296 if (finfo
.symstrtab
!= NULL
)
5297 _bfd_stringtab_free (finfo
.symstrtab
);
5298 if (finfo
.contents
!= NULL
)
5299 free (finfo
.contents
);
5300 if (finfo
.external_relocs
!= NULL
)
5301 free (finfo
.external_relocs
);
5302 if (finfo
.internal_relocs
!= NULL
)
5303 free (finfo
.internal_relocs
);
5304 if (finfo
.external_syms
!= NULL
)
5305 free (finfo
.external_syms
);
5306 if (finfo
.internal_syms
!= NULL
)
5307 free (finfo
.internal_syms
);
5308 if (finfo
.indices
!= NULL
)
5309 free (finfo
.indices
);
5310 if (finfo
.sections
!= NULL
)
5311 free (finfo
.sections
);
5312 if (finfo
.symbuf
!= NULL
)
5313 free (finfo
.symbuf
);
5314 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5316 if ((o
->flags
& SEC_RELOC
) != 0
5317 && elf_section_data (o
)->rel_hashes
!= NULL
)
5318 free (elf_section_data (o
)->rel_hashes
);
5324 /* Add a symbol to the output symbol table. */
5327 elf_link_output_sym (finfo
, name
, elfsym
, input_sec
)
5328 struct elf_final_link_info
*finfo
;
5330 Elf_Internal_Sym
*elfsym
;
5331 asection
*input_sec
;
5333 boolean (*output_symbol_hook
) PARAMS ((bfd
*,
5334 struct bfd_link_info
*info
,
5339 output_symbol_hook
= get_elf_backend_data (finfo
->output_bfd
)->
5340 elf_backend_link_output_symbol_hook
;
5341 if (output_symbol_hook
!= NULL
)
5343 if (! ((*output_symbol_hook
)
5344 (finfo
->output_bfd
, finfo
->info
, name
, elfsym
, input_sec
)))
5348 if (name
== (const char *) NULL
|| *name
== '\0')
5349 elfsym
->st_name
= 0;
5350 else if (input_sec
->flags
& SEC_EXCLUDE
)
5351 elfsym
->st_name
= 0;
5354 elfsym
->st_name
= (unsigned long) _bfd_stringtab_add (finfo
->symstrtab
,
5356 if (elfsym
->st_name
== (unsigned long) -1)
5360 if (finfo
->symbuf_count
>= finfo
->symbuf_size
)
5362 if (! elf_link_flush_output_syms (finfo
))
5366 elf_swap_symbol_out (finfo
->output_bfd
, elfsym
,
5367 (PTR
) (finfo
->symbuf
+ finfo
->symbuf_count
));
5368 ++finfo
->symbuf_count
;
5370 ++ bfd_get_symcount (finfo
->output_bfd
);
5375 /* Flush the output symbols to the file. */
5378 elf_link_flush_output_syms (finfo
)
5379 struct elf_final_link_info
*finfo
;
5381 if (finfo
->symbuf_count
> 0)
5383 Elf_Internal_Shdr
*symtab
;
5385 symtab
= &elf_tdata (finfo
->output_bfd
)->symtab_hdr
;
5387 if (bfd_seek (finfo
->output_bfd
, symtab
->sh_offset
+ symtab
->sh_size
,
5389 || (bfd_write ((PTR
) finfo
->symbuf
, finfo
->symbuf_count
,
5390 sizeof (Elf_External_Sym
), finfo
->output_bfd
)
5391 != finfo
->symbuf_count
* sizeof (Elf_External_Sym
)))
5394 symtab
->sh_size
+= finfo
->symbuf_count
* sizeof (Elf_External_Sym
);
5396 finfo
->symbuf_count
= 0;
5402 /* Adjust all external symbols pointing into SEC_MERGE sections
5403 to reflect the object merging within the sections. */
5406 elf_link_sec_merge_syms (h
, data
)
5407 struct elf_link_hash_entry
*h
;
5412 if ((h
->root
.type
== bfd_link_hash_defined
5413 || h
->root
.type
== bfd_link_hash_defweak
)
5414 && ((sec
= h
->root
.u
.def
.section
)->flags
& SEC_MERGE
)
5415 && elf_section_data (sec
)->merge_info
)
5417 bfd
*output_bfd
= (bfd
*) data
;
5419 h
->root
.u
.def
.value
=
5420 _bfd_merged_section_offset (output_bfd
,
5421 &h
->root
.u
.def
.section
,
5422 elf_section_data (sec
)->merge_info
,
5423 h
->root
.u
.def
.value
, (bfd_vma
) 0);
5429 /* Add an external symbol to the symbol table. This is called from
5430 the hash table traversal routine. When generating a shared object,
5431 we go through the symbol table twice. The first time we output
5432 anything that might have been forced to local scope in a version
5433 script. The second time we output the symbols that are still
5437 elf_link_output_extsym (h
, data
)
5438 struct elf_link_hash_entry
*h
;
5441 struct elf_outext_info
*eoinfo
= (struct elf_outext_info
*) data
;
5442 struct elf_final_link_info
*finfo
= eoinfo
->finfo
;
5444 Elf_Internal_Sym sym
;
5445 asection
*input_sec
;
5447 /* Decide whether to output this symbol in this pass. */
5448 if (eoinfo
->localsyms
)
5450 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5455 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5459 /* If we are not creating a shared library, and this symbol is
5460 referenced by a shared library but is not defined anywhere, then
5461 warn that it is undefined. If we do not do this, the runtime
5462 linker will complain that the symbol is undefined when the
5463 program is run. We don't have to worry about symbols that are
5464 referenced by regular files, because we will already have issued
5465 warnings for them. */
5466 if (! finfo
->info
->relocateable
5467 && ! finfo
->info
->allow_shlib_undefined
5468 && ! finfo
->info
->shared
5469 && h
->root
.type
== bfd_link_hash_undefined
5470 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0
5471 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
5473 if (! ((*finfo
->info
->callbacks
->undefined_symbol
)
5474 (finfo
->info
, h
->root
.root
.string
, h
->root
.u
.undef
.abfd
,
5475 (asection
*) NULL
, 0, true)))
5477 eoinfo
->failed
= true;
5482 /* We don't want to output symbols that have never been mentioned by
5483 a regular file, or that we have been told to strip. However, if
5484 h->indx is set to -2, the symbol is used by a reloc and we must
5488 else if (((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) != 0
5489 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) != 0)
5490 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0
5491 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) == 0)
5493 else if (finfo
->info
->strip
== strip_all
5494 || (finfo
->info
->strip
== strip_some
5495 && bfd_hash_lookup (finfo
->info
->keep_hash
,
5496 h
->root
.root
.string
,
5497 false, false) == NULL
))
5502 /* If we're stripping it, and it's not a dynamic symbol, there's
5503 nothing else to do unless it is a forced local symbol. */
5506 && (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) == 0)
5510 sym
.st_size
= h
->size
;
5511 sym
.st_other
= h
->other
;
5512 if ((h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5513 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, h
->type
);
5514 else if (h
->root
.type
== bfd_link_hash_undefweak
5515 || h
->root
.type
== bfd_link_hash_defweak
)
5516 sym
.st_info
= ELF_ST_INFO (STB_WEAK
, h
->type
);
5518 sym
.st_info
= ELF_ST_INFO (STB_GLOBAL
, h
->type
);
5520 switch (h
->root
.type
)
5523 case bfd_link_hash_new
:
5527 case bfd_link_hash_undefined
:
5528 input_sec
= bfd_und_section_ptr
;
5529 sym
.st_shndx
= SHN_UNDEF
;
5532 case bfd_link_hash_undefweak
:
5533 input_sec
= bfd_und_section_ptr
;
5534 sym
.st_shndx
= SHN_UNDEF
;
5537 case bfd_link_hash_defined
:
5538 case bfd_link_hash_defweak
:
5540 input_sec
= h
->root
.u
.def
.section
;
5541 if (input_sec
->output_section
!= NULL
)
5544 _bfd_elf_section_from_bfd_section (finfo
->output_bfd
,
5545 input_sec
->output_section
);
5546 if (sym
.st_shndx
== (unsigned short) -1)
5548 (*_bfd_error_handler
)
5549 (_("%s: could not find output section %s for input section %s"),
5550 bfd_get_filename (finfo
->output_bfd
),
5551 input_sec
->output_section
->name
,
5553 eoinfo
->failed
= true;
5557 /* ELF symbols in relocateable files are section relative,
5558 but in nonrelocateable files they are virtual
5560 sym
.st_value
= h
->root
.u
.def
.value
+ input_sec
->output_offset
;
5561 if (! finfo
->info
->relocateable
)
5562 sym
.st_value
+= input_sec
->output_section
->vma
;
5566 BFD_ASSERT (input_sec
->owner
== NULL
5567 || (input_sec
->owner
->flags
& DYNAMIC
) != 0);
5568 sym
.st_shndx
= SHN_UNDEF
;
5569 input_sec
= bfd_und_section_ptr
;
5574 case bfd_link_hash_common
:
5575 input_sec
= h
->root
.u
.c
.p
->section
;
5576 sym
.st_shndx
= SHN_COMMON
;
5577 sym
.st_value
= 1 << h
->root
.u
.c
.p
->alignment_power
;
5580 case bfd_link_hash_indirect
:
5581 /* These symbols are created by symbol versioning. They point
5582 to the decorated version of the name. For example, if the
5583 symbol foo@@GNU_1.2 is the default, which should be used when
5584 foo is used with no version, then we add an indirect symbol
5585 foo which points to foo@@GNU_1.2. We ignore these symbols,
5586 since the indirected symbol is already in the hash table. */
5589 case bfd_link_hash_warning
:
5590 /* We can't represent these symbols in ELF, although a warning
5591 symbol may have come from a .gnu.warning.SYMBOL section. We
5592 just put the target symbol in the hash table. If the target
5593 symbol does not really exist, don't do anything. */
5594 if (h
->root
.u
.i
.link
->type
== bfd_link_hash_new
)
5596 return (elf_link_output_extsym
5597 ((struct elf_link_hash_entry
*) h
->root
.u
.i
.link
, data
));
5600 /* Give the processor backend a chance to tweak the symbol value,
5601 and also to finish up anything that needs to be done for this
5603 if ((h
->dynindx
!= -1
5604 || (h
->elf_link_hash_flags
& ELF_LINK_FORCED_LOCAL
) != 0)
5605 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
5607 struct elf_backend_data
*bed
;
5609 bed
= get_elf_backend_data (finfo
->output_bfd
);
5610 if (! ((*bed
->elf_backend_finish_dynamic_symbol
)
5611 (finfo
->output_bfd
, finfo
->info
, h
, &sym
)))
5613 eoinfo
->failed
= true;
5618 /* If we are marking the symbol as undefined, and there are no
5619 non-weak references to this symbol from a regular object, then
5620 mark the symbol as weak undefined; if there are non-weak
5621 references, mark the symbol as strong. We can't do this earlier,
5622 because it might not be marked as undefined until the
5623 finish_dynamic_symbol routine gets through with it. */
5624 if (sym
.st_shndx
== SHN_UNDEF
5625 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR
) != 0
5626 && (ELF_ST_BIND (sym
.st_info
) == STB_GLOBAL
5627 || ELF_ST_BIND (sym
.st_info
) == STB_WEAK
))
5631 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_REGULAR_NONWEAK
) != 0)
5632 bindtype
= STB_GLOBAL
;
5634 bindtype
= STB_WEAK
;
5635 sym
.st_info
= ELF_ST_INFO (bindtype
, ELF_ST_TYPE (sym
.st_info
));
5638 /* If a symbol is not defined locally, we clear the visibility
5640 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5641 sym
.st_other
^= ELF_ST_VISIBILITY (sym
.st_other
);
5643 /* If this symbol should be put in the .dynsym section, then put it
5644 there now. We have already know the symbol index. We also fill
5645 in the entry in the .hash section. */
5646 if (h
->dynindx
!= -1
5647 && elf_hash_table (finfo
->info
)->dynamic_sections_created
)
5651 size_t hash_entry_size
;
5652 bfd_byte
*bucketpos
;
5655 sym
.st_name
= h
->dynstr_index
;
5657 elf_swap_symbol_out (finfo
->output_bfd
, &sym
,
5658 (PTR
) (((Elf_External_Sym
*)
5659 finfo
->dynsym_sec
->contents
)
5662 bucketcount
= elf_hash_table (finfo
->info
)->bucketcount
;
5663 bucket
= h
->elf_hash_value
% bucketcount
;
5665 = elf_section_data (finfo
->hash_sec
)->this_hdr
.sh_entsize
;
5666 bucketpos
= ((bfd_byte
*) finfo
->hash_sec
->contents
5667 + (bucket
+ 2) * hash_entry_size
);
5668 chain
= bfd_get (8 * hash_entry_size
, finfo
->output_bfd
, bucketpos
);
5669 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, h
->dynindx
, bucketpos
);
5670 bfd_put (8 * hash_entry_size
, finfo
->output_bfd
, chain
,
5671 ((bfd_byte
*) finfo
->hash_sec
->contents
5672 + (bucketcount
+ 2 + h
->dynindx
) * hash_entry_size
));
5674 if (finfo
->symver_sec
!= NULL
&& finfo
->symver_sec
->contents
!= NULL
)
5676 Elf_Internal_Versym iversym
;
5678 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
5680 if (h
->verinfo
.verdef
== NULL
)
5681 iversym
.vs_vers
= 0;
5683 iversym
.vs_vers
= h
->verinfo
.verdef
->vd_exp_refno
+ 1;
5687 if (h
->verinfo
.vertree
== NULL
)
5688 iversym
.vs_vers
= 1;
5690 iversym
.vs_vers
= h
->verinfo
.vertree
->vernum
+ 1;
5693 if ((h
->elf_link_hash_flags
& ELF_LINK_HIDDEN
) != 0)
5694 iversym
.vs_vers
|= VERSYM_HIDDEN
;
5696 _bfd_elf_swap_versym_out (finfo
->output_bfd
, &iversym
,
5697 (((Elf_External_Versym
*)
5698 finfo
->symver_sec
->contents
)
5703 /* If we're stripping it, then it was just a dynamic symbol, and
5704 there's nothing else to do. */
5708 h
->indx
= bfd_get_symcount (finfo
->output_bfd
);
5710 if (! elf_link_output_sym (finfo
, h
->root
.root
.string
, &sym
, input_sec
))
5712 eoinfo
->failed
= true;
5719 /* Copy the relocations indicated by the INTERNAL_RELOCS (which
5720 originated from the section given by INPUT_REL_HDR) to the
5724 elf_link_output_relocs (output_bfd
, input_section
, input_rel_hdr
,
5727 asection
*input_section
;
5728 Elf_Internal_Shdr
*input_rel_hdr
;
5729 Elf_Internal_Rela
*internal_relocs
;
5731 Elf_Internal_Rela
*irela
;
5732 Elf_Internal_Rela
*irelaend
;
5733 Elf_Internal_Shdr
*output_rel_hdr
;
5734 asection
*output_section
;
5735 unsigned int *rel_countp
= NULL
;
5736 struct elf_backend_data
*bed
;
5738 output_section
= input_section
->output_section
;
5739 output_rel_hdr
= NULL
;
5741 if (elf_section_data (output_section
)->rel_hdr
.sh_entsize
5742 == input_rel_hdr
->sh_entsize
)
5744 output_rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
5745 rel_countp
= &elf_section_data (output_section
)->rel_count
;
5747 else if (elf_section_data (output_section
)->rel_hdr2
5748 && (elf_section_data (output_section
)->rel_hdr2
->sh_entsize
5749 == input_rel_hdr
->sh_entsize
))
5751 output_rel_hdr
= elf_section_data (output_section
)->rel_hdr2
;
5752 rel_countp
= &elf_section_data (output_section
)->rel_count2
;
5755 BFD_ASSERT (output_rel_hdr
!= NULL
);
5757 bed
= get_elf_backend_data (output_bfd
);
5758 irela
= internal_relocs
;
5759 irelaend
= irela
+ NUM_SHDR_ENTRIES (input_rel_hdr
)
5760 * bed
->s
->int_rels_per_ext_rel
;
5762 if (input_rel_hdr
->sh_entsize
== sizeof (Elf_External_Rel
))
5764 Elf_External_Rel
*erel
;
5765 Elf_Internal_Rel
*irel
;
5767 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
5768 * sizeof (Elf_Internal_Rel
));
5771 (*_bfd_error_handler
) (_("Error: out of memory"));
5775 erel
= ((Elf_External_Rel
*) output_rel_hdr
->contents
+ *rel_countp
);
5776 for (; irela
< irelaend
; irela
+= bed
->s
->int_rels_per_ext_rel
, erel
++)
5780 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
5782 irel
[i
].r_offset
= irela
[i
].r_offset
;
5783 irel
[i
].r_info
= irela
[i
].r_info
;
5784 BFD_ASSERT (irela
[i
].r_addend
== 0);
5787 if (bed
->s
->swap_reloc_out
)
5788 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, (PTR
) erel
);
5790 elf_swap_reloc_out (output_bfd
, irel
, erel
);
5797 Elf_External_Rela
*erela
;
5799 BFD_ASSERT (input_rel_hdr
->sh_entsize
== sizeof (Elf_External_Rela
));
5801 erela
= ((Elf_External_Rela
*) output_rel_hdr
->contents
+ *rel_countp
);
5802 for (; irela
< irelaend
; irela
+= bed
->s
->int_rels_per_ext_rel
, erela
++)
5803 if (bed
->s
->swap_reloca_out
)
5804 (*bed
->s
->swap_reloca_out
) (output_bfd
, irela
, (PTR
) erela
);
5806 elf_swap_reloca_out (output_bfd
, irela
, erela
);
5809 /* Bump the counter, so that we know where to add the next set of
5811 *rel_countp
+= NUM_SHDR_ENTRIES (input_rel_hdr
);
5814 /* Link an input file into the linker output file. This function
5815 handles all the sections and relocations of the input file at once.
5816 This is so that we only have to read the local symbols once, and
5817 don't have to keep them in memory. */
5820 elf_link_input_bfd (finfo
, input_bfd
)
5821 struct elf_final_link_info
*finfo
;
5824 boolean (*relocate_section
) PARAMS ((bfd
*, struct bfd_link_info
*,
5825 bfd
*, asection
*, bfd_byte
*,
5826 Elf_Internal_Rela
*,
5827 Elf_Internal_Sym
*, asection
**));
5829 Elf_Internal_Shdr
*symtab_hdr
;
5832 Elf_External_Sym
*external_syms
;
5833 Elf_External_Sym
*esym
;
5834 Elf_External_Sym
*esymend
;
5835 Elf_Internal_Sym
*isym
;
5837 asection
**ppsection
;
5839 struct elf_backend_data
*bed
;
5840 boolean emit_relocs
;
5842 output_bfd
= finfo
->output_bfd
;
5843 bed
= get_elf_backend_data (output_bfd
);
5844 relocate_section
= bed
->elf_backend_relocate_section
;
5846 /* If this is a dynamic object, we don't want to do anything here:
5847 we don't want the local symbols, and we don't want the section
5849 if ((input_bfd
->flags
& DYNAMIC
) != 0)
5852 emit_relocs
= (finfo
->info
->relocateable
5853 || finfo
->info
->emitrelocations
5854 || bed
->elf_backend_emit_relocs
);
5856 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
5857 if (elf_bad_symtab (input_bfd
))
5859 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
5864 locsymcount
= symtab_hdr
->sh_info
;
5865 extsymoff
= symtab_hdr
->sh_info
;
5868 /* Read the local symbols. */
5869 if (symtab_hdr
->contents
!= NULL
)
5870 external_syms
= (Elf_External_Sym
*) symtab_hdr
->contents
;
5871 else if (locsymcount
== 0)
5872 external_syms
= NULL
;
5875 external_syms
= finfo
->external_syms
;
5876 if (bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
5877 || (bfd_read (external_syms
, sizeof (Elf_External_Sym
),
5878 locsymcount
, input_bfd
)
5879 != locsymcount
* sizeof (Elf_External_Sym
)))
5883 /* Swap in the local symbols and write out the ones which we know
5884 are going into the output file. */
5885 esym
= external_syms
;
5886 esymend
= esym
+ locsymcount
;
5887 isym
= finfo
->internal_syms
;
5888 pindex
= finfo
->indices
;
5889 ppsection
= finfo
->sections
;
5890 for (; esym
< esymend
; esym
++, isym
++, pindex
++, ppsection
++)
5894 Elf_Internal_Sym osym
;
5896 elf_swap_symbol_in (input_bfd
, esym
, isym
);
5899 if (elf_bad_symtab (input_bfd
))
5901 if (ELF_ST_BIND (isym
->st_info
) != STB_LOCAL
)
5909 if (isym
->st_shndx
== SHN_UNDEF
)
5911 isec
= bfd_und_section_ptr
;
5914 else if (isym
->st_shndx
> 0 && isym
->st_shndx
< SHN_LORESERVE
)
5916 isec
= section_from_elf_index (input_bfd
, isym
->st_shndx
);
5917 if (isec
&& elf_section_data (isec
)->merge_info
5918 && ELF_ST_TYPE (isym
->st_info
) != STT_SECTION
)
5920 _bfd_merged_section_offset (output_bfd
, &isec
,
5921 elf_section_data (isec
)->merge_info
,
5922 isym
->st_value
, (bfd_vma
) 0);
5924 else if (isym
->st_shndx
== SHN_ABS
)
5926 isec
= bfd_abs_section_ptr
;
5929 else if (isym
->st_shndx
== SHN_COMMON
)
5931 isec
= bfd_com_section_ptr
;
5942 /* Don't output the first, undefined, symbol. */
5943 if (esym
== external_syms
)
5946 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
5950 /* Save away all section symbol values. */
5955 if (isec
->symbol
->value
!= isym
->st_value
)
5956 (*_bfd_error_handler
)
5957 (_("%s: invalid section symbol index 0x%x (%s) ingored"),
5958 bfd_get_filename (input_bfd
), isym
->st_shndx
,
5962 isec
->symbol
->value
= isym
->st_value
;
5965 /* If this is a discarded link-once section symbol, update
5966 it's value to that of the kept section symbol. The
5967 linker will keep the first of any matching link-once
5968 sections, so we should have already seen it's section
5969 symbol. I trust no-one will have the bright idea of
5970 re-ordering the bfd list... */
5972 && (bfd_get_section_flags (input_bfd
, isec
) & SEC_LINK_ONCE
) != 0
5973 && (ksec
= isec
->kept_section
) != NULL
)
5975 isym
->st_value
= ksec
->symbol
->value
;
5977 /* That put the value right, but the section info is all
5978 wrong. I hope this works. */
5979 isec
->output_offset
= ksec
->output_offset
;
5980 isec
->output_section
= ksec
->output_section
;
5983 /* We never output section symbols. Instead, we use the
5984 section symbol of the corresponding section in the output
5989 /* If we are stripping all symbols, we don't want to output this
5991 if (finfo
->info
->strip
== strip_all
)
5994 /* If we are discarding all local symbols, we don't want to
5995 output this one. If we are generating a relocateable output
5996 file, then some of the local symbols may be required by
5997 relocs; we output them below as we discover that they are
5999 if (finfo
->info
->discard
== discard_all
)
6002 /* If this symbol is defined in a section which we are
6003 discarding, we don't need to keep it, but note that
6004 linker_mark is only reliable for sections that have contents.
6005 For the benefit of the MIPS ELF linker, we check SEC_EXCLUDE
6006 as well as linker_mark. */
6007 if (isym
->st_shndx
> 0
6008 && isym
->st_shndx
< SHN_LORESERVE
6010 && ((! isec
->linker_mark
&& (isec
->flags
& SEC_HAS_CONTENTS
) != 0)
6011 || (! finfo
->info
->relocateable
6012 && (isec
->flags
& SEC_EXCLUDE
) != 0)))
6015 /* Get the name of the symbol. */
6016 name
= bfd_elf_string_from_elf_section (input_bfd
, symtab_hdr
->sh_link
,
6021 /* See if we are discarding symbols with this name. */
6022 if ((finfo
->info
->strip
== strip_some
6023 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false, false)
6025 || (((finfo
->info
->discard
== discard_sec_merge
6026 && (isec
->flags
& SEC_MERGE
) && ! finfo
->info
->relocateable
)
6027 || finfo
->info
->discard
== discard_l
)
6028 && bfd_is_local_label_name (input_bfd
, name
)))
6031 /* If we get here, we are going to output this symbol. */
6035 /* Adjust the section index for the output file. */
6036 osym
.st_shndx
= _bfd_elf_section_from_bfd_section (output_bfd
,
6037 isec
->output_section
);
6038 if (osym
.st_shndx
== (unsigned short) -1)
6041 *pindex
= bfd_get_symcount (output_bfd
);
6043 /* ELF symbols in relocateable files are section relative, but
6044 in executable files they are virtual addresses. Note that
6045 this code assumes that all ELF sections have an associated
6046 BFD section with a reasonable value for output_offset; below
6047 we assume that they also have a reasonable value for
6048 output_section. Any special sections must be set up to meet
6049 these requirements. */
6050 osym
.st_value
+= isec
->output_offset
;
6051 if (! finfo
->info
->relocateable
)
6052 osym
.st_value
+= isec
->output_section
->vma
;
6054 if (! elf_link_output_sym (finfo
, name
, &osym
, isec
))
6058 /* Relocate the contents of each section. */
6059 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
6063 if (! o
->linker_mark
)
6065 /* This section was omitted from the link. */
6069 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
6070 || (o
->_raw_size
== 0 && (o
->flags
& SEC_RELOC
) == 0))
6073 if ((o
->flags
& SEC_LINKER_CREATED
) != 0)
6075 /* Section was created by elf_link_create_dynamic_sections
6080 /* Get the contents of the section. They have been cached by a
6081 relaxation routine. Note that o is a section in an input
6082 file, so the contents field will not have been set by any of
6083 the routines which work on output files. */
6084 if (elf_section_data (o
)->this_hdr
.contents
!= NULL
)
6085 contents
= elf_section_data (o
)->this_hdr
.contents
;
6088 contents
= finfo
->contents
;
6089 if (! bfd_get_section_contents (input_bfd
, o
, contents
,
6090 (file_ptr
) 0, o
->_raw_size
))
6094 if ((o
->flags
& SEC_RELOC
) != 0)
6096 Elf_Internal_Rela
*internal_relocs
;
6098 /* Get the swapped relocs. */
6099 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
6100 (input_bfd
, o
, finfo
->external_relocs
,
6101 finfo
->internal_relocs
, false));
6102 if (internal_relocs
== NULL
6103 && o
->reloc_count
> 0)
6106 /* Relocate the section by invoking a back end routine.
6108 The back end routine is responsible for adjusting the
6109 section contents as necessary, and (if using Rela relocs
6110 and generating a relocateable output file) adjusting the
6111 reloc addend as necessary.
6113 The back end routine does not have to worry about setting
6114 the reloc address or the reloc symbol index.
6116 The back end routine is given a pointer to the swapped in
6117 internal symbols, and can access the hash table entries
6118 for the external symbols via elf_sym_hashes (input_bfd).
6120 When generating relocateable output, the back end routine
6121 must handle STB_LOCAL/STT_SECTION symbols specially. The
6122 output symbol is going to be a section symbol
6123 corresponding to the output section, which will require
6124 the addend to be adjusted. */
6126 if (! (*relocate_section
) (output_bfd
, finfo
->info
,
6127 input_bfd
, o
, contents
,
6129 finfo
->internal_syms
,
6135 Elf_Internal_Rela
*irela
;
6136 Elf_Internal_Rela
*irelaend
;
6137 struct elf_link_hash_entry
**rel_hash
;
6138 Elf_Internal_Shdr
*input_rel_hdr
;
6139 unsigned int next_erel
;
6140 void (* reloc_emitter
) PARAMS ((bfd
*, asection
*,
6141 Elf_Internal_Shdr
*,
6142 Elf_Internal_Rela
*));
6144 /* Adjust the reloc addresses and symbol indices. */
6146 irela
= internal_relocs
;
6148 + o
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6149 rel_hash
= (elf_section_data (o
->output_section
)->rel_hashes
6150 + elf_section_data (o
->output_section
)->rel_count
6151 + elf_section_data (o
->output_section
)->rel_count2
);
6152 for (next_erel
= 0; irela
< irelaend
; irela
++, next_erel
++)
6154 unsigned long r_symndx
;
6155 Elf_Internal_Sym
*isym
;
6158 if (next_erel
== bed
->s
->int_rels_per_ext_rel
)
6164 irela
->r_offset
+= o
->output_offset
;
6166 /* Relocs in an executable have to be virtual addresses. */
6167 if (finfo
->info
->emitrelocations
)
6168 irela
->r_offset
+= o
->output_section
->vma
;
6170 r_symndx
= ELF_R_SYM (irela
->r_info
);
6175 if (r_symndx
>= locsymcount
6176 || (elf_bad_symtab (input_bfd
)
6177 && finfo
->sections
[r_symndx
] == NULL
))
6179 struct elf_link_hash_entry
*rh
;
6182 /* This is a reloc against a global symbol. We
6183 have not yet output all the local symbols, so
6184 we do not know the symbol index of any global
6185 symbol. We set the rel_hash entry for this
6186 reloc to point to the global hash table entry
6187 for this symbol. The symbol index is then
6188 set at the end of elf_bfd_final_link. */
6189 indx
= r_symndx
- extsymoff
;
6190 rh
= elf_sym_hashes (input_bfd
)[indx
];
6191 while (rh
->root
.type
== bfd_link_hash_indirect
6192 || rh
->root
.type
== bfd_link_hash_warning
)
6193 rh
= (struct elf_link_hash_entry
*) rh
->root
.u
.i
.link
;
6195 /* Setting the index to -2 tells
6196 elf_link_output_extsym that this symbol is
6198 BFD_ASSERT (rh
->indx
< 0);
6206 /* This is a reloc against a local symbol. */
6209 isym
= finfo
->internal_syms
+ r_symndx
;
6210 sec
= finfo
->sections
[r_symndx
];
6211 if (ELF_ST_TYPE (isym
->st_info
) == STT_SECTION
)
6213 /* I suppose the backend ought to fill in the
6214 section of any STT_SECTION symbol against a
6215 processor specific section. If we have
6216 discarded a section, the output_section will
6217 be the absolute section. */
6219 && (bfd_is_abs_section (sec
)
6220 || (sec
->output_section
!= NULL
6221 && bfd_is_abs_section (sec
->output_section
))))
6223 else if (sec
== NULL
|| sec
->owner
== NULL
)
6225 bfd_set_error (bfd_error_bad_value
);
6230 r_symndx
= sec
->output_section
->target_index
;
6231 BFD_ASSERT (r_symndx
!= 0);
6236 if (finfo
->indices
[r_symndx
] == -1)
6242 if (finfo
->info
->strip
== strip_all
)
6244 /* You can't do ld -r -s. */
6245 bfd_set_error (bfd_error_invalid_operation
);
6249 /* This symbol was skipped earlier, but
6250 since it is needed by a reloc, we
6251 must output it now. */
6252 link
= symtab_hdr
->sh_link
;
6253 name
= (bfd_elf_string_from_elf_section
6254 (input_bfd
, link
, isym
->st_name
));
6258 osec
= sec
->output_section
;
6260 _bfd_elf_section_from_bfd_section (output_bfd
,
6262 if (isym
->st_shndx
== (unsigned short) -1)
6265 isym
->st_value
+= sec
->output_offset
;
6266 if (! finfo
->info
->relocateable
)
6267 isym
->st_value
+= osec
->vma
;
6269 finfo
->indices
[r_symndx
]
6270 = bfd_get_symcount (output_bfd
);
6272 if (! elf_link_output_sym (finfo
, name
, isym
, sec
))
6276 r_symndx
= finfo
->indices
[r_symndx
];
6279 irela
->r_info
= ELF_R_INFO (r_symndx
,
6280 ELF_R_TYPE (irela
->r_info
));
6283 /* Swap out the relocs. */
6284 if (bed
->elf_backend_emit_relocs
6285 && !(finfo
->info
->relocateable
6286 || finfo
->info
->emitrelocations
))
6287 reloc_emitter
= bed
->elf_backend_emit_relocs
;
6289 reloc_emitter
= elf_link_output_relocs
;
6291 input_rel_hdr
= &elf_section_data (o
)->rel_hdr
;
6292 (*reloc_emitter
) (output_bfd
, o
, input_rel_hdr
, internal_relocs
);
6294 input_rel_hdr
= elf_section_data (o
)->rel_hdr2
;
6297 internal_relocs
+= NUM_SHDR_ENTRIES (input_rel_hdr
)
6298 * bed
->s
->int_rels_per_ext_rel
;
6299 reloc_emitter (output_bfd
, o
, input_rel_hdr
, internal_relocs
);
6305 /* Write out the modified section contents. */
6306 if (elf_section_data (o
)->stab_info
)
6308 if (! (_bfd_write_section_stabs
6309 (output_bfd
, &elf_hash_table (finfo
->info
)->stab_info
,
6310 o
, &elf_section_data (o
)->stab_info
, contents
)))
6313 else if (elf_section_data (o
)->merge_info
)
6315 if (! (_bfd_write_merged_section
6316 (output_bfd
, o
, elf_section_data (o
)->merge_info
)))
6321 if (! (o
->flags
& SEC_EXCLUDE
) &&
6322 ! bfd_set_section_contents (output_bfd
, o
->output_section
,
6323 contents
, o
->output_offset
,
6324 (o
->_cooked_size
!= 0
6334 /* Generate a reloc when linking an ELF file. This is a reloc
6335 requested by the linker, and does come from any input file. This
6336 is used to build constructor and destructor tables when linking
6340 elf_reloc_link_order (output_bfd
, info
, output_section
, link_order
)
6342 struct bfd_link_info
*info
;
6343 asection
*output_section
;
6344 struct bfd_link_order
*link_order
;
6346 reloc_howto_type
*howto
;
6350 struct elf_link_hash_entry
**rel_hash_ptr
;
6351 Elf_Internal_Shdr
*rel_hdr
;
6352 struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
6354 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
6357 bfd_set_error (bfd_error_bad_value
);
6361 addend
= link_order
->u
.reloc
.p
->addend
;
6363 /* Figure out the symbol index. */
6364 rel_hash_ptr
= (elf_section_data (output_section
)->rel_hashes
6365 + elf_section_data (output_section
)->rel_count
6366 + elf_section_data (output_section
)->rel_count2
);
6367 if (link_order
->type
== bfd_section_reloc_link_order
)
6369 indx
= link_order
->u
.reloc
.p
->u
.section
->target_index
;
6370 BFD_ASSERT (indx
!= 0);
6371 *rel_hash_ptr
= NULL
;
6375 struct elf_link_hash_entry
*h
;
6377 /* Treat a reloc against a defined symbol as though it were
6378 actually against the section. */
6379 h
= ((struct elf_link_hash_entry
*)
6380 bfd_wrapped_link_hash_lookup (output_bfd
, info
,
6381 link_order
->u
.reloc
.p
->u
.name
,
6382 false, false, true));
6384 && (h
->root
.type
== bfd_link_hash_defined
6385 || h
->root
.type
== bfd_link_hash_defweak
))
6389 section
= h
->root
.u
.def
.section
;
6390 indx
= section
->output_section
->target_index
;
6391 *rel_hash_ptr
= NULL
;
6392 /* It seems that we ought to add the symbol value to the
6393 addend here, but in practice it has already been added
6394 because it was passed to constructor_callback. */
6395 addend
+= section
->output_section
->vma
+ section
->output_offset
;
6399 /* Setting the index to -2 tells elf_link_output_extsym that
6400 this symbol is used by a reloc. */
6407 if (! ((*info
->callbacks
->unattached_reloc
)
6408 (info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
6409 (asection
*) NULL
, (bfd_vma
) 0)))
6415 /* If this is an inplace reloc, we must write the addend into the
6417 if (howto
->partial_inplace
&& addend
!= 0)
6420 bfd_reloc_status_type rstat
;
6424 size
= bfd_get_reloc_size (howto
);
6425 buf
= (bfd_byte
*) bfd_zmalloc (size
);
6426 if (buf
== (bfd_byte
*) NULL
)
6428 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
6434 case bfd_reloc_outofrange
:
6436 case bfd_reloc_overflow
:
6437 if (! ((*info
->callbacks
->reloc_overflow
)
6439 (link_order
->type
== bfd_section_reloc_link_order
6440 ? bfd_section_name (output_bfd
,
6441 link_order
->u
.reloc
.p
->u
.section
)
6442 : link_order
->u
.reloc
.p
->u
.name
),
6443 howto
->name
, addend
, (bfd
*) NULL
, (asection
*) NULL
,
6451 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
6452 (file_ptr
) link_order
->offset
, size
);
6458 /* The address of a reloc is relative to the section in a
6459 relocateable file, and is a virtual address in an executable
6461 offset
= link_order
->offset
;
6462 if (! info
->relocateable
)
6463 offset
+= output_section
->vma
;
6465 rel_hdr
= &elf_section_data (output_section
)->rel_hdr
;
6467 if (rel_hdr
->sh_type
== SHT_REL
)
6469 Elf_Internal_Rel
*irel
;
6470 Elf_External_Rel
*erel
;
6473 irel
= (Elf_Internal_Rel
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
6474 * sizeof (Elf_Internal_Rel
));
6478 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6479 irel
[i
].r_offset
= offset
;
6480 irel
[0].r_info
= ELF_R_INFO (indx
, howto
->type
);
6482 erel
= ((Elf_External_Rel
*) rel_hdr
->contents
6483 + elf_section_data (output_section
)->rel_count
);
6485 if (bed
->s
->swap_reloc_out
)
6486 (*bed
->s
->swap_reloc_out
) (output_bfd
, irel
, (bfd_byte
*) erel
);
6488 elf_swap_reloc_out (output_bfd
, irel
, erel
);
6494 Elf_Internal_Rela
*irela
;
6495 Elf_External_Rela
*erela
;
6498 irela
= (Elf_Internal_Rela
*) bfd_zmalloc (bed
->s
->int_rels_per_ext_rel
6499 * sizeof (Elf_Internal_Rela
));
6503 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6504 irela
[i
].r_offset
= offset
;
6505 irela
[0].r_info
= ELF_R_INFO (indx
, howto
->type
);
6506 irela
[0].r_addend
= addend
;
6508 erela
= ((Elf_External_Rela
*) rel_hdr
->contents
6509 + elf_section_data (output_section
)->rel_count
);
6511 if (bed
->s
->swap_reloca_out
)
6512 (*bed
->s
->swap_reloca_out
) (output_bfd
, irela
, (bfd_byte
*) erela
);
6514 elf_swap_reloca_out (output_bfd
, irela
, erela
);
6517 ++elf_section_data (output_section
)->rel_count
;
6522 /* Allocate a pointer to live in a linker created section. */
6525 elf_create_pointer_linker_section (abfd
, info
, lsect
, h
, rel
)
6527 struct bfd_link_info
*info
;
6528 elf_linker_section_t
*lsect
;
6529 struct elf_link_hash_entry
*h
;
6530 const Elf_Internal_Rela
*rel
;
6532 elf_linker_section_pointers_t
**ptr_linker_section_ptr
= NULL
;
6533 elf_linker_section_pointers_t
*linker_section_ptr
;
6534 unsigned long r_symndx
= ELF_R_SYM (rel
->r_info
);;
6536 BFD_ASSERT (lsect
!= NULL
);
6538 /* Is this a global symbol? */
6541 /* Has this symbol already been allocated? If so, our work is done. */
6542 if (_bfd_elf_find_pointer_linker_section (h
->linker_section_pointer
,
6547 ptr_linker_section_ptr
= &h
->linker_section_pointer
;
6548 /* Make sure this symbol is output as a dynamic symbol. */
6549 if (h
->dynindx
== -1)
6551 if (! elf_link_record_dynamic_symbol (info
, h
))
6555 if (lsect
->rel_section
)
6556 lsect
->rel_section
->_raw_size
+= sizeof (Elf_External_Rela
);
6560 /* Allocation of a pointer to a local symbol. */
6561 elf_linker_section_pointers_t
**ptr
= elf_local_ptr_offsets (abfd
);
6563 /* Allocate a table to hold the local symbols if first time. */
6566 unsigned int num_symbols
= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
6567 register unsigned int i
;
6569 ptr
= (elf_linker_section_pointers_t
**)
6571 num_symbols
* sizeof (elf_linker_section_pointers_t
*));
6576 elf_local_ptr_offsets (abfd
) = ptr
;
6577 for (i
= 0; i
< num_symbols
; i
++)
6578 ptr
[i
] = (elf_linker_section_pointers_t
*) 0;
6581 /* Has this symbol already been allocated? If so, our work is done. */
6582 if (_bfd_elf_find_pointer_linker_section (ptr
[r_symndx
],
6587 ptr_linker_section_ptr
= &ptr
[r_symndx
];
6591 /* If we are generating a shared object, we need to
6592 output a R_<xxx>_RELATIVE reloc so that the
6593 dynamic linker can adjust this GOT entry. */
6594 BFD_ASSERT (lsect
->rel_section
!= NULL
);
6595 lsect
->rel_section
->_raw_size
+= sizeof (Elf_External_Rela
);
6599 /* Allocate space for a pointer in the linker section, and allocate
6600 a new pointer record from internal memory. */
6601 BFD_ASSERT (ptr_linker_section_ptr
!= NULL
);
6602 linker_section_ptr
= (elf_linker_section_pointers_t
*)
6603 bfd_alloc (abfd
, sizeof (elf_linker_section_pointers_t
));
6605 if (!linker_section_ptr
)
6608 linker_section_ptr
->next
= *ptr_linker_section_ptr
;
6609 linker_section_ptr
->addend
= rel
->r_addend
;
6610 linker_section_ptr
->which
= lsect
->which
;
6611 linker_section_ptr
->written_address_p
= false;
6612 *ptr_linker_section_ptr
= linker_section_ptr
;
6615 if (lsect
->hole_size
&& lsect
->hole_offset
< lsect
->max_hole_offset
)
6617 linker_section_ptr
->offset
= (lsect
->section
->_raw_size
6618 - lsect
->hole_size
+ (ARCH_SIZE
/ 8));
6619 lsect
->hole_offset
+= ARCH_SIZE
/ 8;
6620 lsect
->sym_offset
+= ARCH_SIZE
/ 8;
6621 if (lsect
->sym_hash
)
6623 /* Bump up symbol value if needed. */
6624 lsect
->sym_hash
->root
.u
.def
.value
+= ARCH_SIZE
/ 8;
6626 fprintf (stderr
, "Bump up %s by %ld, current value = %ld\n",
6627 lsect
->sym_hash
->root
.root
.string
,
6628 (long) ARCH_SIZE
/ 8,
6629 (long) lsect
->sym_hash
->root
.u
.def
.value
);
6635 linker_section_ptr
->offset
= lsect
->section
->_raw_size
;
6637 lsect
->section
->_raw_size
+= ARCH_SIZE
/ 8;
6641 "Create pointer in linker section %s, offset = %ld, section size = %ld\n",
6642 lsect
->name
, (long) linker_section_ptr
->offset
,
6643 (long) lsect
->section
->_raw_size
);
6650 #define bfd_put_ptr(BFD,VAL,ADDR) bfd_put_64 (BFD, VAL, ADDR)
6653 #define bfd_put_ptr(BFD,VAL,ADDR) bfd_put_32 (BFD, VAL, ADDR)
6656 /* Fill in the address for a pointer generated in a linker section. */
6659 elf_finish_pointer_linker_section (output_bfd
, input_bfd
, info
, lsect
, h
,
6660 relocation
, rel
, relative_reloc
)
6663 struct bfd_link_info
*info
;
6664 elf_linker_section_t
*lsect
;
6665 struct elf_link_hash_entry
*h
;
6667 const Elf_Internal_Rela
*rel
;
6670 elf_linker_section_pointers_t
*linker_section_ptr
;
6672 BFD_ASSERT (lsect
!= NULL
);
6676 /* Handle global symbol. */
6677 linker_section_ptr
= (_bfd_elf_find_pointer_linker_section
6678 (h
->linker_section_pointer
,
6682 BFD_ASSERT (linker_section_ptr
!= NULL
);
6684 if (! elf_hash_table (info
)->dynamic_sections_created
6687 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
6689 /* This is actually a static link, or it is a
6690 -Bsymbolic link and the symbol is defined
6691 locally. We must initialize this entry in the
6694 When doing a dynamic link, we create a .rela.<xxx>
6695 relocation entry to initialize the value. This
6696 is done in the finish_dynamic_symbol routine. */
6697 if (!linker_section_ptr
->written_address_p
)
6699 linker_section_ptr
->written_address_p
= true;
6700 bfd_put_ptr (output_bfd
,
6701 relocation
+ linker_section_ptr
->addend
,
6702 (lsect
->section
->contents
6703 + linker_section_ptr
->offset
));
6709 /* Handle local symbol. */
6710 unsigned long r_symndx
= ELF_R_SYM (rel
->r_info
);
6711 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
) != NULL
);
6712 BFD_ASSERT (elf_local_ptr_offsets (input_bfd
)[r_symndx
] != NULL
);
6713 linker_section_ptr
= (_bfd_elf_find_pointer_linker_section
6714 (elf_local_ptr_offsets (input_bfd
)[r_symndx
],
6718 BFD_ASSERT (linker_section_ptr
!= NULL
);
6720 /* Write out pointer if it hasn't been rewritten out before. */
6721 if (!linker_section_ptr
->written_address_p
)
6723 linker_section_ptr
->written_address_p
= true;
6724 bfd_put_ptr (output_bfd
, relocation
+ linker_section_ptr
->addend
,
6725 lsect
->section
->contents
+ linker_section_ptr
->offset
);
6729 asection
*srel
= lsect
->rel_section
;
6730 Elf_Internal_Rela
*outrel
;
6731 struct elf_backend_data
*bed
= get_elf_backend_data (output_bfd
);
6734 outrel
= (Elf_Internal_Rela
*)
6735 bfd_zmalloc (sizeof (Elf_Internal_Rela
)
6736 * bed
->s
->int_rels_per_ext_rel
);
6739 (*_bfd_error_handler
) (_("Error: out of memory"));
6743 /* We need to generate a relative reloc for the dynamic
6747 srel
= bfd_get_section_by_name (elf_hash_table (info
)->dynobj
,
6749 lsect
->rel_section
= srel
;
6752 BFD_ASSERT (srel
!= NULL
);
6754 for (i
= 0; i
< bed
->s
->int_rels_per_ext_rel
; i
++)
6755 outrel
[i
].r_offset
= (lsect
->section
->output_section
->vma
6756 + lsect
->section
->output_offset
6757 + linker_section_ptr
->offset
);
6758 outrel
[0].r_info
= ELF_R_INFO (0, relative_reloc
);
6759 outrel
[0].r_addend
= 0;
6760 elf_swap_reloca_out (output_bfd
, outrel
,
6761 (((Elf_External_Rela
*)
6762 lsect
->section
->contents
)
6763 + (elf_section_data (lsect
->section
)
6765 ++elf_section_data (lsect
->section
)->rel_count
;
6772 relocation
= (lsect
->section
->output_offset
6773 + linker_section_ptr
->offset
6774 - lsect
->hole_offset
6775 - lsect
->sym_offset
);
6779 "Finish pointer in linker section %s, offset = %ld (0x%lx)\n",
6780 lsect
->name
, (long) relocation
, (long) relocation
);
6783 /* Subtract out the addend, because it will get added back in by the normal
6785 return relocation
- linker_section_ptr
->addend
;
6788 /* Garbage collect unused sections. */
6790 static boolean elf_gc_mark
6791 PARAMS ((struct bfd_link_info
*info
, asection
*sec
,
6792 asection
* (*gc_mark_hook
)
6793 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
6794 struct elf_link_hash_entry
*, Elf_Internal_Sym
*))));
6796 static boolean elf_gc_sweep
6797 PARAMS ((struct bfd_link_info
*info
,
6798 boolean (*gc_sweep_hook
)
6799 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*o
,
6800 const Elf_Internal_Rela
*relocs
))));
6802 static boolean elf_gc_sweep_symbol
6803 PARAMS ((struct elf_link_hash_entry
*h
, PTR idxptr
));
6805 static boolean elf_gc_allocate_got_offsets
6806 PARAMS ((struct elf_link_hash_entry
*h
, PTR offarg
));
6808 static boolean elf_gc_propagate_vtable_entries_used
6809 PARAMS ((struct elf_link_hash_entry
*h
, PTR dummy
));
6811 static boolean elf_gc_smash_unused_vtentry_relocs
6812 PARAMS ((struct elf_link_hash_entry
*h
, PTR dummy
));
6814 /* The mark phase of garbage collection. For a given section, mark
6815 it, and all the sections which define symbols to which it refers. */
6818 elf_gc_mark (info
, sec
, gc_mark_hook
)
6819 struct bfd_link_info
*info
;
6821 asection
* (*gc_mark_hook
)
6822 PARAMS ((bfd
*, struct bfd_link_info
*, Elf_Internal_Rela
*,
6823 struct elf_link_hash_entry
*, Elf_Internal_Sym
*));
6829 /* Look through the section relocs. */
6831 if ((sec
->flags
& SEC_RELOC
) != 0 && sec
->reloc_count
> 0)
6833 Elf_Internal_Rela
*relstart
, *rel
, *relend
;
6834 Elf_Internal_Shdr
*symtab_hdr
;
6835 struct elf_link_hash_entry
**sym_hashes
;
6838 Elf_External_Sym
*locsyms
, *freesyms
= NULL
;
6839 bfd
*input_bfd
= sec
->owner
;
6840 struct elf_backend_data
*bed
= get_elf_backend_data (input_bfd
);
6842 /* GCFIXME: how to arrange so that relocs and symbols are not
6843 reread continually? */
6845 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
6846 sym_hashes
= elf_sym_hashes (input_bfd
);
6848 /* Read the local symbols. */
6849 if (elf_bad_symtab (input_bfd
))
6851 nlocsyms
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
6855 extsymoff
= nlocsyms
= symtab_hdr
->sh_info
;
6856 if (symtab_hdr
->contents
)
6857 locsyms
= (Elf_External_Sym
*) symtab_hdr
->contents
;
6858 else if (nlocsyms
== 0)
6862 locsyms
= freesyms
=
6863 bfd_malloc (nlocsyms
* sizeof (Elf_External_Sym
));
6864 if (freesyms
== NULL
6865 || bfd_seek (input_bfd
, symtab_hdr
->sh_offset
, SEEK_SET
) != 0
6866 || (bfd_read (locsyms
, sizeof (Elf_External_Sym
),
6867 nlocsyms
, input_bfd
)
6868 != nlocsyms
* sizeof (Elf_External_Sym
)))
6875 /* Read the relocations. */
6876 relstart
= (NAME(_bfd_elf
,link_read_relocs
)
6877 (sec
->owner
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
,
6878 info
->keep_memory
));
6879 if (relstart
== NULL
)
6884 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
6886 for (rel
= relstart
; rel
< relend
; rel
++)
6888 unsigned long r_symndx
;
6890 struct elf_link_hash_entry
*h
;
6893 r_symndx
= ELF_R_SYM (rel
->r_info
);
6897 if (elf_bad_symtab (sec
->owner
))
6899 elf_swap_symbol_in (input_bfd
, &locsyms
[r_symndx
], &s
);
6900 if (ELF_ST_BIND (s
.st_info
) == STB_LOCAL
)
6901 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, NULL
, &s
);
6904 h
= sym_hashes
[r_symndx
- extsymoff
];
6905 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, h
, NULL
);
6908 else if (r_symndx
>= nlocsyms
)
6910 h
= sym_hashes
[r_symndx
- extsymoff
];
6911 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, h
, NULL
);
6915 elf_swap_symbol_in (input_bfd
, &locsyms
[r_symndx
], &s
);
6916 rsec
= (*gc_mark_hook
) (sec
->owner
, info
, rel
, NULL
, &s
);
6919 if (rsec
&& !rsec
->gc_mark
)
6920 if (!elf_gc_mark (info
, rsec
, gc_mark_hook
))
6928 if (!info
->keep_memory
)
6938 /* The sweep phase of garbage collection. Remove all garbage sections. */
6941 elf_gc_sweep (info
, gc_sweep_hook
)
6942 struct bfd_link_info
*info
;
6943 boolean (*gc_sweep_hook
)
6944 PARAMS ((bfd
*abfd
, struct bfd_link_info
*info
, asection
*o
,
6945 const Elf_Internal_Rela
*relocs
));
6949 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
6953 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
6956 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
6958 /* Keep special sections. Keep .debug sections. */
6959 if ((o
->flags
& SEC_LINKER_CREATED
)
6960 || (o
->flags
& SEC_DEBUGGING
))
6966 /* Skip sweeping sections already excluded. */
6967 if (o
->flags
& SEC_EXCLUDE
)
6970 /* Since this is early in the link process, it is simple
6971 to remove a section from the output. */
6972 o
->flags
|= SEC_EXCLUDE
;
6974 /* But we also have to update some of the relocation
6975 info we collected before. */
6977 && (o
->flags
& SEC_RELOC
) && o
->reloc_count
> 0)
6979 Elf_Internal_Rela
*internal_relocs
;
6982 internal_relocs
= (NAME(_bfd_elf
,link_read_relocs
)
6983 (o
->owner
, o
, NULL
, NULL
, info
->keep_memory
));
6984 if (internal_relocs
== NULL
)
6987 r
= (*gc_sweep_hook
) (o
->owner
, info
, o
, internal_relocs
);
6989 if (!info
->keep_memory
)
6990 free (internal_relocs
);
6998 /* Remove the symbols that were in the swept sections from the dynamic
6999 symbol table. GCFIXME: Anyone know how to get them out of the
7000 static symbol table as well? */
7004 elf_link_hash_traverse (elf_hash_table (info
),
7005 elf_gc_sweep_symbol
,
7008 elf_hash_table (info
)->dynsymcount
= i
;
7014 /* Sweep symbols in swept sections. Called via elf_link_hash_traverse. */
7017 elf_gc_sweep_symbol (h
, idxptr
)
7018 struct elf_link_hash_entry
*h
;
7021 int *idx
= (int *) idxptr
;
7023 if (h
->dynindx
!= -1
7024 && ((h
->root
.type
!= bfd_link_hash_defined
7025 && h
->root
.type
!= bfd_link_hash_defweak
)
7026 || h
->root
.u
.def
.section
->gc_mark
))
7027 h
->dynindx
= (*idx
)++;
7032 /* Propogate collected vtable information. This is called through
7033 elf_link_hash_traverse. */
7036 elf_gc_propagate_vtable_entries_used (h
, okp
)
7037 struct elf_link_hash_entry
*h
;
7040 /* Those that are not vtables. */
7041 if (h
->vtable_parent
== NULL
)
7044 /* Those vtables that do not have parents, we cannot merge. */
7045 if (h
->vtable_parent
== (struct elf_link_hash_entry
*) -1)
7048 /* If we've already been done, exit. */
7049 if (h
->vtable_entries_used
&& h
->vtable_entries_used
[-1])
7052 /* Make sure the parent's table is up to date. */
7053 elf_gc_propagate_vtable_entries_used (h
->vtable_parent
, okp
);
7055 if (h
->vtable_entries_used
== NULL
)
7057 /* None of this table's entries were referenced. Re-use the
7059 h
->vtable_entries_used
= h
->vtable_parent
->vtable_entries_used
;
7060 h
->vtable_entries_size
= h
->vtable_parent
->vtable_entries_size
;
7067 /* Or the parent's entries into ours. */
7068 cu
= h
->vtable_entries_used
;
7070 pu
= h
->vtable_parent
->vtable_entries_used
;
7073 asection
*sec
= h
->root
.u
.def
.section
;
7074 struct elf_backend_data
*bed
= get_elf_backend_data (sec
->owner
);
7075 int file_align
= bed
->s
->file_align
;
7077 n
= h
->vtable_parent
->vtable_entries_size
/ file_align
;
7080 if (*pu
) *cu
= true;
7090 elf_gc_smash_unused_vtentry_relocs (h
, okp
)
7091 struct elf_link_hash_entry
*h
;
7095 bfd_vma hstart
, hend
;
7096 Elf_Internal_Rela
*relstart
, *relend
, *rel
;
7097 struct elf_backend_data
*bed
;
7100 /* Take care of both those symbols that do not describe vtables as
7101 well as those that are not loaded. */
7102 if (h
->vtable_parent
== NULL
)
7105 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
7106 || h
->root
.type
== bfd_link_hash_defweak
);
7108 sec
= h
->root
.u
.def
.section
;
7109 hstart
= h
->root
.u
.def
.value
;
7110 hend
= hstart
+ h
->size
;
7112 relstart
= (NAME(_bfd_elf
,link_read_relocs
)
7113 (sec
->owner
, sec
, NULL
, (Elf_Internal_Rela
*) NULL
, true));
7115 return *(boolean
*) okp
= false;
7116 bed
= get_elf_backend_data (sec
->owner
);
7117 file_align
= bed
->s
->file_align
;
7119 relend
= relstart
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7121 for (rel
= relstart
; rel
< relend
; ++rel
)
7122 if (rel
->r_offset
>= hstart
&& rel
->r_offset
< hend
)
7124 /* If the entry is in use, do nothing. */
7125 if (h
->vtable_entries_used
7126 && (rel
->r_offset
- hstart
) < h
->vtable_entries_size
)
7128 bfd_vma entry
= (rel
->r_offset
- hstart
) / file_align
;
7129 if (h
->vtable_entries_used
[entry
])
7132 /* Otherwise, kill it. */
7133 rel
->r_offset
= rel
->r_info
= rel
->r_addend
= 0;
7139 /* Do mark and sweep of unused sections. */
7142 elf_gc_sections (abfd
, info
)
7144 struct bfd_link_info
*info
;
7148 asection
* (*gc_mark_hook
)
7149 PARAMS ((bfd
*abfd
, struct bfd_link_info
*, Elf_Internal_Rela
*,
7150 struct elf_link_hash_entry
*h
, Elf_Internal_Sym
*));
7152 if (!get_elf_backend_data (abfd
)->can_gc_sections
7153 || info
->relocateable
|| info
->emitrelocations
7154 || elf_hash_table (info
)->dynamic_sections_created
)
7157 /* Apply transitive closure to the vtable entry usage info. */
7158 elf_link_hash_traverse (elf_hash_table (info
),
7159 elf_gc_propagate_vtable_entries_used
,
7164 /* Kill the vtable relocations that were not used. */
7165 elf_link_hash_traverse (elf_hash_table (info
),
7166 elf_gc_smash_unused_vtentry_relocs
,
7171 /* Grovel through relocs to find out who stays ... */
7173 gc_mark_hook
= get_elf_backend_data (abfd
)->gc_mark_hook
;
7174 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
7178 if (bfd_get_flavour (sub
) != bfd_target_elf_flavour
)
7181 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
7183 if (o
->flags
& SEC_KEEP
)
7184 if (!elf_gc_mark (info
, o
, gc_mark_hook
))
7189 /* ... and mark SEC_EXCLUDE for those that go. */
7190 if (!elf_gc_sweep (info
, get_elf_backend_data (abfd
)->gc_sweep_hook
))
7196 /* Called from check_relocs to record the existance of a VTINHERIT reloc. */
7199 elf_gc_record_vtinherit (abfd
, sec
, h
, offset
)
7202 struct elf_link_hash_entry
*h
;
7205 struct elf_link_hash_entry
**sym_hashes
, **sym_hashes_end
;
7206 struct elf_link_hash_entry
**search
, *child
;
7207 bfd_size_type extsymcount
;
7209 /* The sh_info field of the symtab header tells us where the
7210 external symbols start. We don't care about the local symbols at
7212 extsymcount
= elf_tdata (abfd
)->symtab_hdr
.sh_size
/sizeof (Elf_External_Sym
);
7213 if (!elf_bad_symtab (abfd
))
7214 extsymcount
-= elf_tdata (abfd
)->symtab_hdr
.sh_info
;
7216 sym_hashes
= elf_sym_hashes (abfd
);
7217 sym_hashes_end
= sym_hashes
+ extsymcount
;
7219 /* Hunt down the child symbol, which is in this section at the same
7220 offset as the relocation. */
7221 for (search
= sym_hashes
; search
!= sym_hashes_end
; ++search
)
7223 if ((child
= *search
) != NULL
7224 && (child
->root
.type
== bfd_link_hash_defined
7225 || child
->root
.type
== bfd_link_hash_defweak
)
7226 && child
->root
.u
.def
.section
== sec
7227 && child
->root
.u
.def
.value
== offset
)
7231 (*_bfd_error_handler
) ("%s: %s+%lu: No symbol found for INHERIT",
7232 bfd_get_filename (abfd
), sec
->name
,
7233 (unsigned long) offset
);
7234 bfd_set_error (bfd_error_invalid_operation
);
7240 /* This *should* only be the absolute section. It could potentially
7241 be that someone has defined a non-global vtable though, which
7242 would be bad. It isn't worth paging in the local symbols to be
7243 sure though; that case should simply be handled by the assembler. */
7245 child
->vtable_parent
= (struct elf_link_hash_entry
*) -1;
7248 child
->vtable_parent
= h
;
7253 /* Called from check_relocs to record the existance of a VTENTRY reloc. */
7256 elf_gc_record_vtentry (abfd
, sec
, h
, addend
)
7257 bfd
*abfd ATTRIBUTE_UNUSED
;
7258 asection
*sec ATTRIBUTE_UNUSED
;
7259 struct elf_link_hash_entry
*h
;
7262 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7263 int file_align
= bed
->s
->file_align
;
7265 if (addend
>= h
->vtable_entries_size
)
7268 boolean
*ptr
= h
->vtable_entries_used
;
7270 /* While the symbol is undefined, we have to be prepared to handle
7272 if (h
->root
.type
== bfd_link_hash_undefined
)
7279 /* Oops! We've got a reference past the defined end of
7280 the table. This is probably a bug -- shall we warn? */
7285 /* Allocate one extra entry for use as a "done" flag for the
7286 consolidation pass. */
7287 bytes
= (size
/ file_align
+ 1) * sizeof (boolean
);
7291 ptr
= bfd_realloc (ptr
- 1, bytes
);
7297 oldbytes
= ((h
->vtable_entries_size
/ file_align
+ 1)
7298 * sizeof (boolean
));
7299 memset (((char *) ptr
) + oldbytes
, 0, bytes
- oldbytes
);
7303 ptr
= bfd_zmalloc (bytes
);
7308 /* And arrange for that done flag to be at index -1. */
7309 h
->vtable_entries_used
= ptr
+ 1;
7310 h
->vtable_entries_size
= size
;
7313 h
->vtable_entries_used
[addend
/ file_align
] = true;
7318 /* And an accompanying bit to work out final got entry offsets once
7319 we're done. Should be called from final_link. */
7322 elf_gc_common_finalize_got_offsets (abfd
, info
)
7324 struct bfd_link_info
*info
;
7327 struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
7330 /* The GOT offset is relative to the .got section, but the GOT header is
7331 put into the .got.plt section, if the backend uses it. */
7332 if (bed
->want_got_plt
)
7335 gotoff
= bed
->got_header_size
;
7337 /* Do the local .got entries first. */
7338 for (i
= info
->input_bfds
; i
; i
= i
->link_next
)
7340 bfd_signed_vma
*local_got
;
7341 bfd_size_type j
, locsymcount
;
7342 Elf_Internal_Shdr
*symtab_hdr
;
7344 if (bfd_get_flavour (i
) != bfd_target_elf_flavour
)
7347 local_got
= elf_local_got_refcounts (i
);
7351 symtab_hdr
= &elf_tdata (i
)->symtab_hdr
;
7352 if (elf_bad_symtab (i
))
7353 locsymcount
= symtab_hdr
->sh_size
/ sizeof (Elf_External_Sym
);
7355 locsymcount
= symtab_hdr
->sh_info
;
7357 for (j
= 0; j
< locsymcount
; ++j
)
7359 if (local_got
[j
] > 0)
7361 local_got
[j
] = gotoff
;
7362 gotoff
+= ARCH_SIZE
/ 8;
7365 local_got
[j
] = (bfd_vma
) -1;
7369 /* Then the global .got entries. .plt refcounts are handled by
7370 adjust_dynamic_symbol */
7371 elf_link_hash_traverse (elf_hash_table (info
),
7372 elf_gc_allocate_got_offsets
,
7377 /* We need a special top-level link routine to convert got reference counts
7378 to real got offsets. */
7381 elf_gc_allocate_got_offsets (h
, offarg
)
7382 struct elf_link_hash_entry
*h
;
7385 bfd_vma
*off
= (bfd_vma
*) offarg
;
7387 if (h
->got
.refcount
> 0)
7389 h
->got
.offset
= off
[0];
7390 off
[0] += ARCH_SIZE
/ 8;
7393 h
->got
.offset
= (bfd_vma
) -1;
7398 /* Many folk need no more in the way of final link than this, once
7399 got entry reference counting is enabled. */
7402 elf_gc_common_final_link (abfd
, info
)
7404 struct bfd_link_info
*info
;
7406 if (!elf_gc_common_finalize_got_offsets (abfd
, info
))
7409 /* Invoke the regular ELF backend linker to do all the work. */
7410 return elf_bfd_final_link (abfd
, info
);
7413 /* This function will be called though elf_link_hash_traverse to store
7414 all hash value of the exported symbols in an array. */
7417 elf_collect_hash_codes (h
, data
)
7418 struct elf_link_hash_entry
*h
;
7421 unsigned long **valuep
= (unsigned long **) data
;
7427 /* Ignore indirect symbols. These are added by the versioning code. */
7428 if (h
->dynindx
== -1)
7431 name
= h
->root
.root
.string
;
7432 p
= strchr (name
, ELF_VER_CHR
);
7435 alc
= bfd_malloc (p
- name
+ 1);
7436 memcpy (alc
, name
, p
- name
);
7437 alc
[p
- name
] = '\0';
7441 /* Compute the hash value. */
7442 ha
= bfd_elf_hash (name
);
7444 /* Store the found hash value in the array given as the argument. */
7447 /* And store it in the struct so that we can put it in the hash table
7449 h
->elf_hash_value
= ha
;