1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 98, 1999
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 static void obj_coff_bss
PARAMS ((int));
34 const char *s_get_name
PARAMS ((symbolS
* s
));
35 static void obj_coff_ln
PARAMS ((int));
36 static void obj_coff_def
PARAMS ((int));
37 static void obj_coff_endef
PARAMS ((int));
38 static void obj_coff_dim
PARAMS ((int));
39 static void obj_coff_line
PARAMS ((int));
40 static void obj_coff_size
PARAMS ((int));
41 static void obj_coff_scl
PARAMS ((int));
42 static void obj_coff_tag
PARAMS ((int));
43 static void obj_coff_val
PARAMS ((int));
44 static void obj_coff_type
PARAMS ((int));
46 /* This is used to hold the symbol built by a sequence of pseudo-ops
47 from .def and .endef. */
48 static symbolS
*def_symbol_in_progress
;
53 unsigned long chunk_size
;
54 unsigned long element_size
;
57 unsigned long pointer
;
62 stack_init (chunk_size
, element_size
)
63 unsigned long chunk_size
;
64 unsigned long element_size
;
68 st
= (stack
*) malloc (sizeof (stack
));
71 st
->data
= malloc (chunk_size
);
78 st
->size
= chunk_size
;
79 st
->chunk_size
= chunk_size
;
80 st
->element_size
= element_size
;
85 /* Not currently used. */
96 stack_push (st
, element
)
100 if (st
->pointer
+ st
->element_size
>= st
->size
)
102 st
->size
+= st
->chunk_size
;
103 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
106 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
107 st
->pointer
+= st
->element_size
;
108 return st
->data
+ st
->pointer
;
115 if (st
->pointer
< st
->element_size
)
120 st
->pointer
-= st
->element_size
;
121 return st
->data
+ st
->pointer
;
125 * Maintain a list of the tagnames of the structres.
128 static struct hash_control
*tag_hash
;
133 tag_hash
= hash_new ();
137 tag_insert (name
, symbolP
)
141 const char *error_string
;
143 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
145 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
154 #ifdef STRIP_UNDERSCORE
157 #endif /* STRIP_UNDERSCORE */
158 return (symbolS
*) hash_find (tag_hash
, name
);
162 tag_find_or_make (name
)
167 if ((symbolP
= tag_find (name
)) == NULL
)
169 symbolP
= symbol_new (name
, undefined_section
,
170 0, &zero_address_frag
);
172 tag_insert (S_GET_NAME (symbolP
), symbolP
);
174 symbol_table_insert (symbolP
);
181 /* We accept the .bss directive to set the section for backward
182 compatibility with earlier versions of gas. */
185 obj_coff_bss (ignore
)
186 int ignore ATTRIBUTE_UNUSED
;
188 if (*input_line_pointer
== '\n')
189 subseg_new (".bss", get_absolute_expression ());
194 /* Handle .weak. This is a GNU extension. */
197 obj_coff_weak (ignore
)
198 int ignore ATTRIBUTE_UNUSED
;
206 name
= input_line_pointer
;
207 c
= get_symbol_end ();
208 symbolP
= symbol_find_or_make (name
);
209 *input_line_pointer
= c
;
213 S_SET_WEAK (symbolP
);
217 S_SET_STORAGE_CLASS (symbolP
, C_NT_WEAK
);
219 S_SET_STORAGE_CLASS (symbolP
, C_WEAKEXT
);
224 input_line_pointer
++;
226 if (*input_line_pointer
== '\n')
232 demand_empty_rest_of_line ();
237 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
239 #define GET_FILENAME_STRING(X) \
240 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
244 fetch_coff_debug_section ()
246 static segT debug_section
;
250 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
252 debug_section
= s
->section
;
254 return debug_section
;
258 SA_SET_SYM_ENDNDX (sym
, val
)
262 combined_entry_type
*entry
, *p
;
264 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
265 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
266 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
271 SA_SET_SYM_TAGNDX (sym
, val
)
275 combined_entry_type
*entry
, *p
;
277 entry
= &coffsymbol (symbol_get_bfdsym (sym
))->native
[1];
278 p
= coffsymbol (symbol_get_bfdsym (val
))->native
;
279 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
284 S_GET_DATA_TYPE (sym
)
287 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
;
291 S_SET_DATA_TYPE (sym
, val
)
295 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_type
= val
;
300 S_GET_STORAGE_CLASS (sym
)
303 return coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
;
307 S_SET_STORAGE_CLASS (sym
, val
)
311 coffsymbol (symbol_get_bfdsym (sym
))->native
->u
.syment
.n_sclass
= val
;
315 /* Merge a debug symbol containing debug information into a normal symbol. */
318 c_symbol_merge (debug
, normal
)
322 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
323 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
325 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
327 /* take the most we have */
328 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
331 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
333 /* Move all the auxiliary information. */
334 memcpy (SYM_AUXINFO (normal
), SYM_AUXINFO (debug
),
335 (S_GET_NUMBER_AUXILIARY (debug
)
336 * sizeof (*SYM_AUXINFO (debug
))));
339 /* Move the debug flags. */
340 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
344 c_dot_file_symbol (filename
)
349 /* BFD converts filename to a .file symbol with an aux entry. It
350 also handles chaining. */
351 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
353 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
354 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
356 symbol_get_bfdsym (symbolP
)->flags
= BSF_DEBUGGING
;
363 listing_source_file (filename
);
368 /* Make sure that the symbol is first on the symbol chain */
369 if (symbol_rootP
!= symbolP
)
371 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
372 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
373 } /* if not first on the list */
376 /* Line number handling */
379 struct line_no
*next
;
386 /* Symbol of last function, which we should hang line#s off of. */
387 static symbolS
*line_fsym
;
389 #define in_function() (line_fsym != 0)
390 #define clear_function() (line_fsym = 0)
391 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
395 coff_obj_symbol_new_hook (symbolP
)
398 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
399 char * s
= (char *) xmalloc (sz
);
402 coffsymbol (symbol_get_bfdsym (symbolP
))->native
= (combined_entry_type
*) s
;
404 S_SET_DATA_TYPE (symbolP
, T_NULL
);
405 S_SET_STORAGE_CLASS (symbolP
, 0);
406 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
408 if (S_IS_STRING (symbolP
))
409 SF_SET_STRING (symbolP
);
411 if (S_IS_LOCAL (symbolP
))
412 SF_SET_LOCAL (symbolP
);
417 * Handle .ln directives.
420 static symbolS
*current_lineno_sym
;
421 static struct line_no
*line_nos
;
422 /* @@ Blindly assume all .ln directives will be in the .text section... */
426 add_lineno (frag
, offset
, num
)
431 struct line_no
*new_line
=
432 (struct line_no
*) xmalloc (sizeof (struct line_no
));
433 if (!current_lineno_sym
)
437 new_line
->next
= line_nos
;
438 new_line
->frag
= frag
;
439 new_line
->l
.line_number
= num
;
440 new_line
->l
.u
.offset
= offset
;
446 coff_add_linesym (sym
)
451 coffsymbol (symbol_get_bfdsym (current_lineno_sym
))->lineno
=
456 current_lineno_sym
= sym
;
460 obj_coff_ln (appline
)
465 if (! appline
&& def_symbol_in_progress
!= NULL
)
467 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
468 demand_empty_rest_of_line ();
472 l
= get_absolute_expression ();
475 add_lineno (frag_now
, frag_now_fix (), l
);
479 new_logical_line ((char *) NULL
, l
- 1);
488 l
+= coff_line_base
- 1;
489 listing_source_line (l
);
494 demand_empty_rest_of_line ();
500 * Handle .def directives.
502 * One might ask : why can't we symbol_new if the symbol does not
503 * already exist and fill it with debug information. Because of
504 * the C_EFCN special symbol. It would clobber the value of the
505 * function symbol before we have a chance to notice that it is
506 * a C_EFCN. And a second reason is that the code is more clear this
507 * way. (at least I think it is :-).
511 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
512 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
513 *input_line_pointer == '\t') \
514 input_line_pointer++;
518 int what ATTRIBUTE_UNUSED
;
520 char name_end
; /* Char after the end of name */
521 char *symbol_name
; /* Name of the debug symbol */
522 char *symbol_name_copy
; /* Temporary copy of the name */
523 unsigned int symbol_name_length
;
525 if (def_symbol_in_progress
!= NULL
)
527 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
528 demand_empty_rest_of_line ();
530 } /* if not inside .def/.endef */
534 symbol_name
= input_line_pointer
;
535 #ifdef STRIP_UNDERSCORE
536 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
538 #endif /* STRIP_UNDERSCORE */
540 name_end
= get_symbol_end ();
541 symbol_name_length
= strlen (symbol_name
);
542 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
543 strcpy (symbol_name_copy
, symbol_name
);
544 #ifdef tc_canonicalize_symbol_name
545 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
548 /* Initialize the new symbol */
549 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
550 symbol_set_frag (def_symbol_in_progress
, &zero_address_frag
);
551 S_SET_VALUE (def_symbol_in_progress
, 0);
553 if (S_IS_STRING (def_symbol_in_progress
))
554 SF_SET_STRING (def_symbol_in_progress
);
556 *input_line_pointer
= name_end
;
558 demand_empty_rest_of_line ();
561 unsigned int dim_index
;
564 obj_coff_endef (ignore
)
565 int ignore ATTRIBUTE_UNUSED
;
569 /* DIM BUG FIX sac@cygnus.com */
571 if (def_symbol_in_progress
== NULL
)
573 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
574 demand_empty_rest_of_line ();
576 } /* if not inside .def/.endef */
578 /* Set the section number according to storage class. */
579 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
584 SF_SET_TAG (def_symbol_in_progress
);
585 /* intentional fallthrough */
588 SF_SET_DEBUG (def_symbol_in_progress
);
589 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
593 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
594 /* intentional fallthrough */
596 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
597 /* intentional fallthrough */
601 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
603 name
= S_GET_NAME (def_symbol_in_progress
);
604 if (name
[1] == 'b' && name
[2] == 'f')
606 if (! in_function ())
607 as_warn (_("`%s' symbol without preceding function"), name
);
608 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
609 /* Will need relocating */
610 SF_SET_PROCESS (def_symbol_in_progress
);
618 #endif /* C_AUTOARG */
624 SF_SET_DEBUG (def_symbol_in_progress
);
625 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
632 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
642 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
649 as_warn (_("unexpected storage class %d"),
650 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
652 } /* switch on storage class */
654 /* Now that we have built a debug symbol, try to find if we should
655 merge with an existing symbol or not. If a symbol is C_EFCN or
656 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
658 /* Two cases for functions. Either debug followed by definition or
659 definition followed by debug. For definition first, we will
660 merge the debug symbol into the definition. For debug first, the
661 lineno entry MUST point to the definition function or else it
662 will point off into space when obj_crawl_symbol_chain() merges
663 the debug symbol into the real symbol. Therefor, let's presume
664 the debug symbol is a real function reference. */
666 /* FIXME-SOON If for some reason the definition label/symbol is
667 never seen, this will probably leave an undefined symbol at link
670 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
671 || (!strcmp (bfd_get_section_name (stdoutput
,
672 S_GET_SEGMENT (def_symbol_in_progress
)),
674 && !SF_GET_TAG (def_symbol_in_progress
))
675 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
676 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
678 if (def_symbol_in_progress
!= symbol_lastP
)
679 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
684 /* This symbol already exists, merge the newly created symbol
685 into the old one. This is not mandatory. The linker can
686 handle duplicate symbols correctly. But I guess that it save
687 a *lot* of space if the assembly file defines a lot of
690 /* The debug entry (def_symbol_in_progress) is merged into the
691 previous definition. */
693 c_symbol_merge (def_symbol_in_progress
, symbolP
);
694 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
696 def_symbol_in_progress
= symbolP
;
698 if (SF_GET_FUNCTION (def_symbol_in_progress
)
699 || SF_GET_TAG (def_symbol_in_progress
)
700 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
702 /* For functions, and tags, and static symbols, the symbol
703 *must* be where the debug symbol appears. Move the
704 existing symbol to the current place. */
705 /* If it already is at the end of the symbol list, do nothing */
706 if (def_symbol_in_progress
!= symbol_lastP
)
708 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
709 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
714 if (SF_GET_TAG (def_symbol_in_progress
))
718 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
720 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
721 tag_insert (S_GET_NAME (def_symbol_in_progress
),
722 def_symbol_in_progress
);
725 if (SF_GET_FUNCTION (def_symbol_in_progress
))
727 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
728 set_function (def_symbol_in_progress
);
729 SF_SET_PROCESS (def_symbol_in_progress
);
733 /* That is, if this is the first time we've seen the
735 symbol_table_insert (def_symbol_in_progress
);
736 } /* definition follows debug */
737 } /* Create the line number entry pointing to the function being defined */
739 def_symbol_in_progress
= NULL
;
740 demand_empty_rest_of_line ();
744 obj_coff_dim (ignore
)
745 int ignore ATTRIBUTE_UNUSED
;
749 if (def_symbol_in_progress
== NULL
)
751 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
752 demand_empty_rest_of_line ();
754 } /* if not inside .def/.endef */
756 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
758 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
761 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
762 get_absolute_expression ());
764 switch (*input_line_pointer
)
767 input_line_pointer
++;
771 as_warn (_("badly formed .dim directive ignored"));
772 /* intentional fallthrough */
780 demand_empty_rest_of_line ();
784 obj_coff_line (ignore
)
785 int ignore ATTRIBUTE_UNUSED
;
789 if (def_symbol_in_progress
== NULL
)
791 /* Probably stabs-style line? */
796 this_base
= get_absolute_expression ();
797 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
798 coff_line_base
= this_base
;
800 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
801 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
803 demand_empty_rest_of_line ();
806 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
811 listing_source_line ((unsigned int) coff_line_base
);
817 obj_coff_size (ignore
)
818 int ignore ATTRIBUTE_UNUSED
;
820 if (def_symbol_in_progress
== NULL
)
822 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
823 demand_empty_rest_of_line ();
825 } /* if not inside .def/.endef */
827 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
828 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
829 demand_empty_rest_of_line ();
833 obj_coff_scl (ignore
)
834 int ignore ATTRIBUTE_UNUSED
;
836 if (def_symbol_in_progress
== NULL
)
838 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
839 demand_empty_rest_of_line ();
841 } /* if not inside .def/.endef */
843 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
844 demand_empty_rest_of_line ();
848 obj_coff_tag (ignore
)
849 int ignore ATTRIBUTE_UNUSED
;
854 if (def_symbol_in_progress
== NULL
)
856 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
857 demand_empty_rest_of_line ();
861 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
862 symbol_name
= input_line_pointer
;
863 name_end
= get_symbol_end ();
865 #ifdef tc_canonicalize_symbol_name
866 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
869 /* Assume that the symbol referred to by .tag is always defined.
870 This was a bad assumption. I've added find_or_make. xoxorich. */
871 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
872 tag_find_or_make (symbol_name
));
873 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
875 as_warn (_("tag not found for .tag %s"), symbol_name
);
878 SF_SET_TAGGED (def_symbol_in_progress
);
879 *input_line_pointer
= name_end
;
881 demand_empty_rest_of_line ();
885 obj_coff_type (ignore
)
886 int ignore ATTRIBUTE_UNUSED
;
888 if (def_symbol_in_progress
== NULL
)
890 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
891 demand_empty_rest_of_line ();
893 } /* if not inside .def/.endef */
895 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
897 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
898 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
900 SF_SET_FUNCTION (def_symbol_in_progress
);
901 } /* is a function */
903 demand_empty_rest_of_line ();
907 obj_coff_val (ignore
)
908 int ignore ATTRIBUTE_UNUSED
;
910 if (def_symbol_in_progress
== NULL
)
912 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
913 demand_empty_rest_of_line ();
915 } /* if not inside .def/.endef */
917 if (is_name_beginner (*input_line_pointer
))
919 char *symbol_name
= input_line_pointer
;
920 char name_end
= get_symbol_end ();
922 #ifdef tc_canonicalize_symbol_name
923 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
925 if (!strcmp (symbol_name
, "."))
927 symbol_set_frag (def_symbol_in_progress
, frag_now
);
928 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
929 /* If the .val is != from the .def (e.g. statics) */
931 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
936 exp
.X_add_symbol
= symbol_find_or_make (symbol_name
);
937 exp
.X_op_symbol
= NULL
;
938 exp
.X_add_number
= 0;
939 symbol_set_value_expression (def_symbol_in_progress
, &exp
);
941 /* If the segment is undefined when the forward reference is
942 resolved, then copy the segment id from the forward
944 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
946 /* FIXME: gcc can generate address expressions here in
947 unusual cases (search for "obscure" in sdbout.c). We
948 just ignore the offset here, thus generating incorrect
949 debugging information. We ignore the rest of the line
952 /* Otherwise, it is the name of a non debug symbol and its value
953 will be calculated later. */
954 *input_line_pointer
= name_end
;
958 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
959 } /* if symbol based */
961 demand_empty_rest_of_line ();
965 coff_obj_read_begin_hook ()
967 /* These had better be the same. Usually 18 bytes. */
969 know (sizeof (SYMENT
) == sizeof (AUXENT
));
970 know (SYMESZ
== AUXESZ
);
976 symbolS
*coff_last_function
;
977 static symbolS
*coff_last_bf
;
980 coff_frob_symbol (symp
, punt
)
984 static symbolS
*last_tagP
;
985 static stack
*block_stack
;
986 static symbolS
*set_end
;
987 symbolS
*next_set_end
= NULL
;
989 if (symp
== &abs_symbol
)
995 if (current_lineno_sym
)
996 coff_add_linesym ((symbolS
*) 0);
999 block_stack
= stack_init (512, sizeof (symbolS
*));
1001 if (S_IS_WEAK (symp
))
1004 S_SET_STORAGE_CLASS (symp
, C_NT_WEAK
);
1006 S_SET_STORAGE_CLASS (symp
, C_WEAKEXT
);
1010 if (!S_IS_DEFINED (symp
)
1011 && !S_IS_WEAK (symp
)
1012 && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
1013 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1015 if (!SF_GET_DEBUG (symp
))
1018 if (!SF_GET_LOCAL (symp
)
1019 && !SF_GET_STATICS (symp
)
1020 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
1023 c_symbol_merge (symp
, real
);
1026 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
1028 assert (S_GET_VALUE (symp
) == 0);
1029 S_SET_EXTERNAL (symp
);
1031 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
1033 if (S_GET_SEGMENT (symp
) == text_section
1034 && symp
!= seg_info (text_section
)->sym
)
1035 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
1037 S_SET_STORAGE_CLASS (symp
, C_STAT
);
1039 if (SF_GET_PROCESS (symp
))
1041 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
1043 if (!strcmp (S_GET_NAME (symp
), ".bb"))
1044 stack_push (block_stack
, (char *) &symp
);
1048 begin
= *(symbolS
**) stack_pop (block_stack
);
1050 as_warn (_("mismatched .eb"));
1052 next_set_end
= begin
;
1055 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
1057 union internal_auxent
*auxp
;
1058 coff_last_function
= symp
;
1059 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
1060 S_SET_NUMBER_AUXILIARY (symp
, 1);
1061 auxp
= SYM_AUXENT (symp
);
1062 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
1063 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
1065 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
1067 if (coff_last_function
== 0)
1068 as_fatal (_("C_EFCN symbol out of scope"));
1069 SA_SET_SYM_FSIZE (coff_last_function
,
1070 (long) (S_GET_VALUE (symp
)
1071 - S_GET_VALUE (coff_last_function
)));
1072 next_set_end
= coff_last_function
;
1073 coff_last_function
= 0;
1076 if (S_IS_EXTERNAL (symp
))
1077 S_SET_STORAGE_CLASS (symp
, C_EXT
);
1078 else if (SF_GET_LOCAL (symp
))
1081 if (SF_GET_FUNCTION (symp
))
1082 symbol_get_bfdsym (symp
)->flags
|= BSF_FUNCTION
;
1087 if (SF_GET_TAG (symp
))
1089 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1090 next_set_end
= last_tagP
;
1093 /* This is pretty horrible, but we have to set *punt correctly in
1094 order to call SA_SET_SYM_ENDNDX correctly. */
1095 if (! symbol_used_in_reloc_p (symp
)
1096 && ((symbol_get_bfdsym (symp
)->flags
& BSF_SECTION_SYM
) != 0
1097 || (! S_IS_EXTERNAL (symp
)
1098 && ! symbol_get_tc (symp
)->output
1099 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1103 if (set_end
!= (symbolS
*) NULL
1105 && ((symbol_get_bfdsym (symp
)->flags
& BSF_NOT_AT_END
) != 0
1106 || (S_IS_DEFINED (symp
)
1107 && ! S_IS_COMMON (symp
)
1108 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1110 SA_SET_SYM_ENDNDX (set_end
, symp
);
1114 if (next_set_end
!= NULL
)
1116 if (set_end
!= NULL
)
1117 as_warn ("Warning: internal error: forgetting to set endndx of %s",
1118 S_GET_NAME (set_end
));
1119 set_end
= next_set_end
;
1123 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1124 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1126 if (coff_last_bf
!= NULL
)
1127 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1128 coff_last_bf
= symp
;
1131 if (coffsymbol (symbol_get_bfdsym (symp
))->lineno
)
1134 struct line_no
*lptr
;
1137 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1138 for (i
= 0; lptr
; lptr
= lptr
->next
)
1140 lptr
= (struct line_no
*) coffsymbol (symbol_get_bfdsym (symp
))->lineno
;
1142 /* We need i entries for line numbers, plus 1 for the first
1143 entry which BFD will override, plus 1 for the last zero
1144 entry (a marker for BFD). */
1145 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1146 coffsymbol (symbol_get_bfdsym (symp
))->lineno
= l
;
1147 l
[i
+ 1].line_number
= 0;
1148 l
[i
+ 1].u
.sym
= NULL
;
1152 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1160 coff_adjust_section_syms (abfd
, sec
, x
)
1161 bfd
*abfd ATTRIBUTE_UNUSED
;
1163 PTR x ATTRIBUTE_UNUSED
;
1166 segment_info_type
*seginfo
= seg_info (sec
);
1167 int nlnno
, nrelocs
= 0;
1169 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1170 tc-ppc.c. Do not get confused by it. */
1171 if (seginfo
== NULL
)
1174 if (!strcmp (sec
->name
, ".text"))
1175 nlnno
= coff_n_line_nos
;
1179 /* @@ Hope that none of the fixups expand to more than one reloc
1181 fixS
*fixp
= seginfo
->fix_root
;
1184 if (! fixp
->fx_done
)
1186 fixp
= fixp
->fx_next
;
1189 if (bfd_get_section_size_before_reloc (sec
) == 0
1192 && sec
!= text_section
1193 && sec
!= data_section
1194 && sec
!= bss_section
)
1196 secsym
= section_symbol (sec
);
1197 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1198 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1202 coff_frob_file_after_relocs ()
1204 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1208 * implement the .section pseudo op:
1209 * .section name {, "flags"}
1211 * | +--- optional flags: 'b' for bss
1213 * +-- section name 'l' for lib
1217 * 'd' (apparently m88k for data)
1219 * 'r' for read-only data
1220 * 's' for shared data (PE)
1221 * But if the argument is not a quoted string, treat it as a
1222 * subsegment number.
1226 obj_coff_section (ignore
)
1227 int ignore ATTRIBUTE_UNUSED
;
1229 /* Strip out the section name */
1245 section_name
= input_line_pointer
;
1246 c
= get_symbol_end ();
1248 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1249 strcpy (name
, section_name
);
1251 *input_line_pointer
= c
;
1258 if (*input_line_pointer
== ',')
1260 ++input_line_pointer
;
1262 if (*input_line_pointer
!= '"')
1263 exp
= get_absolute_expression ();
1266 ++input_line_pointer
;
1267 while (*input_line_pointer
!= '"'
1268 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1270 switch (*input_line_pointer
)
1272 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1273 case 'n': flags
&=~ SEC_LOAD
; break;
1274 case 'd': flags
|= SEC_DATA
| SEC_LOAD
; /* fall through */
1275 case 'w': flags
&=~ SEC_READONLY
; break;
1276 case 'x': flags
|= SEC_CODE
| SEC_LOAD
; break;
1277 case 'r': flags
|= SEC_READONLY
; break;
1278 case 's': flags
|= SEC_SHARED
; break;
1280 case 'i': /* STYP_INFO */
1281 case 'l': /* STYP_LIB */
1282 case 'o': /* STYP_OVER */
1283 as_warn (_("unsupported section attribute '%c'"),
1284 *input_line_pointer
);
1288 as_warn(_("unknown section attribute '%c'"),
1289 *input_line_pointer
);
1292 ++input_line_pointer
;
1294 if (*input_line_pointer
== '"')
1295 ++input_line_pointer
;
1299 sec
= subseg_new (name
, (subsegT
) exp
);
1301 if (flags
!= SEC_NO_FLAGS
)
1305 oldflags
= bfd_get_section_flags (stdoutput
, sec
);
1306 oldflags
&= SEC_LINK_ONCE
| SEC_LINK_DUPLICATES
;
1309 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1310 as_warn (_("error setting flags for \"%s\": %s"),
1311 bfd_section_name (stdoutput
, sec
),
1312 bfd_errmsg (bfd_get_error ()));
1315 demand_empty_rest_of_line ();
1319 coff_adjust_symtab ()
1321 if (symbol_rootP
== NULL
1322 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1323 c_dot_file_symbol ("fake");
1327 coff_frob_section (sec
)
1333 bfd_vma size
, n_entries
, mask
;
1335 /* The COFF back end in BFD requires that all section sizes be
1336 rounded up to multiples of the corresponding section alignments.
1337 Seems kinda silly to me, but that's the way it is. */
1338 size
= bfd_get_section_size_before_reloc (sec
);
1339 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1342 size
= (size
+ mask
) & ~mask
;
1343 bfd_set_section_size (stdoutput
, sec
, size
);
1346 /* If the section size is non-zero, the section symbol needs an aux
1347 entry associated with it, indicating the size. We don't know
1348 all the values yet; coff_frob_symbol will fill them in later. */
1350 || sec
== text_section
1351 || sec
== data_section
1352 || sec
== bss_section
)
1354 symbolS
*secsym
= section_symbol (sec
);
1356 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1357 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1358 SF_SET_STATICS (secsym
);
1359 SA_SET_SCN_SCNLEN (secsym
, size
);
1362 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1363 #ifndef STAB_SECTION_NAME
1364 #define STAB_SECTION_NAME ".stab"
1366 #ifndef STAB_STRING_SECTION_NAME
1367 #define STAB_STRING_SECTION_NAME ".stabstr"
1369 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1373 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1374 /* size is already rounded up, since other section will be listed first */
1375 size
= bfd_get_section_size_before_reloc (strsec
);
1377 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1379 /* Find first non-empty frag. It should be large enough. */
1380 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1381 while (fragp
&& fragp
->fr_fix
== 0)
1382 fragp
= fragp
->fr_next
;
1383 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1385 /* Store the values. */
1386 p
= fragp
->fr_literal
;
1387 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1388 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1392 obj_coff_init_stab_section (seg
)
1398 unsigned int stroff
;
1400 /* Make space for this first symbol. */
1404 as_where (&file
, (unsigned int *) NULL
);
1405 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1406 strcpy (stabstr_name
, seg
->name
);
1407 strcat (stabstr_name
, "str");
1408 stroff
= get_stab_string_offset (file
, stabstr_name
);
1410 md_number_to_chars (p
, stroff
, 4);
1419 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1427 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1429 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1430 (unsigned long) symbolP
,
1431 S_GET_NAME(symbolP
),
1432 (long) S_GET_DATA_TYPE(symbolP
),
1433 S_GET_STORAGE_CLASS(symbolP
),
1434 (int) S_GET_SEGMENT(symbolP
));
1440 #else /* not BFD_ASSEMBLER */
1443 /* This is needed because we include internal bfd things. */
1447 #include "libcoff.h"
1450 #include "coff/pe.h"
1453 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1454 that we can stick sections together without causing trouble. */
1456 #define NOP_OPCODE 0x00
1459 /* The zeroes if symbol name is longer than 8 chars */
1460 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1462 #define MIN(a,b) ((a) < (b)? (a) : (b))
1464 /* This vector is used to turn a gas internal segment number into a
1465 section number suitable for insertion into a coff symbol table.
1466 This must correspond to seg_info_off_by_4. */
1468 const short seg_N_TYPE
[] =
1469 { /* in: segT out: N_TYPE bits */
1471 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1472 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1473 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1474 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1475 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1476 C_UNDEF_SECTION
, /* SEG_GOOF */
1477 C_UNDEF_SECTION
, /* SEG_EXPR */
1478 C_DEBUG_SECTION
, /* SEG_DEBUG */
1479 C_NTV_SECTION
, /* SEG_NTV */
1480 C_PTV_SECTION
, /* SEG_PTV */
1481 C_REGISTER_SECTION
, /* SEG_REGISTER */
1484 int function_lineoff
= -1; /* Offset in line#s where the last function
1485 started (the odd entry for line #0) */
1487 /* structure used to keep the filenames which
1488 are too long around so that we can stick them
1489 into the string table */
1490 struct filename_list
1493 struct filename_list
*next
;
1496 static struct filename_list
*filename_list_head
;
1497 static struct filename_list
*filename_list_tail
;
1499 static symbolS
*last_line_symbol
;
1501 /* Add 4 to the real value to get the index and compensate the
1502 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1503 section number into a segment number
1505 static symbolS
*previous_file_symbol
;
1506 void c_symbol_merge ();
1507 static int line_base
;
1509 symbolS
*c_section_symbol ();
1512 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1513 segT this_segment_type
));
1516 static void fixup_mdeps
PARAMS ((fragS
*,
1521 static void fill_section
PARAMS ((bfd
* abfd
,
1526 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1531 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1532 symbolS
* symbol_rootP
));
1534 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1536 static void obj_coff_lcomm
PARAMS ((int));
1537 static void obj_coff_text
PARAMS ((int));
1538 static void obj_coff_data
PARAMS ((int));
1539 static void obj_coff_ident
PARAMS ((int));
1540 void obj_coff_section
PARAMS ((int));
1542 /* When not using BFD_ASSEMBLER, we permit up to 40 sections.
1544 This array maps a COFF section number into a gas section number.
1545 Because COFF uses negative section numbers, you must add 4 to the
1546 COFF section number when indexing into this array; this is done via
1547 the SEG_INFO_FROM_SECTION_NUMBER macro. This must correspond to
1550 static const segT seg_info_off_by_4
[] =
1557 SEG_E0
, SEG_E1
, SEG_E2
, SEG_E3
, SEG_E4
,
1558 SEG_E5
, SEG_E6
, SEG_E7
, SEG_E8
, SEG_E9
,
1559 SEG_E10
, SEG_E11
, SEG_E12
, SEG_E13
, SEG_E14
,
1560 SEG_E15
, SEG_E16
, SEG_E17
, SEG_E18
, SEG_E19
,
1561 SEG_E20
, SEG_E21
, SEG_E22
, SEG_E23
, SEG_E24
,
1562 SEG_E25
, SEG_E26
, SEG_E27
, SEG_E28
, SEG_E29
,
1563 SEG_E30
, SEG_E31
, SEG_E32
, SEG_E33
, SEG_E34
,
1564 SEG_E35
, SEG_E36
, SEG_E37
, SEG_E38
, SEG_E39
,
1577 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1579 static relax_addressT
1580 relax_align (address
, alignment
)
1581 relax_addressT address
;
1584 relax_addressT mask
;
1585 relax_addressT new_address
;
1587 mask
= ~((~0) << alignment
);
1588 new_address
= (address
+ mask
) & (~mask
);
1589 return (new_address
- address
);
1597 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
);
1600 /* calculate the size of the frag chain and fill in the section header
1601 to contain all of it, also fill in the addr of the sections */
1603 size_section (abfd
, idx
)
1604 bfd
*abfd ATTRIBUTE_UNUSED
;
1608 unsigned int size
= 0;
1609 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1612 size
= frag
->fr_address
;
1613 if (frag
->fr_address
!= size
)
1615 fprintf (stderr
, _("Out of step\n"));
1616 size
= frag
->fr_address
;
1619 switch (frag
->fr_type
)
1621 #ifdef TC_COFF_SIZEMACHDEP
1622 case rs_machine_dependent
:
1623 size
+= TC_COFF_SIZEMACHDEP (frag
);
1627 assert (frag
->fr_symbol
== 0);
1630 size
+= frag
->fr_fix
;
1631 size
+= frag
->fr_offset
* frag
->fr_var
;
1638 size
+= frag
->fr_fix
;
1639 off
= relax_align (size
, frag
->fr_offset
);
1640 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1646 BAD_CASE (frag
->fr_type
);
1649 frag
= frag
->fr_next
;
1651 segment_info
[idx
].scnhdr
.s_size
= size
;
1657 count_entries_in_chain (idx
)
1660 unsigned int nrelocs
;
1663 /* Count the relocations */
1664 fixup_ptr
= segment_info
[idx
].fix_root
;
1666 while (fixup_ptr
!= (fixS
*) NULL
)
1668 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1671 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1680 fixup_ptr
= fixup_ptr
->fx_next
;
1687 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1689 /* AUX's ld expects relocations to be sorted */
1691 compare_external_relocs (x
, y
)
1695 struct external_reloc
*a
= (struct external_reloc
*) x
;
1696 struct external_reloc
*b
= (struct external_reloc
*) y
;
1697 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1698 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1699 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1704 /* output all the relocations for a section */
1706 do_relocs_for (abfd
, h
, file_cursor
)
1709 unsigned long *file_cursor
;
1711 unsigned int nrelocs
;
1713 unsigned long reloc_start
= *file_cursor
;
1715 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1717 if (segment_info
[idx
].scnhdr
.s_name
[0])
1719 struct external_reloc
*ext_ptr
;
1720 struct external_reloc
*external_reloc_vec
;
1721 unsigned int external_reloc_size
;
1722 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1723 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1724 nrelocs
= count_entries_in_chain (idx
);
1727 /* Bypass this stuff if no relocs. This also incidentally
1728 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1730 external_reloc_size
= nrelocs
* RELSZ
;
1731 external_reloc_vec
=
1732 (struct external_reloc
*) malloc (external_reloc_size
);
1734 ext_ptr
= external_reloc_vec
;
1736 /* Fill in the internal coff style reloc struct from the
1737 internal fix list. */
1740 struct internal_reloc intr
;
1742 /* Only output some of the relocations */
1743 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1745 #ifdef TC_RELOC_MANGLE
1746 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1751 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1753 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1755 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1757 #ifdef TC_KEEP_FX_OFFSET
1758 intr
.r_offset
= fix_ptr
->fx_offset
;
1763 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1764 && (! S_IS_DEFINED (symbol_ptr
)
1765 || S_IS_COMMON (symbol_ptr
)))
1769 /* We must avoid looping, as that can occur
1770 with a badly written program. */
1771 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1772 if (n
== symbol_ptr
)
1777 /* Turn the segment of the symbol into an offset. */
1780 resolve_symbol_value (symbol_ptr
, 1);
1781 if (! symbol_ptr
->sy_resolved
)
1786 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1787 as_bad_where (file
, line
,
1788 _("unresolved relocation"));
1790 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1791 S_GET_NAME (symbol_ptr
));
1793 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1796 intr
.r_symndx
= dot
->sy_number
;
1800 intr
.r_symndx
= symbol_ptr
->sy_number
;
1810 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1813 #if defined(TC_A29K)
1815 /* The 29k has a special kludge for the high 16 bit
1816 reloc. Two relocations are emited, R_IHIHALF,
1817 and R_IHCONST. The second one doesn't contain a
1818 symbol, but uses the value for offset. */
1820 if (intr
.r_type
== R_IHIHALF
)
1822 /* now emit the second bit */
1823 intr
.r_type
= R_IHCONST
;
1824 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1825 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1831 fix_ptr
= fix_ptr
->fx_next
;
1835 /* Sort the reloc table */
1836 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1837 sizeof (struct external_reloc
), compare_external_relocs
);
1840 /* Write out the reloc table */
1841 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1843 free (external_reloc_vec
);
1845 /* Fill in section header info. */
1846 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1847 *file_cursor
+= external_reloc_size
;
1848 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1853 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1857 /* Set relocation_size field in file headers */
1858 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1862 /* run through a frag chain and write out the data to go with it, fill
1863 in the scnhdrs with the info on the file postions
1866 fill_section (abfd
, h
, file_cursor
)
1868 object_headers
*h ATTRIBUTE_UNUSED
;
1869 unsigned long *file_cursor
;
1873 unsigned int paddr
= 0;
1875 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1877 unsigned int offset
= 0;
1878 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1884 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1891 buffer
= xmalloc (s
->s_size
);
1892 s
->s_scnptr
= *file_cursor
;
1894 know (s
->s_paddr
== paddr
);
1896 if (strcmp (s
->s_name
, ".text") == 0)
1897 s
->s_flags
|= STYP_TEXT
;
1898 else if (strcmp (s
->s_name
, ".data") == 0)
1899 s
->s_flags
|= STYP_DATA
;
1900 else if (strcmp (s
->s_name
, ".bss") == 0)
1903 s
->s_flags
|= STYP_BSS
;
1905 /* @@ Should make the i386 and a29k coff targets define
1906 COFF_NOLOAD_PROBLEM, and have only one test here. */
1909 #ifndef COFF_NOLOAD_PROBLEM
1910 /* Apparently the SVR3 linker (and exec syscall) and UDI
1911 mondfe progrem are confused by noload sections. */
1912 s
->s_flags
|= STYP_NOLOAD
;
1917 else if (strcmp (s
->s_name
, ".lit") == 0)
1918 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1919 else if (strcmp (s
->s_name
, ".init") == 0)
1920 s
->s_flags
|= STYP_TEXT
;
1921 else if (strcmp (s
->s_name
, ".fini") == 0)
1922 s
->s_flags
|= STYP_TEXT
;
1923 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1924 s
->s_flags
|= STYP_INFO
;
1928 unsigned int fill_size
;
1929 switch (frag
->fr_type
)
1931 case rs_machine_dependent
:
1934 memcpy (buffer
+ frag
->fr_address
,
1936 (unsigned int) frag
->fr_fix
);
1937 offset
+= frag
->fr_fix
;
1942 assert (frag
->fr_symbol
== 0);
1949 memcpy (buffer
+ frag
->fr_address
,
1951 (unsigned int) frag
->fr_fix
);
1952 offset
+= frag
->fr_fix
;
1955 fill_size
= frag
->fr_var
;
1956 if (fill_size
&& frag
->fr_offset
> 0)
1959 unsigned int off
= frag
->fr_fix
;
1960 for (count
= frag
->fr_offset
; count
; count
--)
1962 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1964 memcpy (buffer
+ frag
->fr_address
+ off
,
1965 frag
->fr_literal
+ frag
->fr_fix
,
1968 offset
+= fill_size
;
1973 case rs_broken_word
:
1978 frag
= frag
->fr_next
;
1983 if (s
->s_scnptr
!= 0)
1985 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1986 *file_cursor
+= s
->s_size
;
1995 /* Coff file generation & utilities */
1998 coff_header_append (abfd
, h
)
2005 #ifdef COFF_LONG_SECTION_NAMES
2006 unsigned long string_size
= 4;
2009 bfd_seek (abfd
, 0, 0);
2011 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
2012 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
2013 H_SET_VERSION_STAMP (h
, 0);
2014 H_SET_ENTRY_POINT (h
, 0);
2015 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
2016 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
2017 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
2019 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2020 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
2021 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
2023 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
2025 bfd_write (buffer
, i
, 1, abfd
);
2026 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
2028 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2030 if (segment_info
[i
].scnhdr
.s_name
[0])
2034 #ifdef COFF_LONG_SECTION_NAMES
2035 /* Support long section names as found in PE. This code
2036 must coordinate with that in write_object_file and
2038 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
2040 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
2041 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
2042 string_size
+= strlen (segment_info
[i
].name
) + 1;
2046 size
= bfd_coff_swap_scnhdr_out (abfd
,
2047 &(segment_info
[i
].scnhdr
),
2050 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
2051 bfd_write (buffer
, size
, 1, abfd
);
2058 symbol_to_chars (abfd
, where
, symbolP
)
2063 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
2067 /* Turn any symbols with register attributes into abs symbols */
2068 if (S_GET_SEGMENT (symbolP
) == reg_section
)
2070 S_SET_SEGMENT (symbolP
, absolute_section
);
2072 /* At the same time, relocate all symbols to their output value */
2075 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
2076 + S_GET_VALUE (symbolP
));
2078 val
= S_GET_VALUE (symbolP
);
2081 S_SET_VALUE (symbolP
, val
);
2083 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2085 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2088 for (i
= 0; i
< numaux
; i
++)
2090 where
+= bfd_coff_swap_aux_out (abfd
,
2091 &symbolP
->sy_symbol
.ost_auxent
[i
],
2092 S_GET_DATA_TYPE (symbolP
),
2093 S_GET_STORAGE_CLASS (symbolP
),
2101 coff_obj_symbol_new_hook (symbolP
)
2104 char underscore
= 0; /* Symbol has leading _ */
2106 /* Effective symbol */
2107 /* Store the pointer in the offset. */
2108 S_SET_ZEROES (symbolP
, 0L);
2109 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2110 S_SET_STORAGE_CLASS (symbolP
, 0);
2111 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2112 /* Additional information */
2113 symbolP
->sy_symbol
.ost_flags
= 0;
2114 /* Auxiliary entries */
2115 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2117 if (S_IS_STRING (symbolP
))
2118 SF_SET_STRING (symbolP
);
2119 if (!underscore
&& S_IS_LOCAL (symbolP
))
2120 SF_SET_LOCAL (symbolP
);
2124 * Handle .ln directives.
2128 obj_coff_ln (appline
)
2133 if (! appline
&& def_symbol_in_progress
!= NULL
)
2135 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2136 demand_empty_rest_of_line ();
2138 } /* wrong context */
2140 l
= get_absolute_expression ();
2141 c_line_new (0, frag_now_fix (), l
, frag_now
);
2144 new_logical_line ((char *) NULL
, l
- 1);
2154 listing_source_line ((unsigned int) l
);
2159 demand_empty_rest_of_line ();
2165 * Handle .def directives.
2167 * One might ask : why can't we symbol_new if the symbol does not
2168 * already exist and fill it with debug information. Because of
2169 * the C_EFCN special symbol. It would clobber the value of the
2170 * function symbol before we have a chance to notice that it is
2171 * a C_EFCN. And a second reason is that the code is more clear this
2172 * way. (at least I think it is :-).
2176 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2177 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2178 *input_line_pointer == '\t') \
2179 input_line_pointer++;
2183 int what ATTRIBUTE_UNUSED
;
2185 char name_end
; /* Char after the end of name */
2186 char *symbol_name
; /* Name of the debug symbol */
2187 char *symbol_name_copy
; /* Temporary copy of the name */
2188 unsigned int symbol_name_length
;
2190 if (def_symbol_in_progress
!= NULL
)
2192 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2193 demand_empty_rest_of_line ();
2195 } /* if not inside .def/.endef */
2197 SKIP_WHITESPACES ();
2199 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2200 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2202 symbol_name
= input_line_pointer
;
2203 name_end
= get_symbol_end ();
2204 symbol_name_length
= strlen (symbol_name
);
2205 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2206 strcpy (symbol_name_copy
, symbol_name
);
2207 #ifdef tc_canonicalize_symbol_name
2208 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2211 /* Initialize the new symbol */
2212 #ifdef STRIP_UNDERSCORE
2213 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2214 ? symbol_name_copy
+ 1
2215 : symbol_name_copy
));
2216 #else /* STRIP_UNDERSCORE */
2217 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2218 #endif /* STRIP_UNDERSCORE */
2219 /* free(symbol_name_copy); */
2220 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2221 def_symbol_in_progress
->sy_number
= ~0;
2222 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2223 S_SET_VALUE (def_symbol_in_progress
, 0);
2225 if (S_IS_STRING (def_symbol_in_progress
))
2226 SF_SET_STRING (def_symbol_in_progress
);
2228 *input_line_pointer
= name_end
;
2230 demand_empty_rest_of_line ();
2233 unsigned int dim_index
;
2237 obj_coff_endef (ignore
)
2238 int ignore ATTRIBUTE_UNUSED
;
2240 symbolS
*symbolP
= 0;
2241 /* DIM BUG FIX sac@cygnus.com */
2243 if (def_symbol_in_progress
== NULL
)
2245 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2246 demand_empty_rest_of_line ();
2248 } /* if not inside .def/.endef */
2250 /* Set the section number according to storage class. */
2251 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2256 SF_SET_TAG (def_symbol_in_progress
);
2257 /* intentional fallthrough */
2260 SF_SET_DEBUG (def_symbol_in_progress
);
2261 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2265 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2266 /* intentional fallthrough */
2268 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2269 /* intentional fallthrough */
2271 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2273 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2275 if (function_lineoff
< 0)
2277 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2278 } /* missing function symbol */
2279 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2281 SF_SET_PROCESS (last_line_symbol
);
2282 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2283 SF_SET_PROCESS (def_symbol_in_progress
);
2284 function_lineoff
= -1;
2286 /* Value is always set to . */
2287 def_symbol_in_progress
->sy_frag
= frag_now
;
2288 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2293 #endif /* C_AUTOARG */
2303 SF_SET_DEBUG (def_symbol_in_progress
);
2304 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2314 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2320 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2322 } /* switch on storage class */
2324 /* Now that we have built a debug symbol, try to find if we should
2325 merge with an existing symbol or not. If a symbol is C_EFCN or
2326 absolute_section or untagged SEG_DEBUG it never merges. We also
2327 don't merge labels, which are in a different namespace, nor
2328 symbols which have not yet been defined since they are typically
2329 unique, nor do we merge tags with non-tags. */
2331 /* Two cases for functions. Either debug followed by definition or
2332 definition followed by debug. For definition first, we will
2333 merge the debug symbol into the definition. For debug first, the
2334 lineno entry MUST point to the definition function or else it
2335 will point off into space when crawl_symbols() merges the debug
2336 symbol into the real symbol. Therefor, let's presume the debug
2337 symbol is a real function reference. */
2339 /* FIXME-SOON If for some reason the definition label/symbol is
2340 never seen, this will probably leave an undefined symbol at link
2343 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2344 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2345 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2346 && !SF_GET_TAG (def_symbol_in_progress
))
2347 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2348 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2349 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2350 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2352 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2357 /* This symbol already exists, merge the newly created symbol
2358 into the old one. This is not mandatory. The linker can
2359 handle duplicate symbols correctly. But I guess that it save
2360 a *lot* of space if the assembly file defines a lot of
2363 /* The debug entry (def_symbol_in_progress) is merged into the
2364 previous definition. */
2366 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2367 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2368 def_symbol_in_progress
= symbolP
;
2370 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2371 || SF_GET_TAG (def_symbol_in_progress
)
2372 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2374 /* For functions, and tags, and static symbols, the symbol
2375 *must* be where the debug symbol appears. Move the
2376 existing symbol to the current place. */
2377 /* If it already is at the end of the symbol list, do nothing */
2378 if (def_symbol_in_progress
!= symbol_lastP
)
2380 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2382 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2383 &symbol_rootP
, &symbol_lastP
);
2384 } /* if not already in place */
2386 } /* normal or mergable */
2388 if (SF_GET_TAG (def_symbol_in_progress
))
2392 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2394 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2395 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2396 def_symbol_in_progress
);
2399 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2401 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2403 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2405 SF_SET_PROCESS (def_symbol_in_progress
);
2407 if (symbolP
== NULL
)
2409 /* That is, if this is the first time we've seen the
2411 symbol_table_insert (def_symbol_in_progress
);
2412 } /* definition follows debug */
2413 } /* Create the line number entry pointing to the function being defined */
2415 def_symbol_in_progress
= NULL
;
2416 demand_empty_rest_of_line ();
2420 obj_coff_dim (ignore
)
2421 int ignore ATTRIBUTE_UNUSED
;
2425 if (def_symbol_in_progress
== NULL
)
2427 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2428 demand_empty_rest_of_line ();
2430 } /* if not inside .def/.endef */
2432 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2434 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2436 SKIP_WHITESPACES ();
2437 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2438 get_absolute_expression ());
2440 switch (*input_line_pointer
)
2443 input_line_pointer
++;
2447 as_warn (_("badly formed .dim directive ignored"));
2448 /* intentional fallthrough */
2456 demand_empty_rest_of_line ();
2460 obj_coff_line (ignore
)
2461 int ignore ATTRIBUTE_UNUSED
;
2466 if (def_symbol_in_progress
== NULL
)
2472 name
= S_GET_NAME (def_symbol_in_progress
);
2473 this_base
= get_absolute_expression ();
2475 /* Only .bf symbols indicate the use of a new base line number; the
2476 line numbers associated with .ef, .bb, .eb are relative to the
2477 start of the containing function. */
2478 if (!strcmp (".bf", name
))
2480 #if 0 /* XXX Can we ever have line numbers going backwards? */
2481 if (this_base
> line_base
)
2484 line_base
= this_base
;
2492 listing_source_line ((unsigned int) line_base
);
2498 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2499 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2501 demand_empty_rest_of_line ();
2505 obj_coff_size (ignore
)
2506 int ignore ATTRIBUTE_UNUSED
;
2508 if (def_symbol_in_progress
== NULL
)
2510 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2511 demand_empty_rest_of_line ();
2513 } /* if not inside .def/.endef */
2515 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2516 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2517 demand_empty_rest_of_line ();
2521 obj_coff_scl (ignore
)
2522 int ignore ATTRIBUTE_UNUSED
;
2524 if (def_symbol_in_progress
== NULL
)
2526 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2527 demand_empty_rest_of_line ();
2529 } /* if not inside .def/.endef */
2531 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2532 demand_empty_rest_of_line ();
2536 obj_coff_tag (ignore
)
2537 int ignore ATTRIBUTE_UNUSED
;
2542 if (def_symbol_in_progress
== NULL
)
2544 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2545 demand_empty_rest_of_line ();
2549 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2550 symbol_name
= input_line_pointer
;
2551 name_end
= get_symbol_end ();
2552 #ifdef tc_canonicalize_symbol_name
2553 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2556 /* Assume that the symbol referred to by .tag is always defined.
2557 This was a bad assumption. I've added find_or_make. xoxorich. */
2558 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2559 (long) tag_find_or_make (symbol_name
));
2560 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2562 as_warn (_("tag not found for .tag %s"), symbol_name
);
2565 SF_SET_TAGGED (def_symbol_in_progress
);
2566 *input_line_pointer
= name_end
;
2568 demand_empty_rest_of_line ();
2572 obj_coff_type (ignore
)
2573 int ignore ATTRIBUTE_UNUSED
;
2575 if (def_symbol_in_progress
== NULL
)
2577 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2578 demand_empty_rest_of_line ();
2580 } /* if not inside .def/.endef */
2582 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2584 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2585 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2587 SF_SET_FUNCTION (def_symbol_in_progress
);
2588 } /* is a function */
2590 demand_empty_rest_of_line ();
2594 obj_coff_val (ignore
)
2595 int ignore ATTRIBUTE_UNUSED
;
2597 if (def_symbol_in_progress
== NULL
)
2599 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2600 demand_empty_rest_of_line ();
2602 } /* if not inside .def/.endef */
2604 if (is_name_beginner (*input_line_pointer
))
2606 char *symbol_name
= input_line_pointer
;
2607 char name_end
= get_symbol_end ();
2609 #ifdef tc_canonicalize_symbol_name
2610 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2613 if (!strcmp (symbol_name
, "."))
2615 def_symbol_in_progress
->sy_frag
= frag_now
;
2616 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2617 /* If the .val is != from the .def (e.g. statics) */
2619 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2621 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2622 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2623 symbol_find_or_make (symbol_name
);
2624 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2625 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2627 /* If the segment is undefined when the forward reference is
2628 resolved, then copy the segment id from the forward
2630 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2632 /* FIXME: gcc can generate address expressions here in
2633 unusual cases (search for "obscure" in sdbout.c). We
2634 just ignore the offset here, thus generating incorrect
2635 debugging information. We ignore the rest of the line
2638 /* Otherwise, it is the name of a non debug symbol and
2639 its value will be calculated later. */
2640 *input_line_pointer
= name_end
;
2642 /* FIXME: this is to avoid an error message in the
2643 FIXME case mentioned just above. */
2644 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2645 ++input_line_pointer
;
2649 S_SET_VALUE (def_symbol_in_progress
,
2650 (valueT
) get_absolute_expression ());
2651 } /* if symbol based */
2653 demand_empty_rest_of_line ();
2658 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2659 read.c, which then calls this object file format specific routine. */
2662 obj_coff_pe_handle_link_once (type
)
2663 enum linkonce_type type
;
2665 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2667 /* We store the type in the seg_info structure, and use it to set up
2668 the auxiliary entry for the section symbol in c_section_symbol. */
2669 seg_info (now_seg
)->linkonce
= type
;
2675 coff_obj_read_begin_hook ()
2677 /* These had better be the same. Usually 18 bytes. */
2679 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2680 know (SYMESZ
== AUXESZ
);
2685 /* This function runs through the symbol table and puts all the
2686 externals onto another chain */
2688 /* The chain of globals. */
2689 symbolS
*symbol_globalP
;
2690 symbolS
*symbol_global_lastP
;
2692 /* The chain of externals */
2693 symbolS
*symbol_externP
;
2694 symbolS
*symbol_extern_lastP
;
2697 symbolS
*last_functionP
;
2698 static symbolS
*last_bfP
;
2705 unsigned int symbol_number
= 0;
2706 unsigned int last_file_symno
= 0;
2708 struct filename_list
*filename_list_scan
= filename_list_head
;
2710 for (symbolP
= symbol_rootP
;
2712 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2714 if (symbolP
->sy_mri_common
)
2716 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2718 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2720 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
)
2721 as_bad (_("%s: global symbols not supported in common sections"),
2722 S_GET_NAME (symbolP
));
2723 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2727 if (!SF_GET_DEBUG (symbolP
))
2729 /* Debug symbols do not need all this rubbish */
2730 symbolS
*real_symbolP
;
2732 /* L* and C_EFCN symbols never merge. */
2733 if (!SF_GET_LOCAL (symbolP
)
2734 && !SF_GET_STATICS (symbolP
)
2735 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2736 && symbolP
->sy_value
.X_op
== O_constant
2737 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2738 && real_symbolP
!= symbolP
)
2740 /* FIXME-SOON: where do dups come from?
2741 Maybe tag references before definitions? xoxorich. */
2742 /* Move the debug data from the debug symbol to the
2743 real symbol. Do NOT do the oposite (i.e. move from
2744 real symbol to debug symbol and remove real symbol from the
2745 list.) Because some pointers refer to the real symbol
2746 whereas no pointers refer to the debug symbol. */
2747 c_symbol_merge (symbolP
, real_symbolP
);
2748 /* Replace the current symbol by the real one */
2749 /* The symbols will never be the last or the first
2750 because : 1st symbol is .file and 3 last symbols are
2751 .text, .data, .bss */
2752 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2753 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2754 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2755 symbolP
= real_symbolP
;
2756 } /* if not local but dup'd */
2758 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2760 S_SET_SEGMENT (symbolP
, SEG_E0
);
2761 } /* push data into text */
2763 resolve_symbol_value (symbolP
, 1);
2765 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2767 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2769 S_SET_EXTERNAL (symbolP
);
2771 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2773 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2777 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2781 /* Mainly to speed up if not -g */
2782 if (SF_GET_PROCESS (symbolP
))
2784 /* Handle the nested blocks auxiliary info. */
2785 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2787 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2788 stack_push (block_stack
, (char *) &symbolP
);
2791 register symbolS
*begin_symbolP
;
2792 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2793 if (begin_symbolP
== (symbolS
*) 0)
2794 as_warn (_("mismatched .eb"));
2796 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2799 /* If we are able to identify the type of a function, and we
2800 are out of a function (last_functionP == 0) then, the
2801 function symbol will be associated with an auxiliary
2803 if (last_functionP
== (symbolS
*) 0 &&
2804 SF_GET_FUNCTION (symbolP
))
2806 last_functionP
= symbolP
;
2808 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2810 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2811 } /* make it at least 1 */
2813 /* Clobber possible stale .dim information. */
2815 /* Iffed out by steve - this fries the lnnoptr info too */
2816 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2817 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2820 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2822 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2824 if (last_bfP
!= NULL
)
2825 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2829 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2831 /* I don't even know if this is needed for sdb. But
2832 the standard assembler generates it, so... */
2833 if (last_functionP
== (symbolS
*) 0)
2834 as_fatal (_("C_EFCN symbol out of scope"));
2835 SA_SET_SYM_FSIZE (last_functionP
,
2836 (long) (S_GET_VALUE (symbolP
) -
2837 S_GET_VALUE (last_functionP
)));
2838 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2839 last_functionP
= (symbolS
*) 0;
2843 else if (SF_GET_TAG (symbolP
))
2845 /* First descriptor of a structure must point to
2846 the first slot after the structure description. */
2847 last_tagP
= symbolP
;
2850 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2852 /* +2 take in account the current symbol */
2853 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2855 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2857 /* If the filename was too long to fit in the
2858 auxent, put it in the string table */
2859 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2860 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2862 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2863 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2864 filename_list_scan
= filename_list_scan
->next
;
2866 if (S_GET_VALUE (symbolP
))
2868 S_SET_VALUE (symbolP
, last_file_symno
);
2869 last_file_symno
= symbol_number
;
2870 } /* no one points at the first .file symbol */
2871 } /* if debug or tag or eos or file */
2873 #ifdef tc_frob_coff_symbol
2874 tc_frob_coff_symbol (symbolP
);
2877 /* We must put the external symbols apart. The loader
2878 does not bomb if we do not. But the references in
2879 the endndx field for a .bb symbol are not corrected
2880 if an external symbol is removed between .bb and .be.
2881 I.e in the following case :
2882 [20] .bb endndx = 22
2885 ld will move the symbol 21 to the end of the list but
2886 endndx will still be 22 instead of 21. */
2889 if (SF_GET_LOCAL (symbolP
))
2891 /* remove C_EFCN and LOCAL (L...) symbols */
2892 /* next pointer remains valid */
2893 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2896 else if (symbolP
->sy_value
.X_op
== O_symbol
2897 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2899 /* Skip symbols which were equated to undefined or common
2901 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2903 else if (!S_IS_DEFINED (symbolP
)
2904 && !S_IS_DEBUG (symbolP
)
2905 && !SF_GET_STATICS (symbolP
)
2906 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2908 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2910 || S_GET_STORAGE_CLASS (symbolP
) == C_WEAKEXT
))
2912 /* if external, Remove from the list */
2913 symbolS
*hold
= symbol_previous (symbolP
);
2915 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2916 symbol_clear_list_pointers (symbolP
);
2917 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2920 else if (! S_IS_DEBUG (symbolP
)
2921 && ! SF_GET_STATICS (symbolP
)
2922 && ! SF_GET_FUNCTION (symbolP
)
2923 && (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
2925 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
2927 || S_GET_STORAGE_CLASS (symbolP
) == C_NT_WEAK
))
2929 symbolS
*hold
= symbol_previous (symbolP
);
2931 /* The O'Reilly COFF book says that defined global symbols
2932 come at the end of the symbol table, just before
2933 undefined global symbols. */
2935 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2936 symbol_clear_list_pointers (symbolP
);
2937 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2938 &symbol_global_lastP
);
2943 if (SF_GET_STRING (symbolP
))
2945 symbolP
->sy_name_offset
= string_byte_count
;
2946 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2950 symbolP
->sy_name_offset
= 0;
2951 } /* fix "long" names */
2953 symbolP
->sy_number
= symbol_number
;
2954 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2955 } /* if local symbol */
2956 } /* traverse the symbol list */
2957 return symbol_number
;
2963 glue_symbols (head
, tail
)
2967 unsigned int symbol_number
= 0;
2969 while (*head
!= NULL
)
2971 symbolS
*tmp
= *head
;
2974 symbol_remove (tmp
, head
, tail
);
2975 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2978 if (SF_GET_STRING (tmp
))
2980 tmp
->sy_name_offset
= string_byte_count
;
2981 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2985 tmp
->sy_name_offset
= 0;
2986 } /* fix "long" names */
2988 tmp
->sy_number
= symbol_number
;
2989 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2990 } /* append the entire extern chain */
2992 return symbol_number
;
2998 unsigned int symbol_number
= 0;
3001 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3003 symbolP
->sy_number
= symbol_number
;
3005 if (SF_GET_TAGGED (symbolP
))
3009 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
3012 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
3015 return symbol_number
;
3019 crawl_symbols (h
, abfd
)
3021 bfd
*abfd ATTRIBUTE_UNUSED
;
3025 /* Initialize the stack used to keep track of the matching .bb .be */
3027 block_stack
= stack_init (512, sizeof (symbolS
*));
3029 /* The symbol list should be ordered according to the following sequence
3032 * . debug entries for functions
3033 * . fake symbols for the sections, including .text .data and .bss
3035 * . undefined symbols
3036 * But this is not mandatory. The only important point is to put the
3037 * undefined symbols at the end of the list.
3040 /* Is there a .file symbol ? If not insert one at the beginning. */
3041 if (symbol_rootP
== NULL
3042 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
3044 c_dot_file_symbol ("fake");
3048 * Build up static symbols for the sections, they are filled in later
3052 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3053 if (segment_info
[i
].scnhdr
.s_name
[0])
3054 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
3057 /* Take all the externals out and put them into another chain */
3058 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
3059 /* Take the externals and glue them onto the end.*/
3060 H_SET_SYMBOL_TABLE_SIZE (h
,
3061 (H_GET_SYMBOL_COUNT (h
)
3062 + glue_symbols (&symbol_globalP
,
3063 &symbol_global_lastP
)
3064 + glue_symbols (&symbol_externP
,
3065 &symbol_extern_lastP
)));
3067 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
3068 know (symbol_globalP
== NULL
);
3069 know (symbol_global_lastP
== NULL
);
3070 know (symbol_externP
== NULL
);
3071 know (symbol_extern_lastP
== NULL
);
3075 * Find strings by crawling along symbol table chain.
3083 struct filename_list
*filename_list_scan
= filename_list_head
;
3085 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
3086 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
3089 #ifdef COFF_LONG_SECTION_NAMES
3090 /* Support long section names as found in PE. This code must
3091 coordinate with that in coff_header_append and write_object_file. */
3095 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3097 if (segment_info
[i
].scnhdr
.s_name
[0]
3098 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3102 size
= strlen (segment_info
[i
].name
) + 1;
3103 memcpy (where
, segment_info
[i
].name
, size
);
3108 #endif /* COFF_LONG_SECTION_NAMES */
3110 for (symbolP
= symbol_rootP
;
3112 symbolP
= symbol_next (symbolP
))
3116 if (SF_GET_STRING (symbolP
))
3118 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3119 memcpy (where
, S_GET_NAME (symbolP
), size
);
3122 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3123 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3124 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3126 size
= strlen (filename_list_scan
->filename
) + 1;
3127 memcpy (where
, filename_list_scan
->filename
, size
);
3128 filename_list_scan
= filename_list_scan
->next
;
3135 do_linenos_for (abfd
, h
, file_cursor
)
3138 unsigned long *file_cursor
;
3141 unsigned long start
= *file_cursor
;
3143 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3145 segment_info_type
*s
= segment_info
+ idx
;
3148 if (s
->scnhdr
.s_nlnno
!= 0)
3150 struct lineno_list
*line_ptr
;
3152 struct external_lineno
*buffer
=
3153 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3155 struct external_lineno
*dst
= buffer
;
3157 /* Run through the table we've built and turn it into its external
3158 form, take this chance to remove duplicates */
3160 for (line_ptr
= s
->lineno_list_head
;
3161 line_ptr
!= (struct lineno_list
*) NULL
;
3162 line_ptr
= line_ptr
->next
)
3165 if (line_ptr
->line
.l_lnno
== 0)
3167 /* Turn a pointer to a symbol into the symbols' index */
3168 line_ptr
->line
.l_addr
.l_symndx
=
3169 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3173 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3177 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3182 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3184 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3187 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3190 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3194 /* Now we run through the list of frag chains in a segment and
3195 make all the subsegment frags appear at the end of the
3196 list, as if the seg 0 was extra long */
3203 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3205 frchainS
*head
= segment_info
[i
].frchainP
;
3207 fragS
*prev_frag
= &dummy
;
3209 while (head
&& head
->frch_seg
== i
)
3211 prev_frag
->fr_next
= head
->frch_root
;
3212 prev_frag
= head
->frch_last
;
3213 head
= head
->frch_next
;
3215 prev_frag
->fr_next
= 0;
3219 unsigned long machine
;
3222 write_object_file ()
3226 struct frchain
*frchain_ptr
;
3228 object_headers headers
;
3229 unsigned long file_cursor
;
3232 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3237 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3238 exit (EXIT_FAILURE
);
3240 bfd_set_format (abfd
, bfd_object
);
3241 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3243 string_byte_count
= 4;
3245 for (frchain_ptr
= frchain_root
;
3246 frchain_ptr
!= (struct frchain
*) NULL
;
3247 frchain_ptr
= frchain_ptr
->frch_next
)
3249 /* Run through all the sub-segments and align them up. Also
3250 close any open frags. We tack a .fill onto the end of the
3251 frag chain so that any .align's size can be worked by looking
3252 at the next frag. */
3254 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3256 #ifndef SUB_SEGMENT_ALIGN
3257 #define SUB_SEGMENT_ALIGN(SEG) 1
3260 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3263 frag_align (SUB_SEGMENT_ALIGN (now_seg
),
3264 subseg_text_p (now_seg
) ? NOP_OPCODE
: 0,
3269 frag_wane (frag_now
);
3270 frag_now
->fr_fix
= 0;
3271 know (frag_now
->fr_next
== NULL
);
3278 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3280 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3283 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3285 /* Find out how big the sections are, and set the addresses. */
3287 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3291 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3292 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3294 if (segment_info
[i
].scnhdr
.s_name
[0])
3296 H_SET_NUMBER_OF_SECTIONS (&headers
,
3297 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3299 #ifdef COFF_LONG_SECTION_NAMES
3300 /* Support long section names as found in PE. This code
3301 must coordinate with that in coff_header_append and
3306 len
= strlen (segment_info
[i
].name
);
3308 string_byte_count
+= len
+ 1;
3310 #endif /* COFF_LONG_SECTION_NAMES */
3313 size
= size_section (abfd
, (unsigned int) i
);
3316 /* I think the section alignment is only used on the i960; the
3317 i960 needs it, and it should do no harm on other targets. */
3318 #ifdef ALIGNMENT_IN_S_FLAGS
3319 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3321 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3325 H_SET_TEXT_SIZE (&headers
, size
);
3326 else if (i
== SEG_E1
)
3327 H_SET_DATA_SIZE (&headers
, size
);
3328 else if (i
== SEG_E2
)
3329 H_SET_BSS_SIZE (&headers
, size
);
3332 /* Turn the gas native symbol table shape into a coff symbol table */
3333 crawl_symbols (&headers
, abfd
);
3335 if (string_byte_count
== 4)
3336 string_byte_count
= 0;
3338 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3344 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3346 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3347 fixup_segment (&segment_info
[i
], i
);
3350 /* Look for ".stab" segments and fill in their initial symbols
3352 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3354 name
= segment_info
[i
].name
;
3357 && strncmp (".stab", name
, 5) == 0
3358 && strncmp (".stabstr", name
, 8) != 0)
3359 adjust_stab_section (abfd
, i
);
3362 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3364 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3366 /* Plant the data */
3368 fill_section (abfd
, &headers
, &file_cursor
);
3370 do_relocs_for (abfd
, &headers
, &file_cursor
);
3372 do_linenos_for (abfd
, &headers
, &file_cursor
);
3374 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3375 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3376 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3378 H_SET_TIME_STAMP (&headers
, 0);
3380 #ifdef TC_COFF_SET_MACHINE
3381 TC_COFF_SET_MACHINE (&headers
);
3385 #define COFF_FLAGS 0
3388 #ifdef KEEP_RELOC_INFO
3389 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3390 COFF_FLAGS
| coff_flags
));
3392 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3393 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3394 COFF_FLAGS
| coff_flags
));
3398 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3399 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3401 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3402 w_symbols (abfd
, buffer1
, symbol_rootP
);
3403 if (string_byte_count
> 0)
3404 w_strings (buffer1
+ symtable_size
);
3405 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3409 coff_header_append (abfd
, &headers
);
3411 /* Recent changes to write need this, but where it should
3412 go is up to Ken.. */
3413 if (bfd_close_all_done (abfd
) == false)
3414 as_fatal (_("Can't close %s: %s"), out_file_name
,
3415 bfd_errmsg (bfd_get_error ()));
3418 extern bfd
*stdoutput
;
3425 /* Add a new segment. This is called from subseg_new via the
3426 obj_new_segment macro. */
3429 obj_coff_add_segment (name
)
3434 #ifndef COFF_LONG_SECTION_NAMES
3435 char buf
[SCNNMLEN
+ 1];
3437 strncpy (buf
, name
, SCNNMLEN
);
3438 buf
[SCNNMLEN
] = '\0';
3442 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3443 if (strcmp (name
, segment_info
[i
].name
) == 0)
3448 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3452 /* Add a new section. */
3453 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3454 sizeof (segment_info
[i
].scnhdr
.s_name
));
3455 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3456 segment_info
[i
].name
= xstrdup (name
);
3462 * implement the .section pseudo op:
3463 * .section name {, "flags"}
3465 * | +--- optional flags: 'b' for bss
3467 * +-- section name 'l' for lib
3471 * 'd' (apparently m88k for data)
3473 * 'r' for read-only data
3474 * But if the argument is not a quoted string, treat it as a
3475 * subsegment number.
3479 obj_coff_section (ignore
)
3480 int ignore ATTRIBUTE_UNUSED
;
3482 /* Strip out the section name */
3483 char *section_name
, *name
;
3496 else if (type
== 'D')
3498 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3503 section_name
= input_line_pointer
;
3504 c
= get_symbol_end ();
3506 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3507 strcpy (name
, section_name
);
3509 *input_line_pointer
= c
;
3515 if (*input_line_pointer
== ',')
3517 ++input_line_pointer
;
3520 if (*input_line_pointer
!= '"')
3521 exp
= get_absolute_expression ();
3524 ++input_line_pointer
;
3525 while (*input_line_pointer
!= '"'
3526 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3528 switch (*input_line_pointer
)
3530 case 'b': flags
|= STYP_BSS
; break;
3531 case 'i': flags
|= STYP_INFO
; break;
3532 case 'l': flags
|= STYP_LIB
; break;
3533 case 'n': flags
|= STYP_NOLOAD
; break;
3534 case 'o': flags
|= STYP_OVER
; break;
3536 case 'w': flags
|= STYP_DATA
; break;
3537 case 'x': flags
|= STYP_TEXT
; break;
3538 case 'r': flags
|= STYP_LIT
; break;
3540 as_warn(_("unknown section attribute '%c'"),
3541 *input_line_pointer
);
3544 ++input_line_pointer
;
3546 if (*input_line_pointer
== '"')
3547 ++input_line_pointer
;
3551 subseg_new (name
, (subsegT
) exp
);
3553 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3555 demand_empty_rest_of_line ();
3560 obj_coff_text (ignore
)
3561 int ignore ATTRIBUTE_UNUSED
;
3563 subseg_new (".text", get_absolute_expression ());
3568 obj_coff_data (ignore
)
3569 int ignore ATTRIBUTE_UNUSED
;
3571 if (flag_readonly_data_in_text
)
3572 subseg_new (".text", get_absolute_expression () + 1000);
3574 subseg_new (".data", get_absolute_expression ());
3578 obj_coff_ident (ignore
)
3579 int ignore ATTRIBUTE_UNUSED
;
3581 segT current_seg
= now_seg
; /* save current seg */
3582 subsegT current_subseg
= now_subseg
;
3583 subseg_new (".comment", 0); /* .comment seg */
3584 stringer (1); /* read string */
3585 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3589 c_symbol_merge (debug
, normal
)
3593 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3594 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3596 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3598 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3599 } /* take the most we have */
3601 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3603 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3604 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3605 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3606 } /* Move all the auxiliary information */
3608 /* Move the debug flags. */
3609 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3610 } /* c_symbol_merge() */
3613 c_line_new (symbol
, paddr
, line_number
, frag
)
3619 struct lineno_list
*new_line
=
3620 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3622 segment_info_type
*s
= segment_info
+ now_seg
;
3623 new_line
->line
.l_lnno
= line_number
;
3625 if (line_number
== 0)
3627 last_line_symbol
= symbol
;
3628 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3632 new_line
->line
.l_addr
.l_paddr
= paddr
;
3635 new_line
->frag
= (char *) frag
;
3636 new_line
->next
= (struct lineno_list
*) NULL
;
3639 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3641 s
->lineno_list_head
= new_line
;
3645 s
->lineno_list_tail
->next
= new_line
;
3647 s
->lineno_list_tail
= new_line
;
3648 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3652 c_dot_file_symbol (filename
)
3657 symbolP
= symbol_new (".file",
3660 &zero_address_frag
);
3662 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3663 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3665 if (strlen (filename
) > FILNMLEN
)
3667 /* Filename is too long to fit into an auxent,
3668 we stick it into the string table instead. We keep
3669 a linked list of the filenames we find so we can emit
3671 struct filename_list
*f
= ((struct filename_list
*)
3672 xmalloc (sizeof (struct filename_list
)));
3674 f
->filename
= filename
;
3677 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3678 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3680 if (filename_list_tail
)
3681 filename_list_tail
->next
= f
;
3683 filename_list_head
= f
;
3684 filename_list_tail
= f
;
3688 SA_SET_FILE_FNAME (symbolP
, filename
);
3695 listing_source_file (filename
);
3701 SF_SET_DEBUG (symbolP
);
3702 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3704 previous_file_symbol
= symbolP
;
3706 /* Make sure that the symbol is first on the symbol chain */
3707 if (symbol_rootP
!= symbolP
)
3709 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3710 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3712 } /* c_dot_file_symbol() */
3715 * Build a 'section static' symbol.
3719 c_section_symbol (name
, idx
)
3725 symbolP
= symbol_find_base (name
, DO_NOT_STRIP
);
3726 if (symbolP
== NULL
)
3727 symbolP
= symbol_new (name
, idx
, 0, &zero_address_frag
);
3730 /* Mmmm. I just love violating interfaces. Makes me feel...dirty. */
3731 S_SET_SEGMENT (symbolP
, idx
);
3732 symbolP
->sy_frag
= &zero_address_frag
;
3735 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3736 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3738 SF_SET_STATICS (symbolP
);
3741 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3742 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3743 SF_CLEAR_LOCAL (symbolP
);
3746 /* If the .linkonce pseudo-op was used for this section, we must
3747 store the information in the auxiliary entry for the section
3749 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3753 switch (segment_info
[idx
].linkonce
)
3757 case LINKONCE_DISCARD
:
3758 type
= IMAGE_COMDAT_SELECT_ANY
;
3760 case LINKONCE_ONE_ONLY
:
3761 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3763 case LINKONCE_SAME_SIZE
:
3764 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3766 case LINKONCE_SAME_CONTENTS
:
3767 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3771 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3776 } /* c_section_symbol() */
3779 w_symbols (abfd
, where
, symbol_rootP
)
3782 symbolS
* symbol_rootP
;
3787 /* First fill in those values we have only just worked out */
3788 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3790 symbolP
= segment_info
[i
].dot
;
3793 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3794 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3795 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3800 * Emit all symbols left in the symbol chain.
3802 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3804 /* Used to save the offset of the name. It is used to point
3805 to the string in memory but must be a file offset. */
3806 register char *temp
;
3808 /* We can't fix the lnnoptr field in yank_symbols with the other
3809 adjustments, because we have to wait until we know where they
3811 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3813 SA_GET_SYM_LNNOPTR (symbolP
) +=
3814 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3817 tc_coff_symbol_emit_hook (symbolP
);
3819 temp
= S_GET_NAME (symbolP
);
3820 if (SF_GET_STRING (symbolP
))
3822 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3823 S_SET_ZEROES (symbolP
, 0);
3827 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3828 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3830 where
= symbol_to_chars (abfd
, where
, symbolP
);
3831 S_SET_NAME (symbolP
, temp
);
3837 obj_coff_lcomm (ignore
)
3838 int ignore ATTRIBUTE_UNUSED
;
3850 name
= input_line_pointer
;
3852 c
= get_symbol_end ();
3853 p
= input_line_pointer
;
3856 if (*input_line_pointer
!= ',')
3858 as_bad (_("Expected comma after name"));
3859 ignore_rest_of_line ();
3862 if (*input_line_pointer
== '\n')
3864 as_bad (_("Missing size expression"));
3867 input_line_pointer
++;
3868 if ((temp
= get_absolute_expression ()) < 0)
3870 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3871 ignore_rest_of_line ();
3876 symbolP
= symbol_find_or_make(name
);
3878 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3879 S_GET_VALUE(symbolP
) == 0)
3884 segT current_seg
= now_seg
; /* save current seg */
3885 subsegT current_subseg
= now_subseg
;
3887 subseg_set (SEG_E2
, 1);
3888 symbolP
->sy_frag
= frag_now
;
3889 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3890 (offsetT
) temp
, (char *) 0);
3892 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3893 S_SET_SEGMENT(symbolP
, SEG_E2
);
3894 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3898 as_bad(_("Symbol %s already defined"), name
);
3900 demand_empty_rest_of_line();
3905 fixup_mdeps (frags
, h
, this_segment
)
3910 subseg_change (this_segment
, 0);
3913 switch (frags
->fr_type
)
3919 HANDLE_ALIGN (frags
);
3921 frags
->fr_type
= rs_fill
;
3923 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3926 case rs_machine_dependent
:
3927 md_convert_frag (h
, this_segment
, frags
);
3933 frags
= frags
->fr_next
;
3939 #ifndef TC_FORCE_RELOCATION
3940 #define TC_FORCE_RELOCATION(fix) 0
3944 fixup_segment (segP
, this_segment_type
)
3945 segment_info_type
* segP
;
3946 segT this_segment_type
;
3948 register fixS
* fixP
;
3949 register symbolS
*add_symbolP
;
3950 register symbolS
*sub_symbolP
;
3953 register char *place
;
3954 register long where
;
3955 register char pcrel
;
3956 register fragS
*fragP
;
3957 register segT add_symbol_segment
= absolute_section
;
3959 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3961 fragP
= fixP
->fx_frag
;
3963 where
= fixP
->fx_where
;
3964 place
= fragP
->fr_literal
+ where
;
3965 size
= fixP
->fx_size
;
3966 add_symbolP
= fixP
->fx_addsy
;
3967 sub_symbolP
= fixP
->fx_subsy
;
3968 add_number
= fixP
->fx_offset
;
3969 pcrel
= fixP
->fx_pcrel
;
3971 /* We want function-relative stabs to work on systems which
3972 may use a relaxing linker; thus we must handle the sym1-sym2
3973 fixups function-relative stabs generates.
3975 Of course, if you actually enable relaxing in the linker, the
3976 line and block scoping information is going to be incorrect
3977 in some cases. The only way to really fix this is to support
3978 a reloc involving the difference of two symbols. */
3980 && (!sub_symbolP
|| pcrel
))
3984 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3986 /* Relocation should be done via the associated 'bal' entry
3989 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3991 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3992 _("No 'bal' entry point for leafproc %s"),
3993 S_GET_NAME (add_symbolP
));
3996 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
4000 /* Make sure the symbols have been resolved; this may not have
4001 happened if these are expression symbols. */
4002 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
4003 resolve_symbol_value (add_symbolP
, 1);
4005 if (add_symbolP
!= NULL
)
4007 /* If this fixup is against a symbol which has been equated
4008 to another symbol, convert it to the other symbol. */
4009 if (add_symbolP
->sy_value
.X_op
== O_symbol
4010 && (! S_IS_DEFINED (add_symbolP
)
4011 || S_IS_COMMON (add_symbolP
)))
4013 while (add_symbolP
->sy_value
.X_op
== O_symbol
4014 && (! S_IS_DEFINED (add_symbolP
)
4015 || S_IS_COMMON (add_symbolP
)))
4019 /* We must avoid looping, as that can occur with a
4020 badly written program. */
4021 n
= add_symbolP
->sy_value
.X_add_symbol
;
4022 if (n
== add_symbolP
)
4024 add_number
+= add_symbolP
->sy_value
.X_add_number
;
4027 fixP
->fx_addsy
= add_symbolP
;
4028 fixP
->fx_offset
= add_number
;
4032 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
4033 resolve_symbol_value (sub_symbolP
, 1);
4035 if (add_symbolP
!= NULL
4036 && add_symbolP
->sy_mri_common
)
4038 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
4039 add_number
+= S_GET_VALUE (add_symbolP
);
4040 fixP
->fx_offset
= add_number
;
4041 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
4046 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
4047 } /* if there is an addend */
4051 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
4053 if (add_symbolP
!= NULL
)
4055 add_number
+= S_GET_VALUE (add_symbolP
);
4057 fixP
->fx_addsy
= NULL
;
4060 /* It's just -sym. */
4061 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
4063 add_number
-= S_GET_VALUE (sub_symbolP
);
4070 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4071 _("Negative of non-absolute symbol %s"),
4072 S_GET_NAME (sub_symbolP
));
4074 add_number
-= S_GET_VALUE (sub_symbolP
);
4075 } /* not absolute */
4077 /* if sub_symbol is in the same segment that add_symbol
4078 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
4080 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
4081 && SEG_NORMAL (add_symbol_segment
))
4083 /* Difference of 2 symbols from same segment. Can't
4084 make difference of 2 undefineds: 'value' means
4085 something different for N_UNDF. */
4087 /* Makes no sense to use the difference of 2 arbitrary symbols
4088 as the target of a call instruction. */
4091 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4092 _("callj to difference of 2 symbols"));
4094 #endif /* TC_I960 */
4095 add_number
+= S_GET_VALUE (add_symbolP
) -
4096 S_GET_VALUE (sub_symbolP
);
4099 if (!TC_FORCE_RELOCATION (fixP
))
4101 fixP
->fx_addsy
= NULL
;
4102 fixP
->fx_subsy
= NULL
;
4104 #ifdef TC_M68K /* is this right? */
4112 /* Different segments in subtraction. */
4113 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4115 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4117 add_number
-= S_GET_VALUE (sub_symbolP
);
4120 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4121 #if 0 /* Okay for 68k, at least... */
4126 /* Make it pc-relative. */
4127 add_number
+= (md_pcrel_from (fixP
)
4128 - S_GET_VALUE (sub_symbolP
));
4137 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4138 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4139 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4140 S_GET_NAME (sub_symbolP
),
4141 (long) (fragP
->fr_address
+ where
));
4144 } /* if sub_symbolP */
4148 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4151 * This fixup was made when the symbol's segment was
4152 * SEG_UNKNOWN, but it is now in the local segment.
4153 * So we know how to do the address without relocation.
4156 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4157 * in which cases it modifies *fixP as appropriate. In the case
4158 * of a 'calls', no further work is required, and *fixP has been
4159 * set up to make the rest of the code below a no-op.
4162 #endif /* TC_I960 */
4164 add_number
+= S_GET_VALUE (add_symbolP
);
4165 add_number
-= md_pcrel_from (fixP
);
4168 add_number -= segP->scnhdr.s_vaddr;
4169 if defined (TC_I386) || defined (TE_LYNX). I now
4170 think that was an error propagated from the case when
4171 we are going to emit the relocation. If we are not
4172 going to emit the relocation, then we just want to
4173 set add_number to the difference between the symbols.
4174 This is a case that would only arise when there is a
4175 PC relative reference from a section other than .text
4176 to a symbol defined in the same section, and the
4177 reference is not relaxed. Since jump instructions on
4178 the i386 are relaxed, this could only arise with a
4179 call instruction. */
4181 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4182 if (!TC_FORCE_RELOCATION (fixP
))
4184 fixP
->fx_addsy
= NULL
;
4190 switch (add_symbol_segment
)
4192 case absolute_section
:
4194 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4195 #endif /* TC_I960 */
4196 add_number
+= S_GET_VALUE (add_symbolP
);
4199 if (!TC_FORCE_RELOCATION (fixP
))
4201 fixP
->fx_addsy
= NULL
;
4208 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4209 /* This really should be handled in the linker, but
4210 backward compatibility forbids. */
4211 add_number
+= S_GET_VALUE (add_symbolP
);
4213 add_number
+= S_GET_VALUE (add_symbolP
) +
4214 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4220 if ((int) fixP
->fx_bit_fixP
== 13)
4222 /* This is a COBR instruction. They have only a
4223 * 13-bit displacement and are only to be used
4224 * for local branches: flag as error, don't generate
4227 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4228 _("can't use COBR format with external label"));
4229 fixP
->fx_addsy
= NULL
;
4233 #endif /* TC_I960 */
4234 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4235 /* 386 COFF uses a peculiar format in which the
4236 value of a common symbol is stored in the .text
4237 segment (I've checked this on SVR3.2 and SCO
4238 3.2.2) Ian Taylor <ian@cygnus.com>. */
4239 /* This is also true for 68k COFF on sysv machines
4240 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4241 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4242 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4243 if (S_IS_COMMON (add_symbolP
))
4244 add_number
+= S_GET_VALUE (add_symbolP
);
4249 } /* switch on symbol seg */
4250 } /* if not in local seg */
4251 } /* if there was a + symbol */
4255 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4256 /* This adjustment is not correct on the m88k, for which the
4257 linker does all the computation. */
4258 add_number
-= md_pcrel_from (fixP
);
4260 if (add_symbolP
== 0)
4262 fixP
->fx_addsy
= &abs_symbol
;
4263 } /* if there's an add_symbol */
4264 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4265 /* On the 386 we must adjust by the segment vaddr as well.
4268 I changed the i960 to work this way as well. This is
4269 compatible with the current GNU linker behaviour. I do
4270 not know what other i960 COFF assemblers do. This is not
4271 a common case: normally, only assembler code will contain
4272 a PC relative reloc, and only branches which do not
4273 originate in the .text section will have a non-zero
4276 I changed the m68k to work this way as well. This will
4277 break existing PC relative relocs from sections which do
4278 not start at address 0, but it will make ld -r work.
4279 Ian Taylor, 4 Oct 96. */
4281 add_number
-= segP
->scnhdr
.s_vaddr
;
4285 #ifdef MD_APPLY_FIX3
4286 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4288 md_apply_fix (fixP
, add_number
);
4291 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4294 /* The m88k uses the offset field of the reloc to get around
4297 && ((add_number
& ~0xFF)
4298 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4299 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4300 || (add_number
& 0x80) == 0))
4302 && ((add_number
& ~0xFFFF)
4303 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4304 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4305 || (add_number
& 0x8000) == 0)))
4307 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4308 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4309 (long) add_number
, size
,
4310 (unsigned long) (fragP
->fr_address
+ where
));
4313 #ifdef WARN_SIGNED_OVERFLOW_WORD
4314 /* Warn if a .word value is too large when treated as a
4315 signed number. We already know it is not too negative.
4316 This is to catch over-large switches generated by gcc on
4318 if (!flag_signed_overflow_ok
4320 && add_number
> 0x7fff)
4321 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4322 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4324 (unsigned long) (fragP
->fr_address
+ where
));
4326 } /* not a bit fix */
4327 } /* For each fixS in this segment. */
4328 } /* fixup_segment() */
4332 /* The first entry in a .stab section is special. */
4335 obj_coff_init_stab_section (seg
)
4341 unsigned int stroff
;
4343 /* Make space for this first symbol. */
4347 as_where (&file
, (unsigned int *) NULL
);
4348 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4349 strcpy (stabstr_name
, segment_info
[seg
].name
);
4350 strcat (stabstr_name
, "str");
4351 stroff
= get_stab_string_offset (file
, stabstr_name
);
4353 md_number_to_chars (p
, stroff
, 4);
4356 /* Fill in the counts in the first entry in a .stab section. */
4359 adjust_stab_section(abfd
, seg
)
4363 segT stabstrseg
= SEG_UNKNOWN
;
4364 const char *secname
, *name2
;
4367 int i
, strsz
= 0, nsyms
;
4368 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4370 /* Look for the associated string table section. */
4372 secname
= segment_info
[seg
].name
;
4373 name
= (char *) alloca (strlen (secname
) + 4);
4374 strcpy (name
, secname
);
4375 strcat (name
, "str");
4377 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4379 name2
= segment_info
[i
].name
;
4380 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4387 /* If we found the section, get its size. */
4388 if (stabstrseg
!= SEG_UNKNOWN
)
4389 strsz
= size_section (abfd
, stabstrseg
);
4391 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4393 /* Look for the first frag of sufficient size for the initial stab
4394 symbol, and collect a pointer to it. */
4395 while (frag
&& frag
->fr_fix
< 12)
4396 frag
= frag
->fr_next
;
4398 p
= frag
->fr_literal
;
4401 /* Write in the number of stab symbols and the size of the string
4403 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4404 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4407 #endif /* not BFD_ASSEMBLER */
4409 const pseudo_typeS obj_pseudo_table
[] =
4411 {"def", obj_coff_def
, 0},
4412 {"dim", obj_coff_dim
, 0},
4413 {"endef", obj_coff_endef
, 0},
4414 {"line", obj_coff_line
, 0},
4415 {"ln", obj_coff_ln
, 0},
4416 {"appline", obj_coff_ln
, 1},
4417 {"scl", obj_coff_scl
, 0},
4418 {"size", obj_coff_size
, 0},
4419 {"tag", obj_coff_tag
, 0},
4420 {"type", obj_coff_type
, 0},
4421 {"val", obj_coff_val
, 0},
4422 {"section", obj_coff_section
, 0},
4423 {"sect", obj_coff_section
, 0},
4424 /* FIXME: We ignore the MRI short attribute. */
4425 {"section.s", obj_coff_section
, 0},
4426 {"sect.s", obj_coff_section
, 0},
4427 /* We accept the .bss directive for backward compatibility with
4428 earlier versions of gas. */
4429 {"bss", obj_coff_bss
, 0},
4430 {"weak", obj_coff_weak
, 0},
4431 #ifndef BFD_ASSEMBLER
4432 {"use", obj_coff_section
, 0},
4433 {"text", obj_coff_text
, 0},
4434 {"data", obj_coff_data
, 0},
4435 {"lcomm", obj_coff_lcomm
, 0},
4436 {"ident", obj_coff_ident
, 0},
4438 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4439 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4441 {"version", s_ignore
, 0},
4442 {"ABORT", s_abort
, 0},
4444 /* The m88k uses sdef instead of def. */
4445 {"sdef", obj_coff_def
, 0},
4447 {NULL
, NULL
, 0} /* end sentinel */
4448 }; /* obj_pseudo_table */
4450 #ifdef BFD_ASSEMBLER
4452 static void coff_pop_insert
PARAMS ((void));
4453 static int coff_sec_sym_ok_for_reloc
PARAMS ((asection
*));
4455 /* Support for a COFF emulation. */
4460 pop_insert (obj_pseudo_table
);
4464 coff_sec_sym_ok_for_reloc (sec
)
4465 asection
*sec ATTRIBUTE_UNUSED
;
4470 const struct format_ops coff_format_ops
=
4472 bfd_target_coff_flavour
,
4477 coff_frob_file_after_relocs
,
4482 obj_generate_asm_lineno
,
4491 coff_sec_sym_ok_for_reloc
,
4498 coff_obj_read_begin_hook
,
4499 coff_obj_symbol_new_hook
,