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