1 /* coff object file format
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
27 const short seg_N_TYPE
[] =
28 { /* in: segT out: N_TYPE bits */
33 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
34 C_UNDEF_SECTION
, /* SEG_GOOF */
35 C_UNDEF_SECTION
, /* SEG_EXPR */
36 C_DEBUG_SECTION
, /* SEG_DEBUG */
37 C_NTV_SECTION
, /* SEG_NTV */
38 C_PTV_SECTION
, /* SEG_PTV */
39 C_REGISTER_SECTION
, /* SEG_REGISTER */
43 /* Add 4 to the real value to get the index and compensate the negatives */
45 const segT N_TYPE_seg
[32] =
47 SEG_PTV
, /* C_PTV_SECTION == -4 */
48 SEG_NTV
, /* C_NTV_SECTION == -3 */
49 SEG_DEBUG
, /* C_DEBUG_SECTION == -2 */
50 SEG_ABSOLUTE
, /* C_ABS_SECTION == -1 */
51 SEG_UNKNOWN
, /* C_UNDEF_SECTION == 0 */
52 SEG_TEXT
, /* C_TEXT_SECTION == 1 */
53 SEG_DATA
, /* C_DATA_SECTION == 2 */
54 SEG_BSS
, /* C_BSS_SECTION == 3 */
55 SEG_REGISTER
, /* C_REGISTER_SECTION == 4 */
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
, SEG_GOOF
,
58 SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
, SEG_GOOF
62 const char *s_get_name
PARAMS ((symbolS
* s
));
63 static symbolS
*tag_find_or_make
PARAMS ((char *name
));
64 static symbolS
*tag_find
PARAMS ((char *name
));
68 static void obj_coff_section_header_append
PARAMS ((char **where
, struct internal_scnhdr
* header
));
70 static void obj_coff_section_header_append
PARAMS ((char **where
, SCNHDR
* header
));
74 static void obj_coff_def
PARAMS ((int what
));
75 static void obj_coff_dim
PARAMS ((int));
76 static void obj_coff_endef
PARAMS ((int));
77 static void obj_coff_line
PARAMS ((int));
78 static void obj_coff_ln
PARAMS ((int));
79 static void obj_coff_scl
PARAMS ((int));
80 static void obj_coff_section
PARAMS ((int));
81 static void obj_coff_size
PARAMS ((int));
82 static void obj_coff_tag
PARAMS ((int));
83 static void obj_coff_type
PARAMS ((int));
84 static void obj_coff_val
PARAMS ((int));
85 static void tag_init
PARAMS ((void));
86 static void tag_insert
PARAMS ((const char *name
, symbolS
* symbolP
));
89 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
92 static struct hash_control
*tag_hash
;
93 static symbolS
*def_symbol_in_progress
;
96 static symbolS
*dot_text_symbol
;
97 static symbolS
*dot_data_symbol
;
98 static symbolS
*dot_bss_symbol
;
101 const pseudo_typeS obj_pseudo_table
[] =
104 {"def", obj_coff_def
, 0},
105 {"dim", obj_coff_dim
, 0},
106 {"endef", obj_coff_endef
, 0},
107 {"line", obj_coff_line
, 0},
108 {"ln", obj_coff_ln
, 0},
109 {"appline", obj_coff_ln
, 1},
110 {"scl", obj_coff_scl
, 0},
111 {"size", obj_coff_size
, 0},
112 {"tag", obj_coff_tag
, 0},
113 {"type", obj_coff_type
, 0},
114 {"val", obj_coff_val
, 0},
116 {"def", s_ignore
, 0},
117 {"dim", s_ignore
, 0},
118 {"endef", s_ignore
, 0},
119 {"line", s_ignore
, 0},
121 {"scl", s_ignore
, 0},
122 {"size", s_ignore
, 0},
123 {"tag", s_ignore
, 0},
124 {"type", s_ignore
, 0},
125 {"val", s_ignore
, 0},
126 #endif /* ignore debug */
129 { "section", obj_coff_section
, 0 },
132 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
134 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
136 {"ABORT", s_abort
, 0},
138 {NULL
} /* end sentinel */
139 }; /* obj_pseudo_table */
143 struct line_no
*next
;
149 #define GET_FILENAME_STRING(X) \
150 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
152 /* obj dependant output values */
153 #ifndef BFD_ASSEMBLER
155 static struct internal_scnhdr bss_section_header
;
156 struct internal_scnhdr data_section_header
;
157 struct internal_scnhdr text_section_header
;
159 static SCNHDR bss_section_header
;
160 SCNHDR data_section_header
;
161 SCNHDR text_section_header
;
169 fetch_coff_debug_section ()
171 static segT debug_section
;
175 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
177 debug_section
= s
->section
;
179 return debug_section
;
183 SA_SET_SYM_ENDNDX (sym
, val
)
187 combined_entry_type
*entry
, *p
;
189 entry
= &coffsymbol (sym
->bsym
)->native
[1];
190 p
= coffsymbol (val
->bsym
)->native
;
191 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
196 SA_SET_SYM_TAGNDX (sym
, val
)
200 combined_entry_type
*entry
, *p
;
202 entry
= &coffsymbol (sym
->bsym
)->native
[1];
203 p
= coffsymbol (val
->bsym
)->native
;
204 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
209 S_GET_DATA_TYPE (sym
)
212 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
216 S_SET_DATA_TYPE (sym
, val
)
220 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
225 S_GET_STORAGE_CLASS (sym
)
228 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
232 S_SET_STORAGE_CLASS (sym
, val
)
236 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
240 #else /* ! BFD_ASSEMBLER */
245 reloc_compare (p1
, p2
)
247 struct internal_reloc
*p1
, *p2
;
252 return (int) (p1
->r_vaddr
- p2
->r_vaddr
);
258 * Crawl along a fixS chain. Emit the segment's relocations.
262 obj_emit_relocations (where
, fixP
, segment_address_in_file
)
264 fixS
*fixP
; /* Fixup chain for this segment. */
265 relax_addressT segment_address_in_file
;
268 struct internal_reloc
*ri_table
;
279 for (count
= 0, p
= fixP
; p
; p
= p
->fx_next
)
286 ri_table
= (struct internal_reloc
*) calloc (sizeof (*ri_table
), count
);
288 ri_table
= (RELOC
*) calloc (sizeof (*ri_table
), count
);
291 as_fatal ("obj_emit_relocations: Could not malloc relocation table");
294 callj_table
= (char *) malloc (sizeof (char) * count
);
296 as_fatal ("obj_emit_relocations: Could not malloc callj table");
299 for (i
= 0; fixP
; fixP
= fixP
->fx_next
)
301 symbolP
= fixP
->fx_addsy
;
306 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
307 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
308 fixP
->fx_size
== 2 ? R_PCRWORD
:
310 (fixP
->fx_size
== 1 ? R_RELBYTE
:
311 fixP
->fx_size
== 2 ? R_RELWORD
:
316 /* FIXME-SOON R_OFF8 & R_DIR16 are a vague guess, completly
318 ri_table
[i
].r_type
= (fixP
->fx_pcrel
?
319 (fixP
->fx_size
== 1 ? R_PCRBYTE
:
320 fixP
->fx_size
== 2 ? R_PCRWORD
:
322 (fixP
->fx_size
== 1 ? R_OFF8
:
323 fixP
->fx_size
== 2 ? R_DIR16
:
328 ri_table
[i
].r_type
= (fixP
->fx_pcrel
331 callj_table
[i
] = fixP
->fx_tcbit
? 1 : 0;
335 ri_table
[i
].r_type
= tc_coff_fix2rtype (fixP
);
340 ri_table
[i
].r_vaddr
= (fixP
->fx_frag
->fr_address
342 /* If symbol associated to relocation entry is a bss symbol
343 or undefined symbol just remember the index of the symbol.
344 Otherwise store the index of the symbol describing the
345 section the symbol belong to. This heuristic speeds up ld.
347 /* Local symbols can generate relocation information. In case
348 of structure return for instance. But they have no symbol
349 number because they won't be emitted in the final object.
350 In the case where they are in the BSS section, this leads
351 to an incorrect r_symndx.
352 Under bsd the loader do not care if the symbol reference
353 is incorrect. But the SYS V ld complains about this. To
354 avoid this we associate the symbol to the associated
355 section, *even* if it is the BSS section. */
356 /* If someone can tell me why the other symbols of the bss
357 section are not associated with the .bss section entry,
358 I'd be gratefull. I guess that it has to do with the special
359 nature of the .bss section. Or maybe this is because the
360 bss symbols are declared in the common section and can
361 be resized later. Can it break code some where ? */
362 ri_table
[i
].r_symndx
= (S_GET_SEGMENT (symbolP
) == SEG_TEXT
363 ? dot_text_symbol
->sy_number
364 : (S_GET_SEGMENT (symbolP
) == SEG_DATA
365 ? dot_data_symbol
->sy_number
366 : ((SF_GET_LOCAL (symbolP
)
367 ? dot_bss_symbol
->sy_number
368 : symbolP
->sy_number
)))); /* bss or undefined */
370 /* md_ri_to_chars((char *) &ri, ri); *//* Last step : write md f */
373 } /* if there's a symbol */
374 } /* for each fixP */
376 /* AIX ld prefer to have the reloc table with r_vaddr sorted.
377 But sorting it should not hurt any other ld. */
378 qsort (ri_table
, count
, sizeof (*ri_table
), reloc_compare
);
380 for (i
= 0; i
< count
; i
++)
383 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
], *where
);
385 /* The 29k has a special kludge for the high 16 bit reloc.
386 Two relocations are emmited, R_IHIHALF, and R_IHCONST.
387 The second one doesn't contain a symbol, but uses the
389 if (ri_table
[i
].r_type
== R_IHIHALF
)
391 /* now emit the second bit */
392 ri_table
[i
].r_type
= R_IHCONST
;
393 ri_table
[i
].r_symndx
= fixP
->fx_addnumber
;
394 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
397 # endif /* TC_A29K */
399 #else /* not BFD_HEADERS */
400 append (where
, (char *) &ri_table
[i
], RELSZ
);
401 #endif /* not BFD_HEADERS */
406 ri_table
[i
].r_type
= R_OPTCALL
;
408 *where
+= bfd_coff_swap_reloc_out (stdoutput
, &ri_table
[i
],
411 append (where
, (char *) &ri_table
[i
], (unsigned long) RELSZ
);
412 # endif /* BFD_HEADERS */
413 } /* if it's a callj, do it again for the opcode */
423 /* Coff file generation & utilities */
427 obj_header_append (where
, headers
)
429 object_headers
*headers
;
431 tc_headers_hook (headers
);
432 *where
+= bfd_coff_swap_filehdr_out (stdoutput
, &(headers
->filehdr
), *where
);
433 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
434 *where
+= bfd_coff_swap_aouthdr_out (stdoutput
, &(headers
->aouthdr
), *where
);
436 obj_coff_section_header_append (where
, &text_section_header
);
437 obj_coff_section_header_append (where
, &data_section_header
);
438 obj_coff_section_header_append (where
, &bss_section_header
);
441 #else /* ! BFD_HEADERS */
444 obj_header_append (where
, headers
)
446 object_headers
*headers
;
448 tc_headers_hook (headers
);
451 /* Eventually swap bytes for cross compilation for file header */
452 md_number_to_chars (*where
, headers
->filehdr
.f_magic
, sizeof (headers
->filehdr
.f_magic
));
453 *where
+= sizeof (headers
->filehdr
.f_magic
);
454 md_number_to_chars (*where
, headers
->filehdr
.f_nscns
, sizeof (headers
->filehdr
.f_nscns
));
455 *where
+= sizeof (headers
->filehdr
.f_nscns
);
456 md_number_to_chars (*where
, headers
->filehdr
.f_timdat
, sizeof (headers
->filehdr
.f_timdat
));
457 *where
+= sizeof (headers
->filehdr
.f_timdat
);
458 md_number_to_chars (*where
, headers
->filehdr
.f_symptr
, sizeof (headers
->filehdr
.f_symptr
));
459 *where
+= sizeof (headers
->filehdr
.f_symptr
);
460 md_number_to_chars (*where
, headers
->filehdr
.f_nsyms
, sizeof (headers
->filehdr
.f_nsyms
));
461 *where
+= sizeof (headers
->filehdr
.f_nsyms
);
462 md_number_to_chars (*where
, headers
->filehdr
.f_opthdr
, sizeof (headers
->filehdr
.f_opthdr
));
463 *where
+= sizeof (headers
->filehdr
.f_opthdr
);
464 md_number_to_chars (*where
, headers
->filehdr
.f_flags
, sizeof (headers
->filehdr
.f_flags
));
465 *where
+= sizeof (headers
->filehdr
.f_flags
);
467 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
468 /* Eventually swap bytes for cross compilation for a.out header */
469 md_number_to_chars (*where
, headers
->aouthdr
.magic
, sizeof (headers
->aouthdr
.magic
));
470 *where
+= sizeof (headers
->aouthdr
.magic
);
471 md_number_to_chars (*where
, headers
->aouthdr
.vstamp
, sizeof (headers
->aouthdr
.vstamp
));
472 *where
+= sizeof (headers
->aouthdr
.vstamp
);
473 md_number_to_chars (*where
, headers
->aouthdr
.tsize
, sizeof (headers
->aouthdr
.tsize
));
474 *where
+= sizeof (headers
->aouthdr
.tsize
);
475 md_number_to_chars (*where
, headers
->aouthdr
.dsize
, sizeof (headers
->aouthdr
.dsize
));
476 *where
+= sizeof (headers
->aouthdr
.dsize
);
477 md_number_to_chars (*where
, headers
->aouthdr
.bsize
, sizeof (headers
->aouthdr
.bsize
));
478 *where
+= sizeof (headers
->aouthdr
.bsize
);
479 md_number_to_chars (*where
, headers
->aouthdr
.entry
, sizeof (headers
->aouthdr
.entry
));
480 *where
+= sizeof (headers
->aouthdr
.entry
);
481 md_number_to_chars (*where
, headers
->aouthdr
.text_start
, sizeof (headers
->aouthdr
.text_start
));
482 *where
+= sizeof (headers
->aouthdr
.text_start
);
483 md_number_to_chars (*where
, headers
->aouthdr
.data_start
, sizeof (headers
->aouthdr
.data_start
));
484 *where
+= sizeof (headers
->aouthdr
.data_start
);
485 md_number_to_chars (*where
, headers
->aouthdr
.tagentries
, sizeof (headers
->aouthdr
.tagentries
));
486 *where
+= sizeof (headers
->aouthdr
.tagentries
);
487 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
489 #else /* CROSS_COMPILE */
491 append (where
, (char *) &headers
->filehdr
, sizeof (headers
->filehdr
));
492 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
493 append (where
, (char *) &headers
->aouthdr
, sizeof (headers
->aouthdr
));
494 #endif /* OBJ_COFF_OMIT_OPTIONAL_HEADER */
496 #endif /* CROSS_COMPILE */
498 /* Output the section headers */
499 obj_coff_section_header_append (where
, &text_section_header
);
500 obj_coff_section_header_append (where
, &data_section_header
);
501 obj_coff_section_header_append (where
, &bss_section_header
);
504 #endif /* ! BFD_HEADERS */
507 obj_symbol_to_chars (where
, symbolP
)
511 /* Move the value into the COFF symbol itself. */
512 symbolP
->sy_symbol
.ost_entry
.n_value
= S_GET_VALUE (symbolP
);
515 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
518 if (S_GET_SEGMENT (symbolP
) == SEG_REGISTER
)
520 S_SET_SEGMENT (symbolP
, SEG_ABSOLUTE
);
522 *where
+= bfd_coff_swap_sym_out (stdoutput
, &symbolP
->sy_symbol
.ost_entry
,
525 for (i
= 0; i
< numaux
; i
++)
527 *where
+= bfd_coff_swap_aux_out (stdoutput
,
528 &symbolP
->sy_symbol
.ost_auxent
[i
],
529 S_GET_DATA_TYPE (symbolP
),
530 S_GET_STORAGE_CLASS (symbolP
),
534 #else /* BFD_HEADERS */
536 SYMENT
*syment
= &symbolP
->sy_symbol
.ost_entry
;
538 char numaux
= syment
->n_numaux
;
539 unsigned short type
= S_GET_DATA_TYPE (symbolP
);
542 md_number_to_chars (*where
, syment
->n_value
, sizeof (syment
->n_value
));
543 *where
+= sizeof (syment
->n_value
);
544 md_number_to_chars (*where
, 0xffff & syment
->n_scnum
,
545 sizeof (syment
->n_scnum
));
546 *where
+= sizeof (syment
->n_scnum
);
547 md_number_to_chars (*where
, 0, sizeof (short)); /* pad n_flags */
548 *where
+= sizeof (short);
549 md_number_to_chars (*where
, syment
->n_type
, sizeof (syment
->n_type
));
550 *where
+= sizeof (syment
->n_type
);
551 md_number_to_chars (*where
, syment
->n_sclass
, sizeof (syment
->n_sclass
));
552 *where
+= sizeof (syment
->n_sclass
);
553 md_number_to_chars (*where
, syment
->n_numaux
, sizeof (syment
->n_numaux
));
554 *where
+= sizeof (syment
->n_numaux
);
555 #else /* CROSS_COMPILE */
556 append (where
, (char *) syment
, sizeof (*syment
));
557 #endif /* CROSS_COMPILE */
559 /* Should do the following:
560 if (.file entry) MD(..)... else if (static entry) MD(..) */
561 if (numaux
> OBJ_COFF_MAX_AUXENTRIES
)
562 as_bad ("Internal error? too many auxents for symbol");
564 for (i
= 0; i
< numaux
; ++i
)
567 this code does
not work
;
569 foo
*auxP
= SYM_AUXENT (symbolP
);
570 /* The most common case, x_sym entry. */
571 if ((SF_GET (symbolP
) & SF_STATICS
) == 0)
573 md_number_to_chars (*where
, auxP
->x_sym
.x_tagndx
,
574 sizeof (auxP
->x_sym
.x_tagndx
));
575 *where
+= sizeof (auxP
->x_sym
.x_tagndx
);
578 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_fsize
,
579 sizeof (auxP
->x_sym
.x_misc
.x_fsize
));
580 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_fsize
);
584 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_lnno
,
585 sizeof (auxP
->x_sym
.x_misc
.x_lnno
));
586 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_lnno
);
587 md_number_to_chars (*where
, auxP
->x_sym
.x_misc
.x_size
,
588 sizeof (auxP
->x_sym
.x_misc
.x_size
));
589 *where
+= sizeof (auxP
->x_sym
.x_misc
.x_size
);
594 for (index
= 0; index
< DIMNUM
; index
++)
595 md_number_to_chars (*where
, auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
],
596 sizeof (auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
]));
597 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_ary
.x_dimen
[index
]);
601 md_number_to_chars (*where
,
602 auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
,
603 sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
));
604 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
);
605 md_number_to_chars (*where
,
606 auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
,
607 sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
));
608 *where
+= sizeof (auxP
->x_sym
.x_fcnary
.x_fcn
.x_endndx
);
610 md_number_to_chars (*where
, auxP
->x_sym
.x_tvndx
,
611 sizeof (auxP
->x_sym
.x_tvndx
));
612 *where
+= sizeof (auxP
->x_sym
.x_tvndx
);
614 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
617 else if (SF_GET_STATICS (symbolP
))
618 { /* .text, .data, .bss symbols */
619 md_number_to_chars (*where
, auxP
->x_scn
.x_scnlen
,
620 sizeof (auxP
->x_scn
.x_scnlen
));
621 *where
+= sizeof (auxP
->x_scn
.x_scnlen
);
622 md_number_to_chars (*where
, auxP
->x_scn
.x_nreloc
,
623 sizeof (auxP
->x_scn
.x_nreloc
));
624 *where
+= sizeof (auxP
->x_scn
.x_nreloc
);
625 md_number_to_chars (*where
, auxP
->x_scn
.x_nlinno
,
626 sizeof (auxP
->x_scn
.x_nlinno
));
627 *where
+= sizeof (auxP
->x_scn
.x_nlinno
);
629 #else /* CROSS_COMPILE */
630 append (where
, (char *) &symbolP
->sy_symbol
.ost_auxent
[i
],
631 sizeof (symbolP
->sy_symbol
.ost_auxent
[i
]));
632 #endif /* CROSS_COMPILE */
635 #endif /* BFD_HEADERS */
640 obj_coff_section_header_append (where
, header
)
642 struct internal_scnhdr
*header
;
644 *where
+= bfd_coff_swap_scnhdr_out (stdoutput
, header
, *where
);
649 obj_coff_section_header_append (where
, header
)
654 memcpy (*where
, header
->s_name
, sizeof (header
->s_name
));
655 *where
+= sizeof (header
->s_name
);
657 md_number_to_chars (*where
, header
->s_paddr
, sizeof (header
->s_paddr
));
658 *where
+= sizeof (header
->s_paddr
);
660 md_number_to_chars (*where
, header
->s_vaddr
, sizeof (header
->s_vaddr
));
661 *where
+= sizeof (header
->s_vaddr
);
663 md_number_to_chars (*where
, header
->s_size
, sizeof (header
->s_size
));
664 *where
+= sizeof (header
->s_size
);
666 md_number_to_chars (*where
, header
->s_scnptr
, sizeof (header
->s_scnptr
));
667 *where
+= sizeof (header
->s_scnptr
);
669 md_number_to_chars (*where
, header
->s_relptr
, sizeof (header
->s_relptr
));
670 *where
+= sizeof (header
->s_relptr
);
672 md_number_to_chars (*where
, header
->s_lnnoptr
, sizeof (header
->s_lnnoptr
));
673 *where
+= sizeof (header
->s_lnnoptr
);
675 md_number_to_chars (*where
, header
->s_nreloc
, sizeof (header
->s_nreloc
));
676 *where
+= sizeof (header
->s_nreloc
);
678 md_number_to_chars (*where
, header
->s_nlnno
, sizeof (header
->s_nlnno
));
679 *where
+= sizeof (header
->s_nlnno
);
681 md_number_to_chars (*where
, header
->s_flags
, sizeof (header
->s_flags
));
682 *where
+= sizeof (header
->s_flags
);
685 md_number_to_chars (*where
, header
->s_align
, sizeof (header
->s_align
));
686 *where
+= sizeof (header
->s_align
);
689 #else /* CROSS_COMPILE */
691 append (where
, (char *) header
, sizeof (*header
));
693 #endif /* CROSS_COMPILE */
698 obj_emit_symbols (where
, symbol_rootP
)
700 symbolS
*symbol_rootP
;
704 * Emit all symbols left in the symbol chain.
706 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
708 /* Used to save the offset of the name. It is used to point
709 to the string in memory but must be a file offset. */
712 tc_coff_symbol_emit_hook (symbolP
);
714 temp
= S_GET_NAME (symbolP
);
715 if (SF_GET_STRING (symbolP
))
717 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
718 S_SET_ZEROES (symbolP
, 0);
722 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, '\0', SYMNMLEN
);
723 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
725 obj_symbol_to_chars (where
, symbolP
);
726 S_SET_NAME (symbolP
, temp
);
728 } /* obj_emit_symbols() */
730 #endif /* ! BFD_ASSEMBLER */
732 /* Merge a debug symbol containing debug information into a normal symbol. */
735 c_symbol_merge (debug
, normal
)
739 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
740 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
742 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
743 /* take the most we have */
744 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
746 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
748 /* Move all the auxiliary information. */
750 /* @@ How many fields do we want to preserve? Would it make more
751 sense to pick and choose those we want to copy? Should look
752 into this further.... [raeburn:19920512.2209EST] */
754 linenos
= coffsymbol (normal
->bsym
)->lineno
;
755 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
756 (char *) &coffsymbol (debug
->bsym
)->native
,
757 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
758 coffsymbol (normal
->bsym
)->lineno
= linenos
;
760 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
761 (char *) &debug
->sy_symbol
.ost_auxent
[0],
762 S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
);
766 /* Move the debug flags. */
767 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
770 static symbolS
*previous_file_symbol
;
772 c_dot_file_symbol (filename
)
778 symbolP
= symbol_new (filename
, &bfd_abs_section
, 0,
781 symbolP
= symbol_new (".file",
787 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
788 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
791 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
793 if (strlen(filename
) > 14)
795 /* This won't fit into a 14 char space, it will go into the string
797 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
= 0;
798 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[0] = string_byte_count
;
799 (&(symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
))[1] = (int)filename
;
803 SA_SET_FILE_FNAME (symbolP
, filename
);
805 SF_SET_DEBUG (symbolP
);
813 listing_source_file (filename
);
818 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
820 previous_file_symbol
= symbolP
;
822 /* Make sure that the symbol is first on the symbol chain */
823 if (symbol_rootP
!= symbolP
)
825 if (symbolP
== symbol_lastP
)
827 symbol_lastP
= symbol_lastP
->sy_previous
;
828 } /* if it was the last thing on the list */
830 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
831 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
832 symbol_rootP
= symbolP
;
833 } /* if not first on the list */
837 * Build a 'section static' symbol.
841 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
845 unsigned short nreloc
;
846 unsigned short nlnno
;
850 symbolP
= symbol_new (name
,
859 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
860 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
862 SA_SET_SCN_SCNLEN (symbolP
, length
);
863 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
864 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
866 SF_SET_STATICS (symbolP
);
868 return (char *) symbolP
;
871 #ifndef BFD_ASSEMBLER
873 c_section_header (header
,
884 struct internal_scnhdr
*header
;
898 strncpy (header
->s_name
, name
, 8);
899 header
->s_paddr
= header
->s_vaddr
= core_address
;
900 header
->s_scnptr
= ((header
->s_size
= size
) != 0) ? data_ptr
: 0;
901 header
->s_relptr
= reloc_ptr
;
902 header
->s_lnnoptr
= lineno_ptr
;
903 header
->s_nreloc
= reloc_number
;
904 header
->s_nlnno
= lineno_number
;
906 #ifdef OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT
907 #ifdef OBJ_COFF_BROKEN_ALIGNMENT
908 header
->s_align
= ((name
[1] == 'b' || (size
> 0)) ? 16 : 0);
910 header
->s_align
= ((alignment
== 0)
913 #endif /* OBJ_COFF_BROKEN_ALIGNMENT */
914 #endif /* OBJ_COFF_SECTION_HEADER_HAS_ALIGNMENT */
916 header
->s_flags
= STYP_REG
| (name
[1] == 't'
926 /* Line number handling */
932 /* Symbol of last function, which we should hang line#s off of. */
933 static symbolS
*line_fsym
;
935 #define in_function() (line_fsym != 0)
936 #define clear_function() (line_fsym = 0)
937 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
941 /* Offset in line#s where the last function started (the odd entry for
943 static int function_lineoff
= -1;
945 #define in_function() (function_lineoff >= 0)
946 #define clear_function() (function_lineoff = -1)
947 #define set_function(F) (function_lineoff = c_line_new ((long) (F), 0, &zero_address_frag))
949 int text_lineno_number
;
951 /* We use this to build pointers from .bf's into the linetable. It
952 should match exactly the values that are later assigned in
953 text_lineno_number by write.c. */
954 int our_lineno_number
;
956 lineno
*lineno_rootP
;
957 lineno
*lineno_lastP
;
960 c_line_new (paddr
, line_number
, frag
)
962 unsigned short line_number
;
965 lineno
*new_line
= (lineno
*) xmalloc (sizeof (lineno
));
967 new_line
->line
.l_addr
.l_paddr
= paddr
;
968 new_line
->line
.l_lnno
= line_number
;
969 new_line
->frag
= (char *) frag
;
970 new_line
->next
= (lineno
*) 0;
972 if (lineno_rootP
== (lineno
*) 0)
973 lineno_rootP
= new_line
;
975 lineno_lastP
->next
= new_line
;
976 lineno_lastP
= new_line
;
977 return LINESZ
* our_lineno_number
++;
981 obj_emit_lineno (where
, line
, file_start
)
987 struct bfd_internal_lineno
*line_entry
;
991 char *where2
= *where
;
993 for (; line
; line
= line
->next
)
995 line_entry
= &line
->line
;
997 /* FIXME-SOMEDAY Resolving the sy_number of function linno's used to be
998 done in write_object_file() but their symbols need a fileptr to the
999 lnno, so I moved this resolution check here. xoxorich. */
1001 if (line_entry
->l_lnno
== 0)
1003 /* There is a good chance that the symbol pointed to
1004 is not the one that will be emitted and that the
1005 sy_number is not accurate. */
1008 symbolP
= (symbolS
*) line_entry
->l_addr
.l_symndx
;
1010 line_entry
->l_addr
.l_symndx
= symbolP
->sy_number
;
1011 symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_fcn
.x_lnnoptr
= where2
- file_start
;
1014 where2
+= bfd_coff_swap_lineno_out (stdoutput
, line_entry
, where2
);
1016 /* No matter which member of the union we process, they are
1018 md_number_to_chars (where2
, line_entry
->l_addr
.l_paddr
, sizeof (line_entry
->l_addr
.l_paddr
));
1019 where2
+= sizeof (line_entry
->l_addr
.l_paddr
);
1021 md_number_to_chars (where2
, line_entry
->l_lnno
, sizeof (line_entry
->l_lnno
));
1022 where2
+= sizeof (line_entry
->l_lnno
);
1027 #endif /* TC_I960 */
1029 #endif /* BFD_HEADERS */
1034 #endif /* ! BFD_ASSEMBLER */
1038 obj_symbol_new_hook (symbolP
)
1041 char underscore
= 0; /* Symbol has leading _ */
1043 #ifdef BFD_ASSEMBLER
1045 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
1046 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
1048 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
1051 /* Effective symbol */
1052 /* Store the pointer in the offset. */
1053 S_SET_ZEROES (symbolP
, 0L);
1054 /* Additional information */
1055 symbolP
->sy_symbol
.ost_flags
= 0;
1056 /* Auxiliary entries */
1057 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], '\0', AUXESZ
);
1059 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1060 S_SET_STORAGE_CLASS (symbolP
, 0);
1061 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1063 #ifdef STRIP_UNDERSCORE
1064 /* Remove leading underscore at the beginning of the symbol.
1065 This is to be compatible with the standard librairies. */
1066 if (*S_GET_NAME (symbolP
) == '_')
1069 S_SET_NAME (symbolP
, S_GET_NAME (symbolP
) + 1);
1071 #endif /* STRIP_UNDERSCORE */
1073 if (S_IS_STRING (symbolP
))
1074 SF_SET_STRING (symbolP
);
1075 if (!underscore
&& S_IS_LOCAL (symbolP
))
1076 SF_SET_LOCAL (symbolP
);
1082 stack_init (chunk_size
, element_size
)
1083 unsigned long chunk_size
;
1084 unsigned long element_size
;
1088 st
= (stack
*) malloc (sizeof (stack
));
1091 st
->data
= malloc (chunk_size
);
1098 st
->size
= chunk_size
;
1099 st
->chunk_size
= chunk_size
;
1100 st
->element_size
= element_size
;
1113 stack_push (st
, element
)
1117 if (st
->pointer
+ st
->element_size
>= st
->size
)
1119 st
->size
+= st
->chunk_size
;
1120 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
1123 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
1124 st
->pointer
+= st
->element_size
;
1125 return st
->data
+ st
->pointer
;
1132 if (st
->pointer
< st
->element_size
)
1137 st
->pointer
-= st
->element_size
;
1138 return st
->data
+ st
->pointer
;
1145 return st
->data
+ st
->pointer
- st
->element_size
;
1150 * Handle .ln directives.
1153 #ifdef BFD_ASSEMBLER
1154 static symbolS
*current_lineno_sym
;
1155 static struct line_no
*line_nos
;
1158 add_lineno (frag
, offset
, num
)
1163 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
1164 sizeof (struct line_no
));
1165 if (!current_lineno_sym
)
1169 new_line
->next
= line_nos
;
1170 new_line
->frag
= frag
;
1171 new_line
->l
.line_number
= num
;
1172 new_line
->l
.u
.offset
= offset
;
1173 line_nos
= new_line
;
1177 coff_add_linesym (sym
)
1182 add_lineno (0, 0, 0);
1183 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
1186 current_lineno_sym
= sym
;
1191 obj_coff_ln (appline
)
1196 if (! appline
&& def_symbol_in_progress
!= NULL
)
1198 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1199 demand_empty_rest_of_line ();
1203 l
= get_absolute_expression ();
1206 #ifdef BFD_ASSEMBLER
1207 add_lineno (frag_now
, frag_now_fix (), l
);
1209 c_line_new (frag_now_fix (), l
, frag_now
);
1220 l
+= coff_line_base
- 1;
1221 listing_source_line (l
);
1226 demand_empty_rest_of_line ();
1232 * Handle .def directives.
1234 * One might ask : why can't we symbol_new if the symbol does not
1235 * already exist and fill it with debug information. Because of
1236 * the C_EFCN special symbol. It would clobber the value of the
1237 * function symbol before we have a chance to notice that it is
1238 * a C_EFCN. And a second reason is that the code is more clear this
1239 * way. (at least I think it is :-).
1243 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1244 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1245 *input_line_pointer == '\t') \
1246 input_line_pointer++;
1252 char name_end
; /* Char after the end of name */
1253 char *symbol_name
; /* Name of the debug symbol */
1254 char *symbol_name_copy
; /* Temporary copy of the name */
1255 unsigned int symbol_name_length
;
1257 if (def_symbol_in_progress
!= NULL
)
1259 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1260 demand_empty_rest_of_line ();
1262 } /* if not inside .def/.endef */
1264 SKIP_WHITESPACES ();
1266 symbol_name
= input_line_pointer
;
1267 #ifdef STRIP_UNDERSCORE
1268 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
1270 #endif /* STRIP_UNDERSCORE */
1272 name_end
= get_symbol_end ();
1273 symbol_name_length
= strlen (symbol_name
);
1274 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
1275 strcpy (symbol_name_copy
, symbol_name
);
1277 /* Initialize the new symbol */
1278 #ifdef BFD_ASSEMBLER
1279 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
1281 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1282 memset (def_symbol_in_progress
, '\0', sizeof (*def_symbol_in_progress
));
1284 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
1285 def_symbol_in_progress
->sy_name_offset
= ~0;
1286 def_symbol_in_progress
->sy_number
= ~0;
1289 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
1290 S_SET_VALUE (def_symbol_in_progress
, 0);
1292 if (S_IS_STRING (def_symbol_in_progress
))
1293 SF_SET_STRING (def_symbol_in_progress
);
1295 *input_line_pointer
= name_end
;
1297 demand_empty_rest_of_line ();
1300 unsigned int dim_index
;
1303 obj_coff_endef (ignored
)
1307 /* DIM BUG FIX sac@cygnus.com */
1309 if (def_symbol_in_progress
== NULL
)
1311 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
1312 demand_empty_rest_of_line ();
1314 } /* if not inside .def/.endef */
1316 /* Set the section number according to storage class. */
1317 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
1322 SF_SET_TAG (def_symbol_in_progress
);
1323 /* intentional fallthrough */
1326 SF_SET_DEBUG (def_symbol_in_progress
);
1327 #ifdef BFD_ASSEMBLER
1328 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
1330 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
1335 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
1336 /* intentional fallthrough */
1338 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
1339 /* intentional fallthrough */
1343 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
1345 #ifdef BFD_ASSEMBLER
1346 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
1348 name
= def_symbol_in_progress
->sy_symbol
.ost_entry
._n
._n_nptr
[1];
1350 if (name
[1] == 'b' && name
[2] == 'f')
1352 if (! in_function ())
1353 as_warn ("`%s' symbol without preceding function", name
);
1354 #ifdef BFD_ASSEMBLER
1355 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
1357 SA_GET_SYM_LNNOPTR (def_symbol_in_progress
) = function_lineoff
;
1359 /* Will need relocating */
1360 SF_SET_PROCESS (def_symbol_in_progress
);
1368 #endif /* C_AUTOARG */
1378 SF_SET_DEBUG (def_symbol_in_progress
);
1379 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
1385 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
1391 as_warn ("unexpected storage class %d",
1392 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
1394 } /* switch on storage class */
1396 /* Now that we have built a debug symbol, try to find if we should
1397 merge with an existing symbol or not. If a symbol is C_EFCN or
1398 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
1400 /* Two cases for functions. Either debug followed by definition or
1401 definition followed by debug. For definition first, we will
1402 merge the debug symbol into the definition. For debug first, the
1403 lineno entry MUST point to the definition function or else it
1404 will point off into space when obj_crawl_symbol_chain() merges
1405 the debug symbol into the real symbol. Therefor, let's presume
1406 the debug symbol is a real function reference. */
1408 /* FIXME-SOON If for some reason the definition label/symbol is
1409 never seen, this will probably leave an undefined symbol at link
1412 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
1413 #ifdef BFD_ASSEMBLER
1414 || (!strcmp (bfd_get_section_name (stdoutput
,
1415 S_GET_SEGMENT (def_symbol_in_progress
)),
1417 && !SF_GET_TAG (def_symbol_in_progress
))
1419 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
1420 && !SF_GET_TAG (def_symbol_in_progress
))
1422 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
1423 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
1425 #ifdef BFD_ASSEMBLER
1426 if (def_symbol_in_progress
!= symbol_lastP
)
1427 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1430 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
1436 /* This symbol already exists, merge the newly created symbol
1437 into the old one. This is not mandatory. The linker can
1438 handle duplicate symbols correctly. But I guess that it save
1439 a *lot* of space if the assembly file defines a lot of
1442 /* The debug entry (def_symbol_in_progress) is merged into the
1443 previous definition. */
1445 c_symbol_merge (def_symbol_in_progress
, symbolP
);
1446 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
1447 def_symbol_in_progress
= symbolP
;
1449 if (SF_GET_FUNCTION (def_symbol_in_progress
)
1450 || SF_GET_TAG (def_symbol_in_progress
))
1452 /* For functions, and tags, the symbol *must* be where the
1453 debug symbol appears. Move the existing symbol to the
1455 /* If it already is at the end of the symbol list, do nothing */
1456 if (def_symbol_in_progress
!= symbol_lastP
)
1458 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
1459 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
1464 if (SF_GET_TAG (def_symbol_in_progress
)
1465 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
1467 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
1470 if (SF_GET_FUNCTION (def_symbol_in_progress
))
1472 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
1473 set_function (def_symbol_in_progress
);
1474 SF_SET_PROCESS (def_symbol_in_progress
);
1476 if (symbolP
== NULL
)
1478 /* That is, if this is the first time we've seen the
1480 symbol_table_insert (def_symbol_in_progress
);
1481 } /* definition follows debug */
1482 } /* Create the line number entry pointing to the function being defined */
1484 def_symbol_in_progress
= NULL
;
1485 demand_empty_rest_of_line ();
1489 obj_coff_dim (ignored
)
1494 if (def_symbol_in_progress
== NULL
)
1496 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
1497 demand_empty_rest_of_line ();
1499 } /* if not inside .def/.endef */
1501 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1503 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
1505 SKIP_WHITESPACES ();
1506 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
1507 get_absolute_expression ());
1509 switch (*input_line_pointer
)
1512 input_line_pointer
++;
1516 as_warn ("badly formed .dim directive ignored");
1517 /* intentional fallthrough */
1525 demand_empty_rest_of_line ();
1529 obj_coff_line (ignored
)
1534 if (def_symbol_in_progress
== NULL
)
1536 /* Probably stabs-style line? */
1541 this_base
= get_absolute_expression ();
1542 if (this_base
> coff_line_base
)
1543 coff_line_base
= this_base
;
1545 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1546 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
1548 demand_empty_rest_of_line ();
1552 obj_coff_size (ignored
)
1555 if (def_symbol_in_progress
== NULL
)
1557 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
1558 demand_empty_rest_of_line ();
1560 } /* if not inside .def/.endef */
1562 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1563 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
1564 demand_empty_rest_of_line ();
1568 obj_coff_scl (ignored
)
1571 if (def_symbol_in_progress
== NULL
)
1573 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
1574 demand_empty_rest_of_line ();
1576 } /* if not inside .def/.endef */
1578 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1579 demand_empty_rest_of_line ();
1583 obj_coff_tag (ignored
)
1589 if (def_symbol_in_progress
== NULL
)
1591 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
1592 demand_empty_rest_of_line ();
1596 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1597 symbol_name
= input_line_pointer
;
1598 name_end
= get_symbol_end ();
1600 /* Assume that the symbol referred to by .tag is always defined.
1601 This was a bad assumption. I've added find_or_make. xoxorich. */
1602 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1603 tag_find_or_make (symbol_name
));
1604 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1606 as_warn ("tag not found for .tag %s", symbol_name
);
1609 SF_SET_TAGGED (def_symbol_in_progress
);
1610 *input_line_pointer
= name_end
;
1612 demand_empty_rest_of_line ();
1616 obj_coff_type (ignored
)
1619 if (def_symbol_in_progress
== NULL
)
1621 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
1622 demand_empty_rest_of_line ();
1624 } /* if not inside .def/.endef */
1626 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1628 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1629 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1631 SF_SET_FUNCTION (def_symbol_in_progress
);
1632 } /* is a function */
1634 demand_empty_rest_of_line ();
1638 obj_coff_val (ignored
)
1641 if (def_symbol_in_progress
== NULL
)
1643 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
1644 demand_empty_rest_of_line ();
1646 } /* if not inside .def/.endef */
1648 if (is_name_beginner (*input_line_pointer
))
1650 char *symbol_name
= input_line_pointer
;
1651 char name_end
= get_symbol_end ();
1653 if (!strcmp (symbol_name
, "."))
1655 def_symbol_in_progress
->sy_frag
= frag_now
;
1656 S_SET_VALUE (def_symbol_in_progress
, obstack_next_free (&frags
) - frag_now
->fr_literal
);
1657 /* If the .val is != from the .def (e.g. statics) */
1659 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1661 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
1662 def_symbol_in_progress
->sy_value
.X_add_symbol
=
1663 symbol_find_or_make (symbol_name
);
1664 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
1665 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
1667 /* If the segment is undefined when the forward reference is
1668 resolved, then copy the segment id from the forward
1670 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1672 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
1673 *input_line_pointer
= name_end
;
1677 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1678 } /* if symbol based */
1680 demand_empty_rest_of_line ();
1684 * Maintain a list of the tagnames of the structres.
1690 tag_hash
= hash_new ();
1694 tag_insert (name
, symbolP
)
1698 const char *error_string
;
1700 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
1702 as_fatal ("Inserting \"%s\" into structure table failed: %s",
1703 name
, error_string
);
1708 tag_find_or_make (name
)
1713 if ((symbolP
= tag_find (name
)) == NULL
)
1715 symbolP
= symbol_new (name
, undefined_section
,
1716 0, &zero_address_frag
);
1718 tag_insert (S_GET_NAME (symbolP
), symbolP
);
1719 symbol_table_insert (symbolP
);
1729 #ifdef STRIP_UNDERSCORE
1732 #endif /* STRIP_UNDERSCORE */
1733 return (symbolS
*) hash_find (tag_hash
, name
);
1737 obj_read_begin_hook ()
1739 /* These had better be the same. Usually 18 bytes. */
1741 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1742 know (SYMESZ
== AUXESZ
);
1747 #ifndef BFD_ASSEMBLER
1749 obj_crawl_symbol_chain (headers
)
1750 object_headers
*headers
;
1752 int symbol_number
= 0;
1754 symbolS
*last_functionP
= NULL
;
1757 symbolS
*symbol_externP
= NULL
;
1758 symbolS
*symbol_extern_lastP
= NULL
;
1760 /* Initialize the stack used to keep track of the matching .bb .be */
1761 stack
*block_stack
= stack_init (512, sizeof (symbolS
*));
1763 tc_crawl_symbol_chain (headers
);
1765 /* The symbol list should be ordered according to the following sequence
1768 * . debug entries for functions
1769 * . fake symbols for .text .data and .bss
1771 * . undefined symbols
1772 * But this is not mandatory. The only important point is to put the
1773 * undefined symbols at the end of the list.
1776 if (symbol_rootP
== NULL
1777 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1779 know (!previous_file_symbol
);
1780 c_dot_file_symbol ("fake");
1781 } /* Is there a .file symbol? If not, insert one at the beginning. */
1784 * Build up static symbols for .text, .data and .bss
1786 dot_text_symbol
= (symbolS
*) c_section_symbol (".text",
1788 H_GET_TEXT_SIZE (headers
),
1789 0 /*text_relocation_number*/,
1790 0 /*text_lineno_number */);
1792 symbol_remove (dot_text_symbol
, &symbol_rootP
, &symbol_lastP
);
1793 symbol_append (dot_text_symbol
, previous_file_symbol
,
1794 &symbol_rootP
, &symbol_lastP
);
1795 #endif /* TE_I386AIX */
1797 dot_data_symbol
= (symbolS
*)
1798 c_section_symbol (".data",
1799 H_GET_TEXT_SIZE (headers
),
1800 H_GET_DATA_SIZE (headers
),
1801 0 /*data_relocation_number */ ,
1802 0); /* There are no data lineno entries */
1804 symbol_remove (dot_data_symbol
, &symbol_rootP
, &symbol_lastP
);
1805 symbol_append (dot_data_symbol
, dot_text_symbol
,
1806 &symbol_rootP
, &symbol_lastP
);
1807 #endif /* TE_I386AIX */
1809 dot_bss_symbol
= (symbolS
*)
1810 c_section_symbol (".bss",
1811 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
1812 H_GET_BSS_SIZE (headers
),
1813 0, /* No relocation for a bss section. */
1814 0); /* There are no bss lineno entries */
1816 symbol_remove (dot_bss_symbol
, &symbol_rootP
, &symbol_lastP
);
1817 symbol_append (dot_bss_symbol
, dot_data_symbol
,
1818 &symbol_rootP
, &symbol_lastP
);
1819 #endif /* TE_I386AIX */
1822 verify_symbol_chain (symbol_rootP
, symbol_lastP
);
1825 /* Three traversals of symbol chains here. The
1826 first traversal yanks externals into a temporary
1827 chain, removing the externals from the global
1828 chain, numbers symbols, and does some other guck.
1829 The second traversal is on the temporary chain of
1830 externals and just appends them to the global
1831 chain again, numbering them as we go. The third
1832 traversal patches pointers to symbols (using sym
1833 indexes). The last traversal was once done as
1834 part of the first pass, but that fails when a
1835 reference preceeds a definition as the definition
1836 has no number at the time we process the
1839 /* Note that symbolP will be NULL at the end of a loop
1840 if an external was at the beginning of the list (it
1841 gets moved off the list). Hence the weird check in
1844 for (symbolP
= symbol_rootP
;
1846 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
1848 if (!SF_GET_DEBUG (symbolP
))
1850 /* Debug symbols do not need all this rubbish */
1851 symbolS
*real_symbolP
;
1853 /* L* and C_EFCN symbols never merge. */
1854 if (!SF_GET_LOCAL (symbolP
)
1855 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
1856 && real_symbolP
!= symbolP
)
1858 /* FIXME-SOON: where do dups come from? Maybe tag references before definitions? xoxorich. */
1859 /* Move the debug data from the debug symbol to the
1860 real symbol. Do NOT do the oposite (i.e. move from
1861 real symbol to debug symbol and remove real symbol from the
1862 list.) Because some pointers refer to the real symbol
1863 whereas no pointers refer to the debug symbol. */
1864 c_symbol_merge (symbolP
, real_symbolP
);
1865 /* Replace the current symbol by the real one */
1866 /* The symbols will never be the last or the first
1867 because : 1st symbol is .file and 3 last symbols are
1868 .text, .data, .bss */
1869 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
1870 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
1871 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
1872 symbolP
= real_symbolP
;
1873 } /* if not local but dup'd */
1875 if (flagseen
['R'] && (S_GET_SEGMENT (symbolP
) == SEG_DATA
))
1877 S_SET_SEGMENT (symbolP
, SEG_TEXT
);
1878 } /* push data into text */
1880 resolve_symbol_value (symbolP
);
1882 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
1884 S_SET_EXTERNAL (symbolP
);
1886 else if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
1888 if (S_GET_SEGMENT (symbolP
) == SEG_TEXT
)
1890 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
1894 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
1896 } /* no storage class yet */
1898 /* Mainly to speed up if not -g */
1899 if (SF_GET_PROCESS (symbolP
))
1901 /* Handle the nested blocks auxiliary info. */
1902 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
1904 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
1905 stack_push (block_stack
, (char *) &symbolP
);
1908 register symbolS
*begin_symbolP
;
1909 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
1910 if (begin_symbolP
== (symbolS
*) 0)
1911 as_warn ("mismatched .eb");
1913 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
1916 /* If we are able to identify the type of a function, and we
1917 are out of a function (last_functionP == 0) then, the
1918 function symbol will be associated with an auxiliary
1920 if (last_functionP
== (symbolS
*) 0 &&
1921 SF_GET_FUNCTION (symbolP
))
1923 last_functionP
= symbolP
;
1925 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
1927 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1928 } /* make it at least 1 */
1930 /* Clobber possible stale .dim information. */
1931 memset (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
1932 '\0', sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
1934 /* The C_FCN doesn't need any additional information.
1935 I don't even know if this is needed for sdb. But the
1936 standard assembler generates it, so...
1938 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
1940 if (last_functionP
== (symbolS
*) 0)
1941 as_fatal ("C_EFCN symbol out of scope");
1942 SA_SET_SYM_FSIZE (last_functionP
,
1943 (long) (S_GET_VALUE (symbolP
) -
1944 S_GET_VALUE (last_functionP
)));
1945 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
1946 last_functionP
= (symbolS
*) 0;
1950 else if (SF_GET_TAG (symbolP
))
1952 /* First descriptor of a structure must point to
1953 the first slot after the structure description. */
1954 last_tagP
= symbolP
;
1957 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
1959 /* +2 take in account the current symbol */
1960 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
1962 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
1964 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
1966 symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_offset
= string_byte_count
;
1967 string_byte_count
+=
1968 strlen(GET_FILENAME_STRING(symbolP
)) + 1;
1973 if (S_GET_VALUE (symbolP
))
1975 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symbolP
), symbol_number
);
1976 S_SET_VALUE (symbolP
, 0);
1977 } /* no one points at the first .file symbol */
1978 } /* if debug or tag or eos or file */
1980 /* We must put the external symbols apart. The loader
1981 does not bomb if we do not. But the references in
1982 the endndx field for a .bb symbol are not corrected
1983 if an external symbol is removed between .bb and .be.
1984 I.e in the following case :
1985 [20] .bb endndx = 22
1988 ld will move the symbol 21 to the end of the list but
1989 endndx will still be 22 instead of 21. */
1991 if (SF_GET_LOCAL (symbolP
))
1993 /* remove C_EFCN and LOCAL (L...) symbols */
1994 /* next pointer remains valid */
1995 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2000 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2001 && !SF_GET_FUNCTION (symbolP
)
2002 #else /* not TE_I386AIX */
2003 !S_IS_DEFINED (symbolP
)
2004 && !S_IS_DEBUG (symbolP
)
2005 && !SF_GET_STATICS (symbolP
)
2006 #endif /* not TE_I386AIX */
2009 /* if external, Remove from the list */
2010 symbolS
*hold
= symbol_previous (symbolP
);
2012 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2013 symbol_clear_list_pointers (symbolP
);
2014 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2019 if (SF_GET_STRING (symbolP
))
2021 symbolP
->sy_name_offset
= string_byte_count
;
2022 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2026 symbolP
->sy_name_offset
= 0;
2027 } /* fix "long" names */
2029 symbolP
->sy_number
= symbol_number
;
2030 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2031 } /* if local symbol */
2032 } /* traverse the symbol list */
2034 for (symbolP
= symbol_externP
; symbol_externP
;)
2036 symbolS
*tmp
= symbol_externP
;
2039 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2040 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2043 if (SF_GET_STRING (tmp
))
2045 tmp
->sy_name_offset
= string_byte_count
;
2046 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2050 tmp
->sy_name_offset
= 0;
2051 } /* fix "long" names */
2053 tmp
->sy_number
= symbol_number
;
2054 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2055 } /* append the entire extern chain */
2057 /* When a tag reference preceeds the tag definition, the definition
2058 will not have a number at the time we process the reference
2059 during the first traversal. Thus, a second traversal. */
2061 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2063 if (SF_GET_TAGGED (symbolP
))
2065 SA_SET_SYM_TAGNDX (symbolP
, ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2069 know (symbol_externP
== NULL
);
2070 know (symbol_extern_lastP
== NULL
);
2072 /* FIXME-SOMEDAY I'm counting line no's here so we know what to put
2073 in the section headers, and I'm resolving the addresses since I'm
2074 not sure how to do it later. I am NOT resolving the linno's
2075 representing functions. Their symbols need a fileptr pointing to
2076 this linno when emitted. Thus, I resolve them on emit.
2079 for (lineP
= lineno_rootP
; lineP
; lineP
= lineP
->next
)
2081 if (lineP
->line
.l_lnno
> 0)
2083 lineP
->line
.l_addr
.l_paddr
+= ((fragS
*) lineP
->frag
)->fr_address
;
2089 text_lineno_number
++;
2090 } /* for each line number */
2092 H_SET_SYMBOL_TABLE_SIZE (headers
, symbol_number
);
2096 * Find strings by crawling along symbol table chain.
2100 obj_emit_strings (where
)
2105 #ifdef CROSS_COMPILE
2106 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2107 md_number_to_chars (*where
, string_byte_count
, sizeof (string_byte_count
));
2108 *where
+= sizeof (string_byte_count
);
2109 #else /* CROSS_COMPILE */
2110 append (where
, (char *) &string_byte_count
, (unsigned long) sizeof (string_byte_count
));
2111 #endif /* CROSS_COMPILE */
2113 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2115 if (S_GET_STORAGE_CLASS(symbolP
) == C_FILE
)
2117 /* May need special treatment for this auxent */
2118 if (symbolP
->sy_symbol
.ost_auxent
->x_file
.x_n
.x_zeroes
== 0)
2120 char *p
= GET_FILENAME_STRING(symbolP
);
2122 (where
,p
, strlen(p
)+1);
2125 if (SF_GET_STRING (symbolP
))
2127 append (where
, S_GET_NAME (symbolP
),
2128 (unsigned long) (strlen (S_GET_NAME (symbolP
)) + 1));
2129 } /* if it has a string */
2130 } /* walk the symbol chain */
2134 obj_pre_write_hook (headers
)
2135 object_headers
*headers
;
2137 register int text_relocation_number
= 0;
2138 register int data_relocation_number
= 0;
2139 register fixS
*fixP
;
2141 /* FIXME-SOMEDAY this should be done at fixup_segment time but I'm
2142 going to wait until I do multiple segments. xoxorich. */
2143 /* Count the number of relocation entries for text and data */
2144 for (fixP
= text_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2148 ++text_relocation_number
;
2150 /* two relocs per callj under coff. */
2153 ++text_relocation_number
;
2154 } /* if callj and not already fixed. */
2155 #endif /* TC_I960 */
2157 /* Count 2 for a constH */
2158 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2160 ++text_relocation_number
;
2163 } /* if not yet fixed */
2164 } /* for each fix */
2166 SA_SET_SCN_NRELOC (dot_text_symbol
, text_relocation_number
);
2167 /* Assign the number of line number entries for the text section */
2168 SA_SET_SCN_NLINNO (dot_text_symbol
, text_lineno_number
);
2169 /* Assign the size of the section */
2170 SA_SET_SCN_SCNLEN (dot_text_symbol
, H_GET_TEXT_SIZE (headers
));
2172 for (fixP
= data_fix_root
; fixP
; fixP
= fixP
->fx_next
)
2176 ++data_relocation_number
;
2177 } /* if still relocatable */
2179 /* Count 2 for a constH */
2180 if (fixP
->fx_r_type
== RELOC_CONSTH
)
2182 ++data_relocation_number
;
2187 SA_SET_SCN_NRELOC (dot_data_symbol
, data_relocation_number
);
2188 /* Assign the size of the section */
2189 SA_SET_SCN_SCNLEN (dot_data_symbol
, H_GET_DATA_SIZE (headers
));
2191 /* Assign the size of the section */
2192 SA_SET_SCN_SCNLEN (dot_bss_symbol
, H_GET_BSS_SIZE (headers
));
2194 /* pre write hook can add relocs (for 960 and 29k coff) so */
2195 headers
->relocation_size
= text_relocation_number
* RELSZ
+
2196 data_relocation_number
* RELSZ
;
2200 /* Fill in extra coff fields */
2202 /* Initialize general line number information. */
2203 H_SET_LINENO_SIZE (headers
, text_lineno_number
* LINESZ
);
2206 H_SET_FILE_MAGIC_NUMBER (headers
, FILE_HEADER_MAGIC
);
2207 H_SET_NUMBER_OF_SECTIONS (headers
, 3); /* text+data+bss */
2208 #ifndef OBJ_COFF_OMIT_TIMESTAMP
2209 H_SET_TIME_STAMP (headers
, (long) time ((long *) 0));
2210 #else /* OBJ_COFF_OMIT_TIMESTAMP */
2211 H_SET_TIME_STAMP (headers
, 0);
2212 #endif /* OBJ_COFF_OMIT_TIMESTAMP */
2213 H_SET_SYMBOL_TABLE_POINTER (headers
, H_GET_SYMBOL_TABLE_FILE_OFFSET (headers
));
2215 printf ("FILHSZ %x\n", FILHSZ
);
2216 printf ("OBJ_COFF_AOUTHDRSZ %x\n", OBJ_COFF_AOUTHDRSZ
);
2217 printf ("section headers %x\n", H_GET_NUMBER_OF_SECTIONS (headers
) * SCNHSZ
);
2218 printf ("get text size %x\n", H_GET_TEXT_SIZE (headers
));
2219 printf ("get data size %x\n", H_GET_DATA_SIZE (headers
));
2220 printf ("get relocation size %x\n", H_GET_RELOCATION_SIZE (headers
));
2221 printf ("get lineno size %x\n", H_GET_LINENO_SIZE (headers
));
2223 /* symbol table size allready set */
2224 H_SET_SIZEOF_OPTIONAL_HEADER (headers
, OBJ_COFF_AOUTHDRSZ
);
2226 /* Do not added the F_RELFLG for the standard COFF. The AIX linker
2227 complain on file with relocation info striped flag. */
2228 #ifdef KEEP_RELOC_INFO
2229 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2232 H_SET_FLAGS (headers
, (text_lineno_number
== 0 ? F_LNNO
: 0)
2233 | ((text_relocation_number
+ data_relocation_number
) ? 0 : F_RELFLG
)
2237 /* magic number allready set */
2238 H_SET_VERSION_STAMP (headers
, 0);
2239 /* Text, data, bss size; entry point; text_start and data_start are already set */
2241 /* Build section headers */
2243 c_section_header (&text_section_header
,
2246 H_GET_TEXT_SIZE (headers
),
2247 H_GET_TEXT_FILE_OFFSET (headers
),
2248 (SA_GET_SCN_NRELOC (dot_text_symbol
)
2249 ? H_GET_RELOCATION_FILE_OFFSET (headers
)
2252 ? H_GET_LINENO_FILE_OFFSET (headers
)
2254 SA_GET_SCN_NRELOC (dot_text_symbol
),
2256 section_alignment
[(int) SEG_TEXT
]);
2258 c_section_header (&data_section_header
,
2260 H_GET_TEXT_SIZE (headers
),
2261 H_GET_DATA_SIZE (headers
),
2262 (H_GET_DATA_SIZE (headers
)
2263 ? H_GET_DATA_FILE_OFFSET (headers
)
2265 (SA_GET_SCN_NRELOC (dot_data_symbol
)
2266 ? (H_GET_RELOCATION_FILE_OFFSET (headers
)
2267 + text_section_header
.s_nreloc
* RELSZ
)
2269 0, /* No line number information */
2270 SA_GET_SCN_NRELOC (dot_data_symbol
),
2271 0, /* No line number information */
2272 section_alignment
[(int) SEG_DATA
]);
2274 c_section_header (&bss_section_header
,
2276 H_GET_TEXT_SIZE (headers
) + H_GET_DATA_SIZE (headers
),
2277 H_GET_BSS_SIZE (headers
),
2278 0, /* No file offset */
2279 0, /* No relocation information */
2280 0, /* No line number information */
2281 0, /* No relocation information */
2282 0, /* No line number information */
2283 section_alignment
[(int) SEG_BSS
]);
2287 #ifdef BFD_ASSEMBLER
2289 symbolS
*coff_last_function
;
2292 coff_frob_symbol (symp
, punt
)
2296 static symbolS
*last_tagP
;
2297 static stack
*block_stack
;
2298 static symbolS
*set_end
;
2300 if (symp
== &abs_symbol
)
2306 if (current_lineno_sym
)
2307 coff_add_linesym ((symbolS
*) 0);
2310 block_stack
= stack_init (512, sizeof (symbolS
*));
2312 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
2313 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2315 if (!SF_GET_DEBUG (symp
))
2318 if (!SF_GET_LOCAL (symp
)
2319 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
2322 c_symbol_merge (symp
, real
);
2325 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
2327 assert (S_GET_VALUE (symp
) == 0);
2328 S_SET_EXTERNAL (symp
);
2330 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
2332 if (S_GET_SEGMENT (symp
) == text_section
)
2333 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
2335 S_SET_STORAGE_CLASS (symp
, C_STAT
);
2337 if (SF_GET_PROCESS (symp
))
2339 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
2341 if (!strcmp (S_GET_NAME (symp
), ".bb"))
2342 stack_push (block_stack
, (char *) &symp
);
2346 begin
= *(symbolS
**) stack_pop (block_stack
);
2348 as_warn ("mismatched .eb");
2353 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
2355 union internal_auxent
*auxp
;
2356 coff_last_function
= symp
;
2357 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
2358 S_SET_NUMBER_AUXILIARY (symp
, 1);
2359 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
2360 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
2361 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
2363 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
2365 if (coff_last_function
== 0)
2366 as_fatal ("C_EFCN symbol out of scope");
2367 SA_SET_SYM_FSIZE (coff_last_function
,
2368 (long) (S_GET_VALUE (symp
)
2369 - S_GET_VALUE (coff_last_function
)));
2370 set_end
= coff_last_function
;
2371 coff_last_function
= 0;
2374 else if (SF_GET_TAG (symp
))
2376 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
2377 set_end
= last_tagP
;
2378 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
2380 if (S_GET_VALUE (symp
))
2382 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
2383 S_SET_VALUE (symp
, 0);
2386 if (S_IS_EXTERNAL (symp
))
2387 S_SET_STORAGE_CLASS (symp
, C_EXT
);
2388 else if (SF_GET_LOCAL (symp
))
2393 if (set_end
!= (symbolS
*) NULL
2396 SA_SET_SYM_ENDNDX (set_end
, symp
);
2400 if (coffsymbol (symp
->bsym
)->lineno
)
2403 struct line_no
*lptr
;
2406 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2407 for (i
= 0; lptr
; lptr
= lptr
->next
)
2410 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
2411 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, n
* sizeof (alent
));
2412 coffsymbol (symp
->bsym
)->lineno
= l
;
2413 for (i
= n
- 1; i
> 0; i
--)
2416 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
2424 * implement the .section pseudo op:
2425 * .section name {, "flags"}
2427 * | +--- optional flags: 'b' for bss
2429 * +-- section name 'l' for lib
2433 * 'd' (apparently m88k for data)
2435 * But if the argument is not a quoted string, treat it as a
2436 * subsegment number.
2440 obj_coff_section (ignore
)
2443 /* Strip out the section name */
2451 section_name
= input_line_pointer
;
2452 c
= get_symbol_end ();
2454 name
= xmalloc (input_line_pointer
- section_name
+ 1);
2455 strcpy (name
, section_name
);
2457 *input_line_pointer
= c
;
2462 flags
= SEC_NO_FLAGS
;
2464 if (*input_line_pointer
== ',')
2466 ++input_line_pointer
;
2468 if (*input_line_pointer
!= '"')
2469 exp
= get_absolute_expression ();
2472 ++input_line_pointer
;
2473 while (*input_line_pointer
!= '"'
2474 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
2476 switch (*input_line_pointer
)
2478 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
2479 case 'n': flags
&=~ SEC_LOAD
; break;
2481 case 'w': flags
&=~ SEC_READONLY
; break;
2482 case 'x': flags
|= SEC_CODE
; break;
2484 case 'i': /* STYP_INFO */
2485 case 'l': /* STYP_LIB */
2486 case 'o': /* STYP_OVER */
2487 as_warn ("unsupported section attribute '%c'",
2488 *input_line_pointer
);
2492 as_warn("unknown section attribute '%c'",
2493 *input_line_pointer
);
2496 ++input_line_pointer
;
2498 if (*input_line_pointer
== '"')
2499 ++input_line_pointer
;
2503 sec
= subseg_new (name
, (subsegT
) exp
);
2505 if (flags
!= SEC_NO_FLAGS
)
2507 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
2508 as_warn ("error setting flags for \"%s\": %s",
2509 bfd_section_name (stdoutput
, sec
),
2510 bfd_errmsg (bfd_get_error ()));
2517 if (symbol_rootP
== NULL
2518 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2520 assert (previous_file_symbol
== 0);
2521 c_dot_file_symbol ("fake");
2524 #endif /* BFD_ASSEMBLER */
2532 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
2533 } /* s_get_name() */
2540 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2542 #ifdef BFD_ASSEMBLER
2543 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
2544 (unsigned long) symbolP
,
2545 S_GET_NAME(symbolP
),
2546 (long) S_GET_DATA_TYPE(symbolP
),
2547 S_GET_STORAGE_CLASS(symbolP
),
2548 (int) S_GET_SEGMENT(symbolP
));
2550 printf ("%3ld: 0x%lx \"%s\" type = %ld, class = %d, segment = %d\n",
2552 (unsigned long) symbolP
,
2553 S_GET_NAME (symbolP
),
2554 (long) S_GET_DATA_TYPE (symbolP
),
2555 S_GET_STORAGE_CLASS (symbolP
),
2556 (int) S_GET_SEGMENT (symbolP
));
2563 /* end of obj-coff.c */