1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 Written by Steve Chamberlain steve@cygnus.com
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
41 /* Somewhere above, sys/stat.h got included . . . . */
42 #if !defined(S_ISDIR) && defined(S_IFDIR)
43 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
48 static char *get_emulation
PARAMS ((int, char **));
49 static void set_scripts_dir
PARAMS ((void));
54 const char *output_filename
= "a.out";
56 /* Name this program was invoked by. */
59 /* The file that we're creating */
62 /* set if -y on the command line */
65 /* The local symbol prefix */
68 /* Set by -G argument, for MIPS ECOFF target. */
69 int g_switch_value
= 8;
71 /* Count the number of global symbols multiply defined. */
72 int multiple_def_count
;
74 /* Count the number of symbols defined through common declarations.
75 This count is referenced in symdef_library, linear_library, and
76 modified by enter_global_ref.
78 It is incremented when a symbol is created as a common, and
79 decremented when the common declaration is overridden
81 Another way of thinking of it is that this is a count of
82 all ldsym_types with a ->scoms field */
84 unsigned int commons_pending
;
86 /* Count the number of global symbols referenced and not defined.
87 common symbols are not included in this count. */
89 unsigned int undefined_global_sym_count
;
91 /* Nonzero means print names of input files as processed. */
94 /* Nonzero means same, but note open failures, too. */
95 boolean trace_file_tries
;
97 /* 1 => write load map. */
101 /* Indicates whether output file will be b.out (default) or coff */
102 enum target_flavour output_flavor
= BFD_BOUT_FORMAT
;
105 /* A count of the total number of local symbols ever seen - by adding
106 the symbol_count field of each newly read afile.*/
108 unsigned int total_symbols_seen
;
110 /* A count of the number of read files - the same as the number of elements
113 unsigned int total_files_seen
;
115 args_type command_line
;
117 ld_config_type config
;
126 program_name
= argv
[0];
130 /* Initialize the data about options. */
133 trace_files
= trace_file_tries
= false;
135 config
.relocateable_output
= false;
136 command_line
.force_common_definition
= false;
138 init_bfd_error_vector ();
140 ldfile_add_arch ("");
142 config
.make_executable
= true;
143 force_make_executable
= false;
145 /* Initialize the cumulative counts of symbols. */
146 undefined_global_sym_count
= 0;
147 multiple_def_count
= 0;
150 config
.magic_demand_paged
= true;
151 config
.text_read_only
= true;
152 config
.make_executable
= true;
154 emulation
= get_emulation (argc
, argv
);
155 ldemul_choose_mode (emulation
);
156 default_target
= ldemul_choose_target ();
158 ldemul_before_parse ();
159 lang_has_input_file
= false;
160 parse_args (argc
, argv
);
162 /* This essentially adds another -L directory so this must be done after
163 the -L's in argv have been processed. */
166 if (had_script
== false)
168 /* Read the emulation's appropriate default script. */
170 char *s
= ldemul_get_script (&isfile
);
174 /* sizeof counts the terminating NUL. */
175 size_t size
= strlen (s
) + sizeof ("-T ");
176 char *buf
= (char *) ldmalloc(size
);
177 sprintf (buf
, "-T %s", s
);
185 if (config
.relocateable_output
&& command_line
.relax
)
187 einfo ("%P%F: -relax and -r may not be used together\n");
191 if (lang_has_input_file
== false)
193 einfo ("%P%F: no input files\n");
198 info_msg ("%P: mode %s\n", emulation
);
201 ldemul_after_parse ();
204 if (config
.map_filename
)
206 if (strcmp (config
.map_filename
, "-") == 0)
208 config
.map_file
= stdout
;
212 config
.map_file
= fopen (config
.map_filename
, FOPEN_WT
);
213 if (config
.map_file
== (FILE *) NULL
)
215 einfo ("%P%F: cannot open map file %s: %E\n",
216 config
.map_filename
);
224 /* Print error messages for any missing symbols, for any warning
225 symbols, and possibly multiple definitions */
228 if (config
.text_read_only
)
230 /* Look for a text section and mark the readonly attribute in it */
231 asection
*found
= bfd_get_section_by_name (output_bfd
, ".text");
233 if (found
!= (asection
*) NULL
)
235 found
->flags
|= SEC_READONLY
;
239 if (config
.relocateable_output
)
240 output_bfd
->flags
&= ~EXEC_P
;
242 output_bfd
->flags
|= EXEC_P
;
246 /* Even if we're producing relocateable output, some non-fatal errors should
247 be reported in the exit status. (What non-fatal errors, if any, do we
248 want to ignore for relocateable output?) */
250 if (config
.make_executable
== false && force_make_executable
== false)
252 if (trace_files
== true)
254 einfo ("%P: link errors found, deleting executable `%s'\n",
258 if (output_bfd
->iostream
)
259 fclose ((FILE *) (output_bfd
->iostream
));
261 unlink (output_filename
);
266 bfd_close (output_bfd
);
272 /* We need to find any explicitly given emulation in order to initialize the
273 state that's needed by the lex&yacc argument parser (parse_args). */
276 get_emulation (argc
, argv
)
284 check_v960 (argc
, argv
);
285 emulation
= "gld960";
286 for (i
= 1; i
< argc
; i
++)
288 if (!strcmp (argv
[i
], "-Fcoff"))
290 emulation
= "lnk960";
291 output_flavor
= BFD_COFF_FORMAT
;
296 emulation
= (char *) getenv (EMULATION_ENVIRON
);
297 if (emulation
== NULL
)
298 emulation
= DEFAULT_EMULATION
;
301 for (i
= 1; i
< argc
; i
++)
303 if (!strncmp (argv
[i
], "-m", 2))
305 if (argv
[i
][2] == '\0')
310 emulation
= argv
[i
+ 1];
315 einfo("%P%F: missing argument to -m\n");
318 else if (strcmp (argv
[i
], "-mips1") == 0
319 || strcmp (argv
[i
], "-mips2") == 0
320 || strcmp (argv
[i
], "-mips3") == 0)
322 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
323 passed to the linker by some MIPS compilers. They
324 generally tell the linker to use a slightly different
325 library path. Perhaps someday these should be
326 implemented as emulations; until then, we just ignore
327 the arguments and hope that nobody ever creates
328 emulations named ips1, ips2 or ips3. */
333 emulation
= &argv
[i
][2];
341 /* If directory DIR contains an "ldscripts" subdirectory,
342 add DIR to the library search path and return true,
343 else return false. */
346 check_for_scripts_dir (dir
)
354 dirlen
= strlen (dir
);
355 /* sizeof counts the terminating NUL. */
356 buf
= (char *) ldmalloc (dirlen
+ sizeof("/ldscripts"));
357 sprintf (buf
, "%s/ldscripts", dir
);
359 res
= stat (buf
, &s
) == 0 && S_ISDIR (s
.st_mode
);
362 ldfile_add_library_path (dir
);
366 /* Set the default directory for finding script files.
367 Libraries will be searched for here too, but that's ok.
368 We look for the "ldscripts" directory in:
370 SCRIPTDIR (passed from Makefile)
371 the dir where this program is (for using it from the build tree)
372 the dir where this program is/../lib (for installing the tool suite elsewhere) */
380 if (check_for_scripts_dir (SCRIPTDIR
))
381 return; /* We've been installed normally. */
383 /* Look for "ldscripts" in the dir where our binary is. */
384 end
= strrchr (program_name
, '/');
387 dirlen
= end
- program_name
;
388 /* Make a copy of program_name in dir.
389 Leave room for later "/../lib". */
390 dir
= (char *) ldmalloc (dirlen
+ 8);
391 strncpy (dir
, program_name
, dirlen
);
397 dir
= (char *) ldmalloc (dirlen
+ 8);
401 if (check_for_scripts_dir (dir
))
402 return; /* Don't free dir. */
404 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
405 strcpy (dir
+ dirlen
, "/../lib");
406 if (check_for_scripts_dir (dir
))
409 free (dir
); /* Well, we tried. */
413 read_entry_symbols (desc
, entry
)
415 struct lang_input_statement_struct
*entry
;
417 if (entry
->asymbols
== (asymbol
**) NULL
)
419 bfd_size_type table_size
= get_symtab_upper_bound (desc
);
421 entry
->asymbols
= (asymbol
**) ldmalloc (table_size
);
422 entry
->symbol_count
= bfd_canonicalize_symtab (desc
, entry
->asymbols
);
427 * turn this item into a reference
434 asymbol
*sym
= *nlist_p
;
438 /* FIXME: Why do we clear the flags here? This used to set the
439 flags to zero, but we must not clear BSF_WEAK. */
440 sym
->flags
&= BSF_WEAK
;
442 sym
->section
= &bfd_und_section
;
443 sym
->udata
= (PTR
) (sp
->srefs_chain
);
444 sp
->srefs_chain
= nlist_p
;
448 This function is called for each name which is seen which has a global
449 scope. It enters the name into the global symbol table in the correct
450 symbol on the correct chain. Remember that each ldsym_type has three
451 chains attatched, one of all definitions of a symbol, one of all
452 references of a symbol and one of all common definitions of a symbol.
454 When the function is over, the supplied is left connected to the bfd
455 to which is was born, with its udata field pointing to the next member
456 on the chain in which it has been inserted.
458 A certain amount of jigery pokery is necessary since commons come
459 along and upset things, we only keep one item in the common chain; the
460 one with the biggest size seen sofar. When another common comes along
461 it either bumps the previous definition into the ref chain, since it
462 is bigger, or gets turned into a ref on the spot since the one on the
463 common chain is already bigger. If a real definition comes along then
464 the common gets bumped off anyway.
466 Whilst all this is going on we keep a count of the number of multiple
467 definitions seen, undefined global symbols and pending commons.
471 enter_global_ref (nlist_p
, name
)
472 asymbol
** nlist_p
; /* pointer into symbol table from incoming bfd */
473 CONST
char *name
; /* name of symbol in linker table */
475 asymbol
*sym
= *nlist_p
;
478 /* Lookup the name from the incoming bfd's symbol table in the
479 linker's global symbol table */
482 flagword this_symbol_flags
= sym
->flags
;
484 sp
= ldsym_get (name
);
487 /* If this symbol already has udata, it means that something strange
490 The strange thing is that we've had an undefined symbol resolved by
491 an alias, but the thing the alias defined wasn't in the file. So
492 the symbol got a udata entry, but the file wasn't loaded. Then
493 later on the file was loaded, but we don't need to do this
501 if (this_symbol_flags
& BSF_CONSTRUCTOR
)
503 /* Add this constructor to the list we keep */
504 ldlang_add_constructor (sp
);
505 /* Turn any commons into refs */
506 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
508 refize (sp
, sp
->scoms_chain
);
512 else if ((sym
->flags
& BSF_WEAK
) != 0
513 && (sp
->sdefs_chain
!= NULL
|| sp
->scoms_chain
!= NULL
))
515 /* SYM is a weak symbol for which we already have a definition.
516 Just ignore it. The UnixWare linker is order dependent: if a
517 global symbol follows a weak symbol it gives an error; if a
518 weak symbol follows a global symbol it does not. We are
523 if (bfd_is_com_section (sym
->section
))
525 /* If we have a definition of this symbol already then
526 this common turns into a reference. Also we only
527 ever point to the largest common, so if we
528 have a common, but it's bigger that the new symbol
529 the turn this into a reference too. */
532 /* This is a common symbol, but we already have a definition
533 for it, so just link it into the ref chain as if
534 it were a reference */
535 if (config
.warn_common
)
536 multiple_warn("%C: warning: common of `%s' overridden by definition\n",
538 "%C: warning: defined here\n",
540 refize (sp
, nlist_p
);
542 else if (sp
->scoms_chain
)
544 /* If we have a previous common, keep only the biggest */
545 if ((*(sp
->scoms_chain
))->value
> sym
->value
)
547 /* other common is bigger, throw this one away */
548 if (config
.warn_common
)
549 multiple_warn("%C: warning: common of `%s' overridden by larger common\n",
551 "%C: warning: larger common is here\n",
553 refize (sp
, nlist_p
);
555 else if (sp
->scoms_chain
!= nlist_p
)
557 /* other common is smaller, throw that away */
558 if (config
.warn_common
)
560 if ((*(sp
->scoms_chain
))->value
< sym
->value
)
561 multiple_warn("%C: warning: common of `%s' overriding smaller common\n",
563 "%C: warning: smaller common is here\n",
566 multiple_warn("%C: warning: multiple common of `%s'\n",
568 "%C: warning: previous common is here\n",
571 refize (sp
, sp
->scoms_chain
);
572 sp
->scoms_chain
= nlist_p
;
577 /* This is the first time we've seen a common, so remember it
578 - if it was undefined before, we know it's defined now. If
579 the symbol has been marked as really being a constructor,
580 then treat this as a ref. */
581 if (sp
->flags
& SYM_CONSTRUCTOR
)
583 /* Turn this into a ref */
584 refize (sp
, nlist_p
);
588 /* treat like a common */
590 undefined_global_sym_count
--;
593 sp
->scoms_chain
= nlist_p
;
597 else if (sym
->section
!= &bfd_und_section
)
599 /* This is the definition of a symbol, add to def chain */
600 if (sp
->sdefs_chain
&& (*(sp
->sdefs_chain
))->section
!= sym
->section
)
602 multiple_warn("%X%C: multiple definition of `%s'\n",
604 "%X%C: first defined here\n",
606 multiple_def_count
++;
610 sym
->udata
= (PTR
) (sp
->sdefs_chain
);
611 sp
->sdefs_chain
= nlist_p
;
614 /* A definition overrides a common symbol */
615 if (sp
->scoms_chain
!= NULL
)
617 if (config
.warn_common
)
618 multiple_warn("%C: warning: definition of `%s' overriding common\n",
620 "%C: warning: common is here\n",
622 refize (sp
, sp
->scoms_chain
);
626 else if (sp
->srefs_chain
&& relaxing
== false)
628 /* If previously was undefined, then remember as defined */
629 undefined_global_sym_count
--;
634 if (sp
->scoms_chain
== (asymbol
**) NULL
635 && sp
->srefs_chain
== (asymbol
**) NULL
636 && sp
->sdefs_chain
== (asymbol
**) NULL
)
638 /* And it's the first time we've seen it */
639 undefined_global_sym_count
++;
642 refize (sp
, nlist_p
);
646 ASSERT (sp
->sdefs_chain
== 0 || sp
->scoms_chain
== 0);
647 ASSERT (sp
->scoms_chain
== 0 || (*(sp
->scoms_chain
))->udata
== 0);
651 enter_file_symbols (entry
)
652 lang_input_statement_type
*entry
;
656 entry
->common_section
=
657 bfd_make_section_old_way (entry
->the_bfd
, "COMMON");
658 entry
->common_section
->flags
= SEC_NEVER_LOAD
;
659 ldlang_add_file (entry
);
662 if (trace_files
|| trace_file_tries
)
664 info_msg ("%I\n", entry
);
667 total_symbols_seen
+= entry
->symbol_count
;
669 if (entry
->symbol_count
)
671 for (q
= entry
->asymbols
; *q
; q
++)
675 if (had_y
&& p
->name
)
677 /* look up the symbol anyway to see if the trace bit was
679 ldsym_type
*s
= ldsym_get (p
->name
);
680 if (s
->flags
& SYM_Y
)
682 einfo ("%B: %s %T\n", entry
->the_bfd
,
683 p
->section
== &bfd_und_section
? "reference to" : "definition of ",
688 if (p
->section
== &bfd_ind_section
689 || (p
->flags
& BSF_INDIRECT
) != 0)
693 else if (p
->flags
& BSF_WARNING
)
697 else if (bfd_is_com_section (p
->section
))
699 enter_global_ref (q
, p
->name
);
701 /* If this is not bfd_com_section, make sure we have a
702 section of this name in the bfd. We need this
703 because some targets that use multiple common
704 sections do not actually put the common section in
705 the BFD, but we need it there so that a wildcard
706 specification in the linker script (e.g.,
707 *(.scommon)) will find the section and attach it to
708 the right output section. When an section is chosed
709 for the common symbols (in lang_common) that section
710 must have been correctly given an output section.
711 For normal common symbols we just use
712 entry->common_section, initialized above. */
713 if (p
->section
!= &bfd_com_section
714 && p
->section
->owner
!= entry
->the_bfd
)
715 bfd_make_section (entry
->the_bfd
,
716 bfd_get_section_name (p
->section
->owner
,
719 else if (p
->section
== &bfd_und_section
720 || (p
->flags
& BSF_GLOBAL
)
721 || (p
->flags
& BSF_CONSTRUCTOR
)
722 || (p
->flags
& BSF_WEAK
))
724 enter_global_ref (q
, p
->name
);
731 /* Searching libraries */
733 struct lang_input_statement_struct
*decode_library_subfile ();
734 void linear_library (), symdef_library ();
736 /* Search the library ENTRY, already open on descriptor DESC.
737 This means deciding which library members to load,
738 making a chain of `struct lang_input_statement_struct' for those members,
739 and entering their global symbols in the hash table. */
742 search_library (entry
)
743 struct lang_input_statement_struct
*entry
;
746 /* No need to load a library if no undefined symbols */
747 if (!undefined_global_sym_count
)
750 if (bfd_has_map (entry
->the_bfd
))
751 symdef_library (entry
);
753 linear_library (entry
);
760 gnu960_check_format (abfd
, format
)
766 if ((bfd_check_format (abfd
, format
) == true)
767 && (abfd
->xvec
->flavour
== output_flavor
))
779 ldmain_open_file_read_symbol (entry
)
780 struct lang_input_statement_struct
*entry
;
782 if (entry
->asymbols
== (asymbol
**) NULL
783 && entry
->real
== true
784 && entry
->filename
!= (char *) NULL
)
786 ldfile_open_file (entry
);
790 if (gnu960_check_format (entry
->the_bfd
, bfd_object
))
792 if (bfd_check_format (entry
->the_bfd
, bfd_object
))
795 entry
->the_bfd
->usrdata
= (PTR
) entry
;
798 read_entry_symbols (entry
->the_bfd
, entry
);
800 /* look through the sections in the file and see if any of them
802 ldlang_check_for_constructors (entry
);
804 enter_file_symbols (entry
);
807 else if (gnu960_check_format (entry
->the_bfd
, bfd_archive
))
809 else if (bfd_check_format (entry
->the_bfd
, bfd_archive
))
812 entry
->the_bfd
->usrdata
= (PTR
) entry
;
814 entry
->subfiles
= (lang_input_statement_type
*) NULL
;
815 search_library (entry
);
819 einfo ("%F%B: malformed input file (not rel or archive) \n",
826 /* Construct and return a lang_input_statement_struct for a library member.
827 The library's lang_input_statement_struct is library_entry,
828 and the library is open on DESC.
829 SUBFILE_OFFSET is the byte index in the library of this member's header.
830 We store the length of the member into *LENGTH_LOC. */
832 lang_input_statement_type
*
833 decode_library_subfile (library_entry
, subfile_offset
)
834 struct lang_input_statement_struct
*library_entry
;
837 register struct lang_input_statement_struct
*subentry
;
840 /* First, check if we already have a loaded
841 lang_input_statement_struct for this library subfile. If so,
842 just return it. Otherwise, allocate some space and build a new one. */
844 if (subfile_offset
->usrdata
845 && ((struct lang_input_statement_struct
*) subfile_offset
->usrdata
)->
848 subentry
= (struct lang_input_statement_struct
*) subfile_offset
->usrdata
;
853 (struct lang_input_statement_struct
*)
854 ldmalloc ((bfd_size_type
) (sizeof (struct lang_input_statement_struct
)));
856 subentry
->filename
= subfile_offset
->filename
;
857 subentry
->local_sym_name
= subfile_offset
->filename
;
858 subentry
->asymbols
= 0;
859 subentry
->the_bfd
= subfile_offset
;
860 subentry
->subfiles
= 0;
862 subentry
->superfile
= library_entry
;
863 subentry
->is_archive
= false;
865 subentry
->just_syms_flag
= false;
866 subentry
->loaded
= false;
872 boolean
subfile_wanted_p ();
874 clear_syms (entry
, offset
)
875 struct lang_input_statement_struct
*entry
;
879 unsigned long indx
= bfd_get_next_mapent (entry
->the_bfd
,
883 while (indx
!= BFD_NO_MORE_SYMBOLS
)
885 if (car
->file_offset
== offset
)
889 indx
= bfd_get_next_mapent (entry
->the_bfd
, indx
, &car
);
894 /* Search a library that has a map
897 symdef_library (entry
)
898 struct lang_input_statement_struct
*entry
;
901 register struct lang_input_statement_struct
*prev
= 0;
903 boolean not_finished
= true;
905 while (not_finished
== true)
907 carsym
*exported_library_name
;
908 bfd
*prev_archive_member_bfd
= 0;
910 int idx
= bfd_get_next_mapent (entry
->the_bfd
,
912 &exported_library_name
);
914 not_finished
= false;
916 while (idx
!= BFD_NO_MORE_SYMBOLS
&& undefined_global_sym_count
)
919 if (exported_library_name
->name
)
922 ldsym_type
*sp
= ldsym_get_soft (exported_library_name
->name
);
924 /* If we find a symbol that appears to be needed, think carefully
925 about the archive member that the symbol is in. */
926 /* So - if it exists, and is referenced somewhere and is
928 if (sp
&& sp
->srefs_chain
&& !sp
->sdefs_chain
)
930 bfd
*archive_member_bfd
= bfd_get_elt_at_index (entry
->the_bfd
, idx
);
931 struct lang_input_statement_struct
*archive_member_lang_input_statement_struct
;
934 if (archive_member_bfd
&& gnu960_check_format (archive_member_bfd
, bfd_object
))
936 if (archive_member_bfd
&& bfd_check_format (archive_member_bfd
, bfd_object
))
940 /* Don't think carefully about any archive member
941 more than once in a given pass. */
942 if (prev_archive_member_bfd
!= archive_member_bfd
)
945 prev_archive_member_bfd
= archive_member_bfd
;
947 /* Read the symbol table of the archive member. */
949 if (archive_member_bfd
->usrdata
!= (PTR
) NULL
)
952 archive_member_lang_input_statement_struct
= (lang_input_statement_type
*) archive_member_bfd
->usrdata
;
957 archive_member_lang_input_statement_struct
=
958 decode_library_subfile (entry
, archive_member_bfd
);
959 archive_member_bfd
->usrdata
= (PTR
) archive_member_lang_input_statement_struct
;
963 if (archive_member_lang_input_statement_struct
== 0)
965 einfo ("%F%I contains invalid archive member %s\n",
969 if (archive_member_lang_input_statement_struct
->loaded
== false)
972 read_entry_symbols (archive_member_bfd
, archive_member_lang_input_statement_struct
);
973 /* Now scan the symbol table and decide whether to load. */
976 if (subfile_wanted_p (archive_member_lang_input_statement_struct
) == true)
979 /* This member is needed; load it.
980 Since we are loading something on this pass,
981 we must make another pass through the symdef data. */
985 enter_file_symbols (archive_member_lang_input_statement_struct
);
988 prev
->chain
= archive_member_lang_input_statement_struct
;
990 entry
->subfiles
= archive_member_lang_input_statement_struct
;
993 prev
= archive_member_lang_input_statement_struct
;
996 /* Clear out this member's symbols from the symdef data
997 so that following passes won't waste time on them. */
998 clear_syms (entry
, exported_library_name
->file_offset
);
999 archive_member_lang_input_statement_struct
->loaded
= true;
1006 idx
= bfd_get_next_mapent (entry
->the_bfd
, idx
, &exported_library_name
);
1012 linear_library (entry
)
1013 struct lang_input_statement_struct
*entry
;
1015 boolean more_to_do
= true;
1016 register struct lang_input_statement_struct
*prev
= 0;
1018 if (entry
->complained
== false)
1020 if (entry
->the_bfd
->xvec
->flavour
!= bfd_target_ieee_flavour
)
1023 /* IEEE can use table of contents, so this message is bogus */
1024 einfo ("%P: library %s has bad table of contents, rerun ranlib\n",
1025 entry
->the_bfd
->filename
);
1027 entry
->complained
= true;
1033 bfd
*archive
= bfd_openr_next_archived_file (entry
->the_bfd
, 0);
1038 /* Don't check this file if it's already been read in
1041 if (!archive
->usrdata
||
1042 !((lang_input_statement_type
*) (archive
->usrdata
))->loaded
)
1045 if (gnu960_check_format (archive
, bfd_object
))
1047 if (bfd_check_format (archive
, bfd_object
))
1050 register struct lang_input_statement_struct
*subentry
;
1052 subentry
= decode_library_subfile (entry
,
1055 archive
->usrdata
= (PTR
) subentry
;
1058 if (subentry
->loaded
== false)
1060 read_entry_symbols (archive
, subentry
);
1062 if (subfile_wanted_p (subentry
) == true)
1064 enter_file_symbols (subentry
);
1067 prev
->chain
= subentry
;
1069 entry
->subfiles
= subentry
;
1073 subentry
->loaded
= true;
1078 archive
= bfd_openr_next_archived_file (entry
->the_bfd
, archive
);
1085 /* ENTRY is an entry for a file inside an archive
1086 Its symbols have been read into core, but not entered into the
1088 Return nonzero if we ought to load this file */
1091 subfile_wanted_p (entry
)
1092 struct lang_input_statement_struct
*entry
;
1096 if (entry
->symbol_count
== 0)
1099 for (q
= entry
->asymbols
; *q
; q
++)
1103 /* If the symbol has an interesting definition, we could
1104 potentially want it. */
1106 if (p
->flags
& BSF_INDIRECT
)
1108 /** add_indirect(q);*/
1111 if (bfd_is_com_section (p
->section
)
1112 || (p
->flags
& BSF_GLOBAL
)
1113 || (p
->flags
& BSF_INDIRECT
)
1114 || (p
->flags
& BSF_WEAK
))
1116 register ldsym_type
*sp
= ldsym_get_soft (p
->name
);
1118 /* If this symbol has not been hashed,
1119 we can't be looking for it. */
1120 if (sp
!= (ldsym_type
*) NULL
1121 && sp
->sdefs_chain
== (asymbol
**) NULL
)
1125 /* A weak symbol is not considered to be a reference
1126 when pulling files out of an archive. An unresolved
1127 weak symbol winds up with a value of zero. See the
1128 SVR4 ABI, p. 4-27. */
1129 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
1131 else if (sp
->srefs_chain
== (asymbol
**) NULL
)
1138 for (ptr
= sp
->srefs_chain
;
1139 ptr
!= (asymbol
**) NULL
;
1140 ptr
= (asymbol
**) ((*ptr
)->udata
))
1142 if (((*ptr
)->flags
& BSF_WEAK
) == 0)
1152 /* This is a symbol we are looking for. It is
1153 either common or not yet defined. If this is a
1154 common symbol, then if the symbol in the object
1155 file is common, we need to combine sizes. But if
1156 we already have a common symbol, and the symbol
1157 in the object file is not common, we don't want
1158 the object file: it is providing a definition for
1159 a symbol that we already have a definition for
1160 (this is the else condition below). */
1161 if (bfd_is_com_section (p
->section
))
1164 /* If the symbol in the table is a constructor, we won't to
1165 anything fancy with it */
1166 if ((sp
->flags
& SYM_CONSTRUCTOR
) == 0)
1168 /* This libary member has something to
1169 say about this element. We should
1170 remember if its a new size */
1171 /* Move something from the ref list to the com list */
1172 if (sp
->scoms_chain
)
1174 /* Already a common symbol, maybe update it */
1175 if (p
->value
> (*(sp
->scoms_chain
))->value
)
1177 (*(sp
->scoms_chain
))->value
= p
->value
;
1182 /* Take a value from the ref chain
1183 Here we are moving a symbol from the owning bfd
1184 to another bfd. We must set up the
1185 common_section portion of the bfd thing */
1189 sp
->scoms_chain
= sp
->srefs_chain
;
1191 (asymbol
**) ((*(sp
->srefs_chain
))->udata
);
1192 (*(sp
->scoms_chain
))->udata
= (PTR
) NULL
;
1194 (*(sp
->scoms_chain
))->section
= p
->section
;
1195 (*(sp
->scoms_chain
))->flags
= 0;
1196 /* Remember the size of this item */
1197 sp
->scoms_chain
[0]->value
= p
->value
;
1199 undefined_global_sym_count
--;
1202 asymbol
*com
= *(sp
->scoms_chain
);
1204 if (((lang_input_statement_type
*)
1205 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
==
1208 ((lang_input_statement_type
*)
1209 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
=
1210 bfd_make_section_old_way (bfd_asymbol_bfd (com
), "COMMON");
1213 /* If the symbol is not in the generic
1214 common section, we must make sure the
1215 BFD has a section to hang it on to. */
1216 if (com
->section
!= &bfd_com_section
1217 && (com
->section
->owner
1218 != bfd_asymbol_bfd (com
)))
1220 (bfd_asymbol_bfd (com
),
1221 bfd_get_section_name (bfd_asymbol_bfd (com
),
1225 ASSERT (p
->udata
== 0);
1227 else if (sp
->scoms_chain
== (asymbol
**) NULL
)
1231 info_msg ("%I needed due to %s\n", entry
, sp
->name
);
1247 ldsym_type
*lookup
= ldsym_get (text
);
1248 lookup
->flags
|= SYM_Y
;