1 /* Support for the generic parts of COFF, for BFD.
2 Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
5 Written by Cygnus Support.
7 This file is part of BFD, the Binary File Descriptor library.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 /* Most of this hacked by Steve Chamberlain, sac@cygnus.com.
24 Split out of coffcode.h by Ian Taylor, ian@cygnus.com. */
26 /* This file contains COFF code that is not dependent on any
27 particular COFF target. There is only one version of this file in
28 libbfd.a, so no target specific code may be put in here. Or, to
31 ********** DO NOT PUT TARGET SPECIFIC CODE IN THIS FILE **********
33 If you need to add some target specific behaviour, add a new hook
34 function to bfd_coff_backend_data.
36 Some of these functions are also called by the ECOFF routines.
37 Those functions may not use any COFF specific information, such as
43 #include "coff/internal.h"
46 static void coff_fix_symbol_name
47 PARAMS ((bfd
*, asymbol
*, combined_entry_type
*, bfd_size_type
*,
48 asection
**, bfd_size_type
*));
49 static bfd_boolean coff_write_symbol
50 PARAMS ((bfd
*, asymbol
*, combined_entry_type
*, bfd_vma
*,
51 bfd_size_type
*, asection
**, bfd_size_type
*));
52 static bfd_boolean coff_write_alien_symbol
53 PARAMS ((bfd
*, asymbol
*, bfd_vma
*, bfd_size_type
*,
54 asection
**, bfd_size_type
*));
55 static bfd_boolean coff_write_native_symbol
56 PARAMS ((bfd
*, coff_symbol_type
*, bfd_vma
*, bfd_size_type
*,
57 asection
**, bfd_size_type
*));
58 static void coff_pointerize_aux
59 PARAMS ((bfd
*, combined_entry_type
*, combined_entry_type
*,
60 unsigned int, combined_entry_type
*));
61 static bfd_boolean make_a_section_from_file
62 PARAMS ((bfd
*, struct internal_scnhdr
*, unsigned int));
63 static const bfd_target
*coff_real_object_p
64 PARAMS ((bfd
*, unsigned, struct internal_filehdr
*,
65 struct internal_aouthdr
*));
66 static void fixup_symbol_value
67 PARAMS ((bfd
*, coff_symbol_type
*, struct internal_syment
*));
68 static char *build_debug_section
70 static char *copy_name
71 PARAMS ((bfd
*, char *, size_t));
73 #define STRING_SIZE_SIZE (4)
75 /* Take a section header read from a coff file (in HOST byte order),
76 and make a BFD "section" out of it. This is used by ECOFF. */
78 make_a_section_from_file (abfd
, hdr
, target_index
)
80 struct internal_scnhdr
*hdr
;
81 unsigned int target_index
;
83 asection
*return_section
;
85 bfd_boolean result
= TRUE
;
90 /* Handle long section names as in PE. */
91 if (bfd_coff_long_section_names (abfd
)
92 && hdr
->s_name
[0] == '/')
99 memcpy (buf
, hdr
->s_name
+ 1, SCNNMLEN
- 1);
100 buf
[SCNNMLEN
- 1] = '\0';
101 strindex
= strtol (buf
, &p
, 10);
102 if (*p
== '\0' && strindex
>= 0)
104 strings
= _bfd_coff_read_string_table (abfd
);
107 /* FIXME: For extra safety, we should make sure that
108 strindex does not run us past the end, but right now we
109 don't know the length of the string table. */
111 name
= bfd_alloc (abfd
, (bfd_size_type
) strlen (strings
) + 1);
114 strcpy (name
, strings
);
120 /* Assorted wastage to null-terminate the name, thanks AT&T! */
121 name
= bfd_alloc (abfd
, (bfd_size_type
) sizeof (hdr
->s_name
) + 1);
124 strncpy (name
, (char *) &hdr
->s_name
[0], sizeof (hdr
->s_name
));
125 name
[sizeof (hdr
->s_name
)] = 0;
128 return_section
= bfd_make_section_anyway (abfd
, name
);
129 if (return_section
== NULL
)
132 return_section
->vma
= hdr
->s_vaddr
;
133 return_section
->lma
= hdr
->s_paddr
;
134 return_section
->size
= hdr
->s_size
;
135 return_section
->filepos
= hdr
->s_scnptr
;
136 return_section
->rel_filepos
= hdr
->s_relptr
;
137 return_section
->reloc_count
= hdr
->s_nreloc
;
139 bfd_coff_set_alignment_hook (abfd
, return_section
, hdr
);
141 return_section
->line_filepos
= hdr
->s_lnnoptr
;
143 return_section
->lineno_count
= hdr
->s_nlnno
;
144 return_section
->userdata
= NULL
;
145 return_section
->next
= (asection
*) NULL
;
146 return_section
->target_index
= target_index
;
148 if (! bfd_coff_styp_to_sec_flags_hook (abfd
, hdr
, name
, return_section
,
152 return_section
->flags
= flags
;
154 /* At least on i386-coff, the line number count for a shared library
155 section must be ignored. */
156 if ((return_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
157 return_section
->lineno_count
= 0;
159 if (hdr
->s_nreloc
!= 0)
160 return_section
->flags
|= SEC_RELOC
;
161 /* FIXME: should this check 'hdr->s_size > 0' */
162 if (hdr
->s_scnptr
!= 0)
163 return_section
->flags
|= SEC_HAS_CONTENTS
;
168 /* Read in a COFF object and make it into a BFD. This is used by
171 static const bfd_target
*
172 coff_real_object_p (abfd
, nscns
, internal_f
, internal_a
)
175 struct internal_filehdr
*internal_f
;
176 struct internal_aouthdr
*internal_a
;
178 flagword oflags
= abfd
->flags
;
179 bfd_vma ostart
= bfd_get_start_address (abfd
);
182 bfd_size_type readsize
; /* length of file_info */
184 char *external_sections
;
186 if (!(internal_f
->f_flags
& F_RELFLG
))
187 abfd
->flags
|= HAS_RELOC
;
188 if ((internal_f
->f_flags
& F_EXEC
))
189 abfd
->flags
|= EXEC_P
;
190 if (!(internal_f
->f_flags
& F_LNNO
))
191 abfd
->flags
|= HAS_LINENO
;
192 if (!(internal_f
->f_flags
& F_LSYMS
))
193 abfd
->flags
|= HAS_LOCALS
;
195 /* FIXME: How can we set D_PAGED correctly? */
196 if ((internal_f
->f_flags
& F_EXEC
) != 0)
197 abfd
->flags
|= D_PAGED
;
199 bfd_get_symcount (abfd
) = internal_f
->f_nsyms
;
200 if (internal_f
->f_nsyms
)
201 abfd
->flags
|= HAS_SYMS
;
203 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
204 bfd_get_start_address (abfd
) = internal_a
->entry
;
206 bfd_get_start_address (abfd
) = 0;
208 /* Set up the tdata area. ECOFF uses its own routine, and overrides
210 tdata_save
= abfd
->tdata
.any
;
211 tdata
= bfd_coff_mkobject_hook (abfd
, (PTR
) internal_f
, (PTR
) internal_a
);
215 scnhsz
= bfd_coff_scnhsz (abfd
);
216 readsize
= (bfd_size_type
) nscns
* scnhsz
;
217 external_sections
= (char *) bfd_alloc (abfd
, readsize
);
218 if (!external_sections
)
221 if (bfd_bread ((PTR
) external_sections
, readsize
, abfd
) != readsize
)
224 /* Set the arch/mach *before* swapping in sections; section header swapping
225 may depend on arch/mach info. */
226 if (! bfd_coff_set_arch_mach_hook (abfd
, (PTR
) internal_f
))
229 /* Now copy data as required; construct all asections etc. */
233 for (i
= 0; i
< nscns
; i
++)
235 struct internal_scnhdr tmp
;
236 bfd_coff_swap_scnhdr_in (abfd
,
237 (PTR
) (external_sections
+ i
* scnhsz
),
239 if (! make_a_section_from_file (abfd
, &tmp
, i
+ 1))
247 bfd_release (abfd
, tdata
);
249 abfd
->tdata
.any
= tdata_save
;
250 abfd
->flags
= oflags
;
251 bfd_get_start_address (abfd
) = ostart
;
252 return (const bfd_target
*) NULL
;
255 /* Turn a COFF file into a BFD, but fail with bfd_error_wrong_format if it is
256 not a COFF file. This is also used by ECOFF. */
262 bfd_size_type filhsz
;
263 bfd_size_type aoutsz
;
266 struct internal_filehdr internal_f
;
267 struct internal_aouthdr internal_a
;
269 /* figure out how much to read */
270 filhsz
= bfd_coff_filhsz (abfd
);
271 aoutsz
= bfd_coff_aoutsz (abfd
);
273 filehdr
= bfd_alloc (abfd
, filhsz
);
276 if (bfd_bread (filehdr
, filhsz
, abfd
) != filhsz
)
278 if (bfd_get_error () != bfd_error_system_call
)
279 bfd_set_error (bfd_error_wrong_format
);
280 bfd_release (abfd
, filehdr
);
283 bfd_coff_swap_filehdr_in (abfd
, filehdr
, &internal_f
);
284 bfd_release (abfd
, filehdr
);
286 /* The XCOFF format has two sizes for the f_opthdr. SMALL_AOUTSZ
287 (less than aoutsz) used in object files and AOUTSZ (equal to
288 aoutsz) in executables. The bfd_coff_swap_aouthdr_in function
289 expects this header to be aoutsz bytes in length, so we use that
290 value in the call to bfd_alloc below. But we must be careful to
291 only read in f_opthdr bytes in the call to bfd_bread. We should
292 also attempt to catch corrupt or non-COFF binaries with a strange
293 value for f_opthdr. */
294 if (! bfd_coff_bad_format_hook (abfd
, &internal_f
)
295 || internal_f
.f_opthdr
> aoutsz
)
297 bfd_set_error (bfd_error_wrong_format
);
300 nscns
= internal_f
.f_nscns
;
302 if (internal_f
.f_opthdr
)
306 opthdr
= bfd_alloc (abfd
, aoutsz
);
309 if (bfd_bread (opthdr
, (bfd_size_type
) internal_f
.f_opthdr
, abfd
)
310 != internal_f
.f_opthdr
)
312 bfd_release (abfd
, opthdr
);
315 bfd_coff_swap_aouthdr_in (abfd
, opthdr
, (PTR
) &internal_a
);
316 bfd_release (abfd
, opthdr
);
319 return coff_real_object_p (abfd
, nscns
, &internal_f
,
320 (internal_f
.f_opthdr
!= 0
322 : (struct internal_aouthdr
*) NULL
));
325 /* Get the BFD section from a COFF symbol section number. */
328 coff_section_from_bfd_index (abfd
, index
)
332 struct bfd_section
*answer
= abfd
->sections
;
335 return bfd_abs_section_ptr
;
336 if (index
== N_UNDEF
)
337 return bfd_und_section_ptr
;
338 if (index
== N_DEBUG
)
339 return bfd_abs_section_ptr
;
343 if (answer
->target_index
== index
)
345 answer
= answer
->next
;
348 /* We should not reach this point, but the SCO 3.2v4 /lib/libc_s.a
349 has a bad symbol table in biglitpow.o. */
350 return bfd_und_section_ptr
;
353 /* Get the upper bound of a COFF symbol table. */
356 coff_get_symtab_upper_bound (abfd
)
359 if (!bfd_coff_slurp_symbol_table (abfd
))
362 return (bfd_get_symcount (abfd
) + 1) * (sizeof (coff_symbol_type
*));
365 /* Canonicalize a COFF symbol table. */
368 coff_canonicalize_symtab (abfd
, alocation
)
372 unsigned int counter
;
373 coff_symbol_type
*symbase
;
374 coff_symbol_type
**location
= (coff_symbol_type
**) alocation
;
376 if (!bfd_coff_slurp_symbol_table (abfd
))
379 symbase
= obj_symbols (abfd
);
380 counter
= bfd_get_symcount (abfd
);
381 while (counter
-- > 0)
382 *location
++ = symbase
++;
386 return bfd_get_symcount (abfd
);
389 /* Get the name of a symbol. The caller must pass in a buffer of size
393 _bfd_coff_internal_syment_name (abfd
, sym
, buf
)
395 const struct internal_syment
*sym
;
398 /* FIXME: It's not clear this will work correctly if sizeof
400 if (sym
->_n
._n_n
._n_zeroes
!= 0
401 || sym
->_n
._n_n
._n_offset
== 0)
403 memcpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
404 buf
[SYMNMLEN
] = '\0';
411 BFD_ASSERT (sym
->_n
._n_n
._n_offset
>= STRING_SIZE_SIZE
);
412 strings
= obj_coff_strings (abfd
);
415 strings
= _bfd_coff_read_string_table (abfd
);
419 return strings
+ sym
->_n
._n_n
._n_offset
;
423 /* Read in and swap the relocs. This returns a buffer holding the
424 relocs for section SEC in file ABFD. If CACHE is TRUE and
425 INTERNAL_RELOCS is NULL, the relocs read in will be saved in case
426 the function is called again. If EXTERNAL_RELOCS is not NULL, it
427 is a buffer large enough to hold the unswapped relocs. If
428 INTERNAL_RELOCS is not NULL, it is a buffer large enough to hold
429 the swapped relocs. If REQUIRE_INTERNAL is TRUE, then the return
430 value must be INTERNAL_RELOCS. The function returns NULL on error. */
432 struct internal_reloc
*
433 _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
434 require_internal
, internal_relocs
)
438 bfd_byte
*external_relocs
;
439 bfd_boolean require_internal
;
440 struct internal_reloc
*internal_relocs
;
443 bfd_byte
*free_external
= NULL
;
444 struct internal_reloc
*free_internal
= NULL
;
447 struct internal_reloc
*irel
;
450 if (coff_section_data (abfd
, sec
) != NULL
451 && coff_section_data (abfd
, sec
)->relocs
!= NULL
)
453 if (! require_internal
)
454 return coff_section_data (abfd
, sec
)->relocs
;
455 memcpy (internal_relocs
, coff_section_data (abfd
, sec
)->relocs
,
456 sec
->reloc_count
* sizeof (struct internal_reloc
));
457 return internal_relocs
;
460 relsz
= bfd_coff_relsz (abfd
);
462 amt
= sec
->reloc_count
* relsz
;
463 if (external_relocs
== NULL
)
465 free_external
= (bfd_byte
*) bfd_malloc (amt
);
466 if (free_external
== NULL
&& sec
->reloc_count
> 0)
468 external_relocs
= free_external
;
471 if (bfd_seek (abfd
, sec
->rel_filepos
, SEEK_SET
) != 0
472 || bfd_bread (external_relocs
, amt
, abfd
) != amt
)
475 if (internal_relocs
== NULL
)
477 amt
= sec
->reloc_count
;
478 amt
*= sizeof (struct internal_reloc
);
479 free_internal
= (struct internal_reloc
*) bfd_malloc (amt
);
480 if (free_internal
== NULL
&& sec
->reloc_count
> 0)
482 internal_relocs
= free_internal
;
485 /* Swap in the relocs. */
486 erel
= external_relocs
;
487 erel_end
= erel
+ relsz
* sec
->reloc_count
;
488 irel
= internal_relocs
;
489 for (; erel
< erel_end
; erel
+= relsz
, irel
++)
490 bfd_coff_swap_reloc_in (abfd
, (PTR
) erel
, (PTR
) irel
);
492 if (free_external
!= NULL
)
494 free (free_external
);
495 free_external
= NULL
;
498 if (cache
&& free_internal
!= NULL
)
500 if (coff_section_data (abfd
, sec
) == NULL
)
502 amt
= sizeof (struct coff_section_tdata
);
503 sec
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
504 if (sec
->used_by_bfd
== NULL
)
506 coff_section_data (abfd
, sec
)->contents
= NULL
;
508 coff_section_data (abfd
, sec
)->relocs
= free_internal
;
511 return internal_relocs
;
514 if (free_external
!= NULL
)
515 free (free_external
);
516 if (free_internal
!= NULL
)
517 free (free_internal
);
521 /* Set lineno_count for the output sections of a COFF file. */
524 coff_count_linenumbers (abfd
)
527 unsigned int limit
= bfd_get_symcount (abfd
);
535 /* This may be from the backend linker, in which case the
536 lineno_count in the sections is correct. */
537 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
538 total
+= s
->lineno_count
;
542 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
543 BFD_ASSERT (s
->lineno_count
== 0);
545 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++)
547 asymbol
*q_maybe
= *p
;
549 if (bfd_family_coff (bfd_asymbol_bfd (q_maybe
)))
551 coff_symbol_type
*q
= coffsymbol (q_maybe
);
553 /* The AIX 4.1 compiler can sometimes generate line numbers
554 attached to debugging symbols. We try to simply ignore
556 if (q
->lineno
!= NULL
557 && q
->symbol
.section
->owner
!= NULL
)
559 /* This symbol has line numbers. Increment the owning
560 section's linenumber count. */
561 alent
*l
= q
->lineno
;
565 asection
* sec
= q
->symbol
.section
->output_section
;
567 /* Do not try to update fields in read-only sections. */
568 if (! bfd_is_const_section (sec
))
569 sec
->lineno_count
++;
574 while (l
->line_number
!= 0);
582 /* Takes a bfd and a symbol, returns a pointer to the coff specific
583 area of the symbol if there is one. */
586 coff_symbol_from (ignore_abfd
, symbol
)
587 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
590 if (!bfd_family_coff (bfd_asymbol_bfd (symbol
)))
591 return (coff_symbol_type
*) NULL
;
593 if (bfd_asymbol_bfd (symbol
)->tdata
.coff_obj_data
== (coff_data_type
*) NULL
)
594 return (coff_symbol_type
*) NULL
;
596 return (coff_symbol_type
*) symbol
;
600 fixup_symbol_value (abfd
, coff_symbol_ptr
, syment
)
602 coff_symbol_type
*coff_symbol_ptr
;
603 struct internal_syment
*syment
;
606 /* Normalize the symbol flags */
607 if (bfd_is_com_section (coff_symbol_ptr
->symbol
.section
))
609 /* a common symbol is undefined with a value */
610 syment
->n_scnum
= N_UNDEF
;
611 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
613 else if ((coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
) != 0
614 && (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING_RELOC
) == 0)
616 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
618 else if (bfd_is_und_section (coff_symbol_ptr
->symbol
.section
))
620 syment
->n_scnum
= N_UNDEF
;
623 /* FIXME: Do we need to handle the absolute section here? */
626 if (coff_symbol_ptr
->symbol
.section
)
629 coff_symbol_ptr
->symbol
.section
->output_section
->target_index
;
631 syment
->n_value
= (coff_symbol_ptr
->symbol
.value
632 + coff_symbol_ptr
->symbol
.section
->output_offset
);
635 syment
->n_value
+= (syment
->n_sclass
== C_STATLAB
)
636 ? coff_symbol_ptr
->symbol
.section
->output_section
->lma
637 : coff_symbol_ptr
->symbol
.section
->output_section
->vma
;
643 /* This can happen, but I don't know why yet (steve@cygnus.com) */
644 syment
->n_scnum
= N_ABS
;
645 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
650 /* Run through all the symbols in the symbol table and work out what
651 their indexes into the symbol table will be when output.
653 Coff requires that each C_FILE symbol points to the next one in the
654 chain, and that the last one points to the first external symbol. We
658 coff_renumber_symbols (bfd_ptr
, first_undef
)
662 unsigned int symbol_count
= bfd_get_symcount (bfd_ptr
);
663 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
664 unsigned int native_index
= 0;
665 struct internal_syment
*last_file
= (struct internal_syment
*) NULL
;
666 unsigned int symbol_index
;
668 /* COFF demands that undefined symbols come after all other symbols.
669 Since we don't need to impose this extra knowledge on all our
670 client programs, deal with that here. Sort the symbol table;
671 just move the undefined symbols to the end, leaving the rest
672 alone. The O'Reilly book says that defined global symbols come
673 at the end before the undefined symbols, so we do that here as
675 /* @@ Do we have some condition we could test for, so we don't always
676 have to do this? I don't think relocatability is quite right, but
677 I'm not certain. [raeburn:19920508.1711EST] */
683 amt
= sizeof (asymbol
*) * ((bfd_size_type
) symbol_count
+ 1);
684 newsyms
= (asymbol
**) bfd_alloc (bfd_ptr
, amt
);
687 bfd_ptr
->outsymbols
= newsyms
;
688 for (i
= 0; i
< symbol_count
; i
++)
689 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) != 0
690 || (!bfd_is_und_section (symbol_ptr_ptr
[i
]->section
)
691 && !bfd_is_com_section (symbol_ptr_ptr
[i
]->section
)
692 && ((symbol_ptr_ptr
[i
]->flags
& BSF_FUNCTION
) != 0
693 || ((symbol_ptr_ptr
[i
]->flags
& (BSF_GLOBAL
| BSF_WEAK
))
695 *newsyms
++ = symbol_ptr_ptr
[i
];
697 for (i
= 0; i
< symbol_count
; i
++)
698 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) == 0
699 && !bfd_is_und_section (symbol_ptr_ptr
[i
]->section
)
700 && (bfd_is_com_section (symbol_ptr_ptr
[i
]->section
)
701 || ((symbol_ptr_ptr
[i
]->flags
& BSF_FUNCTION
) == 0
702 && ((symbol_ptr_ptr
[i
]->flags
& (BSF_GLOBAL
| BSF_WEAK
))
704 *newsyms
++ = symbol_ptr_ptr
[i
];
706 *first_undef
= newsyms
- bfd_ptr
->outsymbols
;
708 for (i
= 0; i
< symbol_count
; i
++)
709 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) == 0
710 && bfd_is_und_section (symbol_ptr_ptr
[i
]->section
))
711 *newsyms
++ = symbol_ptr_ptr
[i
];
712 *newsyms
= (asymbol
*) NULL
;
713 symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
716 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++)
718 coff_symbol_type
*coff_symbol_ptr
= coff_symbol_from (bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
719 symbol_ptr_ptr
[symbol_index
]->udata
.i
= symbol_index
;
720 if (coff_symbol_ptr
&& coff_symbol_ptr
->native
)
722 combined_entry_type
*s
= coff_symbol_ptr
->native
;
725 if (s
->u
.syment
.n_sclass
== C_FILE
)
727 if (last_file
!= (struct internal_syment
*) NULL
)
728 last_file
->n_value
= native_index
;
729 last_file
= &(s
->u
.syment
);
734 /* Modify the symbol values according to their section and
737 fixup_symbol_value (bfd_ptr
, coff_symbol_ptr
, &(s
->u
.syment
));
739 for (i
= 0; i
< s
->u
.syment
.n_numaux
+ 1; i
++)
740 s
[i
].offset
= native_index
++;
747 obj_conv_table_size (bfd_ptr
) = native_index
;
752 /* Run thorough the symbol table again, and fix it so that all
753 pointers to entries are changed to the entries' index in the output
757 coff_mangle_symbols (bfd_ptr
)
760 unsigned int symbol_count
= bfd_get_symcount (bfd_ptr
);
761 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
762 unsigned int symbol_index
;
764 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++)
766 coff_symbol_type
*coff_symbol_ptr
=
767 coff_symbol_from (bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
769 if (coff_symbol_ptr
&& coff_symbol_ptr
->native
)
772 combined_entry_type
*s
= coff_symbol_ptr
->native
;
776 /* FIXME: We should use a union here. */
777 s
->u
.syment
.n_value
=
778 (bfd_vma
)((combined_entry_type
*)
779 ((unsigned long) s
->u
.syment
.n_value
))->offset
;
784 /* The value is the offset into the line number entries
785 for the symbol's section. On output, the symbol's
786 section should be N_DEBUG. */
787 s
->u
.syment
.n_value
=
788 (coff_symbol_ptr
->symbol
.section
->output_section
->line_filepos
789 + s
->u
.syment
.n_value
* bfd_coff_linesz (bfd_ptr
));
790 coff_symbol_ptr
->symbol
.section
=
791 coff_section_from_bfd_index (bfd_ptr
, N_DEBUG
);
792 BFD_ASSERT (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
);
794 for (i
= 0; i
< s
->u
.syment
.n_numaux
; i
++)
796 combined_entry_type
*a
= s
+ i
+ 1;
799 a
->u
.auxent
.x_sym
.x_tagndx
.l
=
800 a
->u
.auxent
.x_sym
.x_tagndx
.p
->offset
;
805 a
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
806 a
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
->offset
;
811 a
->u
.auxent
.x_csect
.x_scnlen
.l
=
812 a
->u
.auxent
.x_csect
.x_scnlen
.p
->offset
;
821 coff_fix_symbol_name (abfd
, symbol
, native
, string_size_p
,
822 debug_string_section_p
, debug_string_size_p
)
825 combined_entry_type
*native
;
826 bfd_size_type
*string_size_p
;
827 asection
**debug_string_section_p
;
828 bfd_size_type
*debug_string_size_p
;
830 unsigned int name_length
;
831 union internal_auxent
*auxent
;
832 char *name
= (char *) (symbol
->name
);
834 if (name
== (char *) NULL
)
836 /* coff symbols always have names, so we'll make one up */
837 symbol
->name
= "strange";
838 name
= (char *) symbol
->name
;
840 name_length
= strlen (name
);
842 if (native
->u
.syment
.n_sclass
== C_FILE
843 && native
->u
.syment
.n_numaux
> 0)
845 unsigned int filnmlen
;
847 if (bfd_coff_force_symnames_in_strings (abfd
))
849 native
->u
.syment
._n
._n_n
._n_offset
=
850 (*string_size_p
+ STRING_SIZE_SIZE
);
851 native
->u
.syment
._n
._n_n
._n_zeroes
= 0;
852 *string_size_p
+= 6; /* strlen(".file") + 1 */
855 strncpy (native
->u
.syment
._n
._n_name
, ".file", SYMNMLEN
);
857 auxent
= &(native
+ 1)->u
.auxent
;
859 filnmlen
= bfd_coff_filnmlen (abfd
);
861 if (bfd_coff_long_filenames (abfd
))
863 if (name_length
<= filnmlen
)
865 strncpy (auxent
->x_file
.x_fname
, name
, filnmlen
);
869 auxent
->x_file
.x_n
.x_offset
= *string_size_p
+ STRING_SIZE_SIZE
;
870 auxent
->x_file
.x_n
.x_zeroes
= 0;
871 *string_size_p
+= name_length
+ 1;
876 strncpy (auxent
->x_file
.x_fname
, name
, filnmlen
);
877 if (name_length
> filnmlen
)
878 name
[filnmlen
] = '\0';
883 if (name_length
<= SYMNMLEN
&& !bfd_coff_force_symnames_in_strings (abfd
))
885 /* This name will fit into the symbol neatly */
886 strncpy (native
->u
.syment
._n
._n_name
, symbol
->name
, SYMNMLEN
);
888 else if (!bfd_coff_symname_in_debug (abfd
, &native
->u
.syment
))
890 native
->u
.syment
._n
._n_n
._n_offset
= (*string_size_p
892 native
->u
.syment
._n
._n_n
._n_zeroes
= 0;
893 *string_size_p
+= name_length
+ 1;
899 int prefix_len
= bfd_coff_debug_string_prefix_length (abfd
);
901 /* This name should be written into the .debug section. For
902 some reason each name is preceded by a two byte length
903 and also followed by a null byte. FIXME: We assume that
904 the .debug section has already been created, and that it
906 if (*debug_string_section_p
== (asection
*) NULL
)
907 *debug_string_section_p
= bfd_get_section_by_name (abfd
, ".debug");
908 filepos
= bfd_tell (abfd
);
910 bfd_put_32 (abfd
, (bfd_vma
) (name_length
+ 1), buf
);
912 bfd_put_16 (abfd
, (bfd_vma
) (name_length
+ 1), buf
);
914 if (!bfd_set_section_contents (abfd
,
915 *debug_string_section_p
,
917 (file_ptr
) *debug_string_size_p
,
918 (bfd_size_type
) prefix_len
)
919 || !bfd_set_section_contents (abfd
,
920 *debug_string_section_p
,
922 (file_ptr
) (*debug_string_size_p
924 (bfd_size_type
) name_length
+ 1))
926 if (bfd_seek (abfd
, filepos
, SEEK_SET
) != 0)
928 native
->u
.syment
._n
._n_n
._n_offset
=
929 *debug_string_size_p
+ prefix_len
;
930 native
->u
.syment
._n
._n_n
._n_zeroes
= 0;
931 *debug_string_size_p
+= name_length
+ 1 + prefix_len
;
936 /* We need to keep track of the symbol index so that when we write out
937 the relocs we can get the index for a symbol. This method is a
940 #define set_index(symbol, idx) ((symbol)->udata.i = (idx))
942 /* Write a symbol out to a COFF file. */
945 coff_write_symbol (abfd
, symbol
, native
, written
, string_size_p
,
946 debug_string_section_p
, debug_string_size_p
)
949 combined_entry_type
*native
;
951 bfd_size_type
*string_size_p
;
952 asection
**debug_string_section_p
;
953 bfd_size_type
*debug_string_size_p
;
955 unsigned int numaux
= native
->u
.syment
.n_numaux
;
956 int type
= native
->u
.syment
.n_type
;
957 int class = native
->u
.syment
.n_sclass
;
959 bfd_size_type symesz
;
961 if (native
->u
.syment
.n_sclass
== C_FILE
)
962 symbol
->flags
|= BSF_DEBUGGING
;
964 if (symbol
->flags
& BSF_DEBUGGING
965 && bfd_is_abs_section (symbol
->section
))
967 native
->u
.syment
.n_scnum
= N_DEBUG
;
969 else if (bfd_is_abs_section (symbol
->section
))
971 native
->u
.syment
.n_scnum
= N_ABS
;
973 else if (bfd_is_und_section (symbol
->section
))
975 native
->u
.syment
.n_scnum
= N_UNDEF
;
979 native
->u
.syment
.n_scnum
=
980 symbol
->section
->output_section
->target_index
;
983 coff_fix_symbol_name (abfd
, symbol
, native
, string_size_p
,
984 debug_string_section_p
, debug_string_size_p
);
986 symesz
= bfd_coff_symesz (abfd
);
987 buf
= bfd_alloc (abfd
, symesz
);
990 bfd_coff_swap_sym_out (abfd
, &native
->u
.syment
, buf
);
991 if (bfd_bwrite (buf
, symesz
, abfd
) != symesz
)
993 bfd_release (abfd
, buf
);
995 if (native
->u
.syment
.n_numaux
> 0)
997 bfd_size_type auxesz
;
1000 auxesz
= bfd_coff_auxesz (abfd
);
1001 buf
= bfd_alloc (abfd
, auxesz
);
1004 for (j
= 0; j
< native
->u
.syment
.n_numaux
; j
++)
1006 bfd_coff_swap_aux_out (abfd
,
1007 &((native
+ j
+ 1)->u
.auxent
),
1011 native
->u
.syment
.n_numaux
,
1013 if (bfd_bwrite (buf
, auxesz
, abfd
) != auxesz
)
1016 bfd_release (abfd
, buf
);
1019 /* Store the index for use when we write out the relocs. */
1020 set_index (symbol
, *written
);
1022 *written
+= numaux
+ 1;
1026 /* Write out a symbol to a COFF file that does not come from a COFF
1027 file originally. This symbol may have been created by the linker,
1028 or we may be linking a non COFF file to a COFF file. */
1031 coff_write_alien_symbol (abfd
, symbol
, written
, string_size_p
,
1032 debug_string_section_p
, debug_string_size_p
)
1036 bfd_size_type
*string_size_p
;
1037 asection
**debug_string_section_p
;
1038 bfd_size_type
*debug_string_size_p
;
1040 combined_entry_type
*native
;
1041 combined_entry_type dummy
;
1044 native
->u
.syment
.n_type
= T_NULL
;
1045 native
->u
.syment
.n_flags
= 0;
1046 if (bfd_is_und_section (symbol
->section
))
1048 native
->u
.syment
.n_scnum
= N_UNDEF
;
1049 native
->u
.syment
.n_value
= symbol
->value
;
1051 else if (bfd_is_com_section (symbol
->section
))
1053 native
->u
.syment
.n_scnum
= N_UNDEF
;
1054 native
->u
.syment
.n_value
= symbol
->value
;
1056 else if (symbol
->flags
& BSF_DEBUGGING
)
1058 /* There isn't much point to writing out a debugging symbol
1059 unless we are prepared to convert it into COFF debugging
1060 format. So, we just ignore them. We must clobber the symbol
1061 name to keep it from being put in the string table. */
1067 native
->u
.syment
.n_scnum
=
1068 symbol
->section
->output_section
->target_index
;
1069 native
->u
.syment
.n_value
= (symbol
->value
1070 + symbol
->section
->output_offset
);
1071 if (! obj_pe (abfd
))
1072 native
->u
.syment
.n_value
+= symbol
->section
->output_section
->vma
;
1074 /* Copy the any flags from the file header into the symbol.
1077 coff_symbol_type
*c
= coff_symbol_from (abfd
, symbol
);
1078 if (c
!= (coff_symbol_type
*) NULL
)
1079 native
->u
.syment
.n_flags
= bfd_asymbol_bfd (&c
->symbol
)->flags
;
1083 native
->u
.syment
.n_type
= 0;
1084 if (symbol
->flags
& BSF_LOCAL
)
1085 native
->u
.syment
.n_sclass
= C_STAT
;
1086 else if (symbol
->flags
& BSF_WEAK
)
1087 native
->u
.syment
.n_sclass
= obj_pe (abfd
) ? C_NT_WEAK
: C_WEAKEXT
;
1089 native
->u
.syment
.n_sclass
= C_EXT
;
1090 native
->u
.syment
.n_numaux
= 0;
1092 return coff_write_symbol (abfd
, symbol
, native
, written
, string_size_p
,
1093 debug_string_section_p
, debug_string_size_p
);
1096 /* Write a native symbol to a COFF file. */
1099 coff_write_native_symbol (abfd
, symbol
, written
, string_size_p
,
1100 debug_string_section_p
, debug_string_size_p
)
1102 coff_symbol_type
*symbol
;
1104 bfd_size_type
*string_size_p
;
1105 asection
**debug_string_section_p
;
1106 bfd_size_type
*debug_string_size_p
;
1108 combined_entry_type
*native
= symbol
->native
;
1109 alent
*lineno
= symbol
->lineno
;
1111 /* If this symbol has an associated line number, we must store the
1112 symbol index in the line number field. We also tag the auxent to
1113 point to the right place in the lineno table. */
1114 if (lineno
&& !symbol
->done_lineno
&& symbol
->symbol
.section
->owner
!= NULL
)
1116 unsigned int count
= 0;
1117 lineno
[count
].u
.offset
= *written
;
1118 if (native
->u
.syment
.n_numaux
)
1120 union internal_auxent
*a
= &((native
+ 1)->u
.auxent
);
1122 a
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
1123 symbol
->symbol
.section
->output_section
->moving_line_filepos
;
1126 /* Count and relocate all other linenumbers. */
1128 while (lineno
[count
].line_number
!= 0)
1130 lineno
[count
].u
.offset
+=
1131 (symbol
->symbol
.section
->output_section
->vma
1132 + symbol
->symbol
.section
->output_offset
);
1135 symbol
->done_lineno
= TRUE
;
1137 if (! bfd_is_const_section (symbol
->symbol
.section
->output_section
))
1138 symbol
->symbol
.section
->output_section
->moving_line_filepos
+=
1139 count
* bfd_coff_linesz (abfd
);
1142 return coff_write_symbol (abfd
, &(symbol
->symbol
), native
, written
,
1143 string_size_p
, debug_string_section_p
,
1144 debug_string_size_p
);
1147 /* Write out the COFF symbols. */
1150 coff_write_symbols (abfd
)
1153 bfd_size_type string_size
;
1154 asection
*debug_string_section
;
1155 bfd_size_type debug_string_size
;
1157 unsigned int limit
= bfd_get_symcount (abfd
);
1158 bfd_signed_vma written
= 0;
1162 debug_string_section
= NULL
;
1163 debug_string_size
= 0;
1165 /* If this target supports long section names, they must be put into
1166 the string table. This is supported by PE. This code must
1167 handle section names just as they are handled in
1168 coff_write_object_contents. */
1169 if (bfd_coff_long_section_names (abfd
))
1173 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1177 len
= strlen (o
->name
);
1179 string_size
+= len
+ 1;
1183 /* Seek to the right place */
1184 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0)
1187 /* Output all the symbols we have */
1190 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++)
1192 asymbol
*symbol
= *p
;
1193 coff_symbol_type
*c_symbol
= coff_symbol_from (abfd
, symbol
);
1195 if (c_symbol
== (coff_symbol_type
*) NULL
1196 || c_symbol
->native
== (combined_entry_type
*) NULL
)
1198 if (!coff_write_alien_symbol (abfd
, symbol
, &written
, &string_size
,
1199 &debug_string_section
,
1200 &debug_string_size
))
1205 if (!coff_write_native_symbol (abfd
, c_symbol
, &written
,
1206 &string_size
, &debug_string_section
,
1207 &debug_string_size
))
1212 obj_raw_syment_count (abfd
) = written
;
1214 /* Now write out strings */
1216 if (string_size
!= 0)
1218 unsigned int size
= string_size
+ STRING_SIZE_SIZE
;
1219 bfd_byte buffer
[STRING_SIZE_SIZE
];
1221 #if STRING_SIZE_SIZE == 4
1222 H_PUT_32 (abfd
, size
, buffer
);
1224 #error Change H_PUT_32
1226 if (bfd_bwrite ((PTR
) buffer
, (bfd_size_type
) sizeof (buffer
), abfd
)
1230 /* Handle long section names. This code must handle section
1231 names just as they are handled in coff_write_object_contents. */
1232 if (bfd_coff_long_section_names (abfd
))
1236 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1240 len
= strlen (o
->name
);
1243 if (bfd_bwrite (o
->name
, (bfd_size_type
) (len
+ 1), abfd
)
1250 for (p
= abfd
->outsymbols
, i
= 0;
1255 size_t name_length
= strlen (q
->name
);
1256 coff_symbol_type
*c_symbol
= coff_symbol_from (abfd
, q
);
1259 /* Figure out whether the symbol name should go in the string
1260 table. Symbol names that are short enough are stored
1261 directly in the syment structure. File names permit a
1262 different, longer, length in the syment structure. On
1263 XCOFF, some symbol names are stored in the .debug section
1264 rather than in the string table. */
1266 if (c_symbol
== NULL
1267 || c_symbol
->native
== NULL
)
1269 /* This is not a COFF symbol, so it certainly is not a
1270 file name, nor does it go in the .debug section. */
1271 maxlen
= bfd_coff_force_symnames_in_strings (abfd
) ? 0 : SYMNMLEN
;
1273 else if (bfd_coff_symname_in_debug (abfd
,
1274 &c_symbol
->native
->u
.syment
))
1276 /* This symbol name is in the XCOFF .debug section.
1277 Don't write it into the string table. */
1278 maxlen
= name_length
;
1280 else if (c_symbol
->native
->u
.syment
.n_sclass
== C_FILE
1281 && c_symbol
->native
->u
.syment
.n_numaux
> 0)
1283 if (bfd_coff_force_symnames_in_strings (abfd
))
1285 if (bfd_bwrite (".file", (bfd_size_type
) 6, abfd
) != 6)
1288 maxlen
= bfd_coff_filnmlen (abfd
);
1291 maxlen
= bfd_coff_force_symnames_in_strings (abfd
) ? 0 : SYMNMLEN
;
1293 if (name_length
> maxlen
)
1295 if (bfd_bwrite ((PTR
) (q
->name
), (bfd_size_type
) name_length
+ 1,
1296 abfd
) != name_length
+ 1)
1303 /* We would normally not write anything here, but we'll write
1304 out 4 so that any stupid coff reader which tries to read the
1305 string table even when there isn't one won't croak. */
1306 unsigned int size
= STRING_SIZE_SIZE
;
1307 bfd_byte buffer
[STRING_SIZE_SIZE
];
1309 #if STRING_SIZE_SIZE == 4
1310 H_PUT_32 (abfd
, size
, buffer
);
1312 #error Change H_PUT_32
1314 if (bfd_bwrite ((PTR
) buffer
, (bfd_size_type
) STRING_SIZE_SIZE
, abfd
)
1315 != STRING_SIZE_SIZE
)
1319 /* Make sure the .debug section was created to be the correct size.
1320 We should create it ourselves on the fly, but we don't because
1321 BFD won't let us write to any section until we know how large all
1322 the sections are. We could still do it by making another pass
1323 over the symbols. FIXME. */
1324 BFD_ASSERT (debug_string_size
== 0
1325 || (debug_string_section
!= (asection
*) NULL
1326 && (BFD_ALIGN (debug_string_size
,
1327 1 << debug_string_section
->alignment_power
)
1328 == debug_string_section
->size
)));
1334 coff_write_linenumbers (abfd
)
1338 bfd_size_type linesz
;
1341 linesz
= bfd_coff_linesz (abfd
);
1342 buff
= bfd_alloc (abfd
, linesz
);
1345 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1347 if (s
->lineno_count
)
1349 asymbol
**q
= abfd
->outsymbols
;
1350 if (bfd_seek (abfd
, s
->line_filepos
, SEEK_SET
) != 0)
1352 /* Find all the linenumbers in this section */
1356 if (p
->section
->output_section
== s
)
1359 BFD_SEND (bfd_asymbol_bfd (p
), _get_lineno
,
1360 (bfd_asymbol_bfd (p
), p
));
1363 /* Found a linenumber entry, output */
1364 struct internal_lineno out
;
1365 memset ((PTR
) & out
, 0, sizeof (out
));
1367 out
.l_addr
.l_symndx
= l
->u
.offset
;
1368 bfd_coff_swap_lineno_out (abfd
, &out
, buff
);
1369 if (bfd_bwrite (buff
, (bfd_size_type
) linesz
, abfd
)
1373 while (l
->line_number
)
1375 out
.l_lnno
= l
->line_number
;
1376 out
.l_addr
.l_symndx
= l
->u
.offset
;
1377 bfd_coff_swap_lineno_out (abfd
, &out
, buff
);
1378 if (bfd_bwrite (buff
, (bfd_size_type
) linesz
, abfd
)
1389 bfd_release (abfd
, buff
);
1394 coff_get_lineno (ignore_abfd
, symbol
)
1395 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
1398 return coffsymbol (symbol
)->lineno
;
1401 /* This function transforms the offsets into the symbol table into
1402 pointers to syments. */
1405 coff_pointerize_aux (abfd
, table_base
, symbol
, indaux
, auxent
)
1407 combined_entry_type
*table_base
;
1408 combined_entry_type
*symbol
;
1409 unsigned int indaux
;
1410 combined_entry_type
*auxent
;
1412 unsigned int type
= symbol
->u
.syment
.n_type
;
1413 unsigned int class = symbol
->u
.syment
.n_sclass
;
1415 if (coff_backend_info (abfd
)->_bfd_coff_pointerize_aux_hook
)
1417 if ((*coff_backend_info (abfd
)->_bfd_coff_pointerize_aux_hook
)
1418 (abfd
, table_base
, symbol
, indaux
, auxent
))
1422 /* Don't bother if this is a file or a section */
1423 if (class == C_STAT
&& type
== T_NULL
)
1425 if (class == C_FILE
)
1428 /* Otherwise patch up */
1429 #define N_TMASK coff_data (abfd)->local_n_tmask
1430 #define N_BTSHFT coff_data (abfd)->local_n_btshft
1431 if ((ISFCN (type
) || ISTAG (class) || class == C_BLOCK
|| class == C_FCN
)
1432 && auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
> 0)
1434 auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
=
1435 table_base
+ auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
1436 auxent
->fix_end
= 1;
1438 /* A negative tagndx is meaningless, but the SCO 3.2v4 cc can
1439 generate one, so we must be careful to ignore it. */
1440 if (auxent
->u
.auxent
.x_sym
.x_tagndx
.l
> 0)
1442 auxent
->u
.auxent
.x_sym
.x_tagndx
.p
=
1443 table_base
+ auxent
->u
.auxent
.x_sym
.x_tagndx
.l
;
1444 auxent
->fix_tag
= 1;
1448 /* Allocate space for the ".debug" section, and read it.
1449 We did not read the debug section until now, because
1450 we didn't want to go to the trouble until someone needed it. */
1453 build_debug_section (abfd
)
1456 char *debug_section
;
1458 bfd_size_type sec_size
;
1460 asection
*sect
= bfd_get_section_by_name (abfd
, ".debug");
1464 bfd_set_error (bfd_error_no_debug_section
);
1468 sec_size
= sect
->size
;
1469 debug_section
= (PTR
) bfd_alloc (abfd
, sec_size
);
1470 if (debug_section
== NULL
)
1473 /* Seek to the beginning of the `.debug' section and read it.
1474 Save the current position first; it is needed by our caller.
1475 Then read debug section and reset the file pointer. */
1477 position
= bfd_tell (abfd
);
1478 if (bfd_seek (abfd
, sect
->filepos
, SEEK_SET
) != 0
1479 || bfd_bread (debug_section
, sec_size
, abfd
) != sec_size
1480 || bfd_seek (abfd
, position
, SEEK_SET
) != 0)
1482 return debug_section
;
1485 /* Return a pointer to a malloc'd copy of 'name'. 'name' may not be
1486 \0-terminated, but will not exceed 'maxlen' characters. The copy *will*
1487 be \0-terminated. */
1489 copy_name (abfd
, name
, maxlen
)
1497 for (len
= 0; len
< maxlen
; ++len
)
1499 if (name
[len
] == '\0')
1505 if ((newname
= (PTR
) bfd_alloc (abfd
, (bfd_size_type
) len
+ 1)) == NULL
)
1507 strncpy (newname
, name
, len
);
1508 newname
[len
] = '\0';
1512 /* Read in the external symbols. */
1515 _bfd_coff_get_external_symbols (abfd
)
1518 bfd_size_type symesz
;
1522 if (obj_coff_external_syms (abfd
) != NULL
)
1525 symesz
= bfd_coff_symesz (abfd
);
1527 size
= obj_raw_syment_count (abfd
) * symesz
;
1529 syms
= (PTR
) bfd_malloc (size
);
1530 if (syms
== NULL
&& size
!= 0)
1533 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1534 || bfd_bread (syms
, size
, abfd
) != size
)
1541 obj_coff_external_syms (abfd
) = syms
;
1546 /* Read in the external strings. The strings are not loaded until
1547 they are needed. This is because we have no simple way of
1548 detecting a missing string table in an archive. */
1551 _bfd_coff_read_string_table (abfd
)
1554 char extstrsize
[STRING_SIZE_SIZE
];
1555 bfd_size_type strsize
;
1559 if (obj_coff_strings (abfd
) != NULL
)
1560 return obj_coff_strings (abfd
);
1562 if (obj_sym_filepos (abfd
) == 0)
1564 bfd_set_error (bfd_error_no_symbols
);
1568 pos
= obj_sym_filepos (abfd
);
1569 pos
+= obj_raw_syment_count (abfd
) * bfd_coff_symesz (abfd
);
1570 if (bfd_seek (abfd
, pos
, SEEK_SET
) != 0)
1573 if (bfd_bread (extstrsize
, (bfd_size_type
) sizeof extstrsize
, abfd
)
1574 != sizeof extstrsize
)
1576 if (bfd_get_error () != bfd_error_file_truncated
)
1579 /* There is no string table. */
1580 strsize
= STRING_SIZE_SIZE
;
1584 #if STRING_SIZE_SIZE == 4
1585 strsize
= H_GET_32 (abfd
, extstrsize
);
1587 #error Change H_GET_32
1591 if (strsize
< STRING_SIZE_SIZE
)
1593 (*_bfd_error_handler
)
1594 (_("%B: bad string table size %lu"), abfd
, (unsigned long) strsize
);
1595 bfd_set_error (bfd_error_bad_value
);
1599 strings
= (char *) bfd_malloc (strsize
);
1600 if (strings
== NULL
)
1603 if (bfd_bread (strings
+ STRING_SIZE_SIZE
, strsize
- STRING_SIZE_SIZE
, abfd
)
1604 != strsize
- STRING_SIZE_SIZE
)
1610 obj_coff_strings (abfd
) = strings
;
1615 /* Free up the external symbols and strings read from a COFF file. */
1618 _bfd_coff_free_symbols (abfd
)
1621 if (obj_coff_external_syms (abfd
) != NULL
1622 && ! obj_coff_keep_syms (abfd
))
1624 free (obj_coff_external_syms (abfd
));
1625 obj_coff_external_syms (abfd
) = NULL
;
1627 if (obj_coff_strings (abfd
) != NULL
1628 && ! obj_coff_keep_strings (abfd
))
1630 free (obj_coff_strings (abfd
));
1631 obj_coff_strings (abfd
) = NULL
;
1636 /* Read a symbol table into freshly bfd_allocated memory, swap it, and
1637 knit the symbol names into a normalized form. By normalized here I
1638 mean that all symbols have an n_offset pointer that points to a null-
1639 terminated string. */
1641 combined_entry_type
*
1642 coff_get_normalized_symtab (abfd
)
1645 combined_entry_type
*internal
;
1646 combined_entry_type
*internal_ptr
;
1647 combined_entry_type
*symbol_ptr
;
1648 combined_entry_type
*internal_end
;
1652 const char *string_table
= NULL
;
1653 char *debug_section
= NULL
;
1656 if (obj_raw_syments (abfd
) != NULL
)
1657 return obj_raw_syments (abfd
);
1659 size
= obj_raw_syment_count (abfd
) * sizeof (combined_entry_type
);
1660 internal
= (combined_entry_type
*) bfd_zalloc (abfd
, size
);
1661 if (internal
== NULL
&& size
!= 0)
1663 internal_end
= internal
+ obj_raw_syment_count (abfd
);
1665 if (! _bfd_coff_get_external_symbols (abfd
))
1668 raw_src
= (char *) obj_coff_external_syms (abfd
);
1670 /* mark the end of the symbols */
1671 symesz
= bfd_coff_symesz (abfd
);
1672 raw_end
= (char *) raw_src
+ obj_raw_syment_count (abfd
) * symesz
;
1674 /* FIXME SOMEDAY. A string table size of zero is very weird, but
1675 probably possible. If one shows up, it will probably kill us. */
1677 /* Swap all the raw entries */
1678 for (internal_ptr
= internal
;
1680 raw_src
+= symesz
, internal_ptr
++)
1684 bfd_coff_swap_sym_in (abfd
, (PTR
) raw_src
,
1685 (PTR
) & internal_ptr
->u
.syment
);
1686 symbol_ptr
= internal_ptr
;
1689 i
< symbol_ptr
->u
.syment
.n_numaux
;
1694 bfd_coff_swap_aux_in (abfd
, (PTR
) raw_src
,
1695 symbol_ptr
->u
.syment
.n_type
,
1696 symbol_ptr
->u
.syment
.n_sclass
,
1697 (int) i
, symbol_ptr
->u
.syment
.n_numaux
,
1698 &(internal_ptr
->u
.auxent
));
1699 coff_pointerize_aux (abfd
, internal
, symbol_ptr
, i
,
1704 /* Free the raw symbols, but not the strings (if we have them). */
1705 obj_coff_keep_strings (abfd
) = TRUE
;
1706 if (! _bfd_coff_free_symbols (abfd
))
1709 for (internal_ptr
= internal
; internal_ptr
< internal_end
;
1712 if (internal_ptr
->u
.syment
.n_sclass
== C_FILE
1713 && internal_ptr
->u
.syment
.n_numaux
> 0)
1715 /* make a file symbol point to the name in the auxent, since
1716 the text ".file" is redundant */
1717 if ((internal_ptr
+ 1)->u
.auxent
.x_file
.x_n
.x_zeroes
== 0)
1719 /* the filename is a long one, point into the string table */
1720 if (string_table
== NULL
)
1722 string_table
= _bfd_coff_read_string_table (abfd
);
1723 if (string_table
== NULL
)
1727 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1730 + (internal_ptr
+ 1)->u
.auxent
.x_file
.x_n
.x_offset
));
1734 /* Ordinary short filename, put into memory anyway. The
1735 Microsoft PE tools sometimes store a filename in
1736 multiple AUX entries. */
1737 if (internal_ptr
->u
.syment
.n_numaux
> 1
1738 && coff_data (abfd
)->pe
)
1740 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1743 (internal_ptr
+ 1)->u
.auxent
.x_file
.x_fname
,
1744 internal_ptr
->u
.syment
.n_numaux
* symesz
));
1748 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1751 (internal_ptr
+ 1)->u
.auxent
.x_file
.x_fname
,
1752 (size_t) bfd_coff_filnmlen (abfd
)));
1758 if (internal_ptr
->u
.syment
._n
._n_n
._n_zeroes
!= 0)
1760 /* This is a "short" name. Make it long. */
1764 /* find the length of this string without walking into memory
1766 for (i
= 0; i
< 8; ++i
)
1767 if (internal_ptr
->u
.syment
._n
._n_name
[i
] == '\0')
1770 newstring
= (PTR
) bfd_zalloc (abfd
, (bfd_size_type
) (i
+ 1));
1771 if (newstring
== NULL
)
1773 strncpy (newstring
, internal_ptr
->u
.syment
._n
._n_name
, i
);
1774 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int) newstring
;
1775 internal_ptr
->u
.syment
._n
._n_n
._n_zeroes
= 0;
1777 else if (internal_ptr
->u
.syment
._n
._n_n
._n_offset
== 0)
1778 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int) "";
1779 else if (!bfd_coff_symname_in_debug (abfd
, &internal_ptr
->u
.syment
))
1781 /* Long name already. Point symbol at the string in the
1783 if (string_table
== NULL
)
1785 string_table
= _bfd_coff_read_string_table (abfd
);
1786 if (string_table
== NULL
)
1789 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1792 + internal_ptr
->u
.syment
._n
._n_n
._n_offset
));
1796 /* Long name in debug section. Very similar. */
1797 if (debug_section
== NULL
)
1798 debug_section
= build_debug_section (abfd
);
1799 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int)
1800 (debug_section
+ internal_ptr
->u
.syment
._n
._n_n
._n_offset
);
1803 internal_ptr
+= internal_ptr
->u
.syment
.n_numaux
;
1806 obj_raw_syments (abfd
) = internal
;
1807 BFD_ASSERT (obj_raw_syment_count (abfd
)
1808 == (unsigned int) (internal_ptr
- internal
));
1811 } /* coff_get_normalized_symtab() */
1814 coff_get_reloc_upper_bound (abfd
, asect
)
1818 if (bfd_get_format (abfd
) != bfd_object
)
1820 bfd_set_error (bfd_error_invalid_operation
);
1823 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
1827 coff_make_empty_symbol (abfd
)
1830 bfd_size_type amt
= sizeof (coff_symbol_type
);
1831 coff_symbol_type
*new = (coff_symbol_type
*) bfd_zalloc (abfd
, amt
);
1834 new->symbol
.section
= 0;
1836 new->lineno
= (alent
*) NULL
;
1837 new->done_lineno
= FALSE
;
1838 new->symbol
.the_bfd
= abfd
;
1839 return &new->symbol
;
1842 /* Make a debugging symbol. */
1845 coff_bfd_make_debug_symbol (abfd
, ptr
, sz
)
1847 PTR ptr ATTRIBUTE_UNUSED
;
1848 unsigned long sz ATTRIBUTE_UNUSED
;
1850 bfd_size_type amt
= sizeof (coff_symbol_type
);
1851 coff_symbol_type
*new = (coff_symbol_type
*) bfd_alloc (abfd
, amt
);
1854 /* @@ The 10 is a guess at a plausible maximum number of aux entries
1855 (but shouldn't be a constant). */
1856 amt
= sizeof (combined_entry_type
) * 10;
1857 new->native
= (combined_entry_type
*) bfd_zalloc (abfd
, amt
);
1860 new->symbol
.section
= bfd_abs_section_ptr
;
1861 new->symbol
.flags
= BSF_DEBUGGING
;
1862 new->lineno
= (alent
*) NULL
;
1863 new->done_lineno
= FALSE
;
1864 new->symbol
.the_bfd
= abfd
;
1865 return &new->symbol
;
1869 coff_get_symbol_info (abfd
, symbol
, ret
)
1874 bfd_symbol_info (symbol
, ret
);
1875 if (coffsymbol (symbol
)->native
!= NULL
1876 && coffsymbol (symbol
)->native
->fix_value
)
1878 ret
->value
= coffsymbol (symbol
)->native
->u
.syment
.n_value
-
1879 (unsigned long) obj_raw_syments (abfd
);
1883 /* Return the COFF syment for a symbol. */
1886 bfd_coff_get_syment (abfd
, symbol
, psyment
)
1889 struct internal_syment
*psyment
;
1891 coff_symbol_type
*csym
;
1893 csym
= coff_symbol_from (abfd
, symbol
);
1894 if (csym
== NULL
|| csym
->native
== NULL
)
1896 bfd_set_error (bfd_error_invalid_operation
);
1900 *psyment
= csym
->native
->u
.syment
;
1902 if (csym
->native
->fix_value
)
1903 psyment
->n_value
= psyment
->n_value
-
1904 (unsigned long) obj_raw_syments (abfd
);
1906 /* FIXME: We should handle fix_line here. */
1911 /* Return the COFF auxent for a symbol. */
1914 bfd_coff_get_auxent (abfd
, symbol
, indx
, pauxent
)
1918 union internal_auxent
*pauxent
;
1920 coff_symbol_type
*csym
;
1921 combined_entry_type
*ent
;
1923 csym
= coff_symbol_from (abfd
, symbol
);
1926 || csym
->native
== NULL
1927 || indx
>= csym
->native
->u
.syment
.n_numaux
)
1929 bfd_set_error (bfd_error_invalid_operation
);
1933 ent
= csym
->native
+ indx
+ 1;
1935 *pauxent
= ent
->u
.auxent
;
1938 pauxent
->x_sym
.x_tagndx
.l
=
1939 ((combined_entry_type
*) pauxent
->x_sym
.x_tagndx
.p
1940 - obj_raw_syments (abfd
));
1943 pauxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
1944 ((combined_entry_type
*) pauxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
1945 - obj_raw_syments (abfd
));
1947 if (ent
->fix_scnlen
)
1948 pauxent
->x_csect
.x_scnlen
.l
=
1949 ((combined_entry_type
*) pauxent
->x_csect
.x_scnlen
.p
1950 - obj_raw_syments (abfd
));
1955 /* Print out information about COFF symbol. */
1958 coff_print_symbol (abfd
, filep
, symbol
, how
)
1962 bfd_print_symbol_type how
;
1964 FILE *file
= (FILE *) filep
;
1968 case bfd_print_symbol_name
:
1969 fprintf (file
, "%s", symbol
->name
);
1972 case bfd_print_symbol_more
:
1973 fprintf (file
, "coff %s %s",
1974 coffsymbol (symbol
)->native
? "n" : "g",
1975 coffsymbol (symbol
)->lineno
? "l" : " ");
1978 case bfd_print_symbol_all
:
1979 if (coffsymbol (symbol
)->native
)
1983 combined_entry_type
*combined
= coffsymbol (symbol
)->native
;
1984 combined_entry_type
*root
= obj_raw_syments (abfd
);
1985 struct lineno_cache_entry
*l
= coffsymbol (symbol
)->lineno
;
1987 fprintf (file
, "[%3ld]", (long) (combined
- root
));
1989 if (! combined
->fix_value
)
1990 val
= (bfd_vma
) combined
->u
.syment
.n_value
;
1992 val
= combined
->u
.syment
.n_value
- (unsigned long) root
;
1996 "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s",
1997 combined
->u
.syment
.n_scnum
,
1998 combined
->u
.syment
.n_flags
,
1999 combined
->u
.syment
.n_type
,
2000 combined
->u
.syment
.n_sclass
,
2001 combined
->u
.syment
.n_numaux
,
2002 (unsigned long) val
,
2005 /* Print out the wide, 64 bit, symbol value */
2007 "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%016llx %s",
2008 combined
->u
.syment
.n_scnum
,
2009 combined
->u
.syment
.n_flags
,
2010 combined
->u
.syment
.n_type
,
2011 combined
->u
.syment
.n_sclass
,
2012 combined
->u
.syment
.n_numaux
,
2017 for (aux
= 0; aux
< combined
->u
.syment
.n_numaux
; aux
++)
2019 combined_entry_type
*auxp
= combined
+ aux
+ 1;
2023 tagndx
= auxp
->u
.auxent
.x_sym
.x_tagndx
.p
- root
;
2025 tagndx
= auxp
->u
.auxent
.x_sym
.x_tagndx
.l
;
2027 fprintf (file
, "\n");
2029 if (bfd_coff_print_aux (abfd
, file
, root
, combined
, auxp
, aux
))
2032 switch (combined
->u
.syment
.n_sclass
)
2035 fprintf (file
, "File ");
2039 if (combined
->u
.syment
.n_type
== T_NULL
)
2040 /* probably a section symbol? */
2042 fprintf (file
, "AUX scnlen 0x%lx nreloc %d nlnno %d",
2043 (long) auxp
->u
.auxent
.x_scn
.x_scnlen
,
2044 auxp
->u
.auxent
.x_scn
.x_nreloc
,
2045 auxp
->u
.auxent
.x_scn
.x_nlinno
);
2046 if (auxp
->u
.auxent
.x_scn
.x_checksum
!= 0
2047 || auxp
->u
.auxent
.x_scn
.x_associated
!= 0
2048 || auxp
->u
.auxent
.x_scn
.x_comdat
!= 0)
2049 fprintf (file
, " checksum 0x%lx assoc %d comdat %d",
2050 auxp
->u
.auxent
.x_scn
.x_checksum
,
2051 auxp
->u
.auxent
.x_scn
.x_associated
,
2052 auxp
->u
.auxent
.x_scn
.x_comdat
);
2055 /* else fall through */
2057 if (ISFCN (combined
->u
.syment
.n_type
))
2062 next
= (auxp
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
2065 next
= auxp
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
2066 llnos
= auxp
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
;
2068 "AUX tagndx %ld ttlsiz 0x%lx lnnos %ld next %ld",
2069 tagndx
, auxp
->u
.auxent
.x_sym
.x_misc
.x_fsize
,
2073 /* else fall through */
2075 fprintf (file
, "AUX lnno %d size 0x%x tagndx %ld",
2076 auxp
->u
.auxent
.x_sym
.x_misc
.x_lnsz
.x_lnno
,
2077 auxp
->u
.auxent
.x_sym
.x_misc
.x_lnsz
.x_size
,
2080 fprintf (file
, " endndx %ld",
2082 (auxp
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
2090 fprintf (file
, "\n%s :", l
->u
.sym
->name
);
2092 while (l
->line_number
)
2094 fprintf (file
, "\n%4d : 0x%lx",
2097 (l
->u
.offset
+ symbol
->section
->vma
)));
2104 bfd_print_symbol_vandf (abfd
, (PTR
) file
, symbol
);
2105 fprintf (file
, " %-5s %s %s %s",
2106 symbol
->section
->name
,
2107 coffsymbol (symbol
)->native
? "n" : "g",
2108 coffsymbol (symbol
)->lineno
? "l" : " ",
2114 /* Return whether a symbol name implies a local symbol. In COFF,
2115 local symbols generally start with ``.L''. Most targets use this
2116 function for the is_local_label_name entry point, but some may
2120 _bfd_coff_is_local_label_name (abfd
, name
)
2121 bfd
*abfd ATTRIBUTE_UNUSED
;
2124 return name
[0] == '.' && name
[1] == 'L';
2127 /* Provided a BFD, a section and an offset (in bytes, not octets) into the
2128 section, calculate and return the name of the source file and the line
2129 nearest to the wanted location. */
2132 coff_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2133 functionname_ptr
, line_ptr
)
2138 const char **filename_ptr
;
2139 const char **functionname_ptr
;
2140 unsigned int *line_ptr
;
2144 unsigned int line_base
;
2145 coff_data_type
*cof
= coff_data (abfd
);
2146 /* Run through the raw syments if available */
2147 combined_entry_type
*p
;
2148 combined_entry_type
*pend
;
2150 struct coff_section_tdata
*sec_data
;
2153 /* Before looking through the symbol table, try to use a .stab
2154 section to find the information. */
2155 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
2156 &found
, filename_ptr
,
2157 functionname_ptr
, line_ptr
,
2158 &coff_data(abfd
)->line_info
))
2164 /* Also try examining DWARF2 debugging information. */
2165 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
2166 filename_ptr
, functionname_ptr
,
2168 &coff_data(abfd
)->dwarf2_find_line_info
))
2172 *functionname_ptr
= 0;
2175 /* Don't try and find line numbers in a non coff file */
2176 if (!bfd_family_coff (abfd
))
2182 /* Find the first C_FILE symbol. */
2183 p
= cof
->raw_syments
;
2187 pend
= p
+ cof
->raw_syment_count
;
2190 if (p
->u
.syment
.n_sclass
== C_FILE
)
2192 p
+= 1 + p
->u
.syment
.n_numaux
;
2200 /* Look through the C_FILE symbols to find the best one. */
2201 sec_vma
= bfd_get_section_vma (abfd
, section
);
2202 *filename_ptr
= (char *) p
->u
.syment
._n
._n_n
._n_offset
;
2203 maxdiff
= (bfd_vma
) 0 - (bfd_vma
) 1;
2206 combined_entry_type
*p2
;
2208 for (p2
= p
+ 1 + p
->u
.syment
.n_numaux
;
2210 p2
+= 1 + p2
->u
.syment
.n_numaux
)
2212 if (p2
->u
.syment
.n_scnum
> 0
2214 == coff_section_from_bfd_index (abfd
,
2215 p2
->u
.syment
.n_scnum
)))
2217 if (p2
->u
.syment
.n_sclass
== C_FILE
)
2224 /* We use <= MAXDIFF here so that if we get a zero length
2225 file, we actually use the next file entry. */
2227 && offset
+ sec_vma
>= (bfd_vma
) p2
->u
.syment
.n_value
2228 && offset
+ sec_vma
- (bfd_vma
) p2
->u
.syment
.n_value
<= maxdiff
)
2230 *filename_ptr
= (char *) p
->u
.syment
._n
._n_n
._n_offset
;
2231 maxdiff
= offset
+ sec_vma
- p2
->u
.syment
.n_value
;
2234 /* Avoid endless loops on erroneous files by ensuring that
2235 we always move forward in the file. */
2236 if (p
>= cof
->raw_syments
+ p
->u
.syment
.n_value
)
2239 p
= cof
->raw_syments
+ p
->u
.syment
.n_value
;
2240 if (p
> pend
|| p
->u
.syment
.n_sclass
!= C_FILE
)
2245 /* Now wander though the raw linenumbers of the section */
2246 /* If we have been called on this section before, and the offset we
2247 want is further down then we can prime the lookup loop. */
2248 sec_data
= coff_section_data (abfd
, section
);
2249 if (sec_data
!= NULL
2251 && offset
>= sec_data
->offset
)
2254 *functionname_ptr
= sec_data
->function
;
2255 line_base
= sec_data
->line_base
;
2263 if (section
->lineno
!= NULL
)
2265 bfd_vma last_value
= 0;
2267 l
= §ion
->lineno
[i
];
2269 for (; i
< section
->lineno_count
; i
++)
2271 if (l
->line_number
== 0)
2273 /* Get the symbol this line number points at */
2274 coff_symbol_type
*coff
= (coff_symbol_type
*) (l
->u
.sym
);
2275 if (coff
->symbol
.value
> offset
)
2277 *functionname_ptr
= coff
->symbol
.name
;
2278 last_value
= coff
->symbol
.value
;
2281 combined_entry_type
*s
= coff
->native
;
2282 s
= s
+ 1 + s
->u
.syment
.n_numaux
;
2284 /* In XCOFF a debugging symbol can follow the
2286 if (s
->u
.syment
.n_scnum
== N_DEBUG
)
2287 s
= s
+ 1 + s
->u
.syment
.n_numaux
;
2289 /* S should now point to the .bf of the function. */
2290 if (s
->u
.syment
.n_numaux
)
2292 /* The linenumber is stored in the auxent. */
2293 union internal_auxent
*a
= &((s
+ 1)->u
.auxent
);
2294 line_base
= a
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
2295 *line_ptr
= line_base
;
2301 if (l
->u
.offset
> offset
)
2303 *line_ptr
= l
->line_number
+ line_base
- 1;
2308 /* If we fell off the end of the loop, then assume that this
2309 symbol has no line number info. Otherwise, symbols with no
2310 line number info get reported with the line number of the
2311 last line of the last symbol which does have line number
2312 info. We use 0x100 as a slop to account for cases where the
2313 last line has executable code. */
2314 if (i
>= section
->lineno_count
2316 && offset
- last_value
> 0x100)
2318 *functionname_ptr
= NULL
;
2323 /* Cache the results for the next call. */
2324 if (sec_data
== NULL
&& section
->owner
== abfd
)
2326 amt
= sizeof (struct coff_section_tdata
);
2327 section
->used_by_bfd
= (PTR
) bfd_zalloc (abfd
, amt
);
2328 sec_data
= (struct coff_section_tdata
*) section
->used_by_bfd
;
2330 if (sec_data
!= NULL
)
2332 sec_data
->offset
= offset
;
2334 sec_data
->function
= *functionname_ptr
;
2335 sec_data
->line_base
= line_base
;
2342 coff_sizeof_headers (abfd
, reloc
)
2350 size
= bfd_coff_filhsz (abfd
) + bfd_coff_aoutsz (abfd
);
2354 size
= bfd_coff_filhsz (abfd
);
2357 size
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
2361 /* Change the class of a coff symbol held by BFD. */
2363 bfd_coff_set_symbol_class (abfd
, symbol
, class)
2368 coff_symbol_type
* csym
;
2370 csym
= coff_symbol_from (abfd
, symbol
);
2373 bfd_set_error (bfd_error_invalid_operation
);
2376 else if (csym
->native
== NULL
)
2378 /* This is an alien symbol which no native coff backend data.
2379 We cheat here by creating a fake native entry for it and
2380 then filling in the class. This code is based on that in
2381 coff_write_alien_symbol(). */
2383 combined_entry_type
* native
;
2384 bfd_size_type amt
= sizeof (* native
);
2386 native
= (combined_entry_type
*) bfd_zalloc (abfd
, amt
);
2390 native
->u
.syment
.n_type
= T_NULL
;
2391 native
->u
.syment
.n_sclass
= class;
2393 if (bfd_is_und_section (symbol
->section
))
2395 native
->u
.syment
.n_scnum
= N_UNDEF
;
2396 native
->u
.syment
.n_value
= symbol
->value
;
2398 else if (bfd_is_com_section (symbol
->section
))
2400 native
->u
.syment
.n_scnum
= N_UNDEF
;
2401 native
->u
.syment
.n_value
= symbol
->value
;
2405 native
->u
.syment
.n_scnum
=
2406 symbol
->section
->output_section
->target_index
;
2407 native
->u
.syment
.n_value
= (symbol
->value
2408 + symbol
->section
->output_offset
);
2409 if (! obj_pe (abfd
))
2410 native
->u
.syment
.n_value
+= symbol
->section
->output_section
->vma
;
2412 /* Copy the any flags from the file header into the symbol.
2414 native
->u
.syment
.n_flags
= bfd_asymbol_bfd (& csym
->symbol
)->flags
;
2417 csym
->native
= native
;
2421 csym
->native
->u
.syment
.n_sclass
= class;
2427 struct coff_comdat_info
*
2428 bfd_coff_get_comdat_section (bfd
*abfd
, struct bfd_section
*sec
)
2430 if (bfd_get_flavour (abfd
) == bfd_target_coff_flavour
)
2431 return coff_section_data (abfd
, sec
)->comdat
;