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