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. */
40 /* Somewhere above, sys/stat.h got included . . . . */
41 #if !defined(S_ISDIR) && defined(S_IFDIR)
42 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
47 static char *get_emulation ();
48 static void set_scripts_dir ();
51 extern boolean lang_has_input_file
;
52 extern boolean force_make_executable
;
53 extern boolean relaxing
;
54 extern boolean had_script
;
59 char *output_filename
= "a.out";
61 /* Name this program was invoked by. */
64 /* The file that we're creating */
67 /* set if -y on the command line */
70 /* The local symbol prefix */
73 /* Set by -G argument, for MIPS ECOFF target. */
74 int g_switch_value
= 8;
76 /* Count the number of global symbols multiply defined. */
77 int multiple_def_count
;
79 /* Count the number of symbols defined through common declarations.
80 This count is referenced in symdef_library, linear_library, and
81 modified by enter_global_ref.
83 It is incremented when a symbol is created as a common, and
84 decremented when the common declaration is overridden
86 Another way of thinking of it is that this is a count of
87 all ldsym_types with a ->scoms field */
89 unsigned int commons_pending
;
91 /* Count the number of global symbols referenced and not defined.
92 common symbols are not included in this count. */
94 unsigned int undefined_global_sym_count
;
96 /* Nonzero means print names of input files as processed. */
99 /* Nonzero means same, but note open failures, too. */
100 boolean trace_file_tries
;
102 /* 1 => write load map. */
106 /* Indicates whether output file will be b.out (default) or coff */
107 enum target_flavour output_flavor
= BFD_BOUT_FORMAT
;
110 /* A count of the total number of local symbols ever seen - by adding
111 the symbol_count field of each newly read afile.*/
113 unsigned int total_symbols_seen
;
115 /* A count of the number of read files - the same as the number of elements
118 unsigned int total_files_seen
;
120 args_type command_line
;
122 ld_config_type config
;
131 program_name
= argv
[0];
135 /* Initialize the data about options. */
138 trace_files
= trace_file_tries
= false;
140 config
.relocateable_output
= false;
141 command_line
.force_common_definition
= false;
143 init_bfd_error_vector ();
145 ldfile_add_arch ("");
147 config
.make_executable
= true;
148 force_make_executable
= false;
150 /* Initialize the cumulative counts of symbols. */
151 undefined_global_sym_count
= 0;
152 multiple_def_count
= 0;
155 config
.magic_demand_paged
= true;
156 config
.text_read_only
= true;
157 config
.make_executable
= true;
159 emulation
= get_emulation (argc
, argv
);
160 ldemul_choose_mode (emulation
);
161 default_target
= ldemul_choose_target ();
163 ldemul_before_parse ();
164 lang_has_input_file
= false;
165 parse_args (argc
, argv
);
167 /* This essentially adds another -L directory so this must be done after
168 the -L's in argv have been processed. */
171 if (had_script
== false)
173 /* Read the emulation's appropriate default script. */
175 char *s
= ldemul_get_script (&isfile
);
179 /* sizeof counts the terminating NUL. */
180 size_t size
= strlen (s
) + sizeof ("-T ");
181 char *buf
= (char *) ldmalloc(size
);
182 sprintf (buf
, "-T %s", s
);
190 if (config
.relocateable_output
&& command_line
.relax
)
192 einfo ("%P%F: -relax and -r may not be used together\n");
196 if (lang_has_input_file
== false)
198 einfo ("%P%F: no input files\n");
203 info_msg ("%P: mode %s\n", emulation
);
206 ldemul_after_parse ();
209 if (config
.map_filename
)
211 if (strcmp (config
.map_filename
, "-") == 0)
213 config
.map_file
= stdout
;
217 config
.map_file
= fopen (config
.map_filename
, FOPEN_WT
);
218 if (config
.map_file
== (FILE *) NULL
)
220 einfo ("%P%F: cannot open map file %s: %E\n",
221 config
.map_filename
);
229 /* Print error messages for any missing symbols, for any warning
230 symbols, and possibly multiple definitions */
233 if (config
.text_read_only
)
235 /* Look for a text section and mark the readonly attribute in it */
236 asection
*found
= bfd_get_section_by_name (output_bfd
, ".text");
238 if (found
!= (asection
*) NULL
)
240 found
->flags
|= SEC_READONLY
;
244 if (config
.relocateable_output
)
245 output_bfd
->flags
&= ~EXEC_P
;
247 output_bfd
->flags
|= EXEC_P
;
251 /* Even if we're producing relocateable output, some non-fatal errors should
252 be reported in the exit status. (What non-fatal errors, if any, do we
253 want to ignore for relocateable output?) */
255 if (config
.make_executable
== false && force_make_executable
== false)
257 if (trace_files
== true)
259 einfo ("%P: link errors found, deleting executable `%s'\n",
263 if (output_bfd
->iostream
)
264 fclose ((FILE *) (output_bfd
->iostream
));
266 unlink (output_filename
);
271 bfd_close (output_bfd
);
277 /* We need to find any explicitly given emulation in order to initialize the
278 state that's needed by the lex&yacc argument parser (parse_args). */
281 get_emulation (argc
, argv
)
289 check_v960 (argc
, argv
);
290 emulation
= "gld960";
291 for (i
= 1; i
< argc
; i
++)
293 if (!strcmp (argv
[i
], "-Fcoff"))
295 emulation
= "lnk960";
296 output_flavor
= BFD_COFF_FORMAT
;
301 emulation
= (char *) getenv (EMULATION_ENVIRON
);
302 if (emulation
== NULL
)
303 emulation
= DEFAULT_EMULATION
;
306 for (i
= 1; i
< argc
; i
++)
308 if (!strncmp (argv
[i
], "-m", 2))
310 if (argv
[i
][2] == '\0')
315 emulation
= argv
[i
+ 1];
320 einfo("%P%F: missing argument to -m\n");
323 else if (strcmp (argv
[i
], "-mips1") == 0
324 || strcmp (argv
[i
], "-mips2") == 0
325 || strcmp (argv
[i
], "-mips3") == 0)
327 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
328 passed to the linker by some MIPS compilers. They
329 generally tell the linker to use a slightly different
330 library path. Perhaps someday these should be
331 implemented as emulations; until then, we just ignore
332 the arguments and hope that nobody ever creates
333 emulations named ips1, ips2 or ips3. */
338 emulation
= &argv
[i
][2];
346 /* If directory DIR contains an "ldscripts" subdirectory,
347 add DIR to the library search path and return true,
348 else return false. */
351 check_for_scripts_dir (dir
)
359 dirlen
= strlen (dir
);
360 /* sizeof counts the terminating NUL. */
361 buf
= (char *) ldmalloc (dirlen
+ sizeof("/ldscripts"));
362 sprintf (buf
, "%s/ldscripts", dir
);
364 res
= stat (buf
, &s
) == 0 && S_ISDIR (s
.st_mode
);
367 ldfile_add_library_path (dir
);
371 /* Set the default directory for finding script files.
372 Libraries will be searched for here too, but that's ok.
373 We look for the "ldscripts" directory in:
375 SCRIPTDIR (passed from Makefile)
376 the dir where this program is (for using it from the build tree)
377 the dir where this program is/../lib (for installing the tool suite elsewhere) */
385 if (check_for_scripts_dir (SCRIPTDIR
))
386 return; /* We've been installed normally. */
388 /* Look for "ldscripts" in the dir where our binary is. */
389 end
= strrchr (program_name
, '/');
392 dirlen
= end
- program_name
;
393 /* Make a copy of program_name in dir.
394 Leave room for later "/../lib". */
395 dir
= (char *) ldmalloc (dirlen
+ 8);
396 strncpy (dir
, program_name
, dirlen
);
402 dir
= (char *) ldmalloc (dirlen
+ 8);
406 if (check_for_scripts_dir (dir
))
407 return; /* Don't free dir. */
409 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
410 strcpy (dir
+ dirlen
, "/../lib");
411 if (check_for_scripts_dir (dir
))
414 free (dir
); /* Well, we tried. */
418 read_entry_symbols (desc
, entry
)
420 struct lang_input_statement_struct
*entry
;
422 if (entry
->asymbols
== (asymbol
**) NULL
)
424 bfd_size_type table_size
= get_symtab_upper_bound (desc
);
426 entry
->asymbols
= (asymbol
**) ldmalloc (table_size
);
427 entry
->symbol_count
= bfd_canonicalize_symtab (desc
, entry
->asymbols
);
432 * turn this item into a reference
439 asymbol
*sym
= *nlist_p
;
443 /* FIXME: Why do we clear the flags here? This used to set the
444 flags to zero, but we must not clear BSF_WEAK. */
445 sym
->flags
&= BSF_WEAK
;
447 sym
->section
= &bfd_und_section
;
448 sym
->udata
= (PTR
) (sp
->srefs_chain
);
449 sp
->srefs_chain
= nlist_p
;
453 This function is called for each name which is seen which has a global
454 scope. It enters the name into the global symbol table in the correct
455 symbol on the correct chain. Remember that each ldsym_type has three
456 chains attatched, one of all definitions of a symbol, one of all
457 references of a symbol and one of all common definitions of a symbol.
459 When the function is over, the supplied is left connected to the bfd
460 to which is was born, with its udata field pointing to the next member
461 on the chain in which it has been inserted.
463 A certain amount of jigery pokery is necessary since commons come
464 along and upset things, we only keep one item in the common chain; the
465 one with the biggest size seen sofar. When another common comes along
466 it either bumps the previous definition into the ref chain, since it
467 is bigger, or gets turned into a ref on the spot since the one on the
468 common chain is already bigger. If a real definition comes along then
469 the common gets bumped off anyway.
471 Whilst all this is going on we keep a count of the number of multiple
472 definitions seen, undefined global symbols and pending commons.
476 enter_global_ref (nlist_p
, name
)
477 asymbol
** nlist_p
; /* pointer into symbol table from incoming bfd */
478 CONST
char *name
; /* name of symbol in linker table */
480 asymbol
*sym
= *nlist_p
;
483 /* Lookup the name from the incoming bfd's symbol table in the
484 linker's global symbol table */
487 flagword this_symbol_flags
= sym
->flags
;
489 sp
= ldsym_get (name
);
492 /* If this symbol already has udata, it means that something strange
495 The strange thing is that we've had an undefined symbol resolved by
496 an alias, but the thing the alias defined wasn't in the file. So
497 the symbol got a udata entry, but the file wasn't loaded. Then
498 later on the file was loaded, but we don't need to do this
506 if (this_symbol_flags
& BSF_CONSTRUCTOR
)
508 /* Add this constructor to the list we keep */
509 ldlang_add_constructor (sp
);
510 /* Turn any commons into refs */
511 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
513 refize (sp
, sp
->scoms_chain
);
517 else if ((sym
->flags
& BSF_WEAK
) != 0
518 && (sp
->sdefs_chain
!= NULL
|| sp
->scoms_chain
!= NULL
))
520 /* SYM is a weak symbol for which we already have a definition.
521 Just ignore it. The UnixWare linker is order dependent: if a
522 global symbol follows a weak symbol it gives an error; if a
523 weak symbol follows a global symbol it does not. We are
528 if (bfd_is_com_section (sym
->section
))
530 /* If we have a definition of this symbol already then
531 this common turns into a reference. Also we only
532 ever point to the largest common, so if we
533 have a common, but it's bigger that the new symbol
534 the turn this into a reference too. */
537 /* This is a common symbol, but we already have a definition
538 for it, so just link it into the ref chain as if
539 it were a reference */
540 if (config
.warn_common
)
541 multiple_warn("%C: warning: common of `%s' overridden by definition\n",
543 "%C: warning: defined here\n",
545 refize (sp
, nlist_p
);
547 else if (sp
->scoms_chain
)
549 /* If we have a previous common, keep only the biggest */
550 if ((*(sp
->scoms_chain
))->value
> sym
->value
)
552 /* other common is bigger, throw this one away */
553 if (config
.warn_common
)
554 multiple_warn("%C: warning: common of `%s' overridden by larger common\n",
556 "%C: warning: larger common is here\n",
558 refize (sp
, nlist_p
);
560 else if (sp
->scoms_chain
!= nlist_p
)
562 /* other common is smaller, throw that away */
563 if (config
.warn_common
)
565 if ((*(sp
->scoms_chain
))->value
< sym
->value
)
566 multiple_warn("%C: warning: common of `%s' overriding smaller common\n",
568 "%C: warning: smaller common is here\n",
571 multiple_warn("%C: warning: multiple common of `%s'\n",
573 "%C: warning: previous common is here\n",
576 refize (sp
, sp
->scoms_chain
);
577 sp
->scoms_chain
= nlist_p
;
582 /* This is the first time we've seen a common, so remember it
583 - if it was undefined before, we know it's defined now. If
584 the symbol has been marked as really being a constructor,
585 then treat this as a ref. */
586 if (sp
->flags
& SYM_CONSTRUCTOR
)
588 /* Turn this into a ref */
589 refize (sp
, nlist_p
);
593 /* treat like a common */
595 undefined_global_sym_count
--;
598 sp
->scoms_chain
= nlist_p
;
602 else if (sym
->section
!= &bfd_und_section
)
604 /* This is the definition of a symbol, add to def chain */
605 if (sp
->sdefs_chain
&& (*(sp
->sdefs_chain
))->section
!= sym
->section
)
607 multiple_warn("%X%C: multiple definition of `%s'\n",
609 "%X%C: first defined here\n",
611 multiple_def_count
++;
615 sym
->udata
= (PTR
) (sp
->sdefs_chain
);
616 sp
->sdefs_chain
= nlist_p
;
619 /* A definition overrides a common symbol */
620 if (sp
->scoms_chain
!= NULL
)
622 if (config
.warn_common
)
623 multiple_warn("%C: warning: definition of `%s' overriding common\n",
625 "%C: warning: common is here\n",
627 refize (sp
, sp
->scoms_chain
);
631 else if (sp
->srefs_chain
&& relaxing
== false)
633 /* If previously was undefined, then remember as defined */
634 undefined_global_sym_count
--;
639 if (sp
->scoms_chain
== (asymbol
**) NULL
640 && sp
->srefs_chain
== (asymbol
**) NULL
641 && sp
->sdefs_chain
== (asymbol
**) NULL
)
643 /* And it's the first time we've seen it */
644 undefined_global_sym_count
++;
647 refize (sp
, nlist_p
);
651 ASSERT (sp
->sdefs_chain
== 0 || sp
->scoms_chain
== 0);
652 ASSERT (sp
->scoms_chain
== 0 || (*(sp
->scoms_chain
))->udata
== 0);
656 enter_file_symbols (entry
)
657 lang_input_statement_type
*entry
;
661 entry
->common_section
=
662 bfd_make_section_old_way (entry
->the_bfd
, "COMMON");
663 entry
->common_section
->flags
= SEC_NEVER_LOAD
;
664 ldlang_add_file (entry
);
667 if (trace_files
|| trace_file_tries
)
669 info_msg ("%I\n", entry
);
672 total_symbols_seen
+= entry
->symbol_count
;
674 if (entry
->symbol_count
)
676 for (q
= entry
->asymbols
; *q
; q
++)
680 if (had_y
&& p
->name
)
682 /* look up the symbol anyway to see if the trace bit was
684 ldsym_type
*s
= ldsym_get (p
->name
);
685 if (s
->flags
& SYM_Y
)
687 einfo ("%B: %s %T\n", entry
->the_bfd
,
688 p
->section
== &bfd_und_section
? "reference to" : "definition of ",
693 if (p
->section
== &bfd_ind_section
694 || (p
->flags
& BSF_INDIRECT
) != 0)
698 else if (p
->flags
& BSF_WARNING
)
702 else if (bfd_is_com_section (p
->section
))
704 enter_global_ref (q
, p
->name
);
706 /* If this is not bfd_com_section, make sure we have a
707 section of this name in the bfd. We need this
708 because some targets that use multiple common
709 sections do not actually put the common section in
710 the BFD, but we need it there so that a wildcard
711 specification in the linker script (e.g.,
712 *(.scommon)) will find the section and attach it to
713 the right output section. When an section is chosed
714 for the common symbols (in lang_common) that section
715 must have been correctly given an output section.
716 For normal common symbols we just use
717 entry->common_section, initialized above. */
718 if (p
->section
!= &bfd_com_section
719 && p
->section
->owner
!= entry
->the_bfd
)
720 bfd_make_section (entry
->the_bfd
,
721 bfd_get_section_name (p
->section
->owner
,
724 else if (p
->section
== &bfd_und_section
725 || (p
->flags
& BSF_GLOBAL
)
726 || (p
->flags
& BSF_CONSTRUCTOR
)
727 || (p
->flags
& BSF_WEAK
))
729 enter_global_ref (q
, p
->name
);
736 /* Searching libraries */
738 struct lang_input_statement_struct
*decode_library_subfile ();
739 void linear_library (), symdef_library ();
741 /* Search the library ENTRY, already open on descriptor DESC.
742 This means deciding which library members to load,
743 making a chain of `struct lang_input_statement_struct' for those members,
744 and entering their global symbols in the hash table. */
747 search_library (entry
)
748 struct lang_input_statement_struct
*entry
;
751 /* No need to load a library if no undefined symbols */
752 if (!undefined_global_sym_count
)
755 if (bfd_has_map (entry
->the_bfd
))
756 symdef_library (entry
);
758 linear_library (entry
);
765 gnu960_check_format (abfd
, format
)
771 if ((bfd_check_format (abfd
, format
) == true)
772 && (abfd
->xvec
->flavour
== output_flavor
))
784 ldmain_open_file_read_symbol (entry
)
785 struct lang_input_statement_struct
*entry
;
787 if (entry
->asymbols
== (asymbol
**) NULL
788 && entry
->real
== true
789 && entry
->filename
!= (char *) NULL
)
791 ldfile_open_file (entry
);
795 if (gnu960_check_format (entry
->the_bfd
, bfd_object
))
797 if (bfd_check_format (entry
->the_bfd
, bfd_object
))
800 entry
->the_bfd
->usrdata
= (PTR
) entry
;
803 read_entry_symbols (entry
->the_bfd
, entry
);
805 /* look through the sections in the file and see if any of them
807 ldlang_check_for_constructors (entry
);
809 enter_file_symbols (entry
);
812 else if (gnu960_check_format (entry
->the_bfd
, bfd_archive
))
814 else if (bfd_check_format (entry
->the_bfd
, bfd_archive
))
817 entry
->the_bfd
->usrdata
= (PTR
) entry
;
819 entry
->subfiles
= (lang_input_statement_type
*) NULL
;
820 search_library (entry
);
824 einfo ("%F%B: malformed input file (not rel or archive) \n",
831 /* Construct and return a lang_input_statement_struct for a library member.
832 The library's lang_input_statement_struct is library_entry,
833 and the library is open on DESC.
834 SUBFILE_OFFSET is the byte index in the library of this member's header.
835 We store the length of the member into *LENGTH_LOC. */
837 lang_input_statement_type
*
838 decode_library_subfile (library_entry
, subfile_offset
)
839 struct lang_input_statement_struct
*library_entry
;
842 register struct lang_input_statement_struct
*subentry
;
845 /* First, check if we already have a loaded
846 lang_input_statement_struct for this library subfile. If so,
847 just return it. Otherwise, allocate some space and build a new one. */
849 if (subfile_offset
->usrdata
850 && ((struct lang_input_statement_struct
*) subfile_offset
->usrdata
)->
853 subentry
= (struct lang_input_statement_struct
*) subfile_offset
->usrdata
;
858 (struct lang_input_statement_struct
*)
859 ldmalloc ((bfd_size_type
) (sizeof (struct lang_input_statement_struct
)));
861 subentry
->filename
= subfile_offset
->filename
;
862 subentry
->local_sym_name
= subfile_offset
->filename
;
863 subentry
->asymbols
= 0;
864 subentry
->the_bfd
= subfile_offset
;
865 subentry
->subfiles
= 0;
867 subentry
->superfile
= library_entry
;
868 subentry
->is_archive
= false;
870 subentry
->just_syms_flag
= false;
871 subentry
->loaded
= false;
877 boolean
subfile_wanted_p ();
879 clear_syms (entry
, offset
)
880 struct lang_input_statement_struct
*entry
;
884 unsigned long indx
= bfd_get_next_mapent (entry
->the_bfd
,
888 while (indx
!= BFD_NO_MORE_SYMBOLS
)
890 if (car
->file_offset
== offset
)
894 indx
= bfd_get_next_mapent (entry
->the_bfd
, indx
, &car
);
899 /* Search a library that has a map
902 symdef_library (entry
)
903 struct lang_input_statement_struct
*entry
;
906 register struct lang_input_statement_struct
*prev
= 0;
908 boolean not_finished
= true;
910 while (not_finished
== true)
912 carsym
*exported_library_name
;
913 bfd
*prev_archive_member_bfd
= 0;
915 int idx
= bfd_get_next_mapent (entry
->the_bfd
,
917 &exported_library_name
);
919 not_finished
= false;
921 while (idx
!= BFD_NO_MORE_SYMBOLS
&& undefined_global_sym_count
)
924 if (exported_library_name
->name
)
927 ldsym_type
*sp
= ldsym_get_soft (exported_library_name
->name
);
929 /* If we find a symbol that appears to be needed, think carefully
930 about the archive member that the symbol is in. */
931 /* So - if it exists, and is referenced somewhere and is
933 if (sp
&& sp
->srefs_chain
&& !sp
->sdefs_chain
)
935 bfd
*archive_member_bfd
= bfd_get_elt_at_index (entry
->the_bfd
, idx
);
936 struct lang_input_statement_struct
*archive_member_lang_input_statement_struct
;
939 if (archive_member_bfd
&& gnu960_check_format (archive_member_bfd
, bfd_object
))
941 if (archive_member_bfd
&& bfd_check_format (archive_member_bfd
, bfd_object
))
945 /* Don't think carefully about any archive member
946 more than once in a given pass. */
947 if (prev_archive_member_bfd
!= archive_member_bfd
)
950 prev_archive_member_bfd
= archive_member_bfd
;
952 /* Read the symbol table of the archive member. */
954 if (archive_member_bfd
->usrdata
!= (PTR
) NULL
)
957 archive_member_lang_input_statement_struct
= (lang_input_statement_type
*) archive_member_bfd
->usrdata
;
962 archive_member_lang_input_statement_struct
=
963 decode_library_subfile (entry
, archive_member_bfd
);
964 archive_member_bfd
->usrdata
= (PTR
) archive_member_lang_input_statement_struct
;
968 if (archive_member_lang_input_statement_struct
== 0)
970 einfo ("%F%I contains invalid archive member %s\n",
974 if (archive_member_lang_input_statement_struct
->loaded
== false)
977 read_entry_symbols (archive_member_bfd
, archive_member_lang_input_statement_struct
);
978 /* Now scan the symbol table and decide whether to load. */
981 if (subfile_wanted_p (archive_member_lang_input_statement_struct
) == true)
984 /* This member is needed; load it.
985 Since we are loading something on this pass,
986 we must make another pass through the symdef data. */
990 enter_file_symbols (archive_member_lang_input_statement_struct
);
993 prev
->chain
= archive_member_lang_input_statement_struct
;
995 entry
->subfiles
= archive_member_lang_input_statement_struct
;
998 prev
= archive_member_lang_input_statement_struct
;
1001 /* Clear out this member's symbols from the symdef data
1002 so that following passes won't waste time on them. */
1003 clear_syms (entry
, exported_library_name
->file_offset
);
1004 archive_member_lang_input_statement_struct
->loaded
= true;
1011 idx
= bfd_get_next_mapent (entry
->the_bfd
, idx
, &exported_library_name
);
1017 linear_library (entry
)
1018 struct lang_input_statement_struct
*entry
;
1020 boolean more_to_do
= true;
1021 register struct lang_input_statement_struct
*prev
= 0;
1023 if (entry
->complained
== false)
1025 if (entry
->the_bfd
->xvec
->flavour
!= bfd_target_ieee_flavour
)
1028 /* IEEE can use table of contents, so this message is bogus */
1029 einfo ("%P: library %s has bad table of contents, rerun ranlib\n",
1030 entry
->the_bfd
->filename
);
1032 entry
->complained
= true;
1038 bfd
*archive
= bfd_openr_next_archived_file (entry
->the_bfd
, 0);
1043 /* Don't check this file if it's already been read in
1046 if (!archive
->usrdata
||
1047 !((lang_input_statement_type
*) (archive
->usrdata
))->loaded
)
1050 if (gnu960_check_format (archive
, bfd_object
))
1052 if (bfd_check_format (archive
, bfd_object
))
1055 register struct lang_input_statement_struct
*subentry
;
1057 subentry
= decode_library_subfile (entry
,
1060 archive
->usrdata
= (PTR
) subentry
;
1063 if (subentry
->loaded
== false)
1065 read_entry_symbols (archive
, subentry
);
1067 if (subfile_wanted_p (subentry
) == true)
1069 enter_file_symbols (subentry
);
1072 prev
->chain
= subentry
;
1074 entry
->subfiles
= subentry
;
1078 subentry
->loaded
= true;
1083 archive
= bfd_openr_next_archived_file (entry
->the_bfd
, archive
);
1090 /* ENTRY is an entry for a file inside an archive
1091 Its symbols have been read into core, but not entered into the
1093 Return nonzero if we ought to load this file */
1096 subfile_wanted_p (entry
)
1097 struct lang_input_statement_struct
*entry
;
1101 if (entry
->symbol_count
== 0)
1104 for (q
= entry
->asymbols
; *q
; q
++)
1108 /* If the symbol has an interesting definition, we could
1109 potentially want it. */
1111 if (p
->flags
& BSF_INDIRECT
)
1113 /** add_indirect(q);*/
1116 if (bfd_is_com_section (p
->section
)
1117 || (p
->flags
& BSF_GLOBAL
)
1118 || (p
->flags
& BSF_INDIRECT
)
1119 || (p
->flags
& BSF_WEAK
))
1121 register ldsym_type
*sp
= ldsym_get_soft (p
->name
);
1123 /* If this symbol has not been hashed,
1124 we can't be looking for it. */
1125 if (sp
!= (ldsym_type
*) NULL
1126 && sp
->sdefs_chain
== (asymbol
**) NULL
)
1130 /* A weak symbol is not considered to be a reference
1131 when pulling files out of an archive. An unresolved
1132 weak symbol winds up with a value of zero. See the
1133 SVR4 ABI, p. 4-27. */
1134 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
1136 else if (sp
->srefs_chain
== (asymbol
**) NULL
)
1143 for (ptr
= sp
->srefs_chain
;
1144 ptr
!= (asymbol
**) NULL
;
1145 ptr
= (asymbol
**) ((*ptr
)->udata
))
1147 if (((*ptr
)->flags
& BSF_WEAK
) == 0)
1157 /* This is a symbol we are looking for. It is
1158 either common or not yet defined. If this is a
1159 common symbol, then if the symbol in the object
1160 file is common, we need to combine sizes. But if
1161 we already have a common symbol, and the symbol
1162 in the object file is not common, we don't want
1163 the object file: it is providing a definition for
1164 a symbol that we already have a definition for
1165 (this is the else condition below). */
1166 if (bfd_is_com_section (p
->section
))
1169 /* If the symbol in the table is a constructor, we won't to
1170 anything fancy with it */
1171 if ((sp
->flags
& SYM_CONSTRUCTOR
) == 0)
1173 /* This libary member has something to
1174 say about this element. We should
1175 remember if its a new size */
1176 /* Move something from the ref list to the com list */
1177 if (sp
->scoms_chain
)
1179 /* Already a common symbol, maybe update it */
1180 if (p
->value
> (*(sp
->scoms_chain
))->value
)
1182 (*(sp
->scoms_chain
))->value
= p
->value
;
1187 /* Take a value from the ref chain
1188 Here we are moving a symbol from the owning bfd
1189 to another bfd. We must set up the
1190 common_section portion of the bfd thing */
1194 sp
->scoms_chain
= sp
->srefs_chain
;
1196 (asymbol
**) ((*(sp
->srefs_chain
))->udata
);
1197 (*(sp
->scoms_chain
))->udata
= (PTR
) NULL
;
1199 (*(sp
->scoms_chain
))->section
= p
->section
;
1200 (*(sp
->scoms_chain
))->flags
= 0;
1201 /* Remember the size of this item */
1202 sp
->scoms_chain
[0]->value
= p
->value
;
1204 undefined_global_sym_count
--;
1207 asymbol
*com
= *(sp
->scoms_chain
);
1209 if (((lang_input_statement_type
*)
1210 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
==
1213 ((lang_input_statement_type
*)
1214 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
=
1215 bfd_make_section_old_way (bfd_asymbol_bfd (com
), "COMMON");
1219 ASSERT (p
->udata
== 0);
1221 else if (sp
->scoms_chain
== (asymbol
**) NULL
)
1225 info_msg ("%I needed due to %s\n", entry
, sp
->name
);
1241 ldsym_type
*lookup
= ldsym_get (text
);
1242 lookup
->flags
|= SYM_Y
;