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
26 /* I think this is probably always correct. */
27 #ifndef KEEP_RELOC_INFO
28 #define KEEP_RELOC_INFO
31 const char *s_get_name
PARAMS ((symbolS
* s
));
32 static symbolS
*def_symbol_in_progress
;
38 unsigned long chunk_size
;
39 unsigned long element_size
;
42 unsigned long pointer
;
47 stack_init (chunk_size
, element_size
)
48 unsigned long chunk_size
;
49 unsigned long element_size
;
53 st
= (stack
*) malloc (sizeof (stack
));
56 st
->data
= malloc (chunk_size
);
63 st
->size
= chunk_size
;
64 st
->chunk_size
= chunk_size
;
65 st
->element_size
= element_size
;
70 /* Not currently used. */
81 stack_push (st
, element
)
85 if (st
->pointer
+ st
->element_size
>= st
->size
)
87 st
->size
+= st
->chunk_size
;
88 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
91 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
92 st
->pointer
+= st
->element_size
;
93 return st
->data
+ st
->pointer
;
100 if (st
->pointer
< st
->element_size
)
105 st
->pointer
-= st
->element_size
;
106 return st
->data
+ st
->pointer
;
110 * Maintain a list of the tagnames of the structres.
113 static struct hash_control
*tag_hash
;
118 tag_hash
= hash_new ();
122 tag_insert (name
, symbolP
)
126 const char *error_string
;
128 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
130 as_fatal ("Inserting \"%s\" into structure table failed: %s",
139 #ifdef STRIP_UNDERSCORE
142 #endif /* STRIP_UNDERSCORE */
143 return (symbolS
*) hash_find (tag_hash
, name
);
147 tag_find_or_make (name
)
152 if ((symbolP
= tag_find (name
)) == NULL
)
154 symbolP
= symbol_new (name
, undefined_section
,
155 0, &zero_address_frag
);
157 tag_insert (S_GET_NAME (symbolP
), symbolP
);
159 symbol_table_insert (symbolP
);
170 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
172 #define GET_FILENAME_STRING(X) \
173 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
177 fetch_coff_debug_section ()
179 static segT debug_section
;
183 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
185 debug_section
= s
->section
;
187 return debug_section
;
191 SA_SET_SYM_ENDNDX (sym
, val
)
195 combined_entry_type
*entry
, *p
;
197 entry
= &coffsymbol (sym
->bsym
)->native
[1];
198 p
= coffsymbol (val
->bsym
)->native
;
199 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
204 SA_SET_SYM_TAGNDX (sym
, val
)
208 combined_entry_type
*entry
, *p
;
210 entry
= &coffsymbol (sym
->bsym
)->native
[1];
211 p
= coffsymbol (val
->bsym
)->native
;
212 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
217 S_GET_DATA_TYPE (sym
)
220 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
224 S_SET_DATA_TYPE (sym
, val
)
228 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
233 S_GET_STORAGE_CLASS (sym
)
236 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
240 S_SET_STORAGE_CLASS (sym
, val
)
244 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
248 /* Merge a debug symbol containing debug information into a normal symbol. */
251 c_symbol_merge (debug
, normal
)
255 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
256 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
258 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
259 /* take the most we have */
260 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
262 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
264 /* Move all the auxiliary information. */
265 /* @@ How many fields do we want to preserve? Would it make more
266 sense to pick and choose those we want to copy? Should look
267 into this further.... [raeburn:19920512.2209EST] */
269 linenos
= coffsymbol (normal
->bsym
)->lineno
;
270 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
271 (char *) &coffsymbol (debug
->bsym
)->native
,
272 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
273 coffsymbol (normal
->bsym
)->lineno
= linenos
;
276 /* Move the debug flags. */
277 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
281 c_dot_file_symbol (filename
)
286 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
288 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
289 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
291 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
298 listing_source_file (filename
);
303 /* Make sure that the symbol is first on the symbol chain */
304 if (symbol_rootP
!= symbolP
)
306 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
307 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
308 } /* if not first on the list */
311 /* Line number handling */
314 struct line_no
*next
;
321 /* Symbol of last function, which we should hang line#s off of. */
322 static symbolS
*line_fsym
;
324 #define in_function() (line_fsym != 0)
325 #define clear_function() (line_fsym = 0)
326 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
330 obj_symbol_new_hook (symbolP
)
333 char underscore
= 0; /* Symbol has leading _ */
336 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
337 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
339 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
341 S_SET_DATA_TYPE (symbolP
, T_NULL
);
342 S_SET_STORAGE_CLASS (symbolP
, 0);
343 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
345 if (S_IS_STRING (symbolP
))
346 SF_SET_STRING (symbolP
);
347 if (!underscore
&& S_IS_LOCAL (symbolP
))
348 SF_SET_LOCAL (symbolP
);
353 * Handle .ln directives.
356 static symbolS
*current_lineno_sym
;
357 static struct line_no
*line_nos
;
358 /* @@ Blindly assume all .ln directives will be in the .text section... */
362 add_lineno (frag
, offset
, num
)
367 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
368 sizeof (struct line_no
));
369 if (!current_lineno_sym
)
373 new_line
->next
= line_nos
;
374 new_line
->frag
= frag
;
375 new_line
->l
.line_number
= num
;
376 new_line
->l
.u
.offset
= offset
;
382 coff_add_linesym (sym
)
387 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
391 current_lineno_sym
= sym
;
395 obj_coff_ln (appline
)
400 if (! appline
&& def_symbol_in_progress
!= NULL
)
402 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
403 demand_empty_rest_of_line ();
407 l
= get_absolute_expression ();
410 add_lineno (frag_now
, frag_now_fix (), l
);
414 new_logical_line ((char *) NULL
, l
- 1);
423 l
+= coff_line_base
- 1;
424 listing_source_line (l
);
429 demand_empty_rest_of_line ();
435 * Handle .def directives.
437 * One might ask : why can't we symbol_new if the symbol does not
438 * already exist and fill it with debug information. Because of
439 * the C_EFCN special symbol. It would clobber the value of the
440 * function symbol before we have a chance to notice that it is
441 * a C_EFCN. And a second reason is that the code is more clear this
442 * way. (at least I think it is :-).
446 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
447 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
448 *input_line_pointer == '\t') \
449 input_line_pointer++;
455 char name_end
; /* Char after the end of name */
456 char *symbol_name
; /* Name of the debug symbol */
457 char *symbol_name_copy
; /* Temporary copy of the name */
458 unsigned int symbol_name_length
;
460 if (def_symbol_in_progress
!= NULL
)
462 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
463 demand_empty_rest_of_line ();
465 } /* if not inside .def/.endef */
469 symbol_name
= input_line_pointer
;
470 #ifdef STRIP_UNDERSCORE
471 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
473 #endif /* STRIP_UNDERSCORE */
475 name_end
= get_symbol_end ();
476 symbol_name_length
= strlen (symbol_name
);
477 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
478 strcpy (symbol_name_copy
, symbol_name
);
479 #ifdef tc_canonicalize_symbol_name
480 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
483 /* Initialize the new symbol */
484 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
485 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
486 S_SET_VALUE (def_symbol_in_progress
, 0);
488 if (S_IS_STRING (def_symbol_in_progress
))
489 SF_SET_STRING (def_symbol_in_progress
);
491 *input_line_pointer
= name_end
;
493 demand_empty_rest_of_line ();
496 unsigned int dim_index
;
499 obj_coff_endef (ignore
)
503 /* DIM BUG FIX sac@cygnus.com */
505 if (def_symbol_in_progress
== NULL
)
507 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
508 demand_empty_rest_of_line ();
510 } /* if not inside .def/.endef */
512 /* Set the section number according to storage class. */
513 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
518 SF_SET_TAG (def_symbol_in_progress
);
519 /* intentional fallthrough */
522 SF_SET_DEBUG (def_symbol_in_progress
);
523 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
527 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
528 /* intentional fallthrough */
530 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
531 /* intentional fallthrough */
535 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
537 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
538 if (name
[1] == 'b' && name
[2] == 'f')
540 if (! in_function ())
541 as_warn ("`%s' symbol without preceding function", name
);
542 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
543 /* Will need relocating */
544 SF_SET_PROCESS (def_symbol_in_progress
);
552 #endif /* C_AUTOARG */
558 SF_SET_DEBUG (def_symbol_in_progress
);
559 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
566 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
572 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
578 as_warn ("unexpected storage class %d",
579 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
581 } /* switch on storage class */
583 /* Now that we have built a debug symbol, try to find if we should
584 merge with an existing symbol or not. If a symbol is C_EFCN or
585 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
587 /* Two cases for functions. Either debug followed by definition or
588 definition followed by debug. For definition first, we will
589 merge the debug symbol into the definition. For debug first, the
590 lineno entry MUST point to the definition function or else it
591 will point off into space when obj_crawl_symbol_chain() merges
592 the debug symbol into the real symbol. Therefor, let's presume
593 the debug symbol is a real function reference. */
595 /* FIXME-SOON If for some reason the definition label/symbol is
596 never seen, this will probably leave an undefined symbol at link
599 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
600 || (!strcmp (bfd_get_section_name (stdoutput
,
601 S_GET_SEGMENT (def_symbol_in_progress
)),
603 && !SF_GET_TAG (def_symbol_in_progress
))
604 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
605 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
607 if (def_symbol_in_progress
!= symbol_lastP
)
608 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
613 /* This symbol already exists, merge the newly created symbol
614 into the old one. This is not mandatory. The linker can
615 handle duplicate symbols correctly. But I guess that it save
616 a *lot* of space if the assembly file defines a lot of
619 /* The debug entry (def_symbol_in_progress) is merged into the
620 previous definition. */
622 c_symbol_merge (def_symbol_in_progress
, symbolP
);
623 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
625 def_symbol_in_progress
= symbolP
;
627 if (SF_GET_FUNCTION (def_symbol_in_progress
)
628 || SF_GET_TAG (def_symbol_in_progress
)
629 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
631 /* For functions, and tags, and static symbols, the symbol
632 *must* be where the debug symbol appears. Move the
633 existing symbol to the current place. */
634 /* If it already is at the end of the symbol list, do nothing */
635 if (def_symbol_in_progress
!= symbol_lastP
)
637 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
638 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
643 if (SF_GET_TAG (def_symbol_in_progress
))
647 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
649 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
650 tag_insert (S_GET_NAME (def_symbol_in_progress
),
651 def_symbol_in_progress
);
654 if (SF_GET_FUNCTION (def_symbol_in_progress
))
656 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
657 set_function (def_symbol_in_progress
);
658 SF_SET_PROCESS (def_symbol_in_progress
);
662 /* That is, if this is the first time we've seen the
664 symbol_table_insert (def_symbol_in_progress
);
665 } /* definition follows debug */
666 } /* Create the line number entry pointing to the function being defined */
668 def_symbol_in_progress
= NULL
;
669 demand_empty_rest_of_line ();
673 obj_coff_dim (ignore
)
678 if (def_symbol_in_progress
== NULL
)
680 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
681 demand_empty_rest_of_line ();
683 } /* if not inside .def/.endef */
685 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
687 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
690 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
691 get_absolute_expression ());
693 switch (*input_line_pointer
)
696 input_line_pointer
++;
700 as_warn ("badly formed .dim directive ignored");
701 /* intentional fallthrough */
709 demand_empty_rest_of_line ();
713 obj_coff_line (ignore
)
718 if (def_symbol_in_progress
== NULL
)
720 /* Probably stabs-style line? */
725 this_base
= get_absolute_expression ();
726 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
727 coff_line_base
= this_base
;
729 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
730 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
732 demand_empty_rest_of_line ();
735 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
740 listing_source_line ((unsigned int) coff_line_base
);
746 obj_coff_size (ignore
)
749 if (def_symbol_in_progress
== NULL
)
751 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
752 demand_empty_rest_of_line ();
754 } /* if not inside .def/.endef */
756 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
757 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
758 demand_empty_rest_of_line ();
762 obj_coff_scl (ignore
)
765 if (def_symbol_in_progress
== NULL
)
767 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
768 demand_empty_rest_of_line ();
770 } /* if not inside .def/.endef */
772 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
773 demand_empty_rest_of_line ();
777 obj_coff_tag (ignore
)
783 if (def_symbol_in_progress
== NULL
)
785 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
786 demand_empty_rest_of_line ();
790 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
791 symbol_name
= input_line_pointer
;
792 name_end
= get_symbol_end ();
794 #ifdef tc_canonicalize_symbol_name
795 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
798 /* Assume that the symbol referred to by .tag is always defined.
799 This was a bad assumption. I've added find_or_make. xoxorich. */
800 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
801 tag_find_or_make (symbol_name
));
802 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
804 as_warn ("tag not found for .tag %s", symbol_name
);
807 SF_SET_TAGGED (def_symbol_in_progress
);
808 *input_line_pointer
= name_end
;
810 demand_empty_rest_of_line ();
814 obj_coff_type (ignore
)
817 if (def_symbol_in_progress
== NULL
)
819 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
820 demand_empty_rest_of_line ();
822 } /* if not inside .def/.endef */
824 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
826 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
827 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
829 SF_SET_FUNCTION (def_symbol_in_progress
);
830 } /* is a function */
832 demand_empty_rest_of_line ();
836 obj_coff_val (ignore
)
839 if (def_symbol_in_progress
== NULL
)
841 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
842 demand_empty_rest_of_line ();
844 } /* if not inside .def/.endef */
846 if (is_name_beginner (*input_line_pointer
))
848 char *symbol_name
= input_line_pointer
;
849 char name_end
= get_symbol_end ();
851 #ifdef tc_canonicalize_symbol_name
852 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
854 if (!strcmp (symbol_name
, "."))
856 def_symbol_in_progress
->sy_frag
= frag_now
;
857 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
858 /* If the .val is != from the .def (e.g. statics) */
860 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
862 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
863 def_symbol_in_progress
->sy_value
.X_add_symbol
=
864 symbol_find_or_make (symbol_name
);
865 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
866 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
868 /* If the segment is undefined when the forward reference is
869 resolved, then copy the segment id from the forward
871 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
873 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
874 *input_line_pointer
= name_end
;
878 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
879 } /* if symbol based */
881 demand_empty_rest_of_line ();
885 obj_read_begin_hook ()
887 /* These had better be the same. Usually 18 bytes. */
889 know (sizeof (SYMENT
) == sizeof (AUXENT
));
890 know (SYMESZ
== AUXESZ
);
896 symbolS
*coff_last_function
;
897 static symbolS
*coff_last_bf
;
900 coff_frob_symbol (symp
, punt
)
904 static symbolS
*last_tagP
;
905 static stack
*block_stack
;
906 static symbolS
*set_end
;
907 symbolS
*next_set_end
= NULL
;
909 if (symp
== &abs_symbol
)
915 if (current_lineno_sym
)
916 coff_add_linesym ((symbolS
*) 0);
919 block_stack
= stack_init (512, sizeof (symbolS
*));
921 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
922 S_SET_STORAGE_CLASS (symp
, C_EXT
);
924 if (!SF_GET_DEBUG (symp
))
927 if (!SF_GET_LOCAL (symp
)
928 && !SF_GET_STATICS (symp
)
929 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
932 c_symbol_merge (symp
, real
);
935 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
937 assert (S_GET_VALUE (symp
) == 0);
938 S_SET_EXTERNAL (symp
);
940 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
942 if (S_GET_SEGMENT (symp
) == text_section
943 && symp
!= seg_info (text_section
)->sym
)
944 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
946 S_SET_STORAGE_CLASS (symp
, C_STAT
);
948 if (SF_GET_PROCESS (symp
))
950 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
952 if (!strcmp (S_GET_NAME (symp
), ".bb"))
953 stack_push (block_stack
, (char *) &symp
);
957 begin
= *(symbolS
**) stack_pop (block_stack
);
959 as_warn ("mismatched .eb");
961 next_set_end
= begin
;
964 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
966 union internal_auxent
*auxp
;
967 coff_last_function
= symp
;
968 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
969 S_SET_NUMBER_AUXILIARY (symp
, 1);
970 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
971 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
972 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
974 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
976 if (coff_last_function
== 0)
977 as_fatal ("C_EFCN symbol out of scope");
978 SA_SET_SYM_FSIZE (coff_last_function
,
979 (long) (S_GET_VALUE (symp
)
980 - S_GET_VALUE (coff_last_function
)));
981 next_set_end
= coff_last_function
;
982 coff_last_function
= 0;
985 if (S_IS_EXTERNAL (symp
))
986 S_SET_STORAGE_CLASS (symp
, C_EXT
);
987 else if (SF_GET_LOCAL (symp
))
990 if (SF_GET_FUNCTION (symp
))
991 symp
->bsym
->flags
|= BSF_FUNCTION
;
996 if (SF_GET_TAG (symp
))
998 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
999 next_set_end
= last_tagP
;
1002 /* This is pretty horrible, but we have to set *punt correctly in
1003 order to call SA_SET_SYM_ENDNDX correctly. */
1004 if (! symp
->sy_used_in_reloc
1005 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1006 || (! S_IS_EXTERNAL (symp
)
1007 && ! symp
->sy_tc
.output
1008 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1012 if (set_end
!= (symbolS
*) NULL
1014 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1015 || (S_IS_DEFINED (symp
)
1016 && ! S_IS_COMMON (symp
)
1017 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1019 SA_SET_SYM_ENDNDX (set_end
, symp
);
1023 if (next_set_end
!= NULL
1025 set_end
= next_set_end
;
1028 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1029 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1031 if (coff_last_bf
!= NULL
)
1032 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1033 coff_last_bf
= symp
;
1036 if (coffsymbol (symp
->bsym
)->lineno
)
1039 struct line_no
*lptr
;
1042 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1043 for (i
= 0; lptr
; lptr
= lptr
->next
)
1045 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1047 /* We need i entries for line numbers, plus 1 for the first
1048 entry which BFD will override, plus 1 for the last zero
1049 entry (a marker for BFD). */
1050 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1051 coffsymbol (symp
->bsym
)->lineno
= l
;
1052 l
[i
+ 1].line_number
= 0;
1053 l
[i
+ 1].u
.sym
= NULL
;
1057 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1065 coff_adjust_section_syms (abfd
, sec
, x
)
1071 segment_info_type
*seginfo
= seg_info (sec
);
1072 int nlnno
, nrelocs
= 0;
1074 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1075 tc-ppc.c. Do not get confused by it. */
1076 if (seginfo
== NULL
)
1079 if (!strcmp (sec
->name
, ".text"))
1080 nlnno
= coff_n_line_nos
;
1084 /* @@ Hope that none of the fixups expand to more than one reloc
1086 fixS
*fixp
= seginfo
->fix_root
;
1089 fixp
= fixp
->fx_next
;
1093 if (bfd_get_section_size_before_reloc (sec
) == 0
1096 && sec
!= text_section
1097 && sec
!= data_section
1098 && sec
!= bss_section
)
1100 secsym
= section_symbol (sec
);
1101 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1102 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1108 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1112 * implement the .section pseudo op:
1113 * .section name {, "flags"}
1115 * | +--- optional flags: 'b' for bss
1117 * +-- section name 'l' for lib
1121 * 'd' (apparently m88k for data)
1123 * But if the argument is not a quoted string, treat it as a
1124 * subsegment number.
1128 obj_coff_section (ignore
)
1131 /* Strip out the section name */
1147 section_name
= input_line_pointer
;
1148 c
= get_symbol_end ();
1150 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1151 strcpy (name
, section_name
);
1153 *input_line_pointer
= c
;
1158 flags
= SEC_NO_FLAGS
;
1160 if (*input_line_pointer
== ',')
1162 ++input_line_pointer
;
1164 if (*input_line_pointer
!= '"')
1165 exp
= get_absolute_expression ();
1168 ++input_line_pointer
;
1169 while (*input_line_pointer
!= '"'
1170 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1172 switch (*input_line_pointer
)
1174 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1175 case 'n': flags
&=~ SEC_LOAD
; break;
1177 case 'w': flags
&=~ SEC_READONLY
; break;
1178 case 'x': flags
|= SEC_CODE
; break;
1180 case 'i': /* STYP_INFO */
1181 case 'l': /* STYP_LIB */
1182 case 'o': /* STYP_OVER */
1183 as_warn ("unsupported section attribute '%c'",
1184 *input_line_pointer
);
1188 as_warn("unknown section attribute '%c'",
1189 *input_line_pointer
);
1192 ++input_line_pointer
;
1194 if (*input_line_pointer
== '"')
1195 ++input_line_pointer
;
1199 sec
= subseg_new (name
, (subsegT
) exp
);
1201 if (flags
!= SEC_NO_FLAGS
)
1203 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1204 as_warn ("error setting flags for \"%s\": %s",
1205 bfd_section_name (stdoutput
, sec
),
1206 bfd_errmsg (bfd_get_error ()));
1209 demand_empty_rest_of_line ();
1213 coff_adjust_symtab ()
1215 if (symbol_rootP
== NULL
1216 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1217 c_dot_file_symbol ("fake");
1221 coff_frob_section (sec
)
1227 bfd_vma size
, n_entries
, mask
;
1229 /* The COFF back end in BFD requires that all section sizes be
1230 rounded up to multiples of the corresponding section alignments.
1231 Seems kinda silly to me, but that's the way it is. */
1232 size
= bfd_get_section_size_before_reloc (sec
);
1233 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1236 size
= (size
+ mask
) & ~mask
;
1237 bfd_set_section_size (stdoutput
, sec
, size
);
1240 /* If the section size is non-zero, the section symbol needs an aux
1241 entry associated with it, indicating the size. We don't know
1242 all the values yet; coff_frob_symbol will fill them in later. */
1244 || sec
== text_section
1245 || sec
== data_section
1246 || sec
== bss_section
)
1248 symbolS
*secsym
= section_symbol (sec
);
1250 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1251 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1252 SF_SET_STATICS (secsym
);
1253 SA_SET_SCN_SCNLEN (secsym
, size
);
1256 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1257 #ifndef STAB_SECTION_NAME
1258 #define STAB_SECTION_NAME ".stab"
1260 #ifndef STAB_STRING_SECTION_NAME
1261 #define STAB_STRING_SECTION_NAME ".stabstr"
1263 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1267 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1268 /* size is already rounded up, since other section will be listed first */
1269 size
= bfd_get_section_size_before_reloc (strsec
);
1271 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1273 /* Find first non-empty frag. It should be large enough. */
1274 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1275 while (fragp
&& fragp
->fr_fix
== 0)
1276 fragp
= fragp
->fr_next
;
1277 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1279 /* Store the values. */
1280 p
= fragp
->fr_literal
;
1281 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1282 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1286 obj_coff_init_stab_section (seg
)
1292 unsigned int stroff
;
1294 /* Make space for this first symbol. */
1298 as_where (&file
, (unsigned int *) NULL
);
1299 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1300 strcpy (stabstr_name
, seg
->name
);
1301 strcat (stabstr_name
, "str");
1302 stroff
= get_stab_string_offset (file
, stabstr_name
);
1304 md_number_to_chars (p
, stroff
, 4);
1313 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1321 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1323 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1324 (unsigned long) symbolP
,
1325 S_GET_NAME(symbolP
),
1326 (long) S_GET_DATA_TYPE(symbolP
),
1327 S_GET_STORAGE_CLASS(symbolP
),
1328 (int) S_GET_SEGMENT(symbolP
));
1334 #else /* not BFD_ASSEMBLER */
1337 /* This is needed because we include internal bfd things. */
1341 #include "libcoff.h"
1344 #include "coff/pe.h"
1347 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1348 that we can stick sections together without causing trouble. */
1350 #define NOP_OPCODE 0x00
1353 /* The zeroes if symbol name is longer than 8 chars */
1354 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1356 #define MIN(a,b) ((a) < (b)? (a) : (b))
1357 /* This vector is used to turn an internal segment into a section #
1358 suitable for insertion into a coff symbol table
1361 const short seg_N_TYPE
[] =
1362 { /* in: segT out: N_TYPE bits */
1364 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1365 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1366 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1367 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1368 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1369 C_UNDEF_SECTION
, /* SEG_GOOF */
1370 C_UNDEF_SECTION
, /* SEG_EXPR */
1371 C_DEBUG_SECTION
, /* SEG_DEBUG */
1372 C_NTV_SECTION
, /* SEG_NTV */
1373 C_PTV_SECTION
, /* SEG_PTV */
1374 C_REGISTER_SECTION
, /* SEG_REGISTER */
1377 int function_lineoff
= -1; /* Offset in line#s where the last function
1378 started (the odd entry for line #0) */
1380 /* structure used to keep the filenames which
1381 are too long around so that we can stick them
1382 into the string table */
1383 struct filename_list
1386 struct filename_list
*next
;
1389 static struct filename_list
*filename_list_head
;
1390 static struct filename_list
*filename_list_tail
;
1392 static symbolS
*last_line_symbol
;
1394 /* Add 4 to the real value to get the index and compensate the
1395 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1396 section number into a segment number
1398 static symbolS
*previous_file_symbol
;
1399 void c_symbol_merge ();
1400 static int line_base
;
1402 symbolS
*c_section_symbol ();
1405 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1406 segT this_segment_type
));
1409 static void fixup_mdeps
PARAMS ((fragS
*,
1414 static void fill_section
PARAMS ((bfd
* abfd
,
1419 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1424 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1425 symbolS
* symbol_rootP
));
1427 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1429 static void obj_coff_lcomm
PARAMS ((int));
1430 static void obj_coff_text
PARAMS ((int));
1431 static void obj_coff_data
PARAMS ((int));
1432 static void obj_coff_bss
PARAMS ((int));
1433 static void obj_coff_ident
PARAMS ((int));
1434 void obj_coff_section
PARAMS ((int));
1438 We allow more than just the standard 3 sections, infact, we allow
1439 40 sections, (though the usual three have to be there).
1441 This structure performs the mappings for us:
1451 static const seg_info_type seg_info_off_by_4
[] =
1458 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1459 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1460 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1461 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1462 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1463 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1464 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1465 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1480 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1482 static relax_addressT
1483 relax_align (address
, alignment
)
1484 relax_addressT address
;
1487 relax_addressT mask
;
1488 relax_addressT new_address
;
1490 mask
= ~((~0) << alignment
);
1491 new_address
= (address
+ mask
) & (~mask
);
1492 return (new_address
- address
);
1500 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1505 /* calculate the size of the frag chain and fill in the section header
1506 to contain all of it, also fill in the addr of the sections */
1508 size_section (abfd
, idx
)
1513 unsigned int size
= 0;
1514 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1517 size
= frag
->fr_address
;
1518 if (frag
->fr_address
!= size
)
1520 fprintf (stderr
, "Out of step\n");
1521 size
= frag
->fr_address
;
1524 switch (frag
->fr_type
)
1526 #ifdef TC_COFF_SIZEMACHDEP
1527 case rs_machine_dependent
:
1528 size
+= TC_COFF_SIZEMACHDEP (frag
);
1532 assert (frag
->fr_symbol
== 0);
1535 size
+= frag
->fr_fix
;
1536 size
+= frag
->fr_offset
* frag
->fr_var
;
1543 size
+= frag
->fr_fix
;
1544 off
= relax_align (size
, frag
->fr_offset
);
1545 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1551 BAD_CASE (frag
->fr_type
);
1554 frag
= frag
->fr_next
;
1556 segment_info
[idx
].scnhdr
.s_size
= size
;
1562 count_entries_in_chain (idx
)
1565 unsigned int nrelocs
;
1568 /* Count the relocations */
1569 fixup_ptr
= segment_info
[idx
].fix_root
;
1571 while (fixup_ptr
!= (fixS
*) NULL
)
1573 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1576 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1585 fixup_ptr
= fixup_ptr
->fx_next
;
1592 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1594 /* AUX's ld expects relocations to be sorted */
1596 compare_external_relocs (x
, y
)
1600 struct external_reloc
*a
= (struct external_reloc
*) x
;
1601 struct external_reloc
*b
= (struct external_reloc
*) y
;
1602 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1603 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1604 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1609 /* output all the relocations for a section */
1611 do_relocs_for (abfd
, h
, file_cursor
)
1614 unsigned long *file_cursor
;
1616 unsigned int nrelocs
;
1618 unsigned long reloc_start
= *file_cursor
;
1620 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1622 if (segment_info
[idx
].scnhdr
.s_name
[0])
1624 struct external_reloc
*ext_ptr
;
1625 struct external_reloc
*external_reloc_vec
;
1626 unsigned int external_reloc_size
;
1627 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1628 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1629 nrelocs
= count_entries_in_chain (idx
);
1632 /* Bypass this stuff if no relocs. This also incidentally
1633 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1635 external_reloc_size
= nrelocs
* RELSZ
;
1636 external_reloc_vec
=
1637 (struct external_reloc
*) malloc (external_reloc_size
);
1639 ext_ptr
= external_reloc_vec
;
1641 /* Fill in the internal coff style reloc struct from the
1642 internal fix list. */
1645 struct internal_reloc intr
;
1647 /* Only output some of the relocations */
1648 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1650 #ifdef TC_RELOC_MANGLE
1651 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1656 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1658 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1660 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1662 #ifdef TC_KEEP_FX_OFFSET
1663 intr
.r_offset
= fix_ptr
->fx_offset
;
1668 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1669 && (! S_IS_DEFINED (symbol_ptr
)
1670 || S_IS_COMMON (symbol_ptr
)))
1674 /* We must avoid looping, as that can occur
1675 with a badly written program. */
1676 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1677 if (n
== symbol_ptr
)
1682 /* Turn the segment of the symbol into an offset. */
1685 resolve_symbol_value (symbol_ptr
);
1686 if (! symbol_ptr
->sy_resolved
)
1691 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1692 as_bad_where (file
, line
,
1693 "unresolved relocation");
1695 as_bad ("bad relocation: symbol `%s' not in symbol table",
1696 S_GET_NAME (symbol_ptr
));
1698 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1701 intr
.r_symndx
= dot
->sy_number
;
1705 intr
.r_symndx
= symbol_ptr
->sy_number
;
1715 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1718 #if defined(TC_A29K)
1720 /* The 29k has a special kludge for the high 16 bit
1721 reloc. Two relocations are emited, R_IHIHALF,
1722 and R_IHCONST. The second one doesn't contain a
1723 symbol, but uses the value for offset. */
1725 if (intr
.r_type
== R_IHIHALF
)
1727 /* now emit the second bit */
1728 intr
.r_type
= R_IHCONST
;
1729 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1730 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1736 fix_ptr
= fix_ptr
->fx_next
;
1740 /* Sort the reloc table */
1741 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1742 sizeof (struct external_reloc
), compare_external_relocs
);
1745 /* Write out the reloc table */
1746 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1748 free (external_reloc_vec
);
1750 /* Fill in section header info. */
1751 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1752 *file_cursor
+= external_reloc_size
;
1753 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1758 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1762 /* Set relocation_size field in file headers */
1763 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1767 /* run through a frag chain and write out the data to go with it, fill
1768 in the scnhdrs with the info on the file postions
1771 fill_section (abfd
, h
, file_cursor
)
1774 unsigned long *file_cursor
;
1778 unsigned int paddr
= 0;
1780 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1782 unsigned int offset
= 0;
1783 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1789 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1796 buffer
= xmalloc (s
->s_size
);
1797 s
->s_scnptr
= *file_cursor
;
1799 know (s
->s_paddr
== paddr
);
1801 if (strcmp (s
->s_name
, ".text") == 0)
1802 s
->s_flags
|= STYP_TEXT
;
1803 else if (strcmp (s
->s_name
, ".data") == 0)
1804 s
->s_flags
|= STYP_DATA
;
1805 else if (strcmp (s
->s_name
, ".bss") == 0)
1808 s
->s_flags
|= STYP_BSS
;
1810 /* @@ Should make the i386 and a29k coff targets define
1811 COFF_NOLOAD_PROBLEM, and have only one test here. */
1814 #ifndef COFF_NOLOAD_PROBLEM
1815 /* Apparently the SVR3 linker (and exec syscall) and UDI
1816 mondfe progrem are confused by noload sections. */
1817 s
->s_flags
|= STYP_NOLOAD
;
1822 else if (strcmp (s
->s_name
, ".lit") == 0)
1823 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1824 else if (strcmp (s
->s_name
, ".init") == 0)
1825 s
->s_flags
|= STYP_TEXT
;
1826 else if (strcmp (s
->s_name
, ".fini") == 0)
1827 s
->s_flags
|= STYP_TEXT
;
1828 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1829 s
->s_flags
|= STYP_INFO
;
1833 unsigned int fill_size
;
1834 switch (frag
->fr_type
)
1836 case rs_machine_dependent
:
1839 memcpy (buffer
+ frag
->fr_address
,
1841 (unsigned int) frag
->fr_fix
);
1842 offset
+= frag
->fr_fix
;
1847 assert (frag
->fr_symbol
== 0);
1854 memcpy (buffer
+ frag
->fr_address
,
1856 (unsigned int) frag
->fr_fix
);
1857 offset
+= frag
->fr_fix
;
1860 fill_size
= frag
->fr_var
;
1861 if (fill_size
&& frag
->fr_offset
> 0)
1864 unsigned int off
= frag
->fr_fix
;
1865 for (count
= frag
->fr_offset
; count
; count
--)
1867 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1869 memcpy (buffer
+ frag
->fr_address
+ off
,
1870 frag
->fr_literal
+ frag
->fr_fix
,
1873 offset
+= fill_size
;
1878 case rs_broken_word
:
1883 frag
= frag
->fr_next
;
1888 if (s
->s_scnptr
!= 0)
1890 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1891 *file_cursor
+= s
->s_size
;
1900 /* Coff file generation & utilities */
1903 coff_header_append (abfd
, h
)
1911 bfd_seek (abfd
, 0, 0);
1913 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1914 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1915 H_SET_VERSION_STAMP (h
, 0);
1916 H_SET_ENTRY_POINT (h
, 0);
1917 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1918 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1919 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1921 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1922 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1923 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1925 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1927 bfd_write (buffer
, i
, 1, abfd
);
1928 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1930 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1932 #ifdef COFF_LONG_SECTION_NAMES
1933 unsigned long string_size
= 4;
1936 if (segment_info
[i
].scnhdr
.s_name
[0])
1940 #ifdef COFF_LONG_SECTION_NAMES
1941 /* Support long section names as found in PE. This code
1942 must coordinate with that in write_object_file and
1944 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1946 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1947 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1948 string_size
+= strlen (segment_info
[i
].name
) + 1;
1952 size
= bfd_coff_swap_scnhdr_out (abfd
,
1953 &(segment_info
[i
].scnhdr
),
1956 as_bad ("bfd_coff_swap_scnhdr_out failed");
1957 bfd_write (buffer
, size
, 1, abfd
);
1964 symbol_to_chars (abfd
, where
, symbolP
)
1969 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1973 /* Turn any symbols with register attributes into abs symbols */
1974 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1976 S_SET_SEGMENT (symbolP
, absolute_section
);
1978 /* At the same time, relocate all symbols to their output value */
1980 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1981 + S_GET_VALUE (symbolP
));
1983 S_SET_VALUE (symbolP
, val
);
1985 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1987 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1990 for (i
= 0; i
< numaux
; i
++)
1992 where
+= bfd_coff_swap_aux_out (abfd
,
1993 &symbolP
->sy_symbol
.ost_auxent
[i
],
1994 S_GET_DATA_TYPE (symbolP
),
1995 S_GET_STORAGE_CLASS (symbolP
),
2003 obj_symbol_new_hook (symbolP
)
2006 char underscore
= 0; /* Symbol has leading _ */
2008 /* Effective symbol */
2009 /* Store the pointer in the offset. */
2010 S_SET_ZEROES (symbolP
, 0L);
2011 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2012 S_SET_STORAGE_CLASS (symbolP
, 0);
2013 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2014 /* Additional information */
2015 symbolP
->sy_symbol
.ost_flags
= 0;
2016 /* Auxiliary entries */
2017 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2019 if (S_IS_STRING (symbolP
))
2020 SF_SET_STRING (symbolP
);
2021 if (!underscore
&& S_IS_LOCAL (symbolP
))
2022 SF_SET_LOCAL (symbolP
);
2026 * Handle .ln directives.
2030 obj_coff_ln (appline
)
2035 if (! appline
&& def_symbol_in_progress
!= NULL
)
2037 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2038 demand_empty_rest_of_line ();
2040 } /* wrong context */
2042 l
= get_absolute_expression ();
2043 c_line_new (0, frag_now_fix (), l
, frag_now
);
2046 new_logical_line ((char *) NULL
, l
- 1);
2056 listing_source_line ((unsigned int) l
);
2061 demand_empty_rest_of_line ();
2067 * Handle .def directives.
2069 * One might ask : why can't we symbol_new if the symbol does not
2070 * already exist and fill it with debug information. Because of
2071 * the C_EFCN special symbol. It would clobber the value of the
2072 * function symbol before we have a chance to notice that it is
2073 * a C_EFCN. And a second reason is that the code is more clear this
2074 * way. (at least I think it is :-).
2078 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2079 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2080 *input_line_pointer == '\t') \
2081 input_line_pointer++;
2087 char name_end
; /* Char after the end of name */
2088 char *symbol_name
; /* Name of the debug symbol */
2089 char *symbol_name_copy
; /* Temporary copy of the name */
2090 unsigned int symbol_name_length
;
2092 if (def_symbol_in_progress
!= NULL
)
2094 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2095 demand_empty_rest_of_line ();
2097 } /* if not inside .def/.endef */
2099 SKIP_WHITESPACES ();
2101 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2102 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2104 symbol_name
= input_line_pointer
;
2105 name_end
= get_symbol_end ();
2106 symbol_name_length
= strlen (symbol_name
);
2107 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2108 strcpy (symbol_name_copy
, symbol_name
);
2109 #ifdef tc_canonicalize_symbol_name
2110 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2113 /* Initialize the new symbol */
2114 #ifdef STRIP_UNDERSCORE
2115 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2116 ? symbol_name_copy
+ 1
2117 : symbol_name_copy
));
2118 #else /* STRIP_UNDERSCORE */
2119 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2120 #endif /* STRIP_UNDERSCORE */
2121 /* free(symbol_name_copy); */
2122 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2123 def_symbol_in_progress
->sy_number
= ~0;
2124 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2125 S_SET_VALUE (def_symbol_in_progress
, 0);
2127 if (S_IS_STRING (def_symbol_in_progress
))
2128 SF_SET_STRING (def_symbol_in_progress
);
2130 *input_line_pointer
= name_end
;
2132 demand_empty_rest_of_line ();
2135 unsigned int dim_index
;
2139 obj_coff_endef (ignore
)
2142 symbolS
*symbolP
= 0;
2143 /* DIM BUG FIX sac@cygnus.com */
2145 if (def_symbol_in_progress
== NULL
)
2147 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2148 demand_empty_rest_of_line ();
2150 } /* if not inside .def/.endef */
2152 /* Set the section number according to storage class. */
2153 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2158 SF_SET_TAG (def_symbol_in_progress
);
2159 /* intentional fallthrough */
2162 SF_SET_DEBUG (def_symbol_in_progress
);
2163 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2167 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2168 /* intentional fallthrough */
2170 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2171 /* intentional fallthrough */
2173 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2175 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2177 if (function_lineoff
< 0)
2179 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2180 } /* missing function symbol */
2181 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2183 SF_SET_PROCESS (last_line_symbol
);
2184 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2185 SF_SET_PROCESS (def_symbol_in_progress
);
2186 function_lineoff
= -1;
2188 /* Value is always set to . */
2189 def_symbol_in_progress
->sy_frag
= frag_now
;
2190 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2195 #endif /* C_AUTOARG */
2205 SF_SET_DEBUG (def_symbol_in_progress
);
2206 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2212 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2218 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2220 } /* switch on storage class */
2222 /* Now that we have built a debug symbol, try to find if we should
2223 merge with an existing symbol or not. If a symbol is C_EFCN or
2224 absolute_section or untagged SEG_DEBUG it never merges. We also
2225 don't merge labels, which are in a different namespace, nor
2226 symbols which have not yet been defined since they are typically
2227 unique, nor do we merge tags with non-tags. */
2229 /* Two cases for functions. Either debug followed by definition or
2230 definition followed by debug. For definition first, we will
2231 merge the debug symbol into the definition. For debug first, the
2232 lineno entry MUST point to the definition function or else it
2233 will point off into space when crawl_symbols() merges the debug
2234 symbol into the real symbol. Therefor, let's presume the debug
2235 symbol is a real function reference. */
2237 /* FIXME-SOON If for some reason the definition label/symbol is
2238 never seen, this will probably leave an undefined symbol at link
2241 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2242 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2243 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2244 && !SF_GET_TAG (def_symbol_in_progress
))
2245 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2246 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2247 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2248 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2250 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2255 /* This symbol already exists, merge the newly created symbol
2256 into the old one. This is not mandatory. The linker can
2257 handle duplicate symbols correctly. But I guess that it save
2258 a *lot* of space if the assembly file defines a lot of
2261 /* The debug entry (def_symbol_in_progress) is merged into the
2262 previous definition. */
2264 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2265 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2266 def_symbol_in_progress
= symbolP
;
2268 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2269 || SF_GET_TAG (def_symbol_in_progress
)
2270 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2272 /* For functions, and tags, and static symbols, the symbol
2273 *must* be where the debug symbol appears. Move the
2274 existing symbol to the current place. */
2275 /* If it already is at the end of the symbol list, do nothing */
2276 if (def_symbol_in_progress
!= symbol_lastP
)
2278 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2280 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2281 &symbol_rootP
, &symbol_lastP
);
2282 } /* if not already in place */
2284 } /* normal or mergable */
2286 if (SF_GET_TAG (def_symbol_in_progress
))
2290 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2292 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2293 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2294 def_symbol_in_progress
);
2297 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2299 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2301 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2303 SF_SET_PROCESS (def_symbol_in_progress
);
2305 if (symbolP
== NULL
)
2307 /* That is, if this is the first time we've seen the
2309 symbol_table_insert (def_symbol_in_progress
);
2310 } /* definition follows debug */
2311 } /* Create the line number entry pointing to the function being defined */
2313 def_symbol_in_progress
= NULL
;
2314 demand_empty_rest_of_line ();
2318 obj_coff_dim (ignore
)
2323 if (def_symbol_in_progress
== NULL
)
2325 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2326 demand_empty_rest_of_line ();
2328 } /* if not inside .def/.endef */
2330 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2332 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2334 SKIP_WHITESPACES ();
2335 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2336 get_absolute_expression ());
2338 switch (*input_line_pointer
)
2341 input_line_pointer
++;
2345 as_warn ("badly formed .dim directive ignored");
2346 /* intentional fallthrough */
2354 demand_empty_rest_of_line ();
2358 obj_coff_line (ignore
)
2364 if (def_symbol_in_progress
== NULL
)
2370 name
= S_GET_NAME (def_symbol_in_progress
);
2371 this_base
= get_absolute_expression ();
2373 /* Only .bf symbols indicate the use of a new base line number; the
2374 line numbers associated with .ef, .bb, .eb are relative to the
2375 start of the containing function. */
2376 if (!strcmp (".bf", name
))
2378 #if 0 /* XXX Can we ever have line numbers going backwards? */
2379 if (this_base
> line_base
)
2382 line_base
= this_base
;
2390 listing_source_line ((unsigned int) line_base
);
2396 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2397 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2399 demand_empty_rest_of_line ();
2403 obj_coff_size (ignore
)
2406 if (def_symbol_in_progress
== NULL
)
2408 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2409 demand_empty_rest_of_line ();
2411 } /* if not inside .def/.endef */
2413 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2414 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2415 demand_empty_rest_of_line ();
2419 obj_coff_scl (ignore
)
2422 if (def_symbol_in_progress
== NULL
)
2424 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2425 demand_empty_rest_of_line ();
2427 } /* if not inside .def/.endef */
2429 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2430 demand_empty_rest_of_line ();
2434 obj_coff_tag (ignore
)
2440 if (def_symbol_in_progress
== NULL
)
2442 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2443 demand_empty_rest_of_line ();
2447 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2448 symbol_name
= input_line_pointer
;
2449 name_end
= get_symbol_end ();
2450 #ifdef tc_canonicalize_symbol_name
2451 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2454 /* Assume that the symbol referred to by .tag is always defined.
2455 This was a bad assumption. I've added find_or_make. xoxorich. */
2456 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2457 (long) tag_find_or_make (symbol_name
));
2458 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2460 as_warn ("tag not found for .tag %s", symbol_name
);
2463 SF_SET_TAGGED (def_symbol_in_progress
);
2464 *input_line_pointer
= name_end
;
2466 demand_empty_rest_of_line ();
2470 obj_coff_type (ignore
)
2473 if (def_symbol_in_progress
== NULL
)
2475 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2476 demand_empty_rest_of_line ();
2478 } /* if not inside .def/.endef */
2480 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2482 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2483 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2485 SF_SET_FUNCTION (def_symbol_in_progress
);
2486 } /* is a function */
2488 demand_empty_rest_of_line ();
2492 obj_coff_val (ignore
)
2495 if (def_symbol_in_progress
== NULL
)
2497 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2498 demand_empty_rest_of_line ();
2500 } /* if not inside .def/.endef */
2502 if (is_name_beginner (*input_line_pointer
))
2504 char *symbol_name
= input_line_pointer
;
2505 char name_end
= get_symbol_end ();
2507 #ifdef tc_canonicalize_symbol_name
2508 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2511 if (!strcmp (symbol_name
, "."))
2513 def_symbol_in_progress
->sy_frag
= frag_now
;
2514 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2515 /* If the .val is != from the .def (e.g. statics) */
2517 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2519 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2520 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2521 symbol_find_or_make (symbol_name
);
2522 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2523 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2525 /* If the segment is undefined when the forward reference is
2526 resolved, then copy the segment id from the forward
2528 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2530 /* FIXME: gcc can generate address expressions
2531 here in unusual cases (search for "obscure"
2532 in sdbout.c). We just ignore the offset
2533 here, thus generating incorrect debugging
2534 information. We ignore the rest of the
2537 /* Otherwise, it is the name of a non debug symbol and
2538 its value will be calculated later. */
2539 *input_line_pointer
= name_end
;
2541 /* FIXME: this is to avoid an error message in the
2542 FIXME case mentioned just above. */
2543 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2544 ++input_line_pointer
;
2548 S_SET_VALUE (def_symbol_in_progress
,
2549 (valueT
) get_absolute_expression ());
2550 } /* if symbol based */
2552 demand_empty_rest_of_line ();
2557 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2558 read.c, which then calls this object file format specific routine. */
2561 obj_coff_pe_handle_link_once (type
)
2562 enum linkonce_type type
;
2564 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2566 /* We store the type in the seg_info structure, and use it to set up
2567 the auxiliary entry for the section symbol in c_section_symbol. */
2568 seg_info (now_seg
)->linkonce
= type
;
2574 obj_read_begin_hook ()
2576 /* These had better be the same. Usually 18 bytes. */
2578 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2579 know (SYMESZ
== AUXESZ
);
2584 /* This function runs through the symbol table and puts all the
2585 externals onto another chain */
2587 /* The chain of globals. */
2588 symbolS
*symbol_globalP
;
2589 symbolS
*symbol_global_lastP
;
2591 /* The chain of externals */
2592 symbolS
*symbol_externP
;
2593 symbolS
*symbol_extern_lastP
;
2596 symbolS
*last_functionP
;
2597 static symbolS
*last_bfP
;
2604 unsigned int symbol_number
= 0;
2605 unsigned int last_file_symno
= 0;
2607 struct filename_list
*filename_list_scan
= filename_list_head
;
2609 for (symbolP
= symbol_rootP
;
2611 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2613 if (symbolP
->sy_mri_common
)
2615 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2616 as_bad ("%s: global symbols not supported in common sections",
2617 S_GET_NAME (symbolP
));
2618 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2622 if (!SF_GET_DEBUG (symbolP
))
2624 /* Debug symbols do not need all this rubbish */
2625 symbolS
*real_symbolP
;
2627 /* L* and C_EFCN symbols never merge. */
2628 if (!SF_GET_LOCAL (symbolP
)
2629 && !SF_GET_STATICS (symbolP
)
2630 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2631 && symbolP
->sy_value
.X_op
== O_constant
2632 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2633 && real_symbolP
!= symbolP
)
2635 /* FIXME-SOON: where do dups come from?
2636 Maybe tag references before definitions? xoxorich. */
2637 /* Move the debug data from the debug symbol to the
2638 real symbol. Do NOT do the oposite (i.e. move from
2639 real symbol to debug symbol and remove real symbol from the
2640 list.) Because some pointers refer to the real symbol
2641 whereas no pointers refer to the debug symbol. */
2642 c_symbol_merge (symbolP
, real_symbolP
);
2643 /* Replace the current symbol by the real one */
2644 /* The symbols will never be the last or the first
2645 because : 1st symbol is .file and 3 last symbols are
2646 .text, .data, .bss */
2647 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2648 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2649 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2650 symbolP
= real_symbolP
;
2651 } /* if not local but dup'd */
2653 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2655 S_SET_SEGMENT (symbolP
, SEG_E0
);
2656 } /* push data into text */
2658 resolve_symbol_value (symbolP
);
2660 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2662 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2664 S_SET_EXTERNAL (symbolP
);
2666 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2668 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2672 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2676 /* Mainly to speed up if not -g */
2677 if (SF_GET_PROCESS (symbolP
))
2679 /* Handle the nested blocks auxiliary info. */
2680 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2682 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2683 stack_push (block_stack
, (char *) &symbolP
);
2686 register symbolS
*begin_symbolP
;
2687 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2688 if (begin_symbolP
== (symbolS
*) 0)
2689 as_warn ("mismatched .eb");
2691 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2694 /* If we are able to identify the type of a function, and we
2695 are out of a function (last_functionP == 0) then, the
2696 function symbol will be associated with an auxiliary
2698 if (last_functionP
== (symbolS
*) 0 &&
2699 SF_GET_FUNCTION (symbolP
))
2701 last_functionP
= symbolP
;
2703 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2705 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2706 } /* make it at least 1 */
2708 /* Clobber possible stale .dim information. */
2710 /* Iffed out by steve - this fries the lnnoptr info too */
2711 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2712 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2715 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2717 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2719 if (last_bfP
!= NULL
)
2720 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2724 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2726 /* I don't even know if this is needed for sdb. But
2727 the standard assembler generates it, so... */
2728 if (last_functionP
== (symbolS
*) 0)
2729 as_fatal ("C_EFCN symbol out of scope");
2730 SA_SET_SYM_FSIZE (last_functionP
,
2731 (long) (S_GET_VALUE (symbolP
) -
2732 S_GET_VALUE (last_functionP
)));
2733 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2734 last_functionP
= (symbolS
*) 0;
2738 else if (SF_GET_TAG (symbolP
))
2740 /* First descriptor of a structure must point to
2741 the first slot after the structure description. */
2742 last_tagP
= symbolP
;
2745 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2747 /* +2 take in account the current symbol */
2748 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2750 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2752 /* If the filename was too long to fit in the
2753 auxent, put it in the string table */
2754 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2755 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2757 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2758 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2759 filename_list_scan
= filename_list_scan
->next
;
2761 if (S_GET_VALUE (symbolP
))
2763 S_SET_VALUE (symbolP
, last_file_symno
);
2764 last_file_symno
= symbol_number
;
2765 } /* no one points at the first .file symbol */
2766 } /* if debug or tag or eos or file */
2768 #ifdef tc_frob_coff_symbol
2769 tc_frob_coff_symbol (symbolP
);
2772 /* We must put the external symbols apart. The loader
2773 does not bomb if we do not. But the references in
2774 the endndx field for a .bb symbol are not corrected
2775 if an external symbol is removed between .bb and .be.
2776 I.e in the following case :
2777 [20] .bb endndx = 22
2780 ld will move the symbol 21 to the end of the list but
2781 endndx will still be 22 instead of 21. */
2784 if (SF_GET_LOCAL (symbolP
))
2786 /* remove C_EFCN and LOCAL (L...) symbols */
2787 /* next pointer remains valid */
2788 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2791 else if (symbolP
->sy_value
.X_op
== O_symbol
2792 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2794 /* Skip symbols which were equated to undefined or common
2796 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2798 else if (!S_IS_DEFINED (symbolP
)
2799 && !S_IS_DEBUG (symbolP
)
2800 && !SF_GET_STATICS (symbolP
) &&
2801 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2802 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2803 /* if external, Remove from the list */
2804 symbolS
*hold
= symbol_previous (symbolP
);
2806 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2807 symbol_clear_list_pointers (symbolP
);
2808 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2811 else if (! S_IS_DEBUG (symbolP
)
2812 && ! SF_GET_STATICS (symbolP
)
2813 && ! SF_GET_FUNCTION (symbolP
)
2814 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2816 symbolS
*hold
= symbol_previous (symbolP
);
2818 /* The O'Reilly COFF book says that defined global symbols
2819 come at the end of the symbol table, just before
2820 undefined global symbols. */
2822 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2823 symbol_clear_list_pointers (symbolP
);
2824 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2825 &symbol_global_lastP
);
2830 if (SF_GET_STRING (symbolP
))
2832 symbolP
->sy_name_offset
= string_byte_count
;
2833 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2837 symbolP
->sy_name_offset
= 0;
2838 } /* fix "long" names */
2840 symbolP
->sy_number
= symbol_number
;
2841 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2842 } /* if local symbol */
2843 } /* traverse the symbol list */
2844 return symbol_number
;
2850 glue_symbols (head
, tail
)
2854 unsigned int symbol_number
= 0;
2857 for (symbolP
= *head
; *head
!= NULL
;)
2859 symbolS
*tmp
= *head
;
2862 symbol_remove (tmp
, head
, tail
);
2863 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2866 if (SF_GET_STRING (tmp
))
2868 tmp
->sy_name_offset
= string_byte_count
;
2869 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2873 tmp
->sy_name_offset
= 0;
2874 } /* fix "long" names */
2876 tmp
->sy_number
= symbol_number
;
2877 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2878 } /* append the entire extern chain */
2880 return symbol_number
;
2886 unsigned int symbol_number
= 0;
2889 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2890 symbol_next (symbolP
))
2892 symbolP
->sy_number
= symbol_number
;
2896 if (SF_GET_TAGGED (symbolP
))
2900 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2903 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2905 return symbol_number
;
2910 crawl_symbols (h
, abfd
)
2916 /* Initialize the stack used to keep track of the matching .bb .be */
2918 block_stack
= stack_init (512, sizeof (symbolS
*));
2920 /* The symbol list should be ordered according to the following sequence
2923 * . debug entries for functions
2924 * . fake symbols for the sections, including.text .data and .bss
2926 * . undefined symbols
2927 * But this is not mandatory. The only important point is to put the
2928 * undefined symbols at the end of the list.
2931 if (symbol_rootP
== NULL
2932 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2934 c_dot_file_symbol ("fake");
2936 /* Is there a .file symbol ? If not insert one at the beginning. */
2939 * Build up static symbols for the sections, they are filled in later
2943 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2944 if (segment_info
[i
].scnhdr
.s_name
[0])
2945 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2948 /* Take all the externals out and put them into another chain */
2949 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2950 /* Take the externals and glue them onto the end.*/
2951 H_SET_SYMBOL_TABLE_SIZE (h
,
2952 (H_GET_SYMBOL_COUNT (h
)
2953 + glue_symbols (&symbol_globalP
,
2954 &symbol_global_lastP
)
2955 + glue_symbols (&symbol_externP
,
2956 &symbol_extern_lastP
)));
2958 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2959 know (symbol_globalP
== NULL
);
2960 know (symbol_global_lastP
== NULL
);
2961 know (symbol_externP
== NULL
);
2962 know (symbol_extern_lastP
== NULL
);
2966 * Find strings by crawling along symbol table chain.
2974 struct filename_list
*filename_list_scan
= filename_list_head
;
2976 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2977 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2980 #ifdef COFF_LONG_SECTION_NAMES
2981 /* Support long section names as found in PE. This code must
2982 coordinate with that in coff_header_append and write_object_file. */
2986 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2988 if (segment_info
[i
].scnhdr
.s_name
[0]
2989 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2993 size
= strlen (segment_info
[i
].name
) + 1;
2994 memcpy (where
, segment_info
[i
].name
, size
);
2999 #endif /* COFF_LONG_SECTION_NAMES */
3001 for (symbolP
= symbol_rootP
;
3003 symbolP
= symbol_next (symbolP
))
3007 if (SF_GET_STRING (symbolP
))
3009 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3010 memcpy (where
, S_GET_NAME (symbolP
), size
);
3013 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3014 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3015 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3017 size
= strlen (filename_list_scan
->filename
) + 1;
3018 memcpy (where
, filename_list_scan
->filename
, size
);
3019 filename_list_scan
= filename_list_scan
->next
;
3026 do_linenos_for (abfd
, h
, file_cursor
)
3029 unsigned long *file_cursor
;
3032 unsigned long start
= *file_cursor
;
3034 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3036 segment_info_type
*s
= segment_info
+ idx
;
3039 if (s
->scnhdr
.s_nlnno
!= 0)
3041 struct lineno_list
*line_ptr
;
3043 struct external_lineno
*buffer
=
3044 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3046 struct external_lineno
*dst
= buffer
;
3048 /* Run through the table we've built and turn it into its external
3049 form, take this chance to remove duplicates */
3051 for (line_ptr
= s
->lineno_list_head
;
3052 line_ptr
!= (struct lineno_list
*) NULL
;
3053 line_ptr
= line_ptr
->next
)
3056 if (line_ptr
->line
.l_lnno
== 0)
3058 /* Turn a pointer to a symbol into the symbols' index */
3059 line_ptr
->line
.l_addr
.l_symndx
=
3060 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3064 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3068 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3073 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3075 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3078 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3081 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3085 /* Now we run through the list of frag chains in a segment and
3086 make all the subsegment frags appear at the end of the
3087 list, as if the seg 0 was extra long */
3094 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3096 frchainS
*head
= segment_info
[i
].frchainP
;
3098 fragS
*prev_frag
= &dummy
;
3100 while (head
&& head
->frch_seg
== i
)
3102 prev_frag
->fr_next
= head
->frch_root
;
3103 prev_frag
= head
->frch_last
;
3104 head
= head
->frch_next
;
3106 prev_frag
->fr_next
= 0;
3110 unsigned long machine
;
3113 write_object_file ()
3117 struct frchain
*frchain_ptr
;
3119 object_headers headers
;
3120 unsigned long file_cursor
;
3123 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3128 as_perror ("FATAL: Can't create %s", out_file_name
);
3129 exit (EXIT_FAILURE
);
3131 bfd_set_format (abfd
, bfd_object
);
3132 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3134 string_byte_count
= 4;
3136 for (frchain_ptr
= frchain_root
;
3137 frchain_ptr
!= (struct frchain
*) NULL
;
3138 frchain_ptr
= frchain_ptr
->frch_next
)
3140 /* Run through all the sub-segments and align them up. Also
3141 close any open frags. We tack a .fill onto the end of the
3142 frag chain so that any .align's size can be worked by looking
3143 at the next frag. */
3145 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3146 #ifndef SUB_SEGMENT_ALIGN
3147 #define SUB_SEGMENT_ALIGN(SEG) 1
3151 static char nop
= NOP_OPCODE
;
3152 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, 0, alignment_done
);
3155 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3159 frag_wane (frag_now
);
3160 frag_now
->fr_fix
= 0;
3161 know (frag_now
->fr_next
== NULL
);
3168 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3170 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3173 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3175 /* Find out how big the sections are, and set the addresses. */
3177 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3181 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3182 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3184 if (segment_info
[i
].scnhdr
.s_name
[0])
3186 H_SET_NUMBER_OF_SECTIONS (&headers
,
3187 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3189 #ifdef COFF_LONG_SECTION_NAMES
3190 /* Support long section names as found in PE. This code
3191 must coordinate with that in coff_header_append and
3196 len
= strlen (segment_info
[i
].name
);
3198 string_byte_count
+= len
+ 1;
3200 #endif /* COFF_LONG_SECTION_NAMES */
3203 size
= size_section (abfd
, (unsigned int) i
);
3206 /* I think the section alignment is only used on the i960; the
3207 i960 needs it, and it should do no harm on other targets. */
3208 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3211 H_SET_TEXT_SIZE (&headers
, size
);
3212 else if (i
== SEG_E1
)
3213 H_SET_DATA_SIZE (&headers
, size
);
3214 else if (i
== SEG_E2
)
3215 H_SET_BSS_SIZE (&headers
, size
);
3218 /* Turn the gas native symbol table shape into a coff symbol table */
3219 crawl_symbols (&headers
, abfd
);
3221 if (string_byte_count
== 4)
3222 string_byte_count
= 0;
3224 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3230 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3232 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3233 fixup_segment (&segment_info
[i
], i
);
3236 /* Look for ".stab" segments and fill in their initial symbols
3238 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3240 name
= segment_info
[i
].name
;
3243 && strncmp (".stab", name
, 5) == 0
3244 && strncmp (".stabstr", name
, 8) != 0)
3245 adjust_stab_section (abfd
, i
);
3248 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3250 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3252 /* Plant the data */
3254 fill_section (abfd
, &headers
, &file_cursor
);
3256 do_relocs_for (abfd
, &headers
, &file_cursor
);
3258 do_linenos_for (abfd
, &headers
, &file_cursor
);
3260 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3261 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3262 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3264 H_SET_TIME_STAMP (&headers
, 0);
3266 #ifdef TC_COFF_SET_MACHINE
3267 TC_COFF_SET_MACHINE (&headers
);
3271 #define COFF_FLAGS 0
3274 #ifdef KEEP_RELOC_INFO
3275 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3276 COFF_FLAGS
| coff_flags
));
3278 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3279 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3280 COFF_FLAGS
| coff_flags
));
3284 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3285 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3287 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3288 w_symbols (abfd
, buffer1
, symbol_rootP
);
3289 if (string_byte_count
> 0)
3290 w_strings (buffer1
+ symtable_size
);
3291 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3295 coff_header_append (abfd
, &headers
);
3297 /* Recent changes to write need this, but where it should
3298 go is up to Ken.. */
3299 if (bfd_close_all_done (abfd
) == false)
3300 as_fatal ("Can't close %s: %s", out_file_name
,
3301 bfd_errmsg (bfd_get_error ()));
3304 extern bfd
*stdoutput
;
3311 /* Add a new segment. This is called from subseg_new via the
3312 obj_new_segment macro. */
3315 obj_coff_add_segment (name
)
3320 #ifndef COFF_LONG_SECTION_NAMES
3321 char buf
[SCNNMLEN
+ 1];
3323 strncpy (buf
, name
, SCNNMLEN
);
3324 buf
[SCNNMLEN
] = '\0';
3328 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3329 if (strcmp (name
, segment_info
[i
].name
) == 0)
3334 as_bad ("Too many new sections; can't add \"%s\"", name
);
3338 /* Add a new section. */
3339 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3340 sizeof (segment_info
[i
].scnhdr
.s_name
));
3341 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3342 segment_info
[i
].name
= xstrdup (name
);
3348 * implement the .section pseudo op:
3349 * .section name {, "flags"}
3351 * | +--- optional flags: 'b' for bss
3353 * +-- section name 'l' for lib
3357 * 'd' (apparently m88k for 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;
3424 as_warn("unknown section attribute '%c'",
3425 *input_line_pointer
);
3428 ++input_line_pointer
;
3430 if (*input_line_pointer
== '"')
3431 ++input_line_pointer
;
3435 subseg_new (name
, (subsegT
) exp
);
3437 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3439 demand_empty_rest_of_line ();
3444 obj_coff_text (ignore
)
3447 subseg_new (".text", get_absolute_expression ());
3452 obj_coff_data (ignore
)
3455 if (flag_readonly_data_in_text
)
3456 subseg_new (".text", get_absolute_expression () + 1000);
3458 subseg_new (".data", get_absolute_expression ());
3462 obj_coff_bss (ignore
)
3465 if (*input_line_pointer
== '\n') /* .bss */
3466 subseg_new(".bss", get_absolute_expression());
3467 else /* .bss id,expr */
3472 obj_coff_ident (ignore
)
3475 segT current_seg
= now_seg
; /* save current seg */
3476 subsegT current_subseg
= now_subseg
;
3477 subseg_new (".comment", 0); /* .comment seg */
3478 stringer (1); /* read string */
3479 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3483 c_symbol_merge (debug
, normal
)
3487 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3488 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3490 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3492 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3493 } /* take the most we have */
3495 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3497 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3498 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3499 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3500 } /* Move all the auxiliary information */
3502 /* Move the debug flags. */
3503 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3504 } /* c_symbol_merge() */
3507 c_line_new (symbol
, paddr
, line_number
, frag
)
3513 struct lineno_list
*new_line
=
3514 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3516 segment_info_type
*s
= segment_info
+ now_seg
;
3517 new_line
->line
.l_lnno
= line_number
;
3519 if (line_number
== 0)
3521 last_line_symbol
= symbol
;
3522 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3526 new_line
->line
.l_addr
.l_paddr
= paddr
;
3529 new_line
->frag
= (char *) frag
;
3530 new_line
->next
= (struct lineno_list
*) NULL
;
3533 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3535 s
->lineno_list_head
= new_line
;
3539 s
->lineno_list_tail
->next
= new_line
;
3541 s
->lineno_list_tail
= new_line
;
3542 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3546 c_dot_file_symbol (filename
)
3551 symbolP
= symbol_new (".file",
3554 &zero_address_frag
);
3556 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3557 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3559 if (strlen (filename
) > FILNMLEN
)
3561 /* Filename is too long to fit into an auxent,
3562 we stick it into the string table instead. We keep
3563 a linked list of the filenames we find so we can emit
3565 struct filename_list
*f
= ((struct filename_list
*)
3566 xmalloc (sizeof (struct filename_list
)));
3568 f
->filename
= filename
;
3571 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3572 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3574 if (filename_list_tail
)
3575 filename_list_tail
->next
= f
;
3577 filename_list_head
= f
;
3578 filename_list_tail
= f
;
3582 SA_SET_FILE_FNAME (symbolP
, filename
);
3589 listing_source_file (filename
);
3595 SF_SET_DEBUG (symbolP
);
3596 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3598 previous_file_symbol
= symbolP
;
3600 /* Make sure that the symbol is first on the symbol chain */
3601 if (symbol_rootP
!= symbolP
)
3603 if (symbolP
== symbol_lastP
)
3605 symbol_lastP
= symbol_lastP
->sy_previous
;
3606 } /* if it was the last thing on the list */
3608 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3609 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3610 symbol_rootP
= symbolP
;
3611 } /* if not first on the list */
3613 } /* c_dot_file_symbol() */
3616 * Build a 'section static' symbol.
3620 c_section_symbol (name
, idx
)
3626 symbolP
= symbol_new (name
, idx
,
3628 &zero_address_frag
);
3630 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3631 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3633 SF_SET_STATICS (symbolP
);
3636 /* If the .linkonce pseudo-op was used for this section, we must
3637 store the information in the auxiliary entry for the section
3639 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3643 switch (segment_info
[idx
].linkonce
)
3647 case LINKONCE_DISCARD
:
3648 type
= IMAGE_COMDAT_SELECT_ANY
;
3650 case LINKONCE_ONE_ONLY
:
3651 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3653 case LINKONCE_SAME_SIZE
:
3654 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3656 case LINKONCE_SAME_CONTENTS
:
3657 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3661 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3666 } /* c_section_symbol() */
3669 w_symbols (abfd
, where
, symbol_rootP
)
3672 symbolS
* symbol_rootP
;
3677 /* First fill in those values we have only just worked out */
3678 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3680 symbolP
= segment_info
[i
].dot
;
3683 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3684 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3685 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3690 * Emit all symbols left in the symbol chain.
3692 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3694 /* Used to save the offset of the name. It is used to point
3695 to the string in memory but must be a file offset. */
3696 register char *temp
;
3698 /* We can't fix the lnnoptr field in yank_symbols with the other
3699 adjustments, because we have to wait until we know where they
3701 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3703 SA_GET_SYM_LNNOPTR (symbolP
) +=
3704 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3707 tc_coff_symbol_emit_hook (symbolP
);
3709 temp
= S_GET_NAME (symbolP
);
3710 if (SF_GET_STRING (symbolP
))
3712 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3713 S_SET_ZEROES (symbolP
, 0);
3717 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3718 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3720 where
= symbol_to_chars (abfd
, where
, symbolP
);
3721 S_SET_NAME (symbolP
, temp
);
3727 obj_coff_lcomm (ignore
)
3740 name
= input_line_pointer
;
3742 c
= get_symbol_end ();
3743 p
= input_line_pointer
;
3746 if (*input_line_pointer
!= ',')
3748 as_bad ("Expected comma after name");
3749 ignore_rest_of_line ();
3752 if (*input_line_pointer
== '\n')
3754 as_bad ("Missing size expression");
3757 input_line_pointer
++;
3758 if ((temp
= get_absolute_expression ()) < 0)
3760 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3761 ignore_rest_of_line ();
3766 symbolP
= symbol_find_or_make(name
);
3768 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3769 S_GET_VALUE(symbolP
) == 0)
3774 segT current_seg
= now_seg
; /* save current seg */
3775 subsegT current_subseg
= now_subseg
;
3777 subseg_set (SEG_E2
, 1);
3778 symbolP
->sy_frag
= frag_now
;
3779 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3782 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3783 S_SET_SEGMENT(symbolP
, SEG_E2
);
3784 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3788 as_bad("Symbol %s already defined", name
);
3790 demand_empty_rest_of_line();
3795 fixup_mdeps (frags
, h
, this_segment
)
3800 subseg_change (this_segment
, 0);
3803 switch (frags
->fr_type
)
3809 HANDLE_ALIGN (frags
);
3811 frags
->fr_type
= rs_fill
;
3813 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3816 case rs_machine_dependent
:
3817 md_convert_frag (h
, this_segment
, frags
);
3823 frags
= frags
->fr_next
;
3829 #ifndef TC_FORCE_RELOCATION
3830 #define TC_FORCE_RELOCATION(fix) 0
3834 fixup_segment (segP
, this_segment_type
)
3835 segment_info_type
* segP
;
3836 segT this_segment_type
;
3838 register fixS
* fixP
;
3839 register symbolS
*add_symbolP
;
3840 register symbolS
*sub_symbolP
;
3843 register char *place
;
3844 register long where
;
3845 register char pcrel
;
3846 register fragS
*fragP
;
3847 register segT add_symbol_segment
= absolute_section
;
3849 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3851 fragP
= fixP
->fx_frag
;
3853 where
= fixP
->fx_where
;
3854 place
= fragP
->fr_literal
+ where
;
3855 size
= fixP
->fx_size
;
3856 add_symbolP
= fixP
->fx_addsy
;
3857 sub_symbolP
= fixP
->fx_subsy
;
3858 add_number
= fixP
->fx_offset
;
3859 pcrel
= fixP
->fx_pcrel
;
3861 /* We want function-relative stabs to work on systems which
3862 may use a relaxing linker; thus we must handle the sym1-sym2
3863 fixups function-relative stabs generates.
3865 Of course, if you actually enable relaxing in the linker, the
3866 line and block scoping information is going to be incorrect
3867 in some cases. The only way to really fix this is to support
3868 a reloc involving the difference of two symbols. */
3870 && (!sub_symbolP
|| pcrel
))
3874 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3876 /* Relocation should be done via the associated 'bal' entry
3879 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3881 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3882 "No 'bal' entry point for leafproc %s",
3883 S_GET_NAME (add_symbolP
));
3886 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3890 /* Make sure the symbols have been resolved; this may not have
3891 happened if these are expression symbols. */
3892 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3893 resolve_symbol_value (add_symbolP
);
3895 if (add_symbolP
!= NULL
)
3897 /* If this fixup is against a symbol which has been equated
3898 to another symbol, convert it to the other symbol. */
3899 if (add_symbolP
->sy_value
.X_op
== O_symbol
3900 && (! S_IS_DEFINED (add_symbolP
)
3901 || S_IS_COMMON (add_symbolP
)))
3903 while (add_symbolP
->sy_value
.X_op
== O_symbol
3904 && (! S_IS_DEFINED (add_symbolP
)
3905 || S_IS_COMMON (add_symbolP
)))
3909 /* We must avoid looping, as that can occur with a
3910 badly written program. */
3911 n
= add_symbolP
->sy_value
.X_add_symbol
;
3912 if (n
== add_symbolP
)
3914 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3917 fixP
->fx_addsy
= add_symbolP
;
3918 fixP
->fx_offset
= add_number
;
3922 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3923 resolve_symbol_value (sub_symbolP
);
3925 if (add_symbolP
!= NULL
3926 && add_symbolP
->sy_mri_common
)
3928 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3929 add_number
+= S_GET_VALUE (add_symbolP
);
3930 fixP
->fx_offset
= add_number
;
3931 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3936 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3937 } /* if there is an addend */
3941 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3943 if (add_symbolP
!= NULL
)
3945 add_number
+= S_GET_VALUE (add_symbolP
);
3947 fixP
->fx_addsy
= NULL
;
3950 /* It's just -sym. */
3951 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3953 add_number
-= S_GET_VALUE (sub_symbolP
);
3960 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3961 "Negative of non-absolute symbol %s",
3962 S_GET_NAME (sub_symbolP
));
3964 add_number
-= S_GET_VALUE (sub_symbolP
);
3965 } /* not absolute */
3967 /* if sub_symbol is in the same segment that add_symbol
3968 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3970 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3971 && SEG_NORMAL (add_symbol_segment
))
3973 /* Difference of 2 symbols from same segment. Can't
3974 make difference of 2 undefineds: 'value' means
3975 something different for N_UNDF. */
3977 /* Makes no sense to use the difference of 2 arbitrary symbols
3978 as the target of a call instruction. */
3981 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3982 "callj to difference of 2 symbols");
3984 #endif /* TC_I960 */
3985 add_number
+= S_GET_VALUE (add_symbolP
) -
3986 S_GET_VALUE (sub_symbolP
);
3989 if (!TC_FORCE_RELOCATION (fixP
))
3991 fixP
->fx_addsy
= NULL
;
3992 fixP
->fx_subsy
= NULL
;
3994 #ifdef TC_M68K /* is this right? */
4002 /* Different segments in subtraction. */
4003 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4005 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4007 add_number
-= S_GET_VALUE (sub_symbolP
);
4010 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4011 #if 0 /* Okay for 68k, at least... */
4016 /* Make it pc-relative. */
4017 add_number
+= (md_pcrel_from (fixP
)
4018 - S_GET_VALUE (sub_symbolP
));
4027 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4028 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
4029 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4030 S_GET_NAME (sub_symbolP
),
4031 (long) (fragP
->fr_address
+ where
));
4034 } /* if sub_symbolP */
4038 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4041 * This fixup was made when the symbol's segment was
4042 * SEG_UNKNOWN, but it is now in the local segment.
4043 * So we know how to do the address without relocation.
4046 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4047 * in which cases it modifies *fixP as appropriate. In the case
4048 * of a 'calls', no further work is required, and *fixP has been
4049 * set up to make the rest of the code below a no-op.
4052 #endif /* TC_I960 */
4054 add_number
+= S_GET_VALUE (add_symbolP
);
4055 add_number
-= md_pcrel_from (fixP
);
4056 #if defined (TC_I386) || defined (TE_LYNX)
4057 /* On the 386 we must adjust by the segment vaddr as
4058 well. Ian Taylor. */
4059 add_number
-= segP
->scnhdr
.s_vaddr
;
4061 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4062 if (!TC_FORCE_RELOCATION (fixP
))
4064 fixP
->fx_addsy
= NULL
;
4070 switch (add_symbol_segment
)
4072 case absolute_section
:
4074 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4075 #endif /* TC_I960 */
4076 add_number
+= S_GET_VALUE (add_symbolP
);
4079 if (!TC_FORCE_RELOCATION (fixP
))
4081 fixP
->fx_addsy
= NULL
;
4088 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4089 /* This really should be handled in the linker, but
4090 backward compatibility forbids. */
4091 add_number
+= S_GET_VALUE (add_symbolP
);
4093 add_number
+= S_GET_VALUE (add_symbolP
) +
4094 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4100 if ((int) fixP
->fx_bit_fixP
== 13)
4102 /* This is a COBR instruction. They have only a
4103 * 13-bit displacement and are only to be used
4104 * for local branches: flag as error, don't generate
4107 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4108 "can't use COBR format with external label");
4109 fixP
->fx_addsy
= NULL
;
4113 #endif /* TC_I960 */
4114 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
4115 /* 386 COFF uses a peculiar format in which the
4116 value of a common symbol is stored in the .text
4117 segment (I've checked this on SVR3.2 and SCO
4118 3.2.2) Ian Taylor <ian@cygnus.com>. */
4119 if (S_IS_COMMON (add_symbolP
))
4120 add_number
+= S_GET_VALUE (add_symbolP
);
4125 } /* switch on symbol seg */
4126 } /* if not in local seg */
4127 } /* if there was a + symbol */
4131 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4132 /* This adjustment is not correct on the m88k, for which the
4133 linker does all the computation. */
4134 add_number
-= md_pcrel_from (fixP
);
4136 if (add_symbolP
== 0)
4138 fixP
->fx_addsy
= &abs_symbol
;
4139 } /* if there's an add_symbol */
4140 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4141 /* On the 386 we must adjust by the segment vaddr as well.
4144 I changed the i960 to work this way as well. This is
4145 compatible with the current GNU linker behaviour. I do
4146 not know what other i960 COFF assemblers do. This is not
4147 a common case: normally, only assembler code will contain
4148 a PC relative reloc, and only branches which do not
4149 originate in the .text section will have a non-zero
4152 I changed the m68k to work this way as well. This will
4153 break existing PC relative relocs from sections which do
4154 not start at address 0, but it will make ld -r work.
4155 Ian Taylor, 4 Oct 96. */
4157 add_number
-= segP
->scnhdr
.s_vaddr
;
4161 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4164 /* The m88k uses the offset field of the reloc to get around
4167 && ((add_number
& ~0xFF)
4168 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4169 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4170 || (add_number
& 0x80) == 0))
4172 && ((add_number
& ~0xFFFF)
4173 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4174 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4175 || (add_number
& 0x8000) == 0)))
4177 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4178 "Value of %ld too large for field of %d bytes at 0x%lx",
4179 (long) add_number
, size
,
4180 (unsigned long) (fragP
->fr_address
+ where
));
4183 #ifdef WARN_SIGNED_OVERFLOW_WORD
4184 /* Warn if a .word value is too large when treated as a
4185 signed number. We already know it is not too negative.
4186 This is to catch over-large switches generated by gcc on
4188 if (!flag_signed_overflow_ok
4190 && add_number
> 0x7fff)
4191 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4192 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4194 (unsigned long) (fragP
->fr_address
+ where
));
4196 } /* not a bit fix */
4197 /* Once this fix has been applied, we don't have to output
4198 anything nothing more need be done. */
4199 #ifdef MD_APPLY_FIX3
4200 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4202 md_apply_fix (fixP
, add_number
);
4204 } /* For each fixS in this segment. */
4205 } /* fixup_segment() */
4209 /* The first entry in a .stab section is special. */
4212 obj_coff_init_stab_section (seg
)
4218 unsigned int stroff
;
4220 /* Make space for this first symbol. */
4224 as_where (&file
, (unsigned int *) NULL
);
4225 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4226 strcpy (stabstr_name
, segment_info
[seg
].name
);
4227 strcat (stabstr_name
, "str");
4228 stroff
= get_stab_string_offset (file
, stabstr_name
);
4230 md_number_to_chars (p
, stroff
, 4);
4233 /* Fill in the counts in the first entry in a .stab section. */
4236 adjust_stab_section(abfd
, seg
)
4240 segT stabstrseg
= SEG_UNKNOWN
;
4241 const char *secname
, *name2
;
4244 int i
, strsz
= 0, nsyms
;
4245 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4247 /* Look for the associated string table section. */
4249 secname
= segment_info
[seg
].name
;
4250 name
= (char *) alloca (strlen (secname
) + 4);
4251 strcpy (name
, secname
);
4252 strcat (name
, "str");
4254 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4256 name2
= segment_info
[i
].name
;
4257 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4264 /* If we found the section, get its size. */
4265 if (stabstrseg
!= SEG_UNKNOWN
)
4266 strsz
= size_section (abfd
, stabstrseg
);
4268 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4270 /* Look for the first frag of sufficient size for the initial stab
4271 symbol, and collect a pointer to it. */
4272 while (frag
&& frag
->fr_fix
< 12)
4273 frag
= frag
->fr_next
;
4275 p
= frag
->fr_literal
;
4278 /* Write in the number of stab symbols and the size of the string
4280 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4281 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4284 #endif /* not BFD_ASSEMBLER */
4286 const pseudo_typeS obj_pseudo_table
[] =
4288 {"def", obj_coff_def
, 0},
4289 {"dim", obj_coff_dim
, 0},
4290 {"endef", obj_coff_endef
, 0},
4291 {"line", obj_coff_line
, 0},
4292 {"ln", obj_coff_ln
, 0},
4293 {"appline", obj_coff_ln
, 1},
4294 {"scl", obj_coff_scl
, 0},
4295 {"size", obj_coff_size
, 0},
4296 {"tag", obj_coff_tag
, 0},
4297 {"type", obj_coff_type
, 0},
4298 {"val", obj_coff_val
, 0},
4299 {"section", obj_coff_section
, 0},
4300 {"sect", obj_coff_section
, 0},
4301 /* FIXME: We ignore the MRI short attribute. */
4302 {"section.s", obj_coff_section
, 0},
4303 {"sect.s", obj_coff_section
, 0},
4304 #ifndef BFD_ASSEMBLER
4305 {"use", obj_coff_section
, 0},
4306 {"text", obj_coff_text
, 0},
4307 {"data", obj_coff_data
, 0},
4308 {"bss", obj_coff_bss
, 0},
4309 {"lcomm", obj_coff_lcomm
, 0},
4310 {"ident", obj_coff_ident
, 0},
4312 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4313 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4315 {"ABORT", s_abort
, 0},
4317 /* The m88k uses sdef instead of def. */
4318 {"sdef", obj_coff_def
, 0},
4320 {NULL
} /* end sentinel */
4321 }; /* obj_pseudo_table */