1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004
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 /* This is used to hold the symbol built by a sequence of pseudo-ops
42 from .def and .endef. */
43 static symbolS
*def_symbol_in_progress
;
47 unsigned long chunk_size
;
48 unsigned long element_size
;
51 unsigned long pointer
;
55 static stack
*stack_init
PARAMS ((unsigned long, unsigned long));
56 static char *stack_push
PARAMS ((stack
*, char *));
57 static char *stack_pop
PARAMS ((stack
*));
58 static void tag_init
PARAMS ((void));
59 static void tag_insert
PARAMS ((const char *, symbolS
*));
60 static symbolS
*tag_find
PARAMS ((char *));
61 static symbolS
*tag_find_or_make
PARAMS ((char *));
62 static void obj_coff_bss
PARAMS ((int));
64 static void obj_coff_weak
PARAMS ((int));
66 const char *s_get_name
PARAMS ((symbolS
* s
));
67 static void obj_coff_ln
PARAMS ((int));
68 static void obj_coff_def
PARAMS ((int));
69 static void obj_coff_endef
PARAMS ((int));
70 static void obj_coff_dim
PARAMS ((int));
71 static void obj_coff_line
PARAMS ((int));
72 static void obj_coff_size
PARAMS ((int));
73 static void obj_coff_scl
PARAMS ((int));
74 static void obj_coff_tag
PARAMS ((int));
75 static void obj_coff_val
PARAMS ((int));
76 static void obj_coff_type
PARAMS ((int));
77 static void obj_coff_ident
PARAMS ((int));
79 static void obj_coff_loc
PARAMS((int));
85 stack_init (chunk_size
, element_size
)
86 unsigned long chunk_size
;
87 unsigned long element_size
;
91 st
= (stack
*) malloc (sizeof (stack
));
94 st
->data
= malloc (chunk_size
);
101 st
->size
= chunk_size
;
102 st
->chunk_size
= chunk_size
;
103 st
->element_size
= element_size
;
108 /* Not currently used. */
119 stack_push (st
, element
)
123 if (st
->pointer
+ st
->element_size
>= st
->size
)
125 st
->size
+= st
->chunk_size
;
126 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
129 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
130 st
->pointer
+= st
->element_size
;
131 return st
->data
+ st
->pointer
;
138 if (st
->pointer
< st
->element_size
)
143 st
->pointer
-= st
->element_size
;
144 return st
->data
+ st
->pointer
;
148 * Maintain a list of the tagnames of the structures.
151 static struct hash_control
*tag_hash
;
156 tag_hash
= hash_new ();
160 tag_insert (name
, symbolP
)
164 const char *error_string
;
166 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
168 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
177 #ifdef STRIP_UNDERSCORE
180 #endif /* STRIP_UNDERSCORE */
181 return (symbolS
*) hash_find (tag_hash
, name
);
185 tag_find_or_make (name
)
190 if ((symbolP
= tag_find (name
)) == NULL
)
192 symbolP
= symbol_new (name
, undefined_section
,
193 0, &zero_address_frag
);
195 tag_insert (S_GET_NAME (symbolP
), symbolP
);
197 symbol_table_insert (symbolP
);
204 /* We accept the .bss directive to set the section for backward
205 compatibility with earlier versions of gas. */
208 obj_coff_bss (ignore
)
209 int ignore ATTRIBUTE_UNUSED
;
211 if (*input_line_pointer
== '\n')
212 subseg_new (".bss", get_absolute_expression ());
219 static segT fetch_coff_debug_section
PARAMS ((void));
220 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
221 static int S_GET_DATA_TYPE
PARAMS ((symbolS
*));
222 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
223 static void add_lineno
PARAMS ((fragS
*, addressT
, int));
225 #define GET_FILENAME_STRING(X) \
226 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
230 fetch_coff_debug_section ()
232 static segT debug_section
;
236 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
238 debug_section
= s
->section
;
240 return debug_section
;
244 SA_SET_SYM_ENDNDX (sym
, val
)
248 combined_entry_type
*entry
, *p
;
250 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
251 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
252 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
257 SA_SET_SYM_TAGNDX (sym
, val
)
261 combined_entry_type
*entry
, *p
;
263 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
264 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
265 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
270 S_GET_DATA_TYPE (sym
)
273 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
277 S_SET_DATA_TYPE (sym
, val
)
281 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
286 S_GET_STORAGE_CLASS (sym
)
289 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
293 S_SET_STORAGE_CLASS (sym
, val
)
297 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
301 /* Merge a debug symbol containing debug information into a normal symbol. */
304 c_symbol_merge (debug
, normal
)
308 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
309 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
311 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
313 /* take the most we have */
314 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
317 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
319 /* Move all the auxiliary information. */
320 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
321 (S_GET_NUMBER_AUXILIARY (debug
)
322 * sizeof (*SYM_AUXINFO (debug
))));
325 /* Move the debug flags. */
326 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
330 c_dot_file_symbol (filename
)
331 const char *filename
;
335 /* BFD converts filename to a .file symbol with an aux entry. It
336 also handles chaining. */
337 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
339 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
340 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
342 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
349 listing_source_file (filename
);
354 /* Make sure that the symbol is first on the symbol chain */
355 if (symbol_rootP
!= symbolP
)
357 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
358 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
359 } /* if not first on the list */
362 /* Line number handling */
365 struct line_no
*next
;
372 /* Symbol of last function, which we should hang line#s off of. */
373 static symbolS
*line_fsym
;
375 #define in_function() (line_fsym != 0)
376 #define clear_function() (line_fsym = 0)
377 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
381 coff_obj_symbol_new_hook (symbolP
)
384 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
385 char * s
= (char *) xmalloc (sz
);
388 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
390 S_SET_DATA_TYPE (symbolP
, T_NULL
);
391 S_SET_STORAGE_CLASS (symbolP
, 0);
392 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
394 if (S_IS_STRING (symbolP
))
395 SF_SET_STRING (symbolP
);
397 if (S_IS_LOCAL (symbolP
))
398 SF_SET_LOCAL (symbolP
);
403 * Handle .ln directives.
406 static symbolS
*current_lineno_sym
;
407 static struct line_no
*line_nos
;
408 /* @@ Blindly assume all .ln directives will be in the .text section... */
412 add_lineno (frag
, offset
, num
)
417 struct line_no
*new_line
=
418 (struct line_no
*) xmalloc (sizeof (struct line_no
));
419 if (!current_lineno_sym
)
425 /* The native aix assembler accepts negative line number */
429 /* Zero is used as an end marker in the file. */
430 as_warn (_("Line numbers must be positive integers\n"));
433 #endif /* OBJ_XCOFF */
434 new_line
->next
= line_nos
;
435 new_line
->frag
= frag
;
436 new_line
->l
.line_number
= num
;
437 new_line
->l
.u
.offset
= offset
;
443 coff_add_linesym (sym
)
448 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
453 current_lineno_sym
= sym
;
457 obj_coff_ln (appline
)
462 if (! appline
&& def_symbol_in_progress
!= NULL
)
464 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
465 demand_empty_rest_of_line ();
469 l
= get_absolute_expression ();
471 /* If there is no lineno symbol, treat a .ln
472 directive as if it were a .appline directive. */
473 if (appline
|| current_lineno_sym
== NULL
)
474 new_logical_line ((char *) NULL
, l
- 1);
476 add_lineno (frag_now
, frag_now_fix (), l
);
485 l
+= coff_line_base
- 1;
486 listing_source_line (l
);
491 demand_empty_rest_of_line ();
494 /* .loc is essentially the same as .ln; parse it for assembler
498 obj_coff_loc (ignore
)
499 int ignore ATTRIBUTE_UNUSED
;
503 /* FIXME: Why do we need this check? We need it for ECOFF, but why
504 do we need it for COFF? */
505 if (now_seg
!= text_section
)
507 as_warn (_(".loc outside of .text"));
508 demand_empty_rest_of_line ();
512 if (def_symbol_in_progress
!= NULL
)
514 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
515 demand_empty_rest_of_line ();
519 /* Skip the file number. */
521 get_absolute_expression ();
524 lineno
= get_absolute_expression ();
532 lineno
+= coff_line_base
- 1;
533 listing_source_line (lineno
);
538 demand_empty_rest_of_line ();
540 add_lineno (frag_now
, frag_now_fix (), lineno
);
543 /* Handle the .ident pseudo-op. */
546 obj_coff_ident (ignore
)
547 int ignore ATTRIBUTE_UNUSED
;
549 segT current_seg
= now_seg
;
550 subsegT current_subseg
= now_subseg
;
556 /* We could put it in .comment, but that creates an extra section
557 that shouldn't be loaded into memory, which requires linker
558 changes... For now, until proven otherwise, use .rdata. */
559 sec
= subseg_new (".rdata$zzz", 0);
560 bfd_set_section_flags (stdoutput
, sec
,
561 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
562 & bfd_applicable_section_flags (stdoutput
)));
565 subseg_new (".comment", 0);
569 subseg_set (current_seg
, current_subseg
);
575 * Handle .def directives.
577 * One might ask : why can't we symbol_new if the symbol does not
578 * already exist and fill it with debug information. Because of
579 * the C_EFCN special symbol. It would clobber the value of the
580 * function symbol before we have a chance to notice that it is
581 * a C_EFCN. And a second reason is that the code is more clear this
582 * way. (at least I think it is :-).
586 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
587 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
588 *input_line_pointer == '\t') \
589 input_line_pointer++;
593 int what ATTRIBUTE_UNUSED
;
595 char name_end
; /* Char after the end of name */
596 char *symbol_name
; /* Name of the debug symbol */
597 char *symbol_name_copy
; /* Temporary copy of the name */
598 unsigned int symbol_name_length
;
600 if (def_symbol_in_progress
!= NULL
)
602 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
603 demand_empty_rest_of_line ();
605 } /* if not inside .def/.endef */
609 symbol_name
= input_line_pointer
;
610 #ifdef STRIP_UNDERSCORE
611 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
613 #endif /* STRIP_UNDERSCORE */
615 name_end
= get_symbol_end ();
616 symbol_name_length
= strlen (symbol_name
);
617 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
618 strcpy (symbol_name_copy
, symbol_name
);
619 #ifdef tc_canonicalize_symbol_name
620 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
623 /* Initialize the new symbol */
624 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
625 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
626 S_SET_VALUE (def_symbol_in_progress
, 0);
628 if (S_IS_STRING (def_symbol_in_progress
))
629 SF_SET_STRING (def_symbol_in_progress
);
631 *input_line_pointer
= name_end
;
633 demand_empty_rest_of_line ();
636 unsigned int dim_index
;
639 obj_coff_endef (ignore
)
640 int ignore ATTRIBUTE_UNUSED
;
642 symbolS
*symbolP
= NULL
;
644 /* DIM BUG FIX sac@cygnus.com */
646 if (def_symbol_in_progress
== NULL
)
648 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
649 demand_empty_rest_of_line ();
651 } /* if not inside .def/.endef */
653 /* Set the section number according to storage class. */
654 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
659 SF_SET_TAG (def_symbol_in_progress
);
660 /* intentional fallthrough */
663 SF_SET_DEBUG (def_symbol_in_progress
);
664 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
668 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
669 /* intentional fallthrough */
671 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
672 /* intentional fallthrough */
676 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
678 name
= S_GET_NAME (def_symbol_in_progress
);
679 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
685 if (! in_function ())
686 as_warn (_("`%s' symbol without preceding function"), name
);
687 /* Will need relocating. */
688 SF_SET_PROCESS (def_symbol_in_progress
);
694 /* The MS compilers output the actual endline, not the
695 function-relative one... we want to match without
696 changing the assembler input. */
697 SA_SET_SYM_LNNO (def_symbol_in_progress
,
698 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
709 #endif /* C_AUTOARG */
716 /* According to the COFF documentation:
718 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
720 A special section number (-2) marks symbolic debugging symbols,
721 including structure/union/enumeration tag names, typedefs, and
722 the name of the file. A section number of -1 indicates that the
723 symbol has a value but is not relocatable. Examples of
724 absolute-valued symbols include automatic and register variables,
725 function arguments, and .eos symbols.
727 But from Ian Lance Taylor:
729 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
731 the actual tools all marked them as section -1. So the GNU COFF
732 assembler follows historical COFF assemblers.
734 However, it causes problems for djgpp
736 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
738 By defining STRICTCOFF, a COFF port can make the assembler to
739 follow the documented behavior. */
746 SF_SET_DEBUG (def_symbol_in_progress
);
747 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
755 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
766 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
773 as_warn (_("unexpected storage class %d"),
774 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
776 } /* switch on storage class */
778 /* Now that we have built a debug symbol, try to find if we should
779 merge with an existing symbol or not. If a symbol is C_EFCN or
780 absolute_section or untagged SEG_DEBUG it never merges. We also
781 don't merge labels, which are in a different namespace, nor
782 symbols which have not yet been defined since they are typically
783 unique, nor do we merge tags with non-tags. */
785 /* Two cases for functions. Either debug followed by definition or
786 definition followed by debug. For definition first, we will
787 merge the debug symbol into the definition. For debug first, the
788 lineno entry MUST point to the definition function or else it
789 will point off into space when obj_crawl_symbol_chain() merges
790 the debug symbol into the real symbol. Therefor, let's presume
791 the debug symbol is a real function reference. */
793 /* FIXME-SOON If for some reason the definition label/symbol is
794 never seen, this will probably leave an undefined symbol at link
797 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
798 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
799 || (!strcmp (bfd_get_section_name (stdoutput
,
800 S_GET_SEGMENT (def_symbol_in_progress
)),
802 && !SF_GET_TAG (def_symbol_in_progress
))
803 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
804 || ! symbol_constant_p (def_symbol_in_progress
)
805 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
806 DO_NOT_STRIP
)) == NULL
807 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
809 /* If it already is at the end of the symbol list, do nothing */
810 if (def_symbol_in_progress
!= symbol_lastP
)
812 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
813 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
819 /* This symbol already exists, merge the newly created symbol
820 into the old one. This is not mandatory. The linker can
821 handle duplicate symbols correctly. But I guess that it save
822 a *lot* of space if the assembly file defines a lot of
825 /* The debug entry (def_symbol_in_progress) is merged into the
826 previous definition. */
828 c_symbol_merge (def_symbol_in_progress
, symbolP
);
829 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
831 def_symbol_in_progress
= symbolP
;
833 if (SF_GET_FUNCTION (def_symbol_in_progress
)
834 || SF_GET_TAG (def_symbol_in_progress
)
835 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
837 /* For functions, and tags, and static symbols, the symbol
838 *must* be where the debug symbol appears. Move the
839 existing symbol to the current place. */
840 /* If it already is at the end of the symbol list, do nothing */
841 if (def_symbol_in_progress
!= symbol_lastP
)
843 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
844 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
849 if (SF_GET_TAG (def_symbol_in_progress
))
853 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
855 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
856 tag_insert (S_GET_NAME (def_symbol_in_progress
),
857 def_symbol_in_progress
);
860 if (SF_GET_FUNCTION (def_symbol_in_progress
))
862 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
863 set_function (def_symbol_in_progress
);
864 SF_SET_PROCESS (def_symbol_in_progress
);
868 /* That is, if this is the first time we've seen the
870 symbol_table_insert (def_symbol_in_progress
);
871 } /* definition follows debug */
872 } /* Create the line number entry pointing to the function being defined */
874 def_symbol_in_progress
= NULL
;
875 demand_empty_rest_of_line ();
879 obj_coff_dim (ignore
)
880 int ignore ATTRIBUTE_UNUSED
;
884 if (def_symbol_in_progress
== NULL
)
886 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
887 demand_empty_rest_of_line ();
889 } /* if not inside .def/.endef */
891 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
893 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
896 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
897 get_absolute_expression ());
899 switch (*input_line_pointer
)
902 input_line_pointer
++;
906 as_warn (_("badly formed .dim directive ignored"));
907 /* intentional fallthrough */
915 demand_empty_rest_of_line ();
919 obj_coff_line (ignore
)
920 int ignore ATTRIBUTE_UNUSED
;
924 if (def_symbol_in_progress
== NULL
)
926 /* Probably stabs-style line? */
931 this_base
= get_absolute_expression ();
932 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
933 coff_line_base
= this_base
;
935 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
936 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
938 demand_empty_rest_of_line ();
941 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
946 listing_source_line ((unsigned int) this_base
);
952 obj_coff_size (ignore
)
953 int ignore ATTRIBUTE_UNUSED
;
955 if (def_symbol_in_progress
== NULL
)
957 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
958 demand_empty_rest_of_line ();
960 } /* if not inside .def/.endef */
962 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
963 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
964 demand_empty_rest_of_line ();
968 obj_coff_scl (ignore
)
969 int ignore ATTRIBUTE_UNUSED
;
971 if (def_symbol_in_progress
== NULL
)
973 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
974 demand_empty_rest_of_line ();
976 } /* if not inside .def/.endef */
978 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
979 demand_empty_rest_of_line ();
983 obj_coff_tag (ignore
)
984 int ignore ATTRIBUTE_UNUSED
;
989 if (def_symbol_in_progress
== NULL
)
991 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
992 demand_empty_rest_of_line ();
996 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
997 symbol_name
= input_line_pointer
;
998 name_end
= get_symbol_end ();
1000 #ifdef tc_canonicalize_symbol_name
1001 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1004 /* Assume that the symbol referred to by .tag is always defined.
1005 This was a bad assumption. I've added find_or_make. xoxorich. */
1006 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1007 tag_find_or_make (symbol_name
));
1008 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1010 as_warn (_("tag not found for .tag %s"), symbol_name
);
1013 SF_SET_TAGGED (def_symbol_in_progress
);
1014 *input_line_pointer
= name_end
;
1016 demand_empty_rest_of_line ();
1020 obj_coff_type (ignore
)
1021 int ignore ATTRIBUTE_UNUSED
;
1023 if (def_symbol_in_progress
== NULL
)
1025 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1026 demand_empty_rest_of_line ();
1028 } /* if not inside .def/.endef */
1030 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1032 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1033 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1035 SF_SET_FUNCTION (def_symbol_in_progress
);
1036 } /* is a function */
1038 demand_empty_rest_of_line ();
1042 obj_coff_val (ignore
)
1043 int ignore ATTRIBUTE_UNUSED
;
1045 if (def_symbol_in_progress
== NULL
)
1047 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1048 demand_empty_rest_of_line ();
1050 } /* if not inside .def/.endef */
1052 if (is_name_beginner (*input_line_pointer
))
1054 char *symbol_name
= input_line_pointer
;
1055 char name_end
= get_symbol_end ();
1057 #ifdef tc_canonicalize_symbol_name
1058 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1060 if (!strcmp (symbol_name
, "."))
1062 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1063 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1064 /* If the .val is != from the .def (e.g. statics) */
1066 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1070 exp
.X_op
= O_symbol
;
1071 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1072 exp
.X_op_symbol
= NULL
;
1073 exp
.X_add_number
= 0;
1074 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1076 /* If the segment is undefined when the forward reference is
1077 resolved, then copy the segment id from the forward
1079 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1081 /* FIXME: gcc can generate address expressions here in
1082 unusual cases (search for "obscure" in sdbout.c). We
1083 just ignore the offset here, thus generating incorrect
1084 debugging information. We ignore the rest of the line
1087 /* Otherwise, it is the name of a non debug symbol and its value
1088 will be calculated later. */
1089 *input_line_pointer
= name_end
;
1093 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1094 } /* if symbol based */
1096 demand_empty_rest_of_line ();
1099 /* Handle .weak. This is a GNU extension in formats other than PE. */
1101 obj_coff_weak (ignore
)
1102 int ignore ATTRIBUTE_UNUSED
;
1110 name
= input_line_pointer
;
1111 c
= get_symbol_end ();
1114 as_warn (_("badly formed .weak directive ignored"));
1115 ignore_rest_of_line ();
1118 symbolP
= symbol_find_or_make (name
);
1119 *input_line_pointer
= c
;
1122 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
1123 S_SET_WEAK (symbolP
);
1127 /* See _Microsoft Portable Executable and Common Object
1128 * File Format Specification_, section 5.5.3.
1129 * Note that weak symbols without aux records are a GNU
1132 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
1136 symbolS
*alternateP
;
1137 long characteristics
= 2;
1138 ++input_line_pointer
;
1139 if (*input_line_pointer
== '=')
1141 characteristics
= 1;
1142 ++input_line_pointer
;
1146 name
= input_line_pointer
;
1147 c
= get_symbol_end();
1150 as_warn (_("alternate name missing in .weak directive"));
1151 ignore_rest_of_line ();
1154 alternateP
= symbol_find_or_make (name
);
1155 *input_line_pointer
= c
;
1157 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1158 SA_SET_SYM_TAGNDX (symbolP
, alternateP
);
1159 SA_SET_SYM_FSIZE (symbolP
, characteristics
);
1162 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
1167 input_line_pointer
++;
1169 if (*input_line_pointer
== '\n')
1176 demand_empty_rest_of_line ();
1180 coff_obj_read_begin_hook ()
1182 /* These had better be the same. Usually 18 bytes. */
1184 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1185 know (SYMESZ
== AUXESZ
);
1190 symbolS
*coff_last_function
;
1192 static symbolS
*coff_last_bf
;
1196 coff_frob_symbol (symp
, punt
)
1200 static symbolS
*last_tagP
;
1201 static stack
*block_stack
;
1202 static symbolS
*set_end
;
1203 symbolS
*next_set_end
= NULL
;
1205 if (symp
== &abs_symbol
)
1211 if (current_lineno_sym
)
1212 coff_add_linesym ((symbolS
*) 0);
1215 block_stack
= stack_init (512, sizeof (symbolS
*));
1217 if (S_IS_WEAK (symp
))
1220 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1222 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1226 if (!S_IS_DEFINED (symp
)
1227 && !S_IS_WEAK (symp
)
1228 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1229 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1231 if (!SF_GET_DEBUG (symp
))
1235 if (!SF_GET_LOCAL (symp
)
1236 && !SF_GET_STATICS (symp
)
1237 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1238 && symbol_constant_p(symp
)
1239 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1240 && S_GET_STORAGE_CLASS (real
) == C_NULL
1243 c_symbol_merge (symp
, real
);
1248 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1250 assert (S_GET_VALUE (symp
) == 0);
1251 S_SET_EXTERNAL (symp
);
1253 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1255 if (S_GET_SEGMENT (symp
) == text_section
1256 && symp
!= seg_info (text_section
)->sym
)
1257 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1259 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1262 if (SF_GET_PROCESS (symp
))
1264 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1266 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1267 stack_push (block_stack
, (char *) &symp
);
1272 begin
= *(symbolS
**) stack_pop (block_stack
);
1274 as_warn (_("mismatched .eb"));
1276 next_set_end
= begin
;
1280 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1282 union internal_auxent
*auxp
;
1284 coff_last_function
= symp
;
1285 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1286 S_SET_NUMBER_AUXILIARY (symp
, 1);
1287 auxp
= SYM_AUXENT (symp
);
1288 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1289 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1292 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1294 if (coff_last_function
== 0)
1295 as_fatal (_("C_EFCN symbol out of scope"));
1296 SA_SET_SYM_FSIZE (coff_last_function
,
1297 (long) (S_GET_VALUE (symp
)
1298 - S_GET_VALUE (coff_last_function
)));
1299 next_set_end
= coff_last_function
;
1300 coff_last_function
= 0;
1304 if (S_IS_EXTERNAL (symp
))
1305 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1306 else if (SF_GET_LOCAL (symp
))
1309 if (SF_GET_FUNCTION (symp
))
1310 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1315 /* Double check weak symbols. */
1316 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1317 as_bad (_("Symbol `%s' can not be both weak and common"),
1320 if (SF_GET_TAG (symp
))
1322 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1323 next_set_end
= last_tagP
;
1326 /* This is pretty horrible, but we have to set *punt correctly in
1327 order to call SA_SET_SYM_ENDNDX correctly. */
1328 if (! symbol_used_in_reloc_p (symp
)
1329 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1330 || (! S_IS_EXTERNAL (symp
)
1331 && ! symbol_get_tc (symp
)->output
1332 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1336 if (set_end
!= (symbolS
*) NULL
1338 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1339 || (S_IS_DEFINED (symp
)
1340 && ! S_IS_COMMON (symp
)
1341 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1343 SA_SET_SYM_ENDNDX (set_end
, symp
);
1347 if (next_set_end
!= NULL
)
1349 if (set_end
!= NULL
)
1350 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1351 S_GET_NAME (set_end
));
1352 set_end
= next_set_end
;
1357 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1358 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1360 if (coff_last_bf
!= NULL
)
1361 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1362 coff_last_bf
= symp
;
1365 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1368 struct line_no
*lptr
;
1371 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1372 for (i
= 0; lptr
; lptr
= lptr
->next
)
1374 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1376 /* We need i entries for line numbers, plus 1 for the first
1377 entry which BFD will override, plus 1 for the last zero
1378 entry (a marker for BFD). */
1379 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1380 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1381 l
[i
+ 1].line_number
= 0;
1382 l
[i
+ 1].u
.sym
= NULL
;
1386 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1394 coff_adjust_section_syms (abfd
, sec
, x
)
1395 bfd
*abfd ATTRIBUTE_UNUSED
;
1397 PTR x ATTRIBUTE_UNUSED
;
1400 segment_info_type
*seginfo
= seg_info (sec
);
1401 int nlnno
, nrelocs
= 0;
1403 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1404 tc-ppc.c. Do not get confused by it. */
1405 if (seginfo
== NULL
)
1408 if (!strcmp (sec
->name
, ".text"))
1409 nlnno
= coff_n_line_nos
;
1413 /* @@ Hope that none of the fixups expand to more than one reloc
1415 fixS
*fixp
= seginfo
->fix_root
;
1418 if (! fixp
->fx_done
)
1420 fixp
= fixp
->fx_next
;
1423 if (bfd_get_section_size (sec
) == 0
1426 && sec
!= text_section
1427 && sec
!= data_section
1428 && sec
!= bss_section
)
1430 secsym
= section_symbol (sec
);
1431 /* This is an estimate; we'll plug in the real value using
1432 SET_SECTION_RELOCS later */
1433 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1434 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1438 coff_frob_file_after_relocs ()
1440 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1443 /* Implement the .section pseudo op:
1444 .section name {, "flags"}
1446 | +--- optional flags: 'b' for bss
1448 +-- section name 'l' for lib
1452 'd' (apparently m88k for data)
1454 'r' for read-only data
1455 's' for shared data (PE)
1456 But if the argument is not a quoted string, treat it as a
1459 Note the 'a' flag is silently ignored. This allows the same
1460 .section directive to be parsed in both ELF and COFF formats. */
1463 obj_coff_section (ignore
)
1464 int ignore ATTRIBUTE_UNUSED
;
1466 /* Strip out the section name */
1471 flagword flags
, oldflags
;
1482 section_name
= input_line_pointer
;
1483 c
= get_symbol_end ();
1485 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1486 strcpy (name
, section_name
);
1488 *input_line_pointer
= c
;
1493 flags
= SEC_NO_FLAGS
;
1495 if (*input_line_pointer
== ',')
1497 ++input_line_pointer
;
1499 if (*input_line_pointer
!= '"')
1500 exp
= get_absolute_expression ();
1503 ++input_line_pointer
;
1504 while (*input_line_pointer
!= '"'
1505 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1507 switch (*input_line_pointer
)
1509 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1510 case 'n': flags
&=~ SEC_LOAD
; flags
|= SEC_NEVER_LOAD
; break;
1512 case 's': flags
|= SEC_SHARED
; /* fall through */
1513 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1514 case 'w': flags
&=~ SEC_READONLY
; break;
1516 case 'a': break; /* For compatibility with ELF. */
1517 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1518 case 'r': flags
|= SEC_DATA
| SEC_LOAD
| SEC_READONLY
; break;
1520 case 'i': /* STYP_INFO */
1521 case 'l': /* STYP_LIB */
1522 case 'o': /* STYP_OVER */
1523 as_warn (_("unsupported section attribute '%c'"),
1524 *input_line_pointer
);
1528 as_warn(_("unknown section attribute '%c'"),
1529 *input_line_pointer
);
1532 ++input_line_pointer
;
1534 if (*input_line_pointer
== '"')
1535 ++input_line_pointer
;
1539 sec
= subseg_new (name
, (subsegT
) exp
);
1541 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1542 if (oldflags
== SEC_NO_FLAGS
)
1544 /* Set section flags for a new section just created by subseg_new.
1545 Provide a default if no flags were parsed. */
1546 if (flags
== SEC_NO_FLAGS
)
1547 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1549 #ifdef COFF_LONG_SECTION_NAMES
1550 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1551 sections so adjust_reloc_syms in write.c will correctly handle
1552 relocs which refer to non-local symbols in these sections. */
1553 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1554 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1557 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1558 as_warn (_("error setting flags for \"%s\": %s"),
1559 bfd_section_name (stdoutput
, sec
),
1560 bfd_errmsg (bfd_get_error ()));
1562 else if (flags
!= SEC_NO_FLAGS
)
1564 /* This section's attributes have already been set. Warn if the
1565 attributes don't match. */
1566 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1567 | SEC_DATA
| SEC_SHARED
| SEC_NEVER_LOAD
);
1568 if ((flags
^ oldflags
) & matchflags
)
1569 as_warn (_("Ignoring changed section attributes for %s"), name
);
1572 demand_empty_rest_of_line ();
1576 coff_adjust_symtab ()
1578 if (symbol_rootP
== NULL
1579 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1580 c_dot_file_symbol ("fake");
1584 coff_frob_section (sec
)
1590 bfd_vma size
, n_entries
, mask
;
1591 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1593 /* The COFF back end in BFD requires that all section sizes be
1594 rounded up to multiples of the corresponding section alignments,
1595 supposedly because standard COFF has no other way of encoding alignment
1596 for sections. If your COFF flavor has a different way of encoding
1597 section alignment, then skip this step, as TICOFF does. */
1598 size
= bfd_get_section_size (sec
);
1599 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1600 #if !defined(TICOFF)
1606 new_size
= (size
+ mask
) & ~mask
;
1607 bfd_set_section_size (stdoutput
, sec
, new_size
);
1609 /* If the size had to be rounded up, add some padding in
1610 the last non-empty frag. */
1611 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1612 last
= seg_info (sec
)->frchainP
->frch_last
;
1613 while (fragp
->fr_next
!= last
)
1614 fragp
= fragp
->fr_next
;
1615 last
->fr_address
= size
;
1616 fragp
->fr_offset
+= new_size
- size
;
1620 /* If the section size is non-zero, the section symbol needs an aux
1621 entry associated with it, indicating the size. We don't know
1622 all the values yet; coff_frob_symbol will fill them in later. */
1625 || sec
== text_section
1626 || sec
== data_section
1627 || sec
== bss_section
)
1630 symbolS
*secsym
= section_symbol (sec
);
1632 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1633 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1634 SF_SET_STATICS (secsym
);
1635 SA_SET_SCN_SCNLEN (secsym
, size
);
1638 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1639 #ifndef STAB_SECTION_NAME
1640 #define STAB_SECTION_NAME ".stab"
1642 #ifndef STAB_STRING_SECTION_NAME
1643 #define STAB_STRING_SECTION_NAME ".stabstr"
1645 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1649 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1650 /* size is already rounded up, since other section will be listed first */
1651 size
= bfd_get_section_size (strsec
);
1653 n_entries
= bfd_get_section_size (sec
) / 12 - 1;
1655 /* Find first non-empty frag. It should be large enough. */
1656 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1657 while (fragp
&& fragp
->fr_fix
== 0)
1658 fragp
= fragp
->fr_next
;
1659 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1661 /* Store the values. */
1662 p
= fragp
->fr_literal
;
1663 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1664 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1668 obj_coff_init_stab_section (seg
)
1674 unsigned int stroff
;
1676 /* Make space for this first symbol. */
1680 as_where (&file
, (unsigned int *) NULL
);
1681 stabstr_name
= (char *) xmalloc (strlen (seg
->name
) + 4);
1682 strcpy (stabstr_name
, seg
->name
);
1683 strcat (stabstr_name
, "str");
1684 stroff
= get_stab_string_offset (file
, stabstr_name
);
1686 md_number_to_chars (p
, stroff
, 4);
1695 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1703 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1705 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1706 (unsigned long) symbolP
,
1707 S_GET_NAME(symbolP
),
1708 (long) S_GET_DATA_TYPE(symbolP
),
1709 S_GET_STORAGE_CLASS(symbolP
),
1710 (int) S_GET_SEGMENT(symbolP
));
1716 #else /* not BFD_ASSEMBLER */
1719 /* This is needed because we include internal bfd things. */
1723 #include "libcoff.h"
1726 #include "coff/pe.h"
1729 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1730 that we can stick sections together without causing trouble. */
1732 #define NOP_OPCODE 0x00
1735 /* The zeroes if symbol name is longer than 8 chars */
1736 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1738 #define MIN(a,b) ((a) < (b)? (a) : (b))
1740 /* This vector is used to turn a gas internal segment number into a
1741 section number suitable for insertion into a coff symbol table.
1742 This must correspond to seg_info_off_by_4. */
1744 const short seg_N_TYPE
[] =
1745 { /* in: segT out: N_TYPE bits */
1747 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1748 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1749 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1750 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1751 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1752 C_UNDEF_SECTION
, /* SEG_GOOF */
1753 C_UNDEF_SECTION
, /* SEG_EXPR */
1754 C_DEBUG_SECTION
, /* SEG_DEBUG */
1755 C_NTV_SECTION
, /* SEG_NTV */
1756 C_PTV_SECTION
, /* SEG_PTV */
1757 C_REGISTER_SECTION
, /* SEG_REGISTER */
1760 int function_lineoff
= -1; /* Offset in line#s where the last function
1761 started (the odd entry for line #0) */
1763 /* Structure used to keep the filenames which
1764 are too long around so that we can stick them
1765 into the string table. */
1766 struct filename_list
1769 struct filename_list
*next
;
1772 static struct filename_list
*filename_list_head
;
1773 static struct filename_list
*filename_list_tail
;
1775 static symbolS
*last_line_symbol
;
1777 /* Add 4 to the real value to get the index and compensate the
1778 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1779 section number into a segment number. */
1782 static symbolS
*previous_file_symbol
;
1783 static int line_base
;
1785 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
1786 symbolS
*c_section_symbol
PARAMS ((char *, int));
1787 void obj_coff_section
PARAMS ((int));
1788 void do_relocs_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1789 char * symbol_to_chars
PARAMS ((bfd
*, char *, symbolS
*));
1790 void w_strings
PARAMS ((char *));
1792 static void fixup_segment
PARAMS ((segment_info_type
*, segT
));
1793 static void fixup_mdeps
PARAMS ((fragS
*, object_headers
*, segT
));
1794 static void fill_section
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1795 static int c_line_new
PARAMS ((symbolS
*, long, int, fragS
*));
1796 static void w_symbols
PARAMS ((bfd
*, char *, symbolS
*));
1797 static void adjust_stab_section
PARAMS ((bfd
*, segT
));
1798 static void obj_coff_lcomm
PARAMS ((int));
1799 static void obj_coff_text
PARAMS ((int));
1800 static void obj_coff_data
PARAMS ((int));
1801 static unsigned int count_entries_in_chain
PARAMS ((unsigned int));
1802 static void coff_header_append
PARAMS ((bfd
*, object_headers
*));
1803 static unsigned int yank_symbols
PARAMS ((void));
1804 static unsigned int glue_symbols
PARAMS ((symbolS
**, symbolS
**));
1805 static unsigned int tie_tags
PARAMS ((void));
1806 static void crawl_symbols
PARAMS ((object_headers
*, bfd
*));
1807 static void do_linenos_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1808 static void remove_subsegs
PARAMS ((void));
1812 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1814 This array maps a COFF section number into a gas section number.
1815 Because COFF uses negative section numbers, you must add 4 to the
1816 COFF section number when indexing into this array; this is done via
1817 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1820 static const segT seg_info_off_by_4
[] =
1827 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1828 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1829 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1830 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1831 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1832 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1833 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1834 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1847 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1849 static relax_addressT relax_align
PARAMS ((relax_addressT
, long));
1851 static relax_addressT
1852 relax_align (address
, alignment
)
1853 relax_addressT address
;
1856 relax_addressT mask
;
1857 relax_addressT new_address
;
1859 mask
= ~((~0) << alignment
);
1860 new_address
= (address
+ mask
) & (~mask
);
1861 return (new_address
- address
);
1868 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1871 static unsigned int size_section
PARAMS ((bfd
*, unsigned int));
1873 /* Calculate the size of the frag chain and fill in the section header
1874 to contain all of it, also fill in the addr of the sections. */
1877 size_section (abfd
, idx
)
1878 bfd
*abfd ATTRIBUTE_UNUSED
;
1881 unsigned int size
= 0;
1882 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1886 size
= frag
->fr_address
;
1887 if (frag
->fr_address
!= size
)
1889 fprintf (stderr
, _("Out of step\n"));
1890 size
= frag
->fr_address
;
1893 switch (frag
->fr_type
)
1895 #ifdef TC_COFF_SIZEMACHDEP
1896 case rs_machine_dependent
:
1897 size
+= TC_COFF_SIZEMACHDEP (frag
);
1903 size
+= frag
->fr_fix
;
1904 size
+= frag
->fr_offset
* frag
->fr_var
;
1912 size
+= frag
->fr_fix
;
1913 off
= relax_align (size
, frag
->fr_offset
);
1914 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1920 BAD_CASE (frag
->fr_type
);
1923 frag
= frag
->fr_next
;
1925 segment_info
[idx
].scnhdr
.s_size
= size
;
1930 count_entries_in_chain (idx
)
1933 unsigned int nrelocs
;
1936 /* Count the relocations. */
1937 fixup_ptr
= segment_info
[idx
].fix_root
;
1939 while (fixup_ptr
!= (fixS
*) NULL
)
1941 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1943 #if defined(TC_A29K) || defined(TC_OR32)
1944 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1953 fixup_ptr
= fixup_ptr
->fx_next
;
1960 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1962 /* AUX's ld expects relocations to be sorted. */
1965 compare_external_relocs (x
, y
)
1969 struct external_reloc
*a
= (struct external_reloc
*) x
;
1970 struct external_reloc
*b
= (struct external_reloc
*) y
;
1971 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1972 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1973 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1978 /* Output all the relocations for a section. */
1981 do_relocs_for (abfd
, h
, file_cursor
)
1984 unsigned long *file_cursor
;
1986 unsigned int nrelocs
;
1988 unsigned long reloc_start
= *file_cursor
;
1990 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1992 if (segment_info
[idx
].scnhdr
.s_name
[0])
1994 struct external_reloc
*ext_ptr
;
1995 struct external_reloc
*external_reloc_vec
;
1996 unsigned int external_reloc_size
;
1997 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1998 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1999 nrelocs
= count_entries_in_chain (idx
);
2002 /* Bypass this stuff if no relocs. This also incidentally
2003 avoids a SCO bug, where free(malloc(0)) tends to crash. */
2005 external_reloc_size
= nrelocs
* RELSZ
;
2006 external_reloc_vec
=
2007 (struct external_reloc
*) malloc (external_reloc_size
);
2009 ext_ptr
= external_reloc_vec
;
2011 /* Fill in the internal coff style reloc struct from the
2012 internal fix list. */
2015 struct internal_reloc intr
;
2017 /* Only output some of the relocations. */
2018 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
2020 #ifdef TC_RELOC_MANGLE
2021 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
2025 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
2027 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
2029 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
2031 #ifdef TC_KEEP_FX_OFFSET
2032 intr
.r_offset
= fix_ptr
->fx_offset
;
2037 while (symbol_ptr
->sy_value
.X_op
== O_symbol
2038 && (! S_IS_DEFINED (symbol_ptr
)
2039 || S_IS_COMMON (symbol_ptr
)))
2043 /* We must avoid looping, as that can occur
2044 with a badly written program. */
2045 n
= symbol_ptr
->sy_value
.X_add_symbol
;
2046 if (n
== symbol_ptr
)
2051 /* Turn the segment of the symbol into an offset. */
2054 resolve_symbol_value (symbol_ptr
);
2055 if (! symbol_ptr
->sy_resolved
)
2060 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
2061 as_bad_where (file
, line
,
2062 _("unresolved relocation"));
2064 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2065 S_GET_NAME (symbol_ptr
));
2068 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
2070 intr
.r_symndx
= dot
->sy_number
;
2072 intr
.r_symndx
= symbol_ptr
->sy_number
;
2077 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2079 #if defined(TC_A29K)
2080 /* The 29k has a special kludge for the high 16 bit
2081 reloc. Two relocations are emitted, R_IHIHALF,
2082 and R_IHCONST. The second one doesn't contain a
2083 symbol, but uses the value for offset. */
2084 if (intr
.r_type
== R_IHIHALF
)
2086 /* Now emit the second bit. */
2087 intr
.r_type
= R_IHCONST
;
2088 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2089 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2093 #if defined(TC_OR32)
2094 /* The or32 has a special kludge for the high 16 bit
2095 reloc. Two relocations are emitted, R_IHIHALF,
2096 and R_IHCONST. The second one doesn't contain a
2097 symbol, but uses the value for offset. */
2098 if (intr
.r_type
== R_IHIHALF
)
2100 /* Now emit the second bit. */
2101 intr
.r_type
= R_IHCONST
;
2102 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2103 (void) bfd_coff_swap_reloc_out (abfd
, & intr
, ext_ptr
);
2109 fix_ptr
= fix_ptr
->fx_next
;
2112 /* Sort the reloc table. */
2113 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2114 sizeof (struct external_reloc
), compare_external_relocs
);
2116 /* Write out the reloc table. */
2117 bfd_bwrite ((PTR
) external_reloc_vec
,
2118 (bfd_size_type
) external_reloc_size
, abfd
);
2119 free (external_reloc_vec
);
2121 /* Fill in section header info. */
2122 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2123 *file_cursor
+= external_reloc_size
;
2124 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2129 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2134 /* Set relocation_size field in file headers. */
2135 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2138 /* Run through a frag chain and write out the data to go with it, fill
2139 in the scnhdrs with the info on the file positions. */
2142 fill_section (abfd
, h
, file_cursor
)
2144 object_headers
*h ATTRIBUTE_UNUSED
;
2145 unsigned long *file_cursor
;
2148 unsigned int paddr
= 0;
2150 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2152 unsigned int offset
= 0;
2153 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2159 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2160 char *buffer
= NULL
;
2166 buffer
= xmalloc (s
->s_size
);
2167 s
->s_scnptr
= *file_cursor
;
2169 know (s
->s_paddr
== paddr
);
2171 if (strcmp (s
->s_name
, ".text") == 0)
2172 s
->s_flags
|= STYP_TEXT
;
2173 else if (strcmp (s
->s_name
, ".data") == 0)
2174 s
->s_flags
|= STYP_DATA
;
2175 else if (strcmp (s
->s_name
, ".bss") == 0)
2178 s
->s_flags
|= STYP_BSS
;
2180 /* @@ Should make the i386 and a29k coff targets define
2181 COFF_NOLOAD_PROBLEM, and have only one test here. */
2185 #ifndef COFF_NOLOAD_PROBLEM
2186 /* Apparently the SVR3 linker (and exec syscall) and UDI
2187 mondfe progrem are confused by noload sections. */
2188 s
->s_flags
|= STYP_NOLOAD
;
2194 else if (strcmp (s
->s_name
, ".lit") == 0)
2195 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2196 else if (strcmp (s
->s_name
, ".init") == 0)
2197 s
->s_flags
|= STYP_TEXT
;
2198 else if (strcmp (s
->s_name
, ".fini") == 0)
2199 s
->s_flags
|= STYP_TEXT
;
2200 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2201 s
->s_flags
|= STYP_INFO
;
2205 unsigned int fill_size
;
2206 switch (frag
->fr_type
)
2208 case rs_machine_dependent
:
2211 memcpy (buffer
+ frag
->fr_address
,
2213 (unsigned int) frag
->fr_fix
);
2214 offset
+= frag
->fr_fix
;
2226 memcpy (buffer
+ frag
->fr_address
,
2228 (unsigned int) frag
->fr_fix
);
2229 offset
+= frag
->fr_fix
;
2232 fill_size
= frag
->fr_var
;
2233 if (fill_size
&& frag
->fr_offset
> 0)
2236 unsigned int off
= frag
->fr_fix
;
2237 for (count
= frag
->fr_offset
; count
; count
--)
2239 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2241 memcpy (buffer
+ frag
->fr_address
+ off
,
2242 frag
->fr_literal
+ frag
->fr_fix
,
2245 offset
+= fill_size
;
2250 case rs_broken_word
:
2255 frag
= frag
->fr_next
;
2260 if (s
->s_scnptr
!= 0)
2262 bfd_bwrite (buffer
, s
->s_size
, abfd
);
2263 *file_cursor
+= s
->s_size
;
2272 /* Coff file generation & utilities. */
2275 coff_header_append (abfd
, h
)
2282 #ifdef COFF_LONG_SECTION_NAMES
2283 unsigned long string_size
= 4;
2286 bfd_seek (abfd
, (file_ptr
) 0, 0);
2288 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2289 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2290 H_SET_VERSION_STAMP (h
, 0);
2291 H_SET_ENTRY_POINT (h
, 0);
2292 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2293 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2294 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2296 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2297 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2298 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2300 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2302 bfd_bwrite (buffer
, (bfd_size_type
) i
, abfd
);
2303 bfd_bwrite (buffero
, (bfd_size_type
) H_GET_SIZEOF_OPTIONAL_HEADER (h
), abfd
);
2305 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2307 if (segment_info
[i
].scnhdr
.s_name
[0])
2311 #ifdef COFF_LONG_SECTION_NAMES
2312 /* Support long section names as found in PE. This code
2313 must coordinate with that in write_object_file and
2315 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2317 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2318 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2319 string_size
+= strlen (segment_info
[i
].name
) + 1;
2322 size
= bfd_coff_swap_scnhdr_out (abfd
,
2323 &(segment_info
[i
].scnhdr
),
2326 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2327 bfd_bwrite (buffer
, (bfd_size_type
) size
, abfd
);
2333 symbol_to_chars (abfd
, where
, symbolP
)
2338 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2342 /* Turn any symbols with register attributes into abs symbols. */
2343 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2344 S_SET_SEGMENT (symbolP
, absolute_section
);
2346 /* At the same time, relocate all symbols to their output value. */
2348 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2349 + S_GET_VALUE (symbolP
));
2351 val
= S_GET_VALUE (symbolP
);
2354 S_SET_VALUE (symbolP
, val
);
2356 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2358 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2361 for (i
= 0; i
< numaux
; i
++)
2363 where
+= bfd_coff_swap_aux_out (abfd
,
2364 &symbolP
->sy_symbol
.ost_auxent
[i
],
2365 S_GET_DATA_TYPE (symbolP
),
2366 S_GET_STORAGE_CLASS (symbolP
),
2374 coff_obj_symbol_new_hook (symbolP
)
2377 char underscore
= 0; /* Symbol has leading _ */
2379 /* Effective symbol. */
2380 /* Store the pointer in the offset. */
2381 S_SET_ZEROES (symbolP
, 0L);
2382 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2383 S_SET_STORAGE_CLASS (symbolP
, 0);
2384 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2385 /* Additional information. */
2386 symbolP
->sy_symbol
.ost_flags
= 0;
2387 /* Auxiliary entries. */
2388 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2390 if (S_IS_STRING (symbolP
))
2391 SF_SET_STRING (symbolP
);
2392 if (!underscore
&& S_IS_LOCAL (symbolP
))
2393 SF_SET_LOCAL (symbolP
);
2396 /* Handle .ln directives. */
2399 obj_coff_ln (appline
)
2404 if (! appline
&& def_symbol_in_progress
!= NULL
)
2406 /* Wrong context. */
2407 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2408 demand_empty_rest_of_line ();
2412 l
= get_absolute_expression ();
2413 c_line_new (0, frag_now_fix (), l
, frag_now
);
2416 new_logical_line ((char *) NULL
, l
- 1);
2426 listing_source_line ((unsigned int) l
);
2431 demand_empty_rest_of_line ();
2434 /* Handle .def directives.
2436 One might ask : why can't we symbol_new if the symbol does not
2437 already exist and fill it with debug information. Because of
2438 the C_EFCN special symbol. It would clobber the value of the
2439 function symbol before we have a chance to notice that it is
2440 a C_EFCN. And a second reason is that the code is more clear this
2441 way. (at least I think it is :-). */
2443 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2444 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2445 *input_line_pointer == '\t') \
2446 input_line_pointer++;
2450 int what ATTRIBUTE_UNUSED
;
2452 char name_end
; /* Char after the end of name. */
2453 char *symbol_name
; /* Name of the debug symbol. */
2454 char *symbol_name_copy
; /* Temporary copy of the name. */
2455 unsigned int symbol_name_length
;
2457 if (def_symbol_in_progress
!= NULL
)
2459 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2460 demand_empty_rest_of_line ();
2464 SKIP_WHITESPACES ();
2466 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2467 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2469 symbol_name
= input_line_pointer
;
2470 name_end
= get_symbol_end ();
2471 symbol_name_length
= strlen (symbol_name
);
2472 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2473 strcpy (symbol_name_copy
, symbol_name
);
2474 #ifdef tc_canonicalize_symbol_name
2475 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2478 /* Initialize the new symbol. */
2479 #ifdef STRIP_UNDERSCORE
2480 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2481 ? symbol_name_copy
+ 1
2482 : symbol_name_copy
));
2483 #else /* STRIP_UNDERSCORE */
2484 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2485 #endif /* STRIP_UNDERSCORE */
2486 /* free(symbol_name_copy); */
2487 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2488 def_symbol_in_progress
->sy_number
= ~0;
2489 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2490 S_SET_VALUE (def_symbol_in_progress
, 0);
2492 if (S_IS_STRING (def_symbol_in_progress
))
2493 SF_SET_STRING (def_symbol_in_progress
);
2495 *input_line_pointer
= name_end
;
2497 demand_empty_rest_of_line ();
2500 unsigned int dim_index
;
2503 obj_coff_endef (ignore
)
2504 int ignore ATTRIBUTE_UNUSED
;
2506 symbolS
*symbolP
= 0;
2507 /* DIM BUG FIX sac@cygnus.com */
2509 if (def_symbol_in_progress
== NULL
)
2511 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2512 demand_empty_rest_of_line ();
2516 /* Set the section number according to storage class. */
2517 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2522 SF_SET_TAG (def_symbol_in_progress
);
2523 /* Intentional fallthrough. */
2527 SF_SET_DEBUG (def_symbol_in_progress
);
2528 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2532 /* Do not emit this symbol. */
2533 SF_SET_LOCAL (def_symbol_in_progress
);
2534 /* Intentional fallthrough. */
2537 /* Will need processing before writing. */
2538 SF_SET_PROCESS (def_symbol_in_progress
);
2539 /* Intentional fallthrough. */
2542 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2544 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2546 if (function_lineoff
< 0)
2547 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2549 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2551 SF_SET_PROCESS (last_line_symbol
);
2552 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2553 SF_SET_PROCESS (def_symbol_in_progress
);
2554 function_lineoff
= -1;
2557 /* Value is always set to . */
2558 def_symbol_in_progress
->sy_frag
= frag_now
;
2559 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2564 #endif /* C_AUTOARG */
2574 SF_SET_DEBUG (def_symbol_in_progress
);
2575 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2585 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
2591 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2595 /* Now that we have built a debug symbol, try to find if we should
2596 merge with an existing symbol or not. If a symbol is C_EFCN or
2597 absolute_section or untagged SEG_DEBUG it never merges. We also
2598 don't merge labels, which are in a different namespace, nor
2599 symbols which have not yet been defined since they are typically
2600 unique, nor do we merge tags with non-tags. */
2602 /* Two cases for functions. Either debug followed by definition or
2603 definition followed by debug. For definition first, we will
2604 merge the debug symbol into the definition. For debug first, the
2605 lineno entry MUST point to the definition function or else it
2606 will point off into space when crawl_symbols() merges the debug
2607 symbol into the real symbol. Therefor, let's presume the debug
2608 symbol is a real function reference. */
2610 /* FIXME-SOON If for some reason the definition label/symbol is
2611 never seen, this will probably leave an undefined symbol at link
2614 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2615 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2616 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2617 && !SF_GET_TAG (def_symbol_in_progress
))
2618 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2619 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2620 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2621 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2623 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2628 /* This symbol already exists, merge the newly created symbol
2629 into the old one. This is not mandatory. The linker can
2630 handle duplicate symbols correctly. But I guess that it save
2631 a *lot* of space if the assembly file defines a lot of
2634 /* The debug entry (def_symbol_in_progress) is merged into the
2635 previous definition. */
2637 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2638 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2639 def_symbol_in_progress
= symbolP
;
2641 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2642 || SF_GET_TAG (def_symbol_in_progress
)
2643 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2645 /* For functions, and tags, and static symbols, the symbol
2646 *must* be where the debug symbol appears. Move the
2647 existing symbol to the current place. */
2648 /* If it already is at the end of the symbol list, do nothing. */
2649 if (def_symbol_in_progress
!= symbol_lastP
)
2651 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2653 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2654 &symbol_rootP
, &symbol_lastP
);
2659 if (SF_GET_TAG (def_symbol_in_progress
))
2663 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2665 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2666 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2667 def_symbol_in_progress
);
2670 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2672 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2674 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2676 SF_SET_PROCESS (def_symbol_in_progress
);
2678 if (symbolP
== NULL
)
2680 /* That is, if this is the first time we've seen the
2682 symbol_table_insert (def_symbol_in_progress
);
2686 def_symbol_in_progress
= NULL
;
2687 demand_empty_rest_of_line ();
2691 obj_coff_dim (ignore
)
2692 int ignore ATTRIBUTE_UNUSED
;
2696 if (def_symbol_in_progress
== NULL
)
2698 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2699 demand_empty_rest_of_line ();
2703 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2705 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2707 SKIP_WHITESPACES ();
2708 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2709 get_absolute_expression ());
2711 switch (*input_line_pointer
)
2714 input_line_pointer
++;
2718 as_warn (_("badly formed .dim directive ignored"));
2719 /* Intentional fallthrough. */
2728 demand_empty_rest_of_line ();
2732 obj_coff_line (ignore
)
2733 int ignore ATTRIBUTE_UNUSED
;
2738 if (def_symbol_in_progress
== NULL
)
2744 name
= S_GET_NAME (def_symbol_in_progress
);
2745 this_base
= get_absolute_expression ();
2747 /* Only .bf symbols indicate the use of a new base line number; the
2748 line numbers associated with .ef, .bb, .eb are relative to the
2749 start of the containing function. */
2750 if (!strcmp (".bf", name
))
2752 #if 0 /* XXX Can we ever have line numbers going backwards? */
2753 if (this_base
> line_base
)
2755 line_base
= this_base
;
2761 listing_source_line ((unsigned int) line_base
);
2766 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2767 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2769 demand_empty_rest_of_line ();
2773 obj_coff_size (ignore
)
2774 int ignore ATTRIBUTE_UNUSED
;
2776 if (def_symbol_in_progress
== NULL
)
2778 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2779 demand_empty_rest_of_line ();
2783 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2784 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2785 demand_empty_rest_of_line ();
2789 obj_coff_scl (ignore
)
2790 int ignore ATTRIBUTE_UNUSED
;
2792 if (def_symbol_in_progress
== NULL
)
2794 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2795 demand_empty_rest_of_line ();
2799 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2800 demand_empty_rest_of_line ();
2804 obj_coff_tag (ignore
)
2805 int ignore ATTRIBUTE_UNUSED
;
2810 if (def_symbol_in_progress
== NULL
)
2812 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2813 demand_empty_rest_of_line ();
2817 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2818 symbol_name
= input_line_pointer
;
2819 name_end
= get_symbol_end ();
2820 #ifdef tc_canonicalize_symbol_name
2821 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2824 /* Assume that the symbol referred to by .tag is always defined.
2825 This was a bad assumption. I've added find_or_make. xoxorich. */
2826 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2827 (long) tag_find_or_make (symbol_name
));
2828 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2829 as_warn (_("tag not found for .tag %s"), symbol_name
);
2831 SF_SET_TAGGED (def_symbol_in_progress
);
2832 *input_line_pointer
= name_end
;
2834 demand_empty_rest_of_line ();
2838 obj_coff_type (ignore
)
2839 int ignore ATTRIBUTE_UNUSED
;
2841 if (def_symbol_in_progress
== NULL
)
2843 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2844 demand_empty_rest_of_line ();
2848 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2850 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2851 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2852 SF_SET_FUNCTION (def_symbol_in_progress
);
2854 demand_empty_rest_of_line ();
2858 obj_coff_val (ignore
)
2859 int ignore ATTRIBUTE_UNUSED
;
2861 if (def_symbol_in_progress
== NULL
)
2863 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2864 demand_empty_rest_of_line ();
2868 if (is_name_beginner (*input_line_pointer
))
2870 char *symbol_name
= input_line_pointer
;
2871 char name_end
= get_symbol_end ();
2873 #ifdef tc_canonicalize_symbol_name
2874 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2877 if (!strcmp (symbol_name
, "."))
2879 def_symbol_in_progress
->sy_frag
= frag_now
;
2880 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2881 /* If the .val is != from the .def (e.g. statics). */
2883 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2885 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2886 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2887 symbol_find_or_make (symbol_name
);
2888 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2889 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2891 /* If the segment is undefined when the forward reference is
2892 resolved, then copy the segment id from the forward
2894 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2896 /* FIXME: gcc can generate address expressions here in
2897 unusual cases (search for "obscure" in sdbout.c). We
2898 just ignore the offset here, thus generating incorrect
2899 debugging information. We ignore the rest of the line
2902 /* Otherwise, it is the name of a non debug symbol and
2903 its value will be calculated later. */
2904 *input_line_pointer
= name_end
;
2906 /* FIXME: this is to avoid an error message in the
2907 FIXME case mentioned just above. */
2908 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2909 ++input_line_pointer
;
2913 S_SET_VALUE (def_symbol_in_progress
,
2914 (valueT
) get_absolute_expression ());
2915 } /* if symbol based */
2917 demand_empty_rest_of_line ();
2922 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2923 read.c, which then calls this object file format specific routine. */
2926 obj_coff_pe_handle_link_once (type
)
2927 enum linkonce_type type
;
2929 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2931 /* We store the type in the seg_info structure, and use it to set up
2932 the auxiliary entry for the section symbol in c_section_symbol. */
2933 seg_info (now_seg
)->linkonce
= type
;
2939 coff_obj_read_begin_hook ()
2941 /* These had better be the same. Usually 18 bytes. */
2943 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2944 know (SYMESZ
== AUXESZ
);
2949 /* This function runs through the symbol table and puts all the
2950 externals onto another chain. */
2952 /* The chain of globals. */
2953 symbolS
*symbol_globalP
;
2954 symbolS
*symbol_global_lastP
;
2956 /* The chain of externals. */
2957 symbolS
*symbol_externP
;
2958 symbolS
*symbol_extern_lastP
;
2961 symbolS
*last_functionP
;
2962 static symbolS
*last_bfP
;
2969 unsigned int symbol_number
= 0;
2970 unsigned int last_file_symno
= 0;
2972 struct filename_list
*filename_list_scan
= filename_list_head
;
2974 for (symbolP
= symbol_rootP
;
2976 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2978 if (symbolP
->sy_mri_common
)
2980 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2982 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2984 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2985 as_bad (_("%s: global symbols not supported in common sections"),
2986 S_GET_NAME (symbolP
));
2987 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2991 if (!SF_GET_DEBUG (symbolP
))
2993 /* Debug symbols do not need all this rubbish. */
2994 symbolS
*real_symbolP
;
2996 /* L* and C_EFCN symbols never merge. */
2997 if (!SF_GET_LOCAL (symbolP
)
2998 && !SF_GET_STATICS (symbolP
)
2999 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
3000 && symbolP
->sy_value
.X_op
== O_constant
3001 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
3002 && real_symbolP
!= symbolP
)
3004 /* FIXME-SOON: where do dups come from?
3005 Maybe tag references before definitions? xoxorich. */
3006 /* Move the debug data from the debug symbol to the
3007 real symbol. Do NOT do the opposite (i.e. move from
3008 real symbol to debug symbol and remove real symbol from the
3009 list.) Because some pointers refer to the real symbol
3010 whereas no pointers refer to the debug symbol. */
3011 c_symbol_merge (symbolP
, real_symbolP
);
3012 /* Replace the current symbol by the real one. */
3013 /* The symbols will never be the last or the first
3014 because : 1st symbol is .file and 3 last symbols are
3015 .text, .data, .bss. */
3016 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
3017 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
3018 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3019 symbolP
= real_symbolP
;
3022 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
3023 S_SET_SEGMENT (symbolP
, SEG_E0
);
3025 resolve_symbol_value (symbolP
);
3027 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
3029 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
3031 S_SET_EXTERNAL (symbolP
);
3034 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
3035 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
3038 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3041 /* Mainly to speed up if not -g. */
3042 if (SF_GET_PROCESS (symbolP
))
3044 /* Handle the nested blocks auxiliary info. */
3045 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
3047 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
3048 stack_push (block_stack
, (char *) &symbolP
);
3052 symbolS
*begin_symbolP
;
3054 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
3055 if (begin_symbolP
== (symbolS
*) 0)
3056 as_warn (_("mismatched .eb"));
3058 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
3061 /* If we are able to identify the type of a function, and we
3062 are out of a function (last_functionP == 0) then, the
3063 function symbol will be associated with an auxiliary
3065 if (last_functionP
== (symbolS
*) 0 &&
3066 SF_GET_FUNCTION (symbolP
))
3068 last_functionP
= symbolP
;
3070 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3071 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3073 /* Clobber possible stale .dim information. */
3075 /* Iffed out by steve - this fries the lnnoptr info too. */
3076 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3077 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3080 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3082 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3084 if (last_bfP
!= NULL
)
3085 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3089 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3091 /* I don't even know if this is needed for sdb. But
3092 the standard assembler generates it, so... */
3093 if (last_functionP
== (symbolS
*) 0)
3094 as_fatal (_("C_EFCN symbol out of scope"));
3095 SA_SET_SYM_FSIZE (last_functionP
,
3096 (long) (S_GET_VALUE (symbolP
) -
3097 S_GET_VALUE (last_functionP
)));
3098 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3099 last_functionP
= (symbolS
*) 0;
3103 else if (SF_GET_TAG (symbolP
))
3105 /* First descriptor of a structure must point to
3106 the first slot after the structure description. */
3107 last_tagP
= symbolP
;
3110 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3112 /* +2 take in account the current symbol. */
3113 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3115 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3117 /* If the filename was too long to fit in the
3118 auxent, put it in the string table. */
3119 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3120 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3122 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3123 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3124 filename_list_scan
= filename_list_scan
->next
;
3126 if (S_GET_VALUE (symbolP
))
3128 S_SET_VALUE (symbolP
, last_file_symno
);
3129 last_file_symno
= symbol_number
;
3133 #ifdef tc_frob_coff_symbol
3134 tc_frob_coff_symbol (symbolP
);
3137 /* We must put the external symbols apart. The loader
3138 does not bomb if we do not. But the references in
3139 the endndx field for a .bb symbol are not corrected
3140 if an external symbol is removed between .bb and .be.
3141 I.e in the following case :
3142 [20] .bb endndx = 22
3145 ld will move the symbol 21 to the end of the list but
3146 endndx will still be 22 instead of 21. */
3148 if (SF_GET_LOCAL (symbolP
))
3150 /* Remove C_EFCN and LOCAL (L...) symbols. */
3151 /* Next pointer remains valid. */
3152 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3155 else if (symbolP
->sy_value
.X_op
== O_symbol
3156 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3158 /* Skip symbols which were equated to undefined or common
3160 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3162 else if (!S_IS_DEFINED (symbolP
)
3163 && !S_IS_DEBUG (symbolP
)
3164 && !SF_GET_STATICS (symbolP
)
3165 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3167 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3169 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3171 /* If external, Remove from the list. */
3172 symbolS
*hold
= symbol_previous (symbolP
);
3174 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3175 symbol_clear_list_pointers (symbolP
);
3176 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3179 else if (! S_IS_DEBUG (symbolP
)
3180 && ! SF_GET_STATICS (symbolP
)
3181 && ! SF_GET_FUNCTION (symbolP
)
3182 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3184 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3186 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3188 symbolS
*hold
= symbol_previous (symbolP
);
3190 /* The O'Reilly COFF book says that defined global symbols
3191 come at the end of the symbol table, just before
3192 undefined global symbols. */
3193 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3194 symbol_clear_list_pointers (symbolP
);
3195 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3196 &symbol_global_lastP
);
3201 if (SF_GET_STRING (symbolP
))
3203 symbolP
->sy_name_offset
= string_byte_count
;
3204 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3208 symbolP
->sy_name_offset
= 0;
3211 symbolP
->sy_number
= symbol_number
;
3212 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3216 return symbol_number
;
3220 glue_symbols (head
, tail
)
3224 unsigned int symbol_number
= 0;
3226 while (*head
!= NULL
)
3228 symbolS
*tmp
= *head
;
3231 symbol_remove (tmp
, head
, tail
);
3232 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3235 if (SF_GET_STRING (tmp
))
3237 tmp
->sy_name_offset
= string_byte_count
;
3238 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3242 /* Fix "long" names. */
3243 tmp
->sy_name_offset
= 0;
3246 tmp
->sy_number
= symbol_number
;
3247 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3250 return symbol_number
;
3256 unsigned int symbol_number
= 0;
3259 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3261 symbolP
->sy_number
= symbol_number
;
3263 if (SF_GET_TAGGED (symbolP
))
3267 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3270 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3273 return symbol_number
;
3278 crawl_symbols (h
, abfd
)
3280 bfd
*abfd ATTRIBUTE_UNUSED
;
3284 /* Initialize the stack used to keep track of the matching .bb .be. */
3286 block_stack
= stack_init (512, sizeof (symbolS
*));
3288 /* The symbol list should be ordered according to the following sequence
3291 . debug entries for functions
3292 . fake symbols for the sections, including .text .data and .bss
3295 But this is not mandatory. The only important point is to put the
3296 undefined symbols at the end of the list. */
3298 /* Is there a .file symbol ? If not insert one at the beginning. */
3299 if (symbol_rootP
== NULL
3300 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3301 c_dot_file_symbol ("fake");
3303 /* Build up static symbols for the sections, they are filled in later. */
3305 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3306 if (segment_info
[i
].scnhdr
.s_name
[0])
3307 segment_info
[i
].dot
= c_section_symbol ((char *) segment_info
[i
].name
,
3310 /* Take all the externals out and put them into another chain. */
3311 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3312 /* Take the externals and glue them onto the end. */
3313 H_SET_SYMBOL_TABLE_SIZE (h
,
3314 (H_GET_SYMBOL_COUNT (h
)
3315 + glue_symbols (&symbol_globalP
,
3316 &symbol_global_lastP
)
3317 + glue_symbols (&symbol_externP
,
3318 &symbol_extern_lastP
)));
3320 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3321 know (symbol_globalP
== NULL
);
3322 know (symbol_global_lastP
== NULL
);
3323 know (symbol_externP
== NULL
);
3324 know (symbol_extern_lastP
== NULL
);
3327 /* Find strings by crawling along symbol table chain. */
3334 struct filename_list
*filename_list_scan
= filename_list_head
;
3336 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK. */
3337 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3340 #ifdef COFF_LONG_SECTION_NAMES
3341 /* Support long section names as found in PE. This code must
3342 coordinate with that in coff_header_append and write_object_file. */
3346 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3348 if (segment_info
[i
].scnhdr
.s_name
[0]
3349 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3353 size
= strlen (segment_info
[i
].name
) + 1;
3354 memcpy (where
, segment_info
[i
].name
, size
);
3359 #endif /* COFF_LONG_SECTION_NAMES */
3361 for (symbolP
= symbol_rootP
;
3363 symbolP
= symbol_next (symbolP
))
3367 if (SF_GET_STRING (symbolP
))
3369 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3370 memcpy (where
, S_GET_NAME (symbolP
), size
);
3373 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3374 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3375 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3377 size
= strlen (filename_list_scan
->filename
) + 1;
3378 memcpy (where
, filename_list_scan
->filename
, size
);
3379 filename_list_scan
= filename_list_scan
->next
;
3386 do_linenos_for (abfd
, h
, file_cursor
)
3389 unsigned long *file_cursor
;
3392 unsigned long start
= *file_cursor
;
3394 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3396 segment_info_type
*s
= segment_info
+ idx
;
3398 if (s
->scnhdr
.s_nlnno
!= 0)
3400 struct lineno_list
*line_ptr
;
3402 struct external_lineno
*buffer
=
3403 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3405 struct external_lineno
*dst
= buffer
;
3407 /* Run through the table we've built and turn it into its external
3408 form, take this chance to remove duplicates. */
3410 for (line_ptr
= s
->lineno_list_head
;
3411 line_ptr
!= (struct lineno_list
*) NULL
;
3412 line_ptr
= line_ptr
->next
)
3414 if (line_ptr
->line
.l_lnno
== 0)
3416 /* Turn a pointer to a symbol into the symbols' index,
3417 provided that it has been initialised. */
3418 if (line_ptr
->line
.l_addr
.l_symndx
)
3419 line_ptr
->line
.l_addr
.l_symndx
=
3420 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3423 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3425 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3429 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3431 bfd_bwrite (buffer
, (bfd_size_type
) s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3434 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3438 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3441 /* Now we run through the list of frag chains in a segment and
3442 make all the subsegment frags appear at the end of the
3443 list, as if the seg 0 was extra long. */
3450 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3452 frchainS
*head
= segment_info
[i
].frchainP
;
3454 fragS
*prev_frag
= &dummy
;
3456 while (head
&& head
->frch_seg
== i
)
3458 prev_frag
->fr_next
= head
->frch_root
;
3459 prev_frag
= head
->frch_last
;
3460 head
= head
->frch_next
;
3462 prev_frag
->fr_next
= 0;
3466 unsigned long machine
;
3469 #ifndef SUB_SEGMENT_ALIGN
3471 /* The last subsegment gets an alignment corresponding to the alignment
3472 of the section. This allows proper nop-filling at the end of
3473 code-bearing sections. */
3474 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
3475 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \
3476 ? get_recorded_alignment (SEG) : 0)
3478 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 1
3483 write_object_file ()
3487 struct frchain
*frchain_ptr
;
3489 object_headers headers
;
3490 unsigned long file_cursor
;
3493 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3497 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3498 exit (EXIT_FAILURE
);
3500 bfd_set_format (abfd
, bfd_object
);
3501 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3503 string_byte_count
= 4;
3505 /* Run through all the sub-segments and align them up. Also
3506 close any open frags. We tack a .fill onto the end of the
3507 frag chain so that any .align's size can be worked by looking
3508 at the next frag. */
3509 for (frchain_ptr
= frchain_root
;
3510 frchain_ptr
!= (struct frchain
*) NULL
;
3511 frchain_ptr
= frchain_ptr
->frch_next
)
3515 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3517 alignment
= SUB_SEGMENT_ALIGN (now_seg
, frchain_ptr
);
3520 md_do_align (alignment
, (char *) NULL
, 0, 0, alignment_done
);
3522 if (subseg_text_p (now_seg
))
3523 frag_align_code (alignment
, 0);
3525 frag_align (alignment
, 0, 0);
3531 frag_wane (frag_now
);
3532 frag_now
->fr_fix
= 0;
3533 know (frag_now
->fr_next
== NULL
);
3538 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3539 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3541 /* Relaxation has completed. Freeze all syms. */
3544 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3546 /* Find out how big the sections are, and set the addresses. */
3548 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3552 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3553 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3555 if (segment_info
[i
].scnhdr
.s_name
[0])
3557 H_SET_NUMBER_OF_SECTIONS (&headers
,
3558 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3560 #ifdef COFF_LONG_SECTION_NAMES
3561 /* Support long section names as found in PE. This code
3562 must coordinate with that in coff_header_append and
3567 len
= strlen (segment_info
[i
].name
);
3569 string_byte_count
+= len
+ 1;
3571 #endif /* COFF_LONG_SECTION_NAMES */
3574 size
= size_section (abfd
, (unsigned int) i
);
3577 /* I think the section alignment is only used on the i960; the
3578 i960 needs it, and it should do no harm on other targets. */
3579 #ifdef ALIGNMENT_IN_S_FLAGS
3580 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3582 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3586 H_SET_TEXT_SIZE (&headers
, size
);
3587 else if (i
== SEG_E1
)
3588 H_SET_DATA_SIZE (&headers
, size
);
3589 else if (i
== SEG_E2
)
3590 H_SET_BSS_SIZE (&headers
, size
);
3593 /* Turn the gas native symbol table shape into a coff symbol table. */
3594 crawl_symbols (&headers
, abfd
);
3596 if (string_byte_count
== 4)
3597 string_byte_count
= 0;
3599 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3605 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3607 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3608 fixup_segment (&segment_info
[i
], i
);
3611 /* Look for ".stab" segments and fill in their initial symbols
3613 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3615 name
= segment_info
[i
].name
;
3618 && strncmp (".stab", name
, 5) == 0
3619 && strncmp (".stabstr", name
, 8) != 0)
3620 adjust_stab_section (abfd
, i
);
3623 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3625 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3627 /* Plant the data. */
3628 fill_section (abfd
, &headers
, &file_cursor
);
3630 do_relocs_for (abfd
, &headers
, &file_cursor
);
3632 do_linenos_for (abfd
, &headers
, &file_cursor
);
3634 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3635 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3636 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3638 H_SET_TIME_STAMP (&headers
, 0);
3640 #ifdef TC_COFF_SET_MACHINE
3641 TC_COFF_SET_MACHINE (&headers
);
3645 #define COFF_FLAGS 0
3648 #ifdef KEEP_RELOC_INFO
3649 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3650 COFF_FLAGS
| coff_flags
));
3652 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3653 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3654 COFF_FLAGS
| coff_flags
));
3658 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3659 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3661 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3662 w_symbols (abfd
, buffer1
, symbol_rootP
);
3663 if (string_byte_count
> 0)
3664 w_strings (buffer1
+ symtable_size
);
3665 bfd_bwrite (buffer1
, (bfd_size_type
) symtable_size
+ string_byte_count
,
3670 coff_header_append (abfd
, &headers
);
3672 /* Recent changes to write need this, but where it should
3673 go is up to Ken.. */
3674 if (!bfd_close_all_done (abfd
))
3675 as_fatal (_("Can't close %s: %s"), out_file_name
,
3676 bfd_errmsg (bfd_get_error ()));
3679 extern bfd
*stdoutput
;
3686 /* Add a new segment. This is called from subseg_new via the
3687 obj_new_segment macro. */
3690 obj_coff_add_segment (name
)
3695 #ifndef COFF_LONG_SECTION_NAMES
3696 char buf
[SCNNMLEN
+ 1];
3698 strncpy (buf
, name
, SCNNMLEN
);
3699 buf
[SCNNMLEN
] = '\0';
3703 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3704 if (strcmp (name
, segment_info
[i
].name
) == 0)
3709 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3713 /* Add a new section. */
3714 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3715 sizeof (segment_info
[i
].scnhdr
.s_name
));
3716 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3717 segment_info
[i
].name
= xstrdup (name
);
3722 /* Implement the .section pseudo op:
3723 .section name {, "flags"}
3725 | +--- optional flags: 'b' for bss
3727 +-- section name 'l' for lib
3731 'd' (apparently m88k for data)
3733 'r' for read-only data
3734 But if the argument is not a quoted string, treat it as a
3735 subsegment number. */
3738 obj_coff_section (ignore
)
3739 int ignore ATTRIBUTE_UNUSED
;
3741 /* Strip out the section name. */
3742 char *section_name
, *name
;
3755 else if (type
== 'D')
3757 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3762 section_name
= input_line_pointer
;
3763 c
= get_symbol_end ();
3765 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3766 strcpy (name
, section_name
);
3768 *input_line_pointer
= c
;
3774 if (*input_line_pointer
== ',')
3776 ++input_line_pointer
;
3779 if (*input_line_pointer
!= '"')
3780 exp
= get_absolute_expression ();
3783 ++input_line_pointer
;
3784 while (*input_line_pointer
!= '"'
3785 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3787 switch (*input_line_pointer
)
3789 case 'b': flags
|= STYP_BSS
; break;
3790 case 'i': flags
|= STYP_INFO
; break;
3791 case 'l': flags
|= STYP_LIB
; break;
3792 case 'n': flags
|= STYP_NOLOAD
; break;
3793 case 'o': flags
|= STYP_OVER
; break;
3795 case 'w': flags
|= STYP_DATA
; break;
3796 case 'x': flags
|= STYP_TEXT
; break;
3797 case 'r': flags
|= STYP_LIT
; break;
3799 as_warn(_("unknown section attribute '%c'"),
3800 *input_line_pointer
);
3803 ++input_line_pointer
;
3805 if (*input_line_pointer
== '"')
3806 ++input_line_pointer
;
3810 subseg_new (name
, (subsegT
) exp
);
3812 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3814 demand_empty_rest_of_line ();
3818 obj_coff_text (ignore
)
3819 int ignore ATTRIBUTE_UNUSED
;
3821 subseg_new (".text", get_absolute_expression ());
3825 obj_coff_data (ignore
)
3826 int ignore ATTRIBUTE_UNUSED
;
3828 if (flag_readonly_data_in_text
)
3829 subseg_new (".text", get_absolute_expression () + 1000);
3831 subseg_new (".data", get_absolute_expression ());
3835 obj_coff_ident (ignore
)
3836 int ignore ATTRIBUTE_UNUSED
;
3838 segT current_seg
= now_seg
; /* Save current seg. */
3839 subsegT current_subseg
= now_subseg
;
3841 subseg_new (".comment", 0); /* .comment seg. */
3842 stringer (1); /* Read string. */
3843 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
3847 c_symbol_merge (debug
, normal
)
3851 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3852 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3854 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3855 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3857 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3858 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3859 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3860 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3862 /* Move the debug flags. */
3863 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3867 c_line_new (symbol
, paddr
, line_number
, frag
)
3873 struct lineno_list
*new_line
=
3874 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3876 segment_info_type
*s
= segment_info
+ now_seg
;
3877 new_line
->line
.l_lnno
= line_number
;
3879 if (line_number
== 0)
3881 last_line_symbol
= symbol
;
3882 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3886 new_line
->line
.l_addr
.l_paddr
= paddr
;
3889 new_line
->frag
= (char *) frag
;
3890 new_line
->next
= (struct lineno_list
*) NULL
;
3892 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3893 s
->lineno_list_head
= new_line
;
3895 s
->lineno_list_tail
->next
= new_line
;
3897 s
->lineno_list_tail
= new_line
;
3898 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3902 c_dot_file_symbol (filename
)
3907 symbolP
= symbol_new (".file",
3910 &zero_address_frag
);
3912 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3913 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3915 if (strlen (filename
) > FILNMLEN
)
3917 /* Filename is too long to fit into an auxent,
3918 we stick it into the string table instead. We keep
3919 a linked list of the filenames we find so we can emit
3921 struct filename_list
*f
= ((struct filename_list
*)
3922 xmalloc (sizeof (struct filename_list
)));
3924 f
->filename
= filename
;
3927 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3928 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3930 if (filename_list_tail
)
3931 filename_list_tail
->next
= f
;
3933 filename_list_head
= f
;
3934 filename_list_tail
= f
;
3938 SA_SET_FILE_FNAME (symbolP
, filename
);
3944 listing_source_file (filename
);
3947 SF_SET_DEBUG (symbolP
);
3948 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3950 previous_file_symbol
= symbolP
;
3952 /* Make sure that the symbol is first on the symbol chain. */
3953 if (symbol_rootP
!= symbolP
)
3955 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3956 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3960 /* Build a 'section static' symbol. */
3963 c_section_symbol (name
, idx
)
3969 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3970 if (symbolP
== NULL
)
3971 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3974 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3975 S_SET_SEGMENT (symbolP
, idx
);
3976 symbolP
->sy_frag
= &zero_address_frag
;
3979 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3980 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3982 SF_SET_STATICS (symbolP
);
3985 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3986 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3987 SF_CLEAR_LOCAL (symbolP
);
3990 /* If the .linkonce pseudo-op was used for this section, we must
3991 store the information in the auxiliary entry for the section
3993 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3997 switch (segment_info
[idx
].linkonce
)
4001 case LINKONCE_DISCARD
:
4002 type
= IMAGE_COMDAT_SELECT_ANY
;
4004 case LINKONCE_ONE_ONLY
:
4005 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
4007 case LINKONCE_SAME_SIZE
:
4008 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
4010 case LINKONCE_SAME_CONTENTS
:
4011 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
4015 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
4023 w_symbols (abfd
, where
, symbol_rootP
)
4026 symbolS
* symbol_rootP
;
4031 /* First fill in those values we have only just worked out. */
4032 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
4034 symbolP
= segment_info
[i
].dot
;
4037 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
4038 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
4039 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
4043 /* Emit all symbols left in the symbol chain. */
4044 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
4046 /* Used to save the offset of the name. It is used to point
4047 to the string in memory but must be a file offset. */
4050 /* We can't fix the lnnoptr field in yank_symbols with the other
4051 adjustments, because we have to wait until we know where they
4053 if (SF_GET_ADJ_LNNOPTR (symbolP
))
4054 SA_GET_SYM_LNNOPTR (symbolP
) +=
4055 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4057 tc_coff_symbol_emit_hook (symbolP
);
4059 temp
= S_GET_NAME (symbolP
);
4060 if (SF_GET_STRING (symbolP
))
4062 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4063 S_SET_ZEROES (symbolP
, 0);
4067 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4068 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4070 where
= symbol_to_chars (abfd
, where
, symbolP
);
4071 S_SET_NAME (symbolP
, temp
);
4076 obj_coff_lcomm (ignore
)
4077 int ignore ATTRIBUTE_UNUSED
;
4089 name
= input_line_pointer
;
4091 c
= get_symbol_end ();
4092 p
= input_line_pointer
;
4095 if (*input_line_pointer
!= ',')
4097 as_bad (_("Expected comma after name"));
4098 ignore_rest_of_line ();
4101 if (*input_line_pointer
== '\n')
4103 as_bad (_("Missing size expression"));
4106 input_line_pointer
++;
4107 if ((temp
= get_absolute_expression ()) < 0)
4109 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4110 ignore_rest_of_line ();
4115 symbolP
= symbol_find_or_make (name
);
4117 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
&&
4118 S_GET_VALUE (symbolP
) == 0)
4123 segT current_seg
= now_seg
; /* Save current seg. */
4124 subsegT current_subseg
= now_subseg
;
4126 subseg_set (SEG_E2
, 1);
4127 symbolP
->sy_frag
= frag_now
;
4128 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4129 (offsetT
) temp
, (char *) 0);
4131 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
4132 S_SET_SEGMENT (symbolP
, SEG_E2
);
4133 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4137 as_bad (_("Symbol %s already defined"), name
);
4139 demand_empty_rest_of_line ();
4144 fixup_mdeps (frags
, h
, this_segment
)
4146 object_headers
*h ATTRIBUTE_UNUSED
;
4149 subseg_change (this_segment
, 0);
4153 switch (frags
->fr_type
)
4160 HANDLE_ALIGN (frags
);
4162 frags
->fr_type
= rs_fill
;
4164 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4167 case rs_machine_dependent
:
4168 md_convert_frag (h
, this_segment
, frags
);
4174 frags
= frags
->fr_next
;
4180 #ifndef TC_FORCE_RELOCATION
4181 #define TC_FORCE_RELOCATION(fix) 0
4185 fixup_segment (segP
, this_segment_type
)
4186 segment_info_type
* segP
;
4187 segT this_segment_type
;
4190 symbolS
*add_symbolP
;
4191 symbolS
*sub_symbolP
;
4198 segT add_symbol_segment
= absolute_section
;
4200 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4202 fragP
= fixP
->fx_frag
;
4204 where
= fixP
->fx_where
;
4205 place
= fragP
->fr_literal
+ where
;
4206 size
= fixP
->fx_size
;
4207 add_symbolP
= fixP
->fx_addsy
;
4208 sub_symbolP
= fixP
->fx_subsy
;
4209 add_number
= fixP
->fx_offset
;
4210 pcrel
= fixP
->fx_pcrel
;
4212 /* We want function-relative stabs to work on systems which
4213 may use a relaxing linker; thus we must handle the sym1-sym2
4214 fixups function-relative stabs generates.
4216 Of course, if you actually enable relaxing in the linker, the
4217 line and block scoping information is going to be incorrect
4218 in some cases. The only way to really fix this is to support
4219 a reloc involving the difference of two symbols. */
4221 && (!sub_symbolP
|| pcrel
))
4225 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4227 /* Relocation should be done via the associated 'bal' entry
4230 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4232 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4233 _("No 'bal' entry point for leafproc %s"),
4234 S_GET_NAME (add_symbolP
));
4237 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4241 /* Make sure the symbols have been resolved; this may not have
4242 happened if these are expression symbols. */
4243 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4244 resolve_symbol_value (add_symbolP
);
4246 if (add_symbolP
!= NULL
)
4248 /* If this fixup is against a symbol which has been equated
4249 to another symbol, convert it to the other symbol. */
4250 if (add_symbolP
->sy_value
.X_op
== O_symbol
4251 && (! S_IS_DEFINED (add_symbolP
)
4252 || S_IS_COMMON (add_symbolP
)))
4254 while (add_symbolP
->sy_value
.X_op
== O_symbol
4255 && (! S_IS_DEFINED (add_symbolP
)
4256 || S_IS_COMMON (add_symbolP
)))
4260 /* We must avoid looping, as that can occur with a
4261 badly written program. */
4262 n
= add_symbolP
->sy_value
.X_add_symbol
;
4263 if (n
== add_symbolP
)
4265 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4268 fixP
->fx_addsy
= add_symbolP
;
4269 fixP
->fx_offset
= add_number
;
4273 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4274 resolve_symbol_value (sub_symbolP
);
4276 if (add_symbolP
!= NULL
4277 && add_symbolP
->sy_mri_common
)
4279 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4280 add_number
+= S_GET_VALUE (add_symbolP
);
4281 fixP
->fx_offset
= add_number
;
4282 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4286 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4290 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4292 if (add_symbolP
!= NULL
)
4294 add_number
+= S_GET_VALUE (add_symbolP
);
4296 fixP
->fx_addsy
= NULL
;
4299 /* It's just -sym. */
4300 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4302 add_number
-= S_GET_VALUE (sub_symbolP
);
4309 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4310 _("Negative of non-absolute symbol %s"),
4311 S_GET_NAME (sub_symbolP
));
4313 add_number
-= S_GET_VALUE (sub_symbolP
);
4314 } /* not absolute */
4316 /* if sub_symbol is in the same segment that add_symbol
4317 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE. */
4319 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4320 && SEG_NORMAL (add_symbol_segment
))
4322 /* Difference of 2 symbols from same segment. Can't
4323 make difference of 2 undefineds: 'value' means
4324 something different for N_UNDF. */
4326 /* Makes no sense to use the difference of 2 arbitrary symbols
4327 as the target of a call instruction. */
4329 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4330 _("callj to difference of 2 symbols"));
4331 #endif /* TC_I960 */
4332 add_number
+= S_GET_VALUE (add_symbolP
) -
4333 S_GET_VALUE (sub_symbolP
);
4336 if (!TC_FORCE_RELOCATION (fixP
))
4338 fixP
->fx_addsy
= NULL
;
4339 fixP
->fx_subsy
= NULL
;
4341 #ifdef TC_M68K /* is this right? */
4349 /* Different segments in subtraction. */
4350 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4352 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4353 add_number
-= S_GET_VALUE (sub_symbolP
);
4356 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4357 #if 0 /* Okay for 68k, at least... */
4362 /* Make it pc-relative. */
4363 add_number
+= (md_pcrel_from (fixP
)
4364 - S_GET_VALUE (sub_symbolP
));
4373 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4374 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4375 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4376 S_GET_NAME (sub_symbolP
),
4377 (long) (fragP
->fr_address
+ where
));
4384 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4386 /* This fixup was made when the symbol's segment was
4387 SEG_UNKNOWN, but it is now in the local segment.
4388 So we know how to do the address without relocation. */
4390 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4391 in which cases it modifies *fixP as appropriate. In the case
4392 of a 'calls', no further work is required, and *fixP has been
4393 set up to make the rest of the code below a no-op. */
4395 #endif /* TC_I960 */
4397 add_number
+= S_GET_VALUE (add_symbolP
);
4398 add_number
-= md_pcrel_from (fixP
);
4401 add_number -= segP->scnhdr.s_vaddr;
4402 if defined (TC_I386) || defined (TE_LYNX). I now
4403 think that was an error propagated from the case when
4404 we are going to emit the relocation. If we are not
4405 going to emit the relocation, then we just want to
4406 set add_number to the difference between the symbols.
4407 This is a case that would only arise when there is a
4408 PC relative reference from a section other than .text
4409 to a symbol defined in the same section, and the
4410 reference is not relaxed. Since jump instructions on
4411 the i386 are relaxed, this could only arise with a
4412 call instruction. */
4414 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4415 if (!TC_FORCE_RELOCATION (fixP
))
4417 fixP
->fx_addsy
= NULL
;
4423 switch (add_symbol_segment
)
4425 case absolute_section
:
4427 /* See comment about reloc_callj() above. */
4429 #endif /* TC_I960 */
4430 add_number
+= S_GET_VALUE (add_symbolP
);
4433 if (!TC_FORCE_RELOCATION (fixP
))
4435 fixP
->fx_addsy
= NULL
;
4441 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4442 /* This really should be handled in the linker, but
4443 backward compatibility forbids. */
4444 add_number
+= S_GET_VALUE (add_symbolP
);
4446 add_number
+= S_GET_VALUE (add_symbolP
) +
4447 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4453 if ((int) fixP
->fx_bit_fixP
== 13)
4455 /* This is a COBR instruction. They have only a
4456 13-bit displacement and are only to be used
4457 for local branches: flag as error, don't generate
4459 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4460 _("can't use COBR format with external label"));
4461 fixP
->fx_addsy
= NULL
;
4465 #endif /* TC_I960 */
4466 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4467 /* 386 COFF uses a peculiar format in which the
4468 value of a common symbol is stored in the .text
4469 segment (I've checked this on SVR3.2 and SCO
4470 3.2.2) Ian Taylor <ian@cygnus.com>. */
4471 /* This is also true for 68k COFF on sysv machines
4472 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4473 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4474 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4475 if (S_IS_COMMON (add_symbolP
))
4476 add_number
+= S_GET_VALUE (add_symbolP
);
4486 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) && !defined(TC_OR32)
4487 /* This adjustment is not correct on the m88k, for which the
4488 linker does all the computation. */
4489 add_number
-= md_pcrel_from (fixP
);
4491 if (add_symbolP
== 0)
4492 fixP
->fx_addsy
= &abs_symbol
;
4493 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4494 /* On the 386 we must adjust by the segment vaddr as well.
4497 I changed the i960 to work this way as well. This is
4498 compatible with the current GNU linker behaviour. I do
4499 not know what other i960 COFF assemblers do. This is not
4500 a common case: normally, only assembler code will contain
4501 a PC relative reloc, and only branches which do not
4502 originate in the .text section will have a non-zero
4505 I changed the m68k to work this way as well. This will
4506 break existing PC relative relocs from sections which do
4507 not start at address 0, but it will make ld -r work.
4508 Ian Taylor, 4 Oct 96. */
4510 add_number
-= segP
->scnhdr
.s_vaddr
;
4514 md_apply_fix3 (fixP
, (valueT
*) & add_number
, this_segment_type
);
4516 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4519 /* The m88k uses the offset field of the reloc to get around
4522 && ((add_number
& ~0xFF)
4523 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4524 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4525 || (add_number
& 0x80) == 0))
4527 && ((add_number
& ~0xFFFF)
4528 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4529 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4530 || (add_number
& 0x8000) == 0)))
4532 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4533 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4534 (long) add_number
, size
,
4535 (unsigned long) (fragP
->fr_address
+ where
));
4538 #ifdef WARN_SIGNED_OVERFLOW_WORD
4539 /* Warn if a .word value is too large when treated as a
4540 signed number. We already know it is not too negative.
4541 This is to catch over-large switches generated by gcc on
4543 if (!flag_signed_overflow_ok
4545 && add_number
> 0x7fff)
4546 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4547 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4549 (unsigned long) (fragP
->fr_address
+ where
));
4557 /* The first entry in a .stab section is special. */
4560 obj_coff_init_stab_section (seg
)
4566 unsigned int stroff
;
4568 /* Make space for this first symbol. */
4572 as_where (&file
, (unsigned int *) NULL
);
4573 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4574 strcpy (stabstr_name
, segment_info
[seg
].name
);
4575 strcat (stabstr_name
, "str");
4576 stroff
= get_stab_string_offset (file
, stabstr_name
);
4578 md_number_to_chars (p
, stroff
, 4);
4581 /* Fill in the counts in the first entry in a .stab section. */
4584 adjust_stab_section(abfd
, seg
)
4588 segT stabstrseg
= SEG_UNKNOWN
;
4589 const char *secname
, *name2
;
4592 int i
, strsz
= 0, nsyms
;
4593 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4595 /* Look for the associated string table section. */
4597 secname
= segment_info
[seg
].name
;
4598 name
= (char *) alloca (strlen (secname
) + 4);
4599 strcpy (name
, secname
);
4600 strcat (name
, "str");
4602 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4604 name2
= segment_info
[i
].name
;
4605 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4612 /* If we found the section, get its size. */
4613 if (stabstrseg
!= SEG_UNKNOWN
)
4614 strsz
= size_section (abfd
, stabstrseg
);
4616 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4618 /* Look for the first frag of sufficient size for the initial stab
4619 symbol, and collect a pointer to it. */
4620 while (frag
&& frag
->fr_fix
< 12)
4621 frag
= frag
->fr_next
;
4623 p
= frag
->fr_literal
;
4626 /* Write in the number of stab symbols and the size of the string
4628 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4629 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4632 #endif /* not BFD_ASSEMBLER */
4634 const pseudo_typeS coff_pseudo_table
[] =
4636 {"def", obj_coff_def
, 0},
4637 {"dim", obj_coff_dim
, 0},
4638 {"endef", obj_coff_endef
, 0},
4639 {"line", obj_coff_line
, 0},
4640 {"ln", obj_coff_ln
, 0},
4641 #ifdef BFD_ASSEMBLER
4642 {"loc", obj_coff_loc
, 0},
4644 {"appline", obj_coff_ln
, 1},
4645 {"scl", obj_coff_scl
, 0},
4646 {"size", obj_coff_size
, 0},
4647 {"tag", obj_coff_tag
, 0},
4648 {"type", obj_coff_type
, 0},
4649 {"val", obj_coff_val
, 0},
4650 {"section", obj_coff_section
, 0},
4651 {"sect", obj_coff_section
, 0},
4652 /* FIXME: We ignore the MRI short attribute. */
4653 {"section.s", obj_coff_section
, 0},
4654 {"sect.s", obj_coff_section
, 0},
4655 /* We accept the .bss directive for backward compatibility with
4656 earlier versions of gas. */
4657 {"bss", obj_coff_bss
, 0},
4658 {"ident", obj_coff_ident
, 0},
4659 #ifndef BFD_ASSEMBLER
4660 {"use", obj_coff_section
, 0},
4661 {"text", obj_coff_text
, 0},
4662 {"data", obj_coff_data
, 0},
4663 {"lcomm", obj_coff_lcomm
, 0},
4665 {"weak", obj_coff_weak
, 0},
4666 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4668 {"version", s_ignore
, 0},
4669 {"ABORT", s_abort
, 0},
4670 #if defined( TC_M88K ) || defined ( TC_TIC4X )
4671 /* The m88k and tic4x uses sdef instead of def. */
4672 {"sdef", obj_coff_def
, 0},
4674 {NULL
, NULL
, 0} /* end sentinel */
4675 }; /* coff_pseudo_table */
4677 #ifdef BFD_ASSEMBLER
4679 /* Support for a COFF emulation. */
4681 static void coff_pop_insert
PARAMS ((void));
4682 static int coff_separate_stab_sections
PARAMS ((void));
4687 pop_insert (coff_pseudo_table
);
4691 coff_separate_stab_sections ()
4696 const struct format_ops coff_format_ops
=
4698 bfd_target_coff_flavour
,
4699 0, /* dfl_leading_underscore */
4700 1, /* emit_section_symbols */
4705 0, /* frob_file_before_adjust */
4706 0, /* frob_file_before_fix */
4707 coff_frob_file_after_relocs
,
4710 0, /* s_get_align */
4711 0, /* s_set_align */
4712 0, /* s_get_other */
4713 0, /* s_set_other */
4718 0, /* copy_symbol_attributes */
4719 0, /* generate_asm_lineno */
4720 0, /* process_stab */
4721 coff_separate_stab_sections
,
4722 obj_coff_init_stab_section
,
4723 0, /* sec_sym_ok_for_reloc */
4725 0, /* ecoff_set_ext */
4726 coff_obj_read_begin_hook
,
4727 coff_obj_symbol_new_hook