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
;
1509 /* calculate the size of the frag chain and fill in the section header
1510 to contain all of it, also fill in the addr of the sections */
1512 size_section (abfd
, idx
)
1517 unsigned int size
= 0;
1518 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1521 size
= frag
->fr_address
;
1522 if (frag
->fr_address
!= size
)
1524 fprintf (stderr
, "Out of step\n");
1525 size
= frag
->fr_address
;
1528 switch (frag
->fr_type
)
1530 #ifdef TC_COFF_SIZEMACHDEP
1531 case rs_machine_dependent
:
1532 size
+= TC_COFF_SIZEMACHDEP (frag
);
1536 assert (frag
->fr_symbol
== 0);
1539 size
+= frag
->fr_fix
;
1540 size
+= frag
->fr_offset
* frag
->fr_var
;
1547 size
+= frag
->fr_fix
;
1548 off
= relax_align (size
, frag
->fr_offset
);
1549 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1555 BAD_CASE (frag
->fr_type
);
1558 frag
= frag
->fr_next
;
1560 segment_info
[idx
].scnhdr
.s_size
= size
;
1566 count_entries_in_chain (idx
)
1569 unsigned int nrelocs
;
1572 /* Count the relocations */
1573 fixup_ptr
= segment_info
[idx
].fix_root
;
1575 while (fixup_ptr
!= (fixS
*) NULL
)
1577 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1580 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1589 fixup_ptr
= fixup_ptr
->fx_next
;
1596 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1598 /* AUX's ld expects relocations to be sorted */
1600 compare_external_relocs (x
, y
)
1604 struct external_reloc
*a
= (struct external_reloc
*) x
;
1605 struct external_reloc
*b
= (struct external_reloc
*) y
;
1606 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1607 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1608 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1613 /* output all the relocations for a section */
1615 do_relocs_for (abfd
, h
, file_cursor
)
1618 unsigned long *file_cursor
;
1620 unsigned int nrelocs
;
1622 unsigned long reloc_start
= *file_cursor
;
1624 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1626 if (segment_info
[idx
].scnhdr
.s_name
[0])
1628 struct external_reloc
*ext_ptr
;
1629 struct external_reloc
*external_reloc_vec
;
1630 unsigned int external_reloc_size
;
1631 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1632 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1633 nrelocs
= count_entries_in_chain (idx
);
1636 /* Bypass this stuff if no relocs. This also incidentally
1637 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1639 external_reloc_size
= nrelocs
* RELSZ
;
1640 external_reloc_vec
=
1641 (struct external_reloc
*) malloc (external_reloc_size
);
1643 ext_ptr
= external_reloc_vec
;
1645 /* Fill in the internal coff style reloc struct from the
1646 internal fix list. */
1649 struct internal_reloc intr
;
1651 /* Only output some of the relocations */
1652 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1654 #ifdef TC_RELOC_MANGLE
1655 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1660 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1662 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1664 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1666 #ifdef TC_KEEP_FX_OFFSET
1667 intr
.r_offset
= fix_ptr
->fx_offset
;
1672 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1673 && (! S_IS_DEFINED (symbol_ptr
)
1674 || S_IS_COMMON (symbol_ptr
)))
1678 /* We must avoid looping, as that can occur
1679 with a badly written program. */
1680 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1681 if (n
== symbol_ptr
)
1686 /* Turn the segment of the symbol into an offset. */
1689 resolve_symbol_value (symbol_ptr
);
1690 if (! symbol_ptr
->sy_resolved
)
1695 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1696 as_bad_where (file
, line
,
1697 "unresolved relocation");
1699 as_bad ("bad relocation: symbol `%s' not in symbol table",
1700 S_GET_NAME (symbol_ptr
));
1702 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1705 intr
.r_symndx
= dot
->sy_number
;
1709 intr
.r_symndx
= symbol_ptr
->sy_number
;
1719 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1722 #if defined(TC_A29K)
1724 /* The 29k has a special kludge for the high 16 bit
1725 reloc. Two relocations are emited, R_IHIHALF,
1726 and R_IHCONST. The second one doesn't contain a
1727 symbol, but uses the value for offset. */
1729 if (intr
.r_type
== R_IHIHALF
)
1731 /* now emit the second bit */
1732 intr
.r_type
= R_IHCONST
;
1733 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1734 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1740 fix_ptr
= fix_ptr
->fx_next
;
1744 /* Sort the reloc table */
1745 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1746 sizeof (struct external_reloc
), compare_external_relocs
);
1749 /* Write out the reloc table */
1750 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1752 free (external_reloc_vec
);
1754 /* Fill in section header info. */
1755 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1756 *file_cursor
+= external_reloc_size
;
1757 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1762 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1766 /* Set relocation_size field in file headers */
1767 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1771 /* run through a frag chain and write out the data to go with it, fill
1772 in the scnhdrs with the info on the file postions
1775 fill_section (abfd
, h
, file_cursor
)
1778 unsigned long *file_cursor
;
1782 unsigned int paddr
= 0;
1784 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1786 unsigned int offset
= 0;
1787 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1793 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1800 buffer
= xmalloc (s
->s_size
);
1801 s
->s_scnptr
= *file_cursor
;
1803 know (s
->s_paddr
== paddr
);
1805 if (strcmp (s
->s_name
, ".text") == 0)
1806 s
->s_flags
|= STYP_TEXT
;
1807 else if (strcmp (s
->s_name
, ".data") == 0)
1808 s
->s_flags
|= STYP_DATA
;
1809 else if (strcmp (s
->s_name
, ".bss") == 0)
1812 s
->s_flags
|= STYP_BSS
;
1814 /* @@ Should make the i386 and a29k coff targets define
1815 COFF_NOLOAD_PROBLEM, and have only one test here. */
1818 #ifndef COFF_NOLOAD_PROBLEM
1819 /* Apparently the SVR3 linker (and exec syscall) and UDI
1820 mondfe progrem are confused by noload sections. */
1821 s
->s_flags
|= STYP_NOLOAD
;
1826 else if (strcmp (s
->s_name
, ".lit") == 0)
1827 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1828 else if (strcmp (s
->s_name
, ".init") == 0)
1829 s
->s_flags
|= STYP_TEXT
;
1830 else if (strcmp (s
->s_name
, ".fini") == 0)
1831 s
->s_flags
|= STYP_TEXT
;
1832 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1833 s
->s_flags
|= STYP_INFO
;
1837 unsigned int fill_size
;
1838 switch (frag
->fr_type
)
1840 case rs_machine_dependent
:
1843 memcpy (buffer
+ frag
->fr_address
,
1845 (unsigned int) frag
->fr_fix
);
1846 offset
+= frag
->fr_fix
;
1851 assert (frag
->fr_symbol
== 0);
1858 memcpy (buffer
+ frag
->fr_address
,
1860 (unsigned int) frag
->fr_fix
);
1861 offset
+= frag
->fr_fix
;
1864 fill_size
= frag
->fr_var
;
1865 if (fill_size
&& frag
->fr_offset
> 0)
1868 unsigned int off
= frag
->fr_fix
;
1869 for (count
= frag
->fr_offset
; count
; count
--)
1871 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1873 memcpy (buffer
+ frag
->fr_address
+ off
,
1874 frag
->fr_literal
+ frag
->fr_fix
,
1877 offset
+= fill_size
;
1882 case rs_broken_word
:
1887 frag
= frag
->fr_next
;
1892 if (s
->s_scnptr
!= 0)
1894 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1895 *file_cursor
+= s
->s_size
;
1904 /* Coff file generation & utilities */
1907 coff_header_append (abfd
, h
)
1915 bfd_seek (abfd
, 0, 0);
1917 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1918 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1919 H_SET_VERSION_STAMP (h
, 0);
1920 H_SET_ENTRY_POINT (h
, 0);
1921 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1922 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1923 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1925 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1926 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1927 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1929 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1931 bfd_write (buffer
, i
, 1, abfd
);
1932 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1934 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1936 #ifdef COFF_LONG_SECTION_NAMES
1937 unsigned long string_size
= 4;
1940 if (segment_info
[i
].scnhdr
.s_name
[0])
1944 #ifdef COFF_LONG_SECTION_NAMES
1945 /* Support long section names as found in PE. This code
1946 must coordinate with that in write_object_file and
1948 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1950 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1951 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1952 string_size
+= strlen (segment_info
[i
].name
) + 1;
1956 size
= bfd_coff_swap_scnhdr_out (abfd
,
1957 &(segment_info
[i
].scnhdr
),
1960 as_bad ("bfd_coff_swap_scnhdr_out failed");
1961 bfd_write (buffer
, size
, 1, abfd
);
1968 symbol_to_chars (abfd
, where
, symbolP
)
1973 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1977 /* Turn any symbols with register attributes into abs symbols */
1978 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1980 S_SET_SEGMENT (symbolP
, absolute_section
);
1982 /* At the same time, relocate all symbols to their output value */
1984 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1985 + S_GET_VALUE (symbolP
));
1987 S_SET_VALUE (symbolP
, val
);
1989 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1991 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1994 for (i
= 0; i
< numaux
; i
++)
1996 where
+= bfd_coff_swap_aux_out (abfd
,
1997 &symbolP
->sy_symbol
.ost_auxent
[i
],
1998 S_GET_DATA_TYPE (symbolP
),
1999 S_GET_STORAGE_CLASS (symbolP
),
2007 coff_obj_symbol_new_hook (symbolP
)
2010 char underscore
= 0; /* Symbol has leading _ */
2012 /* Effective symbol */
2013 /* Store the pointer in the offset. */
2014 S_SET_ZEROES (symbolP
, 0L);
2015 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2016 S_SET_STORAGE_CLASS (symbolP
, 0);
2017 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2018 /* Additional information */
2019 symbolP
->sy_symbol
.ost_flags
= 0;
2020 /* Auxiliary entries */
2021 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2023 if (S_IS_STRING (symbolP
))
2024 SF_SET_STRING (symbolP
);
2025 if (!underscore
&& S_IS_LOCAL (symbolP
))
2026 SF_SET_LOCAL (symbolP
);
2030 * Handle .ln directives.
2034 obj_coff_ln (appline
)
2039 if (! appline
&& def_symbol_in_progress
!= NULL
)
2041 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2042 demand_empty_rest_of_line ();
2044 } /* wrong context */
2046 l
= get_absolute_expression ();
2047 c_line_new (0, frag_now_fix (), l
, frag_now
);
2050 new_logical_line ((char *) NULL
, l
- 1);
2060 listing_source_line ((unsigned int) l
);
2065 demand_empty_rest_of_line ();
2071 * Handle .def directives.
2073 * One might ask : why can't we symbol_new if the symbol does not
2074 * already exist and fill it with debug information. Because of
2075 * the C_EFCN special symbol. It would clobber the value of the
2076 * function symbol before we have a chance to notice that it is
2077 * a C_EFCN. And a second reason is that the code is more clear this
2078 * way. (at least I think it is :-).
2082 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2083 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2084 *input_line_pointer == '\t') \
2085 input_line_pointer++;
2091 char name_end
; /* Char after the end of name */
2092 char *symbol_name
; /* Name of the debug symbol */
2093 char *symbol_name_copy
; /* Temporary copy of the name */
2094 unsigned int symbol_name_length
;
2096 if (def_symbol_in_progress
!= NULL
)
2098 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2099 demand_empty_rest_of_line ();
2101 } /* if not inside .def/.endef */
2103 SKIP_WHITESPACES ();
2105 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2106 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2108 symbol_name
= input_line_pointer
;
2109 name_end
= get_symbol_end ();
2110 symbol_name_length
= strlen (symbol_name
);
2111 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2112 strcpy (symbol_name_copy
, symbol_name
);
2113 #ifdef tc_canonicalize_symbol_name
2114 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2117 /* Initialize the new symbol */
2118 #ifdef STRIP_UNDERSCORE
2119 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2120 ? symbol_name_copy
+ 1
2121 : symbol_name_copy
));
2122 #else /* STRIP_UNDERSCORE */
2123 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2124 #endif /* STRIP_UNDERSCORE */
2125 /* free(symbol_name_copy); */
2126 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2127 def_symbol_in_progress
->sy_number
= ~0;
2128 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2129 S_SET_VALUE (def_symbol_in_progress
, 0);
2131 if (S_IS_STRING (def_symbol_in_progress
))
2132 SF_SET_STRING (def_symbol_in_progress
);
2134 *input_line_pointer
= name_end
;
2136 demand_empty_rest_of_line ();
2139 unsigned int dim_index
;
2143 obj_coff_endef (ignore
)
2146 symbolS
*symbolP
= 0;
2147 /* DIM BUG FIX sac@cygnus.com */
2149 if (def_symbol_in_progress
== NULL
)
2151 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2152 demand_empty_rest_of_line ();
2154 } /* if not inside .def/.endef */
2156 /* Set the section number according to storage class. */
2157 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2162 SF_SET_TAG (def_symbol_in_progress
);
2163 /* intentional fallthrough */
2166 SF_SET_DEBUG (def_symbol_in_progress
);
2167 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2171 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2172 /* intentional fallthrough */
2174 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2175 /* intentional fallthrough */
2177 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2179 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2181 if (function_lineoff
< 0)
2183 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2184 } /* missing function symbol */
2185 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2187 SF_SET_PROCESS (last_line_symbol
);
2188 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2189 SF_SET_PROCESS (def_symbol_in_progress
);
2190 function_lineoff
= -1;
2192 /* Value is always set to . */
2193 def_symbol_in_progress
->sy_frag
= frag_now
;
2194 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2199 #endif /* C_AUTOARG */
2209 SF_SET_DEBUG (def_symbol_in_progress
);
2210 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2216 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2222 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2224 } /* switch on storage class */
2226 /* Now that we have built a debug symbol, try to find if we should
2227 merge with an existing symbol or not. If a symbol is C_EFCN or
2228 absolute_section or untagged SEG_DEBUG it never merges. We also
2229 don't merge labels, which are in a different namespace, nor
2230 symbols which have not yet been defined since they are typically
2231 unique, nor do we merge tags with non-tags. */
2233 /* Two cases for functions. Either debug followed by definition or
2234 definition followed by debug. For definition first, we will
2235 merge the debug symbol into the definition. For debug first, the
2236 lineno entry MUST point to the definition function or else it
2237 will point off into space when crawl_symbols() merges the debug
2238 symbol into the real symbol. Therefor, let's presume the debug
2239 symbol is a real function reference. */
2241 /* FIXME-SOON If for some reason the definition label/symbol is
2242 never seen, this will probably leave an undefined symbol at link
2245 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2246 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2247 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2248 && !SF_GET_TAG (def_symbol_in_progress
))
2249 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2250 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2251 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2252 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2254 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2259 /* This symbol already exists, merge the newly created symbol
2260 into the old one. This is not mandatory. The linker can
2261 handle duplicate symbols correctly. But I guess that it save
2262 a *lot* of space if the assembly file defines a lot of
2265 /* The debug entry (def_symbol_in_progress) is merged into the
2266 previous definition. */
2268 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2269 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2270 def_symbol_in_progress
= symbolP
;
2272 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2273 || SF_GET_TAG (def_symbol_in_progress
)
2274 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2276 /* For functions, and tags, and static symbols, the symbol
2277 *must* be where the debug symbol appears. Move the
2278 existing symbol to the current place. */
2279 /* If it already is at the end of the symbol list, do nothing */
2280 if (def_symbol_in_progress
!= symbol_lastP
)
2282 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2284 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2285 &symbol_rootP
, &symbol_lastP
);
2286 } /* if not already in place */
2288 } /* normal or mergable */
2290 if (SF_GET_TAG (def_symbol_in_progress
))
2294 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2296 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2297 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2298 def_symbol_in_progress
);
2301 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2303 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2305 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2307 SF_SET_PROCESS (def_symbol_in_progress
);
2309 if (symbolP
== NULL
)
2311 /* That is, if this is the first time we've seen the
2313 symbol_table_insert (def_symbol_in_progress
);
2314 } /* definition follows debug */
2315 } /* Create the line number entry pointing to the function being defined */
2317 def_symbol_in_progress
= NULL
;
2318 demand_empty_rest_of_line ();
2322 obj_coff_dim (ignore
)
2327 if (def_symbol_in_progress
== NULL
)
2329 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2330 demand_empty_rest_of_line ();
2332 } /* if not inside .def/.endef */
2334 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2336 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2338 SKIP_WHITESPACES ();
2339 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2340 get_absolute_expression ());
2342 switch (*input_line_pointer
)
2345 input_line_pointer
++;
2349 as_warn ("badly formed .dim directive ignored");
2350 /* intentional fallthrough */
2358 demand_empty_rest_of_line ();
2362 obj_coff_line (ignore
)
2368 if (def_symbol_in_progress
== NULL
)
2374 name
= S_GET_NAME (def_symbol_in_progress
);
2375 this_base
= get_absolute_expression ();
2377 /* Only .bf symbols indicate the use of a new base line number; the
2378 line numbers associated with .ef, .bb, .eb are relative to the
2379 start of the containing function. */
2380 if (!strcmp (".bf", name
))
2382 #if 0 /* XXX Can we ever have line numbers going backwards? */
2383 if (this_base
> line_base
)
2386 line_base
= this_base
;
2394 listing_source_line ((unsigned int) line_base
);
2400 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2401 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2403 demand_empty_rest_of_line ();
2407 obj_coff_size (ignore
)
2410 if (def_symbol_in_progress
== NULL
)
2412 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2413 demand_empty_rest_of_line ();
2415 } /* if not inside .def/.endef */
2417 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2418 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2419 demand_empty_rest_of_line ();
2423 obj_coff_scl (ignore
)
2426 if (def_symbol_in_progress
== NULL
)
2428 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2429 demand_empty_rest_of_line ();
2431 } /* if not inside .def/.endef */
2433 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2434 demand_empty_rest_of_line ();
2438 obj_coff_tag (ignore
)
2444 if (def_symbol_in_progress
== NULL
)
2446 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2447 demand_empty_rest_of_line ();
2451 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2452 symbol_name
= input_line_pointer
;
2453 name_end
= get_symbol_end ();
2454 #ifdef tc_canonicalize_symbol_name
2455 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2458 /* Assume that the symbol referred to by .tag is always defined.
2459 This was a bad assumption. I've added find_or_make. xoxorich. */
2460 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2461 (long) tag_find_or_make (symbol_name
));
2462 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2464 as_warn ("tag not found for .tag %s", symbol_name
);
2467 SF_SET_TAGGED (def_symbol_in_progress
);
2468 *input_line_pointer
= name_end
;
2470 demand_empty_rest_of_line ();
2474 obj_coff_type (ignore
)
2477 if (def_symbol_in_progress
== NULL
)
2479 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2480 demand_empty_rest_of_line ();
2482 } /* if not inside .def/.endef */
2484 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2486 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2487 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2489 SF_SET_FUNCTION (def_symbol_in_progress
);
2490 } /* is a function */
2492 demand_empty_rest_of_line ();
2496 obj_coff_val (ignore
)
2499 if (def_symbol_in_progress
== NULL
)
2501 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2502 demand_empty_rest_of_line ();
2504 } /* if not inside .def/.endef */
2506 if (is_name_beginner (*input_line_pointer
))
2508 char *symbol_name
= input_line_pointer
;
2509 char name_end
= get_symbol_end ();
2511 #ifdef tc_canonicalize_symbol_name
2512 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2515 if (!strcmp (symbol_name
, "."))
2517 def_symbol_in_progress
->sy_frag
= frag_now
;
2518 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2519 /* If the .val is != from the .def (e.g. statics) */
2521 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2523 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2524 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2525 symbol_find_or_make (symbol_name
);
2526 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2527 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2529 /* If the segment is undefined when the forward reference is
2530 resolved, then copy the segment id from the forward
2532 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2534 /* FIXME: gcc can generate address expressions
2535 here in unusual cases (search for "obscure"
2536 in sdbout.c). We just ignore the offset
2537 here, thus generating incorrect debugging
2538 information. We ignore the rest of the
2541 /* Otherwise, it is the name of a non debug symbol and
2542 its value will be calculated later. */
2543 *input_line_pointer
= name_end
;
2545 /* FIXME: this is to avoid an error message in the
2546 FIXME case mentioned just above. */
2547 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2548 ++input_line_pointer
;
2552 S_SET_VALUE (def_symbol_in_progress
,
2553 (valueT
) get_absolute_expression ());
2554 } /* if symbol based */
2556 demand_empty_rest_of_line ();
2561 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2562 read.c, which then calls this object file format specific routine. */
2565 obj_coff_pe_handle_link_once (type
)
2566 enum linkonce_type type
;
2568 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2570 /* We store the type in the seg_info structure, and use it to set up
2571 the auxiliary entry for the section symbol in c_section_symbol. */
2572 seg_info (now_seg
)->linkonce
= type
;
2578 coff_obj_read_begin_hook ()
2580 /* These had better be the same. Usually 18 bytes. */
2582 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2583 know (SYMESZ
== AUXESZ
);
2588 /* This function runs through the symbol table and puts all the
2589 externals onto another chain */
2591 /* The chain of globals. */
2592 symbolS
*symbol_globalP
;
2593 symbolS
*symbol_global_lastP
;
2595 /* The chain of externals */
2596 symbolS
*symbol_externP
;
2597 symbolS
*symbol_extern_lastP
;
2600 symbolS
*last_functionP
;
2601 static symbolS
*last_bfP
;
2608 unsigned int symbol_number
= 0;
2609 unsigned int last_file_symno
= 0;
2611 struct filename_list
*filename_list_scan
= filename_list_head
;
2613 for (symbolP
= symbol_rootP
;
2615 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2617 if (symbolP
->sy_mri_common
)
2619 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2620 as_bad ("%s: global symbols not supported in common sections",
2621 S_GET_NAME (symbolP
));
2622 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2626 if (!SF_GET_DEBUG (symbolP
))
2628 /* Debug symbols do not need all this rubbish */
2629 symbolS
*real_symbolP
;
2631 /* L* and C_EFCN symbols never merge. */
2632 if (!SF_GET_LOCAL (symbolP
)
2633 && !SF_GET_STATICS (symbolP
)
2634 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2635 && symbolP
->sy_value
.X_op
== O_constant
2636 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2637 && real_symbolP
!= symbolP
)
2639 /* FIXME-SOON: where do dups come from?
2640 Maybe tag references before definitions? xoxorich. */
2641 /* Move the debug data from the debug symbol to the
2642 real symbol. Do NOT do the oposite (i.e. move from
2643 real symbol to debug symbol and remove real symbol from the
2644 list.) Because some pointers refer to the real symbol
2645 whereas no pointers refer to the debug symbol. */
2646 c_symbol_merge (symbolP
, real_symbolP
);
2647 /* Replace the current symbol by the real one */
2648 /* The symbols will never be the last or the first
2649 because : 1st symbol is .file and 3 last symbols are
2650 .text, .data, .bss */
2651 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2652 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2653 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2654 symbolP
= real_symbolP
;
2655 } /* if not local but dup'd */
2657 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2659 S_SET_SEGMENT (symbolP
, SEG_E0
);
2660 } /* push data into text */
2662 resolve_symbol_value (symbolP
);
2664 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2666 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2668 S_SET_EXTERNAL (symbolP
);
2670 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2672 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2676 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2680 /* Mainly to speed up if not -g */
2681 if (SF_GET_PROCESS (symbolP
))
2683 /* Handle the nested blocks auxiliary info. */
2684 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2686 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2687 stack_push (block_stack
, (char *) &symbolP
);
2690 register symbolS
*begin_symbolP
;
2691 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2692 if (begin_symbolP
== (symbolS
*) 0)
2693 as_warn ("mismatched .eb");
2695 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2698 /* If we are able to identify the type of a function, and we
2699 are out of a function (last_functionP == 0) then, the
2700 function symbol will be associated with an auxiliary
2702 if (last_functionP
== (symbolS
*) 0 &&
2703 SF_GET_FUNCTION (symbolP
))
2705 last_functionP
= symbolP
;
2707 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2709 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2710 } /* make it at least 1 */
2712 /* Clobber possible stale .dim information. */
2714 /* Iffed out by steve - this fries the lnnoptr info too */
2715 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2716 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2719 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2721 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2723 if (last_bfP
!= NULL
)
2724 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2728 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2730 /* I don't even know if this is needed for sdb. But
2731 the standard assembler generates it, so... */
2732 if (last_functionP
== (symbolS
*) 0)
2733 as_fatal ("C_EFCN symbol out of scope");
2734 SA_SET_SYM_FSIZE (last_functionP
,
2735 (long) (S_GET_VALUE (symbolP
) -
2736 S_GET_VALUE (last_functionP
)));
2737 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2738 last_functionP
= (symbolS
*) 0;
2742 else if (SF_GET_TAG (symbolP
))
2744 /* First descriptor of a structure must point to
2745 the first slot after the structure description. */
2746 last_tagP
= symbolP
;
2749 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2751 /* +2 take in account the current symbol */
2752 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2754 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2756 /* If the filename was too long to fit in the
2757 auxent, put it in the string table */
2758 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2759 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2761 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2762 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2763 filename_list_scan
= filename_list_scan
->next
;
2765 if (S_GET_VALUE (symbolP
))
2767 S_SET_VALUE (symbolP
, last_file_symno
);
2768 last_file_symno
= symbol_number
;
2769 } /* no one points at the first .file symbol */
2770 } /* if debug or tag or eos or file */
2772 #ifdef tc_frob_coff_symbol
2773 tc_frob_coff_symbol (symbolP
);
2776 /* We must put the external symbols apart. The loader
2777 does not bomb if we do not. But the references in
2778 the endndx field for a .bb symbol are not corrected
2779 if an external symbol is removed between .bb and .be.
2780 I.e in the following case :
2781 [20] .bb endndx = 22
2784 ld will move the symbol 21 to the end of the list but
2785 endndx will still be 22 instead of 21. */
2788 if (SF_GET_LOCAL (symbolP
))
2790 /* remove C_EFCN and LOCAL (L...) symbols */
2791 /* next pointer remains valid */
2792 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2795 else if (symbolP
->sy_value
.X_op
== O_symbol
2796 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2798 /* Skip symbols which were equated to undefined or common
2800 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2802 else if (!S_IS_DEFINED (symbolP
)
2803 && !S_IS_DEBUG (symbolP
)
2804 && !SF_GET_STATICS (symbolP
) &&
2805 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2806 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2807 /* if external, Remove from the list */
2808 symbolS
*hold
= symbol_previous (symbolP
);
2810 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2811 symbol_clear_list_pointers (symbolP
);
2812 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2815 else if (! S_IS_DEBUG (symbolP
)
2816 && ! SF_GET_STATICS (symbolP
)
2817 && ! SF_GET_FUNCTION (symbolP
)
2818 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2820 symbolS
*hold
= symbol_previous (symbolP
);
2822 /* The O'Reilly COFF book says that defined global symbols
2823 come at the end of the symbol table, just before
2824 undefined global symbols. */
2826 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2827 symbol_clear_list_pointers (symbolP
);
2828 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2829 &symbol_global_lastP
);
2834 if (SF_GET_STRING (symbolP
))
2836 symbolP
->sy_name_offset
= string_byte_count
;
2837 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2841 symbolP
->sy_name_offset
= 0;
2842 } /* fix "long" names */
2844 symbolP
->sy_number
= symbol_number
;
2845 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2846 } /* if local symbol */
2847 } /* traverse the symbol list */
2848 return symbol_number
;
2854 glue_symbols (head
, tail
)
2858 unsigned int symbol_number
= 0;
2861 for (symbolP
= *head
; *head
!= NULL
;)
2863 symbolS
*tmp
= *head
;
2866 symbol_remove (tmp
, head
, tail
);
2867 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2870 if (SF_GET_STRING (tmp
))
2872 tmp
->sy_name_offset
= string_byte_count
;
2873 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2877 tmp
->sy_name_offset
= 0;
2878 } /* fix "long" names */
2880 tmp
->sy_number
= symbol_number
;
2881 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2882 } /* append the entire extern chain */
2884 return symbol_number
;
2890 unsigned int symbol_number
= 0;
2893 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2894 symbol_next (symbolP
))
2896 symbolP
->sy_number
= symbol_number
;
2900 if (SF_GET_TAGGED (symbolP
))
2904 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2907 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2909 return symbol_number
;
2914 crawl_symbols (h
, abfd
)
2920 /* Initialize the stack used to keep track of the matching .bb .be */
2922 block_stack
= stack_init (512, sizeof (symbolS
*));
2924 /* The symbol list should be ordered according to the following sequence
2927 * . debug entries for functions
2928 * . fake symbols for the sections, including .text .data and .bss
2930 * . undefined symbols
2931 * But this is not mandatory. The only important point is to put the
2932 * undefined symbols at the end of the list.
2935 if (symbol_rootP
== NULL
2936 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2938 c_dot_file_symbol ("fake");
2940 /* Is there a .file symbol ? If not insert one at the beginning. */
2943 * Build up static symbols for the sections, they are filled in later
2947 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2948 if (segment_info
[i
].scnhdr
.s_name
[0])
2949 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2952 /* Take all the externals out and put them into another chain */
2953 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2954 /* Take the externals and glue them onto the end.*/
2955 H_SET_SYMBOL_TABLE_SIZE (h
,
2956 (H_GET_SYMBOL_COUNT (h
)
2957 + glue_symbols (&symbol_globalP
,
2958 &symbol_global_lastP
)
2959 + glue_symbols (&symbol_externP
,
2960 &symbol_extern_lastP
)));
2962 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2963 know (symbol_globalP
== NULL
);
2964 know (symbol_global_lastP
== NULL
);
2965 know (symbol_externP
== NULL
);
2966 know (symbol_extern_lastP
== NULL
);
2970 * Find strings by crawling along symbol table chain.
2978 struct filename_list
*filename_list_scan
= filename_list_head
;
2980 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2981 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2984 #ifdef COFF_LONG_SECTION_NAMES
2985 /* Support long section names as found in PE. This code must
2986 coordinate with that in coff_header_append and write_object_file. */
2990 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2992 if (segment_info
[i
].scnhdr
.s_name
[0]
2993 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2997 size
= strlen (segment_info
[i
].name
) + 1;
2998 memcpy (where
, segment_info
[i
].name
, size
);
3003 #endif /* COFF_LONG_SECTION_NAMES */
3005 for (symbolP
= symbol_rootP
;
3007 symbolP
= symbol_next (symbolP
))
3011 if (SF_GET_STRING (symbolP
))
3013 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3014 memcpy (where
, S_GET_NAME (symbolP
), size
);
3017 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3018 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3019 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3021 size
= strlen (filename_list_scan
->filename
) + 1;
3022 memcpy (where
, filename_list_scan
->filename
, size
);
3023 filename_list_scan
= filename_list_scan
->next
;
3030 do_linenos_for (abfd
, h
, file_cursor
)
3033 unsigned long *file_cursor
;
3036 unsigned long start
= *file_cursor
;
3038 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3040 segment_info_type
*s
= segment_info
+ idx
;
3043 if (s
->scnhdr
.s_nlnno
!= 0)
3045 struct lineno_list
*line_ptr
;
3047 struct external_lineno
*buffer
=
3048 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3050 struct external_lineno
*dst
= buffer
;
3052 /* Run through the table we've built and turn it into its external
3053 form, take this chance to remove duplicates */
3055 for (line_ptr
= s
->lineno_list_head
;
3056 line_ptr
!= (struct lineno_list
*) NULL
;
3057 line_ptr
= line_ptr
->next
)
3060 if (line_ptr
->line
.l_lnno
== 0)
3062 /* Turn a pointer to a symbol into the symbols' index */
3063 line_ptr
->line
.l_addr
.l_symndx
=
3064 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3068 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3072 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3077 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3079 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3082 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3085 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3089 /* Now we run through the list of frag chains in a segment and
3090 make all the subsegment frags appear at the end of the
3091 list, as if the seg 0 was extra long */
3098 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3100 frchainS
*head
= segment_info
[i
].frchainP
;
3102 fragS
*prev_frag
= &dummy
;
3104 while (head
&& head
->frch_seg
== i
)
3106 prev_frag
->fr_next
= head
->frch_root
;
3107 prev_frag
= head
->frch_last
;
3108 head
= head
->frch_next
;
3110 prev_frag
->fr_next
= 0;
3114 unsigned long machine
;
3117 write_object_file ()
3121 struct frchain
*frchain_ptr
;
3123 object_headers headers
;
3124 unsigned long file_cursor
;
3127 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3132 as_perror ("FATAL: Can't create %s", out_file_name
);
3133 exit (EXIT_FAILURE
);
3135 bfd_set_format (abfd
, bfd_object
);
3136 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3138 string_byte_count
= 4;
3140 for (frchain_ptr
= frchain_root
;
3141 frchain_ptr
!= (struct frchain
*) NULL
;
3142 frchain_ptr
= frchain_ptr
->frch_next
)
3144 /* Run through all the sub-segments and align them up. Also
3145 close any open frags. We tack a .fill onto the end of the
3146 frag chain so that any .align's size can be worked by looking
3147 at the next frag. */
3149 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3150 #ifndef SUB_SEGMENT_ALIGN
3151 #define SUB_SEGMENT_ALIGN(SEG) 1
3155 static char nop
= NOP_OPCODE
;
3156 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, 0, alignment_done
);
3159 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3163 frag_wane (frag_now
);
3164 frag_now
->fr_fix
= 0;
3165 know (frag_now
->fr_next
== NULL
);
3172 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3174 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3177 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3179 /* Find out how big the sections are, and set the addresses. */
3181 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3185 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3186 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3188 if (segment_info
[i
].scnhdr
.s_name
[0])
3190 H_SET_NUMBER_OF_SECTIONS (&headers
,
3191 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3193 #ifdef COFF_LONG_SECTION_NAMES
3194 /* Support long section names as found in PE. This code
3195 must coordinate with that in coff_header_append and
3200 len
= strlen (segment_info
[i
].name
);
3202 string_byte_count
+= len
+ 1;
3204 #endif /* COFF_LONG_SECTION_NAMES */
3207 size
= size_section (abfd
, (unsigned int) i
);
3210 /* I think the section alignment is only used on the i960; the
3211 i960 needs it, and it should do no harm on other targets. */
3212 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3215 H_SET_TEXT_SIZE (&headers
, size
);
3216 else if (i
== SEG_E1
)
3217 H_SET_DATA_SIZE (&headers
, size
);
3218 else if (i
== SEG_E2
)
3219 H_SET_BSS_SIZE (&headers
, size
);
3222 /* Turn the gas native symbol table shape into a coff symbol table */
3223 crawl_symbols (&headers
, abfd
);
3225 if (string_byte_count
== 4)
3226 string_byte_count
= 0;
3228 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3234 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3236 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3237 fixup_segment (&segment_info
[i
], i
);
3240 /* Look for ".stab" segments and fill in their initial symbols
3242 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3244 name
= segment_info
[i
].name
;
3247 && strncmp (".stab", name
, 5) == 0
3248 && strncmp (".stabstr", name
, 8) != 0)
3249 adjust_stab_section (abfd
, i
);
3252 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3254 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3256 /* Plant the data */
3258 fill_section (abfd
, &headers
, &file_cursor
);
3260 do_relocs_for (abfd
, &headers
, &file_cursor
);
3262 do_linenos_for (abfd
, &headers
, &file_cursor
);
3264 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3265 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3266 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3268 H_SET_TIME_STAMP (&headers
, 0);
3270 #ifdef TC_COFF_SET_MACHINE
3271 TC_COFF_SET_MACHINE (&headers
);
3275 #define COFF_FLAGS 0
3278 #ifdef KEEP_RELOC_INFO
3279 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3280 COFF_FLAGS
| coff_flags
));
3282 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3283 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3284 COFF_FLAGS
| coff_flags
));
3288 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3289 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3291 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3292 w_symbols (abfd
, buffer1
, symbol_rootP
);
3293 if (string_byte_count
> 0)
3294 w_strings (buffer1
+ symtable_size
);
3295 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3299 coff_header_append (abfd
, &headers
);
3301 /* Recent changes to write need this, but where it should
3302 go is up to Ken.. */
3303 if (bfd_close_all_done (abfd
) == false)
3304 as_fatal ("Can't close %s: %s", out_file_name
,
3305 bfd_errmsg (bfd_get_error ()));
3308 extern bfd
*stdoutput
;
3315 /* Add a new segment. This is called from subseg_new via the
3316 obj_new_segment macro. */
3319 obj_coff_add_segment (name
)
3324 #ifndef COFF_LONG_SECTION_NAMES
3325 char buf
[SCNNMLEN
+ 1];
3327 strncpy (buf
, name
, SCNNMLEN
);
3328 buf
[SCNNMLEN
] = '\0';
3332 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3333 if (strcmp (name
, segment_info
[i
].name
) == 0)
3338 as_bad ("Too many new sections; can't add \"%s\"", name
);
3342 /* Add a new section. */
3343 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3344 sizeof (segment_info
[i
].scnhdr
.s_name
));
3345 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3346 segment_info
[i
].name
= xstrdup (name
);
3352 * implement the .section pseudo op:
3353 * .section name {, "flags"}
3355 * | +--- optional flags: 'b' for bss
3357 * +-- section name 'l' for lib
3361 * 'd' (apparently m88k for data)
3363 * 'r' for read-only data
3364 * But if the argument is not a quoted string, treat it as a
3365 * subsegment number.
3369 obj_coff_section (ignore
)
3372 /* Strip out the section name */
3373 char *section_name
, *name
;
3386 else if (type
== 'D')
3388 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3393 section_name
= input_line_pointer
;
3394 c
= get_symbol_end ();
3396 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3397 strcpy (name
, section_name
);
3399 *input_line_pointer
= c
;
3405 if (*input_line_pointer
== ',')
3407 ++input_line_pointer
;
3410 if (*input_line_pointer
!= '"')
3411 exp
= get_absolute_expression ();
3414 ++input_line_pointer
;
3415 while (*input_line_pointer
!= '"'
3416 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3418 switch (*input_line_pointer
)
3420 case 'b': flags
|= STYP_BSS
; break;
3421 case 'i': flags
|= STYP_INFO
; break;
3422 case 'l': flags
|= STYP_LIB
; break;
3423 case 'n': flags
|= STYP_NOLOAD
; break;
3424 case 'o': flags
|= STYP_OVER
; break;
3426 case 'w': flags
|= STYP_DATA
; break;
3427 case 'x': flags
|= STYP_TEXT
; break;
3428 case 'r': flags
|= STYP_LIT
; break;
3430 as_warn("unknown section attribute '%c'",
3431 *input_line_pointer
);
3434 ++input_line_pointer
;
3436 if (*input_line_pointer
== '"')
3437 ++input_line_pointer
;
3441 subseg_new (name
, (subsegT
) exp
);
3443 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3445 demand_empty_rest_of_line ();
3450 obj_coff_text (ignore
)
3453 subseg_new (".text", get_absolute_expression ());
3458 obj_coff_data (ignore
)
3461 if (flag_readonly_data_in_text
)
3462 subseg_new (".text", get_absolute_expression () + 1000);
3464 subseg_new (".data", get_absolute_expression ());
3468 obj_coff_bss (ignore
)
3471 if (*input_line_pointer
== '\n') /* .bss */
3472 subseg_new(".bss", get_absolute_expression());
3473 else /* .bss id,expr */
3478 obj_coff_ident (ignore
)
3481 segT current_seg
= now_seg
; /* save current seg */
3482 subsegT current_subseg
= now_subseg
;
3483 subseg_new (".comment", 0); /* .comment seg */
3484 stringer (1); /* read string */
3485 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3489 c_symbol_merge (debug
, normal
)
3493 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3494 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3496 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3498 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3499 } /* take the most we have */
3501 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3503 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3504 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3505 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3506 } /* Move all the auxiliary information */
3508 /* Move the debug flags. */
3509 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3510 } /* c_symbol_merge() */
3513 c_line_new (symbol
, paddr
, line_number
, frag
)
3519 struct lineno_list
*new_line
=
3520 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3522 segment_info_type
*s
= segment_info
+ now_seg
;
3523 new_line
->line
.l_lnno
= line_number
;
3525 if (line_number
== 0)
3527 last_line_symbol
= symbol
;
3528 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3532 new_line
->line
.l_addr
.l_paddr
= paddr
;
3535 new_line
->frag
= (char *) frag
;
3536 new_line
->next
= (struct lineno_list
*) NULL
;
3539 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3541 s
->lineno_list_head
= new_line
;
3545 s
->lineno_list_tail
->next
= new_line
;
3547 s
->lineno_list_tail
= new_line
;
3548 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3552 c_dot_file_symbol (filename
)
3557 symbolP
= symbol_new (".file",
3560 &zero_address_frag
);
3562 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3563 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3565 if (strlen (filename
) > FILNMLEN
)
3567 /* Filename is too long to fit into an auxent,
3568 we stick it into the string table instead. We keep
3569 a linked list of the filenames we find so we can emit
3571 struct filename_list
*f
= ((struct filename_list
*)
3572 xmalloc (sizeof (struct filename_list
)));
3574 f
->filename
= filename
;
3577 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3578 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3580 if (filename_list_tail
)
3581 filename_list_tail
->next
= f
;
3583 filename_list_head
= f
;
3584 filename_list_tail
= f
;
3588 SA_SET_FILE_FNAME (symbolP
, filename
);
3595 listing_source_file (filename
);
3601 SF_SET_DEBUG (symbolP
);
3602 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3604 previous_file_symbol
= symbolP
;
3606 /* Make sure that the symbol is first on the symbol chain */
3607 if (symbol_rootP
!= symbolP
)
3609 if (symbolP
== symbol_lastP
)
3611 symbol_lastP
= symbol_lastP
->sy_previous
;
3612 } /* if it was the last thing on the list */
3614 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3615 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3616 symbol_rootP
= symbolP
;
3617 } /* if not first on the list */
3619 } /* c_dot_file_symbol() */
3622 * Build a 'section static' symbol.
3626 c_section_symbol (name
, idx
)
3632 symbolP
= symbol_new (name
, idx
,
3634 &zero_address_frag
);
3636 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3637 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3639 SF_SET_STATICS (symbolP
);
3642 /* If the .linkonce pseudo-op was used for this section, we must
3643 store the information in the auxiliary entry for the section
3645 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3649 switch (segment_info
[idx
].linkonce
)
3653 case LINKONCE_DISCARD
:
3654 type
= IMAGE_COMDAT_SELECT_ANY
;
3656 case LINKONCE_ONE_ONLY
:
3657 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3659 case LINKONCE_SAME_SIZE
:
3660 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3662 case LINKONCE_SAME_CONTENTS
:
3663 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3667 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3672 } /* c_section_symbol() */
3675 w_symbols (abfd
, where
, symbol_rootP
)
3678 symbolS
* symbol_rootP
;
3683 /* First fill in those values we have only just worked out */
3684 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3686 symbolP
= segment_info
[i
].dot
;
3689 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3690 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3691 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3696 * Emit all symbols left in the symbol chain.
3698 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3700 /* Used to save the offset of the name. It is used to point
3701 to the string in memory but must be a file offset. */
3702 register char *temp
;
3704 /* We can't fix the lnnoptr field in yank_symbols with the other
3705 adjustments, because we have to wait until we know where they
3707 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3709 SA_GET_SYM_LNNOPTR (symbolP
) +=
3710 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3713 tc_coff_symbol_emit_hook (symbolP
);
3715 temp
= S_GET_NAME (symbolP
);
3716 if (SF_GET_STRING (symbolP
))
3718 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3719 S_SET_ZEROES (symbolP
, 0);
3723 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3724 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3726 where
= symbol_to_chars (abfd
, where
, symbolP
);
3727 S_SET_NAME (symbolP
, temp
);
3733 obj_coff_lcomm (ignore
)
3746 name
= input_line_pointer
;
3748 c
= get_symbol_end ();
3749 p
= input_line_pointer
;
3752 if (*input_line_pointer
!= ',')
3754 as_bad ("Expected comma after name");
3755 ignore_rest_of_line ();
3758 if (*input_line_pointer
== '\n')
3760 as_bad ("Missing size expression");
3763 input_line_pointer
++;
3764 if ((temp
= get_absolute_expression ()) < 0)
3766 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3767 ignore_rest_of_line ();
3772 symbolP
= symbol_find_or_make(name
);
3774 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3775 S_GET_VALUE(symbolP
) == 0)
3780 segT current_seg
= now_seg
; /* save current seg */
3781 subsegT current_subseg
= now_subseg
;
3783 subseg_set (SEG_E2
, 1);
3784 symbolP
->sy_frag
= frag_now
;
3785 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3788 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3789 S_SET_SEGMENT(symbolP
, SEG_E2
);
3790 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3794 as_bad("Symbol %s already defined", name
);
3796 demand_empty_rest_of_line();
3801 fixup_mdeps (frags
, h
, this_segment
)
3806 subseg_change (this_segment
, 0);
3809 switch (frags
->fr_type
)
3815 HANDLE_ALIGN (frags
);
3817 frags
->fr_type
= rs_fill
;
3819 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3822 case rs_machine_dependent
:
3823 md_convert_frag (h
, this_segment
, frags
);
3829 frags
= frags
->fr_next
;
3835 #ifndef TC_FORCE_RELOCATION
3836 #define TC_FORCE_RELOCATION(fix) 0
3840 fixup_segment (segP
, this_segment_type
)
3841 segment_info_type
* segP
;
3842 segT this_segment_type
;
3844 register fixS
* fixP
;
3845 register symbolS
*add_symbolP
;
3846 register symbolS
*sub_symbolP
;
3849 register char *place
;
3850 register long where
;
3851 register char pcrel
;
3852 register fragS
*fragP
;
3853 register segT add_symbol_segment
= absolute_section
;
3855 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3857 fragP
= fixP
->fx_frag
;
3859 where
= fixP
->fx_where
;
3860 place
= fragP
->fr_literal
+ where
;
3861 size
= fixP
->fx_size
;
3862 add_symbolP
= fixP
->fx_addsy
;
3863 sub_symbolP
= fixP
->fx_subsy
;
3864 add_number
= fixP
->fx_offset
;
3865 pcrel
= fixP
->fx_pcrel
;
3867 /* We want function-relative stabs to work on systems which
3868 may use a relaxing linker; thus we must handle the sym1-sym2
3869 fixups function-relative stabs generates.
3871 Of course, if you actually enable relaxing in the linker, the
3872 line and block scoping information is going to be incorrect
3873 in some cases. The only way to really fix this is to support
3874 a reloc involving the difference of two symbols. */
3876 && (!sub_symbolP
|| pcrel
))
3880 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3882 /* Relocation should be done via the associated 'bal' entry
3885 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3887 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3888 "No 'bal' entry point for leafproc %s",
3889 S_GET_NAME (add_symbolP
));
3892 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3896 /* Make sure the symbols have been resolved; this may not have
3897 happened if these are expression symbols. */
3898 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3899 resolve_symbol_value (add_symbolP
);
3901 if (add_symbolP
!= NULL
)
3903 /* If this fixup is against a symbol which has been equated
3904 to another symbol, convert it to the other symbol. */
3905 if (add_symbolP
->sy_value
.X_op
== O_symbol
3906 && (! S_IS_DEFINED (add_symbolP
)
3907 || S_IS_COMMON (add_symbolP
)))
3909 while (add_symbolP
->sy_value
.X_op
== O_symbol
3910 && (! S_IS_DEFINED (add_symbolP
)
3911 || S_IS_COMMON (add_symbolP
)))
3915 /* We must avoid looping, as that can occur with a
3916 badly written program. */
3917 n
= add_symbolP
->sy_value
.X_add_symbol
;
3918 if (n
== add_symbolP
)
3920 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3923 fixP
->fx_addsy
= add_symbolP
;
3924 fixP
->fx_offset
= add_number
;
3928 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3929 resolve_symbol_value (sub_symbolP
);
3931 if (add_symbolP
!= NULL
3932 && add_symbolP
->sy_mri_common
)
3934 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3935 add_number
+= S_GET_VALUE (add_symbolP
);
3936 fixP
->fx_offset
= add_number
;
3937 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3942 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3943 } /* if there is an addend */
3947 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3949 if (add_symbolP
!= NULL
)
3951 add_number
+= S_GET_VALUE (add_symbolP
);
3953 fixP
->fx_addsy
= NULL
;
3956 /* It's just -sym. */
3957 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3959 add_number
-= S_GET_VALUE (sub_symbolP
);
3966 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3967 "Negative of non-absolute symbol %s",
3968 S_GET_NAME (sub_symbolP
));
3970 add_number
-= S_GET_VALUE (sub_symbolP
);
3971 } /* not absolute */
3973 /* if sub_symbol is in the same segment that add_symbol
3974 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3976 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3977 && SEG_NORMAL (add_symbol_segment
))
3979 /* Difference of 2 symbols from same segment. Can't
3980 make difference of 2 undefineds: 'value' means
3981 something different for N_UNDF. */
3983 /* Makes no sense to use the difference of 2 arbitrary symbols
3984 as the target of a call instruction. */
3987 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3988 "callj to difference of 2 symbols");
3990 #endif /* TC_I960 */
3991 add_number
+= S_GET_VALUE (add_symbolP
) -
3992 S_GET_VALUE (sub_symbolP
);
3995 if (!TC_FORCE_RELOCATION (fixP
))
3997 fixP
->fx_addsy
= NULL
;
3998 fixP
->fx_subsy
= NULL
;
4000 #ifdef TC_M68K /* is this right? */
4008 /* Different segments in subtraction. */
4009 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4011 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4013 add_number
-= S_GET_VALUE (sub_symbolP
);
4016 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4017 #if 0 /* Okay for 68k, at least... */
4022 /* Make it pc-relative. */
4023 add_number
+= (md_pcrel_from (fixP
)
4024 - S_GET_VALUE (sub_symbolP
));
4033 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4034 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
4035 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4036 S_GET_NAME (sub_symbolP
),
4037 (long) (fragP
->fr_address
+ where
));
4040 } /* if sub_symbolP */
4044 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4047 * This fixup was made when the symbol's segment was
4048 * SEG_UNKNOWN, but it is now in the local segment.
4049 * So we know how to do the address without relocation.
4052 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4053 * in which cases it modifies *fixP as appropriate. In the case
4054 * of a 'calls', no further work is required, and *fixP has been
4055 * set up to make the rest of the code below a no-op.
4058 #endif /* TC_I960 */
4060 add_number
+= S_GET_VALUE (add_symbolP
);
4061 add_number
-= md_pcrel_from (fixP
);
4062 #if defined (TC_I386) || defined (TE_LYNX)
4063 /* On the 386 we must adjust by the segment vaddr as
4064 well. Ian Taylor. */
4065 add_number
-= segP
->scnhdr
.s_vaddr
;
4067 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4068 if (!TC_FORCE_RELOCATION (fixP
))
4070 fixP
->fx_addsy
= NULL
;
4076 switch (add_symbol_segment
)
4078 case absolute_section
:
4080 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4081 #endif /* TC_I960 */
4082 add_number
+= S_GET_VALUE (add_symbolP
);
4085 if (!TC_FORCE_RELOCATION (fixP
))
4087 fixP
->fx_addsy
= NULL
;
4094 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4095 /* This really should be handled in the linker, but
4096 backward compatibility forbids. */
4097 add_number
+= S_GET_VALUE (add_symbolP
);
4099 add_number
+= S_GET_VALUE (add_symbolP
) +
4100 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4106 if ((int) fixP
->fx_bit_fixP
== 13)
4108 /* This is a COBR instruction. They have only a
4109 * 13-bit displacement and are only to be used
4110 * for local branches: flag as error, don't generate
4113 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4114 "can't use COBR format with external label");
4115 fixP
->fx_addsy
= NULL
;
4119 #endif /* TC_I960 */
4120 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
4121 /* 386 COFF uses a peculiar format in which the
4122 value of a common symbol is stored in the .text
4123 segment (I've checked this on SVR3.2 and SCO
4124 3.2.2) Ian Taylor <ian@cygnus.com>. */
4125 if (S_IS_COMMON (add_symbolP
))
4126 add_number
+= S_GET_VALUE (add_symbolP
);
4131 } /* switch on symbol seg */
4132 } /* if not in local seg */
4133 } /* if there was a + symbol */
4137 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4138 /* This adjustment is not correct on the m88k, for which the
4139 linker does all the computation. */
4140 add_number
-= md_pcrel_from (fixP
);
4142 if (add_symbolP
== 0)
4144 fixP
->fx_addsy
= &abs_symbol
;
4145 } /* if there's an add_symbol */
4146 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4147 /* On the 386 we must adjust by the segment vaddr as well.
4150 I changed the i960 to work this way as well. This is
4151 compatible with the current GNU linker behaviour. I do
4152 not know what other i960 COFF assemblers do. This is not
4153 a common case: normally, only assembler code will contain
4154 a PC relative reloc, and only branches which do not
4155 originate in the .text section will have a non-zero
4158 I changed the m68k to work this way as well. This will
4159 break existing PC relative relocs from sections which do
4160 not start at address 0, but it will make ld -r work.
4161 Ian Taylor, 4 Oct 96. */
4163 add_number
-= segP
->scnhdr
.s_vaddr
;
4167 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4170 /* The m88k uses the offset field of the reloc to get around
4173 && ((add_number
& ~0xFF)
4174 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4175 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4176 || (add_number
& 0x80) == 0))
4178 && ((add_number
& ~0xFFFF)
4179 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4180 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4181 || (add_number
& 0x8000) == 0)))
4183 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4184 "Value of %ld too large for field of %d bytes at 0x%lx",
4185 (long) add_number
, size
,
4186 (unsigned long) (fragP
->fr_address
+ where
));
4189 #ifdef WARN_SIGNED_OVERFLOW_WORD
4190 /* Warn if a .word value is too large when treated as a
4191 signed number. We already know it is not too negative.
4192 This is to catch over-large switches generated by gcc on
4194 if (!flag_signed_overflow_ok
4196 && add_number
> 0x7fff)
4197 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4198 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4200 (unsigned long) (fragP
->fr_address
+ where
));
4202 } /* not a bit fix */
4203 /* Once this fix has been applied, we don't have to output
4204 anything nothing more need be done. */
4205 #ifdef MD_APPLY_FIX3
4206 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4208 md_apply_fix (fixP
, add_number
);
4210 } /* For each fixS in this segment. */
4211 } /* fixup_segment() */
4215 /* The first entry in a .stab section is special. */
4218 obj_coff_init_stab_section (seg
)
4224 unsigned int stroff
;
4226 /* Make space for this first symbol. */
4230 as_where (&file
, (unsigned int *) NULL
);
4231 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4232 strcpy (stabstr_name
, segment_info
[seg
].name
);
4233 strcat (stabstr_name
, "str");
4234 stroff
= get_stab_string_offset (file
, stabstr_name
);
4236 md_number_to_chars (p
, stroff
, 4);
4239 /* Fill in the counts in the first entry in a .stab section. */
4242 adjust_stab_section(abfd
, seg
)
4246 segT stabstrseg
= SEG_UNKNOWN
;
4247 const char *secname
, *name2
;
4250 int i
, strsz
= 0, nsyms
;
4251 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4253 /* Look for the associated string table section. */
4255 secname
= segment_info
[seg
].name
;
4256 name
= (char *) alloca (strlen (secname
) + 4);
4257 strcpy (name
, secname
);
4258 strcat (name
, "str");
4260 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4262 name2
= segment_info
[i
].name
;
4263 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4270 /* If we found the section, get its size. */
4271 if (stabstrseg
!= SEG_UNKNOWN
)
4272 strsz
= size_section (abfd
, stabstrseg
);
4274 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4276 /* Look for the first frag of sufficient size for the initial stab
4277 symbol, and collect a pointer to it. */
4278 while (frag
&& frag
->fr_fix
< 12)
4279 frag
= frag
->fr_next
;
4281 p
= frag
->fr_literal
;
4284 /* Write in the number of stab symbols and the size of the string
4286 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4287 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4290 #endif /* not BFD_ASSEMBLER */
4292 const pseudo_typeS obj_pseudo_table
[] =
4294 {"def", obj_coff_def
, 0},
4295 {"dim", obj_coff_dim
, 0},
4296 {"endef", obj_coff_endef
, 0},
4297 {"line", obj_coff_line
, 0},
4298 {"ln", obj_coff_ln
, 0},
4299 {"appline", obj_coff_ln
, 1},
4300 {"scl", obj_coff_scl
, 0},
4301 {"size", obj_coff_size
, 0},
4302 {"tag", obj_coff_tag
, 0},
4303 {"type", obj_coff_type
, 0},
4304 {"val", obj_coff_val
, 0},
4305 {"section", obj_coff_section
, 0},
4306 {"sect", obj_coff_section
, 0},
4307 /* FIXME: We ignore the MRI short attribute. */
4308 {"section.s", obj_coff_section
, 0},
4309 {"sect.s", obj_coff_section
, 0},
4310 #ifndef BFD_ASSEMBLER
4311 {"use", obj_coff_section
, 0},
4312 {"text", obj_coff_text
, 0},
4313 {"data", obj_coff_data
, 0},
4314 {"bss", obj_coff_bss
, 0},
4315 {"lcomm", obj_coff_lcomm
, 0},
4316 {"ident", obj_coff_ident
, 0},
4318 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4319 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4321 {"version", s_ignore
, 0},
4322 {"ABORT", s_abort
, 0},
4324 /* The m88k uses sdef instead of def. */
4325 {"sdef", obj_coff_def
, 0},
4327 {NULL
} /* end sentinel */
4328 }; /* obj_pseudo_table */
4330 #ifdef BFD_ASSEMBLER
4332 /* Support for a COFF emulation. */
4337 pop_insert (obj_pseudo_table
);
4341 coff_sec_sym_ok_for_reloc (sec
)
4353 const struct format_ops coff_format_ops
=
4355 bfd_target_coff_flavour
,
4365 obj_generate_asm_lineno
,
4374 coff_sec_sym_ok_for_reloc
,
4381 coff_obj_read_begin_hook
,
4382 coff_obj_symbol_new_hook
,