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 ()));
1243 demand_empty_rest_of_line ();
1247 coff_adjust_symtab ()
1249 if (symbol_rootP
== NULL
1250 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1252 assert (previous_file_symbol
== 0);
1253 c_dot_file_symbol ("fake");
1258 coff_frob_section (sec
)
1264 bfd_vma size
, n_entries
, mask
;
1266 /* The COFF back end in BFD requires that all section sizes be
1267 rounded up to multiples of the corresponding section alignments.
1268 Seems kinda silly to me, but that's the way it is. */
1269 size
= bfd_get_section_size_before_reloc (sec
);
1270 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1273 size
= (size
+ mask
) & ~mask
;
1274 bfd_set_section_size (stdoutput
, sec
, size
);
1277 /* If the section size is non-zero, the section symbol needs an aux
1278 entry associated with it, indicating the size. We don't know
1279 all the values yet; coff_frob_symbol will fill them in later. */
1282 symbolS
*secsym
= section_symbol (sec
);
1284 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1285 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1286 SF_SET_STATICS (secsym
);
1287 SA_SET_SCN_SCNLEN (secsym
, size
);
1290 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1291 #ifndef STAB_SECTION_NAME
1292 #define STAB_SECTION_NAME ".stab"
1294 #ifndef STAB_STRING_SECTION_NAME
1295 #define STAB_STRING_SECTION_NAME ".stabstr"
1297 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1301 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1302 /* size is already rounded up, since other section will be listed first */
1303 size
= bfd_get_section_size_before_reloc (strsec
);
1305 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1307 /* Find first non-empty frag. It should be large enough. */
1308 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1309 while (fragp
&& fragp
->fr_fix
== 0)
1310 fragp
= fragp
->fr_next
;
1311 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1313 /* Store the values. */
1314 p
= fragp
->fr_literal
;
1315 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1316 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1320 obj_coff_init_stab_section (seg
)
1326 unsigned int stroff
;
1328 /* Make space for this first symbol. */
1332 as_where (&file
, (unsigned int *) NULL
);
1333 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1334 strcpy (stabstr_name
, seg
->name
);
1335 strcat (stabstr_name
, "str");
1336 stroff
= get_stab_string_offset (file
, stabstr_name
);
1338 md_number_to_chars (p
, stroff
, 4);
1347 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1355 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1357 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1358 (unsigned long) symbolP
,
1359 S_GET_NAME(symbolP
),
1360 (long) S_GET_DATA_TYPE(symbolP
),
1361 S_GET_STORAGE_CLASS(symbolP
),
1362 (int) S_GET_SEGMENT(symbolP
));
1368 #else /* not BFD_ASSEMBLER */
1371 /* This is needed because we include internal bfd things. */
1375 #include "libcoff.h"
1378 #include "coff/pe.h"
1381 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1382 that we can stick sections together without causing trouble. */
1384 #define NOP_OPCODE 0x00
1387 /* The zeroes if symbol name is longer than 8 chars */
1388 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1390 #define MIN(a,b) ((a) < (b)? (a) : (b))
1391 /* This vector is used to turn an internal segment into a section #
1392 suitable for insertion into a coff symbol table
1395 const short seg_N_TYPE
[] =
1396 { /* in: segT out: N_TYPE bits */
1398 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1399 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1400 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1401 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1402 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1403 C_UNDEF_SECTION
, /* SEG_GOOF */
1404 C_UNDEF_SECTION
, /* SEG_EXPR */
1405 C_DEBUG_SECTION
, /* SEG_DEBUG */
1406 C_NTV_SECTION
, /* SEG_NTV */
1407 C_PTV_SECTION
, /* SEG_PTV */
1408 C_REGISTER_SECTION
, /* SEG_REGISTER */
1411 int function_lineoff
= -1; /* Offset in line#s where the last function
1412 started (the odd entry for line #0) */
1414 static symbolS
*last_line_symbol
;
1416 /* Add 4 to the real value to get the index and compensate the
1417 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1418 section number into a segment number
1420 static symbolS
*previous_file_symbol
;
1421 void c_symbol_merge ();
1422 static int line_base
;
1424 symbolS
*c_section_symbol ();
1427 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1428 segT this_segment_type
));
1431 static void fixup_mdeps
PARAMS ((fragS
*,
1436 static void fill_section
PARAMS ((bfd
* abfd
,
1441 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1446 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1447 symbolS
* symbol_rootP
));
1449 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1451 static void obj_coff_lcomm
PARAMS ((int));
1452 static void obj_coff_text
PARAMS ((int));
1453 static void obj_coff_data
PARAMS ((int));
1454 static void obj_coff_bss
PARAMS ((int));
1455 static void obj_coff_ident
PARAMS ((int));
1456 void obj_coff_section
PARAMS ((int));
1460 We allow more than just the standard 3 sections, infact, we allow
1461 40 sections, (though the usual three have to be there).
1463 This structure performs the mappings for us:
1473 static const seg_info_type seg_info_off_by_4
[] =
1480 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1481 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1482 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1483 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1484 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1485 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1486 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1487 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1502 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1504 static relax_addressT
1505 relax_align (address
, alignment
)
1506 relax_addressT address
;
1509 relax_addressT mask
;
1510 relax_addressT new_address
;
1512 mask
= ~((~0) << alignment
);
1513 new_address
= (address
+ mask
) & (~mask
);
1514 return (new_address
- address
);
1522 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1527 /* calculate the size of the frag chain and fill in the section header
1528 to contain all of it, also fill in the addr of the sections */
1530 size_section (abfd
, idx
)
1535 unsigned int size
= 0;
1536 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1539 size
= frag
->fr_address
;
1540 if (frag
->fr_address
!= size
)
1542 fprintf (stderr
, "Out of step\n");
1543 size
= frag
->fr_address
;
1546 switch (frag
->fr_type
)
1548 #ifdef TC_COFF_SIZEMACHDEP
1549 case rs_machine_dependent
:
1550 size
+= TC_COFF_SIZEMACHDEP (frag
);
1554 assert (frag
->fr_symbol
== 0);
1557 size
+= frag
->fr_fix
;
1558 size
+= frag
->fr_offset
* frag
->fr_var
;
1562 size
+= frag
->fr_fix
;
1563 size
+= relax_align (size
, frag
->fr_offset
);
1566 BAD_CASE (frag
->fr_type
);
1569 frag
= frag
->fr_next
;
1571 segment_info
[idx
].scnhdr
.s_size
= size
;
1577 count_entries_in_chain (idx
)
1580 unsigned int nrelocs
;
1583 /* Count the relocations */
1584 fixup_ptr
= segment_info
[idx
].fix_root
;
1586 while (fixup_ptr
!= (fixS
*) NULL
)
1588 if (TC_COUNT_RELOC (fixup_ptr
))
1591 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1600 fixup_ptr
= fixup_ptr
->fx_next
;
1607 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1609 /* AUX's ld expects relocations to be sorted */
1611 compare_external_relocs (x
, y
)
1615 struct external_reloc
*a
= (struct external_reloc
*) x
;
1616 struct external_reloc
*b
= (struct external_reloc
*) y
;
1617 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1618 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1619 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1624 /* output all the relocations for a section */
1626 do_relocs_for (abfd
, h
, file_cursor
)
1629 unsigned long *file_cursor
;
1631 unsigned int nrelocs
;
1633 unsigned long reloc_start
= *file_cursor
;
1635 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1637 if (segment_info
[idx
].scnhdr
.s_name
[0])
1639 struct external_reloc
*ext_ptr
;
1640 struct external_reloc
*external_reloc_vec
;
1641 unsigned int external_reloc_size
;
1642 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1643 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1644 nrelocs
= count_entries_in_chain (idx
);
1647 /* Bypass this stuff if no relocs. This also incidentally
1648 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1650 external_reloc_size
= nrelocs
* RELSZ
;
1651 external_reloc_vec
=
1652 (struct external_reloc
*) malloc (external_reloc_size
);
1654 ext_ptr
= external_reloc_vec
;
1656 /* Fill in the internal coff style reloc struct from the
1657 internal fix list. */
1660 struct internal_reloc intr
;
1662 /* Only output some of the relocations */
1663 if (TC_COUNT_RELOC (fix_ptr
))
1665 #ifdef TC_RELOC_MANGLE
1666 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1671 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1673 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1675 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1677 #ifdef TC_KEEP_FX_OFFSET
1678 intr
.r_offset
= fix_ptr
->fx_offset
;
1683 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1684 && (! S_IS_DEFINED (symbol_ptr
)
1685 || S_IS_COMMON (symbol_ptr
)))
1686 symbol_ptr
= symbol_ptr
->sy_value
.X_add_symbol
;
1688 /* Turn the segment of the symbol into an offset. */
1691 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1694 intr
.r_symndx
= dot
->sy_number
;
1698 intr
.r_symndx
= symbol_ptr
->sy_number
;
1708 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1711 #if defined(TC_A29K)
1713 /* The 29k has a special kludge for the high 16 bit
1714 reloc. Two relocations are emited, R_IHIHALF,
1715 and R_IHCONST. The second one doesn't contain a
1716 symbol, but uses the value for offset. */
1718 if (intr
.r_type
== R_IHIHALF
)
1720 /* now emit the second bit */
1721 intr
.r_type
= R_IHCONST
;
1722 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1723 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1729 fix_ptr
= fix_ptr
->fx_next
;
1733 /* Sort the reloc table */
1734 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1735 sizeof (struct external_reloc
), compare_external_relocs
);
1738 /* Write out the reloc table */
1739 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1741 free (external_reloc_vec
);
1743 /* Fill in section header info. */
1744 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1745 *file_cursor
+= external_reloc_size
;
1746 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1751 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1755 /* Set relocation_size field in file headers */
1756 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1760 /* run through a frag chain and write out the data to go with it, fill
1761 in the scnhdrs with the info on the file postions
1764 fill_section (abfd
, h
, file_cursor
)
1767 unsigned long *file_cursor
;
1771 unsigned int paddr
= 0;
1773 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1775 unsigned int offset
= 0;
1776 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1782 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1789 buffer
= xmalloc (s
->s_size
);
1790 s
->s_scnptr
= *file_cursor
;
1792 know (s
->s_paddr
== paddr
);
1794 if (strcmp (s
->s_name
, ".text") == 0)
1795 s
->s_flags
|= STYP_TEXT
;
1796 else if (strcmp (s
->s_name
, ".data") == 0)
1797 s
->s_flags
|= STYP_DATA
;
1798 else if (strcmp (s
->s_name
, ".bss") == 0)
1801 s
->s_flags
|= STYP_BSS
;
1803 /* @@ Should make the i386 and a29k coff targets define
1804 COFF_NOLOAD_PROBLEM, and have only one test here. */
1807 #ifndef COFF_NOLOAD_PROBLEM
1808 /* Apparently the SVR3 linker (and exec syscall) and UDI
1809 mondfe progrem are confused by noload sections. */
1810 s
->s_flags
|= STYP_NOLOAD
;
1815 else if (strcmp (s
->s_name
, ".lit") == 0)
1816 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1817 else if (strcmp (s
->s_name
, ".init") == 0)
1818 s
->s_flags
|= STYP_TEXT
;
1819 else if (strcmp (s
->s_name
, ".fini") == 0)
1820 s
->s_flags
|= STYP_TEXT
;
1821 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1822 s
->s_flags
|= STYP_INFO
;
1826 unsigned int fill_size
;
1827 switch (frag
->fr_type
)
1829 case rs_machine_dependent
:
1832 memcpy (buffer
+ frag
->fr_address
,
1834 (unsigned int) frag
->fr_fix
);
1835 offset
+= frag
->fr_fix
;
1840 assert (frag
->fr_symbol
== 0);
1847 memcpy (buffer
+ frag
->fr_address
,
1849 (unsigned int) frag
->fr_fix
);
1850 offset
+= frag
->fr_fix
;
1853 fill_size
= frag
->fr_var
;
1854 if (fill_size
&& frag
->fr_offset
> 0)
1857 unsigned int off
= frag
->fr_fix
;
1858 for (count
= frag
->fr_offset
; count
; count
--)
1860 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1862 memcpy (buffer
+ frag
->fr_address
+ off
,
1863 frag
->fr_literal
+ frag
->fr_fix
,
1866 offset
+= fill_size
;
1871 case rs_broken_word
:
1876 frag
= frag
->fr_next
;
1881 if (s
->s_scnptr
!= 0)
1883 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1884 *file_cursor
+= s
->s_size
;
1893 /* Coff file generation & utilities */
1896 coff_header_append (abfd
, h
)
1904 bfd_seek (abfd
, 0, 0);
1906 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1907 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1908 H_SET_VERSION_STAMP (h
, 0);
1909 H_SET_ENTRY_POINT (h
, 0);
1910 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1911 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1912 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1914 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1915 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1916 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1918 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1920 bfd_write (buffer
, i
, 1, abfd
);
1921 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1923 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1925 #ifdef COFF_LONG_SECTION_NAMES
1926 unsigned long string_size
= 4;
1929 if (segment_info
[i
].scnhdr
.s_name
[0])
1933 #ifdef COFF_LONG_SECTION_NAMES
1934 /* Support long section names as found in PE. This code
1935 must coordinate with that in write_object_file and
1937 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1939 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1940 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%d", string_size
);
1941 string_size
+= strlen (segment_info
[i
].scnhdr
.name
) + 1;
1945 size
= bfd_coff_swap_scnhdr_out (abfd
,
1946 &(segment_info
[i
].scnhdr
),
1949 as_bad ("bfd_coff_swap_scnhdr_out failed");
1950 bfd_write (buffer
, size
, 1, abfd
);
1957 symbol_to_chars (abfd
, where
, symbolP
)
1962 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1966 /* Turn any symbols with register attributes into abs symbols */
1967 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1969 S_SET_SEGMENT (symbolP
, absolute_section
);
1971 /* At the same time, relocate all symbols to their output value */
1973 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1974 + S_GET_VALUE (symbolP
));
1976 S_SET_VALUE (symbolP
, val
);
1978 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1980 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1983 for (i
= 0; i
< numaux
; i
++)
1985 where
+= bfd_coff_swap_aux_out (abfd
,
1986 &symbolP
->sy_symbol
.ost_auxent
[i
],
1987 S_GET_DATA_TYPE (symbolP
),
1988 S_GET_STORAGE_CLASS (symbolP
),
1996 obj_symbol_new_hook (symbolP
)
1999 char underscore
= 0; /* Symbol has leading _ */
2001 /* Effective symbol */
2002 /* Store the pointer in the offset. */
2003 S_SET_ZEROES (symbolP
, 0L);
2004 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2005 S_SET_STORAGE_CLASS (symbolP
, 0);
2006 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2007 /* Additional information */
2008 symbolP
->sy_symbol
.ost_flags
= 0;
2009 /* Auxiliary entries */
2010 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2012 if (S_IS_STRING (symbolP
))
2013 SF_SET_STRING (symbolP
);
2014 if (!underscore
&& S_IS_LOCAL (symbolP
))
2015 SF_SET_LOCAL (symbolP
);
2019 * Handle .ln directives.
2023 obj_coff_ln (appline
)
2028 if (! appline
&& def_symbol_in_progress
!= NULL
)
2030 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2031 demand_empty_rest_of_line ();
2033 } /* wrong context */
2035 l
= get_absolute_expression ();
2036 c_line_new (0, frag_now_fix (), l
, frag_now
);
2045 listing_source_line ((unsigned int) l
);
2050 demand_empty_rest_of_line ();
2056 * Handle .def directives.
2058 * One might ask : why can't we symbol_new if the symbol does not
2059 * already exist and fill it with debug information. Because of
2060 * the C_EFCN special symbol. It would clobber the value of the
2061 * function symbol before we have a chance to notice that it is
2062 * a C_EFCN. And a second reason is that the code is more clear this
2063 * way. (at least I think it is :-).
2067 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2068 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2069 *input_line_pointer == '\t') \
2070 input_line_pointer++;
2076 char name_end
; /* Char after the end of name */
2077 char *symbol_name
; /* Name of the debug symbol */
2078 char *symbol_name_copy
; /* Temporary copy of the name */
2079 unsigned int symbol_name_length
;
2081 if (def_symbol_in_progress
!= NULL
)
2083 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2084 demand_empty_rest_of_line ();
2086 } /* if not inside .def/.endef */
2088 SKIP_WHITESPACES ();
2090 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2091 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2093 symbol_name
= input_line_pointer
;
2094 name_end
= get_symbol_end ();
2095 symbol_name_length
= strlen (symbol_name
);
2096 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2097 strcpy (symbol_name_copy
, symbol_name
);
2099 /* Initialize the new symbol */
2100 #ifdef STRIP_UNDERSCORE
2101 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2102 ? symbol_name_copy
+ 1
2103 : symbol_name_copy
));
2104 #else /* STRIP_UNDERSCORE */
2105 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2106 #endif /* STRIP_UNDERSCORE */
2107 /* free(symbol_name_copy); */
2108 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2109 def_symbol_in_progress
->sy_number
= ~0;
2110 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2111 S_SET_VALUE (def_symbol_in_progress
, 0);
2113 if (S_IS_STRING (def_symbol_in_progress
))
2114 SF_SET_STRING (def_symbol_in_progress
);
2116 *input_line_pointer
= name_end
;
2118 demand_empty_rest_of_line ();
2121 unsigned int dim_index
;
2125 obj_coff_endef (ignore
)
2128 symbolS
*symbolP
= 0;
2129 /* DIM BUG FIX sac@cygnus.com */
2131 if (def_symbol_in_progress
== NULL
)
2133 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2134 demand_empty_rest_of_line ();
2136 } /* if not inside .def/.endef */
2138 /* Set the section number according to storage class. */
2139 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2144 SF_SET_TAG (def_symbol_in_progress
);
2145 /* intentional fallthrough */
2148 SF_SET_DEBUG (def_symbol_in_progress
);
2149 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2153 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2154 /* intentional fallthrough */
2156 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2157 /* intentional fallthrough */
2159 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2161 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2163 if (function_lineoff
< 0)
2165 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2166 } /* missing function symbol */
2167 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2169 SF_SET_PROCESS (last_line_symbol
);
2170 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2171 SF_SET_PROCESS (def_symbol_in_progress
);
2172 function_lineoff
= -1;
2174 /* Value is always set to . */
2175 def_symbol_in_progress
->sy_frag
= frag_now
;
2176 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2181 #endif /* C_AUTOARG */
2191 SF_SET_DEBUG (def_symbol_in_progress
);
2192 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2198 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2204 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2206 } /* switch on storage class */
2208 /* Now that we have built a debug symbol, try to find if we should
2209 merge with an existing symbol or not. If a symbol is C_EFCN or
2210 absolute_section or untagged SEG_DEBUG it never merges. We also
2211 don't merge labels, which are in a different namespace, nor
2212 symbols which have not yet been defined since they are typically
2213 unique, nor do we merge tags with non-tags. */
2215 /* Two cases for functions. Either debug followed by definition or
2216 definition followed by debug. For definition first, we will
2217 merge the debug symbol into the definition. For debug first, the
2218 lineno entry MUST point to the definition function or else it
2219 will point off into space when crawl_symbols() merges the debug
2220 symbol into the real symbol. Therefor, let's presume the debug
2221 symbol is a real function reference. */
2223 /* FIXME-SOON If for some reason the definition label/symbol is
2224 never seen, this will probably leave an undefined symbol at link
2227 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2228 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2229 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2230 && !SF_GET_TAG (def_symbol_in_progress
))
2231 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2232 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2233 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2234 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2236 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2241 /* This symbol already exists, merge the newly created symbol
2242 into the old one. This is not mandatory. The linker can
2243 handle duplicate symbols correctly. But I guess that it save
2244 a *lot* of space if the assembly file defines a lot of
2247 /* The debug entry (def_symbol_in_progress) is merged into the
2248 previous definition. */
2250 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2251 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2252 def_symbol_in_progress
= symbolP
;
2254 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2255 || SF_GET_TAG (def_symbol_in_progress
))
2257 /* For functions, and tags, the symbol *must* be where the
2258 debug symbol appears. Move the existing symbol to the
2260 /* If it already is at the end of the symbol list, do nothing */
2261 if (def_symbol_in_progress
!= symbol_lastP
)
2263 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2265 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2266 &symbol_rootP
, &symbol_lastP
);
2267 } /* if not already in place */
2269 } /* normal or mergable */
2271 if (SF_GET_TAG (def_symbol_in_progress
)
2272 && symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
) == NULL
)
2274 tag_insert (S_GET_NAME (def_symbol_in_progress
), def_symbol_in_progress
);
2277 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2279 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2281 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2283 SF_SET_PROCESS (def_symbol_in_progress
);
2285 if (symbolP
== NULL
)
2287 /* That is, if this is the first time we've seen the
2289 symbol_table_insert (def_symbol_in_progress
);
2290 } /* definition follows debug */
2291 } /* Create the line number entry pointing to the function being defined */
2293 def_symbol_in_progress
= NULL
;
2294 demand_empty_rest_of_line ();
2298 obj_coff_dim (ignore
)
2303 if (def_symbol_in_progress
== NULL
)
2305 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2306 demand_empty_rest_of_line ();
2308 } /* if not inside .def/.endef */
2310 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2312 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2314 SKIP_WHITESPACES ();
2315 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2316 get_absolute_expression ());
2318 switch (*input_line_pointer
)
2321 input_line_pointer
++;
2325 as_warn ("badly formed .dim directive ignored");
2326 /* intentional fallthrough */
2334 demand_empty_rest_of_line ();
2338 obj_coff_line (ignore
)
2344 if (def_symbol_in_progress
== NULL
)
2350 name
= S_GET_NAME (def_symbol_in_progress
);
2351 this_base
= get_absolute_expression ();
2353 /* Only .bf symbols indicate the use of a new base line number; the
2354 line numbers associated with .ef, .bb, .eb are relative to the
2355 start of the containing function. */
2356 if (!strcmp (".bf", name
))
2358 #if 0 /* XXX Can we ever have line numbers going backwards? */
2359 if (this_base
> line_base
)
2362 line_base
= this_base
;
2370 listing_source_line ((unsigned int) line_base
);
2376 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2377 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2379 demand_empty_rest_of_line ();
2383 obj_coff_size (ignore
)
2386 if (def_symbol_in_progress
== NULL
)
2388 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2389 demand_empty_rest_of_line ();
2391 } /* if not inside .def/.endef */
2393 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2394 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2395 demand_empty_rest_of_line ();
2399 obj_coff_scl (ignore
)
2402 if (def_symbol_in_progress
== NULL
)
2404 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2405 demand_empty_rest_of_line ();
2407 } /* if not inside .def/.endef */
2409 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2410 demand_empty_rest_of_line ();
2414 obj_coff_tag (ignore
)
2420 if (def_symbol_in_progress
== NULL
)
2422 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2423 demand_empty_rest_of_line ();
2427 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2428 symbol_name
= input_line_pointer
;
2429 name_end
= get_symbol_end ();
2431 /* Assume that the symbol referred to by .tag is always defined.
2432 This was a bad assumption. I've added find_or_make. xoxorich. */
2433 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2434 (long) tag_find_or_make (symbol_name
));
2435 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2437 as_warn ("tag not found for .tag %s", symbol_name
);
2440 SF_SET_TAGGED (def_symbol_in_progress
);
2441 *input_line_pointer
= name_end
;
2443 demand_empty_rest_of_line ();
2447 obj_coff_type (ignore
)
2450 if (def_symbol_in_progress
== NULL
)
2452 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2453 demand_empty_rest_of_line ();
2455 } /* if not inside .def/.endef */
2457 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2459 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2460 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2462 SF_SET_FUNCTION (def_symbol_in_progress
);
2463 } /* is a function */
2465 demand_empty_rest_of_line ();
2469 obj_coff_val (ignore
)
2472 if (def_symbol_in_progress
== NULL
)
2474 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2475 demand_empty_rest_of_line ();
2477 } /* if not inside .def/.endef */
2479 if (is_name_beginner (*input_line_pointer
))
2481 char *symbol_name
= input_line_pointer
;
2482 char name_end
= get_symbol_end ();
2484 if (!strcmp (symbol_name
, "."))
2486 def_symbol_in_progress
->sy_frag
= frag_now
;
2487 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2488 /* If the .val is != from the .def (e.g. statics) */
2490 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2492 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2493 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2494 symbol_find_or_make (symbol_name
);
2495 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2496 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2498 /* If the segment is undefined when the forward reference is
2499 resolved, then copy the segment id from the forward
2501 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2503 /* FIXME: gcc can generate address expressions
2504 here in unusual cases (search for "obscure"
2505 in sdbout.c). We just ignore the offset
2506 here, thus generating incorrect debugging
2507 information. We ignore the rest of the
2510 /* Otherwise, it is the name of a non debug symbol and
2511 its value will be calculated later. */
2512 *input_line_pointer
= name_end
;
2514 /* FIXME: this is to avoid an error message in the
2515 FIXME case mentioned just above. */
2516 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2517 ++input_line_pointer
;
2521 S_SET_VALUE (def_symbol_in_progress
,
2522 (valueT
) get_absolute_expression ());
2523 } /* if symbol based */
2525 demand_empty_rest_of_line ();
2530 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2531 read.c, which then calls this object file format specific routine. */
2534 obj_coff_pe_handle_link_once (type
)
2535 enum linkonce_type type
;
2537 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2539 /* We store the type in the seg_info structure, and use it to set up
2540 the auxiliary entry for the section symbol in c_section_symbol. */
2541 seg_info (now_seg
)->linkonce
= type
;
2547 obj_read_begin_hook ()
2549 /* These had better be the same. Usually 18 bytes. */
2551 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2552 know (SYMESZ
== AUXESZ
);
2557 /* This function runs through the symbol table and puts all the
2558 externals onto another chain */
2560 /* The chain of globals. */
2561 symbolS
*symbol_globalP
;
2562 symbolS
*symbol_global_lastP
;
2564 /* The chain of externals */
2565 symbolS
*symbol_externP
;
2566 symbolS
*symbol_extern_lastP
;
2569 symbolS
*last_functionP
;
2570 static symbolS
*last_bfP
;
2577 unsigned int symbol_number
= 0;
2578 unsigned int last_file_symno
= 0;
2580 struct filename_list
*filename_list_scan
= filename_list_head
;
2582 for (symbolP
= symbol_rootP
;
2584 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2586 if (symbolP
->sy_mri_common
)
2588 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2589 as_bad ("%s: global symbols not supported in common sections",
2590 S_GET_NAME (symbolP
));
2591 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2595 if (!SF_GET_DEBUG (symbolP
))
2597 /* Debug symbols do not need all this rubbish */
2598 symbolS
*real_symbolP
;
2600 /* L* and C_EFCN symbols never merge. */
2601 if (!SF_GET_LOCAL (symbolP
)
2602 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2603 && symbolP
->sy_value
.X_op
== O_constant
2604 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2605 && real_symbolP
!= symbolP
)
2607 /* FIXME-SOON: where do dups come from?
2608 Maybe tag references before definitions? xoxorich. */
2609 /* Move the debug data from the debug symbol to the
2610 real symbol. Do NOT do the oposite (i.e. move from
2611 real symbol to debug symbol and remove real symbol from the
2612 list.) Because some pointers refer to the real symbol
2613 whereas no pointers refer to the debug symbol. */
2614 c_symbol_merge (symbolP
, real_symbolP
);
2615 /* Replace the current symbol by the real one */
2616 /* The symbols will never be the last or the first
2617 because : 1st symbol is .file and 3 last symbols are
2618 .text, .data, .bss */
2619 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2620 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2621 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2622 symbolP
= real_symbolP
;
2623 } /* if not local but dup'd */
2625 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2627 S_SET_SEGMENT (symbolP
, SEG_E0
);
2628 } /* push data into text */
2630 resolve_symbol_value (symbolP
);
2632 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2634 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2636 S_SET_EXTERNAL (symbolP
);
2638 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2640 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2644 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2648 /* Mainly to speed up if not -g */
2649 if (SF_GET_PROCESS (symbolP
))
2651 /* Handle the nested blocks auxiliary info. */
2652 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2654 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2655 stack_push (block_stack
, (char *) &symbolP
);
2658 register symbolS
*begin_symbolP
;
2659 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2660 if (begin_symbolP
== (symbolS
*) 0)
2661 as_warn ("mismatched .eb");
2663 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2666 /* If we are able to identify the type of a function, and we
2667 are out of a function (last_functionP == 0) then, the
2668 function symbol will be associated with an auxiliary
2670 if (last_functionP
== (symbolS
*) 0 &&
2671 SF_GET_FUNCTION (symbolP
))
2673 last_functionP
= symbolP
;
2675 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2677 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2678 } /* make it at least 1 */
2680 /* Clobber possible stale .dim information. */
2682 /* Iffed out by steve - this fries the lnnoptr info too */
2683 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2684 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2687 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2689 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2691 if (last_bfP
!= NULL
)
2692 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2696 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2698 /* I don't even know if this is needed for sdb. But
2699 the standard assembler generates it, so... */
2700 if (last_functionP
== (symbolS
*) 0)
2701 as_fatal ("C_EFCN symbol out of scope");
2702 SA_SET_SYM_FSIZE (last_functionP
,
2703 (long) (S_GET_VALUE (symbolP
) -
2704 S_GET_VALUE (last_functionP
)));
2705 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2706 last_functionP
= (symbolS
*) 0;
2710 else if (SF_GET_TAG (symbolP
))
2712 /* First descriptor of a structure must point to
2713 the first slot after the structure description. */
2714 last_tagP
= symbolP
;
2717 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2719 /* +2 take in account the current symbol */
2720 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2722 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2724 /* If the filename was too long to fit in the
2725 auxent, put it in the string table */
2726 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2728 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2729 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2730 filename_list_scan
= filename_list_scan
->next
;
2732 if (S_GET_VALUE (symbolP
))
2734 S_SET_VALUE (symbolP
, last_file_symno
);
2735 last_file_symno
= symbol_number
;
2736 } /* no one points at the first .file symbol */
2737 } /* if debug or tag or eos or file */
2739 /* We must put the external symbols apart. The loader
2740 does not bomb if we do not. But the references in
2741 the endndx field for a .bb symbol are not corrected
2742 if an external symbol is removed between .bb and .be.
2743 I.e in the following case :
2744 [20] .bb endndx = 22
2747 ld will move the symbol 21 to the end of the list but
2748 endndx will still be 22 instead of 21. */
2751 if (SF_GET_LOCAL (symbolP
))
2753 /* remove C_EFCN and LOCAL (L...) symbols */
2754 /* next pointer remains valid */
2755 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2758 else if (symbolP
->sy_value
.X_op
== O_symbol
2759 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2761 /* Skip symbols which were equated to undefined or common
2763 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2765 else if (!S_IS_DEFINED (symbolP
)
2766 && !S_IS_DEBUG (symbolP
)
2767 && !SF_GET_STATICS (symbolP
) &&
2768 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2769 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2770 /* if external, Remove from the list */
2771 symbolS
*hold
= symbol_previous (symbolP
);
2773 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2774 symbol_clear_list_pointers (symbolP
);
2775 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2778 else if (! S_IS_DEBUG (symbolP
)
2779 && ! SF_GET_STATICS (symbolP
)
2780 && ! SF_GET_FUNCTION (symbolP
)
2781 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2783 symbolS
*hold
= symbol_previous (symbolP
);
2785 /* The O'Reilly COFF book says that defined global symbols
2786 come at the end of the symbol table, just before
2787 undefined global symbols. */
2789 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2790 symbol_clear_list_pointers (symbolP
);
2791 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2792 &symbol_global_lastP
);
2797 if (SF_GET_STRING (symbolP
))
2799 symbolP
->sy_name_offset
= string_byte_count
;
2800 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2804 symbolP
->sy_name_offset
= 0;
2805 } /* fix "long" names */
2807 symbolP
->sy_number
= symbol_number
;
2808 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2809 } /* if local symbol */
2810 } /* traverse the symbol list */
2811 return symbol_number
;
2817 glue_symbols (head
, tail
)
2821 unsigned int symbol_number
= 0;
2824 for (symbolP
= *head
; *head
!= NULL
;)
2826 symbolS
*tmp
= *head
;
2829 symbol_remove (tmp
, head
, tail
);
2830 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2833 if (SF_GET_STRING (tmp
))
2835 tmp
->sy_name_offset
= string_byte_count
;
2836 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2840 tmp
->sy_name_offset
= 0;
2841 } /* fix "long" names */
2843 tmp
->sy_number
= symbol_number
;
2844 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2845 } /* append the entire extern chain */
2847 return symbol_number
;
2853 unsigned int symbol_number
= 0;
2856 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2857 symbol_next (symbolP
))
2859 symbolP
->sy_number
= symbol_number
;
2863 if (SF_GET_TAGGED (symbolP
))
2867 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2870 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2872 return symbol_number
;
2877 crawl_symbols (h
, abfd
)
2883 /* Initialize the stack used to keep track of the matching .bb .be */
2885 block_stack
= stack_init (512, sizeof (symbolS
*));
2887 /* The symbol list should be ordered according to the following sequence
2890 * . debug entries for functions
2891 * . fake symbols for the sections, including.text .data and .bss
2893 * . undefined symbols
2894 * But this is not mandatory. The only important point is to put the
2895 * undefined symbols at the end of the list.
2898 if (symbol_rootP
== NULL
2899 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2901 c_dot_file_symbol ("fake");
2903 /* Is there a .file symbol ? If not insert one at the beginning. */
2906 * Build up static symbols for the sections, they are filled in later
2910 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2911 if (segment_info
[i
].scnhdr
.s_name
[0])
2912 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2915 /* Take all the externals out and put them into another chain */
2916 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2917 /* Take the externals and glue them onto the end.*/
2918 H_SET_SYMBOL_TABLE_SIZE (h
,
2919 (H_GET_SYMBOL_COUNT (h
)
2920 + glue_symbols (&symbol_globalP
,
2921 &symbol_global_lastP
)
2922 + glue_symbols (&symbol_externP
,
2923 &symbol_extern_lastP
)));
2925 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2926 know (symbol_globalP
== NULL
);
2927 know (symbol_global_lastP
== NULL
);
2928 know (symbol_externP
== NULL
);
2929 know (symbol_extern_lastP
== NULL
);
2933 * Find strings by crawling along symbol table chain.
2941 struct filename_list
*filename_list_scan
= filename_list_head
;
2943 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2944 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2947 #ifdef COFF_LONG_SECTION_NAMES
2948 /* Support long section names as found in PE. This code must
2949 coordinate with that in coff_header_append and write_object_file. */
2950 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2952 if (segment_info
[i
].scnhdr
.s_name
[0]
2953 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2957 size
= strlen (segment_info
[i
].name
) + 1;
2958 memcpy (where
, segment_info
[i
].name
, size
);
2962 #endif /* COFF_LONG_SECTION_NAMES */
2964 for (symbolP
= symbol_rootP
;
2966 symbolP
= symbol_next (symbolP
))
2970 if (SF_GET_STRING (symbolP
))
2972 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2973 memcpy (where
, S_GET_NAME (symbolP
), size
);
2976 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2977 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0)
2979 size
= strlen (filename_list_scan
->filename
) + 1;
2980 memcpy (where
, filename_list_scan
->filename
, size
);
2981 filename_list_scan
= filename_list_scan
->next
;
2988 do_linenos_for (abfd
, h
, file_cursor
)
2991 unsigned long *file_cursor
;
2994 unsigned long start
= *file_cursor
;
2996 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
2998 segment_info_type
*s
= segment_info
+ idx
;
3001 if (s
->scnhdr
.s_nlnno
!= 0)
3003 struct lineno_list
*line_ptr
;
3005 struct external_lineno
*buffer
=
3006 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3008 struct external_lineno
*dst
= buffer
;
3010 /* Run through the table we've built and turn it into its external
3011 form, take this chance to remove duplicates */
3013 for (line_ptr
= s
->lineno_list_head
;
3014 line_ptr
!= (struct lineno_list
*) NULL
;
3015 line_ptr
= line_ptr
->next
)
3018 if (line_ptr
->line
.l_lnno
== 0)
3020 /* Turn a pointer to a symbol into the symbols' index */
3021 line_ptr
->line
.l_addr
.l_symndx
=
3022 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3026 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3030 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3035 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3037 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3040 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3043 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3047 /* Now we run through the list of frag chains in a segment and
3048 make all the subsegment frags appear at the end of the
3049 list, as if the seg 0 was extra long */
3056 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3058 frchainS
*head
= segment_info
[i
].frchainP
;
3060 fragS
*prev_frag
= &dummy
;
3062 while (head
&& head
->frch_seg
== i
)
3064 prev_frag
->fr_next
= head
->frch_root
;
3065 prev_frag
= head
->frch_last
;
3066 head
= head
->frch_next
;
3068 prev_frag
->fr_next
= 0;
3072 unsigned long machine
;
3075 write_object_file ()
3079 struct frchain
*frchain_ptr
;
3081 object_headers headers
;
3082 unsigned long file_cursor
;
3085 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3090 as_perror ("FATAL: Can't create %s", out_file_name
);
3091 exit (EXIT_FAILURE
);
3093 bfd_set_format (abfd
, bfd_object
);
3094 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3096 string_byte_count
= 4;
3098 for (frchain_ptr
= frchain_root
;
3099 frchain_ptr
!= (struct frchain
*) NULL
;
3100 frchain_ptr
= frchain_ptr
->frch_next
)
3102 /* Run through all the sub-segments and align them up. Also
3103 close any open frags. We tack a .fill onto the end of the
3104 frag chain so that any .align's size can be worked by looking
3105 at the next frag. */
3107 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3108 #ifndef SUB_SEGMENT_ALIGN
3109 #define SUB_SEGMENT_ALIGN(SEG) 1
3113 static char nop
= NOP_OPCODE
;
3114 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, alignment_done
);
3117 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
3121 frag_wane (frag_now
);
3122 frag_now
->fr_fix
= 0;
3123 know (frag_now
->fr_next
== NULL
);
3130 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3132 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3135 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3137 /* Find out how big the sections are, and set the addresses. */
3139 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3143 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3144 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3146 if (segment_info
[i
].scnhdr
.s_name
[0])
3148 H_SET_NUMBER_OF_SECTIONS (&headers
,
3149 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3151 #ifdef COFF_LONG_SECTION_NAMES
3152 /* Support long section names as found in PE. This code
3153 must coordinate with that in coff_header_append and
3158 len
= strlen (segment_info
[i
].name
);
3160 string_byte_count
+= len
+ 1;
3162 #endif /* COFF_LONG_SECTION_NAMES */
3165 size
= size_section (abfd
, (unsigned int) i
);
3168 /* I think the section alignment is only used on the i960; the
3169 i960 needs it, and it should do no harm on other targets. */
3170 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3173 H_SET_TEXT_SIZE (&headers
, size
);
3174 else if (i
== SEG_E1
)
3175 H_SET_DATA_SIZE (&headers
, size
);
3176 else if (i
== SEG_E2
)
3177 H_SET_BSS_SIZE (&headers
, size
);
3180 /* Turn the gas native symbol table shape into a coff symbol table */
3181 crawl_symbols (&headers
, abfd
);
3183 if (string_byte_count
== 4)
3184 string_byte_count
= 0;
3186 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3192 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3194 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3195 fixup_segment (&segment_info
[i
], i
);
3198 /* Look for ".stab" segments and fill in their initial symbols
3200 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3202 name
= segment_info
[i
].name
;
3205 && strncmp (".stab", name
, 5) == 0
3206 && strncmp (".stabstr", name
, 8) != 0)
3207 adjust_stab_section (abfd
, i
);
3210 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3212 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3214 /* Plant the data */
3216 fill_section (abfd
, &headers
, &file_cursor
);
3218 do_relocs_for (abfd
, &headers
, &file_cursor
);
3220 do_linenos_for (abfd
, &headers
, &file_cursor
);
3222 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3223 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3224 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3226 H_SET_TIME_STAMP (&headers
, 0);
3228 #ifdef TC_COFF_SET_MACHINE
3229 TC_COFF_SET_MACHINE (&headers
);
3233 #define COFF_FLAGS 0
3236 #ifdef KEEP_RELOC_INFO
3237 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3238 COFF_FLAGS
| coff_flags
));
3240 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3241 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3242 COFF_FLAGS
| coff_flags
));
3246 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3247 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3249 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3250 w_symbols (abfd
, buffer1
, symbol_rootP
);
3251 if (string_byte_count
> 0)
3252 w_strings (buffer1
+ symtable_size
);
3253 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3257 coff_header_append (abfd
, &headers
);
3259 /* Recent changes to write need this, but where it should
3260 go is up to Ken.. */
3261 if (bfd_close_all_done (abfd
) == false)
3262 as_fatal ("Can't close %s: %s", out_file_name
,
3263 bfd_errmsg (bfd_get_error ()));
3266 extern bfd
*stdoutput
;
3273 /* Add a new segment. This is called from subseg_new via the
3274 obj_new_segment macro. */
3277 obj_coff_add_segment (name
)
3283 #ifndef COFF_LONG_SECTION_NAMES
3284 char buf
[SCNNMLEN
+ 1];
3286 strncpy (buf
, name
, SCNNMLEN
);
3287 buf
[SCNNMLEN
] = '\0';
3291 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3292 if (strcmp (name
, segment_info
[i
].name
) == 0)
3297 as_bad ("Too many new sections; can't add \"%s\"", name
);
3301 /* Add a new section. */
3302 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3303 sizeof (segment_info
[i
].scnhdr
.s_name
));
3304 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3305 segment_info
[i
].name
= xstrdup (name
);
3311 * implement the .section pseudo op:
3312 * .section name {, "flags"}
3314 * | +--- optional flags: 'b' for bss
3316 * +-- section name 'l' for lib
3320 * 'd' (apparently m88k for data)
3322 * But if the argument is not a quoted string, treat it as a
3323 * subsegment number.
3327 obj_coff_section (ignore
)
3330 /* Strip out the section name */
3331 char *section_name
, *name
;
3344 else if (type
== 'D')
3346 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3351 section_name
= input_line_pointer
;
3352 c
= get_symbol_end ();
3354 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3355 strcpy (name
, section_name
);
3357 *input_line_pointer
= c
;
3363 if (*input_line_pointer
== ',')
3365 ++input_line_pointer
;
3368 if (*input_line_pointer
!= '"')
3369 exp
= get_absolute_expression ();
3372 ++input_line_pointer
;
3373 while (*input_line_pointer
!= '"'
3374 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3376 switch (*input_line_pointer
)
3378 case 'b': flags
|= STYP_BSS
; break;
3379 case 'i': flags
|= STYP_INFO
; break;
3380 case 'l': flags
|= STYP_LIB
; break;
3381 case 'n': flags
|= STYP_NOLOAD
; break;
3382 case 'o': flags
|= STYP_OVER
; break;
3384 case 'w': flags
|= STYP_DATA
; break;
3385 case 'x': flags
|= STYP_TEXT
; break;
3387 as_warn("unknown section attribute '%c'",
3388 *input_line_pointer
);
3391 ++input_line_pointer
;
3393 if (*input_line_pointer
== '"')
3394 ++input_line_pointer
;
3398 subseg_new (name
, (subsegT
) exp
);
3400 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3402 demand_empty_rest_of_line ();
3407 obj_coff_text (ignore
)
3410 subseg_new (".text", get_absolute_expression ());
3415 obj_coff_data (ignore
)
3418 if (flag_readonly_data_in_text
)
3419 subseg_new (".text", get_absolute_expression () + 1000);
3421 subseg_new (".data", get_absolute_expression ());
3425 obj_coff_bss (ignore
)
3428 if (*input_line_pointer
== '\n') /* .bss */
3429 subseg_new(".bss", get_absolute_expression());
3430 else /* .bss id,expr */
3435 obj_coff_ident (ignore
)
3438 segT current_seg
= now_seg
; /* save current seg */
3439 subsegT current_subseg
= now_subseg
;
3440 subseg_new (".comment", 0); /* .comment seg */
3441 stringer (1); /* read string */
3442 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3446 c_symbol_merge (debug
, normal
)
3450 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3451 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3453 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3455 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3456 } /* take the most we have */
3458 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3460 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3461 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3462 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3463 } /* Move all the auxiliary information */
3465 /* Move the debug flags. */
3466 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3467 } /* c_symbol_merge() */
3470 c_line_new (symbol
, paddr
, line_number
, frag
)
3476 struct lineno_list
*new_line
=
3477 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3479 segment_info_type
*s
= segment_info
+ now_seg
;
3480 new_line
->line
.l_lnno
= line_number
;
3482 if (line_number
== 0)
3484 last_line_symbol
= symbol
;
3485 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3489 new_line
->line
.l_addr
.l_paddr
= paddr
;
3492 new_line
->frag
= (char *) frag
;
3493 new_line
->next
= (struct lineno_list
*) NULL
;
3496 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3498 s
->lineno_list_head
= new_line
;
3502 s
->lineno_list_tail
->next
= new_line
;
3504 s
->lineno_list_tail
= new_line
;
3505 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3509 c_dot_file_symbol (filename
)
3514 symbolP
= symbol_new (".file",
3517 &zero_address_frag
);
3519 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3520 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3522 if (strlen (filename
) > FILNMLEN
)
3524 /* Filename is too long to fit into an auxent,
3525 we stick it into the string table instead. We keep
3526 a linked list of the filenames we find so we can emit
3528 struct filename_list
*f
= ((struct filename_list
*)
3529 xmalloc (sizeof (struct filename_list
)));
3531 f
->filename
= filename
;
3534 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3535 SA_SET_FILE_FNAME_OFFSET (symbolP
, 0);
3537 if (filename_list_tail
)
3538 filename_list_tail
->next
= f
;
3540 filename_list_head
= f
;
3541 filename_list_tail
= f
;
3545 SA_SET_FILE_FNAME (symbolP
, filename
);
3552 listing_source_file (filename
);
3558 SF_SET_DEBUG (symbolP
);
3559 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3561 previous_file_symbol
= symbolP
;
3563 /* Make sure that the symbol is first on the symbol chain */
3564 if (symbol_rootP
!= symbolP
)
3566 if (symbolP
== symbol_lastP
)
3568 symbol_lastP
= symbol_lastP
->sy_previous
;
3569 } /* if it was the last thing on the list */
3571 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3572 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3573 symbol_rootP
= symbolP
;
3574 } /* if not first on the list */
3576 } /* c_dot_file_symbol() */
3579 * Build a 'section static' symbol.
3583 c_section_symbol (name
, idx
)
3589 symbolP
= symbol_new (name
, idx
,
3591 &zero_address_frag
);
3593 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3594 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3596 SF_SET_STATICS (symbolP
);
3599 /* If the .linkonce pseudo-op was used for this section, we must
3600 store the information in the auxiliary entry for the section
3602 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3606 switch (segment_info
[idx
].linkonce
)
3610 case LINKONCE_DISCARD
:
3611 type
= IMAGE_COMDAT_SELECT_ANY
;
3613 case LINKONCE_ONE_ONLY
:
3614 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3616 case LINKONCE_SAME_SIZE
:
3617 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3619 case LINKONCE_SAME_CONTENTS
:
3620 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3624 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3629 } /* c_section_symbol() */
3632 w_symbols (abfd
, where
, symbol_rootP
)
3635 symbolS
* symbol_rootP
;
3640 /* First fill in those values we have only just worked out */
3641 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3643 symbolP
= segment_info
[i
].dot
;
3646 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3647 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3648 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3653 * Emit all symbols left in the symbol chain.
3655 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3657 /* Used to save the offset of the name. It is used to point
3658 to the string in memory but must be a file offset. */
3659 register char *temp
;
3661 /* We can't fix the lnnoptr field in yank_symbols with the other
3662 adjustments, because we have to wait until we know where they
3664 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3666 SA_GET_SYM_LNNOPTR (symbolP
) +=
3667 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3670 tc_coff_symbol_emit_hook (symbolP
);
3672 temp
= S_GET_NAME (symbolP
);
3673 if (SF_GET_STRING (symbolP
))
3675 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3676 S_SET_ZEROES (symbolP
, 0);
3680 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3681 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3683 where
= symbol_to_chars (abfd
, where
, symbolP
);
3684 S_SET_NAME (symbolP
, temp
);
3690 obj_coff_lcomm (ignore
)
3703 name
= input_line_pointer
;
3705 c
= get_symbol_end ();
3706 p
= input_line_pointer
;
3709 if (*input_line_pointer
!= ',')
3711 as_bad ("Expected comma after name");
3712 ignore_rest_of_line ();
3715 if (*input_line_pointer
== '\n')
3717 as_bad ("Missing size expression");
3720 input_line_pointer
++;
3721 if ((temp
= get_absolute_expression ()) < 0)
3723 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3724 ignore_rest_of_line ();
3729 symbolP
= symbol_find_or_make(name
);
3731 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3732 S_GET_VALUE(symbolP
) == 0)
3737 segT current_seg
= now_seg
; /* save current seg */
3738 subsegT current_subseg
= now_subseg
;
3740 subseg_set (SEG_E2
, 1);
3741 symbolP
->sy_frag
= frag_now
;
3742 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3745 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3746 S_SET_SEGMENT(symbolP
, SEG_E2
);
3747 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3751 as_bad("Symbol %s already defined", name
);
3753 demand_empty_rest_of_line();
3758 fixup_mdeps (frags
, h
, this_segment
)
3763 subseg_change (this_segment
, 0);
3766 switch (frags
->fr_type
)
3772 HANDLE_ALIGN (frags
);
3774 frags
->fr_type
= rs_fill
;
3776 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3779 case rs_machine_dependent
:
3780 md_convert_frag (h
, this_segment
, frags
);
3786 frags
= frags
->fr_next
;
3792 #ifndef TC_FORCE_RELOCATION
3793 #define TC_FORCE_RELOCATION(fix) 0
3797 fixup_segment (segP
, this_segment_type
)
3798 segment_info_type
* segP
;
3799 segT this_segment_type
;
3801 register fixS
* fixP
;
3802 register symbolS
*add_symbolP
;
3803 register symbolS
*sub_symbolP
;
3806 register char *place
;
3807 register long where
;
3808 register char pcrel
;
3809 register fragS
*fragP
;
3810 register segT add_symbol_segment
= absolute_section
;
3815 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3817 fragP
= fixP
->fx_frag
;
3819 where
= fixP
->fx_where
;
3820 place
= fragP
->fr_literal
+ where
;
3821 size
= fixP
->fx_size
;
3822 add_symbolP
= fixP
->fx_addsy
;
3824 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3826 /* Relocation should be done via the associated 'bal' entry
3829 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3831 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3832 "No 'bal' entry point for leafproc %s",
3833 S_GET_NAME (add_symbolP
));
3836 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3839 sub_symbolP
= fixP
->fx_subsy
;
3840 add_number
= fixP
->fx_offset
;
3841 pcrel
= fixP
->fx_pcrel
;
3843 if (add_symbolP
!= NULL
3844 && add_symbolP
->sy_mri_common
)
3846 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3847 add_number
+= S_GET_VALUE (add_symbolP
);
3848 fixP
->fx_offset
= add_number
;
3849 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3854 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3855 } /* if there is an addend */
3859 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3861 if (add_symbolP
!= NULL
)
3863 add_number
+= S_GET_VALUE (add_symbolP
);
3865 fixP
->fx_addsy
= NULL
;
3868 /* It's just -sym. */
3869 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3871 add_number
-= S_GET_VALUE (sub_symbolP
);
3878 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3879 "Negative of non-absolute symbol %s",
3880 S_GET_NAME (sub_symbolP
));
3882 add_number
-= S_GET_VALUE (sub_symbolP
);
3883 } /* not absolute */
3885 /* if sub_symbol is in the same segment that add_symbol
3886 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3888 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3889 && SEG_NORMAL (add_symbol_segment
))
3891 /* Difference of 2 symbols from same segment. Can't
3892 make difference of 2 undefineds: 'value' means
3893 something different for N_UNDF. */
3895 /* Makes no sense to use the difference of 2 arbitrary symbols
3896 as the target of a call instruction. */
3899 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3900 "callj to difference of 2 symbols");
3902 #endif /* TC_I960 */
3903 add_number
+= S_GET_VALUE (add_symbolP
) -
3904 S_GET_VALUE (sub_symbolP
);
3907 if (!TC_FORCE_RELOCATION (fixP
))
3909 fixP
->fx_addsy
= NULL
;
3910 fixP
->fx_subsy
= NULL
;
3912 #ifdef TC_M68K /* is this right? */
3920 /* Different segments in subtraction. */
3921 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3923 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3925 add_number
-= S_GET_VALUE (sub_symbolP
);
3928 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3929 #if 0 /* Okay for 68k, at least... */
3934 /* Make it pc-relative. */
3935 add_number
+= (md_pcrel_from (fixP
)
3936 - S_GET_VALUE (sub_symbolP
));
3945 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3946 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3947 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3948 S_GET_NAME (sub_symbolP
),
3949 (long) (fragP
->fr_address
+ where
));
3952 } /* if sub_symbolP */
3956 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3959 * This fixup was made when the symbol's segment was
3960 * SEG_UNKNOWN, but it is now in the local segment.
3961 * So we know how to do the address without relocation.
3964 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3965 * in which cases it modifies *fixP as appropriate. In the case
3966 * of a 'calls', no further work is required, and *fixP has been
3967 * set up to make the rest of the code below a no-op.
3970 #endif /* TC_I960 */
3972 add_number
+= S_GET_VALUE (add_symbolP
);
3973 add_number
-= md_pcrel_from (fixP
);
3974 #if defined (TC_I386) || defined (TE_LYNX)
3975 /* On the 386 we must adjust by the segment
3976 vaddr as well. Ian Taylor. */
3977 add_number
-= segP
->scnhdr
.s_vaddr
;
3979 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3980 if (!TC_FORCE_RELOCATION (fixP
))
3982 fixP
->fx_addsy
= NULL
;
3988 switch (add_symbol_segment
)
3990 case absolute_section
:
3992 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
3993 #endif /* TC_I960 */
3994 add_number
+= S_GET_VALUE (add_symbolP
);
3997 if (!TC_FORCE_RELOCATION (fixP
))
3999 fixP
->fx_addsy
= NULL
;
4006 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4007 /* This really should be handled in the linker, but
4008 backward compatibility forbids. */
4009 add_number
+= S_GET_VALUE (add_symbolP
);
4011 add_number
+= S_GET_VALUE (add_symbolP
) +
4012 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4018 if ((int) fixP
->fx_bit_fixP
== 13)
4020 /* This is a COBR instruction. They have only a
4021 * 13-bit displacement and are only to be used
4022 * for local branches: flag as error, don't generate
4025 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4026 "can't use COBR format with external label");
4027 fixP
->fx_addsy
= NULL
;
4031 #endif /* TC_I960 */
4032 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
4033 /* 386 COFF uses a peculiar format in which the
4034 value of a common symbol is stored in the .text
4035 segment (I've checked this on SVR3.2 and SCO
4036 3.2.2) Ian Taylor <ian@cygnus.com>. */
4037 if (S_IS_COMMON (add_symbolP
))
4038 add_number
+= S_GET_VALUE (add_symbolP
);
4043 } /* switch on symbol seg */
4044 } /* if not in local seg */
4045 } /* if there was a + symbol */
4049 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4050 /* This adjustment is not correct on the m88k, for which the
4051 linker does all the computation. */
4052 add_number
-= md_pcrel_from (fixP
);
4054 if (add_symbolP
== 0)
4056 fixP
->fx_addsy
= &abs_symbol
;
4057 } /* if there's an add_symbol */
4058 #if defined (TC_I386) || defined (TE_LYNX)
4059 /* On the 386 we must adjust by the segment vaddr
4060 as well. Ian Taylor. */
4061 add_number
-= segP
->scnhdr
.s_vaddr
;
4065 if (!fixP
->fx_bit_fixP
)
4068 /* The m88k uses the offset field of the reloc to get around
4071 && (add_number
& ~0xFF)
4072 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
4074 && (add_number
& ~0xFFFF)
4075 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
4077 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4078 "Value of %ld too large for field of %d bytes at 0x%lx",
4079 (long) add_number
, size
,
4080 (unsigned long) (fragP
->fr_address
+ where
));
4083 #ifdef WARN_SIGNED_OVERFLOW_WORD
4084 /* Warn if a .word value is too large when treated as a
4085 signed number. We already know it is not too negative.
4086 This is to catch over-large switches generated by gcc on
4088 if (!flag_signed_overflow_ok
4090 && add_number
> 0x7fff)
4091 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4092 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4094 (unsigned long) (fragP
->fr_address
+ where
));
4096 } /* not a bit fix */
4097 /* Once this fix has been applied, we don't have to output
4098 anything nothing more need be done. */
4099 #ifdef MD_APPLY_FIX3
4100 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4102 md_apply_fix (fixP
, add_number
);
4104 } /* For each fixS in this segment. */
4105 } /* fixup_segment() */
4109 /* The first entry in a .stab section is special. */
4112 obj_coff_init_stab_section (seg
)
4118 unsigned int stroff
;
4120 /* Make space for this first symbol. */
4124 as_where (&file
, (unsigned int *) NULL
);
4125 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4126 strcpy (stabstr_name
, segment_info
[seg
].name
);
4127 strcat (stabstr_name
, "str");
4128 stroff
= get_stab_string_offset (file
, stabstr_name
);
4130 md_number_to_chars (p
, stroff
, 4);
4133 /* Fill in the counts in the first entry in a .stab section. */
4136 adjust_stab_section(abfd
, seg
)
4140 segT stabstrseg
= SEG_UNKNOWN
;
4141 char *secname
, *name
, *name2
;
4143 int i
, strsz
= 0, nsyms
;
4144 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4146 /* Look for the associated string table section. */
4148 secname
= segment_info
[seg
].name
;
4149 name
= (char *) alloca (strlen (secname
) + 4);
4150 strcpy (name
, secname
);
4151 strcat (name
, "str");
4153 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4155 name2
= segment_info
[i
].name
;
4156 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4163 /* If we found the section, get its size. */
4164 if (stabstrseg
!= SEG_UNKNOWN
)
4165 strsz
= size_section (abfd
, stabstrseg
);
4167 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4169 /* Look for the first frag of sufficient size for the initial stab
4170 symbol, and collect a pointer to it. */
4171 while (frag
&& frag
->fr_fix
< 12)
4172 frag
= frag
->fr_next
;
4174 p
= frag
->fr_literal
;
4177 /* Write in the number of stab symbols and the size of the string
4179 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4180 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4183 #endif /* not BFD_ASSEMBLER */
4185 const pseudo_typeS obj_pseudo_table
[] =
4187 {"def", obj_coff_def
, 0},
4188 {"dim", obj_coff_dim
, 0},
4189 {"endef", obj_coff_endef
, 0},
4190 {"line", obj_coff_line
, 0},
4191 {"ln", obj_coff_ln
, 0},
4192 {"appline", obj_coff_ln
, 1},
4193 {"scl", obj_coff_scl
, 0},
4194 {"size", obj_coff_size
, 0},
4195 {"tag", obj_coff_tag
, 0},
4196 {"type", obj_coff_type
, 0},
4197 {"val", obj_coff_val
, 0},
4198 {"section", obj_coff_section
, 0},
4199 {"sect", obj_coff_section
, 0},
4200 /* FIXME: We ignore the MRI short attribute. */
4201 {"section.s", obj_coff_section
, 0},
4202 {"sect.s", obj_coff_section
, 0},
4203 #ifndef BFD_ASSEMBLER
4204 {"use", obj_coff_section
, 0},
4205 {"text", obj_coff_text
, 0},
4206 {"data", obj_coff_data
, 0},
4207 {"bss", obj_coff_bss
, 0},
4208 {"lcomm", obj_coff_lcomm
, 0},
4209 {"ident", obj_coff_ident
, 0},
4211 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4212 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4214 {"ABORT", s_abort
, 0},
4216 /* The m88k uses sdef instead of def. */
4217 {"sdef", obj_coff_def
, 0},
4219 {NULL
} /* end sentinel */
4220 }; /* obj_pseudo_table */