1 /* coff object file format
2 Copyright (C) 1989, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GAS.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
26 const short seg_N_TYPE
[] =
27 { /* in: segT out: N_TYPE bits */
32 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
33 C_UNDEF_SECTION
, /* SEG_GOOF */
34 C_UNDEF_SECTION
, /* SEG_EXPR */
35 C_DEBUG_SECTION
, /* SEG_DEBUG */
36 C_NTV_SECTION
, /* SEG_NTV */
37 C_PTV_SECTION
, /* SEG_PTV */
38 C_REGISTER_SECTION
, /* SEG_REGISTER */
42 /* Add 4 to the real value to get the index and compensate the negatives */
44 const segT N_TYPE_seg
[32] =
46 SEG_PTV
, /* C_PTV_SECTION == -4 */
47 SEG_NTV
, /* C_NTV_SECTION == -3 */
48 SEG_DEBUG
, /* C_DEBUG_SECTION == -2 */
49 SEG_ABSOLUTE
, /* C_ABS_SECTION == -1 */
50 SEG_UNKNOWN
, /* C_UNDEF_SECTION == 0 */
51 SEG_TEXT
, /* C_TEXT_SECTION == 1 */
52 SEG_DATA
, /* C_DATA_SECTION == 2 */
53 SEG_BSS
, /* C_BSS_SECTION == 3 */
54 SEG_REGISTER
, /* C_REGISTER_SECTION == 4 */
55 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
56 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
,
57 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
61 const char *s_get_name
PARAMS ((symbolS
* s
));
62 static symbolS
*tag_find_or_make
PARAMS ((char *name
));
63 static symbolS
*tag_find
PARAMS ((char *name
));
67 static void obj_coff_section_header_append
PARAMS ((char **where
, struct internal_scnhdr
* header
));
69 static void obj_coff_section_header_append
PARAMS ((char **where
, SCNHDR
* header
));
73 static void obj_coff_def
PARAMS ((int what
));
74 static void obj_coff_dim
PARAMS ((int));
75 static void obj_coff_endef
PARAMS ((int));
76 static void obj_coff_line
PARAMS ((int));
77 static void obj_coff_ln
PARAMS ((int));
78 static void obj_coff_scl
PARAMS ((int));
79 static void obj_coff_size
PARAMS ((int));
80 static void obj_coff_tag
PARAMS ((int));
81 static void obj_coff_type
PARAMS ((int));
82 static void obj_coff_val
PARAMS ((int));
83 static void tag_init
PARAMS ((void));
84 static void tag_insert
PARAMS ((const char *name
, symbolS
* symbolP
));
87 static void SA_SET_SYM_ENDNDX
PARAMS ((symbolS
*, symbolS
*));
88 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
91 static struct hash_control
*tag_hash
;
92 static symbolS
*def_symbol_in_progress
;
94 static symbolS
*dot_text_symbol
;
95 static symbolS
*dot_data_symbol
;
96 static symbolS
*dot_bss_symbol
;
98 const pseudo_typeS obj_pseudo_table
[] =
101 {"def", obj_coff_def
, 0},
102 {"dim", obj_coff_dim
, 0},
103 {"endef", obj_coff_endef
, 0},
104 {"line", obj_coff_line
, 0},
105 {"ln", obj_coff_ln
, 0},
106 {"appline", obj_coff_ln
, 1},
107 {"scl", obj_coff_scl
, 0},
108 {"size", obj_coff_size
, 0},
109 {"tag", obj_coff_tag
, 0},
110 {"type", obj_coff_type
, 0},
111 {"val", obj_coff_val
, 0},
113 {"def", s_ignore
, 0},
114 {"dim", s_ignore
, 0},
115 {"endef", s_ignore
, 0},
116 {"line", s_ignore
, 0},
118 {"scl", s_ignore
, 0},
119 {"size", s_ignore
, 0},
120 {"tag", s_ignore
, 0},
121 {"type", s_ignore
, 0},
122 {"val", s_ignore
, 0},
123 #endif /* ignore debug */
125 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
127 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
129 {"ABORT", s_abort
, 0},
131 {NULL
} /* end sentinel */
132 }; /* obj_pseudo_table */
136 struct line_no
*next
;
142 #define GET_FILENAME_STRING(X) \
143 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
145 /* obj dependant output values */
146 #ifndef BFD_ASSEMBLER
148 static struct internal_scnhdr bss_section_header
;
149 struct internal_scnhdr data_section_header
;
150 struct internal_scnhdr text_section_header
;
152 static SCNHDR bss_section_header
;
153 SCNHDR data_section_header
;
154 SCNHDR text_section_header
;
162 fetch_coff_debug_section ()
164 static segT debug_section
;
168 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
170 debug_section
= s
->section
;
172 return debug_section
;
176 SA_SET_SYM_ENDNDX (sym
, val
)
180 combined_entry_type
*entry
, *p
;
182 entry
= &coffsymbol (sym
->bsym
)->native
[1];
183 p
= coffsymbol (val
->bsym
)->native
;
184 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
189 SA_SET_SYM_TAGNDX (sym
, val
)
193 combined_entry_type
*entry
, *p
;
195 entry
= &coffsymbol (sym
->bsym
)->native
[1];
196 p
= coffsymbol (val
->bsym
)->native
;
197 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
202 S_GET_DATA_TYPE (sym
)
205 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
209 S_SET_DATA_TYPE (sym
, val
)
213 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
218 S_GET_STORAGE_CLASS (sym
)
221 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
225 S_SET_STORAGE_CLASS (sym
, val
)
229 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
233 #else /* ! BFD_ASSEMBLER */
238 reloc_compare (p1
, p2
)
240 struct internal_reloc
*p1
, *p2
;
245 return (int) (p1
->r_vaddr
- p2
->r_vaddr
);
251 * Crawl along a fixS chain. Emit the segment's relocations.
255 obj_emit_relocations (where
, fixP
, segment_address_in_file
)
257 fixS
*fixP
; /* Fixup chain for this segment. */
258 relax_addressT segment_address_in_file
;
261 struct internal_reloc
*ri_table
;
272 for (count
= 0, p
= fixP
; p
; p
= p
->fx_next
)
279 ri_table
= (struct internal_reloc
*) calloc (sizeof (*ri_table
), count
);
281 ri_table
= (RELOC
*) calloc (sizeof (*ri_table
), count
);
284 as_fatal ("obj_emit_relocations: Could not malloc relocation table");
287 callj_table
= (char *) malloc (sizeof (char) * count
);
289 as_fatal ("obj_emit_relocations: Could not malloc callj table");
292 for (i
= 0; fixP
; fixP
= fixP
->fx_next
)
294 symbolP
= fixP
->fx_addsy
;
299 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
300 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
301 fixP
->fx_size
== 2 ? R_PCRWORD
:
303 (fixP
->fx_size
== 1 ? R_RELBYTE
:
304 fixP
->fx_size
== 2 ? R_RELWORD
:
309 /* FIXME-SOON R_OFF8 & R_DIR16 are a vague guess, completly
311 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
312 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
313 fixP
->fx_size
== 2 ? R_PCRWORD
:
315 (fixP
->fx_size
== 1 ? R_OFF8
:
316 fixP
->fx_size
== 2 ? R_DIR16
:
321 ri_table
[i
].r_type
= (fixP
->fx_pcrel
324 callj_table
[i
] = fixP
->fx_tcbit
? 1 : 0;
328 ri_table
[i
].r_type
= tc_coff_fix2rtype (fixP
);
333 ri_table
[i
].r_vaddr
= (fixP
->fx_frag
->fr_address
335 /* If symbol associated to relocation entry is a bss symbol
336 or undefined symbol just remember the index of the symbol.
337 Otherwise store the index of the symbol describing the
338 section the symbol belong to. This heuristic speeds up ld.
340 /* Local symbols can generate relocation information. In case
341 of structure return for instance. But they have no symbol
342 number because they won't be emitted in the final object.
343 In the case where they are in the BSS section, this leads
344 to an incorrect r_symndx.
345 Under bsd the loader do not care if the symbol reference
346 is incorrect. But the SYS V ld complains about this. To
347 avoid this we associate the symbol to the associated
348 section, *even* if it is the BSS section. */
349 /* If someone can tell me why the other symbols of the bss
350 section are not associated with the .bss section entry,
351 I'd be gratefull. I guess that it has to do with the special
352 nature of the .bss section. Or maybe this is because the
353 bss symbols are declared in the common section and can
354 be resized later. Can it break code some where ? */
355 ri_table
[i
].r_symndx
= (S_GET_SEGMENT (symbolP
) == SEG_TEXT
356 ? dot_text_symbol
->sy_number
357 : (S_GET_SEGMENT (symbolP
) == SEG_DATA
358 ? dot_data_symbol
->sy_number
359 : ((SF_GET_LOCAL (symbolP
)
360 ? dot_bss_symbol
->sy_number
361 : symbolP
->sy_number
)))); /* bss or undefined */
363 /* md_ri_to_chars((char *) &ri, ri); *//* Last step : write md f */
366 } /* if there's a symbol */
367 } /* for each fixP */
369 /* AIX ld prefer to have the reloc table with r_vaddr sorted.
370 But sorting it should not hurt any other ld. */
371 qsort (ri_table
, count
, sizeof (*ri_table
), reloc_compare
);
373 for (i
= 0; i
< count
; i
++)
376 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
], *where
);
378 /* The 29k has a special kludge for the high 16 bit reloc.
379 Two relocations are emmited, R_IHIHALF, and R_IHCONST.
380 The second one doesn't contain a symbol, but uses the
382 if (ri_table
[i
].r_type
== R_IHIHALF
)
384 /* now emit the second bit */
385 ri_table
[i
].r_type
= R_IHCONST
;
386 ri_table
[i
].r_symndx
= fixP
->fx_addnumber
;
387 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
390 # endif /* TC_A29K */
392 #else /* not BFD_HEADERS */
393 append (where
, (char *) &ri_table
[i
], RELSZ
);
394 #endif /* not BFD_HEADERS */
399 ri_table
[i
].r_type
= R_OPTCALL
;
401 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
404 append (where
, (char *) &ri_table
[i
], (unsigned long) RELSZ
);
405 # endif /* BFD_HEADERS */
406 } /* if it's a callj, do it again for the opcode */
416 /* Coff file generation & utilities */
420 obj_header_append (where
, headers
)
422 object_headers
*headers
;
424 tc_headers_hook (headers
);
425 *where
+= bfd_coff_swap_filehdr_out (stdoutput
, &(headers
->filehdr
), *where
);
426 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
427 *where
+= bfd_coff_swap_aouthdr_out (stdoutput
, &(headers
->aouthdr
), *where
);
429 obj_coff_section_header_append (where
, &text_section_header
);
430 obj_coff_section_header_append (where
, &data_section_header
);
431 obj_coff_section_header_append (where
, &bss_section_header
);
434 #else /* ! BFD_HEADERS */
437 obj_header_append (where
, headers
)
439 object_headers
*headers
;
441 tc_headers_hook (headers
);
444 /* Eventually swap bytes for cross compilation for file header */
445 md_number_to_chars (*where
, headers
->filehdr
.f_magic
, sizeof (headers
->filehdr
.f_magic
));
446 *where
+= sizeof (headers
->filehdr
.f_magic
);
447 md_number_to_chars (*where
, headers
->filehdr
.f_nscns
, sizeof (headers
->filehdr
.f_nscns
));
448 *where
+= sizeof (headers
->filehdr
.f_nscns
);
449 md_number_to_chars (*where
, headers
->filehdr
.f_timdat
, sizeof (headers
->filehdr
.f_timdat
));
450 *where
+= sizeof (headers
->filehdr
.f_timdat
);
451 md_number_to_chars (*where
, headers
->filehdr
.f_symptr
, sizeof (headers
->filehdr
.f_symptr
));
452 *where
+= sizeof (headers
->filehdr
.f_symptr
);
453 md_number_to_chars (*where
, headers
->filehdr
.f_nsyms
, sizeof (headers
->filehdr
.f_nsyms
));
454 *where
+= sizeof (headers
->filehdr
.f_nsyms
);
455 md_number_to_chars (*where
, headers
->filehdr
.f_opthdr
, sizeof (headers
->filehdr
.f_opthdr
));
456 *where
+= sizeof (headers
->filehdr
.f_opthdr
);
457 md_number_to_chars (*where
, headers
->filehdr
.f_flags
, sizeof (headers
->filehdr
.f_flags
));
458 *where
+= sizeof (headers
->filehdr
.f_flags
);
460 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
461 /* Eventually swap bytes for cross compilation for a.out header */
462 md_number_to_chars (*where
, headers
->aouthdr
.magic
, sizeof (headers
->aouthdr
.magic
));
463 *where
+= sizeof (headers
->aouthdr
.magic
);
464 md_number_to_chars (*where
, headers
->aouthdr
.vstamp
, sizeof (headers
->aouthdr
.vstamp
));
465 *where
+= sizeof (headers
->aouthdr
.vstamp
);
466 md_number_to_chars (*where
, headers
->aouthdr
.tsize
, sizeof (headers
->aouthdr
.tsize
));
467 *where
+= sizeof (headers
->aouthdr
.tsize
);
468 md_number_to_chars (*where
, headers
->aouthdr
.dsize
, sizeof (headers
->aouthdr
.dsize
));
469 *where
+= sizeof (headers
->aouthdr
.dsize
);
470 md_number_to_chars (*where
, headers
->aouthdr
.bsize
, sizeof (headers
->aouthdr
.bsize
));
471 *where
+= sizeof (headers
->aouthdr
.bsize
);
472 md_number_to_chars (*where
, headers
->aouthdr
.entry
, sizeof (headers
->aouthdr
.entry
));
473 *where
+= sizeof (headers
->aouthdr
.entry
);
474 md_number_to_chars (*where
, headers
->aouthdr
.text_start
, sizeof (headers
->aouthdr
.text_start
));
475 *where
+= sizeof (headers
->aouthdr
.text_start
);
476 md_number_to_chars (*where
, headers
->aouthdr
.data_start
, sizeof (headers
->aouthdr
.data_start
));
477 *where
+= sizeof (headers
->aouthdr
.data_start
);
478 md_number_to_chars (*where
, headers
->aouthdr
.tagentries
, sizeof (headers
->aouthdr
.tagentries
));
479 *where
+= sizeof (headers
->aouthdr
.tagentries
);
480 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
482 #else /* CROSS_COMPILE */
484 append (where
, (char *) &headers
->filehdr
, sizeof (headers
->filehdr
));
485 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
486 append (where
, (char *) &headers
->aouthdr
, sizeof (headers
->aouthdr
));
487 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
489 #endif /* CROSS_COMPILE */
491 /* Output the section headers */
492 obj_coff_section_header_append (where
, &text_section_header
);
493 obj_coff_section_header_append (where
, &data_section_header
);
494 obj_coff_section_header_append (where
, &bss_section_header
);
497 #endif /* ! BFD_HEADERS */
500 obj_symbol_to_chars (where
, symbolP
)
504 /* Move the value into the COFF symbol itself. */
505 symbolP
->sy_symbol
.ost_entry
.n_value
= S_GET_VALUE (symbolP
);
508 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
511 if (S_GET_SEGMENT (symbolP
) == SEG_REGISTER
)
513 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
515 *where
+= bfd_coff_swap_sym_out (stdoutput
, &symbolP
->sy_symbol
.ost_entry
,
518 for (i
= 0; i
< numaux
; i
++)
520 *where
+= bfd_coff_swap_aux_out (stdoutput
,
521 &symbolP
->sy_symbol
.ost_auxent
[i
],
522 S_GET_DATA_TYPE (symbolP
),
523 S_GET_STORAGE_CLASS (symbolP
),
527 #else /* BFD_HEADERS */
528 SYMENT
*syment
= &symbolP
->sy_symbol
.ost_entry
;
530 char numaux
= syment
->n_numaux
;
531 unsigned short type
= S_GET_DATA_TYPE (symbolP
);
534 md_number_to_chars (*where
, syment
->n_value
, sizeof (syment
->n_value
));
535 *where
+= sizeof (syment
->n_value
);
536 md_number_to_chars (*where
, syment
->n_scnum
, sizeof (syment
->n_scnum
));
537 *where
+= sizeof (syment
->n_scnum
);
538 md_number_to_chars (*where
, 0, sizeof (short)); /* pad n_flags */
539 *where
+= sizeof (short);
540 md_number_to_chars (*where
, syment
->n_type
, sizeof (syment
->n_type
));
541 *where
+= sizeof (syment
->n_type
);
542 md_number_to_chars (*where
, syment
->n_sclass
, sizeof (syment
->n_sclass
));
543 *where
+= sizeof (syment
->n_sclass
);
544 md_number_to_chars (*where
, syment
->n_numaux
, sizeof (syment
->n_numaux
));
545 *where
+= sizeof (syment
->n_numaux
);
546 #else /* CROSS_COMPILE */
547 append (where
, (char *) syment
, sizeof (*syment
));
548 #endif /* CROSS_COMPILE */
550 /* Should do the following:
551 if (.file entry) MD(..)... else if (static entry) MD(..) */
552 if (numaux
> OBJ_COFF_MAX_AUXENTRIES
)
554 as_bad ("Internal error? too many auxents for symbol");
555 } /* too many auxents */
557 for (i
= 0; i
< numaux
; ++i
)
560 #if 0 /* This code has never been tested */
561 /* The most common case, x_sym entry. */
562 if ((SF_GET (symbolP
) & (SF_FILE
| SF_STATICS
)) == 0)
564 md_number_to_chars (*where
, auxP
->x_sym
.x_tagndx
, sizeof (auxP
->x_sym
.x_tagndx
));
565 *where
+= sizeof (auxP
->x_sym
.x_tagndx
);
568 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_fsize
, sizeof (auxP
->x_sym
.x_misc
.x_fsize
));
569 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_fsize
);
573 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_lnno
, sizeof (auxP
->x_sym
.x_misc
.x_lnno
));
574 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_lnno
);
575 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_size
, sizeof (auxP
->x_sym
.x_misc
.x_size
));
576 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_size
);
581 for (index
= 0; index
< DIMNUM
; index
++)
582 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
], sizeof (auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
]));
583 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
]);
587 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
));
588 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
589 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
, sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
590 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
592 md_number_to_chars (*where
, auxP
->x_sym
.x_tvndx
, sizeof (auxP
->x_sym
.x_tvndx
));
593 *where
+= sizeof (auxP
->x_sym
.x_tvndx
);
595 else if (SF_GET_FILE (symbolP
))
599 else if (SF_GET_STATICS (symbolP
))
600 { /* .text, .data, .bss symbols */
601 md_number_to_chars (*where
, auxP
->x_scn
.x_scnlen
, sizeof (auxP
->x_scn
.x_scnlen
));
602 *where
+= sizeof (auxP
->x_scn
.x_scnlen
);
603 md_number_to_chars (*where
, auxP
->x_scn
.x_nreloc
, sizeof (auxP
->x_scn
.x_nreloc
));
604 *where
+= sizeof (auxP
->x_scn
.x_nreloc
);
605 md_number_to_chars (*where
, auxP
->x_scn
.x_nlinno
, sizeof (auxP
->x_scn
.x_nlinno
));
606 *where
+= sizeof (auxP
->x_scn
.x_nlinno
);
609 #else /* CROSS_COMPILE */
610 append (where
, (char *) &symbolP
->sy_symbol
.ost_auxent
[i
], sizeof (symbolP
->sy_symbol
.ost_auxent
[i
]));
611 #endif /* CROSS_COMPILE */
613 }; /* for each aux in use */
614 #endif /* BFD_HEADERS */
619 obj_coff_section_header_append (where
, header
)
621 struct internal_scnhdr
*header
;
623 *where
+= bfd_coff_swap_scnhdr_out (stdoutput
, header
, *where
);
628 obj_coff_section_header_append (where
, header
)
633 memcpy (*where
, header
->s_name
, sizeof (header
->s_name
));
634 *where
+= sizeof (header
->s_name
);
636 md_number_to_chars (*where
, header
->s_paddr
, sizeof (header
->s_paddr
));
637 *where
+= sizeof (header
->s_paddr
);
639 md_number_to_chars (*where
, header
->s_vaddr
, sizeof (header
->s_vaddr
));
640 *where
+= sizeof (header
->s_vaddr
);
642 md_number_to_chars (*where
, header
->s_size
, sizeof (header
->s_size
));
643 *where
+= sizeof (header
->s_size
);
645 md_number_to_chars (*where
, header
->s_scnptr
, sizeof (header
->s_scnptr
));
646 *where
+= sizeof (header
->s_scnptr
);
648 md_number_to_chars (*where
, header
->s_relptr
, sizeof (header
->s_relptr
));
649 *where
+= sizeof (header
->s_relptr
);
651 md_number_to_chars (*where
, header
->s_lnnoptr
, sizeof (header
->s_lnnoptr
));
652 *where
+= sizeof (header
->s_lnnoptr
);
654 md_number_to_chars (*where
, header
->s_nreloc
, sizeof (header
->s_nreloc
));
655 *where
+= sizeof (header
->s_nreloc
);
657 md_number_to_chars (*where
, header
->s_nlnno
, sizeof (header
->s_nlnno
));
658 *where
+= sizeof (header
->s_nlnno
);
660 md_number_to_chars (*where
, header
->s_flags
, sizeof (header
->s_flags
));
661 *where
+= sizeof (header
->s_flags
);
664 md_number_to_chars (*where
, header
->s_align
, sizeof (header
->s_align
));
665 *where
+= sizeof (header
->s_align
);
668 #else /* CROSS_COMPILE */
670 append (where
, (char *) header
, sizeof (*header
));
672 #endif /* CROSS_COMPILE */
677 obj_emit_symbols (where
, symbol_rootP
)
679 symbolS
*symbol_rootP
;
683 * Emit all symbols left in the symbol chain.
685 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
687 /* Used to save the offset of the name. It is used to point
688 to the string in memory but must be a file offset. */
691 tc_coff_symbol_emit_hook (symbolP
);
693 temp
= S_GET_NAME (symbolP
);
694 if (SF_GET_STRING (symbolP
))
696 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
697 S_SET_ZEROES (symbolP
, 0);
701 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, '\0', SYMNMLEN
);
702 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
704 obj_symbol_to_chars (where
, symbolP
);
705 S_SET_NAME (symbolP
, temp
);
707 } /* obj_emit_symbols() */
709 #endif /* ! BFD_ASSEMBLER */
711 /* Merge a debug symbol containing debug information into a normal symbol. */
714 c_symbol_merge (debug
, normal
)
718 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
719 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
721 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
722 /* take the most we have */
723 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
725 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
727 /* Move all the auxiliary information. */
729 /* @@ How many fields do we want to preserve? Would it make more
730 sense to pick and choose those we want to copy? Should look
731 into this further.... [raeburn:19920512.2209EST] */
733 linenos
= coffsymbol (normal
->bsym
)->lineno
;
734 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
735 (char *) &coffsymbol (debug
->bsym
)->native
,
736 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
737 coffsymbol (normal
->bsym
)->lineno
= linenos
;
739 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
740 (char *) &debug
->sy_symbol
.ost_auxent
[0],
741 S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
);
745 /* Move the debug flags. */
746 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
749 static symbolS
*previous_file_symbol
;
751 c_dot_file_symbol (filename
)
757 symbolP
= symbol_new (filename
, &bfd_abs_section
, 0,
760 symbolP
= symbol_new (".file",
766 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
767 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
770 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
772 if (strlen(filename
) > 14)
774 /* This won't fit into a 14 char space, it will go into the string
776 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
= 0;
777 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[0] = string_byte_count
;
778 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[1] = (int)filename
;
782 SA_SET_FILE_FNAME (symbolP
, filename
);
784 SF_SET_DEBUG (symbolP
);
792 listing_source_file (filename
);
797 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
799 previous_file_symbol
= symbolP
;
801 /* Make sure that the symbol is first on the symbol chain */
802 if (symbol_rootP
!= symbolP
)
804 if (symbolP
== symbol_lastP
)
806 symbol_lastP
= symbol_lastP
->sy_previous
;
807 } /* if it was the last thing on the list */
809 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
810 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
811 symbol_rootP
= symbolP
;
812 } /* if not first on the list */
816 * Build a 'section static' symbol.
820 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
824 unsigned short nreloc
;
825 unsigned short nlnno
;
829 symbolP
= symbol_new (name
,
838 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
839 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
841 SA_SET_SCN_SCNLEN (symbolP
, length
);
842 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
843 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
845 SF_SET_STATICS (symbolP
);
847 return (char *) symbolP
;
850 #ifndef BFD_ASSEMBLER
852 c_section_header (header
,
863 struct internal_scnhdr
*header
;
877 strncpy (header
->s_name
, name
, 8);
878 header
->s_paddr
= header
->s_vaddr
= core_address
;
879 header
->s_scnptr
= ((header
->s_size
= size
) != 0) ? data_ptr
: 0;
880 header
->s_relptr
= reloc_ptr
;
881 header
->s_lnnoptr
= lineno_ptr
;
882 header
->s_nreloc
= reloc_number
;
883 header
->s_nlnno
= lineno_number
;
885 #ifdef OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT
886 #ifdef OBJ_COFF_BROKEN_ALIGNMENT
887 header
->s_align
= ((name
[1] == 'b' || (size
> 0)) ? 16 : 0);
889 header
->s_align
= ((alignment
== 0)
892 #endif /* OBJ_COFF_BROKEN_ALIGNMENT */
893 #endif /* OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT */
895 header
->s_flags
= STYP_REG
| (name
[1] == 't'
905 /* Line number handling */
911 /* Symbol of last function, which we should hang line#s off of. */
912 static symbolS
*line_fsym
;
914 #define in_function() (line_fsym != 0)
915 #define clear_function() (line_fsym = 0)
916 #define set_function(F) (line_fsym = (F), add_linesym (F))
920 /* Offset in line#s where the last function started (the odd entry for
922 static int function_lineoff
= -1;
924 #define in_function() (function_lineoff >= 0)
925 #define clear_function() (function_lineoff = -1)
926 #define set_function(F) (function_lineoff = c_line_new ((long) (F), 0, &zero_address_frag))
928 int text_lineno_number
;
930 /* We use this to build pointers from .bf's into the linetable. It
931 should match exactly the values that are later assigned in
932 text_lineno_number by write.c. */
933 int our_lineno_number
;
935 lineno
*lineno_rootP
;
936 lineno
*lineno_lastP
;
939 c_line_new (paddr
, line_number
, frag
)
941 unsigned short line_number
;
944 lineno
*new_line
= (lineno
*) xmalloc (sizeof (lineno
));
946 new_line
->line
.l_addr
.l_paddr
= paddr
;
947 new_line
->line
.l_lnno
= line_number
;
948 new_line
->frag
= (char *) frag
;
949 new_line
->next
= (lineno
*) 0;
951 if (lineno_rootP
== (lineno
*) 0)
952 lineno_rootP
= new_line
;
954 lineno_lastP
->next
= new_line
;
955 lineno_lastP
= new_line
;
956 return LINESZ
* our_lineno_number
++;
960 obj_emit_lineno (where
, line
, file_start
)
966 struct bfd_internal_lineno
*line_entry
;
970 char *where2
= *where
;
972 for (; line
; line
= line
->next
)
974 line_entry
= &line
->line
;
976 /* FIXME-SOMEDAY Resolving the sy_number of function linno's used to be
977 done in write_object_file() but their symbols need a fileptr to the
978 lnno, so I moved this resolution check here. xoxorich. */
980 if (line_entry
->l_lnno
== 0)
982 /* There is a good chance that the symbol pointed to
983 is not the one that will be emitted and that the
984 sy_number is not accurate. */
987 symbolP
= (symbolS
*) line_entry
->l_addr
.l_symndx
;
989 line_entry
->l_addr
.l_symndx
= symbolP
->sy_number
;
990 symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= where2
- file_start
;
993 where2
+= bfd_coff_swap_lineno_out (stdoutput
, line_entry
, where2
);
995 /* No matter which member of the union we process, they are
997 md_number_to_chars (where2
, line_entry
->l_addr
.l_paddr
, sizeof (line_entry
->l_addr
.l_paddr
));
998 where2
+= sizeof (line_entry
->l_addr
.l_paddr
);
1000 md_number_to_chars (where2
, line_entry
->l_lnno
, sizeof (line_entry
->l_lnno
));
1001 where2
+= sizeof (line_entry
->l_lnno
);
1006 #endif /* TC_I960 */
1008 #endif /* BFD_HEADERS */
1013 #endif /* ! BFD_ASSEMBLER */
1017 obj_symbol_new_hook (symbolP
)
1020 char underscore
= 0; /* Symbol has leading _ */
1022 #ifdef BFD_ASSEMBLER
1024 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
1025 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
1027 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
1030 /* Effective symbol */
1031 /* Store the pointer in the offset. */
1032 S_SET_ZEROES (symbolP
, 0L);
1033 /* Additional information */
1034 symbolP
->sy_symbol
.ost_flags
= 0;
1035 /* Auxiliary entries */
1036 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], '\0', AUXESZ
);
1038 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1039 S_SET_STORAGE_CLASS (symbolP
, 0);
1040 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1042 #ifdef STRIP_UNDERSCORE
1043 /* Remove leading underscore at the beginning of the symbol.
1044 This is to be compatible with the standard librairies. */
1045 if (*S_GET_NAME (symbolP
) == '_')
1048 S_SET_NAME (symbolP
, S_GET_NAME (symbolP
) + 1);
1050 #endif /* STRIP_UNDERSCORE */
1052 if (S_IS_STRING (symbolP
))
1053 SF_SET_STRING (symbolP
);
1054 if (!underscore
&& S_IS_LOCAL (symbolP
))
1055 SF_SET_LOCAL (symbolP
);
1061 stack_init (chunk_size
, element_size
)
1062 unsigned long chunk_size
;
1063 unsigned long element_size
;
1067 st
= (stack
*) malloc (sizeof (stack
));
1070 st
->data
= malloc (chunk_size
);
1077 st
->size
= chunk_size
;
1078 st
->chunk_size
= chunk_size
;
1079 st
->element_size
= element_size
;
1092 stack_push (st
, element
)
1096 if (st
->pointer
+ st
->element_size
>= st
->size
)
1098 st
->size
+= st
->chunk_size
;
1099 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
1102 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
1103 st
->pointer
+= st
->element_size
;
1104 return st
->data
+ st
->pointer
;
1111 if (st
->pointer
< st
->element_size
)
1116 st
->pointer
-= st
->element_size
;
1117 return st
->data
+ st
->pointer
;
1124 return st
->data
+ st
->pointer
- st
->element_size
;
1129 * Handle .ln directives.
1132 #ifdef BFD_ASSEMBLER
1133 static symbolS
*current_lineno_sym
;
1134 static struct line_no
*line_nos
;
1137 add_lineno (frag
, offset
, num
)
1142 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
1143 sizeof (struct line_no
));
1144 if (!current_lineno_sym
)
1148 new_line
->next
= line_nos
;
1149 new_line
->frag
= frag
;
1150 new_line
->l
.line_number
= num
;
1151 new_line
->l
.u
.offset
= offset
;
1152 line_nos
= new_line
;
1161 add_lineno (0, 0, 0);
1162 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
1165 current_lineno_sym
= sym
;
1170 obj_coff_ln (appline
)
1175 if (! appline
&& def_symbol_in_progress
!= NULL
)
1177 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1178 demand_empty_rest_of_line ();
1182 l
= get_absolute_expression ();
1185 #ifdef BFD_ASSEMBLER
1186 add_lineno (frag_now
, frag_now_fix (), l
);
1188 c_line_new (frag_now_fix (), l
, frag_now
);
1200 listing_source_line (l
);
1205 demand_empty_rest_of_line ();
1211 * Handle .def directives.
1213 * One might ask : why can't we symbol_new if the symbol does not
1214 * already exist and fill it with debug information. Because of
1215 * the C_EFCN special symbol. It would clobber the value of the
1216 * function symbol before we have a chance to notice that it is
1217 * a C_EFCN. And a second reason is that the code is more clear this
1218 * way. (at least I think it is :-).
1222 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1223 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1224 *input_line_pointer == '\t') \
1225 input_line_pointer++;
1231 char name_end
; /* Char after the end of name */
1232 char *symbol_name
; /* Name of the debug symbol */
1233 char *symbol_name_copy
; /* Temporary copy of the name */
1234 unsigned int symbol_name_length
;
1236 if (def_symbol_in_progress
!= NULL
)
1238 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1239 demand_empty_rest_of_line ();
1241 } /* if not inside .def/.endef */
1243 SKIP_WHITESPACES ();
1245 symbol_name
= input_line_pointer
;
1246 #ifdef STRIP_UNDERSCORE
1247 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
1249 #endif /* STRIP_UNDERSCORE */
1251 name_end
= get_symbol_end ();
1252 symbol_name_length
= strlen (symbol_name
);
1253 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
1254 strcpy (symbol_name_copy
, symbol_name
);
1256 /* Initialize the new symbol */
1257 #ifdef BFD_ASSEMBLER
1258 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
1260 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1261 memset (def_symbol_in_progress
, '\0', sizeof (*def_symbol_in_progress
));
1263 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
1264 def_symbol_in_progress
->sy_name_offset
= ~0;
1265 def_symbol_in_progress
->sy_number
= ~0;
1268 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
1269 S_SET_VALUE (def_symbol_in_progress
, 0);
1271 if (S_IS_STRING (def_symbol_in_progress
))
1272 SF_SET_STRING (def_symbol_in_progress
);
1274 *input_line_pointer
= name_end
;
1276 demand_empty_rest_of_line ();
1279 unsigned int dim_index
;
1282 obj_coff_endef (ignored
)
1286 /* DIM BUG FIX sac@cygnus.com */
1288 if (def_symbol_in_progress
== NULL
)
1290 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
1291 demand_empty_rest_of_line ();
1293 } /* if not inside .def/.endef */
1295 /* Set the section number according to storage class. */
1296 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
1301 SF_SET_TAG (def_symbol_in_progress
);
1302 /* intentional fallthrough */
1305 SF_SET_DEBUG (def_symbol_in_progress
);
1306 #ifdef BFD_ASSEMBLER
1307 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
1309 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
1314 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
1315 /* intentional fallthrough */
1317 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
1318 /* intentional fallthrough */
1322 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
1324 #ifdef BFD_ASSEMBLER
1325 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
1327 name
= def_symbol_in_progress
->sy_symbol
.ost_entry
._n
._n_nptr
[1];
1329 if (name
[1] == 'b' && name
[2] == 'f')
1331 if (! in_function ())
1332 as_warn ("`%s' symbol without preceding function", name
);
1333 #ifdef BFD_ASSEMBLER
1334 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
1336 SA_GET_SYM_LNNOPTR (def_symbol_in_progress
) = function_lineoff
;
1338 /* Will need relocating */
1339 SF_SET_PROCESS (def_symbol_in_progress
);
1347 #endif /* C_AUTOARG */
1357 SF_SET_DEBUG (def_symbol_in_progress
);
1358 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
1364 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
1370 as_warn ("unexpected storage class %d",
1371 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
1373 } /* switch on storage class */
1375 /* Now that we have built a debug symbol, try to find if we should
1376 merge with an existing symbol or not. If a symbol is C_EFCN or
1377 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
1379 /* Two cases for functions. Either debug followed by definition or
1380 definition followed by debug. For definition first, we will
1381 merge the debug symbol into the definition. For debug first, the
1382 lineno entry MUST point to the definition function or else it
1383 will point off into space when obj_crawl_symbol_chain() merges
1384 the debug symbol into the real symbol. Therefor, let's presume
1385 the debug symbol is a real function reference. */
1387 /* FIXME-SOON If for some reason the definition label/symbol is
1388 never seen, this will probably leave an undefined symbol at link
1391 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
1392 #ifdef BFD_ASSEMBLER
1393 || (!strcmp (bfd_get_section_name (stdoutput
,
1394 S_GET_SEGMENT (def_symbol_in_progress
)),
1396 && !SF_GET_TAG (def_symbol_in_progress
))
1398 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
1399 && !SF_GET_TAG (def_symbol_in_progress
))
1401 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
1402 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
1404 #ifdef BFD_ASSEMBLER
1405 if (def_symbol_in_progress
!= symbol_lastP
)
1406 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1409 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1415 /* This symbol already exists, merge the newly created symbol
1416 into the old one. This is not mandatory. The linker can
1417 handle duplicate symbols correctly. But I guess that it save
1418 a *lot* of space if the assembly file defines a lot of
1421 /* The debug entry (def_symbol_in_progress) is merged into the
1422 previous definition. */
1424 c_symbol_merge (def_symbol_in_progress
, symbolP
);
1425 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
1426 def_symbol_in_progress
= symbolP
;
1428 if (SF_GET_FUNCTION (def_symbol_in_progress
)
1429 || SF_GET_TAG (def_symbol_in_progress
))
1431 /* For functions, and tags, the symbol *must* be where the
1432 debug symbol appears. Move the existing symbol to the
1434 /* If it already is at the end of the symbol list, do nothing */
1435 if (def_symbol_in_progress
!= symbol_lastP
)
1437 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
1438 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1443 if (SF_GET_TAG (def_symbol_in_progress
)
1444 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
1446 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
1449 if (SF_GET_FUNCTION (def_symbol_in_progress
))
1451 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
1452 set_function (def_symbol_in_progress
);
1453 SF_SET_PROCESS (def_symbol_in_progress
);
1455 if (symbolP
== NULL
)
1457 /* That is, if this is the first time we've seen the
1459 symbol_table_insert (def_symbol_in_progress
);
1460 } /* definition follows debug */
1461 } /* Create the line number entry pointing to the function being defined */
1463 def_symbol_in_progress
= NULL
;
1464 demand_empty_rest_of_line ();
1468 obj_coff_dim (ignored
)
1473 if (def_symbol_in_progress
== NULL
)
1475 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
1476 demand_empty_rest_of_line ();
1478 } /* if not inside .def/.endef */
1480 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1482 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
1484 SKIP_WHITESPACES ();
1485 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
1486 get_absolute_expression ());
1488 switch (*input_line_pointer
)
1491 input_line_pointer
++;
1495 as_warn ("badly formed .dim directive ignored");
1496 /* intentional fallthrough */
1504 demand_empty_rest_of_line ();
1508 obj_coff_line (ignored
)
1513 if (def_symbol_in_progress
== NULL
)
1515 /* Probably stabs-style line? */
1520 this_base
= get_absolute_expression ();
1521 if (this_base
> line_base
)
1522 line_base
= this_base
;
1524 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1525 SA_SET_SYM_LNNO (def_symbol_in_progress
, line_base
);
1527 demand_empty_rest_of_line ();
1531 obj_coff_size (ignored
)
1534 if (def_symbol_in_progress
== NULL
)
1536 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
1537 demand_empty_rest_of_line ();
1539 } /* if not inside .def/.endef */
1541 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1542 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
1543 demand_empty_rest_of_line ();
1547 obj_coff_scl (ignored
)
1550 if (def_symbol_in_progress
== NULL
)
1552 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
1553 demand_empty_rest_of_line ();
1555 } /* if not inside .def/.endef */
1557 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1558 demand_empty_rest_of_line ();
1562 obj_coff_tag (ignored
)
1568 if (def_symbol_in_progress
== NULL
)
1570 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
1571 demand_empty_rest_of_line ();
1575 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1576 symbol_name
= input_line_pointer
;
1577 name_end
= get_symbol_end ();
1579 /* Assume that the symbol referred to by .tag is always defined.
1580 This was a bad assumption. I've added find_or_make. xoxorich. */
1581 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1582 tag_find_or_make (symbol_name
));
1583 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1585 as_warn ("tag not found for .tag %s", symbol_name
);
1588 SF_SET_TAGGED (def_symbol_in_progress
);
1589 *input_line_pointer
= name_end
;
1591 demand_empty_rest_of_line ();
1595 obj_coff_type (ignored
)
1598 if (def_symbol_in_progress
== NULL
)
1600 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
1601 demand_empty_rest_of_line ();
1603 } /* if not inside .def/.endef */
1605 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1607 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1608 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1610 SF_SET_FUNCTION (def_symbol_in_progress
);
1611 } /* is a function */
1613 demand_empty_rest_of_line ();
1617 obj_coff_val (ignored
)
1620 if (def_symbol_in_progress
== NULL
)
1622 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
1623 demand_empty_rest_of_line ();
1625 } /* if not inside .def/.endef */
1627 if (is_name_beginner (*input_line_pointer
))
1629 char *symbol_name
= input_line_pointer
;
1630 char name_end
= get_symbol_end ();
1632 if (!strcmp (symbol_name
, "."))
1634 def_symbol_in_progress
->sy_frag
= frag_now
;
1635 S_SET_VALUE (def_symbol_in_progress
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
1636 /* If the .val is != from the .def (e.g. statics) */
1638 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1640 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
1641 def_symbol_in_progress
->sy_value
.X_add_symbol
=
1642 symbol_find_or_make (symbol_name
);
1643 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
1644 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
1646 /* If the segment is undefined when the forward reference is
1647 resolved, then copy the segment id from the forward
1649 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1651 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
1652 *input_line_pointer
= name_end
;
1656 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1657 } /* if symbol based */
1659 demand_empty_rest_of_line ();
1663 * Maintain a list of the tagnames of the structres.
1669 tag_hash
= hash_new ();
1673 tag_insert (name
, symbolP
)
1677 const char *error_string
;
1679 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
1681 as_fatal ("Inserting \"%s\" into structure table failed: %s",
1682 name
, error_string
);
1687 tag_find_or_make (name
)
1692 if ((symbolP
= tag_find (name
)) == NULL
)
1694 symbolP
= symbol_new (name
, undefined_section
,
1695 0, &zero_address_frag
);
1697 tag_insert (S_GET_NAME (symbolP
), symbolP
);
1698 symbol_table_insert (symbolP
);
1708 #ifdef STRIP_UNDERSCORE
1711 #endif /* STRIP_UNDERSCORE */
1712 return (symbolS
*) hash_find (tag_hash
, name
);
1716 obj_read_begin_hook ()
1718 /* These had better be the same. Usually 18 bytes. */
1720 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1721 know (SYMESZ
== AUXESZ
);
1726 #ifndef BFD_ASSEMBLER
1728 obj_crawl_symbol_chain (headers
)
1729 object_headers
*headers
;
1731 int symbol_number
= 0;
1733 symbolS
*last_functionP
= NULL
;
1736 symbolS
*symbol_externP
= NULL
;
1737 symbolS
*symbol_extern_lastP
= NULL
;
1739 /* Initialize the stack used to keep track of the matching .bb .be */
1740 stack
*block_stack
= stack_init (512, sizeof (symbolS
*));
1742 tc_crawl_symbol_chain (headers
);
1744 /* The symbol list should be ordered according to the following sequence
1747 * . debug entries for functions
1748 * . fake symbols for .text .data and .bss
1750 * . undefined symbols
1751 * But this is not mandatory. The only important point is to put the
1752 * undefined symbols at the end of the list.
1755 if (symbol_rootP
== NULL
1756 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1758 know (!previous_file_symbol
);
1759 c_dot_file_symbol ("fake");
1760 } /* Is there a .file symbol? If not, insert one at the beginning. */
1763 * Build up static symbols for .text, .data and .bss
1765 dot_text_symbol
= (symbolS
*) c_section_symbol (".text",
1767 H_GET_TEXT_SIZE (headers
),
1768 0 /*text_relocation_number*/,
1769 0 /*text_lineno_number */);
1771 symbol_remove (dot_text_symbol
, &symbol_rootP
, &symbol_lastP
);
1772 symbol_append (dot_text_symbol
, previous_file_symbol
,
1773 &symbol_rootP
, &symbol_lastP
);
1774 #endif /* TE_I386AIX */
1776 dot_data_symbol
= (symbolS
*)
1777 c_section_symbol (".data",
1778 H_GET_TEXT_SIZE (headers
),
1779 H_GET_DATA_SIZE (headers
),
1780 0 /*data_relocation_number */ ,
1781 0); /* There are no data lineno entries */
1783 symbol_remove (dot_data_symbol
, &symbol_rootP
, &symbol_lastP
);
1784 symbol_append (dot_data_symbol
, dot_text_symbol
,
1785 &symbol_rootP
, &symbol_lastP
);
1786 #endif /* TE_I386AIX */
1788 dot_bss_symbol
= (symbolS
*)
1789 c_section_symbol (".bss",
1790 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
1791 H_GET_BSS_SIZE (headers
),
1792 0, /* No relocation for a bss section. */
1793 0); /* There are no bss lineno entries */
1795 symbol_remove (dot_bss_symbol
, &symbol_rootP
, &symbol_lastP
);
1796 symbol_append (dot_bss_symbol
, dot_data_symbol
,
1797 &symbol_rootP
, &symbol_lastP
);
1798 #endif /* TE_I386AIX */
1801 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
1804 /* Three traversals of symbol chains here. The
1805 first traversal yanks externals into a temporary
1806 chain, removing the externals from the global
1807 chain, numbers symbols, and does some other guck.
1808 The second traversal is on the temporary chain of
1809 externals and just appends them to the global
1810 chain again, numbering them as we go. The third
1811 traversal patches pointers to symbols (using sym
1812 indexes). The last traversal was once done as
1813 part of the first pass, but that fails when a
1814 reference preceeds a definition as the definition
1815 has no number at the time we process the
1818 /* Note that symbolP will be NULL at the end of a loop
1819 if an external was at the beginning of the list (it
1820 gets moved off the list). Hence the weird check in
1823 for (symbolP
= symbol_rootP
;
1825 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
1827 if (!SF_GET_DEBUG (symbolP
))
1829 /* Debug symbols do not need all this rubbish */
1830 symbolS
*real_symbolP
;
1832 /* L* and C_EFCN symbols never merge. */
1833 if (!SF_GET_LOCAL (symbolP
)
1834 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
1835 && real_symbolP
!= symbolP
)
1837 /* FIXME-SOON: where do dups come from? Maybe tag references before definitions? xoxorich. */
1838 /* Move the debug data from the debug symbol to the
1839 real symbol. Do NOT do the oposite (i.e. move from
1840 real symbol to debug symbol and remove real symbol from the
1841 list.) Because some pointers refer to the real symbol
1842 whereas no pointers refer to the debug symbol. */
1843 c_symbol_merge (symbolP
, real_symbolP
);
1844 /* Replace the current symbol by the real one */
1845 /* The symbols will never be the last or the first
1846 because : 1st symbol is .file and 3 last symbols are
1847 .text, .data, .bss */
1848 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
1849 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
1850 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1851 symbolP
= real_symbolP
;
1852 } /* if not local but dup'd */
1854 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
1856 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
1857 } /* push data into text */
1859 resolve_symbol_value (symbolP
);
1861 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
1863 S_SET_EXTERNAL (symbolP
);
1865 else if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
1867 if (S_GET_SEGMENT (symbolP
) == SEG_TEXT
)
1869 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
1873 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1875 } /* no storage class yet */
1877 /* Mainly to speed up if not -g */
1878 if (SF_GET_PROCESS (symbolP
))
1880 /* Handle the nested blocks auxiliary info. */
1881 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
1883 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
1884 stack_push (block_stack
, (char *) &symbolP
);
1887 register symbolS
*begin_symbolP
;
1888 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
1889 if (begin_symbolP
== (symbolS
*) 0)
1890 as_warn ("mismatched .eb");
1892 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
1895 /* If we are able to identify the type of a function, and we
1896 are out of a function (last_functionP == 0) then, the
1897 function symbol will be associated with an auxiliary
1899 if (last_functionP
== (symbolS
*) 0 &&
1900 SF_GET_FUNCTION (symbolP
))
1902 last_functionP
= symbolP
;
1904 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
1906 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1907 } /* make it at least 1 */
1909 /* Clobber possible stale .dim information. */
1910 memset (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
1911 '\0', sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
1913 /* The C_FCN doesn't need any additional information.
1914 I don't even know if this is needed for sdb. But the
1915 standard assembler generates it, so...
1917 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
1919 if (last_functionP
== (symbolS
*) 0)
1920 as_fatal ("C_EFCN symbol out of scope");
1921 SA_SET_SYM_FSIZE (last_functionP
,
1922 (long) (S_GET_VALUE (symbolP
) -
1923 S_GET_VALUE (last_functionP
)));
1924 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
1925 last_functionP
= (symbolS
*) 0;
1929 else if (SF_GET_TAG (symbolP
))
1931 /* First descriptor of a structure must point to
1932 the first slot after the structure description. */
1933 last_tagP
= symbolP
;
1936 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
1938 /* +2 take in account the current symbol */
1939 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
1941 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
1943 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
1945 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
= string_byte_count
;
1946 string_byte_count
+=
1947 strlen(GET_FILENAME_STRING(symbolP
)) + 1;
1952 if (S_GET_VALUE (symbolP
))
1954 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symbolP
), symbol_number
);
1955 S_SET_VALUE (symbolP
, 0);
1956 } /* no one points at the first .file symbol */
1957 } /* if debug or tag or eos or file */
1959 /* We must put the external symbols apart. The loader
1960 does not bomb if we do not. But the references in
1961 the endndx field for a .bb symbol are not corrected
1962 if an external symbol is removed between .bb and .be.
1963 I.e in the following case :
1964 [20] .bb endndx = 22
1967 ld will move the symbol 21 to the end of the list but
1968 endndx will still be 22 instead of 21. */
1970 if (SF_GET_LOCAL (symbolP
))
1972 /* remove C_EFCN and LOCAL (L...) symbols */
1973 /* next pointer remains valid */
1974 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1979 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
1980 && !SF_GET_FUNCTION (symbolP
)
1981 #else /* not TE_I386AIX */
1982 !S_IS_DEFINED (symbolP
)
1983 && !S_IS_DEBUG (symbolP
)
1984 && !SF_GET_STATICS (symbolP
)
1985 #endif /* not TE_I386AIX */
1988 /* if external, Remove from the list */
1989 symbolS
*hold
= symbol_previous (symbolP
);
1991 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1992 symbol_clear_list_pointers (symbolP
);
1993 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
1998 if (SF_GET_STRING (symbolP
))
2000 symbolP
->sy_name_offset
= string_byte_count
;
2001 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2005 symbolP
->sy_name_offset
= 0;
2006 } /* fix "long" names */
2008 symbolP
->sy_number
= symbol_number
;
2009 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2010 } /* if local symbol */
2011 } /* traverse the symbol list */
2013 for (symbolP
= symbol_externP
; symbol_externP
;)
2015 symbolS
*tmp
= symbol_externP
;
2018 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2019 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2022 if (SF_GET_STRING (tmp
))
2024 tmp
->sy_name_offset
= string_byte_count
;
2025 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2029 tmp
->sy_name_offset
= 0;
2030 } /* fix "long" names */
2032 tmp
->sy_number
= symbol_number
;
2033 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2034 } /* append the entire extern chain */
2036 /* When a tag reference preceeds the tag definition, the definition
2037 will not have a number at the time we process the reference
2038 during the first traversal. Thus, a second traversal. */
2040 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2042 if (SF_GET_TAGGED (symbolP
))
2044 SA_SET_SYM_TAGNDX (symbolP
, ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2048 know (symbol_externP
== NULL
);
2049 know (symbol_extern_lastP
== NULL
);
2051 /* FIXME-SOMEDAY I'm counting line no's here so we know what to put
2052 in the section headers, and I'm resolving the addresses since I'm
2053 not sure how to do it later. I am NOT resolving the linno's
2054 representing functions. Their symbols need a fileptr pointing to
2055 this linno when emitted. Thus, I resolve them on emit.
2058 for (lineP
= lineno_rootP
; lineP
; lineP
= lineP
->next
)
2060 if (lineP
->line
.l_lnno
> 0)
2062 lineP
->line
.l_addr
.l_paddr
+= ((fragS
*) lineP
->frag
)->fr_address
;
2068 text_lineno_number
++;
2069 } /* for each line number */
2071 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
2075 * Find strings by crawling along symbol table chain.
2079 obj_emit_strings (where
)
2084 #ifdef CROSS_COMPILE
2085 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2086 md_number_to_chars (*where
, string_byte_count
, sizeof (string_byte_count
));
2087 *where
+= sizeof (string_byte_count
);
2088 #else /* CROSS_COMPILE */
2089 append (where
, (char *) &string_byte_count
, (unsigned long) sizeof (string_byte_count
));
2090 #endif /* CROSS_COMPILE */
2092 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2094 if (S_GET_STORAGE_CLASS(symbolP
) == C_FILE
)
2096 /* May need special treatment for this auxent */
2097 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
2099 char *p
= GET_FILENAME_STRING(symbolP
);
2101 (where
,p
, strlen(p
)+1);
2104 if (SF_GET_STRING (symbolP
))
2106 append (where
, S_GET_NAME (symbolP
),
2107 (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
2108 } /* if it has a string */
2109 } /* walk the symbol chain */
2113 obj_pre_write_hook (headers
)
2114 object_headers
*headers
;
2116 register int text_relocation_number
= 0;
2117 register int data_relocation_number
= 0;
2118 register fixS
*fixP
;
2120 /* FIXME-SOMEDAY this should be done at fixup_segment time but I'm
2121 going to wait until I do multiple segments. xoxorich. */
2122 /* Count the number of relocation entries for text and data */
2123 for (fixP
= text_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2127 ++text_relocation_number
;
2129 /* two relocs per callj under coff. */
2132 ++text_relocation_number
;
2133 } /* if callj and not already fixed. */
2134 #endif /* TC_I960 */
2136 /* Count 2 for a constH */
2137 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2139 ++text_relocation_number
;
2142 } /* if not yet fixed */
2143 } /* for each fix */
2145 SA_SET_SCN_NRELOC (dot_text_symbol
, text_relocation_number
);
2146 /* Assign the number of line number entries for the text section */
2147 SA_SET_SCN_NLINNO (dot_text_symbol
, text_lineno_number
);
2148 /* Assign the size of the section */
2149 SA_SET_SCN_SCNLEN (dot_text_symbol
, H_GET_TEXT_SIZE (headers
));
2151 for (fixP
= data_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2155 ++data_relocation_number
;
2156 } /* if still relocatable */
2158 /* Count 2 for a constH */
2159 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2161 ++data_relocation_number
;
2166 SA_SET_SCN_NRELOC (dot_data_symbol
, data_relocation_number
);
2167 /* Assign the size of the section */
2168 SA_SET_SCN_SCNLEN (dot_data_symbol
, H_GET_DATA_SIZE (headers
));
2170 /* Assign the size of the section */
2171 SA_SET_SCN_SCNLEN (dot_bss_symbol
, H_GET_BSS_SIZE (headers
));
2173 /* pre write hook can add relocs (for 960 and 29k coff) so */
2174 headers
->relocation_size
= text_relocation_number
* RELSZ
+
2175 data_relocation_number
* RELSZ
;
2179 /* Fill in extra coff fields */
2181 /* Initialize general line number information. */
2182 H_SET_LINENO_SIZE (headers
, text_lineno_number
* LINESZ
);
2185 H_SET_FILE_MAGIC_NUMBER (headers
, FILE_HEADER_MAGIC
);
2186 H_SET_NUMBER_OF_SECTIONS (headers
, 3); /* text+data+bss */
2187 #ifndef OBJ_COFF_OMIT_TIMESTAMP
2188 H_SET_TIME_STAMP (headers
, (long) time ((long *) 0));
2189 #else /* OBJ_COFF_OMIT_TIMESTAMP */
2190 H_SET_TIME_STAMP (headers
, 0);
2191 #endif /* OBJ_COFF_OMIT_TIMESTAMP */
2192 H_SET_SYMBOL_TABLE_POINTER (headers
, H_GET_SYMBOL_TABLE_FILE_OFFSET (headers
));
2194 printf ("FILHSZ %x\n", FILHSZ
);
2195 printf ("OBJ_COFF_AOUTHDRSZ %x\n", OBJ_COFF_AOUTHDRSZ
);
2196 printf ("section headers %x\n", H_GET_NUMBER_OF_SECTIONS (headers
) * SCNHSZ
);
2197 printf ("get text size %x\n", H_GET_TEXT_SIZE (headers
));
2198 printf ("get data size %x\n", H_GET_DATA_SIZE (headers
));
2199 printf ("get relocation size %x\n", H_GET_RELOCATION_SIZE (headers
));
2200 printf ("get lineno size %x\n", H_GET_LINENO_SIZE (headers
));
2202 /* symbol table size allready set */
2203 H_SET_SIZEOF_OPTIONAL_HEADER (headers
, OBJ_COFF_AOUTHDRSZ
);
2205 /* Do not added the F_RELFLG for the standard COFF. The AIX linker
2206 complain on file with relocation info striped flag. */
2207 #ifdef KEEP_RELOC_INFO
2208 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2211 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2212 | ((text_relocation_number
+ data_relocation_number
) ? 0 : F_RELFLG
)
2216 /* magic number allready set */
2217 H_SET_VERSION_STAMP (headers
, 0);
2218 /* Text, data, bss size; entry point; text_start and data_start are already set */
2220 /* Build section headers */
2222 c_section_header (&text_section_header
,
2225 H_GET_TEXT_SIZE (headers
),
2226 H_GET_TEXT_FILE_OFFSET (headers
),
2227 (SA_GET_SCN_NRELOC (dot_text_symbol
)
2228 ? H_GET_RELOCATION_FILE_OFFSET (headers
)
2231 ? H_GET_LINENO_FILE_OFFSET (headers
)
2233 SA_GET_SCN_NRELOC (dot_text_symbol
),
2235 section_alignment
[(int) SEG_TEXT
]);
2237 c_section_header (&data_section_header
,
2239 H_GET_TEXT_SIZE (headers
),
2240 H_GET_DATA_SIZE (headers
),
2241 (H_GET_DATA_SIZE (headers
)
2242 ? H_GET_DATA_FILE_OFFSET (headers
)
2244 (SA_GET_SCN_NRELOC (dot_data_symbol
)
2245 ? (H_GET_RELOCATION_FILE_OFFSET (headers
)
2246 + text_section_header
.s_nreloc
* RELSZ
)
2248 0, /* No line number information */
2249 SA_GET_SCN_NRELOC (dot_data_symbol
),
2250 0, /* No line number information */
2251 section_alignment
[(int) SEG_DATA
]);
2253 c_section_header (&bss_section_header
,
2255 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
2256 H_GET_BSS_SIZE (headers
),
2257 0, /* No file offset */
2258 0, /* No relocation information */
2259 0, /* No line number information */
2260 0, /* No relocation information */
2261 0, /* No line number information */
2262 section_alignment
[(int) SEG_BSS
]);
2266 #ifdef BFD_ASSEMBLER
2269 coff_frob_symbol (symp
, punt
)
2273 static symbolS
*last_functionP
, *last_tagP
;
2274 static stack
*block_stack
;
2276 if (current_lineno_sym
)
2277 add_linesym ((symbolS
*) 0);
2280 block_stack
= stack_init (512, sizeof (symbolS
*));
2282 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
2283 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2285 if (!SF_GET_DEBUG (symp
))
2288 if (!SF_GET_LOCAL (symp
)
2289 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
2292 c_symbol_merge (symp
, real
);
2295 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
2297 assert (S_GET_VALUE (symp
) == 0);
2298 S_SET_EXTERNAL (symp
);
2300 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
2302 if (S_GET_SEGMENT (symp
) == text_section
)
2303 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
2305 S_SET_STORAGE_CLASS (symp
, C_STAT
);
2307 if (SF_GET_PROCESS (symp
))
2309 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
2311 if (!strcmp (S_GET_NAME (symp
), ".bb"))
2312 stack_push (block_stack
, (char *) &symp
);
2316 begin
= *(symbolS
**) stack_pop (block_stack
);
2318 as_warn ("mismatched .eb");
2320 SA_SET_SYM_ENDNDX (begin
, begin
);
2323 if (last_functionP
== 0 && SF_GET_FUNCTION (symp
))
2325 union internal_auxent
*auxp
;
2326 last_functionP
= symp
;
2327 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
2328 S_SET_NUMBER_AUXILIARY (symp
, 1);
2329 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
2330 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
2331 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
2333 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
2335 if (last_functionP
== 0)
2336 as_fatal ("C_EFCN symbol out of scope");
2337 SA_SET_SYM_FSIZE (last_functionP
,
2338 (long) (S_GET_VALUE (symp
)
2339 - S_GET_VALUE (last_functionP
)));
2340 SA_SET_SYM_ENDNDX (last_functionP
, symp
);
2344 else if (SF_GET_TAG (symp
))
2346 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
2347 SA_SET_SYM_ENDNDX (last_tagP
, symp
);
2348 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
2350 if (S_GET_VALUE (symp
))
2352 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
2353 S_SET_VALUE (symp
, 0);
2356 if (S_IS_EXTERNAL (symp
))
2357 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2358 else if (SF_GET_LOCAL (symp
))
2362 if (coffsymbol (symp
->bsym
)->lineno
)
2365 struct line_no
*lptr
;
2368 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2369 for (i
= 0; lptr
; lptr
= lptr
->next
)
2372 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2373 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, n
* sizeof (alent
));
2374 coffsymbol (symp
->bsym
)->lineno
= l
;
2375 for (i
= n
- 1; i
> 0; i
--)
2378 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
2386 DEFUN_VOID(obj_coff_section
)
2388 /* Strip out the section name */
2389 char *section_name
;
2390 char *section_name_end
;
2396 section_name
= input_line_pointer
;
2397 c
= get_symbol_end();
2398 section_name_end
= input_line_pointer
;
2400 len
= section_name_end
- section_name
;
2401 input_line_pointer
++;
2404 exp
= get_absolute_expression();
2405 else if (*input_line_pointer
== ',')
2407 input_line_pointer
++;
2408 exp
= get_absolute_expression();
2415 *section_name_end
= c
;
2421 if (symbol_rootP
== NULL
2422 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2424 assert (previous_file_symbol
== 0);
2425 c_dot_file_symbol ("fake");
2428 #endif /* BFD_ASSEMBLER */
2436 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
2437 } /* s_get_name() */
2444 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2446 #ifdef BFD_ASSEMBLER
2447 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
2448 (unsigned long) symbolP
,
2449 S_GET_NAME(symbolP
),
2450 (long) S_GET_DATA_TYPE(symbolP
),
2451 S_GET_STORAGE_CLASS(symbolP
),
2452 (int) S_GET_SEGMENT(symbolP
));
2454 printf ("%3ld: 0x%lx \"%s\" type = %ld, class = %d, segment = %d\n",
2456 (unsigned long) symbolP
,
2457 S_GET_NAME (symbolP
),
2458 (long) S_GET_DATA_TYPE (symbolP
),
2459 S_GET_STORAGE_CLASS (symbolP
),
2460 (int) S_GET_SEGMENT (symbolP
));
2467 /* end of obj-coff.c */