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 const char *s_get_name
PARAMS ((symbolS
* s
));
26 static symbolS
*def_symbol_in_progress
;
32 unsigned long chunk_size
;
33 unsigned long element_size
;
36 unsigned long pointer
;
41 stack_init (chunk_size
, element_size
)
42 unsigned long chunk_size
;
43 unsigned long element_size
;
47 st
= (stack
*) malloc (sizeof (stack
));
50 st
->data
= malloc (chunk_size
);
57 st
->size
= chunk_size
;
58 st
->chunk_size
= chunk_size
;
59 st
->element_size
= element_size
;
64 /* Not currently used. */
75 stack_push (st
, element
)
79 if (st
->pointer
+ st
->element_size
>= st
->size
)
81 st
->size
+= st
->chunk_size
;
82 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
85 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
86 st
->pointer
+= st
->element_size
;
87 return st
->data
+ st
->pointer
;
94 if (st
->pointer
< st
->element_size
)
99 st
->pointer
-= st
->element_size
;
100 return st
->data
+ st
->pointer
;
104 * Maintain a list of the tagnames of the structres.
107 static struct hash_control
*tag_hash
;
112 tag_hash
= hash_new ();
116 tag_insert (name
, symbolP
)
120 const char *error_string
;
122 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
124 as_fatal ("Inserting \"%s\" into structure table failed: %s",
133 #ifdef STRIP_UNDERSCORE
136 #endif /* STRIP_UNDERSCORE */
137 return (symbolS
*) hash_find (tag_hash
, name
);
141 tag_find_or_make (name
)
146 if ((symbolP
= tag_find (name
)) == NULL
)
148 symbolP
= symbol_new (name
, undefined_section
,
149 0, &zero_address_frag
);
151 tag_insert (S_GET_NAME (symbolP
), symbolP
);
153 symbol_table_insert (symbolP
);
164 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
166 #define GET_FILENAME_STRING(X) \
167 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
171 fetch_coff_debug_section ()
173 static segT debug_section
;
177 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
179 debug_section
= s
->section
;
181 return debug_section
;
185 SA_SET_SYM_ENDNDX (sym
, val
)
189 combined_entry_type
*entry
, *p
;
191 entry
= &coffsymbol (sym
->bsym
)->native
[1];
192 p
= coffsymbol (val
->bsym
)->native
;
193 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
198 SA_SET_SYM_TAGNDX (sym
, val
)
202 combined_entry_type
*entry
, *p
;
204 entry
= &coffsymbol (sym
->bsym
)->native
[1];
205 p
= coffsymbol (val
->bsym
)->native
;
206 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
211 S_GET_DATA_TYPE (sym
)
214 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
218 S_SET_DATA_TYPE (sym
, val
)
222 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
227 S_GET_STORAGE_CLASS (sym
)
230 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
234 S_SET_STORAGE_CLASS (sym
, val
)
238 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
242 /* Merge a debug symbol containing debug information into a normal symbol. */
245 c_symbol_merge (debug
, normal
)
249 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
250 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
252 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
253 /* take the most we have */
254 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
256 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
258 /* Move all the auxiliary information. */
259 /* @@ How many fields do we want to preserve? Would it make more
260 sense to pick and choose those we want to copy? Should look
261 into this further.... [raeburn:19920512.2209EST] */
263 linenos
= coffsymbol (normal
->bsym
)->lineno
;
264 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
265 (char *) &coffsymbol (debug
->bsym
)->native
,
266 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
267 coffsymbol (normal
->bsym
)->lineno
= linenos
;
270 /* Move the debug flags. */
271 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
274 static symbolS
*previous_file_symbol
;
276 c_dot_file_symbol (filename
)
281 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
283 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
284 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
286 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
293 listing_source_file (filename
);
298 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
300 previous_file_symbol
= symbolP
;
302 /* Make sure that the symbol is first on the symbol chain */
303 if (symbol_rootP
!= symbolP
)
305 if (symbolP
== symbol_lastP
)
307 symbol_lastP
= symbol_lastP
->sy_previous
;
308 } /* if it was the last thing on the list */
310 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
311 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
312 symbol_rootP
= symbolP
;
313 } /* if not first on the list */
317 * Build a 'section static' symbol.
321 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
325 unsigned short nreloc
;
326 unsigned short nlnno
;
330 symbolP
= symbol_new (name
,
339 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
340 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
342 SA_SET_SCN_SCNLEN (symbolP
, length
);
343 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
344 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
346 SF_SET_STATICS (symbolP
);
348 return (char *) symbolP
;
351 /* Line number handling */
354 struct line_no
*next
;
361 /* Symbol of last function, which we should hang line#s off of. */
362 static symbolS
*line_fsym
;
364 #define in_function() (line_fsym != 0)
365 #define clear_function() (line_fsym = 0)
366 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
370 obj_symbol_new_hook (symbolP
)
373 char underscore
= 0; /* Symbol has leading _ */
376 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
377 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
379 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
381 S_SET_DATA_TYPE (symbolP
, T_NULL
);
382 S_SET_STORAGE_CLASS (symbolP
, 0);
383 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
385 if (S_IS_STRING (symbolP
))
386 SF_SET_STRING (symbolP
);
387 if (!underscore
&& S_IS_LOCAL (symbolP
))
388 SF_SET_LOCAL (symbolP
);
393 * Handle .ln directives.
396 static symbolS
*current_lineno_sym
;
397 static struct line_no
*line_nos
;
398 /* @@ Blindly assume all .ln directives will be in the .text section... */
399 static int n_line_nos
;
402 add_lineno (frag
, offset
, num
)
407 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
408 sizeof (struct line_no
));
409 if (!current_lineno_sym
)
413 new_line
->next
= line_nos
;
414 new_line
->frag
= frag
;
415 new_line
->l
.line_number
= num
;
416 new_line
->l
.u
.offset
= offset
;
422 coff_add_linesym (sym
)
427 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
431 current_lineno_sym
= sym
;
435 obj_coff_ln (appline
)
440 if (! appline
&& def_symbol_in_progress
!= NULL
)
442 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
443 demand_empty_rest_of_line ();
447 l
= get_absolute_expression ();
450 add_lineno (frag_now
, frag_now_fix (), l
);
460 l
+= coff_line_base
- 1;
461 listing_source_line (l
);
466 demand_empty_rest_of_line ();
472 * Handle .def directives.
474 * One might ask : why can't we symbol_new if the symbol does not
475 * already exist and fill it with debug information. Because of
476 * the C_EFCN special symbol. It would clobber the value of the
477 * function symbol before we have a chance to notice that it is
478 * a C_EFCN. And a second reason is that the code is more clear this
479 * way. (at least I think it is :-).
483 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
484 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
485 *input_line_pointer == '\t') \
486 input_line_pointer++;
492 char name_end
; /* Char after the end of name */
493 char *symbol_name
; /* Name of the debug symbol */
494 char *symbol_name_copy
; /* Temporary copy of the name */
495 unsigned int symbol_name_length
;
497 if (def_symbol_in_progress
!= NULL
)
499 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
500 demand_empty_rest_of_line ();
502 } /* if not inside .def/.endef */
506 symbol_name
= input_line_pointer
;
507 #ifdef STRIP_UNDERSCORE
508 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
510 #endif /* STRIP_UNDERSCORE */
512 name_end
= get_symbol_end ();
513 symbol_name_length
= strlen (symbol_name
);
514 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
515 strcpy (symbol_name_copy
, symbol_name
);
517 /* Initialize the new symbol */
518 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
519 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
520 S_SET_VALUE (def_symbol_in_progress
, 0);
522 if (S_IS_STRING (def_symbol_in_progress
))
523 SF_SET_STRING (def_symbol_in_progress
);
525 *input_line_pointer
= name_end
;
527 demand_empty_rest_of_line ();
530 unsigned int dim_index
;
533 obj_coff_endef (ignore
)
537 /* DIM BUG FIX sac@cygnus.com */
539 if (def_symbol_in_progress
== NULL
)
541 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
542 demand_empty_rest_of_line ();
544 } /* if not inside .def/.endef */
546 /* Set the section number according to storage class. */
547 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
552 SF_SET_TAG (def_symbol_in_progress
);
553 /* intentional fallthrough */
556 SF_SET_DEBUG (def_symbol_in_progress
);
557 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
561 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
562 /* intentional fallthrough */
564 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
565 /* intentional fallthrough */
569 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
571 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
572 if (name
[1] == 'b' && name
[2] == 'f')
574 if (! in_function ())
575 as_warn ("`%s' symbol without preceding function", name
);
576 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
577 /* Will need relocating */
578 SF_SET_PROCESS (def_symbol_in_progress
);
586 #endif /* C_AUTOARG */
596 SF_SET_DEBUG (def_symbol_in_progress
);
597 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
603 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
609 as_warn ("unexpected storage class %d",
610 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
612 } /* switch on storage class */
614 /* Now that we have built a debug symbol, try to find if we should
615 merge with an existing symbol or not. If a symbol is C_EFCN or
616 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
618 /* Two cases for functions. Either debug followed by definition or
619 definition followed by debug. For definition first, we will
620 merge the debug symbol into the definition. For debug first, the
621 lineno entry MUST point to the definition function or else it
622 will point off into space when obj_crawl_symbol_chain() merges
623 the debug symbol into the real symbol. Therefor, let's presume
624 the debug symbol is a real function reference. */
626 /* FIXME-SOON If for some reason the definition label/symbol is
627 never seen, this will probably leave an undefined symbol at link
630 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
631 || (!strcmp (bfd_get_section_name (stdoutput
,
632 S_GET_SEGMENT (def_symbol_in_progress
)),
634 && !SF_GET_TAG (def_symbol_in_progress
))
635 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
636 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
638 if (def_symbol_in_progress
!= symbol_lastP
)
639 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
644 /* This symbol already exists, merge the newly created symbol
645 into the old one. This is not mandatory. The linker can
646 handle duplicate symbols correctly. But I guess that it save
647 a *lot* of space if the assembly file defines a lot of
650 /* The debug entry (def_symbol_in_progress) is merged into the
651 previous definition. */
653 c_symbol_merge (def_symbol_in_progress
, symbolP
);
654 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
655 def_symbol_in_progress
= symbolP
;
657 if (SF_GET_FUNCTION (def_symbol_in_progress
)
658 || SF_GET_TAG (def_symbol_in_progress
))
660 /* For functions, and tags, the symbol *must* be where the
661 debug symbol appears. Move the existing symbol to the
663 /* If it already is at the end of the symbol list, do nothing */
664 if (def_symbol_in_progress
!= symbol_lastP
)
666 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
667 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
672 if (SF_GET_TAG (def_symbol_in_progress
)
673 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
675 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
678 if (SF_GET_FUNCTION (def_symbol_in_progress
))
680 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
681 set_function (def_symbol_in_progress
);
682 SF_SET_PROCESS (def_symbol_in_progress
);
686 /* That is, if this is the first time we've seen the
688 symbol_table_insert (def_symbol_in_progress
);
689 } /* definition follows debug */
690 } /* Create the line number entry pointing to the function being defined */
692 def_symbol_in_progress
= NULL
;
693 demand_empty_rest_of_line ();
697 obj_coff_dim (ignore
)
702 if (def_symbol_in_progress
== NULL
)
704 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
705 demand_empty_rest_of_line ();
707 } /* if not inside .def/.endef */
709 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
711 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
714 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
715 get_absolute_expression ());
717 switch (*input_line_pointer
)
720 input_line_pointer
++;
724 as_warn ("badly formed .dim directive ignored");
725 /* intentional fallthrough */
733 demand_empty_rest_of_line ();
737 obj_coff_line (ignore
)
742 if (def_symbol_in_progress
== NULL
)
744 /* Probably stabs-style line? */
749 this_base
= get_absolute_expression ();
750 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
751 coff_line_base
= this_base
;
753 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
754 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
756 demand_empty_rest_of_line ();
760 obj_coff_size (ignore
)
763 if (def_symbol_in_progress
== NULL
)
765 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
766 demand_empty_rest_of_line ();
768 } /* if not inside .def/.endef */
770 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
771 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
772 demand_empty_rest_of_line ();
776 obj_coff_scl (ignore
)
779 if (def_symbol_in_progress
== NULL
)
781 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
782 demand_empty_rest_of_line ();
784 } /* if not inside .def/.endef */
786 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
787 demand_empty_rest_of_line ();
791 obj_coff_tag (ignore
)
797 if (def_symbol_in_progress
== NULL
)
799 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
800 demand_empty_rest_of_line ();
804 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
805 symbol_name
= input_line_pointer
;
806 name_end
= get_symbol_end ();
808 /* Assume that the symbol referred to by .tag is always defined.
809 This was a bad assumption. I've added find_or_make. xoxorich. */
810 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
811 tag_find_or_make (symbol_name
));
812 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
814 as_warn ("tag not found for .tag %s", symbol_name
);
817 SF_SET_TAGGED (def_symbol_in_progress
);
818 *input_line_pointer
= name_end
;
820 demand_empty_rest_of_line ();
824 obj_coff_type (ignore
)
827 if (def_symbol_in_progress
== NULL
)
829 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
830 demand_empty_rest_of_line ();
832 } /* if not inside .def/.endef */
834 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
836 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
837 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
839 SF_SET_FUNCTION (def_symbol_in_progress
);
840 } /* is a function */
842 demand_empty_rest_of_line ();
846 obj_coff_val (ignore
)
849 if (def_symbol_in_progress
== NULL
)
851 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
852 demand_empty_rest_of_line ();
854 } /* if not inside .def/.endef */
856 if (is_name_beginner (*input_line_pointer
))
858 char *symbol_name
= input_line_pointer
;
859 char name_end
= get_symbol_end ();
861 if (!strcmp (symbol_name
, "."))
863 def_symbol_in_progress
->sy_frag
= frag_now
;
864 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
865 /* If the .val is != from the .def (e.g. statics) */
867 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
869 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
870 def_symbol_in_progress
->sy_value
.X_add_symbol
=
871 symbol_find_or_make (symbol_name
);
872 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
873 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
875 /* If the segment is undefined when the forward reference is
876 resolved, then copy the segment id from the forward
878 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
880 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
881 *input_line_pointer
= name_end
;
885 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
886 } /* if symbol based */
888 demand_empty_rest_of_line ();
892 obj_read_begin_hook ()
894 /* These had better be the same. Usually 18 bytes. */
896 know (sizeof (SYMENT
) == sizeof (AUXENT
));
897 know (SYMESZ
== AUXESZ
);
903 symbolS
*coff_last_function
;
906 coff_frob_symbol (symp
, punt
)
910 static symbolS
*last_tagP
;
911 static stack
*block_stack
;
912 static symbolS
*set_end
;
914 if (symp
== &abs_symbol
)
920 if (current_lineno_sym
)
921 coff_add_linesym ((symbolS
*) 0);
924 block_stack
= stack_init (512, sizeof (symbolS
*));
926 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
927 S_SET_STORAGE_CLASS (symp
, C_EXT
);
929 if (!SF_GET_DEBUG (symp
))
932 if (!SF_GET_LOCAL (symp
)
933 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
936 c_symbol_merge (symp
, real
);
939 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
941 assert (S_GET_VALUE (symp
) == 0);
942 S_SET_EXTERNAL (symp
);
944 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
946 if (S_GET_SEGMENT (symp
) == text_section
947 && symp
!= seg_info (text_section
)->sym
)
948 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
950 S_SET_STORAGE_CLASS (symp
, C_STAT
);
952 if (SF_GET_PROCESS (symp
))
954 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
956 if (!strcmp (S_GET_NAME (symp
), ".bb"))
957 stack_push (block_stack
, (char *) &symp
);
961 begin
= *(symbolS
**) stack_pop (block_stack
);
963 as_warn ("mismatched .eb");
968 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
970 union internal_auxent
*auxp
;
971 coff_last_function
= symp
;
972 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
973 S_SET_NUMBER_AUXILIARY (symp
, 1);
974 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
975 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
976 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
978 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
980 if (coff_last_function
== 0)
981 as_fatal ("C_EFCN symbol out of scope");
982 SA_SET_SYM_FSIZE (coff_last_function
,
983 (long) (S_GET_VALUE (symp
)
984 - S_GET_VALUE (coff_last_function
)));
985 set_end
= coff_last_function
;
986 coff_last_function
= 0;
989 else if (SF_GET_TAG (symp
))
991 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
993 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
995 if (S_GET_VALUE (symp
))
997 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
998 S_SET_VALUE (symp
, 0);
1001 if (S_IS_EXTERNAL (symp
))
1002 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1003 else if (SF_GET_LOCAL (symp
))
1008 if (set_end
!= (symbolS
*) NULL
1011 SA_SET_SYM_ENDNDX (set_end
, symp
);
1015 if (coffsymbol (symp
->bsym
)->lineno
)
1018 struct line_no
*lptr
;
1021 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1022 for (i
= 0; lptr
; lptr
= lptr
->next
)
1024 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1026 /* We need i entries for line numbers, plus 1 for the first
1027 entry which BFD will override, plus 1 for the last zero
1028 entry (a marker for BFD). */
1029 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1030 coffsymbol (symp
->bsym
)->lineno
= l
;
1031 l
[i
+ 1].line_number
= 0;
1032 l
[i
+ 1].u
.sym
= NULL
;
1036 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1044 coff_adjust_section_syms (abfd
, sec
, x
)
1050 segment_info_type
*seginfo
= seg_info (sec
);
1051 int nlnno
, nrelocs
= 0;
1053 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1054 tc-ppc.c. Do not get confused by it. */
1055 if (seginfo
== NULL
)
1058 if (!strcmp (sec
->name
, ".text"))
1063 /* @@ Hope that none of the fixups expand to more than one reloc
1065 fixS
*fixp
= seginfo
->fix_root
;
1068 fixp
= fixp
->fx_next
;
1072 if (bfd_get_section_size_before_reloc (sec
) == 0
1073 && nrelocs
== 0 && nlnno
== 0)
1075 secsym
= section_symbol (sec
);
1076 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1077 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1083 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1087 * implement the .section pseudo op:
1088 * .section name {, "flags"}
1090 * | +--- optional flags: 'b' for bss
1092 * +-- section name 'l' for lib
1096 * 'd' (apparently m88k for data)
1098 * But if the argument is not a quoted string, treat it as a
1099 * subsegment number.
1103 obj_coff_section (ignore
)
1106 /* Strip out the section name */
1114 section_name
= input_line_pointer
;
1115 c
= get_symbol_end ();
1117 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1118 strcpy (name
, section_name
);
1120 *input_line_pointer
= c
;
1125 flags
= SEC_NO_FLAGS
;
1127 if (*input_line_pointer
== ',')
1129 ++input_line_pointer
;
1131 if (*input_line_pointer
!= '"')
1132 exp
= get_absolute_expression ();
1135 ++input_line_pointer
;
1136 while (*input_line_pointer
!= '"'
1137 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1139 switch (*input_line_pointer
)
1141 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1142 case 'n': flags
&=~ SEC_LOAD
; break;
1144 case 'w': flags
&=~ SEC_READONLY
; break;
1145 case 'x': flags
|= SEC_CODE
; break;
1147 case 'i': /* STYP_INFO */
1148 case 'l': /* STYP_LIB */
1149 case 'o': /* STYP_OVER */
1150 as_warn ("unsupported section attribute '%c'",
1151 *input_line_pointer
);
1155 as_warn("unknown section attribute '%c'",
1156 *input_line_pointer
);
1159 ++input_line_pointer
;
1161 if (*input_line_pointer
== '"')
1162 ++input_line_pointer
;
1166 sec
= subseg_new (name
, (subsegT
) exp
);
1168 if (flags
!= SEC_NO_FLAGS
)
1170 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1171 as_warn ("error setting flags for \"%s\": %s",
1172 bfd_section_name (stdoutput
, sec
),
1173 bfd_errmsg (bfd_get_error ()));
1178 coff_adjust_symtab ()
1180 if (symbol_rootP
== NULL
1181 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1183 assert (previous_file_symbol
== 0);
1184 c_dot_file_symbol ("fake");
1189 coff_frob_section (sec
)
1195 bfd_vma size
, n_entries
, mask
;
1197 /* The COFF back end in BFD requires that all section sizes be
1198 rounded up to multiples of the corresponding section alignments.
1199 Seems kinda silly to me, but that's the way it is. */
1200 size
= bfd_get_section_size_before_reloc (sec
);
1201 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1204 size
= (size
+ mask
) & ~mask
;
1205 bfd_set_section_size (stdoutput
, sec
, size
);
1208 /* If the section size is non-zero, the section symbol needs an aux
1209 entry associated with it, indicating the size. We don't know
1210 all the values yet; coff_frob_symbol will fill them in later. */
1213 symbolS
*secsym
= section_symbol (sec
);
1215 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1216 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1217 SF_SET_STATICS (secsym
);
1218 SA_SET_SCN_SCNLEN (secsym
, size
);
1221 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1222 #ifndef STAB_SECTION_NAME
1223 #define STAB_SECTION_NAME ".stab"
1225 #ifndef STAB_STRING_SECTION_NAME
1226 #define STAB_STRING_SECTION_NAME ".stabstr"
1228 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1232 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1233 /* size is already rounded up, since other section will be listed first */
1234 size
= bfd_get_section_size_before_reloc (strsec
);
1236 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1238 /* Find first non-empty frag. It should be large enough. */
1239 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1240 while (fragp
&& fragp
->fr_fix
== 0)
1241 fragp
= fragp
->fr_next
;
1242 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1244 /* Store the values. */
1245 p
= fragp
->fr_literal
;
1246 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1247 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1251 obj_coff_init_stab_section (seg
)
1257 unsigned int stroff
;
1259 /* Make space for this first symbol. */
1263 as_where (&file
, (unsigned int *) NULL
);
1264 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1265 strcpy (stabstr_name
, seg
->name
);
1266 strcat (stabstr_name
, "str");
1267 stroff
= get_stab_string_offset (file
, stabstr_name
);
1269 md_number_to_chars (p
, stroff
, 4);
1278 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1286 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1288 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1289 (unsigned long) symbolP
,
1290 S_GET_NAME(symbolP
),
1291 (long) S_GET_DATA_TYPE(symbolP
),
1292 S_GET_STORAGE_CLASS(symbolP
),
1293 (int) S_GET_SEGMENT(symbolP
));
1299 #else /* not BFD_ASSEMBLER */
1302 /* This is needed because we include internal bfd things. */
1304 #include "bfd/libbfd.h"
1305 #include "bfd/libcoff.h"
1307 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1308 that we can stick sections together without causing trouble. */
1310 #define NOP_OPCODE 0x00
1313 /* The zeroes if symbol name is longer than 8 chars */
1314 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1316 #define MIN(a,b) ((a) < (b)? (a) : (b))
1317 /* This vector is used to turn an internal segment into a section #
1318 suitable for insertion into a coff symbol table
1321 const short seg_N_TYPE
[] =
1322 { /* in: segT out: N_TYPE bits */
1334 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1335 C_UNDEF_SECTION
, /* SEG_GOOF */
1336 C_UNDEF_SECTION
, /* SEG_EXPR */
1337 C_DEBUG_SECTION
, /* SEG_DEBUG */
1338 C_NTV_SECTION
, /* SEG_NTV */
1339 C_PTV_SECTION
, /* SEG_PTV */
1340 C_REGISTER_SECTION
, /* SEG_REGISTER */
1343 int function_lineoff
= -1; /* Offset in line#s where the last function
1344 started (the odd entry for line #0) */
1346 static symbolS
*last_line_symbol
;
1348 /* Add 4 to the real value to get the index and compensate the
1349 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1350 section number into a segment number
1352 static symbolS
*previous_file_symbol
;
1353 void c_symbol_merge ();
1354 static int line_base
;
1356 symbolS
*c_section_symbol ();
1359 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1360 segT this_segment_type
));
1363 static void fixup_mdeps
PARAMS ((fragS
*,
1368 static void fill_section
PARAMS ((bfd
* abfd
,
1373 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1378 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1379 symbolS
* symbol_rootP
));
1381 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1383 static void obj_coff_lcomm
PARAMS ((int));
1384 static void obj_coff_text
PARAMS ((int));
1385 static void obj_coff_data
PARAMS ((int));
1386 static void obj_coff_bss
PARAMS ((int));
1387 static void obj_coff_ident
PARAMS ((int));
1388 void obj_coff_section
PARAMS ((int));
1392 We allow more than just the standard 3 sections, infact, we allow
1393 10 sections, (though the usual three have to be there).
1395 This structure performs the mappings for us:
1406 static const seg_info_type seg_info_off_by_4
[N_SEG
] =
1437 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1439 static relax_addressT
1440 relax_align (address
, alignment
)
1441 relax_addressT address
;
1444 relax_addressT mask
;
1445 relax_addressT new_address
;
1447 mask
= ~((~0) << alignment
);
1448 new_address
= (address
+ mask
) & (~mask
);
1449 return (new_address
- address
);
1457 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1462 /* calculate the size of the frag chain and fill in the section header
1463 to contain all of it, also fill in the addr of the sections */
1465 size_section (abfd
, idx
)
1470 unsigned int size
= 0;
1471 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1474 size
= frag
->fr_address
;
1475 if (frag
->fr_address
!= size
)
1477 fprintf (stderr
, "Out of step\n");
1478 size
= frag
->fr_address
;
1481 switch (frag
->fr_type
)
1483 #ifdef TC_COFF_SIZEMACHDEP
1484 case rs_machine_dependent
:
1485 size
+= TC_COFF_SIZEMACHDEP (frag
);
1490 size
+= frag
->fr_fix
;
1491 size
+= frag
->fr_offset
* frag
->fr_var
;
1494 size
+= frag
->fr_fix
;
1495 size
+= relax_align (size
, frag
->fr_offset
);
1498 BAD_CASE (frag
->fr_type
);
1501 frag
= frag
->fr_next
;
1503 segment_info
[idx
].scnhdr
.s_size
= size
;
1509 count_entries_in_chain (idx
)
1512 unsigned int nrelocs
;
1515 /* Count the relocations */
1516 fixup_ptr
= segment_info
[idx
].fix_root
;
1518 while (fixup_ptr
!= (fixS
*) NULL
)
1520 if (TC_COUNT_RELOC (fixup_ptr
))
1523 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1532 fixup_ptr
= fixup_ptr
->fx_next
;
1537 /* output all the relocations for a section */
1539 do_relocs_for (abfd
, h
, file_cursor
)
1542 unsigned long *file_cursor
;
1544 unsigned int nrelocs
;
1546 unsigned long reloc_start
= *file_cursor
;
1548 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1550 if (segment_info
[idx
].scnhdr
.s_name
[0])
1552 struct external_reloc
*ext_ptr
;
1553 struct external_reloc
*external_reloc_vec
;
1554 unsigned int external_reloc_size
;
1555 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1556 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1557 nrelocs
= count_entries_in_chain (idx
);
1560 /* Bypass this stuff if no relocs. This also incidentally
1561 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1563 external_reloc_size
= nrelocs
* RELSZ
;
1564 external_reloc_vec
=
1565 (struct external_reloc
*) malloc (external_reloc_size
);
1567 ext_ptr
= external_reloc_vec
;
1569 /* Fill in the internal coff style reloc struct from the
1570 internal fix list. */
1573 symbolS
*symbol_ptr
;
1574 struct internal_reloc intr
;
1576 /* Only output some of the relocations */
1577 if (TC_COUNT_RELOC (fix_ptr
))
1579 #ifdef TC_RELOC_MANGLE
1580 TC_RELOC_MANGLE (fix_ptr
, &intr
, base
);
1584 symbol_ptr
= fix_ptr
->fx_addsy
;
1586 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1588 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1590 #ifdef TC_KEEP_FX_OFFSET
1591 intr
.r_offset
= fix_ptr
->fx_offset
;
1596 /* Turn the segment of the symbol into an offset. */
1599 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1602 intr
.r_symndx
= dot
->sy_number
;
1606 intr
.r_symndx
= symbol_ptr
->sy_number
;
1616 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1619 #if defined(TC_A29K)
1621 /* The 29k has a special kludge for the high 16 bit
1622 reloc. Two relocations are emited, R_IHIHALF,
1623 and R_IHCONST. The second one doesn't contain a
1624 symbol, but uses the value for offset. */
1626 if (intr
.r_type
== R_IHIHALF
)
1628 /* now emit the second bit */
1629 intr
.r_type
= R_IHCONST
;
1630 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1631 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1637 fix_ptr
= fix_ptr
->fx_next
;
1640 /* Write out the reloc table */
1641 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1643 free (external_reloc_vec
);
1645 /* Fill in section header info. */
1646 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1647 *file_cursor
+= external_reloc_size
;
1648 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1653 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1657 /* Set relocation_size field in file headers */
1658 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1662 /* run through a frag chain and write out the data to go with it, fill
1663 in the scnhdrs with the info on the file postions
1666 fill_section (abfd
, h
, file_cursor
)
1669 unsigned long *file_cursor
;
1673 unsigned int paddr
= 0;
1675 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1677 unsigned int offset
= 0;
1679 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1683 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1690 buffer
= xmalloc (s
->s_size
);
1691 s
->s_scnptr
= *file_cursor
;
1693 know (s
->s_paddr
== paddr
);
1695 if (strcmp (s
->s_name
, ".text") == 0)
1696 s
->s_flags
|= STYP_TEXT
;
1697 else if (strcmp (s
->s_name
, ".data") == 0)
1698 s
->s_flags
|= STYP_DATA
;
1699 else if (strcmp (s
->s_name
, ".bss") == 0)
1702 s
->s_flags
|= STYP_BSS
;
1704 /* @@ Should make the i386 and a29k coff targets define
1705 COFF_NOLOAD_PROBLEM, and have only one test here. */
1708 #ifndef COFF_NOLOAD_PROBLEM
1709 /* Apparently the SVR3 linker (and exec syscall) and UDI
1710 mondfe progrem are confused by noload sections. */
1711 s
->s_flags
|= STYP_NOLOAD
;
1716 else if (strcmp (s
->s_name
, ".lit") == 0)
1717 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1718 else if (strcmp (s
->s_name
, ".init") == 0)
1719 s
->s_flags
|= STYP_TEXT
;
1720 else if (strcmp (s
->s_name
, ".fini") == 0)
1721 s
->s_flags
|= STYP_TEXT
;
1722 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1723 s
->s_flags
|= STYP_INFO
;
1727 unsigned int fill_size
;
1728 switch (frag
->fr_type
)
1730 case rs_machine_dependent
:
1733 memcpy (buffer
+ frag
->fr_address
,
1735 (unsigned int) frag
->fr_fix
);
1736 offset
+= frag
->fr_fix
;
1745 memcpy (buffer
+ frag
->fr_address
,
1747 (unsigned int) frag
->fr_fix
);
1748 offset
+= frag
->fr_fix
;
1751 fill_size
= frag
->fr_var
;
1752 if (fill_size
&& frag
->fr_offset
> 0)
1755 unsigned int off
= frag
->fr_fix
;
1756 for (count
= frag
->fr_offset
; count
; count
--)
1758 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1760 memcpy (buffer
+ frag
->fr_address
+ off
,
1761 frag
->fr_literal
+ frag
->fr_fix
,
1764 offset
+= fill_size
;
1769 case rs_broken_word
:
1774 frag
= frag
->fr_next
;
1779 if (s
->s_scnptr
!= 0)
1781 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1782 *file_cursor
+= s
->s_size
;
1791 /* Coff file generation & utilities */
1794 coff_header_append (abfd
, h
)
1802 bfd_seek (abfd
, 0, 0);
1804 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1805 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1806 H_SET_VERSION_STAMP (h
, 0);
1807 H_SET_ENTRY_POINT (h
, 0);
1808 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1809 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1810 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1812 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1813 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1814 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1816 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1818 bfd_write (buffer
, i
, 1, abfd
);
1819 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1821 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1823 if (segment_info
[i
].scnhdr
.s_name
[0])
1826 bfd_coff_swap_scnhdr_out (abfd
,
1827 &(segment_info
[i
].scnhdr
),
1829 bfd_write (buffer
, size
, 1, abfd
);
1836 symbol_to_chars (abfd
, where
, symbolP
)
1841 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1845 /* Turn any symbols with register attributes into abs symbols */
1846 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1848 S_SET_SEGMENT (symbolP
, absolute_section
);
1850 /* At the same time, relocate all symbols to their output value */
1852 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1853 + S_GET_VALUE (symbolP
));
1855 S_SET_VALUE (symbolP
, val
);
1857 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1859 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1862 for (i
= 0; i
< numaux
; i
++)
1864 where
+= bfd_coff_swap_aux_out (abfd
,
1865 &symbolP
->sy_symbol
.ost_auxent
[i
],
1866 S_GET_DATA_TYPE (symbolP
),
1867 S_GET_STORAGE_CLASS (symbolP
),
1875 obj_symbol_new_hook (symbolP
)
1878 char underscore
= 0; /* Symbol has leading _ */
1880 /* Effective symbol */
1881 /* Store the pointer in the offset. */
1882 S_SET_ZEROES (symbolP
, 0L);
1883 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1884 S_SET_STORAGE_CLASS (symbolP
, 0);
1885 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1886 /* Additional information */
1887 symbolP
->sy_symbol
.ost_flags
= 0;
1888 /* Auxiliary entries */
1889 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1891 if (S_IS_STRING (symbolP
))
1892 SF_SET_STRING (symbolP
);
1893 if (!underscore
&& S_IS_LOCAL (symbolP
))
1894 SF_SET_LOCAL (symbolP
);
1898 * Handle .ln directives.
1902 obj_coff_ln (appline
)
1907 if (! appline
&& def_symbol_in_progress
!= NULL
)
1909 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1910 demand_empty_rest_of_line ();
1912 } /* wrong context */
1914 l
= get_absolute_expression ();
1915 c_line_new (0, frag_now_fix (), l
, frag_now
);
1924 listing_source_line ((unsigned int) l
);
1929 demand_empty_rest_of_line ();
1935 * Handle .def directives.
1937 * One might ask : why can't we symbol_new if the symbol does not
1938 * already exist and fill it with debug information. Because of
1939 * the C_EFCN special symbol. It would clobber the value of the
1940 * function symbol before we have a chance to notice that it is
1941 * a C_EFCN. And a second reason is that the code is more clear this
1942 * way. (at least I think it is :-).
1946 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1947 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1948 *input_line_pointer == '\t') \
1949 input_line_pointer++;
1955 char name_end
; /* Char after the end of name */
1956 char *symbol_name
; /* Name of the debug symbol */
1957 char *symbol_name_copy
; /* Temporary copy of the name */
1958 unsigned int symbol_name_length
;
1960 if (def_symbol_in_progress
!= NULL
)
1962 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1963 demand_empty_rest_of_line ();
1965 } /* if not inside .def/.endef */
1967 SKIP_WHITESPACES ();
1969 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1970 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
1972 symbol_name
= input_line_pointer
;
1973 name_end
= get_symbol_end ();
1974 symbol_name_length
= strlen (symbol_name
);
1975 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
1976 strcpy (symbol_name_copy
, symbol_name
);
1978 /* Initialize the new symbol */
1979 #ifdef STRIP_UNDERSCORE
1980 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
1981 ? symbol_name_copy
+ 1
1982 : symbol_name_copy
));
1983 #else /* STRIP_UNDERSCORE */
1984 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
1985 #endif /* STRIP_UNDERSCORE */
1986 /* free(symbol_name_copy); */
1987 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
1988 def_symbol_in_progress
->sy_number
= ~0;
1989 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
1990 S_SET_VALUE (def_symbol_in_progress
, 0);
1992 if (S_IS_STRING (def_symbol_in_progress
))
1993 SF_SET_STRING (def_symbol_in_progress
);
1995 *input_line_pointer
= name_end
;
1997 demand_empty_rest_of_line ();
2000 unsigned int dim_index
;
2004 obj_coff_endef (ignore
)
2007 symbolS
*symbolP
= 0;
2008 /* DIM BUG FIX sac@cygnus.com */
2010 if (def_symbol_in_progress
== NULL
)
2012 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2013 demand_empty_rest_of_line ();
2015 } /* if not inside .def/.endef */
2017 /* Set the section number according to storage class. */
2018 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2023 SF_SET_TAG (def_symbol_in_progress
);
2024 /* intentional fallthrough */
2027 SF_SET_DEBUG (def_symbol_in_progress
);
2028 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2032 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2033 /* intentional fallthrough */
2035 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2036 /* intentional fallthrough */
2038 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2040 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2042 if (function_lineoff
< 0)
2044 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2045 } /* missing function symbol */
2046 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2048 SF_SET_PROCESS (last_line_symbol
);
2049 function_lineoff
= -1;
2051 /* Value is always set to . */
2052 def_symbol_in_progress
->sy_frag
= frag_now
;
2053 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2058 #endif /* C_AUTOARG */
2068 SF_SET_DEBUG (def_symbol_in_progress
);
2069 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2075 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2081 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2083 } /* switch on storage class */
2085 /* Now that we have built a debug symbol, try to find if we should
2086 merge with an existing symbol or not. If a symbol is C_EFCN or
2087 absolute_section or untagged SEG_DEBUG it never merges. We also
2088 don't merge labels, which are in a different namespace, nor
2089 symbols which have not yet been defined since they are typically
2090 unique, nor do we merge tags with non-tags. */
2092 /* Two cases for functions. Either debug followed by definition or
2093 definition followed by debug. For definition first, we will
2094 merge the debug symbol into the definition. For debug first, the
2095 lineno entry MUST point to the definition function or else it
2096 will point off into space when crawl_symbols() merges the debug
2097 symbol into the real symbol. Therefor, let's presume the debug
2098 symbol is a real function reference. */
2100 /* FIXME-SOON If for some reason the definition label/symbol is
2101 never seen, this will probably leave an undefined symbol at link
2104 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2105 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2106 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2107 && !SF_GET_TAG (def_symbol_in_progress
))
2108 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2109 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2110 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2111 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2113 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2118 /* This symbol already exists, merge the newly created symbol
2119 into the old one. This is not mandatory. The linker can
2120 handle duplicate symbols correctly. But I guess that it save
2121 a *lot* of space if the assembly file defines a lot of
2124 /* The debug entry (def_symbol_in_progress) is merged into the
2125 previous definition. */
2127 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2128 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2129 def_symbol_in_progress
= symbolP
;
2131 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2132 || SF_GET_TAG (def_symbol_in_progress
))
2134 /* For functions, and tags, the symbol *must* be where the
2135 debug symbol appears. Move the existing symbol to the
2137 /* If it already is at the end of the symbol list, do nothing */
2138 if (def_symbol_in_progress
!= symbol_lastP
)
2140 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2142 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2143 &symbol_rootP
, &symbol_lastP
);
2144 } /* if not already in place */
2146 } /* normal or mergable */
2148 if (SF_GET_TAG (def_symbol_in_progress
)
2149 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2151 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2154 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2156 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2158 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2160 SF_SET_PROCESS (def_symbol_in_progress
);
2162 if (symbolP
== NULL
)
2164 /* That is, if this is the first time we've seen the
2166 symbol_table_insert (def_symbol_in_progress
);
2167 } /* definition follows debug */
2168 } /* Create the line number entry pointing to the function being defined */
2170 def_symbol_in_progress
= NULL
;
2171 demand_empty_rest_of_line ();
2175 obj_coff_dim (ignore
)
2180 if (def_symbol_in_progress
== NULL
)
2182 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2183 demand_empty_rest_of_line ();
2185 } /* if not inside .def/.endef */
2187 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2189 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2191 SKIP_WHITESPACES ();
2192 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2193 get_absolute_expression ());
2195 switch (*input_line_pointer
)
2198 input_line_pointer
++;
2202 as_warn ("badly formed .dim directive ignored");
2203 /* intentional fallthrough */
2211 demand_empty_rest_of_line ();
2215 obj_coff_line (ignore
)
2221 if (def_symbol_in_progress
== NULL
)
2227 name
= S_GET_NAME (def_symbol_in_progress
);
2228 this_base
= get_absolute_expression ();
2230 /* Only .bf symbols indicate the use of a new base line number; the
2231 line numbers associated with .ef, .bb, .eb are relative to the
2232 start of the containing function. */
2233 if (!strcmp (".bf", name
))
2235 #if 0 /* XXX Can we ever have line numbers going backwards? */
2236 if (this_base
> line_base
)
2239 line_base
= this_base
;
2247 listing_source_line ((unsigned int) line_base
);
2253 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2254 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2256 demand_empty_rest_of_line ();
2260 obj_coff_size (ignore
)
2263 if (def_symbol_in_progress
== NULL
)
2265 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2266 demand_empty_rest_of_line ();
2268 } /* if not inside .def/.endef */
2270 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2271 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2272 demand_empty_rest_of_line ();
2276 obj_coff_scl (ignore
)
2279 if (def_symbol_in_progress
== NULL
)
2281 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2282 demand_empty_rest_of_line ();
2284 } /* if not inside .def/.endef */
2286 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2287 demand_empty_rest_of_line ();
2291 obj_coff_tag (ignore
)
2297 if (def_symbol_in_progress
== NULL
)
2299 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2300 demand_empty_rest_of_line ();
2304 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2305 symbol_name
= input_line_pointer
;
2306 name_end
= get_symbol_end ();
2308 /* Assume that the symbol referred to by .tag is always defined.
2309 This was a bad assumption. I've added find_or_make. xoxorich. */
2310 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2311 (long) tag_find_or_make (symbol_name
));
2312 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2314 as_warn ("tag not found for .tag %s", symbol_name
);
2317 SF_SET_TAGGED (def_symbol_in_progress
);
2318 *input_line_pointer
= name_end
;
2320 demand_empty_rest_of_line ();
2324 obj_coff_type (ignore
)
2327 if (def_symbol_in_progress
== NULL
)
2329 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2330 demand_empty_rest_of_line ();
2332 } /* if not inside .def/.endef */
2334 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2336 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2337 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2339 SF_SET_FUNCTION (def_symbol_in_progress
);
2340 } /* is a function */
2342 demand_empty_rest_of_line ();
2346 obj_coff_val (ignore
)
2349 if (def_symbol_in_progress
== NULL
)
2351 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2352 demand_empty_rest_of_line ();
2354 } /* if not inside .def/.endef */
2356 if (is_name_beginner (*input_line_pointer
))
2358 char *symbol_name
= input_line_pointer
;
2359 char name_end
= get_symbol_end ();
2361 if (!strcmp (symbol_name
, "."))
2363 def_symbol_in_progress
->sy_frag
= frag_now
;
2364 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2365 /* If the .val is != from the .def (e.g. statics) */
2367 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2369 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2370 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2371 symbol_find_or_make (symbol_name
);
2372 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2373 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2375 /* If the segment is undefined when the forward reference is
2376 resolved, then copy the segment id from the forward
2378 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2380 /* FIXME: gcc can generate address expressions
2381 here in unusual cases (search for "obscure"
2382 in sdbout.c). We just ignore the offset
2383 here, thus generating incorrect debugging
2384 information. We ignore the rest of the
2387 /* Otherwise, it is the name of a non debug symbol and
2388 its value will be calculated later. */
2389 *input_line_pointer
= name_end
;
2391 /* FIXME: this is to avoid an error message in the
2392 FIXME case mentioned just above. */
2393 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2394 ++input_line_pointer
;
2398 S_SET_VALUE (def_symbol_in_progress
,
2399 (valueT
) get_absolute_expression ());
2400 } /* if symbol based */
2402 demand_empty_rest_of_line ();
2406 obj_read_begin_hook ()
2408 /* These had better be the same. Usually 18 bytes. */
2410 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2411 know (SYMESZ
== AUXESZ
);
2416 /* This function runs through the symbol table and puts all the
2417 externals onto another chain */
2419 /* The chain of externals */
2420 symbolS
*symbol_externP
;
2421 symbolS
*symbol_extern_lastP
;
2424 symbolS
*last_functionP
;
2431 unsigned int symbol_number
= 0;
2432 unsigned int last_file_symno
= 0;
2434 for (symbolP
= symbol_rootP
;
2436 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2438 if (!SF_GET_DEBUG (symbolP
))
2440 /* Debug symbols do not need all this rubbish */
2441 symbolS
*real_symbolP
;
2443 /* L* and C_EFCN symbols never merge. */
2444 if (!SF_GET_LOCAL (symbolP
)
2445 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2446 && symbolP
->sy_value
.X_op
== O_constant
2447 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2448 && real_symbolP
!= symbolP
)
2450 /* FIXME-SOON: where do dups come from?
2451 Maybe tag references before definitions? xoxorich. */
2452 /* Move the debug data from the debug symbol to the
2453 real symbol. Do NOT do the oposite (i.e. move from
2454 real symbol to debug symbol and remove real symbol from the
2455 list.) Because some pointers refer to the real symbol
2456 whereas no pointers refer to the debug symbol. */
2457 c_symbol_merge (symbolP
, real_symbolP
);
2458 /* Replace the current symbol by the real one */
2459 /* The symbols will never be the last or the first
2460 because : 1st symbol is .file and 3 last symbols are
2461 .text, .data, .bss */
2462 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2463 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2464 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2465 symbolP
= real_symbolP
;
2466 } /* if not local but dup'd */
2468 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2470 S_SET_SEGMENT (symbolP
, SEG_E0
);
2471 } /* push data into text */
2473 resolve_symbol_value (symbolP
);
2475 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2477 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2479 S_SET_EXTERNAL (symbolP
);
2481 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2483 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2487 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2491 /* Mainly to speed up if not -g */
2492 if (SF_GET_PROCESS (symbolP
))
2494 /* Handle the nested blocks auxiliary info. */
2495 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2497 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2498 stack_push (block_stack
, (char *) &symbolP
);
2501 register symbolS
*begin_symbolP
;
2502 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2503 if (begin_symbolP
== (symbolS
*) 0)
2504 as_warn ("mismatched .eb");
2506 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2509 /* If we are able to identify the type of a function, and we
2510 are out of a function (last_functionP == 0) then, the
2511 function symbol will be associated with an auxiliary
2513 if (last_functionP
== (symbolS
*) 0 &&
2514 SF_GET_FUNCTION (symbolP
))
2516 last_functionP
= symbolP
;
2518 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2520 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2521 } /* make it at least 1 */
2523 /* Clobber possible stale .dim information. */
2525 /* Iffed out by steve - this fries the lnnoptr info too */
2526 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2527 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2530 /* The C_FCN doesn't need any additional information. I
2531 don't even know if this is needed for sdb. But the
2532 standard assembler generates it, so... */
2533 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2535 if (last_functionP
== (symbolS
*) 0)
2536 as_fatal ("C_EFCN symbol out of scope");
2537 SA_SET_SYM_FSIZE (last_functionP
,
2538 (long) (S_GET_VALUE (symbolP
) -
2539 S_GET_VALUE (last_functionP
)));
2540 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2541 last_functionP
= (symbolS
*) 0;
2545 else if (SF_GET_TAG (symbolP
))
2547 /* First descriptor of a structure must point to
2548 the first slot after the structure description. */
2549 last_tagP
= symbolP
;
2552 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2554 /* +2 take in account the current symbol */
2555 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2557 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2559 if (S_GET_VALUE (symbolP
))
2561 S_SET_VALUE (symbolP
, last_file_symno
);
2562 last_file_symno
= symbol_number
;
2563 } /* no one points at the first .file symbol */
2564 } /* if debug or tag or eos or file */
2566 /* We must put the external symbols apart. The loader
2567 does not bomb if we do not. But the references in
2568 the endndx field for a .bb symbol are not corrected
2569 if an external symbol is removed between .bb and .be.
2570 I.e in the following case :
2571 [20] .bb endndx = 22
2574 ld will move the symbol 21 to the end of the list but
2575 endndx will still be 22 instead of 21. */
2578 if (SF_GET_LOCAL (symbolP
))
2580 /* remove C_EFCN and LOCAL (L...) symbols */
2581 /* next pointer remains valid */
2582 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2585 else if (!S_IS_DEFINED (symbolP
)
2586 && !S_IS_DEBUG (symbolP
)
2587 && !SF_GET_STATICS (symbolP
) &&
2588 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2589 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2590 /* if external, Remove from the list */
2591 symbolS
*hold
= symbol_previous (symbolP
);
2593 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2594 symbol_clear_list_pointers (symbolP
);
2595 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2600 if (SF_GET_STRING (symbolP
))
2602 symbolP
->sy_name_offset
= string_byte_count
;
2603 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2607 symbolP
->sy_name_offset
= 0;
2608 } /* fix "long" names */
2610 symbolP
->sy_number
= symbol_number
;
2611 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2612 } /* if local symbol */
2613 } /* traverse the symbol list */
2614 return symbol_number
;
2622 unsigned int symbol_number
= 0;
2624 for (symbolP
= symbol_externP
; symbol_externP
;)
2626 symbolS
*tmp
= symbol_externP
;
2629 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2630 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2633 if (SF_GET_STRING (tmp
))
2635 tmp
->sy_name_offset
= string_byte_count
;
2636 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2640 tmp
->sy_name_offset
= 0;
2641 } /* fix "long" names */
2643 tmp
->sy_number
= symbol_number
;
2644 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2645 } /* append the entire extern chain */
2646 return symbol_number
;
2653 unsigned int symbol_number
= 0;
2656 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2657 symbol_next (symbolP
))
2659 symbolP
->sy_number
= symbol_number
;
2663 if (SF_GET_TAGGED (symbolP
))
2667 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2670 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2672 return symbol_number
;
2677 crawl_symbols (h
, abfd
)
2683 /* Initialize the stack used to keep track of the matching .bb .be */
2685 block_stack
= stack_init (512, sizeof (symbolS
*));
2687 /* The symbol list should be ordered according to the following sequence
2690 * . debug entries for functions
2691 * . fake symbols for the sections, including.text .data and .bss
2693 * . undefined symbols
2694 * But this is not mandatory. The only important point is to put the
2695 * undefined symbols at the end of the list.
2698 if (symbol_rootP
== NULL
2699 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2701 c_dot_file_symbol ("fake");
2703 /* Is there a .file symbol ? If not insert one at the beginning. */
2706 * Build up static symbols for the sections, they are filled in later
2710 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2712 if (segment_info
[i
].scnhdr
.s_name
[0])
2716 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2718 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2723 /* Take all the externals out and put them into another chain */
2724 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2725 /* Take the externals and glue them onto the end.*/
2726 H_SET_SYMBOL_TABLE_SIZE (h
, H_GET_SYMBOL_COUNT (h
) + glue_symbols ());
2728 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2729 know (symbol_externP
== NULL
);
2730 know (symbol_extern_lastP
== NULL
);
2734 * Find strings by crawling along symbol table chain.
2743 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2744 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2746 for (symbolP
= symbol_rootP
;
2748 symbolP
= symbol_next (symbolP
))
2752 if (SF_GET_STRING (symbolP
))
2754 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2756 memcpy (where
, S_GET_NAME (symbolP
), size
);
2764 do_linenos_for (abfd
, h
, file_cursor
)
2767 unsigned long *file_cursor
;
2770 unsigned long start
= *file_cursor
;
2772 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2774 segment_info_type
*s
= segment_info
+ idx
;
2777 if (s
->scnhdr
.s_nlnno
!= 0)
2779 struct lineno_list
*line_ptr
;
2781 struct external_lineno
*buffer
=
2782 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2784 struct external_lineno
*dst
= buffer
;
2786 /* Run through the table we've built and turn it into its external
2787 form, take this chance to remove duplicates */
2789 for (line_ptr
= s
->lineno_list_head
;
2790 line_ptr
!= (struct lineno_list
*) NULL
;
2791 line_ptr
= line_ptr
->next
)
2794 if (line_ptr
->line
.l_lnno
== 0)
2796 /* Turn a pointer to a symbol into the symbols' index */
2797 line_ptr
->line
.l_addr
.l_symndx
=
2798 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2802 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2806 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2811 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2813 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2816 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2819 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2823 /* Now we run through the list of frag chains in a segment and
2824 make all the subsegment frags appear at the end of the
2825 list, as if the seg 0 was extra long */
2832 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2834 frchainS
*head
= segment_info
[i
].frchainP
;
2836 fragS
*prev_frag
= &dummy
;
2838 while (head
&& head
->frch_seg
== i
)
2840 prev_frag
->fr_next
= head
->frch_root
;
2841 prev_frag
= head
->frch_last
;
2842 head
= head
->frch_next
;
2844 prev_frag
->fr_next
= 0;
2848 unsigned long machine
;
2851 write_object_file ()
2855 struct frchain
*frchain_ptr
;
2857 object_headers headers
;
2858 unsigned long file_cursor
;
2861 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
2866 as_perror ("FATAL: Can't create %s", out_file_name
);
2867 exit (EXIT_FAILURE
);
2869 bfd_set_format (abfd
, bfd_object
);
2870 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
2872 string_byte_count
= 4;
2874 for (frchain_ptr
= frchain_root
;
2875 frchain_ptr
!= (struct frchain
*) NULL
;
2876 frchain_ptr
= frchain_ptr
->frch_next
)
2878 /* Run through all the sub-segments and align them up. Also
2879 close any open frags. We tack a .fill onto the end of the
2880 frag chain so that any .align's size can be worked by looking
2881 at the next frag. */
2883 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
2884 #ifndef SUB_SEGMENT_ALIGN
2885 #define SUB_SEGMENT_ALIGN(SEG) 1
2887 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
2888 frag_wane (frag_now
);
2889 frag_now
->fr_fix
= 0;
2890 know (frag_now
->fr_next
== NULL
);
2897 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2899 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
2902 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
2904 /* Find out how big the sections are, and set the addresses. */
2906 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2910 segment_info
[i
].scnhdr
.s_paddr
= addr
;
2911 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
2913 if (segment_info
[i
].scnhdr
.s_name
[0])
2915 H_SET_NUMBER_OF_SECTIONS (&headers
,
2916 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
2919 size
= size_section (abfd
, (unsigned int) i
);
2922 /* I think the section alignment is only used on the i960; the
2923 i960 needs it, and it should do no harm on other targets. */
2924 segment_info
[i
].scnhdr
.s_align
= section_alignment
[i
];
2927 H_SET_TEXT_SIZE (&headers
, size
);
2928 else if (i
== SEG_E1
)
2929 H_SET_DATA_SIZE (&headers
, size
);
2930 else if (i
== SEG_E2
)
2931 H_SET_BSS_SIZE (&headers
, size
);
2934 /* Turn the gas native symbol table shape into a coff symbol table */
2935 crawl_symbols (&headers
, abfd
);
2937 if (string_byte_count
== 4)
2938 string_byte_count
= 0;
2940 H_SET_STRING_SIZE (&headers
, string_byte_count
);
2942 #if !defined(TC_H8300) && !defined(TC_Z8K)
2943 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2945 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
2946 fixup_segment (&segment_info
[i
], i
);
2950 /* Look for ".stab" segments and fill in their initial symbols
2952 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2954 name
= segment_info
[i
].scnhdr
.s_name
;
2957 && strncmp (".stab", name
, 5) == 0
2958 && strncmp (".stabstr", name
, 8) != 0)
2959 adjust_stab_section (abfd
, i
);
2962 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
2964 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
2966 /* Plant the data */
2968 fill_section (abfd
, &headers
, &file_cursor
);
2970 do_relocs_for (abfd
, &headers
, &file_cursor
);
2972 do_linenos_for (abfd
, &headers
, &file_cursor
);
2974 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
2975 #ifndef OBJ_COFF_OMIT_TIMESTAMP
2976 H_SET_TIME_STAMP (&headers
, (long)time((long*)0));
2978 H_SET_TIME_STAMP (&headers
, 0);
2980 #ifdef TC_COFF_SET_MACHINE
2981 TC_COFF_SET_MACHINE (&headers
);
2984 #ifdef KEEP_RELOC_INFO
2985 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
2986 COFF_FLAGS
| coff_flags
));
2988 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
2989 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
2990 COFF_FLAGS
| coff_flags
));
2994 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
2995 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
2997 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
2998 w_symbols (abfd
, buffer1
, symbol_rootP
);
2999 if (string_byte_count
> 0)
3000 w_strings (buffer1
+ symtable_size
);
3001 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3005 coff_header_append (abfd
, &headers
);
3007 /* Recent changes to write need this, but where it should
3008 go is up to Ken.. */
3009 if (bfd_close_all_done (abfd
) == false)
3010 as_fatal ("Can't close %s: %s", out_file_name
,
3011 bfd_errmsg (bfd_get_error ()));
3014 extern bfd
*stdoutput
;
3021 /* Add a new segment. This is called from subseg_new via the
3022 obj_new_segment macro. */
3025 obj_coff_add_segment (name
)
3031 /* Find out if we've already got a section of this name. */
3032 len
= strlen (name
);
3033 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3036 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3037 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3038 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3039 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3040 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3045 as_bad ("Too many new sections; can't add \"%s\"", name
);
3049 /* Add a new section. */
3050 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3051 sizeof (segment_info
[i
].scnhdr
.s_name
));
3052 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3058 * implement the .section pseudo op:
3059 * .section name {, "flags"}
3061 * | +--- optional flags: 'b' for bss
3063 * +-- section name 'l' for lib
3067 * 'd' (apparently m88k for data)
3069 * But if the argument is not a quoted string, treat it as a
3070 * subsegment number.
3074 obj_coff_section (ignore
)
3077 /* Strip out the section name */
3079 char *section_name_end
;
3086 section_name
= input_line_pointer
;
3087 c
= get_symbol_end ();
3088 section_name_end
= input_line_pointer
;
3090 len
= section_name_end
- section_name
;
3091 input_line_pointer
++;
3097 else if (*input_line_pointer
== ',')
3100 ++input_line_pointer
;
3108 if (*input_line_pointer
!= '"')
3109 exp
= get_absolute_expression ();
3112 ++input_line_pointer
;
3113 while (*input_line_pointer
!= '"'
3114 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3116 switch (*input_line_pointer
)
3118 case 'b': flags
|= STYP_BSS
; break;
3119 case 'i': flags
|= STYP_INFO
; break;
3120 case 'l': flags
|= STYP_LIB
; break;
3121 case 'n': flags
|= STYP_NOLOAD
; break;
3122 case 'o': flags
|= STYP_OVER
; break;
3124 case 'w': flags
|= STYP_DATA
; break;
3125 case 'x': flags
|= STYP_TEXT
; break;
3127 as_warn("unknown section attribute '%c'",
3128 *input_line_pointer
);
3131 ++input_line_pointer
;
3133 if (*input_line_pointer
== '"')
3134 ++input_line_pointer
;
3138 subseg_new (section_name
, (subsegT
) exp
);
3140 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3142 *section_name_end
= c
;
3147 obj_coff_text (ignore
)
3150 subseg_new (".text", get_absolute_expression ());
3155 obj_coff_data (ignore
)
3158 if (flag_readonly_data_in_text
)
3159 subseg_new (".text", get_absolute_expression () + 1000);
3161 subseg_new (".data", get_absolute_expression ());
3165 obj_coff_bss (ignore
)
3168 if (*input_line_pointer
== '\n') /* .bss */
3169 subseg_new(".bss", get_absolute_expression());
3170 else /* .bss id,expr */
3175 obj_coff_ident (ignore
)
3178 segT current_seg
= now_seg
; /* save current seg */
3179 subsegT current_subseg
= now_subseg
;
3180 subseg_new (".comment", 0); /* .comment seg */
3181 stringer (1); /* read string */
3182 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3186 c_symbol_merge (debug
, normal
)
3190 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3191 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3193 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3195 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3196 } /* take the most we have */
3198 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3200 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3201 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3202 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3203 } /* Move all the auxiliary information */
3205 /* Move the debug flags. */
3206 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3207 } /* c_symbol_merge() */
3210 c_line_new (symbol
, paddr
, line_number
, frag
)
3216 struct lineno_list
*new_line
=
3217 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3219 segment_info_type
*s
= segment_info
+ now_seg
;
3220 new_line
->line
.l_lnno
= line_number
;
3222 if (line_number
== 0)
3224 last_line_symbol
= symbol
;
3225 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3229 new_line
->line
.l_addr
.l_paddr
= paddr
;
3232 new_line
->frag
= (char *) frag
;
3233 new_line
->next
= (struct lineno_list
*) NULL
;
3236 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3238 s
->lineno_list_head
= new_line
;
3242 s
->lineno_list_tail
->next
= new_line
;
3244 s
->lineno_list_tail
= new_line
;
3245 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3249 c_dot_file_symbol (filename
)
3254 symbolP
= symbol_new (".file",
3257 &zero_address_frag
);
3259 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3260 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3261 SA_SET_FILE_FNAME (symbolP
, filename
);
3267 listing_source_file (filename
);
3273 SF_SET_DEBUG (symbolP
);
3274 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3276 previous_file_symbol
= symbolP
;
3278 /* Make sure that the symbol is first on the symbol chain */
3279 if (symbol_rootP
!= symbolP
)
3281 if (symbolP
== symbol_lastP
)
3283 symbol_lastP
= symbol_lastP
->sy_previous
;
3284 } /* if it was the last thing on the list */
3286 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3287 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3288 symbol_rootP
= symbolP
;
3289 } /* if not first on the list */
3291 } /* c_dot_file_symbol() */
3294 * Build a 'section static' symbol.
3298 c_section_symbol (name
, idx
)
3304 symbolP
= symbol_new (name
, idx
,
3306 &zero_address_frag
);
3308 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3309 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3311 SF_SET_STATICS (symbolP
);
3314 } /* c_section_symbol() */
3317 w_symbols (abfd
, where
, symbol_rootP
)
3320 symbolS
* symbol_rootP
;
3325 /* First fill in those values we have only just worked out */
3326 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3328 symbolP
= segment_info
[i
].dot
;
3331 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3332 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3333 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3338 * Emit all symbols left in the symbol chain.
3340 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3342 /* Used to save the offset of the name. It is used to point
3343 to the string in memory but must be a file offset. */
3344 register char *temp
;
3346 tc_coff_symbol_emit_hook (symbolP
);
3348 temp
= S_GET_NAME (symbolP
);
3349 if (SF_GET_STRING (symbolP
))
3351 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3352 S_SET_ZEROES (symbolP
, 0);
3356 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3357 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3359 where
= symbol_to_chars (abfd
, where
, symbolP
);
3360 S_SET_NAME (symbolP
, temp
);
3366 obj_coff_lcomm (ignore
)
3379 name
= input_line_pointer
;
3381 c
= get_symbol_end ();
3382 p
= input_line_pointer
;
3385 if (*input_line_pointer
!= ',')
3387 as_bad ("Expected comma after name");
3388 ignore_rest_of_line ();
3391 if (*input_line_pointer
== '\n')
3393 as_bad ("Missing size expression");
3396 input_line_pointer
++;
3397 if ((temp
= get_absolute_expression ()) < 0)
3399 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3400 ignore_rest_of_line ();
3405 symbolP
= symbol_find_or_make(name
);
3407 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3408 S_GET_VALUE(symbolP
) == 0)
3413 segT current_seg
= now_seg
; /* save current seg */
3414 subsegT current_subseg
= now_subseg
;
3416 subseg_set (SEG_E2
, 1);
3417 symbolP
->sy_frag
= frag_now
;
3418 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3421 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3422 S_SET_SEGMENT(symbolP
, SEG_E2
);
3423 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3427 as_bad("Symbol %s already defined", name
);
3429 demand_empty_rest_of_line();
3434 fixup_mdeps (frags
, h
, this_segment
)
3439 subseg_change (this_segment
, 0);
3442 switch (frags
->fr_type
)
3446 frags
->fr_type
= rs_fill
;
3448 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3450 case rs_machine_dependent
:
3451 md_convert_frag (h
, frags
);
3457 frags
= frags
->fr_next
;
3463 fixup_segment (segP
, this_segment_type
)
3464 segment_info_type
* segP
;
3465 segT this_segment_type
;
3467 register fixS
* fixP
;
3468 register symbolS
*add_symbolP
;
3469 register symbolS
*sub_symbolP
;
3470 register long add_number
;
3472 register char *place
;
3473 register long where
;
3474 register char pcrel
;
3475 register fragS
*fragP
;
3476 register segT add_symbol_segment
= absolute_section
;
3479 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3481 fragP
= fixP
->fx_frag
;
3483 where
= fixP
->fx_where
;
3484 place
= fragP
->fr_literal
+ where
;
3485 size
= fixP
->fx_size
;
3486 add_symbolP
= fixP
->fx_addsy
;
3488 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3490 /* Relocation should be done via the associated 'bal' entry
3493 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3495 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3496 "No 'bal' entry point for leafproc %s",
3497 S_GET_NAME (add_symbolP
));
3500 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3503 sub_symbolP
= fixP
->fx_subsy
;
3504 add_number
= fixP
->fx_offset
;
3505 pcrel
= fixP
->fx_pcrel
;
3509 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3510 } /* if there is an addend */
3517 if (S_GET_SEGMENT (sub_symbolP
) != absolute_section
)
3519 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3520 "Negative of non-absolute symbol %s",
3521 S_GET_NAME (sub_symbolP
));
3522 } /* not absolute */
3524 add_number
-= S_GET_VALUE (sub_symbolP
);
3527 /* if sub_symbol is in the same segment that add_symbol
3528 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3530 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
3531 && (SEG_NORMAL (add_symbol_segment
)
3532 || (add_symbol_segment
== absolute_section
)))
3534 /* Difference of 2 symbols from same segment. Can't
3535 make difference of 2 undefineds: 'value' means
3536 something different for N_UNDF. */
3538 /* Makes no sense to use the difference of 2 arbitrary symbols
3539 as the target of a call instruction. */
3542 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3543 "callj to difference of 2 symbols");
3545 #endif /* TC_I960 */
3546 add_number
+= S_GET_VALUE (add_symbolP
) -
3547 S_GET_VALUE (sub_symbolP
);
3550 fixP
->fx_addsy
= NULL
;
3551 fixP
->fx_subsy
= NULL
;
3556 /* Different segments in subtraction. */
3557 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3559 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3561 add_number
-= S_GET_VALUE (sub_symbolP
);
3564 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3565 #if 0 /* Okay for 68k, at least... */
3570 /* Make it pc-relative. */
3571 add_number
+= (md_pcrel_from (fixP
)
3572 - S_GET_VALUE (sub_symbolP
));
3581 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3582 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3583 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3584 S_GET_NAME (sub_symbolP
),
3585 (long) (fragP
->fr_address
+ where
));
3588 } /* if sub_symbolP */
3592 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3595 * This fixup was made when the symbol's segment was
3596 * SEG_UNKNOWN, but it is now in the local segment.
3597 * So we know how to do the address without relocation.
3600 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3601 * in which cases it modifies *fixP as appropriate. In the case
3602 * of a 'calls', no further work is required, and *fixP has been
3603 * set up to make the rest of the code below a no-op.
3606 #endif /* TC_I960 */
3608 add_number
+= S_GET_VALUE (add_symbolP
);
3609 add_number
-= md_pcrel_from (fixP
);
3610 #if defined (TC_I386) || defined (TE_LYNX)
3611 /* On the 386 we must adjust by the segment
3612 vaddr as well. Ian Taylor. */
3613 add_number
-= segP
->scnhdr
.s_vaddr
;
3615 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3616 fixP
->fx_addsy
= NULL
;
3621 switch (add_symbol_segment
)
3623 case absolute_section
:
3625 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3626 #endif /* TC_I960 */
3627 add_number
+= S_GET_VALUE (add_symbolP
);
3628 fixP
->fx_addsy
= NULL
;
3635 /* This really should be handled in the linker, but
3636 backward compatibility forbids. */
3637 add_number
+= S_GET_VALUE (add_symbolP
);
3639 add_number
+= S_GET_VALUE (add_symbolP
) +
3640 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3646 if ((int) fixP
->fx_bit_fixP
== 13)
3648 /* This is a COBR instruction. They have only a
3649 * 13-bit displacement and are only to be used
3650 * for local branches: flag as error, don't generate
3653 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3654 "can't use COBR format with external label");
3655 fixP
->fx_addsy
= NULL
;
3659 #endif /* TC_I960 */
3660 #if defined (TC_I386) || defined (TE_LYNX)
3661 /* 386 COFF uses a peculiar format in
3662 which the value of a common symbol is
3663 stored in the .text segment (I've
3664 checked this on SVR3.2 and SCO 3.2.2)
3665 Ian Taylor <ian@cygnus.com>. */
3666 if (S_IS_COMMON (add_symbolP
))
3667 add_number
+= S_GET_VALUE (add_symbolP
);
3672 } /* switch on symbol seg */
3673 } /* if not in local seg */
3674 } /* if there was a + symbol */
3679 /* This adjustment is not correct on the m88k, for which the
3680 linker does all the computation. */
3681 add_number
-= md_pcrel_from (fixP
);
3683 if (add_symbolP
== 0)
3685 fixP
->fx_addsy
= &abs_symbol
;
3686 } /* if there's an add_symbol */
3687 #if defined (TC_I386) || defined (TE_LYNX)
3688 /* On the 386 we must adjust by the segment vaddr
3689 as well. Ian Taylor. */
3690 add_number
-= segP
->scnhdr
.s_vaddr
;
3694 if (!fixP
->fx_bit_fixP
)
3697 /* The m88k uses the offset field of the reloc to get around
3700 && (add_number
& ~0xFF)
3701 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
3703 && (add_number
& ~0xFFFF)
3704 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3706 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3707 "Value of %ld too large for field of %d bytes at 0x%lx",
3708 (long) add_number
, size
,
3709 (unsigned long) (fragP
->fr_address
+ where
));
3712 #ifdef WARN_SIGNED_OVERFLOW_WORD
3713 /* Warn if a .word value is too large when treated as
3714 a signed number. We already know it is not too
3715 negative. This is to catch over-large switches
3716 generated by gcc on the 68k. */
3717 if (!flag_signed_overflow_ok
3719 && add_number
> 0x7fff)
3720 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3721 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
3723 (unsigned long) (fragP
->fr_address
+ where
));
3725 } /* not a bit fix */
3726 /* once this fix has been applied, we don't have to output anything
3727 nothing more need be done -*/
3728 md_apply_fix (fixP
, add_number
);
3729 } /* For each fixS in this segment. */
3730 } /* fixup_segment() */
3734 /* The first entry in a .stab section is special. */
3737 obj_coff_init_stab_section (seg
)
3743 unsigned int stroff
;
3745 /* Make space for this first symbol. */
3749 as_where (&file
, (unsigned int *) NULL
);
3750 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
3751 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
3752 strcat (stabstr_name
, "str");
3753 stroff
= get_stab_string_offset (file
, stabstr_name
);
3755 md_number_to_chars (p
, stroff
, 4);
3758 /* Fill in the counts in the first entry in a .stab section. */
3761 adjust_stab_section(abfd
, seg
)
3765 segT stabstrseg
= SEG_UNKNOWN
;
3766 char *secname
, *name
, *name2
;
3768 int i
, strsz
= 0, nsyms
;
3769 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
3771 /* Look for the associated string table section. */
3773 secname
= segment_info
[seg
].scnhdr
.s_name
;
3774 name
= (char *) alloca (strlen (secname
) + 4);
3775 strcpy (name
, secname
);
3776 strcat (name
, "str");
3778 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3780 name2
= segment_info
[i
].scnhdr
.s_name
;
3781 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
3788 /* If we found the section, get its size. */
3789 if (stabstrseg
!= SEG_UNKNOWN
)
3790 strsz
= size_section (abfd
, stabstrseg
);
3792 nsyms
= size_section (abfd
, seg
) / 12 - 1;
3794 /* Look for the first frag of sufficient size for the initial stab
3795 symbol, and collect a pointer to it. */
3796 while (frag
&& frag
->fr_fix
< 12)
3797 frag
= frag
->fr_next
;
3799 p
= frag
->fr_literal
;
3802 /* Write in the number of stab symbols and the size of the string
3804 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
3805 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
3808 #endif /* not BFD_ASSEMBLER */
3810 const pseudo_typeS obj_pseudo_table
[] =
3812 {"def", obj_coff_def
, 0},
3813 {"dim", obj_coff_dim
, 0},
3814 {"endef", obj_coff_endef
, 0},
3815 {"line", obj_coff_line
, 0},
3816 {"ln", obj_coff_ln
, 0},
3817 {"appline", obj_coff_ln
, 1},
3818 {"scl", obj_coff_scl
, 0},
3819 {"size", obj_coff_size
, 0},
3820 {"tag", obj_coff_tag
, 0},
3821 {"type", obj_coff_type
, 0},
3822 {"val", obj_coff_val
, 0},
3823 {"section", obj_coff_section
, 0},
3824 #ifndef BFD_ASSEMBLER
3825 {"use", obj_coff_section
, 0},
3826 {"sect", obj_coff_section
, 0},
3827 {"text", obj_coff_text
, 0},
3828 {"data", obj_coff_data
, 0},
3829 {"bss", obj_coff_bss
, 0},
3830 {"lcomm", obj_coff_lcomm
, 0},
3831 {"ident", obj_coff_ident
, 0},
3833 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
3834 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
3836 {"ABORT", s_abort
, 0},
3838 /* The m88k uses sdef instead of def. */
3839 {"sdef", obj_coff_def
, 0},
3841 {NULL
} /* end sentinel */
3842 }; /* obj_pseudo_table */