1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 static void obj_coff_bss
PARAMS ((int));
34 const char *s_get_name
PARAMS ((symbolS
* s
));
35 static void obj_coff_ln
PARAMS ((int));
36 static void obj_coff_def
PARAMS ((int));
37 static void obj_coff_endef
PARAMS ((int));
38 static void obj_coff_dim
PARAMS ((int));
39 static void obj_coff_line
PARAMS ((int));
40 static void obj_coff_size
PARAMS ((int));
41 static void obj_coff_scl
PARAMS ((int));
42 static void obj_coff_tag
PARAMS ((int));
43 static void obj_coff_val
PARAMS ((int));
44 static void obj_coff_type
PARAMS ((int));
46 static void obj_coff_loc
PARAMS((int));
49 /* This is used to hold the symbol built by a sequence of pseudo-ops
50 from .def and .endef. */
51 static symbolS
*def_symbol_in_progress
;
56 unsigned long chunk_size
;
57 unsigned long element_size
;
60 unsigned long pointer
;
65 stack_init (chunk_size
, element_size
)
66 unsigned long chunk_size
;
67 unsigned long element_size
;
71 st
= (stack
*) malloc (sizeof (stack
));
74 st
->data
= malloc (chunk_size
);
81 st
->size
= chunk_size
;
82 st
->chunk_size
= chunk_size
;
83 st
->element_size
= element_size
;
88 /* Not currently used. */
99 stack_push (st
, element
)
103 if (st
->pointer
+ st
->element_size
>= st
->size
)
105 st
->size
+= st
->chunk_size
;
106 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
109 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
110 st
->pointer
+= st
->element_size
;
111 return st
->data
+ st
->pointer
;
118 if (st
->pointer
< st
->element_size
)
123 st
->pointer
-= st
->element_size
;
124 return st
->data
+ st
->pointer
;
128 * Maintain a list of the tagnames of the structres.
131 static struct hash_control
*tag_hash
;
136 tag_hash
= hash_new ();
140 tag_insert (name
, symbolP
)
144 const char *error_string
;
146 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
148 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
157 #ifdef STRIP_UNDERSCORE
160 #endif /* STRIP_UNDERSCORE */
161 return (symbolS
*) hash_find (tag_hash
, name
);
165 tag_find_or_make (name
)
170 if ((symbolP
= tag_find (name
)) == NULL
)
172 symbolP
= symbol_new (name
, undefined_section
,
173 0, &zero_address_frag
);
175 tag_insert (S_GET_NAME (symbolP
), symbolP
);
177 symbol_table_insert (symbolP
);
184 /* We accept the .bss directive to set the section for backward
185 compatibility with earlier versions of gas. */
188 obj_coff_bss (ignore
)
189 int ignore ATTRIBUTE_UNUSED
;
191 if (*input_line_pointer
== '\n')
192 subseg_new (".bss", get_absolute_expression ());
197 /* Handle .weak. This is a GNU extension. */
200 obj_coff_weak (ignore
)
201 int ignore ATTRIBUTE_UNUSED
;
209 name
= input_line_pointer
;
210 c
= get_symbol_end ();
211 symbolP
= symbol_find_or_make (name
);
212 *input_line_pointer
= c
;
216 S_SET_WEAK (symbolP
);
220 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
222 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
227 input_line_pointer
++;
229 if (*input_line_pointer
== '\n')
235 demand_empty_rest_of_line ();
240 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
242 #define GET_FILENAME_STRING(X) \
243 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
247 fetch_coff_debug_section ()
249 static segT debug_section
;
253 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
255 debug_section
= s
->section
;
257 return debug_section
;
261 SA_SET_SYM_ENDNDX (sym
, val
)
265 combined_entry_type
*entry
, *p
;
267 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
268 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
269 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
274 SA_SET_SYM_TAGNDX (sym
, val
)
278 combined_entry_type
*entry
, *p
;
280 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
281 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
282 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
287 S_GET_DATA_TYPE (sym
)
290 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
294 S_SET_DATA_TYPE (sym
, val
)
298 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
303 S_GET_STORAGE_CLASS (sym
)
306 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
310 S_SET_STORAGE_CLASS (sym
, val
)
314 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
318 /* Merge a debug symbol containing debug information into a normal symbol. */
321 c_symbol_merge (debug
, normal
)
325 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
326 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
328 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
330 /* take the most we have */
331 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
334 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
336 /* Move all the auxiliary information. */
337 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
338 (S_GET_NUMBER_AUXILIARY (debug
)
339 * sizeof (*SYM_AUXINFO (debug
))));
342 /* Move the debug flags. */
343 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
347 c_dot_file_symbol (filename
)
352 /* BFD converts filename to a .file symbol with an aux entry. It
353 also handles chaining. */
354 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
356 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
357 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
359 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
366 listing_source_file (filename
);
371 /* Make sure that the symbol is first on the symbol chain */
372 if (symbol_rootP
!= symbolP
)
374 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
375 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
376 } /* if not first on the list */
379 /* Line number handling */
382 struct line_no
*next
;
389 /* Symbol of last function, which we should hang line#s off of. */
390 static symbolS
*line_fsym
;
392 #define in_function() (line_fsym != 0)
393 #define clear_function() (line_fsym = 0)
394 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
398 coff_obj_symbol_new_hook (symbolP
)
401 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
402 char * s
= (char *) xmalloc (sz
);
405 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
407 S_SET_DATA_TYPE (symbolP
, T_NULL
);
408 S_SET_STORAGE_CLASS (symbolP
, 0);
409 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
411 if (S_IS_STRING (symbolP
))
412 SF_SET_STRING (symbolP
);
414 if (S_IS_LOCAL (symbolP
))
415 SF_SET_LOCAL (symbolP
);
420 * Handle .ln directives.
423 static symbolS
*current_lineno_sym
;
424 static struct line_no
*line_nos
;
425 /* @@ Blindly assume all .ln directives will be in the .text section... */
429 add_lineno (frag
, offset
, num
)
434 struct line_no
*new_line
=
435 (struct line_no
*) xmalloc (sizeof (struct line_no
));
436 if (!current_lineno_sym
)
442 /* Zero is used as an end marker in the file. */
443 as_bad (_("Line numbers must be positive integers\n"));
446 new_line
->next
= line_nos
;
447 new_line
->frag
= frag
;
448 new_line
->l
.line_number
= num
;
449 new_line
->l
.u
.offset
= offset
;
455 coff_add_linesym (sym
)
460 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
465 current_lineno_sym
= sym
;
469 obj_coff_ln (appline
)
474 if (! appline
&& def_symbol_in_progress
!= NULL
)
476 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
477 demand_empty_rest_of_line ();
481 l
= get_absolute_expression ();
484 add_lineno (frag_now
, frag_now_fix (), l
);
488 new_logical_line ((char *) NULL
, l
- 1);
497 l
+= coff_line_base
- 1;
498 listing_source_line (l
);
503 demand_empty_rest_of_line ();
506 /* .loc is essentially the same as .ln; parse it for assembler
510 obj_coff_loc (ignore
)
511 int ignore ATTRIBUTE_UNUSED
;
515 /* FIXME: Why do we need this check? We need it for ECOFF, but why
516 do we need it for COFF? */
517 if (now_seg
!= text_section
)
519 as_warn (_(".loc outside of .text"));
520 demand_empty_rest_of_line ();
524 if (def_symbol_in_progress
!= NULL
)
526 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
527 demand_empty_rest_of_line ();
531 /* Skip the file number. */
533 get_absolute_expression ();
536 lineno
= get_absolute_expression ();
544 lineno
+= coff_line_base
- 1;
545 listing_source_line (lineno
);
550 demand_empty_rest_of_line ();
552 add_lineno (frag_now
, frag_now_fix (), lineno
);
558 * Handle .def directives.
560 * One might ask : why can't we symbol_new if the symbol does not
561 * already exist and fill it with debug information. Because of
562 * the C_EFCN special symbol. It would clobber the value of the
563 * function symbol before we have a chance to notice that it is
564 * a C_EFCN. And a second reason is that the code is more clear this
565 * way. (at least I think it is :-).
569 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
570 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
571 *input_line_pointer == '\t') \
572 input_line_pointer++;
576 int what ATTRIBUTE_UNUSED
;
578 char name_end
; /* Char after the end of name */
579 char *symbol_name
; /* Name of the debug symbol */
580 char *symbol_name_copy
; /* Temporary copy of the name */
581 unsigned int symbol_name_length
;
583 if (def_symbol_in_progress
!= NULL
)
585 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
586 demand_empty_rest_of_line ();
588 } /* if not inside .def/.endef */
592 symbol_name
= input_line_pointer
;
593 #ifdef STRIP_UNDERSCORE
594 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
596 #endif /* STRIP_UNDERSCORE */
598 name_end
= get_symbol_end ();
599 symbol_name_length
= strlen (symbol_name
);
600 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
601 strcpy (symbol_name_copy
, symbol_name
);
602 #ifdef tc_canonicalize_symbol_name
603 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
606 /* Initialize the new symbol */
607 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
608 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
609 S_SET_VALUE (def_symbol_in_progress
, 0);
611 if (S_IS_STRING (def_symbol_in_progress
))
612 SF_SET_STRING (def_symbol_in_progress
);
614 *input_line_pointer
= name_end
;
616 demand_empty_rest_of_line ();
619 unsigned int dim_index
;
622 obj_coff_endef (ignore
)
623 int ignore ATTRIBUTE_UNUSED
;
627 /* DIM BUG FIX sac@cygnus.com */
629 if (def_symbol_in_progress
== NULL
)
631 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
632 demand_empty_rest_of_line ();
634 } /* if not inside .def/.endef */
636 /* Set the section number according to storage class. */
637 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
642 SF_SET_TAG (def_symbol_in_progress
);
643 /* intentional fallthrough */
646 SF_SET_DEBUG (def_symbol_in_progress
);
647 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
651 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
652 /* intentional fallthrough */
654 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
655 /* intentional fallthrough */
659 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
661 name
= S_GET_NAME (def_symbol_in_progress
);
662 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
668 if (! in_function ())
669 as_warn (_("`%s' symbol without preceding function"), name
);
670 /* Will need relocating. */
671 SF_SET_PROCESS (def_symbol_in_progress
);
677 /* The MS compilers output the actual endline, not the
678 function-relative one... we want to match without
679 changing the assembler input. */
680 SA_SET_SYM_LNNO (def_symbol_in_progress
,
681 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
692 #endif /* C_AUTOARG */
698 SF_SET_DEBUG (def_symbol_in_progress
);
699 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
706 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
716 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
723 as_warn (_("unexpected storage class %d"),
724 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
726 } /* switch on storage class */
728 /* Now that we have built a debug symbol, try to find if we should
729 merge with an existing symbol or not. If a symbol is C_EFCN or
730 absolute_section or untagged SEG_DEBUG it never merges. We also
731 don't merge labels, which are in a different namespace, nor
732 symbols which have not yet been defined since they are typically
733 unique, nor do we merge tags with non-tags. */
735 /* Two cases for functions. Either debug followed by definition or
736 definition followed by debug. For definition first, we will
737 merge the debug symbol into the definition. For debug first, the
738 lineno entry MUST point to the definition function or else it
739 will point off into space when obj_crawl_symbol_chain() merges
740 the debug symbol into the real symbol. Therefor, let's presume
741 the debug symbol is a real function reference. */
743 /* FIXME-SOON If for some reason the definition label/symbol is
744 never seen, this will probably leave an undefined symbol at link
747 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
748 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
749 || (!strcmp (bfd_get_section_name (stdoutput
,
750 S_GET_SEGMENT (def_symbol_in_progress
)),
752 && !SF_GET_TAG (def_symbol_in_progress
))
753 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
754 || ! symbol_constant_p (def_symbol_in_progress
)
755 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
756 DO_NOT_STRIP
)) == NULL
757 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
759 /* If it already is at the end of the symbol list, do nothing */
760 if (def_symbol_in_progress
!= symbol_lastP
)
762 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
763 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
769 /* This symbol already exists, merge the newly created symbol
770 into the old one. This is not mandatory. The linker can
771 handle duplicate symbols correctly. But I guess that it save
772 a *lot* of space if the assembly file defines a lot of
775 /* The debug entry (def_symbol_in_progress) is merged into the
776 previous definition. */
778 c_symbol_merge (def_symbol_in_progress
, symbolP
);
779 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
781 def_symbol_in_progress
= symbolP
;
783 if (SF_GET_FUNCTION (def_symbol_in_progress
)
784 || SF_GET_TAG (def_symbol_in_progress
)
785 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
787 /* For functions, and tags, and static symbols, the symbol
788 *must* be where the debug symbol appears. Move the
789 existing symbol to the current place. */
790 /* If it already is at the end of the symbol list, do nothing */
791 if (def_symbol_in_progress
!= symbol_lastP
)
793 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
794 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
799 if (SF_GET_TAG (def_symbol_in_progress
))
803 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
805 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
806 tag_insert (S_GET_NAME (def_symbol_in_progress
),
807 def_symbol_in_progress
);
810 if (SF_GET_FUNCTION (def_symbol_in_progress
))
812 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
813 set_function (def_symbol_in_progress
);
814 SF_SET_PROCESS (def_symbol_in_progress
);
818 /* That is, if this is the first time we've seen the
820 symbol_table_insert (def_symbol_in_progress
);
821 } /* definition follows debug */
822 } /* Create the line number entry pointing to the function being defined */
824 def_symbol_in_progress
= NULL
;
825 demand_empty_rest_of_line ();
829 obj_coff_dim (ignore
)
830 int ignore ATTRIBUTE_UNUSED
;
834 if (def_symbol_in_progress
== NULL
)
836 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
837 demand_empty_rest_of_line ();
839 } /* if not inside .def/.endef */
841 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
843 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
846 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
847 get_absolute_expression ());
849 switch (*input_line_pointer
)
852 input_line_pointer
++;
856 as_warn (_("badly formed .dim directive ignored"));
857 /* intentional fallthrough */
865 demand_empty_rest_of_line ();
869 obj_coff_line (ignore
)
870 int ignore ATTRIBUTE_UNUSED
;
874 if (def_symbol_in_progress
== NULL
)
876 /* Probably stabs-style line? */
881 this_base
= get_absolute_expression ();
882 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
883 coff_line_base
= this_base
;
885 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
886 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
888 demand_empty_rest_of_line ();
891 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
896 listing_source_line ((unsigned int) this_base
);
902 obj_coff_size (ignore
)
903 int ignore ATTRIBUTE_UNUSED
;
905 if (def_symbol_in_progress
== NULL
)
907 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
908 demand_empty_rest_of_line ();
910 } /* if not inside .def/.endef */
912 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
913 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
914 demand_empty_rest_of_line ();
918 obj_coff_scl (ignore
)
919 int ignore ATTRIBUTE_UNUSED
;
921 if (def_symbol_in_progress
== NULL
)
923 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
924 demand_empty_rest_of_line ();
926 } /* if not inside .def/.endef */
928 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
929 demand_empty_rest_of_line ();
933 obj_coff_tag (ignore
)
934 int ignore ATTRIBUTE_UNUSED
;
939 if (def_symbol_in_progress
== NULL
)
941 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
942 demand_empty_rest_of_line ();
946 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
947 symbol_name
= input_line_pointer
;
948 name_end
= get_symbol_end ();
950 #ifdef tc_canonicalize_symbol_name
951 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
954 /* Assume that the symbol referred to by .tag is always defined.
955 This was a bad assumption. I've added find_or_make. xoxorich. */
956 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
957 tag_find_or_make (symbol_name
));
958 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
960 as_warn (_("tag not found for .tag %s"), symbol_name
);
963 SF_SET_TAGGED (def_symbol_in_progress
);
964 *input_line_pointer
= name_end
;
966 demand_empty_rest_of_line ();
970 obj_coff_type (ignore
)
971 int ignore ATTRIBUTE_UNUSED
;
973 if (def_symbol_in_progress
== NULL
)
975 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
976 demand_empty_rest_of_line ();
978 } /* if not inside .def/.endef */
980 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
982 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
983 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
985 SF_SET_FUNCTION (def_symbol_in_progress
);
986 } /* is a function */
988 demand_empty_rest_of_line ();
992 obj_coff_val (ignore
)
993 int ignore ATTRIBUTE_UNUSED
;
995 if (def_symbol_in_progress
== NULL
)
997 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
998 demand_empty_rest_of_line ();
1000 } /* if not inside .def/.endef */
1002 if (is_name_beginner (*input_line_pointer
))
1004 char *symbol_name
= input_line_pointer
;
1005 char name_end
= get_symbol_end ();
1007 #ifdef tc_canonicalize_symbol_name
1008 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1010 if (!strcmp (symbol_name
, "."))
1012 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1013 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1014 /* If the .val is != from the .def (e.g. statics) */
1016 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1020 exp
.X_op
= O_symbol
;
1021 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1022 exp
.X_op_symbol
= NULL
;
1023 exp
.X_add_number
= 0;
1024 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1026 /* If the segment is undefined when the forward reference is
1027 resolved, then copy the segment id from the forward
1029 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1031 /* FIXME: gcc can generate address expressions here in
1032 unusual cases (search for "obscure" in sdbout.c). We
1033 just ignore the offset here, thus generating incorrect
1034 debugging information. We ignore the rest of the line
1037 /* Otherwise, it is the name of a non debug symbol and its value
1038 will be calculated later. */
1039 *input_line_pointer
= name_end
;
1043 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1044 } /* if symbol based */
1046 demand_empty_rest_of_line ();
1050 coff_obj_read_begin_hook ()
1052 /* These had better be the same. Usually 18 bytes. */
1054 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1055 know (SYMESZ
== AUXESZ
);
1061 symbolS
*coff_last_function
;
1062 static symbolS
*coff_last_bf
;
1065 coff_frob_symbol (symp
, punt
)
1069 static symbolS
*last_tagP
;
1070 static stack
*block_stack
;
1071 static symbolS
*set_end
;
1072 symbolS
*next_set_end
= NULL
;
1074 if (symp
== &abs_symbol
)
1080 if (current_lineno_sym
)
1081 coff_add_linesym ((symbolS
*) 0);
1084 block_stack
= stack_init (512, sizeof (symbolS
*));
1086 if (S_IS_WEAK (symp
))
1089 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1091 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1095 if (!S_IS_DEFINED (symp
)
1096 && !S_IS_WEAK (symp
)
1097 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1098 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1100 if (!SF_GET_DEBUG (symp
))
1103 if (!SF_GET_LOCAL (symp
)
1104 && !SF_GET_STATICS (symp
)
1105 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1108 c_symbol_merge (symp
, real
);
1111 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1113 assert (S_GET_VALUE (symp
) == 0);
1114 S_SET_EXTERNAL (symp
);
1116 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1118 if (S_GET_SEGMENT (symp
) == text_section
1119 && symp
!= seg_info (text_section
)->sym
)
1120 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1122 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1124 if (SF_GET_PROCESS (symp
))
1126 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1128 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1129 stack_push (block_stack
, (char *) &symp
);
1133 begin
= *(symbolS
**) stack_pop (block_stack
);
1135 as_warn (_("mismatched .eb"));
1137 next_set_end
= begin
;
1140 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1142 union internal_auxent
*auxp
;
1143 coff_last_function
= symp
;
1144 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1145 S_SET_NUMBER_AUXILIARY (symp
, 1);
1146 auxp
= SYM_AUXENT (symp
);
1147 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1148 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1150 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1152 if (coff_last_function
== 0)
1153 as_fatal (_("C_EFCN symbol out of scope"));
1154 SA_SET_SYM_FSIZE (coff_last_function
,
1155 (long) (S_GET_VALUE (symp
)
1156 - S_GET_VALUE (coff_last_function
)));
1157 next_set_end
= coff_last_function
;
1158 coff_last_function
= 0;
1161 if (S_IS_EXTERNAL (symp
))
1162 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1163 else if (SF_GET_LOCAL (symp
))
1166 if (SF_GET_FUNCTION (symp
))
1167 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1172 /* Double check weak symbols. */
1173 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1174 as_bad (_("Symbol `%s' can not be both weak and common"),
1177 if (SF_GET_TAG (symp
))
1179 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1180 next_set_end
= last_tagP
;
1183 /* This is pretty horrible, but we have to set *punt correctly in
1184 order to call SA_SET_SYM_ENDNDX correctly. */
1185 if (! symbol_used_in_reloc_p (symp
)
1186 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1187 || (! S_IS_EXTERNAL (symp
)
1188 && ! symbol_get_tc (symp
)->output
1189 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1193 if (set_end
!= (symbolS
*) NULL
1195 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1196 || (S_IS_DEFINED (symp
)
1197 && ! S_IS_COMMON (symp
)
1198 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1200 SA_SET_SYM_ENDNDX (set_end
, symp
);
1204 if (next_set_end
!= NULL
)
1206 if (set_end
!= NULL
)
1207 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1208 S_GET_NAME (set_end
));
1209 set_end
= next_set_end
;
1213 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1214 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1216 if (coff_last_bf
!= NULL
)
1217 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1218 coff_last_bf
= symp
;
1221 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1224 struct line_no
*lptr
;
1227 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1228 for (i
= 0; lptr
; lptr
= lptr
->next
)
1230 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1232 /* We need i entries for line numbers, plus 1 for the first
1233 entry which BFD will override, plus 1 for the last zero
1234 entry (a marker for BFD). */
1235 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1236 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1237 l
[i
+ 1].line_number
= 0;
1238 l
[i
+ 1].u
.sym
= NULL
;
1242 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1250 coff_adjust_section_syms (abfd
, sec
, x
)
1251 bfd
*abfd ATTRIBUTE_UNUSED
;
1253 PTR x ATTRIBUTE_UNUSED
;
1256 segment_info_type
*seginfo
= seg_info (sec
);
1257 int nlnno
, nrelocs
= 0;
1259 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1260 tc-ppc.c. Do not get confused by it. */
1261 if (seginfo
== NULL
)
1264 if (!strcmp (sec
->name
, ".text"))
1265 nlnno
= coff_n_line_nos
;
1269 /* @@ Hope that none of the fixups expand to more than one reloc
1271 fixS
*fixp
= seginfo
->fix_root
;
1274 if (! fixp
->fx_done
)
1276 fixp
= fixp
->fx_next
;
1279 if (bfd_get_section_size_before_reloc (sec
) == 0
1282 && sec
!= text_section
1283 && sec
!= data_section
1284 && sec
!= bss_section
)
1286 secsym
= section_symbol (sec
);
1287 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1288 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1292 coff_frob_file_after_relocs ()
1294 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1298 * implement the .section pseudo op:
1299 * .section name {, "flags"}
1301 * | +--- optional flags: 'b' for bss
1303 * +-- section name 'l' for lib
1307 * 'd' (apparently m88k for data)
1309 * 'r' for read-only data
1310 * 's' for shared data (PE)
1311 * But if the argument is not a quoted string, treat it as a
1312 * subsegment number.
1316 obj_coff_section (ignore
)
1317 int ignore ATTRIBUTE_UNUSED
;
1319 /* Strip out the section name */
1335 section_name
= input_line_pointer
;
1336 c
= get_symbol_end ();
1338 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1339 strcpy (name
, section_name
);
1341 *input_line_pointer
= c
;
1348 if (*input_line_pointer
== ',')
1350 ++input_line_pointer
;
1352 if (*input_line_pointer
!= '"')
1353 exp
= get_absolute_expression ();
1356 ++input_line_pointer
;
1357 while (*input_line_pointer
!= '"'
1358 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1360 switch (*input_line_pointer
)
1362 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1363 case 'n': flags
&=~ SEC_LOAD
; break;
1364 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1365 case 'w': flags
&=~ SEC_READONLY
; break;
1366 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1367 case 'r': flags
|= SEC_READONLY
; break;
1368 case 's': flags
|= SEC_SHARED
; break;
1370 case 'i': /* STYP_INFO */
1371 case 'l': /* STYP_LIB */
1372 case 'o': /* STYP_OVER */
1373 as_warn (_("unsupported section attribute '%c'"),
1374 *input_line_pointer
);
1378 as_warn(_("unknown section attribute '%c'"),
1379 *input_line_pointer
);
1382 ++input_line_pointer
;
1384 if (*input_line_pointer
== '"')
1385 ++input_line_pointer
;
1389 sec
= subseg_new (name
, (subsegT
) exp
);
1391 if (flags
!= SEC_NO_FLAGS
)
1395 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1396 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1399 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1400 as_warn (_("error setting flags for \"%s\": %s"),
1401 bfd_section_name (stdoutput
, sec
),
1402 bfd_errmsg (bfd_get_error ()));
1405 demand_empty_rest_of_line ();
1409 coff_adjust_symtab ()
1411 if (symbol_rootP
== NULL
1412 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1413 c_dot_file_symbol ("fake");
1417 coff_frob_section (sec
)
1423 bfd_vma size
, n_entries
, mask
;
1425 /* The COFF back end in BFD requires that all section sizes be
1426 rounded up to multiples of the corresponding section alignments.
1427 Seems kinda silly to me, but that's the way it is. */
1428 size
= bfd_get_section_size_before_reloc (sec
);
1429 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1432 size
= (size
+ mask
) & ~mask
;
1433 bfd_set_section_size (stdoutput
, sec
, size
);
1436 /* If the section size is non-zero, the section symbol needs an aux
1437 entry associated with it, indicating the size. We don't know
1438 all the values yet; coff_frob_symbol will fill them in later. */
1440 || sec
== text_section
1441 || sec
== data_section
1442 || sec
== bss_section
)
1444 symbolS
*secsym
= section_symbol (sec
);
1446 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1447 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1448 SF_SET_STATICS (secsym
);
1449 SA_SET_SCN_SCNLEN (secsym
, size
);
1452 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1453 #ifndef STAB_SECTION_NAME
1454 #define STAB_SECTION_NAME ".stab"
1456 #ifndef STAB_STRING_SECTION_NAME
1457 #define STAB_STRING_SECTION_NAME ".stabstr"
1459 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1463 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1464 /* size is already rounded up, since other section will be listed first */
1465 size
= bfd_get_section_size_before_reloc (strsec
);
1467 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1469 /* Find first non-empty frag. It should be large enough. */
1470 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1471 while (fragp
&& fragp
->fr_fix
== 0)
1472 fragp
= fragp
->fr_next
;
1473 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1475 /* Store the values. */
1476 p
= fragp
->fr_literal
;
1477 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1478 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1482 obj_coff_init_stab_section (seg
)
1488 unsigned int stroff
;
1490 /* Make space for this first symbol. */
1494 as_where (&file
, (unsigned int *) NULL
);
1495 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1496 strcpy (stabstr_name
, seg
->name
);
1497 strcat (stabstr_name
, "str");
1498 stroff
= get_stab_string_offset (file
, stabstr_name
);
1500 md_number_to_chars (p
, stroff
, 4);
1509 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1517 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1519 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1520 (unsigned long) symbolP
,
1521 S_GET_NAME(symbolP
),
1522 (long) S_GET_DATA_TYPE(symbolP
),
1523 S_GET_STORAGE_CLASS(symbolP
),
1524 (int) S_GET_SEGMENT(symbolP
));
1530 #else /* not BFD_ASSEMBLER */
1533 /* This is needed because we include internal bfd things. */
1537 #include "libcoff.h"
1540 #include "coff/pe.h"
1543 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1544 that we can stick sections together without causing trouble. */
1546 #define NOP_OPCODE 0x00
1549 /* The zeroes if symbol name is longer than 8 chars */
1550 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1552 #define MIN(a,b) ((a) < (b)? (a) : (b))
1554 /* This vector is used to turn a gas internal segment number into a
1555 section number suitable for insertion into a coff symbol table.
1556 This must correspond to seg_info_off_by_4. */
1558 const short seg_N_TYPE
[] =
1559 { /* in: segT out: N_TYPE bits */
1561 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1562 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1563 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1564 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1565 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1566 C_UNDEF_SECTION
, /* SEG_GOOF */
1567 C_UNDEF_SECTION
, /* SEG_EXPR */
1568 C_DEBUG_SECTION
, /* SEG_DEBUG */
1569 C_NTV_SECTION
, /* SEG_NTV */
1570 C_PTV_SECTION
, /* SEG_PTV */
1571 C_REGISTER_SECTION
, /* SEG_REGISTER */
1574 int function_lineoff
= -1; /* Offset in line#s where the last function
1575 started (the odd entry for line #0) */
1577 /* structure used to keep the filenames which
1578 are too long around so that we can stick them
1579 into the string table */
1580 struct filename_list
1583 struct filename_list
*next
;
1586 static struct filename_list
*filename_list_head
;
1587 static struct filename_list
*filename_list_tail
;
1589 static symbolS
*last_line_symbol
;
1591 /* Add 4 to the real value to get the index and compensate the
1592 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1593 section number into a segment number
1595 static symbolS
*previous_file_symbol
;
1596 void c_symbol_merge ();
1597 static int line_base
;
1599 symbolS
*c_section_symbol ();
1602 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1603 segT this_segment_type
));
1606 static void fixup_mdeps
PARAMS ((fragS
*,
1611 static void fill_section
PARAMS ((bfd
* abfd
,
1616 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1621 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1622 symbolS
* symbol_rootP
));
1624 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1626 static void obj_coff_lcomm
PARAMS ((int));
1627 static void obj_coff_text
PARAMS ((int));
1628 static void obj_coff_data
PARAMS ((int));
1629 static void obj_coff_ident
PARAMS ((int));
1630 void obj_coff_section
PARAMS ((int));
1632 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1634 This array maps a COFF section number into a gas section number.
1635 Because COFF uses negative section numbers, you must add 4 to the
1636 COFF section number when indexing into this array; this is done via
1637 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1640 static const segT seg_info_off_by_4
[] =
1647 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1648 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1649 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1650 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1651 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1652 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1653 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1654 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1667 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1669 static relax_addressT
1670 relax_align (address
, alignment
)
1671 relax_addressT address
;
1674 relax_addressT mask
;
1675 relax_addressT new_address
;
1677 mask
= ~((~0) << alignment
);
1678 new_address
= (address
+ mask
) & (~mask
);
1679 return (new_address
- address
);
1687 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1690 /* calculate the size of the frag chain and fill in the section header
1691 to contain all of it, also fill in the addr of the sections */
1693 size_section (abfd
, idx
)
1694 bfd
*abfd ATTRIBUTE_UNUSED
;
1698 unsigned int size
= 0;
1699 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1702 size
= frag
->fr_address
;
1703 if (frag
->fr_address
!= size
)
1705 fprintf (stderr
, _("Out of step\n"));
1706 size
= frag
->fr_address
;
1709 switch (frag
->fr_type
)
1711 #ifdef TC_COFF_SIZEMACHDEP
1712 case rs_machine_dependent
:
1713 size
+= TC_COFF_SIZEMACHDEP (frag
);
1717 assert (frag
->fr_symbol
== 0);
1720 size
+= frag
->fr_fix
;
1721 size
+= frag
->fr_offset
* frag
->fr_var
;
1728 size
+= frag
->fr_fix
;
1729 off
= relax_align (size
, frag
->fr_offset
);
1730 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1736 BAD_CASE (frag
->fr_type
);
1739 frag
= frag
->fr_next
;
1741 segment_info
[idx
].scnhdr
.s_size
= size
;
1747 count_entries_in_chain (idx
)
1750 unsigned int nrelocs
;
1753 /* Count the relocations */
1754 fixup_ptr
= segment_info
[idx
].fix_root
;
1756 while (fixup_ptr
!= (fixS
*) NULL
)
1758 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1761 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1770 fixup_ptr
= fixup_ptr
->fx_next
;
1777 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1779 /* AUX's ld expects relocations to be sorted */
1781 compare_external_relocs (x
, y
)
1785 struct external_reloc
*a
= (struct external_reloc
*) x
;
1786 struct external_reloc
*b
= (struct external_reloc
*) y
;
1787 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1788 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1789 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1794 /* output all the relocations for a section */
1796 do_relocs_for (abfd
, h
, file_cursor
)
1799 unsigned long *file_cursor
;
1801 unsigned int nrelocs
;
1803 unsigned long reloc_start
= *file_cursor
;
1805 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1807 if (segment_info
[idx
].scnhdr
.s_name
[0])
1809 struct external_reloc
*ext_ptr
;
1810 struct external_reloc
*external_reloc_vec
;
1811 unsigned int external_reloc_size
;
1812 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1813 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1814 nrelocs
= count_entries_in_chain (idx
);
1817 /* Bypass this stuff if no relocs. This also incidentally
1818 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1820 external_reloc_size
= nrelocs
* RELSZ
;
1821 external_reloc_vec
=
1822 (struct external_reloc
*) malloc (external_reloc_size
);
1824 ext_ptr
= external_reloc_vec
;
1826 /* Fill in the internal coff style reloc struct from the
1827 internal fix list. */
1830 struct internal_reloc intr
;
1832 /* Only output some of the relocations */
1833 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1835 #ifdef TC_RELOC_MANGLE
1836 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1841 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1843 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1845 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1847 #ifdef TC_KEEP_FX_OFFSET
1848 intr
.r_offset
= fix_ptr
->fx_offset
;
1853 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1854 && (! S_IS_DEFINED (symbol_ptr
)
1855 || S_IS_COMMON (symbol_ptr
)))
1859 /* We must avoid looping, as that can occur
1860 with a badly written program. */
1861 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1862 if (n
== symbol_ptr
)
1867 /* Turn the segment of the symbol into an offset. */
1870 resolve_symbol_value (symbol_ptr
, 1);
1871 if (! symbol_ptr
->sy_resolved
)
1876 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1877 as_bad_where (file
, line
,
1878 _("unresolved relocation"));
1880 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1881 S_GET_NAME (symbol_ptr
));
1883 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1886 intr
.r_symndx
= dot
->sy_number
;
1890 intr
.r_symndx
= symbol_ptr
->sy_number
;
1900 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1903 #if defined(TC_A29K)
1905 /* The 29k has a special kludge for the high 16 bit
1906 reloc. Two relocations are emited, R_IHIHALF,
1907 and R_IHCONST. The second one doesn't contain a
1908 symbol, but uses the value for offset. */
1910 if (intr
.r_type
== R_IHIHALF
)
1912 /* now emit the second bit */
1913 intr
.r_type
= R_IHCONST
;
1914 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1915 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1921 fix_ptr
= fix_ptr
->fx_next
;
1925 /* Sort the reloc table */
1926 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1927 sizeof (struct external_reloc
), compare_external_relocs
);
1930 /* Write out the reloc table */
1931 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1933 free (external_reloc_vec
);
1935 /* Fill in section header info. */
1936 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1937 *file_cursor
+= external_reloc_size
;
1938 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1943 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1947 /* Set relocation_size field in file headers */
1948 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1952 /* run through a frag chain and write out the data to go with it, fill
1953 in the scnhdrs with the info on the file postions
1956 fill_section (abfd
, h
, file_cursor
)
1958 object_headers
*h ATTRIBUTE_UNUSED
;
1959 unsigned long *file_cursor
;
1963 unsigned int paddr
= 0;
1965 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1967 unsigned int offset
= 0;
1968 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1974 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1981 buffer
= xmalloc (s
->s_size
);
1982 s
->s_scnptr
= *file_cursor
;
1984 know (s
->s_paddr
== paddr
);
1986 if (strcmp (s
->s_name
, ".text") == 0)
1987 s
->s_flags
|= STYP_TEXT
;
1988 else if (strcmp (s
->s_name
, ".data") == 0)
1989 s
->s_flags
|= STYP_DATA
;
1990 else if (strcmp (s
->s_name
, ".bss") == 0)
1993 s
->s_flags
|= STYP_BSS
;
1995 /* @@ Should make the i386 and a29k coff targets define
1996 COFF_NOLOAD_PROBLEM, and have only one test here. */
1999 #ifndef COFF_NOLOAD_PROBLEM
2000 /* Apparently the SVR3 linker (and exec syscall) and UDI
2001 mondfe progrem are confused by noload sections. */
2002 s
->s_flags
|= STYP_NOLOAD
;
2007 else if (strcmp (s
->s_name
, ".lit") == 0)
2008 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2009 else if (strcmp (s
->s_name
, ".init") == 0)
2010 s
->s_flags
|= STYP_TEXT
;
2011 else if (strcmp (s
->s_name
, ".fini") == 0)
2012 s
->s_flags
|= STYP_TEXT
;
2013 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2014 s
->s_flags
|= STYP_INFO
;
2018 unsigned int fill_size
;
2019 switch (frag
->fr_type
)
2021 case rs_machine_dependent
:
2024 memcpy (buffer
+ frag
->fr_address
,
2026 (unsigned int) frag
->fr_fix
);
2027 offset
+= frag
->fr_fix
;
2032 assert (frag
->fr_symbol
== 0);
2039 memcpy (buffer
+ frag
->fr_address
,
2041 (unsigned int) frag
->fr_fix
);
2042 offset
+= frag
->fr_fix
;
2045 fill_size
= frag
->fr_var
;
2046 if (fill_size
&& frag
->fr_offset
> 0)
2049 unsigned int off
= frag
->fr_fix
;
2050 for (count
= frag
->fr_offset
; count
; count
--)
2052 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2054 memcpy (buffer
+ frag
->fr_address
+ off
,
2055 frag
->fr_literal
+ frag
->fr_fix
,
2058 offset
+= fill_size
;
2063 case rs_broken_word
:
2068 frag
= frag
->fr_next
;
2073 if (s
->s_scnptr
!= 0)
2075 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2076 *file_cursor
+= s
->s_size
;
2085 /* Coff file generation & utilities */
2088 coff_header_append (abfd
, h
)
2095 #ifdef COFF_LONG_SECTION_NAMES
2096 unsigned long string_size
= 4;
2099 bfd_seek (abfd
, 0, 0);
2101 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2102 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2103 H_SET_VERSION_STAMP (h
, 0);
2104 H_SET_ENTRY_POINT (h
, 0);
2105 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2106 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2107 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2109 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2110 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2111 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2113 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2115 bfd_write (buffer
, i
, 1, abfd
);
2116 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2118 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2120 if (segment_info
[i
].scnhdr
.s_name
[0])
2124 #ifdef COFF_LONG_SECTION_NAMES
2125 /* Support long section names as found in PE. This code
2126 must coordinate with that in write_object_file and
2128 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2130 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2131 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2132 string_size
+= strlen (segment_info
[i
].name
) + 1;
2136 size
= bfd_coff_swap_scnhdr_out (abfd
,
2137 &(segment_info
[i
].scnhdr
),
2140 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2141 bfd_write (buffer
, size
, 1, abfd
);
2148 symbol_to_chars (abfd
, where
, symbolP
)
2153 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2157 /* Turn any symbols with register attributes into abs symbols */
2158 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2160 S_SET_SEGMENT (symbolP
, absolute_section
);
2162 /* At the same time, relocate all symbols to their output value */
2165 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2166 + S_GET_VALUE (symbolP
));
2168 val
= S_GET_VALUE (symbolP
);
2171 S_SET_VALUE (symbolP
, val
);
2173 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2175 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2178 for (i
= 0; i
< numaux
; i
++)
2180 where
+= bfd_coff_swap_aux_out (abfd
,
2181 &symbolP
->sy_symbol
.ost_auxent
[i
],
2182 S_GET_DATA_TYPE (symbolP
),
2183 S_GET_STORAGE_CLASS (symbolP
),
2191 coff_obj_symbol_new_hook (symbolP
)
2194 char underscore
= 0; /* Symbol has leading _ */
2196 /* Effective symbol */
2197 /* Store the pointer in the offset. */
2198 S_SET_ZEROES (symbolP
, 0L);
2199 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2200 S_SET_STORAGE_CLASS (symbolP
, 0);
2201 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2202 /* Additional information */
2203 symbolP
->sy_symbol
.ost_flags
= 0;
2204 /* Auxiliary entries */
2205 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2207 if (S_IS_STRING (symbolP
))
2208 SF_SET_STRING (symbolP
);
2209 if (!underscore
&& S_IS_LOCAL (symbolP
))
2210 SF_SET_LOCAL (symbolP
);
2214 * Handle .ln directives.
2218 obj_coff_ln (appline
)
2223 if (! appline
&& def_symbol_in_progress
!= NULL
)
2225 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2226 demand_empty_rest_of_line ();
2228 } /* wrong context */
2230 l
= get_absolute_expression ();
2231 c_line_new (0, frag_now_fix (), l
, frag_now
);
2234 new_logical_line ((char *) NULL
, l
- 1);
2244 listing_source_line ((unsigned int) l
);
2249 demand_empty_rest_of_line ();
2255 * Handle .def directives.
2257 * One might ask : why can't we symbol_new if the symbol does not
2258 * already exist and fill it with debug information. Because of
2259 * the C_EFCN special symbol. It would clobber the value of the
2260 * function symbol before we have a chance to notice that it is
2261 * a C_EFCN. And a second reason is that the code is more clear this
2262 * way. (at least I think it is :-).
2266 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2267 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2268 *input_line_pointer == '\t') \
2269 input_line_pointer++;
2273 int what ATTRIBUTE_UNUSED
;
2275 char name_end
; /* Char after the end of name */
2276 char *symbol_name
; /* Name of the debug symbol */
2277 char *symbol_name_copy
; /* Temporary copy of the name */
2278 unsigned int symbol_name_length
;
2280 if (def_symbol_in_progress
!= NULL
)
2282 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2283 demand_empty_rest_of_line ();
2285 } /* if not inside .def/.endef */
2287 SKIP_WHITESPACES ();
2289 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2290 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2292 symbol_name
= input_line_pointer
;
2293 name_end
= get_symbol_end ();
2294 symbol_name_length
= strlen (symbol_name
);
2295 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2296 strcpy (symbol_name_copy
, symbol_name
);
2297 #ifdef tc_canonicalize_symbol_name
2298 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2301 /* Initialize the new symbol */
2302 #ifdef STRIP_UNDERSCORE
2303 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2304 ? symbol_name_copy
+ 1
2305 : symbol_name_copy
));
2306 #else /* STRIP_UNDERSCORE */
2307 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2308 #endif /* STRIP_UNDERSCORE */
2309 /* free(symbol_name_copy); */
2310 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2311 def_symbol_in_progress
->sy_number
= ~0;
2312 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2313 S_SET_VALUE (def_symbol_in_progress
, 0);
2315 if (S_IS_STRING (def_symbol_in_progress
))
2316 SF_SET_STRING (def_symbol_in_progress
);
2318 *input_line_pointer
= name_end
;
2320 demand_empty_rest_of_line ();
2323 unsigned int dim_index
;
2327 obj_coff_endef (ignore
)
2328 int ignore ATTRIBUTE_UNUSED
;
2330 symbolS
*symbolP
= 0;
2331 /* DIM BUG FIX sac@cygnus.com */
2333 if (def_symbol_in_progress
== NULL
)
2335 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2336 demand_empty_rest_of_line ();
2338 } /* if not inside .def/.endef */
2340 /* Set the section number according to storage class. */
2341 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2346 SF_SET_TAG (def_symbol_in_progress
);
2347 /* intentional fallthrough */
2350 SF_SET_DEBUG (def_symbol_in_progress
);
2351 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2355 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2356 /* intentional fallthrough */
2358 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2359 /* intentional fallthrough */
2361 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2363 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2365 if (function_lineoff
< 0)
2367 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2368 } /* missing function symbol */
2369 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2371 SF_SET_PROCESS (last_line_symbol
);
2372 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2373 SF_SET_PROCESS (def_symbol_in_progress
);
2374 function_lineoff
= -1;
2376 /* Value is always set to . */
2377 def_symbol_in_progress
->sy_frag
= frag_now
;
2378 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2383 #endif /* C_AUTOARG */
2393 SF_SET_DEBUG (def_symbol_in_progress
);
2394 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2404 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2410 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2412 } /* switch on storage class */
2414 /* Now that we have built a debug symbol, try to find if we should
2415 merge with an existing symbol or not. If a symbol is C_EFCN or
2416 absolute_section or untagged SEG_DEBUG it never merges. We also
2417 don't merge labels, which are in a different namespace, nor
2418 symbols which have not yet been defined since they are typically
2419 unique, nor do we merge tags with non-tags. */
2421 /* Two cases for functions. Either debug followed by definition or
2422 definition followed by debug. For definition first, we will
2423 merge the debug symbol into the definition. For debug first, the
2424 lineno entry MUST point to the definition function or else it
2425 will point off into space when crawl_symbols() merges the debug
2426 symbol into the real symbol. Therefor, let's presume the debug
2427 symbol is a real function reference. */
2429 /* FIXME-SOON If for some reason the definition label/symbol is
2430 never seen, this will probably leave an undefined symbol at link
2433 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2434 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2435 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2436 && !SF_GET_TAG (def_symbol_in_progress
))
2437 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2438 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2439 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2440 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2442 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2447 /* This symbol already exists, merge the newly created symbol
2448 into the old one. This is not mandatory. The linker can
2449 handle duplicate symbols correctly. But I guess that it save
2450 a *lot* of space if the assembly file defines a lot of
2453 /* The debug entry (def_symbol_in_progress) is merged into the
2454 previous definition. */
2456 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2457 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2458 def_symbol_in_progress
= symbolP
;
2460 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2461 || SF_GET_TAG (def_symbol_in_progress
)
2462 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2464 /* For functions, and tags, and static symbols, the symbol
2465 *must* be where the debug symbol appears. Move the
2466 existing symbol to the current place. */
2467 /* If it already is at the end of the symbol list, do nothing */
2468 if (def_symbol_in_progress
!= symbol_lastP
)
2470 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2472 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2473 &symbol_rootP
, &symbol_lastP
);
2474 } /* if not already in place */
2476 } /* normal or mergable */
2478 if (SF_GET_TAG (def_symbol_in_progress
))
2482 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2484 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2485 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2486 def_symbol_in_progress
);
2489 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2491 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2493 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2495 SF_SET_PROCESS (def_symbol_in_progress
);
2497 if (symbolP
== NULL
)
2499 /* That is, if this is the first time we've seen the
2501 symbol_table_insert (def_symbol_in_progress
);
2502 } /* definition follows debug */
2503 } /* Create the line number entry pointing to the function being defined */
2505 def_symbol_in_progress
= NULL
;
2506 demand_empty_rest_of_line ();
2510 obj_coff_dim (ignore
)
2511 int ignore ATTRIBUTE_UNUSED
;
2515 if (def_symbol_in_progress
== NULL
)
2517 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2518 demand_empty_rest_of_line ();
2520 } /* if not inside .def/.endef */
2522 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2524 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2526 SKIP_WHITESPACES ();
2527 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2528 get_absolute_expression ());
2530 switch (*input_line_pointer
)
2533 input_line_pointer
++;
2537 as_warn (_("badly formed .dim directive ignored"));
2538 /* intentional fallthrough */
2546 demand_empty_rest_of_line ();
2550 obj_coff_line (ignore
)
2551 int ignore ATTRIBUTE_UNUSED
;
2556 if (def_symbol_in_progress
== NULL
)
2562 name
= S_GET_NAME (def_symbol_in_progress
);
2563 this_base
= get_absolute_expression ();
2565 /* Only .bf symbols indicate the use of a new base line number; the
2566 line numbers associated with .ef, .bb, .eb are relative to the
2567 start of the containing function. */
2568 if (!strcmp (".bf", name
))
2570 #if 0 /* XXX Can we ever have line numbers going backwards? */
2571 if (this_base
> line_base
)
2574 line_base
= this_base
;
2582 listing_source_line ((unsigned int) line_base
);
2588 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2589 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2591 demand_empty_rest_of_line ();
2595 obj_coff_size (ignore
)
2596 int ignore ATTRIBUTE_UNUSED
;
2598 if (def_symbol_in_progress
== NULL
)
2600 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2601 demand_empty_rest_of_line ();
2603 } /* if not inside .def/.endef */
2605 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2606 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2607 demand_empty_rest_of_line ();
2611 obj_coff_scl (ignore
)
2612 int ignore ATTRIBUTE_UNUSED
;
2614 if (def_symbol_in_progress
== NULL
)
2616 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2617 demand_empty_rest_of_line ();
2619 } /* if not inside .def/.endef */
2621 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2622 demand_empty_rest_of_line ();
2626 obj_coff_tag (ignore
)
2627 int ignore ATTRIBUTE_UNUSED
;
2632 if (def_symbol_in_progress
== NULL
)
2634 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2635 demand_empty_rest_of_line ();
2639 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2640 symbol_name
= input_line_pointer
;
2641 name_end
= get_symbol_end ();
2642 #ifdef tc_canonicalize_symbol_name
2643 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2646 /* Assume that the symbol referred to by .tag is always defined.
2647 This was a bad assumption. I've added find_or_make. xoxorich. */
2648 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2649 (long) tag_find_or_make (symbol_name
));
2650 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2652 as_warn (_("tag not found for .tag %s"), symbol_name
);
2655 SF_SET_TAGGED (def_symbol_in_progress
);
2656 *input_line_pointer
= name_end
;
2658 demand_empty_rest_of_line ();
2662 obj_coff_type (ignore
)
2663 int ignore ATTRIBUTE_UNUSED
;
2665 if (def_symbol_in_progress
== NULL
)
2667 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2668 demand_empty_rest_of_line ();
2670 } /* if not inside .def/.endef */
2672 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2674 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2675 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2677 SF_SET_FUNCTION (def_symbol_in_progress
);
2678 } /* is a function */
2680 demand_empty_rest_of_line ();
2684 obj_coff_val (ignore
)
2685 int ignore ATTRIBUTE_UNUSED
;
2687 if (def_symbol_in_progress
== NULL
)
2689 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2690 demand_empty_rest_of_line ();
2692 } /* if not inside .def/.endef */
2694 if (is_name_beginner (*input_line_pointer
))
2696 char *symbol_name
= input_line_pointer
;
2697 char name_end
= get_symbol_end ();
2699 #ifdef tc_canonicalize_symbol_name
2700 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2703 if (!strcmp (symbol_name
, "."))
2705 def_symbol_in_progress
->sy_frag
= frag_now
;
2706 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2707 /* If the .val is != from the .def (e.g. statics) */
2709 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2711 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2712 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2713 symbol_find_or_make (symbol_name
);
2714 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2715 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2717 /* If the segment is undefined when the forward reference is
2718 resolved, then copy the segment id from the forward
2720 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2722 /* FIXME: gcc can generate address expressions here in
2723 unusual cases (search for "obscure" in sdbout.c). We
2724 just ignore the offset here, thus generating incorrect
2725 debugging information. We ignore the rest of the line
2728 /* Otherwise, it is the name of a non debug symbol and
2729 its value will be calculated later. */
2730 *input_line_pointer
= name_end
;
2732 /* FIXME: this is to avoid an error message in the
2733 FIXME case mentioned just above. */
2734 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2735 ++input_line_pointer
;
2739 S_SET_VALUE (def_symbol_in_progress
,
2740 (valueT
) get_absolute_expression ());
2741 } /* if symbol based */
2743 demand_empty_rest_of_line ();
2748 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2749 read.c, which then calls this object file format specific routine. */
2752 obj_coff_pe_handle_link_once (type
)
2753 enum linkonce_type type
;
2755 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2757 /* We store the type in the seg_info structure, and use it to set up
2758 the auxiliary entry for the section symbol in c_section_symbol. */
2759 seg_info (now_seg
)->linkonce
= type
;
2765 coff_obj_read_begin_hook ()
2767 /* These had better be the same. Usually 18 bytes. */
2769 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2770 know (SYMESZ
== AUXESZ
);
2775 /* This function runs through the symbol table and puts all the
2776 externals onto another chain */
2778 /* The chain of globals. */
2779 symbolS
*symbol_globalP
;
2780 symbolS
*symbol_global_lastP
;
2782 /* The chain of externals */
2783 symbolS
*symbol_externP
;
2784 symbolS
*symbol_extern_lastP
;
2787 symbolS
*last_functionP
;
2788 static symbolS
*last_bfP
;
2795 unsigned int symbol_number
= 0;
2796 unsigned int last_file_symno
= 0;
2798 struct filename_list
*filename_list_scan
= filename_list_head
;
2800 for (symbolP
= symbol_rootP
;
2802 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2804 if (symbolP
->sy_mri_common
)
2806 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2808 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2810 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2811 as_bad (_("%s: global symbols not supported in common sections"),
2812 S_GET_NAME (symbolP
));
2813 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2817 if (!SF_GET_DEBUG (symbolP
))
2819 /* Debug symbols do not need all this rubbish */
2820 symbolS
*real_symbolP
;
2822 /* L* and C_EFCN symbols never merge. */
2823 if (!SF_GET_LOCAL (symbolP
)
2824 && !SF_GET_STATICS (symbolP
)
2825 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2826 && symbolP
->sy_value
.X_op
== O_constant
2827 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2828 && real_symbolP
!= symbolP
)
2830 /* FIXME-SOON: where do dups come from?
2831 Maybe tag references before definitions? xoxorich. */
2832 /* Move the debug data from the debug symbol to the
2833 real symbol. Do NOT do the oposite (i.e. move from
2834 real symbol to debug symbol and remove real symbol from the
2835 list.) Because some pointers refer to the real symbol
2836 whereas no pointers refer to the debug symbol. */
2837 c_symbol_merge (symbolP
, real_symbolP
);
2838 /* Replace the current symbol by the real one */
2839 /* The symbols will never be the last or the first
2840 because : 1st symbol is .file and 3 last symbols are
2841 .text, .data, .bss */
2842 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2843 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2844 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2845 symbolP
= real_symbolP
;
2846 } /* if not local but dup'd */
2848 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2850 S_SET_SEGMENT (symbolP
, SEG_E0
);
2851 } /* push data into text */
2853 resolve_symbol_value (symbolP
, 1);
2855 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2857 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2859 S_SET_EXTERNAL (symbolP
);
2861 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2863 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2867 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2871 /* Mainly to speed up if not -g */
2872 if (SF_GET_PROCESS (symbolP
))
2874 /* Handle the nested blocks auxiliary info. */
2875 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2877 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2878 stack_push (block_stack
, (char *) &symbolP
);
2881 register symbolS
*begin_symbolP
;
2882 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2883 if (begin_symbolP
== (symbolS
*) 0)
2884 as_warn (_("mismatched .eb"));
2886 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2889 /* If we are able to identify the type of a function, and we
2890 are out of a function (last_functionP == 0) then, the
2891 function symbol will be associated with an auxiliary
2893 if (last_functionP
== (symbolS
*) 0 &&
2894 SF_GET_FUNCTION (symbolP
))
2896 last_functionP
= symbolP
;
2898 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2900 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2901 } /* make it at least 1 */
2903 /* Clobber possible stale .dim information. */
2905 /* Iffed out by steve - this fries the lnnoptr info too */
2906 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2907 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2910 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2912 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2914 if (last_bfP
!= NULL
)
2915 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2919 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2921 /* I don't even know if this is needed for sdb. But
2922 the standard assembler generates it, so... */
2923 if (last_functionP
== (symbolS
*) 0)
2924 as_fatal (_("C_EFCN symbol out of scope"));
2925 SA_SET_SYM_FSIZE (last_functionP
,
2926 (long) (S_GET_VALUE (symbolP
) -
2927 S_GET_VALUE (last_functionP
)));
2928 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2929 last_functionP
= (symbolS
*) 0;
2933 else if (SF_GET_TAG (symbolP
))
2935 /* First descriptor of a structure must point to
2936 the first slot after the structure description. */
2937 last_tagP
= symbolP
;
2940 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2942 /* +2 take in account the current symbol */
2943 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2945 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2947 /* If the filename was too long to fit in the
2948 auxent, put it in the string table */
2949 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2950 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2952 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2953 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2954 filename_list_scan
= filename_list_scan
->next
;
2956 if (S_GET_VALUE (symbolP
))
2958 S_SET_VALUE (symbolP
, last_file_symno
);
2959 last_file_symno
= symbol_number
;
2960 } /* no one points at the first .file symbol */
2961 } /* if debug or tag or eos or file */
2963 #ifdef tc_frob_coff_symbol
2964 tc_frob_coff_symbol (symbolP
);
2967 /* We must put the external symbols apart. The loader
2968 does not bomb if we do not. But the references in
2969 the endndx field for a .bb symbol are not corrected
2970 if an external symbol is removed between .bb and .be.
2971 I.e in the following case :
2972 [20] .bb endndx = 22
2975 ld will move the symbol 21 to the end of the list but
2976 endndx will still be 22 instead of 21. */
2979 if (SF_GET_LOCAL (symbolP
))
2981 /* remove C_EFCN and LOCAL (L...) symbols */
2982 /* next pointer remains valid */
2983 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2986 else if (symbolP
->sy_value
.X_op
== O_symbol
2987 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2989 /* Skip symbols which were equated to undefined or common
2991 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2993 else if (!S_IS_DEFINED (symbolP
)
2994 && !S_IS_DEBUG (symbolP
)
2995 && !SF_GET_STATICS (symbolP
)
2996 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2998 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3000 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3002 /* if external, Remove from the list */
3003 symbolS
*hold
= symbol_previous (symbolP
);
3005 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3006 symbol_clear_list_pointers (symbolP
);
3007 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3010 else if (! S_IS_DEBUG (symbolP
)
3011 && ! SF_GET_STATICS (symbolP
)
3012 && ! SF_GET_FUNCTION (symbolP
)
3013 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3015 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3017 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3019 symbolS
*hold
= symbol_previous (symbolP
);
3021 /* The O'Reilly COFF book says that defined global symbols
3022 come at the end of the symbol table, just before
3023 undefined global symbols. */
3025 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3026 symbol_clear_list_pointers (symbolP
);
3027 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3028 &symbol_global_lastP
);
3033 if (SF_GET_STRING (symbolP
))
3035 symbolP
->sy_name_offset
= string_byte_count
;
3036 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3040 symbolP
->sy_name_offset
= 0;
3041 } /* fix "long" names */
3043 symbolP
->sy_number
= symbol_number
;
3044 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3045 } /* if local symbol */
3046 } /* traverse the symbol list */
3047 return symbol_number
;
3053 glue_symbols (head
, tail
)
3057 unsigned int symbol_number
= 0;
3059 while (*head
!= NULL
)
3061 symbolS
*tmp
= *head
;
3064 symbol_remove (tmp
, head
, tail
);
3065 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3068 if (SF_GET_STRING (tmp
))
3070 tmp
->sy_name_offset
= string_byte_count
;
3071 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3075 tmp
->sy_name_offset
= 0;
3076 } /* fix "long" names */
3078 tmp
->sy_number
= symbol_number
;
3079 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3080 } /* append the entire extern chain */
3082 return symbol_number
;
3088 unsigned int symbol_number
= 0;
3091 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3093 symbolP
->sy_number
= symbol_number
;
3095 if (SF_GET_TAGGED (symbolP
))
3099 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3102 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3105 return symbol_number
;
3109 crawl_symbols (h
, abfd
)
3111 bfd
*abfd ATTRIBUTE_UNUSED
;
3115 /* Initialize the stack used to keep track of the matching .bb .be */
3117 block_stack
= stack_init (512, sizeof (symbolS
*));
3119 /* The symbol list should be ordered according to the following sequence
3122 * . debug entries for functions
3123 * . fake symbols for the sections, including .text .data and .bss
3125 * . undefined symbols
3126 * But this is not mandatory. The only important point is to put the
3127 * undefined symbols at the end of the list.
3130 /* Is there a .file symbol ? If not insert one at the beginning. */
3131 if (symbol_rootP
== NULL
3132 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3134 c_dot_file_symbol ("fake");
3138 * Build up static symbols for the sections, they are filled in later
3142 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3143 if (segment_info
[i
].scnhdr
.s_name
[0])
3144 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3147 /* Take all the externals out and put them into another chain */
3148 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3149 /* Take the externals and glue them onto the end.*/
3150 H_SET_SYMBOL_TABLE_SIZE (h
,
3151 (H_GET_SYMBOL_COUNT (h
)
3152 + glue_symbols (&symbol_globalP
,
3153 &symbol_global_lastP
)
3154 + glue_symbols (&symbol_externP
,
3155 &symbol_extern_lastP
)));
3157 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3158 know (symbol_globalP
== NULL
);
3159 know (symbol_global_lastP
== NULL
);
3160 know (symbol_externP
== NULL
);
3161 know (symbol_extern_lastP
== NULL
);
3165 * Find strings by crawling along symbol table chain.
3173 struct filename_list
*filename_list_scan
= filename_list_head
;
3175 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3176 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3179 #ifdef COFF_LONG_SECTION_NAMES
3180 /* Support long section names as found in PE. This code must
3181 coordinate with that in coff_header_append and write_object_file. */
3185 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3187 if (segment_info
[i
].scnhdr
.s_name
[0]
3188 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3192 size
= strlen (segment_info
[i
].name
) + 1;
3193 memcpy (where
, segment_info
[i
].name
, size
);
3198 #endif /* COFF_LONG_SECTION_NAMES */
3200 for (symbolP
= symbol_rootP
;
3202 symbolP
= symbol_next (symbolP
))
3206 if (SF_GET_STRING (symbolP
))
3208 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3209 memcpy (where
, S_GET_NAME (symbolP
), size
);
3212 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3213 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3214 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3216 size
= strlen (filename_list_scan
->filename
) + 1;
3217 memcpy (where
, filename_list_scan
->filename
, size
);
3218 filename_list_scan
= filename_list_scan
->next
;
3225 do_linenos_for (abfd
, h
, file_cursor
)
3228 unsigned long *file_cursor
;
3231 unsigned long start
= *file_cursor
;
3233 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3235 segment_info_type
*s
= segment_info
+ idx
;
3238 if (s
->scnhdr
.s_nlnno
!= 0)
3240 struct lineno_list
*line_ptr
;
3242 struct external_lineno
*buffer
=
3243 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3245 struct external_lineno
*dst
= buffer
;
3247 /* Run through the table we've built and turn it into its external
3248 form, take this chance to remove duplicates */
3250 for (line_ptr
= s
->lineno_list_head
;
3251 line_ptr
!= (struct lineno_list
*) NULL
;
3252 line_ptr
= line_ptr
->next
)
3255 if (line_ptr
->line
.l_lnno
== 0)
3257 /* Turn a pointer to a symbol into the symbols' index */
3258 line_ptr
->line
.l_addr
.l_symndx
=
3259 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3263 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3267 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3272 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3274 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3277 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3280 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3284 /* Now we run through the list of frag chains in a segment and
3285 make all the subsegment frags appear at the end of the
3286 list, as if the seg 0 was extra long */
3293 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3295 frchainS
*head
= segment_info
[i
].frchainP
;
3297 fragS
*prev_frag
= &dummy
;
3299 while (head
&& head
->frch_seg
== i
)
3301 prev_frag
->fr_next
= head
->frch_root
;
3302 prev_frag
= head
->frch_last
;
3303 head
= head
->frch_next
;
3305 prev_frag
->fr_next
= 0;
3309 unsigned long machine
;
3312 write_object_file ()
3316 struct frchain
*frchain_ptr
;
3318 object_headers headers
;
3319 unsigned long file_cursor
;
3322 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3327 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3328 exit (EXIT_FAILURE
);
3330 bfd_set_format (abfd
, bfd_object
);
3331 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3333 string_byte_count
= 4;
3335 for (frchain_ptr
= frchain_root
;
3336 frchain_ptr
!= (struct frchain
*) NULL
;
3337 frchain_ptr
= frchain_ptr
->frch_next
)
3339 /* Run through all the sub-segments and align them up. Also
3340 close any open frags. We tack a .fill onto the end of the
3341 frag chain so that any .align's size can be worked by looking
3342 at the next frag. */
3344 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3346 #ifndef SUB_SEGMENT_ALIGN
3347 #define SUB_SEGMENT_ALIGN(SEG) 1
3350 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3353 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3354 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3359 frag_wane (frag_now
);
3360 frag_now
->fr_fix
= 0;
3361 know (frag_now
->fr_next
== NULL
);
3368 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3370 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3373 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3375 /* Find out how big the sections are, and set the addresses. */
3377 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3381 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3382 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3384 if (segment_info
[i
].scnhdr
.s_name
[0])
3386 H_SET_NUMBER_OF_SECTIONS (&headers
,
3387 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3389 #ifdef COFF_LONG_SECTION_NAMES
3390 /* Support long section names as found in PE. This code
3391 must coordinate with that in coff_header_append and
3396 len
= strlen (segment_info
[i
].name
);
3398 string_byte_count
+= len
+ 1;
3400 #endif /* COFF_LONG_SECTION_NAMES */
3403 size
= size_section (abfd
, (unsigned int) i
);
3406 /* I think the section alignment is only used on the i960; the
3407 i960 needs it, and it should do no harm on other targets. */
3408 #ifdef ALIGNMENT_IN_S_FLAGS
3409 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3411 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3415 H_SET_TEXT_SIZE (&headers
, size
);
3416 else if (i
== SEG_E1
)
3417 H_SET_DATA_SIZE (&headers
, size
);
3418 else if (i
== SEG_E2
)
3419 H_SET_BSS_SIZE (&headers
, size
);
3422 /* Turn the gas native symbol table shape into a coff symbol table */
3423 crawl_symbols (&headers
, abfd
);
3425 if (string_byte_count
== 4)
3426 string_byte_count
= 0;
3428 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3434 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3436 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3437 fixup_segment (&segment_info
[i
], i
);
3440 /* Look for ".stab" segments and fill in their initial symbols
3442 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3444 name
= segment_info
[i
].name
;
3447 && strncmp (".stab", name
, 5) == 0
3448 && strncmp (".stabstr", name
, 8) != 0)
3449 adjust_stab_section (abfd
, i
);
3452 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3454 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3456 /* Plant the data */
3458 fill_section (abfd
, &headers
, &file_cursor
);
3460 do_relocs_for (abfd
, &headers
, &file_cursor
);
3462 do_linenos_for (abfd
, &headers
, &file_cursor
);
3464 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3465 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3466 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3468 H_SET_TIME_STAMP (&headers
, 0);
3470 #ifdef TC_COFF_SET_MACHINE
3471 TC_COFF_SET_MACHINE (&headers
);
3475 #define COFF_FLAGS 0
3478 #ifdef KEEP_RELOC_INFO
3479 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3480 COFF_FLAGS
| coff_flags
));
3482 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3483 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3484 COFF_FLAGS
| coff_flags
));
3488 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3489 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3491 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3492 w_symbols (abfd
, buffer1
, symbol_rootP
);
3493 if (string_byte_count
> 0)
3494 w_strings (buffer1
+ symtable_size
);
3495 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3499 coff_header_append (abfd
, &headers
);
3501 /* Recent changes to write need this, but where it should
3502 go is up to Ken.. */
3503 if (bfd_close_all_done (abfd
) == false)
3504 as_fatal (_("Can't close %s: %s"), out_file_name
,
3505 bfd_errmsg (bfd_get_error ()));
3508 extern bfd
*stdoutput
;
3515 /* Add a new segment. This is called from subseg_new via the
3516 obj_new_segment macro. */
3519 obj_coff_add_segment (name
)
3524 #ifndef COFF_LONG_SECTION_NAMES
3525 char buf
[SCNNMLEN
+ 1];
3527 strncpy (buf
, name
, SCNNMLEN
);
3528 buf
[SCNNMLEN
] = '\0';
3532 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3533 if (strcmp (name
, segment_info
[i
].name
) == 0)
3538 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3542 /* Add a new section. */
3543 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3544 sizeof (segment_info
[i
].scnhdr
.s_name
));
3545 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3546 segment_info
[i
].name
= xstrdup (name
);
3552 * implement the .section pseudo op:
3553 * .section name {, "flags"}
3555 * | +--- optional flags: 'b' for bss
3557 * +-- section name 'l' for lib
3561 * 'd' (apparently m88k for data)
3563 * 'r' for read-only data
3564 * But if the argument is not a quoted string, treat it as a
3565 * subsegment number.
3569 obj_coff_section (ignore
)
3570 int ignore ATTRIBUTE_UNUSED
;
3572 /* Strip out the section name */
3573 char *section_name
, *name
;
3586 else if (type
== 'D')
3588 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3593 section_name
= input_line_pointer
;
3594 c
= get_symbol_end ();
3596 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3597 strcpy (name
, section_name
);
3599 *input_line_pointer
= c
;
3605 if (*input_line_pointer
== ',')
3607 ++input_line_pointer
;
3610 if (*input_line_pointer
!= '"')
3611 exp
= get_absolute_expression ();
3614 ++input_line_pointer
;
3615 while (*input_line_pointer
!= '"'
3616 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3618 switch (*input_line_pointer
)
3620 case 'b': flags
|= STYP_BSS
; break;
3621 case 'i': flags
|= STYP_INFO
; break;
3622 case 'l': flags
|= STYP_LIB
; break;
3623 case 'n': flags
|= STYP_NOLOAD
; break;
3624 case 'o': flags
|= STYP_OVER
; break;
3626 case 'w': flags
|= STYP_DATA
; break;
3627 case 'x': flags
|= STYP_TEXT
; break;
3628 case 'r': flags
|= STYP_LIT
; break;
3630 as_warn(_("unknown section attribute '%c'"),
3631 *input_line_pointer
);
3634 ++input_line_pointer
;
3636 if (*input_line_pointer
== '"')
3637 ++input_line_pointer
;
3641 subseg_new (name
, (subsegT
) exp
);
3643 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3645 demand_empty_rest_of_line ();
3650 obj_coff_text (ignore
)
3651 int ignore ATTRIBUTE_UNUSED
;
3653 subseg_new (".text", get_absolute_expression ());
3658 obj_coff_data (ignore
)
3659 int ignore ATTRIBUTE_UNUSED
;
3661 if (flag_readonly_data_in_text
)
3662 subseg_new (".text", get_absolute_expression () + 1000);
3664 subseg_new (".data", get_absolute_expression ());
3668 obj_coff_ident (ignore
)
3669 int ignore ATTRIBUTE_UNUSED
;
3671 segT current_seg
= now_seg
; /* save current seg */
3672 subsegT current_subseg
= now_subseg
;
3673 subseg_new (".comment", 0); /* .comment seg */
3674 stringer (1); /* read string */
3675 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3679 c_symbol_merge (debug
, normal
)
3683 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3684 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3686 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3688 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3689 } /* take the most we have */
3691 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3693 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3694 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3695 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3696 } /* Move all the auxiliary information */
3698 /* Move the debug flags. */
3699 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3700 } /* c_symbol_merge() */
3703 c_line_new (symbol
, paddr
, line_number
, frag
)
3709 struct lineno_list
*new_line
=
3710 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3712 segment_info_type
*s
= segment_info
+ now_seg
;
3713 new_line
->line
.l_lnno
= line_number
;
3715 if (line_number
== 0)
3717 last_line_symbol
= symbol
;
3718 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3722 new_line
->line
.l_addr
.l_paddr
= paddr
;
3725 new_line
->frag
= (char *) frag
;
3726 new_line
->next
= (struct lineno_list
*) NULL
;
3729 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3731 s
->lineno_list_head
= new_line
;
3735 s
->lineno_list_tail
->next
= new_line
;
3737 s
->lineno_list_tail
= new_line
;
3738 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3742 c_dot_file_symbol (filename
)
3747 symbolP
= symbol_new (".file",
3750 &zero_address_frag
);
3752 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3753 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3755 if (strlen (filename
) > FILNMLEN
)
3757 /* Filename is too long to fit into an auxent,
3758 we stick it into the string table instead. We keep
3759 a linked list of the filenames we find so we can emit
3761 struct filename_list
*f
= ((struct filename_list
*)
3762 xmalloc (sizeof (struct filename_list
)));
3764 f
->filename
= filename
;
3767 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3768 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3770 if (filename_list_tail
)
3771 filename_list_tail
->next
= f
;
3773 filename_list_head
= f
;
3774 filename_list_tail
= f
;
3778 SA_SET_FILE_FNAME (symbolP
, filename
);
3785 listing_source_file (filename
);
3791 SF_SET_DEBUG (symbolP
);
3792 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3794 previous_file_symbol
= symbolP
;
3796 /* Make sure that the symbol is first on the symbol chain */
3797 if (symbol_rootP
!= symbolP
)
3799 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3800 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3802 } /* c_dot_file_symbol() */
3805 * Build a 'section static' symbol.
3809 c_section_symbol (name
, idx
)
3815 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3816 if (symbolP
== NULL
)
3817 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3820 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3821 S_SET_SEGMENT (symbolP
, idx
);
3822 symbolP
->sy_frag
= &zero_address_frag
;
3825 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3826 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3828 SF_SET_STATICS (symbolP
);
3831 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3832 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3833 SF_CLEAR_LOCAL (symbolP
);
3836 /* If the .linkonce pseudo-op was used for this section, we must
3837 store the information in the auxiliary entry for the section
3839 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3843 switch (segment_info
[idx
].linkonce
)
3847 case LINKONCE_DISCARD
:
3848 type
= IMAGE_COMDAT_SELECT_ANY
;
3850 case LINKONCE_ONE_ONLY
:
3851 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3853 case LINKONCE_SAME_SIZE
:
3854 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3856 case LINKONCE_SAME_CONTENTS
:
3857 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3861 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3866 } /* c_section_symbol() */
3869 w_symbols (abfd
, where
, symbol_rootP
)
3872 symbolS
* symbol_rootP
;
3877 /* First fill in those values we have only just worked out */
3878 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3880 symbolP
= segment_info
[i
].dot
;
3883 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3884 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3885 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3890 * Emit all symbols left in the symbol chain.
3892 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3894 /* Used to save the offset of the name. It is used to point
3895 to the string in memory but must be a file offset. */
3896 register char *temp
;
3898 /* We can't fix the lnnoptr field in yank_symbols with the other
3899 adjustments, because we have to wait until we know where they
3901 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3903 SA_GET_SYM_LNNOPTR (symbolP
) +=
3904 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3907 tc_coff_symbol_emit_hook (symbolP
);
3909 temp
= S_GET_NAME (symbolP
);
3910 if (SF_GET_STRING (symbolP
))
3912 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3913 S_SET_ZEROES (symbolP
, 0);
3917 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3918 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3920 where
= symbol_to_chars (abfd
, where
, symbolP
);
3921 S_SET_NAME (symbolP
, temp
);
3927 obj_coff_lcomm (ignore
)
3928 int ignore ATTRIBUTE_UNUSED
;
3940 name
= input_line_pointer
;
3942 c
= get_symbol_end ();
3943 p
= input_line_pointer
;
3946 if (*input_line_pointer
!= ',')
3948 as_bad (_("Expected comma after name"));
3949 ignore_rest_of_line ();
3952 if (*input_line_pointer
== '\n')
3954 as_bad (_("Missing size expression"));
3957 input_line_pointer
++;
3958 if ((temp
= get_absolute_expression ()) < 0)
3960 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3961 ignore_rest_of_line ();
3966 symbolP
= symbol_find_or_make(name
);
3968 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3969 S_GET_VALUE(symbolP
) == 0)
3974 segT current_seg
= now_seg
; /* save current seg */
3975 subsegT current_subseg
= now_subseg
;
3977 subseg_set (SEG_E2
, 1);
3978 symbolP
->sy_frag
= frag_now
;
3979 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3980 (offsetT
) temp
, (char *) 0);
3982 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3983 S_SET_SEGMENT(symbolP
, SEG_E2
);
3984 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3988 as_bad(_("Symbol %s already defined"), name
);
3990 demand_empty_rest_of_line();
3995 fixup_mdeps (frags
, h
, this_segment
)
4000 subseg_change (this_segment
, 0);
4003 switch (frags
->fr_type
)
4009 HANDLE_ALIGN (frags
);
4011 frags
->fr_type
= rs_fill
;
4013 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4016 case rs_machine_dependent
:
4017 md_convert_frag (h
, this_segment
, frags
);
4023 frags
= frags
->fr_next
;
4029 #ifndef TC_FORCE_RELOCATION
4030 #define TC_FORCE_RELOCATION(fix) 0
4034 fixup_segment (segP
, this_segment_type
)
4035 segment_info_type
* segP
;
4036 segT this_segment_type
;
4038 register fixS
* fixP
;
4039 register symbolS
*add_symbolP
;
4040 register symbolS
*sub_symbolP
;
4043 register char *place
;
4044 register long where
;
4045 register char pcrel
;
4046 register fragS
*fragP
;
4047 register segT add_symbol_segment
= absolute_section
;
4049 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4051 fragP
= fixP
->fx_frag
;
4053 where
= fixP
->fx_where
;
4054 place
= fragP
->fr_literal
+ where
;
4055 size
= fixP
->fx_size
;
4056 add_symbolP
= fixP
->fx_addsy
;
4057 sub_symbolP
= fixP
->fx_subsy
;
4058 add_number
= fixP
->fx_offset
;
4059 pcrel
= fixP
->fx_pcrel
;
4061 /* We want function-relative stabs to work on systems which
4062 may use a relaxing linker; thus we must handle the sym1-sym2
4063 fixups function-relative stabs generates.
4065 Of course, if you actually enable relaxing in the linker, the
4066 line and block scoping information is going to be incorrect
4067 in some cases. The only way to really fix this is to support
4068 a reloc involving the difference of two symbols. */
4070 && (!sub_symbolP
|| pcrel
))
4074 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4076 /* Relocation should be done via the associated 'bal' entry
4079 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4081 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4082 _("No 'bal' entry point for leafproc %s"),
4083 S_GET_NAME (add_symbolP
));
4086 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4090 /* Make sure the symbols have been resolved; this may not have
4091 happened if these are expression symbols. */
4092 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4093 resolve_symbol_value (add_symbolP
, 1);
4095 if (add_symbolP
!= NULL
)
4097 /* If this fixup is against a symbol which has been equated
4098 to another symbol, convert it to the other symbol. */
4099 if (add_symbolP
->sy_value
.X_op
== O_symbol
4100 && (! S_IS_DEFINED (add_symbolP
)
4101 || S_IS_COMMON (add_symbolP
)))
4103 while (add_symbolP
->sy_value
.X_op
== O_symbol
4104 && (! S_IS_DEFINED (add_symbolP
)
4105 || S_IS_COMMON (add_symbolP
)))
4109 /* We must avoid looping, as that can occur with a
4110 badly written program. */
4111 n
= add_symbolP
->sy_value
.X_add_symbol
;
4112 if (n
== add_symbolP
)
4114 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4117 fixP
->fx_addsy
= add_symbolP
;
4118 fixP
->fx_offset
= add_number
;
4122 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4123 resolve_symbol_value (sub_symbolP
, 1);
4125 if (add_symbolP
!= NULL
4126 && add_symbolP
->sy_mri_common
)
4128 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4129 add_number
+= S_GET_VALUE (add_symbolP
);
4130 fixP
->fx_offset
= add_number
;
4131 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4136 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4137 } /* if there is an addend */
4141 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4143 if (add_symbolP
!= NULL
)
4145 add_number
+= S_GET_VALUE (add_symbolP
);
4147 fixP
->fx_addsy
= NULL
;
4150 /* It's just -sym. */
4151 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4153 add_number
-= S_GET_VALUE (sub_symbolP
);
4160 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4161 _("Negative of non-absolute symbol %s"),
4162 S_GET_NAME (sub_symbolP
));
4164 add_number
-= S_GET_VALUE (sub_symbolP
);
4165 } /* not absolute */
4167 /* if sub_symbol is in the same segment that add_symbol
4168 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4170 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4171 && SEG_NORMAL (add_symbol_segment
))
4173 /* Difference of 2 symbols from same segment. Can't
4174 make difference of 2 undefineds: 'value' means
4175 something different for N_UNDF. */
4177 /* Makes no sense to use the difference of 2 arbitrary symbols
4178 as the target of a call instruction. */
4181 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4182 _("callj to difference of 2 symbols"));
4184 #endif /* TC_I960 */
4185 add_number
+= S_GET_VALUE (add_symbolP
) -
4186 S_GET_VALUE (sub_symbolP
);
4189 if (!TC_FORCE_RELOCATION (fixP
))
4191 fixP
->fx_addsy
= NULL
;
4192 fixP
->fx_subsy
= NULL
;
4194 #ifdef TC_M68K /* is this right? */
4202 /* Different segments in subtraction. */
4203 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4205 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4207 add_number
-= S_GET_VALUE (sub_symbolP
);
4210 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4211 #if 0 /* Okay for 68k, at least... */
4216 /* Make it pc-relative. */
4217 add_number
+= (md_pcrel_from (fixP
)
4218 - S_GET_VALUE (sub_symbolP
));
4227 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4228 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4229 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4230 S_GET_NAME (sub_symbolP
),
4231 (long) (fragP
->fr_address
+ where
));
4234 } /* if sub_symbolP */
4238 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4241 * This fixup was made when the symbol's segment was
4242 * SEG_UNKNOWN, but it is now in the local segment.
4243 * So we know how to do the address without relocation.
4246 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4247 * in which cases it modifies *fixP as appropriate. In the case
4248 * of a 'calls', no further work is required, and *fixP has been
4249 * set up to make the rest of the code below a no-op.
4252 #endif /* TC_I960 */
4254 add_number
+= S_GET_VALUE (add_symbolP
);
4255 add_number
-= md_pcrel_from (fixP
);
4258 add_number -= segP->scnhdr.s_vaddr;
4259 if defined (TC_I386) || defined (TE_LYNX). I now
4260 think that was an error propagated from the case when
4261 we are going to emit the relocation. If we are not
4262 going to emit the relocation, then we just want to
4263 set add_number to the difference between the symbols.
4264 This is a case that would only arise when there is a
4265 PC relative reference from a section other than .text
4266 to a symbol defined in the same section, and the
4267 reference is not relaxed. Since jump instructions on
4268 the i386 are relaxed, this could only arise with a
4269 call instruction. */
4271 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4272 if (!TC_FORCE_RELOCATION (fixP
))
4274 fixP
->fx_addsy
= NULL
;
4280 switch (add_symbol_segment
)
4282 case absolute_section
:
4284 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4285 #endif /* TC_I960 */
4286 add_number
+= S_GET_VALUE (add_symbolP
);
4289 if (!TC_FORCE_RELOCATION (fixP
))
4291 fixP
->fx_addsy
= NULL
;
4298 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4299 /* This really should be handled in the linker, but
4300 backward compatibility forbids. */
4301 add_number
+= S_GET_VALUE (add_symbolP
);
4303 add_number
+= S_GET_VALUE (add_symbolP
) +
4304 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4310 if ((int) fixP
->fx_bit_fixP
== 13)
4312 /* This is a COBR instruction. They have only a
4313 * 13-bit displacement and are only to be used
4314 * for local branches: flag as error, don't generate
4317 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4318 _("can't use COBR format with external label"));
4319 fixP
->fx_addsy
= NULL
;
4323 #endif /* TC_I960 */
4324 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4325 /* 386 COFF uses a peculiar format in which the
4326 value of a common symbol is stored in the .text
4327 segment (I've checked this on SVR3.2 and SCO
4328 3.2.2) Ian Taylor <ian@cygnus.com>. */
4329 /* This is also true for 68k COFF on sysv machines
4330 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4331 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4332 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4333 if (S_IS_COMMON (add_symbolP
))
4334 add_number
+= S_GET_VALUE (add_symbolP
);
4339 } /* switch on symbol seg */
4340 } /* if not in local seg */
4341 } /* if there was a + symbol */
4345 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4346 /* This adjustment is not correct on the m88k, for which the
4347 linker does all the computation. */
4348 add_number
-= md_pcrel_from (fixP
);
4350 if (add_symbolP
== 0)
4352 fixP
->fx_addsy
= &abs_symbol
;
4353 } /* if there's an add_symbol */
4354 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4355 /* On the 386 we must adjust by the segment vaddr as well.
4358 I changed the i960 to work this way as well. This is
4359 compatible with the current GNU linker behaviour. I do
4360 not know what other i960 COFF assemblers do. This is not
4361 a common case: normally, only assembler code will contain
4362 a PC relative reloc, and only branches which do not
4363 originate in the .text section will have a non-zero
4366 I changed the m68k to work this way as well. This will
4367 break existing PC relative relocs from sections which do
4368 not start at address 0, but it will make ld -r work.
4369 Ian Taylor, 4 Oct 96. */
4371 add_number
-= segP
->scnhdr
.s_vaddr
;
4375 #ifdef MD_APPLY_FIX3
4376 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4378 md_apply_fix (fixP
, add_number
);
4381 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4384 /* The m88k uses the offset field of the reloc to get around
4387 && ((add_number
& ~0xFF)
4388 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4389 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4390 || (add_number
& 0x80) == 0))
4392 && ((add_number
& ~0xFFFF)
4393 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4394 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4395 || (add_number
& 0x8000) == 0)))
4397 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4398 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4399 (long) add_number
, size
,
4400 (unsigned long) (fragP
->fr_address
+ where
));
4403 #ifdef WARN_SIGNED_OVERFLOW_WORD
4404 /* Warn if a .word value is too large when treated as a
4405 signed number. We already know it is not too negative.
4406 This is to catch over-large switches generated by gcc on
4408 if (!flag_signed_overflow_ok
4410 && add_number
> 0x7fff)
4411 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4412 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4414 (unsigned long) (fragP
->fr_address
+ where
));
4416 } /* not a bit fix */
4417 } /* For each fixS in this segment. */
4418 } /* fixup_segment() */
4422 /* The first entry in a .stab section is special. */
4425 obj_coff_init_stab_section (seg
)
4431 unsigned int stroff
;
4433 /* Make space for this first symbol. */
4437 as_where (&file
, (unsigned int *) NULL
);
4438 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4439 strcpy (stabstr_name
, segment_info
[seg
].name
);
4440 strcat (stabstr_name
, "str");
4441 stroff
= get_stab_string_offset (file
, stabstr_name
);
4443 md_number_to_chars (p
, stroff
, 4);
4446 /* Fill in the counts in the first entry in a .stab section. */
4449 adjust_stab_section(abfd
, seg
)
4453 segT stabstrseg
= SEG_UNKNOWN
;
4454 const char *secname
, *name2
;
4457 int i
, strsz
= 0, nsyms
;
4458 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4460 /* Look for the associated string table section. */
4462 secname
= segment_info
[seg
].name
;
4463 name
= (char *) alloca (strlen (secname
) + 4);
4464 strcpy (name
, secname
);
4465 strcat (name
, "str");
4467 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4469 name2
= segment_info
[i
].name
;
4470 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4477 /* If we found the section, get its size. */
4478 if (stabstrseg
!= SEG_UNKNOWN
)
4479 strsz
= size_section (abfd
, stabstrseg
);
4481 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4483 /* Look for the first frag of sufficient size for the initial stab
4484 symbol, and collect a pointer to it. */
4485 while (frag
&& frag
->fr_fix
< 12)
4486 frag
= frag
->fr_next
;
4488 p
= frag
->fr_literal
;
4491 /* Write in the number of stab symbols and the size of the string
4493 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4494 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4497 #endif /* not BFD_ASSEMBLER */
4499 const pseudo_typeS obj_pseudo_table
[] =
4501 {"def", obj_coff_def
, 0},
4502 {"dim", obj_coff_dim
, 0},
4503 {"endef", obj_coff_endef
, 0},
4504 {"line", obj_coff_line
, 0},
4505 {"ln", obj_coff_ln
, 0},
4506 #ifdef BFD_ASSEMBLER
4507 {"loc", obj_coff_loc
, 0},
4509 {"appline", obj_coff_ln
, 1},
4510 {"scl", obj_coff_scl
, 0},
4511 {"size", obj_coff_size
, 0},
4512 {"tag", obj_coff_tag
, 0},
4513 {"type", obj_coff_type
, 0},
4514 {"val", obj_coff_val
, 0},
4515 {"section", obj_coff_section
, 0},
4516 {"sect", obj_coff_section
, 0},
4517 /* FIXME: We ignore the MRI short attribute. */
4518 {"section.s", obj_coff_section
, 0},
4519 {"sect.s", obj_coff_section
, 0},
4520 /* We accept the .bss directive for backward compatibility with
4521 earlier versions of gas. */
4522 {"bss", obj_coff_bss
, 0},
4523 {"weak", obj_coff_weak
, 0},
4524 #ifndef BFD_ASSEMBLER
4525 {"use", obj_coff_section
, 0},
4526 {"text", obj_coff_text
, 0},
4527 {"data", obj_coff_data
, 0},
4528 {"lcomm", obj_coff_lcomm
, 0},
4529 {"ident", obj_coff_ident
, 0},
4531 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4532 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4534 {"version", s_ignore
, 0},
4535 {"ABORT", s_abort
, 0},
4537 /* The m88k uses sdef instead of def. */
4538 {"sdef", obj_coff_def
, 0},
4540 {NULL
, NULL
, 0} /* end sentinel */
4541 }; /* obj_pseudo_table */
4543 #ifdef BFD_ASSEMBLER
4545 static void coff_pop_insert
PARAMS ((void));
4546 static int coff_sec_sym_ok_for_reloc
PARAMS ((asection
*));
4548 /* Support for a COFF emulation. */
4553 pop_insert (obj_pseudo_table
);
4557 coff_sec_sym_ok_for_reloc (sec
)
4558 asection
*sec ATTRIBUTE_UNUSED
;
4563 const struct format_ops coff_format_ops
=
4565 bfd_target_coff_flavour
,
4570 coff_frob_file_after_relocs
,
4575 obj_generate_asm_lineno
,
4584 coff_sec_sym_ok_for_reloc
,
4591 coff_obj_read_begin_hook
,
4592 coff_obj_symbol_new_hook
,