1 /* POWER/PowerPC XCOFF linker support.
2 Copyright 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <ian@cygnus.com>, Cygnus Support.
5 This file is part of BFD, the Binary File Descriptor library.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 #include "coff/internal.h"
28 /* This file holds the XCOFF linker code. */
30 #define STRING_SIZE_SIZE (4)
32 /* In order to support linking different object file formats into an
33 XCOFF format, we need to be able to determine whether a particular
34 bfd_target is an XCOFF vector. FIXME: We need to rethink this
36 #define XCOFF_XVECP(xv) \
37 (strcmp ((xv)->name, "aixcoff-rs6000") == 0 \
38 || strcmp ((xv)->name, "xcoff-powermac") == 0)
40 /* Get the XCOFF hash table entries for a BFD. */
41 #define obj_xcoff_sym_hashes(bfd) \
42 ((struct xcoff_link_hash_entry **) obj_coff_sym_hashes (bfd))
44 /* XCOFF relocation types. These probably belong in a header file
45 somewhere. The relocations are described in the function
46 _bfd_ppc_xcoff_relocate_section in this file. */
62 #define R_RRTBI (0x14)
63 #define R_RRTBA (0x15)
71 /* The first word of global linkage code. This must be modified by
72 filling in the correct TOC offset. */
74 #define XCOFF_GLINK_FIRST (0x81820000) /* lwz r12,0(r2) */
76 /* The remaining words of global linkage code. */
78 static unsigned long xcoff_glink_code
[] =
80 0x90410014, /* stw r2,20(r1) */
81 0x800c0000, /* lwz r0,0(r12) */
82 0x804c0004, /* lwz r2,4(r12) */
83 0x7c0903a6, /* mtctr r0 */
84 0x4e800420, /* bctr */
85 0x0, /* start of traceback table */
86 0x000c8000, /* traceback table */
87 0x0 /* traceback table */
90 #define XCOFF_GLINK_SIZE \
91 (((sizeof xcoff_glink_code / sizeof xcoff_glink_code[0]) * 4) + 4)
93 /* We reuse the SEC_ROM flag as a mark flag for garbage collection.
94 This flag will only be used on input sections. */
96 #define SEC_MARK (SEC_ROM)
98 /* The ldhdr structure. This appears at the start of the .loader
101 struct internal_ldhdr
103 /* The version number: currently always 1. */
104 unsigned long l_version
;
105 /* The number of symbol table entries. */
106 bfd_size_type l_nsyms
;
107 /* The number of relocation table entries. */
108 bfd_size_type l_nreloc
;
109 /* The length of the import file string table. */
110 bfd_size_type l_istlen
;
111 /* The number of import files. */
112 bfd_size_type l_nimpid
;
113 /* The offset from the start of the .loader section to the first
114 entry in the import file table. */
115 bfd_size_type l_impoff
;
116 /* The length of the string table. */
117 bfd_size_type l_stlen
;
118 /* The offset from the start of the .loader section to the first
119 entry in the string table. */
120 bfd_size_type l_stoff
;
123 struct external_ldhdr
125 bfd_byte l_version
[4];
127 bfd_byte l_nreloc
[4];
128 bfd_byte l_istlen
[4];
129 bfd_byte l_nimpid
[4];
130 bfd_byte l_impoff
[4];
135 #define LDHDRSZ (8 * 4)
137 /* The ldsym structure. This is used to represent a symbol in the
140 struct internal_ldsym
144 /* The symbol name if <= SYMNMLEN characters. */
145 char _l_name
[SYMNMLEN
];
148 /* Zero if the symbol name is more than SYMNMLEN characters. */
150 /* The offset in the string table if the symbol name is more
151 than SYMNMLEN characters. */
155 /* The symbol value. */
157 /* The symbol section number. */
159 /* The symbol type and flags. */
161 /* The symbol storage class. */
163 /* The import file ID. */
164 bfd_size_type l_ifile
;
165 /* Offset to the parameter type check string. */
166 bfd_size_type l_parm
;
169 struct external_ldsym
173 bfd_byte _l_name
[SYMNMLEN
];
176 bfd_byte _l_zeroes
[4];
177 bfd_byte _l_offset
[4];
182 bfd_byte l_smtype
[1];
183 bfd_byte l_smclas
[1];
188 #define LDSYMSZ (8 + 3 * 4 + 2 + 2)
190 /* These flags are for the l_smtype field (the lower three bits are an
193 /* Imported symbol. */
194 #define L_IMPORT (0x40)
196 #define L_ENTRY (0x20)
197 /* Exported symbol. */
198 #define L_EXPORT (0x10)
200 /* The ldrel structure. This is used to represent a reloc in the
203 struct internal_ldrel
205 /* The reloc address. */
207 /* The symbol table index in the .loader section symbol table. */
208 bfd_size_type l_symndx
;
209 /* The relocation type and size. */
211 /* The section number this relocation applies to. */
215 struct external_ldrel
218 bfd_byte l_symndx
[4];
220 bfd_byte l_rsecnm
[2];
223 #define LDRELSZ (2 * 4 + 2 * 2)
225 /* The list of import files. */
227 struct xcoff_import_file
229 /* The next entry in the list. */
230 struct xcoff_import_file
*next
;
235 /* The member name. */
239 /* An entry in the XCOFF linker hash table. */
241 struct xcoff_link_hash_entry
243 struct bfd_link_hash_entry root
;
245 /* Symbol index in output file. Set to -1 initially. Set to -2 if
246 there is a reloc against this symbol. */
249 /* If we have created a TOC entry for this symbol, this is the .tc
250 section which holds it. */
251 asection
*toc_section
;
255 /* If we have created a TOC entry (the XCOFF_SET_TOC flag is
256 set), this is the offset in toc_section. */
258 /* If the TOC entry comes from an input file, this is set to the
259 symbo lindex of the C_HIDEXT XMC_TC symbol. */
263 /* If this symbol is a function entry point which is called, this
264 field holds a pointer to the function descriptor. */
265 struct xcoff_link_hash_entry
*descriptor
;
267 /* The .loader symbol table entry, if there is one. */
268 struct internal_ldsym
*ldsym
;
270 /* The .loader symbol table index. */
273 /* Some linker flags. */
274 unsigned short flags
;
275 /* Symbol is referenced by a regular object. */
276 #define XCOFF_REF_REGULAR (01)
277 /* Symbol is defined by a regular object. */
278 #define XCOFF_DEF_REGULAR (02)
279 /* Symbol is defined by a dynamic object. */
280 #define XCOFF_DEF_DYNAMIC (04)
281 /* Symbol is used in a reloc being copied into the .loader section. */
282 #define XCOFF_LDREL (010)
283 /* Symbol is the entry point. */
284 #define XCOFF_ENTRY (020)
285 /* Symbol is called; this is, it appears in a R_BR reloc. */
286 #define XCOFF_CALLED (040)
287 /* Symbol needs the TOC entry filled in. */
288 #define XCOFF_SET_TOC (0100)
289 /* Symbol is explicitly imported. */
290 #define XCOFF_IMPORT (0200)
291 /* Symbol is explicitly exported. */
292 #define XCOFF_EXPORT (0400)
293 /* Symbol has been processed by xcoff_build_ldsyms. */
294 #define XCOFF_BUILT_LDSYM (01000)
295 /* Symbol is mentioned by a section which was not garbage collected. */
296 #define XCOFF_MARK (02000)
297 /* Symbol size is recorded in size_list list from hash table. */
298 #define XCOFF_HAS_SIZE (04000)
300 /* The storage mapping class. */
301 unsigned char smclas
;
304 /* The XCOFF linker hash table. */
306 struct xcoff_link_hash_table
308 struct bfd_link_hash_table root
;
310 /* The .debug string hash table. We need to compute this while
311 reading the input files, so that we know how large the .debug
312 section will be before we assign section positions. */
313 struct bfd_strtab_hash
*debug_strtab
;
315 /* The .debug section we will use for the final output. */
316 asection
*debug_section
;
318 /* The .loader section we will use for the final output. */
319 asection
*loader_section
;
321 /* A count of non TOC relative relocs which will need to be
322 allocated in the .loader section. */
325 /* The .loader section header. */
326 struct internal_ldhdr ldhdr
;
328 /* The .gl section we use to hold global linkage code. */
329 asection
*linkage_section
;
331 /* The .tc section we use to hold toc entries we build for global
333 asection
*toc_section
;
335 /* The list of import files. */
336 struct xcoff_import_file
*imports
;
338 /* Required alignment of sections within the output file. */
339 unsigned long file_align
;
341 /* Whether the .text section must be read-only. */
344 /* Whether garbage collection was done. */
347 /* A linked list of symbols for which we have size information. */
348 struct xcoff_link_size_list
350 struct xcoff_link_size_list
*next
;
351 struct xcoff_link_hash_entry
*h
;
356 /* Information we keep for each section in the output file during the
359 struct xcoff_link_section_info
361 /* The relocs to be output. */
362 struct internal_reloc
*relocs
;
363 /* For each reloc against a global symbol whose index was not known
364 when the reloc was handled, the global hash table entry. */
365 struct xcoff_link_hash_entry
**rel_hashes
;
366 /* If there is a TOC relative reloc against a global symbol, and the
367 index of the TOC symbol is not known when the reloc was handled,
368 an entry is added to this linked list. This is not an array,
369 like rel_hashes, because this case is quite uncommon. */
370 struct xcoff_toc_rel_hash
372 struct xcoff_toc_rel_hash
*next
;
373 struct xcoff_link_hash_entry
*h
;
374 struct internal_reloc
*rel
;
378 /* Information that we pass around while doing the final link step. */
380 struct xcoff_final_link_info
382 /* General link information. */
383 struct bfd_link_info
*info
;
386 /* Hash table for long symbol names. */
387 struct bfd_strtab_hash
*strtab
;
388 /* Array of information kept for each output section, indexed by the
389 target_index field. */
390 struct xcoff_link_section_info
*section_info
;
391 /* Symbol index of last C_FILE symbol (-1 if none). */
392 long last_file_index
;
393 /* Contents of last C_FILE symbol. */
394 struct internal_syment last_file
;
395 /* Symbol index of TOC symbol. */
397 /* Start of .loader symbols. */
398 struct external_ldsym
*ldsym
;
399 /* Next .loader reloc to swap out. */
400 struct external_ldrel
*ldrel
;
401 /* File position of start of line numbers. */
402 file_ptr line_filepos
;
403 /* Buffer large enough to hold swapped symbols of any input file. */
404 struct internal_syment
*internal_syms
;
405 /* Buffer large enough to hold output indices of symbols of any
408 /* Buffer large enough to hold output symbols for any input file. */
410 /* Buffer large enough to hold external line numbers for any input
413 /* Buffer large enough to hold any input section. */
415 /* Buffer large enough to hold external relocs of any input section. */
416 bfd_byte
*external_relocs
;
419 static void xcoff_swap_ldhdr_in
420 PARAMS ((bfd
*, const struct external_ldhdr
*, struct internal_ldhdr
*));
421 static void xcoff_swap_ldhdr_out
422 PARAMS ((bfd
*, const struct internal_ldhdr
*, struct external_ldhdr
*));
423 static void xcoff_swap_ldsym_in
424 PARAMS ((bfd
*, const struct external_ldsym
*, struct internal_ldsym
*));
425 static void xcoff_swap_ldsym_out
426 PARAMS ((bfd
*, const struct internal_ldsym
*, struct external_ldsym
*));
427 static void xcoff_swap_ldrel_out
428 PARAMS ((bfd
*, const struct internal_ldrel
*, struct external_ldrel
*));
429 static struct bfd_hash_entry
*xcoff_link_hash_newfunc
430 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
431 static struct internal_reloc
*xcoff_read_internal_relocs
432 PARAMS ((bfd
*, asection
*, boolean
, bfd_byte
*, boolean
,
433 struct internal_reloc
*));
434 static boolean xcoff_link_add_object_symbols
435 PARAMS ((bfd
*, struct bfd_link_info
*));
436 static boolean xcoff_link_check_archive_element
437 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
438 static boolean xcoff_link_check_ar_symbols
439 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
440 static bfd_size_type xcoff_find_reloc
441 PARAMS ((struct internal_reloc
*, bfd_size_type
, bfd_vma
));
442 static boolean xcoff_link_add_symbols
PARAMS ((bfd
*, struct bfd_link_info
*));
443 static boolean xcoff_link_add_dynamic_symbols
444 PARAMS ((bfd
*, struct bfd_link_info
*));
445 static boolean xcoff_mark
PARAMS ((struct bfd_link_info
*, asection
*));
446 static void xcoff_sweep
PARAMS ((struct bfd_link_info
*));
447 static boolean xcoff_build_ldsyms
448 PARAMS ((struct xcoff_link_hash_entry
*, PTR
));
449 static boolean xcoff_link_input_bfd
450 PARAMS ((struct xcoff_final_link_info
*, bfd
*));
451 static boolean xcoff_write_global_symbol
452 PARAMS ((struct xcoff_link_hash_entry
*, PTR
));
453 static boolean xcoff_reloc_link_order
454 PARAMS ((bfd
*, struct xcoff_final_link_info
*, asection
*,
455 struct bfd_link_order
*));
456 static int xcoff_sort_relocs
PARAMS ((const PTR
, const PTR
));
458 /* Routines to swap information in the XCOFF .loader section. If we
459 ever need to write an XCOFF loader, this stuff will need to be
460 moved to another file shared by the linker (which XCOFF calls the
461 ``binder'') and the loader. */
463 /* Swap in the ldhdr structure. */
466 xcoff_swap_ldhdr_in (abfd
, src
, dst
)
468 const struct external_ldhdr
*src
;
469 struct internal_ldhdr
*dst
;
471 dst
->l_version
= bfd_get_32 (abfd
, src
->l_version
);
472 dst
->l_nsyms
= bfd_get_32 (abfd
, src
->l_nsyms
);
473 dst
->l_nreloc
= bfd_get_32 (abfd
, src
->l_nreloc
);
474 dst
->l_istlen
= bfd_get_32 (abfd
, src
->l_istlen
);
475 dst
->l_nimpid
= bfd_get_32 (abfd
, src
->l_nimpid
);
476 dst
->l_impoff
= bfd_get_32 (abfd
, src
->l_impoff
);
477 dst
->l_stlen
= bfd_get_32 (abfd
, src
->l_stlen
);
478 dst
->l_stoff
= bfd_get_32 (abfd
, src
->l_stoff
);
481 /* Swap out the ldhdr structure. */
484 xcoff_swap_ldhdr_out (abfd
, src
, dst
)
486 const struct internal_ldhdr
*src
;
487 struct external_ldhdr
*dst
;
489 bfd_put_32 (abfd
, src
->l_version
, dst
->l_version
);
490 bfd_put_32 (abfd
, src
->l_nsyms
, dst
->l_nsyms
);
491 bfd_put_32 (abfd
, src
->l_nreloc
, dst
->l_nreloc
);
492 bfd_put_32 (abfd
, src
->l_istlen
, dst
->l_istlen
);
493 bfd_put_32 (abfd
, src
->l_nimpid
, dst
->l_nimpid
);
494 bfd_put_32 (abfd
, src
->l_impoff
, dst
->l_impoff
);
495 bfd_put_32 (abfd
, src
->l_stlen
, dst
->l_stlen
);
496 bfd_put_32 (abfd
, src
->l_stoff
, dst
->l_stoff
);
499 /* Swap in the ldsym structure. */
502 xcoff_swap_ldsym_in (abfd
, src
, dst
)
504 const struct external_ldsym
*src
;
505 struct internal_ldsym
*dst
;
507 if (bfd_get_32 (abfd
, src
->_l
._l_l
._l_zeroes
) != 0)
508 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
511 dst
->_l
._l_l
._l_zeroes
= 0;
512 dst
->_l
._l_l
._l_offset
= bfd_get_32 (abfd
, src
->_l
._l_l
._l_offset
);
514 dst
->l_value
= bfd_get_32 (abfd
, src
->l_value
);
515 dst
->l_scnum
= bfd_get_16 (abfd
, src
->l_scnum
);
516 dst
->l_smtype
= bfd_get_8 (abfd
, src
->l_smtype
);
517 dst
->l_smclas
= bfd_get_8 (abfd
, src
->l_smclas
);
518 dst
->l_ifile
= bfd_get_32 (abfd
, src
->l_ifile
);
519 dst
->l_parm
= bfd_get_32 (abfd
, src
->l_parm
);
522 /* Swap out the ldsym structure. */
525 xcoff_swap_ldsym_out (abfd
, src
, dst
)
527 const struct internal_ldsym
*src
;
528 struct external_ldsym
*dst
;
530 if (src
->_l
._l_l
._l_zeroes
!= 0)
531 memcpy (dst
->_l
._l_name
, src
->_l
._l_name
, SYMNMLEN
);
534 bfd_put_32 (abfd
, 0, dst
->_l
._l_l
._l_zeroes
);
535 bfd_put_32 (abfd
, src
->_l
._l_l
._l_offset
, dst
->_l
._l_l
._l_offset
);
537 bfd_put_32 (abfd
, src
->l_value
, dst
->l_value
);
538 bfd_put_16 (abfd
, src
->l_scnum
, dst
->l_scnum
);
539 bfd_put_8 (abfd
, src
->l_smtype
, dst
->l_smtype
);
540 bfd_put_8 (abfd
, src
->l_smclas
, dst
->l_smclas
);
541 bfd_put_32 (abfd
, src
->l_ifile
, dst
->l_ifile
);
542 bfd_put_32 (abfd
, src
->l_parm
, dst
->l_parm
);
545 /* As it happens, we never need to swap in the ldrel structure. */
547 /* Swap out the ldrel structure. */
550 xcoff_swap_ldrel_out (abfd
, src
, dst
)
552 const struct internal_ldrel
*src
;
553 struct external_ldrel
*dst
;
555 bfd_put_32 (abfd
, src
->l_vaddr
, dst
->l_vaddr
);
556 bfd_put_32 (abfd
, src
->l_symndx
, dst
->l_symndx
);
557 bfd_put_16 (abfd
, src
->l_rtype
, dst
->l_rtype
);
558 bfd_put_16 (abfd
, src
->l_rsecnm
, dst
->l_rsecnm
);
561 /* Routine to create an entry in an XCOFF link hash table. */
563 static struct bfd_hash_entry
*
564 xcoff_link_hash_newfunc (entry
, table
, string
)
565 struct bfd_hash_entry
*entry
;
566 struct bfd_hash_table
*table
;
569 struct xcoff_link_hash_entry
*ret
= (struct xcoff_link_hash_entry
*) entry
;
571 /* Allocate the structure if it has not already been allocated by a
573 if (ret
== (struct xcoff_link_hash_entry
*) NULL
)
574 ret
= ((struct xcoff_link_hash_entry
*)
575 bfd_hash_allocate (table
, sizeof (struct xcoff_link_hash_entry
)));
576 if (ret
== (struct xcoff_link_hash_entry
*) NULL
)
578 bfd_set_error (bfd_error_no_memory
);
579 return (struct bfd_hash_entry
*) ret
;
582 /* Call the allocation method of the superclass. */
583 ret
= ((struct xcoff_link_hash_entry
*)
584 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
588 /* Set local fields. */
590 ret
->toc_section
= NULL
;
591 ret
->u
.toc_indx
= -1;
592 ret
->descriptor
= NULL
;
596 ret
->smclas
= XMC_UA
;
599 return (struct bfd_hash_entry
*) ret
;
602 /* Create a XCOFF link hash table. */
604 struct bfd_link_hash_table
*
605 _bfd_xcoff_bfd_link_hash_table_create (abfd
)
608 struct xcoff_link_hash_table
*ret
;
610 ret
= ((struct xcoff_link_hash_table
*)
611 bfd_alloc (abfd
, sizeof (struct xcoff_link_hash_table
)));
612 if (ret
== (struct xcoff_link_hash_table
*) NULL
)
614 bfd_set_error (bfd_error_no_memory
);
615 return (struct bfd_link_hash_table
*) NULL
;
617 if (! _bfd_link_hash_table_init (&ret
->root
, abfd
, xcoff_link_hash_newfunc
))
619 bfd_release (abfd
, ret
);
620 return (struct bfd_link_hash_table
*) NULL
;
623 ret
->debug_strtab
= _bfd_xcoff_stringtab_init ();
624 ret
->debug_section
= NULL
;
625 ret
->loader_section
= NULL
;
626 ret
->ldrel_count
= 0;
627 memset (&ret
->ldhdr
, 0, sizeof (struct internal_ldhdr
));
628 ret
->linkage_section
= NULL
;
629 ret
->toc_section
= NULL
;
635 /* The linker will always generate a full a.out header. We need to
636 record that fact now, before the sizeof_headers routine could be
638 xcoff_data (abfd
)->full_aouthdr
= true;
643 /* Look up an entry in an XCOFF link hash table. */
645 #define xcoff_link_hash_lookup(table, string, create, copy, follow) \
646 ((struct xcoff_link_hash_entry *) \
647 bfd_link_hash_lookup (&(table)->root, (string), (create), (copy),\
650 /* Traverse an XCOFF link hash table. */
652 #define xcoff_link_hash_traverse(table, func, info) \
653 (bfd_link_hash_traverse \
655 (boolean (*) PARAMS ((struct bfd_link_hash_entry *, PTR))) (func), \
658 /* Get the XCOFF link hash table from the info structure. This is
661 #define xcoff_hash_table(p) ((struct xcoff_link_hash_table *) ((p)->hash))
663 /* Read internal relocs for an XCOFF csect. This is a wrapper around
664 _bfd_coff_read_internal_relocs which tries to take advantage of any
665 relocs which may have been cached for the enclosing section. */
667 static struct internal_reloc
*
668 xcoff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
669 require_internal
, internal_relocs
)
673 bfd_byte
*external_relocs
;
674 boolean require_internal
;
675 struct internal_reloc
*internal_relocs
;
677 if (coff_section_data (abfd
, sec
) != NULL
678 && coff_section_data (abfd
, sec
)->relocs
== NULL
679 && xcoff_section_data (abfd
, sec
) != NULL
)
683 enclosing
= xcoff_section_data (abfd
, sec
)->enclosing
;
685 if (enclosing
!= NULL
686 && (coff_section_data (abfd
, enclosing
) == NULL
687 || coff_section_data (abfd
, enclosing
)->relocs
== NULL
)
689 && enclosing
->reloc_count
> 0)
691 if (_bfd_coff_read_internal_relocs (abfd
, enclosing
, true,
692 external_relocs
, false,
693 (struct internal_reloc
*) NULL
)
698 if (enclosing
!= NULL
699 && coff_section_data (abfd
, enclosing
) != NULL
700 && coff_section_data (abfd
, enclosing
)->relocs
!= NULL
)
704 off
= ((sec
->rel_filepos
- enclosing
->rel_filepos
)
705 / bfd_coff_relsz (abfd
));
706 if (! require_internal
)
707 return coff_section_data (abfd
, enclosing
)->relocs
+ off
;
708 memcpy (internal_relocs
,
709 coff_section_data (abfd
, enclosing
)->relocs
+ off
,
710 sec
->reloc_count
* sizeof (struct internal_reloc
));
711 return internal_relocs
;
715 return _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
716 require_internal
, internal_relocs
);
719 /* Given an XCOFF BFD, add symbols to the global hash table as
723 _bfd_xcoff_bfd_link_add_symbols (abfd
, info
)
725 struct bfd_link_info
*info
;
727 switch (bfd_get_format (abfd
))
730 return xcoff_link_add_object_symbols (abfd
, info
);
732 return (_bfd_generic_link_add_archive_symbols
733 (abfd
, info
, xcoff_link_check_archive_element
));
735 bfd_set_error (bfd_error_wrong_format
);
740 /* Add symbols from an XCOFF object file. */
743 xcoff_link_add_object_symbols (abfd
, info
)
745 struct bfd_link_info
*info
;
747 if (! _bfd_coff_get_external_symbols (abfd
))
749 if (! xcoff_link_add_symbols (abfd
, info
))
751 if (! info
->keep_memory
)
753 if (! _bfd_coff_free_symbols (abfd
))
759 /* Check a single archive element to see if we need to include it in
760 the link. *PNEEDED is set according to whether this element is
761 needed in the link or not. This is called via
762 _bfd_generic_link_add_archive_symbols. */
765 xcoff_link_check_archive_element (abfd
, info
, pneeded
)
767 struct bfd_link_info
*info
;
770 if (! _bfd_coff_get_external_symbols (abfd
))
773 if (! xcoff_link_check_ar_symbols (abfd
, info
, pneeded
))
778 if (! xcoff_link_add_symbols (abfd
, info
))
782 if (! info
->keep_memory
|| ! *pneeded
)
784 if (! _bfd_coff_free_symbols (abfd
))
791 /* Look through the symbols to see if this object file should be
792 included in the link. */
795 xcoff_link_check_ar_symbols (abfd
, info
, pneeded
)
797 struct bfd_link_info
*info
;
800 bfd_size_type symesz
;
806 symesz
= bfd_coff_symesz (abfd
);
807 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
808 esym_end
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
809 while (esym
< esym_end
)
811 struct internal_syment sym
;
813 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
815 if (sym
.n_sclass
== C_EXT
&& sym
.n_scnum
!= N_UNDEF
)
818 char buf
[SYMNMLEN
+ 1];
819 struct bfd_link_hash_entry
*h
;
821 /* This symbol is externally visible, and is defined by this
824 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
827 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
829 /* We are only interested in symbols that are currently
830 undefined. If a symbol is currently known to be common,
831 XCOFF linkers do not bring in an object file which
832 defines it. We also don't bring in symbols to satisfy
833 undefined references in shared objects. */
834 if (h
!= (struct bfd_link_hash_entry
*) NULL
835 && h
->type
== bfd_link_hash_undefined
)
837 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
844 esym
+= (sym
.n_numaux
+ 1) * symesz
;
847 /* We do not need this object file. */
851 /* Returns the index of reloc in RELOCS with the least address greater
852 than or equal to ADDRESS. The relocs are sorted by address. */
855 xcoff_find_reloc (relocs
, count
, address
)
856 struct internal_reloc
*relocs
;
860 bfd_size_type min
, max
, this;
868 /* Do a binary search over (min,max]. */
869 while (min
+ 1 < max
)
873 this = (max
+ min
) / 2;
874 raddr
= relocs
[this].r_vaddr
;
877 else if (raddr
< address
)
886 if (relocs
[min
].r_vaddr
< address
)
890 && relocs
[min
- 1].r_vaddr
== address
)
896 /* Add all the symbols from an object file to the hash table.
898 XCOFF is a weird format. A normal XCOFF .o files will have three
899 COFF sections--.text, .data, and .bss--but each COFF section will
900 contain many csects. These csects are described in the symbol
901 table. From the linker's point of view, each csect must be
902 considered a section in its own right. For example, a TOC entry is
903 handled as a small XMC_TC csect. The linker must be able to merge
904 different TOC entries together, which means that it must be able to
905 extract the XMC_TC csects from the .data section of the input .o
908 From the point of view of our linker, this is, of course, a hideous
909 nightmare. We cope by actually creating sections for each csect,
910 and discarding the original sections. We then have to handle the
911 relocation entries carefully, since the only way to tell which
912 csect they belong to is to examine the address. */
915 xcoff_link_add_symbols (abfd
, info
)
917 struct bfd_link_info
*info
;
919 unsigned int n_tmask
;
920 unsigned int n_btshft
;
921 boolean default_copy
;
922 bfd_size_type symcount
;
923 struct xcoff_link_hash_entry
**sym_hash
;
924 asection
**csect_cache
;
925 bfd_size_type linesz
;
930 unsigned int csect_index
;
931 asection
*first_csect
;
932 bfd_size_type symesz
;
935 struct reloc_info_struct
937 struct internal_reloc
*relocs
;
940 } *reloc_info
= NULL
;
942 if ((abfd
->flags
& DYNAMIC
) != 0
943 && ! info
->static_link
)
944 return xcoff_link_add_dynamic_symbols (abfd
, info
);
946 n_tmask
= coff_data (abfd
)->local_n_tmask
;
947 n_btshft
= coff_data (abfd
)->local_n_btshft
;
949 /* Define macros so that ISFCN, et. al., macros work correctly. */
950 #define N_TMASK n_tmask
951 #define N_BTSHFT n_btshft
953 /* We need to build a .loader section, so we do it here. This won't
954 work if we're producing an XCOFF output file with no non dynamic
955 XCOFF input files. FIXME. */
956 if (xcoff_hash_table (info
)->loader_section
== NULL
)
960 lsec
= bfd_make_section_anyway (abfd
, ".loader");
963 xcoff_hash_table (info
)->loader_section
= lsec
;
964 lsec
->flags
|= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
966 /* Likewise for the linkage section. */
967 if (xcoff_hash_table (info
)->linkage_section
== NULL
)
971 lsec
= bfd_make_section_anyway (abfd
, ".gl");
974 xcoff_hash_table (info
)->linkage_section
= lsec
;
975 lsec
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
977 /* Likewise for the TOC section. */
978 if (xcoff_hash_table (info
)->toc_section
== NULL
)
982 tsec
= bfd_make_section_anyway (abfd
, ".tc");
985 xcoff_hash_table (info
)->toc_section
= tsec
;
986 tsec
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
987 tsec
->alignment_power
= 2;
989 /* Likewise for the .debug section. */
990 if (xcoff_hash_table (info
)->debug_section
== NULL
)
994 dsec
= bfd_make_section_anyway (abfd
, ".debug");
997 xcoff_hash_table (info
)->debug_section
= dsec
;
998 dsec
->flags
|= SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
1001 if (info
->keep_memory
)
1002 default_copy
= false;
1004 default_copy
= true;
1006 symcount
= obj_raw_syment_count (abfd
);
1008 /* We keep a list of the linker hash table entries that correspond
1009 to each external symbol. */
1010 sym_hash
= ((struct xcoff_link_hash_entry
**)
1013 * sizeof (struct xcoff_link_hash_entry
*))));
1014 if (sym_hash
== NULL
&& symcount
!= 0)
1016 bfd_set_error (bfd_error_no_memory
);
1019 coff_data (abfd
)->sym_hashes
= (struct coff_link_hash_entry
**) sym_hash
;
1020 memset (sym_hash
, 0,
1021 (size_t) symcount
* sizeof (struct xcoff_link_hash_entry
*));
1023 /* Because of the weird stuff we are doing with XCOFF csects, we can
1024 not easily determine which section a symbol is in, so we store
1025 the information in the tdata for the input file. */
1026 csect_cache
= ((asection
**)
1027 bfd_alloc (abfd
, symcount
* sizeof (asection
*)));
1028 if (csect_cache
== NULL
&& symcount
!= 0)
1030 bfd_set_error (bfd_error_no_memory
);
1033 xcoff_data (abfd
)->csects
= csect_cache
;
1034 memset (csect_cache
, 0, (size_t) symcount
* sizeof (asection
*));
1036 /* While splitting sections into csects, we need to assign the
1037 relocs correctly. The relocs and the csects must both be in
1038 order by VMA within a given section, so we handle this by
1039 scanning along the relocs as we process the csects. We index
1040 into reloc_info using the section target_index. */
1041 reloc_info
= ((struct reloc_info_struct
*)
1042 malloc ((abfd
->section_count
+ 1)
1043 * sizeof (struct reloc_info_struct
)));
1044 if (reloc_info
== NULL
)
1046 bfd_set_error (bfd_error_no_memory
);
1049 memset ((PTR
) reloc_info
, 0,
1050 (abfd
->section_count
+ 1) * sizeof (struct reloc_info_struct
));
1052 /* Read in the relocs and line numbers for each section. */
1053 linesz
= bfd_coff_linesz (abfd
);
1055 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1058 if ((o
->flags
& SEC_RELOC
) != 0)
1060 reloc_info
[o
->target_index
].relocs
=
1061 xcoff_read_internal_relocs (abfd
, o
, true, (bfd_byte
*) NULL
,
1062 false, (struct internal_reloc
*) NULL
);
1063 reloc_info
[o
->target_index
].csects
=
1064 (asection
**) malloc (o
->reloc_count
* sizeof (asection
*));
1065 if (reloc_info
[o
->target_index
].csects
== NULL
)
1067 bfd_set_error (bfd_error_no_memory
);
1070 memset (reloc_info
[o
->target_index
].csects
, 0,
1071 o
->reloc_count
* sizeof (asection
*));
1074 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1075 && o
->lineno_count
> 0)
1079 linenos
= (bfd_byte
*) malloc (o
->lineno_count
* linesz
);
1080 if (linenos
== NULL
)
1082 bfd_set_error (bfd_error_no_memory
);
1085 reloc_info
[o
->target_index
].linenos
= linenos
;
1086 if (bfd_seek (abfd
, o
->line_filepos
, SEEK_SET
) != 0
1087 || (bfd_read (linenos
, linesz
, o
->lineno_count
, abfd
)
1088 != linesz
* o
->lineno_count
))
1093 /* Don't let the linker relocation routines discard the symbols. */
1094 keep_syms
= obj_coff_keep_syms (abfd
);
1095 obj_coff_keep_syms (abfd
) = true;
1101 symesz
= bfd_coff_symesz (abfd
);
1102 BFD_ASSERT (symesz
== bfd_coff_auxesz (abfd
));
1103 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
1104 esym_end
= esym
+ symcount
* symesz
;
1105 while (esym
< esym_end
)
1107 struct internal_syment sym
;
1108 union internal_auxent aux
;
1110 char buf
[SYMNMLEN
+ 1];
1115 struct xcoff_link_hash_entry
*set_toc
;
1117 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
1119 /* In this pass we are only interested in symbols with csect
1121 if (sym
.n_sclass
!= C_EXT
&& sym
.n_sclass
!= C_HIDEXT
)
1123 if (sym
.n_sclass
== C_FILE
&& csect
!= NULL
)
1125 xcoff_section_data (abfd
, csect
)->last_symndx
=
1127 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1133 *csect_cache
= csect
;
1134 else if (first_csect
== NULL
|| sym
.n_sclass
== C_FILE
)
1135 *csect_cache
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1137 *csect_cache
= NULL
;
1138 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1139 sym_hash
+= sym
.n_numaux
+ 1;
1140 csect_cache
+= sym
.n_numaux
+ 1;
1144 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
1148 /* If this symbol has line number information attached to it,
1149 and we're not stripping it, count the number of entries and
1150 add them to the count for this csect. In the final link pass
1151 we are going to attach line number information by symbol,
1152 rather than by section, in order to more easily handle
1153 garbage collection. */
1154 if ((info
->strip
== strip_none
|| info
->strip
== strip_some
)
1157 && ISFCN (sym
.n_type
))
1159 union internal_auxent auxlin
;
1161 bfd_coff_swap_aux_in (abfd
, (PTR
) (esym
+ symesz
),
1162 sym
.n_type
, sym
.n_sclass
,
1163 0, sym
.n_numaux
, (PTR
) &auxlin
);
1164 if (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
1166 asection
*enclosing
;
1167 bfd_size_type linoff
;
1169 enclosing
= xcoff_section_data (abfd
, csect
)->enclosing
;
1170 if (enclosing
== NULL
)
1172 (*_bfd_error_handler
)
1173 ("%s: `%s' has line numbers but no enclosing section",
1174 bfd_get_filename (abfd
), name
);
1175 bfd_set_error (bfd_error_bad_value
);
1178 linoff
= (auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
1179 - enclosing
->line_filepos
);
1180 if (linoff
< enclosing
->lineno_count
* linesz
)
1182 struct internal_lineno lin
;
1183 bfd_byte
*linpstart
;
1185 linpstart
= (reloc_info
[enclosing
->target_index
].linenos
1187 bfd_coff_swap_lineno_in (abfd
, (PTR
) linpstart
, (PTR
) &lin
);
1189 && ((bfd_size_type
) lin
.l_addr
.l_symndx
1191 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1194 bfd_byte
*linpend
, *linp
;
1196 linpend
= (reloc_info
[enclosing
->target_index
].linenos
1197 + enclosing
->lineno_count
* linesz
);
1198 for (linp
= linpstart
+ linesz
;
1202 bfd_coff_swap_lineno_in (abfd
, (PTR
) linp
,
1204 if (lin
.l_lnno
== 0)
1207 csect
->lineno_count
+= (linp
- linpstart
) / linesz
;
1208 /* The setting of line_filepos will only be
1209 useful if all the line number entries for a
1210 csect are contiguous; this only matters for
1212 if (csect
->line_filepos
== 0)
1213 csect
->line_filepos
=
1214 auxlin
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
1220 /* Pick up the csect auxiliary information. */
1222 if (sym
.n_numaux
== 0)
1224 (*_bfd_error_handler
)
1225 ("%s: class %d symbol `%s' has no aux entries",
1226 bfd_get_filename (abfd
), sym
.n_sclass
, name
);
1227 bfd_set_error (bfd_error_bad_value
);
1231 bfd_coff_swap_aux_in (abfd
,
1232 (PTR
) (esym
+ symesz
* sym
.n_numaux
),
1233 sym
.n_type
, sym
.n_sclass
,
1234 sym
.n_numaux
- 1, sym
.n_numaux
,
1237 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
1247 (*_bfd_error_handler
)
1248 ("%s: symbol `%s' has unrecognized csect type %d",
1249 bfd_get_filename (abfd
), name
, smtyp
);
1250 bfd_set_error (bfd_error_bad_value
);
1254 /* This is an external reference. */
1255 if (sym
.n_sclass
== C_HIDEXT
1256 || sym
.n_scnum
!= N_UNDEF
1257 || aux
.x_csect
.x_scnlen
.l
!= 0)
1259 (*_bfd_error_handler
)
1260 ("%s: bad XTY_ER symbol `%s': class %d scnum %d scnlen %d",
1261 bfd_get_filename (abfd
), name
, sym
.n_sclass
, sym
.n_scnum
,
1262 aux
.x_csect
.x_scnlen
.l
);
1263 bfd_set_error (bfd_error_bad_value
);
1266 section
= bfd_und_section_ptr
;
1270 /* This is a csect definition. */
1274 xcoff_section_data (abfd
, csect
)->last_symndx
=
1276 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1283 /* When we see a TOC anchor, we record the TOC value. */
1284 if (aux
.x_csect
.x_smclas
== XMC_TC0
)
1286 if (sym
.n_sclass
!= C_HIDEXT
1287 || aux
.x_csect
.x_scnlen
.l
!= 0)
1289 (*_bfd_error_handler
)
1290 ("%s: XMC_TC0 symbol `%s' is class %d scnlen %d",
1291 bfd_get_filename (abfd
), name
, sym
.n_sclass
,
1292 aux
.x_csect
.x_scnlen
.l
);
1293 bfd_set_error (bfd_error_bad_value
);
1296 xcoff_data (abfd
)->toc
= sym
.n_value
;
1299 /* We must merge TOC entries for the same symbol. We can
1300 merge two TOC entries if they are both C_HIDEXT, they
1301 both have the same name, they are both 4 bytes long, and
1302 they both have a relocation table entry for an external
1303 symbol with the same name. Unfortunately, this means
1304 that we must look through the relocations. Ick. */
1305 if (aux
.x_csect
.x_smclas
== XMC_TC
1306 && sym
.n_sclass
== C_HIDEXT
1307 && aux
.x_csect
.x_scnlen
.l
== 4
1308 && info
->hash
->creator
== abfd
->xvec
)
1310 asection
*enclosing
;
1311 struct internal_reloc
*relocs
;
1312 bfd_size_type relindx
;
1313 struct internal_reloc
*rel
;
1315 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1316 if (enclosing
== NULL
)
1319 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1320 relindx
= xcoff_find_reloc (relocs
, enclosing
->reloc_count
,
1322 rel
= relocs
+ relindx
;
1323 if (relindx
< enclosing
->reloc_count
1324 && rel
->r_vaddr
== (bfd_vma
) sym
.n_value
1325 && rel
->r_size
== 31
1326 && rel
->r_type
== R_POS
)
1329 struct internal_syment relsym
;
1331 erelsym
= ((bfd_byte
*) obj_coff_external_syms (abfd
)
1332 + rel
->r_symndx
* symesz
);
1333 bfd_coff_swap_sym_in (abfd
, (PTR
) erelsym
, (PTR
) &relsym
);
1334 if (relsym
.n_sclass
== C_EXT
)
1336 const char *relname
;
1337 char relbuf
[SYMNMLEN
+ 1];
1339 struct xcoff_link_hash_entry
*h
;
1341 /* At this point we know that the TOC entry is
1342 for an externally visible symbol. */
1343 relname
= _bfd_coff_internal_syment_name (abfd
, &relsym
,
1345 if (relname
== NULL
)
1348 /* We only merge TOC entries if the TC name is
1349 the same as the symbol name. This handles
1350 the normal case, but not common cases like
1351 SYM.P4 which gcc generates to store SYM + 4
1352 in the TOC. FIXME. */
1353 if (strcmp (name
, relname
) == 0)
1355 copy
= (! info
->keep_memory
1356 || relsym
._n
._n_n
._n_zeroes
!= 0
1357 || relsym
._n
._n_n
._n_offset
== 0);
1358 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1359 relname
, true, copy
,
1364 /* At this point h->root.type could be
1365 bfd_link_hash_new. That should be OK,
1366 since we know for sure that we will come
1367 across this symbol as we step through the
1370 /* We store h in *sym_hash for the
1371 convenience of the relocate_section
1375 if (h
->toc_section
!= NULL
)
1377 asection
**rel_csects
;
1379 /* We already have a TOC entry for this
1380 symbol, so we can just ignore this
1383 reloc_info
[enclosing
->target_index
].csects
;
1384 rel_csects
[relindx
] = bfd_und_section_ptr
;
1388 /* We are about to create a TOC entry for
1396 /* We need to create a new section. We get the name from
1397 the csect storage mapping class, so that the linker can
1398 accumulate similar csects together. */
1400 static const char *csect_name_by_class
[] =
1402 ".pr", ".ro", ".db", ".tc", ".ua", ".rw", ".gl", ".xo",
1403 ".sv", ".bs", ".ds", ".uc", ".ti", ".tb", NULL
, ".tc0",
1406 const char *csect_name
;
1407 asection
*enclosing
;
1409 if ((aux
.x_csect
.x_smclas
>=
1410 sizeof csect_name_by_class
/ sizeof csect_name_by_class
[0])
1411 || csect_name_by_class
[aux
.x_csect
.x_smclas
] == NULL
)
1413 (*_bfd_error_handler
)
1414 ("%s: symbol `%s' has unrecognized smclas %d",
1415 bfd_get_filename (abfd
), name
, aux
.x_csect
.x_smclas
);
1416 bfd_set_error (bfd_error_bad_value
);
1420 csect_name
= csect_name_by_class
[aux
.x_csect
.x_smclas
];
1421 csect
= bfd_make_section_anyway (abfd
, csect_name
);
1424 enclosing
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
1425 if (enclosing
== NULL
)
1427 if (! bfd_is_abs_section (enclosing
)
1428 && ((bfd_vma
) sym
.n_value
< enclosing
->vma
1429 || ((bfd_vma
) sym
.n_value
+ aux
.x_csect
.x_scnlen
.l
1430 > enclosing
->vma
+ enclosing
->_raw_size
)))
1432 (*_bfd_error_handler
)
1433 ("%s: csect `%s' not in enclosing section",
1434 bfd_get_filename (abfd
), name
);
1435 bfd_set_error (bfd_error_bad_value
);
1438 csect
->vma
= sym
.n_value
;
1439 csect
->filepos
= (enclosing
->filepos
1442 csect
->_raw_size
= aux
.x_csect
.x_scnlen
.l
;
1443 csect
->flags
|= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
;
1444 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1446 /* Record the enclosing section in the tdata for this new
1448 csect
->used_by_bfd
=
1449 ((struct coff_section_tdata
*)
1450 bfd_zalloc (abfd
, sizeof (struct coff_section_tdata
)));
1451 if (csect
->used_by_bfd
== NULL
)
1453 bfd_set_error (bfd_error_no_memory
);
1456 coff_section_data (abfd
, csect
)->tdata
=
1457 bfd_zalloc (abfd
, sizeof (struct xcoff_section_tdata
));
1458 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1460 bfd_set_error (bfd_error_no_memory
);
1463 xcoff_section_data (abfd
, csect
)->enclosing
= enclosing
;
1464 xcoff_section_data (abfd
, csect
)->lineno_count
=
1465 enclosing
->lineno_count
;
1467 if (enclosing
->owner
== abfd
)
1469 struct internal_reloc
*relocs
;
1470 bfd_size_type relindx
;
1471 struct internal_reloc
*rel
;
1472 asection
**rel_csect
;
1474 relocs
= reloc_info
[enclosing
->target_index
].relocs
;
1475 relindx
= xcoff_find_reloc (relocs
, enclosing
->reloc_count
,
1477 rel
= relocs
+ relindx
;
1478 rel_csect
= (reloc_info
[enclosing
->target_index
].csects
1480 csect
->rel_filepos
= (enclosing
->rel_filepos
1481 + relindx
* bfd_coff_relsz (abfd
));
1482 while (relindx
< enclosing
->reloc_count
1483 && *rel_csect
== NULL
1484 && rel
->r_vaddr
< csect
->vma
+ csect
->_raw_size
)
1487 csect
->flags
|= SEC_RELOC
;
1488 ++csect
->reloc_count
;
1495 /* There are a number of other fields and section flags
1496 which we do not bother to set. */
1498 csect_index
= ((esym
1499 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1502 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1504 if (first_csect
== NULL
)
1505 first_csect
= csect
;
1507 /* If this symbol is C_EXT, we treat it as starting at the
1508 beginning of the newly created section. */
1509 if (sym
.n_sclass
== C_EXT
)
1515 /* If this is a TOC section for a symbol, record it. */
1516 if (set_toc
!= NULL
)
1517 set_toc
->toc_section
= csect
;
1522 /* This is a label definition. The x_scnlen field is the
1523 symbol index of the csect. I believe that this must
1524 always follow the appropriate XTY_SD symbol, so I will
1530 if (aux
.x_csect
.x_scnlen
.l
< 0
1531 || (aux
.x_csect
.x_scnlen
.l
1532 >= esym
- (bfd_byte
*) obj_coff_external_syms (abfd
)))
1536 section
= xcoff_data (abfd
)->csects
[aux
.x_csect
.x_scnlen
.l
];
1538 || (section
->flags
& SEC_HAS_CONTENTS
) == 0)
1543 (*_bfd_error_handler
)
1544 ("%s: misplaced XTY_LD `%s'",
1545 bfd_get_filename (abfd
), name
);
1546 bfd_set_error (bfd_error_bad_value
);
1550 value
= sym
.n_value
- csect
->vma
;
1555 /* This is an unitialized csect. We could base the name on
1556 the storage mapping class, but we don't bother. If this
1557 csect is externally visible, it is a common symbol. */
1561 xcoff_section_data (abfd
, csect
)->last_symndx
=
1563 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1567 csect
= bfd_make_section_anyway (abfd
, ".bss");
1570 csect
->vma
= sym
.n_value
;
1571 csect
->_raw_size
= aux
.x_csect
.x_scnlen
.l
;
1572 csect
->flags
|= SEC_ALLOC
;
1573 csect
->alignment_power
= SMTYP_ALIGN (aux
.x_csect
.x_smtyp
);
1574 /* There are a number of other fields and section flags
1575 which we do not bother to set. */
1577 csect_index
= ((esym
1578 - (bfd_byte
*) obj_coff_external_syms (abfd
))
1581 csect
->used_by_bfd
=
1582 ((struct coff_section_tdata
*)
1583 bfd_zalloc (abfd
, sizeof (struct coff_section_tdata
)));
1584 if (csect
->used_by_bfd
== NULL
)
1586 bfd_set_error (bfd_error_no_memory
);
1589 coff_section_data (abfd
, csect
)->tdata
=
1590 bfd_zalloc (abfd
, sizeof (struct xcoff_section_tdata
));
1591 if (coff_section_data (abfd
, csect
)->tdata
== NULL
)
1593 bfd_set_error (bfd_error_no_memory
);
1596 xcoff_section_data (abfd
, csect
)->first_symndx
= csect_index
;
1598 if (first_csect
== NULL
)
1599 first_csect
= csect
;
1601 if (sym
.n_sclass
== C_EXT
)
1603 csect
->flags
|= SEC_IS_COMMON
;
1604 csect
->_raw_size
= 0;
1606 value
= aux
.x_csect
.x_scnlen
.l
;
1612 /* Now we have enough information to add the symbol to the
1613 linker hash table. */
1615 if (sym
.n_sclass
== C_EXT
)
1619 BFD_ASSERT (section
!= NULL
);
1621 /* We must copy the name into memory if we got it from the
1622 syment itself, rather than the string table. */
1623 copy
= default_copy
;
1624 if (sym
._n
._n_n
._n_zeroes
!= 0
1625 || sym
._n
._n_n
._n_offset
== 0)
1628 if (info
->hash
->creator
== abfd
->xvec
)
1630 /* If we are statically linking a shared object, it is
1631 OK for symbol redefinitions to occur. I can't figure
1632 out just what the XCOFF linker is doing, but
1633 something like this is required for -bnso to work. */
1634 *sym_hash
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1635 name
, true, copy
, false);
1636 if (*sym_hash
== NULL
)
1638 if (((*sym_hash
)->root
.type
== bfd_link_hash_defined
1639 || (*sym_hash
)->root
.type
== bfd_link_hash_defweak
)
1640 && ! bfd_is_und_section (section
)
1641 && ! bfd_is_com_section (section
))
1643 if ((abfd
->flags
& DYNAMIC
) != 0)
1645 section
= bfd_und_section_ptr
;
1648 else if (((*sym_hash
)->root
.u
.def
.section
->owner
->flags
1651 (*sym_hash
)->root
.type
= bfd_link_hash_undefined
;
1652 (*sym_hash
)->root
.u
.undef
.abfd
=
1653 (*sym_hash
)->root
.u
.def
.section
->owner
;
1658 /* _bfd_generic_link_add_one_symbol may call the linker to
1659 generate an error message, and the linker may try to read
1660 the symbol table to give a good error. Right now, the
1661 line numbers are in an inconsistent state, since they are
1662 counted both in the real sections and in the new csects.
1663 We need to leave the count in the real sections so that
1664 the linker can report the line number of the error
1665 correctly, so temporarily clobber the link to the csects
1666 so that the linker will not try to read the line numbers
1667 a second time from the csects. */
1668 BFD_ASSERT (last_real
->next
== first_csect
);
1669 last_real
->next
= NULL
;
1670 if (! (_bfd_generic_link_add_one_symbol
1671 (info
, abfd
, name
, flags
, section
, value
,
1672 (const char *) NULL
, copy
, true,
1673 (struct bfd_link_hash_entry
**) sym_hash
)))
1675 last_real
->next
= first_csect
;
1677 if (smtyp
== XTY_CM
)
1679 if ((*sym_hash
)->root
.type
!= bfd_link_hash_common
1680 || (*sym_hash
)->root
.u
.c
.p
->section
!= csect
)
1682 /* We don't need the common csect we just created. */
1683 csect
->_raw_size
= 0;
1687 (*sym_hash
)->root
.u
.c
.p
->alignment_power
1688 = csect
->alignment_power
;
1692 if (info
->hash
->creator
== abfd
->xvec
)
1696 if (smtyp
== XTY_ER
|| smtyp
== XTY_CM
)
1697 flag
= XCOFF_REF_REGULAR
;
1699 flag
= XCOFF_DEF_REGULAR
;
1700 (*sym_hash
)->flags
|= flag
;
1702 if ((*sym_hash
)->smclas
== XMC_UA
1703 || flag
== XCOFF_DEF_REGULAR
)
1704 (*sym_hash
)->smclas
= aux
.x_csect
.x_smclas
;
1708 *csect_cache
= csect
;
1710 esym
+= (sym
.n_numaux
+ 1) * symesz
;
1711 sym_hash
+= sym
.n_numaux
+ 1;
1712 csect_cache
+= sym
.n_numaux
+ 1;
1715 BFD_ASSERT (last_real
== NULL
|| last_real
->next
== first_csect
);
1717 /* Make sure that we have seen all the relocs. */
1718 for (o
= abfd
->sections
; o
!= first_csect
; o
= o
->next
)
1720 /* Reset the section size and the line numebr count, since the
1721 data is now attached to the csects. Don't reset the size of
1722 the .debug section, since we need to read it below in
1723 bfd_xcoff_size_dynamic_sections. */
1724 if (strcmp (bfd_get_section_name (abfd
, o
), ".debug") != 0)
1726 o
->lineno_count
= 0;
1728 if ((o
->flags
& SEC_RELOC
) != 0)
1731 struct internal_reloc
*rel
;
1732 asection
**rel_csect
;
1734 rel
= reloc_info
[o
->target_index
].relocs
;
1735 rel_csect
= reloc_info
[o
->target_index
].csects
;
1736 for (i
= 0; i
< o
->reloc_count
; i
++, rel
++, rel_csect
++)
1738 if (*rel_csect
== NULL
)
1740 (*_bfd_error_handler
)
1741 ("%s: reloc %s:%d not in csect",
1742 bfd_get_filename (abfd
), o
->name
, i
);
1743 bfd_set_error (bfd_error_bad_value
);
1747 /* We identify all symbols which are called, so that we
1748 can create glue code for calls to functions imported
1749 from dynamic objects. */
1750 if (info
->hash
->creator
== abfd
->xvec
1751 && *rel_csect
!= bfd_und_section_ptr
1752 && (rel
->r_type
== R_BR
1753 || rel
->r_type
== R_RBR
)
1754 && obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
] != NULL
)
1756 struct xcoff_link_hash_entry
*h
;
1758 h
= obj_xcoff_sym_hashes (abfd
)[rel
->r_symndx
];
1759 h
->flags
|= XCOFF_CALLED
;
1760 /* If the symbol name starts with a period, it is
1761 the code of a function. If the symbol is
1762 currently undefined, then add an undefined symbol
1763 for the function descriptor. This should do no
1764 harm, because any regular object that defines the
1765 function should also define the function
1766 descriptor. It helps, because it means that we
1767 will identify the function descriptor with a
1768 dynamic object if a dynamic object defines it. */
1769 if (h
->root
.root
.string
[0] == '.'
1770 && h
->descriptor
== NULL
)
1772 struct xcoff_link_hash_entry
*hds
;
1774 hds
= xcoff_link_hash_lookup (xcoff_hash_table (info
),
1775 h
->root
.root
.string
+ 1,
1779 if (hds
->root
.type
== bfd_link_hash_new
)
1781 if (! (_bfd_generic_link_add_one_symbol
1782 (info
, abfd
, hds
->root
.root
.string
,
1783 (flagword
) 0, bfd_und_section_ptr
,
1784 (bfd_vma
) 0, (const char *) NULL
, false,
1786 (struct bfd_link_hash_entry
**) &hds
)))
1789 h
->descriptor
= hds
;
1794 free (reloc_info
[o
->target_index
].csects
);
1795 reloc_info
[o
->target_index
].csects
= NULL
;
1797 /* Reset SEC_RELOC and the reloc_count, since the reloc
1798 information is now attached to the csects. */
1799 o
->flags
&=~ SEC_RELOC
;
1802 /* If we are not keeping memory, free the reloc information. */
1803 if (! info
->keep_memory
1804 && coff_section_data (abfd
, o
) != NULL
1805 && coff_section_data (abfd
, o
)->relocs
!= NULL
1806 && ! coff_section_data (abfd
, o
)->keep_relocs
)
1808 free (coff_section_data (abfd
, o
)->relocs
);
1809 coff_section_data (abfd
, o
)->relocs
= NULL
;
1813 /* Free up the line numbers. FIXME: We could cache these
1814 somewhere for the final link, to avoid reading them again. */
1815 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
1817 free (reloc_info
[o
->target_index
].linenos
);
1818 reloc_info
[o
->target_index
].linenos
= NULL
;
1824 obj_coff_keep_syms (abfd
) = keep_syms
;
1829 if (reloc_info
!= NULL
)
1831 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1833 if (reloc_info
[o
->target_index
].csects
!= NULL
)
1834 free (reloc_info
[o
->target_index
].csects
);
1835 if (reloc_info
[o
->target_index
].linenos
!= NULL
)
1836 free (reloc_info
[o
->target_index
].linenos
);
1840 obj_coff_keep_syms (abfd
) = keep_syms
;
1847 /* This function is used to add symbols from a dynamic object to the
1848 global symbol table. */
1851 xcoff_link_add_dynamic_symbols (abfd
, info
)
1853 struct bfd_link_info
*info
;
1856 bfd_byte
*buf
= NULL
;
1857 struct internal_ldhdr ldhdr
;
1858 const char *strings
;
1859 struct external_ldsym
*elsym
, *elsymend
;
1860 struct xcoff_import_file
*n
;
1865 struct xcoff_import_file
**pp
;
1867 /* We can only handle a dynamic object if we are generating an XCOFF
1869 if (info
->hash
->creator
!= abfd
->xvec
)
1871 (*_bfd_error_handler
)
1872 ("%s: XCOFF shared object when not producing XCOFF output",
1873 bfd_get_filename (abfd
));
1874 bfd_set_error (bfd_error_invalid_operation
);
1878 /* The symbols we use from a dynamic object are not the symbols in
1879 the normal symbol table, but, rather, the symbols in the export
1880 table. If there is a global symbol in a dynamic object which is
1881 not in the export table, the loader will not be able to find it,
1882 so we don't want to find it either. Also, on AIX 4.1.3, shr.o in
1883 libc.a has symbols in the export table which are not in the
1886 /* Read in the .loader section. FIXME: We should really use the
1887 o_snloader field in the a.out header, rather than grabbing the
1889 lsec
= bfd_get_section_by_name (abfd
, ".loader");
1892 (*_bfd_error_handler
)
1893 ("%s: dynamic object with no .loader section",
1894 bfd_get_filename (abfd
));
1895 bfd_set_error (bfd_error_no_symbols
);
1899 buf
= (bfd_byte
*) malloc (lsec
->_raw_size
);
1900 if (buf
== NULL
&& lsec
->_raw_size
> 0)
1902 bfd_set_error (bfd_error_no_memory
);
1906 if (! bfd_get_section_contents (abfd
, lsec
, (PTR
) buf
, (file_ptr
) 0,
1910 /* Remove the sections from this object, so that they do not get
1911 included in the link. */
1912 abfd
->sections
= NULL
;
1914 xcoff_swap_ldhdr_in (abfd
, (struct external_ldhdr
*) buf
, &ldhdr
);
1916 strings
= (char *) buf
+ ldhdr
.l_stoff
;
1918 elsym
= (struct external_ldsym
*) (buf
+ LDHDRSZ
);
1919 elsymend
= elsym
+ ldhdr
.l_nsyms
;
1920 BFD_ASSERT (sizeof (struct external_ldsym
) == LDSYMSZ
);
1921 for (; elsym
< elsymend
; elsym
++)
1923 struct internal_ldsym ldsym
;
1924 char nambuf
[SYMNMLEN
+ 1];
1926 struct xcoff_link_hash_entry
*h
;
1928 xcoff_swap_ldsym_in (abfd
, elsym
, &ldsym
);
1930 /* We are only interested in exported symbols. */
1931 if ((ldsym
.l_smtype
& L_EXPORT
) == 0)
1934 /* All we have to do is look up the symbol in the hash table.
1935 If it's not there, we just won't import it. Normally we
1936 could not xcoff_link_hash_lookup in an add symbols routine,
1937 since we might not be using an XCOFF hash table. However, we
1938 verified above that we are using an XCOFF hash table. */
1940 if (ldsym
._l
._l_l
._l_zeroes
== 0)
1941 name
= strings
+ ldsym
._l
._l_l
._l_offset
;
1944 memcpy (nambuf
, ldsym
._l
._l_name
, SYMNMLEN
);
1945 nambuf
[SYMNMLEN
] = '\0';
1949 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, false,
1953 h
->flags
|= XCOFF_DEF_DYNAMIC
;
1955 /* If the symbol is undefined, and the BFD it was found in
1956 is not a dynamic object, change the BFD to this dynamic
1957 object, so that we can get the correct import file ID. */
1958 if ((h
->root
.type
== bfd_link_hash_undefined
1959 || h
->root
.type
== bfd_link_hash_undefweak
)
1960 && (h
->root
.u
.undef
.abfd
== NULL
1961 || (h
->root
.u
.undef
.abfd
->flags
& DYNAMIC
) == 0))
1962 h
->root
.u
.undef
.abfd
= abfd
;
1964 if (h
->smclas
== XMC_UA
1965 || h
->root
.type
== bfd_link_hash_undefined
1966 || h
->root
.type
== bfd_link_hash_undefweak
)
1967 h
->smclas
= ldsym
.l_smclas
;
1977 /* Record this file in the import files. */
1979 n
= ((struct xcoff_import_file
*)
1980 bfd_alloc (abfd
, sizeof (struct xcoff_import_file
)));
1983 bfd_set_error (bfd_error_no_memory
);
1988 /* For some reason, the path entry in the import file list for a
1989 shared object appears to always be empty. The file name is the
1992 if (abfd
->my_archive
== NULL
)
1994 bname
= bfd_get_filename (abfd
);
1999 bname
= bfd_get_filename (abfd
->my_archive
);
2000 mname
= bfd_get_filename (abfd
);
2002 s
= strrchr (bname
, '/');
2008 /* We start c at 1 because the first import file number is reserved
2010 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
2012 pp
= &(*pp
)->next
, ++c
)
2016 xcoff_data (abfd
)->import_file_id
= c
;
2026 /* Routines that are called after all the input files have been
2027 handled, but before the sections are laid out in memory. */
2029 /* Mark a symbol as not being garbage, including the section in which
2032 static INLINE boolean
2033 xcoff_mark_symbol (info
, h
)
2034 struct bfd_link_info
*info
;
2035 struct xcoff_link_hash_entry
*h
;
2037 if ((h
->flags
& XCOFF_MARK
) != 0)
2040 h
->flags
|= XCOFF_MARK
;
2041 if (h
->root
.type
== bfd_link_hash_defined
2042 || h
->root
.type
== bfd_link_hash_defweak
)
2046 hsec
= h
->root
.u
.def
.section
;
2047 if ((hsec
->flags
& SEC_MARK
) == 0)
2049 if (! xcoff_mark (info
, hsec
))
2054 if (h
->toc_section
!= NULL
2055 && (h
->toc_section
->flags
& SEC_MARK
) == 0)
2057 if (! xcoff_mark (info
, h
->toc_section
))
2064 /* The mark phase of garbage collection. For a given section, mark
2065 it, and all the sections which define symbols to which it refers.
2066 Because this function needs to look at the relocs, we also count
2067 the number of relocs which need to be copied into the .loader
2071 xcoff_mark (info
, sec
)
2072 struct bfd_link_info
*info
;
2075 if ((sec
->flags
& SEC_MARK
) != 0)
2078 sec
->flags
|= SEC_MARK
;
2080 if (sec
->owner
->xvec
== info
->hash
->creator
2081 && coff_section_data (sec
->owner
, sec
) != NULL
2082 && xcoff_section_data (sec
->owner
, sec
) != NULL
)
2084 register struct xcoff_link_hash_entry
**hp
, **hpend
;
2085 struct internal_reloc
*rel
, *relend
;
2087 /* Mark all the symbols in this section. */
2089 hp
= (obj_xcoff_sym_hashes (sec
->owner
)
2090 + xcoff_section_data (sec
->owner
, sec
)->first_symndx
);
2091 hpend
= (obj_xcoff_sym_hashes (sec
->owner
)
2092 + xcoff_section_data (sec
->owner
, sec
)->last_symndx
);
2093 for (; hp
< hpend
; hp
++)
2095 register struct xcoff_link_hash_entry
*h
;
2099 && (h
->flags
& XCOFF_MARK
) == 0)
2101 if (! xcoff_mark_symbol (info
, h
))
2106 /* Look through the section relocs. */
2108 if ((sec
->flags
& SEC_RELOC
) != 0
2109 && sec
->reloc_count
> 0)
2111 rel
= xcoff_read_internal_relocs (sec
->owner
, sec
, true,
2112 (bfd_byte
*) NULL
, false,
2113 (struct internal_reloc
*) NULL
);
2116 relend
= rel
+ sec
->reloc_count
;
2117 for (; rel
< relend
; rel
++)
2120 struct xcoff_link_hash_entry
*h
;
2122 if ((unsigned int) rel
->r_symndx
2123 > obj_raw_syment_count (sec
->owner
))
2126 h
= obj_xcoff_sym_hashes (sec
->owner
)[rel
->r_symndx
];
2128 && (h
->flags
& XCOFF_MARK
) == 0)
2130 if (! xcoff_mark_symbol (info
, h
))
2134 rsec
= xcoff_data (sec
->owner
)->csects
[rel
->r_symndx
];
2136 && (rsec
->flags
& SEC_MARK
) == 0)
2138 if (! xcoff_mark (info
, rsec
))
2142 /* See if this reloc needs to be copied into the .loader
2144 switch (rel
->r_type
)
2148 || h
->root
.type
== bfd_link_hash_defined
2149 || h
->root
.type
== bfd_link_hash_defweak
2150 || h
->root
.type
== bfd_link_hash_common
2151 || ((h
->flags
& XCOFF_CALLED
) != 0
2152 && (h
->root
.type
== bfd_link_hash_undefined
2153 || h
->root
.type
== bfd_link_hash_undefweak
)
2154 && h
->root
.root
.string
[0] == '.'
2155 && h
->descriptor
!= NULL
2156 && ((h
->descriptor
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2164 ++xcoff_hash_table (info
)->ldrel_count
;
2166 h
->flags
|= XCOFF_LDREL
;
2173 /* We should never need a .loader reloc for a TOC
2179 if (! info
->keep_memory
2180 && coff_section_data (sec
->owner
, sec
) != NULL
2181 && coff_section_data (sec
->owner
, sec
)->relocs
!= NULL
2182 && ! coff_section_data (sec
->owner
, sec
)->keep_relocs
)
2184 free (coff_section_data (sec
->owner
, sec
)->relocs
);
2185 coff_section_data (sec
->owner
, sec
)->relocs
= NULL
;
2193 /* The sweep phase of garbage collection. Remove all garbage
2198 struct bfd_link_info
*info
;
2202 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2206 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2208 if ((o
->flags
& SEC_MARK
) == 0)
2210 /* Keep all sections from non-XCOFF input files. Keep
2211 special sections. Keep .debug sections for the
2213 if (sub
->xvec
!= info
->hash
->creator
2214 || o
== xcoff_hash_table (info
)->debug_section
2215 || o
== xcoff_hash_table (info
)->loader_section
2216 || o
== xcoff_hash_table (info
)->linkage_section
2217 || o
== xcoff_hash_table (info
)->toc_section
2218 || strcmp (o
->name
, ".debug") == 0)
2219 o
->flags
|= SEC_MARK
;
2224 o
->lineno_count
= 0;
2231 /* Record the number of elements in a set. This is used to output the
2232 correct csect length. */
2235 bfd_xcoff_link_record_set (output_bfd
, info
, harg
, size
)
2237 struct bfd_link_info
*info
;
2238 struct bfd_link_hash_entry
*harg
;
2241 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2242 struct xcoff_link_size_list
*n
;
2244 if (! XCOFF_XVECP (output_bfd
->xvec
))
2247 /* This will hardly ever be called. I don't want to burn four bytes
2248 per global symbol, so instead the size is kept on a linked list
2249 attached to the hash table. */
2251 n
= ((struct xcoff_link_size_list
*)
2252 bfd_alloc (output_bfd
, sizeof (struct xcoff_link_size_list
)));
2255 bfd_set_error (bfd_error_no_memory
);
2258 n
->next
= xcoff_hash_table (info
)->size_list
;
2261 xcoff_hash_table (info
)->size_list
= n
;
2263 h
->flags
|= XCOFF_HAS_SIZE
;
2268 /* Import a symbol. */
2271 bfd_xcoff_import_symbol (output_bfd
, info
, harg
, val
, imppath
, impfile
,
2274 struct bfd_link_info
*info
;
2275 struct bfd_link_hash_entry
*harg
;
2277 const char *imppath
;
2278 const char *impfile
;
2279 const char *impmember
;
2281 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2283 if (! XCOFF_XVECP (output_bfd
->xvec
))
2286 h
->flags
|= XCOFF_IMPORT
;
2288 if (val
!= (bfd_vma
) -1)
2290 if (h
->root
.type
== bfd_link_hash_defined
)
2292 if (! ((*info
->callbacks
->multiple_definition
)
2293 (info
, h
->root
.root
.string
, h
->root
.u
.def
.section
->owner
,
2294 h
->root
.u
.def
.section
, h
->root
.u
.def
.value
,
2295 output_bfd
, bfd_abs_section_ptr
, val
)))
2299 h
->root
.type
= bfd_link_hash_defined
;
2300 h
->root
.u
.def
.section
= bfd_abs_section_ptr
;
2301 h
->root
.u
.def
.value
= val
;
2304 if (h
->ldsym
== NULL
)
2306 h
->ldsym
= ((struct internal_ldsym
*)
2307 bfd_zalloc (output_bfd
, sizeof (struct internal_ldsym
)));
2308 if (h
->ldsym
== NULL
)
2310 bfd_set_error (bfd_error_no_memory
);
2315 if (imppath
== NULL
)
2316 h
->ldsym
->l_ifile
= (bfd_size_type
) -1;
2320 struct xcoff_import_file
**pp
;
2322 /* We start c at 1 because the first entry in the import list is
2323 reserved for the library search path. */
2324 for (pp
= &xcoff_hash_table (info
)->imports
, c
= 1;
2326 pp
= &(*pp
)->next
, ++c
)
2328 if (strcmp ((*pp
)->path
, imppath
) == 0
2329 && strcmp ((*pp
)->file
, impfile
) == 0
2330 && strcmp ((*pp
)->member
, impmember
) == 0)
2336 struct xcoff_import_file
*n
;
2338 n
= ((struct xcoff_import_file
*)
2339 bfd_alloc (output_bfd
, sizeof (struct xcoff_import_file
)));
2342 bfd_set_error (bfd_error_no_memory
);
2348 n
->member
= impmember
;
2352 h
->ldsym
->l_ifile
= c
;
2358 /* Export a symbol. */
2361 bfd_xcoff_export_symbol (output_bfd
, info
, harg
, syscall
)
2363 struct bfd_link_info
*info
;
2364 struct bfd_link_hash_entry
*harg
;
2367 struct xcoff_link_hash_entry
*h
= (struct xcoff_link_hash_entry
*) harg
;
2369 if (! XCOFF_XVECP (output_bfd
->xvec
))
2372 h
->flags
|= XCOFF_EXPORT
;
2374 /* FIXME: I'm not at all sure what syscall is supposed to mean, so
2375 I'm just going to ignore it until somebody explains it. */
2377 /* Make sure we don't garbage collect this symbol. */
2378 if (! xcoff_mark_symbol (info
, h
))
2384 /* Count a reloc against a symbol. This is called for relocs
2385 generated by the linker script, typically for global constructors
2389 bfd_xcoff_link_count_reloc (output_bfd
, info
, name
)
2391 struct bfd_link_info
*info
;
2394 struct xcoff_link_hash_entry
*h
;
2396 if (! XCOFF_XVECP (output_bfd
->xvec
))
2399 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, false, false,
2403 (*_bfd_error_handler
) ("%s: no such symbol", name
);
2404 bfd_set_error (bfd_error_no_symbols
);
2408 h
->flags
|= XCOFF_REF_REGULAR
| XCOFF_LDREL
;
2409 ++xcoff_hash_table (info
)->ldrel_count
;
2411 /* Mark the symbol to avoid garbage collection. */
2412 if (! xcoff_mark_symbol (info
, h
))
2418 /* This function is called for each symbol to which the linker script
2422 bfd_xcoff_record_link_assignment (output_bfd
, info
, name
)
2424 struct bfd_link_info
*info
;
2427 struct xcoff_link_hash_entry
*h
;
2429 if (! XCOFF_XVECP (output_bfd
->xvec
))
2432 h
= xcoff_link_hash_lookup (xcoff_hash_table (info
), name
, true, true,
2437 h
->flags
|= XCOFF_DEF_REGULAR
;
2442 /* This structure is used to pass information through
2443 xcoff_link_hash_traverse. */
2445 struct xcoff_loader_info
2447 /* Set if a problem occurred. */
2451 /* Link information structure. */
2452 struct bfd_link_info
*info
;
2453 /* Number of ldsym structures. */
2455 /* Size of string table. */
2459 /* Allocated size of string table. */
2463 /* Build the .loader section. This is called by the XCOFF linker
2464 emulation before_allocation routine. We must set the size of the
2465 .loader section before the linker lays out the output file.
2466 LIBPATH is the library path to search for shared objects; this is
2467 normally built from the -L arguments passed to the linker. ENTRY
2468 is the name of the entry point symbol. */
2471 bfd_xcoff_size_dynamic_sections (output_bfd
, info
, libpath
, entry
,
2472 file_align
, maxstack
, maxdata
, gc
,
2475 struct bfd_link_info
*info
;
2476 const char *libpath
;
2478 unsigned long file_align
;
2479 unsigned long maxstack
;
2480 unsigned long maxdata
;
2485 struct xcoff_link_hash_entry
*hentry
;
2487 struct xcoff_loader_info ldinfo
;
2488 size_t impsize
, impcount
;
2489 struct xcoff_import_file
*fl
;
2490 struct internal_ldhdr
*ldhdr
;
2491 bfd_size_type stoff
;
2495 struct bfd_strtab_hash
*debug_strtab
;
2496 bfd_byte
*debug_contents
= NULL
;
2498 if (! XCOFF_XVECP (output_bfd
->xvec
))
2501 ldinfo
.failed
= false;
2502 ldinfo
.output_bfd
= output_bfd
;
2504 ldinfo
.ldsym_count
= 0;
2505 ldinfo
.string_size
= 0;
2506 ldinfo
.strings
= NULL
;
2507 ldinfo
.string_alc
= 0;
2509 xcoff_data (output_bfd
)->maxstack
= maxstack
;
2510 xcoff_data (output_bfd
)->maxdata
= maxdata
;
2511 xcoff_data (output_bfd
)->modtype
= modtype
;
2513 xcoff_hash_table (info
)->file_align
= file_align
;
2514 xcoff_hash_table (info
)->textro
= textro
;
2516 hentry
= xcoff_link_hash_lookup (xcoff_hash_table (info
), entry
,
2517 false, false, true);
2520 hentry
->flags
|= XCOFF_ENTRY
;
2521 if (hentry
->root
.type
== bfd_link_hash_defined
2522 || hentry
->root
.type
== bfd_link_hash_defweak
)
2523 xcoff_data (output_bfd
)->entry_section
=
2524 hentry
->root
.u
.def
.section
->output_section
;
2527 /* Garbage collect unused sections. */
2528 if (info
->relocateable
2531 || (hentry
->root
.type
!= bfd_link_hash_defined
2532 && hentry
->root
.type
!= bfd_link_hash_defweak
))
2535 xcoff_hash_table (info
)->gc
= false;
2537 /* We still need to call xcoff_mark, in order to set ldrel_count
2539 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2543 for (o
= sub
->sections
; o
!= NULL
; o
= o
->next
)
2545 if ((o
->flags
& SEC_MARK
) == 0)
2547 if (! xcoff_mark (info
, o
))
2555 if (! xcoff_mark (info
, hentry
->root
.u
.def
.section
))
2558 xcoff_hash_table (info
)->gc
= true;
2561 if (info
->input_bfds
== NULL
)
2563 /* I'm not sure what to do in this bizarre case. */
2567 xcoff_link_hash_traverse (xcoff_hash_table (info
), xcoff_build_ldsyms
,
2572 /* Work out the size of the import file names. Each import file ID
2573 consists of three null terminated strings: the path, the file
2574 name, and the archive member name. The first entry in the list
2575 of names is the path to use to find objects, which the linker has
2576 passed in as the libpath argument. For some reason, the path
2577 entry in the other import file names appears to always be empty. */
2578 impsize
= strlen (libpath
) + 3;
2580 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
2583 impsize
+= (strlen (fl
->path
)
2585 + strlen (fl
->member
)
2589 /* Set up the .loader section header. */
2590 ldhdr
= &xcoff_hash_table (info
)->ldhdr
;
2591 ldhdr
->l_version
= 1;
2592 ldhdr
->l_nsyms
= ldinfo
.ldsym_count
;
2593 ldhdr
->l_nreloc
= xcoff_hash_table (info
)->ldrel_count
;
2594 ldhdr
->l_istlen
= impsize
;
2595 ldhdr
->l_nimpid
= impcount
;
2596 ldhdr
->l_impoff
= (LDHDRSZ
2597 + ldhdr
->l_nsyms
* LDSYMSZ
2598 + ldhdr
->l_nreloc
* LDRELSZ
);
2599 ldhdr
->l_stlen
= ldinfo
.string_size
;
2600 stoff
= ldhdr
->l_impoff
+ impsize
;
2601 if (ldinfo
.string_size
== 0)
2604 ldhdr
->l_stoff
= stoff
;
2606 /* We now know the final size of the .loader section. Allocate
2608 lsec
= xcoff_hash_table (info
)->loader_section
;
2609 lsec
->_raw_size
= stoff
+ ldhdr
->l_stlen
;
2610 lsec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, lsec
->_raw_size
);
2611 if (lsec
->contents
== NULL
)
2613 bfd_set_error (bfd_error_no_memory
);
2617 /* Set up the header. */
2618 xcoff_swap_ldhdr_out (output_bfd
, ldhdr
,
2619 (struct external_ldhdr
*) lsec
->contents
);
2621 /* Set up the import file names. */
2622 out
= (char *) lsec
->contents
+ ldhdr
->l_impoff
;
2623 strcpy (out
, libpath
);
2624 out
+= strlen (libpath
) + 1;
2627 for (fl
= xcoff_hash_table (info
)->imports
; fl
!= NULL
; fl
= fl
->next
)
2629 register const char *s
;
2632 while ((*out
++ = *s
++) != '\0')
2635 while ((*out
++ = *s
++) != '\0')
2638 while ((*out
++ = *s
++) != '\0')
2642 BFD_ASSERT ((bfd_size_type
) ((bfd_byte
*) out
- lsec
->contents
) == stoff
);
2644 /* Set up the symbol string table. */
2645 if (ldinfo
.string_size
> 0)
2647 memcpy (out
, ldinfo
.strings
, ldinfo
.string_size
);
2648 free (ldinfo
.strings
);
2649 ldinfo
.strings
= NULL
;
2652 /* We can't set up the symbol table or the relocs yet, because we
2653 don't yet know the final position of the various sections. The
2654 .loader symbols are written out when the corresponding normal
2655 symbols are written out in xcoff_link_input_bfd or
2656 xcoff_write_global_symbol. The .loader relocs are written out
2657 when the corresponding normal relocs are handled in
2658 xcoff_link_input_bfd. */
2660 /* Allocate space for the global linkage section and the global toc
2662 sec
= xcoff_hash_table (info
)->linkage_section
;
2663 if (sec
->_raw_size
> 0)
2665 sec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, sec
->_raw_size
);
2666 if (sec
->contents
== NULL
)
2668 bfd_set_error (bfd_error_no_memory
);
2672 sec
= xcoff_hash_table (info
)->toc_section
;
2673 if (sec
->_raw_size
> 0)
2675 sec
->contents
= (bfd_byte
*) bfd_zalloc (output_bfd
, sec
->_raw_size
);
2676 if (sec
->contents
== NULL
)
2678 bfd_set_error (bfd_error_no_memory
);
2683 /* Now that we've done garbage collection, figure out the contents
2684 of the .debug section. */
2685 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
2687 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
2690 bfd_size_type symcount
;
2691 unsigned long *debug_index
;
2693 bfd_byte
*esym
, *esymend
;
2694 bfd_size_type symesz
;
2696 if (sub
->xvec
!= info
->hash
->creator
)
2698 subdeb
= bfd_get_section_by_name (sub
, ".debug");
2699 if (subdeb
== NULL
|| subdeb
->_raw_size
== 0)
2702 if (info
->strip
== strip_all
2703 || info
->strip
== strip_debugger
2704 || info
->discard
== discard_all
)
2706 subdeb
->_raw_size
= 0;
2710 if (! _bfd_coff_get_external_symbols (sub
))
2713 symcount
= obj_raw_syment_count (sub
);
2714 debug_index
= ((unsigned long *)
2715 bfd_zalloc (sub
, symcount
* sizeof (unsigned long)));
2716 if (debug_index
== NULL
)
2718 bfd_set_error (bfd_error_no_memory
);
2721 xcoff_data (sub
)->debug_indices
= debug_index
;
2723 /* Grab the contents of the .debug section. We use malloc and
2724 copy the neams into the debug stringtab, rather than
2725 bfd_alloc, because I expect that, when linking many files
2726 together, many of the strings will be the same. Storing the
2727 strings in the hash table should save space in this case. */
2728 debug_contents
= (bfd_byte
*) malloc (subdeb
->_raw_size
);
2729 if (debug_contents
== NULL
)
2731 bfd_set_error (bfd_error_no_memory
);
2734 if (! bfd_get_section_contents (sub
, subdeb
, (PTR
) debug_contents
,
2735 (file_ptr
) 0, subdeb
->_raw_size
))
2738 csectpp
= xcoff_data (sub
)->csects
;
2740 symesz
= bfd_coff_symesz (sub
);
2741 esym
= (bfd_byte
*) obj_coff_external_syms (sub
);
2742 esymend
= esym
+ symcount
* symesz
;
2743 while (esym
< esymend
)
2745 struct internal_syment sym
;
2747 bfd_coff_swap_sym_in (sub
, (PTR
) esym
, (PTR
) &sym
);
2749 *debug_index
= (unsigned long) -1;
2751 if (sym
._n
._n_n
._n_zeroes
== 0
2754 || ((*csectpp
)->flags
& SEC_MARK
) != 0
2755 || *csectpp
== bfd_abs_section_ptr
)
2756 && bfd_coff_symname_in_debug (sub
, &sym
))
2761 name
= (char *) debug_contents
+ sym
._n
._n_n
._n_offset
;
2762 indx
= _bfd_stringtab_add (debug_strtab
, name
, true, true);
2763 if (indx
== (bfd_size_type
) -1)
2765 *debug_index
= indx
;
2768 esym
+= (sym
.n_numaux
+ 1) * symesz
;
2769 csectpp
+= sym
.n_numaux
+ 1;
2770 debug_index
+= sym
.n_numaux
+ 1;
2773 free (debug_contents
);
2774 debug_contents
= NULL
;
2776 /* Clear the size of subdeb, so that it is not included directly
2777 in the output file. */
2778 subdeb
->_raw_size
= 0;
2780 if (! info
->keep_memory
)
2782 if (! _bfd_coff_free_symbols (sub
))
2787 xcoff_hash_table (info
)->debug_section
->_raw_size
=
2788 _bfd_stringtab_size (debug_strtab
);
2793 if (ldinfo
.strings
!= NULL
)
2794 free (ldinfo
.strings
);
2795 if (debug_contents
!= NULL
)
2796 free (debug_contents
);
2800 /* Add a symbol to the .loader symbols, if necessary. */
2803 xcoff_build_ldsyms (h
, p
)
2804 struct xcoff_link_hash_entry
*h
;
2807 struct xcoff_loader_info
*ldinfo
= (struct xcoff_loader_info
*) p
;
2810 /* We don't want to garbage collect symbols which are not defined in
2811 XCOFF files. This is a convenient place to mark them. */
2812 if (xcoff_hash_table (ldinfo
->info
)->gc
2813 && (h
->flags
& XCOFF_MARK
) == 0
2814 && (h
->root
.type
== bfd_link_hash_defined
2815 || h
->root
.type
== bfd_link_hash_defweak
)
2816 && (h
->root
.u
.def
.section
->owner
== NULL
2817 || (h
->root
.u
.def
.section
->owner
->xvec
2818 != ldinfo
->info
->hash
->creator
)))
2819 h
->flags
|= XCOFF_MARK
;
2821 /* If this symbol is called and defined in a dynamic object, or not
2822 defined at all when building a shared object, then we need to set
2823 up global linkage code for it. (Unless we did garbage collection
2824 and we didn't need this symbol.) */
2825 if ((h
->flags
& XCOFF_CALLED
) != 0
2826 && (h
->root
.type
== bfd_link_hash_undefined
2827 || h
->root
.type
== bfd_link_hash_undefweak
)
2828 && h
->root
.root
.string
[0] == '.'
2829 && h
->descriptor
!= NULL
2830 && ((h
->descriptor
->flags
& XCOFF_DEF_DYNAMIC
) != 0
2831 || ldinfo
->info
->shared
)
2832 && (! xcoff_hash_table (ldinfo
->info
)->gc
2833 || (h
->flags
& XCOFF_MARK
) != 0))
2836 struct xcoff_link_hash_entry
*hds
;
2838 sec
= xcoff_hash_table (ldinfo
->info
)->linkage_section
;
2839 h
->root
.type
= bfd_link_hash_defined
;
2840 h
->root
.u
.def
.section
= sec
;
2841 h
->root
.u
.def
.value
= sec
->_raw_size
;
2843 sec
->_raw_size
+= XCOFF_GLINK_SIZE
;
2845 /* The global linkage code requires a TOC entry for the
2847 hds
= h
->descriptor
;
2848 BFD_ASSERT ((hds
->root
.type
== bfd_link_hash_undefined
2849 || hds
->root
.type
== bfd_link_hash_undefweak
)
2850 && (hds
->flags
& XCOFF_DEF_REGULAR
) == 0);
2851 hds
->flags
|= XCOFF_MARK
;
2852 if (hds
->toc_section
== NULL
)
2854 hds
->toc_section
= xcoff_hash_table (ldinfo
->info
)->toc_section
;
2855 hds
->u
.toc_offset
= hds
->toc_section
->_raw_size
;
2856 hds
->toc_section
->_raw_size
+= 4;
2857 ++xcoff_hash_table (ldinfo
->info
)->ldrel_count
;
2858 ++hds
->toc_section
->reloc_count
;
2860 hds
->flags
|= XCOFF_SET_TOC
| XCOFF_LDREL
;
2862 /* We need to call xcoff_build_ldsyms recursively here,
2863 because we may already have passed hds on the traversal. */
2864 xcoff_build_ldsyms (hds
, p
);
2868 /* If this is still a common symbol, and it wasn't garbage
2869 collected, we need to actually allocate space for it in the .bss
2871 if (h
->root
.type
== bfd_link_hash_common
2872 && (! xcoff_hash_table (ldinfo
->info
)->gc
2873 || (h
->flags
& XCOFF_MARK
) != 0)
2874 && h
->root
.u
.c
.p
->section
->_raw_size
== 0)
2876 BFD_ASSERT (bfd_is_com_section (h
->root
.u
.c
.p
->section
));
2877 h
->root
.u
.c
.p
->section
->_raw_size
= h
->root
.u
.c
.size
;
2880 /* We need to add a symbol to the .loader section if it is mentioned
2881 in a reloc which we are copying to the .loader section and it was
2882 not defined or common, or if it is the entry point, or if it is
2885 if (((h
->flags
& XCOFF_LDREL
) == 0
2886 || h
->root
.type
== bfd_link_hash_defined
2887 || h
->root
.type
== bfd_link_hash_defweak
2888 || h
->root
.type
== bfd_link_hash_common
)
2889 && (h
->flags
& XCOFF_ENTRY
) == 0
2890 && (h
->flags
& XCOFF_EXPORT
) == 0)
2896 /* We don't need to add this symbol if we did garbage collection and
2897 we did not mark this symbol. */
2898 if (xcoff_hash_table (ldinfo
->info
)->gc
2899 && (h
->flags
& XCOFF_MARK
) == 0)
2905 /* We may have already processed this symbol due to the recursive
2907 if ((h
->flags
& XCOFF_BUILT_LDSYM
) != 0)
2910 /* We need to add this symbol to the .loader symbols. */
2912 /* h->ldsym will already have been allocated for an explicitly
2914 if (h
->ldsym
== NULL
)
2916 h
->ldsym
= ((struct internal_ldsym
*)
2917 bfd_zalloc (ldinfo
->output_bfd
,
2918 sizeof (struct internal_ldsym
)));
2919 if (h
->ldsym
== NULL
)
2921 ldinfo
->failed
= true;
2922 bfd_set_error (bfd_error_no_memory
);
2927 /* The first 3 symbol table indices are reserved to indicate the
2929 h
->ldindx
= ldinfo
->ldsym_count
+ 3;
2931 ++ldinfo
->ldsym_count
;
2933 len
= strlen (h
->root
.root
.string
);
2934 if (len
<= SYMNMLEN
)
2935 strncpy (h
->ldsym
->_l
._l_name
, h
->root
.root
.string
, SYMNMLEN
);
2938 if (ldinfo
->string_size
+ len
+ 3 > ldinfo
->string_alc
)
2941 bfd_byte
*newstrings
;
2943 newalc
= ldinfo
->string_alc
* 2;
2946 while (ldinfo
->string_size
+ len
+ 3 > newalc
)
2949 if (ldinfo
->strings
== NULL
)
2950 newstrings
= (bfd_byte
*) malloc (newalc
);
2952 newstrings
= ((bfd_byte
*)
2953 realloc ((PTR
) ldinfo
->strings
, newalc
));
2954 if (newstrings
== NULL
)
2956 ldinfo
->failed
= true;
2957 bfd_set_error (bfd_error_no_memory
);
2960 ldinfo
->string_alc
= newalc
;
2961 ldinfo
->strings
= newstrings
;
2964 bfd_put_16 (ldinfo
->output_bfd
, len
+ 1,
2965 ldinfo
->strings
+ ldinfo
->string_size
);
2966 strcpy (ldinfo
->strings
+ ldinfo
->string_size
+ 2, h
->root
.root
.string
);
2967 h
->ldsym
->_l
._l_l
._l_zeroes
= 0;
2968 h
->ldsym
->_l
._l_l
._l_offset
= ldinfo
->string_size
+ 2;
2969 ldinfo
->string_size
+= len
+ 3;
2972 h
->flags
|= XCOFF_BUILT_LDSYM
;
2977 /* Do the final link step. */
2980 _bfd_xcoff_bfd_final_link (abfd
, info
)
2982 struct bfd_link_info
*info
;
2984 bfd_size_type symesz
;
2985 struct xcoff_final_link_info finfo
;
2987 struct bfd_link_order
*p
;
2988 size_t max_contents_size
;
2989 size_t max_sym_count
;
2990 size_t max_lineno_count
;
2991 size_t max_reloc_count
;
2992 size_t max_output_reloc_count
;
2993 file_ptr rel_filepos
;
2995 file_ptr line_filepos
;
2996 unsigned int linesz
;
2998 bfd_byte
*external_relocs
= NULL
;
2999 char strbuf
[STRING_SIZE_SIZE
];
3002 abfd
->flags
|= DYNAMIC
;
3004 symesz
= bfd_coff_symesz (abfd
);
3007 finfo
.output_bfd
= abfd
;
3008 finfo
.strtab
= NULL
;
3009 finfo
.section_info
= NULL
;
3010 finfo
.last_file_index
= -1;
3011 finfo
.toc_symindx
= -1;
3012 finfo
.internal_syms
= NULL
;
3013 finfo
.sym_indices
= NULL
;
3014 finfo
.outsyms
= NULL
;
3015 finfo
.linenos
= NULL
;
3016 finfo
.contents
= NULL
;
3017 finfo
.external_relocs
= NULL
;
3019 finfo
.ldsym
= ((struct external_ldsym
*)
3020 (xcoff_hash_table (info
)->loader_section
->contents
3022 finfo
.ldrel
= ((struct external_ldrel
*)
3023 (xcoff_hash_table (info
)->loader_section
->contents
3025 + xcoff_hash_table (info
)->ldhdr
.l_nsyms
* LDSYMSZ
));
3027 xcoff_data (abfd
)->coff
.link_info
= info
;
3029 finfo
.strtab
= _bfd_stringtab_init ();
3030 if (finfo
.strtab
== NULL
)
3033 /* Compute the file positions for all the sections. */
3034 if (abfd
->output_has_begun
)
3036 if (xcoff_hash_table (info
)->file_align
!= 0)
3043 file_align
= xcoff_hash_table (info
)->file_align
;
3044 if (file_align
!= 0)
3046 boolean saw_contents
;
3051 /* Insert .pad sections before every section which has
3052 contents and is loaded, if it is preceded by some other
3053 section which has contents and is loaded. */
3054 saw_contents
= true;
3055 for (op
= &abfd
->sections
; *op
!= NULL
; op
= &(*op
)->next
)
3057 (*op
)->target_index
= indx
;
3058 if (strcmp ((*op
)->name
, ".pad") == 0)
3059 saw_contents
= false;
3060 else if (((*op
)->flags
& SEC_HAS_CONTENTS
) != 0
3061 && ((*op
)->flags
& SEC_LOAD
) != 0)
3064 saw_contents
= true;
3071 n
= bfd_make_section_anyway (abfd
, ".pad");
3072 BFD_ASSERT (*op
== n
);
3074 n
->flags
= SEC_HAS_CONTENTS
;
3075 n
->alignment_power
= 0;
3076 saw_contents
= false;
3081 /* Reset the section indices after inserting the new
3084 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3087 o
->target_index
= indx
;
3089 BFD_ASSERT ((unsigned int) indx
== abfd
->section_count
);
3091 /* Work out appropriate sizes for the .pad sections to force
3092 each section to land on a page boundary. This bit of
3093 code knows what compute_section_file_positions is going
3095 sofar
= bfd_coff_filhsz (abfd
);
3096 sofar
+= bfd_coff_aoutsz (abfd
);
3097 sofar
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
3099 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3101 if (strcmp (o
->name
, ".pad") == 0)
3105 BFD_ASSERT (o
->_raw_size
== 0);
3106 pageoff
= sofar
& (file_align
- 1);
3109 o
->_raw_size
= file_align
- pageoff
;
3110 sofar
+= file_align
- pageoff
;
3111 o
->flags
|= SEC_HAS_CONTENTS
;
3116 if ((o
->flags
& SEC_HAS_CONTENTS
) != 0)
3117 sofar
+= BFD_ALIGN (o
->_raw_size
,
3118 1 << o
->alignment_power
);
3123 bfd_coff_compute_section_file_positions (abfd
);
3126 /* Count the line numbers and relocation entries required for the
3127 output file. Set the file positions for the relocs. */
3128 rel_filepos
= obj_relocbase (abfd
);
3129 relsz
= bfd_coff_relsz (abfd
);
3130 max_contents_size
= 0;
3131 max_lineno_count
= 0;
3132 max_reloc_count
= 0;
3133 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3136 o
->lineno_count
= 0;
3137 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3139 if (p
->type
== bfd_indirect_link_order
)
3143 sec
= p
->u
.indirect
.section
;
3145 if (info
->strip
== strip_none
3146 || info
->strip
== strip_some
)
3147 o
->lineno_count
+= sec
->lineno_count
;
3149 o
->reloc_count
+= sec
->reloc_count
;
3151 if (sec
->_raw_size
> max_contents_size
)
3152 max_contents_size
= sec
->_raw_size
;
3153 if (sec
->lineno_count
> max_lineno_count
)
3154 max_lineno_count
= sec
->lineno_count
;
3155 if (coff_section_data (sec
->owner
, sec
) != NULL
3156 && xcoff_section_data (sec
->owner
, sec
) != NULL
3157 && (xcoff_section_data (sec
->owner
, sec
)->lineno_count
3158 > max_lineno_count
))
3160 xcoff_section_data (sec
->owner
, sec
)->lineno_count
;
3161 if (sec
->reloc_count
> max_reloc_count
)
3162 max_reloc_count
= sec
->reloc_count
;
3164 else if (p
->type
== bfd_section_reloc_link_order
3165 || p
->type
== bfd_symbol_reloc_link_order
)
3168 if (o
->reloc_count
== 0)
3172 o
->flags
|= SEC_RELOC
;
3173 o
->rel_filepos
= rel_filepos
;
3174 rel_filepos
+= o
->reloc_count
* relsz
;
3178 /* Allocate space for the pointers we need to keep for the relocs. */
3182 /* We use section_count + 1, rather than section_count, because
3183 the target_index fields are 1 based. */
3184 finfo
.section_info
= ((struct xcoff_link_section_info
*)
3185 malloc ((abfd
->section_count
+ 1)
3186 * sizeof (struct xcoff_link_section_info
)));
3187 if (finfo
.section_info
== NULL
)
3189 bfd_set_error (bfd_error_no_memory
);
3192 for (i
= 0; i
<= abfd
->section_count
; i
++)
3194 finfo
.section_info
[i
].relocs
= NULL
;
3195 finfo
.section_info
[i
].rel_hashes
= NULL
;
3196 finfo
.section_info
[i
].toc_rel_hashes
= NULL
;
3200 /* We now know the size of the relocs, so we can determine the file
3201 positions of the line numbers. */
3202 line_filepos
= rel_filepos
;
3203 finfo
.line_filepos
= line_filepos
;
3204 linesz
= bfd_coff_linesz (abfd
);
3205 max_output_reloc_count
= 0;
3206 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3208 if (o
->lineno_count
== 0)
3209 o
->line_filepos
= 0;
3212 o
->line_filepos
= line_filepos
;
3213 line_filepos
+= o
->lineno_count
* linesz
;
3216 if (o
->reloc_count
!= 0)
3218 /* We don't know the indices of global symbols until we have
3219 written out all the local symbols. For each section in
3220 the output file, we keep an array of pointers to hash
3221 table entries. Each entry in the array corresponds to a
3222 reloc. When we find a reloc against a global symbol, we
3223 set the corresponding entry in this array so that we can
3224 fix up the symbol index after we have written out all the
3227 Because of this problem, we also keep the relocs in
3228 memory until the end of the link. This wastes memory.
3229 We could backpatch the file later, I suppose, although it
3231 finfo
.section_info
[o
->target_index
].relocs
=
3232 ((struct internal_reloc
*)
3233 malloc (o
->reloc_count
* sizeof (struct internal_reloc
)));
3234 finfo
.section_info
[o
->target_index
].rel_hashes
=
3235 ((struct xcoff_link_hash_entry
**)
3236 malloc (o
->reloc_count
3237 * sizeof (struct xcoff_link_hash_entry
*)));
3238 if (finfo
.section_info
[o
->target_index
].relocs
== NULL
3239 || finfo
.section_info
[o
->target_index
].rel_hashes
== NULL
)
3241 bfd_set_error (bfd_error_no_memory
);
3245 if (o
->reloc_count
> max_output_reloc_count
)
3246 max_output_reloc_count
= o
->reloc_count
;
3249 /* Reset the reloc and lineno counts, so that we can use them to
3250 count the number of entries we have output so far. */
3252 o
->lineno_count
= 0;
3255 obj_sym_filepos (abfd
) = line_filepos
;
3257 /* Figure out the largest number of symbols in an input BFD. Take
3258 the opportunity to clear the output_has_begun fields of all the
3259 input BFD's. We want at least 4 symbols, since that is the
3260 number which xcoff_write_global_symbol may need. */
3262 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
3266 sub
->output_has_begun
= false;
3267 sz
= obj_raw_syment_count (sub
);
3268 if (sz
> max_sym_count
)
3272 /* Allocate some buffers used while linking. */
3273 finfo
.internal_syms
= ((struct internal_syment
*)
3274 malloc (max_sym_count
3275 * sizeof (struct internal_syment
)));
3276 finfo
.sym_indices
= (long *) malloc (max_sym_count
* sizeof (long));
3277 finfo
.outsyms
= ((bfd_byte
*)
3278 malloc ((size_t) ((max_sym_count
+ 1) * symesz
)));
3279 finfo
.linenos
= (bfd_byte
*) malloc (max_lineno_count
3280 * bfd_coff_linesz (abfd
));
3281 finfo
.contents
= (bfd_byte
*) malloc (max_contents_size
);
3282 finfo
.external_relocs
= (bfd_byte
*) malloc (max_reloc_count
* relsz
);
3283 if ((finfo
.internal_syms
== NULL
&& max_sym_count
> 0)
3284 || (finfo
.sym_indices
== NULL
&& max_sym_count
> 0)
3285 || finfo
.outsyms
== NULL
3286 || (finfo
.linenos
== NULL
&& max_lineno_count
> 0)
3287 || (finfo
.contents
== NULL
&& max_contents_size
> 0)
3288 || (finfo
.external_relocs
== NULL
&& max_reloc_count
> 0))
3290 bfd_set_error (bfd_error_no_memory
);
3294 obj_raw_syment_count (abfd
) = 0;
3295 xcoff_data (abfd
)->toc
= (bfd_vma
) -1;
3297 /* We now know the position of everything in the file, except that
3298 we don't know the size of the symbol table and therefore we don't
3299 know where the string table starts. We just build the string
3300 table in memory as we go along. We process all the relocations
3301 for a single input file at once. */
3302 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3304 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
3306 if (p
->type
== bfd_indirect_link_order
3307 && p
->u
.indirect
.section
->owner
->xvec
== abfd
->xvec
)
3309 sub
= p
->u
.indirect
.section
->owner
;
3310 if (! sub
->output_has_begun
)
3312 if (! xcoff_link_input_bfd (&finfo
, sub
))
3314 sub
->output_has_begun
= true;
3317 else if (p
->type
== bfd_section_reloc_link_order
3318 || p
->type
== bfd_symbol_reloc_link_order
)
3320 if (! xcoff_reloc_link_order (abfd
, &finfo
, o
, p
))
3325 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
3331 /* Free up the buffers used by xcoff_link_input_bfd. */
3333 if (finfo
.internal_syms
!= NULL
)
3335 free (finfo
.internal_syms
);
3336 finfo
.internal_syms
= NULL
;
3338 if (finfo
.sym_indices
!= NULL
)
3340 free (finfo
.sym_indices
);
3341 finfo
.sym_indices
= NULL
;
3343 if (finfo
.linenos
!= NULL
)
3345 free (finfo
.linenos
);
3346 finfo
.linenos
= NULL
;
3348 if (finfo
.contents
!= NULL
)
3350 free (finfo
.contents
);
3351 finfo
.contents
= NULL
;
3353 if (finfo
.external_relocs
!= NULL
)
3355 free (finfo
.external_relocs
);
3356 finfo
.external_relocs
= NULL
;
3359 /* The value of the last C_FILE symbol is supposed to be -1. Write
3361 if (finfo
.last_file_index
!= -1)
3363 finfo
.last_file
.n_value
= -1;
3364 bfd_coff_swap_sym_out (abfd
, (PTR
) &finfo
.last_file
,
3365 (PTR
) finfo
.outsyms
);
3367 (obj_sym_filepos (abfd
)
3368 + finfo
.last_file_index
* symesz
),
3370 || bfd_write (finfo
.outsyms
, symesz
, 1, abfd
) != symesz
)
3374 /* Write out all the global symbols which do not come from XCOFF
3376 xcoff_link_hash_traverse (xcoff_hash_table (info
),
3377 xcoff_write_global_symbol
,
3380 if (finfo
.outsyms
!= NULL
)
3382 free (finfo
.outsyms
);
3383 finfo
.outsyms
= NULL
;
3386 /* Now that we have written out all the global symbols, we know the
3387 symbol indices to use for relocs against them, and we can finally
3388 write out the relocs. */
3389 external_relocs
= (bfd_byte
*) malloc (max_output_reloc_count
* relsz
);
3390 if (external_relocs
== NULL
&& max_output_reloc_count
!= 0)
3392 bfd_set_error (bfd_error_no_memory
);
3396 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
3398 struct internal_reloc
*irel
;
3399 struct internal_reloc
*irelend
;
3400 struct xcoff_link_hash_entry
**rel_hash
;
3401 struct xcoff_toc_rel_hash
*toc_rel_hash
;
3404 if (o
->reloc_count
== 0)
3407 irel
= finfo
.section_info
[o
->target_index
].relocs
;
3408 irelend
= irel
+ o
->reloc_count
;
3409 rel_hash
= finfo
.section_info
[o
->target_index
].rel_hashes
;
3410 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
3412 if (*rel_hash
!= NULL
)
3414 if ((*rel_hash
)->indx
< 0)
3416 if (! ((*info
->callbacks
->unattached_reloc
)
3417 (info
, (*rel_hash
)->root
.root
.string
,
3418 (bfd
*) NULL
, o
, irel
->r_vaddr
)))
3420 (*rel_hash
)->indx
= 0;
3422 irel
->r_symndx
= (*rel_hash
)->indx
;
3426 for (toc_rel_hash
= finfo
.section_info
[o
->target_index
].toc_rel_hashes
;
3427 toc_rel_hash
!= NULL
;
3428 toc_rel_hash
= toc_rel_hash
->next
)
3430 if (toc_rel_hash
->h
->u
.toc_indx
< 0)
3432 if (! ((*info
->callbacks
->unattached_reloc
)
3433 (info
, toc_rel_hash
->h
->root
.root
.string
,
3434 (bfd
*) NULL
, o
, toc_rel_hash
->rel
->r_vaddr
)))
3436 toc_rel_hash
->h
->u
.toc_indx
= 0;
3438 toc_rel_hash
->rel
->r_symndx
= toc_rel_hash
->h
->u
.toc_indx
;
3441 /* XCOFF requires that the relocs be sorted by address. We tend
3442 to produce them in the order in which their containing csects
3443 appear in the symbol table, which is not necessarily by
3444 address. So we sort them here. There may be a better way to
3446 qsort ((PTR
) finfo
.section_info
[o
->target_index
].relocs
,
3447 o
->reloc_count
, sizeof (struct internal_reloc
),
3450 irel
= finfo
.section_info
[o
->target_index
].relocs
;
3451 irelend
= irel
+ o
->reloc_count
;
3452 erel
= external_relocs
;
3453 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
3454 bfd_coff_swap_reloc_out (abfd
, (PTR
) irel
, (PTR
) erel
);
3456 if (bfd_seek (abfd
, o
->rel_filepos
, SEEK_SET
) != 0
3457 || bfd_write ((PTR
) external_relocs
, relsz
, o
->reloc_count
,
3458 abfd
) != relsz
* o
->reloc_count
)
3462 if (external_relocs
!= NULL
)
3464 free (external_relocs
);
3465 external_relocs
= NULL
;
3468 /* Free up the section information. */
3469 if (finfo
.section_info
!= NULL
)
3473 for (i
= 0; i
< abfd
->section_count
; i
++)
3475 if (finfo
.section_info
[i
].relocs
!= NULL
)
3476 free (finfo
.section_info
[i
].relocs
);
3477 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
3478 free (finfo
.section_info
[i
].rel_hashes
);
3480 free (finfo
.section_info
);
3481 finfo
.section_info
= NULL
;
3484 /* Write out the loader section contents. */
3485 BFD_ASSERT ((bfd_byte
*) finfo
.ldrel
3486 == (xcoff_hash_table (info
)->loader_section
->contents
3487 + xcoff_hash_table (info
)->ldhdr
.l_impoff
));
3488 o
= xcoff_hash_table (info
)->loader_section
;
3489 if (! bfd_set_section_contents (abfd
, o
->output_section
,
3490 o
->contents
, o
->output_offset
,
3494 /* Write out the global linkage section and the toc section. */
3495 o
= xcoff_hash_table (info
)->linkage_section
;
3496 if (o
->_raw_size
> 0
3497 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
3498 o
->output_offset
, o
->_raw_size
))
3500 o
= xcoff_hash_table (info
)->toc_section
;
3501 if (o
->_raw_size
> 0
3502 && ! bfd_set_section_contents (abfd
, o
->output_section
, o
->contents
,
3503 o
->output_offset
, o
->_raw_size
))
3506 /* Write out the string table. */
3508 (obj_sym_filepos (abfd
)
3509 + obj_raw_syment_count (abfd
) * symesz
),
3513 _bfd_stringtab_size (finfo
.strtab
) + STRING_SIZE_SIZE
,
3514 (bfd_byte
*) strbuf
);
3515 if (bfd_write (strbuf
, 1, STRING_SIZE_SIZE
, abfd
) != STRING_SIZE_SIZE
)
3517 if (! _bfd_stringtab_emit (abfd
, finfo
.strtab
))
3520 _bfd_stringtab_free (finfo
.strtab
);
3522 /* Write out the debugging string table. */
3523 o
= xcoff_hash_table (info
)->debug_section
;
3526 struct bfd_strtab_hash
*debug_strtab
;
3528 debug_strtab
= xcoff_hash_table (info
)->debug_strtab
;
3529 BFD_ASSERT (o
->output_section
->_raw_size
- o
->output_offset
3530 >= _bfd_stringtab_size (debug_strtab
));
3532 o
->output_section
->filepos
+ o
->output_offset
,
3535 if (! _bfd_stringtab_emit (abfd
, debug_strtab
))
3539 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
3540 not try to write out the symbols. */
3541 bfd_get_symcount (abfd
) = 0;
3546 if (finfo
.strtab
!= NULL
)
3547 _bfd_stringtab_free (finfo
.strtab
);
3548 if (finfo
.section_info
!= NULL
)
3552 for (i
= 0; i
< abfd
->section_count
; i
++)
3554 if (finfo
.section_info
[i
].relocs
!= NULL
)
3555 free (finfo
.section_info
[i
].relocs
);
3556 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
3557 free (finfo
.section_info
[i
].rel_hashes
);
3559 free (finfo
.section_info
);
3561 if (finfo
.internal_syms
!= NULL
)
3562 free (finfo
.internal_syms
);
3563 if (finfo
.sym_indices
!= NULL
)
3564 free (finfo
.sym_indices
);
3565 if (finfo
.outsyms
!= NULL
)
3566 free (finfo
.outsyms
);
3567 if (finfo
.linenos
!= NULL
)
3568 free (finfo
.linenos
);
3569 if (finfo
.contents
!= NULL
)
3570 free (finfo
.contents
);
3571 if (finfo
.external_relocs
!= NULL
)
3572 free (finfo
.external_relocs
);
3573 if (external_relocs
!= NULL
)
3574 free (external_relocs
);
3578 /* Link an input file into the linker output file. This function
3579 handles all the sections and relocations of the input file at once. */
3582 xcoff_link_input_bfd (finfo
, input_bfd
)
3583 struct xcoff_final_link_info
*finfo
;
3587 const char *strings
;
3588 bfd_size_type syment_base
;
3589 unsigned int n_tmask
;
3590 unsigned int n_btshft
;
3592 bfd_size_type isymesz
;
3593 bfd_size_type osymesz
;
3594 bfd_size_type linesz
;
3597 struct xcoff_link_hash_entry
**sym_hash
;
3598 struct internal_syment
*isymp
;
3600 unsigned long *debug_index
;
3602 unsigned long output_index
;
3609 /* We can just skip DYNAMIC files, unless this is a static link. */
3610 if ((input_bfd
->flags
& DYNAMIC
) != 0
3611 && ! finfo
->info
->static_link
)
3614 /* Move all the symbols to the output file. */
3616 output_bfd
= finfo
->output_bfd
;
3618 syment_base
= obj_raw_syment_count (output_bfd
);
3619 isymesz
= bfd_coff_symesz (input_bfd
);
3620 osymesz
= bfd_coff_symesz (output_bfd
);
3621 linesz
= bfd_coff_linesz (input_bfd
);
3622 BFD_ASSERT (linesz
== bfd_coff_linesz (output_bfd
));
3624 n_tmask
= coff_data (input_bfd
)->local_n_tmask
;
3625 n_btshft
= coff_data (input_bfd
)->local_n_btshft
;
3627 /* Define macros so that ISFCN, et. al., macros work correctly. */
3628 #define N_TMASK n_tmask
3629 #define N_BTSHFT n_btshft
3632 if (! finfo
->info
->keep_memory
)
3635 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
3638 if (! _bfd_coff_get_external_symbols (input_bfd
))
3641 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
3642 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
3643 sym_hash
= obj_xcoff_sym_hashes (input_bfd
);
3644 csectpp
= xcoff_data (input_bfd
)->csects
;
3645 debug_index
= xcoff_data (input_bfd
)->debug_indices
;
3646 isymp
= finfo
->internal_syms
;
3647 indexp
= finfo
->sym_indices
;
3648 output_index
= syment_base
;
3649 outsym
= finfo
->outsyms
;
3653 while (esym
< esym_end
)
3655 struct internal_syment isym
;
3656 union internal_auxent aux
;
3662 bfd_coff_swap_sym_in (input_bfd
, (PTR
) esym
, (PTR
) isymp
);
3664 /* If this is a C_EXT or C_HIDEXT symbol, we need the csect
3666 if (isymp
->n_sclass
== C_EXT
|| isymp
->n_sclass
== C_HIDEXT
)
3668 BFD_ASSERT (isymp
->n_numaux
> 0);
3669 bfd_coff_swap_aux_in (input_bfd
,
3670 (PTR
) (esym
+ isymesz
* isymp
->n_numaux
),
3671 isymp
->n_type
, isymp
->n_sclass
,
3672 isymp
->n_numaux
- 1, isymp
->n_numaux
,
3674 smtyp
= SMTYP_SMTYP (aux
.x_csect
.x_smtyp
);
3677 /* Make a copy of *isymp so that the relocate_section function
3678 always sees the original values. This is more reliable than
3679 always recomputing the symbol value even if we are stripping
3683 /* If this symbol is in the .loader section, swap out the
3684 .loader symbol information. If this is an external symbol
3685 reference to a defined symbol, though, then wait until we get
3686 to the definition. */
3687 if (isym
.n_sclass
== C_EXT
3688 && *sym_hash
!= NULL
3689 && (*sym_hash
)->ldsym
!= NULL
3691 || (*sym_hash
)->root
.type
== bfd_link_hash_undefined
))
3693 struct xcoff_link_hash_entry
*h
;
3694 struct internal_ldsym
*ldsym
;
3698 if (isym
.n_scnum
> 0)
3700 ldsym
->l_scnum
= (*csectpp
)->output_section
->target_index
;
3701 ldsym
->l_value
= (isym
.n_value
3702 + (*csectpp
)->output_section
->vma
3703 + (*csectpp
)->output_offset
3708 ldsym
->l_scnum
= isym
.n_scnum
;
3709 ldsym
->l_value
= isym
.n_value
;
3712 ldsym
->l_smtype
= smtyp
;
3713 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
3714 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3715 || (h
->flags
& XCOFF_IMPORT
) != 0)
3716 ldsym
->l_smtype
|= L_IMPORT
;
3717 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
3718 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
3719 || (h
->flags
& XCOFF_EXPORT
) != 0)
3720 ldsym
->l_smtype
|= L_EXPORT
;
3721 if ((h
->flags
& XCOFF_ENTRY
) != 0)
3722 ldsym
->l_smtype
|= L_ENTRY
;
3724 ldsym
->l_smclas
= aux
.x_csect
.x_smclas
;
3726 if (ldsym
->l_ifile
== (bfd_size_type
) -1)
3728 else if (ldsym
->l_ifile
== 0)
3730 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
3736 if (h
->root
.type
== bfd_link_hash_defined
3737 || h
->root
.type
== bfd_link_hash_defweak
)
3738 impbfd
= h
->root
.u
.def
.section
->owner
;
3739 else if (h
->root
.type
== bfd_link_hash_undefined
3740 || h
->root
.type
== bfd_link_hash_undefweak
)
3741 impbfd
= h
->root
.u
.undef
.abfd
;
3749 BFD_ASSERT (impbfd
->xvec
== finfo
->output_bfd
->xvec
);
3750 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
3757 BFD_ASSERT (h
->ldindx
>= 0);
3758 BFD_ASSERT (LDSYMSZ
== sizeof (struct external_ldsym
));
3759 xcoff_swap_ldsym_out (finfo
->output_bfd
, ldsym
,
3760 finfo
->ldsym
+ h
->ldindx
- 3);
3768 add
= 1 + isym
.n_numaux
;
3770 /* If we are skipping this csect, we want to skip this symbol. */
3771 if (*csectpp
== NULL
)
3774 /* If we garbage collected this csect, we want to skip this
3777 && xcoff_hash_table (finfo
->info
)->gc
3778 && ((*csectpp
)->flags
& SEC_MARK
) == 0
3779 && *csectpp
!= bfd_abs_section_ptr
)
3782 /* An XCOFF linker always skips C_STAT symbols. */
3784 && isymp
->n_sclass
== C_STAT
)
3787 /* We skip all but the first TOC anchor. */
3789 && isymp
->n_sclass
== C_HIDEXT
3790 && aux
.x_csect
.x_smclas
== XMC_TC0
)
3792 if (finfo
->toc_symindx
!= -1)
3796 finfo
->toc_symindx
= output_index
;
3797 xcoff_data (finfo
->output_bfd
)->toc
=
3798 ((*csectpp
)->output_section
->vma
3799 + (*csectpp
)->output_offset
3802 xcoff_data (finfo
->output_bfd
)->toc_section
=
3803 (*csectpp
)->output_section
;
3808 /* If we are stripping all symbols, we want to skip this one. */
3810 && finfo
->info
->strip
== strip_all
)
3813 /* We can skip resolved external references. */
3815 && isym
.n_sclass
== C_EXT
3817 && (*sym_hash
)->root
.type
!= bfd_link_hash_undefined
)
3820 /* We can skip common symbols if they got defined somewhere
3823 && isym
.n_sclass
== C_EXT
3825 && ((*sym_hash
)->root
.type
!= bfd_link_hash_common
3826 || (*sym_hash
)->root
.u
.c
.p
->section
!= *csectpp
)
3827 && ((*sym_hash
)->root
.type
!= bfd_link_hash_defined
3828 || (*sym_hash
)->root
.u
.def
.section
!= *csectpp
))
3831 /* Skip local symbols if we are discarding them. */
3833 && finfo
->info
->discard
== discard_all
3834 && isym
.n_sclass
!= C_EXT
3835 && (isym
.n_sclass
!= C_HIDEXT
3836 || smtyp
!= XTY_SD
))
3839 /* If we stripping debugging symbols, and this is a debugging
3840 symbol, then skip it. */
3842 && finfo
->info
->strip
== strip_debugger
3843 && isym
.n_scnum
== N_DEBUG
)
3846 /* If some symbols are stripped based on the name, work out the
3847 name and decide whether to skip this symbol. We don't handle
3848 this correctly for symbols whose names are in the .debug
3849 section; to get it right we would need a new bfd_strtab_hash
3850 function to return the string given the index. */
3852 && (finfo
->info
->strip
== strip_some
3853 || finfo
->info
->discard
== discard_l
)
3854 && (debug_index
== NULL
|| *debug_index
== (unsigned long) -1))
3857 char buf
[SYMNMLEN
+ 1];
3859 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
, buf
);
3863 if ((finfo
->info
->strip
== strip_some
3864 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false,
3866 || (finfo
->info
->discard
== discard_l
3867 && (isym
.n_sclass
!= C_EXT
3868 && (isym
.n_sclass
!= C_HIDEXT
3869 || smtyp
!= XTY_SD
))
3870 && strncmp (name
, finfo
->info
->lprefix
,
3871 finfo
->info
->lprefix_len
) == 0))
3875 /* We can not skip the first TOC anchor. */
3878 && finfo
->info
->strip
!= strip_all
)
3881 /* We now know whether we are to skip this symbol or not. */
3884 /* Adjust the symbol in order to output it. */
3886 if (isym
._n
._n_n
._n_zeroes
== 0
3887 && isym
._n
._n_n
._n_offset
!= 0)
3889 /* This symbol has a long name. Enter it in the string
3890 table we are building. If *debug_index != -1, the
3891 name has already been entered in the .debug section. */
3892 if (debug_index
!= NULL
&& *debug_index
!= (unsigned long) -1)
3893 isym
._n
._n_n
._n_offset
= *debug_index
;
3899 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
,
3903 indx
= _bfd_stringtab_add (finfo
->strtab
, name
, hash
, copy
);
3904 if (indx
== (bfd_size_type
) -1)
3906 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
3910 if (isym
.n_sclass
!= C_BSTAT
3911 && isym
.n_sclass
!= C_ESTAT
3912 && isym
.n_sclass
!= C_DECL
3913 && isym
.n_scnum
> 0)
3915 isym
.n_scnum
= (*csectpp
)->output_section
->target_index
;
3916 isym
.n_value
+= ((*csectpp
)->output_section
->vma
3917 + (*csectpp
)->output_offset
3921 /* The value of a C_FILE symbol is the symbol index of the
3922 next C_FILE symbol. The value of the last C_FILE symbol
3923 is -1. We try to get this right, below, just before we
3924 write the symbols out, but in the general case we may
3925 have to write the symbol out twice. */
3926 if (isym
.n_sclass
== C_FILE
)
3928 if (finfo
->last_file_index
!= -1
3929 && finfo
->last_file
.n_value
!= (long) output_index
)
3931 /* We must correct the value of the last C_FILE entry. */
3932 finfo
->last_file
.n_value
= output_index
;
3933 if ((bfd_size_type
) finfo
->last_file_index
>= syment_base
)
3935 /* The last C_FILE symbol is in this input file. */
3936 bfd_coff_swap_sym_out (output_bfd
,
3937 (PTR
) &finfo
->last_file
,
3938 (PTR
) (finfo
->outsyms
3939 + ((finfo
->last_file_index
3945 /* We have already written out the last C_FILE
3946 symbol. We need to write it out again. We
3947 borrow *outsym temporarily. */
3948 bfd_coff_swap_sym_out (output_bfd
,
3949 (PTR
) &finfo
->last_file
,
3951 if (bfd_seek (output_bfd
,
3952 (obj_sym_filepos (output_bfd
)
3953 + finfo
->last_file_index
* osymesz
),
3955 || (bfd_write (outsym
, osymesz
, 1, output_bfd
)
3961 finfo
->last_file_index
= output_index
;
3962 finfo
->last_file
= isym
;
3965 /* The value of a C_BINCL or C_EINCL symbol is a file offset
3966 into the line numbers. We update the symbol values when
3967 we handle the line numbers. */
3968 if (isym
.n_sclass
== C_BINCL
3969 || isym
.n_sclass
== C_EINCL
)
3971 isym
.n_value
= finfo
->line_filepos
;
3975 /* Output the symbol. */
3977 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
3979 *indexp
= output_index
;
3981 if (isym
.n_sclass
== C_EXT
)
3984 struct xcoff_link_hash_entry
*h
;
3986 indx
= ((esym
- (bfd_byte
*) obj_coff_external_syms (input_bfd
))
3988 h
= obj_xcoff_sym_hashes (input_bfd
)[indx
];
3989 BFD_ASSERT (h
!= NULL
);
3990 h
->indx
= output_index
;
3993 /* If this is a symbol in the TOC which we may have merged
3994 (class XMC_TC), remember the symbol index of the TOC
3996 if (isym
.n_sclass
== C_HIDEXT
3997 && aux
.x_csect
.x_smclas
== XMC_TC
3998 && *sym_hash
!= NULL
)
4000 BFD_ASSERT (((*sym_hash
)->flags
& XCOFF_SET_TOC
) == 0);
4001 BFD_ASSERT ((*sym_hash
)->toc_section
!= NULL
);
4002 (*sym_hash
)->u
.toc_indx
= output_index
;
4005 output_index
+= add
;
4006 outsym
+= add
* osymesz
;
4009 esym
+= add
* isymesz
;
4013 if (debug_index
!= NULL
)
4016 for (--add
; add
> 0; --add
)
4020 /* Fix up the aux entries and the C_BSTAT symbols. This must be
4021 done in a separate pass, because we don't know the correct symbol
4022 indices until we have already decided which symbols we are going
4025 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
4026 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
4027 isymp
= finfo
->internal_syms
;
4028 indexp
= finfo
->sym_indices
;
4029 csectpp
= xcoff_data (input_bfd
)->csects
;
4030 outsym
= finfo
->outsyms
;
4031 while (esym
< esym_end
)
4035 add
= 1 + isymp
->n_numaux
;
4038 esym
+= add
* isymesz
;
4043 if (isymp
->n_sclass
== C_BSTAT
)
4045 struct internal_syment isym
;
4048 /* The value of a C_BSTAT symbol is the symbol table
4049 index of the containing csect. */
4050 bfd_coff_swap_sym_in (output_bfd
, (PTR
) outsym
, (PTR
) &isym
);
4051 indx
= isym
.n_value
;
4052 if (indx
< obj_raw_syment_count (input_bfd
))
4056 symindx
= finfo
->sym_indices
[indx
];
4060 isym
.n_value
= symindx
;
4061 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
,
4069 for (i
= 0; i
< isymp
->n_numaux
&& esym
< esym_end
; i
++)
4071 union internal_auxent aux
;
4073 bfd_coff_swap_aux_in (input_bfd
, (PTR
) esym
, isymp
->n_type
,
4074 isymp
->n_sclass
, i
, isymp
->n_numaux
,
4077 if (isymp
->n_sclass
== C_FILE
)
4079 /* This is the file name (or some comment put in by
4080 the compiler). If it is long, we must put it in
4081 the string table. */
4082 if (aux
.x_file
.x_n
.x_zeroes
== 0
4083 && aux
.x_file
.x_n
.x_offset
!= 0)
4085 const char *filename
;
4088 BFD_ASSERT (aux
.x_file
.x_n
.x_offset
4089 >= STRING_SIZE_SIZE
);
4090 if (strings
== NULL
)
4092 strings
= _bfd_coff_read_string_table (input_bfd
);
4093 if (strings
== NULL
)
4096 filename
= strings
+ aux
.x_file
.x_n
.x_offset
;
4097 indx
= _bfd_stringtab_add (finfo
->strtab
, filename
,
4099 if (indx
== (bfd_size_type
) -1)
4101 aux
.x_file
.x_n
.x_offset
= STRING_SIZE_SIZE
+ indx
;
4104 else if ((isymp
->n_sclass
== C_EXT
4105 || isymp
->n_sclass
== C_HIDEXT
)
4106 && i
+ 1 == isymp
->n_numaux
)
4108 /* We don't support type checking. I don't know if
4110 aux
.x_csect
.x_parmhash
= 0;
4111 /* I don't think anybody uses these fields, but we'd
4112 better clobber them just in case. */
4113 aux
.x_csect
.x_stab
= 0;
4114 aux
.x_csect
.x_snstab
= 0;
4115 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_LD
)
4119 indx
= aux
.x_csect
.x_scnlen
.l
;
4120 if (indx
< obj_raw_syment_count (input_bfd
))
4124 symindx
= finfo
->sym_indices
[indx
];
4126 aux
.x_sym
.x_tagndx
.l
= 0;
4128 aux
.x_sym
.x_tagndx
.l
= symindx
;
4132 else if (isymp
->n_sclass
!= C_STAT
|| isymp
->n_type
!= T_NULL
)
4136 if (ISFCN (isymp
->n_type
)
4137 || ISTAG (isymp
->n_sclass
)
4138 || isymp
->n_sclass
== C_BLOCK
)
4140 indx
= aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
4142 && indx
< obj_raw_syment_count (input_bfd
))
4144 /* We look forward through the symbol for
4145 the index of the next symbol we are going
4146 to include. I don't know if this is
4148 while (finfo
->sym_indices
[indx
] < 0
4149 && indx
< obj_raw_syment_count (input_bfd
))
4151 if (indx
>= obj_raw_syment_count (input_bfd
))
4152 indx
= output_index
;
4154 indx
= finfo
->sym_indices
[indx
];
4155 aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= indx
;
4159 indx
= aux
.x_sym
.x_tagndx
.l
;
4160 if (indx
> 0 && indx
< obj_raw_syment_count (input_bfd
))
4164 symindx
= finfo
->sym_indices
[indx
];
4166 aux
.x_sym
.x_tagndx
.l
= 0;
4168 aux
.x_sym
.x_tagndx
.l
= symindx
;
4172 /* Copy over the line numbers, unless we are stripping
4173 them. We do this on a symbol by symbol basis in
4174 order to more easily handle garbage collection. */
4175 if ((isymp
->n_sclass
== C_EXT
4176 || isymp
->n_sclass
== C_HIDEXT
)
4178 && isymp
->n_numaux
> 1
4179 && ISFCN (isymp
->n_type
)
4180 && aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
!= 0)
4182 if (finfo
->info
->strip
!= strip_none
4183 && finfo
->info
->strip
!= strip_some
)
4184 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4187 asection
*enclosing
;
4188 unsigned int enc_count
;
4189 bfd_size_type linoff
;
4190 struct internal_lineno lin
;
4193 enclosing
= xcoff_section_data (abfd
, o
)->enclosing
;
4194 enc_count
= xcoff_section_data (abfd
, o
)->lineno_count
;
4195 if (oline
!= enclosing
)
4197 if (bfd_seek (input_bfd
,
4198 enclosing
->line_filepos
,
4200 || (bfd_read (finfo
->linenos
, linesz
,
4201 enc_count
, input_bfd
)
4202 != linesz
* enc_count
))
4207 linoff
= (aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
4208 - enclosing
->line_filepos
);
4210 bfd_coff_swap_lineno_in (input_bfd
,
4211 (PTR
) (finfo
->linenos
+ linoff
),
4214 || ((bfd_size_type
) lin
.l_addr
.l_symndx
4218 obj_coff_external_syms (input_bfd
)))
4220 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= 0;
4223 bfd_byte
*linpend
, *linp
;
4225 bfd_size_type count
;
4227 lin
.l_addr
.l_symndx
= *indexp
;
4228 bfd_coff_swap_lineno_out (output_bfd
, (PTR
) &lin
,
4229 (PTR
) (finfo
->linenos
4232 linpend
= (finfo
->linenos
4233 + enc_count
* linesz
);
4234 offset
= (o
->output_section
->vma
4237 for (linp
= finfo
->linenos
+ linoff
+ linesz
;
4241 bfd_coff_swap_lineno_in (input_bfd
, (PTR
) linp
,
4243 if (lin
.l_lnno
== 0)
4245 lin
.l_addr
.l_paddr
+= offset
;
4246 bfd_coff_swap_lineno_out (output_bfd
,
4251 count
= (linp
- (finfo
->linenos
+ linoff
)) / linesz
;
4253 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
4254 (o
->output_section
->line_filepos
4255 + o
->output_section
->lineno_count
* linesz
);
4257 if (bfd_seek (output_bfd
,
4258 aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
4260 || (bfd_write (finfo
->linenos
+ linoff
,
4261 linesz
, count
, output_bfd
)
4265 o
->output_section
->lineno_count
+= count
;
4269 struct internal_syment
*iisp
, *iispend
;
4273 /* Update any C_BINCL or C_EINCL symbols
4274 that refer to a line number in the
4275 range we just output. */
4276 iisp
= finfo
->internal_syms
;
4278 + obj_raw_syment_count (input_bfd
));
4279 iindp
= finfo
->sym_indices
;
4280 oos
= finfo
->outsyms
;
4281 while (iisp
< iispend
)
4283 if ((iisp
->n_sclass
== C_BINCL
4284 || iisp
->n_sclass
== C_EINCL
)
4285 && ((bfd_size_type
) iisp
->n_value
4286 >= enclosing
->line_filepos
+ linoff
)
4287 && ((bfd_size_type
) iisp
->n_value
4288 < (enclosing
->line_filepos
4289 + enc_count
* linesz
)))
4291 struct internal_syment iis
;
4293 bfd_coff_swap_sym_in (output_bfd
,
4298 - enclosing
->line_filepos
4300 + aux
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
4301 bfd_coff_swap_sym_out (output_bfd
,
4307 iisp
+= iisp
->n_numaux
+ 1;
4308 iindp
+= iisp
->n_numaux
+ 1;
4309 oos
+= (iisp
->n_numaux
+ 1) * osymesz
;
4316 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, isymp
->n_type
,
4317 isymp
->n_sclass
, i
, isymp
->n_numaux
,
4329 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
4330 symbol will be the first symbol in the next input file. In the
4331 normal case, this will save us from writing out the C_FILE symbol
4333 if (finfo
->last_file_index
!= -1
4334 && (bfd_size_type
) finfo
->last_file_index
>= syment_base
)
4336 finfo
->last_file
.n_value
= output_index
;
4337 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &finfo
->last_file
,
4338 (PTR
) (finfo
->outsyms
4339 + ((finfo
->last_file_index
- syment_base
)
4343 /* Write the modified symbols to the output file. */
4344 if (outsym
> finfo
->outsyms
)
4346 if (bfd_seek (output_bfd
,
4347 obj_sym_filepos (output_bfd
) + syment_base
* osymesz
,
4349 || (bfd_write (finfo
->outsyms
, outsym
- finfo
->outsyms
, 1,
4351 != (bfd_size_type
) (outsym
- finfo
->outsyms
)))
4354 BFD_ASSERT ((obj_raw_syment_count (output_bfd
)
4355 + (outsym
- finfo
->outsyms
) / osymesz
)
4358 obj_raw_syment_count (output_bfd
) = output_index
;
4361 /* Don't let the linker relocation routines discard the symbols. */
4362 keep_syms
= obj_coff_keep_syms (input_bfd
);
4363 obj_coff_keep_syms (input_bfd
) = true;
4365 /* Relocate the contents of each section. */
4366 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
4370 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0
4371 || o
->_raw_size
== 0
4372 || (o
->flags
& SEC_IN_MEMORY
) != 0)
4375 /* We have set filepos correctly for the sections we created to
4376 represent csects, so bfd_get_section_contents should work. */
4377 if (coff_section_data (input_bfd
, o
) != NULL
4378 && coff_section_data (input_bfd
, o
)->contents
!= NULL
)
4379 contents
= coff_section_data (input_bfd
, o
)->contents
;
4382 if (! bfd_get_section_contents (input_bfd
, o
, finfo
->contents
,
4383 (file_ptr
) 0, o
->_raw_size
))
4385 contents
= finfo
->contents
;
4388 if ((o
->flags
& SEC_RELOC
) != 0)
4391 struct internal_reloc
*internal_relocs
;
4392 struct internal_reloc
*irel
;
4394 struct internal_reloc
*irelend
;
4395 struct xcoff_link_hash_entry
**rel_hash
;
4398 /* Read in the relocs. */
4399 target_index
= o
->output_section
->target_index
;
4400 internal_relocs
= (xcoff_read_internal_relocs
4401 (input_bfd
, o
, false, finfo
->external_relocs
,
4403 (finfo
->section_info
[target_index
].relocs
4404 + o
->output_section
->reloc_count
)));
4405 if (internal_relocs
== NULL
)
4408 /* Call processor specific code to relocate the section
4410 if (! bfd_coff_relocate_section (output_bfd
, finfo
->info
,
4414 finfo
->internal_syms
,
4415 xcoff_data (input_bfd
)->csects
))
4418 offset
= o
->output_section
->vma
+ o
->output_offset
- o
->vma
;
4419 irel
= internal_relocs
;
4420 irelend
= irel
+ o
->reloc_count
;
4421 rel_hash
= (finfo
->section_info
[target_index
].rel_hashes
4422 + o
->output_section
->reloc_count
);
4423 for (; irel
< irelend
; irel
++, rel_hash
++)
4425 struct xcoff_link_hash_entry
*h
= NULL
;
4426 struct internal_ldrel ldrel
;
4430 /* Adjust the reloc address and symbol index. */
4432 irel
->r_vaddr
+= offset
;
4434 r_symndx
= irel
->r_symndx
;
4438 h
= obj_xcoff_sym_hashes (input_bfd
)[r_symndx
];
4440 && (irel
->r_type
== R_TOC
4441 || irel
->r_type
== R_GL
4442 || irel
->r_type
== R_TCL
4443 || irel
->r_type
== R_TRL
4444 || irel
->r_type
== R_TRLA
))
4446 /* This is a TOC relative reloc with a symbol
4447 attached. The symbol should be the one which
4448 this reloc is for. We want to make this
4449 reloc against the TOC address of the symbol,
4450 not the symbol itself. */
4451 BFD_ASSERT (h
->toc_section
!= NULL
);
4452 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
4453 if (h
->u
.toc_indx
!= -1)
4454 irel
->r_symndx
= h
->u
.toc_indx
;
4457 struct xcoff_toc_rel_hash
*n
;
4458 struct xcoff_link_section_info
*si
;
4460 n
= ((struct xcoff_toc_rel_hash
*)
4461 bfd_alloc (finfo
->output_bfd
,
4462 sizeof (struct xcoff_toc_rel_hash
)));
4465 bfd_set_error (bfd_error_no_memory
);
4468 si
= finfo
->section_info
+ target_index
;
4469 n
->next
= si
->toc_rel_hashes
;
4472 si
->toc_rel_hashes
= n
;
4477 /* This is a global symbol. */
4479 irel
->r_symndx
= h
->indx
;
4482 /* This symbol is being written at the end
4483 of the file, and we do not yet know the
4484 symbol index. We save the pointer to the
4485 hash table entry in the rel_hash list.
4486 We set the indx field to -2 to indicate
4487 that this symbol must not be stripped. */
4496 indx
= finfo
->sym_indices
[r_symndx
];
4500 struct internal_syment
*is
;
4502 /* Relocations against a TC0 TOC anchor are
4503 automatically transformed to be against
4504 the TOC anchor in the output file. */
4505 is
= finfo
->internal_syms
+ r_symndx
;
4506 if (is
->n_sclass
== C_HIDEXT
4507 && is
->n_numaux
> 0)
4510 union internal_auxent aux
;
4514 obj_coff_external_syms (input_bfd
))
4515 + ((r_symndx
+ is
->n_numaux
)
4517 bfd_coff_swap_aux_in (input_bfd
, auxptr
,
4518 is
->n_type
, is
->n_sclass
,
4522 if (SMTYP_SMTYP (aux
.x_csect
.x_smtyp
) == XTY_SD
4523 && aux
.x_csect
.x_smclas
== XMC_TC0
)
4524 indx
= finfo
->toc_symindx
;
4529 irel
->r_symndx
= indx
;
4532 struct internal_syment
*is
;
4534 char buf
[SYMNMLEN
+ 1];
4536 /* This reloc is against a symbol we are
4537 stripping. It would be possible to handle
4538 this case, but I don't think it's worth it. */
4539 is
= finfo
->internal_syms
+ r_symndx
;
4541 name
= (_bfd_coff_internal_syment_name
4542 (input_bfd
, is
, buf
));
4546 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4547 (finfo
->info
, name
, input_bfd
, o
,
4554 switch (irel
->r_type
)
4558 || h
->root
.type
== bfd_link_hash_defined
4559 || h
->root
.type
== bfd_link_hash_defweak
4560 || h
->root
.type
== bfd_link_hash_common
)
4567 /* This reloc needs to be copied into the .loader
4569 ldrel
.l_vaddr
= irel
->r_vaddr
;
4571 ldrel
.l_symndx
= -1;
4573 || (h
->root
.type
== bfd_link_hash_defined
4574 || h
->root
.type
== bfd_link_hash_defweak
4575 || h
->root
.type
== bfd_link_hash_common
))
4580 sec
= xcoff_data (input_bfd
)->csects
[r_symndx
];
4581 else if (h
->root
.type
== bfd_link_hash_common
)
4582 sec
= h
->root
.u
.c
.p
->section
;
4584 sec
= h
->root
.u
.def
.section
;
4585 sec
= sec
->output_section
;
4587 if (strcmp (sec
->name
, ".text") == 0)
4589 else if (strcmp (sec
->name
, ".data") == 0)
4591 else if (strcmp (sec
->name
, ".bss") == 0)
4595 (*_bfd_error_handler
)
4596 ("%s: loader reloc in unrecognized section `%s'",
4597 bfd_get_filename (input_bfd
),
4599 bfd_set_error (bfd_error_nonrepresentable_section
);
4607 (*_bfd_error_handler
)
4608 ("%s: `%s' in loader reloc but not loader sym",
4609 bfd_get_filename (input_bfd
),
4610 h
->root
.root
.string
);
4611 bfd_set_error (bfd_error_bad_value
);
4614 ldrel
.l_symndx
= h
->ldindx
;
4616 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
4617 ldrel
.l_rsecnm
= o
->output_section
->target_index
;
4618 if (xcoff_hash_table (finfo
->info
)->textro
4619 && strcmp (o
->output_section
->name
, ".text") == 0)
4621 (*_bfd_error_handler
)
4622 ("%s: loader reloc in read-only section %s",
4623 bfd_get_filename (input_bfd
),
4624 bfd_get_section_name (finfo
->output_bfd
,
4625 o
->output_section
));
4626 bfd_set_error (bfd_error_invalid_operation
);
4629 xcoff_swap_ldrel_out (output_bfd
, &ldrel
,
4631 BFD_ASSERT (sizeof (struct external_ldrel
) == LDRELSZ
);
4640 /* We should never need a .loader reloc for a TOC
4646 o
->output_section
->reloc_count
+= o
->reloc_count
;
4649 /* Write out the modified section contents. */
4650 if (! bfd_set_section_contents (output_bfd
, o
->output_section
,
4651 contents
, o
->output_offset
,
4652 (o
->_cooked_size
!= 0
4658 obj_coff_keep_syms (input_bfd
) = keep_syms
;
4660 if (! finfo
->info
->keep_memory
)
4662 if (! _bfd_coff_free_symbols (input_bfd
))
4672 /* Write out a non-XCOFF global symbol. */
4675 xcoff_write_global_symbol (h
, p
)
4676 struct xcoff_link_hash_entry
*h
;
4679 struct xcoff_final_link_info
*finfo
= (struct xcoff_final_link_info
*) p
;
4682 struct internal_syment isym
;
4683 union internal_auxent aux
;
4685 output_bfd
= finfo
->output_bfd
;
4687 /* If this symbol was garbage collected, just skip it. */
4688 if (xcoff_hash_table (finfo
->info
)->gc
4689 && (h
->flags
& XCOFF_MARK
) == 0)
4692 /* If we need a .loader section entry, write it out. */
4693 if (h
->ldsym
!= NULL
)
4695 struct internal_ldsym
*ldsym
;
4700 if (h
->root
.type
== bfd_link_hash_undefined
4701 || h
->root
.type
== bfd_link_hash_undefweak
)
4704 ldsym
->l_scnum
= N_UNDEF
;
4705 ldsym
->l_smtype
= XTY_ER
;
4706 impbfd
= h
->root
.u
.undef
.abfd
;
4708 else if (h
->root
.type
== bfd_link_hash_defined
4709 || h
->root
.type
== bfd_link_hash_defweak
)
4713 sec
= h
->root
.u
.def
.section
;
4714 ldsym
->l_value
= (sec
->output_section
->vma
4715 + sec
->output_offset
4716 + h
->root
.u
.def
.value
);
4717 ldsym
->l_scnum
= sec
->output_section
->target_index
;
4718 ldsym
->l_smtype
= XTY_SD
;
4719 impbfd
= sec
->owner
;
4724 if (((h
->flags
& XCOFF_DEF_REGULAR
) == 0
4725 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4726 || (h
->flags
& XCOFF_IMPORT
) != 0)
4727 ldsym
->l_smtype
|= L_IMPORT
;
4728 if (((h
->flags
& XCOFF_DEF_REGULAR
) != 0
4729 && (h
->flags
& XCOFF_DEF_DYNAMIC
) != 0)
4730 || (h
->flags
& XCOFF_EXPORT
) != 0)
4731 ldsym
->l_smtype
|= L_EXPORT
;
4732 if ((h
->flags
& XCOFF_ENTRY
) != 0)
4733 ldsym
->l_smtype
|= L_ENTRY
;
4735 ldsym
->l_smclas
= h
->smclas
;
4737 if (ldsym
->l_ifile
== (bfd_size_type
) -1)
4739 else if (ldsym
->l_ifile
== 0)
4741 if ((ldsym
->l_smtype
& L_IMPORT
) == 0)
4743 else if (impbfd
== NULL
)
4747 BFD_ASSERT (impbfd
->xvec
== output_bfd
->xvec
);
4748 ldsym
->l_ifile
= xcoff_data (impbfd
)->import_file_id
;
4754 BFD_ASSERT (h
->ldindx
>= 0);
4755 BFD_ASSERT (LDSYMSZ
== sizeof (struct external_ldsym
));
4756 xcoff_swap_ldsym_out (output_bfd
, ldsym
, finfo
->ldsym
+ h
->ldindx
- 3);
4760 /* If this symbol needs global linkage code, write it out. */
4761 if (h
->root
.type
== bfd_link_hash_defined
4762 && (h
->root
.u
.def
.section
4763 == xcoff_hash_table (finfo
->info
)->linkage_section
))
4769 p
= h
->root
.u
.def
.section
->contents
+ h
->root
.u
.def
.value
;
4771 /* The first instruction in the global linkage code loads a
4772 specific TOC element. */
4773 tocoff
= (h
->descriptor
->toc_section
->output_section
->vma
4774 + h
->descriptor
->toc_section
->output_offset
4775 - xcoff_data (output_bfd
)->toc
);
4776 if ((h
->descriptor
->flags
& XCOFF_SET_TOC
) != 0)
4777 tocoff
+= h
->descriptor
->u
.toc_offset
;
4778 bfd_put_32 (output_bfd
, XCOFF_GLINK_FIRST
| tocoff
, p
);
4780 i
< sizeof xcoff_glink_code
/ sizeof xcoff_glink_code
[0];
4782 bfd_put_32 (output_bfd
, xcoff_glink_code
[i
], p
);
4785 /* If we created a TOC entry for this symbol, write out the required
4787 if ((h
->flags
& XCOFF_SET_TOC
) != 0)
4792 struct internal_reloc
*irel
;
4793 struct internal_ldrel ldrel
;
4795 tocsec
= h
->toc_section
;
4796 osec
= tocsec
->output_section
;
4797 oindx
= osec
->target_index
;
4798 irel
= finfo
->section_info
[oindx
].relocs
+ osec
->reloc_count
;
4799 irel
->r_vaddr
= (osec
->vma
4800 + tocsec
->output_offset
4803 irel
->r_symndx
= h
->indx
;
4807 irel
->r_symndx
= obj_raw_syment_count (output_bfd
);
4809 irel
->r_type
= R_POS
;
4811 finfo
->section_info
[oindx
].rel_hashes
[osec
->reloc_count
] = NULL
;
4812 ++osec
->reloc_count
;
4814 BFD_ASSERT (h
->ldindx
>= 0);
4815 ldrel
.l_vaddr
= irel
->r_vaddr
;
4816 ldrel
.l_symndx
= h
->ldindx
;
4817 ldrel
.l_rtype
= (31 << 8) | R_POS
;
4818 ldrel
.l_rsecnm
= oindx
;
4819 xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
4827 && (finfo
->info
->strip
== strip_all
4828 || (finfo
->info
->strip
== strip_some
4829 && (bfd_hash_lookup (finfo
->info
->keep_hash
,
4830 h
->root
.root
.string
, false, false)
4835 && (h
->flags
& (XCOFF_REF_REGULAR
| XCOFF_DEF_REGULAR
)) == 0)
4838 outsym
= finfo
->outsyms
;
4840 memset (&aux
, 0, sizeof aux
);
4842 h
->indx
= obj_raw_syment_count (output_bfd
);
4844 if (strlen (h
->root
.root
.string
) <= SYMNMLEN
)
4845 strncpy (isym
._n
._n_name
, h
->root
.root
.string
, SYMNMLEN
);
4852 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
4854 indx
= _bfd_stringtab_add (finfo
->strtab
, h
->root
.root
.string
, hash
,
4856 if (indx
== (bfd_size_type
) -1)
4858 isym
._n
._n_n
._n_zeroes
= 0;
4859 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
4862 if (h
->root
.type
== bfd_link_hash_undefined
4863 || h
->root
.type
== bfd_link_hash_undefweak
)
4866 isym
.n_scnum
= N_UNDEF
;
4867 isym
.n_sclass
= C_EXT
;
4868 aux
.x_csect
.x_smtyp
= XTY_ER
;
4870 else if (h
->root
.type
== bfd_link_hash_defined
4871 || h
->root
.type
== bfd_link_hash_defweak
)
4873 struct xcoff_link_size_list
*l
;
4875 isym
.n_value
= (h
->root
.u
.def
.section
->output_section
->vma
4876 + h
->root
.u
.def
.section
->output_offset
4877 + h
->root
.u
.def
.value
);
4878 isym
.n_scnum
= h
->root
.u
.def
.section
->output_section
->target_index
;
4879 isym
.n_sclass
= C_HIDEXT
;
4880 aux
.x_csect
.x_smtyp
= XTY_SD
;
4882 if ((h
->flags
& XCOFF_HAS_SIZE
) != 0)
4884 for (l
= xcoff_hash_table (finfo
->info
)->size_list
;
4890 aux
.x_csect
.x_scnlen
.l
= l
->size
;
4896 else if (h
->root
.type
== bfd_link_hash_common
)
4898 isym
.n_value
= (h
->root
.u
.c
.p
->section
->output_section
->vma
4899 + h
->root
.u
.c
.p
->section
->output_offset
);
4900 isym
.n_scnum
= h
->root
.u
.c
.p
->section
->output_section
->target_index
;
4901 isym
.n_sclass
= C_EXT
;
4902 aux
.x_csect
.x_smtyp
= XTY_CM
;
4903 aux
.x_csect
.x_scnlen
.l
= h
->root
.u
.c
.size
;
4908 isym
.n_type
= T_NULL
;
4911 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
4912 outsym
+= bfd_coff_symesz (output_bfd
);
4914 aux
.x_csect
.x_smclas
= h
->smclas
;
4916 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, T_NULL
, isym
.n_sclass
, 0, 1,
4918 outsym
+= bfd_coff_auxesz (output_bfd
);
4920 if (h
->root
.type
== bfd_link_hash_defined
4921 || h
->root
.type
== bfd_link_hash_defweak
)
4923 /* We just output an SD symbol. Now output an LD symbol. */
4927 isym
.n_sclass
= C_EXT
;
4928 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
4929 outsym
+= bfd_coff_symesz (output_bfd
);
4931 aux
.x_csect
.x_smtyp
= XTY_LD
;
4932 aux
.x_csect
.x_scnlen
.l
= obj_raw_syment_count (output_bfd
);
4934 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &aux
, T_NULL
, C_EXT
, 0, 1,
4936 outsym
+= bfd_coff_auxesz (output_bfd
);
4939 if (bfd_seek (output_bfd
,
4940 (obj_sym_filepos (output_bfd
)
4941 + (obj_raw_syment_count (output_bfd
)
4942 * bfd_coff_symesz (output_bfd
))),
4944 || (bfd_write (finfo
->outsyms
, outsym
- finfo
->outsyms
, 1, output_bfd
)
4945 != (bfd_size_type
) (outsym
- finfo
->outsyms
)))
4947 obj_raw_syment_count (output_bfd
) +=
4948 (outsym
- finfo
->outsyms
) / bfd_coff_symesz (output_bfd
);
4953 /* Handle a link order which is supposed to generate a reloc. */
4956 xcoff_reloc_link_order (output_bfd
, finfo
, output_section
, link_order
)
4958 struct xcoff_final_link_info
*finfo
;
4959 asection
*output_section
;
4960 struct bfd_link_order
*link_order
;
4962 reloc_howto_type
*howto
;
4963 struct xcoff_link_hash_entry
*h
;
4967 struct internal_reloc
*irel
;
4968 struct xcoff_link_hash_entry
**rel_hash_ptr
;
4969 struct internal_ldrel ldrel
;
4971 if (link_order
->type
== bfd_section_reloc_link_order
)
4973 /* We need to somehow locate a symbol in the right section. The
4974 symbol must either have a value of zero, or we must adjust
4975 the addend by the value of the symbol. FIXME: Write this
4976 when we need it. The old linker couldn't handle this anyhow. */
4980 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
4983 bfd_set_error (bfd_error_bad_value
);
4987 h
= xcoff_link_hash_lookup (xcoff_hash_table (finfo
->info
),
4988 link_order
->u
.reloc
.p
->u
.name
,
4989 false, false, true);
4992 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
4993 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
4994 (asection
*) NULL
, (bfd_vma
) 0)))
4999 if (h
->root
.type
== bfd_link_hash_common
)
5001 hsec
= h
->root
.u
.c
.p
->section
;
5004 else if (h
->root
.type
== bfd_link_hash_defined
5005 || h
->root
.type
== bfd_link_hash_defweak
)
5007 hsec
= h
->root
.u
.def
.section
;
5008 hval
= h
->root
.u
.def
.value
;
5016 addend
= link_order
->u
.reloc
.p
->addend
;
5018 addend
+= (hsec
->output_section
->vma
5019 + hsec
->output_offset
5026 bfd_reloc_status_type rstat
;
5029 size
= bfd_get_reloc_size (howto
);
5030 buf
= (bfd_byte
*) bfd_zmalloc (size
);
5033 bfd_set_error (bfd_error_no_memory
);
5037 rstat
= _bfd_relocate_contents (howto
, output_bfd
, addend
, buf
);
5043 case bfd_reloc_outofrange
:
5045 case bfd_reloc_overflow
:
5046 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
5047 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
,
5048 howto
->name
, addend
, (bfd
*) NULL
, (asection
*) NULL
,
5056 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
5057 (file_ptr
) link_order
->offset
, size
);
5063 /* Store the reloc information in the right place. It will get
5064 swapped and written out at the end of the final_link routine. */
5066 irel
= (finfo
->section_info
[output_section
->target_index
].relocs
5067 + output_section
->reloc_count
);
5068 rel_hash_ptr
= (finfo
->section_info
[output_section
->target_index
].rel_hashes
5069 + output_section
->reloc_count
);
5071 memset (irel
, 0, sizeof (struct internal_reloc
));
5072 *rel_hash_ptr
= NULL
;
5074 irel
->r_vaddr
= output_section
->vma
+ link_order
->offset
;
5077 irel
->r_symndx
= h
->indx
;
5080 /* Set the index to -2 to force this symbol to get written out. */
5086 irel
->r_type
= howto
->type
;
5087 irel
->r_size
= howto
->bitsize
- 1;
5088 if (howto
->complain_on_overflow
== complain_overflow_signed
)
5089 irel
->r_size
|= 0x80;
5091 ++output_section
->reloc_count
;
5093 /* Now output the reloc to the .loader section. */
5095 ldrel
.l_vaddr
= irel
->r_vaddr
;
5099 const char *secname
;
5101 secname
= hsec
->output_section
->name
;
5103 if (strcmp (secname
, ".text") == 0)
5105 else if (strcmp (secname
, ".data") == 0)
5107 else if (strcmp (secname
, ".bss") == 0)
5111 (*_bfd_error_handler
)
5112 ("%s: loader reloc in unrecognized section `%s'",
5113 bfd_get_filename (output_bfd
), secname
);
5114 bfd_set_error (bfd_error_nonrepresentable_section
);
5122 (*_bfd_error_handler
)
5123 ("%s: `%s' in loader reloc but not loader sym",
5124 bfd_get_filename (output_bfd
),
5125 h
->root
.root
.string
);
5126 bfd_set_error (bfd_error_bad_value
);
5129 ldrel
.l_symndx
= h
->ldindx
;
5132 ldrel
.l_rtype
= (irel
->r_size
<< 8) | irel
->r_type
;
5133 ldrel
.l_rsecnm
= output_section
->target_index
;
5134 xcoff_swap_ldrel_out (output_bfd
, &ldrel
, finfo
->ldrel
);
5140 /* Sort relocs by VMA. This is called via qsort. */
5143 xcoff_sort_relocs (p1
, p2
)
5147 const struct internal_reloc
*r1
= (const struct internal_reloc
*) p1
;
5148 const struct internal_reloc
*r2
= (const struct internal_reloc
*) p2
;
5150 if (r1
->r_vaddr
> r2
->r_vaddr
)
5152 else if (r1
->r_vaddr
< r2
->r_vaddr
)
5158 /* This is the relocation function for the RS/6000/POWER/PowerPC.
5159 This is currently the only processor which uses XCOFF; I hope that
5160 will never change. */
5163 _bfd_ppc_xcoff_relocate_section (output_bfd
, info
, input_bfd
,
5164 input_section
, contents
, relocs
, syms
,
5167 struct bfd_link_info
*info
;
5169 asection
*input_section
;
5171 struct internal_reloc
*relocs
;
5172 struct internal_syment
*syms
;
5173 asection
**sections
;
5175 struct internal_reloc
*rel
;
5176 struct internal_reloc
*relend
;
5179 relend
= rel
+ input_section
->reloc_count
;
5180 for (; rel
< relend
; rel
++)
5183 struct xcoff_link_hash_entry
*h
;
5184 struct internal_syment
*sym
;
5187 struct reloc_howto_struct howto
;
5188 bfd_reloc_status_type rstat
;
5190 /* Relocation type R_REF is a special relocation type which is
5191 merely used to prevent garbage collection from occurring for
5192 the csect including the symbol which it references. */
5193 if (rel
->r_type
== R_REF
)
5196 symndx
= rel
->r_symndx
;
5206 h
= obj_xcoff_sym_hashes (input_bfd
)[symndx
];
5207 sym
= syms
+ symndx
;
5208 addend
= - sym
->n_value
;
5211 /* We build the howto information on the fly. */
5213 howto
.type
= rel
->r_type
;
5214 howto
.rightshift
= 0;
5216 howto
.bitsize
= (rel
->r_size
& 0x1f) + 1;
5217 howto
.pc_relative
= false;
5219 if ((rel
->r_size
& 0x80) != 0)
5220 howto
.complain_on_overflow
= complain_overflow_signed
;
5222 howto
.complain_on_overflow
= complain_overflow_bitfield
;
5223 howto
.special_function
= NULL
;
5224 howto
.name
= "internal";
5225 howto
.partial_inplace
= true;
5226 if (howto
.bitsize
== 32)
5227 howto
.src_mask
= howto
.dst_mask
= 0xffffffff;
5230 howto
.src_mask
= howto
.dst_mask
= (1 << howto
.bitsize
) - 1;
5231 if (howto
.bitsize
== 16)
5234 howto
.pcrel_offset
= false;
5244 sec
= bfd_abs_section_ptr
;
5249 sec
= sections
[symndx
];
5250 val
= (sec
->output_section
->vma
5251 + sec
->output_offset
5258 if (h
->root
.type
== bfd_link_hash_defined
5259 || h
->root
.type
== bfd_link_hash_defweak
)
5263 sec
= h
->root
.u
.def
.section
;
5264 val
= (h
->root
.u
.def
.value
5265 + sec
->output_section
->vma
5266 + sec
->output_offset
);
5268 else if (h
->root
.type
== bfd_link_hash_common
)
5272 sec
= h
->root
.u
.c
.p
->section
;
5273 val
= (sec
->output_section
->vma
5274 + sec
->output_offset
);
5276 else if ((h
->flags
& XCOFF_DEF_DYNAMIC
) != 0
5277 || (h
->flags
& XCOFF_IMPORT
) != 0)
5279 /* Every symbol in a shared object is defined somewhere. */
5282 else if (! info
->relocateable
5285 if (! ((*info
->callbacks
->undefined_symbol
)
5286 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
5287 rel
->r_vaddr
- input_section
->vma
)))
5292 /* I took the relocation type definitions from two documents:
5293 the PowerPC AIX Version 4 Application Binary Interface, First
5294 Edition (April 1992), and the PowerOpen ABI, Big-Endian
5295 32-Bit Hardware Implementation (June 30, 1994). Differences
5296 between the documents are noted below. */
5298 switch (rel
->r_type
)
5303 /* These relocs are defined by the PowerPC ABI to be
5304 relative branches which use half of the difference
5305 between the symbol and the program counter. I can't
5306 quite figure out when this is useful. These relocs are
5307 not defined by the PowerOpen ABI. */
5309 (*_bfd_error_handler
)
5310 ("%s: unsupported relocation type 0x%02x",
5311 bfd_get_filename (input_bfd
), (unsigned int) rel
->r_type
);
5312 bfd_set_error (bfd_error_bad_value
);
5315 /* Simple positive relocation. */
5318 /* Simple negative relocation. */
5322 /* Simple PC relative relocation. */
5323 howto
.pc_relative
= true;
5326 /* TOC relative relocation. The value in the instruction in
5327 the input file is the offset from the input file TOC to
5328 the desired location. We want the offset from the final
5329 TOC to the desired location. We have:
5334 so we must change insn by on - in.
5337 /* Global linkage relocation. The value of this relocation
5338 is the address of the entry in the TOC section. */
5340 /* Local object TOC address. I can't figure out the
5341 difference between this and case R_GL. */
5343 /* TOC relative relocation. A TOC relative load instruction
5344 which may be changed to a load address instruction.
5345 FIXME: We don't currently implement this optimization. */
5347 /* TOC relative relocation. This is a TOC relative load
5348 address instruction which may be changed to a load
5349 instruction. FIXME: I don't know if this is the correct
5351 if (h
!= NULL
&& h
->toc_section
== NULL
)
5353 (*_bfd_error_handler
)
5354 ("%s: TOC reloc at 0x%x to symbol `%s' with no TOC entry",
5355 bfd_get_filename (input_bfd
), rel
->r_vaddr
,
5356 h
->root
.root
.string
);
5357 bfd_set_error (bfd_error_bad_value
);
5362 BFD_ASSERT ((h
->flags
& XCOFF_SET_TOC
) == 0);
5363 val
= (h
->toc_section
->output_section
->vma
5364 + h
->toc_section
->output_offset
);
5366 val
= ((val
- xcoff_data (output_bfd
)->toc
)
5367 - (sym
->n_value
- xcoff_data (input_bfd
)->toc
));
5371 /* Absolute branch. We don't want to mess with the lower
5372 two bits of the instruction. */
5374 /* The PowerPC ABI defines this as an absolute call which
5375 may be modified to become a relative call. The PowerOpen
5376 ABI does not define this relocation type. */
5378 /* Absolute branch which may be modified to become a
5381 /* The PowerPC ABI defines this as an absolute branch to a
5382 fixed address which may be modified to an absolute branch
5383 to a symbol. The PowerOpen ABI does not define this
5386 /* The PowerPC ABI defines this as an absolute branch to a
5387 fixed address which may be modified to a relative branch.
5388 The PowerOpen ABI does not define this relocation type. */
5389 howto
.src_mask
&= ~3;
5390 howto
.dst_mask
= howto
.src_mask
;
5393 /* Relative branch. We don't want to mess with the lower
5394 two bits of the instruction. */
5396 /* The PowerPC ABI defines this as a relative call which may
5397 be modified to become an absolute call. The PowerOpen
5398 ABI does not define this relocation type. */
5400 /* A relative branch which may be modified to become an
5401 absolute branch. FIXME: We don't implement this,
5402 although we should for symbols of storage mapping class
5404 howto
.pc_relative
= true;
5405 howto
.src_mask
&= ~3;
5406 howto
.dst_mask
= howto
.src_mask
;
5409 /* The PowerPC AIX ABI describes this as a load which may be
5410 changed to a load address. The PowerOpen ABI says this
5411 is the same as case R_POS. */
5414 /* The PowerPC AIX ABI describes this as a load address
5415 which may be changed to a load. The PowerOpen ABI says
5416 this is the same as R_POS. */
5420 /* If we see an R_BR or R_RBR reloc which is jumping to global
5421 linkage code, and it is followed by an appropriate cror nop
5422 instruction, we replace the cror with lwz r2,20(r1). This
5423 restores the TOC after the glink code. Contrariwise, if the
5424 call is followed by a lwz r2,20(r1), but the call is not
5425 going to global linkage code, we can replace the load with a
5427 if ((rel
->r_type
== R_BR
|| rel
->r_type
== R_RBR
)
5429 && h
->root
.type
== bfd_link_hash_defined
5430 && (rel
->r_vaddr
- input_section
->vma
+ 8
5431 <= input_section
->_cooked_size
))
5436 pnext
= contents
+ (rel
->r_vaddr
- input_section
->vma
) + 4;
5437 next
= bfd_get_32 (input_bfd
, pnext
);
5438 if (h
->smclas
== XMC_GL
)
5440 if (next
== 0x4def7b82 /* cror 15,15,15 */
5441 || next
== 0x4ffffb82) /* cror 31,31,31 */
5442 bfd_put_32 (input_bfd
, 0x80410014, pnext
); /* lwz r1,20(r1) */
5446 if (next
== 0x80410014) /* lwz r1,20(r1) */
5447 bfd_put_32 (input_bfd
, 0x4ffffb82, pnext
); /* cror 31,31,31 */
5451 /* A PC relative reloc includes the section address. */
5452 if (howto
.pc_relative
)
5453 addend
+= input_section
->vma
;
5455 rstat
= _bfd_final_link_relocate (&howto
, input_bfd
, input_section
,
5457 rel
->r_vaddr
- input_section
->vma
,
5466 case bfd_reloc_overflow
:
5469 char buf
[SYMNMLEN
+ 1];
5470 char howto_name
[10];
5475 name
= h
->root
.root
.string
;
5478 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
5482 sprintf (howto_name
, "0x%02x", rel
->r_type
);
5484 if (! ((*info
->callbacks
->reloc_overflow
)
5485 (info
, name
, howto_name
, (bfd_vma
) 0, input_bfd
,
5486 input_section
, rel
->r_vaddr
- input_section
->vma
)))