1 /* COFF specific linker code.
2 Copyright 1994, 1995 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor, 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. */
21 /* This file contains the COFF backend linker code. */
27 #include "coff/internal.h"
30 #define STRING_SIZE_SIZE (4)
32 /* We use a hash table to merge identical enum, struct, and union
33 definitions in the linker. */
35 /* Information we keep for a single element (an enum value, a
36 structure or union field) in the debug merge hash table. */
38 struct coff_debug_merge_element
41 struct coff_debug_merge_element
*next
;
49 /* Symbol index for complex type. */
53 /* A linked list of debug merge entries for a given name. */
55 struct coff_debug_merge_type
57 /* Next type with the same name. */
58 struct coff_debug_merge_type
*next
;
63 /* Symbol index where this type is defined. */
66 /* List of elements. */
67 struct coff_debug_merge_element
*elements
;
70 /* Information we store in the debug merge hash table. */
72 struct coff_debug_merge_hash_entry
74 struct bfd_hash_entry root
;
76 /* A list of types with this name. */
77 struct coff_debug_merge_type
*types
;
80 /* The debug merge hash table. */
82 struct coff_debug_merge_hash_table
84 struct bfd_hash_table root
;
87 /* Initialize a COFF debug merge hash table. */
89 #define coff_debug_merge_hash_table_init(table) \
90 (bfd_hash_table_init (&(table)->root, coff_debug_merge_hash_newfunc))
92 /* Free a COFF debug merge hash table. */
94 #define coff_debug_merge_hash_table_free(table) \
95 (bfd_hash_table_free (&(table)->root))
97 /* Look up an entry in a COFF debug merge hash table. */
99 #define coff_debug_merge_hash_lookup(table, string, create, copy) \
100 ((struct coff_debug_merge_hash_entry *) \
101 bfd_hash_lookup (&(table)->root, (string), (create), (copy)))
103 /* Information we keep for each section in the output file when doing
104 a relocateable link. */
106 struct coff_link_section_info
108 /* The relocs to be output. */
109 struct internal_reloc
*relocs
;
110 /* For each reloc against a global symbol whose index was not known
111 when the reloc was handled, the global hash table entry. */
112 struct coff_link_hash_entry
**rel_hashes
;
115 /* Information that we pass around while doing the final link step. */
117 struct coff_final_link_info
119 /* General link information. */
120 struct bfd_link_info
*info
;
123 /* Used to indicate failure in traversal routine. */
125 /* Hash table for long symbol names. */
126 struct bfd_strtab_hash
*strtab
;
127 /* When doing a relocateable link, an array of information kept for
128 each output section, indexed by the target_index field. */
129 struct coff_link_section_info
*section_info
;
130 /* Symbol index of last C_FILE symbol (-1 if none). */
131 long last_file_index
;
132 /* Contents of last C_FILE symbol. */
133 struct internal_syment last_file
;
134 /* Hash table used to merge debug information. */
135 struct coff_debug_merge_hash_table debug_merge
;
136 /* Buffer large enough to hold swapped symbols of any input file. */
137 struct internal_syment
*internal_syms
;
138 /* Buffer large enough to hold sections of symbols of any input file. */
140 /* Buffer large enough to hold output indices of symbols of any
143 /* Buffer large enough to hold output symbols for any input file. */
145 /* Buffer large enough to hold external line numbers for any input
148 /* Buffer large enough to hold any input section. */
150 /* Buffer large enough to hold external relocs of any input section. */
151 bfd_byte
*external_relocs
;
152 /* Buffer large enough to hold swapped relocs of any input section. */
153 struct internal_reloc
*internal_relocs
;
156 static struct bfd_hash_entry
*coff_debug_merge_hash_newfunc
157 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
158 static boolean coff_link_add_object_symbols
159 PARAMS ((bfd
*, struct bfd_link_info
*));
160 static boolean coff_link_check_archive_element
161 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
162 static boolean coff_link_check_ar_symbols
163 PARAMS ((bfd
*, struct bfd_link_info
*, boolean
*));
164 static boolean coff_link_add_symbols
PARAMS ((bfd
*, struct bfd_link_info
*));
165 static boolean coff_link_input_bfd
166 PARAMS ((struct coff_final_link_info
*, bfd
*));
167 static boolean coff_write_global_sym
168 PARAMS ((struct coff_link_hash_entry
*, PTR
));
169 static boolean coff_reloc_link_order
170 PARAMS ((bfd
*, struct coff_final_link_info
*, asection
*,
171 struct bfd_link_order
*));
173 /* Create an entry in a COFF linker hash table. */
175 struct bfd_hash_entry
*
176 _bfd_coff_link_hash_newfunc (entry
, table
, string
)
177 struct bfd_hash_entry
*entry
;
178 struct bfd_hash_table
*table
;
181 struct coff_link_hash_entry
*ret
= (struct coff_link_hash_entry
*) entry
;
183 /* Allocate the structure if it has not already been allocated by a
185 if (ret
== (struct coff_link_hash_entry
*) NULL
)
186 ret
= ((struct coff_link_hash_entry
*)
187 bfd_hash_allocate (table
, sizeof (struct coff_link_hash_entry
)));
188 if (ret
== (struct coff_link_hash_entry
*) NULL
)
190 bfd_set_error (bfd_error_no_memory
);
191 return (struct bfd_hash_entry
*) ret
;
194 /* Call the allocation method of the superclass. */
195 ret
= ((struct coff_link_hash_entry
*)
196 _bfd_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
198 if (ret
!= (struct coff_link_hash_entry
*) NULL
)
200 /* Set local fields. */
209 return (struct bfd_hash_entry
*) ret
;
212 /* Initialize a COFF linker hash table. */
215 _bfd_coff_link_hash_table_init (table
, abfd
, newfunc
)
216 struct coff_link_hash_table
*table
;
218 struct bfd_hash_entry
*(*newfunc
) PARAMS ((struct bfd_hash_entry
*,
219 struct bfd_hash_table
*,
222 return _bfd_link_hash_table_init (&table
->root
, abfd
, newfunc
);
225 /* Create a COFF linker hash table. */
227 struct bfd_link_hash_table
*
228 _bfd_coff_link_hash_table_create (abfd
)
231 struct coff_link_hash_table
*ret
;
233 ret
= ((struct coff_link_hash_table
*)
234 bfd_alloc (abfd
, sizeof (struct coff_link_hash_table
)));
237 bfd_set_error (bfd_error_no_memory
);
240 if (! _bfd_coff_link_hash_table_init (ret
, abfd
,
241 _bfd_coff_link_hash_newfunc
))
243 bfd_release (abfd
, ret
);
244 return (struct bfd_link_hash_table
*) NULL
;
249 /* Create an entry in a COFF debug merge hash table. */
251 static struct bfd_hash_entry
*
252 coff_debug_merge_hash_newfunc (entry
, table
, string
)
253 struct bfd_hash_entry
*entry
;
254 struct bfd_hash_table
*table
;
257 struct coff_debug_merge_hash_entry
*ret
=
258 (struct coff_debug_merge_hash_entry
*) entry
;
260 /* Allocate the structure if it has not already been allocated by a
262 if (ret
== (struct coff_debug_merge_hash_entry
*) NULL
)
263 ret
= ((struct coff_debug_merge_hash_entry
*)
264 bfd_hash_allocate (table
,
265 sizeof (struct coff_debug_merge_hash_entry
)));
266 if (ret
== (struct coff_debug_merge_hash_entry
*) NULL
)
268 bfd_set_error (bfd_error_no_memory
);
269 return (struct bfd_hash_entry
*) ret
;
272 /* Call the allocation method of the superclass. */
273 ret
= ((struct coff_debug_merge_hash_entry
*)
274 bfd_hash_newfunc ((struct bfd_hash_entry
*) ret
, table
, string
));
275 if (ret
!= (struct coff_debug_merge_hash_entry
*) NULL
)
277 /* Set local fields. */
281 return (struct bfd_hash_entry
*) ret
;
284 /* Given a COFF BFD, add symbols to the global hash table as
288 _bfd_coff_link_add_symbols (abfd
, info
)
290 struct bfd_link_info
*info
;
292 switch (bfd_get_format (abfd
))
295 return coff_link_add_object_symbols (abfd
, info
);
297 return (_bfd_generic_link_add_archive_symbols
298 (abfd
, info
, coff_link_check_archive_element
));
300 bfd_set_error (bfd_error_wrong_format
);
305 /* Add symbols from a COFF object file. */
308 coff_link_add_object_symbols (abfd
, info
)
310 struct bfd_link_info
*info
;
312 if (! _bfd_coff_get_external_symbols (abfd
))
314 if (! coff_link_add_symbols (abfd
, info
))
316 if (! info
->keep_memory
)
318 if (! _bfd_coff_free_symbols (abfd
))
324 /* Check a single archive element to see if we need to include it in
325 the link. *PNEEDED is set according to whether this element is
326 needed in the link or not. This is called via
327 _bfd_generic_link_add_archive_symbols. */
330 coff_link_check_archive_element (abfd
, info
, pneeded
)
332 struct bfd_link_info
*info
;
335 if (! _bfd_coff_get_external_symbols (abfd
))
338 if (! coff_link_check_ar_symbols (abfd
, info
, pneeded
))
343 if (! coff_link_add_symbols (abfd
, info
))
347 if (! info
->keep_memory
|| ! *pneeded
)
349 if (! _bfd_coff_free_symbols (abfd
))
356 /* Get the name of a symbol. The caller must pass in a buffer of size
360 _bfd_coff_internal_syment_name (abfd
, sym
, buf
)
362 const struct internal_syment
*sym
;
365 /* FIXME: It's not clear this will work correctly if sizeof
367 if (sym
->_n
._n_n
._n_zeroes
!= 0
368 || sym
->_n
._n_n
._n_offset
== 0)
370 memcpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
371 buf
[SYMNMLEN
] = '\0';
378 BFD_ASSERT (sym
->_n
._n_n
._n_offset
>= STRING_SIZE_SIZE
);
379 strings
= obj_coff_strings (abfd
);
382 strings
= _bfd_coff_read_string_table (abfd
);
386 return strings
+ sym
->_n
._n_n
._n_offset
;
390 /* Look through the symbols to see if this object file should be
391 included in the link. */
394 coff_link_check_ar_symbols (abfd
, info
, pneeded
)
396 struct bfd_link_info
*info
;
399 boolean (*sym_is_global
) PARAMS ((bfd
*, struct internal_syment
*));
400 bfd_size_type symesz
;
406 sym_is_global
= coff_backend_info (abfd
)->_bfd_coff_sym_is_global
;
408 symesz
= bfd_coff_symesz (abfd
);
409 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
410 esym_end
= esym
+ obj_raw_syment_count (abfd
) * symesz
;
411 while (esym
< esym_end
)
413 struct internal_syment sym
;
415 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
417 if ((sym
.n_sclass
== C_EXT
418 || (sym_is_global
&& (*sym_is_global
) (abfd
, &sym
)))
419 && (sym
.n_scnum
!= 0 || sym
.n_value
!= 0))
422 char buf
[SYMNMLEN
+ 1];
423 struct bfd_link_hash_entry
*h
;
425 /* This symbol is externally visible, and is defined by this
428 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
431 h
= bfd_link_hash_lookup (info
->hash
, name
, false, false, true);
433 /* We are only interested in symbols that are currently
434 undefined. If a symbol is currently known to be common,
435 COFF linkers do not bring in an object file which defines
437 if (h
!= (struct bfd_link_hash_entry
*) NULL
438 && h
->type
== bfd_link_hash_undefined
)
440 if (! (*info
->callbacks
->add_archive_element
) (info
, abfd
, name
))
447 esym
+= (sym
.n_numaux
+ 1) * symesz
;
450 /* We do not need this object file. */
454 /* Add all the symbols from an object file to the hash table. */
457 coff_link_add_symbols (abfd
, info
)
459 struct bfd_link_info
*info
;
461 boolean (*sym_is_global
) PARAMS ((bfd
*, struct internal_syment
*));
462 boolean default_copy
;
463 bfd_size_type symcount
;
464 struct coff_link_hash_entry
**sym_hash
;
465 bfd_size_type symesz
;
469 sym_is_global
= coff_backend_info (abfd
)->_bfd_coff_sym_is_global
;
471 if (info
->keep_memory
)
472 default_copy
= false;
476 symcount
= obj_raw_syment_count (abfd
);
478 /* We keep a list of the linker hash table entries that correspond
479 to particular symbols. */
480 sym_hash
= ((struct coff_link_hash_entry
**)
483 * sizeof (struct coff_link_hash_entry
*))));
484 if (sym_hash
== NULL
&& symcount
!= 0)
486 bfd_set_error (bfd_error_no_memory
);
489 obj_coff_sym_hashes (abfd
) = sym_hash
;
491 (size_t) symcount
* sizeof (struct coff_link_hash_entry
*));
493 symesz
= bfd_coff_symesz (abfd
);
494 BFD_ASSERT (symesz
== bfd_coff_auxesz (abfd
));
495 esym
= (bfd_byte
*) obj_coff_external_syms (abfd
);
496 esym_end
= esym
+ symcount
* symesz
;
497 while (esym
< esym_end
)
499 struct internal_syment sym
;
502 bfd_coff_swap_sym_in (abfd
, (PTR
) esym
, (PTR
) &sym
);
504 if (sym
.n_sclass
== C_EXT
505 || (sym_is_global
&& (*sym_is_global
) (abfd
, &sym
)))
508 char buf
[SYMNMLEN
+ 1];
513 /* This symbol is externally visible. */
515 name
= _bfd_coff_internal_syment_name (abfd
, &sym
, buf
);
519 /* We must copy the name into memory if we got it from the
520 syment itself, rather than the string table. */
522 if (sym
._n
._n_n
._n_zeroes
!= 0
523 || sym
._n
._n_n
._n_offset
== 0)
528 if (sym
.n_scnum
== 0)
533 section
= bfd_und_section_ptr
;
538 section
= bfd_com_section_ptr
;
543 flags
= BSF_EXPORT
| BSF_GLOBAL
;
544 section
= coff_section_from_bfd_index (abfd
, sym
.n_scnum
);
545 value
-= section
->vma
;
548 if (! (_bfd_generic_link_add_one_symbol
549 (info
, abfd
, name
, flags
, section
, value
,
550 (const char *) NULL
, copy
, false,
551 (struct bfd_link_hash_entry
**) sym_hash
)))
554 if (info
->hash
->creator
->flavour
== bfd_get_flavour (abfd
))
556 if (((*sym_hash
)->class == C_NULL
557 && (*sym_hash
)->type
== T_NULL
)
560 && (*sym_hash
)->root
.type
!= bfd_link_hash_defined
))
562 (*sym_hash
)->class = sym
.n_sclass
;
563 (*sym_hash
)->type
= sym
.n_type
;
564 (*sym_hash
)->numaux
= sym
.n_numaux
;
565 (*sym_hash
)->auxbfd
= abfd
;
566 if (sym
.n_numaux
!= 0)
568 union internal_auxent
*alloc
;
571 union internal_auxent
*iaux
;
573 alloc
= ((union internal_auxent
*)
574 bfd_hash_allocate (&info
->hash
->table
,
576 * sizeof (*alloc
))));
579 bfd_set_error (bfd_error_no_memory
);
582 for (i
= 0, eaux
= esym
+ symesz
, iaux
= alloc
;
584 i
++, eaux
+= symesz
, iaux
++)
585 bfd_coff_swap_aux_in (abfd
, (PTR
) eaux
, sym
.n_type
,
586 sym
.n_sclass
, i
, sym
.n_numaux
,
588 (*sym_hash
)->aux
= alloc
;
594 esym
+= (sym
.n_numaux
+ 1) * symesz
;
595 sym_hash
+= sym
.n_numaux
+ 1;
601 /* Do the final link step. */
604 _bfd_coff_final_link (abfd
, info
)
606 struct bfd_link_info
*info
;
608 bfd_size_type symesz
;
609 struct coff_final_link_info finfo
;
610 boolean debug_merge_allocated
;
612 struct bfd_link_order
*p
;
613 size_t max_contents_size
;
614 size_t max_sym_count
;
615 size_t max_lineno_count
;
616 size_t max_reloc_count
;
617 size_t max_output_reloc_count
;
618 file_ptr rel_filepos
;
620 file_ptr line_filepos
;
623 bfd_byte
*external_relocs
= NULL
;
624 char strbuf
[STRING_SIZE_SIZE
];
626 symesz
= bfd_coff_symesz (abfd
);
629 finfo
.output_bfd
= abfd
;
631 finfo
.section_info
= NULL
;
632 finfo
.last_file_index
= -1;
633 finfo
.internal_syms
= NULL
;
634 finfo
.sec_ptrs
= NULL
;
635 finfo
.sym_indices
= NULL
;
636 finfo
.outsyms
= NULL
;
637 finfo
.linenos
= NULL
;
638 finfo
.contents
= NULL
;
639 finfo
.external_relocs
= NULL
;
640 finfo
.internal_relocs
= NULL
;
641 debug_merge_allocated
= false;
643 coff_data (abfd
)->link_info
= info
;
645 finfo
.strtab
= _bfd_stringtab_init ();
646 if (finfo
.strtab
== NULL
)
649 if (! coff_debug_merge_hash_table_init (&finfo
.debug_merge
))
651 debug_merge_allocated
= true;
653 /* Compute the file positions for all the sections. */
654 if (! abfd
->output_has_begun
)
655 bfd_coff_compute_section_file_positions (abfd
);
657 /* Count the line numbers and relocation entries required for the
658 output file. Set the file positions for the relocs. */
659 rel_filepos
= obj_relocbase (abfd
);
660 relsz
= bfd_coff_relsz (abfd
);
661 max_contents_size
= 0;
662 max_lineno_count
= 0;
664 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
668 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
670 if (p
->type
== bfd_indirect_link_order
)
674 sec
= p
->u
.indirect
.section
;
676 if (info
->strip
== strip_none
677 || info
->strip
== strip_some
)
678 o
->lineno_count
+= sec
->lineno_count
;
680 if (info
->relocateable
)
681 o
->reloc_count
+= sec
->reloc_count
;
683 if (sec
->_raw_size
> max_contents_size
)
684 max_contents_size
= sec
->_raw_size
;
685 if (sec
->lineno_count
> max_lineno_count
)
686 max_lineno_count
= sec
->lineno_count
;
687 if (sec
->reloc_count
> max_reloc_count
)
688 max_reloc_count
= sec
->reloc_count
;
690 else if (info
->relocateable
691 && (p
->type
== bfd_section_reloc_link_order
692 || p
->type
== bfd_symbol_reloc_link_order
))
695 if (o
->reloc_count
== 0)
699 o
->flags
|= SEC_RELOC
;
700 o
->rel_filepos
= rel_filepos
;
701 rel_filepos
+= o
->reloc_count
* relsz
;
705 /* If doing a relocateable link, allocate space for the pointers we
707 if (info
->relocateable
)
711 /* We use section_count + 1, rather than section_count, because
712 the target_index fields are 1 based. */
713 finfo
.section_info
= ((struct coff_link_section_info
*)
714 malloc ((abfd
->section_count
+ 1)
715 * sizeof (struct coff_link_section_info
)));
716 if (finfo
.section_info
== NULL
)
718 bfd_set_error (bfd_error_no_memory
);
721 for (i
= 0; i
<= abfd
->section_count
; i
++)
723 finfo
.section_info
[i
].relocs
= NULL
;
724 finfo
.section_info
[i
].rel_hashes
= NULL
;
728 /* We now know the size of the relocs, so we can determine the file
729 positions of the line numbers. */
730 line_filepos
= rel_filepos
;
731 linesz
= bfd_coff_linesz (abfd
);
732 max_output_reloc_count
= 0;
733 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
735 if (o
->lineno_count
== 0)
739 o
->line_filepos
= line_filepos
;
740 line_filepos
+= o
->lineno_count
* linesz
;
743 if (o
->reloc_count
!= 0)
745 /* We don't know the indices of global symbols until we have
746 written out all the local symbols. For each section in
747 the output file, we keep an array of pointers to hash
748 table entries. Each entry in the array corresponds to a
749 reloc. When we find a reloc against a global symbol, we
750 set the corresponding entry in this array so that we can
751 fix up the symbol index after we have written out all the
754 Because of this problem, we also keep the relocs in
755 memory until the end of the link. This wastes memory,
756 but only when doing a relocateable link, which is not the
758 BFD_ASSERT (info
->relocateable
);
759 finfo
.section_info
[o
->target_index
].relocs
=
760 ((struct internal_reloc
*)
761 malloc (o
->reloc_count
* sizeof (struct internal_reloc
)));
762 finfo
.section_info
[o
->target_index
].rel_hashes
=
763 ((struct coff_link_hash_entry
**)
764 malloc (o
->reloc_count
765 * sizeof (struct coff_link_hash_entry
*)));
766 if (finfo
.section_info
[o
->target_index
].relocs
== NULL
767 || finfo
.section_info
[o
->target_index
].rel_hashes
== NULL
)
769 bfd_set_error (bfd_error_no_memory
);
773 if (o
->reloc_count
> max_output_reloc_count
)
774 max_output_reloc_count
= o
->reloc_count
;
777 /* Reset the reloc and lineno counts, so that we can use them to
778 count the number of entries we have output so far. */
783 obj_sym_filepos (abfd
) = line_filepos
;
785 /* Figure out the largest number of symbols in an input BFD. Take
786 the opportunity to clear the output_has_begun fields of all the
789 for (sub
= info
->input_bfds
; sub
!= NULL
; sub
= sub
->link_next
)
793 sub
->output_has_begun
= false;
794 sz
= obj_raw_syment_count (sub
);
795 if (sz
> max_sym_count
)
799 /* Allocate some buffers used while linking. */
800 finfo
.internal_syms
= ((struct internal_syment
*)
801 malloc (max_sym_count
802 * sizeof (struct internal_syment
)));
803 finfo
.sec_ptrs
= (asection
**) malloc (max_sym_count
* sizeof (asection
*));
804 finfo
.sym_indices
= (long *) malloc (max_sym_count
* sizeof (long));
805 finfo
.outsyms
= ((bfd_byte
*)
806 malloc ((size_t) ((max_sym_count
+ 1) * symesz
)));
807 finfo
.linenos
= (bfd_byte
*) malloc (max_lineno_count
808 * bfd_coff_linesz (abfd
));
809 finfo
.contents
= (bfd_byte
*) malloc (max_contents_size
);
810 finfo
.external_relocs
= (bfd_byte
*) malloc (max_reloc_count
* relsz
);
811 if (! info
->relocateable
)
812 finfo
.internal_relocs
= ((struct internal_reloc
*)
813 malloc (max_reloc_count
814 * sizeof (struct internal_reloc
)));
815 if ((finfo
.internal_syms
== NULL
&& max_sym_count
> 0)
816 || (finfo
.sec_ptrs
== NULL
&& max_sym_count
> 0)
817 || (finfo
.sym_indices
== NULL
&& max_sym_count
> 0)
818 || finfo
.outsyms
== NULL
819 || (finfo
.linenos
== NULL
&& max_lineno_count
> 0)
820 || (finfo
.contents
== NULL
&& max_contents_size
> 0)
821 || (finfo
.external_relocs
== NULL
&& max_reloc_count
> 0)
822 || (! info
->relocateable
823 && finfo
.internal_relocs
== NULL
824 && max_reloc_count
> 0))
826 bfd_set_error (bfd_error_no_memory
);
830 /* We now know the position of everything in the file, except that
831 we don't know the size of the symbol table and therefore we don't
832 know where the string table starts. We just build the string
833 table in memory as we go along. We process all the relocations
834 for a single input file at once. */
835 obj_raw_syment_count (abfd
) = 0;
837 if (coff_backend_info (abfd
)->_bfd_coff_start_final_link
)
839 if (! bfd_coff_start_final_link (abfd
, info
))
843 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
845 for (p
= o
->link_order_head
; p
!= NULL
; p
= p
->next
)
847 if (p
->type
== bfd_indirect_link_order
848 && (bfd_get_flavour (p
->u
.indirect
.section
->owner
)
849 == bfd_target_coff_flavour
))
851 sub
= p
->u
.indirect
.section
->owner
;
852 if (! sub
->output_has_begun
)
854 if (! coff_link_input_bfd (&finfo
, sub
))
856 sub
->output_has_begun
= true;
859 else if (p
->type
== bfd_section_reloc_link_order
860 || p
->type
== bfd_symbol_reloc_link_order
)
862 if (! coff_reloc_link_order (abfd
, &finfo
, o
, p
))
867 if (! _bfd_default_link_order (abfd
, info
, o
, p
))
873 /* Free up the buffers used by coff_link_input_bfd. */
875 coff_debug_merge_hash_table_free (&finfo
.debug_merge
);
876 debug_merge_allocated
= false;
878 if (finfo
.internal_syms
!= NULL
)
880 free (finfo
.internal_syms
);
881 finfo
.internal_syms
= NULL
;
883 if (finfo
.sec_ptrs
!= NULL
)
885 free (finfo
.sec_ptrs
);
886 finfo
.sec_ptrs
= NULL
;
888 if (finfo
.sym_indices
!= NULL
)
890 free (finfo
.sym_indices
);
891 finfo
.sym_indices
= NULL
;
893 if (finfo
.linenos
!= NULL
)
895 free (finfo
.linenos
);
896 finfo
.linenos
= NULL
;
898 if (finfo
.contents
!= NULL
)
900 free (finfo
.contents
);
901 finfo
.contents
= NULL
;
903 if (finfo
.external_relocs
!= NULL
)
905 free (finfo
.external_relocs
);
906 finfo
.external_relocs
= NULL
;
908 if (finfo
.internal_relocs
!= NULL
)
910 free (finfo
.internal_relocs
);
911 finfo
.internal_relocs
= NULL
;
914 /* The value of the last C_FILE symbol is supposed to be the symbol
915 index of the first external symbol. Write it out again if
917 if (finfo
.last_file_index
!= -1
918 && (unsigned int) finfo
.last_file
.n_value
!= obj_raw_syment_count (abfd
))
920 finfo
.last_file
.n_value
= obj_raw_syment_count (abfd
);
921 bfd_coff_swap_sym_out (abfd
, (PTR
) &finfo
.last_file
,
922 (PTR
) finfo
.outsyms
);
924 (obj_sym_filepos (abfd
)
925 + finfo
.last_file_index
* symesz
),
927 || bfd_write (finfo
.outsyms
, symesz
, 1, abfd
) != symesz
)
931 /* Write out the global symbols. */
932 finfo
.failed
= false;
933 coff_link_hash_traverse (coff_hash_table (info
), coff_write_global_sym
,
938 /* The outsyms buffer is used by coff_write_global_sym. */
939 if (finfo
.outsyms
!= NULL
)
941 free (finfo
.outsyms
);
942 finfo
.outsyms
= NULL
;
945 if (info
->relocateable
)
947 /* Now that we have written out all the global symbols, we know
948 the symbol indices to use for relocs against them, and we can
949 finally write out the relocs. */
950 external_relocs
= (bfd_byte
*) malloc (max_output_reloc_count
* relsz
);
951 if (external_relocs
== NULL
)
953 bfd_set_error (bfd_error_no_memory
);
957 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
959 struct internal_reloc
*irel
;
960 struct internal_reloc
*irelend
;
961 struct coff_link_hash_entry
**rel_hash
;
964 if (o
->reloc_count
== 0)
967 irel
= finfo
.section_info
[o
->target_index
].relocs
;
968 irelend
= irel
+ o
->reloc_count
;
969 rel_hash
= finfo
.section_info
[o
->target_index
].rel_hashes
;
970 erel
= external_relocs
;
971 for (; irel
< irelend
; irel
++, rel_hash
++, erel
+= relsz
)
973 if (*rel_hash
!= NULL
)
975 BFD_ASSERT ((*rel_hash
)->indx
>= 0);
976 irel
->r_symndx
= (*rel_hash
)->indx
;
978 bfd_coff_swap_reloc_out (abfd
, (PTR
) irel
, (PTR
) erel
);
981 if (bfd_seek (abfd
, o
->rel_filepos
, SEEK_SET
) != 0
982 || bfd_write ((PTR
) external_relocs
, relsz
, o
->reloc_count
,
983 abfd
) != relsz
* o
->reloc_count
)
987 free (external_relocs
);
988 external_relocs
= NULL
;
991 /* Free up the section information. */
992 if (finfo
.section_info
!= NULL
)
996 for (i
= 0; i
< abfd
->section_count
; i
++)
998 if (finfo
.section_info
[i
].relocs
!= NULL
)
999 free (finfo
.section_info
[i
].relocs
);
1000 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
1001 free (finfo
.section_info
[i
].rel_hashes
);
1003 free (finfo
.section_info
);
1004 finfo
.section_info
= NULL
;
1007 /* Write out the string table. */
1009 (obj_sym_filepos (abfd
)
1010 + obj_raw_syment_count (abfd
) * symesz
),
1014 #if STRING_SIZE_SIZE == 4
1016 _bfd_stringtab_size (finfo
.strtab
) + STRING_SIZE_SIZE
,
1017 (bfd_byte
*) strbuf
);
1019 #error Change bfd_h_put_32
1022 if (bfd_write (strbuf
, 1, STRING_SIZE_SIZE
, abfd
) != STRING_SIZE_SIZE
)
1025 if (! _bfd_stringtab_emit (abfd
, finfo
.strtab
))
1028 _bfd_stringtab_free (finfo
.strtab
);
1030 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
1031 not try to write out the symbols. */
1032 bfd_get_symcount (abfd
) = 0;
1037 if (debug_merge_allocated
)
1038 coff_debug_merge_hash_table_free (&finfo
.debug_merge
);
1039 if (finfo
.strtab
!= NULL
)
1040 _bfd_stringtab_free (finfo
.strtab
);
1041 if (finfo
.section_info
!= NULL
)
1045 for (i
= 0; i
< abfd
->section_count
; i
++)
1047 if (finfo
.section_info
[i
].relocs
!= NULL
)
1048 free (finfo
.section_info
[i
].relocs
);
1049 if (finfo
.section_info
[i
].rel_hashes
!= NULL
)
1050 free (finfo
.section_info
[i
].rel_hashes
);
1052 free (finfo
.section_info
);
1054 if (finfo
.internal_syms
!= NULL
)
1055 free (finfo
.internal_syms
);
1056 if (finfo
.sec_ptrs
!= NULL
)
1057 free (finfo
.sec_ptrs
);
1058 if (finfo
.sym_indices
!= NULL
)
1059 free (finfo
.sym_indices
);
1060 if (finfo
.outsyms
!= NULL
)
1061 free (finfo
.outsyms
);
1062 if (finfo
.linenos
!= NULL
)
1063 free (finfo
.linenos
);
1064 if (finfo
.contents
!= NULL
)
1065 free (finfo
.contents
);
1066 if (finfo
.external_relocs
!= NULL
)
1067 free (finfo
.external_relocs
);
1068 if (finfo
.internal_relocs
!= NULL
)
1069 free (finfo
.internal_relocs
);
1070 if (external_relocs
!= NULL
)
1071 free (external_relocs
);
1075 /* Read in and swap the relocs. This returns a buffer holding the
1076 relocs for section SEC in file ABFD. If CACHE is true and
1077 INTERNAL_RELOCS is NULL, the relocs read in wil be saved in case
1078 the function is called again. If EXTERNAL_RELOCS is not NULL, it
1079 is a buffer large enough to hold the unswapped relocs. If
1080 INTERNAL_RELOCS is not NULL, it is a buffer large enough to hold
1081 the swapped relocs. If REQUIRE_INTERNAL is true, then the return
1082 value must be INTERNAL_RELOCS. The function returns NULL on error. */
1084 struct internal_reloc
*
1085 _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
1086 require_internal
, internal_relocs
)
1090 bfd_byte
*external_relocs
;
1091 boolean require_internal
;
1092 struct internal_reloc
*internal_relocs
;
1094 bfd_size_type relsz
;
1095 bfd_byte
*free_external
= NULL
;
1096 struct internal_reloc
*free_internal
= NULL
;
1099 struct internal_reloc
*irel
;
1101 if (coff_section_data (abfd
, sec
) != NULL
1102 && coff_section_data (abfd
, sec
)->relocs
!= NULL
)
1104 if (! require_internal
)
1105 return coff_section_data (abfd
, sec
)->relocs
;
1106 memcpy (internal_relocs
, coff_section_data (abfd
, sec
)->relocs
,
1107 sec
->reloc_count
* sizeof (struct internal_reloc
));
1108 return internal_relocs
;
1111 relsz
= bfd_coff_relsz (abfd
);
1113 if (external_relocs
== NULL
)
1115 free_external
= (bfd_byte
*) malloc (sec
->reloc_count
* relsz
);
1116 if (free_external
== NULL
&& sec
->reloc_count
> 0)
1118 bfd_set_error (bfd_error_no_memory
);
1121 external_relocs
= free_external
;
1124 if (bfd_seek (abfd
, sec
->rel_filepos
, SEEK_SET
) != 0
1125 || (bfd_read (external_relocs
, relsz
, sec
->reloc_count
, abfd
)
1126 != relsz
* sec
->reloc_count
))
1129 if (internal_relocs
== NULL
)
1131 free_internal
= ((struct internal_reloc
*)
1132 malloc (sec
->reloc_count
1133 * sizeof (struct internal_reloc
)));
1134 if (free_internal
== NULL
&& sec
->reloc_count
> 0)
1136 bfd_set_error (bfd_error_no_memory
);
1139 internal_relocs
= free_internal
;
1142 /* Swap in the relocs. */
1143 erel
= external_relocs
;
1144 erel_end
= erel
+ relsz
* sec
->reloc_count
;
1145 irel
= internal_relocs
;
1146 for (; erel
< erel_end
; erel
+= relsz
, irel
++)
1147 bfd_coff_swap_reloc_in (abfd
, (PTR
) erel
, (PTR
) irel
);
1149 if (free_external
!= NULL
)
1151 free (free_external
);
1152 free_external
= NULL
;
1155 if (cache
&& free_internal
!= NULL
)
1157 if (coff_section_data (abfd
, sec
) == NULL
)
1159 sec
->used_by_bfd
= ((PTR
) bfd_zalloc (abfd
,
1160 sizeof (struct coff_section_tdata
)));
1161 if (sec
->used_by_bfd
== NULL
)
1163 bfd_set_error (bfd_error_no_memory
);
1166 coff_section_data (abfd
, sec
)->contents
= NULL
;
1168 coff_section_data (abfd
, sec
)->relocs
= free_internal
;
1171 return internal_relocs
;
1174 if (free_external
!= NULL
)
1175 free (free_external
);
1176 if (free_internal
!= NULL
)
1177 free (free_internal
);
1181 /* parse out a -heap <reserved>,<commit> line */
1184 dores_com (ptr
, output_bfd
, heap
)
1189 if (coff_data(output_bfd
)->pe
)
1191 int val
= strtoul (ptr
, &ptr
, 0);
1193 pe_data(output_bfd
)->pe_opthdr
.SizeOfHeapReserve
=val
;
1195 pe_data(output_bfd
)->pe_opthdr
.SizeOfStackReserve
=val
;
1199 int val
= strtoul (ptr
+1, &ptr
, 0);
1201 pe_data(output_bfd
)->pe_opthdr
.SizeOfHeapCommit
=val
;
1203 pe_data(output_bfd
)->pe_opthdr
.SizeOfStackCommit
=val
;
1209 static char *get_name(ptr
, dst
)
1216 while (*ptr
&& *ptr
!= ' ')
1222 /* Process any magic embedded commands in a section called .drectve */
1225 process_embedded_commands (output_bfd
, info
, abfd
)
1227 struct bfd_link_info
*info
;
1230 asection
*sec
= bfd_get_section_by_name (abfd
, ".drectve");
1237 copy
= malloc ((size_t) sec
->_raw_size
);
1240 bfd_set_error (bfd_error_no_memory
);
1243 if (! bfd_get_section_contents(abfd
, sec
, copy
, 0, sec
->_raw_size
))
1248 e
= copy
+ sec
->_raw_size
;
1249 for (s
= copy
; s
< e
; )
1255 if (strncmp (s
,"-attr", 5) == 0)
1267 s
= get_name(s
, &name
);
1268 s
= get_name(s
, &attribs
);
1288 asec
= bfd_get_section_by_name (abfd
, name
);
1291 asec
->flags
|= SEC_CODE
;
1293 asec
->flags
|= SEC_READONLY
;
1296 else if (strncmp (s
,"-heap", 5) == 0)
1298 s
= dores_com (s
+5, output_bfd
, 1);
1300 else if (strncmp (s
,"-stack", 6) == 0)
1302 s
= dores_com (s
+6, output_bfd
, 0);
1311 /* Link an input file into the linker output file. This function
1312 handles all the sections and relocations of the input file at once. */
1315 coff_link_input_bfd (finfo
, input_bfd
)
1316 struct coff_final_link_info
*finfo
;
1319 boolean (*sym_is_global
) PARAMS ((bfd
*, struct internal_syment
*));
1320 boolean (*adjust_symndx
) PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*,
1321 asection
*, struct internal_reloc
*,
1324 const char *strings
;
1325 bfd_size_type syment_base
;
1326 unsigned int n_tmask
;
1327 unsigned int n_btshft
;
1329 bfd_size_type isymesz
;
1330 bfd_size_type osymesz
;
1331 bfd_size_type linesz
;
1334 struct internal_syment
*isymp
;
1337 unsigned long output_index
;
1339 struct coff_link_hash_entry
**sym_hash
;
1342 /* Move all the symbols to the output file. */
1344 output_bfd
= finfo
->output_bfd
;
1345 sym_is_global
= coff_backend_info (input_bfd
)->_bfd_coff_sym_is_global
;
1347 syment_base
= obj_raw_syment_count (output_bfd
);
1348 isymesz
= bfd_coff_symesz (input_bfd
);
1349 osymesz
= bfd_coff_symesz (output_bfd
);
1350 linesz
= bfd_coff_linesz (input_bfd
);
1351 BFD_ASSERT (linesz
== bfd_coff_linesz (output_bfd
));
1353 n_tmask
= coff_data (input_bfd
)->local_n_tmask
;
1354 n_btshft
= coff_data (input_bfd
)->local_n_btshft
;
1356 /* Define macros so that ISFCN, et. al., macros work correctly. */
1357 #define N_TMASK n_tmask
1358 #define N_BTSHFT n_btshft
1361 if (! finfo
->info
->keep_memory
)
1364 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
1367 if (! _bfd_coff_get_external_symbols (input_bfd
))
1370 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
1371 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
1372 isymp
= finfo
->internal_syms
;
1373 secpp
= finfo
->sec_ptrs
;
1374 indexp
= finfo
->sym_indices
;
1375 output_index
= syment_base
;
1376 outsym
= finfo
->outsyms
;
1378 if (coff_data(output_bfd
)->pe
)
1380 if (!process_embedded_commands (output_bfd
, finfo
->info
, input_bfd
))
1384 while (esym
< esym_end
)
1386 struct internal_syment isym
;
1391 bfd_coff_swap_sym_in (input_bfd
, (PTR
) esym
, (PTR
) isymp
);
1393 /* Make a copy of *isymp so that the relocate_section function
1394 always sees the original values. This is more reliable than
1395 always recomputing the symbol value even if we are stripping
1399 if (isym
.n_scnum
!= 0)
1400 *secpp
= coff_section_from_bfd_index (input_bfd
, isym
.n_scnum
);
1403 if (isym
.n_value
== 0)
1404 *secpp
= bfd_und_section_ptr
;
1406 *secpp
= bfd_com_section_ptr
;
1413 add
= 1 + isym
.n_numaux
;
1415 /* If we are stripping all symbols, we want to skip this one. */
1416 if (finfo
->info
->strip
== strip_all
)
1421 if (isym
.n_sclass
== C_EXT
1422 || (sym_is_global
&& (*sym_is_global
) (input_bfd
, &isym
)))
1424 /* This is a global symbol. Global symbols come at the
1425 end of the symbol table, so skip them for now.
1426 Function symbols, however, are an exception, and are
1427 not moved to the end. */
1429 if (! ISFCN (isym
.n_type
))
1434 /* This is a local symbol. Skip it if we are discarding
1436 if (finfo
->info
->discard
== discard_all
)
1441 /* If we stripping debugging symbols, and this is a debugging
1442 symbol, then skip it. */
1444 && finfo
->info
->strip
== strip_debugger
1445 && isym
.n_scnum
== N_DEBUG
)
1448 /* If some symbols are stripped based on the name, work out the
1449 name and decide whether to skip this symbol. */
1451 && (finfo
->info
->strip
== strip_some
1452 || finfo
->info
->discard
== discard_l
))
1455 char buf
[SYMNMLEN
+ 1];
1457 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
, buf
);
1461 if ((finfo
->info
->strip
== strip_some
1462 && (bfd_hash_lookup (finfo
->info
->keep_hash
, name
, false,
1465 && finfo
->info
->discard
== discard_l
1466 && strncmp (name
, finfo
->info
->lprefix
,
1467 finfo
->info
->lprefix_len
) == 0))
1471 /* If this is an enum, struct, or union tag, see if we have
1472 already output an identical type. */
1474 && (finfo
->output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) == 0
1475 && (isym
.n_sclass
== C_ENTAG
1476 || isym
.n_sclass
== C_STRTAG
1477 || isym
.n_sclass
== C_UNTAG
)
1478 && isym
.n_numaux
== 1)
1481 char buf
[SYMNMLEN
+ 1];
1482 struct coff_debug_merge_hash_entry
*mh
;
1483 struct coff_debug_merge_type
*mt
;
1484 union internal_auxent aux
;
1485 struct coff_debug_merge_element
**epp
;
1486 bfd_byte
*esl
, *eslend
;
1487 struct internal_syment
*islp
;
1488 struct coff_debug_merge_type
*mtl
;
1490 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
, buf
);
1494 /* Ignore fake names invented by compiler; treat them all as
1496 if (*name
== '~' || *name
== '.'
1497 || (*name
== bfd_get_symbol_leading_char (input_bfd
)
1498 && (name
[1] == '~' || name
[1] == '.')))
1501 mh
= coff_debug_merge_hash_lookup (&finfo
->debug_merge
, name
,
1506 /* Allocate memory to hold type information. If this turns
1507 out to be a duplicate, we pass this address to
1509 mt
= ((struct coff_debug_merge_type
*)
1510 bfd_alloc (input_bfd
,
1511 sizeof (struct coff_debug_merge_type
)));
1514 bfd_set_error (bfd_error_no_memory
);
1517 mt
->class = isym
.n_sclass
;
1519 /* Pick up the aux entry, which points to the end of the tag
1521 bfd_coff_swap_aux_in (input_bfd
, (PTR
) (esym
+ isymesz
),
1522 isym
.n_type
, isym
.n_sclass
, 0, isym
.n_numaux
,
1525 /* Gather the elements. */
1526 epp
= &mt
->elements
;
1527 mt
->elements
= NULL
;
1529 esl
= esym
+ 2 * isymesz
;
1530 eslend
= ((bfd_byte
*) obj_coff_external_syms (input_bfd
)
1531 + aux
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
* isymesz
);
1532 while (esl
< eslend
)
1534 const char *elename
;
1535 char elebuf
[SYMNMLEN
+ 1];
1538 bfd_coff_swap_sym_in (input_bfd
, (PTR
) esl
, (PTR
) islp
);
1540 *epp
= ((struct coff_debug_merge_element
*)
1541 bfd_alloc (input_bfd
,
1542 sizeof (struct coff_debug_merge_element
)));
1545 bfd_set_error (bfd_error_no_memory
);
1549 elename
= _bfd_coff_internal_syment_name (input_bfd
, islp
,
1551 if (elename
== NULL
)
1554 copy
= (char *) bfd_alloc (input_bfd
, strlen (elename
) + 1);
1557 bfd_set_error (bfd_error_no_memory
);
1560 strcpy (copy
, elename
);
1562 (*epp
)->name
= copy
;
1563 (*epp
)->type
= islp
->n_type
;
1565 if (islp
->n_numaux
>= 1
1566 && islp
->n_type
!= T_NULL
1567 && islp
->n_sclass
!= C_EOS
)
1569 union internal_auxent eleaux
;
1572 bfd_coff_swap_aux_in (input_bfd
, (PTR
) (esl
+ isymesz
),
1573 islp
->n_type
, islp
->n_sclass
, 0,
1574 islp
->n_numaux
, (PTR
) &eleaux
);
1575 indx
= eleaux
.x_sym
.x_tagndx
.l
;
1577 /* FIXME: If this tagndx entry refers to a symbol
1578 defined later in this file, we just ignore it.
1579 Handling this correctly would be tedious, and may
1585 (bfd_byte
*) obj_coff_external_syms (input_bfd
))
1588 (*epp
)->tagndx
= finfo
->sym_indices
[indx
];
1589 if ((*epp
)->tagndx
< 0)
1593 epp
= &(*epp
)->next
;
1596 esl
+= (islp
->n_numaux
+ 1) * isymesz
;
1597 islp
+= islp
->n_numaux
+ 1;
1600 /* See if we already have a definition which matches this
1602 for (mtl
= mh
->types
; mtl
!= NULL
; mtl
= mtl
->next
)
1604 struct coff_debug_merge_element
*me
, *mel
;
1606 if (mtl
->class != mt
->class)
1609 for (me
= mt
->elements
, mel
= mtl
->elements
;
1610 me
!= NULL
&& mel
!= NULL
;
1611 me
= me
->next
, mel
= mel
->next
)
1613 if (strcmp (me
->name
, mel
->name
) != 0
1614 || me
->type
!= mel
->type
1615 || me
->tagndx
!= mel
->tagndx
)
1619 if (me
== NULL
&& mel
== NULL
)
1623 if (mtl
== NULL
|| (bfd_size_type
) mtl
->indx
>= syment_base
)
1625 /* This is the first definition of this type. */
1626 mt
->indx
= output_index
;
1627 mt
->next
= mh
->types
;
1632 /* This is a redefinition which can be merged. */
1633 bfd_release (input_bfd
, (PTR
) mt
);
1634 *indexp
= mtl
->indx
;
1635 add
= (eslend
- esym
) / isymesz
;
1640 /* We now know whether we are to skip this symbol or not. */
1643 /* Adjust the symbol in order to output it. */
1645 if (isym
._n
._n_n
._n_zeroes
== 0
1646 && isym
._n
._n_n
._n_offset
!= 0)
1651 /* This symbol has a long name. Enter it in the string
1652 table we are building. Note that we do not check
1653 bfd_coff_symname_in_debug. That is only true for
1654 XCOFF, and XCOFF requires different linking code
1656 name
= _bfd_coff_internal_syment_name (input_bfd
, &isym
,
1660 indx
= _bfd_stringtab_add (finfo
->strtab
, name
, hash
, copy
);
1661 if (indx
== (bfd_size_type
) -1)
1663 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
1666 if (isym
.n_scnum
> 0)
1668 isym
.n_scnum
= (*secpp
)->output_section
->target_index
;
1669 isym
.n_value
+= ((*secpp
)->output_section
->vma
1670 + (*secpp
)->output_offset
1674 /* The value of a C_FILE symbol is the symbol index of the
1675 next C_FILE symbol. The value of the last C_FILE symbol
1676 is the symbol index to the first external symbol
1677 (actually, coff_renumber_symbols does not get this
1678 right--it just sets the value of the last C_FILE symbol
1679 to zero--and nobody has ever complained about it). We
1680 try to get this right, below, just before we write the
1681 symbols out, but in the general case we may have to write
1682 the symbol out twice. */
1683 if (isym
.n_sclass
== C_FILE
)
1685 if (finfo
->last_file_index
!= -1
1686 && finfo
->last_file
.n_value
!= (long) output_index
)
1688 /* We must correct the value of the last C_FILE entry. */
1689 finfo
->last_file
.n_value
= output_index
;
1690 if ((bfd_size_type
) finfo
->last_file_index
>= syment_base
)
1692 /* The last C_FILE symbol is in this input file. */
1693 bfd_coff_swap_sym_out (output_bfd
,
1694 (PTR
) &finfo
->last_file
,
1695 (PTR
) (finfo
->outsyms
1696 + ((finfo
->last_file_index
1702 /* We have already written out the last C_FILE
1703 symbol. We need to write it out again. We
1704 borrow *outsym temporarily. */
1705 bfd_coff_swap_sym_out (output_bfd
,
1706 (PTR
) &finfo
->last_file
,
1708 if (bfd_seek (output_bfd
,
1709 (obj_sym_filepos (output_bfd
)
1710 + finfo
->last_file_index
* osymesz
),
1712 || (bfd_write (outsym
, osymesz
, 1, output_bfd
)
1718 finfo
->last_file_index
= output_index
;
1719 finfo
->last_file
= isym
;
1722 /* Output the symbol. */
1724 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) outsym
);
1726 *indexp
= output_index
;
1731 struct coff_link_hash_entry
*h
;
1733 indx
= ((esym
- (bfd_byte
*) obj_coff_external_syms (input_bfd
))
1735 h
= obj_coff_sym_hashes (input_bfd
)[indx
];
1736 BFD_ASSERT (h
!= NULL
);
1737 h
->indx
= output_index
;
1740 output_index
+= add
;
1741 outsym
+= add
* osymesz
;
1744 esym
+= add
* isymesz
;
1748 for (--add
; add
> 0; --add
)
1755 /* Fix up the aux entries. This must be done in a separate pass,
1756 because we don't know the correct symbol indices until we have
1757 already decided which symbols we are going to keep. */
1759 esym
= (bfd_byte
*) obj_coff_external_syms (input_bfd
);
1760 esym_end
= esym
+ obj_raw_syment_count (input_bfd
) * isymesz
;
1761 isymp
= finfo
->internal_syms
;
1762 indexp
= finfo
->sym_indices
;
1763 sym_hash
= obj_coff_sym_hashes (input_bfd
);
1764 outsym
= finfo
->outsyms
;
1765 while (esym
< esym_end
)
1769 add
= 1 + isymp
->n_numaux
;
1772 || (bfd_size_type
) *indexp
< syment_base
)
1773 && (*sym_hash
== NULL
1774 || (*sym_hash
)->auxbfd
!= input_bfd
))
1775 esym
+= add
* isymesz
;
1778 struct coff_link_hash_entry
*h
;
1785 BFD_ASSERT (h
->numaux
== isymp
->n_numaux
);
1793 /* Handle the aux entries. This handling is based on
1794 coff_pointerize_aux. I don't know if it always correct. */
1795 for (i
= 0; i
< isymp
->n_numaux
&& esym
< esym_end
; i
++)
1797 union internal_auxent aux
;
1798 union internal_auxent
*auxp
;
1804 bfd_coff_swap_aux_in (input_bfd
, (PTR
) esym
, isymp
->n_type
,
1805 isymp
->n_sclass
, i
, isymp
->n_numaux
,
1810 if (isymp
->n_sclass
== C_FILE
)
1812 /* If this is a long filename, we must put it in the
1814 if (auxp
->x_file
.x_n
.x_zeroes
== 0
1815 && auxp
->x_file
.x_n
.x_offset
!= 0)
1817 const char *filename
;
1820 BFD_ASSERT (auxp
->x_file
.x_n
.x_offset
1821 >= STRING_SIZE_SIZE
);
1822 if (strings
== NULL
)
1824 strings
= _bfd_coff_read_string_table (input_bfd
);
1825 if (strings
== NULL
)
1828 filename
= strings
+ auxp
->x_file
.x_n
.x_offset
;
1829 indx
= _bfd_stringtab_add (finfo
->strtab
, filename
,
1831 if (indx
== (bfd_size_type
) -1)
1833 auxp
->x_file
.x_n
.x_offset
= STRING_SIZE_SIZE
+ indx
;
1836 else if (isymp
->n_sclass
!= C_STAT
|| isymp
->n_type
!= T_NULL
)
1840 if (ISFCN (isymp
->n_type
)
1841 || ISTAG (isymp
->n_sclass
)
1842 || isymp
->n_sclass
== C_BLOCK
)
1844 indx
= auxp
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
1846 && indx
< obj_raw_syment_count (input_bfd
))
1848 /* We look forward through the symbol for
1849 the index of the next symbol we are going
1850 to include. I don't know if this is
1852 while (finfo
->sym_indices
[indx
] < 0
1853 && indx
< obj_raw_syment_count (input_bfd
))
1855 if (indx
>= obj_raw_syment_count (input_bfd
))
1856 indx
= output_index
;
1858 indx
= finfo
->sym_indices
[indx
];
1859 auxp
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
= indx
;
1863 indx
= auxp
->x_sym
.x_tagndx
.l
;
1864 if (indx
> 0 && indx
< obj_raw_syment_count (input_bfd
))
1868 symindx
= finfo
->sym_indices
[indx
];
1870 auxp
->x_sym
.x_tagndx
.l
= 0;
1872 auxp
->x_sym
.x_tagndx
.l
= symindx
;
1878 bfd_coff_swap_aux_out (output_bfd
, (PTR
) auxp
, isymp
->n_type
,
1879 isymp
->n_sclass
, i
, isymp
->n_numaux
,
1893 /* Relocate the line numbers, unless we are stripping them. */
1894 if (finfo
->info
->strip
== strip_none
1895 || finfo
->info
->strip
== strip_some
)
1897 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
1903 /* FIXME: If SEC_HAS_CONTENTS is not for the section, then
1904 build_link_order in ldwrite.c will not have created a
1905 link order, which means that we will not have seen this
1906 input section in _bfd_coff_final_link, which means that
1907 we will not have allocated space for the line numbers of
1908 this section. I don't think line numbers can be
1909 meaningful for a section which does not have
1910 SEC_HAS_CONTENTS set, but, if they do, this must be
1912 if (o
->lineno_count
== 0
1913 || (o
->output_section
->flags
& SEC_HAS_CONTENTS
) == 0)
1916 if (bfd_seek (input_bfd
, o
->line_filepos
, SEEK_SET
) != 0
1917 || bfd_read (finfo
->linenos
, linesz
, o
->lineno_count
,
1918 input_bfd
) != linesz
* o
->lineno_count
)
1921 offset
= o
->output_section
->vma
+ o
->output_offset
- o
->vma
;
1922 eline
= finfo
->linenos
;
1923 elineend
= eline
+ linesz
* o
->lineno_count
;
1924 for (; eline
< elineend
; eline
+= linesz
)
1926 struct internal_lineno iline
;
1928 bfd_coff_swap_lineno_in (input_bfd
, (PTR
) eline
, (PTR
) &iline
);
1930 if (iline
.l_lnno
!= 0)
1931 iline
.l_addr
.l_paddr
+= offset
;
1932 else if (iline
.l_addr
.l_symndx
>= 0
1933 && ((unsigned long) iline
.l_addr
.l_symndx
1934 < obj_raw_syment_count (input_bfd
)))
1938 indx
= finfo
->sym_indices
[iline
.l_addr
.l_symndx
];
1942 /* These line numbers are attached to a symbol
1943 which we are stripping. We should really
1944 just discard the line numbers, but that would
1945 be a pain because we have already counted
1951 struct internal_syment is
;
1952 union internal_auxent ia
;
1954 /* Fix up the lnnoptr field in the aux entry of
1955 the symbol. It turns out that we can't do
1956 this when we modify the symbol aux entries,
1957 because gas sometimes screws up the lnnoptr
1958 field and makes it an offset from the start
1959 of the line numbers rather than an absolute
1961 bfd_coff_swap_sym_in (output_bfd
,
1962 (PTR
) (finfo
->outsyms
1963 + ((indx
- syment_base
)
1966 if ((ISFCN (is
.n_type
)
1967 || is
.n_sclass
== C_BLOCK
)
1968 && is
.n_numaux
>= 1)
1972 auxptr
= (PTR
) (finfo
->outsyms
1973 + ((indx
- syment_base
+ 1)
1975 bfd_coff_swap_aux_in (output_bfd
, auxptr
,
1976 is
.n_type
, is
.n_sclass
,
1977 0, is
.n_numaux
, (PTR
) &ia
);
1978 ia
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
1979 (o
->output_section
->line_filepos
1980 + o
->output_section
->lineno_count
* linesz
1981 + eline
- finfo
->linenos
);
1982 bfd_coff_swap_aux_out (output_bfd
, (PTR
) &ia
,
1983 is
.n_type
, is
.n_sclass
, 0,
1984 is
.n_numaux
, auxptr
);
1988 iline
.l_addr
.l_symndx
= indx
;
1991 bfd_coff_swap_lineno_out (output_bfd
, (PTR
) &iline
, (PTR
) eline
);
1994 if (bfd_seek (output_bfd
,
1995 (o
->output_section
->line_filepos
1996 + o
->output_section
->lineno_count
* linesz
),
1998 || bfd_write (finfo
->linenos
, linesz
, o
->lineno_count
,
1999 output_bfd
) != linesz
* o
->lineno_count
)
2002 o
->output_section
->lineno_count
+= o
->lineno_count
;
2006 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
2007 symbol will be the first symbol in the next input file. In the
2008 normal case, this will save us from writing out the C_FILE symbol
2010 if (finfo
->last_file_index
!= -1
2011 && (bfd_size_type
) finfo
->last_file_index
>= syment_base
)
2013 finfo
->last_file
.n_value
= output_index
;
2014 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &finfo
->last_file
,
2015 (PTR
) (finfo
->outsyms
2016 + ((finfo
->last_file_index
- syment_base
)
2020 /* Write the modified symbols to the output file. */
2021 if (outsym
> finfo
->outsyms
)
2023 if (bfd_seek (output_bfd
,
2024 obj_sym_filepos (output_bfd
) + syment_base
* osymesz
,
2026 || (bfd_write (finfo
->outsyms
, outsym
- finfo
->outsyms
, 1,
2028 != (bfd_size_type
) (outsym
- finfo
->outsyms
)))
2031 BFD_ASSERT ((obj_raw_syment_count (output_bfd
)
2032 + (outsym
- finfo
->outsyms
) / osymesz
)
2035 obj_raw_syment_count (output_bfd
) = output_index
;
2038 /* Relocate the contents of each section. */
2039 adjust_symndx
= coff_backend_info (input_bfd
)->_bfd_coff_adjust_symndx
;
2040 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
2044 if ((o
->flags
& SEC_HAS_CONTENTS
) == 0)
2046 if ((o
->flags
& SEC_RELOC
) != 0
2047 && o
->reloc_count
!= 0)
2049 ((*_bfd_error_handler
)
2050 ("%s: relocs in section `%s', but it has no contents",
2051 bfd_get_filename (input_bfd
),
2052 bfd_get_section_name (input_bfd
, o
)));
2053 bfd_set_error (bfd_error_no_contents
);
2060 if (coff_section_data (input_bfd
, o
) != NULL
2061 && coff_section_data (input_bfd
, o
)->contents
!= NULL
)
2062 contents
= coff_section_data (input_bfd
, o
)->contents
;
2065 if (! bfd_get_section_contents (input_bfd
, o
, finfo
->contents
,
2066 (file_ptr
) 0, o
->_raw_size
))
2068 contents
= finfo
->contents
;
2071 if ((o
->flags
& SEC_RELOC
) != 0)
2074 struct internal_reloc
*internal_relocs
;
2075 struct internal_reloc
*irel
;
2077 /* Read in the relocs. */
2078 target_index
= o
->output_section
->target_index
;
2079 internal_relocs
= (_bfd_coff_read_internal_relocs
2080 (input_bfd
, o
, false, finfo
->external_relocs
,
2081 finfo
->info
->relocateable
,
2082 (finfo
->info
->relocateable
2083 ? (finfo
->section_info
[target_index
].relocs
2084 + o
->output_section
->reloc_count
)
2085 : finfo
->internal_relocs
)));
2086 if (internal_relocs
== NULL
)
2089 /* Call processor specific code to relocate the section
2091 if (! bfd_coff_relocate_section (output_bfd
, finfo
->info
,
2095 finfo
->internal_syms
,
2099 if (finfo
->info
->relocateable
)
2102 struct internal_reloc
*irelend
;
2103 struct coff_link_hash_entry
**rel_hash
;
2105 offset
= o
->output_section
->vma
+ o
->output_offset
- o
->vma
;
2106 irel
= internal_relocs
;
2107 irelend
= irel
+ o
->reloc_count
;
2108 rel_hash
= (finfo
->section_info
[target_index
].rel_hashes
2109 + o
->output_section
->reloc_count
);
2110 for (; irel
< irelend
; irel
++, rel_hash
++)
2112 struct coff_link_hash_entry
*h
;
2117 /* Adjust the reloc address and symbol index. */
2119 irel
->r_vaddr
+= offset
;
2121 if (irel
->r_symndx
== -1)
2126 if (! (*adjust_symndx
) (output_bfd
, finfo
->info
,
2134 h
= obj_coff_sym_hashes (input_bfd
)[irel
->r_symndx
];
2137 /* This is a global symbol. */
2139 irel
->r_symndx
= h
->indx
;
2142 /* This symbol is being written at the end
2143 of the file, and we do not yet know the
2144 symbol index. We save the pointer to the
2145 hash table entry in the rel_hash list.
2146 We set the indx field to -2 to indicate
2147 that this symbol must not be stripped. */
2156 indx
= finfo
->sym_indices
[irel
->r_symndx
];
2158 irel
->r_symndx
= indx
;
2161 struct internal_syment
*is
;
2163 char buf
[SYMNMLEN
+ 1];
2165 /* This reloc is against a symbol we are
2166 stripping. It would be possible to
2167 handle this case, but I don't think it's
2169 is
= finfo
->internal_syms
+ irel
->r_symndx
;
2171 name
= (_bfd_coff_internal_syment_name
2172 (input_bfd
, is
, buf
));
2176 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
2177 (finfo
->info
, name
, input_bfd
, o
,
2184 o
->output_section
->reloc_count
+= o
->reloc_count
;
2188 /* Write out the modified section contents. */
2189 if (! bfd_set_section_contents (output_bfd
, o
->output_section
,
2190 contents
, o
->output_offset
,
2191 (o
->_cooked_size
!= 0
2197 if (! finfo
->info
->keep_memory
)
2199 if (! _bfd_coff_free_symbols (input_bfd
))
2206 /* Write out a global symbol. Called via coff_link_hash_traverse. */
2209 coff_write_global_sym (h
, data
)
2210 struct coff_link_hash_entry
*h
;
2213 struct coff_final_link_info
*finfo
= (struct coff_final_link_info
*) data
;
2215 struct internal_syment isym
;
2216 bfd_size_type symesz
;
2219 output_bfd
= finfo
->output_bfd
;
2225 && (finfo
->info
->strip
== strip_all
2226 || (finfo
->info
->strip
== strip_some
2227 && (bfd_hash_lookup (finfo
->info
->keep_hash
,
2228 h
->root
.root
.string
, false, false)
2232 switch (h
->root
.type
)
2235 case bfd_link_hash_new
:
2239 case bfd_link_hash_undefined
:
2240 case bfd_link_hash_undefweak
:
2241 isym
.n_scnum
= N_UNDEF
;
2245 case bfd_link_hash_defined
:
2246 case bfd_link_hash_defweak
:
2250 sec
= h
->root
.u
.def
.section
->output_section
;
2251 if (bfd_is_abs_section (sec
))
2252 isym
.n_scnum
= N_ABS
;
2254 isym
.n_scnum
= sec
->target_index
;
2255 isym
.n_value
= (h
->root
.u
.def
.value
2257 + h
->root
.u
.def
.section
->output_offset
);
2261 case bfd_link_hash_common
:
2262 isym
.n_scnum
= N_UNDEF
;
2263 isym
.n_value
= h
->root
.u
.c
.size
;
2266 case bfd_link_hash_indirect
:
2267 case bfd_link_hash_warning
:
2268 /* Just ignore these. They can't be handled anyhow. */
2272 if (strlen (h
->root
.root
.string
) <= SYMNMLEN
)
2273 strncpy (isym
._n
._n_name
, h
->root
.root
.string
, SYMNMLEN
);
2280 if ((output_bfd
->flags
& BFD_TRADITIONAL_FORMAT
) != 0)
2282 indx
= _bfd_stringtab_add (finfo
->strtab
, h
->root
.root
.string
, hash
,
2284 if (indx
== (bfd_size_type
) -1)
2286 finfo
->failed
= true;
2289 isym
._n
._n_n
._n_zeroes
= 0;
2290 isym
._n
._n_n
._n_offset
= STRING_SIZE_SIZE
+ indx
;
2293 isym
.n_sclass
= h
->class;
2294 isym
.n_type
= h
->type
;
2296 if (isym
.n_sclass
== C_NULL
)
2297 isym
.n_sclass
= C_EXT
;
2299 isym
.n_numaux
= h
->numaux
;
2301 bfd_coff_swap_sym_out (output_bfd
, (PTR
) &isym
, (PTR
) finfo
->outsyms
);
2303 symesz
= bfd_coff_symesz (output_bfd
);
2305 if (bfd_seek (output_bfd
,
2306 (obj_sym_filepos (output_bfd
)
2307 + obj_raw_syment_count (output_bfd
) * symesz
),
2309 || bfd_write (finfo
->outsyms
, symesz
, 1, output_bfd
) != symesz
)
2311 finfo
->failed
= true;
2315 h
->indx
= obj_raw_syment_count (output_bfd
);
2317 ++obj_raw_syment_count (output_bfd
);
2319 /* Write out any associated aux entries. There normally will be
2320 none. If there are any, I have no idea how to modify them. */
2321 for (i
= 0; i
< isym
.n_numaux
; i
++)
2323 bfd_coff_swap_aux_out (output_bfd
, (PTR
) (h
->aux
+ i
), isym
.n_type
,
2324 isym
.n_sclass
, i
, isym
.n_numaux
,
2325 (PTR
) finfo
->outsyms
);
2326 if (bfd_write (finfo
->outsyms
, symesz
, 1, output_bfd
) != symesz
)
2328 finfo
->failed
= true;
2331 ++obj_raw_syment_count (output_bfd
);
2337 /* Handle a link order which is supposed to generate a reloc. */
2340 coff_reloc_link_order (output_bfd
, finfo
, output_section
, link_order
)
2342 struct coff_final_link_info
*finfo
;
2343 asection
*output_section
;
2344 struct bfd_link_order
*link_order
;
2346 reloc_howto_type
*howto
;
2347 struct internal_reloc
*irel
;
2348 struct coff_link_hash_entry
**rel_hash_ptr
;
2350 howto
= bfd_reloc_type_lookup (output_bfd
, link_order
->u
.reloc
.p
->reloc
);
2353 bfd_set_error (bfd_error_bad_value
);
2357 if (link_order
->u
.reloc
.p
->addend
!= 0)
2361 bfd_reloc_status_type rstat
;
2364 size
= bfd_get_reloc_size (howto
);
2365 buf
= (bfd_byte
*) bfd_zmalloc (size
);
2368 bfd_set_error (bfd_error_no_memory
);
2372 rstat
= _bfd_relocate_contents (howto
, output_bfd
,
2373 link_order
->u
.reloc
.p
->addend
, buf
);
2379 case bfd_reloc_outofrange
:
2381 case bfd_reloc_overflow
:
2382 if (! ((*finfo
->info
->callbacks
->reloc_overflow
)
2384 (link_order
->type
== bfd_section_reloc_link_order
2385 ? bfd_section_name (output_bfd
,
2386 link_order
->u
.reloc
.p
->u
.section
)
2387 : link_order
->u
.reloc
.p
->u
.name
),
2388 howto
->name
, link_order
->u
.reloc
.p
->addend
,
2389 (bfd
*) NULL
, (asection
*) NULL
, (bfd_vma
) 0)))
2396 ok
= bfd_set_section_contents (output_bfd
, output_section
, (PTR
) buf
,
2397 (file_ptr
) link_order
->offset
, size
);
2403 /* Store the reloc information in the right place. It will get
2404 swapped and written out at the end of the final_link routine. */
2406 irel
= (finfo
->section_info
[output_section
->target_index
].relocs
2407 + output_section
->reloc_count
);
2408 rel_hash_ptr
= (finfo
->section_info
[output_section
->target_index
].rel_hashes
2409 + output_section
->reloc_count
);
2411 memset (irel
, 0, sizeof (struct internal_reloc
));
2412 *rel_hash_ptr
= NULL
;
2414 irel
->r_vaddr
= output_section
->vma
+ link_order
->offset
;
2416 if (link_order
->type
== bfd_section_reloc_link_order
)
2418 /* We need to somehow locate a symbol in the right section. The
2419 symbol must either have a value of zero, or we must adjust
2420 the addend by the value of the symbol. FIXME: Write this
2421 when we need it. The old linker couldn't handle this anyhow. */
2423 *rel_hash_ptr
= NULL
;
2428 struct coff_link_hash_entry
*h
;
2430 h
= coff_link_hash_lookup (coff_hash_table (finfo
->info
),
2431 link_order
->u
.reloc
.p
->u
.name
,
2432 false, false, true);
2436 irel
->r_symndx
= h
->indx
;
2439 /* Set the index to -2 to force this symbol to get
2448 if (! ((*finfo
->info
->callbacks
->unattached_reloc
)
2449 (finfo
->info
, link_order
->u
.reloc
.p
->u
.name
, (bfd
*) NULL
,
2450 (asection
*) NULL
, (bfd_vma
) 0)))
2456 /* FIXME: Is this always right? */
2457 irel
->r_type
= howto
->type
;
2459 /* r_size is only used on the RS/6000, which needs its own linker
2460 routines anyhow. r_extern is only used for ECOFF. */
2462 /* FIXME: What is the right value for r_offset? Is zero OK? */
2464 ++output_section
->reloc_count
;
2469 /* A basic reloc handling routine which may be used by processors with
2473 _bfd_coff_generic_relocate_section (output_bfd
, info
, input_bfd
,
2474 input_section
, contents
, relocs
, syms
,
2477 struct bfd_link_info
*info
;
2479 asection
*input_section
;
2481 struct internal_reloc
*relocs
;
2482 struct internal_syment
*syms
;
2483 asection
**sections
;
2485 struct internal_reloc
*rel
;
2486 struct internal_reloc
*relend
;
2490 relend
= rel
+ input_section
->reloc_count
;
2491 for (; rel
< relend
; rel
++)
2494 struct coff_link_hash_entry
*h
;
2495 struct internal_syment
*sym
;
2498 reloc_howto_type
*howto
;
2499 bfd_reloc_status_type rstat
;
2501 symndx
= rel
->r_symndx
;
2510 h
= obj_coff_sym_hashes (input_bfd
)[symndx
];
2511 sym
= syms
+ symndx
;
2514 /* COFF treats common symbols in one of two ways. Either the
2515 size of the symbol is included in the section contents, or it
2516 is not. We assume that the size is not included, and force
2517 the rtype_to_howto function to adjust the addend as needed. */
2519 if (sym
!= NULL
&& sym
->n_scnum
!= 0)
2520 addend
= - sym
->n_value
;
2525 howto
= bfd_coff_rtype_to_howto (input_bfd
, input_section
, rel
, h
,
2538 sec
= bfd_abs_section_ptr
;
2543 sec
= sections
[symndx
];
2544 val
= (sec
->output_section
->vma
2545 + sec
->output_offset
2552 if (h
->root
.type
== bfd_link_hash_defined
2553 || h
->root
.type
== bfd_link_hash_defweak
)
2557 sec
= h
->root
.u
.def
.section
;
2558 val
= (h
->root
.u
.def
.value
2559 + sec
->output_section
->vma
2560 + sec
->output_offset
);
2563 else if (! info
->relocateable
)
2565 if (! ((*info
->callbacks
->undefined_symbol
)
2566 (info
, h
->root
.root
.string
, input_bfd
, input_section
,
2567 rel
->r_vaddr
- input_section
->vma
)))
2572 if (info
->base_file
)
2574 /* So if this is non pcrelative, and is referenced
2575 to a section or a common symbol, then it needs a reloc */
2576 if (!howto
->pc_relative
2577 && sym
&& (sym
->n_scnum
|| sym
->n_value
))
2579 /* relocation to a symbol in a section which
2580 isn't absolute - we output the address here
2582 bfd_vma addr
= rel
->r_vaddr
2583 + input_section
->output_offset
2584 + input_section
->output_section
->vma
;
2585 if (coff_data(output_bfd
)->pe
)
2586 addr
-= pe_data(output_bfd
)->pe_opthdr
.ImageBase
;
2587 fwrite (&addr
, 1,4, (FILE *) info
->base_file
);
2591 rstat
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
2593 rel
->r_vaddr
- input_section
->vma
,
2602 case bfd_reloc_overflow
:
2605 char buf
[SYMNMLEN
+ 1];
2610 name
= h
->root
.root
.string
;
2613 name
= _bfd_coff_internal_syment_name (input_bfd
, sym
, buf
);
2618 if (! ((*info
->callbacks
->reloc_overflow
)
2619 (info
, name
, howto
->name
, (bfd_vma
) 0, input_bfd
,
2620 input_section
, rel
->r_vaddr
- input_section
->vma
)))