Sun Nov 3 16:37:37 1991 Steve Chamberlain (steve at cygnus.com)
[deliverable/binutils-gdb.git] / ld / ldmain.c
CommitLineData
2fa0b342 1/* Copyright (C) 1991 Free Software Foundation, Inc.
ce4d59e2 2 Written by Steve Chamberlain steve@cygnus.com
2fa0b342
DHW
3
4This file is part of GLD, the Gnu Linker.
5
6GLD is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
ce4d59e2 8the Free Software Foundation; either version 2, or (at your option)
2fa0b342
DHW
9any later version.
10
11GLD is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GLD; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/*
2fa0b342 21 * $Id$
2fa0b342
DHW
22 */
23
2fa0b342 24#include "bfd.h"
f177a611 25#include "sysdep.h"
2fa0b342
DHW
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"
8c514453 35#include "ldemul.h"
2fa0b342
DHW
36#include "ldlex.h"
37#include "ldfile.h"
38
39/* IMPORTS */
40extern boolean lang_has_input_file;
1418c83b 41extern boolean trace_files;
2fa0b342
DHW
42/* EXPORTS */
43
44char *default_target;
45char *output_filename = "a.out";
46/* Name this program was invoked by. */
47char *program_name;
48
49/* The file that we're creating */
b6316534 50bfd *output_bfd = 0;
2fa0b342
DHW
51
52extern boolean option_v;
53
54/* The local symbol prefix */
55char lprefix = 'L';
56
57/* Count the number of global symbols multiply defined. */
58int 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
3e4c643d 69 all ldsym_types with a ->scoms field */
2fa0b342 70
3e4c643d 71unsigned int commons_pending;
2fa0b342
DHW
72
73/* Count the number of global symbols referenced and not defined.
3e4c643d 74 common symbols are not included in this count. */
2fa0b342
DHW
75
76unsigned int undefined_global_sym_count;
77
78
79
80/* Count the number of warning symbols encountered. */
81int warning_count;
82
83/* have we had a load script ? */
84extern boolean had_script;
85
2fa0b342
DHW
86/* Nonzero means print names of input files as processed. */
87boolean trace_files;
88
89
90
91/* 1 => write load map. */
92boolean write_map;
93
94
95int unix_relocate;
81016051
SC
96#ifdef GNU960
97/* Indicates whether output file will be b.out (default) or coff */
f177a611 98enum target_flavour output_flavor = BFD_BOUT_FORMAT;
81016051 99#endif
2fa0b342 100
2fa0b342
DHW
101/* Force the make_executable to be output, even if there are non-fatal
102 errors */
103boolean force_make_executable;
104
2fa0b342
DHW
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
2fa0b342
DHW
108unsigned 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 */
113unsigned int total_files_seen;
114
2fa0b342
DHW
115/* IMPORTS */
116args_type command_line;
117ld_config_type config;
118int
119main (argc, argv)
120 char **argv;
121 int argc;
122{
123 char *emulation;
124 program_name = argv[0];
125 output_filename = "a.out";
99fe4553 126
3e4c643d 127 bfd_init();
99fe4553 128#ifdef GNU960
81016051
SC
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);
99fe4553
SC
144#endif
145
2fa0b342 146 /* Initialize the data about options. */
76855794 147
2fa0b342 148 trace_files = false;
2fa0b342
DHW
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("");
8cb5eb31 155 ldfile_add_library_path("./");
2fa0b342
DHW
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
ce4d59e2
SC
166 config.magic_demand_paged = true;
167 config.text_read_only = true;
2fa0b342 168 config.make_executable = true;
2fa0b342
DHW
169 if (emulation == (char *)NULL) {
170 emulation= DEFAULT_EMULATION;
171 }
1418c83b 172
2fa0b342 173 ldemul_choose_mode(emulation);
2fa0b342 174 default_target = ldemul_choose_target();
2fa0b342
DHW
175 lang_init();
176 ldemul_before_parse();
2fa0b342
DHW
177 lang_has_input_file = false;
178 parse_args(argc, argv);
1418c83b
SC
179 lang_final();
180 if (trace_files) {
181 info("%P: mode %s\n", emulation);
182 }
2fa0b342
DHW
183 if (lang_has_input_file == false) {
184 info("%P%F: No input files\n");
185 }
186
187 ldemul_after_parse();
2fa0b342
DHW
188 lang_process();
189
2fa0b342
DHW
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
3e4c643d
SC
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;
3e4c643d 207 }
2fa0b342
DHW
208
209 if (config.relocateable_output) {
ce4d59e2 210 output_bfd->flags &= ~EXEC_P;
2fa0b342
DHW
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
229void
230Q_read_entry_symbols (desc, entry)
231 bfd *desc;
232 struct lang_input_statement_struct *entry;
233{
234 if (entry->asymbols == (asymbol **)NULL) {
81016051 235 bfd_size_type table_size = get_symtab_upper_bound(desc);
2fa0b342 236 entry->asymbols = (asymbol **)ldmalloc(table_size);
2fa0b342
DHW
237 entry->symbol_count = bfd_canonicalize_symtab(desc, entry->asymbols) ;
238 }
239}
240
241
242/*
243 * turn this item into a reference
244 */
245static void
246refize(sp, nlist_p)
247ldsym_type *sp;
248asymbol **nlist_p;
249{
250 asymbol *sym = *nlist_p;
251 sym->value = 0;
252 sym->flags = BSF_UNDEFINED;
253 sym->section = (asection *)NULL;
99fe4553 254 sym->udata =(PTR)( sp->srefs_chain);
2fa0b342
DHW
255 sp->srefs_chain = nlist_p;
256}
257/*
258This function is called for each name which is seen which has a global
259scope. It enters the name into the global symbol table in the correct
260symbol on the correct chain. Remember that each ldsym_type has three
261chains attatched, one of all definitions of a symbol, one of all
262references of a symbol and one of all common definitions of a symbol.
263
264When the function is over, the supplied is left connected to the bfd
265to which is was born, with its udata field pointing to the next member
266on the chain in which it has been inserted.
267
268A certain amount of jigery pokery is necessary since commons come
269along and upset things, we only keep one item in the common chain; the
270one with the biggest size seen sofar. When another common comes along
271it either bumps the previous definition into the ref chain, since it
272is bigger, or gets turned into a ref on the spot since the one on the
273common chain is already bigger. If a real definition comes along then
274the common gets bumped off anyway.
275
276Whilst all this is going on we keep a count of the number of multiple
277definitions seen, undefined global symbols and pending commons.
278*/
279
280
281void
282Q_enter_global_ref (nlist_p)
283 asymbol **nlist_p;
284
285{
286 asymbol *sym = *nlist_p;
99fe4553 287 CONST char *name = sym->name;
2fa0b342
DHW
288 ldsym_type *sp = ldsym_get (name);
289
290 flagword this_symbol_flags = sym->flags;
291
292
293 ASSERT(sym->udata == 0);
294
3e4c643d 295
81016051 296 if (flag_is_constructor(this_symbol_flags)) {
3e4c643d
SC
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
81016051
SC
305
306 }
307 else {
308 if (flag_is_common(this_symbol_flags)) {
309 /* If we have a definition of this symbol already then
3e4c643d
SC
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. */
81016051
SC
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
3e4c643d 318 it were a reference */
81016051
SC
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 }
2fa0b342 332 }
81016051 333 else {
3e4c643d
SC
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 }
2fa0b342
DHW
351 }
352 }
2fa0b342 353
81016051
SC
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;
2fa0b342 363
81016051
SC
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);
2fa0b342 371
81016051
SC
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 }
2fa0b342
DHW
392 }
393 else {
81016051
SC
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++;
2fa0b342 399
81016051 400 }
2fa0b342 401
81016051
SC
402 refize(sp, nlist_p);
403 }
2fa0b342
DHW
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
412static void
413Q_enter_file_symbols (entry)
414lang_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
81016051 433 if (flag_is_undefined_or_global_or_common_or_constructor(p->flags))
2fa0b342 434 {
2fa0b342
DHW
435 Q_enter_global_ref(q);
436 }
81016051
SC
437 if (p->flags & BSF_INDIRECT) {
438 add_indirect(q);
439 }
440
441 if (p->flags & BSF_WARNING) {
442 add_warning(p);
443 }
2fa0b342
DHW
444 ASSERT(p->flags != 0);
445 }
446}
447
448
449
450/* Searching libraries */
451
452struct lang_input_statement_struct *decode_library_subfile ();
453void 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
460void
461search_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
99fe4553
SC
476#ifdef GNU960
477static
478boolean
479gnu960_check_format (abfd, format)
480bfd *abfd;
481bfd_format format;
482{
483 boolean retval;
484
81016051
SC
485 if ((bfd_check_format(abfd,format) == true)
486 && (abfd->xvec->flavour == output_flavor) ){
487 return true;
99fe4553 488 }
81016051
SC
489
490
99fe4553
SC
491 return false;
492}
493#endif
494
2fa0b342 495void
1418c83b 496ldmain_open_file_read_symbol (entry)
2fa0b342
DHW
497struct 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
ce4d59e2 505
99fe4553
SC
506#ifdef GNU960
507 if (gnu960_check_format(entry->the_bfd, bfd_object))
508#else
2fa0b342 509 if (bfd_check_format(entry->the_bfd, bfd_object))
99fe4553 510#endif
2fa0b342 511 {
99fe4553 512 entry->the_bfd->usrdata = (PTR)entry;
2fa0b342
DHW
513
514
515 Q_read_entry_symbols (entry->the_bfd, entry);
ce4d59e2
SC
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
2fa0b342
DHW
521 Q_enter_file_symbols (entry);
522 }
99fe4553
SC
523#ifdef GNU960
524 else if (gnu960_check_format(entry->the_bfd, bfd_archive))
525#else
2fa0b342 526 else if (bfd_check_format(entry->the_bfd, bfd_archive))
99fe4553 527#endif
2fa0b342 528 {
99fe4553 529 entry->the_bfd->usrdata = (PTR)entry;
2fa0b342
DHW
530
531 entry->subfiles = (lang_input_statement_type *)NULL;
532 search_library (entry);
533 }
534 else
535 {
99fe4553
SC
536 info("%F%B: malformed input file (not rel or archive) \n",
537 entry->the_bfd);
2fa0b342
DHW
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
550lang_input_statement_type *
551decode_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;
81016051 556 subentry = (struct lang_input_statement_struct *) ldmalloc ((bfd_size_type)(sizeof (struct lang_input_statement_struct)));
2fa0b342
DHW
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;
1418c83b 565
2fa0b342
DHW
566 subentry->just_syms_flag = false;
567 subentry->loaded = false;
568 subentry->chain = 0;
569
570 return subentry;
571}
572
573boolean subfile_wanted_p ();
574void
575clear_syms(entry, offset)
576struct lang_input_statement_struct *entry;
577file_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 */
594void
595symdef_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)
3e4c643d
SC
605 {
606 carsym *exported_library_name;
607 bfd *prev_archive_member_bfd = 0;
2fa0b342 608
3e4c643d
SC
609 int idx = bfd_get_next_mapent(entry->the_bfd,
610 BFD_NO_MORE_SYMBOLS,
611 &exported_library_name);
2fa0b342 612
3e4c643d 613 not_finished = false;
2fa0b342 614
3e4c643d 615 while (idx != BFD_NO_MORE_SYMBOLS && undefined_global_sym_count)
2fa0b342
DHW
616 {
617
3e4c643d
SC
618 if (exported_library_name->name)
619 {
2fa0b342 620
3e4c643d
SC
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;
2fa0b342 631
99fe4553 632#ifdef GNU960
3e4c643d 633 if (archive_member_bfd && gnu960_check_format(archive_member_bfd, bfd_object))
99fe4553 634#else
3e4c643d 635 if (archive_member_bfd && bfd_check_format(archive_member_bfd, bfd_object))
99fe4553 636#endif
3e4c643d 637 {
2fa0b342 638
3e4c643d
SC
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 {
2fa0b342 643
3e4c643d 644 prev_archive_member_bfd = archive_member_bfd;
2fa0b342 645
3e4c643d 646 /* Read the symbol table of the archive member. */
2fa0b342 647
3e4c643d 648 if (archive_member_bfd->usrdata != (PTR)NULL) {
2fa0b342 649
3e4c643d
SC
650 archive_member_lang_input_statement_struct =(lang_input_statement_type *) archive_member_bfd->usrdata;
651 }
652 else {
2fa0b342 653
3e4c643d
SC
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;
2fa0b342 657
3e4c643d 658 }
2fa0b342 659
3e4c643d
SC
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 }
2fa0b342 665
3e4c643d
SC
666 if (archive_member_lang_input_statement_struct->loaded == false)
667 {
2fa0b342 668
3e4c643d
SC
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. */
2fa0b342
DHW
671
672
3e4c643d 673 if (subfile_wanted_p (archive_member_lang_input_statement_struct) == true)
2fa0b342 674
3e4c643d
SC
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. */
2fa0b342 679
3e4c643d 680 not_finished = true;
2fa0b342 681
3e4c643d 682 Q_enter_file_symbols (archive_member_lang_input_statement_struct);
2fa0b342 683
3e4c643d
SC
684 if (prev)
685 prev->chain = archive_member_lang_input_statement_struct;
686 else
687 entry->subfiles = archive_member_lang_input_statement_struct;
2fa0b342
DHW
688
689
3e4c643d 690 prev = archive_member_lang_input_statement_struct;
2fa0b342
DHW
691
692
3e4c643d
SC
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 }
2fa0b342 700 }
2fa0b342 701 }
3e4c643d
SC
702 }
703 idx = bfd_get_next_mapent(entry->the_bfd, idx, &exported_library_name);
2fa0b342 704 }
3e4c643d 705 }
2fa0b342
DHW
706}
707
708void
709linear_library (entry)
710struct 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) {
99fe4553
SC
721#ifdef GNU960
722 if (gnu960_check_format(archive, bfd_object))
723#else
2fa0b342 724 if (bfd_check_format(archive, bfd_object))
99fe4553 725#endif
2fa0b342
DHW
726 {
727 register struct lang_input_statement_struct *subentry;
728
729 subentry = decode_library_subfile (entry,
730 archive);
731
99fe4553 732 archive->usrdata = (PTR) subentry;
2fa0b342
DHW
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
763boolean
764subfile_wanted_p (entry)
765struct 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
3e4c643d
SC
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
2fa0b342
DHW
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 {
3e4c643d
SC
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) {
2fa0b342
DHW
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);
99fe4553 825 (*(sp->scoms_chain))->udata = (PTR)NULL;
2fa0b342
DHW
826
827 (*( sp->scoms_chain))->flags = BSF_FORT_COMM;
1418c83b
SC
828 /* Remember the size of this item */
829 sp->scoms_chain[0]->value = p->value;
2fa0b342
DHW
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 }
3e4c643d 842 }
2fa0b342
DHW
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
This page took 0.071054 seconds and 4 git commands to generate.