1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 1997
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 const char *s_get_name
PARAMS ((symbolS
* s
));
34 static symbolS
*def_symbol_in_progress
;
40 unsigned long chunk_size
;
41 unsigned long element_size
;
44 unsigned long pointer
;
49 stack_init (chunk_size
, element_size
)
50 unsigned long chunk_size
;
51 unsigned long element_size
;
55 st
= (stack
*) malloc (sizeof (stack
));
58 st
->data
= malloc (chunk_size
);
65 st
->size
= chunk_size
;
66 st
->chunk_size
= chunk_size
;
67 st
->element_size
= element_size
;
72 /* Not currently used. */
83 stack_push (st
, element
)
87 if (st
->pointer
+ st
->element_size
>= st
->size
)
89 st
->size
+= st
->chunk_size
;
90 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
93 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
94 st
->pointer
+= st
->element_size
;
95 return st
->data
+ st
->pointer
;
102 if (st
->pointer
< st
->element_size
)
107 st
->pointer
-= st
->element_size
;
108 return st
->data
+ st
->pointer
;
112 * Maintain a list of the tagnames of the structres.
115 static struct hash_control
*tag_hash
;
120 tag_hash
= hash_new ();
124 tag_insert (name
, symbolP
)
128 const char *error_string
;
130 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
132 as_fatal ("Inserting \"%s\" into structure table failed: %s",
141 #ifdef STRIP_UNDERSCORE
144 #endif /* STRIP_UNDERSCORE */
145 return (symbolS
*) hash_find (tag_hash
, name
);
149 tag_find_or_make (name
)
154 if ((symbolP
= tag_find (name
)) == NULL
)
156 symbolP
= symbol_new (name
, undefined_section
,
157 0, &zero_address_frag
);
159 tag_insert (S_GET_NAME (symbolP
), symbolP
);
161 symbol_table_insert (symbolP
);
172 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
174 #define GET_FILENAME_STRING(X) \
175 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
179 fetch_coff_debug_section ()
181 static segT debug_section
;
185 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
187 debug_section
= s
->section
;
189 return debug_section
;
193 SA_SET_SYM_ENDNDX (sym
, val
)
197 combined_entry_type
*entry
, *p
;
199 entry
= &coffsymbol (sym
->bsym
)->native
[1];
200 p
= coffsymbol (val
->bsym
)->native
;
201 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
206 SA_SET_SYM_TAGNDX (sym
, val
)
210 combined_entry_type
*entry
, *p
;
212 entry
= &coffsymbol (sym
->bsym
)->native
[1];
213 p
= coffsymbol (val
->bsym
)->native
;
214 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
219 S_GET_DATA_TYPE (sym
)
222 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
226 S_SET_DATA_TYPE (sym
, val
)
230 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
235 S_GET_STORAGE_CLASS (sym
)
238 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
242 S_SET_STORAGE_CLASS (sym
, val
)
246 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
250 /* Merge a debug symbol containing debug information into a normal symbol. */
253 c_symbol_merge (debug
, normal
)
257 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
258 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
260 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
261 /* take the most we have */
262 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
264 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
266 /* Move all the auxiliary information. */
267 /* @@ How many fields do we want to preserve? Would it make more
268 sense to pick and choose those we want to copy? Should look
269 into this further.... [raeburn:19920512.2209EST] */
271 linenos
= coffsymbol (normal
->bsym
)->lineno
;
272 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
273 (char *) &coffsymbol (debug
->bsym
)->native
,
274 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
275 coffsymbol (normal
->bsym
)->lineno
= linenos
;
278 /* Move the debug flags. */
279 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
283 c_dot_file_symbol (filename
)
288 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
290 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
291 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
293 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
300 listing_source_file (filename
);
305 /* Make sure that the symbol is first on the symbol chain */
306 if (symbol_rootP
!= symbolP
)
308 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
309 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
310 } /* if not first on the list */
313 /* Line number handling */
316 struct line_no
*next
;
323 /* Symbol of last function, which we should hang line#s off of. */
324 static symbolS
*line_fsym
;
326 #define in_function() (line_fsym != 0)
327 #define clear_function() (line_fsym = 0)
328 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
332 coff_obj_symbol_new_hook (symbolP
)
335 char underscore
= 0; /* Symbol has leading _ */
338 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
339 char *s
= (char *) xmalloc (sz
);
341 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
343 S_SET_DATA_TYPE (symbolP
, T_NULL
);
344 S_SET_STORAGE_CLASS (symbolP
, 0);
345 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
347 if (S_IS_STRING (symbolP
))
348 SF_SET_STRING (symbolP
);
349 if (!underscore
&& S_IS_LOCAL (symbolP
))
350 SF_SET_LOCAL (symbolP
);
355 * Handle .ln directives.
358 static symbolS
*current_lineno_sym
;
359 static struct line_no
*line_nos
;
360 /* @@ Blindly assume all .ln directives will be in the .text section... */
364 add_lineno (frag
, offset
, num
)
369 struct line_no
*new_line
=
370 (struct line_no
*) xmalloc (sizeof (struct line_no
));
371 if (!current_lineno_sym
)
375 new_line
->next
= line_nos
;
376 new_line
->frag
= frag
;
377 new_line
->l
.line_number
= num
;
378 new_line
->l
.u
.offset
= offset
;
384 coff_add_linesym (sym
)
389 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
393 current_lineno_sym
= sym
;
397 obj_coff_ln (appline
)
402 if (! appline
&& def_symbol_in_progress
!= NULL
)
404 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
405 demand_empty_rest_of_line ();
409 l
= get_absolute_expression ();
412 add_lineno (frag_now
, frag_now_fix (), l
);
416 new_logical_line ((char *) NULL
, l
- 1);
425 l
+= coff_line_base
- 1;
426 listing_source_line (l
);
431 demand_empty_rest_of_line ();
437 * Handle .def directives.
439 * One might ask : why can't we symbol_new if the symbol does not
440 * already exist and fill it with debug information. Because of
441 * the C_EFCN special symbol. It would clobber the value of the
442 * function symbol before we have a chance to notice that it is
443 * a C_EFCN. And a second reason is that the code is more clear this
444 * way. (at least I think it is :-).
448 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
449 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
450 *input_line_pointer == '\t') \
451 input_line_pointer++;
457 char name_end
; /* Char after the end of name */
458 char *symbol_name
; /* Name of the debug symbol */
459 char *symbol_name_copy
; /* Temporary copy of the name */
460 unsigned int symbol_name_length
;
462 if (def_symbol_in_progress
!= NULL
)
464 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
465 demand_empty_rest_of_line ();
467 } /* if not inside .def/.endef */
471 symbol_name
= input_line_pointer
;
472 #ifdef STRIP_UNDERSCORE
473 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
475 #endif /* STRIP_UNDERSCORE */
477 name_end
= get_symbol_end ();
478 symbol_name_length
= strlen (symbol_name
);
479 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
480 strcpy (symbol_name_copy
, symbol_name
);
481 #ifdef tc_canonicalize_symbol_name
482 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
485 /* Initialize the new symbol */
486 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
487 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
488 S_SET_VALUE (def_symbol_in_progress
, 0);
490 if (S_IS_STRING (def_symbol_in_progress
))
491 SF_SET_STRING (def_symbol_in_progress
);
493 *input_line_pointer
= name_end
;
495 demand_empty_rest_of_line ();
498 unsigned int dim_index
;
501 obj_coff_endef (ignore
)
505 /* DIM BUG FIX sac@cygnus.com */
507 if (def_symbol_in_progress
== NULL
)
509 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
510 demand_empty_rest_of_line ();
512 } /* if not inside .def/.endef */
514 /* Set the section number according to storage class. */
515 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
520 SF_SET_TAG (def_symbol_in_progress
);
521 /* intentional fallthrough */
524 SF_SET_DEBUG (def_symbol_in_progress
);
525 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
529 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
530 /* intentional fallthrough */
532 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
533 /* intentional fallthrough */
537 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
539 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
540 if (name
[1] == 'b' && name
[2] == 'f')
542 if (! in_function ())
543 as_warn ("`%s' symbol without preceding function", name
);
544 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
545 /* Will need relocating */
546 SF_SET_PROCESS (def_symbol_in_progress
);
554 #endif /* C_AUTOARG */
560 SF_SET_DEBUG (def_symbol_in_progress
);
561 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
568 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
574 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
580 as_warn ("unexpected storage class %d",
581 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
583 } /* switch on storage class */
585 /* Now that we have built a debug symbol, try to find if we should
586 merge with an existing symbol or not. If a symbol is C_EFCN or
587 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
589 /* Two cases for functions. Either debug followed by definition or
590 definition followed by debug. For definition first, we will
591 merge the debug symbol into the definition. For debug first, the
592 lineno entry MUST point to the definition function or else it
593 will point off into space when obj_crawl_symbol_chain() merges
594 the debug symbol into the real symbol. Therefor, let's presume
595 the debug symbol is a real function reference. */
597 /* FIXME-SOON If for some reason the definition label/symbol is
598 never seen, this will probably leave an undefined symbol at link
601 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
602 || (!strcmp (bfd_get_section_name (stdoutput
,
603 S_GET_SEGMENT (def_symbol_in_progress
)),
605 && !SF_GET_TAG (def_symbol_in_progress
))
606 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
607 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
609 if (def_symbol_in_progress
!= symbol_lastP
)
610 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
615 /* This symbol already exists, merge the newly created symbol
616 into the old one. This is not mandatory. The linker can
617 handle duplicate symbols correctly. But I guess that it save
618 a *lot* of space if the assembly file defines a lot of
621 /* The debug entry (def_symbol_in_progress) is merged into the
622 previous definition. */
624 c_symbol_merge (def_symbol_in_progress
, symbolP
);
625 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
627 def_symbol_in_progress
= symbolP
;
629 if (SF_GET_FUNCTION (def_symbol_in_progress
)
630 || SF_GET_TAG (def_symbol_in_progress
)
631 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
633 /* For functions, and tags, and static symbols, the symbol
634 *must* be where the debug symbol appears. Move the
635 existing symbol to the current place. */
636 /* If it already is at the end of the symbol list, do nothing */
637 if (def_symbol_in_progress
!= symbol_lastP
)
639 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
640 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
645 if (SF_GET_TAG (def_symbol_in_progress
))
649 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
651 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
652 tag_insert (S_GET_NAME (def_symbol_in_progress
),
653 def_symbol_in_progress
);
656 if (SF_GET_FUNCTION (def_symbol_in_progress
))
658 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
659 set_function (def_symbol_in_progress
);
660 SF_SET_PROCESS (def_symbol_in_progress
);
664 /* That is, if this is the first time we've seen the
666 symbol_table_insert (def_symbol_in_progress
);
667 } /* definition follows debug */
668 } /* Create the line number entry pointing to the function being defined */
670 def_symbol_in_progress
= NULL
;
671 demand_empty_rest_of_line ();
675 obj_coff_dim (ignore
)
680 if (def_symbol_in_progress
== NULL
)
682 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
683 demand_empty_rest_of_line ();
685 } /* if not inside .def/.endef */
687 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
689 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
692 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
693 get_absolute_expression ());
695 switch (*input_line_pointer
)
698 input_line_pointer
++;
702 as_warn ("badly formed .dim directive ignored");
703 /* intentional fallthrough */
711 demand_empty_rest_of_line ();
715 obj_coff_line (ignore
)
720 if (def_symbol_in_progress
== NULL
)
722 /* Probably stabs-style line? */
727 this_base
= get_absolute_expression ();
728 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
729 coff_line_base
= this_base
;
731 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
732 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
734 demand_empty_rest_of_line ();
737 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
742 listing_source_line ((unsigned int) coff_line_base
);
748 obj_coff_size (ignore
)
751 if (def_symbol_in_progress
== NULL
)
753 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
754 demand_empty_rest_of_line ();
756 } /* if not inside .def/.endef */
758 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
759 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
760 demand_empty_rest_of_line ();
764 obj_coff_scl (ignore
)
767 if (def_symbol_in_progress
== NULL
)
769 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
770 demand_empty_rest_of_line ();
772 } /* if not inside .def/.endef */
774 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
775 demand_empty_rest_of_line ();
779 obj_coff_tag (ignore
)
785 if (def_symbol_in_progress
== NULL
)
787 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
788 demand_empty_rest_of_line ();
792 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
793 symbol_name
= input_line_pointer
;
794 name_end
= get_symbol_end ();
796 #ifdef tc_canonicalize_symbol_name
797 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
800 /* Assume that the symbol referred to by .tag is always defined.
801 This was a bad assumption. I've added find_or_make. xoxorich. */
802 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
803 tag_find_or_make (symbol_name
));
804 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
806 as_warn ("tag not found for .tag %s", symbol_name
);
809 SF_SET_TAGGED (def_symbol_in_progress
);
810 *input_line_pointer
= name_end
;
812 demand_empty_rest_of_line ();
816 obj_coff_type (ignore
)
819 if (def_symbol_in_progress
== NULL
)
821 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
822 demand_empty_rest_of_line ();
824 } /* if not inside .def/.endef */
826 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
828 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
829 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
831 SF_SET_FUNCTION (def_symbol_in_progress
);
832 } /* is a function */
834 demand_empty_rest_of_line ();
838 obj_coff_val (ignore
)
841 if (def_symbol_in_progress
== NULL
)
843 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
844 demand_empty_rest_of_line ();
846 } /* if not inside .def/.endef */
848 if (is_name_beginner (*input_line_pointer
))
850 char *symbol_name
= input_line_pointer
;
851 char name_end
= get_symbol_end ();
853 #ifdef tc_canonicalize_symbol_name
854 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
856 if (!strcmp (symbol_name
, "."))
858 def_symbol_in_progress
->sy_frag
= frag_now
;
859 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
860 /* If the .val is != from the .def (e.g. statics) */
862 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
864 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
865 def_symbol_in_progress
->sy_value
.X_add_symbol
=
866 symbol_find_or_make (symbol_name
);
867 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
868 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
870 /* If the segment is undefined when the forward reference is
871 resolved, then copy the segment id from the forward
873 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
875 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
876 *input_line_pointer
= name_end
;
880 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
881 } /* if symbol based */
883 demand_empty_rest_of_line ();
887 coff_obj_read_begin_hook ()
889 /* These had better be the same. Usually 18 bytes. */
891 know (sizeof (SYMENT
) == sizeof (AUXENT
));
892 know (SYMESZ
== AUXESZ
);
898 symbolS
*coff_last_function
;
899 static symbolS
*coff_last_bf
;
902 coff_frob_symbol (symp
, punt
)
906 static symbolS
*last_tagP
;
907 static stack
*block_stack
;
908 static symbolS
*set_end
;
909 symbolS
*next_set_end
= NULL
;
911 if (symp
== &abs_symbol
)
917 if (current_lineno_sym
)
918 coff_add_linesym ((symbolS
*) 0);
921 block_stack
= stack_init (512, sizeof (symbolS
*));
923 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
924 S_SET_STORAGE_CLASS (symp
, C_EXT
);
926 if (!SF_GET_DEBUG (symp
))
929 if (!SF_GET_LOCAL (symp
)
930 && !SF_GET_STATICS (symp
)
931 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
934 c_symbol_merge (symp
, real
);
937 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
939 assert (S_GET_VALUE (symp
) == 0);
940 S_SET_EXTERNAL (symp
);
942 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
944 if (S_GET_SEGMENT (symp
) == text_section
945 && symp
!= seg_info (text_section
)->sym
)
946 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
948 S_SET_STORAGE_CLASS (symp
, C_STAT
);
950 if (SF_GET_PROCESS (symp
))
952 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
954 if (!strcmp (S_GET_NAME (symp
), ".bb"))
955 stack_push (block_stack
, (char *) &symp
);
959 begin
= *(symbolS
**) stack_pop (block_stack
);
961 as_warn ("mismatched .eb");
963 next_set_end
= begin
;
966 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
968 union internal_auxent
*auxp
;
969 coff_last_function
= symp
;
970 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
971 S_SET_NUMBER_AUXILIARY (symp
, 1);
972 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
973 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
974 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
976 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
978 if (coff_last_function
== 0)
979 as_fatal ("C_EFCN symbol out of scope");
980 SA_SET_SYM_FSIZE (coff_last_function
,
981 (long) (S_GET_VALUE (symp
)
982 - S_GET_VALUE (coff_last_function
)));
983 next_set_end
= coff_last_function
;
984 coff_last_function
= 0;
987 if (S_IS_EXTERNAL (symp
))
988 S_SET_STORAGE_CLASS (symp
, C_EXT
);
989 else if (SF_GET_LOCAL (symp
))
992 if (SF_GET_FUNCTION (symp
))
993 symp
->bsym
->flags
|= BSF_FUNCTION
;
998 if (SF_GET_TAG (symp
))
1000 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1001 next_set_end
= last_tagP
;
1004 /* This is pretty horrible, but we have to set *punt correctly in
1005 order to call SA_SET_SYM_ENDNDX correctly. */
1006 if (! symp
->sy_used_in_reloc
1007 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1008 || (! S_IS_EXTERNAL (symp
)
1009 && ! symp
->sy_tc
.output
1010 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1014 if (set_end
!= (symbolS
*) NULL
1016 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1017 || (S_IS_DEFINED (symp
)
1018 && ! S_IS_COMMON (symp
)
1019 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1021 SA_SET_SYM_ENDNDX (set_end
, symp
);
1025 if (next_set_end
!= NULL
1027 set_end
= next_set_end
;
1030 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1031 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1033 if (coff_last_bf
!= NULL
)
1034 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1035 coff_last_bf
= symp
;
1038 if (coffsymbol (symp
->bsym
)->lineno
)
1041 struct line_no
*lptr
;
1044 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1045 for (i
= 0; lptr
; lptr
= lptr
->next
)
1047 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1049 /* We need i entries for line numbers, plus 1 for the first
1050 entry which BFD will override, plus 1 for the last zero
1051 entry (a marker for BFD). */
1052 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1053 coffsymbol (symp
->bsym
)->lineno
= l
;
1054 l
[i
+ 1].line_number
= 0;
1055 l
[i
+ 1].u
.sym
= NULL
;
1059 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1067 coff_adjust_section_syms (abfd
, sec
, x
)
1073 segment_info_type
*seginfo
= seg_info (sec
);
1074 int nlnno
, nrelocs
= 0;
1076 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1077 tc-ppc.c. Do not get confused by it. */
1078 if (seginfo
== NULL
)
1081 if (!strcmp (sec
->name
, ".text"))
1082 nlnno
= coff_n_line_nos
;
1086 /* @@ Hope that none of the fixups expand to more than one reloc
1088 fixS
*fixp
= seginfo
->fix_root
;
1091 fixp
= fixp
->fx_next
;
1095 if (bfd_get_section_size_before_reloc (sec
) == 0
1098 && sec
!= text_section
1099 && sec
!= data_section
1100 && sec
!= bss_section
)
1102 secsym
= section_symbol (sec
);
1103 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1104 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1110 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1114 * implement the .section pseudo op:
1115 * .section name {, "flags"}
1117 * | +--- optional flags: 'b' for bss
1119 * +-- section name 'l' for lib
1123 * 'd' (apparently m88k for data)
1125 * 'r' for read-only data
1126 * But if the argument is not a quoted string, treat it as a
1127 * subsegment number.
1131 obj_coff_section (ignore
)
1134 /* Strip out the section name */
1150 section_name
= input_line_pointer
;
1151 c
= get_symbol_end ();
1153 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1154 strcpy (name
, section_name
);
1156 *input_line_pointer
= c
;
1161 flags
= SEC_NO_FLAGS
;
1163 if (*input_line_pointer
== ',')
1165 ++input_line_pointer
;
1167 if (*input_line_pointer
!= '"')
1168 exp
= get_absolute_expression ();
1171 ++input_line_pointer
;
1172 while (*input_line_pointer
!= '"'
1173 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1175 switch (*input_line_pointer
)
1177 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1178 case 'n': flags
&=~ SEC_LOAD
; break;
1180 case 'w': flags
&=~ SEC_READONLY
; break;
1181 case 'x': flags
|= SEC_CODE
; break;
1182 case 'r': flags
|= SEC_READONLY
; break;
1184 case 'i': /* STYP_INFO */
1185 case 'l': /* STYP_LIB */
1186 case 'o': /* STYP_OVER */
1187 as_warn ("unsupported section attribute '%c'",
1188 *input_line_pointer
);
1192 as_warn("unknown section attribute '%c'",
1193 *input_line_pointer
);
1196 ++input_line_pointer
;
1198 if (*input_line_pointer
== '"')
1199 ++input_line_pointer
;
1203 sec
= subseg_new (name
, (subsegT
) exp
);
1205 if (flags
!= SEC_NO_FLAGS
)
1207 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1208 as_warn ("error setting flags for \"%s\": %s",
1209 bfd_section_name (stdoutput
, sec
),
1210 bfd_errmsg (bfd_get_error ()));
1213 demand_empty_rest_of_line ();
1217 coff_adjust_symtab ()
1219 if (symbol_rootP
== NULL
1220 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1221 c_dot_file_symbol ("fake");
1225 coff_frob_section (sec
)
1231 bfd_vma size
, n_entries
, mask
;
1233 /* The COFF back end in BFD requires that all section sizes be
1234 rounded up to multiples of the corresponding section alignments.
1235 Seems kinda silly to me, but that's the way it is. */
1236 size
= bfd_get_section_size_before_reloc (sec
);
1237 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1240 size
= (size
+ mask
) & ~mask
;
1241 bfd_set_section_size (stdoutput
, sec
, size
);
1244 /* If the section size is non-zero, the section symbol needs an aux
1245 entry associated with it, indicating the size. We don't know
1246 all the values yet; coff_frob_symbol will fill them in later. */
1248 || sec
== text_section
1249 || sec
== data_section
1250 || sec
== bss_section
)
1252 symbolS
*secsym
= section_symbol (sec
);
1254 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1255 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1256 SF_SET_STATICS (secsym
);
1257 SA_SET_SCN_SCNLEN (secsym
, size
);
1260 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1261 #ifndef STAB_SECTION_NAME
1262 #define STAB_SECTION_NAME ".stab"
1264 #ifndef STAB_STRING_SECTION_NAME
1265 #define STAB_STRING_SECTION_NAME ".stabstr"
1267 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1271 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1272 /* size is already rounded up, since other section will be listed first */
1273 size
= bfd_get_section_size_before_reloc (strsec
);
1275 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1277 /* Find first non-empty frag. It should be large enough. */
1278 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1279 while (fragp
&& fragp
->fr_fix
== 0)
1280 fragp
= fragp
->fr_next
;
1281 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1283 /* Store the values. */
1284 p
= fragp
->fr_literal
;
1285 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1286 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1290 obj_coff_init_stab_section (seg
)
1296 unsigned int stroff
;
1298 /* Make space for this first symbol. */
1302 as_where (&file
, (unsigned int *) NULL
);
1303 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1304 strcpy (stabstr_name
, seg
->name
);
1305 strcat (stabstr_name
, "str");
1306 stroff
= get_stab_string_offset (file
, stabstr_name
);
1308 md_number_to_chars (p
, stroff
, 4);
1317 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1325 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1327 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1328 (unsigned long) symbolP
,
1329 S_GET_NAME(symbolP
),
1330 (long) S_GET_DATA_TYPE(symbolP
),
1331 S_GET_STORAGE_CLASS(symbolP
),
1332 (int) S_GET_SEGMENT(symbolP
));
1338 #else /* not BFD_ASSEMBLER */
1341 /* This is needed because we include internal bfd things. */
1345 #include "libcoff.h"
1348 #include "coff/pe.h"
1351 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1352 that we can stick sections together without causing trouble. */
1354 #define NOP_OPCODE 0x00
1357 /* The zeroes if symbol name is longer than 8 chars */
1358 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1360 #define MIN(a,b) ((a) < (b)? (a) : (b))
1361 /* This vector is used to turn an internal segment into a section #
1362 suitable for insertion into a coff symbol table
1365 const short seg_N_TYPE
[] =
1366 { /* in: segT out: N_TYPE bits */
1368 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1369 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1370 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1371 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1372 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1373 C_UNDEF_SECTION
, /* SEG_GOOF */
1374 C_UNDEF_SECTION
, /* SEG_EXPR */
1375 C_DEBUG_SECTION
, /* SEG_DEBUG */
1376 C_NTV_SECTION
, /* SEG_NTV */
1377 C_PTV_SECTION
, /* SEG_PTV */
1378 C_REGISTER_SECTION
, /* SEG_REGISTER */
1381 int function_lineoff
= -1; /* Offset in line#s where the last function
1382 started (the odd entry for line #0) */
1384 /* structure used to keep the filenames which
1385 are too long around so that we can stick them
1386 into the string table */
1387 struct filename_list
1390 struct filename_list
*next
;
1393 static struct filename_list
*filename_list_head
;
1394 static struct filename_list
*filename_list_tail
;
1396 static symbolS
*last_line_symbol
;
1398 /* Add 4 to the real value to get the index and compensate the
1399 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1400 section number into a segment number
1402 static symbolS
*previous_file_symbol
;
1403 void c_symbol_merge ();
1404 static int line_base
;
1406 symbolS
*c_section_symbol ();
1409 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1410 segT this_segment_type
));
1413 static void fixup_mdeps
PARAMS ((fragS
*,
1418 static void fill_section
PARAMS ((bfd
* abfd
,
1423 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1428 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1429 symbolS
* symbol_rootP
));
1431 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1433 static void obj_coff_lcomm
PARAMS ((int));
1434 static void obj_coff_text
PARAMS ((int));
1435 static void obj_coff_data
PARAMS ((int));
1436 static void obj_coff_bss
PARAMS ((int));
1437 static void obj_coff_ident
PARAMS ((int));
1438 void obj_coff_section
PARAMS ((int));
1442 We allow more than just the standard 3 sections, infact, we allow
1443 40 sections, (though the usual three have to be there).
1445 This structure performs the mappings for us:
1455 static const seg_info_type seg_info_off_by_4
[] =
1462 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1463 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1464 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1465 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1466 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1467 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1468 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1469 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1484 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1486 static relax_addressT
1487 relax_align (address
, alignment
)
1488 relax_addressT address
;
1491 relax_addressT mask
;
1492 relax_addressT new_address
;
1494 mask
= ~((~0) << alignment
);
1495 new_address
= (address
+ mask
) & (~mask
);
1496 return (new_address
- address
);
1504 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1507 /* calculate the size of the frag chain and fill in the section header
1508 to contain all of it, also fill in the addr of the sections */
1510 size_section (abfd
, idx
)
1515 unsigned int size
= 0;
1516 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1519 size
= frag
->fr_address
;
1520 if (frag
->fr_address
!= size
)
1522 fprintf (stderr
, "Out of step\n");
1523 size
= frag
->fr_address
;
1526 switch (frag
->fr_type
)
1528 #ifdef TC_COFF_SIZEMACHDEP
1529 case rs_machine_dependent
:
1530 size
+= TC_COFF_SIZEMACHDEP (frag
);
1534 assert (frag
->fr_symbol
== 0);
1537 size
+= frag
->fr_fix
;
1538 size
+= frag
->fr_offset
* frag
->fr_var
;
1545 size
+= frag
->fr_fix
;
1546 off
= relax_align (size
, frag
->fr_offset
);
1547 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1553 BAD_CASE (frag
->fr_type
);
1556 frag
= frag
->fr_next
;
1558 segment_info
[idx
].scnhdr
.s_size
= size
;
1564 count_entries_in_chain (idx
)
1567 unsigned int nrelocs
;
1570 /* Count the relocations */
1571 fixup_ptr
= segment_info
[idx
].fix_root
;
1573 while (fixup_ptr
!= (fixS
*) NULL
)
1575 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1578 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1587 fixup_ptr
= fixup_ptr
->fx_next
;
1594 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1596 /* AUX's ld expects relocations to be sorted */
1598 compare_external_relocs (x
, y
)
1602 struct external_reloc
*a
= (struct external_reloc
*) x
;
1603 struct external_reloc
*b
= (struct external_reloc
*) y
;
1604 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1605 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1606 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1611 /* output all the relocations for a section */
1613 do_relocs_for (abfd
, h
, file_cursor
)
1616 unsigned long *file_cursor
;
1618 unsigned int nrelocs
;
1620 unsigned long reloc_start
= *file_cursor
;
1622 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1624 if (segment_info
[idx
].scnhdr
.s_name
[0])
1626 struct external_reloc
*ext_ptr
;
1627 struct external_reloc
*external_reloc_vec
;
1628 unsigned int external_reloc_size
;
1629 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1630 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1631 nrelocs
= count_entries_in_chain (idx
);
1634 /* Bypass this stuff if no relocs. This also incidentally
1635 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1637 external_reloc_size
= nrelocs
* RELSZ
;
1638 external_reloc_vec
=
1639 (struct external_reloc
*) malloc (external_reloc_size
);
1641 ext_ptr
= external_reloc_vec
;
1643 /* Fill in the internal coff style reloc struct from the
1644 internal fix list. */
1647 struct internal_reloc intr
;
1649 /* Only output some of the relocations */
1650 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1652 #ifdef TC_RELOC_MANGLE
1653 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1658 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1660 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1662 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1664 #ifdef TC_KEEP_FX_OFFSET
1665 intr
.r_offset
= fix_ptr
->fx_offset
;
1670 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1671 && (! S_IS_DEFINED (symbol_ptr
)
1672 || S_IS_COMMON (symbol_ptr
)))
1676 /* We must avoid looping, as that can occur
1677 with a badly written program. */
1678 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1679 if (n
== symbol_ptr
)
1684 /* Turn the segment of the symbol into an offset. */
1687 resolve_symbol_value (symbol_ptr
);
1688 if (! symbol_ptr
->sy_resolved
)
1693 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1694 as_bad_where (file
, line
,
1695 "unresolved relocation");
1697 as_bad ("bad relocation: symbol `%s' not in symbol table",
1698 S_GET_NAME (symbol_ptr
));
1700 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1703 intr
.r_symndx
= dot
->sy_number
;
1707 intr
.r_symndx
= symbol_ptr
->sy_number
;
1717 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1720 #if defined(TC_A29K)
1722 /* The 29k has a special kludge for the high 16 bit
1723 reloc. Two relocations are emited, R_IHIHALF,
1724 and R_IHCONST. The second one doesn't contain a
1725 symbol, but uses the value for offset. */
1727 if (intr
.r_type
== R_IHIHALF
)
1729 /* now emit the second bit */
1730 intr
.r_type
= R_IHCONST
;
1731 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1732 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1738 fix_ptr
= fix_ptr
->fx_next
;
1742 /* Sort the reloc table */
1743 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1744 sizeof (struct external_reloc
), compare_external_relocs
);
1747 /* Write out the reloc table */
1748 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1750 free (external_reloc_vec
);
1752 /* Fill in section header info. */
1753 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1754 *file_cursor
+= external_reloc_size
;
1755 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1760 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1764 /* Set relocation_size field in file headers */
1765 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1769 /* run through a frag chain and write out the data to go with it, fill
1770 in the scnhdrs with the info on the file postions
1773 fill_section (abfd
, h
, file_cursor
)
1776 unsigned long *file_cursor
;
1780 unsigned int paddr
= 0;
1782 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1784 unsigned int offset
= 0;
1785 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1791 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1798 buffer
= xmalloc (s
->s_size
);
1799 s
->s_scnptr
= *file_cursor
;
1801 know (s
->s_paddr
== paddr
);
1803 if (strcmp (s
->s_name
, ".text") == 0)
1804 s
->s_flags
|= STYP_TEXT
;
1805 else if (strcmp (s
->s_name
, ".data") == 0)
1806 s
->s_flags
|= STYP_DATA
;
1807 else if (strcmp (s
->s_name
, ".bss") == 0)
1810 s
->s_flags
|= STYP_BSS
;
1812 /* @@ Should make the i386 and a29k coff targets define
1813 COFF_NOLOAD_PROBLEM, and have only one test here. */
1816 #ifndef COFF_NOLOAD_PROBLEM
1817 /* Apparently the SVR3 linker (and exec syscall) and UDI
1818 mondfe progrem are confused by noload sections. */
1819 s
->s_flags
|= STYP_NOLOAD
;
1824 else if (strcmp (s
->s_name
, ".lit") == 0)
1825 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1826 else if (strcmp (s
->s_name
, ".init") == 0)
1827 s
->s_flags
|= STYP_TEXT
;
1828 else if (strcmp (s
->s_name
, ".fini") == 0)
1829 s
->s_flags
|= STYP_TEXT
;
1830 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1831 s
->s_flags
|= STYP_INFO
;
1835 unsigned int fill_size
;
1836 switch (frag
->fr_type
)
1838 case rs_machine_dependent
:
1841 memcpy (buffer
+ frag
->fr_address
,
1843 (unsigned int) frag
->fr_fix
);
1844 offset
+= frag
->fr_fix
;
1849 assert (frag
->fr_symbol
== 0);
1856 memcpy (buffer
+ frag
->fr_address
,
1858 (unsigned int) frag
->fr_fix
);
1859 offset
+= frag
->fr_fix
;
1862 fill_size
= frag
->fr_var
;
1863 if (fill_size
&& frag
->fr_offset
> 0)
1866 unsigned int off
= frag
->fr_fix
;
1867 for (count
= frag
->fr_offset
; count
; count
--)
1869 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1871 memcpy (buffer
+ frag
->fr_address
+ off
,
1872 frag
->fr_literal
+ frag
->fr_fix
,
1875 offset
+= fill_size
;
1880 case rs_broken_word
:
1885 frag
= frag
->fr_next
;
1890 if (s
->s_scnptr
!= 0)
1892 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1893 *file_cursor
+= s
->s_size
;
1902 /* Coff file generation & utilities */
1905 coff_header_append (abfd
, h
)
1913 bfd_seek (abfd
, 0, 0);
1915 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1916 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1917 H_SET_VERSION_STAMP (h
, 0);
1918 H_SET_ENTRY_POINT (h
, 0);
1919 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1920 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1921 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1923 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1924 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1925 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1927 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1929 bfd_write (buffer
, i
, 1, abfd
);
1930 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1932 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1934 #ifdef COFF_LONG_SECTION_NAMES
1935 unsigned long string_size
= 4;
1938 if (segment_info
[i
].scnhdr
.s_name
[0])
1942 #ifdef COFF_LONG_SECTION_NAMES
1943 /* Support long section names as found in PE. This code
1944 must coordinate with that in write_object_file and
1946 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1948 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1949 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1950 string_size
+= strlen (segment_info
[i
].name
) + 1;
1954 size
= bfd_coff_swap_scnhdr_out (abfd
,
1955 &(segment_info
[i
].scnhdr
),
1958 as_bad ("bfd_coff_swap_scnhdr_out failed");
1959 bfd_write (buffer
, size
, 1, abfd
);
1966 symbol_to_chars (abfd
, where
, symbolP
)
1971 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1975 /* Turn any symbols with register attributes into abs symbols */
1976 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1978 S_SET_SEGMENT (symbolP
, absolute_section
);
1980 /* At the same time, relocate all symbols to their output value */
1982 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1983 + S_GET_VALUE (symbolP
));
1985 S_SET_VALUE (symbolP
, val
);
1987 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1989 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1992 for (i
= 0; i
< numaux
; i
++)
1994 where
+= bfd_coff_swap_aux_out (abfd
,
1995 &symbolP
->sy_symbol
.ost_auxent
[i
],
1996 S_GET_DATA_TYPE (symbolP
),
1997 S_GET_STORAGE_CLASS (symbolP
),
2005 coff_obj_symbol_new_hook (symbolP
)
2008 char underscore
= 0; /* Symbol has leading _ */
2010 /* Effective symbol */
2011 /* Store the pointer in the offset. */
2012 S_SET_ZEROES (symbolP
, 0L);
2013 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2014 S_SET_STORAGE_CLASS (symbolP
, 0);
2015 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2016 /* Additional information */
2017 symbolP
->sy_symbol
.ost_flags
= 0;
2018 /* Auxiliary entries */
2019 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2021 if (S_IS_STRING (symbolP
))
2022 SF_SET_STRING (symbolP
);
2023 if (!underscore
&& S_IS_LOCAL (symbolP
))
2024 SF_SET_LOCAL (symbolP
);
2028 * Handle .ln directives.
2032 obj_coff_ln (appline
)
2037 if (! appline
&& def_symbol_in_progress
!= NULL
)
2039 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2040 demand_empty_rest_of_line ();
2042 } /* wrong context */
2044 l
= get_absolute_expression ();
2045 c_line_new (0, frag_now_fix (), l
, frag_now
);
2048 new_logical_line ((char *) NULL
, l
- 1);
2058 listing_source_line ((unsigned int) l
);
2063 demand_empty_rest_of_line ();
2069 * Handle .def directives.
2071 * One might ask : why can't we symbol_new if the symbol does not
2072 * already exist and fill it with debug information. Because of
2073 * the C_EFCN special symbol. It would clobber the value of the
2074 * function symbol before we have a chance to notice that it is
2075 * a C_EFCN. And a second reason is that the code is more clear this
2076 * way. (at least I think it is :-).
2080 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2081 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2082 *input_line_pointer == '\t') \
2083 input_line_pointer++;
2089 char name_end
; /* Char after the end of name */
2090 char *symbol_name
; /* Name of the debug symbol */
2091 char *symbol_name_copy
; /* Temporary copy of the name */
2092 unsigned int symbol_name_length
;
2094 if (def_symbol_in_progress
!= NULL
)
2096 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2097 demand_empty_rest_of_line ();
2099 } /* if not inside .def/.endef */
2101 SKIP_WHITESPACES ();
2103 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2104 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2106 symbol_name
= input_line_pointer
;
2107 name_end
= get_symbol_end ();
2108 symbol_name_length
= strlen (symbol_name
);
2109 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2110 strcpy (symbol_name_copy
, symbol_name
);
2111 #ifdef tc_canonicalize_symbol_name
2112 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2115 /* Initialize the new symbol */
2116 #ifdef STRIP_UNDERSCORE
2117 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2118 ? symbol_name_copy
+ 1
2119 : symbol_name_copy
));
2120 #else /* STRIP_UNDERSCORE */
2121 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2122 #endif /* STRIP_UNDERSCORE */
2123 /* free(symbol_name_copy); */
2124 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2125 def_symbol_in_progress
->sy_number
= ~0;
2126 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2127 S_SET_VALUE (def_symbol_in_progress
, 0);
2129 if (S_IS_STRING (def_symbol_in_progress
))
2130 SF_SET_STRING (def_symbol_in_progress
);
2132 *input_line_pointer
= name_end
;
2134 demand_empty_rest_of_line ();
2137 unsigned int dim_index
;
2141 obj_coff_endef (ignore
)
2144 symbolS
*symbolP
= 0;
2145 /* DIM BUG FIX sac@cygnus.com */
2147 if (def_symbol_in_progress
== NULL
)
2149 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2150 demand_empty_rest_of_line ();
2152 } /* if not inside .def/.endef */
2154 /* Set the section number according to storage class. */
2155 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2160 SF_SET_TAG (def_symbol_in_progress
);
2161 /* intentional fallthrough */
2164 SF_SET_DEBUG (def_symbol_in_progress
);
2165 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2169 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2170 /* intentional fallthrough */
2172 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2173 /* intentional fallthrough */
2175 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2177 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2179 if (function_lineoff
< 0)
2181 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2182 } /* missing function symbol */
2183 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2185 SF_SET_PROCESS (last_line_symbol
);
2186 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2187 SF_SET_PROCESS (def_symbol_in_progress
);
2188 function_lineoff
= -1;
2190 /* Value is always set to . */
2191 def_symbol_in_progress
->sy_frag
= frag_now
;
2192 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2197 #endif /* C_AUTOARG */
2207 SF_SET_DEBUG (def_symbol_in_progress
);
2208 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2214 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2220 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2222 } /* switch on storage class */
2224 /* Now that we have built a debug symbol, try to find if we should
2225 merge with an existing symbol or not. If a symbol is C_EFCN or
2226 absolute_section or untagged SEG_DEBUG it never merges. We also
2227 don't merge labels, which are in a different namespace, nor
2228 symbols which have not yet been defined since they are typically
2229 unique, nor do we merge tags with non-tags. */
2231 /* Two cases for functions. Either debug followed by definition or
2232 definition followed by debug. For definition first, we will
2233 merge the debug symbol into the definition. For debug first, the
2234 lineno entry MUST point to the definition function or else it
2235 will point off into space when crawl_symbols() merges the debug
2236 symbol into the real symbol. Therefor, let's presume the debug
2237 symbol is a real function reference. */
2239 /* FIXME-SOON If for some reason the definition label/symbol is
2240 never seen, this will probably leave an undefined symbol at link
2243 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2244 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2245 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2246 && !SF_GET_TAG (def_symbol_in_progress
))
2247 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2248 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2249 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2250 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2252 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2257 /* This symbol already exists, merge the newly created symbol
2258 into the old one. This is not mandatory. The linker can
2259 handle duplicate symbols correctly. But I guess that it save
2260 a *lot* of space if the assembly file defines a lot of
2263 /* The debug entry (def_symbol_in_progress) is merged into the
2264 previous definition. */
2266 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2267 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2268 def_symbol_in_progress
= symbolP
;
2270 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2271 || SF_GET_TAG (def_symbol_in_progress
)
2272 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2274 /* For functions, and tags, and static symbols, the symbol
2275 *must* be where the debug symbol appears. Move the
2276 existing symbol to the current place. */
2277 /* If it already is at the end of the symbol list, do nothing */
2278 if (def_symbol_in_progress
!= symbol_lastP
)
2280 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2282 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2283 &symbol_rootP
, &symbol_lastP
);
2284 } /* if not already in place */
2286 } /* normal or mergable */
2288 if (SF_GET_TAG (def_symbol_in_progress
))
2292 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2294 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2295 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2296 def_symbol_in_progress
);
2299 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2301 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2303 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2305 SF_SET_PROCESS (def_symbol_in_progress
);
2307 if (symbolP
== NULL
)
2309 /* That is, if this is the first time we've seen the
2311 symbol_table_insert (def_symbol_in_progress
);
2312 } /* definition follows debug */
2313 } /* Create the line number entry pointing to the function being defined */
2315 def_symbol_in_progress
= NULL
;
2316 demand_empty_rest_of_line ();
2320 obj_coff_dim (ignore
)
2325 if (def_symbol_in_progress
== NULL
)
2327 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2328 demand_empty_rest_of_line ();
2330 } /* if not inside .def/.endef */
2332 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2334 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2336 SKIP_WHITESPACES ();
2337 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2338 get_absolute_expression ());
2340 switch (*input_line_pointer
)
2343 input_line_pointer
++;
2347 as_warn ("badly formed .dim directive ignored");
2348 /* intentional fallthrough */
2356 demand_empty_rest_of_line ();
2360 obj_coff_line (ignore
)
2366 if (def_symbol_in_progress
== NULL
)
2372 name
= S_GET_NAME (def_symbol_in_progress
);
2373 this_base
= get_absolute_expression ();
2375 /* Only .bf symbols indicate the use of a new base line number; the
2376 line numbers associated with .ef, .bb, .eb are relative to the
2377 start of the containing function. */
2378 if (!strcmp (".bf", name
))
2380 #if 0 /* XXX Can we ever have line numbers going backwards? */
2381 if (this_base
> line_base
)
2384 line_base
= this_base
;
2392 listing_source_line ((unsigned int) line_base
);
2398 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2399 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2401 demand_empty_rest_of_line ();
2405 obj_coff_size (ignore
)
2408 if (def_symbol_in_progress
== NULL
)
2410 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2411 demand_empty_rest_of_line ();
2413 } /* if not inside .def/.endef */
2415 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2416 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2417 demand_empty_rest_of_line ();
2421 obj_coff_scl (ignore
)
2424 if (def_symbol_in_progress
== NULL
)
2426 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2427 demand_empty_rest_of_line ();
2429 } /* if not inside .def/.endef */
2431 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2432 demand_empty_rest_of_line ();
2436 obj_coff_tag (ignore
)
2442 if (def_symbol_in_progress
== NULL
)
2444 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2445 demand_empty_rest_of_line ();
2449 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2450 symbol_name
= input_line_pointer
;
2451 name_end
= get_symbol_end ();
2452 #ifdef tc_canonicalize_symbol_name
2453 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2456 /* Assume that the symbol referred to by .tag is always defined.
2457 This was a bad assumption. I've added find_or_make. xoxorich. */
2458 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2459 (long) tag_find_or_make (symbol_name
));
2460 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2462 as_warn ("tag not found for .tag %s", symbol_name
);
2465 SF_SET_TAGGED (def_symbol_in_progress
);
2466 *input_line_pointer
= name_end
;
2468 demand_empty_rest_of_line ();
2472 obj_coff_type (ignore
)
2475 if (def_symbol_in_progress
== NULL
)
2477 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2478 demand_empty_rest_of_line ();
2480 } /* if not inside .def/.endef */
2482 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2484 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2485 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2487 SF_SET_FUNCTION (def_symbol_in_progress
);
2488 } /* is a function */
2490 demand_empty_rest_of_line ();
2494 obj_coff_val (ignore
)
2497 if (def_symbol_in_progress
== NULL
)
2499 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2500 demand_empty_rest_of_line ();
2502 } /* if not inside .def/.endef */
2504 if (is_name_beginner (*input_line_pointer
))
2506 char *symbol_name
= input_line_pointer
;
2507 char name_end
= get_symbol_end ();
2509 #ifdef tc_canonicalize_symbol_name
2510 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2513 if (!strcmp (symbol_name
, "."))
2515 def_symbol_in_progress
->sy_frag
= frag_now
;
2516 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2517 /* If the .val is != from the .def (e.g. statics) */
2519 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2521 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2522 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2523 symbol_find_or_make (symbol_name
);
2524 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2525 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2527 /* If the segment is undefined when the forward reference is
2528 resolved, then copy the segment id from the forward
2530 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2532 /* FIXME: gcc can generate address expressions
2533 here in unusual cases (search for "obscure"
2534 in sdbout.c). We just ignore the offset
2535 here, thus generating incorrect debugging
2536 information. We ignore the rest of the
2539 /* Otherwise, it is the name of a non debug symbol and
2540 its value will be calculated later. */
2541 *input_line_pointer
= name_end
;
2543 /* FIXME: this is to avoid an error message in the
2544 FIXME case mentioned just above. */
2545 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2546 ++input_line_pointer
;
2550 S_SET_VALUE (def_symbol_in_progress
,
2551 (valueT
) get_absolute_expression ());
2552 } /* if symbol based */
2554 demand_empty_rest_of_line ();
2559 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2560 read.c, which then calls this object file format specific routine. */
2563 obj_coff_pe_handle_link_once (type
)
2564 enum linkonce_type type
;
2566 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2568 /* We store the type in the seg_info structure, and use it to set up
2569 the auxiliary entry for the section symbol in c_section_symbol. */
2570 seg_info (now_seg
)->linkonce
= type
;
2576 coff_obj_read_begin_hook ()
2578 /* These had better be the same. Usually 18 bytes. */
2580 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2581 know (SYMESZ
== AUXESZ
);
2586 /* This function runs through the symbol table and puts all the
2587 externals onto another chain */
2589 /* The chain of globals. */
2590 symbolS
*symbol_globalP
;
2591 symbolS
*symbol_global_lastP
;
2593 /* The chain of externals */
2594 symbolS
*symbol_externP
;
2595 symbolS
*symbol_extern_lastP
;
2598 symbolS
*last_functionP
;
2599 static symbolS
*last_bfP
;
2606 unsigned int symbol_number
= 0;
2607 unsigned int last_file_symno
= 0;
2609 struct filename_list
*filename_list_scan
= filename_list_head
;
2611 for (symbolP
= symbol_rootP
;
2613 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2615 if (symbolP
->sy_mri_common
)
2617 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2618 as_bad ("%s: global symbols not supported in common sections",
2619 S_GET_NAME (symbolP
));
2620 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2624 if (!SF_GET_DEBUG (symbolP
))
2626 /* Debug symbols do not need all this rubbish */
2627 symbolS
*real_symbolP
;
2629 /* L* and C_EFCN symbols never merge. */
2630 if (!SF_GET_LOCAL (symbolP
)
2631 && !SF_GET_STATICS (symbolP
)
2632 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2633 && symbolP
->sy_value
.X_op
== O_constant
2634 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2635 && real_symbolP
!= symbolP
)
2637 /* FIXME-SOON: where do dups come from?
2638 Maybe tag references before definitions? xoxorich. */
2639 /* Move the debug data from the debug symbol to the
2640 real symbol. Do NOT do the oposite (i.e. move from
2641 real symbol to debug symbol and remove real symbol from the
2642 list.) Because some pointers refer to the real symbol
2643 whereas no pointers refer to the debug symbol. */
2644 c_symbol_merge (symbolP
, real_symbolP
);
2645 /* Replace the current symbol by the real one */
2646 /* The symbols will never be the last or the first
2647 because : 1st symbol is .file and 3 last symbols are
2648 .text, .data, .bss */
2649 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2650 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2651 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2652 symbolP
= real_symbolP
;
2653 } /* if not local but dup'd */
2655 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2657 S_SET_SEGMENT (symbolP
, SEG_E0
);
2658 } /* push data into text */
2660 resolve_symbol_value (symbolP
);
2662 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2664 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2666 S_SET_EXTERNAL (symbolP
);
2668 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2670 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2674 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2678 /* Mainly to speed up if not -g */
2679 if (SF_GET_PROCESS (symbolP
))
2681 /* Handle the nested blocks auxiliary info. */
2682 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2684 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2685 stack_push (block_stack
, (char *) &symbolP
);
2688 register symbolS
*begin_symbolP
;
2689 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2690 if (begin_symbolP
== (symbolS
*) 0)
2691 as_warn ("mismatched .eb");
2693 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2696 /* If we are able to identify the type of a function, and we
2697 are out of a function (last_functionP == 0) then, the
2698 function symbol will be associated with an auxiliary
2700 if (last_functionP
== (symbolS
*) 0 &&
2701 SF_GET_FUNCTION (symbolP
))
2703 last_functionP
= symbolP
;
2705 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2707 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2708 } /* make it at least 1 */
2710 /* Clobber possible stale .dim information. */
2712 /* Iffed out by steve - this fries the lnnoptr info too */
2713 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2714 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2717 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2719 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2721 if (last_bfP
!= NULL
)
2722 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2726 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2728 /* I don't even know if this is needed for sdb. But
2729 the standard assembler generates it, so... */
2730 if (last_functionP
== (symbolS
*) 0)
2731 as_fatal ("C_EFCN symbol out of scope");
2732 SA_SET_SYM_FSIZE (last_functionP
,
2733 (long) (S_GET_VALUE (symbolP
) -
2734 S_GET_VALUE (last_functionP
)));
2735 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2736 last_functionP
= (symbolS
*) 0;
2740 else if (SF_GET_TAG (symbolP
))
2742 /* First descriptor of a structure must point to
2743 the first slot after the structure description. */
2744 last_tagP
= symbolP
;
2747 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2749 /* +2 take in account the current symbol */
2750 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2752 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2754 /* If the filename was too long to fit in the
2755 auxent, put it in the string table */
2756 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2757 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2759 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2760 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2761 filename_list_scan
= filename_list_scan
->next
;
2763 if (S_GET_VALUE (symbolP
))
2765 S_SET_VALUE (symbolP
, last_file_symno
);
2766 last_file_symno
= symbol_number
;
2767 } /* no one points at the first .file symbol */
2768 } /* if debug or tag or eos or file */
2770 #ifdef tc_frob_coff_symbol
2771 tc_frob_coff_symbol (symbolP
);
2774 /* We must put the external symbols apart. The loader
2775 does not bomb if we do not. But the references in
2776 the endndx field for a .bb symbol are not corrected
2777 if an external symbol is removed between .bb and .be.
2778 I.e in the following case :
2779 [20] .bb endndx = 22
2782 ld will move the symbol 21 to the end of the list but
2783 endndx will still be 22 instead of 21. */
2786 if (SF_GET_LOCAL (symbolP
))
2788 /* remove C_EFCN and LOCAL (L...) symbols */
2789 /* next pointer remains valid */
2790 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2793 else if (symbolP
->sy_value
.X_op
== O_symbol
2794 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2796 /* Skip symbols which were equated to undefined or common
2798 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2800 else if (!S_IS_DEFINED (symbolP
)
2801 && !S_IS_DEBUG (symbolP
)
2802 && !SF_GET_STATICS (symbolP
) &&
2803 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2804 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2805 /* if external, Remove from the list */
2806 symbolS
*hold
= symbol_previous (symbolP
);
2808 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2809 symbol_clear_list_pointers (symbolP
);
2810 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2813 else if (! S_IS_DEBUG (symbolP
)
2814 && ! SF_GET_STATICS (symbolP
)
2815 && ! SF_GET_FUNCTION (symbolP
)
2816 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2818 symbolS
*hold
= symbol_previous (symbolP
);
2820 /* The O'Reilly COFF book says that defined global symbols
2821 come at the end of the symbol table, just before
2822 undefined global symbols. */
2824 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2825 symbol_clear_list_pointers (symbolP
);
2826 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2827 &symbol_global_lastP
);
2832 if (SF_GET_STRING (symbolP
))
2834 symbolP
->sy_name_offset
= string_byte_count
;
2835 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2839 symbolP
->sy_name_offset
= 0;
2840 } /* fix "long" names */
2842 symbolP
->sy_number
= symbol_number
;
2843 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2844 } /* if local symbol */
2845 } /* traverse the symbol list */
2846 return symbol_number
;
2852 glue_symbols (head
, tail
)
2856 unsigned int symbol_number
= 0;
2858 while (*head
!= NULL
)
2860 symbolS
*tmp
= *head
;
2863 symbol_remove (tmp
, head
, tail
);
2864 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2867 if (SF_GET_STRING (tmp
))
2869 tmp
->sy_name_offset
= string_byte_count
;
2870 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2874 tmp
->sy_name_offset
= 0;
2875 } /* fix "long" names */
2877 tmp
->sy_number
= symbol_number
;
2878 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2879 } /* append the entire extern chain */
2881 return symbol_number
;
2887 unsigned int symbol_number
= 0;
2890 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2892 symbolP
->sy_number
= symbol_number
;
2894 if (SF_GET_TAGGED (symbolP
))
2898 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2901 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2904 return symbol_number
;
2908 crawl_symbols (h
, abfd
)
2914 /* Initialize the stack used to keep track of the matching .bb .be */
2916 block_stack
= stack_init (512, sizeof (symbolS
*));
2918 /* The symbol list should be ordered according to the following sequence
2921 * . debug entries for functions
2922 * . fake symbols for the sections, including .text .data and .bss
2924 * . undefined symbols
2925 * But this is not mandatory. The only important point is to put the
2926 * undefined symbols at the end of the list.
2929 /* Is there a .file symbol ? If not insert one at the beginning. */
2930 if (symbol_rootP
== NULL
2931 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2933 c_dot_file_symbol ("fake");
2937 * Build up static symbols for the sections, they are filled in later
2941 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2942 if (segment_info
[i
].scnhdr
.s_name
[0])
2943 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2946 /* Take all the externals out and put them into another chain */
2947 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2948 /* Take the externals and glue them onto the end.*/
2949 H_SET_SYMBOL_TABLE_SIZE (h
,
2950 (H_GET_SYMBOL_COUNT (h
)
2951 + glue_symbols (&symbol_globalP
,
2952 &symbol_global_lastP
)
2953 + glue_symbols (&symbol_externP
,
2954 &symbol_extern_lastP
)));
2956 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2957 know (symbol_globalP
== NULL
);
2958 know (symbol_global_lastP
== NULL
);
2959 know (symbol_externP
== NULL
);
2960 know (symbol_extern_lastP
== NULL
);
2964 * Find strings by crawling along symbol table chain.
2972 struct filename_list
*filename_list_scan
= filename_list_head
;
2974 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2975 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2978 #ifdef COFF_LONG_SECTION_NAMES
2979 /* Support long section names as found in PE. This code must
2980 coordinate with that in coff_header_append and write_object_file. */
2984 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2986 if (segment_info
[i
].scnhdr
.s_name
[0]
2987 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2991 size
= strlen (segment_info
[i
].name
) + 1;
2992 memcpy (where
, segment_info
[i
].name
, size
);
2997 #endif /* COFF_LONG_SECTION_NAMES */
2999 for (symbolP
= symbol_rootP
;
3001 symbolP
= symbol_next (symbolP
))
3005 if (SF_GET_STRING (symbolP
))
3007 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3008 memcpy (where
, S_GET_NAME (symbolP
), size
);
3011 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3012 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3013 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3015 size
= strlen (filename_list_scan
->filename
) + 1;
3016 memcpy (where
, filename_list_scan
->filename
, size
);
3017 filename_list_scan
= filename_list_scan
->next
;
3024 do_linenos_for (abfd
, h
, file_cursor
)
3027 unsigned long *file_cursor
;
3030 unsigned long start
= *file_cursor
;
3032 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3034 segment_info_type
*s
= segment_info
+ idx
;
3037 if (s
->scnhdr
.s_nlnno
!= 0)
3039 struct lineno_list
*line_ptr
;
3041 struct external_lineno
*buffer
=
3042 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3044 struct external_lineno
*dst
= buffer
;
3046 /* Run through the table we've built and turn it into its external
3047 form, take this chance to remove duplicates */
3049 for (line_ptr
= s
->lineno_list_head
;
3050 line_ptr
!= (struct lineno_list
*) NULL
;
3051 line_ptr
= line_ptr
->next
)
3054 if (line_ptr
->line
.l_lnno
== 0)
3056 /* Turn a pointer to a symbol into the symbols' index */
3057 line_ptr
->line
.l_addr
.l_symndx
=
3058 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3062 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3066 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3071 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3073 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3076 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3079 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3083 /* Now we run through the list of frag chains in a segment and
3084 make all the subsegment frags appear at the end of the
3085 list, as if the seg 0 was extra long */
3092 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3094 frchainS
*head
= segment_info
[i
].frchainP
;
3096 fragS
*prev_frag
= &dummy
;
3098 while (head
&& head
->frch_seg
== i
)
3100 prev_frag
->fr_next
= head
->frch_root
;
3101 prev_frag
= head
->frch_last
;
3102 head
= head
->frch_next
;
3104 prev_frag
->fr_next
= 0;
3108 unsigned long machine
;
3111 write_object_file ()
3115 struct frchain
*frchain_ptr
;
3117 object_headers headers
;
3118 unsigned long file_cursor
;
3121 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3126 as_perror ("FATAL: Can't create %s", out_file_name
);
3127 exit (EXIT_FAILURE
);
3129 bfd_set_format (abfd
, bfd_object
);
3130 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3132 string_byte_count
= 4;
3134 for (frchain_ptr
= frchain_root
;
3135 frchain_ptr
!= (struct frchain
*) NULL
;
3136 frchain_ptr
= frchain_ptr
->frch_next
)
3138 /* Run through all the sub-segments and align them up. Also
3139 close any open frags. We tack a .fill onto the end of the
3140 frag chain so that any .align's size can be worked by looking
3141 at the next frag. */
3143 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3144 #ifndef SUB_SEGMENT_ALIGN
3145 #define SUB_SEGMENT_ALIGN(SEG) 1
3149 static char nop
= NOP_OPCODE
;
3150 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, 0, alignment_done
);
3153 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3157 frag_wane (frag_now
);
3158 frag_now
->fr_fix
= 0;
3159 know (frag_now
->fr_next
== NULL
);
3166 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3168 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3171 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3173 /* Find out how big the sections are, and set the addresses. */
3175 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3179 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3180 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3182 if (segment_info
[i
].scnhdr
.s_name
[0])
3184 H_SET_NUMBER_OF_SECTIONS (&headers
,
3185 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3187 #ifdef COFF_LONG_SECTION_NAMES
3188 /* Support long section names as found in PE. This code
3189 must coordinate with that in coff_header_append and
3194 len
= strlen (segment_info
[i
].name
);
3196 string_byte_count
+= len
+ 1;
3198 #endif /* COFF_LONG_SECTION_NAMES */
3201 size
= size_section (abfd
, (unsigned int) i
);
3204 /* I think the section alignment is only used on the i960; the
3205 i960 needs it, and it should do no harm on other targets. */
3206 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3209 H_SET_TEXT_SIZE (&headers
, size
);
3210 else if (i
== SEG_E1
)
3211 H_SET_DATA_SIZE (&headers
, size
);
3212 else if (i
== SEG_E2
)
3213 H_SET_BSS_SIZE (&headers
, size
);
3216 /* Turn the gas native symbol table shape into a coff symbol table */
3217 crawl_symbols (&headers
, abfd
);
3219 if (string_byte_count
== 4)
3220 string_byte_count
= 0;
3222 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3228 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3230 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3231 fixup_segment (&segment_info
[i
], i
);
3234 /* Look for ".stab" segments and fill in their initial symbols
3236 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3238 name
= segment_info
[i
].name
;
3241 && strncmp (".stab", name
, 5) == 0
3242 && strncmp (".stabstr", name
, 8) != 0)
3243 adjust_stab_section (abfd
, i
);
3246 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3248 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3250 /* Plant the data */
3252 fill_section (abfd
, &headers
, &file_cursor
);
3254 do_relocs_for (abfd
, &headers
, &file_cursor
);
3256 do_linenos_for (abfd
, &headers
, &file_cursor
);
3258 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3259 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3260 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3262 H_SET_TIME_STAMP (&headers
, 0);
3264 #ifdef TC_COFF_SET_MACHINE
3265 TC_COFF_SET_MACHINE (&headers
);
3269 #define COFF_FLAGS 0
3272 #ifdef KEEP_RELOC_INFO
3273 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3274 COFF_FLAGS
| coff_flags
));
3276 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3277 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3278 COFF_FLAGS
| coff_flags
));
3282 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3283 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3285 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3286 w_symbols (abfd
, buffer1
, symbol_rootP
);
3287 if (string_byte_count
> 0)
3288 w_strings (buffer1
+ symtable_size
);
3289 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3293 coff_header_append (abfd
, &headers
);
3295 /* Recent changes to write need this, but where it should
3296 go is up to Ken.. */
3297 if (bfd_close_all_done (abfd
) == false)
3298 as_fatal ("Can't close %s: %s", out_file_name
,
3299 bfd_errmsg (bfd_get_error ()));
3302 extern bfd
*stdoutput
;
3309 /* Add a new segment. This is called from subseg_new via the
3310 obj_new_segment macro. */
3313 obj_coff_add_segment (name
)
3318 #ifndef COFF_LONG_SECTION_NAMES
3319 char buf
[SCNNMLEN
+ 1];
3321 strncpy (buf
, name
, SCNNMLEN
);
3322 buf
[SCNNMLEN
] = '\0';
3326 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3327 if (strcmp (name
, segment_info
[i
].name
) == 0)
3332 as_bad ("Too many new sections; can't add \"%s\"", name
);
3336 /* Add a new section. */
3337 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3338 sizeof (segment_info
[i
].scnhdr
.s_name
));
3339 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3340 segment_info
[i
].name
= xstrdup (name
);
3346 * implement the .section pseudo op:
3347 * .section name {, "flags"}
3349 * | +--- optional flags: 'b' for bss
3351 * +-- section name 'l' for lib
3355 * 'd' (apparently m88k for data)
3357 * 'r' for read-only data
3358 * But if the argument is not a quoted string, treat it as a
3359 * subsegment number.
3363 obj_coff_section (ignore
)
3366 /* Strip out the section name */
3367 char *section_name
, *name
;
3380 else if (type
== 'D')
3382 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3387 section_name
= input_line_pointer
;
3388 c
= get_symbol_end ();
3390 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3391 strcpy (name
, section_name
);
3393 *input_line_pointer
= c
;
3399 if (*input_line_pointer
== ',')
3401 ++input_line_pointer
;
3404 if (*input_line_pointer
!= '"')
3405 exp
= get_absolute_expression ();
3408 ++input_line_pointer
;
3409 while (*input_line_pointer
!= '"'
3410 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3412 switch (*input_line_pointer
)
3414 case 'b': flags
|= STYP_BSS
; break;
3415 case 'i': flags
|= STYP_INFO
; break;
3416 case 'l': flags
|= STYP_LIB
; break;
3417 case 'n': flags
|= STYP_NOLOAD
; break;
3418 case 'o': flags
|= STYP_OVER
; break;
3420 case 'w': flags
|= STYP_DATA
; break;
3421 case 'x': flags
|= STYP_TEXT
; break;
3422 case 'r': flags
|= STYP_LIT
; break;
3424 as_warn("unknown section attribute '%c'",
3425 *input_line_pointer
);
3428 ++input_line_pointer
;
3430 if (*input_line_pointer
== '"')
3431 ++input_line_pointer
;
3435 subseg_new (name
, (subsegT
) exp
);
3437 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3439 demand_empty_rest_of_line ();
3444 obj_coff_text (ignore
)
3447 subseg_new (".text", get_absolute_expression ());
3452 obj_coff_data (ignore
)
3455 if (flag_readonly_data_in_text
)
3456 subseg_new (".text", get_absolute_expression () + 1000);
3458 subseg_new (".data", get_absolute_expression ());
3462 obj_coff_bss (ignore
)
3465 if (*input_line_pointer
== '\n') /* .bss */
3466 subseg_new(".bss", get_absolute_expression());
3467 else /* .bss id,expr */
3472 obj_coff_ident (ignore
)
3475 segT current_seg
= now_seg
; /* save current seg */
3476 subsegT current_subseg
= now_subseg
;
3477 subseg_new (".comment", 0); /* .comment seg */
3478 stringer (1); /* read string */
3479 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3483 c_symbol_merge (debug
, normal
)
3487 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3488 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3490 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3492 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3493 } /* take the most we have */
3495 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3497 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3498 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3499 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3500 } /* Move all the auxiliary information */
3502 /* Move the debug flags. */
3503 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3504 } /* c_symbol_merge() */
3507 c_line_new (symbol
, paddr
, line_number
, frag
)
3513 struct lineno_list
*new_line
=
3514 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3516 segment_info_type
*s
= segment_info
+ now_seg
;
3517 new_line
->line
.l_lnno
= line_number
;
3519 if (line_number
== 0)
3521 last_line_symbol
= symbol
;
3522 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3526 new_line
->line
.l_addr
.l_paddr
= paddr
;
3529 new_line
->frag
= (char *) frag
;
3530 new_line
->next
= (struct lineno_list
*) NULL
;
3533 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3535 s
->lineno_list_head
= new_line
;
3539 s
->lineno_list_tail
->next
= new_line
;
3541 s
->lineno_list_tail
= new_line
;
3542 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3546 c_dot_file_symbol (filename
)
3551 symbolP
= symbol_new (".file",
3554 &zero_address_frag
);
3556 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3557 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3559 if (strlen (filename
) > FILNMLEN
)
3561 /* Filename is too long to fit into an auxent,
3562 we stick it into the string table instead. We keep
3563 a linked list of the filenames we find so we can emit
3565 struct filename_list
*f
= ((struct filename_list
*)
3566 xmalloc (sizeof (struct filename_list
)));
3568 f
->filename
= filename
;
3571 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3572 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3574 if (filename_list_tail
)
3575 filename_list_tail
->next
= f
;
3577 filename_list_head
= f
;
3578 filename_list_tail
= f
;
3582 SA_SET_FILE_FNAME (symbolP
, filename
);
3589 listing_source_file (filename
);
3595 SF_SET_DEBUG (symbolP
);
3596 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3598 previous_file_symbol
= symbolP
;
3600 /* Make sure that the symbol is first on the symbol chain */
3601 if (symbol_rootP
!= symbolP
)
3603 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3604 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3606 } /* c_dot_file_symbol() */
3609 * Build a 'section static' symbol.
3613 c_section_symbol (name
, idx
)
3619 symbolP
= symbol_new (name
, idx
,
3621 &zero_address_frag
);
3623 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3624 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3626 SF_SET_STATICS (symbolP
);
3629 /* If the .linkonce pseudo-op was used for this section, we must
3630 store the information in the auxiliary entry for the section
3632 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3636 switch (segment_info
[idx
].linkonce
)
3640 case LINKONCE_DISCARD
:
3641 type
= IMAGE_COMDAT_SELECT_ANY
;
3643 case LINKONCE_ONE_ONLY
:
3644 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3646 case LINKONCE_SAME_SIZE
:
3647 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3649 case LINKONCE_SAME_CONTENTS
:
3650 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3654 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3659 } /* c_section_symbol() */
3662 w_symbols (abfd
, where
, symbol_rootP
)
3665 symbolS
* symbol_rootP
;
3670 /* First fill in those values we have only just worked out */
3671 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3673 symbolP
= segment_info
[i
].dot
;
3676 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3677 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3678 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3683 * Emit all symbols left in the symbol chain.
3685 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3687 /* Used to save the offset of the name. It is used to point
3688 to the string in memory but must be a file offset. */
3689 register char *temp
;
3691 /* We can't fix the lnnoptr field in yank_symbols with the other
3692 adjustments, because we have to wait until we know where they
3694 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3696 SA_GET_SYM_LNNOPTR (symbolP
) +=
3697 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3700 tc_coff_symbol_emit_hook (symbolP
);
3702 temp
= S_GET_NAME (symbolP
);
3703 if (SF_GET_STRING (symbolP
))
3705 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3706 S_SET_ZEROES (symbolP
, 0);
3710 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3711 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3713 where
= symbol_to_chars (abfd
, where
, symbolP
);
3714 S_SET_NAME (symbolP
, temp
);
3720 obj_coff_lcomm (ignore
)
3733 name
= input_line_pointer
;
3735 c
= get_symbol_end ();
3736 p
= input_line_pointer
;
3739 if (*input_line_pointer
!= ',')
3741 as_bad ("Expected comma after name");
3742 ignore_rest_of_line ();
3745 if (*input_line_pointer
== '\n')
3747 as_bad ("Missing size expression");
3750 input_line_pointer
++;
3751 if ((temp
= get_absolute_expression ()) < 0)
3753 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3754 ignore_rest_of_line ();
3759 symbolP
= symbol_find_or_make(name
);
3761 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3762 S_GET_VALUE(symbolP
) == 0)
3767 segT current_seg
= now_seg
; /* save current seg */
3768 subsegT current_subseg
= now_subseg
;
3770 subseg_set (SEG_E2
, 1);
3771 symbolP
->sy_frag
= frag_now
;
3772 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3775 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3776 S_SET_SEGMENT(symbolP
, SEG_E2
);
3777 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3781 as_bad("Symbol %s already defined", name
);
3783 demand_empty_rest_of_line();
3788 fixup_mdeps (frags
, h
, this_segment
)
3793 subseg_change (this_segment
, 0);
3796 switch (frags
->fr_type
)
3802 HANDLE_ALIGN (frags
);
3804 frags
->fr_type
= rs_fill
;
3806 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3809 case rs_machine_dependent
:
3810 md_convert_frag (h
, this_segment
, frags
);
3816 frags
= frags
->fr_next
;
3822 #ifndef TC_FORCE_RELOCATION
3823 #define TC_FORCE_RELOCATION(fix) 0
3827 fixup_segment (segP
, this_segment_type
)
3828 segment_info_type
* segP
;
3829 segT this_segment_type
;
3831 register fixS
* fixP
;
3832 register symbolS
*add_symbolP
;
3833 register symbolS
*sub_symbolP
;
3836 register char *place
;
3837 register long where
;
3838 register char pcrel
;
3839 register fragS
*fragP
;
3840 register segT add_symbol_segment
= absolute_section
;
3842 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3844 fragP
= fixP
->fx_frag
;
3846 where
= fixP
->fx_where
;
3847 place
= fragP
->fr_literal
+ where
;
3848 size
= fixP
->fx_size
;
3849 add_symbolP
= fixP
->fx_addsy
;
3850 sub_symbolP
= fixP
->fx_subsy
;
3851 add_number
= fixP
->fx_offset
;
3852 pcrel
= fixP
->fx_pcrel
;
3854 /* We want function-relative stabs to work on systems which
3855 may use a relaxing linker; thus we must handle the sym1-sym2
3856 fixups function-relative stabs generates.
3858 Of course, if you actually enable relaxing in the linker, the
3859 line and block scoping information is going to be incorrect
3860 in some cases. The only way to really fix this is to support
3861 a reloc involving the difference of two symbols. */
3863 && (!sub_symbolP
|| pcrel
))
3867 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3869 /* Relocation should be done via the associated 'bal' entry
3872 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3874 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3875 "No 'bal' entry point for leafproc %s",
3876 S_GET_NAME (add_symbolP
));
3879 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3883 /* Make sure the symbols have been resolved; this may not have
3884 happened if these are expression symbols. */
3885 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3886 resolve_symbol_value (add_symbolP
);
3888 if (add_symbolP
!= NULL
)
3890 /* If this fixup is against a symbol which has been equated
3891 to another symbol, convert it to the other symbol. */
3892 if (add_symbolP
->sy_value
.X_op
== O_symbol
3893 && (! S_IS_DEFINED (add_symbolP
)
3894 || S_IS_COMMON (add_symbolP
)))
3896 while (add_symbolP
->sy_value
.X_op
== O_symbol
3897 && (! S_IS_DEFINED (add_symbolP
)
3898 || S_IS_COMMON (add_symbolP
)))
3902 /* We must avoid looping, as that can occur with a
3903 badly written program. */
3904 n
= add_symbolP
->sy_value
.X_add_symbol
;
3905 if (n
== add_symbolP
)
3907 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3910 fixP
->fx_addsy
= add_symbolP
;
3911 fixP
->fx_offset
= add_number
;
3915 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3916 resolve_symbol_value (sub_symbolP
);
3918 if (add_symbolP
!= NULL
3919 && add_symbolP
->sy_mri_common
)
3921 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3922 add_number
+= S_GET_VALUE (add_symbolP
);
3923 fixP
->fx_offset
= add_number
;
3924 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3929 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3930 } /* if there is an addend */
3934 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3936 if (add_symbolP
!= NULL
)
3938 add_number
+= S_GET_VALUE (add_symbolP
);
3940 fixP
->fx_addsy
= NULL
;
3943 /* It's just -sym. */
3944 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3946 add_number
-= S_GET_VALUE (sub_symbolP
);
3953 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3954 "Negative of non-absolute symbol %s",
3955 S_GET_NAME (sub_symbolP
));
3957 add_number
-= S_GET_VALUE (sub_symbolP
);
3958 } /* not absolute */
3960 /* if sub_symbol is in the same segment that add_symbol
3961 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3963 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3964 && SEG_NORMAL (add_symbol_segment
))
3966 /* Difference of 2 symbols from same segment. Can't
3967 make difference of 2 undefineds: 'value' means
3968 something different for N_UNDF. */
3970 /* Makes no sense to use the difference of 2 arbitrary symbols
3971 as the target of a call instruction. */
3974 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3975 "callj to difference of 2 symbols");
3977 #endif /* TC_I960 */
3978 add_number
+= S_GET_VALUE (add_symbolP
) -
3979 S_GET_VALUE (sub_symbolP
);
3982 if (!TC_FORCE_RELOCATION (fixP
))
3984 fixP
->fx_addsy
= NULL
;
3985 fixP
->fx_subsy
= NULL
;
3987 #ifdef TC_M68K /* is this right? */
3995 /* Different segments in subtraction. */
3996 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3998 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4000 add_number
-= S_GET_VALUE (sub_symbolP
);
4003 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4004 #if 0 /* Okay for 68k, at least... */
4009 /* Make it pc-relative. */
4010 add_number
+= (md_pcrel_from (fixP
)
4011 - S_GET_VALUE (sub_symbolP
));
4020 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4021 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
4022 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4023 S_GET_NAME (sub_symbolP
),
4024 (long) (fragP
->fr_address
+ where
));
4027 } /* if sub_symbolP */
4031 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4034 * This fixup was made when the symbol's segment was
4035 * SEG_UNKNOWN, but it is now in the local segment.
4036 * So we know how to do the address without relocation.
4039 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4040 * in which cases it modifies *fixP as appropriate. In the case
4041 * of a 'calls', no further work is required, and *fixP has been
4042 * set up to make the rest of the code below a no-op.
4045 #endif /* TC_I960 */
4047 add_number
+= S_GET_VALUE (add_symbolP
);
4048 add_number
-= md_pcrel_from (fixP
);
4049 #if defined (TC_I386) || defined (TE_LYNX)
4050 /* On the 386 we must adjust by the segment vaddr as
4051 well. Ian Taylor. */
4052 add_number
-= segP
->scnhdr
.s_vaddr
;
4054 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4055 if (!TC_FORCE_RELOCATION (fixP
))
4057 fixP
->fx_addsy
= NULL
;
4063 switch (add_symbol_segment
)
4065 case absolute_section
:
4067 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4068 #endif /* TC_I960 */
4069 add_number
+= S_GET_VALUE (add_symbolP
);
4072 if (!TC_FORCE_RELOCATION (fixP
))
4074 fixP
->fx_addsy
= NULL
;
4081 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4082 /* This really should be handled in the linker, but
4083 backward compatibility forbids. */
4084 add_number
+= S_GET_VALUE (add_symbolP
);
4086 add_number
+= S_GET_VALUE (add_symbolP
) +
4087 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4093 if ((int) fixP
->fx_bit_fixP
== 13)
4095 /* This is a COBR instruction. They have only a
4096 * 13-bit displacement and are only to be used
4097 * for local branches: flag as error, don't generate
4100 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4101 "can't use COBR format with external label");
4102 fixP
->fx_addsy
= NULL
;
4106 #endif /* TC_I960 */
4107 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4108 /* 386 COFF uses a peculiar format in which the
4109 value of a common symbol is stored in the .text
4110 segment (I've checked this on SVR3.2 and SCO
4111 3.2.2) Ian Taylor <ian@cygnus.com>. */
4112 /* This is also true for 68k COFF on sysv machines
4113 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4114 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4115 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4116 if (S_IS_COMMON (add_symbolP
))
4117 add_number
+= S_GET_VALUE (add_symbolP
);
4122 } /* switch on symbol seg */
4123 } /* if not in local seg */
4124 } /* if there was a + symbol */
4128 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4129 /* This adjustment is not correct on the m88k, for which the
4130 linker does all the computation. */
4131 add_number
-= md_pcrel_from (fixP
);
4133 if (add_symbolP
== 0)
4135 fixP
->fx_addsy
= &abs_symbol
;
4136 } /* if there's an add_symbol */
4137 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4138 /* On the 386 we must adjust by the segment vaddr as well.
4141 I changed the i960 to work this way as well. This is
4142 compatible with the current GNU linker behaviour. I do
4143 not know what other i960 COFF assemblers do. This is not
4144 a common case: normally, only assembler code will contain
4145 a PC relative reloc, and only branches which do not
4146 originate in the .text section will have a non-zero
4149 I changed the m68k to work this way as well. This will
4150 break existing PC relative relocs from sections which do
4151 not start at address 0, but it will make ld -r work.
4152 Ian Taylor, 4 Oct 96. */
4154 add_number
-= segP
->scnhdr
.s_vaddr
;
4158 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4161 /* The m88k uses the offset field of the reloc to get around
4164 && ((add_number
& ~0xFF)
4165 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4166 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4167 || (add_number
& 0x80) == 0))
4169 && ((add_number
& ~0xFFFF)
4170 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4171 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4172 || (add_number
& 0x8000) == 0)))
4174 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4175 "Value of %ld too large for field of %d bytes at 0x%lx",
4176 (long) add_number
, size
,
4177 (unsigned long) (fragP
->fr_address
+ where
));
4180 #ifdef WARN_SIGNED_OVERFLOW_WORD
4181 /* Warn if a .word value is too large when treated as a
4182 signed number. We already know it is not too negative.
4183 This is to catch over-large switches generated by gcc on
4185 if (!flag_signed_overflow_ok
4187 && add_number
> 0x7fff)
4188 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4189 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4191 (unsigned long) (fragP
->fr_address
+ where
));
4193 } /* not a bit fix */
4194 /* Once this fix has been applied, we don't have to output
4195 anything nothing more need be done. */
4196 #ifdef MD_APPLY_FIX3
4197 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4199 md_apply_fix (fixP
, add_number
);
4201 } /* For each fixS in this segment. */
4202 } /* fixup_segment() */
4206 /* The first entry in a .stab section is special. */
4209 obj_coff_init_stab_section (seg
)
4215 unsigned int stroff
;
4217 /* Make space for this first symbol. */
4221 as_where (&file
, (unsigned int *) NULL
);
4222 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4223 strcpy (stabstr_name
, segment_info
[seg
].name
);
4224 strcat (stabstr_name
, "str");
4225 stroff
= get_stab_string_offset (file
, stabstr_name
);
4227 md_number_to_chars (p
, stroff
, 4);
4230 /* Fill in the counts in the first entry in a .stab section. */
4233 adjust_stab_section(abfd
, seg
)
4237 segT stabstrseg
= SEG_UNKNOWN
;
4238 const char *secname
, *name2
;
4241 int i
, strsz
= 0, nsyms
;
4242 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4244 /* Look for the associated string table section. */
4246 secname
= segment_info
[seg
].name
;
4247 name
= (char *) alloca (strlen (secname
) + 4);
4248 strcpy (name
, secname
);
4249 strcat (name
, "str");
4251 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4253 name2
= segment_info
[i
].name
;
4254 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4261 /* If we found the section, get its size. */
4262 if (stabstrseg
!= SEG_UNKNOWN
)
4263 strsz
= size_section (abfd
, stabstrseg
);
4265 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4267 /* Look for the first frag of sufficient size for the initial stab
4268 symbol, and collect a pointer to it. */
4269 while (frag
&& frag
->fr_fix
< 12)
4270 frag
= frag
->fr_next
;
4272 p
= frag
->fr_literal
;
4275 /* Write in the number of stab symbols and the size of the string
4277 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4278 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4281 #endif /* not BFD_ASSEMBLER */
4283 const pseudo_typeS obj_pseudo_table
[] =
4285 {"def", obj_coff_def
, 0},
4286 {"dim", obj_coff_dim
, 0},
4287 {"endef", obj_coff_endef
, 0},
4288 {"line", obj_coff_line
, 0},
4289 {"ln", obj_coff_ln
, 0},
4290 {"appline", obj_coff_ln
, 1},
4291 {"scl", obj_coff_scl
, 0},
4292 {"size", obj_coff_size
, 0},
4293 {"tag", obj_coff_tag
, 0},
4294 {"type", obj_coff_type
, 0},
4295 {"val", obj_coff_val
, 0},
4296 {"section", obj_coff_section
, 0},
4297 {"sect", obj_coff_section
, 0},
4298 /* FIXME: We ignore the MRI short attribute. */
4299 {"section.s", obj_coff_section
, 0},
4300 {"sect.s", obj_coff_section
, 0},
4301 #ifndef BFD_ASSEMBLER
4302 {"use", obj_coff_section
, 0},
4303 {"text", obj_coff_text
, 0},
4304 {"data", obj_coff_data
, 0},
4305 {"bss", obj_coff_bss
, 0},
4306 {"lcomm", obj_coff_lcomm
, 0},
4307 {"ident", obj_coff_ident
, 0},
4309 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4310 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4312 {"version", s_ignore
, 0},
4313 {"ABORT", s_abort
, 0},
4315 /* The m88k uses sdef instead of def. */
4316 {"sdef", obj_coff_def
, 0},
4318 {NULL
} /* end sentinel */
4319 }; /* obj_pseudo_table */
4321 #ifdef BFD_ASSEMBLER
4323 /* Support for a COFF emulation. */
4328 pop_insert (obj_pseudo_table
);
4332 coff_sec_sym_ok_for_reloc (sec
)
4344 const struct format_ops coff_format_ops
=
4346 bfd_target_coff_flavour
,
4356 obj_generate_asm_lineno
,
4365 coff_sec_sym_ok_for_reloc
,
4372 coff_obj_read_begin_hook
,
4373 coff_obj_symbol_new_hook
,