1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 static void obj_coff_bss
PARAMS ((int));
34 const char *s_get_name
PARAMS ((symbolS
* s
));
35 static void obj_coff_ln
PARAMS ((int));
36 static void obj_coff_def
PARAMS ((int));
37 static void obj_coff_endef
PARAMS ((int));
38 static void obj_coff_dim
PARAMS ((int));
39 static void obj_coff_line
PARAMS ((int));
40 static void obj_coff_size
PARAMS ((int));
41 static void obj_coff_scl
PARAMS ((int));
42 static void obj_coff_tag
PARAMS ((int));
43 static void obj_coff_val
PARAMS ((int));
44 static void obj_coff_type
PARAMS ((int));
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
)
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_bad (_("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
;
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 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1318 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1322 coff_frob_file_after_relocs ()
1324 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1328 * implement the .section pseudo op:
1329 * .section name {, "flags"}
1331 * | +--- optional flags: 'b' for bss
1333 * +-- section name 'l' for lib
1337 * 'd' (apparently m88k for data)
1339 * 'r' for read-only data
1340 * 's' for shared data (PE)
1341 * But if the argument is not a quoted string, treat it as a
1342 * subsegment number.
1346 obj_coff_section (ignore
)
1347 int ignore ATTRIBUTE_UNUSED
;
1349 /* Strip out the section name */
1365 section_name
= input_line_pointer
;
1366 c
= get_symbol_end ();
1368 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1369 strcpy (name
, section_name
);
1371 *input_line_pointer
= c
;
1378 if (*input_line_pointer
== ',')
1380 ++input_line_pointer
;
1382 if (*input_line_pointer
!= '"')
1383 exp
= get_absolute_expression ();
1386 ++input_line_pointer
;
1387 while (*input_line_pointer
!= '"'
1388 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1390 switch (*input_line_pointer
)
1392 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1393 case 'n': flags
&=~ SEC_LOAD
; break;
1394 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1395 case 'w': flags
&=~ SEC_READONLY
; break;
1396 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1397 case 'r': flags
|= SEC_READONLY
; break;
1398 case 's': flags
|= SEC_SHARED
; break;
1400 case 'i': /* STYP_INFO */
1401 case 'l': /* STYP_LIB */
1402 case 'o': /* STYP_OVER */
1403 as_warn (_("unsupported section attribute '%c'"),
1404 *input_line_pointer
);
1408 as_warn(_("unknown section attribute '%c'"),
1409 *input_line_pointer
);
1412 ++input_line_pointer
;
1414 if (*input_line_pointer
== '"')
1415 ++input_line_pointer
;
1419 sec
= subseg_new (name
, (subsegT
) exp
);
1421 if (flags
!= SEC_NO_FLAGS
)
1425 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1426 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1429 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1430 as_warn (_("error setting flags for \"%s\": %s"),
1431 bfd_section_name (stdoutput
, sec
),
1432 bfd_errmsg (bfd_get_error ()));
1435 demand_empty_rest_of_line ();
1439 coff_adjust_symtab ()
1441 if (symbol_rootP
== NULL
1442 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1443 c_dot_file_symbol ("fake");
1447 coff_frob_section (sec
)
1453 bfd_vma size
, n_entries
, mask
;
1455 /* The COFF back end in BFD requires that all section sizes be
1456 rounded up to multiples of the corresponding section alignments.
1457 Seems kinda silly to me, but that's the way it is. */
1458 size
= bfd_get_section_size_before_reloc (sec
);
1459 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1462 size
= (size
+ mask
) & ~mask
;
1463 bfd_set_section_size (stdoutput
, sec
, size
);
1466 /* If the section size is non-zero, the section symbol needs an aux
1467 entry associated with it, indicating the size. We don't know
1468 all the values yet; coff_frob_symbol will fill them in later. */
1470 || sec
== text_section
1471 || sec
== data_section
1472 || sec
== bss_section
)
1474 symbolS
*secsym
= section_symbol (sec
);
1476 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1477 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1478 SF_SET_STATICS (secsym
);
1479 SA_SET_SCN_SCNLEN (secsym
, size
);
1482 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1483 #ifndef STAB_SECTION_NAME
1484 #define STAB_SECTION_NAME ".stab"
1486 #ifndef STAB_STRING_SECTION_NAME
1487 #define STAB_STRING_SECTION_NAME ".stabstr"
1489 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1493 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1494 /* size is already rounded up, since other section will be listed first */
1495 size
= bfd_get_section_size_before_reloc (strsec
);
1497 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1499 /* Find first non-empty frag. It should be large enough. */
1500 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1501 while (fragp
&& fragp
->fr_fix
== 0)
1502 fragp
= fragp
->fr_next
;
1503 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1505 /* Store the values. */
1506 p
= fragp
->fr_literal
;
1507 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1508 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1512 obj_coff_init_stab_section (seg
)
1518 unsigned int stroff
;
1520 /* Make space for this first symbol. */
1524 as_where (&file
, (unsigned int *) NULL
);
1525 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1526 strcpy (stabstr_name
, seg
->name
);
1527 strcat (stabstr_name
, "str");
1528 stroff
= get_stab_string_offset (file
, stabstr_name
);
1530 md_number_to_chars (p
, stroff
, 4);
1539 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1547 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1549 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1550 (unsigned long) symbolP
,
1551 S_GET_NAME(symbolP
),
1552 (long) S_GET_DATA_TYPE(symbolP
),
1553 S_GET_STORAGE_CLASS(symbolP
),
1554 (int) S_GET_SEGMENT(symbolP
));
1560 #else /* not BFD_ASSEMBLER */
1563 /* This is needed because we include internal bfd things. */
1567 #include "libcoff.h"
1570 #include "coff/pe.h"
1573 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1574 that we can stick sections together without causing trouble. */
1576 #define NOP_OPCODE 0x00
1579 /* The zeroes if symbol name is longer than 8 chars */
1580 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1582 #define MIN(a,b) ((a) < (b)? (a) : (b))
1584 /* This vector is used to turn a gas internal segment number into a
1585 section number suitable for insertion into a coff symbol table.
1586 This must correspond to seg_info_off_by_4. */
1588 const short seg_N_TYPE
[] =
1589 { /* in: segT out: N_TYPE bits */
1591 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1592 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1593 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1594 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1595 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1596 C_UNDEF_SECTION
, /* SEG_GOOF */
1597 C_UNDEF_SECTION
, /* SEG_EXPR */
1598 C_DEBUG_SECTION
, /* SEG_DEBUG */
1599 C_NTV_SECTION
, /* SEG_NTV */
1600 C_PTV_SECTION
, /* SEG_PTV */
1601 C_REGISTER_SECTION
, /* SEG_REGISTER */
1604 int function_lineoff
= -1; /* Offset in line#s where the last function
1605 started (the odd entry for line #0) */
1607 /* structure used to keep the filenames which
1608 are too long around so that we can stick them
1609 into the string table */
1610 struct filename_list
1613 struct filename_list
*next
;
1616 static struct filename_list
*filename_list_head
;
1617 static struct filename_list
*filename_list_tail
;
1619 static symbolS
*last_line_symbol
;
1621 /* Add 4 to the real value to get the index and compensate the
1622 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1623 section number into a segment number
1625 static symbolS
*previous_file_symbol
;
1626 void c_symbol_merge ();
1627 static int line_base
;
1629 symbolS
*c_section_symbol ();
1632 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1633 segT this_segment_type
));
1636 static void fixup_mdeps
PARAMS ((fragS
*,
1641 static void fill_section
PARAMS ((bfd
* abfd
,
1646 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1651 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1652 symbolS
* symbol_rootP
));
1654 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1656 static void obj_coff_lcomm
PARAMS ((int));
1657 static void obj_coff_text
PARAMS ((int));
1658 static void obj_coff_data
PARAMS ((int));
1659 void obj_coff_section
PARAMS ((int));
1661 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1663 This array maps a COFF section number into a gas section number.
1664 Because COFF uses negative section numbers, you must add 4 to the
1665 COFF section number when indexing into this array; this is done via
1666 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1669 static const segT seg_info_off_by_4
[] =
1676 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1677 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1678 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1679 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1680 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1681 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1682 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1683 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1696 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1698 static relax_addressT
1699 relax_align (address
, alignment
)
1700 relax_addressT address
;
1703 relax_addressT mask
;
1704 relax_addressT new_address
;
1706 mask
= ~((~0) << alignment
);
1707 new_address
= (address
+ mask
) & (~mask
);
1708 return (new_address
- address
);
1716 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1719 /* calculate the size of the frag chain and fill in the section header
1720 to contain all of it, also fill in the addr of the sections */
1722 size_section (abfd
, idx
)
1723 bfd
*abfd ATTRIBUTE_UNUSED
;
1727 unsigned int size
= 0;
1728 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1731 size
= frag
->fr_address
;
1732 if (frag
->fr_address
!= size
)
1734 fprintf (stderr
, _("Out of step\n"));
1735 size
= frag
->fr_address
;
1738 switch (frag
->fr_type
)
1740 #ifdef TC_COFF_SIZEMACHDEP
1741 case rs_machine_dependent
:
1742 size
+= TC_COFF_SIZEMACHDEP (frag
);
1746 assert (frag
->fr_symbol
== 0);
1749 size
+= frag
->fr_fix
;
1750 size
+= frag
->fr_offset
* frag
->fr_var
;
1757 size
+= frag
->fr_fix
;
1758 off
= relax_align (size
, frag
->fr_offset
);
1759 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1765 BAD_CASE (frag
->fr_type
);
1768 frag
= frag
->fr_next
;
1770 segment_info
[idx
].scnhdr
.s_size
= size
;
1776 count_entries_in_chain (idx
)
1779 unsigned int nrelocs
;
1782 /* Count the relocations */
1783 fixup_ptr
= segment_info
[idx
].fix_root
;
1785 while (fixup_ptr
!= (fixS
*) NULL
)
1787 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1790 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1799 fixup_ptr
= fixup_ptr
->fx_next
;
1806 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1808 /* AUX's ld expects relocations to be sorted */
1810 compare_external_relocs (x
, y
)
1814 struct external_reloc
*a
= (struct external_reloc
*) x
;
1815 struct external_reloc
*b
= (struct external_reloc
*) y
;
1816 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1817 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1818 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1823 /* output all the relocations for a section */
1825 do_relocs_for (abfd
, h
, file_cursor
)
1828 unsigned long *file_cursor
;
1830 unsigned int nrelocs
;
1832 unsigned long reloc_start
= *file_cursor
;
1834 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1836 if (segment_info
[idx
].scnhdr
.s_name
[0])
1838 struct external_reloc
*ext_ptr
;
1839 struct external_reloc
*external_reloc_vec
;
1840 unsigned int external_reloc_size
;
1841 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1842 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1843 nrelocs
= count_entries_in_chain (idx
);
1846 /* Bypass this stuff if no relocs. This also incidentally
1847 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1849 external_reloc_size
= nrelocs
* RELSZ
;
1850 external_reloc_vec
=
1851 (struct external_reloc
*) malloc (external_reloc_size
);
1853 ext_ptr
= external_reloc_vec
;
1855 /* Fill in the internal coff style reloc struct from the
1856 internal fix list. */
1859 struct internal_reloc intr
;
1861 /* Only output some of the relocations */
1862 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1864 #ifdef TC_RELOC_MANGLE
1865 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1870 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1872 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1874 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1876 #ifdef TC_KEEP_FX_OFFSET
1877 intr
.r_offset
= fix_ptr
->fx_offset
;
1882 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1883 && (! S_IS_DEFINED (symbol_ptr
)
1884 || S_IS_COMMON (symbol_ptr
)))
1888 /* We must avoid looping, as that can occur
1889 with a badly written program. */
1890 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1891 if (n
== symbol_ptr
)
1896 /* Turn the segment of the symbol into an offset. */
1899 resolve_symbol_value (symbol_ptr
, 1);
1900 if (! symbol_ptr
->sy_resolved
)
1905 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1906 as_bad_where (file
, line
,
1907 _("unresolved relocation"));
1909 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1910 S_GET_NAME (symbol_ptr
));
1912 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1915 intr
.r_symndx
= dot
->sy_number
;
1919 intr
.r_symndx
= symbol_ptr
->sy_number
;
1929 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1932 #if defined(TC_A29K)
1934 /* The 29k has a special kludge for the high 16 bit
1935 reloc. Two relocations are emited, R_IHIHALF,
1936 and R_IHCONST. The second one doesn't contain a
1937 symbol, but uses the value for offset. */
1939 if (intr
.r_type
== R_IHIHALF
)
1941 /* now emit the second bit */
1942 intr
.r_type
= R_IHCONST
;
1943 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1944 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1950 fix_ptr
= fix_ptr
->fx_next
;
1954 /* Sort the reloc table */
1955 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1956 sizeof (struct external_reloc
), compare_external_relocs
);
1959 /* Write out the reloc table */
1960 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1962 free (external_reloc_vec
);
1964 /* Fill in section header info. */
1965 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1966 *file_cursor
+= external_reloc_size
;
1967 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1972 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1976 /* Set relocation_size field in file headers */
1977 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1981 /* run through a frag chain and write out the data to go with it, fill
1982 in the scnhdrs with the info on the file postions
1985 fill_section (abfd
, h
, file_cursor
)
1987 object_headers
*h ATTRIBUTE_UNUSED
;
1988 unsigned long *file_cursor
;
1992 unsigned int paddr
= 0;
1994 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1996 unsigned int offset
= 0;
1997 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2003 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2010 buffer
= xmalloc (s
->s_size
);
2011 s
->s_scnptr
= *file_cursor
;
2013 know (s
->s_paddr
== paddr
);
2015 if (strcmp (s
->s_name
, ".text") == 0)
2016 s
->s_flags
|= STYP_TEXT
;
2017 else if (strcmp (s
->s_name
, ".data") == 0)
2018 s
->s_flags
|= STYP_DATA
;
2019 else if (strcmp (s
->s_name
, ".bss") == 0)
2022 s
->s_flags
|= STYP_BSS
;
2024 /* @@ Should make the i386 and a29k coff targets define
2025 COFF_NOLOAD_PROBLEM, and have only one test here. */
2028 #ifndef COFF_NOLOAD_PROBLEM
2029 /* Apparently the SVR3 linker (and exec syscall) and UDI
2030 mondfe progrem are confused by noload sections. */
2031 s
->s_flags
|= STYP_NOLOAD
;
2036 else if (strcmp (s
->s_name
, ".lit") == 0)
2037 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2038 else if (strcmp (s
->s_name
, ".init") == 0)
2039 s
->s_flags
|= STYP_TEXT
;
2040 else if (strcmp (s
->s_name
, ".fini") == 0)
2041 s
->s_flags
|= STYP_TEXT
;
2042 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2043 s
->s_flags
|= STYP_INFO
;
2047 unsigned int fill_size
;
2048 switch (frag
->fr_type
)
2050 case rs_machine_dependent
:
2053 memcpy (buffer
+ frag
->fr_address
,
2055 (unsigned int) frag
->fr_fix
);
2056 offset
+= frag
->fr_fix
;
2061 assert (frag
->fr_symbol
== 0);
2068 memcpy (buffer
+ frag
->fr_address
,
2070 (unsigned int) frag
->fr_fix
);
2071 offset
+= frag
->fr_fix
;
2074 fill_size
= frag
->fr_var
;
2075 if (fill_size
&& frag
->fr_offset
> 0)
2078 unsigned int off
= frag
->fr_fix
;
2079 for (count
= frag
->fr_offset
; count
; count
--)
2081 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2083 memcpy (buffer
+ frag
->fr_address
+ off
,
2084 frag
->fr_literal
+ frag
->fr_fix
,
2087 offset
+= fill_size
;
2092 case rs_broken_word
:
2097 frag
= frag
->fr_next
;
2102 if (s
->s_scnptr
!= 0)
2104 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2105 *file_cursor
+= s
->s_size
;
2114 /* Coff file generation & utilities */
2117 coff_header_append (abfd
, h
)
2124 #ifdef COFF_LONG_SECTION_NAMES
2125 unsigned long string_size
= 4;
2128 bfd_seek (abfd
, 0, 0);
2130 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2131 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2132 H_SET_VERSION_STAMP (h
, 0);
2133 H_SET_ENTRY_POINT (h
, 0);
2134 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2135 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2136 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2138 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2139 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2140 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2142 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2144 bfd_write (buffer
, i
, 1, abfd
);
2145 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2147 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2149 if (segment_info
[i
].scnhdr
.s_name
[0])
2153 #ifdef COFF_LONG_SECTION_NAMES
2154 /* Support long section names as found in PE. This code
2155 must coordinate with that in write_object_file and
2157 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2159 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2160 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2161 string_size
+= strlen (segment_info
[i
].name
) + 1;
2165 size
= bfd_coff_swap_scnhdr_out (abfd
,
2166 &(segment_info
[i
].scnhdr
),
2169 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2170 bfd_write (buffer
, size
, 1, abfd
);
2177 symbol_to_chars (abfd
, where
, symbolP
)
2182 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2186 /* Turn any symbols with register attributes into abs symbols */
2187 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2189 S_SET_SEGMENT (symbolP
, absolute_section
);
2191 /* At the same time, relocate all symbols to their output value */
2194 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2195 + S_GET_VALUE (symbolP
));
2197 val
= S_GET_VALUE (symbolP
);
2200 S_SET_VALUE (symbolP
, val
);
2202 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2204 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2207 for (i
= 0; i
< numaux
; i
++)
2209 where
+= bfd_coff_swap_aux_out (abfd
,
2210 &symbolP
->sy_symbol
.ost_auxent
[i
],
2211 S_GET_DATA_TYPE (symbolP
),
2212 S_GET_STORAGE_CLASS (symbolP
),
2220 coff_obj_symbol_new_hook (symbolP
)
2223 char underscore
= 0; /* Symbol has leading _ */
2225 /* Effective symbol */
2226 /* Store the pointer in the offset. */
2227 S_SET_ZEROES (symbolP
, 0L);
2228 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2229 S_SET_STORAGE_CLASS (symbolP
, 0);
2230 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2231 /* Additional information */
2232 symbolP
->sy_symbol
.ost_flags
= 0;
2233 /* Auxiliary entries */
2234 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2236 if (S_IS_STRING (symbolP
))
2237 SF_SET_STRING (symbolP
);
2238 if (!underscore
&& S_IS_LOCAL (symbolP
))
2239 SF_SET_LOCAL (symbolP
);
2243 * Handle .ln directives.
2247 obj_coff_ln (appline
)
2252 if (! appline
&& def_symbol_in_progress
!= NULL
)
2254 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2255 demand_empty_rest_of_line ();
2257 } /* wrong context */
2259 l
= get_absolute_expression ();
2260 c_line_new (0, frag_now_fix (), l
, frag_now
);
2263 new_logical_line ((char *) NULL
, l
- 1);
2273 listing_source_line ((unsigned int) l
);
2278 demand_empty_rest_of_line ();
2284 * Handle .def directives.
2286 * One might ask : why can't we symbol_new if the symbol does not
2287 * already exist and fill it with debug information. Because of
2288 * the C_EFCN special symbol. It would clobber the value of the
2289 * function symbol before we have a chance to notice that it is
2290 * a C_EFCN. And a second reason is that the code is more clear this
2291 * way. (at least I think it is :-).
2295 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2296 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2297 *input_line_pointer == '\t') \
2298 input_line_pointer++;
2302 int what ATTRIBUTE_UNUSED
;
2304 char name_end
; /* Char after the end of name */
2305 char *symbol_name
; /* Name of the debug symbol */
2306 char *symbol_name_copy
; /* Temporary copy of the name */
2307 unsigned int symbol_name_length
;
2309 if (def_symbol_in_progress
!= NULL
)
2311 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2312 demand_empty_rest_of_line ();
2314 } /* if not inside .def/.endef */
2316 SKIP_WHITESPACES ();
2318 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2319 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2321 symbol_name
= input_line_pointer
;
2322 name_end
= get_symbol_end ();
2323 symbol_name_length
= strlen (symbol_name
);
2324 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2325 strcpy (symbol_name_copy
, symbol_name
);
2326 #ifdef tc_canonicalize_symbol_name
2327 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2330 /* Initialize the new symbol */
2331 #ifdef STRIP_UNDERSCORE
2332 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2333 ? symbol_name_copy
+ 1
2334 : symbol_name_copy
));
2335 #else /* STRIP_UNDERSCORE */
2336 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2337 #endif /* STRIP_UNDERSCORE */
2338 /* free(symbol_name_copy); */
2339 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2340 def_symbol_in_progress
->sy_number
= ~0;
2341 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2342 S_SET_VALUE (def_symbol_in_progress
, 0);
2344 if (S_IS_STRING (def_symbol_in_progress
))
2345 SF_SET_STRING (def_symbol_in_progress
);
2347 *input_line_pointer
= name_end
;
2349 demand_empty_rest_of_line ();
2352 unsigned int dim_index
;
2356 obj_coff_endef (ignore
)
2357 int ignore ATTRIBUTE_UNUSED
;
2359 symbolS
*symbolP
= 0;
2360 /* DIM BUG FIX sac@cygnus.com */
2362 if (def_symbol_in_progress
== NULL
)
2364 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2365 demand_empty_rest_of_line ();
2367 } /* if not inside .def/.endef */
2369 /* Set the section number according to storage class. */
2370 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2375 SF_SET_TAG (def_symbol_in_progress
);
2376 /* intentional fallthrough */
2379 SF_SET_DEBUG (def_symbol_in_progress
);
2380 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2384 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2385 /* intentional fallthrough */
2387 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2388 /* intentional fallthrough */
2390 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2392 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2394 if (function_lineoff
< 0)
2396 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2397 } /* missing function symbol */
2398 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2400 SF_SET_PROCESS (last_line_symbol
);
2401 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2402 SF_SET_PROCESS (def_symbol_in_progress
);
2403 function_lineoff
= -1;
2405 /* Value is always set to . */
2406 def_symbol_in_progress
->sy_frag
= frag_now
;
2407 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2412 #endif /* C_AUTOARG */
2422 SF_SET_DEBUG (def_symbol_in_progress
);
2423 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2433 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2439 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2441 } /* switch on storage class */
2443 /* Now that we have built a debug symbol, try to find if we should
2444 merge with an existing symbol or not. If a symbol is C_EFCN or
2445 absolute_section or untagged SEG_DEBUG it never merges. We also
2446 don't merge labels, which are in a different namespace, nor
2447 symbols which have not yet been defined since they are typically
2448 unique, nor do we merge tags with non-tags. */
2450 /* Two cases for functions. Either debug followed by definition or
2451 definition followed by debug. For definition first, we will
2452 merge the debug symbol into the definition. For debug first, the
2453 lineno entry MUST point to the definition function or else it
2454 will point off into space when crawl_symbols() merges the debug
2455 symbol into the real symbol. Therefor, let's presume the debug
2456 symbol is a real function reference. */
2458 /* FIXME-SOON If for some reason the definition label/symbol is
2459 never seen, this will probably leave an undefined symbol at link
2462 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2463 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2464 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2465 && !SF_GET_TAG (def_symbol_in_progress
))
2466 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2467 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2468 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2469 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2471 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2476 /* This symbol already exists, merge the newly created symbol
2477 into the old one. This is not mandatory. The linker can
2478 handle duplicate symbols correctly. But I guess that it save
2479 a *lot* of space if the assembly file defines a lot of
2482 /* The debug entry (def_symbol_in_progress) is merged into the
2483 previous definition. */
2485 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2486 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2487 def_symbol_in_progress
= symbolP
;
2489 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2490 || SF_GET_TAG (def_symbol_in_progress
)
2491 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2493 /* For functions, and tags, and static symbols, the symbol
2494 *must* be where the debug symbol appears. Move the
2495 existing symbol to the current place. */
2496 /* If it already is at the end of the symbol list, do nothing */
2497 if (def_symbol_in_progress
!= symbol_lastP
)
2499 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2501 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2502 &symbol_rootP
, &symbol_lastP
);
2503 } /* if not already in place */
2505 } /* normal or mergable */
2507 if (SF_GET_TAG (def_symbol_in_progress
))
2511 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2513 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2514 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2515 def_symbol_in_progress
);
2518 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2520 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2522 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2524 SF_SET_PROCESS (def_symbol_in_progress
);
2526 if (symbolP
== NULL
)
2528 /* That is, if this is the first time we've seen the
2530 symbol_table_insert (def_symbol_in_progress
);
2531 } /* definition follows debug */
2532 } /* Create the line number entry pointing to the function being defined */
2534 def_symbol_in_progress
= NULL
;
2535 demand_empty_rest_of_line ();
2539 obj_coff_dim (ignore
)
2540 int ignore ATTRIBUTE_UNUSED
;
2544 if (def_symbol_in_progress
== NULL
)
2546 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2547 demand_empty_rest_of_line ();
2549 } /* if not inside .def/.endef */
2551 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2553 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2555 SKIP_WHITESPACES ();
2556 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2557 get_absolute_expression ());
2559 switch (*input_line_pointer
)
2562 input_line_pointer
++;
2566 as_warn (_("badly formed .dim directive ignored"));
2567 /* intentional fallthrough */
2575 demand_empty_rest_of_line ();
2579 obj_coff_line (ignore
)
2580 int ignore ATTRIBUTE_UNUSED
;
2585 if (def_symbol_in_progress
== NULL
)
2591 name
= S_GET_NAME (def_symbol_in_progress
);
2592 this_base
= get_absolute_expression ();
2594 /* Only .bf symbols indicate the use of a new base line number; the
2595 line numbers associated with .ef, .bb, .eb are relative to the
2596 start of the containing function. */
2597 if (!strcmp (".bf", name
))
2599 #if 0 /* XXX Can we ever have line numbers going backwards? */
2600 if (this_base
> line_base
)
2603 line_base
= this_base
;
2611 listing_source_line ((unsigned int) line_base
);
2617 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2618 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2620 demand_empty_rest_of_line ();
2624 obj_coff_size (ignore
)
2625 int ignore ATTRIBUTE_UNUSED
;
2627 if (def_symbol_in_progress
== NULL
)
2629 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2630 demand_empty_rest_of_line ();
2632 } /* if not inside .def/.endef */
2634 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2635 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2636 demand_empty_rest_of_line ();
2640 obj_coff_scl (ignore
)
2641 int ignore ATTRIBUTE_UNUSED
;
2643 if (def_symbol_in_progress
== NULL
)
2645 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2646 demand_empty_rest_of_line ();
2648 } /* if not inside .def/.endef */
2650 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2651 demand_empty_rest_of_line ();
2655 obj_coff_tag (ignore
)
2656 int ignore ATTRIBUTE_UNUSED
;
2661 if (def_symbol_in_progress
== NULL
)
2663 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2664 demand_empty_rest_of_line ();
2668 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2669 symbol_name
= input_line_pointer
;
2670 name_end
= get_symbol_end ();
2671 #ifdef tc_canonicalize_symbol_name
2672 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2675 /* Assume that the symbol referred to by .tag is always defined.
2676 This was a bad assumption. I've added find_or_make. xoxorich. */
2677 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2678 (long) tag_find_or_make (symbol_name
));
2679 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2681 as_warn (_("tag not found for .tag %s"), symbol_name
);
2684 SF_SET_TAGGED (def_symbol_in_progress
);
2685 *input_line_pointer
= name_end
;
2687 demand_empty_rest_of_line ();
2691 obj_coff_type (ignore
)
2692 int ignore ATTRIBUTE_UNUSED
;
2694 if (def_symbol_in_progress
== NULL
)
2696 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2697 demand_empty_rest_of_line ();
2699 } /* if not inside .def/.endef */
2701 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2703 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2704 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2706 SF_SET_FUNCTION (def_symbol_in_progress
);
2707 } /* is a function */
2709 demand_empty_rest_of_line ();
2713 obj_coff_val (ignore
)
2714 int ignore ATTRIBUTE_UNUSED
;
2716 if (def_symbol_in_progress
== NULL
)
2718 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2719 demand_empty_rest_of_line ();
2721 } /* if not inside .def/.endef */
2723 if (is_name_beginner (*input_line_pointer
))
2725 char *symbol_name
= input_line_pointer
;
2726 char name_end
= get_symbol_end ();
2728 #ifdef tc_canonicalize_symbol_name
2729 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2732 if (!strcmp (symbol_name
, "."))
2734 def_symbol_in_progress
->sy_frag
= frag_now
;
2735 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2736 /* If the .val is != from the .def (e.g. statics) */
2738 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2740 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2741 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2742 symbol_find_or_make (symbol_name
);
2743 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2744 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2746 /* If the segment is undefined when the forward reference is
2747 resolved, then copy the segment id from the forward
2749 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2751 /* FIXME: gcc can generate address expressions here in
2752 unusual cases (search for "obscure" in sdbout.c). We
2753 just ignore the offset here, thus generating incorrect
2754 debugging information. We ignore the rest of the line
2757 /* Otherwise, it is the name of a non debug symbol and
2758 its value will be calculated later. */
2759 *input_line_pointer
= name_end
;
2761 /* FIXME: this is to avoid an error message in the
2762 FIXME case mentioned just above. */
2763 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2764 ++input_line_pointer
;
2768 S_SET_VALUE (def_symbol_in_progress
,
2769 (valueT
) get_absolute_expression ());
2770 } /* if symbol based */
2772 demand_empty_rest_of_line ();
2777 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2778 read.c, which then calls this object file format specific routine. */
2781 obj_coff_pe_handle_link_once (type
)
2782 enum linkonce_type type
;
2784 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2786 /* We store the type in the seg_info structure, and use it to set up
2787 the auxiliary entry for the section symbol in c_section_symbol. */
2788 seg_info (now_seg
)->linkonce
= type
;
2794 coff_obj_read_begin_hook ()
2796 /* These had better be the same. Usually 18 bytes. */
2798 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2799 know (SYMESZ
== AUXESZ
);
2804 /* This function runs through the symbol table and puts all the
2805 externals onto another chain */
2807 /* The chain of globals. */
2808 symbolS
*symbol_globalP
;
2809 symbolS
*symbol_global_lastP
;
2811 /* The chain of externals */
2812 symbolS
*symbol_externP
;
2813 symbolS
*symbol_extern_lastP
;
2816 symbolS
*last_functionP
;
2817 static symbolS
*last_bfP
;
2824 unsigned int symbol_number
= 0;
2825 unsigned int last_file_symno
= 0;
2827 struct filename_list
*filename_list_scan
= filename_list_head
;
2829 for (symbolP
= symbol_rootP
;
2831 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2833 if (symbolP
->sy_mri_common
)
2835 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2837 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2839 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2840 as_bad (_("%s: global symbols not supported in common sections"),
2841 S_GET_NAME (symbolP
));
2842 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2846 if (!SF_GET_DEBUG (symbolP
))
2848 /* Debug symbols do not need all this rubbish */
2849 symbolS
*real_symbolP
;
2851 /* L* and C_EFCN symbols never merge. */
2852 if (!SF_GET_LOCAL (symbolP
)
2853 && !SF_GET_STATICS (symbolP
)
2854 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2855 && symbolP
->sy_value
.X_op
== O_constant
2856 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2857 && real_symbolP
!= symbolP
)
2859 /* FIXME-SOON: where do dups come from?
2860 Maybe tag references before definitions? xoxorich. */
2861 /* Move the debug data from the debug symbol to the
2862 real symbol. Do NOT do the oposite (i.e. move from
2863 real symbol to debug symbol and remove real symbol from the
2864 list.) Because some pointers refer to the real symbol
2865 whereas no pointers refer to the debug symbol. */
2866 c_symbol_merge (symbolP
, real_symbolP
);
2867 /* Replace the current symbol by the real one */
2868 /* The symbols will never be the last or the first
2869 because : 1st symbol is .file and 3 last symbols are
2870 .text, .data, .bss */
2871 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2872 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2873 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2874 symbolP
= real_symbolP
;
2875 } /* if not local but dup'd */
2877 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2879 S_SET_SEGMENT (symbolP
, SEG_E0
);
2880 } /* push data into text */
2882 resolve_symbol_value (symbolP
, 1);
2884 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2886 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2888 S_SET_EXTERNAL (symbolP
);
2890 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2892 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2896 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2900 /* Mainly to speed up if not -g */
2901 if (SF_GET_PROCESS (symbolP
))
2903 /* Handle the nested blocks auxiliary info. */
2904 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2906 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2907 stack_push (block_stack
, (char *) &symbolP
);
2910 register symbolS
*begin_symbolP
;
2911 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2912 if (begin_symbolP
== (symbolS
*) 0)
2913 as_warn (_("mismatched .eb"));
2915 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2918 /* If we are able to identify the type of a function, and we
2919 are out of a function (last_functionP == 0) then, the
2920 function symbol will be associated with an auxiliary
2922 if (last_functionP
== (symbolS
*) 0 &&
2923 SF_GET_FUNCTION (symbolP
))
2925 last_functionP
= symbolP
;
2927 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2929 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2930 } /* make it at least 1 */
2932 /* Clobber possible stale .dim information. */
2934 /* Iffed out by steve - this fries the lnnoptr info too */
2935 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2936 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2939 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2941 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2943 if (last_bfP
!= NULL
)
2944 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2948 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2950 /* I don't even know if this is needed for sdb. But
2951 the standard assembler generates it, so... */
2952 if (last_functionP
== (symbolS
*) 0)
2953 as_fatal (_("C_EFCN symbol out of scope"));
2954 SA_SET_SYM_FSIZE (last_functionP
,
2955 (long) (S_GET_VALUE (symbolP
) -
2956 S_GET_VALUE (last_functionP
)));
2957 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2958 last_functionP
= (symbolS
*) 0;
2962 else if (SF_GET_TAG (symbolP
))
2964 /* First descriptor of a structure must point to
2965 the first slot after the structure description. */
2966 last_tagP
= symbolP
;
2969 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2971 /* +2 take in account the current symbol */
2972 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2974 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2976 /* If the filename was too long to fit in the
2977 auxent, put it in the string table */
2978 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2979 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2981 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2982 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2983 filename_list_scan
= filename_list_scan
->next
;
2985 if (S_GET_VALUE (symbolP
))
2987 S_SET_VALUE (symbolP
, last_file_symno
);
2988 last_file_symno
= symbol_number
;
2989 } /* no one points at the first .file symbol */
2990 } /* if debug or tag or eos or file */
2992 #ifdef tc_frob_coff_symbol
2993 tc_frob_coff_symbol (symbolP
);
2996 /* We must put the external symbols apart. The loader
2997 does not bomb if we do not. But the references in
2998 the endndx field for a .bb symbol are not corrected
2999 if an external symbol is removed between .bb and .be.
3000 I.e in the following case :
3001 [20] .bb endndx = 22
3004 ld will move the symbol 21 to the end of the list but
3005 endndx will still be 22 instead of 21. */
3008 if (SF_GET_LOCAL (symbolP
))
3010 /* remove C_EFCN and LOCAL (L...) symbols */
3011 /* next pointer remains valid */
3012 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3015 else if (symbolP
->sy_value
.X_op
== O_symbol
3016 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3018 /* Skip symbols which were equated to undefined or common
3020 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3022 else if (!S_IS_DEFINED (symbolP
)
3023 && !S_IS_DEBUG (symbolP
)
3024 && !SF_GET_STATICS (symbolP
)
3025 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3027 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3029 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3031 /* if external, Remove from the list */
3032 symbolS
*hold
= symbol_previous (symbolP
);
3034 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3035 symbol_clear_list_pointers (symbolP
);
3036 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3039 else if (! S_IS_DEBUG (symbolP
)
3040 && ! SF_GET_STATICS (symbolP
)
3041 && ! SF_GET_FUNCTION (symbolP
)
3042 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3044 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3046 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3048 symbolS
*hold
= symbol_previous (symbolP
);
3050 /* The O'Reilly COFF book says that defined global symbols
3051 come at the end of the symbol table, just before
3052 undefined global symbols. */
3054 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3055 symbol_clear_list_pointers (symbolP
);
3056 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3057 &symbol_global_lastP
);
3062 if (SF_GET_STRING (symbolP
))
3064 symbolP
->sy_name_offset
= string_byte_count
;
3065 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3069 symbolP
->sy_name_offset
= 0;
3070 } /* fix "long" names */
3072 symbolP
->sy_number
= symbol_number
;
3073 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3074 } /* if local symbol */
3075 } /* traverse the symbol list */
3076 return symbol_number
;
3082 glue_symbols (head
, tail
)
3086 unsigned int symbol_number
= 0;
3088 while (*head
!= NULL
)
3090 symbolS
*tmp
= *head
;
3093 symbol_remove (tmp
, head
, tail
);
3094 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3097 if (SF_GET_STRING (tmp
))
3099 tmp
->sy_name_offset
= string_byte_count
;
3100 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3104 tmp
->sy_name_offset
= 0;
3105 } /* fix "long" names */
3107 tmp
->sy_number
= symbol_number
;
3108 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3109 } /* append the entire extern chain */
3111 return symbol_number
;
3117 unsigned int symbol_number
= 0;
3120 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3122 symbolP
->sy_number
= symbol_number
;
3124 if (SF_GET_TAGGED (symbolP
))
3128 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3131 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3134 return symbol_number
;
3138 crawl_symbols (h
, abfd
)
3140 bfd
*abfd ATTRIBUTE_UNUSED
;
3144 /* Initialize the stack used to keep track of the matching .bb .be */
3146 block_stack
= stack_init (512, sizeof (symbolS
*));
3148 /* The symbol list should be ordered according to the following sequence
3151 * . debug entries for functions
3152 * . fake symbols for the sections, including .text .data and .bss
3154 * . undefined symbols
3155 * But this is not mandatory. The only important point is to put the
3156 * undefined symbols at the end of the list.
3159 /* Is there a .file symbol ? If not insert one at the beginning. */
3160 if (symbol_rootP
== NULL
3161 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3163 c_dot_file_symbol ("fake");
3167 * Build up static symbols for the sections, they are filled in later
3171 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3172 if (segment_info
[i
].scnhdr
.s_name
[0])
3173 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3176 /* Take all the externals out and put them into another chain */
3177 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3178 /* Take the externals and glue them onto the end.*/
3179 H_SET_SYMBOL_TABLE_SIZE (h
,
3180 (H_GET_SYMBOL_COUNT (h
)
3181 + glue_symbols (&symbol_globalP
,
3182 &symbol_global_lastP
)
3183 + glue_symbols (&symbol_externP
,
3184 &symbol_extern_lastP
)));
3186 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3187 know (symbol_globalP
== NULL
);
3188 know (symbol_global_lastP
== NULL
);
3189 know (symbol_externP
== NULL
);
3190 know (symbol_extern_lastP
== NULL
);
3194 * Find strings by crawling along symbol table chain.
3202 struct filename_list
*filename_list_scan
= filename_list_head
;
3204 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3205 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3208 #ifdef COFF_LONG_SECTION_NAMES
3209 /* Support long section names as found in PE. This code must
3210 coordinate with that in coff_header_append and write_object_file. */
3214 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3216 if (segment_info
[i
].scnhdr
.s_name
[0]
3217 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3221 size
= strlen (segment_info
[i
].name
) + 1;
3222 memcpy (where
, segment_info
[i
].name
, size
);
3227 #endif /* COFF_LONG_SECTION_NAMES */
3229 for (symbolP
= symbol_rootP
;
3231 symbolP
= symbol_next (symbolP
))
3235 if (SF_GET_STRING (symbolP
))
3237 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3238 memcpy (where
, S_GET_NAME (symbolP
), size
);
3241 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3242 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3243 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3245 size
= strlen (filename_list_scan
->filename
) + 1;
3246 memcpy (where
, filename_list_scan
->filename
, size
);
3247 filename_list_scan
= filename_list_scan
->next
;
3254 do_linenos_for (abfd
, h
, file_cursor
)
3257 unsigned long *file_cursor
;
3260 unsigned long start
= *file_cursor
;
3262 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3264 segment_info_type
*s
= segment_info
+ idx
;
3267 if (s
->scnhdr
.s_nlnno
!= 0)
3269 struct lineno_list
*line_ptr
;
3271 struct external_lineno
*buffer
=
3272 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3274 struct external_lineno
*dst
= buffer
;
3276 /* Run through the table we've built and turn it into its external
3277 form, take this chance to remove duplicates */
3279 for (line_ptr
= s
->lineno_list_head
;
3280 line_ptr
!= (struct lineno_list
*) NULL
;
3281 line_ptr
= line_ptr
->next
)
3284 if (line_ptr
->line
.l_lnno
== 0)
3286 /* Turn a pointer to a symbol into the symbols' index */
3287 line_ptr
->line
.l_addr
.l_symndx
=
3288 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3292 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3296 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3301 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3303 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3306 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3309 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3313 /* Now we run through the list of frag chains in a segment and
3314 make all the subsegment frags appear at the end of the
3315 list, as if the seg 0 was extra long */
3322 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3324 frchainS
*head
= segment_info
[i
].frchainP
;
3326 fragS
*prev_frag
= &dummy
;
3328 while (head
&& head
->frch_seg
== i
)
3330 prev_frag
->fr_next
= head
->frch_root
;
3331 prev_frag
= head
->frch_last
;
3332 head
= head
->frch_next
;
3334 prev_frag
->fr_next
= 0;
3338 unsigned long machine
;
3341 write_object_file ()
3345 struct frchain
*frchain_ptr
;
3347 object_headers headers
;
3348 unsigned long file_cursor
;
3351 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3356 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3357 exit (EXIT_FAILURE
);
3359 bfd_set_format (abfd
, bfd_object
);
3360 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3362 string_byte_count
= 4;
3364 for (frchain_ptr
= frchain_root
;
3365 frchain_ptr
!= (struct frchain
*) NULL
;
3366 frchain_ptr
= frchain_ptr
->frch_next
)
3368 /* Run through all the sub-segments and align them up. Also
3369 close any open frags. We tack a .fill onto the end of the
3370 frag chain so that any .align's size can be worked by looking
3371 at the next frag. */
3373 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3375 #ifndef SUB_SEGMENT_ALIGN
3376 #define SUB_SEGMENT_ALIGN(SEG) 1
3379 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3382 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3383 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3388 frag_wane (frag_now
);
3389 frag_now
->fr_fix
= 0;
3390 know (frag_now
->fr_next
== NULL
);
3397 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3399 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3402 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3404 /* Find out how big the sections are, and set the addresses. */
3406 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3410 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3411 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3413 if (segment_info
[i
].scnhdr
.s_name
[0])
3415 H_SET_NUMBER_OF_SECTIONS (&headers
,
3416 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3418 #ifdef COFF_LONG_SECTION_NAMES
3419 /* Support long section names as found in PE. This code
3420 must coordinate with that in coff_header_append and
3425 len
= strlen (segment_info
[i
].name
);
3427 string_byte_count
+= len
+ 1;
3429 #endif /* COFF_LONG_SECTION_NAMES */
3432 size
= size_section (abfd
, (unsigned int) i
);
3435 /* I think the section alignment is only used on the i960; the
3436 i960 needs it, and it should do no harm on other targets. */
3437 #ifdef ALIGNMENT_IN_S_FLAGS
3438 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3440 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3444 H_SET_TEXT_SIZE (&headers
, size
);
3445 else if (i
== SEG_E1
)
3446 H_SET_DATA_SIZE (&headers
, size
);
3447 else if (i
== SEG_E2
)
3448 H_SET_BSS_SIZE (&headers
, size
);
3451 /* Turn the gas native symbol table shape into a coff symbol table */
3452 crawl_symbols (&headers
, abfd
);
3454 if (string_byte_count
== 4)
3455 string_byte_count
= 0;
3457 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3463 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3465 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3466 fixup_segment (&segment_info
[i
], i
);
3469 /* Look for ".stab" segments and fill in their initial symbols
3471 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3473 name
= segment_info
[i
].name
;
3476 && strncmp (".stab", name
, 5) == 0
3477 && strncmp (".stabstr", name
, 8) != 0)
3478 adjust_stab_section (abfd
, i
);
3481 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3483 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3485 /* Plant the data */
3487 fill_section (abfd
, &headers
, &file_cursor
);
3489 do_relocs_for (abfd
, &headers
, &file_cursor
);
3491 do_linenos_for (abfd
, &headers
, &file_cursor
);
3493 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3494 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3495 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3497 H_SET_TIME_STAMP (&headers
, 0);
3499 #ifdef TC_COFF_SET_MACHINE
3500 TC_COFF_SET_MACHINE (&headers
);
3504 #define COFF_FLAGS 0
3507 #ifdef KEEP_RELOC_INFO
3508 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3509 COFF_FLAGS
| coff_flags
));
3511 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3512 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3513 COFF_FLAGS
| coff_flags
));
3517 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3518 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3520 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3521 w_symbols (abfd
, buffer1
, symbol_rootP
);
3522 if (string_byte_count
> 0)
3523 w_strings (buffer1
+ symtable_size
);
3524 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3528 coff_header_append (abfd
, &headers
);
3530 /* Recent changes to write need this, but where it should
3531 go is up to Ken.. */
3532 if (bfd_close_all_done (abfd
) == false)
3533 as_fatal (_("Can't close %s: %s"), out_file_name
,
3534 bfd_errmsg (bfd_get_error ()));
3537 extern bfd
*stdoutput
;
3544 /* Add a new segment. This is called from subseg_new via the
3545 obj_new_segment macro. */
3548 obj_coff_add_segment (name
)
3553 #ifndef COFF_LONG_SECTION_NAMES
3554 char buf
[SCNNMLEN
+ 1];
3556 strncpy (buf
, name
, SCNNMLEN
);
3557 buf
[SCNNMLEN
] = '\0';
3561 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3562 if (strcmp (name
, segment_info
[i
].name
) == 0)
3567 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3571 /* Add a new section. */
3572 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3573 sizeof (segment_info
[i
].scnhdr
.s_name
));
3574 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3575 segment_info
[i
].name
= xstrdup (name
);
3581 * implement the .section pseudo op:
3582 * .section name {, "flags"}
3584 * | +--- optional flags: 'b' for bss
3586 * +-- section name 'l' for lib
3590 * 'd' (apparently m88k for data)
3592 * 'r' for read-only data
3593 * But if the argument is not a quoted string, treat it as a
3594 * subsegment number.
3598 obj_coff_section (ignore
)
3599 int ignore ATTRIBUTE_UNUSED
;
3601 /* Strip out the section name */
3602 char *section_name
, *name
;
3615 else if (type
== 'D')
3617 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3622 section_name
= input_line_pointer
;
3623 c
= get_symbol_end ();
3625 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3626 strcpy (name
, section_name
);
3628 *input_line_pointer
= c
;
3634 if (*input_line_pointer
== ',')
3636 ++input_line_pointer
;
3639 if (*input_line_pointer
!= '"')
3640 exp
= get_absolute_expression ();
3643 ++input_line_pointer
;
3644 while (*input_line_pointer
!= '"'
3645 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3647 switch (*input_line_pointer
)
3649 case 'b': flags
|= STYP_BSS
; break;
3650 case 'i': flags
|= STYP_INFO
; break;
3651 case 'l': flags
|= STYP_LIB
; break;
3652 case 'n': flags
|= STYP_NOLOAD
; break;
3653 case 'o': flags
|= STYP_OVER
; break;
3655 case 'w': flags
|= STYP_DATA
; break;
3656 case 'x': flags
|= STYP_TEXT
; break;
3657 case 'r': flags
|= STYP_LIT
; break;
3659 as_warn(_("unknown section attribute '%c'"),
3660 *input_line_pointer
);
3663 ++input_line_pointer
;
3665 if (*input_line_pointer
== '"')
3666 ++input_line_pointer
;
3670 subseg_new (name
, (subsegT
) exp
);
3672 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3674 demand_empty_rest_of_line ();
3679 obj_coff_text (ignore
)
3680 int ignore ATTRIBUTE_UNUSED
;
3682 subseg_new (".text", get_absolute_expression ());
3687 obj_coff_data (ignore
)
3688 int ignore ATTRIBUTE_UNUSED
;
3690 if (flag_readonly_data_in_text
)
3691 subseg_new (".text", get_absolute_expression () + 1000);
3693 subseg_new (".data", get_absolute_expression ());
3697 obj_coff_ident (ignore
)
3698 int ignore ATTRIBUTE_UNUSED
;
3700 segT current_seg
= now_seg
; /* save current seg */
3701 subsegT current_subseg
= now_subseg
;
3702 subseg_new (".comment", 0); /* .comment seg */
3703 stringer (1); /* read string */
3704 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3708 c_symbol_merge (debug
, normal
)
3712 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3713 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3715 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3717 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3718 } /* take the most we have */
3720 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3722 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3723 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3724 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3725 } /* Move all the auxiliary information */
3727 /* Move the debug flags. */
3728 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3729 } /* c_symbol_merge() */
3732 c_line_new (symbol
, paddr
, line_number
, frag
)
3738 struct lineno_list
*new_line
=
3739 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3741 segment_info_type
*s
= segment_info
+ now_seg
;
3742 new_line
->line
.l_lnno
= line_number
;
3744 if (line_number
== 0)
3746 last_line_symbol
= symbol
;
3747 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3751 new_line
->line
.l_addr
.l_paddr
= paddr
;
3754 new_line
->frag
= (char *) frag
;
3755 new_line
->next
= (struct lineno_list
*) NULL
;
3758 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3760 s
->lineno_list_head
= new_line
;
3764 s
->lineno_list_tail
->next
= new_line
;
3766 s
->lineno_list_tail
= new_line
;
3767 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3771 c_dot_file_symbol (filename
)
3776 symbolP
= symbol_new (".file",
3779 &zero_address_frag
);
3781 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3782 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3784 if (strlen (filename
) > FILNMLEN
)
3786 /* Filename is too long to fit into an auxent,
3787 we stick it into the string table instead. We keep
3788 a linked list of the filenames we find so we can emit
3790 struct filename_list
*f
= ((struct filename_list
*)
3791 xmalloc (sizeof (struct filename_list
)));
3793 f
->filename
= filename
;
3796 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3797 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3799 if (filename_list_tail
)
3800 filename_list_tail
->next
= f
;
3802 filename_list_head
= f
;
3803 filename_list_tail
= f
;
3807 SA_SET_FILE_FNAME (symbolP
, filename
);
3814 listing_source_file (filename
);
3820 SF_SET_DEBUG (symbolP
);
3821 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3823 previous_file_symbol
= symbolP
;
3825 /* Make sure that the symbol is first on the symbol chain */
3826 if (symbol_rootP
!= symbolP
)
3828 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3829 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3831 } /* c_dot_file_symbol() */
3834 * Build a 'section static' symbol.
3838 c_section_symbol (name
, idx
)
3844 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3845 if (symbolP
== NULL
)
3846 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3849 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3850 S_SET_SEGMENT (symbolP
, idx
);
3851 symbolP
->sy_frag
= &zero_address_frag
;
3854 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3855 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3857 SF_SET_STATICS (symbolP
);
3860 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3861 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3862 SF_CLEAR_LOCAL (symbolP
);
3865 /* If the .linkonce pseudo-op was used for this section, we must
3866 store the information in the auxiliary entry for the section
3868 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3872 switch (segment_info
[idx
].linkonce
)
3876 case LINKONCE_DISCARD
:
3877 type
= IMAGE_COMDAT_SELECT_ANY
;
3879 case LINKONCE_ONE_ONLY
:
3880 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3882 case LINKONCE_SAME_SIZE
:
3883 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3885 case LINKONCE_SAME_CONTENTS
:
3886 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3890 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3895 } /* c_section_symbol() */
3898 w_symbols (abfd
, where
, symbol_rootP
)
3901 symbolS
* symbol_rootP
;
3906 /* First fill in those values we have only just worked out */
3907 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3909 symbolP
= segment_info
[i
].dot
;
3912 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3913 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3914 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3919 * Emit all symbols left in the symbol chain.
3921 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3923 /* Used to save the offset of the name. It is used to point
3924 to the string in memory but must be a file offset. */
3925 register char *temp
;
3927 /* We can't fix the lnnoptr field in yank_symbols with the other
3928 adjustments, because we have to wait until we know where they
3930 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3932 SA_GET_SYM_LNNOPTR (symbolP
) +=
3933 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3936 tc_coff_symbol_emit_hook (symbolP
);
3938 temp
= S_GET_NAME (symbolP
);
3939 if (SF_GET_STRING (symbolP
))
3941 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3942 S_SET_ZEROES (symbolP
, 0);
3946 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3947 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3949 where
= symbol_to_chars (abfd
, where
, symbolP
);
3950 S_SET_NAME (symbolP
, temp
);
3956 obj_coff_lcomm (ignore
)
3957 int ignore ATTRIBUTE_UNUSED
;
3969 name
= input_line_pointer
;
3971 c
= get_symbol_end ();
3972 p
= input_line_pointer
;
3975 if (*input_line_pointer
!= ',')
3977 as_bad (_("Expected comma after name"));
3978 ignore_rest_of_line ();
3981 if (*input_line_pointer
== '\n')
3983 as_bad (_("Missing size expression"));
3986 input_line_pointer
++;
3987 if ((temp
= get_absolute_expression ()) < 0)
3989 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3990 ignore_rest_of_line ();
3995 symbolP
= symbol_find_or_make(name
);
3997 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3998 S_GET_VALUE(symbolP
) == 0)
4003 segT current_seg
= now_seg
; /* save current seg */
4004 subsegT current_subseg
= now_subseg
;
4006 subseg_set (SEG_E2
, 1);
4007 symbolP
->sy_frag
= frag_now
;
4008 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4009 (offsetT
) temp
, (char *) 0);
4011 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4012 S_SET_SEGMENT(symbolP
, SEG_E2
);
4013 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
4017 as_bad(_("Symbol %s already defined"), name
);
4019 demand_empty_rest_of_line();
4024 fixup_mdeps (frags
, h
, this_segment
)
4029 subseg_change (this_segment
, 0);
4032 switch (frags
->fr_type
)
4038 HANDLE_ALIGN (frags
);
4040 frags
->fr_type
= rs_fill
;
4042 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4045 case rs_machine_dependent
:
4046 md_convert_frag (h
, this_segment
, frags
);
4052 frags
= frags
->fr_next
;
4058 #ifndef TC_FORCE_RELOCATION
4059 #define TC_FORCE_RELOCATION(fix) 0
4063 fixup_segment (segP
, this_segment_type
)
4064 segment_info_type
* segP
;
4065 segT this_segment_type
;
4067 register fixS
* fixP
;
4068 register symbolS
*add_symbolP
;
4069 register symbolS
*sub_symbolP
;
4072 register char *place
;
4073 register long where
;
4074 register char pcrel
;
4075 register fragS
*fragP
;
4076 register segT add_symbol_segment
= absolute_section
;
4078 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4080 fragP
= fixP
->fx_frag
;
4082 where
= fixP
->fx_where
;
4083 place
= fragP
->fr_literal
+ where
;
4084 size
= fixP
->fx_size
;
4085 add_symbolP
= fixP
->fx_addsy
;
4086 sub_symbolP
= fixP
->fx_subsy
;
4087 add_number
= fixP
->fx_offset
;
4088 pcrel
= fixP
->fx_pcrel
;
4090 /* We want function-relative stabs to work on systems which
4091 may use a relaxing linker; thus we must handle the sym1-sym2
4092 fixups function-relative stabs generates.
4094 Of course, if you actually enable relaxing in the linker, the
4095 line and block scoping information is going to be incorrect
4096 in some cases. The only way to really fix this is to support
4097 a reloc involving the difference of two symbols. */
4099 && (!sub_symbolP
|| pcrel
))
4103 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4105 /* Relocation should be done via the associated 'bal' entry
4108 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4110 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4111 _("No 'bal' entry point for leafproc %s"),
4112 S_GET_NAME (add_symbolP
));
4115 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4119 /* Make sure the symbols have been resolved; this may not have
4120 happened if these are expression symbols. */
4121 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4122 resolve_symbol_value (add_symbolP
, 1);
4124 if (add_symbolP
!= NULL
)
4126 /* If this fixup is against a symbol which has been equated
4127 to another symbol, convert it to the other symbol. */
4128 if (add_symbolP
->sy_value
.X_op
== O_symbol
4129 && (! S_IS_DEFINED (add_symbolP
)
4130 || S_IS_COMMON (add_symbolP
)))
4132 while (add_symbolP
->sy_value
.X_op
== O_symbol
4133 && (! S_IS_DEFINED (add_symbolP
)
4134 || S_IS_COMMON (add_symbolP
)))
4138 /* We must avoid looping, as that can occur with a
4139 badly written program. */
4140 n
= add_symbolP
->sy_value
.X_add_symbol
;
4141 if (n
== add_symbolP
)
4143 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4146 fixP
->fx_addsy
= add_symbolP
;
4147 fixP
->fx_offset
= add_number
;
4151 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4152 resolve_symbol_value (sub_symbolP
, 1);
4154 if (add_symbolP
!= NULL
4155 && add_symbolP
->sy_mri_common
)
4157 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4158 add_number
+= S_GET_VALUE (add_symbolP
);
4159 fixP
->fx_offset
= add_number
;
4160 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4165 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4166 } /* if there is an addend */
4170 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4172 if (add_symbolP
!= NULL
)
4174 add_number
+= S_GET_VALUE (add_symbolP
);
4176 fixP
->fx_addsy
= NULL
;
4179 /* It's just -sym. */
4180 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4182 add_number
-= S_GET_VALUE (sub_symbolP
);
4189 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4190 _("Negative of non-absolute symbol %s"),
4191 S_GET_NAME (sub_symbolP
));
4193 add_number
-= S_GET_VALUE (sub_symbolP
);
4194 } /* not absolute */
4196 /* if sub_symbol is in the same segment that add_symbol
4197 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4199 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4200 && SEG_NORMAL (add_symbol_segment
))
4202 /* Difference of 2 symbols from same segment. Can't
4203 make difference of 2 undefineds: 'value' means
4204 something different for N_UNDF. */
4206 /* Makes no sense to use the difference of 2 arbitrary symbols
4207 as the target of a call instruction. */
4210 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4211 _("callj to difference of 2 symbols"));
4213 #endif /* TC_I960 */
4214 add_number
+= S_GET_VALUE (add_symbolP
) -
4215 S_GET_VALUE (sub_symbolP
);
4218 if (!TC_FORCE_RELOCATION (fixP
))
4220 fixP
->fx_addsy
= NULL
;
4221 fixP
->fx_subsy
= NULL
;
4223 #ifdef TC_M68K /* is this right? */
4231 /* Different segments in subtraction. */
4232 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4234 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4236 add_number
-= S_GET_VALUE (sub_symbolP
);
4239 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4240 #if 0 /* Okay for 68k, at least... */
4245 /* Make it pc-relative. */
4246 add_number
+= (md_pcrel_from (fixP
)
4247 - S_GET_VALUE (sub_symbolP
));
4256 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4257 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4258 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4259 S_GET_NAME (sub_symbolP
),
4260 (long) (fragP
->fr_address
+ where
));
4263 } /* if sub_symbolP */
4267 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4270 * This fixup was made when the symbol's segment was
4271 * SEG_UNKNOWN, but it is now in the local segment.
4272 * So we know how to do the address without relocation.
4275 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4276 * in which cases it modifies *fixP as appropriate. In the case
4277 * of a 'calls', no further work is required, and *fixP has been
4278 * set up to make the rest of the code below a no-op.
4281 #endif /* TC_I960 */
4283 add_number
+= S_GET_VALUE (add_symbolP
);
4284 add_number
-= md_pcrel_from (fixP
);
4287 add_number -= segP->scnhdr.s_vaddr;
4288 if defined (TC_I386) || defined (TE_LYNX). I now
4289 think that was an error propagated from the case when
4290 we are going to emit the relocation. If we are not
4291 going to emit the relocation, then we just want to
4292 set add_number to the difference between the symbols.
4293 This is a case that would only arise when there is a
4294 PC relative reference from a section other than .text
4295 to a symbol defined in the same section, and the
4296 reference is not relaxed. Since jump instructions on
4297 the i386 are relaxed, this could only arise with a
4298 call instruction. */
4300 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4301 if (!TC_FORCE_RELOCATION (fixP
))
4303 fixP
->fx_addsy
= NULL
;
4309 switch (add_symbol_segment
)
4311 case absolute_section
:
4313 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4314 #endif /* TC_I960 */
4315 add_number
+= S_GET_VALUE (add_symbolP
);
4318 if (!TC_FORCE_RELOCATION (fixP
))
4320 fixP
->fx_addsy
= NULL
;
4327 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4328 /* This really should be handled in the linker, but
4329 backward compatibility forbids. */
4330 add_number
+= S_GET_VALUE (add_symbolP
);
4332 add_number
+= S_GET_VALUE (add_symbolP
) +
4333 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4339 if ((int) fixP
->fx_bit_fixP
== 13)
4341 /* This is a COBR instruction. They have only a
4342 * 13-bit displacement and are only to be used
4343 * for local branches: flag as error, don't generate
4346 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4347 _("can't use COBR format with external label"));
4348 fixP
->fx_addsy
= NULL
;
4352 #endif /* TC_I960 */
4353 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4354 /* 386 COFF uses a peculiar format in which the
4355 value of a common symbol is stored in the .text
4356 segment (I've checked this on SVR3.2 and SCO
4357 3.2.2) Ian Taylor <ian@cygnus.com>. */
4358 /* This is also true for 68k COFF on sysv machines
4359 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4360 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4361 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4362 if (S_IS_COMMON (add_symbolP
))
4363 add_number
+= S_GET_VALUE (add_symbolP
);
4368 } /* switch on symbol seg */
4369 } /* if not in local seg */
4370 } /* if there was a + symbol */
4374 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4375 /* This adjustment is not correct on the m88k, for which the
4376 linker does all the computation. */
4377 add_number
-= md_pcrel_from (fixP
);
4379 if (add_symbolP
== 0)
4381 fixP
->fx_addsy
= &abs_symbol
;
4382 } /* if there's an add_symbol */
4383 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4384 /* On the 386 we must adjust by the segment vaddr as well.
4387 I changed the i960 to work this way as well. This is
4388 compatible with the current GNU linker behaviour. I do
4389 not know what other i960 COFF assemblers do. This is not
4390 a common case: normally, only assembler code will contain
4391 a PC relative reloc, and only branches which do not
4392 originate in the .text section will have a non-zero
4395 I changed the m68k to work this way as well. This will
4396 break existing PC relative relocs from sections which do
4397 not start at address 0, but it will make ld -r work.
4398 Ian Taylor, 4 Oct 96. */
4400 add_number
-= segP
->scnhdr
.s_vaddr
;
4404 #ifdef MD_APPLY_FIX3
4405 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4407 md_apply_fix (fixP
, add_number
);
4410 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4413 /* The m88k uses the offset field of the reloc to get around
4416 && ((add_number
& ~0xFF)
4417 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4418 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4419 || (add_number
& 0x80) == 0))
4421 && ((add_number
& ~0xFFFF)
4422 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4423 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4424 || (add_number
& 0x8000) == 0)))
4426 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4427 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4428 (long) add_number
, size
,
4429 (unsigned long) (fragP
->fr_address
+ where
));
4432 #ifdef WARN_SIGNED_OVERFLOW_WORD
4433 /* Warn if a .word value is too large when treated as a
4434 signed number. We already know it is not too negative.
4435 This is to catch over-large switches generated by gcc on
4437 if (!flag_signed_overflow_ok
4439 && add_number
> 0x7fff)
4440 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4441 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4443 (unsigned long) (fragP
->fr_address
+ where
));
4445 } /* not a bit fix */
4446 } /* For each fixS in this segment. */
4447 } /* fixup_segment() */
4451 /* The first entry in a .stab section is special. */
4454 obj_coff_init_stab_section (seg
)
4460 unsigned int stroff
;
4462 /* Make space for this first symbol. */
4466 as_where (&file
, (unsigned int *) NULL
);
4467 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4468 strcpy (stabstr_name
, segment_info
[seg
].name
);
4469 strcat (stabstr_name
, "str");
4470 stroff
= get_stab_string_offset (file
, stabstr_name
);
4472 md_number_to_chars (p
, stroff
, 4);
4475 /* Fill in the counts in the first entry in a .stab section. */
4478 adjust_stab_section(abfd
, seg
)
4482 segT stabstrseg
= SEG_UNKNOWN
;
4483 const char *secname
, *name2
;
4486 int i
, strsz
= 0, nsyms
;
4487 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4489 /* Look for the associated string table section. */
4491 secname
= segment_info
[seg
].name
;
4492 name
= (char *) alloca (strlen (secname
) + 4);
4493 strcpy (name
, secname
);
4494 strcat (name
, "str");
4496 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4498 name2
= segment_info
[i
].name
;
4499 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4506 /* If we found the section, get its size. */
4507 if (stabstrseg
!= SEG_UNKNOWN
)
4508 strsz
= size_section (abfd
, stabstrseg
);
4510 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4512 /* Look for the first frag of sufficient size for the initial stab
4513 symbol, and collect a pointer to it. */
4514 while (frag
&& frag
->fr_fix
< 12)
4515 frag
= frag
->fr_next
;
4517 p
= frag
->fr_literal
;
4520 /* Write in the number of stab symbols and the size of the string
4522 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4523 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4526 #endif /* not BFD_ASSEMBLER */
4528 const pseudo_typeS obj_pseudo_table
[] =
4530 {"def", obj_coff_def
, 0},
4531 {"dim", obj_coff_dim
, 0},
4532 {"endef", obj_coff_endef
, 0},
4533 {"line", obj_coff_line
, 0},
4534 {"ln", obj_coff_ln
, 0},
4535 #ifdef BFD_ASSEMBLER
4536 {"loc", obj_coff_loc
, 0},
4538 {"appline", obj_coff_ln
, 1},
4539 {"scl", obj_coff_scl
, 0},
4540 {"size", obj_coff_size
, 0},
4541 {"tag", obj_coff_tag
, 0},
4542 {"type", obj_coff_type
, 0},
4543 {"val", obj_coff_val
, 0},
4544 {"section", obj_coff_section
, 0},
4545 {"sect", obj_coff_section
, 0},
4546 /* FIXME: We ignore the MRI short attribute. */
4547 {"section.s", obj_coff_section
, 0},
4548 {"sect.s", obj_coff_section
, 0},
4549 /* We accept the .bss directive for backward compatibility with
4550 earlier versions of gas. */
4551 {"bss", obj_coff_bss
, 0},
4552 {"weak", obj_coff_weak
, 0},
4553 {"ident", obj_coff_ident
, 0},
4554 #ifndef BFD_ASSEMBLER
4555 {"use", obj_coff_section
, 0},
4556 {"text", obj_coff_text
, 0},
4557 {"data", obj_coff_data
, 0},
4558 {"lcomm", obj_coff_lcomm
, 0},
4560 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4562 {"version", s_ignore
, 0},
4563 {"ABORT", s_abort
, 0},
4565 /* The m88k uses sdef instead of def. */
4566 {"sdef", obj_coff_def
, 0},
4568 {NULL
, NULL
, 0} /* end sentinel */
4569 }; /* obj_pseudo_table */
4571 #ifdef BFD_ASSEMBLER
4573 static void coff_pop_insert
PARAMS ((void));
4574 static int coff_sec_sym_ok_for_reloc
PARAMS ((asection
*));
4576 /* Support for a COFF emulation. */
4581 pop_insert (obj_pseudo_table
);
4585 coff_sec_sym_ok_for_reloc (sec
)
4586 asection
*sec ATTRIBUTE_UNUSED
;
4591 const struct format_ops coff_format_ops
=
4593 bfd_target_coff_flavour
,
4598 coff_frob_file_after_relocs
,
4603 obj_generate_asm_lineno
,
4612 coff_sec_sym_ok_for_reloc
,
4619 coff_obj_read_begin_hook
,
4620 coff_obj_symbol_new_hook
,