Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5197 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* COFF specific linker code. |
1 | /* COFF specific linker code. |
2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
- | |
3 | 2004, 2005, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc. |
2 | Copyright (C) 1994-2015 Free Software Foundation, Inc. |
4 | Written by Ian Lance Taylor, Cygnus Support. |
3 | Written by Ian Lance Taylor, Cygnus Support. |
Line 5... | Line 4... | ||
5 | 4 | ||
Line 6... | Line 5... | ||
6 | This file is part of BFD, the Binary File Descriptor library. |
5 | This file is part of BFD, the Binary File Descriptor library. |
Line 28... | Line 27... | ||
28 | #include "libbfd.h" |
27 | #include "libbfd.h" |
29 | #include "coff/internal.h" |
28 | #include "coff/internal.h" |
30 | #include "libcoff.h" |
29 | #include "libcoff.h" |
31 | #include "safe-ctype.h" |
30 | #include "safe-ctype.h" |
Line 32... | Line 31... | ||
32 | 31 | ||
33 | static bfd_boolean coff_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info); |
32 | static bfd_boolean coff_link_add_object_symbols (bfd *, struct bfd_link_info *); |
- | 33 | static bfd_boolean coff_link_check_archive_element |
|
- | 34 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
|
34 | static bfd_boolean coff_link_check_archive_element (bfd *abfd, struct bfd_link_info *info, bfd_boolean *pneeded); |
35 | bfd_boolean *); |
Line 35... | Line 36... | ||
35 | static bfd_boolean coff_link_add_symbols (bfd *abfd, struct bfd_link_info *info); |
36 | static bfd_boolean coff_link_add_symbols (bfd *, struct bfd_link_info *); |
36 | 37 | ||
37 | /* Return TRUE if SYM is a weak, external symbol. */ |
38 | /* Return TRUE if SYM is a weak, external symbol. */ |
38 | #define IS_WEAK_EXTERNAL(abfd, sym) \ |
39 | #define IS_WEAK_EXTERNAL(abfd, sym) \ |
Line 189... | Line 190... | ||
189 | return FALSE; |
190 | return FALSE; |
Line 190... | Line 191... | ||
190 | 191 | ||
191 | return TRUE; |
192 | return TRUE; |
Line 192... | Line -... | ||
192 | } |
- | |
193 | - | ||
194 | /* Look through the symbols to see if this object file should be |
- | |
195 | included in the link. */ |
- | |
196 | - | ||
197 | static bfd_boolean |
- | |
198 | coff_link_check_ar_symbols (bfd *abfd, |
- | |
199 | struct bfd_link_info *info, |
- | |
200 | bfd_boolean *pneeded, |
- | |
201 | bfd **subsbfd) |
- | |
202 | { |
- | |
203 | bfd_size_type symesz; |
- | |
204 | bfd_byte *esym; |
- | |
205 | bfd_byte *esym_end; |
- | |
206 | - | ||
207 | *pneeded = FALSE; |
- | |
208 | - | ||
209 | symesz = bfd_coff_symesz (abfd); |
- | |
210 | esym = (bfd_byte *) obj_coff_external_syms (abfd); |
- | |
211 | esym_end = esym + obj_raw_syment_count (abfd) * symesz; |
- | |
212 | while (esym < esym_end) |
- | |
213 | { |
- | |
214 | struct internal_syment sym; |
- | |
215 | enum coff_symbol_classification classification; |
- | |
216 | - | ||
217 | bfd_coff_swap_sym_in (abfd, esym, &sym); |
- | |
218 | - | ||
219 | classification = bfd_coff_classify_symbol (abfd, &sym); |
- | |
220 | if (classification == COFF_SYMBOL_GLOBAL |
- | |
221 | || classification == COFF_SYMBOL_COMMON) |
- | |
222 | { |
- | |
223 | const char *name; |
- | |
224 | char buf[SYMNMLEN + 1]; |
- | |
225 | struct bfd_link_hash_entry *h; |
- | |
226 | - | ||
227 | /* This symbol is externally visible, and is defined by this |
- | |
228 | object file. */ |
- | |
229 | name = _bfd_coff_internal_syment_name (abfd, &sym, buf); |
- | |
230 | if (name == NULL) |
- | |
231 | return FALSE; |
- | |
232 | h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE); |
- | |
233 | - | ||
234 | /* Auto import. */ |
- | |
235 | if (!h |
- | |
236 | && info->pei386_auto_import |
- | |
237 | && CONST_STRNEQ (name, "__imp_")) |
- | |
238 | h = bfd_link_hash_lookup (info->hash, name + 6, FALSE, FALSE, TRUE); |
- | |
239 | - | ||
240 | /* We are only interested in symbols that are currently |
- | |
241 | undefined. If a symbol is currently known to be common, |
- | |
242 | COFF linkers do not bring in an object file which defines |
- | |
243 | it. */ |
- | |
244 | if (h != (struct bfd_link_hash_entry *) NULL |
- | |
245 | && h->type == bfd_link_hash_undefined) |
- | |
246 | { |
- | |
247 | if (!(*info->callbacks |
- | |
248 | ->add_archive_element) (info, abfd, name, subsbfd)) |
- | |
249 | return FALSE; |
- | |
250 | *pneeded = TRUE; |
- | |
251 | return TRUE; |
- | |
252 | } |
- | |
253 | } |
- | |
254 | - | ||
255 | esym += (sym.n_numaux + 1) * symesz; |
- | |
256 | } |
- | |
257 | - | ||
258 | /* We do not need this object file. */ |
- | |
259 | return TRUE; |
- | |
260 | } |
193 | } |
261 | 194 | ||
262 | /* Check a single archive element to see if we need to include it in |
195 | /* Check a single archive element to see if we need to include it in |
263 | the link. *PNEEDED is set according to whether this element is |
196 | the link. *PNEEDED is set according to whether this element is |
Line 264... | Line 197... | ||
264 | needed in the link or not. This is called via |
197 | needed in the link or not. This is called via |
265 | _bfd_generic_link_add_archive_symbols. */ |
198 | _bfd_generic_link_add_archive_symbols. */ |
266 | 199 | ||
- | 200 | static bfd_boolean |
|
- | 201 | coff_link_check_archive_element (bfd *abfd, |
|
267 | static bfd_boolean |
202 | struct bfd_link_info *info, |
268 | coff_link_check_archive_element (bfd *abfd, |
203 | struct bfd_link_hash_entry *h, |
269 | struct bfd_link_info *info, |
204 | const char *name, |
270 | bfd_boolean *pneeded) |
- | |
Line -... | Line 205... | ||
- | 205 | bfd_boolean *pneeded) |
|
- | 206 | { |
|
- | 207 | *pneeded = FALSE; |
|
271 | { |
208 | |
272 | bfd *oldbfd; |
209 | /* We are only interested in symbols that are currently undefined. |
Line 273... | Line -... | ||
273 | bfd_boolean needed; |
- | |
274 | 210 | If a symbol is currently known to be common, COFF linkers do not |
|
275 | if (!_bfd_coff_get_external_symbols (abfd)) |
211 | bring in an object file which defines it. */ |
- | 212 | if (h->type != bfd_link_hash_undefined) |
|
Line 276... | Line -... | ||
276 | return FALSE; |
- | |
277 | - | ||
278 | oldbfd = abfd; |
- | |
279 | if (!coff_link_check_ar_symbols (abfd, info, pneeded, &abfd)) |
- | |
280 | return FALSE; |
- | |
281 | - | ||
282 | needed = *pneeded; |
- | |
283 | if (needed) |
- | |
284 | { |
- | |
285 | /* Potentially, the add_archive_element hook may have set a |
- | |
286 | substitute BFD for us. */ |
- | |
287 | if (abfd != oldbfd) |
- | |
288 | { |
- | |
289 | if (!info->keep_memory |
213 | return TRUE; |
290 | && !_bfd_coff_free_symbols (oldbfd)) |
- | |
291 | return FALSE; |
- | |
292 | if (!_bfd_coff_get_external_symbols (abfd)) |
- | |
293 | return FALSE; |
- | |
294 | } |
- | |
295 | if (!coff_link_add_symbols (abfd, info)) |
- | |
296 | return FALSE; |
- | |
297 | } |
- | |
298 | - | ||
299 | if (!info->keep_memory || !needed) |
214 | |
Line 300... | Line 215... | ||
300 | { |
215 | if (!(*info->callbacks->add_archive_element) (info, abfd, name, &abfd)) |
Line 301... | Line 216... | ||
301 | if (!_bfd_coff_free_symbols (abfd)) |
216 | return FALSE; |
Line 590... | Line 505... | ||
590 | sym_hash += sym.n_numaux + 1; |
505 | sym_hash += sym.n_numaux + 1; |
591 | } |
506 | } |
Line 592... | Line 507... | ||
592 | 507 | ||
593 | /* If this is a non-traditional, non-relocatable link, try to |
508 | /* If this is a non-traditional, non-relocatable link, try to |
594 | optimize the handling of any .stab/.stabstr sections. */ |
509 | optimize the handling of any .stab/.stabstr sections. */ |
595 | if (! info->relocatable |
510 | if (! bfd_link_relocatable (info) |
596 | && ! info->traditional_format |
511 | && ! info->traditional_format |
597 | && bfd_get_flavour (info->output_bfd) == bfd_get_flavour (abfd) |
512 | && bfd_get_flavour (info->output_bfd) == bfd_get_flavour (abfd) |
598 | && (info->strip != strip_all && info->strip != strip_debugger)) |
513 | && (info->strip != strip_all && info->strip != strip_debugger)) |
599 | { |
514 | { |
Line 735... | Line 650... | ||
735 | 650 | ||
736 | if (info->strip == strip_none |
651 | if (info->strip == strip_none |
737 | || info->strip == strip_some) |
652 | || info->strip == strip_some) |
Line 738... | Line 653... | ||
738 | o->lineno_count += sec->lineno_count; |
653 | o->lineno_count += sec->lineno_count; |
739 | 654 | ||
Line 740... | Line 655... | ||
740 | if (info->relocatable) |
655 | if (bfd_link_relocatable (info)) |
741 | o->reloc_count += sec->reloc_count; |
656 | o->reloc_count += sec->reloc_count; |
742 | 657 | ||
Line 747... | Line 662... | ||
747 | if (sec->lineno_count > max_lineno_count) |
662 | if (sec->lineno_count > max_lineno_count) |
748 | max_lineno_count = sec->lineno_count; |
663 | max_lineno_count = sec->lineno_count; |
749 | if (sec->reloc_count > max_reloc_count) |
664 | if (sec->reloc_count > max_reloc_count) |
750 | max_reloc_count = sec->reloc_count; |
665 | max_reloc_count = sec->reloc_count; |
751 | } |
666 | } |
752 | else if (info->relocatable |
667 | else if (bfd_link_relocatable (info) |
753 | && (p->type == bfd_section_reloc_link_order |
668 | && (p->type == bfd_section_reloc_link_order |
754 | || p->type == bfd_symbol_reloc_link_order)) |
669 | || p->type == bfd_symbol_reloc_link_order)) |
755 | ++o->reloc_count; |
670 | ++o->reloc_count; |
756 | } |
671 | } |
757 | if (o->reloc_count == 0) |
672 | if (o->reloc_count == 0) |
Line 782... | Line 697... | ||
782 | } |
697 | } |
783 | } |
698 | } |
Line 784... | Line 699... | ||
784 | 699 | ||
785 | /* If doing a relocatable link, allocate space for the pointers we |
700 | /* If doing a relocatable link, allocate space for the pointers we |
786 | need to keep. */ |
701 | need to keep. */ |
787 | if (info->relocatable) |
702 | if (bfd_link_relocatable (info)) |
788 | { |
703 | { |
Line 789... | Line 704... | ||
789 | unsigned int i; |
704 | unsigned int i; |
790 | 705 | ||
Line 830... | Line 745... | ||
830 | 745 | ||
831 | Because of this problem, we also keep the relocs in |
746 | Because of this problem, we also keep the relocs in |
832 | memory until the end of the link. This wastes memory, |
747 | memory until the end of the link. This wastes memory, |
833 | but only when doing a relocatable link, which is not the |
748 | but only when doing a relocatable link, which is not the |
834 | common case. */ |
749 | common case. */ |
835 | BFD_ASSERT (info->relocatable); |
750 | BFD_ASSERT (bfd_link_relocatable (info)); |
836 | amt = o->reloc_count; |
751 | amt = o->reloc_count; |
837 | amt *= sizeof (struct internal_reloc); |
752 | amt *= sizeof (struct internal_reloc); |
838 | flaginfo.section_info[o->target_index].relocs = |
753 | flaginfo.section_info[o->target_index].relocs = |
839 | (struct internal_reloc *) bfd_malloc (amt); |
754 | (struct internal_reloc *) bfd_malloc (amt); |
Line 859... | Line 774... | ||
859 | 774 | ||
860 | /* Figure out the largest number of symbols in an input BFD. Take |
775 | /* Figure out the largest number of symbols in an input BFD. Take |
861 | the opportunity to clear the output_has_begun fields of all the |
776 | the opportunity to clear the output_has_begun fields of all the |
862 | input BFD's. */ |
777 | input BFD's. */ |
863 | max_sym_count = 0; |
778 | max_sym_count = 0; |
864 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) |
779 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
865 | { |
780 | { |
Line 866... | Line 781... | ||
866 | size_t sz; |
781 | size_t sz; |
867 | 782 | ||
Line 882... | Line 797... | ||
882 | amt = max_lineno_count * bfd_coff_linesz (abfd); |
797 | amt = max_lineno_count * bfd_coff_linesz (abfd); |
883 | flaginfo.linenos = (bfd_byte *) bfd_malloc (amt); |
798 | flaginfo.linenos = (bfd_byte *) bfd_malloc (amt); |
884 | flaginfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); |
799 | flaginfo.contents = (bfd_byte *) bfd_malloc (max_contents_size); |
885 | amt = max_reloc_count * relsz; |
800 | amt = max_reloc_count * relsz; |
886 | flaginfo.external_relocs = (bfd_byte *) bfd_malloc (amt); |
801 | flaginfo.external_relocs = (bfd_byte *) bfd_malloc (amt); |
887 | if (! info->relocatable) |
802 | if (! bfd_link_relocatable (info)) |
888 | { |
803 | { |
889 | amt = max_reloc_count * sizeof (struct internal_reloc); |
804 | amt = max_reloc_count * sizeof (struct internal_reloc); |
890 | flaginfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt); |
805 | flaginfo.internal_relocs = (struct internal_reloc *) bfd_malloc (amt); |
891 | } |
806 | } |
892 | if ((flaginfo.internal_syms == NULL && max_sym_count > 0) |
807 | if ((flaginfo.internal_syms == NULL && max_sym_count > 0) |
Line 894... | Line 809... | ||
894 | || (flaginfo.sym_indices == NULL && max_sym_count > 0) |
809 | || (flaginfo.sym_indices == NULL && max_sym_count > 0) |
895 | || flaginfo.outsyms == NULL |
810 | || flaginfo.outsyms == NULL |
896 | || (flaginfo.linenos == NULL && max_lineno_count > 0) |
811 | || (flaginfo.linenos == NULL && max_lineno_count > 0) |
897 | || (flaginfo.contents == NULL && max_contents_size > 0) |
812 | || (flaginfo.contents == NULL && max_contents_size > 0) |
898 | || (flaginfo.external_relocs == NULL && max_reloc_count > 0) |
813 | || (flaginfo.external_relocs == NULL && max_reloc_count > 0) |
899 | || (! info->relocatable |
814 | || (! bfd_link_relocatable (info) |
900 | && flaginfo.internal_relocs == NULL |
815 | && flaginfo.internal_relocs == NULL |
901 | && max_reloc_count > 0)) |
816 | && max_reloc_count > 0)) |
902 | goto error_return; |
817 | goto error_return; |
Line 903... | Line 818... | ||
903 | 818 | ||
Line 944... | Line 859... | ||
944 | } |
859 | } |
Line 945... | Line 860... | ||
945 | 860 | ||
946 | if (flaginfo.info->strip != strip_all && flaginfo.info->discard != discard_all) |
861 | if (flaginfo.info->strip != strip_all && flaginfo.info->discard != discard_all) |
947 | { |
862 | { |
948 | /* Add local symbols from foreign inputs. */ |
863 | /* Add local symbols from foreign inputs. */ |
949 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) |
864 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
950 | { |
865 | { |
Line 951... | Line 866... | ||
951 | unsigned int i; |
866 | unsigned int i; |
952 | 867 | ||
Line 974... | Line 889... | ||
974 | && (bfd_hash_lookup (flaginfo.info->keep_hash, |
889 | && (bfd_hash_lookup (flaginfo.info->keep_hash, |
975 | bfd_asymbol_name(sym), FALSE, FALSE) |
890 | bfd_asymbol_name(sym), FALSE, FALSE) |
976 | == NULL)) |
891 | == NULL)) |
977 | || (((flaginfo.info->discard == discard_sec_merge |
892 | || (((flaginfo.info->discard == discard_sec_merge |
978 | && (bfd_get_section (sym)->flags & SEC_MERGE) |
893 | && (bfd_get_section (sym)->flags & SEC_MERGE) |
979 | && ! flaginfo.info->relocatable) |
894 | && ! bfd_link_relocatable (flaginfo.info)) |
980 | || flaginfo.info->discard == discard_l) |
895 | || flaginfo.info->discard == discard_l) |
981 | && bfd_is_local_label_name (sub, bfd_asymbol_name(sym)))) |
896 | && bfd_is_local_label_name (sub, bfd_asymbol_name(sym)))) |
982 | continue; |
897 | continue; |
Line 983... | Line 898... | ||
983 | 898 | ||
Line 1114... | Line 1029... | ||
1114 | { |
1029 | { |
1115 | free (flaginfo.outsyms); |
1030 | free (flaginfo.outsyms); |
1116 | flaginfo.outsyms = NULL; |
1031 | flaginfo.outsyms = NULL; |
1117 | } |
1032 | } |
Line 1118... | Line 1033... | ||
1118 | 1033 | ||
1119 | if (info->relocatable && max_output_reloc_count > 0) |
1034 | if (bfd_link_relocatable (info) && max_output_reloc_count > 0) |
1120 | { |
1035 | { |
1121 | /* Now that we have written out all the global symbols, we know |
1036 | /* Now that we have written out all the global symbols, we know |
1122 | the symbol indices to use for relocs against them, and we can |
1037 | the symbol indices to use for relocs against them, and we can |
1123 | finally write out the relocs. */ |
1038 | finally write out the relocs. */ |
Line 1433... | Line 1348... | ||
1433 | 1348 | ||
1434 | /* Read in the relocs. */ |
1349 | /* Read in the relocs. */ |
1435 | internal_relocs = _bfd_coff_read_internal_relocs |
1350 | internal_relocs = _bfd_coff_read_internal_relocs |
1436 | (input_bfd, a, FALSE, |
1351 | (input_bfd, a, FALSE, |
1437 | flaginfo->external_relocs, |
1352 | flaginfo->external_relocs, |
1438 | flaginfo->info->relocatable, |
1353 | bfd_link_relocatable (flaginfo->info), |
1439 | (flaginfo->info->relocatable |
1354 | (bfd_link_relocatable (flaginfo->info) |
1440 | ? (flaginfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count) |
1355 | ? (flaginfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count) |
1441 | : flaginfo->internal_relocs) |
1356 | : flaginfo->internal_relocs) |
Line 1442... | Line 1357... | ||
1442 | ); |
1357 | ); |
Line 1519... | Line 1434... | ||
1519 | /* If we are going to perform relocations and also strip/discard some |
1434 | /* If we are going to perform relocations and also strip/discard some |
1520 | symbols then we must make sure that we do not strip/discard those |
1435 | symbols then we must make sure that we do not strip/discard those |
1521 | symbols that are going to be involved in the relocations. */ |
1436 | symbols that are going to be involved in the relocations. */ |
1522 | if (( flaginfo->info->strip != strip_none |
1437 | if (( flaginfo->info->strip != strip_none |
1523 | || flaginfo->info->discard != discard_none) |
1438 | || flaginfo->info->discard != discard_none) |
1524 | && flaginfo->info->relocatable) |
1439 | && bfd_link_relocatable (flaginfo->info)) |
1525 | { |
1440 | { |
1526 | /* Mark the symbol array as 'not-used'. */ |
1441 | /* Mark the symbol array as 'not-used'. */ |
1527 | memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp); |
1442 | memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp); |
Line 1528... | Line 1443... | ||
1528 | 1443 | ||
Line 1566... | Line 1481... | ||
1566 | 1481 | ||
1567 | /* Extract the flag indicating if this symbol is used by a |
1482 | /* Extract the flag indicating if this symbol is used by a |
1568 | relocation. */ |
1483 | relocation. */ |
1569 | if ((flaginfo->info->strip != strip_none |
1484 | if ((flaginfo->info->strip != strip_none |
1570 | || flaginfo->info->discard != discard_none) |
1485 | || flaginfo->info->discard != discard_none) |
1571 | && flaginfo->info->relocatable) |
1486 | && bfd_link_relocatable (flaginfo->info)) |
1572 | dont_skip_symbol = *indexp; |
1487 | dont_skip_symbol = *indexp; |
1573 | else |
1488 | else |
Line 1574... | Line 1489... | ||
1574 | dont_skip_symbol = FALSE; |
1489 | dont_skip_symbol = FALSE; |
Line 2086... | Line 2001... | ||
2086 | { |
2001 | { |
2087 | strings = _bfd_coff_read_string_table (input_bfd); |
2002 | strings = _bfd_coff_read_string_table (input_bfd); |
2088 | if (strings == NULL) |
2003 | if (strings == NULL) |
2089 | return FALSE; |
2004 | return FALSE; |
2090 | } |
2005 | } |
- | 2006 | if ((bfd_size_type) auxp->x_file.x_n.x_offset >= obj_coff_strings_len (input_bfd)) |
|
- | 2007 | filename = _(" |
|
- | 2008 | else |
|
2091 | filename = strings + auxp->x_file.x_n.x_offset; |
2009 | filename = strings + auxp->x_file.x_n.x_offset; |
2092 | indx = _bfd_stringtab_add (flaginfo->strtab, filename, |
2010 | indx = _bfd_stringtab_add (flaginfo->strtab, filename, |
2093 | hash, copy); |
2011 | hash, copy); |
2094 | if (indx == (bfd_size_type) -1) |
2012 | if (indx == (bfd_size_type) -1) |
2095 | return FALSE; |
2013 | return FALSE; |
Line 2440... | Line 2358... | ||
2440 | 2358 | ||
2441 | /* Read in the relocs. */ |
2359 | /* Read in the relocs. */ |
2442 | target_index = o->output_section->target_index; |
2360 | target_index = o->output_section->target_index; |
2443 | internal_relocs = (_bfd_coff_read_internal_relocs |
2361 | internal_relocs = (_bfd_coff_read_internal_relocs |
2444 | (input_bfd, o, FALSE, flaginfo->external_relocs, |
2362 | (input_bfd, o, FALSE, flaginfo->external_relocs, |
2445 | flaginfo->info->relocatable, |
2363 | bfd_link_relocatable (flaginfo->info), |
2446 | (flaginfo->info->relocatable |
2364 | (bfd_link_relocatable (flaginfo->info) |
2447 | ? (flaginfo->section_info[target_index].relocs |
2365 | ? (flaginfo->section_info[target_index].relocs |
2448 | + o->output_section->reloc_count) |
2366 | + o->output_section->reloc_count) |
2449 | : flaginfo->internal_relocs))); |
2367 | : flaginfo->internal_relocs))); |
2450 | if (internal_relocs == NULL |
2368 | if (internal_relocs == NULL |
Line 2488... | Line 2406... | ||
2488 | internal_relocs, |
2406 | internal_relocs, |
2489 | flaginfo->internal_syms, |
2407 | flaginfo->internal_syms, |
2490 | flaginfo->sec_ptrs)) |
2408 | flaginfo->sec_ptrs)) |
2491 | return FALSE; |
2409 | return FALSE; |
Line 2492... | Line 2410... | ||
2492 | 2410 | ||
2493 | if (flaginfo->info->relocatable) |
2411 | if (bfd_link_relocatable (flaginfo->info)) |
2494 | { |
2412 | { |
2495 | bfd_vma offset; |
2413 | bfd_vma offset; |
2496 | struct internal_reloc *irelend; |
2414 | struct internal_reloc *irelend; |
Line 2716... | Line 2634... | ||
2716 | } |
2634 | } |
Line 2717... | Line 2635... | ||
2717 | 2635 | ||
2718 | /* When a weak symbol is not overridden by a strong one, |
2636 | /* When a weak symbol is not overridden by a strong one, |
2719 | turn it into an external symbol when not building a |
2637 | turn it into an external symbol when not building a |
2720 | shared or relocatable object. */ |
2638 | shared or relocatable object. */ |
2721 | if (! flaginfo->info->shared |
2639 | if (! bfd_link_pic (flaginfo->info) |
2722 | && ! flaginfo->info->relocatable |
2640 | && ! bfd_link_relocatable (flaginfo->info) |
2723 | && IS_WEAK_EXTERNAL (flaginfo->output_bfd, isym)) |
2641 | && IS_WEAK_EXTERNAL (flaginfo->output_bfd, isym)) |
Line 2724... | Line 2642... | ||
2724 | isym.n_sclass = C_EXT; |
2642 | isym.n_sclass = C_EXT; |
Line 2770... | Line 2688... | ||
2770 | 2688 | ||
2771 | /* For PE, an overflow on the final link reportedly does |
2689 | /* For PE, an overflow on the final link reportedly does |
2772 | not matter. FIXME: Why not? */ |
2690 | not matter. FIXME: Why not? */ |
2773 | if (sec->reloc_count > 0xffff |
2691 | if (sec->reloc_count > 0xffff |
2774 | && (! obj_pe (output_bfd) |
2692 | && (! obj_pe (output_bfd) |
2775 | || flaginfo->info->relocatable)) |
2693 | || bfd_link_relocatable (flaginfo->info))) |
2776 | (*_bfd_error_handler) |
2694 | (*_bfd_error_handler) |
2777 | (_("%s: %s: reloc overflow: 0x%lx > 0xffff"), |
2695 | (_("%s: %s: reloc overflow: 0x%lx > 0xffff"), |
2778 | bfd_get_filename (output_bfd), |
2696 | bfd_get_filename (output_bfd), |
2779 | bfd_get_section_name (output_bfd, sec), |
2697 | bfd_get_section_name (output_bfd, sec), |
Line 2780... | Line 2698... | ||
2780 | sec->reloc_count); |
2698 | sec->reloc_count); |
2781 | 2699 | ||
2782 | if (sec->lineno_count > 0xffff |
2700 | if (sec->lineno_count > 0xffff |
2783 | && (! obj_pe (output_bfd) |
2701 | && (! obj_pe (output_bfd) |
2784 | || flaginfo->info->relocatable)) |
2702 | || bfd_link_relocatable (flaginfo->info))) |
2785 | (*_bfd_error_handler) |
2703 | (*_bfd_error_handler) |
2786 | (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), |
2704 | (_("%s: warning: %s: line number overflow: 0x%lx > 0xffff"), |
2787 | bfd_get_filename (output_bfd), |
2705 | bfd_get_filename (output_bfd), |
Line 2869... | Line 2787... | ||
2869 | bfd_boolean ok; |
2787 | bfd_boolean ok; |
2870 | file_ptr loc; |
2788 | file_ptr loc; |
Line 2871... | Line 2789... | ||
2871 | 2789 | ||
2872 | size = bfd_get_reloc_size (howto); |
2790 | size = bfd_get_reloc_size (howto); |
2873 | buf = (bfd_byte *) bfd_zmalloc (size); |
2791 | buf = (bfd_byte *) bfd_zmalloc (size); |
2874 | if (buf == NULL) |
2792 | if (buf == NULL && size != 0) |
Line 2875... | Line 2793... | ||
2875 | return FALSE; |
2793 | return FALSE; |
2876 | 2794 | ||
2877 | rstat = _bfd_relocate_contents (howto, output_bfd, |
2795 | rstat = _bfd_relocate_contents (howto, output_bfd, |
Line 2995... | Line 2913... | ||
2995 | long symndx; |
2913 | long symndx; |
2996 | struct coff_link_hash_entry *h; |
2914 | struct coff_link_hash_entry *h; |
2997 | struct internal_syment *sym; |
2915 | struct internal_syment *sym; |
2998 | bfd_vma addend; |
2916 | bfd_vma addend; |
2999 | bfd_vma val; |
2917 | bfd_vma val; |
- | 2918 | asection *sec; |
|
3000 | reloc_howto_type *howto; |
2919 | reloc_howto_type *howto; |
3001 | bfd_reloc_status_type rstat; |
2920 | bfd_reloc_status_type rstat; |
Line 3002... | Line 2921... | ||
3002 | 2921 | ||
Line 3038... | Line 2957... | ||
3038 | a PC relative reloc that is pcrel_offset. It will already |
2957 | a PC relative reloc that is pcrel_offset. It will already |
3039 | have the correct value. If this is not a relocatable link, |
2958 | have the correct value. If this is not a relocatable link, |
3040 | then we should ignore the symbol value. */ |
2959 | then we should ignore the symbol value. */ |
3041 | if (howto->pc_relative && howto->pcrel_offset) |
2960 | if (howto->pc_relative && howto->pcrel_offset) |
3042 | { |
2961 | { |
3043 | if (info->relocatable) |
2962 | if (bfd_link_relocatable (info)) |
3044 | continue; |
2963 | continue; |
3045 | if (sym != NULL && sym->n_scnum != 0) |
2964 | if (sym != NULL && sym->n_scnum != 0) |
3046 | addend += sym->n_value; |
2965 | addend += sym->n_value; |
3047 | } |
2966 | } |
Line 3048... | Line 2967... | ||
3048 | 2967 | ||
3049 | val = 0; |
- | |
- | 2968 | val = 0; |
|
3050 | 2969 | sec = NULL; |
|
3051 | if (h == NULL) |
2970 | if (h == NULL) |
3052 | { |
- | |
3053 | asection *sec; |
- | |
3054 | 2971 | { |
|
3055 | if (symndx == -1) |
2972 | if (symndx == -1) |
3056 | { |
2973 | { |
3057 | sec = bfd_abs_section_ptr; |
2974 | sec = bfd_abs_section_ptr; |
3058 | val = 0; |
2975 | val = 0; |
Line 3071... | Line 2988... | ||
3071 | { |
2988 | { |
3072 | if (h->root.type == bfd_link_hash_defined |
2989 | if (h->root.type == bfd_link_hash_defined |
3073 | || h->root.type == bfd_link_hash_defweak) |
2990 | || h->root.type == bfd_link_hash_defweak) |
3074 | { |
2991 | { |
3075 | /* Defined weak symbols are a GNU extension. */ |
2992 | /* Defined weak symbols are a GNU extension. */ |
3076 | asection *sec; |
- | |
3077 | - | ||
3078 | sec = h->root.u.def.section; |
2993 | sec = h->root.u.def.section; |
3079 | val = (h->root.u.def.value |
2994 | val = (h->root.u.def.value |
3080 | + sec->output_section->vma |
2995 | + sec->output_section->vma |
3081 | + sec->output_offset); |
2996 | + sec->output_offset); |
3082 | } |
2997 | } |
Line 3093... | Line 3008... | ||
3093 | characteristic IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1). |
3008 | characteristic IMAGE_WEAK_EXTERN_SEARCH_NOLIBRARY (1). |
3094 | These behave as per SVR4 ABI: A library member |
3009 | These behave as per SVR4 ABI: A library member |
3095 | will resolve a weak external only if a normal |
3010 | will resolve a weak external only if a normal |
3096 | external causes the library member to be linked. |
3011 | external causes the library member to be linked. |
3097 | See also linker.c: generic_link_check_archive_element. */ |
3012 | See also linker.c: generic_link_check_archive_element. */ |
3098 | asection *sec; |
- | |
3099 | struct coff_link_hash_entry *h2 = |
3013 | struct coff_link_hash_entry *h2 = |
3100 | h->auxbfd->tdata.coff_obj_data->sym_hashes[ |
3014 | h->auxbfd->tdata.coff_obj_data->sym_hashes[ |
3101 | h->aux->x_sym.x_tagndx.l]; |
3015 | h->aux->x_sym.x_tagndx.l]; |
Line 3102... | Line 3016... | ||
3102 | 3016 | ||
Line 3115... | Line 3029... | ||
3115 | else |
3029 | else |
3116 | /* This is a GNU extension. */ |
3030 | /* This is a GNU extension. */ |
3117 | val = 0; |
3031 | val = 0; |
3118 | } |
3032 | } |
Line 3119... | Line 3033... | ||
3119 | 3033 | ||
3120 | else if (! info->relocatable) |
3034 | else if (! bfd_link_relocatable (info)) |
3121 | { |
3035 | { |
3122 | if (! ((*info->callbacks->undefined_symbol) |
3036 | if (! ((*info->callbacks->undefined_symbol) |
3123 | (info, h->root.root.string, input_bfd, input_section, |
3037 | (info, h->root.root.string, input_bfd, input_section, |
3124 | rel->r_vaddr - input_section->vma, TRUE))) |
3038 | rel->r_vaddr - input_section->vma, TRUE))) |
3125 | return FALSE; |
3039 | return FALSE; |
3126 | } |
3040 | } |
Line -... | Line 3041... | ||
- | 3041 | } |
|
- | 3042 | ||
- | 3043 | /* If the input section defining the symbol has been discarded |
|
- | 3044 | then zero this reloc field. */ |
|
- | 3045 | if (sec != NULL && discarded_section (sec)) |
|
- | 3046 | { |
|
- | 3047 | _bfd_clear_contents (howto, input_bfd, input_section, |
|
- | 3048 | contents + (rel->r_vaddr - input_section->vma)); |
|
- | 3049 | continue; |
|
3127 | } |
3050 | } |
3128 | 3051 | ||
3129 | if (info->base_file) |
3052 | if (info->base_file) |
3130 | { |
3053 | { |
3131 | /* Emit a reloc if the backend thinks it needs it. */ |
3054 | /* Emit a reloc if the backend thinks it needs it. */ |