source: trunk/src/binutils/bfd/linker.c@ 10

Last change on this file since 10 was 10, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 86.3 KB
Line 
1/* linker.c -- BFD linker routines
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 Free Software Foundation, Inc.
4 Written by Steve Chamberlain and Ian Lance Taylor, Cygnus Support
5
6This file is part of BFD, the Binary File Descriptor library.
7
8This program is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2 of the License, or
11(at your option) any later version.
12
13This program is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with this program; if not, write to the Free Software
20Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21
22#include "bfd.h"
23#include "sysdep.h"
24#include "libbfd.h"
25#include "bfdlink.h"
26#include "genlink.h"
27
28/*
29SECTION
30 Linker Functions
31
32@cindex Linker
33 The linker uses three special entry points in the BFD target
34 vector. It is not necessary to write special routines for
35 these entry points when creating a new BFD back end, since
36 generic versions are provided. However, writing them can
37 speed up linking and make it use significantly less runtime
38 memory.
39
40 The first routine creates a hash table used by the other
41 routines. The second routine adds the symbols from an object
42 file to the hash table. The third routine takes all the
43 object files and links them together to create the output
44 file. These routines are designed so that the linker proper
45 does not need to know anything about the symbols in the object
46 files that it is linking. The linker merely arranges the
47 sections as directed by the linker script and lets BFD handle
48 the details of symbols and relocs.
49
50 The second routine and third routines are passed a pointer to
51 a <<struct bfd_link_info>> structure (defined in
52 <<bfdlink.h>>) which holds information relevant to the link,
53 including the linker hash table (which was created by the
54 first routine) and a set of callback functions to the linker
55 proper.
56
57 The generic linker routines are in <<linker.c>>, and use the
58 header file <<genlink.h>>. As of this writing, the only back
59 ends which have implemented versions of these routines are
60 a.out (in <<aoutx.h>>) and ECOFF (in <<ecoff.c>>). The a.out
61 routines are used as examples throughout this section.
62
63@menu
64@* Creating a Linker Hash Table::
65@* Adding Symbols to the Hash Table::
66@* Performing the Final Link::
67@end menu
68
69INODE
70Creating a Linker Hash Table, Adding Symbols to the Hash Table, Linker Functions, Linker Functions
71SUBSECTION
72 Creating a linker hash table
73
74@cindex _bfd_link_hash_table_create in target vector
75@cindex target vector (_bfd_link_hash_table_create)
76 The linker routines must create a hash table, which must be
77 derived from <<struct bfd_link_hash_table>> described in
78 <<bfdlink.c>>. @xref{Hash Tables}, for information on how to
79 create a derived hash table. This entry point is called using
80 the target vector of the linker output file.
81
82 The <<_bfd_link_hash_table_create>> entry point must allocate
83 and initialize an instance of the desired hash table. If the
84 back end does not require any additional information to be
85 stored with the entries in the hash table, the entry point may
86 simply create a <<struct bfd_link_hash_table>>. Most likely,
87 however, some additional information will be needed.
88
89 For example, with each entry in the hash table the a.out
90 linker keeps the index the symbol has in the final output file
91 (this index number is used so that when doing a relocateable
92 link the symbol index used in the output file can be quickly
93 filled in when copying over a reloc). The a.out linker code
94 defines the required structures and functions for a hash table
95 derived from <<struct bfd_link_hash_table>>. The a.out linker
96 hash table is created by the function
97 <<NAME(aout,link_hash_table_create)>>; it simply allocates
98 space for the hash table, initializes it, and returns a
99 pointer to it.
100
101 When writing the linker routines for a new back end, you will
102 generally not know exactly which fields will be required until
103 you have finished. You should simply create a new hash table
104 which defines no additional fields, and then simply add fields
105 as they become necessary.
106
107INODE
108Adding Symbols to the Hash Table, Performing the Final Link, Creating a Linker Hash Table, Linker Functions
109SUBSECTION
110 Adding symbols to the hash table
111
112@cindex _bfd_link_add_symbols in target vector
113@cindex target vector (_bfd_link_add_symbols)
114 The linker proper will call the <<_bfd_link_add_symbols>>
115 entry point for each object file or archive which is to be
116 linked (typically these are the files named on the command
117 line, but some may also come from the linker script). The
118 entry point is responsible for examining the file. For an
119 object file, BFD must add any relevant symbol information to
120 the hash table. For an archive, BFD must determine which
121 elements of the archive should be used and adding them to the
122 link.
123
124 The a.out version of this entry point is
125 <<NAME(aout,link_add_symbols)>>.
126
127@menu
128@* Differing file formats::
129@* Adding symbols from an object file::
130@* Adding symbols from an archive::
131@end menu
132
133INODE
134Differing file formats, Adding symbols from an object file, Adding Symbols to the Hash Table, Adding Symbols to the Hash Table
135SUBSUBSECTION
136 Differing file formats
137
138 Normally all the files involved in a link will be of the same
139 format, but it is also possible to link together different
140 format object files, and the back end must support that. The
141 <<_bfd_link_add_symbols>> entry point is called via the target
142 vector of the file to be added. This has an important
143 consequence: the function may not assume that the hash table
144 is the type created by the corresponding
145 <<_bfd_link_hash_table_create>> vector. All the
146 <<_bfd_link_add_symbols>> function can assume about the hash
147 table is that it is derived from <<struct
148 bfd_link_hash_table>>.
149
150 Sometimes the <<_bfd_link_add_symbols>> function must store
151 some information in the hash table entry to be used by the
152 <<_bfd_final_link>> function. In such a case the <<creator>>
153 field of the hash table must be checked to make sure that the
154 hash table was created by an object file of the same format.
155
156 The <<_bfd_final_link>> routine must be prepared to handle a
157 hash entry without any extra information added by the
158 <<_bfd_link_add_symbols>> function. A hash entry without
159 extra information will also occur when the linker script
160 directs the linker to create a symbol. Note that, regardless
161 of how a hash table entry is added, all the fields will be
162 initialized to some sort of null value by the hash table entry
163 initialization function.
164
165 See <<ecoff_link_add_externals>> for an example of how to
166 check the <<creator>> field before saving information (in this
167 case, the ECOFF external symbol debugging information) in a
168 hash table entry.
169
170INODE
171Adding symbols from an object file, Adding symbols from an archive, Differing file formats, Adding Symbols to the Hash Table
172SUBSUBSECTION
173 Adding symbols from an object file
174
175 When the <<_bfd_link_add_symbols>> routine is passed an object
176 file, it must add all externally visible symbols in that
177 object file to the hash table. The actual work of adding the
178 symbol to the hash table is normally handled by the function
179 <<_bfd_generic_link_add_one_symbol>>. The
180 <<_bfd_link_add_symbols>> routine is responsible for reading
181 all the symbols from the object file and passing the correct
182 information to <<_bfd_generic_link_add_one_symbol>>.
183
184 The <<_bfd_link_add_symbols>> routine should not use
185 <<bfd_canonicalize_symtab>> to read the symbols. The point of
186 providing this routine is to avoid the overhead of converting
187 the symbols into generic <<asymbol>> structures.
188
189@findex _bfd_generic_link_add_one_symbol
190 <<_bfd_generic_link_add_one_symbol>> handles the details of
191 combining common symbols, warning about multiple definitions,
192 and so forth. It takes arguments which describe the symbol to
193 add, notably symbol flags, a section, and an offset. The
194 symbol flags include such things as <<BSF_WEAK>> or
195 <<BSF_INDIRECT>>. The section is a section in the object
196 file, or something like <<bfd_und_section_ptr>> for an undefined
197 symbol or <<bfd_com_section_ptr>> for a common symbol.
198
199 If the <<_bfd_final_link>> routine is also going to need to
200 read the symbol information, the <<_bfd_link_add_symbols>>
201 routine should save it somewhere attached to the object file
202 BFD. However, the information should only be saved if the
203 <<keep_memory>> field of the <<info>> argument is true, so
204 that the <<-no-keep-memory>> linker switch is effective.
205
206 The a.out function which adds symbols from an object file is
207 <<aout_link_add_object_symbols>>, and most of the interesting
208 work is in <<aout_link_add_symbols>>. The latter saves
209 pointers to the hash tables entries created by
210 <<_bfd_generic_link_add_one_symbol>> indexed by symbol number,
211 so that the <<_bfd_final_link>> routine does not have to call
212 the hash table lookup routine to locate the entry.
213
214INODE
215Adding symbols from an archive, , Adding symbols from an object file, Adding Symbols to the Hash Table
216SUBSUBSECTION
217 Adding symbols from an archive
218
219 When the <<_bfd_link_add_symbols>> routine is passed an
220 archive, it must look through the symbols defined by the
221 archive and decide which elements of the archive should be
222 included in the link. For each such element it must call the
223 <<add_archive_element>> linker callback, and it must add the
224 symbols from the object file to the linker hash table.
225
226@findex _bfd_generic_link_add_archive_symbols
227 In most cases the work of looking through the symbols in the
228 archive should be done by the
229 <<_bfd_generic_link_add_archive_symbols>> function. This
230 function builds a hash table from the archive symbol table and
231 looks through the list of undefined symbols to see which
232 elements should be included.
233 <<_bfd_generic_link_add_archive_symbols>> is passed a function
234 to call to make the final decision about adding an archive
235 element to the link and to do the actual work of adding the
236 symbols to the linker hash table.
237
238 The function passed to
239 <<_bfd_generic_link_add_archive_symbols>> must read the
240 symbols of the archive element and decide whether the archive
241 element should be included in the link. If the element is to
242 be included, the <<add_archive_element>> linker callback
243 routine must be called with the element as an argument, and
244 the elements symbols must be added to the linker hash table
245 just as though the element had itself been passed to the
246 <<_bfd_link_add_symbols>> function.
247
248 When the a.out <<_bfd_link_add_symbols>> function receives an
249 archive, it calls <<_bfd_generic_link_add_archive_symbols>>
250 passing <<aout_link_check_archive_element>> as the function
251 argument. <<aout_link_check_archive_element>> calls
252 <<aout_link_check_ar_symbols>>. If the latter decides to add
253 the element (an element is only added if it provides a real,
254 non-common, definition for a previously undefined or common
255 symbol) it calls the <<add_archive_element>> callback and then
256 <<aout_link_check_archive_element>> calls
257 <<aout_link_add_symbols>> to actually add the symbols to the
258 linker hash table.
259
260 The ECOFF back end is unusual in that it does not normally
261 call <<_bfd_generic_link_add_archive_symbols>>, because ECOFF
262 archives already contain a hash table of symbols. The ECOFF
263 back end searches the archive itself to avoid the overhead of
264 creating a new hash table.
265
266INODE
267Performing the Final Link, , Adding Symbols to the Hash Table, Linker Functions
268SUBSECTION
269 Performing the final link
270
271@cindex _bfd_link_final_link in target vector
272@cindex target vector (_bfd_final_link)
273 When all the input files have been processed, the linker calls
274 the <<_bfd_final_link>> entry point of the output BFD. This
275 routine is responsible for producing the final output file,
276 which has several aspects. It must relocate the contents of
277 the input sections and copy the data into the output sections.
278 It must build an output symbol table including any local
279 symbols from the input files and the global symbols from the
280 hash table. When producing relocateable output, it must
281 modify the input relocs and write them into the output file.
282 There may also be object format dependent work to be done.
283
284 The linker will also call the <<write_object_contents>> entry
285 point when the BFD is closed. The two entry points must work
286 together in order to produce the correct output file.
287
288 The details of how this works are inevitably dependent upon
289 the specific object file format. The a.out
290 <<_bfd_final_link>> routine is <<NAME(aout,final_link)>>.
291
292@menu
293@* Information provided by the linker::
294@* Relocating the section contents::
295@* Writing the symbol table::
296@end menu
297
298INODE
299Information provided by the linker, Relocating the section contents, Performing the Final Link, Performing the Final Link
300SUBSUBSECTION
301 Information provided by the linker
302
303 Before the linker calls the <<_bfd_final_link>> entry point,
304 it sets up some data structures for the function to use.
305
306 The <<input_bfds>> field of the <<bfd_link_info>> structure
307 will point to a list of all the input files included in the
308 link. These files are linked through the <<link_next>> field
309 of the <<bfd>> structure.
310
311 Each section in the output file will have a list of
312 <<link_order>> structures attached to the <<link_order_head>>
313 field (the <<link_order>> structure is defined in
314 <<bfdlink.h>>). These structures describe how to create the
315 contents of the output section in terms of the contents of
316 various input sections, fill constants, and, eventually, other
317 types of information. They also describe relocs that must be
318 created by the BFD backend, but do not correspond to any input
319 file; this is used to support -Ur, which builds constructors
320 while generating a relocateable object file.
321
322INODE
323Relocating the section contents, Writing the symbol table, Information provided by the linker, Performing the Final Link
324SUBSUBSECTION
325 Relocating the section contents
326
327 The <<_bfd_final_link>> function should look through the
328 <<link_order>> structures attached to each section of the
329 output file. Each <<link_order>> structure should either be
330 handled specially, or it should be passed to the function
331 <<_bfd_default_link_order>> which will do the right thing
332 (<<_bfd_default_link_order>> is defined in <<linker.c>>).
333
334 For efficiency, a <<link_order>> of type
335 <<bfd_indirect_link_order>> whose associated section belongs
336 to a BFD of the same format as the output BFD must be handled
337 specially. This type of <<link_order>> describes part of an
338 output section in terms of a section belonging to one of the
339 input files. The <<_bfd_final_link>> function should read the
340 contents of the section and any associated relocs, apply the
341 relocs to the section contents, and write out the modified
342 section contents. If performing a relocateable link, the
343 relocs themselves must also be modified and written out.
344
345@findex _bfd_relocate_contents
346@findex _bfd_final_link_relocate
347 The functions <<_bfd_relocate_contents>> and
348 <<_bfd_final_link_relocate>> provide some general support for
349 performing the actual relocations, notably overflow checking.
350 Their arguments include information about the symbol the
351 relocation is against and a <<reloc_howto_type>> argument
352 which describes the relocation to perform. These functions
353 are defined in <<reloc.c>>.
354
355 The a.out function which handles reading, relocating, and
356 writing section contents is <<aout_link_input_section>>. The
357 actual relocation is done in <<aout_link_input_section_std>>
358 and <<aout_link_input_section_ext>>.
359
360INODE
361Writing the symbol table, , Relocating the section contents, Performing the Final Link
362SUBSUBSECTION
363 Writing the symbol table
364
365 The <<_bfd_final_link>> function must gather all the symbols
366 in the input files and write them out. It must also write out
367 all the symbols in the global hash table. This must be
368 controlled by the <<strip>> and <<discard>> fields of the
369 <<bfd_link_info>> structure.
370
371 The local symbols of the input files will not have been
372 entered into the linker hash table. The <<_bfd_final_link>>
373 routine must consider each input file and include the symbols
374 in the output file. It may be convenient to do this when
375 looking through the <<link_order>> structures, or it may be
376 done by stepping through the <<input_bfds>> list.
377
378 The <<_bfd_final_link>> routine must also traverse the global
379 hash table to gather all the externally visible symbols. It
380 is possible that most of the externally visible symbols may be
381 written out when considering the symbols of each input file,
382 but it is still necessary to traverse the hash table since the
383 linker script may have defined some symbols that are not in
384 any of the input files.
385
386 The <<strip>> field of the <<bfd_link_info>> structure
387 controls which symbols are written out. The possible values
388 are listed in <<bfdlink.h>>. If the value is <<strip_some>>,
389 then the <<keep_hash>> field of the <<bfd_link_info>>
390 structure is a hash table of symbols to keep; each symbol
391 should be looked up in this hash table, and only symbols which
392 are present should be included in the output file.
393
394 If the <<strip>> field of the <<bfd_link_info>> structure
395 permits local symbols to be written out, the <<discard>> field
396 is used to further controls which local symbols are included
397 in the output file. If the value is <<discard_l>>, then all
398 local symbols which begin with a certain prefix are discarded;
399 this is controlled by the <<bfd_is_local_label_name>> entry point.
400
401 The a.out backend handles symbols by calling
402 <<aout_link_write_symbols>> on each input BFD and then
403 traversing the global hash table with the function
404 <<aout_link_write_other_symbol>>. It builds a string table
405 while writing out the symbols, which is written to the output
406 file at the end of <<NAME(aout,final_link)>>.
407*/
408
409static boolean generic_link_read_symbols
410 PARAMS ((bfd *));
411static boolean generic_link_add_symbols
412 PARAMS ((bfd *, struct bfd_link_info *, boolean collect));
413static boolean generic_link_add_object_symbols
414 PARAMS ((bfd *, struct bfd_link_info *, boolean collect));
415static boolean generic_link_check_archive_element_no_collect
416 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded));
417static boolean generic_link_check_archive_element_collect
418 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded));
419static boolean generic_link_check_archive_element
420 PARAMS ((bfd *, struct bfd_link_info *, boolean *pneeded, boolean collect));
421static boolean generic_link_add_symbol_list
422 PARAMS ((bfd *, struct bfd_link_info *, bfd_size_type count, asymbol **,
423 boolean collect));
424static bfd *hash_entry_bfd PARAMS ((struct bfd_link_hash_entry *));
425static void set_symbol_from_hash
426 PARAMS ((asymbol *, struct bfd_link_hash_entry *));
427static boolean generic_add_output_symbol
428 PARAMS ((bfd *, size_t *psymalloc, asymbol *));
429static boolean default_fill_link_order
430 PARAMS ((bfd *, struct bfd_link_info *, asection *,
431 struct bfd_link_order *));
432static boolean default_indirect_link_order
433 PARAMS ((bfd *, struct bfd_link_info *, asection *,
434 struct bfd_link_order *, boolean));
435
436/* The link hash table structure is defined in bfdlink.h. It provides
437 a base hash table which the backend specific hash tables are built
438 upon. */
439
440/* Routine to create an entry in the link hash table. */
441
442struct bfd_hash_entry *
443_bfd_link_hash_newfunc (entry, table, string)
444 struct bfd_hash_entry *entry;
445 struct bfd_hash_table *table;
446 const char *string;
447{
448 struct bfd_link_hash_entry *ret = (struct bfd_link_hash_entry *) entry;
449
450 /* Allocate the structure if it has not already been allocated by a
451 subclass. */
452 if (ret == (struct bfd_link_hash_entry *) NULL)
453 ret = ((struct bfd_link_hash_entry *)
454 bfd_hash_allocate (table, sizeof (struct bfd_link_hash_entry)));
455 if (ret == (struct bfd_link_hash_entry *) NULL)
456 return NULL;
457
458 /* Call the allocation method of the superclass. */
459 ret = ((struct bfd_link_hash_entry *)
460 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
461
462 if (ret)
463 {
464 /* Initialize the local fields. */
465 ret->type = bfd_link_hash_new;
466 ret->next = NULL;
467 }
468
469 return (struct bfd_hash_entry *) ret;
470}
471
472/* Initialize a link hash table. The BFD argument is the one
473 responsible for creating this table. */
474
475boolean
476_bfd_link_hash_table_init (table, abfd, newfunc)
477 struct bfd_link_hash_table *table;
478 bfd *abfd;
479 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
480 struct bfd_hash_table *,
481 const char *));
482{
483 table->creator = abfd->xvec;
484 table->undefs = NULL;
485 table->undefs_tail = NULL;
486 return bfd_hash_table_init (&table->table, newfunc);
487}
488
489/* Look up a symbol in a link hash table. If follow is true, we
490 follow bfd_link_hash_indirect and bfd_link_hash_warning links to
491 the real symbol. */
492
493struct bfd_link_hash_entry *
494bfd_link_hash_lookup (table, string, create, copy, follow)
495 struct bfd_link_hash_table *table;
496 const char *string;
497 boolean create;
498 boolean copy;
499 boolean follow;
500{
501 struct bfd_link_hash_entry *ret;
502
503 ret = ((struct bfd_link_hash_entry *)
504 bfd_hash_lookup (&table->table, string, create, copy));
505
506 if (follow && ret != (struct bfd_link_hash_entry *) NULL)
507 {
508 while (ret->type == bfd_link_hash_indirect
509 || ret->type == bfd_link_hash_warning)
510 ret = ret->u.i.link;
511 }
512
513 return ret;
514}
515
516/* Look up a symbol in the main linker hash table if the symbol might
517 be wrapped. This should only be used for references to an
518 undefined symbol, not for definitions of a symbol. */
519
520struct bfd_link_hash_entry *
521bfd_wrapped_link_hash_lookup (abfd, info, string, create, copy, follow)
522 bfd *abfd;
523 struct bfd_link_info *info;
524 const char *string;
525 boolean create;
526 boolean copy;
527 boolean follow;
528{
529 if (info->wrap_hash != NULL)
530 {
531 const char *l;
532
533 l = string;
534 if (*l == bfd_get_symbol_leading_char (abfd))
535 ++l;
536
537#undef WRAP
538#define WRAP "__wrap_"
539
540 if (bfd_hash_lookup (info->wrap_hash, l, false, false) != NULL)
541 {
542 char *n;
543 struct bfd_link_hash_entry *h;
544
545 /* This symbol is being wrapped. We want to replace all
546 references to SYM with references to __wrap_SYM. */
547
548 n = (char *) bfd_malloc (strlen (l) + sizeof WRAP + 1);
549 if (n == NULL)
550 return NULL;
551
552 /* Note that symbol_leading_char may be '\0'. */
553 n[0] = bfd_get_symbol_leading_char (abfd);
554 n[1] = '\0';
555 strcat (n, WRAP);
556 strcat (n, l);
557 h = bfd_link_hash_lookup (info->hash, n, create, true, follow);
558 free (n);
559 return h;
560 }
561
562#undef WRAP
563
564#undef REAL
565#define REAL "__real_"
566
567 if (*l == '_'
568 && strncmp (l, REAL, sizeof REAL - 1) == 0
569 && bfd_hash_lookup (info->wrap_hash, l + sizeof REAL - 1,
570 false, false) != NULL)
571 {
572 char *n;
573 struct bfd_link_hash_entry *h;
574
575 /* This is a reference to __real_SYM, where SYM is being
576 wrapped. We want to replace all references to __real_SYM
577 with references to SYM. */
578
579 n = (char *) bfd_malloc (strlen (l + sizeof REAL - 1) + 2);
580 if (n == NULL)
581 return NULL;
582
583 /* Note that symbol_leading_char may be '\0'. */
584 n[0] = bfd_get_symbol_leading_char (abfd);
585 n[1] = '\0';
586 strcat (n, l + sizeof REAL - 1);
587 h = bfd_link_hash_lookup (info->hash, n, create, true, follow);
588 free (n);
589 return h;
590 }
591
592#undef REAL
593 }
594
595 return bfd_link_hash_lookup (info->hash, string, create, copy, follow);
596}
597
598/* Traverse a generic link hash table. The only reason this is not a
599 macro is to do better type checking. This code presumes that an
600 argument passed as a struct bfd_hash_entry * may be caught as a
601 struct bfd_link_hash_entry * with no explicit cast required on the
602 call. */
603
604void
605bfd_link_hash_traverse (table, func, info)
606 struct bfd_link_hash_table *table;
607 boolean (*func) PARAMS ((struct bfd_link_hash_entry *, PTR));
608 PTR info;
609{
610 bfd_hash_traverse (&table->table,
611 ((boolean (*) PARAMS ((struct bfd_hash_entry *, PTR)))
612 func),
613 info);
614}
615
616/* Add a symbol to the linker hash table undefs list. */
617
618INLINE void
619bfd_link_add_undef (table, h)
620 struct bfd_link_hash_table *table;
621 struct bfd_link_hash_entry *h;
622{
623 BFD_ASSERT (h->next == NULL);
624 if (table->undefs_tail != (struct bfd_link_hash_entry *) NULL)
625 table->undefs_tail->next = h;
626 if (table->undefs == (struct bfd_link_hash_entry *) NULL)
627 table->undefs = h;
628 table->undefs_tail = h;
629}
630
631
632/* Routine to create an entry in an generic link hash table. */
633
634struct bfd_hash_entry *
635_bfd_generic_link_hash_newfunc (entry, table, string)
636 struct bfd_hash_entry *entry;
637 struct bfd_hash_table *table;
638 const char *string;
639{
640 struct generic_link_hash_entry *ret =
641 (struct generic_link_hash_entry *) entry;
642
643 /* Allocate the structure if it has not already been allocated by a
644 subclass. */
645 if (ret == (struct generic_link_hash_entry *) NULL)
646 ret = ((struct generic_link_hash_entry *)
647 bfd_hash_allocate (table, sizeof (struct generic_link_hash_entry)));
648 if (ret == (struct generic_link_hash_entry *) NULL)
649 return NULL;
650
651 /* Call the allocation method of the superclass. */
652 ret = ((struct generic_link_hash_entry *)
653 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
654 table, string));
655
656 if (ret)
657 {
658 /* Set local fields. */
659 ret->written = false;
660 ret->sym = NULL;
661 }
662
663 return (struct bfd_hash_entry *) ret;
664}
665
666/* Create an generic link hash table. */
667
668struct bfd_link_hash_table *
669_bfd_generic_link_hash_table_create (abfd)
670 bfd *abfd;
671{
672 struct generic_link_hash_table *ret;
673
674 ret = ((struct generic_link_hash_table *)
675 bfd_alloc (abfd, sizeof (struct generic_link_hash_table)));
676 if (ret == NULL)
677 return (struct bfd_link_hash_table *) NULL;
678 if (! _bfd_link_hash_table_init (&ret->root, abfd,
679 _bfd_generic_link_hash_newfunc))
680 {
681 free (ret);
682 return (struct bfd_link_hash_table *) NULL;
683 }
684 return &ret->root;
685}
686
687/* Grab the symbols for an object file when doing a generic link. We
688 store the symbols in the outsymbols field. We need to keep them
689 around for the entire link to ensure that we only read them once.
690 If we read them multiple times, we might wind up with relocs and
691 the hash table pointing to different instances of the symbol
692 structure. */
693
694static boolean
695generic_link_read_symbols (abfd)
696 bfd *abfd;
697{
698 if (bfd_get_outsymbols (abfd) == (asymbol **) NULL)
699 {
700 long symsize;
701 long symcount;
702
703 symsize = bfd_get_symtab_upper_bound (abfd);
704 if (symsize < 0)
705 return false;
706 bfd_get_outsymbols (abfd) = (asymbol **) bfd_alloc (abfd, symsize);
707 if (bfd_get_outsymbols (abfd) == NULL && symsize != 0)
708 return false;
709 symcount = bfd_canonicalize_symtab (abfd, bfd_get_outsymbols (abfd));
710 if (symcount < 0)
711 return false;
712 bfd_get_symcount (abfd) = symcount;
713 }
714
715 return true;
716}
717
718
719/* Generic function to add symbols to from an object file to the
720 global hash table. This version does not automatically collect
721 constructors by name. */
722
723boolean
724_bfd_generic_link_add_symbols (abfd, info)
725 bfd *abfd;
726 struct bfd_link_info *info;
727{
728 return generic_link_add_symbols (abfd, info, false);
729}
730
731/* Generic function to add symbols from an object file to the global
732 hash table. This version automatically collects constructors by
733 name, as the collect2 program does. It should be used for any
734 target which does not provide some other mechanism for setting up
735 constructors and destructors; these are approximately those targets
736 for which gcc uses collect2 and do not support stabs. */
737
738boolean
739_bfd_generic_link_add_symbols_collect (abfd, info)
740 bfd *abfd;
741 struct bfd_link_info *info;
742{
743 return generic_link_add_symbols (abfd, info, true);
744}
745
746/* Add symbols from an object file to the global hash table. */
747
748static boolean
749generic_link_add_symbols (abfd, info, collect)
750 bfd *abfd;
751 struct bfd_link_info *info;
752 boolean collect;
753{
754 boolean ret;
755
756 switch (bfd_get_format (abfd))
757 {
758 case bfd_object:
759 ret = generic_link_add_object_symbols (abfd, info, collect);
760 break;
761 case bfd_archive:
762 ret = (_bfd_generic_link_add_archive_symbols
763 (abfd, info,
764 (collect
765 ? generic_link_check_archive_element_collect
766 : generic_link_check_archive_element_no_collect)));
767 break;
768 default:
769 bfd_set_error (bfd_error_wrong_format);
770 ret = false;
771 }
772
773 return ret;
774}
775
776/* Add symbols from an object file to the global hash table. */
777
778static boolean
779generic_link_add_object_symbols (abfd, info, collect)
780 bfd *abfd;
781 struct bfd_link_info *info;
782 boolean collect;
783{
784 if (! generic_link_read_symbols (abfd))
785 return false;
786 return generic_link_add_symbol_list (abfd, info,
787 _bfd_generic_link_get_symcount (abfd),
788 _bfd_generic_link_get_symbols (abfd),
789 collect);
790}
791
792
793/* We build a hash table of all symbols defined in an archive. */
794
795/* An archive symbol may be defined by multiple archive elements.
796 This linked list is used to hold the elements. */
797
798struct archive_list
799{
800 struct archive_list *next;
801 int indx;
802};
803
804/* An entry in an archive hash table. */
805
806struct archive_hash_entry
807{
808 struct bfd_hash_entry root;
809 /* Where the symbol is defined. */
810 struct archive_list *defs;
811};
812
813/* An archive hash table itself. */
814
815struct archive_hash_table
816{
817 struct bfd_hash_table table;
818};
819
820static struct bfd_hash_entry *archive_hash_newfunc
821 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));
822static boolean archive_hash_table_init
823 PARAMS ((struct archive_hash_table *,
824 struct bfd_hash_entry *(*) (struct bfd_hash_entry *,
825 struct bfd_hash_table *,
826 const char *)));
827
828/* Create a new entry for an archive hash table. */
829
830static struct bfd_hash_entry *
831archive_hash_newfunc (entry, table, string)
832 struct bfd_hash_entry *entry;
833 struct bfd_hash_table *table;
834 const char *string;
835{
836 struct archive_hash_entry *ret = (struct archive_hash_entry *) entry;
837
838 /* Allocate the structure if it has not already been allocated by a
839 subclass. */
840 if (ret == (struct archive_hash_entry *) NULL)
841 ret = ((struct archive_hash_entry *)
842 bfd_hash_allocate (table, sizeof (struct archive_hash_entry)));
843 if (ret == (struct archive_hash_entry *) NULL)
844 return NULL;
845
846 /* Call the allocation method of the superclass. */
847 ret = ((struct archive_hash_entry *)
848 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
849
850 if (ret)
851 {
852 /* Initialize the local fields. */
853 ret->defs = (struct archive_list *) NULL;
854 }
855
856 return (struct bfd_hash_entry *) ret;
857}
858
859/* Initialize an archive hash table. */
860
861static boolean
862archive_hash_table_init (table, newfunc)
863 struct archive_hash_table *table;
864 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
865 struct bfd_hash_table *,
866 const char *));
867{
868 return bfd_hash_table_init (&table->table, newfunc);
869}
870
871/* Look up an entry in an archive hash table. */
872
873#define archive_hash_lookup(t, string, create, copy) \
874 ((struct archive_hash_entry *) \
875 bfd_hash_lookup (&(t)->table, (string), (create), (copy)))
876
877/* Allocate space in an archive hash table. */
878
879#define archive_hash_allocate(t, size) bfd_hash_allocate (&(t)->table, (size))
880
881/* Free an archive hash table. */
882
883#define archive_hash_table_free(t) bfd_hash_table_free (&(t)->table)
884
885/* Generic function to add symbols from an archive file to the global
886 hash file. This function presumes that the archive symbol table
887 has already been read in (this is normally done by the
888 bfd_check_format entry point). It looks through the undefined and
889 common symbols and searches the archive symbol table for them. If
890 it finds an entry, it includes the associated object file in the
891 link.
892
893 The old linker looked through the archive symbol table for
894 undefined symbols. We do it the other way around, looking through
895 undefined symbols for symbols defined in the archive. The
896 advantage of the newer scheme is that we only have to look through
897 the list of undefined symbols once, whereas the old method had to
898 re-search the symbol table each time a new object file was added.
899
900 The CHECKFN argument is used to see if an object file should be
901 included. CHECKFN should set *PNEEDED to true if the object file
902 should be included, and must also call the bfd_link_info
903 add_archive_element callback function and handle adding the symbols
904 to the global hash table. CHECKFN should only return false if some
905 sort of error occurs.
906
907 For some formats, such as a.out, it is possible to look through an
908 object file but not actually include it in the link. The
909 archive_pass field in a BFD is used to avoid checking the symbols
910 of an object files too many times. When an object is included in
911 the link, archive_pass is set to -1. If an object is scanned but
912 not included, archive_pass is set to the pass number. The pass
913 number is incremented each time a new object file is included. The
914 pass number is used because when a new object file is included it
915 may create new undefined symbols which cause a previously examined
916 object file to be included. */
917
918boolean
919_bfd_generic_link_add_archive_symbols (abfd, info, checkfn)
920 bfd *abfd;
921 struct bfd_link_info *info;
922 boolean (*checkfn) PARAMS ((bfd *, struct bfd_link_info *,
923 boolean *pneeded));
924{
925 carsym *arsyms;
926 carsym *arsym_end;
927 register carsym *arsym;
928 int pass;
929 struct archive_hash_table arsym_hash;
930 int indx;
931 struct bfd_link_hash_entry **pundef;
932
933 if (! bfd_has_map (abfd))
934 {
935 /* An empty archive is a special case. */
936 if (bfd_openr_next_archived_file (abfd, (bfd *) NULL) == NULL)
937 return true;
938 bfd_set_error (bfd_error_no_armap);
939 return false;
940 }
941
942 arsyms = bfd_ardata (abfd)->symdefs;
943 arsym_end = arsyms + bfd_ardata (abfd)->symdef_count;
944
945 /* In order to quickly determine whether an symbol is defined in
946 this archive, we build a hash table of the symbols. */
947 if (! archive_hash_table_init (&arsym_hash, archive_hash_newfunc))
948 return false;
949 for (arsym = arsyms, indx = 0; arsym < arsym_end; arsym++, indx++)
950 {
951 struct archive_hash_entry *arh;
952 struct archive_list *l, **pp;
953
954 arh = archive_hash_lookup (&arsym_hash, arsym->name, true, false);
955 if (arh == (struct archive_hash_entry *) NULL)
956 goto error_return;
957 l = ((struct archive_list *)
958 archive_hash_allocate (&arsym_hash, sizeof (struct archive_list)));
959 if (l == NULL)
960 goto error_return;
961 l->indx = indx;
962 for (pp = &arh->defs;
963 *pp != (struct archive_list *) NULL;
964 pp = &(*pp)->next)
965 ;
966 *pp = l;
967 l->next = NULL;
968 }
969
970 /* The archive_pass field in the archive itself is used to
971 initialize PASS, sine we may search the same archive multiple
972 times. */
973 pass = abfd->archive_pass + 1;
974
975 /* New undefined symbols are added to the end of the list, so we
976 only need to look through it once. */
977 pundef = &info->hash->undefs;
978 while (*pundef != (struct bfd_link_hash_entry *) NULL)
979 {
980 struct bfd_link_hash_entry *h;
981 struct archive_hash_entry *arh;
982 struct archive_list *l;
983
984 h = *pundef;
985
986 /* When a symbol is defined, it is not necessarily removed from
987 the list. */
988 if (h->type != bfd_link_hash_undefined
989 && h->type != bfd_link_hash_common)
990 {
991 /* Remove this entry from the list, for general cleanliness
992 and because we are going to look through the list again
993 if we search any more libraries. We can't remove the
994 entry if it is the tail, because that would lose any
995 entries we add to the list later on (it would also cause
996 us to lose track of whether the symbol has been
997 referenced). */
998 if (*pundef != info->hash->undefs_tail)
999 *pundef = (*pundef)->next;
1000 else
1001 pundef = &(*pundef)->next;
1002 continue;
1003 }
1004
1005 /* Look for this symbol in the archive symbol map. */
1006 arh = archive_hash_lookup (&arsym_hash, h->root.string, false, false);
1007 if (arh == (struct archive_hash_entry *) NULL)
1008 {
1009 pundef = &(*pundef)->next;
1010 continue;
1011 }
1012
1013 /* Look at all the objects which define this symbol. */
1014 for (l = arh->defs; l != (struct archive_list *) NULL; l = l->next)
1015 {
1016 bfd *element;
1017 boolean needed;
1018
1019 /* If the symbol has gotten defined along the way, quit. */
1020 if (h->type != bfd_link_hash_undefined
1021 && h->type != bfd_link_hash_common)
1022 break;
1023
1024 element = bfd_get_elt_at_index (abfd, l->indx);
1025 if (element == (bfd *) NULL)
1026 goto error_return;
1027
1028 /* If we've already included this element, or if we've
1029 already checked it on this pass, continue. */
1030 if (element->archive_pass == -1
1031 || element->archive_pass == pass)
1032 continue;
1033
1034 /* If we can't figure this element out, just ignore it. */
1035 if (! bfd_check_format (element, bfd_object))
1036 {
1037 element->archive_pass = -1;
1038 continue;
1039 }
1040
1041 /* CHECKFN will see if this element should be included, and
1042 go ahead and include it if appropriate. */
1043 if (! (*checkfn) (element, info, &needed))
1044 goto error_return;
1045
1046 if (! needed)
1047 element->archive_pass = pass;
1048 else
1049 {
1050 element->archive_pass = -1;
1051
1052 /* Increment the pass count to show that we may need to
1053 recheck object files which were already checked. */
1054 ++pass;
1055 }
1056 }
1057
1058 pundef = &(*pundef)->next;
1059 }
1060
1061 archive_hash_table_free (&arsym_hash);
1062
1063 /* Save PASS in case we are called again. */
1064 abfd->archive_pass = pass;
1065
1066 return true;
1067
1068 error_return:
1069 archive_hash_table_free (&arsym_hash);
1070 return false;
1071}
1072
1073
1074/* See if we should include an archive element. This version is used
1075 when we do not want to automatically collect constructors based on
1076 the symbol name, presumably because we have some other mechanism
1077 for finding them. */
1078
1079static boolean
1080generic_link_check_archive_element_no_collect (abfd, info, pneeded)
1081 bfd *abfd;
1082 struct bfd_link_info *info;
1083 boolean *pneeded;
1084{
1085 return generic_link_check_archive_element (abfd, info, pneeded, false);
1086}
1087
1088/* See if we should include an archive element. This version is used
1089 when we want to automatically collect constructors based on the
1090 symbol name, as collect2 does. */
1091
1092static boolean
1093generic_link_check_archive_element_collect (abfd, info, pneeded)
1094 bfd *abfd;
1095 struct bfd_link_info *info;
1096 boolean *pneeded;
1097{
1098 return generic_link_check_archive_element (abfd, info, pneeded, true);
1099}
1100
1101/* See if we should include an archive element. Optionally collect
1102 constructors. */
1103
1104static boolean
1105generic_link_check_archive_element (abfd, info, pneeded, collect)
1106 bfd *abfd;
1107 struct bfd_link_info *info;
1108 boolean *pneeded;
1109 boolean collect;
1110{
1111 asymbol **pp, **ppend;
1112
1113 *pneeded = false;
1114
1115 if (! generic_link_read_symbols (abfd))
1116 return false;
1117
1118 pp = _bfd_generic_link_get_symbols (abfd);
1119 ppend = pp + _bfd_generic_link_get_symcount (abfd);
1120 for (; pp < ppend; pp++)
1121 {
1122 asymbol *p;
1123 struct bfd_link_hash_entry *h;
1124
1125 p = *pp;
1126
1127 /* We are only interested in globally visible symbols. */
1128 if (! bfd_is_com_section (p->section)
1129 && (p->flags & (BSF_GLOBAL | BSF_INDIRECT | BSF_WEAK)) == 0)
1130 continue;
1131
1132 /* We are only interested if we know something about this
1133 symbol, and it is undefined or common. An undefined weak
1134 symbol (type bfd_link_hash_undefweak) is not considered to be
1135 a reference when pulling files out of an archive. See the
1136 SVR4 ABI, p. 4-27. */
1137 h = bfd_link_hash_lookup (info->hash, bfd_asymbol_name (p), false,
1138 false, true);
1139 if (h == (struct bfd_link_hash_entry *) NULL
1140 || (h->type != bfd_link_hash_undefined
1141 && h->type != bfd_link_hash_common))
1142 continue;
1143
1144 /* P is a symbol we are looking for. */
1145
1146 if (! bfd_is_com_section (p->section))
1147 {
1148 bfd_size_type symcount;
1149 asymbol **symbols;
1150
1151 /* This object file defines this symbol, so pull it in. */
1152 if (! (*info->callbacks->add_archive_element) (info, abfd,
1153 bfd_asymbol_name (p)))
1154 return false;
1155 symcount = _bfd_generic_link_get_symcount (abfd);
1156 symbols = _bfd_generic_link_get_symbols (abfd);
1157 if (! generic_link_add_symbol_list (abfd, info, symcount,
1158 symbols, collect))
1159 return false;
1160 *pneeded = true;
1161 return true;
1162 }
1163
1164 /* P is a common symbol. */
1165
1166 if (h->type == bfd_link_hash_undefined)
1167 {
1168 bfd *symbfd;
1169 bfd_vma size;
1170 unsigned int power;
1171
1172 symbfd = h->u.undef.abfd;
1173 if (symbfd == (bfd *) NULL)
1174 {
1175 /* This symbol was created as undefined from outside
1176 BFD. We assume that we should link in the object
1177 file. This is for the -u option in the linker. */
1178 if (! (*info->callbacks->add_archive_element)
1179 (info, abfd, bfd_asymbol_name (p)))
1180 return false;
1181 *pneeded = true;
1182 return true;
1183 }
1184
1185 /* Turn the symbol into a common symbol but do not link in
1186 the object file. This is how a.out works. Object
1187 formats that require different semantics must implement
1188 this function differently. This symbol is already on the
1189 undefs list. We add the section to a common section
1190 attached to symbfd to ensure that it is in a BFD which
1191 will be linked in. */
1192 h->type = bfd_link_hash_common;
1193 h->u.c.p =
1194 ((struct bfd_link_hash_common_entry *)
1195 bfd_hash_allocate (&info->hash->table,
1196 sizeof (struct bfd_link_hash_common_entry)));
1197 if (h->u.c.p == NULL)
1198 return false;
1199
1200 size = bfd_asymbol_value (p);
1201 h->u.c.size = size;
1202
1203 power = bfd_log2 (size);
1204 if (power > 4)
1205 power = 4;
1206 h->u.c.p->alignment_power = power;
1207
1208 if (p->section == bfd_com_section_ptr)
1209 h->u.c.p->section = bfd_make_section_old_way (symbfd, "COMMON");
1210 else
1211 h->u.c.p->section = bfd_make_section_old_way (symbfd,
1212 p->section->name);
1213 h->u.c.p->section->flags = SEC_ALLOC;
1214 }
1215 else
1216 {
1217 /* Adjust the size of the common symbol if necessary. This
1218 is how a.out works. Object formats that require
1219 different semantics must implement this function
1220 differently. */
1221 if (bfd_asymbol_value (p) > h->u.c.size)
1222 h->u.c.size = bfd_asymbol_value (p);
1223 }
1224 }
1225
1226 /* This archive element is not needed. */
1227 return true;
1228}
1229
1230/* Add the symbols from an object file to the global hash table. ABFD
1231 is the object file. INFO is the linker information. SYMBOL_COUNT
1232 is the number of symbols. SYMBOLS is the list of symbols. COLLECT
1233 is true if constructors should be automatically collected by name
1234 as is done by collect2. */
1235
1236static boolean
1237generic_link_add_symbol_list (abfd, info, symbol_count, symbols, collect)
1238 bfd *abfd;
1239 struct bfd_link_info *info;
1240 bfd_size_type symbol_count;
1241 asymbol **symbols;
1242 boolean collect;
1243{
1244 asymbol **pp, **ppend;
1245
1246 pp = symbols;
1247 ppend = symbols + symbol_count;
1248 for (; pp < ppend; pp++)
1249 {
1250 asymbol *p;
1251
1252 p = *pp;
1253
1254 if ((p->flags & (BSF_INDIRECT
1255 | BSF_WARNING
1256 | BSF_GLOBAL
1257 | BSF_CONSTRUCTOR
1258 | BSF_WEAK)) != 0
1259 || bfd_is_und_section (bfd_get_section (p))
1260 || bfd_is_com_section (bfd_get_section (p))
1261 || bfd_is_ind_section (bfd_get_section (p)))
1262 {
1263 const char *name;
1264 const char *string;
1265 struct generic_link_hash_entry *h;
1266
1267 name = bfd_asymbol_name (p);
1268 if (((p->flags & BSF_INDIRECT) != 0
1269 || bfd_is_ind_section (p->section))
1270 && pp + 1 < ppend)
1271 {
1272 pp++;
1273 string = bfd_asymbol_name (*pp);
1274 }
1275 else if ((p->flags & BSF_WARNING) != 0
1276 && pp + 1 < ppend)
1277 {
1278 /* The name of P is actually the warning string, and the
1279 next symbol is the one to warn about. */
1280 string = name;
1281 pp++;
1282 name = bfd_asymbol_name (*pp);
1283 }
1284 else
1285 string = NULL;
1286
1287 h = NULL;
1288 if (! (_bfd_generic_link_add_one_symbol
1289 (info, abfd, name, p->flags, bfd_get_section (p),
1290 p->value, string, false, collect,
1291 (struct bfd_link_hash_entry **) &h)))
1292 return false;
1293
1294 /* If this is a constructor symbol, and the linker didn't do
1295 anything with it, then we want to just pass the symbol
1296 through to the output file. This will happen when
1297 linking with -r. */
1298 if ((p->flags & BSF_CONSTRUCTOR) != 0
1299 && (h == NULL || h->root.type == bfd_link_hash_new))
1300 {
1301 p->udata.p = NULL;
1302 continue;
1303 }
1304
1305 /* Save the BFD symbol so that we don't lose any backend
1306 specific information that may be attached to it. We only
1307 want this one if it gives more information than the
1308 existing one; we don't want to replace a defined symbol
1309 with an undefined one. This routine may be called with a
1310 hash table other than the generic hash table, so we only
1311 do this if we are certain that the hash table is a
1312 generic one. */
1313 if (info->hash->creator == abfd->xvec)
1314 {
1315 if (h->sym == (asymbol *) NULL
1316 || (! bfd_is_und_section (bfd_get_section (p))
1317 && (! bfd_is_com_section (bfd_get_section (p))
1318 || bfd_is_und_section (bfd_get_section (h->sym)))))
1319 {
1320 h->sym = p;
1321 /* BSF_OLD_COMMON is a hack to support COFF reloc
1322 reading, and it should go away when the COFF
1323 linker is switched to the new version. */
1324 if (bfd_is_com_section (bfd_get_section (p)))
1325 p->flags |= BSF_OLD_COMMON;
1326 }
1327 }
1328
1329 /* Store a back pointer from the symbol to the hash
1330 table entry for the benefit of relaxation code until
1331 it gets rewritten to not use asymbol structures.
1332 Setting this is also used to check whether these
1333 symbols were set up by the generic linker. */
1334 p->udata.p = (PTR) h;
1335 }
1336 }
1337
1338 return true;
1339}
1340
1341
1342/* We use a state table to deal with adding symbols from an object
1343 file. The first index into the state table describes the symbol
1344 from the object file. The second index into the state table is the
1345 type of the symbol in the hash table. */
1346
1347/* The symbol from the object file is turned into one of these row
1348 values. */
1349
1350enum link_row
1351{
1352 UNDEF_ROW, /* Undefined. */
1353 UNDEFW_ROW, /* Weak undefined. */
1354 DEF_ROW, /* Defined. */
1355 DEFW_ROW, /* Weak defined. */
1356 COMMON_ROW, /* Common. */
1357 INDR_ROW, /* Indirect. */
1358 WARN_ROW, /* Warning. */
1359 SET_ROW /* Member of set. */
1360};
1361
1362/* apparently needed for Hitachi 3050R(HI-UX/WE2)? */
1363#undef FAIL
1364
1365/* The actions to take in the state table. */
1366
1367enum link_action
1368{
1369 FAIL, /* Abort. */
1370 UND, /* Mark symbol undefined. */
1371 WEAK, /* Mark symbol weak undefined. */
1372 DEF, /* Mark symbol defined. */
1373 DEFW, /* Mark symbol weak defined. */
1374 COM, /* Mark symbol common. */
1375 REF, /* Mark defined symbol referenced. */
1376 CREF, /* Possibly warn about common reference to defined symbol. */
1377 CDEF, /* Define existing common symbol. */
1378 NOACT, /* No action. */
1379 BIG, /* Mark symbol common using largest size. */
1380 MDEF, /* Multiple definition error. */
1381 MIND, /* Multiple indirect symbols. */
1382 IND, /* Make indirect symbol. */
1383 CIND, /* Make indirect symbol from existing common symbol. */
1384 SET, /* Add value to set. */
1385 MWARN, /* Make warning symbol. */
1386 WARN, /* Issue warning. */
1387 CWARN, /* Warn if referenced, else MWARN. */
1388 CYCLE, /* Repeat with symbol pointed to. */
1389 REFC, /* Mark indirect symbol referenced and then CYCLE. */
1390 WARNC /* Issue warning and then CYCLE. */
1391};
1392
1393/* The state table itself. The first index is a link_row and the
1394 second index is a bfd_link_hash_type. */
1395
1396static const enum link_action link_action[8][8] =
1397{
1398 /* current\prev new undef undefw def defw com indr warn */
1399 /* UNDEF_ROW */ {UND, NOACT, UND, REF, REF, NOACT, REFC, WARNC },
1400 /* UNDEFW_ROW */ {WEAK, NOACT, NOACT, REF, REF, NOACT, REFC, WARNC },
1401 /* DEF_ROW */ {DEF, DEF, DEF, MDEF, DEF, CDEF, MDEF, CYCLE },
1402 /* DEFW_ROW */ {DEFW, DEFW, DEFW, NOACT, NOACT, NOACT, NOACT, CYCLE },
1403 /* COMMON_ROW */ {COM, COM, COM, CREF, CREF, BIG, REFC, WARNC },
1404 /* INDR_ROW */ {IND, IND, IND, MDEF, IND, CIND, MIND, CYCLE },
1405 /* WARN_ROW */ {MWARN, WARN, WARN, CWARN, CWARN, WARN, CWARN, MWARN },
1406 /* SET_ROW */ {SET, SET, SET, SET, SET, SET, CYCLE, CYCLE }
1407};
1408
1409/* Most of the entries in the LINK_ACTION table are straightforward,
1410 but a few are somewhat subtle.
1411
1412 A reference to an indirect symbol (UNDEF_ROW/indr or
1413 UNDEFW_ROW/indr) is counted as a reference both to the indirect
1414 symbol and to the symbol the indirect symbol points to.
1415
1416 A reference to a warning symbol (UNDEF_ROW/warn or UNDEFW_ROW/warn)
1417 causes the warning to be issued.
1418
1419 A common definition of an indirect symbol (COMMON_ROW/indr) is
1420 treated as a multiple definition error. Likewise for an indirect
1421 definition of a common symbol (INDR_ROW/com).
1422
1423 An indirect definition of a warning (INDR_ROW/warn) does not cause
1424 the warning to be issued.
1425
1426 If a warning is created for an indirect symbol (WARN_ROW/indr) no
1427 warning is created for the symbol the indirect symbol points to.
1428
1429 Adding an entry to a set does not count as a reference to a set,
1430 and no warning is issued (SET_ROW/warn). */
1431
1432/* Return the BFD in which a hash entry has been defined, if known. */
1433
1434static bfd *
1435hash_entry_bfd (h)
1436 struct bfd_link_hash_entry *h;
1437{
1438 while (h->type == bfd_link_hash_warning)
1439 h = h->u.i.link;
1440 switch (h->type)
1441 {
1442 default:
1443 return NULL;
1444 case bfd_link_hash_undefined:
1445 case bfd_link_hash_undefweak:
1446 return h->u.undef.abfd;
1447 case bfd_link_hash_defined:
1448 case bfd_link_hash_defweak:
1449 return h->u.def.section->owner;
1450 case bfd_link_hash_common:
1451 return h->u.c.p->section->owner;
1452 }
1453 /*NOTREACHED*/
1454}
1455
1456/* Add a symbol to the global hash table.
1457 ABFD is the BFD the symbol comes from.
1458 NAME is the name of the symbol.
1459 FLAGS is the BSF_* bits associated with the symbol.
1460 SECTION is the section in which the symbol is defined; this may be
1461 bfd_und_section_ptr or bfd_com_section_ptr.
1462 VALUE is the value of the symbol, relative to the section.
1463 STRING is used for either an indirect symbol, in which case it is
1464 the name of the symbol to indirect to, or a warning symbol, in
1465 which case it is the warning string.
1466 COPY is true if NAME or STRING must be copied into locally
1467 allocated memory if they need to be saved.
1468 COLLECT is true if we should automatically collect gcc constructor
1469 or destructor names as collect2 does.
1470 HASHP, if not NULL, is a place to store the created hash table
1471 entry; if *HASHP is not NULL, the caller has already looked up
1472 the hash table entry, and stored it in *HASHP. */
1473
1474boolean
1475_bfd_generic_link_add_one_symbol (info, abfd, name, flags, section, value,
1476 string, copy, collect, hashp)
1477 struct bfd_link_info *info;
1478 bfd *abfd;
1479 const char *name;
1480 flagword flags;
1481 asection *section;
1482 bfd_vma value;
1483 const char *string;
1484 boolean copy;
1485 boolean collect;
1486 struct bfd_link_hash_entry **hashp;
1487{
1488 enum link_row row;
1489 struct bfd_link_hash_entry *h;
1490 boolean cycle;
1491
1492 if (bfd_is_ind_section (section)
1493 || (flags & BSF_INDIRECT) != 0)
1494 row = INDR_ROW;
1495 else if ((flags & BSF_WARNING) != 0)
1496 row = WARN_ROW;
1497 else if ((flags & BSF_CONSTRUCTOR) != 0)
1498 row = SET_ROW;
1499 else if (bfd_is_und_section (section))
1500 {
1501 if ((flags & BSF_WEAK) != 0)
1502 row = UNDEFW_ROW;
1503 else
1504 row = UNDEF_ROW;
1505 }
1506 else if ((flags & BSF_WEAK) != 0)
1507 row = DEFW_ROW;
1508 else if (bfd_is_com_section (section))
1509 row = COMMON_ROW;
1510 else
1511 row = DEF_ROW;
1512
1513 if (hashp != NULL && *hashp != NULL)
1514 h = *hashp;
1515 else
1516 {
1517 if (row == UNDEF_ROW || row == UNDEFW_ROW)
1518 h = bfd_wrapped_link_hash_lookup (abfd, info, name, true, copy, false);
1519 else
1520 h = bfd_link_hash_lookup (info->hash, name, true, copy, false);
1521 if (h == NULL)
1522 {
1523 if (hashp != NULL)
1524 *hashp = NULL;
1525 return false;
1526 }
1527 }
1528
1529 if (info->notice_all
1530 || (info->notice_hash != (struct bfd_hash_table *) NULL
1531 && (bfd_hash_lookup (info->notice_hash, name, false, false)
1532 != (struct bfd_hash_entry *) NULL)))
1533 {
1534 if (! (*info->callbacks->notice) (info, h->root.string, abfd, section,
1535 value))
1536 return false;
1537 }
1538
1539 if (hashp != (struct bfd_link_hash_entry **) NULL)
1540 *hashp = h;
1541
1542 do
1543 {
1544 enum link_action action;
1545
1546 cycle = false;
1547 action = link_action[(int) row][(int) h->type];
1548 switch (action)
1549 {
1550 case FAIL:
1551 abort ();
1552
1553 case NOACT:
1554 /* Do nothing. */
1555 break;
1556
1557 case UND:
1558 /* Make a new undefined symbol. */
1559 h->type = bfd_link_hash_undefined;
1560 h->u.undef.abfd = abfd;
1561 bfd_link_add_undef (info->hash, h);
1562 break;
1563
1564 case WEAK:
1565 /* Make a new weak undefined symbol. */
1566 h->type = bfd_link_hash_undefweak;
1567 h->u.undef.abfd = abfd;
1568 break;
1569
1570 case CDEF:
1571 /* We have found a definition for a symbol which was
1572 previously common. */
1573 BFD_ASSERT (h->type == bfd_link_hash_common);
1574 if (! ((*info->callbacks->multiple_common)
1575 (info, h->root.string,
1576 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
1577 abfd, bfd_link_hash_defined, (bfd_vma) 0)))
1578 return false;
1579 /* Fall through. */
1580 case DEF:
1581 case DEFW:
1582 {
1583 enum bfd_link_hash_type oldtype;
1584
1585 /* Define a symbol. */
1586 oldtype = h->type;
1587 if (action == DEFW)
1588 h->type = bfd_link_hash_defweak;
1589 else
1590 h->type = bfd_link_hash_defined;
1591 h->u.def.section = section;
1592 h->u.def.value = value;
1593
1594 /* If we have been asked to, we act like collect2 and
1595 identify all functions that might be global
1596 constructors and destructors and pass them up in a
1597 callback. We only do this for certain object file
1598 types, since many object file types can handle this
1599 automatically. */
1600 if (collect && name[0] == '_')
1601 {
1602 const char *s;
1603
1604 /* A constructor or destructor name starts like this:
1605 _+GLOBAL_[_.$][ID][_.$] where the first [_.$] and
1606 the second are the same character (we accept any
1607 character there, in case a new object file format
1608 comes along with even worse naming restrictions). */
1609
1610#define CONS_PREFIX "GLOBAL_"
1611#define CONS_PREFIX_LEN (sizeof CONS_PREFIX - 1)
1612
1613 s = name + 1;
1614 while (*s == '_')
1615 ++s;
1616 if (s[0] == 'G'
1617 && strncmp (s, CONS_PREFIX, CONS_PREFIX_LEN - 1) == 0)
1618 {
1619 char c;
1620
1621 c = s[CONS_PREFIX_LEN + 1];
1622 if ((c == 'I' || c == 'D')
1623 && s[CONS_PREFIX_LEN] == s[CONS_PREFIX_LEN + 2])
1624 {
1625 /* If this is a definition of a symbol which
1626 was previously weakly defined, we are in
1627 trouble. We have already added a
1628 constructor entry for the weak defined
1629 symbol, and now we are trying to add one
1630 for the new symbol. Fortunately, this case
1631 should never arise in practice. */
1632 if (oldtype == bfd_link_hash_defweak)
1633 abort ();
1634
1635 if (! ((*info->callbacks->constructor)
1636 (info,
1637 c == 'I' ? true : false,
1638 h->root.string, abfd, section, value)))
1639 return false;
1640 }
1641 }
1642 }
1643 }
1644
1645 break;
1646
1647 case COM:
1648 /* We have found a common definition for a symbol. */
1649 if (h->type == bfd_link_hash_new)
1650 bfd_link_add_undef (info->hash, h);
1651 h->type = bfd_link_hash_common;
1652 h->u.c.p =
1653 ((struct bfd_link_hash_common_entry *)
1654 bfd_hash_allocate (&info->hash->table,
1655 sizeof (struct bfd_link_hash_common_entry)));
1656 if (h->u.c.p == NULL)
1657 return false;
1658
1659 h->u.c.size = value;
1660
1661 /* Select a default alignment based on the size. This may
1662 be overridden by the caller. */
1663 {
1664 unsigned int power;
1665
1666 power = bfd_log2 (value);
1667 if (power > 4)
1668 power = 4;
1669 h->u.c.p->alignment_power = power;
1670 }
1671
1672 /* The section of a common symbol is only used if the common
1673 symbol is actually allocated. It basically provides a
1674 hook for the linker script to decide which output section
1675 the common symbols should be put in. In most cases, the
1676 section of a common symbol will be bfd_com_section_ptr,
1677 the code here will choose a common symbol section named
1678 "COMMON", and the linker script will contain *(COMMON) in
1679 the appropriate place. A few targets use separate common
1680 sections for small symbols, and they require special
1681 handling. */
1682 if (section == bfd_com_section_ptr)
1683 {
1684 h->u.c.p->section = bfd_make_section_old_way (abfd, "COMMON");
1685 h->u.c.p->section->flags = SEC_ALLOC;
1686 }
1687 else if (section->owner != abfd)
1688 {
1689 h->u.c.p->section = bfd_make_section_old_way (abfd,
1690 section->name);
1691 h->u.c.p->section->flags = SEC_ALLOC;
1692 }
1693 else
1694 h->u.c.p->section = section;
1695 break;
1696
1697 case REF:
1698 /* A reference to a defined symbol. */
1699 if (h->next == NULL && info->hash->undefs_tail != h)
1700 h->next = h;
1701 break;
1702
1703 case BIG:
1704 /* We have found a common definition for a symbol which
1705 already had a common definition. Use the maximum of the
1706 two sizes. */
1707 BFD_ASSERT (h->type == bfd_link_hash_common);
1708 if (! ((*info->callbacks->multiple_common)
1709 (info, h->root.string,
1710 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
1711 abfd, bfd_link_hash_common, value)))
1712 return false;
1713 if (value > h->u.c.size)
1714 {
1715 unsigned int power;
1716
1717 h->u.c.size = value;
1718
1719 /* Select a default alignment based on the size. This may
1720 be overridden by the caller. */
1721 power = bfd_log2 (value);
1722 if (power > 4)
1723 power = 4;
1724 h->u.c.p->alignment_power = power;
1725 }
1726 break;
1727
1728 case CREF:
1729 {
1730 bfd *obfd;
1731
1732 /* We have found a common definition for a symbol which
1733 was already defined. FIXME: It would nice if we could
1734 report the BFD which defined an indirect symbol, but we
1735 don't have anywhere to store the information. */
1736 if (h->type == bfd_link_hash_defined
1737 || h->type == bfd_link_hash_defweak)
1738 obfd = h->u.def.section->owner;
1739 else
1740 obfd = NULL;
1741 if (! ((*info->callbacks->multiple_common)
1742 (info, h->root.string, obfd, h->type, (bfd_vma) 0,
1743 abfd, bfd_link_hash_common, value)))
1744 return false;
1745 }
1746 break;
1747
1748 case MIND:
1749 /* Multiple indirect symbols. This is OK if they both point
1750 to the same symbol. */
1751 if (strcmp (h->u.i.link->root.string, string) == 0)
1752 break;
1753 /* Fall through. */
1754 case MDEF:
1755 /* Handle a multiple definition. */
1756 {
1757 asection *msec = NULL;
1758 bfd_vma mval = 0;
1759
1760 switch (h->type)
1761 {
1762 case bfd_link_hash_defined:
1763 msec = h->u.def.section;
1764 mval = h->u.def.value;
1765 break;
1766 case bfd_link_hash_indirect:
1767 msec = bfd_ind_section_ptr;
1768 mval = 0;
1769 break;
1770 default:
1771 abort ();
1772 }
1773
1774 /* Ignore a redefinition of an absolute symbol to the same
1775 value; it's harmless. */
1776 if (h->type == bfd_link_hash_defined
1777 && bfd_is_abs_section (msec)
1778 && bfd_is_abs_section (section)
1779 && value == mval)
1780 break;
1781
1782 if (! ((*info->callbacks->multiple_definition)
1783 (info, h->root.string, msec->owner, msec, mval, abfd,
1784 section, value)))
1785 return false;
1786 }
1787 break;
1788
1789 case CIND:
1790 /* Create an indirect symbol from an existing common symbol. */
1791 BFD_ASSERT (h->type == bfd_link_hash_common);
1792 if (! ((*info->callbacks->multiple_common)
1793 (info, h->root.string,
1794 h->u.c.p->section->owner, bfd_link_hash_common, h->u.c.size,
1795 abfd, bfd_link_hash_indirect, (bfd_vma) 0)))
1796 return false;
1797 /* Fall through. */
1798 case IND:
1799 /* Create an indirect symbol. */
1800 {
1801 struct bfd_link_hash_entry *inh;
1802
1803 /* STRING is the name of the symbol we want to indirect
1804 to. */
1805 inh = bfd_wrapped_link_hash_lookup (abfd, info, string, true,
1806 copy, false);
1807 if (inh == (struct bfd_link_hash_entry *) NULL)
1808 return false;
1809 if (inh->type == bfd_link_hash_indirect
1810 && inh->u.i.link == h)
1811 {
1812 (*_bfd_error_handler)
1813 (_("%s: indirect symbol `%s' to `%s' is a loop"),
1814 bfd_get_filename (abfd), name, string);
1815 bfd_set_error (bfd_error_invalid_operation);
1816 return false;
1817 }
1818 if (inh->type == bfd_link_hash_new)
1819 {
1820 inh->type = bfd_link_hash_undefined;
1821 inh->u.undef.abfd = abfd;
1822 bfd_link_add_undef (info->hash, inh);
1823 }
1824
1825 /* If the indirect symbol has been referenced, we need to
1826 push the reference down to the symbol we are
1827 referencing. */
1828 if (h->type != bfd_link_hash_new)
1829 {
1830 row = UNDEF_ROW;
1831 cycle = true;
1832 }
1833
1834 h->type = bfd_link_hash_indirect;
1835 h->u.i.link = inh;
1836 }
1837 break;
1838
1839 case SET:
1840 /* Add an entry to a set. */
1841 if (! (*info->callbacks->add_to_set) (info, h, BFD_RELOC_CTOR,
1842 abfd, section, value))
1843 return false;
1844 break;
1845
1846 case WARNC:
1847 /* Issue a warning and cycle. */
1848 if (h->u.i.warning != NULL)
1849 {
1850 if (! (*info->callbacks->warning) (info, h->u.i.warning,
1851 h->root.string, abfd,
1852 (asection *) NULL,
1853 (bfd_vma) 0))
1854 return false;
1855 /* Only issue a warning once. */
1856 h->u.i.warning = NULL;
1857 }
1858 /* Fall through. */
1859 case CYCLE:
1860 /* Try again with the referenced symbol. */
1861 h = h->u.i.link;
1862 cycle = true;
1863 break;
1864
1865 case REFC:
1866 /* A reference to an indirect symbol. */
1867 if (h->next == NULL && info->hash->undefs_tail != h)
1868 h->next = h;
1869 h = h->u.i.link;
1870 cycle = true;
1871 break;
1872
1873 case WARN:
1874 /* Issue a warning. */
1875 if (! (*info->callbacks->warning) (info, string, h->root.string,
1876 hash_entry_bfd (h),
1877 (asection *) NULL, (bfd_vma) 0))
1878 return false;
1879 break;
1880
1881 case CWARN:
1882 /* Warn if this symbol has been referenced already,
1883 otherwise add a warning. A symbol has been referenced if
1884 the next field is not NULL, or it is the tail of the
1885 undefined symbol list. The REF case above helps to
1886 ensure this. */
1887 if (h->next != NULL || info->hash->undefs_tail == h)
1888 {
1889 if (! (*info->callbacks->warning) (info, string, h->root.string,
1890 hash_entry_bfd (h),
1891 (asection *) NULL,
1892 (bfd_vma) 0))
1893 return false;
1894 break;
1895 }
1896 /* Fall through. */
1897 case MWARN:
1898 /* Make a warning symbol. */
1899 {
1900 struct bfd_link_hash_entry *sub;
1901
1902 /* STRING is the warning to give. */
1903 sub = ((struct bfd_link_hash_entry *)
1904 ((*info->hash->table.newfunc)
1905 ((struct bfd_hash_entry *) NULL, &info->hash->table,
1906 h->root.string)));
1907 if (sub == NULL)
1908 return false;
1909 *sub = *h;
1910 sub->type = bfd_link_hash_warning;
1911 sub->u.i.link = h;
1912 if (! copy)
1913 sub->u.i.warning = string;
1914 else
1915 {
1916 char *w;
1917
1918 w = bfd_hash_allocate (&info->hash->table,
1919 strlen (string) + 1);
1920 if (w == NULL)
1921 return false;
1922 strcpy (w, string);
1923 sub->u.i.warning = w;
1924 }
1925
1926 bfd_hash_replace (&info->hash->table,
1927 (struct bfd_hash_entry *) h,
1928 (struct bfd_hash_entry *) sub);
1929 if (hashp != NULL)
1930 *hashp = sub;
1931 }
1932 break;
1933 }
1934 }
1935 while (cycle);
1936
1937 return true;
1938}
1939
1940
1941/* Generic final link routine. */
1942
1943boolean
1944_bfd_generic_final_link (abfd, info)
1945 bfd *abfd;
1946 struct bfd_link_info *info;
1947{
1948 bfd *sub;
1949 asection *o;
1950 struct bfd_link_order *p;
1951 size_t outsymalloc;
1952 struct generic_write_global_symbol_info wginfo;
1953
1954 bfd_get_outsymbols (abfd) = (asymbol **) NULL;
1955 bfd_get_symcount (abfd) = 0;
1956 outsymalloc = 0;
1957
1958 /* Mark all sections which will be included in the output file. */
1959 for (o = abfd->sections; o != NULL; o = o->next)
1960 for (p = o->link_order_head; p != NULL; p = p->next)
1961 if (p->type == bfd_indirect_link_order)
1962 p->u.indirect.section->linker_mark = true;
1963
1964 /* Build the output symbol table. */
1965 for (sub = info->input_bfds; sub != (bfd *) NULL; sub = sub->link_next)
1966 if (! _bfd_generic_link_output_symbols (abfd, sub, info, &outsymalloc))
1967 return false;
1968
1969 /* Accumulate the global symbols. */
1970 wginfo.info = info;
1971 wginfo.output_bfd = abfd;
1972 wginfo.psymalloc = &outsymalloc;
1973 _bfd_generic_link_hash_traverse (_bfd_generic_hash_table (info),
1974 _bfd_generic_link_write_global_symbol,
1975 (PTR) &wginfo);
1976
1977 /* Make sure we have a trailing NULL pointer on OUTSYMBOLS. We
1978 shouldn't really need one, since we have SYMCOUNT, but some old
1979 code still expects one. */
1980 if (! generic_add_output_symbol (abfd, &outsymalloc, NULL))
1981 return false;
1982
1983 if (info->relocateable)
1984 {
1985 /* Allocate space for the output relocs for each section. */
1986 for (o = abfd->sections;
1987 o != (asection *) NULL;
1988 o = o->next)
1989 {
1990 o->reloc_count = 0;
1991 for (p = o->link_order_head;
1992 p != (struct bfd_link_order *) NULL;
1993 p = p->next)
1994 {
1995 if (p->type == bfd_section_reloc_link_order
1996 || p->type == bfd_symbol_reloc_link_order)
1997 ++o->reloc_count;
1998 else if (p->type == bfd_indirect_link_order)
1999 {
2000 asection *input_section;
2001 bfd *input_bfd;
2002 long relsize;
2003 arelent **relocs;
2004 asymbol **symbols;
2005 long reloc_count;
2006
2007 input_section = p->u.indirect.section;
2008 input_bfd = input_section->owner;
2009 relsize = bfd_get_reloc_upper_bound (input_bfd,
2010 input_section);
2011 if (relsize < 0)
2012 return false;
2013 relocs = (arelent **) bfd_malloc ((size_t) relsize);
2014 if (!relocs && relsize != 0)
2015 return false;
2016 symbols = _bfd_generic_link_get_symbols (input_bfd);
2017 reloc_count = bfd_canonicalize_reloc (input_bfd,
2018 input_section,
2019 relocs,
2020 symbols);
2021 if (reloc_count < 0)
2022 return false;
2023 BFD_ASSERT ((unsigned long) reloc_count
2024 == input_section->reloc_count);
2025 o->reloc_count += reloc_count;
2026 free (relocs);
2027 }
2028 }
2029 if (o->reloc_count > 0)
2030 {
2031 o->orelocation = ((arelent **)
2032 bfd_alloc (abfd,
2033 (o->reloc_count
2034 * sizeof (arelent *))));
2035 if (!o->orelocation)
2036 return false;
2037 o->flags |= SEC_RELOC;
2038 /* Reset the count so that it can be used as an index
2039 when putting in the output relocs. */
2040 o->reloc_count = 0;
2041 }
2042 }
2043 }
2044
2045 /* Handle all the link order information for the sections. */
2046 for (o = abfd->sections;
2047 o != (asection *) NULL;
2048 o = o->next)
2049 {
2050 for (p = o->link_order_head;
2051 p != (struct bfd_link_order *) NULL;
2052 p = p->next)
2053 {
2054 switch (p->type)
2055 {
2056 case bfd_section_reloc_link_order:
2057 case bfd_symbol_reloc_link_order:
2058 if (! _bfd_generic_reloc_link_order (abfd, info, o, p))
2059 return false;
2060 break;
2061 case bfd_indirect_link_order:
2062 if (! default_indirect_link_order (abfd, info, o, p, true))
2063 return false;
2064 break;
2065 default:
2066 if (! _bfd_default_link_order (abfd, info, o, p))
2067 return false;
2068 break;
2069 }
2070 }
2071 }
2072
2073 return true;
2074}
2075
2076/* Add an output symbol to the output BFD. */
2077
2078static boolean
2079generic_add_output_symbol (output_bfd, psymalloc, sym)
2080 bfd *output_bfd;
2081 size_t *psymalloc;
2082 asymbol *sym;
2083{
2084 if (bfd_get_symcount (output_bfd) >= *psymalloc)
2085 {
2086 asymbol **newsyms;
2087
2088 if (*psymalloc == 0)
2089 *psymalloc = 124;
2090 else
2091 *psymalloc *= 2;
2092 newsyms = (asymbol **) bfd_realloc (bfd_get_outsymbols (output_bfd),
2093 *psymalloc * sizeof (asymbol *));
2094 if (newsyms == (asymbol **) NULL)
2095 return false;
2096 bfd_get_outsymbols (output_bfd) = newsyms;
2097 }
2098
2099 bfd_get_outsymbols (output_bfd) [bfd_get_symcount (output_bfd)] = sym;
2100 if (sym != NULL)
2101 ++ bfd_get_symcount (output_bfd);
2102
2103 return true;
2104}
2105
2106/* Handle the symbols for an input BFD. */
2107
2108boolean
2109_bfd_generic_link_output_symbols (output_bfd, input_bfd, info, psymalloc)
2110 bfd *output_bfd;
2111 bfd *input_bfd;
2112 struct bfd_link_info *info;
2113 size_t *psymalloc;
2114{
2115 asymbol **sym_ptr;
2116 asymbol **sym_end;
2117
2118 if (! generic_link_read_symbols (input_bfd))
2119 return false;
2120
2121 /* Create a filename symbol if we are supposed to. */
2122 if (info->create_object_symbols_section != (asection *) NULL)
2123 {
2124 asection *sec;
2125
2126 for (sec = input_bfd->sections;
2127 sec != (asection *) NULL;
2128 sec = sec->next)
2129 {
2130 if (sec->output_section == info->create_object_symbols_section)
2131 {
2132 asymbol *newsym;
2133
2134 newsym = bfd_make_empty_symbol (input_bfd);
2135 if (!newsym)
2136 return false;
2137 newsym->name = input_bfd->filename;
2138 newsym->value = 0;
2139 newsym->flags = BSF_LOCAL | BSF_FILE;
2140 newsym->section = sec;
2141
2142 if (! generic_add_output_symbol (output_bfd, psymalloc,
2143 newsym))
2144 return false;
2145
2146 break;
2147 }
2148 }
2149 }
2150
2151 /* Adjust the values of the globally visible symbols, and write out
2152 local symbols. */
2153 sym_ptr = _bfd_generic_link_get_symbols (input_bfd);
2154 sym_end = sym_ptr + _bfd_generic_link_get_symcount (input_bfd);
2155 for (; sym_ptr < sym_end; sym_ptr++)
2156 {
2157 asymbol *sym;
2158 struct generic_link_hash_entry *h;
2159 boolean output;
2160
2161 h = (struct generic_link_hash_entry *) NULL;
2162 sym = *sym_ptr;
2163 if ((sym->flags & (BSF_INDIRECT
2164 | BSF_WARNING
2165 | BSF_GLOBAL
2166 | BSF_CONSTRUCTOR
2167 | BSF_WEAK)) != 0
2168 || bfd_is_und_section (bfd_get_section (sym))
2169 || bfd_is_com_section (bfd_get_section (sym))
2170 || bfd_is_ind_section (bfd_get_section (sym)))
2171 {
2172 if (sym->udata.p != NULL)
2173 h = (struct generic_link_hash_entry *) sym->udata.p;
2174 else if ((sym->flags & BSF_CONSTRUCTOR) != 0)
2175 {
2176 /* This case normally means that the main linker code
2177 deliberately ignored this constructor symbol. We
2178 should just pass it through. This will screw up if
2179 the constructor symbol is from a different,
2180 non-generic, object file format, but the case will
2181 only arise when linking with -r, which will probably
2182 fail anyhow, since there will be no way to represent
2183 the relocs in the output format being used. */
2184 h = NULL;
2185 }
2186 else if (bfd_is_und_section (bfd_get_section (sym)))
2187 h = ((struct generic_link_hash_entry *)
2188 bfd_wrapped_link_hash_lookup (output_bfd, info,
2189 bfd_asymbol_name (sym),
2190 false, false, true));
2191 else
2192 h = _bfd_generic_link_hash_lookup (_bfd_generic_hash_table (info),
2193 bfd_asymbol_name (sym),
2194 false, false, true);
2195
2196 if (h != (struct generic_link_hash_entry *) NULL)
2197 {
2198 /* Force all references to this symbol to point to
2199 the same area in memory. It is possible that
2200 this routine will be called with a hash table
2201 other than a generic hash table, so we double
2202 check that. */
2203 if (info->hash->creator == input_bfd->xvec)
2204 {
2205 if (h->sym != (asymbol *) NULL)
2206 *sym_ptr = sym = h->sym;
2207 }
2208
2209 switch (h->root.type)
2210 {
2211 default:
2212 case bfd_link_hash_new:
2213 abort ();
2214 case bfd_link_hash_undefined:
2215 break;
2216 case bfd_link_hash_undefweak:
2217 sym->flags |= BSF_WEAK;
2218 break;
2219 case bfd_link_hash_indirect:
2220 h = (struct generic_link_hash_entry *) h->root.u.i.link;
2221 /* fall through */
2222 case bfd_link_hash_defined:
2223 sym->flags |= BSF_GLOBAL;
2224 sym->flags &=~ BSF_CONSTRUCTOR;
2225 sym->value = h->root.u.def.value;
2226 sym->section = h->root.u.def.section;
2227 break;
2228 case bfd_link_hash_defweak:
2229 sym->flags |= BSF_WEAK;
2230 sym->flags &=~ BSF_CONSTRUCTOR;
2231 sym->value = h->root.u.def.value;
2232 sym->section = h->root.u.def.section;
2233 break;
2234 case bfd_link_hash_common:
2235 sym->value = h->root.u.c.size;
2236 sym->flags |= BSF_GLOBAL;
2237 if (! bfd_is_com_section (sym->section))
2238 {
2239 BFD_ASSERT (bfd_is_und_section (sym->section));
2240 sym->section = bfd_com_section_ptr;
2241 }
2242 /* We do not set the section of the symbol to
2243 h->root.u.c.p->section. That value was saved so
2244 that we would know where to allocate the symbol
2245 if it was defined. In this case the type is
2246 still bfd_link_hash_common, so we did not define
2247 it, so we do not want to use that section. */
2248 break;
2249 }
2250 }
2251 }
2252
2253 /* This switch is straight from the old code in
2254 write_file_locals in ldsym.c. */
2255 if (info->strip == strip_all
2256 || (info->strip == strip_some
2257 && (bfd_hash_lookup (info->keep_hash, bfd_asymbol_name (sym),
2258 false, false)
2259 == (struct bfd_hash_entry *) NULL)))
2260 output = false;
2261 else if ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0)
2262 {
2263 /* If this symbol is marked as occurring now, rather
2264 than at the end, output it now. This is used for
2265 COFF C_EXT FCN symbols. FIXME: There must be a
2266 better way. */
2267 if (bfd_asymbol_bfd (sym) == input_bfd
2268 && (sym->flags & BSF_NOT_AT_END) != 0)
2269 output = true;
2270 else
2271 output = false;
2272 }
2273 else if (bfd_is_ind_section (sym->section))
2274 output = false;
2275 else if ((sym->flags & BSF_DEBUGGING) != 0)
2276 {
2277 if (info->strip == strip_none)
2278 output = true;
2279 else
2280 output = false;
2281 }
2282 else if (bfd_is_und_section (sym->section)
2283 || bfd_is_com_section (sym->section))
2284 output = false;
2285 else if ((sym->flags & BSF_LOCAL) != 0)
2286 {
2287 if ((sym->flags & BSF_WARNING) != 0)
2288 output = false;
2289 else
2290 {
2291 switch (info->discard)
2292 {
2293 default:
2294 case discard_all:
2295 output = false;
2296 break;
2297 case discard_l:
2298 if (bfd_is_local_label (input_bfd, sym))
2299 output = false;
2300 else
2301 output = true;
2302 break;
2303 case discard_none:
2304 output = true;
2305 break;
2306 }
2307 }
2308 }
2309 else if ((sym->flags & BSF_CONSTRUCTOR))
2310 {
2311 if (info->strip != strip_all)
2312 output = true;
2313 else
2314 output = false;
2315 }
2316 else
2317 abort ();
2318
2319 /* If this symbol is in a section which is not being included
2320 in the output file, then we don't want to output the symbol.
2321
2322 Gross. .bss and similar sections won't have the linker_mark
2323 field set. */
2324 if ((sym->section->flags & SEC_HAS_CONTENTS) != 0
2325 && sym->section->linker_mark == false)
2326 output = false;
2327
2328 if (output)
2329 {
2330 if (! generic_add_output_symbol (output_bfd, psymalloc, sym))
2331 return false;
2332 if (h != (struct generic_link_hash_entry *) NULL)
2333 h->written = true;
2334 }
2335 }
2336
2337 return true;
2338}
2339
2340/* Set the section and value of a generic BFD symbol based on a linker
2341 hash table entry. */
2342
2343static void
2344set_symbol_from_hash (sym, h)
2345 asymbol *sym;
2346 struct bfd_link_hash_entry *h;
2347{
2348 switch (h->type)
2349 {
2350 default:
2351 abort ();
2352 break;
2353 case bfd_link_hash_new:
2354 /* This can happen when a constructor symbol is seen but we are
2355 not building constructors. */
2356 if (sym->section != NULL)
2357 {
2358 BFD_ASSERT ((sym->flags & BSF_CONSTRUCTOR) != 0);
2359 }
2360 else
2361 {
2362 sym->flags |= BSF_CONSTRUCTOR;
2363 sym->section = bfd_abs_section_ptr;
2364 sym->value = 0;
2365 }
2366 break;
2367 case bfd_link_hash_undefined:
2368 sym->section = bfd_und_section_ptr;
2369 sym->value = 0;
2370 break;
2371 case bfd_link_hash_undefweak:
2372 sym->section = bfd_und_section_ptr;
2373 sym->value = 0;
2374 sym->flags |= BSF_WEAK;
2375 break;
2376 case bfd_link_hash_defined:
2377 sym->section = h->u.def.section;
2378 sym->value = h->u.def.value;
2379 break;
2380 case bfd_link_hash_defweak:
2381 sym->flags |= BSF_WEAK;
2382 sym->section = h->u.def.section;
2383 sym->value = h->u.def.value;
2384 break;
2385 case bfd_link_hash_common:
2386 sym->value = h->u.c.size;
2387 if (sym->section == NULL)
2388 sym->section = bfd_com_section_ptr;
2389 else if (! bfd_is_com_section (sym->section))
2390 {
2391 BFD_ASSERT (bfd_is_und_section (sym->section));
2392 sym->section = bfd_com_section_ptr;
2393 }
2394 /* Do not set the section; see _bfd_generic_link_output_symbols. */
2395 break;
2396 case bfd_link_hash_indirect:
2397 case bfd_link_hash_warning:
2398 /* FIXME: What should we do here? */
2399 break;
2400 }
2401}
2402
2403/* Write out a global symbol, if it hasn't already been written out.
2404 This is called for each symbol in the hash table. */
2405
2406boolean
2407_bfd_generic_link_write_global_symbol (h, data)
2408 struct generic_link_hash_entry *h;
2409 PTR data;
2410{
2411 struct generic_write_global_symbol_info *wginfo =
2412 (struct generic_write_global_symbol_info *) data;
2413 asymbol *sym;
2414
2415 if (h->written)
2416 return true;
2417
2418 h->written = true;
2419
2420 if (wginfo->info->strip == strip_all
2421 || (wginfo->info->strip == strip_some
2422 && bfd_hash_lookup (wginfo->info->keep_hash, h->root.root.string,
2423 false, false) == NULL))
2424 return true;
2425
2426 if (h->sym != (asymbol *) NULL)
2427 sym = h->sym;
2428 else
2429 {
2430 sym = bfd_make_empty_symbol (wginfo->output_bfd);
2431 if (!sym)
2432 return false;
2433 sym->name = h->root.root.string;
2434 sym->flags = 0;
2435 }
2436
2437 set_symbol_from_hash (sym, &h->root);
2438
2439 sym->flags |= BSF_GLOBAL;
2440
2441 if (! generic_add_output_symbol (wginfo->output_bfd, wginfo->psymalloc,
2442 sym))
2443 {
2444 /* FIXME: No way to return failure. */
2445 abort ();
2446 }
2447
2448 return true;
2449}
2450
2451/* Create a relocation. */
2452
2453boolean
2454_bfd_generic_reloc_link_order (abfd, info, sec, link_order)
2455 bfd *abfd;
2456 struct bfd_link_info *info;
2457 asection *sec;
2458 struct bfd_link_order *link_order;
2459{
2460 arelent *r;
2461
2462 if (! info->relocateable)
2463 abort ();
2464 if (sec->orelocation == (arelent **) NULL)
2465 abort ();
2466
2467 r = (arelent *) bfd_alloc (abfd, sizeof (arelent));
2468 if (r == (arelent *) NULL)
2469 return false;
2470
2471 r->address = link_order->offset;
2472 r->howto = bfd_reloc_type_lookup (abfd, link_order->u.reloc.p->reloc);
2473 if (r->howto == 0)
2474 {
2475 bfd_set_error (bfd_error_bad_value);
2476 return false;
2477 }
2478
2479 /* Get the symbol to use for the relocation. */
2480 if (link_order->type == bfd_section_reloc_link_order)
2481 r->sym_ptr_ptr = link_order->u.reloc.p->u.section->symbol_ptr_ptr;
2482 else
2483 {
2484 struct generic_link_hash_entry *h;
2485
2486 h = ((struct generic_link_hash_entry *)
2487 bfd_wrapped_link_hash_lookup (abfd, info,
2488 link_order->u.reloc.p->u.name,
2489 false, false, true));
2490 if (h == (struct generic_link_hash_entry *) NULL
2491 || ! h->written)
2492 {
2493 if (! ((*info->callbacks->unattached_reloc)
2494 (info, link_order->u.reloc.p->u.name,
2495 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
2496 return false;
2497 bfd_set_error (bfd_error_bad_value);
2498 return false;
2499 }
2500 r->sym_ptr_ptr = &h->sym;
2501 }
2502
2503 /* If this is an inplace reloc, write the addend to the object file.
2504 Otherwise, store it in the reloc addend. */
2505 if (! r->howto->partial_inplace)
2506 r->addend = link_order->u.reloc.p->addend;
2507 else
2508 {
2509 bfd_size_type size;
2510 bfd_reloc_status_type rstat;
2511 bfd_byte *buf;
2512 boolean ok;
2513
2514 size = bfd_get_reloc_size (r->howto);
2515 buf = (bfd_byte *) bfd_zmalloc (size);
2516 if (buf == (bfd_byte *) NULL)
2517 return false;
2518 rstat = _bfd_relocate_contents (r->howto, abfd,
2519 link_order->u.reloc.p->addend, buf);
2520 switch (rstat)
2521 {
2522 case bfd_reloc_ok:
2523 break;
2524 default:
2525 case bfd_reloc_outofrange:
2526 abort ();
2527 case bfd_reloc_overflow:
2528 if (! ((*info->callbacks->reloc_overflow)
2529 (info,
2530 (link_order->type == bfd_section_reloc_link_order
2531 ? bfd_section_name (abfd, link_order->u.reloc.p->u.section)
2532 : link_order->u.reloc.p->u.name),
2533 r->howto->name, link_order->u.reloc.p->addend,
2534 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
2535 {
2536 free (buf);
2537 return false;
2538 }
2539 break;
2540 }
2541 ok = bfd_set_section_contents (abfd, sec, (PTR) buf,
2542 (file_ptr)
2543 (link_order->offset *
2544 bfd_octets_per_byte (abfd)), size);
2545 free (buf);
2546 if (! ok)
2547 return false;
2548
2549 r->addend = 0;
2550 }
2551
2552 sec->orelocation[sec->reloc_count] = r;
2553 ++sec->reloc_count;
2554
2555 return true;
2556}
2557
2558
2559/* Allocate a new link_order for a section. */
2560
2561struct bfd_link_order *
2562bfd_new_link_order (abfd, section)
2563 bfd *abfd;
2564 asection *section;
2565{
2566 struct bfd_link_order *new;
2567
2568 new = ((struct bfd_link_order *)
2569 bfd_alloc (abfd, sizeof (struct bfd_link_order)));
2570 if (!new)
2571 return NULL;
2572
2573 new->type = bfd_undefined_link_order;
2574 new->offset = 0;
2575 new->size = 0;
2576 new->next = (struct bfd_link_order *) NULL;
2577
2578 if (section->link_order_tail != (struct bfd_link_order *) NULL)
2579 section->link_order_tail->next = new;
2580 else
2581 section->link_order_head = new;
2582 section->link_order_tail = new;
2583
2584 return new;
2585}
2586
2587/* Default link order processing routine. Note that we can not handle
2588 the reloc_link_order types here, since they depend upon the details
2589 of how the particular backends generates relocs. */
2590
2591boolean
2592_bfd_default_link_order (abfd, info, sec, link_order)
2593 bfd *abfd;
2594 struct bfd_link_info *info;
2595 asection *sec;
2596 struct bfd_link_order *link_order;
2597{
2598 switch (link_order->type)
2599 {
2600 case bfd_undefined_link_order:
2601 case bfd_section_reloc_link_order:
2602 case bfd_symbol_reloc_link_order:
2603 default:
2604 abort ();
2605 case bfd_indirect_link_order:
2606 return default_indirect_link_order (abfd, info, sec, link_order,
2607 false);
2608 case bfd_fill_link_order:
2609 return default_fill_link_order (abfd, info, sec, link_order);
2610 case bfd_data_link_order:
2611 return bfd_set_section_contents (abfd, sec,
2612 (PTR) link_order->u.data.contents,
2613 (file_ptr)
2614 (link_order->offset *
2615 bfd_octets_per_byte (abfd)),
2616 link_order->size);
2617 }
2618}
2619
2620/* Default routine to handle a bfd_fill_link_order. */
2621
2622static boolean
2623default_fill_link_order (abfd, info, sec, link_order)
2624 bfd *abfd;
2625 struct bfd_link_info *info ATTRIBUTE_UNUSED;
2626 asection *sec;
2627 struct bfd_link_order *link_order;
2628{
2629 size_t size;
2630 char *space;
2631 size_t i;
2632 int fill;
2633 boolean result;
2634
2635 BFD_ASSERT ((sec->flags & SEC_HAS_CONTENTS) != 0);
2636
2637 size = (size_t) link_order->size;
2638 space = (char *) bfd_malloc (size);
2639 if (space == NULL && size != 0)
2640 return false;
2641
2642 fill = link_order->u.fill.value;
2643 for (i = 0; i < size; i += 2)
2644 space[i] = fill >> 8;
2645 for (i = 1; i < size; i += 2)
2646 space[i] = fill;
2647 result = bfd_set_section_contents (abfd, sec, space,
2648 (file_ptr)
2649 (link_order->offset *
2650 bfd_octets_per_byte (abfd)),
2651 link_order->size);
2652 free (space);
2653 return result;
2654}
2655
2656/* Default routine to handle a bfd_indirect_link_order. */
2657
2658static boolean
2659default_indirect_link_order (output_bfd, info, output_section, link_order,
2660 generic_linker)
2661 bfd *output_bfd;
2662 struct bfd_link_info *info;
2663 asection *output_section;
2664 struct bfd_link_order *link_order;
2665 boolean generic_linker;
2666{
2667 asection *input_section;
2668 bfd *input_bfd;
2669 bfd_byte *contents = NULL;
2670 bfd_byte *new_contents;
2671
2672 BFD_ASSERT ((output_section->flags & SEC_HAS_CONTENTS) != 0);
2673
2674 if (link_order->size == 0)
2675 return true;
2676
2677 input_section = link_order->u.indirect.section;
2678 input_bfd = input_section->owner;
2679
2680 BFD_ASSERT (input_section->output_section == output_section);
2681 BFD_ASSERT (input_section->output_offset == link_order->offset);
2682 BFD_ASSERT (input_section->_cooked_size == link_order->size);
2683
2684 if (info->relocateable
2685 && input_section->reloc_count > 0
2686 && output_section->orelocation == (arelent **) NULL)
2687 {
2688 /* Space has not been allocated for the output relocations.
2689 This can happen when we are called by a specific backend
2690 because somebody is attempting to link together different
2691 types of object files. Handling this case correctly is
2692 difficult, and sometimes impossible. */
2693 (*_bfd_error_handler)
2694 (_("Attempt to do relocateable link with %s input and %s output"),
2695 bfd_get_target (input_bfd), bfd_get_target (output_bfd));
2696 bfd_set_error (bfd_error_wrong_format);
2697 return false;
2698 }
2699
2700 if (! generic_linker)
2701 {
2702 asymbol **sympp;
2703 asymbol **symppend;
2704
2705 /* Get the canonical symbols. The generic linker will always
2706 have retrieved them by this point, but we are being called by
2707 a specific linker, presumably because we are linking
2708 different types of object files together. */
2709 if (! generic_link_read_symbols (input_bfd))
2710 return false;
2711
2712 /* Since we have been called by a specific linker, rather than
2713 the generic linker, the values of the symbols will not be
2714 right. They will be the values as seen in the input file,
2715 not the values of the final link. We need to fix them up
2716 before we can relocate the section. */
2717 sympp = _bfd_generic_link_get_symbols (input_bfd);
2718 symppend = sympp + _bfd_generic_link_get_symcount (input_bfd);
2719 for (; sympp < symppend; sympp++)
2720 {
2721 asymbol *sym;
2722 struct bfd_link_hash_entry *h;
2723
2724 sym = *sympp;
2725
2726 if ((sym->flags & (BSF_INDIRECT
2727 | BSF_WARNING
2728 | BSF_GLOBAL
2729 | BSF_CONSTRUCTOR
2730 | BSF_WEAK)) != 0
2731 || bfd_is_und_section (bfd_get_section (sym))
2732 || bfd_is_com_section (bfd_get_section (sym))
2733 || bfd_is_ind_section (bfd_get_section (sym)))
2734 {
2735 /* sym->udata may have been set by
2736 generic_link_add_symbol_list. */
2737 if (sym->udata.p != NULL)
2738 h = (struct bfd_link_hash_entry *) sym->udata.p;
2739 else if (bfd_is_und_section (bfd_get_section (sym)))
2740 h = bfd_wrapped_link_hash_lookup (output_bfd, info,
2741 bfd_asymbol_name (sym),
2742 false, false, true);
2743 else
2744 h = bfd_link_hash_lookup (info->hash,
2745 bfd_asymbol_name (sym),
2746 false, false, true);
2747 if (h != NULL)
2748 set_symbol_from_hash (sym, h);
2749 }
2750 }
2751 }
2752
2753 /* Get and relocate the section contents. */
2754 contents = ((bfd_byte *)
2755 bfd_malloc (bfd_section_size (input_bfd, input_section)));
2756 if (contents == NULL && bfd_section_size (input_bfd, input_section) != 0)
2757 goto error_return;
2758 new_contents = (bfd_get_relocated_section_contents
2759 (output_bfd, info, link_order, contents, info->relocateable,
2760 _bfd_generic_link_get_symbols (input_bfd)));
2761 if (!new_contents)
2762 goto error_return;
2763
2764 /* Output the section contents. */
2765 if (! bfd_set_section_contents (output_bfd, output_section,
2766 (PTR) new_contents,
2767 (file_ptr)
2768 (link_order->offset *
2769 bfd_octets_per_byte (output_bfd)),
2770 link_order->size))
2771 goto error_return;
2772
2773 if (contents != NULL)
2774 free (contents);
2775 return true;
2776
2777 error_return:
2778 if (contents != NULL)
2779 free (contents);
2780 return false;
2781}
2782
2783/* A little routine to count the number of relocs in a link_order
2784 list. */
2785
2786unsigned int
2787_bfd_count_link_order_relocs (link_order)
2788 struct bfd_link_order *link_order;
2789{
2790 register unsigned int c;
2791 register struct bfd_link_order *l;
2792
2793 c = 0;
2794 for (l = link_order; l != (struct bfd_link_order *) NULL; l = l->next)
2795 {
2796 if (l->type == bfd_section_reloc_link_order
2797 || l->type == bfd_symbol_reloc_link_order)
2798 ++c;
2799 }
2800
2801 return c;
2802}
2803
2804/*
2805FUNCTION
2806 bfd_link_split_section
2807
2808SYNOPSIS
2809 boolean bfd_link_split_section(bfd *abfd, asection *sec);
2810
2811DESCRIPTION
2812 Return nonzero if @var{sec} should be split during a
2813 reloceatable or final link.
2814
2815.#define bfd_link_split_section(abfd, sec) \
2816. BFD_SEND (abfd, _bfd_link_split_section, (abfd, sec))
2817.
2818
2819*/
2820
2821boolean
2822_bfd_generic_link_split_section (abfd, sec)
2823 bfd *abfd ATTRIBUTE_UNUSED;
2824 asection *sec ATTRIBUTE_UNUSED;
2825{
2826 return false;
2827}
Note: See TracBrowser for help on using the repository browser.