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
[1] == 'b' && name
[2] == 'f')
664 if (! in_function ())
665 as_warn (_("`%s' symbol without preceding function"), name
);
666 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
667 /* Will need relocating */
668 SF_SET_PROCESS (def_symbol_in_progress
);
676 #endif /* C_AUTOARG */
682 SF_SET_DEBUG (def_symbol_in_progress
);
683 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
690 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
700 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
707 as_warn (_("unexpected storage class %d"),
708 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
710 } /* switch on storage class */
712 /* Now that we have built a debug symbol, try to find if we should
713 merge with an existing symbol or not. If a symbol is C_EFCN or
714 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
716 /* Two cases for functions. Either debug followed by definition or
717 definition followed by debug. For definition first, we will
718 merge the debug symbol into the definition. For debug first, the
719 lineno entry MUST point to the definition function or else it
720 will point off into space when obj_crawl_symbol_chain() merges
721 the debug symbol into the real symbol. Therefor, let's presume
722 the debug symbol is a real function reference. */
724 /* FIXME-SOON If for some reason the definition label/symbol is
725 never seen, this will probably leave an undefined symbol at link
728 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
729 || (!strcmp (bfd_get_section_name (stdoutput
,
730 S_GET_SEGMENT (def_symbol_in_progress
)),
732 && !SF_GET_TAG (def_symbol_in_progress
))
733 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
734 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
736 if (def_symbol_in_progress
!= symbol_lastP
)
737 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
742 /* This symbol already exists, merge the newly created symbol
743 into the old one. This is not mandatory. The linker can
744 handle duplicate symbols correctly. But I guess that it save
745 a *lot* of space if the assembly file defines a lot of
748 /* The debug entry (def_symbol_in_progress) is merged into the
749 previous definition. */
751 c_symbol_merge (def_symbol_in_progress
, symbolP
);
752 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
754 def_symbol_in_progress
= symbolP
;
756 if (SF_GET_FUNCTION (def_symbol_in_progress
)
757 || SF_GET_TAG (def_symbol_in_progress
)
758 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
760 /* For functions, and tags, and static symbols, the symbol
761 *must* be where the debug symbol appears. Move the
762 existing symbol to the current place. */
763 /* If it already is at the end of the symbol list, do nothing */
764 if (def_symbol_in_progress
!= symbol_lastP
)
766 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
767 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
772 if (SF_GET_TAG (def_symbol_in_progress
))
776 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
778 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
779 tag_insert (S_GET_NAME (def_symbol_in_progress
),
780 def_symbol_in_progress
);
783 if (SF_GET_FUNCTION (def_symbol_in_progress
))
785 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
786 set_function (def_symbol_in_progress
);
787 SF_SET_PROCESS (def_symbol_in_progress
);
791 /* That is, if this is the first time we've seen the
793 symbol_table_insert (def_symbol_in_progress
);
794 } /* definition follows debug */
795 } /* Create the line number entry pointing to the function being defined */
797 def_symbol_in_progress
= NULL
;
798 demand_empty_rest_of_line ();
802 obj_coff_dim (ignore
)
803 int ignore ATTRIBUTE_UNUSED
;
807 if (def_symbol_in_progress
== NULL
)
809 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
810 demand_empty_rest_of_line ();
812 } /* if not inside .def/.endef */
814 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
816 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
819 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
820 get_absolute_expression ());
822 switch (*input_line_pointer
)
825 input_line_pointer
++;
829 as_warn (_("badly formed .dim directive ignored"));
830 /* intentional fallthrough */
838 demand_empty_rest_of_line ();
842 obj_coff_line (ignore
)
843 int ignore ATTRIBUTE_UNUSED
;
847 if (def_symbol_in_progress
== NULL
)
849 /* Probably stabs-style line? */
854 this_base
= get_absolute_expression ();
855 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
856 coff_line_base
= this_base
;
858 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
859 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
861 demand_empty_rest_of_line ();
864 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
869 listing_source_line ((unsigned int) coff_line_base
);
875 obj_coff_size (ignore
)
876 int ignore ATTRIBUTE_UNUSED
;
878 if (def_symbol_in_progress
== NULL
)
880 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
881 demand_empty_rest_of_line ();
883 } /* if not inside .def/.endef */
885 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
886 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
887 demand_empty_rest_of_line ();
891 obj_coff_scl (ignore
)
892 int ignore ATTRIBUTE_UNUSED
;
894 if (def_symbol_in_progress
== NULL
)
896 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
897 demand_empty_rest_of_line ();
899 } /* if not inside .def/.endef */
901 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
902 demand_empty_rest_of_line ();
906 obj_coff_tag (ignore
)
907 int ignore ATTRIBUTE_UNUSED
;
912 if (def_symbol_in_progress
== NULL
)
914 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
915 demand_empty_rest_of_line ();
919 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
920 symbol_name
= input_line_pointer
;
921 name_end
= get_symbol_end ();
923 #ifdef tc_canonicalize_symbol_name
924 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
927 /* Assume that the symbol referred to by .tag is always defined.
928 This was a bad assumption. I've added find_or_make. xoxorich. */
929 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
930 tag_find_or_make (symbol_name
));
931 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
933 as_warn (_("tag not found for .tag %s"), symbol_name
);
936 SF_SET_TAGGED (def_symbol_in_progress
);
937 *input_line_pointer
= name_end
;
939 demand_empty_rest_of_line ();
943 obj_coff_type (ignore
)
944 int ignore ATTRIBUTE_UNUSED
;
946 if (def_symbol_in_progress
== NULL
)
948 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
949 demand_empty_rest_of_line ();
951 } /* if not inside .def/.endef */
953 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
955 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
956 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
958 SF_SET_FUNCTION (def_symbol_in_progress
);
959 } /* is a function */
961 demand_empty_rest_of_line ();
965 obj_coff_val (ignore
)
966 int ignore ATTRIBUTE_UNUSED
;
968 if (def_symbol_in_progress
== NULL
)
970 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
971 demand_empty_rest_of_line ();
973 } /* if not inside .def/.endef */
975 if (is_name_beginner (*input_line_pointer
))
977 char *symbol_name
= input_line_pointer
;
978 char name_end
= get_symbol_end ();
980 #ifdef tc_canonicalize_symbol_name
981 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
983 if (!strcmp (symbol_name
, "."))
985 symbol_set_frag (def_symbol_in_progress
, frag_now
);
986 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
987 /* If the .val is != from the .def (e.g. statics) */
989 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
994 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
995 exp
.X_op_symbol
= NULL
;
996 exp
.X_add_number
= 0;
997 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
999 /* If the segment is undefined when the forward reference is
1000 resolved, then copy the segment id from the forward
1002 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1004 /* FIXME: gcc can generate address expressions here in
1005 unusual cases (search for "obscure" in sdbout.c). We
1006 just ignore the offset here, thus generating incorrect
1007 debugging information. We ignore the rest of the line
1010 /* Otherwise, it is the name of a non debug symbol and its value
1011 will be calculated later. */
1012 *input_line_pointer
= name_end
;
1016 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1017 } /* if symbol based */
1019 demand_empty_rest_of_line ();
1023 coff_obj_read_begin_hook ()
1025 /* These had better be the same. Usually 18 bytes. */
1027 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1028 know (SYMESZ
== AUXESZ
);
1034 symbolS
*coff_last_function
;
1035 static symbolS
*coff_last_bf
;
1038 coff_frob_symbol (symp
, punt
)
1042 static symbolS
*last_tagP
;
1043 static stack
*block_stack
;
1044 static symbolS
*set_end
;
1045 symbolS
*next_set_end
= NULL
;
1047 if (symp
== &abs_symbol
)
1053 if (current_lineno_sym
)
1054 coff_add_linesym ((symbolS
*) 0);
1057 block_stack
= stack_init (512, sizeof (symbolS
*));
1059 if (S_IS_WEAK (symp
))
1062 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1064 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1068 if (!S_IS_DEFINED (symp
)
1069 && !S_IS_WEAK (symp
)
1070 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1071 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1073 if (!SF_GET_DEBUG (symp
))
1076 if (!SF_GET_LOCAL (symp
)
1077 && !SF_GET_STATICS (symp
)
1078 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1081 c_symbol_merge (symp
, real
);
1084 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1086 assert (S_GET_VALUE (symp
) == 0);
1087 S_SET_EXTERNAL (symp
);
1089 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1091 if (S_GET_SEGMENT (symp
) == text_section
1092 && symp
!= seg_info (text_section
)->sym
)
1093 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1095 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1097 if (SF_GET_PROCESS (symp
))
1099 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1101 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1102 stack_push (block_stack
, (char *) &symp
);
1106 begin
= *(symbolS
**) stack_pop (block_stack
);
1108 as_warn (_("mismatched .eb"));
1110 next_set_end
= begin
;
1113 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1115 union internal_auxent
*auxp
;
1116 coff_last_function
= symp
;
1117 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1118 S_SET_NUMBER_AUXILIARY (symp
, 1);
1119 auxp
= SYM_AUXENT (symp
);
1120 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1121 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1123 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1125 if (coff_last_function
== 0)
1126 as_fatal (_("C_EFCN symbol out of scope"));
1127 SA_SET_SYM_FSIZE (coff_last_function
,
1128 (long) (S_GET_VALUE (symp
)
1129 - S_GET_VALUE (coff_last_function
)));
1130 next_set_end
= coff_last_function
;
1131 coff_last_function
= 0;
1134 if (S_IS_EXTERNAL (symp
))
1135 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1136 else if (SF_GET_LOCAL (symp
))
1139 if (SF_GET_FUNCTION (symp
))
1140 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1145 if (SF_GET_TAG (symp
))
1147 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1148 next_set_end
= last_tagP
;
1151 /* This is pretty horrible, but we have to set *punt correctly in
1152 order to call SA_SET_SYM_ENDNDX correctly. */
1153 if (! symbol_used_in_reloc_p (symp
)
1154 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1155 || (! S_IS_EXTERNAL (symp
)
1156 && ! symbol_get_tc (symp
)->output
1157 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1161 if (set_end
!= (symbolS
*) NULL
1163 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1164 || (S_IS_DEFINED (symp
)
1165 && ! S_IS_COMMON (symp
)
1166 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1168 SA_SET_SYM_ENDNDX (set_end
, symp
);
1172 if (next_set_end
!= NULL
)
1174 if (set_end
!= NULL
)
1175 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1176 S_GET_NAME (set_end
));
1177 set_end
= next_set_end
;
1181 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1182 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1184 if (coff_last_bf
!= NULL
)
1185 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1186 coff_last_bf
= symp
;
1189 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1192 struct line_no
*lptr
;
1195 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1196 for (i
= 0; lptr
; lptr
= lptr
->next
)
1198 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1200 /* We need i entries for line numbers, plus 1 for the first
1201 entry which BFD will override, plus 1 for the last zero
1202 entry (a marker for BFD). */
1203 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1204 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1205 l
[i
+ 1].line_number
= 0;
1206 l
[i
+ 1].u
.sym
= NULL
;
1210 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1218 coff_adjust_section_syms (abfd
, sec
, x
)
1219 bfd
*abfd ATTRIBUTE_UNUSED
;
1221 PTR x ATTRIBUTE_UNUSED
;
1224 segment_info_type
*seginfo
= seg_info (sec
);
1225 int nlnno
, nrelocs
= 0;
1227 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1228 tc-ppc.c. Do not get confused by it. */
1229 if (seginfo
== NULL
)
1232 if (!strcmp (sec
->name
, ".text"))
1233 nlnno
= coff_n_line_nos
;
1237 /* @@ Hope that none of the fixups expand to more than one reloc
1239 fixS
*fixp
= seginfo
->fix_root
;
1242 if (! fixp
->fx_done
)
1244 fixp
= fixp
->fx_next
;
1247 if (bfd_get_section_size_before_reloc (sec
) == 0
1250 && sec
!= text_section
1251 && sec
!= data_section
1252 && sec
!= bss_section
)
1254 secsym
= section_symbol (sec
);
1255 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1256 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1260 coff_frob_file_after_relocs ()
1262 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1266 * implement the .section pseudo op:
1267 * .section name {, "flags"}
1269 * | +--- optional flags: 'b' for bss
1271 * +-- section name 'l' for lib
1275 * 'd' (apparently m88k for data)
1277 * 'r' for read-only data
1278 * 's' for shared data (PE)
1279 * But if the argument is not a quoted string, treat it as a
1280 * subsegment number.
1284 obj_coff_section (ignore
)
1285 int ignore ATTRIBUTE_UNUSED
;
1287 /* Strip out the section name */
1303 section_name
= input_line_pointer
;
1304 c
= get_symbol_end ();
1306 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1307 strcpy (name
, section_name
);
1309 *input_line_pointer
= c
;
1316 if (*input_line_pointer
== ',')
1318 ++input_line_pointer
;
1320 if (*input_line_pointer
!= '"')
1321 exp
= get_absolute_expression ();
1324 ++input_line_pointer
;
1325 while (*input_line_pointer
!= '"'
1326 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1328 switch (*input_line_pointer
)
1330 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1331 case 'n': flags
&=~ SEC_LOAD
; break;
1332 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1333 case 'w': flags
&=~ SEC_READONLY
; break;
1334 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1335 case 'r': flags
|= SEC_READONLY
; break;
1336 case 's': flags
|= SEC_SHARED
; break;
1338 case 'i': /* STYP_INFO */
1339 case 'l': /* STYP_LIB */
1340 case 'o': /* STYP_OVER */
1341 as_warn (_("unsupported section attribute '%c'"),
1342 *input_line_pointer
);
1346 as_warn(_("unknown section attribute '%c'"),
1347 *input_line_pointer
);
1350 ++input_line_pointer
;
1352 if (*input_line_pointer
== '"')
1353 ++input_line_pointer
;
1357 sec
= subseg_new (name
, (subsegT
) exp
);
1359 if (flags
!= SEC_NO_FLAGS
)
1363 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1364 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1367 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1368 as_warn (_("error setting flags for \"%s\": %s"),
1369 bfd_section_name (stdoutput
, sec
),
1370 bfd_errmsg (bfd_get_error ()));
1373 demand_empty_rest_of_line ();
1377 coff_adjust_symtab ()
1379 if (symbol_rootP
== NULL
1380 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1381 c_dot_file_symbol ("fake");
1385 coff_frob_section (sec
)
1391 bfd_vma size
, n_entries
, mask
;
1393 /* The COFF back end in BFD requires that all section sizes be
1394 rounded up to multiples of the corresponding section alignments.
1395 Seems kinda silly to me, but that's the way it is. */
1396 size
= bfd_get_section_size_before_reloc (sec
);
1397 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1400 size
= (size
+ mask
) & ~mask
;
1401 bfd_set_section_size (stdoutput
, sec
, size
);
1404 /* If the section size is non-zero, the section symbol needs an aux
1405 entry associated with it, indicating the size. We don't know
1406 all the values yet; coff_frob_symbol will fill them in later. */
1408 || sec
== text_section
1409 || sec
== data_section
1410 || sec
== bss_section
)
1412 symbolS
*secsym
= section_symbol (sec
);
1414 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1415 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1416 SF_SET_STATICS (secsym
);
1417 SA_SET_SCN_SCNLEN (secsym
, size
);
1420 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1421 #ifndef STAB_SECTION_NAME
1422 #define STAB_SECTION_NAME ".stab"
1424 #ifndef STAB_STRING_SECTION_NAME
1425 #define STAB_STRING_SECTION_NAME ".stabstr"
1427 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1431 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1432 /* size is already rounded up, since other section will be listed first */
1433 size
= bfd_get_section_size_before_reloc (strsec
);
1435 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1437 /* Find first non-empty frag. It should be large enough. */
1438 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1439 while (fragp
&& fragp
->fr_fix
== 0)
1440 fragp
= fragp
->fr_next
;
1441 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1443 /* Store the values. */
1444 p
= fragp
->fr_literal
;
1445 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1446 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1450 obj_coff_init_stab_section (seg
)
1456 unsigned int stroff
;
1458 /* Make space for this first symbol. */
1462 as_where (&file
, (unsigned int *) NULL
);
1463 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1464 strcpy (stabstr_name
, seg
->name
);
1465 strcat (stabstr_name
, "str");
1466 stroff
= get_stab_string_offset (file
, stabstr_name
);
1468 md_number_to_chars (p
, stroff
, 4);
1477 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1485 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1487 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1488 (unsigned long) symbolP
,
1489 S_GET_NAME(symbolP
),
1490 (long) S_GET_DATA_TYPE(symbolP
),
1491 S_GET_STORAGE_CLASS(symbolP
),
1492 (int) S_GET_SEGMENT(symbolP
));
1498 #else /* not BFD_ASSEMBLER */
1501 /* This is needed because we include internal bfd things. */
1505 #include "libcoff.h"
1508 #include "coff/pe.h"
1511 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1512 that we can stick sections together without causing trouble. */
1514 #define NOP_OPCODE 0x00
1517 /* The zeroes if symbol name is longer than 8 chars */
1518 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1520 #define MIN(a,b) ((a) < (b)? (a) : (b))
1522 /* This vector is used to turn a gas internal segment number into a
1523 section number suitable for insertion into a coff symbol table.
1524 This must correspond to seg_info_off_by_4. */
1526 const short seg_N_TYPE
[] =
1527 { /* in: segT out: N_TYPE bits */
1529 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1530 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1531 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1532 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1533 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1534 C_UNDEF_SECTION
, /* SEG_GOOF */
1535 C_UNDEF_SECTION
, /* SEG_EXPR */
1536 C_DEBUG_SECTION
, /* SEG_DEBUG */
1537 C_NTV_SECTION
, /* SEG_NTV */
1538 C_PTV_SECTION
, /* SEG_PTV */
1539 C_REGISTER_SECTION
, /* SEG_REGISTER */
1542 int function_lineoff
= -1; /* Offset in line#s where the last function
1543 started (the odd entry for line #0) */
1545 /* structure used to keep the filenames which
1546 are too long around so that we can stick them
1547 into the string table */
1548 struct filename_list
1551 struct filename_list
*next
;
1554 static struct filename_list
*filename_list_head
;
1555 static struct filename_list
*filename_list_tail
;
1557 static symbolS
*last_line_symbol
;
1559 /* Add 4 to the real value to get the index and compensate the
1560 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1561 section number into a segment number
1563 static symbolS
*previous_file_symbol
;
1564 void c_symbol_merge ();
1565 static int line_base
;
1567 symbolS
*c_section_symbol ();
1570 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1571 segT this_segment_type
));
1574 static void fixup_mdeps
PARAMS ((fragS
*,
1579 static void fill_section
PARAMS ((bfd
* abfd
,
1584 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1589 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1590 symbolS
* symbol_rootP
));
1592 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1594 static void obj_coff_lcomm
PARAMS ((int));
1595 static void obj_coff_text
PARAMS ((int));
1596 static void obj_coff_data
PARAMS ((int));
1597 static void obj_coff_ident
PARAMS ((int));
1598 void obj_coff_section
PARAMS ((int));
1600 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1602 This array maps a COFF section number into a gas section number.
1603 Because COFF uses negative section numbers, you must add 4 to the
1604 COFF section number when indexing into this array; this is done via
1605 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1608 static const segT seg_info_off_by_4
[] =
1615 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1616 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1617 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1618 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1619 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1620 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1621 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1622 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1635 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1637 static relax_addressT
1638 relax_align (address
, alignment
)
1639 relax_addressT address
;
1642 relax_addressT mask
;
1643 relax_addressT new_address
;
1645 mask
= ~((~0) << alignment
);
1646 new_address
= (address
+ mask
) & (~mask
);
1647 return (new_address
- address
);
1655 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1658 /* calculate the size of the frag chain and fill in the section header
1659 to contain all of it, also fill in the addr of the sections */
1661 size_section (abfd
, idx
)
1662 bfd
*abfd ATTRIBUTE_UNUSED
;
1666 unsigned int size
= 0;
1667 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1670 size
= frag
->fr_address
;
1671 if (frag
->fr_address
!= size
)
1673 fprintf (stderr
, _("Out of step\n"));
1674 size
= frag
->fr_address
;
1677 switch (frag
->fr_type
)
1679 #ifdef TC_COFF_SIZEMACHDEP
1680 case rs_machine_dependent
:
1681 size
+= TC_COFF_SIZEMACHDEP (frag
);
1685 assert (frag
->fr_symbol
== 0);
1688 size
+= frag
->fr_fix
;
1689 size
+= frag
->fr_offset
* frag
->fr_var
;
1696 size
+= frag
->fr_fix
;
1697 off
= relax_align (size
, frag
->fr_offset
);
1698 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1704 BAD_CASE (frag
->fr_type
);
1707 frag
= frag
->fr_next
;
1709 segment_info
[idx
].scnhdr
.s_size
= size
;
1715 count_entries_in_chain (idx
)
1718 unsigned int nrelocs
;
1721 /* Count the relocations */
1722 fixup_ptr
= segment_info
[idx
].fix_root
;
1724 while (fixup_ptr
!= (fixS
*) NULL
)
1726 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1729 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1738 fixup_ptr
= fixup_ptr
->fx_next
;
1745 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1747 /* AUX's ld expects relocations to be sorted */
1749 compare_external_relocs (x
, y
)
1753 struct external_reloc
*a
= (struct external_reloc
*) x
;
1754 struct external_reloc
*b
= (struct external_reloc
*) y
;
1755 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1756 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1757 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1762 /* output all the relocations for a section */
1764 do_relocs_for (abfd
, h
, file_cursor
)
1767 unsigned long *file_cursor
;
1769 unsigned int nrelocs
;
1771 unsigned long reloc_start
= *file_cursor
;
1773 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1775 if (segment_info
[idx
].scnhdr
.s_name
[0])
1777 struct external_reloc
*ext_ptr
;
1778 struct external_reloc
*external_reloc_vec
;
1779 unsigned int external_reloc_size
;
1780 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1781 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1782 nrelocs
= count_entries_in_chain (idx
);
1785 /* Bypass this stuff if no relocs. This also incidentally
1786 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1788 external_reloc_size
= nrelocs
* RELSZ
;
1789 external_reloc_vec
=
1790 (struct external_reloc
*) malloc (external_reloc_size
);
1792 ext_ptr
= external_reloc_vec
;
1794 /* Fill in the internal coff style reloc struct from the
1795 internal fix list. */
1798 struct internal_reloc intr
;
1800 /* Only output some of the relocations */
1801 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1803 #ifdef TC_RELOC_MANGLE
1804 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1809 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1811 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1813 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1815 #ifdef TC_KEEP_FX_OFFSET
1816 intr
.r_offset
= fix_ptr
->fx_offset
;
1821 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1822 && (! S_IS_DEFINED (symbol_ptr
)
1823 || S_IS_COMMON (symbol_ptr
)))
1827 /* We must avoid looping, as that can occur
1828 with a badly written program. */
1829 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1830 if (n
== symbol_ptr
)
1835 /* Turn the segment of the symbol into an offset. */
1838 resolve_symbol_value (symbol_ptr
, 1);
1839 if (! symbol_ptr
->sy_resolved
)
1844 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1845 as_bad_where (file
, line
,
1846 _("unresolved relocation"));
1848 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1849 S_GET_NAME (symbol_ptr
));
1851 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1854 intr
.r_symndx
= dot
->sy_number
;
1858 intr
.r_symndx
= symbol_ptr
->sy_number
;
1868 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1871 #if defined(TC_A29K)
1873 /* The 29k has a special kludge for the high 16 bit
1874 reloc. Two relocations are emited, R_IHIHALF,
1875 and R_IHCONST. The second one doesn't contain a
1876 symbol, but uses the value for offset. */
1878 if (intr
.r_type
== R_IHIHALF
)
1880 /* now emit the second bit */
1881 intr
.r_type
= R_IHCONST
;
1882 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1883 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1889 fix_ptr
= fix_ptr
->fx_next
;
1893 /* Sort the reloc table */
1894 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1895 sizeof (struct external_reloc
), compare_external_relocs
);
1898 /* Write out the reloc table */
1899 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1901 free (external_reloc_vec
);
1903 /* Fill in section header info. */
1904 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1905 *file_cursor
+= external_reloc_size
;
1906 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1911 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1915 /* Set relocation_size field in file headers */
1916 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1920 /* run through a frag chain and write out the data to go with it, fill
1921 in the scnhdrs with the info on the file postions
1924 fill_section (abfd
, h
, file_cursor
)
1926 object_headers
*h ATTRIBUTE_UNUSED
;
1927 unsigned long *file_cursor
;
1931 unsigned int paddr
= 0;
1933 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1935 unsigned int offset
= 0;
1936 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1942 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1949 buffer
= xmalloc (s
->s_size
);
1950 s
->s_scnptr
= *file_cursor
;
1952 know (s
->s_paddr
== paddr
);
1954 if (strcmp (s
->s_name
, ".text") == 0)
1955 s
->s_flags
|= STYP_TEXT
;
1956 else if (strcmp (s
->s_name
, ".data") == 0)
1957 s
->s_flags
|= STYP_DATA
;
1958 else if (strcmp (s
->s_name
, ".bss") == 0)
1961 s
->s_flags
|= STYP_BSS
;
1963 /* @@ Should make the i386 and a29k coff targets define
1964 COFF_NOLOAD_PROBLEM, and have only one test here. */
1967 #ifndef COFF_NOLOAD_PROBLEM
1968 /* Apparently the SVR3 linker (and exec syscall) and UDI
1969 mondfe progrem are confused by noload sections. */
1970 s
->s_flags
|= STYP_NOLOAD
;
1975 else if (strcmp (s
->s_name
, ".lit") == 0)
1976 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1977 else if (strcmp (s
->s_name
, ".init") == 0)
1978 s
->s_flags
|= STYP_TEXT
;
1979 else if (strcmp (s
->s_name
, ".fini") == 0)
1980 s
->s_flags
|= STYP_TEXT
;
1981 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1982 s
->s_flags
|= STYP_INFO
;
1986 unsigned int fill_size
;
1987 switch (frag
->fr_type
)
1989 case rs_machine_dependent
:
1992 memcpy (buffer
+ frag
->fr_address
,
1994 (unsigned int) frag
->fr_fix
);
1995 offset
+= frag
->fr_fix
;
2000 assert (frag
->fr_symbol
== 0);
2007 memcpy (buffer
+ frag
->fr_address
,
2009 (unsigned int) frag
->fr_fix
);
2010 offset
+= frag
->fr_fix
;
2013 fill_size
= frag
->fr_var
;
2014 if (fill_size
&& frag
->fr_offset
> 0)
2017 unsigned int off
= frag
->fr_fix
;
2018 for (count
= frag
->fr_offset
; count
; count
--)
2020 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2022 memcpy (buffer
+ frag
->fr_address
+ off
,
2023 frag
->fr_literal
+ frag
->fr_fix
,
2026 offset
+= fill_size
;
2031 case rs_broken_word
:
2036 frag
= frag
->fr_next
;
2041 if (s
->s_scnptr
!= 0)
2043 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2044 *file_cursor
+= s
->s_size
;
2053 /* Coff file generation & utilities */
2056 coff_header_append (abfd
, h
)
2063 #ifdef COFF_LONG_SECTION_NAMES
2064 unsigned long string_size
= 4;
2067 bfd_seek (abfd
, 0, 0);
2069 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2070 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2071 H_SET_VERSION_STAMP (h
, 0);
2072 H_SET_ENTRY_POINT (h
, 0);
2073 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2074 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2075 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2077 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2078 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2079 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2081 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2083 bfd_write (buffer
, i
, 1, abfd
);
2084 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2086 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2088 if (segment_info
[i
].scnhdr
.s_name
[0])
2092 #ifdef COFF_LONG_SECTION_NAMES
2093 /* Support long section names as found in PE. This code
2094 must coordinate with that in write_object_file and
2096 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2098 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2099 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2100 string_size
+= strlen (segment_info
[i
].name
) + 1;
2104 size
= bfd_coff_swap_scnhdr_out (abfd
,
2105 &(segment_info
[i
].scnhdr
),
2108 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2109 bfd_write (buffer
, size
, 1, abfd
);
2116 symbol_to_chars (abfd
, where
, symbolP
)
2121 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2125 /* Turn any symbols with register attributes into abs symbols */
2126 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2128 S_SET_SEGMENT (symbolP
, absolute_section
);
2130 /* At the same time, relocate all symbols to their output value */
2133 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2134 + S_GET_VALUE (symbolP
));
2136 val
= S_GET_VALUE (symbolP
);
2139 S_SET_VALUE (symbolP
, val
);
2141 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2143 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2146 for (i
= 0; i
< numaux
; i
++)
2148 where
+= bfd_coff_swap_aux_out (abfd
,
2149 &symbolP
->sy_symbol
.ost_auxent
[i
],
2150 S_GET_DATA_TYPE (symbolP
),
2151 S_GET_STORAGE_CLASS (symbolP
),
2159 coff_obj_symbol_new_hook (symbolP
)
2162 char underscore
= 0; /* Symbol has leading _ */
2164 /* Effective symbol */
2165 /* Store the pointer in the offset. */
2166 S_SET_ZEROES (symbolP
, 0L);
2167 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2168 S_SET_STORAGE_CLASS (symbolP
, 0);
2169 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2170 /* Additional information */
2171 symbolP
->sy_symbol
.ost_flags
= 0;
2172 /* Auxiliary entries */
2173 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2175 if (S_IS_STRING (symbolP
))
2176 SF_SET_STRING (symbolP
);
2177 if (!underscore
&& S_IS_LOCAL (symbolP
))
2178 SF_SET_LOCAL (symbolP
);
2182 * Handle .ln directives.
2186 obj_coff_ln (appline
)
2191 if (! appline
&& def_symbol_in_progress
!= NULL
)
2193 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2194 demand_empty_rest_of_line ();
2196 } /* wrong context */
2198 l
= get_absolute_expression ();
2199 c_line_new (0, frag_now_fix (), l
, frag_now
);
2202 new_logical_line ((char *) NULL
, l
- 1);
2212 listing_source_line ((unsigned int) l
);
2217 demand_empty_rest_of_line ();
2223 * Handle .def directives.
2225 * One might ask : why can't we symbol_new if the symbol does not
2226 * already exist and fill it with debug information. Because of
2227 * the C_EFCN special symbol. It would clobber the value of the
2228 * function symbol before we have a chance to notice that it is
2229 * a C_EFCN. And a second reason is that the code is more clear this
2230 * way. (at least I think it is :-).
2234 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2235 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2236 *input_line_pointer == '\t') \
2237 input_line_pointer++;
2241 int what ATTRIBUTE_UNUSED
;
2243 char name_end
; /* Char after the end of name */
2244 char *symbol_name
; /* Name of the debug symbol */
2245 char *symbol_name_copy
; /* Temporary copy of the name */
2246 unsigned int symbol_name_length
;
2248 if (def_symbol_in_progress
!= NULL
)
2250 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2251 demand_empty_rest_of_line ();
2253 } /* if not inside .def/.endef */
2255 SKIP_WHITESPACES ();
2257 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2258 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2260 symbol_name
= input_line_pointer
;
2261 name_end
= get_symbol_end ();
2262 symbol_name_length
= strlen (symbol_name
);
2263 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2264 strcpy (symbol_name_copy
, symbol_name
);
2265 #ifdef tc_canonicalize_symbol_name
2266 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2269 /* Initialize the new symbol */
2270 #ifdef STRIP_UNDERSCORE
2271 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2272 ? symbol_name_copy
+ 1
2273 : symbol_name_copy
));
2274 #else /* STRIP_UNDERSCORE */
2275 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2276 #endif /* STRIP_UNDERSCORE */
2277 /* free(symbol_name_copy); */
2278 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2279 def_symbol_in_progress
->sy_number
= ~0;
2280 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2281 S_SET_VALUE (def_symbol_in_progress
, 0);
2283 if (S_IS_STRING (def_symbol_in_progress
))
2284 SF_SET_STRING (def_symbol_in_progress
);
2286 *input_line_pointer
= name_end
;
2288 demand_empty_rest_of_line ();
2291 unsigned int dim_index
;
2295 obj_coff_endef (ignore
)
2296 int ignore ATTRIBUTE_UNUSED
;
2298 symbolS
*symbolP
= 0;
2299 /* DIM BUG FIX sac@cygnus.com */
2301 if (def_symbol_in_progress
== NULL
)
2303 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2304 demand_empty_rest_of_line ();
2306 } /* if not inside .def/.endef */
2308 /* Set the section number according to storage class. */
2309 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2314 SF_SET_TAG (def_symbol_in_progress
);
2315 /* intentional fallthrough */
2318 SF_SET_DEBUG (def_symbol_in_progress
);
2319 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2323 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2324 /* intentional fallthrough */
2326 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2327 /* intentional fallthrough */
2329 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2331 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2333 if (function_lineoff
< 0)
2335 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2336 } /* missing function symbol */
2337 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2339 SF_SET_PROCESS (last_line_symbol
);
2340 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2341 SF_SET_PROCESS (def_symbol_in_progress
);
2342 function_lineoff
= -1;
2344 /* Value is always set to . */
2345 def_symbol_in_progress
->sy_frag
= frag_now
;
2346 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2351 #endif /* C_AUTOARG */
2361 SF_SET_DEBUG (def_symbol_in_progress
);
2362 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2372 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2378 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2380 } /* switch on storage class */
2382 /* Now that we have built a debug symbol, try to find if we should
2383 merge with an existing symbol or not. If a symbol is C_EFCN or
2384 absolute_section or untagged SEG_DEBUG it never merges. We also
2385 don't merge labels, which are in a different namespace, nor
2386 symbols which have not yet been defined since they are typically
2387 unique, nor do we merge tags with non-tags. */
2389 /* Two cases for functions. Either debug followed by definition or
2390 definition followed by debug. For definition first, we will
2391 merge the debug symbol into the definition. For debug first, the
2392 lineno entry MUST point to the definition function or else it
2393 will point off into space when crawl_symbols() merges the debug
2394 symbol into the real symbol. Therefor, let's presume the debug
2395 symbol is a real function reference. */
2397 /* FIXME-SOON If for some reason the definition label/symbol is
2398 never seen, this will probably leave an undefined symbol at link
2401 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2402 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2403 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2404 && !SF_GET_TAG (def_symbol_in_progress
))
2405 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2406 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2407 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2408 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2410 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2415 /* This symbol already exists, merge the newly created symbol
2416 into the old one. This is not mandatory. The linker can
2417 handle duplicate symbols correctly. But I guess that it save
2418 a *lot* of space if the assembly file defines a lot of
2421 /* The debug entry (def_symbol_in_progress) is merged into the
2422 previous definition. */
2424 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2425 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2426 def_symbol_in_progress
= symbolP
;
2428 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2429 || SF_GET_TAG (def_symbol_in_progress
)
2430 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2432 /* For functions, and tags, and static symbols, the symbol
2433 *must* be where the debug symbol appears. Move the
2434 existing symbol to the current place. */
2435 /* If it already is at the end of the symbol list, do nothing */
2436 if (def_symbol_in_progress
!= symbol_lastP
)
2438 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2440 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2441 &symbol_rootP
, &symbol_lastP
);
2442 } /* if not already in place */
2444 } /* normal or mergable */
2446 if (SF_GET_TAG (def_symbol_in_progress
))
2450 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2452 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2453 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2454 def_symbol_in_progress
);
2457 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2459 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2461 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2463 SF_SET_PROCESS (def_symbol_in_progress
);
2465 if (symbolP
== NULL
)
2467 /* That is, if this is the first time we've seen the
2469 symbol_table_insert (def_symbol_in_progress
);
2470 } /* definition follows debug */
2471 } /* Create the line number entry pointing to the function being defined */
2473 def_symbol_in_progress
= NULL
;
2474 demand_empty_rest_of_line ();
2478 obj_coff_dim (ignore
)
2479 int ignore ATTRIBUTE_UNUSED
;
2483 if (def_symbol_in_progress
== NULL
)
2485 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2486 demand_empty_rest_of_line ();
2488 } /* if not inside .def/.endef */
2490 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2492 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2494 SKIP_WHITESPACES ();
2495 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2496 get_absolute_expression ());
2498 switch (*input_line_pointer
)
2501 input_line_pointer
++;
2505 as_warn (_("badly formed .dim directive ignored"));
2506 /* intentional fallthrough */
2514 demand_empty_rest_of_line ();
2518 obj_coff_line (ignore
)
2519 int ignore ATTRIBUTE_UNUSED
;
2524 if (def_symbol_in_progress
== NULL
)
2530 name
= S_GET_NAME (def_symbol_in_progress
);
2531 this_base
= get_absolute_expression ();
2533 /* Only .bf symbols indicate the use of a new base line number; the
2534 line numbers associated with .ef, .bb, .eb are relative to the
2535 start of the containing function. */
2536 if (!strcmp (".bf", name
))
2538 #if 0 /* XXX Can we ever have line numbers going backwards? */
2539 if (this_base
> line_base
)
2542 line_base
= this_base
;
2550 listing_source_line ((unsigned int) line_base
);
2556 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2557 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2559 demand_empty_rest_of_line ();
2563 obj_coff_size (ignore
)
2564 int ignore ATTRIBUTE_UNUSED
;
2566 if (def_symbol_in_progress
== NULL
)
2568 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2569 demand_empty_rest_of_line ();
2571 } /* if not inside .def/.endef */
2573 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2574 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2575 demand_empty_rest_of_line ();
2579 obj_coff_scl (ignore
)
2580 int ignore ATTRIBUTE_UNUSED
;
2582 if (def_symbol_in_progress
== NULL
)
2584 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2585 demand_empty_rest_of_line ();
2587 } /* if not inside .def/.endef */
2589 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2590 demand_empty_rest_of_line ();
2594 obj_coff_tag (ignore
)
2595 int ignore ATTRIBUTE_UNUSED
;
2600 if (def_symbol_in_progress
== NULL
)
2602 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2603 demand_empty_rest_of_line ();
2607 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2608 symbol_name
= input_line_pointer
;
2609 name_end
= get_symbol_end ();
2610 #ifdef tc_canonicalize_symbol_name
2611 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2614 /* Assume that the symbol referred to by .tag is always defined.
2615 This was a bad assumption. I've added find_or_make. xoxorich. */
2616 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2617 (long) tag_find_or_make (symbol_name
));
2618 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2620 as_warn (_("tag not found for .tag %s"), symbol_name
);
2623 SF_SET_TAGGED (def_symbol_in_progress
);
2624 *input_line_pointer
= name_end
;
2626 demand_empty_rest_of_line ();
2630 obj_coff_type (ignore
)
2631 int ignore ATTRIBUTE_UNUSED
;
2633 if (def_symbol_in_progress
== NULL
)
2635 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2636 demand_empty_rest_of_line ();
2638 } /* if not inside .def/.endef */
2640 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2642 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2643 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2645 SF_SET_FUNCTION (def_symbol_in_progress
);
2646 } /* is a function */
2648 demand_empty_rest_of_line ();
2652 obj_coff_val (ignore
)
2653 int ignore ATTRIBUTE_UNUSED
;
2655 if (def_symbol_in_progress
== NULL
)
2657 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2658 demand_empty_rest_of_line ();
2660 } /* if not inside .def/.endef */
2662 if (is_name_beginner (*input_line_pointer
))
2664 char *symbol_name
= input_line_pointer
;
2665 char name_end
= get_symbol_end ();
2667 #ifdef tc_canonicalize_symbol_name
2668 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2671 if (!strcmp (symbol_name
, "."))
2673 def_symbol_in_progress
->sy_frag
= frag_now
;
2674 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2675 /* If the .val is != from the .def (e.g. statics) */
2677 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2679 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2680 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2681 symbol_find_or_make (symbol_name
);
2682 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2683 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2685 /* If the segment is undefined when the forward reference is
2686 resolved, then copy the segment id from the forward
2688 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2690 /* FIXME: gcc can generate address expressions here in
2691 unusual cases (search for "obscure" in sdbout.c). We
2692 just ignore the offset here, thus generating incorrect
2693 debugging information. We ignore the rest of the line
2696 /* Otherwise, it is the name of a non debug symbol and
2697 its value will be calculated later. */
2698 *input_line_pointer
= name_end
;
2700 /* FIXME: this is to avoid an error message in the
2701 FIXME case mentioned just above. */
2702 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2703 ++input_line_pointer
;
2707 S_SET_VALUE (def_symbol_in_progress
,
2708 (valueT
) get_absolute_expression ());
2709 } /* if symbol based */
2711 demand_empty_rest_of_line ();
2716 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2717 read.c, which then calls this object file format specific routine. */
2720 obj_coff_pe_handle_link_once (type
)
2721 enum linkonce_type type
;
2723 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2725 /* We store the type in the seg_info structure, and use it to set up
2726 the auxiliary entry for the section symbol in c_section_symbol. */
2727 seg_info (now_seg
)->linkonce
= type
;
2733 coff_obj_read_begin_hook ()
2735 /* These had better be the same. Usually 18 bytes. */
2737 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2738 know (SYMESZ
== AUXESZ
);
2743 /* This function runs through the symbol table and puts all the
2744 externals onto another chain */
2746 /* The chain of globals. */
2747 symbolS
*symbol_globalP
;
2748 symbolS
*symbol_global_lastP
;
2750 /* The chain of externals */
2751 symbolS
*symbol_externP
;
2752 symbolS
*symbol_extern_lastP
;
2755 symbolS
*last_functionP
;
2756 static symbolS
*last_bfP
;
2763 unsigned int symbol_number
= 0;
2764 unsigned int last_file_symno
= 0;
2766 struct filename_list
*filename_list_scan
= filename_list_head
;
2768 for (symbolP
= symbol_rootP
;
2770 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2772 if (symbolP
->sy_mri_common
)
2774 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2776 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2778 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2779 as_bad (_("%s: global symbols not supported in common sections"),
2780 S_GET_NAME (symbolP
));
2781 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2785 if (!SF_GET_DEBUG (symbolP
))
2787 /* Debug symbols do not need all this rubbish */
2788 symbolS
*real_symbolP
;
2790 /* L* and C_EFCN symbols never merge. */
2791 if (!SF_GET_LOCAL (symbolP
)
2792 && !SF_GET_STATICS (symbolP
)
2793 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2794 && symbolP
->sy_value
.X_op
== O_constant
2795 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2796 && real_symbolP
!= symbolP
)
2798 /* FIXME-SOON: where do dups come from?
2799 Maybe tag references before definitions? xoxorich. */
2800 /* Move the debug data from the debug symbol to the
2801 real symbol. Do NOT do the oposite (i.e. move from
2802 real symbol to debug symbol and remove real symbol from the
2803 list.) Because some pointers refer to the real symbol
2804 whereas no pointers refer to the debug symbol. */
2805 c_symbol_merge (symbolP
, real_symbolP
);
2806 /* Replace the current symbol by the real one */
2807 /* The symbols will never be the last or the first
2808 because : 1st symbol is .file and 3 last symbols are
2809 .text, .data, .bss */
2810 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2811 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2812 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2813 symbolP
= real_symbolP
;
2814 } /* if not local but dup'd */
2816 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2818 S_SET_SEGMENT (symbolP
, SEG_E0
);
2819 } /* push data into text */
2821 resolve_symbol_value (symbolP
, 1);
2823 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2825 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2827 S_SET_EXTERNAL (symbolP
);
2829 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2831 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2835 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2839 /* Mainly to speed up if not -g */
2840 if (SF_GET_PROCESS (symbolP
))
2842 /* Handle the nested blocks auxiliary info. */
2843 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2845 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2846 stack_push (block_stack
, (char *) &symbolP
);
2849 register symbolS
*begin_symbolP
;
2850 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2851 if (begin_symbolP
== (symbolS
*) 0)
2852 as_warn (_("mismatched .eb"));
2854 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2857 /* If we are able to identify the type of a function, and we
2858 are out of a function (last_functionP == 0) then, the
2859 function symbol will be associated with an auxiliary
2861 if (last_functionP
== (symbolS
*) 0 &&
2862 SF_GET_FUNCTION (symbolP
))
2864 last_functionP
= symbolP
;
2866 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2868 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2869 } /* make it at least 1 */
2871 /* Clobber possible stale .dim information. */
2873 /* Iffed out by steve - this fries the lnnoptr info too */
2874 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2875 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2878 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2880 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2882 if (last_bfP
!= NULL
)
2883 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2887 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2889 /* I don't even know if this is needed for sdb. But
2890 the standard assembler generates it, so... */
2891 if (last_functionP
== (symbolS
*) 0)
2892 as_fatal (_("C_EFCN symbol out of scope"));
2893 SA_SET_SYM_FSIZE (last_functionP
,
2894 (long) (S_GET_VALUE (symbolP
) -
2895 S_GET_VALUE (last_functionP
)));
2896 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2897 last_functionP
= (symbolS
*) 0;
2901 else if (SF_GET_TAG (symbolP
))
2903 /* First descriptor of a structure must point to
2904 the first slot after the structure description. */
2905 last_tagP
= symbolP
;
2908 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2910 /* +2 take in account the current symbol */
2911 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2913 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2915 /* If the filename was too long to fit in the
2916 auxent, put it in the string table */
2917 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2918 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2920 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2921 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2922 filename_list_scan
= filename_list_scan
->next
;
2924 if (S_GET_VALUE (symbolP
))
2926 S_SET_VALUE (symbolP
, last_file_symno
);
2927 last_file_symno
= symbol_number
;
2928 } /* no one points at the first .file symbol */
2929 } /* if debug or tag or eos or file */
2931 #ifdef tc_frob_coff_symbol
2932 tc_frob_coff_symbol (symbolP
);
2935 /* We must put the external symbols apart. The loader
2936 does not bomb if we do not. But the references in
2937 the endndx field for a .bb symbol are not corrected
2938 if an external symbol is removed between .bb and .be.
2939 I.e in the following case :
2940 [20] .bb endndx = 22
2943 ld will move the symbol 21 to the end of the list but
2944 endndx will still be 22 instead of 21. */
2947 if (SF_GET_LOCAL (symbolP
))
2949 /* remove C_EFCN and LOCAL (L...) symbols */
2950 /* next pointer remains valid */
2951 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2954 else if (symbolP
->sy_value
.X_op
== O_symbol
2955 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2957 /* Skip symbols which were equated to undefined or common
2959 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2961 else if (!S_IS_DEFINED (symbolP
)
2962 && !S_IS_DEBUG (symbolP
)
2963 && !SF_GET_STATICS (symbolP
)
2964 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2966 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2968 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
2970 /* if external, Remove from the list */
2971 symbolS
*hold
= symbol_previous (symbolP
);
2973 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2974 symbol_clear_list_pointers (symbolP
);
2975 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2978 else if (! S_IS_DEBUG (symbolP
)
2979 && ! SF_GET_STATICS (symbolP
)
2980 && ! SF_GET_FUNCTION (symbolP
)
2981 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2983 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2985 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
2987 symbolS
*hold
= symbol_previous (symbolP
);
2989 /* The O'Reilly COFF book says that defined global symbols
2990 come at the end of the symbol table, just before
2991 undefined global symbols. */
2993 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2994 symbol_clear_list_pointers (symbolP
);
2995 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2996 &symbol_global_lastP
);
3001 if (SF_GET_STRING (symbolP
))
3003 symbolP
->sy_name_offset
= string_byte_count
;
3004 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3008 symbolP
->sy_name_offset
= 0;
3009 } /* fix "long" names */
3011 symbolP
->sy_number
= symbol_number
;
3012 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3013 } /* if local symbol */
3014 } /* traverse the symbol list */
3015 return symbol_number
;
3021 glue_symbols (head
, tail
)
3025 unsigned int symbol_number
= 0;
3027 while (*head
!= NULL
)
3029 symbolS
*tmp
= *head
;
3032 symbol_remove (tmp
, head
, tail
);
3033 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3036 if (SF_GET_STRING (tmp
))
3038 tmp
->sy_name_offset
= string_byte_count
;
3039 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3043 tmp
->sy_name_offset
= 0;
3044 } /* fix "long" names */
3046 tmp
->sy_number
= symbol_number
;
3047 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3048 } /* append the entire extern chain */
3050 return symbol_number
;
3056 unsigned int symbol_number
= 0;
3059 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3061 symbolP
->sy_number
= symbol_number
;
3063 if (SF_GET_TAGGED (symbolP
))
3067 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3070 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3073 return symbol_number
;
3077 crawl_symbols (h
, abfd
)
3079 bfd
*abfd ATTRIBUTE_UNUSED
;
3083 /* Initialize the stack used to keep track of the matching .bb .be */
3085 block_stack
= stack_init (512, sizeof (symbolS
*));
3087 /* The symbol list should be ordered according to the following sequence
3090 * . debug entries for functions
3091 * . fake symbols for the sections, including .text .data and .bss
3093 * . undefined symbols
3094 * But this is not mandatory. The only important point is to put the
3095 * undefined symbols at the end of the list.
3098 /* Is there a .file symbol ? If not insert one at the beginning. */
3099 if (symbol_rootP
== NULL
3100 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3102 c_dot_file_symbol ("fake");
3106 * Build up static symbols for the sections, they are filled in later
3110 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3111 if (segment_info
[i
].scnhdr
.s_name
[0])
3112 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3115 /* Take all the externals out and put them into another chain */
3116 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3117 /* Take the externals and glue them onto the end.*/
3118 H_SET_SYMBOL_TABLE_SIZE (h
,
3119 (H_GET_SYMBOL_COUNT (h
)
3120 + glue_symbols (&symbol_globalP
,
3121 &symbol_global_lastP
)
3122 + glue_symbols (&symbol_externP
,
3123 &symbol_extern_lastP
)));
3125 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3126 know (symbol_globalP
== NULL
);
3127 know (symbol_global_lastP
== NULL
);
3128 know (symbol_externP
== NULL
);
3129 know (symbol_extern_lastP
== NULL
);
3133 * Find strings by crawling along symbol table chain.
3141 struct filename_list
*filename_list_scan
= filename_list_head
;
3143 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3144 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3147 #ifdef COFF_LONG_SECTION_NAMES
3148 /* Support long section names as found in PE. This code must
3149 coordinate with that in coff_header_append and write_object_file. */
3153 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3155 if (segment_info
[i
].scnhdr
.s_name
[0]
3156 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3160 size
= strlen (segment_info
[i
].name
) + 1;
3161 memcpy (where
, segment_info
[i
].name
, size
);
3166 #endif /* COFF_LONG_SECTION_NAMES */
3168 for (symbolP
= symbol_rootP
;
3170 symbolP
= symbol_next (symbolP
))
3174 if (SF_GET_STRING (symbolP
))
3176 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3177 memcpy (where
, S_GET_NAME (symbolP
), size
);
3180 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3181 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3182 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3184 size
= strlen (filename_list_scan
->filename
) + 1;
3185 memcpy (where
, filename_list_scan
->filename
, size
);
3186 filename_list_scan
= filename_list_scan
->next
;
3193 do_linenos_for (abfd
, h
, file_cursor
)
3196 unsigned long *file_cursor
;
3199 unsigned long start
= *file_cursor
;
3201 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3203 segment_info_type
*s
= segment_info
+ idx
;
3206 if (s
->scnhdr
.s_nlnno
!= 0)
3208 struct lineno_list
*line_ptr
;
3210 struct external_lineno
*buffer
=
3211 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3213 struct external_lineno
*dst
= buffer
;
3215 /* Run through the table we've built and turn it into its external
3216 form, take this chance to remove duplicates */
3218 for (line_ptr
= s
->lineno_list_head
;
3219 line_ptr
!= (struct lineno_list
*) NULL
;
3220 line_ptr
= line_ptr
->next
)
3223 if (line_ptr
->line
.l_lnno
== 0)
3225 /* Turn a pointer to a symbol into the symbols' index */
3226 line_ptr
->line
.l_addr
.l_symndx
=
3227 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3231 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3235 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3240 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3242 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3245 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3248 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3252 /* Now we run through the list of frag chains in a segment and
3253 make all the subsegment frags appear at the end of the
3254 list, as if the seg 0 was extra long */
3261 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3263 frchainS
*head
= segment_info
[i
].frchainP
;
3265 fragS
*prev_frag
= &dummy
;
3267 while (head
&& head
->frch_seg
== i
)
3269 prev_frag
->fr_next
= head
->frch_root
;
3270 prev_frag
= head
->frch_last
;
3271 head
= head
->frch_next
;
3273 prev_frag
->fr_next
= 0;
3277 unsigned long machine
;
3280 write_object_file ()
3284 struct frchain
*frchain_ptr
;
3286 object_headers headers
;
3287 unsigned long file_cursor
;
3290 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3295 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3296 exit (EXIT_FAILURE
);
3298 bfd_set_format (abfd
, bfd_object
);
3299 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3301 string_byte_count
= 4;
3303 for (frchain_ptr
= frchain_root
;
3304 frchain_ptr
!= (struct frchain
*) NULL
;
3305 frchain_ptr
= frchain_ptr
->frch_next
)
3307 /* Run through all the sub-segments and align them up. Also
3308 close any open frags. We tack a .fill onto the end of the
3309 frag chain so that any .align's size can be worked by looking
3310 at the next frag. */
3312 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3314 #ifndef SUB_SEGMENT_ALIGN
3315 #define SUB_SEGMENT_ALIGN(SEG) 1
3318 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3321 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3322 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3327 frag_wane (frag_now
);
3328 frag_now
->fr_fix
= 0;
3329 know (frag_now
->fr_next
== NULL
);
3336 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3338 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3341 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3343 /* Find out how big the sections are, and set the addresses. */
3345 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3349 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3350 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3352 if (segment_info
[i
].scnhdr
.s_name
[0])
3354 H_SET_NUMBER_OF_SECTIONS (&headers
,
3355 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3357 #ifdef COFF_LONG_SECTION_NAMES
3358 /* Support long section names as found in PE. This code
3359 must coordinate with that in coff_header_append and
3364 len
= strlen (segment_info
[i
].name
);
3366 string_byte_count
+= len
+ 1;
3368 #endif /* COFF_LONG_SECTION_NAMES */
3371 size
= size_section (abfd
, (unsigned int) i
);
3374 /* I think the section alignment is only used on the i960; the
3375 i960 needs it, and it should do no harm on other targets. */
3376 #ifdef ALIGNMENT_IN_S_FLAGS
3377 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3379 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3383 H_SET_TEXT_SIZE (&headers
, size
);
3384 else if (i
== SEG_E1
)
3385 H_SET_DATA_SIZE (&headers
, size
);
3386 else if (i
== SEG_E2
)
3387 H_SET_BSS_SIZE (&headers
, size
);
3390 /* Turn the gas native symbol table shape into a coff symbol table */
3391 crawl_symbols (&headers
, abfd
);
3393 if (string_byte_count
== 4)
3394 string_byte_count
= 0;
3396 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3402 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3404 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3405 fixup_segment (&segment_info
[i
], i
);
3408 /* Look for ".stab" segments and fill in their initial symbols
3410 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3412 name
= segment_info
[i
].name
;
3415 && strncmp (".stab", name
, 5) == 0
3416 && strncmp (".stabstr", name
, 8) != 0)
3417 adjust_stab_section (abfd
, i
);
3420 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3422 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3424 /* Plant the data */
3426 fill_section (abfd
, &headers
, &file_cursor
);
3428 do_relocs_for (abfd
, &headers
, &file_cursor
);
3430 do_linenos_for (abfd
, &headers
, &file_cursor
);
3432 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3433 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3434 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3436 H_SET_TIME_STAMP (&headers
, 0);
3438 #ifdef TC_COFF_SET_MACHINE
3439 TC_COFF_SET_MACHINE (&headers
);
3443 #define COFF_FLAGS 0
3446 #ifdef KEEP_RELOC_INFO
3447 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3448 COFF_FLAGS
| coff_flags
));
3450 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3451 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3452 COFF_FLAGS
| coff_flags
));
3456 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3457 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3459 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3460 w_symbols (abfd
, buffer1
, symbol_rootP
);
3461 if (string_byte_count
> 0)
3462 w_strings (buffer1
+ symtable_size
);
3463 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3467 coff_header_append (abfd
, &headers
);
3469 /* Recent changes to write need this, but where it should
3470 go is up to Ken.. */
3471 if (bfd_close_all_done (abfd
) == false)
3472 as_fatal (_("Can't close %s: %s"), out_file_name
,
3473 bfd_errmsg (bfd_get_error ()));
3476 extern bfd
*stdoutput
;
3483 /* Add a new segment. This is called from subseg_new via the
3484 obj_new_segment macro. */
3487 obj_coff_add_segment (name
)
3492 #ifndef COFF_LONG_SECTION_NAMES
3493 char buf
[SCNNMLEN
+ 1];
3495 strncpy (buf
, name
, SCNNMLEN
);
3496 buf
[SCNNMLEN
] = '\0';
3500 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3501 if (strcmp (name
, segment_info
[i
].name
) == 0)
3506 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3510 /* Add a new section. */
3511 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3512 sizeof (segment_info
[i
].scnhdr
.s_name
));
3513 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3514 segment_info
[i
].name
= xstrdup (name
);
3520 * implement the .section pseudo op:
3521 * .section name {, "flags"}
3523 * | +--- optional flags: 'b' for bss
3525 * +-- section name 'l' for lib
3529 * 'd' (apparently m88k for data)
3531 * 'r' for read-only data
3532 * But if the argument is not a quoted string, treat it as a
3533 * subsegment number.
3537 obj_coff_section (ignore
)
3538 int ignore ATTRIBUTE_UNUSED
;
3540 /* Strip out the section name */
3541 char *section_name
, *name
;
3554 else if (type
== 'D')
3556 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3561 section_name
= input_line_pointer
;
3562 c
= get_symbol_end ();
3564 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3565 strcpy (name
, section_name
);
3567 *input_line_pointer
= c
;
3573 if (*input_line_pointer
== ',')
3575 ++input_line_pointer
;
3578 if (*input_line_pointer
!= '"')
3579 exp
= get_absolute_expression ();
3582 ++input_line_pointer
;
3583 while (*input_line_pointer
!= '"'
3584 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3586 switch (*input_line_pointer
)
3588 case 'b': flags
|= STYP_BSS
; break;
3589 case 'i': flags
|= STYP_INFO
; break;
3590 case 'l': flags
|= STYP_LIB
; break;
3591 case 'n': flags
|= STYP_NOLOAD
; break;
3592 case 'o': flags
|= STYP_OVER
; break;
3594 case 'w': flags
|= STYP_DATA
; break;
3595 case 'x': flags
|= STYP_TEXT
; break;
3596 case 'r': flags
|= STYP_LIT
; break;
3598 as_warn(_("unknown section attribute '%c'"),
3599 *input_line_pointer
);
3602 ++input_line_pointer
;
3604 if (*input_line_pointer
== '"')
3605 ++input_line_pointer
;
3609 subseg_new (name
, (subsegT
) exp
);
3611 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3613 demand_empty_rest_of_line ();
3618 obj_coff_text (ignore
)
3619 int ignore ATTRIBUTE_UNUSED
;
3621 subseg_new (".text", get_absolute_expression ());
3626 obj_coff_data (ignore
)
3627 int ignore ATTRIBUTE_UNUSED
;
3629 if (flag_readonly_data_in_text
)
3630 subseg_new (".text", get_absolute_expression () + 1000);
3632 subseg_new (".data", get_absolute_expression ());
3636 obj_coff_ident (ignore
)
3637 int ignore ATTRIBUTE_UNUSED
;
3639 segT current_seg
= now_seg
; /* save current seg */
3640 subsegT current_subseg
= now_subseg
;
3641 subseg_new (".comment", 0); /* .comment seg */
3642 stringer (1); /* read string */
3643 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3647 c_symbol_merge (debug
, normal
)
3651 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3652 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3654 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3656 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3657 } /* take the most we have */
3659 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3661 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3662 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3663 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3664 } /* Move all the auxiliary information */
3666 /* Move the debug flags. */
3667 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3668 } /* c_symbol_merge() */
3671 c_line_new (symbol
, paddr
, line_number
, frag
)
3677 struct lineno_list
*new_line
=
3678 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3680 segment_info_type
*s
= segment_info
+ now_seg
;
3681 new_line
->line
.l_lnno
= line_number
;
3683 if (line_number
== 0)
3685 last_line_symbol
= symbol
;
3686 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3690 new_line
->line
.l_addr
.l_paddr
= paddr
;
3693 new_line
->frag
= (char *) frag
;
3694 new_line
->next
= (struct lineno_list
*) NULL
;
3697 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3699 s
->lineno_list_head
= new_line
;
3703 s
->lineno_list_tail
->next
= new_line
;
3705 s
->lineno_list_tail
= new_line
;
3706 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3710 c_dot_file_symbol (filename
)
3715 symbolP
= symbol_new (".file",
3718 &zero_address_frag
);
3720 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3721 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3723 if (strlen (filename
) > FILNMLEN
)
3725 /* Filename is too long to fit into an auxent,
3726 we stick it into the string table instead. We keep
3727 a linked list of the filenames we find so we can emit
3729 struct filename_list
*f
= ((struct filename_list
*)
3730 xmalloc (sizeof (struct filename_list
)));
3732 f
->filename
= filename
;
3735 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3736 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3738 if (filename_list_tail
)
3739 filename_list_tail
->next
= f
;
3741 filename_list_head
= f
;
3742 filename_list_tail
= f
;
3746 SA_SET_FILE_FNAME (symbolP
, filename
);
3753 listing_source_file (filename
);
3759 SF_SET_DEBUG (symbolP
);
3760 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3762 previous_file_symbol
= symbolP
;
3764 /* Make sure that the symbol is first on the symbol chain */
3765 if (symbol_rootP
!= symbolP
)
3767 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3768 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3770 } /* c_dot_file_symbol() */
3773 * Build a 'section static' symbol.
3777 c_section_symbol (name
, idx
)
3783 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3784 if (symbolP
== NULL
)
3785 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3788 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3789 S_SET_SEGMENT (symbolP
, idx
);
3790 symbolP
->sy_frag
= &zero_address_frag
;
3793 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3794 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3796 SF_SET_STATICS (symbolP
);
3799 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3800 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3801 SF_CLEAR_LOCAL (symbolP
);
3804 /* If the .linkonce pseudo-op was used for this section, we must
3805 store the information in the auxiliary entry for the section
3807 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3811 switch (segment_info
[idx
].linkonce
)
3815 case LINKONCE_DISCARD
:
3816 type
= IMAGE_COMDAT_SELECT_ANY
;
3818 case LINKONCE_ONE_ONLY
:
3819 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3821 case LINKONCE_SAME_SIZE
:
3822 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3824 case LINKONCE_SAME_CONTENTS
:
3825 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3829 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3834 } /* c_section_symbol() */
3837 w_symbols (abfd
, where
, symbol_rootP
)
3840 symbolS
* symbol_rootP
;
3845 /* First fill in those values we have only just worked out */
3846 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3848 symbolP
= segment_info
[i
].dot
;
3851 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3852 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3853 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3858 * Emit all symbols left in the symbol chain.
3860 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3862 /* Used to save the offset of the name. It is used to point
3863 to the string in memory but must be a file offset. */
3864 register char *temp
;
3866 /* We can't fix the lnnoptr field in yank_symbols with the other
3867 adjustments, because we have to wait until we know where they
3869 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3871 SA_GET_SYM_LNNOPTR (symbolP
) +=
3872 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3875 tc_coff_symbol_emit_hook (symbolP
);
3877 temp
= S_GET_NAME (symbolP
);
3878 if (SF_GET_STRING (symbolP
))
3880 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3881 S_SET_ZEROES (symbolP
, 0);
3885 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3886 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3888 where
= symbol_to_chars (abfd
, where
, symbolP
);
3889 S_SET_NAME (symbolP
, temp
);
3895 obj_coff_lcomm (ignore
)
3896 int ignore ATTRIBUTE_UNUSED
;
3908 name
= input_line_pointer
;
3910 c
= get_symbol_end ();
3911 p
= input_line_pointer
;
3914 if (*input_line_pointer
!= ',')
3916 as_bad (_("Expected comma after name"));
3917 ignore_rest_of_line ();
3920 if (*input_line_pointer
== '\n')
3922 as_bad (_("Missing size expression"));
3925 input_line_pointer
++;
3926 if ((temp
= get_absolute_expression ()) < 0)
3928 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3929 ignore_rest_of_line ();
3934 symbolP
= symbol_find_or_make(name
);
3936 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3937 S_GET_VALUE(symbolP
) == 0)
3942 segT current_seg
= now_seg
; /* save current seg */
3943 subsegT current_subseg
= now_subseg
;
3945 subseg_set (SEG_E2
, 1);
3946 symbolP
->sy_frag
= frag_now
;
3947 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3948 (offsetT
) temp
, (char *) 0);
3950 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3951 S_SET_SEGMENT(symbolP
, SEG_E2
);
3952 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3956 as_bad(_("Symbol %s already defined"), name
);
3958 demand_empty_rest_of_line();
3963 fixup_mdeps (frags
, h
, this_segment
)
3968 subseg_change (this_segment
, 0);
3971 switch (frags
->fr_type
)
3977 HANDLE_ALIGN (frags
);
3979 frags
->fr_type
= rs_fill
;
3981 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3984 case rs_machine_dependent
:
3985 md_convert_frag (h
, this_segment
, frags
);
3991 frags
= frags
->fr_next
;
3997 #ifndef TC_FORCE_RELOCATION
3998 #define TC_FORCE_RELOCATION(fix) 0
4002 fixup_segment (segP
, this_segment_type
)
4003 segment_info_type
* segP
;
4004 segT this_segment_type
;
4006 register fixS
* fixP
;
4007 register symbolS
*add_symbolP
;
4008 register symbolS
*sub_symbolP
;
4011 register char *place
;
4012 register long where
;
4013 register char pcrel
;
4014 register fragS
*fragP
;
4015 register segT add_symbol_segment
= absolute_section
;
4017 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4019 fragP
= fixP
->fx_frag
;
4021 where
= fixP
->fx_where
;
4022 place
= fragP
->fr_literal
+ where
;
4023 size
= fixP
->fx_size
;
4024 add_symbolP
= fixP
->fx_addsy
;
4025 sub_symbolP
= fixP
->fx_subsy
;
4026 add_number
= fixP
->fx_offset
;
4027 pcrel
= fixP
->fx_pcrel
;
4029 /* We want function-relative stabs to work on systems which
4030 may use a relaxing linker; thus we must handle the sym1-sym2
4031 fixups function-relative stabs generates.
4033 Of course, if you actually enable relaxing in the linker, the
4034 line and block scoping information is going to be incorrect
4035 in some cases. The only way to really fix this is to support
4036 a reloc involving the difference of two symbols. */
4038 && (!sub_symbolP
|| pcrel
))
4042 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4044 /* Relocation should be done via the associated 'bal' entry
4047 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4049 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4050 _("No 'bal' entry point for leafproc %s"),
4051 S_GET_NAME (add_symbolP
));
4054 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4058 /* Make sure the symbols have been resolved; this may not have
4059 happened if these are expression symbols. */
4060 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4061 resolve_symbol_value (add_symbolP
, 1);
4063 if (add_symbolP
!= NULL
)
4065 /* If this fixup is against a symbol which has been equated
4066 to another symbol, convert it to the other symbol. */
4067 if (add_symbolP
->sy_value
.X_op
== O_symbol
4068 && (! S_IS_DEFINED (add_symbolP
)
4069 || S_IS_COMMON (add_symbolP
)))
4071 while (add_symbolP
->sy_value
.X_op
== O_symbol
4072 && (! S_IS_DEFINED (add_symbolP
)
4073 || S_IS_COMMON (add_symbolP
)))
4077 /* We must avoid looping, as that can occur with a
4078 badly written program. */
4079 n
= add_symbolP
->sy_value
.X_add_symbol
;
4080 if (n
== add_symbolP
)
4082 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4085 fixP
->fx_addsy
= add_symbolP
;
4086 fixP
->fx_offset
= add_number
;
4090 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4091 resolve_symbol_value (sub_symbolP
, 1);
4093 if (add_symbolP
!= NULL
4094 && add_symbolP
->sy_mri_common
)
4096 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4097 add_number
+= S_GET_VALUE (add_symbolP
);
4098 fixP
->fx_offset
= add_number
;
4099 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4104 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4105 } /* if there is an addend */
4109 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4111 if (add_symbolP
!= NULL
)
4113 add_number
+= S_GET_VALUE (add_symbolP
);
4115 fixP
->fx_addsy
= NULL
;
4118 /* It's just -sym. */
4119 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4121 add_number
-= S_GET_VALUE (sub_symbolP
);
4128 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4129 _("Negative of non-absolute symbol %s"),
4130 S_GET_NAME (sub_symbolP
));
4132 add_number
-= S_GET_VALUE (sub_symbolP
);
4133 } /* not absolute */
4135 /* if sub_symbol is in the same segment that add_symbol
4136 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4138 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4139 && SEG_NORMAL (add_symbol_segment
))
4141 /* Difference of 2 symbols from same segment. Can't
4142 make difference of 2 undefineds: 'value' means
4143 something different for N_UNDF. */
4145 /* Makes no sense to use the difference of 2 arbitrary symbols
4146 as the target of a call instruction. */
4149 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4150 _("callj to difference of 2 symbols"));
4152 #endif /* TC_I960 */
4153 add_number
+= S_GET_VALUE (add_symbolP
) -
4154 S_GET_VALUE (sub_symbolP
);
4157 if (!TC_FORCE_RELOCATION (fixP
))
4159 fixP
->fx_addsy
= NULL
;
4160 fixP
->fx_subsy
= NULL
;
4162 #ifdef TC_M68K /* is this right? */
4170 /* Different segments in subtraction. */
4171 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4173 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4175 add_number
-= S_GET_VALUE (sub_symbolP
);
4178 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4179 #if 0 /* Okay for 68k, at least... */
4184 /* Make it pc-relative. */
4185 add_number
+= (md_pcrel_from (fixP
)
4186 - S_GET_VALUE (sub_symbolP
));
4195 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4196 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4197 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4198 S_GET_NAME (sub_symbolP
),
4199 (long) (fragP
->fr_address
+ where
));
4202 } /* if sub_symbolP */
4206 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4209 * This fixup was made when the symbol's segment was
4210 * SEG_UNKNOWN, but it is now in the local segment.
4211 * So we know how to do the address without relocation.
4214 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4215 * in which cases it modifies *fixP as appropriate. In the case
4216 * of a 'calls', no further work is required, and *fixP has been
4217 * set up to make the rest of the code below a no-op.
4220 #endif /* TC_I960 */
4222 add_number
+= S_GET_VALUE (add_symbolP
);
4223 add_number
-= md_pcrel_from (fixP
);
4226 add_number -= segP->scnhdr.s_vaddr;
4227 if defined (TC_I386) || defined (TE_LYNX). I now
4228 think that was an error propagated from the case when
4229 we are going to emit the relocation. If we are not
4230 going to emit the relocation, then we just want to
4231 set add_number to the difference between the symbols.
4232 This is a case that would only arise when there is a
4233 PC relative reference from a section other than .text
4234 to a symbol defined in the same section, and the
4235 reference is not relaxed. Since jump instructions on
4236 the i386 are relaxed, this could only arise with a
4237 call instruction. */
4239 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4240 if (!TC_FORCE_RELOCATION (fixP
))
4242 fixP
->fx_addsy
= NULL
;
4248 switch (add_symbol_segment
)
4250 case absolute_section
:
4252 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4253 #endif /* TC_I960 */
4254 add_number
+= S_GET_VALUE (add_symbolP
);
4257 if (!TC_FORCE_RELOCATION (fixP
))
4259 fixP
->fx_addsy
= NULL
;
4266 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4267 /* This really should be handled in the linker, but
4268 backward compatibility forbids. */
4269 add_number
+= S_GET_VALUE (add_symbolP
);
4271 add_number
+= S_GET_VALUE (add_symbolP
) +
4272 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4278 if ((int) fixP
->fx_bit_fixP
== 13)
4280 /* This is a COBR instruction. They have only a
4281 * 13-bit displacement and are only to be used
4282 * for local branches: flag as error, don't generate
4285 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4286 _("can't use COBR format with external label"));
4287 fixP
->fx_addsy
= NULL
;
4291 #endif /* TC_I960 */
4292 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4293 /* 386 COFF uses a peculiar format in which the
4294 value of a common symbol is stored in the .text
4295 segment (I've checked this on SVR3.2 and SCO
4296 3.2.2) Ian Taylor <ian@cygnus.com>. */
4297 /* This is also true for 68k COFF on sysv machines
4298 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4299 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4300 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4301 if (S_IS_COMMON (add_symbolP
))
4302 add_number
+= S_GET_VALUE (add_symbolP
);
4307 } /* switch on symbol seg */
4308 } /* if not in local seg */
4309 } /* if there was a + symbol */
4313 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4314 /* This adjustment is not correct on the m88k, for which the
4315 linker does all the computation. */
4316 add_number
-= md_pcrel_from (fixP
);
4318 if (add_symbolP
== 0)
4320 fixP
->fx_addsy
= &abs_symbol
;
4321 } /* if there's an add_symbol */
4322 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4323 /* On the 386 we must adjust by the segment vaddr as well.
4326 I changed the i960 to work this way as well. This is
4327 compatible with the current GNU linker behaviour. I do
4328 not know what other i960 COFF assemblers do. This is not
4329 a common case: normally, only assembler code will contain
4330 a PC relative reloc, and only branches which do not
4331 originate in the .text section will have a non-zero
4334 I changed the m68k to work this way as well. This will
4335 break existing PC relative relocs from sections which do
4336 not start at address 0, but it will make ld -r work.
4337 Ian Taylor, 4 Oct 96. */
4339 add_number
-= segP
->scnhdr
.s_vaddr
;
4343 #ifdef MD_APPLY_FIX3
4344 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4346 md_apply_fix (fixP
, add_number
);
4349 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4352 /* The m88k uses the offset field of the reloc to get around
4355 && ((add_number
& ~0xFF)
4356 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4357 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4358 || (add_number
& 0x80) == 0))
4360 && ((add_number
& ~0xFFFF)
4361 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4362 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4363 || (add_number
& 0x8000) == 0)))
4365 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4366 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4367 (long) add_number
, size
,
4368 (unsigned long) (fragP
->fr_address
+ where
));
4371 #ifdef WARN_SIGNED_OVERFLOW_WORD
4372 /* Warn if a .word value is too large when treated as a
4373 signed number. We already know it is not too negative.
4374 This is to catch over-large switches generated by gcc on
4376 if (!flag_signed_overflow_ok
4378 && add_number
> 0x7fff)
4379 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4380 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4382 (unsigned long) (fragP
->fr_address
+ where
));
4384 } /* not a bit fix */
4385 } /* For each fixS in this segment. */
4386 } /* fixup_segment() */
4390 /* The first entry in a .stab section is special. */
4393 obj_coff_init_stab_section (seg
)
4399 unsigned int stroff
;
4401 /* Make space for this first symbol. */
4405 as_where (&file
, (unsigned int *) NULL
);
4406 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4407 strcpy (stabstr_name
, segment_info
[seg
].name
);
4408 strcat (stabstr_name
, "str");
4409 stroff
= get_stab_string_offset (file
, stabstr_name
);
4411 md_number_to_chars (p
, stroff
, 4);
4414 /* Fill in the counts in the first entry in a .stab section. */
4417 adjust_stab_section(abfd
, seg
)
4421 segT stabstrseg
= SEG_UNKNOWN
;
4422 const char *secname
, *name2
;
4425 int i
, strsz
= 0, nsyms
;
4426 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4428 /* Look for the associated string table section. */
4430 secname
= segment_info
[seg
].name
;
4431 name
= (char *) alloca (strlen (secname
) + 4);
4432 strcpy (name
, secname
);
4433 strcat (name
, "str");
4435 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4437 name2
= segment_info
[i
].name
;
4438 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4445 /* If we found the section, get its size. */
4446 if (stabstrseg
!= SEG_UNKNOWN
)
4447 strsz
= size_section (abfd
, stabstrseg
);
4449 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4451 /* Look for the first frag of sufficient size for the initial stab
4452 symbol, and collect a pointer to it. */
4453 while (frag
&& frag
->fr_fix
< 12)
4454 frag
= frag
->fr_next
;
4456 p
= frag
->fr_literal
;
4459 /* Write in the number of stab symbols and the size of the string
4461 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4462 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4465 #endif /* not BFD_ASSEMBLER */
4467 const pseudo_typeS obj_pseudo_table
[] =
4469 {"def", obj_coff_def
, 0},
4470 {"dim", obj_coff_dim
, 0},
4471 {"endef", obj_coff_endef
, 0},
4472 {"line", obj_coff_line
, 0},
4473 {"ln", obj_coff_ln
, 0},
4474 #ifdef BFD_ASSEMBLER
4475 {"loc", obj_coff_loc
, 0},
4477 {"appline", obj_coff_ln
, 1},
4478 {"scl", obj_coff_scl
, 0},
4479 {"size", obj_coff_size
, 0},
4480 {"tag", obj_coff_tag
, 0},
4481 {"type", obj_coff_type
, 0},
4482 {"val", obj_coff_val
, 0},
4483 {"section", obj_coff_section
, 0},
4484 {"sect", obj_coff_section
, 0},
4485 /* FIXME: We ignore the MRI short attribute. */
4486 {"section.s", obj_coff_section
, 0},
4487 {"sect.s", obj_coff_section
, 0},
4488 /* We accept the .bss directive for backward compatibility with
4489 earlier versions of gas. */
4490 {"bss", obj_coff_bss
, 0},
4491 {"weak", obj_coff_weak
, 0},
4492 #ifndef BFD_ASSEMBLER
4493 {"use", obj_coff_section
, 0},
4494 {"text", obj_coff_text
, 0},
4495 {"data", obj_coff_data
, 0},
4496 {"lcomm", obj_coff_lcomm
, 0},
4497 {"ident", obj_coff_ident
, 0},
4499 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4500 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4502 {"version", s_ignore
, 0},
4503 {"ABORT", s_abort
, 0},
4505 /* The m88k uses sdef instead of def. */
4506 {"sdef", obj_coff_def
, 0},
4508 {NULL
, NULL
, 0} /* end sentinel */
4509 }; /* obj_pseudo_table */
4511 #ifdef BFD_ASSEMBLER
4513 static void coff_pop_insert
PARAMS ((void));
4514 static int coff_sec_sym_ok_for_reloc
PARAMS ((asection
*));
4516 /* Support for a COFF emulation. */
4521 pop_insert (obj_pseudo_table
);
4525 coff_sec_sym_ok_for_reloc (sec
)
4526 asection
*sec ATTRIBUTE_UNUSED
;
4531 const struct format_ops coff_format_ops
=
4533 bfd_target_coff_flavour
,
4538 coff_frob_file_after_relocs
,
4543 obj_generate_asm_lineno
,
4552 coff_sec_sym_ok_for_reloc
,
4559 coff_obj_read_begin_hook
,
4560 coff_obj_symbol_new_hook
,