1 /* coff object file format
2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
4 Free Software Foundation, Inc.
6 This file is part of GAS.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #define OBJ_HEADER "obj-coff.h"
29 /* I think this is probably always correct. */
30 #ifndef KEEP_RELOC_INFO
31 #define KEEP_RELOC_INFO
34 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
35 a new section's attributes when a directive has no valid flags or the
36 "w" flag is used. This default should be appropriate for most. */
37 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
38 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
41 /* 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 structres.
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 ());
215 /* Handle .weak. This is a GNU extension. */
218 obj_coff_weak (ignore
)
219 int ignore ATTRIBUTE_UNUSED
;
227 name
= input_line_pointer
;
228 c
= get_symbol_end ();
229 symbolP
= symbol_find_or_make (name
);
230 *input_line_pointer
= c
;
233 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
234 S_SET_WEAK (symbolP
);
238 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
240 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
245 input_line_pointer
++;
247 if (*input_line_pointer
== '\n')
253 demand_empty_rest_of_line ();
258 static segT fetch_coff_debug_section
PARAMS ((void));
259 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
260 static int S_GET_DATA_TYPE
PARAMS ((symbolS
*));
261 void c_symbol_merge
PARAMS ((symbolS
*, symbolS
*));
262 static void add_lineno
PARAMS ((fragS
*, addressT
, int));
264 #define GET_FILENAME_STRING(X) \
265 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
269 fetch_coff_debug_section ()
271 static segT debug_section
;
275 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
277 debug_section
= s
->section
;
279 return debug_section
;
283 SA_SET_SYM_ENDNDX (sym
, val
)
287 combined_entry_type
*entry
, *p
;
289 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
290 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
291 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
296 SA_SET_SYM_TAGNDX (sym
, val
)
300 combined_entry_type
*entry
, *p
;
302 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
303 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
304 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
309 S_GET_DATA_TYPE (sym
)
312 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
316 S_SET_DATA_TYPE (sym
, val
)
320 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
325 S_GET_STORAGE_CLASS (sym
)
328 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
332 S_SET_STORAGE_CLASS (sym
, val
)
336 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
340 /* Merge a debug symbol containing debug information into a normal symbol. */
343 c_symbol_merge (debug
, normal
)
347 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
348 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
350 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
352 /* take the most we have */
353 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
356 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
358 /* Move all the auxiliary information. */
359 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
360 (S_GET_NUMBER_AUXILIARY (debug
)
361 * sizeof (*SYM_AUXINFO (debug
))));
364 /* Move the debug flags. */
365 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
369 c_dot_file_symbol (filename
)
370 const char *filename
;
374 /* BFD converts filename to a .file symbol with an aux entry. It
375 also handles chaining. */
376 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
378 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
379 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
381 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
388 listing_source_file (filename
);
393 /* Make sure that the symbol is first on the symbol chain */
394 if (symbol_rootP
!= symbolP
)
396 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
397 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
398 } /* if not first on the list */
401 /* Line number handling */
404 struct line_no
*next
;
411 /* Symbol of last function, which we should hang line#s off of. */
412 static symbolS
*line_fsym
;
414 #define in_function() (line_fsym != 0)
415 #define clear_function() (line_fsym = 0)
416 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
420 coff_obj_symbol_new_hook (symbolP
)
423 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
424 char * s
= (char *) xmalloc (sz
);
427 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
429 S_SET_DATA_TYPE (symbolP
, T_NULL
);
430 S_SET_STORAGE_CLASS (symbolP
, 0);
431 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
433 if (S_IS_STRING (symbolP
))
434 SF_SET_STRING (symbolP
);
436 if (S_IS_LOCAL (symbolP
))
437 SF_SET_LOCAL (symbolP
);
442 * Handle .ln directives.
445 static symbolS
*current_lineno_sym
;
446 static struct line_no
*line_nos
;
447 /* @@ Blindly assume all .ln directives will be in the .text section... */
451 add_lineno (frag
, offset
, num
)
456 struct line_no
*new_line
=
457 (struct line_no
*) xmalloc (sizeof (struct line_no
));
458 if (!current_lineno_sym
)
464 /* The native aix assembler accepts negative line number */
468 /* Zero is used as an end marker in the file. */
469 as_warn (_("Line numbers must be positive integers\n"));
472 #endif /* OBJ_XCOFF */
473 new_line
->next
= line_nos
;
474 new_line
->frag
= frag
;
475 new_line
->l
.line_number
= num
;
476 new_line
->l
.u
.offset
= offset
;
482 coff_add_linesym (sym
)
487 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
492 current_lineno_sym
= sym
;
496 obj_coff_ln (appline
)
501 if (! appline
&& def_symbol_in_progress
!= NULL
)
503 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
504 demand_empty_rest_of_line ();
508 l
= get_absolute_expression ();
510 /* If there is no lineno symbol, treat a .ln
511 directive as if it were a .appline directive. */
512 if (appline
|| current_lineno_sym
== NULL
)
513 new_logical_line ((char *) NULL
, l
- 1);
515 add_lineno (frag_now
, frag_now_fix (), l
);
524 l
+= coff_line_base
- 1;
525 listing_source_line (l
);
530 demand_empty_rest_of_line ();
533 /* .loc is essentially the same as .ln; parse it for assembler
537 obj_coff_loc (ignore
)
538 int ignore ATTRIBUTE_UNUSED
;
542 /* FIXME: Why do we need this check? We need it for ECOFF, but why
543 do we need it for COFF? */
544 if (now_seg
!= text_section
)
546 as_warn (_(".loc outside of .text"));
547 demand_empty_rest_of_line ();
551 if (def_symbol_in_progress
!= NULL
)
553 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
554 demand_empty_rest_of_line ();
558 /* Skip the file number. */
560 get_absolute_expression ();
563 lineno
= get_absolute_expression ();
571 lineno
+= coff_line_base
- 1;
572 listing_source_line (lineno
);
577 demand_empty_rest_of_line ();
579 add_lineno (frag_now
, frag_now_fix (), lineno
);
582 /* Handle the .ident pseudo-op. */
585 obj_coff_ident (ignore
)
586 int ignore ATTRIBUTE_UNUSED
;
588 segT current_seg
= now_seg
;
589 subsegT current_subseg
= now_subseg
;
595 /* We could put it in .comment, but that creates an extra section
596 that shouldn't be loaded into memory, which requires linker
597 changes... For now, until proven otherwise, use .rdata. */
598 sec
= subseg_new (".rdata$zzz", 0);
599 bfd_set_section_flags (stdoutput
, sec
,
600 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
601 & bfd_applicable_section_flags (stdoutput
)));
604 subseg_new (".comment", 0);
608 subseg_set (current_seg
, current_subseg
);
614 * Handle .def directives.
616 * One might ask : why can't we symbol_new if the symbol does not
617 * already exist and fill it with debug information. Because of
618 * the C_EFCN special symbol. It would clobber the value of the
619 * function symbol before we have a chance to notice that it is
620 * a C_EFCN. And a second reason is that the code is more clear this
621 * way. (at least I think it is :-).
625 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
626 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
627 *input_line_pointer == '\t') \
628 input_line_pointer++;
632 int what ATTRIBUTE_UNUSED
;
634 char name_end
; /* Char after the end of name */
635 char *symbol_name
; /* Name of the debug symbol */
636 char *symbol_name_copy
; /* Temporary copy of the name */
637 unsigned int symbol_name_length
;
639 if (def_symbol_in_progress
!= NULL
)
641 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
642 demand_empty_rest_of_line ();
644 } /* if not inside .def/.endef */
648 symbol_name
= input_line_pointer
;
649 #ifdef STRIP_UNDERSCORE
650 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
652 #endif /* STRIP_UNDERSCORE */
654 name_end
= get_symbol_end ();
655 symbol_name_length
= strlen (symbol_name
);
656 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
657 strcpy (symbol_name_copy
, symbol_name
);
658 #ifdef tc_canonicalize_symbol_name
659 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
662 /* Initialize the new symbol */
663 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
664 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
665 S_SET_VALUE (def_symbol_in_progress
, 0);
667 if (S_IS_STRING (def_symbol_in_progress
))
668 SF_SET_STRING (def_symbol_in_progress
);
670 *input_line_pointer
= name_end
;
672 demand_empty_rest_of_line ();
675 unsigned int dim_index
;
678 obj_coff_endef (ignore
)
679 int ignore ATTRIBUTE_UNUSED
;
681 symbolS
*symbolP
= NULL
;
683 /* DIM BUG FIX sac@cygnus.com */
685 if (def_symbol_in_progress
== NULL
)
687 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
688 demand_empty_rest_of_line ();
690 } /* if not inside .def/.endef */
692 /* Set the section number according to storage class. */
693 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
698 SF_SET_TAG (def_symbol_in_progress
);
699 /* intentional fallthrough */
702 SF_SET_DEBUG (def_symbol_in_progress
);
703 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
707 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
708 /* intentional fallthrough */
710 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
711 /* intentional fallthrough */
715 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
717 name
= S_GET_NAME (def_symbol_in_progress
);
718 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
724 if (! in_function ())
725 as_warn (_("`%s' symbol without preceding function"), name
);
726 /* Will need relocating. */
727 SF_SET_PROCESS (def_symbol_in_progress
);
733 /* The MS compilers output the actual endline, not the
734 function-relative one... we want to match without
735 changing the assembler input. */
736 SA_SET_SYM_LNNO (def_symbol_in_progress
,
737 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
748 #endif /* C_AUTOARG */
755 /* According to the COFF documentation:
757 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
759 A special section number (-2) marks symbolic debugging symbols,
760 including structure/union/enumeration tag names, typedefs, and
761 the name of the file. A section number of -1 indicates that the
762 symbol has a value but is not relocatable. Examples of
763 absolute-valued symbols include automatic and register variables,
764 function arguments, and .eos symbols.
766 But from Ian Lance Taylor:
768 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
770 the actual tools all marked them as section -1. So the GNU COFF
771 assembler follows historical COFF assemblers.
773 However, it causes problems for djgpp
775 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
777 By defining STRICTCOFF, a COFF port can make the assembler to
778 follow the documented behavior. */
785 SF_SET_DEBUG (def_symbol_in_progress
);
786 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
794 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
805 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
812 as_warn (_("unexpected storage class %d"),
813 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
815 } /* switch on storage class */
817 /* Now that we have built a debug symbol, try to find if we should
818 merge with an existing symbol or not. If a symbol is C_EFCN or
819 absolute_section or untagged SEG_DEBUG it never merges. We also
820 don't merge labels, which are in a different namespace, nor
821 symbols which have not yet been defined since they are typically
822 unique, nor do we merge tags with non-tags. */
824 /* Two cases for functions. Either debug followed by definition or
825 definition followed by debug. For definition first, we will
826 merge the debug symbol into the definition. For debug first, the
827 lineno entry MUST point to the definition function or else it
828 will point off into space when obj_crawl_symbol_chain() merges
829 the debug symbol into the real symbol. Therefor, let's presume
830 the debug symbol is a real function reference. */
832 /* FIXME-SOON If for some reason the definition label/symbol is
833 never seen, this will probably leave an undefined symbol at link
836 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
837 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
838 || (!strcmp (bfd_get_section_name (stdoutput
,
839 S_GET_SEGMENT (def_symbol_in_progress
)),
841 && !SF_GET_TAG (def_symbol_in_progress
))
842 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
843 || ! symbol_constant_p (def_symbol_in_progress
)
844 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
845 DO_NOT_STRIP
)) == NULL
846 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
848 /* If it already is at the end of the symbol list, do nothing */
849 if (def_symbol_in_progress
!= symbol_lastP
)
851 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
852 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
858 /* This symbol already exists, merge the newly created symbol
859 into the old one. This is not mandatory. The linker can
860 handle duplicate symbols correctly. But I guess that it save
861 a *lot* of space if the assembly file defines a lot of
864 /* The debug entry (def_symbol_in_progress) is merged into the
865 previous definition. */
867 c_symbol_merge (def_symbol_in_progress
, symbolP
);
868 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
870 def_symbol_in_progress
= symbolP
;
872 if (SF_GET_FUNCTION (def_symbol_in_progress
)
873 || SF_GET_TAG (def_symbol_in_progress
)
874 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
876 /* For functions, and tags, and static symbols, the symbol
877 *must* be where the debug symbol appears. Move the
878 existing symbol to the current place. */
879 /* If it already is at the end of the symbol list, do nothing */
880 if (def_symbol_in_progress
!= symbol_lastP
)
882 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
883 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
888 if (SF_GET_TAG (def_symbol_in_progress
))
892 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
894 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
895 tag_insert (S_GET_NAME (def_symbol_in_progress
),
896 def_symbol_in_progress
);
899 if (SF_GET_FUNCTION (def_symbol_in_progress
))
901 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
902 set_function (def_symbol_in_progress
);
903 SF_SET_PROCESS (def_symbol_in_progress
);
907 /* That is, if this is the first time we've seen the
909 symbol_table_insert (def_symbol_in_progress
);
910 } /* definition follows debug */
911 } /* Create the line number entry pointing to the function being defined */
913 def_symbol_in_progress
= NULL
;
914 demand_empty_rest_of_line ();
918 obj_coff_dim (ignore
)
919 int ignore ATTRIBUTE_UNUSED
;
923 if (def_symbol_in_progress
== NULL
)
925 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
926 demand_empty_rest_of_line ();
928 } /* if not inside .def/.endef */
930 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
932 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
935 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
936 get_absolute_expression ());
938 switch (*input_line_pointer
)
941 input_line_pointer
++;
945 as_warn (_("badly formed .dim directive ignored"));
946 /* intentional fallthrough */
954 demand_empty_rest_of_line ();
958 obj_coff_line (ignore
)
959 int ignore ATTRIBUTE_UNUSED
;
963 if (def_symbol_in_progress
== NULL
)
965 /* Probably stabs-style line? */
970 this_base
= get_absolute_expression ();
971 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
972 coff_line_base
= this_base
;
974 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
975 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
977 demand_empty_rest_of_line ();
980 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
985 listing_source_line ((unsigned int) this_base
);
991 obj_coff_size (ignore
)
992 int ignore ATTRIBUTE_UNUSED
;
994 if (def_symbol_in_progress
== NULL
)
996 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
997 demand_empty_rest_of_line ();
999 } /* if not inside .def/.endef */
1001 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1002 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
1003 demand_empty_rest_of_line ();
1007 obj_coff_scl (ignore
)
1008 int ignore ATTRIBUTE_UNUSED
;
1010 if (def_symbol_in_progress
== NULL
)
1012 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
1013 demand_empty_rest_of_line ();
1015 } /* if not inside .def/.endef */
1017 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
1018 demand_empty_rest_of_line ();
1022 obj_coff_tag (ignore
)
1023 int ignore ATTRIBUTE_UNUSED
;
1028 if (def_symbol_in_progress
== NULL
)
1030 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
1031 demand_empty_rest_of_line ();
1035 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1036 symbol_name
= input_line_pointer
;
1037 name_end
= get_symbol_end ();
1039 #ifdef tc_canonicalize_symbol_name
1040 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1043 /* Assume that the symbol referred to by .tag is always defined.
1044 This was a bad assumption. I've added find_or_make. xoxorich. */
1045 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1046 tag_find_or_make (symbol_name
));
1047 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1049 as_warn (_("tag not found for .tag %s"), symbol_name
);
1052 SF_SET_TAGGED (def_symbol_in_progress
);
1053 *input_line_pointer
= name_end
;
1055 demand_empty_rest_of_line ();
1059 obj_coff_type (ignore
)
1060 int ignore ATTRIBUTE_UNUSED
;
1062 if (def_symbol_in_progress
== NULL
)
1064 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1065 demand_empty_rest_of_line ();
1067 } /* if not inside .def/.endef */
1069 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1071 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1072 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1074 SF_SET_FUNCTION (def_symbol_in_progress
);
1075 } /* is a function */
1077 demand_empty_rest_of_line ();
1081 obj_coff_val (ignore
)
1082 int ignore ATTRIBUTE_UNUSED
;
1084 if (def_symbol_in_progress
== NULL
)
1086 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1087 demand_empty_rest_of_line ();
1089 } /* if not inside .def/.endef */
1091 if (is_name_beginner (*input_line_pointer
))
1093 char *symbol_name
= input_line_pointer
;
1094 char name_end
= get_symbol_end ();
1096 #ifdef tc_canonicalize_symbol_name
1097 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1099 if (!strcmp (symbol_name
, "."))
1101 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1102 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1103 /* If the .val is != from the .def (e.g. statics) */
1105 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1109 exp
.X_op
= O_symbol
;
1110 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1111 exp
.X_op_symbol
= NULL
;
1112 exp
.X_add_number
= 0;
1113 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1115 /* If the segment is undefined when the forward reference is
1116 resolved, then copy the segment id from the forward
1118 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1120 /* FIXME: gcc can generate address expressions here in
1121 unusual cases (search for "obscure" in sdbout.c). We
1122 just ignore the offset here, thus generating incorrect
1123 debugging information. We ignore the rest of the line
1126 /* Otherwise, it is the name of a non debug symbol and its value
1127 will be calculated later. */
1128 *input_line_pointer
= name_end
;
1132 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1133 } /* if symbol based */
1135 demand_empty_rest_of_line ();
1139 coff_obj_read_begin_hook ()
1141 /* These had better be the same. Usually 18 bytes. */
1143 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1144 know (SYMESZ
== AUXESZ
);
1149 symbolS
*coff_last_function
;
1150 static symbolS
*coff_last_bf
;
1153 coff_frob_symbol (symp
, punt
)
1157 static symbolS
*last_tagP
;
1158 static stack
*block_stack
;
1159 static symbolS
*set_end
;
1160 symbolS
*next_set_end
= NULL
;
1162 if (symp
== &abs_symbol
)
1168 if (current_lineno_sym
)
1169 coff_add_linesym ((symbolS
*) 0);
1172 block_stack
= stack_init (512, sizeof (symbolS
*));
1174 if (S_IS_WEAK (symp
))
1177 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1179 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1183 if (!S_IS_DEFINED (symp
)
1184 && !S_IS_WEAK (symp
)
1185 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1186 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1188 if (!SF_GET_DEBUG (symp
))
1192 if (!SF_GET_LOCAL (symp
)
1193 && !SF_GET_STATICS (symp
)
1194 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1195 && symbol_constant_p(symp
)
1196 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1197 && S_GET_STORAGE_CLASS (real
) == C_NULL
1200 c_symbol_merge (symp
, real
);
1205 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1207 assert (S_GET_VALUE (symp
) == 0);
1208 S_SET_EXTERNAL (symp
);
1210 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1212 if (S_GET_SEGMENT (symp
) == text_section
1213 && symp
!= seg_info (text_section
)->sym
)
1214 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1216 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1219 if (SF_GET_PROCESS (symp
))
1221 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1223 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1224 stack_push (block_stack
, (char *) &symp
);
1229 begin
= *(symbolS
**) stack_pop (block_stack
);
1231 as_warn (_("mismatched .eb"));
1233 next_set_end
= begin
;
1237 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1239 union internal_auxent
*auxp
;
1241 coff_last_function
= symp
;
1242 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1243 S_SET_NUMBER_AUXILIARY (symp
, 1);
1244 auxp
= SYM_AUXENT (symp
);
1245 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1246 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1249 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1251 if (coff_last_function
== 0)
1252 as_fatal (_("C_EFCN symbol out of scope"));
1253 SA_SET_SYM_FSIZE (coff_last_function
,
1254 (long) (S_GET_VALUE (symp
)
1255 - S_GET_VALUE (coff_last_function
)));
1256 next_set_end
= coff_last_function
;
1257 coff_last_function
= 0;
1261 if (S_IS_EXTERNAL (symp
))
1262 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1263 else if (SF_GET_LOCAL (symp
))
1266 if (SF_GET_FUNCTION (symp
))
1267 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1272 /* Double check weak symbols. */
1273 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1274 as_bad (_("Symbol `%s' can not be both weak and common"),
1277 if (SF_GET_TAG (symp
))
1279 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1280 next_set_end
= last_tagP
;
1283 /* This is pretty horrible, but we have to set *punt correctly in
1284 order to call SA_SET_SYM_ENDNDX correctly. */
1285 if (! symbol_used_in_reloc_p (symp
)
1286 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1287 || (! S_IS_EXTERNAL (symp
)
1288 && ! symbol_get_tc (symp
)->output
1289 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1293 if (set_end
!= (symbolS
*) NULL
1295 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1296 || (S_IS_DEFINED (symp
)
1297 && ! S_IS_COMMON (symp
)
1298 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1300 SA_SET_SYM_ENDNDX (set_end
, symp
);
1304 if (next_set_end
!= NULL
)
1306 if (set_end
!= NULL
)
1307 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1308 S_GET_NAME (set_end
));
1309 set_end
= next_set_end
;
1314 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1315 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1317 if (coff_last_bf
!= NULL
)
1318 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1319 coff_last_bf
= symp
;
1322 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1325 struct line_no
*lptr
;
1328 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1329 for (i
= 0; lptr
; lptr
= lptr
->next
)
1331 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1333 /* We need i entries for line numbers, plus 1 for the first
1334 entry which BFD will override, plus 1 for the last zero
1335 entry (a marker for BFD). */
1336 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1337 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1338 l
[i
+ 1].line_number
= 0;
1339 l
[i
+ 1].u
.sym
= NULL
;
1343 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1351 coff_adjust_section_syms (abfd
, sec
, x
)
1352 bfd
*abfd ATTRIBUTE_UNUSED
;
1354 PTR x ATTRIBUTE_UNUSED
;
1357 segment_info_type
*seginfo
= seg_info (sec
);
1358 int nlnno
, nrelocs
= 0;
1360 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1361 tc-ppc.c. Do not get confused by it. */
1362 if (seginfo
== NULL
)
1365 if (!strcmp (sec
->name
, ".text"))
1366 nlnno
= coff_n_line_nos
;
1370 /* @@ Hope that none of the fixups expand to more than one reloc
1372 fixS
*fixp
= seginfo
->fix_root
;
1375 if (! fixp
->fx_done
)
1377 fixp
= fixp
->fx_next
;
1380 if (bfd_get_section_size_before_reloc (sec
) == 0
1383 && sec
!= text_section
1384 && sec
!= data_section
1385 && sec
!= bss_section
)
1387 secsym
= section_symbol (sec
);
1388 /* This is an estimate; we'll plug in the real value using
1389 SET_SECTION_RELOCS later */
1390 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1391 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1395 coff_frob_file_after_relocs ()
1397 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1401 * implement the .section pseudo op:
1402 * .section name {, "flags"}
1404 * | +--- optional flags: 'b' for bss
1406 * +-- section name 'l' for lib
1410 * 'd' (apparently m88k for data)
1412 * 'r' for read-only data
1413 * 's' for shared data (PE)
1414 * But if the argument is not a quoted string, treat it as a
1415 * subsegment number.
1419 obj_coff_section (ignore
)
1420 int ignore ATTRIBUTE_UNUSED
;
1422 /* Strip out the section name */
1427 flagword flags
, oldflags
;
1438 section_name
= input_line_pointer
;
1439 c
= get_symbol_end ();
1441 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1442 strcpy (name
, section_name
);
1444 *input_line_pointer
= c
;
1449 flags
= SEC_NO_FLAGS
;
1451 if (*input_line_pointer
== ',')
1453 ++input_line_pointer
;
1455 if (*input_line_pointer
!= '"')
1456 exp
= get_absolute_expression ();
1459 ++input_line_pointer
;
1460 while (*input_line_pointer
!= '"'
1461 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1463 switch (*input_line_pointer
)
1465 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1466 case 'n': flags
&=~ SEC_LOAD
; flags
|= SEC_NEVER_LOAD
; break;
1467 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1468 case 'w': flags
&=~ SEC_READONLY
; break;
1469 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1470 case 'r': flags
|= SEC_READONLY
; break;
1471 case 's': flags
|= SEC_SHARED
; break;
1473 case 'i': /* STYP_INFO */
1474 case 'l': /* STYP_LIB */
1475 case 'o': /* STYP_OVER */
1476 as_warn (_("unsupported section attribute '%c'"),
1477 *input_line_pointer
);
1481 as_warn(_("unknown section attribute '%c'"),
1482 *input_line_pointer
);
1485 ++input_line_pointer
;
1487 if (*input_line_pointer
== '"')
1488 ++input_line_pointer
;
1492 sec
= subseg_new (name
, (subsegT
) exp
);
1494 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1495 if (oldflags
== SEC_NO_FLAGS
)
1497 /* Set section flags for a new section just created by subseg_new.
1498 Provide a default if no flags were parsed. */
1499 if (flags
== SEC_NO_FLAGS
)
1500 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1502 #ifdef COFF_LONG_SECTION_NAMES
1503 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1504 sections so adjust_reloc_syms in write.c will correctly handle
1505 relocs which refer to non-local symbols in these sections. */
1506 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1507 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1510 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1511 as_warn (_("error setting flags for \"%s\": %s"),
1512 bfd_section_name (stdoutput
, sec
),
1513 bfd_errmsg (bfd_get_error ()));
1515 else if (flags
!= SEC_NO_FLAGS
)
1517 /* This section's attributes have already been set. Warn if the
1518 attributes don't match. */
1519 flagword matchflags
= (SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1520 | SEC_DATA
| SEC_SHARED
| SEC_NEVER_LOAD
);
1521 if ((flags
^ oldflags
) & matchflags
)
1522 as_warn (_("Ignoring changed section attributes for %s"), name
);
1525 demand_empty_rest_of_line ();
1529 coff_adjust_symtab ()
1531 if (symbol_rootP
== NULL
1532 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1533 c_dot_file_symbol ("fake");
1537 coff_frob_section (sec
)
1543 bfd_vma size
, n_entries
, mask
;
1544 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1546 /* The COFF back end in BFD requires that all section sizes be
1547 rounded up to multiples of the corresponding section alignments,
1548 supposedly because standard COFF has no other way of encoding alignment
1549 for sections. If your COFF flavor has a different way of encoding
1550 section alignment, then skip this step, as TICOFF does. */
1551 size
= bfd_get_section_size_before_reloc (sec
);
1552 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1553 #if !defined(TICOFF)
1559 new_size
= (size
+ mask
) & ~mask
;
1560 bfd_set_section_size (stdoutput
, sec
, new_size
);
1562 /* If the size had to be rounded up, add some padding in
1563 the last non-empty frag. */
1564 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1565 last
= seg_info (sec
)->frchainP
->frch_last
;
1566 while (fragp
->fr_next
!= last
)
1567 fragp
= fragp
->fr_next
;
1568 last
->fr_address
= size
;
1569 fragp
->fr_offset
+= new_size
- size
;
1573 /* If the section size is non-zero, the section symbol needs an aux
1574 entry associated with it, indicating the size. We don't know
1575 all the values yet; coff_frob_symbol will fill them in later. */
1578 || sec
== text_section
1579 || sec
== data_section
1580 || sec
== bss_section
)
1583 symbolS
*secsym
= section_symbol (sec
);
1585 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1586 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1587 SF_SET_STATICS (secsym
);
1588 SA_SET_SCN_SCNLEN (secsym
, size
);
1591 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1592 #ifndef STAB_SECTION_NAME
1593 #define STAB_SECTION_NAME ".stab"
1595 #ifndef STAB_STRING_SECTION_NAME
1596 #define STAB_STRING_SECTION_NAME ".stabstr"
1598 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1602 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1603 /* size is already rounded up, since other section will be listed first */
1604 size
= bfd_get_section_size_before_reloc (strsec
);
1606 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1608 /* Find first non-empty frag. It should be large enough. */
1609 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1610 while (fragp
&& fragp
->fr_fix
== 0)
1611 fragp
= fragp
->fr_next
;
1612 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1614 /* Store the values. */
1615 p
= fragp
->fr_literal
;
1616 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1617 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1621 obj_coff_init_stab_section (seg
)
1627 unsigned int stroff
;
1629 /* Make space for this first symbol. */
1633 as_where (&file
, (unsigned int *) NULL
);
1634 stabstr_name
= (char *) xmalloc (strlen (seg
->name
) + 4);
1635 strcpy (stabstr_name
, seg
->name
);
1636 strcat (stabstr_name
, "str");
1637 stroff
= get_stab_string_offset (file
, stabstr_name
);
1639 md_number_to_chars (p
, stroff
, 4);
1648 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1656 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1658 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1659 (unsigned long) symbolP
,
1660 S_GET_NAME(symbolP
),
1661 (long) S_GET_DATA_TYPE(symbolP
),
1662 S_GET_STORAGE_CLASS(symbolP
),
1663 (int) S_GET_SEGMENT(symbolP
));
1669 #else /* not BFD_ASSEMBLER */
1672 /* This is needed because we include internal bfd things. */
1676 #include "libcoff.h"
1679 #include "coff/pe.h"
1682 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1683 that we can stick sections together without causing trouble. */
1685 #define NOP_OPCODE 0x00
1688 /* The zeroes if symbol name is longer than 8 chars */
1689 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1691 #define MIN(a,b) ((a) < (b)? (a) : (b))
1693 /* This vector is used to turn a gas internal segment number into a
1694 section number suitable for insertion into a coff symbol table.
1695 This must correspond to seg_info_off_by_4. */
1697 const short seg_N_TYPE
[] =
1698 { /* in: segT out: N_TYPE bits */
1700 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1701 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1702 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1703 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1704 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1705 C_UNDEF_SECTION
, /* SEG_GOOF */
1706 C_UNDEF_SECTION
, /* SEG_EXPR */
1707 C_DEBUG_SECTION
, /* SEG_DEBUG */
1708 C_NTV_SECTION
, /* SEG_NTV */
1709 C_PTV_SECTION
, /* SEG_PTV */
1710 C_REGISTER_SECTION
, /* SEG_REGISTER */
1713 int function_lineoff
= -1; /* Offset in line#s where the last function
1714 started (the odd entry for line #0) */
1716 /* structure used to keep the filenames which
1717 are too long around so that we can stick them
1718 into the string table */
1719 struct filename_list
1722 struct filename_list
*next
;
1725 static struct filename_list
*filename_list_head
;
1726 static struct filename_list
*filename_list_tail
;
1728 static symbolS
*last_line_symbol
;
1730 /* Add 4 to the real value to get the index and compensate the
1731 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1732 section number into a segment number
1734 static symbolS
*previous_file_symbol
;
1735 void c_symbol_merge ();
1736 static int line_base
;
1738 symbolS
*c_section_symbol ();
1741 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1742 segT this_segment_type
));
1744 static void fixup_mdeps
PARAMS ((fragS
*,
1748 static void fill_section
PARAMS ((bfd
* abfd
,
1752 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1756 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1757 symbolS
* symbol_rootP
));
1759 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1761 static void obj_coff_lcomm
PARAMS ((int));
1762 static void obj_coff_text
PARAMS ((int));
1763 static void obj_coff_data
PARAMS ((int));
1764 void obj_coff_section
PARAMS ((int));
1766 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1768 This array maps a COFF section number into a gas section number.
1769 Because COFF uses negative section numbers, you must add 4 to the
1770 COFF section number when indexing into this array; this is done via
1771 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1774 static const segT seg_info_off_by_4
[] =
1781 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1782 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1783 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1784 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1785 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1786 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1787 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1788 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1801 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1803 static relax_addressT
1804 relax_align (address
, alignment
)
1805 relax_addressT address
;
1808 relax_addressT mask
;
1809 relax_addressT new_address
;
1811 mask
= ~((~0) << alignment
);
1812 new_address
= (address
+ mask
) & (~mask
);
1813 return (new_address
- address
);
1820 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1823 /* calculate the size of the frag chain and fill in the section header
1824 to contain all of it, also fill in the addr of the sections */
1826 size_section (abfd
, idx
)
1827 bfd
*abfd ATTRIBUTE_UNUSED
;
1831 unsigned int size
= 0;
1832 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1835 size
= frag
->fr_address
;
1836 if (frag
->fr_address
!= size
)
1838 fprintf (stderr
, _("Out of step\n"));
1839 size
= frag
->fr_address
;
1842 switch (frag
->fr_type
)
1844 #ifdef TC_COFF_SIZEMACHDEP
1845 case rs_machine_dependent
:
1846 size
+= TC_COFF_SIZEMACHDEP (frag
);
1852 size
+= frag
->fr_fix
;
1853 size
+= frag
->fr_offset
* frag
->fr_var
;
1861 size
+= frag
->fr_fix
;
1862 off
= relax_align (size
, frag
->fr_offset
);
1863 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1869 BAD_CASE (frag
->fr_type
);
1872 frag
= frag
->fr_next
;
1874 segment_info
[idx
].scnhdr
.s_size
= size
;
1879 count_entries_in_chain (idx
)
1882 unsigned int nrelocs
;
1885 /* Count the relocations */
1886 fixup_ptr
= segment_info
[idx
].fix_root
;
1888 while (fixup_ptr
!= (fixS
*) NULL
)
1890 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1892 #if defined(TC_A29K) || defined(TC_OR32)
1893 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1902 fixup_ptr
= fixup_ptr
->fx_next
;
1909 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1911 /* AUX's ld expects relocations to be sorted */
1913 compare_external_relocs (x
, y
)
1917 struct external_reloc
*a
= (struct external_reloc
*) x
;
1918 struct external_reloc
*b
= (struct external_reloc
*) y
;
1919 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1920 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1921 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1926 /* output all the relocations for a section */
1928 do_relocs_for (abfd
, h
, file_cursor
)
1931 unsigned long *file_cursor
;
1933 unsigned int nrelocs
;
1935 unsigned long reloc_start
= *file_cursor
;
1937 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1939 if (segment_info
[idx
].scnhdr
.s_name
[0])
1941 struct external_reloc
*ext_ptr
;
1942 struct external_reloc
*external_reloc_vec
;
1943 unsigned int external_reloc_size
;
1944 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1945 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1946 nrelocs
= count_entries_in_chain (idx
);
1949 /* Bypass this stuff if no relocs. This also incidentally
1950 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1952 external_reloc_size
= nrelocs
* RELSZ
;
1953 external_reloc_vec
=
1954 (struct external_reloc
*) malloc (external_reloc_size
);
1956 ext_ptr
= external_reloc_vec
;
1958 /* Fill in the internal coff style reloc struct from the
1959 internal fix list. */
1962 struct internal_reloc intr
;
1964 /* Only output some of the relocations */
1965 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1967 #ifdef TC_RELOC_MANGLE
1968 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1973 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1975 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1977 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1979 #ifdef TC_KEEP_FX_OFFSET
1980 intr
.r_offset
= fix_ptr
->fx_offset
;
1985 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1986 && (! S_IS_DEFINED (symbol_ptr
)
1987 || S_IS_COMMON (symbol_ptr
)))
1991 /* We must avoid looping, as that can occur
1992 with a badly written program. */
1993 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1994 if (n
== symbol_ptr
)
1999 /* Turn the segment of the symbol into an offset. */
2002 resolve_symbol_value (symbol_ptr
);
2003 if (! symbol_ptr
->sy_resolved
)
2008 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
2009 as_bad_where (file
, line
,
2010 _("unresolved relocation"));
2012 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
2013 S_GET_NAME (symbol_ptr
));
2015 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
2018 intr
.r_symndx
= dot
->sy_number
;
2022 intr
.r_symndx
= symbol_ptr
->sy_number
;
2032 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2035 #if defined(TC_A29K)
2037 /* The 29k has a special kludge for the high 16 bit
2038 reloc. Two relocations are emited, R_IHIHALF,
2039 and R_IHCONST. The second one doesn't contain a
2040 symbol, but uses the value for offset. */
2042 if (intr
.r_type
== R_IHIHALF
)
2044 /* now emit the second bit */
2045 intr
.r_type
= R_IHCONST
;
2046 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2047 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2051 #if defined(TC_OR32)
2052 /* The or32 has a special kludge for the high 16 bit
2053 reloc. Two relocations are emited, R_IHIHALF,
2054 and R_IHCONST. The second one doesn't contain a
2055 symbol, but uses the value for offset. */
2056 if (intr
.r_type
== R_IHIHALF
)
2058 /* Now emit the second bit. */
2059 intr
.r_type
= R_IHCONST
;
2060 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2061 (void) bfd_coff_swap_reloc_out (abfd
, & intr
, ext_ptr
);
2067 fix_ptr
= fix_ptr
->fx_next
;
2071 /* Sort the reloc table */
2072 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2073 sizeof (struct external_reloc
), compare_external_relocs
);
2076 /* Write out the reloc table */
2077 bfd_bwrite ((PTR
) external_reloc_vec
,
2078 (bfd_size_type
) external_reloc_size
, abfd
);
2079 free (external_reloc_vec
);
2081 /* Fill in section header info. */
2082 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2083 *file_cursor
+= external_reloc_size
;
2084 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2089 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2093 /* Set relocation_size field in file headers */
2094 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2097 /* run through a frag chain and write out the data to go with it, fill
2098 in the scnhdrs with the info on the file postions
2101 fill_section (abfd
, h
, file_cursor
)
2103 object_headers
*h ATTRIBUTE_UNUSED
;
2104 unsigned long *file_cursor
;
2108 unsigned int paddr
= 0;
2110 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2112 unsigned int offset
= 0;
2113 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2119 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2120 char *buffer
= NULL
;
2126 buffer
= xmalloc (s
->s_size
);
2127 s
->s_scnptr
= *file_cursor
;
2129 know (s
->s_paddr
== paddr
);
2131 if (strcmp (s
->s_name
, ".text") == 0)
2132 s
->s_flags
|= STYP_TEXT
;
2133 else if (strcmp (s
->s_name
, ".data") == 0)
2134 s
->s_flags
|= STYP_DATA
;
2135 else if (strcmp (s
->s_name
, ".bss") == 0)
2138 s
->s_flags
|= STYP_BSS
;
2140 /* @@ Should make the i386 and a29k coff targets define
2141 COFF_NOLOAD_PROBLEM, and have only one test here. */
2145 #ifndef COFF_NOLOAD_PROBLEM
2146 /* Apparently the SVR3 linker (and exec syscall) and UDI
2147 mondfe progrem are confused by noload sections. */
2148 s
->s_flags
|= STYP_NOLOAD
;
2154 else if (strcmp (s
->s_name
, ".lit") == 0)
2155 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2156 else if (strcmp (s
->s_name
, ".init") == 0)
2157 s
->s_flags
|= STYP_TEXT
;
2158 else if (strcmp (s
->s_name
, ".fini") == 0)
2159 s
->s_flags
|= STYP_TEXT
;
2160 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2161 s
->s_flags
|= STYP_INFO
;
2165 unsigned int fill_size
;
2166 switch (frag
->fr_type
)
2168 case rs_machine_dependent
:
2171 memcpy (buffer
+ frag
->fr_address
,
2173 (unsigned int) frag
->fr_fix
);
2174 offset
+= frag
->fr_fix
;
2186 memcpy (buffer
+ frag
->fr_address
,
2188 (unsigned int) frag
->fr_fix
);
2189 offset
+= frag
->fr_fix
;
2192 fill_size
= frag
->fr_var
;
2193 if (fill_size
&& frag
->fr_offset
> 0)
2196 unsigned int off
= frag
->fr_fix
;
2197 for (count
= frag
->fr_offset
; count
; count
--)
2199 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2201 memcpy (buffer
+ frag
->fr_address
+ off
,
2202 frag
->fr_literal
+ frag
->fr_fix
,
2205 offset
+= fill_size
;
2210 case rs_broken_word
:
2215 frag
= frag
->fr_next
;
2220 if (s
->s_scnptr
!= 0)
2222 bfd_bwrite (buffer
, s
->s_size
, abfd
);
2223 *file_cursor
+= s
->s_size
;
2232 /* Coff file generation & utilities */
2235 coff_header_append (abfd
, h
)
2242 #ifdef COFF_LONG_SECTION_NAMES
2243 unsigned long string_size
= 4;
2246 bfd_seek (abfd
, (file_ptr
) 0, 0);
2248 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2249 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2250 H_SET_VERSION_STAMP (h
, 0);
2251 H_SET_ENTRY_POINT (h
, 0);
2252 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2253 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2254 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2256 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2257 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2258 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2260 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2262 bfd_bwrite (buffer
, (bfd_size_type
) i
, abfd
);
2263 bfd_bwrite (buffero
, (bfd_size_type
) H_GET_SIZEOF_OPTIONAL_HEADER (h
), abfd
);
2265 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2267 if (segment_info
[i
].scnhdr
.s_name
[0])
2271 #ifdef COFF_LONG_SECTION_NAMES
2272 /* Support long section names as found in PE. This code
2273 must coordinate with that in write_object_file and
2275 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2277 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2278 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2279 string_size
+= strlen (segment_info
[i
].name
) + 1;
2283 size
= bfd_coff_swap_scnhdr_out (abfd
,
2284 &(segment_info
[i
].scnhdr
),
2287 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2288 bfd_bwrite (buffer
, (bfd_size_type
) size
, abfd
);
2294 symbol_to_chars (abfd
, where
, symbolP
)
2299 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2303 /* Turn any symbols with register attributes into abs symbols */
2304 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2306 S_SET_SEGMENT (symbolP
, absolute_section
);
2308 /* At the same time, relocate all symbols to their output value */
2311 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2312 + S_GET_VALUE (symbolP
));
2314 val
= S_GET_VALUE (symbolP
);
2317 S_SET_VALUE (symbolP
, val
);
2319 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2321 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2324 for (i
= 0; i
< numaux
; i
++)
2326 where
+= bfd_coff_swap_aux_out (abfd
,
2327 &symbolP
->sy_symbol
.ost_auxent
[i
],
2328 S_GET_DATA_TYPE (symbolP
),
2329 S_GET_STORAGE_CLASS (symbolP
),
2337 coff_obj_symbol_new_hook (symbolP
)
2340 char underscore
= 0; /* Symbol has leading _ */
2342 /* Effective symbol */
2343 /* Store the pointer in the offset. */
2344 S_SET_ZEROES (symbolP
, 0L);
2345 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2346 S_SET_STORAGE_CLASS (symbolP
, 0);
2347 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2348 /* Additional information */
2349 symbolP
->sy_symbol
.ost_flags
= 0;
2350 /* Auxiliary entries */
2351 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2353 if (S_IS_STRING (symbolP
))
2354 SF_SET_STRING (symbolP
);
2355 if (!underscore
&& S_IS_LOCAL (symbolP
))
2356 SF_SET_LOCAL (symbolP
);
2360 * Handle .ln directives.
2364 obj_coff_ln (appline
)
2369 if (! appline
&& def_symbol_in_progress
!= NULL
)
2371 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2372 demand_empty_rest_of_line ();
2374 } /* wrong context */
2376 l
= get_absolute_expression ();
2377 c_line_new (0, frag_now_fix (), l
, frag_now
);
2380 new_logical_line ((char *) NULL
, l
- 1);
2390 listing_source_line ((unsigned int) l
);
2395 demand_empty_rest_of_line ();
2401 * Handle .def directives.
2403 * One might ask : why can't we symbol_new if the symbol does not
2404 * already exist and fill it with debug information. Because of
2405 * the C_EFCN special symbol. It would clobber the value of the
2406 * function symbol before we have a chance to notice that it is
2407 * a C_EFCN. And a second reason is that the code is more clear this
2408 * way. (at least I think it is :-).
2412 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2413 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2414 *input_line_pointer == '\t') \
2415 input_line_pointer++;
2419 int what ATTRIBUTE_UNUSED
;
2421 char name_end
; /* Char after the end of name */
2422 char *symbol_name
; /* Name of the debug symbol */
2423 char *symbol_name_copy
; /* Temporary copy of the name */
2424 unsigned int symbol_name_length
;
2426 if (def_symbol_in_progress
!= NULL
)
2428 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2429 demand_empty_rest_of_line ();
2431 } /* if not inside .def/.endef */
2433 SKIP_WHITESPACES ();
2435 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2436 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2438 symbol_name
= input_line_pointer
;
2439 name_end
= get_symbol_end ();
2440 symbol_name_length
= strlen (symbol_name
);
2441 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2442 strcpy (symbol_name_copy
, symbol_name
);
2443 #ifdef tc_canonicalize_symbol_name
2444 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2447 /* Initialize the new symbol */
2448 #ifdef STRIP_UNDERSCORE
2449 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2450 ? symbol_name_copy
+ 1
2451 : symbol_name_copy
));
2452 #else /* STRIP_UNDERSCORE */
2453 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2454 #endif /* STRIP_UNDERSCORE */
2455 /* free(symbol_name_copy); */
2456 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2457 def_symbol_in_progress
->sy_number
= ~0;
2458 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2459 S_SET_VALUE (def_symbol_in_progress
, 0);
2461 if (S_IS_STRING (def_symbol_in_progress
))
2462 SF_SET_STRING (def_symbol_in_progress
);
2464 *input_line_pointer
= name_end
;
2466 demand_empty_rest_of_line ();
2469 unsigned int dim_index
;
2472 obj_coff_endef (ignore
)
2473 int ignore ATTRIBUTE_UNUSED
;
2475 symbolS
*symbolP
= 0;
2476 /* DIM BUG FIX sac@cygnus.com */
2478 if (def_symbol_in_progress
== NULL
)
2480 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2481 demand_empty_rest_of_line ();
2483 } /* if not inside .def/.endef */
2485 /* Set the section number according to storage class. */
2486 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2491 SF_SET_TAG (def_symbol_in_progress
);
2492 /* intentional fallthrough */
2495 SF_SET_DEBUG (def_symbol_in_progress
);
2496 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2500 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2501 /* intentional fallthrough */
2503 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2504 /* intentional fallthrough */
2506 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2508 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2510 if (function_lineoff
< 0)
2512 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2513 } /* missing function symbol */
2514 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2516 SF_SET_PROCESS (last_line_symbol
);
2517 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2518 SF_SET_PROCESS (def_symbol_in_progress
);
2519 function_lineoff
= -1;
2521 /* Value is always set to . */
2522 def_symbol_in_progress
->sy_frag
= frag_now
;
2523 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2528 #endif /* C_AUTOARG */
2538 SF_SET_DEBUG (def_symbol_in_progress
);
2539 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2549 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2555 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2557 } /* switch on storage class */
2559 /* Now that we have built a debug symbol, try to find if we should
2560 merge with an existing symbol or not. If a symbol is C_EFCN or
2561 absolute_section or untagged SEG_DEBUG it never merges. We also
2562 don't merge labels, which are in a different namespace, nor
2563 symbols which have not yet been defined since they are typically
2564 unique, nor do we merge tags with non-tags. */
2566 /* Two cases for functions. Either debug followed by definition or
2567 definition followed by debug. For definition first, we will
2568 merge the debug symbol into the definition. For debug first, the
2569 lineno entry MUST point to the definition function or else it
2570 will point off into space when crawl_symbols() merges the debug
2571 symbol into the real symbol. Therefor, let's presume the debug
2572 symbol is a real function reference. */
2574 /* FIXME-SOON If for some reason the definition label/symbol is
2575 never seen, this will probably leave an undefined symbol at link
2578 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2579 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2580 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2581 && !SF_GET_TAG (def_symbol_in_progress
))
2582 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2583 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2584 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2585 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2587 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2592 /* This symbol already exists, merge the newly created symbol
2593 into the old one. This is not mandatory. The linker can
2594 handle duplicate symbols correctly. But I guess that it save
2595 a *lot* of space if the assembly file defines a lot of
2598 /* The debug entry (def_symbol_in_progress) is merged into the
2599 previous definition. */
2601 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2602 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2603 def_symbol_in_progress
= symbolP
;
2605 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2606 || SF_GET_TAG (def_symbol_in_progress
)
2607 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2609 /* For functions, and tags, and static symbols, the symbol
2610 *must* be where the debug symbol appears. Move the
2611 existing symbol to the current place. */
2612 /* If it already is at the end of the symbol list, do nothing */
2613 if (def_symbol_in_progress
!= symbol_lastP
)
2615 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2617 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2618 &symbol_rootP
, &symbol_lastP
);
2619 } /* if not already in place */
2621 } /* normal or mergable */
2623 if (SF_GET_TAG (def_symbol_in_progress
))
2627 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2629 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2630 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2631 def_symbol_in_progress
);
2634 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2636 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2638 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2640 SF_SET_PROCESS (def_symbol_in_progress
);
2642 if (symbolP
== NULL
)
2644 /* That is, if this is the first time we've seen the
2646 symbol_table_insert (def_symbol_in_progress
);
2647 } /* definition follows debug */
2648 } /* Create the line number entry pointing to the function being defined */
2650 def_symbol_in_progress
= NULL
;
2651 demand_empty_rest_of_line ();
2655 obj_coff_dim (ignore
)
2656 int ignore ATTRIBUTE_UNUSED
;
2660 if (def_symbol_in_progress
== NULL
)
2662 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2663 demand_empty_rest_of_line ();
2665 } /* if not inside .def/.endef */
2667 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2669 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2671 SKIP_WHITESPACES ();
2672 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2673 get_absolute_expression ());
2675 switch (*input_line_pointer
)
2678 input_line_pointer
++;
2682 as_warn (_("badly formed .dim directive ignored"));
2683 /* intentional fallthrough */
2691 demand_empty_rest_of_line ();
2695 obj_coff_line (ignore
)
2696 int ignore ATTRIBUTE_UNUSED
;
2701 if (def_symbol_in_progress
== NULL
)
2707 name
= S_GET_NAME (def_symbol_in_progress
);
2708 this_base
= get_absolute_expression ();
2710 /* Only .bf symbols indicate the use of a new base line number; the
2711 line numbers associated with .ef, .bb, .eb are relative to the
2712 start of the containing function. */
2713 if (!strcmp (".bf", name
))
2715 #if 0 /* XXX Can we ever have line numbers going backwards? */
2716 if (this_base
> line_base
)
2719 line_base
= this_base
;
2727 listing_source_line ((unsigned int) line_base
);
2733 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2734 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2736 demand_empty_rest_of_line ();
2740 obj_coff_size (ignore
)
2741 int ignore ATTRIBUTE_UNUSED
;
2743 if (def_symbol_in_progress
== NULL
)
2745 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2746 demand_empty_rest_of_line ();
2748 } /* if not inside .def/.endef */
2750 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2751 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2752 demand_empty_rest_of_line ();
2756 obj_coff_scl (ignore
)
2757 int ignore ATTRIBUTE_UNUSED
;
2759 if (def_symbol_in_progress
== NULL
)
2761 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2762 demand_empty_rest_of_line ();
2764 } /* if not inside .def/.endef */
2766 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2767 demand_empty_rest_of_line ();
2771 obj_coff_tag (ignore
)
2772 int ignore ATTRIBUTE_UNUSED
;
2777 if (def_symbol_in_progress
== NULL
)
2779 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2780 demand_empty_rest_of_line ();
2784 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2785 symbol_name
= input_line_pointer
;
2786 name_end
= get_symbol_end ();
2787 #ifdef tc_canonicalize_symbol_name
2788 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2791 /* Assume that the symbol referred to by .tag is always defined.
2792 This was a bad assumption. I've added find_or_make. xoxorich. */
2793 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2794 (long) tag_find_or_make (symbol_name
));
2795 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2797 as_warn (_("tag not found for .tag %s"), symbol_name
);
2800 SF_SET_TAGGED (def_symbol_in_progress
);
2801 *input_line_pointer
= name_end
;
2803 demand_empty_rest_of_line ();
2807 obj_coff_type (ignore
)
2808 int ignore ATTRIBUTE_UNUSED
;
2810 if (def_symbol_in_progress
== NULL
)
2812 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2813 demand_empty_rest_of_line ();
2815 } /* if not inside .def/.endef */
2817 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2819 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2820 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2822 SF_SET_FUNCTION (def_symbol_in_progress
);
2823 } /* is a function */
2825 demand_empty_rest_of_line ();
2829 obj_coff_val (ignore
)
2830 int ignore ATTRIBUTE_UNUSED
;
2832 if (def_symbol_in_progress
== NULL
)
2834 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2835 demand_empty_rest_of_line ();
2837 } /* if not inside .def/.endef */
2839 if (is_name_beginner (*input_line_pointer
))
2841 char *symbol_name
= input_line_pointer
;
2842 char name_end
= get_symbol_end ();
2844 #ifdef tc_canonicalize_symbol_name
2845 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2848 if (!strcmp (symbol_name
, "."))
2850 def_symbol_in_progress
->sy_frag
= frag_now
;
2851 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2852 /* If the .val is != from the .def (e.g. statics) */
2854 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2856 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2857 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2858 symbol_find_or_make (symbol_name
);
2859 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2860 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2862 /* If the segment is undefined when the forward reference is
2863 resolved, then copy the segment id from the forward
2865 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2867 /* FIXME: gcc can generate address expressions here in
2868 unusual cases (search for "obscure" in sdbout.c). We
2869 just ignore the offset here, thus generating incorrect
2870 debugging information. We ignore the rest of the line
2873 /* Otherwise, it is the name of a non debug symbol and
2874 its value will be calculated later. */
2875 *input_line_pointer
= name_end
;
2877 /* FIXME: this is to avoid an error message in the
2878 FIXME case mentioned just above. */
2879 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2880 ++input_line_pointer
;
2884 S_SET_VALUE (def_symbol_in_progress
,
2885 (valueT
) get_absolute_expression ());
2886 } /* if symbol based */
2888 demand_empty_rest_of_line ();
2893 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2894 read.c, which then calls this object file format specific routine. */
2897 obj_coff_pe_handle_link_once (type
)
2898 enum linkonce_type type
;
2900 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2902 /* We store the type in the seg_info structure, and use it to set up
2903 the auxiliary entry for the section symbol in c_section_symbol. */
2904 seg_info (now_seg
)->linkonce
= type
;
2910 coff_obj_read_begin_hook ()
2912 /* These had better be the same. Usually 18 bytes. */
2914 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2915 know (SYMESZ
== AUXESZ
);
2920 /* This function runs through the symbol table and puts all the
2921 externals onto another chain */
2923 /* The chain of globals. */
2924 symbolS
*symbol_globalP
;
2925 symbolS
*symbol_global_lastP
;
2927 /* The chain of externals */
2928 symbolS
*symbol_externP
;
2929 symbolS
*symbol_extern_lastP
;
2932 symbolS
*last_functionP
;
2933 static symbolS
*last_bfP
;
2940 unsigned int symbol_number
= 0;
2941 unsigned int last_file_symno
= 0;
2943 struct filename_list
*filename_list_scan
= filename_list_head
;
2945 for (symbolP
= symbol_rootP
;
2947 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2949 if (symbolP
->sy_mri_common
)
2951 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2953 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2955 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2956 as_bad (_("%s: global symbols not supported in common sections"),
2957 S_GET_NAME (symbolP
));
2958 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2962 if (!SF_GET_DEBUG (symbolP
))
2964 /* Debug symbols do not need all this rubbish */
2965 symbolS
*real_symbolP
;
2967 /* L* and C_EFCN symbols never merge. */
2968 if (!SF_GET_LOCAL (symbolP
)
2969 && !SF_GET_STATICS (symbolP
)
2970 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2971 && symbolP
->sy_value
.X_op
== O_constant
2972 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2973 && real_symbolP
!= symbolP
)
2975 /* FIXME-SOON: where do dups come from?
2976 Maybe tag references before definitions? xoxorich. */
2977 /* Move the debug data from the debug symbol to the
2978 real symbol. Do NOT do the oposite (i.e. move from
2979 real symbol to debug symbol and remove real symbol from the
2980 list.) Because some pointers refer to the real symbol
2981 whereas no pointers refer to the debug symbol. */
2982 c_symbol_merge (symbolP
, real_symbolP
);
2983 /* Replace the current symbol by the real one */
2984 /* The symbols will never be the last or the first
2985 because : 1st symbol is .file and 3 last symbols are
2986 .text, .data, .bss */
2987 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2988 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2989 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2990 symbolP
= real_symbolP
;
2991 } /* if not local but dup'd */
2993 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2995 S_SET_SEGMENT (symbolP
, SEG_E0
);
2996 } /* push data into text */
2998 resolve_symbol_value (symbolP
);
3000 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
3002 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
3004 S_SET_EXTERNAL (symbolP
);
3006 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
3008 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
3012 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3016 /* Mainly to speed up if not -g */
3017 if (SF_GET_PROCESS (symbolP
))
3019 /* Handle the nested blocks auxiliary info. */
3020 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
3022 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
3023 stack_push (block_stack
, (char *) &symbolP
);
3026 register symbolS
*begin_symbolP
;
3027 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
3028 if (begin_symbolP
== (symbolS
*) 0)
3029 as_warn (_("mismatched .eb"));
3031 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
3034 /* If we are able to identify the type of a function, and we
3035 are out of a function (last_functionP == 0) then, the
3036 function symbol will be associated with an auxiliary
3038 if (last_functionP
== (symbolS
*) 0 &&
3039 SF_GET_FUNCTION (symbolP
))
3041 last_functionP
= symbolP
;
3043 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3045 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3046 } /* make it at least 1 */
3048 /* Clobber possible stale .dim information. */
3050 /* Iffed out by steve - this fries the lnnoptr info too */
3051 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3052 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3055 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3057 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3059 if (last_bfP
!= NULL
)
3060 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3064 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3066 /* I don't even know if this is needed for sdb. But
3067 the standard assembler generates it, so... */
3068 if (last_functionP
== (symbolS
*) 0)
3069 as_fatal (_("C_EFCN symbol out of scope"));
3070 SA_SET_SYM_FSIZE (last_functionP
,
3071 (long) (S_GET_VALUE (symbolP
) -
3072 S_GET_VALUE (last_functionP
)));
3073 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3074 last_functionP
= (symbolS
*) 0;
3078 else if (SF_GET_TAG (symbolP
))
3080 /* First descriptor of a structure must point to
3081 the first slot after the structure description. */
3082 last_tagP
= symbolP
;
3085 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3087 /* +2 take in account the current symbol */
3088 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3090 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3092 /* If the filename was too long to fit in the
3093 auxent, put it in the string table */
3094 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3095 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3097 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3098 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3099 filename_list_scan
= filename_list_scan
->next
;
3101 if (S_GET_VALUE (symbolP
))
3103 S_SET_VALUE (symbolP
, last_file_symno
);
3104 last_file_symno
= symbol_number
;
3105 } /* no one points at the first .file symbol */
3106 } /* if debug or tag or eos or file */
3108 #ifdef tc_frob_coff_symbol
3109 tc_frob_coff_symbol (symbolP
);
3112 /* We must put the external symbols apart. The loader
3113 does not bomb if we do not. But the references in
3114 the endndx field for a .bb symbol are not corrected
3115 if an external symbol is removed between .bb and .be.
3116 I.e in the following case :
3117 [20] .bb endndx = 22
3120 ld will move the symbol 21 to the end of the list but
3121 endndx will still be 22 instead of 21. */
3123 if (SF_GET_LOCAL (symbolP
))
3125 /* remove C_EFCN and LOCAL (L...) symbols */
3126 /* next pointer remains valid */
3127 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3130 else if (symbolP
->sy_value
.X_op
== O_symbol
3131 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3133 /* Skip symbols which were equated to undefined or common
3135 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3137 else if (!S_IS_DEFINED (symbolP
)
3138 && !S_IS_DEBUG (symbolP
)
3139 && !SF_GET_STATICS (symbolP
)
3140 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3142 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3144 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3146 /* if external, Remove from the list */
3147 symbolS
*hold
= symbol_previous (symbolP
);
3149 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3150 symbol_clear_list_pointers (symbolP
);
3151 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3154 else if (! S_IS_DEBUG (symbolP
)
3155 && ! SF_GET_STATICS (symbolP
)
3156 && ! SF_GET_FUNCTION (symbolP
)
3157 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3159 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3161 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3163 symbolS
*hold
= symbol_previous (symbolP
);
3165 /* The O'Reilly COFF book says that defined global symbols
3166 come at the end of the symbol table, just before
3167 undefined global symbols. */
3169 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3170 symbol_clear_list_pointers (symbolP
);
3171 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3172 &symbol_global_lastP
);
3177 if (SF_GET_STRING (symbolP
))
3179 symbolP
->sy_name_offset
= string_byte_count
;
3180 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3184 symbolP
->sy_name_offset
= 0;
3185 } /* fix "long" names */
3187 symbolP
->sy_number
= symbol_number
;
3188 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3189 } /* if local symbol */
3190 } /* traverse the symbol list */
3191 return symbol_number
;
3196 glue_symbols (head
, tail
)
3200 unsigned int symbol_number
= 0;
3202 while (*head
!= NULL
)
3204 symbolS
*tmp
= *head
;
3207 symbol_remove (tmp
, head
, tail
);
3208 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3211 if (SF_GET_STRING (tmp
))
3213 tmp
->sy_name_offset
= string_byte_count
;
3214 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3218 tmp
->sy_name_offset
= 0;
3219 } /* fix "long" names */
3221 tmp
->sy_number
= symbol_number
;
3222 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3223 } /* append the entire extern chain */
3225 return symbol_number
;
3231 unsigned int symbol_number
= 0;
3234 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3236 symbolP
->sy_number
= symbol_number
;
3238 if (SF_GET_TAGGED (symbolP
))
3242 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3245 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3248 return symbol_number
;
3252 crawl_symbols (h
, abfd
)
3254 bfd
*abfd ATTRIBUTE_UNUSED
;
3258 /* Initialize the stack used to keep track of the matching .bb .be */
3260 block_stack
= stack_init (512, sizeof (symbolS
*));
3262 /* The symbol list should be ordered according to the following sequence
3265 * . debug entries for functions
3266 * . fake symbols for the sections, including .text .data and .bss
3268 * . undefined symbols
3269 * But this is not mandatory. The only important point is to put the
3270 * undefined symbols at the end of the list.
3273 /* Is there a .file symbol ? If not insert one at the beginning. */
3274 if (symbol_rootP
== NULL
3275 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3277 c_dot_file_symbol ("fake");
3281 * Build up static symbols for the sections, they are filled in later
3284 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3285 if (segment_info
[i
].scnhdr
.s_name
[0])
3286 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3289 /* Take all the externals out and put them into another chain */
3290 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3291 /* Take the externals and glue them onto the end.*/
3292 H_SET_SYMBOL_TABLE_SIZE (h
,
3293 (H_GET_SYMBOL_COUNT (h
)
3294 + glue_symbols (&symbol_globalP
,
3295 &symbol_global_lastP
)
3296 + glue_symbols (&symbol_externP
,
3297 &symbol_extern_lastP
)));
3299 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3300 know (symbol_globalP
== NULL
);
3301 know (symbol_global_lastP
== NULL
);
3302 know (symbol_externP
== NULL
);
3303 know (symbol_extern_lastP
== NULL
);
3307 * Find strings by crawling along symbol table chain.
3315 struct filename_list
*filename_list_scan
= filename_list_head
;
3317 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3318 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3321 #ifdef COFF_LONG_SECTION_NAMES
3322 /* Support long section names as found in PE. This code must
3323 coordinate with that in coff_header_append and write_object_file. */
3327 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3329 if (segment_info
[i
].scnhdr
.s_name
[0]
3330 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3334 size
= strlen (segment_info
[i
].name
) + 1;
3335 memcpy (where
, segment_info
[i
].name
, size
);
3340 #endif /* COFF_LONG_SECTION_NAMES */
3342 for (symbolP
= symbol_rootP
;
3344 symbolP
= symbol_next (symbolP
))
3348 if (SF_GET_STRING (symbolP
))
3350 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3351 memcpy (where
, S_GET_NAME (symbolP
), size
);
3354 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3355 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3356 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3358 size
= strlen (filename_list_scan
->filename
) + 1;
3359 memcpy (where
, filename_list_scan
->filename
, size
);
3360 filename_list_scan
= filename_list_scan
->next
;
3367 do_linenos_for (abfd
, h
, file_cursor
)
3370 unsigned long *file_cursor
;
3373 unsigned long start
= *file_cursor
;
3375 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3377 segment_info_type
*s
= segment_info
+ idx
;
3379 if (s
->scnhdr
.s_nlnno
!= 0)
3381 struct lineno_list
*line_ptr
;
3383 struct external_lineno
*buffer
=
3384 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3386 struct external_lineno
*dst
= buffer
;
3388 /* Run through the table we've built and turn it into its external
3389 form, take this chance to remove duplicates */
3391 for (line_ptr
= s
->lineno_list_head
;
3392 line_ptr
!= (struct lineno_list
*) NULL
;
3393 line_ptr
= line_ptr
->next
)
3395 if (line_ptr
->line
.l_lnno
== 0)
3397 /* Turn a pointer to a symbol into the symbols' index,
3398 provided that it has been initialised. */
3399 if (line_ptr
->line
.l_addr
.l_symndx
)
3400 line_ptr
->line
.l_addr
.l_symndx
=
3401 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3405 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3408 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3413 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3415 bfd_bwrite (buffer
, (bfd_size_type
) s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3418 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3421 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3424 /* Now we run through the list of frag chains in a segment and
3425 make all the subsegment frags appear at the end of the
3426 list, as if the seg 0 was extra long */
3433 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3435 frchainS
*head
= segment_info
[i
].frchainP
;
3437 fragS
*prev_frag
= &dummy
;
3439 while (head
&& head
->frch_seg
== i
)
3441 prev_frag
->fr_next
= head
->frch_root
;
3442 prev_frag
= head
->frch_last
;
3443 head
= head
->frch_next
;
3445 prev_frag
->fr_next
= 0;
3449 unsigned long machine
;
3452 write_object_file ()
3456 struct frchain
*frchain_ptr
;
3458 object_headers headers
;
3459 unsigned long file_cursor
;
3462 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3466 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3467 exit (EXIT_FAILURE
);
3469 bfd_set_format (abfd
, bfd_object
);
3470 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3472 string_byte_count
= 4;
3474 for (frchain_ptr
= frchain_root
;
3475 frchain_ptr
!= (struct frchain
*) NULL
;
3476 frchain_ptr
= frchain_ptr
->frch_next
)
3478 /* Run through all the sub-segments and align them up. Also
3479 close any open frags. We tack a .fill onto the end of the
3480 frag chain so that any .align's size can be worked by looking
3481 at the next frag. */
3483 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3485 #ifndef SUB_SEGMENT_ALIGN
3486 #define SUB_SEGMENT_ALIGN(SEG) 1
3489 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3492 if (subseg_text_p (now_seg
))
3493 frag_align_code (SUB_SEGMENT_ALIGN (now_seg
), 0);
3495 frag_align (SUB_SEGMENT_ALIGN (now_seg
), 0, 0);
3501 frag_wane (frag_now
);
3502 frag_now
->fr_fix
= 0;
3503 know (frag_now
->fr_next
== NULL
);
3508 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3510 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3513 /* Relaxation has completed. Freeze all syms. */
3516 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3518 /* Find out how big the sections are, and set the addresses. */
3520 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3524 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3525 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3527 if (segment_info
[i
].scnhdr
.s_name
[0])
3529 H_SET_NUMBER_OF_SECTIONS (&headers
,
3530 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3532 #ifdef COFF_LONG_SECTION_NAMES
3533 /* Support long section names as found in PE. This code
3534 must coordinate with that in coff_header_append and
3539 len
= strlen (segment_info
[i
].name
);
3541 string_byte_count
+= len
+ 1;
3543 #endif /* COFF_LONG_SECTION_NAMES */
3546 size
= size_section (abfd
, (unsigned int) i
);
3549 /* I think the section alignment is only used on the i960; the
3550 i960 needs it, and it should do no harm on other targets. */
3551 #ifdef ALIGNMENT_IN_S_FLAGS
3552 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3554 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3558 H_SET_TEXT_SIZE (&headers
, size
);
3559 else if (i
== SEG_E1
)
3560 H_SET_DATA_SIZE (&headers
, size
);
3561 else if (i
== SEG_E2
)
3562 H_SET_BSS_SIZE (&headers
, size
);
3565 /* Turn the gas native symbol table shape into a coff symbol table */
3566 crawl_symbols (&headers
, abfd
);
3568 if (string_byte_count
== 4)
3569 string_byte_count
= 0;
3571 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3577 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3579 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3580 fixup_segment (&segment_info
[i
], i
);
3583 /* Look for ".stab" segments and fill in their initial symbols
3585 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3587 name
= segment_info
[i
].name
;
3590 && strncmp (".stab", name
, 5) == 0
3591 && strncmp (".stabstr", name
, 8) != 0)
3592 adjust_stab_section (abfd
, i
);
3595 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3597 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3599 /* Plant the data */
3601 fill_section (abfd
, &headers
, &file_cursor
);
3603 do_relocs_for (abfd
, &headers
, &file_cursor
);
3605 do_linenos_for (abfd
, &headers
, &file_cursor
);
3607 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3608 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3609 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3611 H_SET_TIME_STAMP (&headers
, 0);
3613 #ifdef TC_COFF_SET_MACHINE
3614 TC_COFF_SET_MACHINE (&headers
);
3618 #define COFF_FLAGS 0
3621 #ifdef KEEP_RELOC_INFO
3622 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3623 COFF_FLAGS
| coff_flags
));
3625 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3626 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3627 COFF_FLAGS
| coff_flags
));
3631 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3632 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3634 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3635 w_symbols (abfd
, buffer1
, symbol_rootP
);
3636 if (string_byte_count
> 0)
3637 w_strings (buffer1
+ symtable_size
);
3638 bfd_bwrite (buffer1
, (bfd_size_type
) symtable_size
+ string_byte_count
,
3643 coff_header_append (abfd
, &headers
);
3645 /* Recent changes to write need this, but where it should
3646 go is up to Ken.. */
3647 if (bfd_close_all_done (abfd
) == false)
3648 as_fatal (_("Can't close %s: %s"), out_file_name
,
3649 bfd_errmsg (bfd_get_error ()));
3652 extern bfd
*stdoutput
;
3659 /* Add a new segment. This is called from subseg_new via the
3660 obj_new_segment macro. */
3663 obj_coff_add_segment (name
)
3668 #ifndef COFF_LONG_SECTION_NAMES
3669 char buf
[SCNNMLEN
+ 1];
3671 strncpy (buf
, name
, SCNNMLEN
);
3672 buf
[SCNNMLEN
] = '\0';
3676 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3677 if (strcmp (name
, segment_info
[i
].name
) == 0)
3682 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3686 /* Add a new section. */
3687 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3688 sizeof (segment_info
[i
].scnhdr
.s_name
));
3689 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3690 segment_info
[i
].name
= xstrdup (name
);
3696 * implement the .section pseudo op:
3697 * .section name {, "flags"}
3699 * | +--- optional flags: 'b' for bss
3701 * +-- section name 'l' for lib
3705 * 'd' (apparently m88k for data)
3707 * 'r' for read-only data
3708 * But if the argument is not a quoted string, treat it as a
3709 * subsegment number.
3713 obj_coff_section (ignore
)
3714 int ignore ATTRIBUTE_UNUSED
;
3716 /* Strip out the section name */
3717 char *section_name
, *name
;
3730 else if (type
== 'D')
3732 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3737 section_name
= input_line_pointer
;
3738 c
= get_symbol_end ();
3740 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3741 strcpy (name
, section_name
);
3743 *input_line_pointer
= c
;
3749 if (*input_line_pointer
== ',')
3751 ++input_line_pointer
;
3754 if (*input_line_pointer
!= '"')
3755 exp
= get_absolute_expression ();
3758 ++input_line_pointer
;
3759 while (*input_line_pointer
!= '"'
3760 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3762 switch (*input_line_pointer
)
3764 case 'b': flags
|= STYP_BSS
; break;
3765 case 'i': flags
|= STYP_INFO
; break;
3766 case 'l': flags
|= STYP_LIB
; break;
3767 case 'n': flags
|= STYP_NOLOAD
; break;
3768 case 'o': flags
|= STYP_OVER
; break;
3770 case 'w': flags
|= STYP_DATA
; break;
3771 case 'x': flags
|= STYP_TEXT
; break;
3772 case 'r': flags
|= STYP_LIT
; break;
3774 as_warn(_("unknown section attribute '%c'"),
3775 *input_line_pointer
);
3778 ++input_line_pointer
;
3780 if (*input_line_pointer
== '"')
3781 ++input_line_pointer
;
3785 subseg_new (name
, (subsegT
) exp
);
3787 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3789 demand_empty_rest_of_line ();
3793 obj_coff_text (ignore
)
3794 int ignore ATTRIBUTE_UNUSED
;
3796 subseg_new (".text", get_absolute_expression ());
3800 obj_coff_data (ignore
)
3801 int ignore ATTRIBUTE_UNUSED
;
3803 if (flag_readonly_data_in_text
)
3804 subseg_new (".text", get_absolute_expression () + 1000);
3806 subseg_new (".data", get_absolute_expression ());
3810 obj_coff_ident (ignore
)
3811 int ignore ATTRIBUTE_UNUSED
;
3813 segT current_seg
= now_seg
; /* save current seg */
3814 subsegT current_subseg
= now_subseg
;
3815 subseg_new (".comment", 0); /* .comment seg */
3816 stringer (1); /* read string */
3817 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3821 c_symbol_merge (debug
, normal
)
3825 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3826 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3828 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3830 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3831 } /* take the most we have */
3833 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3835 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3836 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3837 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3838 } /* Move all the auxiliary information */
3840 /* Move the debug flags. */
3841 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3842 } /* c_symbol_merge() */
3845 c_line_new (symbol
, paddr
, line_number
, frag
)
3851 struct lineno_list
*new_line
=
3852 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3854 segment_info_type
*s
= segment_info
+ now_seg
;
3855 new_line
->line
.l_lnno
= line_number
;
3857 if (line_number
== 0)
3859 last_line_symbol
= symbol
;
3860 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3864 new_line
->line
.l_addr
.l_paddr
= paddr
;
3867 new_line
->frag
= (char *) frag
;
3868 new_line
->next
= (struct lineno_list
*) NULL
;
3870 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3872 s
->lineno_list_head
= new_line
;
3876 s
->lineno_list_tail
->next
= new_line
;
3878 s
->lineno_list_tail
= new_line
;
3879 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3883 c_dot_file_symbol (filename
)
3888 symbolP
= symbol_new (".file",
3891 &zero_address_frag
);
3893 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3894 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3896 if (strlen (filename
) > FILNMLEN
)
3898 /* Filename is too long to fit into an auxent,
3899 we stick it into the string table instead. We keep
3900 a linked list of the filenames we find so we can emit
3902 struct filename_list
*f
= ((struct filename_list
*)
3903 xmalloc (sizeof (struct filename_list
)));
3905 f
->filename
= filename
;
3908 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3909 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3911 if (filename_list_tail
)
3912 filename_list_tail
->next
= f
;
3914 filename_list_head
= f
;
3915 filename_list_tail
= f
;
3919 SA_SET_FILE_FNAME (symbolP
, filename
);
3926 listing_source_file (filename
);
3932 SF_SET_DEBUG (symbolP
);
3933 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3935 previous_file_symbol
= symbolP
;
3937 /* Make sure that the symbol is first on the symbol chain */
3938 if (symbol_rootP
!= symbolP
)
3940 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3941 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3943 } /* c_dot_file_symbol() */
3946 * Build a 'section static' symbol.
3950 c_section_symbol (name
, idx
)
3956 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3957 if (symbolP
== NULL
)
3958 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3961 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3962 S_SET_SEGMENT (symbolP
, idx
);
3963 symbolP
->sy_frag
= &zero_address_frag
;
3966 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3967 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3969 SF_SET_STATICS (symbolP
);
3972 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3973 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3974 SF_CLEAR_LOCAL (symbolP
);
3977 /* If the .linkonce pseudo-op was used for this section, we must
3978 store the information in the auxiliary entry for the section
3980 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3984 switch (segment_info
[idx
].linkonce
)
3988 case LINKONCE_DISCARD
:
3989 type
= IMAGE_COMDAT_SELECT_ANY
;
3991 case LINKONCE_ONE_ONLY
:
3992 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3994 case LINKONCE_SAME_SIZE
:
3995 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3997 case LINKONCE_SAME_CONTENTS
:
3998 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
4002 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
4007 } /* c_section_symbol() */
4010 w_symbols (abfd
, where
, symbol_rootP
)
4013 symbolS
* symbol_rootP
;
4018 /* First fill in those values we have only just worked out */
4019 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
4021 symbolP
= segment_info
[i
].dot
;
4024 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
4025 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
4026 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
4031 * Emit all symbols left in the symbol chain.
4033 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
4035 /* Used to save the offset of the name. It is used to point
4036 to the string in memory but must be a file offset. */
4037 register char *temp
;
4039 /* We can't fix the lnnoptr field in yank_symbols with the other
4040 adjustments, because we have to wait until we know where they
4042 if (SF_GET_ADJ_LNNOPTR (symbolP
))
4044 SA_GET_SYM_LNNOPTR (symbolP
) +=
4045 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4048 tc_coff_symbol_emit_hook (symbolP
);
4050 temp
= S_GET_NAME (symbolP
);
4051 if (SF_GET_STRING (symbolP
))
4053 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4054 S_SET_ZEROES (symbolP
, 0);
4058 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4059 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4061 where
= symbol_to_chars (abfd
, where
, symbolP
);
4062 S_SET_NAME (symbolP
, temp
);
4068 obj_coff_lcomm (ignore
)
4069 int ignore ATTRIBUTE_UNUSED
;
4081 name
= input_line_pointer
;
4083 c
= get_symbol_end ();
4084 p
= input_line_pointer
;
4087 if (*input_line_pointer
!= ',')
4089 as_bad (_("Expected comma after name"));
4090 ignore_rest_of_line ();
4093 if (*input_line_pointer
== '\n')
4095 as_bad (_("Missing size expression"));
4098 input_line_pointer
++;
4099 if ((temp
= get_absolute_expression ()) < 0)
4101 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4102 ignore_rest_of_line ();
4107 symbolP
= symbol_find_or_make (name
);
4109 if (S_GET_SEGMENT (symbolP
) == SEG_UNKNOWN
&&
4110 S_GET_VALUE (symbolP
) == 0)
4115 segT current_seg
= now_seg
; /* save current seg */
4116 subsegT current_subseg
= now_subseg
;
4118 subseg_set (SEG_E2
, 1);
4119 symbolP
->sy_frag
= frag_now
;
4120 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4121 (offsetT
) temp
, (char *) 0);
4123 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4124 S_SET_SEGMENT (symbolP
, SEG_E2
);
4125 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
4129 as_bad (_("Symbol %s already defined"), name
);
4131 demand_empty_rest_of_line ();
4136 fixup_mdeps (frags
, h
, this_segment
)
4141 subseg_change (this_segment
, 0);
4144 switch (frags
->fr_type
)
4151 HANDLE_ALIGN (frags
);
4153 frags
->fr_type
= rs_fill
;
4155 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4158 case rs_machine_dependent
:
4159 md_convert_frag (h
, this_segment
, frags
);
4165 frags
= frags
->fr_next
;
4171 #ifndef TC_FORCE_RELOCATION
4172 #define TC_FORCE_RELOCATION(fix) 0
4176 fixup_segment (segP
, this_segment_type
)
4177 segment_info_type
* segP
;
4178 segT this_segment_type
;
4180 register fixS
* fixP
;
4181 register symbolS
*add_symbolP
;
4182 register symbolS
*sub_symbolP
;
4185 register char *place
;
4186 register long where
;
4187 register char pcrel
;
4188 register fragS
*fragP
;
4189 register segT add_symbol_segment
= absolute_section
;
4191 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4193 fragP
= fixP
->fx_frag
;
4195 where
= fixP
->fx_where
;
4196 place
= fragP
->fr_literal
+ where
;
4197 size
= fixP
->fx_size
;
4198 add_symbolP
= fixP
->fx_addsy
;
4199 sub_symbolP
= fixP
->fx_subsy
;
4200 add_number
= fixP
->fx_offset
;
4201 pcrel
= fixP
->fx_pcrel
;
4203 /* We want function-relative stabs to work on systems which
4204 may use a relaxing linker; thus we must handle the sym1-sym2
4205 fixups function-relative stabs generates.
4207 Of course, if you actually enable relaxing in the linker, the
4208 line and block scoping information is going to be incorrect
4209 in some cases. The only way to really fix this is to support
4210 a reloc involving the difference of two symbols. */
4212 && (!sub_symbolP
|| pcrel
))
4216 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4218 /* Relocation should be done via the associated 'bal' entry
4221 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4223 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4224 _("No 'bal' entry point for leafproc %s"),
4225 S_GET_NAME (add_symbolP
));
4228 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4232 /* Make sure the symbols have been resolved; this may not have
4233 happened if these are expression symbols. */
4234 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4235 resolve_symbol_value (add_symbolP
);
4237 if (add_symbolP
!= NULL
)
4239 /* If this fixup is against a symbol which has been equated
4240 to another symbol, convert it to the other symbol. */
4241 if (add_symbolP
->sy_value
.X_op
== O_symbol
4242 && (! S_IS_DEFINED (add_symbolP
)
4243 || S_IS_COMMON (add_symbolP
)))
4245 while (add_symbolP
->sy_value
.X_op
== O_symbol
4246 && (! S_IS_DEFINED (add_symbolP
)
4247 || S_IS_COMMON (add_symbolP
)))
4251 /* We must avoid looping, as that can occur with a
4252 badly written program. */
4253 n
= add_symbolP
->sy_value
.X_add_symbol
;
4254 if (n
== add_symbolP
)
4256 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4259 fixP
->fx_addsy
= add_symbolP
;
4260 fixP
->fx_offset
= add_number
;
4264 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4265 resolve_symbol_value (sub_symbolP
);
4267 if (add_symbolP
!= NULL
4268 && add_symbolP
->sy_mri_common
)
4270 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4271 add_number
+= S_GET_VALUE (add_symbolP
);
4272 fixP
->fx_offset
= add_number
;
4273 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4278 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4279 } /* if there is an addend */
4283 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4285 if (add_symbolP
!= NULL
)
4287 add_number
+= S_GET_VALUE (add_symbolP
);
4289 fixP
->fx_addsy
= NULL
;
4292 /* It's just -sym. */
4293 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4295 add_number
-= S_GET_VALUE (sub_symbolP
);
4302 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4303 _("Negative of non-absolute symbol %s"),
4304 S_GET_NAME (sub_symbolP
));
4306 add_number
-= S_GET_VALUE (sub_symbolP
);
4307 } /* not absolute */
4309 /* if sub_symbol is in the same segment that add_symbol
4310 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4312 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4313 && SEG_NORMAL (add_symbol_segment
))
4315 /* Difference of 2 symbols from same segment. Can't
4316 make difference of 2 undefineds: 'value' means
4317 something different for N_UNDF. */
4319 /* Makes no sense to use the difference of 2 arbitrary symbols
4320 as the target of a call instruction. */
4323 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4324 _("callj to difference of 2 symbols"));
4326 #endif /* TC_I960 */
4327 add_number
+= S_GET_VALUE (add_symbolP
) -
4328 S_GET_VALUE (sub_symbolP
);
4331 if (!TC_FORCE_RELOCATION (fixP
))
4333 fixP
->fx_addsy
= NULL
;
4334 fixP
->fx_subsy
= NULL
;
4336 #ifdef TC_M68K /* is this right? */
4344 /* Different segments in subtraction. */
4345 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4347 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4349 add_number
-= S_GET_VALUE (sub_symbolP
);
4352 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4353 #if 0 /* Okay for 68k, at least... */
4358 /* Make it pc-relative. */
4359 add_number
+= (md_pcrel_from (fixP
)
4360 - S_GET_VALUE (sub_symbolP
));
4369 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4370 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4371 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4372 S_GET_NAME (sub_symbolP
),
4373 (long) (fragP
->fr_address
+ where
));
4376 } /* if sub_symbolP */
4380 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4383 * This fixup was made when the symbol's segment was
4384 * SEG_UNKNOWN, but it is now in the local segment.
4385 * So we know how to do the address without relocation.
4388 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4389 * in which cases it modifies *fixP as appropriate. In the case
4390 * of a 'calls', no further work is required, and *fixP has been
4391 * 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 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4427 #endif /* TC_I960 */
4428 add_number
+= S_GET_VALUE (add_symbolP
);
4431 if (!TC_FORCE_RELOCATION (fixP
))
4433 fixP
->fx_addsy
= NULL
;
4439 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K) || defined(TC_OR32)
4440 /* This really should be handled in the linker, but
4441 backward compatibility forbids. */
4442 add_number
+= S_GET_VALUE (add_symbolP
);
4444 add_number
+= S_GET_VALUE (add_symbolP
) +
4445 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4451 if ((int) fixP
->fx_bit_fixP
== 13)
4453 /* This is a COBR instruction. They have only a
4454 * 13-bit displacement and are only to be used
4455 * 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
);
4479 } /* switch on symbol seg */
4480 } /* if not in local seg */
4481 } /* if there was a + symbol */
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)
4492 fixP
->fx_addsy
= &abs_symbol
;
4493 } /* if there's an add_symbol */
4494 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4495 /* On the 386 we must adjust by the segment vaddr as well.
4498 I changed the i960 to work this way as well. This is
4499 compatible with the current GNU linker behaviour. I do
4500 not know what other i960 COFF assemblers do. This is not
4501 a common case: normally, only assembler code will contain
4502 a PC relative reloc, and only branches which do not
4503 originate in the .text section will have a non-zero
4506 I changed the m68k to work this way as well. This will
4507 break existing PC relative relocs from sections which do
4508 not start at address 0, but it will make ld -r work.
4509 Ian Taylor, 4 Oct 96. */
4511 add_number
-= segP
->scnhdr
.s_vaddr
;
4515 md_apply_fix3 (fixP
, (valueT
*) & add_number
, this_segment_type
);
4517 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4520 /* The m88k uses the offset field of the reloc to get around
4523 && ((add_number
& ~0xFF)
4524 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4525 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4526 || (add_number
& 0x80) == 0))
4528 && ((add_number
& ~0xFFFF)
4529 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4530 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4531 || (add_number
& 0x8000) == 0)))
4533 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4534 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4535 (long) add_number
, size
,
4536 (unsigned long) (fragP
->fr_address
+ where
));
4539 #ifdef WARN_SIGNED_OVERFLOW_WORD
4540 /* Warn if a .word value is too large when treated as a
4541 signed number. We already know it is not too negative.
4542 This is to catch over-large switches generated by gcc on
4544 if (!flag_signed_overflow_ok
4546 && add_number
> 0x7fff)
4547 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4548 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4550 (unsigned long) (fragP
->fr_address
+ where
));
4552 } /* not a bit fix */
4553 } /* For each fixS in this segment. */
4554 } /* fixup_segment() */
4558 /* The first entry in a .stab section is special. */
4561 obj_coff_init_stab_section (seg
)
4567 unsigned int stroff
;
4569 /* Make space for this first symbol. */
4573 as_where (&file
, (unsigned int *) NULL
);
4574 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4575 strcpy (stabstr_name
, segment_info
[seg
].name
);
4576 strcat (stabstr_name
, "str");
4577 stroff
= get_stab_string_offset (file
, stabstr_name
);
4579 md_number_to_chars (p
, stroff
, 4);
4582 /* Fill in the counts in the first entry in a .stab section. */
4585 adjust_stab_section(abfd
, seg
)
4589 segT stabstrseg
= SEG_UNKNOWN
;
4590 const char *secname
, *name2
;
4593 int i
, strsz
= 0, nsyms
;
4594 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4596 /* Look for the associated string table section. */
4598 secname
= segment_info
[seg
].name
;
4599 name
= (char *) alloca (strlen (secname
) + 4);
4600 strcpy (name
, secname
);
4601 strcat (name
, "str");
4603 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4605 name2
= segment_info
[i
].name
;
4606 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4613 /* If we found the section, get its size. */
4614 if (stabstrseg
!= SEG_UNKNOWN
)
4615 strsz
= size_section (abfd
, stabstrseg
);
4617 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4619 /* Look for the first frag of sufficient size for the initial stab
4620 symbol, and collect a pointer to it. */
4621 while (frag
&& frag
->fr_fix
< 12)
4622 frag
= frag
->fr_next
;
4624 p
= frag
->fr_literal
;
4627 /* Write in the number of stab symbols and the size of the string
4629 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4630 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4633 #endif /* not BFD_ASSEMBLER */
4635 const pseudo_typeS coff_pseudo_table
[] =
4637 {"def", obj_coff_def
, 0},
4638 {"dim", obj_coff_dim
, 0},
4639 {"endef", obj_coff_endef
, 0},
4640 {"line", obj_coff_line
, 0},
4641 {"ln", obj_coff_ln
, 0},
4642 #ifdef BFD_ASSEMBLER
4643 {"loc", obj_coff_loc
, 0},
4645 {"appline", obj_coff_ln
, 1},
4646 {"scl", obj_coff_scl
, 0},
4647 {"size", obj_coff_size
, 0},
4648 {"tag", obj_coff_tag
, 0},
4649 {"type", obj_coff_type
, 0},
4650 {"val", obj_coff_val
, 0},
4651 {"section", obj_coff_section
, 0},
4652 {"sect", obj_coff_section
, 0},
4653 /* FIXME: We ignore the MRI short attribute. */
4654 {"section.s", obj_coff_section
, 0},
4655 {"sect.s", obj_coff_section
, 0},
4656 /* We accept the .bss directive for backward compatibility with
4657 earlier versions of gas. */
4658 {"bss", obj_coff_bss
, 0},
4659 {"weak", obj_coff_weak
, 0},
4660 {"ident", obj_coff_ident
, 0},
4661 #ifndef BFD_ASSEMBLER
4662 {"use", obj_coff_section
, 0},
4663 {"text", obj_coff_text
, 0},
4664 {"data", obj_coff_data
, 0},
4665 {"lcomm", obj_coff_lcomm
, 0},
4667 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4669 {"version", s_ignore
, 0},
4670 {"ABORT", s_abort
, 0},
4672 /* The m88k uses sdef instead of def. */
4673 {"sdef", obj_coff_def
, 0},
4675 {NULL
, NULL
, 0} /* end sentinel */
4676 }; /* coff_pseudo_table */
4678 #ifdef BFD_ASSEMBLER
4680 /* Support for a COFF emulation. */
4682 static void coff_pop_insert
PARAMS ((void));
4683 static int coff_separate_stab_sections
PARAMS ((void));
4688 pop_insert (coff_pseudo_table
);
4692 coff_separate_stab_sections ()
4697 const struct format_ops coff_format_ops
=
4699 bfd_target_coff_flavour
,
4700 0, /* dfl_leading_underscore */
4701 1, /* emit_section_symbols */
4706 0, /* frob_file_before_adjust */
4707 coff_frob_file_after_relocs
,
4710 0, /* s_get_align */
4711 0, /* s_set_align */
4712 0, /* s_get_other */
4713 0, /* s_set_other */
4718 0, /* copy_symbol_attributes */
4719 0, /* generate_asm_lineno */
4720 0, /* process_stab */
4721 coff_separate_stab_sections
,
4722 obj_coff_init_stab_section
,
4723 0, /* sec_sym_ok_for_reloc */
4725 0, /* ecoff_set_ext */
4726 coff_obj_read_begin_hook
,
4727 coff_obj_symbol_new_hook