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