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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
25 /* I think this is probably always correct. */
26 #ifndef KEEP_RELOC_INFO
27 #define KEEP_RELOC_INFO
31 /* structure used to keep the filenames which
32 are too long around so that we can stick them
33 into the string table */
37 struct filename_list
*next
;
40 static struct filename_list
*filename_list_head
;
41 static struct filename_list
*filename_list_tail
;
43 const char *s_get_name
PARAMS ((symbolS
* s
));
44 static symbolS
*def_symbol_in_progress
;
50 unsigned long chunk_size
;
51 unsigned long element_size
;
54 unsigned long pointer
;
59 stack_init (chunk_size
, element_size
)
60 unsigned long chunk_size
;
61 unsigned long element_size
;
65 st
= (stack
*) malloc (sizeof (stack
));
68 st
->data
= malloc (chunk_size
);
75 st
->size
= chunk_size
;
76 st
->chunk_size
= chunk_size
;
77 st
->element_size
= element_size
;
82 /* Not currently used. */
93 stack_push (st
, element
)
97 if (st
->pointer
+ st
->element_size
>= st
->size
)
99 st
->size
+= st
->chunk_size
;
100 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
103 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
104 st
->pointer
+= st
->element_size
;
105 return st
->data
+ st
->pointer
;
112 if (st
->pointer
< st
->element_size
)
117 st
->pointer
-= st
->element_size
;
118 return st
->data
+ st
->pointer
;
122 * Maintain a list of the tagnames of the structres.
125 static struct hash_control
*tag_hash
;
130 tag_hash
= hash_new ();
134 tag_insert (name
, symbolP
)
138 const char *error_string
;
140 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
142 as_fatal ("Inserting \"%s\" into structure table failed: %s",
151 #ifdef STRIP_UNDERSCORE
154 #endif /* STRIP_UNDERSCORE */
155 return (symbolS
*) hash_find (tag_hash
, name
);
159 tag_find_or_make (name
)
164 if ((symbolP
= tag_find (name
)) == NULL
)
166 symbolP
= symbol_new (name
, undefined_section
,
167 0, &zero_address_frag
);
169 tag_insert (S_GET_NAME (symbolP
), symbolP
);
171 symbol_table_insert (symbolP
);
182 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
184 #define GET_FILENAME_STRING(X) \
185 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
189 fetch_coff_debug_section ()
191 static segT debug_section
;
195 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
197 debug_section
= s
->section
;
199 return debug_section
;
203 SA_SET_SYM_ENDNDX (sym
, val
)
207 combined_entry_type
*entry
, *p
;
209 entry
= &coffsymbol (sym
->bsym
)->native
[1];
210 p
= coffsymbol (val
->bsym
)->native
;
211 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
216 SA_SET_SYM_TAGNDX (sym
, val
)
220 combined_entry_type
*entry
, *p
;
222 entry
= &coffsymbol (sym
->bsym
)->native
[1];
223 p
= coffsymbol (val
->bsym
)->native
;
224 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
229 S_GET_DATA_TYPE (sym
)
232 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
236 S_SET_DATA_TYPE (sym
, val
)
240 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
245 S_GET_STORAGE_CLASS (sym
)
248 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
252 S_SET_STORAGE_CLASS (sym
, val
)
256 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
260 /* Merge a debug symbol containing debug information into a normal symbol. */
263 c_symbol_merge (debug
, normal
)
267 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
268 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
270 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
271 /* take the most we have */
272 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
274 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
276 /* Move all the auxiliary information. */
277 /* @@ How many fields do we want to preserve? Would it make more
278 sense to pick and choose those we want to copy? Should look
279 into this further.... [raeburn:19920512.2209EST] */
281 linenos
= coffsymbol (normal
->bsym
)->lineno
;
282 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
283 (char *) &coffsymbol (debug
->bsym
)->native
,
284 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
285 coffsymbol (normal
->bsym
)->lineno
= linenos
;
288 /* Move the debug flags. */
289 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
292 static symbolS
*previous_file_symbol
;
294 c_dot_file_symbol (filename
)
299 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
301 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
302 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
304 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
311 listing_source_file (filename
);
316 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
318 previous_file_symbol
= symbolP
;
320 /* Make sure that the symbol is first on the symbol chain */
321 if (symbol_rootP
!= symbolP
)
323 if (symbolP
== symbol_lastP
)
325 symbol_lastP
= symbol_lastP
->sy_previous
;
326 } /* if it was the last thing on the list */
328 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
329 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
330 symbol_rootP
= symbolP
;
331 } /* if not first on the list */
335 * Build a 'section static' symbol.
339 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
343 unsigned short nreloc
;
344 unsigned short nlnno
;
348 symbolP
= symbol_new (name
,
357 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
358 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
360 SA_SET_SCN_SCNLEN (symbolP
, length
);
361 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
362 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
364 SF_SET_STATICS (symbolP
);
366 return (char *) symbolP
;
369 /* Line number handling */
372 struct line_no
*next
;
379 /* Symbol of last function, which we should hang line#s off of. */
380 static symbolS
*line_fsym
;
382 #define in_function() (line_fsym != 0)
383 #define clear_function() (line_fsym = 0)
384 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
388 obj_symbol_new_hook (symbolP
)
391 char underscore
= 0; /* Symbol has leading _ */
394 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
395 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
397 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
399 S_SET_DATA_TYPE (symbolP
, T_NULL
);
400 S_SET_STORAGE_CLASS (symbolP
, 0);
401 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
403 if (S_IS_STRING (symbolP
))
404 SF_SET_STRING (symbolP
);
405 if (!underscore
&& S_IS_LOCAL (symbolP
))
406 SF_SET_LOCAL (symbolP
);
411 * Handle .ln directives.
414 static symbolS
*current_lineno_sym
;
415 static struct line_no
*line_nos
;
416 /* @@ Blindly assume all .ln directives will be in the .text section... */
417 static int n_line_nos
;
420 add_lineno (frag
, offset
, num
)
425 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
426 sizeof (struct line_no
));
427 if (!current_lineno_sym
)
431 new_line
->next
= line_nos
;
432 new_line
->frag
= frag
;
433 new_line
->l
.line_number
= num
;
434 new_line
->l
.u
.offset
= offset
;
440 coff_add_linesym (sym
)
445 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
449 current_lineno_sym
= sym
;
453 obj_coff_ln (appline
)
458 if (! appline
&& def_symbol_in_progress
!= NULL
)
460 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
461 demand_empty_rest_of_line ();
465 l
= get_absolute_expression ();
468 add_lineno (frag_now
, frag_now_fix (), l
);
478 l
+= coff_line_base
- 1;
479 listing_source_line (l
);
484 demand_empty_rest_of_line ();
490 * Handle .def directives.
492 * One might ask : why can't we symbol_new if the symbol does not
493 * already exist and fill it with debug information. Because of
494 * the C_EFCN special symbol. It would clobber the value of the
495 * function symbol before we have a chance to notice that it is
496 * a C_EFCN. And a second reason is that the code is more clear this
497 * way. (at least I think it is :-).
501 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
502 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
503 *input_line_pointer == '\t') \
504 input_line_pointer++;
510 char name_end
; /* Char after the end of name */
511 char *symbol_name
; /* Name of the debug symbol */
512 char *symbol_name_copy
; /* Temporary copy of the name */
513 unsigned int symbol_name_length
;
515 if (def_symbol_in_progress
!= NULL
)
517 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
518 demand_empty_rest_of_line ();
520 } /* if not inside .def/.endef */
524 symbol_name
= input_line_pointer
;
525 #ifdef STRIP_UNDERSCORE
526 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
528 #endif /* STRIP_UNDERSCORE */
530 name_end
= get_symbol_end ();
531 symbol_name_length
= strlen (symbol_name
);
532 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
533 strcpy (symbol_name_copy
, symbol_name
);
535 /* Initialize the new symbol */
536 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
537 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
538 S_SET_VALUE (def_symbol_in_progress
, 0);
540 if (S_IS_STRING (def_symbol_in_progress
))
541 SF_SET_STRING (def_symbol_in_progress
);
543 *input_line_pointer
= name_end
;
545 demand_empty_rest_of_line ();
548 unsigned int dim_index
;
551 obj_coff_endef (ignore
)
555 /* DIM BUG FIX sac@cygnus.com */
557 if (def_symbol_in_progress
== NULL
)
559 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
560 demand_empty_rest_of_line ();
562 } /* if not inside .def/.endef */
564 /* Set the section number according to storage class. */
565 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
570 SF_SET_TAG (def_symbol_in_progress
);
571 /* intentional fallthrough */
574 SF_SET_DEBUG (def_symbol_in_progress
);
575 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
579 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
580 /* intentional fallthrough */
582 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
583 /* intentional fallthrough */
587 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
589 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
590 if (name
[1] == 'b' && name
[2] == 'f')
592 if (! in_function ())
593 as_warn ("`%s' symbol without preceding function", name
);
594 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
595 /* Will need relocating */
596 SF_SET_PROCESS (def_symbol_in_progress
);
604 #endif /* C_AUTOARG */
614 SF_SET_DEBUG (def_symbol_in_progress
);
615 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
621 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
627 as_warn ("unexpected storage class %d",
628 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
630 } /* switch on storage class */
632 /* Now that we have built a debug symbol, try to find if we should
633 merge with an existing symbol or not. If a symbol is C_EFCN or
634 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
636 /* Two cases for functions. Either debug followed by definition or
637 definition followed by debug. For definition first, we will
638 merge the debug symbol into the definition. For debug first, the
639 lineno entry MUST point to the definition function or else it
640 will point off into space when obj_crawl_symbol_chain() merges
641 the debug symbol into the real symbol. Therefor, let's presume
642 the debug symbol is a real function reference. */
644 /* FIXME-SOON If for some reason the definition label/symbol is
645 never seen, this will probably leave an undefined symbol at link
648 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
649 || (!strcmp (bfd_get_section_name (stdoutput
,
650 S_GET_SEGMENT (def_symbol_in_progress
)),
652 && !SF_GET_TAG (def_symbol_in_progress
))
653 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
654 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
656 if (def_symbol_in_progress
!= symbol_lastP
)
657 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
662 /* This symbol already exists, merge the newly created symbol
663 into the old one. This is not mandatory. The linker can
664 handle duplicate symbols correctly. But I guess that it save
665 a *lot* of space if the assembly file defines a lot of
668 /* The debug entry (def_symbol_in_progress) is merged into the
669 previous definition. */
671 c_symbol_merge (def_symbol_in_progress
, symbolP
);
672 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
673 def_symbol_in_progress
= symbolP
;
675 if (SF_GET_FUNCTION (def_symbol_in_progress
)
676 || SF_GET_TAG (def_symbol_in_progress
))
678 /* For functions, and tags, the symbol *must* be where the
679 debug symbol appears. Move the existing symbol to the
681 /* If it already is at the end of the symbol list, do nothing */
682 if (def_symbol_in_progress
!= symbol_lastP
)
684 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
685 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
690 if (SF_GET_TAG (def_symbol_in_progress
)
691 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
693 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
696 if (SF_GET_FUNCTION (def_symbol_in_progress
))
698 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
699 set_function (def_symbol_in_progress
);
700 SF_SET_PROCESS (def_symbol_in_progress
);
704 /* That is, if this is the first time we've seen the
706 symbol_table_insert (def_symbol_in_progress
);
707 } /* definition follows debug */
708 } /* Create the line number entry pointing to the function being defined */
710 def_symbol_in_progress
= NULL
;
711 demand_empty_rest_of_line ();
715 obj_coff_dim (ignore
)
720 if (def_symbol_in_progress
== NULL
)
722 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
723 demand_empty_rest_of_line ();
725 } /* if not inside .def/.endef */
727 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
729 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
732 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
733 get_absolute_expression ());
735 switch (*input_line_pointer
)
738 input_line_pointer
++;
742 as_warn ("badly formed .dim directive ignored");
743 /* intentional fallthrough */
751 demand_empty_rest_of_line ();
755 obj_coff_line (ignore
)
760 if (def_symbol_in_progress
== NULL
)
762 /* Probably stabs-style line? */
767 this_base
= get_absolute_expression ();
768 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
769 coff_line_base
= this_base
;
771 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
772 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
774 demand_empty_rest_of_line ();
777 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
782 listing_source_line ((unsigned int) coff_line_base
);
788 obj_coff_size (ignore
)
791 if (def_symbol_in_progress
== NULL
)
793 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
794 demand_empty_rest_of_line ();
796 } /* if not inside .def/.endef */
798 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
799 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
800 demand_empty_rest_of_line ();
804 obj_coff_scl (ignore
)
807 if (def_symbol_in_progress
== NULL
)
809 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
810 demand_empty_rest_of_line ();
812 } /* if not inside .def/.endef */
814 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
815 demand_empty_rest_of_line ();
819 obj_coff_tag (ignore
)
825 if (def_symbol_in_progress
== NULL
)
827 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
828 demand_empty_rest_of_line ();
832 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
833 symbol_name
= input_line_pointer
;
834 name_end
= get_symbol_end ();
836 /* Assume that the symbol referred to by .tag is always defined.
837 This was a bad assumption. I've added find_or_make. xoxorich. */
838 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
839 tag_find_or_make (symbol_name
));
840 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
842 as_warn ("tag not found for .tag %s", symbol_name
);
845 SF_SET_TAGGED (def_symbol_in_progress
);
846 *input_line_pointer
= name_end
;
848 demand_empty_rest_of_line ();
852 obj_coff_type (ignore
)
855 if (def_symbol_in_progress
== NULL
)
857 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
858 demand_empty_rest_of_line ();
860 } /* if not inside .def/.endef */
862 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
864 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
865 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
867 SF_SET_FUNCTION (def_symbol_in_progress
);
868 } /* is a function */
870 demand_empty_rest_of_line ();
874 obj_coff_val (ignore
)
877 if (def_symbol_in_progress
== NULL
)
879 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
880 demand_empty_rest_of_line ();
882 } /* if not inside .def/.endef */
884 if (is_name_beginner (*input_line_pointer
))
886 char *symbol_name
= input_line_pointer
;
887 char name_end
= get_symbol_end ();
889 if (!strcmp (symbol_name
, "."))
891 def_symbol_in_progress
->sy_frag
= frag_now
;
892 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
893 /* If the .val is != from the .def (e.g. statics) */
895 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
897 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
898 def_symbol_in_progress
->sy_value
.X_add_symbol
=
899 symbol_find_or_make (symbol_name
);
900 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
901 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
903 /* If the segment is undefined when the forward reference is
904 resolved, then copy the segment id from the forward
906 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
908 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
909 *input_line_pointer
= name_end
;
913 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
914 } /* if symbol based */
916 demand_empty_rest_of_line ();
920 obj_read_begin_hook ()
922 /* These had better be the same. Usually 18 bytes. */
924 know (sizeof (SYMENT
) == sizeof (AUXENT
));
925 know (SYMESZ
== AUXESZ
);
931 symbolS
*coff_last_function
;
934 coff_frob_symbol (symp
, punt
)
938 static symbolS
*last_tagP
;
939 static stack
*block_stack
;
940 static symbolS
*set_end
;
942 if (symp
== &abs_symbol
)
948 if (current_lineno_sym
)
949 coff_add_linesym ((symbolS
*) 0);
952 block_stack
= stack_init (512, sizeof (symbolS
*));
954 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
955 S_SET_STORAGE_CLASS (symp
, C_EXT
);
957 if (!SF_GET_DEBUG (symp
))
960 if (!SF_GET_LOCAL (symp
)
961 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
964 c_symbol_merge (symp
, real
);
967 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
969 assert (S_GET_VALUE (symp
) == 0);
970 S_SET_EXTERNAL (symp
);
972 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
974 if (S_GET_SEGMENT (symp
) == text_section
975 && symp
!= seg_info (text_section
)->sym
)
976 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
978 S_SET_STORAGE_CLASS (symp
, C_STAT
);
980 if (SF_GET_PROCESS (symp
))
982 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
984 if (!strcmp (S_GET_NAME (symp
), ".bb"))
985 stack_push (block_stack
, (char *) &symp
);
989 begin
= *(symbolS
**) stack_pop (block_stack
);
991 as_warn ("mismatched .eb");
996 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
998 union internal_auxent
*auxp
;
999 coff_last_function
= symp
;
1000 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1001 S_SET_NUMBER_AUXILIARY (symp
, 1);
1002 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
1003 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1004 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1006 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1008 if (coff_last_function
== 0)
1009 as_fatal ("C_EFCN symbol out of scope");
1010 SA_SET_SYM_FSIZE (coff_last_function
,
1011 (long) (S_GET_VALUE (symp
)
1012 - S_GET_VALUE (coff_last_function
)));
1013 set_end
= coff_last_function
;
1014 coff_last_function
= 0;
1017 else if (SF_GET_TAG (symp
))
1019 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1020 set_end
= last_tagP
;
1021 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1023 if (S_GET_VALUE (symp
))
1025 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1026 S_SET_VALUE (symp
, 0);
1029 if (S_IS_EXTERNAL (symp
))
1030 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1031 else if (SF_GET_LOCAL (symp
))
1034 if (SF_GET_FUNCTION (symp
))
1035 symp
->bsym
->flags
|= BSF_FUNCTION
;
1040 if (set_end
!= (symbolS
*) NULL
1043 SA_SET_SYM_ENDNDX (set_end
, symp
);
1047 if (coffsymbol (symp
->bsym
)->lineno
)
1050 struct line_no
*lptr
;
1053 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1054 for (i
= 0; lptr
; lptr
= lptr
->next
)
1056 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1058 /* We need i entries for line numbers, plus 1 for the first
1059 entry which BFD will override, plus 1 for the last zero
1060 entry (a marker for BFD). */
1061 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1062 coffsymbol (symp
->bsym
)->lineno
= l
;
1063 l
[i
+ 1].line_number
= 0;
1064 l
[i
+ 1].u
.sym
= NULL
;
1068 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1076 coff_adjust_section_syms (abfd
, sec
, x
)
1082 segment_info_type
*seginfo
= seg_info (sec
);
1083 int nlnno
, nrelocs
= 0;
1085 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1086 tc-ppc.c. Do not get confused by it. */
1087 if (seginfo
== NULL
)
1090 if (!strcmp (sec
->name
, ".text"))
1095 /* @@ Hope that none of the fixups expand to more than one reloc
1097 fixS
*fixp
= seginfo
->fix_root
;
1100 fixp
= fixp
->fx_next
;
1104 if (bfd_get_section_size_before_reloc (sec
) == 0
1105 && nrelocs
== 0 && nlnno
== 0)
1107 secsym
= section_symbol (sec
);
1108 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1109 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1115 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1119 * implement the .section pseudo op:
1120 * .section name {, "flags"}
1122 * | +--- optional flags: 'b' for bss
1124 * +-- section name 'l' for lib
1128 * 'd' (apparently m88k for data)
1130 * But if the argument is not a quoted string, treat it as a
1131 * subsegment number.
1135 obj_coff_section (ignore
)
1138 /* Strip out the section name */
1146 section_name
= input_line_pointer
;
1147 c
= get_symbol_end ();
1149 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1150 strcpy (name
, section_name
);
1152 *input_line_pointer
= c
;
1157 flags
= SEC_NO_FLAGS
;
1159 if (*input_line_pointer
== ',')
1161 ++input_line_pointer
;
1163 if (*input_line_pointer
!= '"')
1164 exp
= get_absolute_expression ();
1167 ++input_line_pointer
;
1168 while (*input_line_pointer
!= '"'
1169 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1171 switch (*input_line_pointer
)
1173 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1174 case 'n': flags
&=~ SEC_LOAD
; break;
1176 case 'w': flags
&=~ SEC_READONLY
; break;
1177 case 'x': flags
|= SEC_CODE
; break;
1179 case 'i': /* STYP_INFO */
1180 case 'l': /* STYP_LIB */
1181 case 'o': /* STYP_OVER */
1182 as_warn ("unsupported section attribute '%c'",
1183 *input_line_pointer
);
1187 as_warn("unknown section attribute '%c'",
1188 *input_line_pointer
);
1191 ++input_line_pointer
;
1193 if (*input_line_pointer
== '"')
1194 ++input_line_pointer
;
1198 sec
= subseg_new (name
, (subsegT
) exp
);
1200 if (flags
!= SEC_NO_FLAGS
)
1202 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1203 as_warn ("error setting flags for \"%s\": %s",
1204 bfd_section_name (stdoutput
, sec
),
1205 bfd_errmsg (bfd_get_error ()));
1210 coff_adjust_symtab ()
1212 if (symbol_rootP
== NULL
1213 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1215 assert (previous_file_symbol
== 0);
1216 c_dot_file_symbol ("fake");
1221 coff_frob_section (sec
)
1227 bfd_vma size
, n_entries
, mask
;
1229 /* The COFF back end in BFD requires that all section sizes be
1230 rounded up to multiples of the corresponding section alignments.
1231 Seems kinda silly to me, but that's the way it is. */
1232 size
= bfd_get_section_size_before_reloc (sec
);
1233 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1236 size
= (size
+ mask
) & ~mask
;
1237 bfd_set_section_size (stdoutput
, sec
, size
);
1240 /* If the section size is non-zero, the section symbol needs an aux
1241 entry associated with it, indicating the size. We don't know
1242 all the values yet; coff_frob_symbol will fill them in later. */
1245 symbolS
*secsym
= section_symbol (sec
);
1247 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1248 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1249 SF_SET_STATICS (secsym
);
1250 SA_SET_SCN_SCNLEN (secsym
, size
);
1253 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1254 #ifndef STAB_SECTION_NAME
1255 #define STAB_SECTION_NAME ".stab"
1257 #ifndef STAB_STRING_SECTION_NAME
1258 #define STAB_STRING_SECTION_NAME ".stabstr"
1260 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1264 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1265 /* size is already rounded up, since other section will be listed first */
1266 size
= bfd_get_section_size_before_reloc (strsec
);
1268 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1270 /* Find first non-empty frag. It should be large enough. */
1271 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1272 while (fragp
&& fragp
->fr_fix
== 0)
1273 fragp
= fragp
->fr_next
;
1274 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1276 /* Store the values. */
1277 p
= fragp
->fr_literal
;
1278 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1279 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1283 obj_coff_init_stab_section (seg
)
1289 unsigned int stroff
;
1291 /* Make space for this first symbol. */
1295 as_where (&file
, (unsigned int *) NULL
);
1296 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1297 strcpy (stabstr_name
, seg
->name
);
1298 strcat (stabstr_name
, "str");
1299 stroff
= get_stab_string_offset (file
, stabstr_name
);
1301 md_number_to_chars (p
, stroff
, 4);
1310 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1318 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1320 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1321 (unsigned long) symbolP
,
1322 S_GET_NAME(symbolP
),
1323 (long) S_GET_DATA_TYPE(symbolP
),
1324 S_GET_STORAGE_CLASS(symbolP
),
1325 (int) S_GET_SEGMENT(symbolP
));
1331 #else /* not BFD_ASSEMBLER */
1334 /* This is needed because we include internal bfd things. */
1338 #include "libcoff.h"
1340 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1341 that we can stick sections together without causing trouble. */
1343 #define NOP_OPCODE 0x00
1346 /* The zeroes if symbol name is longer than 8 chars */
1347 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1349 #define MIN(a,b) ((a) < (b)? (a) : (b))
1350 /* This vector is used to turn an internal segment into a section #
1351 suitable for insertion into a coff symbol table
1354 const short seg_N_TYPE
[] =
1355 { /* in: segT out: N_TYPE bits */
1367 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1368 C_UNDEF_SECTION
, /* SEG_GOOF */
1369 C_UNDEF_SECTION
, /* SEG_EXPR */
1370 C_DEBUG_SECTION
, /* SEG_DEBUG */
1371 C_NTV_SECTION
, /* SEG_NTV */
1372 C_PTV_SECTION
, /* SEG_PTV */
1373 C_REGISTER_SECTION
, /* SEG_REGISTER */
1376 int function_lineoff
= -1; /* Offset in line#s where the last function
1377 started (the odd entry for line #0) */
1379 static symbolS
*last_line_symbol
;
1381 /* Add 4 to the real value to get the index and compensate the
1382 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1383 section number into a segment number
1385 static symbolS
*previous_file_symbol
;
1386 void c_symbol_merge ();
1387 static int line_base
;
1389 symbolS
*c_section_symbol ();
1392 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1393 segT this_segment_type
));
1396 static void fixup_mdeps
PARAMS ((fragS
*,
1401 static void fill_section
PARAMS ((bfd
* abfd
,
1406 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1411 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1412 symbolS
* symbol_rootP
));
1414 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1416 static void obj_coff_lcomm
PARAMS ((int));
1417 static void obj_coff_text
PARAMS ((int));
1418 static void obj_coff_data
PARAMS ((int));
1419 static void obj_coff_bss
PARAMS ((int));
1420 static void obj_coff_ident
PARAMS ((int));
1421 void obj_coff_section
PARAMS ((int));
1425 We allow more than just the standard 3 sections, infact, we allow
1426 10 sections, (though the usual three have to be there).
1428 This structure performs the mappings for us:
1439 static const seg_info_type seg_info_off_by_4
[N_SEG
] =
1470 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1472 static relax_addressT
1473 relax_align (address
, alignment
)
1474 relax_addressT address
;
1477 relax_addressT mask
;
1478 relax_addressT new_address
;
1480 mask
= ~((~0) << alignment
);
1481 new_address
= (address
+ mask
) & (~mask
);
1482 return (new_address
- address
);
1490 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1495 /* calculate the size of the frag chain and fill in the section header
1496 to contain all of it, also fill in the addr of the sections */
1498 size_section (abfd
, idx
)
1503 unsigned int size
= 0;
1504 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1507 size
= frag
->fr_address
;
1508 if (frag
->fr_address
!= size
)
1510 fprintf (stderr
, "Out of step\n");
1511 size
= frag
->fr_address
;
1514 switch (frag
->fr_type
)
1516 #ifdef TC_COFF_SIZEMACHDEP
1517 case rs_machine_dependent
:
1518 size
+= TC_COFF_SIZEMACHDEP (frag
);
1522 assert (frag
->fr_symbol
== 0);
1525 size
+= frag
->fr_fix
;
1526 size
+= frag
->fr_offset
* frag
->fr_var
;
1529 size
+= frag
->fr_fix
;
1530 size
+= relax_align (size
, frag
->fr_offset
);
1533 BAD_CASE (frag
->fr_type
);
1536 frag
= frag
->fr_next
;
1538 segment_info
[idx
].scnhdr
.s_size
= size
;
1544 count_entries_in_chain (idx
)
1547 unsigned int nrelocs
;
1550 /* Count the relocations */
1551 fixup_ptr
= segment_info
[idx
].fix_root
;
1553 while (fixup_ptr
!= (fixS
*) NULL
)
1555 if (TC_COUNT_RELOC (fixup_ptr
))
1558 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1567 fixup_ptr
= fixup_ptr
->fx_next
;
1572 /* output all the relocations for a section */
1574 do_relocs_for (abfd
, h
, file_cursor
)
1577 unsigned long *file_cursor
;
1579 unsigned int nrelocs
;
1581 unsigned long reloc_start
= *file_cursor
;
1583 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1585 if (segment_info
[idx
].scnhdr
.s_name
[0])
1587 struct external_reloc
*ext_ptr
;
1588 struct external_reloc
*external_reloc_vec
;
1589 unsigned int external_reloc_size
;
1590 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1591 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1592 nrelocs
= count_entries_in_chain (idx
);
1595 /* Bypass this stuff if no relocs. This also incidentally
1596 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1598 external_reloc_size
= nrelocs
* RELSZ
;
1599 external_reloc_vec
=
1600 (struct external_reloc
*) malloc (external_reloc_size
);
1602 ext_ptr
= external_reloc_vec
;
1604 /* Fill in the internal coff style reloc struct from the
1605 internal fix list. */
1608 struct internal_reloc intr
;
1610 /* Only output some of the relocations */
1611 if (TC_COUNT_RELOC (fix_ptr
))
1613 #ifdef TC_RELOC_MANGLE
1614 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1619 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1621 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1623 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1625 #ifdef TC_KEEP_FX_OFFSET
1626 intr
.r_offset
= fix_ptr
->fx_offset
;
1631 /* Turn the segment of the symbol into an offset. */
1634 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1637 intr
.r_symndx
= dot
->sy_number
;
1641 intr
.r_symndx
= symbol_ptr
->sy_number
;
1651 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1654 #if defined(TC_A29K)
1656 /* The 29k has a special kludge for the high 16 bit
1657 reloc. Two relocations are emited, R_IHIHALF,
1658 and R_IHCONST. The second one doesn't contain a
1659 symbol, but uses the value for offset. */
1661 if (intr
.r_type
== R_IHIHALF
)
1663 /* now emit the second bit */
1664 intr
.r_type
= R_IHCONST
;
1665 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1666 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1672 fix_ptr
= fix_ptr
->fx_next
;
1675 /* Write out the reloc table */
1676 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1678 free (external_reloc_vec
);
1680 /* Fill in section header info. */
1681 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1682 *file_cursor
+= external_reloc_size
;
1683 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1688 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1692 /* Set relocation_size field in file headers */
1693 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1697 /* run through a frag chain and write out the data to go with it, fill
1698 in the scnhdrs with the info on the file postions
1701 fill_section (abfd
, h
, file_cursor
)
1704 unsigned long *file_cursor
;
1708 unsigned int paddr
= 0;
1710 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1712 unsigned int offset
= 0;
1713 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1719 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1726 buffer
= xmalloc (s
->s_size
);
1727 s
->s_scnptr
= *file_cursor
;
1729 know (s
->s_paddr
== paddr
);
1731 if (strcmp (s
->s_name
, ".text") == 0)
1732 s
->s_flags
|= STYP_TEXT
;
1733 else if (strcmp (s
->s_name
, ".data") == 0)
1734 s
->s_flags
|= STYP_DATA
;
1735 else if (strcmp (s
->s_name
, ".bss") == 0)
1738 s
->s_flags
|= STYP_BSS
;
1740 /* @@ Should make the i386 and a29k coff targets define
1741 COFF_NOLOAD_PROBLEM, and have only one test here. */
1744 #ifndef COFF_NOLOAD_PROBLEM
1745 /* Apparently the SVR3 linker (and exec syscall) and UDI
1746 mondfe progrem are confused by noload sections. */
1747 s
->s_flags
|= STYP_NOLOAD
;
1752 else if (strcmp (s
->s_name
, ".lit") == 0)
1753 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1754 else if (strcmp (s
->s_name
, ".init") == 0)
1755 s
->s_flags
|= STYP_TEXT
;
1756 else if (strcmp (s
->s_name
, ".fini") == 0)
1757 s
->s_flags
|= STYP_TEXT
;
1758 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1759 s
->s_flags
|= STYP_INFO
;
1763 unsigned int fill_size
;
1764 switch (frag
->fr_type
)
1766 case rs_machine_dependent
:
1769 memcpy (buffer
+ frag
->fr_address
,
1771 (unsigned int) frag
->fr_fix
);
1772 offset
+= frag
->fr_fix
;
1777 assert (frag
->fr_symbol
== 0);
1783 memcpy (buffer
+ frag
->fr_address
,
1785 (unsigned int) frag
->fr_fix
);
1786 offset
+= frag
->fr_fix
;
1789 fill_size
= frag
->fr_var
;
1790 if (fill_size
&& frag
->fr_offset
> 0)
1793 unsigned int off
= frag
->fr_fix
;
1794 for (count
= frag
->fr_offset
; count
; count
--)
1796 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1798 memcpy (buffer
+ frag
->fr_address
+ off
,
1799 frag
->fr_literal
+ frag
->fr_fix
,
1802 offset
+= fill_size
;
1807 case rs_broken_word
:
1812 frag
= frag
->fr_next
;
1817 if (s
->s_scnptr
!= 0)
1819 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1820 *file_cursor
+= s
->s_size
;
1829 /* Coff file generation & utilities */
1832 coff_header_append (abfd
, h
)
1840 bfd_seek (abfd
, 0, 0);
1842 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1843 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1844 H_SET_VERSION_STAMP (h
, 0);
1845 H_SET_ENTRY_POINT (h
, 0);
1846 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1847 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1848 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1850 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1851 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1852 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1854 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1856 bfd_write (buffer
, i
, 1, abfd
);
1857 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1859 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1861 if (segment_info
[i
].scnhdr
.s_name
[0])
1864 bfd_coff_swap_scnhdr_out (abfd
,
1865 &(segment_info
[i
].scnhdr
),
1868 as_bad ("bfd_coff_swap_scnhdr_out failed");
1869 bfd_write (buffer
, size
, 1, abfd
);
1876 symbol_to_chars (abfd
, where
, symbolP
)
1881 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1885 /* Turn any symbols with register attributes into abs symbols */
1886 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1888 S_SET_SEGMENT (symbolP
, absolute_section
);
1890 /* At the same time, relocate all symbols to their output value */
1892 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1893 + S_GET_VALUE (symbolP
));
1895 S_SET_VALUE (symbolP
, val
);
1897 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1899 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1902 for (i
= 0; i
< numaux
; i
++)
1904 where
+= bfd_coff_swap_aux_out (abfd
,
1905 &symbolP
->sy_symbol
.ost_auxent
[i
],
1906 S_GET_DATA_TYPE (symbolP
),
1907 S_GET_STORAGE_CLASS (symbolP
),
1915 obj_symbol_new_hook (symbolP
)
1918 char underscore
= 0; /* Symbol has leading _ */
1920 /* Effective symbol */
1921 /* Store the pointer in the offset. */
1922 S_SET_ZEROES (symbolP
, 0L);
1923 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1924 S_SET_STORAGE_CLASS (symbolP
, 0);
1925 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1926 /* Additional information */
1927 symbolP
->sy_symbol
.ost_flags
= 0;
1928 /* Auxiliary entries */
1929 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1931 if (S_IS_STRING (symbolP
))
1932 SF_SET_STRING (symbolP
);
1933 if (!underscore
&& S_IS_LOCAL (symbolP
))
1934 SF_SET_LOCAL (symbolP
);
1938 * Handle .ln directives.
1942 obj_coff_ln (appline
)
1947 if (! appline
&& def_symbol_in_progress
!= NULL
)
1949 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1950 demand_empty_rest_of_line ();
1952 } /* wrong context */
1954 l
= get_absolute_expression ();
1955 c_line_new (0, frag_now_fix (), l
, frag_now
);
1964 listing_source_line ((unsigned int) l
);
1969 demand_empty_rest_of_line ();
1975 * Handle .def directives.
1977 * One might ask : why can't we symbol_new if the symbol does not
1978 * already exist and fill it with debug information. Because of
1979 * the C_EFCN special symbol. It would clobber the value of the
1980 * function symbol before we have a chance to notice that it is
1981 * a C_EFCN. And a second reason is that the code is more clear this
1982 * way. (at least I think it is :-).
1986 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1987 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1988 *input_line_pointer == '\t') \
1989 input_line_pointer++;
1995 char name_end
; /* Char after the end of name */
1996 char *symbol_name
; /* Name of the debug symbol */
1997 char *symbol_name_copy
; /* Temporary copy of the name */
1998 unsigned int symbol_name_length
;
2000 if (def_symbol_in_progress
!= NULL
)
2002 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2003 demand_empty_rest_of_line ();
2005 } /* if not inside .def/.endef */
2007 SKIP_WHITESPACES ();
2009 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2010 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2012 symbol_name
= input_line_pointer
;
2013 name_end
= get_symbol_end ();
2014 symbol_name_length
= strlen (symbol_name
);
2015 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2016 strcpy (symbol_name_copy
, symbol_name
);
2018 /* Initialize the new symbol */
2019 #ifdef STRIP_UNDERSCORE
2020 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2021 ? symbol_name_copy
+ 1
2022 : symbol_name_copy
));
2023 #else /* STRIP_UNDERSCORE */
2024 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2025 #endif /* STRIP_UNDERSCORE */
2026 /* free(symbol_name_copy); */
2027 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2028 def_symbol_in_progress
->sy_number
= ~0;
2029 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2030 S_SET_VALUE (def_symbol_in_progress
, 0);
2032 if (S_IS_STRING (def_symbol_in_progress
))
2033 SF_SET_STRING (def_symbol_in_progress
);
2035 *input_line_pointer
= name_end
;
2037 demand_empty_rest_of_line ();
2040 unsigned int dim_index
;
2044 obj_coff_endef (ignore
)
2047 symbolS
*symbolP
= 0;
2048 /* DIM BUG FIX sac@cygnus.com */
2050 if (def_symbol_in_progress
== NULL
)
2052 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2053 demand_empty_rest_of_line ();
2055 } /* if not inside .def/.endef */
2057 /* Set the section number according to storage class. */
2058 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2063 SF_SET_TAG (def_symbol_in_progress
);
2064 /* intentional fallthrough */
2067 SF_SET_DEBUG (def_symbol_in_progress
);
2068 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2072 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2073 /* intentional fallthrough */
2075 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2076 /* intentional fallthrough */
2078 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2080 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2082 if (function_lineoff
< 0)
2084 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2085 } /* missing function symbol */
2086 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2088 SF_SET_PROCESS (last_line_symbol
);
2089 function_lineoff
= -1;
2091 /* Value is always set to . */
2092 def_symbol_in_progress
->sy_frag
= frag_now
;
2093 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2098 #endif /* C_AUTOARG */
2108 SF_SET_DEBUG (def_symbol_in_progress
);
2109 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2115 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2121 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2123 } /* switch on storage class */
2125 /* Now that we have built a debug symbol, try to find if we should
2126 merge with an existing symbol or not. If a symbol is C_EFCN or
2127 absolute_section or untagged SEG_DEBUG it never merges. We also
2128 don't merge labels, which are in a different namespace, nor
2129 symbols which have not yet been defined since they are typically
2130 unique, nor do we merge tags with non-tags. */
2132 /* Two cases for functions. Either debug followed by definition or
2133 definition followed by debug. For definition first, we will
2134 merge the debug symbol into the definition. For debug first, the
2135 lineno entry MUST point to the definition function or else it
2136 will point off into space when crawl_symbols() merges the debug
2137 symbol into the real symbol. Therefor, let's presume the debug
2138 symbol is a real function reference. */
2140 /* FIXME-SOON If for some reason the definition label/symbol is
2141 never seen, this will probably leave an undefined symbol at link
2144 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2145 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2146 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2147 && !SF_GET_TAG (def_symbol_in_progress
))
2148 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2149 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2150 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2151 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2153 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2158 /* This symbol already exists, merge the newly created symbol
2159 into the old one. This is not mandatory. The linker can
2160 handle duplicate symbols correctly. But I guess that it save
2161 a *lot* of space if the assembly file defines a lot of
2164 /* The debug entry (def_symbol_in_progress) is merged into the
2165 previous definition. */
2167 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2168 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2169 def_symbol_in_progress
= symbolP
;
2171 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2172 || SF_GET_TAG (def_symbol_in_progress
))
2174 /* For functions, and tags, the symbol *must* be where the
2175 debug symbol appears. Move the existing symbol to the
2177 /* If it already is at the end of the symbol list, do nothing */
2178 if (def_symbol_in_progress
!= symbol_lastP
)
2180 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2182 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2183 &symbol_rootP
, &symbol_lastP
);
2184 } /* if not already in place */
2186 } /* normal or mergable */
2188 if (SF_GET_TAG (def_symbol_in_progress
)
2189 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2191 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2194 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2196 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2198 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2200 SF_SET_PROCESS (def_symbol_in_progress
);
2202 if (symbolP
== NULL
)
2204 /* That is, if this is the first time we've seen the
2206 symbol_table_insert (def_symbol_in_progress
);
2207 } /* definition follows debug */
2208 } /* Create the line number entry pointing to the function being defined */
2210 def_symbol_in_progress
= NULL
;
2211 demand_empty_rest_of_line ();
2215 obj_coff_dim (ignore
)
2220 if (def_symbol_in_progress
== NULL
)
2222 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2223 demand_empty_rest_of_line ();
2225 } /* if not inside .def/.endef */
2227 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2229 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2231 SKIP_WHITESPACES ();
2232 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2233 get_absolute_expression ());
2235 switch (*input_line_pointer
)
2238 input_line_pointer
++;
2242 as_warn ("badly formed .dim directive ignored");
2243 /* intentional fallthrough */
2251 demand_empty_rest_of_line ();
2255 obj_coff_line (ignore
)
2261 if (def_symbol_in_progress
== NULL
)
2267 name
= S_GET_NAME (def_symbol_in_progress
);
2268 this_base
= get_absolute_expression ();
2270 /* Only .bf symbols indicate the use of a new base line number; the
2271 line numbers associated with .ef, .bb, .eb are relative to the
2272 start of the containing function. */
2273 if (!strcmp (".bf", name
))
2275 #if 0 /* XXX Can we ever have line numbers going backwards? */
2276 if (this_base
> line_base
)
2279 line_base
= this_base
;
2287 listing_source_line ((unsigned int) line_base
);
2293 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2294 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2296 demand_empty_rest_of_line ();
2300 obj_coff_size (ignore
)
2303 if (def_symbol_in_progress
== NULL
)
2305 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2306 demand_empty_rest_of_line ();
2308 } /* if not inside .def/.endef */
2310 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2311 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2312 demand_empty_rest_of_line ();
2316 obj_coff_scl (ignore
)
2319 if (def_symbol_in_progress
== NULL
)
2321 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2322 demand_empty_rest_of_line ();
2324 } /* if not inside .def/.endef */
2326 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2327 demand_empty_rest_of_line ();
2331 obj_coff_tag (ignore
)
2337 if (def_symbol_in_progress
== NULL
)
2339 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2340 demand_empty_rest_of_line ();
2344 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2345 symbol_name
= input_line_pointer
;
2346 name_end
= get_symbol_end ();
2348 /* Assume that the symbol referred to by .tag is always defined.
2349 This was a bad assumption. I've added find_or_make. xoxorich. */
2350 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2351 (long) tag_find_or_make (symbol_name
));
2352 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2354 as_warn ("tag not found for .tag %s", symbol_name
);
2357 SF_SET_TAGGED (def_symbol_in_progress
);
2358 *input_line_pointer
= name_end
;
2360 demand_empty_rest_of_line ();
2364 obj_coff_type (ignore
)
2367 if (def_symbol_in_progress
== NULL
)
2369 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2370 demand_empty_rest_of_line ();
2372 } /* if not inside .def/.endef */
2374 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2376 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2377 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2379 SF_SET_FUNCTION (def_symbol_in_progress
);
2380 } /* is a function */
2382 demand_empty_rest_of_line ();
2386 obj_coff_val (ignore
)
2389 if (def_symbol_in_progress
== NULL
)
2391 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2392 demand_empty_rest_of_line ();
2394 } /* if not inside .def/.endef */
2396 if (is_name_beginner (*input_line_pointer
))
2398 char *symbol_name
= input_line_pointer
;
2399 char name_end
= get_symbol_end ();
2401 if (!strcmp (symbol_name
, "."))
2403 def_symbol_in_progress
->sy_frag
= frag_now
;
2404 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2405 /* If the .val is != from the .def (e.g. statics) */
2407 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2409 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2410 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2411 symbol_find_or_make (symbol_name
);
2412 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2413 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2415 /* If the segment is undefined when the forward reference is
2416 resolved, then copy the segment id from the forward
2418 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2420 /* FIXME: gcc can generate address expressions
2421 here in unusual cases (search for "obscure"
2422 in sdbout.c). We just ignore the offset
2423 here, thus generating incorrect debugging
2424 information. We ignore the rest of the
2427 /* Otherwise, it is the name of a non debug symbol and
2428 its value will be calculated later. */
2429 *input_line_pointer
= name_end
;
2431 /* FIXME: this is to avoid an error message in the
2432 FIXME case mentioned just above. */
2433 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2434 ++input_line_pointer
;
2438 S_SET_VALUE (def_symbol_in_progress
,
2439 (valueT
) get_absolute_expression ());
2440 } /* if symbol based */
2442 demand_empty_rest_of_line ();
2446 obj_read_begin_hook ()
2448 /* These had better be the same. Usually 18 bytes. */
2450 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2451 know (SYMESZ
== AUXESZ
);
2456 /* This function runs through the symbol table and puts all the
2457 externals onto another chain */
2459 /* The chain of globals. */
2460 symbolS
*symbol_globalP
;
2461 symbolS
*symbol_global_lastP
;
2463 /* The chain of externals */
2464 symbolS
*symbol_externP
;
2465 symbolS
*symbol_extern_lastP
;
2468 symbolS
*last_functionP
;
2475 unsigned int symbol_number
= 0;
2476 unsigned int last_file_symno
= 0;
2478 struct filename_list
*filename_list_scan
= filename_list_head
;
2480 for (symbolP
= symbol_rootP
;
2482 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2484 if (!SF_GET_DEBUG (symbolP
))
2486 /* Debug symbols do not need all this rubbish */
2487 symbolS
*real_symbolP
;
2489 /* L* and C_EFCN symbols never merge. */
2490 if (!SF_GET_LOCAL (symbolP
)
2491 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2492 && symbolP
->sy_value
.X_op
== O_constant
2493 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2494 && real_symbolP
!= symbolP
)
2496 /* FIXME-SOON: where do dups come from?
2497 Maybe tag references before definitions? xoxorich. */
2498 /* Move the debug data from the debug symbol to the
2499 real symbol. Do NOT do the oposite (i.e. move from
2500 real symbol to debug symbol and remove real symbol from the
2501 list.) Because some pointers refer to the real symbol
2502 whereas no pointers refer to the debug symbol. */
2503 c_symbol_merge (symbolP
, real_symbolP
);
2504 /* Replace the current symbol by the real one */
2505 /* The symbols will never be the last or the first
2506 because : 1st symbol is .file and 3 last symbols are
2507 .text, .data, .bss */
2508 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2509 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2510 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2511 symbolP
= real_symbolP
;
2512 } /* if not local but dup'd */
2514 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2516 S_SET_SEGMENT (symbolP
, SEG_E0
);
2517 } /* push data into text */
2519 resolve_symbol_value (symbolP
);
2521 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2523 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2525 S_SET_EXTERNAL (symbolP
);
2527 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2529 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2533 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2537 /* Mainly to speed up if not -g */
2538 if (SF_GET_PROCESS (symbolP
))
2540 /* Handle the nested blocks auxiliary info. */
2541 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2543 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2544 stack_push (block_stack
, (char *) &symbolP
);
2547 register symbolS
*begin_symbolP
;
2548 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2549 if (begin_symbolP
== (symbolS
*) 0)
2550 as_warn ("mismatched .eb");
2552 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2555 /* If we are able to identify the type of a function, and we
2556 are out of a function (last_functionP == 0) then, the
2557 function symbol will be associated with an auxiliary
2559 if (last_functionP
== (symbolS
*) 0 &&
2560 SF_GET_FUNCTION (symbolP
))
2562 last_functionP
= symbolP
;
2564 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2566 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2567 } /* make it at least 1 */
2569 /* Clobber possible stale .dim information. */
2571 /* Iffed out by steve - this fries the lnnoptr info too */
2572 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2573 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2576 /* The C_FCN doesn't need any additional information. I
2577 don't even know if this is needed for sdb. But the
2578 standard assembler generates it, so... */
2579 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2581 if (last_functionP
== (symbolS
*) 0)
2582 as_fatal ("C_EFCN symbol out of scope");
2583 SA_SET_SYM_FSIZE (last_functionP
,
2584 (long) (S_GET_VALUE (symbolP
) -
2585 S_GET_VALUE (last_functionP
)));
2586 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2587 last_functionP
= (symbolS
*) 0;
2591 else if (SF_GET_TAG (symbolP
))
2593 /* First descriptor of a structure must point to
2594 the first slot after the structure description. */
2595 last_tagP
= symbolP
;
2598 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2600 /* +2 take in account the current symbol */
2601 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2603 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2605 /* If the filename was too long to fit in the
2606 auxent, put it in the string table */
2607 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2609 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2610 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2611 filename_list_scan
= filename_list_scan
->next
;
2613 if (S_GET_VALUE (symbolP
))
2615 S_SET_VALUE (symbolP
, last_file_symno
);
2616 last_file_symno
= symbol_number
;
2617 } /* no one points at the first .file symbol */
2618 } /* if debug or tag or eos or file */
2620 /* We must put the external symbols apart. The loader
2621 does not bomb if we do not. But the references in
2622 the endndx field for a .bb symbol are not corrected
2623 if an external symbol is removed between .bb and .be.
2624 I.e in the following case :
2625 [20] .bb endndx = 22
2628 ld will move the symbol 21 to the end of the list but
2629 endndx will still be 22 instead of 21. */
2632 if (SF_GET_LOCAL (symbolP
))
2634 /* remove C_EFCN and LOCAL (L...) symbols */
2635 /* next pointer remains valid */
2636 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2639 else if (!S_IS_DEFINED (symbolP
)
2640 && !S_IS_DEBUG (symbolP
)
2641 && !SF_GET_STATICS (symbolP
) &&
2642 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2643 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2644 /* if external, Remove from the list */
2645 symbolS
*hold
= symbol_previous (symbolP
);
2647 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2648 symbol_clear_list_pointers (symbolP
);
2649 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2652 else if (! S_IS_DEBUG (symbolP
)
2653 && ! SF_GET_STATICS (symbolP
)
2654 && ! SF_GET_FUNCTION (symbolP
)
2655 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2657 symbolS
*hold
= symbol_previous (symbolP
);
2659 /* The O'Reilly COFF book says that defined global symbols
2660 come at the end of the symbol table, just before
2661 undefined global symbols. */
2663 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2664 symbol_clear_list_pointers (symbolP
);
2665 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2666 &symbol_global_lastP
);
2671 if (SF_GET_STRING (symbolP
))
2673 symbolP
->sy_name_offset
= string_byte_count
;
2674 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2678 symbolP
->sy_name_offset
= 0;
2679 } /* fix "long" names */
2681 symbolP
->sy_number
= symbol_number
;
2682 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2683 } /* if local symbol */
2684 } /* traverse the symbol list */
2685 return symbol_number
;
2691 glue_symbols (head
, tail
)
2695 unsigned int symbol_number
= 0;
2698 for (symbolP
= *head
; *head
!= NULL
;)
2700 symbolS
*tmp
= *head
;
2703 symbol_remove (tmp
, head
, tail
);
2704 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2707 if (SF_GET_STRING (tmp
))
2709 tmp
->sy_name_offset
= string_byte_count
;
2710 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2714 tmp
->sy_name_offset
= 0;
2715 } /* fix "long" names */
2717 tmp
->sy_number
= symbol_number
;
2718 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2719 } /* append the entire extern chain */
2721 return symbol_number
;
2727 unsigned int symbol_number
= 0;
2730 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2731 symbol_next (symbolP
))
2733 symbolP
->sy_number
= symbol_number
;
2737 if (SF_GET_TAGGED (symbolP
))
2741 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2744 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2746 return symbol_number
;
2751 crawl_symbols (h
, abfd
)
2757 /* Initialize the stack used to keep track of the matching .bb .be */
2759 block_stack
= stack_init (512, sizeof (symbolS
*));
2761 /* The symbol list should be ordered according to the following sequence
2764 * . debug entries for functions
2765 * . fake symbols for the sections, including.text .data and .bss
2767 * . undefined symbols
2768 * But this is not mandatory. The only important point is to put the
2769 * undefined symbols at the end of the list.
2772 if (symbol_rootP
== NULL
2773 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2775 c_dot_file_symbol ("fake");
2777 /* Is there a .file symbol ? If not insert one at the beginning. */
2780 * Build up static symbols for the sections, they are filled in later
2784 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2786 if (segment_info
[i
].scnhdr
.s_name
[0])
2790 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2792 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2797 /* Take all the externals out and put them into another chain */
2798 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2799 /* Take the externals and glue them onto the end.*/
2800 H_SET_SYMBOL_TABLE_SIZE (h
,
2801 (H_GET_SYMBOL_COUNT (h
)
2802 + glue_symbols (&symbol_globalP
,
2803 &symbol_global_lastP
)
2804 + glue_symbols (&symbol_externP
,
2805 &symbol_extern_lastP
)));
2807 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2808 know (symbol_globalP
== NULL
);
2809 know (symbol_global_lastP
== NULL
);
2810 know (symbol_externP
== NULL
);
2811 know (symbol_extern_lastP
== NULL
);
2815 * Find strings by crawling along symbol table chain.
2823 struct filename_list
*filename_list_scan
= filename_list_head
;
2825 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2826 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2828 for (symbolP
= symbol_rootP
;
2830 symbolP
= symbol_next (symbolP
))
2834 if (SF_GET_STRING (symbolP
))
2836 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2837 memcpy (where
, S_GET_NAME (symbolP
), size
);
2840 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2841 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2843 size
= strlen (filename_list_scan
->filename
) + 1;
2844 memcpy (where
, filename_list_scan
->filename
, size
);
2845 filename_list_scan
= filename_list_scan
->next
;
2852 do_linenos_for (abfd
, h
, file_cursor
)
2855 unsigned long *file_cursor
;
2858 unsigned long start
= *file_cursor
;
2860 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2862 segment_info_type
*s
= segment_info
+ idx
;
2865 if (s
->scnhdr
.s_nlnno
!= 0)
2867 struct lineno_list
*line_ptr
;
2869 struct external_lineno
*buffer
=
2870 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2872 struct external_lineno
*dst
= buffer
;
2874 /* Run through the table we've built and turn it into its external
2875 form, take this chance to remove duplicates */
2877 for (line_ptr
= s
->lineno_list_head
;
2878 line_ptr
!= (struct lineno_list
*) NULL
;
2879 line_ptr
= line_ptr
->next
)
2882 if (line_ptr
->line
.l_lnno
== 0)
2884 /* Turn a pointer to a symbol into the symbols' index */
2885 line_ptr
->line
.l_addr
.l_symndx
=
2886 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2890 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2894 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2899 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2901 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2904 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2907 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2911 /* Now we run through the list of frag chains in a segment and
2912 make all the subsegment frags appear at the end of the
2913 list, as if the seg 0 was extra long */
2920 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2922 frchainS
*head
= segment_info
[i
].frchainP
;
2924 fragS
*prev_frag
= &dummy
;
2926 while (head
&& head
->frch_seg
== i
)
2928 prev_frag
->fr_next
= head
->frch_root
;
2929 prev_frag
= head
->frch_last
;
2930 head
= head
->frch_next
;
2932 prev_frag
->fr_next
= 0;
2936 unsigned long machine
;
2939 write_object_file ()
2943 struct frchain
*frchain_ptr
;
2945 object_headers headers
;
2946 unsigned long file_cursor
;
2949 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
2954 as_perror ("FATAL: Can't create %s", out_file_name
);
2955 exit (EXIT_FAILURE
);
2957 bfd_set_format (abfd
, bfd_object
);
2958 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
2960 string_byte_count
= 4;
2962 for (frchain_ptr
= frchain_root
;
2963 frchain_ptr
!= (struct frchain
*) NULL
;
2964 frchain_ptr
= frchain_ptr
->frch_next
)
2966 /* Run through all the sub-segments and align them up. Also
2967 close any open frags. We tack a .fill onto the end of the
2968 frag chain so that any .align's size can be worked by looking
2969 at the next frag. */
2971 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
2972 #ifndef SUB_SEGMENT_ALIGN
2973 #define SUB_SEGMENT_ALIGN(SEG) 1
2975 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
2976 frag_wane (frag_now
);
2977 frag_now
->fr_fix
= 0;
2978 know (frag_now
->fr_next
== NULL
);
2985 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2987 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
2990 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
2992 /* Find out how big the sections are, and set the addresses. */
2994 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2998 segment_info
[i
].scnhdr
.s_paddr
= addr
;
2999 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3001 if (segment_info
[i
].scnhdr
.s_name
[0])
3003 H_SET_NUMBER_OF_SECTIONS (&headers
,
3004 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3007 size
= size_section (abfd
, (unsigned int) i
);
3010 /* I think the section alignment is only used on the i960; the
3011 i960 needs it, and it should do no harm on other targets. */
3012 segment_info
[i
].scnhdr
.s_align
= section_alignment
[i
];
3015 H_SET_TEXT_SIZE (&headers
, size
);
3016 else if (i
== SEG_E1
)
3017 H_SET_DATA_SIZE (&headers
, size
);
3018 else if (i
== SEG_E2
)
3019 H_SET_BSS_SIZE (&headers
, size
);
3022 /* Turn the gas native symbol table shape into a coff symbol table */
3023 crawl_symbols (&headers
, abfd
);
3025 if (string_byte_count
== 4)
3026 string_byte_count
= 0;
3028 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3034 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3036 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3037 fixup_segment (&segment_info
[i
], i
);
3040 /* Look for ".stab" segments and fill in their initial symbols
3042 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3044 name
= segment_info
[i
].scnhdr
.s_name
;
3047 && strncmp (".stab", name
, 5) == 0
3048 && strncmp (".stabstr", name
, 8) != 0)
3049 adjust_stab_section (abfd
, i
);
3052 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3054 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3056 /* Plant the data */
3058 fill_section (abfd
, &headers
, &file_cursor
);
3060 do_relocs_for (abfd
, &headers
, &file_cursor
);
3062 do_linenos_for (abfd
, &headers
, &file_cursor
);
3064 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3065 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3066 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3068 H_SET_TIME_STAMP (&headers
, 0);
3070 #ifdef TC_COFF_SET_MACHINE
3071 TC_COFF_SET_MACHINE (&headers
);
3075 #define COFF_FLAGS 0
3078 #ifdef KEEP_RELOC_INFO
3079 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3080 COFF_FLAGS
| coff_flags
));
3082 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3083 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3084 COFF_FLAGS
| coff_flags
));
3088 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3089 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3091 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3092 w_symbols (abfd
, buffer1
, symbol_rootP
);
3093 if (string_byte_count
> 0)
3094 w_strings (buffer1
+ symtable_size
);
3095 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3099 coff_header_append (abfd
, &headers
);
3101 /* Recent changes to write need this, but where it should
3102 go is up to Ken.. */
3103 if (bfd_close_all_done (abfd
) == false)
3104 as_fatal ("Can't close %s: %s", out_file_name
,
3105 bfd_errmsg (bfd_get_error ()));
3108 extern bfd
*stdoutput
;
3115 /* Add a new segment. This is called from subseg_new via the
3116 obj_new_segment macro. */
3119 obj_coff_add_segment (name
)
3125 /* Find out if we've already got a section of this name. */
3126 len
= strlen (name
);
3127 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3130 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3131 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3132 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3133 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3134 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3139 as_bad ("Too many new sections; can't add \"%s\"", name
);
3143 /* Add a new section. */
3144 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3145 sizeof (segment_info
[i
].scnhdr
.s_name
));
3146 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3152 * implement the .section pseudo op:
3153 * .section name {, "flags"}
3155 * | +--- optional flags: 'b' for bss
3157 * +-- section name 'l' for lib
3161 * 'd' (apparently m88k for data)
3163 * But if the argument is not a quoted string, treat it as a
3164 * subsegment number.
3168 obj_coff_section (ignore
)
3171 /* Strip out the section name */
3173 char *section_name_end
;
3180 section_name
= input_line_pointer
;
3181 c
= get_symbol_end ();
3182 section_name_end
= input_line_pointer
;
3184 len
= section_name_end
- section_name
;
3185 input_line_pointer
++;
3191 else if (*input_line_pointer
== ',')
3194 ++input_line_pointer
;
3202 if (*input_line_pointer
!= '"')
3203 exp
= get_absolute_expression ();
3206 ++input_line_pointer
;
3207 while (*input_line_pointer
!= '"'
3208 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3210 switch (*input_line_pointer
)
3212 case 'b': flags
|= STYP_BSS
; break;
3213 case 'i': flags
|= STYP_INFO
; break;
3214 case 'l': flags
|= STYP_LIB
; break;
3215 case 'n': flags
|= STYP_NOLOAD
; break;
3216 case 'o': flags
|= STYP_OVER
; break;
3218 case 'w': flags
|= STYP_DATA
; break;
3219 case 'x': flags
|= STYP_TEXT
; break;
3221 as_warn("unknown section attribute '%c'",
3222 *input_line_pointer
);
3225 ++input_line_pointer
;
3227 if (*input_line_pointer
== '"')
3228 ++input_line_pointer
;
3232 subseg_new (section_name
, (subsegT
) exp
);
3234 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3236 *section_name_end
= c
;
3241 obj_coff_text (ignore
)
3244 subseg_new (".text", get_absolute_expression ());
3249 obj_coff_data (ignore
)
3252 if (flag_readonly_data_in_text
)
3253 subseg_new (".text", get_absolute_expression () + 1000);
3255 subseg_new (".data", get_absolute_expression ());
3259 obj_coff_bss (ignore
)
3262 if (*input_line_pointer
== '\n') /* .bss */
3263 subseg_new(".bss", get_absolute_expression());
3264 else /* .bss id,expr */
3269 obj_coff_ident (ignore
)
3272 segT current_seg
= now_seg
; /* save current seg */
3273 subsegT current_subseg
= now_subseg
;
3274 subseg_new (".comment", 0); /* .comment seg */
3275 stringer (1); /* read string */
3276 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3280 c_symbol_merge (debug
, normal
)
3284 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3285 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3287 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3289 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3290 } /* take the most we have */
3292 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3294 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3295 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3296 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3297 } /* Move all the auxiliary information */
3299 /* Move the debug flags. */
3300 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3301 } /* c_symbol_merge() */
3304 c_line_new (symbol
, paddr
, line_number
, frag
)
3310 struct lineno_list
*new_line
=
3311 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3313 segment_info_type
*s
= segment_info
+ now_seg
;
3314 new_line
->line
.l_lnno
= line_number
;
3316 if (line_number
== 0)
3318 last_line_symbol
= symbol
;
3319 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3323 new_line
->line
.l_addr
.l_paddr
= paddr
;
3326 new_line
->frag
= (char *) frag
;
3327 new_line
->next
= (struct lineno_list
*) NULL
;
3330 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3332 s
->lineno_list_head
= new_line
;
3336 s
->lineno_list_tail
->next
= new_line
;
3338 s
->lineno_list_tail
= new_line
;
3339 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3343 c_dot_file_symbol (filename
)
3348 symbolP
= symbol_new (".file",
3351 &zero_address_frag
);
3353 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3354 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3356 if (strlen (filename
) > FILNMLEN
)
3358 /* Filename is too long to fit into an auxent,
3359 we stick it into the string table instead. We keep
3360 a linked list of the filenames we find so we can emit
3362 struct filename_list
*f
= xmalloc (sizeof (struct filename_list
));
3364 f
->filename
= filename
;
3367 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3368 SA_SET_FILE_FNAME_OFFSET (symbolP
, 0);
3370 if (filename_list_tail
)
3371 filename_list_tail
->next
= f
;
3373 filename_list_head
= f
;
3374 filename_list_tail
= f
;
3378 SA_SET_FILE_FNAME (symbolP
, filename
);
3385 listing_source_file (filename
);
3391 SF_SET_DEBUG (symbolP
);
3392 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3394 previous_file_symbol
= symbolP
;
3396 /* Make sure that the symbol is first on the symbol chain */
3397 if (symbol_rootP
!= symbolP
)
3399 if (symbolP
== symbol_lastP
)
3401 symbol_lastP
= symbol_lastP
->sy_previous
;
3402 } /* if it was the last thing on the list */
3404 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3405 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3406 symbol_rootP
= symbolP
;
3407 } /* if not first on the list */
3409 } /* c_dot_file_symbol() */
3412 * Build a 'section static' symbol.
3416 c_section_symbol (name
, idx
)
3422 symbolP
= symbol_new (name
, idx
,
3424 &zero_address_frag
);
3426 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3427 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3429 SF_SET_STATICS (symbolP
);
3432 } /* c_section_symbol() */
3435 w_symbols (abfd
, where
, symbol_rootP
)
3438 symbolS
* symbol_rootP
;
3443 /* First fill in those values we have only just worked out */
3444 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3446 symbolP
= segment_info
[i
].dot
;
3449 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3450 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3451 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3456 * Emit all symbols left in the symbol chain.
3458 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3460 /* Used to save the offset of the name. It is used to point
3461 to the string in memory but must be a file offset. */
3462 register char *temp
;
3464 tc_coff_symbol_emit_hook (symbolP
);
3466 temp
= S_GET_NAME (symbolP
);
3467 if (SF_GET_STRING (symbolP
))
3469 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3470 S_SET_ZEROES (symbolP
, 0);
3474 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3475 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3477 where
= symbol_to_chars (abfd
, where
, symbolP
);
3478 S_SET_NAME (symbolP
, temp
);
3484 obj_coff_lcomm (ignore
)
3497 name
= input_line_pointer
;
3499 c
= get_symbol_end ();
3500 p
= input_line_pointer
;
3503 if (*input_line_pointer
!= ',')
3505 as_bad ("Expected comma after name");
3506 ignore_rest_of_line ();
3509 if (*input_line_pointer
== '\n')
3511 as_bad ("Missing size expression");
3514 input_line_pointer
++;
3515 if ((temp
= get_absolute_expression ()) < 0)
3517 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3518 ignore_rest_of_line ();
3523 symbolP
= symbol_find_or_make(name
);
3525 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3526 S_GET_VALUE(symbolP
) == 0)
3531 segT current_seg
= now_seg
; /* save current seg */
3532 subsegT current_subseg
= now_subseg
;
3534 subseg_set (SEG_E2
, 1);
3535 symbolP
->sy_frag
= frag_now
;
3536 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3539 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3540 S_SET_SEGMENT(symbolP
, SEG_E2
);
3541 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3545 as_bad("Symbol %s already defined", name
);
3547 demand_empty_rest_of_line();
3552 fixup_mdeps (frags
, h
, this_segment
)
3557 subseg_change (this_segment
, 0);
3560 switch (frags
->fr_type
)
3565 HANDLE_ALIGN (frags
);
3567 frags
->fr_type
= rs_fill
;
3569 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3571 case rs_machine_dependent
:
3572 md_convert_frag (h
, this_segment
, frags
);
3578 frags
= frags
->fr_next
;
3584 #ifndef TC_FORCE_RELOCATION
3585 #define TC_FORCE_RELOCATION(fix) 0
3589 fixup_segment (segP
, this_segment_type
)
3590 segment_info_type
* segP
;
3591 segT this_segment_type
;
3593 register fixS
* fixP
;
3594 register symbolS
*add_symbolP
;
3595 register symbolS
*sub_symbolP
;
3596 register long add_number
;
3598 register char *place
;
3599 register long where
;
3600 register char pcrel
;
3601 register fragS
*fragP
;
3602 register segT add_symbol_segment
= absolute_section
;
3607 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3609 fragP
= fixP
->fx_frag
;
3611 where
= fixP
->fx_where
;
3612 place
= fragP
->fr_literal
+ where
;
3613 size
= fixP
->fx_size
;
3614 add_symbolP
= fixP
->fx_addsy
;
3616 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3618 /* Relocation should be done via the associated 'bal' entry
3621 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3623 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3624 "No 'bal' entry point for leafproc %s",
3625 S_GET_NAME (add_symbolP
));
3628 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3631 sub_symbolP
= fixP
->fx_subsy
;
3632 add_number
= fixP
->fx_offset
;
3633 pcrel
= fixP
->fx_pcrel
;
3637 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3638 } /* if there is an addend */
3645 if (S_GET_SEGMENT (sub_symbolP
) != absolute_section
)
3647 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3648 "Negative of non-absolute symbol %s",
3649 S_GET_NAME (sub_symbolP
));
3650 } /* not absolute */
3652 add_number
-= S_GET_VALUE (sub_symbolP
);
3655 /* if sub_symbol is in the same segment that add_symbol
3656 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3658 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
3659 && (SEG_NORMAL (add_symbol_segment
)
3660 || (add_symbol_segment
== absolute_section
)))
3662 /* Difference of 2 symbols from same segment. Can't
3663 make difference of 2 undefineds: 'value' means
3664 something different for N_UNDF. */
3666 /* Makes no sense to use the difference of 2 arbitrary symbols
3667 as the target of a call instruction. */
3670 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3671 "callj to difference of 2 symbols");
3673 #endif /* TC_I960 */
3674 add_number
+= S_GET_VALUE (add_symbolP
) -
3675 S_GET_VALUE (sub_symbolP
);
3678 if (!TC_FORCE_RELOCATION (fixP
))
3680 fixP
->fx_addsy
= NULL
;
3681 fixP
->fx_subsy
= NULL
;
3687 /* Different segments in subtraction. */
3688 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3690 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3692 add_number
-= S_GET_VALUE (sub_symbolP
);
3695 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3696 #if 0 /* Okay for 68k, at least... */
3701 /* Make it pc-relative. */
3702 add_number
+= (md_pcrel_from (fixP
)
3703 - S_GET_VALUE (sub_symbolP
));
3712 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3713 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3714 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3715 S_GET_NAME (sub_symbolP
),
3716 (long) (fragP
->fr_address
+ where
));
3719 } /* if sub_symbolP */
3723 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3726 * This fixup was made when the symbol's segment was
3727 * SEG_UNKNOWN, but it is now in the local segment.
3728 * So we know how to do the address without relocation.
3731 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3732 * in which cases it modifies *fixP as appropriate. In the case
3733 * of a 'calls', no further work is required, and *fixP has been
3734 * set up to make the rest of the code below a no-op.
3737 #endif /* TC_I960 */
3739 add_number
+= S_GET_VALUE (add_symbolP
);
3740 add_number
-= md_pcrel_from (fixP
);
3741 #if defined (TC_I386) || defined (TE_LYNX)
3742 /* On the 386 we must adjust by the segment
3743 vaddr as well. Ian Taylor. */
3744 add_number
-= segP
->scnhdr
.s_vaddr
;
3746 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3747 if (!TC_FORCE_RELOCATION (fixP
))
3749 fixP
->fx_addsy
= NULL
;
3755 switch (add_symbol_segment
)
3757 case absolute_section
:
3759 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3760 #endif /* TC_I960 */
3761 add_number
+= S_GET_VALUE (add_symbolP
);
3764 if (!TC_FORCE_RELOCATION (fixP
))
3766 fixP
->fx_addsy
= NULL
;
3773 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386))
3774 /* This really should be handled in the linker, but
3775 backward compatibility forbids. */
3776 add_number
+= S_GET_VALUE (add_symbolP
);
3778 add_number
+= S_GET_VALUE (add_symbolP
) +
3779 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3785 if ((int) fixP
->fx_bit_fixP
== 13)
3787 /* This is a COBR instruction. They have only a
3788 * 13-bit displacement and are only to be used
3789 * for local branches: flag as error, don't generate
3792 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3793 "can't use COBR format with external label");
3794 fixP
->fx_addsy
= NULL
;
3798 #endif /* TC_I960 */
3799 #if (defined (TC_I386) || defined (TE_LYNX)) && !defined(TE_PE)
3800 /* 386 COFF uses a peculiar format in which the
3801 value of a common symbol is stored in the .text
3802 segment (I've checked this on SVR3.2 and SCO
3803 3.2.2) Ian Taylor <ian@cygnus.com>. */
3804 if (S_IS_COMMON (add_symbolP
))
3805 add_number
+= S_GET_VALUE (add_symbolP
);
3810 } /* switch on symbol seg */
3811 } /* if not in local seg */
3812 } /* if there was a + symbol */
3816 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386))
3817 /* This adjustment is not correct on the m88k, for which the
3818 linker does all the computation. */
3819 add_number
-= md_pcrel_from (fixP
);
3821 if (add_symbolP
== 0)
3823 fixP
->fx_addsy
= &abs_symbol
;
3824 } /* if there's an add_symbol */
3825 #if defined (TC_I386) || defined (TE_LYNX)
3826 /* On the 386 we must adjust by the segment vaddr
3827 as well. Ian Taylor. */
3828 add_number
-= segP
->scnhdr
.s_vaddr
;
3832 if (!fixP
->fx_bit_fixP
)
3835 /* The m88k uses the offset field of the reloc to get around
3838 && (add_number
& ~0xFF)
3839 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
3841 && (add_number
& ~0xFFFF)
3842 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3844 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3845 "Value of %ld too large for field of %d bytes at 0x%lx",
3846 (long) add_number
, size
,
3847 (unsigned long) (fragP
->fr_address
+ where
));
3850 #ifdef WARN_SIGNED_OVERFLOW_WORD
3851 /* Warn if a .word value is too large when treated as a
3852 signed number. We already know it is not too negative.
3853 This is to catch over-large switches generated by gcc on
3855 if (!flag_signed_overflow_ok
3857 && add_number
> 0x7fff)
3858 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3859 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
3861 (unsigned long) (fragP
->fr_address
+ where
));
3863 } /* not a bit fix */
3864 /* Once this fix has been applied, we don't have to output
3865 anything nothing more need be done. */
3866 #ifdef MD_APPLY_FIX3
3867 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
3869 md_apply_fix (fixP
, add_number
);
3871 } /* For each fixS in this segment. */
3872 } /* fixup_segment() */
3876 /* The first entry in a .stab section is special. */
3879 obj_coff_init_stab_section (seg
)
3885 unsigned int stroff
;
3887 /* Make space for this first symbol. */
3891 as_where (&file
, (unsigned int *) NULL
);
3892 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
3893 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
3894 strcat (stabstr_name
, "str");
3895 stroff
= get_stab_string_offset (file
, stabstr_name
);
3897 md_number_to_chars (p
, stroff
, 4);
3900 /* Fill in the counts in the first entry in a .stab section. */
3903 adjust_stab_section(abfd
, seg
)
3907 segT stabstrseg
= SEG_UNKNOWN
;
3908 char *secname
, *name
, *name2
;
3910 int i
, strsz
= 0, nsyms
;
3911 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
3913 /* Look for the associated string table section. */
3915 secname
= segment_info
[seg
].scnhdr
.s_name
;
3916 name
= (char *) alloca (strlen (secname
) + 4);
3917 strcpy (name
, secname
);
3918 strcat (name
, "str");
3920 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3922 name2
= segment_info
[i
].scnhdr
.s_name
;
3923 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
3930 /* If we found the section, get its size. */
3931 if (stabstrseg
!= SEG_UNKNOWN
)
3932 strsz
= size_section (abfd
, stabstrseg
);
3934 nsyms
= size_section (abfd
, seg
) / 12 - 1;
3936 /* Look for the first frag of sufficient size for the initial stab
3937 symbol, and collect a pointer to it. */
3938 while (frag
&& frag
->fr_fix
< 12)
3939 frag
= frag
->fr_next
;
3941 p
= frag
->fr_literal
;
3944 /* Write in the number of stab symbols and the size of the string
3946 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
3947 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
3950 #endif /* not BFD_ASSEMBLER */
3952 const pseudo_typeS obj_pseudo_table
[] =
3954 {"def", obj_coff_def
, 0},
3955 {"dim", obj_coff_dim
, 0},
3956 {"endef", obj_coff_endef
, 0},
3957 {"line", obj_coff_line
, 0},
3958 {"ln", obj_coff_ln
, 0},
3959 {"appline", obj_coff_ln
, 1},
3960 {"scl", obj_coff_scl
, 0},
3961 {"size", obj_coff_size
, 0},
3962 {"tag", obj_coff_tag
, 0},
3963 {"type", obj_coff_type
, 0},
3964 {"val", obj_coff_val
, 0},
3965 {"section", obj_coff_section
, 0},
3966 #ifndef BFD_ASSEMBLER
3967 {"use", obj_coff_section
, 0},
3968 {"sect", obj_coff_section
, 0},
3969 {"text", obj_coff_text
, 0},
3970 {"data", obj_coff_data
, 0},
3971 {"bss", obj_coff_bss
, 0},
3972 {"lcomm", obj_coff_lcomm
, 0},
3973 {"ident", obj_coff_ident
, 0},
3975 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
3976 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
3978 {"ABORT", s_abort
, 0},
3980 /* The m88k uses sdef instead of def. */
3981 {"sdef", obj_coff_def
, 0},
3983 {NULL
} /* end sentinel */
3984 }; /* obj_pseudo_table */