1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
3 Free Software Foundation, Inc.
5 This file is part of GAS.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #define OBJ_HEADER "obj-coff.h"
28 /* I think this is probably always correct. */
29 #ifndef KEEP_RELOC_INFO
30 #define KEEP_RELOC_INFO
33 /* The BFD_ASSEMBLER version of obj_coff_section will use this macro to set
34 a new section's attributes when a directive has no valid flags or the
35 "w" flag is used. This default should be appropriate for most. */
36 #ifndef TC_COFF_SECTION_DEFAULT_ATTRIBUTES
37 #define TC_COFF_SECTION_DEFAULT_ATTRIBUTES (SEC_LOAD | SEC_DATA)
40 static void obj_coff_bss
PARAMS ((int));
41 const char *s_get_name
PARAMS ((symbolS
* s
));
42 static void obj_coff_ln
PARAMS ((int));
43 static void obj_coff_def
PARAMS ((int));
44 static void obj_coff_endef
PARAMS ((int));
45 static void obj_coff_dim
PARAMS ((int));
46 static void obj_coff_line
PARAMS ((int));
47 static void obj_coff_size
PARAMS ((int));
48 static void obj_coff_scl
PARAMS ((int));
49 static void obj_coff_tag
PARAMS ((int));
50 static void obj_coff_val
PARAMS ((int));
51 static void obj_coff_type
PARAMS ((int));
52 static void obj_coff_ident
PARAMS ((int));
54 static void obj_coff_loc
PARAMS((int));
57 /* This is used to hold the symbol built by a sequence of pseudo-ops
58 from .def and .endef. */
59 static symbolS
*def_symbol_in_progress
;
64 unsigned long chunk_size
;
65 unsigned long element_size
;
68 unsigned long pointer
;
73 stack_init (chunk_size
, element_size
)
74 unsigned long chunk_size
;
75 unsigned long element_size
;
79 st
= (stack
*) malloc (sizeof (stack
));
82 st
->data
= malloc (chunk_size
);
89 st
->size
= chunk_size
;
90 st
->chunk_size
= chunk_size
;
91 st
->element_size
= element_size
;
96 /* Not currently used. */
107 stack_push (st
, element
)
111 if (st
->pointer
+ st
->element_size
>= st
->size
)
113 st
->size
+= st
->chunk_size
;
114 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
117 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
118 st
->pointer
+= st
->element_size
;
119 return st
->data
+ st
->pointer
;
126 if (st
->pointer
< st
->element_size
)
131 st
->pointer
-= st
->element_size
;
132 return st
->data
+ st
->pointer
;
136 * Maintain a list of the tagnames of the structres.
139 static struct hash_control
*tag_hash
;
144 tag_hash
= hash_new ();
148 tag_insert (name
, symbolP
)
152 const char *error_string
;
154 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
156 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
165 #ifdef STRIP_UNDERSCORE
168 #endif /* STRIP_UNDERSCORE */
169 return (symbolS
*) hash_find (tag_hash
, name
);
173 tag_find_or_make (name
)
178 if ((symbolP
= tag_find (name
)) == NULL
)
180 symbolP
= symbol_new (name
, undefined_section
,
181 0, &zero_address_frag
);
183 tag_insert (S_GET_NAME (symbolP
), symbolP
);
185 symbol_table_insert (symbolP
);
192 /* We accept the .bss directive to set the section for backward
193 compatibility with earlier versions of gas. */
196 obj_coff_bss (ignore
)
197 int ignore ATTRIBUTE_UNUSED
;
199 if (*input_line_pointer
== '\n')
200 subseg_new (".bss", get_absolute_expression ());
205 /* Handle .weak. This is a GNU extension. */
208 obj_coff_weak (ignore
)
209 int ignore ATTRIBUTE_UNUSED
;
217 name
= input_line_pointer
;
218 c
= get_symbol_end ();
219 symbolP
= symbol_find_or_make (name
);
220 *input_line_pointer
= c
;
223 #if defined BFD_ASSEMBLER || defined S_SET_WEAK
224 S_SET_WEAK (symbolP
);
228 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
230 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
235 input_line_pointer
++;
237 if (*input_line_pointer
== '\n')
243 demand_empty_rest_of_line ();
248 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
250 #define GET_FILENAME_STRING(X) \
251 ((char*) (&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
255 fetch_coff_debug_section ()
257 static segT debug_section
;
261 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
263 debug_section
= s
->section
;
265 return debug_section
;
269 SA_SET_SYM_ENDNDX (sym
, val
)
273 combined_entry_type
*entry
, *p
;
275 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
276 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
277 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
282 SA_SET_SYM_TAGNDX (sym
, val
)
286 combined_entry_type
*entry
, *p
;
288 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
289 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
290 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
295 S_GET_DATA_TYPE (sym
)
298 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
302 S_SET_DATA_TYPE (sym
, val
)
306 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
311 S_GET_STORAGE_CLASS (sym
)
314 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
318 S_SET_STORAGE_CLASS (sym
, val
)
322 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
326 /* Merge a debug symbol containing debug information into a normal symbol. */
329 c_symbol_merge (debug
, normal
)
333 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
334 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
336 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
338 /* take the most we have */
339 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
342 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
344 /* Move all the auxiliary information. */
345 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
346 (S_GET_NUMBER_AUXILIARY (debug
)
347 * sizeof (*SYM_AUXINFO (debug
))));
350 /* Move the debug flags. */
351 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
355 c_dot_file_symbol (filename
)
356 const char *filename
;
360 /* BFD converts filename to a .file symbol with an aux entry. It
361 also handles chaining. */
362 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
364 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
365 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
367 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
374 listing_source_file (filename
);
379 /* Make sure that the symbol is first on the symbol chain */
380 if (symbol_rootP
!= symbolP
)
382 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
383 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
384 } /* if not first on the list */
387 /* Line number handling */
390 struct line_no
*next
;
397 /* Symbol of last function, which we should hang line#s off of. */
398 static symbolS
*line_fsym
;
400 #define in_function() (line_fsym != 0)
401 #define clear_function() (line_fsym = 0)
402 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
406 coff_obj_symbol_new_hook (symbolP
)
409 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
410 char * s
= (char *) xmalloc (sz
);
413 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
415 S_SET_DATA_TYPE (symbolP
, T_NULL
);
416 S_SET_STORAGE_CLASS (symbolP
, 0);
417 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
419 if (S_IS_STRING (symbolP
))
420 SF_SET_STRING (symbolP
);
422 if (S_IS_LOCAL (symbolP
))
423 SF_SET_LOCAL (symbolP
);
428 * Handle .ln directives.
431 static symbolS
*current_lineno_sym
;
432 static struct line_no
*line_nos
;
433 /* @@ Blindly assume all .ln directives will be in the .text section... */
437 add_lineno (frag
, offset
, num
)
442 struct line_no
*new_line
=
443 (struct line_no
*) xmalloc (sizeof (struct line_no
));
444 if (!current_lineno_sym
)
450 /* Zero is used as an end marker in the file. */
451 as_warn (_("Line numbers must be positive integers\n"));
454 new_line
->next
= line_nos
;
455 new_line
->frag
= frag
;
456 new_line
->l
.line_number
= num
;
457 new_line
->l
.u
.offset
= offset
;
463 coff_add_linesym (sym
)
468 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
473 current_lineno_sym
= sym
;
477 obj_coff_ln (appline
)
482 if (! appline
&& def_symbol_in_progress
!= NULL
)
484 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
485 demand_empty_rest_of_line ();
489 l
= get_absolute_expression ();
492 add_lineno (frag_now
, frag_now_fix (), l
);
496 new_logical_line ((char *) NULL
, l
- 1);
505 l
+= coff_line_base
- 1;
506 listing_source_line (l
);
511 demand_empty_rest_of_line ();
514 /* .loc is essentially the same as .ln; parse it for assembler
518 obj_coff_loc (ignore
)
519 int ignore ATTRIBUTE_UNUSED
;
523 /* FIXME: Why do we need this check? We need it for ECOFF, but why
524 do we need it for COFF? */
525 if (now_seg
!= text_section
)
527 as_warn (_(".loc outside of .text"));
528 demand_empty_rest_of_line ();
532 if (def_symbol_in_progress
!= NULL
)
534 as_warn (_(".loc pseudo-op inside .def/.endef: ignored."));
535 demand_empty_rest_of_line ();
539 /* Skip the file number. */
541 get_absolute_expression ();
544 lineno
= get_absolute_expression ();
552 lineno
+= coff_line_base
- 1;
553 listing_source_line (lineno
);
558 demand_empty_rest_of_line ();
560 add_lineno (frag_now
, frag_now_fix (), lineno
);
563 /* Handle the .ident pseudo-op. */
566 obj_coff_ident (ignore
)
567 int ignore ATTRIBUTE_UNUSED
;
569 segT current_seg
= now_seg
;
570 subsegT current_subseg
= now_subseg
;
576 /* We could put it in .comment, but that creates an extra section
577 that shouldn't be loaded into memory, which requires linker
578 changes... For now, until proven otherwise, use .rdata. */
579 sec
= subseg_new (".rdata$zzz", 0);
580 bfd_set_section_flags (stdoutput
, sec
,
581 ((SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_DATA
)
582 & bfd_applicable_section_flags (stdoutput
)));
585 subseg_new (".comment", 0);
589 subseg_set (current_seg
, current_subseg
);
595 * Handle .def directives.
597 * One might ask : why can't we symbol_new if the symbol does not
598 * already exist and fill it with debug information. Because of
599 * the C_EFCN special symbol. It would clobber the value of the
600 * function symbol before we have a chance to notice that it is
601 * a C_EFCN. And a second reason is that the code is more clear this
602 * way. (at least I think it is :-).
606 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
607 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
608 *input_line_pointer == '\t') \
609 input_line_pointer++;
613 int what ATTRIBUTE_UNUSED
;
615 char name_end
; /* Char after the end of name */
616 char *symbol_name
; /* Name of the debug symbol */
617 char *symbol_name_copy
; /* Temporary copy of the name */
618 unsigned int symbol_name_length
;
620 if (def_symbol_in_progress
!= NULL
)
622 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
623 demand_empty_rest_of_line ();
625 } /* if not inside .def/.endef */
629 symbol_name
= input_line_pointer
;
630 #ifdef STRIP_UNDERSCORE
631 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
633 #endif /* STRIP_UNDERSCORE */
635 name_end
= get_symbol_end ();
636 symbol_name_length
= strlen (symbol_name
);
637 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
638 strcpy (symbol_name_copy
, symbol_name
);
639 #ifdef tc_canonicalize_symbol_name
640 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
643 /* Initialize the new symbol */
644 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
645 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
646 S_SET_VALUE (def_symbol_in_progress
, 0);
648 if (S_IS_STRING (def_symbol_in_progress
))
649 SF_SET_STRING (def_symbol_in_progress
);
651 *input_line_pointer
= name_end
;
653 demand_empty_rest_of_line ();
656 unsigned int dim_index
;
659 obj_coff_endef (ignore
)
660 int ignore ATTRIBUTE_UNUSED
;
662 symbolS
*symbolP
= NULL
;
664 /* DIM BUG FIX sac@cygnus.com */
666 if (def_symbol_in_progress
== NULL
)
668 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
669 demand_empty_rest_of_line ();
671 } /* if not inside .def/.endef */
673 /* Set the section number according to storage class. */
674 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
679 SF_SET_TAG (def_symbol_in_progress
);
680 /* intentional fallthrough */
683 SF_SET_DEBUG (def_symbol_in_progress
);
684 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
688 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
689 /* intentional fallthrough */
691 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
692 /* intentional fallthrough */
696 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
698 name
= S_GET_NAME (def_symbol_in_progress
);
699 if (name
[0] == '.' && name
[2] == 'f' && name
[3] == '\0')
705 if (! in_function ())
706 as_warn (_("`%s' symbol without preceding function"), name
);
707 /* Will need relocating. */
708 SF_SET_PROCESS (def_symbol_in_progress
);
714 /* The MS compilers output the actual endline, not the
715 function-relative one... we want to match without
716 changing the assembler input. */
717 SA_SET_SYM_LNNO (def_symbol_in_progress
,
718 (SA_GET_SYM_LNNO (def_symbol_in_progress
)
729 #endif /* C_AUTOARG */
736 /* According to the COFF documentation:
738 http://osr5doc.sco.com:1996/topics/COFF_SectNumFld.html
740 A special section number (-2) marks symbolic debugging symbols,
741 including structure/union/enumeration tag names, typedefs, and
742 the name of the file. A section number of -1 indicates that the
743 symbol has a value but is not relocatable. Examples of
744 absolute-valued symbols include automatic and register variables,
745 function arguments, and .eos symbols.
747 But from Ian Lance Taylor:
749 http://sources.redhat.com/ml/binutils/2000-08/msg00202.html
751 the actual tools all marked them as section -1. So the GNU COFF
752 assembler follows historical COFF assemblers.
754 However, it causes problems for djgpp
756 http://sources.redhat.com/ml/binutils/2000-08/msg00210.html
758 By defining STRICTCOFF, a COFF port can make the assembler to
759 follow the documented behavior. */
766 SF_SET_DEBUG (def_symbol_in_progress
);
767 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
775 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
786 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
793 as_warn (_("unexpected storage class %d"),
794 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
796 } /* switch on storage class */
798 /* Now that we have built a debug symbol, try to find if we should
799 merge with an existing symbol or not. If a symbol is C_EFCN or
800 absolute_section or untagged SEG_DEBUG it never merges. We also
801 don't merge labels, which are in a different namespace, nor
802 symbols which have not yet been defined since they are typically
803 unique, nor do we merge tags with non-tags. */
805 /* Two cases for functions. Either debug followed by definition or
806 definition followed by debug. For definition first, we will
807 merge the debug symbol into the definition. For debug first, the
808 lineno entry MUST point to the definition function or else it
809 will point off into space when obj_crawl_symbol_chain() merges
810 the debug symbol into the real symbol. Therefor, let's presume
811 the debug symbol is a real function reference. */
813 /* FIXME-SOON If for some reason the definition label/symbol is
814 never seen, this will probably leave an undefined symbol at link
817 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
818 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
819 || (!strcmp (bfd_get_section_name (stdoutput
,
820 S_GET_SEGMENT (def_symbol_in_progress
)),
822 && !SF_GET_TAG (def_symbol_in_progress
))
823 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
824 || ! symbol_constant_p (def_symbol_in_progress
)
825 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
826 DO_NOT_STRIP
)) == NULL
827 || SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
))
829 /* If it already is at the end of the symbol list, do nothing */
830 if (def_symbol_in_progress
!= symbol_lastP
)
832 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
833 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
839 /* This symbol already exists, merge the newly created symbol
840 into the old one. This is not mandatory. The linker can
841 handle duplicate symbols correctly. But I guess that it save
842 a *lot* of space if the assembly file defines a lot of
845 /* The debug entry (def_symbol_in_progress) is merged into the
846 previous definition. */
848 c_symbol_merge (def_symbol_in_progress
, symbolP
);
849 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
851 def_symbol_in_progress
= symbolP
;
853 if (SF_GET_FUNCTION (def_symbol_in_progress
)
854 || SF_GET_TAG (def_symbol_in_progress
)
855 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
857 /* For functions, and tags, and static symbols, the symbol
858 *must* be where the debug symbol appears. Move the
859 existing symbol to the current place. */
860 /* If it already is at the end of the symbol list, do nothing */
861 if (def_symbol_in_progress
!= symbol_lastP
)
863 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
864 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
869 if (SF_GET_TAG (def_symbol_in_progress
))
873 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
875 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
876 tag_insert (S_GET_NAME (def_symbol_in_progress
),
877 def_symbol_in_progress
);
880 if (SF_GET_FUNCTION (def_symbol_in_progress
))
882 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
883 set_function (def_symbol_in_progress
);
884 SF_SET_PROCESS (def_symbol_in_progress
);
888 /* That is, if this is the first time we've seen the
890 symbol_table_insert (def_symbol_in_progress
);
891 } /* definition follows debug */
892 } /* Create the line number entry pointing to the function being defined */
894 def_symbol_in_progress
= NULL
;
895 demand_empty_rest_of_line ();
899 obj_coff_dim (ignore
)
900 int ignore ATTRIBUTE_UNUSED
;
904 if (def_symbol_in_progress
== NULL
)
906 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
907 demand_empty_rest_of_line ();
909 } /* if not inside .def/.endef */
911 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
913 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
916 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
917 get_absolute_expression ());
919 switch (*input_line_pointer
)
922 input_line_pointer
++;
926 as_warn (_("badly formed .dim directive ignored"));
927 /* intentional fallthrough */
935 demand_empty_rest_of_line ();
939 obj_coff_line (ignore
)
940 int ignore ATTRIBUTE_UNUSED
;
944 if (def_symbol_in_progress
== NULL
)
946 /* Probably stabs-style line? */
951 this_base
= get_absolute_expression ();
952 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
953 coff_line_base
= this_base
;
955 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
956 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
958 demand_empty_rest_of_line ();
961 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
966 listing_source_line ((unsigned int) this_base
);
972 obj_coff_size (ignore
)
973 int ignore ATTRIBUTE_UNUSED
;
975 if (def_symbol_in_progress
== NULL
)
977 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
978 demand_empty_rest_of_line ();
980 } /* if not inside .def/.endef */
982 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
983 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
984 demand_empty_rest_of_line ();
988 obj_coff_scl (ignore
)
989 int ignore ATTRIBUTE_UNUSED
;
991 if (def_symbol_in_progress
== NULL
)
993 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
994 demand_empty_rest_of_line ();
996 } /* if not inside .def/.endef */
998 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
999 demand_empty_rest_of_line ();
1003 obj_coff_tag (ignore
)
1004 int ignore ATTRIBUTE_UNUSED
;
1009 if (def_symbol_in_progress
== NULL
)
1011 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
1012 demand_empty_rest_of_line ();
1016 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
1017 symbol_name
= input_line_pointer
;
1018 name_end
= get_symbol_end ();
1020 #ifdef tc_canonicalize_symbol_name
1021 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1024 /* Assume that the symbol referred to by .tag is always defined.
1025 This was a bad assumption. I've added find_or_make. xoxorich. */
1026 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
1027 tag_find_or_make (symbol_name
));
1028 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
1030 as_warn (_("tag not found for .tag %s"), symbol_name
);
1033 SF_SET_TAGGED (def_symbol_in_progress
);
1034 *input_line_pointer
= name_end
;
1036 demand_empty_rest_of_line ();
1040 obj_coff_type (ignore
)
1041 int ignore ATTRIBUTE_UNUSED
;
1043 if (def_symbol_in_progress
== NULL
)
1045 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
1046 demand_empty_rest_of_line ();
1048 } /* if not inside .def/.endef */
1050 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
1052 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
1053 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
1055 SF_SET_FUNCTION (def_symbol_in_progress
);
1056 } /* is a function */
1058 demand_empty_rest_of_line ();
1062 obj_coff_val (ignore
)
1063 int ignore ATTRIBUTE_UNUSED
;
1065 if (def_symbol_in_progress
== NULL
)
1067 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
1068 demand_empty_rest_of_line ();
1070 } /* if not inside .def/.endef */
1072 if (is_name_beginner (*input_line_pointer
))
1074 char *symbol_name
= input_line_pointer
;
1075 char name_end
= get_symbol_end ();
1077 #ifdef tc_canonicalize_symbol_name
1078 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
1080 if (!strcmp (symbol_name
, "."))
1082 symbol_set_frag (def_symbol_in_progress
, frag_now
);
1083 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
1084 /* If the .val is != from the .def (e.g. statics) */
1086 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
1090 exp
.X_op
= O_symbol
;
1091 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
1092 exp
.X_op_symbol
= NULL
;
1093 exp
.X_add_number
= 0;
1094 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
1096 /* If the segment is undefined when the forward reference is
1097 resolved, then copy the segment id from the forward
1099 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
1101 /* FIXME: gcc can generate address expressions here in
1102 unusual cases (search for "obscure" in sdbout.c). We
1103 just ignore the offset here, thus generating incorrect
1104 debugging information. We ignore the rest of the line
1107 /* Otherwise, it is the name of a non debug symbol and its value
1108 will be calculated later. */
1109 *input_line_pointer
= name_end
;
1113 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
1114 } /* if symbol based */
1116 demand_empty_rest_of_line ();
1120 coff_obj_read_begin_hook ()
1122 /* These had better be the same. Usually 18 bytes. */
1124 know (sizeof (SYMENT
) == sizeof (AUXENT
));
1125 know (SYMESZ
== AUXESZ
);
1130 symbolS
*coff_last_function
;
1131 static symbolS
*coff_last_bf
;
1134 coff_frob_symbol (symp
, punt
)
1138 static symbolS
*last_tagP
;
1139 static stack
*block_stack
;
1140 static symbolS
*set_end
;
1141 symbolS
*next_set_end
= NULL
;
1143 if (symp
== &abs_symbol
)
1149 if (current_lineno_sym
)
1150 coff_add_linesym ((symbolS
*) 0);
1153 block_stack
= stack_init (512, sizeof (symbolS
*));
1155 if (S_IS_WEAK (symp
))
1158 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1160 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1164 if (!S_IS_DEFINED (symp
)
1165 && !S_IS_WEAK (symp
)
1166 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1167 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1169 if (!SF_GET_DEBUG (symp
))
1172 if (!SF_GET_LOCAL (symp
)
1173 && !SF_GET_STATICS (symp
)
1174 && S_GET_STORAGE_CLASS (symp
) != C_LABEL
1175 && symbol_constant_p(symp
)
1176 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1179 c_symbol_merge (symp
, real
);
1183 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1185 assert (S_GET_VALUE (symp
) == 0);
1186 S_SET_EXTERNAL (symp
);
1188 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1190 if (S_GET_SEGMENT (symp
) == text_section
1191 && symp
!= seg_info (text_section
)->sym
)
1192 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1194 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1196 if (SF_GET_PROCESS (symp
))
1198 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1200 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1201 stack_push (block_stack
, (char *) &symp
);
1205 begin
= *(symbolS
**) stack_pop (block_stack
);
1207 as_warn (_("mismatched .eb"));
1209 next_set_end
= begin
;
1212 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1214 union internal_auxent
*auxp
;
1215 coff_last_function
= symp
;
1216 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1217 S_SET_NUMBER_AUXILIARY (symp
, 1);
1218 auxp
= SYM_AUXENT (symp
);
1219 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1220 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1222 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1224 if (coff_last_function
== 0)
1225 as_fatal (_("C_EFCN symbol out of scope"));
1226 SA_SET_SYM_FSIZE (coff_last_function
,
1227 (long) (S_GET_VALUE (symp
)
1228 - S_GET_VALUE (coff_last_function
)));
1229 next_set_end
= coff_last_function
;
1230 coff_last_function
= 0;
1233 if (S_IS_EXTERNAL (symp
))
1234 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1235 else if (SF_GET_LOCAL (symp
))
1238 if (SF_GET_FUNCTION (symp
))
1239 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1244 /* Double check weak symbols. */
1245 if (S_IS_WEAK (symp
) && S_IS_COMMON (symp
))
1246 as_bad (_("Symbol `%s' can not be both weak and common"),
1249 if (SF_GET_TAG (symp
))
1251 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1252 next_set_end
= last_tagP
;
1255 /* This is pretty horrible, but we have to set *punt correctly in
1256 order to call SA_SET_SYM_ENDNDX correctly. */
1257 if (! symbol_used_in_reloc_p (symp
)
1258 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1259 || (! S_IS_EXTERNAL (symp
)
1260 && ! symbol_get_tc (symp
)->output
1261 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1265 if (set_end
!= (symbolS
*) NULL
1267 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1268 || (S_IS_DEFINED (symp
)
1269 && ! S_IS_COMMON (symp
)
1270 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1272 SA_SET_SYM_ENDNDX (set_end
, symp
);
1276 if (next_set_end
!= NULL
)
1278 if (set_end
!= NULL
)
1279 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1280 S_GET_NAME (set_end
));
1281 set_end
= next_set_end
;
1285 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1286 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1288 if (coff_last_bf
!= NULL
)
1289 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1290 coff_last_bf
= symp
;
1293 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1296 struct line_no
*lptr
;
1299 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1300 for (i
= 0; lptr
; lptr
= lptr
->next
)
1302 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1304 /* We need i entries for line numbers, plus 1 for the first
1305 entry which BFD will override, plus 1 for the last zero
1306 entry (a marker for BFD). */
1307 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1308 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1309 l
[i
+ 1].line_number
= 0;
1310 l
[i
+ 1].u
.sym
= NULL
;
1314 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
/ OCTETS_PER_BYTE
;
1322 coff_adjust_section_syms (abfd
, sec
, x
)
1323 bfd
*abfd ATTRIBUTE_UNUSED
;
1325 PTR x ATTRIBUTE_UNUSED
;
1328 segment_info_type
*seginfo
= seg_info (sec
);
1329 int nlnno
, nrelocs
= 0;
1331 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1332 tc-ppc.c. Do not get confused by it. */
1333 if (seginfo
== NULL
)
1336 if (!strcmp (sec
->name
, ".text"))
1337 nlnno
= coff_n_line_nos
;
1341 /* @@ Hope that none of the fixups expand to more than one reloc
1343 fixS
*fixp
= seginfo
->fix_root
;
1346 if (! fixp
->fx_done
)
1348 fixp
= fixp
->fx_next
;
1351 if (bfd_get_section_size_before_reloc (sec
) == 0
1354 && sec
!= text_section
1355 && sec
!= data_section
1356 && sec
!= bss_section
)
1358 secsym
= section_symbol (sec
);
1359 /* This is an estimate; we'll plug in the real value using
1360 SET_SECTION_RELOCS later */
1361 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1362 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1366 coff_frob_file_after_relocs ()
1368 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1372 * implement the .section pseudo op:
1373 * .section name {, "flags"}
1375 * | +--- optional flags: 'b' for bss
1377 * +-- section name 'l' for lib
1381 * 'd' (apparently m88k for data)
1383 * 'r' for read-only data
1384 * 's' for shared data (PE)
1385 * But if the argument is not a quoted string, treat it as a
1386 * subsegment number.
1390 obj_coff_section (ignore
)
1391 int ignore ATTRIBUTE_UNUSED
;
1393 /* Strip out the section name */
1398 flagword flags
, oldflags
;
1409 section_name
= input_line_pointer
;
1410 c
= get_symbol_end ();
1412 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1413 strcpy (name
, section_name
);
1415 *input_line_pointer
= c
;
1420 flags
= SEC_NO_FLAGS
;
1422 if (*input_line_pointer
== ',')
1424 ++input_line_pointer
;
1426 if (*input_line_pointer
!= '"')
1427 exp
= get_absolute_expression ();
1430 ++input_line_pointer
;
1431 while (*input_line_pointer
!= '"'
1432 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1434 switch (*input_line_pointer
)
1436 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1437 case 'n': flags
&=~ SEC_LOAD
; break;
1438 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1439 case 'w': flags
&=~ SEC_READONLY
; break;
1440 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1441 case 'r': flags
|= SEC_READONLY
; break;
1442 case 's': flags
|= SEC_SHARED
; break;
1444 case 'i': /* STYP_INFO */
1445 case 'l': /* STYP_LIB */
1446 case 'o': /* STYP_OVER */
1447 as_warn (_("unsupported section attribute '%c'"),
1448 *input_line_pointer
);
1452 as_warn(_("unknown section attribute '%c'"),
1453 *input_line_pointer
);
1456 ++input_line_pointer
;
1458 if (*input_line_pointer
== '"')
1459 ++input_line_pointer
;
1463 sec
= subseg_new (name
, (subsegT
) exp
);
1465 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1466 if (oldflags
== SEC_NO_FLAGS
)
1468 /* Set section flags for a new section just created by subseg_new.
1469 Provide a default if no flags were parsed. */
1470 if (flags
== SEC_NO_FLAGS
)
1471 flags
= TC_COFF_SECTION_DEFAULT_ATTRIBUTES
;
1473 #ifdef COFF_LONG_SECTION_NAMES
1474 /* Add SEC_LINK_ONCE and SEC_LINK_DUPLICATES_DISCARD to .gnu.linkonce
1475 sections so adjust_reloc_syms in write.c will correctly handle
1476 relocs which refer to non-local symbols in these sections. */
1477 if (strncmp (name
, ".gnu.linkonce", sizeof (".gnu.linkonce") - 1) == 0)
1478 flags
|= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_DISCARD
;
1481 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1482 as_warn (_("error setting flags for \"%s\": %s"),
1483 bfd_section_name (stdoutput
, sec
),
1484 bfd_errmsg (bfd_get_error ()));
1486 else if (flags
!= SEC_NO_FLAGS
)
1488 /* This section's attributes have already been set. Warn if the
1489 attributes don't match. */
1490 flagword matchflags
= SEC_ALLOC
| SEC_LOAD
| SEC_READONLY
| SEC_CODE
1491 | SEC_DATA
| SEC_SHARED
;
1492 if ((flags
^ oldflags
) & matchflags
)
1493 as_warn (_("Ignoring changed section attributes for %s"), name
);
1496 demand_empty_rest_of_line ();
1500 coff_adjust_symtab ()
1502 if (symbol_rootP
== NULL
1503 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1504 c_dot_file_symbol ("fake");
1508 coff_frob_section (sec
)
1514 bfd_vma size
, n_entries
, mask
;
1515 bfd_vma align_power
= (bfd_vma
)sec
->alignment_power
+ OCTETS_PER_BYTE_POWER
;
1517 /* The COFF back end in BFD requires that all section sizes be
1518 rounded up to multiples of the corresponding section alignments,
1519 supposedly because standard COFF has no other way of encoding alignment
1520 for sections. If your COFF flavor has a different way of encoding
1521 section alignment, then skip this step, as TICOFF does. */
1522 size
= bfd_get_section_size_before_reloc (sec
);
1523 mask
= ((bfd_vma
) 1 << align_power
) - 1;
1524 #if !defined(TICOFF)
1530 new_size
= (size
+ mask
) & ~mask
;
1531 bfd_set_section_size (stdoutput
, sec
, new_size
);
1533 /* If the size had to be rounded up, add some padding in
1534 the last non-empty frag. */
1535 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1536 last
= seg_info (sec
)->frchainP
->frch_last
;
1537 while (fragp
->fr_next
!= last
)
1538 fragp
= fragp
->fr_next
;
1539 last
->fr_address
= size
;
1540 fragp
->fr_offset
+= new_size
- size
;
1544 /* If the section size is non-zero, the section symbol needs an aux
1545 entry associated with it, indicating the size. We don't know
1546 all the values yet; coff_frob_symbol will fill them in later. */
1549 || sec
== text_section
1550 || sec
== data_section
1551 || sec
== bss_section
)
1554 symbolS
*secsym
= section_symbol (sec
);
1556 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1557 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1558 SF_SET_STATICS (secsym
);
1559 SA_SET_SCN_SCNLEN (secsym
, size
);
1562 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1563 #ifndef STAB_SECTION_NAME
1564 #define STAB_SECTION_NAME ".stab"
1566 #ifndef STAB_STRING_SECTION_NAME
1567 #define STAB_STRING_SECTION_NAME ".stabstr"
1569 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1573 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1574 /* size is already rounded up, since other section will be listed first */
1575 size
= bfd_get_section_size_before_reloc (strsec
);
1577 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1579 /* Find first non-empty frag. It should be large enough. */
1580 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1581 while (fragp
&& fragp
->fr_fix
== 0)
1582 fragp
= fragp
->fr_next
;
1583 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1585 /* Store the values. */
1586 p
= fragp
->fr_literal
;
1587 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1588 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1592 obj_coff_init_stab_section (seg
)
1598 unsigned int stroff
;
1600 /* Make space for this first symbol. */
1604 as_where (&file
, (unsigned int *) NULL
);
1605 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1606 strcpy (stabstr_name
, seg
->name
);
1607 strcat (stabstr_name
, "str");
1608 stroff
= get_stab_string_offset (file
, stabstr_name
);
1610 md_number_to_chars (p
, stroff
, 4);
1619 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1627 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1629 printf (_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1630 (unsigned long) symbolP
,
1631 S_GET_NAME(symbolP
),
1632 (long) S_GET_DATA_TYPE(symbolP
),
1633 S_GET_STORAGE_CLASS(symbolP
),
1634 (int) S_GET_SEGMENT(symbolP
));
1640 #else /* not BFD_ASSEMBLER */
1643 /* This is needed because we include internal bfd things. */
1647 #include "libcoff.h"
1650 #include "coff/pe.h"
1653 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1654 that we can stick sections together without causing trouble. */
1656 #define NOP_OPCODE 0x00
1659 /* The zeroes if symbol name is longer than 8 chars */
1660 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1662 #define MIN(a,b) ((a) < (b)? (a) : (b))
1664 /* This vector is used to turn a gas internal segment number into a
1665 section number suitable for insertion into a coff symbol table.
1666 This must correspond to seg_info_off_by_4. */
1668 const short seg_N_TYPE
[] =
1669 { /* in: segT out: N_TYPE bits */
1671 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1672 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1673 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1674 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1675 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1676 C_UNDEF_SECTION
, /* SEG_GOOF */
1677 C_UNDEF_SECTION
, /* SEG_EXPR */
1678 C_DEBUG_SECTION
, /* SEG_DEBUG */
1679 C_NTV_SECTION
, /* SEG_NTV */
1680 C_PTV_SECTION
, /* SEG_PTV */
1681 C_REGISTER_SECTION
, /* SEG_REGISTER */
1684 int function_lineoff
= -1; /* Offset in line#s where the last function
1685 started (the odd entry for line #0) */
1687 /* structure used to keep the filenames which
1688 are too long around so that we can stick them
1689 into the string table */
1690 struct filename_list
1693 struct filename_list
*next
;
1696 static struct filename_list
*filename_list_head
;
1697 static struct filename_list
*filename_list_tail
;
1699 static symbolS
*last_line_symbol
;
1701 /* Add 4 to the real value to get the index and compensate the
1702 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1703 section number into a segment number
1705 static symbolS
*previous_file_symbol
;
1706 void c_symbol_merge ();
1707 static int line_base
;
1709 symbolS
*c_section_symbol ();
1712 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1713 segT this_segment_type
));
1715 static void fixup_mdeps
PARAMS ((fragS
*,
1719 static void fill_section
PARAMS ((bfd
* abfd
,
1723 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1727 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1728 symbolS
* symbol_rootP
));
1730 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1732 static void obj_coff_lcomm
PARAMS ((int));
1733 static void obj_coff_text
PARAMS ((int));
1734 static void obj_coff_data
PARAMS ((int));
1735 void obj_coff_section
PARAMS ((int));
1737 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1739 This array maps a COFF section number into a gas section number.
1740 Because COFF uses negative section numbers, you must add 4 to the
1741 COFF section number when indexing into this array; this is done via
1742 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1745 static const segT seg_info_off_by_4
[] =
1752 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1753 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1754 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1755 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1756 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1757 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1758 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1759 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1772 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1774 static relax_addressT
1775 relax_align (address
, alignment
)
1776 relax_addressT address
;
1779 relax_addressT mask
;
1780 relax_addressT new_address
;
1782 mask
= ~((~0) << alignment
);
1783 new_address
= (address
+ mask
) & (~mask
);
1784 return (new_address
- address
);
1791 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1794 /* calculate the size of the frag chain and fill in the section header
1795 to contain all of it, also fill in the addr of the sections */
1797 size_section (abfd
, idx
)
1798 bfd
*abfd ATTRIBUTE_UNUSED
;
1802 unsigned int size
= 0;
1803 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1806 size
= frag
->fr_address
;
1807 if (frag
->fr_address
!= size
)
1809 fprintf (stderr
, _("Out of step\n"));
1810 size
= frag
->fr_address
;
1813 switch (frag
->fr_type
)
1815 #ifdef TC_COFF_SIZEMACHDEP
1816 case rs_machine_dependent
:
1817 size
+= TC_COFF_SIZEMACHDEP (frag
);
1821 assert (frag
->fr_symbol
== 0);
1824 size
+= frag
->fr_fix
;
1825 size
+= frag
->fr_offset
* frag
->fr_var
;
1833 size
+= frag
->fr_fix
;
1834 off
= relax_align (size
, frag
->fr_offset
);
1835 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1841 BAD_CASE (frag
->fr_type
);
1844 frag
= frag
->fr_next
;
1846 segment_info
[idx
].scnhdr
.s_size
= size
;
1851 count_entries_in_chain (idx
)
1854 unsigned int nrelocs
;
1857 /* Count the relocations */
1858 fixup_ptr
= segment_info
[idx
].fix_root
;
1860 while (fixup_ptr
!= (fixS
*) NULL
)
1862 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1865 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1874 fixup_ptr
= fixup_ptr
->fx_next
;
1881 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1883 /* AUX's ld expects relocations to be sorted */
1885 compare_external_relocs (x
, y
)
1889 struct external_reloc
*a
= (struct external_reloc
*) x
;
1890 struct external_reloc
*b
= (struct external_reloc
*) y
;
1891 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1892 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1893 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1898 /* output all the relocations for a section */
1900 do_relocs_for (abfd
, h
, file_cursor
)
1903 unsigned long *file_cursor
;
1905 unsigned int nrelocs
;
1907 unsigned long reloc_start
= *file_cursor
;
1909 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1911 if (segment_info
[idx
].scnhdr
.s_name
[0])
1913 struct external_reloc
*ext_ptr
;
1914 struct external_reloc
*external_reloc_vec
;
1915 unsigned int external_reloc_size
;
1916 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1917 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1918 nrelocs
= count_entries_in_chain (idx
);
1921 /* Bypass this stuff if no relocs. This also incidentally
1922 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1924 external_reloc_size
= nrelocs
* RELSZ
;
1925 external_reloc_vec
=
1926 (struct external_reloc
*) malloc (external_reloc_size
);
1928 ext_ptr
= external_reloc_vec
;
1930 /* Fill in the internal coff style reloc struct from the
1931 internal fix list. */
1934 struct internal_reloc intr
;
1936 /* Only output some of the relocations */
1937 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1939 #ifdef TC_RELOC_MANGLE
1940 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1945 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1947 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1949 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1951 #ifdef TC_KEEP_FX_OFFSET
1952 intr
.r_offset
= fix_ptr
->fx_offset
;
1957 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1958 && (! S_IS_DEFINED (symbol_ptr
)
1959 || S_IS_COMMON (symbol_ptr
)))
1963 /* We must avoid looping, as that can occur
1964 with a badly written program. */
1965 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1966 if (n
== symbol_ptr
)
1971 /* Turn the segment of the symbol into an offset. */
1974 resolve_symbol_value (symbol_ptr
, 1);
1975 if (! symbol_ptr
->sy_resolved
)
1980 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1981 as_bad_where (file
, line
,
1982 _("unresolved relocation"));
1984 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1985 S_GET_NAME (symbol_ptr
));
1987 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1990 intr
.r_symndx
= dot
->sy_number
;
1994 intr
.r_symndx
= symbol_ptr
->sy_number
;
2004 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2007 #if defined(TC_A29K)
2009 /* The 29k has a special kludge for the high 16 bit
2010 reloc. Two relocations are emited, R_IHIHALF,
2011 and R_IHCONST. The second one doesn't contain a
2012 symbol, but uses the value for offset. */
2014 if (intr
.r_type
== R_IHIHALF
)
2016 /* now emit the second bit */
2017 intr
.r_type
= R_IHCONST
;
2018 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
2019 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
2025 fix_ptr
= fix_ptr
->fx_next
;
2029 /* Sort the reloc table */
2030 qsort ((PTR
) external_reloc_vec
, nrelocs
,
2031 sizeof (struct external_reloc
), compare_external_relocs
);
2034 /* Write out the reloc table */
2035 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
2037 free (external_reloc_vec
);
2039 /* Fill in section header info. */
2040 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
2041 *file_cursor
+= external_reloc_size
;
2042 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
2047 segment_info
[idx
].scnhdr
.s_relptr
= 0;
2051 /* Set relocation_size field in file headers */
2052 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
2055 /* run through a frag chain and write out the data to go with it, fill
2056 in the scnhdrs with the info on the file postions
2059 fill_section (abfd
, h
, file_cursor
)
2061 object_headers
*h ATTRIBUTE_UNUSED
;
2062 unsigned long *file_cursor
;
2066 unsigned int paddr
= 0;
2068 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
2070 unsigned int offset
= 0;
2071 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
2077 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
2084 buffer
= xmalloc (s
->s_size
);
2085 s
->s_scnptr
= *file_cursor
;
2087 know (s
->s_paddr
== paddr
);
2089 if (strcmp (s
->s_name
, ".text") == 0)
2090 s
->s_flags
|= STYP_TEXT
;
2091 else if (strcmp (s
->s_name
, ".data") == 0)
2092 s
->s_flags
|= STYP_DATA
;
2093 else if (strcmp (s
->s_name
, ".bss") == 0)
2096 s
->s_flags
|= STYP_BSS
;
2098 /* @@ Should make the i386 and a29k coff targets define
2099 COFF_NOLOAD_PROBLEM, and have only one test here. */
2102 #ifndef COFF_NOLOAD_PROBLEM
2103 /* Apparently the SVR3 linker (and exec syscall) and UDI
2104 mondfe progrem are confused by noload sections. */
2105 s
->s_flags
|= STYP_NOLOAD
;
2110 else if (strcmp (s
->s_name
, ".lit") == 0)
2111 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
2112 else if (strcmp (s
->s_name
, ".init") == 0)
2113 s
->s_flags
|= STYP_TEXT
;
2114 else if (strcmp (s
->s_name
, ".fini") == 0)
2115 s
->s_flags
|= STYP_TEXT
;
2116 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
2117 s
->s_flags
|= STYP_INFO
;
2121 unsigned int fill_size
;
2122 switch (frag
->fr_type
)
2124 case rs_machine_dependent
:
2127 memcpy (buffer
+ frag
->fr_address
,
2129 (unsigned int) frag
->fr_fix
);
2130 offset
+= frag
->fr_fix
;
2135 assert (frag
->fr_symbol
== 0);
2143 memcpy (buffer
+ frag
->fr_address
,
2145 (unsigned int) frag
->fr_fix
);
2146 offset
+= frag
->fr_fix
;
2149 fill_size
= frag
->fr_var
;
2150 if (fill_size
&& frag
->fr_offset
> 0)
2153 unsigned int off
= frag
->fr_fix
;
2154 for (count
= frag
->fr_offset
; count
; count
--)
2156 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
2158 memcpy (buffer
+ frag
->fr_address
+ off
,
2159 frag
->fr_literal
+ frag
->fr_fix
,
2162 offset
+= fill_size
;
2167 case rs_broken_word
:
2172 frag
= frag
->fr_next
;
2177 if (s
->s_scnptr
!= 0)
2179 bfd_write (buffer
, s
->s_size
, 1, abfd
);
2180 *file_cursor
+= s
->s_size
;
2189 /* Coff file generation & utilities */
2192 coff_header_append (abfd
, h
)
2199 #ifdef COFF_LONG_SECTION_NAMES
2200 unsigned long string_size
= 4;
2203 bfd_seek (abfd
, 0, 0);
2205 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2206 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2207 H_SET_VERSION_STAMP (h
, 0);
2208 H_SET_ENTRY_POINT (h
, 0);
2209 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2210 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2211 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2213 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2214 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2215 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2217 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2219 bfd_write (buffer
, i
, 1, abfd
);
2220 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2222 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2224 if (segment_info
[i
].scnhdr
.s_name
[0])
2228 #ifdef COFF_LONG_SECTION_NAMES
2229 /* Support long section names as found in PE. This code
2230 must coordinate with that in write_object_file and
2232 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2234 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2235 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2236 string_size
+= strlen (segment_info
[i
].name
) + 1;
2240 size
= bfd_coff_swap_scnhdr_out (abfd
,
2241 &(segment_info
[i
].scnhdr
),
2244 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2245 bfd_write (buffer
, size
, 1, abfd
);
2251 symbol_to_chars (abfd
, where
, symbolP
)
2256 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2260 /* Turn any symbols with register attributes into abs symbols */
2261 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2263 S_SET_SEGMENT (symbolP
, absolute_section
);
2265 /* At the same time, relocate all symbols to their output value */
2268 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2269 + S_GET_VALUE (symbolP
));
2271 val
= S_GET_VALUE (symbolP
);
2274 S_SET_VALUE (symbolP
, val
);
2276 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2278 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2281 for (i
= 0; i
< numaux
; i
++)
2283 where
+= bfd_coff_swap_aux_out (abfd
,
2284 &symbolP
->sy_symbol
.ost_auxent
[i
],
2285 S_GET_DATA_TYPE (symbolP
),
2286 S_GET_STORAGE_CLASS (symbolP
),
2294 coff_obj_symbol_new_hook (symbolP
)
2297 char underscore
= 0; /* Symbol has leading _ */
2299 /* Effective symbol */
2300 /* Store the pointer in the offset. */
2301 S_SET_ZEROES (symbolP
, 0L);
2302 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2303 S_SET_STORAGE_CLASS (symbolP
, 0);
2304 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2305 /* Additional information */
2306 symbolP
->sy_symbol
.ost_flags
= 0;
2307 /* Auxiliary entries */
2308 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2310 if (S_IS_STRING (symbolP
))
2311 SF_SET_STRING (symbolP
);
2312 if (!underscore
&& S_IS_LOCAL (symbolP
))
2313 SF_SET_LOCAL (symbolP
);
2317 * Handle .ln directives.
2321 obj_coff_ln (appline
)
2326 if (! appline
&& def_symbol_in_progress
!= NULL
)
2328 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2329 demand_empty_rest_of_line ();
2331 } /* wrong context */
2333 l
= get_absolute_expression ();
2334 c_line_new (0, frag_now_fix (), l
, frag_now
);
2337 new_logical_line ((char *) NULL
, l
- 1);
2347 listing_source_line ((unsigned int) l
);
2352 demand_empty_rest_of_line ();
2358 * Handle .def directives.
2360 * One might ask : why can't we symbol_new if the symbol does not
2361 * already exist and fill it with debug information. Because of
2362 * the C_EFCN special symbol. It would clobber the value of the
2363 * function symbol before we have a chance to notice that it is
2364 * a C_EFCN. And a second reason is that the code is more clear this
2365 * way. (at least I think it is :-).
2369 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2370 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2371 *input_line_pointer == '\t') \
2372 input_line_pointer++;
2376 int what ATTRIBUTE_UNUSED
;
2378 char name_end
; /* Char after the end of name */
2379 char *symbol_name
; /* Name of the debug symbol */
2380 char *symbol_name_copy
; /* Temporary copy of the name */
2381 unsigned int symbol_name_length
;
2383 if (def_symbol_in_progress
!= NULL
)
2385 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2386 demand_empty_rest_of_line ();
2388 } /* if not inside .def/.endef */
2390 SKIP_WHITESPACES ();
2392 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2393 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2395 symbol_name
= input_line_pointer
;
2396 name_end
= get_symbol_end ();
2397 symbol_name_length
= strlen (symbol_name
);
2398 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2399 strcpy (symbol_name_copy
, symbol_name
);
2400 #ifdef tc_canonicalize_symbol_name
2401 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2404 /* Initialize the new symbol */
2405 #ifdef STRIP_UNDERSCORE
2406 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2407 ? symbol_name_copy
+ 1
2408 : symbol_name_copy
));
2409 #else /* STRIP_UNDERSCORE */
2410 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2411 #endif /* STRIP_UNDERSCORE */
2412 /* free(symbol_name_copy); */
2413 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2414 def_symbol_in_progress
->sy_number
= ~0;
2415 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2416 S_SET_VALUE (def_symbol_in_progress
, 0);
2418 if (S_IS_STRING (def_symbol_in_progress
))
2419 SF_SET_STRING (def_symbol_in_progress
);
2421 *input_line_pointer
= name_end
;
2423 demand_empty_rest_of_line ();
2426 unsigned int dim_index
;
2429 obj_coff_endef (ignore
)
2430 int ignore ATTRIBUTE_UNUSED
;
2432 symbolS
*symbolP
= 0;
2433 /* DIM BUG FIX sac@cygnus.com */
2435 if (def_symbol_in_progress
== NULL
)
2437 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2438 demand_empty_rest_of_line ();
2440 } /* if not inside .def/.endef */
2442 /* Set the section number according to storage class. */
2443 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2448 SF_SET_TAG (def_symbol_in_progress
);
2449 /* intentional fallthrough */
2452 SF_SET_DEBUG (def_symbol_in_progress
);
2453 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2457 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2458 /* intentional fallthrough */
2460 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2461 /* intentional fallthrough */
2463 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2465 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2467 if (function_lineoff
< 0)
2469 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2470 } /* missing function symbol */
2471 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2473 SF_SET_PROCESS (last_line_symbol
);
2474 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2475 SF_SET_PROCESS (def_symbol_in_progress
);
2476 function_lineoff
= -1;
2478 /* Value is always set to . */
2479 def_symbol_in_progress
->sy_frag
= frag_now
;
2480 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2485 #endif /* C_AUTOARG */
2495 SF_SET_DEBUG (def_symbol_in_progress
);
2496 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2506 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2512 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2514 } /* switch on storage class */
2516 /* Now that we have built a debug symbol, try to find if we should
2517 merge with an existing symbol or not. If a symbol is C_EFCN or
2518 absolute_section or untagged SEG_DEBUG it never merges. We also
2519 don't merge labels, which are in a different namespace, nor
2520 symbols which have not yet been defined since they are typically
2521 unique, nor do we merge tags with non-tags. */
2523 /* Two cases for functions. Either debug followed by definition or
2524 definition followed by debug. For definition first, we will
2525 merge the debug symbol into the definition. For debug first, the
2526 lineno entry MUST point to the definition function or else it
2527 will point off into space when crawl_symbols() merges the debug
2528 symbol into the real symbol. Therefor, let's presume the debug
2529 symbol is a real function reference. */
2531 /* FIXME-SOON If for some reason the definition label/symbol is
2532 never seen, this will probably leave an undefined symbol at link
2535 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2536 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2537 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2538 && !SF_GET_TAG (def_symbol_in_progress
))
2539 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2540 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2541 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2542 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2544 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2549 /* This symbol already exists, merge the newly created symbol
2550 into the old one. This is not mandatory. The linker can
2551 handle duplicate symbols correctly. But I guess that it save
2552 a *lot* of space if the assembly file defines a lot of
2555 /* The debug entry (def_symbol_in_progress) is merged into the
2556 previous definition. */
2558 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2559 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2560 def_symbol_in_progress
= symbolP
;
2562 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2563 || SF_GET_TAG (def_symbol_in_progress
)
2564 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2566 /* For functions, and tags, and static symbols, the symbol
2567 *must* be where the debug symbol appears. Move the
2568 existing symbol to the current place. */
2569 /* If it already is at the end of the symbol list, do nothing */
2570 if (def_symbol_in_progress
!= symbol_lastP
)
2572 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2574 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2575 &symbol_rootP
, &symbol_lastP
);
2576 } /* if not already in place */
2578 } /* normal or mergable */
2580 if (SF_GET_TAG (def_symbol_in_progress
))
2584 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2586 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2587 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2588 def_symbol_in_progress
);
2591 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2593 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2595 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2597 SF_SET_PROCESS (def_symbol_in_progress
);
2599 if (symbolP
== NULL
)
2601 /* That is, if this is the first time we've seen the
2603 symbol_table_insert (def_symbol_in_progress
);
2604 } /* definition follows debug */
2605 } /* Create the line number entry pointing to the function being defined */
2607 def_symbol_in_progress
= NULL
;
2608 demand_empty_rest_of_line ();
2612 obj_coff_dim (ignore
)
2613 int ignore ATTRIBUTE_UNUSED
;
2617 if (def_symbol_in_progress
== NULL
)
2619 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2620 demand_empty_rest_of_line ();
2622 } /* if not inside .def/.endef */
2624 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2626 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2628 SKIP_WHITESPACES ();
2629 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2630 get_absolute_expression ());
2632 switch (*input_line_pointer
)
2635 input_line_pointer
++;
2639 as_warn (_("badly formed .dim directive ignored"));
2640 /* intentional fallthrough */
2648 demand_empty_rest_of_line ();
2652 obj_coff_line (ignore
)
2653 int ignore ATTRIBUTE_UNUSED
;
2658 if (def_symbol_in_progress
== NULL
)
2664 name
= S_GET_NAME (def_symbol_in_progress
);
2665 this_base
= get_absolute_expression ();
2667 /* Only .bf symbols indicate the use of a new base line number; the
2668 line numbers associated with .ef, .bb, .eb are relative to the
2669 start of the containing function. */
2670 if (!strcmp (".bf", name
))
2672 #if 0 /* XXX Can we ever have line numbers going backwards? */
2673 if (this_base
> line_base
)
2676 line_base
= this_base
;
2684 listing_source_line ((unsigned int) line_base
);
2690 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2691 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2693 demand_empty_rest_of_line ();
2697 obj_coff_size (ignore
)
2698 int ignore ATTRIBUTE_UNUSED
;
2700 if (def_symbol_in_progress
== NULL
)
2702 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2703 demand_empty_rest_of_line ();
2705 } /* if not inside .def/.endef */
2707 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2708 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2709 demand_empty_rest_of_line ();
2713 obj_coff_scl (ignore
)
2714 int ignore ATTRIBUTE_UNUSED
;
2716 if (def_symbol_in_progress
== NULL
)
2718 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2719 demand_empty_rest_of_line ();
2721 } /* if not inside .def/.endef */
2723 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2724 demand_empty_rest_of_line ();
2728 obj_coff_tag (ignore
)
2729 int ignore ATTRIBUTE_UNUSED
;
2734 if (def_symbol_in_progress
== NULL
)
2736 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2737 demand_empty_rest_of_line ();
2741 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2742 symbol_name
= input_line_pointer
;
2743 name_end
= get_symbol_end ();
2744 #ifdef tc_canonicalize_symbol_name
2745 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2748 /* Assume that the symbol referred to by .tag is always defined.
2749 This was a bad assumption. I've added find_or_make. xoxorich. */
2750 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2751 (long) tag_find_or_make (symbol_name
));
2752 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2754 as_warn (_("tag not found for .tag %s"), symbol_name
);
2757 SF_SET_TAGGED (def_symbol_in_progress
);
2758 *input_line_pointer
= name_end
;
2760 demand_empty_rest_of_line ();
2764 obj_coff_type (ignore
)
2765 int ignore ATTRIBUTE_UNUSED
;
2767 if (def_symbol_in_progress
== NULL
)
2769 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2770 demand_empty_rest_of_line ();
2772 } /* if not inside .def/.endef */
2774 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2776 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2777 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2779 SF_SET_FUNCTION (def_symbol_in_progress
);
2780 } /* is a function */
2782 demand_empty_rest_of_line ();
2786 obj_coff_val (ignore
)
2787 int ignore ATTRIBUTE_UNUSED
;
2789 if (def_symbol_in_progress
== NULL
)
2791 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2792 demand_empty_rest_of_line ();
2794 } /* if not inside .def/.endef */
2796 if (is_name_beginner (*input_line_pointer
))
2798 char *symbol_name
= input_line_pointer
;
2799 char name_end
= get_symbol_end ();
2801 #ifdef tc_canonicalize_symbol_name
2802 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2805 if (!strcmp (symbol_name
, "."))
2807 def_symbol_in_progress
->sy_frag
= frag_now
;
2808 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2809 /* If the .val is != from the .def (e.g. statics) */
2811 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2813 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2814 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2815 symbol_find_or_make (symbol_name
);
2816 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2817 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2819 /* If the segment is undefined when the forward reference is
2820 resolved, then copy the segment id from the forward
2822 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2824 /* FIXME: gcc can generate address expressions here in
2825 unusual cases (search for "obscure" in sdbout.c). We
2826 just ignore the offset here, thus generating incorrect
2827 debugging information. We ignore the rest of the line
2830 /* Otherwise, it is the name of a non debug symbol and
2831 its value will be calculated later. */
2832 *input_line_pointer
= name_end
;
2834 /* FIXME: this is to avoid an error message in the
2835 FIXME case mentioned just above. */
2836 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2837 ++input_line_pointer
;
2841 S_SET_VALUE (def_symbol_in_progress
,
2842 (valueT
) get_absolute_expression ());
2843 } /* if symbol based */
2845 demand_empty_rest_of_line ();
2850 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2851 read.c, which then calls this object file format specific routine. */
2854 obj_coff_pe_handle_link_once (type
)
2855 enum linkonce_type type
;
2857 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2859 /* We store the type in the seg_info structure, and use it to set up
2860 the auxiliary entry for the section symbol in c_section_symbol. */
2861 seg_info (now_seg
)->linkonce
= type
;
2867 coff_obj_read_begin_hook ()
2869 /* These had better be the same. Usually 18 bytes. */
2871 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2872 know (SYMESZ
== AUXESZ
);
2877 /* This function runs through the symbol table and puts all the
2878 externals onto another chain */
2880 /* The chain of globals. */
2881 symbolS
*symbol_globalP
;
2882 symbolS
*symbol_global_lastP
;
2884 /* The chain of externals */
2885 symbolS
*symbol_externP
;
2886 symbolS
*symbol_extern_lastP
;
2889 symbolS
*last_functionP
;
2890 static symbolS
*last_bfP
;
2897 unsigned int symbol_number
= 0;
2898 unsigned int last_file_symno
= 0;
2900 struct filename_list
*filename_list_scan
= filename_list_head
;
2902 for (symbolP
= symbol_rootP
;
2904 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2906 if (symbolP
->sy_mri_common
)
2908 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2910 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2912 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2913 as_bad (_("%s: global symbols not supported in common sections"),
2914 S_GET_NAME (symbolP
));
2915 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2919 if (!SF_GET_DEBUG (symbolP
))
2921 /* Debug symbols do not need all this rubbish */
2922 symbolS
*real_symbolP
;
2924 /* L* and C_EFCN symbols never merge. */
2925 if (!SF_GET_LOCAL (symbolP
)
2926 && !SF_GET_STATICS (symbolP
)
2927 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2928 && symbolP
->sy_value
.X_op
== O_constant
2929 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2930 && real_symbolP
!= symbolP
)
2932 /* FIXME-SOON: where do dups come from?
2933 Maybe tag references before definitions? xoxorich. */
2934 /* Move the debug data from the debug symbol to the
2935 real symbol. Do NOT do the oposite (i.e. move from
2936 real symbol to debug symbol and remove real symbol from the
2937 list.) Because some pointers refer to the real symbol
2938 whereas no pointers refer to the debug symbol. */
2939 c_symbol_merge (symbolP
, real_symbolP
);
2940 /* Replace the current symbol by the real one */
2941 /* The symbols will never be the last or the first
2942 because : 1st symbol is .file and 3 last symbols are
2943 .text, .data, .bss */
2944 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2945 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2946 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2947 symbolP
= real_symbolP
;
2948 } /* if not local but dup'd */
2950 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2952 S_SET_SEGMENT (symbolP
, SEG_E0
);
2953 } /* push data into text */
2955 resolve_symbol_value (symbolP
, 1);
2957 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2959 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2961 S_SET_EXTERNAL (symbolP
);
2963 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2965 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2969 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2973 /* Mainly to speed up if not -g */
2974 if (SF_GET_PROCESS (symbolP
))
2976 /* Handle the nested blocks auxiliary info. */
2977 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2979 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2980 stack_push (block_stack
, (char *) &symbolP
);
2983 register symbolS
*begin_symbolP
;
2984 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2985 if (begin_symbolP
== (symbolS
*) 0)
2986 as_warn (_("mismatched .eb"));
2988 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2991 /* If we are able to identify the type of a function, and we
2992 are out of a function (last_functionP == 0) then, the
2993 function symbol will be associated with an auxiliary
2995 if (last_functionP
== (symbolS
*) 0 &&
2996 SF_GET_FUNCTION (symbolP
))
2998 last_functionP
= symbolP
;
3000 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
3002 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3003 } /* make it at least 1 */
3005 /* Clobber possible stale .dim information. */
3007 /* Iffed out by steve - this fries the lnnoptr info too */
3008 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
3009 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
3012 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
3014 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
3016 if (last_bfP
!= NULL
)
3017 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
3021 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
3023 /* I don't even know if this is needed for sdb. But
3024 the standard assembler generates it, so... */
3025 if (last_functionP
== (symbolS
*) 0)
3026 as_fatal (_("C_EFCN symbol out of scope"));
3027 SA_SET_SYM_FSIZE (last_functionP
,
3028 (long) (S_GET_VALUE (symbolP
) -
3029 S_GET_VALUE (last_functionP
)));
3030 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
3031 last_functionP
= (symbolS
*) 0;
3035 else if (SF_GET_TAG (symbolP
))
3037 /* First descriptor of a structure must point to
3038 the first slot after the structure description. */
3039 last_tagP
= symbolP
;
3042 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
3044 /* +2 take in account the current symbol */
3045 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
3047 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
3049 /* If the filename was too long to fit in the
3050 auxent, put it in the string table */
3051 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3052 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3054 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
3055 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
3056 filename_list_scan
= filename_list_scan
->next
;
3058 if (S_GET_VALUE (symbolP
))
3060 S_SET_VALUE (symbolP
, last_file_symno
);
3061 last_file_symno
= symbol_number
;
3062 } /* no one points at the first .file symbol */
3063 } /* if debug or tag or eos or file */
3065 #ifdef tc_frob_coff_symbol
3066 tc_frob_coff_symbol (symbolP
);
3069 /* We must put the external symbols apart. The loader
3070 does not bomb if we do not. But the references in
3071 the endndx field for a .bb symbol are not corrected
3072 if an external symbol is removed between .bb and .be.
3073 I.e in the following case :
3074 [20] .bb endndx = 22
3077 ld will move the symbol 21 to the end of the list but
3078 endndx will still be 22 instead of 21. */
3080 if (SF_GET_LOCAL (symbolP
))
3082 /* remove C_EFCN and LOCAL (L...) symbols */
3083 /* next pointer remains valid */
3084 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3087 else if (symbolP
->sy_value
.X_op
== O_symbol
3088 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
3090 /* Skip symbols which were equated to undefined or common
3092 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3094 else if (!S_IS_DEFINED (symbolP
)
3095 && !S_IS_DEBUG (symbolP
)
3096 && !SF_GET_STATICS (symbolP
)
3097 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3099 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3101 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
3103 /* if external, Remove from the list */
3104 symbolS
*hold
= symbol_previous (symbolP
);
3106 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3107 symbol_clear_list_pointers (symbolP
);
3108 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
3111 else if (! S_IS_DEBUG (symbolP
)
3112 && ! SF_GET_STATICS (symbolP
)
3113 && ! SF_GET_FUNCTION (symbolP
)
3114 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
3116 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
3118 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
3120 symbolS
*hold
= symbol_previous (symbolP
);
3122 /* The O'Reilly COFF book says that defined global symbols
3123 come at the end of the symbol table, just before
3124 undefined global symbols. */
3126 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3127 symbol_clear_list_pointers (symbolP
);
3128 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
3129 &symbol_global_lastP
);
3134 if (SF_GET_STRING (symbolP
))
3136 symbolP
->sy_name_offset
= string_byte_count
;
3137 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
3141 symbolP
->sy_name_offset
= 0;
3142 } /* fix "long" names */
3144 symbolP
->sy_number
= symbol_number
;
3145 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3146 } /* if local symbol */
3147 } /* traverse the symbol list */
3148 return symbol_number
;
3153 glue_symbols (head
, tail
)
3157 unsigned int symbol_number
= 0;
3159 while (*head
!= NULL
)
3161 symbolS
*tmp
= *head
;
3164 symbol_remove (tmp
, head
, tail
);
3165 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
3168 if (SF_GET_STRING (tmp
))
3170 tmp
->sy_name_offset
= string_byte_count
;
3171 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
3175 tmp
->sy_name_offset
= 0;
3176 } /* fix "long" names */
3178 tmp
->sy_number
= symbol_number
;
3179 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
3180 } /* append the entire extern chain */
3182 return symbol_number
;
3188 unsigned int symbol_number
= 0;
3191 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3193 symbolP
->sy_number
= symbol_number
;
3195 if (SF_GET_TAGGED (symbolP
))
3199 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3202 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3205 return symbol_number
;
3209 crawl_symbols (h
, abfd
)
3211 bfd
*abfd ATTRIBUTE_UNUSED
;
3215 /* Initialize the stack used to keep track of the matching .bb .be */
3217 block_stack
= stack_init (512, sizeof (symbolS
*));
3219 /* The symbol list should be ordered according to the following sequence
3222 * . debug entries for functions
3223 * . fake symbols for the sections, including .text .data and .bss
3225 * . undefined symbols
3226 * But this is not mandatory. The only important point is to put the
3227 * undefined symbols at the end of the list.
3230 /* Is there a .file symbol ? If not insert one at the beginning. */
3231 if (symbol_rootP
== NULL
3232 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3234 c_dot_file_symbol ("fake");
3238 * Build up static symbols for the sections, they are filled in later
3241 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3242 if (segment_info
[i
].scnhdr
.s_name
[0])
3243 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3246 /* Take all the externals out and put them into another chain */
3247 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3248 /* Take the externals and glue them onto the end.*/
3249 H_SET_SYMBOL_TABLE_SIZE (h
,
3250 (H_GET_SYMBOL_COUNT (h
)
3251 + glue_symbols (&symbol_globalP
,
3252 &symbol_global_lastP
)
3253 + glue_symbols (&symbol_externP
,
3254 &symbol_extern_lastP
)));
3256 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3257 know (symbol_globalP
== NULL
);
3258 know (symbol_global_lastP
== NULL
);
3259 know (symbol_externP
== NULL
);
3260 know (symbol_extern_lastP
== NULL
);
3264 * Find strings by crawling along symbol table chain.
3272 struct filename_list
*filename_list_scan
= filename_list_head
;
3274 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3275 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3278 #ifdef COFF_LONG_SECTION_NAMES
3279 /* Support long section names as found in PE. This code must
3280 coordinate with that in coff_header_append and write_object_file. */
3284 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3286 if (segment_info
[i
].scnhdr
.s_name
[0]
3287 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3291 size
= strlen (segment_info
[i
].name
) + 1;
3292 memcpy (where
, segment_info
[i
].name
, size
);
3297 #endif /* COFF_LONG_SECTION_NAMES */
3299 for (symbolP
= symbol_rootP
;
3301 symbolP
= symbol_next (symbolP
))
3305 if (SF_GET_STRING (symbolP
))
3307 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3308 memcpy (where
, S_GET_NAME (symbolP
), size
);
3311 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3312 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3313 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3315 size
= strlen (filename_list_scan
->filename
) + 1;
3316 memcpy (where
, filename_list_scan
->filename
, size
);
3317 filename_list_scan
= filename_list_scan
->next
;
3324 do_linenos_for (abfd
, h
, file_cursor
)
3327 unsigned long *file_cursor
;
3330 unsigned long start
= *file_cursor
;
3332 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3334 segment_info_type
*s
= segment_info
+ idx
;
3336 if (s
->scnhdr
.s_nlnno
!= 0)
3338 struct lineno_list
*line_ptr
;
3340 struct external_lineno
*buffer
=
3341 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3343 struct external_lineno
*dst
= buffer
;
3345 /* Run through the table we've built and turn it into its external
3346 form, take this chance to remove duplicates */
3348 for (line_ptr
= s
->lineno_list_head
;
3349 line_ptr
!= (struct lineno_list
*) NULL
;
3350 line_ptr
= line_ptr
->next
)
3353 if (line_ptr
->line
.l_lnno
== 0)
3355 /* Turn a pointer to a symbol into the symbols' index */
3356 line_ptr
->line
.l_addr
.l_symndx
=
3357 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3361 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3364 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3369 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3371 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3374 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3377 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3380 /* Now we run through the list of frag chains in a segment and
3381 make all the subsegment frags appear at the end of the
3382 list, as if the seg 0 was extra long */
3389 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3391 frchainS
*head
= segment_info
[i
].frchainP
;
3393 fragS
*prev_frag
= &dummy
;
3395 while (head
&& head
->frch_seg
== i
)
3397 prev_frag
->fr_next
= head
->frch_root
;
3398 prev_frag
= head
->frch_last
;
3399 head
= head
->frch_next
;
3401 prev_frag
->fr_next
= 0;
3405 unsigned long machine
;
3408 write_object_file ()
3412 struct frchain
*frchain_ptr
;
3414 object_headers headers
;
3415 unsigned long file_cursor
;
3418 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3422 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3423 exit (EXIT_FAILURE
);
3425 bfd_set_format (abfd
, bfd_object
);
3426 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3428 string_byte_count
= 4;
3430 for (frchain_ptr
= frchain_root
;
3431 frchain_ptr
!= (struct frchain
*) NULL
;
3432 frchain_ptr
= frchain_ptr
->frch_next
)
3434 /* Run through all the sub-segments and align them up. Also
3435 close any open frags. We tack a .fill onto the end of the
3436 frag chain so that any .align's size can be worked by looking
3437 at the next frag. */
3439 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3441 #ifndef SUB_SEGMENT_ALIGN
3442 #define SUB_SEGMENT_ALIGN(SEG) 1
3445 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3448 if (subseg_text_p (now_seg
))
3449 frag_align_code (SUB_SEGMENT_ALIGN (now_seg
), 0);
3451 frag_align (SUB_SEGMENT_ALIGN (now_seg
), 0, 0);
3457 frag_wane (frag_now
);
3458 frag_now
->fr_fix
= 0;
3459 know (frag_now
->fr_next
== NULL
);
3464 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3466 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3469 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3471 /* Find out how big the sections are, and set the addresses. */
3473 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3477 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3478 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3480 if (segment_info
[i
].scnhdr
.s_name
[0])
3482 H_SET_NUMBER_OF_SECTIONS (&headers
,
3483 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3485 #ifdef COFF_LONG_SECTION_NAMES
3486 /* Support long section names as found in PE. This code
3487 must coordinate with that in coff_header_append and
3492 len
= strlen (segment_info
[i
].name
);
3494 string_byte_count
+= len
+ 1;
3496 #endif /* COFF_LONG_SECTION_NAMES */
3499 size
= size_section (abfd
, (unsigned int) i
);
3502 /* I think the section alignment is only used on the i960; the
3503 i960 needs it, and it should do no harm on other targets. */
3504 #ifdef ALIGNMENT_IN_S_FLAGS
3505 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3507 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3511 H_SET_TEXT_SIZE (&headers
, size
);
3512 else if (i
== SEG_E1
)
3513 H_SET_DATA_SIZE (&headers
, size
);
3514 else if (i
== SEG_E2
)
3515 H_SET_BSS_SIZE (&headers
, size
);
3518 /* Turn the gas native symbol table shape into a coff symbol table */
3519 crawl_symbols (&headers
, abfd
);
3521 if (string_byte_count
== 4)
3522 string_byte_count
= 0;
3524 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3530 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3532 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3533 fixup_segment (&segment_info
[i
], i
);
3536 /* Look for ".stab" segments and fill in their initial symbols
3538 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3540 name
= segment_info
[i
].name
;
3543 && strncmp (".stab", name
, 5) == 0
3544 && strncmp (".stabstr", name
, 8) != 0)
3545 adjust_stab_section (abfd
, i
);
3548 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3550 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3552 /* Plant the data */
3554 fill_section (abfd
, &headers
, &file_cursor
);
3556 do_relocs_for (abfd
, &headers
, &file_cursor
);
3558 do_linenos_for (abfd
, &headers
, &file_cursor
);
3560 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3561 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3562 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3564 H_SET_TIME_STAMP (&headers
, 0);
3566 #ifdef TC_COFF_SET_MACHINE
3567 TC_COFF_SET_MACHINE (&headers
);
3571 #define COFF_FLAGS 0
3574 #ifdef KEEP_RELOC_INFO
3575 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3576 COFF_FLAGS
| coff_flags
));
3578 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3579 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3580 COFF_FLAGS
| coff_flags
));
3584 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3585 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3587 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3588 w_symbols (abfd
, buffer1
, symbol_rootP
);
3589 if (string_byte_count
> 0)
3590 w_strings (buffer1
+ symtable_size
);
3591 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3595 coff_header_append (abfd
, &headers
);
3597 /* Recent changes to write need this, but where it should
3598 go is up to Ken.. */
3599 if (bfd_close_all_done (abfd
) == false)
3600 as_fatal (_("Can't close %s: %s"), out_file_name
,
3601 bfd_errmsg (bfd_get_error ()));
3604 extern bfd
*stdoutput
;
3611 /* Add a new segment. This is called from subseg_new via the
3612 obj_new_segment macro. */
3615 obj_coff_add_segment (name
)
3620 #ifndef COFF_LONG_SECTION_NAMES
3621 char buf
[SCNNMLEN
+ 1];
3623 strncpy (buf
, name
, SCNNMLEN
);
3624 buf
[SCNNMLEN
] = '\0';
3628 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3629 if (strcmp (name
, segment_info
[i
].name
) == 0)
3634 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3638 /* Add a new section. */
3639 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3640 sizeof (segment_info
[i
].scnhdr
.s_name
));
3641 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3642 segment_info
[i
].name
= xstrdup (name
);
3648 * implement the .section pseudo op:
3649 * .section name {, "flags"}
3651 * | +--- optional flags: 'b' for bss
3653 * +-- section name 'l' for lib
3657 * 'd' (apparently m88k for data)
3659 * 'r' for read-only data
3660 * But if the argument is not a quoted string, treat it as a
3661 * subsegment number.
3665 obj_coff_section (ignore
)
3666 int ignore ATTRIBUTE_UNUSED
;
3668 /* Strip out the section name */
3669 char *section_name
, *name
;
3682 else if (type
== 'D')
3684 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3689 section_name
= input_line_pointer
;
3690 c
= get_symbol_end ();
3692 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3693 strcpy (name
, section_name
);
3695 *input_line_pointer
= c
;
3701 if (*input_line_pointer
== ',')
3703 ++input_line_pointer
;
3706 if (*input_line_pointer
!= '"')
3707 exp
= get_absolute_expression ();
3710 ++input_line_pointer
;
3711 while (*input_line_pointer
!= '"'
3712 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3714 switch (*input_line_pointer
)
3716 case 'b': flags
|= STYP_BSS
; break;
3717 case 'i': flags
|= STYP_INFO
; break;
3718 case 'l': flags
|= STYP_LIB
; break;
3719 case 'n': flags
|= STYP_NOLOAD
; break;
3720 case 'o': flags
|= STYP_OVER
; break;
3722 case 'w': flags
|= STYP_DATA
; break;
3723 case 'x': flags
|= STYP_TEXT
; break;
3724 case 'r': flags
|= STYP_LIT
; break;
3726 as_warn(_("unknown section attribute '%c'"),
3727 *input_line_pointer
);
3730 ++input_line_pointer
;
3732 if (*input_line_pointer
== '"')
3733 ++input_line_pointer
;
3737 subseg_new (name
, (subsegT
) exp
);
3739 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3741 demand_empty_rest_of_line ();
3745 obj_coff_text (ignore
)
3746 int ignore ATTRIBUTE_UNUSED
;
3748 subseg_new (".text", get_absolute_expression ());
3752 obj_coff_data (ignore
)
3753 int ignore ATTRIBUTE_UNUSED
;
3755 if (flag_readonly_data_in_text
)
3756 subseg_new (".text", get_absolute_expression () + 1000);
3758 subseg_new (".data", get_absolute_expression ());
3762 obj_coff_ident (ignore
)
3763 int ignore ATTRIBUTE_UNUSED
;
3765 segT current_seg
= now_seg
; /* save current seg */
3766 subsegT current_subseg
= now_subseg
;
3767 subseg_new (".comment", 0); /* .comment seg */
3768 stringer (1); /* read string */
3769 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3773 c_symbol_merge (debug
, normal
)
3777 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3778 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3780 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3782 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3783 } /* take the most we have */
3785 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3787 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3788 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3789 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3790 } /* Move all the auxiliary information */
3792 /* Move the debug flags. */
3793 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3794 } /* c_symbol_merge() */
3797 c_line_new (symbol
, paddr
, line_number
, frag
)
3803 struct lineno_list
*new_line
=
3804 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3806 segment_info_type
*s
= segment_info
+ now_seg
;
3807 new_line
->line
.l_lnno
= line_number
;
3809 if (line_number
== 0)
3811 last_line_symbol
= symbol
;
3812 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3816 new_line
->line
.l_addr
.l_paddr
= paddr
;
3819 new_line
->frag
= (char *) frag
;
3820 new_line
->next
= (struct lineno_list
*) NULL
;
3822 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3824 s
->lineno_list_head
= new_line
;
3828 s
->lineno_list_tail
->next
= new_line
;
3830 s
->lineno_list_tail
= new_line
;
3831 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3835 c_dot_file_symbol (filename
)
3840 symbolP
= symbol_new (".file",
3843 &zero_address_frag
);
3845 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3846 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3848 if (strlen (filename
) > FILNMLEN
)
3850 /* Filename is too long to fit into an auxent,
3851 we stick it into the string table instead. We keep
3852 a linked list of the filenames we find so we can emit
3854 struct filename_list
*f
= ((struct filename_list
*)
3855 xmalloc (sizeof (struct filename_list
)));
3857 f
->filename
= filename
;
3860 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3861 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3863 if (filename_list_tail
)
3864 filename_list_tail
->next
= f
;
3866 filename_list_head
= f
;
3867 filename_list_tail
= f
;
3871 SA_SET_FILE_FNAME (symbolP
, filename
);
3878 listing_source_file (filename
);
3884 SF_SET_DEBUG (symbolP
);
3885 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3887 previous_file_symbol
= symbolP
;
3889 /* Make sure that the symbol is first on the symbol chain */
3890 if (symbol_rootP
!= symbolP
)
3892 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3893 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3895 } /* c_dot_file_symbol() */
3898 * Build a 'section static' symbol.
3902 c_section_symbol (name
, idx
)
3908 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3909 if (symbolP
== NULL
)
3910 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3913 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3914 S_SET_SEGMENT (symbolP
, idx
);
3915 symbolP
->sy_frag
= &zero_address_frag
;
3918 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3919 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3921 SF_SET_STATICS (symbolP
);
3924 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3925 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3926 SF_CLEAR_LOCAL (symbolP
);
3929 /* If the .linkonce pseudo-op was used for this section, we must
3930 store the information in the auxiliary entry for the section
3932 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3936 switch (segment_info
[idx
].linkonce
)
3940 case LINKONCE_DISCARD
:
3941 type
= IMAGE_COMDAT_SELECT_ANY
;
3943 case LINKONCE_ONE_ONLY
:
3944 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3946 case LINKONCE_SAME_SIZE
:
3947 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3949 case LINKONCE_SAME_CONTENTS
:
3950 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3954 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3959 } /* c_section_symbol() */
3962 w_symbols (abfd
, where
, symbol_rootP
)
3965 symbolS
* symbol_rootP
;
3970 /* First fill in those values we have only just worked out */
3971 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3973 symbolP
= segment_info
[i
].dot
;
3976 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3977 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3978 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3983 * Emit all symbols left in the symbol chain.
3985 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3987 /* Used to save the offset of the name. It is used to point
3988 to the string in memory but must be a file offset. */
3989 register char *temp
;
3991 /* We can't fix the lnnoptr field in yank_symbols with the other
3992 adjustments, because we have to wait until we know where they
3994 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3996 SA_GET_SYM_LNNOPTR (symbolP
) +=
3997 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
4000 tc_coff_symbol_emit_hook (symbolP
);
4002 temp
= S_GET_NAME (symbolP
);
4003 if (SF_GET_STRING (symbolP
))
4005 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
4006 S_SET_ZEROES (symbolP
, 0);
4010 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
4011 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
4013 where
= symbol_to_chars (abfd
, where
, symbolP
);
4014 S_SET_NAME (symbolP
, temp
);
4020 obj_coff_lcomm (ignore
)
4021 int ignore ATTRIBUTE_UNUSED
;
4033 name
= input_line_pointer
;
4035 c
= get_symbol_end ();
4036 p
= input_line_pointer
;
4039 if (*input_line_pointer
!= ',')
4041 as_bad (_("Expected comma after name"));
4042 ignore_rest_of_line ();
4045 if (*input_line_pointer
== '\n')
4047 as_bad (_("Missing size expression"));
4050 input_line_pointer
++;
4051 if ((temp
= get_absolute_expression ()) < 0)
4053 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
4054 ignore_rest_of_line ();
4059 symbolP
= symbol_find_or_make(name
);
4061 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
4062 S_GET_VALUE(symbolP
) == 0)
4067 segT current_seg
= now_seg
; /* save current seg */
4068 subsegT current_subseg
= now_subseg
;
4070 subseg_set (SEG_E2
, 1);
4071 symbolP
->sy_frag
= frag_now
;
4072 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
4073 (offsetT
) temp
, (char *) 0);
4075 subseg_set (current_seg
, current_subseg
); /* restore current seg */
4076 S_SET_SEGMENT(symbolP
, SEG_E2
);
4077 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
4081 as_bad(_("Symbol %s already defined"), name
);
4083 demand_empty_rest_of_line();
4088 fixup_mdeps (frags
, h
, this_segment
)
4093 subseg_change (this_segment
, 0);
4096 switch (frags
->fr_type
)
4103 HANDLE_ALIGN (frags
);
4105 frags
->fr_type
= rs_fill
;
4107 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
4110 case rs_machine_dependent
:
4111 md_convert_frag (h
, this_segment
, frags
);
4117 frags
= frags
->fr_next
;
4123 #ifndef TC_FORCE_RELOCATION
4124 #define TC_FORCE_RELOCATION(fix) 0
4128 fixup_segment (segP
, this_segment_type
)
4129 segment_info_type
* segP
;
4130 segT this_segment_type
;
4132 register fixS
* fixP
;
4133 register symbolS
*add_symbolP
;
4134 register symbolS
*sub_symbolP
;
4137 register char *place
;
4138 register long where
;
4139 register char pcrel
;
4140 register fragS
*fragP
;
4141 register segT add_symbol_segment
= absolute_section
;
4143 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
4145 fragP
= fixP
->fx_frag
;
4147 where
= fixP
->fx_where
;
4148 place
= fragP
->fr_literal
+ where
;
4149 size
= fixP
->fx_size
;
4150 add_symbolP
= fixP
->fx_addsy
;
4151 sub_symbolP
= fixP
->fx_subsy
;
4152 add_number
= fixP
->fx_offset
;
4153 pcrel
= fixP
->fx_pcrel
;
4155 /* We want function-relative stabs to work on systems which
4156 may use a relaxing linker; thus we must handle the sym1-sym2
4157 fixups function-relative stabs generates.
4159 Of course, if you actually enable relaxing in the linker, the
4160 line and block scoping information is going to be incorrect
4161 in some cases. The only way to really fix this is to support
4162 a reloc involving the difference of two symbols. */
4164 && (!sub_symbolP
|| pcrel
))
4168 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
4170 /* Relocation should be done via the associated 'bal' entry
4173 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
4175 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4176 _("No 'bal' entry point for leafproc %s"),
4177 S_GET_NAME (add_symbolP
));
4180 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4184 /* Make sure the symbols have been resolved; this may not have
4185 happened if these are expression symbols. */
4186 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4187 resolve_symbol_value (add_symbolP
, 1);
4189 if (add_symbolP
!= NULL
)
4191 /* If this fixup is against a symbol which has been equated
4192 to another symbol, convert it to the other symbol. */
4193 if (add_symbolP
->sy_value
.X_op
== O_symbol
4194 && (! S_IS_DEFINED (add_symbolP
)
4195 || S_IS_COMMON (add_symbolP
)))
4197 while (add_symbolP
->sy_value
.X_op
== O_symbol
4198 && (! S_IS_DEFINED (add_symbolP
)
4199 || S_IS_COMMON (add_symbolP
)))
4203 /* We must avoid looping, as that can occur with a
4204 badly written program. */
4205 n
= add_symbolP
->sy_value
.X_add_symbol
;
4206 if (n
== add_symbolP
)
4208 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4211 fixP
->fx_addsy
= add_symbolP
;
4212 fixP
->fx_offset
= add_number
;
4216 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4217 resolve_symbol_value (sub_symbolP
, 1);
4219 if (add_symbolP
!= NULL
4220 && add_symbolP
->sy_mri_common
)
4222 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4223 add_number
+= S_GET_VALUE (add_symbolP
);
4224 fixP
->fx_offset
= add_number
;
4225 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4230 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4231 } /* if there is an addend */
4235 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4237 if (add_symbolP
!= NULL
)
4239 add_number
+= S_GET_VALUE (add_symbolP
);
4241 fixP
->fx_addsy
= NULL
;
4244 /* It's just -sym. */
4245 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4247 add_number
-= S_GET_VALUE (sub_symbolP
);
4254 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4255 _("Negative of non-absolute symbol %s"),
4256 S_GET_NAME (sub_symbolP
));
4258 add_number
-= S_GET_VALUE (sub_symbolP
);
4259 } /* not absolute */
4261 /* if sub_symbol is in the same segment that add_symbol
4262 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4264 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4265 && SEG_NORMAL (add_symbol_segment
))
4267 /* Difference of 2 symbols from same segment. Can't
4268 make difference of 2 undefineds: 'value' means
4269 something different for N_UNDF. */
4271 /* Makes no sense to use the difference of 2 arbitrary symbols
4272 as the target of a call instruction. */
4275 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4276 _("callj to difference of 2 symbols"));
4278 #endif /* TC_I960 */
4279 add_number
+= S_GET_VALUE (add_symbolP
) -
4280 S_GET_VALUE (sub_symbolP
);
4283 if (!TC_FORCE_RELOCATION (fixP
))
4285 fixP
->fx_addsy
= NULL
;
4286 fixP
->fx_subsy
= NULL
;
4288 #ifdef TC_M68K /* is this right? */
4296 /* Different segments in subtraction. */
4297 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4299 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4301 add_number
-= S_GET_VALUE (sub_symbolP
);
4304 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4305 #if 0 /* Okay for 68k, at least... */
4310 /* Make it pc-relative. */
4311 add_number
+= (md_pcrel_from (fixP
)
4312 - S_GET_VALUE (sub_symbolP
));
4321 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4322 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4323 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4324 S_GET_NAME (sub_symbolP
),
4325 (long) (fragP
->fr_address
+ where
));
4328 } /* if sub_symbolP */
4332 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4335 * This fixup was made when the symbol's segment was
4336 * SEG_UNKNOWN, but it is now in the local segment.
4337 * So we know how to do the address without relocation.
4340 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4341 * in which cases it modifies *fixP as appropriate. In the case
4342 * of a 'calls', no further work is required, and *fixP has been
4343 * set up to make the rest of the code below a no-op.
4346 #endif /* TC_I960 */
4348 add_number
+= S_GET_VALUE (add_symbolP
);
4349 add_number
-= md_pcrel_from (fixP
);
4352 add_number -= segP->scnhdr.s_vaddr;
4353 if defined (TC_I386) || defined (TE_LYNX). I now
4354 think that was an error propagated from the case when
4355 we are going to emit the relocation. If we are not
4356 going to emit the relocation, then we just want to
4357 set add_number to the difference between the symbols.
4358 This is a case that would only arise when there is a
4359 PC relative reference from a section other than .text
4360 to a symbol defined in the same section, and the
4361 reference is not relaxed. Since jump instructions on
4362 the i386 are relaxed, this could only arise with a
4363 call instruction. */
4365 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4366 if (!TC_FORCE_RELOCATION (fixP
))
4368 fixP
->fx_addsy
= NULL
;
4374 switch (add_symbol_segment
)
4376 case absolute_section
:
4378 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4379 #endif /* TC_I960 */
4380 add_number
+= S_GET_VALUE (add_symbolP
);
4383 if (!TC_FORCE_RELOCATION (fixP
))
4385 fixP
->fx_addsy
= NULL
;
4391 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4392 /* This really should be handled in the linker, but
4393 backward compatibility forbids. */
4394 add_number
+= S_GET_VALUE (add_symbolP
);
4396 add_number
+= S_GET_VALUE (add_symbolP
) +
4397 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4403 if ((int) fixP
->fx_bit_fixP
== 13)
4405 /* This is a COBR instruction. They have only a
4406 * 13-bit displacement and are only to be used
4407 * for local branches: flag as error, don't generate
4410 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4411 _("can't use COBR format with external label"));
4412 fixP
->fx_addsy
= NULL
;
4416 #endif /* TC_I960 */
4417 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4418 /* 386 COFF uses a peculiar format in which the
4419 value of a common symbol is stored in the .text
4420 segment (I've checked this on SVR3.2 and SCO
4421 3.2.2) Ian Taylor <ian@cygnus.com>. */
4422 /* This is also true for 68k COFF on sysv machines
4423 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4424 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4425 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4426 if (S_IS_COMMON (add_symbolP
))
4427 add_number
+= S_GET_VALUE (add_symbolP
);
4431 } /* switch on symbol seg */
4432 } /* if not in local seg */
4433 } /* if there was a + symbol */
4437 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4438 /* This adjustment is not correct on the m88k, for which the
4439 linker does all the computation. */
4440 add_number
-= md_pcrel_from (fixP
);
4442 if (add_symbolP
== 0)
4444 fixP
->fx_addsy
= &abs_symbol
;
4445 } /* if there's an add_symbol */
4446 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4447 /* On the 386 we must adjust by the segment vaddr as well.
4450 I changed the i960 to work this way as well. This is
4451 compatible with the current GNU linker behaviour. I do
4452 not know what other i960 COFF assemblers do. This is not
4453 a common case: normally, only assembler code will contain
4454 a PC relative reloc, and only branches which do not
4455 originate in the .text section will have a non-zero
4458 I changed the m68k to work this way as well. This will
4459 break existing PC relative relocs from sections which do
4460 not start at address 0, but it will make ld -r work.
4461 Ian Taylor, 4 Oct 96. */
4463 add_number
-= segP
->scnhdr
.s_vaddr
;
4467 #ifdef MD_APPLY_FIX3
4468 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4470 md_apply_fix (fixP
, add_number
);
4473 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4476 /* The m88k uses the offset field of the reloc to get around
4479 && ((add_number
& ~0xFF)
4480 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4481 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4482 || (add_number
& 0x80) == 0))
4484 && ((add_number
& ~0xFFFF)
4485 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4486 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4487 || (add_number
& 0x8000) == 0)))
4489 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4490 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4491 (long) add_number
, size
,
4492 (unsigned long) (fragP
->fr_address
+ where
));
4495 #ifdef WARN_SIGNED_OVERFLOW_WORD
4496 /* Warn if a .word value is too large when treated as a
4497 signed number. We already know it is not too negative.
4498 This is to catch over-large switches generated by gcc on
4500 if (!flag_signed_overflow_ok
4502 && add_number
> 0x7fff)
4503 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4504 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4506 (unsigned long) (fragP
->fr_address
+ where
));
4508 } /* not a bit fix */
4509 } /* For each fixS in this segment. */
4510 } /* fixup_segment() */
4514 /* The first entry in a .stab section is special. */
4517 obj_coff_init_stab_section (seg
)
4523 unsigned int stroff
;
4525 /* Make space for this first symbol. */
4529 as_where (&file
, (unsigned int *) NULL
);
4530 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4531 strcpy (stabstr_name
, segment_info
[seg
].name
);
4532 strcat (stabstr_name
, "str");
4533 stroff
= get_stab_string_offset (file
, stabstr_name
);
4535 md_number_to_chars (p
, stroff
, 4);
4538 /* Fill in the counts in the first entry in a .stab section. */
4541 adjust_stab_section(abfd
, seg
)
4545 segT stabstrseg
= SEG_UNKNOWN
;
4546 const char *secname
, *name2
;
4549 int i
, strsz
= 0, nsyms
;
4550 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4552 /* Look for the associated string table section. */
4554 secname
= segment_info
[seg
].name
;
4555 name
= (char *) alloca (strlen (secname
) + 4);
4556 strcpy (name
, secname
);
4557 strcat (name
, "str");
4559 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4561 name2
= segment_info
[i
].name
;
4562 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4569 /* If we found the section, get its size. */
4570 if (stabstrseg
!= SEG_UNKNOWN
)
4571 strsz
= size_section (abfd
, stabstrseg
);
4573 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4575 /* Look for the first frag of sufficient size for the initial stab
4576 symbol, and collect a pointer to it. */
4577 while (frag
&& frag
->fr_fix
< 12)
4578 frag
= frag
->fr_next
;
4580 p
= frag
->fr_literal
;
4583 /* Write in the number of stab symbols and the size of the string
4585 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4586 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4589 #endif /* not BFD_ASSEMBLER */
4591 const pseudo_typeS coff_pseudo_table
[] =
4593 {"def", obj_coff_def
, 0},
4594 {"dim", obj_coff_dim
, 0},
4595 {"endef", obj_coff_endef
, 0},
4596 {"line", obj_coff_line
, 0},
4597 {"ln", obj_coff_ln
, 0},
4598 #ifdef BFD_ASSEMBLER
4599 {"loc", obj_coff_loc
, 0},
4601 {"appline", obj_coff_ln
, 1},
4602 {"scl", obj_coff_scl
, 0},
4603 {"size", obj_coff_size
, 0},
4604 {"tag", obj_coff_tag
, 0},
4605 {"type", obj_coff_type
, 0},
4606 {"val", obj_coff_val
, 0},
4607 {"section", obj_coff_section
, 0},
4608 {"sect", obj_coff_section
, 0},
4609 /* FIXME: We ignore the MRI short attribute. */
4610 {"section.s", obj_coff_section
, 0},
4611 {"sect.s", obj_coff_section
, 0},
4612 /* We accept the .bss directive for backward compatibility with
4613 earlier versions of gas. */
4614 {"bss", obj_coff_bss
, 0},
4615 {"weak", obj_coff_weak
, 0},
4616 {"ident", obj_coff_ident
, 0},
4617 #ifndef BFD_ASSEMBLER
4618 {"use", obj_coff_section
, 0},
4619 {"text", obj_coff_text
, 0},
4620 {"data", obj_coff_data
, 0},
4621 {"lcomm", obj_coff_lcomm
, 0},
4623 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4625 {"version", s_ignore
, 0},
4626 {"ABORT", s_abort
, 0},
4628 /* The m88k uses sdef instead of def. */
4629 {"sdef", obj_coff_def
, 0},
4631 {NULL
, NULL
, 0} /* end sentinel */
4632 }; /* coff_pseudo_table */
4634 #ifdef BFD_ASSEMBLER
4636 /* Support for a COFF emulation. */
4638 static void coff_pop_insert
PARAMS ((void));
4639 static int coff_separate_stab_sections
PARAMS ((void));
4644 pop_insert (coff_pseudo_table
);
4648 coff_separate_stab_sections ()
4653 const struct format_ops coff_format_ops
=
4655 bfd_target_coff_flavour
,
4656 0, /* dfl_leading_underscore */
4657 1, /* emit_section_symbols */
4662 0, /* frob_file_before_adjust */
4663 coff_frob_file_after_relocs
,
4666 0, /* s_get_align */
4667 0, /* s_set_align */
4668 0, /* s_get_other */
4669 0, /* s_set_other */
4674 0, /* copy_symbol_attributes */
4675 0, /* generate_asm_lineno */
4676 0, /* process_stab */
4677 coff_separate_stab_sections
,
4678 obj_coff_init_stab_section
,
4679 0, /* sec_sym_ok_for_reloc */
4681 0, /* ecoff_set_ext */
4682 coff_obj_read_begin_hook
,
4683 coff_obj_symbol_new_hook