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. */
25 /* I think this is probably always correct. */
26 #ifndef KEEP_RELOC_INFO
27 #define KEEP_RELOC_INFO
30 const char *s_get_name
PARAMS ((symbolS
* s
));
31 static symbolS
*def_symbol_in_progress
;
37 unsigned long chunk_size
;
38 unsigned long element_size
;
41 unsigned long pointer
;
46 stack_init (chunk_size
, element_size
)
47 unsigned long chunk_size
;
48 unsigned long element_size
;
52 st
= (stack
*) malloc (sizeof (stack
));
55 st
->data
= malloc (chunk_size
);
62 st
->size
= chunk_size
;
63 st
->chunk_size
= chunk_size
;
64 st
->element_size
= element_size
;
69 /* Not currently used. */
80 stack_push (st
, element
)
84 if (st
->pointer
+ st
->element_size
>= st
->size
)
86 st
->size
+= st
->chunk_size
;
87 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
90 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
91 st
->pointer
+= st
->element_size
;
92 return st
->data
+ st
->pointer
;
99 if (st
->pointer
< st
->element_size
)
104 st
->pointer
-= st
->element_size
;
105 return st
->data
+ st
->pointer
;
109 * Maintain a list of the tagnames of the structres.
112 static struct hash_control
*tag_hash
;
117 tag_hash
= hash_new ();
121 tag_insert (name
, symbolP
)
125 const char *error_string
;
127 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
129 as_fatal ("Inserting \"%s\" into structure table failed: %s",
138 #ifdef STRIP_UNDERSCORE
141 #endif /* STRIP_UNDERSCORE */
142 return (symbolS
*) hash_find (tag_hash
, name
);
146 tag_find_or_make (name
)
151 if ((symbolP
= tag_find (name
)) == NULL
)
153 symbolP
= symbol_new (name
, undefined_section
,
154 0, &zero_address_frag
);
156 tag_insert (S_GET_NAME (symbolP
), symbolP
);
158 symbol_table_insert (symbolP
);
169 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
171 #define GET_FILENAME_STRING(X) \
172 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
176 fetch_coff_debug_section ()
178 static segT debug_section
;
182 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
184 debug_section
= s
->section
;
186 return debug_section
;
190 SA_SET_SYM_ENDNDX (sym
, val
)
194 combined_entry_type
*entry
, *p
;
196 entry
= &coffsymbol (sym
->bsym
)->native
[1];
197 p
= coffsymbol (val
->bsym
)->native
;
198 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
203 SA_SET_SYM_TAGNDX (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_tagndx
.p
= p
;
216 S_GET_DATA_TYPE (sym
)
219 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
223 S_SET_DATA_TYPE (sym
, val
)
227 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
232 S_GET_STORAGE_CLASS (sym
)
235 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
239 S_SET_STORAGE_CLASS (sym
, val
)
243 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
247 /* Merge a debug symbol containing debug information into a normal symbol. */
250 c_symbol_merge (debug
, normal
)
254 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
255 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
257 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
258 /* take the most we have */
259 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
261 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
263 /* Move all the auxiliary information. */
264 /* @@ How many fields do we want to preserve? Would it make more
265 sense to pick and choose those we want to copy? Should look
266 into this further.... [raeburn:19920512.2209EST] */
268 linenos
= coffsymbol (normal
->bsym
)->lineno
;
269 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
270 (char *) &coffsymbol (debug
->bsym
)->native
,
271 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
272 coffsymbol (normal
->bsym
)->lineno
= linenos
;
275 /* Move the debug flags. */
276 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
279 static symbolS
*previous_file_symbol
;
281 c_dot_file_symbol (filename
)
286 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
288 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
289 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
291 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
298 listing_source_file (filename
);
303 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
305 previous_file_symbol
= symbolP
;
307 /* Make sure that the symbol is first on the symbol chain */
308 if (symbol_rootP
!= symbolP
)
310 if (symbolP
== symbol_lastP
)
312 symbol_lastP
= symbol_lastP
->sy_previous
;
313 } /* if it was the last thing on the list */
315 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
316 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
317 symbol_rootP
= symbolP
;
318 } /* if not first on the list */
322 * Build a 'section static' symbol.
326 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
330 unsigned short nreloc
;
331 unsigned short nlnno
;
335 symbolP
= symbol_new (name
,
344 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
345 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
347 SA_SET_SCN_SCNLEN (symbolP
, length
);
348 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
349 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
351 SF_SET_STATICS (symbolP
);
353 return (char *) symbolP
;
356 /* Line number handling */
359 struct line_no
*next
;
366 /* Symbol of last function, which we should hang line#s off of. */
367 static symbolS
*line_fsym
;
369 #define in_function() (line_fsym != 0)
370 #define clear_function() (line_fsym = 0)
371 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
375 obj_symbol_new_hook (symbolP
)
378 char underscore
= 0; /* Symbol has leading _ */
381 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
382 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
384 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
386 S_SET_DATA_TYPE (symbolP
, T_NULL
);
387 S_SET_STORAGE_CLASS (symbolP
, 0);
388 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
390 if (S_IS_STRING (symbolP
))
391 SF_SET_STRING (symbolP
);
392 if (!underscore
&& S_IS_LOCAL (symbolP
))
393 SF_SET_LOCAL (symbolP
);
398 * Handle .ln directives.
401 static symbolS
*current_lineno_sym
;
402 static struct line_no
*line_nos
;
403 /* @@ Blindly assume all .ln directives will be in the .text section... */
404 static int n_line_nos
;
407 add_lineno (frag
, offset
, num
)
412 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
413 sizeof (struct line_no
));
414 if (!current_lineno_sym
)
418 new_line
->next
= line_nos
;
419 new_line
->frag
= frag
;
420 new_line
->l
.line_number
= num
;
421 new_line
->l
.u
.offset
= offset
;
427 coff_add_linesym (sym
)
432 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
436 current_lineno_sym
= sym
;
440 obj_coff_ln (appline
)
445 if (! appline
&& def_symbol_in_progress
!= NULL
)
447 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
448 demand_empty_rest_of_line ();
452 l
= get_absolute_expression ();
455 add_lineno (frag_now
, frag_now_fix (), l
);
465 l
+= coff_line_base
- 1;
466 listing_source_line (l
);
471 demand_empty_rest_of_line ();
477 * Handle .def directives.
479 * One might ask : why can't we symbol_new if the symbol does not
480 * already exist and fill it with debug information. Because of
481 * the C_EFCN special symbol. It would clobber the value of the
482 * function symbol before we have a chance to notice that it is
483 * a C_EFCN. And a second reason is that the code is more clear this
484 * way. (at least I think it is :-).
488 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
489 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
490 *input_line_pointer == '\t') \
491 input_line_pointer++;
497 char name_end
; /* Char after the end of name */
498 char *symbol_name
; /* Name of the debug symbol */
499 char *symbol_name_copy
; /* Temporary copy of the name */
500 unsigned int symbol_name_length
;
502 if (def_symbol_in_progress
!= NULL
)
504 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
505 demand_empty_rest_of_line ();
507 } /* if not inside .def/.endef */
511 symbol_name
= input_line_pointer
;
512 #ifdef STRIP_UNDERSCORE
513 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
515 #endif /* STRIP_UNDERSCORE */
517 name_end
= get_symbol_end ();
518 symbol_name_length
= strlen (symbol_name
);
519 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
520 strcpy (symbol_name_copy
, symbol_name
);
522 /* Initialize the new symbol */
523 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
524 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
525 S_SET_VALUE (def_symbol_in_progress
, 0);
527 if (S_IS_STRING (def_symbol_in_progress
))
528 SF_SET_STRING (def_symbol_in_progress
);
530 *input_line_pointer
= name_end
;
532 demand_empty_rest_of_line ();
535 unsigned int dim_index
;
538 obj_coff_endef (ignore
)
542 /* DIM BUG FIX sac@cygnus.com */
544 if (def_symbol_in_progress
== NULL
)
546 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
547 demand_empty_rest_of_line ();
549 } /* if not inside .def/.endef */
551 /* Set the section number according to storage class. */
552 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
557 SF_SET_TAG (def_symbol_in_progress
);
558 /* intentional fallthrough */
561 SF_SET_DEBUG (def_symbol_in_progress
);
562 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
566 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
567 /* intentional fallthrough */
569 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
570 /* intentional fallthrough */
574 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
576 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
577 if (name
[1] == 'b' && name
[2] == 'f')
579 if (! in_function ())
580 as_warn ("`%s' symbol without preceding function", name
);
581 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
582 /* Will need relocating */
583 SF_SET_PROCESS (def_symbol_in_progress
);
591 #endif /* C_AUTOARG */
601 SF_SET_DEBUG (def_symbol_in_progress
);
602 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
608 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
614 as_warn ("unexpected storage class %d",
615 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
617 } /* switch on storage class */
619 /* Now that we have built a debug symbol, try to find if we should
620 merge with an existing symbol or not. If a symbol is C_EFCN or
621 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
623 /* Two cases for functions. Either debug followed by definition or
624 definition followed by debug. For definition first, we will
625 merge the debug symbol into the definition. For debug first, the
626 lineno entry MUST point to the definition function or else it
627 will point off into space when obj_crawl_symbol_chain() merges
628 the debug symbol into the real symbol. Therefor, let's presume
629 the debug symbol is a real function reference. */
631 /* FIXME-SOON If for some reason the definition label/symbol is
632 never seen, this will probably leave an undefined symbol at link
635 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
636 || (!strcmp (bfd_get_section_name (stdoutput
,
637 S_GET_SEGMENT (def_symbol_in_progress
)),
639 && !SF_GET_TAG (def_symbol_in_progress
))
640 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
641 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
643 if (def_symbol_in_progress
!= symbol_lastP
)
644 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
649 /* This symbol already exists, merge the newly created symbol
650 into the old one. This is not mandatory. The linker can
651 handle duplicate symbols correctly. But I guess that it save
652 a *lot* of space if the assembly file defines a lot of
655 /* The debug entry (def_symbol_in_progress) is merged into the
656 previous definition. */
658 c_symbol_merge (def_symbol_in_progress
, symbolP
);
659 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
660 def_symbol_in_progress
= symbolP
;
662 if (SF_GET_FUNCTION (def_symbol_in_progress
)
663 || SF_GET_TAG (def_symbol_in_progress
))
665 /* For functions, and tags, the symbol *must* be where the
666 debug symbol appears. Move the existing symbol to the
668 /* If it already is at the end of the symbol list, do nothing */
669 if (def_symbol_in_progress
!= symbol_lastP
)
671 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
672 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
677 if (SF_GET_TAG (def_symbol_in_progress
)
678 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
680 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
683 if (SF_GET_FUNCTION (def_symbol_in_progress
))
685 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
686 set_function (def_symbol_in_progress
);
687 SF_SET_PROCESS (def_symbol_in_progress
);
691 /* That is, if this is the first time we've seen the
693 symbol_table_insert (def_symbol_in_progress
);
694 } /* definition follows debug */
695 } /* Create the line number entry pointing to the function being defined */
697 def_symbol_in_progress
= NULL
;
698 demand_empty_rest_of_line ();
702 obj_coff_dim (ignore
)
707 if (def_symbol_in_progress
== NULL
)
709 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
710 demand_empty_rest_of_line ();
712 } /* if not inside .def/.endef */
714 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
716 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
719 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
720 get_absolute_expression ());
722 switch (*input_line_pointer
)
725 input_line_pointer
++;
729 as_warn ("badly formed .dim directive ignored");
730 /* intentional fallthrough */
738 demand_empty_rest_of_line ();
742 obj_coff_line (ignore
)
747 if (def_symbol_in_progress
== NULL
)
749 /* Probably stabs-style line? */
754 this_base
= get_absolute_expression ();
755 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
756 coff_line_base
= this_base
;
758 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
759 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
761 demand_empty_rest_of_line ();
765 obj_coff_size (ignore
)
768 if (def_symbol_in_progress
== NULL
)
770 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
771 demand_empty_rest_of_line ();
773 } /* if not inside .def/.endef */
775 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
776 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
777 demand_empty_rest_of_line ();
781 obj_coff_scl (ignore
)
784 if (def_symbol_in_progress
== NULL
)
786 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
787 demand_empty_rest_of_line ();
789 } /* if not inside .def/.endef */
791 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
792 demand_empty_rest_of_line ();
796 obj_coff_tag (ignore
)
802 if (def_symbol_in_progress
== NULL
)
804 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
805 demand_empty_rest_of_line ();
809 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
810 symbol_name
= input_line_pointer
;
811 name_end
= get_symbol_end ();
813 /* Assume that the symbol referred to by .tag is always defined.
814 This was a bad assumption. I've added find_or_make. xoxorich. */
815 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
816 tag_find_or_make (symbol_name
));
817 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
819 as_warn ("tag not found for .tag %s", symbol_name
);
822 SF_SET_TAGGED (def_symbol_in_progress
);
823 *input_line_pointer
= name_end
;
825 demand_empty_rest_of_line ();
829 obj_coff_type (ignore
)
832 if (def_symbol_in_progress
== NULL
)
834 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
835 demand_empty_rest_of_line ();
837 } /* if not inside .def/.endef */
839 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
841 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
842 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
844 SF_SET_FUNCTION (def_symbol_in_progress
);
845 } /* is a function */
847 demand_empty_rest_of_line ();
851 obj_coff_val (ignore
)
854 if (def_symbol_in_progress
== NULL
)
856 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
857 demand_empty_rest_of_line ();
859 } /* if not inside .def/.endef */
861 if (is_name_beginner (*input_line_pointer
))
863 char *symbol_name
= input_line_pointer
;
864 char name_end
= get_symbol_end ();
866 if (!strcmp (symbol_name
, "."))
868 def_symbol_in_progress
->sy_frag
= frag_now
;
869 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
870 /* If the .val is != from the .def (e.g. statics) */
872 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
874 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
875 def_symbol_in_progress
->sy_value
.X_add_symbol
=
876 symbol_find_or_make (symbol_name
);
877 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
878 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
880 /* If the segment is undefined when the forward reference is
881 resolved, then copy the segment id from the forward
883 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
885 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
886 *input_line_pointer
= name_end
;
890 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
891 } /* if symbol based */
893 demand_empty_rest_of_line ();
897 obj_read_begin_hook ()
899 /* These had better be the same. Usually 18 bytes. */
901 know (sizeof (SYMENT
) == sizeof (AUXENT
));
902 know (SYMESZ
== AUXESZ
);
908 symbolS
*coff_last_function
;
911 coff_frob_symbol (symp
, punt
)
915 static symbolS
*last_tagP
;
916 static stack
*block_stack
;
917 static symbolS
*set_end
;
919 if (symp
== &abs_symbol
)
925 if (current_lineno_sym
)
926 coff_add_linesym ((symbolS
*) 0);
929 block_stack
= stack_init (512, sizeof (symbolS
*));
931 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
932 S_SET_STORAGE_CLASS (symp
, C_EXT
);
934 if (!SF_GET_DEBUG (symp
))
937 if (!SF_GET_LOCAL (symp
)
938 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
941 c_symbol_merge (symp
, real
);
944 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
946 assert (S_GET_VALUE (symp
) == 0);
947 S_SET_EXTERNAL (symp
);
949 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
951 if (S_GET_SEGMENT (symp
) == text_section
952 && symp
!= seg_info (text_section
)->sym
)
953 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
955 S_SET_STORAGE_CLASS (symp
, C_STAT
);
957 if (SF_GET_PROCESS (symp
))
959 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
961 if (!strcmp (S_GET_NAME (symp
), ".bb"))
962 stack_push (block_stack
, (char *) &symp
);
966 begin
= *(symbolS
**) stack_pop (block_stack
);
968 as_warn ("mismatched .eb");
973 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
975 union internal_auxent
*auxp
;
976 coff_last_function
= symp
;
977 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
978 S_SET_NUMBER_AUXILIARY (symp
, 1);
979 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
980 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
981 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
983 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
985 if (coff_last_function
== 0)
986 as_fatal ("C_EFCN symbol out of scope");
987 SA_SET_SYM_FSIZE (coff_last_function
,
988 (long) (S_GET_VALUE (symp
)
989 - S_GET_VALUE (coff_last_function
)));
990 set_end
= coff_last_function
;
991 coff_last_function
= 0;
994 else if (SF_GET_TAG (symp
))
996 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
998 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1000 if (S_GET_VALUE (symp
))
1002 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1003 S_SET_VALUE (symp
, 0);
1006 if (S_IS_EXTERNAL (symp
))
1007 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1008 else if (SF_GET_LOCAL (symp
))
1013 if (set_end
!= (symbolS
*) NULL
1016 SA_SET_SYM_ENDNDX (set_end
, symp
);
1020 if (coffsymbol (symp
->bsym
)->lineno
)
1023 struct line_no
*lptr
;
1026 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1027 for (i
= 0; lptr
; lptr
= lptr
->next
)
1029 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1031 /* We need i entries for line numbers, plus 1 for the first
1032 entry which BFD will override, plus 1 for the last zero
1033 entry (a marker for BFD). */
1034 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1035 coffsymbol (symp
->bsym
)->lineno
= l
;
1036 l
[i
+ 1].line_number
= 0;
1037 l
[i
+ 1].u
.sym
= NULL
;
1041 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1049 coff_adjust_section_syms (abfd
, sec
, x
)
1055 segment_info_type
*seginfo
= seg_info (sec
);
1056 int nlnno
, nrelocs
= 0;
1058 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1059 tc-ppc.c. Do not get confused by it. */
1060 if (seginfo
== NULL
)
1063 if (!strcmp (sec
->name
, ".text"))
1068 /* @@ Hope that none of the fixups expand to more than one reloc
1070 fixS
*fixp
= seginfo
->fix_root
;
1073 fixp
= fixp
->fx_next
;
1077 if (bfd_get_section_size_before_reloc (sec
) == 0
1078 && nrelocs
== 0 && nlnno
== 0)
1080 secsym
= section_symbol (sec
);
1081 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1082 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1088 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1092 * implement the .section pseudo op:
1093 * .section name {, "flags"}
1095 * | +--- optional flags: 'b' for bss
1097 * +-- section name 'l' for lib
1101 * 'd' (apparently m88k for data)
1103 * But if the argument is not a quoted string, treat it as a
1104 * subsegment number.
1108 obj_coff_section (ignore
)
1111 /* Strip out the section name */
1119 section_name
= input_line_pointer
;
1120 c
= get_symbol_end ();
1122 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1123 strcpy (name
, section_name
);
1125 *input_line_pointer
= c
;
1130 flags
= SEC_NO_FLAGS
;
1132 if (*input_line_pointer
== ',')
1134 ++input_line_pointer
;
1136 if (*input_line_pointer
!= '"')
1137 exp
= get_absolute_expression ();
1140 ++input_line_pointer
;
1141 while (*input_line_pointer
!= '"'
1142 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1144 switch (*input_line_pointer
)
1146 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1147 case 'n': flags
&=~ SEC_LOAD
; break;
1149 case 'w': flags
&=~ SEC_READONLY
; break;
1150 case 'x': flags
|= SEC_CODE
; break;
1152 case 'i': /* STYP_INFO */
1153 case 'l': /* STYP_LIB */
1154 case 'o': /* STYP_OVER */
1155 as_warn ("unsupported section attribute '%c'",
1156 *input_line_pointer
);
1160 as_warn("unknown section attribute '%c'",
1161 *input_line_pointer
);
1164 ++input_line_pointer
;
1166 if (*input_line_pointer
== '"')
1167 ++input_line_pointer
;
1171 sec
= subseg_new (name
, (subsegT
) exp
);
1173 if (flags
!= SEC_NO_FLAGS
)
1175 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1176 as_warn ("error setting flags for \"%s\": %s",
1177 bfd_section_name (stdoutput
, sec
),
1178 bfd_errmsg (bfd_get_error ()));
1183 coff_adjust_symtab ()
1185 if (symbol_rootP
== NULL
1186 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1188 assert (previous_file_symbol
== 0);
1189 c_dot_file_symbol ("fake");
1194 coff_frob_section (sec
)
1200 bfd_vma size
, n_entries
, mask
;
1202 /* The COFF back end in BFD requires that all section sizes be
1203 rounded up to multiples of the corresponding section alignments.
1204 Seems kinda silly to me, but that's the way it is. */
1205 size
= bfd_get_section_size_before_reloc (sec
);
1206 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1209 size
= (size
+ mask
) & ~mask
;
1210 bfd_set_section_size (stdoutput
, sec
, size
);
1213 /* If the section size is non-zero, the section symbol needs an aux
1214 entry associated with it, indicating the size. We don't know
1215 all the values yet; coff_frob_symbol will fill them in later. */
1218 symbolS
*secsym
= section_symbol (sec
);
1220 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1221 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1222 SF_SET_STATICS (secsym
);
1223 SA_SET_SCN_SCNLEN (secsym
, size
);
1226 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1227 #ifndef STAB_SECTION_NAME
1228 #define STAB_SECTION_NAME ".stab"
1230 #ifndef STAB_STRING_SECTION_NAME
1231 #define STAB_STRING_SECTION_NAME ".stabstr"
1233 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1237 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1238 /* size is already rounded up, since other section will be listed first */
1239 size
= bfd_get_section_size_before_reloc (strsec
);
1241 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1243 /* Find first non-empty frag. It should be large enough. */
1244 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1245 while (fragp
&& fragp
->fr_fix
== 0)
1246 fragp
= fragp
->fr_next
;
1247 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1249 /* Store the values. */
1250 p
= fragp
->fr_literal
;
1251 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1252 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1256 obj_coff_init_stab_section (seg
)
1262 unsigned int stroff
;
1264 /* Make space for this first symbol. */
1268 as_where (&file
, (unsigned int *) NULL
);
1269 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1270 strcpy (stabstr_name
, seg
->name
);
1271 strcat (stabstr_name
, "str");
1272 stroff
= get_stab_string_offset (file
, stabstr_name
);
1274 md_number_to_chars (p
, stroff
, 4);
1283 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1291 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1293 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1294 (unsigned long) symbolP
,
1295 S_GET_NAME(symbolP
),
1296 (long) S_GET_DATA_TYPE(symbolP
),
1297 S_GET_STORAGE_CLASS(symbolP
),
1298 (int) S_GET_SEGMENT(symbolP
));
1304 #else /* not BFD_ASSEMBLER */
1307 /* This is needed because we include internal bfd things. */
1309 #include "bfd/libbfd.h"
1310 #include "bfd/libcoff.h"
1312 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1313 that we can stick sections together without causing trouble. */
1315 #define NOP_OPCODE 0x00
1318 /* The zeroes if symbol name is longer than 8 chars */
1319 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1321 #define MIN(a,b) ((a) < (b)? (a) : (b))
1322 /* This vector is used to turn an internal segment into a section #
1323 suitable for insertion into a coff symbol table
1326 const short seg_N_TYPE
[] =
1327 { /* in: segT out: N_TYPE bits */
1339 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1340 C_UNDEF_SECTION
, /* SEG_GOOF */
1341 C_UNDEF_SECTION
, /* SEG_EXPR */
1342 C_DEBUG_SECTION
, /* SEG_DEBUG */
1343 C_NTV_SECTION
, /* SEG_NTV */
1344 C_PTV_SECTION
, /* SEG_PTV */
1345 C_REGISTER_SECTION
, /* SEG_REGISTER */
1348 int function_lineoff
= -1; /* Offset in line#s where the last function
1349 started (the odd entry for line #0) */
1351 static symbolS
*last_line_symbol
;
1353 /* Add 4 to the real value to get the index and compensate the
1354 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1355 section number into a segment number
1357 static symbolS
*previous_file_symbol
;
1358 void c_symbol_merge ();
1359 static int line_base
;
1361 symbolS
*c_section_symbol ();
1364 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1365 segT this_segment_type
));
1368 static void fixup_mdeps
PARAMS ((fragS
*,
1373 static void fill_section
PARAMS ((bfd
* abfd
,
1378 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1383 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1384 symbolS
* symbol_rootP
));
1386 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1388 static void obj_coff_lcomm
PARAMS ((int));
1389 static void obj_coff_text
PARAMS ((int));
1390 static void obj_coff_data
PARAMS ((int));
1391 static void obj_coff_bss
PARAMS ((int));
1392 static void obj_coff_ident
PARAMS ((int));
1393 void obj_coff_section
PARAMS ((int));
1397 We allow more than just the standard 3 sections, infact, we allow
1398 10 sections, (though the usual three have to be there).
1400 This structure performs the mappings for us:
1411 static const seg_info_type seg_info_off_by_4
[N_SEG
] =
1442 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1444 static relax_addressT
1445 relax_align (address
, alignment
)
1446 relax_addressT address
;
1449 relax_addressT mask
;
1450 relax_addressT new_address
;
1452 mask
= ~((~0) << alignment
);
1453 new_address
= (address
+ mask
) & (~mask
);
1454 return (new_address
- address
);
1462 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1467 /* calculate the size of the frag chain and fill in the section header
1468 to contain all of it, also fill in the addr of the sections */
1470 size_section (abfd
, idx
)
1475 unsigned int size
= 0;
1476 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1479 size
= frag
->fr_address
;
1480 if (frag
->fr_address
!= size
)
1482 fprintf (stderr
, "Out of step\n");
1483 size
= frag
->fr_address
;
1486 switch (frag
->fr_type
)
1488 #ifdef TC_COFF_SIZEMACHDEP
1489 case rs_machine_dependent
:
1490 size
+= TC_COFF_SIZEMACHDEP (frag
);
1494 assert (frag
->fr_symbol
== 0);
1497 size
+= frag
->fr_fix
;
1498 size
+= frag
->fr_offset
* frag
->fr_var
;
1501 size
+= frag
->fr_fix
;
1502 size
+= relax_align (size
, frag
->fr_offset
);
1505 BAD_CASE (frag
->fr_type
);
1508 frag
= frag
->fr_next
;
1510 segment_info
[idx
].scnhdr
.s_size
= size
;
1516 count_entries_in_chain (idx
)
1519 unsigned int nrelocs
;
1522 /* Count the relocations */
1523 fixup_ptr
= segment_info
[idx
].fix_root
;
1525 while (fixup_ptr
!= (fixS
*) NULL
)
1527 if (TC_COUNT_RELOC (fixup_ptr
))
1530 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1539 fixup_ptr
= fixup_ptr
->fx_next
;
1544 /* output all the relocations for a section */
1546 do_relocs_for (abfd
, h
, file_cursor
)
1549 unsigned long *file_cursor
;
1551 unsigned int nrelocs
;
1553 unsigned long reloc_start
= *file_cursor
;
1555 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1557 if (segment_info
[idx
].scnhdr
.s_name
[0])
1559 struct external_reloc
*ext_ptr
;
1560 struct external_reloc
*external_reloc_vec
;
1561 unsigned int external_reloc_size
;
1562 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1563 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1564 nrelocs
= count_entries_in_chain (idx
);
1567 /* Bypass this stuff if no relocs. This also incidentally
1568 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1570 external_reloc_size
= nrelocs
* RELSZ
;
1571 external_reloc_vec
=
1572 (struct external_reloc
*) malloc (external_reloc_size
);
1574 ext_ptr
= external_reloc_vec
;
1576 /* Fill in the internal coff style reloc struct from the
1577 internal fix list. */
1580 struct internal_reloc intr
;
1582 /* Only output some of the relocations */
1583 if (TC_COUNT_RELOC (fix_ptr
))
1585 #ifdef TC_RELOC_MANGLE
1586 TC_RELOC_MANGLE (fix_ptr
, &intr
, base
);
1590 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1592 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1594 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1596 #ifdef TC_KEEP_FX_OFFSET
1597 intr
.r_offset
= fix_ptr
->fx_offset
;
1602 /* Turn the segment of the symbol into an offset. */
1605 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1608 intr
.r_symndx
= dot
->sy_number
;
1612 intr
.r_symndx
= symbol_ptr
->sy_number
;
1622 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1625 #if defined(TC_A29K)
1627 /* The 29k has a special kludge for the high 16 bit
1628 reloc. Two relocations are emited, R_IHIHALF,
1629 and R_IHCONST. The second one doesn't contain a
1630 symbol, but uses the value for offset. */
1632 if (intr
.r_type
== R_IHIHALF
)
1634 /* now emit the second bit */
1635 intr
.r_type
= R_IHCONST
;
1636 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1637 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1643 fix_ptr
= fix_ptr
->fx_next
;
1646 /* Write out the reloc table */
1647 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1649 free (external_reloc_vec
);
1651 /* Fill in section header info. */
1652 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1653 *file_cursor
+= external_reloc_size
;
1654 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1659 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1663 /* Set relocation_size field in file headers */
1664 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1668 /* run through a frag chain and write out the data to go with it, fill
1669 in the scnhdrs with the info on the file postions
1672 fill_section (abfd
, h
, file_cursor
)
1675 unsigned long *file_cursor
;
1679 unsigned int paddr
= 0;
1681 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1683 unsigned int offset
= 0;
1685 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1689 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1696 buffer
= xmalloc (s
->s_size
);
1697 s
->s_scnptr
= *file_cursor
;
1699 know (s
->s_paddr
== paddr
);
1701 if (strcmp (s
->s_name
, ".text") == 0)
1702 s
->s_flags
|= STYP_TEXT
;
1703 else if (strcmp (s
->s_name
, ".data") == 0)
1704 s
->s_flags
|= STYP_DATA
;
1705 else if (strcmp (s
->s_name
, ".bss") == 0)
1708 s
->s_flags
|= STYP_BSS
;
1710 /* @@ Should make the i386 and a29k coff targets define
1711 COFF_NOLOAD_PROBLEM, and have only one test here. */
1714 #ifndef COFF_NOLOAD_PROBLEM
1715 /* Apparently the SVR3 linker (and exec syscall) and UDI
1716 mondfe progrem are confused by noload sections. */
1717 s
->s_flags
|= STYP_NOLOAD
;
1722 else if (strcmp (s
->s_name
, ".lit") == 0)
1723 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1724 else if (strcmp (s
->s_name
, ".init") == 0)
1725 s
->s_flags
|= STYP_TEXT
;
1726 else if (strcmp (s
->s_name
, ".fini") == 0)
1727 s
->s_flags
|= STYP_TEXT
;
1728 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1729 s
->s_flags
|= STYP_INFO
;
1733 unsigned int fill_size
;
1734 switch (frag
->fr_type
)
1736 case rs_machine_dependent
:
1739 memcpy (buffer
+ frag
->fr_address
,
1741 (unsigned int) frag
->fr_fix
);
1742 offset
+= frag
->fr_fix
;
1747 assert (frag
->fr_symbol
== 0);
1753 memcpy (buffer
+ frag
->fr_address
,
1755 (unsigned int) frag
->fr_fix
);
1756 offset
+= frag
->fr_fix
;
1759 fill_size
= frag
->fr_var
;
1760 if (fill_size
&& frag
->fr_offset
> 0)
1763 unsigned int off
= frag
->fr_fix
;
1764 for (count
= frag
->fr_offset
; count
; count
--)
1766 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1768 memcpy (buffer
+ frag
->fr_address
+ off
,
1769 frag
->fr_literal
+ frag
->fr_fix
,
1772 offset
+= fill_size
;
1777 case rs_broken_word
:
1782 frag
= frag
->fr_next
;
1787 if (s
->s_scnptr
!= 0)
1789 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1790 *file_cursor
+= s
->s_size
;
1799 /* Coff file generation & utilities */
1802 coff_header_append (abfd
, h
)
1810 bfd_seek (abfd
, 0, 0);
1812 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1813 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1814 H_SET_VERSION_STAMP (h
, 0);
1815 H_SET_ENTRY_POINT (h
, 0);
1816 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1817 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1818 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1820 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1821 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1822 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1824 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1826 bfd_write (buffer
, i
, 1, abfd
);
1827 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1829 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1831 if (segment_info
[i
].scnhdr
.s_name
[0])
1834 bfd_coff_swap_scnhdr_out (abfd
,
1835 &(segment_info
[i
].scnhdr
),
1838 as_bad ("bfd_coff_swap_scnhdr_out failed");
1839 bfd_write (buffer
, size
, 1, abfd
);
1846 symbol_to_chars (abfd
, where
, symbolP
)
1851 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1855 /* Turn any symbols with register attributes into abs symbols */
1856 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1858 S_SET_SEGMENT (symbolP
, absolute_section
);
1860 /* At the same time, relocate all symbols to their output value */
1862 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1863 + S_GET_VALUE (symbolP
));
1865 S_SET_VALUE (symbolP
, val
);
1867 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1869 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1872 for (i
= 0; i
< numaux
; i
++)
1874 where
+= bfd_coff_swap_aux_out (abfd
,
1875 &symbolP
->sy_symbol
.ost_auxent
[i
],
1876 S_GET_DATA_TYPE (symbolP
),
1877 S_GET_STORAGE_CLASS (symbolP
),
1885 obj_symbol_new_hook (symbolP
)
1888 char underscore
= 0; /* Symbol has leading _ */
1890 /* Effective symbol */
1891 /* Store the pointer in the offset. */
1892 S_SET_ZEROES (symbolP
, 0L);
1893 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1894 S_SET_STORAGE_CLASS (symbolP
, 0);
1895 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1896 /* Additional information */
1897 symbolP
->sy_symbol
.ost_flags
= 0;
1898 /* Auxiliary entries */
1899 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1901 if (S_IS_STRING (symbolP
))
1902 SF_SET_STRING (symbolP
);
1903 if (!underscore
&& S_IS_LOCAL (symbolP
))
1904 SF_SET_LOCAL (symbolP
);
1908 * Handle .ln directives.
1912 obj_coff_ln (appline
)
1917 if (! appline
&& def_symbol_in_progress
!= NULL
)
1919 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1920 demand_empty_rest_of_line ();
1922 } /* wrong context */
1924 l
= get_absolute_expression ();
1925 c_line_new (0, frag_now_fix (), l
, frag_now
);
1934 listing_source_line ((unsigned int) l
);
1939 demand_empty_rest_of_line ();
1945 * Handle .def directives.
1947 * One might ask : why can't we symbol_new if the symbol does not
1948 * already exist and fill it with debug information. Because of
1949 * the C_EFCN special symbol. It would clobber the value of the
1950 * function symbol before we have a chance to notice that it is
1951 * a C_EFCN. And a second reason is that the code is more clear this
1952 * way. (at least I think it is :-).
1956 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1957 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1958 *input_line_pointer == '\t') \
1959 input_line_pointer++;
1965 char name_end
; /* Char after the end of name */
1966 char *symbol_name
; /* Name of the debug symbol */
1967 char *symbol_name_copy
; /* Temporary copy of the name */
1968 unsigned int symbol_name_length
;
1970 if (def_symbol_in_progress
!= NULL
)
1972 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1973 demand_empty_rest_of_line ();
1975 } /* if not inside .def/.endef */
1977 SKIP_WHITESPACES ();
1979 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1980 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
1982 symbol_name
= input_line_pointer
;
1983 name_end
= get_symbol_end ();
1984 symbol_name_length
= strlen (symbol_name
);
1985 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
1986 strcpy (symbol_name_copy
, symbol_name
);
1988 /* Initialize the new symbol */
1989 #ifdef STRIP_UNDERSCORE
1990 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
1991 ? symbol_name_copy
+ 1
1992 : symbol_name_copy
));
1993 #else /* STRIP_UNDERSCORE */
1994 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
1995 #endif /* STRIP_UNDERSCORE */
1996 /* free(symbol_name_copy); */
1997 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
1998 def_symbol_in_progress
->sy_number
= ~0;
1999 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2000 S_SET_VALUE (def_symbol_in_progress
, 0);
2002 if (S_IS_STRING (def_symbol_in_progress
))
2003 SF_SET_STRING (def_symbol_in_progress
);
2005 *input_line_pointer
= name_end
;
2007 demand_empty_rest_of_line ();
2010 unsigned int dim_index
;
2014 obj_coff_endef (ignore
)
2017 symbolS
*symbolP
= 0;
2018 /* DIM BUG FIX sac@cygnus.com */
2020 if (def_symbol_in_progress
== NULL
)
2022 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2023 demand_empty_rest_of_line ();
2025 } /* if not inside .def/.endef */
2027 /* Set the section number according to storage class. */
2028 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2033 SF_SET_TAG (def_symbol_in_progress
);
2034 /* intentional fallthrough */
2037 SF_SET_DEBUG (def_symbol_in_progress
);
2038 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2042 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2043 /* intentional fallthrough */
2045 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2046 /* intentional fallthrough */
2048 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2050 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2052 if (function_lineoff
< 0)
2054 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2055 } /* missing function symbol */
2056 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2058 SF_SET_PROCESS (last_line_symbol
);
2059 function_lineoff
= -1;
2061 /* Value is always set to . */
2062 def_symbol_in_progress
->sy_frag
= frag_now
;
2063 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2068 #endif /* C_AUTOARG */
2078 SF_SET_DEBUG (def_symbol_in_progress
);
2079 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2085 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2091 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2093 } /* switch on storage class */
2095 /* Now that we have built a debug symbol, try to find if we should
2096 merge with an existing symbol or not. If a symbol is C_EFCN or
2097 absolute_section or untagged SEG_DEBUG it never merges. We also
2098 don't merge labels, which are in a different namespace, nor
2099 symbols which have not yet been defined since they are typically
2100 unique, nor do we merge tags with non-tags. */
2102 /* Two cases for functions. Either debug followed by definition or
2103 definition followed by debug. For definition first, we will
2104 merge the debug symbol into the definition. For debug first, the
2105 lineno entry MUST point to the definition function or else it
2106 will point off into space when crawl_symbols() merges the debug
2107 symbol into the real symbol. Therefor, let's presume the debug
2108 symbol is a real function reference. */
2110 /* FIXME-SOON If for some reason the definition label/symbol is
2111 never seen, this will probably leave an undefined symbol at link
2114 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2115 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2116 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2117 && !SF_GET_TAG (def_symbol_in_progress
))
2118 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2119 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2120 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2121 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2123 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2128 /* This symbol already exists, merge the newly created symbol
2129 into the old one. This is not mandatory. The linker can
2130 handle duplicate symbols correctly. But I guess that it save
2131 a *lot* of space if the assembly file defines a lot of
2134 /* The debug entry (def_symbol_in_progress) is merged into the
2135 previous definition. */
2137 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2138 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2139 def_symbol_in_progress
= symbolP
;
2141 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2142 || SF_GET_TAG (def_symbol_in_progress
))
2144 /* For functions, and tags, the symbol *must* be where the
2145 debug symbol appears. Move the existing symbol to the
2147 /* If it already is at the end of the symbol list, do nothing */
2148 if (def_symbol_in_progress
!= symbol_lastP
)
2150 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2152 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2153 &symbol_rootP
, &symbol_lastP
);
2154 } /* if not already in place */
2156 } /* normal or mergable */
2158 if (SF_GET_TAG (def_symbol_in_progress
)
2159 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2161 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2164 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2166 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2168 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2170 SF_SET_PROCESS (def_symbol_in_progress
);
2172 if (symbolP
== NULL
)
2174 /* That is, if this is the first time we've seen the
2176 symbol_table_insert (def_symbol_in_progress
);
2177 } /* definition follows debug */
2178 } /* Create the line number entry pointing to the function being defined */
2180 def_symbol_in_progress
= NULL
;
2181 demand_empty_rest_of_line ();
2185 obj_coff_dim (ignore
)
2190 if (def_symbol_in_progress
== NULL
)
2192 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2193 demand_empty_rest_of_line ();
2195 } /* if not inside .def/.endef */
2197 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2199 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2201 SKIP_WHITESPACES ();
2202 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2203 get_absolute_expression ());
2205 switch (*input_line_pointer
)
2208 input_line_pointer
++;
2212 as_warn ("badly formed .dim directive ignored");
2213 /* intentional fallthrough */
2221 demand_empty_rest_of_line ();
2225 obj_coff_line (ignore
)
2231 if (def_symbol_in_progress
== NULL
)
2237 name
= S_GET_NAME (def_symbol_in_progress
);
2238 this_base
= get_absolute_expression ();
2240 /* Only .bf symbols indicate the use of a new base line number; the
2241 line numbers associated with .ef, .bb, .eb are relative to the
2242 start of the containing function. */
2243 if (!strcmp (".bf", name
))
2245 #if 0 /* XXX Can we ever have line numbers going backwards? */
2246 if (this_base
> line_base
)
2249 line_base
= this_base
;
2257 listing_source_line ((unsigned int) line_base
);
2263 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2264 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2266 demand_empty_rest_of_line ();
2270 obj_coff_size (ignore
)
2273 if (def_symbol_in_progress
== NULL
)
2275 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2276 demand_empty_rest_of_line ();
2278 } /* if not inside .def/.endef */
2280 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2281 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2282 demand_empty_rest_of_line ();
2286 obj_coff_scl (ignore
)
2289 if (def_symbol_in_progress
== NULL
)
2291 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2292 demand_empty_rest_of_line ();
2294 } /* if not inside .def/.endef */
2296 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2297 demand_empty_rest_of_line ();
2301 obj_coff_tag (ignore
)
2307 if (def_symbol_in_progress
== NULL
)
2309 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2310 demand_empty_rest_of_line ();
2314 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2315 symbol_name
= input_line_pointer
;
2316 name_end
= get_symbol_end ();
2318 /* Assume that the symbol referred to by .tag is always defined.
2319 This was a bad assumption. I've added find_or_make. xoxorich. */
2320 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2321 (long) tag_find_or_make (symbol_name
));
2322 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2324 as_warn ("tag not found for .tag %s", symbol_name
);
2327 SF_SET_TAGGED (def_symbol_in_progress
);
2328 *input_line_pointer
= name_end
;
2330 demand_empty_rest_of_line ();
2334 obj_coff_type (ignore
)
2337 if (def_symbol_in_progress
== NULL
)
2339 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2340 demand_empty_rest_of_line ();
2342 } /* if not inside .def/.endef */
2344 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2346 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2347 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2349 SF_SET_FUNCTION (def_symbol_in_progress
);
2350 } /* is a function */
2352 demand_empty_rest_of_line ();
2356 obj_coff_val (ignore
)
2359 if (def_symbol_in_progress
== NULL
)
2361 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2362 demand_empty_rest_of_line ();
2364 } /* if not inside .def/.endef */
2366 if (is_name_beginner (*input_line_pointer
))
2368 char *symbol_name
= input_line_pointer
;
2369 char name_end
= get_symbol_end ();
2371 if (!strcmp (symbol_name
, "."))
2373 def_symbol_in_progress
->sy_frag
= frag_now
;
2374 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2375 /* If the .val is != from the .def (e.g. statics) */
2377 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2379 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2380 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2381 symbol_find_or_make (symbol_name
);
2382 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2383 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2385 /* If the segment is undefined when the forward reference is
2386 resolved, then copy the segment id from the forward
2388 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2390 /* FIXME: gcc can generate address expressions
2391 here in unusual cases (search for "obscure"
2392 in sdbout.c). We just ignore the offset
2393 here, thus generating incorrect debugging
2394 information. We ignore the rest of the
2397 /* Otherwise, it is the name of a non debug symbol and
2398 its value will be calculated later. */
2399 *input_line_pointer
= name_end
;
2401 /* FIXME: this is to avoid an error message in the
2402 FIXME case mentioned just above. */
2403 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2404 ++input_line_pointer
;
2408 S_SET_VALUE (def_symbol_in_progress
,
2409 (valueT
) get_absolute_expression ());
2410 } /* if symbol based */
2412 demand_empty_rest_of_line ();
2416 obj_read_begin_hook ()
2418 /* These had better be the same. Usually 18 bytes. */
2420 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2421 know (SYMESZ
== AUXESZ
);
2426 /* This function runs through the symbol table and puts all the
2427 externals onto another chain */
2429 /* The chain of externals */
2430 symbolS
*symbol_externP
;
2431 symbolS
*symbol_extern_lastP
;
2434 symbolS
*last_functionP
;
2441 unsigned int symbol_number
= 0;
2442 unsigned int last_file_symno
= 0;
2444 for (symbolP
= symbol_rootP
;
2446 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2448 if (!SF_GET_DEBUG (symbolP
))
2450 /* Debug symbols do not need all this rubbish */
2451 symbolS
*real_symbolP
;
2453 /* L* and C_EFCN symbols never merge. */
2454 if (!SF_GET_LOCAL (symbolP
)
2455 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2456 && symbolP
->sy_value
.X_op
== O_constant
2457 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2458 && real_symbolP
!= symbolP
)
2460 /* FIXME-SOON: where do dups come from?
2461 Maybe tag references before definitions? xoxorich. */
2462 /* Move the debug data from the debug symbol to the
2463 real symbol. Do NOT do the oposite (i.e. move from
2464 real symbol to debug symbol and remove real symbol from the
2465 list.) Because some pointers refer to the real symbol
2466 whereas no pointers refer to the debug symbol. */
2467 c_symbol_merge (symbolP
, real_symbolP
);
2468 /* Replace the current symbol by the real one */
2469 /* The symbols will never be the last or the first
2470 because : 1st symbol is .file and 3 last symbols are
2471 .text, .data, .bss */
2472 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2473 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2474 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2475 symbolP
= real_symbolP
;
2476 } /* if not local but dup'd */
2478 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2480 S_SET_SEGMENT (symbolP
, SEG_E0
);
2481 } /* push data into text */
2483 resolve_symbol_value (symbolP
);
2485 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2487 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2489 S_SET_EXTERNAL (symbolP
);
2491 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2493 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2497 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2501 /* Mainly to speed up if not -g */
2502 if (SF_GET_PROCESS (symbolP
))
2504 /* Handle the nested blocks auxiliary info. */
2505 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2507 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2508 stack_push (block_stack
, (char *) &symbolP
);
2511 register symbolS
*begin_symbolP
;
2512 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2513 if (begin_symbolP
== (symbolS
*) 0)
2514 as_warn ("mismatched .eb");
2516 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2519 /* If we are able to identify the type of a function, and we
2520 are out of a function (last_functionP == 0) then, the
2521 function symbol will be associated with an auxiliary
2523 if (last_functionP
== (symbolS
*) 0 &&
2524 SF_GET_FUNCTION (symbolP
))
2526 last_functionP
= symbolP
;
2528 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2530 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2531 } /* make it at least 1 */
2533 /* Clobber possible stale .dim information. */
2535 /* Iffed out by steve - this fries the lnnoptr info too */
2536 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2537 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2540 /* The C_FCN doesn't need any additional information. I
2541 don't even know if this is needed for sdb. But the
2542 standard assembler generates it, so... */
2543 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2545 if (last_functionP
== (symbolS
*) 0)
2546 as_fatal ("C_EFCN symbol out of scope");
2547 SA_SET_SYM_FSIZE (last_functionP
,
2548 (long) (S_GET_VALUE (symbolP
) -
2549 S_GET_VALUE (last_functionP
)));
2550 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2551 last_functionP
= (symbolS
*) 0;
2555 else if (SF_GET_TAG (symbolP
))
2557 /* First descriptor of a structure must point to
2558 the first slot after the structure description. */
2559 last_tagP
= symbolP
;
2562 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2564 /* +2 take in account the current symbol */
2565 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2567 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2569 if (S_GET_VALUE (symbolP
))
2571 S_SET_VALUE (symbolP
, last_file_symno
);
2572 last_file_symno
= symbol_number
;
2573 } /* no one points at the first .file symbol */
2574 } /* if debug or tag or eos or file */
2576 /* We must put the external symbols apart. The loader
2577 does not bomb if we do not. But the references in
2578 the endndx field for a .bb symbol are not corrected
2579 if an external symbol is removed between .bb and .be.
2580 I.e in the following case :
2581 [20] .bb endndx = 22
2584 ld will move the symbol 21 to the end of the list but
2585 endndx will still be 22 instead of 21. */
2588 if (SF_GET_LOCAL (symbolP
))
2590 /* remove C_EFCN and LOCAL (L...) symbols */
2591 /* next pointer remains valid */
2592 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2595 else if (!S_IS_DEFINED (symbolP
)
2596 && !S_IS_DEBUG (symbolP
)
2597 && !SF_GET_STATICS (symbolP
) &&
2598 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2599 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2600 /* if external, Remove from the list */
2601 symbolS
*hold
= symbol_previous (symbolP
);
2603 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2604 symbol_clear_list_pointers (symbolP
);
2605 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2610 if (SF_GET_STRING (symbolP
))
2612 symbolP
->sy_name_offset
= string_byte_count
;
2613 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2617 symbolP
->sy_name_offset
= 0;
2618 } /* fix "long" names */
2620 symbolP
->sy_number
= symbol_number
;
2621 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2622 } /* if local symbol */
2623 } /* traverse the symbol list */
2624 return symbol_number
;
2632 unsigned int symbol_number
= 0;
2634 for (symbolP
= symbol_externP
; symbol_externP
;)
2636 symbolS
*tmp
= symbol_externP
;
2639 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2640 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2643 if (SF_GET_STRING (tmp
))
2645 tmp
->sy_name_offset
= string_byte_count
;
2646 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2650 tmp
->sy_name_offset
= 0;
2651 } /* fix "long" names */
2653 tmp
->sy_number
= symbol_number
;
2654 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2655 } /* append the entire extern chain */
2656 return symbol_number
;
2663 unsigned int symbol_number
= 0;
2666 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2667 symbol_next (symbolP
))
2669 symbolP
->sy_number
= symbol_number
;
2673 if (SF_GET_TAGGED (symbolP
))
2677 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2680 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2682 return symbol_number
;
2687 crawl_symbols (h
, abfd
)
2693 /* Initialize the stack used to keep track of the matching .bb .be */
2695 block_stack
= stack_init (512, sizeof (symbolS
*));
2697 /* The symbol list should be ordered according to the following sequence
2700 * . debug entries for functions
2701 * . fake symbols for the sections, including.text .data and .bss
2703 * . undefined symbols
2704 * But this is not mandatory. The only important point is to put the
2705 * undefined symbols at the end of the list.
2708 if (symbol_rootP
== NULL
2709 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2711 c_dot_file_symbol ("fake");
2713 /* Is there a .file symbol ? If not insert one at the beginning. */
2716 * Build up static symbols for the sections, they are filled in later
2720 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2722 if (segment_info
[i
].scnhdr
.s_name
[0])
2726 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2728 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2733 /* Take all the externals out and put them into another chain */
2734 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2735 /* Take the externals and glue them onto the end.*/
2736 H_SET_SYMBOL_TABLE_SIZE (h
, H_GET_SYMBOL_COUNT (h
) + glue_symbols ());
2738 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2739 know (symbol_externP
== NULL
);
2740 know (symbol_extern_lastP
== NULL
);
2744 * Find strings by crawling along symbol table chain.
2753 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2754 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2756 for (symbolP
= symbol_rootP
;
2758 symbolP
= symbol_next (symbolP
))
2762 if (SF_GET_STRING (symbolP
))
2764 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2766 memcpy (where
, S_GET_NAME (symbolP
), size
);
2774 do_linenos_for (abfd
, h
, file_cursor
)
2777 unsigned long *file_cursor
;
2780 unsigned long start
= *file_cursor
;
2782 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2784 segment_info_type
*s
= segment_info
+ idx
;
2787 if (s
->scnhdr
.s_nlnno
!= 0)
2789 struct lineno_list
*line_ptr
;
2791 struct external_lineno
*buffer
=
2792 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2794 struct external_lineno
*dst
= buffer
;
2796 /* Run through the table we've built and turn it into its external
2797 form, take this chance to remove duplicates */
2799 for (line_ptr
= s
->lineno_list_head
;
2800 line_ptr
!= (struct lineno_list
*) NULL
;
2801 line_ptr
= line_ptr
->next
)
2804 if (line_ptr
->line
.l_lnno
== 0)
2806 /* Turn a pointer to a symbol into the symbols' index */
2807 line_ptr
->line
.l_addr
.l_symndx
=
2808 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2812 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2816 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2821 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2823 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2826 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2829 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2833 /* Now we run through the list of frag chains in a segment and
2834 make all the subsegment frags appear at the end of the
2835 list, as if the seg 0 was extra long */
2842 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2844 frchainS
*head
= segment_info
[i
].frchainP
;
2846 fragS
*prev_frag
= &dummy
;
2848 while (head
&& head
->frch_seg
== i
)
2850 prev_frag
->fr_next
= head
->frch_root
;
2851 prev_frag
= head
->frch_last
;
2852 head
= head
->frch_next
;
2854 prev_frag
->fr_next
= 0;
2858 unsigned long machine
;
2861 write_object_file ()
2865 struct frchain
*frchain_ptr
;
2867 object_headers headers
;
2868 unsigned long file_cursor
;
2871 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
2876 as_perror ("FATAL: Can't create %s", out_file_name
);
2877 exit (EXIT_FAILURE
);
2879 bfd_set_format (abfd
, bfd_object
);
2880 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
2882 string_byte_count
= 4;
2884 for (frchain_ptr
= frchain_root
;
2885 frchain_ptr
!= (struct frchain
*) NULL
;
2886 frchain_ptr
= frchain_ptr
->frch_next
)
2888 /* Run through all the sub-segments and align them up. Also
2889 close any open frags. We tack a .fill onto the end of the
2890 frag chain so that any .align's size can be worked by looking
2891 at the next frag. */
2893 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
2894 #ifndef SUB_SEGMENT_ALIGN
2895 #define SUB_SEGMENT_ALIGN(SEG) 1
2897 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
2898 frag_wane (frag_now
);
2899 frag_now
->fr_fix
= 0;
2900 know (frag_now
->fr_next
== NULL
);
2907 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2909 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
2912 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
2914 /* Find out how big the sections are, and set the addresses. */
2916 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2920 segment_info
[i
].scnhdr
.s_paddr
= addr
;
2921 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
2923 if (segment_info
[i
].scnhdr
.s_name
[0])
2925 H_SET_NUMBER_OF_SECTIONS (&headers
,
2926 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
2929 size
= size_section (abfd
, (unsigned int) i
);
2932 /* I think the section alignment is only used on the i960; the
2933 i960 needs it, and it should do no harm on other targets. */
2934 segment_info
[i
].scnhdr
.s_align
= section_alignment
[i
];
2937 H_SET_TEXT_SIZE (&headers
, size
);
2938 else if (i
== SEG_E1
)
2939 H_SET_DATA_SIZE (&headers
, size
);
2940 else if (i
== SEG_E2
)
2941 H_SET_BSS_SIZE (&headers
, size
);
2944 /* Turn the gas native symbol table shape into a coff symbol table */
2945 crawl_symbols (&headers
, abfd
);
2947 if (string_byte_count
== 4)
2948 string_byte_count
= 0;
2950 H_SET_STRING_SIZE (&headers
, string_byte_count
);
2952 #if !defined(TC_H8300) && !defined(TC_Z8K)
2953 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2955 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
2956 fixup_segment (&segment_info
[i
], i
);
2960 /* Look for ".stab" segments and fill in their initial symbols
2962 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2964 name
= segment_info
[i
].scnhdr
.s_name
;
2967 && strncmp (".stab", name
, 5) == 0
2968 && strncmp (".stabstr", name
, 8) != 0)
2969 adjust_stab_section (abfd
, i
);
2972 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
2974 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
2976 /* Plant the data */
2978 fill_section (abfd
, &headers
, &file_cursor
);
2980 do_relocs_for (abfd
, &headers
, &file_cursor
);
2982 do_linenos_for (abfd
, &headers
, &file_cursor
);
2984 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
2985 #ifndef OBJ_COFF_OMIT_TIMESTAMP
2986 H_SET_TIME_STAMP (&headers
, (long)time((long*)0));
2988 H_SET_TIME_STAMP (&headers
, 0);
2990 #ifdef TC_COFF_SET_MACHINE
2991 TC_COFF_SET_MACHINE (&headers
);
2995 #define COFF_FLAGS 0
2998 #ifdef KEEP_RELOC_INFO
2999 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3000 COFF_FLAGS
| coff_flags
));
3002 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3003 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3004 COFF_FLAGS
| coff_flags
));
3008 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3009 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3011 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3012 w_symbols (abfd
, buffer1
, symbol_rootP
);
3013 if (string_byte_count
> 0)
3014 w_strings (buffer1
+ symtable_size
);
3015 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3019 coff_header_append (abfd
, &headers
);
3021 /* Recent changes to write need this, but where it should
3022 go is up to Ken.. */
3023 if (bfd_close_all_done (abfd
) == false)
3024 as_fatal ("Can't close %s: %s", out_file_name
,
3025 bfd_errmsg (bfd_get_error ()));
3028 extern bfd
*stdoutput
;
3035 /* Add a new segment. This is called from subseg_new via the
3036 obj_new_segment macro. */
3039 obj_coff_add_segment (name
)
3045 /* Find out if we've already got a section of this name. */
3046 len
= strlen (name
);
3047 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3050 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3051 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3052 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3053 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3054 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3059 as_bad ("Too many new sections; can't add \"%s\"", name
);
3063 /* Add a new section. */
3064 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3065 sizeof (segment_info
[i
].scnhdr
.s_name
));
3066 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3072 * implement the .section pseudo op:
3073 * .section name {, "flags"}
3075 * | +--- optional flags: 'b' for bss
3077 * +-- section name 'l' for lib
3081 * 'd' (apparently m88k for data)
3083 * But if the argument is not a quoted string, treat it as a
3084 * subsegment number.
3088 obj_coff_section (ignore
)
3091 /* Strip out the section name */
3093 char *section_name_end
;
3100 section_name
= input_line_pointer
;
3101 c
= get_symbol_end ();
3102 section_name_end
= input_line_pointer
;
3104 len
= section_name_end
- section_name
;
3105 input_line_pointer
++;
3111 else if (*input_line_pointer
== ',')
3114 ++input_line_pointer
;
3122 if (*input_line_pointer
!= '"')
3123 exp
= get_absolute_expression ();
3126 ++input_line_pointer
;
3127 while (*input_line_pointer
!= '"'
3128 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3130 switch (*input_line_pointer
)
3132 case 'b': flags
|= STYP_BSS
; break;
3133 case 'i': flags
|= STYP_INFO
; break;
3134 case 'l': flags
|= STYP_LIB
; break;
3135 case 'n': flags
|= STYP_NOLOAD
; break;
3136 case 'o': flags
|= STYP_OVER
; break;
3138 case 'w': flags
|= STYP_DATA
; break;
3139 case 'x': flags
|= STYP_TEXT
; break;
3141 as_warn("unknown section attribute '%c'",
3142 *input_line_pointer
);
3145 ++input_line_pointer
;
3147 if (*input_line_pointer
== '"')
3148 ++input_line_pointer
;
3152 subseg_new (section_name
, (subsegT
) exp
);
3154 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3156 *section_name_end
= c
;
3161 obj_coff_text (ignore
)
3164 subseg_new (".text", get_absolute_expression ());
3169 obj_coff_data (ignore
)
3172 if (flag_readonly_data_in_text
)
3173 subseg_new (".text", get_absolute_expression () + 1000);
3175 subseg_new (".data", get_absolute_expression ());
3179 obj_coff_bss (ignore
)
3182 if (*input_line_pointer
== '\n') /* .bss */
3183 subseg_new(".bss", get_absolute_expression());
3184 else /* .bss id,expr */
3189 obj_coff_ident (ignore
)
3192 segT current_seg
= now_seg
; /* save current seg */
3193 subsegT current_subseg
= now_subseg
;
3194 subseg_new (".comment", 0); /* .comment seg */
3195 stringer (1); /* read string */
3196 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3200 c_symbol_merge (debug
, normal
)
3204 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3205 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3207 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3209 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3210 } /* take the most we have */
3212 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3214 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3215 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3216 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3217 } /* Move all the auxiliary information */
3219 /* Move the debug flags. */
3220 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3221 } /* c_symbol_merge() */
3224 c_line_new (symbol
, paddr
, line_number
, frag
)
3230 struct lineno_list
*new_line
=
3231 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3233 segment_info_type
*s
= segment_info
+ now_seg
;
3234 new_line
->line
.l_lnno
= line_number
;
3236 if (line_number
== 0)
3238 last_line_symbol
= symbol
;
3239 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3243 new_line
->line
.l_addr
.l_paddr
= paddr
;
3246 new_line
->frag
= (char *) frag
;
3247 new_line
->next
= (struct lineno_list
*) NULL
;
3250 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3252 s
->lineno_list_head
= new_line
;
3256 s
->lineno_list_tail
->next
= new_line
;
3258 s
->lineno_list_tail
= new_line
;
3259 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3263 c_dot_file_symbol (filename
)
3268 symbolP
= symbol_new (".file",
3271 &zero_address_frag
);
3273 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3274 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3275 SA_SET_FILE_FNAME (symbolP
, filename
);
3281 listing_source_file (filename
);
3287 SF_SET_DEBUG (symbolP
);
3288 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3290 previous_file_symbol
= symbolP
;
3292 /* Make sure that the symbol is first on the symbol chain */
3293 if (symbol_rootP
!= symbolP
)
3295 if (symbolP
== symbol_lastP
)
3297 symbol_lastP
= symbol_lastP
->sy_previous
;
3298 } /* if it was the last thing on the list */
3300 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3301 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3302 symbol_rootP
= symbolP
;
3303 } /* if not first on the list */
3305 } /* c_dot_file_symbol() */
3308 * Build a 'section static' symbol.
3312 c_section_symbol (name
, idx
)
3318 symbolP
= symbol_new (name
, idx
,
3320 &zero_address_frag
);
3322 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3323 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3325 SF_SET_STATICS (symbolP
);
3328 } /* c_section_symbol() */
3331 w_symbols (abfd
, where
, symbol_rootP
)
3334 symbolS
* symbol_rootP
;
3339 /* First fill in those values we have only just worked out */
3340 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3342 symbolP
= segment_info
[i
].dot
;
3345 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3346 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3347 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3352 * Emit all symbols left in the symbol chain.
3354 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3356 /* Used to save the offset of the name. It is used to point
3357 to the string in memory but must be a file offset. */
3358 register char *temp
;
3360 tc_coff_symbol_emit_hook (symbolP
);
3362 temp
= S_GET_NAME (symbolP
);
3363 if (SF_GET_STRING (symbolP
))
3365 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3366 S_SET_ZEROES (symbolP
, 0);
3370 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3371 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3373 where
= symbol_to_chars (abfd
, where
, symbolP
);
3374 S_SET_NAME (symbolP
, temp
);
3380 obj_coff_lcomm (ignore
)
3393 name
= input_line_pointer
;
3395 c
= get_symbol_end ();
3396 p
= input_line_pointer
;
3399 if (*input_line_pointer
!= ',')
3401 as_bad ("Expected comma after name");
3402 ignore_rest_of_line ();
3405 if (*input_line_pointer
== '\n')
3407 as_bad ("Missing size expression");
3410 input_line_pointer
++;
3411 if ((temp
= get_absolute_expression ()) < 0)
3413 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3414 ignore_rest_of_line ();
3419 symbolP
= symbol_find_or_make(name
);
3421 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3422 S_GET_VALUE(symbolP
) == 0)
3427 segT current_seg
= now_seg
; /* save current seg */
3428 subsegT current_subseg
= now_subseg
;
3430 subseg_set (SEG_E2
, 1);
3431 symbolP
->sy_frag
= frag_now
;
3432 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3435 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3436 S_SET_SEGMENT(symbolP
, SEG_E2
);
3437 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3441 as_bad("Symbol %s already defined", name
);
3443 demand_empty_rest_of_line();
3448 fixup_mdeps (frags
, h
, this_segment
)
3453 subseg_change (this_segment
, 0);
3456 switch (frags
->fr_type
)
3460 frags
->fr_type
= rs_fill
;
3462 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3464 case rs_machine_dependent
:
3465 md_convert_frag (h
, frags
);
3471 frags
= frags
->fr_next
;
3477 fixup_segment (segP
, this_segment_type
)
3478 segment_info_type
* segP
;
3479 segT this_segment_type
;
3481 register fixS
* fixP
;
3482 register symbolS
*add_symbolP
;
3483 register symbolS
*sub_symbolP
;
3484 register long add_number
;
3486 register char *place
;
3487 register long where
;
3488 register char pcrel
;
3489 register fragS
*fragP
;
3490 register segT add_symbol_segment
= absolute_section
;
3493 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3495 fragP
= fixP
->fx_frag
;
3497 where
= fixP
->fx_where
;
3498 place
= fragP
->fr_literal
+ where
;
3499 size
= fixP
->fx_size
;
3500 add_symbolP
= fixP
->fx_addsy
;
3502 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3504 /* Relocation should be done via the associated 'bal' entry
3507 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3509 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3510 "No 'bal' entry point for leafproc %s",
3511 S_GET_NAME (add_symbolP
));
3514 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3517 sub_symbolP
= fixP
->fx_subsy
;
3518 add_number
= fixP
->fx_offset
;
3519 pcrel
= fixP
->fx_pcrel
;
3523 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3524 } /* if there is an addend */
3531 if (S_GET_SEGMENT (sub_symbolP
) != absolute_section
)
3533 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3534 "Negative of non-absolute symbol %s",
3535 S_GET_NAME (sub_symbolP
));
3536 } /* not absolute */
3538 add_number
-= S_GET_VALUE (sub_symbolP
);
3541 /* if sub_symbol is in the same segment that add_symbol
3542 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3544 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
3545 && (SEG_NORMAL (add_symbol_segment
)
3546 || (add_symbol_segment
== absolute_section
)))
3548 /* Difference of 2 symbols from same segment. Can't
3549 make difference of 2 undefineds: 'value' means
3550 something different for N_UNDF. */
3552 /* Makes no sense to use the difference of 2 arbitrary symbols
3553 as the target of a call instruction. */
3556 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3557 "callj to difference of 2 symbols");
3559 #endif /* TC_I960 */
3560 add_number
+= S_GET_VALUE (add_symbolP
) -
3561 S_GET_VALUE (sub_symbolP
);
3564 fixP
->fx_addsy
= NULL
;
3565 fixP
->fx_subsy
= NULL
;
3570 /* Different segments in subtraction. */
3571 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3573 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3575 add_number
-= S_GET_VALUE (sub_symbolP
);
3578 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3579 #if 0 /* Okay for 68k, at least... */
3584 /* Make it pc-relative. */
3585 add_number
+= (md_pcrel_from (fixP
)
3586 - S_GET_VALUE (sub_symbolP
));
3595 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3596 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3597 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3598 S_GET_NAME (sub_symbolP
),
3599 (long) (fragP
->fr_address
+ where
));
3602 } /* if sub_symbolP */
3606 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3609 * This fixup was made when the symbol's segment was
3610 * SEG_UNKNOWN, but it is now in the local segment.
3611 * So we know how to do the address without relocation.
3614 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3615 * in which cases it modifies *fixP as appropriate. In the case
3616 * of a 'calls', no further work is required, and *fixP has been
3617 * set up to make the rest of the code below a no-op.
3620 #endif /* TC_I960 */
3622 add_number
+= S_GET_VALUE (add_symbolP
);
3623 add_number
-= md_pcrel_from (fixP
);
3624 #if defined (TC_I386) || defined (TE_LYNX)
3625 /* On the 386 we must adjust by the segment
3626 vaddr as well. Ian Taylor. */
3627 add_number
-= segP
->scnhdr
.s_vaddr
;
3629 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3630 fixP
->fx_addsy
= NULL
;
3635 switch (add_symbol_segment
)
3637 case absolute_section
:
3639 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3640 #endif /* TC_I960 */
3641 add_number
+= S_GET_VALUE (add_symbolP
);
3642 fixP
->fx_addsy
= NULL
;
3649 /* This really should be handled in the linker, but
3650 backward compatibility forbids. */
3651 add_number
+= S_GET_VALUE (add_symbolP
);
3653 add_number
+= S_GET_VALUE (add_symbolP
) +
3654 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3660 if ((int) fixP
->fx_bit_fixP
== 13)
3662 /* This is a COBR instruction. They have only a
3663 * 13-bit displacement and are only to be used
3664 * for local branches: flag as error, don't generate
3667 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3668 "can't use COBR format with external label");
3669 fixP
->fx_addsy
= NULL
;
3673 #endif /* TC_I960 */
3674 #if defined (TC_I386) || defined (TE_LYNX)
3675 /* 386 COFF uses a peculiar format in
3676 which the value of a common symbol is
3677 stored in the .text segment (I've
3678 checked this on SVR3.2 and SCO 3.2.2)
3679 Ian Taylor <ian@cygnus.com>. */
3680 if (S_IS_COMMON (add_symbolP
))
3681 add_number
+= S_GET_VALUE (add_symbolP
);
3686 } /* switch on symbol seg */
3687 } /* if not in local seg */
3688 } /* if there was a + symbol */
3693 /* This adjustment is not correct on the m88k, for which the
3694 linker does all the computation. */
3695 add_number
-= md_pcrel_from (fixP
);
3697 if (add_symbolP
== 0)
3699 fixP
->fx_addsy
= &abs_symbol
;
3700 } /* if there's an add_symbol */
3701 #if defined (TC_I386) || defined (TE_LYNX)
3702 /* On the 386 we must adjust by the segment vaddr
3703 as well. Ian Taylor. */
3704 add_number
-= segP
->scnhdr
.s_vaddr
;
3708 if (!fixP
->fx_bit_fixP
)
3711 /* The m88k uses the offset field of the reloc to get around
3714 && (add_number
& ~0xFF)
3715 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
3717 && (add_number
& ~0xFFFF)
3718 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3720 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3721 "Value of %ld too large for field of %d bytes at 0x%lx",
3722 (long) add_number
, size
,
3723 (unsigned long) (fragP
->fr_address
+ where
));
3726 #ifdef WARN_SIGNED_OVERFLOW_WORD
3727 /* Warn if a .word value is too large when treated as
3728 a signed number. We already know it is not too
3729 negative. This is to catch over-large switches
3730 generated by gcc on the 68k. */
3731 if (!flag_signed_overflow_ok
3733 && add_number
> 0x7fff)
3734 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3735 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
3737 (unsigned long) (fragP
->fr_address
+ where
));
3739 } /* not a bit fix */
3740 /* once this fix has been applied, we don't have to output anything
3741 nothing more need be done -*/
3742 md_apply_fix (fixP
, add_number
);
3743 } /* For each fixS in this segment. */
3744 } /* fixup_segment() */
3748 /* The first entry in a .stab section is special. */
3751 obj_coff_init_stab_section (seg
)
3757 unsigned int stroff
;
3759 /* Make space for this first symbol. */
3763 as_where (&file
, (unsigned int *) NULL
);
3764 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
3765 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
3766 strcat (stabstr_name
, "str");
3767 stroff
= get_stab_string_offset (file
, stabstr_name
);
3769 md_number_to_chars (p
, stroff
, 4);
3772 /* Fill in the counts in the first entry in a .stab section. */
3775 adjust_stab_section(abfd
, seg
)
3779 segT stabstrseg
= SEG_UNKNOWN
;
3780 char *secname
, *name
, *name2
;
3782 int i
, strsz
= 0, nsyms
;
3783 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
3785 /* Look for the associated string table section. */
3787 secname
= segment_info
[seg
].scnhdr
.s_name
;
3788 name
= (char *) alloca (strlen (secname
) + 4);
3789 strcpy (name
, secname
);
3790 strcat (name
, "str");
3792 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3794 name2
= segment_info
[i
].scnhdr
.s_name
;
3795 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
3802 /* If we found the section, get its size. */
3803 if (stabstrseg
!= SEG_UNKNOWN
)
3804 strsz
= size_section (abfd
, stabstrseg
);
3806 nsyms
= size_section (abfd
, seg
) / 12 - 1;
3808 /* Look for the first frag of sufficient size for the initial stab
3809 symbol, and collect a pointer to it. */
3810 while (frag
&& frag
->fr_fix
< 12)
3811 frag
= frag
->fr_next
;
3813 p
= frag
->fr_literal
;
3816 /* Write in the number of stab symbols and the size of the string
3818 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
3819 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
3822 #endif /* not BFD_ASSEMBLER */
3824 const pseudo_typeS obj_pseudo_table
[] =
3826 {"def", obj_coff_def
, 0},
3827 {"dim", obj_coff_dim
, 0},
3828 {"endef", obj_coff_endef
, 0},
3829 {"line", obj_coff_line
, 0},
3830 {"ln", obj_coff_ln
, 0},
3831 {"appline", obj_coff_ln
, 1},
3832 {"scl", obj_coff_scl
, 0},
3833 {"size", obj_coff_size
, 0},
3834 {"tag", obj_coff_tag
, 0},
3835 {"type", obj_coff_type
, 0},
3836 {"val", obj_coff_val
, 0},
3837 {"section", obj_coff_section
, 0},
3838 #ifndef BFD_ASSEMBLER
3839 {"use", obj_coff_section
, 0},
3840 {"sect", obj_coff_section
, 0},
3841 {"text", obj_coff_text
, 0},
3842 {"data", obj_coff_data
, 0},
3843 {"bss", obj_coff_bss
, 0},
3844 {"lcomm", obj_coff_lcomm
, 0},
3845 {"ident", obj_coff_ident
, 0},
3847 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
3848 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
3850 {"ABORT", s_abort
, 0},
3852 /* The m88k uses sdef instead of def. */
3853 {"sdef", obj_coff_def
, 0},
3855 {NULL
} /* end sentinel */
3856 }; /* obj_pseudo_table */