* configure.in, hosts/delta68.h, config/delta68.mh: Add stuff for
[binutils-gdb.git] / ld / ldmain.c
1 /* Copyright (C) 1991 Free Software Foundation, Inc.
2 Written by Steve Chamberlain steve@cygnus.com
3
4 This file is part of GLD, the Gnu Linker.
5
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)
9 any later version.
10
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.
15
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. */
19
20
21 #include "bfd.h"
22 #include "sysdep.h"
23
24 #include "config.h"
25 #include "ld.h"
26 #include "ldmain.h"
27 #include "ldmisc.h"
28 #include "ldwrite.h"
29 #include "ldgram.h"
30 #include "ldsym.h"
31 #include "ldlang.h"
32 #include "ldemul.h"
33 #include "ldlex.h"
34 #include "ldfile.h"
35 #include "ldindr.h"
36 #include "ldwarn.h"
37 #include "ldctor.h"
38 #include "lderror.h"
39
40 /* IMPORTS */
41 extern boolean lang_has_input_file;
42 extern boolean trace_files;
43
44 /* EXPORTS */
45
46 char *default_target;
47 char *output_filename = "a.out";
48
49 /* Name this program was invoked by. */
50 char *program_name;
51
52 /* The file that we're creating */
53 bfd *output_bfd = 0;
54
55 extern boolean option_v;
56
57 /* set if -y on the command line */
58 int had_y;
59
60 /* The local symbol prefix */
61 char lprefix = 'L';
62
63 /* Count the number of global symbols multiply defined. */
64 int multiple_def_count;
65
66 /* Count the number of symbols defined through common declarations.
67 This count is referenced in symdef_library, linear_library, and
68 modified by enter_global_ref.
69
70 It is incremented when a symbol is created as a common, and
71 decremented when the common declaration is overridden
72
73 Another way of thinking of it is that this is a count of
74 all ldsym_types with a ->scoms field */
75
76 unsigned int commons_pending;
77
78 /* Count the number of global symbols referenced and not defined.
79 common symbols are not included in this count. */
80
81 unsigned int undefined_global_sym_count;
82
83 /* Count the number of warning symbols encountered. */
84 int warning_count;
85
86 /* have we had a load script ? */
87 extern boolean had_script;
88
89 /* Nonzero means print names of input files as processed. */
90 boolean trace_files;
91
92 /* 1 => write load map. */
93 boolean write_map;
94
95
96 int unix_relocate;
97
98 #ifdef GNU960
99 /* Indicates whether output file will be b.out (default) or coff */
100 enum target_flavour output_flavor = BFD_BOUT_FORMAT;
101
102 #endif
103
104 /* Force the make_executable to be output, even if there are non-fatal
105 errors */
106 boolean force_make_executable;
107
108 /* A count of the total number of local symbols ever seen - by adding
109 the symbol_count field of each newly read afile.*/
110
111 unsigned int total_symbols_seen;
112
113 /* A count of the number of read files - the same as the number of elements
114 in file_chain
115 */
116 unsigned int total_files_seen;
117
118 /* IMPORTS */
119 args_type command_line;
120 ld_config_type config;
121 void
122 main (argc, argv)
123 char **argv;
124 int argc;
125 {
126 char *emulation;
127
128 program_name = argv[0];
129 output_filename = "a.out";
130
131 bfd_init ();
132
133 #ifdef GNU960
134 {
135 int i;
136
137 check_v960 (argc, argv);
138 emulation = "gld960";
139 for (i = 1; i < argc; i++)
140 {
141 if (!strcmp (argv[i], "-Fcoff"))
142 {
143 emulation = "lnk960";
144 output_flavor = BFD_COFF_FORMAT;
145 break;
146 }
147 }
148 }
149 #else
150 emulation = (char *) getenv (EMULATION_ENVIRON);
151 #endif
152
153 /* Initialize the data about options. */
154
155
156 trace_files = false;
157 write_map = false;
158 config.relocateable_output = false;
159 unix_relocate = 0;
160 command_line.force_common_definition = false;
161
162 init_bfd_error_vector ();
163 ldsym_init ();
164 ldfile_add_arch ("");
165
166 config.make_executable = true;
167 force_make_executable = false;
168
169
170 /* Initialize the cumulative counts of symbols. */
171 undefined_global_sym_count = 0;
172 warning_count = 0;
173 multiple_def_count = 0;
174 commons_pending = 0;
175
176 config.magic_demand_paged = true;
177 config.text_read_only = true;
178 config.make_executable = true;
179 if (emulation == (char *) NULL)
180 {
181 emulation = DEFAULT_EMULATION;
182 }
183
184 ldemul_choose_mode (emulation);
185 default_target = ldemul_choose_target ();
186 lang_init ();
187 ldemul_before_parse ();
188 lang_has_input_file = false;
189 parse_args (argc, argv);
190
191 if (config.relocateable_output && command_line.relax)
192 {
193 einfo ("%P%F: -relax and -r may not be used together\n");
194 }
195 lang_final ();
196
197 if (trace_files)
198 {
199 info ("%P: mode %s\n", emulation);
200 }
201 if (lang_has_input_file == false)
202 {
203 einfo ("%P%F: No input files\n");
204 }
205
206 ldemul_after_parse ();
207
208
209 if (config.map_filename)
210 {
211 if (strcmp (config.map_filename, "-") == 0)
212 {
213 config.map_file = stdout;
214 }
215 else
216 {
217 config.map_file = fopen (config.map_filename, FOPEN_WT);
218 if (config.map_file == (FILE *) NULL)
219 {
220 einfo ("%P%F: can't open map file %s\n",
221 config.map_filename);
222 }
223 }
224 }
225
226
227 lang_process ();
228
229 /* Print error messages for any missing symbols, for any warning
230 symbols, and possibly multiple definitions */
231
232
233 if (config.text_read_only)
234 {
235 /* Look for a text section and mark the readonly attribute in it */
236 asection *found = bfd_get_section_by_name (output_bfd, ".text");
237
238 if (found != (asection *) NULL)
239 {
240 found->flags |= SEC_READONLY;
241 }
242 }
243
244 if (config.relocateable_output)
245 output_bfd->flags &= ~EXEC_P;
246 else
247 output_bfd->flags |= EXEC_P;
248
249 ldwrite ();
250
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?) */
254
255 if (config.make_executable == false && force_make_executable == false)
256 {
257 if (trace_files == true)
258 {
259 einfo ("%P: Link errors found, deleting executable `%s'\n",
260 output_filename);
261 }
262
263 if (output_bfd->iostream)
264 fclose ((FILE *) (output_bfd->iostream));
265
266 unlink (output_filename);
267 exit (1);
268 }
269 else
270 {
271 bfd_close (output_bfd);
272 }
273
274 exit (0);
275 } /* main() */
276
277 void
278 Q_read_entry_symbols (desc, entry)
279 bfd *desc;
280 struct lang_input_statement_struct *entry;
281 {
282 if (entry->asymbols == (asymbol **) NULL)
283 {
284 bfd_size_type table_size = get_symtab_upper_bound (desc);
285
286 entry->asymbols = (asymbol **) ldmalloc (table_size);
287 entry->symbol_count = bfd_canonicalize_symtab (desc, entry->asymbols);
288 }
289 }
290
291 /*
292 * turn this item into a reference
293 */
294 void
295 refize (sp, nlist_p)
296 ldsym_type *sp;
297 asymbol **nlist_p;
298 {
299 asymbol *sym = *nlist_p;
300
301 sym->value = 0;
302 sym->flags = 0;
303 sym->section = &bfd_und_section;
304 sym->udata = (PTR) (sp->srefs_chain);
305 sp->srefs_chain = nlist_p;
306 }
307
308 /*
309 This function is called for each name which is seen which has a global
310 scope. It enters the name into the global symbol table in the correct
311 symbol on the correct chain. Remember that each ldsym_type has three
312 chains attatched, one of all definitions of a symbol, one of all
313 references of a symbol and one of all common definitions of a symbol.
314
315 When the function is over, the supplied is left connected to the bfd
316 to which is was born, with its udata field pointing to the next member
317 on the chain in which it has been inserted.
318
319 A certain amount of jigery pokery is necessary since commons come
320 along and upset things, we only keep one item in the common chain; the
321 one with the biggest size seen sofar. When another common comes along
322 it either bumps the previous definition into the ref chain, since it
323 is bigger, or gets turned into a ref on the spot since the one on the
324 common chain is already bigger. If a real definition comes along then
325 the common gets bumped off anyway.
326
327 Whilst all this is going on we keep a count of the number of multiple
328 definitions seen, undefined global symbols and pending commons.
329 */
330
331 extern boolean relaxing;
332
333 void
334 DEFUN (Q_enter_global_ref, (nlist_p, name),
335 asymbol ** nlist_p AND /* pointer into symbol table from incoming bfd */
336 CONST char *name /* name of symbol in linker table */ )
337 {
338 asymbol *sym = *nlist_p;
339 ldsym_type *sp;
340
341 /* Lookup the name from the incoming bfd's symbol table in the
342 linker's global symbol table */
343
344
345 flagword this_symbol_flags = sym->flags;
346
347 sp = ldsym_get (name);
348
349
350 /* If this symbol already has udata, it means that something strange
351 has happened.
352
353 The strange thing is that we've had an undefined symbol resolved by
354 an alias, but the thing the alias defined wasn't in the file. So
355 the symbol got a udata entry, but the file wasn't loaded. Then
356 later on the file was loaded, but we don't need to do this
357 processing again */
358
359
360 if (sym->udata)
361 return;
362
363
364 if (flag_is_constructor (this_symbol_flags))
365 {
366 /* Add this constructor to the list we keep */
367 ldlang_add_constructor (sp);
368 /* Turn any commons into refs */
369 if (sp->scoms_chain != (asymbol **) NULL)
370 {
371 refize (sp, sp->scoms_chain);
372 sp->scoms_chain = 0;
373 }
374
375
376 }
377 else
378 {
379 if (bfd_is_com_section (sym->section))
380 {
381 /* If we have a definition of this symbol already then
382 this common turns into a reference. Also we only
383 ever point to the largest common, so if we
384 have a common, but it's bigger that the new symbol
385 the turn this into a reference too. */
386 if (sp->sdefs_chain)
387 {
388 /* This is a common symbol, but we already have a definition
389 for it, so just link it into the ref chain as if
390 it were a reference */
391 refize (sp, nlist_p);
392 }
393 else if (sp->scoms_chain)
394 {
395 /* If we have a previous common, keep only the biggest */
396 if ((*(sp->scoms_chain))->value > sym->value)
397 {
398 /* other common is bigger, throw this one away */
399 refize (sp, nlist_p);
400 }
401 else if (sp->scoms_chain != nlist_p)
402 {
403 /* other common is smaller, throw that away */
404 refize (sp, sp->scoms_chain);
405 sp->scoms_chain = nlist_p;
406 }
407 }
408 else
409 {
410 /* This is the first time we've seen a common, so remember it
411 - if it was undefined before, we know it's defined now. If
412 the symbol has been marked as really being a constructor,
413 then treat this as a ref
414 */
415 if (sp->flags & SYM_CONSTRUCTOR)
416 {
417 /* Turn this into a ref */
418 refize (sp, nlist_p);
419 }
420 else
421 {
422 /* treat like a common */
423 if (sp->srefs_chain)
424 undefined_global_sym_count--;
425
426 commons_pending++;
427 sp->scoms_chain = nlist_p;
428 }
429 }
430 }
431
432 else if (sym->section != &bfd_und_section)
433 {
434 /* This is the definition of a symbol, add to def chain */
435 if (sp->sdefs_chain && (*(sp->sdefs_chain))->section != sym->section)
436 {
437 /* Multiple definition */
438 asymbol *sy = *(sp->sdefs_chain);
439 lang_input_statement_type *stat =
440 (lang_input_statement_type *) bfd_asymbol_bfd (sy)->usrdata;
441 lang_input_statement_type *stat1 =
442 (lang_input_statement_type *) bfd_asymbol_bfd (sym)->usrdata;
443 asymbol **stat1_symbols = stat1 ? stat1->asymbols : 0;
444 asymbol **stat_symbols = stat ? stat->asymbols : 0;
445
446 multiple_def_count++;
447 einfo ("%X%C: multiple definition of `%T'\n",
448 bfd_asymbol_bfd (sym), sym->section, stat1_symbols, sym->value, sym);
449
450 einfo ("%X%C: first seen here\n",
451 bfd_asymbol_bfd (sy), sy->section, stat_symbols, sy->value);
452 }
453 else
454 {
455 sym->udata = (PTR) (sp->sdefs_chain);
456 sp->sdefs_chain = nlist_p;
457 }
458 /* A definition overrides a common symbol */
459 if (sp->scoms_chain)
460 {
461 refize (sp, sp->scoms_chain);
462 sp->scoms_chain = 0;
463 commons_pending--;
464 }
465 else if (sp->srefs_chain && relaxing == false)
466 {
467 /* If previously was undefined, then remember as defined */
468 undefined_global_sym_count--;
469 }
470 }
471 else
472 {
473 if (sp->scoms_chain == (asymbol **) NULL
474 && sp->srefs_chain == (asymbol **) NULL
475 && sp->sdefs_chain == (asymbol **) NULL)
476 {
477 /* And it's the first time we've seen it */
478 undefined_global_sym_count++;
479
480 }
481
482 refize (sp, nlist_p);
483 }
484 }
485
486 ASSERT (sp->sdefs_chain == 0 || sp->scoms_chain == 0);
487 ASSERT (sp->scoms_chain == 0 || (*(sp->scoms_chain))->udata == 0);
488
489
490 }
491
492 static void
493 Q_enter_file_symbols (entry)
494 lang_input_statement_type *entry;
495 {
496 asymbol **q;
497
498 entry->common_section =
499 bfd_make_section_old_way (entry->the_bfd, "COMMON");
500 entry->common_section->flags = SEC_NEVER_LOAD;
501 ldlang_add_file (entry);
502
503
504 if (trace_files || option_v)
505 {
506 info ("%I\n", entry);
507 }
508
509 total_symbols_seen += entry->symbol_count;
510 total_files_seen++;
511 if (entry->symbol_count)
512 {
513 for (q = entry->asymbols; *q; q++)
514 {
515 asymbol *p = *q;
516
517 if (had_y && p->name)
518 {
519 /* look up the symbol anyway to see if the trace bit was
520 set */
521 ldsym_type *s = ldsym_get (p->name);
522 if (s->flags & SYM_Y)
523 {
524 einfo ("%B: %s %T\n", entry->the_bfd,
525 p->section == &bfd_und_section ? "reference to" : "definition of ",
526 p);
527 }
528 }
529
530 if (p->section == &bfd_ind_section)
531 {
532 add_indirect (q);
533 }
534 else if (p->flags & BSF_WARNING)
535 {
536 add_warning (p);
537 }
538 else if (p->section == &bfd_und_section
539 || (p->flags & BSF_GLOBAL)
540 || bfd_is_com_section (p->section)
541 || (p->flags & BSF_CONSTRUCTOR))
542
543 {
544
545 asymbol *p = *q;
546
547 if (p->flags & BSF_INDIRECT)
548 {
549 add_indirect (q);
550 }
551 else if (p->flags & BSF_WARNING)
552 {
553 add_warning (p);
554 }
555 else if (p->section == &bfd_und_section
556 || (p->flags & BSF_GLOBAL)
557 || bfd_is_com_section (p->section)
558 || (p->flags & BSF_CONSTRUCTOR))
559 {
560 Q_enter_global_ref (q, p->name);
561 }
562
563 }
564
565 }
566 }
567 }
568
569
570 /* Searching libraries */
571
572 struct lang_input_statement_struct *decode_library_subfile ();
573 void linear_library (), symdef_library ();
574
575 /* Search the library ENTRY, already open on descriptor DESC.
576 This means deciding which library members to load,
577 making a chain of `struct lang_input_statement_struct' for those members,
578 and entering their global symbols in the hash table. */
579
580 void
581 search_library (entry)
582 struct lang_input_statement_struct *entry;
583 {
584
585 /* No need to load a library if no undefined symbols */
586 if (!undefined_global_sym_count)
587 return;
588
589 if (bfd_has_map (entry->the_bfd))
590 symdef_library (entry);
591 else
592 linear_library (entry);
593
594 }
595
596 #ifdef GNU960
597 static
598 boolean
599 gnu960_check_format (abfd, format)
600 bfd *abfd;
601 bfd_format format;
602 {
603 boolean retval;
604
605 if ((bfd_check_format (abfd, format) == true)
606 && (abfd->xvec->flavour == output_flavor))
607 {
608 return true;
609 }
610
611
612 return false;
613 }
614
615 #endif
616
617 void
618 ldmain_open_file_read_symbol (entry)
619 struct lang_input_statement_struct *entry;
620 {
621 if (entry->asymbols == (asymbol **) NULL
622 && entry->real == true
623 && entry->filename != (char *) NULL)
624 {
625 ldfile_open_file (entry);
626
627
628 #ifdef GNU960
629 if (gnu960_check_format (entry->the_bfd, bfd_object))
630 #else
631 if (bfd_check_format (entry->the_bfd, bfd_object))
632 #endif
633 {
634 entry->the_bfd->usrdata = (PTR) entry;
635
636
637 Q_read_entry_symbols (entry->the_bfd, entry);
638
639 /* look through the sections in the file and see if any of them
640 are constructors */
641 ldlang_check_for_constructors (entry);
642
643 Q_enter_file_symbols (entry);
644 }
645 #ifdef GNU960
646 else if (gnu960_check_format (entry->the_bfd, bfd_archive))
647 #else
648 else if (bfd_check_format (entry->the_bfd, bfd_archive))
649 #endif
650 {
651 entry->the_bfd->usrdata = (PTR) entry;
652
653 entry->subfiles = (lang_input_statement_type *) NULL;
654 search_library (entry);
655 }
656 else
657 {
658 einfo ("%F%B: malformed input file (not rel or archive) \n",
659 entry->the_bfd);
660 }
661 }
662
663 }
664
665 /* Construct and return a lang_input_statement_struct for a library member.
666 The library's lang_input_statement_struct is library_entry,
667 and the library is open on DESC.
668 SUBFILE_OFFSET is the byte index in the library of this member's header.
669 We store the length of the member into *LENGTH_LOC. */
670
671 lang_input_statement_type *
672 decode_library_subfile (library_entry, subfile_offset)
673 struct lang_input_statement_struct *library_entry;
674 bfd *subfile_offset;
675 {
676 register struct lang_input_statement_struct *subentry;
677
678
679 /* First, check if we already have a loaded
680 lang_input_statement_struct for this library subfile. If so,
681 just return it. Otherwise, allocate some space and build a new one. */
682
683 if (subfile_offset->usrdata
684 && ((struct lang_input_statement_struct *) subfile_offset->usrdata)->
685 loaded == true)
686 {
687 subentry = (struct lang_input_statement_struct *) subfile_offset->usrdata;
688 }
689 else
690 {
691 subentry =
692 (struct lang_input_statement_struct *)
693 ldmalloc ((bfd_size_type) (sizeof (struct lang_input_statement_struct)));
694
695 subentry->filename = subfile_offset->filename;
696 subentry->local_sym_name = subfile_offset->filename;
697 subentry->asymbols = 0;
698 subentry->the_bfd = subfile_offset;
699 subentry->subfiles = 0;
700 subentry->next = 0;
701 subentry->superfile = library_entry;
702 subentry->is_archive = false;
703
704 subentry->just_syms_flag = false;
705 subentry->loaded = false;
706 subentry->chain = 0;
707 }
708 return subentry;
709 }
710
711 boolean subfile_wanted_p ();
712 void
713 clear_syms (entry, offset)
714 struct lang_input_statement_struct *entry;
715 file_ptr offset;
716 {
717 carsym *car;
718 unsigned long indx = bfd_get_next_mapent (entry->the_bfd,
719 BFD_NO_MORE_SYMBOLS,
720 &car);
721
722 while (indx != BFD_NO_MORE_SYMBOLS)
723 {
724 if (car->file_offset == offset)
725 {
726 car->name = 0;
727 }
728 indx = bfd_get_next_mapent (entry->the_bfd, indx, &car);
729 }
730
731 }
732
733 /* Search a library that has a map
734 */
735 void
736 symdef_library (entry)
737 struct lang_input_statement_struct *entry;
738
739 {
740 register struct lang_input_statement_struct *prev = 0;
741
742 boolean not_finished = true;
743
744 while (not_finished == true)
745 {
746 carsym *exported_library_name;
747 bfd *prev_archive_member_bfd = 0;
748
749 int idx = bfd_get_next_mapent (entry->the_bfd,
750 BFD_NO_MORE_SYMBOLS,
751 &exported_library_name);
752
753 not_finished = false;
754
755 while (idx != BFD_NO_MORE_SYMBOLS && undefined_global_sym_count)
756 {
757
758 if (exported_library_name->name)
759 {
760
761 ldsym_type *sp = ldsym_get_soft (exported_library_name->name);
762
763 /* If we find a symbol that appears to be needed, think carefully
764 about the archive member that the symbol is in. */
765 /* So - if it exists, and is referenced somewhere and is
766 undefined or */
767 if (sp && sp->srefs_chain && !sp->sdefs_chain)
768 {
769 bfd *archive_member_bfd = bfd_get_elt_at_index (entry->the_bfd, idx);
770 struct lang_input_statement_struct *archive_member_lang_input_statement_struct;
771
772 #ifdef GNU960
773 if (archive_member_bfd && gnu960_check_format (archive_member_bfd, bfd_object))
774 #else
775 if (archive_member_bfd && bfd_check_format (archive_member_bfd, bfd_object))
776 #endif
777 {
778
779 /* Don't think carefully about any archive member
780 more than once in a given pass. */
781 if (prev_archive_member_bfd != archive_member_bfd)
782 {
783
784 prev_archive_member_bfd = archive_member_bfd;
785
786 /* Read the symbol table of the archive member. */
787
788 if (archive_member_bfd->usrdata != (PTR) NULL)
789 {
790
791 archive_member_lang_input_statement_struct = (lang_input_statement_type *) archive_member_bfd->usrdata;
792 }
793 else
794 {
795
796 archive_member_lang_input_statement_struct =
797 decode_library_subfile (entry, archive_member_bfd);
798 archive_member_bfd->usrdata = (PTR) archive_member_lang_input_statement_struct;
799
800 }
801
802 if (archive_member_lang_input_statement_struct == 0)
803 {
804 einfo ("%F%I contains invalid archive member %s\n",
805 entry, sp->name);
806 }
807
808 if (archive_member_lang_input_statement_struct->loaded == false)
809 {
810
811 Q_read_entry_symbols (archive_member_bfd, archive_member_lang_input_statement_struct);
812 /* Now scan the symbol table and decide whether to load. */
813
814
815 if (subfile_wanted_p (archive_member_lang_input_statement_struct) == true)
816
817 {
818 /* This member is needed; load it.
819 Since we are loading something on this pass,
820 we must make another pass through the symdef data. */
821
822 not_finished = true;
823
824 Q_enter_file_symbols (archive_member_lang_input_statement_struct);
825
826 if (prev)
827 prev->chain = archive_member_lang_input_statement_struct;
828 else
829 entry->subfiles = archive_member_lang_input_statement_struct;
830
831
832 prev = archive_member_lang_input_statement_struct;
833
834
835 /* Clear out this member's symbols from the symdef data
836 so that following passes won't waste time on them. */
837 clear_syms (entry, exported_library_name->file_offset);
838 archive_member_lang_input_statement_struct->loaded = true;
839 }
840 }
841 }
842 }
843 }
844 }
845 idx = bfd_get_next_mapent (entry->the_bfd, idx, &exported_library_name);
846 }
847 }
848 }
849
850 void
851 linear_library (entry)
852 struct lang_input_statement_struct *entry;
853 {
854 boolean more_to_do = true;
855 register struct lang_input_statement_struct *prev = 0;
856
857 if (entry->complained == false)
858 {
859 if (entry->the_bfd->xvec->flavour != bfd_target_ieee_flavour)
860
861 {
862 /* IEEE can use table of contents, so this message is bogus */
863 einfo ("%P: library %s has bad table of contents, rerun ranlib\n",
864 entry->the_bfd->filename);
865 }
866 entry->complained = true;
867
868 }
869 while (more_to_do)
870 {
871
872 bfd *archive = bfd_openr_next_archived_file (entry->the_bfd, 0);
873
874 more_to_do = false;
875 while (archive)
876 {
877 /* Don't check this file if it's already been read in
878 once */
879
880 if (!archive->usrdata ||
881 !((lang_input_statement_type *) (archive->usrdata))->loaded)
882 {
883 #ifdef GNU960
884 if (gnu960_check_format (archive, bfd_object))
885 #else
886 if (bfd_check_format (archive, bfd_object))
887 #endif
888 {
889 register struct lang_input_statement_struct *subentry;
890
891 subentry = decode_library_subfile (entry,
892 archive);
893
894 archive->usrdata = (PTR) subentry;
895 if (!subentry)
896 return;
897 if (subentry->loaded == false)
898 {
899 Q_read_entry_symbols (archive, subentry);
900
901 if (subfile_wanted_p (subentry) == true)
902 {
903 Q_enter_file_symbols (subentry);
904
905 if (prev)
906 prev->chain = subentry;
907 else
908 entry->subfiles = subentry;
909 prev = subentry;
910
911 more_to_do = true;
912 subentry->loaded = true;
913 }
914 }
915 }
916 }
917 archive = bfd_openr_next_archived_file (entry->the_bfd, archive);
918
919 }
920
921 }
922 }
923
924 /* ENTRY is an entry for a file inside an archive
925 Its symbols have been read into core, but not entered into the
926 linker ymbol table
927 Return nonzero if we ought to load this file */
928
929 boolean
930 subfile_wanted_p (entry)
931 struct lang_input_statement_struct *entry;
932 {
933 asymbol **q;
934
935 for (q = entry->asymbols; *q; q++)
936 {
937 asymbol *p = *q;
938
939 /* If the symbol has an interesting definition, we could
940 potentially want it. */
941
942 if (p->flags & BSF_INDIRECT)
943 {
944 /** add_indirect(q);*/
945 }
946
947 if (bfd_is_com_section (p->section)
948 || (p->flags & BSF_GLOBAL)
949 || (p->flags & BSF_INDIRECT))
950 {
951 register ldsym_type *sp = ldsym_get_soft (p->name);
952
953 /* If this symbol has not been hashed,
954 we can't be looking for it. */
955 if (sp != (ldsym_type *) NULL
956 && sp->sdefs_chain == (asymbol **) NULL)
957 {
958 if (sp->srefs_chain != (asymbol **) NULL
959 || sp->scoms_chain != (asymbol **) NULL)
960 {
961 /* This is a symbol we are looking for. It is
962 either not yet defined or common. If this is a
963 common symbol, then if the symbol in the object
964 file is common, we need to combine sizes. But if
965 we already have a common symbol, and the symbol
966 in the object file is not common, we don't want
967 the object file: it is providing a definition for
968 a symbol that we already have a definition for
969 (this is the else condition below). */
970 if (bfd_is_com_section (p->section))
971 {
972
973 /* If the symbol in the table is a constructor, we won't to
974 anything fancy with it */
975 if ((sp->flags & SYM_CONSTRUCTOR) == 0)
976 {
977 /* This libary member has something to
978 say about this element. We should
979 remember if its a new size */
980 /* Move something from the ref list to the com list */
981 if (sp->scoms_chain)
982 {
983 /* Already a common symbol, maybe update it */
984 if (p->value > (*(sp->scoms_chain))->value)
985 {
986 (*(sp->scoms_chain))->value = p->value;
987 }
988 }
989 else
990 {
991 /* Take a value from the ref chain
992 Here we are moving a symbol from the owning bfd
993 to another bfd. We must set up the
994 common_section portion of the bfd thing */
995
996
997
998 sp->scoms_chain = sp->srefs_chain;
999 sp->srefs_chain =
1000 (asymbol **) ((*(sp->srefs_chain))->udata);
1001 (*(sp->scoms_chain))->udata = (PTR) NULL;
1002
1003 (*(sp->scoms_chain))->section = p->section;
1004 (*(sp->scoms_chain))->flags = 0;
1005 /* Remember the size of this item */
1006 sp->scoms_chain[0]->value = p->value;
1007 commons_pending++;
1008 undefined_global_sym_count--;
1009 }
1010 {
1011 asymbol *com = *(sp->scoms_chain);
1012
1013 if (((lang_input_statement_type *)
1014 (bfd_asymbol_bfd (com)->usrdata))->common_section ==
1015 (asection *) NULL)
1016 {
1017 ((lang_input_statement_type *)
1018 (bfd_asymbol_bfd (com)->usrdata))->common_section =
1019 bfd_make_section_old_way (bfd_asymbol_bfd (com), "COMMON");
1020 }
1021 }
1022 }
1023 ASSERT (p->udata == 0);
1024 }
1025 else if (sp->scoms_chain == (asymbol **) NULL)
1026 {
1027 if (write_map)
1028 {
1029 info ("%I needed due to %s\n", entry, sp->name);
1030 }
1031 return true;
1032 }
1033 }
1034 }
1035 }
1036 }
1037
1038 return false;
1039 }
1040
1041 void
1042 add_ysym (text)
1043 char *text;
1044 {
1045 ldsym_type *lookup = ldsym_get (text);
1046 lookup->flags |= SYM_Y;
1047 had_y = 1;
1048 }