1 /* Support for the generic parts of COFF, for BFD.
2 Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
4 Written by Cygnus Support.
6 This file is part of BFD, the Binary File Descriptor library.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
22 /* Most of this hacked by Steve Chamberlain, sac@cygnus.com.
23 Split out of coffcode.h by Ian Taylor, ian@cygnus.com. */
25 /* This file contains COFF code that is not dependent on any
26 particular COFF target. There is only one version of this file in
27 libbfd.a, so no target specific code may be put in here. Or, to
30 ********** DO NOT PUT TARGET SPECIFIC CODE IN THIS FILE **********
32 If you need to add some target specific behaviour, add a new hook
33 function to bfd_coff_backend_data.
35 Some of these functions are also called by the ECOFF routines.
36 Those functions may not use any COFF specific information, such as
42 #include "coff/internal.h"
45 static void coff_fix_symbol_name
46 PARAMS ((bfd
*, asymbol
*, combined_entry_type
*, bfd_size_type
*,
47 asection
**, bfd_size_type
*));
48 static boolean coff_write_symbol
49 PARAMS ((bfd
*, asymbol
*, combined_entry_type
*, unsigned int *,
50 bfd_size_type
*, asection
**, bfd_size_type
*));
51 static boolean coff_write_alien_symbol
52 PARAMS ((bfd
*, asymbol
*, unsigned int *, bfd_size_type
*,
53 asection
**, bfd_size_type
*));
54 static boolean coff_write_native_symbol
55 PARAMS ((bfd
*, coff_symbol_type
*, unsigned int *, bfd_size_type
*,
56 asection
**, bfd_size_type
*));
57 static void coff_pointerize_aux
58 PARAMS ((bfd
*, combined_entry_type
*, combined_entry_type
*,
59 unsigned int, combined_entry_type
*));
60 static boolean make_a_section_from_file
61 PARAMS ((bfd
*, struct internal_scnhdr
*, unsigned int));
62 static const bfd_target
*coff_real_object_p
63 PARAMS ((bfd
*, unsigned, struct internal_filehdr
*,
64 struct internal_aouthdr
*));
65 static void fixup_symbol_value
66 PARAMS ((bfd
*, coff_symbol_type
*, struct internal_syment
*));
67 static char *build_debug_section
69 static char *copy_name
70 PARAMS ((bfd
*, char *, int));
72 #define STRING_SIZE_SIZE (4)
74 /* Take a section header read from a coff file (in HOST byte order),
75 and make a BFD "section" out of it. This is used by ECOFF. */
77 make_a_section_from_file (abfd
, hdr
, target_index
)
79 struct internal_scnhdr
*hdr
;
80 unsigned int target_index
;
82 asection
*return_section
;
87 /* Handle long section names as in PE. */
88 if (bfd_coff_long_section_names (abfd
)
89 && hdr
->s_name
[0] == '/')
96 memcpy (buf
, hdr
->s_name
+ 1, SCNNMLEN
- 1);
97 buf
[SCNNMLEN
- 1] = '\0';
98 strindex
= strtol (buf
, &p
, 10);
99 if (*p
== '\0' && strindex
>= 0)
101 strings
= _bfd_coff_read_string_table (abfd
);
104 /* FIXME: For extra safety, we should make sure that
105 strindex does not run us past the end, but right now we
106 don't know the length of the string table. */
108 name
= bfd_alloc (abfd
, strlen (strings
) + 1);
111 strcpy (name
, strings
);
117 /* Assorted wastage to null-terminate the name, thanks AT&T! */
118 name
= bfd_alloc (abfd
, sizeof (hdr
->s_name
) + 1);
121 strncpy (name
, (char *) &hdr
->s_name
[0], sizeof (hdr
->s_name
));
122 name
[sizeof (hdr
->s_name
)] = 0;
125 return_section
= bfd_make_section_anyway (abfd
, name
);
126 if (return_section
== NULL
)
129 return_section
->vma
= hdr
->s_vaddr
;
130 return_section
->lma
= hdr
->s_paddr
;
131 return_section
->_raw_size
= hdr
->s_size
;
132 return_section
->filepos
= hdr
->s_scnptr
;
133 return_section
->rel_filepos
= hdr
->s_relptr
;
134 return_section
->reloc_count
= hdr
->s_nreloc
;
136 bfd_coff_set_alignment_hook (abfd
, return_section
, hdr
);
138 return_section
->line_filepos
= hdr
->s_lnnoptr
;
140 return_section
->lineno_count
= hdr
->s_nlnno
;
141 return_section
->userdata
= NULL
;
142 return_section
->next
= (asection
*) NULL
;
143 return_section
->target_index
= target_index
;
144 return_section
->flags
= bfd_coff_styp_to_sec_flags_hook (abfd
, hdr
, name
,
147 /* At least on i386-coff, the line number count for a shared library
148 section must be ignored. */
149 if ((return_section
->flags
& SEC_COFF_SHARED_LIBRARY
) != 0)
150 return_section
->lineno_count
= 0;
152 if (hdr
->s_nreloc
!= 0)
153 return_section
->flags
|= SEC_RELOC
;
154 /* FIXME: should this check 'hdr->s_size > 0' */
155 if (hdr
->s_scnptr
!= 0)
156 return_section
->flags
|= SEC_HAS_CONTENTS
;
160 /* Read in a COFF object and make it into a BFD. This is used by
163 static const bfd_target
*
164 coff_real_object_p (abfd
, nscns
, internal_f
, internal_a
)
167 struct internal_filehdr
*internal_f
;
168 struct internal_aouthdr
*internal_a
;
170 flagword oflags
= abfd
->flags
;
171 bfd_vma ostart
= bfd_get_start_address (abfd
);
173 size_t readsize
; /* length of file_info */
175 char *external_sections
;
177 if (!(internal_f
->f_flags
& F_RELFLG
))
178 abfd
->flags
|= HAS_RELOC
;
179 if ((internal_f
->f_flags
& F_EXEC
))
180 abfd
->flags
|= EXEC_P
;
181 if (!(internal_f
->f_flags
& F_LNNO
))
182 abfd
->flags
|= HAS_LINENO
;
183 if (!(internal_f
->f_flags
& F_LSYMS
))
184 abfd
->flags
|= HAS_LOCALS
;
186 /* FIXME: How can we set D_PAGED correctly? */
187 if ((internal_f
->f_flags
& F_EXEC
) != 0)
188 abfd
->flags
|= D_PAGED
;
190 bfd_get_symcount (abfd
) = internal_f
->f_nsyms
;
191 if (internal_f
->f_nsyms
)
192 abfd
->flags
|= HAS_SYMS
;
194 if (internal_a
!= (struct internal_aouthdr
*) NULL
)
195 bfd_get_start_address (abfd
) = internal_a
->entry
;
197 bfd_get_start_address (abfd
) = 0;
199 /* Set up the tdata area. ECOFF uses its own routine, and overrides
201 tdata
= bfd_coff_mkobject_hook (abfd
, (PTR
) internal_f
, (PTR
) internal_a
);
205 scnhsz
= bfd_coff_scnhsz (abfd
);
206 readsize
= nscns
* scnhsz
;
207 external_sections
= (char *) bfd_alloc (abfd
, readsize
);
208 if (!external_sections
)
211 if (bfd_read ((PTR
) external_sections
, 1, readsize
, abfd
) != readsize
)
214 /* Now copy data as required; construct all asections etc */
218 for (i
= 0; i
< nscns
; i
++)
220 struct internal_scnhdr tmp
;
221 bfd_coff_swap_scnhdr_in (abfd
,
222 (PTR
) (external_sections
+ i
* scnhsz
),
224 if (! make_a_section_from_file (abfd
, &tmp
, i
+ 1))
229 /* make_abs_section (abfd); */
231 if (bfd_coff_set_arch_mach_hook (abfd
, (PTR
) internal_f
) == false)
237 bfd_release (abfd
, tdata
);
238 abfd
->flags
= oflags
;
239 bfd_get_start_address (abfd
) = ostart
;
240 return (const bfd_target
*) NULL
;
243 /* Turn a COFF file into a BFD, but fail with bfd_error_wrong_format if it is
244 not a COFF file. This is also used by ECOFF. */
254 struct internal_filehdr internal_f
;
255 struct internal_aouthdr internal_a
;
257 /* figure out how much to read */
258 filhsz
= bfd_coff_filhsz (abfd
);
259 aoutsz
= bfd_coff_aoutsz (abfd
);
261 filehdr
= bfd_alloc (abfd
, filhsz
);
264 if (bfd_read (filehdr
, 1, filhsz
, abfd
) != filhsz
)
266 if (bfd_get_error () != bfd_error_system_call
)
267 bfd_set_error (bfd_error_wrong_format
);
270 bfd_coff_swap_filehdr_in (abfd
, filehdr
, &internal_f
);
271 bfd_release (abfd
, filehdr
);
273 if (bfd_coff_bad_format_hook (abfd
, &internal_f
) == false)
275 bfd_set_error (bfd_error_wrong_format
);
278 nscns
= internal_f
.f_nscns
;
280 if (internal_f
.f_opthdr
)
284 opthdr
= bfd_alloc (abfd
, aoutsz
);
287 if (bfd_read (opthdr
, 1, internal_f
.f_opthdr
, abfd
)
288 != internal_f
.f_opthdr
)
292 bfd_coff_swap_aouthdr_in (abfd
, opthdr
, (PTR
) &internal_a
);
295 return coff_real_object_p (abfd
, nscns
, &internal_f
,
296 (internal_f
.f_opthdr
!= 0
298 : (struct internal_aouthdr
*) NULL
));
301 /* Get the BFD section from a COFF symbol section number. */
304 coff_section_from_bfd_index (abfd
, index
)
308 struct sec
*answer
= abfd
->sections
;
311 return bfd_abs_section_ptr
;
312 if (index
== N_UNDEF
)
313 return bfd_und_section_ptr
;
314 if (index
== N_DEBUG
)
315 return bfd_abs_section_ptr
;
319 if (answer
->target_index
== index
)
321 answer
= answer
->next
;
324 /* We should not reach this point, but the SCO 3.2v4 /lib/libc_s.a
325 has a bad symbol table in biglitpow.o. */
326 return bfd_und_section_ptr
;
329 /* Get the upper bound of a COFF symbol table. */
332 coff_get_symtab_upper_bound (abfd
)
335 if (!bfd_coff_slurp_symbol_table (abfd
))
338 return (bfd_get_symcount (abfd
) + 1) * (sizeof (coff_symbol_type
*));
342 /* Canonicalize a COFF symbol table. */
345 coff_get_symtab (abfd
, alocation
)
349 unsigned int counter
;
350 coff_symbol_type
*symbase
;
351 coff_symbol_type
**location
= (coff_symbol_type
**) alocation
;
353 if (!bfd_coff_slurp_symbol_table (abfd
))
356 symbase
= obj_symbols (abfd
);
357 counter
= bfd_get_symcount (abfd
);
358 while (counter
-- > 0)
359 *location
++ = symbase
++;
363 return bfd_get_symcount (abfd
);
366 /* Get the name of a symbol. The caller must pass in a buffer of size
370 _bfd_coff_internal_syment_name (abfd
, sym
, buf
)
372 const struct internal_syment
*sym
;
375 /* FIXME: It's not clear this will work correctly if sizeof
377 if (sym
->_n
._n_n
._n_zeroes
!= 0
378 || sym
->_n
._n_n
._n_offset
== 0)
380 memcpy (buf
, sym
->_n
._n_name
, SYMNMLEN
);
381 buf
[SYMNMLEN
] = '\0';
388 BFD_ASSERT (sym
->_n
._n_n
._n_offset
>= STRING_SIZE_SIZE
);
389 strings
= obj_coff_strings (abfd
);
392 strings
= _bfd_coff_read_string_table (abfd
);
396 return strings
+ sym
->_n
._n_n
._n_offset
;
400 /* Read in and swap the relocs. This returns a buffer holding the
401 relocs for section SEC in file ABFD. If CACHE is true and
402 INTERNAL_RELOCS is NULL, the relocs read in will be saved in case
403 the function is called again. If EXTERNAL_RELOCS is not NULL, it
404 is a buffer large enough to hold the unswapped relocs. If
405 INTERNAL_RELOCS is not NULL, it is a buffer large enough to hold
406 the swapped relocs. If REQUIRE_INTERNAL is true, then the return
407 value must be INTERNAL_RELOCS. The function returns NULL on error. */
409 struct internal_reloc
*
410 _bfd_coff_read_internal_relocs (abfd
, sec
, cache
, external_relocs
,
411 require_internal
, internal_relocs
)
415 bfd_byte
*external_relocs
;
416 boolean require_internal
;
417 struct internal_reloc
*internal_relocs
;
420 bfd_byte
*free_external
= NULL
;
421 struct internal_reloc
*free_internal
= NULL
;
424 struct internal_reloc
*irel
;
426 if (coff_section_data (abfd
, sec
) != NULL
427 && coff_section_data (abfd
, sec
)->relocs
!= NULL
)
429 if (! require_internal
)
430 return coff_section_data (abfd
, sec
)->relocs
;
431 memcpy (internal_relocs
, coff_section_data (abfd
, sec
)->relocs
,
432 sec
->reloc_count
* sizeof (struct internal_reloc
));
433 return internal_relocs
;
436 relsz
= bfd_coff_relsz (abfd
);
438 if (external_relocs
== NULL
)
440 free_external
= (bfd_byte
*) bfd_malloc (sec
->reloc_count
* relsz
);
441 if (free_external
== NULL
&& sec
->reloc_count
> 0)
443 external_relocs
= free_external
;
446 if (bfd_seek (abfd
, sec
->rel_filepos
, SEEK_SET
) != 0
447 || (bfd_read (external_relocs
, relsz
, sec
->reloc_count
, abfd
)
448 != relsz
* sec
->reloc_count
))
451 if (internal_relocs
== NULL
)
453 free_internal
= ((struct internal_reloc
*)
454 bfd_malloc (sec
->reloc_count
455 * sizeof (struct internal_reloc
)));
456 if (free_internal
== NULL
&& sec
->reloc_count
> 0)
458 internal_relocs
= free_internal
;
461 /* Swap in the relocs. */
462 erel
= external_relocs
;
463 erel_end
= erel
+ relsz
* sec
->reloc_count
;
464 irel
= internal_relocs
;
465 for (; erel
< erel_end
; erel
+= relsz
, irel
++)
466 bfd_coff_swap_reloc_in (abfd
, (PTR
) erel
, (PTR
) irel
);
468 if (free_external
!= NULL
)
470 free (free_external
);
471 free_external
= NULL
;
474 if (cache
&& free_internal
!= NULL
)
476 if (coff_section_data (abfd
, sec
) == NULL
)
479 (PTR
) bfd_zalloc (abfd
,
480 sizeof (struct coff_section_tdata
));
481 if (sec
->used_by_bfd
== NULL
)
483 coff_section_data (abfd
, sec
)->contents
= NULL
;
485 coff_section_data (abfd
, sec
)->relocs
= free_internal
;
488 return internal_relocs
;
491 if (free_external
!= NULL
)
492 free (free_external
);
493 if (free_internal
!= NULL
)
494 free (free_internal
);
498 /* Set lineno_count for the output sections of a COFF file. */
501 coff_count_linenumbers (abfd
)
504 unsigned int limit
= bfd_get_symcount (abfd
);
512 /* This may be from the backend linker, in which case the
513 lineno_count in the sections is correct. */
514 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
515 total
+= s
->lineno_count
;
519 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
520 BFD_ASSERT (s
->lineno_count
== 0);
522 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++)
524 asymbol
*q_maybe
= *p
;
526 if (bfd_asymbol_flavour (q_maybe
) == bfd_target_coff_flavour
)
528 coff_symbol_type
*q
= coffsymbol (q_maybe
);
530 /* The AIX 4.1 compiler can sometimes generate line numbers
531 attached to debugging symbols. We try to simply ignore
533 if (q
->lineno
!= NULL
534 && q
->symbol
.section
->owner
!= NULL
)
536 /* This symbol has line numbers. Increment the owning
537 section's linenumber count. */
538 alent
*l
= q
->lineno
;
540 ++q
->symbol
.section
->output_section
->lineno_count
;
543 while (l
->line_number
!= 0)
546 ++q
->symbol
.section
->output_section
->lineno_count
;
556 /* Takes a bfd and a symbol, returns a pointer to the coff specific
557 area of the symbol if there is one. */
561 coff_symbol_from (ignore_abfd
, symbol
)
562 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
565 if (bfd_asymbol_flavour (symbol
) != bfd_target_coff_flavour
)
566 return (coff_symbol_type
*) NULL
;
568 if (bfd_asymbol_bfd (symbol
)->tdata
.coff_obj_data
== (coff_data_type
*) NULL
)
569 return (coff_symbol_type
*) NULL
;
571 return (coff_symbol_type
*) symbol
;
575 fixup_symbol_value (abfd
, coff_symbol_ptr
, syment
)
577 coff_symbol_type
*coff_symbol_ptr
;
578 struct internal_syment
*syment
;
581 /* Normalize the symbol flags */
582 if (bfd_is_com_section (coff_symbol_ptr
->symbol
.section
))
584 /* a common symbol is undefined with a value */
585 syment
->n_scnum
= N_UNDEF
;
586 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
588 else if (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
)
590 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
592 else if (bfd_is_und_section (coff_symbol_ptr
->symbol
.section
))
594 syment
->n_scnum
= N_UNDEF
;
597 /* FIXME: Do we need to handle the absolute section here? */
600 if (coff_symbol_ptr
->symbol
.section
)
603 coff_symbol_ptr
->symbol
.section
->output_section
->target_index
;
605 syment
->n_value
= (coff_symbol_ptr
->symbol
.value
606 + coff_symbol_ptr
->symbol
.section
->output_offset
);
609 coff_symbol_ptr
->symbol
.section
->output_section
->vma
;
614 /* This can happen, but I don't know why yet (steve@cygnus.com) */
615 syment
->n_scnum
= N_ABS
;
616 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
621 /* Run through all the symbols in the symbol table and work out what
622 their indexes into the symbol table will be when output.
624 Coff requires that each C_FILE symbol points to the next one in the
625 chain, and that the last one points to the first external symbol. We
629 coff_renumber_symbols (bfd_ptr
, first_undef
)
633 unsigned int symbol_count
= bfd_get_symcount (bfd_ptr
);
634 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
635 unsigned int native_index
= 0;
636 struct internal_syment
*last_file
= (struct internal_syment
*) NULL
;
637 unsigned int symbol_index
;
639 /* COFF demands that undefined symbols come after all other symbols.
640 Since we don't need to impose this extra knowledge on all our
641 client programs, deal with that here. Sort the symbol table;
642 just move the undefined symbols to the end, leaving the rest
643 alone. The O'Reilly book says that defined global symbols come
644 at the end before the undefined symbols, so we do that here as
646 /* @@ Do we have some condition we could test for, so we don't always
647 have to do this? I don't think relocatability is quite right, but
648 I'm not certain. [raeburn:19920508.1711EST] */
653 newsyms
= (asymbol
**) bfd_alloc (bfd_ptr
,
654 sizeof (asymbol
*) * (symbol_count
+ 1));
657 bfd_ptr
->outsymbols
= newsyms
;
658 for (i
= 0; i
< symbol_count
; i
++)
659 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) != 0
660 || (!bfd_is_und_section (symbol_ptr_ptr
[i
]->section
)
661 && !bfd_is_com_section (symbol_ptr_ptr
[i
]->section
)
662 && ((symbol_ptr_ptr
[i
]->flags
& BSF_FUNCTION
) != 0
663 || ((symbol_ptr_ptr
[i
]->flags
& (BSF_GLOBAL
| BSF_WEAK
))
665 *newsyms
++ = symbol_ptr_ptr
[i
];
667 for (i
= 0; i
< symbol_count
; i
++)
668 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) == 0
669 && !bfd_is_und_section (symbol_ptr_ptr
[i
]->section
)
670 && (bfd_is_com_section (symbol_ptr_ptr
[i
]->section
)
671 || ((symbol_ptr_ptr
[i
]->flags
& BSF_FUNCTION
) == 0
672 && ((symbol_ptr_ptr
[i
]->flags
& (BSF_GLOBAL
| BSF_WEAK
))
674 *newsyms
++ = symbol_ptr_ptr
[i
];
676 *first_undef
= newsyms
- bfd_ptr
->outsymbols
;
678 for (i
= 0; i
< symbol_count
; i
++)
679 if ((symbol_ptr_ptr
[i
]->flags
& BSF_NOT_AT_END
) == 0
680 && bfd_is_und_section (symbol_ptr_ptr
[i
]->section
))
681 *newsyms
++ = symbol_ptr_ptr
[i
];
682 *newsyms
= (asymbol
*) NULL
;
683 symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
686 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++)
688 coff_symbol_type
*coff_symbol_ptr
= coff_symbol_from (bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
689 symbol_ptr_ptr
[symbol_index
]->udata
.i
= symbol_index
;
690 if (coff_symbol_ptr
&& coff_symbol_ptr
->native
)
692 combined_entry_type
*s
= coff_symbol_ptr
->native
;
695 if (s
->u
.syment
.n_sclass
== C_FILE
)
697 if (last_file
!= (struct internal_syment
*) NULL
)
698 last_file
->n_value
= native_index
;
699 last_file
= &(s
->u
.syment
);
704 /* Modify the symbol values according to their section and
707 fixup_symbol_value (bfd_ptr
, coff_symbol_ptr
, &(s
->u
.syment
));
709 for (i
= 0; i
< s
->u
.syment
.n_numaux
+ 1; i
++)
710 s
[i
].offset
= native_index
++;
717 obj_conv_table_size (bfd_ptr
) = native_index
;
722 /* Run thorough the symbol table again, and fix it so that all
723 pointers to entries are changed to the entries' index in the output
727 coff_mangle_symbols (bfd_ptr
)
730 unsigned int symbol_count
= bfd_get_symcount (bfd_ptr
);
731 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
732 unsigned int symbol_index
;
734 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++)
736 coff_symbol_type
*coff_symbol_ptr
=
737 coff_symbol_from (bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
739 if (coff_symbol_ptr
&& coff_symbol_ptr
->native
)
742 combined_entry_type
*s
= coff_symbol_ptr
->native
;
746 /* FIXME: We should use a union here. */
747 s
->u
.syment
.n_value
=
748 ((combined_entry_type
*) s
->u
.syment
.n_value
)->offset
;
753 /* The value is the offset into the line number entries
754 for the symbol's section. On output, the symbol's
755 section should be N_DEBUG. */
756 s
->u
.syment
.n_value
=
757 (coff_symbol_ptr
->symbol
.section
->output_section
->line_filepos
758 + s
->u
.syment
.n_value
* bfd_coff_linesz (bfd_ptr
));
759 coff_symbol_ptr
->symbol
.section
=
760 coff_section_from_bfd_index (bfd_ptr
, N_DEBUG
);
761 BFD_ASSERT (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
);
763 for (i
= 0; i
< s
->u
.syment
.n_numaux
; i
++)
765 combined_entry_type
*a
= s
+ i
+ 1;
768 a
->u
.auxent
.x_sym
.x_tagndx
.l
=
769 a
->u
.auxent
.x_sym
.x_tagndx
.p
->offset
;
774 a
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
775 a
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
->offset
;
780 a
->u
.auxent
.x_csect
.x_scnlen
.l
=
781 a
->u
.auxent
.x_csect
.x_scnlen
.p
->offset
;
790 coff_fix_symbol_name (abfd
, symbol
, native
, string_size_p
,
791 debug_string_section_p
, debug_string_size_p
)
794 combined_entry_type
*native
;
795 bfd_size_type
*string_size_p
;
796 asection
**debug_string_section_p
;
797 bfd_size_type
*debug_string_size_p
;
799 unsigned int name_length
;
800 union internal_auxent
*auxent
;
801 char *name
= (char *) (symbol
->name
);
803 if (name
== (char *) NULL
)
805 /* coff symbols always have names, so we'll make one up */
806 symbol
->name
= "strange";
807 name
= (char *) symbol
->name
;
809 name_length
= strlen (name
);
811 if (native
->u
.syment
.n_sclass
== C_FILE
812 && native
->u
.syment
.n_numaux
> 0)
814 unsigned int filnmlen
;
816 strncpy (native
->u
.syment
._n
._n_name
, ".file", SYMNMLEN
);
817 auxent
= &(native
+ 1)->u
.auxent
;
819 filnmlen
= bfd_coff_filnmlen (abfd
);
821 if (bfd_coff_long_filenames (abfd
))
823 if (name_length
<= filnmlen
)
825 strncpy (auxent
->x_file
.x_fname
, name
, filnmlen
);
829 auxent
->x_file
.x_n
.x_offset
= *string_size_p
+ STRING_SIZE_SIZE
;
830 auxent
->x_file
.x_n
.x_zeroes
= 0;
831 *string_size_p
+= name_length
+ 1;
836 strncpy (auxent
->x_file
.x_fname
, name
, filnmlen
);
837 if (name_length
> filnmlen
)
838 name
[filnmlen
] = '\0';
843 if (name_length
<= SYMNMLEN
)
845 /* This name will fit into the symbol neatly */
846 strncpy (native
->u
.syment
._n
._n_name
, symbol
->name
, SYMNMLEN
);
848 else if (!bfd_coff_symname_in_debug (abfd
, &native
->u
.syment
))
850 native
->u
.syment
._n
._n_n
._n_offset
= (*string_size_p
852 native
->u
.syment
._n
._n_n
._n_zeroes
= 0;
853 *string_size_p
+= name_length
+ 1;
860 /* This name should be written into the .debug section. For
861 some reason each name is preceded by a two byte length
862 and also followed by a null byte. FIXME: We assume that
863 the .debug section has already been created, and that it
865 if (*debug_string_section_p
== (asection
*) NULL
)
866 *debug_string_section_p
= bfd_get_section_by_name (abfd
, ".debug");
867 filepos
= bfd_tell (abfd
);
868 bfd_put_16 (abfd
, name_length
+ 1, buf
);
869 if (!bfd_set_section_contents (abfd
,
870 *debug_string_section_p
,
872 (file_ptr
) *debug_string_size_p
,
874 || !bfd_set_section_contents (abfd
,
875 *debug_string_section_p
,
877 ((file_ptr
) *debug_string_size_p
879 (bfd_size_type
) name_length
+ 1))
881 if (bfd_seek (abfd
, filepos
, SEEK_SET
) != 0)
883 native
->u
.syment
._n
._n_n
._n_offset
= *debug_string_size_p
+ 2;
884 native
->u
.syment
._n
._n_n
._n_zeroes
= 0;
885 *debug_string_size_p
+= name_length
+ 3;
890 /* We need to keep track of the symbol index so that when we write out
891 the relocs we can get the index for a symbol. This method is a
894 #define set_index(symbol, idx) ((symbol)->udata.i = (idx))
896 /* Write a symbol out to a COFF file. */
899 coff_write_symbol (abfd
, symbol
, native
, written
, string_size_p
,
900 debug_string_section_p
, debug_string_size_p
)
903 combined_entry_type
*native
;
904 unsigned int *written
;
905 bfd_size_type
*string_size_p
;
906 asection
**debug_string_section_p
;
907 bfd_size_type
*debug_string_size_p
;
909 unsigned int numaux
= native
->u
.syment
.n_numaux
;
910 int type
= native
->u
.syment
.n_type
;
911 int class = native
->u
.syment
.n_sclass
;
913 bfd_size_type symesz
;
915 if (native
->u
.syment
.n_sclass
== C_FILE
)
916 symbol
->flags
|= BSF_DEBUGGING
;
918 if (symbol
->flags
& BSF_DEBUGGING
919 && bfd_is_abs_section (symbol
->section
))
921 native
->u
.syment
.n_scnum
= N_DEBUG
;
923 else if (bfd_is_abs_section (symbol
->section
))
925 native
->u
.syment
.n_scnum
= N_ABS
;
927 else if (bfd_is_und_section (symbol
->section
))
929 native
->u
.syment
.n_scnum
= N_UNDEF
;
933 native
->u
.syment
.n_scnum
=
934 symbol
->section
->output_section
->target_index
;
937 coff_fix_symbol_name (abfd
, symbol
, native
, string_size_p
,
938 debug_string_section_p
, debug_string_size_p
);
940 symesz
= bfd_coff_symesz (abfd
);
941 buf
= bfd_alloc (abfd
, symesz
);
944 bfd_coff_swap_sym_out (abfd
, &native
->u
.syment
, buf
);
945 if (bfd_write (buf
, 1, symesz
, abfd
) != symesz
)
947 bfd_release (abfd
, buf
);
949 if (native
->u
.syment
.n_numaux
> 0)
951 bfd_size_type auxesz
;
954 auxesz
= bfd_coff_auxesz (abfd
);
955 buf
= bfd_alloc (abfd
, auxesz
);
958 for (j
= 0; j
< native
->u
.syment
.n_numaux
; j
++)
960 bfd_coff_swap_aux_out (abfd
,
961 &((native
+ j
+ 1)->u
.auxent
),
965 native
->u
.syment
.n_numaux
,
967 if (bfd_write (buf
, 1, auxesz
, abfd
) != auxesz
)
970 bfd_release (abfd
, buf
);
973 /* Store the index for use when we write out the relocs. */
974 set_index (symbol
, *written
);
976 *written
+= numaux
+ 1;
980 /* Write out a symbol to a COFF file that does not come from a COFF
981 file originally. This symbol may have been created by the linker,
982 or we may be linking a non COFF file to a COFF file. */
985 coff_write_alien_symbol (abfd
, symbol
, written
, string_size_p
,
986 debug_string_section_p
, debug_string_size_p
)
989 unsigned int *written
;
990 bfd_size_type
*string_size_p
;
991 asection
**debug_string_section_p
;
992 bfd_size_type
*debug_string_size_p
;
994 combined_entry_type
*native
;
995 combined_entry_type dummy
;
998 native
->u
.syment
.n_type
= T_NULL
;
999 native
->u
.syment
.n_flags
= 0;
1000 if (bfd_is_und_section (symbol
->section
))
1002 native
->u
.syment
.n_scnum
= N_UNDEF
;
1003 native
->u
.syment
.n_value
= symbol
->value
;
1005 else if (bfd_is_com_section (symbol
->section
))
1007 native
->u
.syment
.n_scnum
= N_UNDEF
;
1008 native
->u
.syment
.n_value
= symbol
->value
;
1010 else if (symbol
->flags
& BSF_DEBUGGING
)
1012 /* There isn't much point to writing out a debugging symbol
1013 unless we are prepared to convert it into COFF debugging
1014 format. So, we just ignore them. We must clobber the symbol
1015 name to keep it from being put in the string table. */
1021 native
->u
.syment
.n_scnum
=
1022 symbol
->section
->output_section
->target_index
;
1023 native
->u
.syment
.n_value
= (symbol
->value
1024 + symbol
->section
->output_offset
);
1025 if (! obj_pe (abfd
))
1026 native
->u
.syment
.n_value
+= symbol
->section
->output_section
->vma
;
1028 /* Copy the any flags from the the file header into the symbol.
1031 coff_symbol_type
*c
= coff_symbol_from (abfd
, symbol
);
1032 if (c
!= (coff_symbol_type
*) NULL
)
1033 native
->u
.syment
.n_flags
= bfd_asymbol_bfd (&c
->symbol
)->flags
;
1037 native
->u
.syment
.n_type
= 0;
1038 if (symbol
->flags
& BSF_LOCAL
)
1039 native
->u
.syment
.n_sclass
= C_STAT
;
1040 else if (symbol
->flags
& BSF_WEAK
)
1041 native
->u
.syment
.n_sclass
= obj_pe (abfd
) ? C_NT_WEAK
: C_WEAKEXT
;
1043 native
->u
.syment
.n_sclass
= C_EXT
;
1044 native
->u
.syment
.n_numaux
= 0;
1046 return coff_write_symbol (abfd
, symbol
, native
, written
, string_size_p
,
1047 debug_string_section_p
, debug_string_size_p
);
1050 /* Write a native symbol to a COFF file. */
1053 coff_write_native_symbol (abfd
, symbol
, written
, string_size_p
,
1054 debug_string_section_p
, debug_string_size_p
)
1056 coff_symbol_type
*symbol
;
1057 unsigned int *written
;
1058 bfd_size_type
*string_size_p
;
1059 asection
**debug_string_section_p
;
1060 bfd_size_type
*debug_string_size_p
;
1062 combined_entry_type
*native
= symbol
->native
;
1063 alent
*lineno
= symbol
->lineno
;
1065 /* If this symbol has an associated line number, we must store the
1066 symbol index in the line number field. We also tag the auxent to
1067 point to the right place in the lineno table. */
1068 if (lineno
&& !symbol
->done_lineno
&& symbol
->symbol
.section
->owner
!= NULL
)
1070 unsigned int count
= 0;
1071 lineno
[count
].u
.offset
= *written
;
1072 if (native
->u
.syment
.n_numaux
)
1074 union internal_auxent
*a
= &((native
+ 1)->u
.auxent
);
1076 a
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
1077 symbol
->symbol
.section
->output_section
->moving_line_filepos
;
1080 /* Count and relocate all other linenumbers. */
1082 while (lineno
[count
].line_number
!= 0)
1086 I've been told this, but still need proof:
1087 > The second bug is also in `bfd/coffcode.h'. This bug
1088 > causes the linker to screw up the pc-relocations for
1089 > all the line numbers in COFF code. This bug isn't only
1090 > specific to A29K implementations, but affects all
1091 > systems using COFF format binaries. Note that in COFF
1092 > object files, the line number core offsets output by
1093 > the assembler are relative to the start of each
1094 > procedure, not to the start of the .text section. This
1095 > patch relocates the line numbers relative to the
1096 > `native->u.syment.n_value' instead of the section
1098 > modular!olson@cs.arizona.edu (Jon Olson)
1100 lineno
[count
].u
.offset
+= native
->u
.syment
.n_value
;
1102 lineno
[count
].u
.offset
+=
1103 (symbol
->symbol
.section
->output_section
->vma
1104 + symbol
->symbol
.section
->output_offset
);
1108 symbol
->done_lineno
= true;
1110 symbol
->symbol
.section
->output_section
->moving_line_filepos
+=
1111 count
* bfd_coff_linesz (abfd
);
1114 return coff_write_symbol (abfd
, &(symbol
->symbol
), native
, written
,
1115 string_size_p
, debug_string_section_p
,
1116 debug_string_size_p
);
1119 /* Write out the COFF symbols. */
1122 coff_write_symbols (abfd
)
1125 bfd_size_type string_size
;
1126 asection
*debug_string_section
;
1127 bfd_size_type debug_string_size
;
1129 unsigned int limit
= bfd_get_symcount (abfd
);
1130 unsigned int written
= 0;
1134 debug_string_section
= NULL
;
1135 debug_string_size
= 0;
1137 /* If this target supports long section names, they must be put into
1138 the string table. This is supported by PE. This code must
1139 handle section names just as they are handled in
1140 coff_write_object_contents. */
1141 if (bfd_coff_long_section_names (abfd
))
1145 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1149 len
= strlen (o
->name
);
1151 string_size
+= len
+ 1;
1155 /* Seek to the right place */
1156 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0)
1159 /* Output all the symbols we have */
1162 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++)
1164 asymbol
*symbol
= *p
;
1165 coff_symbol_type
*c_symbol
= coff_symbol_from (abfd
, symbol
);
1167 if (c_symbol
== (coff_symbol_type
*) NULL
1168 || c_symbol
->native
== (combined_entry_type
*) NULL
)
1170 if (!coff_write_alien_symbol (abfd
, symbol
, &written
, &string_size
,
1171 &debug_string_section
,
1172 &debug_string_size
))
1177 if (!coff_write_native_symbol (abfd
, c_symbol
, &written
,
1178 &string_size
, &debug_string_section
,
1179 &debug_string_size
))
1184 obj_raw_syment_count (abfd
) = written
;
1186 /* Now write out strings */
1188 if (string_size
!= 0)
1190 unsigned int size
= string_size
+ STRING_SIZE_SIZE
;
1191 bfd_byte buffer
[STRING_SIZE_SIZE
];
1193 #if STRING_SIZE_SIZE == 4
1194 bfd_h_put_32 (abfd
, size
, buffer
);
1196 #error Change bfd_h_put_32
1198 if (bfd_write ((PTR
) buffer
, 1, sizeof (buffer
), abfd
) != sizeof (buffer
))
1201 /* Handle long section names. This code must handle section
1202 names just as they are handled in coff_write_object_contents. */
1203 if (bfd_coff_long_section_names (abfd
))
1207 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
1211 len
= strlen (o
->name
);
1214 if (bfd_write (o
->name
, 1, len
+ 1, abfd
) != len
+ 1)
1220 for (p
= abfd
->outsymbols
, i
= 0;
1225 size_t name_length
= strlen (q
->name
);
1226 coff_symbol_type
*c_symbol
= coff_symbol_from (abfd
, q
);
1229 /* Figure out whether the symbol name should go in the string
1230 table. Symbol names that are short enough are stored
1231 directly in the syment structure. File names permit a
1232 different, longer, length in the syment structure. On
1233 XCOFF, some symbol names are stored in the .debug section
1234 rather than in the string table. */
1236 if (c_symbol
== NULL
1237 || c_symbol
->native
== NULL
)
1239 /* This is not a COFF symbol, so it certainly is not a
1240 file name, nor does it go in the .debug section. */
1243 else if (bfd_coff_symname_in_debug (abfd
,
1244 &c_symbol
->native
->u
.syment
))
1246 /* This symbol name is in the XCOFF .debug section.
1247 Don't write it into the string table. */
1248 maxlen
= name_length
;
1250 else if (c_symbol
->native
->u
.syment
.n_sclass
== C_FILE
1251 && c_symbol
->native
->u
.syment
.n_numaux
> 0)
1252 maxlen
= bfd_coff_filnmlen (abfd
);
1256 if (name_length
> maxlen
)
1258 if (bfd_write ((PTR
) (q
->name
), 1, name_length
+ 1, abfd
)
1266 /* We would normally not write anything here, but we'll write
1267 out 4 so that any stupid coff reader which tries to read the
1268 string table even when there isn't one won't croak. */
1269 unsigned int size
= STRING_SIZE_SIZE
;
1270 bfd_byte buffer
[STRING_SIZE_SIZE
];
1272 #if STRING_SIZE_SIZE == 4
1273 bfd_h_put_32 (abfd
, size
, buffer
);
1275 #error Change bfd_h_put_32
1277 if (bfd_write ((PTR
) buffer
, 1, STRING_SIZE_SIZE
, abfd
)
1278 != STRING_SIZE_SIZE
)
1282 /* Make sure the .debug section was created to be the correct size.
1283 We should create it ourselves on the fly, but we don't because
1284 BFD won't let us write to any section until we know how large all
1285 the sections are. We could still do it by making another pass
1286 over the symbols. FIXME. */
1287 BFD_ASSERT (debug_string_size
== 0
1288 || (debug_string_section
!= (asection
*) NULL
1289 && (BFD_ALIGN (debug_string_size
,
1290 1 << debug_string_section
->alignment_power
)
1291 == bfd_section_size (abfd
, debug_string_section
))));
1297 coff_write_linenumbers (abfd
)
1301 bfd_size_type linesz
;
1304 linesz
= bfd_coff_linesz (abfd
);
1305 buff
= bfd_alloc (abfd
, linesz
);
1308 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
)
1310 if (s
->lineno_count
)
1312 asymbol
**q
= abfd
->outsymbols
;
1313 if (bfd_seek (abfd
, s
->line_filepos
, SEEK_SET
) != 0)
1315 /* Find all the linenumbers in this section */
1319 if (p
->section
->output_section
== s
)
1322 BFD_SEND (bfd_asymbol_bfd (p
), _get_lineno
,
1323 (bfd_asymbol_bfd (p
), p
));
1326 /* Found a linenumber entry, output */
1327 struct internal_lineno out
;
1328 memset ((PTR
) & out
, 0, sizeof (out
));
1330 out
.l_addr
.l_symndx
= l
->u
.offset
;
1331 bfd_coff_swap_lineno_out (abfd
, &out
, buff
);
1332 if (bfd_write (buff
, 1, linesz
, abfd
) != linesz
)
1335 while (l
->line_number
)
1337 out
.l_lnno
= l
->line_number
;
1338 out
.l_addr
.l_symndx
= l
->u
.offset
;
1339 bfd_coff_swap_lineno_out (abfd
, &out
, buff
);
1340 if (bfd_write (buff
, 1, linesz
, abfd
) != linesz
)
1350 bfd_release (abfd
, buff
);
1356 coff_get_lineno (ignore_abfd
, symbol
)
1357 bfd
*ignore_abfd ATTRIBUTE_UNUSED
;
1360 return coffsymbol (symbol
)->lineno
;
1365 /* This is only called from coff_add_missing_symbols, which has been
1369 coff_section_symbol (abfd
, name
)
1373 asection
*sec
= bfd_make_section_old_way (abfd
, name
);
1375 combined_entry_type
*csym
;
1378 csym
= coff_symbol_from (abfd
, sym
)->native
;
1379 /* Make sure back-end COFF stuff is there. */
1384 coff_symbol_type sym
;
1385 /* @@FIXME This shouldn't use a fixed size!! */
1386 combined_entry_type e
[10];
1389 f
= (struct foo
*) bfd_alloc (abfd
, sizeof (*f
));
1392 bfd_set_error (bfd_error_no_error
);
1395 memset ((char *) f
, 0, sizeof (*f
));
1396 coff_symbol_from (abfd
, sym
)->native
= csym
= f
->e
;
1398 csym
[0].u
.syment
.n_sclass
= C_STAT
;
1399 csym
[0].u
.syment
.n_numaux
= 1;
1400 /* SF_SET_STATICS (sym); @@ ??? */
1401 csym
[1].u
.auxent
.x_scn
.x_scnlen
= sec
->_raw_size
;
1402 csym
[1].u
.auxent
.x_scn
.x_nreloc
= sec
->reloc_count
;
1403 csym
[1].u
.auxent
.x_scn
.x_nlinno
= sec
->lineno_count
;
1405 if (sec
->output_section
== NULL
)
1407 sec
->output_section
= sec
;
1408 sec
->output_offset
= 0;
1416 /* This function transforms the offsets into the symbol table into
1417 pointers to syments. */
1420 coff_pointerize_aux (abfd
, table_base
, symbol
, indaux
, auxent
)
1422 combined_entry_type
*table_base
;
1423 combined_entry_type
*symbol
;
1424 unsigned int indaux
;
1425 combined_entry_type
*auxent
;
1427 unsigned int type
= symbol
->u
.syment
.n_type
;
1428 unsigned int class = symbol
->u
.syment
.n_sclass
;
1430 if (coff_backend_info (abfd
)->_bfd_coff_pointerize_aux_hook
)
1432 if ((*coff_backend_info (abfd
)->_bfd_coff_pointerize_aux_hook
)
1433 (abfd
, table_base
, symbol
, indaux
, auxent
))
1437 /* Don't bother if this is a file or a section */
1438 if (class == C_STAT
&& type
== T_NULL
)
1440 if (class == C_FILE
)
1443 /* Otherwise patch up */
1444 #define N_TMASK coff_data (abfd)->local_n_tmask
1445 #define N_BTSHFT coff_data (abfd)->local_n_btshft
1446 if ((ISFCN (type
) || ISTAG (class) || class == C_BLOCK
|| class == C_FCN
)
1447 && auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
> 0)
1449 auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
=
1450 table_base
+ auxent
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
;
1451 auxent
->fix_end
= 1;
1453 /* A negative tagndx is meaningless, but the SCO 3.2v4 cc can
1454 generate one, so we must be careful to ignore it. */
1455 if (auxent
->u
.auxent
.x_sym
.x_tagndx
.l
> 0)
1457 auxent
->u
.auxent
.x_sym
.x_tagndx
.p
=
1458 table_base
+ auxent
->u
.auxent
.x_sym
.x_tagndx
.l
;
1459 auxent
->fix_tag
= 1;
1463 /* Allocate space for the ".debug" section, and read it.
1464 We did not read the debug section until now, because
1465 we didn't want to go to the trouble until someone needed it. */
1468 build_debug_section (abfd
)
1471 char *debug_section
;
1474 asection
*sect
= bfd_get_section_by_name (abfd
, ".debug");
1478 bfd_set_error (bfd_error_no_debug_section
);
1482 debug_section
= (PTR
) bfd_alloc (abfd
,
1483 bfd_get_section_size_before_reloc (sect
));
1484 if (debug_section
== NULL
)
1487 /* Seek to the beginning of the `.debug' section and read it.
1488 Save the current position first; it is needed by our caller.
1489 Then read debug section and reset the file pointer. */
1491 position
= bfd_tell (abfd
);
1492 if (bfd_seek (abfd
, sect
->filepos
, SEEK_SET
) != 0
1493 || (bfd_read (debug_section
,
1494 bfd_get_section_size_before_reloc (sect
), 1, abfd
)
1495 != bfd_get_section_size_before_reloc (sect
))
1496 || bfd_seek (abfd
, position
, SEEK_SET
) != 0)
1498 return debug_section
;
1502 /* Return a pointer to a malloc'd copy of 'name'. 'name' may not be
1503 \0-terminated, but will not exceed 'maxlen' characters. The copy *will*
1504 be \0-terminated. */
1506 copy_name (abfd
, name
, maxlen
)
1514 for (len
= 0; len
< maxlen
; ++len
)
1516 if (name
[len
] == '\0')
1522 if ((newname
= (PTR
) bfd_alloc (abfd
, len
+ 1)) == NULL
)
1524 strncpy (newname
, name
, len
);
1525 newname
[len
] = '\0';
1529 /* Read in the external symbols. */
1532 _bfd_coff_get_external_symbols (abfd
)
1535 bfd_size_type symesz
;
1539 if (obj_coff_external_syms (abfd
) != NULL
)
1542 symesz
= bfd_coff_symesz (abfd
);
1544 size
= obj_raw_syment_count (abfd
) * symesz
;
1546 syms
= (PTR
) bfd_malloc (size
);
1547 if (syms
== NULL
&& size
!= 0)
1550 if (bfd_seek (abfd
, obj_sym_filepos (abfd
), SEEK_SET
) != 0
1551 || bfd_read (syms
, size
, 1, abfd
) != size
)
1558 obj_coff_external_syms (abfd
) = syms
;
1563 /* Read in the external strings. The strings are not loaded until
1564 they are needed. This is because we have no simple way of
1565 detecting a missing string table in an archive. */
1568 _bfd_coff_read_string_table (abfd
)
1571 char extstrsize
[STRING_SIZE_SIZE
];
1575 if (obj_coff_strings (abfd
) != NULL
)
1576 return obj_coff_strings (abfd
);
1578 if (obj_sym_filepos (abfd
) == 0)
1580 bfd_set_error (bfd_error_no_symbols
);
1585 (obj_sym_filepos (abfd
)
1586 + obj_raw_syment_count (abfd
) * bfd_coff_symesz (abfd
)),
1590 if (bfd_read (extstrsize
, sizeof extstrsize
, 1, abfd
) != sizeof extstrsize
)
1592 if (bfd_get_error () != bfd_error_file_truncated
)
1595 /* There is no string table. */
1596 strsize
= STRING_SIZE_SIZE
;
1600 #if STRING_SIZE_SIZE == 4
1601 strsize
= bfd_h_get_32 (abfd
, (bfd_byte
*) extstrsize
);
1603 #error Change bfd_h_get_32
1607 if (strsize
< STRING_SIZE_SIZE
)
1609 (*_bfd_error_handler
)
1610 (_("%s: bad string table size %lu"), bfd_get_filename (abfd
),
1611 (unsigned long) strsize
);
1612 bfd_set_error (bfd_error_bad_value
);
1616 strings
= (char *) bfd_malloc (strsize
);
1617 if (strings
== NULL
)
1620 if (bfd_read (strings
+ STRING_SIZE_SIZE
,
1621 strsize
- STRING_SIZE_SIZE
, 1, abfd
)
1622 != strsize
- STRING_SIZE_SIZE
)
1628 obj_coff_strings (abfd
) = strings
;
1633 /* Free up the external symbols and strings read from a COFF file. */
1636 _bfd_coff_free_symbols (abfd
)
1639 if (obj_coff_external_syms (abfd
) != NULL
1640 && ! obj_coff_keep_syms (abfd
))
1642 free (obj_coff_external_syms (abfd
));
1643 obj_coff_external_syms (abfd
) = NULL
;
1645 if (obj_coff_strings (abfd
) != NULL
1646 && ! obj_coff_keep_strings (abfd
))
1648 free (obj_coff_strings (abfd
));
1649 obj_coff_strings (abfd
) = NULL
;
1654 /* Read a symbol table into freshly bfd_allocated memory, swap it, and
1655 knit the symbol names into a normalized form. By normalized here I
1656 mean that all symbols have an n_offset pointer that points to a null-
1657 terminated string. */
1659 combined_entry_type
*
1660 coff_get_normalized_symtab (abfd
)
1663 combined_entry_type
*internal
;
1664 combined_entry_type
*internal_ptr
;
1665 combined_entry_type
*symbol_ptr
;
1666 combined_entry_type
*internal_end
;
1667 bfd_size_type symesz
;
1670 const char *string_table
= NULL
;
1671 char *debug_section
= NULL
;
1674 if (obj_raw_syments (abfd
) != NULL
)
1675 return obj_raw_syments (abfd
);
1677 size
= obj_raw_syment_count (abfd
) * sizeof (combined_entry_type
);
1678 internal
= (combined_entry_type
*) bfd_zalloc (abfd
, size
);
1679 if (internal
== NULL
&& size
!= 0)
1681 internal_end
= internal
+ obj_raw_syment_count (abfd
);
1683 if (! _bfd_coff_get_external_symbols (abfd
))
1686 raw_src
= (char *) obj_coff_external_syms (abfd
);
1688 /* mark the end of the symbols */
1689 symesz
= bfd_coff_symesz (abfd
);
1690 raw_end
= (char *) raw_src
+ obj_raw_syment_count (abfd
) * symesz
;
1692 /* FIXME SOMEDAY. A string table size of zero is very weird, but
1693 probably possible. If one shows up, it will probably kill us. */
1695 /* Swap all the raw entries */
1696 for (internal_ptr
= internal
;
1698 raw_src
+= symesz
, internal_ptr
++)
1702 bfd_coff_swap_sym_in (abfd
, (PTR
) raw_src
,
1703 (PTR
) & internal_ptr
->u
.syment
);
1704 symbol_ptr
= internal_ptr
;
1707 i
< symbol_ptr
->u
.syment
.n_numaux
;
1712 bfd_coff_swap_aux_in (abfd
, (PTR
) raw_src
,
1713 symbol_ptr
->u
.syment
.n_type
,
1714 symbol_ptr
->u
.syment
.n_sclass
,
1715 i
, symbol_ptr
->u
.syment
.n_numaux
,
1716 &(internal_ptr
->u
.auxent
));
1717 coff_pointerize_aux (abfd
, internal
, symbol_ptr
, i
,
1722 /* Free the raw symbols, but not the strings (if we have them). */
1723 obj_coff_keep_strings (abfd
) = true;
1724 if (! _bfd_coff_free_symbols (abfd
))
1727 for (internal_ptr
= internal
; internal_ptr
< internal_end
;
1730 if (internal_ptr
->u
.syment
.n_sclass
== C_FILE
1731 && internal_ptr
->u
.syment
.n_numaux
> 0)
1733 /* make a file symbol point to the name in the auxent, since
1734 the text ".file" is redundant */
1735 if ((internal_ptr
+ 1)->u
.auxent
.x_file
.x_n
.x_zeroes
== 0)
1737 /* the filename is a long one, point into the string table */
1738 if (string_table
== NULL
)
1740 string_table
= _bfd_coff_read_string_table (abfd
);
1741 if (string_table
== NULL
)
1745 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1748 + (internal_ptr
+ 1)->u
.auxent
.x_file
.x_n
.x_offset
));
1752 /* Ordinary short filename, put into memory anyway. The
1753 Microsoft PE tools sometimes store a filename in
1754 multiple AUX entries. */
1755 if (internal_ptr
->u
.syment
.n_numaux
> 1
1756 && coff_data (abfd
)->pe
)
1758 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1761 (internal_ptr
+ 1)->u
.auxent
.x_file
.x_fname
,
1762 internal_ptr
->u
.syment
.n_numaux
* symesz
));
1766 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1769 (internal_ptr
+ 1)->u
.auxent
.x_file
.x_fname
,
1770 bfd_coff_filnmlen (abfd
)));
1776 if (internal_ptr
->u
.syment
._n
._n_n
._n_zeroes
!= 0)
1778 /* This is a "short" name. Make it long. */
1779 unsigned long i
= 0;
1780 char *newstring
= NULL
;
1782 /* find the length of this string without walking into memory
1784 for (i
= 0; i
< 8; ++i
)
1786 if (internal_ptr
->u
.syment
._n
._n_name
[i
] == '\0')
1789 } /* if end of string */
1790 } /* possible lengths of this string. */
1792 if ((newstring
= (PTR
) bfd_alloc (abfd
, ++i
)) == NULL
)
1794 memset (newstring
, 0, i
);
1795 strncpy (newstring
, internal_ptr
->u
.syment
._n
._n_name
, i
- 1);
1796 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int) newstring
;
1797 internal_ptr
->u
.syment
._n
._n_n
._n_zeroes
= 0;
1799 else if (internal_ptr
->u
.syment
._n
._n_n
._n_offset
== 0)
1800 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int) "";
1801 else if (!bfd_coff_symname_in_debug (abfd
, &internal_ptr
->u
.syment
))
1803 /* Long name already. Point symbol at the string in the
1805 if (string_table
== NULL
)
1807 string_table
= _bfd_coff_read_string_table (abfd
);
1808 if (string_table
== NULL
)
1811 internal_ptr
->u
.syment
._n
._n_n
._n_offset
=
1814 + internal_ptr
->u
.syment
._n
._n_n
._n_offset
));
1818 /* Long name in debug section. Very similar. */
1819 if (debug_section
== NULL
)
1820 debug_section
= build_debug_section (abfd
);
1821 internal_ptr
->u
.syment
._n
._n_n
._n_offset
= (long int)
1822 (debug_section
+ internal_ptr
->u
.syment
._n
._n_n
._n_offset
);
1825 internal_ptr
+= internal_ptr
->u
.syment
.n_numaux
;
1828 obj_raw_syments (abfd
) = internal
;
1829 BFD_ASSERT (obj_raw_syment_count (abfd
)
1830 == (unsigned int) (internal_ptr
- internal
));
1833 } /* coff_get_normalized_symtab() */
1836 coff_get_reloc_upper_bound (abfd
, asect
)
1840 if (bfd_get_format (abfd
) != bfd_object
)
1842 bfd_set_error (bfd_error_invalid_operation
);
1845 return (asect
->reloc_count
+ 1) * sizeof (arelent
*);
1849 coff_make_empty_symbol (abfd
)
1852 coff_symbol_type
*new = (coff_symbol_type
*) bfd_alloc (abfd
, sizeof (coff_symbol_type
));
1855 memset (new, 0, sizeof *new);
1856 new->symbol
.section
= 0;
1858 new->lineno
= (alent
*) NULL
;
1859 new->done_lineno
= false;
1860 new->symbol
.the_bfd
= abfd
;
1861 return &new->symbol
;
1864 /* Make a debugging symbol. */
1867 coff_bfd_make_debug_symbol (abfd
, ptr
, sz
)
1869 PTR ptr ATTRIBUTE_UNUSED
;
1870 unsigned long sz ATTRIBUTE_UNUSED
;
1872 coff_symbol_type
*new = (coff_symbol_type
*) bfd_alloc (abfd
, sizeof (coff_symbol_type
));
1875 /* @@ The 10 is a guess at a plausible maximum number of aux entries
1876 (but shouldn't be a constant). */
1877 new->native
= (combined_entry_type
*) bfd_zalloc (abfd
, sizeof (combined_entry_type
) * 10);
1880 new->symbol
.section
= bfd_abs_section_ptr
;
1881 new->symbol
.flags
= BSF_DEBUGGING
;
1882 new->lineno
= (alent
*) NULL
;
1883 new->done_lineno
= false;
1884 new->symbol
.the_bfd
= abfd
;
1885 return &new->symbol
;
1890 coff_get_symbol_info (abfd
, symbol
, ret
)
1895 bfd_symbol_info (symbol
, ret
);
1896 if (coffsymbol (symbol
)->native
!= NULL
1897 && coffsymbol (symbol
)->native
->fix_value
)
1899 combined_entry_type
*psym
;
1901 psym
= ((combined_entry_type
*)
1902 coffsymbol (symbol
)->native
->u
.syment
.n_value
);
1903 ret
->value
= (bfd_vma
) (psym
- obj_raw_syments (abfd
));
1907 /* Return the COFF syment for a symbol. */
1910 bfd_coff_get_syment (abfd
, symbol
, psyment
)
1913 struct internal_syment
*psyment
;
1915 coff_symbol_type
*csym
;
1917 csym
= coff_symbol_from (abfd
, symbol
);
1918 if (csym
== NULL
|| csym
->native
== NULL
)
1920 bfd_set_error (bfd_error_invalid_operation
);
1924 *psyment
= csym
->native
->u
.syment
;
1926 if (csym
->native
->fix_value
)
1927 psyment
->n_value
= ((combined_entry_type
*) psyment
->n_value
1928 - obj_raw_syments (abfd
));
1930 /* FIXME: We should handle fix_line here. */
1935 /* Return the COFF auxent for a symbol. */
1938 bfd_coff_get_auxent (abfd
, symbol
, indx
, pauxent
)
1942 union internal_auxent
*pauxent
;
1944 coff_symbol_type
*csym
;
1945 combined_entry_type
*ent
;
1947 csym
= coff_symbol_from (abfd
, symbol
);
1950 || csym
->native
== NULL
1951 || indx
>= csym
->native
->u
.syment
.n_numaux
)
1953 bfd_set_error (bfd_error_invalid_operation
);
1957 ent
= csym
->native
+ indx
+ 1;
1959 *pauxent
= ent
->u
.auxent
;
1962 pauxent
->x_sym
.x_tagndx
.l
=
1963 ((combined_entry_type
*) pauxent
->x_sym
.x_tagndx
.p
1964 - obj_raw_syments (abfd
));
1967 pauxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.l
=
1968 ((combined_entry_type
*) pauxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
1969 - obj_raw_syments (abfd
));
1971 if (ent
->fix_scnlen
)
1972 pauxent
->x_csect
.x_scnlen
.l
=
1973 ((combined_entry_type
*) pauxent
->x_csect
.x_scnlen
.p
1974 - obj_raw_syments (abfd
));
1979 /* Print out information about COFF symbol. */
1982 coff_print_symbol (abfd
, filep
, symbol
, how
)
1986 bfd_print_symbol_type how
;
1988 FILE *file
= (FILE *) filep
;
1992 case bfd_print_symbol_name
:
1993 fprintf (file
, "%s", symbol
->name
);
1996 case bfd_print_symbol_more
:
1997 fprintf (file
, "coff %s %s",
1998 coffsymbol (symbol
)->native
? "n" : "g",
1999 coffsymbol (symbol
)->lineno
? "l" : " ");
2002 case bfd_print_symbol_all
:
2003 if (coffsymbol (symbol
)->native
)
2007 combined_entry_type
*combined
= coffsymbol (symbol
)->native
;
2008 combined_entry_type
*root
= obj_raw_syments (abfd
);
2009 struct lineno_cache_entry
*l
= coffsymbol (symbol
)->lineno
;
2011 fprintf (file
, "[%3ld]", (long) (combined
- root
));
2013 if (! combined
->fix_value
)
2014 val
= (unsigned long) combined
->u
.syment
.n_value
;
2016 val
= ((unsigned long)
2017 ((combined_entry_type
*) combined
->u
.syment
.n_value
2021 "(sec %2d)(fl 0x%02x)(ty %3x)(scl %3d) (nx %d) 0x%08lx %s",
2022 combined
->u
.syment
.n_scnum
,
2023 combined
->u
.syment
.n_flags
,
2024 combined
->u
.syment
.n_type
,
2025 combined
->u
.syment
.n_sclass
,
2026 combined
->u
.syment
.n_numaux
,
2030 for (aux
= 0; aux
< combined
->u
.syment
.n_numaux
; aux
++)
2032 combined_entry_type
*auxp
= combined
+ aux
+ 1;
2036 tagndx
= auxp
->u
.auxent
.x_sym
.x_tagndx
.p
- root
;
2038 tagndx
= auxp
->u
.auxent
.x_sym
.x_tagndx
.l
;
2040 fprintf (file
, "\n");
2042 if (bfd_coff_print_aux (abfd
, file
, root
, combined
, auxp
, aux
))
2045 switch (combined
->u
.syment
.n_sclass
)
2048 fprintf (file
, "File ");
2052 if (combined
->u
.syment
.n_type
== T_NULL
)
2053 /* probably a section symbol? */
2055 fprintf (file
, "AUX scnlen 0x%lx nreloc %d nlnno %d",
2056 (long) auxp
->u
.auxent
.x_scn
.x_scnlen
,
2057 auxp
->u
.auxent
.x_scn
.x_nreloc
,
2058 auxp
->u
.auxent
.x_scn
.x_nlinno
);
2059 if (auxp
->u
.auxent
.x_scn
.x_checksum
!= 0
2060 || auxp
->u
.auxent
.x_scn
.x_associated
!= 0
2061 || auxp
->u
.auxent
.x_scn
.x_comdat
!= 0)
2062 fprintf (file
, " checksum 0x%lx assoc %d comdat %d",
2063 auxp
->u
.auxent
.x_scn
.x_checksum
,
2064 auxp
->u
.auxent
.x_scn
.x_associated
,
2065 auxp
->u
.auxent
.x_scn
.x_comdat
);
2068 /* else fall through */
2071 fprintf (file
, "AUX lnno %d size 0x%x tagndx %ld",
2072 auxp
->u
.auxent
.x_sym
.x_misc
.x_lnsz
.x_lnno
,
2073 auxp
->u
.auxent
.x_sym
.x_misc
.x_lnsz
.x_size
,
2076 fprintf (file
, " endndx %ld",
2078 (auxp
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
2086 fprintf (file
, "\n%s :", l
->u
.sym
->name
);
2088 while (l
->line_number
)
2090 fprintf (file
, "\n%4d : 0x%lx",
2093 (l
->u
.offset
+ symbol
->section
->vma
)));
2100 bfd_print_symbol_vandf ((PTR
) file
, symbol
);
2101 fprintf (file
, " %-5s %s %s %s",
2102 symbol
->section
->name
,
2103 coffsymbol (symbol
)->native
? "n" : "g",
2104 coffsymbol (symbol
)->lineno
? "l" : " ",
2110 /* Return whether a symbol name implies a local symbol. In COFF,
2111 local symbols generally start with ``.L''. Most targets use this
2112 function for the is_local_label_name entry point, but some may
2116 _bfd_coff_is_local_label_name (abfd
, name
)
2117 bfd
*abfd ATTRIBUTE_UNUSED
;
2120 return name
[0] == '.' && name
[1] == 'L';
2123 /* Provided a BFD, a section and an offset into the section, calculate
2124 and return the name of the source file and the line nearest to the
2129 coff_find_nearest_line (abfd
, section
, symbols
, offset
, filename_ptr
,
2130 functionname_ptr
, line_ptr
)
2135 CONST
char **filename_ptr
;
2136 CONST
char **functionname_ptr
;
2137 unsigned int *line_ptr
;
2141 unsigned int line_base
;
2142 coff_data_type
*cof
= coff_data (abfd
);
2143 /* Run through the raw syments if available */
2144 combined_entry_type
*p
;
2145 combined_entry_type
*pend
;
2147 struct coff_section_tdata
*sec_data
;
2149 /* Before looking through the symbol table, try to use a .stab
2150 section to find the information. */
2151 if (! _bfd_stab_section_find_nearest_line (abfd
, symbols
, section
, offset
,
2152 &found
, filename_ptr
,
2153 functionname_ptr
, line_ptr
,
2154 &coff_data (abfd
)->line_info
))
2160 *functionname_ptr
= 0;
2163 /* Don't try and find line numbers in a non coff file */
2164 if (abfd
->xvec
->flavour
!= bfd_target_coff_flavour
)
2170 /* Find the first C_FILE symbol. */
2171 p
= cof
->raw_syments
;
2175 pend
= p
+ cof
->raw_syment_count
;
2178 if (p
->u
.syment
.n_sclass
== C_FILE
)
2180 p
+= 1 + p
->u
.syment
.n_numaux
;
2188 /* Look through the C_FILE symbols to find the best one. */
2189 sec_vma
= bfd_get_section_vma (abfd
, section
);
2190 *filename_ptr
= (char *) p
->u
.syment
._n
._n_n
._n_offset
;
2191 maxdiff
= (bfd_vma
) 0 - (bfd_vma
) 1;
2194 combined_entry_type
*p2
;
2196 for (p2
= p
+ 1 + p
->u
.syment
.n_numaux
;
2198 p2
+= 1 + p2
->u
.syment
.n_numaux
)
2200 if (p2
->u
.syment
.n_scnum
> 0
2202 == coff_section_from_bfd_index (abfd
,
2203 p2
->u
.syment
.n_scnum
)))
2205 if (p2
->u
.syment
.n_sclass
== C_FILE
)
2212 /* We use <= MAXDIFF here so that if we get a zero length
2213 file, we actually use the next file entry. */
2215 && offset
+ sec_vma
>= (bfd_vma
) p2
->u
.syment
.n_value
2216 && offset
+ sec_vma
- (bfd_vma
) p2
->u
.syment
.n_value
<= maxdiff
)
2218 *filename_ptr
= (char *) p
->u
.syment
._n
._n_n
._n_offset
;
2219 maxdiff
= offset
+ sec_vma
- p2
->u
.syment
.n_value
;
2222 /* Avoid endless loops on erroneous files by ensuring that
2223 we always move forward in the file. */
2224 if (p
- cof
->raw_syments
>= p
->u
.syment
.n_value
)
2227 p
= cof
->raw_syments
+ p
->u
.syment
.n_value
;
2228 if (p
> pend
|| p
->u
.syment
.n_sclass
!= C_FILE
)
2233 /* Now wander though the raw linenumbers of the section */
2234 /* If we have been called on this section before, and the offset we
2235 want is further down then we can prime the lookup loop. */
2236 sec_data
= coff_section_data (abfd
, section
);
2237 if (sec_data
!= NULL
2239 && offset
>= sec_data
->offset
)
2242 *functionname_ptr
= sec_data
->function
;
2243 line_base
= sec_data
->line_base
;
2251 if (section
->lineno
!= NULL
)
2253 bfd_vma last_value
= 0;
2255 l
= §ion
->lineno
[i
];
2257 for (; i
< section
->lineno_count
; i
++)
2259 if (l
->line_number
== 0)
2261 /* Get the symbol this line number points at */
2262 coff_symbol_type
*coff
= (coff_symbol_type
*) (l
->u
.sym
);
2263 if (coff
->symbol
.value
> offset
)
2265 *functionname_ptr
= coff
->symbol
.name
;
2266 last_value
= coff
->symbol
.value
;
2269 combined_entry_type
*s
= coff
->native
;
2270 s
= s
+ 1 + s
->u
.syment
.n_numaux
;
2272 /* In XCOFF a debugging symbol can follow the
2274 if (s
->u
.syment
.n_scnum
== N_DEBUG
)
2275 s
= s
+ 1 + s
->u
.syment
.n_numaux
;
2277 /* S should now point to the .bf of the function. */
2278 if (s
->u
.syment
.n_numaux
)
2280 /* The linenumber is stored in the auxent. */
2281 union internal_auxent
*a
= &((s
+ 1)->u
.auxent
);
2282 line_base
= a
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
2283 *line_ptr
= line_base
;
2289 if (l
->u
.offset
> offset
)
2291 *line_ptr
= l
->line_number
+ line_base
- 1;
2296 /* If we fell off the end of the loop, then assume that this
2297 symbol has no line number info. Otherwise, symbols with no
2298 line number info get reported with the line number of the
2299 last line of the last symbol which does have line number
2300 info. We use 0x100 as a slop to account for cases where the
2301 last line has executable code. */
2302 if (i
>= section
->lineno_count
2304 && offset
- last_value
> 0x100)
2306 *functionname_ptr
= NULL
;
2311 /* Cache the results for the next call. */
2312 if (sec_data
== NULL
&& section
->owner
== abfd
)
2314 section
->used_by_bfd
=
2315 ((PTR
) bfd_zalloc (abfd
,
2316 sizeof (struct coff_section_tdata
)));
2317 sec_data
= (struct coff_section_tdata
*) section
->used_by_bfd
;
2319 if (sec_data
!= NULL
)
2321 sec_data
->offset
= offset
;
2323 sec_data
->function
= *functionname_ptr
;
2324 sec_data
->line_base
= line_base
;
2331 coff_sizeof_headers (abfd
, reloc
)
2339 size
= bfd_coff_filhsz (abfd
) + bfd_coff_aoutsz (abfd
);
2343 size
= bfd_coff_filhsz (abfd
);
2346 size
+= abfd
->section_count
* bfd_coff_scnhsz (abfd
);
2350 /* Change the class of a coff symbol held by BFD. */
2352 bfd_coff_set_symbol_class (abfd
, symbol
, class)
2357 coff_symbol_type
* csym
;
2359 csym
= coff_symbol_from (abfd
, symbol
);
2362 bfd_set_error (bfd_error_invalid_operation
);
2365 else if (csym
->native
== NULL
)
2367 /* This is an alien symbol which no native coff backend data.
2368 We cheat here by creating a fake native entry for it and
2369 then filling in the class. This code is based on that in
2370 coff_write_alien_symbol(). */
2372 combined_entry_type
* native
;
2374 native
= (combined_entry_type
*) bfd_alloc (abfd
, sizeof (* native
));
2378 memset (native
, 0, sizeof (* native
));
2380 native
->u
.syment
.n_type
= T_NULL
;
2381 native
->u
.syment
.n_sclass
= class;
2383 if (bfd_is_und_section (symbol
->section
))
2385 native
->u
.syment
.n_scnum
= N_UNDEF
;
2386 native
->u
.syment
.n_value
= symbol
->value
;
2388 else if (bfd_is_com_section (symbol
->section
))
2390 native
->u
.syment
.n_scnum
= N_UNDEF
;
2391 native
->u
.syment
.n_value
= symbol
->value
;
2395 native
->u
.syment
.n_scnum
=
2396 symbol
->section
->output_section
->target_index
;
2397 native
->u
.syment
.n_value
= (symbol
->value
2398 + symbol
->section
->output_offset
);
2399 if (! obj_pe (abfd
))
2400 native
->u
.syment
.n_value
+= symbol
->section
->output_section
->vma
;
2402 /* Copy the any flags from the the file header into the symbol.
2404 native
->u
.syment
.n_flags
= bfd_asymbol_bfd (& csym
->symbol
)->flags
;
2407 csym
->native
= native
;
2411 csym
->native
->u
.syment
.n_sclass
= class;