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