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 #define PUTWORD bfd_h_put_32
44 #define PUTHALF bfd_h_put_16
46 #define GDB_EXPORT static
48 #define GDB_EXPORT /* nothing */
51 PROTO(static void,force_indices_file_symbol_relative
,(bfd
*abfd
,
52 struct internal_syment
*symtab
));
56 extern asection abs_section
;
59 DEFUN(get_index
,(symbol
),
62 return (int) symbol
->value
;
66 DEFUN(set_index
,(symbol
, idx
),
77 /* All the swapping routines:
82 DEFUN(bfd_swap_reloc_in
,(abfd
, reloc_src
, reloc_dst
),
85 struct internal_reloc
*reloc_dst
)
87 reloc_dst
->r_vaddr
= bfd_h_get_32(abfd
, reloc_src
->r_vaddr
);
88 reloc_dst
->r_symndx
= bfd_h_get_32(abfd
, reloc_src
->r_symndx
);
89 reloc_dst
->r_type
= bfd_h_get_16(abfd
, reloc_src
->r_type
);
91 reloc_dst
->r_offset
= bfd_h_get_16(abfd
, reloc_src
->r_offset
);
97 DEFUN(bfd_swap_reloc_out
,(abfd
, reloc_src
, reloc_dst
),
99 struct internal_reloc
*reloc_src AND
100 struct external_reloc
*reloc_dst
)
102 bfd_h_put_32(abfd
, reloc_src
->r_vaddr
, reloc_dst
->r_vaddr
);
103 bfd_h_put_32(abfd
, reloc_src
->r_symndx
, reloc_dst
->r_symndx
);
104 bfd_h_put_16(abfd
, reloc_src
->r_type
, reloc_dst
->r_type
);
106 bfd_h_put_16(abfd
, reloc_src
->r_offset
, reloc_dst
->r_offset
);
112 DEFUN(bfd_swap_filehdr_in
,(abfd
, filehdr_src
, filehdr_dst
),
114 FILHDR
*filehdr_src AND
115 struct internal_filehdr
*filehdr_dst
)
117 filehdr_dst
->f_magic
= bfd_h_get_16(abfd
, filehdr_src
->f_magic
);
118 filehdr_dst
->f_nscns
= bfd_h_get_16(abfd
,filehdr_src
-> f_nscns
);
119 filehdr_dst
->f_timdat
= bfd_h_get_32(abfd
,filehdr_src
-> f_timdat
);
120 filehdr_dst
->f_symptr
= bfd_h_get_32(abfd
,filehdr_src
-> f_symptr
);
121 filehdr_dst
->f_nsyms
= bfd_h_get_32(abfd
,filehdr_src
-> f_nsyms
);
122 filehdr_dst
->f_opthdr
= bfd_h_get_16(abfd
,filehdr_src
-> f_opthdr
);
123 filehdr_dst
->f_flags
= bfd_h_get_16(abfd
,filehdr_src
-> f_flags
);
127 DEFUN(bfd_swap_filehdr_out
,(abfd
, filehdr_in
, filehdr_out
),
129 struct internal_filehdr
*filehdr_in AND
132 bfd_h_put_16(abfd
, filehdr_in
->f_magic
, filehdr_out
->f_magic
);
133 bfd_h_put_16(abfd
, filehdr_in
->f_nscns
, filehdr_out
->f_nscns
);
134 bfd_h_put_32(abfd
, filehdr_in
->f_timdat
, filehdr_out
->f_timdat
);
135 bfd_h_put_32(abfd
, filehdr_in
->f_symptr
, filehdr_out
->f_symptr
);
136 bfd_h_put_32(abfd
, filehdr_in
->f_nsyms
, filehdr_out
->f_nsyms
);
137 bfd_h_put_16(abfd
, filehdr_in
->f_opthdr
, filehdr_out
->f_opthdr
);
138 bfd_h_put_16(abfd
, filehdr_in
->f_flags
, filehdr_out
->f_flags
);
144 DEFUN(coff_swap_sym_in
,(abfd
, ext
, in
),
147 struct internal_syment
*in
)
149 if( ext
->e
.e_name
[0] == 0) {
150 in
->_n
._n_n
._n_zeroes
= 0;
151 in
->_n
._n_n
._n_offset
= bfd_h_get_32(abfd
, ext
->e
.e
.e_offset
);
154 memcpy(in
->_n
._n_name
, ext
->e
.e_name
, SYMNMLEN
);
156 in
->n_value
= bfd_h_get_32(abfd
, ext
->e_value
);
157 in
->n_scnum
= bfd_h_get_16(abfd
, ext
->e_scnum
);
158 if (sizeof(ext
->e_type
) == 2){
159 in
->n_type
= bfd_h_get_16(abfd
, ext
->e_type
);
162 in
->n_type
= bfd_h_get_32(abfd
, ext
->e_type
);
164 in
->n_sclass
= bfd_h_get_8(abfd
, ext
->e_sclass
);
165 in
->n_numaux
= bfd_h_get_8(abfd
, ext
->e_numaux
);
169 DEFUN(coff_swap_sym_out
,(abfd
,in
, ext
),
171 struct internal_syment
*in AND
174 if(in
->_n
._n_name
[0] == 0) {
175 bfd_h_put_32(abfd
, 0, ext
->e
.e
.e_zeroes
);
176 bfd_h_put_32(abfd
, in
->_n
._n_n
._n_offset
, ext
->e
.e
.e_offset
);
179 memcpy(ext
->e
.e_name
, in
->_n
._n_name
, SYMNMLEN
);
181 bfd_h_put_32(abfd
, in
->n_value
, ext
->e_value
);
182 bfd_h_put_16(abfd
, in
->n_scnum
, ext
->e_scnum
);
183 if (sizeof(ext
->e_type
) == 2)
185 bfd_h_put_16(abfd
, in
->n_type
, ext
->e_type
);
189 bfd_h_put_32(abfd
, in
->n_type
, ext
->e_type
);
191 bfd_h_put_8(abfd
, in
->n_sclass
, ext
->e_sclass
);
192 bfd_h_put_8(abfd
, in
->n_numaux
, ext
->e_numaux
);
196 DEFUN(coff_swap_aux_in
,(abfd
, ext
, type
, class, in
),
201 union internal_auxent
*in
)
205 if (ext
->x_file
.x_fname
[0] == 0) {
206 in
->x_file
.x_n
.x_zeroes
= 0;
207 in
->x_file
.x_n
.x_offset
= bfd_h_get_32(abfd
, ext
->x_file
.x_n
.x_offset
);
209 memcpy (in
->x_file
.x_fname
, ext
->x_file
.x_fname
,
210 sizeof (in
->x_file
.x_fname
));
219 if (type
== T_NULL
) {
220 in
->x_scn
.x_scnlen
= bfd_h_get_32(abfd
, ext
->x_scn
.x_scnlen
);
221 in
->x_scn
.x_nreloc
= bfd_h_get_16(abfd
, ext
->x_scn
.x_nreloc
);
222 in
->x_scn
.x_nlinno
= bfd_h_get_16(abfd
, ext
->x_scn
.x_nlinno
);
226 in
->x_sym
.x_tagndx
= bfd_h_get_32(abfd
, ext
->x_sym
.x_tagndx
);
227 in
->x_sym
.x_tvndx
= bfd_h_get_16(abfd
, ext
->x_sym
.x_tvndx
);
229 if (ISARY(type
) || class == C_BLOCK
) {
230 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0] = bfd_h_get_16(abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
231 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1] = bfd_h_get_16(abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
232 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2] = bfd_h_get_16(abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
233 in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3] = bfd_h_get_16(abfd
, ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
236 in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= bfd_h_get_32(abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
237 in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= bfd_h_get_32(abfd
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
240 in
->x_sym
.x_misc
.x_fsize
= bfd_h_get_32(abfd
, ext
->x_sym
.x_misc
.x_fsize
);
243 in
->x_sym
.x_misc
.x_lnsz
.x_lnno
= bfd_h_get_16(abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
244 in
->x_sym
.x_misc
.x_lnsz
.x_size
= bfd_h_get_16(abfd
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
250 DEFUN(coff_swap_aux_out
,(abfd
, in
, type
, class, ext
),
252 union internal_auxent
*in AND
259 if (in
->x_file
.x_fname
[0] == 0) {
260 PUTWORD(abfd
, 0, ext
->x_file
.x_n
.x_zeroes
);
261 PUTWORD(abfd
, in
->x_file
.x_n
.x_offset
, ext
->x_file
.x_n
.x_offset
);
270 if (type
== T_NULL
) {
271 PUTWORD(abfd
, in
->x_scn
.x_scnlen
, ext
->x_scn
.x_scnlen
);
272 PUTWORD(abfd
, in
->x_scn
.x_nreloc
, ext
->x_scn
.x_nreloc
);
273 PUTWORD(abfd
, in
->x_scn
.x_nlinno
, ext
->x_scn
.x_nlinno
);
277 PUTWORD(abfd
, in
->x_sym
.x_tagndx
, ext
->x_sym
.x_tagndx
);
278 PUTWORD(abfd
, in
->x_sym
.x_tvndx
, ext
->x_sym
.x_tvndx
);
280 if (ISARY(type
) || class == C_BLOCK
) {
281 bfd_h_put_16(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0],ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[0]);
282 bfd_h_put_16(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1],ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[1]);
283 bfd_h_put_16(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2],ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[2]);
284 bfd_h_put_16(abfd
, in
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3],ext
->x_sym
.x_fcnary
.x_ary
.x_dimen
[3]);
287 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, ext
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
288 PUTWORD(abfd
, in
->x_sym
.x_fcnary
.x_fcn
.x_endndx
, ext
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
291 PUTWORD(abfd
, in
->x_sym
.x_misc
.x_fsize
, ext
->x_sym
.x_misc
.x_fsize
);
294 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_lnno
, ext
->x_sym
.x_misc
.x_lnsz
.x_lnno
);
295 bfd_h_put_16(abfd
, in
->x_sym
.x_misc
.x_lnsz
.x_size
, ext
->x_sym
.x_misc
.x_lnsz
.x_size
);
301 DEFUN(coff_swap_lineno_in
,(abfd
, ext
, in
),
304 struct internal_lineno
*in
)
306 in
->l_addr
.l_symndx
= bfd_h_get_32(abfd
, ext
->l_addr
.l_symndx
);
307 in
->l_lnno
= bfd_h_get_16(abfd
, ext
->l_lnno
);
311 DEFUN(coff_swap_lineno_out
,(abfd
, in
, ext
),
313 struct internal_lineno
*in AND
314 struct external_lineno
*ext
)
316 PUTWORD(abfd
, in
->l_addr
.l_symndx
, ext
->l_addr
.l_symndx
);
317 PUTHALF(abfd
, in
->l_lnno
, ext
->l_lnno
);
324 DEFUN(bfd_swap_aouthdr_in
,(abfd
, aouthdr_ext
, aouthdr_int
),
326 AOUTHDR
*aouthdr_ext AND
327 struct internal_aouthdr
*aouthdr_int
)
329 aouthdr_int
->magic
= bfd_h_get_16(abfd
, aouthdr_ext
->magic
);
330 aouthdr_int
->vstamp
= bfd_h_get_16(abfd
, aouthdr_ext
->vstamp
);
331 aouthdr_int
->tsize
= bfd_h_get_32(abfd
, aouthdr_ext
->tsize
);
332 aouthdr_int
->dsize
= bfd_h_get_32(abfd
, aouthdr_ext
->dsize
);
333 aouthdr_int
->bsize
= bfd_h_get_32(abfd
, aouthdr_ext
->bsize
);
334 aouthdr_int
->entry
= bfd_h_get_32(abfd
, aouthdr_ext
->entry
);
335 aouthdr_int
->text_start
= bfd_h_get_32(abfd
, aouthdr_ext
->text_start
);
336 aouthdr_int
->data_start
= bfd_h_get_32(abfd
, aouthdr_ext
->data_start
);
338 aouthdr_int
->tagentries
= bfd_h_get_32(abfd
, aouthdr_ext
->tagentries
);
343 DEFUN(bfd_swap_aouthdr_out
,(abfd
, aouthdr_in
, aouthdr_out
),
345 struct internal_aouthdr
*aouthdr_in AND
346 AOUTHDR
*aouthdr_out
)
348 bfd_h_put_16(abfd
, aouthdr_in
->magic
, aouthdr_out
->magic
);
349 bfd_h_put_16(abfd
, aouthdr_in
->vstamp
, aouthdr_out
->vstamp
);
350 bfd_h_put_32(abfd
, aouthdr_in
->tsize
, aouthdr_out
->tsize
);
351 bfd_h_put_32(abfd
, aouthdr_in
->dsize
, aouthdr_out
->dsize
);
352 bfd_h_put_32(abfd
, aouthdr_in
->bsize
, aouthdr_out
->bsize
);
353 bfd_h_put_32(abfd
, aouthdr_in
->entry
, aouthdr_out
->entry
);
354 bfd_h_put_32(abfd
, aouthdr_in
->text_start
, aouthdr_out
->text_start
);
355 bfd_h_put_32(abfd
, aouthdr_in
->data_start
, aouthdr_out
->data_start
);
357 bfd_h_put_32(abfd
, aouthdr_in
->tagentries
, aouthdr_out
->tagentries
);
362 DEFUN(coff_swap_scnhdr_in
,(abfd
, scnhdr_ext
, scnhdr_int
),
364 SCNHDR
*scnhdr_ext AND
365 struct internal_scnhdr
*scnhdr_int
)
367 memcpy(scnhdr_int
->s_name
, scnhdr_ext
->s_name
, sizeof(scnhdr_int
->s_name
));
368 scnhdr_int
->s_vaddr
= bfd_h_get_32(abfd
, scnhdr_ext
->s_vaddr
);
369 scnhdr_int
->s_paddr
= bfd_h_get_32(abfd
, scnhdr_ext
->s_paddr
);
370 scnhdr_int
->s_size
= bfd_h_get_32(abfd
, scnhdr_ext
->s_size
);
371 scnhdr_int
->s_scnptr
= bfd_h_get_32(abfd
, scnhdr_ext
->s_scnptr
);
372 scnhdr_int
->s_relptr
= bfd_h_get_32(abfd
, scnhdr_ext
->s_relptr
);
373 scnhdr_int
->s_lnnoptr
= bfd_h_get_32(abfd
, scnhdr_ext
->s_lnnoptr
);
374 scnhdr_int
->s_nreloc
= bfd_h_get_16(abfd
, scnhdr_ext
->s_nreloc
);
375 scnhdr_int
->s_nlnno
= bfd_h_get_16(abfd
, scnhdr_ext
->s_nlnno
);
376 scnhdr_int
->s_flags
= bfd_h_get_32(abfd
, scnhdr_ext
->s_flags
);
378 scnhdr_int
->s_align
= bfd_h_get_32(abfd
, scnhdr_ext
->s_align
);
383 DEFUN(swap_scnhdr_out
,(abfd
, scnhdr_int
, scnhdr_ext
),
385 struct internal_scnhdr
*scnhdr_int AND
388 memcpy(scnhdr_ext
->s_name
, scnhdr_int
->s_name
, sizeof(scnhdr_int
->s_name
));
389 PUTWORD(abfd
, scnhdr_int
->s_vaddr
, scnhdr_ext
->s_vaddr
);
390 PUTWORD(abfd
, scnhdr_int
->s_paddr
, scnhdr_ext
->s_paddr
);
391 PUTWORD(abfd
, scnhdr_int
->s_size
, scnhdr_ext
->s_size
);
392 PUTWORD(abfd
, scnhdr_int
->s_scnptr
, scnhdr_ext
->s_scnptr
);
393 PUTWORD(abfd
, scnhdr_int
->s_relptr
, scnhdr_ext
->s_relptr
);
394 PUTWORD(abfd
, scnhdr_int
->s_lnnoptr
, scnhdr_ext
->s_lnnoptr
);
395 PUTWORD(abfd
, scnhdr_int
->s_nreloc
, scnhdr_ext
->s_nreloc
);
396 PUTHALF(abfd
, scnhdr_int
->s_nlnno
, scnhdr_ext
->s_nlnno
);
397 PUTHALF(abfd
, scnhdr_int
->s_flags
, scnhdr_ext
->s_flags
);
399 PUTWORD(abfd
, scnhdr_int
->s_align
, scnhdr_ext
->s_align
);
404 initialize a section structure with information peculiar to this
405 particular implementation of coff
409 DEFUN(coff_new_section_hook
,(abfd_ignore
, section_ignore
),
411 asection
*section_ignore
)
414 /* FIXME, shouldn't this ifdef be on something that says we are
415 actually COMPILING FOR an 88K coff file, rather than simply
416 knowing its magic number? */
417 /* Align to at least 16 bytes */
418 section_ignore
->alignment_power
= 4;
421 section_ignore
->alignment_power
= 3;
424 section_ignore
->alignment_power
= 2;
429 /* Take a section header read from a coff file (in HOST byte order),
430 and make a BFD "section" out of it. */
432 DEFUN(make_a_section_from_file
,(abfd
, hdr
),
434 struct internal_scnhdr
*hdr
)
436 asection
*return_section
;
439 /* Assorted wastage to null-terminate the name, thanks AT&T! */
440 char *name
= bfd_alloc(abfd
, sizeof (hdr
->s_name
)+1);
442 bfd_error
= no_memory
;
445 strncpy(name
, (char *) &hdr
->s_name
[0], sizeof (hdr
->s_name
));
446 name
[sizeof (hdr
->s_name
)] = 0;
448 return_section
= bfd_make_section(abfd
, name
);
451 /* s_paddr is presumed to be = to s_vaddr */
452 #define assign(to, from) return_section->to = hdr->from
453 assign(vma
, s_vaddr
);
454 /* assign (vma, s_vaddr); */
455 assign(size
, s_size
);
456 assign(filepos
, s_scnptr
);
457 assign(rel_filepos
, s_relptr
);
458 assign(reloc_count
, s_nreloc
);
461 /* FIXME, use a temp var rather than alignment_power */
462 assign(alignment_power
, s_align
);
465 for (i
= 0; i
< 32; i
++) {
466 if ((1 << i
) >= (int) (return_section
->alignment_power
)) {
467 return_section
->alignment_power
= i
;
474 assign(line_filepos
, s_lnnoptr
);
476 return_section->linesize = hdr->s_nlnno * sizeof (struct lineno);
480 return_section
->lineno_count
= hdr
->s_nlnno
;
481 return_section
->userdata
= NULL
;
482 return_section
->next
= (asection
*) NULL
;
483 return_section
->flags
= 0;
484 if ((hdr
->s_flags
& STYP_TEXT
) || (hdr
->s_flags
& STYP_DATA
))
485 return_section
->flags
= (SEC_LOAD
| SEC_ALLOC
);
486 else if (hdr
->s_flags
& STYP_BSS
)
487 return_section
->flags
= SEC_ALLOC
;
489 if (hdr
->s_nreloc
!= 0)
490 return_section
->flags
|= SEC_RELOC
;
491 if (hdr
->s_scnptr
!= 0)
492 return_section
->flags
|= SEC_HAS_CONTENTS
;
496 DEFUN(coff_mkobject
,(abfd
),
499 set_tdata (abfd
, bfd_zalloc (abfd
,sizeof(coff_data_type
)));
500 if (coff_data(abfd
) == 0) {
501 bfd_error
= no_memory
;
504 coff_data(abfd
)->relocbase
= 0;
510 DEFUN(coff_real_object_p
,(abfd
, nscns
, internal_f
, internal_a
),
513 struct internal_filehdr
*internal_f AND
514 struct internal_aouthdr
*internal_a
)
516 coff_data_type
*coff
;
518 size_t readsize
; /* length of file_info */
519 SCNHDR
*external_sections
;
521 /* Build a play area */
522 if (coff_mkobject(abfd
) != true)
524 coff
= coff_data(abfd
);
527 external_sections
= (SCNHDR
*)bfd_alloc(abfd
, readsize
= (nscns
* SCNHSZ
));
528 if (bfd_read((PTR
)external_sections
, 1, readsize
, abfd
) != readsize
) {
534 /* Now copy data as required; construct all asections etc */
535 coff
->symbol_index_slew
= 0;
537 coff
->raw_syment_count
= 0;
538 coff
->raw_linenos
= 0;
539 coff
->raw_syments
= 0;
540 coff
->sym_filepos
=0;
541 coff
->flags
= internal_f
->f_flags
;
544 for (i
= 0; i
< nscns
; i
++) {
545 struct internal_scnhdr tmp
;
546 coff_swap_scnhdr_in(abfd
, external_sections
+ i
, &tmp
);
547 make_a_section_from_file(abfd
,&tmp
);
550 /* Determine the machine architecture and type. */
551 abfd
->obj_machine
= 0;
552 switch (internal_f
->f_magic
) {
555 abfd
->obj_arch
= bfd_arch_i386
;
556 abfd
->obj_machine
= 0;
563 abfd
->obj_arch
= bfd_arch_mips
;
564 abfd
->obj_machine
= 0;
571 abfd
->obj_arch
= bfd_arch_m68k
;
572 abfd
->obj_machine
= 68020;
579 abfd
->obj_arch
= bfd_arch_m88k
;
580 abfd
->obj_machine
= 88100;
587 abfd
->obj_arch
= bfd_arch_i960
;
588 switch (F_I960TYPE
& internal_f
->f_flags
)
592 abfd
->obj_machine
= bfd_mach_i960_core
;
595 abfd
->obj_machine
= bfd_mach_i960_kb_sb
;
598 abfd
->obj_machine
= bfd_mach_i960_mc
;
601 abfd
->obj_machine
= bfd_mach_i960_xa
;
604 abfd
->obj_machine
= bfd_mach_i960_ca
;
607 abfd
->obj_machine
= bfd_mach_i960_ka_sa
;
615 default: /* Unreadable input file type */
616 abfd
->obj_arch
= bfd_arch_obscure
;
620 if (!(internal_f
->f_flags
& F_RELFLG
))
621 abfd
->flags
|= HAS_RELOC
;
622 if ((internal_f
->f_flags
& F_EXEC
))
623 abfd
->flags
|= EXEC_P
;
624 if (!(internal_f
->f_flags
& F_LNNO
))
625 abfd
->flags
|= HAS_LINENO
;
626 if (!(internal_f
->f_flags
& F_LSYMS
))
627 abfd
->flags
|= HAS_LOCALS
;
630 bfd_get_symcount(abfd
) = internal_f
->f_nsyms
;
631 if (internal_f
->f_nsyms
)
632 abfd
->flags
|= HAS_SYMS
;
634 coff
->sym_filepos
= internal_f
->f_symptr
;
638 coff
->symbols
= (coff_symbol_type
*) NULL
;
639 bfd_get_start_address(abfd
) = internal_f
->f_opthdr
? internal_a
->entry
: 0;
643 bfd_release(abfd
, coff
);
644 return (bfd_target
*)NULL
;
648 DEFUN(coff_object_p
,(abfd
),
654 struct internal_filehdr internal_f
;
655 struct internal_aouthdr internal_a
;
657 bfd_error
= system_call_error
;
659 /* figure out how much to read */
660 if (bfd_read((PTR
) &filehdr
, 1, FILHSZ
, abfd
) != FILHSZ
)
663 bfd_swap_filehdr_in(abfd
, &filehdr
, &internal_f
);
665 if (BADMAG(internal_f
)) {
666 bfd_error
= wrong_format
;
669 nscns
=internal_f
.f_nscns
;
671 if (internal_f
.f_opthdr
) {
672 if (bfd_read((PTR
) &opthdr
, 1,AOUTSZ
, abfd
) != AOUTSZ
) {
675 bfd_swap_aouthdr_in(abfd
, &opthdr
, &internal_a
);
678 /* Seek past the opt hdr stuff */
679 bfd_seek(abfd
, internal_f
.f_opthdr
+ FILHSZ
, SEEK_SET
);
681 /* if the optional header is NULL or not the correct size then
682 quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)
683 and Intel 960 readwrite headers (I960WRMAGIC) is that the
684 optional header is of a different size.
686 But the mips keeps extra stuff in it's opthdr, so dont check
691 if (internal_f
.f_opthdr
!= 0 && AOUTSZ
!= internal_f
.f_opthdr
)
692 return (bfd_target
*)NULL
;
695 return coff_real_object_p(abfd
, nscns
, &internal_f
, &internal_a
);
702 Takes a bfd and a symbol, returns a pointer to the coff specific area
703 of the symbol if there is one.
705 static coff_symbol_type
*
706 DEFUN(coff_symbol_from
,(abfd
, symbol
),
710 if (symbol
->the_bfd
->xvec
->flavour
!= bfd_target_coff_flavour_enum
)
711 return (coff_symbol_type
*)NULL
;
713 if (symbol
->the_bfd
->tdata
== (PTR
)NULL
)
714 return (coff_symbol_type
*)NULL
;
716 return (coff_symbol_type
*) symbol
;
726 DEFUN(coff_count_linenumbers
,(abfd
),
729 unsigned int limit
= bfd_get_symcount(abfd
);
733 asection
*s
= abfd
->sections
->output_section
;
735 BFD_ASSERT(s
->lineno_count
== 0);
741 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
742 asymbol
*q_maybe
= *p
;
743 if (q_maybe
->the_bfd
->xvec
->flavour
== bfd_target_coff_flavour_enum
) {
744 coff_symbol_type
*q
= coffsymbol(q_maybe
);
747 This symbol has a linenumber, increment the owning
748 section's linenumber count
750 alent
*l
= q
->lineno
;
751 q
->symbol
.section
->output_section
->lineno_count
++;
753 while (l
->line_number
) {
754 q
->symbol
.section
->output_section
->lineno_count
++;
763 This function returns true if the supplied SYMENT has an AUXENT with
764 a tagndx field which should be relocated.
766 The coff book says that all auxents have this and should be moved,
767 but all the actual implementations I've looked at do this ..
772 DEFUN(uses_x_sym_x_tagndx_p
,(abfd
, native
),
774 struct internal_syment
*native
)
776 if (BTYPE(native
->n_type
) == T_STRUCT
) return true;
777 if (BTYPE(native
->n_type
) == T_UNION
) return true;
778 if (BTYPE(native
->n_type
) == T_ENUM
) return true;
784 This procedure runs through the native entries in a coff symbol table
785 and links up all the elements which should point to one another, in
786 particular these are:
788 strtag, entag and untags have an auxent endindex which points to the
789 first syment after the .eos. This is simple to do, we just keep a
790 pointer to the symbol with the most recent pending strtag and patch it
791 when we see the eos. This works since coff structs are never nested.
793 ISFCN type entries have an endindex which points to the next static or
794 extern in the table, thereby skipping the function contents.
795 The coff book says that an ISFCN's tagindex
796 points to the first .bf for the function, so far I havn't seen it
797 used. We do this using the same mechanism as strtags.
799 Each file entry has a value which points to the next file entry,
800 the last file entry points to the first extern symbol in the table
801 which is not an ISFCN.
803 Each .bb entry points to the matching .eb entry, but these are nested
804 so we keep a stack of them.
806 The tagndx of .eos items points to the strtag attached to them, this
807 is simply the last_tagndx again.
809 The tagndx of items with type strtag point to the defining struct.
810 This bit is complicated; We know that a struct ref and def must be
811 within the same file, so all the natives will be in the same vector.
812 This means that we can subtracts two pointers and get the index
813 differences between to items, used to work out the true index of the
816 We store in the name field of each syment the actual native index
817 applied so we can dig it out through a pointer. */
820 DEFUN(coff_mangle_symbols
,(bfd_ptr
),
823 unsigned int symbol_count
= bfd_get_symcount(bfd_ptr
);
824 asymbol
**symbol_ptr_ptr
= bfd_ptr
->outsymbols
;
825 struct internal_syment
*last_tagndx
= (struct internal_syment
*)NULL
;
826 struct internal_syment
*last_file
= (struct internal_syment
*)NULL
;
827 struct internal_syment
*last_fcn
= (struct internal_syment
*)NULL
;
828 struct internal_syment
*block_stack
[50];
829 struct internal_syment
**last_block
= &block_stack
[0];
830 boolean first_time
= true;
831 unsigned int symbol_index
;
832 unsigned int native_index
= 0;
834 for (symbol_index
= 0; symbol_index
< symbol_count
; symbol_index
++) {
835 coff_symbol_type
*coff_symbol_ptr
=
836 coff_symbol_from(bfd_ptr
, symbol_ptr_ptr
[symbol_index
]);
837 if (coff_symbol_ptr
== (coff_symbol_type
*)NULL
) {
839 This symbol has no coff information in it, it will take up
840 only one slot in the output symbol table
845 struct internal_syment
*syment
= coff_symbol_ptr
->native
;
846 if (syment
== (struct internal_syment
*)NULL
) {
850 /* Normalize the symbol flags */
851 if (coff_symbol_ptr
->symbol
.flags
& BSF_FORT_COMM
) {
852 /* a common symbol is undefined with a value */
853 syment
->n_scnum
= N_UNDEF
;
854 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
856 else if (coff_symbol_ptr
->symbol
.flags
& BSF_DEBUGGING
) {
857 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
859 else if (coff_symbol_ptr
->symbol
.flags
& BSF_UNDEFINED
) {
860 syment
->n_scnum
= N_UNDEF
;
863 else if (coff_symbol_ptr
->symbol
.flags
& BSF_ABSOLUTE
) {
864 syment
->n_scnum
= N_ABS
;
865 syment
->n_value
= coff_symbol_ptr
->symbol
.value
;
869 coff_symbol_ptr
->symbol
.section
->output_section
->index
+1;
872 coff_symbol_ptr
->symbol
.value
+
873 coff_symbol_ptr
->symbol
.section
->output_offset
+
874 coff_symbol_ptr
->symbol
.section
->output_section
->vma
;
878 /* If this symbol ties up something then do it */
880 if (syment
->n_sclass
== C_FILE
&& last_file
!= (struct internal_syment
*)NULL
)
882 last_file
->n_value
= native_index
;
884 else if ((syment
->n_sclass
== C_EXT
885 || syment
->n_sclass
== C_STAT
887 || syment
->n_sclass
== C_LEAFEXT
888 || syment
->n_sclass
== C_LEAFSTAT
891 && last_fcn
!= (struct internal_syment
*)NULL
)
893 union internal_auxent
*auxent
= (union internal_auxent
*)(last_fcn
+1);
894 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= native_index
;
895 last_fcn
= (struct internal_syment
*)NULL
;
898 else if (syment
->n_sclass
== C_EOS
&& last_tagndx
!= (struct internal_syment
*)NULL
)
900 union internal_auxent
*auxent
= (union internal_auxent
*)(last_tagndx
+1);
901 /* Remember that we keep the native index in the offset
902 so patch the beginning of the struct to point to this
904 auxent
->x_sym
.x_tagndx
= last_tagndx
->_n
._n_n
._n_offset
;
905 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= syment
->n_numaux
+ 1 + native_index
;
906 /* Now point the eos to the structure */
907 auxent
= (union internal_auxent
*)(syment
+1);
908 auxent
->x_sym
.x_tagndx
= last_tagndx
->_n
._n_n
._n_offset
;
910 else if (syment
->n_sclass
== C_BLOCK
911 && coff_symbol_ptr
->symbol
.name
[1] == 'e')
913 union internal_auxent
*auxent
= (union internal_auxent
*)((*(--last_block
))+1);
914 auxent
->x_sym
.x_fcnary
.x_fcn
.x_endndx
= native_index
+ syment
->n_numaux
+ 1;
916 if (syment
->n_sclass
== C_EXT
917 && !ISFCN(syment
->n_type
)
918 && first_time
== true
919 && last_file
!= (struct internal_syment
*)NULL
) {
920 /* This is the first external symbol seen which isn't a
921 function place it in the last .file entry */
922 last_file
->n_value
= native_index
;
926 if (syment
->n_sclass
== C_LEAFPROC
&&
927 syment
->n_numaux
== 2) {
928 union internal_auxent
*auxent
= (union internal_auxent
*)(syment
+2);
929 /* This is the definition of a leaf proc, we'll relocate the
931 auxent
->x_bal
.x_balntry
=
932 coff_symbol_ptr
->symbol
.section
->output_offset
+
933 coff_symbol_ptr
->symbol
.section
->output_section
->vma
+
934 auxent
->x_bal
.x_balntry
;
937 /* If this symbol needs to be tied up then remember some facts */
938 if (syment
->n_sclass
== C_FILE
)
942 if (syment
->n_numaux
!= 0) {
944 If this symbol would like to point to something in the
945 future then remember where it is
947 if (uses_x_sym_x_tagndx_p(bfd_ptr
, syment
)) {
949 If this is a ref to a structure then we'll tie it up
950 now - there are never any forward refs for one
952 if (syment
->n_sclass
== C_STRTAG
||
953 syment
->n_sclass
== C_ENTAG
||
954 syment
->n_sclass
== C_UNTAG
) {
955 last_tagndx
= syment
;
959 This is a ref to a structure - the structure must
960 have been defined within the same file, and previous
961 to this point, so we can deduce the new tagndx
964 union internal_auxent
*auxent
= (union internal_auxent
*)(syment
+1);
965 bfd
*bfd_ptr
= coff_symbol_ptr
->symbol
.the_bfd
;
966 struct internal_syment
*base
= obj_raw_syments(bfd_ptr
);
967 auxent
->x_sym
.x_tagndx
= base
[auxent
->x_sym
.x_tagndx
]._n
._n_n
._n_offset
;
972 if (ISFCN(syment
->n_type
)) {
975 if (syment
->n_sclass
== C_BLOCK
976 && coff_symbol_ptr
->symbol
.name
[1] == 'b')
978 *last_block
++ = syment
;
981 syment
->_n
._n_n
._n_offset
= native_index
;
982 native_index
= native_index
+ 1 + syment
->n_numaux
;
990 DEFUN(coff_write_symbols
,(abfd
),
994 unsigned int limit
= bfd_get_symcount(abfd
);
995 unsigned int written
= 0;
996 struct internal_syment dummy
;
998 unsigned int string_size
= 0;
1001 /* Seek to the right place */
1002 bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
);
1004 /* Output all the symbols we have */
1007 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
1008 asymbol
*symbol
= *p
;
1009 coff_symbol_type
*c_symbol
= coff_symbol_from(abfd
, symbol
);
1012 struct internal_syment
*native
;
1013 if (c_symbol
== (coff_symbol_type
*) NULL
||
1014 c_symbol
->native
== (struct internal_syment
*) NULL
) {
1016 This symbol has been created by the loader, or come from a non
1017 coff format. It has no native element to inherit, make our
1022 native
->n_type
= T_NULL
;
1024 native
->n_flags
= 0;
1026 if (symbol
->flags
& BSF_ABSOLUTE
) {
1027 native
->n_scnum
= N_ABS
;
1028 native
->n_value
= symbol
->value
;
1030 else if (symbol
->flags
& (BSF_UNDEFINED
| BSF_FORT_COMM
)) {
1031 native
->n_scnum
= N_UNDEF
;
1032 native
->n_value
= symbol
->value
;
1034 else if (symbol
->flags
& BSF_DEBUGGING
) {
1036 remove name so it doesn't take up any space
1042 native
->n_scnum
= symbol
->section
->output_section
->index
+
1044 native
->n_value
= symbol
->value
+
1045 symbol
->section
->output_section
->vma
+
1046 symbol
->section
->output_offset
;
1048 /* Copy the any flags from the the file hdr into the symbol */
1050 coff_symbol_type
*c
= coff_symbol_from(abfd
, symbol
);
1051 if (c
!= (coff_symbol_type
*)NULL
) {
1052 native
->n_flags
= c
->symbol
.the_bfd
->flags
;
1059 native
->pad1
[0] = 0;
1060 native
->pad1
[0] = 0;
1064 if (symbol
->flags
& BSF_LOCAL
)
1065 native
->n_sclass
= C_STAT
;
1067 native
->n_sclass
= C_EXT
;
1068 native
->n_numaux
= 0;
1072 Does this symbol have an ascociated line number - if so then
1073 make it remember this symbol index. Also tag the auxent of
1074 this symbol to point to the right place in the lineno table
1077 alent
*lineno
= c_symbol
->lineno
;
1078 native
= c_symbol
->native
;
1080 unsigned int count
= 0;
1081 lineno
[count
].u
.offset
= written
;
1082 if (native
->n_numaux
) {
1083 union internal_auxent
*a
= (union internal_auxent
*) (native
+ 1);
1085 a
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
=
1086 c_symbol
->symbol
.section
->output_section
->moving_line_filepos
;
1089 And count and relocate all other linenumbers
1092 while (lineno
[count
].line_number
) {
1093 lineno
[count
].u
.offset
+=
1094 c_symbol
->symbol
.section
->output_section
->vma
+
1095 c_symbol
->symbol
.section
->output_offset
;
1098 c_symbol
->symbol
.section
->output_section
->moving_line_filepos
+=
1102 } /* if symbol new to coff */
1104 /* Fix the symbol names */
1106 unsigned int name_length
;
1107 if (symbol
->name
== (char *) NULL
) {
1109 coff symbols always have names, so we'll make one up
1111 symbol
->name
= "strange";
1113 name_length
= strlen(symbol
->name
);
1114 if (name_length
<= SYMNMLEN
) {
1115 /* This name will fit into the symbol neatly */
1116 strncpy(native
->_n
._n_name
, symbol
->name
, SYMNMLEN
);
1119 native
->_n
._n_n
._n_offset
= string_size
+ 4;
1120 native
->_n
._n_n
._n_zeroes
= 0;
1121 string_size
+= name_length
+ 1;
1124 unsigned int numaux
= native
->n_numaux
;
1125 int type
= native
->n_type
;
1126 int class = native
->n_sclass
;
1128 coff_swap_sym_out(abfd
, native
, &buf
);
1129 bfd_write((PTR
)& buf
, 1, SYMESZ
, abfd
);
1130 for (j
= 0; j
!= native
->n_numaux
;
1133 coff_swap_aux_out(abfd
,
1134 (union internal_auxent
*)(native
+ j
+ 1), type
, class, &buf1
);
1135 bfd_write((PTR
) (native
+ j
+ 1), 1, AUXESZ
, abfd
);
1138 Reuse somewhere in the symbol to keep the index
1140 set_index(symbol
, written
);
1141 written
+= 1 + numaux
;
1144 } /* for each out symbol */
1146 bfd_get_symcount(abfd
) = written
;
1147 /* Now write out strings */
1150 unsigned int size
= string_size
+ 4;
1152 bfd_write((PTR
) &size
, 1, sizeof(size
), abfd
);
1153 for (p
= abfd
->outsymbols
, i
= 0; i
< limit
; i
++, p
++) {
1155 size_t name_length
= strlen(q
->name
);
1156 if (name_length
> SYMNMLEN
) {
1157 bfd_write((PTR
) (q
->name
), 1, name_length
+ 1, abfd
);
1162 /* We would normally not write anything here, but we'll write
1163 out 4 so that any stupid coff reader which tries to read
1164 the string table even when there isn't one won't croak.
1167 uint32e_type size
= 4;
1169 bfd_write((PTR
)&size
, 1, sizeof(size
), abfd
);
1176 coff_write_relocs(abfd
)
1180 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
) {
1182 struct external_reloc dst
;
1184 arelent
**p
= s
->orelocation
;
1185 bfd_seek(abfd
, s
->rel_filepos
, SEEK_SET
);
1186 for (i
= 0; i
< s
->reloc_count
; i
++) {
1187 struct internal_reloc n
;
1189 memset((PTR
)&n
, 0, sizeof(n
));
1190 n
.r_vaddr
= q
->address
+ s
->vma
;
1191 if (q
->sym_ptr_ptr
) {
1192 n
.r_symndx
= get_index((*(q
->sym_ptr_ptr
)));
1195 /* Work out reloc type from what is required */
1196 SELECT_RELOC(n
.r_type
, q
->howto
);
1198 n
.r_type
= q
->howto
->type
;
1200 bfd_swap_reloc_out(abfd
, &n
, &dst
);
1201 bfd_write((PTR
) &n
, 1, RELSZ
, abfd
);
1207 DEFUN(coff_write_linenumbers
,(abfd
),
1211 for (s
= abfd
->sections
; s
!= (asection
*) NULL
; s
= s
->next
) {
1212 if (s
->lineno_count
) {
1213 asymbol
**q
= abfd
->outsymbols
;
1214 bfd_seek(abfd
, s
->line_filepos
, SEEK_SET
);
1215 /* Find all the linenumbers in this section */
1218 alent
*l
= BFD_SEND(p
->the_bfd
, _get_lineno
, (p
->the_bfd
, p
));
1220 /* Found a linenumber entry, output */
1221 struct internal_lineno out
;
1223 bzero( (PTR
)&out
, sizeof(out
));
1225 out
.l_addr
.l_symndx
= l
->u
.offset
;
1226 coff_swap_lineno_out(abfd
, &out
, &buff
);
1227 bfd_write((PTR
) &buff
, 1, LINESZ
, abfd
);
1229 while (l
->line_number
) {
1230 out
.l_lnno
= l
->line_number
;
1231 out
.l_addr
.l_symndx
= l
->u
.offset
;
1232 coff_swap_lineno_out(abfd
, &out
, &buff
);
1233 bfd_write((PTR
) &buff
, 1, LINESZ
, abfd
);
1245 coff_make_empty_symbol(abfd
)
1248 coff_symbol_type
*new = (coff_symbol_type
*) bfd_alloc(abfd
, sizeof(coff_symbol_type
));
1250 bfd_error
= no_memory
;
1254 new->lineno
= (alent
*) NULL
;
1255 new->symbol
.the_bfd
= abfd
;
1256 return &new->symbol
;
1260 coff_print_symbol(ignore_abfd
, file
, symbol
, how
)
1264 bfd_print_symbol_enum_type how
;
1267 case bfd_print_symbol_name_enum
:
1268 fprintf(file
, "%s", symbol
->name
);
1270 case bfd_print_symbol_type_enum
:
1271 fprintf(file
, "coff %lx %lx", (unsigned long) coffsymbol(symbol
)->native
,
1272 (unsigned long) coffsymbol(symbol
)->lineno
);
1274 case bfd_print_symbol_all_enum
:
1276 CONST
char *section_name
= symbol
->section
== (asection
*) NULL
?
1277 "*abs" : symbol
->section
->name
;
1278 bfd_print_symbol_vandf((PTR
) file
, symbol
);
1280 fprintf(file
, " %-5s %s %s %s",
1282 coffsymbol(symbol
)->native
? "n" : "g",
1283 coffsymbol(symbol
)->lineno
? "l" : " ",
1293 coff_get_lineno(ignore_abfd
, symbol
)
1297 return coffsymbol(symbol
)->lineno
;
1301 Set flags and magic number of a coff file from architecture and machine
1302 type. Result is true if we can represent the arch&type, false if not.
1305 coff_set_flags(abfd
, magicp
, flagsp
)
1311 switch (abfd
->obj_arch
) {
1319 *magicp
= I960ROMAGIC
;
1321 ((bfd_get_file_flags(abfd) & WP_TEXT) ? I960ROMAGIC :
1322 I960RWMAGIC); FIXME???
1324 switch (abfd
->obj_machine
) {
1325 case bfd_mach_i960_core
:
1328 case bfd_mach_i960_kb_sb
:
1331 case bfd_mach_i960_mc
:
1334 case bfd_mach_i960_xa
:
1337 case bfd_mach_i960_ca
:
1340 case bfd_mach_i960_ka_sa
:
1353 *magicp
= MIPS_MAGIC_2
;
1359 *magicp
= I386MAGIC
;
1364 *magicp
= MC68MAGIC
;
1370 *magicp
= MC88OMAGIC
;
1375 default: /* Unknown architecture */
1384 coff_set_arch_mach(abfd
, arch
, machine
)
1386 enum bfd_architecture arch
;
1387 unsigned long machine
;
1391 abfd
->obj_arch
= arch
;
1392 abfd
->obj_machine
= machine
;
1393 if (arch
!= bfd_arch_unknown
&&
1394 coff_set_flags(abfd
, &dummy1
, &dummy2
) != true)
1395 return false; /* We can't represent this type */
1396 return true; /* We're easy ... */
1400 /* Calculate the file position for each section. */
1403 coff_compute_section_file_positions(abfd
)
1407 file_ptr sofar
= FILHSZ
;
1408 if (bfd_get_start_address(abfd
)) {
1410 A start address may have been added to the original file. In this
1411 case it will need an optional header to record it.
1413 abfd
->flags
|= EXEC_P
;
1415 if (abfd
->flags
& EXEC_P
)
1419 sofar
+= abfd
->section_count
* SCNHSZ
;
1421 for (current
= abfd
->sections
; current
!= NULL
; current
=
1423 /* Only deal with sections which have contents */
1424 if (!(current
->flags
& SEC_HAS_CONTENTS
))
1427 /* Align the sections in the file to the same boundary on
1428 which they are aligned in virtual memory. I960 doesn't
1429 do this (FIXME) so we can stay in sync with Intel. 960
1430 doesn't yet page from files... */
1432 sofar
= ALIGN(sofar
, 1 << current
->alignment_power
);
1434 /* FIXME, in demand paged files, the low order bits of the file
1435 offset must match the low order bits of the virtual address.
1436 "Low order" is apparently implementation defined. Add code
1437 here to round sofar up to match the virtual address. */
1439 current
->filepos
= sofar
;
1440 sofar
+= current
->size
;
1442 obj_relocbase(abfd
) = sofar
;
1451 DEFUN(coff_write_object_contents
,(abfd
),
1455 boolean hasrelocs
= false;
1456 boolean haslinno
= false;
1457 file_ptr reloc_base
;
1458 file_ptr lineno_base
;
1462 unsigned long reloc_size
= 0;
1463 unsigned long lnno_size
= 0;
1464 asection
*text_sec
= NULL
;
1465 asection
*data_sec
= NULL
;
1466 asection
*bss_sec
= NULL
;
1468 struct internal_filehdr internal_f
;
1469 struct internal_aouthdr internal_a
;
1471 struct icofdata
*coff
= obj_icof(abfd
);
1474 bfd_error
= system_call_error
;
1477 if(abfd
->output_has_begun
== false) {
1478 coff_compute_section_file_positions(abfd
);
1481 if (abfd
->sections
!= (asection
*)NULL
) {
1482 scn_base
= abfd
->sections
->filepos
;
1487 if (bfd_seek(abfd
, scn_base
, SEEK_SET
) != 0)
1489 reloc_base
= obj_relocbase(abfd
);
1491 /* Make a pass through the symbol table to count line number entries and
1492 put them into the correct asections */
1494 coff_count_linenumbers(abfd
);
1495 data_base
= scn_base
;
1497 /* Work out the size of the reloc and linno areas */
1499 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1500 reloc_size
+= current
->reloc_count
* RELSZ
;
1501 lnno_size
+= current
->lineno_count
* LINESZ
;
1502 data_base
+= SCNHSZ
;
1505 lineno_base
= reloc_base
+ reloc_size
;
1506 sym_base
= lineno_base
+ lnno_size
;
1508 /* Indicate in each section->line_filepos its actual file address */
1509 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1510 if (current
->lineno_count
) {
1511 current
->line_filepos
= lineno_base
;
1512 current
->moving_line_filepos
= lineno_base
;
1513 lineno_base
+= current
->lineno_count
* LINESZ
;
1516 current
->line_filepos
= 0;
1518 if (current
->reloc_count
) {
1519 current
->rel_filepos
= reloc_base
;
1520 reloc_base
+= current
->reloc_count
* sizeof(struct internal_reloc
);
1523 current
->rel_filepos
= 0;
1527 /* Write section headers to the file. */
1530 (file_ptr
) ((abfd
->flags
& EXEC_P
) ?
1531 (FILHSZ
+ AOUTSZ
) : FILHSZ
),
1536 unsigned int pad
= abfd
->flags
& D_PAGED
? data_base
: 0;
1538 unsigned int pad
= 0;
1540 for (current
= abfd
->sections
; current
!= NULL
; current
= current
->next
) {
1541 struct internal_scnhdr section
;
1542 strncpy(&(section
.s_name
[0]), current
->name
, 8);
1543 section
.s_vaddr
= current
->vma
+ pad
;
1544 section
.s_paddr
= current
->vma
+ pad
;
1545 section
.s_size
= current
->size
- pad
;
1547 If this section has no size or is unloadable then the scnptr
1550 if (current
->size
- pad
== 0 ||
1551 (current
->flags
& SEC_LOAD
) == 0) {
1552 section
.s_scnptr
= 0;
1556 section
.s_scnptr
= current
->filepos
;
1558 section
.s_relptr
= current
->rel_filepos
;
1559 section
.s_lnnoptr
= current
->line_filepos
;
1560 section
.s_nreloc
= current
->reloc_count
;
1561 section
.s_nlnno
= current
->lineno_count
;
1562 if (current
->reloc_count
!= 0)
1564 if (current
->lineno_count
!= 0)
1567 if (!strcmp(current
->name
, _TEXT
)) {
1569 section
.s_flags
= STYP_TEXT
; /* kinda stupid */
1571 else if (!strcmp(current
->name
, _DATA
)) {
1573 section
.s_flags
= STYP_DATA
; /* kinda stupid */
1575 else if (!strcmp(current
->name
, _BSS
)) {
1577 section
.s_flags
= STYP_BSS
; /* kinda stupid */
1582 section
.s_align
= (current
->alignment_power
1583 ? 1 << current
->alignment_power
1590 swap_scnhdr_out(abfd
, §ion
, &buff
);
1591 bfd_write((PTR
) (&buff
), 1, SCNHSZ
, abfd
);
1598 /* OK, now set up the filehdr... */
1599 internal_f
.f_nscns
= abfd
->section_count
;
1601 We will NOT put a fucking timestamp in the header here. Every time you
1602 put it back, I will come in and take it out again. I'm sorry. This
1603 field does not belong here. We fill it with a 0 so it compares the
1604 same but is not a reasonable time. -- gnu@cygnus.com
1607 Well, I like it, so I'm conditionally compiling it in.
1610 #ifdef COFF_TIMESTAMP
1611 internal_f
.f_timdat
= time(0);
1613 internal_f
.f_timdat
= 0;
1616 if (bfd_get_symcount(abfd
) != 0)
1617 internal_f
.f_symptr
= sym_base
;
1619 internal_f
.f_symptr
= 0;
1621 internal_f
.f_flags
= 0;
1623 if (abfd
->flags
& EXEC_P
)
1624 internal_f
.f_opthdr
= AOUTSZ
;
1626 internal_f
.f_opthdr
= 0;
1629 internal_f
.f_flags
|= F_RELFLG
;
1631 internal_f
.f_flags
|= F_LNNO
;
1632 if (0 == bfd_get_symcount(abfd
))
1633 internal_f
.f_flags
|= F_LSYMS
;
1634 if (abfd
->flags
& EXEC_P
)
1635 internal_f
.f_flags
|= F_EXEC
;
1637 internal_f
.f_flags
|= F_AR32W
;
1639 if (!abfd
->xvec
->byteorder_big_p
)
1640 internal_f
.f_flags
|= F_AR32WR
;
1643 FIXME, should do something about the other byte orders and
1647 /* Set up architecture-dependent stuff */
1651 coff_set_flags(abfd
, &magic
, &flags
);
1652 internal_f
.f_magic
= magic
;
1653 internal_f
.f_flags
= flags
;
1655 /* ...and the "opt"hdr... */
1658 internal_a
.magic
= (magic
== I960ROMAGIC
? NMAGIC
: OMAGIC
);
1661 internal_a
.magic
= PAGEMAGICBCS
;
1664 /* Now should write relocs, strings, syms */
1665 obj_sym_filepos(abfd
) = sym_base
;
1667 if (bfd_get_symcount(abfd
) != 0) {
1668 coff_mangle_symbols(abfd
);
1669 coff_write_symbols(abfd
);
1670 coff_write_linenumbers(abfd
);
1671 coff_write_relocs(abfd
);
1674 internal_a
.tsize
= text_sec
->size
;
1675 internal_a
.text_start
=text_sec
->size
? text_sec
->vma
: 0;
1678 internal_a
.dsize
= data_sec
->size
;
1679 internal_a
.data_start
= data_sec
->size
? data_sec
->vma
: 0;
1682 internal_a
.bsize
= bss_sec
->size
;
1685 internal_a
.entry
= bfd_get_start_address(abfd
);
1686 internal_f
.f_nsyms
= bfd_get_symcount(abfd
);
1688 /* now write them */
1689 if (bfd_seek(abfd
, 0L, SEEK_SET
) != 0)
1693 bfd_swap_filehdr_out(abfd
, &internal_f
, &buff
);
1694 bfd_write((PTR
) &buff
, 1, FILHSZ
, abfd
);
1696 if (abfd
->flags
& EXEC_P
) {
1698 bfd_swap_aouthdr_out(abfd
, &internal_a
, &buff
);
1699 bfd_write((PTR
) &buff
, 1, AOUTSZ
, abfd
);
1705 coff_set_section_contents(abfd
, section
, location
, offset
, count
)
1712 if (abfd
->output_has_begun
== false) /* set by bfd.c handler */
1713 coff_compute_section_file_positions(abfd
);
1715 bfd_seek(abfd
, (file_ptr
) (section
->filepos
+ offset
), SEEK_SET
);
1718 return (bfd_write(location
, 1, count
, abfd
) == count
) ? true : false;
1724 coff_close_and_cleanup(abfd
)
1727 if (!bfd_read_p(abfd
))
1728 switch (abfd
->format
) {
1730 if (!_bfd_write_archive_contents(abfd
))
1734 if (!coff_write_object_contents(abfd
))
1738 bfd_error
= invalid_operation
;
1742 /* We depend on bfd_close to free all the memory on the obstack. */
1743 /* FIXME if bfd_release is not using obstacks! */
1749 buy_and_read(abfd
, where
, seek_direction
, size
)
1755 PTR area
= (PTR
) bfd_alloc(abfd
, size
);
1757 bfd_error
= no_memory
;
1760 bfd_seek(abfd
, where
, seek_direction
);
1761 if (bfd_read(area
, 1, size
, abfd
) != size
) {
1762 bfd_error
= system_call_error
;
1766 } /* buy_and_read() */
1769 DEFUN(offset_symbol_indices
,(abfd
, symtab
, count
, offset
),
1771 struct internal_syment
*symtab AND
1772 unsigned long count AND
1775 struct internal_syment
*end
= symtab
+ count
;
1776 for (; symtab
< end
; ++symtab
) {
1777 if (symtab
->n_sclass
== C_FILE
) {
1778 symtab
->n_value
= 0;
1780 else if (symtab
->n_sclass
== C_ALIAS
) {
1782 These guys have indices in their values.
1784 symtab
->n_value
= symtab
->n_value
+ offset
;
1786 else if (symtab
->n_numaux
) {
1788 anybody else without an aux, has no indices.
1791 if (symtab
->n_sclass
== C_EOS
1792 || (BTYPE(symtab
->n_type
) == T_STRUCT
1793 && symtab
->n_sclass
!= C_STRTAG
)
1794 || BTYPE(symtab
->n_type
) == T_UNION
1795 || BTYPE(symtab
->n_type
) == T_ENUM
) {
1796 /* If the tagndx is 0 then the struct hasn't really been
1797 defined, so leave it alone */
1799 if(((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tagndx
!= 0) {
1800 ((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tagndx
+= offset
;
1803 } /* These guys have a tagndx */
1804 if (symtab
->n_sclass
== C_STRTAG
1805 || symtab
->n_sclass
== C_UNTAG
1806 || symtab
->n_sclass
== C_ENTAG
1807 || symtab
->n_sclass
== C_BLOCK
1808 || symtab
->n_sclass
== C_FCN
1809 || ISFCN(symtab
->n_type
)) {
1811 ((union internal_auxent
*) (symtab
+
1812 1))->x_sym
.x_fcnary
.x_fcn
.x_endndx
1815 } /* These guys have an endndx */
1817 if (ISFCN(symtab
->n_type
)) {
1818 ((union internal_auxent
*) (symtab
+ 1))->x_sym
.x_tvndx
+= offset
;
1819 } /* These guys have a tvndx. I think...
1821 #endif /* Not I960 */
1823 } /* if value, else if aux */
1824 symtab
+= symtab
->n_numaux
;
1825 } /* walk the symtab */
1828 } /* offset_symbol_indices() */
1831 read a symbol table into freshly mallocated memory, swap it, and knit the
1832 symbol names into a normalized form. By normalized here I mean that all
1833 symbols have an n_offset pointer that points to a NULL terminated string.
1834 Oh, and the first symbol MUST be a C_FILE. If there wasn't one there
1835 before, put one there.
1838 static struct internal_syment
*
1839 DEFUN(get_normalized_symtab
,(abfd
),
1843 struct internal_syment
*internal
;
1844 struct internal_syment
*internal_ptr
;
1845 struct internal_syment
*internal_end
;
1849 char *string_table
= NULL
;
1851 char string_table_size_buffer
[4];
1852 unsigned long string_table_size
= 0;
1853 unsigned int raw_size
;
1854 if (obj_raw_syments(abfd
) != (struct internal_syment
*)NULL
) {
1855 return obj_raw_syments(abfd
);
1857 if ((size
= bfd_get_symcount(abfd
) * sizeof(struct internal_syment
)) == 0) {
1858 bfd_error
= no_symbols
;
1862 internal
= (struct internal_syment
*)bfd_alloc(abfd
, size
);
1863 internal_end
= internal
+ bfd_get_symcount(abfd
);
1865 raw_size
= bfd_get_symcount(abfd
) * SYMESZ
;
1866 raw
= (SYMENT
*)bfd_alloc(abfd
,raw_size
);
1868 if (bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
) == -1
1869 || bfd_read((PTR
)raw
, raw_size
, 1, abfd
) != raw_size
) {
1870 bfd_error
= system_call_error
;
1873 /* mark the end of the symbols */
1874 raw_end
= raw
+ bfd_get_symcount(abfd
);
1876 FIXME SOMEDAY. A string table size of zero is very weird, but
1877 probably possible. If one shows up, it will probably kill us.
1880 /* Swap all the raw entries */
1881 for (raw_src
= raw
, internal_ptr
= internal
; raw_src
< raw_end
; raw_src
++, internal_ptr
++) {
1883 coff_swap_sym_in(abfd
, raw_src
,internal_ptr
);
1884 for (i
= internal_ptr
->n_numaux
; i
; --i
, raw_src
++, internal_ptr
++) {
1885 coff_swap_aux_in(abfd
, (AUXENT
*)(raw_src
+1), internal_ptr
->n_type
,
1886 internal_ptr
->n_sclass
, (union
1887 internal_auxent
*)(internal_ptr
+1));
1891 /* Free all the raw stuff */
1892 bfd_release(abfd
, raw_src
);
1894 for (internal_ptr
= internal
; internal_ptr
< internal_end
; internal_ptr
++) {
1896 if (internal_ptr
->_n
._n_n
._n_zeroes
!= 0) {
1898 This is a "short" name. Make it long.
1900 unsigned long i
= 0;
1901 char *newstring
= NULL
;
1903 find the length of this string without walking into memory
1907 for (i
= 0; i
< 8; ++i
) {
1908 if (internal_ptr
->_n
._n_name
[i
] == '\0') {
1910 } /* if end of string */
1911 } /* possible lengths of this string. */
1913 if ((newstring
= (PTR
) bfd_alloc(abfd
, ++i
)) == NULL
) {
1914 bfd_error
= no_memory
;
1917 bzero(newstring
, i
);
1918 strncpy(newstring
, internal_ptr
->_n
._n_name
, i
-1);
1919 internal_ptr
->_n
._n_n
._n_offset
= (int) newstring
;
1920 internal_ptr
->_n
._n_n
._n_zeroes
= 0;
1924 if (string_table
== NULL
) {
1926 NOTE: we don't read the string table until now because we
1927 don't necessarily know that we have one until now.
1930 At this point we should be "seek"'d to the end of the
1931 symbols === the symbol table size.
1934 if (bfd_read((char *) string_table_size_buffer
,
1935 sizeof(string_table_size_buffer
),
1936 1, abfd
) != sizeof(string_table_size
)) {
1937 bfd_error
= system_call_error
;
1941 string_table_size
= bfd_h_get_32(abfd
, string_table_size_buffer
);
1943 if ((string_table
= (PTR
) bfd_alloc(abfd
, string_table_size
-= 4)) == NULL
) {
1944 bfd_error
= no_memory
;
1946 } /* on mallocation error */
1947 if (bfd_read(string_table
, string_table_size
, 1, abfd
) != string_table_size
) {
1948 bfd_error
= system_call_error
;
1951 } /* have not yet read the string table. */
1953 This is a long name already. Just point it at the string in
1956 internal_ptr
->_n
._n_n
._n_offset
= (int) (string_table
- 4 + internal_ptr
->_n
._n_n
._n_offset
);
1958 } /* switch on type of symbol name */
1960 internal_ptr
+= internal_ptr
->n_numaux
;
1961 } /* for each symbol */
1964 /* I'm not sure of the repercussions of this, so the Intel
1965 folks will always do the force
1967 if (obj_symbol_slew(abfd
) > 0)
1968 force_indices_file_symbol_relative(abfd
, internal
);
1970 force_indices_file_symbol_relative(abfd
, internal
);
1973 obj_raw_syments(abfd
) = internal
;
1974 obj_string_table(abfd
) = string_table
;
1977 } /* get_normalized_symtab() */
1981 DEFUN(section_from_bfd_index
,(abfd
, index
),
1986 struct sec
*answer
= abfd
->sections
;
1988 answer
= answer
->next
;
1999 coff_slurp_line_table(abfd
, asect
)
2003 LINENO
*native_lineno
;
2004 alent
*lineno_cache
;
2006 BFD_ASSERT(asect
->lineno
== (alent
*) NULL
);
2008 native_lineno
= (LINENO
*) buy_and_read(abfd
,
2009 asect
->line_filepos
,
2012 asect
->lineno_count
));
2014 (alent
*) bfd_alloc(abfd
, (size_t) ((asect
->lineno_count
+ 1) * sizeof(alent
)));
2015 if (lineno_cache
== NULL
) {
2016 bfd_error
= no_memory
;
2019 unsigned int counter
= 0;
2020 alent
*cache_ptr
= lineno_cache
;
2021 LINENO
*src
= native_lineno
;
2023 while (counter
< asect
->lineno_count
) {
2024 struct internal_lineno dst
;
2025 coff_swap_lineno_in(abfd
, src
, &dst
);
2026 cache_ptr
->line_number
= dst
.l_lnno
;
2028 if (cache_ptr
->line_number
== 0) {
2029 coff_symbol_type
*sym
=
2030 (coff_symbol_type
*) (dst
.l_addr
.l_symndx
2031 + obj_symbol_slew(abfd
)
2032 + obj_raw_syments(abfd
))->_n
._n_n
._n_zeroes
;
2033 cache_ptr
->u
.sym
= (asymbol
*) sym
;
2034 sym
->lineno
= cache_ptr
;
2037 cache_ptr
->u
.offset
= dst
.l_addr
.l_paddr
2038 - bfd_section_vma(abfd
, asect
);
2039 } /* If no linenumber expect a symbol index */
2045 cache_ptr
->line_number
= 0;
2048 asect
->lineno
= lineno_cache
;
2049 /* FIXME, free native_lineno here, or use alloca or something. */
2051 } /* coff_slurp_line_table() */
2054 DEFUN(coff_slurp_symbol_table
,(abfd
),
2057 struct internal_syment
*native_symbols
;
2058 coff_symbol_type
*cached_area
;
2059 unsigned int *table_ptr
;
2061 unsigned int number_of_symbols
= 0;
2062 if (obj_symbols(abfd
))
2064 bfd_seek(abfd
, obj_sym_filepos(abfd
), SEEK_SET
);
2066 /* Read in the symbol table */
2067 if ((native_symbols
= get_normalized_symtab(abfd
)) == NULL
) {
2072 /* Allocate enough room for all the symbols in cached form */
2074 (coff_symbol_type
*)
2075 bfd_alloc(abfd
, (size_t) (bfd_get_symcount(abfd
) * sizeof(coff_symbol_type
)));
2077 if (cached_area
== NULL
) {
2078 bfd_error
= no_memory
;
2083 bfd_alloc(abfd
, (size_t) (bfd_get_symcount(abfd
) * sizeof(unsigned int)));
2085 if (table_ptr
== NULL
) {
2086 bfd_error
= no_memory
;
2089 coff_symbol_type
*dst
= cached_area
;
2090 unsigned int last_native_index
= bfd_get_symcount(abfd
);
2091 unsigned int this_index
= 0;
2092 while (this_index
< last_native_index
) {
2093 struct internal_syment
*src
= native_symbols
+ this_index
;
2094 table_ptr
[this_index
] = number_of_symbols
;
2095 dst
->symbol
.the_bfd
= abfd
;
2097 dst
->symbol
.name
= (char *)(src
->_n
._n_n
._n_offset
);
2099 We use the native name field to point to the cached field
2101 src
->_n
._n_n
._n_zeroes
= (int) dst
;
2102 dst
->symbol
.section
= section_from_bfd_index(abfd
,
2104 switch (src
->n_sclass
) {
2108 dst
->symbol
.value
= src
->n_value
- dst
->symbol
.section
->vma
;
2109 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
;
2110 dst
->symbol
.flags
|= BSF_NOT_AT_END
;
2112 /* Fall through to next case */
2117 if ((src
->n_scnum
) == 0) {
2118 if ((src
->n_value
) == 0) {
2119 dst
->symbol
.flags
= BSF_UNDEFINED
;
2120 dst
->symbol
.value
= 0;
2123 dst
->symbol
.flags
= BSF_FORT_COMM
;
2124 dst
->symbol
.value
= (src
->n_value
);
2129 Base the value as an index from the base of the
2132 if (dst
->symbol
.section
== (asection
*) NULL
) {
2133 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
| BSF_ABSOLUTE
;
2134 dst
->symbol
.value
= src
->n_value
;
2137 dst
->symbol
.flags
= BSF_EXPORT
| BSF_GLOBAL
;
2138 dst
->symbol
.value
= src
->n_value
- dst
->symbol
.section
->vma
;
2140 if (ISFCN((src
->n_type
))) {
2142 A function ext does not go at the end of a file
2144 dst
->symbol
.flags
|= BSF_NOT_AT_END
;
2149 case C_STAT
: /* static */
2151 case C_LEAFSTAT
: /* static leaf procedure */
2153 case C_LABEL
: /* label */
2154 dst
->symbol
.flags
= BSF_LOCAL
;
2156 Base the value as an index from the base of the section
2158 dst
->symbol
.value
= (src
->n_value
) - dst
->symbol
.section
->vma
;
2161 case C_MOS
: /* member of structure */
2162 case C_EOS
: /* end of structure */
2163 case C_REGPARM
: /* register parameter */
2164 case C_REG
: /* register variable */
2166 case C_AUTOARG
: /* 960-specific storage class */
2168 case C_TPDEF
: /* type definition */
2171 case C_AUTO
: /* automatic variable */
2172 case C_FIELD
: /* bit field */
2173 case C_ENTAG
: /* enumeration tag */
2174 case C_MOE
: /* member of enumeration */
2175 case C_MOU
: /* member of union */
2176 case C_UNTAG
: /* union tag */
2178 dst
->symbol
.flags
= BSF_DEBUGGING
;
2179 dst
->symbol
.value
= (src
->n_value
);
2182 case C_FILE
: /* file name */
2183 case C_STRTAG
: /* structure tag */
2184 dst
->symbol
.flags
= BSF_DEBUGGING
;
2185 dst
->symbol
.value
= (src
->n_value
);
2188 case C_BLOCK
: /* ".bb" or ".eb" */
2189 case C_FCN
: /* ".bf" or ".ef" */
2190 dst
->symbol
.flags
= BSF_LOCAL
;
2192 Base the value as an index from the base of the section
2194 dst
->symbol
.value
= (src
->n_value
) - dst
->symbol
.section
->vma
;
2197 case C_EFCN
: /* physical end of function */
2199 case C_EXTDEF
: /* external definition */
2200 case C_ULABEL
: /* undefined label */
2201 case C_USTATIC
: /* undefined static */
2202 case C_LINE
: /* line # reformatted as symbol table entry */
2203 case C_ALIAS
: /* duplicate tag */
2204 case C_HIDDEN
: /* ext symbol in dmert public lib */
2209 dst
->symbol
.flags
= BSF_DEBUGGING
;
2210 dst
->symbol
.value
= (src
->n_value
);
2215 BFD_ASSERT(dst
->symbol
.flags
!= 0);
2219 dst
->symbol
.udata
= 0;
2220 dst
->lineno
= (alent
*) NULL
;
2221 this_index
+= (src
->n_numaux
) + 1;
2223 number_of_symbols
++;
2224 } /* walk the native symtab */
2225 } /* bfdize the native symtab */
2227 obj_symbols(abfd
) = cached_area
;
2228 obj_raw_syments(abfd
) = native_symbols
;
2230 bfd_get_symcount(abfd
) = number_of_symbols
;
2231 obj_convert(abfd
) = table_ptr
;
2232 /* Slurp the line tables for each section too */
2237 coff_slurp_line_table(abfd
, p
);
2242 } /* coff_slurp_symbol_table() */
2245 coff_get_symtab_upper_bound(abfd
)
2248 if (!coff_slurp_symbol_table(abfd
))
2251 return (bfd_get_symcount(abfd
) + 1) * (sizeof(coff_symbol_type
*));
2256 coff_get_symtab(abfd
, alocation
)
2258 asymbol
**alocation
;
2260 unsigned int counter
= 0;
2261 coff_symbol_type
*symbase
;
2262 coff_symbol_type
**location
= (coff_symbol_type
**) (alocation
);
2263 if (!coff_slurp_symbol_table(abfd
))
2266 for (symbase
= obj_symbols(abfd
); counter
++ < bfd_get_symcount(abfd
);)
2267 *(location
++) = symbase
++;
2269 return bfd_get_symcount(abfd
);
2273 coff_get_reloc_upper_bound(abfd
, asect
)
2277 if (bfd_get_format(abfd
) != bfd_object
) {
2278 bfd_error
= invalid_operation
;
2281 return (asect
->reloc_count
+ 1) * sizeof(arelent
*);
2285 DEFUN(coff_slurp_reloc_table
,(abfd
, asect
, symbols
),
2290 RELOC
*native_relocs
;
2291 arelent
*reloc_cache
;
2292 if (asect
->relocation
)
2294 if (asect
->reloc_count
== 0)
2296 if (!coff_slurp_symbol_table(abfd
))
2299 (RELOC
*) buy_and_read(abfd
,
2303 asect
->reloc_count
));
2304 reloc_cache
= (arelent
*)
2305 bfd_alloc(abfd
, (size_t) (asect
->reloc_count
* sizeof(arelent
)));
2307 if (reloc_cache
== NULL
) {
2308 bfd_error
= no_memory
;
2313 for (cache_ptr
= reloc_cache
,
2314 src
= native_relocs
;
2315 cache_ptr
< reloc_cache
+ asect
->reloc_count
;
2318 struct internal_reloc dst
;
2320 bfd_swap_reloc_in(abfd
, src
, &dst
);
2321 dst
.r_symndx
+= obj_symbol_slew(abfd
);
2322 cache_ptr
->sym_ptr_ptr
= symbols
+ obj_convert(abfd
)[dst
.r_symndx
];
2324 ptr
= *(cache_ptr
->sym_ptr_ptr
);
2325 cache_ptr
->address
= dst
.r_vaddr
;
2327 The symbols definitions that we have read in have been
2328 relocated as if their sections started at 0. But the offsets
2329 refering to the symbols in the raw data have not been
2330 modified, so we have to have a negative addend to compensate.
2332 Note that symbols which used to be common must be left alone
2335 if (ptr
->the_bfd
== abfd
2336 && ptr
->section
!= (asection
*) NULL
2337 && ((ptr
->flags
& BSF_OLD_COMMON
)== 0))
2339 cache_ptr
->addend
= -(ptr
->section
->vma
+ ptr
->value
);
2342 cache_ptr
->addend
= 0;
2345 cache_ptr
->address
-= asect
->vma
;
2347 cache_ptr
->section
= (asection
*) NULL
;
2350 cache_ptr
->howto
= howto_table
+ dst
.r_type
;
2353 cache_ptr
->howto
= howto_table
+ dst
.r_type
;
2356 cache_ptr
->howto
= howto_table
+ dst
.r_type
- R_RELBYTE
;
2359 if (dst
.r_type
>= R_PCR16L
&& dst
.r_type
<= R_VRT32
) {
2360 cache_ptr
->howto
= howto_table
+ dst
.r_type
- R_PCR16L
;
2361 cache_ptr
->addend
+= dst
.r_offset
<< 16;
2372 asect
->relocation
= reloc_cache
;
2377 /* This is stupid. This function should be a boolean predicate */
2379 coff_canonicalize_reloc(abfd
, section
, relptr
, symbols
)
2385 arelent
*tblptr
= section
->relocation
;
2386 unsigned int count
= 0;
2387 if (!(tblptr
|| coff_slurp_reloc_table(abfd
, section
, symbols
)))
2389 tblptr
= section
->relocation
;
2393 for (; count
++ < section
->reloc_count
;)
2394 *relptr
++ = tblptr
++;
2398 return section
->reloc_count
;
2403 provided a bfd, a section and an offset into the section, calculate and
2404 return the name of the source file and the line nearest to the wanted
2409 DEFUN(coff_find_nearest_line
,(abfd
,
2417 asection
*section AND
2418 asymbol
**symbols AND
2420 CONST
char **filename_ptr AND
2421 CONST
char **functionname_ptr AND
2422 unsigned int *line_ptr
)
2424 static bfd
*cache_abfd
;
2425 static asection
*cache_section
;
2426 static bfd_vma cache_offset
;
2427 static unsigned int cache_i
;
2428 static alent
*cache_l
;
2431 struct icofdata
*cof
= obj_icof(abfd
);
2432 /* Run through the raw syments if available */
2433 struct internal_syment
*p
;
2435 unsigned int line_base
= 0;
2439 *functionname_ptr
= 0;
2442 /* Don't try and find line numbers in a non coff file */
2443 if (abfd
->xvec
->flavour
!= bfd_target_coff_flavour_enum
)
2446 if (cof
== (struct icofdata
*)NULL
)
2449 p
= cof
->raw_syments
;
2451 I don't know for sure what's right, but this isn't it. First off, an
2452 object file may not have any C_FILE's in it. After
2453 get_normalized_symtab(), it should have at least 1, the one I put
2454 there, but otherwise, all bets are off. Point #2, the first C_FILE
2455 isn't necessarily the right C_FILE because any given object may have
2456 many. I think you'll have to track sections as they coelesce in order
2457 to find the C_STAT symbol for this section. Then you'll have to work
2458 backwards to find the previous C_FILE, or choke if you get to a C_STAT
2459 for the same kind of section. That will mean that the original object
2460 file didn't have a C_FILE. xoxorich.
2464 #ifdef WEREBEINGPEDANTIC
2468 for (i
= 0; i
< cof
->raw_syment_count
; i
++) {
2469 if (p
->n_sclass
== C_FILE
) {
2470 /* File name is embeded in auxent */
2472 This isn't right. The fname should probably be normalized
2473 during get_normalized_symtab(). In any case, what was here
2474 wasn't right because a SYMENT.n_name isn't an
2475 AUXENT.x_file.x_fname. xoxorich.
2478 *filename_ptr
= ((AUXENT
*) (p
+ 1))->x_file
.x_fname
;
2481 p
+= 1 + p
->n_numaux
;
2483 /* Now wander though the raw linenumbers of the section */
2485 If this is the same bfd as we were previously called with and this is
2486 the same section, and the offset we want is further down then we can
2487 prime the lookup loop
2489 if (abfd
== cache_abfd
&&
2490 section
== cache_section
&&
2491 offset
>= cache_offset
) {
2497 l
= section
->lineno
;
2500 for (; i
< section
->lineno_count
; i
++) {
2501 if (l
->line_number
== 0) {
2502 /* Get the symbol this line number points at */
2503 coff_symbol_type
*coff
= (coff_symbol_type
*) (l
->u
.sym
);
2504 *functionname_ptr
= coff
->symbol
.name
;
2506 struct internal_syment
*s
= coff
->native
;
2507 s
= s
+ 1 + s
->n_numaux
;
2509 S should now point to the .bf of the function
2513 The linenumber is stored in the auxent
2515 union internal_auxent
*a
= (union internal_auxent
*) (s
+ 1);
2516 line_base
= a
->x_sym
.x_misc
.x_lnsz
.x_lnno
;
2521 if (l
->u
.offset
> offset
)
2523 *line_ptr
= l
->line_number
+ line_base
+ 1;
2529 cache_section
= section
;
2530 cache_offset
= offset
;
2538 coff_sym_filepos(abfd
)
2541 return obj_sym_filepos(abfd
);
2547 DEFUN(coff_sizeof_headers
,(abfd
, reloc
),
2553 if (reloc
== false) {
2554 size
= FILHSZ
+ AOUTSZ
;
2560 size
+= abfd
->section_count
* SCNHSZ
;
2565 #define coff_core_file_failing_command _bfd_dummy_core_file_failing_command
2566 #define coff_core_file_failing_signal _bfd_dummy_core_file_failing_signal
2567 #define coff_core_file_matches_executable_p _bfd_dummy_core_file_matches_executable_p
2568 #define coff_slurp_armap bfd_slurp_coff_armap
2569 #define coff_slurp_extended_name_table _bfd_slurp_extended_name_table
2570 #define coff_truncate_arname bfd_dont_truncate_arname
2571 #define coff_openr_next_archived_file bfd_generic_openr_next_archived_file
2572 #define coff_generic_stat_arch_elt bfd_generic_stat_arch_elt
2573 #define coff_get_section_contents bfd_generic_get_section_contents
2574 #define coff_close_and_cleanup bfd_generic_close_and_cleanup