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
;
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 */
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
;
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 if (flags
!= SEC_NO_FLAGS
)
1427 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1428 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1431 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1432 as_warn (_("error setting flags for \"%s\": %s"),
1433 bfd_section_name (stdoutput
, sec
),
1434 bfd_errmsg (bfd_get_error ()));
1437 demand_empty_rest_of_line ();
1441 coff_adjust_symtab ()
1443 if (symbol_rootP
== NULL
1444 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1445 c_dot_file_symbol ("fake");
1449 coff_frob_section (sec
)
1455 bfd_vma size
, n_entries
, mask
;
1456 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1458 /* The COFF back end in BFD requires that all section sizes be
1459 rounded up to multiples of the corresponding section alignments,
1460 supposedly because standard COFF has no other way of encoding alignment
1461 for sections. If your COFF flavor has a different way of encoding
1462 section alignment, then skip this step, as TICOFF does. */
1463 size
= bfd_get_section_size_before_reloc (sec
);
1464 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1465 #if !defined(TICOFF)
1468 size
= (size
+ mask
) & ~mask
;
1469 bfd_set_section_size (stdoutput
, sec
, size
);
1473 /* If the section size is non-zero, the section symbol needs an aux
1474 entry associated with it, indicating the size. We don't know
1475 all the values yet; coff_frob_symbol will fill them in later. */
1478 || sec
== text_section
1479 || sec
== data_section
1480 || sec
== bss_section
)
1483 symbolS
*secsym
= section_symbol (sec
);
1485 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1486 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1487 SF_SET_STATICS (secsym
);
1488 SA_SET_SCN_SCNLEN (secsym
, size
);
1491 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1492 #ifndef STAB_SECTION_NAME
1493 #define STAB_SECTION_NAME ".stab"
1495 #ifndef STAB_STRING_SECTION_NAME
1496 #define STAB_STRING_SECTION_NAME ".stabstr"
1498 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1502 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1503 /* size is already rounded up, since other section will be listed first */
1504 size
= bfd_get_section_size_before_reloc (strsec
);
1506 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1508 /* Find first non-empty frag. It should be large enough. */
1509 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1510 while (fragp
&& fragp
->fr_fix
== 0)
1511 fragp
= fragp
->fr_next
;
1512 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1514 /* Store the values. */
1515 p
= fragp
->fr_literal
;
1516 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1517 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1521 obj_coff_init_stab_section (seg
)
1527 unsigned int stroff
;
1529 /* Make space for this first symbol. */
1533 as_where (&file
, (unsigned int *) NULL
);
1534 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1535 strcpy (stabstr_name
, seg
->name
);
1536 strcat (stabstr_name
, "str");
1537 stroff
= get_stab_string_offset (file
, stabstr_name
);
1539 md_number_to_chars (p
, stroff
, 4);
1548 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1556 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1558 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1559 (unsigned long) symbolP
,
1560 S_GET_NAME(symbolP
),
1561 (long) S_GET_DATA_TYPE(symbolP
),
1562 S_GET_STORAGE_CLASS(symbolP
),
1563 (int) S_GET_SEGMENT(symbolP
));
1569 #else /* not BFD_ASSEMBLER */
1572 /* This is needed because we include internal bfd things. */
1576 #include "libcoff.h"
1579 #include "coff/pe.h"
1582 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1583 that we can stick sections together without causing trouble. */
1585 #define NOP_OPCODE 0x00
1588 /* The zeroes if symbol name is longer than 8 chars */
1589 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1591 #define MIN(a,b) ((a) < (b)? (a) : (b))
1593 /* This vector is used to turn a gas internal segment number into a
1594 section number suitable for insertion into a coff symbol table.
1595 This must correspond to seg_info_off_by_4. */
1597 const short seg_N_TYPE
[] =
1598 { /* in: segT out: N_TYPE bits */
1600 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1601 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1602 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1603 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1604 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1605 C_UNDEF_SECTION
, /* SEG_GOOF */
1606 C_UNDEF_SECTION
, /* SEG_EXPR */
1607 C_DEBUG_SECTION
, /* SEG_DEBUG */
1608 C_NTV_SECTION
, /* SEG_NTV */
1609 C_PTV_SECTION
, /* SEG_PTV */
1610 C_REGISTER_SECTION
, /* SEG_REGISTER */
1613 int function_lineoff
= -1; /* Offset in line#s where the last function
1614 started (the odd entry for line #0) */
1616 /* structure used to keep the filenames which
1617 are too long around so that we can stick them
1618 into the string table */
1619 struct filename_list
1622 struct filename_list
*next
;
1625 static struct filename_list
*filename_list_head
;
1626 static struct filename_list
*filename_list_tail
;
1628 static symbolS
*last_line_symbol
;
1630 /* Add 4 to the real value to get the index and compensate the
1631 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1632 section number into a segment number
1634 static symbolS
*previous_file_symbol
;
1635 void c_symbol_merge ();
1636 static int line_base
;
1638 symbolS
*c_section_symbol ();
1641 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1642 segT this_segment_type
));
1645 static void fixup_mdeps
PARAMS ((fragS
*,
1650 static void fill_section
PARAMS ((bfd
* abfd
,
1655 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1660 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1661 symbolS
* symbol_rootP
));
1663 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1665 static void obj_coff_lcomm
PARAMS ((int));
1666 static void obj_coff_text
PARAMS ((int));
1667 static void obj_coff_data
PARAMS ((int));
1668 void obj_coff_section
PARAMS ((int));
1670 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1672 This array maps a COFF section number into a gas section number.
1673 Because COFF uses negative section numbers, you must add 4 to the
1674 COFF section number when indexing into this array; this is done via
1675 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1678 static const segT seg_info_off_by_4
[] =
1685 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1686 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1687 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1688 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1689 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1690 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1691 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1692 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1705 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1707 static relax_addressT
1708 relax_align (address
, alignment
)
1709 relax_addressT address
;
1712 relax_addressT mask
;
1713 relax_addressT new_address
;
1715 mask
= ~((~0) << alignment
);
1716 new_address
= (address
+ mask
) & (~mask
);
1717 return (new_address
- address
);
1725 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1728 /* calculate the size of the frag chain and fill in the section header
1729 to contain all of it, also fill in the addr of the sections */
1731 size_section (abfd
, idx
)
1732 bfd
*abfd ATTRIBUTE_UNUSED
;
1736 unsigned int size
= 0;
1737 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1740 size
= frag
->fr_address
;
1741 if (frag
->fr_address
!= size
)
1743 fprintf (stderr
, _("Out of step\n"));
1744 size
= frag
->fr_address
;
1747 switch (frag
->fr_type
)
1749 #ifdef TC_COFF_SIZEMACHDEP
1750 case rs_machine_dependent
:
1751 size
+= TC_COFF_SIZEMACHDEP (frag
);
1755 assert (frag
->fr_symbol
== 0);
1758 size
+= frag
->fr_fix
;
1759 size
+= frag
->fr_offset
* frag
->fr_var
;
1766 size
+= frag
->fr_fix
;
1767 off
= relax_align (size
, frag
->fr_offset
);
1768 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1774 BAD_CASE (frag
->fr_type
);
1777 frag
= frag
->fr_next
;
1779 segment_info
[idx
].scnhdr
.s_size
= size
;
1785 count_entries_in_chain (idx
)
1788 unsigned int nrelocs
;
1791 /* Count the relocations */
1792 fixup_ptr
= segment_info
[idx
].fix_root
;
1794 while (fixup_ptr
!= (fixS
*) NULL
)
1796 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1799 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1808 fixup_ptr
= fixup_ptr
->fx_next
;
1815 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1817 /* AUX's ld expects relocations to be sorted */
1819 compare_external_relocs (x
, y
)
1823 struct external_reloc
*a
= (struct external_reloc
*) x
;
1824 struct external_reloc
*b
= (struct external_reloc
*) y
;
1825 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1826 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1827 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1832 /* output all the relocations for a section */
1834 do_relocs_for (abfd
, h
, file_cursor
)
1837 unsigned long *file_cursor
;
1839 unsigned int nrelocs
;
1841 unsigned long reloc_start
= *file_cursor
;
1843 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1845 if (segment_info
[idx
].scnhdr
.s_name
[0])
1847 struct external_reloc
*ext_ptr
;
1848 struct external_reloc
*external_reloc_vec
;
1849 unsigned int external_reloc_size
;
1850 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1851 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1852 nrelocs
= count_entries_in_chain (idx
);
1855 /* Bypass this stuff if no relocs. This also incidentally
1856 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1858 external_reloc_size
= nrelocs
* RELSZ
;
1859 external_reloc_vec
=
1860 (struct external_reloc
*) malloc (external_reloc_size
);
1862 ext_ptr
= external_reloc_vec
;
1864 /* Fill in the internal coff style reloc struct from the
1865 internal fix list. */
1868 struct internal_reloc intr
;
1870 /* Only output some of the relocations */
1871 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1873 #ifdef TC_RELOC_MANGLE
1874 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1879 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1881 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1883 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1885 #ifdef TC_KEEP_FX_OFFSET
1886 intr
.r_offset
= fix_ptr
->fx_offset
;
1891 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1892 && (! S_IS_DEFINED (symbol_ptr
)
1893 || S_IS_COMMON (symbol_ptr
)))
1897 /* We must avoid looping, as that can occur
1898 with a badly written program. */
1899 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1900 if (n
== symbol_ptr
)
1905 /* Turn the segment of the symbol into an offset. */
1908 resolve_symbol_value (symbol_ptr
, 1);
1909 if (! symbol_ptr
->sy_resolved
)
1914 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1915 as_bad_where (file
, line
,
1916 _("unresolved relocation"));
1918 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1919 S_GET_NAME (symbol_ptr
));
1921 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1924 intr
.r_symndx
= dot
->sy_number
;
1928 intr
.r_symndx
= symbol_ptr
->sy_number
;
1938 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1941 #if defined(TC_A29K)
1943 /* The 29k has a special kludge for the high 16 bit
1944 reloc. Two relocations are emited, R_IHIHALF,
1945 and R_IHCONST. The second one doesn't contain a
1946 symbol, but uses the value for offset. */
1948 if (intr
.r_type
== R_IHIHALF
)
1950 /* now emit the second bit */
1951 intr
.r_type
= R_IHCONST
;
1952 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1953 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1959 fix_ptr
= fix_ptr
->fx_next
;
1963 /* Sort the reloc table */
1964 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1965 sizeof (struct external_reloc
), compare_external_relocs
);
1968 /* Write out the reloc table */
1969 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1971 free (external_reloc_vec
);
1973 /* Fill in section header info. */
1974 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1975 *file_cursor
+= external_reloc_size
;
1976 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1981 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1985 /* Set relocation_size field in file headers */
1986 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1990 /* run through a frag chain and write out the data to go with it, fill
1991 in the scnhdrs with the info on the file postions
1994 fill_section (abfd
, h
, file_cursor
)
1996 object_headers
*h ATTRIBUTE_UNUSED
;
1997 unsigned long *file_cursor
;
2001 unsigned int paddr
= 0;
2003 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2005 unsigned int offset
= 0;
2006 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2012 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2019 buffer
= xmalloc (s
->s_size
);
2020 s
->s_scnptr
= *file_cursor
;
2022 know (s
->s_paddr
== paddr
);
2024 if (strcmp (s
->s_name
, ".text") == 0)
2025 s
->s_flags
|= STYP_TEXT
;
2026 else if (strcmp (s
->s_name
, ".data") == 0)
2027 s
->s_flags
|= STYP_DATA
;
2028 else if (strcmp (s
->s_name
, ".bss") == 0)
2031 s
->s_flags
|= STYP_BSS
;
2033 /* @@ Should make the i386 and a29k coff targets define
2034 COFF_NOLOAD_PROBLEM, and have only one test here. */
2037 #ifndef COFF_NOLOAD_PROBLEM
2038 /* Apparently the SVR3 linker (and exec syscall) and UDI
2039 mondfe progrem are confused by noload sections. */
2040 s
->s_flags
|= STYP_NOLOAD
;
2045 else if (strcmp (s
->s_name
, ".lit") == 0)
2046 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2047 else if (strcmp (s
->s_name
, ".init") == 0)
2048 s
->s_flags
|= STYP_TEXT
;
2049 else if (strcmp (s
->s_name
, ".fini") == 0)
2050 s
->s_flags
|= STYP_TEXT
;
2051 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2052 s
->s_flags
|= STYP_INFO
;
2056 unsigned int fill_size
;
2057 switch (frag
->fr_type
)
2059 case rs_machine_dependent
:
2062 memcpy (buffer
+ frag
->fr_address
,
2064 (unsigned int) frag
->fr_fix
);
2065 offset
+= frag
->fr_fix
;
2070 assert (frag
->fr_symbol
== 0);
2077 memcpy (buffer
+ frag
->fr_address
,
2079 (unsigned int) frag
->fr_fix
);
2080 offset
+= frag
->fr_fix
;
2083 fill_size
= frag
->fr_var
;
2084 if (fill_size
&& frag
->fr_offset
> 0)
2087 unsigned int off
= frag
->fr_fix
;
2088 for (count
= frag
->fr_offset
; count
; count
--)
2090 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2092 memcpy (buffer
+ frag
->fr_address
+ off
,
2093 frag
->fr_literal
+ frag
->fr_fix
,
2096 offset
+= fill_size
;
2101 case rs_broken_word
:
2106 frag
= frag
->fr_next
;
2111 if (s
->s_scnptr
!= 0)
2113 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2114 *file_cursor
+= s
->s_size
;
2123 /* Coff file generation & utilities */
2126 coff_header_append (abfd
, h
)
2133 #ifdef COFF_LONG_SECTION_NAMES
2134 unsigned long string_size
= 4;
2137 bfd_seek (abfd
, 0, 0);
2139 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2140 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2141 H_SET_VERSION_STAMP (h
, 0);
2142 H_SET_ENTRY_POINT (h
, 0);
2143 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2144 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2145 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2147 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2148 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2149 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2151 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2153 bfd_write (buffer
, i
, 1, abfd
);
2154 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2156 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2158 if (segment_info
[i
].scnhdr
.s_name
[0])
2162 #ifdef COFF_LONG_SECTION_NAMES
2163 /* Support long section names as found in PE. This code
2164 must coordinate with that in write_object_file and
2166 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2168 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2169 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2170 string_size
+= strlen (segment_info
[i
].name
) + 1;
2174 size
= bfd_coff_swap_scnhdr_out (abfd
,
2175 &(segment_info
[i
].scnhdr
),
2178 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2179 bfd_write (buffer
, size
, 1, abfd
);
2186 symbol_to_chars (abfd
, where
, symbolP
)
2191 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2195 /* Turn any symbols with register attributes into abs symbols */
2196 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2198 S_SET_SEGMENT (symbolP
, absolute_section
);
2200 /* At the same time, relocate all symbols to their output value */
2203 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2204 + S_GET_VALUE (symbolP
));
2206 val
= S_GET_VALUE (symbolP
);
2209 S_SET_VALUE (symbolP
, val
);
2211 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2213 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2216 for (i
= 0; i
< numaux
; i
++)
2218 where
+= bfd_coff_swap_aux_out (abfd
,
2219 &symbolP
->sy_symbol
.ost_auxent
[i
],
2220 S_GET_DATA_TYPE (symbolP
),
2221 S_GET_STORAGE_CLASS (symbolP
),
2229 coff_obj_symbol_new_hook (symbolP
)
2232 char underscore
= 0; /* Symbol has leading _ */
2234 /* Effective symbol */
2235 /* Store the pointer in the offset. */
2236 S_SET_ZEROES (symbolP
, 0L);
2237 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2238 S_SET_STORAGE_CLASS (symbolP
, 0);
2239 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2240 /* Additional information */
2241 symbolP
->sy_symbol
.ost_flags
= 0;
2242 /* Auxiliary entries */
2243 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2245 if (S_IS_STRING (symbolP
))
2246 SF_SET_STRING (symbolP
);
2247 if (!underscore
&& S_IS_LOCAL (symbolP
))
2248 SF_SET_LOCAL (symbolP
);
2252 * Handle .ln directives.
2256 obj_coff_ln (appline
)
2261 if (! appline
&& def_symbol_in_progress
!= NULL
)
2263 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2264 demand_empty_rest_of_line ();
2266 } /* wrong context */
2268 l
= get_absolute_expression ();
2269 c_line_new (0, frag_now_fix (), l
, frag_now
);
2272 new_logical_line ((char *) NULL
, l
- 1);
2282 listing_source_line ((unsigned int) l
);
2287 demand_empty_rest_of_line ();
2293 * Handle .def directives.
2295 * One might ask : why can't we symbol_new if the symbol does not
2296 * already exist and fill it with debug information. Because of
2297 * the C_EFCN special symbol. It would clobber the value of the
2298 * function symbol before we have a chance to notice that it is
2299 * a C_EFCN. And a second reason is that the code is more clear this
2300 * way. (at least I think it is :-).
2304 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2305 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2306 *input_line_pointer == '\t') \
2307 input_line_pointer++;
2311 int what ATTRIBUTE_UNUSED
;
2313 char name_end
; /* Char after the end of name */
2314 char *symbol_name
; /* Name of the debug symbol */
2315 char *symbol_name_copy
; /* Temporary copy of the name */
2316 unsigned int symbol_name_length
;
2318 if (def_symbol_in_progress
!= NULL
)
2320 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2321 demand_empty_rest_of_line ();
2323 } /* if not inside .def/.endef */
2325 SKIP_WHITESPACES ();
2327 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2328 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2330 symbol_name
= input_line_pointer
;
2331 name_end
= get_symbol_end ();
2332 symbol_name_length
= strlen (symbol_name
);
2333 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2334 strcpy (symbol_name_copy
, symbol_name
);
2335 #ifdef tc_canonicalize_symbol_name
2336 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2339 /* Initialize the new symbol */
2340 #ifdef STRIP_UNDERSCORE
2341 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2342 ? symbol_name_copy
+ 1
2343 : symbol_name_copy
));
2344 #else /* STRIP_UNDERSCORE */
2345 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2346 #endif /* STRIP_UNDERSCORE */
2347 /* free(symbol_name_copy); */
2348 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2349 def_symbol_in_progress
->sy_number
= ~0;
2350 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2351 S_SET_VALUE (def_symbol_in_progress
, 0);
2353 if (S_IS_STRING (def_symbol_in_progress
))
2354 SF_SET_STRING (def_symbol_in_progress
);
2356 *input_line_pointer
= name_end
;
2358 demand_empty_rest_of_line ();
2361 unsigned int dim_index
;
2365 obj_coff_endef (ignore
)
2366 int ignore ATTRIBUTE_UNUSED
;
2368 symbolS
*symbolP
= 0;
2369 /* DIM BUG FIX sac@cygnus.com */
2371 if (def_symbol_in_progress
== NULL
)
2373 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2374 demand_empty_rest_of_line ();
2376 } /* if not inside .def/.endef */
2378 /* Set the section number according to storage class. */
2379 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2384 SF_SET_TAG (def_symbol_in_progress
);
2385 /* intentional fallthrough */
2388 SF_SET_DEBUG (def_symbol_in_progress
);
2389 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2393 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2394 /* intentional fallthrough */
2396 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2397 /* intentional fallthrough */
2399 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2401 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2403 if (function_lineoff
< 0)
2405 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2406 } /* missing function symbol */
2407 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2409 SF_SET_PROCESS (last_line_symbol
);
2410 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2411 SF_SET_PROCESS (def_symbol_in_progress
);
2412 function_lineoff
= -1;
2414 /* Value is always set to . */
2415 def_symbol_in_progress
->sy_frag
= frag_now
;
2416 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2421 #endif /* C_AUTOARG */
2431 SF_SET_DEBUG (def_symbol_in_progress
);
2432 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2442 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2448 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2450 } /* switch on storage class */
2452 /* Now that we have built a debug symbol, try to find if we should
2453 merge with an existing symbol or not. If a symbol is C_EFCN or
2454 absolute_section or untagged SEG_DEBUG it never merges. We also
2455 don't merge labels, which are in a different namespace, nor
2456 symbols which have not yet been defined since they are typically
2457 unique, nor do we merge tags with non-tags. */
2459 /* Two cases for functions. Either debug followed by definition or
2460 definition followed by debug. For definition first, we will
2461 merge the debug symbol into the definition. For debug first, the
2462 lineno entry MUST point to the definition function or else it
2463 will point off into space when crawl_symbols() merges the debug
2464 symbol into the real symbol. Therefor, let's presume the debug
2465 symbol is a real function reference. */
2467 /* FIXME-SOON If for some reason the definition label/symbol is
2468 never seen, this will probably leave an undefined symbol at link
2471 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2472 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2473 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2474 && !SF_GET_TAG (def_symbol_in_progress
))
2475 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2476 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2477 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2478 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2480 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2485 /* This symbol already exists, merge the newly created symbol
2486 into the old one. This is not mandatory. The linker can
2487 handle duplicate symbols correctly. But I guess that it save
2488 a *lot* of space if the assembly file defines a lot of
2491 /* The debug entry (def_symbol_in_progress) is merged into the
2492 previous definition. */
2494 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2495 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2496 def_symbol_in_progress
= symbolP
;
2498 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2499 || SF_GET_TAG (def_symbol_in_progress
)
2500 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2502 /* For functions, and tags, and static symbols, the symbol
2503 *must* be where the debug symbol appears. Move the
2504 existing symbol to the current place. */
2505 /* If it already is at the end of the symbol list, do nothing */
2506 if (def_symbol_in_progress
!= symbol_lastP
)
2508 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2510 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2511 &symbol_rootP
, &symbol_lastP
);
2512 } /* if not already in place */
2514 } /* normal or mergable */
2516 if (SF_GET_TAG (def_symbol_in_progress
))
2520 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2522 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2523 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2524 def_symbol_in_progress
);
2527 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2529 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2531 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2533 SF_SET_PROCESS (def_symbol_in_progress
);
2535 if (symbolP
== NULL
)
2537 /* That is, if this is the first time we've seen the
2539 symbol_table_insert (def_symbol_in_progress
);
2540 } /* definition follows debug */
2541 } /* Create the line number entry pointing to the function being defined */
2543 def_symbol_in_progress
= NULL
;
2544 demand_empty_rest_of_line ();
2548 obj_coff_dim (ignore
)
2549 int ignore ATTRIBUTE_UNUSED
;
2553 if (def_symbol_in_progress
== NULL
)
2555 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2556 demand_empty_rest_of_line ();
2558 } /* if not inside .def/.endef */
2560 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2562 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2564 SKIP_WHITESPACES ();
2565 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2566 get_absolute_expression ());
2568 switch (*input_line_pointer
)
2571 input_line_pointer
++;
2575 as_warn (_("badly formed .dim directive ignored"));
2576 /* intentional fallthrough */
2584 demand_empty_rest_of_line ();
2588 obj_coff_line (ignore
)
2589 int ignore ATTRIBUTE_UNUSED
;
2594 if (def_symbol_in_progress
== NULL
)
2600 name
= S_GET_NAME (def_symbol_in_progress
);
2601 this_base
= get_absolute_expression ();
2603 /* Only .bf symbols indicate the use of a new base line number; the
2604 line numbers associated with .ef, .bb, .eb are relative to the
2605 start of the containing function. */
2606 if (!strcmp (".bf", name
))
2608 #if 0 /* XXX Can we ever have line numbers going backwards? */
2609 if (this_base
> line_base
)
2612 line_base
= this_base
;
2620 listing_source_line ((unsigned int) line_base
);
2626 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2627 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2629 demand_empty_rest_of_line ();
2633 obj_coff_size (ignore
)
2634 int ignore ATTRIBUTE_UNUSED
;
2636 if (def_symbol_in_progress
== NULL
)
2638 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2639 demand_empty_rest_of_line ();
2641 } /* if not inside .def/.endef */
2643 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2644 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2645 demand_empty_rest_of_line ();
2649 obj_coff_scl (ignore
)
2650 int ignore ATTRIBUTE_UNUSED
;
2652 if (def_symbol_in_progress
== NULL
)
2654 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2655 demand_empty_rest_of_line ();
2657 } /* if not inside .def/.endef */
2659 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2660 demand_empty_rest_of_line ();
2664 obj_coff_tag (ignore
)
2665 int ignore ATTRIBUTE_UNUSED
;
2670 if (def_symbol_in_progress
== NULL
)
2672 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2673 demand_empty_rest_of_line ();
2677 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2678 symbol_name
= input_line_pointer
;
2679 name_end
= get_symbol_end ();
2680 #ifdef tc_canonicalize_symbol_name
2681 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2684 /* Assume that the symbol referred to by .tag is always defined.
2685 This was a bad assumption. I've added find_or_make. xoxorich. */
2686 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2687 (long) tag_find_or_make (symbol_name
));
2688 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2690 as_warn (_("tag not found for .tag %s"), symbol_name
);
2693 SF_SET_TAGGED (def_symbol_in_progress
);
2694 *input_line_pointer
= name_end
;
2696 demand_empty_rest_of_line ();
2700 obj_coff_type (ignore
)
2701 int ignore ATTRIBUTE_UNUSED
;
2703 if (def_symbol_in_progress
== NULL
)
2705 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2706 demand_empty_rest_of_line ();
2708 } /* if not inside .def/.endef */
2710 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2712 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2713 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2715 SF_SET_FUNCTION (def_symbol_in_progress
);
2716 } /* is a function */
2718 demand_empty_rest_of_line ();
2722 obj_coff_val (ignore
)
2723 int ignore ATTRIBUTE_UNUSED
;
2725 if (def_symbol_in_progress
== NULL
)
2727 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2728 demand_empty_rest_of_line ();
2730 } /* if not inside .def/.endef */
2732 if (is_name_beginner (*input_line_pointer
))
2734 char *symbol_name
= input_line_pointer
;
2735 char name_end
= get_symbol_end ();
2737 #ifdef tc_canonicalize_symbol_name
2738 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2741 if (!strcmp (symbol_name
, "."))
2743 def_symbol_in_progress
->sy_frag
= frag_now
;
2744 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2745 /* If the .val is != from the .def (e.g. statics) */
2747 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2749 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2750 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2751 symbol_find_or_make (symbol_name
);
2752 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2753 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2755 /* If the segment is undefined when the forward reference is
2756 resolved, then copy the segment id from the forward
2758 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2760 /* FIXME: gcc can generate address expressions here in
2761 unusual cases (search for "obscure" in sdbout.c). We
2762 just ignore the offset here, thus generating incorrect
2763 debugging information. We ignore the rest of the line
2766 /* Otherwise, it is the name of a non debug symbol and
2767 its value will be calculated later. */
2768 *input_line_pointer
= name_end
;
2770 /* FIXME: this is to avoid an error message in the
2771 FIXME case mentioned just above. */
2772 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2773 ++input_line_pointer
;
2777 S_SET_VALUE (def_symbol_in_progress
,
2778 (valueT
) get_absolute_expression ());
2779 } /* if symbol based */
2781 demand_empty_rest_of_line ();
2786 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2787 read.c, which then calls this object file format specific routine. */
2790 obj_coff_pe_handle_link_once (type
)
2791 enum linkonce_type type
;
2793 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2795 /* We store the type in the seg_info structure, and use it to set up
2796 the auxiliary entry for the section symbol in c_section_symbol. */
2797 seg_info (now_seg
)->linkonce
= type
;
2803 coff_obj_read_begin_hook ()
2805 /* These had better be the same. Usually 18 bytes. */
2807 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2808 know (SYMESZ
== AUXESZ
);
2813 /* This function runs through the symbol table and puts all the
2814 externals onto another chain */
2816 /* The chain of globals. */
2817 symbolS
*symbol_globalP
;
2818 symbolS
*symbol_global_lastP
;
2820 /* The chain of externals */
2821 symbolS
*symbol_externP
;
2822 symbolS
*symbol_extern_lastP
;
2825 symbolS
*last_functionP
;
2826 static symbolS
*last_bfP
;
2833 unsigned int symbol_number
= 0;
2834 unsigned int last_file_symno
= 0;
2836 struct filename_list
*filename_list_scan
= filename_list_head
;
2838 for (symbolP
= symbol_rootP
;
2840 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2842 if (symbolP
->sy_mri_common
)
2844 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2846 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2848 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2849 as_bad (_("%s: global symbols not supported in common sections"),
2850 S_GET_NAME (symbolP
));
2851 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2855 if (!SF_GET_DEBUG (symbolP
))
2857 /* Debug symbols do not need all this rubbish */
2858 symbolS
*real_symbolP
;
2860 /* L* and C_EFCN symbols never merge. */
2861 if (!SF_GET_LOCAL (symbolP
)
2862 && !SF_GET_STATICS (symbolP
)
2863 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2864 && symbolP
->sy_value
.X_op
== O_constant
2865 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2866 && real_symbolP
!= symbolP
)
2868 /* FIXME-SOON: where do dups come from?
2869 Maybe tag references before definitions? xoxorich. */
2870 /* Move the debug data from the debug symbol to the
2871 real symbol. Do NOT do the oposite (i.e. move from
2872 real symbol to debug symbol and remove real symbol from the
2873 list.) Because some pointers refer to the real symbol
2874 whereas no pointers refer to the debug symbol. */
2875 c_symbol_merge (symbolP
, real_symbolP
);
2876 /* Replace the current symbol by the real one */
2877 /* The symbols will never be the last or the first
2878 because : 1st symbol is .file and 3 last symbols are
2879 .text, .data, .bss */
2880 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2881 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2882 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2883 symbolP
= real_symbolP
;
2884 } /* if not local but dup'd */
2886 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2888 S_SET_SEGMENT (symbolP
, SEG_E0
);
2889 } /* push data into text */
2891 resolve_symbol_value (symbolP
, 1);
2893 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2895 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2897 S_SET_EXTERNAL (symbolP
);
2899 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2901 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2905 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2909 /* Mainly to speed up if not -g */
2910 if (SF_GET_PROCESS (symbolP
))
2912 /* Handle the nested blocks auxiliary info. */
2913 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2915 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2916 stack_push (block_stack
, (char *) &symbolP
);
2919 register symbolS
*begin_symbolP
;
2920 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2921 if (begin_symbolP
== (symbolS
*) 0)
2922 as_warn (_("mismatched .eb"));
2924 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2927 /* If we are able to identify the type of a function, and we
2928 are out of a function (last_functionP == 0) then, the
2929 function symbol will be associated with an auxiliary
2931 if (last_functionP
== (symbolS
*) 0 &&
2932 SF_GET_FUNCTION (symbolP
))
2934 last_functionP
= symbolP
;
2936 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2938 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2939 } /* make it at least 1 */
2941 /* Clobber possible stale .dim information. */
2943 /* Iffed out by steve - this fries the lnnoptr info too */
2944 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2945 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2948 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2950 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2952 if (last_bfP
!= NULL
)
2953 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2957 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2959 /* I don't even know if this is needed for sdb. But
2960 the standard assembler generates it, so... */
2961 if (last_functionP
== (symbolS
*) 0)
2962 as_fatal (_("C_EFCN symbol out of scope"));
2963 SA_SET_SYM_FSIZE (last_functionP
,
2964 (long) (S_GET_VALUE (symbolP
) -
2965 S_GET_VALUE (last_functionP
)));
2966 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2967 last_functionP
= (symbolS
*) 0;
2971 else if (SF_GET_TAG (symbolP
))
2973 /* First descriptor of a structure must point to
2974 the first slot after the structure description. */
2975 last_tagP
= symbolP
;
2978 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2980 /* +2 take in account the current symbol */
2981 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2983 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2985 /* If the filename was too long to fit in the
2986 auxent, put it in the string table */
2987 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2988 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2990 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2991 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2992 filename_list_scan
= filename_list_scan
->next
;
2994 if (S_GET_VALUE (symbolP
))
2996 S_SET_VALUE (symbolP
, last_file_symno
);
2997 last_file_symno
= symbol_number
;
2998 } /* no one points at the first .file symbol */
2999 } /* if debug or tag or eos or file */
3001 #ifdef tc_frob_coff_symbol
3002 tc_frob_coff_symbol (symbolP
);
3005 /* We must put the external symbols apart. The loader
3006 does not bomb if we do not. But the references in
3007 the endndx field for a .bb symbol are not corrected
3008 if an external symbol is removed between .bb and .be.
3009 I.e in the following case :
3010 [20] .bb endndx = 22
3013 ld will move the symbol 21 to the end of the list but
3014 endndx will still be 22 instead of 21. */
3017 if (SF_GET_LOCAL (symbolP
))
3019 /* remove C_EFCN and LOCAL (L...) symbols */
3020 /* next pointer remains valid */
3021 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3024 else if (symbolP
->sy_value
.X_op
== O_symbol
3025 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3027 /* Skip symbols which were equated to undefined or common
3029 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3031 else if (!S_IS_DEFINED (symbolP
)
3032 && !S_IS_DEBUG (symbolP
)
3033 && !SF_GET_STATICS (symbolP
)
3034 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3036 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3038 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3040 /* if external, Remove from the list */
3041 symbolS
*hold
= symbol_previous (symbolP
);
3043 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3044 symbol_clear_list_pointers (symbolP
);
3045 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3048 else if (! S_IS_DEBUG (symbolP
)
3049 && ! SF_GET_STATICS (symbolP
)
3050 && ! SF_GET_FUNCTION (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_NT_WEAK
))
3057 symbolS
*hold
= symbol_previous (symbolP
);
3059 /* The O'Reilly COFF book says that defined global symbols
3060 come at the end of the symbol table, just before
3061 undefined global symbols. */
3063 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3064 symbol_clear_list_pointers (symbolP
);
3065 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3066 &symbol_global_lastP
);
3071 if (SF_GET_STRING (symbolP
))
3073 symbolP
->sy_name_offset
= string_byte_count
;
3074 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3078 symbolP
->sy_name_offset
= 0;
3079 } /* fix "long" names */
3081 symbolP
->sy_number
= symbol_number
;
3082 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3083 } /* if local symbol */
3084 } /* traverse the symbol list */
3085 return symbol_number
;
3091 glue_symbols (head
, tail
)
3095 unsigned int symbol_number
= 0;
3097 while (*head
!= NULL
)
3099 symbolS
*tmp
= *head
;
3102 symbol_remove (tmp
, head
, tail
);
3103 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3106 if (SF_GET_STRING (tmp
))
3108 tmp
->sy_name_offset
= string_byte_count
;
3109 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3113 tmp
->sy_name_offset
= 0;
3114 } /* fix "long" names */
3116 tmp
->sy_number
= symbol_number
;
3117 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3118 } /* append the entire extern chain */
3120 return symbol_number
;
3126 unsigned int symbol_number
= 0;
3129 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3131 symbolP
->sy_number
= symbol_number
;
3133 if (SF_GET_TAGGED (symbolP
))
3137 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3140 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3143 return symbol_number
;
3147 crawl_symbols (h
, abfd
)
3149 bfd
*abfd ATTRIBUTE_UNUSED
;
3153 /* Initialize the stack used to keep track of the matching .bb .be */
3155 block_stack
= stack_init (512, sizeof (symbolS
*));
3157 /* The symbol list should be ordered according to the following sequence
3160 * . debug entries for functions
3161 * . fake symbols for the sections, including .text .data and .bss
3163 * . undefined symbols
3164 * But this is not mandatory. The only important point is to put the
3165 * undefined symbols at the end of the list.
3168 /* Is there a .file symbol ? If not insert one at the beginning. */
3169 if (symbol_rootP
== NULL
3170 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3172 c_dot_file_symbol ("fake");
3176 * Build up static symbols for the sections, they are filled in later
3180 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3181 if (segment_info
[i
].scnhdr
.s_name
[0])
3182 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3185 /* Take all the externals out and put them into another chain */
3186 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3187 /* Take the externals and glue them onto the end.*/
3188 H_SET_SYMBOL_TABLE_SIZE (h
,
3189 (H_GET_SYMBOL_COUNT (h
)
3190 + glue_symbols (&symbol_globalP
,
3191 &symbol_global_lastP
)
3192 + glue_symbols (&symbol_externP
,
3193 &symbol_extern_lastP
)));
3195 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3196 know (symbol_globalP
== NULL
);
3197 know (symbol_global_lastP
== NULL
);
3198 know (symbol_externP
== NULL
);
3199 know (symbol_extern_lastP
== NULL
);
3203 * Find strings by crawling along symbol table chain.
3211 struct filename_list
*filename_list_scan
= filename_list_head
;
3213 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3214 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3217 #ifdef COFF_LONG_SECTION_NAMES
3218 /* Support long section names as found in PE. This code must
3219 coordinate with that in coff_header_append and write_object_file. */
3223 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3225 if (segment_info
[i
].scnhdr
.s_name
[0]
3226 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3230 size
= strlen (segment_info
[i
].name
) + 1;
3231 memcpy (where
, segment_info
[i
].name
, size
);
3236 #endif /* COFF_LONG_SECTION_NAMES */
3238 for (symbolP
= symbol_rootP
;
3240 symbolP
= symbol_next (symbolP
))
3244 if (SF_GET_STRING (symbolP
))
3246 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3247 memcpy (where
, S_GET_NAME (symbolP
), size
);
3250 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3251 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3252 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3254 size
= strlen (filename_list_scan
->filename
) + 1;
3255 memcpy (where
, filename_list_scan
->filename
, size
);
3256 filename_list_scan
= filename_list_scan
->next
;
3263 do_linenos_for (abfd
, h
, file_cursor
)
3266 unsigned long *file_cursor
;
3269 unsigned long start
= *file_cursor
;
3271 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3273 segment_info_type
*s
= segment_info
+ idx
;
3276 if (s
->scnhdr
.s_nlnno
!= 0)
3278 struct lineno_list
*line_ptr
;
3280 struct external_lineno
*buffer
=
3281 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3283 struct external_lineno
*dst
= buffer
;
3285 /* Run through the table we've built and turn it into its external
3286 form, take this chance to remove duplicates */
3288 for (line_ptr
= s
->lineno_list_head
;
3289 line_ptr
!= (struct lineno_list
*) NULL
;
3290 line_ptr
= line_ptr
->next
)
3293 if (line_ptr
->line
.l_lnno
== 0)
3295 /* Turn a pointer to a symbol into the symbols' index */
3296 line_ptr
->line
.l_addr
.l_symndx
=
3297 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3301 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3305 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3310 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3312 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3315 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3318 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3322 /* Now we run through the list of frag chains in a segment and
3323 make all the subsegment frags appear at the end of the
3324 list, as if the seg 0 was extra long */
3331 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3333 frchainS
*head
= segment_info
[i
].frchainP
;
3335 fragS
*prev_frag
= &dummy
;
3337 while (head
&& head
->frch_seg
== i
)
3339 prev_frag
->fr_next
= head
->frch_root
;
3340 prev_frag
= head
->frch_last
;
3341 head
= head
->frch_next
;
3343 prev_frag
->fr_next
= 0;
3347 unsigned long machine
;
3350 write_object_file ()
3354 struct frchain
*frchain_ptr
;
3356 object_headers headers
;
3357 unsigned long file_cursor
;
3360 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3365 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3366 exit (EXIT_FAILURE
);
3368 bfd_set_format (abfd
, bfd_object
);
3369 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3371 string_byte_count
= 4;
3373 for (frchain_ptr
= frchain_root
;
3374 frchain_ptr
!= (struct frchain
*) NULL
;
3375 frchain_ptr
= frchain_ptr
->frch_next
)
3377 /* Run through all the sub-segments and align them up. Also
3378 close any open frags. We tack a .fill onto the end of the
3379 frag chain so that any .align's size can be worked by looking
3380 at the next frag. */
3382 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3384 #ifndef SUB_SEGMENT_ALIGN
3385 #define SUB_SEGMENT_ALIGN(SEG) 1
3388 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3391 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3392 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3397 frag_wane (frag_now
);
3398 frag_now
->fr_fix
= 0;
3399 know (frag_now
->fr_next
== NULL
);
3406 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3408 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3411 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3413 /* Find out how big the sections are, and set the addresses. */
3415 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3419 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3420 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3422 if (segment_info
[i
].scnhdr
.s_name
[0])
3424 H_SET_NUMBER_OF_SECTIONS (&headers
,
3425 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3427 #ifdef COFF_LONG_SECTION_NAMES
3428 /* Support long section names as found in PE. This code
3429 must coordinate with that in coff_header_append and
3434 len
= strlen (segment_info
[i
].name
);
3436 string_byte_count
+= len
+ 1;
3438 #endif /* COFF_LONG_SECTION_NAMES */
3441 size
= size_section (abfd
, (unsigned int) i
);
3444 /* I think the section alignment is only used on the i960; the
3445 i960 needs it, and it should do no harm on other targets. */
3446 #ifdef ALIGNMENT_IN_S_FLAGS
3447 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3449 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3453 H_SET_TEXT_SIZE (&headers
, size
);
3454 else if (i
== SEG_E1
)
3455 H_SET_DATA_SIZE (&headers
, size
);
3456 else if (i
== SEG_E2
)
3457 H_SET_BSS_SIZE (&headers
, size
);
3460 /* Turn the gas native symbol table shape into a coff symbol table */
3461 crawl_symbols (&headers
, abfd
);
3463 if (string_byte_count
== 4)
3464 string_byte_count
= 0;
3466 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3472 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3474 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3475 fixup_segment (&segment_info
[i
], i
);
3478 /* Look for ".stab" segments and fill in their initial symbols
3480 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3482 name
= segment_info
[i
].name
;
3485 && strncmp (".stab", name
, 5) == 0
3486 && strncmp (".stabstr", name
, 8) != 0)
3487 adjust_stab_section (abfd
, i
);
3490 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3492 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3494 /* Plant the data */
3496 fill_section (abfd
, &headers
, &file_cursor
);
3498 do_relocs_for (abfd
, &headers
, &file_cursor
);
3500 do_linenos_for (abfd
, &headers
, &file_cursor
);
3502 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3503 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3504 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3506 H_SET_TIME_STAMP (&headers
, 0);
3508 #ifdef TC_COFF_SET_MACHINE
3509 TC_COFF_SET_MACHINE (&headers
);
3513 #define COFF_FLAGS 0
3516 #ifdef KEEP_RELOC_INFO
3517 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3518 COFF_FLAGS
| coff_flags
));
3520 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3521 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3522 COFF_FLAGS
| coff_flags
));
3526 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3527 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3529 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3530 w_symbols (abfd
, buffer1
, symbol_rootP
);
3531 if (string_byte_count
> 0)
3532 w_strings (buffer1
+ symtable_size
);
3533 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3537 coff_header_append (abfd
, &headers
);
3539 /* Recent changes to write need this, but where it should
3540 go is up to Ken.. */
3541 if (bfd_close_all_done (abfd
) == false)
3542 as_fatal (_("Can't close %s: %s"), out_file_name
,
3543 bfd_errmsg (bfd_get_error ()));
3546 extern bfd
*stdoutput
;
3553 /* Add a new segment. This is called from subseg_new via the
3554 obj_new_segment macro. */
3557 obj_coff_add_segment (name
)
3562 #ifndef COFF_LONG_SECTION_NAMES
3563 char buf
[SCNNMLEN
+ 1];
3565 strncpy (buf
, name
, SCNNMLEN
);
3566 buf
[SCNNMLEN
] = '\0';
3570 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3571 if (strcmp (name
, segment_info
[i
].name
) == 0)
3576 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3580 /* Add a new section. */
3581 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3582 sizeof (segment_info
[i
].scnhdr
.s_name
));
3583 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3584 segment_info
[i
].name
= xstrdup (name
);
3590 * implement the .section pseudo op:
3591 * .section name {, "flags"}
3593 * | +--- optional flags: 'b' for bss
3595 * +-- section name 'l' for lib
3599 * 'd' (apparently m88k for data)
3601 * 'r' for read-only data
3602 * But if the argument is not a quoted string, treat it as a
3603 * subsegment number.
3607 obj_coff_section (ignore
)
3608 int ignore ATTRIBUTE_UNUSED
;
3610 /* Strip out the section name */
3611 char *section_name
, *name
;
3624 else if (type
== 'D')
3626 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3631 section_name
= input_line_pointer
;
3632 c
= get_symbol_end ();
3634 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3635 strcpy (name
, section_name
);
3637 *input_line_pointer
= c
;
3643 if (*input_line_pointer
== ',')
3645 ++input_line_pointer
;
3648 if (*input_line_pointer
!= '"')
3649 exp
= get_absolute_expression ();
3652 ++input_line_pointer
;
3653 while (*input_line_pointer
!= '"'
3654 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3656 switch (*input_line_pointer
)
3658 case 'b': flags
|= STYP_BSS
; break;
3659 case 'i': flags
|= STYP_INFO
; break;
3660 case 'l': flags
|= STYP_LIB
; break;
3661 case 'n': flags
|= STYP_NOLOAD
; break;
3662 case 'o': flags
|= STYP_OVER
; break;
3664 case 'w': flags
|= STYP_DATA
; break;
3665 case 'x': flags
|= STYP_TEXT
; break;
3666 case 'r': flags
|= STYP_LIT
; break;
3668 as_warn(_("unknown section attribute '%c'"),
3669 *input_line_pointer
);
3672 ++input_line_pointer
;
3674 if (*input_line_pointer
== '"')
3675 ++input_line_pointer
;
3679 subseg_new (name
, (subsegT
) exp
);
3681 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3683 demand_empty_rest_of_line ();
3688 obj_coff_text (ignore
)
3689 int ignore ATTRIBUTE_UNUSED
;
3691 subseg_new (".text", get_absolute_expression ());
3696 obj_coff_data (ignore
)
3697 int ignore ATTRIBUTE_UNUSED
;
3699 if (flag_readonly_data_in_text
)
3700 subseg_new (".text", get_absolute_expression () + 1000);
3702 subseg_new (".data", get_absolute_expression ());
3706 obj_coff_ident (ignore
)
3707 int ignore ATTRIBUTE_UNUSED
;
3709 segT current_seg
= now_seg
; /* save current seg */
3710 subsegT current_subseg
= now_subseg
;
3711 subseg_new (".comment", 0); /* .comment seg */
3712 stringer (1); /* read string */
3713 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3717 c_symbol_merge (debug
, normal
)
3721 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3722 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3724 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3726 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3727 } /* take the most we have */
3729 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3731 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3732 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3733 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3734 } /* Move all the auxiliary information */
3736 /* Move the debug flags. */
3737 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3738 } /* c_symbol_merge() */
3741 c_line_new (symbol
, paddr
, line_number
, frag
)
3747 struct lineno_list
*new_line
=
3748 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3750 segment_info_type
*s
= segment_info
+ now_seg
;
3751 new_line
->line
.l_lnno
= line_number
;
3753 if (line_number
== 0)
3755 last_line_symbol
= symbol
;
3756 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3760 new_line
->line
.l_addr
.l_paddr
= paddr
;
3763 new_line
->frag
= (char *) frag
;
3764 new_line
->next
= (struct lineno_list
*) NULL
;
3767 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3769 s
->lineno_list_head
= new_line
;
3773 s
->lineno_list_tail
->next
= new_line
;
3775 s
->lineno_list_tail
= new_line
;
3776 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3780 c_dot_file_symbol (filename
)
3785 symbolP
= symbol_new (".file",
3788 &zero_address_frag
);
3790 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3791 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3793 if (strlen (filename
) > FILNMLEN
)
3795 /* Filename is too long to fit into an auxent,
3796 we stick it into the string table instead. We keep
3797 a linked list of the filenames we find so we can emit
3799 struct filename_list
*f
= ((struct filename_list
*)
3800 xmalloc (sizeof (struct filename_list
)));
3802 f
->filename
= filename
;
3805 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3806 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3808 if (filename_list_tail
)
3809 filename_list_tail
->next
= f
;
3811 filename_list_head
= f
;
3812 filename_list_tail
= f
;
3816 SA_SET_FILE_FNAME (symbolP
, filename
);
3823 listing_source_file (filename
);
3829 SF_SET_DEBUG (symbolP
);
3830 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3832 previous_file_symbol
= symbolP
;
3834 /* Make sure that the symbol is first on the symbol chain */
3835 if (symbol_rootP
!= symbolP
)
3837 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3838 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3840 } /* c_dot_file_symbol() */
3843 * Build a 'section static' symbol.
3847 c_section_symbol (name
, idx
)
3853 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3854 if (symbolP
== NULL
)
3855 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3858 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3859 S_SET_SEGMENT (symbolP
, idx
);
3860 symbolP
->sy_frag
= &zero_address_frag
;
3863 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3864 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3866 SF_SET_STATICS (symbolP
);
3869 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3870 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3871 SF_CLEAR_LOCAL (symbolP
);
3874 /* If the .linkonce pseudo-op was used for this section, we must
3875 store the information in the auxiliary entry for the section
3877 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3881 switch (segment_info
[idx
].linkonce
)
3885 case LINKONCE_DISCARD
:
3886 type
= IMAGE_COMDAT_SELECT_ANY
;
3888 case LINKONCE_ONE_ONLY
:
3889 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3891 case LINKONCE_SAME_SIZE
:
3892 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3894 case LINKONCE_SAME_CONTENTS
:
3895 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3899 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3904 } /* c_section_symbol() */
3907 w_symbols (abfd
, where
, symbol_rootP
)
3910 symbolS
* symbol_rootP
;
3915 /* First fill in those values we have only just worked out */
3916 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3918 symbolP
= segment_info
[i
].dot
;
3921 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3922 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3923 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3928 * Emit all symbols left in the symbol chain.
3930 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3932 /* Used to save the offset of the name. It is used to point
3933 to the string in memory but must be a file offset. */
3934 register char *temp
;
3936 /* We can't fix the lnnoptr field in yank_symbols with the other
3937 adjustments, because we have to wait until we know where they
3939 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3941 SA_GET_SYM_LNNOPTR (symbolP
) +=
3942 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3945 tc_coff_symbol_emit_hook (symbolP
);
3947 temp
= S_GET_NAME (symbolP
);
3948 if (SF_GET_STRING (symbolP
))
3950 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3951 S_SET_ZEROES (symbolP
, 0);
3955 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3956 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3958 where
= symbol_to_chars (abfd
, where
, symbolP
);
3959 S_SET_NAME (symbolP
, temp
);
3965 obj_coff_lcomm (ignore
)
3966 int ignore ATTRIBUTE_UNUSED
;
3978 name
= input_line_pointer
;
3980 c
= get_symbol_end ();
3981 p
= input_line_pointer
;
3984 if (*input_line_pointer
!= ',')
3986 as_bad (_("Expected comma after name"));
3987 ignore_rest_of_line ();
3990 if (*input_line_pointer
== '\n')
3992 as_bad (_("Missing size expression"));
3995 input_line_pointer
++;
3996 if ((temp
= get_absolute_expression ()) < 0)
3998 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3999 ignore_rest_of_line ();
4004 symbolP
= symbol_find_or_make(name
);
4006 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
4007 S_GET_VALUE(symbolP
) == 0)
4012 segT current_seg
= now_seg
; /* save current seg */
4013 subsegT current_subseg
= now_subseg
;
4015 subseg_set (SEG_E2
, 1);
4016 symbolP
->sy_frag
= frag_now
;
4017 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4018 (offsetT
) temp
, (char *) 0);
4020 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4021 S_SET_SEGMENT(symbolP
, SEG_E2
);
4022 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
4026 as_bad(_("Symbol %s already defined"), name
);
4028 demand_empty_rest_of_line();
4033 fixup_mdeps (frags
, h
, this_segment
)
4038 subseg_change (this_segment
, 0);
4041 switch (frags
->fr_type
)
4047 HANDLE_ALIGN (frags
);
4049 frags
->fr_type
= rs_fill
;
4051 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4054 case rs_machine_dependent
:
4055 md_convert_frag (h
, this_segment
, frags
);
4061 frags
= frags
->fr_next
;
4067 #ifndef TC_FORCE_RELOCATION
4068 #define TC_FORCE_RELOCATION(fix) 0
4072 fixup_segment (segP
, this_segment_type
)
4073 segment_info_type
* segP
;
4074 segT this_segment_type
;
4076 register fixS
* fixP
;
4077 register symbolS
*add_symbolP
;
4078 register symbolS
*sub_symbolP
;
4081 register char *place
;
4082 register long where
;
4083 register char pcrel
;
4084 register fragS
*fragP
;
4085 register segT add_symbol_segment
= absolute_section
;
4087 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4089 fragP
= fixP
->fx_frag
;
4091 where
= fixP
->fx_where
;
4092 place
= fragP
->fr_literal
+ where
;
4093 size
= fixP
->fx_size
;
4094 add_symbolP
= fixP
->fx_addsy
;
4095 sub_symbolP
= fixP
->fx_subsy
;
4096 add_number
= fixP
->fx_offset
;
4097 pcrel
= fixP
->fx_pcrel
;
4099 /* We want function-relative stabs to work on systems which
4100 may use a relaxing linker; thus we must handle the sym1-sym2
4101 fixups function-relative stabs generates.
4103 Of course, if you actually enable relaxing in the linker, the
4104 line and block scoping information is going to be incorrect
4105 in some cases. The only way to really fix this is to support
4106 a reloc involving the difference of two symbols. */
4108 && (!sub_symbolP
|| pcrel
))
4112 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4114 /* Relocation should be done via the associated 'bal' entry
4117 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4119 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4120 _("No 'bal' entry point for leafproc %s"),
4121 S_GET_NAME (add_symbolP
));
4124 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4128 /* Make sure the symbols have been resolved; this may not have
4129 happened if these are expression symbols. */
4130 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4131 resolve_symbol_value (add_symbolP
, 1);
4133 if (add_symbolP
!= NULL
)
4135 /* If this fixup is against a symbol which has been equated
4136 to another symbol, convert it to the other symbol. */
4137 if (add_symbolP
->sy_value
.X_op
== O_symbol
4138 && (! S_IS_DEFINED (add_symbolP
)
4139 || S_IS_COMMON (add_symbolP
)))
4141 while (add_symbolP
->sy_value
.X_op
== O_symbol
4142 && (! S_IS_DEFINED (add_symbolP
)
4143 || S_IS_COMMON (add_symbolP
)))
4147 /* We must avoid looping, as that can occur with a
4148 badly written program. */
4149 n
= add_symbolP
->sy_value
.X_add_symbol
;
4150 if (n
== add_symbolP
)
4152 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4155 fixP
->fx_addsy
= add_symbolP
;
4156 fixP
->fx_offset
= add_number
;
4160 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4161 resolve_symbol_value (sub_symbolP
, 1);
4163 if (add_symbolP
!= NULL
4164 && add_symbolP
->sy_mri_common
)
4166 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4167 add_number
+= S_GET_VALUE (add_symbolP
);
4168 fixP
->fx_offset
= add_number
;
4169 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4174 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4175 } /* if there is an addend */
4179 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4181 if (add_symbolP
!= NULL
)
4183 add_number
+= S_GET_VALUE (add_symbolP
);
4185 fixP
->fx_addsy
= NULL
;
4188 /* It's just -sym. */
4189 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4191 add_number
-= S_GET_VALUE (sub_symbolP
);
4198 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4199 _("Negative of non-absolute symbol %s"),
4200 S_GET_NAME (sub_symbolP
));
4202 add_number
-= S_GET_VALUE (sub_symbolP
);
4203 } /* not absolute */
4205 /* if sub_symbol is in the same segment that add_symbol
4206 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4208 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4209 && SEG_NORMAL (add_symbol_segment
))
4211 /* Difference of 2 symbols from same segment. Can't
4212 make difference of 2 undefineds: 'value' means
4213 something different for N_UNDF. */
4215 /* Makes no sense to use the difference of 2 arbitrary symbols
4216 as the target of a call instruction. */
4219 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4220 _("callj to difference of 2 symbols"));
4222 #endif /* TC_I960 */
4223 add_number
+= S_GET_VALUE (add_symbolP
) -
4224 S_GET_VALUE (sub_symbolP
);
4227 if (!TC_FORCE_RELOCATION (fixP
))
4229 fixP
->fx_addsy
= NULL
;
4230 fixP
->fx_subsy
= NULL
;
4232 #ifdef TC_M68K /* is this right? */
4240 /* Different segments in subtraction. */
4241 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4243 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4245 add_number
-= S_GET_VALUE (sub_symbolP
);
4248 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4249 #if 0 /* Okay for 68k, at least... */
4254 /* Make it pc-relative. */
4255 add_number
+= (md_pcrel_from (fixP
)
4256 - S_GET_VALUE (sub_symbolP
));
4265 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4266 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4267 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4268 S_GET_NAME (sub_symbolP
),
4269 (long) (fragP
->fr_address
+ where
));
4272 } /* if sub_symbolP */
4276 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4279 * This fixup was made when the symbol's segment was
4280 * SEG_UNKNOWN, but it is now in the local segment.
4281 * So we know how to do the address without relocation.
4284 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4285 * in which cases it modifies *fixP as appropriate. In the case
4286 * of a 'calls', no further work is required, and *fixP has been
4287 * set up to make the rest of the code below a no-op.
4290 #endif /* TC_I960 */
4292 add_number
+= S_GET_VALUE (add_symbolP
);
4293 add_number
-= md_pcrel_from (fixP
);
4296 add_number -= segP->scnhdr.s_vaddr;
4297 if defined (TC_I386) || defined (TE_LYNX). I now
4298 think that was an error propagated from the case when
4299 we are going to emit the relocation. If we are not
4300 going to emit the relocation, then we just want to
4301 set add_number to the difference between the symbols.
4302 This is a case that would only arise when there is a
4303 PC relative reference from a section other than .text
4304 to a symbol defined in the same section, and the
4305 reference is not relaxed. Since jump instructions on
4306 the i386 are relaxed, this could only arise with a
4307 call instruction. */
4309 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4310 if (!TC_FORCE_RELOCATION (fixP
))
4312 fixP
->fx_addsy
= NULL
;
4318 switch (add_symbol_segment
)
4320 case absolute_section
:
4322 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4323 #endif /* TC_I960 */
4324 add_number
+= S_GET_VALUE (add_symbolP
);
4327 if (!TC_FORCE_RELOCATION (fixP
))
4329 fixP
->fx_addsy
= NULL
;
4336 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4337 /* This really should be handled in the linker, but
4338 backward compatibility forbids. */
4339 add_number
+= S_GET_VALUE (add_symbolP
);
4341 add_number
+= S_GET_VALUE (add_symbolP
) +
4342 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4348 if ((int) fixP
->fx_bit_fixP
== 13)
4350 /* This is a COBR instruction. They have only a
4351 * 13-bit displacement and are only to be used
4352 * for local branches: flag as error, don't generate
4355 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4356 _("can't use COBR format with external label"));
4357 fixP
->fx_addsy
= NULL
;
4361 #endif /* TC_I960 */
4362 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4363 /* 386 COFF uses a peculiar format in which the
4364 value of a common symbol is stored in the .text
4365 segment (I've checked this on SVR3.2 and SCO
4366 3.2.2) Ian Taylor <ian@cygnus.com>. */
4367 /* This is also true for 68k COFF on sysv machines
4368 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4369 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4370 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4371 if (S_IS_COMMON (add_symbolP
))
4372 add_number
+= S_GET_VALUE (add_symbolP
);
4377 } /* switch on symbol seg */
4378 } /* if not in local seg */
4379 } /* if there was a + symbol */
4383 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4384 /* This adjustment is not correct on the m88k, for which the
4385 linker does all the computation. */
4386 add_number
-= md_pcrel_from (fixP
);
4388 if (add_symbolP
== 0)
4390 fixP
->fx_addsy
= &abs_symbol
;
4391 } /* if there's an add_symbol */
4392 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4393 /* On the 386 we must adjust by the segment vaddr as well.
4396 I changed the i960 to work this way as well. This is
4397 compatible with the current GNU linker behaviour. I do
4398 not know what other i960 COFF assemblers do. This is not
4399 a common case: normally, only assembler code will contain
4400 a PC relative reloc, and only branches which do not
4401 originate in the .text section will have a non-zero
4404 I changed the m68k to work this way as well. This will
4405 break existing PC relative relocs from sections which do
4406 not start at address 0, but it will make ld -r work.
4407 Ian Taylor, 4 Oct 96. */
4409 add_number
-= segP
->scnhdr
.s_vaddr
;
4413 #ifdef MD_APPLY_FIX3
4414 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4416 md_apply_fix (fixP
, add_number
);
4419 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4422 /* The m88k uses the offset field of the reloc to get around
4425 && ((add_number
& ~0xFF)
4426 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4427 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4428 || (add_number
& 0x80) == 0))
4430 && ((add_number
& ~0xFFFF)
4431 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4432 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4433 || (add_number
& 0x8000) == 0)))
4435 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4436 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4437 (long) add_number
, size
,
4438 (unsigned long) (fragP
->fr_address
+ where
));
4441 #ifdef WARN_SIGNED_OVERFLOW_WORD
4442 /* Warn if a .word value is too large when treated as a
4443 signed number. We already know it is not too negative.
4444 This is to catch over-large switches generated by gcc on
4446 if (!flag_signed_overflow_ok
4448 && add_number
> 0x7fff)
4449 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4450 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4452 (unsigned long) (fragP
->fr_address
+ where
));
4454 } /* not a bit fix */
4455 } /* For each fixS in this segment. */
4456 } /* fixup_segment() */
4460 /* The first entry in a .stab section is special. */
4463 obj_coff_init_stab_section (seg
)
4469 unsigned int stroff
;
4471 /* Make space for this first symbol. */
4475 as_where (&file
, (unsigned int *) NULL
);
4476 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4477 strcpy (stabstr_name
, segment_info
[seg
].name
);
4478 strcat (stabstr_name
, "str");
4479 stroff
= get_stab_string_offset (file
, stabstr_name
);
4481 md_number_to_chars (p
, stroff
, 4);
4484 /* Fill in the counts in the first entry in a .stab section. */
4487 adjust_stab_section(abfd
, seg
)
4491 segT stabstrseg
= SEG_UNKNOWN
;
4492 const char *secname
, *name2
;
4495 int i
, strsz
= 0, nsyms
;
4496 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4498 /* Look for the associated string table section. */
4500 secname
= segment_info
[seg
].name
;
4501 name
= (char *) alloca (strlen (secname
) + 4);
4502 strcpy (name
, secname
);
4503 strcat (name
, "str");
4505 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4507 name2
= segment_info
[i
].name
;
4508 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4515 /* If we found the section, get its size. */
4516 if (stabstrseg
!= SEG_UNKNOWN
)
4517 strsz
= size_section (abfd
, stabstrseg
);
4519 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4521 /* Look for the first frag of sufficient size for the initial stab
4522 symbol, and collect a pointer to it. */
4523 while (frag
&& frag
->fr_fix
< 12)
4524 frag
= frag
->fr_next
;
4526 p
= frag
->fr_literal
;
4529 /* Write in the number of stab symbols and the size of the string
4531 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4532 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4535 #endif /* not BFD_ASSEMBLER */
4537 const pseudo_typeS coff_pseudo_table
[] =
4539 {"def", obj_coff_def
, 0},
4540 {"dim", obj_coff_dim
, 0},
4541 {"endef", obj_coff_endef
, 0},
4542 {"line", obj_coff_line
, 0},
4543 {"ln", obj_coff_ln
, 0},
4544 #ifdef BFD_ASSEMBLER
4545 {"loc", obj_coff_loc
, 0},
4547 {"appline", obj_coff_ln
, 1},
4548 {"scl", obj_coff_scl
, 0},
4549 {"size", obj_coff_size
, 0},
4550 {"tag", obj_coff_tag
, 0},
4551 {"type", obj_coff_type
, 0},
4552 {"val", obj_coff_val
, 0},
4553 {"section", obj_coff_section
, 0},
4554 {"sect", obj_coff_section
, 0},
4555 /* FIXME: We ignore the MRI short attribute. */
4556 {"section.s", obj_coff_section
, 0},
4557 {"sect.s", obj_coff_section
, 0},
4558 /* We accept the .bss directive for backward compatibility with
4559 earlier versions of gas. */
4560 {"bss", obj_coff_bss
, 0},
4561 {"weak", obj_coff_weak
, 0},
4562 {"ident", obj_coff_ident
, 0},
4563 #ifndef BFD_ASSEMBLER
4564 {"use", obj_coff_section
, 0},
4565 {"text", obj_coff_text
, 0},
4566 {"data", obj_coff_data
, 0},
4567 {"lcomm", obj_coff_lcomm
, 0},
4569 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4571 {"version", s_ignore
, 0},
4572 {"ABORT", s_abort
, 0},
4574 /* The m88k uses sdef instead of def. */
4575 {"sdef", obj_coff_def
, 0},
4577 {NULL
, NULL
, 0} /* end sentinel */
4578 }; /* coff_pseudo_table */
4580 #ifdef BFD_ASSEMBLER
4582 /* Support for a COFF emulation. */
4584 static void coff_pop_insert
PARAMS ((void));
4585 static int coff_separate_stab_sections
PARAMS ((void));
4590 pop_insert (coff_pseudo_table
);
4594 coff_separate_stab_sections ()
4599 const struct format_ops coff_format_ops
=
4601 bfd_target_coff_flavour
,
4602 0, /* dfl_leading_underscore */
4603 1, /* emit_section_symbols */
4608 coff_frob_file_after_relocs
,
4611 0, /* s_get_align */
4612 0, /* s_set_align */
4613 0, /* s_get_other */
4614 0, /* s_set_other */
4619 0, /* copy_symbol_attributes */
4620 0, /* generate_asm_lineno */
4621 0, /* process_stab */
4622 coff_separate_stab_sections
,
4623 obj_coff_init_stab_section
,
4624 0, /* sec_sym_ok_for_reloc */
4626 0, /* ecoff_set_ext */
4627 coff_obj_read_begin_hook
,
4628 coff_obj_symbol_new_hook