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 static symbolS
*tag_find_or_make
PARAMS ((char *name
));
28 static symbolS
*tag_find
PARAMS ((char *name
));
29 static void tag_init
PARAMS ((void));
30 static void tag_insert
PARAMS ((const char *name
, symbolS
* symbolP
));
31 const char *s_get_name
PARAMS ((symbolS
* s
));
33 static void obj_coff_def
PARAMS ((int));
34 static void obj_coff_dim
PARAMS ((int));
35 static void obj_coff_endef
PARAMS ((int));
36 static void obj_coff_line
PARAMS ((int));
37 static void obj_coff_ln
PARAMS ((int));
38 static void obj_coff_scl
PARAMS ((int));
39 static void obj_coff_size
PARAMS ((int));
40 static void obj_coff_tag
PARAMS ((int));
41 static void obj_coff_type
PARAMS ((int));
42 static void obj_coff_val
PARAMS ((int));
44 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
46 static struct hash_control
*tag_hash
;
47 static symbolS
*def_symbol_in_progress
;
49 const pseudo_typeS obj_pseudo_table
[] =
51 {"def", obj_coff_def
, 0},
52 {"dim", obj_coff_dim
, 0},
53 {"endef", obj_coff_endef
, 0},
54 {"line", obj_coff_line
, 0},
55 {"ln", obj_coff_ln
, 0},
56 {"appline", obj_coff_ln
, 1},
57 {"scl", obj_coff_scl
, 0},
58 {"size", obj_coff_size
, 0},
59 {"tag", obj_coff_tag
, 0},
60 {"type", obj_coff_type
, 0},
61 {"val", obj_coff_val
, 0},
62 { "section", obj_coff_section
, 0 },
63 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
64 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
66 {"ABORT", s_abort
, 0},
68 {NULL
} /* end sentinel */
69 }; /* obj_pseudo_table */
74 unsigned long chunk_size
;
75 unsigned long element_size
;
78 unsigned long pointer
;
83 stack_init (chunk_size
, element_size
)
84 unsigned long chunk_size
;
85 unsigned long element_size
;
89 st
= (stack
*) malloc (sizeof (stack
));
92 st
->data
= malloc (chunk_size
);
99 st
->size
= chunk_size
;
100 st
->chunk_size
= chunk_size
;
101 st
->element_size
= element_size
;
114 stack_push (st
, element
)
118 if (st
->pointer
+ st
->element_size
>= st
->size
)
120 st
->size
+= st
->chunk_size
;
121 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
124 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
125 st
->pointer
+= st
->element_size
;
126 return st
->data
+ st
->pointer
;
133 if (st
->pointer
< st
->element_size
)
138 st
->pointer
-= st
->element_size
;
139 return st
->data
+ st
->pointer
;
143 * Maintain a list of the tagnames of the structres.
149 tag_hash
= hash_new ();
153 tag_insert (name
, symbolP
)
157 const char *error_string
;
159 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
161 as_fatal ("Inserting \"%s\" into structure table failed: %s",
167 tag_find_or_make (name
)
172 if ((symbolP
= tag_find (name
)) == NULL
)
174 symbolP
= symbol_new (name
, undefined_section
,
175 0, &zero_address_frag
);
177 tag_insert (S_GET_NAME (symbolP
), symbolP
);
178 symbol_table_insert (symbolP
);
188 #ifdef STRIP_UNDERSCORE
191 #endif /* STRIP_UNDERSCORE */
192 return (symbolS
*) hash_find (tag_hash
, name
);
196 struct line_no
*next
;
201 #define GET_FILENAME_STRING(X) \
202 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
206 fetch_coff_debug_section ()
208 static segT debug_section
;
212 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
214 debug_section
= s
->section
;
216 return debug_section
;
220 SA_SET_SYM_ENDNDX (sym
, val
)
224 combined_entry_type
*entry
, *p
;
226 entry
= &coffsymbol (sym
->bsym
)->native
[1];
227 p
= coffsymbol (val
->bsym
)->native
;
228 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
233 SA_SET_SYM_TAGNDX (sym
, val
)
237 combined_entry_type
*entry
, *p
;
239 entry
= &coffsymbol (sym
->bsym
)->native
[1];
240 p
= coffsymbol (val
->bsym
)->native
;
241 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
246 S_GET_DATA_TYPE (sym
)
249 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
253 S_SET_DATA_TYPE (sym
, val
)
257 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
262 S_GET_STORAGE_CLASS (sym
)
265 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
269 S_SET_STORAGE_CLASS (sym
, val
)
273 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
277 /* Merge a debug symbol containing debug information into a normal symbol. */
280 c_symbol_merge (debug
, normal
)
284 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
285 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
287 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
288 /* take the most we have */
289 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
291 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
293 /* Move all the auxiliary information. */
294 /* @@ How many fields do we want to preserve? Would it make more
295 sense to pick and choose those we want to copy? Should look
296 into this further.... [raeburn:19920512.2209EST] */
298 linenos
= coffsymbol (normal
->bsym
)->lineno
;
299 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
300 (char *) &coffsymbol (debug
->bsym
)->native
,
301 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
302 coffsymbol (normal
->bsym
)->lineno
= linenos
;
305 /* Move the debug flags. */
306 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
309 static symbolS
*previous_file_symbol
;
311 c_dot_file_symbol (filename
)
316 symbolP
= symbol_new (filename
, &bfd_abs_section
, 0,
319 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
320 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
322 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
329 listing_source_file (filename
);
334 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
336 previous_file_symbol
= symbolP
;
338 /* Make sure that the symbol is first on the symbol chain */
339 if (symbol_rootP
!= symbolP
)
341 if (symbolP
== symbol_lastP
)
343 symbol_lastP
= symbol_lastP
->sy_previous
;
344 } /* if it was the last thing on the list */
346 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
347 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
348 symbol_rootP
= symbolP
;
349 } /* if not first on the list */
353 * Build a 'section static' symbol.
357 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
361 unsigned short nreloc
;
362 unsigned short nlnno
;
366 symbolP
= symbol_new (name
,
375 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
376 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
378 SA_SET_SCN_SCNLEN (symbolP
, length
);
379 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
380 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
382 SF_SET_STATICS (symbolP
);
384 return (char *) symbolP
;
387 /* Line number handling */
391 /* Symbol of last function, which we should hang line#s off of. */
392 static symbolS
*line_fsym
;
394 #define in_function() (line_fsym != 0)
395 #define clear_function() (line_fsym = 0)
396 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
400 obj_symbol_new_hook (symbolP
)
403 char underscore
= 0; /* Symbol has leading _ */
406 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
407 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
409 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
411 S_SET_DATA_TYPE (symbolP
, T_NULL
);
412 S_SET_STORAGE_CLASS (symbolP
, 0);
413 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
415 if (S_IS_STRING (symbolP
))
416 SF_SET_STRING (symbolP
);
417 if (!underscore
&& S_IS_LOCAL (symbolP
))
418 SF_SET_LOCAL (symbolP
);
423 * Handle .ln directives.
426 static symbolS
*current_lineno_sym
;
427 static struct line_no
*line_nos
;
430 add_lineno (frag
, offset
, num
)
435 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
436 sizeof (struct line_no
));
437 if (!current_lineno_sym
)
441 new_line
->next
= line_nos
;
442 new_line
->frag
= frag
;
443 new_line
->l
.line_number
= num
;
444 new_line
->l
.u
.offset
= offset
;
449 coff_add_linesym (sym
)
454 add_lineno (0, 0, 0);
455 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
458 current_lineno_sym
= sym
;
462 obj_coff_ln (appline
)
467 if (! appline
&& def_symbol_in_progress
!= NULL
)
469 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
470 demand_empty_rest_of_line ();
474 l
= get_absolute_expression ();
477 add_lineno (frag_now
, frag_now_fix (), l
);
487 l
+= coff_line_base
- 1;
488 listing_source_line (l
);
493 demand_empty_rest_of_line ();
499 * Handle .def directives.
501 * One might ask : why can't we symbol_new if the symbol does not
502 * already exist and fill it with debug information. Because of
503 * the C_EFCN special symbol. It would clobber the value of the
504 * function symbol before we have a chance to notice that it is
505 * a C_EFCN. And a second reason is that the code is more clear this
506 * way. (at least I think it is :-).
510 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
511 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
512 *input_line_pointer == '\t') \
513 input_line_pointer++;
519 char name_end
; /* Char after the end of name */
520 char *symbol_name
; /* Name of the debug symbol */
521 char *symbol_name_copy
; /* Temporary copy of the name */
522 unsigned int symbol_name_length
;
524 if (def_symbol_in_progress
!= NULL
)
526 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
527 demand_empty_rest_of_line ();
529 } /* if not inside .def/.endef */
533 symbol_name
= input_line_pointer
;
534 #ifdef STRIP_UNDERSCORE
535 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
537 #endif /* STRIP_UNDERSCORE */
539 name_end
= get_symbol_end ();
540 symbol_name_length
= strlen (symbol_name
);
541 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
542 strcpy (symbol_name_copy
, symbol_name
);
544 /* Initialize the new symbol */
545 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
546 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
547 S_SET_VALUE (def_symbol_in_progress
, 0);
549 if (S_IS_STRING (def_symbol_in_progress
))
550 SF_SET_STRING (def_symbol_in_progress
);
552 *input_line_pointer
= name_end
;
554 demand_empty_rest_of_line ();
557 unsigned int dim_index
;
560 obj_coff_endef (ignore
)
564 /* DIM BUG FIX sac@cygnus.com */
566 if (def_symbol_in_progress
== NULL
)
568 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
569 demand_empty_rest_of_line ();
571 } /* if not inside .def/.endef */
573 /* Set the section number according to storage class. */
574 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
579 SF_SET_TAG (def_symbol_in_progress
);
580 /* intentional fallthrough */
583 SF_SET_DEBUG (def_symbol_in_progress
);
584 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
588 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
589 /* intentional fallthrough */
591 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
592 /* intentional fallthrough */
596 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
598 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
599 if (name
[1] == 'b' && name
[2] == 'f')
601 if (! in_function ())
602 as_warn ("`%s' symbol without preceding function", name
);
603 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
604 /* Will need relocating */
605 SF_SET_PROCESS (def_symbol_in_progress
);
613 #endif /* C_AUTOARG */
623 SF_SET_DEBUG (def_symbol_in_progress
);
624 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
630 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
636 as_warn ("unexpected storage class %d",
637 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
639 } /* switch on storage class */
641 /* Now that we have built a debug symbol, try to find if we should
642 merge with an existing symbol or not. If a symbol is C_EFCN or
643 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
645 /* Two cases for functions. Either debug followed by definition or
646 definition followed by debug. For definition first, we will
647 merge the debug symbol into the definition. For debug first, the
648 lineno entry MUST point to the definition function or else it
649 will point off into space when obj_crawl_symbol_chain() merges
650 the debug symbol into the real symbol. Therefor, let's presume
651 the debug symbol is a real function reference. */
653 /* FIXME-SOON If for some reason the definition label/symbol is
654 never seen, this will probably leave an undefined symbol at link
657 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
658 || (!strcmp (bfd_get_section_name (stdoutput
,
659 S_GET_SEGMENT (def_symbol_in_progress
)),
661 && !SF_GET_TAG (def_symbol_in_progress
))
662 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
663 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
665 if (def_symbol_in_progress
!= symbol_lastP
)
666 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
671 /* This symbol already exists, merge the newly created symbol
672 into the old one. This is not mandatory. The linker can
673 handle duplicate symbols correctly. But I guess that it save
674 a *lot* of space if the assembly file defines a lot of
677 /* The debug entry (def_symbol_in_progress) is merged into the
678 previous definition. */
680 c_symbol_merge (def_symbol_in_progress
, symbolP
);
681 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
682 def_symbol_in_progress
= symbolP
;
684 if (SF_GET_FUNCTION (def_symbol_in_progress
)
685 || SF_GET_TAG (def_symbol_in_progress
))
687 /* For functions, and tags, the symbol *must* be where the
688 debug symbol appears. Move the existing symbol to the
690 /* If it already is at the end of the symbol list, do nothing */
691 if (def_symbol_in_progress
!= symbol_lastP
)
693 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
694 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
699 if (SF_GET_TAG (def_symbol_in_progress
)
700 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
702 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
705 if (SF_GET_FUNCTION (def_symbol_in_progress
))
707 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
708 set_function (def_symbol_in_progress
);
709 SF_SET_PROCESS (def_symbol_in_progress
);
713 /* That is, if this is the first time we've seen the
715 symbol_table_insert (def_symbol_in_progress
);
716 } /* definition follows debug */
717 } /* Create the line number entry pointing to the function being defined */
719 def_symbol_in_progress
= NULL
;
720 demand_empty_rest_of_line ();
724 obj_coff_dim (ignore
)
729 if (def_symbol_in_progress
== NULL
)
731 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
732 demand_empty_rest_of_line ();
734 } /* if not inside .def/.endef */
736 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
738 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
741 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
742 get_absolute_expression ());
744 switch (*input_line_pointer
)
747 input_line_pointer
++;
751 as_warn ("badly formed .dim directive ignored");
752 /* intentional fallthrough */
760 demand_empty_rest_of_line ();
764 obj_coff_line (ignore
)
769 if (def_symbol_in_progress
== NULL
)
771 /* Probably stabs-style line? */
776 this_base
= get_absolute_expression ();
777 if (this_base
> coff_line_base
)
778 coff_line_base
= this_base
;
780 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
781 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
783 demand_empty_rest_of_line ();
787 obj_coff_size (ignore
)
790 if (def_symbol_in_progress
== NULL
)
792 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
793 demand_empty_rest_of_line ();
795 } /* if not inside .def/.endef */
797 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
798 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
799 demand_empty_rest_of_line ();
803 obj_coff_scl (ignore
)
806 if (def_symbol_in_progress
== NULL
)
808 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
809 demand_empty_rest_of_line ();
811 } /* if not inside .def/.endef */
813 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
814 demand_empty_rest_of_line ();
818 obj_coff_tag (ignore
)
824 if (def_symbol_in_progress
== NULL
)
826 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
827 demand_empty_rest_of_line ();
831 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
832 symbol_name
= input_line_pointer
;
833 name_end
= get_symbol_end ();
835 /* Assume that the symbol referred to by .tag is always defined.
836 This was a bad assumption. I've added find_or_make. xoxorich. */
837 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
838 tag_find_or_make (symbol_name
));
839 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
841 as_warn ("tag not found for .tag %s", symbol_name
);
844 SF_SET_TAGGED (def_symbol_in_progress
);
845 *input_line_pointer
= name_end
;
847 demand_empty_rest_of_line ();
851 obj_coff_type (ignore
)
854 if (def_symbol_in_progress
== NULL
)
856 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
857 demand_empty_rest_of_line ();
859 } /* if not inside .def/.endef */
861 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
863 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
864 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
866 SF_SET_FUNCTION (def_symbol_in_progress
);
867 } /* is a function */
869 demand_empty_rest_of_line ();
873 obj_coff_val (ignore
)
876 if (def_symbol_in_progress
== NULL
)
878 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
879 demand_empty_rest_of_line ();
881 } /* if not inside .def/.endef */
883 if (is_name_beginner (*input_line_pointer
))
885 char *symbol_name
= input_line_pointer
;
886 char name_end
= get_symbol_end ();
888 if (!strcmp (symbol_name
, "."))
890 def_symbol_in_progress
->sy_frag
= frag_now
;
891 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
892 /* If the .val is != from the .def (e.g. statics) */
894 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
896 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
897 def_symbol_in_progress
->sy_value
.X_add_symbol
=
898 symbol_find_or_make (symbol_name
);
899 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
900 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
902 /* If the segment is undefined when the forward reference is
903 resolved, then copy the segment id from the forward
905 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
907 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
908 *input_line_pointer
= name_end
;
912 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
913 } /* if symbol based */
915 demand_empty_rest_of_line ();
919 obj_read_begin_hook ()
921 /* These had better be the same. Usually 18 bytes. */
923 know (sizeof (SYMENT
) == sizeof (AUXENT
));
924 know (SYMESZ
== AUXESZ
);
930 symbolS
*coff_last_function
;
933 coff_frob_symbol (symp
, punt
)
937 static symbolS
*last_tagP
;
938 static stack
*block_stack
;
939 static symbolS
*set_end
;
941 if (symp
== &abs_symbol
)
947 if (current_lineno_sym
)
948 coff_add_linesym ((symbolS
*) 0);
951 block_stack
= stack_init (512, sizeof (symbolS
*));
953 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
954 S_SET_STORAGE_CLASS (symp
, C_EXT
);
956 if (!SF_GET_DEBUG (symp
))
959 if (!SF_GET_LOCAL (symp
)
960 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
963 c_symbol_merge (symp
, real
);
966 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
968 assert (S_GET_VALUE (symp
) == 0);
969 S_SET_EXTERNAL (symp
);
971 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
973 if (S_GET_SEGMENT (symp
) == text_section
)
974 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
976 S_SET_STORAGE_CLASS (symp
, C_STAT
);
978 if (SF_GET_PROCESS (symp
))
980 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
982 if (!strcmp (S_GET_NAME (symp
), ".bb"))
983 stack_push (block_stack
, (char *) &symp
);
987 begin
= *(symbolS
**) stack_pop (block_stack
);
989 as_warn ("mismatched .eb");
994 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
996 union internal_auxent
*auxp
;
997 coff_last_function
= symp
;
998 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
999 S_SET_NUMBER_AUXILIARY (symp
, 1);
1000 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
1001 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1002 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1004 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1006 if (coff_last_function
== 0)
1007 as_fatal ("C_EFCN symbol out of scope");
1008 SA_SET_SYM_FSIZE (coff_last_function
,
1009 (long) (S_GET_VALUE (symp
)
1010 - S_GET_VALUE (coff_last_function
)));
1011 set_end
= coff_last_function
;
1012 coff_last_function
= 0;
1015 else if (SF_GET_TAG (symp
))
1017 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1018 set_end
= last_tagP
;
1019 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1021 if (S_GET_VALUE (symp
))
1023 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1024 S_SET_VALUE (symp
, 0);
1027 if (S_IS_EXTERNAL (symp
))
1028 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1029 else if (SF_GET_LOCAL (symp
))
1034 if (set_end
!= (symbolS
*) NULL
1037 SA_SET_SYM_ENDNDX (set_end
, symp
);
1041 if (coffsymbol (symp
->bsym
)->lineno
)
1044 struct line_no
*lptr
;
1047 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1048 for (i
= 0; lptr
; lptr
= lptr
->next
)
1051 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1052 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, n
* sizeof (alent
));
1053 coffsymbol (symp
->bsym
)->lineno
= l
;
1054 for (i
= n
- 1; i
> 0; i
--)
1057 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1065 * implement the .section pseudo op:
1066 * .section name {, "flags"}
1068 * | +--- optional flags: 'b' for bss
1070 * +-- section name 'l' for lib
1074 * 'd' (apparently m88k for data)
1076 * But if the argument is not a quoted string, treat it as a
1077 * subsegment number.
1081 obj_coff_section (ignore
)
1084 /* Strip out the section name */
1092 section_name
= input_line_pointer
;
1093 c
= get_symbol_end ();
1095 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1096 strcpy (name
, section_name
);
1098 *input_line_pointer
= c
;
1103 flags
= SEC_NO_FLAGS
;
1105 if (*input_line_pointer
== ',')
1107 ++input_line_pointer
;
1109 if (*input_line_pointer
!= '"')
1110 exp
= get_absolute_expression ();
1113 ++input_line_pointer
;
1114 while (*input_line_pointer
!= '"'
1115 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1117 switch (*input_line_pointer
)
1119 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1120 case 'n': flags
&=~ SEC_LOAD
; break;
1122 case 'w': flags
&=~ SEC_READONLY
; break;
1123 case 'x': flags
|= SEC_CODE
; break;
1125 case 'i': /* STYP_INFO */
1126 case 'l': /* STYP_LIB */
1127 case 'o': /* STYP_OVER */
1128 as_warn ("unsupported section attribute '%c'",
1129 *input_line_pointer
);
1133 as_warn("unknown section attribute '%c'",
1134 *input_line_pointer
);
1137 ++input_line_pointer
;
1139 if (*input_line_pointer
== '"')
1140 ++input_line_pointer
;
1144 sec
= subseg_new (name
, (subsegT
) exp
);
1146 if (flags
!= SEC_NO_FLAGS
)
1148 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1149 as_warn ("error setting flags for \"%s\": %s",
1150 bfd_section_name (stdoutput
, sec
),
1151 bfd_errmsg (bfd_get_error ()));
1156 coff_adjust_symtab ()
1158 if (symbol_rootP
== NULL
1159 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1161 assert (previous_file_symbol
== 0);
1162 c_dot_file_symbol ("fake");
1167 coff_frob_section (sec
)
1173 bfd_vma size
, n_entries
, mask
;
1175 /* The COFF back end in BFD requires that all section sizes be
1176 rounded up to multiples of the corresponding section alignments.
1177 Seems kinda silly to me, but that's the way it is. */
1178 size
= bfd_get_section_size_before_reloc (sec
);
1179 assert (sec
->alignment_power
>= stdoutput
->xvec
->align_power_min
);
1180 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1182 bfd_set_section_size (stdoutput
, sec
, (size
+ mask
) & ~mask
);
1184 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1185 #ifndef STAB_SECTION_NAME
1186 #define STAB_SECTION_NAME ".stab"
1188 #ifndef STAB_STRING_SECTION_NAME
1189 #define STAB_STRING_SECTION_NAME ".stabstr"
1191 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1195 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1196 /* size is already rounded up, since other section will be listed first */
1197 size
= bfd_get_section_size_before_reloc (strsec
);
1199 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1201 /* Find first non-empty frag. It should be large enough. */
1202 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1203 while (fragp
&& fragp
->fr_fix
== 0)
1204 fragp
= fragp
->fr_next
;
1205 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1207 /* Store the values. */
1208 p
= fragp
->fr_literal
;
1209 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1210 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1214 obj_coff_init_stab_section (seg
)
1220 unsigned int stroff
;
1222 /* Make space for this first symbol. */
1226 as_where (&file
, (unsigned int *) NULL
);
1227 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1228 strcpy (stabstr_name
, seg
->name
);
1229 strcat (stabstr_name
, "str");
1230 stroff
= get_stab_string_offset (file
, stabstr_name
);
1232 md_number_to_chars (p
, stroff
, 4);
1241 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1249 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1251 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1252 (unsigned long) symbolP
,
1253 S_GET_NAME(symbolP
),
1254 (long) S_GET_DATA_TYPE(symbolP
),
1255 S_GET_STORAGE_CLASS(symbolP
),
1256 (int) S_GET_SEGMENT(symbolP
));
1262 #else /* not BFD_ASSEMBLER */
1265 /* This is needed because we include internal bfd things. */
1267 #include "../bfd/libbfd.h"
1268 #include "../bfd/libcoff.h"
1270 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1271 that we can stick sections together without causing trouble. */
1273 #define NOP_OPCODE 0x00
1276 #define MIN(a,b) ((a) < (b)? (a) : (b))
1277 /* This vector is used to turn an internal segment into a section #
1278 suitable for insertion into a coff symbol table
1281 const short seg_N_TYPE
[] =
1282 { /* in: segT out: N_TYPE bits */
1294 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1295 C_UNDEF_SECTION
, /* SEG_GOOF */
1296 C_UNDEF_SECTION
, /* SEG_EXPR */
1297 C_DEBUG_SECTION
, /* SEG_DEBUG */
1298 C_NTV_SECTION
, /* SEG_NTV */
1299 C_PTV_SECTION
, /* SEG_PTV */
1300 C_REGISTER_SECTION
, /* SEG_REGISTER */
1303 int function_lineoff
= -1; /* Offset in line#s where the last function
1304 started (the odd entry for line #0) */
1306 static symbolS
*last_line_symbol
;
1308 /* Add 4 to the real value to get the index and compensate the
1309 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1310 section number into a segment number
1312 static symbolS
*previous_file_symbol
= NULL
;
1313 void c_symbol_merge ();
1314 static int line_base
;
1316 symbolS
*c_section_symbol ();
1319 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1320 segT this_segment_type
));
1323 static void fixup_mdeps
PARAMS ((fragS
*,
1328 static void fill_section
PARAMS ((bfd
* abfd
,
1333 static symbolS
*tag_find_or_make
PARAMS ((char *name
));
1334 static symbolS
*tag_find
PARAMS ((char *name
));
1335 static void tag_init
PARAMS ((void));
1336 static void tag_insert
PARAMS ((char *name
, symbolS
* symbolP
));
1337 char *s_get_name
PARAMS ((symbolS
* s
));
1339 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1340 unsigned short line_number
,
1344 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1345 symbolS
* symbol_rootP
));
1347 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1349 static struct hash_control
*tag_hash
;
1351 static symbolS
*def_symbol_in_progress
= NULL
;
1353 static void obj_coff_def
PARAMS ((int));
1354 static void obj_coff_dim
PARAMS ((int));
1355 static void obj_coff_endef
PARAMS ((int));
1356 static void obj_coff_line
PARAMS ((int));
1357 static void obj_coff_ln
PARAMS ((int));
1358 static void obj_coff_scl
PARAMS ((int));
1359 static void obj_coff_size
PARAMS ((int));
1360 static void obj_coff_tag
PARAMS ((int));
1361 static void obj_coff_type
PARAMS ((int));
1362 static void obj_coff_val
PARAMS ((int));
1363 static void obj_coff_lcomm
PARAMS ((int));
1364 static void obj_coff_text
PARAMS ((int));
1365 static void obj_coff_data
PARAMS ((int));
1366 static void obj_coff_bss
PARAMS ((int));
1367 static void obj_coff_ident
PARAMS ((int));
1368 void obj_coff_section
PARAMS ((int));
1370 const pseudo_typeS obj_pseudo_table
[] =
1372 {"def", obj_coff_def
, 0},
1373 {"dim", obj_coff_dim
, 0},
1374 {"endef", obj_coff_endef
, 0},
1375 {"line", obj_coff_line
, 0},
1376 {"ln", obj_coff_ln
, 0},
1377 {"appline", obj_coff_ln
, 1},
1378 {"scl", obj_coff_scl
, 0},
1379 {"size", obj_coff_size
, 0},
1380 {"tag", obj_coff_tag
, 0},
1381 {"type", obj_coff_type
, 0},
1382 {"val", obj_coff_val
, 0},
1383 {"section", obj_coff_section
, 0},
1384 {"use", obj_coff_section
, 0},
1385 {"sect", obj_coff_section
, 0},
1386 {"text", obj_coff_text
, 0},
1387 {"data", obj_coff_data
, 0},
1388 {"bss", obj_coff_bss
, 0},
1389 {"ident", obj_coff_ident
, 0},
1390 {"ABORT", s_abort
, 0},
1391 {"lcomm", obj_coff_lcomm
, 0},
1393 /* The m88k uses sdef instead of def. */
1394 {"sdef", obj_coff_def
, 0},
1396 {NULL
} /* end sentinel */
1397 }; /* obj_pseudo_table */
1402 unsigned long chunk_size
;
1403 unsigned long element_size
;
1406 unsigned long pointer
;
1411 stack_init (chunk_size
, element_size
)
1412 unsigned long chunk_size
;
1413 unsigned long element_size
;
1417 st
= (stack
*) malloc (sizeof (stack
));
1420 st
->data
= malloc (chunk_size
);
1427 st
->size
= chunk_size
;
1428 st
->chunk_size
= chunk_size
;
1429 st
->element_size
= element_size
;
1442 stack_push (st
, element
)
1446 if (st
->pointer
+ st
->element_size
>= st
->size
)
1448 st
->size
+= st
->chunk_size
;
1449 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
1452 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
1453 st
->pointer
+= st
->element_size
;
1454 return st
->data
+ st
->pointer
;
1461 if (st
->pointer
< st
->element_size
)
1466 st
->pointer
-= st
->element_size
;
1467 return st
->data
+ st
->pointer
;
1471 * Maintain a list of the tagnames of the structres.
1477 tag_hash
= hash_new ();
1481 tag_insert (name
, symbolP
)
1485 const char *error_string
;
1487 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
1489 as_fatal ("Inserting \"%s\" into structure table failed: %s",
1490 name
, error_string
);
1495 tag_find_or_make (name
)
1500 if ((symbolP
= tag_find (name
)) == NULL
)
1502 symbolP
= symbol_new (name
, undefined_section
,
1503 0, &zero_address_frag
);
1505 tag_insert (S_GET_NAME (symbolP
), symbolP
);
1515 #ifdef STRIP_UNDERSCORE
1518 #endif /* STRIP_UNDERSCORE */
1519 return (symbolS
*) hash_find (tag_hash
, name
);
1524 We allow more than just the standard 3 sections, infact, we allow
1525 10 sections, (though the usual three have to be there).
1527 This structure performs the mappings for us:
1538 seg_info_type seg_info_off_by_4
[N_SEG
] =
1569 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1570 #define SEG_INFO_FROM_SEG_NUMBER(x) (seg_info_off_by_4[(x)])
1573 static relax_addressT
1574 relax_align (address
, alignment
)
1575 relax_addressT address
;
1578 relax_addressT mask
;
1579 relax_addressT new_address
;
1581 mask
= ~((~0) << alignment
);
1582 new_address
= (address
+ mask
) & (~mask
);
1583 return (new_address
- address
);
1584 } /* relax_align() */
1591 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1596 /* calculate the size of the frag chain and fill in the section header
1597 to contain all of it, also fill in the addr of the sections */
1599 size_section (abfd
, idx
)
1604 unsigned int size
= 0;
1605 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1608 size
= frag
->fr_address
;
1609 if (frag
->fr_address
!= size
)
1611 printf ("Out of step\n");
1612 size
= frag
->fr_address
;
1615 switch (frag
->fr_type
)
1617 #ifdef TC_COFF_SIZEMACHDEP
1618 case rs_machine_dependent
:
1619 size
+= TC_COFF_SIZEMACHDEP (frag
);
1624 size
+= frag
->fr_fix
;
1625 size
+= frag
->fr_offset
* frag
->fr_var
;
1628 size
+= frag
->fr_fix
;
1629 size
+= relax_align (size
, frag
->fr_offset
);
1632 BAD_CASE (frag
->fr_type
);
1635 frag
= frag
->fr_next
;
1637 segment_info
[idx
].scnhdr
.s_size
= size
;
1643 count_entries_in_chain (idx
)
1646 unsigned int nrelocs
;
1649 /* Count the relocations */
1650 fixup_ptr
= segment_info
[idx
].fix_root
;
1652 while (fixup_ptr
!= (fixS
*) NULL
)
1654 if (TC_COUNT_RELOC (fixup_ptr
))
1657 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1666 fixup_ptr
= fixup_ptr
->fx_next
;
1671 /* output all the relocations for a section */
1673 do_relocs_for (abfd
, h
, file_cursor
)
1676 unsigned long *file_cursor
;
1678 unsigned int nrelocs
;
1680 unsigned long reloc_start
= *file_cursor
;
1682 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1684 if (segment_info
[idx
].scnhdr
.s_name
[0])
1686 struct external_reloc
*ext_ptr
;
1687 struct external_reloc
*external_reloc_vec
;
1688 unsigned int external_reloc_size
;
1689 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1690 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1691 nrelocs
= count_entries_in_chain (idx
);
1694 /* Bypass this stuff if no relocs. This also incidentally
1695 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1697 external_reloc_size
= nrelocs
* RELSZ
;
1698 external_reloc_vec
=
1699 (struct external_reloc
*) malloc (external_reloc_size
);
1701 ext_ptr
= external_reloc_vec
;
1703 /* Fill in the internal coff style reloc struct from the
1704 internal fix list. */
1707 symbolS
*symbol_ptr
;
1708 struct internal_reloc intr
;
1710 /* Only output some of the relocations */
1711 if (TC_COUNT_RELOC (fix_ptr
))
1713 #ifdef TC_RELOC_MANGLE
1714 TC_RELOC_MANGLE (fix_ptr
, &intr
, base
);
1718 symbol_ptr
= fix_ptr
->fx_addsy
;
1720 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1722 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1725 intr
.r_offset
= fix_ptr
->fx_offset
;
1730 /* Turn the segment of the symbol into an offset. */
1733 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1736 intr
.r_symndx
= dot
->sy_number
;
1740 intr
.r_symndx
= symbol_ptr
->sy_number
;
1750 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1753 #if defined(TC_A29K)
1755 /* The 29k has a special kludge for the high 16 bit
1756 reloc. Two relocations are emited, R_IHIHALF,
1757 and R_IHCONST. The second one doesn't contain a
1758 symbol, but uses the value for offset. */
1760 if (intr
.r_type
== R_IHIHALF
)
1762 /* now emit the second bit */
1763 intr
.r_type
= R_IHCONST
;
1764 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1765 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1771 fix_ptr
= fix_ptr
->fx_next
;
1774 /* Write out the reloc table */
1775 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1777 free (external_reloc_vec
);
1779 /* Fill in section header info. */
1780 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1781 *file_cursor
+= external_reloc_size
;
1782 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1787 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1791 /* Set relocation_size field in file headers */
1792 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1796 /* run through a frag chain and write out the data to go with it, fill
1797 in the scnhdrs with the info on the file postions
1800 fill_section (abfd
, h
, file_cursor
)
1803 unsigned long *file_cursor
;
1807 unsigned int paddr
= 0;
1809 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1811 unsigned int offset
= 0;
1813 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1817 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1824 buffer
= xmalloc (s
->s_size
);
1825 s
->s_scnptr
= *file_cursor
;
1827 know (s
->s_paddr
== paddr
);
1829 if (strcmp (s
->s_name
, ".text") == 0)
1830 s
->s_flags
|= STYP_TEXT
;
1831 else if (strcmp (s
->s_name
, ".data") == 0)
1832 s
->s_flags
|= STYP_DATA
;
1833 else if (strcmp (s
->s_name
, ".bss") == 0)
1836 s
->s_flags
|= STYP_BSS
;
1838 /* @@ Should make the i386 and a29k coff targets define
1839 COFF_NOLOAD_PROBLEM, and have only one test here. */
1842 #ifndef COFF_NOLOAD_PROBLEM
1843 /* Apparently the SVR3 linker (and exec syscall) and UDI
1844 mondfe progrem are confused by noload sections. */
1845 s
->s_flags
|= STYP_NOLOAD
;
1850 else if (strcmp (s
->s_name
, ".lit") == 0)
1851 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1852 else if (strcmp (s
->s_name
, ".init") == 0)
1853 s
->s_flags
|= STYP_TEXT
;
1854 else if (strcmp (s
->s_name
, ".fini") == 0)
1855 s
->s_flags
|= STYP_TEXT
;
1856 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1857 s
->s_flags
|= STYP_INFO
;
1861 unsigned int fill_size
;
1862 switch (frag
->fr_type
)
1864 case rs_machine_dependent
:
1867 memcpy (buffer
+ frag
->fr_address
,
1869 (unsigned int) frag
->fr_fix
);
1870 offset
+= frag
->fr_fix
;
1879 memcpy (buffer
+ frag
->fr_address
,
1881 (unsigned int) frag
->fr_fix
);
1882 offset
+= frag
->fr_fix
;
1885 fill_size
= frag
->fr_var
;
1886 if (fill_size
&& frag
->fr_offset
> 0)
1889 unsigned int off
= frag
->fr_fix
;
1890 for (count
= frag
->fr_offset
; count
; count
--)
1892 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1894 memcpy (buffer
+ frag
->fr_address
+ off
,
1895 frag
->fr_literal
+ frag
->fr_fix
,
1898 offset
+= fill_size
;
1903 case rs_broken_word
:
1908 frag
= frag
->fr_next
;
1913 if (s
->s_scnptr
!= 0)
1915 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1916 *file_cursor
+= s
->s_size
;
1925 /* Coff file generation & utilities */
1928 coff_header_append (abfd
, h
)
1936 bfd_seek (abfd
, 0, 0);
1938 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1939 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1940 H_SET_VERSION_STAMP (h
, 0);
1941 H_SET_ENTRY_POINT (h
, 0);
1942 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1943 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1944 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1946 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1947 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1948 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1950 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1952 bfd_write (buffer
, i
, 1, abfd
);
1953 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1955 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1957 if (segment_info
[i
].scnhdr
.s_name
[0])
1960 bfd_coff_swap_scnhdr_out (abfd
,
1961 &(segment_info
[i
].scnhdr
),
1963 bfd_write (buffer
, size
, 1, abfd
);
1970 symbol_to_chars (abfd
, where
, symbolP
)
1975 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1979 /* Turn any symbols with register attributes into abs symbols */
1980 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1982 S_SET_SEGMENT (symbolP
, absolute_section
);
1984 /* At the same time, relocate all symbols to their output value */
1986 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1987 + S_GET_VALUE (symbolP
));
1989 S_SET_VALUE (symbolP
, val
);
1991 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1993 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1996 for (i
= 0; i
< numaux
; i
++)
1998 where
+= bfd_coff_swap_aux_out (abfd
,
1999 &symbolP
->sy_symbol
.ost_auxent
[i
],
2000 S_GET_DATA_TYPE (symbolP
),
2001 S_GET_STORAGE_CLASS (symbolP
),
2009 obj_symbol_new_hook (symbolP
)
2012 char underscore
= 0; /* Symbol has leading _ */
2014 /* Effective symbol */
2015 /* Store the pointer in the offset. */
2016 S_SET_ZEROES (symbolP
, 0L);
2017 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2018 S_SET_STORAGE_CLASS (symbolP
, 0);
2019 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2020 /* Additional information */
2021 symbolP
->sy_symbol
.ost_flags
= 0;
2022 /* Auxiliary entries */
2023 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2025 if (S_IS_STRING (symbolP
))
2026 SF_SET_STRING (symbolP
);
2027 if (!underscore
&& S_IS_LOCAL (symbolP
))
2028 SF_SET_LOCAL (symbolP
);
2032 * Handle .ln directives.
2036 obj_coff_ln (appline
)
2041 if (! appline
&& def_symbol_in_progress
!= NULL
)
2043 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2044 demand_empty_rest_of_line ();
2046 } /* wrong context */
2049 obstack_next_free (&frags
) - frag_now
->fr_literal
,
2050 l
= get_absolute_expression (),
2060 listing_source_line ((unsigned int) l
);
2065 demand_empty_rest_of_line ();
2071 * Handle .def directives.
2073 * One might ask : why can't we symbol_new if the symbol does not
2074 * already exist and fill it with debug information. Because of
2075 * the C_EFCN special symbol. It would clobber the value of the
2076 * function symbol before we have a chance to notice that it is
2077 * a C_EFCN. And a second reason is that the code is more clear this
2078 * way. (at least I think it is :-).
2082 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2083 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2084 *input_line_pointer == '\t') \
2085 input_line_pointer++;
2091 char name_end
; /* Char after the end of name */
2092 char *symbol_name
; /* Name of the debug symbol */
2093 char *symbol_name_copy
; /* Temporary copy of the name */
2094 unsigned int symbol_name_length
;
2096 if (def_symbol_in_progress
!= NULL
)
2098 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2099 demand_empty_rest_of_line ();
2101 } /* if not inside .def/.endef */
2103 SKIP_WHITESPACES ();
2105 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2106 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2108 symbol_name
= input_line_pointer
;
2109 name_end
= get_symbol_end ();
2110 symbol_name_length
= strlen (symbol_name
);
2111 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2112 strcpy (symbol_name_copy
, symbol_name
);
2114 /* Initialize the new symbol */
2115 #ifdef STRIP_UNDERSCORE
2116 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2117 ? symbol_name_copy
+ 1
2118 : symbol_name_copy
));
2119 #else /* STRIP_UNDERSCORE */
2120 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2121 #endif /* STRIP_UNDERSCORE */
2122 /* free(symbol_name_copy); */
2123 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2124 def_symbol_in_progress
->sy_number
= ~0;
2125 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2126 S_SET_VALUE (def_symbol_in_progress
, 0);
2128 if (S_IS_STRING (def_symbol_in_progress
))
2129 SF_SET_STRING (def_symbol_in_progress
);
2131 *input_line_pointer
= name_end
;
2133 demand_empty_rest_of_line ();
2136 unsigned int dim_index
;
2140 obj_coff_endef (ignore
)
2143 symbolS
*symbolP
= 0;
2144 /* DIM BUG FIX sac@cygnus.com */
2146 if (def_symbol_in_progress
== NULL
)
2148 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2149 demand_empty_rest_of_line ();
2151 } /* if not inside .def/.endef */
2153 /* Set the section number according to storage class. */
2154 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2159 SF_SET_TAG (def_symbol_in_progress
);
2160 /* intentional fallthrough */
2163 SF_SET_DEBUG (def_symbol_in_progress
);
2164 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2168 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2169 /* intentional fallthrough */
2171 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2172 /* intentional fallthrough */
2174 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2176 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2178 if (function_lineoff
< 0)
2180 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2181 } /* missing function symbol */
2182 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2184 SF_SET_PROCESS (last_line_symbol
);
2185 function_lineoff
= -1;
2187 /* Value is always set to . */
2188 def_symbol_in_progress
->sy_frag
= frag_now
;
2189 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2194 #endif /* C_AUTOARG */
2204 SF_SET_DEBUG (def_symbol_in_progress
);
2205 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2211 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2217 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2219 } /* switch on storage class */
2221 /* Now that we have built a debug symbol, try to find if we should
2222 merge with an existing symbol or not. If a symbol is C_EFCN or
2223 absolute_section or untagged SEG_DEBUG it never merges. We also
2224 don't merge labels, which are in a different namespace, nor
2225 symbols which have not yet been defined since they are typically
2226 unique, nor do we merge tags with non-tags. */
2228 /* Two cases for functions. Either debug followed by definition or
2229 definition followed by debug. For definition first, we will
2230 merge the debug symbol into the definition. For debug first, the
2231 lineno entry MUST point to the definition function or else it
2232 will point off into space when crawl_symbols() merges the debug
2233 symbol into the real symbol. Therefor, let's presume the debug
2234 symbol is a real function reference. */
2236 /* FIXME-SOON If for some reason the definition label/symbol is
2237 never seen, this will probably leave an undefined symbol at link
2240 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2241 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2242 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2243 && !SF_GET_TAG (def_symbol_in_progress
))
2244 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2245 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2246 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2247 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2249 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2254 /* This symbol already exists, merge the newly created symbol
2255 into the old one. This is not mandatory. The linker can
2256 handle duplicate symbols correctly. But I guess that it save
2257 a *lot* of space if the assembly file defines a lot of
2260 /* The debug entry (def_symbol_in_progress) is merged into the
2261 previous definition. */
2263 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2264 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2265 def_symbol_in_progress
= symbolP
;
2267 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2268 || SF_GET_TAG (def_symbol_in_progress
))
2270 /* For functions, and tags, the symbol *must* be where the
2271 debug symbol appears. Move the existing symbol to the
2273 /* If it already is at the end of the symbol list, do nothing */
2274 if (def_symbol_in_progress
!= symbol_lastP
)
2276 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2278 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2279 &symbol_rootP
, &symbol_lastP
);
2280 } /* if not already in place */
2282 } /* normal or mergable */
2284 if (SF_GET_TAG (def_symbol_in_progress
)
2285 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2287 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2290 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2292 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2294 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2296 SF_SET_PROCESS (def_symbol_in_progress
);
2298 if (symbolP
== NULL
)
2300 /* That is, if this is the first time we've seen the
2302 symbol_table_insert (def_symbol_in_progress
);
2303 } /* definition follows debug */
2304 } /* Create the line number entry pointing to the function being defined */
2306 def_symbol_in_progress
= NULL
;
2307 demand_empty_rest_of_line ();
2311 obj_coff_dim (ignore
)
2316 if (def_symbol_in_progress
== NULL
)
2318 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2319 demand_empty_rest_of_line ();
2321 } /* if not inside .def/.endef */
2323 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2325 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2327 SKIP_WHITESPACES ();
2328 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2329 get_absolute_expression ());
2331 switch (*input_line_pointer
)
2334 input_line_pointer
++;
2338 as_warn ("badly formed .dim directive ignored");
2339 /* intentional fallthrough */
2347 demand_empty_rest_of_line ();
2351 obj_coff_line (ignore
)
2356 if (def_symbol_in_progress
== NULL
)
2362 this_base
= get_absolute_expression ();
2363 if (this_base
> line_base
)
2365 line_base
= this_base
;
2373 listing_source_line ((unsigned int) line_base
);
2377 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2378 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2380 demand_empty_rest_of_line ();
2384 obj_coff_size (ignore
)
2387 if (def_symbol_in_progress
== NULL
)
2389 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2390 demand_empty_rest_of_line ();
2392 } /* if not inside .def/.endef */
2394 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2395 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2396 demand_empty_rest_of_line ();
2400 obj_coff_scl (ignore
)
2403 if (def_symbol_in_progress
== NULL
)
2405 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2406 demand_empty_rest_of_line ();
2408 } /* if not inside .def/.endef */
2410 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2411 demand_empty_rest_of_line ();
2415 obj_coff_tag (ignore
)
2421 if (def_symbol_in_progress
== NULL
)
2423 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2424 demand_empty_rest_of_line ();
2428 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2429 symbol_name
= input_line_pointer
;
2430 name_end
= get_symbol_end ();
2432 /* Assume that the symbol referred to by .tag is always defined.
2433 This was a bad assumption. I've added find_or_make. xoxorich. */
2434 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2435 (long) tag_find_or_make (symbol_name
));
2436 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2438 as_warn ("tag not found for .tag %s", symbol_name
);
2441 SF_SET_TAGGED (def_symbol_in_progress
);
2442 *input_line_pointer
= name_end
;
2444 demand_empty_rest_of_line ();
2448 obj_coff_type (ignore
)
2451 if (def_symbol_in_progress
== NULL
)
2453 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2454 demand_empty_rest_of_line ();
2456 } /* if not inside .def/.endef */
2458 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2460 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2461 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2463 SF_SET_FUNCTION (def_symbol_in_progress
);
2464 } /* is a function */
2466 demand_empty_rest_of_line ();
2470 obj_coff_val (ignore
)
2473 if (def_symbol_in_progress
== NULL
)
2475 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2476 demand_empty_rest_of_line ();
2478 } /* if not inside .def/.endef */
2480 if (is_name_beginner (*input_line_pointer
))
2482 char *symbol_name
= input_line_pointer
;
2483 char name_end
= get_symbol_end ();
2485 if (!strcmp (symbol_name
, "."))
2487 def_symbol_in_progress
->sy_frag
= frag_now
;
2488 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2489 /* If the .val is != from the .def (e.g. statics) */
2491 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2493 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2494 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2495 symbol_find_or_make (symbol_name
);
2496 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2497 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2499 /* If the segment is undefined when the forward reference is
2500 resolved, then copy the segment id from the forward
2502 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2504 /* FIXME: gcc can generate address expressions
2505 here in unusual cases (search for "obscure"
2506 in sdbout.c). We just ignore the offset
2507 here, thus generating incorrect debugging
2508 information. We ignore the rest of the
2511 /* Otherwise, it is the name of a non debug symbol and
2512 its value will be calculated later. */
2513 *input_line_pointer
= name_end
;
2515 /* FIXME: this is to avoid an error message in the
2516 FIXME case mentioned just above. */
2517 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2518 ++input_line_pointer
;
2522 S_SET_VALUE (def_symbol_in_progress
,
2523 (valueT
) get_absolute_expression ());
2524 } /* if symbol based */
2526 demand_empty_rest_of_line ();
2530 obj_read_begin_hook ()
2532 /* These had better be the same. Usually 18 bytes. */
2534 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2535 know (SYMESZ
== AUXESZ
);
2540 /* This function runs through the symbol table and puts all the
2541 externals onto another chain */
2543 /* The chain of externals */
2544 symbolS
*symbol_externP
= NULL
;
2545 symbolS
*symbol_extern_lastP
= NULL
;
2548 symbolS
*last_functionP
= NULL
;
2555 unsigned int symbol_number
= 0;
2556 unsigned int last_file_symno
= 0;
2558 for (symbolP
= symbol_rootP
;
2560 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2562 if (!SF_GET_DEBUG (symbolP
))
2564 /* Debug symbols do not need all this rubbish */
2565 symbolS
*real_symbolP
;
2567 /* L* and C_EFCN symbols never merge. */
2568 if (!SF_GET_LOCAL (symbolP
)
2569 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2570 && symbolP
->sy_value
.X_op
== O_constant
2571 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2572 && real_symbolP
!= symbolP
)
2574 /* FIXME-SOON: where do dups come from?
2575 Maybe tag references before definitions? xoxorich. */
2576 /* Move the debug data from the debug symbol to the
2577 real symbol. Do NOT do the oposite (i.e. move from
2578 real symbol to debug symbol and remove real symbol from the
2579 list.) Because some pointers refer to the real symbol
2580 whereas no pointers refer to the debug symbol. */
2581 c_symbol_merge (symbolP
, real_symbolP
);
2582 /* Replace the current symbol by the real one */
2583 /* The symbols will never be the last or the first
2584 because : 1st symbol is .file and 3 last symbols are
2585 .text, .data, .bss */
2586 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2587 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2588 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2589 symbolP
= real_symbolP
;
2590 } /* if not local but dup'd */
2592 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2594 S_SET_SEGMENT (symbolP
, SEG_E0
);
2595 } /* push data into text */
2597 resolve_symbol_value (symbolP
);
2599 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2601 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2603 S_SET_EXTERNAL (symbolP
);
2605 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2607 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2611 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2615 /* Mainly to speed up if not -g */
2616 if (SF_GET_PROCESS (symbolP
))
2618 /* Handle the nested blocks auxiliary info. */
2619 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2621 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2622 stack_push (block_stack
, (char *) &symbolP
);
2625 register symbolS
*begin_symbolP
;
2626 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2627 if (begin_symbolP
== (symbolS
*) 0)
2628 as_warn ("mismatched .eb");
2630 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2633 /* If we are able to identify the type of a function, and we
2634 are out of a function (last_functionP == 0) then, the
2635 function symbol will be associated with an auxiliary
2637 if (last_functionP
== (symbolS
*) 0 &&
2638 SF_GET_FUNCTION (symbolP
))
2640 last_functionP
= symbolP
;
2642 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2644 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2645 } /* make it at least 1 */
2647 /* Clobber possible stale .dim information. */
2649 /* Iffed out by steve - this fries the lnnoptr info too */
2650 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2651 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2654 /* The C_FCN doesn't need any additional information. I
2655 don't even know if this is needed for sdb. But the
2656 standard assembler generates it, so... */
2657 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2659 if (last_functionP
== (symbolS
*) 0)
2660 as_fatal ("C_EFCN symbol out of scope");
2661 SA_SET_SYM_FSIZE (last_functionP
,
2662 (long) (S_GET_VALUE (symbolP
) -
2663 S_GET_VALUE (last_functionP
)));
2664 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2665 last_functionP
= (symbolS
*) 0;
2669 else if (SF_GET_TAG (symbolP
))
2671 /* First descriptor of a structure must point to
2672 the first slot after the structure description. */
2673 last_tagP
= symbolP
;
2676 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2678 /* +2 take in account the current symbol */
2679 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2681 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2683 if (S_GET_VALUE (symbolP
))
2685 S_SET_VALUE (symbolP
, last_file_symno
);
2686 last_file_symno
= symbol_number
;
2687 } /* no one points at the first .file symbol */
2688 } /* if debug or tag or eos or file */
2690 /* We must put the external symbols apart. The loader
2691 does not bomb if we do not. But the references in
2692 the endndx field for a .bb symbol are not corrected
2693 if an external symbol is removed between .bb and .be.
2694 I.e in the following case :
2695 [20] .bb endndx = 22
2698 ld will move the symbol 21 to the end of the list but
2699 endndx will still be 22 instead of 21. */
2702 if (SF_GET_LOCAL (symbolP
))
2704 /* remove C_EFCN and LOCAL (L...) symbols */
2705 /* next pointer remains valid */
2706 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2709 else if (!S_IS_DEFINED (symbolP
)
2710 && !S_IS_DEBUG (symbolP
)
2711 && !SF_GET_STATICS (symbolP
) &&
2712 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2713 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2714 /* if external, Remove from the list */
2715 symbolS
*hold
= symbol_previous (symbolP
);
2717 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2718 symbol_clear_list_pointers (symbolP
);
2719 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2724 if (SF_GET_STRING (symbolP
))
2726 symbolP
->sy_name_offset
= string_byte_count
;
2727 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2731 symbolP
->sy_name_offset
= 0;
2732 } /* fix "long" names */
2734 symbolP
->sy_number
= symbol_number
;
2735 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2736 } /* if local symbol */
2737 } /* traverse the symbol list */
2738 return symbol_number
;
2746 unsigned int symbol_number
= 0;
2748 for (symbolP
= symbol_externP
; symbol_externP
;)
2750 symbolS
*tmp
= symbol_externP
;
2753 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2754 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2757 if (SF_GET_STRING (tmp
))
2759 tmp
->sy_name_offset
= string_byte_count
;
2760 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2764 tmp
->sy_name_offset
= 0;
2765 } /* fix "long" names */
2767 tmp
->sy_number
= symbol_number
;
2768 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2769 } /* append the entire extern chain */
2770 return symbol_number
;
2777 unsigned int symbol_number
= 0;
2780 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2781 symbol_next (symbolP
))
2783 symbolP
->sy_number
= symbol_number
;
2787 if (SF_GET_TAGGED (symbolP
))
2791 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2794 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2796 return symbol_number
;
2801 crawl_symbols (h
, abfd
)
2807 /* Initialize the stack used to keep track of the matching .bb .be */
2809 block_stack
= stack_init (512, sizeof (symbolS
*));
2811 /* The symbol list should be ordered according to the following sequence
2814 * . debug entries for functions
2815 * . fake symbols for the sections, including.text .data and .bss
2817 * . undefined symbols
2818 * But this is not mandatory. The only important point is to put the
2819 * undefined symbols at the end of the list.
2822 if (symbol_rootP
== NULL
2823 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2825 c_dot_file_symbol ("fake");
2827 /* Is there a .file symbol ? If not insert one at the beginning. */
2830 * Build up static symbols for the sections, they are filled in later
2834 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2836 if (segment_info
[i
].scnhdr
.s_name
[0])
2840 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2842 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2847 /* Take all the externals out and put them into another chain */
2848 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2849 /* Take the externals and glue them onto the end.*/
2850 H_SET_SYMBOL_TABLE_SIZE (h
, H_GET_SYMBOL_COUNT (h
) + glue_symbols ());
2852 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2853 know (symbol_externP
== NULL
);
2854 know (symbol_extern_lastP
== NULL
);
2858 * Find strings by crawling along symbol table chain.
2867 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2868 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2870 for (symbolP
= symbol_rootP
;
2872 symbolP
= symbol_next (symbolP
))
2876 if (SF_GET_STRING (symbolP
))
2878 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2880 memcpy (where
, S_GET_NAME (symbolP
), size
);
2888 do_linenos_for (abfd
, h
, file_cursor
)
2891 unsigned long *file_cursor
;
2894 unsigned long start
= *file_cursor
;
2896 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2898 segment_info_type
*s
= segment_info
+ idx
;
2901 if (s
->scnhdr
.s_nlnno
!= 0)
2903 struct lineno_list
*line_ptr
;
2905 struct external_lineno
*buffer
=
2906 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2908 struct external_lineno
*dst
= buffer
;
2910 /* Run through the table we've built and turn it into its external
2911 form, take this chance to remove duplicates */
2913 for (line_ptr
= s
->lineno_list_head
;
2914 line_ptr
!= (struct lineno_list
*) NULL
;
2915 line_ptr
= line_ptr
->next
)
2918 if (line_ptr
->line
.l_lnno
== 0)
2920 /* Turn a pointer to a symbol into the symbols' index */
2921 line_ptr
->line
.l_addr
.l_symndx
=
2922 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2926 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2930 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2935 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2937 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2940 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2943 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2947 /* Now we run through the list of frag chains in a segment and
2948 make all the subsegment frags appear at the end of the
2949 list, as if the seg 0 was extra long */
2956 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2958 frchainS
*head
= segment_info
[i
].frchainP
;
2960 fragS
*prev_frag
= &dummy
;
2962 while (head
&& head
->frch_seg
== i
)
2964 prev_frag
->fr_next
= head
->frch_root
;
2965 prev_frag
= head
->frch_last
;
2966 head
= head
->frch_next
;
2968 prev_frag
->fr_next
= 0;
2972 unsigned long machine
;
2975 write_object_file ()
2979 struct frchain
*frchain_ptr
;
2981 object_headers headers
;
2982 unsigned long file_cursor
;
2985 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
2990 as_perror ("FATAL: Can't create %s", out_file_name
);
2993 bfd_set_format (abfd
, bfd_object
);
2994 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
2996 string_byte_count
= 4;
2998 for (frchain_ptr
= frchain_root
;
2999 frchain_ptr
!= (struct frchain
*) NULL
;
3000 frchain_ptr
= frchain_ptr
->frch_next
)
3002 /* Run through all the sub-segments and align them up. Also close any
3003 open frags. We tack a .fill onto the end of the frag chain so
3004 that any .align's size can be worked by looking at the next
3007 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3008 #ifndef SUB_SEGMENT_ALIGN
3009 #define SUB_SEGMENT_ALIGN(SEG) 1
3011 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
3012 frag_wane (frag_now
);
3013 frag_now
->fr_fix
= 0;
3014 know (frag_now
->fr_next
== NULL
);
3021 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3023 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3026 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3028 /* Find out how big the sections are, and set the addresses. */
3030 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3034 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3035 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3037 if (segment_info
[i
].scnhdr
.s_name
[0])
3039 H_SET_NUMBER_OF_SECTIONS (&headers
,
3040 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3043 size
= size_section (abfd
, (unsigned int) i
);
3047 H_SET_TEXT_SIZE (&headers
, size
);
3048 else if (i
== SEG_E1
)
3049 H_SET_DATA_SIZE (&headers
, size
);
3050 else if (i
== SEG_E2
)
3051 H_SET_BSS_SIZE (&headers
, size
);
3054 /* Turn the gas native symbol table shape into a coff symbol table */
3055 crawl_symbols (&headers
, abfd
);
3057 if (string_byte_count
== 4)
3058 string_byte_count
= 0;
3060 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3062 #if !defined(TC_H8300) && !defined(TC_Z8K)
3063 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3065 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3066 fixup_segment (&segment_info
[i
], i
);
3070 /* Look for ".stab" segments and fill in their initial symbols
3072 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3074 name
= segment_info
[i
].scnhdr
.s_name
;
3077 && strncmp (".stab", name
, 5) == 0
3078 && strncmp (".stabstr", name
, 8) != 0)
3079 adjust_stab_section (abfd
, i
);
3082 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3084 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3086 /* Plant the data */
3088 fill_section (abfd
, &headers
, &file_cursor
);
3090 do_relocs_for (abfd
, &headers
, &file_cursor
);
3092 do_linenos_for (abfd
, &headers
, &file_cursor
);
3094 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3095 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3096 H_SET_TIME_STAMP (&headers
, (long)time((long*)0));
3098 H_SET_TIME_STAMP (&headers
, 0);
3101 #ifdef KEEP_RELOC_INFO
3102 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3103 COFF_FLAGS
| coff_flags
));
3105 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3106 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3107 COFF_FLAGS
| coff_flags
));
3111 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3112 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3114 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3115 w_symbols (abfd
, buffer1
, symbol_rootP
);
3116 if (string_byte_count
> 0)
3117 w_strings (buffer1
+ symtable_size
);
3118 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3122 coff_header_append (abfd
, &headers
);
3124 /* Recent changes to write need this, but where it should
3125 go is up to Ken.. */
3126 if (bfd_close_all_done (abfd
) == false)
3127 as_fatal ("Can't close %s: %s", out_file_name
,
3128 bfd_errmsg (bfd_get_error ()));
3131 extern bfd
*stdoutput
;
3138 /* Add a new segment. This is called from subseg_new via the
3139 obj_new_segment macro. */
3142 obj_coff_add_segment (name
)
3148 /* Find out if we've already got a section of this name. */
3149 len
= strlen (name
);
3150 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3153 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3154 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3155 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3156 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3157 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3162 as_bad ("Too many new sections; can't add \"%s\"", name
);
3166 /* Add a new section. */
3167 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3168 sizeof (segment_info
[i
].scnhdr
.s_name
));
3169 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3175 * implement the .section pseudo op:
3176 * .section name {, "flags"}
3178 * | +--- optional flags: 'b' for bss
3180 * +-- section name 'l' for lib
3184 * 'd' (apparently m88k for data)
3186 * But if the argument is not a quoted string, treat it as a
3187 * subsegment number.
3191 obj_coff_section (ignore
)
3194 /* Strip out the section name */
3196 char *section_name_end
;
3203 section_name
= input_line_pointer
;
3204 c
= get_symbol_end ();
3205 section_name_end
= input_line_pointer
;
3207 len
= section_name_end
- section_name
;
3208 input_line_pointer
++;
3214 else if (*input_line_pointer
== ',')
3217 ++input_line_pointer
;
3225 if (*input_line_pointer
!= '"')
3226 exp
= get_absolute_expression ();
3229 ++input_line_pointer
;
3230 while (*input_line_pointer
!= '"'
3231 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3233 switch (*input_line_pointer
)
3235 case 'b': flags
|= STYP_BSS
; break;
3236 case 'i': flags
|= STYP_INFO
; break;
3237 case 'l': flags
|= STYP_LIB
; break;
3238 case 'n': flags
|= STYP_NOLOAD
; break;
3239 case 'o': flags
|= STYP_OVER
; break;
3241 case 'w': flags
|= STYP_DATA
; break;
3242 case 'x': flags
|= STYP_TEXT
; break;
3244 as_warn("unknown section attribute '%c'",
3245 *input_line_pointer
);
3248 ++input_line_pointer
;
3250 if (*input_line_pointer
== '"')
3251 ++input_line_pointer
;
3255 subseg_new (section_name
, (subsegT
) exp
);
3257 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3259 *section_name_end
= c
;
3264 obj_coff_text (ignore
)
3267 subseg_new (".text", get_absolute_expression ());
3272 obj_coff_data (ignore
)
3275 if (flag_readonly_data_in_text
)
3276 subseg_new (".text", get_absolute_expression () + 1000);
3278 subseg_new (".data", get_absolute_expression ());
3282 obj_coff_bss (ignore
)
3285 if (*input_line_pointer
== '\n') /* .bss */
3286 subseg_new(".bss", get_absolute_expression());
3287 else /* .bss id,expr */
3292 obj_coff_ident (ignore
)
3295 segT current_seg
= now_seg
; /* save current seg */
3296 subsegT current_subseg
= now_subseg
;
3297 subseg_new (".comment", 0); /* .comment seg */
3298 stringer (1); /* read string */
3299 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3303 c_symbol_merge (debug
, normal
)
3307 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3308 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3310 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3312 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3313 } /* take the most we have */
3315 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3317 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3318 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3319 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3320 } /* Move all the auxiliary information */
3322 /* Move the debug flags. */
3323 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3324 } /* c_symbol_merge() */
3327 c_line_new (symbol
, paddr
, line_number
, frag
)
3330 unsigned short line_number
;
3333 struct lineno_list
*new_line
=
3334 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3336 segment_info_type
*s
= segment_info
+ now_seg
;
3337 new_line
->line
.l_lnno
= line_number
;
3339 if (line_number
== 0)
3341 last_line_symbol
= symbol
;
3342 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3346 new_line
->line
.l_addr
.l_paddr
= paddr
;
3349 new_line
->frag
= (char *) frag
;
3350 new_line
->next
= (struct lineno_list
*) NULL
;
3353 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3355 s
->lineno_list_head
= new_line
;
3359 s
->lineno_list_tail
->next
= new_line
;
3361 s
->lineno_list_tail
= new_line
;
3362 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3366 c_dot_file_symbol (filename
)
3371 symbolP
= symbol_new (".file",
3374 &zero_address_frag
);
3376 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3377 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3378 SA_SET_FILE_FNAME (symbolP
, filename
);
3384 listing_source_file (filename
);
3390 SF_SET_DEBUG (symbolP
);
3391 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3393 previous_file_symbol
= symbolP
;
3395 /* Make sure that the symbol is first on the symbol chain */
3396 if (symbol_rootP
!= symbolP
)
3398 if (symbolP
== symbol_lastP
)
3400 symbol_lastP
= symbol_lastP
->sy_previous
;
3401 } /* if it was the last thing on the list */
3403 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3404 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3405 symbol_rootP
= symbolP
;
3406 } /* if not first on the list */
3408 } /* c_dot_file_symbol() */
3411 * Build a 'section static' symbol.
3415 c_section_symbol (name
, idx
)
3421 symbolP
= symbol_new (name
, idx
,
3423 &zero_address_frag
);
3425 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3426 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3428 SF_SET_STATICS (symbolP
);
3431 } /* c_section_symbol() */
3434 w_symbols (abfd
, where
, symbol_rootP
)
3437 symbolS
* symbol_rootP
;
3442 /* First fill in those values we have only just worked out */
3443 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3445 symbolP
= segment_info
[i
].dot
;
3449 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3450 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3451 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3457 * Emit all symbols left in the symbol chain.
3459 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3461 /* Used to save the offset of the name. It is used to point
3462 to the string in memory but must be a file offset. */
3463 register char *temp
;
3465 tc_coff_symbol_emit_hook (symbolP
);
3467 temp
= S_GET_NAME (symbolP
);
3468 if (SF_GET_STRING (symbolP
))
3470 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3471 S_SET_ZEROES (symbolP
, 0);
3475 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3476 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3478 where
= symbol_to_chars (abfd
, where
, symbolP
);
3479 S_SET_NAME (symbolP
, temp
);
3485 obj_coff_lcomm (ignore
)
3498 name
= input_line_pointer
;
3500 c
= get_symbol_end ();
3501 p
= input_line_pointer
;
3504 if (*input_line_pointer
!= ',')
3506 as_bad ("Expected comma after name");
3507 ignore_rest_of_line ();
3510 if (*input_line_pointer
== '\n')
3512 as_bad ("Missing size expression");
3515 input_line_pointer
++;
3516 if ((temp
= get_absolute_expression ()) < 0)
3518 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3519 ignore_rest_of_line ();
3524 symbolP
= symbol_find_or_make(name
);
3526 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3527 S_GET_VALUE(symbolP
) == 0)
3532 segT current_seg
= now_seg
; /* save current seg */
3533 subsegT current_subseg
= now_subseg
;
3535 subseg_set (SEG_E2
, 1);
3536 symbolP
->sy_frag
= frag_now
;
3537 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3540 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3541 S_SET_SEGMENT(symbolP
, SEG_E2
);
3542 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3546 as_bad("Symbol %s already defined", name
);
3548 demand_empty_rest_of_line();
3553 fixup_mdeps (frags
, h
, this_segment
)
3558 subseg_change (this_segment
, 0);
3561 switch (frags
->fr_type
)
3565 frags
->fr_type
= rs_fill
;
3567 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3569 case rs_machine_dependent
:
3570 md_convert_frag (h
, frags
);
3576 frags
= frags
->fr_next
;
3582 fixup_segment (segP
, this_segment_type
)
3583 segment_info_type
* segP
;
3584 segT this_segment_type
;
3586 register fixS
* fixP
;
3587 register symbolS
*add_symbolP
;
3588 register symbolS
*sub_symbolP
;
3589 register long add_number
;
3591 register char *place
;
3592 register long where
;
3593 register char pcrel
;
3594 register fragS
*fragP
;
3595 register segT add_symbol_segment
= absolute_section
;
3598 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3600 fragP
= fixP
->fx_frag
;
3602 where
= fixP
->fx_where
;
3603 place
= fragP
->fr_literal
+ where
;
3604 size
= fixP
->fx_size
;
3605 add_symbolP
= fixP
->fx_addsy
;
3607 if (fixP
->fx_tcbit
&& TC_S_IS_CALLNAME (add_symbolP
))
3609 /* Relocation should be done via the associated 'bal' entry
3612 if (!TC_S_IS_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3614 as_bad ("No 'bal' entry point for leafproc %s",
3615 S_GET_NAME (add_symbolP
));
3618 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3621 sub_symbolP
= fixP
->fx_subsy
;
3622 add_number
= fixP
->fx_offset
;
3623 pcrel
= fixP
->fx_pcrel
;
3627 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3628 } /* if there is an addend */
3635 if (S_GET_SEGMENT (sub_symbolP
) != absolute_section
)
3637 as_bad ("Negative of non-absolute symbol %s", S_GET_NAME (sub_symbolP
));
3638 } /* not absolute */
3640 add_number
-= S_GET_VALUE (sub_symbolP
);
3643 /* if sub_symbol is in the same segment that add_symbol
3644 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3646 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
3647 && (SEG_NORMAL (add_symbol_segment
)
3648 || (add_symbol_segment
== absolute_section
)))
3650 /* Difference of 2 symbols from same segment. Can't
3651 make difference of 2 undefineds: 'value' means
3652 something different for N_UNDF. */
3654 /* Makes no sense to use the difference of 2 arbitrary symbols
3655 as the target of a call instruction. */
3658 as_bad ("callj to difference of 2 symbols");
3660 #endif /* TC_I960 */
3661 add_number
+= S_GET_VALUE (add_symbolP
) -
3662 S_GET_VALUE (sub_symbolP
);
3665 fixP
->fx_addsy
= NULL
;
3670 /* Different segments in subtraction. */
3671 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3673 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3675 add_number
-= S_GET_VALUE (sub_symbolP
);
3678 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3679 #if 0 /* Okay for 68k, at least... */
3684 /* Make it pc-relative. */
3685 add_number
+= (md_pcrel_from (fixP
)
3686 - S_GET_VALUE (sub_symbolP
));
3695 as_bad ("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3696 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3697 S_GET_NAME (sub_symbolP
),
3698 (long) (fragP
->fr_address
+ where
));
3701 } /* if sub_symbolP */
3705 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3708 * This fixup was made when the symbol's segment was
3709 * SEG_UNKNOWN, but it is now in the local segment.
3710 * So we know how to do the address without relocation.
3713 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3714 * in which cases it modifies *fixP as appropriate. In the case
3715 * of a 'calls', no further work is required, and *fixP has been
3716 * set up to make the rest of the code below a no-op.
3719 #endif /* TC_I960 */
3721 add_number
+= S_GET_VALUE (add_symbolP
);
3722 add_number
-= md_pcrel_from (fixP
);
3723 #if defined (TC_I386) || defined (TE_LYNX)
3724 /* On the 386 we must adjust by the segment
3725 vaddr as well. Ian Taylor. */
3726 add_number
-= segP
->scnhdr
.s_vaddr
;
3728 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3729 fixP
->fx_addsy
= NULL
;
3734 switch (add_symbol_segment
)
3736 case absolute_section
:
3738 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3739 #endif /* TC_I960 */
3740 add_number
+= S_GET_VALUE (add_symbolP
);
3741 fixP
->fx_addsy
= NULL
;
3748 /* This really should be handled in the linker, but
3749 backward compatibility forbids. */
3750 add_number
+= S_GET_VALUE (add_symbolP
);
3752 add_number
+= S_GET_VALUE (add_symbolP
) +
3753 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3759 if ((int) fixP
->fx_bit_fixP
== 13)
3761 /* This is a COBR instruction. They have only a
3762 * 13-bit displacement and are only to be used
3763 * for local branches: flag as error, don't generate
3766 as_bad ("can't use COBR format with external label");
3767 fixP
->fx_addsy
= NULL
;
3771 #endif /* TC_I960 */
3772 #if defined (TC_I386) || defined (TE_LYNX)
3773 /* 386 COFF uses a peculiar format in
3774 which the value of a common symbol is
3775 stored in the .text segment (I've
3776 checked this on SVR3.2 and SCO 3.2.2)
3777 Ian Taylor <ian@cygnus.com>. */
3778 if (S_IS_COMMON (add_symbolP
))
3779 add_number
+= S_GET_VALUE (add_symbolP
);
3784 } /* switch on symbol seg */
3785 } /* if not in local seg */
3786 } /* if there was a + symbol */
3791 /* This adjustment is not correct on the m88k, for which the
3792 linker does all the computation. */
3793 add_number
-= md_pcrel_from (fixP
);
3795 if (add_symbolP
== 0)
3797 fixP
->fx_addsy
= &abs_symbol
;
3798 } /* if there's an add_symbol */
3799 #if defined (TC_I386) || defined (TE_LYNX)
3800 /* On the 386 we must adjust by the segment vaddr
3801 as well. Ian Taylor. */
3802 add_number
-= segP
->scnhdr
.s_vaddr
;
3806 if (!fixP
->fx_bit_fixP
)
3809 /* The m88k uses the offset field of the reloc to get around
3812 (add_number
& ~0xFF) && ((add_number
& ~0xFF) != (-1 & ~0xFF))) ||
3814 (add_number
& ~0xFFFF) && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3816 as_bad ("Value of %ld too large for field of %d bytes at 0x%lx",
3817 (long) add_number
, size
,
3818 (unsigned long) (fragP
->fr_address
+ where
));
3819 } /* generic error checking */
3821 #ifdef WARN_SIGNED_OVERFLOW_WORD
3822 /* Warn if a .word value is too large when treated as
3823 a signed number. We already know it is not too
3824 negative. This is to catch over-large switches
3825 generated by gcc on the 68k. */
3826 if (!flag_signed_overflow_ok
3828 && add_number
> 0x7fff)
3829 as_bad ("Signed .word overflow; switch may be too large; %ld at 0x%lx",
3831 (unsigned long) (fragP
->fr_address
+ where
));
3833 } /* not a bit fix */
3834 /* once this fix has been applied, we don't have to output anything
3835 nothing more need be done -*/
3836 md_apply_fix (fixP
, add_number
);
3837 } /* For each fixS in this segment. */
3838 } /* fixup_segment() */
3842 /* The first entry in a .stab section is special. */
3845 obj_coff_init_stab_section (seg
)
3851 unsigned int stroff
;
3853 /* Make space for this first symbol. */
3857 as_where (&file
, (unsigned int *) NULL
);
3858 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
3859 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
3860 strcat (stabstr_name
, "str");
3861 stroff
= get_stab_string_offset (file
, stabstr_name
);
3863 md_number_to_chars (p
, stroff
, 4);
3866 /* Fill in the counts in the first entry in a .stab section. */
3869 adjust_stab_section(abfd
, seg
)
3873 segT stabstrseg
= SEG_UNKNOWN
;
3874 char *secname
, *name
, *name2
;
3876 int i
, strsz
= 0, nsyms
;
3877 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
3879 /* Look for the associated string table section. */
3881 secname
= segment_info
[seg
].scnhdr
.s_name
;
3882 name
= (char *) alloca (strlen (secname
) + 4);
3883 strcpy (name
, secname
);
3884 strcat (name
, "str");
3886 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3888 name2
= segment_info
[i
].scnhdr
.s_name
;
3889 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
3896 /* If we found the section, get its size. */
3897 if (stabstrseg
!= SEG_UNKNOWN
)
3898 strsz
= size_section (abfd
, stabstrseg
);
3900 nsyms
= size_section (abfd
, seg
) / 12 - 1;
3902 /* Look for the first frag of sufficient size for the initial stab
3903 symbol, and collect a pointer to it. */
3904 while (frag
&& frag
->fr_fix
< 12)
3905 frag
= frag
->fr_next
;
3907 p
= frag
->fr_literal
;
3910 /* Write in the number of stab symbols and the size of the string
3912 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
3913 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
3917 #endif /* not BFD_ASSEMBLER */