1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
29 /* I think this is probably always correct. */
30 #ifndef KEEP_RELOC_INFO
31 #define KEEP_RELOC_INFO
34 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
35 a new section's attributes when a directive has no valid flags or the
36 "w" flag is used. This default should be appropriate for most. */
37 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
38 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
41 static void obj_coff_bss
PARAMS ((int));
42 const char *s_get_name
PARAMS ((symbolS
* s
));
43 static void obj_coff_ln
PARAMS ((int));
44 static void obj_coff_def
PARAMS ((int));
45 static void obj_coff_endef
PARAMS ((int));
46 static void obj_coff_dim
PARAMS ((int));
47 static void obj_coff_line
PARAMS ((int));
48 static void obj_coff_size
PARAMS ((int));
49 static void obj_coff_scl
PARAMS ((int));
50 static void obj_coff_tag
PARAMS ((int));
51 static void obj_coff_val
PARAMS ((int));
52 static void obj_coff_type
PARAMS ((int));
53 static void obj_coff_ident
PARAMS ((int));
55 static void obj_coff_loc
PARAMS((int));
58 /* This is used to hold the symbol built by a sequence of pseudo-ops
59 from .def and .endef. */
60 static symbolS
*def_symbol_in_progress
;
65 unsigned long chunk_size
;
66 unsigned long element_size
;
69 unsigned long pointer
;
74 stack_init (chunk_size
, element_size
)
75 unsigned long chunk_size
;
76 unsigned long element_size
;
80 st
= (stack
*) malloc (sizeof (stack
));
83 st
->data
= malloc (chunk_size
);
90 st
->size
= chunk_size
;
91 st
->chunk_size
= chunk_size
;
92 st
->element_size
= element_size
;
97 /* Not currently used. */
108 stack_push (st
, element
)
112 if (st
->pointer
+ st
->element_size
>= st
->size
)
114 st
->size
+= st
->chunk_size
;
115 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
118 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
119 st
->pointer
+= st
->element_size
;
120 return st
->data
+ st
->pointer
;
127 if (st
->pointer
< st
->element_size
)
132 st
->pointer
-= st
->element_size
;
133 return st
->data
+ st
->pointer
;
137 * Maintain a list of the tagnames of the structres.
140 static struct hash_control
*tag_hash
;
145 tag_hash
= hash_new ();
149 tag_insert (name
, symbolP
)
153 const char *error_string
;
155 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
157 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
166 #ifdef STRIP_UNDERSCORE
169 #endif /* STRIP_UNDERSCORE */
170 return (symbolS
*) hash_find (tag_hash
, name
);
174 tag_find_or_make (name
)
179 if ((symbolP
= tag_find (name
)) == NULL
)
181 symbolP
= symbol_new (name
, undefined_section
,
182 0, &zero_address_frag
);
184 tag_insert (S_GET_NAME (symbolP
), symbolP
);
186 symbol_table_insert (symbolP
);
193 /* We accept the .bss directive to set the section for backward
194 compatibility with earlier versions of gas. */
197 obj_coff_bss (ignore
)
198 int ignore ATTRIBUTE_UNUSED
;
200 if (*input_line_pointer
== '\n')
201 subseg_new (".bss", get_absolute_expression ());
206 /* Handle .weak. This is a GNU extension. */
209 obj_coff_weak (ignore
)
210 int ignore ATTRIBUTE_UNUSED
;
218 name
= input_line_pointer
;
219 c
= get_symbol_end ();
220 symbolP
= symbol_find_or_make (name
);
221 *input_line_pointer
= c
;
224 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
225 S_SET_WEAK (symbolP
);
229 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
231 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
236 input_line_pointer
++;
238 if (*input_line_pointer
== '\n')
244 demand_empty_rest_of_line ();
249 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
251 #define GET_FILENAME_STRING(X) \
252 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
256 fetch_coff_debug_section ()
258 static segT debug_section
;
262 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
264 debug_section
= s
->section
;
266 return debug_section
;
270 SA_SET_SYM_ENDNDX (sym
, val
)
274 combined_entry_type
*entry
, *p
;
276 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
277 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
278 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
283 SA_SET_SYM_TAGNDX (sym
, val
)
287 combined_entry_type
*entry
, *p
;
289 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
290 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
291 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
296 S_GET_DATA_TYPE (sym
)
299 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
303 S_SET_DATA_TYPE (sym
, val
)
307 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
312 S_GET_STORAGE_CLASS (sym
)
315 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
319 S_SET_STORAGE_CLASS (sym
, val
)
323 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
327 /* Merge a debug symbol containing debug information into a normal symbol. */
330 c_symbol_merge (debug
, normal
)
334 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
335 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
337 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
339 /* take the most we have */
340 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
343 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
345 /* Move all the auxiliary information. */
346 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
347 (S_GET_NUMBER_AUXILIARY (debug
)
348 * sizeof (*SYM_AUXINFO (debug
))));
351 /* Move the debug flags. */
352 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
356 c_dot_file_symbol (filename
)
357 const char *filename
;
361 /* BFD converts filename to a .file symbol with an aux entry. It
362 also handles chaining. */
363 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
365 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
366 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
368 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
375 listing_source_file (filename
);
380 /* Make sure that the symbol is first on the symbol chain */
381 if (symbol_rootP
!= symbolP
)
383 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
384 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
385 } /* if not first on the list */
388 /* Line number handling */
391 struct line_no
*next
;
398 /* Symbol of last function, which we should hang line#s off of. */
399 static symbolS
*line_fsym
;
401 #define in_function() (line_fsym != 0)
402 #define clear_function() (line_fsym = 0)
403 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
407 coff_obj_symbol_new_hook (symbolP
)
410 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
411 char * s
= (char *) xmalloc (sz
);
414 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
416 S_SET_DATA_TYPE (symbolP
, T_NULL
);
417 S_SET_STORAGE_CLASS (symbolP
, 0);
418 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
420 if (S_IS_STRING (symbolP
))
421 SF_SET_STRING (symbolP
);
423 if (S_IS_LOCAL (symbolP
))
424 SF_SET_LOCAL (symbolP
);
429 * Handle .ln directives.
432 static symbolS
*current_lineno_sym
;
433 static struct line_no
*line_nos
;
434 /* @@ Blindly assume all .ln directives will be in the .text section... */
438 add_lineno (frag
, offset
, num
)
443 struct line_no
*new_line
=
444 (struct line_no
*) xmalloc (sizeof (struct line_no
));
445 if (!current_lineno_sym
)
451 /* Zero is used as an end marker in the file. */
452 as_warn (_("Line numbers must be positive integers\n"));
455 new_line
->next
= line_nos
;
456 new_line
->frag
= frag
;
457 new_line
->l
.line_number
= num
;
458 new_line
->l
.u
.offset
= offset
;
464 coff_add_linesym (sym
)
469 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
474 current_lineno_sym
= sym
;
478 obj_coff_ln (appline
)
483 if (! appline
&& def_symbol_in_progress
!= NULL
)
485 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
486 demand_empty_rest_of_line ();
490 l
= get_absolute_expression ();
493 add_lineno (frag_now
, frag_now_fix (), l
);
497 new_logical_line ((char *) NULL
, l
- 1);
506 l
+= coff_line_base
- 1;
507 listing_source_line (l
);
512 demand_empty_rest_of_line ();
515 /* .loc is essentially the same as .ln; parse it for assembler
519 obj_coff_loc (ignore
)
520 int ignore ATTRIBUTE_UNUSED
;
524 /* FIXME: Why do we need this check? We need it for ECOFF, but why
525 do we need it for COFF? */
526 if (now_seg
!= text_section
)
528 as_warn (_(".loc outside of .text"));
529 demand_empty_rest_of_line ();
533 if (def_symbol_in_progress
!= NULL
)
535 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
536 demand_empty_rest_of_line ();
540 /* Skip the file number. */
542 get_absolute_expression ();
545 lineno
= get_absolute_expression ();
553 lineno
+= coff_line_base
- 1;
554 listing_source_line (lineno
);
559 demand_empty_rest_of_line ();
561 add_lineno (frag_now
, frag_now_fix (), lineno
);
564 /* Handle the .ident pseudo-op. */
567 obj_coff_ident (ignore
)
568 int ignore ATTRIBUTE_UNUSED
;
570 segT current_seg
= now_seg
;
571 subsegT current_subseg
= now_subseg
;
577 /* We could put it in .comment, but that creates an extra section
578 that shouldn't be loaded into memory, which requires linker
579 changes... For now, until proven otherwise, use .rdata. */
580 sec
= subseg_new (".rdata$zzz", 0);
581 bfd_set_section_flags (stdoutput
, sec
,
582 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
583 & bfd_applicable_section_flags (stdoutput
)));
586 subseg_new (".comment", 0);
590 subseg_set (current_seg
, current_subseg
);
596 * Handle .def directives.
598 * One might ask : why can't we symbol_new if the symbol does not
599 * already exist and fill it with debug information. Because of
600 * the C_EFCN special symbol. It would clobber the value of the
601 * function symbol before we have a chance to notice that it is
602 * a C_EFCN. And a second reason is that the code is more clear this
603 * way. (at least I think it is :-).
607 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
608 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
609 *input_line_pointer == '\t') \
610 input_line_pointer++;
614 int what ATTRIBUTE_UNUSED
;
616 char name_end
; /* Char after the end of name */
617 char *symbol_name
; /* Name of the debug symbol */
618 char *symbol_name_copy
; /* Temporary copy of the name */
619 unsigned int symbol_name_length
;
621 if (def_symbol_in_progress
!= NULL
)
623 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
624 demand_empty_rest_of_line ();
626 } /* if not inside .def/.endef */
630 symbol_name
= input_line_pointer
;
631 #ifdef STRIP_UNDERSCORE
632 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
634 #endif /* STRIP_UNDERSCORE */
636 name_end
= get_symbol_end ();
637 symbol_name_length
= strlen (symbol_name
);
638 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
639 strcpy (symbol_name_copy
, symbol_name
);
640 #ifdef tc_canonicalize_symbol_name
641 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
644 /* Initialize the new symbol */
645 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
646 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
647 S_SET_VALUE (def_symbol_in_progress
, 0);
649 if (S_IS_STRING (def_symbol_in_progress
))
650 SF_SET_STRING (def_symbol_in_progress
);
652 *input_line_pointer
= name_end
;
654 demand_empty_rest_of_line ();
657 unsigned int dim_index
;
660 obj_coff_endef (ignore
)
661 int ignore ATTRIBUTE_UNUSED
;
663 symbolS
*symbolP
= NULL
;
665 /* DIM BUG FIX sac@cygnus.com */
667 if (def_symbol_in_progress
== NULL
)
669 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
670 demand_empty_rest_of_line ();
672 } /* if not inside .def/.endef */
674 /* Set the section number according to storage class. */
675 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
680 SF_SET_TAG (def_symbol_in_progress
);
681 /* intentional fallthrough */
684 SF_SET_DEBUG (def_symbol_in_progress
);
685 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
689 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
690 /* intentional fallthrough */
692 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
693 /* intentional fallthrough */
697 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
699 name
= S_GET_NAME (def_symbol_in_progress
);
700 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
706 if (! in_function ())
707 as_warn (_("`%s' symbol without preceding function"), name
);
708 /* Will need relocating. */
709 SF_SET_PROCESS (def_symbol_in_progress
);
715 /* The MS compilers output the actual endline, not the
716 function-relative one... we want to match without
717 changing the assembler input. */
718 SA_SET_SYM_LNNO (def_symbol_in_progress
,
719 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
730 #endif /* C_AUTOARG */
737 /* According to the COFF documentation:
739 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
741 A special section number (-2) marks symbolic debugging symbols,
742 including structure/union/enumeration tag names, typedefs, and
743 the name of the file. A section number of -1 indicates that the
744 symbol has a value but is not relocatable. Examples of
745 absolute-valued symbols include automatic and register variables,
746 function arguments, and .eos symbols.
748 But from Ian Lance Taylor:
750 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
752 the actual tools all marked them as section -1. So the GNU COFF
753 assembler follows historical COFF assemblers.
755 However, it causes problems for djgpp
757 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
759 By defining STRICTCOFF, a COFF port can make the assembler to
760 follow the documented behavior. */
767 SF_SET_DEBUG (def_symbol_in_progress
);
768 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
776 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
787 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
794 as_warn (_("unexpected storage class %d"),
795 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
797 } /* switch on storage class */
799 /* Now that we have built a debug symbol, try to find if we should
800 merge with an existing symbol or not. If a symbol is C_EFCN or
801 absolute_section or untagged SEG_DEBUG it never merges. We also
802 don't merge labels, which are in a different namespace, nor
803 symbols which have not yet been defined since they are typically
804 unique, nor do we merge tags with non-tags. */
806 /* Two cases for functions. Either debug followed by definition or
807 definition followed by debug. For definition first, we will
808 merge the debug symbol into the definition. For debug first, the
809 lineno entry MUST point to the definition function or else it
810 will point off into space when obj_crawl_symbol_chain() merges
811 the debug symbol into the real symbol. Therefor, let's presume
812 the debug symbol is a real function reference. */
814 /* FIXME-SOON If for some reason the definition label/symbol is
815 never seen, this will probably leave an undefined symbol at link
818 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
819 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
820 || (!strcmp (bfd_get_section_name (stdoutput
,
821 S_GET_SEGMENT (def_symbol_in_progress
)),
823 && !SF_GET_TAG (def_symbol_in_progress
))
824 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
825 || ! symbol_constant_p (def_symbol_in_progress
)
826 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
827 DO_NOT_STRIP
)) == NULL
828 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
830 /* If it already is at the end of the symbol list, do nothing */
831 if (def_symbol_in_progress
!= symbol_lastP
)
833 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
834 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
840 /* This symbol already exists, merge the newly created symbol
841 into the old one. This is not mandatory. The linker can
842 handle duplicate symbols correctly. But I guess that it save
843 a *lot* of space if the assembly file defines a lot of
846 /* The debug entry (def_symbol_in_progress) is merged into the
847 previous definition. */
849 c_symbol_merge (def_symbol_in_progress
, symbolP
);
850 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
852 def_symbol_in_progress
= symbolP
;
854 if (SF_GET_FUNCTION (def_symbol_in_progress
)
855 || SF_GET_TAG (def_symbol_in_progress
)
856 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
858 /* For functions, and tags, and static symbols, the symbol
859 *must* be where the debug symbol appears. Move the
860 existing symbol to the current place. */
861 /* If it already is at the end of the symbol list, do nothing */
862 if (def_symbol_in_progress
!= symbol_lastP
)
864 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
865 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
870 if (SF_GET_TAG (def_symbol_in_progress
))
874 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
876 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
877 tag_insert (S_GET_NAME (def_symbol_in_progress
),
878 def_symbol_in_progress
);
881 if (SF_GET_FUNCTION (def_symbol_in_progress
))
883 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
884 set_function (def_symbol_in_progress
);
885 SF_SET_PROCESS (def_symbol_in_progress
);
889 /* That is, if this is the first time we've seen the
891 symbol_table_insert (def_symbol_in_progress
);
892 } /* definition follows debug */
893 } /* Create the line number entry pointing to the function being defined */
895 def_symbol_in_progress
= NULL
;
896 demand_empty_rest_of_line ();
900 obj_coff_dim (ignore
)
901 int ignore ATTRIBUTE_UNUSED
;
905 if (def_symbol_in_progress
== NULL
)
907 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
908 demand_empty_rest_of_line ();
910 } /* if not inside .def/.endef */
912 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
914 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
917 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
918 get_absolute_expression ());
920 switch (*input_line_pointer
)
923 input_line_pointer
++;
927 as_warn (_("badly formed .dim directive ignored"));
928 /* intentional fallthrough */
936 demand_empty_rest_of_line ();
940 obj_coff_line (ignore
)
941 int ignore ATTRIBUTE_UNUSED
;
945 if (def_symbol_in_progress
== NULL
)
947 /* Probably stabs-style line? */
952 this_base
= get_absolute_expression ();
953 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
954 coff_line_base
= this_base
;
956 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
957 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
959 demand_empty_rest_of_line ();
962 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
967 listing_source_line ((unsigned int) this_base
);
973 obj_coff_size (ignore
)
974 int ignore ATTRIBUTE_UNUSED
;
976 if (def_symbol_in_progress
== NULL
)
978 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
979 demand_empty_rest_of_line ();
981 } /* if not inside .def/.endef */
983 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
984 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
985 demand_empty_rest_of_line ();
989 obj_coff_scl (ignore
)
990 int ignore ATTRIBUTE_UNUSED
;
992 if (def_symbol_in_progress
== NULL
)
994 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
995 demand_empty_rest_of_line ();
997 } /* if not inside .def/.endef */
999 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1000 demand_empty_rest_of_line ();
1004 obj_coff_tag (ignore
)
1005 int ignore ATTRIBUTE_UNUSED
;
1010 if (def_symbol_in_progress
== NULL
)
1012 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
1013 demand_empty_rest_of_line ();
1017 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1018 symbol_name
= input_line_pointer
;
1019 name_end
= get_symbol_end ();
1021 #ifdef tc_canonicalize_symbol_name
1022 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1025 /* Assume that the symbol referred to by .tag is always defined.
1026 This was a bad assumption. I've added find_or_make. xoxorich. */
1027 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1028 tag_find_or_make (symbol_name
));
1029 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1031 as_warn (_("tag not found for .tag %s"), symbol_name
);
1034 SF_SET_TAGGED (def_symbol_in_progress
);
1035 *input_line_pointer
= name_end
;
1037 demand_empty_rest_of_line ();
1041 obj_coff_type (ignore
)
1042 int ignore ATTRIBUTE_UNUSED
;
1044 if (def_symbol_in_progress
== NULL
)
1046 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1047 demand_empty_rest_of_line ();
1049 } /* if not inside .def/.endef */
1051 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1053 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1054 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1056 SF_SET_FUNCTION (def_symbol_in_progress
);
1057 } /* is a function */
1059 demand_empty_rest_of_line ();
1063 obj_coff_val (ignore
)
1064 int ignore ATTRIBUTE_UNUSED
;
1066 if (def_symbol_in_progress
== NULL
)
1068 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1069 demand_empty_rest_of_line ();
1071 } /* if not inside .def/.endef */
1073 if (is_name_beginner (*input_line_pointer
))
1075 char *symbol_name
= input_line_pointer
;
1076 char name_end
= get_symbol_end ();
1078 #ifdef tc_canonicalize_symbol_name
1079 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1081 if (!strcmp (symbol_name
, "."))
1083 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1084 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1085 /* If the .val is != from the .def (e.g. statics) */
1087 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1091 exp
.X_op
= O_symbol
;
1092 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1093 exp
.X_op_symbol
= NULL
;
1094 exp
.X_add_number
= 0;
1095 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1097 /* If the segment is undefined when the forward reference is
1098 resolved, then copy the segment id from the forward
1100 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1102 /* FIXME: gcc can generate address expressions here in
1103 unusual cases (search for "obscure" in sdbout.c). We
1104 just ignore the offset here, thus generating incorrect
1105 debugging information. We ignore the rest of the line
1108 /* Otherwise, it is the name of a non debug symbol and its value
1109 will be calculated later. */
1110 *input_line_pointer
= name_end
;
1114 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1115 } /* if symbol based */
1117 demand_empty_rest_of_line ();
1121 coff_obj_read_begin_hook ()
1123 /* These had better be the same. Usually 18 bytes. */
1125 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1126 know (SYMESZ
== AUXESZ
);
1131 symbolS
*coff_last_function
;
1132 static symbolS
*coff_last_bf
;
1135 coff_frob_symbol (symp
, punt
)
1139 static symbolS
*last_tagP
;
1140 static stack
*block_stack
;
1141 static symbolS
*set_end
;
1142 symbolS
*next_set_end
= NULL
;
1144 if (symp
== &abs_symbol
)
1150 if (current_lineno_sym
)
1151 coff_add_linesym ((symbolS
*) 0);
1154 block_stack
= stack_init (512, sizeof (symbolS
*));
1156 if (S_IS_WEAK (symp
))
1159 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1161 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1165 if (!S_IS_DEFINED (symp
)
1166 && !S_IS_WEAK (symp
)
1167 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1168 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1170 if (!SF_GET_DEBUG (symp
))
1173 if (!SF_GET_LOCAL (symp
)
1174 && !SF_GET_STATICS (symp
)
1175 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1176 && symbol_constant_p(symp
)
1177 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1180 c_symbol_merge (symp
, real
);
1184 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1186 assert (S_GET_VALUE (symp
) == 0);
1187 S_SET_EXTERNAL (symp
);
1189 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1191 if (S_GET_SEGMENT (symp
) == text_section
1192 && symp
!= seg_info (text_section
)->sym
)
1193 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1195 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1197 if (SF_GET_PROCESS (symp
))
1199 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1201 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1202 stack_push (block_stack
, (char *) &symp
);
1206 begin
= *(symbolS
**) stack_pop (block_stack
);
1208 as_warn (_("mismatched .eb"));
1210 next_set_end
= begin
;
1213 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1215 union internal_auxent
*auxp
;
1216 coff_last_function
= symp
;
1217 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1218 S_SET_NUMBER_AUXILIARY (symp
, 1);
1219 auxp
= SYM_AUXENT (symp
);
1220 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1221 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1223 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1225 if (coff_last_function
== 0)
1226 as_fatal (_("C_EFCN symbol out of scope"));
1227 SA_SET_SYM_FSIZE (coff_last_function
,
1228 (long) (S_GET_VALUE (symp
)
1229 - S_GET_VALUE (coff_last_function
)));
1230 next_set_end
= coff_last_function
;
1231 coff_last_function
= 0;
1234 if (S_IS_EXTERNAL (symp
))
1235 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1236 else if (SF_GET_LOCAL (symp
))
1239 if (SF_GET_FUNCTION (symp
))
1240 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1245 /* Double check weak symbols. */
1246 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1247 as_bad (_("Symbol `%s' can not be both weak and common"),
1250 if (SF_GET_TAG (symp
))
1252 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1253 next_set_end
= last_tagP
;
1256 /* This is pretty horrible, but we have to set *punt correctly in
1257 order to call SA_SET_SYM_ENDNDX correctly. */
1258 if (! symbol_used_in_reloc_p (symp
)
1259 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1260 || (! S_IS_EXTERNAL (symp
)
1261 && ! symbol_get_tc (symp
)->output
1262 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1266 if (set_end
!= (symbolS
*) NULL
1268 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1269 || (S_IS_DEFINED (symp
)
1270 && ! S_IS_COMMON (symp
)
1271 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1273 SA_SET_SYM_ENDNDX (set_end
, symp
);
1277 if (next_set_end
!= NULL
)
1279 if (set_end
!= NULL
)
1280 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1281 S_GET_NAME (set_end
));
1282 set_end
= next_set_end
;
1286 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1287 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1289 if (coff_last_bf
!= NULL
)
1290 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1291 coff_last_bf
= symp
;
1294 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1297 struct line_no
*lptr
;
1300 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1301 for (i
= 0; lptr
; lptr
= lptr
->next
)
1303 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1305 /* We need i entries for line numbers, plus 1 for the first
1306 entry which BFD will override, plus 1 for the last zero
1307 entry (a marker for BFD). */
1308 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1309 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1310 l
[i
+ 1].line_number
= 0;
1311 l
[i
+ 1].u
.sym
= NULL
;
1315 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1323 coff_adjust_section_syms (abfd
, sec
, x
)
1324 bfd
*abfd ATTRIBUTE_UNUSED
;
1326 PTR x ATTRIBUTE_UNUSED
;
1329 segment_info_type
*seginfo
= seg_info (sec
);
1330 int nlnno
, nrelocs
= 0;
1332 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1333 tc-ppc.c. Do not get confused by it. */
1334 if (seginfo
== NULL
)
1337 if (!strcmp (sec
->name
, ".text"))
1338 nlnno
= coff_n_line_nos
;
1342 /* @@ Hope that none of the fixups expand to more than one reloc
1344 fixS
*fixp
= seginfo
->fix_root
;
1347 if (! fixp
->fx_done
)
1349 fixp
= fixp
->fx_next
;
1352 if (bfd_get_section_size_before_reloc (sec
) == 0
1355 && sec
!= text_section
1356 && sec
!= data_section
1357 && sec
!= bss_section
)
1359 secsym
= section_symbol (sec
);
1360 /* This is an estimate; we'll plug in the real value using
1361 SET_SECTION_RELOCS later */
1362 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1363 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1367 coff_frob_file_after_relocs ()
1369 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1373 * implement the .section pseudo op:
1374 * .section name {, "flags"}
1376 * | +--- optional flags: 'b' for bss
1378 * +-- section name 'l' for lib
1382 * 'd' (apparently m88k for data)
1384 * 'r' for read-only data
1385 * 's' for shared data (PE)
1386 * But if the argument is not a quoted string, treat it as a
1387 * subsegment number.
1391 obj_coff_section (ignore
)
1392 int ignore ATTRIBUTE_UNUSED
;
1394 /* Strip out the section name */
1399 flagword flags
, oldflags
;
1410 section_name
= input_line_pointer
;
1411 c
= get_symbol_end ();
1413 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1414 strcpy (name
, section_name
);
1416 *input_line_pointer
= c
;
1421 flags
= SEC_NO_FLAGS
;
1423 if (*input_line_pointer
== ',')
1425 ++input_line_pointer
;
1427 if (*input_line_pointer
!= '"')
1428 exp
= get_absolute_expression ();
1431 ++input_line_pointer
;
1432 while (*input_line_pointer
!= '"'
1433 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1435 switch (*input_line_pointer
)
1437 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1438 case 'n': flags
&=~ SEC_LOAD
; flags
|= SEC_NEVER_LOAD
; break;
1439 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1440 case 'w': flags
&=~ SEC_READONLY
; break;
1441 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1442 case 'r': flags
|= SEC_READONLY
; break;
1443 case 's': flags
|= SEC_SHARED
; break;
1445 case 'i': /* STYP_INFO */
1446 case 'l': /* STYP_LIB */
1447 case 'o': /* STYP_OVER */
1448 as_warn (_("unsupported section attribute '%c'"),
1449 *input_line_pointer
);
1453 as_warn(_("unknown section attribute '%c'"),
1454 *input_line_pointer
);
1457 ++input_line_pointer
;
1459 if (*input_line_pointer
== '"')
1460 ++input_line_pointer
;
1464 sec
= subseg_new (name
, (subsegT
) exp
);
1466 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1467 if (oldflags
== SEC_NO_FLAGS
)
1469 /* Set section flags for a new section just created by subseg_new.
1470 Provide a default if no flags were parsed. */
1471 if (flags
== SEC_NO_FLAGS
)
1472 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1474 #ifdef COFF_LONG_SECTION_NAMES
1475 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1476 sections so adjust_reloc_syms in write.c will correctly handle
1477 relocs which refer to non-local symbols in these sections. */
1478 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1479 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1482 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1483 as_warn (_("error setting flags for \"%s\": %s"),
1484 bfd_section_name (stdoutput
, sec
),
1485 bfd_errmsg (bfd_get_error ()));
1487 else if (flags
!= SEC_NO_FLAGS
)
1489 /* This section's attributes have already been set. Warn if the
1490 attributes don't match. */
1491 flagword matchflags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1492 | SEC_DATA
| SEC_SHARED
| SEC_NEVER_LOAD
;
1493 if ((flags
^ oldflags
) & matchflags
)
1494 as_warn (_("Ignoring changed section attributes for %s"), name
);
1497 demand_empty_rest_of_line ();
1501 coff_adjust_symtab ()
1503 if (symbol_rootP
== NULL
1504 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1505 c_dot_file_symbol ("fake");
1509 coff_frob_section (sec
)
1515 bfd_vma size
, n_entries
, mask
;
1516 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1518 /* The COFF back end in BFD requires that all section sizes be
1519 rounded up to multiples of the corresponding section alignments,
1520 supposedly because standard COFF has no other way of encoding alignment
1521 for sections. If your COFF flavor has a different way of encoding
1522 section alignment, then skip this step, as TICOFF does. */
1523 size
= bfd_get_section_size_before_reloc (sec
);
1524 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1525 #if !defined(TICOFF)
1531 new_size
= (size
+ mask
) & ~mask
;
1532 bfd_set_section_size (stdoutput
, sec
, new_size
);
1534 /* If the size had to be rounded up, add some padding in
1535 the last non-empty frag. */
1536 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1537 last
= seg_info (sec
)->frchainP
->frch_last
;
1538 while (fragp
->fr_next
!= last
)
1539 fragp
= fragp
->fr_next
;
1540 last
->fr_address
= size
;
1541 fragp
->fr_offset
+= new_size
- size
;
1545 /* If the section size is non-zero, the section symbol needs an aux
1546 entry associated with it, indicating the size. We don't know
1547 all the values yet; coff_frob_symbol will fill them in later. */
1550 || sec
== text_section
1551 || sec
== data_section
1552 || sec
== bss_section
)
1555 symbolS
*secsym
= section_symbol (sec
);
1557 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1558 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1559 SF_SET_STATICS (secsym
);
1560 SA_SET_SCN_SCNLEN (secsym
, size
);
1563 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1564 #ifndef STAB_SECTION_NAME
1565 #define STAB_SECTION_NAME ".stab"
1567 #ifndef STAB_STRING_SECTION_NAME
1568 #define STAB_STRING_SECTION_NAME ".stabstr"
1570 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1574 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1575 /* size is already rounded up, since other section will be listed first */
1576 size
= bfd_get_section_size_before_reloc (strsec
);
1578 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1580 /* Find first non-empty frag. It should be large enough. */
1581 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1582 while (fragp
&& fragp
->fr_fix
== 0)
1583 fragp
= fragp
->fr_next
;
1584 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1586 /* Store the values. */
1587 p
= fragp
->fr_literal
;
1588 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1589 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1593 obj_coff_init_stab_section (seg
)
1599 unsigned int stroff
;
1601 /* Make space for this first symbol. */
1605 as_where (&file
, (unsigned int *) NULL
);
1606 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1607 strcpy (stabstr_name
, seg
->name
);
1608 strcat (stabstr_name
, "str");
1609 stroff
= get_stab_string_offset (file
, stabstr_name
);
1611 md_number_to_chars (p
, stroff
, 4);
1620 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1628 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1630 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1631 (unsigned long) symbolP
,
1632 S_GET_NAME(symbolP
),
1633 (long) S_GET_DATA_TYPE(symbolP
),
1634 S_GET_STORAGE_CLASS(symbolP
),
1635 (int) S_GET_SEGMENT(symbolP
));
1641 #else /* not BFD_ASSEMBLER */
1644 /* This is needed because we include internal bfd things. */
1648 #include "libcoff.h"
1651 #include "coff/pe.h"
1654 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1655 that we can stick sections together without causing trouble. */
1657 #define NOP_OPCODE 0x00
1660 /* The zeroes if symbol name is longer than 8 chars */
1661 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1663 #define MIN(a,b) ((a) < (b)? (a) : (b))
1665 /* This vector is used to turn a gas internal segment number into a
1666 section number suitable for insertion into a coff symbol table.
1667 This must correspond to seg_info_off_by_4. */
1669 const short seg_N_TYPE
[] =
1670 { /* in: segT out: N_TYPE bits */
1672 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1673 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1674 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1675 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1676 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1677 C_UNDEF_SECTION
, /* SEG_GOOF */
1678 C_UNDEF_SECTION
, /* SEG_EXPR */
1679 C_DEBUG_SECTION
, /* SEG_DEBUG */
1680 C_NTV_SECTION
, /* SEG_NTV */
1681 C_PTV_SECTION
, /* SEG_PTV */
1682 C_REGISTER_SECTION
, /* SEG_REGISTER */
1685 int function_lineoff
= -1; /* Offset in line#s where the last function
1686 started (the odd entry for line #0) */
1688 /* structure used to keep the filenames which
1689 are too long around so that we can stick them
1690 into the string table */
1691 struct filename_list
1694 struct filename_list
*next
;
1697 static struct filename_list
*filename_list_head
;
1698 static struct filename_list
*filename_list_tail
;
1700 static symbolS
*last_line_symbol
;
1702 /* Add 4 to the real value to get the index and compensate the
1703 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1704 section number into a segment number
1706 static symbolS
*previous_file_symbol
;
1707 void c_symbol_merge ();
1708 static int line_base
;
1710 symbolS
*c_section_symbol ();
1713 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1714 segT this_segment_type
));
1716 static void fixup_mdeps
PARAMS ((fragS
*,
1720 static void fill_section
PARAMS ((bfd
* abfd
,
1724 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1728 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1729 symbolS
* symbol_rootP
));
1731 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1733 static void obj_coff_lcomm
PARAMS ((int));
1734 static void obj_coff_text
PARAMS ((int));
1735 static void obj_coff_data
PARAMS ((int));
1736 void obj_coff_section
PARAMS ((int));
1738 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1740 This array maps a COFF section number into a gas section number.
1741 Because COFF uses negative section numbers, you must add 4 to the
1742 COFF section number when indexing into this array; this is done via
1743 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1746 static const segT seg_info_off_by_4
[] =
1753 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1754 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1755 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1756 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1757 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1758 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1759 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1760 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1773 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1775 static relax_addressT
1776 relax_align (address
, alignment
)
1777 relax_addressT address
;
1780 relax_addressT mask
;
1781 relax_addressT new_address
;
1783 mask
= ~((~0) << alignment
);
1784 new_address
= (address
+ mask
) & (~mask
);
1785 return (new_address
- address
);
1792 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1795 /* calculate the size of the frag chain and fill in the section header
1796 to contain all of it, also fill in the addr of the sections */
1798 size_section (abfd
, idx
)
1799 bfd
*abfd ATTRIBUTE_UNUSED
;
1803 unsigned int size
= 0;
1804 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1807 size
= frag
->fr_address
;
1808 if (frag
->fr_address
!= size
)
1810 fprintf (stderr
, _("Out of step\n"));
1811 size
= frag
->fr_address
;
1814 switch (frag
->fr_type
)
1816 #ifdef TC_COFF_SIZEMACHDEP
1817 case rs_machine_dependent
:
1818 size
+= TC_COFF_SIZEMACHDEP (frag
);
1822 assert (frag
->fr_symbol
== 0);
1825 size
+= frag
->fr_fix
;
1826 size
+= frag
->fr_offset
* frag
->fr_var
;
1834 size
+= frag
->fr_fix
;
1835 off
= relax_align (size
, frag
->fr_offset
);
1836 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1842 BAD_CASE (frag
->fr_type
);
1845 frag
= frag
->fr_next
;
1847 segment_info
[idx
].scnhdr
.s_size
= size
;
1852 count_entries_in_chain (idx
)
1855 unsigned int nrelocs
;
1858 /* Count the relocations */
1859 fixup_ptr
= segment_info
[idx
].fix_root
;
1861 while (fixup_ptr
!= (fixS
*) NULL
)
1863 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1866 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1875 fixup_ptr
= fixup_ptr
->fx_next
;
1882 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1884 /* AUX's ld expects relocations to be sorted */
1886 compare_external_relocs (x
, y
)
1890 struct external_reloc
*a
= (struct external_reloc
*) x
;
1891 struct external_reloc
*b
= (struct external_reloc
*) y
;
1892 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1893 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1894 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1899 /* output all the relocations for a section */
1901 do_relocs_for (abfd
, h
, file_cursor
)
1904 unsigned long *file_cursor
;
1906 unsigned int nrelocs
;
1908 unsigned long reloc_start
= *file_cursor
;
1910 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1912 if (segment_info
[idx
].scnhdr
.s_name
[0])
1914 struct external_reloc
*ext_ptr
;
1915 struct external_reloc
*external_reloc_vec
;
1916 unsigned int external_reloc_size
;
1917 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1918 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1919 nrelocs
= count_entries_in_chain (idx
);
1922 /* Bypass this stuff if no relocs. This also incidentally
1923 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1925 external_reloc_size
= nrelocs
* RELSZ
;
1926 external_reloc_vec
=
1927 (struct external_reloc
*) malloc (external_reloc_size
);
1929 ext_ptr
= external_reloc_vec
;
1931 /* Fill in the internal coff style reloc struct from the
1932 internal fix list. */
1935 struct internal_reloc intr
;
1937 /* Only output some of the relocations */
1938 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1940 #ifdef TC_RELOC_MANGLE
1941 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1946 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1948 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1950 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1952 #ifdef TC_KEEP_FX_OFFSET
1953 intr
.r_offset
= fix_ptr
->fx_offset
;
1958 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1959 && (! S_IS_DEFINED (symbol_ptr
)
1960 || S_IS_COMMON (symbol_ptr
)))
1964 /* We must avoid looping, as that can occur
1965 with a badly written program. */
1966 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1967 if (n
== symbol_ptr
)
1972 /* Turn the segment of the symbol into an offset. */
1975 resolve_symbol_value (symbol_ptr
, finalize_syms
);
1976 if (! symbol_ptr
->sy_resolved
)
1981 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1982 as_bad_where (file
, line
,
1983 _("unresolved relocation"));
1985 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1986 S_GET_NAME (symbol_ptr
));
1988 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1991 intr
.r_symndx
= dot
->sy_number
;
1995 intr
.r_symndx
= symbol_ptr
->sy_number
;
2005 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2008 #if defined(TC_A29K)
2010 /* The 29k has a special kludge for the high 16 bit
2011 reloc. Two relocations are emited, R_IHIHALF,
2012 and R_IHCONST. The second one doesn't contain a
2013 symbol, but uses the value for offset. */
2015 if (intr
.r_type
== R_IHIHALF
)
2017 /* now emit the second bit */
2018 intr
.r_type
= R_IHCONST
;
2019 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2020 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2026 fix_ptr
= fix_ptr
->fx_next
;
2030 /* Sort the reloc table */
2031 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2032 sizeof (struct external_reloc
), compare_external_relocs
);
2035 /* Write out the reloc table */
2036 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
2038 free (external_reloc_vec
);
2040 /* Fill in section header info. */
2041 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2042 *file_cursor
+= external_reloc_size
;
2043 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2048 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2052 /* Set relocation_size field in file headers */
2053 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2056 /* run through a frag chain and write out the data to go with it, fill
2057 in the scnhdrs with the info on the file postions
2060 fill_section (abfd
, h
, file_cursor
)
2062 object_headers
*h ATTRIBUTE_UNUSED
;
2063 unsigned long *file_cursor
;
2067 unsigned int paddr
= 0;
2069 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2071 unsigned int offset
= 0;
2072 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2078 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2085 buffer
= xmalloc (s
->s_size
);
2086 s
->s_scnptr
= *file_cursor
;
2088 know (s
->s_paddr
== paddr
);
2090 if (strcmp (s
->s_name
, ".text") == 0)
2091 s
->s_flags
|= STYP_TEXT
;
2092 else if (strcmp (s
->s_name
, ".data") == 0)
2093 s
->s_flags
|= STYP_DATA
;
2094 else if (strcmp (s
->s_name
, ".bss") == 0)
2097 s
->s_flags
|= STYP_BSS
;
2099 /* @@ Should make the i386 and a29k coff targets define
2100 COFF_NOLOAD_PROBLEM, and have only one test here. */
2103 #ifndef COFF_NOLOAD_PROBLEM
2104 /* Apparently the SVR3 linker (and exec syscall) and UDI
2105 mondfe progrem are confused by noload sections. */
2106 s
->s_flags
|= STYP_NOLOAD
;
2111 else if (strcmp (s
->s_name
, ".lit") == 0)
2112 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2113 else if (strcmp (s
->s_name
, ".init") == 0)
2114 s
->s_flags
|= STYP_TEXT
;
2115 else if (strcmp (s
->s_name
, ".fini") == 0)
2116 s
->s_flags
|= STYP_TEXT
;
2117 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2118 s
->s_flags
|= STYP_INFO
;
2122 unsigned int fill_size
;
2123 switch (frag
->fr_type
)
2125 case rs_machine_dependent
:
2128 memcpy (buffer
+ frag
->fr_address
,
2130 (unsigned int) frag
->fr_fix
);
2131 offset
+= frag
->fr_fix
;
2136 assert (frag
->fr_symbol
== 0);
2144 memcpy (buffer
+ frag
->fr_address
,
2146 (unsigned int) frag
->fr_fix
);
2147 offset
+= frag
->fr_fix
;
2150 fill_size
= frag
->fr_var
;
2151 if (fill_size
&& frag
->fr_offset
> 0)
2154 unsigned int off
= frag
->fr_fix
;
2155 for (count
= frag
->fr_offset
; count
; count
--)
2157 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2159 memcpy (buffer
+ frag
->fr_address
+ off
,
2160 frag
->fr_literal
+ frag
->fr_fix
,
2163 offset
+= fill_size
;
2168 case rs_broken_word
:
2173 frag
= frag
->fr_next
;
2178 if (s
->s_scnptr
!= 0)
2180 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2181 *file_cursor
+= s
->s_size
;
2190 /* Coff file generation & utilities */
2193 coff_header_append (abfd
, h
)
2200 #ifdef COFF_LONG_SECTION_NAMES
2201 unsigned long string_size
= 4;
2204 bfd_seek (abfd
, 0, 0);
2206 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2207 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2208 H_SET_VERSION_STAMP (h
, 0);
2209 H_SET_ENTRY_POINT (h
, 0);
2210 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2211 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2212 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2214 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2215 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2216 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2218 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2220 bfd_write (buffer
, i
, 1, abfd
);
2221 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2223 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2225 if (segment_info
[i
].scnhdr
.s_name
[0])
2229 #ifdef COFF_LONG_SECTION_NAMES
2230 /* Support long section names as found in PE. This code
2231 must coordinate with that in write_object_file and
2233 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2235 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2236 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2237 string_size
+= strlen (segment_info
[i
].name
) + 1;
2241 size
= bfd_coff_swap_scnhdr_out (abfd
,
2242 &(segment_info
[i
].scnhdr
),
2245 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2246 bfd_write (buffer
, size
, 1, abfd
);
2252 symbol_to_chars (abfd
, where
, symbolP
)
2257 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2261 /* Turn any symbols with register attributes into abs symbols */
2262 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2264 S_SET_SEGMENT (symbolP
, absolute_section
);
2266 /* At the same time, relocate all symbols to their output value */
2269 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2270 + S_GET_VALUE (symbolP
));
2272 val
= S_GET_VALUE (symbolP
);
2275 S_SET_VALUE (symbolP
, val
);
2277 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2279 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2282 for (i
= 0; i
< numaux
; i
++)
2284 where
+= bfd_coff_swap_aux_out (abfd
,
2285 &symbolP
->sy_symbol
.ost_auxent
[i
],
2286 S_GET_DATA_TYPE (symbolP
),
2287 S_GET_STORAGE_CLASS (symbolP
),
2295 coff_obj_symbol_new_hook (symbolP
)
2298 char underscore
= 0; /* Symbol has leading _ */
2300 /* Effective symbol */
2301 /* Store the pointer in the offset. */
2302 S_SET_ZEROES (symbolP
, 0L);
2303 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2304 S_SET_STORAGE_CLASS (symbolP
, 0);
2305 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2306 /* Additional information */
2307 symbolP
->sy_symbol
.ost_flags
= 0;
2308 /* Auxiliary entries */
2309 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2311 if (S_IS_STRING (symbolP
))
2312 SF_SET_STRING (symbolP
);
2313 if (!underscore
&& S_IS_LOCAL (symbolP
))
2314 SF_SET_LOCAL (symbolP
);
2318 * Handle .ln directives.
2322 obj_coff_ln (appline
)
2327 if (! appline
&& def_symbol_in_progress
!= NULL
)
2329 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2330 demand_empty_rest_of_line ();
2332 } /* wrong context */
2334 l
= get_absolute_expression ();
2335 c_line_new (0, frag_now_fix (), l
, frag_now
);
2338 new_logical_line ((char *) NULL
, l
- 1);
2348 listing_source_line ((unsigned int) l
);
2353 demand_empty_rest_of_line ();
2359 * Handle .def directives.
2361 * One might ask : why can't we symbol_new if the symbol does not
2362 * already exist and fill it with debug information. Because of
2363 * the C_EFCN special symbol. It would clobber the value of the
2364 * function symbol before we have a chance to notice that it is
2365 * a C_EFCN. And a second reason is that the code is more clear this
2366 * way. (at least I think it is :-).
2370 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2371 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2372 *input_line_pointer == '\t') \
2373 input_line_pointer++;
2377 int what ATTRIBUTE_UNUSED
;
2379 char name_end
; /* Char after the end of name */
2380 char *symbol_name
; /* Name of the debug symbol */
2381 char *symbol_name_copy
; /* Temporary copy of the name */
2382 unsigned int symbol_name_length
;
2384 if (def_symbol_in_progress
!= NULL
)
2386 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2387 demand_empty_rest_of_line ();
2389 } /* if not inside .def/.endef */
2391 SKIP_WHITESPACES ();
2393 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2394 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2396 symbol_name
= input_line_pointer
;
2397 name_end
= get_symbol_end ();
2398 symbol_name_length
= strlen (symbol_name
);
2399 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2400 strcpy (symbol_name_copy
, symbol_name
);
2401 #ifdef tc_canonicalize_symbol_name
2402 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2405 /* Initialize the new symbol */
2406 #ifdef STRIP_UNDERSCORE
2407 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2408 ? symbol_name_copy
+ 1
2409 : symbol_name_copy
));
2410 #else /* STRIP_UNDERSCORE */
2411 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2412 #endif /* STRIP_UNDERSCORE */
2413 /* free(symbol_name_copy); */
2414 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2415 def_symbol_in_progress
->sy_number
= ~0;
2416 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2417 S_SET_VALUE (def_symbol_in_progress
, 0);
2419 if (S_IS_STRING (def_symbol_in_progress
))
2420 SF_SET_STRING (def_symbol_in_progress
);
2422 *input_line_pointer
= name_end
;
2424 demand_empty_rest_of_line ();
2427 unsigned int dim_index
;
2430 obj_coff_endef (ignore
)
2431 int ignore ATTRIBUTE_UNUSED
;
2433 symbolS
*symbolP
= 0;
2434 /* DIM BUG FIX sac@cygnus.com */
2436 if (def_symbol_in_progress
== NULL
)
2438 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2439 demand_empty_rest_of_line ();
2441 } /* if not inside .def/.endef */
2443 /* Set the section number according to storage class. */
2444 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2449 SF_SET_TAG (def_symbol_in_progress
);
2450 /* intentional fallthrough */
2453 SF_SET_DEBUG (def_symbol_in_progress
);
2454 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2458 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2459 /* intentional fallthrough */
2461 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2462 /* intentional fallthrough */
2464 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2466 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2468 if (function_lineoff
< 0)
2470 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2471 } /* missing function symbol */
2472 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2474 SF_SET_PROCESS (last_line_symbol
);
2475 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2476 SF_SET_PROCESS (def_symbol_in_progress
);
2477 function_lineoff
= -1;
2479 /* Value is always set to . */
2480 def_symbol_in_progress
->sy_frag
= frag_now
;
2481 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2486 #endif /* C_AUTOARG */
2496 SF_SET_DEBUG (def_symbol_in_progress
);
2497 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2507 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2513 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2515 } /* switch on storage class */
2517 /* Now that we have built a debug symbol, try to find if we should
2518 merge with an existing symbol or not. If a symbol is C_EFCN or
2519 absolute_section or untagged SEG_DEBUG it never merges. We also
2520 don't merge labels, which are in a different namespace, nor
2521 symbols which have not yet been defined since they are typically
2522 unique, nor do we merge tags with non-tags. */
2524 /* Two cases for functions. Either debug followed by definition or
2525 definition followed by debug. For definition first, we will
2526 merge the debug symbol into the definition. For debug first, the
2527 lineno entry MUST point to the definition function or else it
2528 will point off into space when crawl_symbols() merges the debug
2529 symbol into the real symbol. Therefor, let's presume the debug
2530 symbol is a real function reference. */
2532 /* FIXME-SOON If for some reason the definition label/symbol is
2533 never seen, this will probably leave an undefined symbol at link
2536 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2537 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2538 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2539 && !SF_GET_TAG (def_symbol_in_progress
))
2540 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2541 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2542 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2543 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2545 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2550 /* This symbol already exists, merge the newly created symbol
2551 into the old one. This is not mandatory. The linker can
2552 handle duplicate symbols correctly. But I guess that it save
2553 a *lot* of space if the assembly file defines a lot of
2556 /* The debug entry (def_symbol_in_progress) is merged into the
2557 previous definition. */
2559 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2560 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2561 def_symbol_in_progress
= symbolP
;
2563 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2564 || SF_GET_TAG (def_symbol_in_progress
)
2565 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2567 /* For functions, and tags, and static symbols, the symbol
2568 *must* be where the debug symbol appears. Move the
2569 existing symbol to the current place. */
2570 /* If it already is at the end of the symbol list, do nothing */
2571 if (def_symbol_in_progress
!= symbol_lastP
)
2573 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2575 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2576 &symbol_rootP
, &symbol_lastP
);
2577 } /* if not already in place */
2579 } /* normal or mergable */
2581 if (SF_GET_TAG (def_symbol_in_progress
))
2585 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2587 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2588 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2589 def_symbol_in_progress
);
2592 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2594 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2596 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2598 SF_SET_PROCESS (def_symbol_in_progress
);
2600 if (symbolP
== NULL
)
2602 /* That is, if this is the first time we've seen the
2604 symbol_table_insert (def_symbol_in_progress
);
2605 } /* definition follows debug */
2606 } /* Create the line number entry pointing to the function being defined */
2608 def_symbol_in_progress
= NULL
;
2609 demand_empty_rest_of_line ();
2613 obj_coff_dim (ignore
)
2614 int ignore ATTRIBUTE_UNUSED
;
2618 if (def_symbol_in_progress
== NULL
)
2620 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2621 demand_empty_rest_of_line ();
2623 } /* if not inside .def/.endef */
2625 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2627 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2629 SKIP_WHITESPACES ();
2630 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2631 get_absolute_expression ());
2633 switch (*input_line_pointer
)
2636 input_line_pointer
++;
2640 as_warn (_("badly formed .dim directive ignored"));
2641 /* intentional fallthrough */
2649 demand_empty_rest_of_line ();
2653 obj_coff_line (ignore
)
2654 int ignore ATTRIBUTE_UNUSED
;
2659 if (def_symbol_in_progress
== NULL
)
2665 name
= S_GET_NAME (def_symbol_in_progress
);
2666 this_base
= get_absolute_expression ();
2668 /* Only .bf symbols indicate the use of a new base line number; the
2669 line numbers associated with .ef, .bb, .eb are relative to the
2670 start of the containing function. */
2671 if (!strcmp (".bf", name
))
2673 #if 0 /* XXX Can we ever have line numbers going backwards? */
2674 if (this_base
> line_base
)
2677 line_base
= this_base
;
2685 listing_source_line ((unsigned int) line_base
);
2691 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2692 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2694 demand_empty_rest_of_line ();
2698 obj_coff_size (ignore
)
2699 int ignore ATTRIBUTE_UNUSED
;
2701 if (def_symbol_in_progress
== NULL
)
2703 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2704 demand_empty_rest_of_line ();
2706 } /* if not inside .def/.endef */
2708 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2709 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2710 demand_empty_rest_of_line ();
2714 obj_coff_scl (ignore
)
2715 int ignore ATTRIBUTE_UNUSED
;
2717 if (def_symbol_in_progress
== NULL
)
2719 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2720 demand_empty_rest_of_line ();
2722 } /* if not inside .def/.endef */
2724 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2725 demand_empty_rest_of_line ();
2729 obj_coff_tag (ignore
)
2730 int ignore ATTRIBUTE_UNUSED
;
2735 if (def_symbol_in_progress
== NULL
)
2737 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2738 demand_empty_rest_of_line ();
2742 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2743 symbol_name
= input_line_pointer
;
2744 name_end
= get_symbol_end ();
2745 #ifdef tc_canonicalize_symbol_name
2746 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2749 /* Assume that the symbol referred to by .tag is always defined.
2750 This was a bad assumption. I've added find_or_make. xoxorich. */
2751 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2752 (long) tag_find_or_make (symbol_name
));
2753 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2755 as_warn (_("tag not found for .tag %s"), symbol_name
);
2758 SF_SET_TAGGED (def_symbol_in_progress
);
2759 *input_line_pointer
= name_end
;
2761 demand_empty_rest_of_line ();
2765 obj_coff_type (ignore
)
2766 int ignore ATTRIBUTE_UNUSED
;
2768 if (def_symbol_in_progress
== NULL
)
2770 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2771 demand_empty_rest_of_line ();
2773 } /* if not inside .def/.endef */
2775 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2777 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2778 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2780 SF_SET_FUNCTION (def_symbol_in_progress
);
2781 } /* is a function */
2783 demand_empty_rest_of_line ();
2787 obj_coff_val (ignore
)
2788 int ignore ATTRIBUTE_UNUSED
;
2790 if (def_symbol_in_progress
== NULL
)
2792 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2793 demand_empty_rest_of_line ();
2795 } /* if not inside .def/.endef */
2797 if (is_name_beginner (*input_line_pointer
))
2799 char *symbol_name
= input_line_pointer
;
2800 char name_end
= get_symbol_end ();
2802 #ifdef tc_canonicalize_symbol_name
2803 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2806 if (!strcmp (symbol_name
, "."))
2808 def_symbol_in_progress
->sy_frag
= frag_now
;
2809 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2810 /* If the .val is != from the .def (e.g. statics) */
2812 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2814 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2815 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2816 symbol_find_or_make (symbol_name
);
2817 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2818 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2820 /* If the segment is undefined when the forward reference is
2821 resolved, then copy the segment id from the forward
2823 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2825 /* FIXME: gcc can generate address expressions here in
2826 unusual cases (search for "obscure" in sdbout.c). We
2827 just ignore the offset here, thus generating incorrect
2828 debugging information. We ignore the rest of the line
2831 /* Otherwise, it is the name of a non debug symbol and
2832 its value will be calculated later. */
2833 *input_line_pointer
= name_end
;
2835 /* FIXME: this is to avoid an error message in the
2836 FIXME case mentioned just above. */
2837 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2838 ++input_line_pointer
;
2842 S_SET_VALUE (def_symbol_in_progress
,
2843 (valueT
) get_absolute_expression ());
2844 } /* if symbol based */
2846 demand_empty_rest_of_line ();
2851 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2852 read.c, which then calls this object file format specific routine. */
2855 obj_coff_pe_handle_link_once (type
)
2856 enum linkonce_type type
;
2858 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2860 /* We store the type in the seg_info structure, and use it to set up
2861 the auxiliary entry for the section symbol in c_section_symbol. */
2862 seg_info (now_seg
)->linkonce
= type
;
2868 coff_obj_read_begin_hook ()
2870 /* These had better be the same. Usually 18 bytes. */
2872 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2873 know (SYMESZ
== AUXESZ
);
2878 /* This function runs through the symbol table and puts all the
2879 externals onto another chain */
2881 /* The chain of globals. */
2882 symbolS
*symbol_globalP
;
2883 symbolS
*symbol_global_lastP
;
2885 /* The chain of externals */
2886 symbolS
*symbol_externP
;
2887 symbolS
*symbol_extern_lastP
;
2890 symbolS
*last_functionP
;
2891 static symbolS
*last_bfP
;
2898 unsigned int symbol_number
= 0;
2899 unsigned int last_file_symno
= 0;
2901 struct filename_list
*filename_list_scan
= filename_list_head
;
2903 for (symbolP
= symbol_rootP
;
2905 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2907 if (symbolP
->sy_mri_common
)
2909 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2911 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2913 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2914 as_bad (_("%s: global symbols not supported in common sections"),
2915 S_GET_NAME (symbolP
));
2916 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2920 if (!SF_GET_DEBUG (symbolP
))
2922 /* Debug symbols do not need all this rubbish */
2923 symbolS
*real_symbolP
;
2925 /* L* and C_EFCN symbols never merge. */
2926 if (!SF_GET_LOCAL (symbolP
)
2927 && !SF_GET_STATICS (symbolP
)
2928 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2929 && symbolP
->sy_value
.X_op
== O_constant
2930 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2931 && real_symbolP
!= symbolP
)
2933 /* FIXME-SOON: where do dups come from?
2934 Maybe tag references before definitions? xoxorich. */
2935 /* Move the debug data from the debug symbol to the
2936 real symbol. Do NOT do the oposite (i.e. move from
2937 real symbol to debug symbol and remove real symbol from the
2938 list.) Because some pointers refer to the real symbol
2939 whereas no pointers refer to the debug symbol. */
2940 c_symbol_merge (symbolP
, real_symbolP
);
2941 /* Replace the current symbol by the real one */
2942 /* The symbols will never be the last or the first
2943 because : 1st symbol is .file and 3 last symbols are
2944 .text, .data, .bss */
2945 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2946 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2947 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2948 symbolP
= real_symbolP
;
2949 } /* if not local but dup'd */
2951 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2953 S_SET_SEGMENT (symbolP
, SEG_E0
);
2954 } /* push data into text */
2956 resolve_symbol_value (symbolP
, finalize_syms
);
2958 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2960 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2962 S_SET_EXTERNAL (symbolP
);
2964 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2966 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2970 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2974 /* Mainly to speed up if not -g */
2975 if (SF_GET_PROCESS (symbolP
))
2977 /* Handle the nested blocks auxiliary info. */
2978 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2980 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2981 stack_push (block_stack
, (char *) &symbolP
);
2984 register symbolS
*begin_symbolP
;
2985 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2986 if (begin_symbolP
== (symbolS
*) 0)
2987 as_warn (_("mismatched .eb"));
2989 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2992 /* If we are able to identify the type of a function, and we
2993 are out of a function (last_functionP == 0) then, the
2994 function symbol will be associated with an auxiliary
2996 if (last_functionP
== (symbolS
*) 0 &&
2997 SF_GET_FUNCTION (symbolP
))
2999 last_functionP
= symbolP
;
3001 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3003 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3004 } /* make it at least 1 */
3006 /* Clobber possible stale .dim information. */
3008 /* Iffed out by steve - this fries the lnnoptr info too */
3009 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3010 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3013 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3015 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3017 if (last_bfP
!= NULL
)
3018 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3022 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3024 /* I don't even know if this is needed for sdb. But
3025 the standard assembler generates it, so... */
3026 if (last_functionP
== (symbolS
*) 0)
3027 as_fatal (_("C_EFCN symbol out of scope"));
3028 SA_SET_SYM_FSIZE (last_functionP
,
3029 (long) (S_GET_VALUE (symbolP
) -
3030 S_GET_VALUE (last_functionP
)));
3031 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3032 last_functionP
= (symbolS
*) 0;
3036 else if (SF_GET_TAG (symbolP
))
3038 /* First descriptor of a structure must point to
3039 the first slot after the structure description. */
3040 last_tagP
= symbolP
;
3043 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3045 /* +2 take in account the current symbol */
3046 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3048 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3050 /* If the filename was too long to fit in the
3051 auxent, put it in the string table */
3052 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3053 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3055 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3056 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3057 filename_list_scan
= filename_list_scan
->next
;
3059 if (S_GET_VALUE (symbolP
))
3061 S_SET_VALUE (symbolP
, last_file_symno
);
3062 last_file_symno
= symbol_number
;
3063 } /* no one points at the first .file symbol */
3064 } /* if debug or tag or eos or file */
3066 #ifdef tc_frob_coff_symbol
3067 tc_frob_coff_symbol (symbolP
);
3070 /* We must put the external symbols apart. The loader
3071 does not bomb if we do not. But the references in
3072 the endndx field for a .bb symbol are not corrected
3073 if an external symbol is removed between .bb and .be.
3074 I.e in the following case :
3075 [20] .bb endndx = 22
3078 ld will move the symbol 21 to the end of the list but
3079 endndx will still be 22 instead of 21. */
3081 if (SF_GET_LOCAL (symbolP
))
3083 /* remove C_EFCN and LOCAL (L...) symbols */
3084 /* next pointer remains valid */
3085 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3088 else if (symbolP
->sy_value
.X_op
== O_symbol
3089 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3091 /* Skip symbols which were equated to undefined or common
3093 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3095 else if (!S_IS_DEFINED (symbolP
)
3096 && !S_IS_DEBUG (symbolP
)
3097 && !SF_GET_STATICS (symbolP
)
3098 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3100 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3102 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3104 /* if external, Remove from the list */
3105 symbolS
*hold
= symbol_previous (symbolP
);
3107 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3108 symbol_clear_list_pointers (symbolP
);
3109 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3112 else if (! S_IS_DEBUG (symbolP
)
3113 && ! SF_GET_STATICS (symbolP
)
3114 && ! SF_GET_FUNCTION (symbolP
)
3115 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3117 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3119 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3121 symbolS
*hold
= symbol_previous (symbolP
);
3123 /* The O'Reilly COFF book says that defined global symbols
3124 come at the end of the symbol table, just before
3125 undefined global symbols. */
3127 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3128 symbol_clear_list_pointers (symbolP
);
3129 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3130 &symbol_global_lastP
);
3135 if (SF_GET_STRING (symbolP
))
3137 symbolP
->sy_name_offset
= string_byte_count
;
3138 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3142 symbolP
->sy_name_offset
= 0;
3143 } /* fix "long" names */
3145 symbolP
->sy_number
= symbol_number
;
3146 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3147 } /* if local symbol */
3148 } /* traverse the symbol list */
3149 return symbol_number
;
3154 glue_symbols (head
, tail
)
3158 unsigned int symbol_number
= 0;
3160 while (*head
!= NULL
)
3162 symbolS
*tmp
= *head
;
3165 symbol_remove (tmp
, head
, tail
);
3166 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3169 if (SF_GET_STRING (tmp
))
3171 tmp
->sy_name_offset
= string_byte_count
;
3172 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3176 tmp
->sy_name_offset
= 0;
3177 } /* fix "long" names */
3179 tmp
->sy_number
= symbol_number
;
3180 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3181 } /* append the entire extern chain */
3183 return symbol_number
;
3189 unsigned int symbol_number
= 0;
3192 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3194 symbolP
->sy_number
= symbol_number
;
3196 if (SF_GET_TAGGED (symbolP
))
3200 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3203 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3206 return symbol_number
;
3210 crawl_symbols (h
, abfd
)
3212 bfd
*abfd ATTRIBUTE_UNUSED
;
3216 /* Initialize the stack used to keep track of the matching .bb .be */
3218 block_stack
= stack_init (512, sizeof (symbolS
*));
3220 /* The symbol list should be ordered according to the following sequence
3223 * . debug entries for functions
3224 * . fake symbols for the sections, including .text .data and .bss
3226 * . undefined symbols
3227 * But this is not mandatory. The only important point is to put the
3228 * undefined symbols at the end of the list.
3231 /* Is there a .file symbol ? If not insert one at the beginning. */
3232 if (symbol_rootP
== NULL
3233 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3235 c_dot_file_symbol ("fake");
3239 * Build up static symbols for the sections, they are filled in later
3242 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3243 if (segment_info
[i
].scnhdr
.s_name
[0])
3244 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3247 /* Take all the externals out and put them into another chain */
3248 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3249 /* Take the externals and glue them onto the end.*/
3250 H_SET_SYMBOL_TABLE_SIZE (h
,
3251 (H_GET_SYMBOL_COUNT (h
)
3252 + glue_symbols (&symbol_globalP
,
3253 &symbol_global_lastP
)
3254 + glue_symbols (&symbol_externP
,
3255 &symbol_extern_lastP
)));
3257 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3258 know (symbol_globalP
== NULL
);
3259 know (symbol_global_lastP
== NULL
);
3260 know (symbol_externP
== NULL
);
3261 know (symbol_extern_lastP
== NULL
);
3265 * Find strings by crawling along symbol table chain.
3273 struct filename_list
*filename_list_scan
= filename_list_head
;
3275 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3276 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3279 #ifdef COFF_LONG_SECTION_NAMES
3280 /* Support long section names as found in PE. This code must
3281 coordinate with that in coff_header_append and write_object_file. */
3285 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3287 if (segment_info
[i
].scnhdr
.s_name
[0]
3288 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3292 size
= strlen (segment_info
[i
].name
) + 1;
3293 memcpy (where
, segment_info
[i
].name
, size
);
3298 #endif /* COFF_LONG_SECTION_NAMES */
3300 for (symbolP
= symbol_rootP
;
3302 symbolP
= symbol_next (symbolP
))
3306 if (SF_GET_STRING (symbolP
))
3308 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3309 memcpy (where
, S_GET_NAME (symbolP
), size
);
3312 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3313 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3314 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3316 size
= strlen (filename_list_scan
->filename
) + 1;
3317 memcpy (where
, filename_list_scan
->filename
, size
);
3318 filename_list_scan
= filename_list_scan
->next
;
3325 do_linenos_for (abfd
, h
, file_cursor
)
3328 unsigned long *file_cursor
;
3331 unsigned long start
= *file_cursor
;
3333 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3335 segment_info_type
*s
= segment_info
+ idx
;
3337 if (s
->scnhdr
.s_nlnno
!= 0)
3339 struct lineno_list
*line_ptr
;
3341 struct external_lineno
*buffer
=
3342 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3344 struct external_lineno
*dst
= buffer
;
3346 /* Run through the table we've built and turn it into its external
3347 form, take this chance to remove duplicates */
3349 for (line_ptr
= s
->lineno_list_head
;
3350 line_ptr
!= (struct lineno_list
*) NULL
;
3351 line_ptr
= line_ptr
->next
)
3354 if (line_ptr
->line
.l_lnno
== 0)
3356 /* Turn a pointer to a symbol into the symbols' index */
3357 line_ptr
->line
.l_addr
.l_symndx
=
3358 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3362 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3365 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3370 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3372 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3375 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3378 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3381 /* Now we run through the list of frag chains in a segment and
3382 make all the subsegment frags appear at the end of the
3383 list, as if the seg 0 was extra long */
3390 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3392 frchainS
*head
= segment_info
[i
].frchainP
;
3394 fragS
*prev_frag
= &dummy
;
3396 while (head
&& head
->frch_seg
== i
)
3398 prev_frag
->fr_next
= head
->frch_root
;
3399 prev_frag
= head
->frch_last
;
3400 head
= head
->frch_next
;
3402 prev_frag
->fr_next
= 0;
3406 unsigned long machine
;
3409 write_object_file ()
3413 struct frchain
*frchain_ptr
;
3415 object_headers headers
;
3416 unsigned long file_cursor
;
3419 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3423 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3424 exit (EXIT_FAILURE
);
3426 bfd_set_format (abfd
, bfd_object
);
3427 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3429 string_byte_count
= 4;
3431 for (frchain_ptr
= frchain_root
;
3432 frchain_ptr
!= (struct frchain
*) NULL
;
3433 frchain_ptr
= frchain_ptr
->frch_next
)
3435 /* Run through all the sub-segments and align them up. Also
3436 close any open frags. We tack a .fill onto the end of the
3437 frag chain so that any .align's size can be worked by looking
3438 at the next frag. */
3440 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3442 #ifndef SUB_SEGMENT_ALIGN
3443 #define SUB_SEGMENT_ALIGN(SEG) 1
3446 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3449 if (subseg_text_p (now_seg
))
3450 frag_align_code (SUB_SEGMENT_ALIGN (now_seg
), 0);
3452 frag_align (SUB_SEGMENT_ALIGN (now_seg
), 0, 0);
3458 frag_wane (frag_now
);
3459 frag_now
->fr_fix
= 0;
3460 know (frag_now
->fr_next
== NULL
);
3465 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3467 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3470 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3472 /* Find out how big the sections are, and set the addresses. */
3474 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3478 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3479 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3481 if (segment_info
[i
].scnhdr
.s_name
[0])
3483 H_SET_NUMBER_OF_SECTIONS (&headers
,
3484 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3486 #ifdef COFF_LONG_SECTION_NAMES
3487 /* Support long section names as found in PE. This code
3488 must coordinate with that in coff_header_append and
3493 len
= strlen (segment_info
[i
].name
);
3495 string_byte_count
+= len
+ 1;
3497 #endif /* COFF_LONG_SECTION_NAMES */
3500 size
= size_section (abfd
, (unsigned int) i
);
3503 /* I think the section alignment is only used on the i960; the
3504 i960 needs it, and it should do no harm on other targets. */
3505 #ifdef ALIGNMENT_IN_S_FLAGS
3506 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3508 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3512 H_SET_TEXT_SIZE (&headers
, size
);
3513 else if (i
== SEG_E1
)
3514 H_SET_DATA_SIZE (&headers
, size
);
3515 else if (i
== SEG_E2
)
3516 H_SET_BSS_SIZE (&headers
, size
);
3519 /* Turn the gas native symbol table shape into a coff symbol table */
3520 crawl_symbols (&headers
, abfd
);
3522 if (string_byte_count
== 4)
3523 string_byte_count
= 0;
3525 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3531 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3533 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3534 fixup_segment (&segment_info
[i
], i
);
3537 /* Look for ".stab" segments and fill in their initial symbols
3539 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3541 name
= segment_info
[i
].name
;
3544 && strncmp (".stab", name
, 5) == 0
3545 && strncmp (".stabstr", name
, 8) != 0)
3546 adjust_stab_section (abfd
, i
);
3549 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3551 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3553 /* Plant the data */
3555 fill_section (abfd
, &headers
, &file_cursor
);
3557 do_relocs_for (abfd
, &headers
, &file_cursor
);
3559 do_linenos_for (abfd
, &headers
, &file_cursor
);
3561 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3562 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3563 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3565 H_SET_TIME_STAMP (&headers
, 0);
3567 #ifdef TC_COFF_SET_MACHINE
3568 TC_COFF_SET_MACHINE (&headers
);
3572 #define COFF_FLAGS 0
3575 #ifdef KEEP_RELOC_INFO
3576 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3577 COFF_FLAGS
| coff_flags
));
3579 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3580 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3581 COFF_FLAGS
| coff_flags
));
3585 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3586 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3588 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3589 w_symbols (abfd
, buffer1
, symbol_rootP
);
3590 if (string_byte_count
> 0)
3591 w_strings (buffer1
+ symtable_size
);
3592 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3596 coff_header_append (abfd
, &headers
);
3598 /* Recent changes to write need this, but where it should
3599 go is up to Ken.. */
3600 if (bfd_close_all_done (abfd
) == false)
3601 as_fatal (_("Can't close %s: %s"), out_file_name
,
3602 bfd_errmsg (bfd_get_error ()));
3605 extern bfd
*stdoutput
;
3612 /* Add a new segment. This is called from subseg_new via the
3613 obj_new_segment macro. */
3616 obj_coff_add_segment (name
)
3621 #ifndef COFF_LONG_SECTION_NAMES
3622 char buf
[SCNNMLEN
+ 1];
3624 strncpy (buf
, name
, SCNNMLEN
);
3625 buf
[SCNNMLEN
] = '\0';
3629 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3630 if (strcmp (name
, segment_info
[i
].name
) == 0)
3635 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3639 /* Add a new section. */
3640 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3641 sizeof (segment_info
[i
].scnhdr
.s_name
));
3642 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3643 segment_info
[i
].name
= xstrdup (name
);
3649 * implement the .section pseudo op:
3650 * .section name {, "flags"}
3652 * | +--- optional flags: 'b' for bss
3654 * +-- section name 'l' for lib
3658 * 'd' (apparently m88k for data)
3660 * 'r' for read-only data
3661 * But if the argument is not a quoted string, treat it as a
3662 * subsegment number.
3666 obj_coff_section (ignore
)
3667 int ignore ATTRIBUTE_UNUSED
;
3669 /* Strip out the section name */
3670 char *section_name
, *name
;
3683 else if (type
== 'D')
3685 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3690 section_name
= input_line_pointer
;
3691 c
= get_symbol_end ();
3693 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3694 strcpy (name
, section_name
);
3696 *input_line_pointer
= c
;
3702 if (*input_line_pointer
== ',')
3704 ++input_line_pointer
;
3707 if (*input_line_pointer
!= '"')
3708 exp
= get_absolute_expression ();
3711 ++input_line_pointer
;
3712 while (*input_line_pointer
!= '"'
3713 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3715 switch (*input_line_pointer
)
3717 case 'b': flags
|= STYP_BSS
; break;
3718 case 'i': flags
|= STYP_INFO
; break;
3719 case 'l': flags
|= STYP_LIB
; break;
3720 case 'n': flags
|= STYP_NOLOAD
; break;
3721 case 'o': flags
|= STYP_OVER
; break;
3723 case 'w': flags
|= STYP_DATA
; break;
3724 case 'x': flags
|= STYP_TEXT
; break;
3725 case 'r': flags
|= STYP_LIT
; break;
3727 as_warn(_("unknown section attribute '%c'"),
3728 *input_line_pointer
);
3731 ++input_line_pointer
;
3733 if (*input_line_pointer
== '"')
3734 ++input_line_pointer
;
3738 subseg_new (name
, (subsegT
) exp
);
3740 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3742 demand_empty_rest_of_line ();
3746 obj_coff_text (ignore
)
3747 int ignore ATTRIBUTE_UNUSED
;
3749 subseg_new (".text", get_absolute_expression ());
3753 obj_coff_data (ignore
)
3754 int ignore ATTRIBUTE_UNUSED
;
3756 if (flag_readonly_data_in_text
)
3757 subseg_new (".text", get_absolute_expression () + 1000);
3759 subseg_new (".data", get_absolute_expression ());
3763 obj_coff_ident (ignore
)
3764 int ignore ATTRIBUTE_UNUSED
;
3766 segT current_seg
= now_seg
; /* save current seg */
3767 subsegT current_subseg
= now_subseg
;
3768 subseg_new (".comment", 0); /* .comment seg */
3769 stringer (1); /* read string */
3770 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3774 c_symbol_merge (debug
, normal
)
3778 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3779 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3781 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3783 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3784 } /* take the most we have */
3786 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3788 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3789 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3790 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3791 } /* Move all the auxiliary information */
3793 /* Move the debug flags. */
3794 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3795 } /* c_symbol_merge() */
3798 c_line_new (symbol
, paddr
, line_number
, frag
)
3804 struct lineno_list
*new_line
=
3805 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3807 segment_info_type
*s
= segment_info
+ now_seg
;
3808 new_line
->line
.l_lnno
= line_number
;
3810 if (line_number
== 0)
3812 last_line_symbol
= symbol
;
3813 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3817 new_line
->line
.l_addr
.l_paddr
= paddr
;
3820 new_line
->frag
= (char *) frag
;
3821 new_line
->next
= (struct lineno_list
*) NULL
;
3823 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3825 s
->lineno_list_head
= new_line
;
3829 s
->lineno_list_tail
->next
= new_line
;
3831 s
->lineno_list_tail
= new_line
;
3832 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3836 c_dot_file_symbol (filename
)
3841 symbolP
= symbol_new (".file",
3844 &zero_address_frag
);
3846 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3847 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3849 if (strlen (filename
) > FILNMLEN
)
3851 /* Filename is too long to fit into an auxent,
3852 we stick it into the string table instead. We keep
3853 a linked list of the filenames we find so we can emit
3855 struct filename_list
*f
= ((struct filename_list
*)
3856 xmalloc (sizeof (struct filename_list
)));
3858 f
->filename
= filename
;
3861 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3862 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3864 if (filename_list_tail
)
3865 filename_list_tail
->next
= f
;
3867 filename_list_head
= f
;
3868 filename_list_tail
= f
;
3872 SA_SET_FILE_FNAME (symbolP
, filename
);
3879 listing_source_file (filename
);
3885 SF_SET_DEBUG (symbolP
);
3886 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3888 previous_file_symbol
= symbolP
;
3890 /* Make sure that the symbol is first on the symbol chain */
3891 if (symbol_rootP
!= symbolP
)
3893 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3894 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3896 } /* c_dot_file_symbol() */
3899 * Build a 'section static' symbol.
3903 c_section_symbol (name
, idx
)
3909 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3910 if (symbolP
== NULL
)
3911 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3914 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3915 S_SET_SEGMENT (symbolP
, idx
);
3916 symbolP
->sy_frag
= &zero_address_frag
;
3919 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3920 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3922 SF_SET_STATICS (symbolP
);
3925 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3926 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3927 SF_CLEAR_LOCAL (symbolP
);
3930 /* If the .linkonce pseudo-op was used for this section, we must
3931 store the information in the auxiliary entry for the section
3933 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3937 switch (segment_info
[idx
].linkonce
)
3941 case LINKONCE_DISCARD
:
3942 type
= IMAGE_COMDAT_SELECT_ANY
;
3944 case LINKONCE_ONE_ONLY
:
3945 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3947 case LINKONCE_SAME_SIZE
:
3948 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3950 case LINKONCE_SAME_CONTENTS
:
3951 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3955 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3960 } /* c_section_symbol() */
3963 w_symbols (abfd
, where
, symbol_rootP
)
3966 symbolS
* symbol_rootP
;
3971 /* First fill in those values we have only just worked out */
3972 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3974 symbolP
= segment_info
[i
].dot
;
3977 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3978 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3979 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3984 * Emit all symbols left in the symbol chain.
3986 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3988 /* Used to save the offset of the name. It is used to point
3989 to the string in memory but must be a file offset. */
3990 register char *temp
;
3992 /* We can't fix the lnnoptr field in yank_symbols with the other
3993 adjustments, because we have to wait until we know where they
3995 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3997 SA_GET_SYM_LNNOPTR (symbolP
) +=
3998 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4001 tc_coff_symbol_emit_hook (symbolP
);
4003 temp
= S_GET_NAME (symbolP
);
4004 if (SF_GET_STRING (symbolP
))
4006 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4007 S_SET_ZEROES (symbolP
, 0);
4011 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4012 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4014 where
= symbol_to_chars (abfd
, where
, symbolP
);
4015 S_SET_NAME (symbolP
, temp
);
4021 obj_coff_lcomm (ignore
)
4022 int ignore ATTRIBUTE_UNUSED
;
4034 name
= input_line_pointer
;
4036 c
= get_symbol_end ();
4037 p
= input_line_pointer
;
4040 if (*input_line_pointer
!= ',')
4042 as_bad (_("Expected comma after name"));
4043 ignore_rest_of_line ();
4046 if (*input_line_pointer
== '\n')
4048 as_bad (_("Missing size expression"));
4051 input_line_pointer
++;
4052 if ((temp
= get_absolute_expression ()) < 0)
4054 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4055 ignore_rest_of_line ();
4060 symbolP
= symbol_find_or_make (name
);
4062 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
&&
4063 S_GET_VALUE (symbolP
) == 0)
4068 segT current_seg
= now_seg
; /* save current seg */
4069 subsegT current_subseg
= now_subseg
;
4071 subseg_set (SEG_E2
, 1);
4072 symbolP
->sy_frag
= frag_now
;
4073 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4074 (offsetT
) temp
, (char *) 0);
4076 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4077 S_SET_SEGMENT (symbolP
, SEG_E2
);
4078 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4082 as_bad (_("Symbol %s already defined"), name
);
4084 demand_empty_rest_of_line ();
4089 fixup_mdeps (frags
, h
, this_segment
)
4094 subseg_change (this_segment
, 0);
4097 switch (frags
->fr_type
)
4104 HANDLE_ALIGN (frags
);
4106 frags
->fr_type
= rs_fill
;
4108 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4111 case rs_machine_dependent
:
4112 md_convert_frag (h
, this_segment
, frags
);
4118 frags
= frags
->fr_next
;
4124 #ifndef TC_FORCE_RELOCATION
4125 #define TC_FORCE_RELOCATION(fix) 0
4129 fixup_segment (segP
, this_segment_type
)
4130 segment_info_type
* segP
;
4131 segT this_segment_type
;
4133 register fixS
* fixP
;
4134 register symbolS
*add_symbolP
;
4135 register symbolS
*sub_symbolP
;
4138 register char *place
;
4139 register long where
;
4140 register char pcrel
;
4141 register fragS
*fragP
;
4142 register segT add_symbol_segment
= absolute_section
;
4144 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4146 fragP
= fixP
->fx_frag
;
4148 where
= fixP
->fx_where
;
4149 place
= fragP
->fr_literal
+ where
;
4150 size
= fixP
->fx_size
;
4151 add_symbolP
= fixP
->fx_addsy
;
4152 sub_symbolP
= fixP
->fx_subsy
;
4153 add_number
= fixP
->fx_offset
;
4154 pcrel
= fixP
->fx_pcrel
;
4156 /* We want function-relative stabs to work on systems which
4157 may use a relaxing linker; thus we must handle the sym1-sym2
4158 fixups function-relative stabs generates.
4160 Of course, if you actually enable relaxing in the linker, the
4161 line and block scoping information is going to be incorrect
4162 in some cases. The only way to really fix this is to support
4163 a reloc involving the difference of two symbols. */
4165 && (!sub_symbolP
|| pcrel
))
4169 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4171 /* Relocation should be done via the associated 'bal' entry
4174 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4176 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4177 _("No 'bal' entry point for leafproc %s"),
4178 S_GET_NAME (add_symbolP
));
4181 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4185 /* Make sure the symbols have been resolved; this may not have
4186 happened if these are expression symbols. */
4187 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4188 resolve_symbol_value (add_symbolP
, finalize_syms
);
4190 if (add_symbolP
!= NULL
)
4192 /* If this fixup is against a symbol which has been equated
4193 to another symbol, convert it to the other symbol. */
4194 if (add_symbolP
->sy_value
.X_op
== O_symbol
4195 && (! S_IS_DEFINED (add_symbolP
)
4196 || S_IS_COMMON (add_symbolP
)))
4198 while (add_symbolP
->sy_value
.X_op
== O_symbol
4199 && (! S_IS_DEFINED (add_symbolP
)
4200 || S_IS_COMMON (add_symbolP
)))
4204 /* We must avoid looping, as that can occur with a
4205 badly written program. */
4206 n
= add_symbolP
->sy_value
.X_add_symbol
;
4207 if (n
== add_symbolP
)
4209 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4212 fixP
->fx_addsy
= add_symbolP
;
4213 fixP
->fx_offset
= add_number
;
4217 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4218 resolve_symbol_value (sub_symbolP
, finalize_syms
);
4220 if (add_symbolP
!= NULL
4221 && add_symbolP
->sy_mri_common
)
4223 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4224 add_number
+= S_GET_VALUE (add_symbolP
);
4225 fixP
->fx_offset
= add_number
;
4226 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4231 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4232 } /* if there is an addend */
4236 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4238 if (add_symbolP
!= NULL
)
4240 add_number
+= S_GET_VALUE (add_symbolP
);
4242 fixP
->fx_addsy
= NULL
;
4245 /* It's just -sym. */
4246 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4248 add_number
-= S_GET_VALUE (sub_symbolP
);
4255 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4256 _("Negative of non-absolute symbol %s"),
4257 S_GET_NAME (sub_symbolP
));
4259 add_number
-= S_GET_VALUE (sub_symbolP
);
4260 } /* not absolute */
4262 /* if sub_symbol is in the same segment that add_symbol
4263 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4265 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4266 && SEG_NORMAL (add_symbol_segment
))
4268 /* Difference of 2 symbols from same segment. Can't
4269 make difference of 2 undefineds: 'value' means
4270 something different for N_UNDF. */
4272 /* Makes no sense to use the difference of 2 arbitrary symbols
4273 as the target of a call instruction. */
4276 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4277 _("callj to difference of 2 symbols"));
4279 #endif /* TC_I960 */
4280 add_number
+= S_GET_VALUE (add_symbolP
) -
4281 S_GET_VALUE (sub_symbolP
);
4284 if (!TC_FORCE_RELOCATION (fixP
))
4286 fixP
->fx_addsy
= NULL
;
4287 fixP
->fx_subsy
= NULL
;
4289 #ifdef TC_M68K /* is this right? */
4297 /* Different segments in subtraction. */
4298 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4300 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4302 add_number
-= S_GET_VALUE (sub_symbolP
);
4305 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4306 #if 0 /* Okay for 68k, at least... */
4311 /* Make it pc-relative. */
4312 add_number
+= (md_pcrel_from (fixP
)
4313 - S_GET_VALUE (sub_symbolP
));
4322 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4323 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4324 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4325 S_GET_NAME (sub_symbolP
),
4326 (long) (fragP
->fr_address
+ where
));
4329 } /* if sub_symbolP */
4333 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4336 * This fixup was made when the symbol's segment was
4337 * SEG_UNKNOWN, but it is now in the local segment.
4338 * So we know how to do the address without relocation.
4341 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4342 * in which cases it modifies *fixP as appropriate. In the case
4343 * of a 'calls', no further work is required, and *fixP has been
4344 * set up to make the rest of the code below a no-op.
4347 #endif /* TC_I960 */
4349 add_number
+= S_GET_VALUE (add_symbolP
);
4350 add_number
-= md_pcrel_from (fixP
);
4353 add_number -= segP->scnhdr.s_vaddr;
4354 if defined (TC_I386) || defined (TE_LYNX). I now
4355 think that was an error propagated from the case when
4356 we are going to emit the relocation. If we are not
4357 going to emit the relocation, then we just want to
4358 set add_number to the difference between the symbols.
4359 This is a case that would only arise when there is a
4360 PC relative reference from a section other than .text
4361 to a symbol defined in the same section, and the
4362 reference is not relaxed. Since jump instructions on
4363 the i386 are relaxed, this could only arise with a
4364 call instruction. */
4366 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4367 if (!TC_FORCE_RELOCATION (fixP
))
4369 fixP
->fx_addsy
= NULL
;
4375 switch (add_symbol_segment
)
4377 case absolute_section
:
4379 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4380 #endif /* TC_I960 */
4381 add_number
+= S_GET_VALUE (add_symbolP
);
4384 if (!TC_FORCE_RELOCATION (fixP
))
4386 fixP
->fx_addsy
= NULL
;
4392 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4393 /* This really should be handled in the linker, but
4394 backward compatibility forbids. */
4395 add_number
+= S_GET_VALUE (add_symbolP
);
4397 add_number
+= S_GET_VALUE (add_symbolP
) +
4398 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4404 if ((int) fixP
->fx_bit_fixP
== 13)
4406 /* This is a COBR instruction. They have only a
4407 * 13-bit displacement and are only to be used
4408 * for local branches: flag as error, don't generate
4411 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4412 _("can't use COBR format with external label"));
4413 fixP
->fx_addsy
= NULL
;
4417 #endif /* TC_I960 */
4418 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4419 /* 386 COFF uses a peculiar format in which the
4420 value of a common symbol is stored in the .text
4421 segment (I've checked this on SVR3.2 and SCO
4422 3.2.2) Ian Taylor <ian@cygnus.com>. */
4423 /* This is also true for 68k COFF on sysv machines
4424 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4425 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4426 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4427 if (S_IS_COMMON (add_symbolP
))
4428 add_number
+= S_GET_VALUE (add_symbolP
);
4432 } /* switch on symbol seg */
4433 } /* if not in local seg */
4434 } /* if there was a + symbol */
4438 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4439 /* This adjustment is not correct on the m88k, for which the
4440 linker does all the computation. */
4441 add_number
-= md_pcrel_from (fixP
);
4443 if (add_symbolP
== 0)
4445 fixP
->fx_addsy
= &abs_symbol
;
4446 } /* if there's an add_symbol */
4447 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4448 /* On the 386 we must adjust by the segment vaddr as well.
4451 I changed the i960 to work this way as well. This is
4452 compatible with the current GNU linker behaviour. I do
4453 not know what other i960 COFF assemblers do. This is not
4454 a common case: normally, only assembler code will contain
4455 a PC relative reloc, and only branches which do not
4456 originate in the .text section will have a non-zero
4459 I changed the m68k to work this way as well. This will
4460 break existing PC relative relocs from sections which do
4461 not start at address 0, but it will make ld -r work.
4462 Ian Taylor, 4 Oct 96. */
4464 add_number
-= segP
->scnhdr
.s_vaddr
;
4468 #ifdef MD_APPLY_FIX3
4469 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4471 md_apply_fix (fixP
, add_number
);
4474 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4477 /* The m88k uses the offset field of the reloc to get around
4480 && ((add_number
& ~0xFF)
4481 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4482 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4483 || (add_number
& 0x80) == 0))
4485 && ((add_number
& ~0xFFFF)
4486 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4487 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4488 || (add_number
& 0x8000) == 0)))
4490 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4491 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4492 (long) add_number
, size
,
4493 (unsigned long) (fragP
->fr_address
+ where
));
4496 #ifdef WARN_SIGNED_OVERFLOW_WORD
4497 /* Warn if a .word value is too large when treated as a
4498 signed number. We already know it is not too negative.
4499 This is to catch over-large switches generated by gcc on
4501 if (!flag_signed_overflow_ok
4503 && add_number
> 0x7fff)
4504 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4505 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4507 (unsigned long) (fragP
->fr_address
+ where
));
4509 } /* not a bit fix */
4510 } /* For each fixS in this segment. */
4511 } /* fixup_segment() */
4515 /* The first entry in a .stab section is special. */
4518 obj_coff_init_stab_section (seg
)
4524 unsigned int stroff
;
4526 /* Make space for this first symbol. */
4530 as_where (&file
, (unsigned int *) NULL
);
4531 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4532 strcpy (stabstr_name
, segment_info
[seg
].name
);
4533 strcat (stabstr_name
, "str");
4534 stroff
= get_stab_string_offset (file
, stabstr_name
);
4536 md_number_to_chars (p
, stroff
, 4);
4539 /* Fill in the counts in the first entry in a .stab section. */
4542 adjust_stab_section(abfd
, seg
)
4546 segT stabstrseg
= SEG_UNKNOWN
;
4547 const char *secname
, *name2
;
4550 int i
, strsz
= 0, nsyms
;
4551 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4553 /* Look for the associated string table section. */
4555 secname
= segment_info
[seg
].name
;
4556 name
= (char *) alloca (strlen (secname
) + 4);
4557 strcpy (name
, secname
);
4558 strcat (name
, "str");
4560 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4562 name2
= segment_info
[i
].name
;
4563 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4570 /* If we found the section, get its size. */
4571 if (stabstrseg
!= SEG_UNKNOWN
)
4572 strsz
= size_section (abfd
, stabstrseg
);
4574 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4576 /* Look for the first frag of sufficient size for the initial stab
4577 symbol, and collect a pointer to it. */
4578 while (frag
&& frag
->fr_fix
< 12)
4579 frag
= frag
->fr_next
;
4581 p
= frag
->fr_literal
;
4584 /* Write in the number of stab symbols and the size of the string
4586 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4587 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4590 #endif /* not BFD_ASSEMBLER */
4592 const pseudo_typeS coff_pseudo_table
[] =
4594 {"def", obj_coff_def
, 0},
4595 {"dim", obj_coff_dim
, 0},
4596 {"endef", obj_coff_endef
, 0},
4597 {"line", obj_coff_line
, 0},
4598 {"ln", obj_coff_ln
, 0},
4599 #ifdef BFD_ASSEMBLER
4600 {"loc", obj_coff_loc
, 0},
4602 {"appline", obj_coff_ln
, 1},
4603 {"scl", obj_coff_scl
, 0},
4604 {"size", obj_coff_size
, 0},
4605 {"tag", obj_coff_tag
, 0},
4606 {"type", obj_coff_type
, 0},
4607 {"val", obj_coff_val
, 0},
4608 {"section", obj_coff_section
, 0},
4609 {"sect", obj_coff_section
, 0},
4610 /* FIXME: We ignore the MRI short attribute. */
4611 {"section.s", obj_coff_section
, 0},
4612 {"sect.s", obj_coff_section
, 0},
4613 /* We accept the .bss directive for backward compatibility with
4614 earlier versions of gas. */
4615 {"bss", obj_coff_bss
, 0},
4616 {"weak", obj_coff_weak
, 0},
4617 {"ident", obj_coff_ident
, 0},
4618 #ifndef BFD_ASSEMBLER
4619 {"use", obj_coff_section
, 0},
4620 {"text", obj_coff_text
, 0},
4621 {"data", obj_coff_data
, 0},
4622 {"lcomm", obj_coff_lcomm
, 0},
4624 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4626 {"version", s_ignore
, 0},
4627 {"ABORT", s_abort
, 0},
4629 /* The m88k uses sdef instead of def. */
4630 {"sdef", obj_coff_def
, 0},
4632 {NULL
, NULL
, 0} /* end sentinel */
4633 }; /* coff_pseudo_table */
4635 #ifdef BFD_ASSEMBLER
4637 /* Support for a COFF emulation. */
4639 static void coff_pop_insert
PARAMS ((void));
4640 static int coff_separate_stab_sections
PARAMS ((void));
4645 pop_insert (coff_pseudo_table
);
4649 coff_separate_stab_sections ()
4654 const struct format_ops coff_format_ops
=
4656 bfd_target_coff_flavour
,
4657 0, /* dfl_leading_underscore */
4658 1, /* emit_section_symbols */
4663 0, /* frob_file_before_adjust */
4664 coff_frob_file_after_relocs
,
4667 0, /* s_get_align */
4668 0, /* s_set_align */
4669 0, /* s_get_other */
4670 0, /* s_set_other */
4675 0, /* copy_symbol_attributes */
4676 0, /* generate_asm_lineno */
4677 0, /* process_stab */
4678 coff_separate_stab_sections
,
4679 obj_coff_init_stab_section
,
4680 0, /* sec_sym_ok_for_reloc */
4682 0, /* ecoff_set_ext */
4683 coff_obj_read_begin_hook
,
4684 coff_obj_symbol_new_hook