1 /* POWER/PowerPC XCOFF linker support.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
4 Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
27 #include "coff/internal.h"
28 #include "coff/xcoff.h"
32 /* This file holds the XCOFF linker code. */
34 #undef STRING_SIZE_SIZE
35 #define STRING_SIZE_SIZE 4
37 /* We reuse the SEC_ROM flag as a mark flag for garbage collection.
38 This flag will only be used on input sections. */
40 #define SEC_MARK (SEC_ROM)
42 /* The list of import files. */
44 struct xcoff_import_file
46 /* The next entry in the list. */
47 struct xcoff_import_file
*next
;
52 /* The member name. */
56 /* Information we keep for each section in the output file during the
59 struct xcoff_link_section_info
61 /* The relocs to be output. */
62 struct internal_reloc
*relocs
;
63 /* For each reloc against a global symbol whose index was not known
64 when the reloc was handled, the global hash table entry. */
65 struct xcoff_link_hash_entry
**rel_hashes
;
66 /* If there is a TOC relative reloc against a global symbol, and the
67 index of the TOC symbol is not known when the reloc was handled,
68 an entry is added to this linked list. This is not an array,
69 like rel_hashes, because this case is quite uncommon. */
70 struct xcoff_toc_rel_hash
72 struct xcoff_toc_rel_hash
*next
;
73 struct xcoff_link_hash_entry
*h
;
74 struct internal_reloc
*rel
;
78 /* Information that we pass around while doing the final link step. */
80 struct xcoff_final_link_info
82 /* General link information. */
83 struct bfd_link_info
*info
;
86 /* Hash table for long symbol names. */
87 struct bfd_strtab_hash
*strtab
;
88 /* Array of information kept for each output section, indexed by the
89 target_index field. */
90 struct xcoff_link_section_info
*section_info
;
91 /* Symbol index of last C_FILE symbol (-1 if none). */
93 /* Contents of last C_FILE symbol. */
94 struct internal_syment last_file
;
95 /* Symbol index of TOC symbol. */
97 /* Start of .loader symbols. */
99 /* Next .loader reloc to swap out. */
101 /* File position of start of line numbers. */
102 file_ptr line_filepos
;
103 /* Buffer large enough to hold swapped symbols of any input file. */
104 struct internal_syment
*internal_syms
;
105 /* Buffer large enough to hold output indices of symbols of any
108 /* Buffer large enough to hold output symbols for any input file. */
110 /* Buffer large enough to hold external line numbers for any input
113 /* Buffer large enough to hold any input section. */
115 /* Buffer large enough to hold external relocs of any input section. */
116 bfd_byte
*external_relocs
;
119 static bfd_boolean
xcoff_mark (struct bfd_link_info
*, asection
*);
123 /* Routines to read XCOFF dynamic information. This don't really
124 belong here, but we already have the ldsym manipulation routines
127 /* Read the contents of a section. */
130 xcoff_get_section_contents (bfd
*abfd
, asection
*sec
)
132 if (coff_section_data (abfd
, sec
) == NULL
)
134 bfd_size_type amt
= sizeof (struct coff_section_tdata
);
136 sec
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
137 if (sec
->used_by_bfd
== NULL
)
141 if (coff_section_data (abfd
, sec
)->contents
== NULL
)
145 if (! bfd_malloc_and_get_section (abfd
, sec
, &contents
))
147 if (contents
!= NULL
)
151 coff_section_data (abfd
, sec
)->contents
= contents
;
157 /* Get the size required to hold the dynamic symbols. */
160 _bfd_xcoff_get_dynamic_symtab_upper_bound (bfd
*abfd
)
164 struct internal_ldhdr ldhdr
;
166 if ((abfd
->flags
& DYNAMIC
) == 0)
168 bfd_set_error (bfd_error_invalid_operation
);
172 lsec
= bfd_get_section_by_name (abfd
, ".loader");
175 bfd_set_error (bfd_error_no_symbols
);
179 if (! xcoff_get_section_contents (abfd
, lsec
))
181 contents
= coff_section_data (abfd
, lsec
)->contents
;
183 bfd_xcoff_swap_ldhdr_in (abfd
, (void *) contents
, &ldhdr
);
185 return (ldhdr
.l_nsyms
+ 1) * sizeof (asymbol
*);
188 /* Get the dynamic symbols. */
191 _bfd_xcoff_canonicalize_dynamic_symtab (bfd
*abfd
, asymbol
**psyms
)
195 struct internal_ldhdr ldhdr
;
197 bfd_byte
*elsym
, *elsymend
;
198 coff_symbol_type
*symbuf
;
200 if ((abfd
->flags
& DYNAMIC
) == 0)
202 bfd_set_error (bfd_error_invalid_operation
);
206 lsec
= bfd_get_section_by_name (abfd
, ".loader");
209 bfd_set_error (bfd_error_no_symbols
);
213 if (! xcoff_get_section_contents (abfd
, lsec
))
215 contents
= coff_section_data (abfd
, lsec
)->contents
;
217 coff_section_data (abfd
, lsec
)->keep_contents
= TRUE
;
219 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
221 strings
= (char *) contents
+ ldhdr
.l_stoff
;
223 symbuf
= bfd_zalloc (abfd
, ldhdr
.l_nsyms
* sizeof (* symbuf
));
227 elsym
= contents
+ bfd_xcoff_loader_symbol_offset(abfd
, &ldhdr
);
229 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz(abfd
);
230 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz(abfd
), symbuf
++, psyms
++)
232 struct internal_ldsym ldsym
;
234 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
236 symbuf
->symbol
.the_bfd
= abfd
;
238 if (ldsym
._l
._l_l
._l_zeroes
== 0)
239 symbuf
->symbol
.name
= strings
+ ldsym
._l
._l_l
._l_offset
;
244 c
= bfd_alloc (abfd
, (bfd_size_type
) SYMNMLEN
+ 1);
247 memcpy (c
, ldsym
._l
._l_name
, SYMNMLEN
);
249 symbuf
->symbol
.name
= c
;
252 if (ldsym
.l_smclas
== XMC_XO
)
253 symbuf
->symbol
.section
= bfd_abs_section_ptr
;
255 symbuf
->symbol
.section
= coff_section_from_bfd_index (abfd
,
257 symbuf
->symbol
.value
= ldsym
.l_value
- symbuf
->symbol
.section
->vma
;
259 symbuf
->symbol
.flags
= BSF_NO_FLAGS
;
260 if ((ldsym
.l_smtype
& L_EXPORT
) != 0)
261 symbuf
->symbol
.flags
|= BSF_GLOBAL
;
263 /* FIXME: We have no way to record the other information stored
264 with the loader symbol. */
265 *psyms
= (asymbol
*) symbuf
;
270 return ldhdr
.l_nsyms
;
273 /* Get the size required to hold the dynamic relocs. */
276 _bfd_xcoff_get_dynamic_reloc_upper_bound (bfd
*abfd
)
280 struct internal_ldhdr ldhdr
;
282 if ((abfd
->flags
& DYNAMIC
) == 0)
284 bfd_set_error (bfd_error_invalid_operation
);
288 lsec
= bfd_get_section_by_name (abfd
, ".loader");
291 bfd_set_error (bfd_error_no_symbols
);
295 if (! xcoff_get_section_contents (abfd
, lsec
))
297 contents
= coff_section_data (abfd
, lsec
)->contents
;
299 bfd_xcoff_swap_ldhdr_in (abfd
, (struct external_ldhdr
*) contents
, &ldhdr
);
301 return (ldhdr
.l_nreloc
+ 1) * sizeof (arelent
*);
304 /* Get the dynamic relocs. */
307 _bfd_xcoff_canonicalize_dynamic_reloc (bfd
*abfd
,
313 struct internal_ldhdr ldhdr
;
315 bfd_byte
*elrel
, *elrelend
;
317 if ((abfd
->flags
& DYNAMIC
) == 0)
319 bfd_set_error (bfd_error_invalid_operation
);
323 lsec
= bfd_get_section_by_name (abfd
, ".loader");
326 bfd_set_error (bfd_error_no_symbols
);
330 if (! xcoff_get_section_contents (abfd
, lsec
))
332 contents
= coff_section_data (abfd
, lsec
)->contents
;
334 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
336 relbuf
= bfd_alloc (abfd
, ldhdr
.l_nreloc
* sizeof (arelent
));
340 elrel
= contents
+ bfd_xcoff_loader_reloc_offset(abfd
, &ldhdr
);
342 elrelend
= elrel
+ ldhdr
.l_nreloc
* bfd_xcoff_ldrelsz(abfd
);
343 for (; elrel
< elrelend
; elrel
+= bfd_xcoff_ldrelsz(abfd
), relbuf
++,
346 struct internal_ldrel ldrel
;
348 bfd_xcoff_swap_ldrel_in (abfd
, elrel
, &ldrel
);
350 if (ldrel
.l_symndx
>= 3)
351 relbuf
->sym_ptr_ptr
= syms
+ (ldrel
.l_symndx
- 3);
357 switch (ldrel
.l_symndx
)
373 sec
= bfd_get_section_by_name (abfd
, name
);
376 bfd_set_error (bfd_error_bad_value
);
380 relbuf
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
383 relbuf
->address
= ldrel
.l_vaddr
;
386 /* Most dynamic relocs have the same type. FIXME: This is only
387 correct if ldrel.l_rtype == 0. In other cases, we should use
388 a different howto. */
389 relbuf
->howto
= bfd_xcoff_dynamic_reloc_howto(abfd
);
391 /* FIXME: We have no way to record the l_rsecnm field. */
398 return ldhdr
.l_nreloc
;
401 /* Routine to create an entry in an XCOFF link hash table. */
403 static struct bfd_hash_entry
*
404 xcoff_link_hash_newfunc (struct bfd_hash_entry
*entry
,
405 struct bfd_hash_table
*table
,
408 struct xcoff_link_hash_entry
*ret
= (struct xcoff_link_hash_entry
*) entry
;
410 /* Allocate the structure if it has not already been allocated by a
413 ret
= bfd_hash_allocate (table
, sizeof (* ret
));
417 /* Call the allocation method of the superclass. */
418 ret
= ((struct xcoff_link_hash_entry
*)
419 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
423 /* Set local fields. */
425 ret
->toc_section
= NULL
;
426 ret
->u
.toc_indx
= -1;
427 ret
->descriptor
= NULL
;
431 ret
->smclas
= XMC_UA
;
434 return (struct bfd_hash_entry
*) ret
;
437 /* Create a XCOFF link hash table. */
439 struct bfd_link_hash_table
*
440 _bfd_xcoff_bfd_link_hash_table_create (bfd
*abfd
)
442 struct xcoff_link_hash_table
*ret
;
443 bfd_size_type amt
= sizeof (* ret
);
445 ret
= bfd_malloc (amt
);
448 if (!_bfd_link_hash_table_init (&ret
->root
, abfd
, xcoff_link_hash_newfunc
,
449 sizeof (struct xcoff_link_hash_entry
)))
455 ret
->debug_strtab
= _bfd_xcoff_stringtab_init ();
456 ret
->debug_section
= NULL
;
457 ret
->loader_section
= NULL
;
458 ret
->ldrel_count
= 0;
459 memset (&ret
->ldhdr
, 0, sizeof (struct internal_ldhdr
));
460 ret
->linkage_section
= NULL
;
461 ret
->toc_section
= NULL
;
462 ret
->descriptor_section
= NULL
;
467 memset (ret
->special_sections
, 0, sizeof ret
->special_sections
);
469 /* The linker will always generate a full a.out header. We need to
470 record that fact now, before the sizeof_headers routine could be
472 xcoff_data (abfd
)->full_aouthdr
= TRUE
;
477 /* Free a XCOFF link hash table. */
480 _bfd_xcoff_bfd_link_hash_table_free (struct bfd_link_hash_table
*hash
)
482 struct xcoff_link_hash_table
*ret
= (struct xcoff_link_hash_table
*) hash
;
484 _bfd_stringtab_free (ret
->debug_strtab
);
485 bfd_hash_table_free (&ret
->root
.table
);
489 /* Read internal relocs for an XCOFF csect. This is a wrapper around
490 _bfd_coff_read_internal_relocs which tries to take advantage of any
491 relocs which may have been cached for the enclosing section. */
493 static struct internal_reloc
*
494 xcoff_read_internal_relocs (bfd
*abfd
,
497 bfd_byte
*external_relocs
,
498 bfd_boolean require_internal
,
499 struct internal_reloc
*internal_relocs
)
501 if (coff_section_data (abfd
, sec
) != NULL
502 && coff_section_data (abfd
, sec
)->relocs
== NULL
503 && xcoff_section_data (abfd
, sec
) != NULL
)
507 enclosing
= xcoff_section_data (abfd
, sec
)->enclosing
;
509 if (enclosing
!= NULL
510 && (coff_section_data (abfd
, enclosing
) == NULL
511 || coff_section_data (abfd
, enclosing
)->relocs
== NULL
)
513 && enclosing
->reloc_count
> 0)
515 if (_bfd_coff_read_internal_relocs (abfd
, enclosing
, TRUE
,
516 external_relocs
, FALSE
, NULL
)
521 if (enclosing
!= NULL
522 && coff_section_data (abfd
, enclosing
) != NULL
523 && coff_section_data (abfd
, enclosing
)->relocs
!= NULL
)
527 off
= ((sec
->rel_filepos
- enclosing
->rel_filepos
)
528 / bfd_coff_relsz (abfd
));
530 if (! require_internal
)
531 return coff_section_data (abfd
, enclosing
)->relocs
+ off
;
532 memcpy (internal_relocs
,
533 coff_section_data (abfd
, enclosing
)->relocs
+ off
,
534 sec
->reloc_count
* sizeof (struct internal_reloc
));
535 return internal_relocs
;
539 return _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
540 require_internal
, internal_relocs
);
543 /* This function is used to add symbols from a dynamic object to the
544 global symbol table. */
547 xcoff_link_add_dynamic_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
551 struct internal_ldhdr ldhdr
;
553 bfd_byte
*elsym
, *elsymend
;
554 struct xcoff_import_file
*n
;
559 struct xcoff_import_file
**pp
;
561 /* We can only handle a dynamic object if we are generating an XCOFF
563 if (info
->output_bfd
->xvec
!= abfd
->xvec
)
565 (*_bfd_error_handler
)
566 (_("%s: XCOFF shared object when not producing XCOFF output"),
567 bfd_get_filename (abfd
));
568 bfd_set_error (bfd_error_invalid_operation
);
572 /* The symbols we use from a dynamic object are not the symbols in
573 the normal symbol table, but, rather, the symbols in the export
574 table. If there is a global symbol in a dynamic object which is
575 not in the export table, the loader will not be able to find it,
576 so we don't want to find it either. Also, on AIX 4.1.3, shr.o in
577 libc.a has symbols in the export table which are not in the
580 /* Read in the .loader section. FIXME: We should really use the
581 o_snloader field in the a.out header, rather than grabbing the
583 lsec
= bfd_get_section_by_name (abfd
, ".loader");
586 (*_bfd_error_handler
)
587 (_("%s: dynamic object with no .loader section"),
588 bfd_get_filename (abfd
));
589 bfd_set_error (bfd_error_no_symbols
);
593 if (! xcoff_get_section_contents (abfd
, lsec
))
595 contents
= coff_section_data (abfd
, lsec
)->contents
;
597 /* Remove the sections from this object, so that they do not get
598 included in the link. */
599 bfd_section_list_clear (abfd
);
601 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
603 strings
= (char *) contents
+ ldhdr
.l_stoff
;
605 elsym
= contents
+ bfd_xcoff_loader_symbol_offset(abfd
, &ldhdr
);
607 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz(abfd
);
609 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz(abfd
))
611 struct internal_ldsym ldsym
;
612 char nambuf
[SYMNMLEN
+ 1];
614 struct xcoff_link_hash_entry
*h
;
616 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
618 /* We are only interested in exported symbols. */
619 if ((ldsym
.l_smtype
& L_EXPORT
) == 0)
622 if (ldsym
._l
._l_l
._l_zeroes
== 0)
623 name
= strings
+ ldsym
._l
._l_l
._l_offset
;
626 memcpy (nambuf
, ldsym
._l
._l_name
, SYMNMLEN
);
627 nambuf
[SYMNMLEN
] = '\0';
631 /* Normally we could not call xcoff_link_hash_lookup in an add
632 symbols routine, since we might not be using an XCOFF hash
633 table. However, we verified above that we are using an XCOFF
636 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, TRUE
,
641 h
->flags
|= XCOFF_DEF_DYNAMIC
;
643 /* If the symbol is undefined, and the BFD it was found in is
644 not a dynamic object, change the BFD to this dynamic object,
645 so that we can get the correct import file ID. */
646 if ((h
->root
.type
== bfd_link_hash_undefined
647 || h
->root
.type
== bfd_link_hash_undefweak
)
648 && (h
->root
.u
.undef
.abfd
== NULL
649 || (h
->root
.u
.undef
.abfd
->flags
& DYNAMIC
) == 0))
650 h
->root
.u
.undef
.abfd
= abfd
;
652 if (h
->root
.type
== bfd_link_hash_new
)
654 h
->root
.type
= bfd_link_hash_undefined
;
655 h
->root
.u
.undef
.abfd
= abfd
;
656 /* We do not want to add this to the undefined symbol list. */
659 if (h
->smclas
== XMC_UA
660 || h
->root
.type
== bfd_link_hash_undefined
661 || h
->root
.type
== bfd_link_hash_undefweak
)
662 h
->smclas
= ldsym
.l_smclas
;
664 /* Unless this is an XMC_XO symbol, we don't bother to actually
665 define it, since we don't have a section to put it in anyhow.
666 Instead, the relocation routines handle the DEF_DYNAMIC flag
669 if (h
->smclas
== XMC_XO
670 && (h
->root
.type
== bfd_link_hash_undefined
671 || h
->root
.type
== bfd_link_hash_undefweak
))
673 /* This symbol has an absolute value. */
674 h
->root
.type
= bfd_link_hash_defined
;
675 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
676 h
->root
.u
.def
.value
= ldsym
.l_value
;
679 /* If this symbol defines a function descriptor, then it
680 implicitly defines the function code as well. */
681 if (h
->smclas
== XMC_DS
682 || (h
->smclas
== XMC_XO
&& name
[0] != '.'))
683 h
->flags
|= XCOFF_DESCRIPTOR
;
684 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0)
686 struct xcoff_link_hash_entry
*hds
;
693 dsnm
= bfd_malloc ((bfd_size_type
) strlen (name
) + 2);
697 strcpy (dsnm
+ 1, name
);
698 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
), dsnm
,
704 if (hds
->root
.type
== bfd_link_hash_new
)
706 hds
->root
.type
= bfd_link_hash_undefined
;
707 hds
->root
.u
.undef
.abfd
= abfd
;
708 /* We do not want to add this to the undefined
716 hds
->flags
|= XCOFF_DEF_DYNAMIC
;
717 if (hds
->smclas
== XMC_UA
)
718 hds
->smclas
= XMC_PR
;
720 /* An absolute symbol appears to actually define code, not a
721 function descriptor. This is how some math functions are
722 implemented on AIX 4.1. */
723 if (h
->smclas
== XMC_XO
724 && (hds
->root
.type
== bfd_link_hash_undefined
725 || hds
->root
.type
== bfd_link_hash_undefweak
))
727 hds
->smclas
= XMC_XO
;
728 hds
->root
.type
= bfd_link_hash_defined
;
729 hds
->root
.u
.def
.section
= bfd_abs_section_ptr
;
730 hds
->root
.u
.def
.value
= ldsym
.l_value
;
735 if (contents
!= NULL
&& ! coff_section_data (abfd
, lsec
)->keep_contents
)
737 free (coff_section_data (abfd
, lsec
)->contents
);
738 coff_section_data (abfd
, lsec
)->contents
= NULL
;
741 /* Record this file in the import files. */
742 n
= bfd_alloc (abfd
, (bfd_size_type
) sizeof (struct xcoff_import_file
));
747 /* For some reason, the path entry in the import file list for a
748 shared object appears to always be empty. The file name is the
751 if (abfd
->my_archive
== NULL
)
753 bname
= bfd_get_filename (abfd
);
758 bname
= bfd_get_filename (abfd
->my_archive
);
759 mname
= bfd_get_filename (abfd
);
761 s
= strrchr (bname
, '/');
767 /* We start c at 1 because the first import file number is reserved
769 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
771 pp
= &(*pp
)->next
, ++c
)
775 xcoff_data (abfd
)->import_file_id
= c
;
780 /* xcoff_link_create_extra_sections
782 Takes care of creating the .loader, .gl, .ds, .debug and sections. */
785 xcoff_link_create_extra_sections (bfd
* abfd
, struct bfd_link_info
*info
)
787 bfd_boolean return_value
= FALSE
;
789 if (info
->output_bfd
->xvec
== abfd
->xvec
)
791 /* We need to build a .loader section, so we do it here. This
792 won't work if we're producing an XCOFF output file with no
793 XCOFF input files. FIXME. */
795 if (xcoff_hash_table (info
)->loader_section
== NULL
)
798 flagword flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
800 lsec
= bfd_make_section_anyway_with_flags (abfd
, ".loader", flags
);
804 xcoff_hash_table (info
)->loader_section
= lsec
;
807 /* Likewise for the linkage section. */
808 if (xcoff_hash_table (info
)->linkage_section
== NULL
)
811 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
814 lsec
= bfd_make_section_anyway_with_flags (abfd
, ".gl", flags
);
818 xcoff_hash_table (info
)->linkage_section
= lsec
;
819 lsec
->alignment_power
= 2;
822 /* Likewise for the TOC section. */
823 if (xcoff_hash_table (info
)->toc_section
== NULL
)
826 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
829 tsec
= bfd_make_section_anyway_with_flags (abfd
, ".tc", flags
);
833 xcoff_hash_table (info
)->toc_section
= tsec
;
834 tsec
->alignment_power
= 2;
837 /* Likewise for the descriptor section. */
838 if (xcoff_hash_table (info
)->descriptor_section
== NULL
)
841 flagword flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
844 dsec
= bfd_make_section_anyway_with_flags (abfd
, ".ds", flags
);
848 xcoff_hash_table (info
)->descriptor_section
= dsec
;
849 dsec
->alignment_power
= 2;
852 /* Likewise for the .debug section. */
853 if (xcoff_hash_table (info
)->debug_section
== NULL
854 && info
->strip
!= strip_all
)
857 flagword flags
= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
859 dsec
= bfd_make_section_anyway_with_flags (abfd
, ".debug", flags
);
863 xcoff_hash_table (info
)->debug_section
= dsec
;
874 /* Returns the index of reloc in RELOCS with the least address greater
875 than or equal to ADDRESS. The relocs are sorted by address. */
878 xcoff_find_reloc (struct internal_reloc
*relocs
,
882 bfd_size_type min
, max
, this;
886 if (count
== 1 && relocs
[0].r_vaddr
< address
)
895 /* Do a binary search over (min,max]. */
896 while (min
+ 1 < max
)
900 this = (max
+ min
) / 2;
901 raddr
= relocs
[this].r_vaddr
;
904 else if (raddr
< address
)
913 if (relocs
[min
].r_vaddr
< address
)
917 && relocs
[min
- 1].r_vaddr
== address
)
923 /* Add all the symbols from an object file to the hash table.
925 XCOFF is a weird format. A normal XCOFF .o files will have three
926 COFF sections--.text, .data, and .bss--but each COFF section will
927 contain many csects. These csects are described in the symbol
928 table. From the linker's point of view, each csect must be
929 considered a section in its own right. For example, a TOC entry is
930 handled as a small XMC_TC csect. The linker must be able to merge
931 different TOC entries together, which means that it must be able to
932 extract the XMC_TC csects from the .data section of the input .o
935 From the point of view of our linker, this is, of course, a hideous
936 nightmare. We cope by actually creating sections for each csect,
937 and discarding the original sections. We then have to handle the
938 relocation entries carefully, since the only way to tell which
939 csect they belong to is to examine the address. */
942 xcoff_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
944 unsigned int n_tmask
;
945 unsigned int n_btshft
;
946 bfd_boolean default_copy
;
947 bfd_size_type symcount
;
948 struct xcoff_link_hash_entry
**sym_hash
;
949 asection
**csect_cache
;
950 bfd_size_type linesz
;
953 bfd_boolean keep_syms
;
955 unsigned int csect_index
;
956 asection
*first_csect
;
957 bfd_size_type symesz
;
960 struct reloc_info_struct
962 struct internal_reloc
*relocs
;
965 } *reloc_info
= NULL
;
968 keep_syms
= obj_coff_keep_syms (abfd
);
970 if ((abfd
->flags
& DYNAMIC
) != 0
971 && ! info
->static_link
)
973 if (! xcoff_link_add_dynamic_symbols (abfd
, info
))
977 /* Create the loader, toc, gl, ds and debug sections, if needed. */
978 if (! xcoff_link_create_extra_sections (abfd
, info
))
981 if ((abfd
->flags
& DYNAMIC
) != 0
982 && ! info
->static_link
)
985 n_tmask
= coff_data (abfd
)->local_n_tmask
;
986 n_btshft
= coff_data (abfd
)->local_n_btshft
;
988 /* Define macros so that ISFCN, et. al., macros work correctly. */
989 #define N_TMASK n_tmask
990 #define N_BTSHFT n_btshft
992 if (info
->keep_memory
)
993 default_copy
= FALSE
;
997 symcount
= obj_raw_syment_count (abfd
);
999 /* We keep a list of the linker hash table entries that correspond
1000 to each external symbol. */
1001 amt
= symcount
* sizeof (struct xcoff_link_hash_entry
*);
1002 sym_hash
= bfd_zalloc (abfd
, amt
);
1003 if (sym_hash
== NULL
&& symcount
!= 0)
1005 coff_data (abfd
)->sym_hashes
= (struct coff_link_hash_entry
**) sym_hash
;
1007 /* Because of the weird stuff we are doing with XCOFF csects, we can
1008 not easily determine which section a symbol is in, so we store
1009 the information in the tdata for the input file. */
1010 amt
= symcount
* sizeof (asection
*);
1011 csect_cache
= bfd_zalloc (abfd
, amt
);
1012 if (csect_cache
== NULL
&& symcount
!= 0)
1014 xcoff_data (abfd
)->csects
= csect_cache
;
1016 /* While splitting sections into csects, we need to assign the
1017 relocs correctly. The relocs and the csects must both be in
1018 order by VMA within a given section, so we handle this by
1019 scanning along the relocs as we process the csects. We index
1020 into reloc_info using the section target_index. */
1021 amt
= abfd
->section_count
+ 1;
1022 amt
*= sizeof (struct reloc_info_struct
);
1023 reloc_info
= bfd_zmalloc (amt
);
1024 if (reloc_info
== NULL
)
1027 /* Read in the relocs and line numbers for each section. */
1028 linesz
= bfd_coff_linesz (abfd
);
1030 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1034 if ((o
->flags
& SEC_RELOC
) != 0)
1036 reloc_info
[o
->target_index
].relocs
=
1037 xcoff_read_internal_relocs (abfd
, o
, TRUE
, NULL
, FALSE
, NULL
);
1038 amt
= o
->reloc_count
;
1039 amt
*= sizeof (asection
*);
1040 reloc_info
[o
->target_index
].csects
= bfd_zmalloc (amt
);
1041 if (reloc_info
[o
->target_index
].csects
== NULL
)
1045 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1046 && o
->lineno_count
> 0)
1050 amt
= linesz
* o
->lineno_count
;
1051 linenos
= bfd_malloc (amt
);
1052 if (linenos
== NULL
)
1054 reloc_info
[o
->target_index
].linenos
= linenos
;
1055 if (bfd_seek (abfd
, o
->line_filepos
, SEEK_SET
) != 0
1056 || bfd_bread (linenos
, amt
, abfd
) != amt
)
1061 /* Don't let the linker relocation routines discard the symbols. */
1062 obj_coff_keep_syms (abfd
) = TRUE
;
1068 symesz
= bfd_coff_symesz (abfd
);
1069 BFD_ASSERT (symesz
== bfd_coff_auxesz (abfd
));
1070 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
1071 esym_end
= esym
+ symcount
* symesz
;
1073 while (esym
< esym_end
)
1075 struct internal_syment sym
;
1076 union internal_auxent aux
;
1078 char buf
[SYMNMLEN
+ 1];
1083 struct xcoff_link_hash_entry
*set_toc
;
1085 bfd_coff_swap_sym_in (abfd
, (void *) esym
, (void *) &sym
);
1087 /* In this pass we are only interested in symbols with csect
1089 if (sym
.n_sclass
!= C_EXT
&& sym
.n_sclass
!= C_HIDEXT
)
1092 Normally csect is a .pr, .rw etc. created in the loop
1093 If C_FILE or first time, handle special
1095 Advance esym, sym_hash, csect_hash ptrs. */
1096 if (sym
.n_sclass
== C_FILE
)
1099 *csect_cache
= csect
;
1100 else if (first_csect
== NULL
|| sym
.n_sclass
== C_FILE
)
1101 *csect_cache
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1103 *csect_cache
= NULL
;
1104 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1105 sym_hash
+= sym
.n_numaux
+ 1;
1106 csect_cache
+= sym
.n_numaux
+ 1;
1111 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
1116 /* If this symbol has line number information attached to it,
1117 and we're not stripping it, count the number of entries and
1118 add them to the count for this csect. In the final link pass
1119 we are going to attach line number information by symbol,
1120 rather than by section, in order to more easily handle
1121 garbage collection. */
1122 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1125 && ISFCN (sym
.n_type
))
1127 union internal_auxent auxlin
;
1129 bfd_coff_swap_aux_in (abfd
, (void *) (esym
+ symesz
),
1130 sym
.n_type
, sym
.n_sclass
,
1131 0, sym
.n_numaux
, (void *) &auxlin
);
1133 if (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
1135 asection
*enclosing
;
1136 bfd_signed_vma linoff
;
1138 enclosing
= xcoff_section_data (abfd
, csect
)->enclosing
;
1139 if (enclosing
== NULL
)
1141 (*_bfd_error_handler
)
1142 (_("%B: `%s' has line numbers but no enclosing section"),
1144 bfd_set_error (bfd_error_bad_value
);
1147 linoff
= (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
1148 - enclosing
->line_filepos
);
1149 /* Explicit cast to bfd_signed_vma for compiler. */
1150 if (linoff
< (bfd_signed_vma
) (enclosing
->lineno_count
* linesz
))
1152 struct internal_lineno lin
;
1153 bfd_byte
*linpstart
;
1155 linpstart
= (reloc_info
[enclosing
->target_index
].linenos
1157 bfd_coff_swap_lineno_in (abfd
, (void *) linpstart
, (void *) &lin
);
1159 && ((bfd_size_type
) lin
.l_addr
.l_symndx
1161 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1164 bfd_byte
*linpend
, *linp
;
1166 linpend
= (reloc_info
[enclosing
->target_index
].linenos
1167 + enclosing
->lineno_count
* linesz
);
1168 for (linp
= linpstart
+ linesz
;
1172 bfd_coff_swap_lineno_in (abfd
, (void *) linp
,
1174 if (lin
.l_lnno
== 0)
1177 csect
->lineno_count
+= (linp
- linpstart
) / linesz
;
1178 /* The setting of line_filepos will only be
1179 useful if all the line number entries for a
1180 csect are contiguous; this only matters for
1182 if (csect
->line_filepos
== 0)
1183 csect
->line_filepos
=
1184 auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1190 /* Pick up the csect auxiliary information. */
1191 if (sym
.n_numaux
== 0)
1193 (*_bfd_error_handler
)
1194 (_("%B: class %d symbol `%s' has no aux entries"),
1195 abfd
, sym
.n_sclass
, name
);
1196 bfd_set_error (bfd_error_bad_value
);
1200 bfd_coff_swap_aux_in (abfd
,
1201 (void *) (esym
+ symesz
* sym
.n_numaux
),
1202 sym
.n_type
, sym
.n_sclass
,
1203 sym
.n_numaux
- 1, sym
.n_numaux
,
1206 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
1216 (*_bfd_error_handler
)
1217 (_("%B: symbol `%s' has unrecognized csect type %d"),
1219 bfd_set_error (bfd_error_bad_value
);
1223 /* This is an external reference. */
1224 if (sym
.n_sclass
== C_HIDEXT
1225 || sym
.n_scnum
!= N_UNDEF
1226 || aux
.x_csect
.x_scnlen
.l
!= 0)
1228 (*_bfd_error_handler
)
1229 (_("%B: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
1230 abfd
, name
, sym
.n_sclass
, sym
.n_scnum
,
1231 aux
.x_csect
.x_scnlen
.l
);
1232 bfd_set_error (bfd_error_bad_value
);
1236 /* An XMC_XO external reference is actually a reference to
1237 an absolute location. */
1238 if (aux
.x_csect
.x_smclas
!= XMC_XO
)
1239 section
= bfd_und_section_ptr
;
1242 section
= bfd_abs_section_ptr
;
1243 value
= sym
.n_value
;
1249 csect_index
= -(unsigned) 1;
1251 /* When we see a TOC anchor, we record the TOC value. */
1252 if (aux
.x_csect
.x_smclas
== XMC_TC0
)
1254 if (sym
.n_sclass
!= C_HIDEXT
1255 || aux
.x_csect
.x_scnlen
.l
!= 0)
1257 (*_bfd_error_handler
)
1258 (_("%B: XMC_TC0 symbol `%s' is class %d scnlen %d"),
1259 abfd
, name
, sym
.n_sclass
, aux
.x_csect
.x_scnlen
.l
);
1260 bfd_set_error (bfd_error_bad_value
);
1263 xcoff_data (abfd
)->toc
= sym
.n_value
;
1266 /* We must merge TOC entries for the same symbol. We can
1267 merge two TOC entries if they are both C_HIDEXT, they
1268 both have the same name, they are both 4 or 8 bytes long, and
1269 they both have a relocation table entry for an external
1270 symbol with the same name. Unfortunately, this means
1271 that we must look through the relocations. Ick.
1273 Logic for 32 bit vs 64 bit.
1274 32 bit has a csect length of 4 for TOC
1275 64 bit has a csect length of 8 for TOC
1277 The conditions to get past the if-check are not that bad.
1278 They are what is used to create the TOC csects in the first
1280 if (aux
.x_csect
.x_smclas
== XMC_TC
1281 && sym
.n_sclass
== C_HIDEXT
1282 && info
->output_bfd
->xvec
== abfd
->xvec
1283 && ((bfd_xcoff_is_xcoff32 (abfd
)
1284 && aux
.x_csect
.x_scnlen
.l
== 4)
1285 || (bfd_xcoff_is_xcoff64 (abfd
)
1286 && aux
.x_csect
.x_scnlen
.l
== 8)))
1288 asection
*enclosing
;
1289 struct internal_reloc
*relocs
;
1290 bfd_size_type relindx
;
1291 struct internal_reloc
*rel
;
1293 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1294 if (enclosing
== NULL
)
1297 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1298 amt
= enclosing
->reloc_count
;
1299 relindx
= xcoff_find_reloc (relocs
, amt
, sym
.n_value
);
1300 rel
= relocs
+ relindx
;
1302 /* 32 bit R_POS r_size is 31
1303 64 bit R_POS r_size is 63 */
1304 if (relindx
< enclosing
->reloc_count
1305 && rel
->r_vaddr
== (bfd_vma
) sym
.n_value
1306 && rel
->r_type
== R_POS
1307 && ((bfd_xcoff_is_xcoff32 (abfd
)
1308 && rel
->r_size
== 31)
1309 || (bfd_xcoff_is_xcoff64 (abfd
)
1310 && rel
->r_size
== 63)))
1314 struct internal_syment relsym
;
1316 erelsym
= ((bfd_byte
*) obj_coff_external_syms (abfd
)
1317 + rel
->r_symndx
* symesz
);
1318 bfd_coff_swap_sym_in (abfd
, (void *) erelsym
, (void *) &relsym
);
1319 if (relsym
.n_sclass
== C_EXT
)
1321 const char *relname
;
1322 char relbuf
[SYMNMLEN
+ 1];
1324 struct xcoff_link_hash_entry
*h
;
1326 /* At this point we know that the TOC entry is
1327 for an externally visible symbol. */
1328 relname
= _bfd_coff_internal_syment_name (abfd
, &relsym
,
1330 if (relname
== NULL
)
1333 /* We only merge TOC entries if the TC name is
1334 the same as the symbol name. This handles
1335 the normal case, but not common cases like
1336 SYM.P4 which gcc generates to store SYM + 4
1337 in the TOC. FIXME. */
1338 if (strcmp (name
, relname
) == 0)
1340 copy
= (! info
->keep_memory
1341 || relsym
._n
._n_n
._n_zeroes
!= 0
1342 || relsym
._n
._n_n
._n_offset
== 0);
1343 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1344 relname
, TRUE
, copy
,
1349 /* At this point h->root.type could be
1350 bfd_link_hash_new. That should be OK,
1351 since we know for sure that we will come
1352 across this symbol as we step through the
1355 /* We store h in *sym_hash for the
1356 convenience of the relocate_section
1360 if (h
->toc_section
!= NULL
)
1362 asection
**rel_csects
;
1364 /* We already have a TOC entry for this
1365 symbol, so we can just ignore this
1368 reloc_info
[enclosing
->target_index
].csects
;
1369 rel_csects
[relindx
] = bfd_und_section_ptr
;
1373 /* We are about to create a TOC entry for
1382 asection
*enclosing
;
1384 /* We need to create a new section. We get the name from
1385 the csect storage mapping class, so that the linker can
1386 accumulate similar csects together. */
1388 csect
= bfd_xcoff_create_csect_from_smclas(abfd
, &aux
, name
);
1392 /* The enclosing section is the main section : .data, .text
1393 or .bss that the csect is coming from. */
1394 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1395 if (enclosing
== NULL
)
1398 if (! bfd_is_abs_section (enclosing
)
1399 && ((bfd_vma
) sym
.n_value
< enclosing
->vma
1400 || ((bfd_vma
) sym
.n_value
+ aux
.x_csect
.x_scnlen
.l
1401 > enclosing
->vma
+ enclosing
->size
)))
1403 (*_bfd_error_handler
)
1404 (_("%B: csect `%s' not in enclosing section"),
1406 bfd_set_error (bfd_error_bad_value
);
1409 csect
->vma
= sym
.n_value
;
1410 csect
->filepos
= (enclosing
->filepos
1413 csect
->size
= aux
.x_csect
.x_scnlen
.l
;
1414 csect
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
1415 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1417 /* Record the enclosing section in the tdata for this new
1419 amt
= sizeof (struct coff_section_tdata
);
1420 csect
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
1421 if (csect
->used_by_bfd
== NULL
)
1423 amt
= sizeof (struct xcoff_section_tdata
);
1424 coff_section_data (abfd
, csect
)->tdata
= bfd_zalloc (abfd
, amt
);
1425 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1427 xcoff_section_data (abfd
, csect
)->enclosing
= enclosing
;
1428 xcoff_section_data (abfd
, csect
)->lineno_count
=
1429 enclosing
->lineno_count
;
1431 if (enclosing
->owner
== abfd
)
1433 struct internal_reloc
*relocs
;
1434 bfd_size_type relindx
;
1435 struct internal_reloc
*rel
;
1436 asection
**rel_csect
;
1438 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1439 amt
= enclosing
->reloc_count
;
1440 relindx
= xcoff_find_reloc (relocs
, amt
, csect
->vma
);
1442 rel
= relocs
+ relindx
;
1443 rel_csect
= (reloc_info
[enclosing
->target_index
].csects
1446 csect
->rel_filepos
= (enclosing
->rel_filepos
1447 + relindx
* bfd_coff_relsz (abfd
));
1448 while (relindx
< enclosing
->reloc_count
1449 && *rel_csect
== NULL
1450 && rel
->r_vaddr
< csect
->vma
+ csect
->size
)
1454 csect
->flags
|= SEC_RELOC
;
1455 ++csect
->reloc_count
;
1462 /* There are a number of other fields and section flags
1463 which we do not bother to set. */
1465 csect_index
= ((esym
1466 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1469 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1471 if (first_csect
== NULL
)
1472 first_csect
= csect
;
1474 /* If this symbol is C_EXT, we treat it as starting at the
1475 beginning of the newly created section. */
1476 if (sym
.n_sclass
== C_EXT
)
1482 /* If this is a TOC section for a symbol, record it. */
1483 if (set_toc
!= NULL
)
1484 set_toc
->toc_section
= csect
;
1489 /* This is a label definition. The x_scnlen field is the
1490 symbol index of the csect. Usually the XTY_LD symbol will
1491 follow its appropriate XTY_SD symbol. The .set pseudo op can
1492 cause the XTY_LD to not follow the XTY_SD symbol. */
1497 if (aux
.x_csect
.x_scnlen
.l
< 0
1498 || (aux
.x_csect
.x_scnlen
.l
1499 >= esym
- (bfd_byte
*) obj_coff_external_syms (abfd
)))
1503 section
= xcoff_data (abfd
)->csects
[aux
.x_csect
.x_scnlen
.l
];
1505 || (section
->flags
& SEC_HAS_CONTENTS
) == 0)
1510 (*_bfd_error_handler
)
1511 (_("%B: misplaced XTY_LD `%s'"),
1513 bfd_set_error (bfd_error_bad_value
);
1517 value
= sym
.n_value
- csect
->vma
;
1522 /* This is an unitialized csect. We could base the name on
1523 the storage mapping class, but we don't bother except for
1524 an XMC_TD symbol. If this csect is externally visible,
1525 it is a common symbol. We put XMC_TD symbols in sections
1526 named .tocbss, and rely on the linker script to put that
1529 if (aux
.x_csect
.x_smclas
== XMC_TD
)
1531 /* The linker script puts the .td section in the data
1532 section after the .tc section. */
1533 csect
= bfd_make_section_anyway_with_flags (abfd
, ".td",
1537 csect
= bfd_make_section_anyway_with_flags (abfd
, ".bss",
1542 csect
->vma
= sym
.n_value
;
1543 csect
->size
= aux
.x_csect
.x_scnlen
.l
;
1544 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1545 /* There are a number of other fields and section flags
1546 which we do not bother to set. */
1548 csect_index
= ((esym
1549 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1552 amt
= sizeof (struct coff_section_tdata
);
1553 csect
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
1554 if (csect
->used_by_bfd
== NULL
)
1556 amt
= sizeof (struct xcoff_section_tdata
);
1557 coff_section_data (abfd
, csect
)->tdata
= bfd_zalloc (abfd
, amt
);
1558 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1560 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1562 if (first_csect
== NULL
)
1563 first_csect
= csect
;
1565 if (sym
.n_sclass
== C_EXT
)
1567 csect
->flags
|= SEC_IS_COMMON
;
1570 value
= aux
.x_csect
.x_scnlen
.l
;
1576 /* Check for magic symbol names. */
1577 if ((smtyp
== XTY_SD
|| smtyp
== XTY_CM
)
1578 && aux
.x_csect
.x_smclas
!= XMC_TC
1579 && aux
.x_csect
.x_smclas
!= XMC_TD
)
1585 if (strcmp (name
, "_text") == 0)
1586 i
= XCOFF_SPECIAL_SECTION_TEXT
;
1587 else if (strcmp (name
, "_etext") == 0)
1588 i
= XCOFF_SPECIAL_SECTION_ETEXT
;
1589 else if (strcmp (name
, "_data") == 0)
1590 i
= XCOFF_SPECIAL_SECTION_DATA
;
1591 else if (strcmp (name
, "_edata") == 0)
1592 i
= XCOFF_SPECIAL_SECTION_EDATA
;
1593 else if (strcmp (name
, "_end") == 0)
1594 i
= XCOFF_SPECIAL_SECTION_END
;
1596 else if (name
[0] == 'e' && strcmp (name
, "end") == 0)
1597 i
= XCOFF_SPECIAL_SECTION_END2
;
1600 xcoff_hash_table (info
)->special_sections
[i
] = csect
;
1603 /* Now we have enough information to add the symbol to the
1604 linker hash table. */
1606 if (sym
.n_sclass
== C_EXT
)
1610 BFD_ASSERT (section
!= NULL
);
1612 /* We must copy the name into memory if we got it from the
1613 syment itself, rather than the string table. */
1614 copy
= default_copy
;
1615 if (sym
._n
._n_n
._n_zeroes
!= 0
1616 || sym
._n
._n_n
._n_offset
== 0)
1619 /* The AIX linker appears to only detect multiple symbol
1620 definitions when there is a reference to the symbol. If
1621 a symbol is defined multiple times, and the only
1622 references are from the same object file, the AIX linker
1623 appears to permit it. It does not merge the different
1624 definitions, but handles them independently. On the
1625 other hand, if there is a reference, the linker reports
1628 This matters because the AIX <net/net_globals.h> header
1629 file actually defines an initialized array, so we have to
1630 actually permit that to work.
1632 Just to make matters even more confusing, the AIX linker
1633 appears to permit multiple symbol definitions whenever
1634 the second definition is in an archive rather than an
1635 object file. This may be a consequence of the manner in
1636 which it handles archives: I think it may load the entire
1637 archive in as separate csects, and then let garbage
1638 collection discard symbols.
1640 We also have to handle the case of statically linking a
1641 shared object, which will cause symbol redefinitions,
1642 although this is an easier case to detect. */
1644 if (info
->output_bfd
->xvec
== abfd
->xvec
)
1646 if (! bfd_is_und_section (section
))
1647 *sym_hash
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1648 name
, TRUE
, copy
, FALSE
);
1650 /* Make a copy of the symbol name to prevent problems with
1652 *sym_hash
= ((struct xcoff_link_hash_entry
*)
1653 bfd_wrapped_link_hash_lookup (abfd
, info
, name
,
1654 TRUE
, TRUE
, FALSE
));
1656 if (*sym_hash
== NULL
)
1658 if (((*sym_hash
)->root
.type
== bfd_link_hash_defined
1659 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1660 && ! bfd_is_und_section (section
)
1661 && ! bfd_is_com_section (section
))
1663 /* This is a second definition of a defined symbol. */
1664 if ((abfd
->flags
& DYNAMIC
) != 0
1665 && ((*sym_hash
)->smclas
!= XMC_GL
1666 || aux
.x_csect
.x_smclas
== XMC_GL
1667 || ((*sym_hash
)->root
.u
.def
.section
->owner
->flags
1670 /* The new symbol is from a shared library, and
1671 either the existing symbol is not global
1672 linkage code or this symbol is global linkage
1673 code. If the existing symbol is global
1674 linkage code and the new symbol is not, then
1675 we want to use the new symbol. */
1676 section
= bfd_und_section_ptr
;
1679 else if (((*sym_hash
)->root
.u
.def
.section
->owner
->flags
1682 /* The existing symbol is from a shared library.
1684 (*sym_hash
)->root
.type
= bfd_link_hash_undefined
;
1685 (*sym_hash
)->root
.u
.undef
.abfd
=
1686 (*sym_hash
)->root
.u
.def
.section
->owner
;
1688 else if (abfd
->my_archive
!= NULL
)
1690 /* This is a redefinition in an object contained
1691 in an archive. Just ignore it. See the
1693 section
= bfd_und_section_ptr
;
1696 else if ((*sym_hash
)->root
.u
.undef
.next
!= NULL
1697 || info
->hash
->undefs_tail
== &(*sym_hash
)->root
)
1699 /* This symbol has been referenced. In this
1700 case, we just continue and permit the
1701 multiple definition error. See the comment
1702 above about the behaviour of the AIX linker. */
1704 else if ((*sym_hash
)->smclas
== aux
.x_csect
.x_smclas
)
1706 /* The symbols are both csects of the same
1707 class. There is at least a chance that this
1708 is a semi-legitimate redefinition. */
1709 section
= bfd_und_section_ptr
;
1711 (*sym_hash
)->flags
|= XCOFF_MULTIPLY_DEFINED
;
1714 else if (((*sym_hash
)->flags
& XCOFF_MULTIPLY_DEFINED
) != 0
1715 && ((*sym_hash
)->root
.type
== bfd_link_hash_defined
1716 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1717 && (bfd_is_und_section (section
)
1718 || bfd_is_com_section (section
)))
1720 /* This is a reference to a multiply defined symbol.
1721 Report the error now. See the comment above
1722 about the behaviour of the AIX linker. We could
1723 also do this with warning symbols, but I'm not
1724 sure the XCOFF linker is wholly prepared to
1725 handle them, and that would only be a warning,
1727 if (! ((*info
->callbacks
->multiple_definition
)
1728 (info
, (*sym_hash
)->root
.root
.string
,
1729 NULL
, NULL
, (bfd_vma
) 0,
1730 (*sym_hash
)->root
.u
.def
.section
->owner
,
1731 (*sym_hash
)->root
.u
.def
.section
,
1732 (*sym_hash
)->root
.u
.def
.value
)))
1734 /* Try not to give this error too many times. */
1735 (*sym_hash
)->flags
&= ~XCOFF_MULTIPLY_DEFINED
;
1739 /* _bfd_generic_link_add_one_symbol may call the linker to
1740 generate an error message, and the linker may try to read
1741 the symbol table to give a good error. Right now, the
1742 line numbers are in an inconsistent state, since they are
1743 counted both in the real sections and in the new csects.
1744 We need to leave the count in the real sections so that
1745 the linker can report the line number of the error
1746 correctly, so temporarily clobber the link to the csects
1747 so that the linker will not try to read the line numbers
1748 a second time from the csects. */
1749 BFD_ASSERT (last_real
->next
== first_csect
);
1750 last_real
->next
= NULL
;
1751 if (! (_bfd_generic_link_add_one_symbol
1752 (info
, abfd
, name
, flags
, section
, value
,
1754 (struct bfd_link_hash_entry
**) sym_hash
)))
1756 last_real
->next
= first_csect
;
1758 if (smtyp
== XTY_CM
)
1760 if ((*sym_hash
)->root
.type
!= bfd_link_hash_common
1761 || (*sym_hash
)->root
.u
.c
.p
->section
!= csect
)
1762 /* We don't need the common csect we just created. */
1765 (*sym_hash
)->root
.u
.c
.p
->alignment_power
1766 = csect
->alignment_power
;
1769 if (info
->output_bfd
->xvec
== abfd
->xvec
)
1773 if (smtyp
== XTY_ER
|| smtyp
== XTY_CM
)
1774 flag
= XCOFF_REF_REGULAR
;
1776 flag
= XCOFF_DEF_REGULAR
;
1777 (*sym_hash
)->flags
|= flag
;
1779 if ((*sym_hash
)->smclas
== XMC_UA
1780 || flag
== XCOFF_DEF_REGULAR
)
1781 (*sym_hash
)->smclas
= aux
.x_csect
.x_smclas
;
1785 if (smtyp
== XTY_ER
)
1786 *csect_cache
= section
;
1789 *csect_cache
= csect
;
1791 xcoff_section_data (abfd
, csect
)->last_symndx
1792 = (esym
- (bfd_byte
*) obj_coff_external_syms (abfd
)) / symesz
;
1795 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1796 sym_hash
+= sym
.n_numaux
+ 1;
1797 csect_cache
+= sym
.n_numaux
+ 1;
1800 BFD_ASSERT (last_real
== NULL
|| last_real
->next
== first_csect
);
1802 /* Make sure that we have seen all the relocs. */
1803 for (o
= abfd
->sections
; o
!= first_csect
; o
= o
->next
)
1805 /* Reset the section size and the line number count, since the
1806 data is now attached to the csects. Don't reset the size of
1807 the .debug section, since we need to read it below in
1808 bfd_xcoff_size_dynamic_sections. */
1809 if (strcmp (bfd_get_section_name (abfd
, o
), ".debug") != 0)
1811 o
->lineno_count
= 0;
1813 if ((o
->flags
& SEC_RELOC
) != 0)
1816 struct internal_reloc
*rel
;
1817 asection
**rel_csect
;
1819 rel
= reloc_info
[o
->target_index
].relocs
;
1820 rel_csect
= reloc_info
[o
->target_index
].csects
;
1822 for (i
= 0; i
< o
->reloc_count
; i
++, rel
++, rel_csect
++)
1824 if (*rel_csect
== NULL
)
1826 (*_bfd_error_handler
)
1827 (_("%B: reloc %s:%d not in csect"),
1829 bfd_set_error (bfd_error_bad_value
);
1833 /* We identify all function symbols that are the target
1834 of a relocation, so that we can create glue code for
1835 functions imported from dynamic objects. */
1836 if (info
->output_bfd
->xvec
== abfd
->xvec
1837 && *rel_csect
!= bfd_und_section_ptr
1838 && obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
] != NULL
)
1840 struct xcoff_link_hash_entry
*h
;
1842 h
= obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
];
1843 /* If the symbol name starts with a period, it is
1844 the code of a function. If the symbol is
1845 currently undefined, then add an undefined symbol
1846 for the function descriptor. This should do no
1847 harm, because any regular object that defines the
1848 function should also define the function
1849 descriptor. It helps, because it means that we
1850 will identify the function descriptor with a
1851 dynamic object if a dynamic object defines it. */
1852 if (h
->root
.root
.string
[0] == '.'
1853 && h
->descriptor
== NULL
)
1855 struct xcoff_link_hash_entry
*hds
;
1856 struct bfd_link_hash_entry
*bh
;
1858 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1859 h
->root
.root
.string
+ 1,
1863 if (hds
->root
.type
== bfd_link_hash_new
)
1866 if (! (_bfd_generic_link_add_one_symbol
1867 (info
, abfd
, hds
->root
.root
.string
,
1868 (flagword
) 0, bfd_und_section_ptr
,
1869 (bfd_vma
) 0, NULL
, FALSE
,
1872 hds
= (struct xcoff_link_hash_entry
*) bh
;
1874 hds
->flags
|= XCOFF_DESCRIPTOR
;
1875 BFD_ASSERT ((h
->flags
& XCOFF_DESCRIPTOR
) == 0);
1876 hds
->descriptor
= h
;
1877 h
->descriptor
= hds
;
1879 if (h
->root
.root
.string
[0] == '.')
1880 h
->flags
|= XCOFF_CALLED
;
1884 free (reloc_info
[o
->target_index
].csects
);
1885 reloc_info
[o
->target_index
].csects
= NULL
;
1887 /* Reset SEC_RELOC and the reloc_count, since the reloc
1888 information is now attached to the csects. */
1889 o
->flags
&=~ SEC_RELOC
;
1892 /* If we are not keeping memory, free the reloc information. */
1893 if (! info
->keep_memory
1894 && coff_section_data (abfd
, o
) != NULL
1895 && coff_section_data (abfd
, o
)->relocs
!= NULL
1896 && ! coff_section_data (abfd
, o
)->keep_relocs
)
1898 free (coff_section_data (abfd
, o
)->relocs
);
1899 coff_section_data (abfd
, o
)->relocs
= NULL
;
1903 /* Free up the line numbers. FIXME: We could cache these
1904 somewhere for the final link, to avoid reading them again. */
1905 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
1907 free (reloc_info
[o
->target_index
].linenos
);
1908 reloc_info
[o
->target_index
].linenos
= NULL
;
1914 obj_coff_keep_syms (abfd
) = keep_syms
;
1919 if (reloc_info
!= NULL
)
1921 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1923 if (reloc_info
[o
->target_index
].csects
!= NULL
)
1924 free (reloc_info
[o
->target_index
].csects
);
1925 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
1926 free (reloc_info
[o
->target_index
].linenos
);
1930 obj_coff_keep_syms (abfd
) = keep_syms
;
1937 /* Add symbols from an XCOFF object file. */
1940 xcoff_link_add_object_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
1942 if (! _bfd_coff_get_external_symbols (abfd
))
1944 if (! xcoff_link_add_symbols (abfd
, info
))
1946 if (! info
->keep_memory
)
1948 if (! _bfd_coff_free_symbols (abfd
))
1954 /* Look through the loader symbols to see if this dynamic object
1955 should be included in the link. The native linker uses the loader
1956 symbols, not the normal symbol table, so we do too. */
1959 xcoff_link_check_dynamic_ar_symbols (bfd
*abfd
,
1960 struct bfd_link_info
*info
,
1961 bfd_boolean
*pneeded
)
1965 struct internal_ldhdr ldhdr
;
1966 const char *strings
;
1967 bfd_byte
*elsym
, *elsymend
;
1971 lsec
= bfd_get_section_by_name (abfd
, ".loader");
1973 /* There are no symbols, so don't try to include it. */
1976 if (! xcoff_get_section_contents (abfd
, lsec
))
1978 contents
= coff_section_data (abfd
, lsec
)->contents
;
1980 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
1982 strings
= (char *) contents
+ ldhdr
.l_stoff
;
1984 elsym
= contents
+ bfd_xcoff_loader_symbol_offset (abfd
, &ldhdr
);
1986 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz (abfd
);
1987 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz (abfd
))
1989 struct internal_ldsym ldsym
;
1990 char nambuf
[SYMNMLEN
+ 1];
1992 struct bfd_link_hash_entry
*h
;
1994 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
1996 /* We are only interested in exported symbols. */
1997 if ((ldsym
.l_smtype
& L_EXPORT
) == 0)
2000 if (ldsym
._l
._l_l
._l_zeroes
== 0)
2001 name
= strings
+ ldsym
._l
._l_l
._l_offset
;
2004 memcpy (nambuf
, ldsym
._l
._l_name
, SYMNMLEN
);
2005 nambuf
[SYMNMLEN
] = '\0';
2009 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
2011 /* We are only interested in symbols that are currently
2012 undefined. At this point we know that we are using an XCOFF
2015 && h
->type
== bfd_link_hash_undefined
2016 && (((struct xcoff_link_hash_entry
*) h
)->flags
2017 & XCOFF_DEF_DYNAMIC
) == 0)
2019 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
2026 /* We do not need this shared object. */
2027 if (contents
!= NULL
&& ! coff_section_data (abfd
, lsec
)->keep_contents
)
2029 free (coff_section_data (abfd
, lsec
)->contents
);
2030 coff_section_data (abfd
, lsec
)->contents
= NULL
;
2036 /* Look through the symbols to see if this object file should be
2037 included in the link. */
2040 xcoff_link_check_ar_symbols (bfd
*abfd
,
2041 struct bfd_link_info
*info
,
2042 bfd_boolean
*pneeded
)
2044 bfd_size_type symesz
;
2050 if ((abfd
->flags
& DYNAMIC
) != 0
2051 && ! info
->static_link
2052 && info
->output_bfd
->xvec
== abfd
->xvec
)
2053 return xcoff_link_check_dynamic_ar_symbols (abfd
, info
, pneeded
);
2055 symesz
= bfd_coff_symesz (abfd
);
2056 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
2057 esym_end
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
2058 while (esym
< esym_end
)
2060 struct internal_syment sym
;
2062 bfd_coff_swap_sym_in (abfd
, (void *) esym
, (void *) &sym
);
2064 if (sym
.n_sclass
== C_EXT
&& sym
.n_scnum
!= N_UNDEF
)
2067 char buf
[SYMNMLEN
+ 1];
2068 struct bfd_link_hash_entry
*h
;
2070 /* This symbol is externally visible, and is defined by this
2072 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
2076 h
= bfd_link_hash_lookup (info
->hash
, name
, FALSE
, FALSE
, TRUE
);
2078 /* We are only interested in symbols that are currently
2079 undefined. If a symbol is currently known to be common,
2080 XCOFF linkers do not bring in an object file which
2081 defines it. We also don't bring in symbols to satisfy
2082 undefined references in shared objects. */
2084 && h
->type
== bfd_link_hash_undefined
2085 && (info
->output_bfd
->xvec
!= abfd
->xvec
2086 || (((struct xcoff_link_hash_entry
*) h
)->flags
2087 & XCOFF_DEF_DYNAMIC
) == 0))
2089 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
2096 esym
+= (sym
.n_numaux
+ 1) * symesz
;
2099 /* We do not need this object file. */
2103 /* Check a single archive element to see if we need to include it in
2104 the link. *PNEEDED is set according to whether this element is
2105 needed in the link or not. This is called via
2106 _bfd_generic_link_add_archive_symbols. */
2109 xcoff_link_check_archive_element (bfd
*abfd
,
2110 struct bfd_link_info
*info
,
2111 bfd_boolean
*pneeded
)
2113 if (! _bfd_coff_get_external_symbols (abfd
))
2116 if (! xcoff_link_check_ar_symbols (abfd
, info
, pneeded
))
2121 if (! xcoff_link_add_symbols (abfd
, info
))
2125 if (! info
->keep_memory
|| ! *pneeded
)
2127 if (! _bfd_coff_free_symbols (abfd
))
2134 /* Given an XCOFF BFD, add symbols to the global hash table as
2138 _bfd_xcoff_bfd_link_add_symbols (bfd
*abfd
, struct bfd_link_info
*info
)
2140 switch (bfd_get_format (abfd
))
2143 return xcoff_link_add_object_symbols (abfd
, info
);
2146 /* If the archive has a map, do the usual search. We then need
2147 to check the archive for dynamic objects, because they may not
2148 appear in the archive map even though they should, perhaps, be
2149 included. If the archive has no map, we just consider each object
2150 file in turn, since that apparently is what the AIX native linker
2152 if (bfd_has_map (abfd
))
2154 if (! (_bfd_generic_link_add_archive_symbols
2155 (abfd
, info
, xcoff_link_check_archive_element
)))
2162 member
= bfd_openr_next_archived_file (abfd
, NULL
);
2163 while (member
!= NULL
)
2165 if (bfd_check_format (member
, bfd_object
)
2166 && (info
->output_bfd
->xvec
== member
->xvec
)
2167 && (! bfd_has_map (abfd
) || (member
->flags
& DYNAMIC
) != 0))
2171 if (! xcoff_link_check_archive_element (member
, info
,
2175 member
->archive_pass
= -1;
2177 member
= bfd_openr_next_archived_file (abfd
, member
);
2184 bfd_set_error (bfd_error_wrong_format
);
2189 /* If symbol H has not been interpreted as a function descriptor,
2190 see whether it should be. Set up its descriptor information if so. */
2193 xcoff_find_function (struct bfd_link_info
*info
,
2194 struct xcoff_link_hash_entry
*h
)
2196 if ((h
->flags
& XCOFF_DESCRIPTOR
) == 0
2197 && h
->root
.root
.string
[0] != '.')
2200 struct xcoff_link_hash_entry
*hfn
;
2203 amt
= strlen (h
->root
.root
.string
) + 2;
2204 fnname
= bfd_malloc (amt
);
2208 strcpy (fnname
+ 1, h
->root
.root
.string
);
2209 hfn
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
2210 fnname
, FALSE
, FALSE
, TRUE
);
2213 && hfn
->smclas
== XMC_PR
2214 && (hfn
->root
.type
== bfd_link_hash_defined
2215 || hfn
->root
.type
== bfd_link_hash_defweak
))
2217 h
->flags
|= XCOFF_DESCRIPTOR
;
2218 h
->descriptor
= hfn
;
2219 hfn
->descriptor
= h
;
2225 /* H is an imported symbol. Set the import module's path, file and member
2226 to IMPATH, IMPFILE and IMPMEMBER respectively. All three are null if
2227 no specific import module is specified. */
2230 xcoff_set_import_path (struct bfd_link_info
*info
,
2231 struct xcoff_link_hash_entry
*h
,
2232 const char *imppath
, const char *impfile
,
2233 const char *impmember
)
2236 struct xcoff_import_file
**pp
;
2238 /* We overload the ldindx field to hold the l_ifile value for this
2240 BFD_ASSERT (h
->ldsym
== NULL
);
2241 BFD_ASSERT ((h
->flags
& XCOFF_BUILT_LDSYM
) == 0);
2242 if (imppath
== NULL
)
2246 /* We start c at 1 because the first entry in the import list is
2247 reserved for the library search path. */
2248 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
2250 pp
= &(*pp
)->next
, ++c
)
2252 if (strcmp ((*pp
)->path
, imppath
) == 0
2253 && strcmp ((*pp
)->file
, impfile
) == 0
2254 && strcmp ((*pp
)->member
, impmember
) == 0)
2260 struct xcoff_import_file
*n
;
2261 bfd_size_type amt
= sizeof (* n
);
2263 n
= bfd_alloc (info
->output_bfd
, amt
);
2269 n
->member
= impmember
;
2277 /* Mark a symbol as not being garbage, including the section in which
2280 static inline bfd_boolean
2281 xcoff_mark_symbol (struct bfd_link_info
*info
, struct xcoff_link_hash_entry
*h
)
2283 if ((h
->flags
& XCOFF_MARK
) != 0)
2286 h
->flags
|= XCOFF_MARK
;
2288 /* If we're marking an undefined symbol, try find some way of
2290 if (!info
->relocatable
2291 && (h
->flags
& XCOFF_IMPORT
) == 0
2292 && (h
->flags
& XCOFF_DEF_REGULAR
) == 0
2293 && (h
->root
.type
== bfd_link_hash_undefined
2294 || h
->root
.type
== bfd_link_hash_undefweak
))
2296 /* First check whether this symbol can be interpreted as an
2297 undefined function descriptor for a defined function symbol. */
2298 if (!xcoff_find_function (info
, h
))
2301 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0
2302 && (h
->descriptor
->root
.type
== bfd_link_hash_defined
2303 || h
->descriptor
->root
.type
== bfd_link_hash_defweak
))
2305 /* This is a descriptor for a defined symbol, but the input
2306 objects have not defined the descriptor itself. Fill in
2307 the definition automatically.
2309 Note that we do this even if we found a dynamic definition
2310 of H. The local function definition logically overrides
2314 sec
= xcoff_hash_table (info
)->descriptor_section
;
2315 h
->root
.type
= bfd_link_hash_defined
;
2316 h
->root
.u
.def
.section
= sec
;
2317 h
->root
.u
.def
.value
= sec
->size
;
2319 h
->flags
|= XCOFF_DEF_REGULAR
;
2321 /* The size of the function descriptor depends on whether this
2322 is xcoff32 (12) or xcoff64 (24). */
2323 sec
->size
+= bfd_xcoff_function_descriptor_size (sec
->owner
);
2325 /* A function descriptor uses two relocs: one for the
2326 associated code, and one for the TOC address. */
2327 xcoff_hash_table (info
)->ldrel_count
+= 2;
2328 sec
->reloc_count
+= 2;
2330 /* Mark the function itself. */
2331 if (!xcoff_mark_symbol (info
, h
->descriptor
))
2334 /* Mark the TOC section, so that we get an anchor
2335 to relocate against. */
2336 if (!xcoff_mark (info
, xcoff_hash_table (info
)->toc_section
))
2339 /* We handle writing out the contents of the descriptor in
2340 xcoff_write_global_symbol. */
2342 else if ((h
->flags
& XCOFF_CALLED
) != 0)
2344 /* This is a function symbol for which we need to create
2347 struct xcoff_link_hash_entry
*hds
;
2349 /* Mark the descriptor (and its TOC section). */
2350 hds
= h
->descriptor
;
2351 BFD_ASSERT ((hds
->root
.type
== bfd_link_hash_undefined
2352 || hds
->root
.type
== bfd_link_hash_undefweak
)
2353 && (hds
->flags
& XCOFF_DEF_REGULAR
) == 0);
2354 if (!xcoff_mark_symbol (info
, hds
))
2357 /* Treat this symbol as undefined if the descriptor was. */
2358 if ((hds
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
2359 h
->flags
|= XCOFF_WAS_UNDEFINED
;
2361 /* Allocate room for the global linkage code itself. */
2362 sec
= xcoff_hash_table (info
)->linkage_section
;
2363 h
->root
.type
= bfd_link_hash_defined
;
2364 h
->root
.u
.def
.section
= sec
;
2365 h
->root
.u
.def
.value
= sec
->size
;
2367 h
->flags
|= XCOFF_DEF_REGULAR
;
2368 sec
->size
+= bfd_xcoff_glink_code_size (info
->output_bfd
);
2370 /* The global linkage code requires a TOC entry for the
2372 if (hds
->toc_section
== NULL
)
2377 xcoff32 uses 4 bytes in the toc.
2378 xcoff64 uses 8 bytes in the toc. */
2379 if (bfd_xcoff_is_xcoff64 (info
->output_bfd
))
2381 else if (bfd_xcoff_is_xcoff32 (info
->output_bfd
))
2386 /* Allocate room in the fallback TOC section. */
2387 hds
->toc_section
= xcoff_hash_table (info
)->toc_section
;
2388 hds
->u
.toc_offset
= hds
->toc_section
->size
;
2389 hds
->toc_section
->size
+= byte_size
;
2390 if (!xcoff_mark (info
, hds
->toc_section
))
2393 /* Allocate room for a static and dynamic R_TOC
2395 ++xcoff_hash_table (info
)->ldrel_count
;
2396 ++hds
->toc_section
->reloc_count
;
2398 /* Set the index to -2 to force this symbol to
2401 hds
->flags
|= XCOFF_SET_TOC
| XCOFF_LDREL
;
2404 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) == 0)
2406 /* Record that the symbol was undefined, then import it.
2407 -brtl links use a special fake import file. */
2408 h
->flags
|= XCOFF_WAS_UNDEFINED
| XCOFF_IMPORT
;
2409 if (xcoff_hash_table (info
)->rtld
)
2411 if (!xcoff_set_import_path (info
, h
, "", "..", ""))
2416 if (!xcoff_set_import_path (info
, h
, NULL
, NULL
, NULL
))
2422 if (h
->root
.type
== bfd_link_hash_defined
2423 || h
->root
.type
== bfd_link_hash_defweak
)
2427 hsec
= h
->root
.u
.def
.section
;
2428 if (! bfd_is_abs_section (hsec
)
2429 && (hsec
->flags
& SEC_MARK
) == 0)
2431 if (! xcoff_mark (info
, hsec
))
2436 if (h
->toc_section
!= NULL
2437 && (h
->toc_section
->flags
& SEC_MARK
) == 0)
2439 if (! xcoff_mark (info
, h
->toc_section
))
2446 /* The mark phase of garbage collection. For a given section, mark
2447 it, and all the sections which define symbols to which it refers.
2448 Because this function needs to look at the relocs, we also count
2449 the number of relocs which need to be copied into the .loader
2453 xcoff_mark (struct bfd_link_info
*info
, asection
*sec
)
2455 if (bfd_is_abs_section (sec
)
2456 || (sec
->flags
& SEC_MARK
) != 0)
2459 sec
->flags
|= SEC_MARK
;
2461 if (sec
->owner
->xvec
== info
->output_bfd
->xvec
2462 && coff_section_data (sec
->owner
, sec
) != NULL
2463 && xcoff_section_data (sec
->owner
, sec
) != NULL
)
2465 struct xcoff_link_hash_entry
**syms
;
2466 struct internal_reloc
*rel
, *relend
;
2468 unsigned long i
, first
, last
;
2470 /* Mark all the symbols in this section. */
2471 syms
= obj_xcoff_sym_hashes (sec
->owner
);
2472 csects
= xcoff_data (sec
->owner
)->csects
;
2473 first
= xcoff_section_data (sec
->owner
, sec
)->first_symndx
;
2474 last
= xcoff_section_data (sec
->owner
, sec
)->last_symndx
;
2475 for (i
= first
; i
<= last
; i
++)
2476 if (csects
[i
] == sec
2478 && (syms
[i
]->flags
& XCOFF_MARK
) == 0)
2480 if (!xcoff_mark_symbol (info
, syms
[i
]))
2484 /* Look through the section relocs. */
2485 if ((sec
->flags
& SEC_RELOC
) != 0
2486 && sec
->reloc_count
> 0)
2488 rel
= xcoff_read_internal_relocs (sec
->owner
, sec
, TRUE
,
2492 relend
= rel
+ sec
->reloc_count
;
2493 for (; rel
< relend
; rel
++)
2496 struct xcoff_link_hash_entry
*h
;
2498 if ((unsigned int) rel
->r_symndx
2499 > obj_raw_syment_count (sec
->owner
))
2502 h
= obj_xcoff_sym_hashes (sec
->owner
)[rel
->r_symndx
];
2504 && (h
->flags
& XCOFF_MARK
) == 0)
2506 if (! xcoff_mark_symbol (info
, h
))
2510 rsec
= xcoff_data (sec
->owner
)->csects
[rel
->r_symndx
];
2512 && !bfd_is_und_section (rsec
)
2513 && !bfd_is_abs_section (rsec
)
2514 && (rsec
->flags
& SEC_MARK
) == 0)
2516 if (! xcoff_mark (info
, rsec
))
2520 /* See if this reloc needs to be copied into the .loader
2522 switch (rel
->r_type
)
2526 || h
->root
.type
== bfd_link_hash_defined
2527 || h
->root
.type
== bfd_link_hash_defweak
2528 || h
->root
.type
== bfd_link_hash_common
2529 /* We will always provide a local definition of
2530 function symbols. */
2531 || (h
->flags
& XCOFF_CALLED
) != 0)
2539 && (h
->root
.type
== bfd_link_hash_defined
2540 || h
->root
.type
== bfd_link_hash_defweak
)
2541 && bfd_is_abs_section (h
->root
.u
.def
.section
))
2543 ++xcoff_hash_table (info
)->ldrel_count
;
2545 h
->flags
|= XCOFF_LDREL
;
2552 /* We should never need a .loader reloc for a TOC
2558 if (! info
->keep_memory
2559 && coff_section_data (sec
->owner
, sec
) != NULL
2560 && coff_section_data (sec
->owner
, sec
)->relocs
!= NULL
2561 && ! coff_section_data (sec
->owner
, sec
)->keep_relocs
)
2563 free (coff_section_data (sec
->owner
, sec
)->relocs
);
2564 coff_section_data (sec
->owner
, sec
)->relocs
= NULL
;
2572 /* Routines that are called after all the input files have been
2573 handled, but before the sections are laid out in memory. */
2575 /* The sweep phase of garbage collection. Remove all garbage
2579 xcoff_sweep (struct bfd_link_info
*info
)
2583 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2587 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2589 if ((o
->flags
& SEC_MARK
) == 0)
2591 /* Keep all sections from non-XCOFF input files. Keep
2592 special sections. Keep .debug sections for the
2594 if (sub
->xvec
!= info
->output_bfd
->xvec
2595 || o
== xcoff_hash_table (info
)->debug_section
2596 || o
== xcoff_hash_table (info
)->loader_section
2597 || o
== xcoff_hash_table (info
)->linkage_section
2598 || o
== xcoff_hash_table (info
)->descriptor_section
2599 || strcmp (o
->name
, ".debug") == 0)
2600 o
->flags
|= SEC_MARK
;
2605 o
->lineno_count
= 0;
2612 /* Record the number of elements in a set. This is used to output the
2613 correct csect length. */
2616 bfd_xcoff_link_record_set (bfd
*output_bfd
,
2617 struct bfd_link_info
*info
,
2618 struct bfd_link_hash_entry
*harg
,
2621 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2622 struct xcoff_link_size_list
*n
;
2625 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2628 /* This will hardly ever be called. I don't want to burn four bytes
2629 per global symbol, so instead the size is kept on a linked list
2630 attached to the hash table. */
2632 n
= bfd_alloc (output_bfd
, amt
);
2635 n
->next
= xcoff_hash_table (info
)->size_list
;
2638 xcoff_hash_table (info
)->size_list
= n
;
2640 h
->flags
|= XCOFF_HAS_SIZE
;
2645 /* Import a symbol. */
2648 bfd_xcoff_import_symbol (bfd
*output_bfd
,
2649 struct bfd_link_info
*info
,
2650 struct bfd_link_hash_entry
*harg
,
2652 const char *imppath
,
2653 const char *impfile
,
2654 const char *impmember
,
2655 unsigned int syscall_flag
)
2657 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2659 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2662 /* A symbol name which starts with a period is the code for a
2663 function. If the symbol is undefined, then add an undefined
2664 symbol for the function descriptor, and import that instead. */
2665 if (h
->root
.root
.string
[0] == '.'
2666 && h
->root
.type
== bfd_link_hash_undefined
2667 && val
== (bfd_vma
) -1)
2669 struct xcoff_link_hash_entry
*hds
;
2671 hds
= h
->descriptor
;
2674 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
2675 h
->root
.root
.string
+ 1,
2679 if (hds
->root
.type
== bfd_link_hash_new
)
2681 hds
->root
.type
= bfd_link_hash_undefined
;
2682 hds
->root
.u
.undef
.abfd
= h
->root
.u
.undef
.abfd
;
2684 hds
->flags
|= XCOFF_DESCRIPTOR
;
2685 BFD_ASSERT ((h
->flags
& XCOFF_DESCRIPTOR
) == 0);
2686 hds
->descriptor
= h
;
2687 h
->descriptor
= hds
;
2690 /* Now, if the descriptor is undefined, import the descriptor
2691 rather than the symbol we were told to import. FIXME: Is
2692 this correct in all cases? */
2693 if (hds
->root
.type
== bfd_link_hash_undefined
)
2697 h
->flags
|= (XCOFF_IMPORT
| syscall_flag
);
2699 if (val
!= (bfd_vma
) -1)
2701 if (h
->root
.type
== bfd_link_hash_defined
2702 && (! bfd_is_abs_section (h
->root
.u
.def
.section
)
2703 || h
->root
.u
.def
.value
!= val
))
2705 if (! ((*info
->callbacks
->multiple_definition
)
2706 (info
, h
->root
.root
.string
, h
->root
.u
.def
.section
->owner
,
2707 h
->root
.u
.def
.section
, h
->root
.u
.def
.value
,
2708 output_bfd
, bfd_abs_section_ptr
, val
)))
2712 h
->root
.type
= bfd_link_hash_defined
;
2713 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
2714 h
->root
.u
.def
.value
= val
;
2717 if (!xcoff_set_import_path (info
, h
, imppath
, impfile
, impmember
))
2723 /* Export a symbol. */
2726 bfd_xcoff_export_symbol (bfd
*output_bfd
,
2727 struct bfd_link_info
*info
,
2728 struct bfd_link_hash_entry
*harg
)
2730 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2732 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2735 h
->flags
|= XCOFF_EXPORT
;
2737 /* FIXME: I'm not at all sure what syscall is supposed to mean, so
2738 I'm just going to ignore it until somebody explains it. */
2740 /* Make sure we don't garbage collect this symbol. */
2741 if (! xcoff_mark_symbol (info
, h
))
2744 /* If this is a function descriptor, make sure we don't garbage
2745 collect the associated function code. We normally don't have to
2746 worry about this, because the descriptor will be attached to a
2747 section with relocs, but if we are creating the descriptor
2748 ourselves those relocs will not be visible to the mark code. */
2749 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0)
2751 if (! xcoff_mark_symbol (info
, h
->descriptor
))
2758 /* Count a reloc against a symbol. This is called for relocs
2759 generated by the linker script, typically for global constructors
2763 bfd_xcoff_link_count_reloc (bfd
*output_bfd
,
2764 struct bfd_link_info
*info
,
2767 struct xcoff_link_hash_entry
*h
;
2769 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2772 h
= ((struct xcoff_link_hash_entry
*)
2773 bfd_wrapped_link_hash_lookup (output_bfd
, info
, name
, FALSE
, FALSE
,
2777 (*_bfd_error_handler
) (_("%s: no such symbol"), name
);
2778 bfd_set_error (bfd_error_no_symbols
);
2782 h
->flags
|= XCOFF_REF_REGULAR
| XCOFF_LDREL
;
2783 ++xcoff_hash_table (info
)->ldrel_count
;
2785 /* Mark the symbol to avoid garbage collection. */
2786 if (! xcoff_mark_symbol (info
, h
))
2792 /* This function is called for each symbol to which the linker script
2796 bfd_xcoff_record_link_assignment (bfd
*output_bfd
,
2797 struct bfd_link_info
*info
,
2800 struct xcoff_link_hash_entry
*h
;
2802 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2805 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, TRUE
, TRUE
,
2810 h
->flags
|= XCOFF_DEF_REGULAR
;
2815 /* Add a symbol to the .loader symbols, if necessary. */
2818 xcoff_build_ldsyms (struct xcoff_link_hash_entry
*h
, void * p
)
2820 struct xcoff_loader_info
*ldinfo
= (struct xcoff_loader_info
*) p
;
2823 if (h
->root
.type
== bfd_link_hash_warning
)
2824 h
= (struct xcoff_link_hash_entry
*) h
->root
.u
.i
.link
;
2826 /* __rtinit, this symbol has special handling. */
2827 if (h
->flags
& XCOFF_RTINIT
)
2830 /* If this is a final link, and the symbol was defined as a common
2831 symbol in a regular object file, and there was no definition in
2832 any dynamic object, then the linker will have allocated space for
2833 the symbol in a common section but the XCOFF_DEF_REGULAR flag
2834 will not have been set. */
2835 if (h
->root
.type
== bfd_link_hash_defined
2836 && (h
->flags
& XCOFF_DEF_REGULAR
) == 0
2837 && (h
->flags
& XCOFF_REF_REGULAR
) != 0
2838 && (h
->flags
& XCOFF_DEF_DYNAMIC
) == 0
2839 && (bfd_is_abs_section (h
->root
.u
.def
.section
)
2840 || (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0))
2841 h
->flags
|= XCOFF_DEF_REGULAR
;
2843 /* If all defined symbols should be exported, mark them now. We
2844 don't want to export the actual functions, just the function
2846 if (ldinfo
->export_defineds
2847 && (h
->flags
& XCOFF_DEF_REGULAR
) != 0
2848 && h
->root
.root
.string
[0] != '.')
2852 /* We don't export a symbol which is being defined by an object
2853 included from an archive which contains a shared object. The
2854 rationale is that if an archive contains both an unshared and
2855 a shared object, then there must be some reason that the
2856 unshared object is unshared, and we don't want to start
2857 providing a shared version of it. In particular, this solves
2858 a bug involving the _savefNN set of functions. gcc will call
2859 those functions without providing a slot to restore the TOC,
2860 so it is essential that these functions be linked in directly
2861 and not from a shared object, which means that a shared
2862 object which also happens to link them in must not export
2863 them. This is confusing, but I haven't been able to think of
2864 a different approach. Note that the symbols can, of course,
2865 be exported explicitly. */
2867 if ((h
->root
.type
== bfd_link_hash_defined
2868 || h
->root
.type
== bfd_link_hash_defweak
)
2869 && h
->root
.u
.def
.section
->owner
!= NULL
2870 && h
->root
.u
.def
.section
->owner
->my_archive
!= NULL
)
2872 bfd
*arbfd
, *member
;
2874 arbfd
= h
->root
.u
.def
.section
->owner
->my_archive
;
2875 member
= bfd_openr_next_archived_file (arbfd
, NULL
);
2876 while (member
!= NULL
)
2878 if ((member
->flags
& DYNAMIC
) != 0)
2883 member
= bfd_openr_next_archived_file (arbfd
, member
);
2888 h
->flags
|= XCOFF_EXPORT
;
2891 /* We don't want to garbage collect symbols which are not defined in
2892 XCOFF files. This is a convenient place to mark them. */
2893 if (xcoff_hash_table (ldinfo
->info
)->gc
2894 && (h
->flags
& XCOFF_MARK
) == 0
2895 && (h
->root
.type
== bfd_link_hash_defined
2896 || h
->root
.type
== bfd_link_hash_defweak
)
2897 && (h
->root
.u
.def
.section
->owner
== NULL
2898 || (h
->root
.u
.def
.section
->owner
->xvec
2899 != ldinfo
->info
->output_bfd
->xvec
)))
2900 h
->flags
|= XCOFF_MARK
;
2902 /* If this symbol is exported, but not defined, we need to try to
2904 if ((h
->flags
& XCOFF_EXPORT
) != 0
2905 && (h
->flags
& XCOFF_WAS_UNDEFINED
) != 0)
2907 (*_bfd_error_handler
)
2908 (_("warning: attempt to export undefined symbol `%s'"),
2909 h
->root
.root
.string
);
2914 /* If this is still a common symbol, and it wasn't garbage
2915 collected, we need to actually allocate space for it in the .bss
2917 if (h
->root
.type
== bfd_link_hash_common
2918 && (! xcoff_hash_table (ldinfo
->info
)->gc
2919 || (h
->flags
& XCOFF_MARK
) != 0)
2920 && h
->root
.u
.c
.p
->section
->size
== 0)
2922 BFD_ASSERT (bfd_is_com_section (h
->root
.u
.c
.p
->section
));
2923 h
->root
.u
.c
.p
->section
->size
= h
->root
.u
.c
.size
;
2926 /* We need to add a symbol to the .loader section if it is mentioned
2927 in a reloc which we are copying to the .loader section and it was
2928 not defined or common, or if it is the entry point, or if it is
2931 if (((h
->flags
& XCOFF_LDREL
) == 0
2932 || h
->root
.type
== bfd_link_hash_defined
2933 || h
->root
.type
== bfd_link_hash_defweak
2934 || h
->root
.type
== bfd_link_hash_common
)
2935 && (h
->flags
& XCOFF_ENTRY
) == 0
2936 && (h
->flags
& XCOFF_EXPORT
) == 0)
2942 /* We don't need to add this symbol if we did garbage collection and
2943 we did not mark this symbol. */
2944 if (xcoff_hash_table (ldinfo
->info
)->gc
2945 && (h
->flags
& XCOFF_MARK
) == 0)
2951 /* We may have already processed this symbol due to the recursive
2953 if ((h
->flags
& XCOFF_BUILT_LDSYM
) != 0)
2956 /* We need to add this symbol to the .loader symbols. */
2958 BFD_ASSERT (h
->ldsym
== NULL
);
2959 amt
= sizeof (struct internal_ldsym
);
2960 h
->ldsym
= bfd_zalloc (ldinfo
->output_bfd
, amt
);
2961 if (h
->ldsym
== NULL
)
2963 ldinfo
->failed
= TRUE
;
2967 if ((h
->flags
& XCOFF_IMPORT
) != 0)
2968 h
->ldsym
->l_ifile
= h
->ldindx
;
2970 /* The first 3 symbol table indices are reserved to indicate the
2971 data, text and bss sections. */
2972 h
->ldindx
= ldinfo
->ldsym_count
+ 3;
2974 ++ldinfo
->ldsym_count
;
2976 if (! bfd_xcoff_put_ldsymbol_name (ldinfo
->output_bfd
, ldinfo
,
2977 h
->ldsym
, h
->root
.root
.string
))
2980 h
->flags
|= XCOFF_BUILT_LDSYM
;
2985 /* INPUT_BFD includes XCOFF symbol ISYM, which is associated with linker
2986 hash table entry H and csect CSECT. AUX contains ISYM's auxillary
2987 csect information, if any. NAME is the function's name if the name
2988 is stored in the .debug section, otherwise it is null.
2990 Return 1 if we should include an appropriately-adjusted ISYM
2991 in the output file, 0 if we should discard ISYM, or -1 if an
2995 xcoff_keep_symbol_p (struct bfd_link_info
*info
, bfd
*input_bfd
,
2996 struct internal_syment
*isym
,
2997 union internal_auxent
*aux
,
2998 struct xcoff_link_hash_entry
*h
,
2999 asection
*csect
, const char *name
)
3003 /* If we are skipping this csect, we want to strip the symbol too. */
3007 /* Likewise if we garbage-collected the csect. */
3008 if (xcoff_hash_table (info
)->gc
3009 && !bfd_is_abs_section (csect
)
3010 && !bfd_is_und_section (csect
)
3011 && (csect
->flags
& SEC_MARK
) == 0)
3014 /* An XCOFF linker always removes C_STAT symbols. */
3015 if (isym
->n_sclass
== C_STAT
)
3018 /* We generate the TOC anchor separately. */
3019 if (isym
->n_sclass
== C_HIDEXT
3020 && aux
->x_csect
.x_smclas
== XMC_TC0
)
3023 /* If we are stripping all symbols, we want to discard this one. */
3024 if (info
->strip
== strip_all
)
3027 /* We can ignore external references that were resolved by the link. */
3028 smtyp
= SMTYP_SMTYP (aux
->x_csect
.x_smtyp
);
3029 if (isym
->n_sclass
== C_EXT
3031 && h
->root
.type
!= bfd_link_hash_undefined
)
3034 /* We can ignore common symbols if they got defined somewhere else. */
3035 if (isym
->n_sclass
== C_EXT
3037 && (h
->root
.type
!= bfd_link_hash_common
3038 || h
->root
.u
.c
.p
->section
!= csect
)
3039 && (h
->root
.type
!= bfd_link_hash_defined
3040 || h
->root
.u
.def
.section
!= csect
))
3043 /* If we're discarding local symbols, check whether ISYM is local. */
3044 if (info
->discard
== discard_all
3045 && isym
->n_sclass
!= C_EXT
3046 && (isym
->n_sclass
!= C_HIDEXT
|| smtyp
!= XTY_SD
))
3049 /* If we're stripping debugging symbols, check whether ISYM is one. */
3050 if (info
->strip
== strip_debugger
3051 && isym
->n_scnum
== N_DEBUG
)
3054 /* If we are stripping symbols based on name, check how ISYM's
3055 name should be handled. */
3056 if (info
->strip
== strip_some
3057 || info
->discard
== discard_l
)
3059 char buf
[SYMNMLEN
+ 1];
3063 name
= _bfd_coff_internal_syment_name (input_bfd
, isym
, buf
);
3068 if (info
->strip
== strip_some
3069 && bfd_hash_lookup (info
->keep_hash
, name
, FALSE
, FALSE
) == NULL
)
3072 if (info
->discard
== discard_l
3073 && isym
->n_sclass
!= C_EXT
3074 && (isym
->n_sclass
!= C_HIDEXT
|| smtyp
!= XTY_SD
)
3075 && bfd_is_local_label_name (input_bfd
, name
))
3082 /* Build the .loader section. This is called by the XCOFF linker
3083 emulation before_allocation routine. We must set the size of the
3084 .loader section before the linker lays out the output file.
3085 LIBPATH is the library path to search for shared objects; this is
3086 normally built from the -L arguments passed to the linker. ENTRY
3087 is the name of the entry point symbol (the -e linker option).
3088 FILE_ALIGN is the alignment to use for sections within the file
3089 (the -H linker option). MAXSTACK is the maximum stack size (the
3090 -bmaxstack linker option). MAXDATA is the maximum data size (the
3091 -bmaxdata linker option). GC is whether to do garbage collection
3092 (the -bgc linker option). MODTYPE is the module type (the
3093 -bmodtype linker option). TEXTRO is whether the text section must
3094 be read only (the -btextro linker option). EXPORT_DEFINEDS is
3095 whether all defined symbols should be exported (the -unix linker
3096 option). SPECIAL_SECTIONS is set by this routine to csects with
3097 magic names like _end. */
3100 bfd_xcoff_size_dynamic_sections (bfd
*output_bfd
,
3101 struct bfd_link_info
*info
,
3102 const char *libpath
,
3104 unsigned long file_align
,
3105 unsigned long maxstack
,
3106 unsigned long maxdata
,
3110 bfd_boolean export_defineds
,
3111 asection
**special_sections
,
3114 struct xcoff_link_hash_entry
*hentry
;
3116 struct xcoff_loader_info ldinfo
;
3118 size_t impsize
, impcount
;
3119 struct xcoff_import_file
*fl
;
3120 struct internal_ldhdr
*ldhdr
;
3121 bfd_size_type stoff
;
3125 struct bfd_strtab_hash
*debug_strtab
;
3126 bfd_byte
*debug_contents
= NULL
;
3129 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
3131 for (i
= 0; i
< XCOFF_NUMBER_OF_SPECIAL_SECTIONS
; i
++)
3132 special_sections
[i
] = NULL
;
3136 ldinfo
.failed
= FALSE
;
3137 ldinfo
.output_bfd
= output_bfd
;
3139 ldinfo
.export_defineds
= export_defineds
;
3140 ldinfo
.ldsym_count
= 0;
3141 ldinfo
.string_size
= 0;
3142 ldinfo
.strings
= NULL
;
3143 ldinfo
.string_alc
= 0;
3145 xcoff_data (output_bfd
)->maxstack
= maxstack
;
3146 xcoff_data (output_bfd
)->maxdata
= maxdata
;
3147 xcoff_data (output_bfd
)->modtype
= modtype
;
3149 xcoff_hash_table (info
)->file_align
= file_align
;
3150 xcoff_hash_table (info
)->textro
= textro
;
3151 xcoff_hash_table (info
)->rtld
= rtld
;
3156 hentry
= xcoff_link_hash_lookup (xcoff_hash_table (info
), entry
,
3157 FALSE
, FALSE
, TRUE
);
3159 hentry
->flags
|= XCOFF_ENTRY
;
3163 if (info
->init_function
|| info
->fini_function
|| rtld
)
3165 struct xcoff_link_hash_entry
*hsym
;
3166 struct internal_ldsym
*ldsym
;
3168 hsym
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
3169 "__rtinit", FALSE
, FALSE
, TRUE
);
3172 (*_bfd_error_handler
)
3173 (_("error: undefined symbol __rtinit"));
3177 xcoff_mark_symbol (info
, hsym
);
3178 hsym
->flags
|= (XCOFF_DEF_REGULAR
| XCOFF_RTINIT
);
3180 /* __rtinit initialized. */
3181 amt
= sizeof (* ldsym
);
3182 ldsym
= bfd_malloc (amt
);
3184 ldsym
->l_value
= 0; /* Will be filled in later. */
3185 ldsym
->l_scnum
= 2; /* Data section. */
3186 ldsym
->l_smtype
= XTY_SD
; /* Csect section definition. */
3187 ldsym
->l_smclas
= 5; /* .rw. */
3188 ldsym
->l_ifile
= 0; /* Special system loader symbol. */
3189 ldsym
->l_parm
= 0; /* NA. */
3191 /* Force __rtinit to be the first symbol in the loader symbol table
3192 See xcoff_build_ldsyms
3194 The first 3 symbol table indices are reserved to indicate the data,
3195 text and bss sections. */
3196 BFD_ASSERT (0 == ldinfo
.ldsym_count
);
3199 ldinfo
.ldsym_count
= 1;
3200 hsym
->ldsym
= ldsym
;
3202 if (! bfd_xcoff_put_ldsymbol_name (ldinfo
.output_bfd
, &ldinfo
,
3203 hsym
->ldsym
, hsym
->root
.root
.string
))
3206 /* This symbol is written out by xcoff_write_global_symbol
3207 Set stuff up so xcoff_write_global_symbol logic works. */
3208 hsym
->flags
|= XCOFF_DEF_REGULAR
| XCOFF_MARK
;
3209 hsym
->root
.type
= bfd_link_hash_defined
;
3210 hsym
->root
.u
.def
.value
= 0;
3213 /* Garbage collect unused sections. */
3214 if (info
->relocatable
3217 || (hentry
->root
.type
!= bfd_link_hash_defined
3218 && hentry
->root
.type
!= bfd_link_hash_defweak
))
3221 xcoff_hash_table (info
)->gc
= FALSE
;
3223 /* We still need to call xcoff_mark, in order to set ldrel_count
3225 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3229 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
3231 /* We shouldn't unconditionaly mark the TOC section.
3232 The output file should only have a TOC if either
3233 (a) one of the input files did or (b) we end up
3234 creating TOC references as part of the link process. */
3235 if (o
!= xcoff_hash_table (info
)->toc_section
3236 && (o
->flags
& SEC_MARK
) == 0)
3238 if (! xcoff_mark (info
, o
))
3246 if (! xcoff_mark (info
, hentry
->root
.u
.def
.section
))
3249 xcoff_hash_table (info
)->gc
= TRUE
;
3252 /* Return special sections to the caller. */
3253 for (i
= 0; i
< XCOFF_NUMBER_OF_SPECIAL_SECTIONS
; i
++)
3255 sec
= xcoff_hash_table (info
)->special_sections
[i
];
3259 && (sec
->flags
& SEC_MARK
) == 0)
3262 special_sections
[i
] = sec
;
3265 if (info
->input_bfds
== NULL
)
3266 /* I'm not sure what to do in this bizarre case. */
3269 xcoff_link_hash_traverse (xcoff_hash_table (info
), xcoff_build_ldsyms
,
3274 /* Work out the size of the import file names. Each import file ID
3275 consists of three null terminated strings: the path, the file
3276 name, and the archive member name. The first entry in the list
3277 of names is the path to use to find objects, which the linker has
3278 passed in as the libpath argument. For some reason, the path
3279 entry in the other import file names appears to always be empty. */
3280 impsize
= strlen (libpath
) + 3;
3282 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
3285 impsize
+= (strlen (fl
->path
)
3287 + strlen (fl
->member
)
3291 /* Set up the .loader section header. */
3292 ldhdr
= &xcoff_hash_table (info
)->ldhdr
;
3293 ldhdr
->l_version
= bfd_xcoff_ldhdr_version(output_bfd
);
3294 ldhdr
->l_nsyms
= ldinfo
.ldsym_count
;
3295 ldhdr
->l_nreloc
= xcoff_hash_table (info
)->ldrel_count
;
3296 ldhdr
->l_istlen
= impsize
;
3297 ldhdr
->l_nimpid
= impcount
;
3298 ldhdr
->l_impoff
= (bfd_xcoff_ldhdrsz(output_bfd
)
3299 + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(output_bfd
)
3300 + ldhdr
->l_nreloc
* bfd_xcoff_ldrelsz(output_bfd
));
3301 ldhdr
->l_stlen
= ldinfo
.string_size
;
3302 stoff
= ldhdr
->l_impoff
+ impsize
;
3303 if (ldinfo
.string_size
== 0)
3306 ldhdr
->l_stoff
= stoff
;
3308 /* 64 bit elements to ldhdr
3309 The swap out routine for 32 bit will ignore them.
3310 Nothing fancy, symbols come after the header and relocs come
3312 ldhdr
->l_symoff
= bfd_xcoff_ldhdrsz (output_bfd
);
3313 ldhdr
->l_rldoff
= (bfd_xcoff_ldhdrsz (output_bfd
)
3314 + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (output_bfd
));
3316 /* We now know the final size of the .loader section. Allocate
3318 lsec
= xcoff_hash_table (info
)->loader_section
;
3319 lsec
->size
= stoff
+ ldhdr
->l_stlen
;
3320 lsec
->contents
= bfd_zalloc (output_bfd
, lsec
->size
);
3321 if (lsec
->contents
== NULL
)
3324 /* Set up the header. */
3325 bfd_xcoff_swap_ldhdr_out (output_bfd
, ldhdr
, lsec
->contents
);
3327 /* Set up the import file names. */
3328 out
= (char *) lsec
->contents
+ ldhdr
->l_impoff
;
3329 strcpy (out
, libpath
);
3330 out
+= strlen (libpath
) + 1;
3333 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
3338 while ((*out
++ = *s
++) != '\0')
3341 while ((*out
++ = *s
++) != '\0')
3344 while ((*out
++ = *s
++) != '\0')
3348 BFD_ASSERT ((bfd_size_type
) ((bfd_byte
*) out
- lsec
->contents
) == stoff
);
3350 /* Set up the symbol string table. */
3351 if (ldinfo
.string_size
> 0)
3353 memcpy (out
, ldinfo
.strings
, ldinfo
.string_size
);
3354 free (ldinfo
.strings
);
3355 ldinfo
.strings
= NULL
;
3358 /* We can't set up the symbol table or the relocs yet, because we
3359 don't yet know the final position of the various sections. The
3360 .loader symbols are written out when the corresponding normal
3361 symbols are written out in xcoff_link_input_bfd or
3362 xcoff_write_global_symbol. The .loader relocs are written out
3363 when the corresponding normal relocs are handled in
3364 xcoff_link_input_bfd. */
3366 /* Allocate space for the magic sections. */
3367 sec
= xcoff_hash_table (info
)->linkage_section
;
3370 sec
->contents
= bfd_zalloc (output_bfd
, sec
->size
);
3371 if (sec
->contents
== NULL
)
3374 sec
= xcoff_hash_table (info
)->toc_section
;
3377 sec
->contents
= bfd_zalloc (output_bfd
, sec
->size
);
3378 if (sec
->contents
== NULL
)
3381 sec
= xcoff_hash_table (info
)->descriptor_section
;
3384 sec
->contents
= bfd_zalloc (output_bfd
, sec
->size
);
3385 if (sec
->contents
== NULL
)
3389 /* Now that we've done garbage collection, decide which symbols to keep,
3390 and figure out the contents of the .debug section. */
3391 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
3393 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3396 bfd_size_type symcount
;
3399 struct xcoff_link_hash_entry
**sym_hash
;
3400 bfd_byte
*esym
, *esymend
;
3401 bfd_size_type symesz
;
3403 if (sub
->xvec
!= info
->output_bfd
->xvec
)
3406 if ((sub
->flags
& DYNAMIC
) != 0
3407 && !info
->static_link
)
3410 if (! _bfd_coff_get_external_symbols (sub
))
3413 symcount
= obj_raw_syment_count (sub
);
3414 debug_index
= bfd_zalloc (sub
, symcount
* sizeof (long));
3415 if (debug_index
== NULL
)
3417 xcoff_data (sub
)->debug_indices
= debug_index
;
3419 if (info
->strip
== strip_all
3420 || info
->strip
== strip_debugger
3421 || info
->discard
== discard_all
)
3422 /* We're stripping all debugging information, so there's no need
3423 to read SUB's .debug section. */
3427 /* Grab the contents of SUB's .debug section, if any. */
3428 subdeb
= bfd_get_section_by_name (sub
, ".debug");
3429 if (subdeb
!= NULL
&& subdeb
->size
> 0)
3431 /* We use malloc and copy the names into the debug
3432 stringtab, rather than bfd_alloc, because I expect
3433 that, when linking many files together, many of the
3434 strings will be the same. Storing the strings in the
3435 hash table should save space in this case. */
3436 if (!bfd_malloc_and_get_section (sub
, subdeb
, &debug_contents
))
3441 csectpp
= xcoff_data (sub
)->csects
;
3442 sym_hash
= obj_xcoff_sym_hashes (sub
);
3443 symesz
= bfd_coff_symesz (sub
);
3444 esym
= (bfd_byte
*) obj_coff_external_syms (sub
);
3445 esymend
= esym
+ symcount
* symesz
;
3447 while (esym
< esymend
)
3449 struct internal_syment sym
;
3450 union internal_auxent aux
;
3454 bfd_coff_swap_sym_in (sub
, esym
, &sym
);
3456 /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
3458 if (sym
.n_sclass
== C_EXT
|| sym
.n_sclass
== C_HIDEXT
)
3460 BFD_ASSERT (sym
.n_numaux
> 0);
3461 bfd_coff_swap_aux_in (sub
, esym
+ symesz
* sym
.n_numaux
,
3462 sym
.n_type
, sym
.n_sclass
,
3463 sym
.n_numaux
- 1, sym
.n_numaux
, &aux
);
3466 /* If this symbol's name is stored in the debug section,
3467 get a pointer to it. */
3468 if (debug_contents
!= NULL
3469 && sym
._n
._n_n
._n_zeroes
== 0
3470 && bfd_coff_symname_in_debug (sub
, &sym
))
3471 name
= (const char *) debug_contents
+ sym
._n
._n_n
._n_offset
;
3475 /* Decide whether to copy this symbol to the output file. */
3476 keep_p
= xcoff_keep_symbol_p (info
, sub
, &sym
, &aux
,
3477 *sym_hash
, *csectpp
, name
);
3482 /* Use a debug_index of -2 to record that a symbol should
3487 /* See whether we should store the symbol name in the
3488 output .debug section. */
3493 indx
= _bfd_stringtab_add (debug_strtab
, name
, TRUE
, TRUE
);
3494 if (indx
== (bfd_size_type
) -1)
3496 *debug_index
= indx
;
3502 esym
+= (sym
.n_numaux
+ 1) * symesz
;
3503 csectpp
+= sym
.n_numaux
+ 1;
3504 sym_hash
+= sym
.n_numaux
+ 1;
3505 debug_index
+= sym
.n_numaux
+ 1;
3510 free (debug_contents
);
3511 debug_contents
= NULL
;
3513 /* Clear the size of subdeb, so that it is not included directly
3514 in the output file. */
3518 if (! info
->keep_memory
)
3520 if (! _bfd_coff_free_symbols (sub
))
3525 if (info
->strip
!= strip_all
)
3526 xcoff_hash_table (info
)->debug_section
->size
=
3527 _bfd_stringtab_size (debug_strtab
);
3532 if (ldinfo
.strings
!= NULL
)
3533 free (ldinfo
.strings
);
3534 if (debug_contents
!= NULL
)
3535 free (debug_contents
);
3540 bfd_xcoff_link_generate_rtinit (bfd
*abfd
,
3545 struct bfd_in_memory
*bim
;
3547 bim
= bfd_malloc ((bfd_size_type
) sizeof (* bim
));
3554 abfd
->link_next
= 0;
3555 abfd
->format
= bfd_object
;
3556 abfd
->iostream
= (void *) bim
;
3557 abfd
->flags
= BFD_IN_MEMORY
;
3558 abfd
->direction
= write_direction
;
3561 if (! bfd_xcoff_generate_rtinit (abfd
, init
, fini
, rtld
))
3564 /* need to reset to unknown or it will not be read back in correctly */
3565 abfd
->format
= bfd_unknown
;
3566 abfd
->direction
= read_direction
;
3572 /* Link an input file into the linker output file. This function
3573 handles all the sections and relocations of the input file at once. */
3576 xcoff_link_input_bfd (struct xcoff_final_link_info
*finfo
,
3580 const char *strings
;
3581 bfd_size_type syment_base
;
3582 unsigned int n_tmask
;
3583 unsigned int n_btshft
;
3584 bfd_boolean copy
, hash
;
3585 bfd_size_type isymesz
;
3586 bfd_size_type osymesz
;
3587 bfd_size_type linesz
;
3590 struct xcoff_link_hash_entry
**sym_hash
;
3591 struct internal_syment
*isymp
;
3595 unsigned long output_index
;
3599 bfd_boolean keep_syms
;
3602 /* We can just skip DYNAMIC files, unless this is a static link. */
3603 if ((input_bfd
->flags
& DYNAMIC
) != 0
3604 && ! finfo
->info
->static_link
)
3607 /* Move all the symbols to the output file. */
3608 output_bfd
= finfo
->output_bfd
;
3610 syment_base
= obj_raw_syment_count (output_bfd
);
3611 isymesz
= bfd_coff_symesz (input_bfd
);
3612 osymesz
= bfd_coff_symesz (output_bfd
);
3613 linesz
= bfd_coff_linesz (input_bfd
);
3614 BFD_ASSERT (linesz
== bfd_coff_linesz (output_bfd
));
3616 n_tmask
= coff_data (input_bfd
)->local_n_tmask
;
3617 n_btshft
= coff_data (input_bfd
)->local_n_btshft
;
3619 /* Define macros so that ISFCN, et. al., macros work correctly. */
3620 #define N_TMASK n_tmask
3621 #define N_BTSHFT n_btshft
3624 if (! finfo
->info
->keep_memory
)
3627 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3630 if (! _bfd_coff_get_external_symbols (input_bfd
))
3633 /* Make one pass over the symbols and assign indices to symbols that
3634 we have decided to keep. Also use create .loader symbol information
3635 and update information in hash table entries. */
3636 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
3637 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
3638 sym_hash
= obj_xcoff_sym_hashes (input_bfd
);
3639 csectpp
= xcoff_data (input_bfd
)->csects
;
3640 debug_index
= xcoff_data (input_bfd
)->debug_indices
;
3641 isymp
= finfo
->internal_syms
;
3642 indexp
= finfo
->sym_indices
;
3643 output_index
= syment_base
;
3644 while (esym
< esym_end
)
3646 union internal_auxent aux
;
3650 bfd_coff_swap_sym_in (input_bfd
, (void *) esym
, (void *) isymp
);
3652 /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
3654 if (isymp
->n_sclass
== C_EXT
|| isymp
->n_sclass
== C_HIDEXT
)
3656 BFD_ASSERT (isymp
->n_numaux
> 0);
3657 bfd_coff_swap_aux_in (input_bfd
,
3658 (void *) (esym
+ isymesz
* isymp
->n_numaux
),
3659 isymp
->n_type
, isymp
->n_sclass
,
3660 isymp
->n_numaux
- 1, isymp
->n_numaux
,
3663 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
3666 /* If this symbol is in the .loader section, swap out the
3667 .loader symbol information. If this is an external symbol
3668 reference to a defined symbol, though, then wait until we get
3669 to the definition. */
3670 if (isymp
->n_sclass
== C_EXT
3671 && *sym_hash
!= NULL
3672 && (*sym_hash
)->ldsym
!= NULL
3674 || (*sym_hash
)->root
.type
== bfd_link_hash_undefined
))
3676 struct xcoff_link_hash_entry
*h
;
3677 struct internal_ldsym
*ldsym
;
3681 if (isymp
->n_scnum
> 0)
3683 ldsym
->l_scnum
= (*csectpp
)->output_section
->target_index
;
3684 ldsym
->l_value
= (isymp
->n_value
3685 + (*csectpp
)->output_section
->vma
3686 + (*csectpp
)->output_offset
3691 ldsym
->l_scnum
= isymp
->n_scnum
;
3692 ldsym
->l_value
= isymp
->n_value
;
3695 ldsym
->l_smtype
= smtyp
;
3696 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
3697 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3698 || (h
->flags
& XCOFF_IMPORT
) != 0)
3699 ldsym
->l_smtype
|= L_IMPORT
;
3700 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
3701 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3702 || (h
->flags
& XCOFF_EXPORT
) != 0)
3703 ldsym
->l_smtype
|= L_EXPORT
;
3704 if ((h
->flags
& XCOFF_ENTRY
) != 0)
3705 ldsym
->l_smtype
|= L_ENTRY
;
3707 ldsym
->l_smclas
= aux
.x_csect
.x_smclas
;
3709 if (ldsym
->l_ifile
== (bfd_size_type
) -1)
3711 else if (ldsym
->l_ifile
== 0)
3713 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
3719 if (h
->root
.type
== bfd_link_hash_defined
3720 || h
->root
.type
== bfd_link_hash_defweak
)
3721 impbfd
= h
->root
.u
.def
.section
->owner
;
3722 else if (h
->root
.type
== bfd_link_hash_undefined
3723 || h
->root
.type
== bfd_link_hash_undefweak
)
3724 impbfd
= h
->root
.u
.undef
.abfd
;
3732 BFD_ASSERT (impbfd
->xvec
== finfo
->output_bfd
->xvec
);
3733 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
3740 BFD_ASSERT (h
->ldindx
>= 0);
3741 bfd_xcoff_swap_ldsym_out (finfo
->output_bfd
, ldsym
,
3744 * bfd_xcoff_ldsymsz (finfo
->output_bfd
))));
3747 /* Fill in snentry now that we know the target_index. */
3748 if ((h
->flags
& XCOFF_ENTRY
) != 0
3749 && (h
->root
.type
== bfd_link_hash_defined
3750 || h
->root
.type
== bfd_link_hash_defweak
))
3752 xcoff_data (output_bfd
)->snentry
=
3753 h
->root
.u
.def
.section
->output_section
->target_index
;
3757 add
= 1 + isymp
->n_numaux
;
3759 if (*debug_index
== -2)
3760 /* We've decided to strip this symbol. */
3764 /* Assign the next unused index to this symbol. */
3765 *indexp
= output_index
;
3767 if (isymp
->n_sclass
== C_EXT
)
3769 BFD_ASSERT (*sym_hash
!= NULL
);
3770 (*sym_hash
)->indx
= output_index
;
3773 /* If this is a symbol in the TOC which we may have merged
3774 (class XMC_TC), remember the symbol index of the TOC
3776 if (isymp
->n_sclass
== C_HIDEXT
3777 && aux
.x_csect
.x_smclas
== XMC_TC
3778 && *sym_hash
!= NULL
)
3780 BFD_ASSERT (((*sym_hash
)->flags
& XCOFF_SET_TOC
) == 0);
3781 BFD_ASSERT ((*sym_hash
)->toc_section
!= NULL
);
3782 (*sym_hash
)->u
.toc_indx
= output_index
;
3785 output_index
+= add
;
3788 esym
+= add
* isymesz
;
3794 for (--add
; add
> 0; --add
)
3798 /* Now write out the symbols that we decided to keep. */
3800 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
3801 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
3802 isymp
= finfo
->internal_syms
;
3803 indexp
= finfo
->sym_indices
;
3804 csectpp
= xcoff_data (input_bfd
)->csects
;
3805 debug_index
= xcoff_data (input_bfd
)->debug_indices
;
3806 outsym
= finfo
->outsyms
;
3809 while (esym
< esym_end
)
3813 add
= 1 + isymp
->n_numaux
;
3816 esym
+= add
* isymesz
;
3819 struct internal_syment isym
;
3822 /* Adjust the symbol in order to output it. */
3824 if (isym
._n
._n_n
._n_zeroes
== 0
3825 && isym
._n
._n_n
._n_offset
!= 0)
3827 /* This symbol has a long name. Enter it in the string
3828 table we are building. If *debug_index != -1, the
3829 name has already been entered in the .debug section. */
3830 if (*debug_index
>= 0)
3831 isym
._n
._n_n
._n_offset
= *debug_index
;
3837 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
, NULL
);
3841 indx
= _bfd_stringtab_add (finfo
->strtab
, name
, hash
, copy
);
3842 if (indx
== (bfd_size_type
) -1)
3844 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3848 /* The value of a C_FILE symbol is the symbol index of the
3849 next C_FILE symbol. The value of the last C_FILE symbol
3850 is -1. We try to get this right, below, just before we
3851 write the symbols out, but in the general case we may
3852 have to write the symbol out twice. */
3853 if (isym
.n_sclass
== C_FILE
)
3855 if (finfo
->last_file_index
!= -1
3856 && finfo
->last_file
.n_value
!= (bfd_vma
) *indexp
)
3858 /* We must correct the value of the last C_FILE entry. */
3859 finfo
->last_file
.n_value
= *indexp
;
3860 if ((bfd_size_type
) finfo
->last_file_index
>= syment_base
)
3862 /* The last C_FILE symbol is in this input file. */
3863 bfd_coff_swap_sym_out (output_bfd
,
3864 (void *) &finfo
->last_file
,
3865 (void *) (finfo
->outsyms
3866 + ((finfo
->last_file_index
3872 /* We have already written out the last C_FILE
3873 symbol. We need to write it out again. We
3874 borrow *outsym temporarily. */
3877 bfd_coff_swap_sym_out (output_bfd
,
3878 (void *) &finfo
->last_file
,
3881 pos
= obj_sym_filepos (output_bfd
);
3882 pos
+= finfo
->last_file_index
* osymesz
;
3883 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
3884 || (bfd_bwrite (outsym
, osymesz
, output_bfd
)
3890 finfo
->last_file_index
= *indexp
;
3891 finfo
->last_file
= isym
;
3894 /* The value of a C_BINCL or C_EINCL symbol is a file offset
3895 into the line numbers. We update the symbol values when
3896 we handle the line numbers. */
3897 if (isym
.n_sclass
== C_BINCL
3898 || isym
.n_sclass
== C_EINCL
)
3900 isym
.n_value
= finfo
->line_filepos
;
3903 /* The value of a C_BSTAT symbol is the symbol table
3904 index of the containing csect. */
3905 else if (isym
.n_sclass
== C_BSTAT
)
3909 indx
= isym
.n_value
;
3910 if (indx
< obj_raw_syment_count (input_bfd
))
3914 symindx
= finfo
->sym_indices
[indx
];
3918 isym
.n_value
= symindx
;
3921 else if (isym
.n_sclass
!= C_ESTAT
3922 && isym
.n_sclass
!= C_DECL
3923 && isym
.n_scnum
> 0)
3925 isym
.n_scnum
= (*csectpp
)->output_section
->target_index
;
3926 isym
.n_value
+= ((*csectpp
)->output_section
->vma
3927 + (*csectpp
)->output_offset
3931 /* Output the symbol. */
3932 bfd_coff_swap_sym_out (output_bfd
, (void *) &isym
, (void *) outsym
);
3937 for (i
= 0; i
< isymp
->n_numaux
&& esym
< esym_end
; i
++)
3939 union internal_auxent aux
;
3941 bfd_coff_swap_aux_in (input_bfd
, (void *) esym
, isymp
->n_type
,
3942 isymp
->n_sclass
, i
, isymp
->n_numaux
,
3945 if (isymp
->n_sclass
== C_FILE
)
3947 /* This is the file name (or some comment put in by
3948 the compiler). If it is long, we must put it in
3949 the string table. */
3950 if (aux
.x_file
.x_n
.x_zeroes
== 0
3951 && aux
.x_file
.x_n
.x_offset
!= 0)
3953 const char *filename
;
3956 BFD_ASSERT (aux
.x_file
.x_n
.x_offset
3957 >= STRING_SIZE_SIZE
);
3958 if (strings
== NULL
)
3960 strings
= _bfd_coff_read_string_table (input_bfd
);
3961 if (strings
== NULL
)
3964 filename
= strings
+ aux
.x_file
.x_n
.x_offset
;
3965 indx
= _bfd_stringtab_add (finfo
->strtab
, filename
,
3967 if (indx
== (bfd_size_type
) -1)
3969 aux
.x_file
.x_n
.x_offset
= STRING_SIZE_SIZE
+ indx
;
3972 else if ((isymp
->n_sclass
== C_EXT
3973 || isymp
->n_sclass
== C_HIDEXT
)
3974 && i
+ 1 == isymp
->n_numaux
)
3977 /* We don't support type checking. I don't know if
3979 aux
.x_csect
.x_parmhash
= 0;
3980 /* I don't think anybody uses these fields, but we'd
3981 better clobber them just in case. */
3982 aux
.x_csect
.x_stab
= 0;
3983 aux
.x_csect
.x_snstab
= 0;
3985 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_LD
)
3989 indx
= aux
.x_csect
.x_scnlen
.l
;
3990 if (indx
< obj_raw_syment_count (input_bfd
))
3994 symindx
= finfo
->sym_indices
[indx
];
3997 aux
.x_csect
.x_scnlen
.l
= 0;
4001 aux
.x_csect
.x_scnlen
.l
= symindx
;
4006 else if (isymp
->n_sclass
!= C_STAT
|| isymp
->n_type
!= T_NULL
)
4010 if (ISFCN (isymp
->n_type
)
4011 || ISTAG (isymp
->n_sclass
)
4012 || isymp
->n_sclass
== C_BLOCK
4013 || isymp
->n_sclass
== C_FCN
)
4015 indx
= aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
4017 && indx
< obj_raw_syment_count (input_bfd
))
4019 /* We look forward through the symbol for
4020 the index of the next symbol we are going
4021 to include. I don't know if this is
4023 while (finfo
->sym_indices
[indx
] < 0
4024 && indx
< obj_raw_syment_count (input_bfd
))
4026 if (indx
>= obj_raw_syment_count (input_bfd
))
4027 indx
= output_index
;
4029 indx
= finfo
->sym_indices
[indx
];
4030 aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= indx
;
4035 indx
= aux
.x_sym
.x_tagndx
.l
;
4036 if (indx
> 0 && indx
< obj_raw_syment_count (input_bfd
))
4040 symindx
= finfo
->sym_indices
[indx
];
4042 aux
.x_sym
.x_tagndx
.l
= 0;
4044 aux
.x_sym
.x_tagndx
.l
= symindx
;
4049 /* Copy over the line numbers, unless we are stripping
4050 them. We do this on a symbol by symbol basis in
4051 order to more easily handle garbage collection. */
4052 if ((isymp
->n_sclass
== C_EXT
4053 || isymp
->n_sclass
== C_HIDEXT
)
4055 && isymp
->n_numaux
> 1
4056 && ISFCN (isymp
->n_type
)
4057 && aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
4059 if (finfo
->info
->strip
!= strip_none
4060 && finfo
->info
->strip
!= strip_some
)
4061 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4064 asection
*enclosing
;
4065 unsigned int enc_count
;
4066 bfd_signed_vma linoff
;
4067 struct internal_lineno lin
;
4070 enclosing
= xcoff_section_data (abfd
, o
)->enclosing
;
4071 enc_count
= xcoff_section_data (abfd
, o
)->lineno_count
;
4072 if (oline
!= enclosing
)
4074 file_ptr pos
= enclosing
->line_filepos
;
4075 bfd_size_type amt
= linesz
* enc_count
;
4076 if (bfd_seek (input_bfd
, pos
, SEEK_SET
) != 0
4077 || (bfd_bread (finfo
->linenos
, amt
, input_bfd
)
4083 linoff
= (aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
4084 - enclosing
->line_filepos
);
4086 bfd_coff_swap_lineno_in (input_bfd
,
4087 (void *) (finfo
->linenos
+ linoff
),
4090 || ((bfd_size_type
) lin
.l_addr
.l_symndx
4094 obj_coff_external_syms (input_bfd
)))
4096 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4099 bfd_byte
*linpend
, *linp
;
4101 bfd_size_type count
;
4103 lin
.l_addr
.l_symndx
= *indexp
;
4104 bfd_coff_swap_lineno_out (output_bfd
, (void *) &lin
,
4105 (void *) (finfo
->linenos
4108 linpend
= (finfo
->linenos
4109 + enc_count
* linesz
);
4110 offset
= (o
->output_section
->vma
4113 for (linp
= finfo
->linenos
+ linoff
+ linesz
;
4117 bfd_coff_swap_lineno_in (input_bfd
, (void *) linp
,
4119 if (lin
.l_lnno
== 0)
4121 lin
.l_addr
.l_paddr
+= offset
;
4122 bfd_coff_swap_lineno_out (output_bfd
,
4127 count
= (linp
- (finfo
->linenos
+ linoff
)) / linesz
;
4129 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
4130 (o
->output_section
->line_filepos
4131 + o
->output_section
->lineno_count
* linesz
);
4133 if (bfd_seek (output_bfd
,
4134 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
4136 || (bfd_bwrite (finfo
->linenos
+ linoff
,
4137 linesz
* count
, output_bfd
)
4141 o
->output_section
->lineno_count
+= count
;
4145 struct internal_syment
*iisp
, *iispend
;
4150 /* Update any C_BINCL or C_EINCL symbols
4151 that refer to a line number in the
4152 range we just output. */
4153 iisp
= finfo
->internal_syms
;
4155 + obj_raw_syment_count (input_bfd
));
4156 iindp
= finfo
->sym_indices
;
4157 oos
= finfo
->outsyms
;
4158 while (iisp
< iispend
)
4161 && (iisp
->n_sclass
== C_BINCL
4162 || iisp
->n_sclass
== C_EINCL
)
4163 && ((bfd_size_type
) iisp
->n_value
4164 >= (bfd_size_type
)(enclosing
->line_filepos
+ linoff
))
4165 && ((bfd_size_type
) iisp
->n_value
4166 < (enclosing
->line_filepos
4167 + enc_count
* linesz
)))
4169 struct internal_syment iis
;
4171 bfd_coff_swap_sym_in (output_bfd
,
4176 - enclosing
->line_filepos
4178 + aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
4179 bfd_coff_swap_sym_out (output_bfd
,
4185 iiadd
= 1 + iisp
->n_numaux
;
4187 oos
+= iiadd
* osymesz
;
4196 bfd_coff_swap_aux_out (output_bfd
, (void *) &aux
, isymp
->n_type
,
4197 isymp
->n_sclass
, i
, isymp
->n_numaux
,
4210 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
4211 symbol will be the first symbol in the next input file. In the
4212 normal case, this will save us from writing out the C_FILE symbol
4214 if (finfo
->last_file_index
!= -1
4215 && (bfd_size_type
) finfo
->last_file_index
>= syment_base
)
4217 finfo
->last_file
.n_value
= output_index
;
4218 bfd_coff_swap_sym_out (output_bfd
, (void *) &finfo
->last_file
,
4219 (void *) (finfo
->outsyms
4220 + ((finfo
->last_file_index
- syment_base
)
4224 /* Write the modified symbols to the output file. */
4225 if (outsym
> finfo
->outsyms
)
4227 file_ptr pos
= obj_sym_filepos (output_bfd
) + syment_base
* osymesz
;
4228 bfd_size_type amt
= outsym
- finfo
->outsyms
;
4229 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4230 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
4233 BFD_ASSERT ((obj_raw_syment_count (output_bfd
)
4234 + (outsym
- finfo
->outsyms
) / osymesz
)
4237 obj_raw_syment_count (output_bfd
) = output_index
;
4240 /* Don't let the linker relocation routines discard the symbols. */
4241 keep_syms
= obj_coff_keep_syms (input_bfd
);
4242 obj_coff_keep_syms (input_bfd
) = TRUE
;
4244 /* Relocate the contents of each section. */
4245 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4249 if (! o
->linker_mark
)
4250 /* This section was omitted from the link. */
4253 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
4255 || (o
->flags
& SEC_IN_MEMORY
) != 0)
4258 /* We have set filepos correctly for the sections we created to
4259 represent csects, so bfd_get_section_contents should work. */
4260 if (coff_section_data (input_bfd
, o
) != NULL
4261 && coff_section_data (input_bfd
, o
)->contents
!= NULL
)
4262 contents
= coff_section_data (input_bfd
, o
)->contents
;
4265 bfd_size_type sz
= o
->rawsize
? o
->rawsize
: o
->size
;
4266 if (!bfd_get_section_contents (input_bfd
, o
, finfo
->contents
, 0, sz
))
4268 contents
= finfo
->contents
;
4271 if ((o
->flags
& SEC_RELOC
) != 0)
4274 struct internal_reloc
*internal_relocs
;
4275 struct internal_reloc
*irel
;
4277 struct internal_reloc
*irelend
;
4278 struct xcoff_link_hash_entry
**rel_hash
;
4281 /* Read in the relocs. */
4282 target_index
= o
->output_section
->target_index
;
4283 internal_relocs
= (xcoff_read_internal_relocs
4284 (input_bfd
, o
, FALSE
, finfo
->external_relocs
,
4286 (finfo
->section_info
[target_index
].relocs
4287 + o
->output_section
->reloc_count
)));
4288 if (internal_relocs
== NULL
)
4291 /* Call processor specific code to relocate the section
4293 if (! bfd_coff_relocate_section (output_bfd
, finfo
->info
,
4297 finfo
->internal_syms
,
4298 xcoff_data (input_bfd
)->csects
))
4301 offset
= o
->output_section
->vma
+ o
->output_offset
- o
->vma
;
4302 irel
= internal_relocs
;
4303 irelend
= irel
+ o
->reloc_count
;
4304 rel_hash
= (finfo
->section_info
[target_index
].rel_hashes
4305 + o
->output_section
->reloc_count
);
4306 for (; irel
< irelend
; irel
++, rel_hash
++)
4308 struct xcoff_link_hash_entry
*h
= NULL
;
4309 struct internal_ldrel ldrel
;
4313 /* Adjust the reloc address and symbol index. */
4315 irel
->r_vaddr
+= offset
;
4317 r_symndx
= irel
->r_symndx
;
4322 h
= obj_xcoff_sym_hashes (input_bfd
)[r_symndx
];
4324 if (r_symndx
!= -1 && finfo
->info
->strip
!= strip_all
)
4327 && h
->smclas
!= XMC_TD
4328 && (irel
->r_type
== R_TOC
4329 || irel
->r_type
== R_GL
4330 || irel
->r_type
== R_TCL
4331 || irel
->r_type
== R_TRL
4332 || irel
->r_type
== R_TRLA
))
4334 /* This is a TOC relative reloc with a symbol
4335 attached. The symbol should be the one which
4336 this reloc is for. We want to make this
4337 reloc against the TOC address of the symbol,
4338 not the symbol itself. */
4339 BFD_ASSERT (h
->toc_section
!= NULL
);
4340 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
4341 if (h
->u
.toc_indx
!= -1)
4342 irel
->r_symndx
= h
->u
.toc_indx
;
4345 struct xcoff_toc_rel_hash
*n
;
4346 struct xcoff_link_section_info
*si
;
4350 n
= bfd_alloc (finfo
->output_bfd
, amt
);
4353 si
= finfo
->section_info
+ target_index
;
4354 n
->next
= si
->toc_rel_hashes
;
4357 si
->toc_rel_hashes
= n
;
4362 /* This is a global symbol. */
4364 irel
->r_symndx
= h
->indx
;
4367 /* This symbol is being written at the end
4368 of the file, and we do not yet know the
4369 symbol index. We save the pointer to the
4370 hash table entry in the rel_hash list.
4371 We set the indx field to -2 to indicate
4372 that this symbol must not be stripped. */
4381 indx
= finfo
->sym_indices
[r_symndx
];
4385 struct internal_syment
*is
;
4387 /* Relocations against a TC0 TOC anchor are
4388 automatically transformed to be against
4389 the TOC anchor in the output file. */
4390 is
= finfo
->internal_syms
+ r_symndx
;
4391 if (is
->n_sclass
== C_HIDEXT
4392 && is
->n_numaux
> 0)
4395 union internal_auxent aux
;
4399 obj_coff_external_syms (input_bfd
))
4400 + ((r_symndx
+ is
->n_numaux
)
4402 bfd_coff_swap_aux_in (input_bfd
, auxptr
,
4403 is
->n_type
, is
->n_sclass
,
4407 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_SD
4408 && aux
.x_csect
.x_smclas
== XMC_TC0
)
4409 indx
= finfo
->toc_symindx
;
4414 irel
->r_symndx
= indx
;
4418 struct internal_syment
*is
;
4421 char buf
[SYMNMLEN
+ 1];
4423 /* This reloc is against a symbol we are
4424 stripping. It would be possible to handle
4425 this case, but I don't think it's worth it. */
4426 is
= finfo
->internal_syms
+ r_symndx
;
4428 name
= (_bfd_coff_internal_syment_name
4429 (input_bfd
, is
, buf
));
4434 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4435 (finfo
->info
, name
, input_bfd
, o
,
4442 switch (irel
->r_type
)
4446 || h
->root
.type
== bfd_link_hash_defined
4447 || h
->root
.type
== bfd_link_hash_defweak
4448 || h
->root
.type
== bfd_link_hash_common
)
4456 && (h
->root
.type
== bfd_link_hash_defined
4457 || h
->root
.type
== bfd_link_hash_defweak
)
4458 && bfd_is_abs_section (h
->root
.u
.def
.section
))
4460 /* This reloc needs to be copied into the .loader
4462 ldrel
.l_vaddr
= irel
->r_vaddr
;
4464 ldrel
.l_symndx
= -(bfd_size_type
) 1;
4466 || (h
->root
.type
== bfd_link_hash_defined
4467 || h
->root
.type
== bfd_link_hash_defweak
4468 || h
->root
.type
== bfd_link_hash_common
))
4473 sec
= xcoff_data (input_bfd
)->csects
[r_symndx
];
4474 else if (h
->root
.type
== bfd_link_hash_common
)
4475 sec
= h
->root
.u
.c
.p
->section
;
4477 sec
= h
->root
.u
.def
.section
;
4478 sec
= sec
->output_section
;
4480 if (strcmp (sec
->name
, ".text") == 0)
4482 else if (strcmp (sec
->name
, ".data") == 0)
4484 else if (strcmp (sec
->name
, ".bss") == 0)
4488 (*_bfd_error_handler
)
4489 (_("%B: loader reloc in unrecognized section `%A'"),
4491 bfd_set_error (bfd_error_nonrepresentable_section
);
4499 (*_bfd_error_handler
)
4500 (_("%B: `%s' in loader reloc but not loader sym"),
4502 h
->root
.root
.string
);
4503 bfd_set_error (bfd_error_bad_value
);
4506 ldrel
.l_symndx
= h
->ldindx
;
4508 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
4509 ldrel
.l_rsecnm
= o
->output_section
->target_index
;
4510 if (xcoff_hash_table (finfo
->info
)->textro
4511 && strcmp (o
->output_section
->name
, ".text") == 0)
4513 (*_bfd_error_handler
)
4514 (_("%B: loader reloc in read-only section %A"),
4515 input_bfd
, o
->output_section
);
4516 bfd_set_error (bfd_error_invalid_operation
);
4519 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
,
4522 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
4530 /* We should never need a .loader reloc for a TOC
4536 o
->output_section
->reloc_count
+= o
->reloc_count
;
4539 /* Write out the modified section contents. */
4540 if (! bfd_set_section_contents (output_bfd
, o
->output_section
,
4541 contents
, (file_ptr
) o
->output_offset
,
4546 obj_coff_keep_syms (input_bfd
) = keep_syms
;
4548 if (! finfo
->info
->keep_memory
)
4550 if (! _bfd_coff_free_symbols (input_bfd
))
4560 /* Sort relocs by VMA. This is called via qsort. */
4563 xcoff_sort_relocs (const void * p1
, const void * p2
)
4565 const struct internal_reloc
*r1
= (const struct internal_reloc
*) p1
;
4566 const struct internal_reloc
*r2
= (const struct internal_reloc
*) p2
;
4568 if (r1
->r_vaddr
> r2
->r_vaddr
)
4570 else if (r1
->r_vaddr
< r2
->r_vaddr
)
4576 /* Return true if section SEC is a TOC section. */
4578 static inline bfd_boolean
4579 xcoff_toc_section_p (asection
*sec
)
4584 if (name
[0] == '.' && name
[1] == 't')
4588 if (name
[3] == '0' && name
[4] == 0)
4593 if (name
[2] == 'd' && name
[3] == 0)
4599 /* See if the link requires a TOC (it usually does!). If so, find a
4600 good place to put the TOC anchor csect, and write out the associated
4604 xcoff_find_tc0 (bfd
*output_bfd
, struct xcoff_final_link_info
*finfo
)
4606 bfd_vma toc_start
, toc_end
, start
, end
, best_address
;
4610 struct internal_syment irsym
;
4611 union internal_auxent iraux
;
4615 /* Set [TOC_START, TOC_END) to the range of the TOC. Record the
4616 index of a csect at the beginning of the TOC. */
4617 toc_start
= ~(bfd_vma
) 0;
4620 for (input_bfd
= finfo
->info
->input_bfds
;
4622 input_bfd
= input_bfd
->link_next
)
4623 for (sec
= input_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4624 if ((sec
->flags
& SEC_MARK
) != 0 && xcoff_toc_section_p (sec
))
4626 start
= sec
->output_section
->vma
+ sec
->output_offset
;
4627 if (toc_start
> start
)
4630 section_index
= sec
->output_section
->target_index
;
4633 end
= start
+ sec
->size
;
4638 /* There's no need for a TC0 symbol if we don't have a TOC. */
4639 if (toc_end
< toc_start
)
4641 xcoff_data (output_bfd
)->toc
= toc_start
;
4645 if (toc_end
- toc_start
< 0x8000)
4646 /* Every TOC csect can be accessed from TOC_START. */
4647 best_address
= toc_start
;
4650 /* Find the lowest TOC csect that is still within range of TOC_END. */
4651 best_address
= toc_end
;
4652 for (input_bfd
= finfo
->info
->input_bfds
;
4654 input_bfd
= input_bfd
->link_next
)
4655 for (sec
= input_bfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
4656 if ((sec
->flags
& SEC_MARK
) != 0 && xcoff_toc_section_p (sec
))
4658 start
= sec
->output_section
->vma
+ sec
->output_offset
;
4659 if (start
< best_address
4660 && start
+ 0x8000 >= toc_end
)
4662 best_address
= start
;
4663 section_index
= sec
->output_section
->target_index
;
4667 /* Make sure that the start of the TOC is also within range. */
4668 if (best_address
> toc_start
+ 0x8000)
4670 (*_bfd_error_handler
)
4671 (_("TOC overflow: 0x%lx > 0x10000; try -mminimal-toc "
4673 (unsigned long) (toc_end
- toc_start
));
4674 bfd_set_error (bfd_error_file_too_big
);
4679 /* Record the chosen TOC value. */
4680 finfo
->toc_symindx
= obj_raw_syment_count (output_bfd
);
4681 xcoff_data (output_bfd
)->toc
= best_address
;
4682 xcoff_data (output_bfd
)->sntoc
= section_index
;
4684 /* Fill out the TC0 symbol. */
4685 if (!bfd_xcoff_put_symbol_name (output_bfd
, finfo
->strtab
, &irsym
, "TOC"))
4687 irsym
.n_value
= best_address
;
4688 irsym
.n_scnum
= section_index
;
4689 irsym
.n_sclass
= C_HIDEXT
;
4690 irsym
.n_type
= T_NULL
;
4692 bfd_coff_swap_sym_out (output_bfd
, &irsym
, finfo
->outsyms
);
4694 /* Fill out the auxillary csect information. */
4695 memset (&iraux
, 0, sizeof iraux
);
4696 iraux
.x_csect
.x_smtyp
= XTY_SD
;
4697 iraux
.x_csect
.x_smclas
= XMC_TC0
;
4698 iraux
.x_csect
.x_scnlen
.l
= 0;
4699 bfd_coff_swap_aux_out (output_bfd
, &iraux
, T_NULL
, C_HIDEXT
, 0, 1,
4700 finfo
->outsyms
+ bfd_coff_symesz (output_bfd
));
4702 /* Write the contents to the file. */
4703 pos
= obj_sym_filepos (output_bfd
);
4704 pos
+= obj_raw_syment_count (output_bfd
) * bfd_coff_symesz (output_bfd
);
4705 size
= 2 * bfd_coff_symesz (output_bfd
);
4706 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4707 || bfd_bwrite (finfo
->outsyms
, size
, output_bfd
) != size
)
4709 obj_raw_syment_count (output_bfd
) += 2;
4714 /* Write out a non-XCOFF global symbol. */
4717 xcoff_write_global_symbol (struct xcoff_link_hash_entry
*h
, void * inf
)
4719 struct xcoff_final_link_info
*finfo
= (struct xcoff_final_link_info
*) inf
;
4722 struct internal_syment isym
;
4723 union internal_auxent aux
;
4728 output_bfd
= finfo
->output_bfd
;
4729 outsym
= finfo
->outsyms
;
4731 if (h
->root
.type
== bfd_link_hash_warning
)
4733 h
= (struct xcoff_link_hash_entry
*) h
->root
.u
.i
.link
;
4734 if (h
->root
.type
== bfd_link_hash_new
)
4738 /* If this symbol was garbage collected, just skip it. */
4739 if (xcoff_hash_table (finfo
->info
)->gc
4740 && (h
->flags
& XCOFF_MARK
) == 0)
4743 /* If we need a .loader section entry, write it out. */
4744 if (h
->ldsym
!= NULL
)
4746 struct internal_ldsym
*ldsym
;
4751 if (h
->root
.type
== bfd_link_hash_undefined
4752 || h
->root
.type
== bfd_link_hash_undefweak
)
4756 ldsym
->l_scnum
= N_UNDEF
;
4757 ldsym
->l_smtype
= XTY_ER
;
4758 impbfd
= h
->root
.u
.undef
.abfd
;
4761 else if (h
->root
.type
== bfd_link_hash_defined
4762 || h
->root
.type
== bfd_link_hash_defweak
)
4766 sec
= h
->root
.u
.def
.section
;
4767 ldsym
->l_value
= (sec
->output_section
->vma
4768 + sec
->output_offset
4769 + h
->root
.u
.def
.value
);
4770 ldsym
->l_scnum
= sec
->output_section
->target_index
;
4771 ldsym
->l_smtype
= XTY_SD
;
4772 impbfd
= sec
->owner
;
4778 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
4779 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4780 || (h
->flags
& XCOFF_IMPORT
) != 0)
4782 Import symbols are defined so the check above will make
4783 the l_smtype XTY_SD. But this is not correct, it should
4785 ldsym
->l_smtype
|= L_IMPORT
;
4787 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
4788 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4789 || (h
->flags
& XCOFF_EXPORT
) != 0)
4790 ldsym
->l_smtype
|= L_EXPORT
;
4792 if ((h
->flags
& XCOFF_ENTRY
) != 0)
4793 ldsym
->l_smtype
|= L_ENTRY
;
4795 if ((h
->flags
& XCOFF_RTINIT
) != 0)
4796 ldsym
->l_smtype
= XTY_SD
;
4798 ldsym
->l_smclas
= h
->smclas
;
4800 if (ldsym
->l_smtype
& L_IMPORT
)
4802 if ((h
->root
.type
== bfd_link_hash_defined
4803 || h
->root
.type
== bfd_link_hash_defweak
)
4804 && (h
->root
.u
.def
.value
!= 0))
4805 ldsym
->l_smclas
= XMC_XO
;
4807 else if ((h
->flags
& (XCOFF_SYSCALL32
| XCOFF_SYSCALL64
)) ==
4808 (XCOFF_SYSCALL32
| XCOFF_SYSCALL64
))
4809 ldsym
->l_smclas
= XMC_SV3264
;
4811 else if (h
->flags
& XCOFF_SYSCALL32
)
4812 ldsym
->l_smclas
= XMC_SV
;
4814 else if (h
->flags
& XCOFF_SYSCALL64
)
4815 ldsym
->l_smclas
= XMC_SV64
;
4818 if (ldsym
->l_ifile
== -(bfd_size_type
) 1)
4822 else if (ldsym
->l_ifile
== 0)
4824 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
4826 else if (impbfd
== NULL
)
4830 BFD_ASSERT (impbfd
->xvec
== output_bfd
->xvec
);
4831 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
4837 BFD_ASSERT (h
->ldindx
>= 0);
4839 bfd_xcoff_swap_ldsym_out (output_bfd
, ldsym
,
4842 * bfd_xcoff_ldsymsz(finfo
->output_bfd
)));
4846 /* If this symbol needs global linkage code, write it out. */
4847 if (h
->root
.type
== bfd_link_hash_defined
4848 && (h
->root
.u
.def
.section
4849 == xcoff_hash_table (finfo
->info
)->linkage_section
))
4855 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
4857 /* The first instruction in the global linkage code loads a
4858 specific TOC element. */
4859 tocoff
= (h
->descriptor
->toc_section
->output_section
->vma
4860 + h
->descriptor
->toc_section
->output_offset
4861 - xcoff_data (output_bfd
)->toc
);
4863 if ((h
->descriptor
->flags
& XCOFF_SET_TOC
) != 0)
4864 tocoff
+= h
->descriptor
->u
.toc_offset
;
4866 /* The first instruction in the glink code needs to be
4867 cooked to to hold the correct offset in the toc. The
4868 rest are just output raw. */
4869 bfd_put_32 (output_bfd
,
4870 bfd_xcoff_glink_code(output_bfd
, 0) | (tocoff
& 0xffff), p
);
4872 /* Start with i == 1 to get past the first instruction done above
4873 The /4 is because the glink code is in bytes and we are going
4875 for (i
= 1; i
< bfd_xcoff_glink_code_size(output_bfd
) / 4; i
++)
4876 bfd_put_32 (output_bfd
,
4877 (bfd_vma
) bfd_xcoff_glink_code(output_bfd
, i
),
4881 /* If we created a TOC entry for this symbol, write out the required
4883 if ((h
->flags
& XCOFF_SET_TOC
) != 0)
4888 struct internal_reloc
*irel
;
4889 struct internal_ldrel ldrel
;
4890 struct internal_syment irsym
;
4891 union internal_auxent iraux
;
4893 tocsec
= h
->toc_section
;
4894 osec
= tocsec
->output_section
;
4895 oindx
= osec
->target_index
;
4896 irel
= finfo
->section_info
[oindx
].relocs
+ osec
->reloc_count
;
4897 irel
->r_vaddr
= (osec
->vma
4898 + tocsec
->output_offset
4902 irel
->r_symndx
= h
->indx
;
4906 irel
->r_symndx
= obj_raw_syment_count (output_bfd
);
4909 BFD_ASSERT (h
->ldindx
>= 0);
4911 /* Initialize the aux union here instead of closer to when it is
4912 written out below because the length of the csect depends on
4913 whether the output is 32 or 64 bit. */
4914 memset (&iraux
, 0, sizeof iraux
);
4915 iraux
.x_csect
.x_smtyp
= XTY_SD
;
4916 /* iraux.x_csect.x_scnlen.l = 4 or 8, see below. */
4917 iraux
.x_csect
.x_smclas
= XMC_TC
;
4919 /* 32 bit uses a 32 bit R_POS to do the relocations
4920 64 bit uses a 64 bit R_POS to do the relocations
4922 Also needs to change the csect size : 4 for 32 bit, 8 for 64 bit
4924 Which one is determined by the backend. */
4925 if (bfd_xcoff_is_xcoff64 (output_bfd
))
4928 iraux
.x_csect
.x_scnlen
.l
= 8;
4930 else if (bfd_xcoff_is_xcoff32 (output_bfd
))
4933 iraux
.x_csect
.x_scnlen
.l
= 4;
4938 irel
->r_type
= R_POS
;
4939 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
4940 ++osec
->reloc_count
;
4942 ldrel
.l_vaddr
= irel
->r_vaddr
;
4943 ldrel
.l_symndx
= h
->ldindx
;
4944 ldrel
.l_rtype
= (irel
->r_size
<< 8) | R_POS
;
4945 ldrel
.l_rsecnm
= oindx
;
4946 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
4947 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
4949 /* We need to emit a symbol to define a csect which holds
4951 if (finfo
->info
->strip
!= strip_all
)
4953 result
= bfd_xcoff_put_symbol_name (output_bfd
, finfo
->strtab
,
4954 &irsym
, h
->root
.root
.string
);
4958 irsym
.n_value
= irel
->r_vaddr
;
4959 irsym
.n_scnum
= osec
->target_index
;
4960 irsym
.n_sclass
= C_HIDEXT
;
4961 irsym
.n_type
= T_NULL
;
4964 bfd_coff_swap_sym_out (output_bfd
, (void *) &irsym
, (void *) outsym
);
4965 outsym
+= bfd_coff_symesz (output_bfd
);
4967 /* Note : iraux is initialized above. */
4968 bfd_coff_swap_aux_out (output_bfd
, (void *) &iraux
, T_NULL
, C_HIDEXT
,
4969 0, 1, (void *) outsym
);
4970 outsym
+= bfd_coff_auxesz (output_bfd
);
4974 /* We aren't going to write out the symbols below, so we
4975 need to write them out now. */
4976 pos
= obj_sym_filepos (output_bfd
);
4977 pos
+= (obj_raw_syment_count (output_bfd
)
4978 * bfd_coff_symesz (output_bfd
));
4979 amt
= outsym
- finfo
->outsyms
;
4980 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4981 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
4983 obj_raw_syment_count (output_bfd
) +=
4984 (outsym
- finfo
->outsyms
) / bfd_coff_symesz (output_bfd
);
4986 outsym
= finfo
->outsyms
;
4991 /* If this symbol is a specially defined function descriptor, write
4992 it out. The first word is the address of the function code
4993 itself, the second word is the address of the TOC, and the third
4997 The addresses for the 32 bit will take 4 bytes and the addresses
4998 for 64 bit will take 8 bytes. Similar for the relocs. This type
4999 of logic was also done above to create a TOC entry in
5000 xcoff_write_global_symbol. */
5001 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0
5002 && h
->root
.type
== bfd_link_hash_defined
5003 && (h
->root
.u
.def
.section
5004 == xcoff_hash_table (finfo
->info
)->descriptor_section
))
5010 struct xcoff_link_hash_entry
*hentry
;
5012 struct internal_reloc
*irel
;
5013 struct internal_ldrel ldrel
;
5015 unsigned int reloc_size
, byte_size
;
5017 if (bfd_xcoff_is_xcoff64 (output_bfd
))
5022 else if (bfd_xcoff_is_xcoff32 (output_bfd
))
5030 sec
= h
->root
.u
.def
.section
;
5031 osec
= sec
->output_section
;
5032 oindx
= osec
->target_index
;
5033 p
= sec
->contents
+ h
->root
.u
.def
.value
;
5035 hentry
= h
->descriptor
;
5036 BFD_ASSERT (hentry
!= NULL
5037 && (hentry
->root
.type
== bfd_link_hash_defined
5038 || hentry
->root
.type
== bfd_link_hash_defweak
));
5039 esec
= hentry
->root
.u
.def
.section
;
5041 irel
= finfo
->section_info
[oindx
].relocs
+ osec
->reloc_count
;
5042 irel
->r_vaddr
= (osec
->vma
5043 + sec
->output_offset
5044 + h
->root
.u
.def
.value
);
5045 irel
->r_symndx
= esec
->output_section
->target_index
;
5046 irel
->r_type
= R_POS
;
5047 irel
->r_size
= reloc_size
;
5048 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
5049 ++osec
->reloc_count
;
5051 ldrel
.l_vaddr
= irel
->r_vaddr
;
5052 if (strcmp (esec
->output_section
->name
, ".text") == 0)
5054 else if (strcmp (esec
->output_section
->name
, ".data") == 0)
5056 else if (strcmp (esec
->output_section
->name
, ".bss") == 0)
5060 (*_bfd_error_handler
)
5061 (_("%s: loader reloc in unrecognized section `%s'"),
5062 bfd_get_filename (output_bfd
),
5063 esec
->output_section
->name
);
5064 bfd_set_error (bfd_error_nonrepresentable_section
);
5067 ldrel
.l_rtype
= (reloc_size
<< 8) | R_POS
;
5068 ldrel
.l_rsecnm
= oindx
;
5069 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5070 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5072 /* There are three items to write out,
5073 the address of the code
5074 the address of the toc anchor
5075 the environment pointer.
5076 We are ignoring the environment pointer. So set it to zero. */
5077 if (bfd_xcoff_is_xcoff64 (output_bfd
))
5079 bfd_put_64 (output_bfd
,
5080 (esec
->output_section
->vma
+ esec
->output_offset
5081 + hentry
->root
.u
.def
.value
),
5083 bfd_put_64 (output_bfd
, xcoff_data (output_bfd
)->toc
, p
+ 8);
5084 bfd_put_64 (output_bfd
, (bfd_vma
) 0, p
+ 16);
5089 This logic was already called above so the error case where
5090 the backend is neither has already been checked. */
5091 bfd_put_32 (output_bfd
,
5092 (esec
->output_section
->vma
+ esec
->output_offset
5093 + hentry
->root
.u
.def
.value
),
5095 bfd_put_32 (output_bfd
, xcoff_data (output_bfd
)->toc
, p
+ 4);
5096 bfd_put_32 (output_bfd
, (bfd_vma
) 0, p
+ 8);
5099 tsec
= coff_section_from_bfd_index (output_bfd
,
5100 xcoff_data (output_bfd
)->sntoc
);
5103 irel
->r_vaddr
= (osec
->vma
5104 + sec
->output_offset
5105 + h
->root
.u
.def
.value
5107 irel
->r_symndx
= tsec
->output_section
->target_index
;
5108 irel
->r_type
= R_POS
;
5109 irel
->r_size
= reloc_size
;
5110 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
5111 ++osec
->reloc_count
;
5113 ldrel
.l_vaddr
= irel
->r_vaddr
;
5114 if (strcmp (tsec
->output_section
->name
, ".text") == 0)
5116 else if (strcmp (tsec
->output_section
->name
, ".data") == 0)
5118 else if (strcmp (tsec
->output_section
->name
, ".bss") == 0)
5122 (*_bfd_error_handler
)
5123 (_("%s: loader reloc in unrecognized section `%s'"),
5124 bfd_get_filename (output_bfd
),
5125 tsec
->output_section
->name
);
5126 bfd_set_error (bfd_error_nonrepresentable_section
);
5129 ldrel
.l_rtype
= (reloc_size
<< 8) | R_POS
;
5130 ldrel
.l_rsecnm
= oindx
;
5131 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5132 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5135 if (h
->indx
>= 0 || finfo
->info
->strip
== strip_all
)
5137 BFD_ASSERT (outsym
== finfo
->outsyms
);
5142 && (finfo
->info
->strip
== strip_all
5143 || (finfo
->info
->strip
== strip_some
5144 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
5145 FALSE
, FALSE
) == NULL
)))
5147 BFD_ASSERT (outsym
== finfo
->outsyms
);
5152 && (h
->flags
& (XCOFF_REF_REGULAR
| XCOFF_DEF_REGULAR
)) == 0)
5154 BFD_ASSERT (outsym
== finfo
->outsyms
);
5158 memset (&aux
, 0, sizeof aux
);
5160 h
->indx
= obj_raw_syment_count (output_bfd
);
5162 result
= bfd_xcoff_put_symbol_name (output_bfd
, finfo
->strtab
, &isym
,
5163 h
->root
.root
.string
);
5167 if (h
->root
.type
== bfd_link_hash_undefined
5168 || h
->root
.type
== bfd_link_hash_undefweak
)
5171 isym
.n_scnum
= N_UNDEF
;
5172 isym
.n_sclass
= C_EXT
;
5173 aux
.x_csect
.x_smtyp
= XTY_ER
;
5175 else if ((h
->root
.type
== bfd_link_hash_defined
5176 || h
->root
.type
== bfd_link_hash_defweak
)
5177 && h
->smclas
== XMC_XO
)
5179 BFD_ASSERT (bfd_is_abs_section (h
->root
.u
.def
.section
));
5180 isym
.n_value
= h
->root
.u
.def
.value
;
5181 isym
.n_scnum
= N_UNDEF
;
5182 isym
.n_sclass
= C_EXT
;
5183 aux
.x_csect
.x_smtyp
= XTY_ER
;
5185 else if (h
->root
.type
== bfd_link_hash_defined
5186 || h
->root
.type
== bfd_link_hash_defweak
)
5188 struct xcoff_link_size_list
*l
;
5190 isym
.n_value
= (h
->root
.u
.def
.section
->output_section
->vma
5191 + h
->root
.u
.def
.section
->output_offset
5192 + h
->root
.u
.def
.value
);
5193 if (bfd_is_abs_section (h
->root
.u
.def
.section
->output_section
))
5194 isym
.n_scnum
= N_ABS
;
5196 isym
.n_scnum
= h
->root
.u
.def
.section
->output_section
->target_index
;
5197 isym
.n_sclass
= C_HIDEXT
;
5198 aux
.x_csect
.x_smtyp
= XTY_SD
;
5200 if ((h
->flags
& XCOFF_HAS_SIZE
) != 0)
5202 for (l
= xcoff_hash_table (finfo
->info
)->size_list
;
5208 aux
.x_csect
.x_scnlen
.l
= l
->size
;
5214 else if (h
->root
.type
== bfd_link_hash_common
)
5216 isym
.n_value
= (h
->root
.u
.c
.p
->section
->output_section
->vma
5217 + h
->root
.u
.c
.p
->section
->output_offset
);
5218 isym
.n_scnum
= h
->root
.u
.c
.p
->section
->output_section
->target_index
;
5219 isym
.n_sclass
= C_EXT
;
5220 aux
.x_csect
.x_smtyp
= XTY_CM
;
5221 aux
.x_csect
.x_scnlen
.l
= h
->root
.u
.c
.size
;
5226 isym
.n_type
= T_NULL
;
5229 bfd_coff_swap_sym_out (output_bfd
, (void *) &isym
, (void *) outsym
);
5230 outsym
+= bfd_coff_symesz (output_bfd
);
5232 aux
.x_csect
.x_smclas
= h
->smclas
;
5233 bfd_coff_swap_aux_out (output_bfd
, (void *) &aux
, T_NULL
, isym
.n_sclass
, 0, 1,
5235 outsym
+= bfd_coff_auxesz (output_bfd
);
5237 if ((h
->root
.type
== bfd_link_hash_defined
5238 || h
->root
.type
== bfd_link_hash_defweak
)
5239 && h
->smclas
!= XMC_XO
)
5241 /* We just output an SD symbol. Now output an LD symbol. */
5244 isym
.n_sclass
= C_EXT
;
5245 bfd_coff_swap_sym_out (output_bfd
, (void *) &isym
, (void *) outsym
);
5246 outsym
+= bfd_coff_symesz (output_bfd
);
5248 aux
.x_csect
.x_smtyp
= XTY_LD
;
5249 aux
.x_csect
.x_scnlen
.l
= obj_raw_syment_count (output_bfd
);
5250 bfd_coff_swap_aux_out (output_bfd
, (void *) &aux
, T_NULL
, C_EXT
, 0, 1,
5252 outsym
+= bfd_coff_auxesz (output_bfd
);
5255 pos
= obj_sym_filepos (output_bfd
);
5256 pos
+= obj_raw_syment_count (output_bfd
) * bfd_coff_symesz (output_bfd
);
5257 amt
= outsym
- finfo
->outsyms
;
5258 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
5259 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
5261 obj_raw_syment_count (output_bfd
) +=
5262 (outsym
- finfo
->outsyms
) / bfd_coff_symesz (output_bfd
);
5267 /* Handle a link order which is supposed to generate a reloc. */
5270 xcoff_reloc_link_order (bfd
*output_bfd
,
5271 struct xcoff_final_link_info
*finfo
,
5272 asection
*output_section
,
5273 struct bfd_link_order
*link_order
)
5275 reloc_howto_type
*howto
;
5276 struct xcoff_link_hash_entry
*h
;
5280 struct internal_reloc
*irel
;
5281 struct xcoff_link_hash_entry
**rel_hash_ptr
;
5282 struct internal_ldrel ldrel
;
5284 if (link_order
->type
== bfd_section_reloc_link_order
)
5285 /* We need to somehow locate a symbol in the right section. The
5286 symbol must either have a value of zero, or we must adjust
5287 the addend by the value of the symbol. FIXME: Write this
5288 when we need it. The old linker couldn't handle this anyhow. */
5291 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
5294 bfd_set_error (bfd_error_bad_value
);
5298 h
= ((struct xcoff_link_hash_entry
*)
5299 bfd_wrapped_link_hash_lookup (output_bfd
, finfo
->info
,
5300 link_order
->u
.reloc
.p
->u
.name
,
5301 FALSE
, FALSE
, TRUE
));
5304 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5305 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
, NULL
, NULL
, (bfd_vma
) 0)))
5310 if (h
->root
.type
== bfd_link_hash_common
)
5312 hsec
= h
->root
.u
.c
.p
->section
;
5315 else if (h
->root
.type
== bfd_link_hash_defined
5316 || h
->root
.type
== bfd_link_hash_defweak
)
5318 hsec
= h
->root
.u
.def
.section
;
5319 hval
= h
->root
.u
.def
.value
;
5327 addend
= link_order
->u
.reloc
.p
->addend
;
5329 addend
+= (hsec
->output_section
->vma
5330 + hsec
->output_offset
5337 bfd_reloc_status_type rstat
;
5340 size
= bfd_get_reloc_size (howto
);
5341 buf
= bfd_zmalloc (size
);
5345 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
5351 case bfd_reloc_outofrange
:
5353 case bfd_reloc_overflow
:
5354 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5355 (finfo
->info
, NULL
, link_order
->u
.reloc
.p
->u
.name
,
5356 howto
->name
, addend
, NULL
, NULL
, (bfd_vma
) 0)))
5363 ok
= bfd_set_section_contents (output_bfd
, output_section
, (void *) buf
,
5364 (file_ptr
) link_order
->offset
, size
);
5370 /* Store the reloc information in the right place. It will get
5371 swapped and written out at the end of the final_link routine. */
5372 irel
= (finfo
->section_info
[output_section
->target_index
].relocs
5373 + output_section
->reloc_count
);
5374 rel_hash_ptr
= (finfo
->section_info
[output_section
->target_index
].rel_hashes
5375 + output_section
->reloc_count
);
5377 memset (irel
, 0, sizeof (struct internal_reloc
));
5378 *rel_hash_ptr
= NULL
;
5380 irel
->r_vaddr
= output_section
->vma
+ link_order
->offset
;
5383 irel
->r_symndx
= h
->indx
;
5386 /* Set the index to -2 to force this symbol to get written out. */
5392 irel
->r_type
= howto
->type
;
5393 irel
->r_size
= howto
->bitsize
- 1;
5394 if (howto
->complain_on_overflow
== complain_overflow_signed
)
5395 irel
->r_size
|= 0x80;
5397 ++output_section
->reloc_count
;
5399 /* Now output the reloc to the .loader section. */
5401 ldrel
.l_vaddr
= irel
->r_vaddr
;
5405 const char *secname
;
5407 secname
= hsec
->output_section
->name
;
5409 if (strcmp (secname
, ".text") == 0)
5411 else if (strcmp (secname
, ".data") == 0)
5413 else if (strcmp (secname
, ".bss") == 0)
5417 (*_bfd_error_handler
)
5418 (_("%s: loader reloc in unrecognized section `%s'"),
5419 bfd_get_filename (output_bfd
), secname
);
5420 bfd_set_error (bfd_error_nonrepresentable_section
);
5428 (*_bfd_error_handler
)
5429 (_("%s: `%s' in loader reloc but not loader sym"),
5430 bfd_get_filename (output_bfd
),
5431 h
->root
.root
.string
);
5432 bfd_set_error (bfd_error_bad_value
);
5435 ldrel
.l_symndx
= h
->ldindx
;
5438 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
5439 ldrel
.l_rsecnm
= output_section
->target_index
;
5440 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5441 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5446 /* Do the final link step. */
5449 _bfd_xcoff_bfd_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
5451 bfd_size_type symesz
;
5452 struct xcoff_final_link_info finfo
;
5454 struct bfd_link_order
*p
;
5455 bfd_size_type max_contents_size
;
5456 bfd_size_type max_sym_count
;
5457 bfd_size_type max_lineno_count
;
5458 bfd_size_type max_reloc_count
;
5459 bfd_size_type max_output_reloc_count
;
5460 file_ptr rel_filepos
;
5462 file_ptr line_filepos
;
5463 unsigned int linesz
;
5465 bfd_byte
*external_relocs
= NULL
;
5466 char strbuf
[STRING_SIZE_SIZE
];
5471 abfd
->flags
|= DYNAMIC
;
5473 symesz
= bfd_coff_symesz (abfd
);
5476 finfo
.output_bfd
= abfd
;
5477 finfo
.strtab
= NULL
;
5478 finfo
.section_info
= NULL
;
5479 finfo
.last_file_index
= -1;
5480 finfo
.toc_symindx
= -1;
5481 finfo
.internal_syms
= NULL
;
5482 finfo
.sym_indices
= NULL
;
5483 finfo
.outsyms
= NULL
;
5484 finfo
.linenos
= NULL
;
5485 finfo
.contents
= NULL
;
5486 finfo
.external_relocs
= NULL
;
5488 finfo
.ldsym
= (xcoff_hash_table (info
)->loader_section
->contents
5489 + bfd_xcoff_ldhdrsz (abfd
));
5490 finfo
.ldrel
= (xcoff_hash_table (info
)->loader_section
->contents
5491 + bfd_xcoff_ldhdrsz(abfd
)
5492 + (xcoff_hash_table (info
)->ldhdr
.l_nsyms
5493 * bfd_xcoff_ldsymsz(abfd
)));
5495 xcoff_data (abfd
)->coff
.link_info
= info
;
5497 finfo
.strtab
= _bfd_stringtab_init ();
5498 if (finfo
.strtab
== NULL
)
5501 /* Count the line number and relocation entries required for the
5502 output file. Determine a few maximum sizes. */
5503 max_contents_size
= 0;
5504 max_lineno_count
= 0;
5505 max_reloc_count
= 0;
5506 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5509 o
->lineno_count
= 0;
5510 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
5512 if (p
->type
== bfd_indirect_link_order
)
5516 sec
= p
->u
.indirect
.section
;
5518 /* Mark all sections which are to be included in the
5519 link. This will normally be every section. We need
5520 to do this so that we can identify any sections which
5521 the linker has decided to not include. */
5522 sec
->linker_mark
= TRUE
;
5524 if (info
->strip
== strip_none
5525 || info
->strip
== strip_some
)
5526 o
->lineno_count
+= sec
->lineno_count
;
5528 o
->reloc_count
+= sec
->reloc_count
;
5530 if (sec
->rawsize
> max_contents_size
)
5531 max_contents_size
= sec
->rawsize
;
5532 if (sec
->size
> max_contents_size
)
5533 max_contents_size
= sec
->size
;
5534 if (sec
->lineno_count
> max_lineno_count
)
5535 max_lineno_count
= sec
->lineno_count
;
5536 if (coff_section_data (sec
->owner
, sec
) != NULL
5537 && xcoff_section_data (sec
->owner
, sec
) != NULL
5538 && (xcoff_section_data (sec
->owner
, sec
)->lineno_count
5539 > max_lineno_count
))
5541 xcoff_section_data (sec
->owner
, sec
)->lineno_count
;
5542 if (sec
->reloc_count
> max_reloc_count
)
5543 max_reloc_count
= sec
->reloc_count
;
5545 else if (p
->type
== bfd_section_reloc_link_order
5546 || p
->type
== bfd_symbol_reloc_link_order
)
5551 /* Compute the file positions for all the sections. */
5552 if (abfd
->output_has_begun
)
5554 if (xcoff_hash_table (info
)->file_align
!= 0)
5561 file_align
= xcoff_hash_table (info
)->file_align
;
5562 if (file_align
!= 0)
5564 bfd_boolean saw_contents
;
5568 /* Insert .pad sections before every section which has
5569 contents and is loaded, if it is preceded by some other
5570 section which has contents and is loaded. */
5571 saw_contents
= TRUE
;
5572 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5574 if (strcmp (o
->name
, ".pad") == 0)
5575 saw_contents
= FALSE
;
5576 else if ((o
->flags
& SEC_HAS_CONTENTS
) != 0
5577 && (o
->flags
& SEC_LOAD
) != 0)
5580 saw_contents
= TRUE
;
5585 /* Create a pad section and place it before the section
5586 that needs padding. This requires unlinking and
5587 relinking the bfd's section list. */
5589 n
= bfd_make_section_anyway_with_flags (abfd
, ".pad",
5591 n
->alignment_power
= 0;
5593 bfd_section_list_remove (abfd
, n
);
5594 bfd_section_list_insert_before (abfd
, o
, n
);
5595 saw_contents
= FALSE
;
5600 /* Reset the section indices after inserting the new
5603 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5606 o
->target_index
= indx
;
5608 BFD_ASSERT ((unsigned int) indx
== abfd
->section_count
);
5610 /* Work out appropriate sizes for the .pad sections to force
5611 each section to land on a page boundary. This bit of
5612 code knows what compute_section_file_positions is going
5614 sofar
= bfd_coff_filhsz (abfd
);
5615 sofar
+= bfd_coff_aoutsz (abfd
);
5616 sofar
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
5617 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5618 if ((bfd_xcoff_is_reloc_count_overflow
5619 (abfd
, (bfd_vma
) o
->reloc_count
))
5620 || (bfd_xcoff_is_lineno_count_overflow
5621 (abfd
, (bfd_vma
) o
->lineno_count
)))
5622 /* 64 does not overflow, need to check if 32 does */
5623 sofar
+= bfd_coff_scnhsz (abfd
);
5625 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5627 if (strcmp (o
->name
, ".pad") == 0)
5631 BFD_ASSERT (o
->size
== 0);
5632 pageoff
= sofar
& (file_align
- 1);
5635 o
->size
= file_align
- pageoff
;
5636 sofar
+= file_align
- pageoff
;
5637 o
->flags
|= SEC_HAS_CONTENTS
;
5642 if ((o
->flags
& SEC_HAS_CONTENTS
) != 0)
5643 sofar
+= BFD_ALIGN (o
->size
,
5644 1 << o
->alignment_power
);
5649 if (! bfd_coff_compute_section_file_positions (abfd
))
5653 /* Allocate space for the pointers we need to keep for the relocs. */
5657 /* We use section_count + 1, rather than section_count, because
5658 the target_index fields are 1 based. */
5659 amt
= abfd
->section_count
+ 1;
5660 amt
*= sizeof (struct xcoff_link_section_info
);
5661 finfo
.section_info
= bfd_malloc (amt
);
5662 if (finfo
.section_info
== NULL
)
5664 for (i
= 0; i
<= abfd
->section_count
; i
++)
5666 finfo
.section_info
[i
].relocs
= NULL
;
5667 finfo
.section_info
[i
].rel_hashes
= NULL
;
5668 finfo
.section_info
[i
].toc_rel_hashes
= NULL
;
5672 /* Set the file positions for the relocs. */
5673 rel_filepos
= obj_relocbase (abfd
);
5674 relsz
= bfd_coff_relsz (abfd
);
5675 max_output_reloc_count
= 0;
5676 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5678 if (o
->reloc_count
== 0)
5682 /* A stripped file has no relocs. However, we still
5683 allocate the buffers, so that later code doesn't have to
5684 worry about whether we are stripping or not. */
5685 if (info
->strip
== strip_all
)
5689 o
->flags
|= SEC_RELOC
;
5690 o
->rel_filepos
= rel_filepos
;
5691 rel_filepos
+= o
->reloc_count
* relsz
;
5694 /* We don't know the indices of global symbols until we have
5695 written out all the local symbols. For each section in
5696 the output file, we keep an array of pointers to hash
5697 table entries. Each entry in the array corresponds to a
5698 reloc. When we find a reloc against a global symbol, we
5699 set the corresponding entry in this array so that we can
5700 fix up the symbol index after we have written out all the
5703 Because of this problem, we also keep the relocs in
5704 memory until the end of the link. This wastes memory.
5705 We could backpatch the file later, I suppose, although it
5707 amt
= o
->reloc_count
;
5708 amt
*= sizeof (struct internal_reloc
);
5709 finfo
.section_info
[o
->target_index
].relocs
= bfd_malloc (amt
);
5711 amt
= o
->reloc_count
;
5712 amt
*= sizeof (struct xcoff_link_hash_entry
*);
5713 finfo
.section_info
[o
->target_index
].rel_hashes
= bfd_malloc (amt
);
5715 if (finfo
.section_info
[o
->target_index
].relocs
== NULL
5716 || finfo
.section_info
[o
->target_index
].rel_hashes
== NULL
)
5719 if (o
->reloc_count
> max_output_reloc_count
)
5720 max_output_reloc_count
= o
->reloc_count
;
5724 /* We now know the size of the relocs, so we can determine the file
5725 positions of the line numbers. */
5726 line_filepos
= rel_filepos
;
5727 finfo
.line_filepos
= line_filepos
;
5728 linesz
= bfd_coff_linesz (abfd
);
5729 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5731 if (o
->lineno_count
== 0)
5732 o
->line_filepos
= 0;
5735 o
->line_filepos
= line_filepos
;
5736 line_filepos
+= o
->lineno_count
* linesz
;
5739 /* Reset the reloc and lineno counts, so that we can use them to
5740 count the number of entries we have output so far. */
5742 o
->lineno_count
= 0;
5745 obj_sym_filepos (abfd
) = line_filepos
;
5747 /* Figure out the largest number of symbols in an input BFD. Take
5748 the opportunity to clear the output_has_begun fields of all the
5749 input BFD's. We want at least 6 symbols, since that is the
5750 number which xcoff_write_global_symbol may need. */
5752 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
5756 sub
->output_has_begun
= FALSE
;
5757 sz
= obj_raw_syment_count (sub
);
5758 if (sz
> max_sym_count
)
5762 /* Allocate some buffers used while linking. */
5763 amt
= max_sym_count
* sizeof (struct internal_syment
);
5764 finfo
.internal_syms
= bfd_malloc (amt
);
5766 amt
= max_sym_count
* sizeof (long);
5767 finfo
.sym_indices
= bfd_malloc (amt
);
5769 amt
= (max_sym_count
+ 1) * symesz
;
5770 finfo
.outsyms
= bfd_malloc (amt
);
5772 amt
= max_lineno_count
* bfd_coff_linesz (abfd
);
5773 finfo
.linenos
= bfd_malloc (amt
);
5775 amt
= max_contents_size
;
5776 finfo
.contents
= bfd_malloc (amt
);
5778 amt
= max_reloc_count
* relsz
;
5779 finfo
.external_relocs
= bfd_malloc (amt
);
5781 if ((finfo
.internal_syms
== NULL
&& max_sym_count
> 0)
5782 || (finfo
.sym_indices
== NULL
&& max_sym_count
> 0)
5783 || finfo
.outsyms
== NULL
5784 || (finfo
.linenos
== NULL
&& max_lineno_count
> 0)
5785 || (finfo
.contents
== NULL
&& max_contents_size
> 0)
5786 || (finfo
.external_relocs
== NULL
&& max_reloc_count
> 0))
5789 obj_raw_syment_count (abfd
) = 0;
5791 /* Find a TOC symbol, if we need one. */
5792 if (!xcoff_find_tc0 (abfd
, &finfo
))
5795 /* We now know the position of everything in the file, except that
5796 we don't know the size of the symbol table and therefore we don't
5797 know where the string table starts. We just build the string
5798 table in memory as we go along. We process all the relocations
5799 for a single input file at once. */
5800 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5802 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
5804 if (p
->type
== bfd_indirect_link_order
5805 && p
->u
.indirect
.section
->owner
->xvec
== abfd
->xvec
)
5807 sub
= p
->u
.indirect
.section
->owner
;
5808 if (! sub
->output_has_begun
)
5810 if (! xcoff_link_input_bfd (&finfo
, sub
))
5812 sub
->output_has_begun
= TRUE
;
5815 else if (p
->type
== bfd_section_reloc_link_order
5816 || p
->type
== bfd_symbol_reloc_link_order
)
5818 if (! xcoff_reloc_link_order (abfd
, &finfo
, o
, p
))
5823 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
5829 /* Free up the buffers used by xcoff_link_input_bfd. */
5830 if (finfo
.internal_syms
!= NULL
)
5832 free (finfo
.internal_syms
);
5833 finfo
.internal_syms
= NULL
;
5835 if (finfo
.sym_indices
!= NULL
)
5837 free (finfo
.sym_indices
);
5838 finfo
.sym_indices
= NULL
;
5840 if (finfo
.linenos
!= NULL
)
5842 free (finfo
.linenos
);
5843 finfo
.linenos
= NULL
;
5845 if (finfo
.contents
!= NULL
)
5847 free (finfo
.contents
);
5848 finfo
.contents
= NULL
;
5850 if (finfo
.external_relocs
!= NULL
)
5852 free (finfo
.external_relocs
);
5853 finfo
.external_relocs
= NULL
;
5856 /* The value of the last C_FILE symbol is supposed to be -1. Write
5858 if (finfo
.last_file_index
!= -1)
5860 finfo
.last_file
.n_value
= -(bfd_vma
) 1;
5861 bfd_coff_swap_sym_out (abfd
, (void *) &finfo
.last_file
,
5862 (void *) finfo
.outsyms
);
5863 pos
= obj_sym_filepos (abfd
) + finfo
.last_file_index
* symesz
;
5864 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
5865 || bfd_bwrite (finfo
.outsyms
, symesz
, abfd
) != symesz
)
5869 /* Write out all the global symbols which do not come from XCOFF
5871 xcoff_link_hash_traverse (xcoff_hash_table (info
),
5872 xcoff_write_global_symbol
,
5875 if (finfo
.outsyms
!= NULL
)
5877 free (finfo
.outsyms
);
5878 finfo
.outsyms
= NULL
;
5881 /* Now that we have written out all the global symbols, we know the
5882 symbol indices to use for relocs against them, and we can finally
5883 write out the relocs. */
5884 amt
= max_output_reloc_count
* relsz
;
5885 external_relocs
= bfd_malloc (amt
);
5886 if (external_relocs
== NULL
&& max_output_reloc_count
!= 0)
5889 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
5891 struct internal_reloc
*irel
;
5892 struct internal_reloc
*irelend
;
5893 struct xcoff_link_hash_entry
**rel_hash
;
5894 struct xcoff_toc_rel_hash
*toc_rel_hash
;
5896 bfd_size_type rel_size
;
5898 /* A stripped file has no relocs. */
5899 if (info
->strip
== strip_all
)
5905 if (o
->reloc_count
== 0)
5908 irel
= finfo
.section_info
[o
->target_index
].relocs
;
5909 irelend
= irel
+ o
->reloc_count
;
5910 rel_hash
= finfo
.section_info
[o
->target_index
].rel_hashes
;
5911 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
5913 if (*rel_hash
!= NULL
)
5915 if ((*rel_hash
)->indx
< 0)
5917 if (! ((*info
->callbacks
->unattached_reloc
)
5918 (info
, (*rel_hash
)->root
.root
.string
,
5919 NULL
, o
, irel
->r_vaddr
)))
5921 (*rel_hash
)->indx
= 0;
5923 irel
->r_symndx
= (*rel_hash
)->indx
;
5927 for (toc_rel_hash
= finfo
.section_info
[o
->target_index
].toc_rel_hashes
;
5928 toc_rel_hash
!= NULL
;
5929 toc_rel_hash
= toc_rel_hash
->next
)
5931 if (toc_rel_hash
->h
->u
.toc_indx
< 0)
5933 if (! ((*info
->callbacks
->unattached_reloc
)
5934 (info
, toc_rel_hash
->h
->root
.root
.string
,
5935 NULL
, o
, toc_rel_hash
->rel
->r_vaddr
)))
5937 toc_rel_hash
->h
->u
.toc_indx
= 0;
5939 toc_rel_hash
->rel
->r_symndx
= toc_rel_hash
->h
->u
.toc_indx
;
5942 /* XCOFF requires that the relocs be sorted by address. We tend
5943 to produce them in the order in which their containing csects
5944 appear in the symbol table, which is not necessarily by
5945 address. So we sort them here. There may be a better way to
5947 qsort ((void *) finfo
.section_info
[o
->target_index
].relocs
,
5948 o
->reloc_count
, sizeof (struct internal_reloc
),
5951 irel
= finfo
.section_info
[o
->target_index
].relocs
;
5952 irelend
= irel
+ o
->reloc_count
;
5953 erel
= external_relocs
;
5954 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
5955 bfd_coff_swap_reloc_out (abfd
, (void *) irel
, (void *) erel
);
5957 rel_size
= relsz
* o
->reloc_count
;
5958 if (bfd_seek (abfd
, o
->rel_filepos
, SEEK_SET
) != 0
5959 || bfd_bwrite ((void *) external_relocs
, rel_size
, abfd
) != rel_size
)
5963 if (external_relocs
!= NULL
)
5965 free (external_relocs
);
5966 external_relocs
= NULL
;
5969 /* Free up the section information. */
5970 if (finfo
.section_info
!= NULL
)
5974 for (i
= 0; i
< abfd
->section_count
; i
++)
5976 if (finfo
.section_info
[i
].relocs
!= NULL
)
5977 free (finfo
.section_info
[i
].relocs
);
5978 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
5979 free (finfo
.section_info
[i
].rel_hashes
);
5981 free (finfo
.section_info
);
5982 finfo
.section_info
= NULL
;
5985 /* Write out the loader section contents. */
5986 BFD_ASSERT ((bfd_byte
*) finfo
.ldrel
5987 == (xcoff_hash_table (info
)->loader_section
->contents
5988 + xcoff_hash_table (info
)->ldhdr
.l_impoff
));
5989 o
= xcoff_hash_table (info
)->loader_section
;
5990 if (! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
5991 (file_ptr
) o
->output_offset
, o
->size
))
5994 /* Write out the magic sections. */
5995 o
= xcoff_hash_table (info
)->linkage_section
;
5997 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
5998 (file_ptr
) o
->output_offset
,
6001 o
= xcoff_hash_table (info
)->toc_section
;
6003 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
6004 (file_ptr
) o
->output_offset
,
6007 o
= xcoff_hash_table (info
)->descriptor_section
;
6009 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
6010 (file_ptr
) o
->output_offset
,
6014 /* Write out the string table. */
6015 pos
= obj_sym_filepos (abfd
) + obj_raw_syment_count (abfd
) * symesz
;
6016 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
6019 _bfd_stringtab_size (finfo
.strtab
) + STRING_SIZE_SIZE
,
6021 amt
= STRING_SIZE_SIZE
;
6022 if (bfd_bwrite (strbuf
, amt
, abfd
) != amt
)
6024 if (! _bfd_stringtab_emit (abfd
, finfo
.strtab
))
6027 _bfd_stringtab_free (finfo
.strtab
);
6029 /* Write out the debugging string table. */
6030 o
= xcoff_hash_table (info
)->debug_section
;
6033 struct bfd_strtab_hash
*debug_strtab
;
6035 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
6036 BFD_ASSERT (o
->output_section
->size
- o
->output_offset
6037 >= _bfd_stringtab_size (debug_strtab
));
6038 pos
= o
->output_section
->filepos
+ o
->output_offset
;
6039 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
6041 if (! _bfd_stringtab_emit (abfd
, debug_strtab
))
6045 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
6046 not try to write out the symbols. */
6047 bfd_get_symcount (abfd
) = 0;
6052 if (finfo
.strtab
!= NULL
)
6053 _bfd_stringtab_free (finfo
.strtab
);
6055 if (finfo
.section_info
!= NULL
)
6059 for (i
= 0; i
< abfd
->section_count
; i
++)
6061 if (finfo
.section_info
[i
].relocs
!= NULL
)
6062 free (finfo
.section_info
[i
].relocs
);
6063 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
6064 free (finfo
.section_info
[i
].rel_hashes
);
6066 free (finfo
.section_info
);
6069 if (finfo
.internal_syms
!= NULL
)
6070 free (finfo
.internal_syms
);
6071 if (finfo
.sym_indices
!= NULL
)
6072 free (finfo
.sym_indices
);
6073 if (finfo
.outsyms
!= NULL
)
6074 free (finfo
.outsyms
);
6075 if (finfo
.linenos
!= NULL
)
6076 free (finfo
.linenos
);
6077 if (finfo
.contents
!= NULL
)
6078 free (finfo
.contents
);
6079 if (finfo
.external_relocs
!= NULL
)
6080 free (finfo
.external_relocs
);
6081 if (external_relocs
!= NULL
)
6082 free (external_relocs
);