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
;
119 static boolean check_for_scripts_dir
PARAMS ((char *dir
));
120 static void read_entry_symbols
121 PARAMS ((bfd
*desc
, struct lang_input_statement_struct
*entry
));
122 static void enter_file_symbols
PARAMS ((lang_input_statement_type
*entry
));
123 static void search_library
PARAMS ((struct lang_input_statement_struct
*));
124 static lang_input_statement_type
*decode_library_subfile
125 PARAMS ((struct lang_input_statement_struct
*library_entry
,
126 bfd
*subfile_offset
));
127 static void linear_library
PARAMS ((struct lang_input_statement_struct
*));
128 static void symdef_library
PARAMS ((struct lang_input_statement_struct
*));
129 static void clear_syms
PARAMS ((struct lang_input_statement_struct
*entry
,
131 static boolean subfile_wanted_p
132 PARAMS ((struct lang_input_statement_struct
*));
134 extern int main
PARAMS ((int, char **));
143 program_name
= argv
[0];
147 /* Initialize the data about options. */
150 trace_files
= trace_file_tries
= false;
152 config
.relocateable_output
= false;
153 command_line
.force_common_definition
= false;
155 init_bfd_error_vector ();
157 ldfile_add_arch ("");
159 config
.make_executable
= true;
160 force_make_executable
= false;
162 /* Initialize the cumulative counts of symbols. */
163 undefined_global_sym_count
= 0;
164 multiple_def_count
= 0;
167 config
.magic_demand_paged
= true;
168 config
.text_read_only
= true;
169 config
.make_executable
= true;
171 emulation
= get_emulation (argc
, argv
);
172 ldemul_choose_mode (emulation
);
173 default_target
= ldemul_choose_target ();
175 ldemul_before_parse ();
176 lang_has_input_file
= false;
177 parse_args (argc
, argv
);
179 /* This essentially adds another -L directory so this must be done after
180 the -L's in argv have been processed. */
183 if (had_script
== false)
185 /* Read the emulation's appropriate default script. */
187 char *s
= ldemul_get_script (&isfile
);
191 /* sizeof counts the terminating NUL. */
192 size_t size
= strlen (s
) + sizeof ("-T ");
193 char *buf
= (char *) ldmalloc(size
);
194 sprintf (buf
, "-T %s", s
);
202 if (config
.relocateable_output
&& command_line
.relax
)
204 einfo ("%P%F: -relax and -r may not be used together\n");
208 if (lang_has_input_file
== false)
210 einfo ("%P%F: no input files\n");
215 info_msg ("%P: mode %s\n", emulation
);
218 ldemul_after_parse ();
221 if (config
.map_filename
)
223 if (strcmp (config
.map_filename
, "-") == 0)
225 config
.map_file
= stdout
;
229 config
.map_file
= fopen (config
.map_filename
, FOPEN_WT
);
230 if (config
.map_file
== (FILE *) NULL
)
232 einfo ("%P%F: cannot open map file %s: %E\n",
233 config
.map_filename
);
241 /* Print error messages for any missing symbols, for any warning
242 symbols, and possibly multiple definitions */
245 if (config
.text_read_only
)
247 /* Look for a text section and mark the readonly attribute in it */
248 asection
*found
= bfd_get_section_by_name (output_bfd
, ".text");
250 if (found
!= (asection
*) NULL
)
252 found
->flags
|= SEC_READONLY
;
256 if (config
.relocateable_output
)
257 output_bfd
->flags
&= ~EXEC_P
;
259 output_bfd
->flags
|= EXEC_P
;
263 /* Even if we're producing relocateable output, some non-fatal errors should
264 be reported in the exit status. (What non-fatal errors, if any, do we
265 want to ignore for relocateable output?) */
267 if (config
.make_executable
== false && force_make_executable
== false)
269 if (trace_files
== true)
271 einfo ("%P: link errors found, deleting executable `%s'\n",
275 if (output_bfd
->iostream
)
276 fclose ((FILE *) (output_bfd
->iostream
));
278 unlink (output_filename
);
283 bfd_close (output_bfd
);
290 /* We need to find any explicitly given emulation in order to initialize the
291 state that's needed by the lex&yacc argument parser (parse_args). */
294 get_emulation (argc
, argv
)
302 check_v960 (argc
, argv
);
303 emulation
= "gld960";
304 for (i
= 1; i
< argc
; i
++)
306 if (!strcmp (argv
[i
], "-Fcoff"))
308 emulation
= "lnk960";
309 output_flavor
= BFD_COFF_FORMAT
;
314 emulation
= (char *) getenv (EMULATION_ENVIRON
);
315 if (emulation
== NULL
)
316 emulation
= DEFAULT_EMULATION
;
319 for (i
= 1; i
< argc
; i
++)
321 if (!strncmp (argv
[i
], "-m", 2))
323 if (argv
[i
][2] == '\0')
328 emulation
= argv
[i
+ 1];
333 einfo("%P%F: missing argument to -m\n");
336 else if (strcmp (argv
[i
], "-mips1") == 0
337 || strcmp (argv
[i
], "-mips2") == 0
338 || strcmp (argv
[i
], "-mips3") == 0)
340 /* FIXME: The arguments -mips1, -mips2 and -mips3 are
341 passed to the linker by some MIPS compilers. They
342 generally tell the linker to use a slightly different
343 library path. Perhaps someday these should be
344 implemented as emulations; until then, we just ignore
345 the arguments and hope that nobody ever creates
346 emulations named ips1, ips2 or ips3. */
351 emulation
= &argv
[i
][2];
359 /* If directory DIR contains an "ldscripts" subdirectory,
360 add DIR to the library search path and return true,
361 else return false. */
364 check_for_scripts_dir (dir
)
372 dirlen
= strlen (dir
);
373 /* sizeof counts the terminating NUL. */
374 buf
= (char *) ldmalloc (dirlen
+ sizeof("/ldscripts"));
375 sprintf (buf
, "%s/ldscripts", dir
);
377 res
= stat (buf
, &s
) == 0 && S_ISDIR (s
.st_mode
);
380 ldfile_add_library_path (dir
);
384 /* Set the default directory for finding script files.
385 Libraries will be searched for here too, but that's ok.
386 We look for the "ldscripts" directory in:
388 SCRIPTDIR (passed from Makefile)
389 the dir where this program is (for using it from the build tree)
390 the dir where this program is/../lib (for installing the tool suite elsewhere) */
398 if (check_for_scripts_dir (SCRIPTDIR
))
399 return; /* We've been installed normally. */
401 /* Look for "ldscripts" in the dir where our binary is. */
402 end
= strrchr (program_name
, '/');
405 dirlen
= end
- program_name
;
406 /* Make a copy of program_name in dir.
407 Leave room for later "/../lib". */
408 dir
= (char *) ldmalloc (dirlen
+ 8);
409 strncpy (dir
, program_name
, dirlen
);
415 dir
= (char *) ldmalloc (dirlen
+ 8);
419 if (check_for_scripts_dir (dir
))
420 return; /* Don't free dir. */
422 /* Look for "ldscripts" in <the dir where our binary is>/../lib. */
423 strcpy (dir
+ dirlen
, "/../lib");
424 if (check_for_scripts_dir (dir
))
427 free (dir
); /* Well, we tried. */
431 read_entry_symbols (desc
, entry
)
433 struct lang_input_statement_struct
*entry
;
435 if (entry
->asymbols
== (asymbol
**) NULL
)
437 bfd_size_type table_size
= get_symtab_upper_bound (desc
);
439 entry
->asymbols
= (asymbol
**) ldmalloc (table_size
);
440 entry
->symbol_count
= bfd_canonicalize_symtab (desc
, entry
->asymbols
);
445 * turn this item into a reference
452 asymbol
*sym
= *nlist_p
;
456 /* FIXME: Why do we clear the flags here? This used to set the
457 flags to zero, but we must not clear BSF_WEAK. */
458 sym
->flags
&= BSF_WEAK
;
460 sym
->section
= &bfd_und_section
;
461 sym
->udata
= (PTR
) (sp
->srefs_chain
);
462 sp
->srefs_chain
= nlist_p
;
466 This function is called for each name which is seen which has a global
467 scope. It enters the name into the global symbol table in the correct
468 symbol on the correct chain. Remember that each ldsym_type has three
469 chains attatched, one of all definitions of a symbol, one of all
470 references of a symbol and one of all common definitions of a symbol.
472 When the function is over, the supplied is left connected to the bfd
473 to which is was born, with its udata field pointing to the next member
474 on the chain in which it has been inserted.
476 A certain amount of jigery pokery is necessary since commons come
477 along and upset things, we only keep one item in the common chain; the
478 one with the biggest size seen sofar. When another common comes along
479 it either bumps the previous definition into the ref chain, since it
480 is bigger, or gets turned into a ref on the spot since the one on the
481 common chain is already bigger. If a real definition comes along then
482 the common gets bumped off anyway.
484 Whilst all this is going on we keep a count of the number of multiple
485 definitions seen, undefined global symbols and pending commons.
489 enter_global_ref (nlist_p
, name
)
490 asymbol
** nlist_p
; /* pointer into symbol table from incoming bfd */
491 CONST
char *name
; /* name of symbol in linker table */
493 asymbol
*sym
= *nlist_p
;
496 /* Lookup the name from the incoming bfd's symbol table in the
497 linker's global symbol table */
500 flagword this_symbol_flags
= sym
->flags
;
502 sp
= ldsym_get (name
);
505 /* If this symbol already has udata, it means that something strange
508 The strange thing is that we've had an undefined symbol resolved by
509 an alias, but the thing the alias defined wasn't in the file. So
510 the symbol got a udata entry, but the file wasn't loaded. Then
511 later on the file was loaded, but we don't need to do this
519 if (this_symbol_flags
& BSF_CONSTRUCTOR
)
521 /* Add this constructor to the list we keep */
522 ldlang_add_constructor (sp
);
523 /* Turn any commons into refs */
524 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
526 refize (sp
, sp
->scoms_chain
);
530 else if ((sym
->flags
& BSF_WEAK
) != 0
531 && (sp
->sdefs_chain
!= NULL
|| sp
->scoms_chain
!= NULL
))
533 /* SYM is a weak symbol for which we already have a definition.
534 Just ignore it. The UnixWare linker is order dependent: if a
535 global symbol follows a weak symbol it gives an error; if a
536 weak symbol follows a global symbol it does not. We are
541 if (bfd_is_com_section (sym
->section
))
543 /* If we have a definition of this symbol already then
544 this common turns into a reference. Also we only
545 ever point to the largest common, so if we
546 have a common, but it's bigger that the new symbol
547 the turn this into a reference too. */
550 /* This is a common symbol, but we already have a definition
551 for it, so just link it into the ref chain as if
552 it were a reference */
553 if (config
.warn_common
)
554 multiple_warn("%C: warning: common of `%s' overridden by definition\n",
556 "%C: warning: defined here\n",
558 refize (sp
, nlist_p
);
560 else if (sp
->scoms_chain
)
562 /* If we have a previous common, keep only the biggest */
563 if ((*(sp
->scoms_chain
))->value
> sym
->value
)
565 /* other common is bigger, throw this one away */
566 if (config
.warn_common
)
567 multiple_warn("%C: warning: common of `%s' overridden by larger common\n",
569 "%C: warning: larger common is here\n",
571 refize (sp
, nlist_p
);
573 else if (sp
->scoms_chain
!= nlist_p
)
575 /* other common is smaller, throw that away */
576 if (config
.warn_common
)
578 if ((*(sp
->scoms_chain
))->value
< sym
->value
)
579 multiple_warn("%C: warning: common of `%s' overriding smaller common\n",
581 "%C: warning: smaller common is here\n",
584 multiple_warn("%C: warning: multiple common of `%s'\n",
586 "%C: warning: previous common is here\n",
589 refize (sp
, sp
->scoms_chain
);
590 sp
->scoms_chain
= nlist_p
;
595 /* This is the first time we've seen a common, so remember it
596 - if it was undefined before, we know it's defined now. If
597 the symbol has been marked as really being a constructor,
598 then treat this as a ref. */
599 if (sp
->flags
& SYM_CONSTRUCTOR
)
601 /* Turn this into a ref */
602 refize (sp
, nlist_p
);
606 /* treat like a common */
608 undefined_global_sym_count
--;
611 sp
->scoms_chain
= nlist_p
;
615 else if (sym
->section
!= &bfd_und_section
)
617 /* This is the definition of a symbol, add to def chain */
618 if (sp
->sdefs_chain
&& (*(sp
->sdefs_chain
))->section
!= sym
->section
)
620 multiple_warn("%X%C: multiple definition of `%s'\n",
622 "%X%C: first defined here\n",
624 multiple_def_count
++;
628 sym
->udata
= (PTR
) (sp
->sdefs_chain
);
629 sp
->sdefs_chain
= nlist_p
;
632 /* A definition overrides a common symbol */
633 if (sp
->scoms_chain
!= NULL
)
635 if (config
.warn_common
)
636 multiple_warn("%C: warning: definition of `%s' overriding common\n",
638 "%C: warning: common is here\n",
640 refize (sp
, sp
->scoms_chain
);
644 else if (sp
->srefs_chain
&& relaxing
== false)
646 /* If previously was undefined, then remember as defined */
647 undefined_global_sym_count
--;
652 if (sp
->scoms_chain
== (asymbol
**) NULL
653 && sp
->srefs_chain
== (asymbol
**) NULL
654 && sp
->sdefs_chain
== (asymbol
**) NULL
)
656 /* And it's the first time we've seen it */
657 undefined_global_sym_count
++;
660 refize (sp
, nlist_p
);
664 ASSERT (sp
->sdefs_chain
== 0 || sp
->scoms_chain
== 0);
665 ASSERT (sp
->scoms_chain
== 0 || (*(sp
->scoms_chain
))->udata
== 0);
669 enter_file_symbols (entry
)
670 lang_input_statement_type
*entry
;
674 entry
->common_section
=
675 bfd_make_section_old_way (entry
->the_bfd
, "COMMON");
676 entry
->common_section
->flags
= SEC_NEVER_LOAD
;
677 ldlang_add_file (entry
);
680 if (trace_files
|| trace_file_tries
)
682 info_msg ("%I\n", entry
);
685 total_symbols_seen
+= entry
->symbol_count
;
687 if (entry
->symbol_count
)
689 for (q
= entry
->asymbols
; *q
; q
++)
693 if (had_y
&& p
->name
)
695 /* look up the symbol anyway to see if the trace bit was
697 ldsym_type
*s
= ldsym_get (p
->name
);
698 if (s
->flags
& SYM_Y
)
700 einfo ("%B: %s %T\n", entry
->the_bfd
,
701 p
->section
== &bfd_und_section
? "reference to" : "definition of ",
706 if (p
->section
== &bfd_ind_section
707 || (p
->flags
& BSF_INDIRECT
) != 0)
711 else if (p
->flags
& BSF_WARNING
)
715 else if (bfd_is_com_section (p
->section
))
717 enter_global_ref (q
, p
->name
);
719 /* If this is not bfd_com_section, make sure we have a
720 section of this name in the bfd. We need this
721 because some targets that use multiple common
722 sections do not actually put the common section in
723 the BFD, but we need it there so that a wildcard
724 specification in the linker script (e.g.,
725 *(.scommon)) will find the section and attach it to
726 the right output section. When an section is chosed
727 for the common symbols (in lang_common) that section
728 must have been correctly given an output section.
729 For normal common symbols we just use
730 entry->common_section, initialized above. */
731 if (p
->section
!= &bfd_com_section
732 && p
->section
->owner
!= entry
->the_bfd
)
733 bfd_make_section (entry
->the_bfd
,
734 bfd_get_section_name (p
->section
->owner
,
737 else if (p
->section
== &bfd_und_section
738 || (p
->flags
& BSF_GLOBAL
)
739 || (p
->flags
& BSF_CONSTRUCTOR
)
740 || (p
->flags
& BSF_WEAK
))
742 enter_global_ref (q
, p
->name
);
749 /* Searching libraries */
751 /* Search the library ENTRY, already open on descriptor DESC.
752 This means deciding which library members to load,
753 making a chain of `struct lang_input_statement_struct' for those members,
754 and entering their global symbols in the hash table. */
757 search_library (entry
)
758 struct lang_input_statement_struct
*entry
;
761 /* No need to load a library if no undefined symbols */
762 if (!undefined_global_sym_count
)
765 if (bfd_has_map (entry
->the_bfd
))
766 symdef_library (entry
);
768 linear_library (entry
);
775 gnu960_check_format (abfd
, format
)
781 if ((bfd_check_format (abfd
, format
) == true)
782 && (abfd
->xvec
->flavour
== output_flavor
))
794 ldmain_open_file_read_symbol (entry
)
795 struct lang_input_statement_struct
*entry
;
797 if (entry
->asymbols
== (asymbol
**) NULL
798 && entry
->real
== true
799 && entry
->filename
!= (char *) NULL
)
801 ldfile_open_file (entry
);
805 if (gnu960_check_format (entry
->the_bfd
, bfd_object
))
807 if (bfd_check_format (entry
->the_bfd
, bfd_object
))
810 entry
->the_bfd
->usrdata
= (PTR
) entry
;
813 read_entry_symbols (entry
->the_bfd
, entry
);
815 /* look through the sections in the file and see if any of them
817 ldlang_check_for_constructors (entry
);
819 enter_file_symbols (entry
);
822 else if (gnu960_check_format (entry
->the_bfd
, bfd_archive
))
824 else if (bfd_check_format (entry
->the_bfd
, bfd_archive
))
827 entry
->the_bfd
->usrdata
= (PTR
) entry
;
829 entry
->subfiles
= (lang_input_statement_type
*) NULL
;
830 search_library (entry
);
834 einfo ("%F%B: malformed input file (not rel or archive) \n",
841 /* Construct and return a lang_input_statement_struct for a library member.
842 The library's lang_input_statement_struct is library_entry,
843 and the library is open on DESC.
844 SUBFILE_OFFSET is the byte index in the library of this member's header.
845 We store the length of the member into *LENGTH_LOC. */
847 static lang_input_statement_type
*
848 decode_library_subfile (library_entry
, subfile_offset
)
849 struct lang_input_statement_struct
*library_entry
;
852 register struct lang_input_statement_struct
*subentry
;
855 /* First, check if we already have a loaded
856 lang_input_statement_struct for this library subfile. If so,
857 just return it. Otherwise, allocate some space and build a new one. */
859 if (subfile_offset
->usrdata
860 && ((struct lang_input_statement_struct
*) subfile_offset
->usrdata
)->
863 subentry
= (struct lang_input_statement_struct
*) subfile_offset
->usrdata
;
868 (struct lang_input_statement_struct
*)
869 ldmalloc ((bfd_size_type
) (sizeof (struct lang_input_statement_struct
)));
871 subentry
->filename
= subfile_offset
->filename
;
872 subentry
->local_sym_name
= subfile_offset
->filename
;
873 subentry
->asymbols
= 0;
874 subentry
->the_bfd
= subfile_offset
;
875 subentry
->subfiles
= 0;
877 subentry
->superfile
= library_entry
;
878 subentry
->is_archive
= false;
880 subentry
->just_syms_flag
= false;
881 subentry
->loaded
= false;
888 clear_syms (entry
, offset
)
889 struct lang_input_statement_struct
*entry
;
893 symindex indx
= bfd_get_next_mapent (entry
->the_bfd
,
897 while (indx
!= BFD_NO_MORE_SYMBOLS
)
899 if (car
->file_offset
== offset
)
903 indx
= bfd_get_next_mapent (entry
->the_bfd
, indx
, &car
);
908 /* Search a library that has a map
911 symdef_library (entry
)
912 struct lang_input_statement_struct
*entry
;
915 register struct lang_input_statement_struct
*prev
= 0;
917 boolean not_finished
= true;
919 while (not_finished
== true)
921 carsym
*exported_library_name
;
922 bfd
*prev_archive_member_bfd
= 0;
924 symindex idx
= bfd_get_next_mapent (entry
->the_bfd
,
926 &exported_library_name
);
928 not_finished
= false;
930 while (idx
!= BFD_NO_MORE_SYMBOLS
&& undefined_global_sym_count
)
932 if (exported_library_name
->name
)
934 ldsym_type
*sp
= ldsym_get_soft (exported_library_name
->name
);
936 /* If we find a symbol that appears to be needed, think carefully
937 about the archive member that the symbol is in. */
938 /* So - if it exists, and is referenced somewhere and is
940 if (sp
&& sp
->srefs_chain
&& !sp
->sdefs_chain
)
942 bfd
*archive_member_bfd
=
943 bfd_get_elt_at_index (entry
->the_bfd
, (int) idx
);
944 struct lang_input_statement_struct
*archive_member_lang_input_statement_struct
;
947 if (archive_member_bfd
948 && gnu960_check_format (archive_member_bfd
, bfd_object
))
950 if (archive_member_bfd
951 && bfd_check_format (archive_member_bfd
, bfd_object
))
954 /* Don't think carefully about any archive member
955 more than once in a given pass. */
956 if (prev_archive_member_bfd
!= archive_member_bfd
)
959 prev_archive_member_bfd
= archive_member_bfd
;
961 /* Read the symbol table of the archive member. */
963 if (archive_member_bfd
->usrdata
!= (PTR
) NULL
)
966 archive_member_lang_input_statement_struct
=
967 ((lang_input_statement_type
*)
968 archive_member_bfd
->usrdata
);
972 archive_member_lang_input_statement_struct
=
973 decode_library_subfile (entry
,
975 archive_member_bfd
->usrdata
=
976 (PTR
) archive_member_lang_input_statement_struct
;
979 if (archive_member_lang_input_statement_struct
== 0)
981 einfo ("%F%I contains invalid archive member %s\n",
985 if (archive_member_lang_input_statement_struct
->loaded
== false)
987 read_entry_symbols (archive_member_bfd
,
988 archive_member_lang_input_statement_struct
);
990 /* Now scan the symbol table and decide
992 if (subfile_wanted_p (archive_member_lang_input_statement_struct
)
996 /* This member is needed; load it.
997 Since we are loading something on
998 this pass, we must make another
999 pass through the symdef data. */
1000 not_finished
= true;
1002 enter_file_symbols (archive_member_lang_input_statement_struct
);
1005 prev
->chain
= archive_member_lang_input_statement_struct
;
1007 entry
->subfiles
= archive_member_lang_input_statement_struct
;
1010 prev
= archive_member_lang_input_statement_struct
;
1013 /* Clear out this member's symbols
1014 from the symdef data so that
1015 following passes won't waste time
1018 exported_library_name
->file_offset
);
1019 archive_member_lang_input_statement_struct
->loaded
= true;
1026 idx
= bfd_get_next_mapent (entry
->the_bfd
, idx
,
1027 &exported_library_name
);
1033 linear_library (entry
)
1034 struct lang_input_statement_struct
*entry
;
1036 boolean more_to_do
= true;
1037 register struct lang_input_statement_struct
*prev
= 0;
1039 if (entry
->complained
== false)
1041 if (entry
->the_bfd
->xvec
->flavour
!= bfd_target_ieee_flavour
)
1044 /* IEEE can use table of contents, so this message is bogus */
1045 einfo ("%P: library %s has bad table of contents, rerun ranlib\n",
1046 entry
->the_bfd
->filename
);
1048 entry
->complained
= true;
1054 bfd
*archive
= bfd_openr_next_archived_file (entry
->the_bfd
, 0);
1059 /* Don't check this file if it's already been read in
1062 if (!archive
->usrdata
||
1063 !((lang_input_statement_type
*) (archive
->usrdata
))->loaded
)
1066 if (gnu960_check_format (archive
, bfd_object
))
1068 if (bfd_check_format (archive
, bfd_object
))
1071 register struct lang_input_statement_struct
*subentry
;
1073 subentry
= decode_library_subfile (entry
,
1076 archive
->usrdata
= (PTR
) subentry
;
1079 if (subentry
->loaded
== false)
1081 read_entry_symbols (archive
, subentry
);
1083 if (subfile_wanted_p (subentry
) == true)
1085 enter_file_symbols (subentry
);
1088 prev
->chain
= subentry
;
1090 entry
->subfiles
= subentry
;
1094 subentry
->loaded
= true;
1099 archive
= bfd_openr_next_archived_file (entry
->the_bfd
, archive
);
1106 /* ENTRY is an entry for a file inside an archive
1107 Its symbols have been read into core, but not entered into the
1109 Return nonzero if we ought to load this file */
1112 subfile_wanted_p (entry
)
1113 struct lang_input_statement_struct
*entry
;
1117 if (entry
->symbol_count
== 0)
1120 for (q
= entry
->asymbols
; *q
; q
++)
1124 /* If the symbol has an interesting definition, we could
1125 potentially want it. */
1127 if (p
->flags
& BSF_INDIRECT
)
1129 /** add_indirect(q);*/
1132 if (bfd_is_com_section (p
->section
)
1133 || (p
->flags
& BSF_GLOBAL
)
1134 || (p
->flags
& BSF_INDIRECT
)
1135 || (p
->flags
& BSF_WEAK
))
1137 register ldsym_type
*sp
= ldsym_get_soft (p
->name
);
1139 /* If this symbol has not been hashed,
1140 we can't be looking for it. */
1141 if (sp
!= (ldsym_type
*) NULL
1142 && sp
->sdefs_chain
== (asymbol
**) NULL
)
1146 /* A weak symbol is not considered to be a reference
1147 when pulling files out of an archive. An unresolved
1148 weak symbol winds up with a value of zero. See the
1149 SVR4 ABI, p. 4-27. */
1150 if (sp
->scoms_chain
!= (asymbol
**) NULL
)
1152 else if (sp
->srefs_chain
== (asymbol
**) NULL
)
1159 for (ptr
= sp
->srefs_chain
;
1160 ptr
!= (asymbol
**) NULL
;
1161 ptr
= (asymbol
**) ((*ptr
)->udata
))
1163 if (((*ptr
)->flags
& BSF_WEAK
) == 0)
1173 /* This is a symbol we are looking for. It is
1174 either common or not yet defined. If this is a
1175 common symbol, then if the symbol in the object
1176 file is common, we need to combine sizes. But if
1177 we already have a common symbol, and the symbol
1178 in the object file is not common, we don't want
1179 the object file: it is providing a definition for
1180 a symbol that we already have a definition for
1181 (this is the else condition below). */
1182 if (bfd_is_com_section (p
->section
))
1185 /* If the symbol in the table is a constructor, we won't to
1186 anything fancy with it */
1187 if ((sp
->flags
& SYM_CONSTRUCTOR
) == 0)
1189 /* This libary member has something to
1190 say about this element. We should
1191 remember if its a new size */
1192 /* Move something from the ref list to the com list */
1193 if (sp
->scoms_chain
)
1195 /* Already a common symbol, maybe update it */
1196 if (p
->value
> (*(sp
->scoms_chain
))->value
)
1198 (*(sp
->scoms_chain
))->value
= p
->value
;
1203 /* Take a value from the ref chain
1204 Here we are moving a symbol from the owning bfd
1205 to another bfd. We must set up the
1206 common_section portion of the bfd thing */
1210 sp
->scoms_chain
= sp
->srefs_chain
;
1212 (asymbol
**) ((*(sp
->srefs_chain
))->udata
);
1213 (*(sp
->scoms_chain
))->udata
= (PTR
) NULL
;
1215 (*(sp
->scoms_chain
))->section
= p
->section
;
1216 (*(sp
->scoms_chain
))->flags
= 0;
1217 /* Remember the size of this item */
1218 sp
->scoms_chain
[0]->value
= p
->value
;
1220 undefined_global_sym_count
--;
1223 asymbol
*com
= *(sp
->scoms_chain
);
1225 if (((lang_input_statement_type
*)
1226 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
==
1229 ((lang_input_statement_type
*)
1230 (bfd_asymbol_bfd (com
)->usrdata
))->common_section
=
1231 bfd_make_section_old_way (bfd_asymbol_bfd (com
), "COMMON");
1234 /* If the symbol is not in the generic
1235 common section, we must make sure the
1236 BFD has a section to hang it on to. */
1237 if (com
->section
!= &bfd_com_section
1238 && (com
->section
->owner
1239 != bfd_asymbol_bfd (com
)))
1241 (bfd_asymbol_bfd (com
),
1242 bfd_get_section_name (bfd_asymbol_bfd (com
),
1246 ASSERT (p
->udata
== 0);
1248 else if (sp
->scoms_chain
== (asymbol
**) NULL
)
1252 info_msg ("%I needed due to %s\n", entry
, sp
->name
);
1268 ldsym_type
*lookup
= ldsym_get (text
);
1269 lookup
->flags
|= SYM_Y
;