1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 const char *s_get_name
PARAMS ((symbolS
* s
));
34 static symbolS
*def_symbol_in_progress
;
40 unsigned long chunk_size
;
41 unsigned long element_size
;
44 unsigned long pointer
;
49 stack_init (chunk_size
, element_size
)
50 unsigned long chunk_size
;
51 unsigned long element_size
;
55 st
= (stack
*) malloc (sizeof (stack
));
58 st
->data
= malloc (chunk_size
);
65 st
->size
= chunk_size
;
66 st
->chunk_size
= chunk_size
;
67 st
->element_size
= element_size
;
72 /* Not currently used. */
83 stack_push (st
, element
)
87 if (st
->pointer
+ st
->element_size
>= st
->size
)
89 st
->size
+= st
->chunk_size
;
90 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
93 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
94 st
->pointer
+= st
->element_size
;
95 return st
->data
+ st
->pointer
;
102 if (st
->pointer
< st
->element_size
)
107 st
->pointer
-= st
->element_size
;
108 return st
->data
+ st
->pointer
;
112 * Maintain a list of the tagnames of the structres.
115 static struct hash_control
*tag_hash
;
120 tag_hash
= hash_new ();
124 tag_insert (name
, symbolP
)
128 const char *error_string
;
130 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
132 as_fatal ("Inserting \"%s\" into structure table failed: %s",
141 #ifdef STRIP_UNDERSCORE
144 #endif /* STRIP_UNDERSCORE */
145 return (symbolS
*) hash_find (tag_hash
, name
);
149 tag_find_or_make (name
)
154 if ((symbolP
= tag_find (name
)) == NULL
)
156 symbolP
= symbol_new (name
, undefined_section
,
157 0, &zero_address_frag
);
159 tag_insert (S_GET_NAME (symbolP
), symbolP
);
161 symbol_table_insert (symbolP
);
172 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
174 #define GET_FILENAME_STRING(X) \
175 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
179 fetch_coff_debug_section ()
181 static segT debug_section
;
185 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
187 debug_section
= s
->section
;
189 return debug_section
;
193 SA_SET_SYM_ENDNDX (sym
, val
)
197 combined_entry_type
*entry
, *p
;
199 entry
= &coffsymbol (sym
->bsym
)->native
[1];
200 p
= coffsymbol (val
->bsym
)->native
;
201 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
206 SA_SET_SYM_TAGNDX (sym
, val
)
210 combined_entry_type
*entry
, *p
;
212 entry
= &coffsymbol (sym
->bsym
)->native
[1];
213 p
= coffsymbol (val
->bsym
)->native
;
214 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
219 S_GET_DATA_TYPE (sym
)
222 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
226 S_SET_DATA_TYPE (sym
, val
)
230 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
235 S_GET_STORAGE_CLASS (sym
)
238 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
242 S_SET_STORAGE_CLASS (sym
, val
)
246 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
250 /* Merge a debug symbol containing debug information into a normal symbol. */
253 c_symbol_merge (debug
, normal
)
257 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
258 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
260 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
261 /* take the most we have */
262 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
264 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
266 /* Move all the auxiliary information. */
267 /* @@ How many fields do we want to preserve? Would it make more
268 sense to pick and choose those we want to copy? Should look
269 into this further.... [raeburn:19920512.2209EST] */
271 linenos
= coffsymbol (normal
->bsym
)->lineno
;
272 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
273 (char *) &coffsymbol (debug
->bsym
)->native
,
274 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
275 coffsymbol (normal
->bsym
)->lineno
= linenos
;
278 /* Move the debug flags. */
279 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
283 c_dot_file_symbol (filename
)
288 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
290 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
291 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
293 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
300 listing_source_file (filename
);
305 /* Make sure that the symbol is first on the symbol chain */
306 if (symbol_rootP
!= symbolP
)
308 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
309 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
310 } /* if not first on the list */
313 /* Line number handling */
316 struct line_no
*next
;
323 /* Symbol of last function, which we should hang line#s off of. */
324 static symbolS
*line_fsym
;
326 #define in_function() (line_fsym != 0)
327 #define clear_function() (line_fsym = 0)
328 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
332 coff_obj_symbol_new_hook (symbolP
)
335 char underscore
= 0; /* Symbol has leading _ */
338 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
339 char *s
= (char *) xmalloc (sz
);
341 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
343 S_SET_DATA_TYPE (symbolP
, T_NULL
);
344 S_SET_STORAGE_CLASS (symbolP
, 0);
345 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
347 if (S_IS_STRING (symbolP
))
348 SF_SET_STRING (symbolP
);
349 if (!underscore
&& S_IS_LOCAL (symbolP
))
350 SF_SET_LOCAL (symbolP
);
355 * Handle .ln directives.
358 static symbolS
*current_lineno_sym
;
359 static struct line_no
*line_nos
;
360 /* @@ Blindly assume all .ln directives will be in the .text section... */
364 add_lineno (frag
, offset
, num
)
369 struct line_no
*new_line
=
370 (struct line_no
*) xmalloc (sizeof (struct line_no
));
371 if (!current_lineno_sym
)
375 new_line
->next
= line_nos
;
376 new_line
->frag
= frag
;
377 new_line
->l
.line_number
= num
;
378 new_line
->l
.u
.offset
= offset
;
384 coff_add_linesym (sym
)
389 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
393 current_lineno_sym
= sym
;
397 obj_coff_ln (appline
)
402 if (! appline
&& def_symbol_in_progress
!= NULL
)
404 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
405 demand_empty_rest_of_line ();
409 l
= get_absolute_expression ();
412 add_lineno (frag_now
, frag_now_fix (), l
);
416 new_logical_line ((char *) NULL
, l
- 1);
425 l
+= coff_line_base
- 1;
426 listing_source_line (l
);
431 demand_empty_rest_of_line ();
437 * Handle .def directives.
439 * One might ask : why can't we symbol_new if the symbol does not
440 * already exist and fill it with debug information. Because of
441 * the C_EFCN special symbol. It would clobber the value of the
442 * function symbol before we have a chance to notice that it is
443 * a C_EFCN. And a second reason is that the code is more clear this
444 * way. (at least I think it is :-).
448 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
449 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
450 *input_line_pointer == '\t') \
451 input_line_pointer++;
457 char name_end
; /* Char after the end of name */
458 char *symbol_name
; /* Name of the debug symbol */
459 char *symbol_name_copy
; /* Temporary copy of the name */
460 unsigned int symbol_name_length
;
462 if (def_symbol_in_progress
!= NULL
)
464 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
465 demand_empty_rest_of_line ();
467 } /* if not inside .def/.endef */
471 symbol_name
= input_line_pointer
;
472 #ifdef STRIP_UNDERSCORE
473 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
475 #endif /* STRIP_UNDERSCORE */
477 name_end
= get_symbol_end ();
478 symbol_name_length
= strlen (symbol_name
);
479 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
480 strcpy (symbol_name_copy
, symbol_name
);
481 #ifdef tc_canonicalize_symbol_name
482 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
485 /* Initialize the new symbol */
486 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
487 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
488 S_SET_VALUE (def_symbol_in_progress
, 0);
490 if (S_IS_STRING (def_symbol_in_progress
))
491 SF_SET_STRING (def_symbol_in_progress
);
493 *input_line_pointer
= name_end
;
495 demand_empty_rest_of_line ();
498 unsigned int dim_index
;
501 obj_coff_endef (ignore
)
505 /* DIM BUG FIX sac@cygnus.com */
507 if (def_symbol_in_progress
== NULL
)
509 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
510 demand_empty_rest_of_line ();
512 } /* if not inside .def/.endef */
514 /* Set the section number according to storage class. */
515 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
520 SF_SET_TAG (def_symbol_in_progress
);
521 /* intentional fallthrough */
524 SF_SET_DEBUG (def_symbol_in_progress
);
525 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
529 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
530 /* intentional fallthrough */
532 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
533 /* intentional fallthrough */
537 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
539 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
540 if (name
[1] == 'b' && name
[2] == 'f')
542 if (! in_function ())
543 as_warn ("`%s' symbol without preceding function", name
);
544 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
545 /* Will need relocating */
546 SF_SET_PROCESS (def_symbol_in_progress
);
554 #endif /* C_AUTOARG */
560 SF_SET_DEBUG (def_symbol_in_progress
);
561 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
568 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
574 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
580 as_warn ("unexpected storage class %d",
581 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
583 } /* switch on storage class */
585 /* Now that we have built a debug symbol, try to find if we should
586 merge with an existing symbol or not. If a symbol is C_EFCN or
587 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
589 /* Two cases for functions. Either debug followed by definition or
590 definition followed by debug. For definition first, we will
591 merge the debug symbol into the definition. For debug first, the
592 lineno entry MUST point to the definition function or else it
593 will point off into space when obj_crawl_symbol_chain() merges
594 the debug symbol into the real symbol. Therefor, let's presume
595 the debug symbol is a real function reference. */
597 /* FIXME-SOON If for some reason the definition label/symbol is
598 never seen, this will probably leave an undefined symbol at link
601 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
602 || (!strcmp (bfd_get_section_name (stdoutput
,
603 S_GET_SEGMENT (def_symbol_in_progress
)),
605 && !SF_GET_TAG (def_symbol_in_progress
))
606 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
607 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
609 if (def_symbol_in_progress
!= symbol_lastP
)
610 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
615 /* This symbol already exists, merge the newly created symbol
616 into the old one. This is not mandatory. The linker can
617 handle duplicate symbols correctly. But I guess that it save
618 a *lot* of space if the assembly file defines a lot of
621 /* The debug entry (def_symbol_in_progress) is merged into the
622 previous definition. */
624 c_symbol_merge (def_symbol_in_progress
, symbolP
);
625 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
627 def_symbol_in_progress
= symbolP
;
629 if (SF_GET_FUNCTION (def_symbol_in_progress
)
630 || SF_GET_TAG (def_symbol_in_progress
)
631 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
633 /* For functions, and tags, and static symbols, the symbol
634 *must* be where the debug symbol appears. Move the
635 existing symbol to the current place. */
636 /* If it already is at the end of the symbol list, do nothing */
637 if (def_symbol_in_progress
!= symbol_lastP
)
639 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
640 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
645 if (SF_GET_TAG (def_symbol_in_progress
))
649 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
651 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
652 tag_insert (S_GET_NAME (def_symbol_in_progress
),
653 def_symbol_in_progress
);
656 if (SF_GET_FUNCTION (def_symbol_in_progress
))
658 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
659 set_function (def_symbol_in_progress
);
660 SF_SET_PROCESS (def_symbol_in_progress
);
664 /* That is, if this is the first time we've seen the
666 symbol_table_insert (def_symbol_in_progress
);
667 } /* definition follows debug */
668 } /* Create the line number entry pointing to the function being defined */
670 def_symbol_in_progress
= NULL
;
671 demand_empty_rest_of_line ();
675 obj_coff_dim (ignore
)
680 if (def_symbol_in_progress
== NULL
)
682 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
683 demand_empty_rest_of_line ();
685 } /* if not inside .def/.endef */
687 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
689 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
692 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
693 get_absolute_expression ());
695 switch (*input_line_pointer
)
698 input_line_pointer
++;
702 as_warn ("badly formed .dim directive ignored");
703 /* intentional fallthrough */
711 demand_empty_rest_of_line ();
715 obj_coff_line (ignore
)
720 if (def_symbol_in_progress
== NULL
)
722 /* Probably stabs-style line? */
727 this_base
= get_absolute_expression ();
728 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
729 coff_line_base
= this_base
;
731 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
732 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
734 demand_empty_rest_of_line ();
737 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
742 listing_source_line ((unsigned int) coff_line_base
);
748 obj_coff_size (ignore
)
751 if (def_symbol_in_progress
== NULL
)
753 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
754 demand_empty_rest_of_line ();
756 } /* if not inside .def/.endef */
758 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
759 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
760 demand_empty_rest_of_line ();
764 obj_coff_scl (ignore
)
767 if (def_symbol_in_progress
== NULL
)
769 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
770 demand_empty_rest_of_line ();
772 } /* if not inside .def/.endef */
774 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
775 demand_empty_rest_of_line ();
779 obj_coff_tag (ignore
)
785 if (def_symbol_in_progress
== NULL
)
787 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
788 demand_empty_rest_of_line ();
792 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
793 symbol_name
= input_line_pointer
;
794 name_end
= get_symbol_end ();
796 #ifdef tc_canonicalize_symbol_name
797 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
800 /* Assume that the symbol referred to by .tag is always defined.
801 This was a bad assumption. I've added find_or_make. xoxorich. */
802 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
803 tag_find_or_make (symbol_name
));
804 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
806 as_warn ("tag not found for .tag %s", symbol_name
);
809 SF_SET_TAGGED (def_symbol_in_progress
);
810 *input_line_pointer
= name_end
;
812 demand_empty_rest_of_line ();
816 obj_coff_type (ignore
)
819 if (def_symbol_in_progress
== NULL
)
821 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
822 demand_empty_rest_of_line ();
824 } /* if not inside .def/.endef */
826 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
828 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
829 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
831 SF_SET_FUNCTION (def_symbol_in_progress
);
832 } /* is a function */
834 demand_empty_rest_of_line ();
838 obj_coff_val (ignore
)
841 if (def_symbol_in_progress
== NULL
)
843 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
844 demand_empty_rest_of_line ();
846 } /* if not inside .def/.endef */
848 if (is_name_beginner (*input_line_pointer
))
850 char *symbol_name
= input_line_pointer
;
851 char name_end
= get_symbol_end ();
853 #ifdef tc_canonicalize_symbol_name
854 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
856 if (!strcmp (symbol_name
, "."))
858 def_symbol_in_progress
->sy_frag
= frag_now
;
859 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
860 /* If the .val is != from the .def (e.g. statics) */
862 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
864 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
865 def_symbol_in_progress
->sy_value
.X_add_symbol
=
866 symbol_find_or_make (symbol_name
);
867 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
868 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
870 /* If the segment is undefined when the forward reference is
871 resolved, then copy the segment id from the forward
873 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
875 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
876 *input_line_pointer
= name_end
;
880 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
881 } /* if symbol based */
883 demand_empty_rest_of_line ();
887 coff_obj_read_begin_hook ()
889 /* These had better be the same. Usually 18 bytes. */
891 know (sizeof (SYMENT
) == sizeof (AUXENT
));
892 know (SYMESZ
== AUXESZ
);
898 symbolS
*coff_last_function
;
899 static symbolS
*coff_last_bf
;
902 coff_frob_symbol (symp
, punt
)
906 static symbolS
*last_tagP
;
907 static stack
*block_stack
;
908 static symbolS
*set_end
;
909 symbolS
*next_set_end
= NULL
;
911 if (symp
== &abs_symbol
)
917 if (current_lineno_sym
)
918 coff_add_linesym ((symbolS
*) 0);
921 block_stack
= stack_init (512, sizeof (symbolS
*));
923 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
924 S_SET_STORAGE_CLASS (symp
, C_EXT
);
926 if (!SF_GET_DEBUG (symp
))
929 if (!SF_GET_LOCAL (symp
)
930 && !SF_GET_STATICS (symp
)
931 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
934 c_symbol_merge (symp
, real
);
937 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
939 assert (S_GET_VALUE (symp
) == 0);
940 S_SET_EXTERNAL (symp
);
942 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
944 if (S_GET_SEGMENT (symp
) == text_section
945 && symp
!= seg_info (text_section
)->sym
)
946 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
948 S_SET_STORAGE_CLASS (symp
, C_STAT
);
950 if (SF_GET_PROCESS (symp
))
952 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
954 if (!strcmp (S_GET_NAME (symp
), ".bb"))
955 stack_push (block_stack
, (char *) &symp
);
959 begin
= *(symbolS
**) stack_pop (block_stack
);
961 as_warn ("mismatched .eb");
963 next_set_end
= begin
;
966 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
968 union internal_auxent
*auxp
;
969 coff_last_function
= symp
;
970 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
971 S_SET_NUMBER_AUXILIARY (symp
, 1);
972 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
973 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
974 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
976 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
978 if (coff_last_function
== 0)
979 as_fatal ("C_EFCN symbol out of scope");
980 SA_SET_SYM_FSIZE (coff_last_function
,
981 (long) (S_GET_VALUE (symp
)
982 - S_GET_VALUE (coff_last_function
)));
983 next_set_end
= coff_last_function
;
984 coff_last_function
= 0;
987 if (S_IS_EXTERNAL (symp
))
988 S_SET_STORAGE_CLASS (symp
, C_EXT
);
989 else if (SF_GET_LOCAL (symp
))
992 if (SF_GET_FUNCTION (symp
))
993 symp
->bsym
->flags
|= BSF_FUNCTION
;
998 if (SF_GET_TAG (symp
))
1000 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1001 next_set_end
= last_tagP
;
1004 /* This is pretty horrible, but we have to set *punt correctly in
1005 order to call SA_SET_SYM_ENDNDX correctly. */
1006 if (! symp
->sy_used_in_reloc
1007 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1008 || (! S_IS_EXTERNAL (symp
)
1009 && ! symp
->sy_tc
.output
1010 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1014 if (set_end
!= (symbolS
*) NULL
1016 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1017 || (S_IS_DEFINED (symp
)
1018 && ! S_IS_COMMON (symp
)
1019 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1021 SA_SET_SYM_ENDNDX (set_end
, symp
);
1025 if (next_set_end
!= NULL
1027 set_end
= next_set_end
;
1030 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1031 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1033 if (coff_last_bf
!= NULL
)
1034 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1035 coff_last_bf
= symp
;
1038 if (coffsymbol (symp
->bsym
)->lineno
)
1041 struct line_no
*lptr
;
1044 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1045 for (i
= 0; lptr
; lptr
= lptr
->next
)
1047 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1049 /* We need i entries for line numbers, plus 1 for the first
1050 entry which BFD will override, plus 1 for the last zero
1051 entry (a marker for BFD). */
1052 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1053 coffsymbol (symp
->bsym
)->lineno
= l
;
1054 l
[i
+ 1].line_number
= 0;
1055 l
[i
+ 1].u
.sym
= NULL
;
1059 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1067 coff_adjust_section_syms (abfd
, sec
, x
)
1073 segment_info_type
*seginfo
= seg_info (sec
);
1074 int nlnno
, nrelocs
= 0;
1076 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1077 tc-ppc.c. Do not get confused by it. */
1078 if (seginfo
== NULL
)
1081 if (!strcmp (sec
->name
, ".text"))
1082 nlnno
= coff_n_line_nos
;
1086 /* @@ Hope that none of the fixups expand to more than one reloc
1088 fixS
*fixp
= seginfo
->fix_root
;
1091 fixp
= fixp
->fx_next
;
1095 if (bfd_get_section_size_before_reloc (sec
) == 0
1098 && sec
!= text_section
1099 && sec
!= data_section
1100 && sec
!= bss_section
)
1102 secsym
= section_symbol (sec
);
1103 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1104 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1110 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1114 * implement the .section pseudo op:
1115 * .section name {, "flags"}
1117 * | +--- optional flags: 'b' for bss
1119 * +-- section name 'l' for lib
1123 * 'd' (apparently m88k for data)
1125 * 'r' for read-only data
1126 * But if the argument is not a quoted string, treat it as a
1127 * subsegment number.
1131 obj_coff_section (ignore
)
1134 /* Strip out the section name */
1150 section_name
= input_line_pointer
;
1151 c
= get_symbol_end ();
1153 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1154 strcpy (name
, section_name
);
1156 *input_line_pointer
= c
;
1161 flags
= SEC_NO_FLAGS
;
1163 if (*input_line_pointer
== ',')
1165 ++input_line_pointer
;
1167 if (*input_line_pointer
!= '"')
1168 exp
= get_absolute_expression ();
1171 ++input_line_pointer
;
1172 while (*input_line_pointer
!= '"'
1173 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1175 switch (*input_line_pointer
)
1177 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1178 case 'n': flags
&=~ SEC_LOAD
; break;
1180 case 'w': flags
&=~ SEC_READONLY
; break;
1181 case 'x': flags
|= SEC_CODE
; break;
1182 case 'r': flags
|= SEC_READONLY
; break;
1184 case 'i': /* STYP_INFO */
1185 case 'l': /* STYP_LIB */
1186 case 'o': /* STYP_OVER */
1187 as_warn ("unsupported section attribute '%c'",
1188 *input_line_pointer
);
1192 as_warn("unknown section attribute '%c'",
1193 *input_line_pointer
);
1196 ++input_line_pointer
;
1198 if (*input_line_pointer
== '"')
1199 ++input_line_pointer
;
1203 sec
= subseg_new (name
, (subsegT
) exp
);
1205 if (flags
!= SEC_NO_FLAGS
)
1207 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1208 as_warn ("error setting flags for \"%s\": %s",
1209 bfd_section_name (stdoutput
, sec
),
1210 bfd_errmsg (bfd_get_error ()));
1213 demand_empty_rest_of_line ();
1217 coff_adjust_symtab ()
1219 if (symbol_rootP
== NULL
1220 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1221 c_dot_file_symbol ("fake");
1225 coff_frob_section (sec
)
1231 bfd_vma size
, n_entries
, mask
;
1233 /* The COFF back end in BFD requires that all section sizes be
1234 rounded up to multiples of the corresponding section alignments.
1235 Seems kinda silly to me, but that's the way it is. */
1236 size
= bfd_get_section_size_before_reloc (sec
);
1237 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1240 size
= (size
+ mask
) & ~mask
;
1241 bfd_set_section_size (stdoutput
, sec
, size
);
1244 /* If the section size is non-zero, the section symbol needs an aux
1245 entry associated with it, indicating the size. We don't know
1246 all the values yet; coff_frob_symbol will fill them in later. */
1248 || sec
== text_section
1249 || sec
== data_section
1250 || sec
== bss_section
)
1252 symbolS
*secsym
= section_symbol (sec
);
1254 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1255 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1256 SF_SET_STATICS (secsym
);
1257 SA_SET_SCN_SCNLEN (secsym
, size
);
1260 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1261 #ifndef STAB_SECTION_NAME
1262 #define STAB_SECTION_NAME ".stab"
1264 #ifndef STAB_STRING_SECTION_NAME
1265 #define STAB_STRING_SECTION_NAME ".stabstr"
1267 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1271 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1272 /* size is already rounded up, since other section will be listed first */
1273 size
= bfd_get_section_size_before_reloc (strsec
);
1275 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1277 /* Find first non-empty frag. It should be large enough. */
1278 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1279 while (fragp
&& fragp
->fr_fix
== 0)
1280 fragp
= fragp
->fr_next
;
1281 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1283 /* Store the values. */
1284 p
= fragp
->fr_literal
;
1285 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1286 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1290 obj_coff_init_stab_section (seg
)
1296 unsigned int stroff
;
1298 /* Make space for this first symbol. */
1302 as_where (&file
, (unsigned int *) NULL
);
1303 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1304 strcpy (stabstr_name
, seg
->name
);
1305 strcat (stabstr_name
, "str");
1306 stroff
= get_stab_string_offset (file
, stabstr_name
);
1308 md_number_to_chars (p
, stroff
, 4);
1317 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1325 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1327 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1328 (unsigned long) symbolP
,
1329 S_GET_NAME(symbolP
),
1330 (long) S_GET_DATA_TYPE(symbolP
),
1331 S_GET_STORAGE_CLASS(symbolP
),
1332 (int) S_GET_SEGMENT(symbolP
));
1338 #else /* not BFD_ASSEMBLER */
1341 /* This is needed because we include internal bfd things. */
1345 #include "libcoff.h"
1348 #include "coff/pe.h"
1351 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1352 that we can stick sections together without causing trouble. */
1354 #define NOP_OPCODE 0x00
1357 /* The zeroes if symbol name is longer than 8 chars */
1358 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1360 #define MIN(a,b) ((a) < (b)? (a) : (b))
1361 /* This vector is used to turn an internal segment into a section #
1362 suitable for insertion into a coff symbol table
1365 const short seg_N_TYPE
[] =
1366 { /* in: segT out: N_TYPE bits */
1368 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1369 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1370 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1371 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1372 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1373 C_UNDEF_SECTION
, /* SEG_GOOF */
1374 C_UNDEF_SECTION
, /* SEG_EXPR */
1375 C_DEBUG_SECTION
, /* SEG_DEBUG */
1376 C_NTV_SECTION
, /* SEG_NTV */
1377 C_PTV_SECTION
, /* SEG_PTV */
1378 C_REGISTER_SECTION
, /* SEG_REGISTER */
1381 int function_lineoff
= -1; /* Offset in line#s where the last function
1382 started (the odd entry for line #0) */
1384 /* structure used to keep the filenames which
1385 are too long around so that we can stick them
1386 into the string table */
1387 struct filename_list
1390 struct filename_list
*next
;
1393 static struct filename_list
*filename_list_head
;
1394 static struct filename_list
*filename_list_tail
;
1396 static symbolS
*last_line_symbol
;
1398 /* Add 4 to the real value to get the index and compensate the
1399 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1400 section number into a segment number
1402 static symbolS
*previous_file_symbol
;
1403 void c_symbol_merge ();
1404 static int line_base
;
1406 symbolS
*c_section_symbol ();
1409 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1410 segT this_segment_type
));
1413 static void fixup_mdeps
PARAMS ((fragS
*,
1418 static void fill_section
PARAMS ((bfd
* abfd
,
1423 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1428 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1429 symbolS
* symbol_rootP
));
1431 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1433 static void obj_coff_lcomm
PARAMS ((int));
1434 static void obj_coff_text
PARAMS ((int));
1435 static void obj_coff_data
PARAMS ((int));
1436 static void obj_coff_bss
PARAMS ((int));
1437 static void obj_coff_ident
PARAMS ((int));
1438 void obj_coff_section
PARAMS ((int));
1442 We allow more than just the standard 3 sections, infact, we allow
1443 40 sections, (though the usual three have to be there).
1445 This structure performs the mappings for us:
1455 static const seg_info_type seg_info_off_by_4
[] =
1462 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1463 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1464 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1465 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1466 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1467 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1468 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1469 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1484 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1486 static relax_addressT
1487 relax_align (address
, alignment
)
1488 relax_addressT address
;
1491 relax_addressT mask
;
1492 relax_addressT new_address
;
1494 mask
= ~((~0) << alignment
);
1495 new_address
= (address
+ mask
) & (~mask
);
1496 return (new_address
- address
);
1504 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1507 /* calculate the size of the frag chain and fill in the section header
1508 to contain all of it, also fill in the addr of the sections */
1510 size_section (abfd
, idx
)
1515 unsigned int size
= 0;
1516 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1519 size
= frag
->fr_address
;
1520 if (frag
->fr_address
!= size
)
1522 fprintf (stderr
, "Out of step\n");
1523 size
= frag
->fr_address
;
1526 switch (frag
->fr_type
)
1528 #ifdef TC_COFF_SIZEMACHDEP
1529 case rs_machine_dependent
:
1530 size
+= TC_COFF_SIZEMACHDEP (frag
);
1534 assert (frag
->fr_symbol
== 0);
1537 size
+= frag
->fr_fix
;
1538 size
+= frag
->fr_offset
* frag
->fr_var
;
1545 size
+= frag
->fr_fix
;
1546 off
= relax_align (size
, frag
->fr_offset
);
1547 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1553 BAD_CASE (frag
->fr_type
);
1556 frag
= frag
->fr_next
;
1558 segment_info
[idx
].scnhdr
.s_size
= size
;
1564 count_entries_in_chain (idx
)
1567 unsigned int nrelocs
;
1570 /* Count the relocations */
1571 fixup_ptr
= segment_info
[idx
].fix_root
;
1573 while (fixup_ptr
!= (fixS
*) NULL
)
1575 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1578 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1587 fixup_ptr
= fixup_ptr
->fx_next
;
1594 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1596 /* AUX's ld expects relocations to be sorted */
1598 compare_external_relocs (x
, y
)
1602 struct external_reloc
*a
= (struct external_reloc
*) x
;
1603 struct external_reloc
*b
= (struct external_reloc
*) y
;
1604 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1605 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1606 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1611 /* output all the relocations for a section */
1613 do_relocs_for (abfd
, h
, file_cursor
)
1616 unsigned long *file_cursor
;
1618 unsigned int nrelocs
;
1620 unsigned long reloc_start
= *file_cursor
;
1622 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1624 if (segment_info
[idx
].scnhdr
.s_name
[0])
1626 struct external_reloc
*ext_ptr
;
1627 struct external_reloc
*external_reloc_vec
;
1628 unsigned int external_reloc_size
;
1629 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1630 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1631 nrelocs
= count_entries_in_chain (idx
);
1634 /* Bypass this stuff if no relocs. This also incidentally
1635 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1637 external_reloc_size
= nrelocs
* RELSZ
;
1638 external_reloc_vec
=
1639 (struct external_reloc
*) malloc (external_reloc_size
);
1641 ext_ptr
= external_reloc_vec
;
1643 /* Fill in the internal coff style reloc struct from the
1644 internal fix list. */
1647 struct internal_reloc intr
;
1649 /* Only output some of the relocations */
1650 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1652 #ifdef TC_RELOC_MANGLE
1653 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1658 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1660 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1662 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1664 #ifdef TC_KEEP_FX_OFFSET
1665 intr
.r_offset
= fix_ptr
->fx_offset
;
1670 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1671 && (! S_IS_DEFINED (symbol_ptr
)
1672 || S_IS_COMMON (symbol_ptr
)))
1676 /* We must avoid looping, as that can occur
1677 with a badly written program. */
1678 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1679 if (n
== symbol_ptr
)
1684 /* Turn the segment of the symbol into an offset. */
1687 resolve_symbol_value (symbol_ptr
);
1688 if (! symbol_ptr
->sy_resolved
)
1693 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1694 as_bad_where (file
, line
,
1695 "unresolved relocation");
1697 as_bad ("bad relocation: symbol `%s' not in symbol table",
1698 S_GET_NAME (symbol_ptr
));
1700 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1703 intr
.r_symndx
= dot
->sy_number
;
1707 intr
.r_symndx
= symbol_ptr
->sy_number
;
1717 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1720 #if defined(TC_A29K)
1722 /* The 29k has a special kludge for the high 16 bit
1723 reloc. Two relocations are emited, R_IHIHALF,
1724 and R_IHCONST. The second one doesn't contain a
1725 symbol, but uses the value for offset. */
1727 if (intr
.r_type
== R_IHIHALF
)
1729 /* now emit the second bit */
1730 intr
.r_type
= R_IHCONST
;
1731 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1732 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1738 fix_ptr
= fix_ptr
->fx_next
;
1742 /* Sort the reloc table */
1743 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1744 sizeof (struct external_reloc
), compare_external_relocs
);
1747 /* Write out the reloc table */
1748 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1750 free (external_reloc_vec
);
1752 /* Fill in section header info. */
1753 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1754 *file_cursor
+= external_reloc_size
;
1755 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1760 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1764 /* Set relocation_size field in file headers */
1765 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1769 /* run through a frag chain and write out the data to go with it, fill
1770 in the scnhdrs with the info on the file postions
1773 fill_section (abfd
, h
, file_cursor
)
1776 unsigned long *file_cursor
;
1780 unsigned int paddr
= 0;
1782 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1784 unsigned int offset
= 0;
1785 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1791 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1798 buffer
= xmalloc (s
->s_size
);
1799 s
->s_scnptr
= *file_cursor
;
1801 know (s
->s_paddr
== paddr
);
1803 if (strcmp (s
->s_name
, ".text") == 0)
1804 s
->s_flags
|= STYP_TEXT
;
1805 else if (strcmp (s
->s_name
, ".data") == 0)
1806 s
->s_flags
|= STYP_DATA
;
1807 else if (strcmp (s
->s_name
, ".bss") == 0)
1810 s
->s_flags
|= STYP_BSS
;
1812 /* @@ Should make the i386 and a29k coff targets define
1813 COFF_NOLOAD_PROBLEM, and have only one test here. */
1816 #ifndef COFF_NOLOAD_PROBLEM
1817 /* Apparently the SVR3 linker (and exec syscall) and UDI
1818 mondfe progrem are confused by noload sections. */
1819 s
->s_flags
|= STYP_NOLOAD
;
1824 else if (strcmp (s
->s_name
, ".lit") == 0)
1825 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1826 else if (strcmp (s
->s_name
, ".init") == 0)
1827 s
->s_flags
|= STYP_TEXT
;
1828 else if (strcmp (s
->s_name
, ".fini") == 0)
1829 s
->s_flags
|= STYP_TEXT
;
1830 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1831 s
->s_flags
|= STYP_INFO
;
1835 unsigned int fill_size
;
1836 switch (frag
->fr_type
)
1838 case rs_machine_dependent
:
1841 memcpy (buffer
+ frag
->fr_address
,
1843 (unsigned int) frag
->fr_fix
);
1844 offset
+= frag
->fr_fix
;
1849 assert (frag
->fr_symbol
== 0);
1856 memcpy (buffer
+ frag
->fr_address
,
1858 (unsigned int) frag
->fr_fix
);
1859 offset
+= frag
->fr_fix
;
1862 fill_size
= frag
->fr_var
;
1863 if (fill_size
&& frag
->fr_offset
> 0)
1866 unsigned int off
= frag
->fr_fix
;
1867 for (count
= frag
->fr_offset
; count
; count
--)
1869 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1871 memcpy (buffer
+ frag
->fr_address
+ off
,
1872 frag
->fr_literal
+ frag
->fr_fix
,
1875 offset
+= fill_size
;
1880 case rs_broken_word
:
1885 frag
= frag
->fr_next
;
1890 if (s
->s_scnptr
!= 0)
1892 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1893 *file_cursor
+= s
->s_size
;
1902 /* Coff file generation & utilities */
1905 coff_header_append (abfd
, h
)
1912 #ifdef COFF_LONG_SECTION_NAMES
1913 unsigned long string_size
= 4;
1916 bfd_seek (abfd
, 0, 0);
1918 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1919 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1920 H_SET_VERSION_STAMP (h
, 0);
1921 H_SET_ENTRY_POINT (h
, 0);
1922 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1923 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1924 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1926 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1927 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1928 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1930 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1932 bfd_write (buffer
, i
, 1, abfd
);
1933 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1935 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1937 if (segment_info
[i
].scnhdr
.s_name
[0])
1941 #ifdef COFF_LONG_SECTION_NAMES
1942 /* Support long section names as found in PE. This code
1943 must coordinate with that in write_object_file and
1945 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1947 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1948 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1949 string_size
+= strlen (segment_info
[i
].name
) + 1;
1953 size
= bfd_coff_swap_scnhdr_out (abfd
,
1954 &(segment_info
[i
].scnhdr
),
1957 as_bad ("bfd_coff_swap_scnhdr_out failed");
1958 bfd_write (buffer
, size
, 1, abfd
);
1965 symbol_to_chars (abfd
, where
, symbolP
)
1970 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1974 /* Turn any symbols with register attributes into abs symbols */
1975 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1977 S_SET_SEGMENT (symbolP
, absolute_section
);
1979 /* At the same time, relocate all symbols to their output value */
1982 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1983 + S_GET_VALUE (symbolP
));
1985 val
= S_GET_VALUE (symbolP
);
1988 S_SET_VALUE (symbolP
, val
);
1990 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1992 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1995 for (i
= 0; i
< numaux
; i
++)
1997 where
+= bfd_coff_swap_aux_out (abfd
,
1998 &symbolP
->sy_symbol
.ost_auxent
[i
],
1999 S_GET_DATA_TYPE (symbolP
),
2000 S_GET_STORAGE_CLASS (symbolP
),
2008 coff_obj_symbol_new_hook (symbolP
)
2011 char underscore
= 0; /* Symbol has leading _ */
2013 /* Effective symbol */
2014 /* Store the pointer in the offset. */
2015 S_SET_ZEROES (symbolP
, 0L);
2016 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2017 S_SET_STORAGE_CLASS (symbolP
, 0);
2018 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2019 /* Additional information */
2020 symbolP
->sy_symbol
.ost_flags
= 0;
2021 /* Auxiliary entries */
2022 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2024 if (S_IS_STRING (symbolP
))
2025 SF_SET_STRING (symbolP
);
2026 if (!underscore
&& S_IS_LOCAL (symbolP
))
2027 SF_SET_LOCAL (symbolP
);
2031 * Handle .ln directives.
2035 obj_coff_ln (appline
)
2040 if (! appline
&& def_symbol_in_progress
!= NULL
)
2042 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2043 demand_empty_rest_of_line ();
2045 } /* wrong context */
2047 l
= get_absolute_expression ();
2048 c_line_new (0, frag_now_fix (), l
, frag_now
);
2051 new_logical_line ((char *) NULL
, l
- 1);
2061 listing_source_line ((unsigned int) l
);
2066 demand_empty_rest_of_line ();
2072 * Handle .def directives.
2074 * One might ask : why can't we symbol_new if the symbol does not
2075 * already exist and fill it with debug information. Because of
2076 * the C_EFCN special symbol. It would clobber the value of the
2077 * function symbol before we have a chance to notice that it is
2078 * a C_EFCN. And a second reason is that the code is more clear this
2079 * way. (at least I think it is :-).
2083 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2084 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2085 *input_line_pointer == '\t') \
2086 input_line_pointer++;
2092 char name_end
; /* Char after the end of name */
2093 char *symbol_name
; /* Name of the debug symbol */
2094 char *symbol_name_copy
; /* Temporary copy of the name */
2095 unsigned int symbol_name_length
;
2097 if (def_symbol_in_progress
!= NULL
)
2099 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2100 demand_empty_rest_of_line ();
2102 } /* if not inside .def/.endef */
2104 SKIP_WHITESPACES ();
2106 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2107 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2109 symbol_name
= input_line_pointer
;
2110 name_end
= get_symbol_end ();
2111 symbol_name_length
= strlen (symbol_name
);
2112 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2113 strcpy (symbol_name_copy
, symbol_name
);
2114 #ifdef tc_canonicalize_symbol_name
2115 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2118 /* Initialize the new symbol */
2119 #ifdef STRIP_UNDERSCORE
2120 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2121 ? symbol_name_copy
+ 1
2122 : symbol_name_copy
));
2123 #else /* STRIP_UNDERSCORE */
2124 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2125 #endif /* STRIP_UNDERSCORE */
2126 /* free(symbol_name_copy); */
2127 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2128 def_symbol_in_progress
->sy_number
= ~0;
2129 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2130 S_SET_VALUE (def_symbol_in_progress
, 0);
2132 if (S_IS_STRING (def_symbol_in_progress
))
2133 SF_SET_STRING (def_symbol_in_progress
);
2135 *input_line_pointer
= name_end
;
2137 demand_empty_rest_of_line ();
2140 unsigned int dim_index
;
2144 obj_coff_endef (ignore
)
2147 symbolS
*symbolP
= 0;
2148 /* DIM BUG FIX sac@cygnus.com */
2150 if (def_symbol_in_progress
== NULL
)
2152 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2153 demand_empty_rest_of_line ();
2155 } /* if not inside .def/.endef */
2157 /* Set the section number according to storage class. */
2158 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2163 SF_SET_TAG (def_symbol_in_progress
);
2164 /* intentional fallthrough */
2167 SF_SET_DEBUG (def_symbol_in_progress
);
2168 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2172 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2173 /* intentional fallthrough */
2175 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2176 /* intentional fallthrough */
2178 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2180 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2182 if (function_lineoff
< 0)
2184 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2185 } /* missing function symbol */
2186 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2188 SF_SET_PROCESS (last_line_symbol
);
2189 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2190 SF_SET_PROCESS (def_symbol_in_progress
);
2191 function_lineoff
= -1;
2193 /* Value is always set to . */
2194 def_symbol_in_progress
->sy_frag
= frag_now
;
2195 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2200 #endif /* C_AUTOARG */
2210 SF_SET_DEBUG (def_symbol_in_progress
);
2211 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2217 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2223 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2225 } /* switch on storage class */
2227 /* Now that we have built a debug symbol, try to find if we should
2228 merge with an existing symbol or not. If a symbol is C_EFCN or
2229 absolute_section or untagged SEG_DEBUG it never merges. We also
2230 don't merge labels, which are in a different namespace, nor
2231 symbols which have not yet been defined since they are typically
2232 unique, nor do we merge tags with non-tags. */
2234 /* Two cases for functions. Either debug followed by definition or
2235 definition followed by debug. For definition first, we will
2236 merge the debug symbol into the definition. For debug first, the
2237 lineno entry MUST point to the definition function or else it
2238 will point off into space when crawl_symbols() merges the debug
2239 symbol into the real symbol. Therefor, let's presume the debug
2240 symbol is a real function reference. */
2242 /* FIXME-SOON If for some reason the definition label/symbol is
2243 never seen, this will probably leave an undefined symbol at link
2246 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2247 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2248 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2249 && !SF_GET_TAG (def_symbol_in_progress
))
2250 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2251 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2252 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2253 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2255 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2260 /* This symbol already exists, merge the newly created symbol
2261 into the old one. This is not mandatory. The linker can
2262 handle duplicate symbols correctly. But I guess that it save
2263 a *lot* of space if the assembly file defines a lot of
2266 /* The debug entry (def_symbol_in_progress) is merged into the
2267 previous definition. */
2269 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2270 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2271 def_symbol_in_progress
= symbolP
;
2273 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2274 || SF_GET_TAG (def_symbol_in_progress
)
2275 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2277 /* For functions, and tags, and static symbols, the symbol
2278 *must* be where the debug symbol appears. Move the
2279 existing symbol to the current place. */
2280 /* If it already is at the end of the symbol list, do nothing */
2281 if (def_symbol_in_progress
!= symbol_lastP
)
2283 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2285 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2286 &symbol_rootP
, &symbol_lastP
);
2287 } /* if not already in place */
2289 } /* normal or mergable */
2291 if (SF_GET_TAG (def_symbol_in_progress
))
2295 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2297 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2298 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2299 def_symbol_in_progress
);
2302 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2304 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2306 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2308 SF_SET_PROCESS (def_symbol_in_progress
);
2310 if (symbolP
== NULL
)
2312 /* That is, if this is the first time we've seen the
2314 symbol_table_insert (def_symbol_in_progress
);
2315 } /* definition follows debug */
2316 } /* Create the line number entry pointing to the function being defined */
2318 def_symbol_in_progress
= NULL
;
2319 demand_empty_rest_of_line ();
2323 obj_coff_dim (ignore
)
2328 if (def_symbol_in_progress
== NULL
)
2330 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2331 demand_empty_rest_of_line ();
2333 } /* if not inside .def/.endef */
2335 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2337 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2339 SKIP_WHITESPACES ();
2340 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2341 get_absolute_expression ());
2343 switch (*input_line_pointer
)
2346 input_line_pointer
++;
2350 as_warn ("badly formed .dim directive ignored");
2351 /* intentional fallthrough */
2359 demand_empty_rest_of_line ();
2363 obj_coff_line (ignore
)
2369 if (def_symbol_in_progress
== NULL
)
2375 name
= S_GET_NAME (def_symbol_in_progress
);
2376 this_base
= get_absolute_expression ();
2378 /* Only .bf symbols indicate the use of a new base line number; the
2379 line numbers associated with .ef, .bb, .eb are relative to the
2380 start of the containing function. */
2381 if (!strcmp (".bf", name
))
2383 #if 0 /* XXX Can we ever have line numbers going backwards? */
2384 if (this_base
> line_base
)
2387 line_base
= this_base
;
2395 listing_source_line ((unsigned int) line_base
);
2401 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2402 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2404 demand_empty_rest_of_line ();
2408 obj_coff_size (ignore
)
2411 if (def_symbol_in_progress
== NULL
)
2413 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2414 demand_empty_rest_of_line ();
2416 } /* if not inside .def/.endef */
2418 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2419 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2420 demand_empty_rest_of_line ();
2424 obj_coff_scl (ignore
)
2427 if (def_symbol_in_progress
== NULL
)
2429 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2430 demand_empty_rest_of_line ();
2432 } /* if not inside .def/.endef */
2434 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2435 demand_empty_rest_of_line ();
2439 obj_coff_tag (ignore
)
2445 if (def_symbol_in_progress
== NULL
)
2447 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2448 demand_empty_rest_of_line ();
2452 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2453 symbol_name
= input_line_pointer
;
2454 name_end
= get_symbol_end ();
2455 #ifdef tc_canonicalize_symbol_name
2456 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2459 /* Assume that the symbol referred to by .tag is always defined.
2460 This was a bad assumption. I've added find_or_make. xoxorich. */
2461 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2462 (long) tag_find_or_make (symbol_name
));
2463 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2465 as_warn ("tag not found for .tag %s", symbol_name
);
2468 SF_SET_TAGGED (def_symbol_in_progress
);
2469 *input_line_pointer
= name_end
;
2471 demand_empty_rest_of_line ();
2475 obj_coff_type (ignore
)
2478 if (def_symbol_in_progress
== NULL
)
2480 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2481 demand_empty_rest_of_line ();
2483 } /* if not inside .def/.endef */
2485 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2487 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2488 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2490 SF_SET_FUNCTION (def_symbol_in_progress
);
2491 } /* is a function */
2493 demand_empty_rest_of_line ();
2497 obj_coff_val (ignore
)
2500 if (def_symbol_in_progress
== NULL
)
2502 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2503 demand_empty_rest_of_line ();
2505 } /* if not inside .def/.endef */
2507 if (is_name_beginner (*input_line_pointer
))
2509 char *symbol_name
= input_line_pointer
;
2510 char name_end
= get_symbol_end ();
2512 #ifdef tc_canonicalize_symbol_name
2513 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2516 if (!strcmp (symbol_name
, "."))
2518 def_symbol_in_progress
->sy_frag
= frag_now
;
2519 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2520 /* If the .val is != from the .def (e.g. statics) */
2522 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2524 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2525 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2526 symbol_find_or_make (symbol_name
);
2527 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2528 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2530 /* If the segment is undefined when the forward reference is
2531 resolved, then copy the segment id from the forward
2533 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2535 /* FIXME: gcc can generate address expressions
2536 here in unusual cases (search for "obscure"
2537 in sdbout.c). We just ignore the offset
2538 here, thus generating incorrect debugging
2539 information. We ignore the rest of the
2542 /* Otherwise, it is the name of a non debug symbol and
2543 its value will be calculated later. */
2544 *input_line_pointer
= name_end
;
2546 /* FIXME: this is to avoid an error message in the
2547 FIXME case mentioned just above. */
2548 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2549 ++input_line_pointer
;
2553 S_SET_VALUE (def_symbol_in_progress
,
2554 (valueT
) get_absolute_expression ());
2555 } /* if symbol based */
2557 demand_empty_rest_of_line ();
2562 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2563 read.c, which then calls this object file format specific routine. */
2566 obj_coff_pe_handle_link_once (type
)
2567 enum linkonce_type type
;
2569 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2571 /* We store the type in the seg_info structure, and use it to set up
2572 the auxiliary entry for the section symbol in c_section_symbol. */
2573 seg_info (now_seg
)->linkonce
= type
;
2579 coff_obj_read_begin_hook ()
2581 /* These had better be the same. Usually 18 bytes. */
2583 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2584 know (SYMESZ
== AUXESZ
);
2589 /* This function runs through the symbol table and puts all the
2590 externals onto another chain */
2592 /* The chain of globals. */
2593 symbolS
*symbol_globalP
;
2594 symbolS
*symbol_global_lastP
;
2596 /* The chain of externals */
2597 symbolS
*symbol_externP
;
2598 symbolS
*symbol_extern_lastP
;
2601 symbolS
*last_functionP
;
2602 static symbolS
*last_bfP
;
2609 unsigned int symbol_number
= 0;
2610 unsigned int last_file_symno
= 0;
2612 struct filename_list
*filename_list_scan
= filename_list_head
;
2614 for (symbolP
= symbol_rootP
;
2616 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2618 if (symbolP
->sy_mri_common
)
2620 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2621 as_bad ("%s: global symbols not supported in common sections",
2622 S_GET_NAME (symbolP
));
2623 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2627 if (!SF_GET_DEBUG (symbolP
))
2629 /* Debug symbols do not need all this rubbish */
2630 symbolS
*real_symbolP
;
2632 /* L* and C_EFCN symbols never merge. */
2633 if (!SF_GET_LOCAL (symbolP
)
2634 && !SF_GET_STATICS (symbolP
)
2635 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2636 && symbolP
->sy_value
.X_op
== O_constant
2637 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2638 && real_symbolP
!= symbolP
)
2640 /* FIXME-SOON: where do dups come from?
2641 Maybe tag references before definitions? xoxorich. */
2642 /* Move the debug data from the debug symbol to the
2643 real symbol. Do NOT do the oposite (i.e. move from
2644 real symbol to debug symbol and remove real symbol from the
2645 list.) Because some pointers refer to the real symbol
2646 whereas no pointers refer to the debug symbol. */
2647 c_symbol_merge (symbolP
, real_symbolP
);
2648 /* Replace the current symbol by the real one */
2649 /* The symbols will never be the last or the first
2650 because : 1st symbol is .file and 3 last symbols are
2651 .text, .data, .bss */
2652 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2653 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2654 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2655 symbolP
= real_symbolP
;
2656 } /* if not local but dup'd */
2658 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2660 S_SET_SEGMENT (symbolP
, SEG_E0
);
2661 } /* push data into text */
2663 resolve_symbol_value (symbolP
);
2665 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2667 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2669 S_SET_EXTERNAL (symbolP
);
2671 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2673 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2677 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2681 /* Mainly to speed up if not -g */
2682 if (SF_GET_PROCESS (symbolP
))
2684 /* Handle the nested blocks auxiliary info. */
2685 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2687 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2688 stack_push (block_stack
, (char *) &symbolP
);
2691 register symbolS
*begin_symbolP
;
2692 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2693 if (begin_symbolP
== (symbolS
*) 0)
2694 as_warn ("mismatched .eb");
2696 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2699 /* If we are able to identify the type of a function, and we
2700 are out of a function (last_functionP == 0) then, the
2701 function symbol will be associated with an auxiliary
2703 if (last_functionP
== (symbolS
*) 0 &&
2704 SF_GET_FUNCTION (symbolP
))
2706 last_functionP
= symbolP
;
2708 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2710 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2711 } /* make it at least 1 */
2713 /* Clobber possible stale .dim information. */
2715 /* Iffed out by steve - this fries the lnnoptr info too */
2716 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2717 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2720 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2722 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2724 if (last_bfP
!= NULL
)
2725 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2729 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2731 /* I don't even know if this is needed for sdb. But
2732 the standard assembler generates it, so... */
2733 if (last_functionP
== (symbolS
*) 0)
2734 as_fatal ("C_EFCN symbol out of scope");
2735 SA_SET_SYM_FSIZE (last_functionP
,
2736 (long) (S_GET_VALUE (symbolP
) -
2737 S_GET_VALUE (last_functionP
)));
2738 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2739 last_functionP
= (symbolS
*) 0;
2743 else if (SF_GET_TAG (symbolP
))
2745 /* First descriptor of a structure must point to
2746 the first slot after the structure description. */
2747 last_tagP
= symbolP
;
2750 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2752 /* +2 take in account the current symbol */
2753 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2755 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2757 /* If the filename was too long to fit in the
2758 auxent, put it in the string table */
2759 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2760 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2762 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2763 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2764 filename_list_scan
= filename_list_scan
->next
;
2766 if (S_GET_VALUE (symbolP
))
2768 S_SET_VALUE (symbolP
, last_file_symno
);
2769 last_file_symno
= symbol_number
;
2770 } /* no one points at the first .file symbol */
2771 } /* if debug or tag or eos or file */
2773 #ifdef tc_frob_coff_symbol
2774 tc_frob_coff_symbol (symbolP
);
2777 /* We must put the external symbols apart. The loader
2778 does not bomb if we do not. But the references in
2779 the endndx field for a .bb symbol are not corrected
2780 if an external symbol is removed between .bb and .be.
2781 I.e in the following case :
2782 [20] .bb endndx = 22
2785 ld will move the symbol 21 to the end of the list but
2786 endndx will still be 22 instead of 21. */
2789 if (SF_GET_LOCAL (symbolP
))
2791 /* remove C_EFCN and LOCAL (L...) symbols */
2792 /* next pointer remains valid */
2793 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2796 else if (symbolP
->sy_value
.X_op
== O_symbol
2797 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2799 /* Skip symbols which were equated to undefined or common
2801 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2803 else if (!S_IS_DEFINED (symbolP
)
2804 && !S_IS_DEBUG (symbolP
)
2805 && !SF_GET_STATICS (symbolP
) &&
2806 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2807 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2808 /* if external, Remove from the list */
2809 symbolS
*hold
= symbol_previous (symbolP
);
2811 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2812 symbol_clear_list_pointers (symbolP
);
2813 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2816 else if (! S_IS_DEBUG (symbolP
)
2817 && ! SF_GET_STATICS (symbolP
)
2818 && ! SF_GET_FUNCTION (symbolP
)
2819 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2821 symbolS
*hold
= symbol_previous (symbolP
);
2823 /* The O'Reilly COFF book says that defined global symbols
2824 come at the end of the symbol table, just before
2825 undefined global symbols. */
2827 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2828 symbol_clear_list_pointers (symbolP
);
2829 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2830 &symbol_global_lastP
);
2835 if (SF_GET_STRING (symbolP
))
2837 symbolP
->sy_name_offset
= string_byte_count
;
2838 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2842 symbolP
->sy_name_offset
= 0;
2843 } /* fix "long" names */
2845 symbolP
->sy_number
= symbol_number
;
2846 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2847 } /* if local symbol */
2848 } /* traverse the symbol list */
2849 return symbol_number
;
2855 glue_symbols (head
, tail
)
2859 unsigned int symbol_number
= 0;
2861 while (*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
= symbol_next (symbolP
))
2895 symbolP
->sy_number
= symbol_number
;
2897 if (SF_GET_TAGGED (symbolP
))
2901 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2904 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2907 return symbol_number
;
2911 crawl_symbols (h
, abfd
)
2917 /* Initialize the stack used to keep track of the matching .bb .be */
2919 block_stack
= stack_init (512, sizeof (symbolS
*));
2921 /* The symbol list should be ordered according to the following sequence
2924 * . debug entries for functions
2925 * . fake symbols for the sections, including .text .data and .bss
2927 * . undefined symbols
2928 * But this is not mandatory. The only important point is to put the
2929 * undefined symbols at the end of the list.
2932 /* Is there a .file symbol ? If not insert one at the beginning. */
2933 if (symbol_rootP
== NULL
2934 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2936 c_dot_file_symbol ("fake");
2940 * Build up static symbols for the sections, they are filled in later
2944 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2945 if (segment_info
[i
].scnhdr
.s_name
[0])
2946 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2949 /* Take all the externals out and put them into another chain */
2950 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2951 /* Take the externals and glue them onto the end.*/
2952 H_SET_SYMBOL_TABLE_SIZE (h
,
2953 (H_GET_SYMBOL_COUNT (h
)
2954 + glue_symbols (&symbol_globalP
,
2955 &symbol_global_lastP
)
2956 + glue_symbols (&symbol_externP
,
2957 &symbol_extern_lastP
)));
2959 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2960 know (symbol_globalP
== NULL
);
2961 know (symbol_global_lastP
== NULL
);
2962 know (symbol_externP
== NULL
);
2963 know (symbol_extern_lastP
== NULL
);
2967 * Find strings by crawling along symbol table chain.
2975 struct filename_list
*filename_list_scan
= filename_list_head
;
2977 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2978 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2981 #ifdef COFF_LONG_SECTION_NAMES
2982 /* Support long section names as found in PE. This code must
2983 coordinate with that in coff_header_append and write_object_file. */
2987 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2989 if (segment_info
[i
].scnhdr
.s_name
[0]
2990 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2994 size
= strlen (segment_info
[i
].name
) + 1;
2995 memcpy (where
, segment_info
[i
].name
, size
);
3000 #endif /* COFF_LONG_SECTION_NAMES */
3002 for (symbolP
= symbol_rootP
;
3004 symbolP
= symbol_next (symbolP
))
3008 if (SF_GET_STRING (symbolP
))
3010 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3011 memcpy (where
, S_GET_NAME (symbolP
), size
);
3014 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3015 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3016 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3018 size
= strlen (filename_list_scan
->filename
) + 1;
3019 memcpy (where
, filename_list_scan
->filename
, size
);
3020 filename_list_scan
= filename_list_scan
->next
;
3027 do_linenos_for (abfd
, h
, file_cursor
)
3030 unsigned long *file_cursor
;
3033 unsigned long start
= *file_cursor
;
3035 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3037 segment_info_type
*s
= segment_info
+ idx
;
3040 if (s
->scnhdr
.s_nlnno
!= 0)
3042 struct lineno_list
*line_ptr
;
3044 struct external_lineno
*buffer
=
3045 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3047 struct external_lineno
*dst
= buffer
;
3049 /* Run through the table we've built and turn it into its external
3050 form, take this chance to remove duplicates */
3052 for (line_ptr
= s
->lineno_list_head
;
3053 line_ptr
!= (struct lineno_list
*) NULL
;
3054 line_ptr
= line_ptr
->next
)
3057 if (line_ptr
->line
.l_lnno
== 0)
3059 /* Turn a pointer to a symbol into the symbols' index */
3060 line_ptr
->line
.l_addr
.l_symndx
=
3061 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3065 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3069 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3074 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3076 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3079 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3082 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3086 /* Now we run through the list of frag chains in a segment and
3087 make all the subsegment frags appear at the end of the
3088 list, as if the seg 0 was extra long */
3095 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3097 frchainS
*head
= segment_info
[i
].frchainP
;
3099 fragS
*prev_frag
= &dummy
;
3101 while (head
&& head
->frch_seg
== i
)
3103 prev_frag
->fr_next
= head
->frch_root
;
3104 prev_frag
= head
->frch_last
;
3105 head
= head
->frch_next
;
3107 prev_frag
->fr_next
= 0;
3111 unsigned long machine
;
3114 write_object_file ()
3118 struct frchain
*frchain_ptr
;
3120 object_headers headers
;
3121 unsigned long file_cursor
;
3124 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3129 as_perror ("FATAL: Can't create %s", out_file_name
);
3130 exit (EXIT_FAILURE
);
3132 bfd_set_format (abfd
, bfd_object
);
3133 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3135 string_byte_count
= 4;
3137 for (frchain_ptr
= frchain_root
;
3138 frchain_ptr
!= (struct frchain
*) NULL
;
3139 frchain_ptr
= frchain_ptr
->frch_next
)
3141 /* Run through all the sub-segments and align them up. Also
3142 close any open frags. We tack a .fill onto the end of the
3143 frag chain so that any .align's size can be worked by looking
3144 at the next frag. */
3146 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3147 #ifndef SUB_SEGMENT_ALIGN
3148 #define SUB_SEGMENT_ALIGN(SEG) 1
3151 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3154 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3158 frag_wane (frag_now
);
3159 frag_now
->fr_fix
= 0;
3160 know (frag_now
->fr_next
== NULL
);
3167 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3169 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3172 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3174 /* Find out how big the sections are, and set the addresses. */
3176 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3180 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3181 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3183 if (segment_info
[i
].scnhdr
.s_name
[0])
3185 H_SET_NUMBER_OF_SECTIONS (&headers
,
3186 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3188 #ifdef COFF_LONG_SECTION_NAMES
3189 /* Support long section names as found in PE. This code
3190 must coordinate with that in coff_header_append and
3195 len
= strlen (segment_info
[i
].name
);
3197 string_byte_count
+= len
+ 1;
3199 #endif /* COFF_LONG_SECTION_NAMES */
3202 size
= size_section (abfd
, (unsigned int) i
);
3205 /* I think the section alignment is only used on the i960; the
3206 i960 needs it, and it should do no harm on other targets. */
3207 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3210 H_SET_TEXT_SIZE (&headers
, size
);
3211 else if (i
== SEG_E1
)
3212 H_SET_DATA_SIZE (&headers
, size
);
3213 else if (i
== SEG_E2
)
3214 H_SET_BSS_SIZE (&headers
, size
);
3217 /* Turn the gas native symbol table shape into a coff symbol table */
3218 crawl_symbols (&headers
, abfd
);
3220 if (string_byte_count
== 4)
3221 string_byte_count
= 0;
3223 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3229 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3231 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3232 fixup_segment (&segment_info
[i
], i
);
3235 /* Look for ".stab" segments and fill in their initial symbols
3237 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3239 name
= segment_info
[i
].name
;
3242 && strncmp (".stab", name
, 5) == 0
3243 && strncmp (".stabstr", name
, 8) != 0)
3244 adjust_stab_section (abfd
, i
);
3247 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3249 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3251 /* Plant the data */
3253 fill_section (abfd
, &headers
, &file_cursor
);
3255 do_relocs_for (abfd
, &headers
, &file_cursor
);
3257 do_linenos_for (abfd
, &headers
, &file_cursor
);
3259 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3260 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3261 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3263 H_SET_TIME_STAMP (&headers
, 0);
3265 #ifdef TC_COFF_SET_MACHINE
3266 TC_COFF_SET_MACHINE (&headers
);
3270 #define COFF_FLAGS 0
3273 #ifdef KEEP_RELOC_INFO
3274 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3275 COFF_FLAGS
| coff_flags
));
3277 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3278 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3279 COFF_FLAGS
| coff_flags
));
3283 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3284 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3286 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3287 w_symbols (abfd
, buffer1
, symbol_rootP
);
3288 if (string_byte_count
> 0)
3289 w_strings (buffer1
+ symtable_size
);
3290 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3294 coff_header_append (abfd
, &headers
);
3296 /* Recent changes to write need this, but where it should
3297 go is up to Ken.. */
3298 if (bfd_close_all_done (abfd
) == false)
3299 as_fatal ("Can't close %s: %s", out_file_name
,
3300 bfd_errmsg (bfd_get_error ()));
3303 extern bfd
*stdoutput
;
3310 /* Add a new segment. This is called from subseg_new via the
3311 obj_new_segment macro. */
3314 obj_coff_add_segment (name
)
3319 #ifndef COFF_LONG_SECTION_NAMES
3320 char buf
[SCNNMLEN
+ 1];
3322 strncpy (buf
, name
, SCNNMLEN
);
3323 buf
[SCNNMLEN
] = '\0';
3327 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3328 if (strcmp (name
, segment_info
[i
].name
) == 0)
3333 as_bad ("Too many new sections; can't add \"%s\"", name
);
3337 /* Add a new section. */
3338 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3339 sizeof (segment_info
[i
].scnhdr
.s_name
));
3340 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3341 segment_info
[i
].name
= xstrdup (name
);
3347 * implement the .section pseudo op:
3348 * .section name {, "flags"}
3350 * | +--- optional flags: 'b' for bss
3352 * +-- section name 'l' for lib
3356 * 'd' (apparently m88k for data)
3358 * 'r' for read-only data
3359 * But if the argument is not a quoted string, treat it as a
3360 * subsegment number.
3364 obj_coff_section (ignore
)
3367 /* Strip out the section name */
3368 char *section_name
, *name
;
3381 else if (type
== 'D')
3383 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3388 section_name
= input_line_pointer
;
3389 c
= get_symbol_end ();
3391 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3392 strcpy (name
, section_name
);
3394 *input_line_pointer
= c
;
3400 if (*input_line_pointer
== ',')
3402 ++input_line_pointer
;
3405 if (*input_line_pointer
!= '"')
3406 exp
= get_absolute_expression ();
3409 ++input_line_pointer
;
3410 while (*input_line_pointer
!= '"'
3411 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3413 switch (*input_line_pointer
)
3415 case 'b': flags
|= STYP_BSS
; break;
3416 case 'i': flags
|= STYP_INFO
; break;
3417 case 'l': flags
|= STYP_LIB
; break;
3418 case 'n': flags
|= STYP_NOLOAD
; break;
3419 case 'o': flags
|= STYP_OVER
; break;
3421 case 'w': flags
|= STYP_DATA
; break;
3422 case 'x': flags
|= STYP_TEXT
; break;
3423 case 'r': flags
|= STYP_LIT
; break;
3425 as_warn("unknown section attribute '%c'",
3426 *input_line_pointer
);
3429 ++input_line_pointer
;
3431 if (*input_line_pointer
== '"')
3432 ++input_line_pointer
;
3436 subseg_new (name
, (subsegT
) exp
);
3438 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3440 demand_empty_rest_of_line ();
3445 obj_coff_text (ignore
)
3448 subseg_new (".text", get_absolute_expression ());
3453 obj_coff_data (ignore
)
3456 if (flag_readonly_data_in_text
)
3457 subseg_new (".text", get_absolute_expression () + 1000);
3459 subseg_new (".data", get_absolute_expression ());
3463 obj_coff_bss (ignore
)
3466 if (*input_line_pointer
== '\n') /* .bss */
3467 subseg_new(".bss", get_absolute_expression());
3468 else /* .bss id,expr */
3473 obj_coff_ident (ignore
)
3476 segT current_seg
= now_seg
; /* save current seg */
3477 subsegT current_subseg
= now_subseg
;
3478 subseg_new (".comment", 0); /* .comment seg */
3479 stringer (1); /* read string */
3480 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3484 c_symbol_merge (debug
, normal
)
3488 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3489 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3491 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3493 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3494 } /* take the most we have */
3496 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3498 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3499 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3500 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3501 } /* Move all the auxiliary information */
3503 /* Move the debug flags. */
3504 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3505 } /* c_symbol_merge() */
3508 c_line_new (symbol
, paddr
, line_number
, frag
)
3514 struct lineno_list
*new_line
=
3515 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3517 segment_info_type
*s
= segment_info
+ now_seg
;
3518 new_line
->line
.l_lnno
= line_number
;
3520 if (line_number
== 0)
3522 last_line_symbol
= symbol
;
3523 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3527 new_line
->line
.l_addr
.l_paddr
= paddr
;
3530 new_line
->frag
= (char *) frag
;
3531 new_line
->next
= (struct lineno_list
*) NULL
;
3534 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3536 s
->lineno_list_head
= new_line
;
3540 s
->lineno_list_tail
->next
= new_line
;
3542 s
->lineno_list_tail
= new_line
;
3543 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3547 c_dot_file_symbol (filename
)
3552 symbolP
= symbol_new (".file",
3555 &zero_address_frag
);
3557 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3558 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3560 if (strlen (filename
) > FILNMLEN
)
3562 /* Filename is too long to fit into an auxent,
3563 we stick it into the string table instead. We keep
3564 a linked list of the filenames we find so we can emit
3566 struct filename_list
*f
= ((struct filename_list
*)
3567 xmalloc (sizeof (struct filename_list
)));
3569 f
->filename
= filename
;
3572 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3573 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3575 if (filename_list_tail
)
3576 filename_list_tail
->next
= f
;
3578 filename_list_head
= f
;
3579 filename_list_tail
= f
;
3583 SA_SET_FILE_FNAME (symbolP
, filename
);
3590 listing_source_file (filename
);
3596 SF_SET_DEBUG (symbolP
);
3597 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3599 previous_file_symbol
= symbolP
;
3601 /* Make sure that the symbol is first on the symbol chain */
3602 if (symbol_rootP
!= symbolP
)
3604 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3605 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3607 } /* c_dot_file_symbol() */
3610 * Build a 'section static' symbol.
3614 c_section_symbol (name
, idx
)
3620 symbolP
= symbol_new (name
, idx
,
3622 &zero_address_frag
);
3624 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3625 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3627 SF_SET_STATICS (symbolP
);
3630 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3631 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3632 SF_CLEAR_LOCAL (symbolP
);
3635 /* If the .linkonce pseudo-op was used for this section, we must
3636 store the information in the auxiliary entry for the section
3638 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3642 switch (segment_info
[idx
].linkonce
)
3646 case LINKONCE_DISCARD
:
3647 type
= IMAGE_COMDAT_SELECT_ANY
;
3649 case LINKONCE_ONE_ONLY
:
3650 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3652 case LINKONCE_SAME_SIZE
:
3653 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3655 case LINKONCE_SAME_CONTENTS
:
3656 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3660 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3665 } /* c_section_symbol() */
3668 w_symbols (abfd
, where
, symbol_rootP
)
3671 symbolS
* symbol_rootP
;
3676 /* First fill in those values we have only just worked out */
3677 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3679 symbolP
= segment_info
[i
].dot
;
3682 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3683 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3684 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3689 * Emit all symbols left in the symbol chain.
3691 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3693 /* Used to save the offset of the name. It is used to point
3694 to the string in memory but must be a file offset. */
3695 register char *temp
;
3697 /* We can't fix the lnnoptr field in yank_symbols with the other
3698 adjustments, because we have to wait until we know where they
3700 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3702 SA_GET_SYM_LNNOPTR (symbolP
) +=
3703 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3706 tc_coff_symbol_emit_hook (symbolP
);
3708 temp
= S_GET_NAME (symbolP
);
3709 if (SF_GET_STRING (symbolP
))
3711 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3712 S_SET_ZEROES (symbolP
, 0);
3716 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3717 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3719 where
= symbol_to_chars (abfd
, where
, symbolP
);
3720 S_SET_NAME (symbolP
, temp
);
3726 obj_coff_lcomm (ignore
)
3739 name
= input_line_pointer
;
3741 c
= get_symbol_end ();
3742 p
= input_line_pointer
;
3745 if (*input_line_pointer
!= ',')
3747 as_bad ("Expected comma after name");
3748 ignore_rest_of_line ();
3751 if (*input_line_pointer
== '\n')
3753 as_bad ("Missing size expression");
3756 input_line_pointer
++;
3757 if ((temp
= get_absolute_expression ()) < 0)
3759 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3760 ignore_rest_of_line ();
3765 symbolP
= symbol_find_or_make(name
);
3767 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3768 S_GET_VALUE(symbolP
) == 0)
3773 segT current_seg
= now_seg
; /* save current seg */
3774 subsegT current_subseg
= now_subseg
;
3776 subseg_set (SEG_E2
, 1);
3777 symbolP
->sy_frag
= frag_now
;
3778 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3779 (offsetT
) temp
, (char *) 0);
3781 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3782 S_SET_SEGMENT(symbolP
, SEG_E2
);
3783 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3787 as_bad("Symbol %s already defined", name
);
3789 demand_empty_rest_of_line();
3794 fixup_mdeps (frags
, h
, this_segment
)
3799 subseg_change (this_segment
, 0);
3802 switch (frags
->fr_type
)
3808 HANDLE_ALIGN (frags
);
3810 frags
->fr_type
= rs_fill
;
3812 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3815 case rs_machine_dependent
:
3816 md_convert_frag (h
, this_segment
, frags
);
3822 frags
= frags
->fr_next
;
3828 #ifndef TC_FORCE_RELOCATION
3829 #define TC_FORCE_RELOCATION(fix) 0
3833 fixup_segment (segP
, this_segment_type
)
3834 segment_info_type
* segP
;
3835 segT this_segment_type
;
3837 register fixS
* fixP
;
3838 register symbolS
*add_symbolP
;
3839 register symbolS
*sub_symbolP
;
3842 register char *place
;
3843 register long where
;
3844 register char pcrel
;
3845 register fragS
*fragP
;
3846 register segT add_symbol_segment
= absolute_section
;
3848 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3850 fragP
= fixP
->fx_frag
;
3852 where
= fixP
->fx_where
;
3853 place
= fragP
->fr_literal
+ where
;
3854 size
= fixP
->fx_size
;
3855 add_symbolP
= fixP
->fx_addsy
;
3856 sub_symbolP
= fixP
->fx_subsy
;
3857 add_number
= fixP
->fx_offset
;
3858 pcrel
= fixP
->fx_pcrel
;
3860 /* We want function-relative stabs to work on systems which
3861 may use a relaxing linker; thus we must handle the sym1-sym2
3862 fixups function-relative stabs generates.
3864 Of course, if you actually enable relaxing in the linker, the
3865 line and block scoping information is going to be incorrect
3866 in some cases. The only way to really fix this is to support
3867 a reloc involving the difference of two symbols. */
3869 && (!sub_symbolP
|| pcrel
))
3873 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3875 /* Relocation should be done via the associated 'bal' entry
3878 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3880 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3881 "No 'bal' entry point for leafproc %s",
3882 S_GET_NAME (add_symbolP
));
3885 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3889 /* Make sure the symbols have been resolved; this may not have
3890 happened if these are expression symbols. */
3891 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3892 resolve_symbol_value (add_symbolP
);
3894 if (add_symbolP
!= NULL
)
3896 /* If this fixup is against a symbol which has been equated
3897 to another symbol, convert it to the other symbol. */
3898 if (add_symbolP
->sy_value
.X_op
== O_symbol
3899 && (! S_IS_DEFINED (add_symbolP
)
3900 || S_IS_COMMON (add_symbolP
)))
3902 while (add_symbolP
->sy_value
.X_op
== O_symbol
3903 && (! S_IS_DEFINED (add_symbolP
)
3904 || S_IS_COMMON (add_symbolP
)))
3908 /* We must avoid looping, as that can occur with a
3909 badly written program. */
3910 n
= add_symbolP
->sy_value
.X_add_symbol
;
3911 if (n
== add_symbolP
)
3913 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3916 fixP
->fx_addsy
= add_symbolP
;
3917 fixP
->fx_offset
= add_number
;
3921 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3922 resolve_symbol_value (sub_symbolP
);
3924 if (add_symbolP
!= NULL
3925 && add_symbolP
->sy_mri_common
)
3927 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3928 add_number
+= S_GET_VALUE (add_symbolP
);
3929 fixP
->fx_offset
= add_number
;
3930 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3935 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3936 } /* if there is an addend */
3940 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3942 if (add_symbolP
!= NULL
)
3944 add_number
+= S_GET_VALUE (add_symbolP
);
3946 fixP
->fx_addsy
= NULL
;
3949 /* It's just -sym. */
3950 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3952 add_number
-= S_GET_VALUE (sub_symbolP
);
3959 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3960 "Negative of non-absolute symbol %s",
3961 S_GET_NAME (sub_symbolP
));
3963 add_number
-= S_GET_VALUE (sub_symbolP
);
3964 } /* not absolute */
3966 /* if sub_symbol is in the same segment that add_symbol
3967 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3969 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3970 && SEG_NORMAL (add_symbol_segment
))
3972 /* Difference of 2 symbols from same segment. Can't
3973 make difference of 2 undefineds: 'value' means
3974 something different for N_UNDF. */
3976 /* Makes no sense to use the difference of 2 arbitrary symbols
3977 as the target of a call instruction. */
3980 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3981 "callj to difference of 2 symbols");
3983 #endif /* TC_I960 */
3984 add_number
+= S_GET_VALUE (add_symbolP
) -
3985 S_GET_VALUE (sub_symbolP
);
3988 if (!TC_FORCE_RELOCATION (fixP
))
3990 fixP
->fx_addsy
= NULL
;
3991 fixP
->fx_subsy
= NULL
;
3993 #ifdef TC_M68K /* is this right? */
4001 /* Different segments in subtraction. */
4002 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4004 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4006 add_number
-= S_GET_VALUE (sub_symbolP
);
4009 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4010 #if 0 /* Okay for 68k, at least... */
4015 /* Make it pc-relative. */
4016 add_number
+= (md_pcrel_from (fixP
)
4017 - S_GET_VALUE (sub_symbolP
));
4026 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4027 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
4028 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4029 S_GET_NAME (sub_symbolP
),
4030 (long) (fragP
->fr_address
+ where
));
4033 } /* if sub_symbolP */
4037 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4040 * This fixup was made when the symbol's segment was
4041 * SEG_UNKNOWN, but it is now in the local segment.
4042 * So we know how to do the address without relocation.
4045 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4046 * in which cases it modifies *fixP as appropriate. In the case
4047 * of a 'calls', no further work is required, and *fixP has been
4048 * set up to make the rest of the code below a no-op.
4051 #endif /* TC_I960 */
4053 add_number
+= S_GET_VALUE (add_symbolP
);
4054 add_number
-= md_pcrel_from (fixP
);
4057 add_number -= segP->scnhdr.s_vaddr;
4058 if defined (TC_I386) || defined (TE_LYNX). I now
4059 think that was an error propagated from the case when
4060 we are going to emit the relocation. If we are not
4061 going to emit the relocation, then we just want to
4062 set add_number to the difference between the symbols.
4063 This is a case that would only arise when there is a
4064 PC relative reference from a section other than .text
4065 to a symbol defined in the same section, and the
4066 reference is not relaxed. Since jump instructions on
4067 the i386 are relaxed, this could only arise with a
4068 call instruction. */
4070 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4071 if (!TC_FORCE_RELOCATION (fixP
))
4073 fixP
->fx_addsy
= NULL
;
4079 switch (add_symbol_segment
)
4081 case absolute_section
:
4083 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4084 #endif /* TC_I960 */
4085 add_number
+= S_GET_VALUE (add_symbolP
);
4088 if (!TC_FORCE_RELOCATION (fixP
))
4090 fixP
->fx_addsy
= NULL
;
4097 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4098 /* This really should be handled in the linker, but
4099 backward compatibility forbids. */
4100 add_number
+= S_GET_VALUE (add_symbolP
);
4102 add_number
+= S_GET_VALUE (add_symbolP
) +
4103 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4109 if ((int) fixP
->fx_bit_fixP
== 13)
4111 /* This is a COBR instruction. They have only a
4112 * 13-bit displacement and are only to be used
4113 * for local branches: flag as error, don't generate
4116 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4117 "can't use COBR format with external label");
4118 fixP
->fx_addsy
= NULL
;
4122 #endif /* TC_I960 */
4123 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4124 /* 386 COFF uses a peculiar format in which the
4125 value of a common symbol is stored in the .text
4126 segment (I've checked this on SVR3.2 and SCO
4127 3.2.2) Ian Taylor <ian@cygnus.com>. */
4128 /* This is also true for 68k COFF on sysv machines
4129 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4130 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4131 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4132 if (S_IS_COMMON (add_symbolP
))
4133 add_number
+= S_GET_VALUE (add_symbolP
);
4138 } /* switch on symbol seg */
4139 } /* if not in local seg */
4140 } /* if there was a + symbol */
4144 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4145 /* This adjustment is not correct on the m88k, for which the
4146 linker does all the computation. */
4147 add_number
-= md_pcrel_from (fixP
);
4149 if (add_symbolP
== 0)
4151 fixP
->fx_addsy
= &abs_symbol
;
4152 } /* if there's an add_symbol */
4153 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4154 /* On the 386 we must adjust by the segment vaddr as well.
4157 I changed the i960 to work this way as well. This is
4158 compatible with the current GNU linker behaviour. I do
4159 not know what other i960 COFF assemblers do. This is not
4160 a common case: normally, only assembler code will contain
4161 a PC relative reloc, and only branches which do not
4162 originate in the .text section will have a non-zero
4165 I changed the m68k to work this way as well. This will
4166 break existing PC relative relocs from sections which do
4167 not start at address 0, but it will make ld -r work.
4168 Ian Taylor, 4 Oct 96. */
4170 add_number
-= segP
->scnhdr
.s_vaddr
;
4174 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4177 /* The m88k uses the offset field of the reloc to get around
4180 && ((add_number
& ~0xFF)
4181 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4182 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4183 || (add_number
& 0x80) == 0))
4185 && ((add_number
& ~0xFFFF)
4186 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4187 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4188 || (add_number
& 0x8000) == 0)))
4190 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4191 "Value of %ld too large for field of %d bytes at 0x%lx",
4192 (long) add_number
, size
,
4193 (unsigned long) (fragP
->fr_address
+ where
));
4196 #ifdef WARN_SIGNED_OVERFLOW_WORD
4197 /* Warn if a .word value is too large when treated as a
4198 signed number. We already know it is not too negative.
4199 This is to catch over-large switches generated by gcc on
4201 if (!flag_signed_overflow_ok
4203 && add_number
> 0x7fff)
4204 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4205 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4207 (unsigned long) (fragP
->fr_address
+ where
));
4209 } /* not a bit fix */
4210 /* Once this fix has been applied, we don't have to output
4211 anything nothing more need be done. */
4212 #ifdef MD_APPLY_FIX3
4213 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4215 md_apply_fix (fixP
, add_number
);
4217 } /* For each fixS in this segment. */
4218 } /* fixup_segment() */
4222 /* The first entry in a .stab section is special. */
4225 obj_coff_init_stab_section (seg
)
4231 unsigned int stroff
;
4233 /* Make space for this first symbol. */
4237 as_where (&file
, (unsigned int *) NULL
);
4238 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4239 strcpy (stabstr_name
, segment_info
[seg
].name
);
4240 strcat (stabstr_name
, "str");
4241 stroff
= get_stab_string_offset (file
, stabstr_name
);
4243 md_number_to_chars (p
, stroff
, 4);
4246 /* Fill in the counts in the first entry in a .stab section. */
4249 adjust_stab_section(abfd
, seg
)
4253 segT stabstrseg
= SEG_UNKNOWN
;
4254 const char *secname
, *name2
;
4257 int i
, strsz
= 0, nsyms
;
4258 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4260 /* Look for the associated string table section. */
4262 secname
= segment_info
[seg
].name
;
4263 name
= (char *) alloca (strlen (secname
) + 4);
4264 strcpy (name
, secname
);
4265 strcat (name
, "str");
4267 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4269 name2
= segment_info
[i
].name
;
4270 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4277 /* If we found the section, get its size. */
4278 if (stabstrseg
!= SEG_UNKNOWN
)
4279 strsz
= size_section (abfd
, stabstrseg
);
4281 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4283 /* Look for the first frag of sufficient size for the initial stab
4284 symbol, and collect a pointer to it. */
4285 while (frag
&& frag
->fr_fix
< 12)
4286 frag
= frag
->fr_next
;
4288 p
= frag
->fr_literal
;
4291 /* Write in the number of stab symbols and the size of the string
4293 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4294 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4297 #endif /* not BFD_ASSEMBLER */
4299 const pseudo_typeS obj_pseudo_table
[] =
4301 {"def", obj_coff_def
, 0},
4302 {"dim", obj_coff_dim
, 0},
4303 {"endef", obj_coff_endef
, 0},
4304 {"line", obj_coff_line
, 0},
4305 {"ln", obj_coff_ln
, 0},
4306 {"appline", obj_coff_ln
, 1},
4307 {"scl", obj_coff_scl
, 0},
4308 {"size", obj_coff_size
, 0},
4309 {"tag", obj_coff_tag
, 0},
4310 {"type", obj_coff_type
, 0},
4311 {"val", obj_coff_val
, 0},
4312 {"section", obj_coff_section
, 0},
4313 {"sect", obj_coff_section
, 0},
4314 /* FIXME: We ignore the MRI short attribute. */
4315 {"section.s", obj_coff_section
, 0},
4316 {"sect.s", obj_coff_section
, 0},
4317 #ifndef BFD_ASSEMBLER
4318 {"use", obj_coff_section
, 0},
4319 {"text", obj_coff_text
, 0},
4320 {"data", obj_coff_data
, 0},
4321 {"bss", obj_coff_bss
, 0},
4322 {"lcomm", obj_coff_lcomm
, 0},
4323 {"ident", obj_coff_ident
, 0},
4325 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4326 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4328 {"version", s_ignore
, 0},
4329 {"ABORT", s_abort
, 0},
4331 /* The m88k uses sdef instead of def. */
4332 {"sdef", obj_coff_def
, 0},
4334 {NULL
} /* end sentinel */
4335 }; /* obj_pseudo_table */
4337 #ifdef BFD_ASSEMBLER
4339 /* Support for a COFF emulation. */
4344 pop_insert (obj_pseudo_table
);
4348 coff_sec_sym_ok_for_reloc (sec
)
4360 const struct format_ops coff_format_ops
=
4362 bfd_target_coff_flavour
,
4372 obj_generate_asm_lineno
,
4381 coff_sec_sym_ok_for_reloc
,
4388 coff_obj_read_begin_hook
,
4389 coff_obj_symbol_new_hook
,