1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
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));
45 static void obj_coff_ident
PARAMS ((int));
47 static void obj_coff_loc
PARAMS((int));
50 /* This is used to hold the symbol built by a sequence of pseudo-ops
51 from .def and .endef. */
52 static symbolS
*def_symbol_in_progress
;
57 unsigned long chunk_size
;
58 unsigned long element_size
;
61 unsigned long pointer
;
66 stack_init (chunk_size
, element_size
)
67 unsigned long chunk_size
;
68 unsigned long element_size
;
72 st
= (stack
*) malloc (sizeof (stack
));
75 st
->data
= malloc (chunk_size
);
82 st
->size
= chunk_size
;
83 st
->chunk_size
= chunk_size
;
84 st
->element_size
= element_size
;
89 /* Not currently used. */
100 stack_push (st
, element
)
104 if (st
->pointer
+ st
->element_size
>= st
->size
)
106 st
->size
+= st
->chunk_size
;
107 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
110 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
111 st
->pointer
+= st
->element_size
;
112 return st
->data
+ st
->pointer
;
119 if (st
->pointer
< st
->element_size
)
124 st
->pointer
-= st
->element_size
;
125 return st
->data
+ st
->pointer
;
129 * Maintain a list of the tagnames of the structres.
132 static struct hash_control
*tag_hash
;
137 tag_hash
= hash_new ();
141 tag_insert (name
, symbolP
)
145 const char *error_string
;
147 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
149 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
158 #ifdef STRIP_UNDERSCORE
161 #endif /* STRIP_UNDERSCORE */
162 return (symbolS
*) hash_find (tag_hash
, name
);
166 tag_find_or_make (name
)
171 if ((symbolP
= tag_find (name
)) == NULL
)
173 symbolP
= symbol_new (name
, undefined_section
,
174 0, &zero_address_frag
);
176 tag_insert (S_GET_NAME (symbolP
), symbolP
);
178 symbol_table_insert (symbolP
);
185 /* We accept the .bss directive to set the section for backward
186 compatibility with earlier versions of gas. */
189 obj_coff_bss (ignore
)
190 int ignore ATTRIBUTE_UNUSED
;
192 if (*input_line_pointer
== '\n')
193 subseg_new (".bss", get_absolute_expression ());
198 /* Handle .weak. This is a GNU extension. */
201 obj_coff_weak (ignore
)
202 int ignore ATTRIBUTE_UNUSED
;
210 name
= input_line_pointer
;
211 c
= get_symbol_end ();
212 symbolP
= symbol_find_or_make (name
);
213 *input_line_pointer
= c
;
217 S_SET_WEAK (symbolP
);
221 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
223 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
228 input_line_pointer
++;
230 if (*input_line_pointer
== '\n')
236 demand_empty_rest_of_line ();
241 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
243 #define GET_FILENAME_STRING(X) \
244 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
248 fetch_coff_debug_section ()
250 static segT debug_section
;
254 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
256 debug_section
= s
->section
;
258 return debug_section
;
262 SA_SET_SYM_ENDNDX (sym
, val
)
266 combined_entry_type
*entry
, *p
;
268 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
269 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
270 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
275 SA_SET_SYM_TAGNDX (sym
, val
)
279 combined_entry_type
*entry
, *p
;
281 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
282 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
283 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
288 S_GET_DATA_TYPE (sym
)
291 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
295 S_SET_DATA_TYPE (sym
, val
)
299 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
304 S_GET_STORAGE_CLASS (sym
)
307 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
311 S_SET_STORAGE_CLASS (sym
, val
)
315 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
319 /* Merge a debug symbol containing debug information into a normal symbol. */
322 c_symbol_merge (debug
, normal
)
326 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
327 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
329 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
331 /* take the most we have */
332 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
335 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
337 /* Move all the auxiliary information. */
338 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
339 (S_GET_NUMBER_AUXILIARY (debug
)
340 * sizeof (*SYM_AUXINFO (debug
))));
343 /* Move the debug flags. */
344 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
348 c_dot_file_symbol (filename
)
349 const char *filename
;
353 /* BFD converts filename to a .file symbol with an aux entry. It
354 also handles chaining. */
355 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
357 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
358 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
360 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
367 listing_source_file (filename
);
372 /* Make sure that the symbol is first on the symbol chain */
373 if (symbol_rootP
!= symbolP
)
375 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
376 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
377 } /* if not first on the list */
380 /* Line number handling */
383 struct line_no
*next
;
390 /* Symbol of last function, which we should hang line#s off of. */
391 static symbolS
*line_fsym
;
393 #define in_function() (line_fsym != 0)
394 #define clear_function() (line_fsym = 0)
395 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
399 coff_obj_symbol_new_hook (symbolP
)
402 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
403 char * s
= (char *) xmalloc (sz
);
406 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
408 S_SET_DATA_TYPE (symbolP
, T_NULL
);
409 S_SET_STORAGE_CLASS (symbolP
, 0);
410 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
412 if (S_IS_STRING (symbolP
))
413 SF_SET_STRING (symbolP
);
415 if (S_IS_LOCAL (symbolP
))
416 SF_SET_LOCAL (symbolP
);
421 * Handle .ln directives.
424 static symbolS
*current_lineno_sym
;
425 static struct line_no
*line_nos
;
426 /* @@ Blindly assume all .ln directives will be in the .text section... */
430 add_lineno (frag
, offset
, num
)
435 struct line_no
*new_line
=
436 (struct line_no
*) xmalloc (sizeof (struct line_no
));
437 if (!current_lineno_sym
)
443 /* Zero is used as an end marker in the file. */
444 as_warn (_("Line numbers must be positive integers\n"));
447 new_line
->next
= line_nos
;
448 new_line
->frag
= frag
;
449 new_line
->l
.line_number
= num
;
450 new_line
->l
.u
.offset
= offset
;
456 coff_add_linesym (sym
)
461 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
466 current_lineno_sym
= sym
;
470 obj_coff_ln (appline
)
475 if (! appline
&& def_symbol_in_progress
!= NULL
)
477 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
478 demand_empty_rest_of_line ();
482 l
= get_absolute_expression ();
485 add_lineno (frag_now
, frag_now_fix (), l
);
489 new_logical_line ((char *) NULL
, l
- 1);
498 l
+= coff_line_base
- 1;
499 listing_source_line (l
);
504 demand_empty_rest_of_line ();
507 /* .loc is essentially the same as .ln; parse it for assembler
511 obj_coff_loc (ignore
)
512 int ignore ATTRIBUTE_UNUSED
;
516 /* FIXME: Why do we need this check? We need it for ECOFF, but why
517 do we need it for COFF? */
518 if (now_seg
!= text_section
)
520 as_warn (_(".loc outside of .text"));
521 demand_empty_rest_of_line ();
525 if (def_symbol_in_progress
!= NULL
)
527 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
528 demand_empty_rest_of_line ();
532 /* Skip the file number. */
534 get_absolute_expression ();
537 lineno
= get_absolute_expression ();
545 lineno
+= coff_line_base
- 1;
546 listing_source_line (lineno
);
551 demand_empty_rest_of_line ();
553 add_lineno (frag_now
, frag_now_fix (), lineno
);
556 /* Handle the .ident pseudo-op. */
559 obj_coff_ident (ignore
)
560 int ignore ATTRIBUTE_UNUSED
;
562 segT current_seg
= now_seg
;
563 subsegT current_subseg
= now_subseg
;
569 /* We could put it in .comment, but that creates an extra section
570 that shouldn't be loaded into memory, which requires linker
571 changes... For now, until proven otherwise, use .rdata. */
572 sec
= subseg_new (".rdata$zzz", 0);
573 bfd_set_section_flags (stdoutput
, sec
,
574 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
575 & bfd_applicable_section_flags (stdoutput
)));
578 subseg_new (".comment", 0);
582 subseg_set (current_seg
, current_subseg
);
588 * Handle .def directives.
590 * One might ask : why can't we symbol_new if the symbol does not
591 * already exist and fill it with debug information. Because of
592 * the C_EFCN special symbol. It would clobber the value of the
593 * function symbol before we have a chance to notice that it is
594 * a C_EFCN. And a second reason is that the code is more clear this
595 * way. (at least I think it is :-).
599 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
600 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
601 *input_line_pointer == '\t') \
602 input_line_pointer++;
606 int what ATTRIBUTE_UNUSED
;
608 char name_end
; /* Char after the end of name */
609 char *symbol_name
; /* Name of the debug symbol */
610 char *symbol_name_copy
; /* Temporary copy of the name */
611 unsigned int symbol_name_length
;
613 if (def_symbol_in_progress
!= NULL
)
615 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
616 demand_empty_rest_of_line ();
618 } /* if not inside .def/.endef */
622 symbol_name
= input_line_pointer
;
623 #ifdef STRIP_UNDERSCORE
624 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
626 #endif /* STRIP_UNDERSCORE */
628 name_end
= get_symbol_end ();
629 symbol_name_length
= strlen (symbol_name
);
630 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
631 strcpy (symbol_name_copy
, symbol_name
);
632 #ifdef tc_canonicalize_symbol_name
633 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
636 /* Initialize the new symbol */
637 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
638 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
639 S_SET_VALUE (def_symbol_in_progress
, 0);
641 if (S_IS_STRING (def_symbol_in_progress
))
642 SF_SET_STRING (def_symbol_in_progress
);
644 *input_line_pointer
= name_end
;
646 demand_empty_rest_of_line ();
649 unsigned int dim_index
;
652 obj_coff_endef (ignore
)
653 int ignore ATTRIBUTE_UNUSED
;
655 symbolS
*symbolP
= NULL
;
657 /* DIM BUG FIX sac@cygnus.com */
659 if (def_symbol_in_progress
== NULL
)
661 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
662 demand_empty_rest_of_line ();
664 } /* if not inside .def/.endef */
666 /* Set the section number according to storage class. */
667 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
672 SF_SET_TAG (def_symbol_in_progress
);
673 /* intentional fallthrough */
676 SF_SET_DEBUG (def_symbol_in_progress
);
677 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
681 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
682 /* intentional fallthrough */
684 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
685 /* intentional fallthrough */
689 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
691 name
= S_GET_NAME (def_symbol_in_progress
);
692 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
698 if (! in_function ())
699 as_warn (_("`%s' symbol without preceding function"), name
);
700 /* Will need relocating. */
701 SF_SET_PROCESS (def_symbol_in_progress
);
707 /* The MS compilers output the actual endline, not the
708 function-relative one... we want to match without
709 changing the assembler input. */
710 SA_SET_SYM_LNNO (def_symbol_in_progress
,
711 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
722 #endif /* C_AUTOARG */
728 SF_SET_DEBUG (def_symbol_in_progress
);
729 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
736 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
746 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
753 as_warn (_("unexpected storage class %d"),
754 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
756 } /* switch on storage class */
758 /* Now that we have built a debug symbol, try to find if we should
759 merge with an existing symbol or not. If a symbol is C_EFCN or
760 absolute_section or untagged SEG_DEBUG it never merges. We also
761 don't merge labels, which are in a different namespace, nor
762 symbols which have not yet been defined since they are typically
763 unique, nor do we merge tags with non-tags. */
765 /* Two cases for functions. Either debug followed by definition or
766 definition followed by debug. For definition first, we will
767 merge the debug symbol into the definition. For debug first, the
768 lineno entry MUST point to the definition function or else it
769 will point off into space when obj_crawl_symbol_chain() merges
770 the debug symbol into the real symbol. Therefor, let's presume
771 the debug symbol is a real function reference. */
773 /* FIXME-SOON If for some reason the definition label/symbol is
774 never seen, this will probably leave an undefined symbol at link
777 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
778 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
779 || (!strcmp (bfd_get_section_name (stdoutput
,
780 S_GET_SEGMENT (def_symbol_in_progress
)),
782 && !SF_GET_TAG (def_symbol_in_progress
))
783 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
784 || ! symbol_constant_p (def_symbol_in_progress
)
785 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
786 DO_NOT_STRIP
)) == NULL
787 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
789 /* If it already is at the end of the symbol list, do nothing */
790 if (def_symbol_in_progress
!= symbol_lastP
)
792 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
793 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
799 /* This symbol already exists, merge the newly created symbol
800 into the old one. This is not mandatory. The linker can
801 handle duplicate symbols correctly. But I guess that it save
802 a *lot* of space if the assembly file defines a lot of
805 /* The debug entry (def_symbol_in_progress) is merged into the
806 previous definition. */
808 c_symbol_merge (def_symbol_in_progress
, symbolP
);
809 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
811 def_symbol_in_progress
= symbolP
;
813 if (SF_GET_FUNCTION (def_symbol_in_progress
)
814 || SF_GET_TAG (def_symbol_in_progress
)
815 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
817 /* For functions, and tags, and static symbols, the symbol
818 *must* be where the debug symbol appears. Move the
819 existing symbol to the current place. */
820 /* If it already is at the end of the symbol list, do nothing */
821 if (def_symbol_in_progress
!= symbol_lastP
)
823 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
824 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
829 if (SF_GET_TAG (def_symbol_in_progress
))
833 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
835 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
836 tag_insert (S_GET_NAME (def_symbol_in_progress
),
837 def_symbol_in_progress
);
840 if (SF_GET_FUNCTION (def_symbol_in_progress
))
842 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
843 set_function (def_symbol_in_progress
);
844 SF_SET_PROCESS (def_symbol_in_progress
);
848 /* That is, if this is the first time we've seen the
850 symbol_table_insert (def_symbol_in_progress
);
851 } /* definition follows debug */
852 } /* Create the line number entry pointing to the function being defined */
854 def_symbol_in_progress
= NULL
;
855 demand_empty_rest_of_line ();
859 obj_coff_dim (ignore
)
860 int ignore ATTRIBUTE_UNUSED
;
864 if (def_symbol_in_progress
== NULL
)
866 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
867 demand_empty_rest_of_line ();
869 } /* if not inside .def/.endef */
871 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
873 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
876 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
877 get_absolute_expression ());
879 switch (*input_line_pointer
)
882 input_line_pointer
++;
886 as_warn (_("badly formed .dim directive ignored"));
887 /* intentional fallthrough */
895 demand_empty_rest_of_line ();
899 obj_coff_line (ignore
)
900 int ignore ATTRIBUTE_UNUSED
;
904 if (def_symbol_in_progress
== NULL
)
906 /* Probably stabs-style line? */
911 this_base
= get_absolute_expression ();
912 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
913 coff_line_base
= this_base
;
915 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
916 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
918 demand_empty_rest_of_line ();
921 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
926 listing_source_line ((unsigned int) this_base
);
932 obj_coff_size (ignore
)
933 int ignore ATTRIBUTE_UNUSED
;
935 if (def_symbol_in_progress
== NULL
)
937 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
938 demand_empty_rest_of_line ();
940 } /* if not inside .def/.endef */
942 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
943 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
944 demand_empty_rest_of_line ();
948 obj_coff_scl (ignore
)
949 int ignore ATTRIBUTE_UNUSED
;
951 if (def_symbol_in_progress
== NULL
)
953 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
954 demand_empty_rest_of_line ();
956 } /* if not inside .def/.endef */
958 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
959 demand_empty_rest_of_line ();
963 obj_coff_tag (ignore
)
964 int ignore ATTRIBUTE_UNUSED
;
969 if (def_symbol_in_progress
== NULL
)
971 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
972 demand_empty_rest_of_line ();
976 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
977 symbol_name
= input_line_pointer
;
978 name_end
= get_symbol_end ();
980 #ifdef tc_canonicalize_symbol_name
981 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
984 /* Assume that the symbol referred to by .tag is always defined.
985 This was a bad assumption. I've added find_or_make. xoxorich. */
986 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
987 tag_find_or_make (symbol_name
));
988 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
990 as_warn (_("tag not found for .tag %s"), symbol_name
);
993 SF_SET_TAGGED (def_symbol_in_progress
);
994 *input_line_pointer
= name_end
;
996 demand_empty_rest_of_line ();
1000 obj_coff_type (ignore
)
1001 int ignore ATTRIBUTE_UNUSED
;
1003 if (def_symbol_in_progress
== NULL
)
1005 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1006 demand_empty_rest_of_line ();
1008 } /* if not inside .def/.endef */
1010 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1012 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1013 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1015 SF_SET_FUNCTION (def_symbol_in_progress
);
1016 } /* is a function */
1018 demand_empty_rest_of_line ();
1022 obj_coff_val (ignore
)
1023 int ignore ATTRIBUTE_UNUSED
;
1025 if (def_symbol_in_progress
== NULL
)
1027 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1028 demand_empty_rest_of_line ();
1030 } /* if not inside .def/.endef */
1032 if (is_name_beginner (*input_line_pointer
))
1034 char *symbol_name
= input_line_pointer
;
1035 char name_end
= get_symbol_end ();
1037 #ifdef tc_canonicalize_symbol_name
1038 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1040 if (!strcmp (symbol_name
, "."))
1042 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1043 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1044 /* If the .val is != from the .def (e.g. statics) */
1046 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1050 exp
.X_op
= O_symbol
;
1051 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1052 exp
.X_op_symbol
= NULL
;
1053 exp
.X_add_number
= 0;
1054 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1056 /* If the segment is undefined when the forward reference is
1057 resolved, then copy the segment id from the forward
1059 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1061 /* FIXME: gcc can generate address expressions here in
1062 unusual cases (search for "obscure" in sdbout.c). We
1063 just ignore the offset here, thus generating incorrect
1064 debugging information. We ignore the rest of the line
1067 /* Otherwise, it is the name of a non debug symbol and its value
1068 will be calculated later. */
1069 *input_line_pointer
= name_end
;
1073 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1074 } /* if symbol based */
1076 demand_empty_rest_of_line ();
1080 coff_obj_read_begin_hook ()
1082 /* These had better be the same. Usually 18 bytes. */
1084 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1085 know (SYMESZ
== AUXESZ
);
1091 symbolS
*coff_last_function
;
1092 static symbolS
*coff_last_bf
;
1095 coff_frob_symbol (symp
, punt
)
1099 static symbolS
*last_tagP
;
1100 static stack
*block_stack
;
1101 static symbolS
*set_end
;
1102 symbolS
*next_set_end
= NULL
;
1104 if (symp
== &abs_symbol
)
1110 if (current_lineno_sym
)
1111 coff_add_linesym ((symbolS
*) 0);
1114 block_stack
= stack_init (512, sizeof (symbolS
*));
1116 if (S_IS_WEAK (symp
))
1119 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1121 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1125 if (!S_IS_DEFINED (symp
)
1126 && !S_IS_WEAK (symp
)
1127 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1128 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1130 if (!SF_GET_DEBUG (symp
))
1133 if (!SF_GET_LOCAL (symp
)
1134 && !SF_GET_STATICS (symp
)
1135 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1138 c_symbol_merge (symp
, real
);
1141 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1143 assert (S_GET_VALUE (symp
) == 0);
1144 S_SET_EXTERNAL (symp
);
1146 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1148 if (S_GET_SEGMENT (symp
) == text_section
1149 && symp
!= seg_info (text_section
)->sym
)
1150 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1152 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1154 if (SF_GET_PROCESS (symp
))
1156 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1158 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1159 stack_push (block_stack
, (char *) &symp
);
1163 begin
= *(symbolS
**) stack_pop (block_stack
);
1165 as_warn (_("mismatched .eb"));
1167 next_set_end
= begin
;
1170 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1172 union internal_auxent
*auxp
;
1173 coff_last_function
= symp
;
1174 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1175 S_SET_NUMBER_AUXILIARY (symp
, 1);
1176 auxp
= SYM_AUXENT (symp
);
1177 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1178 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1180 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1182 if (coff_last_function
== 0)
1183 as_fatal (_("C_EFCN symbol out of scope"));
1184 SA_SET_SYM_FSIZE (coff_last_function
,
1185 (long) (S_GET_VALUE (symp
)
1186 - S_GET_VALUE (coff_last_function
)));
1187 next_set_end
= coff_last_function
;
1188 coff_last_function
= 0;
1191 if (S_IS_EXTERNAL (symp
))
1192 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1193 else if (SF_GET_LOCAL (symp
))
1196 if (SF_GET_FUNCTION (symp
))
1197 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1202 /* Double check weak symbols. */
1203 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1204 as_bad (_("Symbol `%s' can not be both weak and common"),
1207 if (SF_GET_TAG (symp
))
1209 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1210 next_set_end
= last_tagP
;
1213 /* This is pretty horrible, but we have to set *punt correctly in
1214 order to call SA_SET_SYM_ENDNDX correctly. */
1215 if (! symbol_used_in_reloc_p (symp
)
1216 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1217 || (! S_IS_EXTERNAL (symp
)
1218 && ! symbol_get_tc (symp
)->output
1219 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1223 if (set_end
!= (symbolS
*) NULL
1225 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1226 || (S_IS_DEFINED (symp
)
1227 && ! S_IS_COMMON (symp
)
1228 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1230 SA_SET_SYM_ENDNDX (set_end
, symp
);
1234 if (next_set_end
!= NULL
)
1236 if (set_end
!= NULL
)
1237 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1238 S_GET_NAME (set_end
));
1239 set_end
= next_set_end
;
1243 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1244 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1246 if (coff_last_bf
!= NULL
)
1247 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1248 coff_last_bf
= symp
;
1251 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1254 struct line_no
*lptr
;
1257 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1258 for (i
= 0; lptr
; lptr
= lptr
->next
)
1260 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1262 /* We need i entries for line numbers, plus 1 for the first
1263 entry which BFD will override, plus 1 for the last zero
1264 entry (a marker for BFD). */
1265 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1266 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1267 l
[i
+ 1].line_number
= 0;
1268 l
[i
+ 1].u
.sym
= NULL
;
1272 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1280 coff_adjust_section_syms (abfd
, sec
, x
)
1281 bfd
*abfd ATTRIBUTE_UNUSED
;
1283 PTR x ATTRIBUTE_UNUSED
;
1286 segment_info_type
*seginfo
= seg_info (sec
);
1287 int nlnno
, nrelocs
= 0;
1289 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1290 tc-ppc.c. Do not get confused by it. */
1291 if (seginfo
== NULL
)
1294 if (!strcmp (sec
->name
, ".text"))
1295 nlnno
= coff_n_line_nos
;
1299 /* @@ Hope that none of the fixups expand to more than one reloc
1301 fixS
*fixp
= seginfo
->fix_root
;
1304 if (! fixp
->fx_done
)
1306 fixp
= fixp
->fx_next
;
1309 if (bfd_get_section_size_before_reloc (sec
) == 0
1312 && sec
!= text_section
1313 && sec
!= data_section
1314 && sec
!= bss_section
)
1316 secsym
= section_symbol (sec
);
1317 /* This is an estimate; we'll plug in the real value using
1318 SET_SECTION_RELOCS later */
1319 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1320 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1324 coff_frob_file_after_relocs ()
1326 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1330 * implement the .section pseudo op:
1331 * .section name {, "flags"}
1333 * | +--- optional flags: 'b' for bss
1335 * +-- section name 'l' for lib
1339 * 'd' (apparently m88k for data)
1341 * 'r' for read-only data
1342 * 's' for shared data (PE)
1343 * But if the argument is not a quoted string, treat it as a
1344 * subsegment number.
1348 obj_coff_section (ignore
)
1349 int ignore ATTRIBUTE_UNUSED
;
1351 /* Strip out the section name */
1356 flagword flags
, oldflags
;
1367 section_name
= input_line_pointer
;
1368 c
= get_symbol_end ();
1370 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1371 strcpy (name
, section_name
);
1373 *input_line_pointer
= c
;
1378 flags
= SEC_NO_FLAGS
;
1380 if (*input_line_pointer
== ',')
1382 ++input_line_pointer
;
1384 if (*input_line_pointer
!= '"')
1385 exp
= get_absolute_expression ();
1388 ++input_line_pointer
;
1389 while (*input_line_pointer
!= '"'
1390 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1392 switch (*input_line_pointer
)
1394 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1395 case 'n': flags
&=~ SEC_LOAD
; break;
1396 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1397 case 'w': flags
&=~ SEC_READONLY
; break;
1398 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1399 case 'r': flags
|= SEC_READONLY
; break;
1400 case 's': flags
|= SEC_SHARED
; break;
1402 case 'i': /* STYP_INFO */
1403 case 'l': /* STYP_LIB */
1404 case 'o': /* STYP_OVER */
1405 as_warn (_("unsupported section attribute '%c'"),
1406 *input_line_pointer
);
1410 as_warn(_("unknown section attribute '%c'"),
1411 *input_line_pointer
);
1414 ++input_line_pointer
;
1416 if (*input_line_pointer
== '"')
1417 ++input_line_pointer
;
1421 sec
= subseg_new (name
, (subsegT
) exp
);
1423 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1424 if (oldflags
== SEC_NO_FLAGS
)
1426 /* Set section flags for a new section just created by subseg_new.
1427 Provide a default if no flags were parsed. */
1428 if (flags
== SEC_NO_FLAGS
)
1431 #ifdef COFF_LONG_SECTION_NAMES
1432 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1433 sections so adjust_reloc_syms in write.c will correctly handle
1434 relocs which refer to non-local symbols in these sections. */
1435 if (strncmp (name
, ".gnu.linkonce", sizeof(".gnu.linkonce") - 1) == 0)
1436 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1439 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1440 as_warn (_("error setting flags for \"%s\": %s"),
1441 bfd_section_name (stdoutput
, sec
),
1442 bfd_errmsg (bfd_get_error ()));
1444 else if (flags
!= SEC_NO_FLAGS
)
1446 /* This section's attributes have already been set. Warn if the
1447 attributes don't match. */
1448 flagword matchflags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1449 | SEC_DATA
| SEC_SHARED
;
1450 if ((flags
^ oldflags
) & matchflags
)
1451 as_warn (_("Ignoring changed section attributes for %s"), name
);
1454 demand_empty_rest_of_line ();
1458 coff_adjust_symtab ()
1460 if (symbol_rootP
== NULL
1461 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1462 c_dot_file_symbol ("fake");
1466 coff_frob_section (sec
)
1472 bfd_vma size
, n_entries
, mask
;
1473 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1475 /* The COFF back end in BFD requires that all section sizes be
1476 rounded up to multiples of the corresponding section alignments,
1477 supposedly because standard COFF has no other way of encoding alignment
1478 for sections. If your COFF flavor has a different way of encoding
1479 section alignment, then skip this step, as TICOFF does. */
1480 size
= bfd_get_section_size_before_reloc (sec
);
1481 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1482 #if !defined(TICOFF)
1485 size
= (size
+ mask
) & ~mask
;
1486 bfd_set_section_size (stdoutput
, sec
, size
);
1490 /* If the section size is non-zero, the section symbol needs an aux
1491 entry associated with it, indicating the size. We don't know
1492 all the values yet; coff_frob_symbol will fill them in later. */
1495 || sec
== text_section
1496 || sec
== data_section
1497 || sec
== bss_section
)
1500 symbolS
*secsym
= section_symbol (sec
);
1502 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1503 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1504 SF_SET_STATICS (secsym
);
1505 SA_SET_SCN_SCNLEN (secsym
, size
);
1508 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1509 #ifndef STAB_SECTION_NAME
1510 #define STAB_SECTION_NAME ".stab"
1512 #ifndef STAB_STRING_SECTION_NAME
1513 #define STAB_STRING_SECTION_NAME ".stabstr"
1515 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1519 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1520 /* size is already rounded up, since other section will be listed first */
1521 size
= bfd_get_section_size_before_reloc (strsec
);
1523 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1525 /* Find first non-empty frag. It should be large enough. */
1526 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1527 while (fragp
&& fragp
->fr_fix
== 0)
1528 fragp
= fragp
->fr_next
;
1529 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1531 /* Store the values. */
1532 p
= fragp
->fr_literal
;
1533 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1534 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1538 obj_coff_init_stab_section (seg
)
1544 unsigned int stroff
;
1546 /* Make space for this first symbol. */
1550 as_where (&file
, (unsigned int *) NULL
);
1551 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1552 strcpy (stabstr_name
, seg
->name
);
1553 strcat (stabstr_name
, "str");
1554 stroff
= get_stab_string_offset (file
, stabstr_name
);
1556 md_number_to_chars (p
, stroff
, 4);
1565 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1573 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1575 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1576 (unsigned long) symbolP
,
1577 S_GET_NAME(symbolP
),
1578 (long) S_GET_DATA_TYPE(symbolP
),
1579 S_GET_STORAGE_CLASS(symbolP
),
1580 (int) S_GET_SEGMENT(symbolP
));
1586 #else /* not BFD_ASSEMBLER */
1589 /* This is needed because we include internal bfd things. */
1593 #include "libcoff.h"
1596 #include "coff/pe.h"
1599 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1600 that we can stick sections together without causing trouble. */
1602 #define NOP_OPCODE 0x00
1605 /* The zeroes if symbol name is longer than 8 chars */
1606 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1608 #define MIN(a,b) ((a) < (b)? (a) : (b))
1610 /* This vector is used to turn a gas internal segment number into a
1611 section number suitable for insertion into a coff symbol table.
1612 This must correspond to seg_info_off_by_4. */
1614 const short seg_N_TYPE
[] =
1615 { /* in: segT out: N_TYPE bits */
1617 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1618 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1619 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1620 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1621 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1622 C_UNDEF_SECTION
, /* SEG_GOOF */
1623 C_UNDEF_SECTION
, /* SEG_EXPR */
1624 C_DEBUG_SECTION
, /* SEG_DEBUG */
1625 C_NTV_SECTION
, /* SEG_NTV */
1626 C_PTV_SECTION
, /* SEG_PTV */
1627 C_REGISTER_SECTION
, /* SEG_REGISTER */
1630 int function_lineoff
= -1; /* Offset in line#s where the last function
1631 started (the odd entry for line #0) */
1633 /* structure used to keep the filenames which
1634 are too long around so that we can stick them
1635 into the string table */
1636 struct filename_list
1639 struct filename_list
*next
;
1642 static struct filename_list
*filename_list_head
;
1643 static struct filename_list
*filename_list_tail
;
1645 static symbolS
*last_line_symbol
;
1647 /* Add 4 to the real value to get the index and compensate the
1648 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1649 section number into a segment number
1651 static symbolS
*previous_file_symbol
;
1652 void c_symbol_merge ();
1653 static int line_base
;
1655 symbolS
*c_section_symbol ();
1658 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1659 segT this_segment_type
));
1662 static void fixup_mdeps
PARAMS ((fragS
*,
1667 static void fill_section
PARAMS ((bfd
* abfd
,
1672 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1677 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1678 symbolS
* symbol_rootP
));
1680 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1682 static void obj_coff_lcomm
PARAMS ((int));
1683 static void obj_coff_text
PARAMS ((int));
1684 static void obj_coff_data
PARAMS ((int));
1685 void obj_coff_section
PARAMS ((int));
1687 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1689 This array maps a COFF section number into a gas section number.
1690 Because COFF uses negative section numbers, you must add 4 to the
1691 COFF section number when indexing into this array; this is done via
1692 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1695 static const segT seg_info_off_by_4
[] =
1702 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1703 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1704 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1705 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1706 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1707 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1708 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1709 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1722 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1724 static relax_addressT
1725 relax_align (address
, alignment
)
1726 relax_addressT address
;
1729 relax_addressT mask
;
1730 relax_addressT new_address
;
1732 mask
= ~((~0) << alignment
);
1733 new_address
= (address
+ mask
) & (~mask
);
1734 return (new_address
- address
);
1742 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1745 /* calculate the size of the frag chain and fill in the section header
1746 to contain all of it, also fill in the addr of the sections */
1748 size_section (abfd
, idx
)
1749 bfd
*abfd ATTRIBUTE_UNUSED
;
1753 unsigned int size
= 0;
1754 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1757 size
= frag
->fr_address
;
1758 if (frag
->fr_address
!= size
)
1760 fprintf (stderr
, _("Out of step\n"));
1761 size
= frag
->fr_address
;
1764 switch (frag
->fr_type
)
1766 #ifdef TC_COFF_SIZEMACHDEP
1767 case rs_machine_dependent
:
1768 size
+= TC_COFF_SIZEMACHDEP (frag
);
1772 assert (frag
->fr_symbol
== 0);
1775 size
+= frag
->fr_fix
;
1776 size
+= frag
->fr_offset
* frag
->fr_var
;
1783 size
+= frag
->fr_fix
;
1784 off
= relax_align (size
, frag
->fr_offset
);
1785 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1791 BAD_CASE (frag
->fr_type
);
1794 frag
= frag
->fr_next
;
1796 segment_info
[idx
].scnhdr
.s_size
= size
;
1802 count_entries_in_chain (idx
)
1805 unsigned int nrelocs
;
1808 /* Count the relocations */
1809 fixup_ptr
= segment_info
[idx
].fix_root
;
1811 while (fixup_ptr
!= (fixS
*) NULL
)
1813 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1816 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1825 fixup_ptr
= fixup_ptr
->fx_next
;
1832 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1834 /* AUX's ld expects relocations to be sorted */
1836 compare_external_relocs (x
, y
)
1840 struct external_reloc
*a
= (struct external_reloc
*) x
;
1841 struct external_reloc
*b
= (struct external_reloc
*) y
;
1842 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1843 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1844 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1849 /* output all the relocations for a section */
1851 do_relocs_for (abfd
, h
, file_cursor
)
1854 unsigned long *file_cursor
;
1856 unsigned int nrelocs
;
1858 unsigned long reloc_start
= *file_cursor
;
1860 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1862 if (segment_info
[idx
].scnhdr
.s_name
[0])
1864 struct external_reloc
*ext_ptr
;
1865 struct external_reloc
*external_reloc_vec
;
1866 unsigned int external_reloc_size
;
1867 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1868 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1869 nrelocs
= count_entries_in_chain (idx
);
1872 /* Bypass this stuff if no relocs. This also incidentally
1873 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1875 external_reloc_size
= nrelocs
* RELSZ
;
1876 external_reloc_vec
=
1877 (struct external_reloc
*) malloc (external_reloc_size
);
1879 ext_ptr
= external_reloc_vec
;
1881 /* Fill in the internal coff style reloc struct from the
1882 internal fix list. */
1885 struct internal_reloc intr
;
1887 /* Only output some of the relocations */
1888 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1890 #ifdef TC_RELOC_MANGLE
1891 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1896 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1898 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1900 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1902 #ifdef TC_KEEP_FX_OFFSET
1903 intr
.r_offset
= fix_ptr
->fx_offset
;
1908 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1909 && (! S_IS_DEFINED (symbol_ptr
)
1910 || S_IS_COMMON (symbol_ptr
)))
1914 /* We must avoid looping, as that can occur
1915 with a badly written program. */
1916 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1917 if (n
== symbol_ptr
)
1922 /* Turn the segment of the symbol into an offset. */
1925 resolve_symbol_value (symbol_ptr
, 1);
1926 if (! symbol_ptr
->sy_resolved
)
1931 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1932 as_bad_where (file
, line
,
1933 _("unresolved relocation"));
1935 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1936 S_GET_NAME (symbol_ptr
));
1938 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1941 intr
.r_symndx
= dot
->sy_number
;
1945 intr
.r_symndx
= symbol_ptr
->sy_number
;
1955 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1958 #if defined(TC_A29K)
1960 /* The 29k has a special kludge for the high 16 bit
1961 reloc. Two relocations are emited, R_IHIHALF,
1962 and R_IHCONST. The second one doesn't contain a
1963 symbol, but uses the value for offset. */
1965 if (intr
.r_type
== R_IHIHALF
)
1967 /* now emit the second bit */
1968 intr
.r_type
= R_IHCONST
;
1969 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1970 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1976 fix_ptr
= fix_ptr
->fx_next
;
1980 /* Sort the reloc table */
1981 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1982 sizeof (struct external_reloc
), compare_external_relocs
);
1985 /* Write out the reloc table */
1986 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1988 free (external_reloc_vec
);
1990 /* Fill in section header info. */
1991 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1992 *file_cursor
+= external_reloc_size
;
1993 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1998 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2002 /* Set relocation_size field in file headers */
2003 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2007 /* run through a frag chain and write out the data to go with it, fill
2008 in the scnhdrs with the info on the file postions
2011 fill_section (abfd
, h
, file_cursor
)
2013 object_headers
*h ATTRIBUTE_UNUSED
;
2014 unsigned long *file_cursor
;
2018 unsigned int paddr
= 0;
2020 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2022 unsigned int offset
= 0;
2023 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2029 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2036 buffer
= xmalloc (s
->s_size
);
2037 s
->s_scnptr
= *file_cursor
;
2039 know (s
->s_paddr
== paddr
);
2041 if (strcmp (s
->s_name
, ".text") == 0)
2042 s
->s_flags
|= STYP_TEXT
;
2043 else if (strcmp (s
->s_name
, ".data") == 0)
2044 s
->s_flags
|= STYP_DATA
;
2045 else if (strcmp (s
->s_name
, ".bss") == 0)
2048 s
->s_flags
|= STYP_BSS
;
2050 /* @@ Should make the i386 and a29k coff targets define
2051 COFF_NOLOAD_PROBLEM, and have only one test here. */
2054 #ifndef COFF_NOLOAD_PROBLEM
2055 /* Apparently the SVR3 linker (and exec syscall) and UDI
2056 mondfe progrem are confused by noload sections. */
2057 s
->s_flags
|= STYP_NOLOAD
;
2062 else if (strcmp (s
->s_name
, ".lit") == 0)
2063 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2064 else if (strcmp (s
->s_name
, ".init") == 0)
2065 s
->s_flags
|= STYP_TEXT
;
2066 else if (strcmp (s
->s_name
, ".fini") == 0)
2067 s
->s_flags
|= STYP_TEXT
;
2068 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2069 s
->s_flags
|= STYP_INFO
;
2073 unsigned int fill_size
;
2074 switch (frag
->fr_type
)
2076 case rs_machine_dependent
:
2079 memcpy (buffer
+ frag
->fr_address
,
2081 (unsigned int) frag
->fr_fix
);
2082 offset
+= frag
->fr_fix
;
2087 assert (frag
->fr_symbol
== 0);
2094 memcpy (buffer
+ frag
->fr_address
,
2096 (unsigned int) frag
->fr_fix
);
2097 offset
+= frag
->fr_fix
;
2100 fill_size
= frag
->fr_var
;
2101 if (fill_size
&& frag
->fr_offset
> 0)
2104 unsigned int off
= frag
->fr_fix
;
2105 for (count
= frag
->fr_offset
; count
; count
--)
2107 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2109 memcpy (buffer
+ frag
->fr_address
+ off
,
2110 frag
->fr_literal
+ frag
->fr_fix
,
2113 offset
+= fill_size
;
2118 case rs_broken_word
:
2123 frag
= frag
->fr_next
;
2128 if (s
->s_scnptr
!= 0)
2130 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2131 *file_cursor
+= s
->s_size
;
2140 /* Coff file generation & utilities */
2143 coff_header_append (abfd
, h
)
2150 #ifdef COFF_LONG_SECTION_NAMES
2151 unsigned long string_size
= 4;
2154 bfd_seek (abfd
, 0, 0);
2156 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2157 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2158 H_SET_VERSION_STAMP (h
, 0);
2159 H_SET_ENTRY_POINT (h
, 0);
2160 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2161 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2162 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2164 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2165 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2166 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2168 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2170 bfd_write (buffer
, i
, 1, abfd
);
2171 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2173 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2175 if (segment_info
[i
].scnhdr
.s_name
[0])
2179 #ifdef COFF_LONG_SECTION_NAMES
2180 /* Support long section names as found in PE. This code
2181 must coordinate with that in write_object_file and
2183 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2185 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2186 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2187 string_size
+= strlen (segment_info
[i
].name
) + 1;
2191 size
= bfd_coff_swap_scnhdr_out (abfd
,
2192 &(segment_info
[i
].scnhdr
),
2195 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2196 bfd_write (buffer
, size
, 1, abfd
);
2203 symbol_to_chars (abfd
, where
, symbolP
)
2208 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2212 /* Turn any symbols with register attributes into abs symbols */
2213 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2215 S_SET_SEGMENT (symbolP
, absolute_section
);
2217 /* At the same time, relocate all symbols to their output value */
2220 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2221 + S_GET_VALUE (symbolP
));
2223 val
= S_GET_VALUE (symbolP
);
2226 S_SET_VALUE (symbolP
, val
);
2228 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2230 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2233 for (i
= 0; i
< numaux
; i
++)
2235 where
+= bfd_coff_swap_aux_out (abfd
,
2236 &symbolP
->sy_symbol
.ost_auxent
[i
],
2237 S_GET_DATA_TYPE (symbolP
),
2238 S_GET_STORAGE_CLASS (symbolP
),
2246 coff_obj_symbol_new_hook (symbolP
)
2249 char underscore
= 0; /* Symbol has leading _ */
2251 /* Effective symbol */
2252 /* Store the pointer in the offset. */
2253 S_SET_ZEROES (symbolP
, 0L);
2254 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2255 S_SET_STORAGE_CLASS (symbolP
, 0);
2256 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2257 /* Additional information */
2258 symbolP
->sy_symbol
.ost_flags
= 0;
2259 /* Auxiliary entries */
2260 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2262 if (S_IS_STRING (symbolP
))
2263 SF_SET_STRING (symbolP
);
2264 if (!underscore
&& S_IS_LOCAL (symbolP
))
2265 SF_SET_LOCAL (symbolP
);
2269 * Handle .ln directives.
2273 obj_coff_ln (appline
)
2278 if (! appline
&& def_symbol_in_progress
!= NULL
)
2280 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2281 demand_empty_rest_of_line ();
2283 } /* wrong context */
2285 l
= get_absolute_expression ();
2286 c_line_new (0, frag_now_fix (), l
, frag_now
);
2289 new_logical_line ((char *) NULL
, l
- 1);
2299 listing_source_line ((unsigned int) l
);
2304 demand_empty_rest_of_line ();
2310 * Handle .def directives.
2312 * One might ask : why can't we symbol_new if the symbol does not
2313 * already exist and fill it with debug information. Because of
2314 * the C_EFCN special symbol. It would clobber the value of the
2315 * function symbol before we have a chance to notice that it is
2316 * a C_EFCN. And a second reason is that the code is more clear this
2317 * way. (at least I think it is :-).
2321 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2322 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2323 *input_line_pointer == '\t') \
2324 input_line_pointer++;
2328 int what ATTRIBUTE_UNUSED
;
2330 char name_end
; /* Char after the end of name */
2331 char *symbol_name
; /* Name of the debug symbol */
2332 char *symbol_name_copy
; /* Temporary copy of the name */
2333 unsigned int symbol_name_length
;
2335 if (def_symbol_in_progress
!= NULL
)
2337 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2338 demand_empty_rest_of_line ();
2340 } /* if not inside .def/.endef */
2342 SKIP_WHITESPACES ();
2344 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2345 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2347 symbol_name
= input_line_pointer
;
2348 name_end
= get_symbol_end ();
2349 symbol_name_length
= strlen (symbol_name
);
2350 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2351 strcpy (symbol_name_copy
, symbol_name
);
2352 #ifdef tc_canonicalize_symbol_name
2353 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2356 /* Initialize the new symbol */
2357 #ifdef STRIP_UNDERSCORE
2358 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2359 ? symbol_name_copy
+ 1
2360 : symbol_name_copy
));
2361 #else /* STRIP_UNDERSCORE */
2362 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2363 #endif /* STRIP_UNDERSCORE */
2364 /* free(symbol_name_copy); */
2365 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2366 def_symbol_in_progress
->sy_number
= ~0;
2367 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2368 S_SET_VALUE (def_symbol_in_progress
, 0);
2370 if (S_IS_STRING (def_symbol_in_progress
))
2371 SF_SET_STRING (def_symbol_in_progress
);
2373 *input_line_pointer
= name_end
;
2375 demand_empty_rest_of_line ();
2378 unsigned int dim_index
;
2382 obj_coff_endef (ignore
)
2383 int ignore ATTRIBUTE_UNUSED
;
2385 symbolS
*symbolP
= 0;
2386 /* DIM BUG FIX sac@cygnus.com */
2388 if (def_symbol_in_progress
== NULL
)
2390 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2391 demand_empty_rest_of_line ();
2393 } /* if not inside .def/.endef */
2395 /* Set the section number according to storage class. */
2396 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2401 SF_SET_TAG (def_symbol_in_progress
);
2402 /* intentional fallthrough */
2405 SF_SET_DEBUG (def_symbol_in_progress
);
2406 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2410 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2411 /* intentional fallthrough */
2413 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2414 /* intentional fallthrough */
2416 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2418 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2420 if (function_lineoff
< 0)
2422 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2423 } /* missing function symbol */
2424 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2426 SF_SET_PROCESS (last_line_symbol
);
2427 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2428 SF_SET_PROCESS (def_symbol_in_progress
);
2429 function_lineoff
= -1;
2431 /* Value is always set to . */
2432 def_symbol_in_progress
->sy_frag
= frag_now
;
2433 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2438 #endif /* C_AUTOARG */
2448 SF_SET_DEBUG (def_symbol_in_progress
);
2449 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2459 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2465 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2467 } /* switch on storage class */
2469 /* Now that we have built a debug symbol, try to find if we should
2470 merge with an existing symbol or not. If a symbol is C_EFCN or
2471 absolute_section or untagged SEG_DEBUG it never merges. We also
2472 don't merge labels, which are in a different namespace, nor
2473 symbols which have not yet been defined since they are typically
2474 unique, nor do we merge tags with non-tags. */
2476 /* Two cases for functions. Either debug followed by definition or
2477 definition followed by debug. For definition first, we will
2478 merge the debug symbol into the definition. For debug first, the
2479 lineno entry MUST point to the definition function or else it
2480 will point off into space when crawl_symbols() merges the debug
2481 symbol into the real symbol. Therefor, let's presume the debug
2482 symbol is a real function reference. */
2484 /* FIXME-SOON If for some reason the definition label/symbol is
2485 never seen, this will probably leave an undefined symbol at link
2488 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2489 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2490 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2491 && !SF_GET_TAG (def_symbol_in_progress
))
2492 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2493 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2494 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2495 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2497 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2502 /* This symbol already exists, merge the newly created symbol
2503 into the old one. This is not mandatory. The linker can
2504 handle duplicate symbols correctly. But I guess that it save
2505 a *lot* of space if the assembly file defines a lot of
2508 /* The debug entry (def_symbol_in_progress) is merged into the
2509 previous definition. */
2511 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2512 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2513 def_symbol_in_progress
= symbolP
;
2515 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2516 || SF_GET_TAG (def_symbol_in_progress
)
2517 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2519 /* For functions, and tags, and static symbols, the symbol
2520 *must* be where the debug symbol appears. Move the
2521 existing symbol to the current place. */
2522 /* If it already is at the end of the symbol list, do nothing */
2523 if (def_symbol_in_progress
!= symbol_lastP
)
2525 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2527 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2528 &symbol_rootP
, &symbol_lastP
);
2529 } /* if not already in place */
2531 } /* normal or mergable */
2533 if (SF_GET_TAG (def_symbol_in_progress
))
2537 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2539 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2540 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2541 def_symbol_in_progress
);
2544 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2546 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2548 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2550 SF_SET_PROCESS (def_symbol_in_progress
);
2552 if (symbolP
== NULL
)
2554 /* That is, if this is the first time we've seen the
2556 symbol_table_insert (def_symbol_in_progress
);
2557 } /* definition follows debug */
2558 } /* Create the line number entry pointing to the function being defined */
2560 def_symbol_in_progress
= NULL
;
2561 demand_empty_rest_of_line ();
2565 obj_coff_dim (ignore
)
2566 int ignore ATTRIBUTE_UNUSED
;
2570 if (def_symbol_in_progress
== NULL
)
2572 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2573 demand_empty_rest_of_line ();
2575 } /* if not inside .def/.endef */
2577 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2579 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2581 SKIP_WHITESPACES ();
2582 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2583 get_absolute_expression ());
2585 switch (*input_line_pointer
)
2588 input_line_pointer
++;
2592 as_warn (_("badly formed .dim directive ignored"));
2593 /* intentional fallthrough */
2601 demand_empty_rest_of_line ();
2605 obj_coff_line (ignore
)
2606 int ignore ATTRIBUTE_UNUSED
;
2611 if (def_symbol_in_progress
== NULL
)
2617 name
= S_GET_NAME (def_symbol_in_progress
);
2618 this_base
= get_absolute_expression ();
2620 /* Only .bf symbols indicate the use of a new base line number; the
2621 line numbers associated with .ef, .bb, .eb are relative to the
2622 start of the containing function. */
2623 if (!strcmp (".bf", name
))
2625 #if 0 /* XXX Can we ever have line numbers going backwards? */
2626 if (this_base
> line_base
)
2629 line_base
= this_base
;
2637 listing_source_line ((unsigned int) line_base
);
2643 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2644 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2646 demand_empty_rest_of_line ();
2650 obj_coff_size (ignore
)
2651 int ignore ATTRIBUTE_UNUSED
;
2653 if (def_symbol_in_progress
== NULL
)
2655 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2656 demand_empty_rest_of_line ();
2658 } /* if not inside .def/.endef */
2660 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2661 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2662 demand_empty_rest_of_line ();
2666 obj_coff_scl (ignore
)
2667 int ignore ATTRIBUTE_UNUSED
;
2669 if (def_symbol_in_progress
== NULL
)
2671 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2672 demand_empty_rest_of_line ();
2674 } /* if not inside .def/.endef */
2676 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2677 demand_empty_rest_of_line ();
2681 obj_coff_tag (ignore
)
2682 int ignore ATTRIBUTE_UNUSED
;
2687 if (def_symbol_in_progress
== NULL
)
2689 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2690 demand_empty_rest_of_line ();
2694 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2695 symbol_name
= input_line_pointer
;
2696 name_end
= get_symbol_end ();
2697 #ifdef tc_canonicalize_symbol_name
2698 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2701 /* Assume that the symbol referred to by .tag is always defined.
2702 This was a bad assumption. I've added find_or_make. xoxorich. */
2703 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2704 (long) tag_find_or_make (symbol_name
));
2705 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2707 as_warn (_("tag not found for .tag %s"), symbol_name
);
2710 SF_SET_TAGGED (def_symbol_in_progress
);
2711 *input_line_pointer
= name_end
;
2713 demand_empty_rest_of_line ();
2717 obj_coff_type (ignore
)
2718 int ignore ATTRIBUTE_UNUSED
;
2720 if (def_symbol_in_progress
== NULL
)
2722 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2723 demand_empty_rest_of_line ();
2725 } /* if not inside .def/.endef */
2727 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2729 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2730 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2732 SF_SET_FUNCTION (def_symbol_in_progress
);
2733 } /* is a function */
2735 demand_empty_rest_of_line ();
2739 obj_coff_val (ignore
)
2740 int ignore ATTRIBUTE_UNUSED
;
2742 if (def_symbol_in_progress
== NULL
)
2744 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2745 demand_empty_rest_of_line ();
2747 } /* if not inside .def/.endef */
2749 if (is_name_beginner (*input_line_pointer
))
2751 char *symbol_name
= input_line_pointer
;
2752 char name_end
= get_symbol_end ();
2754 #ifdef tc_canonicalize_symbol_name
2755 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2758 if (!strcmp (symbol_name
, "."))
2760 def_symbol_in_progress
->sy_frag
= frag_now
;
2761 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2762 /* If the .val is != from the .def (e.g. statics) */
2764 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2766 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2767 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2768 symbol_find_or_make (symbol_name
);
2769 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2770 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2772 /* If the segment is undefined when the forward reference is
2773 resolved, then copy the segment id from the forward
2775 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2777 /* FIXME: gcc can generate address expressions here in
2778 unusual cases (search for "obscure" in sdbout.c). We
2779 just ignore the offset here, thus generating incorrect
2780 debugging information. We ignore the rest of the line
2783 /* Otherwise, it is the name of a non debug symbol and
2784 its value will be calculated later. */
2785 *input_line_pointer
= name_end
;
2787 /* FIXME: this is to avoid an error message in the
2788 FIXME case mentioned just above. */
2789 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2790 ++input_line_pointer
;
2794 S_SET_VALUE (def_symbol_in_progress
,
2795 (valueT
) get_absolute_expression ());
2796 } /* if symbol based */
2798 demand_empty_rest_of_line ();
2803 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2804 read.c, which then calls this object file format specific routine. */
2807 obj_coff_pe_handle_link_once (type
)
2808 enum linkonce_type type
;
2810 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2812 /* We store the type in the seg_info structure, and use it to set up
2813 the auxiliary entry for the section symbol in c_section_symbol. */
2814 seg_info (now_seg
)->linkonce
= type
;
2820 coff_obj_read_begin_hook ()
2822 /* These had better be the same. Usually 18 bytes. */
2824 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2825 know (SYMESZ
== AUXESZ
);
2830 /* This function runs through the symbol table and puts all the
2831 externals onto another chain */
2833 /* The chain of globals. */
2834 symbolS
*symbol_globalP
;
2835 symbolS
*symbol_global_lastP
;
2837 /* The chain of externals */
2838 symbolS
*symbol_externP
;
2839 symbolS
*symbol_extern_lastP
;
2842 symbolS
*last_functionP
;
2843 static symbolS
*last_bfP
;
2850 unsigned int symbol_number
= 0;
2851 unsigned int last_file_symno
= 0;
2853 struct filename_list
*filename_list_scan
= filename_list_head
;
2855 for (symbolP
= symbol_rootP
;
2857 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2859 if (symbolP
->sy_mri_common
)
2861 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2863 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2865 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2866 as_bad (_("%s: global symbols not supported in common sections"),
2867 S_GET_NAME (symbolP
));
2868 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2872 if (!SF_GET_DEBUG (symbolP
))
2874 /* Debug symbols do not need all this rubbish */
2875 symbolS
*real_symbolP
;
2877 /* L* and C_EFCN symbols never merge. */
2878 if (!SF_GET_LOCAL (symbolP
)
2879 && !SF_GET_STATICS (symbolP
)
2880 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2881 && symbolP
->sy_value
.X_op
== O_constant
2882 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2883 && real_symbolP
!= symbolP
)
2885 /* FIXME-SOON: where do dups come from?
2886 Maybe tag references before definitions? xoxorich. */
2887 /* Move the debug data from the debug symbol to the
2888 real symbol. Do NOT do the oposite (i.e. move from
2889 real symbol to debug symbol and remove real symbol from the
2890 list.) Because some pointers refer to the real symbol
2891 whereas no pointers refer to the debug symbol. */
2892 c_symbol_merge (symbolP
, real_symbolP
);
2893 /* Replace the current symbol by the real one */
2894 /* The symbols will never be the last or the first
2895 because : 1st symbol is .file and 3 last symbols are
2896 .text, .data, .bss */
2897 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2898 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2899 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2900 symbolP
= real_symbolP
;
2901 } /* if not local but dup'd */
2903 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2905 S_SET_SEGMENT (symbolP
, SEG_E0
);
2906 } /* push data into text */
2908 resolve_symbol_value (symbolP
, 1);
2910 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2912 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2914 S_SET_EXTERNAL (symbolP
);
2916 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2918 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2922 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2926 /* Mainly to speed up if not -g */
2927 if (SF_GET_PROCESS (symbolP
))
2929 /* Handle the nested blocks auxiliary info. */
2930 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2932 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2933 stack_push (block_stack
, (char *) &symbolP
);
2936 register symbolS
*begin_symbolP
;
2937 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2938 if (begin_symbolP
== (symbolS
*) 0)
2939 as_warn (_("mismatched .eb"));
2941 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2944 /* If we are able to identify the type of a function, and we
2945 are out of a function (last_functionP == 0) then, the
2946 function symbol will be associated with an auxiliary
2948 if (last_functionP
== (symbolS
*) 0 &&
2949 SF_GET_FUNCTION (symbolP
))
2951 last_functionP
= symbolP
;
2953 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2955 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2956 } /* make it at least 1 */
2958 /* Clobber possible stale .dim information. */
2960 /* Iffed out by steve - this fries the lnnoptr info too */
2961 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2962 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2965 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2967 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2969 if (last_bfP
!= NULL
)
2970 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2974 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2976 /* I don't even know if this is needed for sdb. But
2977 the standard assembler generates it, so... */
2978 if (last_functionP
== (symbolS
*) 0)
2979 as_fatal (_("C_EFCN symbol out of scope"));
2980 SA_SET_SYM_FSIZE (last_functionP
,
2981 (long) (S_GET_VALUE (symbolP
) -
2982 S_GET_VALUE (last_functionP
)));
2983 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2984 last_functionP
= (symbolS
*) 0;
2988 else if (SF_GET_TAG (symbolP
))
2990 /* First descriptor of a structure must point to
2991 the first slot after the structure description. */
2992 last_tagP
= symbolP
;
2995 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2997 /* +2 take in account the current symbol */
2998 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3000 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3002 /* If the filename was too long to fit in the
3003 auxent, put it in the string table */
3004 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3005 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3007 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3008 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3009 filename_list_scan
= filename_list_scan
->next
;
3011 if (S_GET_VALUE (symbolP
))
3013 S_SET_VALUE (symbolP
, last_file_symno
);
3014 last_file_symno
= symbol_number
;
3015 } /* no one points at the first .file symbol */
3016 } /* if debug or tag or eos or file */
3018 #ifdef tc_frob_coff_symbol
3019 tc_frob_coff_symbol (symbolP
);
3022 /* We must put the external symbols apart. The loader
3023 does not bomb if we do not. But the references in
3024 the endndx field for a .bb symbol are not corrected
3025 if an external symbol is removed between .bb and .be.
3026 I.e in the following case :
3027 [20] .bb endndx = 22
3030 ld will move the symbol 21 to the end of the list but
3031 endndx will still be 22 instead of 21. */
3034 if (SF_GET_LOCAL (symbolP
))
3036 /* remove C_EFCN and LOCAL (L...) symbols */
3037 /* next pointer remains valid */
3038 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3041 else if (symbolP
->sy_value
.X_op
== O_symbol
3042 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3044 /* Skip symbols which were equated to undefined or common
3046 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3048 else if (!S_IS_DEFINED (symbolP
)
3049 && !S_IS_DEBUG (symbolP
)
3050 && !SF_GET_STATICS (symbolP
)
3051 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3053 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3055 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3057 /* if external, Remove from the list */
3058 symbolS
*hold
= symbol_previous (symbolP
);
3060 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3061 symbol_clear_list_pointers (symbolP
);
3062 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3065 else if (! S_IS_DEBUG (symbolP
)
3066 && ! SF_GET_STATICS (symbolP
)
3067 && ! SF_GET_FUNCTION (symbolP
)
3068 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3070 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3072 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3074 symbolS
*hold
= symbol_previous (symbolP
);
3076 /* The O'Reilly COFF book says that defined global symbols
3077 come at the end of the symbol table, just before
3078 undefined global symbols. */
3080 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3081 symbol_clear_list_pointers (symbolP
);
3082 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3083 &symbol_global_lastP
);
3088 if (SF_GET_STRING (symbolP
))
3090 symbolP
->sy_name_offset
= string_byte_count
;
3091 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3095 symbolP
->sy_name_offset
= 0;
3096 } /* fix "long" names */
3098 symbolP
->sy_number
= symbol_number
;
3099 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3100 } /* if local symbol */
3101 } /* traverse the symbol list */
3102 return symbol_number
;
3108 glue_symbols (head
, tail
)
3112 unsigned int symbol_number
= 0;
3114 while (*head
!= NULL
)
3116 symbolS
*tmp
= *head
;
3119 symbol_remove (tmp
, head
, tail
);
3120 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3123 if (SF_GET_STRING (tmp
))
3125 tmp
->sy_name_offset
= string_byte_count
;
3126 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3130 tmp
->sy_name_offset
= 0;
3131 } /* fix "long" names */
3133 tmp
->sy_number
= symbol_number
;
3134 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3135 } /* append the entire extern chain */
3137 return symbol_number
;
3143 unsigned int symbol_number
= 0;
3146 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3148 symbolP
->sy_number
= symbol_number
;
3150 if (SF_GET_TAGGED (symbolP
))
3154 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3157 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3160 return symbol_number
;
3164 crawl_symbols (h
, abfd
)
3166 bfd
*abfd ATTRIBUTE_UNUSED
;
3170 /* Initialize the stack used to keep track of the matching .bb .be */
3172 block_stack
= stack_init (512, sizeof (symbolS
*));
3174 /* The symbol list should be ordered according to the following sequence
3177 * . debug entries for functions
3178 * . fake symbols for the sections, including .text .data and .bss
3180 * . undefined symbols
3181 * But this is not mandatory. The only important point is to put the
3182 * undefined symbols at the end of the list.
3185 /* Is there a .file symbol ? If not insert one at the beginning. */
3186 if (symbol_rootP
== NULL
3187 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3189 c_dot_file_symbol ("fake");
3193 * Build up static symbols for the sections, they are filled in later
3197 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3198 if (segment_info
[i
].scnhdr
.s_name
[0])
3199 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3202 /* Take all the externals out and put them into another chain */
3203 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3204 /* Take the externals and glue them onto the end.*/
3205 H_SET_SYMBOL_TABLE_SIZE (h
,
3206 (H_GET_SYMBOL_COUNT (h
)
3207 + glue_symbols (&symbol_globalP
,
3208 &symbol_global_lastP
)
3209 + glue_symbols (&symbol_externP
,
3210 &symbol_extern_lastP
)));
3212 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3213 know (symbol_globalP
== NULL
);
3214 know (symbol_global_lastP
== NULL
);
3215 know (symbol_externP
== NULL
);
3216 know (symbol_extern_lastP
== NULL
);
3220 * Find strings by crawling along symbol table chain.
3228 struct filename_list
*filename_list_scan
= filename_list_head
;
3230 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3231 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3234 #ifdef COFF_LONG_SECTION_NAMES
3235 /* Support long section names as found in PE. This code must
3236 coordinate with that in coff_header_append and write_object_file. */
3240 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3242 if (segment_info
[i
].scnhdr
.s_name
[0]
3243 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3247 size
= strlen (segment_info
[i
].name
) + 1;
3248 memcpy (where
, segment_info
[i
].name
, size
);
3253 #endif /* COFF_LONG_SECTION_NAMES */
3255 for (symbolP
= symbol_rootP
;
3257 symbolP
= symbol_next (symbolP
))
3261 if (SF_GET_STRING (symbolP
))
3263 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3264 memcpy (where
, S_GET_NAME (symbolP
), size
);
3267 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3268 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3269 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3271 size
= strlen (filename_list_scan
->filename
) + 1;
3272 memcpy (where
, filename_list_scan
->filename
, size
);
3273 filename_list_scan
= filename_list_scan
->next
;
3280 do_linenos_for (abfd
, h
, file_cursor
)
3283 unsigned long *file_cursor
;
3286 unsigned long start
= *file_cursor
;
3288 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3290 segment_info_type
*s
= segment_info
+ idx
;
3293 if (s
->scnhdr
.s_nlnno
!= 0)
3295 struct lineno_list
*line_ptr
;
3297 struct external_lineno
*buffer
=
3298 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3300 struct external_lineno
*dst
= buffer
;
3302 /* Run through the table we've built and turn it into its external
3303 form, take this chance to remove duplicates */
3305 for (line_ptr
= s
->lineno_list_head
;
3306 line_ptr
!= (struct lineno_list
*) NULL
;
3307 line_ptr
= line_ptr
->next
)
3310 if (line_ptr
->line
.l_lnno
== 0)
3312 /* Turn a pointer to a symbol into the symbols' index */
3313 line_ptr
->line
.l_addr
.l_symndx
=
3314 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3318 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3322 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3327 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3329 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3332 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3335 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3339 /* Now we run through the list of frag chains in a segment and
3340 make all the subsegment frags appear at the end of the
3341 list, as if the seg 0 was extra long */
3348 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3350 frchainS
*head
= segment_info
[i
].frchainP
;
3352 fragS
*prev_frag
= &dummy
;
3354 while (head
&& head
->frch_seg
== i
)
3356 prev_frag
->fr_next
= head
->frch_root
;
3357 prev_frag
= head
->frch_last
;
3358 head
= head
->frch_next
;
3360 prev_frag
->fr_next
= 0;
3364 unsigned long machine
;
3367 write_object_file ()
3371 struct frchain
*frchain_ptr
;
3373 object_headers headers
;
3374 unsigned long file_cursor
;
3377 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3382 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3383 exit (EXIT_FAILURE
);
3385 bfd_set_format (abfd
, bfd_object
);
3386 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3388 string_byte_count
= 4;
3390 for (frchain_ptr
= frchain_root
;
3391 frchain_ptr
!= (struct frchain
*) NULL
;
3392 frchain_ptr
= frchain_ptr
->frch_next
)
3394 /* Run through all the sub-segments and align them up. Also
3395 close any open frags. We tack a .fill onto the end of the
3396 frag chain so that any .align's size can be worked by looking
3397 at the next frag. */
3399 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3401 #ifndef SUB_SEGMENT_ALIGN
3402 #define SUB_SEGMENT_ALIGN(SEG) 1
3405 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3408 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3409 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3414 frag_wane (frag_now
);
3415 frag_now
->fr_fix
= 0;
3416 know (frag_now
->fr_next
== NULL
);
3423 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3425 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3428 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3430 /* Find out how big the sections are, and set the addresses. */
3432 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3436 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3437 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3439 if (segment_info
[i
].scnhdr
.s_name
[0])
3441 H_SET_NUMBER_OF_SECTIONS (&headers
,
3442 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3444 #ifdef COFF_LONG_SECTION_NAMES
3445 /* Support long section names as found in PE. This code
3446 must coordinate with that in coff_header_append and
3451 len
= strlen (segment_info
[i
].name
);
3453 string_byte_count
+= len
+ 1;
3455 #endif /* COFF_LONG_SECTION_NAMES */
3458 size
= size_section (abfd
, (unsigned int) i
);
3461 /* I think the section alignment is only used on the i960; the
3462 i960 needs it, and it should do no harm on other targets. */
3463 #ifdef ALIGNMENT_IN_S_FLAGS
3464 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3466 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3470 H_SET_TEXT_SIZE (&headers
, size
);
3471 else if (i
== SEG_E1
)
3472 H_SET_DATA_SIZE (&headers
, size
);
3473 else if (i
== SEG_E2
)
3474 H_SET_BSS_SIZE (&headers
, size
);
3477 /* Turn the gas native symbol table shape into a coff symbol table */
3478 crawl_symbols (&headers
, abfd
);
3480 if (string_byte_count
== 4)
3481 string_byte_count
= 0;
3483 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3489 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3491 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3492 fixup_segment (&segment_info
[i
], i
);
3495 /* Look for ".stab" segments and fill in their initial symbols
3497 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3499 name
= segment_info
[i
].name
;
3502 && strncmp (".stab", name
, 5) == 0
3503 && strncmp (".stabstr", name
, 8) != 0)
3504 adjust_stab_section (abfd
, i
);
3507 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3509 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3511 /* Plant the data */
3513 fill_section (abfd
, &headers
, &file_cursor
);
3515 do_relocs_for (abfd
, &headers
, &file_cursor
);
3517 do_linenos_for (abfd
, &headers
, &file_cursor
);
3519 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3520 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3521 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3523 H_SET_TIME_STAMP (&headers
, 0);
3525 #ifdef TC_COFF_SET_MACHINE
3526 TC_COFF_SET_MACHINE (&headers
);
3530 #define COFF_FLAGS 0
3533 #ifdef KEEP_RELOC_INFO
3534 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3535 COFF_FLAGS
| coff_flags
));
3537 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3538 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3539 COFF_FLAGS
| coff_flags
));
3543 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3544 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3546 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3547 w_symbols (abfd
, buffer1
, symbol_rootP
);
3548 if (string_byte_count
> 0)
3549 w_strings (buffer1
+ symtable_size
);
3550 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3554 coff_header_append (abfd
, &headers
);
3556 /* Recent changes to write need this, but where it should
3557 go is up to Ken.. */
3558 if (bfd_close_all_done (abfd
) == false)
3559 as_fatal (_("Can't close %s: %s"), out_file_name
,
3560 bfd_errmsg (bfd_get_error ()));
3563 extern bfd
*stdoutput
;
3570 /* Add a new segment. This is called from subseg_new via the
3571 obj_new_segment macro. */
3574 obj_coff_add_segment (name
)
3579 #ifndef COFF_LONG_SECTION_NAMES
3580 char buf
[SCNNMLEN
+ 1];
3582 strncpy (buf
, name
, SCNNMLEN
);
3583 buf
[SCNNMLEN
] = '\0';
3587 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3588 if (strcmp (name
, segment_info
[i
].name
) == 0)
3593 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3597 /* Add a new section. */
3598 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3599 sizeof (segment_info
[i
].scnhdr
.s_name
));
3600 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3601 segment_info
[i
].name
= xstrdup (name
);
3607 * implement the .section pseudo op:
3608 * .section name {, "flags"}
3610 * | +--- optional flags: 'b' for bss
3612 * +-- section name 'l' for lib
3616 * 'd' (apparently m88k for data)
3618 * 'r' for read-only data
3619 * But if the argument is not a quoted string, treat it as a
3620 * subsegment number.
3624 obj_coff_section (ignore
)
3625 int ignore ATTRIBUTE_UNUSED
;
3627 /* Strip out the section name */
3628 char *section_name
, *name
;
3641 else if (type
== 'D')
3643 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3648 section_name
= input_line_pointer
;
3649 c
= get_symbol_end ();
3651 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3652 strcpy (name
, section_name
);
3654 *input_line_pointer
= c
;
3660 if (*input_line_pointer
== ',')
3662 ++input_line_pointer
;
3665 if (*input_line_pointer
!= '"')
3666 exp
= get_absolute_expression ();
3669 ++input_line_pointer
;
3670 while (*input_line_pointer
!= '"'
3671 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3673 switch (*input_line_pointer
)
3675 case 'b': flags
|= STYP_BSS
; break;
3676 case 'i': flags
|= STYP_INFO
; break;
3677 case 'l': flags
|= STYP_LIB
; break;
3678 case 'n': flags
|= STYP_NOLOAD
; break;
3679 case 'o': flags
|= STYP_OVER
; break;
3681 case 'w': flags
|= STYP_DATA
; break;
3682 case 'x': flags
|= STYP_TEXT
; break;
3683 case 'r': flags
|= STYP_LIT
; break;
3685 as_warn(_("unknown section attribute '%c'"),
3686 *input_line_pointer
);
3689 ++input_line_pointer
;
3691 if (*input_line_pointer
== '"')
3692 ++input_line_pointer
;
3696 subseg_new (name
, (subsegT
) exp
);
3698 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3700 demand_empty_rest_of_line ();
3705 obj_coff_text (ignore
)
3706 int ignore ATTRIBUTE_UNUSED
;
3708 subseg_new (".text", get_absolute_expression ());
3713 obj_coff_data (ignore
)
3714 int ignore ATTRIBUTE_UNUSED
;
3716 if (flag_readonly_data_in_text
)
3717 subseg_new (".text", get_absolute_expression () + 1000);
3719 subseg_new (".data", get_absolute_expression ());
3723 obj_coff_ident (ignore
)
3724 int ignore ATTRIBUTE_UNUSED
;
3726 segT current_seg
= now_seg
; /* save current seg */
3727 subsegT current_subseg
= now_subseg
;
3728 subseg_new (".comment", 0); /* .comment seg */
3729 stringer (1); /* read string */
3730 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3734 c_symbol_merge (debug
, normal
)
3738 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3739 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3741 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3743 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3744 } /* take the most we have */
3746 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3748 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3749 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3750 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3751 } /* Move all the auxiliary information */
3753 /* Move the debug flags. */
3754 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3755 } /* c_symbol_merge() */
3758 c_line_new (symbol
, paddr
, line_number
, frag
)
3764 struct lineno_list
*new_line
=
3765 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3767 segment_info_type
*s
= segment_info
+ now_seg
;
3768 new_line
->line
.l_lnno
= line_number
;
3770 if (line_number
== 0)
3772 last_line_symbol
= symbol
;
3773 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3777 new_line
->line
.l_addr
.l_paddr
= paddr
;
3780 new_line
->frag
= (char *) frag
;
3781 new_line
->next
= (struct lineno_list
*) NULL
;
3784 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3786 s
->lineno_list_head
= new_line
;
3790 s
->lineno_list_tail
->next
= new_line
;
3792 s
->lineno_list_tail
= new_line
;
3793 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3797 c_dot_file_symbol (filename
)
3802 symbolP
= symbol_new (".file",
3805 &zero_address_frag
);
3807 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3808 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3810 if (strlen (filename
) > FILNMLEN
)
3812 /* Filename is too long to fit into an auxent,
3813 we stick it into the string table instead. We keep
3814 a linked list of the filenames we find so we can emit
3816 struct filename_list
*f
= ((struct filename_list
*)
3817 xmalloc (sizeof (struct filename_list
)));
3819 f
->filename
= filename
;
3822 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3823 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3825 if (filename_list_tail
)
3826 filename_list_tail
->next
= f
;
3828 filename_list_head
= f
;
3829 filename_list_tail
= f
;
3833 SA_SET_FILE_FNAME (symbolP
, filename
);
3840 listing_source_file (filename
);
3846 SF_SET_DEBUG (symbolP
);
3847 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3849 previous_file_symbol
= symbolP
;
3851 /* Make sure that the symbol is first on the symbol chain */
3852 if (symbol_rootP
!= symbolP
)
3854 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3855 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3857 } /* c_dot_file_symbol() */
3860 * Build a 'section static' symbol.
3864 c_section_symbol (name
, idx
)
3870 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3871 if (symbolP
== NULL
)
3872 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3875 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3876 S_SET_SEGMENT (symbolP
, idx
);
3877 symbolP
->sy_frag
= &zero_address_frag
;
3880 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3881 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3883 SF_SET_STATICS (symbolP
);
3886 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3887 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3888 SF_CLEAR_LOCAL (symbolP
);
3891 /* If the .linkonce pseudo-op was used for this section, we must
3892 store the information in the auxiliary entry for the section
3894 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3898 switch (segment_info
[idx
].linkonce
)
3902 case LINKONCE_DISCARD
:
3903 type
= IMAGE_COMDAT_SELECT_ANY
;
3905 case LINKONCE_ONE_ONLY
:
3906 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3908 case LINKONCE_SAME_SIZE
:
3909 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3911 case LINKONCE_SAME_CONTENTS
:
3912 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3916 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3921 } /* c_section_symbol() */
3924 w_symbols (abfd
, where
, symbol_rootP
)
3927 symbolS
* symbol_rootP
;
3932 /* First fill in those values we have only just worked out */
3933 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3935 symbolP
= segment_info
[i
].dot
;
3938 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3939 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3940 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3945 * Emit all symbols left in the symbol chain.
3947 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3949 /* Used to save the offset of the name. It is used to point
3950 to the string in memory but must be a file offset. */
3951 register char *temp
;
3953 /* We can't fix the lnnoptr field in yank_symbols with the other
3954 adjustments, because we have to wait until we know where they
3956 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3958 SA_GET_SYM_LNNOPTR (symbolP
) +=
3959 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3962 tc_coff_symbol_emit_hook (symbolP
);
3964 temp
= S_GET_NAME (symbolP
);
3965 if (SF_GET_STRING (symbolP
))
3967 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3968 S_SET_ZEROES (symbolP
, 0);
3972 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3973 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3975 where
= symbol_to_chars (abfd
, where
, symbolP
);
3976 S_SET_NAME (symbolP
, temp
);
3982 obj_coff_lcomm (ignore
)
3983 int ignore ATTRIBUTE_UNUSED
;
3995 name
= input_line_pointer
;
3997 c
= get_symbol_end ();
3998 p
= input_line_pointer
;
4001 if (*input_line_pointer
!= ',')
4003 as_bad (_("Expected comma after name"));
4004 ignore_rest_of_line ();
4007 if (*input_line_pointer
== '\n')
4009 as_bad (_("Missing size expression"));
4012 input_line_pointer
++;
4013 if ((temp
= get_absolute_expression ()) < 0)
4015 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4016 ignore_rest_of_line ();
4021 symbolP
= symbol_find_or_make(name
);
4023 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
4024 S_GET_VALUE(symbolP
) == 0)
4029 segT current_seg
= now_seg
; /* save current seg */
4030 subsegT current_subseg
= now_subseg
;
4032 subseg_set (SEG_E2
, 1);
4033 symbolP
->sy_frag
= frag_now
;
4034 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4035 (offsetT
) temp
, (char *) 0);
4037 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4038 S_SET_SEGMENT(symbolP
, SEG_E2
);
4039 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
4043 as_bad(_("Symbol %s already defined"), name
);
4045 demand_empty_rest_of_line();
4050 fixup_mdeps (frags
, h
, this_segment
)
4055 subseg_change (this_segment
, 0);
4058 switch (frags
->fr_type
)
4064 HANDLE_ALIGN (frags
);
4066 frags
->fr_type
= rs_fill
;
4068 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4071 case rs_machine_dependent
:
4072 md_convert_frag (h
, this_segment
, frags
);
4078 frags
= frags
->fr_next
;
4084 #ifndef TC_FORCE_RELOCATION
4085 #define TC_FORCE_RELOCATION(fix) 0
4089 fixup_segment (segP
, this_segment_type
)
4090 segment_info_type
* segP
;
4091 segT this_segment_type
;
4093 register fixS
* fixP
;
4094 register symbolS
*add_symbolP
;
4095 register symbolS
*sub_symbolP
;
4098 register char *place
;
4099 register long where
;
4100 register char pcrel
;
4101 register fragS
*fragP
;
4102 register segT add_symbol_segment
= absolute_section
;
4104 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4106 fragP
= fixP
->fx_frag
;
4108 where
= fixP
->fx_where
;
4109 place
= fragP
->fr_literal
+ where
;
4110 size
= fixP
->fx_size
;
4111 add_symbolP
= fixP
->fx_addsy
;
4112 sub_symbolP
= fixP
->fx_subsy
;
4113 add_number
= fixP
->fx_offset
;
4114 pcrel
= fixP
->fx_pcrel
;
4116 /* We want function-relative stabs to work on systems which
4117 may use a relaxing linker; thus we must handle the sym1-sym2
4118 fixups function-relative stabs generates.
4120 Of course, if you actually enable relaxing in the linker, the
4121 line and block scoping information is going to be incorrect
4122 in some cases. The only way to really fix this is to support
4123 a reloc involving the difference of two symbols. */
4125 && (!sub_symbolP
|| pcrel
))
4129 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4131 /* Relocation should be done via the associated 'bal' entry
4134 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4136 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4137 _("No 'bal' entry point for leafproc %s"),
4138 S_GET_NAME (add_symbolP
));
4141 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4145 /* Make sure the symbols have been resolved; this may not have
4146 happened if these are expression symbols. */
4147 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4148 resolve_symbol_value (add_symbolP
, 1);
4150 if (add_symbolP
!= NULL
)
4152 /* If this fixup is against a symbol which has been equated
4153 to another symbol, convert it to the other symbol. */
4154 if (add_symbolP
->sy_value
.X_op
== O_symbol
4155 && (! S_IS_DEFINED (add_symbolP
)
4156 || S_IS_COMMON (add_symbolP
)))
4158 while (add_symbolP
->sy_value
.X_op
== O_symbol
4159 && (! S_IS_DEFINED (add_symbolP
)
4160 || S_IS_COMMON (add_symbolP
)))
4164 /* We must avoid looping, as that can occur with a
4165 badly written program. */
4166 n
= add_symbolP
->sy_value
.X_add_symbol
;
4167 if (n
== add_symbolP
)
4169 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4172 fixP
->fx_addsy
= add_symbolP
;
4173 fixP
->fx_offset
= add_number
;
4177 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4178 resolve_symbol_value (sub_symbolP
, 1);
4180 if (add_symbolP
!= NULL
4181 && add_symbolP
->sy_mri_common
)
4183 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4184 add_number
+= S_GET_VALUE (add_symbolP
);
4185 fixP
->fx_offset
= add_number
;
4186 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4191 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4192 } /* if there is an addend */
4196 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4198 if (add_symbolP
!= NULL
)
4200 add_number
+= S_GET_VALUE (add_symbolP
);
4202 fixP
->fx_addsy
= NULL
;
4205 /* It's just -sym. */
4206 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4208 add_number
-= S_GET_VALUE (sub_symbolP
);
4215 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4216 _("Negative of non-absolute symbol %s"),
4217 S_GET_NAME (sub_symbolP
));
4219 add_number
-= S_GET_VALUE (sub_symbolP
);
4220 } /* not absolute */
4222 /* if sub_symbol is in the same segment that add_symbol
4223 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4225 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4226 && SEG_NORMAL (add_symbol_segment
))
4228 /* Difference of 2 symbols from same segment. Can't
4229 make difference of 2 undefineds: 'value' means
4230 something different for N_UNDF. */
4232 /* Makes no sense to use the difference of 2 arbitrary symbols
4233 as the target of a call instruction. */
4236 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4237 _("callj to difference of 2 symbols"));
4239 #endif /* TC_I960 */
4240 add_number
+= S_GET_VALUE (add_symbolP
) -
4241 S_GET_VALUE (sub_symbolP
);
4244 if (!TC_FORCE_RELOCATION (fixP
))
4246 fixP
->fx_addsy
= NULL
;
4247 fixP
->fx_subsy
= NULL
;
4249 #ifdef TC_M68K /* is this right? */
4257 /* Different segments in subtraction. */
4258 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4260 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4262 add_number
-= S_GET_VALUE (sub_symbolP
);
4265 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4266 #if 0 /* Okay for 68k, at least... */
4271 /* Make it pc-relative. */
4272 add_number
+= (md_pcrel_from (fixP
)
4273 - S_GET_VALUE (sub_symbolP
));
4282 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4283 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4284 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4285 S_GET_NAME (sub_symbolP
),
4286 (long) (fragP
->fr_address
+ where
));
4289 } /* if sub_symbolP */
4293 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4296 * This fixup was made when the symbol's segment was
4297 * SEG_UNKNOWN, but it is now in the local segment.
4298 * So we know how to do the address without relocation.
4301 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4302 * in which cases it modifies *fixP as appropriate. In the case
4303 * of a 'calls', no further work is required, and *fixP has been
4304 * set up to make the rest of the code below a no-op.
4307 #endif /* TC_I960 */
4309 add_number
+= S_GET_VALUE (add_symbolP
);
4310 add_number
-= md_pcrel_from (fixP
);
4313 add_number -= segP->scnhdr.s_vaddr;
4314 if defined (TC_I386) || defined (TE_LYNX). I now
4315 think that was an error propagated from the case when
4316 we are going to emit the relocation. If we are not
4317 going to emit the relocation, then we just want to
4318 set add_number to the difference between the symbols.
4319 This is a case that would only arise when there is a
4320 PC relative reference from a section other than .text
4321 to a symbol defined in the same section, and the
4322 reference is not relaxed. Since jump instructions on
4323 the i386 are relaxed, this could only arise with a
4324 call instruction. */
4326 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4327 if (!TC_FORCE_RELOCATION (fixP
))
4329 fixP
->fx_addsy
= NULL
;
4335 switch (add_symbol_segment
)
4337 case absolute_section
:
4339 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4340 #endif /* TC_I960 */
4341 add_number
+= S_GET_VALUE (add_symbolP
);
4344 if (!TC_FORCE_RELOCATION (fixP
))
4346 fixP
->fx_addsy
= NULL
;
4353 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4354 /* This really should be handled in the linker, but
4355 backward compatibility forbids. */
4356 add_number
+= S_GET_VALUE (add_symbolP
);
4358 add_number
+= S_GET_VALUE (add_symbolP
) +
4359 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4365 if ((int) fixP
->fx_bit_fixP
== 13)
4367 /* This is a COBR instruction. They have only a
4368 * 13-bit displacement and are only to be used
4369 * for local branches: flag as error, don't generate
4372 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4373 _("can't use COBR format with external label"));
4374 fixP
->fx_addsy
= NULL
;
4378 #endif /* TC_I960 */
4379 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4380 /* 386 COFF uses a peculiar format in which the
4381 value of a common symbol is stored in the .text
4382 segment (I've checked this on SVR3.2 and SCO
4383 3.2.2) Ian Taylor <ian@cygnus.com>. */
4384 /* This is also true for 68k COFF on sysv machines
4385 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4386 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4387 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4388 if (S_IS_COMMON (add_symbolP
))
4389 add_number
+= S_GET_VALUE (add_symbolP
);
4394 } /* switch on symbol seg */
4395 } /* if not in local seg */
4396 } /* if there was a + symbol */
4400 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4401 /* This adjustment is not correct on the m88k, for which the
4402 linker does all the computation. */
4403 add_number
-= md_pcrel_from (fixP
);
4405 if (add_symbolP
== 0)
4407 fixP
->fx_addsy
= &abs_symbol
;
4408 } /* if there's an add_symbol */
4409 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4410 /* On the 386 we must adjust by the segment vaddr as well.
4413 I changed the i960 to work this way as well. This is
4414 compatible with the current GNU linker behaviour. I do
4415 not know what other i960 COFF assemblers do. This is not
4416 a common case: normally, only assembler code will contain
4417 a PC relative reloc, and only branches which do not
4418 originate in the .text section will have a non-zero
4421 I changed the m68k to work this way as well. This will
4422 break existing PC relative relocs from sections which do
4423 not start at address 0, but it will make ld -r work.
4424 Ian Taylor, 4 Oct 96. */
4426 add_number
-= segP
->scnhdr
.s_vaddr
;
4430 #ifdef MD_APPLY_FIX3
4431 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4433 md_apply_fix (fixP
, add_number
);
4436 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4439 /* The m88k uses the offset field of the reloc to get around
4442 && ((add_number
& ~0xFF)
4443 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4444 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4445 || (add_number
& 0x80) == 0))
4447 && ((add_number
& ~0xFFFF)
4448 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4449 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4450 || (add_number
& 0x8000) == 0)))
4452 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4453 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4454 (long) add_number
, size
,
4455 (unsigned long) (fragP
->fr_address
+ where
));
4458 #ifdef WARN_SIGNED_OVERFLOW_WORD
4459 /* Warn if a .word value is too large when treated as a
4460 signed number. We already know it is not too negative.
4461 This is to catch over-large switches generated by gcc on
4463 if (!flag_signed_overflow_ok
4465 && add_number
> 0x7fff)
4466 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4467 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4469 (unsigned long) (fragP
->fr_address
+ where
));
4471 } /* not a bit fix */
4472 } /* For each fixS in this segment. */
4473 } /* fixup_segment() */
4477 /* The first entry in a .stab section is special. */
4480 obj_coff_init_stab_section (seg
)
4486 unsigned int stroff
;
4488 /* Make space for this first symbol. */
4492 as_where (&file
, (unsigned int *) NULL
);
4493 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4494 strcpy (stabstr_name
, segment_info
[seg
].name
);
4495 strcat (stabstr_name
, "str");
4496 stroff
= get_stab_string_offset (file
, stabstr_name
);
4498 md_number_to_chars (p
, stroff
, 4);
4501 /* Fill in the counts in the first entry in a .stab section. */
4504 adjust_stab_section(abfd
, seg
)
4508 segT stabstrseg
= SEG_UNKNOWN
;
4509 const char *secname
, *name2
;
4512 int i
, strsz
= 0, nsyms
;
4513 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4515 /* Look for the associated string table section. */
4517 secname
= segment_info
[seg
].name
;
4518 name
= (char *) alloca (strlen (secname
) + 4);
4519 strcpy (name
, secname
);
4520 strcat (name
, "str");
4522 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4524 name2
= segment_info
[i
].name
;
4525 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4532 /* If we found the section, get its size. */
4533 if (stabstrseg
!= SEG_UNKNOWN
)
4534 strsz
= size_section (abfd
, stabstrseg
);
4536 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4538 /* Look for the first frag of sufficient size for the initial stab
4539 symbol, and collect a pointer to it. */
4540 while (frag
&& frag
->fr_fix
< 12)
4541 frag
= frag
->fr_next
;
4543 p
= frag
->fr_literal
;
4546 /* Write in the number of stab symbols and the size of the string
4548 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4549 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4552 #endif /* not BFD_ASSEMBLER */
4554 const pseudo_typeS coff_pseudo_table
[] =
4556 {"def", obj_coff_def
, 0},
4557 {"dim", obj_coff_dim
, 0},
4558 {"endef", obj_coff_endef
, 0},
4559 {"line", obj_coff_line
, 0},
4560 {"ln", obj_coff_ln
, 0},
4561 #ifdef BFD_ASSEMBLER
4562 {"loc", obj_coff_loc
, 0},
4564 {"appline", obj_coff_ln
, 1},
4565 {"scl", obj_coff_scl
, 0},
4566 {"size", obj_coff_size
, 0},
4567 {"tag", obj_coff_tag
, 0},
4568 {"type", obj_coff_type
, 0},
4569 {"val", obj_coff_val
, 0},
4570 {"section", obj_coff_section
, 0},
4571 {"sect", obj_coff_section
, 0},
4572 /* FIXME: We ignore the MRI short attribute. */
4573 {"section.s", obj_coff_section
, 0},
4574 {"sect.s", obj_coff_section
, 0},
4575 /* We accept the .bss directive for backward compatibility with
4576 earlier versions of gas. */
4577 {"bss", obj_coff_bss
, 0},
4578 {"weak", obj_coff_weak
, 0},
4579 {"ident", obj_coff_ident
, 0},
4580 #ifndef BFD_ASSEMBLER
4581 {"use", obj_coff_section
, 0},
4582 {"text", obj_coff_text
, 0},
4583 {"data", obj_coff_data
, 0},
4584 {"lcomm", obj_coff_lcomm
, 0},
4586 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4588 {"version", s_ignore
, 0},
4589 {"ABORT", s_abort
, 0},
4591 /* The m88k uses sdef instead of def. */
4592 {"sdef", obj_coff_def
, 0},
4594 {NULL
, NULL
, 0} /* end sentinel */
4595 }; /* coff_pseudo_table */
4597 #ifdef BFD_ASSEMBLER
4599 /* Support for a COFF emulation. */
4601 static void coff_pop_insert
PARAMS ((void));
4602 static int coff_separate_stab_sections
PARAMS ((void));
4607 pop_insert (coff_pseudo_table
);
4611 coff_separate_stab_sections ()
4616 const struct format_ops coff_format_ops
=
4618 bfd_target_coff_flavour
,
4619 0, /* dfl_leading_underscore */
4620 1, /* emit_section_symbols */
4625 coff_frob_file_after_relocs
,
4628 0, /* s_get_align */
4629 0, /* s_set_align */
4630 0, /* s_get_other */
4631 0, /* s_set_other */
4636 0, /* copy_symbol_attributes */
4637 0, /* generate_asm_lineno */
4638 0, /* process_stab */
4639 coff_separate_stab_sections
,
4640 obj_coff_init_stab_section
,
4641 0, /* sec_sym_ok_for_reloc */
4643 0, /* ecoff_set_ext */
4644 coff_obj_read_begin_hook
,
4645 coff_obj_symbol_new_hook