1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
29 /* I think this is probably always correct. */
30 #ifndef KEEP_RELOC_INFO
31 #define KEEP_RELOC_INFO
34 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
35 a new section's attributes when a directive has no valid flags or the
36 "w" flag is used. This default should be appropriate for most. */
37 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
38 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
41 /* This is used to hold the symbol built by a sequence of pseudo-ops
42 from .def and .endef. */
43 static symbolS
*def_symbol_in_progress
;
47 unsigned long chunk_size
;
48 unsigned long element_size
;
51 unsigned long pointer
;
55 static stack
*stack_init
PARAMS ((unsigned long, unsigned long));
56 static char *stack_push
PARAMS ((stack
*, char *));
57 static char *stack_pop
PARAMS ((stack
*));
58 static void tag_init
PARAMS ((void));
59 static void tag_insert
PARAMS ((const char *, symbolS
*));
60 static symbolS
*tag_find
PARAMS ((char *));
61 static symbolS
*tag_find_or_make
PARAMS ((char *));
62 static void obj_coff_bss
PARAMS ((int));
63 static void obj_coff_weak
PARAMS ((int));
64 const char *s_get_name
PARAMS ((symbolS
* s
));
65 static void obj_coff_ln
PARAMS ((int));
66 static void obj_coff_def
PARAMS ((int));
67 static void obj_coff_endef
PARAMS ((int));
68 static void obj_coff_dim
PARAMS ((int));
69 static void obj_coff_line
PARAMS ((int));
70 static void obj_coff_size
PARAMS ((int));
71 static void obj_coff_scl
PARAMS ((int));
72 static void obj_coff_tag
PARAMS ((int));
73 static void obj_coff_val
PARAMS ((int));
74 static void obj_coff_type
PARAMS ((int));
75 static void obj_coff_ident
PARAMS ((int));
77 static void obj_coff_loc
PARAMS((int));
83 stack_init (chunk_size
, element_size
)
84 unsigned long chunk_size
;
85 unsigned long element_size
;
89 st
= (stack
*) malloc (sizeof (stack
));
92 st
->data
= malloc (chunk_size
);
99 st
->size
= chunk_size
;
100 st
->chunk_size
= chunk_size
;
101 st
->element_size
= element_size
;
106 /* Not currently used. */
117 stack_push (st
, element
)
121 if (st
->pointer
+ st
->element_size
>= st
->size
)
123 st
->size
+= st
->chunk_size
;
124 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
127 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
128 st
->pointer
+= st
->element_size
;
129 return st
->data
+ st
->pointer
;
136 if (st
->pointer
< st
->element_size
)
141 st
->pointer
-= st
->element_size
;
142 return st
->data
+ st
->pointer
;
146 * Maintain a list of the tagnames of the structures.
149 static struct hash_control
*tag_hash
;
154 tag_hash
= hash_new ();
158 tag_insert (name
, symbolP
)
162 const char *error_string
;
164 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
166 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
175 #ifdef STRIP_UNDERSCORE
178 #endif /* STRIP_UNDERSCORE */
179 return (symbolS
*) hash_find (tag_hash
, name
);
183 tag_find_or_make (name
)
188 if ((symbolP
= tag_find (name
)) == NULL
)
190 symbolP
= symbol_new (name
, undefined_section
,
191 0, &zero_address_frag
);
193 tag_insert (S_GET_NAME (symbolP
), symbolP
);
195 symbol_table_insert (symbolP
);
202 /* We accept the .bss directive to set the section for backward
203 compatibility with earlier versions of gas. */
206 obj_coff_bss (ignore
)
207 int ignore ATTRIBUTE_UNUSED
;
209 if (*input_line_pointer
== '\n')
210 subseg_new (".bss", get_absolute_expression ());
217 static segT fetch_coff_debug_section
PARAMS ((void));
218 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
219 static int S_GET_DATA_TYPE
PARAMS ((symbolS
*));
220 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
221 static void add_lineno
PARAMS ((fragS
*, addressT
, int));
223 #define GET_FILENAME_STRING(X) \
224 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
228 fetch_coff_debug_section ()
230 static segT debug_section
;
234 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
236 debug_section
= s
->section
;
238 return debug_section
;
242 SA_SET_SYM_ENDNDX (sym
, val
)
246 combined_entry_type
*entry
, *p
;
248 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
249 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
250 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
255 SA_SET_SYM_TAGNDX (sym
, val
)
259 combined_entry_type
*entry
, *p
;
261 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
262 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
263 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
268 S_GET_DATA_TYPE (sym
)
271 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
275 S_SET_DATA_TYPE (sym
, val
)
279 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
284 S_GET_STORAGE_CLASS (sym
)
287 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
291 S_SET_STORAGE_CLASS (sym
, val
)
295 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
299 /* Merge a debug symbol containing debug information into a normal symbol. */
302 c_symbol_merge (debug
, normal
)
306 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
307 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
309 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
311 /* take the most we have */
312 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
315 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
317 /* Move all the auxiliary information. */
318 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
319 (S_GET_NUMBER_AUXILIARY (debug
)
320 * sizeof (*SYM_AUXINFO (debug
))));
323 /* Move the debug flags. */
324 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
328 c_dot_file_symbol (filename
)
329 const char *filename
;
333 /* BFD converts filename to a .file symbol with an aux entry. It
334 also handles chaining. */
335 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
337 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
338 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
340 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
347 listing_source_file (filename
);
352 /* Make sure that the symbol is first on the symbol chain */
353 if (symbol_rootP
!= symbolP
)
355 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
356 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
357 } /* if not first on the list */
360 /* Line number handling */
363 struct line_no
*next
;
370 /* Symbol of last function, which we should hang line#s off of. */
371 static symbolS
*line_fsym
;
373 #define in_function() (line_fsym != 0)
374 #define clear_function() (line_fsym = 0)
375 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
379 coff_obj_symbol_new_hook (symbolP
)
382 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
383 char * s
= (char *) xmalloc (sz
);
386 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
388 S_SET_DATA_TYPE (symbolP
, T_NULL
);
389 S_SET_STORAGE_CLASS (symbolP
, 0);
390 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
392 if (S_IS_STRING (symbolP
))
393 SF_SET_STRING (symbolP
);
395 if (S_IS_LOCAL (symbolP
))
396 SF_SET_LOCAL (symbolP
);
401 * Handle .ln directives.
404 static symbolS
*current_lineno_sym
;
405 static struct line_no
*line_nos
;
406 /* @@ Blindly assume all .ln directives will be in the .text section... */
410 add_lineno (frag
, offset
, num
)
415 struct line_no
*new_line
=
416 (struct line_no
*) xmalloc (sizeof (struct line_no
));
417 if (!current_lineno_sym
)
423 /* The native aix assembler accepts negative line number */
427 /* Zero is used as an end marker in the file. */
428 as_warn (_("Line numbers must be positive integers\n"));
431 #endif /* OBJ_XCOFF */
432 new_line
->next
= line_nos
;
433 new_line
->frag
= frag
;
434 new_line
->l
.line_number
= num
;
435 new_line
->l
.u
.offset
= offset
;
441 coff_add_linesym (sym
)
446 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
451 current_lineno_sym
= sym
;
455 obj_coff_ln (appline
)
460 if (! appline
&& def_symbol_in_progress
!= NULL
)
462 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
463 demand_empty_rest_of_line ();
467 l
= get_absolute_expression ();
469 /* If there is no lineno symbol, treat a .ln
470 directive as if it were a .appline directive. */
471 if (appline
|| current_lineno_sym
== NULL
)
472 new_logical_line ((char *) NULL
, l
- 1);
474 add_lineno (frag_now
, frag_now_fix (), l
);
483 l
+= coff_line_base
- 1;
484 listing_source_line (l
);
489 demand_empty_rest_of_line ();
492 /* .loc is essentially the same as .ln; parse it for assembler
496 obj_coff_loc (ignore
)
497 int ignore ATTRIBUTE_UNUSED
;
501 /* FIXME: Why do we need this check? We need it for ECOFF, but why
502 do we need it for COFF? */
503 if (now_seg
!= text_section
)
505 as_warn (_(".loc outside of .text"));
506 demand_empty_rest_of_line ();
510 if (def_symbol_in_progress
!= NULL
)
512 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
513 demand_empty_rest_of_line ();
517 /* Skip the file number. */
519 get_absolute_expression ();
522 lineno
= get_absolute_expression ();
530 lineno
+= coff_line_base
- 1;
531 listing_source_line (lineno
);
536 demand_empty_rest_of_line ();
538 add_lineno (frag_now
, frag_now_fix (), lineno
);
541 /* Handle the .ident pseudo-op. */
544 obj_coff_ident (ignore
)
545 int ignore ATTRIBUTE_UNUSED
;
547 segT current_seg
= now_seg
;
548 subsegT current_subseg
= now_subseg
;
554 /* We could put it in .comment, but that creates an extra section
555 that shouldn't be loaded into memory, which requires linker
556 changes... For now, until proven otherwise, use .rdata. */
557 sec
= subseg_new (".rdata$zzz", 0);
558 bfd_set_section_flags (stdoutput
, sec
,
559 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
560 & bfd_applicable_section_flags (stdoutput
)));
563 subseg_new (".comment", 0);
567 subseg_set (current_seg
, current_subseg
);
573 * Handle .def directives.
575 * One might ask : why can't we symbol_new if the symbol does not
576 * already exist and fill it with debug information. Because of
577 * the C_EFCN special symbol. It would clobber the value of the
578 * function symbol before we have a chance to notice that it is
579 * a C_EFCN. And a second reason is that the code is more clear this
580 * way. (at least I think it is :-).
584 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
585 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
586 *input_line_pointer == '\t') \
587 input_line_pointer++;
591 int what ATTRIBUTE_UNUSED
;
593 char name_end
; /* Char after the end of name */
594 char *symbol_name
; /* Name of the debug symbol */
595 char *symbol_name_copy
; /* Temporary copy of the name */
596 unsigned int symbol_name_length
;
598 if (def_symbol_in_progress
!= NULL
)
600 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
601 demand_empty_rest_of_line ();
603 } /* if not inside .def/.endef */
607 symbol_name
= input_line_pointer
;
608 #ifdef STRIP_UNDERSCORE
609 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
611 #endif /* STRIP_UNDERSCORE */
613 name_end
= get_symbol_end ();
614 symbol_name_length
= strlen (symbol_name
);
615 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
616 strcpy (symbol_name_copy
, symbol_name
);
617 #ifdef tc_canonicalize_symbol_name
618 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
621 /* Initialize the new symbol */
622 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
623 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
624 S_SET_VALUE (def_symbol_in_progress
, 0);
626 if (S_IS_STRING (def_symbol_in_progress
))
627 SF_SET_STRING (def_symbol_in_progress
);
629 *input_line_pointer
= name_end
;
631 demand_empty_rest_of_line ();
634 unsigned int dim_index
;
637 obj_coff_endef (ignore
)
638 int ignore ATTRIBUTE_UNUSED
;
640 symbolS
*symbolP
= NULL
;
642 /* DIM BUG FIX sac@cygnus.com */
644 if (def_symbol_in_progress
== NULL
)
646 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
647 demand_empty_rest_of_line ();
649 } /* if not inside .def/.endef */
651 /* Set the section number according to storage class. */
652 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
657 SF_SET_TAG (def_symbol_in_progress
);
658 /* intentional fallthrough */
661 SF_SET_DEBUG (def_symbol_in_progress
);
662 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
666 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
667 /* intentional fallthrough */
669 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
670 /* intentional fallthrough */
674 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
676 name
= S_GET_NAME (def_symbol_in_progress
);
677 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
683 if (! in_function ())
684 as_warn (_("`%s' symbol without preceding function"), name
);
685 /* Will need relocating. */
686 SF_SET_PROCESS (def_symbol_in_progress
);
692 /* The MS compilers output the actual endline, not the
693 function-relative one... we want to match without
694 changing the assembler input. */
695 SA_SET_SYM_LNNO (def_symbol_in_progress
,
696 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
707 #endif /* C_AUTOARG */
714 /* According to the COFF documentation:
716 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
718 A special section number (-2) marks symbolic debugging symbols,
719 including structure/union/enumeration tag names, typedefs, and
720 the name of the file. A section number of -1 indicates that the
721 symbol has a value but is not relocatable. Examples of
722 absolute-valued symbols include automatic and register variables,
723 function arguments, and .eos symbols.
725 But from Ian Lance Taylor:
727 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
729 the actual tools all marked them as section -1. So the GNU COFF
730 assembler follows historical COFF assemblers.
732 However, it causes problems for djgpp
734 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
736 By defining STRICTCOFF, a COFF port can make the assembler to
737 follow the documented behavior. */
744 SF_SET_DEBUG (def_symbol_in_progress
);
745 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
753 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
764 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
771 as_warn (_("unexpected storage class %d"),
772 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
774 } /* switch on storage class */
776 /* Now that we have built a debug symbol, try to find if we should
777 merge with an existing symbol or not. If a symbol is C_EFCN or
778 absolute_section or untagged SEG_DEBUG it never merges. We also
779 don't merge labels, which are in a different namespace, nor
780 symbols which have not yet been defined since they are typically
781 unique, nor do we merge tags with non-tags. */
783 /* Two cases for functions. Either debug followed by definition or
784 definition followed by debug. For definition first, we will
785 merge the debug symbol into the definition. For debug first, the
786 lineno entry MUST point to the definition function or else it
787 will point off into space when obj_crawl_symbol_chain() merges
788 the debug symbol into the real symbol. Therefor, let's presume
789 the debug symbol is a real function reference. */
791 /* FIXME-SOON If for some reason the definition label/symbol is
792 never seen, this will probably leave an undefined symbol at link
795 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
796 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
797 || (!strcmp (bfd_get_section_name (stdoutput
,
798 S_GET_SEGMENT (def_symbol_in_progress
)),
800 && !SF_GET_TAG (def_symbol_in_progress
))
801 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
802 || ! symbol_constant_p (def_symbol_in_progress
)
803 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
804 DO_NOT_STRIP
)) == NULL
805 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
807 /* If it already is at the end of the symbol list, do nothing */
808 if (def_symbol_in_progress
!= symbol_lastP
)
810 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
811 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
817 /* This symbol already exists, merge the newly created symbol
818 into the old one. This is not mandatory. The linker can
819 handle duplicate symbols correctly. But I guess that it save
820 a *lot* of space if the assembly file defines a lot of
823 /* The debug entry (def_symbol_in_progress) is merged into the
824 previous definition. */
826 c_symbol_merge (def_symbol_in_progress
, symbolP
);
827 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
829 def_symbol_in_progress
= symbolP
;
831 if (SF_GET_FUNCTION (def_symbol_in_progress
)
832 || SF_GET_TAG (def_symbol_in_progress
)
833 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
835 /* For functions, and tags, and static symbols, the symbol
836 *must* be where the debug symbol appears. Move the
837 existing symbol to the current place. */
838 /* If it already is at the end of the symbol list, do nothing */
839 if (def_symbol_in_progress
!= symbol_lastP
)
841 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
842 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
847 if (SF_GET_TAG (def_symbol_in_progress
))
851 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
853 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
854 tag_insert (S_GET_NAME (def_symbol_in_progress
),
855 def_symbol_in_progress
);
858 if (SF_GET_FUNCTION (def_symbol_in_progress
))
860 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
861 set_function (def_symbol_in_progress
);
862 SF_SET_PROCESS (def_symbol_in_progress
);
866 /* That is, if this is the first time we've seen the
868 symbol_table_insert (def_symbol_in_progress
);
869 } /* definition follows debug */
870 } /* Create the line number entry pointing to the function being defined */
872 def_symbol_in_progress
= NULL
;
873 demand_empty_rest_of_line ();
877 obj_coff_dim (ignore
)
878 int ignore ATTRIBUTE_UNUSED
;
882 if (def_symbol_in_progress
== NULL
)
884 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
885 demand_empty_rest_of_line ();
887 } /* if not inside .def/.endef */
889 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
891 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
894 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
895 get_absolute_expression ());
897 switch (*input_line_pointer
)
900 input_line_pointer
++;
904 as_warn (_("badly formed .dim directive ignored"));
905 /* intentional fallthrough */
913 demand_empty_rest_of_line ();
917 obj_coff_line (ignore
)
918 int ignore ATTRIBUTE_UNUSED
;
922 if (def_symbol_in_progress
== NULL
)
924 /* Probably stabs-style line? */
929 this_base
= get_absolute_expression ();
930 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
931 coff_line_base
= this_base
;
933 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
934 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
936 demand_empty_rest_of_line ();
939 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
944 listing_source_line ((unsigned int) this_base
);
950 obj_coff_size (ignore
)
951 int ignore ATTRIBUTE_UNUSED
;
953 if (def_symbol_in_progress
== NULL
)
955 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
956 demand_empty_rest_of_line ();
958 } /* if not inside .def/.endef */
960 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
961 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
962 demand_empty_rest_of_line ();
966 obj_coff_scl (ignore
)
967 int ignore ATTRIBUTE_UNUSED
;
969 if (def_symbol_in_progress
== NULL
)
971 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
972 demand_empty_rest_of_line ();
974 } /* if not inside .def/.endef */
976 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
977 demand_empty_rest_of_line ();
981 obj_coff_tag (ignore
)
982 int ignore ATTRIBUTE_UNUSED
;
987 if (def_symbol_in_progress
== NULL
)
989 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
990 demand_empty_rest_of_line ();
994 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
995 symbol_name
= input_line_pointer
;
996 name_end
= get_symbol_end ();
998 #ifdef tc_canonicalize_symbol_name
999 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1002 /* Assume that the symbol referred to by .tag is always defined.
1003 This was a bad assumption. I've added find_or_make. xoxorich. */
1004 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1005 tag_find_or_make (symbol_name
));
1006 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1008 as_warn (_("tag not found for .tag %s"), symbol_name
);
1011 SF_SET_TAGGED (def_symbol_in_progress
);
1012 *input_line_pointer
= name_end
;
1014 demand_empty_rest_of_line ();
1018 obj_coff_type (ignore
)
1019 int ignore ATTRIBUTE_UNUSED
;
1021 if (def_symbol_in_progress
== NULL
)
1023 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1024 demand_empty_rest_of_line ();
1026 } /* if not inside .def/.endef */
1028 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1030 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1031 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1033 SF_SET_FUNCTION (def_symbol_in_progress
);
1034 } /* is a function */
1036 demand_empty_rest_of_line ();
1040 obj_coff_val (ignore
)
1041 int ignore ATTRIBUTE_UNUSED
;
1043 if (def_symbol_in_progress
== NULL
)
1045 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1046 demand_empty_rest_of_line ();
1048 } /* if not inside .def/.endef */
1050 if (is_name_beginner (*input_line_pointer
))
1052 char *symbol_name
= input_line_pointer
;
1053 char name_end
= get_symbol_end ();
1055 #ifdef tc_canonicalize_symbol_name
1056 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1058 if (!strcmp (symbol_name
, "."))
1060 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1061 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1062 /* If the .val is != from the .def (e.g. statics) */
1064 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1068 exp
.X_op
= O_symbol
;
1069 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1070 exp
.X_op_symbol
= NULL
;
1071 exp
.X_add_number
= 0;
1072 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1074 /* If the segment is undefined when the forward reference is
1075 resolved, then copy the segment id from the forward
1077 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1079 /* FIXME: gcc can generate address expressions here in
1080 unusual cases (search for "obscure" in sdbout.c). We
1081 just ignore the offset here, thus generating incorrect
1082 debugging information. We ignore the rest of the line
1085 /* Otherwise, it is the name of a non debug symbol and its value
1086 will be calculated later. */
1087 *input_line_pointer
= name_end
;
1091 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1092 } /* if symbol based */
1094 demand_empty_rest_of_line ();
1097 /* Handle .weak. This is a GNU extension in formats other than PE. */
1099 obj_coff_weak (ignore
)
1100 int ignore ATTRIBUTE_UNUSED
;
1108 name
= input_line_pointer
;
1109 c
= get_symbol_end ();
1112 as_warn (_("badly formed .weak directive ignored"));
1113 ignore_rest_of_line ();
1116 symbolP
= symbol_find_or_make (name
);
1117 *input_line_pointer
= c
;
1120 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
1121 S_SET_WEAK (symbolP
);
1125 /* See _Microsoft Portable Executable and Common Object
1126 * File Format Specification_, section 5.5.3.
1127 * Note that weak symbols without aux records are a GNU
1130 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
1134 symbolS
*alternateP
;
1135 long characteristics
= 2;
1136 ++input_line_pointer
;
1137 if (*input_line_pointer
== '=')
1139 characteristics
= 1;
1140 ++input_line_pointer
;
1144 name
= input_line_pointer
;
1145 c
= get_symbol_end();
1148 as_warn (_("alternate name missing in .weak directive"));
1149 ignore_rest_of_line ();
1152 alternateP
= symbol_find_or_make (name
);
1153 *input_line_pointer
= c
;
1155 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
1156 SA_SET_SYM_TAGNDX (symbolP
, alternateP
);
1157 SA_SET_SYM_FSIZE (symbolP
, characteristics
);
1160 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
1165 input_line_pointer
++;
1167 if (*input_line_pointer
== '\n')
1174 demand_empty_rest_of_line ();
1178 coff_obj_read_begin_hook ()
1180 /* These had better be the same. Usually 18 bytes. */
1182 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1183 know (SYMESZ
== AUXESZ
);
1188 symbolS
*coff_last_function
;
1190 static symbolS
*coff_last_bf
;
1194 coff_frob_symbol (symp
, punt
)
1198 static symbolS
*last_tagP
;
1199 static stack
*block_stack
;
1200 static symbolS
*set_end
;
1201 symbolS
*next_set_end
= NULL
;
1203 if (symp
== &abs_symbol
)
1209 if (current_lineno_sym
)
1210 coff_add_linesym ((symbolS
*) 0);
1213 block_stack
= stack_init (512, sizeof (symbolS
*));
1215 if (S_IS_WEAK (symp
))
1218 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1220 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1224 if (!S_IS_DEFINED (symp
)
1225 && !S_IS_WEAK (symp
)
1226 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1227 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1229 if (!SF_GET_DEBUG (symp
))
1233 if (!SF_GET_LOCAL (symp
)
1234 && !SF_GET_STATICS (symp
)
1235 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1236 && symbol_constant_p(symp
)
1237 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1238 && S_GET_STORAGE_CLASS (real
) == C_NULL
1241 c_symbol_merge (symp
, real
);
1246 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1248 assert (S_GET_VALUE (symp
) == 0);
1249 S_SET_EXTERNAL (symp
);
1251 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1253 if (S_GET_SEGMENT (symp
) == text_section
1254 && symp
!= seg_info (text_section
)->sym
)
1255 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1257 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1260 if (SF_GET_PROCESS (symp
))
1262 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1264 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1265 stack_push (block_stack
, (char *) &symp
);
1270 begin
= *(symbolS
**) stack_pop (block_stack
);
1272 as_warn (_("mismatched .eb"));
1274 next_set_end
= begin
;
1278 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1280 union internal_auxent
*auxp
;
1282 coff_last_function
= symp
;
1283 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1284 S_SET_NUMBER_AUXILIARY (symp
, 1);
1285 auxp
= SYM_AUXENT (symp
);
1286 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1287 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1290 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1292 if (coff_last_function
== 0)
1293 as_fatal (_("C_EFCN symbol out of scope"));
1294 SA_SET_SYM_FSIZE (coff_last_function
,
1295 (long) (S_GET_VALUE (symp
)
1296 - S_GET_VALUE (coff_last_function
)));
1297 next_set_end
= coff_last_function
;
1298 coff_last_function
= 0;
1302 if (S_IS_EXTERNAL (symp
))
1303 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1304 else if (SF_GET_LOCAL (symp
))
1307 if (SF_GET_FUNCTION (symp
))
1308 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1313 /* Double check weak symbols. */
1314 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1315 as_bad (_("Symbol `%s' can not be both weak and common"),
1318 if (SF_GET_TAG (symp
))
1320 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1321 next_set_end
= last_tagP
;
1324 /* This is pretty horrible, but we have to set *punt correctly in
1325 order to call SA_SET_SYM_ENDNDX correctly. */
1326 if (! symbol_used_in_reloc_p (symp
)
1327 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1328 || (! S_IS_EXTERNAL (symp
)
1329 && ! symbol_get_tc (symp
)->output
1330 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1334 if (set_end
!= (symbolS
*) NULL
1336 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1337 || (S_IS_DEFINED (symp
)
1338 && ! S_IS_COMMON (symp
)
1339 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1341 SA_SET_SYM_ENDNDX (set_end
, symp
);
1345 if (next_set_end
!= NULL
)
1347 if (set_end
!= NULL
)
1348 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1349 S_GET_NAME (set_end
));
1350 set_end
= next_set_end
;
1355 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1356 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1358 if (coff_last_bf
!= NULL
)
1359 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1360 coff_last_bf
= symp
;
1363 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1366 struct line_no
*lptr
;
1369 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1370 for (i
= 0; lptr
; lptr
= lptr
->next
)
1372 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1374 /* We need i entries for line numbers, plus 1 for the first
1375 entry which BFD will override, plus 1 for the last zero
1376 entry (a marker for BFD). */
1377 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1378 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1379 l
[i
+ 1].line_number
= 0;
1380 l
[i
+ 1].u
.sym
= NULL
;
1384 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1392 coff_adjust_section_syms (abfd
, sec
, x
)
1393 bfd
*abfd ATTRIBUTE_UNUSED
;
1395 PTR x ATTRIBUTE_UNUSED
;
1398 segment_info_type
*seginfo
= seg_info (sec
);
1399 int nlnno
, nrelocs
= 0;
1401 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1402 tc-ppc.c. Do not get confused by it. */
1403 if (seginfo
== NULL
)
1406 if (!strcmp (sec
->name
, ".text"))
1407 nlnno
= coff_n_line_nos
;
1411 /* @@ Hope that none of the fixups expand to more than one reloc
1413 fixS
*fixp
= seginfo
->fix_root
;
1416 if (! fixp
->fx_done
)
1418 fixp
= fixp
->fx_next
;
1421 if (bfd_get_section_size (sec
) == 0
1424 && sec
!= text_section
1425 && sec
!= data_section
1426 && sec
!= bss_section
)
1428 secsym
= section_symbol (sec
);
1429 /* This is an estimate; we'll plug in the real value using
1430 SET_SECTION_RELOCS later */
1431 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1432 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1436 coff_frob_file_after_relocs ()
1438 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1441 /* Implement the .section pseudo op:
1442 .section name {, "flags"}
1444 | +--- optional flags: 'b' for bss
1446 +-- section name 'l' for lib
1450 'd' (apparently m88k for data)
1452 'r' for read-only data
1453 's' for shared data (PE)
1454 But if the argument is not a quoted string, treat it as a
1457 Note the 'a' flag is silently ignored. This allows the same
1458 .section directive to be parsed in both ELF and COFF formats. */
1461 obj_coff_section (ignore
)
1462 int ignore ATTRIBUTE_UNUSED
;
1464 /* Strip out the section name */
1469 flagword flags
, oldflags
;
1480 section_name
= input_line_pointer
;
1481 c
= get_symbol_end ();
1483 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1484 strcpy (name
, section_name
);
1486 *input_line_pointer
= c
;
1491 flags
= SEC_NO_FLAGS
;
1493 if (*input_line_pointer
== ',')
1495 ++input_line_pointer
;
1497 if (*input_line_pointer
!= '"')
1498 exp
= get_absolute_expression ();
1501 ++input_line_pointer
;
1502 while (*input_line_pointer
!= '"'
1503 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1505 switch (*input_line_pointer
)
1507 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1508 case 'n': flags
&=~ SEC_LOAD
; flags
|= SEC_NEVER_LOAD
; break;
1510 case 's': flags
|= SEC_SHARED
; /* fall through */
1511 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1512 case 'w': flags
&=~ SEC_READONLY
; break;
1514 case 'a': break; /* For compatibility with ELF. */
1515 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1516 case 'r': flags
|= SEC_DATA
| SEC_LOAD
| SEC_READONLY
; break;
1518 case 'i': /* STYP_INFO */
1519 case 'l': /* STYP_LIB */
1520 case 'o': /* STYP_OVER */
1521 as_warn (_("unsupported section attribute '%c'"),
1522 *input_line_pointer
);
1526 as_warn(_("unknown section attribute '%c'"),
1527 *input_line_pointer
);
1530 ++input_line_pointer
;
1532 if (*input_line_pointer
== '"')
1533 ++input_line_pointer
;
1537 sec
= subseg_new (name
, (subsegT
) exp
);
1539 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1540 if (oldflags
== SEC_NO_FLAGS
)
1542 /* Set section flags for a new section just created by subseg_new.
1543 Provide a default if no flags were parsed. */
1544 if (flags
== SEC_NO_FLAGS
)
1545 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1547 #ifdef COFF_LONG_SECTION_NAMES
1548 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1549 sections so adjust_reloc_syms in write.c will correctly handle
1550 relocs which refer to non-local symbols in these sections. */
1551 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1552 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1555 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1556 as_warn (_("error setting flags for \"%s\": %s"),
1557 bfd_section_name (stdoutput
, sec
),
1558 bfd_errmsg (bfd_get_error ()));
1560 else if (flags
!= SEC_NO_FLAGS
)
1562 /* This section's attributes have already been set. Warn if the
1563 attributes don't match. */
1564 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1565 | SEC_DATA
| SEC_SHARED
| SEC_NEVER_LOAD
);
1566 if ((flags
^ oldflags
) & matchflags
)
1567 as_warn (_("Ignoring changed section attributes for %s"), name
);
1570 demand_empty_rest_of_line ();
1574 coff_adjust_symtab ()
1576 if (symbol_rootP
== NULL
1577 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1578 c_dot_file_symbol ("fake");
1582 coff_frob_section (sec
)
1588 bfd_vma size
, n_entries
, mask
;
1589 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1591 /* The COFF back end in BFD requires that all section sizes be
1592 rounded up to multiples of the corresponding section alignments,
1593 supposedly because standard COFF has no other way of encoding alignment
1594 for sections. If your COFF flavor has a different way of encoding
1595 section alignment, then skip this step, as TICOFF does. */
1596 size
= bfd_get_section_size (sec
);
1597 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1598 #if !defined(TICOFF)
1604 new_size
= (size
+ mask
) & ~mask
;
1605 bfd_set_section_size (stdoutput
, sec
, new_size
);
1607 /* If the size had to be rounded up, add some padding in
1608 the last non-empty frag. */
1609 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1610 last
= seg_info (sec
)->frchainP
->frch_last
;
1611 while (fragp
->fr_next
!= last
)
1612 fragp
= fragp
->fr_next
;
1613 last
->fr_address
= size
;
1614 fragp
->fr_offset
+= new_size
- size
;
1618 /* If the section size is non-zero, the section symbol needs an aux
1619 entry associated with it, indicating the size. We don't know
1620 all the values yet; coff_frob_symbol will fill them in later. */
1623 || sec
== text_section
1624 || sec
== data_section
1625 || sec
== bss_section
)
1628 symbolS
*secsym
= section_symbol (sec
);
1630 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1631 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1632 SF_SET_STATICS (secsym
);
1633 SA_SET_SCN_SCNLEN (secsym
, size
);
1636 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1637 #ifndef STAB_SECTION_NAME
1638 #define STAB_SECTION_NAME ".stab"
1640 #ifndef STAB_STRING_SECTION_NAME
1641 #define STAB_STRING_SECTION_NAME ".stabstr"
1643 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1647 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1648 /* size is already rounded up, since other section will be listed first */
1649 size
= bfd_get_section_size (strsec
);
1651 n_entries
= bfd_get_section_size (sec
) / 12 - 1;
1653 /* Find first non-empty frag. It should be large enough. */
1654 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1655 while (fragp
&& fragp
->fr_fix
== 0)
1656 fragp
= fragp
->fr_next
;
1657 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1659 /* Store the values. */
1660 p
= fragp
->fr_literal
;
1661 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1662 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1666 obj_coff_init_stab_section (seg
)
1672 unsigned int stroff
;
1674 /* Make space for this first symbol. */
1678 as_where (&file
, (unsigned int *) NULL
);
1679 stabstr_name
= (char *) xmalloc (strlen (seg
->name
) + 4);
1680 strcpy (stabstr_name
, seg
->name
);
1681 strcat (stabstr_name
, "str");
1682 stroff
= get_stab_string_offset (file
, stabstr_name
);
1684 md_number_to_chars (p
, stroff
, 4);
1693 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1701 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1703 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1704 (unsigned long) symbolP
,
1705 S_GET_NAME(symbolP
),
1706 (long) S_GET_DATA_TYPE(symbolP
),
1707 S_GET_STORAGE_CLASS(symbolP
),
1708 (int) S_GET_SEGMENT(symbolP
));
1714 #else /* not BFD_ASSEMBLER */
1717 /* This is needed because we include internal bfd things. */
1721 #include "libcoff.h"
1724 #include "coff/pe.h"
1727 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1728 that we can stick sections together without causing trouble. */
1730 #define NOP_OPCODE 0x00
1733 /* The zeroes if symbol name is longer than 8 chars */
1734 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1736 #define MIN(a,b) ((a) < (b)? (a) : (b))
1738 /* This vector is used to turn a gas internal segment number into a
1739 section number suitable for insertion into a coff symbol table.
1740 This must correspond to seg_info_off_by_4. */
1742 const short seg_N_TYPE
[] =
1743 { /* in: segT out: N_TYPE bits */
1745 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1746 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1747 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1748 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1749 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1750 C_UNDEF_SECTION
, /* SEG_GOOF */
1751 C_UNDEF_SECTION
, /* SEG_EXPR */
1752 C_DEBUG_SECTION
, /* SEG_DEBUG */
1753 C_NTV_SECTION
, /* SEG_NTV */
1754 C_PTV_SECTION
, /* SEG_PTV */
1755 C_REGISTER_SECTION
, /* SEG_REGISTER */
1758 int function_lineoff
= -1; /* Offset in line#s where the last function
1759 started (the odd entry for line #0) */
1761 /* Structure used to keep the filenames which
1762 are too long around so that we can stick them
1763 into the string table. */
1764 struct filename_list
1767 struct filename_list
*next
;
1770 static struct filename_list
*filename_list_head
;
1771 static struct filename_list
*filename_list_tail
;
1773 static symbolS
*last_line_symbol
;
1775 /* Add 4 to the real value to get the index and compensate the
1776 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1777 section number into a segment number. */
1780 static symbolS
*previous_file_symbol
;
1781 static int line_base
;
1783 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
1784 symbolS
*c_section_symbol
PARAMS ((char *, int));
1785 void obj_coff_section
PARAMS ((int));
1786 void do_relocs_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1787 char * symbol_to_chars
PARAMS ((bfd
*, char *, symbolS
*));
1788 void w_strings
PARAMS ((char *));
1790 static void fixup_segment
PARAMS ((segment_info_type
*, segT
));
1791 static void fixup_mdeps
PARAMS ((fragS
*, object_headers
*, segT
));
1792 static void fill_section
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1793 static int c_line_new
PARAMS ((symbolS
*, long, int, fragS
*));
1794 static void w_symbols
PARAMS ((bfd
*, char *, symbolS
*));
1795 static void adjust_stab_section
PARAMS ((bfd
*, segT
));
1796 static void obj_coff_lcomm
PARAMS ((int));
1797 static void obj_coff_text
PARAMS ((int));
1798 static void obj_coff_data
PARAMS ((int));
1799 static unsigned int count_entries_in_chain
PARAMS ((unsigned int));
1800 static void coff_header_append
PARAMS ((bfd
*, object_headers
*));
1801 static unsigned int yank_symbols
PARAMS ((void));
1802 static unsigned int glue_symbols
PARAMS ((symbolS
**, symbolS
**));
1803 static unsigned int tie_tags
PARAMS ((void));
1804 static void crawl_symbols
PARAMS ((object_headers
*, bfd
*));
1805 static void do_linenos_for
PARAMS ((bfd
*, object_headers
*, unsigned long *));
1806 static void remove_subsegs
PARAMS ((void));
1810 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1812 This array maps a COFF section number into a gas section number.
1813 Because COFF uses negative section numbers, you must add 4 to the
1814 COFF section number when indexing into this array; this is done via
1815 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1818 static const segT seg_info_off_by_4
[] =
1825 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1826 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1827 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1828 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1829 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1830 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1831 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1832 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1845 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1847 static relax_addressT relax_align
PARAMS ((relax_addressT
, long));
1849 static relax_addressT
1850 relax_align (address
, alignment
)
1851 relax_addressT address
;
1854 relax_addressT mask
;
1855 relax_addressT new_address
;
1857 mask
= ~((~0) << alignment
);
1858 new_address
= (address
+ mask
) & (~mask
);
1859 return (new_address
- address
);
1866 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1869 static unsigned int size_section
PARAMS ((bfd
*, unsigned int));
1871 /* Calculate the size of the frag chain and fill in the section header
1872 to contain all of it, also fill in the addr of the sections. */
1875 size_section (abfd
, idx
)
1876 bfd
*abfd ATTRIBUTE_UNUSED
;
1880 unsigned int size
= 0;
1881 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1885 size
= frag
->fr_address
;
1886 if (frag
->fr_address
!= size
)
1888 fprintf (stderr
, _("Out of step\n"));
1889 size
= frag
->fr_address
;
1892 switch (frag
->fr_type
)
1894 #ifdef TC_COFF_SIZEMACHDEP
1895 case rs_machine_dependent
:
1896 size
+= TC_COFF_SIZEMACHDEP (frag
);
1902 size
+= frag
->fr_fix
;
1903 size
+= frag
->fr_offset
* frag
->fr_var
;
1911 size
+= frag
->fr_fix
;
1912 off
= relax_align (size
, frag
->fr_offset
);
1913 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1919 BAD_CASE (frag
->fr_type
);
1922 frag
= frag
->fr_next
;
1924 segment_info
[idx
].scnhdr
.s_size
= size
;
1929 count_entries_in_chain (idx
)
1932 unsigned int nrelocs
;
1935 /* Count the relocations. */
1936 fixup_ptr
= segment_info
[idx
].fix_root
;
1938 while (fixup_ptr
!= (fixS
*) NULL
)
1940 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1942 #if defined(TC_A29K) || defined(TC_OR32)
1943 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1952 fixup_ptr
= fixup_ptr
->fx_next
;
1959 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1961 /* AUX's ld expects relocations to be sorted. */
1964 compare_external_relocs (x
, y
)
1968 struct external_reloc
*a
= (struct external_reloc
*) x
;
1969 struct external_reloc
*b
= (struct external_reloc
*) y
;
1970 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1971 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1972 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1977 /* Output all the relocations for a section. */
1980 do_relocs_for (abfd
, h
, file_cursor
)
1983 unsigned long *file_cursor
;
1985 unsigned int nrelocs
;
1987 unsigned long reloc_start
= *file_cursor
;
1989 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1991 if (segment_info
[idx
].scnhdr
.s_name
[0])
1993 struct external_reloc
*ext_ptr
;
1994 struct external_reloc
*external_reloc_vec
;
1995 unsigned int external_reloc_size
;
1996 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1997 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1998 nrelocs
= count_entries_in_chain (idx
);
2001 /* Bypass this stuff if no relocs. This also incidentally
2002 avoids a SCO bug, where free(malloc(0)) tends to crash. */
2004 external_reloc_size
= nrelocs
* RELSZ
;
2005 external_reloc_vec
=
2006 (struct external_reloc
*) malloc (external_reloc_size
);
2008 ext_ptr
= external_reloc_vec
;
2010 /* Fill in the internal coff style reloc struct from the
2011 internal fix list. */
2014 struct internal_reloc intr
;
2016 /* Only output some of the relocations. */
2017 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
2019 #ifdef TC_RELOC_MANGLE
2020 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
2024 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
2026 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
2028 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
2030 #ifdef TC_KEEP_FX_OFFSET
2031 intr
.r_offset
= fix_ptr
->fx_offset
;
2036 while (symbol_ptr
->sy_value
.X_op
== O_symbol
2037 && (! S_IS_DEFINED (symbol_ptr
)
2038 || S_IS_COMMON (symbol_ptr
)))
2042 /* We must avoid looping, as that can occur
2043 with a badly written program. */
2044 n
= symbol_ptr
->sy_value
.X_add_symbol
;
2045 if (n
== symbol_ptr
)
2050 /* Turn the segment of the symbol into an offset. */
2053 resolve_symbol_value (symbol_ptr
);
2054 if (! symbol_ptr
->sy_resolved
)
2059 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
2060 as_bad_where (file
, line
,
2061 _("unresolved relocation"));
2063 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2064 S_GET_NAME (symbol_ptr
));
2067 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
2069 intr
.r_symndx
= dot
->sy_number
;
2071 intr
.r_symndx
= symbol_ptr
->sy_number
;
2076 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2078 #if defined(TC_A29K)
2079 /* The 29k has a special kludge for the high 16 bit
2080 reloc. Two relocations are emitted, R_IHIHALF,
2081 and R_IHCONST. The second one doesn't contain a
2082 symbol, but uses the value for offset. */
2083 if (intr
.r_type
== R_IHIHALF
)
2085 /* Now emit the second bit. */
2086 intr
.r_type
= R_IHCONST
;
2087 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2088 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2092 #if defined(TC_OR32)
2093 /* The or32 has a special kludge for the high 16 bit
2094 reloc. Two relocations are emitted, R_IHIHALF,
2095 and R_IHCONST. The second one doesn't contain a
2096 symbol, but uses the value for offset. */
2097 if (intr
.r_type
== R_IHIHALF
)
2099 /* Now emit the second bit. */
2100 intr
.r_type
= R_IHCONST
;
2101 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2102 (void) bfd_coff_swap_reloc_out (abfd
, & intr
, ext_ptr
);
2108 fix_ptr
= fix_ptr
->fx_next
;
2111 /* Sort the reloc table. */
2112 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2113 sizeof (struct external_reloc
), compare_external_relocs
);
2115 /* Write out the reloc table. */
2116 bfd_bwrite ((PTR
) external_reloc_vec
,
2117 (bfd_size_type
) external_reloc_size
, abfd
);
2118 free (external_reloc_vec
);
2120 /* Fill in section header info. */
2121 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2122 *file_cursor
+= external_reloc_size
;
2123 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2128 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2133 /* Set relocation_size field in file headers. */
2134 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2137 /* Run through a frag chain and write out the data to go with it, fill
2138 in the scnhdrs with the info on the file positions. */
2141 fill_section (abfd
, h
, file_cursor
)
2143 object_headers
*h ATTRIBUTE_UNUSED
;
2144 unsigned long *file_cursor
;
2147 unsigned int paddr
= 0;
2149 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2151 unsigned int offset
= 0;
2152 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2158 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2159 char *buffer
= NULL
;
2165 buffer
= xmalloc (s
->s_size
);
2166 s
->s_scnptr
= *file_cursor
;
2168 know (s
->s_paddr
== paddr
);
2170 if (strcmp (s
->s_name
, ".text") == 0)
2171 s
->s_flags
|= STYP_TEXT
;
2172 else if (strcmp (s
->s_name
, ".data") == 0)
2173 s
->s_flags
|= STYP_DATA
;
2174 else if (strcmp (s
->s_name
, ".bss") == 0)
2177 s
->s_flags
|= STYP_BSS
;
2179 /* @@ Should make the i386 and a29k coff targets define
2180 COFF_NOLOAD_PROBLEM, and have only one test here. */
2184 #ifndef COFF_NOLOAD_PROBLEM
2185 /* Apparently the SVR3 linker (and exec syscall) and UDI
2186 mondfe progrem are confused by noload sections. */
2187 s
->s_flags
|= STYP_NOLOAD
;
2193 else if (strcmp (s
->s_name
, ".lit") == 0)
2194 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2195 else if (strcmp (s
->s_name
, ".init") == 0)
2196 s
->s_flags
|= STYP_TEXT
;
2197 else if (strcmp (s
->s_name
, ".fini") == 0)
2198 s
->s_flags
|= STYP_TEXT
;
2199 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2200 s
->s_flags
|= STYP_INFO
;
2204 unsigned int fill_size
;
2205 switch (frag
->fr_type
)
2207 case rs_machine_dependent
:
2210 memcpy (buffer
+ frag
->fr_address
,
2212 (unsigned int) frag
->fr_fix
);
2213 offset
+= frag
->fr_fix
;
2225 memcpy (buffer
+ frag
->fr_address
,
2227 (unsigned int) frag
->fr_fix
);
2228 offset
+= frag
->fr_fix
;
2231 fill_size
= frag
->fr_var
;
2232 if (fill_size
&& frag
->fr_offset
> 0)
2235 unsigned int off
= frag
->fr_fix
;
2236 for (count
= frag
->fr_offset
; count
; count
--)
2238 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2240 memcpy (buffer
+ frag
->fr_address
+ off
,
2241 frag
->fr_literal
+ frag
->fr_fix
,
2244 offset
+= fill_size
;
2249 case rs_broken_word
:
2254 frag
= frag
->fr_next
;
2259 if (s
->s_scnptr
!= 0)
2261 bfd_bwrite (buffer
, s
->s_size
, abfd
);
2262 *file_cursor
+= s
->s_size
;
2271 /* Coff file generation & utilities. */
2274 coff_header_append (abfd
, h
)
2281 #ifdef COFF_LONG_SECTION_NAMES
2282 unsigned long string_size
= 4;
2285 bfd_seek (abfd
, (file_ptr
) 0, 0);
2287 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2288 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2289 H_SET_VERSION_STAMP (h
, 0);
2290 H_SET_ENTRY_POINT (h
, 0);
2291 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2292 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2293 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2295 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2296 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2297 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2299 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2301 bfd_bwrite (buffer
, (bfd_size_type
) i
, abfd
);
2302 bfd_bwrite (buffero
, (bfd_size_type
) H_GET_SIZEOF_OPTIONAL_HEADER (h
), abfd
);
2304 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2306 if (segment_info
[i
].scnhdr
.s_name
[0])
2310 #ifdef COFF_LONG_SECTION_NAMES
2311 /* Support long section names as found in PE. This code
2312 must coordinate with that in write_object_file and
2314 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2316 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2317 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2318 string_size
+= strlen (segment_info
[i
].name
) + 1;
2321 size
= bfd_coff_swap_scnhdr_out (abfd
,
2322 &(segment_info
[i
].scnhdr
),
2325 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2326 bfd_bwrite (buffer
, (bfd_size_type
) size
, abfd
);
2332 symbol_to_chars (abfd
, where
, symbolP
)
2337 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2341 /* Turn any symbols with register attributes into abs symbols. */
2342 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2343 S_SET_SEGMENT (symbolP
, absolute_section
);
2345 /* At the same time, relocate all symbols to their output value. */
2347 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2348 + S_GET_VALUE (symbolP
));
2350 val
= S_GET_VALUE (symbolP
);
2353 S_SET_VALUE (symbolP
, val
);
2355 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2357 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2360 for (i
= 0; i
< numaux
; i
++)
2362 where
+= bfd_coff_swap_aux_out (abfd
,
2363 &symbolP
->sy_symbol
.ost_auxent
[i
],
2364 S_GET_DATA_TYPE (symbolP
),
2365 S_GET_STORAGE_CLASS (symbolP
),
2373 coff_obj_symbol_new_hook (symbolP
)
2376 char underscore
= 0; /* Symbol has leading _ */
2378 /* Effective symbol. */
2379 /* Store the pointer in the offset. */
2380 S_SET_ZEROES (symbolP
, 0L);
2381 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2382 S_SET_STORAGE_CLASS (symbolP
, 0);
2383 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2384 /* Additional information. */
2385 symbolP
->sy_symbol
.ost_flags
= 0;
2386 /* Auxiliary entries. */
2387 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2389 if (S_IS_STRING (symbolP
))
2390 SF_SET_STRING (symbolP
);
2391 if (!underscore
&& S_IS_LOCAL (symbolP
))
2392 SF_SET_LOCAL (symbolP
);
2395 /* Handle .ln directives. */
2398 obj_coff_ln (appline
)
2403 if (! appline
&& def_symbol_in_progress
!= NULL
)
2405 /* Wrong context. */
2406 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2407 demand_empty_rest_of_line ();
2411 l
= get_absolute_expression ();
2412 c_line_new (0, frag_now_fix (), l
, frag_now
);
2415 new_logical_line ((char *) NULL
, l
- 1);
2425 listing_source_line ((unsigned int) l
);
2430 demand_empty_rest_of_line ();
2433 /* Handle .def directives.
2435 One might ask : why can't we symbol_new if the symbol does not
2436 already exist and fill it with debug information. Because of
2437 the C_EFCN special symbol. It would clobber the value of the
2438 function symbol before we have a chance to notice that it is
2439 a C_EFCN. And a second reason is that the code is more clear this
2440 way. (at least I think it is :-). */
2442 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2443 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2444 *input_line_pointer == '\t') \
2445 input_line_pointer++;
2449 int what ATTRIBUTE_UNUSED
;
2451 char name_end
; /* Char after the end of name. */
2452 char *symbol_name
; /* Name of the debug symbol. */
2453 char *symbol_name_copy
; /* Temporary copy of the name. */
2454 unsigned int symbol_name_length
;
2456 if (def_symbol_in_progress
!= NULL
)
2458 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2459 demand_empty_rest_of_line ();
2463 SKIP_WHITESPACES ();
2465 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2466 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2468 symbol_name
= input_line_pointer
;
2469 name_end
= get_symbol_end ();
2470 symbol_name_length
= strlen (symbol_name
);
2471 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2472 strcpy (symbol_name_copy
, symbol_name
);
2473 #ifdef tc_canonicalize_symbol_name
2474 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2477 /* Initialize the new symbol. */
2478 #ifdef STRIP_UNDERSCORE
2479 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2480 ? symbol_name_copy
+ 1
2481 : symbol_name_copy
));
2482 #else /* STRIP_UNDERSCORE */
2483 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2484 #endif /* STRIP_UNDERSCORE */
2485 /* free(symbol_name_copy); */
2486 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2487 def_symbol_in_progress
->sy_number
= ~0;
2488 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2489 S_SET_VALUE (def_symbol_in_progress
, 0);
2491 if (S_IS_STRING (def_symbol_in_progress
))
2492 SF_SET_STRING (def_symbol_in_progress
);
2494 *input_line_pointer
= name_end
;
2496 demand_empty_rest_of_line ();
2499 unsigned int dim_index
;
2502 obj_coff_endef (ignore
)
2503 int ignore ATTRIBUTE_UNUSED
;
2505 symbolS
*symbolP
= 0;
2506 /* DIM BUG FIX sac@cygnus.com */
2508 if (def_symbol_in_progress
== NULL
)
2510 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2511 demand_empty_rest_of_line ();
2515 /* Set the section number according to storage class. */
2516 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2521 SF_SET_TAG (def_symbol_in_progress
);
2522 /* Intentional fallthrough. */
2526 SF_SET_DEBUG (def_symbol_in_progress
);
2527 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2531 /* Do not emit this symbol. */
2532 SF_SET_LOCAL (def_symbol_in_progress
);
2533 /* Intentional fallthrough. */
2536 /* Will need processing before writing. */
2537 SF_SET_PROCESS (def_symbol_in_progress
);
2538 /* Intentional fallthrough. */
2541 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2543 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2545 if (function_lineoff
< 0)
2546 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2548 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2550 SF_SET_PROCESS (last_line_symbol
);
2551 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2552 SF_SET_PROCESS (def_symbol_in_progress
);
2553 function_lineoff
= -1;
2556 /* Value is always set to . */
2557 def_symbol_in_progress
->sy_frag
= frag_now
;
2558 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2563 #endif /* C_AUTOARG */
2573 SF_SET_DEBUG (def_symbol_in_progress
);
2574 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2584 /* Valid but set somewhere else (s_comm, s_lcomm, colon). */
2590 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2594 /* Now that we have built a debug symbol, try to find if we should
2595 merge with an existing symbol or not. If a symbol is C_EFCN or
2596 absolute_section or untagged SEG_DEBUG it never merges. We also
2597 don't merge labels, which are in a different namespace, nor
2598 symbols which have not yet been defined since they are typically
2599 unique, nor do we merge tags with non-tags. */
2601 /* Two cases for functions. Either debug followed by definition or
2602 definition followed by debug. For definition first, we will
2603 merge the debug symbol into the definition. For debug first, the
2604 lineno entry MUST point to the definition function or else it
2605 will point off into space when crawl_symbols() merges the debug
2606 symbol into the real symbol. Therefor, let's presume the debug
2607 symbol is a real function reference. */
2609 /* FIXME-SOON If for some reason the definition label/symbol is
2610 never seen, this will probably leave an undefined symbol at link
2613 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2614 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2615 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2616 && !SF_GET_TAG (def_symbol_in_progress
))
2617 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2618 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2619 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2620 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2622 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2627 /* This symbol already exists, merge the newly created symbol
2628 into the old one. This is not mandatory. The linker can
2629 handle duplicate symbols correctly. But I guess that it save
2630 a *lot* of space if the assembly file defines a lot of
2633 /* The debug entry (def_symbol_in_progress) is merged into the
2634 previous definition. */
2636 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2637 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2638 def_symbol_in_progress
= symbolP
;
2640 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2641 || SF_GET_TAG (def_symbol_in_progress
)
2642 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2644 /* For functions, and tags, and static symbols, the symbol
2645 *must* be where the debug symbol appears. Move the
2646 existing symbol to the current place. */
2647 /* If it already is at the end of the symbol list, do nothing. */
2648 if (def_symbol_in_progress
!= symbol_lastP
)
2650 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2652 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2653 &symbol_rootP
, &symbol_lastP
);
2658 if (SF_GET_TAG (def_symbol_in_progress
))
2662 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2664 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2665 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2666 def_symbol_in_progress
);
2669 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2671 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2673 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2675 SF_SET_PROCESS (def_symbol_in_progress
);
2677 if (symbolP
== NULL
)
2679 /* That is, if this is the first time we've seen the
2681 symbol_table_insert (def_symbol_in_progress
);
2685 def_symbol_in_progress
= NULL
;
2686 demand_empty_rest_of_line ();
2690 obj_coff_dim (ignore
)
2691 int ignore ATTRIBUTE_UNUSED
;
2695 if (def_symbol_in_progress
== NULL
)
2697 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2698 demand_empty_rest_of_line ();
2702 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2704 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2706 SKIP_WHITESPACES ();
2707 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2708 get_absolute_expression ());
2710 switch (*input_line_pointer
)
2713 input_line_pointer
++;
2717 as_warn (_("badly formed .dim directive ignored"));
2718 /* Intentional fallthrough. */
2727 demand_empty_rest_of_line ();
2731 obj_coff_line (ignore
)
2732 int ignore ATTRIBUTE_UNUSED
;
2737 if (def_symbol_in_progress
== NULL
)
2743 name
= S_GET_NAME (def_symbol_in_progress
);
2744 this_base
= get_absolute_expression ();
2746 /* Only .bf symbols indicate the use of a new base line number; the
2747 line numbers associated with .ef, .bb, .eb are relative to the
2748 start of the containing function. */
2749 if (!strcmp (".bf", name
))
2751 #if 0 /* XXX Can we ever have line numbers going backwards? */
2752 if (this_base
> line_base
)
2754 line_base
= this_base
;
2760 listing_source_line ((unsigned int) line_base
);
2765 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2766 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2768 demand_empty_rest_of_line ();
2772 obj_coff_size (ignore
)
2773 int ignore ATTRIBUTE_UNUSED
;
2775 if (def_symbol_in_progress
== NULL
)
2777 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2778 demand_empty_rest_of_line ();
2782 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2783 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2784 demand_empty_rest_of_line ();
2788 obj_coff_scl (ignore
)
2789 int ignore ATTRIBUTE_UNUSED
;
2791 if (def_symbol_in_progress
== NULL
)
2793 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2794 demand_empty_rest_of_line ();
2798 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2799 demand_empty_rest_of_line ();
2803 obj_coff_tag (ignore
)
2804 int ignore ATTRIBUTE_UNUSED
;
2809 if (def_symbol_in_progress
== NULL
)
2811 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2812 demand_empty_rest_of_line ();
2816 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2817 symbol_name
= input_line_pointer
;
2818 name_end
= get_symbol_end ();
2819 #ifdef tc_canonicalize_symbol_name
2820 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2823 /* Assume that the symbol referred to by .tag is always defined.
2824 This was a bad assumption. I've added find_or_make. xoxorich. */
2825 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2826 (long) tag_find_or_make (symbol_name
));
2827 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2828 as_warn (_("tag not found for .tag %s"), symbol_name
);
2830 SF_SET_TAGGED (def_symbol_in_progress
);
2831 *input_line_pointer
= name_end
;
2833 demand_empty_rest_of_line ();
2837 obj_coff_type (ignore
)
2838 int ignore ATTRIBUTE_UNUSED
;
2840 if (def_symbol_in_progress
== NULL
)
2842 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2843 demand_empty_rest_of_line ();
2847 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2849 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2850 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2851 SF_SET_FUNCTION (def_symbol_in_progress
);
2853 demand_empty_rest_of_line ();
2857 obj_coff_val (ignore
)
2858 int ignore ATTRIBUTE_UNUSED
;
2860 if (def_symbol_in_progress
== NULL
)
2862 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2863 demand_empty_rest_of_line ();
2867 if (is_name_beginner (*input_line_pointer
))
2869 char *symbol_name
= input_line_pointer
;
2870 char name_end
= get_symbol_end ();
2872 #ifdef tc_canonicalize_symbol_name
2873 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2876 if (!strcmp (symbol_name
, "."))
2878 def_symbol_in_progress
->sy_frag
= frag_now
;
2879 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2880 /* If the .val is != from the .def (e.g. statics). */
2882 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2884 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2885 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2886 symbol_find_or_make (symbol_name
);
2887 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2888 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2890 /* If the segment is undefined when the forward reference is
2891 resolved, then copy the segment id from the forward
2893 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2895 /* FIXME: gcc can generate address expressions here in
2896 unusual cases (search for "obscure" in sdbout.c). We
2897 just ignore the offset here, thus generating incorrect
2898 debugging information. We ignore the rest of the line
2901 /* Otherwise, it is the name of a non debug symbol and
2902 its value will be calculated later. */
2903 *input_line_pointer
= name_end
;
2905 /* FIXME: this is to avoid an error message in the
2906 FIXME case mentioned just above. */
2907 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2908 ++input_line_pointer
;
2912 S_SET_VALUE (def_symbol_in_progress
,
2913 (valueT
) get_absolute_expression ());
2914 } /* if symbol based */
2916 demand_empty_rest_of_line ();
2921 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2922 read.c, which then calls this object file format specific routine. */
2925 obj_coff_pe_handle_link_once (type
)
2926 enum linkonce_type type
;
2928 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2930 /* We store the type in the seg_info structure, and use it to set up
2931 the auxiliary entry for the section symbol in c_section_symbol. */
2932 seg_info (now_seg
)->linkonce
= type
;
2938 coff_obj_read_begin_hook ()
2940 /* These had better be the same. Usually 18 bytes. */
2942 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2943 know (SYMESZ
== AUXESZ
);
2948 /* This function runs through the symbol table and puts all the
2949 externals onto another chain. */
2951 /* The chain of globals. */
2952 symbolS
*symbol_globalP
;
2953 symbolS
*symbol_global_lastP
;
2955 /* The chain of externals. */
2956 symbolS
*symbol_externP
;
2957 symbolS
*symbol_extern_lastP
;
2960 symbolS
*last_functionP
;
2961 static symbolS
*last_bfP
;
2968 unsigned int symbol_number
= 0;
2969 unsigned int last_file_symno
= 0;
2971 struct filename_list
*filename_list_scan
= filename_list_head
;
2973 for (symbolP
= symbol_rootP
;
2975 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2977 if (symbolP
->sy_mri_common
)
2979 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2981 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2983 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2984 as_bad (_("%s: global symbols not supported in common sections"),
2985 S_GET_NAME (symbolP
));
2986 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2990 if (!SF_GET_DEBUG (symbolP
))
2992 /* Debug symbols do not need all this rubbish. */
2993 symbolS
*real_symbolP
;
2995 /* L* and C_EFCN symbols never merge. */
2996 if (!SF_GET_LOCAL (symbolP
)
2997 && !SF_GET_STATICS (symbolP
)
2998 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2999 && symbolP
->sy_value
.X_op
== O_constant
3000 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
3001 && real_symbolP
!= symbolP
)
3003 /* FIXME-SOON: where do dups come from?
3004 Maybe tag references before definitions? xoxorich. */
3005 /* Move the debug data from the debug symbol to the
3006 real symbol. Do NOT do the opposite (i.e. move from
3007 real symbol to debug symbol and remove real symbol from the
3008 list.) Because some pointers refer to the real symbol
3009 whereas no pointers refer to the debug symbol. */
3010 c_symbol_merge (symbolP
, real_symbolP
);
3011 /* Replace the current symbol by the real one. */
3012 /* The symbols will never be the last or the first
3013 because : 1st symbol is .file and 3 last symbols are
3014 .text, .data, .bss. */
3015 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
3016 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
3017 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3018 symbolP
= real_symbolP
;
3021 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
3022 S_SET_SEGMENT (symbolP
, SEG_E0
);
3024 resolve_symbol_value (symbolP
);
3026 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
3028 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
3030 S_SET_EXTERNAL (symbolP
);
3033 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
3034 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
3037 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3040 /* Mainly to speed up if not -g. */
3041 if (SF_GET_PROCESS (symbolP
))
3043 /* Handle the nested blocks auxiliary info. */
3044 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
3046 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
3047 stack_push (block_stack
, (char *) &symbolP
);
3051 symbolS
*begin_symbolP
;
3053 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
3054 if (begin_symbolP
== (symbolS
*) 0)
3055 as_warn (_("mismatched .eb"));
3057 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
3060 /* If we are able to identify the type of a function, and we
3061 are out of a function (last_functionP == 0) then, the
3062 function symbol will be associated with an auxiliary
3064 if (last_functionP
== (symbolS
*) 0 &&
3065 SF_GET_FUNCTION (symbolP
))
3067 last_functionP
= symbolP
;
3069 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3070 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3072 /* Clobber possible stale .dim information. */
3074 /* Iffed out by steve - this fries the lnnoptr info too. */
3075 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3076 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3079 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3081 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3083 if (last_bfP
!= NULL
)
3084 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3088 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3090 /* I don't even know if this is needed for sdb. But
3091 the standard assembler generates it, so... */
3092 if (last_functionP
== (symbolS
*) 0)
3093 as_fatal (_("C_EFCN symbol out of scope"));
3094 SA_SET_SYM_FSIZE (last_functionP
,
3095 (long) (S_GET_VALUE (symbolP
) -
3096 S_GET_VALUE (last_functionP
)));
3097 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3098 last_functionP
= (symbolS
*) 0;
3102 else if (SF_GET_TAG (symbolP
))
3104 /* First descriptor of a structure must point to
3105 the first slot after the structure description. */
3106 last_tagP
= symbolP
;
3109 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3111 /* +2 take in account the current symbol. */
3112 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3114 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3116 /* If the filename was too long to fit in the
3117 auxent, put it in the string table. */
3118 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3119 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3121 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3122 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3123 filename_list_scan
= filename_list_scan
->next
;
3125 if (S_GET_VALUE (symbolP
))
3127 S_SET_VALUE (symbolP
, last_file_symno
);
3128 last_file_symno
= symbol_number
;
3132 #ifdef tc_frob_coff_symbol
3133 tc_frob_coff_symbol (symbolP
);
3136 /* We must put the external symbols apart. The loader
3137 does not bomb if we do not. But the references in
3138 the endndx field for a .bb symbol are not corrected
3139 if an external symbol is removed between .bb and .be.
3140 I.e in the following case :
3141 [20] .bb endndx = 22
3144 ld will move the symbol 21 to the end of the list but
3145 endndx will still be 22 instead of 21. */
3147 if (SF_GET_LOCAL (symbolP
))
3149 /* Remove C_EFCN and LOCAL (L...) symbols. */
3150 /* Next pointer remains valid. */
3151 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3154 else if (symbolP
->sy_value
.X_op
== O_symbol
3155 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3157 /* Skip symbols which were equated to undefined or common
3159 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3161 else if (!S_IS_DEFINED (symbolP
)
3162 && !S_IS_DEBUG (symbolP
)
3163 && !SF_GET_STATICS (symbolP
)
3164 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3166 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3168 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3170 /* If external, Remove from the list. */
3171 symbolS
*hold
= symbol_previous (symbolP
);
3173 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3174 symbol_clear_list_pointers (symbolP
);
3175 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3178 else if (! S_IS_DEBUG (symbolP
)
3179 && ! SF_GET_STATICS (symbolP
)
3180 && ! SF_GET_FUNCTION (symbolP
)
3181 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3183 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3185 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3187 symbolS
*hold
= symbol_previous (symbolP
);
3189 /* The O'Reilly COFF book says that defined global symbols
3190 come at the end of the symbol table, just before
3191 undefined global symbols. */
3192 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3193 symbol_clear_list_pointers (symbolP
);
3194 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3195 &symbol_global_lastP
);
3200 if (SF_GET_STRING (symbolP
))
3202 symbolP
->sy_name_offset
= string_byte_count
;
3203 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3207 symbolP
->sy_name_offset
= 0;
3210 symbolP
->sy_number
= symbol_number
;
3211 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3215 return symbol_number
;
3219 glue_symbols (head
, tail
)
3223 unsigned int symbol_number
= 0;
3225 while (*head
!= NULL
)
3227 symbolS
*tmp
= *head
;
3230 symbol_remove (tmp
, head
, tail
);
3231 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3234 if (SF_GET_STRING (tmp
))
3236 tmp
->sy_name_offset
= string_byte_count
;
3237 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3241 /* Fix "long" names. */
3242 tmp
->sy_name_offset
= 0;
3245 tmp
->sy_number
= symbol_number
;
3246 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3249 return symbol_number
;
3255 unsigned int symbol_number
= 0;
3258 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3260 symbolP
->sy_number
= symbol_number
;
3262 if (SF_GET_TAGGED (symbolP
))
3266 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3269 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3272 return symbol_number
;
3277 crawl_symbols (h
, abfd
)
3279 bfd
*abfd ATTRIBUTE_UNUSED
;
3283 /* Initialize the stack used to keep track of the matching .bb .be. */
3285 block_stack
= stack_init (512, sizeof (symbolS
*));
3287 /* The symbol list should be ordered according to the following sequence
3290 . debug entries for functions
3291 . fake symbols for the sections, including .text .data and .bss
3294 But this is not mandatory. The only important point is to put the
3295 undefined symbols at the end of the list. */
3297 /* Is there a .file symbol ? If not insert one at the beginning. */
3298 if (symbol_rootP
== NULL
3299 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3300 c_dot_file_symbol ("fake");
3302 /* Build up static symbols for the sections, they are filled in later. */
3304 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3305 if (segment_info
[i
].scnhdr
.s_name
[0])
3306 segment_info
[i
].dot
= c_section_symbol ((char *) segment_info
[i
].name
,
3309 /* Take all the externals out and put them into another chain. */
3310 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3311 /* Take the externals and glue them onto the end. */
3312 H_SET_SYMBOL_TABLE_SIZE (h
,
3313 (H_GET_SYMBOL_COUNT (h
)
3314 + glue_symbols (&symbol_globalP
,
3315 &symbol_global_lastP
)
3316 + glue_symbols (&symbol_externP
,
3317 &symbol_extern_lastP
)));
3319 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3320 know (symbol_globalP
== NULL
);
3321 know (symbol_global_lastP
== NULL
);
3322 know (symbol_externP
== NULL
);
3323 know (symbol_extern_lastP
== NULL
);
3326 /* Find strings by crawling along symbol table chain. */
3333 struct filename_list
*filename_list_scan
= filename_list_head
;
3335 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK. */
3336 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3339 #ifdef COFF_LONG_SECTION_NAMES
3340 /* Support long section names as found in PE. This code must
3341 coordinate with that in coff_header_append and write_object_file. */
3345 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3347 if (segment_info
[i
].scnhdr
.s_name
[0]
3348 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3352 size
= strlen (segment_info
[i
].name
) + 1;
3353 memcpy (where
, segment_info
[i
].name
, size
);
3358 #endif /* COFF_LONG_SECTION_NAMES */
3360 for (symbolP
= symbol_rootP
;
3362 symbolP
= symbol_next (symbolP
))
3366 if (SF_GET_STRING (symbolP
))
3368 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3369 memcpy (where
, S_GET_NAME (symbolP
), size
);
3372 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3373 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3374 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3376 size
= strlen (filename_list_scan
->filename
) + 1;
3377 memcpy (where
, filename_list_scan
->filename
, size
);
3378 filename_list_scan
= filename_list_scan
->next
;
3385 do_linenos_for (abfd
, h
, file_cursor
)
3388 unsigned long *file_cursor
;
3391 unsigned long start
= *file_cursor
;
3393 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3395 segment_info_type
*s
= segment_info
+ idx
;
3397 if (s
->scnhdr
.s_nlnno
!= 0)
3399 struct lineno_list
*line_ptr
;
3401 struct external_lineno
*buffer
=
3402 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3404 struct external_lineno
*dst
= buffer
;
3406 /* Run through the table we've built and turn it into its external
3407 form, take this chance to remove duplicates. */
3409 for (line_ptr
= s
->lineno_list_head
;
3410 line_ptr
!= (struct lineno_list
*) NULL
;
3411 line_ptr
= line_ptr
->next
)
3413 if (line_ptr
->line
.l_lnno
== 0)
3415 /* Turn a pointer to a symbol into the symbols' index,
3416 provided that it has been initialised. */
3417 if (line_ptr
->line
.l_addr
.l_symndx
)
3418 line_ptr
->line
.l_addr
.l_symndx
=
3419 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3422 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3424 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3428 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3430 bfd_bwrite (buffer
, (bfd_size_type
) s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3433 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3437 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3440 /* Now we run through the list of frag chains in a segment and
3441 make all the subsegment frags appear at the end of the
3442 list, as if the seg 0 was extra long. */
3449 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3451 frchainS
*head
= segment_info
[i
].frchainP
;
3453 fragS
*prev_frag
= &dummy
;
3455 while (head
&& head
->frch_seg
== i
)
3457 prev_frag
->fr_next
= head
->frch_root
;
3458 prev_frag
= head
->frch_last
;
3459 head
= head
->frch_next
;
3461 prev_frag
->fr_next
= 0;
3465 unsigned long machine
;
3468 #ifndef SUB_SEGMENT_ALIGN
3470 /* The last subsegment gets an alignment corresponding to the alignment
3471 of the section. This allows proper nop-filling at the end of
3472 code-bearing sections. */
3473 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) \
3474 (!(FRCHAIN)->frch_next || (FRCHAIN)->frch_next->frch_seg != (SEG) \
3475 ? get_recorded_alignment (SEG) : 0)
3477 #define SUB_SEGMENT_ALIGN(SEG, FRCHAIN) 1
3482 write_object_file ()
3486 struct frchain
*frchain_ptr
;
3488 object_headers headers
;
3489 unsigned long file_cursor
;
3492 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3496 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3497 exit (EXIT_FAILURE
);
3499 bfd_set_format (abfd
, bfd_object
);
3500 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3502 string_byte_count
= 4;
3504 /* Run through all the sub-segments and align them up. Also
3505 close any open frags. We tack a .fill onto the end of the
3506 frag chain so that any .align's size can be worked by looking
3507 at the next frag. */
3508 for (frchain_ptr
= frchain_root
;
3509 frchain_ptr
!= (struct frchain
*) NULL
;
3510 frchain_ptr
= frchain_ptr
->frch_next
)
3514 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3516 alignment
= SUB_SEGMENT_ALIGN (now_seg
, frchain_ptr
);
3519 md_do_align (alignment
, (char *) NULL
, 0, 0, alignment_done
);
3521 if (subseg_text_p (now_seg
))
3522 frag_align_code (alignment
, 0);
3524 frag_align (alignment
, 0, 0);
3530 frag_wane (frag_now
);
3531 frag_now
->fr_fix
= 0;
3532 know (frag_now
->fr_next
== NULL
);
3537 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3538 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3540 /* Relaxation has completed. Freeze all syms. */
3543 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3545 /* Find out how big the sections are, and set the addresses. */
3547 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3551 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3552 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3554 if (segment_info
[i
].scnhdr
.s_name
[0])
3556 H_SET_NUMBER_OF_SECTIONS (&headers
,
3557 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3559 #ifdef COFF_LONG_SECTION_NAMES
3560 /* Support long section names as found in PE. This code
3561 must coordinate with that in coff_header_append and
3566 len
= strlen (segment_info
[i
].name
);
3568 string_byte_count
+= len
+ 1;
3570 #endif /* COFF_LONG_SECTION_NAMES */
3573 size
= size_section (abfd
, (unsigned int) i
);
3576 /* I think the section alignment is only used on the i960; the
3577 i960 needs it, and it should do no harm on other targets. */
3578 #ifdef ALIGNMENT_IN_S_FLAGS
3579 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3581 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3585 H_SET_TEXT_SIZE (&headers
, size
);
3586 else if (i
== SEG_E1
)
3587 H_SET_DATA_SIZE (&headers
, size
);
3588 else if (i
== SEG_E2
)
3589 H_SET_BSS_SIZE (&headers
, size
);
3592 /* Turn the gas native symbol table shape into a coff symbol table. */
3593 crawl_symbols (&headers
, abfd
);
3595 if (string_byte_count
== 4)
3596 string_byte_count
= 0;
3598 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3604 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3606 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3607 fixup_segment (&segment_info
[i
], i
);
3610 /* Look for ".stab" segments and fill in their initial symbols
3612 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3614 name
= segment_info
[i
].name
;
3617 && strncmp (".stab", name
, 5) == 0
3618 && strncmp (".stabstr", name
, 8) != 0)
3619 adjust_stab_section (abfd
, i
);
3622 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3624 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3626 /* Plant the data. */
3627 fill_section (abfd
, &headers
, &file_cursor
);
3629 do_relocs_for (abfd
, &headers
, &file_cursor
);
3631 do_linenos_for (abfd
, &headers
, &file_cursor
);
3633 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3634 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3635 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3637 H_SET_TIME_STAMP (&headers
, 0);
3639 #ifdef TC_COFF_SET_MACHINE
3640 TC_COFF_SET_MACHINE (&headers
);
3644 #define COFF_FLAGS 0
3647 #ifdef KEEP_RELOC_INFO
3648 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3649 COFF_FLAGS
| coff_flags
));
3651 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3652 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3653 COFF_FLAGS
| coff_flags
));
3657 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3658 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3660 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3661 w_symbols (abfd
, buffer1
, symbol_rootP
);
3662 if (string_byte_count
> 0)
3663 w_strings (buffer1
+ symtable_size
);
3664 bfd_bwrite (buffer1
, (bfd_size_type
) symtable_size
+ string_byte_count
,
3669 coff_header_append (abfd
, &headers
);
3671 /* Recent changes to write need this, but where it should
3672 go is up to Ken.. */
3673 if (!bfd_close_all_done (abfd
))
3674 as_fatal (_("Can't close %s: %s"), out_file_name
,
3675 bfd_errmsg (bfd_get_error ()));
3678 extern bfd
*stdoutput
;
3685 /* Add a new segment. This is called from subseg_new via the
3686 obj_new_segment macro. */
3689 obj_coff_add_segment (name
)
3694 #ifndef COFF_LONG_SECTION_NAMES
3695 char buf
[SCNNMLEN
+ 1];
3697 strncpy (buf
, name
, SCNNMLEN
);
3698 buf
[SCNNMLEN
] = '\0';
3702 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3703 if (strcmp (name
, segment_info
[i
].name
) == 0)
3708 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3712 /* Add a new section. */
3713 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3714 sizeof (segment_info
[i
].scnhdr
.s_name
));
3715 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3716 segment_info
[i
].name
= xstrdup (name
);
3721 /* Implement the .section pseudo op:
3722 .section name {, "flags"}
3724 | +--- optional flags: 'b' for bss
3726 +-- section name 'l' for lib
3730 'd' (apparently m88k for data)
3732 'r' for read-only data
3733 But if the argument is not a quoted string, treat it as a
3734 subsegment number. */
3737 obj_coff_section (ignore
)
3738 int ignore ATTRIBUTE_UNUSED
;
3740 /* Strip out the section name. */
3741 char *section_name
, *name
;
3754 else if (type
== 'D')
3756 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3761 section_name
= input_line_pointer
;
3762 c
= get_symbol_end ();
3764 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3765 strcpy (name
, section_name
);
3767 *input_line_pointer
= c
;
3773 if (*input_line_pointer
== ',')
3775 ++input_line_pointer
;
3778 if (*input_line_pointer
!= '"')
3779 exp
= get_absolute_expression ();
3782 ++input_line_pointer
;
3783 while (*input_line_pointer
!= '"'
3784 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3786 switch (*input_line_pointer
)
3788 case 'b': flags
|= STYP_BSS
; break;
3789 case 'i': flags
|= STYP_INFO
; break;
3790 case 'l': flags
|= STYP_LIB
; break;
3791 case 'n': flags
|= STYP_NOLOAD
; break;
3792 case 'o': flags
|= STYP_OVER
; break;
3794 case 'w': flags
|= STYP_DATA
; break;
3795 case 'x': flags
|= STYP_TEXT
; break;
3796 case 'r': flags
|= STYP_LIT
; break;
3798 as_warn(_("unknown section attribute '%c'"),
3799 *input_line_pointer
);
3802 ++input_line_pointer
;
3804 if (*input_line_pointer
== '"')
3805 ++input_line_pointer
;
3809 subseg_new (name
, (subsegT
) exp
);
3811 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3813 demand_empty_rest_of_line ();
3817 obj_coff_text (ignore
)
3818 int ignore ATTRIBUTE_UNUSED
;
3820 subseg_new (".text", get_absolute_expression ());
3824 obj_coff_data (ignore
)
3825 int ignore ATTRIBUTE_UNUSED
;
3827 if (flag_readonly_data_in_text
)
3828 subseg_new (".text", get_absolute_expression () + 1000);
3830 subseg_new (".data", get_absolute_expression ());
3834 obj_coff_ident (ignore
)
3835 int ignore ATTRIBUTE_UNUSED
;
3837 segT current_seg
= now_seg
; /* Save current seg. */
3838 subsegT current_subseg
= now_subseg
;
3840 subseg_new (".comment", 0); /* .comment seg. */
3841 stringer (1); /* Read string. */
3842 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
3846 c_symbol_merge (debug
, normal
)
3850 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3851 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3853 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3854 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3856 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3857 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3858 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3859 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3861 /* Move the debug flags. */
3862 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3866 c_line_new (symbol
, paddr
, line_number
, frag
)
3872 struct lineno_list
*new_line
=
3873 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3875 segment_info_type
*s
= segment_info
+ now_seg
;
3876 new_line
->line
.l_lnno
= line_number
;
3878 if (line_number
== 0)
3880 last_line_symbol
= symbol
;
3881 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3885 new_line
->line
.l_addr
.l_paddr
= paddr
;
3888 new_line
->frag
= (char *) frag
;
3889 new_line
->next
= (struct lineno_list
*) NULL
;
3891 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3892 s
->lineno_list_head
= new_line
;
3894 s
->lineno_list_tail
->next
= new_line
;
3896 s
->lineno_list_tail
= new_line
;
3897 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3901 c_dot_file_symbol (filename
)
3906 symbolP
= symbol_new (".file",
3909 &zero_address_frag
);
3911 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3912 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3914 if (strlen (filename
) > FILNMLEN
)
3916 /* Filename is too long to fit into an auxent,
3917 we stick it into the string table instead. We keep
3918 a linked list of the filenames we find so we can emit
3920 struct filename_list
*f
= ((struct filename_list
*)
3921 xmalloc (sizeof (struct filename_list
)));
3923 f
->filename
= filename
;
3926 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3927 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3929 if (filename_list_tail
)
3930 filename_list_tail
->next
= f
;
3932 filename_list_head
= f
;
3933 filename_list_tail
= f
;
3937 SA_SET_FILE_FNAME (symbolP
, filename
);
3943 listing_source_file (filename
);
3946 SF_SET_DEBUG (symbolP
);
3947 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3949 previous_file_symbol
= symbolP
;
3951 /* Make sure that the symbol is first on the symbol chain. */
3952 if (symbol_rootP
!= symbolP
)
3954 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3955 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3959 /* Build a 'section static' symbol. */
3962 c_section_symbol (name
, idx
)
3968 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3969 if (symbolP
== NULL
)
3970 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3973 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3974 S_SET_SEGMENT (symbolP
, idx
);
3975 symbolP
->sy_frag
= &zero_address_frag
;
3978 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3979 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3981 SF_SET_STATICS (symbolP
);
3984 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3985 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3986 SF_CLEAR_LOCAL (symbolP
);
3989 /* If the .linkonce pseudo-op was used for this section, we must
3990 store the information in the auxiliary entry for the section
3992 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3996 switch (segment_info
[idx
].linkonce
)
4000 case LINKONCE_DISCARD
:
4001 type
= IMAGE_COMDAT_SELECT_ANY
;
4003 case LINKONCE_ONE_ONLY
:
4004 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
4006 case LINKONCE_SAME_SIZE
:
4007 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
4009 case LINKONCE_SAME_CONTENTS
:
4010 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
4014 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
4022 w_symbols (abfd
, where
, symbol_rootP
)
4025 symbolS
* symbol_rootP
;
4030 /* First fill in those values we have only just worked out. */
4031 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
4033 symbolP
= segment_info
[i
].dot
;
4036 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
4037 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
4038 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
4042 /* Emit all symbols left in the symbol chain. */
4043 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
4045 /* Used to save the offset of the name. It is used to point
4046 to the string in memory but must be a file offset. */
4049 /* We can't fix the lnnoptr field in yank_symbols with the other
4050 adjustments, because we have to wait until we know where they
4052 if (SF_GET_ADJ_LNNOPTR (symbolP
))
4053 SA_GET_SYM_LNNOPTR (symbolP
) +=
4054 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4056 tc_coff_symbol_emit_hook (symbolP
);
4058 temp
= S_GET_NAME (symbolP
);
4059 if (SF_GET_STRING (symbolP
))
4061 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4062 S_SET_ZEROES (symbolP
, 0);
4066 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4067 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4069 where
= symbol_to_chars (abfd
, where
, symbolP
);
4070 S_SET_NAME (symbolP
, temp
);
4075 obj_coff_lcomm (ignore
)
4076 int ignore ATTRIBUTE_UNUSED
;
4088 name
= input_line_pointer
;
4090 c
= get_symbol_end ();
4091 p
= input_line_pointer
;
4094 if (*input_line_pointer
!= ',')
4096 as_bad (_("Expected comma after name"));
4097 ignore_rest_of_line ();
4100 if (*input_line_pointer
== '\n')
4102 as_bad (_("Missing size expression"));
4105 input_line_pointer
++;
4106 if ((temp
= get_absolute_expression ()) < 0)
4108 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4109 ignore_rest_of_line ();
4114 symbolP
= symbol_find_or_make (name
);
4116 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
&&
4117 S_GET_VALUE (symbolP
) == 0)
4122 segT current_seg
= now_seg
; /* Save current seg. */
4123 subsegT current_subseg
= now_subseg
;
4125 subseg_set (SEG_E2
, 1);
4126 symbolP
->sy_frag
= frag_now
;
4127 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4128 (offsetT
) temp
, (char *) 0);
4130 subseg_set (current_seg
, current_subseg
); /* Restore current seg. */
4131 S_SET_SEGMENT (symbolP
, SEG_E2
);
4132 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4136 as_bad (_("Symbol %s already defined"), name
);
4138 demand_empty_rest_of_line ();
4143 fixup_mdeps (frags
, h
, this_segment
)
4145 object_headers
*h ATTRIBUTE_UNUSED
;
4148 subseg_change (this_segment
, 0);
4152 switch (frags
->fr_type
)
4159 HANDLE_ALIGN (frags
);
4161 frags
->fr_type
= rs_fill
;
4163 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4166 case rs_machine_dependent
:
4167 md_convert_frag (h
, this_segment
, frags
);
4173 frags
= frags
->fr_next
;
4179 #ifndef TC_FORCE_RELOCATION
4180 #define TC_FORCE_RELOCATION(fix) 0
4184 fixup_segment (segP
, this_segment_type
)
4185 segment_info_type
* segP
;
4186 segT this_segment_type
;
4189 symbolS
*add_symbolP
;
4190 symbolS
*sub_symbolP
;
4197 segT add_symbol_segment
= absolute_section
;
4199 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4201 fragP
= fixP
->fx_frag
;
4203 where
= fixP
->fx_where
;
4204 place
= fragP
->fr_literal
+ where
;
4205 size
= fixP
->fx_size
;
4206 add_symbolP
= fixP
->fx_addsy
;
4207 sub_symbolP
= fixP
->fx_subsy
;
4208 add_number
= fixP
->fx_offset
;
4209 pcrel
= fixP
->fx_pcrel
;
4211 /* We want function-relative stabs to work on systems which
4212 may use a relaxing linker; thus we must handle the sym1-sym2
4213 fixups function-relative stabs generates.
4215 Of course, if you actually enable relaxing in the linker, the
4216 line and block scoping information is going to be incorrect
4217 in some cases. The only way to really fix this is to support
4218 a reloc involving the difference of two symbols. */
4220 && (!sub_symbolP
|| pcrel
))
4224 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4226 /* Relocation should be done via the associated 'bal' entry
4229 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4231 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4232 _("No 'bal' entry point for leafproc %s"),
4233 S_GET_NAME (add_symbolP
));
4236 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4240 /* Make sure the symbols have been resolved; this may not have
4241 happened if these are expression symbols. */
4242 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4243 resolve_symbol_value (add_symbolP
);
4245 if (add_symbolP
!= NULL
)
4247 /* If this fixup is against a symbol which has been equated
4248 to another symbol, convert it to the other symbol. */
4249 if (add_symbolP
->sy_value
.X_op
== O_symbol
4250 && (! S_IS_DEFINED (add_symbolP
)
4251 || S_IS_COMMON (add_symbolP
)))
4253 while (add_symbolP
->sy_value
.X_op
== O_symbol
4254 && (! S_IS_DEFINED (add_symbolP
)
4255 || S_IS_COMMON (add_symbolP
)))
4259 /* We must avoid looping, as that can occur with a
4260 badly written program. */
4261 n
= add_symbolP
->sy_value
.X_add_symbol
;
4262 if (n
== add_symbolP
)
4264 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4267 fixP
->fx_addsy
= add_symbolP
;
4268 fixP
->fx_offset
= add_number
;
4272 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4273 resolve_symbol_value (sub_symbolP
);
4275 if (add_symbolP
!= NULL
4276 && add_symbolP
->sy_mri_common
)
4278 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4279 add_number
+= S_GET_VALUE (add_symbolP
);
4280 fixP
->fx_offset
= add_number
;
4281 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4285 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4289 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4291 if (add_symbolP
!= NULL
)
4293 add_number
+= S_GET_VALUE (add_symbolP
);
4295 fixP
->fx_addsy
= NULL
;
4298 /* It's just -sym. */
4299 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4301 add_number
-= S_GET_VALUE (sub_symbolP
);
4308 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4309 _("Negative of non-absolute symbol %s"),
4310 S_GET_NAME (sub_symbolP
));
4312 add_number
-= S_GET_VALUE (sub_symbolP
);
4313 } /* not absolute */
4315 /* if sub_symbol is in the same segment that add_symbol
4316 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE. */
4318 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4319 && SEG_NORMAL (add_symbol_segment
))
4321 /* Difference of 2 symbols from same segment. Can't
4322 make difference of 2 undefineds: 'value' means
4323 something different for N_UNDF. */
4325 /* Makes no sense to use the difference of 2 arbitrary symbols
4326 as the target of a call instruction. */
4328 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4329 _("callj to difference of 2 symbols"));
4330 #endif /* TC_I960 */
4331 add_number
+= S_GET_VALUE (add_symbolP
) -
4332 S_GET_VALUE (sub_symbolP
);
4335 if (!TC_FORCE_RELOCATION (fixP
))
4337 fixP
->fx_addsy
= NULL
;
4338 fixP
->fx_subsy
= NULL
;
4340 #ifdef TC_M68K /* is this right? */
4348 /* Different segments in subtraction. */
4349 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4351 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4352 add_number
-= S_GET_VALUE (sub_symbolP
);
4355 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4356 #if 0 /* Okay for 68k, at least... */
4361 /* Make it pc-relative. */
4362 add_number
+= (md_pcrel_from (fixP
)
4363 - S_GET_VALUE (sub_symbolP
));
4372 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4373 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4374 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4375 S_GET_NAME (sub_symbolP
),
4376 (long) (fragP
->fr_address
+ where
));
4383 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4385 /* This fixup was made when the symbol's segment was
4386 SEG_UNKNOWN, but it is now in the local segment.
4387 So we know how to do the address without relocation. */
4389 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4390 in which cases it modifies *fixP as appropriate. In the case
4391 of a 'calls', no further work is required, and *fixP has been
4392 set up to make the rest of the code below a no-op. */
4394 #endif /* TC_I960 */
4396 add_number
+= S_GET_VALUE (add_symbolP
);
4397 add_number
-= md_pcrel_from (fixP
);
4400 add_number -= segP->scnhdr.s_vaddr;
4401 if defined (TC_I386) || defined (TE_LYNX). I now
4402 think that was an error propagated from the case when
4403 we are going to emit the relocation. If we are not
4404 going to emit the relocation, then we just want to
4405 set add_number to the difference between the symbols.
4406 This is a case that would only arise when there is a
4407 PC relative reference from a section other than .text
4408 to a symbol defined in the same section, and the
4409 reference is not relaxed. Since jump instructions on
4410 the i386 are relaxed, this could only arise with a
4411 call instruction. */
4413 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4414 if (!TC_FORCE_RELOCATION (fixP
))
4416 fixP
->fx_addsy
= NULL
;
4422 switch (add_symbol_segment
)
4424 case absolute_section
:
4426 /* See comment about reloc_callj() above. */
4428 #endif /* TC_I960 */
4429 add_number
+= S_GET_VALUE (add_symbolP
);
4432 if (!TC_FORCE_RELOCATION (fixP
))
4434 fixP
->fx_addsy
= NULL
;
4440 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4441 /* This really should be handled in the linker, but
4442 backward compatibility forbids. */
4443 add_number
+= S_GET_VALUE (add_symbolP
);
4445 add_number
+= S_GET_VALUE (add_symbolP
) +
4446 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4452 if ((int) fixP
->fx_bit_fixP
== 13)
4454 /* This is a COBR instruction. They have only a
4455 13-bit displacement and are only to be used
4456 for local branches: flag as error, don't generate
4458 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4459 _("can't use COBR format with external label"));
4460 fixP
->fx_addsy
= NULL
;
4464 #endif /* TC_I960 */
4465 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4466 /* 386 COFF uses a peculiar format in which the
4467 value of a common symbol is stored in the .text
4468 segment (I've checked this on SVR3.2 and SCO
4469 3.2.2) Ian Taylor <ian@cygnus.com>. */
4470 /* This is also true for 68k COFF on sysv machines
4471 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4472 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4473 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4474 if (S_IS_COMMON (add_symbolP
))
4475 add_number
+= S_GET_VALUE (add_symbolP
);
4485 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K) && !defined(TC_OR32)
4486 /* This adjustment is not correct on the m88k, for which the
4487 linker does all the computation. */
4488 add_number
-= md_pcrel_from (fixP
);
4490 if (add_symbolP
== 0)
4491 fixP
->fx_addsy
= &abs_symbol
;
4492 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4493 /* On the 386 we must adjust by the segment vaddr as well.
4496 I changed the i960 to work this way as well. This is
4497 compatible with the current GNU linker behaviour. I do
4498 not know what other i960 COFF assemblers do. This is not
4499 a common case: normally, only assembler code will contain
4500 a PC relative reloc, and only branches which do not
4501 originate in the .text section will have a non-zero
4504 I changed the m68k to work this way as well. This will
4505 break existing PC relative relocs from sections which do
4506 not start at address 0, but it will make ld -r work.
4507 Ian Taylor, 4 Oct 96. */
4509 add_number
-= segP
->scnhdr
.s_vaddr
;
4513 md_apply_fix3 (fixP
, (valueT
*) & add_number
, this_segment_type
);
4515 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4518 /* The m88k uses the offset field of the reloc to get around
4521 && ((add_number
& ~0xFF)
4522 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4523 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4524 || (add_number
& 0x80) == 0))
4526 && ((add_number
& ~0xFFFF)
4527 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4528 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4529 || (add_number
& 0x8000) == 0)))
4531 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4532 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4533 (long) add_number
, size
,
4534 (unsigned long) (fragP
->fr_address
+ where
));
4537 #ifdef WARN_SIGNED_OVERFLOW_WORD
4538 /* Warn if a .word value is too large when treated as a
4539 signed number. We already know it is not too negative.
4540 This is to catch over-large switches generated by gcc on
4542 if (!flag_signed_overflow_ok
4544 && add_number
> 0x7fff)
4545 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4546 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4548 (unsigned long) (fragP
->fr_address
+ where
));
4556 /* The first entry in a .stab section is special. */
4559 obj_coff_init_stab_section (seg
)
4565 unsigned int stroff
;
4567 /* Make space for this first symbol. */
4571 as_where (&file
, (unsigned int *) NULL
);
4572 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4573 strcpy (stabstr_name
, segment_info
[seg
].name
);
4574 strcat (stabstr_name
, "str");
4575 stroff
= get_stab_string_offset (file
, stabstr_name
);
4577 md_number_to_chars (p
, stroff
, 4);
4580 /* Fill in the counts in the first entry in a .stab section. */
4583 adjust_stab_section(abfd
, seg
)
4587 segT stabstrseg
= SEG_UNKNOWN
;
4588 const char *secname
, *name2
;
4591 int i
, strsz
= 0, nsyms
;
4592 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4594 /* Look for the associated string table section. */
4596 secname
= segment_info
[seg
].name
;
4597 name
= (char *) alloca (strlen (secname
) + 4);
4598 strcpy (name
, secname
);
4599 strcat (name
, "str");
4601 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4603 name2
= segment_info
[i
].name
;
4604 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4611 /* If we found the section, get its size. */
4612 if (stabstrseg
!= SEG_UNKNOWN
)
4613 strsz
= size_section (abfd
, stabstrseg
);
4615 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4617 /* Look for the first frag of sufficient size for the initial stab
4618 symbol, and collect a pointer to it. */
4619 while (frag
&& frag
->fr_fix
< 12)
4620 frag
= frag
->fr_next
;
4622 p
= frag
->fr_literal
;
4625 /* Write in the number of stab symbols and the size of the string
4627 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4628 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4631 #endif /* not BFD_ASSEMBLER */
4633 const pseudo_typeS coff_pseudo_table
[] =
4635 {"def", obj_coff_def
, 0},
4636 {"dim", obj_coff_dim
, 0},
4637 {"endef", obj_coff_endef
, 0},
4638 {"line", obj_coff_line
, 0},
4639 {"ln", obj_coff_ln
, 0},
4640 #ifdef BFD_ASSEMBLER
4641 {"loc", obj_coff_loc
, 0},
4643 {"appline", obj_coff_ln
, 1},
4644 {"scl", obj_coff_scl
, 0},
4645 {"size", obj_coff_size
, 0},
4646 {"tag", obj_coff_tag
, 0},
4647 {"type", obj_coff_type
, 0},
4648 {"val", obj_coff_val
, 0},
4649 {"section", obj_coff_section
, 0},
4650 {"sect", obj_coff_section
, 0},
4651 /* FIXME: We ignore the MRI short attribute. */
4652 {"section.s", obj_coff_section
, 0},
4653 {"sect.s", obj_coff_section
, 0},
4654 /* We accept the .bss directive for backward compatibility with
4655 earlier versions of gas. */
4656 {"bss", obj_coff_bss
, 0},
4657 {"weak", obj_coff_weak
, 0},
4658 {"ident", obj_coff_ident
, 0},
4659 #ifndef BFD_ASSEMBLER
4660 {"use", obj_coff_section
, 0},
4661 {"text", obj_coff_text
, 0},
4662 {"data", obj_coff_data
, 0},
4663 {"lcomm", obj_coff_lcomm
, 0},
4665 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4667 {"version", s_ignore
, 0},
4668 {"ABORT", s_abort
, 0},
4669 #if defined( TC_M88K ) || defined ( TC_TIC4X )
4670 /* The m88k and tic4x uses sdef instead of def. */
4671 {"sdef", obj_coff_def
, 0},
4673 {NULL
, NULL
, 0} /* end sentinel */
4674 }; /* coff_pseudo_table */
4676 #ifdef BFD_ASSEMBLER
4678 /* Support for a COFF emulation. */
4680 static void coff_pop_insert
PARAMS ((void));
4681 static int coff_separate_stab_sections
PARAMS ((void));
4686 pop_insert (coff_pseudo_table
);
4690 coff_separate_stab_sections ()
4695 const struct format_ops coff_format_ops
=
4697 bfd_target_coff_flavour
,
4698 0, /* dfl_leading_underscore */
4699 1, /* emit_section_symbols */
4704 0, /* frob_file_before_adjust */
4705 0, /* frob_file_before_fix */
4706 coff_frob_file_after_relocs
,
4709 0, /* s_get_align */
4710 0, /* s_set_align */
4711 0, /* s_get_other */
4712 0, /* s_set_other */
4717 0, /* copy_symbol_attributes */
4718 0, /* generate_asm_lineno */
4719 0, /* process_stab */
4720 coff_separate_stab_sections
,
4721 obj_coff_init_stab_section
,
4722 0, /* sec_sym_ok_for_reloc */
4724 0, /* ecoff_set_ext */
4725 coff_obj_read_begin_hook
,
4726 coff_obj_symbol_new_hook