1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 static void obj_coff_bss
PARAMS ((int));
34 const char *s_get_name
PARAMS ((symbolS
* s
));
35 static symbolS
*def_symbol_in_progress
;
41 unsigned long chunk_size
;
42 unsigned long element_size
;
45 unsigned long pointer
;
50 stack_init (chunk_size
, element_size
)
51 unsigned long chunk_size
;
52 unsigned long element_size
;
56 st
= (stack
*) malloc (sizeof (stack
));
59 st
->data
= malloc (chunk_size
);
66 st
->size
= chunk_size
;
67 st
->chunk_size
= chunk_size
;
68 st
->element_size
= element_size
;
73 /* Not currently used. */
84 stack_push (st
, element
)
88 if (st
->pointer
+ st
->element_size
>= st
->size
)
90 st
->size
+= st
->chunk_size
;
91 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
94 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
95 st
->pointer
+= st
->element_size
;
96 return st
->data
+ st
->pointer
;
103 if (st
->pointer
< st
->element_size
)
108 st
->pointer
-= st
->element_size
;
109 return st
->data
+ st
->pointer
;
113 * Maintain a list of the tagnames of the structres.
116 static struct hash_control
*tag_hash
;
121 tag_hash
= hash_new ();
125 tag_insert (name
, symbolP
)
129 const char *error_string
;
131 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
133 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
142 #ifdef STRIP_UNDERSCORE
145 #endif /* STRIP_UNDERSCORE */
146 return (symbolS
*) hash_find (tag_hash
, name
);
150 tag_find_or_make (name
)
155 if ((symbolP
= tag_find (name
)) == NULL
)
157 symbolP
= symbol_new (name
, undefined_section
,
158 0, &zero_address_frag
);
160 tag_insert (S_GET_NAME (symbolP
), symbolP
);
162 symbol_table_insert (symbolP
);
169 /* We accept the .bss directive to set the section for backward
170 compatibility with earlier versions of gas. */
173 obj_coff_bss (ignore
)
176 if (*input_line_pointer
== '\n')
177 subseg_new (".bss", get_absolute_expression ());
184 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
186 #define GET_FILENAME_STRING(X) \
187 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
191 fetch_coff_debug_section ()
193 static segT debug_section
;
197 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
199 debug_section
= s
->section
;
201 return debug_section
;
205 SA_SET_SYM_ENDNDX (sym
, val
)
209 combined_entry_type
*entry
, *p
;
211 entry
= &coffsymbol (sym
->bsym
)->native
[1];
212 p
= coffsymbol (val
->bsym
)->native
;
213 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
218 SA_SET_SYM_TAGNDX (sym
, val
)
222 combined_entry_type
*entry
, *p
;
224 entry
= &coffsymbol (sym
->bsym
)->native
[1];
225 p
= coffsymbol (val
->bsym
)->native
;
226 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
231 S_GET_DATA_TYPE (sym
)
234 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
238 S_SET_DATA_TYPE (sym
, val
)
242 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
247 S_GET_STORAGE_CLASS (sym
)
250 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
254 S_SET_STORAGE_CLASS (sym
, val
)
258 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
262 /* Merge a debug symbol containing debug information into a normal symbol. */
265 c_symbol_merge (debug
, normal
)
269 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
270 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
272 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
273 /* take the most we have */
274 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
276 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
278 /* Move all the auxiliary information. */
279 /* @@ How many fields do we want to preserve? Would it make more
280 sense to pick and choose those we want to copy? Should look
281 into this further.... [raeburn:19920512.2209EST] */
283 linenos
= coffsymbol (normal
->bsym
)->lineno
;
284 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
285 (char *) &coffsymbol (debug
->bsym
)->native
,
286 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
287 coffsymbol (normal
->bsym
)->lineno
= linenos
;
290 /* Move the debug flags. */
291 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
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 /* Make sure that the symbol is first on the symbol chain */
318 if (symbol_rootP
!= symbolP
)
320 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
321 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
322 } /* if not first on the list */
325 /* Line number handling */
328 struct line_no
*next
;
335 /* Symbol of last function, which we should hang line#s off of. */
336 static symbolS
*line_fsym
;
338 #define in_function() (line_fsym != 0)
339 #define clear_function() (line_fsym = 0)
340 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
344 coff_obj_symbol_new_hook (symbolP
)
347 char underscore
= 0; /* Symbol has leading _ */
350 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
351 char *s
= (char *) xmalloc (sz
);
353 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
355 S_SET_DATA_TYPE (symbolP
, T_NULL
);
356 S_SET_STORAGE_CLASS (symbolP
, 0);
357 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
359 if (S_IS_STRING (symbolP
))
360 SF_SET_STRING (symbolP
);
361 if (!underscore
&& S_IS_LOCAL (symbolP
))
362 SF_SET_LOCAL (symbolP
);
367 * Handle .ln directives.
370 static symbolS
*current_lineno_sym
;
371 static struct line_no
*line_nos
;
372 /* @@ Blindly assume all .ln directives will be in the .text section... */
376 add_lineno (frag
, offset
, num
)
381 struct line_no
*new_line
=
382 (struct line_no
*) xmalloc (sizeof (struct line_no
));
383 if (!current_lineno_sym
)
387 new_line
->next
= line_nos
;
388 new_line
->frag
= frag
;
389 new_line
->l
.line_number
= num
;
390 new_line
->l
.u
.offset
= offset
;
396 coff_add_linesym (sym
)
401 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
405 current_lineno_sym
= sym
;
409 obj_coff_ln (appline
)
414 if (! appline
&& def_symbol_in_progress
!= NULL
)
416 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
417 demand_empty_rest_of_line ();
421 l
= get_absolute_expression ();
424 add_lineno (frag_now
, frag_now_fix (), l
);
428 new_logical_line ((char *) NULL
, l
- 1);
437 l
+= coff_line_base
- 1;
438 listing_source_line (l
);
443 demand_empty_rest_of_line ();
449 * Handle .def directives.
451 * One might ask : why can't we symbol_new if the symbol does not
452 * already exist and fill it with debug information. Because of
453 * the C_EFCN special symbol. It would clobber the value of the
454 * function symbol before we have a chance to notice that it is
455 * a C_EFCN. And a second reason is that the code is more clear this
456 * way. (at least I think it is :-).
460 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
461 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
462 *input_line_pointer == '\t') \
463 input_line_pointer++;
469 char name_end
; /* Char after the end of name */
470 char *symbol_name
; /* Name of the debug symbol */
471 char *symbol_name_copy
; /* Temporary copy of the name */
472 unsigned int symbol_name_length
;
474 if (def_symbol_in_progress
!= NULL
)
476 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
477 demand_empty_rest_of_line ();
479 } /* if not inside .def/.endef */
483 symbol_name
= input_line_pointer
;
484 #ifdef STRIP_UNDERSCORE
485 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
487 #endif /* STRIP_UNDERSCORE */
489 name_end
= get_symbol_end ();
490 symbol_name_length
= strlen (symbol_name
);
491 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
492 strcpy (symbol_name_copy
, symbol_name
);
493 #ifdef tc_canonicalize_symbol_name
494 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
497 /* Initialize the new symbol */
498 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
499 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
500 S_SET_VALUE (def_symbol_in_progress
, 0);
502 if (S_IS_STRING (def_symbol_in_progress
))
503 SF_SET_STRING (def_symbol_in_progress
);
505 *input_line_pointer
= name_end
;
507 demand_empty_rest_of_line ();
510 unsigned int dim_index
;
513 obj_coff_endef (ignore
)
517 /* DIM BUG FIX sac@cygnus.com */
519 if (def_symbol_in_progress
== NULL
)
521 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
522 demand_empty_rest_of_line ();
524 } /* if not inside .def/.endef */
526 /* Set the section number according to storage class. */
527 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
532 SF_SET_TAG (def_symbol_in_progress
);
533 /* intentional fallthrough */
536 SF_SET_DEBUG (def_symbol_in_progress
);
537 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
541 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
542 /* intentional fallthrough */
544 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
545 /* intentional fallthrough */
549 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
551 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
552 if (name
[1] == 'b' && name
[2] == 'f')
554 if (! in_function ())
555 as_warn (_("`%s' symbol without preceding function"), name
);
556 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
557 /* Will need relocating */
558 SF_SET_PROCESS (def_symbol_in_progress
);
566 #endif /* C_AUTOARG */
572 SF_SET_DEBUG (def_symbol_in_progress
);
573 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
580 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
586 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
592 as_warn (_("unexpected storage class %d"),
593 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
595 } /* switch on storage class */
597 /* Now that we have built a debug symbol, try to find if we should
598 merge with an existing symbol or not. If a symbol is C_EFCN or
599 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
601 /* Two cases for functions. Either debug followed by definition or
602 definition followed by debug. For definition first, we will
603 merge the debug symbol into the definition. For debug first, the
604 lineno entry MUST point to the definition function or else it
605 will point off into space when obj_crawl_symbol_chain() merges
606 the debug symbol into the real symbol. Therefor, let's presume
607 the debug symbol is a real function reference. */
609 /* FIXME-SOON If for some reason the definition label/symbol is
610 never seen, this will probably leave an undefined symbol at link
613 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
614 || (!strcmp (bfd_get_section_name (stdoutput
,
615 S_GET_SEGMENT (def_symbol_in_progress
)),
617 && !SF_GET_TAG (def_symbol_in_progress
))
618 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
619 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
621 if (def_symbol_in_progress
!= symbol_lastP
)
622 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
627 /* This symbol already exists, merge the newly created symbol
628 into the old one. This is not mandatory. The linker can
629 handle duplicate symbols correctly. But I guess that it save
630 a *lot* of space if the assembly file defines a lot of
633 /* The debug entry (def_symbol_in_progress) is merged into the
634 previous definition. */
636 c_symbol_merge (def_symbol_in_progress
, symbolP
);
637 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
639 def_symbol_in_progress
= symbolP
;
641 if (SF_GET_FUNCTION (def_symbol_in_progress
)
642 || SF_GET_TAG (def_symbol_in_progress
)
643 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
645 /* For functions, and tags, and static symbols, the symbol
646 *must* be where the debug symbol appears. Move the
647 existing symbol to the current place. */
648 /* If it already is at the end of the symbol list, do nothing */
649 if (def_symbol_in_progress
!= symbol_lastP
)
651 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
652 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
657 if (SF_GET_TAG (def_symbol_in_progress
))
661 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
663 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
664 tag_insert (S_GET_NAME (def_symbol_in_progress
),
665 def_symbol_in_progress
);
668 if (SF_GET_FUNCTION (def_symbol_in_progress
))
670 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
671 set_function (def_symbol_in_progress
);
672 SF_SET_PROCESS (def_symbol_in_progress
);
676 /* That is, if this is the first time we've seen the
678 symbol_table_insert (def_symbol_in_progress
);
679 } /* definition follows debug */
680 } /* Create the line number entry pointing to the function being defined */
682 def_symbol_in_progress
= NULL
;
683 demand_empty_rest_of_line ();
687 obj_coff_dim (ignore
)
692 if (def_symbol_in_progress
== NULL
)
694 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
695 demand_empty_rest_of_line ();
697 } /* if not inside .def/.endef */
699 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
701 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
704 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
705 get_absolute_expression ());
707 switch (*input_line_pointer
)
710 input_line_pointer
++;
714 as_warn (_("badly formed .dim directive ignored"));
715 /* intentional fallthrough */
723 demand_empty_rest_of_line ();
727 obj_coff_line (ignore
)
732 if (def_symbol_in_progress
== NULL
)
734 /* Probably stabs-style line? */
739 this_base
= get_absolute_expression ();
740 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
741 coff_line_base
= this_base
;
743 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
744 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
746 demand_empty_rest_of_line ();
749 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
754 listing_source_line ((unsigned int) coff_line_base
);
760 obj_coff_size (ignore
)
763 if (def_symbol_in_progress
== NULL
)
765 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
766 demand_empty_rest_of_line ();
768 } /* if not inside .def/.endef */
770 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
771 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
772 demand_empty_rest_of_line ();
776 obj_coff_scl (ignore
)
779 if (def_symbol_in_progress
== NULL
)
781 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
782 demand_empty_rest_of_line ();
784 } /* if not inside .def/.endef */
786 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
787 demand_empty_rest_of_line ();
791 obj_coff_tag (ignore
)
797 if (def_symbol_in_progress
== NULL
)
799 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
800 demand_empty_rest_of_line ();
804 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
805 symbol_name
= input_line_pointer
;
806 name_end
= get_symbol_end ();
808 #ifdef tc_canonicalize_symbol_name
809 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
812 /* Assume that the symbol referred to by .tag is always defined.
813 This was a bad assumption. I've added find_or_make. xoxorich. */
814 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
815 tag_find_or_make (symbol_name
));
816 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
818 as_warn (_("tag not found for .tag %s"), symbol_name
);
821 SF_SET_TAGGED (def_symbol_in_progress
);
822 *input_line_pointer
= name_end
;
824 demand_empty_rest_of_line ();
828 obj_coff_type (ignore
)
831 if (def_symbol_in_progress
== NULL
)
833 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
834 demand_empty_rest_of_line ();
836 } /* if not inside .def/.endef */
838 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
840 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
841 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
843 SF_SET_FUNCTION (def_symbol_in_progress
);
844 } /* is a function */
846 demand_empty_rest_of_line ();
850 obj_coff_val (ignore
)
853 if (def_symbol_in_progress
== NULL
)
855 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
856 demand_empty_rest_of_line ();
858 } /* if not inside .def/.endef */
860 if (is_name_beginner (*input_line_pointer
))
862 char *symbol_name
= input_line_pointer
;
863 char name_end
= get_symbol_end ();
865 #ifdef tc_canonicalize_symbol_name
866 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
868 if (!strcmp (symbol_name
, "."))
870 def_symbol_in_progress
->sy_frag
= frag_now
;
871 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
872 /* If the .val is != from the .def (e.g. statics) */
874 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
876 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
877 def_symbol_in_progress
->sy_value
.X_add_symbol
=
878 symbol_find_or_make (symbol_name
);
879 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
880 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
882 /* If the segment is undefined when the forward reference is
883 resolved, then copy the segment id from the forward
885 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
887 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
888 *input_line_pointer
= name_end
;
892 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
893 } /* if symbol based */
895 demand_empty_rest_of_line ();
899 coff_obj_read_begin_hook ()
901 /* These had better be the same. Usually 18 bytes. */
903 know (sizeof (SYMENT
) == sizeof (AUXENT
));
904 know (SYMESZ
== AUXESZ
);
910 symbolS
*coff_last_function
;
911 static symbolS
*coff_last_bf
;
914 coff_frob_symbol (symp
, punt
)
918 static symbolS
*last_tagP
;
919 static stack
*block_stack
;
920 static symbolS
*set_end
;
921 symbolS
*next_set_end
= NULL
;
923 if (symp
== &abs_symbol
)
929 if (current_lineno_sym
)
930 coff_add_linesym ((symbolS
*) 0);
933 block_stack
= stack_init (512, sizeof (symbolS
*));
935 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
936 S_SET_STORAGE_CLASS (symp
, C_EXT
);
938 if (!SF_GET_DEBUG (symp
))
941 if (!SF_GET_LOCAL (symp
)
942 && !SF_GET_STATICS (symp
)
943 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
946 c_symbol_merge (symp
, real
);
949 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
951 assert (S_GET_VALUE (symp
) == 0);
952 S_SET_EXTERNAL (symp
);
954 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
956 if (S_GET_SEGMENT (symp
) == text_section
957 && symp
!= seg_info (text_section
)->sym
)
958 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
960 S_SET_STORAGE_CLASS (symp
, C_STAT
);
962 if (SF_GET_PROCESS (symp
))
964 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
966 if (!strcmp (S_GET_NAME (symp
), ".bb"))
967 stack_push (block_stack
, (char *) &symp
);
971 begin
= *(symbolS
**) stack_pop (block_stack
);
973 as_warn (_("mismatched .eb"));
975 next_set_end
= begin
;
978 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
980 union internal_auxent
*auxp
;
981 coff_last_function
= symp
;
982 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
983 S_SET_NUMBER_AUXILIARY (symp
, 1);
984 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
985 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
986 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
988 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
990 if (coff_last_function
== 0)
991 as_fatal (_("C_EFCN symbol out of scope"));
992 SA_SET_SYM_FSIZE (coff_last_function
,
993 (long) (S_GET_VALUE (symp
)
994 - S_GET_VALUE (coff_last_function
)));
995 next_set_end
= coff_last_function
;
996 coff_last_function
= 0;
999 if (S_IS_EXTERNAL (symp
))
1000 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1001 else if (SF_GET_LOCAL (symp
))
1004 if (SF_GET_FUNCTION (symp
))
1005 symp
->bsym
->flags
|= BSF_FUNCTION
;
1010 if (SF_GET_TAG (symp
))
1012 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1013 next_set_end
= last_tagP
;
1016 /* This is pretty horrible, but we have to set *punt correctly in
1017 order to call SA_SET_SYM_ENDNDX correctly. */
1018 if (! symp
->sy_used_in_reloc
1019 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1020 || (! S_IS_EXTERNAL (symp
)
1021 && ! symp
->sy_tc
.output
1022 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1026 if (set_end
!= (symbolS
*) NULL
1028 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1029 || (S_IS_DEFINED (symp
)
1030 && ! S_IS_COMMON (symp
)
1031 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1033 SA_SET_SYM_ENDNDX (set_end
, symp
);
1037 if (next_set_end
!= NULL
1039 set_end
= next_set_end
;
1042 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1043 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1045 if (coff_last_bf
!= NULL
)
1046 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1047 coff_last_bf
= symp
;
1050 if (coffsymbol (symp
->bsym
)->lineno
)
1053 struct line_no
*lptr
;
1056 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1057 for (i
= 0; lptr
; lptr
= lptr
->next
)
1059 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1061 /* We need i entries for line numbers, plus 1 for the first
1062 entry which BFD will override, plus 1 for the last zero
1063 entry (a marker for BFD). */
1064 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1065 coffsymbol (symp
->bsym
)->lineno
= l
;
1066 l
[i
+ 1].line_number
= 0;
1067 l
[i
+ 1].u
.sym
= NULL
;
1071 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1079 coff_adjust_section_syms (abfd
, sec
, x
)
1085 segment_info_type
*seginfo
= seg_info (sec
);
1086 int nlnno
, nrelocs
= 0;
1088 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1089 tc-ppc.c. Do not get confused by it. */
1090 if (seginfo
== NULL
)
1093 if (!strcmp (sec
->name
, ".text"))
1094 nlnno
= coff_n_line_nos
;
1098 /* @@ Hope that none of the fixups expand to more than one reloc
1100 fixS
*fixp
= seginfo
->fix_root
;
1103 if (! fixp
->fx_done
)
1105 fixp
= fixp
->fx_next
;
1108 if (bfd_get_section_size_before_reloc (sec
) == 0
1111 && sec
!= text_section
1112 && sec
!= data_section
1113 && sec
!= bss_section
)
1115 secsym
= section_symbol (sec
);
1116 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1117 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1121 coff_frob_file_after_relocs ()
1123 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1127 * implement the .section pseudo op:
1128 * .section name {, "flags"}
1130 * | +--- optional flags: 'b' for bss
1132 * +-- section name 'l' for lib
1136 * 'd' (apparently m88k for data)
1138 * 'r' for read-only data
1139 * But if the argument is not a quoted string, treat it as a
1140 * subsegment number.
1144 obj_coff_section (ignore
)
1147 /* Strip out the section name */
1163 section_name
= input_line_pointer
;
1164 c
= get_symbol_end ();
1166 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1167 strcpy (name
, section_name
);
1169 *input_line_pointer
= c
;
1174 flags
= SEC_NO_FLAGS
;
1176 if (*input_line_pointer
== ',')
1178 ++input_line_pointer
;
1180 if (*input_line_pointer
!= '"')
1181 exp
= get_absolute_expression ();
1184 ++input_line_pointer
;
1185 while (*input_line_pointer
!= '"'
1186 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1188 switch (*input_line_pointer
)
1190 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1191 case 'n': flags
&=~ SEC_LOAD
; break;
1193 case 'w': flags
&=~ SEC_READONLY
; break;
1194 case 'x': flags
|= SEC_CODE
; break;
1195 case 'r': flags
|= SEC_READONLY
; break;
1197 case 'i': /* STYP_INFO */
1198 case 'l': /* STYP_LIB */
1199 case 'o': /* STYP_OVER */
1200 as_warn (_("unsupported section attribute '%c'"),
1201 *input_line_pointer
);
1205 as_warn(_("unknown section attribute '%c'"),
1206 *input_line_pointer
);
1209 ++input_line_pointer
;
1211 if (*input_line_pointer
== '"')
1212 ++input_line_pointer
;
1216 sec
= subseg_new (name
, (subsegT
) exp
);
1218 if (flags
!= SEC_NO_FLAGS
)
1220 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1221 as_warn (_("error setting flags for \"%s\": %s"),
1222 bfd_section_name (stdoutput
, sec
),
1223 bfd_errmsg (bfd_get_error ()));
1226 demand_empty_rest_of_line ();
1230 coff_adjust_symtab ()
1232 if (symbol_rootP
== NULL
1233 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1234 c_dot_file_symbol ("fake");
1238 coff_frob_section (sec
)
1244 bfd_vma size
, n_entries
, mask
;
1246 /* The COFF back end in BFD requires that all section sizes be
1247 rounded up to multiples of the corresponding section alignments.
1248 Seems kinda silly to me, but that's the way it is. */
1249 size
= bfd_get_section_size_before_reloc (sec
);
1250 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1253 size
= (size
+ mask
) & ~mask
;
1254 bfd_set_section_size (stdoutput
, sec
, size
);
1257 /* If the section size is non-zero, the section symbol needs an aux
1258 entry associated with it, indicating the size. We don't know
1259 all the values yet; coff_frob_symbol will fill them in later. */
1261 || sec
== text_section
1262 || sec
== data_section
1263 || sec
== bss_section
)
1265 symbolS
*secsym
= section_symbol (sec
);
1267 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1268 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1269 SF_SET_STATICS (secsym
);
1270 SA_SET_SCN_SCNLEN (secsym
, size
);
1273 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1274 #ifndef STAB_SECTION_NAME
1275 #define STAB_SECTION_NAME ".stab"
1277 #ifndef STAB_STRING_SECTION_NAME
1278 #define STAB_STRING_SECTION_NAME ".stabstr"
1280 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1284 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1285 /* size is already rounded up, since other section will be listed first */
1286 size
= bfd_get_section_size_before_reloc (strsec
);
1288 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1290 /* Find first non-empty frag. It should be large enough. */
1291 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1292 while (fragp
&& fragp
->fr_fix
== 0)
1293 fragp
= fragp
->fr_next
;
1294 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1296 /* Store the values. */
1297 p
= fragp
->fr_literal
;
1298 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1299 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1303 obj_coff_init_stab_section (seg
)
1309 unsigned int stroff
;
1311 /* Make space for this first symbol. */
1315 as_where (&file
, (unsigned int *) NULL
);
1316 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1317 strcpy (stabstr_name
, seg
->name
);
1318 strcat (stabstr_name
, "str");
1319 stroff
= get_stab_string_offset (file
, stabstr_name
);
1321 md_number_to_chars (p
, stroff
, 4);
1330 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1338 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1340 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1341 (unsigned long) symbolP
,
1342 S_GET_NAME(symbolP
),
1343 (long) S_GET_DATA_TYPE(symbolP
),
1344 S_GET_STORAGE_CLASS(symbolP
),
1345 (int) S_GET_SEGMENT(symbolP
));
1351 #else /* not BFD_ASSEMBLER */
1354 /* This is needed because we include internal bfd things. */
1358 #include "libcoff.h"
1361 #include "coff/pe.h"
1364 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1365 that we can stick sections together without causing trouble. */
1367 #define NOP_OPCODE 0x00
1370 /* The zeroes if symbol name is longer than 8 chars */
1371 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1373 #define MIN(a,b) ((a) < (b)? (a) : (b))
1374 /* This vector is used to turn an internal segment into a section #
1375 suitable for insertion into a coff symbol table
1378 const short seg_N_TYPE
[] =
1379 { /* in: segT out: N_TYPE bits */
1381 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1382 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1383 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1384 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1385 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1386 C_UNDEF_SECTION
, /* SEG_GOOF */
1387 C_UNDEF_SECTION
, /* SEG_EXPR */
1388 C_DEBUG_SECTION
, /* SEG_DEBUG */
1389 C_NTV_SECTION
, /* SEG_NTV */
1390 C_PTV_SECTION
, /* SEG_PTV */
1391 C_REGISTER_SECTION
, /* SEG_REGISTER */
1394 int function_lineoff
= -1; /* Offset in line#s where the last function
1395 started (the odd entry for line #0) */
1397 /* structure used to keep the filenames which
1398 are too long around so that we can stick them
1399 into the string table */
1400 struct filename_list
1403 struct filename_list
*next
;
1406 static struct filename_list
*filename_list_head
;
1407 static struct filename_list
*filename_list_tail
;
1409 static symbolS
*last_line_symbol
;
1411 /* Add 4 to the real value to get the index and compensate the
1412 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1413 section number into a segment number
1415 static symbolS
*previous_file_symbol
;
1416 void c_symbol_merge ();
1417 static int line_base
;
1419 symbolS
*c_section_symbol ();
1422 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1423 segT this_segment_type
));
1426 static void fixup_mdeps
PARAMS ((fragS
*,
1431 static void fill_section
PARAMS ((bfd
* abfd
,
1436 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1441 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1442 symbolS
* symbol_rootP
));
1444 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1446 static void obj_coff_lcomm
PARAMS ((int));
1447 static void obj_coff_text
PARAMS ((int));
1448 static void obj_coff_data
PARAMS ((int));
1449 static void obj_coff_ident
PARAMS ((int));
1450 void obj_coff_section
PARAMS ((int));
1454 We allow more than just the standard 3 sections, infact, we allow
1455 40 sections, (though the usual three have to be there).
1457 This structure performs the mappings for us:
1467 static const seg_info_type seg_info_off_by_4
[] =
1474 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1475 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1476 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1477 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1478 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1479 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1480 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1481 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1496 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1498 static relax_addressT
1499 relax_align (address
, alignment
)
1500 relax_addressT address
;
1503 relax_addressT mask
;
1504 relax_addressT new_address
;
1506 mask
= ~((~0) << alignment
);
1507 new_address
= (address
+ mask
) & (~mask
);
1508 return (new_address
- address
);
1516 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1519 /* calculate the size of the frag chain and fill in the section header
1520 to contain all of it, also fill in the addr of the sections */
1522 size_section (abfd
, idx
)
1527 unsigned int size
= 0;
1528 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1531 size
= frag
->fr_address
;
1532 if (frag
->fr_address
!= size
)
1534 fprintf (stderr
, _("Out of step\n"));
1535 size
= frag
->fr_address
;
1538 switch (frag
->fr_type
)
1540 #ifdef TC_COFF_SIZEMACHDEP
1541 case rs_machine_dependent
:
1542 size
+= TC_COFF_SIZEMACHDEP (frag
);
1546 assert (frag
->fr_symbol
== 0);
1549 size
+= frag
->fr_fix
;
1550 size
+= frag
->fr_offset
* frag
->fr_var
;
1557 size
+= frag
->fr_fix
;
1558 off
= relax_align (size
, frag
->fr_offset
);
1559 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1565 BAD_CASE (frag
->fr_type
);
1568 frag
= frag
->fr_next
;
1570 segment_info
[idx
].scnhdr
.s_size
= size
;
1576 count_entries_in_chain (idx
)
1579 unsigned int nrelocs
;
1582 /* Count the relocations */
1583 fixup_ptr
= segment_info
[idx
].fix_root
;
1585 while (fixup_ptr
!= (fixS
*) NULL
)
1587 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1590 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1599 fixup_ptr
= fixup_ptr
->fx_next
;
1606 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1608 /* AUX's ld expects relocations to be sorted */
1610 compare_external_relocs (x
, y
)
1614 struct external_reloc
*a
= (struct external_reloc
*) x
;
1615 struct external_reloc
*b
= (struct external_reloc
*) y
;
1616 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1617 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1618 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1623 /* output all the relocations for a section */
1625 do_relocs_for (abfd
, h
, file_cursor
)
1628 unsigned long *file_cursor
;
1630 unsigned int nrelocs
;
1632 unsigned long reloc_start
= *file_cursor
;
1634 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1636 if (segment_info
[idx
].scnhdr
.s_name
[0])
1638 struct external_reloc
*ext_ptr
;
1639 struct external_reloc
*external_reloc_vec
;
1640 unsigned int external_reloc_size
;
1641 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1642 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1643 nrelocs
= count_entries_in_chain (idx
);
1646 /* Bypass this stuff if no relocs. This also incidentally
1647 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1649 external_reloc_size
= nrelocs
* RELSZ
;
1650 external_reloc_vec
=
1651 (struct external_reloc
*) malloc (external_reloc_size
);
1653 ext_ptr
= external_reloc_vec
;
1655 /* Fill in the internal coff style reloc struct from the
1656 internal fix list. */
1659 struct internal_reloc intr
;
1661 /* Only output some of the relocations */
1662 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1664 #ifdef TC_RELOC_MANGLE
1665 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1670 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1672 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1674 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1676 #ifdef TC_KEEP_FX_OFFSET
1677 intr
.r_offset
= fix_ptr
->fx_offset
;
1682 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1683 && (! S_IS_DEFINED (symbol_ptr
)
1684 || S_IS_COMMON (symbol_ptr
)))
1688 /* We must avoid looping, as that can occur
1689 with a badly written program. */
1690 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1691 if (n
== symbol_ptr
)
1696 /* Turn the segment of the symbol into an offset. */
1699 resolve_symbol_value (symbol_ptr
, 1);
1700 if (! symbol_ptr
->sy_resolved
)
1705 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1706 as_bad_where (file
, line
,
1707 _("unresolved relocation"));
1709 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1710 S_GET_NAME (symbol_ptr
));
1712 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1715 intr
.r_symndx
= dot
->sy_number
;
1719 intr
.r_symndx
= symbol_ptr
->sy_number
;
1729 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1732 #if defined(TC_A29K)
1734 /* The 29k has a special kludge for the high 16 bit
1735 reloc. Two relocations are emited, R_IHIHALF,
1736 and R_IHCONST. The second one doesn't contain a
1737 symbol, but uses the value for offset. */
1739 if (intr
.r_type
== R_IHIHALF
)
1741 /* now emit the second bit */
1742 intr
.r_type
= R_IHCONST
;
1743 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1744 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1750 fix_ptr
= fix_ptr
->fx_next
;
1754 /* Sort the reloc table */
1755 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1756 sizeof (struct external_reloc
), compare_external_relocs
);
1759 /* Write out the reloc table */
1760 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1762 free (external_reloc_vec
);
1764 /* Fill in section header info. */
1765 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1766 *file_cursor
+= external_reloc_size
;
1767 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1772 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1776 /* Set relocation_size field in file headers */
1777 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1781 /* run through a frag chain and write out the data to go with it, fill
1782 in the scnhdrs with the info on the file postions
1785 fill_section (abfd
, h
, file_cursor
)
1788 unsigned long *file_cursor
;
1792 unsigned int paddr
= 0;
1794 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1796 unsigned int offset
= 0;
1797 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1803 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1810 buffer
= xmalloc (s
->s_size
);
1811 s
->s_scnptr
= *file_cursor
;
1813 know (s
->s_paddr
== paddr
);
1815 if (strcmp (s
->s_name
, ".text") == 0)
1816 s
->s_flags
|= STYP_TEXT
;
1817 else if (strcmp (s
->s_name
, ".data") == 0)
1818 s
->s_flags
|= STYP_DATA
;
1819 else if (strcmp (s
->s_name
, ".bss") == 0)
1822 s
->s_flags
|= STYP_BSS
;
1824 /* @@ Should make the i386 and a29k coff targets define
1825 COFF_NOLOAD_PROBLEM, and have only one test here. */
1828 #ifndef COFF_NOLOAD_PROBLEM
1829 /* Apparently the SVR3 linker (and exec syscall) and UDI
1830 mondfe progrem are confused by noload sections. */
1831 s
->s_flags
|= STYP_NOLOAD
;
1836 else if (strcmp (s
->s_name
, ".lit") == 0)
1837 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1838 else if (strcmp (s
->s_name
, ".init") == 0)
1839 s
->s_flags
|= STYP_TEXT
;
1840 else if (strcmp (s
->s_name
, ".fini") == 0)
1841 s
->s_flags
|= STYP_TEXT
;
1842 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1843 s
->s_flags
|= STYP_INFO
;
1847 unsigned int fill_size
;
1848 switch (frag
->fr_type
)
1850 case rs_machine_dependent
:
1853 memcpy (buffer
+ frag
->fr_address
,
1855 (unsigned int) frag
->fr_fix
);
1856 offset
+= frag
->fr_fix
;
1861 assert (frag
->fr_symbol
== 0);
1868 memcpy (buffer
+ frag
->fr_address
,
1870 (unsigned int) frag
->fr_fix
);
1871 offset
+= frag
->fr_fix
;
1874 fill_size
= frag
->fr_var
;
1875 if (fill_size
&& frag
->fr_offset
> 0)
1878 unsigned int off
= frag
->fr_fix
;
1879 for (count
= frag
->fr_offset
; count
; count
--)
1881 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1883 memcpy (buffer
+ frag
->fr_address
+ off
,
1884 frag
->fr_literal
+ frag
->fr_fix
,
1887 offset
+= fill_size
;
1892 case rs_broken_word
:
1897 frag
= frag
->fr_next
;
1902 if (s
->s_scnptr
!= 0)
1904 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1905 *file_cursor
+= s
->s_size
;
1914 /* Coff file generation & utilities */
1917 coff_header_append (abfd
, h
)
1924 #ifdef COFF_LONG_SECTION_NAMES
1925 unsigned long string_size
= 4;
1928 bfd_seek (abfd
, 0, 0);
1930 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1931 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1932 H_SET_VERSION_STAMP (h
, 0);
1933 H_SET_ENTRY_POINT (h
, 0);
1934 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1935 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1936 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1938 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1939 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1940 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1942 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1944 bfd_write (buffer
, i
, 1, abfd
);
1945 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1947 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1949 if (segment_info
[i
].scnhdr
.s_name
[0])
1953 #ifdef COFF_LONG_SECTION_NAMES
1954 /* Support long section names as found in PE. This code
1955 must coordinate with that in write_object_file and
1957 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1959 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1960 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1961 string_size
+= strlen (segment_info
[i
].name
) + 1;
1965 size
= bfd_coff_swap_scnhdr_out (abfd
,
1966 &(segment_info
[i
].scnhdr
),
1969 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
1970 bfd_write (buffer
, size
, 1, abfd
);
1977 symbol_to_chars (abfd
, where
, symbolP
)
1982 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1986 /* Turn any symbols with register attributes into abs symbols */
1987 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1989 S_SET_SEGMENT (symbolP
, absolute_section
);
1991 /* At the same time, relocate all symbols to their output value */
1994 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1995 + S_GET_VALUE (symbolP
));
1997 val
= S_GET_VALUE (symbolP
);
2000 S_SET_VALUE (symbolP
, val
);
2002 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2004 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2007 for (i
= 0; i
< numaux
; i
++)
2009 where
+= bfd_coff_swap_aux_out (abfd
,
2010 &symbolP
->sy_symbol
.ost_auxent
[i
],
2011 S_GET_DATA_TYPE (symbolP
),
2012 S_GET_STORAGE_CLASS (symbolP
),
2020 coff_obj_symbol_new_hook (symbolP
)
2023 char underscore
= 0; /* Symbol has leading _ */
2025 /* Effective symbol */
2026 /* Store the pointer in the offset. */
2027 S_SET_ZEROES (symbolP
, 0L);
2028 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2029 S_SET_STORAGE_CLASS (symbolP
, 0);
2030 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2031 /* Additional information */
2032 symbolP
->sy_symbol
.ost_flags
= 0;
2033 /* Auxiliary entries */
2034 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2036 if (S_IS_STRING (symbolP
))
2037 SF_SET_STRING (symbolP
);
2038 if (!underscore
&& S_IS_LOCAL (symbolP
))
2039 SF_SET_LOCAL (symbolP
);
2043 * Handle .ln directives.
2047 obj_coff_ln (appline
)
2052 if (! appline
&& def_symbol_in_progress
!= NULL
)
2054 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2055 demand_empty_rest_of_line ();
2057 } /* wrong context */
2059 l
= get_absolute_expression ();
2060 c_line_new (0, frag_now_fix (), l
, frag_now
);
2063 new_logical_line ((char *) NULL
, l
- 1);
2073 listing_source_line ((unsigned int) l
);
2078 demand_empty_rest_of_line ();
2084 * Handle .def directives.
2086 * One might ask : why can't we symbol_new if the symbol does not
2087 * already exist and fill it with debug information. Because of
2088 * the C_EFCN special symbol. It would clobber the value of the
2089 * function symbol before we have a chance to notice that it is
2090 * a C_EFCN. And a second reason is that the code is more clear this
2091 * way. (at least I think it is :-).
2095 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2096 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2097 *input_line_pointer == '\t') \
2098 input_line_pointer++;
2104 char name_end
; /* Char after the end of name */
2105 char *symbol_name
; /* Name of the debug symbol */
2106 char *symbol_name_copy
; /* Temporary copy of the name */
2107 unsigned int symbol_name_length
;
2109 if (def_symbol_in_progress
!= NULL
)
2111 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2112 demand_empty_rest_of_line ();
2114 } /* if not inside .def/.endef */
2116 SKIP_WHITESPACES ();
2118 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2119 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2121 symbol_name
= input_line_pointer
;
2122 name_end
= get_symbol_end ();
2123 symbol_name_length
= strlen (symbol_name
);
2124 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2125 strcpy (symbol_name_copy
, symbol_name
);
2126 #ifdef tc_canonicalize_symbol_name
2127 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2130 /* Initialize the new symbol */
2131 #ifdef STRIP_UNDERSCORE
2132 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2133 ? symbol_name_copy
+ 1
2134 : symbol_name_copy
));
2135 #else /* STRIP_UNDERSCORE */
2136 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2137 #endif /* STRIP_UNDERSCORE */
2138 /* free(symbol_name_copy); */
2139 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2140 def_symbol_in_progress
->sy_number
= ~0;
2141 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2142 S_SET_VALUE (def_symbol_in_progress
, 0);
2144 if (S_IS_STRING (def_symbol_in_progress
))
2145 SF_SET_STRING (def_symbol_in_progress
);
2147 *input_line_pointer
= name_end
;
2149 demand_empty_rest_of_line ();
2152 unsigned int dim_index
;
2156 obj_coff_endef (ignore
)
2159 symbolS
*symbolP
= 0;
2160 /* DIM BUG FIX sac@cygnus.com */
2162 if (def_symbol_in_progress
== NULL
)
2164 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2165 demand_empty_rest_of_line ();
2167 } /* if not inside .def/.endef */
2169 /* Set the section number according to storage class. */
2170 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2175 SF_SET_TAG (def_symbol_in_progress
);
2176 /* intentional fallthrough */
2179 SF_SET_DEBUG (def_symbol_in_progress
);
2180 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2184 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2185 /* intentional fallthrough */
2187 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2188 /* intentional fallthrough */
2190 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2192 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2194 if (function_lineoff
< 0)
2196 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2197 } /* missing function symbol */
2198 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2200 SF_SET_PROCESS (last_line_symbol
);
2201 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2202 SF_SET_PROCESS (def_symbol_in_progress
);
2203 function_lineoff
= -1;
2205 /* Value is always set to . */
2206 def_symbol_in_progress
->sy_frag
= frag_now
;
2207 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2212 #endif /* C_AUTOARG */
2222 SF_SET_DEBUG (def_symbol_in_progress
);
2223 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2229 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2235 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2237 } /* switch on storage class */
2239 /* Now that we have built a debug symbol, try to find if we should
2240 merge with an existing symbol or not. If a symbol is C_EFCN or
2241 absolute_section or untagged SEG_DEBUG it never merges. We also
2242 don't merge labels, which are in a different namespace, nor
2243 symbols which have not yet been defined since they are typically
2244 unique, nor do we merge tags with non-tags. */
2246 /* Two cases for functions. Either debug followed by definition or
2247 definition followed by debug. For definition first, we will
2248 merge the debug symbol into the definition. For debug first, the
2249 lineno entry MUST point to the definition function or else it
2250 will point off into space when crawl_symbols() merges the debug
2251 symbol into the real symbol. Therefor, let's presume the debug
2252 symbol is a real function reference. */
2254 /* FIXME-SOON If for some reason the definition label/symbol is
2255 never seen, this will probably leave an undefined symbol at link
2258 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2259 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2260 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2261 && !SF_GET_TAG (def_symbol_in_progress
))
2262 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2263 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2264 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2265 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2267 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2272 /* This symbol already exists, merge the newly created symbol
2273 into the old one. This is not mandatory. The linker can
2274 handle duplicate symbols correctly. But I guess that it save
2275 a *lot* of space if the assembly file defines a lot of
2278 /* The debug entry (def_symbol_in_progress) is merged into the
2279 previous definition. */
2281 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2282 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2283 def_symbol_in_progress
= symbolP
;
2285 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2286 || SF_GET_TAG (def_symbol_in_progress
)
2287 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2289 /* For functions, and tags, and static symbols, the symbol
2290 *must* be where the debug symbol appears. Move the
2291 existing symbol to the current place. */
2292 /* If it already is at the end of the symbol list, do nothing */
2293 if (def_symbol_in_progress
!= symbol_lastP
)
2295 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2297 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2298 &symbol_rootP
, &symbol_lastP
);
2299 } /* if not already in place */
2301 } /* normal or mergable */
2303 if (SF_GET_TAG (def_symbol_in_progress
))
2307 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2309 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2310 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2311 def_symbol_in_progress
);
2314 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2316 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2318 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2320 SF_SET_PROCESS (def_symbol_in_progress
);
2322 if (symbolP
== NULL
)
2324 /* That is, if this is the first time we've seen the
2326 symbol_table_insert (def_symbol_in_progress
);
2327 } /* definition follows debug */
2328 } /* Create the line number entry pointing to the function being defined */
2330 def_symbol_in_progress
= NULL
;
2331 demand_empty_rest_of_line ();
2335 obj_coff_dim (ignore
)
2340 if (def_symbol_in_progress
== NULL
)
2342 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2343 demand_empty_rest_of_line ();
2345 } /* if not inside .def/.endef */
2347 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2349 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2351 SKIP_WHITESPACES ();
2352 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2353 get_absolute_expression ());
2355 switch (*input_line_pointer
)
2358 input_line_pointer
++;
2362 as_warn (_("badly formed .dim directive ignored"));
2363 /* intentional fallthrough */
2371 demand_empty_rest_of_line ();
2375 obj_coff_line (ignore
)
2381 if (def_symbol_in_progress
== NULL
)
2387 name
= S_GET_NAME (def_symbol_in_progress
);
2388 this_base
= get_absolute_expression ();
2390 /* Only .bf symbols indicate the use of a new base line number; the
2391 line numbers associated with .ef, .bb, .eb are relative to the
2392 start of the containing function. */
2393 if (!strcmp (".bf", name
))
2395 #if 0 /* XXX Can we ever have line numbers going backwards? */
2396 if (this_base
> line_base
)
2399 line_base
= this_base
;
2407 listing_source_line ((unsigned int) line_base
);
2413 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2414 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2416 demand_empty_rest_of_line ();
2420 obj_coff_size (ignore
)
2423 if (def_symbol_in_progress
== NULL
)
2425 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2426 demand_empty_rest_of_line ();
2428 } /* if not inside .def/.endef */
2430 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2431 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2432 demand_empty_rest_of_line ();
2436 obj_coff_scl (ignore
)
2439 if (def_symbol_in_progress
== NULL
)
2441 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2442 demand_empty_rest_of_line ();
2444 } /* if not inside .def/.endef */
2446 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2447 demand_empty_rest_of_line ();
2451 obj_coff_tag (ignore
)
2457 if (def_symbol_in_progress
== NULL
)
2459 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2460 demand_empty_rest_of_line ();
2464 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2465 symbol_name
= input_line_pointer
;
2466 name_end
= get_symbol_end ();
2467 #ifdef tc_canonicalize_symbol_name
2468 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2471 /* Assume that the symbol referred to by .tag is always defined.
2472 This was a bad assumption. I've added find_or_make. xoxorich. */
2473 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2474 (long) tag_find_or_make (symbol_name
));
2475 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2477 as_warn (_("tag not found for .tag %s"), symbol_name
);
2480 SF_SET_TAGGED (def_symbol_in_progress
);
2481 *input_line_pointer
= name_end
;
2483 demand_empty_rest_of_line ();
2487 obj_coff_type (ignore
)
2490 if (def_symbol_in_progress
== NULL
)
2492 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2493 demand_empty_rest_of_line ();
2495 } /* if not inside .def/.endef */
2497 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2499 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2500 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2502 SF_SET_FUNCTION (def_symbol_in_progress
);
2503 } /* is a function */
2505 demand_empty_rest_of_line ();
2509 obj_coff_val (ignore
)
2512 if (def_symbol_in_progress
== NULL
)
2514 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2515 demand_empty_rest_of_line ();
2517 } /* if not inside .def/.endef */
2519 if (is_name_beginner (*input_line_pointer
))
2521 char *symbol_name
= input_line_pointer
;
2522 char name_end
= get_symbol_end ();
2524 #ifdef tc_canonicalize_symbol_name
2525 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2528 if (!strcmp (symbol_name
, "."))
2530 def_symbol_in_progress
->sy_frag
= frag_now
;
2531 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2532 /* If the .val is != from the .def (e.g. statics) */
2534 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2536 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2537 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2538 symbol_find_or_make (symbol_name
);
2539 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2540 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2542 /* If the segment is undefined when the forward reference is
2543 resolved, then copy the segment id from the forward
2545 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2547 /* FIXME: gcc can generate address expressions
2548 here in unusual cases (search for "obscure"
2549 in sdbout.c). We just ignore the offset
2550 here, thus generating incorrect debugging
2551 information. We ignore the rest of the
2554 /* Otherwise, it is the name of a non debug symbol and
2555 its value will be calculated later. */
2556 *input_line_pointer
= name_end
;
2558 /* FIXME: this is to avoid an error message in the
2559 FIXME case mentioned just above. */
2560 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2561 ++input_line_pointer
;
2565 S_SET_VALUE (def_symbol_in_progress
,
2566 (valueT
) get_absolute_expression ());
2567 } /* if symbol based */
2569 demand_empty_rest_of_line ();
2574 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2575 read.c, which then calls this object file format specific routine. */
2578 obj_coff_pe_handle_link_once (type
)
2579 enum linkonce_type type
;
2581 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2583 /* We store the type in the seg_info structure, and use it to set up
2584 the auxiliary entry for the section symbol in c_section_symbol. */
2585 seg_info (now_seg
)->linkonce
= type
;
2591 coff_obj_read_begin_hook ()
2593 /* These had better be the same. Usually 18 bytes. */
2595 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2596 know (SYMESZ
== AUXESZ
);
2601 /* This function runs through the symbol table and puts all the
2602 externals onto another chain */
2604 /* The chain of globals. */
2605 symbolS
*symbol_globalP
;
2606 symbolS
*symbol_global_lastP
;
2608 /* The chain of externals */
2609 symbolS
*symbol_externP
;
2610 symbolS
*symbol_extern_lastP
;
2613 symbolS
*last_functionP
;
2614 static symbolS
*last_bfP
;
2621 unsigned int symbol_number
= 0;
2622 unsigned int last_file_symno
= 0;
2624 struct filename_list
*filename_list_scan
= filename_list_head
;
2626 for (symbolP
= symbol_rootP
;
2628 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2630 if (symbolP
->sy_mri_common
)
2632 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2633 as_bad (_("%s: global symbols not supported in common sections"),
2634 S_GET_NAME (symbolP
));
2635 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2639 if (!SF_GET_DEBUG (symbolP
))
2641 /* Debug symbols do not need all this rubbish */
2642 symbolS
*real_symbolP
;
2644 /* L* and C_EFCN symbols never merge. */
2645 if (!SF_GET_LOCAL (symbolP
)
2646 && !SF_GET_STATICS (symbolP
)
2647 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2648 && symbolP
->sy_value
.X_op
== O_constant
2649 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2650 && real_symbolP
!= symbolP
)
2652 /* FIXME-SOON: where do dups come from?
2653 Maybe tag references before definitions? xoxorich. */
2654 /* Move the debug data from the debug symbol to the
2655 real symbol. Do NOT do the oposite (i.e. move from
2656 real symbol to debug symbol and remove real symbol from the
2657 list.) Because some pointers refer to the real symbol
2658 whereas no pointers refer to the debug symbol. */
2659 c_symbol_merge (symbolP
, real_symbolP
);
2660 /* Replace the current symbol by the real one */
2661 /* The symbols will never be the last or the first
2662 because : 1st symbol is .file and 3 last symbols are
2663 .text, .data, .bss */
2664 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2665 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2666 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2667 symbolP
= real_symbolP
;
2668 } /* if not local but dup'd */
2670 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2672 S_SET_SEGMENT (symbolP
, SEG_E0
);
2673 } /* push data into text */
2675 resolve_symbol_value (symbolP
, 1);
2677 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2679 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2681 S_SET_EXTERNAL (symbolP
);
2683 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2685 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2689 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2693 /* Mainly to speed up if not -g */
2694 if (SF_GET_PROCESS (symbolP
))
2696 /* Handle the nested blocks auxiliary info. */
2697 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2699 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2700 stack_push (block_stack
, (char *) &symbolP
);
2703 register symbolS
*begin_symbolP
;
2704 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2705 if (begin_symbolP
== (symbolS
*) 0)
2706 as_warn (_("mismatched .eb"));
2708 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2711 /* If we are able to identify the type of a function, and we
2712 are out of a function (last_functionP == 0) then, the
2713 function symbol will be associated with an auxiliary
2715 if (last_functionP
== (symbolS
*) 0 &&
2716 SF_GET_FUNCTION (symbolP
))
2718 last_functionP
= symbolP
;
2720 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2722 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2723 } /* make it at least 1 */
2725 /* Clobber possible stale .dim information. */
2727 /* Iffed out by steve - this fries the lnnoptr info too */
2728 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2729 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2732 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2734 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2736 if (last_bfP
!= NULL
)
2737 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2741 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2743 /* I don't even know if this is needed for sdb. But
2744 the standard assembler generates it, so... */
2745 if (last_functionP
== (symbolS
*) 0)
2746 as_fatal (_("C_EFCN symbol out of scope"));
2747 SA_SET_SYM_FSIZE (last_functionP
,
2748 (long) (S_GET_VALUE (symbolP
) -
2749 S_GET_VALUE (last_functionP
)));
2750 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2751 last_functionP
= (symbolS
*) 0;
2755 else if (SF_GET_TAG (symbolP
))
2757 /* First descriptor of a structure must point to
2758 the first slot after the structure description. */
2759 last_tagP
= symbolP
;
2762 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2764 /* +2 take in account the current symbol */
2765 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2767 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2769 /* If the filename was too long to fit in the
2770 auxent, put it in the string table */
2771 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2772 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2774 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2775 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2776 filename_list_scan
= filename_list_scan
->next
;
2778 if (S_GET_VALUE (symbolP
))
2780 S_SET_VALUE (symbolP
, last_file_symno
);
2781 last_file_symno
= symbol_number
;
2782 } /* no one points at the first .file symbol */
2783 } /* if debug or tag or eos or file */
2785 #ifdef tc_frob_coff_symbol
2786 tc_frob_coff_symbol (symbolP
);
2789 /* We must put the external symbols apart. The loader
2790 does not bomb if we do not. But the references in
2791 the endndx field for a .bb symbol are not corrected
2792 if an external symbol is removed between .bb and .be.
2793 I.e in the following case :
2794 [20] .bb endndx = 22
2797 ld will move the symbol 21 to the end of the list but
2798 endndx will still be 22 instead of 21. */
2801 if (SF_GET_LOCAL (symbolP
))
2803 /* remove C_EFCN and LOCAL (L...) symbols */
2804 /* next pointer remains valid */
2805 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2808 else if (symbolP
->sy_value
.X_op
== O_symbol
2809 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2811 /* Skip symbols which were equated to undefined or common
2813 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2815 else if (!S_IS_DEFINED (symbolP
)
2816 && !S_IS_DEBUG (symbolP
)
2817 && !SF_GET_STATICS (symbolP
) &&
2818 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2819 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2820 /* if external, Remove from the list */
2821 symbolS
*hold
= symbol_previous (symbolP
);
2823 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2824 symbol_clear_list_pointers (symbolP
);
2825 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2828 else if (! S_IS_DEBUG (symbolP
)
2829 && ! SF_GET_STATICS (symbolP
)
2830 && ! SF_GET_FUNCTION (symbolP
)
2831 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2833 symbolS
*hold
= symbol_previous (symbolP
);
2835 /* The O'Reilly COFF book says that defined global symbols
2836 come at the end of the symbol table, just before
2837 undefined global symbols. */
2839 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2840 symbol_clear_list_pointers (symbolP
);
2841 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2842 &symbol_global_lastP
);
2847 if (SF_GET_STRING (symbolP
))
2849 symbolP
->sy_name_offset
= string_byte_count
;
2850 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2854 symbolP
->sy_name_offset
= 0;
2855 } /* fix "long" names */
2857 symbolP
->sy_number
= symbol_number
;
2858 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2859 } /* if local symbol */
2860 } /* traverse the symbol list */
2861 return symbol_number
;
2867 glue_symbols (head
, tail
)
2871 unsigned int symbol_number
= 0;
2873 while (*head
!= NULL
)
2875 symbolS
*tmp
= *head
;
2878 symbol_remove (tmp
, head
, tail
);
2879 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2882 if (SF_GET_STRING (tmp
))
2884 tmp
->sy_name_offset
= string_byte_count
;
2885 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2889 tmp
->sy_name_offset
= 0;
2890 } /* fix "long" names */
2892 tmp
->sy_number
= symbol_number
;
2893 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2894 } /* append the entire extern chain */
2896 return symbol_number
;
2902 unsigned int symbol_number
= 0;
2905 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2907 symbolP
->sy_number
= symbol_number
;
2909 if (SF_GET_TAGGED (symbolP
))
2913 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2916 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2919 return symbol_number
;
2923 crawl_symbols (h
, abfd
)
2929 /* Initialize the stack used to keep track of the matching .bb .be */
2931 block_stack
= stack_init (512, sizeof (symbolS
*));
2933 /* The symbol list should be ordered according to the following sequence
2936 * . debug entries for functions
2937 * . fake symbols for the sections, including .text .data and .bss
2939 * . undefined symbols
2940 * But this is not mandatory. The only important point is to put the
2941 * undefined symbols at the end of the list.
2944 /* Is there a .file symbol ? If not insert one at the beginning. */
2945 if (symbol_rootP
== NULL
2946 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2948 c_dot_file_symbol ("fake");
2952 * Build up static symbols for the sections, they are filled in later
2956 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2957 if (segment_info
[i
].scnhdr
.s_name
[0])
2958 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2961 /* Take all the externals out and put them into another chain */
2962 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2963 /* Take the externals and glue them onto the end.*/
2964 H_SET_SYMBOL_TABLE_SIZE (h
,
2965 (H_GET_SYMBOL_COUNT (h
)
2966 + glue_symbols (&symbol_globalP
,
2967 &symbol_global_lastP
)
2968 + glue_symbols (&symbol_externP
,
2969 &symbol_extern_lastP
)));
2971 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2972 know (symbol_globalP
== NULL
);
2973 know (symbol_global_lastP
== NULL
);
2974 know (symbol_externP
== NULL
);
2975 know (symbol_extern_lastP
== NULL
);
2979 * Find strings by crawling along symbol table chain.
2987 struct filename_list
*filename_list_scan
= filename_list_head
;
2989 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2990 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2993 #ifdef COFF_LONG_SECTION_NAMES
2994 /* Support long section names as found in PE. This code must
2995 coordinate with that in coff_header_append and write_object_file. */
2999 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3001 if (segment_info
[i
].scnhdr
.s_name
[0]
3002 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3006 size
= strlen (segment_info
[i
].name
) + 1;
3007 memcpy (where
, segment_info
[i
].name
, size
);
3012 #endif /* COFF_LONG_SECTION_NAMES */
3014 for (symbolP
= symbol_rootP
;
3016 symbolP
= symbol_next (symbolP
))
3020 if (SF_GET_STRING (symbolP
))
3022 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3023 memcpy (where
, S_GET_NAME (symbolP
), size
);
3026 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3027 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3028 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3030 size
= strlen (filename_list_scan
->filename
) + 1;
3031 memcpy (where
, filename_list_scan
->filename
, size
);
3032 filename_list_scan
= filename_list_scan
->next
;
3039 do_linenos_for (abfd
, h
, file_cursor
)
3042 unsigned long *file_cursor
;
3045 unsigned long start
= *file_cursor
;
3047 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3049 segment_info_type
*s
= segment_info
+ idx
;
3052 if (s
->scnhdr
.s_nlnno
!= 0)
3054 struct lineno_list
*line_ptr
;
3056 struct external_lineno
*buffer
=
3057 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3059 struct external_lineno
*dst
= buffer
;
3061 /* Run through the table we've built and turn it into its external
3062 form, take this chance to remove duplicates */
3064 for (line_ptr
= s
->lineno_list_head
;
3065 line_ptr
!= (struct lineno_list
*) NULL
;
3066 line_ptr
= line_ptr
->next
)
3069 if (line_ptr
->line
.l_lnno
== 0)
3071 /* Turn a pointer to a symbol into the symbols' index */
3072 line_ptr
->line
.l_addr
.l_symndx
=
3073 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3077 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3081 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3086 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3088 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3091 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3094 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3098 /* Now we run through the list of frag chains in a segment and
3099 make all the subsegment frags appear at the end of the
3100 list, as if the seg 0 was extra long */
3107 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3109 frchainS
*head
= segment_info
[i
].frchainP
;
3111 fragS
*prev_frag
= &dummy
;
3113 while (head
&& head
->frch_seg
== i
)
3115 prev_frag
->fr_next
= head
->frch_root
;
3116 prev_frag
= head
->frch_last
;
3117 head
= head
->frch_next
;
3119 prev_frag
->fr_next
= 0;
3123 unsigned long machine
;
3126 write_object_file ()
3130 struct frchain
*frchain_ptr
;
3132 object_headers headers
;
3133 unsigned long file_cursor
;
3136 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3141 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3142 exit (EXIT_FAILURE
);
3144 bfd_set_format (abfd
, bfd_object
);
3145 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3147 string_byte_count
= 4;
3149 for (frchain_ptr
= frchain_root
;
3150 frchain_ptr
!= (struct frchain
*) NULL
;
3151 frchain_ptr
= frchain_ptr
->frch_next
)
3153 /* Run through all the sub-segments and align them up. Also
3154 close any open frags. We tack a .fill onto the end of the
3155 frag chain so that any .align's size can be worked by looking
3156 at the next frag. */
3158 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3159 #ifndef SUB_SEGMENT_ALIGN
3160 #define SUB_SEGMENT_ALIGN(SEG) 1
3163 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3166 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3170 frag_wane (frag_now
);
3171 frag_now
->fr_fix
= 0;
3172 know (frag_now
->fr_next
== NULL
);
3179 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3181 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3184 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3186 /* Find out how big the sections are, and set the addresses. */
3188 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3192 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3193 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3195 if (segment_info
[i
].scnhdr
.s_name
[0])
3197 H_SET_NUMBER_OF_SECTIONS (&headers
,
3198 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3200 #ifdef COFF_LONG_SECTION_NAMES
3201 /* Support long section names as found in PE. This code
3202 must coordinate with that in coff_header_append and
3207 len
= strlen (segment_info
[i
].name
);
3209 string_byte_count
+= len
+ 1;
3211 #endif /* COFF_LONG_SECTION_NAMES */
3214 size
= size_section (abfd
, (unsigned int) i
);
3217 /* I think the section alignment is only used on the i960; the
3218 i960 needs it, and it should do no harm on other targets. */
3219 #ifdef ALIGNMENT_IN_S_FLAGS
3220 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3222 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3226 H_SET_TEXT_SIZE (&headers
, size
);
3227 else if (i
== SEG_E1
)
3228 H_SET_DATA_SIZE (&headers
, size
);
3229 else if (i
== SEG_E2
)
3230 H_SET_BSS_SIZE (&headers
, size
);
3233 /* Turn the gas native symbol table shape into a coff symbol table */
3234 crawl_symbols (&headers
, abfd
);
3236 if (string_byte_count
== 4)
3237 string_byte_count
= 0;
3239 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3245 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3247 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3248 fixup_segment (&segment_info
[i
], i
);
3251 /* Look for ".stab" segments and fill in their initial symbols
3253 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3255 name
= segment_info
[i
].name
;
3258 && strncmp (".stab", name
, 5) == 0
3259 && strncmp (".stabstr", name
, 8) != 0)
3260 adjust_stab_section (abfd
, i
);
3263 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3265 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3267 /* Plant the data */
3269 fill_section (abfd
, &headers
, &file_cursor
);
3271 do_relocs_for (abfd
, &headers
, &file_cursor
);
3273 do_linenos_for (abfd
, &headers
, &file_cursor
);
3275 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3276 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3277 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3279 H_SET_TIME_STAMP (&headers
, 0);
3281 #ifdef TC_COFF_SET_MACHINE
3282 TC_COFF_SET_MACHINE (&headers
);
3286 #define COFF_FLAGS 0
3289 #ifdef KEEP_RELOC_INFO
3290 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3291 COFF_FLAGS
| coff_flags
));
3293 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3294 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3295 COFF_FLAGS
| coff_flags
));
3299 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3300 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3302 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3303 w_symbols (abfd
, buffer1
, symbol_rootP
);
3304 if (string_byte_count
> 0)
3305 w_strings (buffer1
+ symtable_size
);
3306 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3310 coff_header_append (abfd
, &headers
);
3312 /* Recent changes to write need this, but where it should
3313 go is up to Ken.. */
3314 if (bfd_close_all_done (abfd
) == false)
3315 as_fatal (_("Can't close %s: %s"), out_file_name
,
3316 bfd_errmsg (bfd_get_error ()));
3319 extern bfd
*stdoutput
;
3326 /* Add a new segment. This is called from subseg_new via the
3327 obj_new_segment macro. */
3330 obj_coff_add_segment (name
)
3335 #ifndef COFF_LONG_SECTION_NAMES
3336 char buf
[SCNNMLEN
+ 1];
3338 strncpy (buf
, name
, SCNNMLEN
);
3339 buf
[SCNNMLEN
] = '\0';
3343 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3344 if (strcmp (name
, segment_info
[i
].name
) == 0)
3349 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3353 /* Add a new section. */
3354 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3355 sizeof (segment_info
[i
].scnhdr
.s_name
));
3356 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3357 segment_info
[i
].name
= xstrdup (name
);
3363 * implement the .section pseudo op:
3364 * .section name {, "flags"}
3366 * | +--- optional flags: 'b' for bss
3368 * +-- section name 'l' for lib
3372 * 'd' (apparently m88k for data)
3374 * 'r' for read-only data
3375 * But if the argument is not a quoted string, treat it as a
3376 * subsegment number.
3380 obj_coff_section (ignore
)
3383 /* Strip out the section name */
3384 char *section_name
, *name
;
3397 else if (type
== 'D')
3399 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3404 section_name
= input_line_pointer
;
3405 c
= get_symbol_end ();
3407 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3408 strcpy (name
, section_name
);
3410 *input_line_pointer
= c
;
3416 if (*input_line_pointer
== ',')
3418 ++input_line_pointer
;
3421 if (*input_line_pointer
!= '"')
3422 exp
= get_absolute_expression ();
3425 ++input_line_pointer
;
3426 while (*input_line_pointer
!= '"'
3427 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3429 switch (*input_line_pointer
)
3431 case 'b': flags
|= STYP_BSS
; break;
3432 case 'i': flags
|= STYP_INFO
; break;
3433 case 'l': flags
|= STYP_LIB
; break;
3434 case 'n': flags
|= STYP_NOLOAD
; break;
3435 case 'o': flags
|= STYP_OVER
; break;
3437 case 'w': flags
|= STYP_DATA
; break;
3438 case 'x': flags
|= STYP_TEXT
; break;
3439 case 'r': flags
|= STYP_LIT
; break;
3441 as_warn(_("unknown section attribute '%c'"),
3442 *input_line_pointer
);
3445 ++input_line_pointer
;
3447 if (*input_line_pointer
== '"')
3448 ++input_line_pointer
;
3452 subseg_new (name
, (subsegT
) exp
);
3454 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3456 demand_empty_rest_of_line ();
3461 obj_coff_text (ignore
)
3464 subseg_new (".text", get_absolute_expression ());
3469 obj_coff_data (ignore
)
3472 if (flag_readonly_data_in_text
)
3473 subseg_new (".text", get_absolute_expression () + 1000);
3475 subseg_new (".data", get_absolute_expression ());
3479 obj_coff_ident (ignore
)
3482 segT current_seg
= now_seg
; /* save current seg */
3483 subsegT current_subseg
= now_subseg
;
3484 subseg_new (".comment", 0); /* .comment seg */
3485 stringer (1); /* read string */
3486 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3490 c_symbol_merge (debug
, normal
)
3494 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3495 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3497 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3499 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3500 } /* take the most we have */
3502 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3504 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3505 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3506 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3507 } /* Move all the auxiliary information */
3509 /* Move the debug flags. */
3510 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3511 } /* c_symbol_merge() */
3514 c_line_new (symbol
, paddr
, line_number
, frag
)
3520 struct lineno_list
*new_line
=
3521 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3523 segment_info_type
*s
= segment_info
+ now_seg
;
3524 new_line
->line
.l_lnno
= line_number
;
3526 if (line_number
== 0)
3528 last_line_symbol
= symbol
;
3529 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3533 new_line
->line
.l_addr
.l_paddr
= paddr
;
3536 new_line
->frag
= (char *) frag
;
3537 new_line
->next
= (struct lineno_list
*) NULL
;
3540 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3542 s
->lineno_list_head
= new_line
;
3546 s
->lineno_list_tail
->next
= new_line
;
3548 s
->lineno_list_tail
= new_line
;
3549 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3553 c_dot_file_symbol (filename
)
3558 symbolP
= symbol_new (".file",
3561 &zero_address_frag
);
3563 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3564 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3566 if (strlen (filename
) > FILNMLEN
)
3568 /* Filename is too long to fit into an auxent,
3569 we stick it into the string table instead. We keep
3570 a linked list of the filenames we find so we can emit
3572 struct filename_list
*f
= ((struct filename_list
*)
3573 xmalloc (sizeof (struct filename_list
)));
3575 f
->filename
= filename
;
3578 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3579 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3581 if (filename_list_tail
)
3582 filename_list_tail
->next
= f
;
3584 filename_list_head
= f
;
3585 filename_list_tail
= f
;
3589 SA_SET_FILE_FNAME (symbolP
, filename
);
3596 listing_source_file (filename
);
3602 SF_SET_DEBUG (symbolP
);
3603 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3605 previous_file_symbol
= symbolP
;
3607 /* Make sure that the symbol is first on the symbol chain */
3608 if (symbol_rootP
!= symbolP
)
3610 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3611 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3613 } /* c_dot_file_symbol() */
3616 * Build a 'section static' symbol.
3620 c_section_symbol (name
, idx
)
3626 symbolP
= symbol_new (name
, idx
,
3628 &zero_address_frag
);
3630 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3631 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3633 SF_SET_STATICS (symbolP
);
3636 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3637 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3638 SF_CLEAR_LOCAL (symbolP
);
3641 /* If the .linkonce pseudo-op was used for this section, we must
3642 store the information in the auxiliary entry for the section
3644 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3648 switch (segment_info
[idx
].linkonce
)
3652 case LINKONCE_DISCARD
:
3653 type
= IMAGE_COMDAT_SELECT_ANY
;
3655 case LINKONCE_ONE_ONLY
:
3656 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3658 case LINKONCE_SAME_SIZE
:
3659 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3661 case LINKONCE_SAME_CONTENTS
:
3662 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3666 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3671 } /* c_section_symbol() */
3674 w_symbols (abfd
, where
, symbol_rootP
)
3677 symbolS
* symbol_rootP
;
3682 /* First fill in those values we have only just worked out */
3683 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3685 symbolP
= segment_info
[i
].dot
;
3688 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3689 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3690 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3695 * Emit all symbols left in the symbol chain.
3697 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3699 /* Used to save the offset of the name. It is used to point
3700 to the string in memory but must be a file offset. */
3701 register char *temp
;
3703 /* We can't fix the lnnoptr field in yank_symbols with the other
3704 adjustments, because we have to wait until we know where they
3706 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3708 SA_GET_SYM_LNNOPTR (symbolP
) +=
3709 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3712 tc_coff_symbol_emit_hook (symbolP
);
3714 temp
= S_GET_NAME (symbolP
);
3715 if (SF_GET_STRING (symbolP
))
3717 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3718 S_SET_ZEROES (symbolP
, 0);
3722 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3723 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3725 where
= symbol_to_chars (abfd
, where
, symbolP
);
3726 S_SET_NAME (symbolP
, temp
);
3732 obj_coff_lcomm (ignore
)
3745 name
= input_line_pointer
;
3747 c
= get_symbol_end ();
3748 p
= input_line_pointer
;
3751 if (*input_line_pointer
!= ',')
3753 as_bad (_("Expected comma after name"));
3754 ignore_rest_of_line ();
3757 if (*input_line_pointer
== '\n')
3759 as_bad (_("Missing size expression"));
3762 input_line_pointer
++;
3763 if ((temp
= get_absolute_expression ()) < 0)
3765 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3766 ignore_rest_of_line ();
3771 symbolP
= symbol_find_or_make(name
);
3773 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3774 S_GET_VALUE(symbolP
) == 0)
3779 segT current_seg
= now_seg
; /* save current seg */
3780 subsegT current_subseg
= now_subseg
;
3782 subseg_set (SEG_E2
, 1);
3783 symbolP
->sy_frag
= frag_now
;
3784 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3785 (offsetT
) temp
, (char *) 0);
3787 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3788 S_SET_SEGMENT(symbolP
, SEG_E2
);
3789 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3793 as_bad(_("Symbol %s already defined"), name
);
3795 demand_empty_rest_of_line();
3800 fixup_mdeps (frags
, h
, this_segment
)
3805 subseg_change (this_segment
, 0);
3808 switch (frags
->fr_type
)
3814 HANDLE_ALIGN (frags
);
3816 frags
->fr_type
= rs_fill
;
3818 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3821 case rs_machine_dependent
:
3822 md_convert_frag (h
, this_segment
, frags
);
3828 frags
= frags
->fr_next
;
3834 #ifndef TC_FORCE_RELOCATION
3835 #define TC_FORCE_RELOCATION(fix) 0
3839 fixup_segment (segP
, this_segment_type
)
3840 segment_info_type
* segP
;
3841 segT this_segment_type
;
3843 register fixS
* fixP
;
3844 register symbolS
*add_symbolP
;
3845 register symbolS
*sub_symbolP
;
3848 register char *place
;
3849 register long where
;
3850 register char pcrel
;
3851 register fragS
*fragP
;
3852 register segT add_symbol_segment
= absolute_section
;
3854 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3856 fragP
= fixP
->fx_frag
;
3858 where
= fixP
->fx_where
;
3859 place
= fragP
->fr_literal
+ where
;
3860 size
= fixP
->fx_size
;
3861 add_symbolP
= fixP
->fx_addsy
;
3862 sub_symbolP
= fixP
->fx_subsy
;
3863 add_number
= fixP
->fx_offset
;
3864 pcrel
= fixP
->fx_pcrel
;
3866 /* We want function-relative stabs to work on systems which
3867 may use a relaxing linker; thus we must handle the sym1-sym2
3868 fixups function-relative stabs generates.
3870 Of course, if you actually enable relaxing in the linker, the
3871 line and block scoping information is going to be incorrect
3872 in some cases. The only way to really fix this is to support
3873 a reloc involving the difference of two symbols. */
3875 && (!sub_symbolP
|| pcrel
))
3879 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3881 /* Relocation should be done via the associated 'bal' entry
3884 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3886 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3887 _("No 'bal' entry point for leafproc %s"),
3888 S_GET_NAME (add_symbolP
));
3891 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3895 /* Make sure the symbols have been resolved; this may not have
3896 happened if these are expression symbols. */
3897 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3898 resolve_symbol_value (add_symbolP
, 1);
3900 if (add_symbolP
!= NULL
)
3902 /* If this fixup is against a symbol which has been equated
3903 to another symbol, convert it to the other symbol. */
3904 if (add_symbolP
->sy_value
.X_op
== O_symbol
3905 && (! S_IS_DEFINED (add_symbolP
)
3906 || S_IS_COMMON (add_symbolP
)))
3908 while (add_symbolP
->sy_value
.X_op
== O_symbol
3909 && (! S_IS_DEFINED (add_symbolP
)
3910 || S_IS_COMMON (add_symbolP
)))
3914 /* We must avoid looping, as that can occur with a
3915 badly written program. */
3916 n
= add_symbolP
->sy_value
.X_add_symbol
;
3917 if (n
== add_symbolP
)
3919 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3922 fixP
->fx_addsy
= add_symbolP
;
3923 fixP
->fx_offset
= add_number
;
3927 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3928 resolve_symbol_value (sub_symbolP
, 1);
3930 if (add_symbolP
!= NULL
3931 && add_symbolP
->sy_mri_common
)
3933 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3934 add_number
+= S_GET_VALUE (add_symbolP
);
3935 fixP
->fx_offset
= add_number
;
3936 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3941 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3942 } /* if there is an addend */
3946 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3948 if (add_symbolP
!= NULL
)
3950 add_number
+= S_GET_VALUE (add_symbolP
);
3952 fixP
->fx_addsy
= NULL
;
3955 /* It's just -sym. */
3956 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3958 add_number
-= S_GET_VALUE (sub_symbolP
);
3965 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3966 _("Negative of non-absolute symbol %s"),
3967 S_GET_NAME (sub_symbolP
));
3969 add_number
-= S_GET_VALUE (sub_symbolP
);
3970 } /* not absolute */
3972 /* if sub_symbol is in the same segment that add_symbol
3973 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3975 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3976 && SEG_NORMAL (add_symbol_segment
))
3978 /* Difference of 2 symbols from same segment. Can't
3979 make difference of 2 undefineds: 'value' means
3980 something different for N_UNDF. */
3982 /* Makes no sense to use the difference of 2 arbitrary symbols
3983 as the target of a call instruction. */
3986 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3987 _("callj to difference of 2 symbols"));
3989 #endif /* TC_I960 */
3990 add_number
+= S_GET_VALUE (add_symbolP
) -
3991 S_GET_VALUE (sub_symbolP
);
3994 if (!TC_FORCE_RELOCATION (fixP
))
3996 fixP
->fx_addsy
= NULL
;
3997 fixP
->fx_subsy
= NULL
;
3999 #ifdef TC_M68K /* is this right? */
4007 /* Different segments in subtraction. */
4008 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4010 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4012 add_number
-= S_GET_VALUE (sub_symbolP
);
4015 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4016 #if 0 /* Okay for 68k, at least... */
4021 /* Make it pc-relative. */
4022 add_number
+= (md_pcrel_from (fixP
)
4023 - S_GET_VALUE (sub_symbolP
));
4032 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4033 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4034 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4035 S_GET_NAME (sub_symbolP
),
4036 (long) (fragP
->fr_address
+ where
));
4039 } /* if sub_symbolP */
4043 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4046 * This fixup was made when the symbol's segment was
4047 * SEG_UNKNOWN, but it is now in the local segment.
4048 * So we know how to do the address without relocation.
4051 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4052 * in which cases it modifies *fixP as appropriate. In the case
4053 * of a 'calls', no further work is required, and *fixP has been
4054 * set up to make the rest of the code below a no-op.
4057 #endif /* TC_I960 */
4059 add_number
+= S_GET_VALUE (add_symbolP
);
4060 add_number
-= md_pcrel_from (fixP
);
4063 add_number -= segP->scnhdr.s_vaddr;
4064 if defined (TC_I386) || defined (TE_LYNX). I now
4065 think that was an error propagated from the case when
4066 we are going to emit the relocation. If we are not
4067 going to emit the relocation, then we just want to
4068 set add_number to the difference between the symbols.
4069 This is a case that would only arise when there is a
4070 PC relative reference from a section other than .text
4071 to a symbol defined in the same section, and the
4072 reference is not relaxed. Since jump instructions on
4073 the i386 are relaxed, this could only arise with a
4074 call instruction. */
4076 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4077 if (!TC_FORCE_RELOCATION (fixP
))
4079 fixP
->fx_addsy
= NULL
;
4085 switch (add_symbol_segment
)
4087 case absolute_section
:
4089 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4090 #endif /* TC_I960 */
4091 add_number
+= S_GET_VALUE (add_symbolP
);
4094 if (!TC_FORCE_RELOCATION (fixP
))
4096 fixP
->fx_addsy
= NULL
;
4103 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4104 /* This really should be handled in the linker, but
4105 backward compatibility forbids. */
4106 add_number
+= S_GET_VALUE (add_symbolP
);
4108 add_number
+= S_GET_VALUE (add_symbolP
) +
4109 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4115 if ((int) fixP
->fx_bit_fixP
== 13)
4117 /* This is a COBR instruction. They have only a
4118 * 13-bit displacement and are only to be used
4119 * for local branches: flag as error, don't generate
4122 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4123 _("can't use COBR format with external label"));
4124 fixP
->fx_addsy
= NULL
;
4128 #endif /* TC_I960 */
4129 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4130 /* 386 COFF uses a peculiar format in which the
4131 value of a common symbol is stored in the .text
4132 segment (I've checked this on SVR3.2 and SCO
4133 3.2.2) Ian Taylor <ian@cygnus.com>. */
4134 /* This is also true for 68k COFF on sysv machines
4135 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4136 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4137 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4138 if (S_IS_COMMON (add_symbolP
))
4139 add_number
+= S_GET_VALUE (add_symbolP
);
4144 } /* switch on symbol seg */
4145 } /* if not in local seg */
4146 } /* if there was a + symbol */
4150 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4151 /* This adjustment is not correct on the m88k, for which the
4152 linker does all the computation. */
4153 add_number
-= md_pcrel_from (fixP
);
4155 if (add_symbolP
== 0)
4157 fixP
->fx_addsy
= &abs_symbol
;
4158 } /* if there's an add_symbol */
4159 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4160 /* On the 386 we must adjust by the segment vaddr as well.
4163 I changed the i960 to work this way as well. This is
4164 compatible with the current GNU linker behaviour. I do
4165 not know what other i960 COFF assemblers do. This is not
4166 a common case: normally, only assembler code will contain
4167 a PC relative reloc, and only branches which do not
4168 originate in the .text section will have a non-zero
4171 I changed the m68k to work this way as well. This will
4172 break existing PC relative relocs from sections which do
4173 not start at address 0, but it will make ld -r work.
4174 Ian Taylor, 4 Oct 96. */
4176 add_number
-= segP
->scnhdr
.s_vaddr
;
4180 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4183 /* The m88k uses the offset field of the reloc to get around
4186 && ((add_number
& ~0xFF)
4187 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4188 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4189 || (add_number
& 0x80) == 0))
4191 && ((add_number
& ~0xFFFF)
4192 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4193 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4194 || (add_number
& 0x8000) == 0)))
4196 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4197 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4198 (long) add_number
, size
,
4199 (unsigned long) (fragP
->fr_address
+ where
));
4202 #ifdef WARN_SIGNED_OVERFLOW_WORD
4203 /* Warn if a .word value is too large when treated as a
4204 signed number. We already know it is not too negative.
4205 This is to catch over-large switches generated by gcc on
4207 if (!flag_signed_overflow_ok
4209 && add_number
> 0x7fff)
4210 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4211 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4213 (unsigned long) (fragP
->fr_address
+ where
));
4215 } /* not a bit fix */
4216 /* Once this fix has been applied, we don't have to output
4217 anything nothing more need be done. */
4218 #ifdef MD_APPLY_FIX3
4219 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4221 md_apply_fix (fixP
, add_number
);
4223 } /* For each fixS in this segment. */
4224 } /* fixup_segment() */
4228 /* The first entry in a .stab section is special. */
4231 obj_coff_init_stab_section (seg
)
4237 unsigned int stroff
;
4239 /* Make space for this first symbol. */
4243 as_where (&file
, (unsigned int *) NULL
);
4244 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4245 strcpy (stabstr_name
, segment_info
[seg
].name
);
4246 strcat (stabstr_name
, "str");
4247 stroff
= get_stab_string_offset (file
, stabstr_name
);
4249 md_number_to_chars (p
, stroff
, 4);
4252 /* Fill in the counts in the first entry in a .stab section. */
4255 adjust_stab_section(abfd
, seg
)
4259 segT stabstrseg
= SEG_UNKNOWN
;
4260 const char *secname
, *name2
;
4263 int i
, strsz
= 0, nsyms
;
4264 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4266 /* Look for the associated string table section. */
4268 secname
= segment_info
[seg
].name
;
4269 name
= (char *) alloca (strlen (secname
) + 4);
4270 strcpy (name
, secname
);
4271 strcat (name
, "str");
4273 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4275 name2
= segment_info
[i
].name
;
4276 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4283 /* If we found the section, get its size. */
4284 if (stabstrseg
!= SEG_UNKNOWN
)
4285 strsz
= size_section (abfd
, stabstrseg
);
4287 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4289 /* Look for the first frag of sufficient size for the initial stab
4290 symbol, and collect a pointer to it. */
4291 while (frag
&& frag
->fr_fix
< 12)
4292 frag
= frag
->fr_next
;
4294 p
= frag
->fr_literal
;
4297 /* Write in the number of stab symbols and the size of the string
4299 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4300 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4303 #endif /* not BFD_ASSEMBLER */
4305 const pseudo_typeS obj_pseudo_table
[] =
4307 {"def", obj_coff_def
, 0},
4308 {"dim", obj_coff_dim
, 0},
4309 {"endef", obj_coff_endef
, 0},
4310 {"line", obj_coff_line
, 0},
4311 {"ln", obj_coff_ln
, 0},
4312 {"appline", obj_coff_ln
, 1},
4313 {"scl", obj_coff_scl
, 0},
4314 {"size", obj_coff_size
, 0},
4315 {"tag", obj_coff_tag
, 0},
4316 {"type", obj_coff_type
, 0},
4317 {"val", obj_coff_val
, 0},
4318 {"section", obj_coff_section
, 0},
4319 {"sect", obj_coff_section
, 0},
4320 /* FIXME: We ignore the MRI short attribute. */
4321 {"section.s", obj_coff_section
, 0},
4322 {"sect.s", obj_coff_section
, 0},
4323 /* We accept the .bss directive for backward compatibility with
4324 earlier versions of gas. */
4325 {"bss", obj_coff_bss
, 0},
4326 #ifndef BFD_ASSEMBLER
4327 {"use", obj_coff_section
, 0},
4328 {"text", obj_coff_text
, 0},
4329 {"data", obj_coff_data
, 0},
4330 {"lcomm", obj_coff_lcomm
, 0},
4331 {"ident", obj_coff_ident
, 0},
4333 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4334 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4336 {"version", s_ignore
, 0},
4337 {"ABORT", s_abort
, 0},
4339 /* The m88k uses sdef instead of def. */
4340 {"sdef", obj_coff_def
, 0},
4342 {NULL
} /* end sentinel */
4343 }; /* obj_pseudo_table */
4345 #ifdef BFD_ASSEMBLER
4347 /* Support for a COFF emulation. */
4352 pop_insert (obj_pseudo_table
);
4356 coff_sec_sym_ok_for_reloc (sec
)
4368 const struct format_ops coff_format_ops
=
4370 bfd_target_coff_flavour
,
4375 coff_frob_file_after_relocs
,
4380 obj_generate_asm_lineno
,
4389 coff_sec_sym_ok_for_reloc
,
4396 coff_obj_read_begin_hook
,
4397 coff_obj_symbol_new_hook
,