1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 1996
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* I think this is probably always correct. */
26 #ifndef KEEP_RELOC_INFO
27 #define KEEP_RELOC_INFO
31 /* structure used to keep the filenames which
32 are too long around so that we can stick them
33 into the string table */
37 struct filename_list
*next
;
40 static struct filename_list
*filename_list_head
;
41 static struct filename_list
*filename_list_tail
;
43 const char *s_get_name
PARAMS ((symbolS
* s
));
44 static symbolS
*def_symbol_in_progress
;
50 unsigned long chunk_size
;
51 unsigned long element_size
;
54 unsigned long pointer
;
59 stack_init (chunk_size
, element_size
)
60 unsigned long chunk_size
;
61 unsigned long element_size
;
65 st
= (stack
*) malloc (sizeof (stack
));
68 st
->data
= malloc (chunk_size
);
75 st
->size
= chunk_size
;
76 st
->chunk_size
= chunk_size
;
77 st
->element_size
= element_size
;
82 /* Not currently used. */
93 stack_push (st
, element
)
97 if (st
->pointer
+ st
->element_size
>= st
->size
)
99 st
->size
+= st
->chunk_size
;
100 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
103 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
104 st
->pointer
+= st
->element_size
;
105 return st
->data
+ st
->pointer
;
112 if (st
->pointer
< st
->element_size
)
117 st
->pointer
-= st
->element_size
;
118 return st
->data
+ st
->pointer
;
122 * Maintain a list of the tagnames of the structres.
125 static struct hash_control
*tag_hash
;
130 tag_hash
= hash_new ();
134 tag_insert (name
, symbolP
)
138 const char *error_string
;
140 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
142 as_fatal ("Inserting \"%s\" into structure table failed: %s",
151 #ifdef STRIP_UNDERSCORE
154 #endif /* STRIP_UNDERSCORE */
155 return (symbolS
*) hash_find (tag_hash
, name
);
159 tag_find_or_make (name
)
164 if ((symbolP
= tag_find (name
)) == NULL
)
166 symbolP
= symbol_new (name
, undefined_section
,
167 0, &zero_address_frag
);
169 tag_insert (S_GET_NAME (symbolP
), symbolP
);
171 symbol_table_insert (symbolP
);
182 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
184 #define GET_FILENAME_STRING(X) \
185 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
189 fetch_coff_debug_section ()
191 static segT debug_section
;
195 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
197 debug_section
= s
->section
;
199 return debug_section
;
203 SA_SET_SYM_ENDNDX (sym
, val
)
207 combined_entry_type
*entry
, *p
;
209 entry
= &coffsymbol (sym
->bsym
)->native
[1];
210 p
= coffsymbol (val
->bsym
)->native
;
211 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
216 SA_SET_SYM_TAGNDX (sym
, val
)
220 combined_entry_type
*entry
, *p
;
222 entry
= &coffsymbol (sym
->bsym
)->native
[1];
223 p
= coffsymbol (val
->bsym
)->native
;
224 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
229 S_GET_DATA_TYPE (sym
)
232 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
236 S_SET_DATA_TYPE (sym
, val
)
240 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
245 S_GET_STORAGE_CLASS (sym
)
248 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
252 S_SET_STORAGE_CLASS (sym
, val
)
256 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
260 /* Merge a debug symbol containing debug information into a normal symbol. */
263 c_symbol_merge (debug
, normal
)
267 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
268 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
270 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
271 /* take the most we have */
272 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
274 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
276 /* Move all the auxiliary information. */
277 /* @@ How many fields do we want to preserve? Would it make more
278 sense to pick and choose those we want to copy? Should look
279 into this further.... [raeburn:19920512.2209EST] */
281 linenos
= coffsymbol (normal
->bsym
)->lineno
;
282 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
283 (char *) &coffsymbol (debug
->bsym
)->native
,
284 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
285 coffsymbol (normal
->bsym
)->lineno
= linenos
;
288 /* Move the debug flags. */
289 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
292 static symbolS
*previous_file_symbol
;
294 c_dot_file_symbol (filename
)
299 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
301 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
302 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
304 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
311 listing_source_file (filename
);
316 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
318 previous_file_symbol
= symbolP
;
320 /* Make sure that the symbol is first on the symbol chain */
321 if (symbol_rootP
!= symbolP
)
323 if (symbolP
== symbol_lastP
)
325 symbol_lastP
= symbol_lastP
->sy_previous
;
326 } /* if it was the last thing on the list */
328 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
329 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
330 symbol_rootP
= symbolP
;
331 } /* if not first on the list */
335 * Build a 'section static' symbol.
339 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
343 unsigned short nreloc
;
344 unsigned short nlnno
;
348 symbolP
= symbol_new (name
,
357 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
358 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
360 SA_SET_SCN_SCNLEN (symbolP
, length
);
361 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
362 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
364 SF_SET_STATICS (symbolP
);
366 return (char *) symbolP
;
369 /* Line number handling */
372 struct line_no
*next
;
379 /* Symbol of last function, which we should hang line#s off of. */
380 static symbolS
*line_fsym
;
382 #define in_function() (line_fsym != 0)
383 #define clear_function() (line_fsym = 0)
384 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
388 obj_symbol_new_hook (symbolP
)
391 char underscore
= 0; /* Symbol has leading _ */
394 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
395 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
397 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
399 S_SET_DATA_TYPE (symbolP
, T_NULL
);
400 S_SET_STORAGE_CLASS (symbolP
, 0);
401 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
403 if (S_IS_STRING (symbolP
))
404 SF_SET_STRING (symbolP
);
405 if (!underscore
&& S_IS_LOCAL (symbolP
))
406 SF_SET_LOCAL (symbolP
);
411 * Handle .ln directives.
414 static symbolS
*current_lineno_sym
;
415 static struct line_no
*line_nos
;
416 /* @@ Blindly assume all .ln directives will be in the .text section... */
420 add_lineno (frag
, offset
, num
)
425 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
426 sizeof (struct line_no
));
427 if (!current_lineno_sym
)
431 new_line
->next
= line_nos
;
432 new_line
->frag
= frag
;
433 new_line
->l
.line_number
= num
;
434 new_line
->l
.u
.offset
= offset
;
440 coff_add_linesym (sym
)
445 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
449 current_lineno_sym
= sym
;
453 obj_coff_ln (appline
)
458 if (! appline
&& def_symbol_in_progress
!= NULL
)
460 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
461 demand_empty_rest_of_line ();
465 l
= get_absolute_expression ();
468 add_lineno (frag_now
, frag_now_fix (), l
);
478 l
+= coff_line_base
- 1;
479 listing_source_line (l
);
484 demand_empty_rest_of_line ();
490 * Handle .def directives.
492 * One might ask : why can't we symbol_new if the symbol does not
493 * already exist and fill it with debug information. Because of
494 * the C_EFCN special symbol. It would clobber the value of the
495 * function symbol before we have a chance to notice that it is
496 * a C_EFCN. And a second reason is that the code is more clear this
497 * way. (at least I think it is :-).
501 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
502 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
503 *input_line_pointer == '\t') \
504 input_line_pointer++;
510 char name_end
; /* Char after the end of name */
511 char *symbol_name
; /* Name of the debug symbol */
512 char *symbol_name_copy
; /* Temporary copy of the name */
513 unsigned int symbol_name_length
;
515 if (def_symbol_in_progress
!= NULL
)
517 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
518 demand_empty_rest_of_line ();
520 } /* if not inside .def/.endef */
524 symbol_name
= input_line_pointer
;
525 #ifdef STRIP_UNDERSCORE
526 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
528 #endif /* STRIP_UNDERSCORE */
530 name_end
= get_symbol_end ();
531 symbol_name_length
= strlen (symbol_name
);
532 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
533 strcpy (symbol_name_copy
, symbol_name
);
535 /* Initialize the new symbol */
536 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
537 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
538 S_SET_VALUE (def_symbol_in_progress
, 0);
540 if (S_IS_STRING (def_symbol_in_progress
))
541 SF_SET_STRING (def_symbol_in_progress
);
543 *input_line_pointer
= name_end
;
545 demand_empty_rest_of_line ();
548 unsigned int dim_index
;
551 obj_coff_endef (ignore
)
555 /* DIM BUG FIX sac@cygnus.com */
557 if (def_symbol_in_progress
== NULL
)
559 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
560 demand_empty_rest_of_line ();
562 } /* if not inside .def/.endef */
564 /* Set the section number according to storage class. */
565 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
570 SF_SET_TAG (def_symbol_in_progress
);
571 /* intentional fallthrough */
574 SF_SET_DEBUG (def_symbol_in_progress
);
575 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
579 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
580 /* intentional fallthrough */
582 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
583 /* intentional fallthrough */
587 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
589 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
590 if (name
[1] == 'b' && name
[2] == 'f')
592 if (! in_function ())
593 as_warn ("`%s' symbol without preceding function", name
);
594 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
595 /* Will need relocating */
596 SF_SET_PROCESS (def_symbol_in_progress
);
604 #endif /* C_AUTOARG */
614 SF_SET_DEBUG (def_symbol_in_progress
);
615 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
621 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
627 as_warn ("unexpected storage class %d",
628 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
630 } /* switch on storage class */
632 /* Now that we have built a debug symbol, try to find if we should
633 merge with an existing symbol or not. If a symbol is C_EFCN or
634 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
636 /* Two cases for functions. Either debug followed by definition or
637 definition followed by debug. For definition first, we will
638 merge the debug symbol into the definition. For debug first, the
639 lineno entry MUST point to the definition function or else it
640 will point off into space when obj_crawl_symbol_chain() merges
641 the debug symbol into the real symbol. Therefor, let's presume
642 the debug symbol is a real function reference. */
644 /* FIXME-SOON If for some reason the definition label/symbol is
645 never seen, this will probably leave an undefined symbol at link
648 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
649 || (!strcmp (bfd_get_section_name (stdoutput
,
650 S_GET_SEGMENT (def_symbol_in_progress
)),
652 && !SF_GET_TAG (def_symbol_in_progress
))
653 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
654 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
656 if (def_symbol_in_progress
!= symbol_lastP
)
657 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
662 /* This symbol already exists, merge the newly created symbol
663 into the old one. This is not mandatory. The linker can
664 handle duplicate symbols correctly. But I guess that it save
665 a *lot* of space if the assembly file defines a lot of
668 /* The debug entry (def_symbol_in_progress) is merged into the
669 previous definition. */
671 c_symbol_merge (def_symbol_in_progress
, symbolP
);
672 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
673 def_symbol_in_progress
= symbolP
;
675 if (SF_GET_FUNCTION (def_symbol_in_progress
)
676 || SF_GET_TAG (def_symbol_in_progress
))
678 /* For functions, and tags, the symbol *must* be where the
679 debug symbol appears. Move the existing symbol to the
681 /* If it already is at the end of the symbol list, do nothing */
682 if (def_symbol_in_progress
!= symbol_lastP
)
684 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
685 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
690 if (SF_GET_TAG (def_symbol_in_progress
)
691 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
693 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
696 if (SF_GET_FUNCTION (def_symbol_in_progress
))
698 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
699 set_function (def_symbol_in_progress
);
700 SF_SET_PROCESS (def_symbol_in_progress
);
704 /* That is, if this is the first time we've seen the
706 symbol_table_insert (def_symbol_in_progress
);
707 } /* definition follows debug */
708 } /* Create the line number entry pointing to the function being defined */
710 def_symbol_in_progress
= NULL
;
711 demand_empty_rest_of_line ();
715 obj_coff_dim (ignore
)
720 if (def_symbol_in_progress
== NULL
)
722 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
723 demand_empty_rest_of_line ();
725 } /* if not inside .def/.endef */
727 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
729 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
732 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
733 get_absolute_expression ());
735 switch (*input_line_pointer
)
738 input_line_pointer
++;
742 as_warn ("badly formed .dim directive ignored");
743 /* intentional fallthrough */
751 demand_empty_rest_of_line ();
755 obj_coff_line (ignore
)
760 if (def_symbol_in_progress
== NULL
)
762 /* Probably stabs-style line? */
767 this_base
= get_absolute_expression ();
768 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
769 coff_line_base
= this_base
;
771 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
772 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
774 demand_empty_rest_of_line ();
777 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
782 listing_source_line ((unsigned int) coff_line_base
);
788 obj_coff_size (ignore
)
791 if (def_symbol_in_progress
== NULL
)
793 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
794 demand_empty_rest_of_line ();
796 } /* if not inside .def/.endef */
798 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
799 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
800 demand_empty_rest_of_line ();
804 obj_coff_scl (ignore
)
807 if (def_symbol_in_progress
== NULL
)
809 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
810 demand_empty_rest_of_line ();
812 } /* if not inside .def/.endef */
814 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
815 demand_empty_rest_of_line ();
819 obj_coff_tag (ignore
)
825 if (def_symbol_in_progress
== NULL
)
827 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
828 demand_empty_rest_of_line ();
832 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
833 symbol_name
= input_line_pointer
;
834 name_end
= get_symbol_end ();
836 /* Assume that the symbol referred to by .tag is always defined.
837 This was a bad assumption. I've added find_or_make. xoxorich. */
838 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
839 tag_find_or_make (symbol_name
));
840 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
842 as_warn ("tag not found for .tag %s", symbol_name
);
845 SF_SET_TAGGED (def_symbol_in_progress
);
846 *input_line_pointer
= name_end
;
848 demand_empty_rest_of_line ();
852 obj_coff_type (ignore
)
855 if (def_symbol_in_progress
== NULL
)
857 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
858 demand_empty_rest_of_line ();
860 } /* if not inside .def/.endef */
862 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
864 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
865 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
867 SF_SET_FUNCTION (def_symbol_in_progress
);
868 } /* is a function */
870 demand_empty_rest_of_line ();
874 obj_coff_val (ignore
)
877 if (def_symbol_in_progress
== NULL
)
879 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
880 demand_empty_rest_of_line ();
882 } /* if not inside .def/.endef */
884 if (is_name_beginner (*input_line_pointer
))
886 char *symbol_name
= input_line_pointer
;
887 char name_end
= get_symbol_end ();
889 if (!strcmp (symbol_name
, "."))
891 def_symbol_in_progress
->sy_frag
= frag_now
;
892 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
893 /* If the .val is != from the .def (e.g. statics) */
895 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
897 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
898 def_symbol_in_progress
->sy_value
.X_add_symbol
=
899 symbol_find_or_make (symbol_name
);
900 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
901 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
903 /* If the segment is undefined when the forward reference is
904 resolved, then copy the segment id from the forward
906 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
908 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
909 *input_line_pointer
= name_end
;
913 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
914 } /* if symbol based */
916 demand_empty_rest_of_line ();
920 obj_read_begin_hook ()
922 /* These had better be the same. Usually 18 bytes. */
924 know (sizeof (SYMENT
) == sizeof (AUXENT
));
925 know (SYMESZ
== AUXESZ
);
931 symbolS
*coff_last_function
;
934 coff_frob_symbol (symp
, punt
)
938 static symbolS
*last_tagP
;
939 static stack
*block_stack
;
940 static symbolS
*set_end
;
941 symbolS
*next_set_end
= NULL
;
943 if (symp
== &abs_symbol
)
949 if (current_lineno_sym
)
950 coff_add_linesym ((symbolS
*) 0);
953 block_stack
= stack_init (512, sizeof (symbolS
*));
955 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
956 S_SET_STORAGE_CLASS (symp
, C_EXT
);
958 if (!SF_GET_DEBUG (symp
))
961 if (!SF_GET_LOCAL (symp
)
962 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
965 c_symbol_merge (symp
, real
);
968 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
970 assert (S_GET_VALUE (symp
) == 0);
971 S_SET_EXTERNAL (symp
);
973 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
975 if (S_GET_SEGMENT (symp
) == text_section
976 && symp
!= seg_info (text_section
)->sym
)
977 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
979 S_SET_STORAGE_CLASS (symp
, C_STAT
);
981 if (SF_GET_PROCESS (symp
))
983 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
985 if (!strcmp (S_GET_NAME (symp
), ".bb"))
986 stack_push (block_stack
, (char *) &symp
);
990 begin
= *(symbolS
**) stack_pop (block_stack
);
992 as_warn ("mismatched .eb");
994 next_set_end
= begin
;
997 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
999 union internal_auxent
*auxp
;
1000 coff_last_function
= symp
;
1001 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1002 S_SET_NUMBER_AUXILIARY (symp
, 1);
1003 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
1004 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1005 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1007 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1009 if (coff_last_function
== 0)
1010 as_fatal ("C_EFCN symbol out of scope");
1011 SA_SET_SYM_FSIZE (coff_last_function
,
1012 (long) (S_GET_VALUE (symp
)
1013 - S_GET_VALUE (coff_last_function
)));
1014 next_set_end
= coff_last_function
;
1015 coff_last_function
= 0;
1018 else if (SF_GET_TAG (symp
))
1020 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1021 next_set_end
= last_tagP
;
1022 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1024 if (S_GET_VALUE (symp
))
1026 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1027 S_SET_VALUE (symp
, 0);
1030 if (S_IS_EXTERNAL (symp
))
1031 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1032 else if (SF_GET_LOCAL (symp
))
1035 if (SF_GET_FUNCTION (symp
))
1036 symp
->bsym
->flags
|= BSF_FUNCTION
;
1042 /* This is pretty horrible, but we have to set *punt correctly in
1043 order to call SA_SET_SYM_ENDNDX correctly. */
1044 if (! symp
->sy_used_in_reloc
1045 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1046 || (! S_IS_EXTERNAL (symp
)
1047 && ! symp
->sy_tc
.output
1048 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1052 if (set_end
!= (symbolS
*) NULL
1055 SA_SET_SYM_ENDNDX (set_end
, symp
);
1059 if (next_set_end
!= NULL
1061 set_end
= next_set_end
;
1063 if (coffsymbol (symp
->bsym
)->lineno
)
1066 struct line_no
*lptr
;
1069 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1070 for (i
= 0; lptr
; lptr
= lptr
->next
)
1072 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1074 /* We need i entries for line numbers, plus 1 for the first
1075 entry which BFD will override, plus 1 for the last zero
1076 entry (a marker for BFD). */
1077 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1078 coffsymbol (symp
->bsym
)->lineno
= l
;
1079 l
[i
+ 1].line_number
= 0;
1080 l
[i
+ 1].u
.sym
= NULL
;
1084 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1092 coff_adjust_section_syms (abfd
, sec
, x
)
1098 segment_info_type
*seginfo
= seg_info (sec
);
1099 int nlnno
, nrelocs
= 0;
1101 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1102 tc-ppc.c. Do not get confused by it. */
1103 if (seginfo
== NULL
)
1106 if (!strcmp (sec
->name
, ".text"))
1107 nlnno
= coff_n_line_nos
;
1111 /* @@ Hope that none of the fixups expand to more than one reloc
1113 fixS
*fixp
= seginfo
->fix_root
;
1116 fixp
= fixp
->fx_next
;
1120 if (bfd_get_section_size_before_reloc (sec
) == 0
1121 && nrelocs
== 0 && nlnno
== 0)
1123 secsym
= section_symbol (sec
);
1124 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1125 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1131 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1135 * implement the .section pseudo op:
1136 * .section name {, "flags"}
1138 * | +--- optional flags: 'b' for bss
1140 * +-- section name 'l' for lib
1144 * 'd' (apparently m88k for data)
1146 * But if the argument is not a quoted string, treat it as a
1147 * subsegment number.
1151 obj_coff_section (ignore
)
1154 /* Strip out the section name */
1170 section_name
= input_line_pointer
;
1171 c
= get_symbol_end ();
1173 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1174 strcpy (name
, section_name
);
1176 *input_line_pointer
= c
;
1181 flags
= SEC_NO_FLAGS
;
1183 if (*input_line_pointer
== ',')
1185 ++input_line_pointer
;
1187 if (*input_line_pointer
!= '"')
1188 exp
= get_absolute_expression ();
1191 ++input_line_pointer
;
1192 while (*input_line_pointer
!= '"'
1193 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1195 switch (*input_line_pointer
)
1197 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1198 case 'n': flags
&=~ SEC_LOAD
; break;
1200 case 'w': flags
&=~ SEC_READONLY
; break;
1201 case 'x': flags
|= SEC_CODE
; break;
1203 case 'i': /* STYP_INFO */
1204 case 'l': /* STYP_LIB */
1205 case 'o': /* STYP_OVER */
1206 as_warn ("unsupported section attribute '%c'",
1207 *input_line_pointer
);
1211 as_warn("unknown section attribute '%c'",
1212 *input_line_pointer
);
1215 ++input_line_pointer
;
1217 if (*input_line_pointer
== '"')
1218 ++input_line_pointer
;
1222 sec
= subseg_new (name
, (subsegT
) exp
);
1224 if (flags
!= SEC_NO_FLAGS
)
1226 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1227 as_warn ("error setting flags for \"%s\": %s",
1228 bfd_section_name (stdoutput
, sec
),
1229 bfd_errmsg (bfd_get_error ()));
1234 coff_adjust_symtab ()
1236 if (symbol_rootP
== NULL
1237 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1239 assert (previous_file_symbol
== 0);
1240 c_dot_file_symbol ("fake");
1245 coff_frob_section (sec
)
1251 bfd_vma size
, n_entries
, mask
;
1253 /* The COFF back end in BFD requires that all section sizes be
1254 rounded up to multiples of the corresponding section alignments.
1255 Seems kinda silly to me, but that's the way it is. */
1256 size
= bfd_get_section_size_before_reloc (sec
);
1257 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1260 size
= (size
+ mask
) & ~mask
;
1261 bfd_set_section_size (stdoutput
, sec
, size
);
1264 /* If the section size is non-zero, the section symbol needs an aux
1265 entry associated with it, indicating the size. We don't know
1266 all the values yet; coff_frob_symbol will fill them in later. */
1269 symbolS
*secsym
= section_symbol (sec
);
1271 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1272 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1273 SF_SET_STATICS (secsym
);
1274 SA_SET_SCN_SCNLEN (secsym
, size
);
1277 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1278 #ifndef STAB_SECTION_NAME
1279 #define STAB_SECTION_NAME ".stab"
1281 #ifndef STAB_STRING_SECTION_NAME
1282 #define STAB_STRING_SECTION_NAME ".stabstr"
1284 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1288 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1289 /* size is already rounded up, since other section will be listed first */
1290 size
= bfd_get_section_size_before_reloc (strsec
);
1292 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1294 /* Find first non-empty frag. It should be large enough. */
1295 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1296 while (fragp
&& fragp
->fr_fix
== 0)
1297 fragp
= fragp
->fr_next
;
1298 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1300 /* Store the values. */
1301 p
= fragp
->fr_literal
;
1302 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1303 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1307 obj_coff_init_stab_section (seg
)
1313 unsigned int stroff
;
1315 /* Make space for this first symbol. */
1319 as_where (&file
, (unsigned int *) NULL
);
1320 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1321 strcpy (stabstr_name
, seg
->name
);
1322 strcat (stabstr_name
, "str");
1323 stroff
= get_stab_string_offset (file
, stabstr_name
);
1325 md_number_to_chars (p
, stroff
, 4);
1334 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1342 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1344 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1345 (unsigned long) symbolP
,
1346 S_GET_NAME(symbolP
),
1347 (long) S_GET_DATA_TYPE(symbolP
),
1348 S_GET_STORAGE_CLASS(symbolP
),
1349 (int) S_GET_SEGMENT(symbolP
));
1355 #else /* not BFD_ASSEMBLER */
1358 /* This is needed because we include internal bfd things. */
1362 #include "libcoff.h"
1364 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1365 that we can stick sections together without causing trouble. */
1367 #define NOP_OPCODE 0x00
1370 /* The zeroes if symbol name is longer than 8 chars */
1371 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1373 #define MIN(a,b) ((a) < (b)? (a) : (b))
1374 /* This vector is used to turn an internal segment into a section #
1375 suitable for insertion into a coff symbol table
1378 const short seg_N_TYPE
[] =
1379 { /* in: segT out: N_TYPE bits */
1391 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1392 C_UNDEF_SECTION
, /* SEG_GOOF */
1393 C_UNDEF_SECTION
, /* SEG_EXPR */
1394 C_DEBUG_SECTION
, /* SEG_DEBUG */
1395 C_NTV_SECTION
, /* SEG_NTV */
1396 C_PTV_SECTION
, /* SEG_PTV */
1397 C_REGISTER_SECTION
, /* SEG_REGISTER */
1400 int function_lineoff
= -1; /* Offset in line#s where the last function
1401 started (the odd entry for line #0) */
1403 static symbolS
*last_line_symbol
;
1405 /* Add 4 to the real value to get the index and compensate the
1406 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1407 section number into a segment number
1409 static symbolS
*previous_file_symbol
;
1410 void c_symbol_merge ();
1411 static int line_base
;
1413 symbolS
*c_section_symbol ();
1416 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1417 segT this_segment_type
));
1420 static void fixup_mdeps
PARAMS ((fragS
*,
1425 static void fill_section
PARAMS ((bfd
* abfd
,
1430 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1435 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1436 symbolS
* symbol_rootP
));
1438 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1440 static void obj_coff_lcomm
PARAMS ((int));
1441 static void obj_coff_text
PARAMS ((int));
1442 static void obj_coff_data
PARAMS ((int));
1443 static void obj_coff_bss
PARAMS ((int));
1444 static void obj_coff_ident
PARAMS ((int));
1445 void obj_coff_section
PARAMS ((int));
1449 We allow more than just the standard 3 sections, infact, we allow
1450 10 sections, (though the usual three have to be there).
1452 This structure performs the mappings for us:
1463 static const seg_info_type seg_info_off_by_4
[N_SEG
] =
1494 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1496 static relax_addressT
1497 relax_align (address
, alignment
)
1498 relax_addressT address
;
1501 relax_addressT mask
;
1502 relax_addressT new_address
;
1504 mask
= ~((~0) << alignment
);
1505 new_address
= (address
+ mask
) & (~mask
);
1506 return (new_address
- address
);
1514 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1519 /* calculate the size of the frag chain and fill in the section header
1520 to contain all of it, also fill in the addr of the sections */
1522 size_section (abfd
, idx
)
1527 unsigned int size
= 0;
1528 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1531 size
= frag
->fr_address
;
1532 if (frag
->fr_address
!= size
)
1534 fprintf (stderr
, "Out of step\n");
1535 size
= frag
->fr_address
;
1538 switch (frag
->fr_type
)
1540 #ifdef TC_COFF_SIZEMACHDEP
1541 case rs_machine_dependent
:
1542 size
+= TC_COFF_SIZEMACHDEP (frag
);
1546 assert (frag
->fr_symbol
== 0);
1549 size
+= frag
->fr_fix
;
1550 size
+= frag
->fr_offset
* frag
->fr_var
;
1554 size
+= frag
->fr_fix
;
1555 size
+= relax_align (size
, frag
->fr_offset
);
1558 BAD_CASE (frag
->fr_type
);
1561 frag
= frag
->fr_next
;
1563 segment_info
[idx
].scnhdr
.s_size
= size
;
1569 count_entries_in_chain (idx
)
1572 unsigned int nrelocs
;
1575 /* Count the relocations */
1576 fixup_ptr
= segment_info
[idx
].fix_root
;
1578 while (fixup_ptr
!= (fixS
*) NULL
)
1580 if (TC_COUNT_RELOC (fixup_ptr
))
1583 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1592 fixup_ptr
= fixup_ptr
->fx_next
;
1599 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1601 /* AUX's ld expects relocations to be sorted */
1603 compare_external_relocs (x
, y
)
1607 struct external_reloc
*a
= (struct external_reloc
*) x
;
1608 struct external_reloc
*b
= (struct external_reloc
*) y
;
1609 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1610 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1611 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1616 /* output all the relocations for a section */
1618 do_relocs_for (abfd
, h
, file_cursor
)
1621 unsigned long *file_cursor
;
1623 unsigned int nrelocs
;
1625 unsigned long reloc_start
= *file_cursor
;
1627 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1629 if (segment_info
[idx
].scnhdr
.s_name
[0])
1631 struct external_reloc
*ext_ptr
;
1632 struct external_reloc
*external_reloc_vec
;
1633 unsigned int external_reloc_size
;
1634 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1635 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1636 nrelocs
= count_entries_in_chain (idx
);
1639 /* Bypass this stuff if no relocs. This also incidentally
1640 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1642 external_reloc_size
= nrelocs
* RELSZ
;
1643 external_reloc_vec
=
1644 (struct external_reloc
*) malloc (external_reloc_size
);
1646 ext_ptr
= external_reloc_vec
;
1648 /* Fill in the internal coff style reloc struct from the
1649 internal fix list. */
1652 struct internal_reloc intr
;
1654 /* Only output some of the relocations */
1655 if (TC_COUNT_RELOC (fix_ptr
))
1657 #ifdef TC_RELOC_MANGLE
1658 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1663 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1665 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1667 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1669 #ifdef TC_KEEP_FX_OFFSET
1670 intr
.r_offset
= fix_ptr
->fx_offset
;
1675 while (S_GET_SEGMENT (symbol_ptr
) == undefined_section
1676 && symbol_ptr
->sy_value
.X_op
== O_symbol
)
1677 symbol_ptr
= symbol_ptr
->sy_value
.X_add_symbol
;
1679 /* Turn the segment of the symbol into an offset. */
1682 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1685 intr
.r_symndx
= dot
->sy_number
;
1689 intr
.r_symndx
= symbol_ptr
->sy_number
;
1699 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1702 #if defined(TC_A29K)
1704 /* The 29k has a special kludge for the high 16 bit
1705 reloc. Two relocations are emited, R_IHIHALF,
1706 and R_IHCONST. The second one doesn't contain a
1707 symbol, but uses the value for offset. */
1709 if (intr
.r_type
== R_IHIHALF
)
1711 /* now emit the second bit */
1712 intr
.r_type
= R_IHCONST
;
1713 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1714 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1720 fix_ptr
= fix_ptr
->fx_next
;
1724 /* Sort the reloc table */
1725 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1726 sizeof (struct external_reloc
), compare_external_relocs
);
1729 /* Write out the reloc table */
1730 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1732 free (external_reloc_vec
);
1734 /* Fill in section header info. */
1735 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1736 *file_cursor
+= external_reloc_size
;
1737 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1742 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1746 /* Set relocation_size field in file headers */
1747 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1751 /* run through a frag chain and write out the data to go with it, fill
1752 in the scnhdrs with the info on the file postions
1755 fill_section (abfd
, h
, file_cursor
)
1758 unsigned long *file_cursor
;
1762 unsigned int paddr
= 0;
1764 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1766 unsigned int offset
= 0;
1767 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1773 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1780 buffer
= xmalloc (s
->s_size
);
1781 s
->s_scnptr
= *file_cursor
;
1783 know (s
->s_paddr
== paddr
);
1785 if (strcmp (s
->s_name
, ".text") == 0)
1786 s
->s_flags
|= STYP_TEXT
;
1787 else if (strcmp (s
->s_name
, ".data") == 0)
1788 s
->s_flags
|= STYP_DATA
;
1789 else if (strcmp (s
->s_name
, ".bss") == 0)
1792 s
->s_flags
|= STYP_BSS
;
1794 /* @@ Should make the i386 and a29k coff targets define
1795 COFF_NOLOAD_PROBLEM, and have only one test here. */
1798 #ifndef COFF_NOLOAD_PROBLEM
1799 /* Apparently the SVR3 linker (and exec syscall) and UDI
1800 mondfe progrem are confused by noload sections. */
1801 s
->s_flags
|= STYP_NOLOAD
;
1806 else if (strcmp (s
->s_name
, ".lit") == 0)
1807 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1808 else if (strcmp (s
->s_name
, ".init") == 0)
1809 s
->s_flags
|= STYP_TEXT
;
1810 else if (strcmp (s
->s_name
, ".fini") == 0)
1811 s
->s_flags
|= STYP_TEXT
;
1812 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1813 s
->s_flags
|= STYP_INFO
;
1817 unsigned int fill_size
;
1818 switch (frag
->fr_type
)
1820 case rs_machine_dependent
:
1823 memcpy (buffer
+ frag
->fr_address
,
1825 (unsigned int) frag
->fr_fix
);
1826 offset
+= frag
->fr_fix
;
1831 assert (frag
->fr_symbol
== 0);
1838 memcpy (buffer
+ frag
->fr_address
,
1840 (unsigned int) frag
->fr_fix
);
1841 offset
+= frag
->fr_fix
;
1844 fill_size
= frag
->fr_var
;
1845 if (fill_size
&& frag
->fr_offset
> 0)
1848 unsigned int off
= frag
->fr_fix
;
1849 for (count
= frag
->fr_offset
; count
; count
--)
1851 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1853 memcpy (buffer
+ frag
->fr_address
+ off
,
1854 frag
->fr_literal
+ frag
->fr_fix
,
1857 offset
+= fill_size
;
1862 case rs_broken_word
:
1867 frag
= frag
->fr_next
;
1872 if (s
->s_scnptr
!= 0)
1874 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1875 *file_cursor
+= s
->s_size
;
1884 /* Coff file generation & utilities */
1887 coff_header_append (abfd
, h
)
1895 bfd_seek (abfd
, 0, 0);
1897 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1898 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1899 H_SET_VERSION_STAMP (h
, 0);
1900 H_SET_ENTRY_POINT (h
, 0);
1901 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1902 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1903 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1905 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1906 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1907 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1909 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1911 bfd_write (buffer
, i
, 1, abfd
);
1912 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1914 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1916 if (segment_info
[i
].scnhdr
.s_name
[0])
1919 bfd_coff_swap_scnhdr_out (abfd
,
1920 &(segment_info
[i
].scnhdr
),
1923 as_bad ("bfd_coff_swap_scnhdr_out failed");
1924 bfd_write (buffer
, size
, 1, abfd
);
1931 symbol_to_chars (abfd
, where
, symbolP
)
1936 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1940 /* Turn any symbols with register attributes into abs symbols */
1941 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1943 S_SET_SEGMENT (symbolP
, absolute_section
);
1945 /* At the same time, relocate all symbols to their output value */
1947 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1948 + S_GET_VALUE (symbolP
));
1950 S_SET_VALUE (symbolP
, val
);
1952 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1954 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1957 for (i
= 0; i
< numaux
; i
++)
1959 where
+= bfd_coff_swap_aux_out (abfd
,
1960 &symbolP
->sy_symbol
.ost_auxent
[i
],
1961 S_GET_DATA_TYPE (symbolP
),
1962 S_GET_STORAGE_CLASS (symbolP
),
1970 obj_symbol_new_hook (symbolP
)
1973 char underscore
= 0; /* Symbol has leading _ */
1975 /* Effective symbol */
1976 /* Store the pointer in the offset. */
1977 S_SET_ZEROES (symbolP
, 0L);
1978 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1979 S_SET_STORAGE_CLASS (symbolP
, 0);
1980 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1981 /* Additional information */
1982 symbolP
->sy_symbol
.ost_flags
= 0;
1983 /* Auxiliary entries */
1984 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1986 if (S_IS_STRING (symbolP
))
1987 SF_SET_STRING (symbolP
);
1988 if (!underscore
&& S_IS_LOCAL (symbolP
))
1989 SF_SET_LOCAL (symbolP
);
1993 * Handle .ln directives.
1997 obj_coff_ln (appline
)
2002 if (! appline
&& def_symbol_in_progress
!= NULL
)
2004 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2005 demand_empty_rest_of_line ();
2007 } /* wrong context */
2009 l
= get_absolute_expression ();
2010 c_line_new (0, frag_now_fix (), l
, frag_now
);
2019 listing_source_line ((unsigned int) l
);
2024 demand_empty_rest_of_line ();
2030 * Handle .def directives.
2032 * One might ask : why can't we symbol_new if the symbol does not
2033 * already exist and fill it with debug information. Because of
2034 * the C_EFCN special symbol. It would clobber the value of the
2035 * function symbol before we have a chance to notice that it is
2036 * a C_EFCN. And a second reason is that the code is more clear this
2037 * way. (at least I think it is :-).
2041 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2042 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2043 *input_line_pointer == '\t') \
2044 input_line_pointer++;
2050 char name_end
; /* Char after the end of name */
2051 char *symbol_name
; /* Name of the debug symbol */
2052 char *symbol_name_copy
; /* Temporary copy of the name */
2053 unsigned int symbol_name_length
;
2055 if (def_symbol_in_progress
!= NULL
)
2057 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2058 demand_empty_rest_of_line ();
2060 } /* if not inside .def/.endef */
2062 SKIP_WHITESPACES ();
2064 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2065 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2067 symbol_name
= input_line_pointer
;
2068 name_end
= get_symbol_end ();
2069 symbol_name_length
= strlen (symbol_name
);
2070 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2071 strcpy (symbol_name_copy
, symbol_name
);
2073 /* Initialize the new symbol */
2074 #ifdef STRIP_UNDERSCORE
2075 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2076 ? symbol_name_copy
+ 1
2077 : symbol_name_copy
));
2078 #else /* STRIP_UNDERSCORE */
2079 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2080 #endif /* STRIP_UNDERSCORE */
2081 /* free(symbol_name_copy); */
2082 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2083 def_symbol_in_progress
->sy_number
= ~0;
2084 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2085 S_SET_VALUE (def_symbol_in_progress
, 0);
2087 if (S_IS_STRING (def_symbol_in_progress
))
2088 SF_SET_STRING (def_symbol_in_progress
);
2090 *input_line_pointer
= name_end
;
2092 demand_empty_rest_of_line ();
2095 unsigned int dim_index
;
2099 obj_coff_endef (ignore
)
2102 symbolS
*symbolP
= 0;
2103 /* DIM BUG FIX sac@cygnus.com */
2105 if (def_symbol_in_progress
== NULL
)
2107 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2108 demand_empty_rest_of_line ();
2110 } /* if not inside .def/.endef */
2112 /* Set the section number according to storage class. */
2113 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2118 SF_SET_TAG (def_symbol_in_progress
);
2119 /* intentional fallthrough */
2122 SF_SET_DEBUG (def_symbol_in_progress
);
2123 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2127 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2128 /* intentional fallthrough */
2130 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2131 /* intentional fallthrough */
2133 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2135 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2137 if (function_lineoff
< 0)
2139 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2140 } /* missing function symbol */
2141 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2143 SF_SET_PROCESS (last_line_symbol
);
2144 function_lineoff
= -1;
2146 /* Value is always set to . */
2147 def_symbol_in_progress
->sy_frag
= frag_now
;
2148 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2153 #endif /* C_AUTOARG */
2163 SF_SET_DEBUG (def_symbol_in_progress
);
2164 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2170 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2176 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2178 } /* switch on storage class */
2180 /* Now that we have built a debug symbol, try to find if we should
2181 merge with an existing symbol or not. If a symbol is C_EFCN or
2182 absolute_section or untagged SEG_DEBUG it never merges. We also
2183 don't merge labels, which are in a different namespace, nor
2184 symbols which have not yet been defined since they are typically
2185 unique, nor do we merge tags with non-tags. */
2187 /* Two cases for functions. Either debug followed by definition or
2188 definition followed by debug. For definition first, we will
2189 merge the debug symbol into the definition. For debug first, the
2190 lineno entry MUST point to the definition function or else it
2191 will point off into space when crawl_symbols() merges the debug
2192 symbol into the real symbol. Therefor, let's presume the debug
2193 symbol is a real function reference. */
2195 /* FIXME-SOON If for some reason the definition label/symbol is
2196 never seen, this will probably leave an undefined symbol at link
2199 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2200 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2201 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2202 && !SF_GET_TAG (def_symbol_in_progress
))
2203 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2204 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2205 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2206 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2208 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2213 /* This symbol already exists, merge the newly created symbol
2214 into the old one. This is not mandatory. The linker can
2215 handle duplicate symbols correctly. But I guess that it save
2216 a *lot* of space if the assembly file defines a lot of
2219 /* The debug entry (def_symbol_in_progress) is merged into the
2220 previous definition. */
2222 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2223 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2224 def_symbol_in_progress
= symbolP
;
2226 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2227 || SF_GET_TAG (def_symbol_in_progress
))
2229 /* For functions, and tags, the symbol *must* be where the
2230 debug symbol appears. Move the existing symbol to the
2232 /* If it already is at the end of the symbol list, do nothing */
2233 if (def_symbol_in_progress
!= symbol_lastP
)
2235 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2237 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2238 &symbol_rootP
, &symbol_lastP
);
2239 } /* if not already in place */
2241 } /* normal or mergable */
2243 if (SF_GET_TAG (def_symbol_in_progress
)
2244 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2246 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2249 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2251 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2253 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2255 SF_SET_PROCESS (def_symbol_in_progress
);
2257 if (symbolP
== NULL
)
2259 /* That is, if this is the first time we've seen the
2261 symbol_table_insert (def_symbol_in_progress
);
2262 } /* definition follows debug */
2263 } /* Create the line number entry pointing to the function being defined */
2265 def_symbol_in_progress
= NULL
;
2266 demand_empty_rest_of_line ();
2270 obj_coff_dim (ignore
)
2275 if (def_symbol_in_progress
== NULL
)
2277 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2278 demand_empty_rest_of_line ();
2280 } /* if not inside .def/.endef */
2282 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2284 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2286 SKIP_WHITESPACES ();
2287 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2288 get_absolute_expression ());
2290 switch (*input_line_pointer
)
2293 input_line_pointer
++;
2297 as_warn ("badly formed .dim directive ignored");
2298 /* intentional fallthrough */
2306 demand_empty_rest_of_line ();
2310 obj_coff_line (ignore
)
2316 if (def_symbol_in_progress
== NULL
)
2322 name
= S_GET_NAME (def_symbol_in_progress
);
2323 this_base
= get_absolute_expression ();
2325 /* Only .bf symbols indicate the use of a new base line number; the
2326 line numbers associated with .ef, .bb, .eb are relative to the
2327 start of the containing function. */
2328 if (!strcmp (".bf", name
))
2330 #if 0 /* XXX Can we ever have line numbers going backwards? */
2331 if (this_base
> line_base
)
2334 line_base
= this_base
;
2342 listing_source_line ((unsigned int) line_base
);
2348 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2349 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2351 demand_empty_rest_of_line ();
2355 obj_coff_size (ignore
)
2358 if (def_symbol_in_progress
== NULL
)
2360 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2361 demand_empty_rest_of_line ();
2363 } /* if not inside .def/.endef */
2365 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2366 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2367 demand_empty_rest_of_line ();
2371 obj_coff_scl (ignore
)
2374 if (def_symbol_in_progress
== NULL
)
2376 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2377 demand_empty_rest_of_line ();
2379 } /* if not inside .def/.endef */
2381 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2382 demand_empty_rest_of_line ();
2386 obj_coff_tag (ignore
)
2392 if (def_symbol_in_progress
== NULL
)
2394 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2395 demand_empty_rest_of_line ();
2399 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2400 symbol_name
= input_line_pointer
;
2401 name_end
= get_symbol_end ();
2403 /* Assume that the symbol referred to by .tag is always defined.
2404 This was a bad assumption. I've added find_or_make. xoxorich. */
2405 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2406 (long) tag_find_or_make (symbol_name
));
2407 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2409 as_warn ("tag not found for .tag %s", symbol_name
);
2412 SF_SET_TAGGED (def_symbol_in_progress
);
2413 *input_line_pointer
= name_end
;
2415 demand_empty_rest_of_line ();
2419 obj_coff_type (ignore
)
2422 if (def_symbol_in_progress
== NULL
)
2424 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2425 demand_empty_rest_of_line ();
2427 } /* if not inside .def/.endef */
2429 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2431 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2432 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2434 SF_SET_FUNCTION (def_symbol_in_progress
);
2435 } /* is a function */
2437 demand_empty_rest_of_line ();
2441 obj_coff_val (ignore
)
2444 if (def_symbol_in_progress
== NULL
)
2446 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2447 demand_empty_rest_of_line ();
2449 } /* if not inside .def/.endef */
2451 if (is_name_beginner (*input_line_pointer
))
2453 char *symbol_name
= input_line_pointer
;
2454 char name_end
= get_symbol_end ();
2456 if (!strcmp (symbol_name
, "."))
2458 def_symbol_in_progress
->sy_frag
= frag_now
;
2459 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2460 /* If the .val is != from the .def (e.g. statics) */
2462 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2464 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2465 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2466 symbol_find_or_make (symbol_name
);
2467 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2468 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2470 /* If the segment is undefined when the forward reference is
2471 resolved, then copy the segment id from the forward
2473 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2475 /* FIXME: gcc can generate address expressions
2476 here in unusual cases (search for "obscure"
2477 in sdbout.c). We just ignore the offset
2478 here, thus generating incorrect debugging
2479 information. We ignore the rest of the
2482 /* Otherwise, it is the name of a non debug symbol and
2483 its value will be calculated later. */
2484 *input_line_pointer
= name_end
;
2486 /* FIXME: this is to avoid an error message in the
2487 FIXME case mentioned just above. */
2488 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2489 ++input_line_pointer
;
2493 S_SET_VALUE (def_symbol_in_progress
,
2494 (valueT
) get_absolute_expression ());
2495 } /* if symbol based */
2497 demand_empty_rest_of_line ();
2501 obj_read_begin_hook ()
2503 /* These had better be the same. Usually 18 bytes. */
2505 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2506 know (SYMESZ
== AUXESZ
);
2511 /* This function runs through the symbol table and puts all the
2512 externals onto another chain */
2514 /* The chain of globals. */
2515 symbolS
*symbol_globalP
;
2516 symbolS
*symbol_global_lastP
;
2518 /* The chain of externals */
2519 symbolS
*symbol_externP
;
2520 symbolS
*symbol_extern_lastP
;
2523 symbolS
*last_functionP
;
2530 unsigned int symbol_number
= 0;
2531 unsigned int last_file_symno
= 0;
2533 struct filename_list
*filename_list_scan
= filename_list_head
;
2535 for (symbolP
= symbol_rootP
;
2537 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2539 if (symbolP
->sy_mri_common
)
2541 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2542 as_bad ("%s: global symbols not supported in common sections",
2543 S_GET_NAME (symbolP
));
2544 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2548 if (!SF_GET_DEBUG (symbolP
))
2550 /* Debug symbols do not need all this rubbish */
2551 symbolS
*real_symbolP
;
2553 /* L* and C_EFCN symbols never merge. */
2554 if (!SF_GET_LOCAL (symbolP
)
2555 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2556 && symbolP
->sy_value
.X_op
== O_constant
2557 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2558 && real_symbolP
!= symbolP
)
2560 /* FIXME-SOON: where do dups come from?
2561 Maybe tag references before definitions? xoxorich. */
2562 /* Move the debug data from the debug symbol to the
2563 real symbol. Do NOT do the oposite (i.e. move from
2564 real symbol to debug symbol and remove real symbol from the
2565 list.) Because some pointers refer to the real symbol
2566 whereas no pointers refer to the debug symbol. */
2567 c_symbol_merge (symbolP
, real_symbolP
);
2568 /* Replace the current symbol by the real one */
2569 /* The symbols will never be the last or the first
2570 because : 1st symbol is .file and 3 last symbols are
2571 .text, .data, .bss */
2572 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2573 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2574 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2575 symbolP
= real_symbolP
;
2576 } /* if not local but dup'd */
2578 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2580 S_SET_SEGMENT (symbolP
, SEG_E0
);
2581 } /* push data into text */
2583 resolve_symbol_value (symbolP
);
2585 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2587 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2589 S_SET_EXTERNAL (symbolP
);
2591 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2593 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2597 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2601 /* Mainly to speed up if not -g */
2602 if (SF_GET_PROCESS (symbolP
))
2604 /* Handle the nested blocks auxiliary info. */
2605 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2607 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2608 stack_push (block_stack
, (char *) &symbolP
);
2611 register symbolS
*begin_symbolP
;
2612 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2613 if (begin_symbolP
== (symbolS
*) 0)
2614 as_warn ("mismatched .eb");
2616 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2619 /* If we are able to identify the type of a function, and we
2620 are out of a function (last_functionP == 0) then, the
2621 function symbol will be associated with an auxiliary
2623 if (last_functionP
== (symbolS
*) 0 &&
2624 SF_GET_FUNCTION (symbolP
))
2626 last_functionP
= symbolP
;
2628 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2630 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2631 } /* make it at least 1 */
2633 /* Clobber possible stale .dim information. */
2635 /* Iffed out by steve - this fries the lnnoptr info too */
2636 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2637 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2640 /* The C_FCN doesn't need any additional information. I
2641 don't even know if this is needed for sdb. But the
2642 standard assembler generates it, so... */
2643 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2645 if (last_functionP
== (symbolS
*) 0)
2646 as_fatal ("C_EFCN symbol out of scope");
2647 SA_SET_SYM_FSIZE (last_functionP
,
2648 (long) (S_GET_VALUE (symbolP
) -
2649 S_GET_VALUE (last_functionP
)));
2650 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2651 last_functionP
= (symbolS
*) 0;
2655 else if (SF_GET_TAG (symbolP
))
2657 /* First descriptor of a structure must point to
2658 the first slot after the structure description. */
2659 last_tagP
= symbolP
;
2662 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2664 /* +2 take in account the current symbol */
2665 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2667 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2669 /* If the filename was too long to fit in the
2670 auxent, put it in the string table */
2671 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2673 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2674 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2675 filename_list_scan
= filename_list_scan
->next
;
2677 if (S_GET_VALUE (symbolP
))
2679 S_SET_VALUE (symbolP
, last_file_symno
);
2680 last_file_symno
= symbol_number
;
2681 } /* no one points at the first .file symbol */
2682 } /* if debug or tag or eos or file */
2684 /* We must put the external symbols apart. The loader
2685 does not bomb if we do not. But the references in
2686 the endndx field for a .bb symbol are not corrected
2687 if an external symbol is removed between .bb and .be.
2688 I.e in the following case :
2689 [20] .bb endndx = 22
2692 ld will move the symbol 21 to the end of the list but
2693 endndx will still be 22 instead of 21. */
2696 if (SF_GET_LOCAL (symbolP
))
2698 /* remove C_EFCN and LOCAL (L...) symbols */
2699 /* next pointer remains valid */
2700 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2703 else if (!S_IS_DEFINED (symbolP
)
2704 && !S_IS_DEBUG (symbolP
)
2705 && !SF_GET_STATICS (symbolP
) &&
2706 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2707 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2708 /* if external, Remove from the list */
2709 symbolS
*hold
= symbol_previous (symbolP
);
2711 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2712 symbol_clear_list_pointers (symbolP
);
2713 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2716 else if (! S_IS_DEBUG (symbolP
)
2717 && ! SF_GET_STATICS (symbolP
)
2718 && ! SF_GET_FUNCTION (symbolP
)
2719 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2721 symbolS
*hold
= symbol_previous (symbolP
);
2723 /* The O'Reilly COFF book says that defined global symbols
2724 come at the end of the symbol table, just before
2725 undefined global symbols. */
2727 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2728 symbol_clear_list_pointers (symbolP
);
2729 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2730 &symbol_global_lastP
);
2735 if (SF_GET_STRING (symbolP
))
2737 symbolP
->sy_name_offset
= string_byte_count
;
2738 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2742 symbolP
->sy_name_offset
= 0;
2743 } /* fix "long" names */
2745 symbolP
->sy_number
= symbol_number
;
2746 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2747 } /* if local symbol */
2748 } /* traverse the symbol list */
2749 return symbol_number
;
2755 glue_symbols (head
, tail
)
2759 unsigned int symbol_number
= 0;
2762 for (symbolP
= *head
; *head
!= NULL
;)
2764 symbolS
*tmp
= *head
;
2767 symbol_remove (tmp
, head
, tail
);
2768 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2771 if (SF_GET_STRING (tmp
))
2773 tmp
->sy_name_offset
= string_byte_count
;
2774 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2778 tmp
->sy_name_offset
= 0;
2779 } /* fix "long" names */
2781 tmp
->sy_number
= symbol_number
;
2782 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2783 } /* append the entire extern chain */
2785 return symbol_number
;
2791 unsigned int symbol_number
= 0;
2794 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2795 symbol_next (symbolP
))
2797 symbolP
->sy_number
= symbol_number
;
2801 if (SF_GET_TAGGED (symbolP
))
2805 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2808 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2810 return symbol_number
;
2815 crawl_symbols (h
, abfd
)
2821 /* Initialize the stack used to keep track of the matching .bb .be */
2823 block_stack
= stack_init (512, sizeof (symbolS
*));
2825 /* The symbol list should be ordered according to the following sequence
2828 * . debug entries for functions
2829 * . fake symbols for the sections, including.text .data and .bss
2831 * . undefined symbols
2832 * But this is not mandatory. The only important point is to put the
2833 * undefined symbols at the end of the list.
2836 if (symbol_rootP
== NULL
2837 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2839 c_dot_file_symbol ("fake");
2841 /* Is there a .file symbol ? If not insert one at the beginning. */
2844 * Build up static symbols for the sections, they are filled in later
2848 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2850 if (segment_info
[i
].scnhdr
.s_name
[0])
2854 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2856 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2861 /* Take all the externals out and put them into another chain */
2862 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2863 /* Take the externals and glue them onto the end.*/
2864 H_SET_SYMBOL_TABLE_SIZE (h
,
2865 (H_GET_SYMBOL_COUNT (h
)
2866 + glue_symbols (&symbol_globalP
,
2867 &symbol_global_lastP
)
2868 + glue_symbols (&symbol_externP
,
2869 &symbol_extern_lastP
)));
2871 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2872 know (symbol_globalP
== NULL
);
2873 know (symbol_global_lastP
== NULL
);
2874 know (symbol_externP
== NULL
);
2875 know (symbol_extern_lastP
== NULL
);
2879 * Find strings by crawling along symbol table chain.
2887 struct filename_list
*filename_list_scan
= filename_list_head
;
2889 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2890 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2892 for (symbolP
= symbol_rootP
;
2894 symbolP
= symbol_next (symbolP
))
2898 if (SF_GET_STRING (symbolP
))
2900 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2901 memcpy (where
, S_GET_NAME (symbolP
), size
);
2904 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2905 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2907 size
= strlen (filename_list_scan
->filename
) + 1;
2908 memcpy (where
, filename_list_scan
->filename
, size
);
2909 filename_list_scan
= filename_list_scan
->next
;
2916 do_linenos_for (abfd
, h
, file_cursor
)
2919 unsigned long *file_cursor
;
2922 unsigned long start
= *file_cursor
;
2924 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2926 segment_info_type
*s
= segment_info
+ idx
;
2929 if (s
->scnhdr
.s_nlnno
!= 0)
2931 struct lineno_list
*line_ptr
;
2933 struct external_lineno
*buffer
=
2934 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2936 struct external_lineno
*dst
= buffer
;
2938 /* Run through the table we've built and turn it into its external
2939 form, take this chance to remove duplicates */
2941 for (line_ptr
= s
->lineno_list_head
;
2942 line_ptr
!= (struct lineno_list
*) NULL
;
2943 line_ptr
= line_ptr
->next
)
2946 if (line_ptr
->line
.l_lnno
== 0)
2948 /* Turn a pointer to a symbol into the symbols' index */
2949 line_ptr
->line
.l_addr
.l_symndx
=
2950 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2954 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2958 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2963 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2965 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2968 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2971 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2975 /* Now we run through the list of frag chains in a segment and
2976 make all the subsegment frags appear at the end of the
2977 list, as if the seg 0 was extra long */
2984 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2986 frchainS
*head
= segment_info
[i
].frchainP
;
2988 fragS
*prev_frag
= &dummy
;
2990 while (head
&& head
->frch_seg
== i
)
2992 prev_frag
->fr_next
= head
->frch_root
;
2993 prev_frag
= head
->frch_last
;
2994 head
= head
->frch_next
;
2996 prev_frag
->fr_next
= 0;
3000 unsigned long machine
;
3003 write_object_file ()
3007 struct frchain
*frchain_ptr
;
3009 object_headers headers
;
3010 unsigned long file_cursor
;
3013 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3018 as_perror ("FATAL: Can't create %s", out_file_name
);
3019 exit (EXIT_FAILURE
);
3021 bfd_set_format (abfd
, bfd_object
);
3022 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3024 string_byte_count
= 4;
3026 for (frchain_ptr
= frchain_root
;
3027 frchain_ptr
!= (struct frchain
*) NULL
;
3028 frchain_ptr
= frchain_ptr
->frch_next
)
3030 /* Run through all the sub-segments and align them up. Also
3031 close any open frags. We tack a .fill onto the end of the
3032 frag chain so that any .align's size can be worked by looking
3033 at the next frag. */
3035 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3036 #ifndef SUB_SEGMENT_ALIGN
3037 #define SUB_SEGMENT_ALIGN(SEG) 1
3041 static char nop
= NOP_OPCODE
;
3042 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, alignment_done
);
3045 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
3049 frag_wane (frag_now
);
3050 frag_now
->fr_fix
= 0;
3051 know (frag_now
->fr_next
== NULL
);
3058 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3060 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3063 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3065 /* Find out how big the sections are, and set the addresses. */
3067 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3071 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3072 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3074 if (segment_info
[i
].scnhdr
.s_name
[0])
3076 H_SET_NUMBER_OF_SECTIONS (&headers
,
3077 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3080 size
= size_section (abfd
, (unsigned int) i
);
3083 /* I think the section alignment is only used on the i960; the
3084 i960 needs it, and it should do no harm on other targets. */
3085 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3088 H_SET_TEXT_SIZE (&headers
, size
);
3089 else if (i
== SEG_E1
)
3090 H_SET_DATA_SIZE (&headers
, size
);
3091 else if (i
== SEG_E2
)
3092 H_SET_BSS_SIZE (&headers
, size
);
3095 /* Turn the gas native symbol table shape into a coff symbol table */
3096 crawl_symbols (&headers
, abfd
);
3098 if (string_byte_count
== 4)
3099 string_byte_count
= 0;
3101 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3107 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3109 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3110 fixup_segment (&segment_info
[i
], i
);
3113 /* Look for ".stab" segments and fill in their initial symbols
3115 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3117 name
= segment_info
[i
].scnhdr
.s_name
;
3120 && strncmp (".stab", name
, 5) == 0
3121 && strncmp (".stabstr", name
, 8) != 0)
3122 adjust_stab_section (abfd
, i
);
3125 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3127 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3129 /* Plant the data */
3131 fill_section (abfd
, &headers
, &file_cursor
);
3133 do_relocs_for (abfd
, &headers
, &file_cursor
);
3135 do_linenos_for (abfd
, &headers
, &file_cursor
);
3137 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3138 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3139 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3141 H_SET_TIME_STAMP (&headers
, 0);
3143 #ifdef TC_COFF_SET_MACHINE
3144 TC_COFF_SET_MACHINE (&headers
);
3148 #define COFF_FLAGS 0
3151 #ifdef KEEP_RELOC_INFO
3152 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3153 COFF_FLAGS
| coff_flags
));
3155 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3156 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3157 COFF_FLAGS
| coff_flags
));
3161 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3162 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3164 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3165 w_symbols (abfd
, buffer1
, symbol_rootP
);
3166 if (string_byte_count
> 0)
3167 w_strings (buffer1
+ symtable_size
);
3168 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3172 coff_header_append (abfd
, &headers
);
3174 /* Recent changes to write need this, but where it should
3175 go is up to Ken.. */
3176 if (bfd_close_all_done (abfd
) == false)
3177 as_fatal ("Can't close %s: %s", out_file_name
,
3178 bfd_errmsg (bfd_get_error ()));
3181 extern bfd
*stdoutput
;
3188 /* Add a new segment. This is called from subseg_new via the
3189 obj_new_segment macro. */
3192 obj_coff_add_segment (name
)
3198 /* Find out if we've already got a section of this name. */
3199 len
= strlen (name
);
3200 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3203 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3204 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3205 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3206 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3207 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3212 as_bad ("Too many new sections; can't add \"%s\"", name
);
3216 /* Add a new section. */
3217 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3218 sizeof (segment_info
[i
].scnhdr
.s_name
));
3219 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3225 * implement the .section pseudo op:
3226 * .section name {, "flags"}
3228 * | +--- optional flags: 'b' for bss
3230 * +-- section name 'l' for lib
3234 * 'd' (apparently m88k for data)
3236 * But if the argument is not a quoted string, treat it as a
3237 * subsegment number.
3241 obj_coff_section (ignore
)
3244 /* Strip out the section name */
3246 char *section_name_end
;
3261 else if (type
== 'D')
3263 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3268 section_name
= input_line_pointer
;
3269 c
= get_symbol_end ();
3270 section_name_end
= input_line_pointer
;
3272 len
= section_name_end
- section_name
;
3273 input_line_pointer
++;
3279 else if (*input_line_pointer
== ',')
3282 ++input_line_pointer
;
3290 if (*input_line_pointer
!= '"')
3291 exp
= get_absolute_expression ();
3294 ++input_line_pointer
;
3295 while (*input_line_pointer
!= '"'
3296 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3298 switch (*input_line_pointer
)
3300 case 'b': flags
|= STYP_BSS
; break;
3301 case 'i': flags
|= STYP_INFO
; break;
3302 case 'l': flags
|= STYP_LIB
; break;
3303 case 'n': flags
|= STYP_NOLOAD
; break;
3304 case 'o': flags
|= STYP_OVER
; break;
3306 case 'w': flags
|= STYP_DATA
; break;
3307 case 'x': flags
|= STYP_TEXT
; break;
3309 as_warn("unknown section attribute '%c'",
3310 *input_line_pointer
);
3313 ++input_line_pointer
;
3315 if (*input_line_pointer
== '"')
3316 ++input_line_pointer
;
3320 subseg_new (section_name
, (subsegT
) exp
);
3322 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3324 *section_name_end
= c
;
3329 obj_coff_text (ignore
)
3332 subseg_new (".text", get_absolute_expression ());
3337 obj_coff_data (ignore
)
3340 if (flag_readonly_data_in_text
)
3341 subseg_new (".text", get_absolute_expression () + 1000);
3343 subseg_new (".data", get_absolute_expression ());
3347 obj_coff_bss (ignore
)
3350 if (*input_line_pointer
== '\n') /* .bss */
3351 subseg_new(".bss", get_absolute_expression());
3352 else /* .bss id,expr */
3357 obj_coff_ident (ignore
)
3360 segT current_seg
= now_seg
; /* save current seg */
3361 subsegT current_subseg
= now_subseg
;
3362 subseg_new (".comment", 0); /* .comment seg */
3363 stringer (1); /* read string */
3364 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3368 c_symbol_merge (debug
, normal
)
3372 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3373 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3375 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3377 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3378 } /* take the most we have */
3380 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3382 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3383 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3384 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3385 } /* Move all the auxiliary information */
3387 /* Move the debug flags. */
3388 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3389 } /* c_symbol_merge() */
3392 c_line_new (symbol
, paddr
, line_number
, frag
)
3398 struct lineno_list
*new_line
=
3399 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3401 segment_info_type
*s
= segment_info
+ now_seg
;
3402 new_line
->line
.l_lnno
= line_number
;
3404 if (line_number
== 0)
3406 last_line_symbol
= symbol
;
3407 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3411 new_line
->line
.l_addr
.l_paddr
= paddr
;
3414 new_line
->frag
= (char *) frag
;
3415 new_line
->next
= (struct lineno_list
*) NULL
;
3418 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3420 s
->lineno_list_head
= new_line
;
3424 s
->lineno_list_tail
->next
= new_line
;
3426 s
->lineno_list_tail
= new_line
;
3427 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3431 c_dot_file_symbol (filename
)
3436 symbolP
= symbol_new (".file",
3439 &zero_address_frag
);
3441 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3442 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3444 if (strlen (filename
) > FILNMLEN
)
3446 /* Filename is too long to fit into an auxent,
3447 we stick it into the string table instead. We keep
3448 a linked list of the filenames we find so we can emit
3450 struct filename_list
*f
= ((struct filename_list
*)
3451 xmalloc (sizeof (struct filename_list
)));
3453 f
->filename
= filename
;
3456 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3457 SA_SET_FILE_FNAME_OFFSET (symbolP
, 0);
3459 if (filename_list_tail
)
3460 filename_list_tail
->next
= f
;
3462 filename_list_head
= f
;
3463 filename_list_tail
= f
;
3467 SA_SET_FILE_FNAME (symbolP
, filename
);
3474 listing_source_file (filename
);
3480 SF_SET_DEBUG (symbolP
);
3481 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3483 previous_file_symbol
= symbolP
;
3485 /* Make sure that the symbol is first on the symbol chain */
3486 if (symbol_rootP
!= symbolP
)
3488 if (symbolP
== symbol_lastP
)
3490 symbol_lastP
= symbol_lastP
->sy_previous
;
3491 } /* if it was the last thing on the list */
3493 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3494 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3495 symbol_rootP
= symbolP
;
3496 } /* if not first on the list */
3498 } /* c_dot_file_symbol() */
3501 * Build a 'section static' symbol.
3505 c_section_symbol (name
, idx
)
3511 symbolP
= symbol_new (name
, idx
,
3513 &zero_address_frag
);
3515 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3516 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3518 SF_SET_STATICS (symbolP
);
3521 } /* c_section_symbol() */
3524 w_symbols (abfd
, where
, symbol_rootP
)
3527 symbolS
* symbol_rootP
;
3532 /* First fill in those values we have only just worked out */
3533 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3535 symbolP
= segment_info
[i
].dot
;
3538 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3539 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3540 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3545 * Emit all symbols left in the symbol chain.
3547 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3549 /* Used to save the offset of the name. It is used to point
3550 to the string in memory but must be a file offset. */
3551 register char *temp
;
3553 tc_coff_symbol_emit_hook (symbolP
);
3555 temp
= S_GET_NAME (symbolP
);
3556 if (SF_GET_STRING (symbolP
))
3558 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3559 S_SET_ZEROES (symbolP
, 0);
3563 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3564 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3566 where
= symbol_to_chars (abfd
, where
, symbolP
);
3567 S_SET_NAME (symbolP
, temp
);
3573 obj_coff_lcomm (ignore
)
3586 name
= input_line_pointer
;
3588 c
= get_symbol_end ();
3589 p
= input_line_pointer
;
3592 if (*input_line_pointer
!= ',')
3594 as_bad ("Expected comma after name");
3595 ignore_rest_of_line ();
3598 if (*input_line_pointer
== '\n')
3600 as_bad ("Missing size expression");
3603 input_line_pointer
++;
3604 if ((temp
= get_absolute_expression ()) < 0)
3606 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3607 ignore_rest_of_line ();
3612 symbolP
= symbol_find_or_make(name
);
3614 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3615 S_GET_VALUE(symbolP
) == 0)
3620 segT current_seg
= now_seg
; /* save current seg */
3621 subsegT current_subseg
= now_subseg
;
3623 subseg_set (SEG_E2
, 1);
3624 symbolP
->sy_frag
= frag_now
;
3625 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3628 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3629 S_SET_SEGMENT(symbolP
, SEG_E2
);
3630 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3634 as_bad("Symbol %s already defined", name
);
3636 demand_empty_rest_of_line();
3641 fixup_mdeps (frags
, h
, this_segment
)
3646 subseg_change (this_segment
, 0);
3649 switch (frags
->fr_type
)
3655 HANDLE_ALIGN (frags
);
3657 frags
->fr_type
= rs_fill
;
3659 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3661 case rs_machine_dependent
:
3662 md_convert_frag (h
, this_segment
, frags
);
3668 frags
= frags
->fr_next
;
3674 #ifndef TC_FORCE_RELOCATION
3675 #define TC_FORCE_RELOCATION(fix) 0
3679 fixup_segment (segP
, this_segment_type
)
3680 segment_info_type
* segP
;
3681 segT this_segment_type
;
3683 register fixS
* fixP
;
3684 register symbolS
*add_symbolP
;
3685 register symbolS
*sub_symbolP
;
3688 register char *place
;
3689 register long where
;
3690 register char pcrel
;
3691 register fragS
*fragP
;
3692 register segT add_symbol_segment
= absolute_section
;
3697 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3699 fragP
= fixP
->fx_frag
;
3701 where
= fixP
->fx_where
;
3702 place
= fragP
->fr_literal
+ where
;
3703 size
= fixP
->fx_size
;
3704 add_symbolP
= fixP
->fx_addsy
;
3706 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3708 /* Relocation should be done via the associated 'bal' entry
3711 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3713 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3714 "No 'bal' entry point for leafproc %s",
3715 S_GET_NAME (add_symbolP
));
3718 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3721 sub_symbolP
= fixP
->fx_subsy
;
3722 add_number
= fixP
->fx_offset
;
3723 pcrel
= fixP
->fx_pcrel
;
3725 if (add_symbolP
!= NULL
3726 && add_symbolP
->sy_mri_common
)
3728 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3729 add_number
+= S_GET_VALUE (add_symbolP
);
3730 fixP
->fx_offset
= add_number
;
3731 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3736 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3737 } /* if there is an addend */
3741 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3743 if (add_symbolP
!= NULL
)
3745 add_number
+= S_GET_VALUE (add_symbolP
);
3747 fixP
->fx_addsy
= NULL
;
3750 /* It's just -sym. */
3751 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3753 add_number
-= S_GET_VALUE (sub_symbolP
);
3760 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3761 "Negative of non-absolute symbol %s",
3762 S_GET_NAME (sub_symbolP
));
3764 add_number
-= S_GET_VALUE (sub_symbolP
);
3765 } /* not absolute */
3767 /* if sub_symbol is in the same segment that add_symbol
3768 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3770 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3771 && SEG_NORMAL (add_symbol_segment
))
3773 /* Difference of 2 symbols from same segment. Can't
3774 make difference of 2 undefineds: 'value' means
3775 something different for N_UNDF. */
3777 /* Makes no sense to use the difference of 2 arbitrary symbols
3778 as the target of a call instruction. */
3781 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3782 "callj to difference of 2 symbols");
3784 #endif /* TC_I960 */
3785 add_number
+= S_GET_VALUE (add_symbolP
) -
3786 S_GET_VALUE (sub_symbolP
);
3789 if (!TC_FORCE_RELOCATION (fixP
))
3791 fixP
->fx_addsy
= NULL
;
3792 fixP
->fx_subsy
= NULL
;
3794 #ifdef TC_M68K /* is this right? */
3802 /* Different segments in subtraction. */
3803 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3805 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3807 add_number
-= S_GET_VALUE (sub_symbolP
);
3810 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3811 #if 0 /* Okay for 68k, at least... */
3816 /* Make it pc-relative. */
3817 add_number
+= (md_pcrel_from (fixP
)
3818 - S_GET_VALUE (sub_symbolP
));
3827 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3828 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3829 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3830 S_GET_NAME (sub_symbolP
),
3831 (long) (fragP
->fr_address
+ where
));
3834 } /* if sub_symbolP */
3838 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3841 * This fixup was made when the symbol's segment was
3842 * SEG_UNKNOWN, but it is now in the local segment.
3843 * So we know how to do the address without relocation.
3846 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3847 * in which cases it modifies *fixP as appropriate. In the case
3848 * of a 'calls', no further work is required, and *fixP has been
3849 * set up to make the rest of the code below a no-op.
3852 #endif /* TC_I960 */
3854 add_number
+= S_GET_VALUE (add_symbolP
);
3855 add_number
-= md_pcrel_from (fixP
);
3856 #if defined (TC_I386) || defined (TE_LYNX)
3857 /* On the 386 we must adjust by the segment
3858 vaddr as well. Ian Taylor. */
3859 add_number
-= segP
->scnhdr
.s_vaddr
;
3861 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3862 if (!TC_FORCE_RELOCATION (fixP
))
3864 fixP
->fx_addsy
= NULL
;
3870 switch (add_symbol_segment
)
3872 case absolute_section
:
3874 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3875 #endif /* TC_I960 */
3876 add_number
+= S_GET_VALUE (add_symbolP
);
3879 if (!TC_FORCE_RELOCATION (fixP
))
3881 fixP
->fx_addsy
= NULL
;
3888 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
3889 /* This really should be handled in the linker, but
3890 backward compatibility forbids. */
3891 add_number
+= S_GET_VALUE (add_symbolP
);
3893 add_number
+= S_GET_VALUE (add_symbolP
) +
3894 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3900 if ((int) fixP
->fx_bit_fixP
== 13)
3902 /* This is a COBR instruction. They have only a
3903 * 13-bit displacement and are only to be used
3904 * for local branches: flag as error, don't generate
3907 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3908 "can't use COBR format with external label");
3909 fixP
->fx_addsy
= NULL
;
3913 #endif /* TC_I960 */
3914 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
3915 /* 386 COFF uses a peculiar format in which the
3916 value of a common symbol is stored in the .text
3917 segment (I've checked this on SVR3.2 and SCO
3918 3.2.2) Ian Taylor <ian@cygnus.com>. */
3919 if (S_IS_COMMON (add_symbolP
))
3920 add_number
+= S_GET_VALUE (add_symbolP
);
3925 } /* switch on symbol seg */
3926 } /* if not in local seg */
3927 } /* if there was a + symbol */
3931 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
3932 /* This adjustment is not correct on the m88k, for which the
3933 linker does all the computation. */
3934 add_number
-= md_pcrel_from (fixP
);
3936 if (add_symbolP
== 0)
3938 fixP
->fx_addsy
= &abs_symbol
;
3939 } /* if there's an add_symbol */
3940 #if defined (TC_I386) || defined (TE_LYNX)
3941 /* On the 386 we must adjust by the segment vaddr
3942 as well. Ian Taylor. */
3943 add_number
-= segP
->scnhdr
.s_vaddr
;
3947 if (!fixP
->fx_bit_fixP
)
3950 /* The m88k uses the offset field of the reloc to get around
3953 && (add_number
& ~0xFF)
3954 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
3956 && (add_number
& ~0xFFFF)
3957 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3959 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3960 "Value of %ld too large for field of %d bytes at 0x%lx",
3961 (long) add_number
, size
,
3962 (unsigned long) (fragP
->fr_address
+ where
));
3965 #ifdef WARN_SIGNED_OVERFLOW_WORD
3966 /* Warn if a .word value is too large when treated as a
3967 signed number. We already know it is not too negative.
3968 This is to catch over-large switches generated by gcc on
3970 if (!flag_signed_overflow_ok
3972 && add_number
> 0x7fff)
3973 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3974 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
3976 (unsigned long) (fragP
->fr_address
+ where
));
3978 } /* not a bit fix */
3979 /* Once this fix has been applied, we don't have to output
3980 anything nothing more need be done. */
3981 #ifdef MD_APPLY_FIX3
3982 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
3984 md_apply_fix (fixP
, add_number
);
3986 } /* For each fixS in this segment. */
3987 } /* fixup_segment() */
3991 /* The first entry in a .stab section is special. */
3994 obj_coff_init_stab_section (seg
)
4000 unsigned int stroff
;
4002 /* Make space for this first symbol. */
4006 as_where (&file
, (unsigned int *) NULL
);
4007 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
4008 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
4009 strcat (stabstr_name
, "str");
4010 stroff
= get_stab_string_offset (file
, stabstr_name
);
4012 md_number_to_chars (p
, stroff
, 4);
4015 /* Fill in the counts in the first entry in a .stab section. */
4018 adjust_stab_section(abfd
, seg
)
4022 segT stabstrseg
= SEG_UNKNOWN
;
4023 char *secname
, *name
, *name2
;
4025 int i
, strsz
= 0, nsyms
;
4026 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4028 /* Look for the associated string table section. */
4030 secname
= segment_info
[seg
].scnhdr
.s_name
;
4031 name
= (char *) alloca (strlen (secname
) + 4);
4032 strcpy (name
, secname
);
4033 strcat (name
, "str");
4035 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4037 name2
= segment_info
[i
].scnhdr
.s_name
;
4038 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4045 /* If we found the section, get its size. */
4046 if (stabstrseg
!= SEG_UNKNOWN
)
4047 strsz
= size_section (abfd
, stabstrseg
);
4049 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4051 /* Look for the first frag of sufficient size for the initial stab
4052 symbol, and collect a pointer to it. */
4053 while (frag
&& frag
->fr_fix
< 12)
4054 frag
= frag
->fr_next
;
4056 p
= frag
->fr_literal
;
4059 /* Write in the number of stab symbols and the size of the string
4061 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4062 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4065 #endif /* not BFD_ASSEMBLER */
4067 const pseudo_typeS obj_pseudo_table
[] =
4069 {"def", obj_coff_def
, 0},
4070 {"dim", obj_coff_dim
, 0},
4071 {"endef", obj_coff_endef
, 0},
4072 {"line", obj_coff_line
, 0},
4073 {"ln", obj_coff_ln
, 0},
4074 {"appline", obj_coff_ln
, 1},
4075 {"scl", obj_coff_scl
, 0},
4076 {"size", obj_coff_size
, 0},
4077 {"tag", obj_coff_tag
, 0},
4078 {"type", obj_coff_type
, 0},
4079 {"val", obj_coff_val
, 0},
4080 {"section", obj_coff_section
, 0},
4081 {"sect", obj_coff_section
, 0},
4082 /* FIXME: We ignore the MRI short attribute. */
4083 {"section.s", obj_coff_section
, 0},
4084 {"sect.s", obj_coff_section
, 0},
4085 #ifndef BFD_ASSEMBLER
4086 {"use", obj_coff_section
, 0},
4087 {"text", obj_coff_text
, 0},
4088 {"data", obj_coff_data
, 0},
4089 {"bss", obj_coff_bss
, 0},
4090 {"lcomm", obj_coff_lcomm
, 0},
4091 {"ident", obj_coff_ident
, 0},
4093 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4094 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4096 {"ABORT", s_abort
, 0},
4098 /* The m88k uses sdef instead of def. */
4099 {"sdef", obj_coff_def
, 0},
4101 {NULL
} /* end sentinel */
4102 }; /* obj_pseudo_table */