Rev 5197 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5197 | Rev 6324 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* linker.c -- BFD linker routines |
1 | /* linker.c -- BFD linker routines |
2 | Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, |
- | |
3 | 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 |
- | |
4 | Free Software Foundation, Inc. |
2 | Copyright (C) 1993-2015 Free Software Foundation, Inc. |
5 | Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support |
3 | Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support |
Line 6... | Line 4... | ||
6 | 4 | ||
Line 7... | Line 5... | ||
7 | This file is part of BFD, the Binary File Descriptor library. |
5 | This file is part of BFD, the Binary File Descriptor library. |
Line 229... | Line 227... | ||
229 | to the linker hash table instead.) |
227 | to the linker hash table instead.) |
Line 230... | Line 228... | ||
230 | 228 | ||
231 | @findex _bfd_generic_link_add_archive_symbols |
229 | @findex _bfd_generic_link_add_archive_symbols |
232 | In most cases the work of looking through the symbols in the |
230 | In most cases the work of looking through the symbols in the |
233 | archive should be done by the |
231 | archive should be done by the |
234 | <<_bfd_generic_link_add_archive_symbols>> function. This |
- | |
235 | function builds a hash table from the archive symbol table and |
- | |
236 | looks through the list of undefined symbols to see which |
- | |
237 | elements should be included. |
232 | <<_bfd_generic_link_add_archive_symbols>> function. |
238 | <<_bfd_generic_link_add_archive_symbols>> is passed a function |
233 | <<_bfd_generic_link_add_archive_symbols>> is passed a function |
239 | to call to make the final decision about adding an archive |
234 | to call to make the final decision about adding an archive |
240 | element to the link and to do the actual work of adding the |
235 | element to the link and to do the actual work of adding the |
241 | symbols to the linker hash table. |
- | |
242 | - | ||
243 | The function passed to |
- | |
244 | <<_bfd_generic_link_add_archive_symbols>> must read the |
- | |
245 | symbols of the archive element and decide whether the archive |
- | |
246 | element should be included in the link. If the element is to |
236 | symbols to the linker hash table. If the element is to |
247 | be included, the < |
237 | be included, the < |
248 | routine must be called with the element as an argument, and |
238 | routine must be called with the element as an argument, and |
249 | the element's symbols must be added to the linker hash table |
239 | the element's symbols must be added to the linker hash table |
250 | just as though the element had itself been passed to the |
240 | just as though the element had itself been passed to the |
251 | <<_bfd_link_add_symbols>> function. The < |
- | |
252 | callback has the option to indicate that it would like to |
- | |
253 | replace the element archive with a substitute BFD, in which |
- | |
254 | case it is the symbols of that substitute BFD that must be |
- | |
Line 255... | Line 241... | ||
255 | added to the linker hash table instead. |
241 | <<_bfd_link_add_symbols>> function. |
256 | 242 | ||
257 | When the a.out <<_bfd_link_add_symbols>> function receives an |
243 | When the a.out <<_bfd_link_add_symbols>> function receives an |
258 | archive, it calls <<_bfd_generic_link_add_archive_symbols>> |
244 | archive, it calls <<_bfd_generic_link_add_archive_symbols>> |
Line 313... | Line 299... | ||
313 | Before the linker calls the <<_bfd_final_link>> entry point, |
299 | Before the linker calls the <<_bfd_final_link>> entry point, |
314 | it sets up some data structures for the function to use. |
300 | it sets up some data structures for the function to use. |
Line 315... | Line 301... | ||
315 | 301 | ||
316 | The < |
302 | The < |
317 | will point to a list of all the input files included in the |
303 | will point to a list of all the input files included in the |
318 | link. These files are linked through the < |
304 | link. These files are linked through the < |
Line 319... | Line 305... | ||
319 | of the < |
305 | of the < |
320 | 306 | ||
321 | Each section in the output file will have a list of |
307 | Each section in the output file will have a list of |
Line 419... | Line 405... | ||
419 | static bfd_boolean generic_link_add_object_symbols |
405 | static bfd_boolean generic_link_add_object_symbols |
420 | (bfd *, struct bfd_link_info *, bfd_boolean collect); |
406 | (bfd *, struct bfd_link_info *, bfd_boolean collect); |
421 | static bfd_boolean generic_link_add_symbols |
407 | static bfd_boolean generic_link_add_symbols |
422 | (bfd *, struct bfd_link_info *, bfd_boolean); |
408 | (bfd *, struct bfd_link_info *, bfd_boolean); |
423 | static bfd_boolean generic_link_check_archive_element_no_collect |
409 | static bfd_boolean generic_link_check_archive_element_no_collect |
424 | (bfd *, struct bfd_link_info *, bfd_boolean *); |
410 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 411 | bfd_boolean *); |
|
425 | static bfd_boolean generic_link_check_archive_element_collect |
412 | static bfd_boolean generic_link_check_archive_element_collect |
426 | (bfd *, struct bfd_link_info *, bfd_boolean *); |
413 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 414 | bfd_boolean *); |
|
427 | static bfd_boolean generic_link_check_archive_element |
415 | static bfd_boolean generic_link_check_archive_element |
428 | (bfd *, struct bfd_link_info *, bfd_boolean *, bfd_boolean); |
416 | (bfd *, struct bfd_link_info *, struct bfd_link_hash_entry *, const char *, |
- | 417 | bfd_boolean *, bfd_boolean); |
|
429 | static bfd_boolean generic_link_add_symbol_list |
418 | static bfd_boolean generic_link_add_symbol_list |
430 | (bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **, |
419 | (bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **, |
431 | bfd_boolean); |
420 | bfd_boolean); |
432 | static bfd_boolean generic_add_output_symbol |
421 | static bfd_boolean generic_add_output_symbol |
433 | (bfd *, size_t *psymalloc, asymbol *); |
422 | (bfd *, size_t *psymalloc, asymbol *); |
Line 482... | Line 471... | ||
482 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
471 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
483 | struct bfd_hash_table *, |
472 | struct bfd_hash_table *, |
484 | const char *), |
473 | const char *), |
485 | unsigned int entsize) |
474 | unsigned int entsize) |
486 | { |
475 | { |
- | 476 | bfd_boolean ret; |
|
- | 477 | ||
- | 478 | BFD_ASSERT (!abfd->is_linker_output && !abfd->link.hash); |
|
487 | table->undefs = NULL; |
479 | table->undefs = NULL; |
488 | table->undefs_tail = NULL; |
480 | table->undefs_tail = NULL; |
489 | table->type = bfd_link_generic_hash_table; |
481 | table->type = bfd_link_generic_hash_table; |
Line 490... | Line 482... | ||
490 | 482 | ||
- | 483 | ret = bfd_hash_table_init (&table->table, newfunc, entsize); |
|
- | 484 | if (ret) |
|
- | 485 | { |
|
- | 486 | /* Arrange for destruction of this hash table on closing ABFD. */ |
|
- | 487 | table->hash_table_free = _bfd_generic_link_hash_table_free; |
|
- | 488 | abfd->link.hash = table; |
|
- | 489 | abfd->is_linker_output = TRUE; |
|
- | 490 | } |
|
491 | return bfd_hash_table_init (&table->table, newfunc, entsize); |
491 | return ret; |
Line 492... | Line 492... | ||
492 | } |
492 | } |
493 | 493 | ||
494 | /* Look up a symbol in a link hash table. If follow is TRUE, we |
494 | /* Look up a symbol in a link hash table. If follow is TRUE, we |
Line 566... | Line 566... | ||
566 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
566 | h = bfd_link_hash_lookup (info->hash, n, create, TRUE, follow); |
567 | free (n); |
567 | free (n); |
568 | return h; |
568 | return h; |
569 | } |
569 | } |
Line 570... | Line -... | ||
570 | - | ||
571 | #undef WRAP |
- | |
572 | 570 | ||
573 | #undef REAL |
571 | #undef REAL |
Line 574... | Line 572... | ||
574 | #define REAL "__real_" |
572 | #define REAL "__real_" |
575 | 573 | ||
Line 602... | Line 600... | ||
602 | } |
600 | } |
Line 603... | Line 601... | ||
603 | 601 | ||
604 | return bfd_link_hash_lookup (info->hash, string, create, copy, follow); |
602 | return bfd_link_hash_lookup (info->hash, string, create, copy, follow); |
Line -... | Line 603... | ||
- | 603 | } |
|
- | 604 | ||
- | 605 | /* If H is a wrapped symbol, ie. the symbol name starts with "__wrap_" |
|
- | 606 | and the remainder is found in wrap_hash, return the real symbol. */ |
|
- | 607 | ||
- | 608 | struct bfd_link_hash_entry * |
|
- | 609 | unwrap_hash_lookup (struct bfd_link_info *info, |
|
- | 610 | bfd *input_bfd, |
|
- | 611 | struct bfd_link_hash_entry *h) |
|
- | 612 | { |
|
- | 613 | const char *l = h->root.string; |
|
- | 614 | ||
- | 615 | if (*l == bfd_get_symbol_leading_char (input_bfd) |
|
- | 616 | || *l == info->wrap_char) |
|
- | 617 | ++l; |
|
- | 618 | ||
- | 619 | if (CONST_STRNEQ (l, WRAP)) |
|
- | 620 | { |
|
- | 621 | l += sizeof WRAP - 1; |
|
- | 622 | ||
- | 623 | if (bfd_hash_lookup (info->wrap_hash, l, FALSE, FALSE) != NULL) |
|
- | 624 | { |
|
- | 625 | char save = 0; |
|
- | 626 | if (l - (sizeof WRAP - 1) != h->root.string) |
|
- | 627 | { |
|
- | 628 | --l; |
|
- | 629 | save = *l; |
|
- | 630 | *(char *) l = *h->root.string; |
|
- | 631 | } |
|
- | 632 | h = bfd_link_hash_lookup (info->hash, l, FALSE, FALSE, FALSE); |
|
- | 633 | if (save) |
|
- | 634 | *(char *) l = save; |
|
- | 635 | } |
|
- | 636 | } |
|
- | 637 | return h; |
|
- | 638 | } |
|
605 | } |
639 | #undef WRAP |
606 | 640 | ||
607 | /* Traverse a generic link hash table. Differs from bfd_hash_traverse |
641 | /* Traverse a generic link hash table. Differs from bfd_hash_traverse |
608 | in the treatment of warning symbols. When warning symbols are |
642 | in the treatment of warning symbols. When warning symbols are |
609 | created they replace the real symbol, so you don't get to see the |
643 | created they replace the real symbol, so you don't get to see the |
Line 737... | Line 771... | ||
737 | } |
771 | } |
738 | return &ret->root; |
772 | return &ret->root; |
739 | } |
773 | } |
Line 740... | Line 774... | ||
740 | 774 | ||
741 | void |
775 | void |
742 | _bfd_generic_link_hash_table_free (struct bfd_link_hash_table *hash) |
776 | _bfd_generic_link_hash_table_free (bfd *obfd) |
743 | { |
777 | { |
744 | struct generic_link_hash_table *ret |
- | |
Line -... | Line 778... | ||
- | 778 | struct generic_link_hash_table *ret; |
|
- | 779 | ||
745 | = (struct generic_link_hash_table *) hash; |
780 | BFD_ASSERT (obfd->is_linker_output && obfd->link.hash); |
746 | 781 | ret = (struct generic_link_hash_table *) obfd->link.hash; |
|
- | 782 | bfd_hash_table_free (&ret->root.table); |
|
- | 783 | free (ret); |
|
747 | bfd_hash_table_free (&ret->root.table); |
784 | obfd->link.hash = NULL; |
Line 748... | Line 785... | ||
748 | free (ret); |
785 | obfd->is_linker_output = FALSE; |
749 | } |
786 | } |
750 | 787 | ||
Line 813... | Line 850... | ||
813 | sec->sec_info_type = SEC_INFO_TYPE_JUST_SYMS; |
850 | sec->sec_info_type = SEC_INFO_TYPE_JUST_SYMS; |
814 | sec->output_section = bfd_abs_section_ptr; |
851 | sec->output_section = bfd_abs_section_ptr; |
815 | sec->output_offset = sec->vma; |
852 | sec->output_offset = sec->vma; |
816 | } |
853 | } |
Line 817... | Line 854... | ||
817 | 854 | ||
818 | /* Copy the type of a symbol assiciated with a linker hast table entry. |
- | |
819 | Override this so that symbols created in linker scripts get their |
855 | /* Copy the symbol type and other attributes for a linker script |
820 | type from the RHS of the assignment. |
856 | assignment from HSRC to HDEST. |
821 | The default implementation does nothing. */ |
857 | The default implementation does nothing. */ |
822 | void |
858 | void |
823 | _bfd_generic_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED, |
859 | _bfd_generic_copy_link_hash_symbol_type (bfd *abfd ATTRIBUTE_UNUSED, |
824 | struct bfd_link_hash_entry * hdest ATTRIBUTE_UNUSED, |
860 | struct bfd_link_hash_entry *hdest ATTRIBUTE_UNUSED, |
Line 870... | Line 906... | ||
870 | symcount = _bfd_generic_link_get_symcount (abfd); |
906 | symcount = _bfd_generic_link_get_symcount (abfd); |
871 | outsyms = _bfd_generic_link_get_symbols (abfd); |
907 | outsyms = _bfd_generic_link_get_symbols (abfd); |
872 | return generic_link_add_symbol_list (abfd, info, symcount, outsyms, collect); |
908 | return generic_link_add_symbol_list (abfd, info, symcount, outsyms, collect); |
873 | } |
909 | } |
874 | 910 | ||
875 | /* We build a hash table of all symbols defined in an archive. */ |
- | |
876 | - | ||
877 | /* An archive symbol may be defined by multiple archive elements. |
- | |
878 | This linked list is used to hold the elements. */ |
- | |
879 | - | ||
880 | struct archive_list |
- | |
881 | { |
- | |
882 | struct archive_list *next; |
- | |
883 | unsigned int indx; |
- | |
884 | }; |
- | |
885 | - | ||
886 | /* An entry in an archive hash table. */ |
- | |
887 | - | ||
888 | struct archive_hash_entry |
- | |
889 | { |
- | |
890 | struct bfd_hash_entry root; |
- | |
891 | /* Where the symbol is defined. */ |
- | |
892 | struct archive_list *defs; |
- | |
893 | }; |
- | |
894 | - | ||
895 | /* An archive hash table itself. */ |
- | |
896 | - | ||
897 | struct archive_hash_table |
- | |
898 | { |
- | |
899 | struct bfd_hash_table table; |
- | |
900 | }; |
- | |
901 | - | ||
902 | /* Create a new entry for an archive hash table. */ |
- | |
903 | - | ||
904 | static struct bfd_hash_entry * |
- | |
905 | archive_hash_newfunc (struct bfd_hash_entry *entry, |
- | |
906 | struct bfd_hash_table *table, |
- | |
907 | const char *string) |
- | |
908 | { |
- | |
909 | struct archive_hash_entry *ret = (struct archive_hash_entry *) entry; |
- | |
910 | - | ||
911 | /* Allocate the structure if it has not already been allocated by a |
- | |
912 | subclass. */ |
- | |
913 | if (ret == NULL) |
- | |
914 | ret = (struct archive_hash_entry *) |
- | |
915 | bfd_hash_allocate (table, sizeof (struct archive_hash_entry)); |
- | |
916 | if (ret == NULL) |
- | |
917 | return NULL; |
- | |
918 | - | ||
919 | /* Call the allocation method of the superclass. */ |
- | |
920 | ret = ((struct archive_hash_entry *) |
- | |
921 | bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string)); |
- | |
922 | - | ||
923 | if (ret) |
- | |
924 | { |
- | |
925 | /* Initialize the local fields. */ |
- | |
926 | ret->defs = NULL; |
- | |
927 | } |
- | |
928 | - | ||
929 | return &ret->root; |
- | |
930 | } |
- | |
931 | - | ||
932 | /* Initialize an archive hash table. */ |
- | |
933 | - | ||
934 | static bfd_boolean |
- | |
935 | archive_hash_table_init |
- | |
936 | (struct archive_hash_table *table, |
- | |
937 | struct bfd_hash_entry *(*newfunc) (struct bfd_hash_entry *, |
- | |
938 | struct bfd_hash_table *, |
- | |
939 | const char *), |
- | |
940 | unsigned int entsize) |
- | |
941 | { |
- | |
942 | return bfd_hash_table_init (&table->table, newfunc, entsize); |
- | |
943 | } |
- | |
944 | - | ||
945 | /* Look up an entry in an archive hash table. */ |
- | |
946 | - | ||
947 | #define archive_hash_lookup(t, string, create, copy) \ |
- | |
948 | ((struct archive_hash_entry *) \ |
- | |
949 | bfd_hash_lookup (&(t)->table, (string), (create), (copy))) |
- | |
950 | - | ||
951 | /* Allocate space in an archive hash table. */ |
- | |
952 | - | ||
953 | #define archive_hash_allocate(t, size) bfd_hash_allocate (&(t)->table, (size)) |
- | |
954 | - | ||
955 | /* Free an archive hash table. */ |
- | |
956 | - | ||
957 | #define archive_hash_table_free(t) bfd_hash_table_free (&(t)->table) |
- | |
958 | - | ||
959 | /* Generic function to add symbols from an archive file to the global |
911 | /* Generic function to add symbols from an archive file to the global |
960 | hash file. This function presumes that the archive symbol table |
912 | hash file. This function presumes that the archive symbol table |
961 | has already been read in (this is normally done by the |
913 | has already been read in (this is normally done by the |
962 | bfd_check_format entry point). It looks through the undefined and |
914 | bfd_check_format entry point). It looks through the archive symbol |
963 | common symbols and searches the archive symbol table for them. If |
915 | table for symbols that are undefined or common in the linker global |
964 | it finds an entry, it includes the associated object file in the |
- | |
965 | link. |
- | |
966 | - | ||
967 | The old linker looked through the archive symbol table for |
- | |
968 | undefined symbols. We do it the other way around, looking through |
916 | symbol hash table. When one is found, the CHECKFN argument is used |
969 | undefined symbols for symbols defined in the archive. The |
- | |
970 | advantage of the newer scheme is that we only have to look through |
917 | to see if an object file should be included. This allows targets |
971 | the list of undefined symbols once, whereas the old method had to |
918 | to customize common symbol behaviour. CHECKFN should set *PNEEDED |
972 | re-search the symbol table each time a new object file was added. |
- | |
973 | - | ||
974 | The CHECKFN argument is used to see if an object file should be |
- | |
975 | included. CHECKFN should set *PNEEDED to TRUE if the object file |
- | |
976 | should be included, and must also call the bfd_link_info |
919 | to TRUE if the object file should be included, and must also call |
977 | add_archive_element callback function and handle adding the symbols |
920 | the bfd_link_info add_archive_element callback function and handle |
978 | to the global hash table. CHECKFN must notice if the callback |
921 | adding the symbols to the global hash table. CHECKFN must notice |
979 | indicates a substitute BFD, and arrange to add those symbols instead |
922 | if the callback indicates a substitute BFD, and arrange to add |
980 | if it does so. CHECKFN should only return FALSE if some sort of |
923 | those symbols instead if it does so. CHECKFN should only return |
981 | error occurs. |
- | |
982 | - | ||
983 | For some formats, such as a.out, it is possible to look through an |
- | |
984 | object file but not actually include it in the link. The |
- | |
985 | archive_pass field in a BFD is used to avoid checking the symbols |
- | |
986 | of an object files too many times. When an object is included in |
- | |
987 | the link, archive_pass is set to -1. If an object is scanned but |
- | |
988 | not included, archive_pass is set to the pass number. The pass |
- | |
989 | number is incremented each time a new object file is included. The |
- | |
990 | pass number is used because when a new object file is included it |
- | |
991 | may create new undefined symbols which cause a previously examined |
- | |
992 | object file to be included. */ |
924 | FALSE if some sort of error occurs. */ |
Line 993... | Line 925... | ||
993 | 925 | ||
994 | bfd_boolean |
926 | bfd_boolean |
995 | _bfd_generic_link_add_archive_symbols |
927 | _bfd_generic_link_add_archive_symbols |
996 | (bfd *abfd, |
928 | (bfd *abfd, |
997 | struct bfd_link_info *info, |
929 | struct bfd_link_info *info, |
- | 930 | bfd_boolean (*checkfn) (bfd *, struct bfd_link_info *, |
|
- | 931 | struct bfd_link_hash_entry *, const char *, |
|
998 | bfd_boolean (*checkfn) (bfd *, struct bfd_link_info *, bfd_boolean *)) |
932 | bfd_boolean *)) |
999 | { |
933 | { |
1000 | carsym *arsyms; |
- | |
1001 | carsym *arsym_end; |
- | |
1002 | register carsym *arsym; |
934 | bfd_boolean loop; |
1003 | int pass; |
- | |
1004 | struct archive_hash_table arsym_hash; |
935 | bfd_size_type amt; |
1005 | unsigned int indx; |
- | |
Line 1006... | Line 936... | ||
1006 | struct bfd_link_hash_entry **pundef; |
936 | unsigned char *included; |
1007 | 937 | ||
1008 | if (! bfd_has_map (abfd)) |
938 | if (! bfd_has_map (abfd)) |
1009 | { |
939 | { |
1010 | /* An empty archive is a special case. */ |
940 | /* An empty archive is a special case. */ |
1011 | if (bfd_openr_next_archived_file (abfd, NULL) == NULL) |
941 | if (bfd_openr_next_archived_file (abfd, NULL) == NULL) |
1012 | return TRUE; |
942 | return TRUE; |
1013 | bfd_set_error (bfd_error_no_armap); |
943 | bfd_set_error (bfd_error_no_armap); |
Line 1014... | Line 944... | ||
1014 | return FALSE; |
944 | return FALSE; |
1015 | } |
945 | } |
1016 | - | ||
1017 | arsyms = bfd_ardata (abfd)->symdefs; |
946 | |
1018 | arsym_end = arsyms + bfd_ardata (abfd)->symdef_count; |
947 | amt = bfd_ardata (abfd)->symdef_count; |
1019 | 948 | if (amt == 0) |
|
1020 | /* In order to quickly determine whether an symbol is defined in |
949 | return TRUE; |
1021 | this archive, we build a hash table of the symbols. */ |
950 | amt *= sizeof (*included); |
1022 | if (! archive_hash_table_init (&arsym_hash, archive_hash_newfunc, |
- | |
- | 951 | included = (unsigned char *) bfd_zmalloc (amt); |
|
- | 952 | if (included == NULL) |
|
1023 | sizeof (struct archive_hash_entry))) |
953 | return FALSE; |
- | 954 | ||
- | 955 | do |
|
- | 956 | { |
|
- | 957 | carsym *arsyms; |
|
1024 | return FALSE; |
958 | carsym *arsym_end; |
- | 959 | carsym *arsym; |
|
1025 | for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++) |
960 | unsigned int indx; |
Line 1026... | Line -... | ||
1026 | { |
- | |
1027 | struct archive_hash_entry *arh; |
- | |
1028 | struct archive_list *l, **pp; |
- | |
1029 | - | ||
1030 | arh = archive_hash_lookup (&arsym_hash, arsym->name, TRUE, FALSE); |
- | |
1031 | if (arh == NULL) |
- | |
1032 | goto error_return; |
- | |
1033 | l = ((struct archive_list *) |
- | |
1034 | archive_hash_allocate (&arsym_hash, sizeof (struct archive_list))); |
- | |
1035 | if (l == NULL) |
- | |
1036 | goto error_return; |
961 | file_ptr last_ar_offset = -1; |
1037 | l->indx = indx; |
- | |
1038 | for (pp = &arh->defs; *pp != NULL; pp = &(*pp)->next) |
- | |
1039 | ; |
- | |
1040 | *pp = l; |
- | |
1041 | l->next = NULL; |
- | |
1042 | } |
- | |
1043 | 962 | bfd_boolean needed = FALSE; |
|
1044 | /* The archive_pass field in the archive itself is used to |
- | |
1045 | initialize PASS, sine we may search the same archive multiple |
963 | bfd *element = NULL; |
1046 | times. */ |
964 | |
1047 | pass = abfd->archive_pass + 1; |
- | |
1048 | - | ||
1049 | /* New undefined symbols are added to the end of the list, so we |
965 | loop = FALSE; |
1050 | only need to look through it once. */ |
966 | arsyms = bfd_ardata (abfd)->symdefs; |
1051 | pundef = &info->hash->undefs; |
967 | arsym_end = arsyms + bfd_ardata (abfd)->symdef_count; |
1052 | while (*pundef != NULL) |
- | |
Line 1053... | Line 968... | ||
1053 | { |
968 | for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++) |
1054 | struct bfd_link_hash_entry *h; |
- | |
1055 | struct archive_hash_entry *arh; |
- | |
1056 | struct archive_list *l; |
969 | { |
1057 | 970 | struct bfd_link_hash_entry *h; |
|
1058 | h = *pundef; |
- | |
1059 | 971 | struct bfd_link_hash_entry *undefs_tail; |
|
1060 | /* When a symbol is defined, it is not necessarily removed from |
- | |
1061 | the list. */ |
- | |
1062 | if (h->type != bfd_link_hash_undefined |
- | |
1063 | && h->type != bfd_link_hash_common) |
- | |
1064 | { |
- | |
1065 | /* Remove this entry from the list, for general cleanliness |
- | |
1066 | and because we are going to look through the list again |
972 | |
1067 | if we search any more libraries. We can't remove the |
- | |
1068 | entry if it is the tail, because that would lose any |
- | |
1069 | entries we add to the list later on (it would also cause |
- | |
1070 | us to lose track of whether the symbol has been |
- | |
1071 | referenced). */ |
973 | if (included[indx]) |
1072 | if (*pundef != info->hash->undefs_tail) |
974 | continue; |
Line 1073... | Line -... | ||
1073 | *pundef = (*pundef)->u.undef.next; |
- | |
1074 | else |
975 | if (needed && arsym->file_offset == last_ar_offset) |
1075 | pundef = &(*pundef)->u.undef.next; |
- | |
1076 | continue; |
- | |
1077 | } |
- | |
1078 | - | ||
1079 | /* Look for this symbol in the archive symbol map. */ |
- | |
1080 | arh = archive_hash_lookup (&arsym_hash, h->root.string, FALSE, FALSE); |
- | |
1081 | if (arh == NULL) |
- | |
1082 | { |
- | |
1083 | /* If we haven't found the exact symbol we're looking for, |
976 | { |
1084 | let's look for its import thunk */ |
- | |
Line -... | Line 977... | ||
- | 977 | included[indx] = 1; |
|
- | 978 | continue; |
|
1085 | if (info->pei386_auto_import) |
979 | } |
1086 | { |
980 | |
1087 | bfd_size_type amt = strlen (h->root.string) + 10; |
981 | h = bfd_link_hash_lookup (info->hash, arsym->name, |
1088 | char *buf = (char *) bfd_malloc (amt); |
- | |
1089 | if (buf == NULL) |
982 | FALSE, FALSE, TRUE); |
1090 | return FALSE; |
- | |
1091 | - | ||
1092 | sprintf (buf, "__imp_%s", h->root.string); |
983 | |
1093 | arh = archive_hash_lookup (&arsym_hash, buf, FALSE, FALSE); |
- | |
1094 | free(buf); |
- | |
1095 | } |
- | |
1096 | if (arh == NULL) |
- | |
1097 | { |
- | |
1098 | pundef = &(*pundef)->u.undef.next; |
- | |
1099 | continue; |
- | |
Line 1100... | Line -... | ||
1100 | } |
- | |
1101 | } |
984 | if (h == NULL |
1102 | /* Look at all the objects which define this symbol. */ |
985 | && info->pei386_auto_import |
1103 | for (l = arh->defs; l != NULL; l = l->next) |
986 | && CONST_STRNEQ (arsym->name, "__imp_")) |
1104 | { |
- | |
1105 | bfd *element; |
987 | h = bfd_link_hash_lookup (info->hash, arsym->name + 6, |
1106 | bfd_boolean needed; |
- | |
1107 | - | ||
1108 | /* If the symbol has gotten defined along the way, quit. */ |
- | |
1109 | if (h->type != bfd_link_hash_undefined |
- | |
1110 | && h->type != bfd_link_hash_common) |
988 | FALSE, FALSE, TRUE); |
1111 | break; |
989 | if (h == NULL) |
1112 | - | ||
1113 | element = bfd_get_elt_at_index (abfd, l->indx); |
990 | continue; |
- | 991 | ||
Line 1114... | Line -... | ||
1114 | if (element == NULL) |
- | |
1115 | goto error_return; |
992 | if (h->type != bfd_link_hash_undefined |
1116 | 993 | && h->type != bfd_link_hash_common) |
|
- | 994 | { |
|
- | 995 | if (h->type != bfd_link_hash_undefweak) |
|
1117 | /* If we've already included this element, or if we've |
996 | /* Symbol must be defined. Don't check it again. */ |
- | 997 | included[indx] = 1; |
|
1118 | already checked it on this pass, continue. */ |
998 | continue; |
1119 | if (element->archive_pass == -1 |
999 | } |
Line -... | Line 1000... | ||
- | 1000 | ||
- | 1001 | if (last_ar_offset != arsym->file_offset) |
|
1120 | || element->archive_pass == pass) |
1002 | { |
1121 | continue; |
1003 | last_ar_offset = arsym->file_offset; |
1122 | 1004 | element = _bfd_get_elt_at_filepos (abfd, last_ar_offset); |
|
1123 | /* If we can't figure this element out, just ignore it. */ |
1005 | if (element == NULL |
Line 1124... | Line 1006... | ||
1124 | if (! bfd_check_format (element, bfd_object)) |
1006 | || !bfd_check_format (element, bfd_object)) |
1125 | { |
- | |
1126 | element->archive_pass = -1; |
- | |
1127 | continue; |
1007 | goto error_return; |
1128 | } |
1008 | } |
Line 1129... | Line 1009... | ||
1129 | 1009 | ||
1130 | /* CHECKFN will see if this element should be included, and |
1010 | undefs_tail = info->hash->undefs_tail; |
1131 | go ahead and include it if appropriate. */ |
1011 | |
1132 | if (! (*checkfn) (element, info, &needed)) |
1012 | /* CHECKFN will see if this element should be included, and |
- | 1013 | go ahead and include it if appropriate. */ |
|
- | 1014 | if (! (*checkfn) (element, info, h, arsym->name, &needed)) |
|
- | 1015 | goto error_return; |
|
- | 1016 | ||
- | 1017 | if (needed) |
|
1133 | goto error_return; |
1018 | { |
- | 1019 | unsigned int mark; |
|
Line 1134... | Line 1020... | ||
1134 | 1020 | ||
- | 1021 | /* Look backward to mark all symbols from this object file |
|
1135 | if (! needed) |
1022 | which we have already seen in this pass. */ |
- | 1023 | mark = indx; |
|
- | 1024 | do |
|
Line 1136... | Line -... | ||
1136 | element->archive_pass = pass; |
- | |
1137 | else |
- | |
1138 | { |
- | |
1139 | element->archive_pass = -1; |
1025 | { |
1140 | - | ||
1141 | /* Increment the pass count to show that we may need to |
1026 | included[mark] = 1; |
Line 1142... | Line 1027... | ||
1142 | recheck object files which were already checked. */ |
1027 | if (mark == 0) |
1143 | ++pass; |
1028 | break; |
1144 | } |
1029 | --mark; |
1145 | } |
1030 | } |
1146 | 1031 | while (arsyms[mark].file_offset == last_ar_offset); |
|
1147 | pundef = &(*pundef)->u.undef.next; |
1032 | |
1148 | } |
1033 | if (undefs_tail != info->hash->undefs_tail) |
1149 | 1034 | loop = TRUE; |
|
1150 | archive_hash_table_free (&arsym_hash); |
1035 | } |
Line 1151... | Line 1036... | ||
1151 | 1036 | } |
|
1152 | /* Save PASS in case we are called again. */ |
1037 | } while (loop); |
1153 | abfd->archive_pass = pass; |
- | |
1154 | 1038 | ||
- | 1039 | free (included); |
|
- | 1040 | return TRUE; |
|
1155 | return TRUE; |
1041 | |
1156 | 1042 | error_return: |
|
1157 | error_return: |
1043 | free (included); |
- | 1044 | return FALSE; |
|
1158 | archive_hash_table_free (&arsym_hash); |
1045 | } |
Line 1159... | Line 1046... | ||
1159 | return FALSE; |
1046 | |
1160 | } |
1047 | /* See if we should include an archive element. This version is used |
1161 | 1048 | when we do not want to automatically collect constructors based on |
|
Line 1162... | Line 1049... | ||
1162 | /* See if we should include an archive element. This version is used |
1049 | the symbol name, presumably because we have some other mechanism |
1163 | when we do not want to automatically collect constructors based on |
1050 | for finding them. */ |
1164 | the symbol name, presumably because we have some other mechanism |
1051 | |
- | 1052 | static bfd_boolean |
|
- | 1053 | generic_link_check_archive_element_no_collect (bfd *abfd, |
|
1165 | for finding them. */ |
1054 | struct bfd_link_info *info, |
1166 | 1055 | struct bfd_link_hash_entry *h, |
|
1167 | static bfd_boolean |
1056 | const char *name, |
- | 1057 | bfd_boolean *pneeded) |
|
1168 | generic_link_check_archive_element_no_collect ( |
1058 | { |
Line 1169... | Line 1059... | ||
1169 | bfd *abfd, |
1059 | return generic_link_check_archive_element (abfd, info, h, name, pneeded, |
1170 | struct bfd_link_info *info, |
1060 | FALSE); |
Line 1171... | Line 1061... | ||
1171 | bfd_boolean *pneeded) |
1061 | } |
1172 | { |
1062 | |
1173 | return generic_link_check_archive_element (abfd, info, pneeded, FALSE); |
1063 | /* See if we should include an archive element. This version is used |
- | 1064 | when we want to automatically collect constructors based on the |
|
- | 1065 | symbol name, as collect2 does. */ |
|
1174 | } |
1066 | |
1175 | 1067 | static bfd_boolean |
|
1176 | /* See if we should include an archive element. This version is used |
1068 | generic_link_check_archive_element_collect (bfd *abfd, |
1177 | when we want to automatically collect constructors based on the |
1069 | struct bfd_link_info *info, |
Line 1204... | Line 1096... | ||
1204 | pp = _bfd_generic_link_get_symbols (abfd); |
1096 | pp = _bfd_generic_link_get_symbols (abfd); |
1205 | ppend = pp + _bfd_generic_link_get_symcount (abfd); |
1097 | ppend = pp + _bfd_generic_link_get_symcount (abfd); |
1206 | for (; pp < ppend; pp++) |
1098 | for (; pp < ppend; pp++) |
1207 | { |
1099 | { |
1208 | asymbol *p; |
1100 | asymbol *p; |
1209 | struct bfd_link_hash_entry *h; |
- | |
Line 1210... | Line 1101... | ||
1210 | 1101 | ||
Line 1211... | Line 1102... | ||
1211 | p = *pp; |
1102 | p = *pp; |
1212 | 1103 | ||
Line 1227... | Line 1118... | ||
1227 | && h->type != bfd_link_hash_common)) |
1118 | && h->type != bfd_link_hash_common)) |
1228 | continue; |
1119 | continue; |
Line 1229... | Line 1120... | ||
1229 | 1120 | ||
Line 1230... | Line 1121... | ||
1230 | /* P is a symbol we are looking for. */ |
1121 | /* P is a symbol we are looking for. */ |
- | 1122 | ||
- | 1123 | if (! bfd_is_com_section (p->section) |
|
1231 | 1124 | || (h->type == bfd_link_hash_undefined |
|
1232 | if (! bfd_is_com_section (p->section)) |
1125 | && h->u.undef.abfd == NULL)) |
1233 | { |
- | |
1234 | bfd_size_type symcount; |
1126 | { |
1235 | asymbol **symbols; |
- | |
1236 | bfd *oldbfd = abfd; |
1127 | /* P is not a common symbol, or an undefined reference was |
- | 1128 | created from outside BFD such as from a linker -u option. |
|
1237 | 1129 | This object file defines the symbol, so pull it in. */ |
|
1238 | /* This object file defines this symbol, so pull it in. */ |
1130 | *pneeded = TRUE; |
1239 | if (!(*info->callbacks |
1131 | if (!(*info->callbacks |
1240 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
1132 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
1241 | &abfd)) |
1133 | &abfd)) |
1242 | return FALSE; |
1134 | return FALSE; |
1243 | /* Potentially, the add_archive_element hook may have set a |
- | |
1244 | substitute BFD for us. */ |
- | |
1245 | if (abfd != oldbfd |
- | |
1246 | && !bfd_generic_link_read_symbols (abfd)) |
- | |
1247 | return FALSE; |
- | |
1248 | symcount = _bfd_generic_link_get_symcount (abfd); |
1135 | /* Potentially, the add_archive_element hook may have set a |
1249 | symbols = _bfd_generic_link_get_symbols (abfd); |
- | |
1250 | if (! generic_link_add_symbol_list (abfd, info, symcount, |
- | |
1251 | symbols, collect)) |
- | |
1252 | return FALSE; |
- | |
1253 | *pneeded = TRUE; |
1136 | substitute BFD for us. */ |
Line 1254... | Line 1137... | ||
1254 | return TRUE; |
1137 | return generic_link_add_object_symbols (abfd, info, collect); |
Line 1255... | Line 1138... | ||
1255 | } |
1138 | } |
1256 | 1139 | ||
1257 | /* P is a common symbol. */ |
1140 | /* P is a common symbol. */ |
1258 | 1141 | ||
1259 | if (h->type == bfd_link_hash_undefined) |
1142 | if (h->type == bfd_link_hash_undefined) |
Line 1260... | Line -... | ||
1260 | { |
- | |
1261 | bfd *symbfd; |
- | |
1262 | bfd_vma size; |
- | |
1263 | unsigned int power; |
- | |
1264 | - | ||
1265 | symbfd = h->u.undef.abfd; |
- | |
1266 | if (symbfd == NULL) |
- | |
1267 | { |
- | |
1268 | /* This symbol was created as undefined from outside |
- | |
1269 | BFD. We assume that we should link in the object |
- | |
1270 | file. This is for the -u option in the linker. */ |
- | |
1271 | if (!(*info->callbacks |
- | |
1272 | ->add_archive_element) (info, abfd, bfd_asymbol_name (p), |
- | |
1273 | &abfd)) |
- | |
1274 | return FALSE; |
- | |
1275 | /* Potentially, the add_archive_element hook may have set a |
- | |
1276 | substitute BFD for us. But no symbols are going to get |
- | |
1277 | registered by anything we're returning to from here. */ |
1143 | { |
1278 | *pneeded = TRUE; |
1144 | bfd *symbfd; |
1279 | return TRUE; |
1145 | bfd_vma size; |
1280 | } |
1146 | unsigned int power; |
1281 | 1147 | ||
1282 | /* Turn the symbol into a common symbol but do not link in |
1148 | /* Turn the symbol into a common symbol but do not link in |
1283 | the object file. This is how a.out works. Object |
1149 | the object file. This is how a.out works. Object |
- | 1150 | formats that require different semantics must implement |
|
1284 | formats that require different semantics must implement |
1151 | this function differently. This symbol is already on the |
1285 | this function differently. This symbol is already on the |
1152 | undefs list. We add the section to a common section |
1286 | undefs list. We add the section to a common section |
1153 | attached to symbfd to ensure that it is in a BFD which |
1287 | attached to symbfd to ensure that it is in a BFD which |
1154 | will be linked in. */ |
1288 | will be linked in. */ |
1155 | symbfd = h->u.undef.abfd; |
Line 1473... | Line 1340... | ||
1473 | MIND, /* Multiple indirect symbols. */ |
1340 | MIND, /* Multiple indirect symbols. */ |
1474 | IND, /* Make indirect symbol. */ |
1341 | IND, /* Make indirect symbol. */ |
1475 | CIND, /* Make indirect symbol from existing common symbol. */ |
1342 | CIND, /* Make indirect symbol from existing common symbol. */ |
1476 | SET, /* Add value to set. */ |
1343 | SET, /* Add value to set. */ |
1477 | MWARN, /* Make warning symbol. */ |
1344 | MWARN, /* Make warning symbol. */ |
1478 | WARN, /* Issue warning. */ |
- | |
1479 | CWARN, /* Warn if referenced, else MWARN. */ |
1345 | WARN, /* Warn if referenced, else MWARN. */ |
1480 | CYCLE, /* Repeat with symbol pointed to. */ |
1346 | CYCLE, /* Repeat with symbol pointed to. */ |
1481 | REFC, /* Mark indirect symbol referenced and then CYCLE. */ |
1347 | REFC, /* Mark indirect symbol referenced and then CYCLE. */ |
1482 | WARNC /* Issue warning and then CYCLE. */ |
1348 | WARNC /* Issue warning and then CYCLE. */ |
1483 | }; |
1349 | }; |
Line 1492... | Line 1358... | ||
1492 | /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, |
1358 | /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC }, |
1493 | /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE }, |
1359 | /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE }, |
1494 | /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE }, |
1360 | /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE }, |
1495 | /* COMMON_ROW */ {COM, COM, COM, CREF, COM, BIG, REFC, WARNC }, |
1361 | /* COMMON_ROW */ {COM, COM, COM, CREF, COM, BIG, REFC, WARNC }, |
1496 | /* INDR_ROW */ {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE }, |
1362 | /* INDR_ROW */ {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE }, |
1497 | /* WARN_ROW */ {MWARN, WARN, WARN, CWARN, CWARN, WARN, CWARN, NOACT }, |
1363 | /* WARN_ROW */ {MWARN, WARN, WARN, WARN, WARN, WARN, WARN, NOACT }, |
1498 | /* SET_ROW */ {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE } |
1364 | /* SET_ROW */ {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE } |
1499 | }; |
1365 | }; |
Line 1500... | Line 1366... | ||
1500 | 1366 | ||
1501 | /* Most of the entries in the LINK_ACTION table are straightforward, |
1367 | /* Most of the entries in the LINK_ACTION table are straightforward, |
Line 1574... | Line 1440... | ||
1574 | bfd_boolean collect, |
1440 | bfd_boolean collect, |
1575 | struct bfd_link_hash_entry **hashp) |
1441 | struct bfd_link_hash_entry **hashp) |
1576 | { |
1442 | { |
1577 | enum link_row row; |
1443 | enum link_row row; |
1578 | struct bfd_link_hash_entry *h; |
1444 | struct bfd_link_hash_entry *h; |
- | 1445 | struct bfd_link_hash_entry *inh = NULL; |
|
1579 | bfd_boolean cycle; |
1446 | bfd_boolean cycle; |
Line 1580... | Line 1447... | ||
1580 | 1447 | ||
Line 1581... | Line 1448... | ||
1581 | BFD_ASSERT (section != NULL); |
1448 | BFD_ASSERT (section != NULL); |
1582 | 1449 | ||
- | 1450 | if (bfd_is_ind_section (section) |
|
1583 | if (bfd_is_ind_section (section) |
1451 | || (flags & BSF_INDIRECT) != 0) |
- | 1452 | { |
|
- | 1453 | row = INDR_ROW; |
|
- | 1454 | /* Create the indirect symbol here. This is for the benefit of |
|
- | 1455 | the plugin "notice" function. |
|
- | 1456 | STRING is the name of the symbol we want to indirect to. */ |
|
- | 1457 | inh = bfd_wrapped_link_hash_lookup (abfd, info, string, TRUE, |
|
- | 1458 | copy, FALSE); |
|
- | 1459 | if (inh == NULL) |
|
1584 | || (flags & BSF_INDIRECT) != 0) |
1460 | return FALSE; |
1585 | row = INDR_ROW; |
1461 | } |
1586 | else if ((flags & BSF_WARNING) != 0) |
1462 | else if ((flags & BSF_WARNING) != 0) |
1587 | row = WARN_ROW; |
1463 | row = WARN_ROW; |
1588 | else if ((flags & BSF_CONSTRUCTOR) != 0) |
1464 | else if ((flags & BSF_CONSTRUCTOR) != 0) |
Line 1595... | Line 1471... | ||
1595 | row = UNDEF_ROW; |
1471 | row = UNDEF_ROW; |
1596 | } |
1472 | } |
1597 | else if ((flags & BSF_WEAK) != 0) |
1473 | else if ((flags & BSF_WEAK) != 0) |
1598 | row = DEFW_ROW; |
1474 | row = DEFW_ROW; |
1599 | else if (bfd_is_com_section (section)) |
1475 | else if (bfd_is_com_section (section)) |
- | 1476 | { |
|
1600 | row = COMMON_ROW; |
1477 | row = COMMON_ROW; |
- | 1478 | if (strcmp (name, "__gnu_lto_slim") == 0) |
|
- | 1479 | (*_bfd_error_handler) |
|
- | 1480 | (_("%s: plugin needed to handle lto object"), |
|
- | 1481 | bfd_get_filename (abfd)); |
|
- | 1482 | } |
|
1601 | else |
1483 | else |
1602 | row = DEF_ROW; |
1484 | row = DEF_ROW; |
Line 1603... | Line 1485... | ||
1603 | 1485 | ||
1604 | if (hashp != NULL && *hashp != NULL) |
1486 | if (hashp != NULL && *hashp != NULL) |
Line 1619... | Line 1501... | ||
1619 | 1501 | ||
1620 | if (info->notice_all |
1502 | if (info->notice_all |
1621 | || (info->notice_hash != NULL |
1503 | || (info->notice_hash != NULL |
1622 | && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)) |
1504 | && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL)) |
1623 | { |
1505 | { |
1624 | if (! (*info->callbacks->notice) (info, h, |
1506 | if (! (*info->callbacks->notice) (info, h, inh, |
1625 | abfd, section, value, flags, string)) |
1507 | abfd, section, value, flags)) |
1626 | return FALSE; |
1508 | return FALSE; |
Line 1627... | Line 1509... | ||
1627 | } |
1509 | } |
1628 | 1510 | ||
Line 1676... | Line 1558... | ||
1676 | h->type = bfd_link_hash_defweak; |
1558 | h->type = bfd_link_hash_defweak; |
1677 | else |
1559 | else |
1678 | h->type = bfd_link_hash_defined; |
1560 | h->type = bfd_link_hash_defined; |
1679 | h->u.def.section = section; |
1561 | h->u.def.section = section; |
1680 | h->u.def.value = value; |
1562 | h->u.def.value = value; |
- | 1563 | h->linker_def = 0; |
|
Line 1681... | Line 1564... | ||
1681 | 1564 | ||
1682 | /* If we have been asked to, we act like collect2 and |
1565 | /* If we have been asked to, we act like collect2 and |
1683 | identify all functions that might be global |
1566 | identify all functions that might be global |
1684 | constructors and destructors and pass them up in a |
1567 | constructors and destructors and pass them up in a |
Line 1775... | Line 1658... | ||
1775 | section->name); |
1658 | section->name); |
1776 | h->u.c.p->section->flags |= SEC_ALLOC; |
1659 | h->u.c.p->section->flags |= SEC_ALLOC; |
1777 | } |
1660 | } |
1778 | else |
1661 | else |
1779 | h->u.c.p->section = section; |
1662 | h->u.c.p->section = section; |
- | 1663 | h->linker_def = 0; |
|
1780 | break; |
1664 | break; |
Line 1781... | Line 1665... | ||
1781 | 1665 | ||
1782 | case REF: |
1666 | case REF: |
1783 | /* A reference to a defined symbol. */ |
1667 | /* A reference to a defined symbol. */ |
Line 1854... | Line 1738... | ||
1854 | if (! ((*info->callbacks->multiple_common) |
1738 | if (! ((*info->callbacks->multiple_common) |
1855 | (info, h, abfd, bfd_link_hash_indirect, 0))) |
1739 | (info, h, abfd, bfd_link_hash_indirect, 0))) |
1856 | return FALSE; |
1740 | return FALSE; |
1857 | /* Fall through. */ |
1741 | /* Fall through. */ |
1858 | case IND: |
1742 | case IND: |
1859 | /* Create an indirect symbol. */ |
- | |
1860 | { |
- | |
1861 | struct bfd_link_hash_entry *inh; |
- | |
1862 | - | ||
1863 | /* STRING is the name of the symbol we want to indirect |
- | |
1864 | to. */ |
- | |
1865 | inh = bfd_wrapped_link_hash_lookup (abfd, info, string, TRUE, |
- | |
1866 | copy, FALSE); |
- | |
1867 | if (inh == NULL) |
- | |
1868 | return FALSE; |
- | |
1869 | if (inh->type == bfd_link_hash_indirect |
1743 | if (inh->type == bfd_link_hash_indirect |
1870 | && inh->u.i.link == h) |
1744 | && inh->u.i.link == h) |
1871 | { |
1745 | { |
1872 | (*_bfd_error_handler) |
1746 | (*_bfd_error_handler) |
1873 | (_("%B: indirect symbol `%s' to `%s' is a loop"), |
1747 | (_("%B: indirect symbol `%s' to `%s' is a loop"), |
Line 1881... | Line 1755... | ||
1881 | inh->u.undef.abfd = abfd; |
1755 | inh->u.undef.abfd = abfd; |
1882 | bfd_link_add_undef (info->hash, inh); |
1756 | bfd_link_add_undef (info->hash, inh); |
1883 | } |
1757 | } |
Line 1884... | Line 1758... | ||
1884 | 1758 | ||
1885 | /* If the indirect symbol has been referenced, we need to |
1759 | /* If the indirect symbol has been referenced, we need to |
1886 | push the reference down to the symbol we are |
- | |
1887 | referencing. */ |
1760 | push the reference down to the symbol we are referencing. */ |
1888 | if (h->type != bfd_link_hash_new) |
1761 | if (h->type != bfd_link_hash_new) |
- | 1762 | { |
|
- | 1763 | /* ??? If inh->type == bfd_link_hash_undefweak this |
|
1889 | { |
1764 | converts inh to bfd_link_hash_undefined. */ |
1890 | row = UNDEF_ROW; |
1765 | row = UNDEF_ROW; |
1891 | cycle = TRUE; |
1766 | cycle = TRUE; |
Line 1892... | Line 1767... | ||
1892 | } |
1767 | } |
1893 | 1768 | ||
- | 1769 | h->type = bfd_link_hash_indirect; |
|
- | 1770 | h->u.i.link = inh; |
|
- | 1771 | /* Not setting h = h->u.i.link here means that when cycle is |
|
- | 1772 | set above we'll always go to REFC, and then cycle again |
|
- | 1773 | to the indirected symbol. This means that any successful |
|
1894 | h->type = bfd_link_hash_indirect; |
1774 | change of an existing symbol to indirect counts as a |
1895 | h->u.i.link = inh; |
1775 | reference. ??? That may not be correct when the existing |
Line 1896... | Line 1776... | ||
1896 | } |
1776 | symbol was defweak. */ |
1897 | break; |
1777 | break; |
1898 | 1778 | ||
1899 | case SET: |
1779 | case SET: |
1900 | /* Add an entry to a set. */ |
1780 | /* Add an entry to a set. */ |
1901 | if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR, |
1781 | if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR, |
Line 1902... | Line 1782... | ||
1902 | abfd, section, value)) |
1782 | abfd, section, value)) |
1903 | return FALSE; |
1783 | return FALSE; |
- | 1784 | break; |
|
1904 | break; |
1785 | |
- | 1786 | case WARNC: |
|
1905 | 1787 | /* Issue a warning and cycle, except when the reference is |
|
1906 | case WARNC: |
1788 | in LTO IR. */ |
1907 | /* Issue a warning and cycle. */ |
1789 | if (h->u.i.warning != NULL |
1908 | if (h->u.i.warning != NULL) |
1790 | && (abfd->flags & BFD_PLUGIN) == 0) |
1909 | { |
1791 | { |
Line 1928... | Line 1810... | ||
1928 | h = h->u.i.link; |
1810 | h = h->u.i.link; |
1929 | cycle = TRUE; |
1811 | cycle = TRUE; |
1930 | break; |
1812 | break; |
Line 1931... | Line 1813... | ||
1931 | 1813 | ||
1932 | case WARN: |
- | |
1933 | /* Issue a warning. */ |
- | |
1934 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
- | |
1935 | hash_entry_bfd (h), NULL, 0)) |
- | |
1936 | return FALSE; |
- | |
1937 | break; |
- | |
1938 | - | ||
1939 | case CWARN: |
1814 | case WARN: |
1940 | /* Warn if this symbol has been referenced already, |
1815 | /* Warn if this symbol has been referenced already from non-IR, |
1941 | otherwise add a warning. A symbol has been referenced if |
1816 | otherwise add a warning. */ |
1942 | the u.undef.next field is not NULL, or it is the tail of the |
1817 | if ((!info->lto_plugin_active |
1943 | undefined symbol list. The REF case above helps to |
1818 | && (h->u.undef.next != NULL || info->hash->undefs_tail == h)) |
1944 | ensure this. */ |
- | |
1945 | if (h->u.undef.next != NULL || info->hash->undefs_tail == h) |
1819 | || h->non_ir_ref) |
1946 | { |
1820 | { |
1947 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
1821 | if (! (*info->callbacks->warning) (info, string, h->root.string, |
1948 | hash_entry_bfd (h), NULL, 0)) |
1822 | hash_entry_bfd (h), NULL, 0)) |
1949 | return FALSE; |
1823 | return FALSE; |
Line 2012... | Line 1886... | ||
2012 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
1886 | for (p = o->map_head.link_order; p != NULL; p = p->next) |
2013 | if (p->type == bfd_indirect_link_order) |
1887 | if (p->type == bfd_indirect_link_order) |
2014 | p->u.indirect.section->linker_mark = TRUE; |
1888 | p->u.indirect.section->linker_mark = TRUE; |
Line 2015... | Line 1889... | ||
2015 | 1889 | ||
2016 | /* Build the output symbol table. */ |
1890 | /* Build the output symbol table. */ |
2017 | for (sub = info->input_bfds; sub != NULL; sub = sub->link_next) |
1891 | for (sub = info->input_bfds; sub != NULL; sub = sub->link.next) |
2018 | if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc)) |
1892 | if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc)) |
Line 2019... | Line 1893... | ||
2019 | return FALSE; |
1893 | return FALSE; |
2020 | 1894 | ||
Line 2030... | Line 1904... | ||
2030 | shouldn't really need one, since we have SYMCOUNT, but some old |
1904 | shouldn't really need one, since we have SYMCOUNT, but some old |
2031 | code still expects one. */ |
1905 | code still expects one. */ |
2032 | if (! generic_add_output_symbol (abfd, &outsymalloc, NULL)) |
1906 | if (! generic_add_output_symbol (abfd, &outsymalloc, NULL)) |
2033 | return FALSE; |
1907 | return FALSE; |
Line 2034... | Line 1908... | ||
2034 | 1908 | ||
2035 | if (info->relocatable) |
1909 | if (bfd_link_relocatable (info)) |
2036 | { |
1910 | { |
2037 | /* Allocate space for the output relocs for each section. */ |
1911 | /* Allocate space for the output relocs for each section. */ |
2038 | for (o = abfd->sections; o != NULL; o = o->next) |
1912 | for (o = abfd->sections; o != NULL; o = o->next) |
2039 | { |
1913 | { |
Line 2260... | Line 2134... | ||
2260 | case bfd_link_hash_indirect: |
2134 | case bfd_link_hash_indirect: |
2261 | h = (struct generic_link_hash_entry *) h->root.u.i.link; |
2135 | h = (struct generic_link_hash_entry *) h->root.u.i.link; |
2262 | /* fall through */ |
2136 | /* fall through */ |
2263 | case bfd_link_hash_defined: |
2137 | case bfd_link_hash_defined: |
2264 | sym->flags |= BSF_GLOBAL; |
2138 | sym->flags |= BSF_GLOBAL; |
2265 | sym->flags &=~ BSF_CONSTRUCTOR; |
2139 | sym->flags &=~ (BSF_WEAK | BSF_CONSTRUCTOR); |
2266 | sym->value = h->root.u.def.value; |
2140 | sym->value = h->root.u.def.value; |
2267 | sym->section = h->root.u.def.section; |
2141 | sym->section = h->root.u.def.section; |
2268 | break; |
2142 | break; |
2269 | case bfd_link_hash_defweak: |
2143 | case bfd_link_hash_defweak: |
2270 | sym->flags |= BSF_WEAK; |
2144 | sym->flags |= BSF_WEAK; |
Line 2334... | Line 2208... | ||
2334 | case discard_all: |
2208 | case discard_all: |
2335 | output = FALSE; |
2209 | output = FALSE; |
2336 | break; |
2210 | break; |
2337 | case discard_sec_merge: |
2211 | case discard_sec_merge: |
2338 | output = TRUE; |
2212 | output = TRUE; |
2339 | if (info->relocatable |
2213 | if (bfd_link_relocatable (info) |
2340 | || ! (sym->section->flags & SEC_MERGE)) |
2214 | || ! (sym->section->flags & SEC_MERGE)) |
2341 | break; |
2215 | break; |
2342 | /* FALLTHROUGH */ |
2216 | /* FALLTHROUGH */ |
2343 | case discard_l: |
2217 | case discard_l: |
2344 | if (bfd_is_local_label (input_bfd, sym)) |
2218 | if (bfd_is_local_label (input_bfd, sym)) |
Line 2504... | Line 2378... | ||
2504 | asection *sec, |
2378 | asection *sec, |
2505 | struct bfd_link_order *link_order) |
2379 | struct bfd_link_order *link_order) |
2506 | { |
2380 | { |
2507 | arelent *r; |
2381 | arelent *r; |
Line 2508... | Line 2382... | ||
2508 | 2382 | ||
2509 | if (! info->relocatable) |
2383 | if (! bfd_link_relocatable (info)) |
2510 | abort (); |
2384 | abort (); |
2511 | if (sec->orelocation == NULL) |
2385 | if (sec->orelocation == NULL) |
Line 2512... | Line 2386... | ||
2512 | abort (); |
2386 | abort (); |
Line 2558... | Line 2432... | ||
2558 | bfd_boolean ok; |
2432 | bfd_boolean ok; |
2559 | file_ptr loc; |
2433 | file_ptr loc; |
Line 2560... | Line 2434... | ||
2560 | 2434 | ||
2561 | size = bfd_get_reloc_size (r->howto); |
2435 | size = bfd_get_reloc_size (r->howto); |
2562 | buf = (bfd_byte *) bfd_zmalloc (size); |
2436 | buf = (bfd_byte *) bfd_zmalloc (size); |
2563 | if (buf == NULL) |
2437 | if (buf == NULL && size != 0) |
2564 | return FALSE; |
2438 | return FALSE; |
2565 | rstat = _bfd_relocate_contents (r->howto, abfd, |
2439 | rstat = _bfd_relocate_contents (r->howto, abfd, |
2566 | (bfd_vma) link_order->u.reloc.p->addend, |
2440 | (bfd_vma) link_order->u.reloc.p->addend, |
2567 | buf); |
2441 | buf); |
Line 2735... | Line 2609... | ||
2735 | 2609 | ||
2736 | BFD_ASSERT (input_section->output_section == output_section); |
2610 | BFD_ASSERT (input_section->output_section == output_section); |
2737 | BFD_ASSERT (input_section->output_offset == link_order->offset); |
2611 | BFD_ASSERT (input_section->output_offset == link_order->offset); |
Line 2738... | Line 2612... | ||
2738 | BFD_ASSERT (input_section->size == link_order->size); |
2612 | BFD_ASSERT (input_section->size == link_order->size); |
2739 | 2613 | ||
2740 | if (info->relocatable |
2614 | if (bfd_link_relocatable (info) |
2741 | && input_section->reloc_count > 0 |
2615 | && input_section->reloc_count > 0 |
2742 | && output_section->orelocation == NULL) |
2616 | && output_section->orelocation == NULL) |
2743 | { |
2617 | { |
Line 2829... | Line 2703... | ||
2829 | contents = (bfd_byte *) bfd_malloc (sec_size); |
2703 | contents = (bfd_byte *) bfd_malloc (sec_size); |
2830 | if (contents == NULL && sec_size != 0) |
2704 | if (contents == NULL && sec_size != 0) |
2831 | goto error_return; |
2705 | goto error_return; |
2832 | new_contents = (bfd_get_relocated_section_contents |
2706 | new_contents = (bfd_get_relocated_section_contents |
2833 | (output_bfd, info, link_order, contents, |
2707 | (output_bfd, info, link_order, contents, |
2834 | info->relocatable, |
2708 | bfd_link_relocatable (info), |
2835 | _bfd_generic_link_get_symbols (input_bfd))); |
2709 | _bfd_generic_link_get_symbols (input_bfd))); |
2836 | if (!new_contents) |
2710 | if (!new_contents) |
2837 | goto error_return; |
2711 | goto error_return; |
2838 | } |
2712 | } |
Line 3020... | Line 2894... | ||
3020 | the first pass, replace it with the LTO output on the |
2894 | the first pass, replace it with the LTO output on the |
3021 | second pass. We can't simply choose real object |
2895 | second pass. We can't simply choose real object |
3022 | files over IR because the first pass may contain a |
2896 | files over IR because the first pass may contain a |
3023 | mix of LTO and normal objects and we must keep the |
2897 | mix of LTO and normal objects and we must keep the |
3024 | first match, be it IR or real. */ |
2898 | first match, be it IR or real. */ |
3025 | if (info->loading_lto_outputs |
2899 | if (sec->owner->lto_output |
3026 | && (l->sec->owner->flags & BFD_PLUGIN) != 0) |
2900 | && (l->sec->owner->flags & BFD_PLUGIN) != 0) |
3027 | { |
2901 | { |
3028 | l->sec = sec; |
2902 | l->sec = sec; |
3029 | return FALSE; |
2903 | return FALSE; |
3030 | } |
2904 | } |