Added ctor.c (I remembered this time)
[deliverable/binutils-gdb.git] / ld / ldmain.c
CommitLineData
2fa0b342
DHW
1/* Copyright (C) 1991 Free Software Foundation, Inc.
2
3This file is part of GLD, the Gnu Linker.
4
5GLD is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 1, or (at your option)
8any later version.
9
10GLD is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with GLD; see the file COPYING. If not, write to
17the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
18
19/*
20 * Written by Steve Chamberlain steve@cygnus.com
21 *
22 * $Id$
2fa0b342
DHW
23 */
24
2fa0b342 25#include "bfd.h"
f177a611 26#include "sysdep.h"
2fa0b342
DHW
27
28#include "config.h"
29#include "ld.h"
30#include "ldmain.h"
31#include "ldmisc.h"
32#include "ldwrite.h"
33#include "ldgram.h"
34#include "ldsym.h"
35#include "ldlang.h"
8c514453 36#include "ldemul.h"
2fa0b342
DHW
37#include "ldlex.h"
38#include "ldfile.h"
39
40/* IMPORTS */
41extern boolean lang_has_input_file;
1418c83b 42extern boolean trace_files;
2fa0b342
DHW
43/* EXPORTS */
44
45char *default_target;
46char *output_filename = "a.out";
47/* Name this program was invoked by. */
48char *program_name;
49
50/* The file that we're creating */
b6316534 51bfd *output_bfd = 0;
2fa0b342
DHW
52
53extern boolean option_v;
54
55/* The local symbol prefix */
56char lprefix = 'L';
57
58/* Count the number of global symbols multiply defined. */
59int multiple_def_count;
60
61
62/* Count the number of symbols defined through common declarations.
63 This count is referenced in symdef_library, linear_library, and
64 modified by enter_global_ref.
65
66 It is incremented when a symbol is created as a common, and
67 decremented when the common declaration is overridden
68
69 Another way of thinking of it is that this is a count of
3e4c643d 70 all ldsym_types with a ->scoms field */
2fa0b342 71
3e4c643d 72unsigned int commons_pending;
2fa0b342
DHW
73
74/* Count the number of global symbols referenced and not defined.
3e4c643d 75 common symbols are not included in this count. */
2fa0b342
DHW
76
77unsigned int undefined_global_sym_count;
78
79
80
81/* Count the number of warning symbols encountered. */
82int warning_count;
83
84/* have we had a load script ? */
85extern boolean had_script;
86
2fa0b342
DHW
87/* Nonzero means print names of input files as processed. */
88boolean trace_files;
89
90
91
92/* 1 => write load map. */
93boolean write_map;
94
95
96int unix_relocate;
81016051
SC
97#ifdef GNU960
98/* Indicates whether output file will be b.out (default) or coff */
f177a611 99enum target_flavour output_flavor = BFD_BOUT_FORMAT;
81016051 100#endif
2fa0b342 101
2fa0b342
DHW
102/* Force the make_executable to be output, even if there are non-fatal
103 errors */
104boolean force_make_executable;
105
2fa0b342
DHW
106/* A count of the total number of local symbols ever seen - by adding
107 the symbol_count field of each newly read afile.*/
108
2fa0b342
DHW
109unsigned int total_symbols_seen;
110
111/* A count of the number of read files - the same as the number of elements
112 in file_chain
113 */
114unsigned int total_files_seen;
115
2fa0b342
DHW
116/* IMPORTS */
117args_type command_line;
118ld_config_type config;
119int
120main (argc, argv)
121 char **argv;
122 int argc;
123{
124 char *emulation;
125 program_name = argv[0];
126 output_filename = "a.out";
99fe4553 127
3e4c643d 128 bfd_init();
99fe4553 129#ifdef GNU960
81016051
SC
130 {
131 int i;
132
133 check_v960( argc, argv );
134 emulation = GLD960_EMULATION_NAME;
135 for ( i = 1; i < argc; i++ ){
136 if ( !strcmp(argv[i],"-Fcoff") ){
137 emulation = LNK960_EMULATION_NAME;
138 output_flavor = BFD_COFF_FORMAT;
139 break;
140 }
141 }
142 }
143#else
144 emulation = (char *) getenv(EMULATION_ENVIRON);
99fe4553
SC
145#endif
146
2fa0b342 147 /* Initialize the data about options. */
76855794 148
2fa0b342 149 trace_files = false;
2fa0b342
DHW
150 write_map = false;
151 config.relocateable_output = false;
152 unix_relocate = 0;
153 command_line.force_common_definition = false;
154
155 ldfile_add_arch("");
8cb5eb31 156 ldfile_add_library_path("./");
2fa0b342
DHW
157 config.make_executable = true;
158 force_make_executable = false;
159
160
161 /* Initialize the cumulative counts of symbols. */
162 undefined_global_sym_count = 0;
163 warning_count = 0;
164 multiple_def_count = 0;
165 commons_pending = 0;
166
167 config.magic_demand_paged = true ;
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;
207 output_bfd->flags |= WP_TEXT;
208 }
209 else {
210 output_bfd->flags |= WP_TEXT;
211 }
212
2fa0b342
DHW
213
214 if (config.relocateable_output) {
215 output_bfd->flags &= ~( D_PAGED);
216 output_bfd->flags |= EXEC_P;
217 ldwrite();
218 bfd_close(output_bfd);
219 }
220 else {
221 output_bfd->flags |= EXEC_P;
222
223 ldwrite();
224 bfd_close(output_bfd);
225 if (config.make_executable == false && force_make_executable == false) {
226 unlink(output_filename);
227 }
228 return (!config.make_executable);
229 }
230
231 return(0);
232} /* main() */
233
234
235void
236Q_read_entry_symbols (desc, entry)
237 bfd *desc;
238 struct lang_input_statement_struct *entry;
239{
240 if (entry->asymbols == (asymbol **)NULL) {
81016051 241 bfd_size_type table_size = get_symtab_upper_bound(desc);
2fa0b342 242 entry->asymbols = (asymbol **)ldmalloc(table_size);
2fa0b342
DHW
243 entry->symbol_count = bfd_canonicalize_symtab(desc, entry->asymbols) ;
244 }
245}
246
247
248/*
249 * turn this item into a reference
250 */
251static void
252refize(sp, nlist_p)
253ldsym_type *sp;
254asymbol **nlist_p;
255{
256 asymbol *sym = *nlist_p;
257 sym->value = 0;
258 sym->flags = BSF_UNDEFINED;
259 sym->section = (asection *)NULL;
99fe4553 260 sym->udata =(PTR)( sp->srefs_chain);
2fa0b342
DHW
261 sp->srefs_chain = nlist_p;
262}
263/*
264This function is called for each name which is seen which has a global
265scope. It enters the name into the global symbol table in the correct
266symbol on the correct chain. Remember that each ldsym_type has three
267chains attatched, one of all definitions of a symbol, one of all
268references of a symbol and one of all common definitions of a symbol.
269
270When the function is over, the supplied is left connected to the bfd
271to which is was born, with its udata field pointing to the next member
272on the chain in which it has been inserted.
273
274A certain amount of jigery pokery is necessary since commons come
275along and upset things, we only keep one item in the common chain; the
276one with the biggest size seen sofar. When another common comes along
277it either bumps the previous definition into the ref chain, since it
278is bigger, or gets turned into a ref on the spot since the one on the
279common chain is already bigger. If a real definition comes along then
280the common gets bumped off anyway.
281
282Whilst all this is going on we keep a count of the number of multiple
283definitions seen, undefined global symbols and pending commons.
284*/
285
286
287void
288Q_enter_global_ref (nlist_p)
289 asymbol **nlist_p;
290
291{
292 asymbol *sym = *nlist_p;
99fe4553 293 CONST char *name = sym->name;
2fa0b342
DHW
294 ldsym_type *sp = ldsym_get (name);
295
296 flagword this_symbol_flags = sym->flags;
297
298
299 ASSERT(sym->udata == 0);
300
3e4c643d 301
81016051 302 if (flag_is_constructor(this_symbol_flags)) {
3e4c643d
SC
303 /* Add this constructor to the list we keep */
304 ldlang_add_constructor(sp);
305 /* Turn any commons into refs */
306 if (sp->scoms_chain != (asymbol **)NULL) {
307 refize(sp, sp->scoms_chain);
308 sp->scoms_chain = 0;
309 }
310
81016051
SC
311
312 }
313 else {
314 if (flag_is_common(this_symbol_flags)) {
315 /* If we have a definition of this symbol already then
3e4c643d
SC
316 this common turns into a reference. Also we only
317 ever point to the largest common, so if we
318 have a common, but it's bigger that the new symbol
319 the turn this into a reference too. */
81016051
SC
320 if (sp->sdefs_chain)
321 {
322 /* This is a common symbol, but we already have a definition
323 for it, so just link it into the ref chain as if
3e4c643d 324 it were a reference */
81016051
SC
325 refize(sp, nlist_p);
326 }
327 else if (sp->scoms_chain) {
328 /* If we have a previous common, keep only the biggest */
329 if ( (*(sp->scoms_chain))->value > sym->value) {
330 /* other common is bigger, throw this one away */
331 refize(sp, nlist_p);
332 }
333 else if (sp->scoms_chain != nlist_p) {
334 /* other common is smaller, throw that away */
335 refize(sp, sp->scoms_chain);
336 sp->scoms_chain = nlist_p;
337 }
2fa0b342 338 }
81016051 339 else {
3e4c643d
SC
340 /* This is the first time we've seen a common, so remember it
341 - if it was undefined before, we know it's defined now. If
342 the symbol has been marked as really being a constructor,
343 then treat this as a ref
344 */
345 if (sp->flags & SYM_CONSTRUCTOR) {
346 /* Turn this into a ref */
347 refize(sp, nlist_p);
348 }
349 else {
350 /* treat like a common */
351 if (sp->srefs_chain)
352 undefined_global_sym_count--;
353
354 commons_pending++;
355 sp->scoms_chain = nlist_p;
356 }
2fa0b342
DHW
357 }
358 }
2fa0b342 359
81016051
SC
360 else if (flag_is_defined(this_symbol_flags)) {
361 /* This is the definition of a symbol, add to def chain */
362 if (sp->sdefs_chain && (*(sp->sdefs_chain))->section != sym->section) {
363 /* Multiple definition */
364 asymbol *sy = *(sp->sdefs_chain);
365 lang_input_statement_type *stat = (lang_input_statement_type *) sy->the_bfd->usrdata;
366 lang_input_statement_type *stat1 = (lang_input_statement_type *) sym->the_bfd->usrdata;
367 asymbol ** stat1_symbols = stat1 ? stat1->asymbols: 0;
368 asymbol ** stat_symbols = stat ? stat->asymbols:0;
2fa0b342 369
81016051
SC
370 multiple_def_count++;
371 info("%C: multiple definition of `%T'\n",
372 sym->the_bfd,
373 sym->section,
374 stat1_symbols,
375 sym->value,
376 sym);
2fa0b342 377
81016051
SC
378 info("%C: first seen here\n",
379 sy->the_bfd,
380 sy->section,
381 stat_symbols,
382 sy->value);
383 }
384 else {
385 sym->udata =(PTR)( sp->sdefs_chain);
386 sp->sdefs_chain = nlist_p;
387 }
388 /* A definition overrides a common symbol */
389 if (sp->scoms_chain) {
390 refize(sp, sp->scoms_chain);
391 sp->scoms_chain = 0;
392 commons_pending--;
393 }
394 else if (sp->srefs_chain) {
395 /* If previously was undefined, then remember as defined */
396 undefined_global_sym_count--;
397 }
2fa0b342
DHW
398 }
399 else {
81016051
SC
400 if (sp->scoms_chain == (asymbol **)NULL
401 && sp->srefs_chain == (asymbol **)NULL
402 && sp->sdefs_chain == (asymbol **)NULL) {
403 /* And it's the first time we've seen it */
404 undefined_global_sym_count++;
2fa0b342 405
81016051 406 }
2fa0b342 407
81016051
SC
408 refize(sp, nlist_p);
409 }
2fa0b342
DHW
410 }
411
412 ASSERT(sp->sdefs_chain == 0 || sp->scoms_chain == 0);
413 ASSERT(sp->scoms_chain ==0 || (*(sp->scoms_chain))->udata == 0);
414
415
416}
417
418static void
419Q_enter_file_symbols (entry)
420lang_input_statement_type *entry;
421{
422 asymbol **q ;
423 entry->common_section =
424 bfd_make_section(entry->the_bfd, "COMMON");
425
426 ldlang_add_file(entry);
427
428
429 if (trace_files || option_v) {
430 info("%I\n", entry);
431 }
432
433 total_symbols_seen += entry->symbol_count;
434 total_files_seen ++;
435 for (q = entry->asymbols; *q; q++)
436 {
437 asymbol *p = *q;
438
81016051 439 if (flag_is_undefined_or_global_or_common_or_constructor(p->flags))
2fa0b342 440 {
2fa0b342
DHW
441 Q_enter_global_ref(q);
442 }
81016051
SC
443 if (p->flags & BSF_INDIRECT) {
444 add_indirect(q);
445 }
446
447 if (p->flags & BSF_WARNING) {
448 add_warning(p);
449 }
2fa0b342
DHW
450 ASSERT(p->flags != 0);
451 }
452}
453
454
455
456/* Searching libraries */
457
458struct lang_input_statement_struct *decode_library_subfile ();
459void linear_library (), symdef_library ();
460
461/* Search the library ENTRY, already open on descriptor DESC.
462 This means deciding which library members to load,
463 making a chain of `struct lang_input_statement_struct' for those members,
464 and entering their global symbols in the hash table. */
465
466void
467search_library (entry)
468 struct lang_input_statement_struct *entry;
469{
470
471 /* No need to load a library if no undefined symbols */
472 if (!undefined_global_sym_count) return;
473
474 if (bfd_has_map(entry->the_bfd))
475 symdef_library (entry);
476 else
477 linear_library (entry);
478
479}
480
481
99fe4553
SC
482#ifdef GNU960
483static
484boolean
485gnu960_check_format (abfd, format)
486bfd *abfd;
487bfd_format format;
488{
489 boolean retval;
490
81016051
SC
491 if ((bfd_check_format(abfd,format) == true)
492 && (abfd->xvec->flavour == output_flavor) ){
493 return true;
99fe4553 494 }
81016051
SC
495
496
99fe4553
SC
497 return false;
498}
499#endif
500
2fa0b342 501void
1418c83b 502ldmain_open_file_read_symbol (entry)
2fa0b342
DHW
503struct lang_input_statement_struct *entry;
504{
505 if (entry->asymbols == (asymbol **)NULL
506 &&entry->real == true
507 && entry->filename != (char *)NULL)
508 {
509 ldfile_open_file (entry);
510
99fe4553
SC
511#ifdef GNU960
512 if (gnu960_check_format(entry->the_bfd, bfd_object))
513#else
2fa0b342 514 if (bfd_check_format(entry->the_bfd, bfd_object))
99fe4553 515#endif
2fa0b342 516 {
99fe4553 517 entry->the_bfd->usrdata = (PTR)entry;
2fa0b342
DHW
518
519
520 Q_read_entry_symbols (entry->the_bfd, entry);
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.101805 seconds and 4 git commands to generate.