1 /* COFF specific linker code.
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999 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 static boolean coff_link_add_object_symbols
31 PARAMS ((bfd *, struct bfd_link_info *));
32 static boolean coff_link_check_archive_element
33 PARAMS ((bfd *, struct bfd_link_info *, boolean *));
34 static boolean coff_link_check_ar_symbols
35 PARAMS ((bfd *, struct bfd_link_info *, boolean *));
36 static boolean coff_link_add_symbols PARAMS ((bfd *, struct bfd_link_info *));
37 static char *dores_com PARAMS ((char *, bfd *, int));
38 static char *get_name PARAMS ((char *, char **));
39 static int process_embedded_commands
40 PARAMS ((bfd *, struct bfd_link_info *, bfd *));
41 static void mark_relocs PARAMS ((struct coff_final_link_info *, bfd *));
43 /* Create an entry in a COFF linker hash table. */
45 struct bfd_hash_entry *
46 _bfd_coff_link_hash_newfunc (entry, table, string)
47 struct bfd_hash_entry *entry;
48 struct bfd_hash_table *table;
51 struct coff_link_hash_entry *ret = (struct coff_link_hash_entry *) entry;
53 /* Allocate the structure if it has not already been allocated by a
55 if (ret == (struct coff_link_hash_entry *) NULL)
56 ret = ((struct coff_link_hash_entry *)
57 bfd_hash_allocate (table, sizeof (struct coff_link_hash_entry)));
58 if (ret == (struct coff_link_hash_entry *) NULL)
59 return (struct bfd_hash_entry *) ret;
61 /* Call the allocation method of the superclass. */
62 ret = ((struct coff_link_hash_entry *)
63 _bfd_link_hash_newfunc ((struct bfd_hash_entry *) ret,
65 if (ret != (struct coff_link_hash_entry *) NULL)
67 /* Set local fields. */
76 return (struct bfd_hash_entry *) ret;
79 /* Initialize a COFF linker hash table. */
82 _bfd_coff_link_hash_table_init (table, abfd, newfunc)
83 struct coff_link_hash_table *table;
85 struct bfd_hash_entry *(*newfunc) PARAMS ((struct bfd_hash_entry *,
86 struct bfd_hash_table *,
89 table->stab_info = NULL;
90 return _bfd_link_hash_table_init (&table->root, abfd, newfunc);
93 /* Create a COFF linker hash table. */
95 struct bfd_link_hash_table *
96 _bfd_coff_link_hash_table_create (abfd)
99 struct coff_link_hash_table *ret;
101 ret = ((struct coff_link_hash_table *)
102 bfd_alloc (abfd, sizeof (struct coff_link_hash_table)));
105 if (! _bfd_coff_link_hash_table_init (ret, abfd,
106 _bfd_coff_link_hash_newfunc))
108 bfd_release (abfd, ret);
109 return (struct bfd_link_hash_table *) NULL;
114 /* Create an entry in a COFF debug merge hash table. */
116 struct bfd_hash_entry *
117 _bfd_coff_debug_merge_hash_newfunc (entry, table, string)
118 struct bfd_hash_entry *entry;
119 struct bfd_hash_table *table;
122 struct coff_debug_merge_hash_entry *ret =
123 (struct coff_debug_merge_hash_entry *) entry;
125 /* Allocate the structure if it has not already been allocated by a
127 if (ret == (struct coff_debug_merge_hash_entry *) NULL)
128 ret = ((struct coff_debug_merge_hash_entry *)
129 bfd_hash_allocate (table,
130 sizeof (struct coff_debug_merge_hash_entry)));
131 if (ret == (struct coff_debug_merge_hash_entry *) NULL)
132 return (struct bfd_hash_entry *) ret;
134 /* Call the allocation method of the superclass. */
135 ret = ((struct coff_debug_merge_hash_entry *)
136 bfd_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
137 if (ret != (struct coff_debug_merge_hash_entry *) NULL)
139 /* Set local fields. */
143 return (struct bfd_hash_entry *) ret;
146 /* Given a COFF BFD, add symbols to the global hash table as
150 _bfd_coff_link_add_symbols (abfd, info)
152 struct bfd_link_info *info;
154 switch (bfd_get_format (abfd))
157 return coff_link_add_object_symbols (abfd, info);
159 return (_bfd_generic_link_add_archive_symbols
160 (abfd, info, coff_link_check_archive_element));
162 bfd_set_error (bfd_error_wrong_format);
167 /* Add symbols from a COFF object file. */
170 coff_link_add_object_symbols (abfd, info)
172 struct bfd_link_info *info;
174 if (! _bfd_coff_get_external_symbols (abfd))
176 if (! coff_link_add_symbols (abfd, info))
179 if (! info->keep_memory)
181 if (! _bfd_coff_free_symbols (abfd))
187 /* Check a single archive element to see if we need to include it in
188 the link. *PNEEDED is set according to whether this element is
189 needed in the link or not. This is called via
190 _bfd_generic_link_add_archive_symbols. */
193 coff_link_check_archive_element (abfd, info, pneeded)
195 struct bfd_link_info *info;
198 if (! _bfd_coff_get_external_symbols (abfd))
201 if (! coff_link_check_ar_symbols (abfd, info, pneeded))
206 if (! coff_link_add_symbols (abfd, info))
210 if (! info->keep_memory || ! *pneeded)
212 if (! _bfd_coff_free_symbols (abfd))
219 /* Look through the symbols to see if this object file should be
220 included in the link. */
223 coff_link_check_ar_symbols (abfd, info, pneeded)
225 struct bfd_link_info *info;
228 boolean (*sym_is_global) PARAMS ((bfd *, struct internal_syment *));
229 bfd_size_type symesz;
235 sym_is_global = coff_backend_info (abfd)->_bfd_coff_sym_is_global;
237 symesz = bfd_coff_symesz (abfd);
238 esym = (bfd_byte *) obj_coff_external_syms (abfd);
239 esym_end = esym + obj_raw_syment_count (abfd) * symesz;
240 while (esym < esym_end)
242 struct internal_syment sym;
244 bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
246 if ((sym.n_sclass == C_EXT
247 || sym.n_sclass == C_WEAKEXT
248 || (obj_pe (abfd) && sym.n_sclass == C_NT_WEAK)
250 || sym.n_sclass == C_SYSTEM
252 || (sym_is_global && (*sym_is_global) (abfd, &sym)))
253 && (sym.n_scnum != 0 || sym.n_value != 0))
256 char buf[SYMNMLEN + 1];
257 struct bfd_link_hash_entry *h;
259 /* This symbol is externally visible, and is defined by this
262 name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
265 h = bfd_link_hash_lookup (info->hash, name, false, false, true);
267 /* We are only interested in symbols that are currently
268 undefined. If a symbol is currently known to be common,
269 COFF linkers do not bring in an object file which defines
271 if (h != (struct bfd_link_hash_entry *) NULL
272 && h->type == bfd_link_hash_undefined)
274 if (! (*info->callbacks->add_archive_element) (info, abfd, name))
281 esym += (sym.n_numaux + 1) * symesz;
284 /* We do not need this object file. */
288 /* Add all the symbols from an object file to the hash table. */
291 coff_link_add_symbols (abfd, info)
293 struct bfd_link_info *info;
295 boolean (*sym_is_global) PARAMS ((bfd *, struct internal_syment *));
297 boolean default_copy;
298 bfd_size_type symcount;
299 struct coff_link_hash_entry **sym_hash;
300 bfd_size_type symesz;
304 /* Keep the symbols during this function, in case the linker needs
305 to read the generic symbols in order to report an error message. */
306 keep_syms = obj_coff_keep_syms (abfd);
307 obj_coff_keep_syms (abfd) = true;
309 sym_is_global = coff_backend_info (abfd)->_bfd_coff_sym_is_global;
311 if (info->keep_memory)
312 default_copy = false;
316 symcount = obj_raw_syment_count (abfd);
318 /* We keep a list of the linker hash table entries that correspond
319 to particular symbols. */
320 sym_hash = ((struct coff_link_hash_entry **)
323 * sizeof (struct coff_link_hash_entry *))));
324 if (sym_hash == NULL && symcount != 0)
326 obj_coff_sym_hashes (abfd) = sym_hash;
328 (size_t) symcount * sizeof (struct coff_link_hash_entry *));
330 symesz = bfd_coff_symesz (abfd);
331 BFD_ASSERT (symesz == bfd_coff_auxesz (abfd));
332 esym = (bfd_byte *) obj_coff_external_syms (abfd);
333 esym_end = esym + symcount * symesz;
334 while (esym < esym_end)
336 struct internal_syment sym;
339 bfd_coff_swap_sym_in (abfd, (PTR) esym, (PTR) &sym);
341 if (sym.n_sclass == C_EXT
342 || sym.n_sclass == C_WEAKEXT
343 || (obj_pe (abfd) && sym.n_sclass == C_NT_WEAK)
345 || sym.n_sclass == C_SYSTEM
347 || (sym_is_global && (*sym_is_global) (abfd, &sym)))
350 char buf[SYMNMLEN + 1];
356 /* This symbol is externally visible. */
358 name = _bfd_coff_internal_syment_name (abfd, &sym, buf);
362 /* We must copy the name into memory if we got it from the
363 syment itself, rather than the string table. */
365 if (sym._n._n_n._n_zeroes != 0
366 || sym._n._n_n._n_offset == 0)
371 if (sym.n_scnum == 0)
376 section = bfd_und_section_ptr;
381 section = bfd_com_section_ptr;
386 flags = BSF_EXPORT | BSF_GLOBAL;
387 section = coff_section_from_bfd_index (abfd, sym.n_scnum);
389 value -= section->vma;
392 if (sym.n_sclass == C_WEAKEXT
393 || (obj_pe (abfd) && sym.n_sclass == C_NT_WEAK))
398 /* In the PE format, section symbols actually refer to the
399 start of the output section. We handle them specially
401 if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
403 *sym_hash = coff_link_hash_lookup (coff_hash_table (info),
404 name, false, copy, false);
405 if (*sym_hash != NULL)
407 if (((*sym_hash)->coff_link_hash_flags
408 & COFF_LINK_HASH_PE_SECTION_SYMBOL) == 0
409 && (*sym_hash)->root.type != bfd_link_hash_undefined
410 && (*sym_hash)->root.type != bfd_link_hash_undefweak)
411 (*_bfd_error_handler)
412 ("Warning: symbol `%s' is both section and non-section",
421 if (! (bfd_coff_link_add_one_symbol
422 (info, abfd, name, flags, section, value,
423 (const char *) NULL, copy, false,
424 (struct bfd_link_hash_entry **) sym_hash)))
428 if (obj_pe (abfd) && (flags & BSF_SECTION_SYM) != 0)
429 (*sym_hash)->coff_link_hash_flags |=
430 COFF_LINK_HASH_PE_SECTION_SYMBOL;
432 if (section == bfd_com_section_ptr
433 && (*sym_hash)->root.type == bfd_link_hash_common
434 && ((*sym_hash)->root.u.c.p->alignment_power
435 > bfd_coff_default_section_alignment_power (abfd)))
436 (*sym_hash)->root.u.c.p->alignment_power
437 = bfd_coff_default_section_alignment_power (abfd);
439 if (info->hash->creator->flavour == bfd_get_flavour (abfd))
441 if (((*sym_hash)->class == C_NULL
442 && (*sym_hash)->type == T_NULL)
445 && (*sym_hash)->root.type != bfd_link_hash_defined
446 && (*sym_hash)->root.type != bfd_link_hash_defweak))
448 (*sym_hash)->class = sym.n_sclass;
449 if (sym.n_type != T_NULL)
451 if ((*sym_hash)->type != T_NULL
452 && (*sym_hash)->type != sym.n_type)
453 (*_bfd_error_handler)
454 (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
455 name, (*sym_hash)->type, sym.n_type,
456 bfd_get_filename (abfd));
457 (*sym_hash)->type = sym.n_type;
459 (*sym_hash)->auxbfd = abfd;
460 if (sym.n_numaux != 0)
462 union internal_auxent *alloc;
465 union internal_auxent *iaux;
467 (*sym_hash)->numaux = sym.n_numaux;
468 alloc = ((union internal_auxent *)
469 bfd_hash_allocate (&info->hash->table,
471 * sizeof (*alloc))));
474 for (i = 0, eaux = esym + symesz, iaux = alloc;
476 i++, eaux += symesz, iaux++)
477 bfd_coff_swap_aux_in (abfd, (PTR) eaux, sym.n_type,
478 sym.n_sclass, i, sym.n_numaux,
480 (*sym_hash)->aux = alloc;
486 esym += (sym.n_numaux + 1) * symesz;
487 sym_hash += sym.n_numaux + 1;
490 /* If this is a non-traditional, non-relocateable link, try to
491 optimize the handling of any .stab/.stabstr sections. */
492 if (! info->relocateable
493 && ! info->traditional_format
494 && info->hash->creator->flavour == bfd_get_flavour (abfd)
495 && (info->strip != strip_all && info->strip != strip_debugger))
497 asection *stab, *stabstr;
499 stab = bfd_get_section_by_name (abfd, ".stab");
502 stabstr = bfd_get_section_by_name (abfd, ".stabstr");
506 struct coff_link_hash_table *table;
507 struct coff_section_tdata *secdata;
509 secdata = coff_section_data (abfd, stab);
513 (PTR) bfd_zalloc (abfd,
514 sizeof (struct coff_section_tdata));
515 if (stab->used_by_bfd == NULL)
517 secdata = coff_section_data (abfd, stab);
520 table = coff_hash_table (info);
522 if (! _bfd_link_section_stabs (abfd, &table->stab_info,
524 &secdata->stab_info))
530 obj_coff_keep_syms (abfd) = keep_syms;
535 obj_coff_keep_syms (abfd) = keep_syms;
539 /* Do the final link step. */
542 _bfd_coff_final_link (abfd, info)
544 struct bfd_link_info *info;
546 bfd_size_type symesz;
547 struct coff_final_link_info finfo;
548 boolean debug_merge_allocated;
549 boolean long_section_names;
551 struct bfd_link_order *p;
552 size_t max_sym_count;
553 size_t max_lineno_count;
554 size_t max_reloc_count;
555 size_t max_output_reloc_count;
556 size_t max_contents_size;
557 file_ptr rel_filepos;
559 file_ptr line_filepos;
562 bfd_byte *external_relocs = NULL;
563 char strbuf[STRING_SIZE_SIZE];
565 symesz = bfd_coff_symesz (abfd);
568 finfo.output_bfd = abfd;
570 finfo.section_info = NULL;
571 finfo.last_file_index = -1;
572 finfo.last_bf_index = -1;
573 finfo.internal_syms = NULL;
574 finfo.sec_ptrs = NULL;
575 finfo.sym_indices = NULL;
576 finfo.outsyms = NULL;
577 finfo.linenos = NULL;
578 finfo.contents = NULL;
579 finfo.external_relocs = NULL;
580 finfo.internal_relocs = NULL;
581 finfo.global_to_static = false;
582 debug_merge_allocated = false;
584 coff_data (abfd)->link_info = info;
586 finfo.strtab = _bfd_stringtab_init ();
587 if (finfo.strtab == NULL)
590 if (! coff_debug_merge_hash_table_init (&finfo.debug_merge))
592 debug_merge_allocated = true;
594 /* Compute the file positions for all the sections. */
595 if (! abfd->output_has_begun)
597 if (! bfd_coff_compute_section_file_positions (abfd))
601 /* Count the line numbers and relocation entries required for the
602 output file. Set the file positions for the relocs. */
603 rel_filepos = obj_relocbase (abfd);
604 relsz = bfd_coff_relsz (abfd);
605 max_contents_size = 0;
606 max_lineno_count = 0;
609 long_section_names = false;
610 for (o = abfd->sections; o != NULL; o = o->next)
614 for (p = o->link_order_head; p != NULL; p = p->next)
616 if (p->type == bfd_indirect_link_order)
620 sec = p->u.indirect.section;
622 /* Mark all sections which are to be included in the
623 link. This will normally be every section. We need
624 to do this so that we can identify any sections which
625 the linker has decided to not include. */
626 sec->linker_mark = true;
628 if (info->strip == strip_none
629 || info->strip == strip_some)
630 o->lineno_count += sec->lineno_count;
632 if (info->relocateable)
633 o->reloc_count += sec->reloc_count;
635 if (sec->_raw_size > max_contents_size)
636 max_contents_size = sec->_raw_size;
637 if (sec->lineno_count > max_lineno_count)
638 max_lineno_count = sec->lineno_count;
639 if (sec->reloc_count > max_reloc_count)
640 max_reloc_count = sec->reloc_count;
642 else if (info->relocateable
643 && (p->type == bfd_section_reloc_link_order
644 || p->type == bfd_symbol_reloc_link_order))
647 if (o->reloc_count == 0)
651 o->flags |= SEC_RELOC;
652 o->rel_filepos = rel_filepos;
653 rel_filepos += o->reloc_count * relsz;
656 if (bfd_coff_long_section_names (abfd)
657 && strlen (o->name) > SCNNMLEN)
659 /* This section has a long name which must go in the string
660 table. This must correspond to the code in
661 coff_write_object_contents which puts the string index
662 into the s_name field of the section header. That is why
663 we pass hash as false. */
664 if (_bfd_stringtab_add (finfo.strtab, o->name, false, false)
665 == (bfd_size_type) -1)
667 long_section_names = true;
671 /* If doing a relocateable link, allocate space for the pointers we
673 if (info->relocateable)
677 /* We use section_count + 1, rather than section_count, because
678 the target_index fields are 1 based. */
680 ((struct coff_link_section_info *)
681 bfd_malloc ((abfd->section_count + 1)
682 * sizeof (struct coff_link_section_info)));
683 if (finfo.section_info == NULL)
685 for (i = 0; i <= abfd->section_count; i++)
687 finfo.section_info[i].relocs = NULL;
688 finfo.section_info[i].rel_hashes = NULL;
692 /* We now know the size of the relocs, so we can determine the file
693 positions of the line numbers. */
694 line_filepos = rel_filepos;
695 linesz = bfd_coff_linesz (abfd);
696 max_output_reloc_count = 0;
697 for (o = abfd->sections; o != NULL; o = o->next)
699 if (o->lineno_count == 0)
703 o->line_filepos = line_filepos;
704 line_filepos += o->lineno_count * linesz;
707 if (o->reloc_count != 0)
709 /* We don't know the indices of global symbols until we have
710 written out all the local symbols. For each section in
711 the output file, we keep an array of pointers to hash
712 table entries. Each entry in the array corresponds to a
713 reloc. When we find a reloc against a global symbol, we
714 set the corresponding entry in this array so that we can
715 fix up the symbol index after we have written out all the
718 Because of this problem, we also keep the relocs in
719 memory until the end of the link. This wastes memory,
720 but only when doing a relocateable link, which is not the
722 BFD_ASSERT (info->relocateable);
723 finfo.section_info[o->target_index].relocs =
724 ((struct internal_reloc *)
725 bfd_malloc (o->reloc_count * sizeof (struct internal_reloc)));
726 finfo.section_info[o->target_index].rel_hashes =
727 ((struct coff_link_hash_entry **)
728 bfd_malloc (o->reloc_count
729 * sizeof (struct coff_link_hash_entry *)));
730 if (finfo.section_info[o->target_index].relocs == NULL
731 || finfo.section_info[o->target_index].rel_hashes == NULL)
734 if (o->reloc_count > max_output_reloc_count)
735 max_output_reloc_count = o->reloc_count;
738 /* Reset the reloc and lineno counts, so that we can use them to
739 count the number of entries we have output so far. */
744 obj_sym_filepos (abfd) = line_filepos;
746 /* Figure out the largest number of symbols in an input BFD. Take
747 the opportunity to clear the output_has_begun fields of all the
750 for (sub = info->input_bfds; sub != NULL; sub = sub->link_next)
754 sub->output_has_begun = false;
755 sz = obj_raw_syment_count (sub);
756 if (sz > max_sym_count)
760 /* Allocate some buffers used while linking. */
761 finfo.internal_syms = ((struct internal_syment *)
762 bfd_malloc (max_sym_count
763 * sizeof (struct internal_syment)));
764 finfo.sec_ptrs = (asection **) bfd_malloc (max_sym_count
765 * sizeof (asection *));
766 finfo.sym_indices = (long *) bfd_malloc (max_sym_count * sizeof (long));
767 finfo.outsyms = ((bfd_byte *)
768 bfd_malloc ((size_t) ((max_sym_count + 1) * symesz)));
769 finfo.linenos = (bfd_byte *) bfd_malloc (max_lineno_count
770 * bfd_coff_linesz (abfd));
771 finfo.contents = (bfd_byte *) bfd_malloc (max_contents_size);
772 finfo.external_relocs = (bfd_byte *) bfd_malloc (max_reloc_count * relsz);
773 if (! info->relocateable)
774 finfo.internal_relocs = ((struct internal_reloc *)
775 bfd_malloc (max_reloc_count
776 * sizeof (struct internal_reloc)));
777 if ((finfo.internal_syms == NULL && max_sym_count > 0)
778 || (finfo.sec_ptrs == NULL && max_sym_count > 0)
779 || (finfo.sym_indices == NULL && max_sym_count > 0)
780 || finfo.outsyms == NULL
781 || (finfo.linenos == NULL && max_lineno_count > 0)
782 || (finfo.contents == NULL && max_contents_size > 0)
783 || (finfo.external_relocs == NULL && max_reloc_count > 0)
784 || (! info->relocateable
785 && finfo.internal_relocs == NULL
786 && max_reloc_count > 0))
789 /* We now know the position of everything in the file, except that
790 we don't know the size of the symbol table and therefore we don't
791 know where the string table starts. We just build the string
792 table in memory as we go along. We process all the relocations
793 for a single input file at once. */
794 obj_raw_syment_count (abfd) = 0;
796 if (coff_backend_info (abfd)->_bfd_coff_start_final_link)
798 if (! bfd_coff_start_final_link (abfd, info))
802 for (o = abfd->sections; o != NULL; o = o->next)
804 for (p = o->link_order_head; p != NULL; p = p->next)
806 if (p->type == bfd_indirect_link_order
807 && (bfd_get_flavour (p->u.indirect.section->owner)
808 == bfd_target_coff_flavour))
810 sub = p->u.indirect.section->owner;
811 if (! bfd_coff_link_output_has_begun (sub, & finfo))
813 if (! _bfd_coff_link_input_bfd (&finfo, sub))
815 sub->output_has_begun = true;
818 else if (p->type == bfd_section_reloc_link_order
819 || p->type == bfd_symbol_reloc_link_order)
821 if (! _bfd_coff_reloc_link_order (abfd, &finfo, o, p))
826 if (! _bfd_default_link_order (abfd, info, o, p))
832 if (! bfd_coff_final_link_postscript (abfd, & finfo))
835 /* Free up the buffers used by _bfd_coff_link_input_bfd. */
837 coff_debug_merge_hash_table_free (&finfo.debug_merge);
838 debug_merge_allocated = false;
840 if (finfo.internal_syms != NULL)
842 free (finfo.internal_syms);
843 finfo.internal_syms = NULL;
845 if (finfo.sec_ptrs != NULL)
847 free (finfo.sec_ptrs);
848 finfo.sec_ptrs = NULL;
850 if (finfo.sym_indices != NULL)
852 free (finfo.sym_indices);
853 finfo.sym_indices = NULL;
855 if (finfo.linenos != NULL)
857 free (finfo.linenos);
858 finfo.linenos = NULL;
860 if (finfo.contents != NULL)
862 free (finfo.contents);
863 finfo.contents = NULL;
865 if (finfo.external_relocs != NULL)
867 free (finfo.external_relocs);
868 finfo.external_relocs = NULL;
870 if (finfo.internal_relocs != NULL)
872 free (finfo.internal_relocs);
873 finfo.internal_relocs = NULL;
876 /* The value of the last C_FILE symbol is supposed to be the symbol
877 index of the first external symbol. Write it out again if
879 if (finfo.last_file_index != -1
880 && (unsigned int) finfo.last_file.n_value != obj_raw_syment_count (abfd))
882 finfo.last_file.n_value = obj_raw_syment_count (abfd);
883 bfd_coff_swap_sym_out (abfd, (PTR) &finfo.last_file,
884 (PTR) finfo.outsyms);
886 (obj_sym_filepos (abfd)
887 + finfo.last_file_index * symesz),
889 || bfd_write (finfo.outsyms, symesz, 1, abfd) != symesz)
893 /* If doing task linking (ld --task-link) then make a pass through the
894 global symbols, writing out any that are defined, and making them
898 finfo.failed = false;
899 coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_task_globals,
905 /* Write out the global symbols. */
906 finfo.failed = false;
907 coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym,
912 /* The outsyms buffer is used by _bfd_coff_write_global_sym. */
913 if (finfo.outsyms != NULL)
915 free (finfo.outsyms);
916 finfo.outsyms = NULL;
919 if (info->relocateable && max_output_reloc_count > 0)
921 /* Now that we have written out all the global symbols, we know
922 the symbol indices to use for relocs against them, and we can
923 finally write out the relocs. */
924 external_relocs = ((bfd_byte *)
925 bfd_malloc (max_output_reloc_count * relsz));
926 if (external_relocs == NULL)
929 for (o = abfd->sections; o != NULL; o = o->next)
931 struct internal_reloc *irel;
932 struct internal_reloc *irelend;
933 struct coff_link_hash_entry **rel_hash;
936 if (o->reloc_count == 0)
939 irel = finfo.section_info[o->target_index].relocs;
940 irelend = irel + o->reloc_count;
941 rel_hash = finfo.section_info[o->target_index].rel_hashes;
942 erel = external_relocs;
943 for (; irel < irelend; irel++, rel_hash++, erel += relsz)
945 if (*rel_hash != NULL)
947 BFD_ASSERT ((*rel_hash)->indx >= 0);
948 irel->r_symndx = (*rel_hash)->indx;
950 bfd_coff_swap_reloc_out (abfd, (PTR) irel, (PTR) erel);
953 if (bfd_seek (abfd, o->rel_filepos, SEEK_SET) != 0
954 || bfd_write ((PTR) external_relocs, relsz, o->reloc_count,
955 abfd) != relsz * o->reloc_count)
959 free (external_relocs);
960 external_relocs = NULL;
963 /* Free up the section information. */
964 if (finfo.section_info != NULL)
968 for (i = 0; i < abfd->section_count; i++)
970 if (finfo.section_info[i].relocs != NULL)
971 free (finfo.section_info[i].relocs);
972 if (finfo.section_info[i].rel_hashes != NULL)
973 free (finfo.section_info[i].rel_hashes);
975 free (finfo.section_info);
976 finfo.section_info = NULL;
979 /* If we have optimized stabs strings, output them. */
980 if (coff_hash_table (info)->stab_info != NULL)
982 if (! _bfd_write_stab_strings (abfd, &coff_hash_table (info)->stab_info))
986 /* Write out the string table. */
987 if (obj_raw_syment_count (abfd) != 0 || long_section_names)
990 (obj_sym_filepos (abfd)
991 + obj_raw_syment_count (abfd) * symesz),
995 #if STRING_SIZE_SIZE == 4
997 _bfd_stringtab_size (finfo.strtab) + STRING_SIZE_SIZE,
998 (bfd_byte *) strbuf);
1000 #error Change bfd_h_put_32
1003 if (bfd_write (strbuf, 1, STRING_SIZE_SIZE, abfd) != STRING_SIZE_SIZE)
1006 if (! _bfd_stringtab_emit (abfd, finfo.strtab))
1010 _bfd_stringtab_free (finfo.strtab);
1012 /* Setting bfd_get_symcount to 0 will cause write_object_contents to
1013 not try to write out the symbols. */
1014 bfd_get_symcount (abfd) = 0;
1019 if (debug_merge_allocated)
1020 coff_debug_merge_hash_table_free (&finfo.debug_merge);
1021 if (finfo.strtab != NULL)
1022 _bfd_stringtab_free (finfo.strtab);
1023 if (finfo.section_info != NULL)
1027 for (i = 0; i < abfd->section_count; i++)
1029 if (finfo.section_info[i].relocs != NULL)
1030 free (finfo.section_info[i].relocs);
1031 if (finfo.section_info[i].rel_hashes != NULL)
1032 free (finfo.section_info[i].rel_hashes);
1034 free (finfo.section_info);
1036 if (finfo.internal_syms != NULL)
1037 free (finfo.internal_syms);
1038 if (finfo.sec_ptrs != NULL)
1039 free (finfo.sec_ptrs);
1040 if (finfo.sym_indices != NULL)
1041 free (finfo.sym_indices);
1042 if (finfo.outsyms != NULL)
1043 free (finfo.outsyms);
1044 if (finfo.linenos != NULL)
1045 free (finfo.linenos);
1046 if (finfo.contents != NULL)
1047 free (finfo.contents);
1048 if (finfo.external_relocs != NULL)
1049 free (finfo.external_relocs);
1050 if (finfo.internal_relocs != NULL)
1051 free (finfo.internal_relocs);
1052 if (external_relocs != NULL)
1053 free (external_relocs);
1057 /* parse out a -heap <reserved>,<commit> line */
1060 dores_com (ptr, output_bfd, heap)
1065 if (coff_data(output_bfd)->pe)
1067 int val = strtoul (ptr, &ptr, 0);
1069 pe_data(output_bfd)->pe_opthdr.SizeOfHeapReserve =val;
1071 pe_data(output_bfd)->pe_opthdr.SizeOfStackReserve =val;
1075 int val = strtoul (ptr+1, &ptr, 0);
1077 pe_data(output_bfd)->pe_opthdr.SizeOfHeapCommit =val;
1079 pe_data(output_bfd)->pe_opthdr.SizeOfStackCommit =val;
1085 static char *get_name(ptr, dst)
1092 while (*ptr && *ptr != ' ')
1098 /* Process any magic embedded commands in a section called .drectve */
1101 process_embedded_commands (output_bfd, info, abfd)
1103 struct bfd_link_info *info ATTRIBUTE_UNUSED;
1106 asection *sec = bfd_get_section_by_name (abfd, ".drectve");
1113 copy = bfd_malloc ((size_t) sec->_raw_size);
1116 if (! bfd_get_section_contents(abfd, sec, copy, 0, sec->_raw_size))
1121 e = copy + sec->_raw_size;
1122 for (s = copy; s < e ; )
1128 if (strncmp (s,"-attr", 5) == 0)
1140 s = get_name(s, &name);
1141 s = get_name(s, &attribs);
1161 asec = bfd_get_section_by_name (abfd, name);
1164 asec->flags |= SEC_CODE;
1166 asec->flags |= SEC_READONLY;
1169 else if (strncmp (s,"-heap", 5) == 0)
1171 s = dores_com (s+5, output_bfd, 1);
1173 else if (strncmp (s,"-stack", 6) == 0)
1175 s = dores_com (s+6, output_bfd, 0);
1184 /* Place a marker against all symbols which are used by relocations.
1185 This marker can be picked up by the 'do we skip this symbol ?'
1186 loop in _bfd_coff_link_input_bfd() and used to prevent skipping
1191 mark_relocs (finfo, input_bfd)
1192 struct coff_final_link_info * finfo;
1197 if ((bfd_get_file_flags (input_bfd) & HAS_SYMS) == 0)
1200 for (a = input_bfd->sections; a != (asection *) NULL; a = a->next)
1202 struct internal_reloc * internal_relocs;
1203 struct internal_reloc * irel;
1204 struct internal_reloc * irelend;
1207 if ((a->flags & SEC_RELOC) == 0 || a->reloc_count < 1)
1210 /* Read in the relocs. */
1211 internal_relocs = _bfd_coff_read_internal_relocs
1212 (input_bfd, a, false,
1213 finfo->external_relocs,
1214 finfo->info->relocateable,
1215 (finfo->info->relocateable
1216 ? (finfo->section_info[ a->output_section->target_index ].relocs + a->output_section->reloc_count)
1217 : finfo->internal_relocs)
1220 if (internal_relocs == NULL)
1223 irel = internal_relocs;
1224 irelend = irel + a->reloc_count;
1226 /* Place a mark in the sym_indices array (whose entries have
1227 been initialised to 0) for all of the symbols that are used
1228 in the relocation table. This will then be picked up in the
1231 for (; irel < irelend; irel++)
1233 finfo->sym_indices[ irel->r_symndx ] = -1;
1238 /* Link an input file into the linker output file. This function
1239 handles all the sections and relocations of the input file at once. */
1242 _bfd_coff_link_input_bfd (finfo, input_bfd)
1243 struct coff_final_link_info *finfo;
1246 boolean (*sym_is_global) PARAMS ((bfd *, struct internal_syment *));
1247 boolean (*adjust_symndx) PARAMS ((bfd *, struct bfd_link_info *, bfd *,
1248 asection *, struct internal_reloc *,
1251 const char *strings;
1252 bfd_size_type syment_base;
1253 unsigned int n_tmask;
1254 unsigned int n_btshft;
1256 bfd_size_type isymesz;
1257 bfd_size_type osymesz;
1258 bfd_size_type linesz;
1261 struct internal_syment *isymp;
1264 unsigned long output_index;
1266 struct coff_link_hash_entry **sym_hash;
1269 /* Move all the symbols to the output file. */
1271 output_bfd = finfo->output_bfd;
1272 sym_is_global = coff_backend_info (input_bfd)->_bfd_coff_sym_is_global;
1274 syment_base = obj_raw_syment_count (output_bfd);
1275 isymesz = bfd_coff_symesz (input_bfd);
1276 osymesz = bfd_coff_symesz (output_bfd);
1277 linesz = bfd_coff_linesz (input_bfd);
1278 BFD_ASSERT (linesz == bfd_coff_linesz (output_bfd));
1280 n_tmask = coff_data (input_bfd)->local_n_tmask;
1281 n_btshft = coff_data (input_bfd)->local_n_btshft;
1283 /* Define macros so that ISFCN, et. al., macros work correctly. */
1284 #define N_TMASK n_tmask
1285 #define N_BTSHFT n_btshft
1288 if (! finfo->info->keep_memory)
1291 if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
1294 if (! _bfd_coff_get_external_symbols (input_bfd))
1297 esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
1298 esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
1299 isymp = finfo->internal_syms;
1300 secpp = finfo->sec_ptrs;
1301 indexp = finfo->sym_indices;
1302 output_index = syment_base;
1303 outsym = finfo->outsyms;
1305 if (coff_data (output_bfd)->pe)
1307 if (! process_embedded_commands (output_bfd, finfo->info, input_bfd))
1311 /* If we are going to perform relocations and also strip/discard some symbols
1312 then we must make sure that we do not strip/discard those symbols that are
1313 going to be involved in the relocations */
1314 if (( finfo->info->strip != strip_none
1315 || finfo->info->discard != discard_none)
1316 && finfo->info->relocateable)
1318 /* mark the symbol array as 'not-used' */
1319 memset (indexp, 0, obj_raw_syment_count (input_bfd) * sizeof * indexp);
1321 mark_relocs (finfo, input_bfd);
1324 while (esym < esym_end)
1326 struct internal_syment isym;
1329 boolean dont_skip_symbol;
1332 bfd_coff_swap_sym_in (input_bfd, (PTR) esym, (PTR) isymp);
1334 /* Make a copy of *isymp so that the relocate_section function
1335 always sees the original values. This is more reliable than
1336 always recomputing the symbol value even if we are stripping
1340 if (isym.n_scnum != 0)
1341 *secpp = coff_section_from_bfd_index (input_bfd, isym.n_scnum);
1344 if (isym.n_value == 0)
1345 *secpp = bfd_und_section_ptr;
1347 *secpp = bfd_com_section_ptr;
1350 /* Extract the flag indicating if this symbol is used by a
1352 if ((finfo->info->strip != strip_none
1353 || finfo->info->discard != discard_none)
1354 && finfo->info->relocateable)
1355 dont_skip_symbol = *indexp;
1357 dont_skip_symbol = false;
1363 add = 1 + isym.n_numaux;
1365 /* If we are stripping all symbols, we want to skip this one. */
1366 if (finfo->info->strip == strip_all && ! dont_skip_symbol)
1371 if (isym.n_sclass == C_EXT
1372 || isym.n_sclass == C_WEAKEXT
1373 || (obj_pe (input_bfd) && isym.n_sclass == C_NT_WEAK)
1375 || isym.n_sclass == C_SYSTEM
1377 || (sym_is_global && (*sym_is_global) (input_bfd, &isym)))
1379 /* This is a global symbol. Global symbols come at the
1380 end of the symbol table, so skip them for now.
1381 Locally defined function symbols, however, are an
1382 exception, and are not moved to the end. */
1384 if (! ISFCN (isym.n_type) || isym.n_scnum == 0)
1389 /* This is a local symbol. Skip it if we are discarding
1391 if (finfo->info->discard == discard_all && ! dont_skip_symbol)
1396 /* If we stripping debugging symbols, and this is a debugging
1397 symbol, then skip it. FIXME: gas sets the section to N_ABS
1398 for some types of debugging symbols; I don't know if this is
1399 a bug or not. In any case, we handle it here. */
1401 && finfo->info->strip == strip_debugger
1402 && ! dont_skip_symbol
1403 && (isym.n_scnum == N_DEBUG
1404 || (isym.n_scnum == N_ABS
1405 && (isym.n_sclass == C_AUTO
1406 || isym.n_sclass == C_REG
1407 || isym.n_sclass == C_MOS
1408 || isym.n_sclass == C_MOE
1409 || isym.n_sclass == C_MOU
1410 || isym.n_sclass == C_ARG
1411 || isym.n_sclass == C_REGPARM
1412 || isym.n_sclass == C_FIELD
1413 || isym.n_sclass == C_EOS))))
1416 /* If some symbols are stripped based on the name, work out the
1417 name and decide whether to skip this symbol. */
1419 && (finfo->info->strip == strip_some
1420 || finfo->info->discard == discard_l))
1423 char buf[SYMNMLEN + 1];
1425 name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
1429 if (! dont_skip_symbol
1430 && ((finfo->info->strip == strip_some
1431 && (bfd_hash_lookup (finfo->info->keep_hash, name, false,
1434 && finfo->info->discard == discard_l
1435 && bfd_is_local_label_name (input_bfd, name))))
1439 /* If this is an enum, struct, or union tag, see if we have
1440 already output an identical type. */
1442 && (finfo->output_bfd->flags & BFD_TRADITIONAL_FORMAT) == 0
1443 && (isym.n_sclass == C_ENTAG
1444 || isym.n_sclass == C_STRTAG
1445 || isym.n_sclass == C_UNTAG)
1446 && isym.n_numaux == 1)
1449 char buf[SYMNMLEN + 1];
1450 struct coff_debug_merge_hash_entry *mh;
1451 struct coff_debug_merge_type *mt;
1452 union internal_auxent aux;
1453 struct coff_debug_merge_element **epp;
1454 bfd_byte *esl, *eslend;
1455 struct internal_syment *islp;
1457 name = _bfd_coff_internal_syment_name (input_bfd, &isym, buf);
1461 /* Ignore fake names invented by compiler; treat them all as
1463 if (*name == '~' || *name == '.' || *name == '$'
1464 || (*name == bfd_get_symbol_leading_char (input_bfd)
1465 && (name[1] == '~' || name[1] == '.' || name[1] == '$')))
1468 mh = coff_debug_merge_hash_lookup (&finfo->debug_merge, name,
1473 /* Allocate memory to hold type information. If this turns
1474 out to be a duplicate, we pass this address to
1476 mt = ((struct coff_debug_merge_type *)
1477 bfd_alloc (input_bfd,
1478 sizeof (struct coff_debug_merge_type)));
1481 mt->class = isym.n_sclass;
1483 /* Pick up the aux entry, which points to the end of the tag
1485 bfd_coff_swap_aux_in (input_bfd, (PTR) (esym + isymesz),
1486 isym.n_type, isym.n_sclass, 0, isym.n_numaux,
1489 /* Gather the elements. */
1490 epp = &mt->elements;
1491 mt->elements = NULL;
1493 esl = esym + 2 * isymesz;
1494 eslend = ((bfd_byte *) obj_coff_external_syms (input_bfd)
1495 + aux.x_sym.x_fcnary.x_fcn.x_endndx.l * isymesz);
1496 while (esl < eslend)
1498 const char *elename;
1499 char elebuf[SYMNMLEN + 1];
1502 bfd_coff_swap_sym_in (input_bfd, (PTR) esl, (PTR) islp);
1504 *epp = ((struct coff_debug_merge_element *)
1505 bfd_alloc (input_bfd,
1506 sizeof (struct coff_debug_merge_element)));
1510 elename = _bfd_coff_internal_syment_name (input_bfd, islp,
1512 if (elename == NULL)
1515 copy = (char *) bfd_alloc (input_bfd, strlen (elename) + 1);
1518 strcpy (copy, elename);
1520 (*epp)->name = copy;
1521 (*epp)->type = islp->n_type;
1523 if (islp->n_numaux >= 1
1524 && islp->n_type != T_NULL
1525 && islp->n_sclass != C_EOS)
1527 union internal_auxent eleaux;
1530 bfd_coff_swap_aux_in (input_bfd, (PTR) (esl + isymesz),
1531 islp->n_type, islp->n_sclass, 0,
1532 islp->n_numaux, (PTR) &eleaux);
1533 indx = eleaux.x_sym.x_tagndx.l;
1535 /* FIXME: If this tagndx entry refers to a symbol
1536 defined later in this file, we just ignore it.
1537 Handling this correctly would be tedious, and may
1543 (bfd_byte *) obj_coff_external_syms (input_bfd))
1546 (*epp)->tagndx = finfo->sym_indices[indx];
1547 if ((*epp)->tagndx < 0)
1551 epp = &(*epp)->next;
1554 esl += (islp->n_numaux + 1) * isymesz;
1555 islp += islp->n_numaux + 1;
1558 /* See if we already have a definition which matches this
1559 type. We always output the type if it has no elements,
1561 if (mt->elements == NULL)
1562 bfd_release (input_bfd, (PTR) mt);
1565 struct coff_debug_merge_type *mtl;
1567 for (mtl = mh->types; mtl != NULL; mtl = mtl->next)
1569 struct coff_debug_merge_element *me, *mel;
1571 if (mtl->class != mt->class)
1574 for (me = mt->elements, mel = mtl->elements;
1575 me != NULL && mel != NULL;
1576 me = me->next, mel = mel->next)
1578 if (strcmp (me->name, mel->name) != 0
1579 || me->type != mel->type
1580 || me->tagndx != mel->tagndx)
1584 if (me == NULL && mel == NULL)
1588 if (mtl == NULL || (bfd_size_type) mtl->indx >= syment_base)
1590 /* This is the first definition of this type. */
1591 mt->indx = output_index;
1592 mt->next = mh->types;
1597 /* This is a redefinition which can be merged. */
1598 bfd_release (input_bfd, (PTR) mt);
1599 *indexp = mtl->indx;
1600 add = (eslend - esym) / isymesz;
1606 /* We now know whether we are to skip this symbol or not. */
1609 /* Adjust the symbol in order to output it. */
1611 if (isym._n._n_n._n_zeroes == 0
1612 && isym._n._n_n._n_offset != 0)
1617 /* This symbol has a long name. Enter it in the string
1618 table we are building. Note that we do not check
1619 bfd_coff_symname_in_debug. That is only true for
1620 XCOFF, and XCOFF requires different linking code
1622 name = _bfd_coff_internal_syment_name (input_bfd, &isym,
1626 indx = _bfd_stringtab_add (finfo->strtab, name, hash, copy);
1627 if (indx == (bfd_size_type) -1)
1629 isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
1632 if (isym.n_scnum > 0)
1634 isym.n_scnum = (*secpp)->output_section->target_index;
1635 isym.n_value += (*secpp)->output_offset;
1636 if (! obj_pe (input_bfd))
1637 isym.n_value -= (*secpp)->vma;
1638 if (! obj_pe (finfo->output_bfd))
1639 isym.n_value += (*secpp)->output_section->vma;
1642 /* The value of a C_FILE symbol is the symbol index of the
1643 next C_FILE symbol. The value of the last C_FILE symbol
1644 is the symbol index to the first external symbol
1645 (actually, coff_renumber_symbols does not get this
1646 right--it just sets the value of the last C_FILE symbol
1647 to zero--and nobody has ever complained about it). We
1648 try to get this right, below, just before we write the
1649 symbols out, but in the general case we may have to write
1650 the symbol out twice. */
1651 if (isym.n_sclass == C_FILE)
1653 if (finfo->last_file_index != -1
1654 && finfo->last_file.n_value != (long) output_index)
1656 /* We must correct the value of the last C_FILE entry. */
1657 finfo->last_file.n_value = output_index;
1658 if ((bfd_size_type) finfo->last_file_index >= syment_base)
1660 /* The last C_FILE symbol is in this input file. */
1661 bfd_coff_swap_sym_out (output_bfd,
1662 (PTR) &finfo->last_file,
1663 (PTR) (finfo->outsyms
1664 + ((finfo->last_file_index
1670 /* We have already written out the last C_FILE
1671 symbol. We need to write it out again. We
1672 borrow *outsym temporarily. */
1673 bfd_coff_swap_sym_out (output_bfd,
1674 (PTR) &finfo->last_file,
1676 if (bfd_seek (output_bfd,
1677 (obj_sym_filepos (output_bfd)
1678 + finfo->last_file_index * osymesz),
1680 || (bfd_write (outsym, osymesz, 1, output_bfd)
1686 finfo->last_file_index = output_index;
1687 finfo->last_file = isym;
1690 /* If doing task linking, convert normal global function symbols to
1691 static functions. */
1693 if (finfo->info->task_link
1694 && (isym.n_sclass == C_EXT
1695 || isym.n_sclass == C_WEAKEXT
1696 || (obj_pe (input_bfd) && isym.n_sclass == C_NT_WEAK)))
1697 isym.n_sclass = C_STAT;
1699 /* Output the symbol. */
1701 bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) outsym);
1703 *indexp = output_index;
1708 struct coff_link_hash_entry *h;
1710 indx = ((esym - (bfd_byte *) obj_coff_external_syms (input_bfd))
1712 h = obj_coff_sym_hashes (input_bfd)[indx];
1715 /* This can happen if there were errors earlier in
1717 bfd_set_error (bfd_error_bad_value);
1720 h->indx = output_index;
1723 output_index += add;
1724 outsym += add * osymesz;
1727 esym += add * isymesz;
1731 for (--add; add > 0; --add)
1738 /* Fix up the aux entries. This must be done in a separate pass,
1739 because we don't know the correct symbol indices until we have
1740 already decided which symbols we are going to keep. */
1742 esym = (bfd_byte *) obj_coff_external_syms (input_bfd);
1743 esym_end = esym + obj_raw_syment_count (input_bfd) * isymesz;
1744 isymp = finfo->internal_syms;
1745 indexp = finfo->sym_indices;
1746 sym_hash = obj_coff_sym_hashes (input_bfd);
1747 outsym = finfo->outsyms;
1748 while (esym < esym_end)
1752 add = 1 + isymp->n_numaux;
1755 || (bfd_size_type) *indexp < syment_base)
1756 && (*sym_hash == NULL
1757 || (*sym_hash)->auxbfd != input_bfd))
1758 esym += add * isymesz;
1761 struct coff_link_hash_entry *h;
1769 /* The m68k-motorola-sysv assembler will sometimes
1770 generate two symbols with the same name, but only one
1771 will have aux entries. */
1772 BFD_ASSERT (isymp->n_numaux == 0
1773 || h->numaux == isymp->n_numaux);
1781 /* Handle the aux entries. This handling is based on
1782 coff_pointerize_aux. I don't know if it always correct. */
1783 for (i = 0; i < isymp->n_numaux && esym < esym_end; i++)
1785 union internal_auxent aux;
1786 union internal_auxent *auxp;
1792 bfd_coff_swap_aux_in (input_bfd, (PTR) esym, isymp->n_type,
1793 isymp->n_sclass, i, isymp->n_numaux,
1798 if (isymp->n_sclass == C_FILE)
1800 /* If this is a long filename, we must put it in the
1802 if (auxp->x_file.x_n.x_zeroes == 0
1803 && auxp->x_file.x_n.x_offset != 0)
1805 const char *filename;
1808 BFD_ASSERT (auxp->x_file.x_n.x_offset
1809 >= STRING_SIZE_SIZE);
1810 if (strings == NULL)
1812 strings = _bfd_coff_read_string_table (input_bfd);
1813 if (strings == NULL)
1816 filename = strings + auxp->x_file.x_n.x_offset;
1817 indx = _bfd_stringtab_add (finfo->strtab, filename,
1819 if (indx == (bfd_size_type) -1)
1821 auxp->x_file.x_n.x_offset = STRING_SIZE_SIZE + indx;
1824 else if (isymp->n_sclass != C_STAT || isymp->n_type != T_NULL)
1828 if (ISFCN (isymp->n_type)
1829 || ISTAG (isymp->n_sclass)
1830 || isymp->n_sclass == C_BLOCK
1831 || isymp->n_sclass == C_FCN)
1833 indx = auxp->x_sym.x_fcnary.x_fcn.x_endndx.l;
1835 && indx < obj_raw_syment_count (input_bfd))
1837 /* We look forward through the symbol for
1838 the index of the next symbol we are going
1839 to include. I don't know if this is
1841 while ((finfo->sym_indices[indx] < 0
1842 || ((bfd_size_type) finfo->sym_indices[indx]
1844 && indx < obj_raw_syment_count (input_bfd))
1846 if (indx >= obj_raw_syment_count (input_bfd))
1847 indx = output_index;
1849 indx = finfo->sym_indices[indx];
1850 auxp->x_sym.x_fcnary.x_fcn.x_endndx.l = indx;
1854 indx = auxp->x_sym.x_tagndx.l;
1855 if (indx > 0 && indx < obj_raw_syment_count (input_bfd))
1859 symindx = finfo->sym_indices[indx];
1861 auxp->x_sym.x_tagndx.l = 0;
1863 auxp->x_sym.x_tagndx.l = symindx;
1866 /* The .bf symbols are supposed to be linked through
1867 the endndx field. We need to carry this list
1868 across object files. */
1871 && isymp->n_sclass == C_FCN
1872 && (isymp->_n._n_n._n_zeroes != 0
1873 || isymp->_n._n_n._n_offset == 0)
1874 && isymp->_n._n_name[0] == '.'
1875 && isymp->_n._n_name[1] == 'b'
1876 && isymp->_n._n_name[2] == 'f'
1877 && isymp->_n._n_name[3] == '\0')
1879 if (finfo->last_bf_index != -1)
1881 finfo->last_bf.x_sym.x_fcnary.x_fcn.x_endndx.l =
1884 if ((bfd_size_type) finfo->last_bf_index
1889 /* The last .bf symbol is in this input
1890 file. This will only happen if the
1891 assembler did not set up the .bf
1892 endndx symbols correctly. */
1893 auxout = (PTR) (finfo->outsyms
1894 + ((finfo->last_bf_index
1897 bfd_coff_swap_aux_out (output_bfd,
1898 (PTR) &finfo->last_bf,
1906 /* We have already written out the last
1907 .bf aux entry. We need to write it
1908 out again. We borrow *outsym
1909 temporarily. FIXME: This case should
1911 bfd_coff_swap_aux_out (output_bfd,
1912 (PTR) &finfo->last_bf,
1917 if (bfd_seek (output_bfd,
1918 (obj_sym_filepos (output_bfd)
1919 + finfo->last_bf_index * osymesz),
1921 || bfd_write (outsym, osymesz, 1,
1922 output_bfd) != osymesz)
1927 if (auxp->x_sym.x_fcnary.x_fcn.x_endndx.l != 0)
1928 finfo->last_bf_index = -1;
1931 /* The endndx field of this aux entry must
1932 be updated with the symbol number of the
1934 finfo->last_bf = *auxp;
1935 finfo->last_bf_index = (((outsym - finfo->outsyms)
1944 bfd_coff_swap_aux_out (output_bfd, (PTR) auxp, isymp->n_type,
1945 isymp->n_sclass, i, isymp->n_numaux,
1959 /* Relocate the line numbers, unless we are stripping them. */
1960 if (finfo->info->strip == strip_none
1961 || finfo->info->strip == strip_some)
1963 for (o = input_bfd->sections; o != NULL; o = o->next)
1969 /* FIXME: If SEC_HAS_CONTENTS is not for the section, then
1970 build_link_order in ldwrite.c will not have created a
1971 link order, which means that we will not have seen this
1972 input section in _bfd_coff_final_link, which means that
1973 we will not have allocated space for the line numbers of
1974 this section. I don't think line numbers can be
1975 meaningful for a section which does not have
1976 SEC_HAS_CONTENTS set, but, if they do, this must be
1978 if (o->lineno_count == 0
1979 || (o->output_section->flags & SEC_HAS_CONTENTS) == 0)
1982 if (bfd_seek (input_bfd, o->line_filepos, SEEK_SET) != 0
1983 || bfd_read (finfo->linenos, linesz, o->lineno_count,
1984 input_bfd) != linesz * o->lineno_count)
1987 offset = o->output_section->vma + o->output_offset - o->vma;
1988 eline = finfo->linenos;
1989 elineend = eline + linesz * o->lineno_count;
1990 for (; eline < elineend; eline += linesz)
1992 struct internal_lineno iline;
1994 bfd_coff_swap_lineno_in (input_bfd, (PTR) eline, (PTR) &iline);
1996 if (iline.l_lnno != 0)
1997 iline.l_addr.l_paddr += offset;
1998 else if (iline.l_addr.l_symndx >= 0
1999 && ((unsigned long) iline.l_addr.l_symndx
2000 < obj_raw_syment_count (input_bfd)))
2004 indx = finfo->sym_indices[iline.l_addr.l_symndx];
2008 /* These line numbers are attached to a symbol
2009 which we are stripping. We should really
2010 just discard the line numbers, but that would
2011 be a pain because we have already counted
2017 struct internal_syment is;
2018 union internal_auxent ia;
2020 /* Fix up the lnnoptr field in the aux entry of
2021 the symbol. It turns out that we can't do
2022 this when we modify the symbol aux entries,
2023 because gas sometimes screws up the lnnoptr
2024 field and makes it an offset from the start
2025 of the line numbers rather than an absolute
2027 bfd_coff_swap_sym_in (output_bfd,
2028 (PTR) (finfo->outsyms
2029 + ((indx - syment_base)
2032 if ((ISFCN (is.n_type)
2033 || is.n_sclass == C_BLOCK)
2034 && is.n_numaux >= 1)
2038 auxptr = (PTR) (finfo->outsyms
2039 + ((indx - syment_base + 1)
2041 bfd_coff_swap_aux_in (output_bfd, auxptr,
2042 is.n_type, is.n_sclass,
2043 0, is.n_numaux, (PTR) &ia);
2044 ia.x_sym.x_fcnary.x_fcn.x_lnnoptr =
2045 (o->output_section->line_filepos
2046 + o->output_section->lineno_count * linesz
2047 + eline - finfo->linenos);
2048 bfd_coff_swap_aux_out (output_bfd, (PTR) &ia,
2049 is.n_type, is.n_sclass, 0,
2050 is.n_numaux, auxptr);
2054 iline.l_addr.l_symndx = indx;
2057 bfd_coff_swap_lineno_out (output_bfd, (PTR) &iline, (PTR) eline);
2060 if (bfd_seek (output_bfd,
2061 (o->output_section->line_filepos
2062 + o->output_section->lineno_count * linesz),
2064 || bfd_write (finfo->linenos, linesz, o->lineno_count,
2065 output_bfd) != linesz * o->lineno_count)
2068 o->output_section->lineno_count += o->lineno_count;
2072 /* If we swapped out a C_FILE symbol, guess that the next C_FILE
2073 symbol will be the first symbol in the next input file. In the
2074 normal case, this will save us from writing out the C_FILE symbol
2076 if (finfo->last_file_index != -1
2077 && (bfd_size_type) finfo->last_file_index >= syment_base)
2079 finfo->last_file.n_value = output_index;
2080 bfd_coff_swap_sym_out (output_bfd, (PTR) &finfo->last_file,
2081 (PTR) (finfo->outsyms
2082 + ((finfo->last_file_index - syment_base)
2086 /* Write the modified symbols to the output file. */
2087 if (outsym > finfo->outsyms)
2089 if (bfd_seek (output_bfd,
2090 obj_sym_filepos (output_bfd) + syment_base * osymesz,
2092 || (bfd_write (finfo->outsyms, outsym - finfo->outsyms, 1,
2094 != (bfd_size_type) (outsym - finfo->outsyms)))
2097 BFD_ASSERT ((obj_raw_syment_count (output_bfd)
2098 + (outsym - finfo->outsyms) / osymesz)
2101 obj_raw_syment_count (output_bfd) = output_index;
2104 /* Relocate the contents of each section. */
2105 adjust_symndx = coff_backend_info (input_bfd)->_bfd_coff_adjust_symndx;
2106 for (o = input_bfd->sections; o != NULL; o = o->next)
2109 struct coff_section_tdata *secdata;
2111 if (! o->linker_mark)
2113 /* This section was omitted from the link. */
2117 if ((o->flags & SEC_HAS_CONTENTS) == 0
2118 || (o->_raw_size == 0 && (o->flags & SEC_RELOC) == 0))
2120 if ((o->flags & SEC_RELOC) != 0
2121 && o->reloc_count != 0)
2123 ((*_bfd_error_handler)
2124 (_("%s: relocs in section `%s', but it has no contents"),
2125 bfd_get_filename (input_bfd),
2126 bfd_get_section_name (input_bfd, o)));
2127 bfd_set_error (bfd_error_no_contents);
2134 secdata = coff_section_data (input_bfd, o);
2135 if (secdata != NULL && secdata->contents != NULL)
2136 contents = secdata->contents;
2139 if (! bfd_get_section_contents (input_bfd, o, finfo->contents,
2140 (file_ptr) 0, o->_raw_size))
2142 contents = finfo->contents;
2145 if ((o->flags & SEC_RELOC) != 0)
2148 struct internal_reloc *internal_relocs;
2149 struct internal_reloc *irel;
2151 /* Read in the relocs. */
2152 target_index = o->output_section->target_index;
2153 internal_relocs = (_bfd_coff_read_internal_relocs
2154 (input_bfd, o, false, finfo->external_relocs,
2155 finfo->info->relocateable,
2156 (finfo->info->relocateable
2157 ? (finfo->section_info[target_index].relocs
2158 + o->output_section->reloc_count)
2159 : finfo->internal_relocs)));
2160 if (internal_relocs == NULL)
2163 /* Call processor specific code to relocate the section
2165 if (! bfd_coff_relocate_section (output_bfd, finfo->info,
2169 finfo->internal_syms,
2173 if (finfo->info->relocateable)
2176 struct internal_reloc *irelend;
2177 struct coff_link_hash_entry **rel_hash;
2179 offset = o->output_section->vma + o->output_offset - o->vma;
2180 irel = internal_relocs;
2181 irelend = irel + o->reloc_count;
2182 rel_hash = (finfo->section_info[target_index].rel_hashes
2183 + o->output_section->reloc_count);
2184 for (; irel < irelend; irel++, rel_hash++)
2186 struct coff_link_hash_entry *h;
2191 /* Adjust the reloc address and symbol index. */
2193 irel->r_vaddr += offset;
2195 if (irel->r_symndx == -1)
2200 if (! (*adjust_symndx) (output_bfd, finfo->info,
2208 h = obj_coff_sym_hashes (input_bfd)[irel->r_symndx];
2211 /* This is a global symbol. */
2213 irel->r_symndx = h->indx;
2216 /* This symbol is being written at the end
2217 of the file, and we do not yet know the
2218 symbol index. We save the pointer to the
2219 hash table entry in the rel_hash list.
2220 We set the indx field to -2 to indicate
2221 that this symbol must not be stripped. */
2230 indx = finfo->sym_indices[irel->r_symndx];
2232 irel->r_symndx = indx;
2235 struct internal_syment *is;
2237 char buf[SYMNMLEN + 1];
2239 /* This reloc is against a symbol we are
2240 stripping. This should have been handled
2241 by the 'dont_skip_symbol' code in the while
2242 loop at the top of this function. */
2244 is = finfo->internal_syms + irel->r_symndx;
2246 name = (_bfd_coff_internal_syment_name
2247 (input_bfd, is, buf));
2251 if (! ((*finfo->info->callbacks->unattached_reloc)
2252 (finfo->info, name, input_bfd, o,
2259 o->output_section->reloc_count += o->reloc_count;
2263 /* Write out the modified section contents. */
2264 if (secdata == NULL || secdata->stab_info == NULL)
2266 if (! bfd_set_section_contents (output_bfd, o->output_section,
2267 contents, o->output_offset,
2268 (o->_cooked_size != 0
2275 if (! (_bfd_write_section_stabs
2276 (output_bfd, &coff_hash_table (finfo->info)->stab_info,
2277 o, &secdata->stab_info, contents)))
2282 if (! finfo->info->keep_memory)
2284 if (! _bfd_coff_free_symbols (input_bfd))
2291 /* Write out a global symbol. Called via coff_link_hash_traverse. */
2294 _bfd_coff_write_global_sym (h, data)
2295 struct coff_link_hash_entry *h;
2298 struct coff_final_link_info *finfo = (struct coff_final_link_info *) data;
2300 struct internal_syment isym;
2301 bfd_size_type symesz;
2304 output_bfd = finfo->output_bfd;
2310 && (finfo->info->strip == strip_all
2311 || (finfo->info->strip == strip_some
2312 && (bfd_hash_lookup (finfo->info->keep_hash,
2313 h->root.root.string, false, false)
2317 switch (h->root.type)
2320 case bfd_link_hash_new:
2324 case bfd_link_hash_undefined:
2325 case bfd_link_hash_undefweak:
2326 isym.n_scnum = N_UNDEF;
2330 case bfd_link_hash_defined:
2331 case bfd_link_hash_defweak:
2335 sec = h->root.u.def.section->output_section;
2336 if (bfd_is_abs_section (sec))
2337 isym.n_scnum = N_ABS;
2339 isym.n_scnum = sec->target_index;
2340 isym.n_value = (h->root.u.def.value
2341 + h->root.u.def.section->output_offset);
2342 if (! obj_pe (finfo->output_bfd))
2343 isym.n_value += sec->vma;
2347 case bfd_link_hash_common:
2348 isym.n_scnum = N_UNDEF;
2349 isym.n_value = h->root.u.c.size;
2352 case bfd_link_hash_indirect:
2353 case bfd_link_hash_warning:
2354 /* Just ignore these. They can't be handled anyhow. */
2358 if (strlen (h->root.root.string) <= SYMNMLEN)
2359 strncpy (isym._n._n_name, h->root.root.string, SYMNMLEN);
2366 if ((output_bfd->flags & BFD_TRADITIONAL_FORMAT) != 0)
2368 indx = _bfd_stringtab_add (finfo->strtab, h->root.root.string, hash,
2370 if (indx == (bfd_size_type) -1)
2372 finfo->failed = true;
2375 isym._n._n_n._n_zeroes = 0;
2376 isym._n._n_n._n_offset = STRING_SIZE_SIZE + indx;
2379 isym.n_sclass = h->class;
2380 isym.n_type = h->type;
2382 if (isym.n_sclass == C_NULL)
2383 isym.n_sclass = C_EXT;
2385 /* If doing task linking and this is the pass where we convert
2386 defined globals to statics, then do that conversion now. If the
2387 symbol is not being converted, just ignore it and it will be
2388 output during a later pass. */
2389 if (finfo->global_to_static)
2391 if (isym.n_sclass != C_EXT
2392 && isym.n_sclass != C_WEAKEXT
2393 && (! obj_pe (output_bfd) || isym.n_sclass != C_NT_WEAK))
2397 isym.n_sclass = C_STAT;
2400 isym.n_numaux = h->numaux;
2402 bfd_coff_swap_sym_out (output_bfd, (PTR) &isym, (PTR) finfo->outsyms);
2404 symesz = bfd_coff_symesz (output_bfd);
2406 if (bfd_seek (output_bfd,
2407 (obj_sym_filepos (output_bfd)
2408 + obj_raw_syment_count (output_bfd) * symesz),
2410 || bfd_write (finfo->outsyms, symesz, 1, output_bfd) != symesz)
2412 finfo->failed = true;
2416 h->indx = obj_raw_syment_count (output_bfd);
2418 ++obj_raw_syment_count (output_bfd);
2420 /* Write out any associated aux entries. There normally will be
2421 none. If there are any, I have no idea how to modify them. */
2422 for (i = 0; i < isym.n_numaux; i++)
2424 bfd_coff_swap_aux_out (output_bfd, (PTR) (h->aux + i), isym.n_type,
2425 isym.n_sclass, i, isym.n_numaux,
2426 (PTR) finfo->outsyms);
2427 if (bfd_write (finfo->outsyms, symesz, 1, output_bfd) != symesz)
2429 finfo->failed = true;
2432 ++obj_raw_syment_count (output_bfd);
2438 /* Write out task global symbols, converting them to statics. Called
2439 via coff_link_hash_traverse. Calls bfd_coff_write_global_sym to do
2440 the dirty work, if the symbol we are processing needs conversion. */
2443 _bfd_coff_write_task_globals (h, data)
2444 struct coff_link_hash_entry *h;
2447 struct coff_final_link_info *finfo = (struct coff_final_link_info *) data;
2448 boolean rtnval = true;
2449 boolean save_global_to_static;
2453 switch (h->root.type)
2455 case bfd_link_hash_defined:
2456 case bfd_link_hash_defweak:
2457 save_global_to_static = finfo->global_to_static;
2458 finfo->global_to_static = true;
2459 rtnval = _bfd_coff_write_global_sym (h, data);
2460 finfo->global_to_static = save_global_to_static;
2469 /* Handle a link order which is supposed to generate a reloc. */
2472 _bfd_coff_reloc_link_order (output_bfd, finfo, output_section, link_order)
2474 struct coff_final_link_info *finfo;
2475 asection *output_section;
2476 struct bfd_link_order *link_order;
2478 reloc_howto_type *howto;
2479 struct internal_reloc *irel;
2480 struct coff_link_hash_entry **rel_hash_ptr;
2482 howto = bfd_reloc_type_lookup (output_bfd, link_order->u.reloc.p->reloc);
2485 bfd_set_error (bfd_error_bad_value);
2489 if (link_order->u.reloc.p->addend != 0)
2493 bfd_reloc_status_type rstat;
2496 size = bfd_get_reloc_size (howto);
2497 buf = (bfd_byte *) bfd_zmalloc (size);
2501 rstat = _bfd_relocate_contents (howto, output_bfd,
2502 link_order->u.reloc.p->addend, buf);
2508 case bfd_reloc_outofrange:
2510 case bfd_reloc_overflow:
2511 if (! ((*finfo->info->callbacks->reloc_overflow)
2513 (link_order->type == bfd_section_reloc_link_order
2514 ? bfd_section_name (output_bfd,
2515 link_order->u.reloc.p->u.section)
2516 : link_order->u.reloc.p->u.name),
2517 howto->name, link_order->u.reloc.p->addend,
2518 (bfd *) NULL, (asection *) NULL, (bfd_vma) 0)))
2525 ok = bfd_set_section_contents (output_bfd, output_section, (PTR) buf,
2526 (file_ptr) link_order->offset, size);
2532 /* Store the reloc information in the right place. It will get
2533 swapped and written out at the end of the final_link routine. */
2535 irel = (finfo->section_info[output_section->target_index].relocs
2536 + output_section->reloc_count);
2537 rel_hash_ptr = (finfo->section_info[output_section->target_index].rel_hashes
2538 + output_section->reloc_count);
2540 memset (irel, 0, sizeof (struct internal_reloc));
2541 *rel_hash_ptr = NULL;
2543 irel->r_vaddr = output_section->vma + link_order->offset;
2545 if (link_order->type == bfd_section_reloc_link_order)
2547 /* We need to somehow locate a symbol in the right section. The
2548 symbol must either have a value of zero, or we must adjust
2549 the addend by the value of the symbol. FIXME: Write this
2550 when we need it. The old linker couldn't handle this anyhow. */
2552 *rel_hash_ptr = NULL;
2557 struct coff_link_hash_entry *h;
2559 h = ((struct coff_link_hash_entry *)
2560 bfd_wrapped_link_hash_lookup (output_bfd, finfo->info,
2561 link_order->u.reloc.p->u.name,
2562 false, false, true));
2566 irel->r_symndx = h->indx;
2569 /* Set the index to -2 to force this symbol to get
2578 if (! ((*finfo->info->callbacks->unattached_reloc)
2579 (finfo->info, link_order->u.reloc.p->u.name, (bfd *) NULL,
2580 (asection *) NULL, (bfd_vma) 0)))
2586 /* FIXME: Is this always right? */
2587 irel->r_type = howto->type;
2589 /* r_size is only used on the RS/6000, which needs its own linker
2590 routines anyhow. r_extern is only used for ECOFF. */
2592 /* FIXME: What is the right value for r_offset? Is zero OK? */
2594 ++output_section->reloc_count;
2599 /* A basic reloc handling routine which may be used by processors with
2603 _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd,
2604 input_section, contents, relocs, syms,
2607 struct bfd_link_info *info;
2609 asection *input_section;
2611 struct internal_reloc *relocs;
2612 struct internal_syment *syms;
2613 asection **sections;
2615 struct internal_reloc *rel;
2616 struct internal_reloc *relend;
2619 relend = rel + input_section->reloc_count;
2620 for (; rel < relend; rel++)
2623 struct coff_link_hash_entry *h;
2624 struct internal_syment *sym;
2627 reloc_howto_type *howto;
2628 bfd_reloc_status_type rstat;
2630 symndx = rel->r_symndx;
2638 || (unsigned long) symndx >= obj_raw_syment_count (input_bfd))
2640 (*_bfd_error_handler)
2641 ("%s: illegal symbol index %ld in relocs",
2642 bfd_get_filename (input_bfd), symndx);
2647 h = obj_coff_sym_hashes (input_bfd)[symndx];
2648 sym = syms + symndx;
2651 /* COFF treats common symbols in one of two ways. Either the
2652 size of the symbol is included in the section contents, or it
2653 is not. We assume that the size is not included, and force
2654 the rtype_to_howto function to adjust the addend as needed. */
2656 if (sym != NULL && sym->n_scnum != 0)
2657 addend = - sym->n_value;
2662 howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h,
2667 /* If we are doing a relocateable link, then we can just ignore
2668 a PC relative reloc that is pcrel_offset. It will already
2669 have the correct value. If this is not a relocateable link,
2670 then we should ignore the symbol value. */
2671 if (howto->pc_relative && howto->pcrel_offset)
2673 if (info->relocateable)
2675 if (sym != NULL && sym->n_scnum != 0)
2676 addend += sym->n_value;
2687 sec = bfd_abs_section_ptr;
2692 sec = sections[symndx];
2693 val = (sec->output_section->vma
2694 + sec->output_offset
2696 if (! obj_pe (input_bfd))
2702 if (h->root.type == bfd_link_hash_defined
2703 || h->root.type == bfd_link_hash_defweak)
2707 sec = h->root.u.def.section;
2708 val = (h->root.u.def.value
2709 + sec->output_section->vma
2710 + sec->output_offset);
2713 else if (! info->relocateable)
2715 if (! ((*info->callbacks->undefined_symbol)
2716 (info, h->root.root.string, input_bfd, input_section,
2717 rel->r_vaddr - input_section->vma)))
2722 if (info->base_file)
2724 /* Emit a reloc if the backend thinks it needs it. */
2725 if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto))
2727 /* Relocation to a symbol in a section which isn't
2728 absolute. We output the address here to a file.
2729 This file is then read by dlltool when generating the
2730 reloc section. Note that the base file is not
2731 portable between systems. We write out a long here,
2732 and dlltool reads in a long. */
2733 long addr = (rel->r_vaddr
2734 - input_section->vma
2735 + input_section->output_offset
2736 + input_section->output_section->vma);
2737 if (coff_data (output_bfd)->pe)
2738 addr -= pe_data(output_bfd)->pe_opthdr.ImageBase;
2739 if (fwrite (&addr, 1, sizeof (long), (FILE *) info->base_file)
2742 bfd_set_error (bfd_error_system_call);
2748 rstat = _bfd_final_link_relocate (howto, input_bfd, input_section,
2750 rel->r_vaddr - input_section->vma,
2759 case bfd_reloc_outofrange:
2760 (*_bfd_error_handler)
2761 (_("%s: bad reloc address 0x%lx in section `%s'"),
2762 bfd_get_filename (input_bfd),
2763 (unsigned long) rel->r_vaddr,
2764 bfd_get_section_name (input_bfd, input_section));
2766 case bfd_reloc_overflow:
2769 char buf[SYMNMLEN + 1];
2774 name = h->root.root.string;
2777 name = _bfd_coff_internal_syment_name (input_bfd, sym, buf);
2782 if (! ((*info->callbacks->reloc_overflow)
2783 (info, name, howto->name, (bfd_vma) 0, input_bfd,
2784 input_section, rel->r_vaddr - input_section->vma)))