1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 1996
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
25 #include "libiberty.h"
27 /* I think this is probably always correct. */
28 #ifndef KEEP_RELOC_INFO
29 #define KEEP_RELOC_INFO
32 const char *s_get_name
PARAMS ((symbolS
* s
));
33 static symbolS
*def_symbol_in_progress
;
39 unsigned long chunk_size
;
40 unsigned long element_size
;
43 unsigned long pointer
;
48 stack_init (chunk_size
, element_size
)
49 unsigned long chunk_size
;
50 unsigned long element_size
;
54 st
= (stack
*) malloc (sizeof (stack
));
57 st
->data
= malloc (chunk_size
);
64 st
->size
= chunk_size
;
65 st
->chunk_size
= chunk_size
;
66 st
->element_size
= element_size
;
71 /* Not currently used. */
82 stack_push (st
, element
)
86 if (st
->pointer
+ st
->element_size
>= st
->size
)
88 st
->size
+= st
->chunk_size
;
89 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
92 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
93 st
->pointer
+= st
->element_size
;
94 return st
->data
+ st
->pointer
;
101 if (st
->pointer
< st
->element_size
)
106 st
->pointer
-= st
->element_size
;
107 return st
->data
+ st
->pointer
;
111 * Maintain a list of the tagnames of the structres.
114 static struct hash_control
*tag_hash
;
119 tag_hash
= hash_new ();
123 tag_insert (name
, symbolP
)
127 const char *error_string
;
129 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
131 as_fatal ("Inserting \"%s\" into structure table failed: %s",
140 #ifdef STRIP_UNDERSCORE
143 #endif /* STRIP_UNDERSCORE */
144 return (symbolS
*) hash_find (tag_hash
, name
);
148 tag_find_or_make (name
)
153 if ((symbolP
= tag_find (name
)) == NULL
)
155 symbolP
= symbol_new (name
, undefined_section
,
156 0, &zero_address_frag
);
158 tag_insert (S_GET_NAME (symbolP
), symbolP
);
160 symbol_table_insert (symbolP
);
171 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
173 #define GET_FILENAME_STRING(X) \
174 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
178 fetch_coff_debug_section ()
180 static segT debug_section
;
184 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
186 debug_section
= s
->section
;
188 return debug_section
;
192 SA_SET_SYM_ENDNDX (sym
, val
)
196 combined_entry_type
*entry
, *p
;
198 entry
= &coffsymbol (sym
->bsym
)->native
[1];
199 p
= coffsymbol (val
->bsym
)->native
;
200 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
205 SA_SET_SYM_TAGNDX (sym
, val
)
209 combined_entry_type
*entry
, *p
;
211 entry
= &coffsymbol (sym
->bsym
)->native
[1];
212 p
= coffsymbol (val
->bsym
)->native
;
213 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
218 S_GET_DATA_TYPE (sym
)
221 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
225 S_SET_DATA_TYPE (sym
, val
)
229 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
234 S_GET_STORAGE_CLASS (sym
)
237 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
241 S_SET_STORAGE_CLASS (sym
, val
)
245 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
249 /* Merge a debug symbol containing debug information into a normal symbol. */
252 c_symbol_merge (debug
, normal
)
256 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
257 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
259 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
260 /* take the most we have */
261 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
263 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
265 /* Move all the auxiliary information. */
266 /* @@ How many fields do we want to preserve? Would it make more
267 sense to pick and choose those we want to copy? Should look
268 into this further.... [raeburn:19920512.2209EST] */
270 linenos
= coffsymbol (normal
->bsym
)->lineno
;
271 memcpy ((char *) &coffsymbol (normal
->bsym
)->native
,
272 (char *) &coffsymbol (debug
->bsym
)->native
,
273 S_GET_NUMBER_AUXILIARY(debug
) * AUXESZ
);
274 coffsymbol (normal
->bsym
)->lineno
= linenos
;
277 /* Move the debug flags. */
278 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
281 static symbolS
*previous_file_symbol
;
283 c_dot_file_symbol (filename
)
288 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
290 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
291 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
293 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
300 listing_source_file (filename
);
305 S_SET_VALUE (symbolP
, (long) previous_file_symbol
);
307 previous_file_symbol
= symbolP
;
309 /* Make sure that the symbol is first on the symbol chain */
310 if (symbol_rootP
!= symbolP
)
312 if (symbolP
== symbol_lastP
)
314 symbol_lastP
= symbol_lastP
->sy_previous
;
315 } /* if it was the last thing on the list */
317 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
318 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
319 symbol_rootP
= symbolP
;
320 } /* if not first on the list */
323 /* Line number handling */
326 struct line_no
*next
;
333 /* Symbol of last function, which we should hang line#s off of. */
334 static symbolS
*line_fsym
;
336 #define in_function() (line_fsym != 0)
337 #define clear_function() (line_fsym = 0)
338 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
342 obj_symbol_new_hook (symbolP
)
345 char underscore
= 0; /* Symbol has leading _ */
348 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
349 char *s
= (char *) bfd_alloc_by_size_t (stdoutput
, sz
);
351 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
353 S_SET_DATA_TYPE (symbolP
, T_NULL
);
354 S_SET_STORAGE_CLASS (symbolP
, 0);
355 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
357 if (S_IS_STRING (symbolP
))
358 SF_SET_STRING (symbolP
);
359 if (!underscore
&& S_IS_LOCAL (symbolP
))
360 SF_SET_LOCAL (symbolP
);
365 * Handle .ln directives.
368 static symbolS
*current_lineno_sym
;
369 static struct line_no
*line_nos
;
370 /* @@ Blindly assume all .ln directives will be in the .text section... */
374 add_lineno (frag
, offset
, num
)
379 struct line_no
*new_line
= (struct line_no
*) bfd_alloc_by_size_t (stdoutput
,
380 sizeof (struct line_no
));
381 if (!current_lineno_sym
)
385 new_line
->next
= line_nos
;
386 new_line
->frag
= frag
;
387 new_line
->l
.line_number
= num
;
388 new_line
->l
.u
.offset
= offset
;
394 coff_add_linesym (sym
)
399 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
403 current_lineno_sym
= sym
;
407 obj_coff_ln (appline
)
412 if (! appline
&& def_symbol_in_progress
!= NULL
)
414 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
415 demand_empty_rest_of_line ();
419 l
= get_absolute_expression ();
422 add_lineno (frag_now
, frag_now_fix (), l
);
432 l
+= coff_line_base
- 1;
433 listing_source_line (l
);
438 demand_empty_rest_of_line ();
444 * Handle .def directives.
446 * One might ask : why can't we symbol_new if the symbol does not
447 * already exist and fill it with debug information. Because of
448 * the C_EFCN special symbol. It would clobber the value of the
449 * function symbol before we have a chance to notice that it is
450 * a C_EFCN. And a second reason is that the code is more clear this
451 * way. (at least I think it is :-).
455 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
456 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
457 *input_line_pointer == '\t') \
458 input_line_pointer++;
464 char name_end
; /* Char after the end of name */
465 char *symbol_name
; /* Name of the debug symbol */
466 char *symbol_name_copy
; /* Temporary copy of the name */
467 unsigned int symbol_name_length
;
469 if (def_symbol_in_progress
!= NULL
)
471 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
472 demand_empty_rest_of_line ();
474 } /* if not inside .def/.endef */
478 symbol_name
= input_line_pointer
;
479 #ifdef STRIP_UNDERSCORE
480 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
482 #endif /* STRIP_UNDERSCORE */
484 name_end
= get_symbol_end ();
485 symbol_name_length
= strlen (symbol_name
);
486 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
487 strcpy (symbol_name_copy
, symbol_name
);
489 /* Initialize the new symbol */
490 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
491 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
492 S_SET_VALUE (def_symbol_in_progress
, 0);
494 if (S_IS_STRING (def_symbol_in_progress
))
495 SF_SET_STRING (def_symbol_in_progress
);
497 *input_line_pointer
= name_end
;
499 demand_empty_rest_of_line ();
502 unsigned int dim_index
;
505 obj_coff_endef (ignore
)
509 /* DIM BUG FIX sac@cygnus.com */
511 if (def_symbol_in_progress
== NULL
)
513 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
514 demand_empty_rest_of_line ();
516 } /* if not inside .def/.endef */
518 /* Set the section number according to storage class. */
519 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
524 SF_SET_TAG (def_symbol_in_progress
);
525 /* intentional fallthrough */
528 SF_SET_DEBUG (def_symbol_in_progress
);
529 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
533 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
534 /* intentional fallthrough */
536 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
537 /* intentional fallthrough */
541 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
543 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
544 if (name
[1] == 'b' && name
[2] == 'f')
546 if (! in_function ())
547 as_warn ("`%s' symbol without preceding function", name
);
548 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
549 /* Will need relocating */
550 SF_SET_PROCESS (def_symbol_in_progress
);
558 #endif /* C_AUTOARG */
564 SF_SET_DEBUG (def_symbol_in_progress
);
565 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
572 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
578 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
584 as_warn ("unexpected storage class %d",
585 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
587 } /* switch on storage class */
589 /* Now that we have built a debug symbol, try to find if we should
590 merge with an existing symbol or not. If a symbol is C_EFCN or
591 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
593 /* Two cases for functions. Either debug followed by definition or
594 definition followed by debug. For definition first, we will
595 merge the debug symbol into the definition. For debug first, the
596 lineno entry MUST point to the definition function or else it
597 will point off into space when obj_crawl_symbol_chain() merges
598 the debug symbol into the real symbol. Therefor, let's presume
599 the debug symbol is a real function reference. */
601 /* FIXME-SOON If for some reason the definition label/symbol is
602 never seen, this will probably leave an undefined symbol at link
605 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
606 || (!strcmp (bfd_get_section_name (stdoutput
,
607 S_GET_SEGMENT (def_symbol_in_progress
)),
609 && !SF_GET_TAG (def_symbol_in_progress
))
610 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
611 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
613 if (def_symbol_in_progress
!= symbol_lastP
)
614 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
619 /* This symbol already exists, merge the newly created symbol
620 into the old one. This is not mandatory. The linker can
621 handle duplicate symbols correctly. But I guess that it save
622 a *lot* of space if the assembly file defines a lot of
625 /* The debug entry (def_symbol_in_progress) is merged into the
626 previous definition. */
628 c_symbol_merge (def_symbol_in_progress
, symbolP
);
629 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
631 def_symbol_in_progress
= symbolP
;
633 if (SF_GET_FUNCTION (def_symbol_in_progress
)
634 || SF_GET_TAG (def_symbol_in_progress
))
636 /* For functions, and tags, the symbol *must* be where the
637 debug symbol appears. Move the existing symbol to the
639 /* If it already is at the end of the symbol list, do nothing */
640 if (def_symbol_in_progress
!= symbol_lastP
)
642 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
643 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
648 if (SF_GET_TAG (def_symbol_in_progress
))
652 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
654 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
655 tag_insert (S_GET_NAME (def_symbol_in_progress
),
656 def_symbol_in_progress
);
659 if (SF_GET_FUNCTION (def_symbol_in_progress
))
661 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
662 set_function (def_symbol_in_progress
);
663 SF_SET_PROCESS (def_symbol_in_progress
);
667 /* That is, if this is the first time we've seen the
669 symbol_table_insert (def_symbol_in_progress
);
670 } /* definition follows debug */
671 } /* Create the line number entry pointing to the function being defined */
673 def_symbol_in_progress
= NULL
;
674 demand_empty_rest_of_line ();
678 obj_coff_dim (ignore
)
683 if (def_symbol_in_progress
== NULL
)
685 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
686 demand_empty_rest_of_line ();
688 } /* if not inside .def/.endef */
690 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
692 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
695 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
696 get_absolute_expression ());
698 switch (*input_line_pointer
)
701 input_line_pointer
++;
705 as_warn ("badly formed .dim directive ignored");
706 /* intentional fallthrough */
714 demand_empty_rest_of_line ();
718 obj_coff_line (ignore
)
723 if (def_symbol_in_progress
== NULL
)
725 /* Probably stabs-style line? */
730 this_base
= get_absolute_expression ();
731 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
732 coff_line_base
= this_base
;
734 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
735 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
737 demand_empty_rest_of_line ();
740 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
745 listing_source_line ((unsigned int) coff_line_base
);
751 obj_coff_size (ignore
)
754 if (def_symbol_in_progress
== NULL
)
756 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
757 demand_empty_rest_of_line ();
759 } /* if not inside .def/.endef */
761 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
762 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
763 demand_empty_rest_of_line ();
767 obj_coff_scl (ignore
)
770 if (def_symbol_in_progress
== NULL
)
772 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
773 demand_empty_rest_of_line ();
775 } /* if not inside .def/.endef */
777 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
778 demand_empty_rest_of_line ();
782 obj_coff_tag (ignore
)
788 if (def_symbol_in_progress
== NULL
)
790 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
791 demand_empty_rest_of_line ();
795 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
796 symbol_name
= input_line_pointer
;
797 name_end
= get_symbol_end ();
799 /* Assume that the symbol referred to by .tag is always defined.
800 This was a bad assumption. I've added find_or_make. xoxorich. */
801 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
802 tag_find_or_make (symbol_name
));
803 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
805 as_warn ("tag not found for .tag %s", symbol_name
);
808 SF_SET_TAGGED (def_symbol_in_progress
);
809 *input_line_pointer
= name_end
;
811 demand_empty_rest_of_line ();
815 obj_coff_type (ignore
)
818 if (def_symbol_in_progress
== NULL
)
820 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
821 demand_empty_rest_of_line ();
823 } /* if not inside .def/.endef */
825 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
827 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
828 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
830 SF_SET_FUNCTION (def_symbol_in_progress
);
831 } /* is a function */
833 demand_empty_rest_of_line ();
837 obj_coff_val (ignore
)
840 if (def_symbol_in_progress
== NULL
)
842 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
843 demand_empty_rest_of_line ();
845 } /* if not inside .def/.endef */
847 if (is_name_beginner (*input_line_pointer
))
849 char *symbol_name
= input_line_pointer
;
850 char name_end
= get_symbol_end ();
852 if (!strcmp (symbol_name
, "."))
854 def_symbol_in_progress
->sy_frag
= frag_now
;
855 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
856 /* If the .val is != from the .def (e.g. statics) */
858 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
860 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
861 def_symbol_in_progress
->sy_value
.X_add_symbol
=
862 symbol_find_or_make (symbol_name
);
863 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
864 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
866 /* If the segment is undefined when the forward reference is
867 resolved, then copy the segment id from the forward
869 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
871 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
872 *input_line_pointer
= name_end
;
876 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
877 } /* if symbol based */
879 demand_empty_rest_of_line ();
883 obj_read_begin_hook ()
885 /* These had better be the same. Usually 18 bytes. */
887 know (sizeof (SYMENT
) == sizeof (AUXENT
));
888 know (SYMESZ
== AUXESZ
);
894 symbolS
*coff_last_function
;
895 static symbolS
*coff_last_bf
;
898 coff_frob_symbol (symp
, punt
)
902 static symbolS
*last_tagP
;
903 static stack
*block_stack
;
904 static symbolS
*set_end
;
905 symbolS
*next_set_end
= NULL
;
907 if (symp
== &abs_symbol
)
913 if (current_lineno_sym
)
914 coff_add_linesym ((symbolS
*) 0);
917 block_stack
= stack_init (512, sizeof (symbolS
*));
919 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
920 S_SET_STORAGE_CLASS (symp
, C_EXT
);
922 if (!SF_GET_DEBUG (symp
))
925 if (!SF_GET_LOCAL (symp
)
926 && !SF_GET_STATICS (symp
)
927 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
930 c_symbol_merge (symp
, real
);
933 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
935 assert (S_GET_VALUE (symp
) == 0);
936 S_SET_EXTERNAL (symp
);
938 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
940 if (S_GET_SEGMENT (symp
) == text_section
941 && symp
!= seg_info (text_section
)->sym
)
942 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
944 S_SET_STORAGE_CLASS (symp
, C_STAT
);
946 if (SF_GET_PROCESS (symp
))
948 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
950 if (!strcmp (S_GET_NAME (symp
), ".bb"))
951 stack_push (block_stack
, (char *) &symp
);
955 begin
= *(symbolS
**) stack_pop (block_stack
);
957 as_warn ("mismatched .eb");
959 next_set_end
= begin
;
962 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
964 union internal_auxent
*auxp
;
965 coff_last_function
= symp
;
966 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
967 S_SET_NUMBER_AUXILIARY (symp
, 1);
968 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
969 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
970 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
972 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
974 if (coff_last_function
== 0)
975 as_fatal ("C_EFCN symbol out of scope");
976 SA_SET_SYM_FSIZE (coff_last_function
,
977 (long) (S_GET_VALUE (symp
)
978 - S_GET_VALUE (coff_last_function
)));
979 next_set_end
= coff_last_function
;
980 coff_last_function
= 0;
983 if (S_IS_EXTERNAL (symp
))
984 S_SET_STORAGE_CLASS (symp
, C_EXT
);
985 else if (SF_GET_LOCAL (symp
))
988 if (SF_GET_FUNCTION (symp
))
989 symp
->bsym
->flags
|= BSF_FUNCTION
;
994 if (SF_GET_TAG (symp
))
996 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
997 next_set_end
= last_tagP
;
998 else if (S_GET_STORAGE_CLASS (symp
) == C_FILE
)
1000 if (S_GET_VALUE (symp
))
1002 S_SET_VALUE ((symbolS
*) S_GET_VALUE (symp
), 0xdeadbeef);
1003 S_SET_VALUE (symp
, 0);
1008 /* This is pretty horrible, but we have to set *punt correctly in
1009 order to call SA_SET_SYM_ENDNDX correctly. */
1010 if (! symp
->sy_used_in_reloc
1011 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1012 || (! S_IS_EXTERNAL (symp
)
1013 && ! symp
->sy_tc
.output
1014 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1018 if (set_end
!= (symbolS
*) NULL
1020 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1021 || (S_IS_DEFINED (symp
)
1022 && ! S_IS_COMMON (symp
)
1023 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1025 SA_SET_SYM_ENDNDX (set_end
, symp
);
1029 if (next_set_end
!= NULL
1031 set_end
= next_set_end
;
1034 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1035 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1037 if (coff_last_bf
!= NULL
)
1038 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1039 coff_last_bf
= symp
;
1042 if (coffsymbol (symp
->bsym
)->lineno
)
1045 struct line_no
*lptr
;
1048 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1049 for (i
= 0; lptr
; lptr
= lptr
->next
)
1051 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1053 /* We need i entries for line numbers, plus 1 for the first
1054 entry which BFD will override, plus 1 for the last zero
1055 entry (a marker for BFD). */
1056 l
= (alent
*) bfd_alloc_by_size_t (stdoutput
, (i
+ 2) * sizeof (alent
));
1057 coffsymbol (symp
->bsym
)->lineno
= l
;
1058 l
[i
+ 1].line_number
= 0;
1059 l
[i
+ 1].u
.sym
= NULL
;
1063 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1071 coff_adjust_section_syms (abfd
, sec
, x
)
1077 segment_info_type
*seginfo
= seg_info (sec
);
1078 int nlnno
, nrelocs
= 0;
1080 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1081 tc-ppc.c. Do not get confused by it. */
1082 if (seginfo
== NULL
)
1085 if (!strcmp (sec
->name
, ".text"))
1086 nlnno
= coff_n_line_nos
;
1090 /* @@ Hope that none of the fixups expand to more than one reloc
1092 fixS
*fixp
= seginfo
->fix_root
;
1095 fixp
= fixp
->fx_next
;
1099 if (bfd_get_section_size_before_reloc (sec
) == 0
1102 && sec
!= text_section
1103 && sec
!= data_section
1104 && sec
!= bss_section
)
1106 secsym
= section_symbol (sec
);
1107 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1108 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1114 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1118 * implement the .section pseudo op:
1119 * .section name {, "flags"}
1121 * | +--- optional flags: 'b' for bss
1123 * +-- section name 'l' for lib
1127 * 'd' (apparently m88k for data)
1129 * But if the argument is not a quoted string, treat it as a
1130 * subsegment number.
1134 obj_coff_section (ignore
)
1137 /* Strip out the section name */
1153 section_name
= input_line_pointer
;
1154 c
= get_symbol_end ();
1156 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1157 strcpy (name
, section_name
);
1159 *input_line_pointer
= c
;
1164 flags
= SEC_NO_FLAGS
;
1166 if (*input_line_pointer
== ',')
1168 ++input_line_pointer
;
1170 if (*input_line_pointer
!= '"')
1171 exp
= get_absolute_expression ();
1174 ++input_line_pointer
;
1175 while (*input_line_pointer
!= '"'
1176 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1178 switch (*input_line_pointer
)
1180 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1181 case 'n': flags
&=~ SEC_LOAD
; break;
1183 case 'w': flags
&=~ SEC_READONLY
; break;
1184 case 'x': flags
|= SEC_CODE
; break;
1186 case 'i': /* STYP_INFO */
1187 case 'l': /* STYP_LIB */
1188 case 'o': /* STYP_OVER */
1189 as_warn ("unsupported section attribute '%c'",
1190 *input_line_pointer
);
1194 as_warn("unknown section attribute '%c'",
1195 *input_line_pointer
);
1198 ++input_line_pointer
;
1200 if (*input_line_pointer
== '"')
1201 ++input_line_pointer
;
1205 sec
= subseg_new (name
, (subsegT
) exp
);
1207 if (flags
!= SEC_NO_FLAGS
)
1209 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1210 as_warn ("error setting flags for \"%s\": %s",
1211 bfd_section_name (stdoutput
, sec
),
1212 bfd_errmsg (bfd_get_error ()));
1215 demand_empty_rest_of_line ();
1219 coff_adjust_symtab ()
1221 if (symbol_rootP
== NULL
1222 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1224 assert (previous_file_symbol
== 0);
1225 c_dot_file_symbol ("fake");
1230 coff_frob_section (sec
)
1236 bfd_vma size
, n_entries
, mask
;
1238 /* The COFF back end in BFD requires that all section sizes be
1239 rounded up to multiples of the corresponding section alignments.
1240 Seems kinda silly to me, but that's the way it is. */
1241 size
= bfd_get_section_size_before_reloc (sec
);
1242 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1245 size
= (size
+ mask
) & ~mask
;
1246 bfd_set_section_size (stdoutput
, sec
, size
);
1249 /* If the section size is non-zero, the section symbol needs an aux
1250 entry associated with it, indicating the size. We don't know
1251 all the values yet; coff_frob_symbol will fill them in later. */
1253 || sec
== text_section
1254 || sec
== data_section
1255 || sec
== bss_section
)
1257 symbolS
*secsym
= section_symbol (sec
);
1259 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1260 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1261 SF_SET_STATICS (secsym
);
1262 SA_SET_SCN_SCNLEN (secsym
, size
);
1265 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1266 #ifndef STAB_SECTION_NAME
1267 #define STAB_SECTION_NAME ".stab"
1269 #ifndef STAB_STRING_SECTION_NAME
1270 #define STAB_STRING_SECTION_NAME ".stabstr"
1272 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1276 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1277 /* size is already rounded up, since other section will be listed first */
1278 size
= bfd_get_section_size_before_reloc (strsec
);
1280 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1282 /* Find first non-empty frag. It should be large enough. */
1283 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1284 while (fragp
&& fragp
->fr_fix
== 0)
1285 fragp
= fragp
->fr_next
;
1286 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1288 /* Store the values. */
1289 p
= fragp
->fr_literal
;
1290 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1291 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1295 obj_coff_init_stab_section (seg
)
1301 unsigned int stroff
;
1303 /* Make space for this first symbol. */
1307 as_where (&file
, (unsigned int *) NULL
);
1308 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1309 strcpy (stabstr_name
, seg
->name
);
1310 strcat (stabstr_name
, "str");
1311 stroff
= get_stab_string_offset (file
, stabstr_name
);
1313 md_number_to_chars (p
, stroff
, 4);
1322 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1330 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1332 printf("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n",
1333 (unsigned long) symbolP
,
1334 S_GET_NAME(symbolP
),
1335 (long) S_GET_DATA_TYPE(symbolP
),
1336 S_GET_STORAGE_CLASS(symbolP
),
1337 (int) S_GET_SEGMENT(symbolP
));
1343 #else /* not BFD_ASSEMBLER */
1346 /* This is needed because we include internal bfd things. */
1350 #include "libcoff.h"
1353 #include "coff/pe.h"
1356 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1357 that we can stick sections together without causing trouble. */
1359 #define NOP_OPCODE 0x00
1362 /* The zeroes if symbol name is longer than 8 chars */
1363 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1365 #define MIN(a,b) ((a) < (b)? (a) : (b))
1366 /* This vector is used to turn an internal segment into a section #
1367 suitable for insertion into a coff symbol table
1370 const short seg_N_TYPE
[] =
1371 { /* in: segT out: N_TYPE bits */
1373 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1374 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1375 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1376 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1377 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1378 C_UNDEF_SECTION
, /* SEG_GOOF */
1379 C_UNDEF_SECTION
, /* SEG_EXPR */
1380 C_DEBUG_SECTION
, /* SEG_DEBUG */
1381 C_NTV_SECTION
, /* SEG_NTV */
1382 C_PTV_SECTION
, /* SEG_PTV */
1383 C_REGISTER_SECTION
, /* SEG_REGISTER */
1386 int function_lineoff
= -1; /* Offset in line#s where the last function
1387 started (the odd entry for line #0) */
1389 /* structure used to keep the filenames which
1390 are too long around so that we can stick them
1391 into the string table */
1392 struct filename_list
1395 struct filename_list
*next
;
1398 static struct filename_list
*filename_list_head
;
1399 static struct filename_list
*filename_list_tail
;
1401 static symbolS
*last_line_symbol
;
1403 /* Add 4 to the real value to get the index and compensate the
1404 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1405 section number into a segment number
1407 static symbolS
*previous_file_symbol
;
1408 void c_symbol_merge ();
1409 static int line_base
;
1411 symbolS
*c_section_symbol ();
1414 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1415 segT this_segment_type
));
1418 static void fixup_mdeps
PARAMS ((fragS
*,
1423 static void fill_section
PARAMS ((bfd
* abfd
,
1428 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1433 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1434 symbolS
* symbol_rootP
));
1436 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1438 static void obj_coff_lcomm
PARAMS ((int));
1439 static void obj_coff_text
PARAMS ((int));
1440 static void obj_coff_data
PARAMS ((int));
1441 static void obj_coff_bss
PARAMS ((int));
1442 static void obj_coff_ident
PARAMS ((int));
1443 void obj_coff_section
PARAMS ((int));
1447 We allow more than just the standard 3 sections, infact, we allow
1448 40 sections, (though the usual three have to be there).
1450 This structure performs the mappings for us:
1460 static const seg_info_type seg_info_off_by_4
[] =
1467 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1468 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1469 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1470 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1471 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1472 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1473 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1474 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1489 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1491 static relax_addressT
1492 relax_align (address
, alignment
)
1493 relax_addressT address
;
1496 relax_addressT mask
;
1497 relax_addressT new_address
;
1499 mask
= ~((~0) << alignment
);
1500 new_address
= (address
+ mask
) & (~mask
);
1501 return (new_address
- address
);
1509 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1514 /* calculate the size of the frag chain and fill in the section header
1515 to contain all of it, also fill in the addr of the sections */
1517 size_section (abfd
, idx
)
1522 unsigned int size
= 0;
1523 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1526 size
= frag
->fr_address
;
1527 if (frag
->fr_address
!= size
)
1529 fprintf (stderr
, "Out of step\n");
1530 size
= frag
->fr_address
;
1533 switch (frag
->fr_type
)
1535 #ifdef TC_COFF_SIZEMACHDEP
1536 case rs_machine_dependent
:
1537 size
+= TC_COFF_SIZEMACHDEP (frag
);
1541 assert (frag
->fr_symbol
== 0);
1544 size
+= frag
->fr_fix
;
1545 size
+= frag
->fr_offset
* frag
->fr_var
;
1549 size
+= frag
->fr_fix
;
1550 size
+= relax_align (size
, frag
->fr_offset
);
1553 BAD_CASE (frag
->fr_type
);
1556 frag
= frag
->fr_next
;
1558 segment_info
[idx
].scnhdr
.s_size
= size
;
1564 count_entries_in_chain (idx
)
1567 unsigned int nrelocs
;
1570 /* Count the relocations */
1571 fixup_ptr
= segment_info
[idx
].fix_root
;
1573 while (fixup_ptr
!= (fixS
*) NULL
)
1575 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1578 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1587 fixup_ptr
= fixup_ptr
->fx_next
;
1594 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1596 /* AUX's ld expects relocations to be sorted */
1598 compare_external_relocs (x
, y
)
1602 struct external_reloc
*a
= (struct external_reloc
*) x
;
1603 struct external_reloc
*b
= (struct external_reloc
*) y
;
1604 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1605 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1606 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1611 /* output all the relocations for a section */
1613 do_relocs_for (abfd
, h
, file_cursor
)
1616 unsigned long *file_cursor
;
1618 unsigned int nrelocs
;
1620 unsigned long reloc_start
= *file_cursor
;
1622 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1624 if (segment_info
[idx
].scnhdr
.s_name
[0])
1626 struct external_reloc
*ext_ptr
;
1627 struct external_reloc
*external_reloc_vec
;
1628 unsigned int external_reloc_size
;
1629 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1630 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1631 nrelocs
= count_entries_in_chain (idx
);
1634 /* Bypass this stuff if no relocs. This also incidentally
1635 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1637 external_reloc_size
= nrelocs
* RELSZ
;
1638 external_reloc_vec
=
1639 (struct external_reloc
*) malloc (external_reloc_size
);
1641 ext_ptr
= external_reloc_vec
;
1643 /* Fill in the internal coff style reloc struct from the
1644 internal fix list. */
1647 struct internal_reloc intr
;
1649 /* Only output some of the relocations */
1650 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1652 #ifdef TC_RELOC_MANGLE
1653 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1658 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1660 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1662 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1664 #ifdef TC_KEEP_FX_OFFSET
1665 intr
.r_offset
= fix_ptr
->fx_offset
;
1670 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1671 && (! S_IS_DEFINED (symbol_ptr
)
1672 || S_IS_COMMON (symbol_ptr
)))
1673 symbol_ptr
= symbol_ptr
->sy_value
.X_add_symbol
;
1675 /* Turn the segment of the symbol into an offset. */
1678 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1681 intr
.r_symndx
= dot
->sy_number
;
1685 intr
.r_symndx
= symbol_ptr
->sy_number
;
1695 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1698 #if defined(TC_A29K)
1700 /* The 29k has a special kludge for the high 16 bit
1701 reloc. Two relocations are emited, R_IHIHALF,
1702 and R_IHCONST. The second one doesn't contain a
1703 symbol, but uses the value for offset. */
1705 if (intr
.r_type
== R_IHIHALF
)
1707 /* now emit the second bit */
1708 intr
.r_type
= R_IHCONST
;
1709 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1710 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1716 fix_ptr
= fix_ptr
->fx_next
;
1720 /* Sort the reloc table */
1721 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1722 sizeof (struct external_reloc
), compare_external_relocs
);
1725 /* Write out the reloc table */
1726 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1728 free (external_reloc_vec
);
1730 /* Fill in section header info. */
1731 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1732 *file_cursor
+= external_reloc_size
;
1733 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1738 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1742 /* Set relocation_size field in file headers */
1743 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1747 /* run through a frag chain and write out the data to go with it, fill
1748 in the scnhdrs with the info on the file postions
1751 fill_section (abfd
, h
, file_cursor
)
1754 unsigned long *file_cursor
;
1758 unsigned int paddr
= 0;
1760 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1762 unsigned int offset
= 0;
1763 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1769 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1776 buffer
= xmalloc (s
->s_size
);
1777 s
->s_scnptr
= *file_cursor
;
1779 know (s
->s_paddr
== paddr
);
1781 if (strcmp (s
->s_name
, ".text") == 0)
1782 s
->s_flags
|= STYP_TEXT
;
1783 else if (strcmp (s
->s_name
, ".data") == 0)
1784 s
->s_flags
|= STYP_DATA
;
1785 else if (strcmp (s
->s_name
, ".bss") == 0)
1788 s
->s_flags
|= STYP_BSS
;
1790 /* @@ Should make the i386 and a29k coff targets define
1791 COFF_NOLOAD_PROBLEM, and have only one test here. */
1794 #ifndef COFF_NOLOAD_PROBLEM
1795 /* Apparently the SVR3 linker (and exec syscall) and UDI
1796 mondfe progrem are confused by noload sections. */
1797 s
->s_flags
|= STYP_NOLOAD
;
1802 else if (strcmp (s
->s_name
, ".lit") == 0)
1803 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1804 else if (strcmp (s
->s_name
, ".init") == 0)
1805 s
->s_flags
|= STYP_TEXT
;
1806 else if (strcmp (s
->s_name
, ".fini") == 0)
1807 s
->s_flags
|= STYP_TEXT
;
1808 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1809 s
->s_flags
|= STYP_INFO
;
1813 unsigned int fill_size
;
1814 switch (frag
->fr_type
)
1816 case rs_machine_dependent
:
1819 memcpy (buffer
+ frag
->fr_address
,
1821 (unsigned int) frag
->fr_fix
);
1822 offset
+= frag
->fr_fix
;
1827 assert (frag
->fr_symbol
== 0);
1834 memcpy (buffer
+ frag
->fr_address
,
1836 (unsigned int) frag
->fr_fix
);
1837 offset
+= frag
->fr_fix
;
1840 fill_size
= frag
->fr_var
;
1841 if (fill_size
&& frag
->fr_offset
> 0)
1844 unsigned int off
= frag
->fr_fix
;
1845 for (count
= frag
->fr_offset
; count
; count
--)
1847 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1849 memcpy (buffer
+ frag
->fr_address
+ off
,
1850 frag
->fr_literal
+ frag
->fr_fix
,
1853 offset
+= fill_size
;
1858 case rs_broken_word
:
1863 frag
= frag
->fr_next
;
1868 if (s
->s_scnptr
!= 0)
1870 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1871 *file_cursor
+= s
->s_size
;
1880 /* Coff file generation & utilities */
1883 coff_header_append (abfd
, h
)
1891 bfd_seek (abfd
, 0, 0);
1893 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1894 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1895 H_SET_VERSION_STAMP (h
, 0);
1896 H_SET_ENTRY_POINT (h
, 0);
1897 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1898 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1899 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1901 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1902 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1903 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1905 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1907 bfd_write (buffer
, i
, 1, abfd
);
1908 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1910 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1912 #ifdef COFF_LONG_SECTION_NAMES
1913 unsigned long string_size
= 4;
1916 if (segment_info
[i
].scnhdr
.s_name
[0])
1920 #ifdef COFF_LONG_SECTION_NAMES
1921 /* Support long section names as found in PE. This code
1922 must coordinate with that in write_object_file and
1924 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1926 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1927 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1928 string_size
+= strlen (segment_info
[i
].name
) + 1;
1932 size
= bfd_coff_swap_scnhdr_out (abfd
,
1933 &(segment_info
[i
].scnhdr
),
1936 as_bad ("bfd_coff_swap_scnhdr_out failed");
1937 bfd_write (buffer
, size
, 1, abfd
);
1944 symbol_to_chars (abfd
, where
, symbolP
)
1949 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1953 /* Turn any symbols with register attributes into abs symbols */
1954 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1956 S_SET_SEGMENT (symbolP
, absolute_section
);
1958 /* At the same time, relocate all symbols to their output value */
1960 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1961 + S_GET_VALUE (symbolP
));
1963 S_SET_VALUE (symbolP
, val
);
1965 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
1967 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
1970 for (i
= 0; i
< numaux
; i
++)
1972 where
+= bfd_coff_swap_aux_out (abfd
,
1973 &symbolP
->sy_symbol
.ost_auxent
[i
],
1974 S_GET_DATA_TYPE (symbolP
),
1975 S_GET_STORAGE_CLASS (symbolP
),
1983 obj_symbol_new_hook (symbolP
)
1986 char underscore
= 0; /* Symbol has leading _ */
1988 /* Effective symbol */
1989 /* Store the pointer in the offset. */
1990 S_SET_ZEROES (symbolP
, 0L);
1991 S_SET_DATA_TYPE (symbolP
, T_NULL
);
1992 S_SET_STORAGE_CLASS (symbolP
, 0);
1993 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
1994 /* Additional information */
1995 symbolP
->sy_symbol
.ost_flags
= 0;
1996 /* Auxiliary entries */
1997 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
1999 if (S_IS_STRING (symbolP
))
2000 SF_SET_STRING (symbolP
);
2001 if (!underscore
&& S_IS_LOCAL (symbolP
))
2002 SF_SET_LOCAL (symbolP
);
2006 * Handle .ln directives.
2010 obj_coff_ln (appline
)
2015 if (! appline
&& def_symbol_in_progress
!= NULL
)
2017 as_warn (".ln pseudo-op inside .def/.endef: ignored.");
2018 demand_empty_rest_of_line ();
2020 } /* wrong context */
2022 l
= get_absolute_expression ();
2023 c_line_new (0, frag_now_fix (), l
, frag_now
);
2032 listing_source_line ((unsigned int) l
);
2037 demand_empty_rest_of_line ();
2043 * Handle .def directives.
2045 * One might ask : why can't we symbol_new if the symbol does not
2046 * already exist and fill it with debug information. Because of
2047 * the C_EFCN special symbol. It would clobber the value of the
2048 * function symbol before we have a chance to notice that it is
2049 * a C_EFCN. And a second reason is that the code is more clear this
2050 * way. (at least I think it is :-).
2054 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2055 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2056 *input_line_pointer == '\t') \
2057 input_line_pointer++;
2063 char name_end
; /* Char after the end of name */
2064 char *symbol_name
; /* Name of the debug symbol */
2065 char *symbol_name_copy
; /* Temporary copy of the name */
2066 unsigned int symbol_name_length
;
2068 if (def_symbol_in_progress
!= NULL
)
2070 as_warn (".def pseudo-op used inside of .def/.endef: ignored.");
2071 demand_empty_rest_of_line ();
2073 } /* if not inside .def/.endef */
2075 SKIP_WHITESPACES ();
2077 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2078 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2080 symbol_name
= input_line_pointer
;
2081 name_end
= get_symbol_end ();
2082 symbol_name_length
= strlen (symbol_name
);
2083 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2084 strcpy (symbol_name_copy
, symbol_name
);
2086 /* Initialize the new symbol */
2087 #ifdef STRIP_UNDERSCORE
2088 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2089 ? symbol_name_copy
+ 1
2090 : symbol_name_copy
));
2091 #else /* STRIP_UNDERSCORE */
2092 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2093 #endif /* STRIP_UNDERSCORE */
2094 /* free(symbol_name_copy); */
2095 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2096 def_symbol_in_progress
->sy_number
= ~0;
2097 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2098 S_SET_VALUE (def_symbol_in_progress
, 0);
2100 if (S_IS_STRING (def_symbol_in_progress
))
2101 SF_SET_STRING (def_symbol_in_progress
);
2103 *input_line_pointer
= name_end
;
2105 demand_empty_rest_of_line ();
2108 unsigned int dim_index
;
2112 obj_coff_endef (ignore
)
2115 symbolS
*symbolP
= 0;
2116 /* DIM BUG FIX sac@cygnus.com */
2118 if (def_symbol_in_progress
== NULL
)
2120 as_warn (".endef pseudo-op used outside of .def/.endef: ignored.");
2121 demand_empty_rest_of_line ();
2123 } /* if not inside .def/.endef */
2125 /* Set the section number according to storage class. */
2126 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2131 SF_SET_TAG (def_symbol_in_progress
);
2132 /* intentional fallthrough */
2135 SF_SET_DEBUG (def_symbol_in_progress
);
2136 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2140 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2141 /* intentional fallthrough */
2143 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2144 /* intentional fallthrough */
2146 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2148 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2150 if (function_lineoff
< 0)
2152 fprintf (stderr
, "`.bf' symbol without preceding function\n");
2153 } /* missing function symbol */
2154 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2156 SF_SET_PROCESS (last_line_symbol
);
2157 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2158 SF_SET_PROCESS (def_symbol_in_progress
);
2159 function_lineoff
= -1;
2161 /* Value is always set to . */
2162 def_symbol_in_progress
->sy_frag
= frag_now
;
2163 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2168 #endif /* C_AUTOARG */
2178 SF_SET_DEBUG (def_symbol_in_progress
);
2179 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2185 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2191 as_warn ("unexpected storage class %d", S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2193 } /* switch on storage class */
2195 /* Now that we have built a debug symbol, try to find if we should
2196 merge with an existing symbol or not. If a symbol is C_EFCN or
2197 absolute_section or untagged SEG_DEBUG it never merges. We also
2198 don't merge labels, which are in a different namespace, nor
2199 symbols which have not yet been defined since they are typically
2200 unique, nor do we merge tags with non-tags. */
2202 /* Two cases for functions. Either debug followed by definition or
2203 definition followed by debug. For definition first, we will
2204 merge the debug symbol into the definition. For debug first, the
2205 lineno entry MUST point to the definition function or else it
2206 will point off into space when crawl_symbols() merges the debug
2207 symbol into the real symbol. Therefor, let's presume the debug
2208 symbol is a real function reference. */
2210 /* FIXME-SOON If for some reason the definition label/symbol is
2211 never seen, this will probably leave an undefined symbol at link
2214 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2215 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2216 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2217 && !SF_GET_TAG (def_symbol_in_progress
))
2218 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2219 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2220 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2221 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2223 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2228 /* This symbol already exists, merge the newly created symbol
2229 into the old one. This is not mandatory. The linker can
2230 handle duplicate symbols correctly. But I guess that it save
2231 a *lot* of space if the assembly file defines a lot of
2234 /* The debug entry (def_symbol_in_progress) is merged into the
2235 previous definition. */
2237 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2238 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2239 def_symbol_in_progress
= symbolP
;
2241 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2242 || SF_GET_TAG (def_symbol_in_progress
))
2244 /* For functions, and tags, the symbol *must* be where the
2245 debug symbol appears. Move the existing symbol to the
2247 /* If it already is at the end of the symbol list, do nothing */
2248 if (def_symbol_in_progress
!= symbol_lastP
)
2250 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2252 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2253 &symbol_rootP
, &symbol_lastP
);
2254 } /* if not already in place */
2256 } /* normal or mergable */
2258 if (SF_GET_TAG (def_symbol_in_progress
))
2262 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2264 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2265 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2266 def_symbol_in_progress
);
2269 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2271 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2273 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2275 SF_SET_PROCESS (def_symbol_in_progress
);
2277 if (symbolP
== NULL
)
2279 /* That is, if this is the first time we've seen the
2281 symbol_table_insert (def_symbol_in_progress
);
2282 } /* definition follows debug */
2283 } /* Create the line number entry pointing to the function being defined */
2285 def_symbol_in_progress
= NULL
;
2286 demand_empty_rest_of_line ();
2290 obj_coff_dim (ignore
)
2295 if (def_symbol_in_progress
== NULL
)
2297 as_warn (".dim pseudo-op used outside of .def/.endef: ignored.");
2298 demand_empty_rest_of_line ();
2300 } /* if not inside .def/.endef */
2302 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2304 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2306 SKIP_WHITESPACES ();
2307 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2308 get_absolute_expression ());
2310 switch (*input_line_pointer
)
2313 input_line_pointer
++;
2317 as_warn ("badly formed .dim directive ignored");
2318 /* intentional fallthrough */
2326 demand_empty_rest_of_line ();
2330 obj_coff_line (ignore
)
2336 if (def_symbol_in_progress
== NULL
)
2342 name
= S_GET_NAME (def_symbol_in_progress
);
2343 this_base
= get_absolute_expression ();
2345 /* Only .bf symbols indicate the use of a new base line number; the
2346 line numbers associated with .ef, .bb, .eb are relative to the
2347 start of the containing function. */
2348 if (!strcmp (".bf", name
))
2350 #if 0 /* XXX Can we ever have line numbers going backwards? */
2351 if (this_base
> line_base
)
2354 line_base
= this_base
;
2362 listing_source_line ((unsigned int) line_base
);
2368 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2369 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2371 demand_empty_rest_of_line ();
2375 obj_coff_size (ignore
)
2378 if (def_symbol_in_progress
== NULL
)
2380 as_warn (".size pseudo-op used outside of .def/.endef ignored.");
2381 demand_empty_rest_of_line ();
2383 } /* if not inside .def/.endef */
2385 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2386 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2387 demand_empty_rest_of_line ();
2391 obj_coff_scl (ignore
)
2394 if (def_symbol_in_progress
== NULL
)
2396 as_warn (".scl pseudo-op used outside of .def/.endef ignored.");
2397 demand_empty_rest_of_line ();
2399 } /* if not inside .def/.endef */
2401 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2402 demand_empty_rest_of_line ();
2406 obj_coff_tag (ignore
)
2412 if (def_symbol_in_progress
== NULL
)
2414 as_warn (".tag pseudo-op used outside of .def/.endef ignored.");
2415 demand_empty_rest_of_line ();
2419 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2420 symbol_name
= input_line_pointer
;
2421 name_end
= get_symbol_end ();
2423 /* Assume that the symbol referred to by .tag is always defined.
2424 This was a bad assumption. I've added find_or_make. xoxorich. */
2425 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2426 (long) tag_find_or_make (symbol_name
));
2427 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2429 as_warn ("tag not found for .tag %s", symbol_name
);
2432 SF_SET_TAGGED (def_symbol_in_progress
);
2433 *input_line_pointer
= name_end
;
2435 demand_empty_rest_of_line ();
2439 obj_coff_type (ignore
)
2442 if (def_symbol_in_progress
== NULL
)
2444 as_warn (".type pseudo-op used outside of .def/.endef ignored.");
2445 demand_empty_rest_of_line ();
2447 } /* if not inside .def/.endef */
2449 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2451 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2452 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2454 SF_SET_FUNCTION (def_symbol_in_progress
);
2455 } /* is a function */
2457 demand_empty_rest_of_line ();
2461 obj_coff_val (ignore
)
2464 if (def_symbol_in_progress
== NULL
)
2466 as_warn (".val pseudo-op used outside of .def/.endef ignored.");
2467 demand_empty_rest_of_line ();
2469 } /* if not inside .def/.endef */
2471 if (is_name_beginner (*input_line_pointer
))
2473 char *symbol_name
= input_line_pointer
;
2474 char name_end
= get_symbol_end ();
2476 if (!strcmp (symbol_name
, "."))
2478 def_symbol_in_progress
->sy_frag
= frag_now
;
2479 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2480 /* If the .val is != from the .def (e.g. statics) */
2482 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2484 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2485 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2486 symbol_find_or_make (symbol_name
);
2487 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2488 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2490 /* If the segment is undefined when the forward reference is
2491 resolved, then copy the segment id from the forward
2493 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2495 /* FIXME: gcc can generate address expressions
2496 here in unusual cases (search for "obscure"
2497 in sdbout.c). We just ignore the offset
2498 here, thus generating incorrect debugging
2499 information. We ignore the rest of the
2502 /* Otherwise, it is the name of a non debug symbol and
2503 its value will be calculated later. */
2504 *input_line_pointer
= name_end
;
2506 /* FIXME: this is to avoid an error message in the
2507 FIXME case mentioned just above. */
2508 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2509 ++input_line_pointer
;
2513 S_SET_VALUE (def_symbol_in_progress
,
2514 (valueT
) get_absolute_expression ());
2515 } /* if symbol based */
2517 demand_empty_rest_of_line ();
2522 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2523 read.c, which then calls this object file format specific routine. */
2526 obj_coff_pe_handle_link_once (type
)
2527 enum linkonce_type type
;
2529 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2531 /* We store the type in the seg_info structure, and use it to set up
2532 the auxiliary entry for the section symbol in c_section_symbol. */
2533 seg_info (now_seg
)->linkonce
= type
;
2539 obj_read_begin_hook ()
2541 /* These had better be the same. Usually 18 bytes. */
2543 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2544 know (SYMESZ
== AUXESZ
);
2549 /* This function runs through the symbol table and puts all the
2550 externals onto another chain */
2552 /* The chain of globals. */
2553 symbolS
*symbol_globalP
;
2554 symbolS
*symbol_global_lastP
;
2556 /* The chain of externals */
2557 symbolS
*symbol_externP
;
2558 symbolS
*symbol_extern_lastP
;
2561 symbolS
*last_functionP
;
2562 static symbolS
*last_bfP
;
2569 unsigned int symbol_number
= 0;
2570 unsigned int last_file_symno
= 0;
2572 struct filename_list
*filename_list_scan
= filename_list_head
;
2574 for (symbolP
= symbol_rootP
;
2576 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2578 if (symbolP
->sy_mri_common
)
2580 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2581 as_bad ("%s: global symbols not supported in common sections",
2582 S_GET_NAME (symbolP
));
2583 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2587 if (!SF_GET_DEBUG (symbolP
))
2589 /* Debug symbols do not need all this rubbish */
2590 symbolS
*real_symbolP
;
2592 /* L* and C_EFCN symbols never merge. */
2593 if (!SF_GET_LOCAL (symbolP
)
2594 && !SF_GET_STATICS (symbolP
)
2595 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2596 && symbolP
->sy_value
.X_op
== O_constant
2597 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2598 && real_symbolP
!= symbolP
)
2600 /* FIXME-SOON: where do dups come from?
2601 Maybe tag references before definitions? xoxorich. */
2602 /* Move the debug data from the debug symbol to the
2603 real symbol. Do NOT do the oposite (i.e. move from
2604 real symbol to debug symbol and remove real symbol from the
2605 list.) Because some pointers refer to the real symbol
2606 whereas no pointers refer to the debug symbol. */
2607 c_symbol_merge (symbolP
, real_symbolP
);
2608 /* Replace the current symbol by the real one */
2609 /* The symbols will never be the last or the first
2610 because : 1st symbol is .file and 3 last symbols are
2611 .text, .data, .bss */
2612 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2613 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2614 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2615 symbolP
= real_symbolP
;
2616 } /* if not local but dup'd */
2618 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2620 S_SET_SEGMENT (symbolP
, SEG_E0
);
2621 } /* push data into text */
2623 resolve_symbol_value (symbolP
);
2625 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2627 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2629 S_SET_EXTERNAL (symbolP
);
2631 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2633 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2637 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2641 /* Mainly to speed up if not -g */
2642 if (SF_GET_PROCESS (symbolP
))
2644 /* Handle the nested blocks auxiliary info. */
2645 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2647 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2648 stack_push (block_stack
, (char *) &symbolP
);
2651 register symbolS
*begin_symbolP
;
2652 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2653 if (begin_symbolP
== (symbolS
*) 0)
2654 as_warn ("mismatched .eb");
2656 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2659 /* If we are able to identify the type of a function, and we
2660 are out of a function (last_functionP == 0) then, the
2661 function symbol will be associated with an auxiliary
2663 if (last_functionP
== (symbolS
*) 0 &&
2664 SF_GET_FUNCTION (symbolP
))
2666 last_functionP
= symbolP
;
2668 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2670 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2671 } /* make it at least 1 */
2673 /* Clobber possible stale .dim information. */
2675 /* Iffed out by steve - this fries the lnnoptr info too */
2676 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2677 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2680 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2682 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2684 if (last_bfP
!= NULL
)
2685 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2689 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2691 /* I don't even know if this is needed for sdb. But
2692 the standard assembler generates it, so... */
2693 if (last_functionP
== (symbolS
*) 0)
2694 as_fatal ("C_EFCN symbol out of scope");
2695 SA_SET_SYM_FSIZE (last_functionP
,
2696 (long) (S_GET_VALUE (symbolP
) -
2697 S_GET_VALUE (last_functionP
)));
2698 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2699 last_functionP
= (symbolS
*) 0;
2703 else if (SF_GET_TAG (symbolP
))
2705 /* First descriptor of a structure must point to
2706 the first slot after the structure description. */
2707 last_tagP
= symbolP
;
2710 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2712 /* +2 take in account the current symbol */
2713 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2715 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2717 /* If the filename was too long to fit in the
2718 auxent, put it in the string table */
2719 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2720 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2722 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2723 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2724 filename_list_scan
= filename_list_scan
->next
;
2726 if (S_GET_VALUE (symbolP
))
2728 S_SET_VALUE (symbolP
, last_file_symno
);
2729 last_file_symno
= symbol_number
;
2730 } /* no one points at the first .file symbol */
2731 } /* if debug or tag or eos or file */
2733 /* We must put the external symbols apart. The loader
2734 does not bomb if we do not. But the references in
2735 the endndx field for a .bb symbol are not corrected
2736 if an external symbol is removed between .bb and .be.
2737 I.e in the following case :
2738 [20] .bb endndx = 22
2741 ld will move the symbol 21 to the end of the list but
2742 endndx will still be 22 instead of 21. */
2745 if (SF_GET_LOCAL (symbolP
))
2747 /* remove C_EFCN and LOCAL (L...) symbols */
2748 /* next pointer remains valid */
2749 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2752 else if (symbolP
->sy_value
.X_op
== O_symbol
2753 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2755 /* Skip symbols which were equated to undefined or common
2757 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2759 else if (!S_IS_DEFINED (symbolP
)
2760 && !S_IS_DEBUG (symbolP
)
2761 && !SF_GET_STATICS (symbolP
) &&
2762 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2763 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2764 /* if external, Remove from the list */
2765 symbolS
*hold
= symbol_previous (symbolP
);
2767 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2768 symbol_clear_list_pointers (symbolP
);
2769 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2772 else if (! S_IS_DEBUG (symbolP
)
2773 && ! SF_GET_STATICS (symbolP
)
2774 && ! SF_GET_FUNCTION (symbolP
)
2775 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2777 symbolS
*hold
= symbol_previous (symbolP
);
2779 /* The O'Reilly COFF book says that defined global symbols
2780 come at the end of the symbol table, just before
2781 undefined global symbols. */
2783 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2784 symbol_clear_list_pointers (symbolP
);
2785 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2786 &symbol_global_lastP
);
2791 if (SF_GET_STRING (symbolP
))
2793 symbolP
->sy_name_offset
= string_byte_count
;
2794 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2798 symbolP
->sy_name_offset
= 0;
2799 } /* fix "long" names */
2801 symbolP
->sy_number
= symbol_number
;
2802 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2803 } /* if local symbol */
2804 } /* traverse the symbol list */
2805 return symbol_number
;
2811 glue_symbols (head
, tail
)
2815 unsigned int symbol_number
= 0;
2818 for (symbolP
= *head
; *head
!= NULL
;)
2820 symbolS
*tmp
= *head
;
2823 symbol_remove (tmp
, head
, tail
);
2824 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2827 if (SF_GET_STRING (tmp
))
2829 tmp
->sy_name_offset
= string_byte_count
;
2830 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2834 tmp
->sy_name_offset
= 0;
2835 } /* fix "long" names */
2837 tmp
->sy_number
= symbol_number
;
2838 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2839 } /* append the entire extern chain */
2841 return symbol_number
;
2847 unsigned int symbol_number
= 0;
2850 for (symbolP
= symbol_rootP
; symbolP
; symbolP
=
2851 symbol_next (symbolP
))
2853 symbolP
->sy_number
= symbol_number
;
2857 if (SF_GET_TAGGED (symbolP
))
2861 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2864 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2866 return symbol_number
;
2871 crawl_symbols (h
, abfd
)
2877 /* Initialize the stack used to keep track of the matching .bb .be */
2879 block_stack
= stack_init (512, sizeof (symbolS
*));
2881 /* The symbol list should be ordered according to the following sequence
2884 * . debug entries for functions
2885 * . fake symbols for the sections, including.text .data and .bss
2887 * . undefined symbols
2888 * But this is not mandatory. The only important point is to put the
2889 * undefined symbols at the end of the list.
2892 if (symbol_rootP
== NULL
2893 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2895 c_dot_file_symbol ("fake");
2897 /* Is there a .file symbol ? If not insert one at the beginning. */
2900 * Build up static symbols for the sections, they are filled in later
2904 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2905 if (segment_info
[i
].scnhdr
.s_name
[0])
2906 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2909 /* Take all the externals out and put them into another chain */
2910 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2911 /* Take the externals and glue them onto the end.*/
2912 H_SET_SYMBOL_TABLE_SIZE (h
,
2913 (H_GET_SYMBOL_COUNT (h
)
2914 + glue_symbols (&symbol_globalP
,
2915 &symbol_global_lastP
)
2916 + glue_symbols (&symbol_externP
,
2917 &symbol_extern_lastP
)));
2919 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2920 know (symbol_globalP
== NULL
);
2921 know (symbol_global_lastP
== NULL
);
2922 know (symbol_externP
== NULL
);
2923 know (symbol_extern_lastP
== NULL
);
2927 * Find strings by crawling along symbol table chain.
2935 struct filename_list
*filename_list_scan
= filename_list_head
;
2937 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2938 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2941 #ifdef COFF_LONG_SECTION_NAMES
2942 /* Support long section names as found in PE. This code must
2943 coordinate with that in coff_header_append and write_object_file. */
2947 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2949 if (segment_info
[i
].scnhdr
.s_name
[0]
2950 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
2954 size
= strlen (segment_info
[i
].name
) + 1;
2955 memcpy (where
, segment_info
[i
].name
, size
);
2960 #endif /* COFF_LONG_SECTION_NAMES */
2962 for (symbolP
= symbol_rootP
;
2964 symbolP
= symbol_next (symbolP
))
2968 if (SF_GET_STRING (symbolP
))
2970 size
= strlen (S_GET_NAME (symbolP
)) + 1;
2971 memcpy (where
, S_GET_NAME (symbolP
), size
);
2974 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
2975 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2976 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2978 size
= strlen (filename_list_scan
->filename
) + 1;
2979 memcpy (where
, filename_list_scan
->filename
, size
);
2980 filename_list_scan
= filename_list_scan
->next
;
2987 do_linenos_for (abfd
, h
, file_cursor
)
2990 unsigned long *file_cursor
;
2993 unsigned long start
= *file_cursor
;
2995 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
2997 segment_info_type
*s
= segment_info
+ idx
;
3000 if (s
->scnhdr
.s_nlnno
!= 0)
3002 struct lineno_list
*line_ptr
;
3004 struct external_lineno
*buffer
=
3005 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3007 struct external_lineno
*dst
= buffer
;
3009 /* Run through the table we've built and turn it into its external
3010 form, take this chance to remove duplicates */
3012 for (line_ptr
= s
->lineno_list_head
;
3013 line_ptr
!= (struct lineno_list
*) NULL
;
3014 line_ptr
= line_ptr
->next
)
3017 if (line_ptr
->line
.l_lnno
== 0)
3019 /* Turn a pointer to a symbol into the symbols' index */
3020 line_ptr
->line
.l_addr
.l_symndx
=
3021 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3025 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3029 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3034 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3036 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3039 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3042 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3046 /* Now we run through the list of frag chains in a segment and
3047 make all the subsegment frags appear at the end of the
3048 list, as if the seg 0 was extra long */
3055 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3057 frchainS
*head
= segment_info
[i
].frchainP
;
3059 fragS
*prev_frag
= &dummy
;
3061 while (head
&& head
->frch_seg
== i
)
3063 prev_frag
->fr_next
= head
->frch_root
;
3064 prev_frag
= head
->frch_last
;
3065 head
= head
->frch_next
;
3067 prev_frag
->fr_next
= 0;
3071 unsigned long machine
;
3074 write_object_file ()
3078 struct frchain
*frchain_ptr
;
3080 object_headers headers
;
3081 unsigned long file_cursor
;
3084 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3089 as_perror ("FATAL: Can't create %s", out_file_name
);
3090 exit (EXIT_FAILURE
);
3092 bfd_set_format (abfd
, bfd_object
);
3093 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3095 string_byte_count
= 4;
3097 for (frchain_ptr
= frchain_root
;
3098 frchain_ptr
!= (struct frchain
*) NULL
;
3099 frchain_ptr
= frchain_ptr
->frch_next
)
3101 /* Run through all the sub-segments and align them up. Also
3102 close any open frags. We tack a .fill onto the end of the
3103 frag chain so that any .align's size can be worked by looking
3104 at the next frag. */
3106 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3107 #ifndef SUB_SEGMENT_ALIGN
3108 #define SUB_SEGMENT_ALIGN(SEG) 1
3112 static char nop
= NOP_OPCODE
;
3113 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), &nop
, 1, alignment_done
);
3116 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
);
3120 frag_wane (frag_now
);
3121 frag_now
->fr_fix
= 0;
3122 know (frag_now
->fr_next
== NULL
);
3129 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3131 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3134 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3136 /* Find out how big the sections are, and set the addresses. */
3138 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3142 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3143 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3145 if (segment_info
[i
].scnhdr
.s_name
[0])
3147 H_SET_NUMBER_OF_SECTIONS (&headers
,
3148 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3150 #ifdef COFF_LONG_SECTION_NAMES
3151 /* Support long section names as found in PE. This code
3152 must coordinate with that in coff_header_append and
3157 len
= strlen (segment_info
[i
].name
);
3159 string_byte_count
+= len
+ 1;
3161 #endif /* COFF_LONG_SECTION_NAMES */
3164 size
= size_section (abfd
, (unsigned int) i
);
3167 /* I think the section alignment is only used on the i960; the
3168 i960 needs it, and it should do no harm on other targets. */
3169 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3172 H_SET_TEXT_SIZE (&headers
, size
);
3173 else if (i
== SEG_E1
)
3174 H_SET_DATA_SIZE (&headers
, size
);
3175 else if (i
== SEG_E2
)
3176 H_SET_BSS_SIZE (&headers
, size
);
3179 /* Turn the gas native symbol table shape into a coff symbol table */
3180 crawl_symbols (&headers
, abfd
);
3182 if (string_byte_count
== 4)
3183 string_byte_count
= 0;
3185 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3191 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3193 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3194 fixup_segment (&segment_info
[i
], i
);
3197 /* Look for ".stab" segments and fill in their initial symbols
3199 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3201 name
= segment_info
[i
].name
;
3204 && strncmp (".stab", name
, 5) == 0
3205 && strncmp (".stabstr", name
, 8) != 0)
3206 adjust_stab_section (abfd
, i
);
3209 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3211 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3213 /* Plant the data */
3215 fill_section (abfd
, &headers
, &file_cursor
);
3217 do_relocs_for (abfd
, &headers
, &file_cursor
);
3219 do_linenos_for (abfd
, &headers
, &file_cursor
);
3221 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3222 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3223 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3225 H_SET_TIME_STAMP (&headers
, 0);
3227 #ifdef TC_COFF_SET_MACHINE
3228 TC_COFF_SET_MACHINE (&headers
);
3232 #define COFF_FLAGS 0
3235 #ifdef KEEP_RELOC_INFO
3236 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3237 COFF_FLAGS
| coff_flags
));
3239 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3240 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3241 COFF_FLAGS
| coff_flags
));
3245 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3246 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3248 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3249 w_symbols (abfd
, buffer1
, symbol_rootP
);
3250 if (string_byte_count
> 0)
3251 w_strings (buffer1
+ symtable_size
);
3252 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3256 coff_header_append (abfd
, &headers
);
3258 /* Recent changes to write need this, but where it should
3259 go is up to Ken.. */
3260 if (bfd_close_all_done (abfd
) == false)
3261 as_fatal ("Can't close %s: %s", out_file_name
,
3262 bfd_errmsg (bfd_get_error ()));
3265 extern bfd
*stdoutput
;
3272 /* Add a new segment. This is called from subseg_new via the
3273 obj_new_segment macro. */
3276 obj_coff_add_segment (name
)
3281 #ifndef COFF_LONG_SECTION_NAMES
3282 char buf
[SCNNMLEN
+ 1];
3284 strncpy (buf
, name
, SCNNMLEN
);
3285 buf
[SCNNMLEN
] = '\0';
3289 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3290 if (strcmp (name
, segment_info
[i
].name
) == 0)
3295 as_bad ("Too many new sections; can't add \"%s\"", name
);
3299 /* Add a new section. */
3300 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3301 sizeof (segment_info
[i
].scnhdr
.s_name
));
3302 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3303 segment_info
[i
].name
= xstrdup (name
);
3309 * implement the .section pseudo op:
3310 * .section name {, "flags"}
3312 * | +--- optional flags: 'b' for bss
3314 * +-- section name 'l' for lib
3318 * 'd' (apparently m88k for data)
3320 * But if the argument is not a quoted string, treat it as a
3321 * subsegment number.
3325 obj_coff_section (ignore
)
3328 /* Strip out the section name */
3329 char *section_name
, *name
;
3342 else if (type
== 'D')
3344 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3349 section_name
= input_line_pointer
;
3350 c
= get_symbol_end ();
3352 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3353 strcpy (name
, section_name
);
3355 *input_line_pointer
= c
;
3361 if (*input_line_pointer
== ',')
3363 ++input_line_pointer
;
3366 if (*input_line_pointer
!= '"')
3367 exp
= get_absolute_expression ();
3370 ++input_line_pointer
;
3371 while (*input_line_pointer
!= '"'
3372 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3374 switch (*input_line_pointer
)
3376 case 'b': flags
|= STYP_BSS
; break;
3377 case 'i': flags
|= STYP_INFO
; break;
3378 case 'l': flags
|= STYP_LIB
; break;
3379 case 'n': flags
|= STYP_NOLOAD
; break;
3380 case 'o': flags
|= STYP_OVER
; break;
3382 case 'w': flags
|= STYP_DATA
; break;
3383 case 'x': flags
|= STYP_TEXT
; break;
3385 as_warn("unknown section attribute '%c'",
3386 *input_line_pointer
);
3389 ++input_line_pointer
;
3391 if (*input_line_pointer
== '"')
3392 ++input_line_pointer
;
3396 subseg_new (name
, (subsegT
) exp
);
3398 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3400 demand_empty_rest_of_line ();
3405 obj_coff_text (ignore
)
3408 subseg_new (".text", get_absolute_expression ());
3413 obj_coff_data (ignore
)
3416 if (flag_readonly_data_in_text
)
3417 subseg_new (".text", get_absolute_expression () + 1000);
3419 subseg_new (".data", get_absolute_expression ());
3423 obj_coff_bss (ignore
)
3426 if (*input_line_pointer
== '\n') /* .bss */
3427 subseg_new(".bss", get_absolute_expression());
3428 else /* .bss id,expr */
3433 obj_coff_ident (ignore
)
3436 segT current_seg
= now_seg
; /* save current seg */
3437 subsegT current_subseg
= now_subseg
;
3438 subseg_new (".comment", 0); /* .comment seg */
3439 stringer (1); /* read string */
3440 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3444 c_symbol_merge (debug
, normal
)
3448 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3449 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3451 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3453 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3454 } /* take the most we have */
3456 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3458 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3459 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3460 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3461 } /* Move all the auxiliary information */
3463 /* Move the debug flags. */
3464 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3465 } /* c_symbol_merge() */
3468 c_line_new (symbol
, paddr
, line_number
, frag
)
3474 struct lineno_list
*new_line
=
3475 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3477 segment_info_type
*s
= segment_info
+ now_seg
;
3478 new_line
->line
.l_lnno
= line_number
;
3480 if (line_number
== 0)
3482 last_line_symbol
= symbol
;
3483 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3487 new_line
->line
.l_addr
.l_paddr
= paddr
;
3490 new_line
->frag
= (char *) frag
;
3491 new_line
->next
= (struct lineno_list
*) NULL
;
3494 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3496 s
->lineno_list_head
= new_line
;
3500 s
->lineno_list_tail
->next
= new_line
;
3502 s
->lineno_list_tail
= new_line
;
3503 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3507 c_dot_file_symbol (filename
)
3512 symbolP
= symbol_new (".file",
3515 &zero_address_frag
);
3517 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3518 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3520 if (strlen (filename
) > FILNMLEN
)
3522 /* Filename is too long to fit into an auxent,
3523 we stick it into the string table instead. We keep
3524 a linked list of the filenames we find so we can emit
3526 struct filename_list
*f
= ((struct filename_list
*)
3527 xmalloc (sizeof (struct filename_list
)));
3529 f
->filename
= filename
;
3532 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3533 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3535 if (filename_list_tail
)
3536 filename_list_tail
->next
= f
;
3538 filename_list_head
= f
;
3539 filename_list_tail
= f
;
3543 SA_SET_FILE_FNAME (symbolP
, filename
);
3550 listing_source_file (filename
);
3556 SF_SET_DEBUG (symbolP
);
3557 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3559 previous_file_symbol
= symbolP
;
3561 /* Make sure that the symbol is first on the symbol chain */
3562 if (symbol_rootP
!= symbolP
)
3564 if (symbolP
== symbol_lastP
)
3566 symbol_lastP
= symbol_lastP
->sy_previous
;
3567 } /* if it was the last thing on the list */
3569 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3570 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3571 symbol_rootP
= symbolP
;
3572 } /* if not first on the list */
3574 } /* c_dot_file_symbol() */
3577 * Build a 'section static' symbol.
3581 c_section_symbol (name
, idx
)
3587 symbolP
= symbol_new (name
, idx
,
3589 &zero_address_frag
);
3591 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3592 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3594 SF_SET_STATICS (symbolP
);
3597 /* If the .linkonce pseudo-op was used for this section, we must
3598 store the information in the auxiliary entry for the section
3600 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3604 switch (segment_info
[idx
].linkonce
)
3608 case LINKONCE_DISCARD
:
3609 type
= IMAGE_COMDAT_SELECT_ANY
;
3611 case LINKONCE_ONE_ONLY
:
3612 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3614 case LINKONCE_SAME_SIZE
:
3615 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3617 case LINKONCE_SAME_CONTENTS
:
3618 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3622 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3627 } /* c_section_symbol() */
3630 w_symbols (abfd
, where
, symbol_rootP
)
3633 symbolS
* symbol_rootP
;
3638 /* First fill in those values we have only just worked out */
3639 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3641 symbolP
= segment_info
[i
].dot
;
3644 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3645 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3646 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3651 * Emit all symbols left in the symbol chain.
3653 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3655 /* Used to save the offset of the name. It is used to point
3656 to the string in memory but must be a file offset. */
3657 register char *temp
;
3659 /* We can't fix the lnnoptr field in yank_symbols with the other
3660 adjustments, because we have to wait until we know where they
3662 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3664 SA_GET_SYM_LNNOPTR (symbolP
) +=
3665 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3668 tc_coff_symbol_emit_hook (symbolP
);
3670 temp
= S_GET_NAME (symbolP
);
3671 if (SF_GET_STRING (symbolP
))
3673 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3674 S_SET_ZEROES (symbolP
, 0);
3678 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3679 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3681 where
= symbol_to_chars (abfd
, where
, symbolP
);
3682 S_SET_NAME (symbolP
, temp
);
3688 obj_coff_lcomm (ignore
)
3701 name
= input_line_pointer
;
3703 c
= get_symbol_end ();
3704 p
= input_line_pointer
;
3707 if (*input_line_pointer
!= ',')
3709 as_bad ("Expected comma after name");
3710 ignore_rest_of_line ();
3713 if (*input_line_pointer
== '\n')
3715 as_bad ("Missing size expression");
3718 input_line_pointer
++;
3719 if ((temp
= get_absolute_expression ()) < 0)
3721 as_warn ("lcomm length (%d.) <0! Ignored.", temp
);
3722 ignore_rest_of_line ();
3727 symbolP
= symbol_find_or_make(name
);
3729 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3730 S_GET_VALUE(symbolP
) == 0)
3735 segT current_seg
= now_seg
; /* save current seg */
3736 subsegT current_subseg
= now_subseg
;
3738 subseg_set (SEG_E2
, 1);
3739 symbolP
->sy_frag
= frag_now
;
3740 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3743 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3744 S_SET_SEGMENT(symbolP
, SEG_E2
);
3745 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3749 as_bad("Symbol %s already defined", name
);
3751 demand_empty_rest_of_line();
3756 fixup_mdeps (frags
, h
, this_segment
)
3761 subseg_change (this_segment
, 0);
3764 switch (frags
->fr_type
)
3770 HANDLE_ALIGN (frags
);
3772 frags
->fr_type
= rs_fill
;
3774 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3777 case rs_machine_dependent
:
3778 md_convert_frag (h
, this_segment
, frags
);
3784 frags
= frags
->fr_next
;
3790 #ifndef TC_FORCE_RELOCATION
3791 #define TC_FORCE_RELOCATION(fix) 0
3795 fixup_segment (segP
, this_segment_type
)
3796 segment_info_type
* segP
;
3797 segT this_segment_type
;
3799 register fixS
* fixP
;
3800 register symbolS
*add_symbolP
;
3801 register symbolS
*sub_symbolP
;
3804 register char *place
;
3805 register long where
;
3806 register char pcrel
;
3807 register fragS
*fragP
;
3808 register segT add_symbol_segment
= absolute_section
;
3810 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3812 fragP
= fixP
->fx_frag
;
3814 where
= fixP
->fx_where
;
3815 place
= fragP
->fr_literal
+ where
;
3816 size
= fixP
->fx_size
;
3817 add_symbolP
= fixP
->fx_addsy
;
3818 sub_symbolP
= fixP
->fx_subsy
;
3819 add_number
= fixP
->fx_offset
;
3820 pcrel
= fixP
->fx_pcrel
;
3822 /* We want function-relative stabs to work on systems which
3823 may use a relaxing linker; thus we must handle the sym1-sym2
3824 fixups function-relative stabs generates.
3826 Of course, if you actually enable relaxing in the linker, the
3827 line and block scoping information is going to be incorrect
3828 in some cases. The only way to really fix this is to support
3829 a reloc involving the difference of two symbols. */
3831 && (!sub_symbolP
|| pcrel
))
3835 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3837 /* Relocation should be done via the associated 'bal' entry
3840 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3842 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3843 "No 'bal' entry point for leafproc %s",
3844 S_GET_NAME (add_symbolP
));
3847 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3851 if (add_symbolP
!= NULL
3852 && add_symbolP
->sy_mri_common
)
3854 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3855 add_number
+= S_GET_VALUE (add_symbolP
);
3856 fixP
->fx_offset
= add_number
;
3857 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3862 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3863 } /* if there is an addend */
3867 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3869 if (add_symbolP
!= NULL
)
3871 add_number
+= S_GET_VALUE (add_symbolP
);
3873 fixP
->fx_addsy
= NULL
;
3876 /* It's just -sym. */
3877 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3879 add_number
-= S_GET_VALUE (sub_symbolP
);
3886 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3887 "Negative of non-absolute symbol %s",
3888 S_GET_NAME (sub_symbolP
));
3890 add_number
-= S_GET_VALUE (sub_symbolP
);
3891 } /* not absolute */
3893 /* if sub_symbol is in the same segment that add_symbol
3894 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3896 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3897 && SEG_NORMAL (add_symbol_segment
))
3899 /* Difference of 2 symbols from same segment. Can't
3900 make difference of 2 undefineds: 'value' means
3901 something different for N_UNDF. */
3903 /* Makes no sense to use the difference of 2 arbitrary symbols
3904 as the target of a call instruction. */
3907 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3908 "callj to difference of 2 symbols");
3910 #endif /* TC_I960 */
3911 add_number
+= S_GET_VALUE (add_symbolP
) -
3912 S_GET_VALUE (sub_symbolP
);
3915 if (!TC_FORCE_RELOCATION (fixP
))
3917 fixP
->fx_addsy
= NULL
;
3918 fixP
->fx_subsy
= NULL
;
3920 #ifdef TC_M68K /* is this right? */
3928 /* Different segments in subtraction. */
3929 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
3931 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
3933 add_number
-= S_GET_VALUE (sub_symbolP
);
3936 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
3937 #if 0 /* Okay for 68k, at least... */
3942 /* Make it pc-relative. */
3943 add_number
+= (md_pcrel_from (fixP
)
3944 - S_GET_VALUE (sub_symbolP
));
3953 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3954 "Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld.",
3955 segment_name (S_GET_SEGMENT (sub_symbolP
)),
3956 S_GET_NAME (sub_symbolP
),
3957 (long) (fragP
->fr_address
+ where
));
3960 } /* if sub_symbolP */
3964 if (add_symbol_segment
== this_segment_type
&& pcrel
)
3967 * This fixup was made when the symbol's segment was
3968 * SEG_UNKNOWN, but it is now in the local segment.
3969 * So we know how to do the address without relocation.
3972 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
3973 * in which cases it modifies *fixP as appropriate. In the case
3974 * of a 'calls', no further work is required, and *fixP has been
3975 * set up to make the rest of the code below a no-op.
3978 #endif /* TC_I960 */
3980 add_number
+= S_GET_VALUE (add_symbolP
);
3981 add_number
-= md_pcrel_from (fixP
);
3982 #if defined (TC_I386) || defined (TE_LYNX)
3983 /* On the 386 we must adjust by the segment
3984 vaddr as well. Ian Taylor. */
3985 add_number
-= segP
->scnhdr
.s_vaddr
;
3987 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
3988 if (!TC_FORCE_RELOCATION (fixP
))
3990 fixP
->fx_addsy
= NULL
;
3996 switch (add_symbol_segment
)
3998 case absolute_section
:
4000 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4001 #endif /* TC_I960 */
4002 add_number
+= S_GET_VALUE (add_symbolP
);
4005 if (!TC_FORCE_RELOCATION (fixP
))
4007 fixP
->fx_addsy
= NULL
;
4014 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4015 /* This really should be handled in the linker, but
4016 backward compatibility forbids. */
4017 add_number
+= S_GET_VALUE (add_symbolP
);
4019 add_number
+= S_GET_VALUE (add_symbolP
) +
4020 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4026 if ((int) fixP
->fx_bit_fixP
== 13)
4028 /* This is a COBR instruction. They have only a
4029 * 13-bit displacement and are only to be used
4030 * for local branches: flag as error, don't generate
4033 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4034 "can't use COBR format with external label");
4035 fixP
->fx_addsy
= NULL
;
4039 #endif /* TC_I960 */
4040 #if (defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)
4041 /* 386 COFF uses a peculiar format in which the
4042 value of a common symbol is stored in the .text
4043 segment (I've checked this on SVR3.2 and SCO
4044 3.2.2) Ian Taylor <ian@cygnus.com>. */
4045 if (S_IS_COMMON (add_symbolP
))
4046 add_number
+= S_GET_VALUE (add_symbolP
);
4051 } /* switch on symbol seg */
4052 } /* if not in local seg */
4053 } /* if there was a + symbol */
4057 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4058 /* This adjustment is not correct on the m88k, for which the
4059 linker does all the computation. */
4060 add_number
-= md_pcrel_from (fixP
);
4062 if (add_symbolP
== 0)
4064 fixP
->fx_addsy
= &abs_symbol
;
4065 } /* if there's an add_symbol */
4066 #if defined (TC_I386) || defined (TE_LYNX)
4067 /* On the 386 we must adjust by the segment vaddr
4068 as well. Ian Taylor. */
4069 add_number
-= segP
->scnhdr
.s_vaddr
;
4073 if (!fixP
->fx_bit_fixP
)
4076 /* The m88k uses the offset field of the reloc to get around
4079 && (add_number
& ~0xFF)
4080 && ((add_number
& ~0xFF) != (-1 & ~0xFF)))
4082 && (add_number
& ~0xFFFF)
4083 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF))))
4085 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4086 "Value of %ld too large for field of %d bytes at 0x%lx",
4087 (long) add_number
, size
,
4088 (unsigned long) (fragP
->fr_address
+ where
));
4091 #ifdef WARN_SIGNED_OVERFLOW_WORD
4092 /* Warn if a .word value is too large when treated as a
4093 signed number. We already know it is not too negative.
4094 This is to catch over-large switches generated by gcc on
4096 if (!flag_signed_overflow_ok
4098 && add_number
> 0x7fff)
4099 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4100 "Signed .word overflow; switch may be too large; %ld at 0x%lx",
4102 (unsigned long) (fragP
->fr_address
+ where
));
4104 } /* not a bit fix */
4105 /* Once this fix has been applied, we don't have to output
4106 anything nothing more need be done. */
4107 #ifdef MD_APPLY_FIX3
4108 md_apply_fix3 (fixP
, &add_number
, this_segment_type
);
4110 md_apply_fix (fixP
, add_number
);
4112 } /* For each fixS in this segment. */
4113 } /* fixup_segment() */
4117 /* The first entry in a .stab section is special. */
4120 obj_coff_init_stab_section (seg
)
4126 unsigned int stroff
;
4128 /* Make space for this first symbol. */
4132 as_where (&file
, (unsigned int *) NULL
);
4133 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4134 strcpy (stabstr_name
, segment_info
[seg
].name
);
4135 strcat (stabstr_name
, "str");
4136 stroff
= get_stab_string_offset (file
, stabstr_name
);
4138 md_number_to_chars (p
, stroff
, 4);
4141 /* Fill in the counts in the first entry in a .stab section. */
4144 adjust_stab_section(abfd
, seg
)
4148 segT stabstrseg
= SEG_UNKNOWN
;
4149 const char *secname
, *name2
;
4152 int i
, strsz
= 0, nsyms
;
4153 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4155 /* Look for the associated string table section. */
4157 secname
= segment_info
[seg
].name
;
4158 name
= (char *) alloca (strlen (secname
) + 4);
4159 strcpy (name
, secname
);
4160 strcat (name
, "str");
4162 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4164 name2
= segment_info
[i
].name
;
4165 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4172 /* If we found the section, get its size. */
4173 if (stabstrseg
!= SEG_UNKNOWN
)
4174 strsz
= size_section (abfd
, stabstrseg
);
4176 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4178 /* Look for the first frag of sufficient size for the initial stab
4179 symbol, and collect a pointer to it. */
4180 while (frag
&& frag
->fr_fix
< 12)
4181 frag
= frag
->fr_next
;
4183 p
= frag
->fr_literal
;
4186 /* Write in the number of stab symbols and the size of the string
4188 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4189 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4192 #endif /* not BFD_ASSEMBLER */
4194 const pseudo_typeS obj_pseudo_table
[] =
4196 {"def", obj_coff_def
, 0},
4197 {"dim", obj_coff_dim
, 0},
4198 {"endef", obj_coff_endef
, 0},
4199 {"line", obj_coff_line
, 0},
4200 {"ln", obj_coff_ln
, 0},
4201 {"appline", obj_coff_ln
, 1},
4202 {"scl", obj_coff_scl
, 0},
4203 {"size", obj_coff_size
, 0},
4204 {"tag", obj_coff_tag
, 0},
4205 {"type", obj_coff_type
, 0},
4206 {"val", obj_coff_val
, 0},
4207 {"section", obj_coff_section
, 0},
4208 {"sect", obj_coff_section
, 0},
4209 /* FIXME: We ignore the MRI short attribute. */
4210 {"section.s", obj_coff_section
, 0},
4211 {"sect.s", obj_coff_section
, 0},
4212 #ifndef BFD_ASSEMBLER
4213 {"use", obj_coff_section
, 0},
4214 {"text", obj_coff_text
, 0},
4215 {"data", obj_coff_data
, 0},
4216 {"bss", obj_coff_bss
, 0},
4217 {"lcomm", obj_coff_lcomm
, 0},
4218 {"ident", obj_coff_ident
, 0},
4220 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4221 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4223 {"ABORT", s_abort
, 0},
4225 /* The m88k uses sdef instead of def. */
4226 {"sdef", obj_coff_def
, 0},
4228 {NULL
} /* end sentinel */
4229 }; /* obj_pseudo_table */