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
));
65 static void obj_coff_section_header_append
PARAMS ((char **where
, struct internal_scnhdr
* header
));
67 static void obj_coff_section_header_append
PARAMS ((char **where
, SCNHDR
* header
));
69 static void obj_coff_def
PARAMS ((int what
));
70 static void obj_coff_dim
PARAMS ((int));
71 static void obj_coff_endef
PARAMS ((int));
72 static void obj_coff_line
PARAMS ((int));
73 static void obj_coff_ln
PARAMS ((int));
74 static void obj_coff_scl
PARAMS ((int));
75 static void obj_coff_size
PARAMS ((int));
76 static void obj_coff_tag
PARAMS ((int));
77 static void obj_coff_type
PARAMS ((int));
78 static void obj_coff_val
PARAMS ((int));
79 static void tag_init
PARAMS ((void));
80 static void tag_insert
PARAMS ((const char *name
, symbolS
* symbolP
));
83 static void SA_SET_SYM_ENDNDX
PARAMS ((symbolS
*, symbolS
*));
84 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
87 static struct hash_control
*tag_hash
;
88 static symbolS
*def_symbol_in_progress
;
90 static symbolS
*dot_text_symbol
;
91 static symbolS
*dot_data_symbol
;
92 static symbolS
*dot_bss_symbol
;
94 const pseudo_typeS obj_pseudo_table
[] =
97 {"def", obj_coff_def
, 0},
98 {"dim", obj_coff_dim
, 0},
99 {"endef", obj_coff_endef
, 0},
100 {"line", obj_coff_line
, 0},
101 {"ln", obj_coff_ln
, 0},
102 {"appline", obj_coff_ln
, 1},
103 {"scl", obj_coff_scl
, 0},
104 {"size", obj_coff_size
, 0},
105 {"tag", obj_coff_tag
, 0},
106 {"type", obj_coff_type
, 0},
107 {"val", obj_coff_val
, 0},
109 {"def", s_ignore
, 0},
110 {"dim", s_ignore
, 0},
111 {"endef", s_ignore
, 0},
112 {"line", s_ignore
, 0},
114 {"scl", s_ignore
, 0},
115 {"size", s_ignore
, 0},
116 {"tag", s_ignore
, 0},
117 {"type", s_ignore
, 0},
118 {"val", s_ignore
, 0},
119 #endif /* ignore debug */
121 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
123 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
125 {"ABORT", s_abort
, 0},
127 {NULL
} /* end sentinel */
128 }; /* obj_pseudo_table */
132 struct line_no
*next
;
138 #define GET_FILENAME_STRING(X) \
139 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
141 /* obj dependant output values */
142 #ifndef BFD_ASSEMBLER
144 static struct internal_scnhdr bss_section_header
;
145 struct internal_scnhdr data_section_header
;
146 struct internal_scnhdr text_section_header
;
148 static SCNHDR bss_section_header
;
149 SCNHDR data_section_header
;
150 SCNHDR text_section_header
;
158 fetch_coff_debug_section ()
160 static segT debug_section
;
164 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
166 debug_section
= s
->section
;
168 return debug_section
;
172 SA_SET_SYM_ENDNDX (sym
, val
)
176 combined_entry_type
*entry
, *p
;
178 entry
= &coffsymbol (sym
->bsym
)->native
[1];
179 p
= coffsymbol (val
->bsym
)->native
;
180 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
185 SA_SET_SYM_TAGNDX (sym
, val
)
189 combined_entry_type
*entry
, *p
;
191 entry
= &coffsymbol (sym
->bsym
)->native
[1];
192 p
= coffsymbol (val
->bsym
)->native
;
193 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
198 S_GET_DATA_TYPE (sym
)
201 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
205 S_SET_DATA_TYPE (sym
, val
)
209 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
214 S_GET_STORAGE_CLASS (sym
)
217 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
221 S_SET_STORAGE_CLASS (sym
, val
)
225 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
229 #else /* ! BFD_ASSEMBLER */
234 reloc_compare (p1
, p2
)
236 struct internal_reloc
*p1
, *p2
;
241 return (int) (p1
->r_vaddr
- p2
->r_vaddr
);
247 * Crawl along a fixS chain. Emit the segment's relocations.
251 obj_emit_relocations (where
, fixP
, segment_address_in_file
)
253 fixS
*fixP
; /* Fixup chain for this segment. */
254 relax_addressT segment_address_in_file
;
257 struct internal_reloc
*ri_table
;
268 for (count
= 0, p
= fixP
; p
; p
= p
->fx_next
)
275 ri_table
= (struct internal_reloc
*) calloc (sizeof (*ri_table
), count
);
277 ri_table
= (RELOC
*) calloc (sizeof (*ri_table
), count
);
280 as_fatal ("obj_emit_relocations: Could not malloc relocation table");
283 callj_table
= (char *) malloc (sizeof (char) * count
);
285 as_fatal ("obj_emit_relocations: Could not malloc callj table");
288 for (i
= 0; fixP
; fixP
= fixP
->fx_next
)
290 symbolP
= fixP
->fx_addsy
;
295 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
296 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
297 fixP
->fx_size
== 2 ? R_PCRWORD
:
299 (fixP
->fx_size
== 1 ? R_RELBYTE
:
300 fixP
->fx_size
== 2 ? R_RELWORD
:
305 /* FIXME-SOON R_OFF8 & R_DIR16 are a vague guess, completly
307 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
308 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
309 fixP
->fx_size
== 2 ? R_PCRWORD
:
311 (fixP
->fx_size
== 1 ? R_OFF8
:
312 fixP
->fx_size
== 2 ? R_DIR16
:
317 ri_table
[i
].r_type
= (fixP
->fx_pcrel
320 callj_table
[i
] = fixP
->fx_tcbit
? 1 : 0;
324 ri_table
[i
].r_type
= tc_coff_fix2rtype (fixP
);
329 ri_table
[i
].r_vaddr
= (fixP
->fx_frag
->fr_address
331 /* If symbol associated to relocation entry is a bss symbol
332 or undefined symbol just remember the index of the symbol.
333 Otherwise store the index of the symbol describing the
334 section the symbol belong to. This heuristic speeds up ld.
336 /* Local symbols can generate relocation information. In case
337 of structure return for instance. But they have no symbol
338 number because they won't be emitted in the final object.
339 In the case where they are in the BSS section, this leads
340 to an incorrect r_symndx.
341 Under bsd the loader do not care if the symbol reference
342 is incorrect. But the SYS V ld complains about this. To
343 avoid this we associate the symbol to the associated
344 section, *even* if it is the BSS section. */
345 /* If someone can tell me why the other symbols of the bss
346 section are not associated with the .bss section entry,
347 I'd be gratefull. I guess that it has to do with the special
348 nature of the .bss section. Or maybe this is because the
349 bss symbols are declared in the common section and can
350 be resized later. Can it break code some where ? */
351 ri_table
[i
].r_symndx
= (S_GET_SEGMENT (symbolP
) == SEG_TEXT
352 ? dot_text_symbol
->sy_number
353 : (S_GET_SEGMENT (symbolP
) == SEG_DATA
354 ? dot_data_symbol
->sy_number
355 : ((SF_GET_LOCAL (symbolP
)
356 ? dot_bss_symbol
->sy_number
357 : symbolP
->sy_number
)))); /* bss or undefined */
359 /* md_ri_to_chars((char *) &ri, ri); *//* Last step : write md f */
362 } /* if there's a symbol */
363 } /* for each fixP */
365 /* AIX ld prefer to have the reloc table with r_vaddr sorted.
366 But sorting it should not hurt any other ld. */
367 qsort (ri_table
, count
, sizeof (*ri_table
), reloc_compare
);
369 for (i
= 0; i
< count
; i
++)
372 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
], *where
);
374 /* The 29k has a special kludge for the high 16 bit reloc.
375 Two relocations are emmited, R_IHIHALF, and R_IHCONST.
376 The second one doesn't contain a symbol, but uses the
378 if (ri_table
[i
].r_type
== R_IHIHALF
)
380 /* now emit the second bit */
381 ri_table
[i
].r_type
= R_IHCONST
;
382 ri_table
[i
].r_symndx
= fixP
->fx_addnumber
;
383 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
386 # endif /* TC_A29K */
388 #else /* not BFD_HEADERS */
389 append (where
, (char *) &ri_table
[i
], RELSZ
);
390 #endif /* not BFD_HEADERS */
395 ri_table
[i
].r_type
= R_OPTCALL
;
397 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
400 append (where
, (char *) &ri_table
[i
], (unsigned long) RELSZ
);
401 # endif /* BFD_HEADERS */
402 } /* if it's a callj, do it again for the opcode */
412 /* Coff file generation & utilities */
416 obj_header_append (where
, headers
)
418 object_headers
*headers
;
420 tc_headers_hook (headers
);
421 *where
+= bfd_coff_swap_filehdr_out (stdoutput
, &(headers
->filehdr
), *where
);
422 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
423 *where
+= bfd_coff_swap_aouthdr_out (stdoutput
, &(headers
->aouthdr
), *where
);
425 obj_coff_section_header_append (where
, &text_section_header
);
426 obj_coff_section_header_append (where
, &data_section_header
);
427 obj_coff_section_header_append (where
, &bss_section_header
);
430 #else /* ! BFD_HEADERS */
433 obj_header_append (where
, headers
)
435 object_headers
*headers
;
437 tc_headers_hook (headers
);
440 /* Eventually swap bytes for cross compilation for file header */
441 md_number_to_chars (*where
, headers
->filehdr
.f_magic
, sizeof (headers
->filehdr
.f_magic
));
442 *where
+= sizeof (headers
->filehdr
.f_magic
);
443 md_number_to_chars (*where
, headers
->filehdr
.f_nscns
, sizeof (headers
->filehdr
.f_nscns
));
444 *where
+= sizeof (headers
->filehdr
.f_nscns
);
445 md_number_to_chars (*where
, headers
->filehdr
.f_timdat
, sizeof (headers
->filehdr
.f_timdat
));
446 *where
+= sizeof (headers
->filehdr
.f_timdat
);
447 md_number_to_chars (*where
, headers
->filehdr
.f_symptr
, sizeof (headers
->filehdr
.f_symptr
));
448 *where
+= sizeof (headers
->filehdr
.f_symptr
);
449 md_number_to_chars (*where
, headers
->filehdr
.f_nsyms
, sizeof (headers
->filehdr
.f_nsyms
));
450 *where
+= sizeof (headers
->filehdr
.f_nsyms
);
451 md_number_to_chars (*where
, headers
->filehdr
.f_opthdr
, sizeof (headers
->filehdr
.f_opthdr
));
452 *where
+= sizeof (headers
->filehdr
.f_opthdr
);
453 md_number_to_chars (*where
, headers
->filehdr
.f_flags
, sizeof (headers
->filehdr
.f_flags
));
454 *where
+= sizeof (headers
->filehdr
.f_flags
);
456 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
457 /* Eventually swap bytes for cross compilation for a.out header */
458 md_number_to_chars (*where
, headers
->aouthdr
.magic
, sizeof (headers
->aouthdr
.magic
));
459 *where
+= sizeof (headers
->aouthdr
.magic
);
460 md_number_to_chars (*where
, headers
->aouthdr
.vstamp
, sizeof (headers
->aouthdr
.vstamp
));
461 *where
+= sizeof (headers
->aouthdr
.vstamp
);
462 md_number_to_chars (*where
, headers
->aouthdr
.tsize
, sizeof (headers
->aouthdr
.tsize
));
463 *where
+= sizeof (headers
->aouthdr
.tsize
);
464 md_number_to_chars (*where
, headers
->aouthdr
.dsize
, sizeof (headers
->aouthdr
.dsize
));
465 *where
+= sizeof (headers
->aouthdr
.dsize
);
466 md_number_to_chars (*where
, headers
->aouthdr
.bsize
, sizeof (headers
->aouthdr
.bsize
));
467 *where
+= sizeof (headers
->aouthdr
.bsize
);
468 md_number_to_chars (*where
, headers
->aouthdr
.entry
, sizeof (headers
->aouthdr
.entry
));
469 *where
+= sizeof (headers
->aouthdr
.entry
);
470 md_number_to_chars (*where
, headers
->aouthdr
.text_start
, sizeof (headers
->aouthdr
.text_start
));
471 *where
+= sizeof (headers
->aouthdr
.text_start
);
472 md_number_to_chars (*where
, headers
->aouthdr
.data_start
, sizeof (headers
->aouthdr
.data_start
));
473 *where
+= sizeof (headers
->aouthdr
.data_start
);
474 md_number_to_chars (*where
, headers
->aouthdr
.tagentries
, sizeof (headers
->aouthdr
.tagentries
));
475 *where
+= sizeof (headers
->aouthdr
.tagentries
);
476 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
478 #else /* CROSS_COMPILE */
480 append (where
, (char *) &headers
->filehdr
, sizeof (headers
->filehdr
));
481 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
482 append (where
, (char *) &headers
->aouthdr
, sizeof (headers
->aouthdr
));
483 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
485 #endif /* CROSS_COMPILE */
487 /* Output the section headers */
488 obj_coff_section_header_append (where
, &text_section_header
);
489 obj_coff_section_header_append (where
, &data_section_header
);
490 obj_coff_section_header_append (where
, &bss_section_header
);
493 #endif /* ! BFD_HEADERS */
496 obj_symbol_to_chars (where
, symbolP
)
500 /* Move the value into the COFF symbol itself. */
501 symbolP
->sy_symbol
.ost_entry
.n_value
= S_GET_VALUE (symbolP
);
504 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
507 if (S_GET_SEGMENT (symbolP
) == SEG_REGISTER
)
509 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
511 *where
+= bfd_coff_swap_sym_out (stdoutput
, &symbolP
->sy_symbol
.ost_entry
,
514 for (i
= 0; i
< numaux
; i
++)
516 *where
+= bfd_coff_swap_aux_out (stdoutput
,
517 &symbolP
->sy_symbol
.ost_auxent
[i
],
518 S_GET_DATA_TYPE (symbolP
),
519 S_GET_STORAGE_CLASS (symbolP
),
523 #else /* BFD_HEADERS */
524 SYMENT
*syment
= &symbolP
->sy_symbol
.ost_entry
;
526 char numaux
= syment
->n_numaux
;
527 unsigned short type
= S_GET_DATA_TYPE (symbolP
);
530 md_number_to_chars (*where
, syment
->n_value
, sizeof (syment
->n_value
));
531 *where
+= sizeof (syment
->n_value
);
532 md_number_to_chars (*where
, syment
->n_scnum
, sizeof (syment
->n_scnum
));
533 *where
+= sizeof (syment
->n_scnum
);
534 md_number_to_chars (*where
, 0, sizeof (short)); /* pad n_flags */
535 *where
+= sizeof (short);
536 md_number_to_chars (*where
, syment
->n_type
, sizeof (syment
->n_type
));
537 *where
+= sizeof (syment
->n_type
);
538 md_number_to_chars (*where
, syment
->n_sclass
, sizeof (syment
->n_sclass
));
539 *where
+= sizeof (syment
->n_sclass
);
540 md_number_to_chars (*where
, syment
->n_numaux
, sizeof (syment
->n_numaux
));
541 *where
+= sizeof (syment
->n_numaux
);
542 #else /* CROSS_COMPILE */
543 append (where
, (char *) syment
, sizeof (*syment
));
544 #endif /* CROSS_COMPILE */
546 /* Should do the following:
547 if (.file entry) MD(..)... else if (static entry) MD(..) */
548 if (numaux
> OBJ_COFF_MAX_AUXENTRIES
)
550 as_bad ("Internal error? too many auxents for symbol");
551 } /* too many auxents */
553 for (i
= 0; i
< numaux
; ++i
)
556 #if 0 /* This code has never been tested */
557 /* The most common case, x_sym entry. */
558 if ((SF_GET (symbolP
) & (SF_FILE
| SF_STATICS
)) == 0)
560 md_number_to_chars (*where
, auxP
->x_sym
.x_tagndx
, sizeof (auxP
->x_sym
.x_tagndx
));
561 *where
+= sizeof (auxP
->x_sym
.x_tagndx
);
564 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_fsize
, sizeof (auxP
->x_sym
.x_misc
.x_fsize
));
565 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_fsize
);
569 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_lnno
, sizeof (auxP
->x_sym
.x_misc
.x_lnno
));
570 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_lnno
);
571 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_size
, sizeof (auxP
->x_sym
.x_misc
.x_size
));
572 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_size
);
577 for (index
= 0; index
< DIMNUM
; index
++)
578 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
]));
579 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
]);
583 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
, sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
));
584 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
585 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
, sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
586 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
588 md_number_to_chars (*where
, auxP
->x_sym
.x_tvndx
, sizeof (auxP
->x_sym
.x_tvndx
));
589 *where
+= sizeof (auxP
->x_sym
.x_tvndx
);
591 else if (SF_GET_FILE (symbolP
))
595 else if (SF_GET_STATICS (symbolP
))
596 { /* .text, .data, .bss symbols */
597 md_number_to_chars (*where
, auxP
->x_scn
.x_scnlen
, sizeof (auxP
->x_scn
.x_scnlen
));
598 *where
+= sizeof (auxP
->x_scn
.x_scnlen
);
599 md_number_to_chars (*where
, auxP
->x_scn
.x_nreloc
, sizeof (auxP
->x_scn
.x_nreloc
));
600 *where
+= sizeof (auxP
->x_scn
.x_nreloc
);
601 md_number_to_chars (*where
, auxP
->x_scn
.x_nlinno
, sizeof (auxP
->x_scn
.x_nlinno
));
602 *where
+= sizeof (auxP
->x_scn
.x_nlinno
);
605 #else /* CROSS_COMPILE */
606 append (where
, (char *) &symbolP
->sy_symbol
.ost_auxent
[i
], sizeof (symbolP
->sy_symbol
.ost_auxent
[i
]));
607 #endif /* CROSS_COMPILE */
609 }; /* for each aux in use */
610 #endif /* BFD_HEADERS */
615 obj_coff_section_header_append (where
, header
)
617 struct internal_scnhdr
*header
;
619 *where
+= bfd_coff_swap_scnhdr_out (stdoutput
, header
, *where
);
624 obj_coff_section_header_append (where
, header
)
629 memcpy (*where
, header
->s_name
, sizeof (header
->s_name
));
630 *where
+= sizeof (header
->s_name
);
632 md_number_to_chars (*where
, header
->s_paddr
, sizeof (header
->s_paddr
));
633 *where
+= sizeof (header
->s_paddr
);
635 md_number_to_chars (*where
, header
->s_vaddr
, sizeof (header
->s_vaddr
));
636 *where
+= sizeof (header
->s_vaddr
);
638 md_number_to_chars (*where
, header
->s_size
, sizeof (header
->s_size
));
639 *where
+= sizeof (header
->s_size
);
641 md_number_to_chars (*where
, header
->s_scnptr
, sizeof (header
->s_scnptr
));
642 *where
+= sizeof (header
->s_scnptr
);
644 md_number_to_chars (*where
, header
->s_relptr
, sizeof (header
->s_relptr
));
645 *where
+= sizeof (header
->s_relptr
);
647 md_number_to_chars (*where
, header
->s_lnnoptr
, sizeof (header
->s_lnnoptr
));
648 *where
+= sizeof (header
->s_lnnoptr
);
650 md_number_to_chars (*where
, header
->s_nreloc
, sizeof (header
->s_nreloc
));
651 *where
+= sizeof (header
->s_nreloc
);
653 md_number_to_chars (*where
, header
->s_nlnno
, sizeof (header
->s_nlnno
));
654 *where
+= sizeof (header
->s_nlnno
);
656 md_number_to_chars (*where
, header
->s_flags
, sizeof (header
->s_flags
));
657 *where
+= sizeof (header
->s_flags
);
660 md_number_to_chars (*where
, header
->s_align
, sizeof (header
->s_align
));
661 *where
+= sizeof (header
->s_align
);
664 #else /* CROSS_COMPILE */
666 append (where
, (char *) header
, sizeof (*header
));
668 #endif /* CROSS_COMPILE */
673 obj_emit_symbols (where
, symbol_rootP
)
675 symbolS
*symbol_rootP
;
679 * Emit all symbols left in the symbol chain.
681 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
683 /* Used to save the offset of the name. It is used to point
684 to the string in memory but must be a file offset. */
687 tc_coff_symbol_emit_hook (symbolP
);
689 temp
= S_GET_NAME (symbolP
);
690 if (SF_GET_STRING (symbolP
))
692 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
693 S_SET_ZEROES (symbolP
, 0);
697 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, '\0', SYMNMLEN
);
698 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
700 obj_symbol_to_chars (where
, symbolP
);
701 S_SET_NAME (symbolP
, temp
);
703 } /* obj_emit_symbols() */
705 #endif /* ! BFD_ASSEMBLER */
707 /* Merge a debug symbol containing debug information into a normal symbol. */
710 c_symbol_merge (debug
, normal
)
714 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
715 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
717 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
718 /* take the most we have */
719 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
721 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
723 /* Move all the auxiliary information. */
725 /* @@ How many fields do we want to preserve? Would it make more
726 sense to pick and choose those we want to copy? Should look
727 into this further.... [raeburn:19920512.2209EST] */
729 linenos
= coffsymbol (normal
->bsym
)->lineno
;
730 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
731 (char *) &coffsymbol (debug
->bsym
)->native
,
732 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
733 coffsymbol (normal
->bsym
)->lineno
= linenos
;
735 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
736 (char *) &debug
->sy_symbol
.ost_auxent
[0],
737 S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
);
741 /* Move the debug flags. */
742 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
745 static symbolS
*previous_file_symbol
;
747 c_dot_file_symbol (filename
)
753 symbolP
= symbol_new (filename
, &bfd_abs_section
, 0,
756 symbolP
= symbol_new (".file",
762 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
763 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
766 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
768 if (strlen(filename
) > 14)
770 /* This won't fit into a 14 char space, it will go into the string
772 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
= 0;
773 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[0] = string_byte_count
;
774 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[1] = (int)filename
;
778 SA_SET_FILE_FNAME (symbolP
, filename
);
780 SF_SET_DEBUG (symbolP
);
788 listing_source_file (filename
);
793 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
795 previous_file_symbol
= symbolP
;
797 /* Make sure that the symbol is first on the symbol chain */
798 if (symbol_rootP
!= symbolP
)
800 if (symbolP
== symbol_lastP
)
802 symbol_lastP
= symbol_lastP
->sy_previous
;
803 } /* if it was the last thing on the list */
805 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
806 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
807 symbol_rootP
= symbolP
;
808 } /* if not first on the list */
812 * Build a 'section static' symbol.
816 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
820 unsigned short nreloc
;
821 unsigned short nlnno
;
825 symbolP
= symbol_new (name
,
834 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
835 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
837 SA_SET_SCN_SCNLEN (symbolP
, length
);
838 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
839 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
841 SF_SET_STATICS (symbolP
);
843 return (char *) symbolP
;
846 #ifndef BFD_ASSEMBLER
848 c_section_header (header
,
859 struct internal_scnhdr
*header
;
873 strncpy (header
->s_name
, name
, 8);
874 header
->s_paddr
= header
->s_vaddr
= core_address
;
875 header
->s_scnptr
= ((header
->s_size
= size
) != 0) ? data_ptr
: 0;
876 header
->s_relptr
= reloc_ptr
;
877 header
->s_lnnoptr
= lineno_ptr
;
878 header
->s_nreloc
= reloc_number
;
879 header
->s_nlnno
= lineno_number
;
881 #ifdef OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT
882 #ifdef OBJ_COFF_BROKEN_ALIGNMENT
883 header
->s_align
= ((name
[1] == 'b' || (size
> 0)) ? 16 : 0);
885 header
->s_align
= ((alignment
== 0)
888 #endif /* OBJ_COFF_BROKEN_ALIGNMENT */
889 #endif /* OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT */
891 header
->s_flags
= STYP_REG
| (name
[1] == 't'
901 /* Line number handling */
907 /* Symbol of last function, which we should hang line#s off of. */
908 static symbolS
*line_fsym
;
910 #define in_function() (line_fsym != 0)
911 #define clear_function() (line_fsym = 0)
912 #define set_function(F) (line_fsym = (F), add_linesym (F))
916 /* Offset in line#s where the last function started (the odd entry for
918 static int function_lineoff
= -1;
920 #define in_function() (function_lineoff >= 0)
921 #define clear_function() (function_lineoff = -1)
922 #define set_function(F) (function_lineoff = c_line_new ((long) (F), 0, &zero_address_frag))
924 int text_lineno_number
;
926 /* We use this to build pointers from .bf's into the linetable. It
927 should match exactly the values that are later assigned in
928 text_lineno_number by write.c. */
929 int our_lineno_number
;
931 lineno
*lineno_rootP
;
932 lineno
*lineno_lastP
;
935 c_line_new (paddr
, line_number
, frag
)
937 unsigned short line_number
;
940 lineno
*new_line
= (lineno
*) xmalloc (sizeof (lineno
));
942 new_line
->line
.l_addr
.l_paddr
= paddr
;
943 new_line
->line
.l_lnno
= line_number
;
944 new_line
->frag
= (char *) frag
;
945 new_line
->next
= (lineno
*) 0;
947 if (lineno_rootP
== (lineno
*) 0)
948 lineno_rootP
= new_line
;
950 lineno_lastP
->next
= new_line
;
951 lineno_lastP
= new_line
;
952 return LINESZ
* our_lineno_number
++;
956 obj_emit_lineno (where
, line
, file_start
)
962 struct bfd_internal_lineno
*line_entry
;
966 char *where2
= *where
;
968 for (; line
; line
= line
->next
)
970 line_entry
= &line
->line
;
972 /* FIXME-SOMEDAY Resolving the sy_number of function linno's used to be
973 done in write_object_file() but their symbols need a fileptr to the
974 lnno, so I moved this resolution check here. xoxorich. */
976 if (line_entry
->l_lnno
== 0)
978 /* There is a good chance that the symbol pointed to
979 is not the one that will be emitted and that the
980 sy_number is not accurate. */
983 symbolP
= (symbolS
*) line_entry
->l_addr
.l_symndx
;
985 line_entry
->l_addr
.l_symndx
= symbolP
->sy_number
;
986 symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= where2
- file_start
;
989 where2
+= bfd_coff_swap_lineno_out (stdoutput
, line_entry
, where2
);
991 /* No matter which member of the union we process, they are
993 md_number_to_chars (where2
, line_entry
->l_addr
.l_paddr
, sizeof (line_entry
->l_addr
.l_paddr
));
994 where2
+= sizeof (line_entry
->l_addr
.l_paddr
);
996 md_number_to_chars (where2
, line_entry
->l_lnno
, sizeof (line_entry
->l_lnno
));
997 where2
+= sizeof (line_entry
->l_lnno
);
1002 #endif /* TC_I960 */
1004 #endif /* BFD_HEADERS */
1009 #endif /* ! BFD_ASSEMBLER */
1013 obj_symbol_new_hook (symbolP
)
1016 char underscore
= 0; /* Symbol has leading _ */
1018 #ifdef BFD_ASSEMBLER
1020 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
1021 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
1023 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
1026 /* Effective symbol */
1027 /* Store the pointer in the offset. */
1028 S_SET_ZEROES (symbolP
, 0L);
1029 /* Additional information */
1030 symbolP
->sy_symbol
.ost_flags
= 0;
1031 /* Auxiliary entries */
1032 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], '\0', AUXESZ
);
1034 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1035 S_SET_STORAGE_CLASS (symbolP
, 0);
1036 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1038 #ifdef STRIP_UNDERSCORE
1039 /* Remove leading underscore at the beginning of the symbol.
1040 This is to be compatible with the standard librairies. */
1041 if (*S_GET_NAME (symbolP
) == '_')
1044 S_SET_NAME (symbolP
, S_GET_NAME (symbolP
) + 1);
1046 #endif /* STRIP_UNDERSCORE */
1048 if (S_IS_STRING (symbolP
))
1049 SF_SET_STRING (symbolP
);
1050 if (!underscore
&& S_IS_LOCAL (symbolP
))
1051 SF_SET_LOCAL (symbolP
);
1057 stack_init (chunk_size
, element_size
)
1058 unsigned long chunk_size
;
1059 unsigned long element_size
;
1063 st
= (stack
*) malloc (sizeof (stack
));
1066 st
->data
= malloc (chunk_size
);
1073 st
->size
= chunk_size
;
1074 st
->chunk_size
= chunk_size
;
1075 st
->element_size
= element_size
;
1088 stack_push (st
, element
)
1092 if (st
->pointer
+ st
->element_size
>= st
->size
)
1094 st
->size
+= st
->chunk_size
;
1095 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
1098 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
1099 st
->pointer
+= st
->element_size
;
1100 return st
->data
+ st
->pointer
;
1107 if ((st
->pointer
-= st
->element_size
) < 0)
1112 return st
->data
+ st
->pointer
;
1119 return st
->data
+ st
->pointer
- st
->element_size
;
1124 * Handle .ln directives.
1127 #ifdef BFD_ASSEMBLER
1128 static symbolS
*current_lineno_sym
;
1129 static struct line_no
*line_nos
;
1132 add_lineno (frag
, offset
, num
)
1137 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
1138 sizeof (struct line_no
));
1139 if (!current_lineno_sym
)
1143 new_line
->next
= line_nos
;
1144 new_line
->frag
= frag
;
1145 new_line
->l
.line_number
= num
;
1146 new_line
->l
.u
.offset
= offset
;
1147 line_nos
= new_line
;
1156 add_lineno (0, 0, 0);
1157 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
1160 current_lineno_sym
= sym
;
1165 obj_coff_ln (appline
)
1170 if (! appline
&& def_symbol_in_progress
!= NULL
)
1172 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1173 demand_empty_rest_of_line ();
1177 l
= get_absolute_expression ();
1180 #ifdef BFD_ASSEMBLER
1181 add_lineno (frag_now
, frag_now_fix (), l
);
1183 c_line_new (frag_now_fix (), l
, frag_now
);
1195 listing_source_line (l
);
1200 demand_empty_rest_of_line ();
1206 * Handle .def directives.
1208 * One might ask : why can't we symbol_new if the symbol does not
1209 * already exist and fill it with debug information. Because of
1210 * the C_EFCN special symbol. It would clobber the value of the
1211 * function symbol before we have a chance to notice that it is
1212 * a C_EFCN. And a second reason is that the code is more clear this
1213 * way. (at least I think it is :-).
1217 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1218 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1219 *input_line_pointer == '\t') \
1220 input_line_pointer++;
1226 char name_end
; /* Char after the end of name */
1227 char *symbol_name
; /* Name of the debug symbol */
1228 char *symbol_name_copy
; /* Temporary copy of the name */
1229 unsigned int symbol_name_length
;
1231 if (def_symbol_in_progress
!= NULL
)
1233 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1234 demand_empty_rest_of_line ();
1236 } /* if not inside .def/.endef */
1238 SKIP_WHITESPACES ();
1240 symbol_name
= input_line_pointer
;
1241 #ifdef STRIP_UNDERSCORE
1242 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
1244 #endif /* STRIP_UNDERSCORE */
1246 name_end
= get_symbol_end ();
1247 symbol_name_length
= strlen (symbol_name
);
1248 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
1249 strcpy (symbol_name_copy
, symbol_name
);
1251 /* Initialize the new symbol */
1252 #ifdef BFD_ASSEMBLER
1253 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
1255 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1256 memset (def_symbol_in_progress
, '\0', sizeof (*def_symbol_in_progress
));
1258 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
1259 def_symbol_in_progress
->sy_name_offset
= ~0;
1260 def_symbol_in_progress
->sy_number
= ~0;
1263 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
1264 S_SET_VALUE (def_symbol_in_progress
, 0);
1266 if (S_IS_STRING (def_symbol_in_progress
))
1267 SF_SET_STRING (def_symbol_in_progress
);
1269 *input_line_pointer
= name_end
;
1271 demand_empty_rest_of_line ();
1274 unsigned int dim_index
;
1276 obj_coff_endef (ignored
)
1279 /* DIM BUG FIX sac@cygnus.com */
1281 if (def_symbol_in_progress
== NULL
)
1283 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
1284 demand_empty_rest_of_line ();
1286 } /* if not inside .def/.endef */
1288 /* Set the section number according to storage class. */
1289 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
1294 SF_SET_TAG (def_symbol_in_progress
);
1295 /* intentional fallthrough */
1298 SF_SET_DEBUG (def_symbol_in_progress
);
1299 #ifdef BFD_ASSEMBLER
1300 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
1302 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
1307 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
1308 /* intentional fallthrough */
1310 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
1311 /* intentional fallthrough */
1315 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
1317 #ifdef BFD_ASSEMBLER
1318 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
1320 name
= def_symbol_in_progress
->sy_symbol
.ost_entry
._n
._n_nptr
[1];
1322 if (name
[1] == 'b' && name
[2] == 'f')
1324 if (! in_function ())
1325 as_warn ("`%s' symbol without preceding function", name
);
1326 #ifdef BFD_ASSEMBLER
1327 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
1329 SA_GET_SYM_LNNOPTR (def_symbol_in_progress
) = function_lineoff
;
1331 /* Will need relocating */
1332 SF_SET_PROCESS (def_symbol_in_progress
);
1340 #endif /* C_AUTOARG */
1350 SF_SET_DEBUG (def_symbol_in_progress
);
1351 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
1357 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
1363 as_warn ("unexpected storage class %d",
1364 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
1366 } /* switch on storage class */
1368 /* Now that we have built a debug symbol, try to find if we should
1369 merge with an existing symbol or not. If a symbol is C_EFCN or
1370 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
1372 /* Two cases for functions. Either debug followed by definition or
1373 definition followed by debug. For definition first, we will
1374 merge the debug symbol into the definition. For debug first, the
1375 lineno entry MUST point to the definition function or else it
1376 will point off into space when obj_crawl_symbol_chain() merges
1377 the debug symbol into the real symbol. Therefor, let's presume
1378 the debug symbol is a real function reference. */
1380 /* FIXME-SOON If for some reason the definition label/symbol is
1381 never seen, this will probably leave an undefined symbol at link
1384 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
1385 #ifdef BFD_ASSEMBLER
1386 || (!strcmp (bfd_get_section_name (stdoutput
,
1387 S_GET_SEGMENT (def_symbol_in_progress
)),
1389 && !SF_GET_TAG (def_symbol_in_progress
))
1391 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
1392 && !SF_GET_TAG (def_symbol_in_progress
))
1394 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
1395 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
1397 #ifdef BFD_ASSEMBLER
1398 if (def_symbol_in_progress
!= symbol_lastP
)
1399 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1402 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1408 /* This symbol already exists, merge the newly created symbol
1409 into the old one. This is not mandatory. The linker can
1410 handle duplicate symbols correctly. But I guess that it save
1411 a *lot* of space if the assembly file defines a lot of
1414 /* The debug entry (def_symbol_in_progress) is merged into the
1415 previous definition. */
1417 c_symbol_merge (def_symbol_in_progress
, symbolP
);
1418 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
1419 def_symbol_in_progress
= symbolP
;
1421 if (SF_GET_FUNCTION (def_symbol_in_progress
)
1422 || SF_GET_TAG (def_symbol_in_progress
))
1424 /* For functions, and tags, the symbol *must* be where the
1425 debug symbol appears. Move the existing symbol to the
1427 /* If it already is at the end of the symbol list, do nothing */
1428 if (def_symbol_in_progress
!= symbol_lastP
)
1430 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
1431 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1436 if (SF_GET_TAG (def_symbol_in_progress
)
1437 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
1439 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
1442 if (SF_GET_FUNCTION (def_symbol_in_progress
))
1444 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
1445 set_function (def_symbol_in_progress
);
1446 SF_SET_PROCESS (def_symbol_in_progress
);
1448 if (symbolP
== NULL
)
1450 /* That is, if this is the first time we've seen the
1452 symbol_table_insert (def_symbol_in_progress
);
1453 } /* definition follows debug */
1454 } /* Create the line number entry pointing to the function being defined */
1456 def_symbol_in_progress
= NULL
;
1457 demand_empty_rest_of_line ();
1461 obj_coff_dim (ignored
)
1465 if (def_symbol_in_progress
== NULL
)
1467 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
1468 demand_empty_rest_of_line ();
1470 } /* if not inside .def/.endef */
1472 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1474 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
1476 SKIP_WHITESPACES ();
1477 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
1478 get_absolute_expression ());
1480 switch (*input_line_pointer
)
1483 input_line_pointer
++;
1487 as_warn ("badly formed .dim directive ignored");
1488 /* intentional fallthrough */
1496 demand_empty_rest_of_line ();
1500 obj_coff_line (ignored
)
1504 if (def_symbol_in_progress
== NULL
)
1506 /* Probably stabs-style line? */
1511 this_base
= get_absolute_expression ();
1512 if (this_base
> line_base
)
1513 line_base
= this_base
;
1515 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1516 SA_SET_SYM_LNNO (def_symbol_in_progress
, line_base
);
1518 demand_empty_rest_of_line ();
1522 obj_coff_size (ignored
)
1524 if (def_symbol_in_progress
== NULL
)
1526 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
1527 demand_empty_rest_of_line ();
1529 } /* if not inside .def/.endef */
1531 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1532 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
1533 demand_empty_rest_of_line ();
1537 obj_coff_scl (ignored
)
1539 if (def_symbol_in_progress
== NULL
)
1541 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
1542 demand_empty_rest_of_line ();
1544 } /* if not inside .def/.endef */
1546 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1547 demand_empty_rest_of_line ();
1551 obj_coff_tag (ignored
)
1556 if (def_symbol_in_progress
== NULL
)
1558 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
1559 demand_empty_rest_of_line ();
1563 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1564 symbol_name
= input_line_pointer
;
1565 name_end
= get_symbol_end ();
1567 /* Assume that the symbol referred to by .tag is always defined.
1568 This was a bad assumption. I've added find_or_make. xoxorich. */
1569 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1570 tag_find_or_make (symbol_name
));
1571 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1573 as_warn ("tag not found for .tag %s", symbol_name
);
1576 SF_SET_TAGGED (def_symbol_in_progress
);
1577 *input_line_pointer
= name_end
;
1579 demand_empty_rest_of_line ();
1583 obj_coff_type (ignored
)
1585 if (def_symbol_in_progress
== NULL
)
1587 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
1588 demand_empty_rest_of_line ();
1590 } /* if not inside .def/.endef */
1592 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1594 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1595 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1597 SF_SET_FUNCTION (def_symbol_in_progress
);
1598 } /* is a function */
1600 demand_empty_rest_of_line ();
1604 obj_coff_val (ignored
)
1606 if (def_symbol_in_progress
== NULL
)
1608 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
1609 demand_empty_rest_of_line ();
1611 } /* if not inside .def/.endef */
1613 if (is_name_beginner (*input_line_pointer
))
1615 char *symbol_name
= input_line_pointer
;
1616 char name_end
= get_symbol_end ();
1618 if (!strcmp (symbol_name
, "."))
1620 def_symbol_in_progress
->sy_frag
= frag_now
;
1621 S_SET_VALUE (def_symbol_in_progress
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
1622 /* If the .val is != from the .def (e.g. statics) */
1624 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1626 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
1627 def_symbol_in_progress
->sy_value
.X_add_symbol
=
1628 symbol_find_or_make (symbol_name
);
1629 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
1630 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
1632 /* If the segment is undefined when the forward reference is
1633 resolved, then copy the segment id from the forward
1635 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1637 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
1638 *input_line_pointer
= name_end
;
1642 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1643 } /* if symbol based */
1645 demand_empty_rest_of_line ();
1649 * Maintain a list of the tagnames of the structres.
1655 tag_hash
= hash_new ();
1659 tag_insert (name
, symbolP
)
1663 const char *error_string
;
1665 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
1667 as_fatal ("Inserting \"%s\" into structure table failed: %s",
1668 name
, error_string
);
1673 tag_find_or_make (name
)
1678 if ((symbolP
= tag_find (name
)) == NULL
)
1680 symbolP
= symbol_new (name
, undefined_section
,
1681 0, &zero_address_frag
);
1683 tag_insert (S_GET_NAME (symbolP
), symbolP
);
1684 symbol_table_insert (symbolP
);
1694 #ifdef STRIP_UNDERSCORE
1697 #endif /* STRIP_UNDERSCORE */
1698 return (symbolS
*) hash_find (tag_hash
, name
);
1702 obj_read_begin_hook ()
1704 /* These had better be the same. Usually 18 bytes. */
1706 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1707 know (SYMESZ
== AUXESZ
);
1712 #ifndef BFD_ASSEMBLER
1714 obj_crawl_symbol_chain (headers
)
1715 object_headers
*headers
;
1717 int symbol_number
= 0;
1719 symbolS
*last_functionP
= NULL
;
1722 symbolS
*symbol_externP
= NULL
;
1723 symbolS
*symbol_extern_lastP
= NULL
;
1725 /* Initialize the stack used to keep track of the matching .bb .be */
1726 stack
*block_stack
= stack_init (512, sizeof (symbolS
*));
1728 tc_crawl_symbol_chain (headers
);
1730 /* The symbol list should be ordered according to the following sequence
1733 * . debug entries for functions
1734 * . fake symbols for .text .data and .bss
1736 * . undefined symbols
1737 * But this is not mandatory. The only important point is to put the
1738 * undefined symbols at the end of the list.
1741 if (symbol_rootP
== NULL
1742 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1744 know (!previous_file_symbol
);
1745 c_dot_file_symbol ("fake");
1746 } /* Is there a .file symbol? If not, insert one at the beginning. */
1749 * Build up static symbols for .text, .data and .bss
1751 dot_text_symbol
= (symbolS
*) c_section_symbol (".text",
1753 H_GET_TEXT_SIZE (headers
),
1754 0 /*text_relocation_number*/,
1755 0 /*text_lineno_number */);
1757 symbol_remove (dot_text_symbol
, &symbol_rootP
, &symbol_lastP
);
1758 symbol_append (dot_text_symbol
, previous_file_symbol
,
1759 &symbol_rootP
, &symbol_lastP
);
1760 #endif /* TE_I386AIX */
1762 dot_data_symbol
= (symbolS
*)
1763 c_section_symbol (".data",
1764 H_GET_TEXT_SIZE (headers
),
1765 H_GET_DATA_SIZE (headers
),
1766 0 /*data_relocation_number */ ,
1767 0); /* There are no data lineno entries */
1769 symbol_remove (dot_data_symbol
, &symbol_rootP
, &symbol_lastP
);
1770 symbol_append (dot_data_symbol
, dot_text_symbol
,
1771 &symbol_rootP
, &symbol_lastP
);
1772 #endif /* TE_I386AIX */
1774 dot_bss_symbol
= (symbolS
*)
1775 c_section_symbol (".bss",
1776 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
1777 H_GET_BSS_SIZE (headers
),
1778 0, /* No relocation for a bss section. */
1779 0); /* There are no bss lineno entries */
1781 symbol_remove (dot_bss_symbol
, &symbol_rootP
, &symbol_lastP
);
1782 symbol_append (dot_bss_symbol
, dot_data_symbol
,
1783 &symbol_rootP
, &symbol_lastP
);
1784 #endif /* TE_I386AIX */
1787 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
1790 /* Three traversals of symbol chains here. The
1791 first traversal yanks externals into a temporary
1792 chain, removing the externals from the global
1793 chain, numbers symbols, and does some other guck.
1794 The second traversal is on the temporary chain of
1795 externals and just appends them to the global
1796 chain again, numbering them as we go. The third
1797 traversal patches pointers to symbols (using sym
1798 indexes). The last traversal was once done as
1799 part of the first pass, but that fails when a
1800 reference preceeds a definition as the definition
1801 has no number at the time we process the
1804 /* Note that symbolP will be NULL at the end of a loop
1805 if an external was at the beginning of the list (it
1806 gets moved off the list). Hence the weird check in
1809 for (symbolP
= symbol_rootP
;
1811 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
1813 if (!SF_GET_DEBUG (symbolP
))
1815 /* Debug symbols do not need all this rubbish */
1816 symbolS
*real_symbolP
;
1818 /* L* and C_EFCN symbols never merge. */
1819 if (!SF_GET_LOCAL (symbolP
)
1820 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
1821 && real_symbolP
!= symbolP
)
1823 /* FIXME-SOON: where do dups come from? Maybe tag references before definitions? xoxorich. */
1824 /* Move the debug data from the debug symbol to the
1825 real symbol. Do NOT do the oposite (i.e. move from
1826 real symbol to debug symbol and remove real symbol from the
1827 list.) Because some pointers refer to the real symbol
1828 whereas no pointers refer to the debug symbol. */
1829 c_symbol_merge (symbolP
, real_symbolP
);
1830 /* Replace the current symbol by the real one */
1831 /* The symbols will never be the last or the first
1832 because : 1st symbol is .file and 3 last symbols are
1833 .text, .data, .bss */
1834 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
1835 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
1836 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1837 symbolP
= real_symbolP
;
1838 } /* if not local but dup'd */
1840 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
1842 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
1843 } /* push data into text */
1845 resolve_symbol_value (symbolP
);
1847 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
1849 S_SET_EXTERNAL (symbolP
);
1851 else if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
1853 if (S_GET_SEGMENT (symbolP
) == SEG_TEXT
)
1855 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
1859 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1861 } /* no storage class yet */
1863 /* Mainly to speed up if not -g */
1864 if (SF_GET_PROCESS (symbolP
))
1866 /* Handle the nested blocks auxiliary info. */
1867 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
1869 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
1870 stack_push (block_stack
, (char *) &symbolP
);
1873 register symbolS
*begin_symbolP
;
1874 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
1875 if (begin_symbolP
== (symbolS
*) 0)
1876 as_warn ("mismatched .eb");
1878 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
1881 /* If we are able to identify the type of a function, and we
1882 are out of a function (last_functionP == 0) then, the
1883 function symbol will be associated with an auxiliary
1885 if (last_functionP
== (symbolS
*) 0 &&
1886 SF_GET_FUNCTION (symbolP
))
1888 last_functionP
= symbolP
;
1890 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
1892 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1893 } /* make it at least 1 */
1895 /* Clobber possible stale .dim information. */
1896 memset (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
1897 '\0', sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
1899 /* The C_FCN doesn't need any additional information.
1900 I don't even know if this is needed for sdb. But the
1901 standard assembler generates it, so...
1903 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
1905 if (last_functionP
== (symbolS
*) 0)
1906 as_fatal ("C_EFCN symbol out of scope");
1907 SA_SET_SYM_FSIZE (last_functionP
,
1908 (long) (S_GET_VALUE (symbolP
) -
1909 S_GET_VALUE (last_functionP
)));
1910 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
1911 last_functionP
= (symbolS
*) 0;
1915 else if (SF_GET_TAG (symbolP
))
1917 /* First descriptor of a structure must point to
1918 the first slot after the structure description. */
1919 last_tagP
= symbolP
;
1922 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
1924 /* +2 take in account the current symbol */
1925 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
1927 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
1929 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
1931 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
= string_byte_count
;
1932 string_byte_count
+=
1933 strlen(GET_FILENAME_STRING(symbolP
)) + 1;
1938 if (S_GET_VALUE (symbolP
))
1940 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symbolP
), symbol_number
);
1941 S_SET_VALUE (symbolP
, 0);
1942 } /* no one points at the first .file symbol */
1943 } /* if debug or tag or eos or file */
1945 /* We must put the external symbols apart. The loader
1946 does not bomb if we do not. But the references in
1947 the endndx field for a .bb symbol are not corrected
1948 if an external symbol is removed between .bb and .be.
1949 I.e in the following case :
1950 [20] .bb endndx = 22
1953 ld will move the symbol 21 to the end of the list but
1954 endndx will still be 22 instead of 21. */
1956 if (SF_GET_LOCAL (symbolP
))
1958 /* remove C_EFCN and LOCAL (L...) symbols */
1959 /* next pointer remains valid */
1960 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1965 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
1966 && !SF_GET_FUNCTION (symbolP
)
1967 #else /* not TE_I386AIX */
1968 !S_IS_DEFINED (symbolP
)
1969 && !S_IS_DEBUG (symbolP
)
1970 && !SF_GET_STATICS (symbolP
)
1971 #endif /* not TE_I386AIX */
1974 /* if external, Remove from the list */
1975 symbolS
*hold
= symbol_previous (symbolP
);
1977 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1978 symbol_clear_list_pointers (symbolP
);
1979 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
1984 if (SF_GET_STRING (symbolP
))
1986 symbolP
->sy_name_offset
= string_byte_count
;
1987 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
1991 symbolP
->sy_name_offset
= 0;
1992 } /* fix "long" names */
1994 symbolP
->sy_number
= symbol_number
;
1995 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
1996 } /* if local symbol */
1997 } /* traverse the symbol list */
1999 for (symbolP
= symbol_externP
; symbol_externP
;)
2001 symbolS
*tmp
= symbol_externP
;
2004 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2005 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2008 if (SF_GET_STRING (tmp
))
2010 tmp
->sy_name_offset
= string_byte_count
;
2011 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2015 tmp
->sy_name_offset
= 0;
2016 } /* fix "long" names */
2018 tmp
->sy_number
= symbol_number
;
2019 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2020 } /* append the entire extern chain */
2022 /* When a tag reference preceeds the tag definition, the definition
2023 will not have a number at the time we process the reference
2024 during the first traversal. Thus, a second traversal. */
2026 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2028 if (SF_GET_TAGGED (symbolP
))
2030 SA_SET_SYM_TAGNDX (symbolP
, ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2034 know (symbol_externP
== NULL
);
2035 know (symbol_extern_lastP
== NULL
);
2037 /* FIXME-SOMEDAY I'm counting line no's here so we know what to put
2038 in the section headers, and I'm resolving the addresses since I'm
2039 not sure how to do it later. I am NOT resolving the linno's
2040 representing functions. Their symbols need a fileptr pointing to
2041 this linno when emitted. Thus, I resolve them on emit.
2044 for (lineP
= lineno_rootP
; lineP
; lineP
= lineP
->next
)
2046 if (lineP
->line
.l_lnno
> 0)
2048 lineP
->line
.l_addr
.l_paddr
+= ((fragS
*) lineP
->frag
)->fr_address
;
2054 text_lineno_number
++;
2055 } /* for each line number */
2057 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
2061 * Find strings by crawling along symbol table chain.
2065 obj_emit_strings (where
)
2070 #ifdef CROSS_COMPILE
2071 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2072 md_number_to_chars (*where
, string_byte_count
, sizeof (string_byte_count
));
2073 *where
+= sizeof (string_byte_count
);
2074 #else /* CROSS_COMPILE */
2075 append (where
, (char *) &string_byte_count
, (unsigned long) sizeof (string_byte_count
));
2076 #endif /* CROSS_COMPILE */
2078 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2080 if (S_GET_STORAGE_CLASS(symbolP
) == C_FILE
)
2082 /* May need special treatment for this auxent */
2083 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
2085 char *p
= GET_FILENAME_STRING(symbolP
);
2087 (where
,p
, strlen(p
)+1);
2090 if (SF_GET_STRING (symbolP
))
2092 append (where
, S_GET_NAME (symbolP
),
2093 (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
2094 } /* if it has a string */
2095 } /* walk the symbol chain */
2099 obj_pre_write_hook (headers
)
2100 object_headers
*headers
;
2102 register int text_relocation_number
= 0;
2103 register int data_relocation_number
= 0;
2104 register fixS
*fixP
;
2106 /* FIXME-SOMEDAY this should be done at fixup_segment time but I'm
2107 going to wait until I do multiple segments. xoxorich. */
2108 /* Count the number of relocation entries for text and data */
2109 for (fixP
= text_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2113 ++text_relocation_number
;
2115 /* two relocs per callj under coff. */
2118 ++text_relocation_number
;
2119 } /* if callj and not already fixed. */
2120 #endif /* TC_I960 */
2122 /* Count 2 for a constH */
2123 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2125 ++text_relocation_number
;
2128 } /* if not yet fixed */
2129 } /* for each fix */
2131 SA_SET_SCN_NRELOC (dot_text_symbol
, text_relocation_number
);
2132 /* Assign the number of line number entries for the text section */
2133 SA_SET_SCN_NLINNO (dot_text_symbol
, text_lineno_number
);
2134 /* Assign the size of the section */
2135 SA_SET_SCN_SCNLEN (dot_text_symbol
, H_GET_TEXT_SIZE (headers
));
2137 for (fixP
= data_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2141 ++data_relocation_number
;
2142 } /* if still relocatable */
2144 /* Count 2 for a constH */
2145 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2147 ++data_relocation_number
;
2152 SA_SET_SCN_NRELOC (dot_data_symbol
, data_relocation_number
);
2153 /* Assign the size of the section */
2154 SA_SET_SCN_SCNLEN (dot_data_symbol
, H_GET_DATA_SIZE (headers
));
2156 /* Assign the size of the section */
2157 SA_SET_SCN_SCNLEN (dot_bss_symbol
, H_GET_BSS_SIZE (headers
));
2159 /* pre write hook can add relocs (for 960 and 29k coff) so */
2160 headers
->relocation_size
= text_relocation_number
* RELSZ
+
2161 data_relocation_number
* RELSZ
;
2165 /* Fill in extra coff fields */
2167 /* Initialize general line number information. */
2168 H_SET_LINENO_SIZE (headers
, text_lineno_number
* LINESZ
);
2171 H_SET_FILE_MAGIC_NUMBER (headers
, FILE_HEADER_MAGIC
);
2172 H_SET_NUMBER_OF_SECTIONS (headers
, 3); /* text+data+bss */
2173 #ifndef OBJ_COFF_OMIT_TIMESTAMP
2174 H_SET_TIME_STAMP (headers
, (long) time ((long *) 0));
2175 #else /* OBJ_COFF_OMIT_TIMESTAMP */
2176 H_SET_TIME_STAMP (headers
, 0);
2177 #endif /* OBJ_COFF_OMIT_TIMESTAMP */
2178 H_SET_SYMBOL_TABLE_POINTER (headers
, H_GET_SYMBOL_TABLE_FILE_OFFSET (headers
));
2180 printf ("FILHSZ %x\n", FILHSZ
);
2181 printf ("OBJ_COFF_AOUTHDRSZ %x\n", OBJ_COFF_AOUTHDRSZ
);
2182 printf ("section headers %x\n", H_GET_NUMBER_OF_SECTIONS (headers
) * SCNHSZ
);
2183 printf ("get text size %x\n", H_GET_TEXT_SIZE (headers
));
2184 printf ("get data size %x\n", H_GET_DATA_SIZE (headers
));
2185 printf ("get relocation size %x\n", H_GET_RELOCATION_SIZE (headers
));
2186 printf ("get lineno size %x\n", H_GET_LINENO_SIZE (headers
));
2188 /* symbol table size allready set */
2189 H_SET_SIZEOF_OPTIONAL_HEADER (headers
, OBJ_COFF_AOUTHDRSZ
);
2191 /* Do not added the F_RELFLG for the standard COFF. The AIX linker
2192 complain on file with relocation info striped flag. */
2193 #ifdef KEEP_RELOC_INFO
2194 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2197 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2198 | ((text_relocation_number
+ data_relocation_number
) ? 0 : F_RELFLG
)
2202 /* magic number allready set */
2203 H_SET_VERSION_STAMP (headers
, 0);
2204 /* Text, data, bss size; entry point; text_start and data_start are already set */
2206 /* Build section headers */
2208 c_section_header (&text_section_header
,
2211 H_GET_TEXT_SIZE (headers
),
2212 H_GET_TEXT_FILE_OFFSET (headers
),
2213 (SA_GET_SCN_NRELOC (dot_text_symbol
)
2214 ? H_GET_RELOCATION_FILE_OFFSET (headers
)
2217 ? H_GET_LINENO_FILE_OFFSET (headers
)
2219 SA_GET_SCN_NRELOC (dot_text_symbol
),
2221 section_alignment
[(int) SEG_TEXT
]);
2223 c_section_header (&data_section_header
,
2225 H_GET_TEXT_SIZE (headers
),
2226 H_GET_DATA_SIZE (headers
),
2227 (H_GET_DATA_SIZE (headers
)
2228 ? H_GET_DATA_FILE_OFFSET (headers
)
2230 (SA_GET_SCN_NRELOC (dot_data_symbol
)
2231 ? (H_GET_RELOCATION_FILE_OFFSET (headers
)
2232 + text_section_header
.s_nreloc
* RELSZ
)
2234 0, /* No line number information */
2235 SA_GET_SCN_NRELOC (dot_data_symbol
),
2236 0, /* No line number information */
2237 section_alignment
[(int) SEG_DATA
]);
2239 c_section_header (&bss_section_header
,
2241 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
2242 H_GET_BSS_SIZE (headers
),
2243 0, /* No file offset */
2244 0, /* No relocation information */
2245 0, /* No line number information */
2246 0, /* No relocation information */
2247 0, /* No line number information */
2248 section_alignment
[(int) SEG_BSS
]);
2252 #ifdef BFD_ASSEMBLER
2257 int n
= (1 << exp
) - 1;
2258 val
= (val
+ n
) & ~n
;
2263 coff_frob_symbol (symp
, punt
)
2267 static symbolS
*last_functionP
, *last_tagP
;
2268 static stack
*block_stack
;
2270 if (current_lineno_sym
)
2271 add_linesym ((symbolS
*) 0);
2274 block_stack
= stack_init (512, sizeof (symbolS
*));
2276 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
2277 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2279 if (!SF_GET_DEBUG (symp
))
2282 if (!SF_GET_LOCAL (symp
)
2283 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
2286 c_symbol_merge (symp
, real
);
2289 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
2291 assert (S_GET_VALUE (symp
) == 0);
2292 S_SET_EXTERNAL (symp
);
2294 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
2296 if (S_GET_SEGMENT (symp
) == text_section
)
2297 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
2299 S_SET_STORAGE_CLASS (symp
, C_STAT
);
2301 if (SF_GET_PROCESS (symp
))
2303 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
2305 if (!strcmp (S_GET_NAME (symp
), ".bb"))
2306 stack_push (block_stack
, (char *) &symp
);
2310 begin
= *(symbolS
**) stack_pop (block_stack
);
2312 as_warn ("mismatched .eb");
2314 SA_SET_SYM_ENDNDX (begin
, begin
);
2317 if (last_functionP
== 0 && SF_GET_FUNCTION (symp
))
2319 union internal_auxent
*auxp
;
2320 last_functionP
= symp
;
2321 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
2322 S_SET_NUMBER_AUXILIARY (symp
, 1);
2323 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
2324 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
2325 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
2327 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
2329 if (last_functionP
== 0)
2330 as_fatal ("C_EFCN symbol out of scope");
2331 SA_SET_SYM_FSIZE (last_functionP
,
2332 (long) (S_GET_VALUE (symp
)
2333 - S_GET_VALUE (last_functionP
)));
2334 SA_SET_SYM_ENDNDX (last_functionP
, symp
);
2338 else if (SF_GET_TAG (symp
))
2340 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
2341 SA_SET_SYM_ENDNDX (last_tagP
, symp
);
2342 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
2344 if (S_GET_VALUE (symp
))
2346 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
2347 S_SET_VALUE (symp
, 0);
2350 if (S_IS_EXTERNAL (symp
))
2351 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2352 else if (SF_GET_LOCAL (symp
))
2356 if (coffsymbol (symp
->bsym
)->lineno
)
2359 struct line_no
*lptr
;
2362 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2363 for (i
= 0; lptr
; lptr
= lptr
->next
)
2366 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2367 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, n
* sizeof (alent
));
2368 coffsymbol (symp
->bsym
)->lineno
= l
;
2369 for (i
= n
- 1; i
> 0; i
--)
2372 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
2380 DEFUN_VOID(obj_coff_section
)
2382 /* Strip out the section name */
2383 char *section_name
;
2384 char *section_name_end
;
2390 section_name
= input_line_pointer
;
2391 c
= get_symbol_end();
2392 section_name_end
= input_line_pointer
;
2394 len
= section_name_end
- section_name
;
2395 input_line_pointer
++;
2398 exp
= get_absolute_expression();
2399 else if (*input_line_pointer
== ',')
2401 input_line_pointer
++;
2402 exp
= get_absolute_expression();
2409 *section_name_end
= c
;
2415 if (symbol_rootP
== NULL
2416 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2418 assert (previous_file_symbol
== 0);
2419 c_dot_file_symbol ("fake");
2422 #endif /* BFD_ASSEMBLER */
2430 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
2431 } /* s_get_name() */
2438 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2440 #ifdef BFD_ASSEMBLER
2441 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
2442 (unsigned long) symbolP
,
2443 S_GET_NAME(symbolP
),
2444 (long) S_GET_DATA_TYPE(symbolP
),
2445 S_GET_STORAGE_CLASS(symbolP
),
2446 (int) S_GET_SEGMENT(symbolP
));
2448 printf ("%3ld: 0x%lx \"%s\" type = %ld, class = %d, segment = %d\n",
2450 (unsigned long) symbolP
,
2451 S_GET_NAME (symbolP
),
2452 (long) S_GET_DATA_TYPE (symbolP
),
2453 S_GET_STORAGE_CLASS (symbolP
),
2454 (int) S_GET_SEGMENT (symbolP
));
2461 /* end of obj-coff.c */