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 /* This is used to hold the symbol built by a sequence of pseudo-ops
47 from .def and .endef. */
48 static symbolS
*def_symbol_in_progress
;
53 unsigned long chunk_size
;
54 unsigned long element_size
;
57 unsigned long pointer
;
62 stack_init (chunk_size
, element_size
)
63 unsigned long chunk_size
;
64 unsigned long element_size
;
68 st
= (stack
*) malloc (sizeof (stack
));
71 st
->data
= malloc (chunk_size
);
78 st
->size
= chunk_size
;
79 st
->chunk_size
= chunk_size
;
80 st
->element_size
= element_size
;
85 /* Not currently used. */
96 stack_push (st
, element
)
100 if (st
->pointer
+ st
->element_size
>= st
->size
)
102 st
->size
+= st
->chunk_size
;
103 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
106 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
107 st
->pointer
+= st
->element_size
;
108 return st
->data
+ st
->pointer
;
115 if (st
->pointer
< st
->element_size
)
120 st
->pointer
-= st
->element_size
;
121 return st
->data
+ st
->pointer
;
125 * Maintain a list of the tagnames of the structres.
128 static struct hash_control
*tag_hash
;
133 tag_hash
= hash_new ();
137 tag_insert (name
, symbolP
)
141 const char *error_string
;
143 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
145 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
154 #ifdef STRIP_UNDERSCORE
157 #endif /* STRIP_UNDERSCORE */
158 return (symbolS
*) hash_find (tag_hash
, name
);
162 tag_find_or_make (name
)
167 if ((symbolP
= tag_find (name
)) == NULL
)
169 symbolP
= symbol_new (name
, undefined_section
,
170 0, &zero_address_frag
);
172 tag_insert (S_GET_NAME (symbolP
), symbolP
);
174 symbol_table_insert (symbolP
);
181 /* We accept the .bss directive to set the section for backward
182 compatibility with earlier versions of gas. */
185 obj_coff_bss (ignore
)
186 int ignore ATTRIBUTE_UNUSED
;
188 if (*input_line_pointer
== '\n')
189 subseg_new (".bss", get_absolute_expression ());
194 /* Handle .weak. This is a GNU extension. */
197 obj_coff_weak (ignore
)
198 int ignore ATTRIBUTE_UNUSED
;
206 name
= input_line_pointer
;
207 c
= get_symbol_end ();
208 symbolP
= symbol_find_or_make (name
);
209 *input_line_pointer
= c
;
213 S_SET_WEAK (symbolP
);
217 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
219 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
224 input_line_pointer
++;
226 if (*input_line_pointer
== '\n')
232 demand_empty_rest_of_line ();
237 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
239 #define GET_FILENAME_STRING(X) \
240 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
244 fetch_coff_debug_section ()
246 static segT debug_section
;
250 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
252 debug_section
= s
->section
;
254 return debug_section
;
258 SA_SET_SYM_ENDNDX (sym
, val
)
262 combined_entry_type
*entry
, *p
;
264 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
265 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
266 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
271 SA_SET_SYM_TAGNDX (sym
, val
)
275 combined_entry_type
*entry
, *p
;
277 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
278 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
279 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
284 S_GET_DATA_TYPE (sym
)
287 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
291 S_SET_DATA_TYPE (sym
, val
)
295 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
300 S_GET_STORAGE_CLASS (sym
)
303 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
307 S_SET_STORAGE_CLASS (sym
, val
)
311 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
315 /* Merge a debug symbol containing debug information into a normal symbol. */
318 c_symbol_merge (debug
, normal
)
322 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
323 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
325 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
327 /* take the most we have */
328 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
331 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
333 /* Move all the auxiliary information. */
334 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
335 (S_GET_NUMBER_AUXILIARY (debug
)
336 * sizeof (*SYM_AUXINFO (debug
))));
339 /* Move the debug flags. */
340 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
344 c_dot_file_symbol (filename
)
349 /* BFD converts filename to a .file symbol with an aux entry. It
350 also handles chaining. */
351 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
353 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
354 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
356 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
363 listing_source_file (filename
);
368 /* Make sure that the symbol is first on the symbol chain */
369 if (symbol_rootP
!= symbolP
)
371 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
372 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
373 } /* if not first on the list */
376 /* Line number handling */
379 struct line_no
*next
;
386 /* Symbol of last function, which we should hang line#s off of. */
387 static symbolS
*line_fsym
;
389 #define in_function() (line_fsym != 0)
390 #define clear_function() (line_fsym = 0)
391 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
395 coff_obj_symbol_new_hook (symbolP
)
398 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
399 char * s
= (char *) xmalloc (sz
);
402 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
404 S_SET_DATA_TYPE (symbolP
, T_NULL
);
405 S_SET_STORAGE_CLASS (symbolP
, 0);
406 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
408 if (S_IS_STRING (symbolP
))
409 SF_SET_STRING (symbolP
);
411 if (S_IS_LOCAL (symbolP
))
412 SF_SET_LOCAL (symbolP
);
417 * Handle .ln directives.
420 static symbolS
*current_lineno_sym
;
421 static struct line_no
*line_nos
;
422 /* @@ Blindly assume all .ln directives will be in the .text section... */
426 add_lineno (frag
, offset
, num
)
431 struct line_no
*new_line
=
432 (struct line_no
*) xmalloc (sizeof (struct line_no
));
433 if (!current_lineno_sym
)
439 /* Zero is used as an end marker in the file. */
440 as_bad (_("Line numbers must be positive integers\n"));
443 new_line
->next
= line_nos
;
444 new_line
->frag
= frag
;
445 new_line
->l
.line_number
= num
;
446 new_line
->l
.u
.offset
= offset
;
452 coff_add_linesym (sym
)
457 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
462 current_lineno_sym
= sym
;
466 obj_coff_ln (appline
)
471 if (! appline
&& def_symbol_in_progress
!= NULL
)
473 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
474 demand_empty_rest_of_line ();
478 l
= get_absolute_expression ();
481 add_lineno (frag_now
, frag_now_fix (), l
);
485 new_logical_line ((char *) NULL
, l
- 1);
494 l
+= coff_line_base
- 1;
495 listing_source_line (l
);
500 demand_empty_rest_of_line ();
506 * Handle .def directives.
508 * One might ask : why can't we symbol_new if the symbol does not
509 * already exist and fill it with debug information. Because of
510 * the C_EFCN special symbol. It would clobber the value of the
511 * function symbol before we have a chance to notice that it is
512 * a C_EFCN. And a second reason is that the code is more clear this
513 * way. (at least I think it is :-).
517 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
518 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
519 *input_line_pointer == '\t') \
520 input_line_pointer++;
524 int what ATTRIBUTE_UNUSED
;
526 char name_end
; /* Char after the end of name */
527 char *symbol_name
; /* Name of the debug symbol */
528 char *symbol_name_copy
; /* Temporary copy of the name */
529 unsigned int symbol_name_length
;
531 if (def_symbol_in_progress
!= NULL
)
533 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
534 demand_empty_rest_of_line ();
536 } /* if not inside .def/.endef */
540 symbol_name
= input_line_pointer
;
541 #ifdef STRIP_UNDERSCORE
542 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
544 #endif /* STRIP_UNDERSCORE */
546 name_end
= get_symbol_end ();
547 symbol_name_length
= strlen (symbol_name
);
548 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
549 strcpy (symbol_name_copy
, symbol_name
);
550 #ifdef tc_canonicalize_symbol_name
551 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
554 /* Initialize the new symbol */
555 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
556 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
557 S_SET_VALUE (def_symbol_in_progress
, 0);
559 if (S_IS_STRING (def_symbol_in_progress
))
560 SF_SET_STRING (def_symbol_in_progress
);
562 *input_line_pointer
= name_end
;
564 demand_empty_rest_of_line ();
567 unsigned int dim_index
;
570 obj_coff_endef (ignore
)
571 int ignore ATTRIBUTE_UNUSED
;
575 /* DIM BUG FIX sac@cygnus.com */
577 if (def_symbol_in_progress
== NULL
)
579 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
580 demand_empty_rest_of_line ();
582 } /* if not inside .def/.endef */
584 /* Set the section number according to storage class. */
585 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
590 SF_SET_TAG (def_symbol_in_progress
);
591 /* intentional fallthrough */
594 SF_SET_DEBUG (def_symbol_in_progress
);
595 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
599 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
600 /* intentional fallthrough */
602 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
603 /* intentional fallthrough */
607 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
609 name
= S_GET_NAME (def_symbol_in_progress
);
610 if (name
[1] == 'b' && name
[2] == 'f')
612 if (! in_function ())
613 as_warn (_("`%s' symbol without preceding function"), name
);
614 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
615 /* Will need relocating */
616 SF_SET_PROCESS (def_symbol_in_progress
);
624 #endif /* C_AUTOARG */
630 SF_SET_DEBUG (def_symbol_in_progress
);
631 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
638 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
648 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
655 as_warn (_("unexpected storage class %d"),
656 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
658 } /* switch on storage class */
660 /* Now that we have built a debug symbol, try to find if we should
661 merge with an existing symbol or not. If a symbol is C_EFCN or
662 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
664 /* Two cases for functions. Either debug followed by definition or
665 definition followed by debug. For definition first, we will
666 merge the debug symbol into the definition. For debug first, the
667 lineno entry MUST point to the definition function or else it
668 will point off into space when obj_crawl_symbol_chain() merges
669 the debug symbol into the real symbol. Therefor, let's presume
670 the debug symbol is a real function reference. */
672 /* FIXME-SOON If for some reason the definition label/symbol is
673 never seen, this will probably leave an undefined symbol at link
676 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
677 || (!strcmp (bfd_get_section_name (stdoutput
,
678 S_GET_SEGMENT (def_symbol_in_progress
)),
680 && !SF_GET_TAG (def_symbol_in_progress
))
681 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
682 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
684 if (def_symbol_in_progress
!= symbol_lastP
)
685 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
690 /* This symbol already exists, merge the newly created symbol
691 into the old one. This is not mandatory. The linker can
692 handle duplicate symbols correctly. But I guess that it save
693 a *lot* of space if the assembly file defines a lot of
696 /* The debug entry (def_symbol_in_progress) is merged into the
697 previous definition. */
699 c_symbol_merge (def_symbol_in_progress
, symbolP
);
700 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
702 def_symbol_in_progress
= symbolP
;
704 if (SF_GET_FUNCTION (def_symbol_in_progress
)
705 || SF_GET_TAG (def_symbol_in_progress
)
706 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
708 /* For functions, and tags, and static symbols, the symbol
709 *must* be where the debug symbol appears. Move the
710 existing symbol to the current place. */
711 /* If it already is at the end of the symbol list, do nothing */
712 if (def_symbol_in_progress
!= symbol_lastP
)
714 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
715 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
720 if (SF_GET_TAG (def_symbol_in_progress
))
724 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
726 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
727 tag_insert (S_GET_NAME (def_symbol_in_progress
),
728 def_symbol_in_progress
);
731 if (SF_GET_FUNCTION (def_symbol_in_progress
))
733 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
734 set_function (def_symbol_in_progress
);
735 SF_SET_PROCESS (def_symbol_in_progress
);
739 /* That is, if this is the first time we've seen the
741 symbol_table_insert (def_symbol_in_progress
);
742 } /* definition follows debug */
743 } /* Create the line number entry pointing to the function being defined */
745 def_symbol_in_progress
= NULL
;
746 demand_empty_rest_of_line ();
750 obj_coff_dim (ignore
)
751 int ignore ATTRIBUTE_UNUSED
;
755 if (def_symbol_in_progress
== NULL
)
757 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
758 demand_empty_rest_of_line ();
760 } /* if not inside .def/.endef */
762 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
764 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
767 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
768 get_absolute_expression ());
770 switch (*input_line_pointer
)
773 input_line_pointer
++;
777 as_warn (_("badly formed .dim directive ignored"));
778 /* intentional fallthrough */
786 demand_empty_rest_of_line ();
790 obj_coff_line (ignore
)
791 int ignore ATTRIBUTE_UNUSED
;
795 if (def_symbol_in_progress
== NULL
)
797 /* Probably stabs-style line? */
802 this_base
= get_absolute_expression ();
803 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
804 coff_line_base
= this_base
;
806 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
807 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
809 demand_empty_rest_of_line ();
812 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
817 listing_source_line ((unsigned int) coff_line_base
);
823 obj_coff_size (ignore
)
824 int ignore ATTRIBUTE_UNUSED
;
826 if (def_symbol_in_progress
== NULL
)
828 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
829 demand_empty_rest_of_line ();
831 } /* if not inside .def/.endef */
833 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
834 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
835 demand_empty_rest_of_line ();
839 obj_coff_scl (ignore
)
840 int ignore ATTRIBUTE_UNUSED
;
842 if (def_symbol_in_progress
== NULL
)
844 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
845 demand_empty_rest_of_line ();
847 } /* if not inside .def/.endef */
849 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
850 demand_empty_rest_of_line ();
854 obj_coff_tag (ignore
)
855 int ignore ATTRIBUTE_UNUSED
;
860 if (def_symbol_in_progress
== NULL
)
862 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
863 demand_empty_rest_of_line ();
867 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
868 symbol_name
= input_line_pointer
;
869 name_end
= get_symbol_end ();
871 #ifdef tc_canonicalize_symbol_name
872 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
875 /* Assume that the symbol referred to by .tag is always defined.
876 This was a bad assumption. I've added find_or_make. xoxorich. */
877 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
878 tag_find_or_make (symbol_name
));
879 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
881 as_warn (_("tag not found for .tag %s"), symbol_name
);
884 SF_SET_TAGGED (def_symbol_in_progress
);
885 *input_line_pointer
= name_end
;
887 demand_empty_rest_of_line ();
891 obj_coff_type (ignore
)
892 int ignore ATTRIBUTE_UNUSED
;
894 if (def_symbol_in_progress
== NULL
)
896 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
897 demand_empty_rest_of_line ();
899 } /* if not inside .def/.endef */
901 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
903 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
904 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
906 SF_SET_FUNCTION (def_symbol_in_progress
);
907 } /* is a function */
909 demand_empty_rest_of_line ();
913 obj_coff_val (ignore
)
914 int ignore ATTRIBUTE_UNUSED
;
916 if (def_symbol_in_progress
== NULL
)
918 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
919 demand_empty_rest_of_line ();
921 } /* if not inside .def/.endef */
923 if (is_name_beginner (*input_line_pointer
))
925 char *symbol_name
= input_line_pointer
;
926 char name_end
= get_symbol_end ();
928 #ifdef tc_canonicalize_symbol_name
929 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
931 if (!strcmp (symbol_name
, "."))
933 symbol_set_frag (def_symbol_in_progress
, frag_now
);
934 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
935 /* If the .val is != from the .def (e.g. statics) */
937 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
942 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
943 exp
.X_op_symbol
= NULL
;
944 exp
.X_add_number
= 0;
945 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
947 /* If the segment is undefined when the forward reference is
948 resolved, then copy the segment id from the forward
950 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
952 /* FIXME: gcc can generate address expressions here in
953 unusual cases (search for "obscure" in sdbout.c). We
954 just ignore the offset here, thus generating incorrect
955 debugging information. We ignore the rest of the line
958 /* Otherwise, it is the name of a non debug symbol and its value
959 will be calculated later. */
960 *input_line_pointer
= name_end
;
964 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
965 } /* if symbol based */
967 demand_empty_rest_of_line ();
971 coff_obj_read_begin_hook ()
973 /* These had better be the same. Usually 18 bytes. */
975 know (sizeof (SYMENT
) == sizeof (AUXENT
));
976 know (SYMESZ
== AUXESZ
);
982 symbolS
*coff_last_function
;
983 static symbolS
*coff_last_bf
;
986 coff_frob_symbol (symp
, punt
)
990 static symbolS
*last_tagP
;
991 static stack
*block_stack
;
992 static symbolS
*set_end
;
993 symbolS
*next_set_end
= NULL
;
995 if (symp
== &abs_symbol
)
1001 if (current_lineno_sym
)
1002 coff_add_linesym ((symbolS
*) 0);
1005 block_stack
= stack_init (512, sizeof (symbolS
*));
1007 if (S_IS_WEAK (symp
))
1010 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1012 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1016 if (!S_IS_DEFINED (symp
)
1017 && !S_IS_WEAK (symp
)
1018 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1019 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1021 if (!SF_GET_DEBUG (symp
))
1024 if (!SF_GET_LOCAL (symp
)
1025 && !SF_GET_STATICS (symp
)
1026 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1029 c_symbol_merge (symp
, real
);
1032 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1034 assert (S_GET_VALUE (symp
) == 0);
1035 S_SET_EXTERNAL (symp
);
1037 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1039 if (S_GET_SEGMENT (symp
) == text_section
1040 && symp
!= seg_info (text_section
)->sym
)
1041 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1043 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1045 if (SF_GET_PROCESS (symp
))
1047 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1049 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1050 stack_push (block_stack
, (char *) &symp
);
1054 begin
= *(symbolS
**) stack_pop (block_stack
);
1056 as_warn (_("mismatched .eb"));
1058 next_set_end
= begin
;
1061 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1063 union internal_auxent
*auxp
;
1064 coff_last_function
= symp
;
1065 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1066 S_SET_NUMBER_AUXILIARY (symp
, 1);
1067 auxp
= SYM_AUXENT (symp
);
1068 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1069 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1071 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1073 if (coff_last_function
== 0)
1074 as_fatal (_("C_EFCN symbol out of scope"));
1075 SA_SET_SYM_FSIZE (coff_last_function
,
1076 (long) (S_GET_VALUE (symp
)
1077 - S_GET_VALUE (coff_last_function
)));
1078 next_set_end
= coff_last_function
;
1079 coff_last_function
= 0;
1082 if (S_IS_EXTERNAL (symp
))
1083 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1084 else if (SF_GET_LOCAL (symp
))
1087 if (SF_GET_FUNCTION (symp
))
1088 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1093 if (SF_GET_TAG (symp
))
1095 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1096 next_set_end
= last_tagP
;
1099 /* This is pretty horrible, but we have to set *punt correctly in
1100 order to call SA_SET_SYM_ENDNDX correctly. */
1101 if (! symbol_used_in_reloc_p (symp
)
1102 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1103 || (! S_IS_EXTERNAL (symp
)
1104 && ! symbol_get_tc (symp
)->output
1105 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1109 if (set_end
!= (symbolS
*) NULL
1111 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1112 || (S_IS_DEFINED (symp
)
1113 && ! S_IS_COMMON (symp
)
1114 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1116 SA_SET_SYM_ENDNDX (set_end
, symp
);
1120 if (next_set_end
!= NULL
)
1122 if (set_end
!= NULL
)
1123 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1124 S_GET_NAME (set_end
));
1125 set_end
= next_set_end
;
1129 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1130 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1132 if (coff_last_bf
!= NULL
)
1133 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1134 coff_last_bf
= symp
;
1137 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1140 struct line_no
*lptr
;
1143 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1144 for (i
= 0; lptr
; lptr
= lptr
->next
)
1146 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1148 /* We need i entries for line numbers, plus 1 for the first
1149 entry which BFD will override, plus 1 for the last zero
1150 entry (a marker for BFD). */
1151 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1152 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1153 l
[i
+ 1].line_number
= 0;
1154 l
[i
+ 1].u
.sym
= NULL
;
1158 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1166 coff_adjust_section_syms (abfd
, sec
, x
)
1167 bfd
*abfd ATTRIBUTE_UNUSED
;
1169 PTR x ATTRIBUTE_UNUSED
;
1172 segment_info_type
*seginfo
= seg_info (sec
);
1173 int nlnno
, nrelocs
= 0;
1175 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1176 tc-ppc.c. Do not get confused by it. */
1177 if (seginfo
== NULL
)
1180 if (!strcmp (sec
->name
, ".text"))
1181 nlnno
= coff_n_line_nos
;
1185 /* @@ Hope that none of the fixups expand to more than one reloc
1187 fixS
*fixp
= seginfo
->fix_root
;
1190 if (! fixp
->fx_done
)
1192 fixp
= fixp
->fx_next
;
1195 if (bfd_get_section_size_before_reloc (sec
) == 0
1198 && sec
!= text_section
1199 && sec
!= data_section
1200 && sec
!= bss_section
)
1202 secsym
= section_symbol (sec
);
1203 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1204 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1208 coff_frob_file_after_relocs ()
1210 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1214 * implement the .section pseudo op:
1215 * .section name {, "flags"}
1217 * | +--- optional flags: 'b' for bss
1219 * +-- section name 'l' for lib
1223 * 'd' (apparently m88k for data)
1225 * 'r' for read-only data
1226 * 's' for shared data (PE)
1227 * But if the argument is not a quoted string, treat it as a
1228 * subsegment number.
1232 obj_coff_section (ignore
)
1233 int ignore ATTRIBUTE_UNUSED
;
1235 /* Strip out the section name */
1251 section_name
= input_line_pointer
;
1252 c
= get_symbol_end ();
1254 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1255 strcpy (name
, section_name
);
1257 *input_line_pointer
= c
;
1264 if (*input_line_pointer
== ',')
1266 ++input_line_pointer
;
1268 if (*input_line_pointer
!= '"')
1269 exp
= get_absolute_expression ();
1272 ++input_line_pointer
;
1273 while (*input_line_pointer
!= '"'
1274 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1276 switch (*input_line_pointer
)
1278 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1279 case 'n': flags
&=~ SEC_LOAD
; break;
1280 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1281 case 'w': flags
&=~ SEC_READONLY
; break;
1282 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1283 case 'r': flags
|= SEC_READONLY
; break;
1284 case 's': flags
|= SEC_SHARED
; break;
1286 case 'i': /* STYP_INFO */
1287 case 'l': /* STYP_LIB */
1288 case 'o': /* STYP_OVER */
1289 as_warn (_("unsupported section attribute '%c'"),
1290 *input_line_pointer
);
1294 as_warn(_("unknown section attribute '%c'"),
1295 *input_line_pointer
);
1298 ++input_line_pointer
;
1300 if (*input_line_pointer
== '"')
1301 ++input_line_pointer
;
1305 sec
= subseg_new (name
, (subsegT
) exp
);
1307 if (flags
!= SEC_NO_FLAGS
)
1311 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1312 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1315 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1316 as_warn (_("error setting flags for \"%s\": %s"),
1317 bfd_section_name (stdoutput
, sec
),
1318 bfd_errmsg (bfd_get_error ()));
1321 demand_empty_rest_of_line ();
1325 coff_adjust_symtab ()
1327 if (symbol_rootP
== NULL
1328 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1329 c_dot_file_symbol ("fake");
1333 coff_frob_section (sec
)
1339 bfd_vma size
, n_entries
, mask
;
1341 /* The COFF back end in BFD requires that all section sizes be
1342 rounded up to multiples of the corresponding section alignments.
1343 Seems kinda silly to me, but that's the way it is. */
1344 size
= bfd_get_section_size_before_reloc (sec
);
1345 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1348 size
= (size
+ mask
) & ~mask
;
1349 bfd_set_section_size (stdoutput
, sec
, size
);
1352 /* If the section size is non-zero, the section symbol needs an aux
1353 entry associated with it, indicating the size. We don't know
1354 all the values yet; coff_frob_symbol will fill them in later. */
1356 || sec
== text_section
1357 || sec
== data_section
1358 || sec
== bss_section
)
1360 symbolS
*secsym
= section_symbol (sec
);
1362 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1363 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1364 SF_SET_STATICS (secsym
);
1365 SA_SET_SCN_SCNLEN (secsym
, size
);
1368 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1369 #ifndef STAB_SECTION_NAME
1370 #define STAB_SECTION_NAME ".stab"
1372 #ifndef STAB_STRING_SECTION_NAME
1373 #define STAB_STRING_SECTION_NAME ".stabstr"
1375 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1379 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1380 /* size is already rounded up, since other section will be listed first */
1381 size
= bfd_get_section_size_before_reloc (strsec
);
1383 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1385 /* Find first non-empty frag. It should be large enough. */
1386 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1387 while (fragp
&& fragp
->fr_fix
== 0)
1388 fragp
= fragp
->fr_next
;
1389 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1391 /* Store the values. */
1392 p
= fragp
->fr_literal
;
1393 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1394 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1398 obj_coff_init_stab_section (seg
)
1404 unsigned int stroff
;
1406 /* Make space for this first symbol. */
1410 as_where (&file
, (unsigned int *) NULL
);
1411 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1412 strcpy (stabstr_name
, seg
->name
);
1413 strcat (stabstr_name
, "str");
1414 stroff
= get_stab_string_offset (file
, stabstr_name
);
1416 md_number_to_chars (p
, stroff
, 4);
1425 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1433 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1435 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1436 (unsigned long) symbolP
,
1437 S_GET_NAME(symbolP
),
1438 (long) S_GET_DATA_TYPE(symbolP
),
1439 S_GET_STORAGE_CLASS(symbolP
),
1440 (int) S_GET_SEGMENT(symbolP
));
1446 #else /* not BFD_ASSEMBLER */
1449 /* This is needed because we include internal bfd things. */
1453 #include "libcoff.h"
1456 #include "coff/pe.h"
1459 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1460 that we can stick sections together without causing trouble. */
1462 #define NOP_OPCODE 0x00
1465 /* The zeroes if symbol name is longer than 8 chars */
1466 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1468 #define MIN(a,b) ((a) < (b)? (a) : (b))
1470 /* This vector is used to turn a gas internal segment number into a
1471 section number suitable for insertion into a coff symbol table.
1472 This must correspond to seg_info_off_by_4. */
1474 const short seg_N_TYPE
[] =
1475 { /* in: segT out: N_TYPE bits */
1477 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1478 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1479 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1480 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1481 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1482 C_UNDEF_SECTION
, /* SEG_GOOF */
1483 C_UNDEF_SECTION
, /* SEG_EXPR */
1484 C_DEBUG_SECTION
, /* SEG_DEBUG */
1485 C_NTV_SECTION
, /* SEG_NTV */
1486 C_PTV_SECTION
, /* SEG_PTV */
1487 C_REGISTER_SECTION
, /* SEG_REGISTER */
1490 int function_lineoff
= -1; /* Offset in line#s where the last function
1491 started (the odd entry for line #0) */
1493 /* structure used to keep the filenames which
1494 are too long around so that we can stick them
1495 into the string table */
1496 struct filename_list
1499 struct filename_list
*next
;
1502 static struct filename_list
*filename_list_head
;
1503 static struct filename_list
*filename_list_tail
;
1505 static symbolS
*last_line_symbol
;
1507 /* Add 4 to the real value to get the index and compensate the
1508 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1509 section number into a segment number
1511 static symbolS
*previous_file_symbol
;
1512 void c_symbol_merge ();
1513 static int line_base
;
1515 symbolS
*c_section_symbol ();
1518 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1519 segT this_segment_type
));
1522 static void fixup_mdeps
PARAMS ((fragS
*,
1527 static void fill_section
PARAMS ((bfd
* abfd
,
1532 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1537 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1538 symbolS
* symbol_rootP
));
1540 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1542 static void obj_coff_lcomm
PARAMS ((int));
1543 static void obj_coff_text
PARAMS ((int));
1544 static void obj_coff_data
PARAMS ((int));
1545 static void obj_coff_ident
PARAMS ((int));
1546 void obj_coff_section
PARAMS ((int));
1548 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1550 This array maps a COFF section number into a gas section number.
1551 Because COFF uses negative section numbers, you must add 4 to the
1552 COFF section number when indexing into this array; this is done via
1553 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1556 static const segT seg_info_off_by_4
[] =
1563 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1564 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1565 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1566 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1567 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1568 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1569 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1570 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1583 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1585 static relax_addressT
1586 relax_align (address
, alignment
)
1587 relax_addressT address
;
1590 relax_addressT mask
;
1591 relax_addressT new_address
;
1593 mask
= ~((~0) << alignment
);
1594 new_address
= (address
+ mask
) & (~mask
);
1595 return (new_address
- address
);
1603 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1606 /* calculate the size of the frag chain and fill in the section header
1607 to contain all of it, also fill in the addr of the sections */
1609 size_section (abfd
, idx
)
1610 bfd
*abfd ATTRIBUTE_UNUSED
;
1614 unsigned int size
= 0;
1615 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1618 size
= frag
->fr_address
;
1619 if (frag
->fr_address
!= size
)
1621 fprintf (stderr
, _("Out of step\n"));
1622 size
= frag
->fr_address
;
1625 switch (frag
->fr_type
)
1627 #ifdef TC_COFF_SIZEMACHDEP
1628 case rs_machine_dependent
:
1629 size
+= TC_COFF_SIZEMACHDEP (frag
);
1633 assert (frag
->fr_symbol
== 0);
1636 size
+= frag
->fr_fix
;
1637 size
+= frag
->fr_offset
* frag
->fr_var
;
1644 size
+= frag
->fr_fix
;
1645 off
= relax_align (size
, frag
->fr_offset
);
1646 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1652 BAD_CASE (frag
->fr_type
);
1655 frag
= frag
->fr_next
;
1657 segment_info
[idx
].scnhdr
.s_size
= size
;
1663 count_entries_in_chain (idx
)
1666 unsigned int nrelocs
;
1669 /* Count the relocations */
1670 fixup_ptr
= segment_info
[idx
].fix_root
;
1672 while (fixup_ptr
!= (fixS
*) NULL
)
1674 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1677 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1686 fixup_ptr
= fixup_ptr
->fx_next
;
1693 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1695 /* AUX's ld expects relocations to be sorted */
1697 compare_external_relocs (x
, y
)
1701 struct external_reloc
*a
= (struct external_reloc
*) x
;
1702 struct external_reloc
*b
= (struct external_reloc
*) y
;
1703 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1704 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1705 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1710 /* output all the relocations for a section */
1712 do_relocs_for (abfd
, h
, file_cursor
)
1715 unsigned long *file_cursor
;
1717 unsigned int nrelocs
;
1719 unsigned long reloc_start
= *file_cursor
;
1721 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1723 if (segment_info
[idx
].scnhdr
.s_name
[0])
1725 struct external_reloc
*ext_ptr
;
1726 struct external_reloc
*external_reloc_vec
;
1727 unsigned int external_reloc_size
;
1728 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1729 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1730 nrelocs
= count_entries_in_chain (idx
);
1733 /* Bypass this stuff if no relocs. This also incidentally
1734 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1736 external_reloc_size
= nrelocs
* RELSZ
;
1737 external_reloc_vec
=
1738 (struct external_reloc
*) malloc (external_reloc_size
);
1740 ext_ptr
= external_reloc_vec
;
1742 /* Fill in the internal coff style reloc struct from the
1743 internal fix list. */
1746 struct internal_reloc intr
;
1748 /* Only output some of the relocations */
1749 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1751 #ifdef TC_RELOC_MANGLE
1752 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1757 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1759 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1761 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1763 #ifdef TC_KEEP_FX_OFFSET
1764 intr
.r_offset
= fix_ptr
->fx_offset
;
1769 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1770 && (! S_IS_DEFINED (symbol_ptr
)
1771 || S_IS_COMMON (symbol_ptr
)))
1775 /* We must avoid looping, as that can occur
1776 with a badly written program. */
1777 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1778 if (n
== symbol_ptr
)
1783 /* Turn the segment of the symbol into an offset. */
1786 resolve_symbol_value (symbol_ptr
, 1);
1787 if (! symbol_ptr
->sy_resolved
)
1792 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1793 as_bad_where (file
, line
,
1794 _("unresolved relocation"));
1796 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1797 S_GET_NAME (symbol_ptr
));
1799 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1802 intr
.r_symndx
= dot
->sy_number
;
1806 intr
.r_symndx
= symbol_ptr
->sy_number
;
1816 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1819 #if defined(TC_A29K)
1821 /* The 29k has a special kludge for the high 16 bit
1822 reloc. Two relocations are emited, R_IHIHALF,
1823 and R_IHCONST. The second one doesn't contain a
1824 symbol, but uses the value for offset. */
1826 if (intr
.r_type
== R_IHIHALF
)
1828 /* now emit the second bit */
1829 intr
.r_type
= R_IHCONST
;
1830 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1831 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1837 fix_ptr
= fix_ptr
->fx_next
;
1841 /* Sort the reloc table */
1842 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1843 sizeof (struct external_reloc
), compare_external_relocs
);
1846 /* Write out the reloc table */
1847 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1849 free (external_reloc_vec
);
1851 /* Fill in section header info. */
1852 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1853 *file_cursor
+= external_reloc_size
;
1854 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1859 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1863 /* Set relocation_size field in file headers */
1864 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1868 /* run through a frag chain and write out the data to go with it, fill
1869 in the scnhdrs with the info on the file postions
1872 fill_section (abfd
, h
, file_cursor
)
1874 object_headers
*h ATTRIBUTE_UNUSED
;
1875 unsigned long *file_cursor
;
1879 unsigned int paddr
= 0;
1881 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1883 unsigned int offset
= 0;
1884 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1890 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1897 buffer
= xmalloc (s
->s_size
);
1898 s
->s_scnptr
= *file_cursor
;
1900 know (s
->s_paddr
== paddr
);
1902 if (strcmp (s
->s_name
, ".text") == 0)
1903 s
->s_flags
|= STYP_TEXT
;
1904 else if (strcmp (s
->s_name
, ".data") == 0)
1905 s
->s_flags
|= STYP_DATA
;
1906 else if (strcmp (s
->s_name
, ".bss") == 0)
1909 s
->s_flags
|= STYP_BSS
;
1911 /* @@ Should make the i386 and a29k coff targets define
1912 COFF_NOLOAD_PROBLEM, and have only one test here. */
1915 #ifndef COFF_NOLOAD_PROBLEM
1916 /* Apparently the SVR3 linker (and exec syscall) and UDI
1917 mondfe progrem are confused by noload sections. */
1918 s
->s_flags
|= STYP_NOLOAD
;
1923 else if (strcmp (s
->s_name
, ".lit") == 0)
1924 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1925 else if (strcmp (s
->s_name
, ".init") == 0)
1926 s
->s_flags
|= STYP_TEXT
;
1927 else if (strcmp (s
->s_name
, ".fini") == 0)
1928 s
->s_flags
|= STYP_TEXT
;
1929 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1930 s
->s_flags
|= STYP_INFO
;
1934 unsigned int fill_size
;
1935 switch (frag
->fr_type
)
1937 case rs_machine_dependent
:
1940 memcpy (buffer
+ frag
->fr_address
,
1942 (unsigned int) frag
->fr_fix
);
1943 offset
+= frag
->fr_fix
;
1948 assert (frag
->fr_symbol
== 0);
1955 memcpy (buffer
+ frag
->fr_address
,
1957 (unsigned int) frag
->fr_fix
);
1958 offset
+= frag
->fr_fix
;
1961 fill_size
= frag
->fr_var
;
1962 if (fill_size
&& frag
->fr_offset
> 0)
1965 unsigned int off
= frag
->fr_fix
;
1966 for (count
= frag
->fr_offset
; count
; count
--)
1968 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1970 memcpy (buffer
+ frag
->fr_address
+ off
,
1971 frag
->fr_literal
+ frag
->fr_fix
,
1974 offset
+= fill_size
;
1979 case rs_broken_word
:
1984 frag
= frag
->fr_next
;
1989 if (s
->s_scnptr
!= 0)
1991 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1992 *file_cursor
+= s
->s_size
;
2001 /* Coff file generation & utilities */
2004 coff_header_append (abfd
, h
)
2011 #ifdef COFF_LONG_SECTION_NAMES
2012 unsigned long string_size
= 4;
2015 bfd_seek (abfd
, 0, 0);
2017 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2018 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2019 H_SET_VERSION_STAMP (h
, 0);
2020 H_SET_ENTRY_POINT (h
, 0);
2021 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2022 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2023 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2025 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2026 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2027 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2029 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2031 bfd_write (buffer
, i
, 1, abfd
);
2032 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2034 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2036 if (segment_info
[i
].scnhdr
.s_name
[0])
2040 #ifdef COFF_LONG_SECTION_NAMES
2041 /* Support long section names as found in PE. This code
2042 must coordinate with that in write_object_file and
2044 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2046 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2047 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2048 string_size
+= strlen (segment_info
[i
].name
) + 1;
2052 size
= bfd_coff_swap_scnhdr_out (abfd
,
2053 &(segment_info
[i
].scnhdr
),
2056 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2057 bfd_write (buffer
, size
, 1, abfd
);
2064 symbol_to_chars (abfd
, where
, symbolP
)
2069 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2073 /* Turn any symbols with register attributes into abs symbols */
2074 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2076 S_SET_SEGMENT (symbolP
, absolute_section
);
2078 /* At the same time, relocate all symbols to their output value */
2081 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2082 + S_GET_VALUE (symbolP
));
2084 val
= S_GET_VALUE (symbolP
);
2087 S_SET_VALUE (symbolP
, val
);
2089 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2091 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2094 for (i
= 0; i
< numaux
; i
++)
2096 where
+= bfd_coff_swap_aux_out (abfd
,
2097 &symbolP
->sy_symbol
.ost_auxent
[i
],
2098 S_GET_DATA_TYPE (symbolP
),
2099 S_GET_STORAGE_CLASS (symbolP
),
2107 coff_obj_symbol_new_hook (symbolP
)
2110 char underscore
= 0; /* Symbol has leading _ */
2112 /* Effective symbol */
2113 /* Store the pointer in the offset. */
2114 S_SET_ZEROES (symbolP
, 0L);
2115 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2116 S_SET_STORAGE_CLASS (symbolP
, 0);
2117 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2118 /* Additional information */
2119 symbolP
->sy_symbol
.ost_flags
= 0;
2120 /* Auxiliary entries */
2121 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2123 if (S_IS_STRING (symbolP
))
2124 SF_SET_STRING (symbolP
);
2125 if (!underscore
&& S_IS_LOCAL (symbolP
))
2126 SF_SET_LOCAL (symbolP
);
2130 * Handle .ln directives.
2134 obj_coff_ln (appline
)
2139 if (! appline
&& def_symbol_in_progress
!= NULL
)
2141 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2142 demand_empty_rest_of_line ();
2144 } /* wrong context */
2146 l
= get_absolute_expression ();
2147 c_line_new (0, frag_now_fix (), l
, frag_now
);
2150 new_logical_line ((char *) NULL
, l
- 1);
2160 listing_source_line ((unsigned int) l
);
2165 demand_empty_rest_of_line ();
2171 * Handle .def directives.
2173 * One might ask : why can't we symbol_new if the symbol does not
2174 * already exist and fill it with debug information. Because of
2175 * the C_EFCN special symbol. It would clobber the value of the
2176 * function symbol before we have a chance to notice that it is
2177 * a C_EFCN. And a second reason is that the code is more clear this
2178 * way. (at least I think it is :-).
2182 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2183 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2184 *input_line_pointer == '\t') \
2185 input_line_pointer++;
2189 int what ATTRIBUTE_UNUSED
;
2191 char name_end
; /* Char after the end of name */
2192 char *symbol_name
; /* Name of the debug symbol */
2193 char *symbol_name_copy
; /* Temporary copy of the name */
2194 unsigned int symbol_name_length
;
2196 if (def_symbol_in_progress
!= NULL
)
2198 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2199 demand_empty_rest_of_line ();
2201 } /* if not inside .def/.endef */
2203 SKIP_WHITESPACES ();
2205 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2206 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2208 symbol_name
= input_line_pointer
;
2209 name_end
= get_symbol_end ();
2210 symbol_name_length
= strlen (symbol_name
);
2211 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2212 strcpy (symbol_name_copy
, symbol_name
);
2213 #ifdef tc_canonicalize_symbol_name
2214 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2217 /* Initialize the new symbol */
2218 #ifdef STRIP_UNDERSCORE
2219 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2220 ? symbol_name_copy
+ 1
2221 : symbol_name_copy
));
2222 #else /* STRIP_UNDERSCORE */
2223 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2224 #endif /* STRIP_UNDERSCORE */
2225 /* free(symbol_name_copy); */
2226 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2227 def_symbol_in_progress
->sy_number
= ~0;
2228 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2229 S_SET_VALUE (def_symbol_in_progress
, 0);
2231 if (S_IS_STRING (def_symbol_in_progress
))
2232 SF_SET_STRING (def_symbol_in_progress
);
2234 *input_line_pointer
= name_end
;
2236 demand_empty_rest_of_line ();
2239 unsigned int dim_index
;
2243 obj_coff_endef (ignore
)
2244 int ignore ATTRIBUTE_UNUSED
;
2246 symbolS
*symbolP
= 0;
2247 /* DIM BUG FIX sac@cygnus.com */
2249 if (def_symbol_in_progress
== NULL
)
2251 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2252 demand_empty_rest_of_line ();
2254 } /* if not inside .def/.endef */
2256 /* Set the section number according to storage class. */
2257 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2262 SF_SET_TAG (def_symbol_in_progress
);
2263 /* intentional fallthrough */
2266 SF_SET_DEBUG (def_symbol_in_progress
);
2267 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2271 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2272 /* intentional fallthrough */
2274 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2275 /* intentional fallthrough */
2277 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2279 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2281 if (function_lineoff
< 0)
2283 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2284 } /* missing function symbol */
2285 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2287 SF_SET_PROCESS (last_line_symbol
);
2288 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2289 SF_SET_PROCESS (def_symbol_in_progress
);
2290 function_lineoff
= -1;
2292 /* Value is always set to . */
2293 def_symbol_in_progress
->sy_frag
= frag_now
;
2294 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2299 #endif /* C_AUTOARG */
2309 SF_SET_DEBUG (def_symbol_in_progress
);
2310 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2320 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2326 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2328 } /* switch on storage class */
2330 /* Now that we have built a debug symbol, try to find if we should
2331 merge with an existing symbol or not. If a symbol is C_EFCN or
2332 absolute_section or untagged SEG_DEBUG it never merges. We also
2333 don't merge labels, which are in a different namespace, nor
2334 symbols which have not yet been defined since they are typically
2335 unique, nor do we merge tags with non-tags. */
2337 /* Two cases for functions. Either debug followed by definition or
2338 definition followed by debug. For definition first, we will
2339 merge the debug symbol into the definition. For debug first, the
2340 lineno entry MUST point to the definition function or else it
2341 will point off into space when crawl_symbols() merges the debug
2342 symbol into the real symbol. Therefor, let's presume the debug
2343 symbol is a real function reference. */
2345 /* FIXME-SOON If for some reason the definition label/symbol is
2346 never seen, this will probably leave an undefined symbol at link
2349 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2350 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2351 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2352 && !SF_GET_TAG (def_symbol_in_progress
))
2353 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2354 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2355 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2356 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2358 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2363 /* This symbol already exists, merge the newly created symbol
2364 into the old one. This is not mandatory. The linker can
2365 handle duplicate symbols correctly. But I guess that it save
2366 a *lot* of space if the assembly file defines a lot of
2369 /* The debug entry (def_symbol_in_progress) is merged into the
2370 previous definition. */
2372 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2373 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2374 def_symbol_in_progress
= symbolP
;
2376 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2377 || SF_GET_TAG (def_symbol_in_progress
)
2378 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2380 /* For functions, and tags, and static symbols, the symbol
2381 *must* be where the debug symbol appears. Move the
2382 existing symbol to the current place. */
2383 /* If it already is at the end of the symbol list, do nothing */
2384 if (def_symbol_in_progress
!= symbol_lastP
)
2386 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2388 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2389 &symbol_rootP
, &symbol_lastP
);
2390 } /* if not already in place */
2392 } /* normal or mergable */
2394 if (SF_GET_TAG (def_symbol_in_progress
))
2398 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2400 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2401 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2402 def_symbol_in_progress
);
2405 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2407 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2409 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2411 SF_SET_PROCESS (def_symbol_in_progress
);
2413 if (symbolP
== NULL
)
2415 /* That is, if this is the first time we've seen the
2417 symbol_table_insert (def_symbol_in_progress
);
2418 } /* definition follows debug */
2419 } /* Create the line number entry pointing to the function being defined */
2421 def_symbol_in_progress
= NULL
;
2422 demand_empty_rest_of_line ();
2426 obj_coff_dim (ignore
)
2427 int ignore ATTRIBUTE_UNUSED
;
2431 if (def_symbol_in_progress
== NULL
)
2433 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2434 demand_empty_rest_of_line ();
2436 } /* if not inside .def/.endef */
2438 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2440 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2442 SKIP_WHITESPACES ();
2443 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2444 get_absolute_expression ());
2446 switch (*input_line_pointer
)
2449 input_line_pointer
++;
2453 as_warn (_("badly formed .dim directive ignored"));
2454 /* intentional fallthrough */
2462 demand_empty_rest_of_line ();
2466 obj_coff_line (ignore
)
2467 int ignore ATTRIBUTE_UNUSED
;
2472 if (def_symbol_in_progress
== NULL
)
2478 name
= S_GET_NAME (def_symbol_in_progress
);
2479 this_base
= get_absolute_expression ();
2481 /* Only .bf symbols indicate the use of a new base line number; the
2482 line numbers associated with .ef, .bb, .eb are relative to the
2483 start of the containing function. */
2484 if (!strcmp (".bf", name
))
2486 #if 0 /* XXX Can we ever have line numbers going backwards? */
2487 if (this_base
> line_base
)
2490 line_base
= this_base
;
2498 listing_source_line ((unsigned int) line_base
);
2504 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2505 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2507 demand_empty_rest_of_line ();
2511 obj_coff_size (ignore
)
2512 int ignore ATTRIBUTE_UNUSED
;
2514 if (def_symbol_in_progress
== NULL
)
2516 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2517 demand_empty_rest_of_line ();
2519 } /* if not inside .def/.endef */
2521 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2522 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2523 demand_empty_rest_of_line ();
2527 obj_coff_scl (ignore
)
2528 int ignore ATTRIBUTE_UNUSED
;
2530 if (def_symbol_in_progress
== NULL
)
2532 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2533 demand_empty_rest_of_line ();
2535 } /* if not inside .def/.endef */
2537 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2538 demand_empty_rest_of_line ();
2542 obj_coff_tag (ignore
)
2543 int ignore ATTRIBUTE_UNUSED
;
2548 if (def_symbol_in_progress
== NULL
)
2550 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2551 demand_empty_rest_of_line ();
2555 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2556 symbol_name
= input_line_pointer
;
2557 name_end
= get_symbol_end ();
2558 #ifdef tc_canonicalize_symbol_name
2559 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2562 /* Assume that the symbol referred to by .tag is always defined.
2563 This was a bad assumption. I've added find_or_make. xoxorich. */
2564 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2565 (long) tag_find_or_make (symbol_name
));
2566 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2568 as_warn (_("tag not found for .tag %s"), symbol_name
);
2571 SF_SET_TAGGED (def_symbol_in_progress
);
2572 *input_line_pointer
= name_end
;
2574 demand_empty_rest_of_line ();
2578 obj_coff_type (ignore
)
2579 int ignore ATTRIBUTE_UNUSED
;
2581 if (def_symbol_in_progress
== NULL
)
2583 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2584 demand_empty_rest_of_line ();
2586 } /* if not inside .def/.endef */
2588 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2590 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2591 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2593 SF_SET_FUNCTION (def_symbol_in_progress
);
2594 } /* is a function */
2596 demand_empty_rest_of_line ();
2600 obj_coff_val (ignore
)
2601 int ignore ATTRIBUTE_UNUSED
;
2603 if (def_symbol_in_progress
== NULL
)
2605 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2606 demand_empty_rest_of_line ();
2608 } /* if not inside .def/.endef */
2610 if (is_name_beginner (*input_line_pointer
))
2612 char *symbol_name
= input_line_pointer
;
2613 char name_end
= get_symbol_end ();
2615 #ifdef tc_canonicalize_symbol_name
2616 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2619 if (!strcmp (symbol_name
, "."))
2621 def_symbol_in_progress
->sy_frag
= frag_now
;
2622 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2623 /* If the .val is != from the .def (e.g. statics) */
2625 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2627 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2628 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2629 symbol_find_or_make (symbol_name
);
2630 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2631 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2633 /* If the segment is undefined when the forward reference is
2634 resolved, then copy the segment id from the forward
2636 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2638 /* FIXME: gcc can generate address expressions here in
2639 unusual cases (search for "obscure" in sdbout.c). We
2640 just ignore the offset here, thus generating incorrect
2641 debugging information. We ignore the rest of the line
2644 /* Otherwise, it is the name of a non debug symbol and
2645 its value will be calculated later. */
2646 *input_line_pointer
= name_end
;
2648 /* FIXME: this is to avoid an error message in the
2649 FIXME case mentioned just above. */
2650 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2651 ++input_line_pointer
;
2655 S_SET_VALUE (def_symbol_in_progress
,
2656 (valueT
) get_absolute_expression ());
2657 } /* if symbol based */
2659 demand_empty_rest_of_line ();
2664 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2665 read.c, which then calls this object file format specific routine. */
2668 obj_coff_pe_handle_link_once (type
)
2669 enum linkonce_type type
;
2671 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2673 /* We store the type in the seg_info structure, and use it to set up
2674 the auxiliary entry for the section symbol in c_section_symbol. */
2675 seg_info (now_seg
)->linkonce
= type
;
2681 coff_obj_read_begin_hook ()
2683 /* These had better be the same. Usually 18 bytes. */
2685 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2686 know (SYMESZ
== AUXESZ
);
2691 /* This function runs through the symbol table and puts all the
2692 externals onto another chain */
2694 /* The chain of globals. */
2695 symbolS
*symbol_globalP
;
2696 symbolS
*symbol_global_lastP
;
2698 /* The chain of externals */
2699 symbolS
*symbol_externP
;
2700 symbolS
*symbol_extern_lastP
;
2703 symbolS
*last_functionP
;
2704 static symbolS
*last_bfP
;
2711 unsigned int symbol_number
= 0;
2712 unsigned int last_file_symno
= 0;
2714 struct filename_list
*filename_list_scan
= filename_list_head
;
2716 for (symbolP
= symbol_rootP
;
2718 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2720 if (symbolP
->sy_mri_common
)
2722 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2724 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2726 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2727 as_bad (_("%s: global symbols not supported in common sections"),
2728 S_GET_NAME (symbolP
));
2729 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2733 if (!SF_GET_DEBUG (symbolP
))
2735 /* Debug symbols do not need all this rubbish */
2736 symbolS
*real_symbolP
;
2738 /* L* and C_EFCN symbols never merge. */
2739 if (!SF_GET_LOCAL (symbolP
)
2740 && !SF_GET_STATICS (symbolP
)
2741 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2742 && symbolP
->sy_value
.X_op
== O_constant
2743 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2744 && real_symbolP
!= symbolP
)
2746 /* FIXME-SOON: where do dups come from?
2747 Maybe tag references before definitions? xoxorich. */
2748 /* Move the debug data from the debug symbol to the
2749 real symbol. Do NOT do the oposite (i.e. move from
2750 real symbol to debug symbol and remove real symbol from the
2751 list.) Because some pointers refer to the real symbol
2752 whereas no pointers refer to the debug symbol. */
2753 c_symbol_merge (symbolP
, real_symbolP
);
2754 /* Replace the current symbol by the real one */
2755 /* The symbols will never be the last or the first
2756 because : 1st symbol is .file and 3 last symbols are
2757 .text, .data, .bss */
2758 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2759 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2760 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2761 symbolP
= real_symbolP
;
2762 } /* if not local but dup'd */
2764 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2766 S_SET_SEGMENT (symbolP
, SEG_E0
);
2767 } /* push data into text */
2769 resolve_symbol_value (symbolP
, 1);
2771 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2773 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2775 S_SET_EXTERNAL (symbolP
);
2777 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2779 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2783 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2787 /* Mainly to speed up if not -g */
2788 if (SF_GET_PROCESS (symbolP
))
2790 /* Handle the nested blocks auxiliary info. */
2791 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2793 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2794 stack_push (block_stack
, (char *) &symbolP
);
2797 register symbolS
*begin_symbolP
;
2798 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2799 if (begin_symbolP
== (symbolS
*) 0)
2800 as_warn (_("mismatched .eb"));
2802 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2805 /* If we are able to identify the type of a function, and we
2806 are out of a function (last_functionP == 0) then, the
2807 function symbol will be associated with an auxiliary
2809 if (last_functionP
== (symbolS
*) 0 &&
2810 SF_GET_FUNCTION (symbolP
))
2812 last_functionP
= symbolP
;
2814 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2816 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2817 } /* make it at least 1 */
2819 /* Clobber possible stale .dim information. */
2821 /* Iffed out by steve - this fries the lnnoptr info too */
2822 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2823 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2826 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2828 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2830 if (last_bfP
!= NULL
)
2831 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2835 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2837 /* I don't even know if this is needed for sdb. But
2838 the standard assembler generates it, so... */
2839 if (last_functionP
== (symbolS
*) 0)
2840 as_fatal (_("C_EFCN symbol out of scope"));
2841 SA_SET_SYM_FSIZE (last_functionP
,
2842 (long) (S_GET_VALUE (symbolP
) -
2843 S_GET_VALUE (last_functionP
)));
2844 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2845 last_functionP
= (symbolS
*) 0;
2849 else if (SF_GET_TAG (symbolP
))
2851 /* First descriptor of a structure must point to
2852 the first slot after the structure description. */
2853 last_tagP
= symbolP
;
2856 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2858 /* +2 take in account the current symbol */
2859 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2861 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2863 /* If the filename was too long to fit in the
2864 auxent, put it in the string table */
2865 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2866 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2868 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2869 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2870 filename_list_scan
= filename_list_scan
->next
;
2872 if (S_GET_VALUE (symbolP
))
2874 S_SET_VALUE (symbolP
, last_file_symno
);
2875 last_file_symno
= symbol_number
;
2876 } /* no one points at the first .file symbol */
2877 } /* if debug or tag or eos or file */
2879 #ifdef tc_frob_coff_symbol
2880 tc_frob_coff_symbol (symbolP
);
2883 /* We must put the external symbols apart. The loader
2884 does not bomb if we do not. But the references in
2885 the endndx field for a .bb symbol are not corrected
2886 if an external symbol is removed between .bb and .be.
2887 I.e in the following case :
2888 [20] .bb endndx = 22
2891 ld will move the symbol 21 to the end of the list but
2892 endndx will still be 22 instead of 21. */
2895 if (SF_GET_LOCAL (symbolP
))
2897 /* remove C_EFCN and LOCAL (L...) symbols */
2898 /* next pointer remains valid */
2899 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2902 else if (symbolP
->sy_value
.X_op
== O_symbol
2903 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2905 /* Skip symbols which were equated to undefined or common
2907 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2909 else if (!S_IS_DEFINED (symbolP
)
2910 && !S_IS_DEBUG (symbolP
)
2911 && !SF_GET_STATICS (symbolP
)
2912 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2914 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2916 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
2918 /* if external, Remove from the list */
2919 symbolS
*hold
= symbol_previous (symbolP
);
2921 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2922 symbol_clear_list_pointers (symbolP
);
2923 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2926 else if (! S_IS_DEBUG (symbolP
)
2927 && ! SF_GET_STATICS (symbolP
)
2928 && ! SF_GET_FUNCTION (symbolP
)
2929 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2931 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2933 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
2935 symbolS
*hold
= symbol_previous (symbolP
);
2937 /* The O'Reilly COFF book says that defined global symbols
2938 come at the end of the symbol table, just before
2939 undefined global symbols. */
2941 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2942 symbol_clear_list_pointers (symbolP
);
2943 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2944 &symbol_global_lastP
);
2949 if (SF_GET_STRING (symbolP
))
2951 symbolP
->sy_name_offset
= string_byte_count
;
2952 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2956 symbolP
->sy_name_offset
= 0;
2957 } /* fix "long" names */
2959 symbolP
->sy_number
= symbol_number
;
2960 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2961 } /* if local symbol */
2962 } /* traverse the symbol list */
2963 return symbol_number
;
2969 glue_symbols (head
, tail
)
2973 unsigned int symbol_number
= 0;
2975 while (*head
!= NULL
)
2977 symbolS
*tmp
= *head
;
2980 symbol_remove (tmp
, head
, tail
);
2981 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2984 if (SF_GET_STRING (tmp
))
2986 tmp
->sy_name_offset
= string_byte_count
;
2987 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2991 tmp
->sy_name_offset
= 0;
2992 } /* fix "long" names */
2994 tmp
->sy_number
= symbol_number
;
2995 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2996 } /* append the entire extern chain */
2998 return symbol_number
;
3004 unsigned int symbol_number
= 0;
3007 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3009 symbolP
->sy_number
= symbol_number
;
3011 if (SF_GET_TAGGED (symbolP
))
3015 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3018 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3021 return symbol_number
;
3025 crawl_symbols (h
, abfd
)
3027 bfd
*abfd ATTRIBUTE_UNUSED
;
3031 /* Initialize the stack used to keep track of the matching .bb .be */
3033 block_stack
= stack_init (512, sizeof (symbolS
*));
3035 /* The symbol list should be ordered according to the following sequence
3038 * . debug entries for functions
3039 * . fake symbols for the sections, including .text .data and .bss
3041 * . undefined symbols
3042 * But this is not mandatory. The only important point is to put the
3043 * undefined symbols at the end of the list.
3046 /* Is there a .file symbol ? If not insert one at the beginning. */
3047 if (symbol_rootP
== NULL
3048 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3050 c_dot_file_symbol ("fake");
3054 * Build up static symbols for the sections, they are filled in later
3058 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3059 if (segment_info
[i
].scnhdr
.s_name
[0])
3060 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3063 /* Take all the externals out and put them into another chain */
3064 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3065 /* Take the externals and glue them onto the end.*/
3066 H_SET_SYMBOL_TABLE_SIZE (h
,
3067 (H_GET_SYMBOL_COUNT (h
)
3068 + glue_symbols (&symbol_globalP
,
3069 &symbol_global_lastP
)
3070 + glue_symbols (&symbol_externP
,
3071 &symbol_extern_lastP
)));
3073 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3074 know (symbol_globalP
== NULL
);
3075 know (symbol_global_lastP
== NULL
);
3076 know (symbol_externP
== NULL
);
3077 know (symbol_extern_lastP
== NULL
);
3081 * Find strings by crawling along symbol table chain.
3089 struct filename_list
*filename_list_scan
= filename_list_head
;
3091 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3092 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3095 #ifdef COFF_LONG_SECTION_NAMES
3096 /* Support long section names as found in PE. This code must
3097 coordinate with that in coff_header_append and write_object_file. */
3101 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3103 if (segment_info
[i
].scnhdr
.s_name
[0]
3104 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3108 size
= strlen (segment_info
[i
].name
) + 1;
3109 memcpy (where
, segment_info
[i
].name
, size
);
3114 #endif /* COFF_LONG_SECTION_NAMES */
3116 for (symbolP
= symbol_rootP
;
3118 symbolP
= symbol_next (symbolP
))
3122 if (SF_GET_STRING (symbolP
))
3124 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3125 memcpy (where
, S_GET_NAME (symbolP
), size
);
3128 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3129 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3130 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3132 size
= strlen (filename_list_scan
->filename
) + 1;
3133 memcpy (where
, filename_list_scan
->filename
, size
);
3134 filename_list_scan
= filename_list_scan
->next
;
3141 do_linenos_for (abfd
, h
, file_cursor
)
3144 unsigned long *file_cursor
;
3147 unsigned long start
= *file_cursor
;
3149 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3151 segment_info_type
*s
= segment_info
+ idx
;
3154 if (s
->scnhdr
.s_nlnno
!= 0)
3156 struct lineno_list
*line_ptr
;
3158 struct external_lineno
*buffer
=
3159 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3161 struct external_lineno
*dst
= buffer
;
3163 /* Run through the table we've built and turn it into its external
3164 form, take this chance to remove duplicates */
3166 for (line_ptr
= s
->lineno_list_head
;
3167 line_ptr
!= (struct lineno_list
*) NULL
;
3168 line_ptr
= line_ptr
->next
)
3171 if (line_ptr
->line
.l_lnno
== 0)
3173 /* Turn a pointer to a symbol into the symbols' index */
3174 line_ptr
->line
.l_addr
.l_symndx
=
3175 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3179 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3183 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3188 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3190 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3193 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3196 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3200 /* Now we run through the list of frag chains in a segment and
3201 make all the subsegment frags appear at the end of the
3202 list, as if the seg 0 was extra long */
3209 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3211 frchainS
*head
= segment_info
[i
].frchainP
;
3213 fragS
*prev_frag
= &dummy
;
3215 while (head
&& head
->frch_seg
== i
)
3217 prev_frag
->fr_next
= head
->frch_root
;
3218 prev_frag
= head
->frch_last
;
3219 head
= head
->frch_next
;
3221 prev_frag
->fr_next
= 0;
3225 unsigned long machine
;
3228 write_object_file ()
3232 struct frchain
*frchain_ptr
;
3234 object_headers headers
;
3235 unsigned long file_cursor
;
3238 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3243 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3244 exit (EXIT_FAILURE
);
3246 bfd_set_format (abfd
, bfd_object
);
3247 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3249 string_byte_count
= 4;
3251 for (frchain_ptr
= frchain_root
;
3252 frchain_ptr
!= (struct frchain
*) NULL
;
3253 frchain_ptr
= frchain_ptr
->frch_next
)
3255 /* Run through all the sub-segments and align them up. Also
3256 close any open frags. We tack a .fill onto the end of the
3257 frag chain so that any .align's size can be worked by looking
3258 at the next frag. */
3260 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3262 #ifndef SUB_SEGMENT_ALIGN
3263 #define SUB_SEGMENT_ALIGN(SEG) 1
3266 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3269 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3270 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3275 frag_wane (frag_now
);
3276 frag_now
->fr_fix
= 0;
3277 know (frag_now
->fr_next
== NULL
);
3284 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3286 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3289 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3291 /* Find out how big the sections are, and set the addresses. */
3293 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3297 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3298 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3300 if (segment_info
[i
].scnhdr
.s_name
[0])
3302 H_SET_NUMBER_OF_SECTIONS (&headers
,
3303 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3305 #ifdef COFF_LONG_SECTION_NAMES
3306 /* Support long section names as found in PE. This code
3307 must coordinate with that in coff_header_append and
3312 len
= strlen (segment_info
[i
].name
);
3314 string_byte_count
+= len
+ 1;
3316 #endif /* COFF_LONG_SECTION_NAMES */
3319 size
= size_section (abfd
, (unsigned int) i
);
3322 /* I think the section alignment is only used on the i960; the
3323 i960 needs it, and it should do no harm on other targets. */
3324 #ifdef ALIGNMENT_IN_S_FLAGS
3325 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3327 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3331 H_SET_TEXT_SIZE (&headers
, size
);
3332 else if (i
== SEG_E1
)
3333 H_SET_DATA_SIZE (&headers
, size
);
3334 else if (i
== SEG_E2
)
3335 H_SET_BSS_SIZE (&headers
, size
);
3338 /* Turn the gas native symbol table shape into a coff symbol table */
3339 crawl_symbols (&headers
, abfd
);
3341 if (string_byte_count
== 4)
3342 string_byte_count
= 0;
3344 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3350 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3352 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3353 fixup_segment (&segment_info
[i
], i
);
3356 /* Look for ".stab" segments and fill in their initial symbols
3358 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3360 name
= segment_info
[i
].name
;
3363 && strncmp (".stab", name
, 5) == 0
3364 && strncmp (".stabstr", name
, 8) != 0)
3365 adjust_stab_section (abfd
, i
);
3368 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3370 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3372 /* Plant the data */
3374 fill_section (abfd
, &headers
, &file_cursor
);
3376 do_relocs_for (abfd
, &headers
, &file_cursor
);
3378 do_linenos_for (abfd
, &headers
, &file_cursor
);
3380 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3381 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3382 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3384 H_SET_TIME_STAMP (&headers
, 0);
3386 #ifdef TC_COFF_SET_MACHINE
3387 TC_COFF_SET_MACHINE (&headers
);
3391 #define COFF_FLAGS 0
3394 #ifdef KEEP_RELOC_INFO
3395 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3396 COFF_FLAGS
| coff_flags
));
3398 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3399 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3400 COFF_FLAGS
| coff_flags
));
3404 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3405 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3407 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3408 w_symbols (abfd
, buffer1
, symbol_rootP
);
3409 if (string_byte_count
> 0)
3410 w_strings (buffer1
+ symtable_size
);
3411 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3415 coff_header_append (abfd
, &headers
);
3417 /* Recent changes to write need this, but where it should
3418 go is up to Ken.. */
3419 if (bfd_close_all_done (abfd
) == false)
3420 as_fatal (_("Can't close %s: %s"), out_file_name
,
3421 bfd_errmsg (bfd_get_error ()));
3424 extern bfd
*stdoutput
;
3431 /* Add a new segment. This is called from subseg_new via the
3432 obj_new_segment macro. */
3435 obj_coff_add_segment (name
)
3440 #ifndef COFF_LONG_SECTION_NAMES
3441 char buf
[SCNNMLEN
+ 1];
3443 strncpy (buf
, name
, SCNNMLEN
);
3444 buf
[SCNNMLEN
] = '\0';
3448 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3449 if (strcmp (name
, segment_info
[i
].name
) == 0)
3454 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3458 /* Add a new section. */
3459 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3460 sizeof (segment_info
[i
].scnhdr
.s_name
));
3461 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3462 segment_info
[i
].name
= xstrdup (name
);
3468 * implement the .section pseudo op:
3469 * .section name {, "flags"}
3471 * | +--- optional flags: 'b' for bss
3473 * +-- section name 'l' for lib
3477 * 'd' (apparently m88k for data)
3479 * 'r' for read-only data
3480 * But if the argument is not a quoted string, treat it as a
3481 * subsegment number.
3485 obj_coff_section (ignore
)
3486 int ignore ATTRIBUTE_UNUSED
;
3488 /* Strip out the section name */
3489 char *section_name
, *name
;
3502 else if (type
== 'D')
3504 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3509 section_name
= input_line_pointer
;
3510 c
= get_symbol_end ();
3512 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3513 strcpy (name
, section_name
);
3515 *input_line_pointer
= c
;
3521 if (*input_line_pointer
== ',')
3523 ++input_line_pointer
;
3526 if (*input_line_pointer
!= '"')
3527 exp
= get_absolute_expression ();
3530 ++input_line_pointer
;
3531 while (*input_line_pointer
!= '"'
3532 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3534 switch (*input_line_pointer
)
3536 case 'b': flags
|= STYP_BSS
; break;
3537 case 'i': flags
|= STYP_INFO
; break;
3538 case 'l': flags
|= STYP_LIB
; break;
3539 case 'n': flags
|= STYP_NOLOAD
; break;
3540 case 'o': flags
|= STYP_OVER
; break;
3542 case 'w': flags
|= STYP_DATA
; break;
3543 case 'x': flags
|= STYP_TEXT
; break;
3544 case 'r': flags
|= STYP_LIT
; break;
3546 as_warn(_("unknown section attribute '%c'"),
3547 *input_line_pointer
);
3550 ++input_line_pointer
;
3552 if (*input_line_pointer
== '"')
3553 ++input_line_pointer
;
3557 subseg_new (name
, (subsegT
) exp
);
3559 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3561 demand_empty_rest_of_line ();
3566 obj_coff_text (ignore
)
3567 int ignore ATTRIBUTE_UNUSED
;
3569 subseg_new (".text", get_absolute_expression ());
3574 obj_coff_data (ignore
)
3575 int ignore ATTRIBUTE_UNUSED
;
3577 if (flag_readonly_data_in_text
)
3578 subseg_new (".text", get_absolute_expression () + 1000);
3580 subseg_new (".data", get_absolute_expression ());
3584 obj_coff_ident (ignore
)
3585 int ignore ATTRIBUTE_UNUSED
;
3587 segT current_seg
= now_seg
; /* save current seg */
3588 subsegT current_subseg
= now_subseg
;
3589 subseg_new (".comment", 0); /* .comment seg */
3590 stringer (1); /* read string */
3591 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3595 c_symbol_merge (debug
, normal
)
3599 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3600 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3602 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3604 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3605 } /* take the most we have */
3607 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3609 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3610 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3611 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3612 } /* Move all the auxiliary information */
3614 /* Move the debug flags. */
3615 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3616 } /* c_symbol_merge() */
3619 c_line_new (symbol
, paddr
, line_number
, frag
)
3625 struct lineno_list
*new_line
=
3626 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3628 segment_info_type
*s
= segment_info
+ now_seg
;
3629 new_line
->line
.l_lnno
= line_number
;
3631 if (line_number
== 0)
3633 last_line_symbol
= symbol
;
3634 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3638 new_line
->line
.l_addr
.l_paddr
= paddr
;
3641 new_line
->frag
= (char *) frag
;
3642 new_line
->next
= (struct lineno_list
*) NULL
;
3645 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3647 s
->lineno_list_head
= new_line
;
3651 s
->lineno_list_tail
->next
= new_line
;
3653 s
->lineno_list_tail
= new_line
;
3654 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3658 c_dot_file_symbol (filename
)
3663 symbolP
= symbol_new (".file",
3666 &zero_address_frag
);
3668 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3669 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3671 if (strlen (filename
) > FILNMLEN
)
3673 /* Filename is too long to fit into an auxent,
3674 we stick it into the string table instead. We keep
3675 a linked list of the filenames we find so we can emit
3677 struct filename_list
*f
= ((struct filename_list
*)
3678 xmalloc (sizeof (struct filename_list
)));
3680 f
->filename
= filename
;
3683 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3684 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3686 if (filename_list_tail
)
3687 filename_list_tail
->next
= f
;
3689 filename_list_head
= f
;
3690 filename_list_tail
= f
;
3694 SA_SET_FILE_FNAME (symbolP
, filename
);
3701 listing_source_file (filename
);
3707 SF_SET_DEBUG (symbolP
);
3708 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3710 previous_file_symbol
= symbolP
;
3712 /* Make sure that the symbol is first on the symbol chain */
3713 if (symbol_rootP
!= symbolP
)
3715 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3716 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3718 } /* c_dot_file_symbol() */
3721 * Build a 'section static' symbol.
3725 c_section_symbol (name
, idx
)
3731 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3732 if (symbolP
== NULL
)
3733 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3736 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3737 S_SET_SEGMENT (symbolP
, idx
);
3738 symbolP
->sy_frag
= &zero_address_frag
;
3741 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3742 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3744 SF_SET_STATICS (symbolP
);
3747 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3748 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3749 SF_CLEAR_LOCAL (symbolP
);
3752 /* If the .linkonce pseudo-op was used for this section, we must
3753 store the information in the auxiliary entry for the section
3755 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3759 switch (segment_info
[idx
].linkonce
)
3763 case LINKONCE_DISCARD
:
3764 type
= IMAGE_COMDAT_SELECT_ANY
;
3766 case LINKONCE_ONE_ONLY
:
3767 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3769 case LINKONCE_SAME_SIZE
:
3770 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3772 case LINKONCE_SAME_CONTENTS
:
3773 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3777 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3782 } /* c_section_symbol() */
3785 w_symbols (abfd
, where
, symbol_rootP
)
3788 symbolS
* symbol_rootP
;
3793 /* First fill in those values we have only just worked out */
3794 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3796 symbolP
= segment_info
[i
].dot
;
3799 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3800 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3801 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3806 * Emit all symbols left in the symbol chain.
3808 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3810 /* Used to save the offset of the name. It is used to point
3811 to the string in memory but must be a file offset. */
3812 register char *temp
;
3814 /* We can't fix the lnnoptr field in yank_symbols with the other
3815 adjustments, because we have to wait until we know where they
3817 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3819 SA_GET_SYM_LNNOPTR (symbolP
) +=
3820 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3823 tc_coff_symbol_emit_hook (symbolP
);
3825 temp
= S_GET_NAME (symbolP
);
3826 if (SF_GET_STRING (symbolP
))
3828 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3829 S_SET_ZEROES (symbolP
, 0);
3833 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3834 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3836 where
= symbol_to_chars (abfd
, where
, symbolP
);
3837 S_SET_NAME (symbolP
, temp
);
3843 obj_coff_lcomm (ignore
)
3844 int ignore ATTRIBUTE_UNUSED
;
3856 name
= input_line_pointer
;
3858 c
= get_symbol_end ();
3859 p
= input_line_pointer
;
3862 if (*input_line_pointer
!= ',')
3864 as_bad (_("Expected comma after name"));
3865 ignore_rest_of_line ();
3868 if (*input_line_pointer
== '\n')
3870 as_bad (_("Missing size expression"));
3873 input_line_pointer
++;
3874 if ((temp
= get_absolute_expression ()) < 0)
3876 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3877 ignore_rest_of_line ();
3882 symbolP
= symbol_find_or_make(name
);
3884 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3885 S_GET_VALUE(symbolP
) == 0)
3890 segT current_seg
= now_seg
; /* save current seg */
3891 subsegT current_subseg
= now_subseg
;
3893 subseg_set (SEG_E2
, 1);
3894 symbolP
->sy_frag
= frag_now
;
3895 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3896 (offsetT
) temp
, (char *) 0);
3898 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3899 S_SET_SEGMENT(symbolP
, SEG_E2
);
3900 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3904 as_bad(_("Symbol %s already defined"), name
);
3906 demand_empty_rest_of_line();
3911 fixup_mdeps (frags
, h
, this_segment
)
3916 subseg_change (this_segment
, 0);
3919 switch (frags
->fr_type
)
3925 HANDLE_ALIGN (frags
);
3927 frags
->fr_type
= rs_fill
;
3929 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3932 case rs_machine_dependent
:
3933 md_convert_frag (h
, this_segment
, frags
);
3939 frags
= frags
->fr_next
;
3945 #ifndef TC_FORCE_RELOCATION
3946 #define TC_FORCE_RELOCATION(fix) 0
3950 fixup_segment (segP
, this_segment_type
)
3951 segment_info_type
* segP
;
3952 segT this_segment_type
;
3954 register fixS
* fixP
;
3955 register symbolS
*add_symbolP
;
3956 register symbolS
*sub_symbolP
;
3959 register char *place
;
3960 register long where
;
3961 register char pcrel
;
3962 register fragS
*fragP
;
3963 register segT add_symbol_segment
= absolute_section
;
3965 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3967 fragP
= fixP
->fx_frag
;
3969 where
= fixP
->fx_where
;
3970 place
= fragP
->fr_literal
+ where
;
3971 size
= fixP
->fx_size
;
3972 add_symbolP
= fixP
->fx_addsy
;
3973 sub_symbolP
= fixP
->fx_subsy
;
3974 add_number
= fixP
->fx_offset
;
3975 pcrel
= fixP
->fx_pcrel
;
3977 /* We want function-relative stabs to work on systems which
3978 may use a relaxing linker; thus we must handle the sym1-sym2
3979 fixups function-relative stabs generates.
3981 Of course, if you actually enable relaxing in the linker, the
3982 line and block scoping information is going to be incorrect
3983 in some cases. The only way to really fix this is to support
3984 a reloc involving the difference of two symbols. */
3986 && (!sub_symbolP
|| pcrel
))
3990 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3992 /* Relocation should be done via the associated 'bal' entry
3995 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3997 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3998 _("No 'bal' entry point for leafproc %s"),
3999 S_GET_NAME (add_symbolP
));
4002 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4006 /* Make sure the symbols have been resolved; this may not have
4007 happened if these are expression symbols. */
4008 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4009 resolve_symbol_value (add_symbolP
, 1);
4011 if (add_symbolP
!= NULL
)
4013 /* If this fixup is against a symbol which has been equated
4014 to another symbol, convert it to the other symbol. */
4015 if (add_symbolP
->sy_value
.X_op
== O_symbol
4016 && (! S_IS_DEFINED (add_symbolP
)
4017 || S_IS_COMMON (add_symbolP
)))
4019 while (add_symbolP
->sy_value
.X_op
== O_symbol
4020 && (! S_IS_DEFINED (add_symbolP
)
4021 || S_IS_COMMON (add_symbolP
)))
4025 /* We must avoid looping, as that can occur with a
4026 badly written program. */
4027 n
= add_symbolP
->sy_value
.X_add_symbol
;
4028 if (n
== add_symbolP
)
4030 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4033 fixP
->fx_addsy
= add_symbolP
;
4034 fixP
->fx_offset
= add_number
;
4038 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4039 resolve_symbol_value (sub_symbolP
, 1);
4041 if (add_symbolP
!= NULL
4042 && add_symbolP
->sy_mri_common
)
4044 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4045 add_number
+= S_GET_VALUE (add_symbolP
);
4046 fixP
->fx_offset
= add_number
;
4047 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4052 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4053 } /* if there is an addend */
4057 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4059 if (add_symbolP
!= NULL
)
4061 add_number
+= S_GET_VALUE (add_symbolP
);
4063 fixP
->fx_addsy
= NULL
;
4066 /* It's just -sym. */
4067 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4069 add_number
-= S_GET_VALUE (sub_symbolP
);
4076 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4077 _("Negative of non-absolute symbol %s"),
4078 S_GET_NAME (sub_symbolP
));
4080 add_number
-= S_GET_VALUE (sub_symbolP
);
4081 } /* not absolute */
4083 /* if sub_symbol is in the same segment that add_symbol
4084 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4086 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4087 && SEG_NORMAL (add_symbol_segment
))
4089 /* Difference of 2 symbols from same segment. Can't
4090 make difference of 2 undefineds: 'value' means
4091 something different for N_UNDF. */
4093 /* Makes no sense to use the difference of 2 arbitrary symbols
4094 as the target of a call instruction. */
4097 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4098 _("callj to difference of 2 symbols"));
4100 #endif /* TC_I960 */
4101 add_number
+= S_GET_VALUE (add_symbolP
) -
4102 S_GET_VALUE (sub_symbolP
);
4105 if (!TC_FORCE_RELOCATION (fixP
))
4107 fixP
->fx_addsy
= NULL
;
4108 fixP
->fx_subsy
= NULL
;
4110 #ifdef TC_M68K /* is this right? */
4118 /* Different segments in subtraction. */
4119 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4121 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4123 add_number
-= S_GET_VALUE (sub_symbolP
);
4126 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4127 #if 0 /* Okay for 68k, at least... */
4132 /* Make it pc-relative. */
4133 add_number
+= (md_pcrel_from (fixP
)
4134 - S_GET_VALUE (sub_symbolP
));
4143 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4144 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4145 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4146 S_GET_NAME (sub_symbolP
),
4147 (long) (fragP
->fr_address
+ where
));
4150 } /* if sub_symbolP */
4154 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4157 * This fixup was made when the symbol's segment was
4158 * SEG_UNKNOWN, but it is now in the local segment.
4159 * So we know how to do the address without relocation.
4162 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4163 * in which cases it modifies *fixP as appropriate. In the case
4164 * of a 'calls', no further work is required, and *fixP has been
4165 * set up to make the rest of the code below a no-op.
4168 #endif /* TC_I960 */
4170 add_number
+= S_GET_VALUE (add_symbolP
);
4171 add_number
-= md_pcrel_from (fixP
);
4174 add_number -= segP->scnhdr.s_vaddr;
4175 if defined (TC_I386) || defined (TE_LYNX). I now
4176 think that was an error propagated from the case when
4177 we are going to emit the relocation. If we are not
4178 going to emit the relocation, then we just want to
4179 set add_number to the difference between the symbols.
4180 This is a case that would only arise when there is a
4181 PC relative reference from a section other than .text
4182 to a symbol defined in the same section, and the
4183 reference is not relaxed. Since jump instructions on
4184 the i386 are relaxed, this could only arise with a
4185 call instruction. */
4187 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4188 if (!TC_FORCE_RELOCATION (fixP
))
4190 fixP
->fx_addsy
= NULL
;
4196 switch (add_symbol_segment
)
4198 case absolute_section
:
4200 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4201 #endif /* TC_I960 */
4202 add_number
+= S_GET_VALUE (add_symbolP
);
4205 if (!TC_FORCE_RELOCATION (fixP
))
4207 fixP
->fx_addsy
= NULL
;
4214 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4215 /* This really should be handled in the linker, but
4216 backward compatibility forbids. */
4217 add_number
+= S_GET_VALUE (add_symbolP
);
4219 add_number
+= S_GET_VALUE (add_symbolP
) +
4220 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4226 if ((int) fixP
->fx_bit_fixP
== 13)
4228 /* This is a COBR instruction. They have only a
4229 * 13-bit displacement and are only to be used
4230 * for local branches: flag as error, don't generate
4233 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4234 _("can't use COBR format with external label"));
4235 fixP
->fx_addsy
= NULL
;
4239 #endif /* TC_I960 */
4240 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4241 /* 386 COFF uses a peculiar format in which the
4242 value of a common symbol is stored in the .text
4243 segment (I've checked this on SVR3.2 and SCO
4244 3.2.2) Ian Taylor <ian@cygnus.com>. */
4245 /* This is also true for 68k COFF on sysv machines
4246 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4247 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4248 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4249 if (S_IS_COMMON (add_symbolP
))
4250 add_number
+= S_GET_VALUE (add_symbolP
);
4255 } /* switch on symbol seg */
4256 } /* if not in local seg */
4257 } /* if there was a + symbol */
4261 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4262 /* This adjustment is not correct on the m88k, for which the
4263 linker does all the computation. */
4264 add_number
-= md_pcrel_from (fixP
);
4266 if (add_symbolP
== 0)
4268 fixP
->fx_addsy
= &abs_symbol
;
4269 } /* if there's an add_symbol */
4270 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4271 /* On the 386 we must adjust by the segment vaddr as well.
4274 I changed the i960 to work this way as well. This is
4275 compatible with the current GNU linker behaviour. I do
4276 not know what other i960 COFF assemblers do. This is not
4277 a common case: normally, only assembler code will contain
4278 a PC relative reloc, and only branches which do not
4279 originate in the .text section will have a non-zero
4282 I changed the m68k to work this way as well. This will
4283 break existing PC relative relocs from sections which do
4284 not start at address 0, but it will make ld -r work.
4285 Ian Taylor, 4 Oct 96. */
4287 add_number
-= segP
->scnhdr
.s_vaddr
;
4291 #ifdef MD_APPLY_FIX3
4292 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4294 md_apply_fix (fixP
, add_number
);
4297 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4300 /* The m88k uses the offset field of the reloc to get around
4303 && ((add_number
& ~0xFF)
4304 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4305 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4306 || (add_number
& 0x80) == 0))
4308 && ((add_number
& ~0xFFFF)
4309 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4310 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4311 || (add_number
& 0x8000) == 0)))
4313 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4314 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4315 (long) add_number
, size
,
4316 (unsigned long) (fragP
->fr_address
+ where
));
4319 #ifdef WARN_SIGNED_OVERFLOW_WORD
4320 /* Warn if a .word value is too large when treated as a
4321 signed number. We already know it is not too negative.
4322 This is to catch over-large switches generated by gcc on
4324 if (!flag_signed_overflow_ok
4326 && add_number
> 0x7fff)
4327 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4328 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4330 (unsigned long) (fragP
->fr_address
+ where
));
4332 } /* not a bit fix */
4333 } /* For each fixS in this segment. */
4334 } /* fixup_segment() */
4338 /* The first entry in a .stab section is special. */
4341 obj_coff_init_stab_section (seg
)
4347 unsigned int stroff
;
4349 /* Make space for this first symbol. */
4353 as_where (&file
, (unsigned int *) NULL
);
4354 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4355 strcpy (stabstr_name
, segment_info
[seg
].name
);
4356 strcat (stabstr_name
, "str");
4357 stroff
= get_stab_string_offset (file
, stabstr_name
);
4359 md_number_to_chars (p
, stroff
, 4);
4362 /* Fill in the counts in the first entry in a .stab section. */
4365 adjust_stab_section(abfd
, seg
)
4369 segT stabstrseg
= SEG_UNKNOWN
;
4370 const char *secname
, *name2
;
4373 int i
, strsz
= 0, nsyms
;
4374 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4376 /* Look for the associated string table section. */
4378 secname
= segment_info
[seg
].name
;
4379 name
= (char *) alloca (strlen (secname
) + 4);
4380 strcpy (name
, secname
);
4381 strcat (name
, "str");
4383 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4385 name2
= segment_info
[i
].name
;
4386 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4393 /* If we found the section, get its size. */
4394 if (stabstrseg
!= SEG_UNKNOWN
)
4395 strsz
= size_section (abfd
, stabstrseg
);
4397 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4399 /* Look for the first frag of sufficient size for the initial stab
4400 symbol, and collect a pointer to it. */
4401 while (frag
&& frag
->fr_fix
< 12)
4402 frag
= frag
->fr_next
;
4404 p
= frag
->fr_literal
;
4407 /* Write in the number of stab symbols and the size of the string
4409 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4410 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4413 #endif /* not BFD_ASSEMBLER */
4415 const pseudo_typeS obj_pseudo_table
[] =
4417 {"def", obj_coff_def
, 0},
4418 {"dim", obj_coff_dim
, 0},
4419 {"endef", obj_coff_endef
, 0},
4420 {"line", obj_coff_line
, 0},
4421 {"ln", obj_coff_ln
, 0},
4422 {"appline", obj_coff_ln
, 1},
4423 {"scl", obj_coff_scl
, 0},
4424 {"size", obj_coff_size
, 0},
4425 {"tag", obj_coff_tag
, 0},
4426 {"type", obj_coff_type
, 0},
4427 {"val", obj_coff_val
, 0},
4428 {"section", obj_coff_section
, 0},
4429 {"sect", obj_coff_section
, 0},
4430 /* FIXME: We ignore the MRI short attribute. */
4431 {"section.s", obj_coff_section
, 0},
4432 {"sect.s", obj_coff_section
, 0},
4433 /* We accept the .bss directive for backward compatibility with
4434 earlier versions of gas. */
4435 {"bss", obj_coff_bss
, 0},
4436 {"weak", obj_coff_weak
, 0},
4437 #ifndef BFD_ASSEMBLER
4438 {"use", obj_coff_section
, 0},
4439 {"text", obj_coff_text
, 0},
4440 {"data", obj_coff_data
, 0},
4441 {"lcomm", obj_coff_lcomm
, 0},
4442 {"ident", obj_coff_ident
, 0},
4444 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4445 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4447 {"version", s_ignore
, 0},
4448 {"ABORT", s_abort
, 0},
4450 /* The m88k uses sdef instead of def. */
4451 {"sdef", obj_coff_def
, 0},
4453 {NULL
, NULL
, 0} /* end sentinel */
4454 }; /* obj_pseudo_table */
4456 #ifdef BFD_ASSEMBLER
4458 static void coff_pop_insert
PARAMS ((void));
4459 static int coff_sec_sym_ok_for_reloc
PARAMS ((asection
*));
4461 /* Support for a COFF emulation. */
4466 pop_insert (obj_pseudo_table
);
4470 coff_sec_sym_ok_for_reloc (sec
)
4471 asection
*sec ATTRIBUTE_UNUSED
;
4476 const struct format_ops coff_format_ops
=
4478 bfd_target_coff_flavour
,
4483 coff_frob_file_after_relocs
,
4488 obj_generate_asm_lineno
,
4497 coff_sec_sym_ok_for_reloc
,
4504 coff_obj_read_begin_hook
,
4505 coff_obj_symbol_new_hook
,