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"
33 /* I think this is probably always correct. */
34 #ifndef KEEP_RELOC_INFO
35 #define KEEP_RELOC_INFO
38 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
39 a new section's attributes when a directive has no valid flags or the
40 "w" flag is used. This default should be appropriate for most. */
41 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
42 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
45 /* This is used to hold the symbol built by a sequence of pseudo-ops
46 from .def and .endef. */
47 static symbolS
*def_symbol_in_progress
;
49 /* PE weak alternate symbols begin with this string. */
50 static const char weak_altprefix
[] = ".weak.";
55 unsigned long chunk_size
;
56 unsigned long element_size
;
59 unsigned long pointer
;
63 static stack
*stack_init
PARAMS ((unsigned long, unsigned long));
64 static char *stack_push
PARAMS ((stack
*, char *));
65 static char *stack_pop
PARAMS ((stack
*));
66 static void tag_init
PARAMS ((void));
67 static void tag_insert
PARAMS ((const char *, symbolS
*));
68 static symbolS
*tag_find
PARAMS ((char *));
69 static symbolS
*tag_find_or_make
PARAMS ((char *));
70 static void obj_coff_bss
PARAMS ((int));
72 static void obj_coff_weak
PARAMS ((int));
74 const char *s_get_name
PARAMS ((symbolS
* s
));
75 static void obj_coff_ln
PARAMS ((int));
76 static void obj_coff_def
PARAMS ((int));
77 static void obj_coff_endef
PARAMS ((int));
78 static void obj_coff_dim
PARAMS ((int));
79 static void obj_coff_line
PARAMS ((int));
80 static void obj_coff_size
PARAMS ((int));
81 static void obj_coff_scl
PARAMS ((int));
82 static void obj_coff_tag
PARAMS ((int));
83 static void obj_coff_val
PARAMS ((int));
84 static void obj_coff_type
PARAMS ((int));
85 static void obj_coff_ident
PARAMS ((int));
87 static void obj_coff_loc
PARAMS((int));
93 stack_init (chunk_size
, element_size
)
94 unsigned long chunk_size
;
95 unsigned long element_size
;
99 st
= (stack
*) malloc (sizeof (stack
));
102 st
->data
= malloc (chunk_size
);
109 st
->size
= chunk_size
;
110 st
->chunk_size
= chunk_size
;
111 st
->element_size
= element_size
;
116 /* Not currently used. */
127 stack_push (st
, element
)
131 if (st
->pointer
+ st
->element_size
>= st
->size
)
133 st
->size
+= st
->chunk_size
;
134 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
137 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
138 st
->pointer
+= st
->element_size
;
139 return st
->data
+ st
->pointer
;
146 if (st
->pointer
< st
->element_size
)
151 st
->pointer
-= st
->element_size
;
152 return st
->data
+ st
->pointer
;
156 * Maintain a list of the tagnames of the structures.
159 static struct hash_control
*tag_hash
;
164 tag_hash
= hash_new ();
168 tag_insert (name
, symbolP
)
172 const char *error_string
;
174 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
176 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
185 #ifdef STRIP_UNDERSCORE
188 #endif /* STRIP_UNDERSCORE */
189 return (symbolS
*) hash_find (tag_hash
, name
);
193 tag_find_or_make (name
)
198 if ((symbolP
= tag_find (name
)) == NULL
)
200 symbolP
= symbol_new (name
, undefined_section
,
201 0, &zero_address_frag
);
203 tag_insert (S_GET_NAME (symbolP
), symbolP
);
205 symbol_table_insert (symbolP
);
212 /* We accept the .bss directive to set the section for backward
213 compatibility with earlier versions of gas. */
216 obj_coff_bss (ignore
)
217 int ignore ATTRIBUTE_UNUSED
;
219 if (*input_line_pointer
== '\n')
220 subseg_new (".bss", get_absolute_expression ());
227 static segT fetch_coff_debug_section
PARAMS ((void));
228 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
229 static int S_GET_DATA_TYPE
PARAMS ((symbolS
*));
230 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
231 static void add_lineno
PARAMS ((fragS
*, addressT
, int));
233 #define GET_FILENAME_STRING(X) \
234 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
238 fetch_coff_debug_section ()
240 static segT debug_section
;
244 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
246 debug_section
= s
->section
;
248 return debug_section
;
252 SA_SET_SYM_ENDNDX (sym
, val
)
256 combined_entry_type
*entry
, *p
;
258 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
259 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
260 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
265 SA_SET_SYM_TAGNDX (sym
, val
)
269 combined_entry_type
*entry
, *p
;
271 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
272 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
273 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
278 S_GET_DATA_TYPE (sym
)
281 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
285 S_SET_DATA_TYPE (sym
, val
)
289 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
294 S_GET_STORAGE_CLASS (sym
)
297 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
301 S_SET_STORAGE_CLASS (sym
, val
)
305 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
309 /* Merge a debug symbol containing debug information into a normal symbol. */
312 c_symbol_merge (debug
, normal
)
316 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
317 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
319 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
321 /* take the most we have */
322 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
325 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
327 /* Move all the auxiliary information. */
328 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
329 (S_GET_NUMBER_AUXILIARY (debug
)
330 * sizeof (*SYM_AUXINFO (debug
))));
333 /* Move the debug flags. */
334 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
338 c_dot_file_symbol (filename
)
339 const char *filename
;
343 /* BFD converts filename to a .file symbol with an aux entry. It
344 also handles chaining. */
345 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
347 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
348 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
350 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
357 listing_source_file (filename
);
362 /* Make sure that the symbol is first on the symbol chain */
363 if (symbol_rootP
!= symbolP
)
365 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
366 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
367 } /* if not first on the list */
370 /* Line number handling */
373 struct line_no
*next
;
380 /* Symbol of last function, which we should hang line#s off of. */
381 static symbolS
*line_fsym
;
383 #define in_function() (line_fsym != 0)
384 #define clear_function() (line_fsym = 0)
385 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
389 coff_obj_symbol_new_hook (symbolP
)
392 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
393 char * s
= (char *) xmalloc (sz
);
396 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
398 S_SET_DATA_TYPE (symbolP
, T_NULL
);
399 S_SET_STORAGE_CLASS (symbolP
, 0);
400 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
402 if (S_IS_STRING (symbolP
))
403 SF_SET_STRING (symbolP
);
405 if (S_IS_LOCAL (symbolP
))
406 SF_SET_LOCAL (symbolP
);
411 * Handle .ln directives.
414 static symbolS
*current_lineno_sym
;
415 static struct line_no
*line_nos
;
416 /* @@ Blindly assume all .ln directives will be in the .text section... */
420 add_lineno (frag
, offset
, num
)
425 struct line_no
*new_line
=
426 (struct line_no
*) xmalloc (sizeof (struct line_no
));
427 if (!current_lineno_sym
)
433 /* The native aix assembler accepts negative line number */
437 /* Zero is used as an end marker in the file. */
438 as_warn (_("Line numbers must be positive integers\n"));
441 #endif /* OBJ_XCOFF */
442 new_line
->next
= line_nos
;
443 new_line
->frag
= frag
;
444 new_line
->l
.line_number
= num
;
445 new_line
->l
.u
.offset
= offset
;
451 coff_add_linesym (sym
)
456 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
461 current_lineno_sym
= sym
;
465 obj_coff_ln (appline
)
470 if (! appline
&& def_symbol_in_progress
!= NULL
)
472 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
473 demand_empty_rest_of_line ();
477 l
= get_absolute_expression ();
479 /* If there is no lineno symbol, treat a .ln
480 directive as if it were a .appline directive. */
481 if (appline
|| current_lineno_sym
== NULL
)
482 new_logical_line ((char *) NULL
, l
- 1);
484 add_lineno (frag_now
, frag_now_fix (), l
);
493 l
+= coff_line_base
- 1;
494 listing_source_line (l
);
499 demand_empty_rest_of_line ();
502 /* .loc is essentially the same as .ln; parse it for assembler
506 obj_coff_loc (ignore
)
507 int ignore ATTRIBUTE_UNUSED
;
511 /* FIXME: Why do we need this check? We need it for ECOFF, but why
512 do we need it for COFF? */
513 if (now_seg
!= text_section
)
515 as_warn (_(".loc outside of .text"));
516 demand_empty_rest_of_line ();
520 if (def_symbol_in_progress
!= NULL
)
522 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
523 demand_empty_rest_of_line ();
527 /* Skip the file number. */
529 get_absolute_expression ();
532 lineno
= get_absolute_expression ();
540 lineno
+= coff_line_base
- 1;
541 listing_source_line (lineno
);
546 demand_empty_rest_of_line ();
548 add_lineno (frag_now
, frag_now_fix (), lineno
);
551 /* Handle the .ident pseudo-op. */
554 obj_coff_ident (ignore
)
555 int ignore ATTRIBUTE_UNUSED
;
557 segT current_seg
= now_seg
;
558 subsegT current_subseg
= now_subseg
;
564 /* We could put it in .comment, but that creates an extra section
565 that shouldn't be loaded into memory, which requires linker
566 changes... For now, until proven otherwise, use .rdata. */
567 sec
= subseg_new (".rdata$zzz", 0);
568 bfd_set_section_flags (stdoutput
, sec
,
569 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
570 & bfd_applicable_section_flags (stdoutput
)));
573 subseg_new (".comment", 0);
577 subseg_set (current_seg
, current_subseg
);
583 * Handle .def directives.
585 * One might ask : why can't we symbol_new if the symbol does not
586 * already exist and fill it with debug information. Because of
587 * the C_EFCN special symbol. It would clobber the value of the
588 * function symbol before we have a chance to notice that it is
589 * a C_EFCN. And a second reason is that the code is more clear this
590 * way. (at least I think it is :-).
594 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
595 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
596 *input_line_pointer == '\t') \
597 input_line_pointer++;
601 int what ATTRIBUTE_UNUSED
;
603 char name_end
; /* Char after the end of name */
604 char *symbol_name
; /* Name of the debug symbol */
605 char *symbol_name_copy
; /* Temporary copy of the name */
606 unsigned int symbol_name_length
;
608 if (def_symbol_in_progress
!= NULL
)
610 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
611 demand_empty_rest_of_line ();
613 } /* if not inside .def/.endef */
617 symbol_name
= input_line_pointer
;
618 #ifdef STRIP_UNDERSCORE
619 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
621 #endif /* STRIP_UNDERSCORE */
623 name_end
= get_symbol_end ();
624 symbol_name_length
= strlen (symbol_name
);
625 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
626 strcpy (symbol_name_copy
, symbol_name
);
627 #ifdef tc_canonicalize_symbol_name
628 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
631 /* Initialize the new symbol */
632 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
633 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
634 S_SET_VALUE (def_symbol_in_progress
, 0);
636 if (S_IS_STRING (def_symbol_in_progress
))
637 SF_SET_STRING (def_symbol_in_progress
);
639 *input_line_pointer
= name_end
;
641 demand_empty_rest_of_line ();
644 unsigned int dim_index
;
647 obj_coff_endef (ignore
)
648 int ignore ATTRIBUTE_UNUSED
;
650 symbolS
*symbolP
= NULL
;
652 /* DIM BUG FIX sac@cygnus.com */
654 if (def_symbol_in_progress
== NULL
)
656 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
657 demand_empty_rest_of_line ();
659 } /* if not inside .def/.endef */
661 /* Set the section number according to storage class. */
662 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
667 SF_SET_TAG (def_symbol_in_progress
);
668 /* intentional fallthrough */
671 SF_SET_DEBUG (def_symbol_in_progress
);
672 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
676 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
677 /* intentional fallthrough */
679 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
680 /* intentional fallthrough */
684 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
686 name
= S_GET_NAME (def_symbol_in_progress
);
687 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
693 if (! in_function ())
694 as_warn (_("`%s' symbol without preceding function"), name
);
695 /* Will need relocating. */
696 SF_SET_PROCESS (def_symbol_in_progress
);
702 /* The MS compilers output the actual endline, not the
703 function-relative one... we want to match without
704 changing the assembler input. */
705 SA_SET_SYM_LNNO (def_symbol_in_progress
,
706 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
717 #endif /* C_AUTOARG */
724 /* According to the COFF documentation:
726 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
728 A special section number (-2) marks symbolic debugging symbols,
729 including structure/union/enumeration tag names, typedefs, and
730 the name of the file. A section number of -1 indicates that the
731 symbol has a value but is not relocatable. Examples of
732 absolute-valued symbols include automatic and register variables,
733 function arguments, and .eos symbols.
735 But from Ian Lance Taylor:
737 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
739 the actual tools all marked them as section -1. So the GNU COFF
740 assembler follows historical COFF assemblers.
742 However, it causes problems for djgpp
744 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
746 By defining STRICTCOFF, a COFF port can make the assembler to
747 follow the documented behavior. */
754 SF_SET_DEBUG (def_symbol_in_progress
);
755 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
763 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
774 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
781 as_warn (_("unexpected storage class %d"),
782 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
784 } /* switch on storage class */
786 /* Now that we have built a debug symbol, try to find if we should
787 merge with an existing symbol or not. If a symbol is C_EFCN or
788 absolute_section or untagged SEG_DEBUG it never merges. We also
789 don't merge labels, which are in a different namespace, nor
790 symbols which have not yet been defined since they are typically
791 unique, nor do we merge tags with non-tags. */
793 /* Two cases for functions. Either debug followed by definition or
794 definition followed by debug. For definition first, we will
795 merge the debug symbol into the definition. For debug first, the
796 lineno entry MUST point to the definition function or else it
797 will point off into space when obj_crawl_symbol_chain() merges
798 the debug symbol into the real symbol. Therefor, let's presume
799 the debug symbol is a real function reference. */
801 /* FIXME-SOON If for some reason the definition label/symbol is
802 never seen, this will probably leave an undefined symbol at link
805 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
806 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
807 || (!strcmp (bfd_get_section_name (stdoutput
,
808 S_GET_SEGMENT (def_symbol_in_progress
)),
810 && !SF_GET_TAG (def_symbol_in_progress
))
811 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
812 || ! symbol_constant_p (def_symbol_in_progress
)
813 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
814 DO_NOT_STRIP
)) == NULL
815 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
817 /* If it already is at the end of the symbol list, do nothing */
818 if (def_symbol_in_progress
!= symbol_lastP
)
820 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
821 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
827 /* This symbol already exists, merge the newly created symbol
828 into the old one. This is not mandatory. The linker can
829 handle duplicate symbols correctly. But I guess that it save
830 a *lot* of space if the assembly file defines a lot of
833 /* The debug entry (def_symbol_in_progress) is merged into the
834 previous definition. */
836 c_symbol_merge (def_symbol_in_progress
, symbolP
);
837 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
839 def_symbol_in_progress
= symbolP
;
841 if (SF_GET_FUNCTION (def_symbol_in_progress
)
842 || SF_GET_TAG (def_symbol_in_progress
)
843 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
845 /* For functions, and tags, and static symbols, the symbol
846 *must* be where the debug symbol appears. Move the
847 existing symbol to the current place. */
848 /* If it already is at the end of the symbol list, do nothing */
849 if (def_symbol_in_progress
!= symbol_lastP
)
851 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
852 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
857 if (SF_GET_TAG (def_symbol_in_progress
))
861 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
863 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
864 tag_insert (S_GET_NAME (def_symbol_in_progress
),
865 def_symbol_in_progress
);
868 if (SF_GET_FUNCTION (def_symbol_in_progress
))
870 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
871 set_function (def_symbol_in_progress
);
872 SF_SET_PROCESS (def_symbol_in_progress
);
876 /* That is, if this is the first time we've seen the
878 symbol_table_insert (def_symbol_in_progress
);
879 } /* definition follows debug */
880 } /* Create the line number entry pointing to the function being defined */
882 def_symbol_in_progress
= NULL
;
883 demand_empty_rest_of_line ();
887 obj_coff_dim (ignore
)
888 int ignore ATTRIBUTE_UNUSED
;
892 if (def_symbol_in_progress
== NULL
)
894 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
895 demand_empty_rest_of_line ();
897 } /* if not inside .def/.endef */
899 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
901 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
904 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
905 get_absolute_expression ());
907 switch (*input_line_pointer
)
910 input_line_pointer
++;
914 as_warn (_("badly formed .dim directive ignored"));
915 /* intentional fallthrough */
923 demand_empty_rest_of_line ();
927 obj_coff_line (ignore
)
928 int ignore ATTRIBUTE_UNUSED
;
932 if (def_symbol_in_progress
== NULL
)
934 /* Probably stabs-style line? */
939 this_base
= get_absolute_expression ();
940 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
941 coff_line_base
= this_base
;
943 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
944 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
946 demand_empty_rest_of_line ();
949 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
954 listing_source_line ((unsigned int) this_base
);
960 obj_coff_size (ignore
)
961 int ignore ATTRIBUTE_UNUSED
;
963 if (def_symbol_in_progress
== NULL
)
965 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
966 demand_empty_rest_of_line ();
968 } /* if not inside .def/.endef */
970 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
971 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
972 demand_empty_rest_of_line ();
976 obj_coff_scl (ignore
)
977 int ignore ATTRIBUTE_UNUSED
;
979 if (def_symbol_in_progress
== NULL
)
981 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
982 demand_empty_rest_of_line ();
984 } /* if not inside .def/.endef */
986 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
987 demand_empty_rest_of_line ();
991 obj_coff_tag (ignore
)
992 int ignore ATTRIBUTE_UNUSED
;
997 if (def_symbol_in_progress
== NULL
)
999 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
1000 demand_empty_rest_of_line ();
1004 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1005 symbol_name
= input_line_pointer
;
1006 name_end
= get_symbol_end ();
1008 #ifdef tc_canonicalize_symbol_name
1009 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1012 /* Assume that the symbol referred to by .tag is always defined.
1013 This was a bad assumption. I've added find_or_make. xoxorich. */
1014 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1015 tag_find_or_make (symbol_name
));
1016 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1018 as_warn (_("tag not found for .tag %s"), symbol_name
);
1021 SF_SET_TAGGED (def_symbol_in_progress
);
1022 *input_line_pointer
= name_end
;
1024 demand_empty_rest_of_line ();
1028 obj_coff_type (ignore
)
1029 int ignore ATTRIBUTE_UNUSED
;
1031 if (def_symbol_in_progress
== NULL
)
1033 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1034 demand_empty_rest_of_line ();
1036 } /* if not inside .def/.endef */
1038 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1040 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1041 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1043 SF_SET_FUNCTION (def_symbol_in_progress
);
1044 } /* is a function */
1046 demand_empty_rest_of_line ();
1050 obj_coff_val (ignore
)
1051 int ignore ATTRIBUTE_UNUSED
;
1053 if (def_symbol_in_progress
== NULL
)
1055 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1056 demand_empty_rest_of_line ();
1058 } /* if not inside .def/.endef */
1060 if (is_name_beginner (*input_line_pointer
))
1062 char *symbol_name
= input_line_pointer
;
1063 char name_end
= get_symbol_end ();
1065 #ifdef tc_canonicalize_symbol_name
1066 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1068 if (!strcmp (symbol_name
, "."))
1070 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1071 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1072 /* If the .val is != from the .def (e.g. statics) */
1074 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1078 exp
.X_op
= O_symbol
;
1079 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1080 exp
.X_op_symbol
= NULL
;
1081 exp
.X_add_number
= 0;
1082 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1084 /* If the segment is undefined when the forward reference is
1085 resolved, then copy the segment id from the forward
1087 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1089 /* FIXME: gcc can generate address expressions here in
1090 unusual cases (search for "obscure" in sdbout.c). We
1091 just ignore the offset here, thus generating incorrect
1092 debugging information. We ignore the rest of the line
1095 /* Otherwise, it is the name of a non debug symbol and its value
1096 will be calculated later. */
1097 *input_line_pointer
= name_end
;
1101 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1102 } /* if symbol based */
1104 demand_empty_rest_of_line ();
1109 /* Return nonzero if name begins with weak alternate symbol prefix. */
1112 weak_is_altname (const char * name
)
1114 return ! strncmp (name
, weak_altprefix
, sizeof (weak_altprefix
) - 1);
1117 /* Return the name of the alternate symbol
1118 name corresponding to a weak symbol's name. */
1121 weak_name2altname (const char * name
)
1125 alt_name
= xmalloc (sizeof (weak_altprefix
) + strlen (name
));
1126 strcpy (alt_name
, weak_altprefix
);
1127 return strcat (alt_name
, name
);
1130 /* Return the name of the weak symbol corresponding to an
1134 weak_altname2name (const char * name
)
1139 assert (weak_is_altname (name
));
1141 weak_name
= xstrdup (name
+ 6);
1142 if ((dot
= strchr (weak_name
, '.')))
1147 /* Make a weak symbol name unique by
1148 appending the name of an external symbol. */
1151 weak_uniquify (const char * name
)
1154 const char * unique
= "";
1157 if (an_external_name
!= NULL
)
1158 unique
= an_external_name
;
1160 assert (weak_is_altname (name
));
1162 if (strchr (name
+ sizeof (weak_altprefix
), '.'))
1165 ret
= xmalloc (strlen (name
) + strlen (unique
) + 2);
1168 strcat (ret
, unique
);
1174 /* Handle .weak. This is a GNU extension in formats other than PE. */
1177 obj_coff_weak (int ignore ATTRIBUTE_UNUSED
)
1183 symbolS
*alternateP
;
1188 name
= input_line_pointer
;
1189 c
= get_symbol_end ();
1192 as_warn (_("badly formed .weak directive ignored"));
1193 ignore_rest_of_line ();
1197 symbolP
= symbol_find_or_make (name
);
1198 *input_line_pointer
= c
;
1201 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
1202 S_SET_WEAK (symbolP
);
1206 /* See _Microsoft Portable Executable and Common Object
1207 File Format Specification_, section 5.5.3.
1208 Create a symbol representing the alternate value.
1209 coff_frob_symbol will set the value of this symbol from
1210 the value of the weak symbol itself. */
1211 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
1212 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1213 SA_SET_SYM_FSIZE (symbolP
, IMAGE_WEAK_EXTERN_SEARCH_LIBRARY
);
1215 alternateP
= symbol_find_or_make (weak_name2altname (name
));
1216 S_SET_EXTERNAL (alternateP
);
1217 S_SET_STORAGE_CLASS (alternateP
, C_NT_WEAK
);
1219 SA_SET_SYM_TAGNDX (symbolP
, alternateP
);
1224 input_line_pointer
++;
1226 if (*input_line_pointer
== '\n')
1233 demand_empty_rest_of_line ();
1237 coff_obj_read_begin_hook ()
1239 /* These had better be the same. Usually 18 bytes. */
1241 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1242 know (SYMESZ
== AUXESZ
);
1247 symbolS
*coff_last_function
;
1249 static symbolS
*coff_last_bf
;
1253 coff_frob_symbol (symp
, punt
)
1257 static symbolS
*last_tagP
;
1258 static stack
*block_stack
;
1259 static symbolS
*set_end
;
1260 symbolS
*next_set_end
= NULL
;
1262 if (symp
== &abs_symbol
)
1268 if (current_lineno_sym
)
1269 coff_add_linesym ((symbolS
*) 0);
1272 block_stack
= stack_init (512, sizeof (symbolS
*));
1275 if (S_GET_STORAGE_CLASS (symp
) == C_NT_WEAK
1276 && ! S_IS_WEAK (symp
)
1277 && weak_is_altname (S_GET_NAME (symp
)))
1279 /* This is a weak alternate symbol. All processing of
1280 PECOFFweak symbols is done here, through the alternate. */
1281 symbolS
*weakp
= symbol_find (weak_altname2name (S_GET_NAME (symp
)));
1284 assert (S_GET_NUMBER_AUXILIARY (weakp
) == 1);
1286 if (symbol_equated_p (weakp
))
1288 /* The weak symbol has an alternate specified; symp is unneeded. */
1289 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1290 SA_SET_SYM_TAGNDX (weakp
,
1291 symbol_get_value_expression (weakp
)->X_add_symbol
);
1293 S_CLEAR_EXTERNAL (symp
);
1299 /* The weak symbol has been assigned an alternate value.
1300 Copy this value to symp, and set symp as weakp's alternate. */
1301 if (S_GET_STORAGE_CLASS (weakp
) != C_NT_WEAK
)
1303 S_SET_STORAGE_CLASS (symp
, S_GET_STORAGE_CLASS (weakp
));
1304 S_SET_STORAGE_CLASS (weakp
, C_NT_WEAK
);
1307 if (S_IS_DEFINED (weakp
))
1309 /* This is a defined weak symbol. Copy value information
1310 from the weak symbol itself to the alternate symbol. */
1311 symbol_set_value_expression (symp
,
1312 symbol_get_value_expression (weakp
));
1313 symbol_set_frag (symp
, symbol_get_frag (weakp
));
1314 S_SET_SEGMENT (symp
, S_GET_SEGMENT (weakp
));
1318 /* This is an undefined weak symbol.
1319 Define the alternate symbol to zero. */
1320 S_SET_VALUE (symp
, 0);
1321 S_SET_SEGMENT (symp
, absolute_section
);
1324 S_SET_NAME (symp
, weak_uniquify (S_GET_NAME (symp
)));
1325 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1327 S_SET_VALUE (weakp
, 0);
1328 S_SET_SEGMENT (weakp
, undefined_section
);
1332 if (S_IS_WEAK (symp
))
1333 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1336 if (!S_IS_DEFINED (symp
)
1337 && !S_IS_WEAK (symp
)
1338 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1339 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1341 if (!SF_GET_DEBUG (symp
))
1345 if (!SF_GET_LOCAL (symp
)
1346 && !SF_GET_STATICS (symp
)
1347 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1348 && symbol_constant_p(symp
)
1349 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1350 && S_GET_STORAGE_CLASS (real
) == C_NULL
1353 c_symbol_merge (symp
, real
);
1358 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1360 assert (S_GET_VALUE (symp
) == 0);
1361 S_SET_EXTERNAL (symp
);
1363 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1365 if (S_GET_SEGMENT (symp
) == text_section
1366 && symp
!= seg_info (text_section
)->sym
)
1367 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1369 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1372 if (SF_GET_PROCESS (symp
))
1374 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1376 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1377 stack_push (block_stack
, (char *) &symp
);
1382 begin
= *(symbolS
**) stack_pop (block_stack
);
1384 as_warn (_("mismatched .eb"));
1386 next_set_end
= begin
;
1390 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1392 union internal_auxent
*auxp
;
1394 coff_last_function
= symp
;
1395 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1396 S_SET_NUMBER_AUXILIARY (symp
, 1);
1397 auxp
= SYM_AUXENT (symp
);
1398 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1399 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1402 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1404 if (coff_last_function
== 0)
1405 as_fatal (_("C_EFCN symbol out of scope"));
1406 SA_SET_SYM_FSIZE (coff_last_function
,
1407 (long) (S_GET_VALUE (symp
)
1408 - S_GET_VALUE (coff_last_function
)));
1409 next_set_end
= coff_last_function
;
1410 coff_last_function
= 0;
1414 if (S_IS_EXTERNAL (symp
))
1415 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1416 else if (SF_GET_LOCAL (symp
))
1419 if (SF_GET_FUNCTION (symp
))
1420 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1425 /* Double check weak symbols. */
1426 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1427 as_bad (_("Symbol `%s' can not be both weak and common"),
1430 if (SF_GET_TAG (symp
))
1432 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1433 next_set_end
= last_tagP
;
1436 /* This is pretty horrible, but we have to set *punt correctly in
1437 order to call SA_SET_SYM_ENDNDX correctly. */
1438 if (! symbol_used_in_reloc_p (symp
)
1439 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1440 || (! (S_IS_EXTERNAL (symp
) || S_IS_WEAK (symp
))
1441 && ! symbol_get_tc (symp
)->output
1442 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1446 if (set_end
!= (symbolS
*) NULL
1448 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1449 || (S_IS_DEFINED (symp
)
1450 && ! S_IS_COMMON (symp
)
1451 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1453 SA_SET_SYM_ENDNDX (set_end
, symp
);
1457 if (next_set_end
!= NULL
)
1459 if (set_end
!= NULL
)
1460 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1461 S_GET_NAME (set_end
));
1462 set_end
= next_set_end
;
1467 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1468 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1470 if (coff_last_bf
!= NULL
)
1471 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1472 coff_last_bf
= symp
;
1475 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1478 struct line_no
*lptr
;
1481 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1482 for (i
= 0; lptr
; lptr
= lptr
->next
)
1484 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1486 /* We need i entries for line numbers, plus 1 for the first
1487 entry which BFD will override, plus 1 for the last zero
1488 entry (a marker for BFD). */
1489 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1490 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1491 l
[i
+ 1].line_number
= 0;
1492 l
[i
+ 1].u
.sym
= NULL
;
1496 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1504 coff_adjust_section_syms (abfd
, sec
, x
)
1505 bfd
*abfd ATTRIBUTE_UNUSED
;
1507 PTR x ATTRIBUTE_UNUSED
;
1510 segment_info_type
*seginfo
= seg_info (sec
);
1511 int nlnno
, nrelocs
= 0;
1513 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1514 tc-ppc.c. Do not get confused by it. */
1515 if (seginfo
== NULL
)
1518 if (!strcmp (sec
->name
, ".text"))
1519 nlnno
= coff_n_line_nos
;
1523 /* @@ Hope that none of the fixups expand to more than one reloc
1525 fixS
*fixp
= seginfo
->fix_root
;
1528 if (! fixp
->fx_done
)
1530 fixp
= fixp
->fx_next
;
1533 if (bfd_get_section_size (sec
) == 0
1536 && sec
!= text_section
1537 && sec
!= data_section
1538 && sec
!= bss_section
)
1540 secsym
= section_symbol (sec
);
1541 /* This is an estimate; we'll plug in the real value using
1542 SET_SECTION_RELOCS later */
1543 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1544 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1548 coff_frob_file_after_relocs ()
1550 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1553 /* Implement the .section pseudo op:
1554 .section name {, "flags"}
1556 | +--- optional flags: 'b' for bss
1558 +-- section name 'l' for lib
1562 'd' (apparently m88k for data)
1564 'r' for read-only data
1565 's' for shared data (PE)
1566 But if the argument is not a quoted string, treat it as a
1569 Note the 'a' flag is silently ignored. This allows the same
1570 .section directive to be parsed in both ELF and COFF formats. */
1573 obj_coff_section (ignore
)
1574 int ignore ATTRIBUTE_UNUSED
;
1576 /* Strip out the section name */
1581 flagword flags
, oldflags
;
1592 section_name
= input_line_pointer
;
1593 c
= get_symbol_end ();
1595 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1596 strcpy (name
, section_name
);
1598 *input_line_pointer
= c
;
1603 flags
= SEC_NO_FLAGS
;
1605 if (*input_line_pointer
== ',')
1607 ++input_line_pointer
;
1609 if (*input_line_pointer
!= '"')
1610 exp
= get_absolute_expression ();
1613 ++input_line_pointer
;
1614 while (*input_line_pointer
!= '"'
1615 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1617 switch (*input_line_pointer
)
1619 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1620 case 'n': flags
&=~ SEC_LOAD
; flags
|= SEC_NEVER_LOAD
; break;
1622 case 's': flags
|= SEC_SHARED
; /* fall through */
1623 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1624 case 'w': flags
&=~ SEC_READONLY
; break;
1626 case 'a': break; /* For compatibility with ELF. */
1627 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1628 case 'r': flags
|= SEC_DATA
| SEC_LOAD
| SEC_READONLY
; break;
1630 case 'i': /* STYP_INFO */
1631 case 'l': /* STYP_LIB */
1632 case 'o': /* STYP_OVER */
1633 as_warn (_("unsupported section attribute '%c'"),
1634 *input_line_pointer
);
1638 as_warn(_("unknown section attribute '%c'"),
1639 *input_line_pointer
);
1642 ++input_line_pointer
;
1644 if (*input_line_pointer
== '"')
1645 ++input_line_pointer
;
1649 sec
= subseg_new (name
, (subsegT
) exp
);
1651 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1652 if (oldflags
== SEC_NO_FLAGS
)
1654 /* Set section flags for a new section just created by subseg_new.
1655 Provide a default if no flags were parsed. */
1656 if (flags
== SEC_NO_FLAGS
)
1657 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1659 #ifdef COFF_LONG_SECTION_NAMES
1660 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1661 sections so adjust_reloc_syms in write.c will correctly handle
1662 relocs which refer to non-local symbols in these sections. */
1663 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1664 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1667 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1668 as_warn (_("error setting flags for \"%s\": %s"),
1669 bfd_section_name (stdoutput
, sec
),
1670 bfd_errmsg (bfd_get_error ()));
1672 else if (flags
!= SEC_NO_FLAGS
)
1674 /* This section's attributes have already been set. Warn if the
1675 attributes don't match. */
1676 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1677 | SEC_DATA
| SEC_SHARED
| SEC_NEVER_LOAD
);
1678 if ((flags
^ oldflags
) & matchflags
)
1679 as_warn (_("Ignoring changed section attributes for %s"), name
);
1682 demand_empty_rest_of_line ();
1686 coff_adjust_symtab ()
1688 if (symbol_rootP
== NULL
1689 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1690 c_dot_file_symbol ("fake");
1694 coff_frob_section (sec
)
1700 bfd_vma size
, n_entries
, mask
;
1701 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1703 /* The COFF back end in BFD requires that all section sizes be
1704 rounded up to multiples of the corresponding section alignments,
1705 supposedly because standard COFF has no other way of encoding alignment
1706 for sections. If your COFF flavor has a different way of encoding
1707 section alignment, then skip this step, as TICOFF does. */
1708 size
= bfd_get_section_size (sec
);
1709 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1710 #if !defined(TICOFF)
1716 new_size
= (size
+ mask
) & ~mask
;
1717 bfd_set_section_size (stdoutput
, sec
, new_size
);
1719 /* If the size had to be rounded up, add some padding in
1720 the last non-empty frag. */
1721 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1722 last
= seg_info (sec
)->frchainP
->frch_last
;
1723 while (fragp
->fr_next
!= last
)
1724 fragp
= fragp
->fr_next
;
1725 last
->fr_address
= size
;
1726 fragp
->fr_offset
+= new_size
- size
;
1730 /* If the section size is non-zero, the section symbol needs an aux
1731 entry associated with it, indicating the size. We don't know
1732 all the values yet; coff_frob_symbol will fill them in later. */
1735 || sec
== text_section
1736 || sec
== data_section
1737 || sec
== bss_section
)
1740 symbolS
*secsym
= section_symbol (sec
);
1742 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1743 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1744 SF_SET_STATICS (secsym
);
1745 SA_SET_SCN_SCNLEN (secsym
, size
);
1748 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1749 #ifndef STAB_SECTION_NAME
1750 #define STAB_SECTION_NAME ".stab"
1752 #ifndef STAB_STRING_SECTION_NAME
1753 #define STAB_STRING_SECTION_NAME ".stabstr"
1755 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1759 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1760 /* size is already rounded up, since other section will be listed first */
1761 size
= bfd_get_section_size (strsec
);
1763 n_entries
= bfd_get_section_size (sec
) / 12 - 1;
1765 /* Find first non-empty frag. It should be large enough. */
1766 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1767 while (fragp
&& fragp
->fr_fix
== 0)
1768 fragp
= fragp
->fr_next
;
1769 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1771 /* Store the values. */
1772 p
= fragp
->fr_literal
;
1773 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1774 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1778 obj_coff_init_stab_section (seg
)
1784 unsigned int stroff
;
1786 /* Make space for this first symbol. */
1790 as_where (&file
, (unsigned int *) NULL
);
1791 stabstr_name
= (char *) xmalloc (strlen (seg
->name
) + 4);
1792 strcpy (stabstr_name
, seg
->name
);
1793 strcat (stabstr_name
, "str");
1794 stroff
= get_stab_string_offset (file
, stabstr_name
);
1796 md_number_to_chars (p
, stroff
, 4);
1805 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1813 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1815 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1816 (unsigned long) symbolP
,
1817 S_GET_NAME(symbolP
),
1818 (long) S_GET_DATA_TYPE(symbolP
),
1819 S_GET_STORAGE_CLASS(symbolP
),
1820 (int) S_GET_SEGMENT(symbolP
));
1826 #else /* not BFD_ASSEMBLER */
1829 /* This is needed because we include internal bfd things. */
1833 #include "libcoff.h"
1835 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1836 that we can stick sections together without causing trouble. */
1838 #define NOP_OPCODE 0x00
1841 /* The zeroes if symbol name is longer than 8 chars */
1842 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1844 #define MIN(a,b) ((a) < (b)? (a) : (b))
1846 /* This vector is used to turn a gas internal segment number into a
1847 section number suitable for insertion into a coff symbol table.
1848 This must correspond to seg_info_off_by_4. */
1850 const short seg_N_TYPE
[] =
1851 { /* in: segT out: N_TYPE bits */
1853 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1854 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1855 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1856 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1857 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1858 C_UNDEF_SECTION
, /* SEG_GOOF */
1859 C_UNDEF_SECTION
, /* SEG_EXPR */
1860 C_DEBUG_SECTION
, /* SEG_DEBUG */
1861 C_NTV_SECTION
, /* SEG_NTV */
1862 C_PTV_SECTION
, /* SEG_PTV */
1863 C_REGISTER_SECTION
, /* SEG_REGISTER */
1866 int function_lineoff
= -1; /* Offset in line#s where the last function
1867 started (the odd entry for line #0) */
1869 /* Structure used to keep the filenames which
1870 are too long around so that we can stick them
1871 into the string table. */
1872 struct filename_list
1875 struct filename_list
*next
;
1878 static struct filename_list
*filename_list_head
;
1879 static struct filename_list
*filename_list_tail
;
1881 static symbolS
*last_line_symbol
;
1883 /* Add 4 to the real value to get the index and compensate the
1884 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1885 section number into a segment number. */
1888 static symbolS
*previous_file_symbol
;
1889 static int line_base
;
1891 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
1892 symbolS
*c_section_symbol
PARAMS ((char *, int));
1893 void obj_coff_section
PARAMS ((int));
1894 void do_relocs_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1895 char * symbol_to_chars
PARAMS ((bfd
*, char *, symbolS
*));
1896 void w_strings
PARAMS ((char *));
1898 static void fixup_segment
PARAMS ((segment_info_type
*, segT
));
1899 static void fixup_mdeps
PARAMS ((fragS
*, object_headers
*, segT
));
1900 static void fill_section
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1901 static int c_line_new
PARAMS ((symbolS
*, long, int, fragS
*));
1902 static void w_symbols
PARAMS ((bfd
*, char *, symbolS
*));
1903 static void adjust_stab_section
PARAMS ((bfd
*, segT
));
1904 static void obj_coff_lcomm
PARAMS ((int));
1905 static void obj_coff_text
PARAMS ((int));
1906 static void obj_coff_data
PARAMS ((int));
1907 static unsigned int count_entries_in_chain
PARAMS ((unsigned int));
1908 static void coff_header_append
PARAMS ((bfd
*, object_headers
*));
1909 static unsigned int yank_symbols
PARAMS ((void));
1910 static unsigned int glue_symbols
PARAMS ((symbolS
**, symbolS
**));
1911 static unsigned int tie_tags
PARAMS ((void));
1912 static void crawl_symbols
PARAMS ((object_headers
*, bfd
*));
1913 static void do_linenos_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1914 static void remove_subsegs
PARAMS ((void));
1918 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1920 This array maps a COFF section number into a gas section number.
1921 Because COFF uses negative section numbers, you must add 4 to the
1922 COFF section number when indexing into this array; this is done via
1923 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1926 static const segT seg_info_off_by_4
[] =
1933 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1934 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1935 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1936 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1937 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1938 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1939 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1940 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1953 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1955 static relax_addressT relax_align
PARAMS ((relax_addressT
, long));
1957 static relax_addressT
1958 relax_align (address
, alignment
)
1959 relax_addressT address
;
1962 relax_addressT mask
;
1963 relax_addressT new_address
;
1965 mask
= ~((~0) << alignment
);
1966 new_address
= (address
+ mask
) & (~mask
);
1967 return (new_address
- address
);
1974 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1977 static unsigned int size_section
PARAMS ((bfd
*, unsigned int));
1979 /* Calculate the size of the frag chain and fill in the section header
1980 to contain all of it, also fill in the addr of the sections. */
1983 size_section (abfd
, idx
)
1984 bfd
*abfd ATTRIBUTE_UNUSED
;
1987 unsigned int size
= 0;
1988 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1992 size
= frag
->fr_address
;
1993 if (frag
->fr_address
!= size
)
1995 fprintf (stderr
, _("Out of step\n"));
1996 size
= frag
->fr_address
;
1999 switch (frag
->fr_type
)
2001 #ifdef TC_COFF_SIZEMACHDEP
2002 case rs_machine_dependent
:
2003 size
+= TC_COFF_SIZEMACHDEP (frag
);
2009 size
+= frag
->fr_fix
;
2010 size
+= frag
->fr_offset
* frag
->fr_var
;
2018 size
+= frag
->fr_fix
;
2019 off
= relax_align (size
, frag
->fr_offset
);
2020 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
2026 BAD_CASE (frag
->fr_type
);
2029 frag
= frag
->fr_next
;
2031 segment_info
[idx
].scnhdr
.s_size
= size
;
2036 count_entries_in_chain (idx
)
2039 unsigned int nrelocs
;
2042 /* Count the relocations. */
2043 fixup_ptr
= segment_info
[idx
].fix_root
;
2045 while (fixup_ptr
!= (fixS
*) NULL
)
2047 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
2049 #if defined(TC_A29K) || defined(TC_OR32)
2050 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
2059 fixup_ptr
= fixup_ptr
->fx_next
;
2066 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
2068 /* AUX's ld expects relocations to be sorted. */
2071 compare_external_relocs (x
, y
)
2075 struct external_reloc
*a
= (struct external_reloc
*) x
;
2076 struct external_reloc
*b
= (struct external_reloc
*) y
;
2077 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
2078 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
2079 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
2084 /* Output all the relocations for a section. */
2087 do_relocs_for (abfd
, h
, file_cursor
)
2090 unsigned long *file_cursor
;
2092 unsigned int nrelocs
;
2094 unsigned long reloc_start
= *file_cursor
;
2096 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
2098 if (segment_info
[idx
].scnhdr
.s_name
[0])
2100 struct external_reloc
*ext_ptr
;
2101 struct external_reloc
*external_reloc_vec
;
2102 unsigned int external_reloc_size
;
2103 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
2104 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
2105 nrelocs
= count_entries_in_chain (idx
);
2108 /* Bypass this stuff if no relocs. This also incidentally
2109 avoids a SCO bug, where free(malloc(0)) tends to crash. */
2111 external_reloc_size
= nrelocs
* RELSZ
;
2112 external_reloc_vec
=
2113 (struct external_reloc
*) malloc (external_reloc_size
);
2115 ext_ptr
= external_reloc_vec
;
2117 /* Fill in the internal coff style reloc struct from the
2118 internal fix list. */
2121 struct internal_reloc intr
;
2123 /* Only output some of the relocations. */
2124 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
2126 #ifdef TC_RELOC_MANGLE
2127 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
2131 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
2133 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
2135 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
2137 #ifdef TC_KEEP_FX_OFFSET
2138 intr
.r_offset
= fix_ptr
->fx_offset
;
2143 while (symbol_ptr
->sy_value
.X_op
== O_symbol
2144 && (! S_IS_DEFINED (symbol_ptr
)
2145 || S_IS_COMMON (symbol_ptr
)))
2149 /* We must avoid looping, as that can occur
2150 with a badly written program. */
2151 n
= symbol_ptr
->sy_value
.X_add_symbol
;
2152 if (n
== symbol_ptr
)
2157 /* Turn the segment of the symbol into an offset. */
2160 resolve_symbol_value (symbol_ptr
);
2161 if (! symbol_ptr
->sy_resolved
)
2166 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
2167 as_bad_where (file
, line
,
2168 _("unresolved relocation"));
2170 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2171 S_GET_NAME (symbol_ptr
));
2174 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
2176 intr
.r_symndx
= dot
->sy_number
;
2178 intr
.r_symndx
= symbol_ptr
->sy_number
;
2183 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2185 #if defined(TC_A29K)
2186 /* The 29k has a special kludge for the high 16 bit
2187 reloc. Two relocations are emitted, R_IHIHALF,
2188 and R_IHCONST. The second one doesn't contain a
2189 symbol, but uses the value for offset. */
2190 if (intr
.r_type
== R_IHIHALF
)
2192 /* Now emit the second bit. */
2193 intr
.r_type
= R_IHCONST
;
2194 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2195 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2199 #if defined(TC_OR32)
2200 /* The or32 has a special kludge for the high 16 bit
2201 reloc. Two relocations are emitted, R_IHIHALF,
2202 and R_IHCONST. The second one doesn't contain a
2203 symbol, but uses the value for offset. */
2204 if (intr
.r_type
== R_IHIHALF
)
2206 /* Now emit the second bit. */
2207 intr
.r_type
= R_IHCONST
;
2208 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2209 (void) bfd_coff_swap_reloc_out (abfd
, & intr
, ext_ptr
);
2215 fix_ptr
= fix_ptr
->fx_next
;
2218 /* Sort the reloc table. */
2219 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2220 sizeof (struct external_reloc
), compare_external_relocs
);
2222 /* Write out the reloc table. */
2223 bfd_bwrite ((PTR
) external_reloc_vec
,
2224 (bfd_size_type
) external_reloc_size
, abfd
);
2225 free (external_reloc_vec
);
2227 /* Fill in section header info. */
2228 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2229 *file_cursor
+= external_reloc_size
;
2230 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2235 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2240 /* Set relocation_size field in file headers. */
2241 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2244 /* Run through a frag chain and write out the data to go with it, fill
2245 in the scnhdrs with the info on the file positions. */
2248 fill_section (abfd
, h
, file_cursor
)
2250 object_headers
*h ATTRIBUTE_UNUSED
;
2251 unsigned long *file_cursor
;
2254 unsigned int paddr
= 0;
2256 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2258 unsigned int offset
= 0;
2259 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2265 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2266 char *buffer
= NULL
;
2272 buffer
= xmalloc (s
->s_size
);
2273 s
->s_scnptr
= *file_cursor
;
2275 know (s
->s_paddr
== paddr
);
2277 if (strcmp (s
->s_name
, ".text") == 0)
2278 s
->s_flags
|= STYP_TEXT
;
2279 else if (strcmp (s
->s_name
, ".data") == 0)
2280 s
->s_flags
|= STYP_DATA
;
2281 else if (strcmp (s
->s_name
, ".bss") == 0)
2284 s
->s_flags
|= STYP_BSS
;
2286 /* @@ Should make the i386 and a29k coff targets define
2287 COFF_NOLOAD_PROBLEM, and have only one test here. */
2291 #ifndef COFF_NOLOAD_PROBLEM
2292 /* Apparently the SVR3 linker (and exec syscall) and UDI
2293 mondfe progrem are confused by noload sections. */
2294 s
->s_flags
|= STYP_NOLOAD
;
2300 else if (strcmp (s
->s_name
, ".lit") == 0)
2301 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2302 else if (strcmp (s
->s_name
, ".init") == 0)
2303 s
->s_flags
|= STYP_TEXT
;
2304 else if (strcmp (s
->s_name
, ".fini") == 0)
2305 s
->s_flags
|= STYP_TEXT
;
2306 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2307 s
->s_flags
|= STYP_INFO
;
2311 unsigned int fill_size
;
2312 switch (frag
->fr_type
)
2314 case rs_machine_dependent
:
2317 memcpy (buffer
+ frag
->fr_address
,
2319 (unsigned int) frag
->fr_fix
);
2320 offset
+= frag
->fr_fix
;
2332 memcpy (buffer
+ frag
->fr_address
,
2334 (unsigned int) frag
->fr_fix
);
2335 offset
+= frag
->fr_fix
;
2338 fill_size
= frag
->fr_var
;
2339 if (fill_size
&& frag
->fr_offset
> 0)
2342 unsigned int off
= frag
->fr_fix
;
2343 for (count
= frag
->fr_offset
; count
; count
--)
2345 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2347 memcpy (buffer
+ frag
->fr_address
+ off
,
2348 frag
->fr_literal
+ frag
->fr_fix
,
2351 offset
+= fill_size
;
2356 case rs_broken_word
:
2361 frag
= frag
->fr_next
;
2366 if (s
->s_scnptr
!= 0)
2368 bfd_bwrite (buffer
, s
->s_size
, abfd
);
2369 *file_cursor
+= s
->s_size
;
2378 /* Coff file generation & utilities. */
2381 coff_header_append (abfd
, h
)
2388 #ifdef COFF_LONG_SECTION_NAMES
2389 unsigned long string_size
= 4;
2392 bfd_seek (abfd
, (file_ptr
) 0, 0);
2394 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2395 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2396 H_SET_VERSION_STAMP (h
, 0);
2397 H_SET_ENTRY_POINT (h
, 0);
2398 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2399 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2400 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2402 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2403 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2404 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2406 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2408 bfd_bwrite (buffer
, (bfd_size_type
) i
, abfd
);
2409 bfd_bwrite (buffero
, (bfd_size_type
) H_GET_SIZEOF_OPTIONAL_HEADER (h
), abfd
);
2411 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2413 if (segment_info
[i
].scnhdr
.s_name
[0])
2417 #ifdef COFF_LONG_SECTION_NAMES
2418 /* Support long section names as found in PE. This code
2419 must coordinate with that in write_object_file and
2421 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2423 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2424 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2425 string_size
+= strlen (segment_info
[i
].name
) + 1;
2428 size
= bfd_coff_swap_scnhdr_out (abfd
,
2429 &(segment_info
[i
].scnhdr
),
2432 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2433 bfd_bwrite (buffer
, (bfd_size_type
) size
, abfd
);
2439 symbol_to_chars (abfd
, where
, symbolP
)
2444 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2448 /* Turn any symbols with register attributes into abs symbols. */
2449 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2450 S_SET_SEGMENT (symbolP
, absolute_section
);
2452 /* At the same time, relocate all symbols to their output value. */
2454 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2455 + S_GET_VALUE (symbolP
));
2457 val
= S_GET_VALUE (symbolP
);
2460 S_SET_VALUE (symbolP
, val
);
2462 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2464 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2467 for (i
= 0; i
< numaux
; i
++)
2469 where
+= bfd_coff_swap_aux_out (abfd
,
2470 &symbolP
->sy_symbol
.ost_auxent
[i
],
2471 S_GET_DATA_TYPE (symbolP
),
2472 S_GET_STORAGE_CLASS (symbolP
),
2480 coff_obj_symbol_new_hook (symbolP
)
2483 char underscore
= 0; /* Symbol has leading _ */
2485 /* Effective symbol. */
2486 /* Store the pointer in the offset. */
2487 S_SET_ZEROES (symbolP
, 0L);
2488 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2489 S_SET_STORAGE_CLASS (symbolP
, 0);
2490 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2491 /* Additional information. */
2492 symbolP
->sy_symbol
.ost_flags
= 0;
2493 /* Auxiliary entries. */
2494 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2496 if (S_IS_STRING (symbolP
))
2497 SF_SET_STRING (symbolP
);
2498 if (!underscore
&& S_IS_LOCAL (symbolP
))
2499 SF_SET_LOCAL (symbolP
);
2502 /* Handle .ln directives. */
2505 obj_coff_ln (appline
)
2510 if (! appline
&& def_symbol_in_progress
!= NULL
)
2512 /* Wrong context. */
2513 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2514 demand_empty_rest_of_line ();
2518 l
= get_absolute_expression ();
2519 c_line_new (0, frag_now_fix (), l
, frag_now
);
2522 new_logical_line ((char *) NULL
, l
- 1);
2532 listing_source_line ((unsigned int) l
);
2537 demand_empty_rest_of_line ();
2540 /* Handle .def directives.
2542 One might ask : why can't we symbol_new if the symbol does not
2543 already exist and fill it with debug information. Because of
2544 the C_EFCN special symbol. It would clobber the value of the
2545 function symbol before we have a chance to notice that it is
2546 a C_EFCN. And a second reason is that the code is more clear this
2547 way. (at least I think it is :-). */
2549 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2550 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2551 *input_line_pointer == '\t') \
2552 input_line_pointer++;
2556 int what ATTRIBUTE_UNUSED
;
2558 char name_end
; /* Char after the end of name. */
2559 char *symbol_name
; /* Name of the debug symbol. */
2560 char *symbol_name_copy
; /* Temporary copy of the name. */
2561 unsigned int symbol_name_length
;
2563 if (def_symbol_in_progress
!= NULL
)
2565 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2566 demand_empty_rest_of_line ();
2570 SKIP_WHITESPACES ();
2572 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2573 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2575 symbol_name
= input_line_pointer
;
2576 name_end
= get_symbol_end ();
2577 symbol_name_length
= strlen (symbol_name
);
2578 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2579 strcpy (symbol_name_copy
, symbol_name
);
2580 #ifdef tc_canonicalize_symbol_name
2581 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2584 /* Initialize the new symbol. */
2585 #ifdef STRIP_UNDERSCORE
2586 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2587 ? symbol_name_copy
+ 1
2588 : symbol_name_copy
));
2589 #else /* STRIP_UNDERSCORE */
2590 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2591 #endif /* STRIP_UNDERSCORE */
2592 /* free(symbol_name_copy); */
2593 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2594 def_symbol_in_progress
->sy_number
= ~0;
2595 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2596 S_SET_VALUE (def_symbol_in_progress
, 0);
2598 if (S_IS_STRING (def_symbol_in_progress
))
2599 SF_SET_STRING (def_symbol_in_progress
);
2601 *input_line_pointer
= name_end
;
2603 demand_empty_rest_of_line ();
2606 unsigned int dim_index
;
2609 obj_coff_endef (ignore
)
2610 int ignore ATTRIBUTE_UNUSED
;
2612 symbolS
*symbolP
= 0;
2613 /* DIM BUG FIX sac@cygnus.com */
2615 if (def_symbol_in_progress
== NULL
)
2617 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2618 demand_empty_rest_of_line ();
2622 /* Set the section number according to storage class. */
2623 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2628 SF_SET_TAG (def_symbol_in_progress
);
2629 /* Intentional fallthrough. */
2633 SF_SET_DEBUG (def_symbol_in_progress
);
2634 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2638 /* Do not emit this symbol. */
2639 SF_SET_LOCAL (def_symbol_in_progress
);
2640 /* Intentional fallthrough. */
2643 /* Will need processing before writing. */
2644 SF_SET_PROCESS (def_symbol_in_progress
);
2645 /* Intentional fallthrough. */
2648 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2650 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2652 if (function_lineoff
< 0)
2653 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2655 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2657 SF_SET_PROCESS (last_line_symbol
);
2658 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2659 SF_SET_PROCESS (def_symbol_in_progress
);
2660 function_lineoff
= -1;
2663 /* Value is always set to . */
2664 def_symbol_in_progress
->sy_frag
= frag_now
;
2665 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2670 #endif /* C_AUTOARG */
2680 SF_SET_DEBUG (def_symbol_in_progress
);
2681 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2691 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
2697 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2701 /* Now that we have built a debug symbol, try to find if we should
2702 merge with an existing symbol or not. If a symbol is C_EFCN or
2703 absolute_section or untagged SEG_DEBUG it never merges. We also
2704 don't merge labels, which are in a different namespace, nor
2705 symbols which have not yet been defined since they are typically
2706 unique, nor do we merge tags with non-tags. */
2708 /* Two cases for functions. Either debug followed by definition or
2709 definition followed by debug. For definition first, we will
2710 merge the debug symbol into the definition. For debug first, the
2711 lineno entry MUST point to the definition function or else it
2712 will point off into space when crawl_symbols() merges the debug
2713 symbol into the real symbol. Therefor, let's presume the debug
2714 symbol is a real function reference. */
2716 /* FIXME-SOON If for some reason the definition label/symbol is
2717 never seen, this will probably leave an undefined symbol at link
2720 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2721 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2722 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2723 && !SF_GET_TAG (def_symbol_in_progress
))
2724 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2725 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2726 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2727 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2729 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2734 /* This symbol already exists, merge the newly created symbol
2735 into the old one. This is not mandatory. The linker can
2736 handle duplicate symbols correctly. But I guess that it save
2737 a *lot* of space if the assembly file defines a lot of
2740 /* The debug entry (def_symbol_in_progress) is merged into the
2741 previous definition. */
2743 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2744 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2745 def_symbol_in_progress
= symbolP
;
2747 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2748 || SF_GET_TAG (def_symbol_in_progress
)
2749 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2751 /* For functions, and tags, and static symbols, the symbol
2752 *must* be where the debug symbol appears. Move the
2753 existing symbol to the current place. */
2754 /* If it already is at the end of the symbol list, do nothing. */
2755 if (def_symbol_in_progress
!= symbol_lastP
)
2757 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2759 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2760 &symbol_rootP
, &symbol_lastP
);
2765 if (SF_GET_TAG (def_symbol_in_progress
))
2769 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2771 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2772 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2773 def_symbol_in_progress
);
2776 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2778 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2780 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2782 SF_SET_PROCESS (def_symbol_in_progress
);
2784 if (symbolP
== NULL
)
2786 /* That is, if this is the first time we've seen the
2788 symbol_table_insert (def_symbol_in_progress
);
2792 def_symbol_in_progress
= NULL
;
2793 demand_empty_rest_of_line ();
2797 obj_coff_dim (ignore
)
2798 int ignore ATTRIBUTE_UNUSED
;
2802 if (def_symbol_in_progress
== NULL
)
2804 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2805 demand_empty_rest_of_line ();
2809 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2811 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2813 SKIP_WHITESPACES ();
2814 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2815 get_absolute_expression ());
2817 switch (*input_line_pointer
)
2820 input_line_pointer
++;
2824 as_warn (_("badly formed .dim directive ignored"));
2825 /* Intentional fallthrough. */
2834 demand_empty_rest_of_line ();
2838 obj_coff_line (ignore
)
2839 int ignore ATTRIBUTE_UNUSED
;
2844 if (def_symbol_in_progress
== NULL
)
2850 name
= S_GET_NAME (def_symbol_in_progress
);
2851 this_base
= get_absolute_expression ();
2853 /* Only .bf symbols indicate the use of a new base line number; the
2854 line numbers associated with .ef, .bb, .eb are relative to the
2855 start of the containing function. */
2856 if (!strcmp (".bf", name
))
2858 #if 0 /* XXX Can we ever have line numbers going backwards? */
2859 if (this_base
> line_base
)
2861 line_base
= this_base
;
2867 listing_source_line ((unsigned int) line_base
);
2872 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2873 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2875 demand_empty_rest_of_line ();
2879 obj_coff_size (ignore
)
2880 int ignore ATTRIBUTE_UNUSED
;
2882 if (def_symbol_in_progress
== NULL
)
2884 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2885 demand_empty_rest_of_line ();
2889 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2890 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2891 demand_empty_rest_of_line ();
2895 obj_coff_scl (ignore
)
2896 int ignore ATTRIBUTE_UNUSED
;
2898 if (def_symbol_in_progress
== NULL
)
2900 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2901 demand_empty_rest_of_line ();
2905 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2906 demand_empty_rest_of_line ();
2910 obj_coff_tag (ignore
)
2911 int ignore ATTRIBUTE_UNUSED
;
2916 if (def_symbol_in_progress
== NULL
)
2918 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2919 demand_empty_rest_of_line ();
2923 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2924 symbol_name
= input_line_pointer
;
2925 name_end
= get_symbol_end ();
2926 #ifdef tc_canonicalize_symbol_name
2927 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2930 /* Assume that the symbol referred to by .tag is always defined.
2931 This was a bad assumption. I've added find_or_make. xoxorich. */
2932 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2933 (long) tag_find_or_make (symbol_name
));
2934 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2935 as_warn (_("tag not found for .tag %s"), symbol_name
);
2937 SF_SET_TAGGED (def_symbol_in_progress
);
2938 *input_line_pointer
= name_end
;
2940 demand_empty_rest_of_line ();
2944 obj_coff_type (ignore
)
2945 int ignore ATTRIBUTE_UNUSED
;
2947 if (def_symbol_in_progress
== NULL
)
2949 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2950 demand_empty_rest_of_line ();
2954 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2956 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2957 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2958 SF_SET_FUNCTION (def_symbol_in_progress
);
2960 demand_empty_rest_of_line ();
2964 obj_coff_val (ignore
)
2965 int ignore ATTRIBUTE_UNUSED
;
2967 if (def_symbol_in_progress
== NULL
)
2969 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2970 demand_empty_rest_of_line ();
2974 if (is_name_beginner (*input_line_pointer
))
2976 char *symbol_name
= input_line_pointer
;
2977 char name_end
= get_symbol_end ();
2979 #ifdef tc_canonicalize_symbol_name
2980 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2983 if (!strcmp (symbol_name
, "."))
2985 def_symbol_in_progress
->sy_frag
= frag_now
;
2986 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2987 /* If the .val is != from the .def (e.g. statics). */
2989 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2991 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2992 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2993 symbol_find_or_make (symbol_name
);
2994 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2995 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2997 /* If the segment is undefined when the forward reference is
2998 resolved, then copy the segment id from the forward
3000 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
3002 /* FIXME: gcc can generate address expressions here in
3003 unusual cases (search for "obscure" in sdbout.c). We
3004 just ignore the offset here, thus generating incorrect
3005 debugging information. We ignore the rest of the line
3008 /* Otherwise, it is the name of a non debug symbol and
3009 its value will be calculated later. */
3010 *input_line_pointer
= name_end
;
3012 /* FIXME: this is to avoid an error message in the
3013 FIXME case mentioned just above. */
3014 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
3015 ++input_line_pointer
;
3019 S_SET_VALUE (def_symbol_in_progress
,
3020 (valueT
) get_absolute_expression ());
3021 } /* if symbol based */
3023 demand_empty_rest_of_line ();
3028 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
3029 read.c, which then calls this object file format specific routine. */
3032 obj_coff_pe_handle_link_once (type
)
3033 enum linkonce_type type
;
3035 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
3037 /* We store the type in the seg_info structure, and use it to set up
3038 the auxiliary entry for the section symbol in c_section_symbol. */
3039 seg_info (now_seg
)->linkonce
= type
;
3045 coff_obj_read_begin_hook ()
3047 /* These had better be the same. Usually 18 bytes. */
3049 know (sizeof (SYMENT
) == sizeof (AUXENT
));
3050 know (SYMESZ
== AUXESZ
);
3055 /* This function runs through the symbol table and puts all the
3056 externals onto another chain. */
3058 /* The chain of globals. */
3059 symbolS
*symbol_globalP
;
3060 symbolS
*symbol_global_lastP
;
3062 /* The chain of externals. */
3063 symbolS
*symbol_externP
;
3064 symbolS
*symbol_extern_lastP
;
3067 symbolS
*last_functionP
;
3068 static symbolS
*last_bfP
;
3075 unsigned int symbol_number
= 0;
3076 unsigned int last_file_symno
= 0;
3078 struct filename_list
*filename_list_scan
= filename_list_head
;
3080 for (symbolP
= symbol_rootP
;
3082 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
3084 if (symbolP
->sy_mri_common
)
3086 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3088 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3090 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
3091 as_bad (_("%s: global symbols not supported in common sections"),
3092 S_GET_NAME (symbolP
));
3093 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3097 if (!SF_GET_DEBUG (symbolP
))
3099 /* Debug symbols do not need all this rubbish. */
3100 symbolS
*real_symbolP
;
3102 /* L* and C_EFCN symbols never merge. */
3103 if (!SF_GET_LOCAL (symbolP
)
3104 && !SF_GET_STATICS (symbolP
)
3105 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
3106 && symbolP
->sy_value
.X_op
== O_constant
3107 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
3108 && real_symbolP
!= symbolP
)
3110 /* FIXME-SOON: where do dups come from?
3111 Maybe tag references before definitions? xoxorich. */
3112 /* Move the debug data from the debug symbol to the
3113 real symbol. Do NOT do the opposite (i.e. move from
3114 real symbol to debug symbol and remove real symbol from the
3115 list.) Because some pointers refer to the real symbol
3116 whereas no pointers refer to the debug symbol. */
3117 c_symbol_merge (symbolP
, real_symbolP
);
3118 /* Replace the current symbol by the real one. */
3119 /* The symbols will never be the last or the first
3120 because : 1st symbol is .file and 3 last symbols are
3121 .text, .data, .bss. */
3122 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
3123 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
3124 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3125 symbolP
= real_symbolP
;
3128 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
3129 S_SET_SEGMENT (symbolP
, SEG_E0
);
3131 resolve_symbol_value (symbolP
);
3133 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
3135 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
3137 S_SET_EXTERNAL (symbolP
);
3140 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
3141 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
3144 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3147 /* Mainly to speed up if not -g. */
3148 if (SF_GET_PROCESS (symbolP
))
3150 /* Handle the nested blocks auxiliary info. */
3151 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
3153 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
3154 stack_push (block_stack
, (char *) &symbolP
);
3158 symbolS
*begin_symbolP
;
3160 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
3161 if (begin_symbolP
== (symbolS
*) 0)
3162 as_warn (_("mismatched .eb"));
3164 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
3167 /* If we are able to identify the type of a function, and we
3168 are out of a function (last_functionP == 0) then, the
3169 function symbol will be associated with an auxiliary
3171 if (last_functionP
== (symbolS
*) 0 &&
3172 SF_GET_FUNCTION (symbolP
))
3174 last_functionP
= symbolP
;
3176 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3177 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3179 /* Clobber possible stale .dim information. */
3181 /* Iffed out by steve - this fries the lnnoptr info too. */
3182 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3183 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3186 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3188 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3190 if (last_bfP
!= NULL
)
3191 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3195 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3197 /* I don't even know if this is needed for sdb. But
3198 the standard assembler generates it, so... */
3199 if (last_functionP
== (symbolS
*) 0)
3200 as_fatal (_("C_EFCN symbol out of scope"));
3201 SA_SET_SYM_FSIZE (last_functionP
,
3202 (long) (S_GET_VALUE (symbolP
) -
3203 S_GET_VALUE (last_functionP
)));
3204 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3205 last_functionP
= (symbolS
*) 0;
3209 else if (SF_GET_TAG (symbolP
))
3211 /* First descriptor of a structure must point to
3212 the first slot after the structure description. */
3213 last_tagP
= symbolP
;
3216 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3218 /* +2 take in account the current symbol. */
3219 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3221 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3223 /* If the filename was too long to fit in the
3224 auxent, put it in the string table. */
3225 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3226 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3228 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3229 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3230 filename_list_scan
= filename_list_scan
->next
;
3232 if (S_GET_VALUE (symbolP
))
3234 S_SET_VALUE (symbolP
, last_file_symno
);
3235 last_file_symno
= symbol_number
;
3239 #ifdef tc_frob_coff_symbol
3240 tc_frob_coff_symbol (symbolP
);
3243 /* We must put the external symbols apart. The loader
3244 does not bomb if we do not. But the references in
3245 the endndx field for a .bb symbol are not corrected
3246 if an external symbol is removed between .bb and .be.
3247 I.e in the following case :
3248 [20] .bb endndx = 22
3251 ld will move the symbol 21 to the end of the list but
3252 endndx will still be 22 instead of 21. */
3254 if (SF_GET_LOCAL (symbolP
))
3256 /* Remove C_EFCN and LOCAL (L...) symbols. */
3257 /* Next pointer remains valid. */
3258 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3261 else if (symbolP
->sy_value
.X_op
== O_symbol
3262 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3264 /* Skip symbols which were equated to undefined or common
3266 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3268 else if (!S_IS_DEFINED (symbolP
)
3269 && !S_IS_DEBUG (symbolP
)
3270 && !SF_GET_STATICS (symbolP
)
3271 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3273 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3275 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3277 /* If external, Remove from the list. */
3278 symbolS
*hold
= symbol_previous (symbolP
);
3280 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3281 symbol_clear_list_pointers (symbolP
);
3282 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3285 else if (! S_IS_DEBUG (symbolP
)
3286 && ! SF_GET_STATICS (symbolP
)
3287 && ! SF_GET_FUNCTION (symbolP
)
3288 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3290 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3292 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3294 symbolS
*hold
= symbol_previous (symbolP
);
3296 /* The O'Reilly COFF book says that defined global symbols
3297 come at the end of the symbol table, just before
3298 undefined global symbols. */
3299 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3300 symbol_clear_list_pointers (symbolP
);
3301 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3302 &symbol_global_lastP
);
3307 if (SF_GET_STRING (symbolP
))
3309 symbolP
->sy_name_offset
= string_byte_count
;
3310 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3314 symbolP
->sy_name_offset
= 0;
3317 symbolP
->sy_number
= symbol_number
;
3318 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3322 return symbol_number
;
3326 glue_symbols (head
, tail
)
3330 unsigned int symbol_number
= 0;
3332 while (*head
!= NULL
)
3334 symbolS
*tmp
= *head
;
3337 symbol_remove (tmp
, head
, tail
);
3338 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3341 if (SF_GET_STRING (tmp
))
3343 tmp
->sy_name_offset
= string_byte_count
;
3344 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3348 /* Fix "long" names. */
3349 tmp
->sy_name_offset
= 0;
3352 tmp
->sy_number
= symbol_number
;
3353 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3356 return symbol_number
;
3362 unsigned int symbol_number
= 0;
3365 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3367 symbolP
->sy_number
= symbol_number
;
3369 if (SF_GET_TAGGED (symbolP
))
3373 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3376 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3379 return symbol_number
;
3384 crawl_symbols (h
, abfd
)
3386 bfd
*abfd ATTRIBUTE_UNUSED
;
3390 /* Initialize the stack used to keep track of the matching .bb .be. */
3392 block_stack
= stack_init (512, sizeof (symbolS
*));
3394 /* The symbol list should be ordered according to the following sequence
3397 . debug entries for functions
3398 . fake symbols for the sections, including .text .data and .bss
3401 But this is not mandatory. The only important point is to put the
3402 undefined symbols at the end of the list. */
3404 /* Is there a .file symbol ? If not insert one at the beginning. */
3405 if (symbol_rootP
== NULL
3406 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3407 c_dot_file_symbol ("fake");
3409 /* Build up static symbols for the sections, they are filled in later. */
3411 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3412 if (segment_info
[i
].scnhdr
.s_name
[0])
3413 segment_info
[i
].dot
= c_section_symbol ((char *) segment_info
[i
].name
,
3416 /* Take all the externals out and put them into another chain. */
3417 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3418 /* Take the externals and glue them onto the end. */
3419 H_SET_SYMBOL_TABLE_SIZE (h
,
3420 (H_GET_SYMBOL_COUNT (h
)
3421 + glue_symbols (&symbol_globalP
,
3422 &symbol_global_lastP
)
3423 + glue_symbols (&symbol_externP
,
3424 &symbol_extern_lastP
)));
3426 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3427 know (symbol_globalP
== NULL
);
3428 know (symbol_global_lastP
== NULL
);
3429 know (symbol_externP
== NULL
);
3430 know (symbol_extern_lastP
== NULL
);
3433 /* Find strings by crawling along symbol table chain. */
3440 struct filename_list
*filename_list_scan
= filename_list_head
;
3442 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK. */
3443 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3446 #ifdef COFF_LONG_SECTION_NAMES
3447 /* Support long section names as found in PE. This code must
3448 coordinate with that in coff_header_append and write_object_file. */
3452 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3454 if (segment_info
[i
].scnhdr
.s_name
[0]
3455 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3459 size
= strlen (segment_info
[i
].name
) + 1;
3460 memcpy (where
, segment_info
[i
].name
, size
);
3465 #endif /* COFF_LONG_SECTION_NAMES */
3467 for (symbolP
= symbol_rootP
;
3469 symbolP
= symbol_next (symbolP
))
3473 if (SF_GET_STRING (symbolP
))
3475 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3476 memcpy (where
, S_GET_NAME (symbolP
), size
);
3479 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3480 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3481 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3483 size
= strlen (filename_list_scan
->filename
) + 1;
3484 memcpy (where
, filename_list_scan
->filename
, size
);
3485 filename_list_scan
= filename_list_scan
->next
;
3492 do_linenos_for (abfd
, h
, file_cursor
)
3495 unsigned long *file_cursor
;
3498 unsigned long start
= *file_cursor
;
3500 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3502 segment_info_type
*s
= segment_info
+ idx
;
3504 if (s
->scnhdr
.s_nlnno
!= 0)
3506 struct lineno_list
*line_ptr
;
3508 struct external_lineno
*buffer
=
3509 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3511 struct external_lineno
*dst
= buffer
;
3513 /* Run through the table we've built and turn it into its external
3514 form, take this chance to remove duplicates. */
3516 for (line_ptr
= s
->lineno_list_head
;
3517 line_ptr
!= (struct lineno_list
*) NULL
;
3518 line_ptr
= line_ptr
->next
)
3520 if (line_ptr
->line
.l_lnno
== 0)
3522 /* Turn a pointer to a symbol into the symbols' index,
3523 provided that it has been initialised. */
3524 if (line_ptr
->line
.l_addr
.l_symndx
)
3525 line_ptr
->line
.l_addr
.l_symndx
=
3526 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3529 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3531 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3535 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3537 bfd_bwrite (buffer
, (bfd_size_type
) s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3540 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3544 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3547 /* Now we run through the list of frag chains in a segment and
3548 make all the subsegment frags appear at the end of the
3549 list, as if the seg 0 was extra long. */
3556 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3558 frchainS
*head
= segment_info
[i
].frchainP
;
3560 fragS
*prev_frag
= &dummy
;
3562 while (head
&& head
->frch_seg
== i
)
3564 prev_frag
->fr_next
= head
->frch_root
;
3565 prev_frag
= head
->frch_last
;
3566 head
= head
->frch_next
;
3568 prev_frag
->fr_next
= 0;
3572 unsigned long machine
;
3575 #ifndef SUB_SEGMENT_ALIGN
3577 /* The last subsegment gets an alignment corresponding to the alignment
3578 of the section. This allows proper nop-filling at the end of
3579 code-bearing sections. */
3580 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
3581 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \
3582 ? get_recorded_alignment (SEG) : 0)
3584 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 1
3589 write_object_file ()
3593 struct frchain
*frchain_ptr
;
3595 object_headers headers
;
3596 unsigned long file_cursor
;
3599 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3603 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3604 exit (EXIT_FAILURE
);
3606 bfd_set_format (abfd
, bfd_object
);
3607 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3609 string_byte_count
= 4;
3611 /* Run through all the sub-segments and align them up. Also
3612 close any open frags. We tack a .fill onto the end of the
3613 frag chain so that any .align's size can be worked by looking
3614 at the next frag. */
3615 for (frchain_ptr
= frchain_root
;
3616 frchain_ptr
!= (struct frchain
*) NULL
;
3617 frchain_ptr
= frchain_ptr
->frch_next
)
3621 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3623 alignment
= SUB_SEGMENT_ALIGN (now_seg
, frchain_ptr
);
3626 md_do_align (alignment
, (char *) NULL
, 0, 0, alignment_done
);
3628 if (subseg_text_p (now_seg
))
3629 frag_align_code (alignment
, 0);
3631 frag_align (alignment
, 0, 0);
3637 frag_wane (frag_now
);
3638 frag_now
->fr_fix
= 0;
3639 know (frag_now
->fr_next
== NULL
);
3644 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3645 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3647 /* Relaxation has completed. Freeze all syms. */
3650 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3652 /* Find out how big the sections are, and set the addresses. */
3654 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3658 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3659 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3661 if (segment_info
[i
].scnhdr
.s_name
[0])
3663 H_SET_NUMBER_OF_SECTIONS (&headers
,
3664 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3666 #ifdef COFF_LONG_SECTION_NAMES
3667 /* Support long section names as found in PE. This code
3668 must coordinate with that in coff_header_append and
3673 len
= strlen (segment_info
[i
].name
);
3675 string_byte_count
+= len
+ 1;
3677 #endif /* COFF_LONG_SECTION_NAMES */
3680 size
= size_section (abfd
, (unsigned int) i
);
3683 /* I think the section alignment is only used on the i960; the
3684 i960 needs it, and it should do no harm on other targets. */
3685 #ifdef ALIGNMENT_IN_S_FLAGS
3686 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3688 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3692 H_SET_TEXT_SIZE (&headers
, size
);
3693 else if (i
== SEG_E1
)
3694 H_SET_DATA_SIZE (&headers
, size
);
3695 else if (i
== SEG_E2
)
3696 H_SET_BSS_SIZE (&headers
, size
);
3699 /* Turn the gas native symbol table shape into a coff symbol table. */
3700 crawl_symbols (&headers
, abfd
);
3702 if (string_byte_count
== 4)
3703 string_byte_count
= 0;
3705 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3711 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3713 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3714 fixup_segment (&segment_info
[i
], i
);
3717 /* Look for ".stab" segments and fill in their initial symbols
3719 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3721 name
= segment_info
[i
].name
;
3724 && strncmp (".stab", name
, 5) == 0
3725 && strncmp (".stabstr", name
, 8) != 0)
3726 adjust_stab_section (abfd
, i
);
3729 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3731 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3733 /* Plant the data. */
3734 fill_section (abfd
, &headers
, &file_cursor
);
3736 do_relocs_for (abfd
, &headers
, &file_cursor
);
3738 do_linenos_for (abfd
, &headers
, &file_cursor
);
3740 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3741 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3742 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3744 H_SET_TIME_STAMP (&headers
, 0);
3746 #ifdef TC_COFF_SET_MACHINE
3747 TC_COFF_SET_MACHINE (&headers
);
3751 #define COFF_FLAGS 0
3754 #ifdef KEEP_RELOC_INFO
3755 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3756 COFF_FLAGS
| coff_flags
));
3758 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3759 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3760 COFF_FLAGS
| coff_flags
));
3764 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3765 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3767 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3768 w_symbols (abfd
, buffer1
, symbol_rootP
);
3769 if (string_byte_count
> 0)
3770 w_strings (buffer1
+ symtable_size
);
3771 bfd_bwrite (buffer1
, (bfd_size_type
) symtable_size
+ string_byte_count
,
3776 coff_header_append (abfd
, &headers
);
3778 /* Recent changes to write need this, but where it should
3779 go is up to Ken.. */
3780 if (!bfd_close_all_done (abfd
))
3781 as_fatal (_("Can't close %s: %s"), out_file_name
,
3782 bfd_errmsg (bfd_get_error ()));
3785 extern bfd
*stdoutput
;
3792 /* Add a new segment. This is called from subseg_new via the
3793 obj_new_segment macro. */
3796 obj_coff_add_segment (name
)
3801 #ifndef COFF_LONG_SECTION_NAMES
3802 char buf
[SCNNMLEN
+ 1];
3804 strncpy (buf
, name
, SCNNMLEN
);
3805 buf
[SCNNMLEN
] = '\0';
3809 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3810 if (strcmp (name
, segment_info
[i
].name
) == 0)
3815 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3819 /* Add a new section. */
3820 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3821 sizeof (segment_info
[i
].scnhdr
.s_name
));
3822 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3823 segment_info
[i
].name
= xstrdup (name
);
3828 /* Implement the .section pseudo op:
3829 .section name {, "flags"}
3831 | +--- optional flags: 'b' for bss
3833 +-- section name 'l' for lib
3837 'd' (apparently m88k for data)
3839 'r' for read-only data
3840 But if the argument is not a quoted string, treat it as a
3841 subsegment number. */
3844 obj_coff_section (ignore
)
3845 int ignore ATTRIBUTE_UNUSED
;
3847 /* Strip out the section name. */
3848 char *section_name
, *name
;
3861 else if (type
== 'D')
3863 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3868 section_name
= input_line_pointer
;
3869 c
= get_symbol_end ();
3871 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3872 strcpy (name
, section_name
);
3874 *input_line_pointer
= c
;
3880 if (*input_line_pointer
== ',')
3882 ++input_line_pointer
;
3885 if (*input_line_pointer
!= '"')
3886 exp
= get_absolute_expression ();
3889 ++input_line_pointer
;
3890 while (*input_line_pointer
!= '"'
3891 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3893 switch (*input_line_pointer
)
3895 case 'b': flags
|= STYP_BSS
; break;
3896 case 'i': flags
|= STYP_INFO
; break;
3897 case 'l': flags
|= STYP_LIB
; break;
3898 case 'n': flags
|= STYP_NOLOAD
; break;
3899 case 'o': flags
|= STYP_OVER
; break;
3901 case 'w': flags
|= STYP_DATA
; break;
3902 case 'x': flags
|= STYP_TEXT
; break;
3903 case 'r': flags
|= STYP_LIT
; break;
3905 as_warn(_("unknown section attribute '%c'"),
3906 *input_line_pointer
);
3909 ++input_line_pointer
;
3911 if (*input_line_pointer
== '"')
3912 ++input_line_pointer
;
3916 subseg_new (name
, (subsegT
) exp
);
3918 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3920 demand_empty_rest_of_line ();
3924 obj_coff_text (ignore
)
3925 int ignore ATTRIBUTE_UNUSED
;
3927 subseg_new (".text", get_absolute_expression ());
3931 obj_coff_data (ignore
)
3932 int ignore ATTRIBUTE_UNUSED
;
3934 if (flag_readonly_data_in_text
)
3935 subseg_new (".text", get_absolute_expression () + 1000);
3937 subseg_new (".data", get_absolute_expression ());
3941 obj_coff_ident (ignore
)
3942 int ignore ATTRIBUTE_UNUSED
;
3944 segT current_seg
= now_seg
; /* Save current seg. */
3945 subsegT current_subseg
= now_subseg
;
3947 subseg_new (".comment", 0); /* .comment seg. */
3948 stringer (1); /* Read string. */
3949 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
3953 c_symbol_merge (debug
, normal
)
3957 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3958 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3960 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3961 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3963 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3964 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3965 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3966 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3968 /* Move the debug flags. */
3969 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3973 c_line_new (symbol
, paddr
, line_number
, frag
)
3979 struct lineno_list
*new_line
=
3980 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3982 segment_info_type
*s
= segment_info
+ now_seg
;
3983 new_line
->line
.l_lnno
= line_number
;
3985 if (line_number
== 0)
3987 last_line_symbol
= symbol
;
3988 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3992 new_line
->line
.l_addr
.l_paddr
= paddr
;
3995 new_line
->frag
= (char *) frag
;
3996 new_line
->next
= (struct lineno_list
*) NULL
;
3998 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3999 s
->lineno_list_head
= new_line
;
4001 s
->lineno_list_tail
->next
= new_line
;
4003 s
->lineno_list_tail
= new_line
;
4004 return LINESZ
* s
->scnhdr
.s_nlnno
++;
4008 c_dot_file_symbol (filename
)
4013 symbolP
= symbol_new (".file",
4016 &zero_address_frag
);
4018 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
4019 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
4021 if (strlen (filename
) > FILNMLEN
)
4023 /* Filename is too long to fit into an auxent,
4024 we stick it into the string table instead. We keep
4025 a linked list of the filenames we find so we can emit
4027 struct filename_list
*f
= ((struct filename_list
*)
4028 xmalloc (sizeof (struct filename_list
)));
4030 f
->filename
= filename
;
4033 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
4034 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
4036 if (filename_list_tail
)
4037 filename_list_tail
->next
= f
;
4039 filename_list_head
= f
;
4040 filename_list_tail
= f
;
4044 SA_SET_FILE_FNAME (symbolP
, filename
);
4050 listing_source_file (filename
);
4053 SF_SET_DEBUG (symbolP
);
4054 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
4056 previous_file_symbol
= symbolP
;
4058 /* Make sure that the symbol is first on the symbol chain. */
4059 if (symbol_rootP
!= symbolP
)
4061 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
4062 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
4066 /* Build a 'section static' symbol. */
4069 c_section_symbol (name
, idx
)
4075 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
4076 if (symbolP
== NULL
)
4077 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
4080 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
4081 S_SET_SEGMENT (symbolP
, idx
);
4082 symbolP
->sy_frag
= &zero_address_frag
;
4085 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4086 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
4088 SF_SET_STATICS (symbolP
);
4091 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
4092 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
4093 SF_CLEAR_LOCAL (symbolP
);
4096 /* If the .linkonce pseudo-op was used for this section, we must
4097 store the information in the auxiliary entry for the section
4099 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
4103 switch (segment_info
[idx
].linkonce
)
4107 case LINKONCE_DISCARD
:
4108 type
= IMAGE_COMDAT_SELECT_ANY
;
4110 case LINKONCE_ONE_ONLY
:
4111 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
4113 case LINKONCE_SAME_SIZE
:
4114 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
4116 case LINKONCE_SAME_CONTENTS
:
4117 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
4121 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
4129 w_symbols (abfd
, where
, symbol_rootP
)
4132 symbolS
* symbol_rootP
;
4137 /* First fill in those values we have only just worked out. */
4138 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
4140 symbolP
= segment_info
[i
].dot
;
4143 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
4144 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
4145 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
4149 /* Emit all symbols left in the symbol chain. */
4150 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
4152 /* Used to save the offset of the name. It is used to point
4153 to the string in memory but must be a file offset. */
4156 /* We can't fix the lnnoptr field in yank_symbols with the other
4157 adjustments, because we have to wait until we know where they
4159 if (SF_GET_ADJ_LNNOPTR (symbolP
))
4160 SA_GET_SYM_LNNOPTR (symbolP
) +=
4161 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4163 tc_coff_symbol_emit_hook (symbolP
);
4165 temp
= S_GET_NAME (symbolP
);
4166 if (SF_GET_STRING (symbolP
))
4168 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4169 S_SET_ZEROES (symbolP
, 0);
4173 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4174 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4176 where
= symbol_to_chars (abfd
, where
, symbolP
);
4177 S_SET_NAME (symbolP
, temp
);
4182 obj_coff_lcomm (ignore
)
4183 int ignore ATTRIBUTE_UNUSED
;
4195 name
= input_line_pointer
;
4197 c
= get_symbol_end ();
4198 p
= input_line_pointer
;
4201 if (*input_line_pointer
!= ',')
4203 as_bad (_("Expected comma after name"));
4204 ignore_rest_of_line ();
4207 if (*input_line_pointer
== '\n')
4209 as_bad (_("Missing size expression"));
4212 input_line_pointer
++;
4213 if ((temp
= get_absolute_expression ()) < 0)
4215 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4216 ignore_rest_of_line ();
4221 symbolP
= symbol_find_or_make (name
);
4223 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
&&
4224 S_GET_VALUE (symbolP
) == 0)
4229 segT current_seg
= now_seg
; /* Save current seg. */
4230 subsegT current_subseg
= now_subseg
;
4232 subseg_set (SEG_E2
, 1);
4233 symbolP
->sy_frag
= frag_now
;
4234 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4235 (offsetT
) temp
, (char *) 0);
4237 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
4238 S_SET_SEGMENT (symbolP
, SEG_E2
);
4239 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4243 as_bad (_("Symbol %s already defined"), name
);
4245 demand_empty_rest_of_line ();
4250 fixup_mdeps (frags
, h
, this_segment
)
4252 object_headers
*h ATTRIBUTE_UNUSED
;
4255 subseg_change (this_segment
, 0);
4259 switch (frags
->fr_type
)
4266 HANDLE_ALIGN (frags
);
4268 frags
->fr_type
= rs_fill
;
4270 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4273 case rs_machine_dependent
:
4274 md_convert_frag (h
, this_segment
, frags
);
4280 frags
= frags
->fr_next
;
4286 #ifndef TC_FORCE_RELOCATION
4287 #define TC_FORCE_RELOCATION(fix) 0
4291 fixup_segment (segP
, this_segment_type
)
4292 segment_info_type
* segP
;
4293 segT this_segment_type
;
4296 symbolS
*add_symbolP
;
4297 symbolS
*sub_symbolP
;
4304 segT add_symbol_segment
= absolute_section
;
4306 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4308 fragP
= fixP
->fx_frag
;
4310 where
= fixP
->fx_where
;
4311 place
= fragP
->fr_literal
+ where
;
4312 size
= fixP
->fx_size
;
4313 add_symbolP
= fixP
->fx_addsy
;
4314 sub_symbolP
= fixP
->fx_subsy
;
4315 add_number
= fixP
->fx_offset
;
4316 pcrel
= fixP
->fx_pcrel
;
4318 /* We want function-relative stabs to work on systems which
4319 may use a relaxing linker; thus we must handle the sym1-sym2
4320 fixups function-relative stabs generates.
4322 Of course, if you actually enable relaxing in the linker, the
4323 line and block scoping information is going to be incorrect
4324 in some cases. The only way to really fix this is to support
4325 a reloc involving the difference of two symbols. */
4327 && (!sub_symbolP
|| pcrel
))
4331 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4333 /* Relocation should be done via the associated 'bal' entry
4336 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4338 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4339 _("No 'bal' entry point for leafproc %s"),
4340 S_GET_NAME (add_symbolP
));
4343 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4347 /* Make sure the symbols have been resolved; this may not have
4348 happened if these are expression symbols. */
4349 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4350 resolve_symbol_value (add_symbolP
);
4352 if (add_symbolP
!= NULL
)
4354 /* If this fixup is against a symbol which has been equated
4355 to another symbol, convert it to the other symbol. */
4356 if (add_symbolP
->sy_value
.X_op
== O_symbol
4357 && (! S_IS_DEFINED (add_symbolP
)
4358 || S_IS_COMMON (add_symbolP
)))
4360 while (add_symbolP
->sy_value
.X_op
== O_symbol
4361 && (! S_IS_DEFINED (add_symbolP
)
4362 || S_IS_COMMON (add_symbolP
)))
4366 /* We must avoid looping, as that can occur with a
4367 badly written program. */
4368 n
= add_symbolP
->sy_value
.X_add_symbol
;
4369 if (n
== add_symbolP
)
4371 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4374 fixP
->fx_addsy
= add_symbolP
;
4375 fixP
->fx_offset
= add_number
;
4379 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4380 resolve_symbol_value (sub_symbolP
);
4382 if (add_symbolP
!= NULL
4383 && add_symbolP
->sy_mri_common
)
4385 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4386 add_number
+= S_GET_VALUE (add_symbolP
);
4387 fixP
->fx_offset
= add_number
;
4388 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4392 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4396 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4398 if (add_symbolP
!= NULL
)
4400 add_number
+= S_GET_VALUE (add_symbolP
);
4402 fixP
->fx_addsy
= NULL
;
4405 /* It's just -sym. */
4406 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4408 add_number
-= S_GET_VALUE (sub_symbolP
);
4415 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4416 _("Negative of non-absolute symbol %s"),
4417 S_GET_NAME (sub_symbolP
));
4419 add_number
-= S_GET_VALUE (sub_symbolP
);
4420 } /* not absolute */
4422 /* if sub_symbol is in the same segment that add_symbol
4423 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE. */
4425 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4426 && SEG_NORMAL (add_symbol_segment
))
4428 /* Difference of 2 symbols from same segment. Can't
4429 make difference of 2 undefineds: 'value' means
4430 something different for N_UNDF. */
4432 /* Makes no sense to use the difference of 2 arbitrary symbols
4433 as the target of a call instruction. */
4435 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4436 _("callj to difference of 2 symbols"));
4437 #endif /* TC_I960 */
4438 add_number
+= S_GET_VALUE (add_symbolP
) -
4439 S_GET_VALUE (sub_symbolP
);
4442 if (!TC_FORCE_RELOCATION (fixP
))
4444 fixP
->fx_addsy
= NULL
;
4445 fixP
->fx_subsy
= NULL
;
4447 #ifdef TC_M68K /* is this right? */
4455 /* Different segments in subtraction. */
4456 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4458 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4459 add_number
-= S_GET_VALUE (sub_symbolP
);
4462 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4463 #if 0 /* Okay for 68k, at least... */
4468 /* Make it pc-relative. */
4469 add_number
+= (md_pcrel_from (fixP
)
4470 - S_GET_VALUE (sub_symbolP
));
4479 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4480 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4481 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4482 S_GET_NAME (sub_symbolP
),
4483 (long) (fragP
->fr_address
+ where
));
4490 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4492 /* This fixup was made when the symbol's segment was
4493 SEG_UNKNOWN, but it is now in the local segment.
4494 So we know how to do the address without relocation. */
4496 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4497 in which cases it modifies *fixP as appropriate. In the case
4498 of a 'calls', no further work is required, and *fixP has been
4499 set up to make the rest of the code below a no-op. */
4501 #endif /* TC_I960 */
4503 add_number
+= S_GET_VALUE (add_symbolP
);
4504 add_number
-= md_pcrel_from (fixP
);
4507 add_number -= segP->scnhdr.s_vaddr;
4508 if defined (TC_I386) || defined (TE_LYNX). I now
4509 think that was an error propagated from the case when
4510 we are going to emit the relocation. If we are not
4511 going to emit the relocation, then we just want to
4512 set add_number to the difference between the symbols.
4513 This is a case that would only arise when there is a
4514 PC relative reference from a section other than .text
4515 to a symbol defined in the same section, and the
4516 reference is not relaxed. Since jump instructions on
4517 the i386 are relaxed, this could only arise with a
4518 call instruction. */
4520 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4521 if (!TC_FORCE_RELOCATION (fixP
))
4523 fixP
->fx_addsy
= NULL
;
4529 switch (add_symbol_segment
)
4531 case absolute_section
:
4533 /* See comment about reloc_callj() above. */
4535 #endif /* TC_I960 */
4536 add_number
+= S_GET_VALUE (add_symbolP
);
4539 if (!TC_FORCE_RELOCATION (fixP
))
4541 fixP
->fx_addsy
= NULL
;
4547 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4548 /* This really should be handled in the linker, but
4549 backward compatibility forbids. */
4550 add_number
+= S_GET_VALUE (add_symbolP
);
4552 add_number
+= S_GET_VALUE (add_symbolP
) +
4553 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4559 if ((int) fixP
->fx_bit_fixP
== 13)
4561 /* This is a COBR instruction. They have only a
4562 13-bit displacement and are only to be used
4563 for local branches: flag as error, don't generate
4565 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4566 _("can't use COBR format with external label"));
4567 fixP
->fx_addsy
= NULL
;
4571 #endif /* TC_I960 */
4572 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4573 /* 386 COFF uses a peculiar format in which the
4574 value of a common symbol is stored in the .text
4575 segment (I've checked this on SVR3.2 and SCO
4576 3.2.2) Ian Taylor <ian@cygnus.com>. */
4577 /* This is also true for 68k COFF on sysv machines
4578 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4579 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4580 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4581 if (S_IS_COMMON (add_symbolP
))
4582 add_number
+= S_GET_VALUE (add_symbolP
);
4592 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) && !defined(TC_OR32)
4593 /* This adjustment is not correct on the m88k, for which the
4594 linker does all the computation. */
4595 add_number
-= md_pcrel_from (fixP
);
4597 if (add_symbolP
== 0)
4598 fixP
->fx_addsy
= &abs_symbol
;
4599 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4600 /* On the 386 we must adjust by the segment vaddr as well.
4603 I changed the i960 to work this way as well. This is
4604 compatible with the current GNU linker behaviour. I do
4605 not know what other i960 COFF assemblers do. This is not
4606 a common case: normally, only assembler code will contain
4607 a PC relative reloc, and only branches which do not
4608 originate in the .text section will have a non-zero
4611 I changed the m68k to work this way as well. This will
4612 break existing PC relative relocs from sections which do
4613 not start at address 0, but it will make ld -r work.
4614 Ian Taylor, 4 Oct 96. */
4616 add_number
-= segP
->scnhdr
.s_vaddr
;
4620 md_apply_fix3 (fixP
, (valueT
*) & add_number
, this_segment_type
);
4622 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4625 /* The m88k uses the offset field of the reloc to get around
4628 && ((add_number
& ~0xFF)
4629 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4630 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4631 || (add_number
& 0x80) == 0))
4633 && ((add_number
& ~0xFFFF)
4634 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4635 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4636 || (add_number
& 0x8000) == 0)))
4638 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4639 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4640 (long) add_number
, size
,
4641 (unsigned long) (fragP
->fr_address
+ where
));
4644 #ifdef WARN_SIGNED_OVERFLOW_WORD
4645 /* Warn if a .word value is too large when treated as a
4646 signed number. We already know it is not too negative.
4647 This is to catch over-large switches generated by gcc on
4649 if (!flag_signed_overflow_ok
4651 && add_number
> 0x7fff)
4652 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4653 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4655 (unsigned long) (fragP
->fr_address
+ where
));
4663 /* The first entry in a .stab section is special. */
4666 obj_coff_init_stab_section (seg
)
4672 unsigned int stroff
;
4674 /* Make space for this first symbol. */
4678 as_where (&file
, (unsigned int *) NULL
);
4679 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4680 strcpy (stabstr_name
, segment_info
[seg
].name
);
4681 strcat (stabstr_name
, "str");
4682 stroff
= get_stab_string_offset (file
, stabstr_name
);
4684 md_number_to_chars (p
, stroff
, 4);
4687 /* Fill in the counts in the first entry in a .stab section. */
4690 adjust_stab_section(abfd
, seg
)
4694 segT stabstrseg
= SEG_UNKNOWN
;
4695 const char *secname
, *name2
;
4698 int i
, strsz
= 0, nsyms
;
4699 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4701 /* Look for the associated string table section. */
4703 secname
= segment_info
[seg
].name
;
4704 name
= (char *) alloca (strlen (secname
) + 4);
4705 strcpy (name
, secname
);
4706 strcat (name
, "str");
4708 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4710 name2
= segment_info
[i
].name
;
4711 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4718 /* If we found the section, get its size. */
4719 if (stabstrseg
!= SEG_UNKNOWN
)
4720 strsz
= size_section (abfd
, stabstrseg
);
4722 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4724 /* Look for the first frag of sufficient size for the initial stab
4725 symbol, and collect a pointer to it. */
4726 while (frag
&& frag
->fr_fix
< 12)
4727 frag
= frag
->fr_next
;
4729 p
= frag
->fr_literal
;
4732 /* Write in the number of stab symbols and the size of the string
4734 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4735 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4738 #endif /* not BFD_ASSEMBLER */
4740 const pseudo_typeS coff_pseudo_table
[] =
4742 {"def", obj_coff_def
, 0},
4743 {"dim", obj_coff_dim
, 0},
4744 {"endef", obj_coff_endef
, 0},
4745 {"line", obj_coff_line
, 0},
4746 {"ln", obj_coff_ln
, 0},
4747 #ifdef BFD_ASSEMBLER
4748 {"loc", obj_coff_loc
, 0},
4750 {"appline", obj_coff_ln
, 1},
4751 {"scl", obj_coff_scl
, 0},
4752 {"size", obj_coff_size
, 0},
4753 {"tag", obj_coff_tag
, 0},
4754 {"type", obj_coff_type
, 0},
4755 {"val", obj_coff_val
, 0},
4756 {"section", obj_coff_section
, 0},
4757 {"sect", obj_coff_section
, 0},
4758 /* FIXME: We ignore the MRI short attribute. */
4759 {"section.s", obj_coff_section
, 0},
4760 {"sect.s", obj_coff_section
, 0},
4761 /* We accept the .bss directive for backward compatibility with
4762 earlier versions of gas. */
4763 {"bss", obj_coff_bss
, 0},
4764 {"ident", obj_coff_ident
, 0},
4765 #ifndef BFD_ASSEMBLER
4766 {"use", obj_coff_section
, 0},
4767 {"text", obj_coff_text
, 0},
4768 {"data", obj_coff_data
, 0},
4769 {"lcomm", obj_coff_lcomm
, 0},
4771 {"weak", obj_coff_weak
, 0},
4772 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4774 {"version", s_ignore
, 0},
4775 {"ABORT", s_abort
, 0},
4776 #if defined( TC_M88K ) || defined ( TC_TIC4X )
4777 /* The m88k and tic4x uses sdef instead of def. */
4778 {"sdef", obj_coff_def
, 0},
4780 {NULL
, NULL
, 0} /* end sentinel */
4781 }; /* coff_pseudo_table */
4783 #ifdef BFD_ASSEMBLER
4785 /* Support for a COFF emulation. */
4787 static void coff_pop_insert
PARAMS ((void));
4788 static int coff_separate_stab_sections
PARAMS ((void));
4793 pop_insert (coff_pseudo_table
);
4797 coff_separate_stab_sections ()
4802 const struct format_ops coff_format_ops
=
4804 bfd_target_coff_flavour
,
4805 0, /* dfl_leading_underscore */
4806 1, /* emit_section_symbols */
4811 0, /* frob_file_before_adjust */
4812 0, /* frob_file_before_fix */
4813 coff_frob_file_after_relocs
,
4816 0, /* s_get_align */
4817 0, /* s_set_align */
4818 0, /* s_get_other */
4819 0, /* s_set_other */
4824 0, /* copy_symbol_attributes */
4825 0, /* generate_asm_lineno */
4826 0, /* process_stab */
4827 coff_separate_stab_sections
,
4828 obj_coff_init_stab_section
,
4829 0, /* sec_sym_ok_for_reloc */
4831 0, /* ecoff_set_ext */
4832 coff_obj_read_begin_hook
,
4833 coff_obj_symbol_new_hook