1 /* coff object file format
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 /* I think this is probably always correct. */
26 #ifndef KEEP_RELOC_INFO
27 #define KEEP_RELOC_INFO
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 ();
778 obj_coff_size (ignore
)
781 if (def_symbol_in_progress
== NULL
)
783 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
784 demand_empty_rest_of_line ();
786 } /* if not inside .def/.endef */
788 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
789 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
790 demand_empty_rest_of_line ();
794 obj_coff_scl (ignore
)
797 if (def_symbol_in_progress
== NULL
)
799 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
800 demand_empty_rest_of_line ();
802 } /* if not inside .def/.endef */
804 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
805 demand_empty_rest_of_line ();
809 obj_coff_tag (ignore
)
815 if (def_symbol_in_progress
== NULL
)
817 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
818 demand_empty_rest_of_line ();
822 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
823 symbol_name
= input_line_pointer
;
824 name_end
= get_symbol_end ();
826 /* Assume that the symbol referred to by .tag is always defined.
827 This was a bad assumption. I've added find_or_make. xoxorich. */
828 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
829 tag_find_or_make (symbol_name
));
830 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
832 as_warn ("tag not found for .tag %s", symbol_name
);
835 SF_SET_TAGGED (def_symbol_in_progress
);
836 *input_line_pointer
= name_end
;
838 demand_empty_rest_of_line ();
842 obj_coff_type (ignore
)
845 if (def_symbol_in_progress
== NULL
)
847 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
848 demand_empty_rest_of_line ();
850 } /* if not inside .def/.endef */
852 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
854 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
855 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
857 SF_SET_FUNCTION (def_symbol_in_progress
);
858 } /* is a function */
860 demand_empty_rest_of_line ();
864 obj_coff_val (ignore
)
867 if (def_symbol_in_progress
== NULL
)
869 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
870 demand_empty_rest_of_line ();
872 } /* if not inside .def/.endef */
874 if (is_name_beginner (*input_line_pointer
))
876 char *symbol_name
= input_line_pointer
;
877 char name_end
= get_symbol_end ();
879 if (!strcmp (symbol_name
, "."))
881 def_symbol_in_progress
->sy_frag
= frag_now
;
882 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
883 /* If the .val is != from the .def (e.g. statics) */
885 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
887 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
888 def_symbol_in_progress
->sy_value
.X_add_symbol
=
889 symbol_find_or_make (symbol_name
);
890 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
891 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
893 /* If the segment is undefined when the forward reference is
894 resolved, then copy the segment id from the forward
896 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
898 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
899 *input_line_pointer
= name_end
;
903 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
904 } /* if symbol based */
906 demand_empty_rest_of_line ();
910 obj_read_begin_hook ()
912 /* These had better be the same. Usually 18 bytes. */
914 know (sizeof (SYMENT
) == sizeof (AUXENT
));
915 know (SYMESZ
== AUXESZ
);
921 symbolS
*coff_last_function
;
924 coff_frob_symbol (symp
, punt
)
928 static symbolS
*last_tagP
;
929 static stack
*block_stack
;
930 static symbolS
*set_end
;
932 if (symp
== &abs_symbol
)
938 if (current_lineno_sym
)
939 coff_add_linesym ((symbolS
*) 0);
942 block_stack
= stack_init (512, sizeof (symbolS
*));
944 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
945 S_SET_STORAGE_CLASS (symp
, C_EXT
);
947 if (!SF_GET_DEBUG (symp
))
950 if (!SF_GET_LOCAL (symp
)
951 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
954 c_symbol_merge (symp
, real
);
957 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
959 assert (S_GET_VALUE (symp
) == 0);
960 S_SET_EXTERNAL (symp
);
962 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
964 if (S_GET_SEGMENT (symp
) == text_section
965 && symp
!= seg_info (text_section
)->sym
)
966 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
968 S_SET_STORAGE_CLASS (symp
, C_STAT
);
970 if (SF_GET_PROCESS (symp
))
972 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
974 if (!strcmp (S_GET_NAME (symp
), ".bb"))
975 stack_push (block_stack
, (char *) &symp
);
979 begin
= *(symbolS
**) stack_pop (block_stack
);
981 as_warn ("mismatched .eb");
986 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
988 union internal_auxent
*auxp
;
989 coff_last_function
= symp
;
990 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
991 S_SET_NUMBER_AUXILIARY (symp
, 1);
992 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
993 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
994 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
996 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
998 if (coff_last_function
== 0)
999 as_fatal ("C_EFCN symbol out of scope");
1000 SA_SET_SYM_FSIZE (coff_last_function
,
1001 (long) (S_GET_VALUE (symp
)
1002 - S_GET_VALUE (coff_last_function
)));
1003 set_end
= coff_last_function
;
1004 coff_last_function
= 0;
1007 else if (SF_GET_TAG (symp
))
1009 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1010 set_end
= last_tagP
;
1011 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1013 if (S_GET_VALUE (symp
))
1015 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1016 S_SET_VALUE (symp
, 0);
1019 if (S_IS_EXTERNAL (symp
))
1020 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1021 else if (SF_GET_LOCAL (symp
))
1026 if (set_end
!= (symbolS
*) NULL
1029 SA_SET_SYM_ENDNDX (set_end
, symp
);
1033 if (coffsymbol (symp
->bsym
)->lineno
)
1036 struct line_no
*lptr
;
1039 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1040 for (i
= 0; lptr
; lptr
= lptr
->next
)
1042 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1044 /* We need i entries for line numbers, plus 1 for the first
1045 entry which BFD will override, plus 1 for the last zero
1046 entry (a marker for BFD). */
1047 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1048 coffsymbol (symp
->bsym
)->lineno
= l
;
1049 l
[i
+ 1].line_number
= 0;
1050 l
[i
+ 1].u
.sym
= NULL
;
1054 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1062 coff_adjust_section_syms (abfd
, sec
, x
)
1068 segment_info_type
*seginfo
= seg_info (sec
);
1069 int nlnno
, nrelocs
= 0;
1071 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1072 tc-ppc.c. Do not get confused by it. */
1073 if (seginfo
== NULL
)
1076 if (!strcmp (sec
->name
, ".text"))
1081 /* @@ Hope that none of the fixups expand to more than one reloc
1083 fixS
*fixp
= seginfo
->fix_root
;
1086 fixp
= fixp
->fx_next
;
1090 if (bfd_get_section_size_before_reloc (sec
) == 0
1091 && nrelocs
== 0 && nlnno
== 0)
1093 secsym
= section_symbol (sec
);
1094 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1095 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1101 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1105 * implement the .section pseudo op:
1106 * .section name {, "flags"}
1108 * | +--- optional flags: 'b' for bss
1110 * +-- section name 'l' for lib
1114 * 'd' (apparently m88k for data)
1116 * But if the argument is not a quoted string, treat it as a
1117 * subsegment number.
1121 obj_coff_section (ignore
)
1124 /* Strip out the section name */
1132 section_name
= input_line_pointer
;
1133 c
= get_symbol_end ();
1135 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1136 strcpy (name
, section_name
);
1138 *input_line_pointer
= c
;
1143 flags
= SEC_NO_FLAGS
;
1145 if (*input_line_pointer
== ',')
1147 ++input_line_pointer
;
1149 if (*input_line_pointer
!= '"')
1150 exp
= get_absolute_expression ();
1153 ++input_line_pointer
;
1154 while (*input_line_pointer
!= '"'
1155 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1157 switch (*input_line_pointer
)
1159 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1160 case 'n': flags
&=~ SEC_LOAD
; break;
1162 case 'w': flags
&=~ SEC_READONLY
; break;
1163 case 'x': flags
|= SEC_CODE
; break;
1165 case 'i': /* STYP_INFO */
1166 case 'l': /* STYP_LIB */
1167 case 'o': /* STYP_OVER */
1168 as_warn ("unsupported section attribute '%c'",
1169 *input_line_pointer
);
1173 as_warn("unknown section attribute '%c'",
1174 *input_line_pointer
);
1177 ++input_line_pointer
;
1179 if (*input_line_pointer
== '"')
1180 ++input_line_pointer
;
1184 sec
= subseg_new (name
, (subsegT
) exp
);
1186 if (flags
!= SEC_NO_FLAGS
)
1188 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1189 as_warn ("error setting flags for \"%s\": %s",
1190 bfd_section_name (stdoutput
, sec
),
1191 bfd_errmsg (bfd_get_error ()));
1196 coff_adjust_symtab ()
1198 if (symbol_rootP
== NULL
1199 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1201 assert (previous_file_symbol
== 0);
1202 c_dot_file_symbol ("fake");
1207 coff_frob_section (sec
)
1213 bfd_vma size
, n_entries
, mask
;
1215 /* The COFF back end in BFD requires that all section sizes be
1216 rounded up to multiples of the corresponding section alignments.
1217 Seems kinda silly to me, but that's the way it is. */
1218 size
= bfd_get_section_size_before_reloc (sec
);
1219 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1222 size
= (size
+ mask
) & ~mask
;
1223 bfd_set_section_size (stdoutput
, sec
, size
);
1226 /* If the section size is non-zero, the section symbol needs an aux
1227 entry associated with it, indicating the size. We don't know
1228 all the values yet; coff_frob_symbol will fill them in later. */
1231 symbolS
*secsym
= section_symbol (sec
);
1233 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1234 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1235 SF_SET_STATICS (secsym
);
1236 SA_SET_SCN_SCNLEN (secsym
, size
);
1239 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1240 #ifndef STAB_SECTION_NAME
1241 #define STAB_SECTION_NAME ".stab"
1243 #ifndef STAB_STRING_SECTION_NAME
1244 #define STAB_STRING_SECTION_NAME ".stabstr"
1246 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1250 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1251 /* size is already rounded up, since other section will be listed first */
1252 size
= bfd_get_section_size_before_reloc (strsec
);
1254 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1256 /* Find first non-empty frag. It should be large enough. */
1257 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1258 while (fragp
&& fragp
->fr_fix
== 0)
1259 fragp
= fragp
->fr_next
;
1260 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1262 /* Store the values. */
1263 p
= fragp
->fr_literal
;
1264 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1265 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1269 obj_coff_init_stab_section (seg
)
1275 unsigned int stroff
;
1277 /* Make space for this first symbol. */
1281 as_where (&file
, (unsigned int *) NULL
);
1282 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1283 strcpy (stabstr_name
, seg
->name
);
1284 strcat (stabstr_name
, "str");
1285 stroff
= get_stab_string_offset (file
, stabstr_name
);
1287 md_number_to_chars (p
, stroff
, 4);
1296 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1304 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1306 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1307 (unsigned long) symbolP
,
1308 S_GET_NAME(symbolP
),
1309 (long) S_GET_DATA_TYPE(symbolP
),
1310 S_GET_STORAGE_CLASS(symbolP
),
1311 (int) S_GET_SEGMENT(symbolP
));
1317 #else /* not BFD_ASSEMBLER */
1320 /* This is needed because we include internal bfd things. */
1324 #include "libcoff.h"
1326 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1327 that we can stick sections together without causing trouble. */
1329 #define NOP_OPCODE 0x00
1332 /* The zeroes if symbol name is longer than 8 chars */
1333 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1335 #define MIN(a,b) ((a) < (b)? (a) : (b))
1336 /* This vector is used to turn an internal segment into a section #
1337 suitable for insertion into a coff symbol table
1340 const short seg_N_TYPE
[] =
1341 { /* in: segT out: N_TYPE bits */
1353 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1354 C_UNDEF_SECTION
, /* SEG_GOOF */
1355 C_UNDEF_SECTION
, /* SEG_EXPR */
1356 C_DEBUG_SECTION
, /* SEG_DEBUG */
1357 C_NTV_SECTION
, /* SEG_NTV */
1358 C_PTV_SECTION
, /* SEG_PTV */
1359 C_REGISTER_SECTION
, /* SEG_REGISTER */
1362 int function_lineoff
= -1; /* Offset in line#s where the last function
1363 started (the odd entry for line #0) */
1365 static symbolS
*last_line_symbol
;
1367 /* Add 4 to the real value to get the index and compensate the
1368 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1369 section number into a segment number
1371 static symbolS
*previous_file_symbol
;
1372 void c_symbol_merge ();
1373 static int line_base
;
1375 symbolS
*c_section_symbol ();
1378 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1379 segT this_segment_type
));
1382 static void fixup_mdeps
PARAMS ((fragS
*,
1387 static void fill_section
PARAMS ((bfd
* abfd
,
1392 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1397 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1398 symbolS
* symbol_rootP
));
1400 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1402 static void obj_coff_lcomm
PARAMS ((int));
1403 static void obj_coff_text
PARAMS ((int));
1404 static void obj_coff_data
PARAMS ((int));
1405 static void obj_coff_bss
PARAMS ((int));
1406 static void obj_coff_ident
PARAMS ((int));
1407 void obj_coff_section
PARAMS ((int));
1411 We allow more than just the standard 3 sections, infact, we allow
1412 10 sections, (though the usual three have to be there).
1414 This structure performs the mappings for us:
1425 static const seg_info_type seg_info_off_by_4
[N_SEG
] =
1456 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1458 static relax_addressT
1459 relax_align (address
, alignment
)
1460 relax_addressT address
;
1463 relax_addressT mask
;
1464 relax_addressT new_address
;
1466 mask
= ~((~0) << alignment
);
1467 new_address
= (address
+ mask
) & (~mask
);
1468 return (new_address
- address
);
1476 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1481 /* calculate the size of the frag chain and fill in the section header
1482 to contain all of it, also fill in the addr of the sections */
1484 size_section (abfd
, idx
)
1489 unsigned int size
= 0;
1490 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1493 size
= frag
->fr_address
;
1494 if (frag
->fr_address
!= size
)
1496 fprintf (stderr
, "Out of step\n");
1497 size
= frag
->fr_address
;
1500 switch (frag
->fr_type
)
1502 #ifdef TC_COFF_SIZEMACHDEP
1503 case rs_machine_dependent
:
1504 size
+= TC_COFF_SIZEMACHDEP (frag
);
1508 assert (frag
->fr_symbol
== 0);
1511 size
+= frag
->fr_fix
;
1512 size
+= frag
->fr_offset
* frag
->fr_var
;
1515 size
+= frag
->fr_fix
;
1516 size
+= relax_align (size
, frag
->fr_offset
);
1519 BAD_CASE (frag
->fr_type
);
1522 frag
= frag
->fr_next
;
1524 segment_info
[idx
].scnhdr
.s_size
= size
;
1530 count_entries_in_chain (idx
)
1533 unsigned int nrelocs
;
1536 /* Count the relocations */
1537 fixup_ptr
= segment_info
[idx
].fix_root
;
1539 while (fixup_ptr
!= (fixS
*) NULL
)
1541 if (TC_COUNT_RELOC (fixup_ptr
))
1544 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1553 fixup_ptr
= fixup_ptr
->fx_next
;
1558 /* output all the relocations for a section */
1560 do_relocs_for (abfd
, h
, file_cursor
)
1563 unsigned long *file_cursor
;
1565 unsigned int nrelocs
;
1567 unsigned long reloc_start
= *file_cursor
;
1569 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
1571 if (segment_info
[idx
].scnhdr
.s_name
[0])
1573 struct external_reloc
*ext_ptr
;
1574 struct external_reloc
*external_reloc_vec
;
1575 unsigned int external_reloc_size
;
1576 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1577 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1578 nrelocs
= count_entries_in_chain (idx
);
1581 /* Bypass this stuff if no relocs. This also incidentally
1582 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1584 external_reloc_size
= nrelocs
* RELSZ
;
1585 external_reloc_vec
=
1586 (struct external_reloc
*) malloc (external_reloc_size
);
1588 ext_ptr
= external_reloc_vec
;
1590 /* Fill in the internal coff style reloc struct from the
1591 internal fix list. */
1594 struct internal_reloc intr
;
1596 /* Only output some of the relocations */
1597 if (TC_COUNT_RELOC (fix_ptr
))
1599 #ifdef TC_RELOC_MANGLE
1600 TC_RELOC_MANGLE (fix_ptr
, &intr
, base
);
1604 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1606 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1608 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1610 #ifdef TC_KEEP_FX_OFFSET
1611 intr
.r_offset
= fix_ptr
->fx_offset
;
1616 /* Turn the segment of the symbol into an offset. */
1619 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1622 intr
.r_symndx
= dot
->sy_number
;
1626 intr
.r_symndx
= symbol_ptr
->sy_number
;
1636 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1639 #if defined(TC_A29K)
1641 /* The 29k has a special kludge for the high 16 bit
1642 reloc. Two relocations are emited, R_IHIHALF,
1643 and R_IHCONST. The second one doesn't contain a
1644 symbol, but uses the value for offset. */
1646 if (intr
.r_type
== R_IHIHALF
)
1648 /* now emit the second bit */
1649 intr
.r_type
= R_IHCONST
;
1650 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1651 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1657 fix_ptr
= fix_ptr
->fx_next
;
1660 /* Write out the reloc table */
1661 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1663 free (external_reloc_vec
);
1665 /* Fill in section header info. */
1666 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1667 *file_cursor
+= external_reloc_size
;
1668 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1673 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1677 /* Set relocation_size field in file headers */
1678 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1682 /* run through a frag chain and write out the data to go with it, fill
1683 in the scnhdrs with the info on the file postions
1686 fill_section (abfd
, h
, file_cursor
)
1689 unsigned long *file_cursor
;
1693 unsigned int paddr
= 0;
1695 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1697 unsigned int offset
= 0;
1698 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1704 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1711 buffer
= xmalloc (s
->s_size
);
1712 s
->s_scnptr
= *file_cursor
;
1714 know (s
->s_paddr
== paddr
);
1716 if (strcmp (s
->s_name
, ".text") == 0)
1717 s
->s_flags
|= STYP_TEXT
;
1718 else if (strcmp (s
->s_name
, ".data") == 0)
1719 s
->s_flags
|= STYP_DATA
;
1720 else if (strcmp (s
->s_name
, ".bss") == 0)
1723 s
->s_flags
|= STYP_BSS
;
1725 /* @@ Should make the i386 and a29k coff targets define
1726 COFF_NOLOAD_PROBLEM, and have only one test here. */
1729 #ifndef COFF_NOLOAD_PROBLEM
1730 /* Apparently the SVR3 linker (and exec syscall) and UDI
1731 mondfe progrem are confused by noload sections. */
1732 s
->s_flags
|= STYP_NOLOAD
;
1737 else if (strcmp (s
->s_name
, ".lit") == 0)
1738 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1739 else if (strcmp (s
->s_name
, ".init") == 0)
1740 s
->s_flags
|= STYP_TEXT
;
1741 else if (strcmp (s
->s_name
, ".fini") == 0)
1742 s
->s_flags
|= STYP_TEXT
;
1743 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1744 s
->s_flags
|= STYP_INFO
;
1748 unsigned int fill_size
;
1749 switch (frag
->fr_type
)
1751 case rs_machine_dependent
:
1754 memcpy (buffer
+ frag
->fr_address
,
1756 (unsigned int) frag
->fr_fix
);
1757 offset
+= frag
->fr_fix
;
1762 assert (frag
->fr_symbol
== 0);
1768 memcpy (buffer
+ frag
->fr_address
,
1770 (unsigned int) frag
->fr_fix
);
1771 offset
+= frag
->fr_fix
;
1774 fill_size
= frag
->fr_var
;
1775 if (fill_size
&& frag
->fr_offset
> 0)
1778 unsigned int off
= frag
->fr_fix
;
1779 for (count
= frag
->fr_offset
; count
; count
--)
1781 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1783 memcpy (buffer
+ frag
->fr_address
+ off
,
1784 frag
->fr_literal
+ frag
->fr_fix
,
1787 offset
+= fill_size
;
1792 case rs_broken_word
:
1797 frag
= frag
->fr_next
;
1802 if (s
->s_scnptr
!= 0)
1804 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1805 *file_cursor
+= s
->s_size
;
1814 /* Coff file generation & utilities */
1817 coff_header_append (abfd
, h
)
1825 bfd_seek (abfd
, 0, 0);
1827 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1828 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1829 H_SET_VERSION_STAMP (h
, 0);
1830 H_SET_ENTRY_POINT (h
, 0);
1831 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1832 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1833 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1835 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1836 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1837 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1839 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1841 bfd_write (buffer
, i
, 1, abfd
);
1842 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1844 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
1846 if (segment_info
[i
].scnhdr
.s_name
[0])
1849 bfd_coff_swap_scnhdr_out (abfd
,
1850 &(segment_info
[i
].scnhdr
),
1853 as_bad ("bfd_coff_swap_scnhdr_out failed");
1854 bfd_write (buffer
, size
, 1, abfd
);
1861 symbol_to_chars (abfd
, where
, symbolP
)
1866 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1870 /* Turn any symbols with register attributes into abs symbols */
1871 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1873 S_SET_SEGMENT (symbolP
, absolute_section
);
1875 /* At the same time, relocate all symbols to their output value */
1877 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1878 + S_GET_VALUE (symbolP
));
1880 S_SET_VALUE (symbolP
, val
);
1882 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1884 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1887 for (i
= 0; i
< numaux
; i
++)
1889 where
+= bfd_coff_swap_aux_out (abfd
,
1890 &symbolP
->sy_symbol
.ost_auxent
[i
],
1891 S_GET_DATA_TYPE (symbolP
),
1892 S_GET_STORAGE_CLASS (symbolP
),
1900 obj_symbol_new_hook (symbolP
)
1903 char underscore
= 0; /* Symbol has leading _ */
1905 /* Effective symbol */
1906 /* Store the pointer in the offset. */
1907 S_SET_ZEROES (symbolP
, 0L);
1908 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1909 S_SET_STORAGE_CLASS (symbolP
, 0);
1910 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1911 /* Additional information */
1912 symbolP
->sy_symbol
.ost_flags
= 0;
1913 /* Auxiliary entries */
1914 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1916 if (S_IS_STRING (symbolP
))
1917 SF_SET_STRING (symbolP
);
1918 if (!underscore
&& S_IS_LOCAL (symbolP
))
1919 SF_SET_LOCAL (symbolP
);
1923 * Handle .ln directives.
1927 obj_coff_ln (appline
)
1932 if (! appline
&& def_symbol_in_progress
!= NULL
)
1934 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
1935 demand_empty_rest_of_line ();
1937 } /* wrong context */
1939 l
= get_absolute_expression ();
1940 c_line_new (0, frag_now_fix (), l
, frag_now
);
1949 listing_source_line ((unsigned int) l
);
1954 demand_empty_rest_of_line ();
1960 * Handle .def directives.
1962 * One might ask : why can't we symbol_new if the symbol does not
1963 * already exist and fill it with debug information. Because of
1964 * the C_EFCN special symbol. It would clobber the value of the
1965 * function symbol before we have a chance to notice that it is
1966 * a C_EFCN. And a second reason is that the code is more clear this
1967 * way. (at least I think it is :-).
1971 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
1972 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
1973 *input_line_pointer == '\t') \
1974 input_line_pointer++;
1980 char name_end
; /* Char after the end of name */
1981 char *symbol_name
; /* Name of the debug symbol */
1982 char *symbol_name_copy
; /* Temporary copy of the name */
1983 unsigned int symbol_name_length
;
1985 if (def_symbol_in_progress
!= NULL
)
1987 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
1988 demand_empty_rest_of_line ();
1990 } /* if not inside .def/.endef */
1992 SKIP_WHITESPACES ();
1994 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
1995 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
1997 symbol_name
= input_line_pointer
;
1998 name_end
= get_symbol_end ();
1999 symbol_name_length
= strlen (symbol_name
);
2000 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2001 strcpy (symbol_name_copy
, symbol_name
);
2003 /* Initialize the new symbol */
2004 #ifdef STRIP_UNDERSCORE
2005 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2006 ? symbol_name_copy
+ 1
2007 : symbol_name_copy
));
2008 #else /* STRIP_UNDERSCORE */
2009 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2010 #endif /* STRIP_UNDERSCORE */
2011 /* free(symbol_name_copy); */
2012 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2013 def_symbol_in_progress
->sy_number
= ~0;
2014 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2015 S_SET_VALUE (def_symbol_in_progress
, 0);
2017 if (S_IS_STRING (def_symbol_in_progress
))
2018 SF_SET_STRING (def_symbol_in_progress
);
2020 *input_line_pointer
= name_end
;
2022 demand_empty_rest_of_line ();
2025 unsigned int dim_index
;
2029 obj_coff_endef (ignore
)
2032 symbolS
*symbolP
= 0;
2033 /* DIM BUG FIX sac@cygnus.com */
2035 if (def_symbol_in_progress
== NULL
)
2037 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2038 demand_empty_rest_of_line ();
2040 } /* if not inside .def/.endef */
2042 /* Set the section number according to storage class. */
2043 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2048 SF_SET_TAG (def_symbol_in_progress
);
2049 /* intentional fallthrough */
2052 SF_SET_DEBUG (def_symbol_in_progress
);
2053 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2057 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2058 /* intentional fallthrough */
2060 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2061 /* intentional fallthrough */
2063 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2065 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2067 if (function_lineoff
< 0)
2069 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2070 } /* missing function symbol */
2071 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2073 SF_SET_PROCESS (last_line_symbol
);
2074 function_lineoff
= -1;
2076 /* Value is always set to . */
2077 def_symbol_in_progress
->sy_frag
= frag_now
;
2078 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2083 #endif /* C_AUTOARG */
2093 SF_SET_DEBUG (def_symbol_in_progress
);
2094 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2100 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2106 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2108 } /* switch on storage class */
2110 /* Now that we have built a debug symbol, try to find if we should
2111 merge with an existing symbol or not. If a symbol is C_EFCN or
2112 absolute_section or untagged SEG_DEBUG it never merges. We also
2113 don't merge labels, which are in a different namespace, nor
2114 symbols which have not yet been defined since they are typically
2115 unique, nor do we merge tags with non-tags. */
2117 /* Two cases for functions. Either debug followed by definition or
2118 definition followed by debug. For definition first, we will
2119 merge the debug symbol into the definition. For debug first, the
2120 lineno entry MUST point to the definition function or else it
2121 will point off into space when crawl_symbols() merges the debug
2122 symbol into the real symbol. Therefor, let's presume the debug
2123 symbol is a real function reference. */
2125 /* FIXME-SOON If for some reason the definition label/symbol is
2126 never seen, this will probably leave an undefined symbol at link
2129 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2130 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2131 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2132 && !SF_GET_TAG (def_symbol_in_progress
))
2133 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2134 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2135 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2136 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2138 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2143 /* This symbol already exists, merge the newly created symbol
2144 into the old one. This is not mandatory. The linker can
2145 handle duplicate symbols correctly. But I guess that it save
2146 a *lot* of space if the assembly file defines a lot of
2149 /* The debug entry (def_symbol_in_progress) is merged into the
2150 previous definition. */
2152 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2153 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2154 def_symbol_in_progress
= symbolP
;
2156 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2157 || SF_GET_TAG (def_symbol_in_progress
))
2159 /* For functions, and tags, the symbol *must* be where the
2160 debug symbol appears. Move the existing symbol to the
2162 /* If it already is at the end of the symbol list, do nothing */
2163 if (def_symbol_in_progress
!= symbol_lastP
)
2165 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2167 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2168 &symbol_rootP
, &symbol_lastP
);
2169 } /* if not already in place */
2171 } /* normal or mergable */
2173 if (SF_GET_TAG (def_symbol_in_progress
)
2174 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2176 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2179 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2181 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2183 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2185 SF_SET_PROCESS (def_symbol_in_progress
);
2187 if (symbolP
== NULL
)
2189 /* That is, if this is the first time we've seen the
2191 symbol_table_insert (def_symbol_in_progress
);
2192 } /* definition follows debug */
2193 } /* Create the line number entry pointing to the function being defined */
2195 def_symbol_in_progress
= NULL
;
2196 demand_empty_rest_of_line ();
2200 obj_coff_dim (ignore
)
2205 if (def_symbol_in_progress
== NULL
)
2207 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2208 demand_empty_rest_of_line ();
2210 } /* if not inside .def/.endef */
2212 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2214 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2216 SKIP_WHITESPACES ();
2217 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2218 get_absolute_expression ());
2220 switch (*input_line_pointer
)
2223 input_line_pointer
++;
2227 as_warn ("badly formed .dim directive ignored");
2228 /* intentional fallthrough */
2236 demand_empty_rest_of_line ();
2240 obj_coff_line (ignore
)
2246 if (def_symbol_in_progress
== NULL
)
2252 name
= S_GET_NAME (def_symbol_in_progress
);
2253 this_base
= get_absolute_expression ();
2255 /* Only .bf symbols indicate the use of a new base line number; the
2256 line numbers associated with .ef, .bb, .eb are relative to the
2257 start of the containing function. */
2258 if (!strcmp (".bf", name
))
2260 #if 0 /* XXX Can we ever have line numbers going backwards? */
2261 if (this_base
> line_base
)
2264 line_base
= this_base
;
2272 listing_source_line ((unsigned int) line_base
);
2278 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2279 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2281 demand_empty_rest_of_line ();
2285 obj_coff_size (ignore
)
2288 if (def_symbol_in_progress
== NULL
)
2290 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2291 demand_empty_rest_of_line ();
2293 } /* if not inside .def/.endef */
2295 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2296 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2297 demand_empty_rest_of_line ();
2301 obj_coff_scl (ignore
)
2304 if (def_symbol_in_progress
== NULL
)
2306 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2307 demand_empty_rest_of_line ();
2309 } /* if not inside .def/.endef */
2311 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2312 demand_empty_rest_of_line ();
2316 obj_coff_tag (ignore
)
2322 if (def_symbol_in_progress
== NULL
)
2324 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2325 demand_empty_rest_of_line ();
2329 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2330 symbol_name
= input_line_pointer
;
2331 name_end
= get_symbol_end ();
2333 /* Assume that the symbol referred to by .tag is always defined.
2334 This was a bad assumption. I've added find_or_make. xoxorich. */
2335 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2336 (long) tag_find_or_make (symbol_name
));
2337 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2339 as_warn ("tag not found for .tag %s", symbol_name
);
2342 SF_SET_TAGGED (def_symbol_in_progress
);
2343 *input_line_pointer
= name_end
;
2345 demand_empty_rest_of_line ();
2349 obj_coff_type (ignore
)
2352 if (def_symbol_in_progress
== NULL
)
2354 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2355 demand_empty_rest_of_line ();
2357 } /* if not inside .def/.endef */
2359 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2361 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2362 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2364 SF_SET_FUNCTION (def_symbol_in_progress
);
2365 } /* is a function */
2367 demand_empty_rest_of_line ();
2371 obj_coff_val (ignore
)
2374 if (def_symbol_in_progress
== NULL
)
2376 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2377 demand_empty_rest_of_line ();
2379 } /* if not inside .def/.endef */
2381 if (is_name_beginner (*input_line_pointer
))
2383 char *symbol_name
= input_line_pointer
;
2384 char name_end
= get_symbol_end ();
2386 if (!strcmp (symbol_name
, "."))
2388 def_symbol_in_progress
->sy_frag
= frag_now
;
2389 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2390 /* If the .val is != from the .def (e.g. statics) */
2392 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2394 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2395 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2396 symbol_find_or_make (symbol_name
);
2397 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2398 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2400 /* If the segment is undefined when the forward reference is
2401 resolved, then copy the segment id from the forward
2403 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2405 /* FIXME: gcc can generate address expressions
2406 here in unusual cases (search for "obscure"
2407 in sdbout.c). We just ignore the offset
2408 here, thus generating incorrect debugging
2409 information. We ignore the rest of the
2412 /* Otherwise, it is the name of a non debug symbol and
2413 its value will be calculated later. */
2414 *input_line_pointer
= name_end
;
2416 /* FIXME: this is to avoid an error message in the
2417 FIXME case mentioned just above. */
2418 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2419 ++input_line_pointer
;
2423 S_SET_VALUE (def_symbol_in_progress
,
2424 (valueT
) get_absolute_expression ());
2425 } /* if symbol based */
2427 demand_empty_rest_of_line ();
2431 obj_read_begin_hook ()
2433 /* These had better be the same. Usually 18 bytes. */
2435 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2436 know (SYMESZ
== AUXESZ
);
2441 /* This function runs through the symbol table and puts all the
2442 externals onto another chain */
2444 /* The chain of externals */
2445 symbolS
*symbol_externP
;
2446 symbolS
*symbol_extern_lastP
;
2449 symbolS
*last_functionP
;
2456 unsigned int symbol_number
= 0;
2457 unsigned int last_file_symno
= 0;
2459 struct filename_list
*filename_list_scan
= filename_list_head
;
2461 for (symbolP
= symbol_rootP
;
2463 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2465 if (!SF_GET_DEBUG (symbolP
))
2467 /* Debug symbols do not need all this rubbish */
2468 symbolS
*real_symbolP
;
2470 /* L* and C_EFCN symbols never merge. */
2471 if (!SF_GET_LOCAL (symbolP
)
2472 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2473 && symbolP
->sy_value
.X_op
== O_constant
2474 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2475 && real_symbolP
!= symbolP
)
2477 /* FIXME-SOON: where do dups come from?
2478 Maybe tag references before definitions? xoxorich. */
2479 /* Move the debug data from the debug symbol to the
2480 real symbol. Do NOT do the oposite (i.e. move from
2481 real symbol to debug symbol and remove real symbol from the
2482 list.) Because some pointers refer to the real symbol
2483 whereas no pointers refer to the debug symbol. */
2484 c_symbol_merge (symbolP
, real_symbolP
);
2485 /* Replace the current symbol by the real one */
2486 /* The symbols will never be the last or the first
2487 because : 1st symbol is .file and 3 last symbols are
2488 .text, .data, .bss */
2489 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2490 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2491 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2492 symbolP
= real_symbolP
;
2493 } /* if not local but dup'd */
2495 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2497 S_SET_SEGMENT (symbolP
, SEG_E0
);
2498 } /* push data into text */
2500 resolve_symbol_value (symbolP
);
2502 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2504 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2506 S_SET_EXTERNAL (symbolP
);
2508 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2510 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2514 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2518 /* Mainly to speed up if not -g */
2519 if (SF_GET_PROCESS (symbolP
))
2521 /* Handle the nested blocks auxiliary info. */
2522 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2524 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2525 stack_push (block_stack
, (char *) &symbolP
);
2528 register symbolS
*begin_symbolP
;
2529 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2530 if (begin_symbolP
== (symbolS
*) 0)
2531 as_warn ("mismatched .eb");
2533 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2536 /* If we are able to identify the type of a function, and we
2537 are out of a function (last_functionP == 0) then, the
2538 function symbol will be associated with an auxiliary
2540 if (last_functionP
== (symbolS
*) 0 &&
2541 SF_GET_FUNCTION (symbolP
))
2543 last_functionP
= symbolP
;
2545 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2547 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2548 } /* make it at least 1 */
2550 /* Clobber possible stale .dim information. */
2552 /* Iffed out by steve - this fries the lnnoptr info too */
2553 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2554 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2557 /* The C_FCN doesn't need any additional information. I
2558 don't even know if this is needed for sdb. But the
2559 standard assembler generates it, so... */
2560 if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2562 if (last_functionP
== (symbolS
*) 0)
2563 as_fatal ("C_EFCN symbol out of scope");
2564 SA_SET_SYM_FSIZE (last_functionP
,
2565 (long) (S_GET_VALUE (symbolP
) -
2566 S_GET_VALUE (last_functionP
)));
2567 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2568 last_functionP
= (symbolS
*) 0;
2572 else if (SF_GET_TAG (symbolP
))
2574 /* First descriptor of a structure must point to
2575 the first slot after the structure description. */
2576 last_tagP
= symbolP
;
2579 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2581 /* +2 take in account the current symbol */
2582 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2584 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2586 /* If the filename was too long to fit in the
2587 auxent, put it in the string table */
2588 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2590 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2591 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2592 filename_list_scan
= filename_list_scan
->next
;
2594 if (S_GET_VALUE (symbolP
))
2596 S_SET_VALUE (symbolP
, last_file_symno
);
2597 last_file_symno
= symbol_number
;
2598 } /* no one points at the first .file symbol */
2599 } /* if debug or tag or eos or file */
2601 /* We must put the external symbols apart. The loader
2602 does not bomb if we do not. But the references in
2603 the endndx field for a .bb symbol are not corrected
2604 if an external symbol is removed between .bb and .be.
2605 I.e in the following case :
2606 [20] .bb endndx = 22
2609 ld will move the symbol 21 to the end of the list but
2610 endndx will still be 22 instead of 21. */
2613 if (SF_GET_LOCAL (symbolP
))
2615 /* remove C_EFCN and LOCAL (L...) symbols */
2616 /* next pointer remains valid */
2617 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2620 else if (!S_IS_DEFINED (symbolP
)
2621 && !S_IS_DEBUG (symbolP
)
2622 && !SF_GET_STATICS (symbolP
) &&
2623 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2624 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2625 /* if external, Remove from the list */
2626 symbolS
*hold
= symbol_previous (symbolP
);
2628 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2629 symbol_clear_list_pointers (symbolP
);
2630 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2635 if (SF_GET_STRING (symbolP
))
2637 symbolP
->sy_name_offset
= string_byte_count
;
2638 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2642 symbolP
->sy_name_offset
= 0;
2643 } /* fix "long" names */
2645 symbolP
->sy_number
= symbol_number
;
2646 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2647 } /* if local symbol */
2648 } /* traverse the symbol list */
2649 return symbol_number
;
2657 unsigned int symbol_number
= 0;
2659 for (symbolP
= symbol_externP
; symbol_externP
;)
2661 symbolS
*tmp
= symbol_externP
;
2664 symbol_remove (tmp
, &symbol_externP
, &symbol_extern_lastP
);
2665 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2668 if (SF_GET_STRING (tmp
))
2670 tmp
->sy_name_offset
= string_byte_count
;
2671 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2675 tmp
->sy_name_offset
= 0;
2676 } /* fix "long" names */
2678 tmp
->sy_number
= symbol_number
;
2679 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2680 } /* append the entire extern chain */
2681 return symbol_number
;
2688 unsigned int symbol_number
= 0;
2691 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2692 symbol_next (symbolP
))
2694 symbolP
->sy_number
= symbol_number
;
2698 if (SF_GET_TAGGED (symbolP
))
2702 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2705 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2707 return symbol_number
;
2712 crawl_symbols (h
, abfd
)
2718 /* Initialize the stack used to keep track of the matching .bb .be */
2720 block_stack
= stack_init (512, sizeof (symbolS
*));
2722 /* The symbol list should be ordered according to the following sequence
2725 * . debug entries for functions
2726 * . fake symbols for the sections, including.text .data and .bss
2728 * . undefined symbols
2729 * But this is not mandatory. The only important point is to put the
2730 * undefined symbols at the end of the list.
2733 if (symbol_rootP
== NULL
2734 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2736 c_dot_file_symbol ("fake");
2738 /* Is there a .file symbol ? If not insert one at the beginning. */
2741 * Build up static symbols for the sections, they are filled in later
2745 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
2747 if (segment_info
[i
].scnhdr
.s_name
[0])
2751 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2753 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2758 /* Take all the externals out and put them into another chain */
2759 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2760 /* Take the externals and glue them onto the end.*/
2761 H_SET_SYMBOL_TABLE_SIZE (h
, H_GET_SYMBOL_COUNT (h
) + glue_symbols ());
2763 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2764 know (symbol_externP
== NULL
);
2765 know (symbol_extern_lastP
== NULL
);
2769 * Find strings by crawling along symbol table chain.
2777 struct filename_list
*filename_list_scan
= filename_list_head
;
2779 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2780 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2782 for (symbolP
= symbol_rootP
;
2784 symbolP
= symbol_next (symbolP
))
2788 if (SF_GET_STRING (symbolP
))
2790 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2791 memcpy (where
, S_GET_NAME (symbolP
), size
);
2794 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2795 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2797 size
= strlen (filename_list_scan
->filename
) + 1;
2798 memcpy (where
, filename_list_scan
->filename
, size
);
2799 filename_list_scan
= filename_list_scan
->next
;
2806 do_linenos_for (abfd
, h
, file_cursor
)
2809 unsigned long *file_cursor
;
2812 unsigned long start
= *file_cursor
;
2814 for (idx
= SEG_E0
; idx
< SEG_E9
; idx
++)
2816 segment_info_type
*s
= segment_info
+ idx
;
2819 if (s
->scnhdr
.s_nlnno
!= 0)
2821 struct lineno_list
*line_ptr
;
2823 struct external_lineno
*buffer
=
2824 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2826 struct external_lineno
*dst
= buffer
;
2828 /* Run through the table we've built and turn it into its external
2829 form, take this chance to remove duplicates */
2831 for (line_ptr
= s
->lineno_list_head
;
2832 line_ptr
!= (struct lineno_list
*) NULL
;
2833 line_ptr
= line_ptr
->next
)
2836 if (line_ptr
->line
.l_lnno
== 0)
2838 /* Turn a pointer to a symbol into the symbols' index */
2839 line_ptr
->line
.l_addr
.l_symndx
=
2840 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2844 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
2848 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
2853 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
2855 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
2858 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
2861 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
2865 /* Now we run through the list of frag chains in a segment and
2866 make all the subsegment frags appear at the end of the
2867 list, as if the seg 0 was extra long */
2874 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2876 frchainS
*head
= segment_info
[i
].frchainP
;
2878 fragS
*prev_frag
= &dummy
;
2880 while (head
&& head
->frch_seg
== i
)
2882 prev_frag
->fr_next
= head
->frch_root
;
2883 prev_frag
= head
->frch_last
;
2884 head
= head
->frch_next
;
2886 prev_frag
->fr_next
= 0;
2890 unsigned long machine
;
2893 write_object_file ()
2897 struct frchain
*frchain_ptr
;
2899 object_headers headers
;
2900 unsigned long file_cursor
;
2903 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
2908 as_perror ("FATAL: Can't create %s", out_file_name
);
2909 exit (EXIT_FAILURE
);
2911 bfd_set_format (abfd
, bfd_object
);
2912 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
2914 string_byte_count
= 4;
2916 for (frchain_ptr
= frchain_root
;
2917 frchain_ptr
!= (struct frchain
*) NULL
;
2918 frchain_ptr
= frchain_ptr
->frch_next
)
2920 /* Run through all the sub-segments and align them up. Also
2921 close any open frags. We tack a .fill onto the end of the
2922 frag chain so that any .align's size can be worked by looking
2923 at the next frag. */
2925 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
2926 #ifndef SUB_SEGMENT_ALIGN
2927 #define SUB_SEGMENT_ALIGN(SEG) 1
2929 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
2930 frag_wane (frag_now
);
2931 frag_now
->fr_fix
= 0;
2932 know (frag_now
->fr_next
== NULL
);
2939 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2941 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
2944 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
2946 /* Find out how big the sections are, and set the addresses. */
2948 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2952 segment_info
[i
].scnhdr
.s_paddr
= addr
;
2953 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
2955 if (segment_info
[i
].scnhdr
.s_name
[0])
2957 H_SET_NUMBER_OF_SECTIONS (&headers
,
2958 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
2961 size
= size_section (abfd
, (unsigned int) i
);
2964 /* I think the section alignment is only used on the i960; the
2965 i960 needs it, and it should do no harm on other targets. */
2966 segment_info
[i
].scnhdr
.s_align
= section_alignment
[i
];
2969 H_SET_TEXT_SIZE (&headers
, size
);
2970 else if (i
== SEG_E1
)
2971 H_SET_DATA_SIZE (&headers
, size
);
2972 else if (i
== SEG_E2
)
2973 H_SET_BSS_SIZE (&headers
, size
);
2976 /* Turn the gas native symbol table shape into a coff symbol table */
2977 crawl_symbols (&headers
, abfd
);
2979 if (string_byte_count
== 4)
2980 string_byte_count
= 0;
2982 H_SET_STRING_SIZE (&headers
, string_byte_count
);
2984 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2986 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
2987 fixup_segment (&segment_info
[i
], i
);
2990 /* Look for ".stab" segments and fill in their initial symbols
2992 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2994 name
= segment_info
[i
].scnhdr
.s_name
;
2997 && strncmp (".stab", name
, 5) == 0
2998 && strncmp (".stabstr", name
, 8) != 0)
2999 adjust_stab_section (abfd
, i
);
3002 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3004 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3006 /* Plant the data */
3008 fill_section (abfd
, &headers
, &file_cursor
);
3010 do_relocs_for (abfd
, &headers
, &file_cursor
);
3012 do_linenos_for (abfd
, &headers
, &file_cursor
);
3014 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3015 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3016 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3018 H_SET_TIME_STAMP (&headers
, 0);
3020 #ifdef TC_COFF_SET_MACHINE
3021 TC_COFF_SET_MACHINE (&headers
);
3025 #define COFF_FLAGS 0
3028 #ifdef KEEP_RELOC_INFO
3029 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3030 COFF_FLAGS
| coff_flags
));
3032 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3033 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3034 COFF_FLAGS
| coff_flags
));
3038 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3039 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3041 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3042 w_symbols (abfd
, buffer1
, symbol_rootP
);
3043 if (string_byte_count
> 0)
3044 w_strings (buffer1
+ symtable_size
);
3045 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3049 coff_header_append (abfd
, &headers
);
3051 /* Recent changes to write need this, but where it should
3052 go is up to Ken.. */
3053 if (bfd_close_all_done (abfd
) == false)
3054 as_fatal ("Can't close %s: %s", out_file_name
,
3055 bfd_errmsg (bfd_get_error ()));
3058 extern bfd
*stdoutput
;
3065 /* Add a new segment. This is called from subseg_new via the
3066 obj_new_segment macro. */
3069 obj_coff_add_segment (name
)
3075 /* Find out if we've already got a section of this name. */
3076 len
= strlen (name
);
3077 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3080 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3081 for (i
= SEG_E0
; i
< SEG_E9
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3082 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3083 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3084 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3089 as_bad ("Too many new sections; can't add \"%s\"", name
);
3093 /* Add a new section. */
3094 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3095 sizeof (segment_info
[i
].scnhdr
.s_name
));
3096 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3102 * implement the .section pseudo op:
3103 * .section name {, "flags"}
3105 * | +--- optional flags: 'b' for bss
3107 * +-- section name 'l' for lib
3111 * 'd' (apparently m88k for data)
3113 * But if the argument is not a quoted string, treat it as a
3114 * subsegment number.
3118 obj_coff_section (ignore
)
3121 /* Strip out the section name */
3123 char *section_name_end
;
3130 section_name
= input_line_pointer
;
3131 c
= get_symbol_end ();
3132 section_name_end
= input_line_pointer
;
3134 len
= section_name_end
- section_name
;
3135 input_line_pointer
++;
3141 else if (*input_line_pointer
== ',')
3144 ++input_line_pointer
;
3152 if (*input_line_pointer
!= '"')
3153 exp
= get_absolute_expression ();
3156 ++input_line_pointer
;
3157 while (*input_line_pointer
!= '"'
3158 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3160 switch (*input_line_pointer
)
3162 case 'b': flags
|= STYP_BSS
; break;
3163 case 'i': flags
|= STYP_INFO
; break;
3164 case 'l': flags
|= STYP_LIB
; break;
3165 case 'n': flags
|= STYP_NOLOAD
; break;
3166 case 'o': flags
|= STYP_OVER
; break;
3168 case 'w': flags
|= STYP_DATA
; break;
3169 case 'x': flags
|= STYP_TEXT
; break;
3171 as_warn("unknown section attribute '%c'",
3172 *input_line_pointer
);
3175 ++input_line_pointer
;
3177 if (*input_line_pointer
== '"')
3178 ++input_line_pointer
;
3182 subseg_new (section_name
, (subsegT
) exp
);
3184 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3186 *section_name_end
= c
;
3191 obj_coff_text (ignore
)
3194 subseg_new (".text", get_absolute_expression ());
3199 obj_coff_data (ignore
)
3202 if (flag_readonly_data_in_text
)
3203 subseg_new (".text", get_absolute_expression () + 1000);
3205 subseg_new (".data", get_absolute_expression ());
3209 obj_coff_bss (ignore
)
3212 if (*input_line_pointer
== '\n') /* .bss */
3213 subseg_new(".bss", get_absolute_expression());
3214 else /* .bss id,expr */
3219 obj_coff_ident (ignore
)
3222 segT current_seg
= now_seg
; /* save current seg */
3223 subsegT current_subseg
= now_subseg
;
3224 subseg_new (".comment", 0); /* .comment seg */
3225 stringer (1); /* read string */
3226 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3230 c_symbol_merge (debug
, normal
)
3234 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3235 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3237 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3239 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3240 } /* take the most we have */
3242 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3244 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3245 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3246 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3247 } /* Move all the auxiliary information */
3249 /* Move the debug flags. */
3250 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3251 } /* c_symbol_merge() */
3254 c_line_new (symbol
, paddr
, line_number
, frag
)
3260 struct lineno_list
*new_line
=
3261 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3263 segment_info_type
*s
= segment_info
+ now_seg
;
3264 new_line
->line
.l_lnno
= line_number
;
3266 if (line_number
== 0)
3268 last_line_symbol
= symbol
;
3269 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3273 new_line
->line
.l_addr
.l_paddr
= paddr
;
3276 new_line
->frag
= (char *) frag
;
3277 new_line
->next
= (struct lineno_list
*) NULL
;
3280 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3282 s
->lineno_list_head
= new_line
;
3286 s
->lineno_list_tail
->next
= new_line
;
3288 s
->lineno_list_tail
= new_line
;
3289 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3293 c_dot_file_symbol (filename
)
3298 symbolP
= symbol_new (".file",
3301 &zero_address_frag
);
3303 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3304 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3306 if (strlen (filename
) > FILNMLEN
)
3308 /* Filename is too long to fit into an auxent,
3309 we stick it into the string table instead. We keep
3310 a linked list of the filenames we find so we can emit
3312 struct filename_list
*f
= xmalloc (sizeof (struct filename_list
));
3314 f
->filename
= filename
;
3317 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3318 SA_SET_FILE_FNAME_OFFSET (symbolP
, 0);
3320 if (filename_list_tail
)
3321 filename_list_tail
->next
= f
;
3323 filename_list_head
= f
;
3324 filename_list_tail
= f
;
3328 SA_SET_FILE_FNAME (symbolP
, filename
);
3335 listing_source_file (filename
);
3341 SF_SET_DEBUG (symbolP
);
3342 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3344 previous_file_symbol
= symbolP
;
3346 /* Make sure that the symbol is first on the symbol chain */
3347 if (symbol_rootP
!= symbolP
)
3349 if (symbolP
== symbol_lastP
)
3351 symbol_lastP
= symbol_lastP
->sy_previous
;
3352 } /* if it was the last thing on the list */
3354 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3355 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3356 symbol_rootP
= symbolP
;
3357 } /* if not first on the list */
3359 } /* c_dot_file_symbol() */
3362 * Build a 'section static' symbol.
3366 c_section_symbol (name
, idx
)
3372 symbolP
= symbol_new (name
, idx
,
3374 &zero_address_frag
);
3376 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3377 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3379 SF_SET_STATICS (symbolP
);
3382 } /* c_section_symbol() */
3385 w_symbols (abfd
, where
, symbol_rootP
)
3388 symbolS
* symbol_rootP
;
3393 /* First fill in those values we have only just worked out */
3394 for (i
= SEG_E0
; i
< SEG_E9
; i
++)
3396 symbolP
= segment_info
[i
].dot
;
3399 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3400 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3401 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3406 * Emit all symbols left in the symbol chain.
3408 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3410 /* Used to save the offset of the name. It is used to point
3411 to the string in memory but must be a file offset. */
3412 register char *temp
;
3414 tc_coff_symbol_emit_hook (symbolP
);
3416 temp
= S_GET_NAME (symbolP
);
3417 if (SF_GET_STRING (symbolP
))
3419 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3420 S_SET_ZEROES (symbolP
, 0);
3424 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3425 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3427 where
= symbol_to_chars (abfd
, where
, symbolP
);
3428 S_SET_NAME (symbolP
, temp
);
3434 obj_coff_lcomm (ignore
)
3447 name
= input_line_pointer
;
3449 c
= get_symbol_end ();
3450 p
= input_line_pointer
;
3453 if (*input_line_pointer
!= ',')
3455 as_bad ("Expected comma after name");
3456 ignore_rest_of_line ();
3459 if (*input_line_pointer
== '\n')
3461 as_bad ("Missing size expression");
3464 input_line_pointer
++;
3465 if ((temp
= get_absolute_expression ()) < 0)
3467 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3468 ignore_rest_of_line ();
3473 symbolP
= symbol_find_or_make(name
);
3475 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3476 S_GET_VALUE(symbolP
) == 0)
3481 segT current_seg
= now_seg
; /* save current seg */
3482 subsegT current_subseg
= now_subseg
;
3484 subseg_set (SEG_E2
, 1);
3485 symbolP
->sy_frag
= frag_now
;
3486 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3489 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3490 S_SET_SEGMENT(symbolP
, SEG_E2
);
3491 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3495 as_bad("Symbol %s already defined", name
);
3497 demand_empty_rest_of_line();
3502 fixup_mdeps (frags
, h
, this_segment
)
3507 subseg_change (this_segment
, 0);
3510 switch (frags
->fr_type
)
3514 frags
->fr_type
= rs_fill
;
3516 (frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
);
3518 case rs_machine_dependent
:
3519 md_convert_frag (h
, frags
);
3525 frags
= frags
->fr_next
;
3531 fixup_segment (segP
, this_segment_type
)
3532 segment_info_type
* segP
;
3533 segT this_segment_type
;
3535 register fixS
* fixP
;
3536 register symbolS
*add_symbolP
;
3537 register symbolS
*sub_symbolP
;
3538 register long add_number
;
3540 register char *place
;
3541 register long where
;
3542 register char pcrel
;
3543 register fragS
*fragP
;
3544 register segT add_symbol_segment
= absolute_section
;
3549 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3551 fragP
= fixP
->fx_frag
;
3553 where
= fixP
->fx_where
;
3554 place
= fragP
->fr_literal
+ where
;
3555 size
= fixP
->fx_size
;
3556 add_symbolP
= fixP
->fx_addsy
;
3558 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3560 /* Relocation should be done via the associated 'bal' entry
3563 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3565 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3566 "No 'bal' entry point for leafproc %s",
3567 S_GET_NAME (add_symbolP
));
3570 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3573 sub_symbolP
= fixP
->fx_subsy
;
3574 add_number
= fixP
->fx_offset
;
3575 pcrel
= fixP
->fx_pcrel
;
3579 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3580 } /* if there is an addend */
3587 if (S_GET_SEGMENT (sub_symbolP
) != absolute_section
)
3589 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3590 "Negative of non-absolute symbol %s",
3591 S_GET_NAME (sub_symbolP
));
3592 } /* not absolute */
3594 add_number
-= S_GET_VALUE (sub_symbolP
);
3597 /* if sub_symbol is in the same segment that add_symbol
3598 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3600 else if ((S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
)
3601 && (SEG_NORMAL (add_symbol_segment
)
3602 || (add_symbol_segment
== absolute_section
)))
3604 /* Difference of 2 symbols from same segment. Can't
3605 make difference of 2 undefineds: 'value' means
3606 something different for N_UNDF. */
3608 /* Makes no sense to use the difference of 2 arbitrary symbols
3609 as the target of a call instruction. */
3612 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3613 "callj to difference of 2 symbols");
3615 #endif /* TC_I960 */
3616 add_number
+= S_GET_VALUE (add_symbolP
) -
3617 S_GET_VALUE (sub_symbolP
);
3620 fixP
->fx_addsy
= NULL
;
3621 fixP
->fx_subsy
= NULL
;
3626 /* Different segments in subtraction. */
3627 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3629 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3631 add_number
-= S_GET_VALUE (sub_symbolP
);
3634 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3635 #if 0 /* Okay for 68k, at least... */
3640 /* Make it pc-relative. */
3641 add_number
+= (md_pcrel_from (fixP
)
3642 - S_GET_VALUE (sub_symbolP
));
3651 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3652 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3653 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3654 S_GET_NAME (sub_symbolP
),
3655 (long) (fragP
->fr_address
+ where
));
3658 } /* if sub_symbolP */
3662 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3665 * This fixup was made when the symbol's segment was
3666 * SEG_UNKNOWN, but it is now in the local segment.
3667 * So we know how to do the address without relocation.
3670 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3671 * in which cases it modifies *fixP as appropriate. In the case
3672 * of a 'calls', no further work is required, and *fixP has been
3673 * set up to make the rest of the code below a no-op.
3676 #endif /* TC_I960 */
3678 add_number
+= S_GET_VALUE (add_symbolP
);
3679 add_number
-= md_pcrel_from (fixP
);
3680 #if defined (TC_I386) || defined (TE_LYNX)
3681 /* On the 386 we must adjust by the segment
3682 vaddr as well. Ian Taylor. */
3683 add_number
-= segP
->scnhdr
.s_vaddr
;
3685 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3686 fixP
->fx_addsy
= NULL
;
3691 switch (add_symbol_segment
)
3693 case absolute_section
:
3695 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3696 #endif /* TC_I960 */
3697 add_number
+= S_GET_VALUE (add_symbolP
);
3698 fixP
->fx_addsy
= NULL
;
3705 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386))
3706 /* This really should be handled in the linker, but
3707 backward compatibility forbids. */
3708 add_number
+= S_GET_VALUE (add_symbolP
);
3710 add_number
+= S_GET_VALUE (add_symbolP
) +
3711 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3717 if ((int) fixP
->fx_bit_fixP
== 13)
3719 /* This is a COBR instruction. They have only a
3720 * 13-bit displacement and are only to be used
3721 * for local branches: flag as error, don't generate
3724 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3725 "can't use COBR format with external label");
3726 fixP
->fx_addsy
= NULL
;
3730 #endif /* TC_I960 */
3731 #if (defined (TC_I386) || defined (TE_LYNX)) && !defined(TE_PE)
3732 /* 386 COFF uses a peculiar format in which the
3733 value of a common symbol is stored in the .text
3734 segment (I've checked this on SVR3.2 and SCO
3735 3.2.2) Ian Taylor <ian@cygnus.com>. */
3736 if (S_IS_COMMON (add_symbolP
))
3737 add_number
+= S_GET_VALUE (add_symbolP
);
3742 } /* switch on symbol seg */
3743 } /* if not in local seg */
3744 } /* if there was a + symbol */
3748 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386))
3749 /* This adjustment is not correct on the m88k, for which the
3750 linker does all the computation. */
3751 add_number
-= md_pcrel_from (fixP
);
3753 if (add_symbolP
== 0)
3755 fixP
->fx_addsy
= &abs_symbol
;
3756 } /* if there's an add_symbol */
3757 #if defined (TC_I386) || defined (TE_LYNX)
3758 /* On the 386 we must adjust by the segment vaddr
3759 as well. Ian Taylor. */
3760 add_number
-= segP
->scnhdr
.s_vaddr
;
3764 if (!fixP
->fx_bit_fixP
)
3767 /* The m88k uses the offset field of the reloc to get around
3770 && (add_number
& ~0xFF)
3771 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
3773 && (add_number
& ~0xFFFF)
3774 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
3776 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3777 "Value of %ld too large for field of %d bytes at 0x%lx",
3778 (long) add_number
, size
,
3779 (unsigned long) (fragP
->fr_address
+ where
));
3782 #ifdef WARN_SIGNED_OVERFLOW_WORD
3783 /* Warn if a .word value is too large when treated as a
3784 signed number. We already know it is not too negative.
3785 This is to catch over-large switches generated by gcc on
3787 if (!flag_signed_overflow_ok
3789 && add_number
> 0x7fff)
3790 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3791 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
3793 (unsigned long) (fragP
->fr_address
+ where
));
3795 } /* not a bit fix */
3796 /* Once this fix has been applied, we don't have to output
3797 anything nothing more need be done. */
3798 md_apply_fix (fixP
, add_number
);
3799 } /* For each fixS in this segment. */
3800 } /* fixup_segment() */
3804 /* The first entry in a .stab section is special. */
3807 obj_coff_init_stab_section (seg
)
3813 unsigned int stroff
;
3815 /* Make space for this first symbol. */
3819 as_where (&file
, (unsigned int *) NULL
);
3820 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
3821 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
3822 strcat (stabstr_name
, "str");
3823 stroff
= get_stab_string_offset (file
, stabstr_name
);
3825 md_number_to_chars (p
, stroff
, 4);
3828 /* Fill in the counts in the first entry in a .stab section. */
3831 adjust_stab_section(abfd
, seg
)
3835 segT stabstrseg
= SEG_UNKNOWN
;
3836 char *secname
, *name
, *name2
;
3838 int i
, strsz
= 0, nsyms
;
3839 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
3841 /* Look for the associated string table section. */
3843 secname
= segment_info
[seg
].scnhdr
.s_name
;
3844 name
= (char *) alloca (strlen (secname
) + 4);
3845 strcpy (name
, secname
);
3846 strcat (name
, "str");
3848 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3850 name2
= segment_info
[i
].scnhdr
.s_name
;
3851 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
3858 /* If we found the section, get its size. */
3859 if (stabstrseg
!= SEG_UNKNOWN
)
3860 strsz
= size_section (abfd
, stabstrseg
);
3862 nsyms
= size_section (abfd
, seg
) / 12 - 1;
3864 /* Look for the first frag of sufficient size for the initial stab
3865 symbol, and collect a pointer to it. */
3866 while (frag
&& frag
->fr_fix
< 12)
3867 frag
= frag
->fr_next
;
3869 p
= frag
->fr_literal
;
3872 /* Write in the number of stab symbols and the size of the string
3874 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
3875 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
3878 #endif /* not BFD_ASSEMBLER */
3880 const pseudo_typeS obj_pseudo_table
[] =
3882 {"def", obj_coff_def
, 0},
3883 {"dim", obj_coff_dim
, 0},
3884 {"endef", obj_coff_endef
, 0},
3885 {"line", obj_coff_line
, 0},
3886 {"ln", obj_coff_ln
, 0},
3887 {"appline", obj_coff_ln
, 1},
3888 {"scl", obj_coff_scl
, 0},
3889 {"size", obj_coff_size
, 0},
3890 {"tag", obj_coff_tag
, 0},
3891 {"type", obj_coff_type
, 0},
3892 {"val", obj_coff_val
, 0},
3893 {"section", obj_coff_section
, 0},
3894 #ifndef BFD_ASSEMBLER
3895 {"use", obj_coff_section
, 0},
3896 {"sect", obj_coff_section
, 0},
3897 {"text", obj_coff_text
, 0},
3898 {"data", obj_coff_data
, 0},
3899 {"bss", obj_coff_bss
, 0},
3900 {"lcomm", obj_coff_lcomm
, 0},
3901 {"ident", obj_coff_ident
, 0},
3903 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
3904 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
3906 {"ABORT", s_abort
, 0},
3908 /* The m88k uses sdef instead of def. */
3909 {"sdef", obj_coff_def
, 0},
3911 {NULL
} /* end sentinel */
3912 }; /* obj_pseudo_table */