1 /* POWER/PowerPC XCOFF linker support.
2 Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001
3 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 2 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 #include "coff/internal.h"
27 #include "coff/xcoff.h"
31 /* This file holds the XCOFF linker code. */
33 #define STRING_SIZE_SIZE (4)
35 /* We reuse the SEC_ROM flag as a mark flag for garbage collection.
36 This flag will only be used on input sections. */
38 #define SEC_MARK (SEC_ROM)
40 /* The list of import files. */
42 struct xcoff_import_file
44 /* The next entry in the list. */
45 struct xcoff_import_file
*next
;
50 /* The member name. */
54 /* Information we keep for each section in the output file during the
57 struct xcoff_link_section_info
59 /* The relocs to be output. */
60 struct internal_reloc
*relocs
;
61 /* For each reloc against a global symbol whose index was not known
62 when the reloc was handled, the global hash table entry. */
63 struct xcoff_link_hash_entry
**rel_hashes
;
64 /* If there is a TOC relative reloc against a global symbol, and the
65 index of the TOC symbol is not known when the reloc was handled,
66 an entry is added to this linked list. This is not an array,
67 like rel_hashes, because this case is quite uncommon. */
68 struct xcoff_toc_rel_hash
{
69 struct xcoff_toc_rel_hash
*next
;
70 struct xcoff_link_hash_entry
*h
;
71 struct internal_reloc
*rel
;
75 /* Information that we pass around while doing the final link step. */
77 struct xcoff_final_link_info
79 /* General link information. */
80 struct bfd_link_info
*info
;
83 /* Hash table for long symbol names. */
84 struct bfd_strtab_hash
*strtab
;
85 /* Array of information kept for each output section, indexed by the
86 target_index field. */
87 struct xcoff_link_section_info
*section_info
;
88 /* Symbol index of last C_FILE symbol (-1 if none). */
90 /* Contents of last C_FILE symbol. */
91 struct internal_syment last_file
;
92 /* Symbol index of TOC symbol. */
94 /* Start of .loader symbols. */
96 /* Next .loader reloc to swap out. */
98 /* File position of start of line numbers. */
99 file_ptr line_filepos
;
100 /* Buffer large enough to hold swapped symbols of any input file. */
101 struct internal_syment
*internal_syms
;
102 /* Buffer large enough to hold output indices of symbols of any
105 /* Buffer large enough to hold output symbols for any input file. */
107 /* Buffer large enough to hold external line numbers for any input
110 /* Buffer large enough to hold any input section. */
112 /* Buffer large enough to hold external relocs of any input section. */
113 bfd_byte
*external_relocs
;
116 static struct bfd_hash_entry
*xcoff_link_hash_newfunc
117 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
118 static boolean xcoff_get_section_contents
PARAMS ((bfd
*, asection
*));
119 static struct internal_reloc
*xcoff_read_internal_relocs
120 PARAMS ((bfd
*, asection
*, boolean
, bfd_byte
*, boolean
,
121 struct internal_reloc
*));
122 static boolean xcoff_link_add_object_symbols
123 PARAMS ((bfd
*, struct bfd_link_info
*));
124 static boolean xcoff_link_check_archive_element
125 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
126 static boolean xcoff_link_check_ar_symbols
127 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
128 static boolean xcoff_link_check_dynamic_ar_symbols
129 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
130 static bfd_size_type xcoff_find_reloc
131 PARAMS ((struct internal_reloc
*, bfd_size_type
, bfd_vma
));
132 static boolean xcoff_link_add_symbols
PARAMS ((bfd
*, struct bfd_link_info
*));
133 static boolean xcoff_link_add_dynamic_symbols
134 PARAMS ((bfd
*, struct bfd_link_info
*));
135 static boolean xcoff_mark_symbol
136 PARAMS ((struct bfd_link_info
*, struct xcoff_link_hash_entry
*));
137 static boolean xcoff_mark
PARAMS ((struct bfd_link_info
*, asection
*));
138 static void xcoff_sweep
PARAMS ((struct bfd_link_info
*));
139 static boolean xcoff_build_ldsyms
140 PARAMS ((struct xcoff_link_hash_entry
*, PTR
));
141 static boolean xcoff_link_input_bfd
142 PARAMS ((struct xcoff_final_link_info
*, bfd
*));
143 static boolean xcoff_write_global_symbol
144 PARAMS ((struct xcoff_link_hash_entry
*, PTR
));
145 static boolean xcoff_reloc_link_order
146 PARAMS ((bfd
*, struct xcoff_final_link_info
*, asection
*,
147 struct bfd_link_order
*));
148 static int xcoff_sort_relocs
PARAMS ((const PTR
, const PTR
));
151 /* Routines to read XCOFF dynamic information. This don't really
152 belong here, but we already have the ldsym manipulation routines
155 /* Read the contents of a section. */
158 xcoff_get_section_contents (abfd
, sec
)
163 if (coff_section_data (abfd
, sec
) == NULL
)
165 bfd_size_type amt
= sizeof (struct coff_section_tdata
);
166 sec
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
167 if (sec
->used_by_bfd
== NULL
)
171 if (coff_section_data (abfd
, sec
)->contents
== NULL
)
173 coff_section_data (abfd
, sec
)->contents
= ((bfd_byte
*)
174 bfd_malloc (sec
->_raw_size
));
175 if (coff_section_data (abfd
, sec
)->contents
== NULL
)
178 if (! bfd_get_section_contents (abfd
, sec
,
179 coff_section_data (abfd
, sec
)->contents
,
180 (file_ptr
) 0, sec
->_raw_size
))
187 /* Get the size required to hold the dynamic symbols. */
190 _bfd_xcoff_get_dynamic_symtab_upper_bound (abfd
)
195 struct internal_ldhdr ldhdr
;
197 if ((abfd
->flags
& DYNAMIC
) == 0)
199 bfd_set_error (bfd_error_invalid_operation
);
203 lsec
= bfd_get_section_by_name (abfd
, ".loader");
206 bfd_set_error (bfd_error_no_symbols
);
210 if (! xcoff_get_section_contents (abfd
, lsec
))
212 contents
= coff_section_data (abfd
, lsec
)->contents
;
214 bfd_xcoff_swap_ldhdr_in (abfd
, (PTR
) contents
, &ldhdr
);
216 return (ldhdr
.l_nsyms
+ 1) * sizeof (asymbol
*);
219 /* Get the dynamic symbols. */
222 _bfd_xcoff_canonicalize_dynamic_symtab (abfd
, psyms
)
228 struct internal_ldhdr ldhdr
;
230 bfd_byte
*elsym
, *elsymend
;
231 coff_symbol_type
*symbuf
;
233 if ((abfd
->flags
& DYNAMIC
) == 0)
235 bfd_set_error (bfd_error_invalid_operation
);
239 lsec
= bfd_get_section_by_name (abfd
, ".loader");
242 bfd_set_error (bfd_error_no_symbols
);
246 if (! xcoff_get_section_contents (abfd
, lsec
))
248 contents
= coff_section_data (abfd
, lsec
)->contents
;
250 coff_section_data (abfd
, lsec
)->keep_contents
= true;
252 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
254 strings
= (char *) contents
+ ldhdr
.l_stoff
;
256 symbuf
= ((coff_symbol_type
*)
257 bfd_zalloc (abfd
, ldhdr
.l_nsyms
* sizeof (coff_symbol_type
)));
261 elsym
= contents
+ bfd_xcoff_loader_symbol_offset(abfd
, &ldhdr
);
263 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz(abfd
);
264 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz(abfd
), symbuf
++, psyms
++)
266 struct internal_ldsym ldsym
;
268 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
270 symbuf
->symbol
.the_bfd
= abfd
;
272 if (ldsym
._l
._l_l
._l_zeroes
== 0)
273 symbuf
->symbol
.name
= strings
+ ldsym
._l
._l_l
._l_offset
;
278 c
= bfd_alloc (abfd
, (bfd_size_type
) SYMNMLEN
+ 1);
281 memcpy (c
, ldsym
._l
._l_name
, SYMNMLEN
);
283 symbuf
->symbol
.name
= c
;
286 if (ldsym
.l_smclas
== XMC_XO
)
287 symbuf
->symbol
.section
= bfd_abs_section_ptr
;
289 symbuf
->symbol
.section
= coff_section_from_bfd_index (abfd
,
291 symbuf
->symbol
.value
= ldsym
.l_value
- symbuf
->symbol
.section
->vma
;
293 symbuf
->symbol
.flags
= BSF_NO_FLAGS
;
294 if ((ldsym
.l_smtype
& L_EXPORT
) != 0)
295 symbuf
->symbol
.flags
|= BSF_GLOBAL
;
297 /* FIXME: We have no way to record the other information stored
298 with the loader symbol. */
300 *psyms
= (asymbol
*) symbuf
;
305 return ldhdr
.l_nsyms
;
308 /* Get the size required to hold the dynamic relocs. */
311 _bfd_xcoff_get_dynamic_reloc_upper_bound (abfd
)
316 struct internal_ldhdr ldhdr
;
318 if ((abfd
->flags
& DYNAMIC
) == 0)
320 bfd_set_error (bfd_error_invalid_operation
);
324 lsec
= bfd_get_section_by_name (abfd
, ".loader");
327 bfd_set_error (bfd_error_no_symbols
);
331 if (! xcoff_get_section_contents (abfd
, lsec
))
333 contents
= coff_section_data (abfd
, lsec
)->contents
;
335 bfd_xcoff_swap_ldhdr_in (abfd
, (struct external_ldhdr
*) contents
, &ldhdr
);
337 return (ldhdr
.l_nreloc
+ 1) * sizeof (arelent
*);
340 /* Get the dynamic relocs. */
343 _bfd_xcoff_canonicalize_dynamic_reloc (abfd
, prelocs
, syms
)
350 struct internal_ldhdr ldhdr
;
352 bfd_byte
*elrel
, *elrelend
;
354 if ((abfd
->flags
& DYNAMIC
) == 0)
356 bfd_set_error (bfd_error_invalid_operation
);
360 lsec
= bfd_get_section_by_name (abfd
, ".loader");
363 bfd_set_error (bfd_error_no_symbols
);
367 if (! xcoff_get_section_contents (abfd
, lsec
))
369 contents
= coff_section_data (abfd
, lsec
)->contents
;
371 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
373 relbuf
= (arelent
*) bfd_alloc (abfd
, ldhdr
.l_nreloc
* sizeof (arelent
));
377 elrel
= contents
+ bfd_xcoff_loader_reloc_offset(abfd
, &ldhdr
);
379 elrelend
= elrel
+ ldhdr
.l_nreloc
* bfd_xcoff_ldrelsz(abfd
);
380 for (; elrel
< elrelend
; elrel
+= bfd_xcoff_ldrelsz(abfd
), relbuf
++,
383 struct internal_ldrel ldrel
;
385 bfd_xcoff_swap_ldrel_in (abfd
, elrel
, &ldrel
);
387 if (ldrel
.l_symndx
>= 3)
388 relbuf
->sym_ptr_ptr
= syms
+ (ldrel
.l_symndx
- 3);
394 switch (ldrel
.l_symndx
)
410 sec
= bfd_get_section_by_name (abfd
, name
);
413 bfd_set_error (bfd_error_bad_value
);
417 relbuf
->sym_ptr_ptr
= sec
->symbol_ptr_ptr
;
420 relbuf
->address
= ldrel
.l_vaddr
;
423 /* Most dynamic relocs have the same type. FIXME: This is only
424 correct if ldrel.l_rtype == 0. In other cases, we should use
425 a different howto. */
426 relbuf
->howto
= bfd_xcoff_dynamic_reloc_howto(abfd
);
428 /* FIXME: We have no way to record the l_rsecnm field. */
435 return ldhdr
.l_nreloc
;
438 /* Routine to create an entry in an XCOFF link hash table. */
440 static struct bfd_hash_entry
*
441 xcoff_link_hash_newfunc (entry
, table
, string
)
442 struct bfd_hash_entry
*entry
;
443 struct bfd_hash_table
*table
;
446 struct xcoff_link_hash_entry
*ret
= (struct xcoff_link_hash_entry
*) entry
;
448 /* Allocate the structure if it has not already been allocated by a
450 if (ret
== (struct xcoff_link_hash_entry
*) NULL
)
451 ret
= ((struct xcoff_link_hash_entry
*)
452 bfd_hash_allocate (table
, sizeof (struct xcoff_link_hash_entry
)));
453 if (ret
== (struct xcoff_link_hash_entry
*) NULL
)
454 return (struct bfd_hash_entry
*) ret
;
456 /* Call the allocation method of the superclass. */
457 ret
= ((struct xcoff_link_hash_entry
*)
458 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
462 /* Set local fields. */
464 ret
->toc_section
= NULL
;
465 ret
->u
.toc_indx
= -1;
466 ret
->descriptor
= NULL
;
470 ret
->smclas
= XMC_UA
;
473 return (struct bfd_hash_entry
*) ret
;
476 /* Create a XCOFF link hash table. */
478 struct bfd_link_hash_table
*
479 _bfd_xcoff_bfd_link_hash_table_create (abfd
)
482 struct xcoff_link_hash_table
*ret
;
483 bfd_size_type amt
= sizeof (struct xcoff_link_hash_table
);
485 ret
= (struct xcoff_link_hash_table
*) bfd_alloc (abfd
, amt
);
486 if (ret
== (struct xcoff_link_hash_table
*) NULL
)
487 return (struct bfd_link_hash_table
*) NULL
;
488 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
, xcoff_link_hash_newfunc
))
490 bfd_release (abfd
, ret
);
491 return (struct bfd_link_hash_table
*) NULL
;
494 ret
->debug_strtab
= _bfd_xcoff_stringtab_init ();
495 ret
->debug_section
= NULL
;
496 ret
->loader_section
= NULL
;
497 ret
->ldrel_count
= 0;
498 memset (&ret
->ldhdr
, 0, sizeof (struct internal_ldhdr
));
499 ret
->linkage_section
= NULL
;
500 ret
->toc_section
= NULL
;
501 ret
->descriptor_section
= NULL
;
506 memset (ret
->special_sections
, 0, sizeof ret
->special_sections
);
508 /* The linker will always generate a full a.out header. We need to
509 record that fact now, before the sizeof_headers routine could be
511 xcoff_data (abfd
)->full_aouthdr
= true;
517 /* Read internal relocs for an XCOFF csect. This is a wrapper around
518 _bfd_coff_read_internal_relocs which tries to take advantage of any
519 relocs which may have been cached for the enclosing section. */
521 static struct internal_reloc
*
522 xcoff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
523 require_internal
, internal_relocs
)
527 bfd_byte
*external_relocs
;
528 boolean require_internal
;
529 struct internal_reloc
*internal_relocs
;
532 if (coff_section_data (abfd
, sec
) != NULL
533 && coff_section_data (abfd
, sec
)->relocs
== NULL
534 && xcoff_section_data (abfd
, sec
) != NULL
)
538 enclosing
= xcoff_section_data (abfd
, sec
)->enclosing
;
540 if (enclosing
!= NULL
541 && (coff_section_data (abfd
, enclosing
) == NULL
542 || coff_section_data (abfd
, enclosing
)->relocs
== NULL
)
544 && enclosing
->reloc_count
> 0)
546 if (_bfd_coff_read_internal_relocs (abfd
, enclosing
, true,
547 external_relocs
, false,
548 (struct internal_reloc
*) NULL
)
553 if (enclosing
!= NULL
554 && coff_section_data (abfd
, enclosing
) != NULL
555 && coff_section_data (abfd
, enclosing
)->relocs
!= NULL
)
559 off
= ((sec
->rel_filepos
- enclosing
->rel_filepos
)
560 / bfd_coff_relsz (abfd
));
562 if (! require_internal
)
563 return coff_section_data (abfd
, enclosing
)->relocs
+ off
;
564 memcpy (internal_relocs
,
565 coff_section_data (abfd
, enclosing
)->relocs
+ off
,
566 sec
->reloc_count
* sizeof (struct internal_reloc
));
567 return internal_relocs
;
571 return _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
572 require_internal
, internal_relocs
);
575 /* Given an XCOFF BFD, add symbols to the global hash table as
579 _bfd_xcoff_bfd_link_add_symbols (abfd
, info
)
581 struct bfd_link_info
*info
;
584 switch (bfd_get_format (abfd
))
587 return xcoff_link_add_object_symbols (abfd
, info
);
590 /* If the archive has a map, do the usual search. We then need
591 to check the archive for stripped dynamic objects, because
592 they will not appear in the archive map even though they
593 should, perhaps, be included. If the archive has no map, we
594 just consider each object file in turn, since that apparently
595 is what the AIX native linker does. */
596 if (bfd_has_map (abfd
))
598 if (! (_bfd_generic_link_add_archive_symbols
599 (abfd
, info
, xcoff_link_check_archive_element
)))
606 member
= bfd_openr_next_archived_file (abfd
, (bfd
*) NULL
);
607 while (member
!= NULL
)
609 if (bfd_check_format (member
, bfd_object
)
610 && (! bfd_has_map (abfd
)
611 || ((member
->flags
& DYNAMIC
) != 0
612 && (member
->flags
& HAS_SYMS
) == 0)))
616 if (! xcoff_link_check_archive_element (member
, info
, &needed
))
619 member
->archive_pass
= -1;
621 member
= bfd_openr_next_archived_file (abfd
, member
);
628 bfd_set_error (bfd_error_wrong_format
);
633 /* Add symbols from an XCOFF object file. */
636 xcoff_link_add_object_symbols (abfd
, info
)
638 struct bfd_link_info
*info
;
641 if (! _bfd_coff_get_external_symbols (abfd
))
643 if (! xcoff_link_add_symbols (abfd
, info
))
645 if (! info
->keep_memory
)
647 if (! _bfd_coff_free_symbols (abfd
))
653 /* Check a single archive element to see if we need to include it in
654 the link. *PNEEDED is set according to whether this element is
655 needed in the link or not. This is called via
656 _bfd_generic_link_add_archive_symbols. */
659 xcoff_link_check_archive_element (abfd
, info
, pneeded
)
661 struct bfd_link_info
*info
;
665 if (! _bfd_coff_get_external_symbols (abfd
))
668 if (! xcoff_link_check_ar_symbols (abfd
, info
, pneeded
))
673 if (! xcoff_link_add_symbols (abfd
, info
))
677 if (! info
->keep_memory
|| ! *pneeded
)
679 if (! _bfd_coff_free_symbols (abfd
))
686 /* Look through the symbols to see if this object file should be
687 included in the link. */
690 xcoff_link_check_ar_symbols (abfd
, info
, pneeded
)
692 struct bfd_link_info
*info
;
695 bfd_size_type symesz
;
701 if ((abfd
->flags
& DYNAMIC
) != 0
702 && ! info
->static_link
703 && info
->hash
->creator
== abfd
->xvec
)
704 return xcoff_link_check_dynamic_ar_symbols (abfd
, info
, pneeded
);
706 symesz
= bfd_coff_symesz (abfd
);
707 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
708 esym_end
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
709 while (esym
< esym_end
)
711 struct internal_syment sym
;
713 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
715 if (sym
.n_sclass
== C_EXT
&& sym
.n_scnum
!= N_UNDEF
)
718 char buf
[SYMNMLEN
+ 1];
719 struct bfd_link_hash_entry
*h
;
721 /* This symbol is externally visible, and is defined by this
724 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
728 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
730 /* We are only interested in symbols that are currently
731 undefined. If a symbol is currently known to be common,
732 XCOFF linkers do not bring in an object file which
733 defines it. We also don't bring in symbols to satisfy
734 undefined references in shared objects. */
735 if (h
!= (struct bfd_link_hash_entry
*) NULL
736 && h
->type
== bfd_link_hash_undefined
737 && (info
->hash
->creator
!= abfd
->xvec
738 || (((struct xcoff_link_hash_entry
*) h
)->flags
739 & XCOFF_DEF_DYNAMIC
) == 0))
741 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
748 esym
+= (sym
.n_numaux
+ 1) * symesz
;
751 /* We do not need this object file. */
755 /* Look through the loader symbols to see if this dynamic object
756 should be included in the link. The native linker uses the loader
757 symbols, not the normal symbol table, so we do too. */
760 xcoff_link_check_dynamic_ar_symbols (abfd
, info
, pneeded
)
762 struct bfd_link_info
*info
;
767 struct internal_ldhdr ldhdr
;
769 bfd_byte
*elsym
, *elsymend
;
773 lsec
= bfd_get_section_by_name (abfd
, ".loader");
776 /* There are no symbols, so don't try to include it. */
780 if (! xcoff_get_section_contents (abfd
, lsec
))
782 contents
= coff_section_data (abfd
, lsec
)->contents
;
784 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
786 strings
= (char *) contents
+ ldhdr
.l_stoff
;
788 elsym
= contents
+ bfd_xcoff_loader_symbol_offset(abfd
, &ldhdr
);
790 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz(abfd
);
791 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz(abfd
))
793 struct internal_ldsym ldsym
;
794 char nambuf
[SYMNMLEN
+ 1];
796 struct bfd_link_hash_entry
*h
;
798 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
800 /* We are only interested in exported symbols. */
801 if ((ldsym
.l_smtype
& L_EXPORT
) == 0)
804 if (ldsym
._l
._l_l
._l_zeroes
== 0)
805 name
= strings
+ ldsym
._l
._l_l
._l_offset
;
808 memcpy (nambuf
, ldsym
._l
._l_name
, SYMNMLEN
);
809 nambuf
[SYMNMLEN
] = '\0';
813 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
815 /* We are only interested in symbols that are currently
816 undefined. At this point we know that we are using an XCOFF
819 && h
->type
== bfd_link_hash_undefined
820 && (((struct xcoff_link_hash_entry
*) h
)->flags
821 & XCOFF_DEF_DYNAMIC
) == 0)
823 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
830 /* We do not need this shared object. */
832 if (contents
!= NULL
&& ! coff_section_data (abfd
, lsec
)->keep_contents
)
834 free (coff_section_data (abfd
, lsec
)->contents
);
835 coff_section_data (abfd
, lsec
)->contents
= NULL
;
841 /* Returns the index of reloc in RELOCS with the least address greater
842 than or equal to ADDRESS. The relocs are sorted by address. */
845 xcoff_find_reloc (relocs
, count
, address
)
846 struct internal_reloc
*relocs
;
850 bfd_size_type min
, max
, this;
854 if (count
== 1 && relocs
[0].r_vaddr
< address
)
863 /* Do a binary search over (min,max]. */
864 while (min
+ 1 < max
)
868 this = (max
+ min
) / 2;
869 raddr
= relocs
[this].r_vaddr
;
872 else if (raddr
< address
)
881 if (relocs
[min
].r_vaddr
< address
)
885 && relocs
[min
- 1].r_vaddr
== address
)
892 /* xcoff_link_create_extra_sections
894 Takes care of creating the .loader, .gl, .ds, .debug and sections. */
897 xcoff_link_create_extra_sections(bfd
* abfd
, struct bfd_link_info
*info
)
900 boolean return_value
= false;
902 if (info
->hash
->creator
== abfd
->xvec
)
905 /* We need to build a .loader section, so we do it here. This
906 won't work if we're producing an XCOFF output file with no
907 XCOFF input files. FIXME. */
909 if (xcoff_hash_table (info
)->loader_section
== NULL
)
913 lsec
= bfd_make_section_anyway (abfd
, ".loader");
918 xcoff_hash_table (info
)->loader_section
= lsec
;
919 lsec
->flags
|= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
922 /* Likewise for the linkage section. */
923 if (xcoff_hash_table (info
)->linkage_section
== NULL
)
927 lsec
= bfd_make_section_anyway (abfd
, ".gl");
933 xcoff_hash_table (info
)->linkage_section
= lsec
;
934 lsec
->flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
936 lsec
->alignment_power
= 2;
939 /* Likewise for the TOC section. */
940 if (xcoff_hash_table (info
)->toc_section
== NULL
)
944 tsec
= bfd_make_section_anyway (abfd
, ".tc");
950 xcoff_hash_table (info
)->toc_section
= tsec
;
951 tsec
->flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
953 tsec
->alignment_power
= 2;
956 /* Likewise for the descriptor section. */
957 if (xcoff_hash_table (info
)->descriptor_section
== NULL
)
961 dsec
= bfd_make_section_anyway (abfd
, ".ds");
967 xcoff_hash_table (info
)->descriptor_section
= dsec
;
968 dsec
->flags
|= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
970 dsec
->alignment_power
= 2;
973 /* Likewise for the .debug section. */
974 if (xcoff_hash_table (info
)->debug_section
== NULL
975 && info
->strip
!= strip_all
)
979 dsec
= bfd_make_section_anyway (abfd
, ".debug");
984 xcoff_hash_table (info
)->debug_section
= dsec
;
985 dsec
->flags
|= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
996 /* Add all the symbols from an object file to the hash table.
998 XCOFF is a weird format. A normal XCOFF .o files will have three
999 COFF sections--.text, .data, and .bss--but each COFF section will
1000 contain many csects. These csects are described in the symbol
1001 table. From the linker's point of view, each csect must be
1002 considered a section in its own right. For example, a TOC entry is
1003 handled as a small XMC_TC csect. The linker must be able to merge
1004 different TOC entries together, which means that it must be able to
1005 extract the XMC_TC csects from the .data section of the input .o
1008 From the point of view of our linker, this is, of course, a hideous
1009 nightmare. We cope by actually creating sections for each csect,
1010 and discarding the original sections. We then have to handle the
1011 relocation entries carefully, since the only way to tell which
1012 csect they belong to is to examine the address. */
1015 xcoff_link_add_symbols (abfd
, info
)
1017 struct bfd_link_info
*info
;
1019 unsigned int n_tmask
;
1020 unsigned int n_btshft
;
1021 boolean default_copy
;
1022 bfd_size_type symcount
;
1023 struct xcoff_link_hash_entry
**sym_hash
;
1024 asection
**csect_cache
;
1025 bfd_size_type linesz
;
1027 asection
*last_real
;
1030 unsigned int csect_index
;
1031 asection
*first_csect
;
1032 bfd_size_type symesz
;
1035 struct reloc_info_struct
1037 struct internal_reloc
*relocs
;
1040 } *reloc_info
= NULL
;
1043 keep_syms
= obj_coff_keep_syms (abfd
);
1045 if ((abfd
->flags
& DYNAMIC
) != 0
1046 && ! info
->static_link
)
1048 if (! xcoff_link_add_dynamic_symbols (abfd
, info
))
1054 /* create the loader, toc, gl, ds and debug sections, if needed */
1055 if (false == xcoff_link_create_extra_sections(abfd
, info
))
1060 if ((abfd
->flags
& DYNAMIC
) != 0
1061 && ! info
->static_link
)
1064 n_tmask
= coff_data (abfd
)->local_n_tmask
;
1065 n_btshft
= coff_data (abfd
)->local_n_btshft
;
1067 /* Define macros so that ISFCN, et. al., macros work correctly. */
1068 #define N_TMASK n_tmask
1069 #define N_BTSHFT n_btshft
1071 if (info
->keep_memory
)
1072 default_copy
= false;
1074 default_copy
= true;
1076 symcount
= obj_raw_syment_count (abfd
);
1078 /* We keep a list of the linker hash table entries that correspond
1079 to each external symbol. */
1080 amt
= symcount
* sizeof (struct xcoff_link_hash_entry
*);
1081 sym_hash
= (struct xcoff_link_hash_entry
**) bfd_alloc (abfd
, amt
);
1082 if (sym_hash
== NULL
&& symcount
!= 0)
1084 coff_data (abfd
)->sym_hashes
= (struct coff_link_hash_entry
**) sym_hash
;
1085 memset (sym_hash
, 0, (size_t) amt
);
1087 /* Because of the weird stuff we are doing with XCOFF csects, we can
1088 not easily determine which section a symbol is in, so we store
1089 the information in the tdata for the input file. */
1090 amt
= symcount
* sizeof (asection
*);
1091 csect_cache
= (asection
**) bfd_alloc (abfd
, amt
);
1092 if (csect_cache
== NULL
&& symcount
!= 0)
1094 xcoff_data (abfd
)->csects
= csect_cache
;
1095 memset (csect_cache
, 0, (size_t) amt
);
1097 /* While splitting sections into csects, we need to assign the
1098 relocs correctly. The relocs and the csects must both be in
1099 order by VMA within a given section, so we handle this by
1100 scanning along the relocs as we process the csects. We index
1101 into reloc_info using the section target_index. */
1102 amt
= abfd
->section_count
+ 1;
1103 amt
*= sizeof (struct reloc_info_struct
);
1104 reloc_info
= (struct reloc_info_struct
*) bfd_malloc (amt
);
1105 if (reloc_info
== NULL
)
1107 memset ((PTR
) reloc_info
, 0, (size_t) amt
);
1109 /* Read in the relocs and line numbers for each section. */
1110 linesz
= bfd_coff_linesz (abfd
);
1112 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1116 if ((o
->flags
& SEC_RELOC
) != 0)
1119 reloc_info
[o
->target_index
].relocs
=
1120 xcoff_read_internal_relocs (abfd
, o
, true, (bfd_byte
*) NULL
,
1121 false, (struct internal_reloc
*) NULL
);
1122 amt
= o
->reloc_count
;
1123 amt
*= sizeof (asection
*);
1124 reloc_info
[o
->target_index
].csects
= (asection
**) bfd_malloc (amt
);
1125 if (reloc_info
[o
->target_index
].csects
== NULL
)
1127 memset (reloc_info
[o
->target_index
].csects
, 0, (size_t) amt
);
1131 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1132 && o
->lineno_count
> 0)
1137 amt
= linesz
* o
->lineno_count
;
1138 linenos
= (bfd_byte
*) bfd_malloc (amt
);
1139 if (linenos
== NULL
)
1141 reloc_info
[o
->target_index
].linenos
= linenos
;
1142 if (bfd_seek (abfd
, o
->line_filepos
, SEEK_SET
) != 0
1143 || bfd_bread (linenos
, amt
, abfd
) != amt
)
1150 /* Don't let the linker relocation routines discard the symbols. */
1151 obj_coff_keep_syms (abfd
) = true;
1157 symesz
= bfd_coff_symesz (abfd
);
1158 BFD_ASSERT (symesz
== bfd_coff_auxesz (abfd
));
1159 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
1160 esym_end
= esym
+ symcount
* symesz
;
1162 while (esym
< esym_end
)
1164 struct internal_syment sym
;
1165 union internal_auxent aux
;
1167 char buf
[SYMNMLEN
+ 1];
1172 struct xcoff_link_hash_entry
*set_toc
;
1174 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
1176 /* In this pass we are only interested in symbols with csect
1178 if (sym
.n_sclass
!= C_EXT
&& sym
.n_sclass
!= C_HIDEXT
)
1182 Normally csect is a .pr, .rw etc. created in the loop
1183 If C_FILE or first time, handle special
1185 Advance esym, sym_hash, csect_hash ptr's
1186 Keep track of the last_symndx for the current file. */
1187 if (sym
.n_sclass
== C_FILE
&& csect
!= NULL
)
1189 xcoff_section_data (abfd
, csect
)->last_symndx
=
1191 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1197 *csect_cache
= csect
;
1198 else if (first_csect
== NULL
|| sym
.n_sclass
== C_FILE
)
1199 *csect_cache
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1201 *csect_cache
= NULL
;
1202 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1203 sym_hash
+= sym
.n_numaux
+ 1;
1204 csect_cache
+= sym
.n_numaux
+ 1;
1209 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
1214 /* If this symbol has line number information attached to it,
1215 and we're not stripping it, count the number of entries and
1216 add them to the count for this csect. In the final link pass
1217 we are going to attach line number information by symbol,
1218 rather than by section, in order to more easily handle
1219 garbage collection. */
1220 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1223 && ISFCN (sym
.n_type
))
1226 union internal_auxent auxlin
;
1228 bfd_coff_swap_aux_in (abfd
, (PTR
) (esym
+ symesz
),
1229 sym
.n_type
, sym
.n_sclass
,
1230 0, sym
.n_numaux
, (PTR
) &auxlin
);
1232 if (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
1234 asection
*enclosing
;
1235 bfd_signed_vma linoff
;
1237 enclosing
= xcoff_section_data (abfd
, csect
)->enclosing
;
1238 if (enclosing
== NULL
)
1240 (*_bfd_error_handler
)
1241 (_("%s: `%s' has line numbers but no enclosing section"),
1242 bfd_archive_filename (abfd
), name
);
1243 bfd_set_error (bfd_error_bad_value
);
1246 linoff
= (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
1247 - enclosing
->line_filepos
);
1248 /* explict cast to bfd_signed_vma for compiler */
1249 if (linoff
< (bfd_signed_vma
) (enclosing
->lineno_count
* linesz
))
1251 struct internal_lineno lin
;
1252 bfd_byte
*linpstart
;
1254 linpstart
= (reloc_info
[enclosing
->target_index
].linenos
1256 bfd_coff_swap_lineno_in (abfd
, (PTR
) linpstart
, (PTR
) &lin
);
1258 && ((bfd_size_type
) lin
.l_addr
.l_symndx
1260 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1263 bfd_byte
*linpend
, *linp
;
1265 linpend
= (reloc_info
[enclosing
->target_index
].linenos
1266 + enclosing
->lineno_count
* linesz
);
1267 for (linp
= linpstart
+ linesz
;
1271 bfd_coff_swap_lineno_in (abfd
, (PTR
) linp
,
1273 if (lin
.l_lnno
== 0)
1276 csect
->lineno_count
+= (linp
- linpstart
) / linesz
;
1277 /* The setting of line_filepos will only be
1278 useful if all the line number entries for a
1279 csect are contiguous; this only matters for
1281 if (csect
->line_filepos
== 0)
1282 csect
->line_filepos
=
1283 auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1289 /* Pick up the csect auxiliary information. */
1291 if (sym
.n_numaux
== 0)
1293 (*_bfd_error_handler
)
1294 (_("%s: class %d symbol `%s' has no aux entries"),
1295 bfd_archive_filename (abfd
), sym
.n_sclass
, name
);
1296 bfd_set_error (bfd_error_bad_value
);
1300 bfd_coff_swap_aux_in (abfd
,
1301 (PTR
) (esym
+ symesz
* sym
.n_numaux
),
1302 sym
.n_type
, sym
.n_sclass
,
1303 sym
.n_numaux
- 1, sym
.n_numaux
,
1306 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
1316 (*_bfd_error_handler
)
1317 (_("%s: symbol `%s' has unrecognized csect type %d"),
1318 bfd_archive_filename (abfd
), name
, smtyp
);
1319 bfd_set_error (bfd_error_bad_value
);
1323 /* This is an external reference. */
1324 if (sym
.n_sclass
== C_HIDEXT
1325 || sym
.n_scnum
!= N_UNDEF
1326 || aux
.x_csect
.x_scnlen
.l
!= 0)
1328 (*_bfd_error_handler
)
1329 (_("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d"),
1330 bfd_archive_filename (abfd
), name
, sym
.n_sclass
, sym
.n_scnum
,
1331 aux
.x_csect
.x_scnlen
.l
);
1332 bfd_set_error (bfd_error_bad_value
);
1336 /* An XMC_XO external reference is actually a reference to
1337 an absolute location. */
1338 if (aux
.x_csect
.x_smclas
!= XMC_XO
)
1339 section
= bfd_und_section_ptr
;
1342 section
= bfd_abs_section_ptr
;
1343 value
= sym
.n_value
;
1348 /* This is a csect definition. */
1351 xcoff_section_data (abfd
, csect
)->last_symndx
=
1352 ((esym
- (bfd_byte
*) obj_coff_external_syms (abfd
)) / symesz
);
1356 csect_index
= -(unsigned) 1;
1358 /* When we see a TOC anchor, we record the TOC value. */
1359 if (aux
.x_csect
.x_smclas
== XMC_TC0
)
1361 if (sym
.n_sclass
!= C_HIDEXT
1362 || aux
.x_csect
.x_scnlen
.l
!= 0)
1364 (*_bfd_error_handler
)
1365 (_("%s: XMC_TC0 symbol `%s' is class %d scnlen %d"),
1366 bfd_archive_filename (abfd
), name
, sym
.n_sclass
,
1367 aux
.x_csect
.x_scnlen
.l
);
1368 bfd_set_error (bfd_error_bad_value
);
1371 xcoff_data (abfd
)->toc
= sym
.n_value
;
1374 /* We must merge TOC entries for the same symbol. We can
1375 merge two TOC entries if they are both C_HIDEXT, they
1376 both have the same name, they are both 4 or 8 bytes long, and
1377 they both have a relocation table entry for an external
1378 symbol with the same name. Unfortunately, this means
1379 that we must look through the relocations. Ick.
1381 Logic for 32 bit vs 64 bit.
1382 32 bit has a csect length of 4 for TOC
1383 64 bit has a csect length of 8 for TOC
1385 The conditions to get past the if-check are not that bad.
1386 They are what is used to create the TOC csects in the first
1388 if (aux
.x_csect
.x_smclas
== XMC_TC
1389 && sym
.n_sclass
== C_HIDEXT
1390 && info
->hash
->creator
== abfd
->xvec
1391 && ((bfd_xcoff_is_xcoff32 (abfd
)
1392 && aux
.x_csect
.x_scnlen
.l
== 4)
1393 || (bfd_xcoff_is_xcoff64 (abfd
)
1394 && aux
.x_csect
.x_scnlen
.l
== 8)))
1396 asection
*enclosing
;
1397 struct internal_reloc
*relocs
;
1398 bfd_size_type relindx
;
1399 struct internal_reloc
*rel
;
1401 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1402 if (enclosing
== NULL
)
1405 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1406 amt
= enclosing
->reloc_count
;
1407 relindx
= xcoff_find_reloc (relocs
, amt
, sym
.n_value
);
1408 rel
= relocs
+ relindx
;
1410 /* 32 bit R_POS r_size is 31
1411 64 bit R_POS r_size is 63 */
1412 if (relindx
< enclosing
->reloc_count
1413 && rel
->r_vaddr
== (bfd_vma
) sym
.n_value
1414 && rel
->r_type
== R_POS
1415 && ((bfd_xcoff_is_xcoff32 (abfd
)
1416 && rel
->r_size
== 31)
1417 || (bfd_xcoff_is_xcoff64 (abfd
)
1418 && rel
->r_size
== 63)))
1422 struct internal_syment relsym
;
1424 erelsym
= ((bfd_byte
*) obj_coff_external_syms (abfd
)
1425 + rel
->r_symndx
* symesz
);
1426 bfd_coff_swap_sym_in (abfd
, (PTR
) erelsym
, (PTR
) &relsym
);
1427 if (relsym
.n_sclass
== C_EXT
)
1429 const char *relname
;
1430 char relbuf
[SYMNMLEN
+ 1];
1432 struct xcoff_link_hash_entry
*h
;
1434 /* At this point we know that the TOC entry is
1435 for an externally visible symbol. */
1437 relname
= _bfd_coff_internal_syment_name (abfd
, &relsym
,
1439 if (relname
== NULL
)
1442 /* We only merge TOC entries if the TC name is
1443 the same as the symbol name. This handles
1444 the normal case, but not common cases like
1445 SYM.P4 which gcc generates to store SYM + 4
1446 in the TOC. FIXME. */
1448 if (strcmp (name
, relname
) == 0)
1450 copy
= (! info
->keep_memory
1451 || relsym
._n
._n_n
._n_zeroes
!= 0
1452 || relsym
._n
._n_n
._n_offset
== 0);
1453 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1454 relname
, true, copy
,
1459 /* At this point h->root.type could be
1460 bfd_link_hash_new. That should be OK,
1461 since we know for sure that we will come
1462 across this symbol as we step through the
1465 /* We store h in *sym_hash for the
1466 convenience of the relocate_section
1470 if (h
->toc_section
!= NULL
)
1472 asection
**rel_csects
;
1474 /* We already have a TOC entry for this
1475 symbol, so we can just ignore this
1478 reloc_info
[enclosing
->target_index
].csects
;
1479 rel_csects
[relindx
] = bfd_und_section_ptr
;
1483 /* We are about to create a TOC entry for
1486 } /* merge toc reloc */
1493 asection
*enclosing
;
1495 /* We need to create a new section. We get the name from
1496 the csect storage mapping class, so that the linker can
1497 accumulate similar csects together. */
1499 csect
= bfd_xcoff_create_csect_from_smclas(abfd
, &aux
, name
);
1505 /* The enclosing section is the main section : .data, .text
1506 or .bss that the csect is coming from. */
1507 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1508 if (enclosing
== NULL
)
1511 if (! bfd_is_abs_section (enclosing
)
1512 && ((bfd_vma
) sym
.n_value
< enclosing
->vma
1513 || ((bfd_vma
) sym
.n_value
+ aux
.x_csect
.x_scnlen
.l
1514 > enclosing
->vma
+ enclosing
->_raw_size
)))
1516 (*_bfd_error_handler
)
1517 (_("%s: csect `%s' not in enclosing section"),
1518 bfd_archive_filename (abfd
), name
);
1519 bfd_set_error (bfd_error_bad_value
);
1522 csect
->vma
= sym
.n_value
;
1523 csect
->filepos
= (enclosing
->filepos
1526 csect
->_raw_size
= aux
.x_csect
.x_scnlen
.l
;
1527 csect
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
1528 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1530 /* Record the enclosing section in the tdata for this new
1532 amt
= sizeof (struct coff_section_tdata
);
1533 csect
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
1534 if (csect
->used_by_bfd
== NULL
)
1536 amt
= sizeof (struct xcoff_section_tdata
);
1537 coff_section_data (abfd
, csect
)->tdata
= bfd_zalloc (abfd
, amt
);
1538 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1540 xcoff_section_data (abfd
, csect
)->enclosing
= enclosing
;
1541 xcoff_section_data (abfd
, csect
)->lineno_count
=
1542 enclosing
->lineno_count
;
1544 if (enclosing
->owner
== abfd
)
1546 struct internal_reloc
*relocs
;
1547 bfd_size_type relindx
;
1548 struct internal_reloc
*rel
;
1549 asection
**rel_csect
;
1551 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1552 amt
= enclosing
->reloc_count
;
1553 relindx
= xcoff_find_reloc (relocs
, amt
, csect
->vma
);
1555 rel
= relocs
+ relindx
;
1556 rel_csect
= (reloc_info
[enclosing
->target_index
].csects
1559 csect
->rel_filepos
= (enclosing
->rel_filepos
1560 + relindx
* bfd_coff_relsz (abfd
));
1561 while (relindx
< enclosing
->reloc_count
1562 && *rel_csect
== NULL
1563 && rel
->r_vaddr
< csect
->vma
+ csect
->_raw_size
)
1567 csect
->flags
|= SEC_RELOC
;
1568 ++csect
->reloc_count
;
1575 /* There are a number of other fields and section flags
1576 which we do not bother to set. */
1578 csect_index
= ((esym
1579 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1582 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1584 if (first_csect
== NULL
)
1585 first_csect
= csect
;
1587 /* If this symbol is C_EXT, we treat it as starting at the
1588 beginning of the newly created section. */
1589 if (sym
.n_sclass
== C_EXT
)
1595 /* If this is a TOC section for a symbol, record it. */
1596 if (set_toc
!= NULL
)
1597 set_toc
->toc_section
= csect
;
1602 /* This is a label definition. The x_scnlen field is the
1603 symbol index of the csect. Usually the XTY_LD symbol will
1604 follow its appropriate XTY_SD symbol. The .set pseudo op can
1605 cause the XTY_LD to not follow the XTY_SD symbol. */
1610 if (aux
.x_csect
.x_scnlen
.l
< 0
1611 || (aux
.x_csect
.x_scnlen
.l
1612 >= esym
- (bfd_byte
*) obj_coff_external_syms (abfd
)))
1616 section
= xcoff_data (abfd
)->csects
[aux
.x_csect
.x_scnlen
.l
];
1618 || (section
->flags
& SEC_HAS_CONTENTS
) == 0)
1623 (*_bfd_error_handler
)
1624 (_("%s: misplaced XTY_LD `%s'"),
1625 bfd_archive_filename (abfd
), name
);
1626 bfd_set_error (bfd_error_bad_value
);
1630 value
= sym
.n_value
- csect
->vma
;
1635 /* This is an unitialized csect. We could base the name on
1636 the storage mapping class, but we don't bother except for
1637 an XMC_TD symbol. If this csect is externally visible,
1638 it is a common symbol. We put XMC_TD symbols in sections
1639 named .tocbss, and rely on the linker script to put that
1644 xcoff_section_data (abfd
, csect
)->last_symndx
=
1646 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1650 if (aux
.x_csect
.x_smclas
== XMC_TD
)
1652 /* The linker script puts the .td section in the data
1653 section after the .tc section. */
1654 csect
= bfd_make_section_anyway (abfd
, ".td");
1659 csect
= bfd_make_section_anyway (abfd
, ".bss");
1663 csect
->vma
= sym
.n_value
;
1664 csect
->_raw_size
= aux
.x_csect
.x_scnlen
.l
;
1665 csect
->flags
|= SEC_ALLOC
;
1666 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1667 /* There are a number of other fields and section flags
1668 which we do not bother to set. */
1670 csect_index
= ((esym
1671 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1674 amt
= sizeof (struct coff_section_tdata
);
1675 csect
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
1676 if (csect
->used_by_bfd
== NULL
)
1678 amt
= sizeof (struct xcoff_section_tdata
);
1679 coff_section_data (abfd
, csect
)->tdata
= bfd_zalloc (abfd
, amt
);
1680 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1682 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1684 if (first_csect
== NULL
)
1685 first_csect
= csect
;
1687 if (sym
.n_sclass
== C_EXT
)
1689 csect
->flags
|= SEC_IS_COMMON
;
1690 csect
->_raw_size
= 0;
1692 value
= aux
.x_csect
.x_scnlen
.l
;
1698 /* Check for magic symbol names. */
1699 if ((smtyp
== XTY_SD
|| smtyp
== XTY_CM
)
1700 && aux
.x_csect
.x_smclas
!= XMC_TC
1701 && aux
.x_csect
.x_smclas
!= XMC_TD
)
1708 if (strcmp (name
, "_text") == 0)
1709 i
= XCOFF_SPECIAL_SECTION_TEXT
;
1710 else if (strcmp (name
, "_etext") == 0)
1711 i
= XCOFF_SPECIAL_SECTION_ETEXT
;
1712 else if (strcmp (name
, "_data") == 0)
1713 i
= XCOFF_SPECIAL_SECTION_DATA
;
1714 else if (strcmp (name
, "_edata") == 0)
1715 i
= XCOFF_SPECIAL_SECTION_EDATA
;
1716 else if (strcmp (name
, "_end") == 0)
1717 i
= XCOFF_SPECIAL_SECTION_END
;
1719 else if (name
[0] == 'e' && strcmp (name
, "end") == 0)
1721 i
= XCOFF_SPECIAL_SECTION_END2
;
1726 xcoff_hash_table (info
)->special_sections
[i
] = csect
;
1730 /* Now we have enough information to add the symbol to the
1731 linker hash table. */
1733 if (sym
.n_sclass
== C_EXT
)
1737 BFD_ASSERT (section
!= NULL
);
1739 /* We must copy the name into memory if we got it from the
1740 syment itself, rather than the string table. */
1741 copy
= default_copy
;
1742 if (sym
._n
._n_n
._n_zeroes
!= 0
1743 || sym
._n
._n_n
._n_offset
== 0)
1746 /* The AIX linker appears to only detect multiple symbol
1747 definitions when there is a reference to the symbol. If
1748 a symbol is defined multiple times, and the only
1749 references are from the same object file, the AIX linker
1750 appears to permit it. It does not merge the different
1751 definitions, but handles them independently. On the
1752 other hand, if there is a reference, the linker reports
1755 This matters because the AIX <net/net_globals.h> header
1756 file actually defines an initialized array, so we have to
1757 actually permit that to work.
1759 Just to make matters even more confusing, the AIX linker
1760 appears to permit multiple symbol definitions whenever
1761 the second definition is in an archive rather than an
1762 object file. This may be a consequence of the manner in
1763 which it handles archives: I think it may load the entire
1764 archive in as separate csects, and then let garbage
1765 collection discard symbols.
1767 We also have to handle the case of statically linking a
1768 shared object, which will cause symbol redefinitions,
1769 although this is an easier case to detect. */
1771 if (info
->hash
->creator
== abfd
->xvec
)
1773 if (! bfd_is_und_section (section
))
1774 *sym_hash
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1775 name
, true, copy
, false);
1777 *sym_hash
= ((struct xcoff_link_hash_entry
*)
1778 bfd_wrapped_link_hash_lookup (abfd
, info
, name
,
1779 true, copy
, false));
1780 if (*sym_hash
== NULL
)
1782 if (((*sym_hash
)->root
.type
== bfd_link_hash_defined
1783 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1784 && ! bfd_is_und_section (section
)
1785 && ! bfd_is_com_section (section
))
1787 /* This is a second definition of a defined symbol. */
1788 if ((abfd
->flags
& DYNAMIC
) != 0
1789 && ((*sym_hash
)->smclas
!= XMC_GL
1790 || aux
.x_csect
.x_smclas
== XMC_GL
1791 || ((*sym_hash
)->root
.u
.def
.section
->owner
->flags
1794 /* The new symbol is from a shared library, and
1795 either the existing symbol is not global
1796 linkage code or this symbol is global linkage
1797 code. If the existing symbol is global
1798 linkage code and the new symbol is not, then
1799 we want to use the new symbol. */
1800 section
= bfd_und_section_ptr
;
1803 else if (((*sym_hash
)->root
.u
.def
.section
->owner
->flags
1806 /* The existing symbol is from a shared library.
1808 (*sym_hash
)->root
.type
= bfd_link_hash_undefined
;
1809 (*sym_hash
)->root
.u
.undef
.abfd
=
1810 (*sym_hash
)->root
.u
.def
.section
->owner
;
1812 else if (abfd
->my_archive
!= NULL
)
1814 /* This is a redefinition in an object contained
1815 in an archive. Just ignore it. See the
1817 section
= bfd_und_section_ptr
;
1820 else if ((*sym_hash
)->root
.next
!= NULL
1821 || info
->hash
->undefs_tail
== &(*sym_hash
)->root
)
1823 /* This symbol has been referenced. In this
1824 case, we just continue and permit the
1825 multiple definition error. See the comment
1826 above about the behaviour of the AIX linker. */
1828 else if ((*sym_hash
)->smclas
== aux
.x_csect
.x_smclas
)
1830 /* The symbols are both csects of the same
1831 class. There is at least a chance that this
1832 is a semi-legitimate redefinition. */
1833 section
= bfd_und_section_ptr
;
1835 (*sym_hash
)->flags
|= XCOFF_MULTIPLY_DEFINED
;
1838 else if (((*sym_hash
)->flags
& XCOFF_MULTIPLY_DEFINED
) != 0
1839 && ((*sym_hash
)->root
.type
== bfd_link_hash_defined
1840 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1841 && (bfd_is_und_section (section
)
1842 || bfd_is_com_section (section
)))
1844 /* This is a reference to a multiply defined symbol.
1845 Report the error now. See the comment above
1846 about the behaviour of the AIX linker. We could
1847 also do this with warning symbols, but I'm not
1848 sure the XCOFF linker is wholly prepared to
1849 handle them, and that would only be a warning,
1851 if (! ((*info
->callbacks
->multiple_definition
)
1852 (info
, (*sym_hash
)->root
.root
.string
,
1853 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0,
1854 (*sym_hash
)->root
.u
.def
.section
->owner
,
1855 (*sym_hash
)->root
.u
.def
.section
,
1856 (*sym_hash
)->root
.u
.def
.value
)))
1858 /* Try not to give this error too many times. */
1859 (*sym_hash
)->flags
&= ~XCOFF_MULTIPLY_DEFINED
;
1863 /* _bfd_generic_link_add_one_symbol may call the linker to
1864 generate an error message, and the linker may try to read
1865 the symbol table to give a good error. Right now, the
1866 line numbers are in an inconsistent state, since they are
1867 counted both in the real sections and in the new csects.
1868 We need to leave the count in the real sections so that
1869 the linker can report the line number of the error
1870 correctly, so temporarily clobber the link to the csects
1871 so that the linker will not try to read the line numbers
1872 a second time from the csects. */
1873 BFD_ASSERT (last_real
->next
== first_csect
);
1874 last_real
->next
= NULL
;
1875 if (! (_bfd_generic_link_add_one_symbol
1876 (info
, abfd
, name
, flags
, section
, value
,
1877 (const char *) NULL
, copy
, true,
1878 (struct bfd_link_hash_entry
**) sym_hash
)))
1880 last_real
->next
= first_csect
;
1882 if (smtyp
== XTY_CM
)
1884 if ((*sym_hash
)->root
.type
!= bfd_link_hash_common
1885 || (*sym_hash
)->root
.u
.c
.p
->section
!= csect
)
1887 /* We don't need the common csect we just created. */
1888 csect
->_raw_size
= 0;
1892 (*sym_hash
)->root
.u
.c
.p
->alignment_power
1893 = csect
->alignment_power
;
1897 if (info
->hash
->creator
== abfd
->xvec
)
1901 if (smtyp
== XTY_ER
|| smtyp
== XTY_CM
)
1902 flag
= XCOFF_REF_REGULAR
;
1904 flag
= XCOFF_DEF_REGULAR
;
1905 (*sym_hash
)->flags
|= flag
;
1907 if ((*sym_hash
)->smclas
== XMC_UA
1908 || flag
== XCOFF_DEF_REGULAR
)
1909 (*sym_hash
)->smclas
= aux
.x_csect
.x_smclas
;
1913 *csect_cache
= csect
;
1915 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1916 sym_hash
+= sym
.n_numaux
+ 1;
1917 csect_cache
+= sym
.n_numaux
+ 1;
1920 BFD_ASSERT (last_real
== NULL
|| last_real
->next
== first_csect
);
1922 /* Make sure that we have seen all the relocs. */
1923 for (o
= abfd
->sections
; o
!= first_csect
; o
= o
->next
)
1925 /* Reset the section size and the line number count, since the
1926 data is now attached to the csects. Don't reset the size of
1927 the .debug section, since we need to read it below in
1928 bfd_xcoff_size_dynamic_sections. */
1929 if (strcmp (bfd_get_section_name (abfd
, o
), ".debug") != 0)
1931 o
->lineno_count
= 0;
1933 if ((o
->flags
& SEC_RELOC
) != 0)
1936 struct internal_reloc
*rel
;
1937 asection
**rel_csect
;
1939 rel
= reloc_info
[o
->target_index
].relocs
;
1940 rel_csect
= reloc_info
[o
->target_index
].csects
;
1942 for (i
= 0; i
< o
->reloc_count
; i
++, rel
++, rel_csect
++)
1945 if (*rel_csect
== NULL
)
1947 (*_bfd_error_handler
)
1948 (_("%s: reloc %s:%d not in csect"),
1949 bfd_archive_filename (abfd
), o
->name
, i
);
1950 bfd_set_error (bfd_error_bad_value
);
1954 /* We identify all symbols which are called, so that we
1955 can create glue code for calls to functions imported
1956 from dynamic objects. */
1957 if (info
->hash
->creator
== abfd
->xvec
1958 && *rel_csect
!= bfd_und_section_ptr
1959 && (rel
->r_type
== R_BR
1960 || rel
->r_type
== R_RBR
)
1961 && obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
] != NULL
)
1963 struct xcoff_link_hash_entry
*h
;
1965 h
= obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
];
1966 h
->flags
|= XCOFF_CALLED
;
1967 /* If the symbol name starts with a period, it is
1968 the code of a function. If the symbol is
1969 currently undefined, then add an undefined symbol
1970 for the function descriptor. This should do no
1971 harm, because any regular object that defines the
1972 function should also define the function
1973 descriptor. It helps, because it means that we
1974 will identify the function descriptor with a
1975 dynamic object if a dynamic object defines it. */
1976 if (h
->root
.root
.string
[0] == '.'
1977 && h
->descriptor
== NULL
)
1979 struct xcoff_link_hash_entry
*hds
;
1981 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1982 h
->root
.root
.string
+ 1,
1986 if (hds
->root
.type
== bfd_link_hash_new
)
1988 if (! (_bfd_generic_link_add_one_symbol
1989 (info
, abfd
, hds
->root
.root
.string
,
1990 (flagword
) 0, bfd_und_section_ptr
,
1991 (bfd_vma
) 0, (const char *) NULL
, false,
1993 (struct bfd_link_hash_entry
**) &hds
)))
1996 hds
->flags
|= XCOFF_DESCRIPTOR
;
1997 BFD_ASSERT ((hds
->flags
& XCOFF_CALLED
) == 0
1998 && (h
->flags
& XCOFF_DESCRIPTOR
) == 0);
1999 hds
->descriptor
= h
;
2000 h
->descriptor
= hds
;
2005 free (reloc_info
[o
->target_index
].csects
);
2006 reloc_info
[o
->target_index
].csects
= NULL
;
2008 /* Reset SEC_RELOC and the reloc_count, since the reloc
2009 information is now attached to the csects. */
2010 o
->flags
&=~ SEC_RELOC
;
2013 /* If we are not keeping memory, free the reloc information. */
2014 if (! info
->keep_memory
2015 && coff_section_data (abfd
, o
) != NULL
2016 && coff_section_data (abfd
, o
)->relocs
!= NULL
2017 && ! coff_section_data (abfd
, o
)->keep_relocs
)
2019 free (coff_section_data (abfd
, o
)->relocs
);
2020 coff_section_data (abfd
, o
)->relocs
= NULL
;
2024 /* Free up the line numbers. FIXME: We could cache these
2025 somewhere for the final link, to avoid reading them again. */
2026 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
2028 free (reloc_info
[o
->target_index
].linenos
);
2029 reloc_info
[o
->target_index
].linenos
= NULL
;
2035 obj_coff_keep_syms (abfd
) = keep_syms
;
2040 if (reloc_info
!= NULL
)
2042 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
2044 if (reloc_info
[o
->target_index
].csects
!= NULL
)
2045 free (reloc_info
[o
->target_index
].csects
);
2046 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
2047 free (reloc_info
[o
->target_index
].linenos
);
2051 obj_coff_keep_syms (abfd
) = keep_syms
;
2058 /* This function is used to add symbols from a dynamic object to the
2059 global symbol table. */
2062 xcoff_link_add_dynamic_symbols (abfd
, info
)
2064 struct bfd_link_info
*info
;
2068 struct internal_ldhdr ldhdr
;
2069 const char *strings
;
2070 bfd_byte
*elsym
, *elsymend
;
2071 struct xcoff_import_file
*n
;
2076 struct xcoff_import_file
**pp
;
2078 /* We can only handle a dynamic object if we are generating an XCOFF
2080 if (info
->hash
->creator
!= abfd
->xvec
)
2082 (*_bfd_error_handler
)
2083 (_("%s: XCOFF shared object when not producing XCOFF output"),
2084 bfd_get_filename (abfd
));
2085 bfd_set_error (bfd_error_invalid_operation
);
2089 /* The symbols we use from a dynamic object are not the symbols in
2090 the normal symbol table, but, rather, the symbols in the export
2091 table. If there is a global symbol in a dynamic object which is
2092 not in the export table, the loader will not be able to find it,
2093 so we don't want to find it either. Also, on AIX 4.1.3, shr.o in
2094 libc.a has symbols in the export table which are not in the
2097 /* Read in the .loader section. FIXME: We should really use the
2098 o_snloader field in the a.out header, rather than grabbing the
2100 lsec
= bfd_get_section_by_name (abfd
, ".loader");
2103 (*_bfd_error_handler
)
2104 (_("%s: dynamic object with no .loader section"),
2105 bfd_get_filename (abfd
));
2106 bfd_set_error (bfd_error_no_symbols
);
2111 if (! xcoff_get_section_contents (abfd
, lsec
))
2113 contents
= coff_section_data (abfd
, lsec
)->contents
;
2115 /* Remove the sections from this object, so that they do not get
2116 included in the link. */
2117 abfd
->sections
= NULL
;
2119 bfd_xcoff_swap_ldhdr_in (abfd
, contents
, &ldhdr
);
2121 strings
= (char *) contents
+ ldhdr
.l_stoff
;
2123 elsym
= contents
+ bfd_xcoff_loader_symbol_offset(abfd
, &ldhdr
);
2125 elsymend
= elsym
+ ldhdr
.l_nsyms
* bfd_xcoff_ldsymsz(abfd
);
2127 for (; elsym
< elsymend
; elsym
+= bfd_xcoff_ldsymsz(abfd
))
2129 struct internal_ldsym ldsym
;
2130 char nambuf
[SYMNMLEN
+ 1];
2132 struct xcoff_link_hash_entry
*h
;
2134 bfd_xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
2136 /* We are only interested in exported symbols. */
2137 if ((ldsym
.l_smtype
& L_EXPORT
) == 0)
2140 if (ldsym
._l
._l_l
._l_zeroes
== 0)
2141 name
= strings
+ ldsym
._l
._l_l
._l_offset
;
2144 memcpy (nambuf
, ldsym
._l
._l_name
, SYMNMLEN
);
2145 nambuf
[SYMNMLEN
] = '\0';
2149 /* Normally we could not call xcoff_link_hash_lookup in an add
2150 symbols routine, since we might not be using an XCOFF hash
2151 table. However, we verified above that we are using an XCOFF
2154 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, true,
2159 h
->flags
|= XCOFF_DEF_DYNAMIC
;
2161 /* If the symbol is undefined, and the BFD it was found in is
2162 not a dynamic object, change the BFD to this dynamic object,
2163 so that we can get the correct import file ID. */
2164 if ((h
->root
.type
== bfd_link_hash_undefined
2165 || h
->root
.type
== bfd_link_hash_undefweak
)
2166 && (h
->root
.u
.undef
.abfd
== NULL
2167 || (h
->root
.u
.undef
.abfd
->flags
& DYNAMIC
) == 0))
2168 h
->root
.u
.undef
.abfd
= abfd
;
2170 if (h
->root
.type
== bfd_link_hash_new
)
2172 h
->root
.type
= bfd_link_hash_undefined
;
2173 h
->root
.u
.undef
.abfd
= abfd
;
2174 /* We do not want to add this to the undefined symbol list. */
2177 if (h
->smclas
== XMC_UA
2178 || h
->root
.type
== bfd_link_hash_undefined
2179 || h
->root
.type
== bfd_link_hash_undefweak
)
2180 h
->smclas
= ldsym
.l_smclas
;
2182 /* Unless this is an XMC_XO symbol, we don't bother to actually
2183 define it, since we don't have a section to put it in anyhow.
2184 Instead, the relocation routines handle the DEF_DYNAMIC flag
2187 if (h
->smclas
== XMC_XO
2188 && (h
->root
.type
== bfd_link_hash_undefined
2189 || h
->root
.type
== bfd_link_hash_undefweak
))
2191 /* This symbol has an absolute value. */
2192 h
->root
.type
= bfd_link_hash_defined
;
2193 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
2194 h
->root
.u
.def
.value
= ldsym
.l_value
;
2197 /* If this symbol defines a function descriptor, then it
2198 implicitly defines the function code as well. */
2199 if (h
->smclas
== XMC_DS
2200 || (h
->smclas
== XMC_XO
&& name
[0] != '.'))
2201 h
->flags
|= XCOFF_DESCRIPTOR
;
2202 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0)
2204 struct xcoff_link_hash_entry
*hds
;
2206 hds
= h
->descriptor
;
2211 dsnm
= bfd_malloc ((bfd_size_type
) strlen (name
) + 2);
2215 strcpy (dsnm
+ 1, name
);
2216 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
), dsnm
,
2222 if (hds
->root
.type
== bfd_link_hash_new
)
2224 hds
->root
.type
= bfd_link_hash_undefined
;
2225 hds
->root
.u
.undef
.abfd
= abfd
;
2226 /* We do not want to add this to the undefined
2230 hds
->descriptor
= h
;
2231 h
->descriptor
= hds
;
2234 hds
->flags
|= XCOFF_DEF_DYNAMIC
;
2235 if (hds
->smclas
== XMC_UA
)
2236 hds
->smclas
= XMC_PR
;
2238 /* An absolute symbol appears to actually define code, not a
2239 function descriptor. This is how some math functions are
2240 implemented on AIX 4.1. */
2241 if (h
->smclas
== XMC_XO
2242 && (hds
->root
.type
== bfd_link_hash_undefined
2243 || hds
->root
.type
== bfd_link_hash_undefweak
))
2245 hds
->smclas
= XMC_XO
;
2246 hds
->root
.type
= bfd_link_hash_defined
;
2247 hds
->root
.u
.def
.section
= bfd_abs_section_ptr
;
2248 hds
->root
.u
.def
.value
= ldsym
.l_value
;
2253 if (contents
!= NULL
&& ! coff_section_data (abfd
, lsec
)->keep_contents
)
2255 free (coff_section_data (abfd
, lsec
)->contents
);
2256 coff_section_data (abfd
, lsec
)->contents
= NULL
;
2259 /* Record this file in the import files. */
2261 n
= ((struct xcoff_import_file
*)
2262 bfd_alloc (abfd
, (bfd_size_type
) sizeof (struct xcoff_import_file
)));
2267 /* For some reason, the path entry in the import file list for a
2268 shared object appears to always be empty. The file name is the
2271 if (abfd
->my_archive
== NULL
)
2273 bname
= bfd_get_filename (abfd
);
2278 bname
= bfd_get_filename (abfd
->my_archive
);
2279 mname
= bfd_get_filename (abfd
);
2281 s
= strrchr (bname
, '/');
2287 /* We start c at 1 because the first import file number is reserved
2289 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
2291 pp
= &(*pp
)->next
, ++c
)
2295 xcoff_data (abfd
)->import_file_id
= c
;
2300 /* Routines that are called after all the input files have been
2301 handled, but before the sections are laid out in memory. */
2303 /* Mark a symbol as not being garbage, including the section in which
2306 static INLINE boolean
2307 xcoff_mark_symbol (info
, h
)
2308 struct bfd_link_info
*info
;
2309 struct xcoff_link_hash_entry
*h
;
2312 if ((h
->flags
& XCOFF_MARK
) != 0)
2315 h
->flags
|= XCOFF_MARK
;
2316 if (h
->root
.type
== bfd_link_hash_defined
2317 || h
->root
.type
== bfd_link_hash_defweak
)
2321 hsec
= h
->root
.u
.def
.section
;
2322 if (! bfd_is_abs_section (hsec
)
2323 && (hsec
->flags
& SEC_MARK
) == 0)
2325 if (! xcoff_mark (info
, hsec
))
2330 if (h
->toc_section
!= NULL
2331 && (h
->toc_section
->flags
& SEC_MARK
) == 0)
2333 if (! xcoff_mark (info
, h
->toc_section
))
2340 /* The mark phase of garbage collection. For a given section, mark
2341 it, and all the sections which define symbols to which it refers.
2342 Because this function needs to look at the relocs, we also count
2343 the number of relocs which need to be copied into the .loader
2347 xcoff_mark (info
, sec
)
2348 struct bfd_link_info
*info
;
2351 if (bfd_is_abs_section (sec
)
2352 || (sec
->flags
& SEC_MARK
) != 0)
2355 sec
->flags
|= SEC_MARK
;
2357 if (sec
->owner
->xvec
== info
->hash
->creator
2358 && coff_section_data (sec
->owner
, sec
) != NULL
2359 && xcoff_section_data (sec
->owner
, sec
) != NULL
)
2361 register struct xcoff_link_hash_entry
**hp
, **hpend
;
2362 struct internal_reloc
*rel
, *relend
;
2364 /* Mark all the symbols in this section. */
2366 hp
= (obj_xcoff_sym_hashes (sec
->owner
)
2367 + xcoff_section_data (sec
->owner
, sec
)->first_symndx
);
2368 hpend
= (obj_xcoff_sym_hashes (sec
->owner
)
2369 + xcoff_section_data (sec
->owner
, sec
)->last_symndx
);
2370 for (; hp
< hpend
; hp
++)
2372 register struct xcoff_link_hash_entry
*h
;
2376 && (h
->flags
& XCOFF_MARK
) == 0)
2378 if (! xcoff_mark_symbol (info
, h
))
2383 /* Look through the section relocs. */
2385 if ((sec
->flags
& SEC_RELOC
) != 0
2386 && sec
->reloc_count
> 0)
2388 rel
= xcoff_read_internal_relocs (sec
->owner
, sec
, true,
2389 (bfd_byte
*) NULL
, false,
2390 (struct internal_reloc
*) NULL
);
2393 relend
= rel
+ sec
->reloc_count
;
2394 for (; rel
< relend
; rel
++)
2397 struct xcoff_link_hash_entry
*h
;
2399 if ((unsigned int) rel
->r_symndx
2400 > obj_raw_syment_count (sec
->owner
))
2403 h
= obj_xcoff_sym_hashes (sec
->owner
)[rel
->r_symndx
];
2405 && (h
->flags
& XCOFF_MARK
) == 0)
2407 if (! xcoff_mark_symbol (info
, h
))
2411 rsec
= xcoff_data (sec
->owner
)->csects
[rel
->r_symndx
];
2413 && (rsec
->flags
& SEC_MARK
) == 0)
2415 if (! xcoff_mark (info
, rsec
))
2419 /* See if this reloc needs to be copied into the .loader
2421 switch (rel
->r_type
)
2425 || h
->root
.type
== bfd_link_hash_defined
2426 || h
->root
.type
== bfd_link_hash_defweak
2427 || h
->root
.type
== bfd_link_hash_common
2428 || ((h
->flags
& XCOFF_CALLED
) != 0
2429 && (h
->root
.type
== bfd_link_hash_undefined
2430 || h
->root
.type
== bfd_link_hash_undefweak
)
2431 && h
->root
.root
.string
[0] == '.'
2432 && h
->descriptor
!= NULL
2433 && ((h
->descriptor
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2434 || ((h
->descriptor
->flags
& XCOFF_IMPORT
) != 0
2435 && (h
->descriptor
->flags
2436 & XCOFF_DEF_REGULAR
) == 0))))
2443 ++xcoff_hash_table (info
)->ldrel_count
;
2445 h
->flags
|= XCOFF_LDREL
;
2452 /* We should never need a .loader reloc for a TOC
2458 if (! info
->keep_memory
2459 && coff_section_data (sec
->owner
, sec
) != NULL
2460 && coff_section_data (sec
->owner
, sec
)->relocs
!= NULL
2461 && ! coff_section_data (sec
->owner
, sec
)->keep_relocs
)
2463 free (coff_section_data (sec
->owner
, sec
)->relocs
);
2464 coff_section_data (sec
->owner
, sec
)->relocs
= NULL
;
2472 /* The sweep phase of garbage collection. Remove all garbage
2477 struct bfd_link_info
*info
;
2481 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2485 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2487 if ((o
->flags
& SEC_MARK
) == 0)
2489 /* Keep all sections from non-XCOFF input files. Keep
2490 special sections. Keep .debug sections for the
2492 if (sub
->xvec
!= info
->hash
->creator
2493 || o
== xcoff_hash_table (info
)->debug_section
2494 || o
== xcoff_hash_table (info
)->loader_section
2495 || o
== xcoff_hash_table (info
)->linkage_section
2496 || o
== xcoff_hash_table (info
)->toc_section
2497 || o
== xcoff_hash_table (info
)->descriptor_section
2498 || strcmp (o
->name
, ".debug") == 0)
2499 o
->flags
|= SEC_MARK
;
2504 o
->lineno_count
= 0;
2511 /* Record the number of elements in a set. This is used to output the
2512 correct csect length. */
2515 bfd_xcoff_link_record_set (output_bfd
, info
, harg
, size
)
2517 struct bfd_link_info
*info
;
2518 struct bfd_link_hash_entry
*harg
;
2521 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2522 struct xcoff_link_size_list
*n
;
2525 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2528 /* This will hardly ever be called. I don't want to burn four bytes
2529 per global symbol, so instead the size is kept on a linked list
2530 attached to the hash table. */
2532 amt
= sizeof (struct xcoff_link_size_list
);
2533 n
= (struct xcoff_link_size_list
*) bfd_alloc (output_bfd
, amt
);
2536 n
->next
= xcoff_hash_table (info
)->size_list
;
2539 xcoff_hash_table (info
)->size_list
= n
;
2541 h
->flags
|= XCOFF_HAS_SIZE
;
2546 /* Import a symbol. */
2549 bfd_xcoff_import_symbol (output_bfd
, info
, harg
, val
, imppath
, impfile
,
2550 impmember
, syscall_flag
)
2552 struct bfd_link_info
*info
;
2553 struct bfd_link_hash_entry
*harg
;
2555 const char *imppath
;
2556 const char *impfile
;
2557 const char *impmember
;
2558 unsigned int syscall_flag
;
2560 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2562 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2565 /* A symbol name which starts with a period is the code for a
2566 function. If the symbol is undefined, then add an undefined
2567 symbol for the function descriptor, and import that instead. */
2568 if (h
->root
.root
.string
[0] == '.'
2569 && h
->root
.type
== bfd_link_hash_undefined
2570 && val
== (bfd_vma
) -1)
2572 struct xcoff_link_hash_entry
*hds
;
2574 hds
= h
->descriptor
;
2577 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
2578 h
->root
.root
.string
+ 1,
2582 if (hds
->root
.type
== bfd_link_hash_new
)
2584 hds
->root
.type
= bfd_link_hash_undefined
;
2585 hds
->root
.u
.undef
.abfd
= h
->root
.u
.undef
.abfd
;
2587 hds
->flags
|= XCOFF_DESCRIPTOR
;
2588 BFD_ASSERT ((hds
->flags
& XCOFF_CALLED
) == 0
2589 && (h
->flags
& XCOFF_DESCRIPTOR
) == 0);
2590 hds
->descriptor
= h
;
2591 h
->descriptor
= hds
;
2594 /* Now, if the descriptor is undefined, import the descriptor
2595 rather than the symbol we were told to import. FIXME: Is
2596 this correct in all cases? */
2597 if (hds
->root
.type
== bfd_link_hash_undefined
)
2601 h
->flags
|= (XCOFF_IMPORT
| syscall_flag
);
2603 if (val
!= (bfd_vma
) -1)
2605 if (h
->root
.type
== bfd_link_hash_defined
2606 && (! bfd_is_abs_section (h
->root
.u
.def
.section
)
2607 || h
->root
.u
.def
.value
!= val
))
2609 if (! ((*info
->callbacks
->multiple_definition
)
2610 (info
, h
->root
.root
.string
, h
->root
.u
.def
.section
->owner
,
2611 h
->root
.u
.def
.section
, h
->root
.u
.def
.value
,
2612 output_bfd
, bfd_abs_section_ptr
, val
)))
2616 h
->root
.type
= bfd_link_hash_defined
;
2617 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
2618 h
->root
.u
.def
.value
= val
;
2621 /* We overload the ldindx field to hold the l_ifile value for this
2623 BFD_ASSERT (h
->ldsym
== NULL
);
2624 BFD_ASSERT ((h
->flags
& XCOFF_BUILT_LDSYM
) == 0);
2625 if (imppath
== NULL
)
2630 struct xcoff_import_file
**pp
;
2632 /* We start c at 1 because the first entry in the import list is
2633 reserved for the library search path. */
2634 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
2636 pp
= &(*pp
)->next
, ++c
)
2638 if (strcmp ((*pp
)->path
, imppath
) == 0
2639 && strcmp ((*pp
)->file
, impfile
) == 0
2640 && strcmp ((*pp
)->member
, impmember
) == 0)
2646 struct xcoff_import_file
*n
;
2647 bfd_size_type amt
= sizeof (struct xcoff_import_file
);
2649 n
= (struct xcoff_import_file
*) bfd_alloc (output_bfd
, amt
);
2655 n
->member
= impmember
;
2665 /* Export a symbol. */
2668 bfd_xcoff_export_symbol (output_bfd
, info
, harg
)
2670 struct bfd_link_info
*info
;
2671 struct bfd_link_hash_entry
*harg
;
2673 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2675 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2678 h
->flags
|= XCOFF_EXPORT
;
2680 /* FIXME: I'm not at all sure what syscall is supposed to mean, so
2681 I'm just going to ignore it until somebody explains it. */
2683 /* See if this is a function descriptor. It may be one even though
2684 it is not so marked. */
2685 if ((h
->flags
& XCOFF_DESCRIPTOR
) == 0
2686 && h
->root
.root
.string
[0] != '.')
2689 struct xcoff_link_hash_entry
*hfn
;
2690 bfd_size_type amt
= strlen (h
->root
.root
.string
) + 2;
2692 fnname
= (char *) bfd_malloc (amt
);
2696 strcpy (fnname
+ 1, h
->root
.root
.string
);
2697 hfn
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
2698 fnname
, false, false, true);
2701 && hfn
->smclas
== XMC_PR
2702 && (hfn
->root
.type
== bfd_link_hash_defined
2703 || hfn
->root
.type
== bfd_link_hash_defweak
))
2705 h
->flags
|= XCOFF_DESCRIPTOR
;
2706 h
->descriptor
= hfn
;
2707 hfn
->descriptor
= h
;
2711 /* Make sure we don't garbage collect this symbol. */
2712 if (! xcoff_mark_symbol (info
, h
))
2715 /* If this is a function descriptor, make sure we don't garbage
2716 collect the associated function code. We normally don't have to
2717 worry about this, because the descriptor will be attached to a
2718 section with relocs, but if we are creating the descriptor
2719 ourselves those relocs will not be visible to the mark code. */
2720 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0)
2722 if (! xcoff_mark_symbol (info
, h
->descriptor
))
2729 /* Count a reloc against a symbol. This is called for relocs
2730 generated by the linker script, typically for global constructors
2734 bfd_xcoff_link_count_reloc (output_bfd
, info
, name
)
2736 struct bfd_link_info
*info
;
2739 struct xcoff_link_hash_entry
*h
;
2741 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2744 h
= ((struct xcoff_link_hash_entry
*)
2745 bfd_wrapped_link_hash_lookup (output_bfd
, info
, name
, false, false,
2749 (*_bfd_error_handler
) (_("%s: no such symbol"), name
);
2750 bfd_set_error (bfd_error_no_symbols
);
2754 h
->flags
|= XCOFF_REF_REGULAR
| XCOFF_LDREL
;
2755 ++xcoff_hash_table (info
)->ldrel_count
;
2757 /* Mark the symbol to avoid garbage collection. */
2758 if (! xcoff_mark_symbol (info
, h
))
2764 /* This function is called for each symbol to which the linker script
2768 bfd_xcoff_record_link_assignment (output_bfd
, info
, name
)
2770 struct bfd_link_info
*info
;
2773 struct xcoff_link_hash_entry
*h
;
2775 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2778 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, true, true,
2783 h
->flags
|= XCOFF_DEF_REGULAR
;
2788 /* Build the .loader section. This is called by the XCOFF linker
2789 emulation before_allocation routine. We must set the size of the
2790 .loader section before the linker lays out the output file.
2791 LIBPATH is the library path to search for shared objects; this is
2792 normally built from the -L arguments passed to the linker. ENTRY
2793 is the name of the entry point symbol (the -e linker option).
2794 FILE_ALIGN is the alignment to use for sections within the file
2795 (the -H linker option). MAXSTACK is the maximum stack size (the
2796 -bmaxstack linker option). MAXDATA is the maximum data size (the
2797 -bmaxdata linker option). GC is whether to do garbage collection
2798 (the -bgc linker option). MODTYPE is the module type (the
2799 -bmodtype linker option). TEXTRO is whether the text section must
2800 be read only (the -btextro linker option). EXPORT_DEFINEDS is
2801 whether all defined symbols should be exported (the -unix linker
2802 option). SPECIAL_SECTIONS is set by this routine to csects with
2803 magic names like _end. */
2806 bfd_xcoff_size_dynamic_sections (output_bfd
, info
, libpath
, entry
,
2807 file_align
, maxstack
, maxdata
, gc
,
2808 modtype
, textro
, export_defineds
,
2811 struct bfd_link_info
*info
;
2812 const char *libpath
;
2814 unsigned long file_align
;
2815 unsigned long maxstack
;
2816 unsigned long maxdata
;
2820 boolean export_defineds
;
2821 asection
**special_sections
;
2823 struct xcoff_link_hash_entry
*hentry
;
2825 struct xcoff_loader_info ldinfo
;
2827 size_t impsize
, impcount
;
2828 struct xcoff_import_file
*fl
;
2829 struct internal_ldhdr
*ldhdr
;
2830 bfd_size_type stoff
;
2834 struct bfd_strtab_hash
*debug_strtab
;
2835 bfd_byte
*debug_contents
= NULL
;
2838 if (bfd_get_flavour (output_bfd
) != bfd_target_xcoff_flavour
)
2841 for (i
= 0; i
< XCOFF_NUMBER_OF_SPECIAL_SECTIONS
; i
++)
2842 special_sections
[i
] = NULL
;
2846 ldinfo
.failed
= false;
2847 ldinfo
.output_bfd
= output_bfd
;
2849 ldinfo
.export_defineds
= export_defineds
;
2850 ldinfo
.ldsym_count
= 0;
2851 ldinfo
.string_size
= 0;
2852 ldinfo
.strings
= NULL
;
2853 ldinfo
.string_alc
= 0;
2855 xcoff_data (output_bfd
)->maxstack
= maxstack
;
2856 xcoff_data (output_bfd
)->maxdata
= maxdata
;
2857 xcoff_data (output_bfd
)->modtype
= modtype
;
2859 xcoff_hash_table (info
)->file_align
= file_align
;
2860 xcoff_hash_table (info
)->textro
= textro
;
2868 hentry
= xcoff_link_hash_lookup (xcoff_hash_table (info
), entry
,
2869 false, false, true);
2871 hentry
->flags
|= XCOFF_ENTRY
;
2875 if (info
->init_function
|| info
->fini_function
) {
2876 struct xcoff_link_hash_entry
*hrtinit
;
2877 struct internal_ldsym
*ldsym
;
2879 hrtinit
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
2881 false, false, true);
2882 if (hrtinit
!= NULL
)
2884 xcoff_mark_symbol (info
, hrtinit
);
2885 hrtinit
->flags
|= (XCOFF_DEF_REGULAR
| XCOFF_RTINIT
);
2889 (*_bfd_error_handler
)
2890 (_("error: undefined symbol __rtinit"));
2895 /* __rtinit initalized here
2896 Some information, like the location of the .initfini seciton will
2899 name or offset taken care of below with bfd_xcoff_put_ldsymbol_name. */
2900 amt
= sizeof (struct internal_ldsym
);
2901 ldsym
= (struct internal_ldsym
*) bfd_malloc (amt
);
2903 ldsym
->l_value
= 0; /* will be filled in later */
2904 ldsym
->l_scnum
= 2; /* data section */
2905 ldsym
->l_smtype
= XTY_SD
; /* csect section definition */
2906 ldsym
->l_smclas
= 5; /* .rw */
2907 ldsym
->l_ifile
= 0; /* special system loader symbol */
2908 ldsym
->l_parm
= 0; /* NA */
2910 /* Force __rtinit to be the first symbol in the loader symbol table
2911 See xcoff_build_ldsyms
2913 The first 3 symbol table indices are reserved to indicate the data,
2914 text and bss sections. */
2915 BFD_ASSERT (0 == ldinfo
.ldsym_count
);
2917 hrtinit
->ldindx
= 3;
2918 ldinfo
.ldsym_count
= 1;
2919 hrtinit
->ldsym
= ldsym
;
2921 if (false == bfd_xcoff_put_ldsymbol_name (ldinfo
.output_bfd
, &ldinfo
,
2923 hrtinit
->root
.root
.string
))
2928 /* This symbol is written out by xcoff_write_global_symbol
2929 Set stuff up so xcoff_write_global_symbol logic works. */
2930 hrtinit
->flags
|= XCOFF_DEF_REGULAR
| XCOFF_MARK
;
2931 hrtinit
->root
.type
= bfd_link_hash_defined
;
2932 hrtinit
->root
.u
.def
.value
= 0;
2935 /* Garbage collect unused sections. */
2936 if (info
->relocateable
2939 || (hentry
->root
.type
!= bfd_link_hash_defined
2940 && hentry
->root
.type
!= bfd_link_hash_defweak
))
2943 xcoff_hash_table (info
)->gc
= false;
2945 /* We still need to call xcoff_mark, in order to set ldrel_count
2947 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2951 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2953 if ((o
->flags
& SEC_MARK
) == 0)
2955 if (! xcoff_mark (info
, o
))
2963 if (! xcoff_mark (info
, hentry
->root
.u
.def
.section
))
2966 xcoff_hash_table (info
)->gc
= true;
2969 /* Return special sections to the caller. */
2970 for (i
= 0; i
< XCOFF_NUMBER_OF_SPECIAL_SECTIONS
; i
++)
2972 sec
= xcoff_hash_table (info
)->special_sections
[i
];
2976 && (sec
->flags
& SEC_MARK
) == 0)
2980 special_sections
[i
] = sec
;
2983 if (info
->input_bfds
== NULL
)
2985 /* I'm not sure what to do in this bizarre case. */
2989 xcoff_link_hash_traverse (xcoff_hash_table (info
), xcoff_build_ldsyms
,
2994 /* Work out the size of the import file names. Each import file ID
2995 consists of three null terminated strings: the path, the file
2996 name, and the archive member name. The first entry in the list
2997 of names is the path to use to find objects, which the linker has
2998 passed in as the libpath argument. For some reason, the path
2999 entry in the other import file names appears to always be empty. */
3000 impsize
= strlen (libpath
) + 3;
3002 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
3005 impsize
+= (strlen (fl
->path
)
3007 + strlen (fl
->member
)
3011 /* Set up the .loader section header. */
3012 ldhdr
= &xcoff_hash_table (info
)->ldhdr
;
3013 ldhdr
->l_version
= bfd_xcoff_ldhdr_version(output_bfd
);
3014 ldhdr
->l_nsyms
= ldinfo
.ldsym_count
;
3015 ldhdr
->l_nreloc
= xcoff_hash_table (info
)->ldrel_count
;
3016 ldhdr
->l_istlen
= impsize
;
3017 ldhdr
->l_nimpid
= impcount
;
3018 ldhdr
->l_impoff
= (bfd_xcoff_ldhdrsz(output_bfd
)
3019 + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz(output_bfd
)
3020 + ldhdr
->l_nreloc
* bfd_xcoff_ldrelsz(output_bfd
));
3021 ldhdr
->l_stlen
= ldinfo
.string_size
;
3022 stoff
= ldhdr
->l_impoff
+ impsize
;
3023 if (ldinfo
.string_size
== 0)
3026 ldhdr
->l_stoff
= stoff
;
3028 /* 64 bit elements to ldhdr
3029 The swap out routine for 32 bit will ignore them.
3030 Nothing fancy, symbols come after the header and relocs come
3032 ldhdr
->l_symoff
= bfd_xcoff_ldhdrsz (output_bfd
);
3033 ldhdr
->l_rldoff
= (bfd_xcoff_ldhdrsz (output_bfd
)
3034 + ldhdr
->l_nsyms
* bfd_xcoff_ldsymsz (output_bfd
));
3036 /* We now know the final size of the .loader section. Allocate
3038 lsec
= xcoff_hash_table (info
)->loader_section
;
3039 lsec
->_raw_size
= stoff
+ ldhdr
->l_stlen
;
3040 lsec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, lsec
->_raw_size
);
3041 if (lsec
->contents
== NULL
)
3044 /* Set up the header. */
3045 bfd_xcoff_swap_ldhdr_out (output_bfd
, ldhdr
, lsec
->contents
);
3047 /* Set up the import file names. */
3048 out
= (char *) lsec
->contents
+ ldhdr
->l_impoff
;
3049 strcpy (out
, libpath
);
3050 out
+= strlen (libpath
) + 1;
3053 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
3055 register const char *s
;
3058 while ((*out
++ = *s
++) != '\0')
3061 while ((*out
++ = *s
++) != '\0')
3064 while ((*out
++ = *s
++) != '\0')
3068 BFD_ASSERT ((bfd_size_type
) ((bfd_byte
*) out
- lsec
->contents
) == stoff
);
3070 /* Set up the symbol string table. */
3071 if (ldinfo
.string_size
> 0)
3073 memcpy (out
, ldinfo
.strings
, ldinfo
.string_size
);
3074 free (ldinfo
.strings
);
3075 ldinfo
.strings
= NULL
;
3078 /* We can't set up the symbol table or the relocs yet, because we
3079 don't yet know the final position of the various sections. The
3080 .loader symbols are written out when the corresponding normal
3081 symbols are written out in xcoff_link_input_bfd or
3082 xcoff_write_global_symbol. The .loader relocs are written out
3083 when the corresponding normal relocs are handled in
3084 xcoff_link_input_bfd.
3087 /* Allocate space for the magic sections. */
3088 sec
= xcoff_hash_table (info
)->linkage_section
;
3089 if (sec
->_raw_size
> 0)
3091 sec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, sec
->_raw_size
);
3092 if (sec
->contents
== NULL
)
3095 sec
= xcoff_hash_table (info
)->toc_section
;
3096 if (sec
->_raw_size
> 0)
3098 sec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, sec
->_raw_size
);
3099 if (sec
->contents
== NULL
)
3102 sec
= xcoff_hash_table (info
)->descriptor_section
;
3103 if (sec
->_raw_size
> 0)
3105 sec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, sec
->_raw_size
);
3106 if (sec
->contents
== NULL
)
3110 /* Now that we've done garbage collection, figure out the contents
3111 of the .debug section. */
3112 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
3114 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3117 bfd_size_type symcount
;
3118 unsigned long *debug_index
;
3120 bfd_byte
*esym
, *esymend
;
3121 bfd_size_type symesz
;
3123 if (sub
->xvec
!= info
->hash
->creator
)
3125 subdeb
= bfd_get_section_by_name (sub
, ".debug");
3126 if (subdeb
== NULL
|| subdeb
->_raw_size
== 0)
3129 if (info
->strip
== strip_all
3130 || info
->strip
== strip_debugger
3131 || info
->discard
== discard_all
)
3133 subdeb
->_raw_size
= 0;
3137 if (! _bfd_coff_get_external_symbols (sub
))
3140 symcount
= obj_raw_syment_count (sub
);
3141 debug_index
= ((unsigned long *)
3142 bfd_zalloc (sub
, symcount
* sizeof (unsigned long)));
3143 if (debug_index
== NULL
)
3145 xcoff_data (sub
)->debug_indices
= debug_index
;
3147 /* Grab the contents of the .debug section. We use malloc and
3148 copy the names into the debug stringtab, rather than
3149 bfd_alloc, because I expect that, when linking many files
3150 together, many of the strings will be the same. Storing the
3151 strings in the hash table should save space in this case. */
3152 debug_contents
= (bfd_byte
*) bfd_malloc (subdeb
->_raw_size
);
3153 if (debug_contents
== NULL
)
3155 if (! bfd_get_section_contents (sub
, subdeb
, (PTR
) debug_contents
,
3156 (file_ptr
) 0, subdeb
->_raw_size
))
3159 csectpp
= xcoff_data (sub
)->csects
;
3161 symesz
= bfd_coff_symesz (sub
);
3162 esym
= (bfd_byte
*) obj_coff_external_syms (sub
);
3163 esymend
= esym
+ symcount
* symesz
;
3164 while (esym
< esymend
)
3166 struct internal_syment sym
;
3168 bfd_coff_swap_sym_in (sub
, (PTR
) esym
, (PTR
) &sym
);
3170 *debug_index
= (unsigned long) -1;
3172 if (sym
._n
._n_n
._n_zeroes
== 0
3175 || ((*csectpp
)->flags
& SEC_MARK
) != 0
3176 || *csectpp
== bfd_abs_section_ptr
)
3177 && bfd_coff_symname_in_debug (sub
, &sym
))
3182 name
= (char *) debug_contents
+ sym
._n
._n_n
._n_offset
;
3183 indx
= _bfd_stringtab_add (debug_strtab
, name
, true, true);
3184 if (indx
== (bfd_size_type
) -1)
3186 *debug_index
= indx
;
3189 esym
+= (sym
.n_numaux
+ 1) * symesz
;
3190 csectpp
+= sym
.n_numaux
+ 1;
3191 debug_index
+= sym
.n_numaux
+ 1;
3194 free (debug_contents
);
3195 debug_contents
= NULL
;
3197 /* Clear the size of subdeb, so that it is not included directly
3198 in the output file. */
3199 subdeb
->_raw_size
= 0;
3201 if (! info
->keep_memory
)
3203 if (! _bfd_coff_free_symbols (sub
))
3208 if (info
->strip
!= strip_all
)
3209 xcoff_hash_table (info
)->debug_section
->_raw_size
=
3210 _bfd_stringtab_size (debug_strtab
);
3215 if (ldinfo
.strings
!= NULL
)
3216 free (ldinfo
.strings
);
3217 if (debug_contents
!= NULL
)
3218 free (debug_contents
);
3223 bfd_xcoff_link_generate_rtinit (abfd
, init
, fini
)
3228 struct bfd_in_memory
*bim
;
3230 bim
= ((struct bfd_in_memory
*)
3231 bfd_malloc ((bfd_size_type
) sizeof (struct bfd_in_memory
)));
3238 abfd
->link_next
= 0;
3239 abfd
->format
= bfd_object
;
3240 abfd
->iostream
= (PTR
) bim
;
3241 abfd
->flags
= BFD_IN_MEMORY
;
3242 abfd
->direction
= write_direction
;
3245 if (false == bfd_xcoff_generate_rtinit (abfd
, init
, fini
))
3248 /* need to reset to unknown or it will not be read back in correctly */
3249 abfd
->format
= bfd_unknown
;
3250 abfd
->direction
= read_direction
;
3257 /* Add a symbol to the .loader symbols, if necessary. */
3260 xcoff_build_ldsyms (h
, p
)
3261 struct xcoff_link_hash_entry
*h
;
3264 struct xcoff_loader_info
*ldinfo
= (struct xcoff_loader_info
*) p
;
3268 Special handling of this symbol to make is the first symbol in
3269 the loader symbol table. Make sure this pass through does not
3271 if (h
->flags
& XCOFF_RTINIT
)
3276 /* If this is a final link, and the symbol was defined as a common
3277 symbol in a regular object file, and there was no definition in
3278 any dynamic object, then the linker will have allocated space for
3279 the symbol in a common section but the XCOFF_DEF_REGULAR flag
3280 will not have been set. */
3281 if (h
->root
.type
== bfd_link_hash_defined
3282 && (h
->flags
& XCOFF_DEF_REGULAR
) == 0
3283 && (h
->flags
& XCOFF_REF_REGULAR
) != 0
3284 && (h
->flags
& XCOFF_DEF_DYNAMIC
) == 0
3285 && (bfd_is_abs_section (h
->root
.u
.def
.section
)
3286 || (h
->root
.u
.def
.section
->owner
->flags
& DYNAMIC
) == 0))
3287 h
->flags
|= XCOFF_DEF_REGULAR
;
3289 /* If all defined symbols should be exported, mark them now. We
3290 don't want to export the actual functions, just the function
3292 if (ldinfo
->export_defineds
3293 && (h
->flags
& XCOFF_DEF_REGULAR
) != 0
3294 && h
->root
.root
.string
[0] != '.')
3298 /* We don't export a symbol which is being defined by an object
3299 included from an archive which contains a shared object. The
3300 rationale is that if an archive contains both an unshared and
3301 a shared object, then there must be some reason that the
3302 unshared object is unshared, and we don't want to start
3303 providing a shared version of it. In particular, this solves
3304 a bug involving the _savefNN set of functions. gcc will call
3305 those functions without providing a slot to restore the TOC,
3306 so it is essential that these functions be linked in directly
3307 and not from a shared object, which means that a shared
3308 object which also happens to link them in must not export
3309 them. This is confusing, but I haven't been able to think of
3310 a different approach. Note that the symbols can, of course,
3311 be exported explicitly. */
3313 if ((h
->root
.type
== bfd_link_hash_defined
3314 || h
->root
.type
== bfd_link_hash_defweak
)
3315 && h
->root
.u
.def
.section
->owner
!= NULL
3316 && h
->root
.u
.def
.section
->owner
->my_archive
!= NULL
)
3318 bfd
*arbfd
, *member
;
3320 arbfd
= h
->root
.u
.def
.section
->owner
->my_archive
;
3321 member
= bfd_openr_next_archived_file (arbfd
, (bfd
*) NULL
);
3322 while (member
!= NULL
)
3324 if ((member
->flags
& DYNAMIC
) != 0)
3329 member
= bfd_openr_next_archived_file (arbfd
, member
);
3334 h
->flags
|= XCOFF_EXPORT
;
3337 /* We don't want to garbage collect symbols which are not defined in
3338 XCOFF files. This is a convenient place to mark them. */
3339 if (xcoff_hash_table (ldinfo
->info
)->gc
3340 && (h
->flags
& XCOFF_MARK
) == 0
3341 && (h
->root
.type
== bfd_link_hash_defined
3342 || h
->root
.type
== bfd_link_hash_defweak
)
3343 && (h
->root
.u
.def
.section
->owner
== NULL
3344 || (h
->root
.u
.def
.section
->owner
->xvec
3345 != ldinfo
->info
->hash
->creator
)))
3346 h
->flags
|= XCOFF_MARK
;
3348 /* If this symbol is called and defined in a dynamic object, or it
3349 is imported, then we need to set up global linkage code for it.
3350 (Unless we did garbage collection and we didn't need this
3352 if ((h
->flags
& XCOFF_CALLED
) != 0
3353 && (h
->root
.type
== bfd_link_hash_undefined
3354 || h
->root
.type
== bfd_link_hash_undefweak
)
3355 && h
->root
.root
.string
[0] == '.'
3356 && h
->descriptor
!= NULL
3357 && ((h
->descriptor
->flags
& XCOFF_DEF_DYNAMIC
) != 0
3358 || ((h
->descriptor
->flags
& XCOFF_IMPORT
) != 0
3359 && (h
->descriptor
->flags
& XCOFF_DEF_REGULAR
) == 0))
3360 && (! xcoff_hash_table (ldinfo
->info
)->gc
3361 || (h
->flags
& XCOFF_MARK
) != 0))
3364 struct xcoff_link_hash_entry
*hds
;
3366 sec
= xcoff_hash_table (ldinfo
->info
)->linkage_section
;
3367 h
->root
.type
= bfd_link_hash_defined
;
3368 h
->root
.u
.def
.section
= sec
;
3369 h
->root
.u
.def
.value
= sec
->_raw_size
;
3371 h
->flags
|= XCOFF_DEF_REGULAR
;
3372 sec
->_raw_size
+= bfd_xcoff_glink_code_size(ldinfo
->output_bfd
);
3374 /* The global linkage code requires a TOC entry for the
3376 hds
= h
->descriptor
;
3377 BFD_ASSERT ((hds
->root
.type
== bfd_link_hash_undefined
3378 || hds
->root
.type
== bfd_link_hash_undefweak
)
3379 && (hds
->flags
& XCOFF_DEF_REGULAR
) == 0);
3380 hds
->flags
|= XCOFF_MARK
;
3381 if (hds
->toc_section
== NULL
)
3386 xcoff32 uses 4 bytes in the toc.
3387 xcoff64 uses 8 bytes in the toc. */
3388 if (bfd_xcoff_is_xcoff64 (ldinfo
->output_bfd
))
3392 else if (bfd_xcoff_is_xcoff32 (ldinfo
->output_bfd
))
3401 hds
->toc_section
= xcoff_hash_table (ldinfo
->info
)->toc_section
;
3402 hds
->u
.toc_offset
= hds
->toc_section
->_raw_size
;
3403 hds
->toc_section
->_raw_size
+= byte_size
;
3404 ++xcoff_hash_table (ldinfo
->info
)->ldrel_count
;
3405 ++hds
->toc_section
->reloc_count
;
3407 hds
->flags
|= XCOFF_SET_TOC
| XCOFF_LDREL
;
3409 /* We need to call xcoff_build_ldsyms recursively here,
3410 because we may already have passed hds on the traversal. */
3411 xcoff_build_ldsyms (hds
, p
);
3415 /* If this symbol is exported, but not defined, we need to try to
3417 if ((h
->flags
& XCOFF_EXPORT
) != 0
3418 && (h
->flags
& XCOFF_IMPORT
) == 0
3419 && (h
->flags
& XCOFF_DEF_REGULAR
) == 0
3420 && (h
->flags
& XCOFF_DEF_DYNAMIC
) == 0
3421 && (h
->root
.type
== bfd_link_hash_undefined
3422 || h
->root
.type
== bfd_link_hash_undefweak
))
3424 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0
3425 && (h
->descriptor
->root
.type
== bfd_link_hash_defined
3426 || h
->descriptor
->root
.type
== bfd_link_hash_defweak
))
3430 /* This is an undefined function descriptor associated with
3431 a defined entry point. We can build up a function
3432 descriptor ourselves. Believe it or not, the AIX linker
3433 actually does this, and there are cases where we need to
3435 sec
= xcoff_hash_table (ldinfo
->info
)->descriptor_section
;
3436 h
->root
.type
= bfd_link_hash_defined
;
3437 h
->root
.u
.def
.section
= sec
;
3438 h
->root
.u
.def
.value
= sec
->_raw_size
;
3440 h
->flags
|= XCOFF_DEF_REGULAR
;
3442 /* The size of the function descriptor depends if this is an
3443 xcoff32 (12) or xcoff64 (24). */
3445 bfd_xcoff_function_descriptor_size(ldinfo
->output_bfd
);
3447 /* A function descriptor uses two relocs: one for the
3448 associated code, and one for the TOC address. */
3449 xcoff_hash_table (ldinfo
->info
)->ldrel_count
+= 2;
3450 sec
->reloc_count
+= 2;
3452 /* We handle writing out the contents of the descriptor in
3453 xcoff_write_global_symbol. */
3457 (*_bfd_error_handler
)
3458 (_("warning: attempt to export undefined symbol `%s'"),
3459 h
->root
.root
.string
);
3465 /* If this is still a common symbol, and it wasn't garbage
3466 collected, we need to actually allocate space for it in the .bss
3468 if (h
->root
.type
== bfd_link_hash_common
3469 && (! xcoff_hash_table (ldinfo
->info
)->gc
3470 || (h
->flags
& XCOFF_MARK
) != 0)
3471 && h
->root
.u
.c
.p
->section
->_raw_size
== 0)
3473 BFD_ASSERT (bfd_is_com_section (h
->root
.u
.c
.p
->section
));
3474 h
->root
.u
.c
.p
->section
->_raw_size
= h
->root
.u
.c
.size
;
3477 /* We need to add a symbol to the .loader section if it is mentioned
3478 in a reloc which we are copying to the .loader section and it was
3479 not defined or common, or if it is the entry point, or if it is
3482 if (((h
->flags
& XCOFF_LDREL
) == 0
3483 || h
->root
.type
== bfd_link_hash_defined
3484 || h
->root
.type
== bfd_link_hash_defweak
3485 || h
->root
.type
== bfd_link_hash_common
)
3486 && (h
->flags
& XCOFF_ENTRY
) == 0
3487 && (h
->flags
& XCOFF_EXPORT
) == 0)
3493 /* We don't need to add this symbol if we did garbage collection and
3494 we did not mark this symbol. */
3495 if (xcoff_hash_table (ldinfo
->info
)->gc
3496 && (h
->flags
& XCOFF_MARK
) == 0)
3502 /* We may have already processed this symbol due to the recursive
3504 if ((h
->flags
& XCOFF_BUILT_LDSYM
) != 0)
3507 /* We need to add this symbol to the .loader symbols. */
3509 BFD_ASSERT (h
->ldsym
== NULL
);
3510 amt
= sizeof (struct internal_ldsym
);
3511 h
->ldsym
= (struct internal_ldsym
*) bfd_zalloc (ldinfo
->output_bfd
, amt
);
3512 if (h
->ldsym
== NULL
)
3514 ldinfo
->failed
= true;
3518 if ((h
->flags
& XCOFF_IMPORT
) != 0)
3519 h
->ldsym
->l_ifile
= h
->ldindx
;
3521 /* The first 3 symbol table indices are reserved to indicate the
3522 data, text and bss sections. */
3523 h
->ldindx
= ldinfo
->ldsym_count
+ 3;
3525 ++ldinfo
->ldsym_count
;
3527 if (false == bfd_xcoff_put_ldsymbol_name (ldinfo
->output_bfd
, ldinfo
,
3529 h
->root
.root
.string
))
3534 h
->flags
|= XCOFF_BUILT_LDSYM
;
3539 /* Do the final link step. */
3542 _bfd_xcoff_bfd_final_link (abfd
, info
)
3544 struct bfd_link_info
*info
;
3546 bfd_size_type symesz
;
3547 struct xcoff_final_link_info finfo
;
3549 struct bfd_link_order
*p
;
3550 bfd_size_type max_contents_size
;
3551 bfd_size_type max_sym_count
;
3552 bfd_size_type max_lineno_count
;
3553 bfd_size_type max_reloc_count
;
3554 bfd_size_type max_output_reloc_count
;
3555 file_ptr rel_filepos
;
3557 file_ptr line_filepos
;
3558 unsigned int linesz
;
3560 bfd_byte
*external_relocs
= NULL
;
3561 char strbuf
[STRING_SIZE_SIZE
];
3566 abfd
->flags
|= DYNAMIC
;
3568 symesz
= bfd_coff_symesz (abfd
);
3571 finfo
.output_bfd
= abfd
;
3572 finfo
.strtab
= NULL
;
3573 finfo
.section_info
= NULL
;
3574 finfo
.last_file_index
= -1;
3575 finfo
.toc_symindx
= -1;
3576 finfo
.internal_syms
= NULL
;
3577 finfo
.sym_indices
= NULL
;
3578 finfo
.outsyms
= NULL
;
3579 finfo
.linenos
= NULL
;
3580 finfo
.contents
= NULL
;
3581 finfo
.external_relocs
= NULL
;
3583 finfo
.ldsym
= (xcoff_hash_table (info
)->loader_section
->contents
3584 + bfd_xcoff_ldhdrsz (abfd
));
3585 finfo
.ldrel
= (xcoff_hash_table (info
)->loader_section
->contents
3586 + bfd_xcoff_ldhdrsz(abfd
)
3587 + (xcoff_hash_table (info
)->ldhdr
.l_nsyms
3588 * bfd_xcoff_ldsymsz(abfd
)));
3590 xcoff_data (abfd
)->coff
.link_info
= info
;
3592 finfo
.strtab
= _bfd_stringtab_init ();
3593 if (finfo
.strtab
== NULL
)
3596 /* Count the line number and relocation entries required for the
3597 output file. Determine a few maximum sizes. */
3598 max_contents_size
= 0;
3599 max_lineno_count
= 0;
3600 max_reloc_count
= 0;
3601 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3604 o
->lineno_count
= 0;
3605 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3607 if (p
->type
== bfd_indirect_link_order
)
3611 sec
= p
->u
.indirect
.section
;
3613 /* Mark all sections which are to be included in the
3614 link. This will normally be every section. We need
3615 to do this so that we can identify any sections which
3616 the linker has decided to not include. */
3617 sec
->linker_mark
= true;
3619 if (info
->strip
== strip_none
3620 || info
->strip
== strip_some
)
3621 o
->lineno_count
+= sec
->lineno_count
;
3623 o
->reloc_count
+= sec
->reloc_count
;
3625 if (sec
->_raw_size
> max_contents_size
)
3626 max_contents_size
= sec
->_raw_size
;
3627 if (sec
->lineno_count
> max_lineno_count
)
3628 max_lineno_count
= sec
->lineno_count
;
3629 if (coff_section_data (sec
->owner
, sec
) != NULL
3630 && xcoff_section_data (sec
->owner
, sec
) != NULL
3631 && (xcoff_section_data (sec
->owner
, sec
)->lineno_count
3632 > max_lineno_count
))
3634 xcoff_section_data (sec
->owner
, sec
)->lineno_count
;
3635 if (sec
->reloc_count
> max_reloc_count
)
3636 max_reloc_count
= sec
->reloc_count
;
3638 else if (p
->type
== bfd_section_reloc_link_order
3639 || p
->type
== bfd_symbol_reloc_link_order
)
3644 /* Compute the file positions for all the sections. */
3645 if (abfd
->output_has_begun
)
3647 if (xcoff_hash_table (info
)->file_align
!= 0)
3654 file_align
= xcoff_hash_table (info
)->file_align
;
3655 if (file_align
!= 0)
3657 boolean saw_contents
;
3662 /* Insert .pad sections before every section which has
3663 contents and is loaded, if it is preceded by some other
3664 section which has contents and is loaded. */
3665 saw_contents
= true;
3666 for (op
= &abfd
->sections
; *op
!= NULL
; op
= &(*op
)->next
)
3668 if (strcmp ((*op
)->name
, ".pad") == 0)
3669 saw_contents
= false;
3670 else if (((*op
)->flags
& SEC_HAS_CONTENTS
) != 0
3671 && ((*op
)->flags
& SEC_LOAD
) != 0)
3674 saw_contents
= true;
3681 n
= bfd_make_section_anyway (abfd
, ".pad");
3682 BFD_ASSERT (*op
== n
);
3684 n
->flags
= SEC_HAS_CONTENTS
;
3685 n
->alignment_power
= 0;
3686 saw_contents
= false;
3691 /* Reset the section indices after inserting the new
3694 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3697 o
->target_index
= indx
;
3699 BFD_ASSERT ((unsigned int) indx
== abfd
->section_count
);
3701 /* Work out appropriate sizes for the .pad sections to force
3702 each section to land on a page boundary. This bit of
3703 code knows what compute_section_file_positions is going
3705 sofar
= bfd_coff_filhsz (abfd
);
3706 sofar
+= bfd_coff_aoutsz (abfd
);
3707 sofar
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
3708 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3709 if ((bfd_xcoff_is_reloc_count_overflow
3710 (abfd
, (bfd_vma
) o
->reloc_count
))
3711 || (bfd_xcoff_is_lineno_count_overflow
3712 (abfd
, (bfd_vma
) o
->lineno_count
)))
3713 /* 64 does not overflow, need to check if 32 does */
3714 sofar
+= bfd_coff_scnhsz (abfd
);
3716 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3718 if (strcmp (o
->name
, ".pad") == 0)
3722 BFD_ASSERT (o
->_raw_size
== 0);
3723 pageoff
= sofar
& (file_align
- 1);
3726 o
->_raw_size
= file_align
- pageoff
;
3727 sofar
+= file_align
- pageoff
;
3728 o
->flags
|= SEC_HAS_CONTENTS
;
3733 if ((o
->flags
& SEC_HAS_CONTENTS
) != 0)
3734 sofar
+= BFD_ALIGN (o
->_raw_size
,
3735 1 << o
->alignment_power
);
3740 if (! bfd_coff_compute_section_file_positions (abfd
))
3744 /* Allocate space for the pointers we need to keep for the relocs. */
3748 /* We use section_count + 1, rather than section_count, because
3749 the target_index fields are 1 based. */
3750 amt
= abfd
->section_count
+ 1;
3751 amt
*= sizeof (struct xcoff_link_section_info
);
3752 finfo
.section_info
= (struct xcoff_link_section_info
*) bfd_malloc (amt
);
3753 if (finfo
.section_info
== NULL
)
3755 for (i
= 0; i
<= abfd
->section_count
; i
++)
3757 finfo
.section_info
[i
].relocs
= NULL
;
3758 finfo
.section_info
[i
].rel_hashes
= NULL
;
3759 finfo
.section_info
[i
].toc_rel_hashes
= NULL
;
3763 /* Set the file positions for the relocs. */
3764 rel_filepos
= obj_relocbase (abfd
);
3765 relsz
= bfd_coff_relsz (abfd
);
3766 max_output_reloc_count
= 0;
3767 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3769 if (o
->reloc_count
== 0)
3773 /* A stripped file has no relocs. However, we still
3774 allocate the buffers, so that later code doesn't have to
3775 worry about whether we are stripping or not. */
3776 if (info
->strip
== strip_all
)
3780 o
->flags
|= SEC_RELOC
;
3781 o
->rel_filepos
= rel_filepos
;
3782 rel_filepos
+= o
->reloc_count
* relsz
;
3785 /* We don't know the indices of global symbols until we have
3786 written out all the local symbols. For each section in
3787 the output file, we keep an array of pointers to hash
3788 table entries. Each entry in the array corresponds to a
3789 reloc. When we find a reloc against a global symbol, we
3790 set the corresponding entry in this array so that we can
3791 fix up the symbol index after we have written out all the
3794 Because of this problem, we also keep the relocs in
3795 memory until the end of the link. This wastes memory.
3796 We could backpatch the file later, I suppose, although it
3798 amt
= o
->reloc_count
;
3799 amt
*= sizeof (struct internal_reloc
);
3800 finfo
.section_info
[o
->target_index
].relocs
=
3801 (struct internal_reloc
*) bfd_malloc (amt
);
3803 amt
= o
->reloc_count
;
3804 amt
*= sizeof (struct xcoff_link_hash_entry
*);
3805 finfo
.section_info
[o
->target_index
].rel_hashes
=
3806 (struct xcoff_link_hash_entry
**) bfd_malloc (amt
);
3808 if (finfo
.section_info
[o
->target_index
].relocs
== NULL
3809 || finfo
.section_info
[o
->target_index
].rel_hashes
== NULL
)
3812 if (o
->reloc_count
> max_output_reloc_count
)
3813 max_output_reloc_count
= o
->reloc_count
;
3817 /* We now know the size of the relocs, so we can determine the file
3818 positions of the line numbers. */
3819 line_filepos
= rel_filepos
;
3820 finfo
.line_filepos
= line_filepos
;
3821 linesz
= bfd_coff_linesz (abfd
);
3822 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3824 if (o
->lineno_count
== 0)
3825 o
->line_filepos
= 0;
3828 o
->line_filepos
= line_filepos
;
3829 line_filepos
+= o
->lineno_count
* linesz
;
3832 /* Reset the reloc and lineno counts, so that we can use them to
3833 count the number of entries we have output so far. */
3835 o
->lineno_count
= 0;
3838 obj_sym_filepos (abfd
) = line_filepos
;
3840 /* Figure out the largest number of symbols in an input BFD. Take
3841 the opportunity to clear the output_has_begun fields of all the
3842 input BFD's. We want at least 6 symbols, since that is the
3843 number which xcoff_write_global_symbol may need. */
3845 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3849 sub
->output_has_begun
= false;
3850 sz
= obj_raw_syment_count (sub
);
3851 if (sz
> max_sym_count
)
3855 /* Allocate some buffers used while linking. */
3856 amt
= max_sym_count
* sizeof (struct internal_syment
);
3857 finfo
.internal_syms
= (struct internal_syment
*) bfd_malloc (amt
);
3859 amt
= max_sym_count
* sizeof (long);
3860 finfo
.sym_indices
= (long *) bfd_malloc (amt
);
3862 amt
= (max_sym_count
+ 1) * symesz
;
3863 finfo
.outsyms
= (bfd_byte
*) bfd_malloc (amt
);
3865 amt
= max_lineno_count
* bfd_coff_linesz (abfd
);
3866 finfo
.linenos
= (bfd_byte
*) bfd_malloc (amt
);
3868 amt
= max_contents_size
;
3869 finfo
.contents
= (bfd_byte
*) bfd_malloc (amt
);
3871 amt
= max_reloc_count
* relsz
;
3872 finfo
.external_relocs
= (bfd_byte
*) bfd_malloc (amt
);
3874 if ((finfo
.internal_syms
== NULL
&& max_sym_count
> 0)
3875 || (finfo
.sym_indices
== NULL
&& max_sym_count
> 0)
3876 || finfo
.outsyms
== NULL
3877 || (finfo
.linenos
== NULL
&& max_lineno_count
> 0)
3878 || (finfo
.contents
== NULL
&& max_contents_size
> 0)
3879 || (finfo
.external_relocs
== NULL
&& max_reloc_count
> 0))
3882 obj_raw_syment_count (abfd
) = 0;
3883 xcoff_data (abfd
)->toc
= (bfd_vma
) -1;
3885 /* We now know the position of everything in the file, except that
3886 we don't know the size of the symbol table and therefore we don't
3887 know where the string table starts. We just build the string
3888 table in memory as we go along. We process all the relocations
3889 for a single input file at once. */
3890 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3892 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3894 if (p
->type
== bfd_indirect_link_order
3895 && p
->u
.indirect
.section
->owner
->xvec
== abfd
->xvec
)
3897 sub
= p
->u
.indirect
.section
->owner
;
3898 if (! sub
->output_has_begun
)
3900 if (! xcoff_link_input_bfd (&finfo
, sub
))
3902 sub
->output_has_begun
= true;
3905 else if (p
->type
== bfd_section_reloc_link_order
3906 || p
->type
== bfd_symbol_reloc_link_order
)
3908 if (! xcoff_reloc_link_order (abfd
, &finfo
, o
, p
))
3913 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3920 /* Free up the buffers used by xcoff_link_input_bfd. */
3922 if (finfo
.internal_syms
!= NULL
)
3924 free (finfo
.internal_syms
);
3925 finfo
.internal_syms
= NULL
;
3927 if (finfo
.sym_indices
!= NULL
)
3929 free (finfo
.sym_indices
);
3930 finfo
.sym_indices
= NULL
;
3932 if (finfo
.linenos
!= NULL
)
3934 free (finfo
.linenos
);
3935 finfo
.linenos
= NULL
;
3937 if (finfo
.contents
!= NULL
)
3939 free (finfo
.contents
);
3940 finfo
.contents
= NULL
;
3942 if (finfo
.external_relocs
!= NULL
)
3944 free (finfo
.external_relocs
);
3945 finfo
.external_relocs
= NULL
;
3948 /* The value of the last C_FILE symbol is supposed to be -1. Write
3950 if (finfo
.last_file_index
!= -1)
3952 finfo
.last_file
.n_value
= -(bfd_vma
) 1;
3953 bfd_coff_swap_sym_out (abfd
, (PTR
) &finfo
.last_file
,
3954 (PTR
) finfo
.outsyms
);
3955 pos
= obj_sym_filepos (abfd
) + finfo
.last_file_index
* symesz
;
3956 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0
3957 || bfd_bwrite (finfo
.outsyms
, symesz
, abfd
) != symesz
)
3962 if (info
->init_function
|| info
->fini_function
)
3964 struct xcoff_link_hash_entry
*hrtinit
;
3966 hrtinit
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
3968 false, false, true);
3972 /* Write out all the global symbols which do not come from XCOFF
3974 xcoff_link_hash_traverse (xcoff_hash_table (info
),
3975 xcoff_write_global_symbol
,
3978 if (finfo
.outsyms
!= NULL
)
3980 free (finfo
.outsyms
);
3981 finfo
.outsyms
= NULL
;
3984 /* Now that we have written out all the global symbols, we know the
3985 symbol indices to use for relocs against them, and we can finally
3986 write out the relocs. */
3987 amt
= max_output_reloc_count
* relsz
;
3988 external_relocs
= (bfd_byte
*) bfd_malloc (amt
);
3989 if (external_relocs
== NULL
&& max_output_reloc_count
!= 0)
3992 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3994 struct internal_reloc
*irel
;
3995 struct internal_reloc
*irelend
;
3996 struct xcoff_link_hash_entry
**rel_hash
;
3997 struct xcoff_toc_rel_hash
*toc_rel_hash
;
3999 bfd_size_type rel_size
;
4001 /* A stripped file has no relocs. */
4002 if (info
->strip
== strip_all
)
4008 if (o
->reloc_count
== 0)
4011 irel
= finfo
.section_info
[o
->target_index
].relocs
;
4012 irelend
= irel
+ o
->reloc_count
;
4013 rel_hash
= finfo
.section_info
[o
->target_index
].rel_hashes
;
4014 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
4016 if (*rel_hash
!= NULL
)
4018 if ((*rel_hash
)->indx
< 0)
4020 if (! ((*info
->callbacks
->unattached_reloc
)
4021 (info
, (*rel_hash
)->root
.root
.string
,
4022 (bfd
*) NULL
, o
, irel
->r_vaddr
)))
4024 (*rel_hash
)->indx
= 0;
4026 irel
->r_symndx
= (*rel_hash
)->indx
;
4030 for (toc_rel_hash
= finfo
.section_info
[o
->target_index
].toc_rel_hashes
;
4031 toc_rel_hash
!= NULL
;
4032 toc_rel_hash
= toc_rel_hash
->next
)
4034 if (toc_rel_hash
->h
->u
.toc_indx
< 0)
4036 if (! ((*info
->callbacks
->unattached_reloc
)
4037 (info
, toc_rel_hash
->h
->root
.root
.string
,
4038 (bfd
*) NULL
, o
, toc_rel_hash
->rel
->r_vaddr
)))
4040 toc_rel_hash
->h
->u
.toc_indx
= 0;
4042 toc_rel_hash
->rel
->r_symndx
= toc_rel_hash
->h
->u
.toc_indx
;
4045 /* XCOFF requires that the relocs be sorted by address. We tend
4046 to produce them in the order in which their containing csects
4047 appear in the symbol table, which is not necessarily by
4048 address. So we sort them here. There may be a better way to
4050 qsort ((PTR
) finfo
.section_info
[o
->target_index
].relocs
,
4051 o
->reloc_count
, sizeof (struct internal_reloc
),
4054 irel
= finfo
.section_info
[o
->target_index
].relocs
;
4055 irelend
= irel
+ o
->reloc_count
;
4056 erel
= external_relocs
;
4057 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
4058 bfd_coff_swap_reloc_out (abfd
, (PTR
) irel
, (PTR
) erel
);
4060 rel_size
= relsz
* o
->reloc_count
;
4061 if (bfd_seek (abfd
, o
->rel_filepos
, SEEK_SET
) != 0
4062 || bfd_bwrite ((PTR
) external_relocs
, rel_size
, abfd
) != rel_size
)
4066 if (external_relocs
!= NULL
)
4068 free (external_relocs
);
4069 external_relocs
= NULL
;
4072 /* Free up the section information. */
4073 if (finfo
.section_info
!= NULL
)
4077 for (i
= 0; i
< abfd
->section_count
; i
++)
4079 if (finfo
.section_info
[i
].relocs
!= NULL
)
4080 free (finfo
.section_info
[i
].relocs
);
4081 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
4082 free (finfo
.section_info
[i
].rel_hashes
);
4084 free (finfo
.section_info
);
4085 finfo
.section_info
= NULL
;
4088 /* Write out the loader section contents. */
4089 BFD_ASSERT ((bfd_byte
*) finfo
.ldrel
4090 == (xcoff_hash_table (info
)->loader_section
->contents
4091 + xcoff_hash_table (info
)->ldhdr
.l_impoff
));
4092 o
= xcoff_hash_table (info
)->loader_section
;
4093 if (! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
4094 (file_ptr
) o
->output_offset
, o
->_raw_size
))
4097 /* Write out the magic sections. */
4098 o
= xcoff_hash_table (info
)->linkage_section
;
4099 if (o
->_raw_size
> 0
4100 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
4101 (file_ptr
) o
->output_offset
,
4104 o
= xcoff_hash_table (info
)->toc_section
;
4105 if (o
->_raw_size
> 0
4106 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
4107 (file_ptr
) o
->output_offset
,
4110 o
= xcoff_hash_table (info
)->descriptor_section
;
4111 if (o
->_raw_size
> 0
4112 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
4113 (file_ptr
) o
->output_offset
,
4117 /* Write out the string table. */
4118 pos
= obj_sym_filepos (abfd
) + obj_raw_syment_count (abfd
) * symesz
;
4119 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
4122 _bfd_stringtab_size (finfo
.strtab
) + STRING_SIZE_SIZE
,
4124 amt
= STRING_SIZE_SIZE
;
4125 if (bfd_bwrite (strbuf
, amt
, abfd
) != amt
)
4127 if (! _bfd_stringtab_emit (abfd
, finfo
.strtab
))
4130 _bfd_stringtab_free (finfo
.strtab
);
4132 /* Write out the debugging string table. */
4133 o
= xcoff_hash_table (info
)->debug_section
;
4136 struct bfd_strtab_hash
*debug_strtab
;
4138 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
4139 BFD_ASSERT (o
->output_section
->_raw_size
- o
->output_offset
4140 >= _bfd_stringtab_size (debug_strtab
));
4141 pos
= o
->output_section
->filepos
+ o
->output_offset
;
4142 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
4144 if (! _bfd_stringtab_emit (abfd
, debug_strtab
))
4148 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
4149 not try to write out the symbols. */
4150 bfd_get_symcount (abfd
) = 0;
4155 if (finfo
.strtab
!= NULL
)
4156 _bfd_stringtab_free (finfo
.strtab
);
4158 if (finfo
.section_info
!= NULL
)
4162 for (i
= 0; i
< abfd
->section_count
; i
++)
4164 if (finfo
.section_info
[i
].relocs
!= NULL
)
4165 free (finfo
.section_info
[i
].relocs
);
4166 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
4167 free (finfo
.section_info
[i
].rel_hashes
);
4169 free (finfo
.section_info
);
4172 if (finfo
.internal_syms
!= NULL
)
4173 free (finfo
.internal_syms
);
4174 if (finfo
.sym_indices
!= NULL
)
4175 free (finfo
.sym_indices
);
4176 if (finfo
.outsyms
!= NULL
)
4177 free (finfo
.outsyms
);
4178 if (finfo
.linenos
!= NULL
)
4179 free (finfo
.linenos
);
4180 if (finfo
.contents
!= NULL
)
4181 free (finfo
.contents
);
4182 if (finfo
.external_relocs
!= NULL
)
4183 free (finfo
.external_relocs
);
4184 if (external_relocs
!= NULL
)
4185 free (external_relocs
);
4189 /* Link an input file into the linker output file. This function
4190 handles all the sections and relocations of the input file at once. */
4193 xcoff_link_input_bfd (finfo
, input_bfd
)
4194 struct xcoff_final_link_info
*finfo
;
4198 const char *strings
;
4199 bfd_size_type syment_base
;
4200 unsigned int n_tmask
;
4201 unsigned int n_btshft
;
4203 bfd_size_type isymesz
;
4204 bfd_size_type osymesz
;
4205 bfd_size_type linesz
;
4208 struct xcoff_link_hash_entry
**sym_hash
;
4209 struct internal_syment
*isymp
;
4211 unsigned long *debug_index
;
4213 unsigned long output_index
;
4220 /* We can just skip DYNAMIC files, unless this is a static link. */
4221 if ((input_bfd
->flags
& DYNAMIC
) != 0
4222 && ! finfo
->info
->static_link
)
4225 /* Move all the symbols to the output file. */
4227 output_bfd
= finfo
->output_bfd
;
4229 syment_base
= obj_raw_syment_count (output_bfd
);
4230 isymesz
= bfd_coff_symesz (input_bfd
);
4231 osymesz
= bfd_coff_symesz (output_bfd
);
4232 linesz
= bfd_coff_linesz (input_bfd
);
4233 BFD_ASSERT (linesz
== bfd_coff_linesz (output_bfd
));
4235 n_tmask
= coff_data (input_bfd
)->local_n_tmask
;
4236 n_btshft
= coff_data (input_bfd
)->local_n_btshft
;
4238 /* Define macros so that ISFCN, et. al., macros work correctly. */
4239 #define N_TMASK n_tmask
4240 #define N_BTSHFT n_btshft
4243 if (! finfo
->info
->keep_memory
)
4246 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
4249 if (! _bfd_coff_get_external_symbols (input_bfd
))
4252 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
4253 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
4254 sym_hash
= obj_xcoff_sym_hashes (input_bfd
);
4255 csectpp
= xcoff_data (input_bfd
)->csects
;
4256 debug_index
= xcoff_data (input_bfd
)->debug_indices
;
4257 isymp
= finfo
->internal_syms
;
4258 indexp
= finfo
->sym_indices
;
4259 output_index
= syment_base
;
4260 outsym
= finfo
->outsyms
;
4264 while (esym
< esym_end
)
4267 struct internal_syment isym
;
4268 union internal_auxent aux
;
4274 bfd_coff_swap_sym_in (input_bfd
, (PTR
) esym
, (PTR
) isymp
);
4276 /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
4278 if (isymp
->n_sclass
== C_EXT
|| isymp
->n_sclass
== C_HIDEXT
)
4280 BFD_ASSERT (isymp
->n_numaux
> 0);
4281 bfd_coff_swap_aux_in (input_bfd
,
4282 (PTR
) (esym
+ isymesz
* isymp
->n_numaux
),
4283 isymp
->n_type
, isymp
->n_sclass
,
4284 isymp
->n_numaux
- 1, isymp
->n_numaux
,
4287 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
4290 /* Make a copy of *isymp so that the relocate_section function
4291 always sees the original values. This is more reliable than
4292 always recomputing the symbol value even if we are stripping
4296 /* If this symbol is in the .loader section, swap out the
4297 .loader symbol information. If this is an external symbol
4298 reference to a defined symbol, though, then wait until we get
4299 to the definition. */
4300 if (isym
.n_sclass
== C_EXT
4301 && *sym_hash
!= NULL
4302 && (*sym_hash
)->ldsym
!= NULL
4304 || (*sym_hash
)->root
.type
== bfd_link_hash_undefined
))
4306 struct xcoff_link_hash_entry
*h
;
4307 struct internal_ldsym
*ldsym
;
4311 if (isym
.n_scnum
> 0)
4313 ldsym
->l_scnum
= (*csectpp
)->output_section
->target_index
;
4314 ldsym
->l_value
= (isym
.n_value
4315 + (*csectpp
)->output_section
->vma
4316 + (*csectpp
)->output_offset
4321 ldsym
->l_scnum
= isym
.n_scnum
;
4322 ldsym
->l_value
= isym
.n_value
;
4325 ldsym
->l_smtype
= smtyp
;
4326 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
4327 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4328 || (h
->flags
& XCOFF_IMPORT
) != 0)
4329 ldsym
->l_smtype
|= L_IMPORT
;
4330 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
4331 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4332 || (h
->flags
& XCOFF_EXPORT
) != 0)
4333 ldsym
->l_smtype
|= L_EXPORT
;
4334 if ((h
->flags
& XCOFF_ENTRY
) != 0)
4335 ldsym
->l_smtype
|= L_ENTRY
;
4337 ldsym
->l_smclas
= aux
.x_csect
.x_smclas
;
4339 if (ldsym
->l_ifile
== (bfd_size_type
) -1)
4341 else if (ldsym
->l_ifile
== 0)
4343 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
4349 if (h
->root
.type
== bfd_link_hash_defined
4350 || h
->root
.type
== bfd_link_hash_defweak
)
4351 impbfd
= h
->root
.u
.def
.section
->owner
;
4352 else if (h
->root
.type
== bfd_link_hash_undefined
4353 || h
->root
.type
== bfd_link_hash_undefweak
)
4354 impbfd
= h
->root
.u
.undef
.abfd
;
4362 BFD_ASSERT (impbfd
->xvec
== finfo
->output_bfd
->xvec
);
4363 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
4370 BFD_ASSERT (h
->ldindx
>= 0);
4371 bfd_xcoff_swap_ldsym_out (finfo
->output_bfd
, ldsym
,
4374 * bfd_xcoff_ldsymsz (finfo
->output_bfd
))));
4377 /* Fill in snentry now that we know the target_index. */
4378 if ((h
->flags
& XCOFF_ENTRY
) != 0
4379 && (h
->root
.type
== bfd_link_hash_defined
4380 || h
->root
.type
== bfd_link_hash_defweak
))
4382 xcoff_data (output_bfd
)->snentry
=
4383 h
->root
.u
.def
.section
->output_section
->target_index
;
4391 add
= 1 + isym
.n_numaux
;
4393 /* If we are skipping this csect, we want to skip this symbol. */
4394 if (*csectpp
== NULL
)
4397 /* If we garbage collected this csect, we want to skip this
4400 && xcoff_hash_table (finfo
->info
)->gc
4401 && ((*csectpp
)->flags
& SEC_MARK
) == 0
4402 && *csectpp
!= bfd_abs_section_ptr
)
4405 /* An XCOFF linker always skips C_STAT symbols. */
4407 && isymp
->n_sclass
== C_STAT
)
4410 /* We skip all but the first TOC anchor. */
4412 && isymp
->n_sclass
== C_HIDEXT
4413 && aux
.x_csect
.x_smclas
== XMC_TC0
)
4415 if (finfo
->toc_symindx
!= -1)
4419 bfd_vma tocval
, tocend
;
4422 tocval
= ((*csectpp
)->output_section
->vma
4423 + (*csectpp
)->output_offset
4427 /* We want to find out if tocval is a good value to use
4428 as the TOC anchor--that is, whether we can access all
4429 of the TOC using a 16 bit offset from tocval. This
4430 test assumes that the TOC comes at the end of the
4431 output section, as it does in the default linker
4433 tocend
= ((*csectpp
)->output_section
->vma
4434 + (*csectpp
)->output_section
->_raw_size
);
4435 for (inp
= finfo
->info
->input_bfds
;
4437 inp
= inp
->link_next
)
4440 for (o
= inp
->sections
; o
!= NULL
; o
= o
->next
)
4441 if (strcmp (o
->name
, ".tocbss") == 0)
4443 bfd_vma new_toc_end
;
4444 new_toc_end
= (o
->output_section
->vma
4447 if (new_toc_end
> tocend
)
4448 tocend
= new_toc_end
;
4453 if (tocval
+ 0x10000 < tocend
)
4455 (*_bfd_error_handler
)
4456 (_("TOC overflow: 0x%lx > 0x10000; try -mminimal-toc when compiling"),
4457 (unsigned long) (tocend
- tocval
));
4458 bfd_set_error (bfd_error_file_too_big
);
4462 if (tocval
+ 0x8000 < tocend
)
4466 tocadd
= tocend
- (tocval
+ 0x8000);
4468 isym
.n_value
+= tocadd
;
4471 finfo
->toc_symindx
= output_index
;
4472 xcoff_data (finfo
->output_bfd
)->toc
= tocval
;
4473 xcoff_data (finfo
->output_bfd
)->sntoc
=
4474 (*csectpp
)->output_section
->target_index
;
4480 /* If we are stripping all symbols, we want to skip this one. */
4482 && finfo
->info
->strip
== strip_all
)
4485 /* We can skip resolved external references. */
4487 && isym
.n_sclass
== C_EXT
4489 && (*sym_hash
)->root
.type
!= bfd_link_hash_undefined
)
4492 /* We can skip common symbols if they got defined somewhere
4495 && isym
.n_sclass
== C_EXT
4497 && ((*sym_hash
)->root
.type
!= bfd_link_hash_common
4498 || (*sym_hash
)->root
.u
.c
.p
->section
!= *csectpp
)
4499 && ((*sym_hash
)->root
.type
!= bfd_link_hash_defined
4500 || (*sym_hash
)->root
.u
.def
.section
!= *csectpp
))
4503 /* Skip local symbols if we are discarding them. */
4505 && finfo
->info
->discard
== discard_all
4506 && isym
.n_sclass
!= C_EXT
4507 && (isym
.n_sclass
!= C_HIDEXT
4508 || smtyp
!= XTY_SD
))
4511 /* If we stripping debugging symbols, and this is a debugging
4512 symbol, then skip it. */
4514 && finfo
->info
->strip
== strip_debugger
4515 && isym
.n_scnum
== N_DEBUG
)
4518 /* If some symbols are stripped based on the name, work out the
4519 name and decide whether to skip this symbol. We don't handle
4520 this correctly for symbols whose names are in the .debug
4521 section; to get it right we would need a new bfd_strtab_hash
4522 function to return the string given the index. */
4524 && (finfo
->info
->strip
== strip_some
4525 || finfo
->info
->discard
== discard_l
)
4526 && (debug_index
== NULL
|| *debug_index
== (unsigned long) -1))
4529 char buf
[SYMNMLEN
+ 1];
4531 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
, buf
);
4536 if ((finfo
->info
->strip
== strip_some
4537 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false,
4539 || (finfo
->info
->discard
== discard_l
4540 && (isym
.n_sclass
!= C_EXT
4541 && (isym
.n_sclass
!= C_HIDEXT
4542 || smtyp
!= XTY_SD
))
4543 && bfd_is_local_label_name (input_bfd
, name
)))
4547 /* We can not skip the first TOC anchor. */
4550 && finfo
->info
->strip
!= strip_all
)
4553 /* We now know whether we are to skip this symbol or not. */
4556 /* Adjust the symbol in order to output it. */
4558 if (isym
._n
._n_n
._n_zeroes
== 0
4559 && isym
._n
._n_n
._n_offset
!= 0)
4561 /* This symbol has a long name. Enter it in the string
4562 table we are building. If *debug_index != -1, the
4563 name has already been entered in the .debug section. */
4564 if (debug_index
!= NULL
&& *debug_index
!= (unsigned long) -1)
4565 isym
._n
._n_n
._n_offset
= *debug_index
;
4571 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
,
4576 indx
= _bfd_stringtab_add (finfo
->strtab
, name
, hash
, copy
);
4577 if (indx
== (bfd_size_type
) -1)
4579 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
4583 if (isym
.n_sclass
!= C_BSTAT
4584 && isym
.n_sclass
!= C_ESTAT
4585 && isym
.n_sclass
!= C_DECL
4586 && isym
.n_scnum
> 0)
4588 isym
.n_scnum
= (*csectpp
)->output_section
->target_index
;
4589 isym
.n_value
+= ((*csectpp
)->output_section
->vma
4590 + (*csectpp
)->output_offset
4594 /* The value of a C_FILE symbol is the symbol index of the
4595 next C_FILE symbol. The value of the last C_FILE symbol
4596 is -1. We try to get this right, below, just before we
4597 write the symbols out, but in the general case we may
4598 have to write the symbol out twice. */
4599 if (isym
.n_sclass
== C_FILE
)
4601 if (finfo
->last_file_index
!= -1
4602 && finfo
->last_file
.n_value
!= (bfd_vma
) output_index
)
4604 /* We must correct the value of the last C_FILE entry. */
4605 finfo
->last_file
.n_value
= output_index
;
4606 if ((bfd_size_type
) finfo
->last_file_index
>= syment_base
)
4608 /* The last C_FILE symbol is in this input file. */
4609 bfd_coff_swap_sym_out (output_bfd
,
4610 (PTR
) &finfo
->last_file
,
4611 (PTR
) (finfo
->outsyms
4612 + ((finfo
->last_file_index
4618 /* We have already written out the last C_FILE
4619 symbol. We need to write it out again. We
4620 borrow *outsym temporarily. */
4623 bfd_coff_swap_sym_out (output_bfd
,
4624 (PTR
) &finfo
->last_file
,
4627 pos
= obj_sym_filepos (output_bfd
);
4628 pos
+= finfo
->last_file_index
* osymesz
;
4629 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
4630 || (bfd_bwrite (outsym
, osymesz
, output_bfd
)
4636 finfo
->last_file_index
= output_index
;
4637 finfo
->last_file
= isym
;
4640 /* The value of a C_BINCL or C_EINCL symbol is a file offset
4641 into the line numbers. We update the symbol values when
4642 we handle the line numbers. */
4643 if (isym
.n_sclass
== C_BINCL
4644 || isym
.n_sclass
== C_EINCL
)
4646 isym
.n_value
= finfo
->line_filepos
;
4650 /* Output the symbol. */
4652 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
4654 *indexp
= output_index
;
4656 if (isym
.n_sclass
== C_EXT
)
4659 struct xcoff_link_hash_entry
*h
;
4661 indx
= ((esym
- (bfd_byte
*) obj_coff_external_syms (input_bfd
))
4663 h
= obj_xcoff_sym_hashes (input_bfd
)[indx
];
4664 BFD_ASSERT (h
!= NULL
);
4665 h
->indx
= output_index
;
4668 /* If this is a symbol in the TOC which we may have merged
4669 (class XMC_TC), remember the symbol index of the TOC
4671 if (isym
.n_sclass
== C_HIDEXT
4672 && aux
.x_csect
.x_smclas
== XMC_TC
4673 && *sym_hash
!= NULL
)
4675 BFD_ASSERT (((*sym_hash
)->flags
& XCOFF_SET_TOC
) == 0);
4676 BFD_ASSERT ((*sym_hash
)->toc_section
!= NULL
);
4677 (*sym_hash
)->u
.toc_indx
= output_index
;
4680 output_index
+= add
;
4681 outsym
+= add
* osymesz
;
4684 esym
+= add
* isymesz
;
4688 if (debug_index
!= NULL
)
4691 for (--add
; add
> 0; --add
)
4695 /* Fix up the aux entries and the C_BSTAT symbols. This must be
4696 done in a separate pass, because we don't know the correct symbol
4697 indices until we have already decided which symbols we are going
4700 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
4701 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
4702 isymp
= finfo
->internal_syms
;
4703 indexp
= finfo
->sym_indices
;
4704 csectpp
= xcoff_data (input_bfd
)->csects
;
4705 outsym
= finfo
->outsyms
;
4706 while (esym
< esym_end
)
4710 add
= 1 + isymp
->n_numaux
;
4713 esym
+= add
* isymesz
;
4718 if (isymp
->n_sclass
== C_BSTAT
)
4720 struct internal_syment isym
;
4724 /* The value of a C_BSTAT symbol is the symbol table
4725 index of the containing csect. */
4726 bfd_coff_swap_sym_in (output_bfd
, (PTR
) outsym
, (PTR
) &isym
);
4727 indx
= isym
.n_value
;
4728 if (indx
< obj_raw_syment_count (input_bfd
))
4732 symindx
= finfo
->sym_indices
[indx
];
4736 isym
.n_value
= symindx
;
4737 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
,
4745 for (i
= 0; i
< isymp
->n_numaux
&& esym
< esym_end
; i
++)
4747 union internal_auxent aux
;
4749 bfd_coff_swap_aux_in (input_bfd
, (PTR
) esym
, isymp
->n_type
,
4750 isymp
->n_sclass
, i
, isymp
->n_numaux
,
4753 if (isymp
->n_sclass
== C_FILE
)
4755 /* This is the file name (or some comment put in by
4756 the compiler). If it is long, we must put it in
4757 the string table. */
4758 if (aux
.x_file
.x_n
.x_zeroes
== 0
4759 && aux
.x_file
.x_n
.x_offset
!= 0)
4761 const char *filename
;
4764 BFD_ASSERT (aux
.x_file
.x_n
.x_offset
4765 >= STRING_SIZE_SIZE
);
4766 if (strings
== NULL
)
4768 strings
= _bfd_coff_read_string_table (input_bfd
);
4769 if (strings
== NULL
)
4772 filename
= strings
+ aux
.x_file
.x_n
.x_offset
;
4773 indx
= _bfd_stringtab_add (finfo
->strtab
, filename
,
4775 if (indx
== (bfd_size_type
) -1)
4777 aux
.x_file
.x_n
.x_offset
= STRING_SIZE_SIZE
+ indx
;
4780 else if ((isymp
->n_sclass
== C_EXT
4781 || isymp
->n_sclass
== C_HIDEXT
)
4782 && i
+ 1 == isymp
->n_numaux
)
4785 /* We don't support type checking. I don't know if
4787 aux
.x_csect
.x_parmhash
= 0;
4788 /* I don't think anybody uses these fields, but we'd
4789 better clobber them just in case. */
4790 aux
.x_csect
.x_stab
= 0;
4791 aux
.x_csect
.x_snstab
= 0;
4793 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_LD
)
4797 indx
= aux
.x_csect
.x_scnlen
.l
;
4798 if (indx
< obj_raw_syment_count (input_bfd
))
4802 symindx
= finfo
->sym_indices
[indx
];
4805 aux
.x_csect
.x_scnlen
.l
= 0;
4809 aux
.x_csect
.x_scnlen
.l
= symindx
;
4814 else if (isymp
->n_sclass
!= C_STAT
|| isymp
->n_type
!= T_NULL
)
4818 if (ISFCN (isymp
->n_type
)
4819 || ISTAG (isymp
->n_sclass
)
4820 || isymp
->n_sclass
== C_BLOCK
4821 || isymp
->n_sclass
== C_FCN
)
4823 indx
= aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
4825 && indx
< obj_raw_syment_count (input_bfd
))
4827 /* We look forward through the symbol for
4828 the index of the next symbol we are going
4829 to include. I don't know if this is
4831 while (finfo
->sym_indices
[indx
] < 0
4832 && indx
< obj_raw_syment_count (input_bfd
))
4834 if (indx
>= obj_raw_syment_count (input_bfd
))
4835 indx
= output_index
;
4837 indx
= finfo
->sym_indices
[indx
];
4838 aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= indx
;
4843 indx
= aux
.x_sym
.x_tagndx
.l
;
4844 if (indx
> 0 && indx
< obj_raw_syment_count (input_bfd
))
4848 symindx
= finfo
->sym_indices
[indx
];
4850 aux
.x_sym
.x_tagndx
.l
= 0;
4852 aux
.x_sym
.x_tagndx
.l
= symindx
;
4857 /* Copy over the line numbers, unless we are stripping
4858 them. We do this on a symbol by symbol basis in
4859 order to more easily handle garbage collection. */
4860 if ((isymp
->n_sclass
== C_EXT
4861 || isymp
->n_sclass
== C_HIDEXT
)
4863 && isymp
->n_numaux
> 1
4864 && ISFCN (isymp
->n_type
)
4865 && aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
4867 if (finfo
->info
->strip
!= strip_none
4868 && finfo
->info
->strip
!= strip_some
)
4869 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4872 asection
*enclosing
;
4873 unsigned int enc_count
;
4874 bfd_signed_vma linoff
;
4875 struct internal_lineno lin
;
4878 enclosing
= xcoff_section_data (abfd
, o
)->enclosing
;
4879 enc_count
= xcoff_section_data (abfd
, o
)->lineno_count
;
4880 if (oline
!= enclosing
)
4882 file_ptr pos
= enclosing
->line_filepos
;
4883 bfd_size_type amt
= linesz
* enc_count
;
4884 if (bfd_seek (input_bfd
, pos
, SEEK_SET
) != 0
4885 || (bfd_bread (finfo
->linenos
, amt
, input_bfd
)
4891 linoff
= (aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
4892 - enclosing
->line_filepos
);
4894 bfd_coff_swap_lineno_in (input_bfd
,
4895 (PTR
) (finfo
->linenos
+ linoff
),
4898 || ((bfd_size_type
) lin
.l_addr
.l_symndx
4902 obj_coff_external_syms (input_bfd
)))
4904 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4907 bfd_byte
*linpend
, *linp
;
4909 bfd_size_type count
;
4911 lin
.l_addr
.l_symndx
= *indexp
;
4912 bfd_coff_swap_lineno_out (output_bfd
, (PTR
) &lin
,
4913 (PTR
) (finfo
->linenos
4916 linpend
= (finfo
->linenos
4917 + enc_count
* linesz
);
4918 offset
= (o
->output_section
->vma
4921 for (linp
= finfo
->linenos
+ linoff
+ linesz
;
4925 bfd_coff_swap_lineno_in (input_bfd
, (PTR
) linp
,
4927 if (lin
.l_lnno
== 0)
4929 lin
.l_addr
.l_paddr
+= offset
;
4930 bfd_coff_swap_lineno_out (output_bfd
,
4935 count
= (linp
- (finfo
->linenos
+ linoff
)) / linesz
;
4937 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
4938 (o
->output_section
->line_filepos
4939 + o
->output_section
->lineno_count
* linesz
);
4941 if (bfd_seek (output_bfd
,
4942 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
4944 || (bfd_bwrite (finfo
->linenos
+ linoff
,
4945 linesz
* count
, output_bfd
)
4949 o
->output_section
->lineno_count
+= count
;
4953 struct internal_syment
*iisp
, *iispend
;
4958 /* Update any C_BINCL or C_EINCL symbols
4959 that refer to a line number in the
4960 range we just output. */
4961 iisp
= finfo
->internal_syms
;
4963 + obj_raw_syment_count (input_bfd
));
4964 iindp
= finfo
->sym_indices
;
4965 oos
= finfo
->outsyms
;
4966 while (iisp
< iispend
)
4969 && (iisp
->n_sclass
== C_BINCL
4970 || iisp
->n_sclass
== C_EINCL
)
4971 && ((bfd_size_type
) iisp
->n_value
4972 >= (bfd_size_type
)(enclosing
->line_filepos
+ linoff
))
4973 && ((bfd_size_type
) iisp
->n_value
4974 < (enclosing
->line_filepos
4975 + enc_count
* linesz
)))
4977 struct internal_syment iis
;
4979 bfd_coff_swap_sym_in (output_bfd
,
4984 - enclosing
->line_filepos
4986 + aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
4987 bfd_coff_swap_sym_out (output_bfd
,
4993 iiadd
= 1 + iisp
->n_numaux
;
4995 oos
+= iiadd
* osymesz
;
5004 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, isymp
->n_type
,
5005 isymp
->n_sclass
, i
, isymp
->n_numaux
,
5017 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
5018 symbol will be the first symbol in the next input file. In the
5019 normal case, this will save us from writing out the C_FILE symbol
5021 if (finfo
->last_file_index
!= -1
5022 && (bfd_size_type
) finfo
->last_file_index
>= syment_base
)
5024 finfo
->last_file
.n_value
= output_index
;
5025 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &finfo
->last_file
,
5026 (PTR
) (finfo
->outsyms
5027 + ((finfo
->last_file_index
- syment_base
)
5031 /* Write the modified symbols to the output file. */
5032 if (outsym
> finfo
->outsyms
)
5034 file_ptr pos
= obj_sym_filepos (output_bfd
) + syment_base
* osymesz
;
5035 bfd_size_type amt
= outsym
- finfo
->outsyms
;
5036 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
5037 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
5040 BFD_ASSERT ((obj_raw_syment_count (output_bfd
)
5041 + (outsym
- finfo
->outsyms
) / osymesz
)
5044 obj_raw_syment_count (output_bfd
) = output_index
;
5047 /* Don't let the linker relocation routines discard the symbols. */
5048 keep_syms
= obj_coff_keep_syms (input_bfd
);
5049 obj_coff_keep_syms (input_bfd
) = true;
5051 /* Relocate the contents of each section. */
5052 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5057 if (! o
->linker_mark
)
5059 /* This section was omitted from the link. */
5063 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
5064 || o
->_raw_size
== 0
5065 || (o
->flags
& SEC_IN_MEMORY
) != 0)
5068 /* We have set filepos correctly for the sections we created to
5069 represent csects, so bfd_get_section_contents should work. */
5070 if (coff_section_data (input_bfd
, o
) != NULL
5071 && coff_section_data (input_bfd
, o
)->contents
!= NULL
)
5072 contents
= coff_section_data (input_bfd
, o
)->contents
;
5074 if (! bfd_get_section_contents (input_bfd
, o
, finfo
->contents
,
5075 (file_ptr
) 0, o
->_raw_size
))
5077 contents
= finfo
->contents
;
5080 if ((o
->flags
& SEC_RELOC
) != 0)
5083 struct internal_reloc
*internal_relocs
;
5084 struct internal_reloc
*irel
;
5086 struct internal_reloc
*irelend
;
5087 struct xcoff_link_hash_entry
**rel_hash
;
5090 /* Read in the relocs. */
5091 target_index
= o
->output_section
->target_index
;
5092 internal_relocs
= (xcoff_read_internal_relocs
5093 (input_bfd
, o
, false, finfo
->external_relocs
,
5095 (finfo
->section_info
[target_index
].relocs
5096 + o
->output_section
->reloc_count
)));
5097 if (internal_relocs
== NULL
)
5100 /* Call processor specific code to relocate the section
5102 if (! bfd_coff_relocate_section (output_bfd
, finfo
->info
,
5106 finfo
->internal_syms
,
5107 xcoff_data (input_bfd
)->csects
))
5110 offset
= o
->output_section
->vma
+ o
->output_offset
- o
->vma
;
5111 irel
= internal_relocs
;
5112 irelend
= irel
+ o
->reloc_count
;
5113 rel_hash
= (finfo
->section_info
[target_index
].rel_hashes
5114 + o
->output_section
->reloc_count
);
5115 for (; irel
< irelend
; irel
++, rel_hash
++)
5117 struct xcoff_link_hash_entry
*h
= NULL
;
5118 struct internal_ldrel ldrel
;
5123 /* Adjust the reloc address and symbol index. */
5125 irel
->r_vaddr
+= offset
;
5127 r_symndx
= irel
->r_symndx
;
5132 h
= obj_xcoff_sym_hashes (input_bfd
)[r_symndx
];
5134 if (r_symndx
!= -1 && finfo
->info
->strip
!= strip_all
)
5137 && h
->smclas
!= XMC_TD
5138 && (irel
->r_type
== R_TOC
5139 || irel
->r_type
== R_GL
5140 || irel
->r_type
== R_TCL
5141 || irel
->r_type
== R_TRL
5142 || irel
->r_type
== R_TRLA
))
5144 /* This is a TOC relative reloc with a symbol
5145 attached. The symbol should be the one which
5146 this reloc is for. We want to make this
5147 reloc against the TOC address of the symbol,
5148 not the symbol itself. */
5149 BFD_ASSERT (h
->toc_section
!= NULL
);
5150 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
5151 if (h
->u
.toc_indx
!= -1)
5152 irel
->r_symndx
= h
->u
.toc_indx
;
5155 struct xcoff_toc_rel_hash
*n
;
5156 struct xcoff_link_section_info
*si
;
5159 amt
= sizeof (struct xcoff_toc_rel_hash
);
5160 n
= ((struct xcoff_toc_rel_hash
*)
5161 bfd_alloc (finfo
->output_bfd
, amt
));
5164 si
= finfo
->section_info
+ target_index
;
5165 n
->next
= si
->toc_rel_hashes
;
5168 si
->toc_rel_hashes
= n
;
5173 /* This is a global symbol. */
5175 irel
->r_symndx
= h
->indx
;
5178 /* This symbol is being written at the end
5179 of the file, and we do not yet know the
5180 symbol index. We save the pointer to the
5181 hash table entry in the rel_hash list.
5182 We set the indx field to -2 to indicate
5183 that this symbol must not be stripped. */
5192 indx
= finfo
->sym_indices
[r_symndx
];
5196 struct internal_syment
*is
;
5198 /* Relocations against a TC0 TOC anchor are
5199 automatically transformed to be against
5200 the TOC anchor in the output file. */
5201 is
= finfo
->internal_syms
+ r_symndx
;
5202 if (is
->n_sclass
== C_HIDEXT
5203 && is
->n_numaux
> 0)
5206 union internal_auxent aux
;
5210 obj_coff_external_syms (input_bfd
))
5211 + ((r_symndx
+ is
->n_numaux
)
5213 bfd_coff_swap_aux_in (input_bfd
, auxptr
,
5214 is
->n_type
, is
->n_sclass
,
5218 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_SD
5219 && aux
.x_csect
.x_smclas
== XMC_TC0
)
5220 indx
= finfo
->toc_symindx
;
5225 irel
->r_symndx
= indx
;
5229 struct internal_syment
*is
;
5232 char buf
[SYMNMLEN
+ 1];
5234 /* This reloc is against a symbol we are
5235 stripping. It would be possible to handle
5236 this case, but I don't think it's worth it. */
5237 is
= finfo
->internal_syms
+ r_symndx
;
5239 name
= (_bfd_coff_internal_syment_name
5240 (input_bfd
, is
, buf
));
5245 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
5246 (finfo
->info
, name
, input_bfd
, o
,
5254 switch (irel
->r_type
)
5258 || h
->root
.type
== bfd_link_hash_defined
5259 || h
->root
.type
== bfd_link_hash_defweak
5260 || h
->root
.type
== bfd_link_hash_common
)
5267 /* This reloc needs to be copied into the .loader
5269 ldrel
.l_vaddr
= irel
->r_vaddr
;
5271 ldrel
.l_symndx
= -(bfd_size_type
) 1;
5273 || (h
->root
.type
== bfd_link_hash_defined
5274 || h
->root
.type
== bfd_link_hash_defweak
5275 || h
->root
.type
== bfd_link_hash_common
))
5280 sec
= xcoff_data (input_bfd
)->csects
[r_symndx
];
5281 else if (h
->root
.type
== bfd_link_hash_common
)
5282 sec
= h
->root
.u
.c
.p
->section
;
5284 sec
= h
->root
.u
.def
.section
;
5285 sec
= sec
->output_section
;
5287 if (strcmp (sec
->name
, ".text") == 0)
5289 else if (strcmp (sec
->name
, ".data") == 0)
5291 else if (strcmp (sec
->name
, ".bss") == 0)
5295 (*_bfd_error_handler
)
5296 (_("%s: loader reloc in unrecognized section `%s'"),
5297 bfd_archive_filename (input_bfd
),
5299 bfd_set_error (bfd_error_nonrepresentable_section
);
5305 if (! finfo
->info
->relocateable
5306 && (h
->flags
& XCOFF_DEF_DYNAMIC
) == 0
5307 && (h
->flags
& XCOFF_IMPORT
) == 0)
5309 /* We already called the undefined_symbol
5310 callback for this relocation, in
5311 _bfd_ppc_xcoff_relocate_section. Don't
5312 issue any more warnings. */
5315 if (h
->ldindx
< 0 && ! quiet
)
5317 (*_bfd_error_handler
)
5318 (_("%s: `%s' in loader reloc but not loader sym"),
5319 bfd_archive_filename (input_bfd
),
5320 h
->root
.root
.string
);
5321 bfd_set_error (bfd_error_bad_value
);
5324 ldrel
.l_symndx
= h
->ldindx
;
5326 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
5327 ldrel
.l_rsecnm
= o
->output_section
->target_index
;
5328 if (xcoff_hash_table (finfo
->info
)->textro
5329 && strcmp (o
->output_section
->name
, ".text") == 0
5332 (*_bfd_error_handler
)
5333 (_("%s: loader reloc in read-only section %s"),
5334 bfd_archive_filename (input_bfd
),
5335 bfd_get_section_name (finfo
->output_bfd
,
5336 o
->output_section
));
5337 bfd_set_error (bfd_error_invalid_operation
);
5340 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
,
5343 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5351 /* We should never need a .loader reloc for a TOC
5357 o
->output_section
->reloc_count
+= o
->reloc_count
;
5360 /* Write out the modified section contents. */
5361 if (! bfd_set_section_contents (output_bfd
, o
->output_section
,
5362 contents
, (file_ptr
) o
->output_offset
,
5363 (o
->_cooked_size
!= 0
5369 obj_coff_keep_syms (input_bfd
) = keep_syms
;
5371 if (! finfo
->info
->keep_memory
)
5373 if (! _bfd_coff_free_symbols (input_bfd
))
5383 /* Write out a non-XCOFF global symbol. */
5387 xcoff_write_global_symbol (h
, inf
)
5388 struct xcoff_link_hash_entry
*h
;
5391 struct xcoff_final_link_info
*finfo
= (struct xcoff_final_link_info
*) inf
;
5394 struct internal_syment isym
;
5395 union internal_auxent aux
;
5400 output_bfd
= finfo
->output_bfd
;
5401 outsym
= finfo
->outsyms
;
5403 /* If this symbol was garbage collected, just skip it. */
5404 if (xcoff_hash_table (finfo
->info
)->gc
5405 && (h
->flags
& XCOFF_MARK
) == 0)
5408 /* If we need a .loader section entry, write it out. */
5409 if (h
->ldsym
!= NULL
)
5411 struct internal_ldsym
*ldsym
;
5416 if (h
->root
.type
== bfd_link_hash_undefined
5417 || h
->root
.type
== bfd_link_hash_undefweak
)
5421 ldsym
->l_scnum
= N_UNDEF
;
5422 ldsym
->l_smtype
= XTY_ER
;
5423 impbfd
= h
->root
.u
.undef
.abfd
;
5426 else if (h
->root
.type
== bfd_link_hash_defined
5427 || h
->root
.type
== bfd_link_hash_defweak
)
5432 sec
= h
->root
.u
.def
.section
;
5433 ldsym
->l_value
= (sec
->output_section
->vma
5434 + sec
->output_offset
5435 + h
->root
.u
.def
.value
);
5436 ldsym
->l_scnum
= sec
->output_section
->target_index
;
5437 ldsym
->l_smtype
= XTY_SD
;
5438 impbfd
= sec
->owner
;
5444 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
5445 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
5446 || (h
->flags
& XCOFF_IMPORT
) != 0)
5449 Import symbols are defined so the check above will make
5450 the l_smtype XTY_SD. But this is not correct, it should
5452 ldsym
->l_smtype
|= L_IMPORT
;
5455 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
5456 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
5457 || (h
->flags
& XCOFF_EXPORT
) != 0)
5459 ldsym
->l_smtype
|= L_EXPORT
;
5462 if ((h
->flags
& XCOFF_ENTRY
) != 0)
5464 ldsym
->l_smtype
|= L_ENTRY
;
5467 if ((h
->flags
& XCOFF_RTINIT
) != 0)
5469 ldsym
->l_smtype
= XTY_SD
;
5472 ldsym
->l_smclas
= h
->smclas
;
5474 if (ldsym
->l_smtype
& L_IMPORT
)
5476 if ((h
->root
.type
== bfd_link_hash_defined
5477 || h
->root
.type
== bfd_link_hash_defweak
)
5478 && (h
->root
.u
.def
.value
!= 0))
5480 ldsym
->l_smclas
= XMC_XO
;
5482 else if ((h
->flags
& (XCOFF_SYSCALL32
| XCOFF_SYSCALL64
)) ==
5483 (XCOFF_SYSCALL32
| XCOFF_SYSCALL64
))
5485 ldsym
->l_smclas
= XMC_SV3264
;
5487 else if (h
->flags
& XCOFF_SYSCALL32
)
5489 ldsym
->l_smclas
= XMC_SV
;
5491 else if (h
->flags
& XCOFF_SYSCALL64
)
5493 ldsym
->l_smclas
= XMC_SV64
;
5497 if (ldsym
->l_ifile
== -(bfd_size_type
) 1)
5501 else if (ldsym
->l_ifile
== 0)
5503 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
5507 else if (impbfd
== NULL
)
5513 BFD_ASSERT (impbfd
->xvec
== output_bfd
->xvec
);
5514 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
5520 BFD_ASSERT (h
->ldindx
>= 0);
5522 bfd_xcoff_swap_ldsym_out (output_bfd
, ldsym
,
5525 * bfd_xcoff_ldsymsz(finfo
->output_bfd
)));
5529 /* If this symbol needs global linkage code, write it out. */
5530 if (h
->root
.type
== bfd_link_hash_defined
5531 && (h
->root
.u
.def
.section
5532 == xcoff_hash_table (finfo
->info
)->linkage_section
))
5538 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
5540 /* The first instruction in the global linkage code loads a
5541 specific TOC element. */
5542 tocoff
= (h
->descriptor
->toc_section
->output_section
->vma
5543 + h
->descriptor
->toc_section
->output_offset
5544 - xcoff_data (output_bfd
)->toc
);
5546 if ((h
->descriptor
->flags
& XCOFF_SET_TOC
) != 0)
5548 tocoff
+= h
->descriptor
->u
.toc_offset
;
5552 /* The first instruction in the glink code needs to be
5553 cooked to to hold the correct offset in the toc. The
5554 rest are just output raw. */
5555 bfd_put_32 (output_bfd
,
5556 bfd_xcoff_glink_code(output_bfd
, 0) | (tocoff
& 0xffff), p
);
5558 /* Start with i == 1 to get past the first instruction done above
5559 The /4 is because the glink code is in bytes and we are going
5561 for (i
= 1; i
< bfd_xcoff_glink_code_size(output_bfd
) / 4; i
++)
5563 bfd_put_32 (output_bfd
,
5564 (bfd_vma
) bfd_xcoff_glink_code(output_bfd
, i
),
5569 /* If we created a TOC entry for this symbol, write out the required
5571 if ((h
->flags
& XCOFF_SET_TOC
) != 0)
5576 struct internal_reloc
*irel
;
5577 struct internal_ldrel ldrel
;
5578 struct internal_syment irsym
;
5579 union internal_auxent iraux
;
5581 tocsec
= h
->toc_section
;
5582 osec
= tocsec
->output_section
;
5583 oindx
= osec
->target_index
;
5584 irel
= finfo
->section_info
[oindx
].relocs
+ osec
->reloc_count
;
5585 irel
->r_vaddr
= (osec
->vma
5586 + tocsec
->output_offset
5592 irel
->r_symndx
= h
->indx
;
5597 irel
->r_symndx
= obj_raw_syment_count (output_bfd
);
5600 BFD_ASSERT (h
->ldindx
>= 0);
5602 /* Initialize the aux union here instead of closer to when it is
5603 written out below because the length of the csect depends on
5604 whether the output is 32 or 64 bit. */
5605 memset (&iraux
, 0, sizeof iraux
);
5606 iraux
.x_csect
.x_smtyp
= XTY_SD
;
5607 /* iraux.x_csect.x_scnlen.l = 4 or 8, see below */
5608 iraux
.x_csect
.x_smclas
= XMC_TC
;
5610 /* 32 bit uses a 32 bit R_POS to do the relocations
5611 64 bit uses a 64 bit R_POS to do the relocations
5613 Also needs to change the csect size : 4 for 32 bit, 8 for 64 bit
5615 Which one is determined by the backend. */
5616 if (bfd_xcoff_is_xcoff64 (output_bfd
))
5619 iraux
.x_csect
.x_scnlen
.l
= 8;
5621 else if (bfd_xcoff_is_xcoff32 (output_bfd
))
5624 iraux
.x_csect
.x_scnlen
.l
= 4;
5630 irel
->r_type
= R_POS
;
5631 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
5632 ++osec
->reloc_count
;
5634 ldrel
.l_vaddr
= irel
->r_vaddr
;
5635 ldrel
.l_symndx
= h
->ldindx
;
5636 ldrel
.l_rtype
= (irel
->r_size
<< 8) | R_POS
;
5637 ldrel
.l_rsecnm
= oindx
;
5638 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5639 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5641 /* We need to emit a symbol to define a csect which holds
5643 if (finfo
->info
->strip
!= strip_all
)
5646 result
= bfd_xcoff_put_symbol_name (output_bfd
, finfo
->strtab
,
5647 &irsym
, h
->root
.root
.string
);
5648 if (false == result
)
5653 irsym
.n_value
= irel
->r_vaddr
;
5654 irsym
.n_scnum
= osec
->target_index
;
5655 irsym
.n_sclass
= C_HIDEXT
;
5656 irsym
.n_type
= T_NULL
;
5659 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &irsym
, (PTR
) outsym
);
5660 outsym
+= bfd_coff_symesz (output_bfd
);
5662 /* note : iraux is initialized above */
5663 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &iraux
, T_NULL
, C_HIDEXT
,
5664 0, 1, (PTR
) outsym
);
5665 outsym
+= bfd_coff_auxesz (output_bfd
);
5669 /* We aren't going to write out the symbols below, so we
5670 need to write them out now. */
5671 pos
= obj_sym_filepos (output_bfd
);
5672 pos
+= (obj_raw_syment_count (output_bfd
)
5673 * bfd_coff_symesz (output_bfd
));
5674 amt
= outsym
- finfo
->outsyms
;
5675 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
5676 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
5678 obj_raw_syment_count (output_bfd
) +=
5679 (outsym
- finfo
->outsyms
) / bfd_coff_symesz (output_bfd
);
5681 outsym
= finfo
->outsyms
;
5686 /* If this symbol is a specially defined function descriptor, write
5687 it out. The first word is the address of the function code
5688 itself, the second word is the address of the TOC, and the third
5692 The addresses for the 32 bit will take 4 bytes and the addresses
5693 for 64 bit will take 8 bytes. Similar for the relocs. This type
5694 of logic was also done above to create a TOC entry in
5695 xcoff_write_global_symbol. */
5696 if ((h
->flags
& XCOFF_DESCRIPTOR
) != 0
5697 && h
->root
.type
== bfd_link_hash_defined
5698 && (h
->root
.u
.def
.section
5699 == xcoff_hash_table (finfo
->info
)->descriptor_section
))
5705 struct xcoff_link_hash_entry
*hentry
;
5707 struct internal_reloc
*irel
;
5708 struct internal_ldrel ldrel
;
5710 unsigned int reloc_size
, byte_size
;
5712 if (bfd_xcoff_is_xcoff64 (output_bfd
))
5717 else if (bfd_xcoff_is_xcoff32 (output_bfd
))
5727 sec
= h
->root
.u
.def
.section
;
5728 osec
= sec
->output_section
;
5729 oindx
= osec
->target_index
;
5730 p
= sec
->contents
+ h
->root
.u
.def
.value
;
5732 hentry
= h
->descriptor
;
5733 BFD_ASSERT (hentry
!= NULL
5734 && (hentry
->root
.type
== bfd_link_hash_defined
5735 || hentry
->root
.type
== bfd_link_hash_defweak
));
5736 esec
= hentry
->root
.u
.def
.section
;
5738 irel
= finfo
->section_info
[oindx
].relocs
+ osec
->reloc_count
;
5739 irel
->r_vaddr
= (osec
->vma
5740 + sec
->output_offset
5741 + h
->root
.u
.def
.value
);
5742 irel
->r_symndx
= esec
->output_section
->target_index
;
5743 irel
->r_type
= R_POS
;
5744 irel
->r_size
= reloc_size
;
5745 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
5746 ++osec
->reloc_count
;
5748 ldrel
.l_vaddr
= irel
->r_vaddr
;
5749 if (strcmp (esec
->output_section
->name
, ".text") == 0)
5751 else if (strcmp (esec
->output_section
->name
, ".data") == 0)
5753 else if (strcmp (esec
->output_section
->name
, ".bss") == 0)
5757 (*_bfd_error_handler
)
5758 (_("%s: loader reloc in unrecognized section `%s'"),
5759 bfd_get_filename (output_bfd
),
5760 esec
->output_section
->name
);
5761 bfd_set_error (bfd_error_nonrepresentable_section
);
5764 ldrel
.l_rtype
= (reloc_size
<< 8) | R_POS
;
5765 ldrel
.l_rsecnm
= oindx
;
5766 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5767 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5769 /* There are three items to write out,
5770 the address of the code
5771 the address of the toc anchor
5772 the environment pointer.
5773 We are ignoring the environment pointer. So set it to zero. */
5774 if (bfd_xcoff_is_xcoff64 (output_bfd
))
5776 bfd_put_64 (output_bfd
,
5777 (esec
->output_section
->vma
+ esec
->output_offset
5778 + hentry
->root
.u
.def
.value
),
5780 bfd_put_64 (output_bfd
, xcoff_data (output_bfd
)->toc
, p
+ 8);
5781 bfd_put_64 (output_bfd
, (bfd_vma
) 0, p
+ 16);
5786 This logic was already called above so the error case where
5787 the backend is neither has already been checked. */
5788 bfd_put_32 (output_bfd
,
5789 (esec
->output_section
->vma
+ esec
->output_offset
5790 + hentry
->root
.u
.def
.value
),
5792 bfd_put_32 (output_bfd
, xcoff_data (output_bfd
)->toc
, p
+ 4);
5793 bfd_put_32 (output_bfd
, (bfd_vma
) 0, p
+ 8);
5796 tsec
= coff_section_from_bfd_index (output_bfd
,
5797 xcoff_data (output_bfd
)->sntoc
);
5800 irel
->r_vaddr
= (osec
->vma
5801 + sec
->output_offset
5802 + h
->root
.u
.def
.value
5804 irel
->r_symndx
= tsec
->output_section
->target_index
;
5805 irel
->r_type
= R_POS
;
5806 irel
->r_size
= reloc_size
;
5807 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
5808 ++osec
->reloc_count
;
5810 ldrel
.l_vaddr
= irel
->r_vaddr
;
5811 if (strcmp (tsec
->output_section
->name
, ".text") == 0)
5813 else if (strcmp (tsec
->output_section
->name
, ".data") == 0)
5815 else if (strcmp (tsec
->output_section
->name
, ".bss") == 0)
5819 (*_bfd_error_handler
)
5820 (_("%s: loader reloc in unrecognized section `%s'"),
5821 bfd_get_filename (output_bfd
),
5822 tsec
->output_section
->name
);
5823 bfd_set_error (bfd_error_nonrepresentable_section
);
5826 ldrel
.l_rtype
= (reloc_size
<< 8) | R_POS
;
5827 ldrel
.l_rsecnm
= oindx
;
5828 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5829 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
5832 if (h
->indx
>= 0 || finfo
->info
->strip
== strip_all
)
5834 BFD_ASSERT (outsym
== finfo
->outsyms
);
5839 && (finfo
->info
->strip
== strip_all
5840 || (finfo
->info
->strip
== strip_some
5841 && bfd_hash_lookup (finfo
->info
->keep_hash
, h
->root
.root
.string
,
5842 false, false) == NULL
)))
5844 BFD_ASSERT (outsym
== finfo
->outsyms
);
5849 && (h
->flags
& (XCOFF_REF_REGULAR
| XCOFF_DEF_REGULAR
)) == 0)
5851 BFD_ASSERT (outsym
== finfo
->outsyms
);
5855 memset (&aux
, 0, sizeof aux
);
5857 h
->indx
= obj_raw_syment_count (output_bfd
);
5859 result
= bfd_xcoff_put_symbol_name (output_bfd
, finfo
->strtab
, &isym
,
5860 h
->root
.root
.string
);
5861 if (false == result
)
5866 if (h
->root
.type
== bfd_link_hash_undefined
5867 || h
->root
.type
== bfd_link_hash_undefweak
)
5870 isym
.n_scnum
= N_UNDEF
;
5871 isym
.n_sclass
= C_EXT
;
5872 aux
.x_csect
.x_smtyp
= XTY_ER
;
5874 else if ((h
->root
.type
== bfd_link_hash_defined
5875 || h
->root
.type
== bfd_link_hash_defweak
)
5876 && h
->smclas
== XMC_XO
)
5878 BFD_ASSERT (bfd_is_abs_section (h
->root
.u
.def
.section
));
5879 isym
.n_value
= h
->root
.u
.def
.value
;
5880 isym
.n_scnum
= N_UNDEF
;
5881 isym
.n_sclass
= C_EXT
;
5882 aux
.x_csect
.x_smtyp
= XTY_ER
;
5884 else if (h
->root
.type
== bfd_link_hash_defined
5885 || h
->root
.type
== bfd_link_hash_defweak
)
5887 struct xcoff_link_size_list
*l
;
5889 isym
.n_value
= (h
->root
.u
.def
.section
->output_section
->vma
5890 + h
->root
.u
.def
.section
->output_offset
5891 + h
->root
.u
.def
.value
);
5892 isym
.n_scnum
= h
->root
.u
.def
.section
->output_section
->target_index
;
5893 isym
.n_sclass
= C_HIDEXT
;
5894 aux
.x_csect
.x_smtyp
= XTY_SD
;
5896 if ((h
->flags
& XCOFF_HAS_SIZE
) != 0)
5898 for (l
= xcoff_hash_table (finfo
->info
)->size_list
;
5904 aux
.x_csect
.x_scnlen
.l
= l
->size
;
5910 else if (h
->root
.type
== bfd_link_hash_common
)
5912 isym
.n_value
= (h
->root
.u
.c
.p
->section
->output_section
->vma
5913 + h
->root
.u
.c
.p
->section
->output_offset
);
5914 isym
.n_scnum
= h
->root
.u
.c
.p
->section
->output_section
->target_index
;
5915 isym
.n_sclass
= C_EXT
;
5916 aux
.x_csect
.x_smtyp
= XTY_CM
;
5917 aux
.x_csect
.x_scnlen
.l
= h
->root
.u
.c
.size
;
5922 isym
.n_type
= T_NULL
;
5925 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
5926 outsym
+= bfd_coff_symesz (output_bfd
);
5928 aux
.x_csect
.x_smclas
= h
->smclas
;
5929 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, T_NULL
, isym
.n_sclass
, 0, 1,
5931 outsym
+= bfd_coff_auxesz (output_bfd
);
5933 if ((h
->root
.type
== bfd_link_hash_defined
5934 || h
->root
.type
== bfd_link_hash_defweak
)
5935 && h
->smclas
!= XMC_XO
)
5937 /* We just output an SD symbol. Now output an LD symbol. */
5941 isym
.n_sclass
= C_EXT
;
5942 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
5943 outsym
+= bfd_coff_symesz (output_bfd
);
5945 aux
.x_csect
.x_smtyp
= XTY_LD
;
5946 aux
.x_csect
.x_scnlen
.l
= obj_raw_syment_count (output_bfd
);
5947 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, T_NULL
, C_EXT
, 0, 1,
5949 outsym
+= bfd_coff_auxesz (output_bfd
);
5952 pos
= obj_sym_filepos (output_bfd
);
5953 pos
+= obj_raw_syment_count (output_bfd
) * bfd_coff_symesz (output_bfd
);
5954 amt
= outsym
- finfo
->outsyms
;
5955 if (bfd_seek (output_bfd
, pos
, SEEK_SET
) != 0
5956 || bfd_bwrite (finfo
->outsyms
, amt
, output_bfd
) != amt
)
5958 obj_raw_syment_count (output_bfd
) +=
5959 (outsym
- finfo
->outsyms
) / bfd_coff_symesz (output_bfd
);
5964 /* Handle a link order which is supposed to generate a reloc. */
5967 xcoff_reloc_link_order (output_bfd
, finfo
, output_section
, link_order
)
5969 struct xcoff_final_link_info
*finfo
;
5970 asection
*output_section
;
5971 struct bfd_link_order
*link_order
;
5973 reloc_howto_type
*howto
;
5974 struct xcoff_link_hash_entry
*h
;
5978 struct internal_reloc
*irel
;
5979 struct xcoff_link_hash_entry
**rel_hash_ptr
;
5980 struct internal_ldrel ldrel
;
5982 if (link_order
->type
== bfd_section_reloc_link_order
)
5984 /* We need to somehow locate a symbol in the right section. The
5985 symbol must either have a value of zero, or we must adjust
5986 the addend by the value of the symbol. FIXME: Write this
5987 when we need it. The old linker couldn't handle this anyhow. */
5991 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
5994 bfd_set_error (bfd_error_bad_value
);
5998 h
= ((struct xcoff_link_hash_entry
*)
5999 bfd_wrapped_link_hash_lookup (output_bfd
, finfo
->info
,
6000 link_order
->u
.reloc
.p
->u
.name
,
6001 false, false, true));
6004 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
6005 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
6006 (asection
*) NULL
, (bfd_vma
) 0)))
6011 if (h
->root
.type
== bfd_link_hash_common
)
6013 hsec
= h
->root
.u
.c
.p
->section
;
6016 else if (h
->root
.type
== bfd_link_hash_defined
6017 || h
->root
.type
== bfd_link_hash_defweak
)
6019 hsec
= h
->root
.u
.def
.section
;
6020 hval
= h
->root
.u
.def
.value
;
6028 addend
= link_order
->u
.reloc
.p
->addend
;
6030 addend
+= (hsec
->output_section
->vma
6031 + hsec
->output_offset
6038 bfd_reloc_status_type rstat
;
6041 size
= bfd_get_reloc_size (howto
);
6042 buf
= (bfd_byte
*) bfd_zmalloc (size
);
6046 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
6052 case bfd_reloc_outofrange
:
6054 case bfd_reloc_overflow
:
6055 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
6056 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
,
6057 howto
->name
, addend
, (bfd
*) NULL
, (asection
*) NULL
,
6065 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
6066 (file_ptr
) link_order
->offset
, size
);
6072 /* Store the reloc information in the right place. It will get
6073 swapped and written out at the end of the final_link routine. */
6075 irel
= (finfo
->section_info
[output_section
->target_index
].relocs
6076 + output_section
->reloc_count
);
6077 rel_hash_ptr
= (finfo
->section_info
[output_section
->target_index
].rel_hashes
6078 + output_section
->reloc_count
);
6080 memset (irel
, 0, sizeof (struct internal_reloc
));
6081 *rel_hash_ptr
= NULL
;
6083 irel
->r_vaddr
= output_section
->vma
+ link_order
->offset
;
6086 irel
->r_symndx
= h
->indx
;
6089 /* Set the index to -2 to force this symbol to get written out. */
6095 irel
->r_type
= howto
->type
;
6096 irel
->r_size
= howto
->bitsize
- 1;
6097 if (howto
->complain_on_overflow
== complain_overflow_signed
)
6098 irel
->r_size
|= 0x80;
6100 ++output_section
->reloc_count
;
6102 /* Now output the reloc to the .loader section. */
6104 ldrel
.l_vaddr
= irel
->r_vaddr
;
6108 const char *secname
;
6110 secname
= hsec
->output_section
->name
;
6112 if (strcmp (secname
, ".text") == 0)
6114 else if (strcmp (secname
, ".data") == 0)
6116 else if (strcmp (secname
, ".bss") == 0)
6120 (*_bfd_error_handler
)
6121 (_("%s: loader reloc in unrecognized section `%s'"),
6122 bfd_get_filename (output_bfd
), secname
);
6123 bfd_set_error (bfd_error_nonrepresentable_section
);
6131 (*_bfd_error_handler
)
6132 (_("%s: `%s' in loader reloc but not loader sym"),
6133 bfd_get_filename (output_bfd
),
6134 h
->root
.root
.string
);
6135 bfd_set_error (bfd_error_bad_value
);
6138 ldrel
.l_symndx
= h
->ldindx
;
6141 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
6142 ldrel
.l_rsecnm
= output_section
->target_index
;
6143 bfd_xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
6144 finfo
->ldrel
+= bfd_xcoff_ldrelsz(output_bfd
);
6149 /* Sort relocs by VMA. This is called via qsort. */
6152 xcoff_sort_relocs (p1
, p2
)
6156 const struct internal_reloc
*r1
= (const struct internal_reloc
*) p1
;
6157 const struct internal_reloc
*r2
= (const struct internal_reloc
*) p2
;
6159 if (r1
->r_vaddr
> r2
->r_vaddr
)
6161 else if (r1
->r_vaddr
< r2
->r_vaddr
)