1 /* Support for Intel 960 COFF and Motorola 88k BCS COFF (and maybe others) */
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Diddler.
7 BFD is free software; you can redistribute it and/or modify it under the
8 terms of the GNU General Public License as published by the Free Software
9 Foundation; either version 1, or (at your option) any later version.
11 BFD is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 You should have received a copy of the GNU General Public License along with
17 BFD; see the file COPYING. If not, write to the Free Software Foundation,
18 675 Mass Ave, Cambridge, MA 02139, USA.
22 /* Most of this hacked by Steve Chamberlain, steve@cygnus.com */
24 #include "archures.h" /* Machine architectures and types */
31 /* Align an address upward to a boundary, expressed as a number of bytes.
32 E.g. align to an 8-byte boundary with argument of 8. */
33 #define ALIGN(this, boundary) \
34 ((( (this) + ((boundary) -1)) & (~((boundary)-1))))
36 /* Align an address upward to a power of two. Argument is the power
37 of two, e.g. 8-byte alignment uses argument of 3 (8 == 2^3). */
38 #define i960_align(addr, align) \
39 ( ((addr) + ((1<<(align))-1)) & (-1 << (align)))
41 #define sp(x) bfd_h_put_x(abfd, x, &x)
43 PROTO(static void,force_indices_file_symbol_relative
,(bfd
*abfd
,
44 struct internal_syment
*symtab
));
46 /* All the swapping routines:
52 DEFUN(swap_reloc_in
,(abfd
, reloc_src
, reloc_dst
),
55 struct internal_reloc
*reloc_dst
)
57 reloc_dst
->r_vaddr
= bfd_h_getlong(abfd
, reloc_src
->r_vaddr
);
58 reloc_dst
->r_symndx
= bfd_h_getlong(abfd
, reloc_src
->r_symndx
);
59 reloc_dst
->r_type
= bfd_h_getshort(abfd
, reloc_src
->r_type
);
61 reloc_dst
->r_offset
= bfd_h_getshort(abfd
, reloc_src
->r_offset
);
66 DEFUN(swap_reloc_out
,(abfd
, reloc_src
, reloc_dst
),
68 struct internal_reloc
*reloc_src AND
69 struct external_reloc
*reloc_dst
)
71 bfd_h_putlong(abfd
, reloc_src
->r_vaddr
, reloc_dst
->r_vaddr
);
72 bfd_h_putlong(abfd
, reloc_src
->r_symndx
, reloc_dst
->r_symndx
);
73 bfd_h_putshort(abfd
, reloc_src
->r_type
, reloc_dst
->r_type
);
75 bfd_h_putshort(abfd
, reloc_src
->r_offset
, reloc_dst
->r_offset
);
81 DEFUN(swap_filehdr
,(abfd
, filehdr
),
87 sp(filehdr
->f_timdat
);
88 sp(filehdr
->f_symptr
);
90 sp(filehdr
->f_opthdr
);
98 DEFUN(bfd_coff_swap_name_in
,(abfd
, ptr
),
103 /* There is an index which needs to be swapped */
104 bfd_h_put_x(abfd
, ptr
[1], (ptr
+ 1));
107 /* This is a string .. leave it alone */
112 DEFUN(bfd_coff_swap_sym_in
,(abfd
, ext
, in
),
115 struct internal_syment
*in
)
117 if( ext
->e
.e_name
[0] == 0) {
118 in
->_n
._n_n
._n_zeroes
= 0;
119 in
->_n
._n_n
._n_offset
= bfd_h_getlong(abfd
, &ext
->e
.e
.e_offset
);
122 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
124 in
->n_value
= bfd_h_get_x(abfd
, &ext
->e_value
);
125 in
->n_scnum
= bfd_h_get_x(abfd
, &ext
->e_scnum
);
126 in
->n_type
= bfd_h_get_x(abfd
, &ext
->e_type
);
127 in
->n_sclass
= bfd_h_get_x(abfd
, &ext
->e_sclass
);
128 in
->n_numaux
= bfd_h_get_x(abfd
, &ext
->e_numaux
);
132 DEFUN(bfd_coff_swap_sym_out
,(abfd
,in
, ext
),
134 struct internal_syment
*in AND
137 if(in
->_n
._n_name
[0] == 0) {
138 bfd_h_putlong(abfd
, 0, ext
->e
.e
.e_zeroes
);
139 bfd_h_putlong(abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
142 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
144 bfd_h_put_x(abfd
, in
->n_value
, &ext
->e_value
);
145 bfd_h_put_x(abfd
, in
->n_scnum
, &ext
->e_scnum
);
146 bfd_h_put_x(abfd
, in
->n_type
, &ext
->e_type
);
147 bfd_h_put_x(abfd
, in
->n_sclass
, &ext
->e_sclass
);
148 bfd_h_put_x(abfd
, in
->n_numaux
, &ext
->e_numaux
);
152 DEFUN(bfd_coff_swap_aux_in
,(abfd
, ext
, type
, class, in
),
157 union internal_auxent
*in
)
161 if (ext
->x_file
.x_fname
[0] == 0) {
162 in
->x_file
.x_n
.x_zeroes
= 0;
163 in
->x_file
.x_n
.x_offset
= bfd_h_getlong(abfd
, &ext
->x_file
.x_n
.x_offset
);
172 if (type
== T_NULL
) {
173 in
->x_scn
.x_scnlen
= bfd_h_get_x(abfd
, & ext
->x_scn
.x_scnlen
);
174 in
->x_scn
.x_nreloc
= bfd_h_get_x(abfd
, &ext
->x_scn
.x_nreloc
);
175 in
->x_scn
.x_nlinno
= bfd_h_get_x(abfd
, &ext
->x_scn
.x_nlinno
);
179 in
->x_sym
.x_tagndx
= bfd_h_get_x(abfd
, &ext
->x_sym
.x_tagndx
);
180 in
->x_sym
.x_tvndx
= bfd_h_get_x(abfd
, &ext
->x_sym
.x_tvndx
);
182 if (ISARY(type
) || class == C_BLOCK
) {
183 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] = bfd_h_get_x(abfd
, & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
184 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] = bfd_h_get_x(abfd
, & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
185 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] = bfd_h_get_x(abfd
, & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
186 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] = bfd_h_get_x(abfd
, &ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
189 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_x(abfd
, & ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
190 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= bfd_h_get_x(abfd
, & ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
193 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_x(abfd
, &ext
->x_sym
.x_misc
.x_fsize
);
196 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_x(abfd
, & ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
197 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_x(abfd
, & ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
203 DEFUN(bfd_coff_swap_aux_out
,(abfd
, in
, type
, class, ext
),
205 union internal_auxent
*in AND
212 if (in
->x_file
.x_fname
[0] == 0) {
213 bfd_h_put_x(abfd
, 0,&ext
->x_file
.x_n
.x_zeroes
);
214 bfd_h_put_x(abfd
, in
->x_file
.x_n
.x_offset
, &ext
->x_file
.x_n
.x_offset
);
223 if (type
== T_NULL
) {
224 bfd_h_put_x(abfd
, in
->x_scn
.x_scnlen
, & ext
->x_scn
.x_scnlen
);
225 bfd_h_put_x(abfd
, in
->x_scn
.x_nreloc
, & ext
->x_scn
.x_nreloc
);
226 bfd_h_put_x(abfd
, in
->x_scn
.x_nlinno
, & ext
->x_scn
.x_nlinno
);
230 bfd_h_put_x(abfd
, in
->x_sym
.x_tagndx
, &ext
->x_sym
.x_tagndx
);
231 bfd_h_put_x(abfd
, in
->x_sym
.x_tvndx
, &ext
->x_sym
.x_tvndx
);
233 if (ISARY(type
) || class == C_BLOCK
) {
234 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0], & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
235 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1], & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
236 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2], & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
237 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3], & ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
240 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, & ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
241 bfd_h_put_x(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
, & ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
244 bfd_h_put_x(abfd
, in
->x_sym
.x_misc
.x_fsize
, &ext
->x_sym
.x_misc
.x_fsize
);
247 bfd_h_put_x(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, & ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
248 bfd_h_put_x(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
, & ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
254 DEFUN(bfd_coff_swap_lineno_in
,(abfd
, ext
, in
),
257 struct internal_lineno
*in
)
259 in
->l_addr
.l_symndx
= bfd_h_get_x(abfd
, &ext
->l_addr
.l_symndx
);
260 in
->l_lnno
= bfd_h_get_x(abfd
, & ext
->l_lnno
);
264 DEFUN(bfd_coff_swap_lineno_out
,(abfd
, in
, ext
),
266 struct internal_lineno
*in AND
267 struct external_lineno
*ext
)
269 bfd_h_put_x(abfd
, in
->l_addr
.l_symndx
, &ext
->l_addr
.l_symndx
);
270 bfd_h_put_x(abfd
, in
->l_lnno
, &ext
->l_lnno
);
277 DEFUN(swap_aouthdr
,(abfd
, aouthdr
),
288 sp(aouthdr
->text_start
);
289 sp(aouthdr
->data_start
);
291 sp(aouthdr
->tagentries
);
296 DEFUN(swap_scnhdr
,(abfd
, scnhdr
),
303 sp(scnhdr
->s_scnptr
);
304 sp(scnhdr
->s_relptr
);
305 sp(scnhdr
->s_lnnoptr
);
306 sp(scnhdr
->s_nreloc
);
314 /* void warning(); */
315 extern asection abs_section
;
318 DEFUN(get_index
,(symbol
),
321 return (int) symbol
->value
;
325 DEFUN(set_index
,(symbol
, idx
),
333 initialize a section structure with information peculiar to this
334 particular implementation of coff
338 DEFUN(coff_new_section_hook
,(abfd_ignore
, section_ignore
),
340 asection
*section_ignore
)
343 /* FIXME, shouldn't this ifdef be on something that says we are
344 actually COMPILING FOR an 88K coff file, rather than simply
345 knowing its magic number? */
346 /* Align to at least 16 bytes */
347 section_ignore
->alignment_power
= 4;
350 section_ignore
->alignment_power
= 3;
355 /* Take a section header read from a coff file (in HOST byte order),
356 and make a BFD "section" out of it. */
358 DEFUN(make_a_section_from_file
,(abfd
, hdr
),
362 asection
*return_section
;
365 /* Assorted wastage to null-terminate the name, thanks AT&T! */
366 char *name
= bfd_alloc(abfd
, sizeof (hdr
->s_name
)+1);
368 bfd_error
= no_memory
;
371 strncpy(name
, (char *) &hdr
->s_name
[0], sizeof (hdr
->s_name
));
372 name
[sizeof (hdr
->s_name
)] = 0;
374 return_section
= bfd_make_section(abfd
, name
);
377 /* s_paddr is presumed to be = to s_vaddr */
378 #define assign(to, from) return_section->to = hdr->from
379 assign(vma
, s_vaddr
);
380 /* assign (vma, s_vaddr); */
381 assign(size
, s_size
);
382 assign(filepos
, s_scnptr
);
383 assign(rel_filepos
, s_relptr
);
384 assign(reloc_count
, s_nreloc
);
387 /* FIXME, use a temp var rather than alignment_power */
388 assign(alignment_power
, s_align
);
391 for (i
= 0; i
< 32; i
++) {
392 if ((1 << i
) >= (int) (return_section
->alignment_power
)) {
393 return_section
->alignment_power
= i
;
400 assign(line_filepos
, s_lnnoptr
);
402 return_section->linesize = hdr->s_nlnno * sizeof (struct lineno);
406 return_section
->lineno_count
= hdr
->s_nlnno
;
407 return_section
->userdata
= NULL
;
408 return_section
->next
= (asection
*) NULL
;
409 if ((hdr
->s_flags
& STYP_TEXT
) || (hdr
->s_flags
& STYP_DATA
))
410 return_section
->flags
= (SEC_LOAD
| SEC_ALLOC
);
411 else if (hdr
->s_flags
& STYP_BSS
)
412 return_section
->flags
= SEC_ALLOC
;
414 if (hdr
->s_nreloc
!= 0)
415 return_section
->flags
|= SEC_RELOC
;
416 if (hdr
->s_scnptr
!= 0)
417 return_section
->flags
|= SEC_HAS_CONTENTS
;
422 DEFUN(coff_mkobject
,(abfd
),
425 set_tdata (abfd
, bfd_zalloc (abfd
,sizeof(coff_data_type
)));
426 if (coff_data(abfd
) == 0) {
427 bfd_error
= no_memory
;
430 coff_data(abfd
)->relocbase
= 0;
436 DEFUN(coff_real_object_p
,(abfd
, nscns
, opthdr
),
441 coff_data_type
*coff
;
442 char *file_info
; /* buffer for all the headers */
443 size_t readsize
; /* length of file_info */
444 struct filehdr
*filehdr
; /* points into file_info */
445 struct scnhdr
*sections
; /* points into file_info */
447 /* Build a play area */
448 if (coff_mkobject(abfd
) != true)
450 coff
= coff_data(abfd
);
452 /* OK, now we know the format, read in the filehdr, soi-disant "optional
453 header", and all the sections. */
455 readsize
= sizeof(struct filehdr
)
457 + (nscns
* sizeof(struct scnhdr
));
459 file_info
= (PTR
) bfd_alloc(abfd
, readsize
);
460 if (file_info
== NULL
) {
461 bfd_error
= no_memory
;
465 if (bfd_seek(abfd
, 0L, SEEK_SET
) < 0) {
466 bfd_release (abfd
, (PTR
)file_info
);
469 if (bfd_read((PTR
) file_info
, 1, readsize
, abfd
) != readsize
) {
470 bfd_release (abfd
, (PTR
)file_info
);
473 filehdr
= (struct filehdr
*) file_info
;
474 sections
= (struct scnhdr
*) (file_info
+ sizeof(struct filehdr
) + opthdr
);
476 swap_filehdr(abfd
, filehdr
);
478 /* Now copy data as required; construct all asections etc */
479 coff
->symbol_index_slew
= 0;
481 coff
->raw_syment_count
= 0;
482 coff
->raw_linenos
= 0;
483 coff
->raw_syments
= 0;
484 coff
->sym_filepos
=0;
485 coff
->flags
= filehdr
->f_flags
;
488 for (i
= 0; i
< nscns
; i
++) {
489 swap_scnhdr(abfd
, sections
+ i
);
490 make_a_section_from_file(abfd
, sections
+ i
);
493 /* Determine the machine architecture and type. */
494 abfd
->obj_machine
= 0;
495 switch (filehdr
->f_magic
) {
499 abfd
->obj_arch
= bfd_arch_m68k
;
500 abfd
->obj_machine
= 68020;
507 abfd
->obj_arch
= bfd_arch_m88k
;
508 abfd
->obj_machine
= 88100;
514 abfd
->obj_arch
= bfd_arch_i960
;
515 switch (F_I960TYPE
& filehdr
->f_flags
)
519 abfd
->obj_machine
= bfd_mach_i960_core
;
522 abfd
->obj_machine
= bfd_mach_i960_kb_sb
;
525 abfd
->obj_machine
= bfd_mach_i960_mc
;
528 abfd
->obj_machine
= bfd_mach_i960_xa
;
531 abfd
->obj_machine
= bfd_mach_i960_ca
;
534 abfd
->obj_machine
= bfd_mach_i960_ka_sa
;
541 default: /* Unreadable input file type */
542 abfd
->obj_arch
= bfd_arch_obscure
;
546 if (!(filehdr
->f_flags
& F_RELFLG
))
547 abfd
->flags
|= HAS_RELOC
;
548 if ((filehdr
->f_flags
& F_EXEC
))
549 abfd
->flags
|= EXEC_P
;
550 if (!(filehdr
->f_flags
& F_LNNO
))
551 abfd
->flags
|= HAS_LINENO
;
552 if (!(filehdr
->f_flags
& F_LSYMS
))
553 abfd
->flags
|= HAS_LOCALS
;
556 bfd_get_symcount(abfd
) = filehdr
->f_nsyms
;
557 if (filehdr
->f_nsyms
)
558 abfd
->flags
|= HAS_SYMS
;
560 coff
->sym_filepos
= filehdr
->f_symptr
;
561 swap_aouthdr(abfd
, &coff
->hdr
);
563 coff
->symbols
= (coff_symbol_type
*) NULL
;
564 bfd_get_start_address(abfd
) = opthdr
? exec_hdr(abfd
).entry
: 0;
568 bfd_release(abfd
, coff
);
569 return (bfd_target
*)NULL
;
574 Takes a bfd and a symbol, returns a pointer to the coff specific area
575 of the symbol if there is one.
577 static coff_symbol_type
*
578 DEFUN(coff_symbol_from
,(abfd
, symbol
),
582 if (symbol
->the_bfd
->xvec
->flavour
!= bfd_target_coff_flavour_enum
)
583 return (coff_symbol_type
*)NULL
;
585 if (symbol
->the_bfd
->tdata
== (PTR
)NULL
)
586 return (coff_symbol_type
*)NULL
;
588 return (coff_symbol_type
*) symbol
;
594 DEFUN(coff_object_p
,(abfd
),
597 unsigned short magic
,
600 bfd_error
= system_call_error
;
602 /* figure out how much to read */
603 if (bfd_read((PTR
) &magic
, 1, sizeof(magic
), abfd
) != sizeof(magic
))
606 magic
= bfd_h_getshort(abfd
, (bfd_byte
*) (&magic
));
608 if (BADMAG(*((struct filehdr
*) & magic
))) {
609 bfd_error
= wrong_format
;
612 if (bfd_read((PTR
) &nscns
, 1, sizeof(nscns
), abfd
) != sizeof(nscns
))
614 nscns
= bfd_h_getshort(abfd
, (unsigned char *) &nscns
);
615 if (bfd_seek(abfd
, (file_ptr
) & (((struct filehdr
*) NULL
)->f_opthdr
), SEEK_SET
)
618 if (bfd_read((PTR
) &opthdr
, 1, sizeof(opthdr
), abfd
) != sizeof(opthdr
))
620 opthdr
= bfd_h_getshort(abfd
, (unsigned char *) &opthdr
);
622 /* if the optional header is NULL or not the correct size then
623 quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
624 and Intel 960 readwrite headers (I960WRMAGIC) is that the
625 optional header is of a different size
630 return (bfd_target
*)NULL
;
632 return coff_real_object_p(abfd
, nscns
, opthdr
);
639 DEFUN(coff_count_linenumbers
,(abfd
),
642 unsigned int limit
= bfd_get_symcount(abfd
);
646 asection
*s
= abfd
->sections
->output_section
;
648 BFD_ASSERT(s
->lineno_count
== 0);
654 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
655 asymbol
*q_maybe
= *p
;
656 if (q_maybe
->the_bfd
->xvec
->flavour
== bfd_target_coff_flavour_enum
) {
657 coff_symbol_type
*q
= coffsymbol(q_maybe
);
660 This symbol has a linenumber, increment the owning
661 section's linenumber count
663 alent
*l
= q
->lineno
;
664 q
->symbol
.section
->output_section
->lineno_count
++;
666 while (l
->line_number
) {
667 q
->symbol
.section
->output_section
->lineno_count
++;
676 This function returns true if the supplied SYMENT has an AUXENT with
677 a tagndx field which should be relocated.
679 The coff book says that all auxents have this and should be moved,
680 but all the actual implementations I've looked at do this ..
685 DEFUN(uses_x_sym_x_tagndx_p
,(abfd
, native
),
687 struct internal_syment
*native
)
689 if (BTYPE(native
->n_type
) == T_STRUCT
) return true;
690 if (BTYPE(native
->n_type
) == T_UNION
) return true;
691 if (BTYPE(native
->n_type
) == T_ENUM
) return true;
697 This procedure runs through the native entries in a coff symbol table
698 and links up all the elements which should point to one another, in
699 particular these are:
701 strtag, entag and untags have an auxent endindex which points to the
702 first syment after the .eos. This is simple to do, we just keep a
703 pointer to the symbol with the most recent pending strtag and patch it
704 when we see the eos. This works since coff structs are never nested.
706 ISFCN type entries have an endindex which points to the next static or
707 extern in the table, thereby skipping the function contents.
708 The coff book says that an ISFCN's tagindex
709 points to the first .bf for the function, so far I havn't seen it
710 used. We do this using the same mechanism as strtags.
712 Each file entry has a value which points to the next file entry,
713 the last file entry points to the first extern symbol in the table
714 which is not an ISFCN.
716 Each .bb entry points to the matching .eb entry, but these are nested
717 so we keep a stack of them.
719 The tagndx of .eos items points to the strtag attached to them, this
720 is simply the last_tagndx again.
722 The tagndx of items with type strtag point to the defining struct.
723 This bit is complicated; We know that a struct ref and def must be
724 within the same file, so all the natives will be in the same vector.
725 This means that we can subtracts two pointers and get the index
726 differences between to items, used to work out the true index of the
729 We store in the name field of each syment the actual native index
730 applied so we can dig it out through a pointer. */
733 coff_mangle_symbols(bfd_ptr
)
736 unsigned int symbol_count
= bfd_get_symcount(bfd_ptr
);
737 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
738 struct internal_syment
*last_tagndx
= (struct internal_syment
*)NULL
;
739 struct internal_syment
*last_file
= (struct internal_syment
*)NULL
;
740 struct internal_syment
*last_fcn
= (struct internal_syment
*)NULL
;
741 struct internal_syment
*block_stack
[50];
742 struct internal_syment
**last_block
= &block_stack
[0];
743 boolean first_time
= true;
744 unsigned int symbol_index
;
745 unsigned int native_index
= 0;
747 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++) {
748 coff_symbol_type
*coff_symbol_ptr
=
749 coff_symbol_from(bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
750 if (coff_symbol_ptr
== (coff_symbol_type
*)NULL
) {
752 This symbol has no coff information in it, it will take up
753 only one slot in the output symbol table
758 struct internal_syment
*syment
= coff_symbol_ptr
->native
;
759 if (syment
== (struct internal_syment
*)NULL
) {
763 /* Normalize the symbol flags */
764 if (coff_symbol_ptr
->symbol
.flags
& BSF_FORT_COMM
) {
765 /* a common symbol is undefined with a value */
766 syment
->n_scnum
= N_UNDEF
;
767 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
769 else if (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
) {
770 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
772 else if (coff_symbol_ptr
->symbol
.flags
& BSF_UNDEFINED
) {
773 syment
->n_scnum
= N_UNDEF
;
776 else if (coff_symbol_ptr
->symbol
.flags
& BSF_ABSOLUTE
) {
777 syment
->n_scnum
= N_ABS
;
778 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
782 coff_symbol_ptr
->symbol
.section
->output_section
->index
+1;
785 coff_symbol_ptr
->symbol
.value
+
786 coff_symbol_ptr
->symbol
.section
->output_offset
+
787 coff_symbol_ptr
->symbol
.section
->output_section
->vma
;
791 /* If this symbol ties up something then do it */
793 if (syment
->n_sclass
== C_FILE
&& last_file
!= (struct internal_syment
*)NULL
)
795 last_file
->n_value
= native_index
;
797 else if ((syment
->n_sclass
== C_EXT
798 || syment
->n_sclass
== C_STAT
800 || syment
->n_sclass
== C_LEAFEXT
801 || syment
->n_sclass
== C_LEAFSTAT
804 && last_fcn
!= (struct internal_syment
*)NULL
)
806 union internal_auxent
*auxent
= (union internal_auxent
*)(last_fcn
+1);
807 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= native_index
;
808 last_fcn
= (struct internal_syment
*)NULL
;
811 else if (syment
->n_sclass
== C_EOS
&& last_tagndx
!= (struct internal_syment
*)NULL
)
813 union internal_auxent
*auxent
= (union internal_auxent
*)(last_tagndx
+1);
814 /* Remember that we keep the native index in the offset
815 so patch the beginning of the struct to point to this
817 auxent
->x_sym
.x_tagndx
= last_tagndx
->_n
._n_n
._n_offset
;
818 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= syment
->n_numaux
+ 1 + native_index
;
819 /* Now point the eos to the structure */
820 auxent
= (union internal_auxent
*)(syment
+1);
821 auxent
->x_sym
.x_tagndx
= last_tagndx
->_n
._n_n
._n_offset
;
823 else if (syment
->n_sclass
== C_BLOCK
824 && coff_symbol_ptr
->symbol
.name
[1] == 'e')
826 union internal_auxent
*auxent
= (union internal_auxent
*)((*(--last_block
))+1);
827 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= native_index
+ syment
->n_numaux
+ 1;
829 if (syment
->n_sclass
== C_EXT
830 && !ISFCN(syment
->n_type
)
831 && first_time
== true
832 && last_file
!= (struct internal_syment
*)NULL
) {
833 /* This is the first external symbol seen which isn't a
834 function place it in the last .file entry */
835 last_file
->n_value
= native_index
;
839 if (syment
->n_sclass
== C_LEAFPROC
&&
840 bfd_h_get_x(bfd_ptr
, &syment
->n_numaux
) == 2) {
841 union internal_auxent
*auxent
= (union internal_auxent
*)(syment
+2);
842 /* This is the definition of a leaf proc, we'll relocate the
844 auxent
->x_bal
.x_balntry
=
845 coff_symbol_ptr
->symbol
.section
->output_offset
+
846 coff_symbol_ptr
->symbol
.section
->output_section
->vma
+
847 auxent
->x_bal
.x_balntry
;
850 /* If this symbol needs to be tied up then remember some facts */
851 if (syment
->n_sclass
== C_FILE
)
855 if (syment
->n_numaux
!= 0) {
857 If this symbol would like to point to something in the
858 future then remember where it is
860 if (uses_x_sym_x_tagndx_p(bfd_ptr
, syment
)) {
862 If this is a ref to a structure then we'll tie it up
863 now - there are never any forward refs for one
865 if (syment
->n_sclass
== C_STRTAG
||
866 syment
->n_sclass
== C_ENTAG
||
867 syment
->n_sclass
== C_UNTAG
) {
868 last_tagndx
= syment
;
872 This is a ref to a structure - the structure must
873 have been defined within the same file, and previous
874 to this point, so we can deduce the new tagndx
877 union internal_auxent
*auxent
= (union internal_auxent
*)(syment
+1);
878 bfd
*bfd_ptr
= coff_symbol_ptr
->symbol
.the_bfd
;
879 struct internal_syment
*base
= obj_raw_syments(bfd_ptr
);
880 auxent
->x_sym
.x_tagndx
= base
[auxent
->x_sym
.x_tagndx
]._n
._n_n
._n_offset
;
885 if (ISFCN(syment
->n_type
)) {
888 if (bfd_h_get_x(bfd_ptr
, & syment
->n_sclass
) == C_BLOCK
889 && coff_symbol_ptr
->symbol
.name
[1] == 'b')
891 *last_block
++ = syment
;
894 syment
->_n
._n_n
._n_offset
= native_index
;
895 native_index
= native_index
+ 1 + syment
->n_numaux
;
903 coff_write_symbols(abfd
)
907 unsigned int limit
= bfd_get_symcount(abfd
);
908 unsigned int written
= 0;
909 struct internal_syment dummy
;
911 unsigned int string_size
= 0;
914 /* Seek to the right place */
915 bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
);
917 /* Output all the symbols we have */
920 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
921 asymbol
*symbol
= *p
;
922 coff_symbol_type
*c_symbol
= coff_symbol_from(abfd
, symbol
);
925 struct internal_syment
*native
;
926 if (c_symbol
== (coff_symbol_type
*) NULL
||
927 c_symbol
->native
== (struct internal_syment
*) NULL
) {
929 This symbol has been created by the loader, or come from a non
930 coff format. It has no native element to inherit, make our
935 native
->n_type
= T_NULL
;
939 if (symbol
->flags
& BSF_ABSOLUTE
) {
940 native
->n_scnum
= N_ABS
;
941 native
->n_value
= symbol
->value
;
943 else if (symbol
->flags
& (BSF_UNDEFINED
| BSF_FORT_COMM
)) {
944 native
->n_scnum
= N_UNDEF
;
945 native
->n_value
= symbol
->value
;
947 else if (symbol
->flags
& BSF_DEBUGGING
) {
949 remove name so it doesn't take up any space
955 native
->n_scnum
= symbol
->section
->output_section
->index
+
957 native
->n_value
= symbol
->value
+
958 symbol
->section
->output_section
->vma
+
959 symbol
->section
->output_offset
;
961 /* Copy the any flags from the the file hdr into the symbol */
963 coff_symbol_type
*c
= coff_symbol_from(abfd
, symbol
);
964 if (c
!= (coff_symbol_type
*)NULL
) {
965 native
->n_flags
= c
->symbol
.the_bfd
->flags
;
977 if (symbol
->flags
& BSF_LOCAL
)
978 native
->n_sclass
= C_STAT
;
980 native
->n_sclass
= C_EXT
;
981 native
->n_numaux
= 0;
985 Does this symbol have an ascociated line number - if so then
986 make it remember this symbol index. Also tag the auxent of
987 this symbol to point to the right place in the lineno table
990 alent
*lineno
= c_symbol
->lineno
;
991 native
= c_symbol
->native
;
993 unsigned int count
= 0;
994 lineno
[count
].u
.offset
= written
;
995 if (native
->n_numaux
) {
996 union internal_auxent
*a
= (union internal_auxent
*) (native
+ 1);
998 a
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
999 c_symbol
->symbol
.section
->output_section
->moving_line_filepos
;
1002 And count and relocate all other linenumbers
1005 while (lineno
[count
].line_number
) {
1006 lineno
[count
].u
.offset
+=
1007 c_symbol
->symbol
.section
->output_section
->vma
+
1008 c_symbol
->symbol
.section
->output_offset
;
1011 c_symbol
->symbol
.section
->output_section
->moving_line_filepos
+=
1015 } /* if symbol new to coff */
1017 /* Fix the symbol names */
1019 unsigned int name_length
;
1020 if (symbol
->name
== (char *) NULL
) {
1022 coff symbols always have names, so we'll make one up
1024 symbol
->name
= "strange";
1026 name_length
= strlen(symbol
->name
);
1027 if (name_length
<= SYMNMLEN
) {
1028 /* This name will fit into the symbol neatly */
1029 strncpy(native
->_n
._n_name
, symbol
->name
, SYMNMLEN
);
1032 native
->_n
._n_n
._n_offset
= string_size
+ 4;
1033 native
->_n
._n_n
._n_zeroes
= 0;
1034 string_size
+= name_length
+ 1;
1037 unsigned int numaux
= native
->n_numaux
;
1038 int type
= native
->n_type
;
1039 int class = native
->n_sclass
;
1041 bfd_coff_swap_sym_out(abfd
, native
, &buf
);
1042 bfd_write((PTR
)& buf
, 1, SYMESZ
, abfd
);
1043 for (j
= 0; j
!= bfd_h_get_x(abfd
, &native
->n_numaux
);
1046 bfd_coff_swap_aux_out(abfd
,
1047 (union internal_auxent
*)(native
+ j
+ 1), type
, class, &buf1
);
1048 bfd_write((PTR
) (native
+ j
+ 1), 1, AUXESZ
, abfd
);
1051 Reuse somewhere in the symbol to keep the index
1053 set_index(symbol
, written
);
1054 written
+= 1 + numaux
;
1057 } /* for each out symbol */
1059 bfd_get_symcount(abfd
) = written
;
1060 /* Now write out strings */
1063 unsigned int size
= string_size
+ 4;
1065 bfd_write((PTR
) &size
, 1, sizeof(size
), abfd
);
1066 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
1068 size_t name_length
= strlen(q
->name
);
1069 if (name_length
> SYMNMLEN
) {
1070 bfd_write((PTR
) (q
->name
), 1, name_length
+ 1, abfd
);
1075 /* We would normally not write anything here, but we'll write
1076 out 4 so that any stupid coff reader which tries to read
1077 the string table even when there isn't one won't croak.
1080 uint32e_type size
= 4;
1082 bfd_write((PTR
)&size
, 1, sizeof(size
), abfd
);
1089 coff_write_relocs(abfd
)
1093 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
) {
1095 struct external_reloc dst
;
1097 arelent
**p
= s
->orelocation
;
1098 bfd_seek(abfd
, s
->rel_filepos
, SEEK_SET
);
1099 for (i
= 0; i
< s
->reloc_count
; i
++) {
1100 struct internal_reloc n
;
1102 memset((PTR
)&n
, 0, sizeof(n
));
1103 n
.r_vaddr
= q
->address
+ s
->vma
;
1104 if (q
->sym_ptr_ptr
) {
1105 n
.r_symndx
= get_index((*(q
->sym_ptr_ptr
)));
1108 /* Work out reloc type from what is required */
1109 SELECT_RELOC(n
.r_type
, q
->howto
);
1111 n
.r_type
= q
->howto
->type
;
1113 swap_reloc_out(abfd
, &n
, &dst
);
1114 bfd_write((PTR
) &n
, 1, RELSZ
, abfd
);
1120 coff_write_linenumbers(abfd
)
1124 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
) {
1125 if (s
->lineno_count
) {
1126 asymbol
**q
= abfd
->outsymbols
;
1127 bfd_seek(abfd
, s
->line_filepos
, SEEK_SET
);
1128 /* Find all the linenumbers in this section */
1131 alent
*l
= BFD_SEND(p
->the_bfd
, _get_lineno
, (p
->the_bfd
, p
));
1133 /* Found a linenumber entry, output */
1134 struct internal_lineno out
;
1136 bzero( (PTR
)&out
, sizeof(out
));
1138 out
.l_addr
.l_symndx
= l
->u
.offset
;
1139 bfd_coff_swap_lineno_out(abfd
, &out
, &buff
);
1140 bfd_write((PTR
) &buff
, 1, LINESZ
, abfd
);
1142 while (l
->line_number
) {
1143 out
.l_lnno
= l
->line_number
;
1144 out
.l_addr
.l_symndx
= l
->u
.offset
;
1145 bfd_coff_swap_lineno_out(abfd
, &out
, &buff
);
1146 bfd_write((PTR
) &buff
, 1, LINESZ
, abfd
);
1158 coff_make_empty_symbol(abfd
)
1161 coff_symbol_type
*new = (coff_symbol_type
*) bfd_alloc(abfd
, sizeof(coff_symbol_type
));
1163 bfd_error
= no_memory
;
1167 new->lineno
= (alent
*) NULL
;
1168 new->symbol
.the_bfd
= abfd
;
1169 return &new->symbol
;
1173 coff_print_symbol(ignore_abfd
, file
, symbol
, how
)
1177 bfd_print_symbol_enum_type how
;
1180 case bfd_print_symbol_name_enum
:
1181 fprintf(file
, "%s", symbol
->name
);
1183 case bfd_print_symbol_type_enum
:
1184 fprintf(file
, "coff %lx %lx", (unsigned long) coffsymbol(symbol
)->native
,
1185 (unsigned long) coffsymbol(symbol
)->lineno
);
1187 case bfd_print_symbol_all_enum
:
1189 CONST
char *section_name
= symbol
->section
== (asection
*) NULL
?
1190 "*abs" : symbol
->section
->name
;
1191 bfd_print_symbol_vandf((PTR
) file
, symbol
);
1193 fprintf(file
, " %-5s %s %s %s",
1195 coffsymbol(symbol
)->native
? "n" : "g",
1196 coffsymbol(symbol
)->lineno
? "l" : " ",
1206 coff_get_lineno(ignore_abfd
, symbol
)
1210 return coffsymbol(symbol
)->lineno
;
1214 Set flags and magic number of a coff file from architecture and machine
1215 type. Result is true if we can represent the arch&type, false if not.
1218 coff_set_flags(abfd
, magicp
, flagsp
)
1224 switch (abfd
->obj_arch
) {
1232 *magicp
= I960ROMAGIC
;
1234 ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC :
1235 I960RWMAGIC); FIXME???
1237 switch (abfd
->obj_machine
) {
1238 case bfd_mach_i960_core
:
1241 case bfd_mach_i960_kb_sb
:
1244 case bfd_mach_i960_mc
:
1247 case bfd_mach_i960_xa
:
1250 case bfd_mach_i960_ca
:
1253 case bfd_mach_i960_ka_sa
:
1267 *magicp
= MC68MAGIC
;
1273 *magicp
= MC88OMAGIC
;
1278 default: /* Unknown architecture */
1287 coff_set_arch_mach(abfd
, arch
, machine
)
1289 enum bfd_architecture arch
;
1290 unsigned long machine
;
1294 abfd
->obj_arch
= arch
;
1295 abfd
->obj_machine
= machine
;
1296 if (arch
!= bfd_arch_unknown
&&
1297 coff_set_flags(abfd
, &dummy1
, &dummy2
) != true)
1298 return false; /* We can't represent this type */
1299 return true; /* We're easy ... */
1303 /* Calculate the file position for each section. */
1306 coff_compute_section_file_positions(abfd
)
1310 file_ptr sofar
= FILHSZ
;
1311 if (bfd_get_start_address(abfd
)) {
1313 A start address may have been added to the original file. In this
1314 case it will need an optional header to record it.
1316 abfd
->flags
|= EXEC_P
;
1318 if (abfd
->flags
& EXEC_P
)
1322 sofar
+= abfd
->section_count
* SCNHSZ
;
1324 for (current
= abfd
->sections
; current
!= NULL
; current
=
1326 /* Only deal with sections which have contents */
1327 if (!(current
->flags
& SEC_HAS_CONTENTS
))
1330 /* Align the sections in the file to the same boundary on
1331 which they are aligned in virtual memory. I960 doesn't
1332 do this (FIXME) so we can stay in sync with Intel. 960
1333 doesn't yet page from files... */
1335 sofar
= ALIGN(sofar
, 1 << current
->alignment_power
);
1337 /* FIXME, in demand paged files, the low order bits of the file
1338 offset must match the low order bits of the virtual address.
1339 "Low order" is apparently implementation defined. Add code
1340 here to round sofar up to match the virtual address. */
1342 current
->filepos
= sofar
;
1343 sofar
+= current
->size
;
1345 obj_relocbase(abfd
) = sofar
;
1354 coff_write_object_contents(abfd
)
1357 struct filehdr file_header
;
1359 boolean hasrelocs
= false;
1360 boolean haslinno
= false;
1361 file_ptr reloc_base
;
1362 file_ptr lineno_base
;
1366 unsigned long reloc_size
= 0;
1367 unsigned long lnno_size
= 0;
1368 asection
*text_sec
= NULL
;
1369 asection
*data_sec
= NULL
;
1370 asection
*bss_sec
= NULL
;
1375 struct icofdata
*coff
= obj_icof(abfd
);
1378 bfd_error
= system_call_error
;
1381 if(abfd
->output_has_begun
== false) {
1382 coff_compute_section_file_positions(abfd
);
1385 if (abfd
->sections
!= (asection
*)NULL
) {
1386 scn_base
= abfd
->sections
->filepos
;
1391 if (bfd_seek(abfd
, scn_base
, SEEK_SET
) != 0)
1393 reloc_base
= obj_relocbase(abfd
);
1395 /* Make a pass through the symbol table to count line number entries and
1396 put them into the correct asections */
1398 coff_count_linenumbers(abfd
);
1399 data_base
= scn_base
;
1401 /* Work out the size of the reloc and linno areas */
1403 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1404 reloc_size
+= current
->reloc_count
* RELSZ
;
1405 lnno_size
+= current
->lineno_count
* LINESZ
;
1406 data_base
+= SCNHSZ
;
1409 lineno_base
= reloc_base
+ reloc_size
;
1410 sym_base
= lineno_base
+ lnno_size
;
1412 /* Indicate in each section->line_filepos its actual file address */
1413 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1414 if (current
->lineno_count
) {
1415 current
->line_filepos
= lineno_base
;
1416 current
->moving_line_filepos
= lineno_base
;
1417 lineno_base
+= current
->lineno_count
* LINESZ
;
1420 current
->line_filepos
= 0;
1422 if (current
->reloc_count
) {
1423 current
->rel_filepos
= reloc_base
;
1424 reloc_base
+= current
->reloc_count
* sizeof(struct internal_reloc
);
1427 current
->rel_filepos
= 0;
1431 /* Write section headers to the file. */
1434 (file_ptr
) ((abfd
->flags
& EXEC_P
) ?
1435 (FILHSZ
+ AOUTSZ
) : FILHSZ
),
1440 unsigned int pad
= abfd
->flags
& D_PAGED
? data_base
: 0;
1442 unsigned int pad
= 0;
1444 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1446 strncpy(&(section
.s_name
[0]), current
->name
, 8);
1447 section
.s_vaddr
= current
->vma
+ pad
;
1448 section
.s_paddr
= current
->vma
+ pad
;
1449 section
.s_size
= current
->size
- pad
;
1451 If this section has no size or is unloadable then the scnptr
1454 if (current
->size
- pad
== 0 ||
1455 (current
->flags
& SEC_LOAD
) == 0) {
1456 section
.s_scnptr
= 0;
1460 section
.s_scnptr
= current
->filepos
;
1462 section
.s_relptr
= current
->rel_filepos
;
1463 section
.s_lnnoptr
= current
->line_filepos
;
1464 section
.s_nreloc
= current
->reloc_count
;
1465 section
.s_nlnno
= current
->lineno_count
;
1466 if (current
->reloc_count
!= 0)
1468 if (current
->lineno_count
!= 0)
1471 if (!strcmp(current
->name
, _TEXT
)) {
1473 section
.s_flags
= STYP_TEXT
; /* kinda stupid */
1475 else if (!strcmp(current
->name
, _DATA
)) {
1477 section
.s_flags
= STYP_DATA
; /* kinda stupid */
1479 else if (!strcmp(current
->name
, _BSS
)) {
1481 section
.s_flags
= STYP_BSS
; /* kinda stupid */
1486 section
.s_align
= (current
->alignment_power
1487 ? 1 << current
->alignment_power
1491 swap_scnhdr(abfd
, §ion
);
1492 bfd_write((PTR
) (§ion
), 1, SCNHSZ
, abfd
);
1497 /* OK, now set up the filehdr... */
1499 bfd_h_put_x(abfd
, abfd
->section_count
, &file_header
.f_nscns
);
1501 We will NOT put a fucking timestamp in the header here. Every time you
1502 put it back, I will come in and take it out again. I'm sorry. This
1503 field does not belong here. We fill it with a 0 so it compares the
1504 same but is not a reasonable time. -- gnu@cygnus.com
1507 Well, I like it, so I'm conditionally compiling it in.
1510 #ifdef COFF_TIMESTAMP
1511 bfd_h_put_x(abfd
, time(0), &file_header
.f_timdat
);
1513 bfd_h_put_x(abfd
, 0, &file_header
.f_timdat
);
1516 if (bfd_get_symcount(abfd
) != 0)
1517 bfd_h_put_x(abfd
, sym_base
, &file_header
.f_symptr
);
1519 bfd_h_put_x(abfd
, 0, &file_header
.f_symptr
);
1521 file_header
.f_flags
= 0;
1523 if (abfd
->flags
& EXEC_P
)
1524 bfd_h_put_x(abfd
, sizeof(AOUTHDR
), &file_header
.f_opthdr
);
1526 bfd_h_put_x(abfd
, 0, &file_header
.f_opthdr
);
1529 file_header
.f_flags
|= F_RELFLG
;
1531 file_header
.f_flags
|= F_LNNO
;
1532 if (0 == bfd_get_symcount(abfd
))
1533 file_header
.f_flags
|= F_LSYMS
;
1534 if (abfd
->flags
& EXEC_P
)
1535 file_header
.f_flags
|= F_EXEC
;
1537 file_header
.f_flags
|= F_AR32W
;
1539 if (!abfd
->xvec
->byteorder_big_p
)
1540 file_header
.f_flags
|= F_AR32WR
;
1543 FIXME, should do something about the other byte orders and
1547 /* Set up architecture-dependent stuff */
1551 coff_set_flags(abfd
, &magic
, &flags
);
1552 file_header
.f_flags
|= flags
;
1554 bfd_h_put_x(abfd
, magic
, &file_header
.f_magic
);
1555 bfd_h_put_x(abfd
, file_header
.f_flags
, &file_header
.f_flags
);
1557 /* ...and the "opt"hdr... */
1559 bfd_h_put_x(abfd
, (magic
== I960ROMAGIC
? NMAGIC
: OMAGIC
),
1560 &(exec_hdr(abfd
).magic
));
1563 exec_hdr(abfd
).magic
= PAGEMAGICBCS
;
1566 /* Now should write relocs, strings, syms */
1567 obj_sym_filepos(abfd
) = sym_base
;
1569 if (bfd_get_symcount(abfd
) != 0) {
1570 coff_mangle_symbols(abfd
);
1571 coff_write_symbols(abfd
);
1572 coff_write_linenumbers(abfd
);
1573 coff_write_relocs(abfd
);
1576 bfd_h_put_x(abfd
, text_sec
->size
, &coff
->hdr
.tsize
);
1578 text_sec
->size
? text_sec
->vma
: 0,
1579 &exec_hdr(abfd
).text_start
);
1582 bfd_h_put_x(abfd
, data_sec
->size
, &coff
->hdr
.dsize
);
1584 data_sec
->size
? data_sec
->vma
: 0,
1585 &exec_hdr(abfd
).data_start
);
1588 bfd_h_put_x(abfd
, bss_sec
->size
, &coff
->hdr
.bsize
);
1591 bfd_h_put_x(abfd
, bfd_get_start_address(abfd
), &coff
->hdr
.entry
);
1592 bfd_h_put_x(abfd
, bfd_get_symcount(abfd
), &file_header
.f_nsyms
);
1594 /* now write them */
1595 if (bfd_seek(abfd
, 0L, SEEK_SET
) != 0)
1598 bfd_write((PTR
) &file_header
, 1, FILHSZ
, abfd
);
1600 if (abfd
->flags
& EXEC_P
) {
1601 bfd_write((PTR
) &coff
->hdr
, 1, AOUTSZ
, abfd
);
1607 coff_set_section_contents(abfd
, section
, location
, offset
, count
)
1614 if (abfd
->output_has_begun
== false) /* set by bfd.c handler */
1615 coff_compute_section_file_positions(abfd
);
1617 bfd_seek(abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
1620 return (bfd_write(location
, 1, count
, abfd
) == count
) ? true : false;
1627 buy_and_read(abfd
, where
, seek_direction
, size
)
1633 PTR area
= (PTR
) bfd_alloc(abfd
, size
);
1635 bfd_error
= no_memory
;
1638 bfd_seek(abfd
, where
, seek_direction
);
1639 if (bfd_read(area
, 1, size
, abfd
) != size
) {
1640 bfd_error
= system_call_error
;
1644 } /* buy_and_read() */
1647 DEFUN(offset_symbol_indices
,(abfd
, symtab
, count
, offset
),
1649 struct internal_syment
*symtab AND
1650 unsigned long count AND
1653 struct internal_syment
*end
= symtab
+ count
;
1654 for (; symtab
< end
; ++symtab
) {
1655 if (bfd_h_get_x(abfd
, &symtab
->n_sclass
) == C_FILE
) {
1656 bfd_h_put_x(abfd
, 0, & symtab
->n_value
);
1658 else if (bfd_h_get_x(abfd
, &symtab
->n_sclass
) == C_ALIAS
) {
1660 These guys have indices in their values.
1662 bfd_h_put_x(abfd
, bfd_h_get_x(abfd
, & symtab
->n_value
) + offset
, & symtab
->n_value
);
1665 else if (symtab
->n_numaux
) {
1667 anybody else without an aux, has no indices.
1670 if (symtab
->n_sclass
== C_EOS
1671 || (BTYPE(symtab
->n_type
) == T_STRUCT
1672 && symtab
->n_sclass
!= C_STRTAG
)
1673 || BTYPE(symtab
->n_type
) == T_UNION
1674 || BTYPE(symtab
->n_type
) == T_ENUM
) {
1675 /* If the tagndx is 0 then the struct hasn't really been
1676 defined, so leave it alone */
1678 if(((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tagndx
!= 0) {
1679 ((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tagndx
+= offset
;
1682 } /* These guys have a tagndx */
1683 if (symtab
->n_sclass
== C_STRTAG
1684 || symtab
->n_sclass
== C_UNTAG
1685 || symtab
->n_sclass
== C_ENTAG
1686 || symtab
->n_sclass
== C_BLOCK
1687 || symtab
->n_sclass
== C_FCN
1688 || ISFCN(bfd_h_get_x(abfd
, &symtab
->n_type
))) {
1690 ((union internal_auxent
*) (symtab
+
1691 1))->x_sym
.x_fcnary
.x_fcn
.x_endndx
1694 } /* These guys have an endndx */
1696 if (ISFCN(bfd_h_get_x(abfd
,& symtab
->n_type
))) {
1697 ((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tvndx
+= offset
;
1698 } /* These guys have a tvndx. I think...
1700 #endif /* Not I960 */
1702 } /* if value, else if aux */
1703 symtab
+= bfd_h_get_x(abfd
, &symtab
->n_numaux
);
1704 } /* walk the symtab */
1707 } /* offset_symbol_indices() */
1710 /* swap the entire symbol table - we c*/
1712 swap_raw_symtab(abfd
, raw_symtab
)
1717 SYMENT
*end
= raw_symtab
+ bfd_get_symcount(abfd
);
1718 for (; raw_symtab
< end
; ++raw_symtab
) {
1719 bfd_coff_swap_sym(abfd
, raw_symtab
);
1721 for (i
= raw_symtab
->n_numaux
; i
; --i
, ++raw_symtab
) {
1722 bfd_coff_swap_aux(abfd
,
1723 (AUXENT
*)(raw_symtab
+ 1),
1725 raw_symtab
->n_sclass
);
1726 } /* swap all the aux entries */
1727 } /* walk the symbol table */
1730 } /* swap_raw_symtab() */
1733 read a symbol table into freshly mallocated memory, swap it, and knit the
1734 symbol names into a normalized form. By normalized here I mean that all
1735 symbols have an n_offset pointer that points to a NULL terminated string.
1736 Oh, and the first symbol MUST be a C_FILE. If there wasn't one there
1737 before, put one there.
1740 static struct internal_syment
*
1741 DEFUN(get_normalized_symtab
,(abfd
),
1745 struct internal_syment
*internal
;
1746 struct internal_syment
*internal_ptr
;
1747 struct internal_syment
*internal_end
;
1751 char *string_table
= NULL
;
1753 char string_table_size_buffer
[4];
1754 unsigned long string_table_size
= 0;
1755 unsigned int raw_size
;
1756 if (obj_raw_syments(abfd
) != (struct internal_syment
*)NULL
) {
1757 return obj_raw_syments(abfd
);
1759 if ((size
= bfd_get_symcount(abfd
) * sizeof(struct internal_syment
)) == 0) {
1760 bfd_error
= no_symbols
;
1764 internal
= (struct internal_syment
*)bfd_alloc(abfd
, size
);
1765 internal_end
= internal
+ bfd_get_symcount(abfd
);
1767 raw_size
= bfd_get_symcount(abfd
) * SYMESZ
;
1768 raw
= (SYMENT
*)bfd_alloc(abfd
,raw_size
);
1770 if (bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
) == -1
1771 || bfd_read((PTR
)raw
, raw_size
, 1, abfd
) != raw_size
) {
1772 bfd_error
= system_call_error
;
1775 /* mark the end of the symbols */
1776 raw_end
= raw
+ bfd_get_symcount(abfd
);
1778 FIXME SOMEDAY. A string table size of zero is very weird, but
1779 probably possible. If one shows up, it will probably kill us.
1782 /* Swap all the raw entries */
1783 for (raw_src
= raw
, internal_ptr
= internal
; raw_src
< raw_end
; raw_src
++, internal_ptr
++) {
1785 bfd_coff_swap_sym_in(abfd
, raw_src
,internal_ptr
);
1786 for (i
= internal_ptr
->n_numaux
; i
; --i
, raw_src
++, internal_ptr
++) {
1787 bfd_coff_swap_aux_in(abfd
, (AUXENT
*)(raw_src
+1), internal_ptr
->n_type
,
1788 internal_ptr
->n_sclass
, (union
1789 internal_auxent
*)(internal_ptr
+1));
1793 /* Free all the raw stuff */
1794 bfd_release(abfd
, raw_src
);
1796 for (internal_ptr
= internal
; internal_ptr
< internal_end
; internal_ptr
++) {
1798 if (internal_ptr
->_n
._n_n
._n_zeroes
!= 0) {
1800 This is a "short" name. Make it long.
1802 unsigned long i
= 0;
1803 char *newstring
= NULL
;
1805 find the length of this string without walking into memory
1809 for (i
= 0; i
< 8; ++i
) {
1810 if (internal_ptr
->_n
._n_name
[i
] == '\0') {
1812 } /* if end of string */
1813 } /* possible lengths of this string. */
1815 if ((newstring
= (PTR
) bfd_alloc(abfd
, ++i
)) == NULL
) {
1816 bfd_error
= no_memory
;
1819 bzero(newstring
, i
);
1820 strncpy(newstring
, internal_ptr
->_n
._n_name
, i
-1);
1821 internal_ptr
->_n
._n_n
._n_offset
= (int) newstring
;
1822 internal_ptr
->_n
._n_n
._n_zeroes
= 0;
1826 if (string_table
== NULL
) {
1828 NOTE: we don't read the string table until now because we
1829 don't necessarily know that we have one until now.
1832 At this point we should be "seek"'d to the end of the
1833 symbols === the symbol table size.
1836 if (bfd_read((char *) &string_table_size_buffer
,
1837 sizeof(string_table_size_buffer
),
1838 1, abfd
) != sizeof(string_table_size
)) {
1839 bfd_error
= system_call_error
;
1843 string_table_size
= bfd_h_getlong(abfd
, &string_table_size_buffer
);
1845 if ((string_table
= (PTR
) bfd_alloc(abfd
, string_table_size
-= 4)) == NULL
) {
1846 bfd_error
= no_memory
;
1848 } /* on mallocation error */
1849 if (bfd_read(string_table
, string_table_size
, 1, abfd
) != string_table_size
) {
1850 bfd_error
= system_call_error
;
1853 } /* have not yet read the string table. */
1855 This is a long name already. Just point it at the string in
1858 internal_ptr
->_n
._n_n
._n_offset
= (int) (string_table
- 4 + internal_ptr
->_n
._n_n
._n_offset
);
1860 } /* switch on type of symbol name */
1862 internal_ptr
+= internal_ptr
->n_numaux
;
1863 } /* for each symbol */
1866 /* I'm not sure of the repercussions of this, so the Intel
1867 folks will always do the force
1869 if (obj_symbol_slew(abfd
) > 0)
1870 force_indices_file_symbol_relative(abfd
, internal
);
1872 force_indices_file_symbol_relative(abfd
, internal
);
1875 obj_raw_syments(abfd
) = internal
;
1876 obj_string_table(abfd
) = string_table
;
1879 } /* get_normalized_symtab() */
1883 DEFUN(section_from_bfd_index
,(abfd
, index
),
1888 struct sec
*answer
= abfd
->sections
;
1890 answer
= answer
->next
;
1901 coff_slurp_line_table(abfd
, asect
)
1905 LINENO
*native_lineno
;
1906 alent
*lineno_cache
;
1908 BFD_ASSERT(asect
->lineno
== (alent
*) NULL
);
1910 native_lineno
= (LINENO
*) buy_and_read(abfd
,
1911 asect
->line_filepos
,
1914 asect
->lineno_count
));
1916 (alent
*) bfd_alloc(abfd
, (size_t) ((asect
->lineno_count
+ 1) * sizeof(alent
)));
1917 if (lineno_cache
== NULL
) {
1918 bfd_error
= no_memory
;
1921 unsigned int counter
= 0;
1922 alent
*cache_ptr
= lineno_cache
;
1923 LINENO
*src
= native_lineno
;
1925 while (counter
< asect
->lineno_count
) {
1926 struct internal_lineno dst
;
1927 bfd_coff_swap_lineno_in(abfd
, src
, &dst
);
1928 cache_ptr
->line_number
= dst
.l_lnno
;
1930 if (cache_ptr
->line_number
== 0) {
1931 coff_symbol_type
*sym
=
1932 (coff_symbol_type
*) (dst
.l_addr
.l_symndx
1933 + obj_symbol_slew(abfd
)
1934 + obj_raw_syments(abfd
))->_n
._n_n
._n_zeroes
;
1935 cache_ptr
->u
.sym
= (asymbol
*) sym
;
1936 sym
->lineno
= cache_ptr
;
1939 cache_ptr
->u
.offset
= dst
.l_addr
.l_paddr
1940 - bfd_section_vma(abfd
, asect
);
1941 } /* If no linenumber expect a symbol index */
1947 cache_ptr
->line_number
= 0;
1950 asect
->lineno
= lineno_cache
;
1951 /* FIXME, free native_lineno here, or use alloca or something. */
1953 } /* coff_slurp_line_table() */
1955 static struct internal_syment
*
1956 DEFUN(find_next_file_symbol
,(abfd
, current
, end
),
1958 struct internal_syment
*current AND
1959 struct internal_syment
*end
)
1961 current
+= current
->n_numaux
+ 1;
1963 while (current
< end
) {
1964 if (current
->n_sclass
== C_FILE
) {
1967 current
+= current
->n_numaux
+ 1;
1974 Note that C_FILE symbols can, and some do, have more than 1 aux entry.
1978 DEFUN(force_indices_file_symbol_relative
,(abfd
, symtab
),
1980 struct internal_syment
*symtab
)
1982 struct internal_syment
*end
= symtab
+ bfd_get_symcount(abfd
);
1983 struct internal_syment
*current
;
1984 struct internal_syment
*next
;
1985 /* the first symbol had damn well better be a C_FILE. */
1986 BFD_ASSERT(symtab
->n_sclass
== C_FILE
);
1988 for (current
= find_next_file_symbol(abfd
, symtab
, end
);
1991 offset_symbol_indices(abfd
, current
,
1993 find_next_file_symbol(abfd
, current
,
2001 DEFUN(coff_slurp_symbol_table
,(abfd
),
2004 struct internal_syment
*native_symbols
;
2005 coff_symbol_type
*cached_area
;
2006 unsigned int *table_ptr
;
2008 unsigned int number_of_symbols
= 0;
2009 if (obj_symbols(abfd
))
2011 bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
);
2013 /* Read in the symbol table */
2014 if ((native_symbols
= get_normalized_symtab(abfd
)) == NULL
) {
2019 /* Allocate enough room for all the symbols in cached form */
2021 (coff_symbol_type
*)
2022 bfd_alloc(abfd
, (size_t) (bfd_get_symcount(abfd
) * sizeof(coff_symbol_type
)));
2024 if (cached_area
== NULL
) {
2025 bfd_error
= no_memory
;
2030 bfd_alloc(abfd
, (size_t) (bfd_get_symcount(abfd
) * sizeof(unsigned int)));
2032 if (table_ptr
== NULL
) {
2033 bfd_error
= no_memory
;
2036 coff_symbol_type
*dst
= cached_area
;
2037 unsigned int last_native_index
= bfd_get_symcount(abfd
);
2038 unsigned int this_index
= 0;
2039 while (this_index
< last_native_index
) {
2040 struct internal_syment
*src
= native_symbols
+ this_index
;
2041 table_ptr
[this_index
] = number_of_symbols
;
2042 dst
->symbol
.the_bfd
= abfd
;
2044 dst
->symbol
.name
= (char *)(src
->_n
._n_n
._n_offset
);
2046 We use the native name field to point to the cached field
2048 src
->_n
._n_n
._n_zeroes
= (int) dst
;
2049 dst
->symbol
.section
= section_from_bfd_index(abfd
,
2051 switch (src
->n_sclass
) {
2055 dst
->symbol
.value
= src
->n_value
- dst
->symbol
.section
->vma
;
2056 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
;
2057 dst
->symbol
.flags
|= BSF_NOT_AT_END
;
2059 /* Fall through to next case */
2064 if ((src
->n_scnum
) == 0) {
2065 if ((src
->n_value
) == 0) {
2066 dst
->symbol
.flags
= BSF_UNDEFINED
;
2067 dst
->symbol
.value
= 0;
2070 dst
->symbol
.flags
= BSF_FORT_COMM
;
2071 dst
->symbol
.value
= (src
->n_value
);
2076 Base the value as an index from the base of the
2079 if (dst
->symbol
.section
== (asection
*) NULL
) {
2080 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
| BSF_ABSOLUTE
;
2081 dst
->symbol
.value
= src
->n_value
;
2084 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
;
2085 dst
->symbol
.value
= src
->n_value
- dst
->symbol
.section
->vma
;
2087 if (ISFCN((src
->n_type
))) {
2089 A function ext does not go at the end of a file
2091 dst
->symbol
.flags
|= BSF_NOT_AT_END
;
2096 case C_STAT
: /* static */
2098 case C_LEAFSTAT
: /* static leaf procedure */
2100 case C_LABEL
: /* label */
2101 dst
->symbol
.flags
= BSF_LOCAL
;
2103 Base the value as an index from the base of the section
2105 dst
->symbol
.value
= (src
->n_value
) - dst
->symbol
.section
->vma
;
2108 case C_MOS
: /* member of structure */
2109 case C_EOS
: /* end of structure */
2110 case C_REGPARM
: /* register parameter */
2111 case C_REG
: /* register variable */
2113 case C_AUTOARG
: /* 960-specific storage class */
2115 case C_TPDEF
: /* type definition */
2118 case C_AUTO
: /* automatic variable */
2119 case C_FIELD
: /* bit field */
2120 case C_ENTAG
: /* enumeration tag */
2121 case C_MOE
: /* member of enumeration */
2122 case C_MOU
: /* member of union */
2123 case C_UNTAG
: /* union tag */
2125 dst
->symbol
.flags
= BSF_DEBUGGING
;
2126 dst
->symbol
.value
= (src
->n_value
);
2129 case C_FILE
: /* file name */
2130 case C_STRTAG
: /* structure tag */
2131 dst
->symbol
.flags
= BSF_DEBUGGING
;
2132 dst
->symbol
.value
= (src
->n_value
);
2135 case C_BLOCK
: /* ".bb" or ".eb" */
2136 case C_FCN
: /* ".bf" or ".ef" */
2137 dst
->symbol
.flags
= BSF_LOCAL
;
2139 Base the value as an index from the base of the section
2141 dst
->symbol
.value
= (src
->n_value
) - dst
->symbol
.section
->vma
;
2144 case C_EFCN
: /* physical end of function */
2146 case C_EXTDEF
: /* external definition */
2147 case C_ULABEL
: /* undefined label */
2148 case C_USTATIC
: /* undefined static */
2149 case C_LINE
: /* line # reformatted as symbol table entry */
2150 case C_ALIAS
: /* duplicate tag */
2151 case C_HIDDEN
: /* ext symbol in dmert public lib */
2156 dst
->symbol
.flags
= BSF_DEBUGGING
;
2157 dst
->symbol
.value
= (src
->n_value
);
2162 BFD_ASSERT(dst
->symbol
.flags
!= 0);
2166 dst
->symbol
.udata
= 0;
2167 dst
->lineno
= (alent
*) NULL
;
2168 this_index
+= (src
->n_numaux
) + 1;
2170 number_of_symbols
++;
2171 } /* walk the native symtab */
2172 } /* bfdize the native symtab */
2174 obj_symbols(abfd
) = cached_area
;
2175 obj_raw_syments(abfd
) = native_symbols
;
2177 bfd_get_symcount(abfd
) = number_of_symbols
;
2178 obj_convert(abfd
) = table_ptr
;
2179 /* Slurp the line tables for each section too */
2184 coff_slurp_line_table(abfd
, p
);
2189 } /* coff_slurp_symbol_table() */
2192 coff_get_symtab_upper_bound(abfd
)
2195 if (!coff_slurp_symbol_table(abfd
))
2198 return (bfd_get_symcount(abfd
) + 1) * (sizeof(coff_symbol_type
*));
2203 coff_get_symtab(abfd
, alocation
)
2205 asymbol
**alocation
;
2207 unsigned int counter
= 0;
2208 coff_symbol_type
*symbase
;
2209 coff_symbol_type
**location
= (coff_symbol_type
**) (alocation
);
2210 if (!coff_slurp_symbol_table(abfd
))
2213 for (symbase
= obj_symbols(abfd
); counter
++ < bfd_get_symcount(abfd
);)
2214 *(location
++) = symbase
++;
2216 return bfd_get_symcount(abfd
);
2220 coff_get_reloc_upper_bound(abfd
, asect
)
2224 if (bfd_get_format(abfd
) != bfd_object
) {
2225 bfd_error
= invalid_operation
;
2228 return (asect
->reloc_count
+ 1) * sizeof(arelent
*);
2232 DEFUN(coff_slurp_reloc_table
,(abfd
, asect
, symbols
),
2237 RELOC
*native_relocs
;
2238 arelent
*reloc_cache
;
2239 if (asect
->relocation
)
2241 if (asect
->reloc_count
== 0)
2243 if (!coff_slurp_symbol_table(abfd
))
2246 (RELOC
*) buy_and_read(abfd
,
2250 asect
->reloc_count
));
2251 reloc_cache
= (arelent
*)
2252 bfd_alloc(abfd
, (size_t) (asect
->reloc_count
* sizeof(arelent
)));
2254 if (reloc_cache
== NULL
) {
2255 bfd_error
= no_memory
;
2260 for (cache_ptr
= reloc_cache
,
2261 src
= native_relocs
;
2262 cache_ptr
< reloc_cache
+ asect
->reloc_count
;
2265 struct internal_reloc dst
;
2267 swap_reloc_in(abfd
, src
, &dst
);
2268 dst
.r_symndx
+= obj_symbol_slew(abfd
);
2269 cache_ptr
->sym_ptr_ptr
= symbols
+ obj_convert(abfd
)[dst
.r_symndx
];
2271 ptr
= *(cache_ptr
->sym_ptr_ptr
);
2272 cache_ptr
->address
= dst
.r_vaddr
;
2274 The symbols definitions that we have read in have been
2275 relocated as if their sections started at 0. But the offsets
2276 refering to the symbols in the raw data have not been
2277 modified, so we have to have a negative addend to compensate.
2279 Note that symbols which used to be common must be left alone
2282 if (ptr
->the_bfd
== abfd
2283 && ptr
->section
!= (asection
*) NULL
2284 && ((ptr
->flags
& BSF_OLD_COMMON
)== 0))
2286 cache_ptr
->addend
= -(ptr
->section
->vma
+ ptr
->value
);
2289 cache_ptr
->addend
= 0;
2292 cache_ptr
->address
-= asect
->vma
;
2294 cache_ptr
->section
= (asection
*) NULL
;
2297 cache_ptr
->howto
= howto_table
+ dst
.r_type
;
2300 cache_ptr
->howto
= howto_table
+ dst
.r_type
- R_RELBYTE
;
2303 if (dst
.r_type
>= R_PCR16L
&& dst
.r_type
<= R_VRT32
) {
2304 cache_ptr
->howto
= howto_table
+ dst
.r_type
- R_PCR16L
;
2305 cache_ptr
->addend
+= dst
.r_offset
<< 16;
2316 asect
->relocation
= reloc_cache
;
2321 /* This is stupid. This function should be a boolean predicate */
2323 coff_canonicalize_reloc(abfd
, section
, relptr
, symbols
)
2329 arelent
*tblptr
= section
->relocation
;
2330 unsigned int count
= 0;
2331 if (!(tblptr
|| coff_slurp_reloc_table(abfd
, section
, symbols
)))
2333 tblptr
= section
->relocation
;
2337 for (; count
++ < section
->reloc_count
;)
2338 *relptr
++ = tblptr
++;
2342 return section
->reloc_count
;
2347 provided a bfd, a section and an offset into the section, calculate and
2348 return the name of the source file and the line nearest to the wanted
2353 DEFUN(coff_find_nearest_line
,(abfd
,
2361 asection
*section AND
2362 asymbol
**symbols AND
2364 CONST
char **filename_ptr AND
2365 CONST
char **functionname_ptr AND
2366 unsigned int *line_ptr
)
2368 static bfd
*cache_abfd
;
2369 static asection
*cache_section
;
2370 static bfd_vma cache_offset
;
2371 static unsigned int cache_i
;
2372 static alent
*cache_l
;
2375 struct icofdata
*cof
= obj_icof(abfd
);
2376 /* Run through the raw syments if available */
2377 struct internal_syment
*p
;
2379 unsigned int line_base
= 0;
2383 *functionname_ptr
= 0;
2386 /* Don't try and find line numbers in a non coff file */
2387 if (abfd
->xvec
->flavour
!= bfd_target_coff_flavour_enum
)
2390 if (cof
== (struct icofdata
*)NULL
)
2393 p
= cof
->raw_syments
;
2395 I don't know for sure what's right, but this isn't it. First off, an
2396 object file may not have any C_FILE's in it. After
2397 get_normalized_symtab(), it should have at least 1, the one I put
2398 there, but otherwise, all bets are off. Point #2, the first C_FILE
2399 isn't necessarily the right C_FILE because any given object may have
2400 many. I think you'll have to track sections as they coelesce in order
2401 to find the C_STAT symbol for this section. Then you'll have to work
2402 backwards to find the previous C_FILE, or choke if you get to a C_STAT
2403 for the same kind of section. That will mean that the original object
2404 file didn't have a C_FILE. xoxorich.
2407 #ifdef WEREBEINGPEDANTIC
2411 for (i
= 0; i
< cof
->raw_syment_count
; i
++) {
2412 if (bfd_h_get_x(abfd
, &p
->n_sclass
) == C_FILE
) {
2413 /* File name is embeded in auxent */
2415 This isn't right. The fname should probably be normalized
2416 during get_normalized_symtab(). In any case, what was here
2417 wasn't right because a SYMENT.n_name isn't an
2418 AUXENT.x_file.x_fname. xoxorich.
2421 *filename_ptr
= ((AUXENT
*) (p
+ 1))->x_file
.x_fname
;
2424 p
+= 1 + bfd_h_get_x(abfd
, & p
->n_numaux
);
2426 /* Now wander though the raw linenumbers of the section */
2428 If this is the same bfd as we were previously called with and this is
2429 the same section, and the offset we want is further down then we can
2430 prime the lookup loop
2432 if (abfd
== cache_abfd
&&
2433 section
== cache_section
&&
2434 offset
>= cache_offset
) {
2440 l
= section
->lineno
;
2443 for (; i
< section
->lineno_count
; i
++) {
2444 if (l
->line_number
== 0) {
2445 /* Get the symbol this line number points at */
2446 coff_symbol_type
*coff
= (coff_symbol_type
*) (l
->u
.sym
);
2447 *functionname_ptr
= coff
->symbol
.name
;
2449 struct internal_syment
*s
= coff
->native
;
2450 s
= s
+ 1 + s
->n_numaux
;
2452 S should now point to the .bf of the function
2456 The linenumber is stored in the auxent
2458 union internal_auxent
*a
= (union internal_auxent
*) (s
+ 1);
2459 line_base
= bfd_h_get_x(abfd
, &a
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
2464 if (l
->u
.offset
> offset
)
2466 *line_ptr
= l
->line_number
+ line_base
+ 1;
2472 cache_section
= section
;
2473 cache_offset
= offset
;
2481 coff_sym_filepos(abfd
)
2484 return obj_sym_filepos(abfd
);
2490 DEFUN(coff_sizeof_headers
,(abfd
, reloc
),
2496 if (reloc
== false) {
2497 size
= sizeof(struct filehdr
) + sizeof(AOUTHDR
);
2500 size
= sizeof(struct filehdr
);
2503 size
+= abfd
->section_count
* SCNHSZ
;
2508 #define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
2509 #define coff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
2510 #define coff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
2511 #define coff_slurp_armap bfd_slurp_coff_armap
2512 #define coff_slurp_extended_name_table _bfd_slurp_extended_name_table
2513 #define coff_truncate_arname bfd_dont_truncate_arname
2514 #define coff_openr_next_archived_file bfd_generic_openr_next_archived_file
2515 #define coff_generic_stat_arch_elt bfd_generic_stat_arch_elt
2516 #define coff_get_section_contents bfd_generic_get_section_contents
2517 #define coff_close_and_cleanup bfd_generic_close_and_cleanup