1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 1996
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
26 /* I think this is probably always correct. */
27 #ifndef KEEP_RELOC_INFO
28 #define KEEP_RELOC_INFO
32 /* structure used to keep the filenames which
33 are too long around so that we can stick them
34 into the string table */
38 struct filename_list
*next
;
41 static struct filename_list
*filename_list_head
;
42 static struct filename_list
*filename_list_tail
;
44 const char *s_get_name
PARAMS ((symbolS
* s
));
45 static symbolS
*def_symbol_in_progress
;
51 unsigned long chunk_size
;
52 unsigned long element_size
;
55 unsigned long pointer
;
60 stack_init (chunk_size
, element_size
)
61 unsigned long chunk_size
;
62 unsigned long element_size
;
66 st
= (stack
*) malloc (sizeof (stack
));
69 st
->data
= malloc (chunk_size
);
76 st
->size
= chunk_size
;
77 st
->chunk_size
= chunk_size
;
78 st
->element_size
= element_size
;
83 /* Not currently used. */
94 stack_push (st
, element
)
98 if (st
->pointer
+ st
->element_size
>= st
->size
)
100 st
->size
+= st
->chunk_size
;
101 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
104 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
105 st
->pointer
+= st
->element_size
;
106 return st
->data
+ st
->pointer
;
113 if (st
->pointer
< st
->element_size
)
118 st
->pointer
-= st
->element_size
;
119 return st
->data
+ st
->pointer
;
123 * Maintain a list of the tagnames of the structres.
126 static struct hash_control
*tag_hash
;
131 tag_hash
= hash_new ();
135 tag_insert (name
, symbolP
)
139 const char *error_string
;
141 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
143 as_fatal ("Inserting \"%s\" into structure table failed: %s",
152 #ifdef STRIP_UNDERSCORE
155 #endif /* STRIP_UNDERSCORE */
156 return (symbolS
*) hash_find (tag_hash
, name
);
160 tag_find_or_make (name
)
165 if ((symbolP
= tag_find (name
)) == NULL
)
167 symbolP
= symbol_new (name
, undefined_section
,
168 0, &zero_address_frag
);
170 tag_insert (S_GET_NAME (symbolP
), symbolP
);
172 symbol_table_insert (symbolP
);
183 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
185 #define GET_FILENAME_STRING(X) \
186 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
190 fetch_coff_debug_section ()
192 static segT debug_section
;
196 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
198 debug_section
= s
->section
;
200 return debug_section
;
204 SA_SET_SYM_ENDNDX (sym
, val
)
208 combined_entry_type
*entry
, *p
;
210 entry
= &coffsymbol (sym
->bsym
)->native
[1];
211 p
= coffsymbol (val
->bsym
)->native
;
212 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
217 SA_SET_SYM_TAGNDX (sym
, val
)
221 combined_entry_type
*entry
, *p
;
223 entry
= &coffsymbol (sym
->bsym
)->native
[1];
224 p
= coffsymbol (val
->bsym
)->native
;
225 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
230 S_GET_DATA_TYPE (sym
)
233 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
237 S_SET_DATA_TYPE (sym
, val
)
241 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
246 S_GET_STORAGE_CLASS (sym
)
249 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
253 S_SET_STORAGE_CLASS (sym
, val
)
257 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
261 /* Merge a debug symbol containing debug information into a normal symbol. */
264 c_symbol_merge (debug
, normal
)
268 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
269 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
271 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
272 /* take the most we have */
273 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
275 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
277 /* Move all the auxiliary information. */
278 /* @@ How many fields do we want to preserve? Would it make more
279 sense to pick and choose those we want to copy? Should look
280 into this further.... [raeburn:19920512.2209EST] */
282 linenos
= coffsymbol (normal
->bsym
)->lineno
;
283 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
284 (char *) &coffsymbol (debug
->bsym
)->native
,
285 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
286 coffsymbol (normal
->bsym
)->lineno
= linenos
;
289 /* Move the debug flags. */
290 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
293 static symbolS
*previous_file_symbol
;
295 c_dot_file_symbol (filename
)
300 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
302 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
303 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
305 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
312 listing_source_file (filename
);
317 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
319 previous_file_symbol
= symbolP
;
321 /* Make sure that the symbol is first on the symbol chain */
322 if (symbol_rootP
!= symbolP
)
324 if (symbolP
== symbol_lastP
)
326 symbol_lastP
= symbol_lastP
->sy_previous
;
327 } /* if it was the last thing on the list */
329 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
330 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
331 symbol_rootP
= symbolP
;
332 } /* if not first on the list */
336 * Build a 'section static' symbol.
340 c_section_symbol (name
, value
, length
, nreloc
, nlnno
)
344 unsigned short nreloc
;
345 unsigned short nlnno
;
349 symbolP
= symbol_new (name
,
358 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
359 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
361 SA_SET_SCN_SCNLEN (symbolP
, length
);
362 SA_SET_SCN_NRELOC (symbolP
, nreloc
);
363 SA_SET_SCN_NLINNO (symbolP
, nlnno
);
365 SF_SET_STATICS (symbolP
);
367 return (char *) symbolP
;
370 /* Line number handling */
373 struct line_no
*next
;
380 /* Symbol of last function, which we should hang line#s off of. */
381 static symbolS
*line_fsym
;
383 #define in_function() (line_fsym != 0)
384 #define clear_function() (line_fsym = 0)
385 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
389 obj_symbol_new_hook (symbolP
)
392 char underscore
= 0; /* Symbol has leading _ */
395 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
396 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
398 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
400 S_SET_DATA_TYPE (symbolP
, T_NULL
);
401 S_SET_STORAGE_CLASS (symbolP
, 0);
402 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
404 if (S_IS_STRING (symbolP
))
405 SF_SET_STRING (symbolP
);
406 if (!underscore
&& S_IS_LOCAL (symbolP
))
407 SF_SET_LOCAL (symbolP
);
412 * Handle .ln directives.
415 static symbolS
*current_lineno_sym
;
416 static struct line_no
*line_nos
;
417 /* @@ Blindly assume all .ln directives will be in the .text section... */
421 add_lineno (frag
, offset
, num
)
426 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
427 sizeof (struct line_no
));
428 if (!current_lineno_sym
)
432 new_line
->next
= line_nos
;
433 new_line
->frag
= frag
;
434 new_line
->l
.line_number
= num
;
435 new_line
->l
.u
.offset
= offset
;
441 coff_add_linesym (sym
)
446 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
450 current_lineno_sym
= sym
;
454 obj_coff_ln (appline
)
459 if (! appline
&& def_symbol_in_progress
!= NULL
)
461 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
462 demand_empty_rest_of_line ();
466 l
= get_absolute_expression ();
469 add_lineno (frag_now
, frag_now_fix (), l
);
479 l
+= coff_line_base
- 1;
480 listing_source_line (l
);
485 demand_empty_rest_of_line ();
491 * Handle .def directives.
493 * One might ask : why can't we symbol_new if the symbol does not
494 * already exist and fill it with debug information. Because of
495 * the C_EFCN special symbol. It would clobber the value of the
496 * function symbol before we have a chance to notice that it is
497 * a C_EFCN. And a second reason is that the code is more clear this
498 * way. (at least I think it is :-).
502 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
503 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
504 *input_line_pointer == '\t') \
505 input_line_pointer++;
511 char name_end
; /* Char after the end of name */
512 char *symbol_name
; /* Name of the debug symbol */
513 char *symbol_name_copy
; /* Temporary copy of the name */
514 unsigned int symbol_name_length
;
516 if (def_symbol_in_progress
!= NULL
)
518 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
519 demand_empty_rest_of_line ();
521 } /* if not inside .def/.endef */
525 symbol_name
= input_line_pointer
;
526 #ifdef STRIP_UNDERSCORE
527 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
529 #endif /* STRIP_UNDERSCORE */
531 name_end
= get_symbol_end ();
532 symbol_name_length
= strlen (symbol_name
);
533 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
534 strcpy (symbol_name_copy
, symbol_name
);
536 /* Initialize the new symbol */
537 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
538 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
539 S_SET_VALUE (def_symbol_in_progress
, 0);
541 if (S_IS_STRING (def_symbol_in_progress
))
542 SF_SET_STRING (def_symbol_in_progress
);
544 *input_line_pointer
= name_end
;
546 demand_empty_rest_of_line ();
549 unsigned int dim_index
;
552 obj_coff_endef (ignore
)
556 /* DIM BUG FIX sac@cygnus.com */
558 if (def_symbol_in_progress
== NULL
)
560 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
561 demand_empty_rest_of_line ();
563 } /* if not inside .def/.endef */
565 /* Set the section number according to storage class. */
566 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
571 SF_SET_TAG (def_symbol_in_progress
);
572 /* intentional fallthrough */
575 SF_SET_DEBUG (def_symbol_in_progress
);
576 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
580 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
581 /* intentional fallthrough */
583 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
584 /* intentional fallthrough */
588 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
590 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
591 if (name
[1] == 'b' && name
[2] == 'f')
593 if (! in_function ())
594 as_warn ("`%s' symbol without preceding function", name
);
595 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
596 /* Will need relocating */
597 SF_SET_PROCESS (def_symbol_in_progress
);
605 #endif /* C_AUTOARG */
615 SF_SET_DEBUG (def_symbol_in_progress
);
616 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
622 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
628 as_warn ("unexpected storage class %d",
629 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
631 } /* switch on storage class */
633 /* Now that we have built a debug symbol, try to find if we should
634 merge with an existing symbol or not. If a symbol is C_EFCN or
635 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
637 /* Two cases for functions. Either debug followed by definition or
638 definition followed by debug. For definition first, we will
639 merge the debug symbol into the definition. For debug first, the
640 lineno entry MUST point to the definition function or else it
641 will point off into space when obj_crawl_symbol_chain() merges
642 the debug symbol into the real symbol. Therefor, let's presume
643 the debug symbol is a real function reference. */
645 /* FIXME-SOON If for some reason the definition label/symbol is
646 never seen, this will probably leave an undefined symbol at link
649 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
650 || (!strcmp (bfd_get_section_name (stdoutput
,
651 S_GET_SEGMENT (def_symbol_in_progress
)),
653 && !SF_GET_TAG (def_symbol_in_progress
))
654 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
655 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
657 if (def_symbol_in_progress
!= symbol_lastP
)
658 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
663 /* This symbol already exists, merge the newly created symbol
664 into the old one. This is not mandatory. The linker can
665 handle duplicate symbols correctly. But I guess that it save
666 a *lot* of space if the assembly file defines a lot of
669 /* The debug entry (def_symbol_in_progress) is merged into the
670 previous definition. */
672 c_symbol_merge (def_symbol_in_progress
, symbolP
);
673 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
674 def_symbol_in_progress
= symbolP
;
676 if (SF_GET_FUNCTION (def_symbol_in_progress
)
677 || SF_GET_TAG (def_symbol_in_progress
))
679 /* For functions, and tags, the symbol *must* be where the
680 debug symbol appears. Move the existing symbol to the
682 /* If it already is at the end of the symbol list, do nothing */
683 if (def_symbol_in_progress
!= symbol_lastP
)
685 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
686 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
691 if (SF_GET_TAG (def_symbol_in_progress
)
692 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
694 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
697 if (SF_GET_FUNCTION (def_symbol_in_progress
))
699 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
700 set_function (def_symbol_in_progress
);
701 SF_SET_PROCESS (def_symbol_in_progress
);
705 /* That is, if this is the first time we've seen the
707 symbol_table_insert (def_symbol_in_progress
);
708 } /* definition follows debug */
709 } /* Create the line number entry pointing to the function being defined */
711 def_symbol_in_progress
= NULL
;
712 demand_empty_rest_of_line ();
716 obj_coff_dim (ignore
)
721 if (def_symbol_in_progress
== NULL
)
723 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
724 demand_empty_rest_of_line ();
726 } /* if not inside .def/.endef */
728 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
730 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
733 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
734 get_absolute_expression ());
736 switch (*input_line_pointer
)
739 input_line_pointer
++;
743 as_warn ("badly formed .dim directive ignored");
744 /* intentional fallthrough */
752 demand_empty_rest_of_line ();
756 obj_coff_line (ignore
)
761 if (def_symbol_in_progress
== NULL
)
763 /* Probably stabs-style line? */
768 this_base
= get_absolute_expression ();
769 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
770 coff_line_base
= this_base
;
772 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
773 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
775 demand_empty_rest_of_line ();
778 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
783 listing_source_line ((unsigned int) coff_line_base
);
789 obj_coff_size (ignore
)
792 if (def_symbol_in_progress
== NULL
)
794 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
795 demand_empty_rest_of_line ();
797 } /* if not inside .def/.endef */
799 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
800 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
801 demand_empty_rest_of_line ();
805 obj_coff_scl (ignore
)
808 if (def_symbol_in_progress
== NULL
)
810 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
811 demand_empty_rest_of_line ();
813 } /* if not inside .def/.endef */
815 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
816 demand_empty_rest_of_line ();
820 obj_coff_tag (ignore
)
826 if (def_symbol_in_progress
== NULL
)
828 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
829 demand_empty_rest_of_line ();
833 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
834 symbol_name
= input_line_pointer
;
835 name_end
= get_symbol_end ();
837 /* Assume that the symbol referred to by .tag is always defined.
838 This was a bad assumption. I've added find_or_make. xoxorich. */
839 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
840 tag_find_or_make (symbol_name
));
841 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
843 as_warn ("tag not found for .tag %s", symbol_name
);
846 SF_SET_TAGGED (def_symbol_in_progress
);
847 *input_line_pointer
= name_end
;
849 demand_empty_rest_of_line ();
853 obj_coff_type (ignore
)
856 if (def_symbol_in_progress
== NULL
)
858 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
859 demand_empty_rest_of_line ();
861 } /* if not inside .def/.endef */
863 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
865 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
866 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
868 SF_SET_FUNCTION (def_symbol_in_progress
);
869 } /* is a function */
871 demand_empty_rest_of_line ();
875 obj_coff_val (ignore
)
878 if (def_symbol_in_progress
== NULL
)
880 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
881 demand_empty_rest_of_line ();
883 } /* if not inside .def/.endef */
885 if (is_name_beginner (*input_line_pointer
))
887 char *symbol_name
= input_line_pointer
;
888 char name_end
= get_symbol_end ();
890 if (!strcmp (symbol_name
, "."))
892 def_symbol_in_progress
->sy_frag
= frag_now
;
893 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
894 /* If the .val is != from the .def (e.g. statics) */
896 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
898 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
899 def_symbol_in_progress
->sy_value
.X_add_symbol
=
900 symbol_find_or_make (symbol_name
);
901 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
902 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
904 /* If the segment is undefined when the forward reference is
905 resolved, then copy the segment id from the forward
907 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
909 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
910 *input_line_pointer
= name_end
;
914 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
915 } /* if symbol based */
917 demand_empty_rest_of_line ();
921 obj_read_begin_hook ()
923 /* These had better be the same. Usually 18 bytes. */
925 know (sizeof (SYMENT
) == sizeof (AUXENT
));
926 know (SYMESZ
== AUXESZ
);
932 symbolS
*coff_last_function
;
933 static symbolS
*coff_last_bf
;
936 coff_frob_symbol (symp
, punt
)
940 static symbolS
*last_tagP
;
941 static stack
*block_stack
;
942 static symbolS
*set_end
;
943 symbolS
*next_set_end
= NULL
;
945 if (symp
== &abs_symbol
)
951 if (current_lineno_sym
)
952 coff_add_linesym ((symbolS
*) 0);
955 block_stack
= stack_init (512, sizeof (symbolS
*));
957 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
958 S_SET_STORAGE_CLASS (symp
, C_EXT
);
960 if (!SF_GET_DEBUG (symp
))
963 if (!SF_GET_LOCAL (symp
)
964 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
967 c_symbol_merge (symp
, real
);
970 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
972 assert (S_GET_VALUE (symp
) == 0);
973 S_SET_EXTERNAL (symp
);
975 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
977 if (S_GET_SEGMENT (symp
) == text_section
978 && symp
!= seg_info (text_section
)->sym
)
979 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
981 S_SET_STORAGE_CLASS (symp
, C_STAT
);
983 if (SF_GET_PROCESS (symp
))
985 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
987 if (!strcmp (S_GET_NAME (symp
), ".bb"))
988 stack_push (block_stack
, (char *) &symp
);
992 begin
= *(symbolS
**) stack_pop (block_stack
);
994 as_warn ("mismatched .eb");
996 next_set_end
= begin
;
999 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1001 union internal_auxent
*auxp
;
1002 coff_last_function
= symp
;
1003 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1004 S_SET_NUMBER_AUXILIARY (symp
, 1);
1005 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
1006 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1007 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1009 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1011 if (coff_last_function
== 0)
1012 as_fatal ("C_EFCN symbol out of scope");
1013 SA_SET_SYM_FSIZE (coff_last_function
,
1014 (long) (S_GET_VALUE (symp
)
1015 - S_GET_VALUE (coff_last_function
)));
1016 next_set_end
= coff_last_function
;
1017 coff_last_function
= 0;
1020 else if (SF_GET_TAG (symp
))
1022 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1023 next_set_end
= last_tagP
;
1024 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1026 if (S_GET_VALUE (symp
))
1028 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1029 S_SET_VALUE (symp
, 0);
1032 if (S_IS_EXTERNAL (symp
))
1033 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1034 else if (SF_GET_LOCAL (symp
))
1037 if (SF_GET_FUNCTION (symp
))
1038 symp
->bsym
->flags
|= BSF_FUNCTION
;
1044 /* This is pretty horrible, but we have to set *punt correctly in
1045 order to call SA_SET_SYM_ENDNDX correctly. */
1046 if (! symp
->sy_used_in_reloc
1047 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1048 || (! S_IS_EXTERNAL (symp
)
1049 && ! symp
->sy_tc
.output
1050 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1054 if (set_end
!= (symbolS
*) NULL
1057 SA_SET_SYM_ENDNDX (set_end
, symp
);
1061 if (next_set_end
!= NULL
1063 set_end
= next_set_end
;
1066 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1067 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1069 if (coff_last_bf
!= NULL
)
1070 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1071 coff_last_bf
= symp
;
1074 if (coffsymbol (symp
->bsym
)->lineno
)
1077 struct line_no
*lptr
;
1080 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1081 for (i
= 0; lptr
; lptr
= lptr
->next
)
1083 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1085 /* We need i entries for line numbers, plus 1 for the first
1086 entry which BFD will override, plus 1 for the last zero
1087 entry (a marker for BFD). */
1088 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1089 coffsymbol (symp
->bsym
)->lineno
= l
;
1090 l
[i
+ 1].line_number
= 0;
1091 l
[i
+ 1].u
.sym
= NULL
;
1095 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1103 coff_adjust_section_syms (abfd
, sec
, x
)
1109 segment_info_type
*seginfo
= seg_info (sec
);
1110 int nlnno
, nrelocs
= 0;
1112 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1113 tc-ppc.c. Do not get confused by it. */
1114 if (seginfo
== NULL
)
1117 if (!strcmp (sec
->name
, ".text"))
1118 nlnno
= coff_n_line_nos
;
1122 /* @@ Hope that none of the fixups expand to more than one reloc
1124 fixS
*fixp
= seginfo
->fix_root
;
1127 fixp
= fixp
->fx_next
;
1131 if (bfd_get_section_size_before_reloc (sec
) == 0
1132 && nrelocs
== 0 && nlnno
== 0)
1134 secsym
= section_symbol (sec
);
1135 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1136 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1142 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1146 * implement the .section pseudo op:
1147 * .section name {, "flags"}
1149 * | +--- optional flags: 'b' for bss
1151 * +-- section name 'l' for lib
1155 * 'd' (apparently m88k for data)
1157 * But if the argument is not a quoted string, treat it as a
1158 * subsegment number.
1162 obj_coff_section (ignore
)
1165 /* Strip out the section name */
1181 section_name
= input_line_pointer
;
1182 c
= get_symbol_end ();
1184 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1185 strcpy (name
, section_name
);
1187 *input_line_pointer
= c
;
1192 flags
= SEC_NO_FLAGS
;
1194 if (*input_line_pointer
== ',')
1196 ++input_line_pointer
;
1198 if (*input_line_pointer
!= '"')
1199 exp
= get_absolute_expression ();
1202 ++input_line_pointer
;
1203 while (*input_line_pointer
!= '"'
1204 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1206 switch (*input_line_pointer
)
1208 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1209 case 'n': flags
&=~ SEC_LOAD
; break;
1211 case 'w': flags
&=~ SEC_READONLY
; break;
1212 case 'x': flags
|= SEC_CODE
; break;
1214 case 'i': /* STYP_INFO */
1215 case 'l': /* STYP_LIB */
1216 case 'o': /* STYP_OVER */
1217 as_warn ("unsupported section attribute '%c'",
1218 *input_line_pointer
);
1222 as_warn("unknown section attribute '%c'",
1223 *input_line_pointer
);
1226 ++input_line_pointer
;
1228 if (*input_line_pointer
== '"')
1229 ++input_line_pointer
;
1233 sec
= subseg_new (name
, (subsegT
) exp
);
1235 if (flags
!= SEC_NO_FLAGS
)
1237 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1238 as_warn ("error setting flags for \"%s\": %s",
1239 bfd_section_name (stdoutput
, sec
),
1240 bfd_errmsg (bfd_get_error ()));
1245 coff_adjust_symtab ()
1247 if (symbol_rootP
== NULL
1248 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1250 assert (previous_file_symbol
== 0);
1251 c_dot_file_symbol ("fake");
1256 coff_frob_section (sec
)
1262 bfd_vma size
, n_entries
, mask
;
1264 /* The COFF back end in BFD requires that all section sizes be
1265 rounded up to multiples of the corresponding section alignments.
1266 Seems kinda silly to me, but that's the way it is. */
1267 size
= bfd_get_section_size_before_reloc (sec
);
1268 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1271 size
= (size
+ mask
) & ~mask
;
1272 bfd_set_section_size (stdoutput
, sec
, size
);
1275 /* If the section size is non-zero, the section symbol needs an aux
1276 entry associated with it, indicating the size. We don't know
1277 all the values yet; coff_frob_symbol will fill them in later. */
1280 symbolS
*secsym
= section_symbol (sec
);
1282 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1283 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1284 SF_SET_STATICS (secsym
);
1285 SA_SET_SCN_SCNLEN (secsym
, size
);
1288 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1289 #ifndef STAB_SECTION_NAME
1290 #define STAB_SECTION_NAME ".stab"
1292 #ifndef STAB_STRING_SECTION_NAME
1293 #define STAB_STRING_SECTION_NAME ".stabstr"
1295 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1299 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1300 /* size is already rounded up, since other section will be listed first */
1301 size
= bfd_get_section_size_before_reloc (strsec
);
1303 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1305 /* Find first non-empty frag. It should be large enough. */
1306 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1307 while (fragp
&& fragp
->fr_fix
== 0)
1308 fragp
= fragp
->fr_next
;
1309 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1311 /* Store the values. */
1312 p
= fragp
->fr_literal
;
1313 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1314 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1318 obj_coff_init_stab_section (seg
)
1324 unsigned int stroff
;
1326 /* Make space for this first symbol. */
1330 as_where (&file
, (unsigned int *) NULL
);
1331 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1332 strcpy (stabstr_name
, seg
->name
);
1333 strcat (stabstr_name
, "str");
1334 stroff
= get_stab_string_offset (file
, stabstr_name
);
1336 md_number_to_chars (p
, stroff
, 4);
1345 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1353 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1355 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1356 (unsigned long) symbolP
,
1357 S_GET_NAME(symbolP
),
1358 (long) S_GET_DATA_TYPE(symbolP
),
1359 S_GET_STORAGE_CLASS(symbolP
),
1360 (int) S_GET_SEGMENT(symbolP
));
1366 #else /* not BFD_ASSEMBLER */
1369 /* This is needed because we include internal bfd things. */
1373 #include "libcoff.h"
1376 #include "coff/pe.h"
1379 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1380 that we can stick sections together without causing trouble. */
1382 #define NOP_OPCODE 0x00
1385 /* The zeroes if symbol name is longer than 8 chars */
1386 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1388 #define MIN(a,b) ((a) < (b)? (a) : (b))
1389 /* This vector is used to turn an internal segment into a section #
1390 suitable for insertion into a coff symbol table
1393 const short seg_N_TYPE
[] =
1394 { /* in: segT out: N_TYPE bits */
1396 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1397 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1398 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1399 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1400 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1401 C_UNDEF_SECTION
, /* SEG_GOOF */
1402 C_UNDEF_SECTION
, /* SEG_EXPR */
1403 C_DEBUG_SECTION
, /* SEG_DEBUG */
1404 C_NTV_SECTION
, /* SEG_NTV */
1405 C_PTV_SECTION
, /* SEG_PTV */
1406 C_REGISTER_SECTION
, /* SEG_REGISTER */
1409 int function_lineoff
= -1; /* Offset in line#s where the last function
1410 started (the odd entry for line #0) */
1412 static symbolS
*last_line_symbol
;
1414 /* Add 4 to the real value to get the index and compensate the
1415 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1416 section number into a segment number
1418 static symbolS
*previous_file_symbol
;
1419 void c_symbol_merge ();
1420 static int line_base
;
1422 symbolS
*c_section_symbol ();
1425 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1426 segT this_segment_type
));
1429 static void fixup_mdeps
PARAMS ((fragS
*,
1434 static void fill_section
PARAMS ((bfd
* abfd
,
1439 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1444 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1445 symbolS
* symbol_rootP
));
1447 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1449 static void obj_coff_lcomm
PARAMS ((int));
1450 static void obj_coff_text
PARAMS ((int));
1451 static void obj_coff_data
PARAMS ((int));
1452 static void obj_coff_bss
PARAMS ((int));
1453 static void obj_coff_ident
PARAMS ((int));
1454 void obj_coff_section
PARAMS ((int));
1458 We allow more than just the standard 3 sections, infact, we allow
1459 40 sections, (though the usual three have to be there).
1461 This structure performs the mappings for us:
1471 static const seg_info_type seg_info_off_by_4
[] =
1478 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1479 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1480 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1481 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1482 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1483 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1484 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1485 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1500 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1502 static relax_addressT
1503 relax_align (address
, alignment
)
1504 relax_addressT address
;
1507 relax_addressT mask
;
1508 relax_addressT new_address
;
1510 mask
= ~((~0) << alignment
);
1511 new_address
= (address
+ mask
) & (~mask
);
1512 return (new_address
- address
);
1520 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1525 /* calculate the size of the frag chain and fill in the section header
1526 to contain all of it, also fill in the addr of the sections */
1528 size_section (abfd
, idx
)
1533 unsigned int size
= 0;
1534 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1537 size
= frag
->fr_address
;
1538 if (frag
->fr_address
!= size
)
1540 fprintf (stderr
, "Out of step\n");
1541 size
= frag
->fr_address
;
1544 switch (frag
->fr_type
)
1546 #ifdef TC_COFF_SIZEMACHDEP
1547 case rs_machine_dependent
:
1548 size
+= TC_COFF_SIZEMACHDEP (frag
);
1552 assert (frag
->fr_symbol
== 0);
1555 size
+= frag
->fr_fix
;
1556 size
+= frag
->fr_offset
* frag
->fr_var
;
1560 size
+= frag
->fr_fix
;
1561 size
+= relax_align (size
, frag
->fr_offset
);
1564 BAD_CASE (frag
->fr_type
);
1567 frag
= frag
->fr_next
;
1569 segment_info
[idx
].scnhdr
.s_size
= size
;
1575 count_entries_in_chain (idx
)
1578 unsigned int nrelocs
;
1581 /* Count the relocations */
1582 fixup_ptr
= segment_info
[idx
].fix_root
;
1584 while (fixup_ptr
!= (fixS
*) NULL
)
1586 if (TC_COUNT_RELOC (fixup_ptr
))
1589 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1598 fixup_ptr
= fixup_ptr
->fx_next
;
1605 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1607 /* AUX's ld expects relocations to be sorted */
1609 compare_external_relocs (x
, y
)
1613 struct external_reloc
*a
= (struct external_reloc
*) x
;
1614 struct external_reloc
*b
= (struct external_reloc
*) y
;
1615 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1616 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1617 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1622 /* output all the relocations for a section */
1624 do_relocs_for (abfd
, h
, file_cursor
)
1627 unsigned long *file_cursor
;
1629 unsigned int nrelocs
;
1631 unsigned long reloc_start
= *file_cursor
;
1633 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1635 if (segment_info
[idx
].scnhdr
.s_name
[0])
1637 struct external_reloc
*ext_ptr
;
1638 struct external_reloc
*external_reloc_vec
;
1639 unsigned int external_reloc_size
;
1640 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1641 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1642 nrelocs
= count_entries_in_chain (idx
);
1645 /* Bypass this stuff if no relocs. This also incidentally
1646 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1648 external_reloc_size
= nrelocs
* RELSZ
;
1649 external_reloc_vec
=
1650 (struct external_reloc
*) malloc (external_reloc_size
);
1652 ext_ptr
= external_reloc_vec
;
1654 /* Fill in the internal coff style reloc struct from the
1655 internal fix list. */
1658 struct internal_reloc intr
;
1660 /* Only output some of the relocations */
1661 if (TC_COUNT_RELOC (fix_ptr
))
1663 #ifdef TC_RELOC_MANGLE
1664 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1669 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1671 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1673 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1675 #ifdef TC_KEEP_FX_OFFSET
1676 intr
.r_offset
= fix_ptr
->fx_offset
;
1681 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1682 && (! S_IS_DEFINED (symbol_ptr
)
1683 || S_IS_COMMON (symbol_ptr
)))
1684 symbol_ptr
= symbol_ptr
->sy_value
.X_add_symbol
;
1686 /* Turn the segment of the symbol into an offset. */
1689 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1692 intr
.r_symndx
= dot
->sy_number
;
1696 intr
.r_symndx
= symbol_ptr
->sy_number
;
1706 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1709 #if defined(TC_A29K)
1711 /* The 29k has a special kludge for the high 16 bit
1712 reloc. Two relocations are emited, R_IHIHALF,
1713 and R_IHCONST. The second one doesn't contain a
1714 symbol, but uses the value for offset. */
1716 if (intr
.r_type
== R_IHIHALF
)
1718 /* now emit the second bit */
1719 intr
.r_type
= R_IHCONST
;
1720 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1721 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1727 fix_ptr
= fix_ptr
->fx_next
;
1731 /* Sort the reloc table */
1732 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1733 sizeof (struct external_reloc
), compare_external_relocs
);
1736 /* Write out the reloc table */
1737 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1739 free (external_reloc_vec
);
1741 /* Fill in section header info. */
1742 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1743 *file_cursor
+= external_reloc_size
;
1744 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1749 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1753 /* Set relocation_size field in file headers */
1754 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1758 /* run through a frag chain and write out the data to go with it, fill
1759 in the scnhdrs with the info on the file postions
1762 fill_section (abfd
, h
, file_cursor
)
1765 unsigned long *file_cursor
;
1769 unsigned int paddr
= 0;
1771 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1773 unsigned int offset
= 0;
1774 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1780 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1787 buffer
= xmalloc (s
->s_size
);
1788 s
->s_scnptr
= *file_cursor
;
1790 know (s
->s_paddr
== paddr
);
1792 if (strcmp (s
->s_name
, ".text") == 0)
1793 s
->s_flags
|= STYP_TEXT
;
1794 else if (strcmp (s
->s_name
, ".data") == 0)
1795 s
->s_flags
|= STYP_DATA
;
1796 else if (strcmp (s
->s_name
, ".bss") == 0)
1799 s
->s_flags
|= STYP_BSS
;
1801 /* @@ Should make the i386 and a29k coff targets define
1802 COFF_NOLOAD_PROBLEM, and have only one test here. */
1805 #ifndef COFF_NOLOAD_PROBLEM
1806 /* Apparently the SVR3 linker (and exec syscall) and UDI
1807 mondfe progrem are confused by noload sections. */
1808 s
->s_flags
|= STYP_NOLOAD
;
1813 else if (strcmp (s
->s_name
, ".lit") == 0)
1814 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1815 else if (strcmp (s
->s_name
, ".init") == 0)
1816 s
->s_flags
|= STYP_TEXT
;
1817 else if (strcmp (s
->s_name
, ".fini") == 0)
1818 s
->s_flags
|= STYP_TEXT
;
1819 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1820 s
->s_flags
|= STYP_INFO
;
1824 unsigned int fill_size
;
1825 switch (frag
->fr_type
)
1827 case rs_machine_dependent
:
1830 memcpy (buffer
+ frag
->fr_address
,
1832 (unsigned int) frag
->fr_fix
);
1833 offset
+= frag
->fr_fix
;
1838 assert (frag
->fr_symbol
== 0);
1845 memcpy (buffer
+ frag
->fr_address
,
1847 (unsigned int) frag
->fr_fix
);
1848 offset
+= frag
->fr_fix
;
1851 fill_size
= frag
->fr_var
;
1852 if (fill_size
&& frag
->fr_offset
> 0)
1855 unsigned int off
= frag
->fr_fix
;
1856 for (count
= frag
->fr_offset
; count
; count
--)
1858 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1860 memcpy (buffer
+ frag
->fr_address
+ off
,
1861 frag
->fr_literal
+ frag
->fr_fix
,
1864 offset
+= fill_size
;
1869 case rs_broken_word
:
1874 frag
= frag
->fr_next
;
1879 if (s
->s_scnptr
!= 0)
1881 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1882 *file_cursor
+= s
->s_size
;
1891 /* Coff file generation & utilities */
1894 coff_header_append (abfd
, h
)
1902 bfd_seek (abfd
, 0, 0);
1904 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1905 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1906 H_SET_VERSION_STAMP (h
, 0);
1907 H_SET_ENTRY_POINT (h
, 0);
1908 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1909 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1910 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1912 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1913 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1914 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1916 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1918 bfd_write (buffer
, i
, 1, abfd
);
1919 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1921 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1923 if (segment_info
[i
].scnhdr
.s_name
[0])
1926 bfd_coff_swap_scnhdr_out (abfd
,
1927 &(segment_info
[i
].scnhdr
),
1930 as_bad ("bfd_coff_swap_scnhdr_out failed");
1931 bfd_write (buffer
, size
, 1, abfd
);
1938 symbol_to_chars (abfd
, where
, symbolP
)
1943 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1947 /* Turn any symbols with register attributes into abs symbols */
1948 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1950 S_SET_SEGMENT (symbolP
, absolute_section
);
1952 /* At the same time, relocate all symbols to their output value */
1954 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1955 + S_GET_VALUE (symbolP
));
1957 S_SET_VALUE (symbolP
, val
);
1959 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1961 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1964 for (i
= 0; i
< numaux
; i
++)
1966 where
+= bfd_coff_swap_aux_out (abfd
,
1967 &symbolP
->sy_symbol
.ost_auxent
[i
],
1968 S_GET_DATA_TYPE (symbolP
),
1969 S_GET_STORAGE_CLASS (symbolP
),
1977 obj_symbol_new_hook (symbolP
)
1980 char underscore
= 0; /* Symbol has leading _ */
1982 /* Effective symbol */
1983 /* Store the pointer in the offset. */
1984 S_SET_ZEROES (symbolP
, 0L);
1985 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1986 S_SET_STORAGE_CLASS (symbolP
, 0);
1987 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1988 /* Additional information */
1989 symbolP
->sy_symbol
.ost_flags
= 0;
1990 /* Auxiliary entries */
1991 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1993 if (S_IS_STRING (symbolP
))
1994 SF_SET_STRING (symbolP
);
1995 if (!underscore
&& S_IS_LOCAL (symbolP
))
1996 SF_SET_LOCAL (symbolP
);
2000 * Handle .ln directives.
2004 obj_coff_ln (appline
)
2009 if (! appline
&& def_symbol_in_progress
!= NULL
)
2011 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2012 demand_empty_rest_of_line ();
2014 } /* wrong context */
2016 l
= get_absolute_expression ();
2017 c_line_new (0, frag_now_fix (), l
, frag_now
);
2026 listing_source_line ((unsigned int) l
);
2031 demand_empty_rest_of_line ();
2037 * Handle .def directives.
2039 * One might ask : why can't we symbol_new if the symbol does not
2040 * already exist and fill it with debug information. Because of
2041 * the C_EFCN special symbol. It would clobber the value of the
2042 * function symbol before we have a chance to notice that it is
2043 * a C_EFCN. And a second reason is that the code is more clear this
2044 * way. (at least I think it is :-).
2048 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2049 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2050 *input_line_pointer == '\t') \
2051 input_line_pointer++;
2057 char name_end
; /* Char after the end of name */
2058 char *symbol_name
; /* Name of the debug symbol */
2059 char *symbol_name_copy
; /* Temporary copy of the name */
2060 unsigned int symbol_name_length
;
2062 if (def_symbol_in_progress
!= NULL
)
2064 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2065 demand_empty_rest_of_line ();
2067 } /* if not inside .def/.endef */
2069 SKIP_WHITESPACES ();
2071 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2072 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2074 symbol_name
= input_line_pointer
;
2075 name_end
= get_symbol_end ();
2076 symbol_name_length
= strlen (symbol_name
);
2077 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2078 strcpy (symbol_name_copy
, symbol_name
);
2080 /* Initialize the new symbol */
2081 #ifdef STRIP_UNDERSCORE
2082 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2083 ? symbol_name_copy
+ 1
2084 : symbol_name_copy
));
2085 #else /* STRIP_UNDERSCORE */
2086 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2087 #endif /* STRIP_UNDERSCORE */
2088 /* free(symbol_name_copy); */
2089 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2090 def_symbol_in_progress
->sy_number
= ~0;
2091 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2092 S_SET_VALUE (def_symbol_in_progress
, 0);
2094 if (S_IS_STRING (def_symbol_in_progress
))
2095 SF_SET_STRING (def_symbol_in_progress
);
2097 *input_line_pointer
= name_end
;
2099 demand_empty_rest_of_line ();
2102 unsigned int dim_index
;
2106 obj_coff_endef (ignore
)
2109 symbolS
*symbolP
= 0;
2110 /* DIM BUG FIX sac@cygnus.com */
2112 if (def_symbol_in_progress
== NULL
)
2114 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2115 demand_empty_rest_of_line ();
2117 } /* if not inside .def/.endef */
2119 /* Set the section number according to storage class. */
2120 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2125 SF_SET_TAG (def_symbol_in_progress
);
2126 /* intentional fallthrough */
2129 SF_SET_DEBUG (def_symbol_in_progress
);
2130 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2134 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2135 /* intentional fallthrough */
2137 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2138 /* intentional fallthrough */
2140 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2142 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2144 if (function_lineoff
< 0)
2146 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2147 } /* missing function symbol */
2148 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2150 SF_SET_PROCESS (last_line_symbol
);
2151 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2152 SF_SET_PROCESS (def_symbol_in_progress
);
2153 function_lineoff
= -1;
2155 /* Value is always set to . */
2156 def_symbol_in_progress
->sy_frag
= frag_now
;
2157 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2162 #endif /* C_AUTOARG */
2172 SF_SET_DEBUG (def_symbol_in_progress
);
2173 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2179 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2185 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2187 } /* switch on storage class */
2189 /* Now that we have built a debug symbol, try to find if we should
2190 merge with an existing symbol or not. If a symbol is C_EFCN or
2191 absolute_section or untagged SEG_DEBUG it never merges. We also
2192 don't merge labels, which are in a different namespace, nor
2193 symbols which have not yet been defined since they are typically
2194 unique, nor do we merge tags with non-tags. */
2196 /* Two cases for functions. Either debug followed by definition or
2197 definition followed by debug. For definition first, we will
2198 merge the debug symbol into the definition. For debug first, the
2199 lineno entry MUST point to the definition function or else it
2200 will point off into space when crawl_symbols() merges the debug
2201 symbol into the real symbol. Therefor, let's presume the debug
2202 symbol is a real function reference. */
2204 /* FIXME-SOON If for some reason the definition label/symbol is
2205 never seen, this will probably leave an undefined symbol at link
2208 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2209 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2210 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2211 && !SF_GET_TAG (def_symbol_in_progress
))
2212 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2213 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2214 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2215 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2217 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2222 /* This symbol already exists, merge the newly created symbol
2223 into the old one. This is not mandatory. The linker can
2224 handle duplicate symbols correctly. But I guess that it save
2225 a *lot* of space if the assembly file defines a lot of
2228 /* The debug entry (def_symbol_in_progress) is merged into the
2229 previous definition. */
2231 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2232 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2233 def_symbol_in_progress
= symbolP
;
2235 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2236 || SF_GET_TAG (def_symbol_in_progress
))
2238 /* For functions, and tags, the symbol *must* be where the
2239 debug symbol appears. Move the existing symbol to the
2241 /* If it already is at the end of the symbol list, do nothing */
2242 if (def_symbol_in_progress
!= symbol_lastP
)
2244 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2246 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2247 &symbol_rootP
, &symbol_lastP
);
2248 } /* if not already in place */
2250 } /* normal or mergable */
2252 if (SF_GET_TAG (def_symbol_in_progress
)
2253 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2255 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2258 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2260 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2262 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2264 SF_SET_PROCESS (def_symbol_in_progress
);
2266 if (symbolP
== NULL
)
2268 /* That is, if this is the first time we've seen the
2270 symbol_table_insert (def_symbol_in_progress
);
2271 } /* definition follows debug */
2272 } /* Create the line number entry pointing to the function being defined */
2274 def_symbol_in_progress
= NULL
;
2275 demand_empty_rest_of_line ();
2279 obj_coff_dim (ignore
)
2284 if (def_symbol_in_progress
== NULL
)
2286 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2287 demand_empty_rest_of_line ();
2289 } /* if not inside .def/.endef */
2291 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2293 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2295 SKIP_WHITESPACES ();
2296 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2297 get_absolute_expression ());
2299 switch (*input_line_pointer
)
2302 input_line_pointer
++;
2306 as_warn ("badly formed .dim directive ignored");
2307 /* intentional fallthrough */
2315 demand_empty_rest_of_line ();
2319 obj_coff_line (ignore
)
2325 if (def_symbol_in_progress
== NULL
)
2331 name
= S_GET_NAME (def_symbol_in_progress
);
2332 this_base
= get_absolute_expression ();
2334 /* Only .bf symbols indicate the use of a new base line number; the
2335 line numbers associated with .ef, .bb, .eb are relative to the
2336 start of the containing function. */
2337 if (!strcmp (".bf", name
))
2339 #if 0 /* XXX Can we ever have line numbers going backwards? */
2340 if (this_base
> line_base
)
2343 line_base
= this_base
;
2351 listing_source_line ((unsigned int) line_base
);
2357 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2358 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2360 demand_empty_rest_of_line ();
2364 obj_coff_size (ignore
)
2367 if (def_symbol_in_progress
== NULL
)
2369 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2370 demand_empty_rest_of_line ();
2372 } /* if not inside .def/.endef */
2374 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2375 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2376 demand_empty_rest_of_line ();
2380 obj_coff_scl (ignore
)
2383 if (def_symbol_in_progress
== NULL
)
2385 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2386 demand_empty_rest_of_line ();
2388 } /* if not inside .def/.endef */
2390 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2391 demand_empty_rest_of_line ();
2395 obj_coff_tag (ignore
)
2401 if (def_symbol_in_progress
== NULL
)
2403 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2404 demand_empty_rest_of_line ();
2408 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2409 symbol_name
= input_line_pointer
;
2410 name_end
= get_symbol_end ();
2412 /* Assume that the symbol referred to by .tag is always defined.
2413 This was a bad assumption. I've added find_or_make. xoxorich. */
2414 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2415 (long) tag_find_or_make (symbol_name
));
2416 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2418 as_warn ("tag not found for .tag %s", symbol_name
);
2421 SF_SET_TAGGED (def_symbol_in_progress
);
2422 *input_line_pointer
= name_end
;
2424 demand_empty_rest_of_line ();
2428 obj_coff_type (ignore
)
2431 if (def_symbol_in_progress
== NULL
)
2433 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2434 demand_empty_rest_of_line ();
2436 } /* if not inside .def/.endef */
2438 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2440 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2441 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2443 SF_SET_FUNCTION (def_symbol_in_progress
);
2444 } /* is a function */
2446 demand_empty_rest_of_line ();
2450 obj_coff_val (ignore
)
2453 if (def_symbol_in_progress
== NULL
)
2455 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2456 demand_empty_rest_of_line ();
2458 } /* if not inside .def/.endef */
2460 if (is_name_beginner (*input_line_pointer
))
2462 char *symbol_name
= input_line_pointer
;
2463 char name_end
= get_symbol_end ();
2465 if (!strcmp (symbol_name
, "."))
2467 def_symbol_in_progress
->sy_frag
= frag_now
;
2468 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2469 /* If the .val is != from the .def (e.g. statics) */
2471 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2473 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2474 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2475 symbol_find_or_make (symbol_name
);
2476 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2477 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2479 /* If the segment is undefined when the forward reference is
2480 resolved, then copy the segment id from the forward
2482 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2484 /* FIXME: gcc can generate address expressions
2485 here in unusual cases (search for "obscure"
2486 in sdbout.c). We just ignore the offset
2487 here, thus generating incorrect debugging
2488 information. We ignore the rest of the
2491 /* Otherwise, it is the name of a non debug symbol and
2492 its value will be calculated later. */
2493 *input_line_pointer
= name_end
;
2495 /* FIXME: this is to avoid an error message in the
2496 FIXME case mentioned just above. */
2497 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2498 ++input_line_pointer
;
2502 S_SET_VALUE (def_symbol_in_progress
,
2503 (valueT
) get_absolute_expression ());
2504 } /* if symbol based */
2506 demand_empty_rest_of_line ();
2511 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2512 read.c, which then calls this object file format specific routine. */
2515 obj_coff_pe_handle_link_once (type
)
2516 enum linkonce_type type
;
2518 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2520 /* We store the type in the seg_info structure, and use it to set up
2521 the auxiliary entry for the section symbol in c_section_symbol. */
2522 seg_info (now_seg
)->linkonce
= type
;
2528 obj_read_begin_hook ()
2530 /* These had better be the same. Usually 18 bytes. */
2532 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2533 know (SYMESZ
== AUXESZ
);
2538 /* This function runs through the symbol table and puts all the
2539 externals onto another chain */
2541 /* The chain of globals. */
2542 symbolS
*symbol_globalP
;
2543 symbolS
*symbol_global_lastP
;
2545 /* The chain of externals */
2546 symbolS
*symbol_externP
;
2547 symbolS
*symbol_extern_lastP
;
2550 symbolS
*last_functionP
;
2551 static symbolS
*last_bfP
;
2558 unsigned int symbol_number
= 0;
2559 unsigned int last_file_symno
= 0;
2561 struct filename_list
*filename_list_scan
= filename_list_head
;
2563 for (symbolP
= symbol_rootP
;
2565 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2567 if (symbolP
->sy_mri_common
)
2569 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2570 as_bad ("%s: global symbols not supported in common sections",
2571 S_GET_NAME (symbolP
));
2572 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2576 if (!SF_GET_DEBUG (symbolP
))
2578 /* Debug symbols do not need all this rubbish */
2579 symbolS
*real_symbolP
;
2581 /* L* and C_EFCN symbols never merge. */
2582 if (!SF_GET_LOCAL (symbolP
)
2583 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2584 && symbolP
->sy_value
.X_op
== O_constant
2585 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2586 && real_symbolP
!= symbolP
)
2588 /* FIXME-SOON: where do dups come from?
2589 Maybe tag references before definitions? xoxorich. */
2590 /* Move the debug data from the debug symbol to the
2591 real symbol. Do NOT do the oposite (i.e. move from
2592 real symbol to debug symbol and remove real symbol from the
2593 list.) Because some pointers refer to the real symbol
2594 whereas no pointers refer to the debug symbol. */
2595 c_symbol_merge (symbolP
, real_symbolP
);
2596 /* Replace the current symbol by the real one */
2597 /* The symbols will never be the last or the first
2598 because : 1st symbol is .file and 3 last symbols are
2599 .text, .data, .bss */
2600 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2601 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2602 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2603 symbolP
= real_symbolP
;
2604 } /* if not local but dup'd */
2606 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2608 S_SET_SEGMENT (symbolP
, SEG_E0
);
2609 } /* push data into text */
2611 resolve_symbol_value (symbolP
);
2613 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2615 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2617 S_SET_EXTERNAL (symbolP
);
2619 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2621 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2625 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2629 /* Mainly to speed up if not -g */
2630 if (SF_GET_PROCESS (symbolP
))
2632 /* Handle the nested blocks auxiliary info. */
2633 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2635 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2636 stack_push (block_stack
, (char *) &symbolP
);
2639 register symbolS
*begin_symbolP
;
2640 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2641 if (begin_symbolP
== (symbolS
*) 0)
2642 as_warn ("mismatched .eb");
2644 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2647 /* If we are able to identify the type of a function, and we
2648 are out of a function (last_functionP == 0) then, the
2649 function symbol will be associated with an auxiliary
2651 if (last_functionP
== (symbolS
*) 0 &&
2652 SF_GET_FUNCTION (symbolP
))
2654 last_functionP
= symbolP
;
2656 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2658 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2659 } /* make it at least 1 */
2661 /* Clobber possible stale .dim information. */
2663 /* Iffed out by steve - this fries the lnnoptr info too */
2664 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2665 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2668 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2670 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2672 if (last_bfP
!= NULL
)
2673 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2677 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2679 /* I don't even know if this is needed for sdb. But
2680 the standard assembler generates it, so... */
2681 if (last_functionP
== (symbolS
*) 0)
2682 as_fatal ("C_EFCN symbol out of scope");
2683 SA_SET_SYM_FSIZE (last_functionP
,
2684 (long) (S_GET_VALUE (symbolP
) -
2685 S_GET_VALUE (last_functionP
)));
2686 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2687 last_functionP
= (symbolS
*) 0;
2691 else if (SF_GET_TAG (symbolP
))
2693 /* First descriptor of a structure must point to
2694 the first slot after the structure description. */
2695 last_tagP
= symbolP
;
2698 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2700 /* +2 take in account the current symbol */
2701 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2703 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2705 /* If the filename was too long to fit in the
2706 auxent, put it in the string table */
2707 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2709 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2710 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2711 filename_list_scan
= filename_list_scan
->next
;
2713 if (S_GET_VALUE (symbolP
))
2715 S_SET_VALUE (symbolP
, last_file_symno
);
2716 last_file_symno
= symbol_number
;
2717 } /* no one points at the first .file symbol */
2718 } /* if debug or tag or eos or file */
2720 /* We must put the external symbols apart. The loader
2721 does not bomb if we do not. But the references in
2722 the endndx field for a .bb symbol are not corrected
2723 if an external symbol is removed between .bb and .be.
2724 I.e in the following case :
2725 [20] .bb endndx = 22
2728 ld will move the symbol 21 to the end of the list but
2729 endndx will still be 22 instead of 21. */
2732 if (SF_GET_LOCAL (symbolP
))
2734 /* remove C_EFCN and LOCAL (L...) symbols */
2735 /* next pointer remains valid */
2736 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2739 else if (symbolP
->sy_value
.X_op
== O_symbol
2740 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2742 /* Skip symbols which were equated to undefined or common
2744 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2746 else if (!S_IS_DEFINED (symbolP
)
2747 && !S_IS_DEBUG (symbolP
)
2748 && !SF_GET_STATICS (symbolP
) &&
2749 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2750 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2751 /* if external, Remove from the list */
2752 symbolS
*hold
= symbol_previous (symbolP
);
2754 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2755 symbol_clear_list_pointers (symbolP
);
2756 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2759 else if (! S_IS_DEBUG (symbolP
)
2760 && ! SF_GET_STATICS (symbolP
)
2761 && ! SF_GET_FUNCTION (symbolP
)
2762 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2764 symbolS
*hold
= symbol_previous (symbolP
);
2766 /* The O'Reilly COFF book says that defined global symbols
2767 come at the end of the symbol table, just before
2768 undefined global symbols. */
2770 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2771 symbol_clear_list_pointers (symbolP
);
2772 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2773 &symbol_global_lastP
);
2778 if (SF_GET_STRING (symbolP
))
2780 symbolP
->sy_name_offset
= string_byte_count
;
2781 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2785 symbolP
->sy_name_offset
= 0;
2786 } /* fix "long" names */
2788 symbolP
->sy_number
= symbol_number
;
2789 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2790 } /* if local symbol */
2791 } /* traverse the symbol list */
2792 return symbol_number
;
2798 glue_symbols (head
, tail
)
2802 unsigned int symbol_number
= 0;
2805 for (symbolP
= *head
; *head
!= NULL
;)
2807 symbolS
*tmp
= *head
;
2810 symbol_remove (tmp
, head
, tail
);
2811 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2814 if (SF_GET_STRING (tmp
))
2816 tmp
->sy_name_offset
= string_byte_count
;
2817 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2821 tmp
->sy_name_offset
= 0;
2822 } /* fix "long" names */
2824 tmp
->sy_number
= symbol_number
;
2825 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2826 } /* append the entire extern chain */
2828 return symbol_number
;
2834 unsigned int symbol_number
= 0;
2837 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2838 symbol_next (symbolP
))
2840 symbolP
->sy_number
= symbol_number
;
2844 if (SF_GET_TAGGED (symbolP
))
2848 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2851 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2853 return symbol_number
;
2858 crawl_symbols (h
, abfd
)
2864 /* Initialize the stack used to keep track of the matching .bb .be */
2866 block_stack
= stack_init (512, sizeof (symbolS
*));
2868 /* The symbol list should be ordered according to the following sequence
2871 * . debug entries for functions
2872 * . fake symbols for the sections, including.text .data and .bss
2874 * . undefined symbols
2875 * But this is not mandatory. The only important point is to put the
2876 * undefined symbols at the end of the list.
2879 if (symbol_rootP
== NULL
2880 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2882 c_dot_file_symbol ("fake");
2884 /* Is there a .file symbol ? If not insert one at the beginning. */
2887 * Build up static symbols for the sections, they are filled in later
2891 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2893 if (segment_info
[i
].scnhdr
.s_name
[0])
2897 strncpy (name
, segment_info
[i
].scnhdr
.s_name
, 8);
2899 segment_info
[i
].dot
= c_section_symbol (name
, i
- SEG_E0
+ 1);
2904 /* Take all the externals out and put them into another chain */
2905 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2906 /* Take the externals and glue them onto the end.*/
2907 H_SET_SYMBOL_TABLE_SIZE (h
,
2908 (H_GET_SYMBOL_COUNT (h
)
2909 + glue_symbols (&symbol_globalP
,
2910 &symbol_global_lastP
)
2911 + glue_symbols (&symbol_externP
,
2912 &symbol_extern_lastP
)));
2914 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2915 know (symbol_globalP
== NULL
);
2916 know (symbol_global_lastP
== NULL
);
2917 know (symbol_externP
== NULL
);
2918 know (symbol_extern_lastP
== NULL
);
2922 * Find strings by crawling along symbol table chain.
2930 struct filename_list
*filename_list_scan
= filename_list_head
;
2932 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2933 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2935 for (symbolP
= symbol_rootP
;
2937 symbolP
= symbol_next (symbolP
))
2941 if (SF_GET_STRING (symbolP
))
2943 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2944 memcpy (where
, S_GET_NAME (symbolP
), size
);
2947 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2948 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2950 size
= strlen (filename_list_scan
->filename
) + 1;
2951 memcpy (where
, filename_list_scan
->filename
, size
);
2952 filename_list_scan
= filename_list_scan
->next
;
2959 do_linenos_for (abfd
, h
, file_cursor
)
2962 unsigned long *file_cursor
;
2965 unsigned long start
= *file_cursor
;
2967 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
2969 segment_info_type
*s
= segment_info
+ idx
;
2972 if (s
->scnhdr
.s_nlnno
!= 0)
2974 struct lineno_list
*line_ptr
;
2976 struct external_lineno
*buffer
=
2977 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
2979 struct external_lineno
*dst
= buffer
;
2981 /* Run through the table we've built and turn it into its external
2982 form, take this chance to remove duplicates */
2984 for (line_ptr
= s
->lineno_list_head
;
2985 line_ptr
!= (struct lineno_list
*) NULL
;
2986 line_ptr
= line_ptr
->next
)
2989 if (line_ptr
->line
.l_lnno
== 0)
2991 /* Turn a pointer to a symbol into the symbols' index */
2992 line_ptr
->line
.l_addr
.l_symndx
=
2993 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
2997 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3001 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3006 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3008 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3011 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3014 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3018 /* Now we run through the list of frag chains in a segment and
3019 make all the subsegment frags appear at the end of the
3020 list, as if the seg 0 was extra long */
3027 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3029 frchainS
*head
= segment_info
[i
].frchainP
;
3031 fragS
*prev_frag
= &dummy
;
3033 while (head
&& head
->frch_seg
== i
)
3035 prev_frag
->fr_next
= head
->frch_root
;
3036 prev_frag
= head
->frch_last
;
3037 head
= head
->frch_next
;
3039 prev_frag
->fr_next
= 0;
3043 unsigned long machine
;
3046 write_object_file ()
3050 struct frchain
*frchain_ptr
;
3052 object_headers headers
;
3053 unsigned long file_cursor
;
3056 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3061 as_perror ("FATAL: Can't create %s", out_file_name
);
3062 exit (EXIT_FAILURE
);
3064 bfd_set_format (abfd
, bfd_object
);
3065 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3067 string_byte_count
= 4;
3069 for (frchain_ptr
= frchain_root
;
3070 frchain_ptr
!= (struct frchain
*) NULL
;
3071 frchain_ptr
= frchain_ptr
->frch_next
)
3073 /* Run through all the sub-segments and align them up. Also
3074 close any open frags. We tack a .fill onto the end of the
3075 frag chain so that any .align's size can be worked by looking
3076 at the next frag. */
3078 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3079 #ifndef SUB_SEGMENT_ALIGN
3080 #define SUB_SEGMENT_ALIGN(SEG) 1
3084 static char nop
= NOP_OPCODE
;
3085 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, alignment_done
);
3088 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
3092 frag_wane (frag_now
);
3093 frag_now
->fr_fix
= 0;
3094 know (frag_now
->fr_next
== NULL
);
3101 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3103 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3106 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3108 /* Find out how big the sections are, and set the addresses. */
3110 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3114 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3115 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3117 if (segment_info
[i
].scnhdr
.s_name
[0])
3119 H_SET_NUMBER_OF_SECTIONS (&headers
,
3120 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3123 size
= size_section (abfd
, (unsigned int) i
);
3126 /* I think the section alignment is only used on the i960; the
3127 i960 needs it, and it should do no harm on other targets. */
3128 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3131 H_SET_TEXT_SIZE (&headers
, size
);
3132 else if (i
== SEG_E1
)
3133 H_SET_DATA_SIZE (&headers
, size
);
3134 else if (i
== SEG_E2
)
3135 H_SET_BSS_SIZE (&headers
, size
);
3138 /* Turn the gas native symbol table shape into a coff symbol table */
3139 crawl_symbols (&headers
, abfd
);
3141 if (string_byte_count
== 4)
3142 string_byte_count
= 0;
3144 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3150 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3152 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3153 fixup_segment (&segment_info
[i
], i
);
3156 /* Look for ".stab" segments and fill in their initial symbols
3158 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3160 name
= segment_info
[i
].scnhdr
.s_name
;
3163 && strncmp (".stab", name
, 5) == 0
3164 && strncmp (".stabstr", name
, 8) != 0)
3165 adjust_stab_section (abfd
, i
);
3168 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3170 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3172 /* Plant the data */
3174 fill_section (abfd
, &headers
, &file_cursor
);
3176 do_relocs_for (abfd
, &headers
, &file_cursor
);
3178 do_linenos_for (abfd
, &headers
, &file_cursor
);
3180 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3181 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3182 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3184 H_SET_TIME_STAMP (&headers
, 0);
3186 #ifdef TC_COFF_SET_MACHINE
3187 TC_COFF_SET_MACHINE (&headers
);
3191 #define COFF_FLAGS 0
3194 #ifdef KEEP_RELOC_INFO
3195 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3196 COFF_FLAGS
| coff_flags
));
3198 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3199 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3200 COFF_FLAGS
| coff_flags
));
3204 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3205 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3207 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3208 w_symbols (abfd
, buffer1
, symbol_rootP
);
3209 if (string_byte_count
> 0)
3210 w_strings (buffer1
+ symtable_size
);
3211 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3215 coff_header_append (abfd
, &headers
);
3217 /* Recent changes to write need this, but where it should
3218 go is up to Ken.. */
3219 if (bfd_close_all_done (abfd
) == false)
3220 as_fatal ("Can't close %s: %s", out_file_name
,
3221 bfd_errmsg (bfd_get_error ()));
3224 extern bfd
*stdoutput
;
3231 /* Add a new segment. This is called from subseg_new via the
3232 obj_new_segment macro. */
3235 obj_coff_add_segment (name
)
3241 /* Find out if we've already got a section of this name. */
3242 len
= strlen (name
);
3243 if (len
< sizeof (segment_info
[i
].scnhdr
.s_name
))
3246 len
= sizeof (segment_info
[i
].scnhdr
.s_name
);
3247 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3248 if (strncmp (segment_info
[i
].scnhdr
.s_name
, name
, len
) == 0
3249 && (len
== sizeof (segment_info
[i
].scnhdr
.s_name
)
3250 || segment_info
[i
].scnhdr
.s_name
[len
] == '\0'))
3255 as_bad ("Too many new sections; can't add \"%s\"", name
);
3259 /* Add a new section. */
3260 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3261 sizeof (segment_info
[i
].scnhdr
.s_name
));
3262 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3268 * implement the .section pseudo op:
3269 * .section name {, "flags"}
3271 * | +--- optional flags: 'b' for bss
3273 * +-- section name 'l' for lib
3277 * 'd' (apparently m88k for data)
3279 * But if the argument is not a quoted string, treat it as a
3280 * subsegment number.
3284 obj_coff_section (ignore
)
3287 /* Strip out the section name */
3289 char *section_name_end
;
3304 else if (type
== 'D')
3306 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3311 section_name
= input_line_pointer
;
3312 c
= get_symbol_end ();
3313 section_name_end
= input_line_pointer
;
3315 len
= section_name_end
- section_name
;
3316 input_line_pointer
++;
3322 else if (*input_line_pointer
== ',')
3325 ++input_line_pointer
;
3333 if (*input_line_pointer
!= '"')
3334 exp
= get_absolute_expression ();
3337 ++input_line_pointer
;
3338 while (*input_line_pointer
!= '"'
3339 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3341 switch (*input_line_pointer
)
3343 case 'b': flags
|= STYP_BSS
; break;
3344 case 'i': flags
|= STYP_INFO
; break;
3345 case 'l': flags
|= STYP_LIB
; break;
3346 case 'n': flags
|= STYP_NOLOAD
; break;
3347 case 'o': flags
|= STYP_OVER
; break;
3349 case 'w': flags
|= STYP_DATA
; break;
3350 case 'x': flags
|= STYP_TEXT
; break;
3352 as_warn("unknown section attribute '%c'",
3353 *input_line_pointer
);
3356 ++input_line_pointer
;
3358 if (*input_line_pointer
== '"')
3359 ++input_line_pointer
;
3363 subseg_new (section_name
, (subsegT
) exp
);
3365 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3367 *section_name_end
= c
;
3372 obj_coff_text (ignore
)
3375 subseg_new (".text", get_absolute_expression ());
3380 obj_coff_data (ignore
)
3383 if (flag_readonly_data_in_text
)
3384 subseg_new (".text", get_absolute_expression () + 1000);
3386 subseg_new (".data", get_absolute_expression ());
3390 obj_coff_bss (ignore
)
3393 if (*input_line_pointer
== '\n') /* .bss */
3394 subseg_new(".bss", get_absolute_expression());
3395 else /* .bss id,expr */
3400 obj_coff_ident (ignore
)
3403 segT current_seg
= now_seg
; /* save current seg */
3404 subsegT current_subseg
= now_subseg
;
3405 subseg_new (".comment", 0); /* .comment seg */
3406 stringer (1); /* read string */
3407 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3411 c_symbol_merge (debug
, normal
)
3415 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3416 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3418 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3420 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3421 } /* take the most we have */
3423 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3425 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3426 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3427 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3428 } /* Move all the auxiliary information */
3430 /* Move the debug flags. */
3431 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3432 } /* c_symbol_merge() */
3435 c_line_new (symbol
, paddr
, line_number
, frag
)
3441 struct lineno_list
*new_line
=
3442 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3444 segment_info_type
*s
= segment_info
+ now_seg
;
3445 new_line
->line
.l_lnno
= line_number
;
3447 if (line_number
== 0)
3449 last_line_symbol
= symbol
;
3450 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3454 new_line
->line
.l_addr
.l_paddr
= paddr
;
3457 new_line
->frag
= (char *) frag
;
3458 new_line
->next
= (struct lineno_list
*) NULL
;
3461 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3463 s
->lineno_list_head
= new_line
;
3467 s
->lineno_list_tail
->next
= new_line
;
3469 s
->lineno_list_tail
= new_line
;
3470 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3474 c_dot_file_symbol (filename
)
3479 symbolP
= symbol_new (".file",
3482 &zero_address_frag
);
3484 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3485 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3487 if (strlen (filename
) > FILNMLEN
)
3489 /* Filename is too long to fit into an auxent,
3490 we stick it into the string table instead. We keep
3491 a linked list of the filenames we find so we can emit
3493 struct filename_list
*f
= ((struct filename_list
*)
3494 xmalloc (sizeof (struct filename_list
)));
3496 f
->filename
= filename
;
3499 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3500 SA_SET_FILE_FNAME_OFFSET (symbolP
, 0);
3502 if (filename_list_tail
)
3503 filename_list_tail
->next
= f
;
3505 filename_list_head
= f
;
3506 filename_list_tail
= f
;
3510 SA_SET_FILE_FNAME (symbolP
, filename
);
3517 listing_source_file (filename
);
3523 SF_SET_DEBUG (symbolP
);
3524 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3526 previous_file_symbol
= symbolP
;
3528 /* Make sure that the symbol is first on the symbol chain */
3529 if (symbol_rootP
!= symbolP
)
3531 if (symbolP
== symbol_lastP
)
3533 symbol_lastP
= symbol_lastP
->sy_previous
;
3534 } /* if it was the last thing on the list */
3536 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3537 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3538 symbol_rootP
= symbolP
;
3539 } /* if not first on the list */
3541 } /* c_dot_file_symbol() */
3544 * Build a 'section static' symbol.
3548 c_section_symbol (name
, idx
)
3554 symbolP
= symbol_new (name
, idx
,
3556 &zero_address_frag
);
3558 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3559 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3561 SF_SET_STATICS (symbolP
);
3564 /* If the .linkonce pseudo-op was used for this section, we must
3565 store the information in the auxiliary entry for the section
3567 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3571 switch (segment_info
[idx
].linkonce
)
3575 case LINKONCE_DISCARD
:
3576 type
= IMAGE_COMDAT_SELECT_ANY
;
3578 case LINKONCE_ONE_ONLY
:
3579 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3581 case LINKONCE_SAME_SIZE
:
3582 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3584 case LINKONCE_SAME_CONTENTS
:
3585 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3589 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3594 } /* c_section_symbol() */
3597 w_symbols (abfd
, where
, symbol_rootP
)
3600 symbolS
* symbol_rootP
;
3605 /* First fill in those values we have only just worked out */
3606 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3608 symbolP
= segment_info
[i
].dot
;
3611 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3612 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3613 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3618 * Emit all symbols left in the symbol chain.
3620 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3622 /* Used to save the offset of the name. It is used to point
3623 to the string in memory but must be a file offset. */
3624 register char *temp
;
3626 /* We can't fix the lnnoptr field in yank_symbols with the other
3627 adjustments, because we have to wait until we know where they
3629 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3631 SA_GET_SYM_LNNOPTR (symbolP
) +=
3632 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3635 tc_coff_symbol_emit_hook (symbolP
);
3637 temp
= S_GET_NAME (symbolP
);
3638 if (SF_GET_STRING (symbolP
))
3640 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3641 S_SET_ZEROES (symbolP
, 0);
3645 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3646 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3648 where
= symbol_to_chars (abfd
, where
, symbolP
);
3649 S_SET_NAME (symbolP
, temp
);
3655 obj_coff_lcomm (ignore
)
3668 name
= input_line_pointer
;
3670 c
= get_symbol_end ();
3671 p
= input_line_pointer
;
3674 if (*input_line_pointer
!= ',')
3676 as_bad ("Expected comma after name");
3677 ignore_rest_of_line ();
3680 if (*input_line_pointer
== '\n')
3682 as_bad ("Missing size expression");
3685 input_line_pointer
++;
3686 if ((temp
= get_absolute_expression ()) < 0)
3688 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3689 ignore_rest_of_line ();
3694 symbolP
= symbol_find_or_make(name
);
3696 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3697 S_GET_VALUE(symbolP
) == 0)
3702 segT current_seg
= now_seg
; /* save current seg */
3703 subsegT current_subseg
= now_subseg
;
3705 subseg_set (SEG_E2
, 1);
3706 symbolP
->sy_frag
= frag_now
;
3707 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3710 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3711 S_SET_SEGMENT(symbolP
, SEG_E2
);
3712 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3716 as_bad("Symbol %s already defined", name
);
3718 demand_empty_rest_of_line();
3723 fixup_mdeps (frags
, h
, this_segment
)
3728 subseg_change (this_segment
, 0);
3731 switch (frags
->fr_type
)
3737 HANDLE_ALIGN (frags
);
3739 frags
->fr_type
= rs_fill
;
3741 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3744 case rs_machine_dependent
:
3745 md_convert_frag (h
, this_segment
, frags
);
3751 frags
= frags
->fr_next
;
3757 #ifndef TC_FORCE_RELOCATION
3758 #define TC_FORCE_RELOCATION(fix) 0
3762 fixup_segment (segP
, this_segment_type
)
3763 segment_info_type
* segP
;
3764 segT this_segment_type
;
3766 register fixS
* fixP
;
3767 register symbolS
*add_symbolP
;
3768 register symbolS
*sub_symbolP
;
3771 register char *place
;
3772 register long where
;
3773 register char pcrel
;
3774 register fragS
*fragP
;
3775 register segT add_symbol_segment
= absolute_section
;
3780 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3782 fragP
= fixP
->fx_frag
;
3784 where
= fixP
->fx_where
;
3785 place
= fragP
->fr_literal
+ where
;
3786 size
= fixP
->fx_size
;
3787 add_symbolP
= fixP
->fx_addsy
;
3789 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3791 /* Relocation should be done via the associated 'bal' entry
3794 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3796 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3797 "No 'bal' entry point for leafproc %s",
3798 S_GET_NAME (add_symbolP
));
3801 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3804 sub_symbolP
= fixP
->fx_subsy
;
3805 add_number
= fixP
->fx_offset
;
3806 pcrel
= fixP
->fx_pcrel
;
3808 if (add_symbolP
!= NULL
3809 && add_symbolP
->sy_mri_common
)
3811 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3812 add_number
+= S_GET_VALUE (add_symbolP
);
3813 fixP
->fx_offset
= add_number
;
3814 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3819 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3820 } /* if there is an addend */
3824 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3826 if (add_symbolP
!= NULL
)
3828 add_number
+= S_GET_VALUE (add_symbolP
);
3830 fixP
->fx_addsy
= NULL
;
3833 /* It's just -sym. */
3834 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3836 add_number
-= S_GET_VALUE (sub_symbolP
);
3843 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3844 "Negative of non-absolute symbol %s",
3845 S_GET_NAME (sub_symbolP
));
3847 add_number
-= S_GET_VALUE (sub_symbolP
);
3848 } /* not absolute */
3850 /* if sub_symbol is in the same segment that add_symbol
3851 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3853 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3854 && SEG_NORMAL (add_symbol_segment
))
3856 /* Difference of 2 symbols from same segment. Can't
3857 make difference of 2 undefineds: 'value' means
3858 something different for N_UNDF. */
3860 /* Makes no sense to use the difference of 2 arbitrary symbols
3861 as the target of a call instruction. */
3864 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3865 "callj to difference of 2 symbols");
3867 #endif /* TC_I960 */
3868 add_number
+= S_GET_VALUE (add_symbolP
) -
3869 S_GET_VALUE (sub_symbolP
);
3872 if (!TC_FORCE_RELOCATION (fixP
))
3874 fixP
->fx_addsy
= NULL
;
3875 fixP
->fx_subsy
= NULL
;
3877 #ifdef TC_M68K /* is this right? */
3885 /* Different segments in subtraction. */
3886 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3888 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3890 add_number
-= S_GET_VALUE (sub_symbolP
);
3893 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3894 #if 0 /* Okay for 68k, at least... */
3899 /* Make it pc-relative. */
3900 add_number
+= (md_pcrel_from (fixP
)
3901 - S_GET_VALUE (sub_symbolP
));
3910 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3911 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3912 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3913 S_GET_NAME (sub_symbolP
),
3914 (long) (fragP
->fr_address
+ where
));
3917 } /* if sub_symbolP */
3921 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3924 * This fixup was made when the symbol's segment was
3925 * SEG_UNKNOWN, but it is now in the local segment.
3926 * So we know how to do the address without relocation.
3929 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3930 * in which cases it modifies *fixP as appropriate. In the case
3931 * of a 'calls', no further work is required, and *fixP has been
3932 * set up to make the rest of the code below a no-op.
3935 #endif /* TC_I960 */
3937 add_number
+= S_GET_VALUE (add_symbolP
);
3938 add_number
-= md_pcrel_from (fixP
);
3939 #if defined (TC_I386) || defined (TE_LYNX)
3940 /* On the 386 we must adjust by the segment
3941 vaddr as well. Ian Taylor. */
3942 add_number
-= segP
->scnhdr
.s_vaddr
;
3944 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3945 if (!TC_FORCE_RELOCATION (fixP
))
3947 fixP
->fx_addsy
= NULL
;
3953 switch (add_symbol_segment
)
3955 case absolute_section
:
3957 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3958 #endif /* TC_I960 */
3959 add_number
+= S_GET_VALUE (add_symbolP
);
3962 if (!TC_FORCE_RELOCATION (fixP
))
3964 fixP
->fx_addsy
= NULL
;
3971 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
3972 /* This really should be handled in the linker, but
3973 backward compatibility forbids. */
3974 add_number
+= S_GET_VALUE (add_symbolP
);
3976 add_number
+= S_GET_VALUE (add_symbolP
) +
3977 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
3983 if ((int) fixP
->fx_bit_fixP
== 13)
3985 /* This is a COBR instruction. They have only a
3986 * 13-bit displacement and are only to be used
3987 * for local branches: flag as error, don't generate
3990 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3991 "can't use COBR format with external label");
3992 fixP
->fx_addsy
= NULL
;
3996 #endif /* TC_I960 */
3997 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
3998 /* 386 COFF uses a peculiar format in which the
3999 value of a common symbol is stored in the .text
4000 segment (I've checked this on SVR3.2 and SCO
4001 3.2.2) Ian Taylor <ian@cygnus.com>. */
4002 if (S_IS_COMMON (add_symbolP
))
4003 add_number
+= S_GET_VALUE (add_symbolP
);
4008 } /* switch on symbol seg */
4009 } /* if not in local seg */
4010 } /* if there was a + symbol */
4014 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4015 /* This adjustment is not correct on the m88k, for which the
4016 linker does all the computation. */
4017 add_number
-= md_pcrel_from (fixP
);
4019 if (add_symbolP
== 0)
4021 fixP
->fx_addsy
= &abs_symbol
;
4022 } /* if there's an add_symbol */
4023 #if defined (TC_I386) || defined (TE_LYNX)
4024 /* On the 386 we must adjust by the segment vaddr
4025 as well. Ian Taylor. */
4026 add_number
-= segP
->scnhdr
.s_vaddr
;
4030 if (!fixP
->fx_bit_fixP
)
4033 /* The m88k uses the offset field of the reloc to get around
4036 && (add_number
& ~0xFF)
4037 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
4039 && (add_number
& ~0xFFFF)
4040 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
4042 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4043 "Value of %ld too large for field of %d bytes at 0x%lx",
4044 (long) add_number
, size
,
4045 (unsigned long) (fragP
->fr_address
+ where
));
4048 #ifdef WARN_SIGNED_OVERFLOW_WORD
4049 /* Warn if a .word value is too large when treated as a
4050 signed number. We already know it is not too negative.
4051 This is to catch over-large switches generated by gcc on
4053 if (!flag_signed_overflow_ok
4055 && add_number
> 0x7fff)
4056 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4057 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4059 (unsigned long) (fragP
->fr_address
+ where
));
4061 } /* not a bit fix */
4062 /* Once this fix has been applied, we don't have to output
4063 anything nothing more need be done. */
4064 #ifdef MD_APPLY_FIX3
4065 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4067 md_apply_fix (fixP
, add_number
);
4069 } /* For each fixS in this segment. */
4070 } /* fixup_segment() */
4074 /* The first entry in a .stab section is special. */
4077 obj_coff_init_stab_section (seg
)
4083 unsigned int stroff
;
4085 /* Make space for this first symbol. */
4089 as_where (&file
, (unsigned int *) NULL
);
4090 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].scnhdr
.s_name
) + 4);
4091 strcpy (stabstr_name
, segment_info
[seg
].scnhdr
.s_name
);
4092 strcat (stabstr_name
, "str");
4093 stroff
= get_stab_string_offset (file
, stabstr_name
);
4095 md_number_to_chars (p
, stroff
, 4);
4098 /* Fill in the counts in the first entry in a .stab section. */
4101 adjust_stab_section(abfd
, seg
)
4105 segT stabstrseg
= SEG_UNKNOWN
;
4106 char *secname
, *name
, *name2
;
4108 int i
, strsz
= 0, nsyms
;
4109 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4111 /* Look for the associated string table section. */
4113 secname
= segment_info
[seg
].scnhdr
.s_name
;
4114 name
= (char *) alloca (strlen (secname
) + 4);
4115 strcpy (name
, secname
);
4116 strcat (name
, "str");
4118 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4120 name2
= segment_info
[i
].scnhdr
.s_name
;
4121 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4128 /* If we found the section, get its size. */
4129 if (stabstrseg
!= SEG_UNKNOWN
)
4130 strsz
= size_section (abfd
, stabstrseg
);
4132 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4134 /* Look for the first frag of sufficient size for the initial stab
4135 symbol, and collect a pointer to it. */
4136 while (frag
&& frag
->fr_fix
< 12)
4137 frag
= frag
->fr_next
;
4139 p
= frag
->fr_literal
;
4142 /* Write in the number of stab symbols and the size of the string
4144 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4145 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4148 #endif /* not BFD_ASSEMBLER */
4150 const pseudo_typeS obj_pseudo_table
[] =
4152 {"def", obj_coff_def
, 0},
4153 {"dim", obj_coff_dim
, 0},
4154 {"endef", obj_coff_endef
, 0},
4155 {"line", obj_coff_line
, 0},
4156 {"ln", obj_coff_ln
, 0},
4157 {"appline", obj_coff_ln
, 1},
4158 {"scl", obj_coff_scl
, 0},
4159 {"size", obj_coff_size
, 0},
4160 {"tag", obj_coff_tag
, 0},
4161 {"type", obj_coff_type
, 0},
4162 {"val", obj_coff_val
, 0},
4163 {"section", obj_coff_section
, 0},
4164 {"sect", obj_coff_section
, 0},
4165 /* FIXME: We ignore the MRI short attribute. */
4166 {"section.s", obj_coff_section
, 0},
4167 {"sect.s", obj_coff_section
, 0},
4168 #ifndef BFD_ASSEMBLER
4169 {"use", obj_coff_section
, 0},
4170 {"text", obj_coff_text
, 0},
4171 {"data", obj_coff_data
, 0},
4172 {"bss", obj_coff_bss
, 0},
4173 {"lcomm", obj_coff_lcomm
, 0},
4174 {"ident", obj_coff_ident
, 0},
4176 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4177 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4179 {"ABORT", s_abort
, 0},
4181 /* The m88k uses sdef instead of def. */
4182 {"sdef", obj_coff_def
, 0},
4184 {NULL
} /* end sentinel */
4185 }; /* obj_pseudo_table */