1 /* coff object file format
2 Copyright (C) 1989, 90, 91, 92, 93, 94, 95, 96, 97, 1998
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 symbolS
*def_symbol_in_progress
;
41 unsigned long chunk_size
;
42 unsigned long element_size
;
45 unsigned long pointer
;
50 stack_init (chunk_size
, element_size
)
51 unsigned long chunk_size
;
52 unsigned long element_size
;
56 st
= (stack
*) malloc (sizeof (stack
));
59 st
->data
= malloc (chunk_size
);
66 st
->size
= chunk_size
;
67 st
->chunk_size
= chunk_size
;
68 st
->element_size
= element_size
;
73 /* Not currently used. */
84 stack_push (st
, element
)
88 if (st
->pointer
+ st
->element_size
>= st
->size
)
90 st
->size
+= st
->chunk_size
;
91 if ((st
->data
= xrealloc (st
->data
, st
->size
)) == (char *) 0)
94 memcpy (st
->data
+ st
->pointer
, element
, st
->element_size
);
95 st
->pointer
+= st
->element_size
;
96 return st
->data
+ st
->pointer
;
103 if (st
->pointer
< st
->element_size
)
108 st
->pointer
-= st
->element_size
;
109 return st
->data
+ st
->pointer
;
113 * Maintain a list of the tagnames of the structres.
116 static struct hash_control
*tag_hash
;
121 tag_hash
= hash_new ();
125 tag_insert (name
, symbolP
)
129 const char *error_string
;
131 if ((error_string
= hash_jam (tag_hash
, name
, (char *) symbolP
)))
133 as_fatal (_("Inserting \"%s\" into structure table failed: %s"),
142 #ifdef STRIP_UNDERSCORE
145 #endif /* STRIP_UNDERSCORE */
146 return (symbolS
*) hash_find (tag_hash
, name
);
150 tag_find_or_make (name
)
155 if ((symbolP
= tag_find (name
)) == NULL
)
157 symbolP
= symbol_new (name
, undefined_section
,
158 0, &zero_address_frag
);
160 tag_insert (S_GET_NAME (symbolP
), symbolP
);
162 symbol_table_insert (symbolP
);
169 /* We accept the .bss directive to set the section for backward
170 compatibility with earlier versions of gas. */
173 obj_coff_bss (ignore
)
176 if (*input_line_pointer
== '\n')
177 subseg_new (".bss", get_absolute_expression ());
184 static void SA_SET_SYM_TAGNDX
PARAMS ((symbolS
*, symbolS
*));
186 #define GET_FILENAME_STRING(X) \
187 ((char*)(&((X)->sy_symbol.ost_auxent->x_file.x_n.x_offset))[1])
191 fetch_coff_debug_section ()
193 static segT debug_section
;
197 s
= bfd_make_debug_symbol (stdoutput
, (char *) 0, 0);
199 debug_section
= s
->section
;
201 return debug_section
;
205 SA_SET_SYM_ENDNDX (sym
, val
)
209 combined_entry_type
*entry
, *p
;
211 entry
= &coffsymbol (sym
->bsym
)->native
[1];
212 p
= coffsymbol (val
->bsym
)->native
;
213 entry
->u
.auxent
.x_sym
.x_fcnary
.x_fcn
.x_endndx
.p
= p
;
218 SA_SET_SYM_TAGNDX (sym
, val
)
222 combined_entry_type
*entry
, *p
;
224 entry
= &coffsymbol (sym
->bsym
)->native
[1];
225 p
= coffsymbol (val
->bsym
)->native
;
226 entry
->u
.auxent
.x_sym
.x_tagndx
.p
= p
;
231 S_GET_DATA_TYPE (sym
)
234 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
;
238 S_SET_DATA_TYPE (sym
, val
)
242 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_type
= val
;
247 S_GET_STORAGE_CLASS (sym
)
250 return coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
;
254 S_SET_STORAGE_CLASS (sym
, val
)
258 coffsymbol (sym
->bsym
)->native
->u
.syment
.n_sclass
= val
;
262 /* Merge a debug symbol containing debug information into a normal symbol. */
265 c_symbol_merge (debug
, normal
)
269 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
270 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
272 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
274 /* take the most we have */
275 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
278 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
280 /* Move all the auxiliary information. */
281 memcpy (coffsymbol (normal
->bsym
)->native
+ 1,
282 coffsymbol (debug
->bsym
)->native
+ 1,
283 S_GET_NUMBER_AUXILIARY (debug
) * sizeof (combined_entry_type
));
286 /* Move the debug flags. */
287 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
291 c_dot_file_symbol (filename
)
296 symbolP
= symbol_new (filename
, bfd_abs_section_ptr
, 0, &zero_address_frag
);
298 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
299 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
301 symbolP
->bsym
->flags
= BSF_DEBUGGING
;
308 listing_source_file (filename
);
313 /* Make sure that the symbol is first on the symbol chain */
314 if (symbol_rootP
!= symbolP
)
316 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
317 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
318 } /* if not first on the list */
321 /* Line number handling */
324 struct line_no
*next
;
331 /* Symbol of last function, which we should hang line#s off of. */
332 static symbolS
*line_fsym
;
334 #define in_function() (line_fsym != 0)
335 #define clear_function() (line_fsym = 0)
336 #define set_function(F) (line_fsym = (F), coff_add_linesym (F))
340 coff_obj_symbol_new_hook (symbolP
)
343 long sz
= (OBJ_COFF_MAX_AUXENTRIES
+ 1) * sizeof (combined_entry_type
);
344 char * s
= (char *) xmalloc (sz
);
347 coffsymbol (symbolP
->bsym
)->native
= (combined_entry_type
*) s
;
349 S_SET_DATA_TYPE (symbolP
, T_NULL
);
350 S_SET_STORAGE_CLASS (symbolP
, 0);
351 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
353 if (S_IS_STRING (symbolP
))
354 SF_SET_STRING (symbolP
);
356 if (S_IS_LOCAL (symbolP
))
357 SF_SET_LOCAL (symbolP
);
362 * Handle .ln directives.
365 static symbolS
*current_lineno_sym
;
366 static struct line_no
*line_nos
;
367 /* @@ Blindly assume all .ln directives will be in the .text section... */
371 add_lineno (frag
, offset
, num
)
376 struct line_no
*new_line
=
377 (struct line_no
*) xmalloc (sizeof (struct line_no
));
378 if (!current_lineno_sym
)
382 new_line
->next
= line_nos
;
383 new_line
->frag
= frag
;
384 new_line
->l
.line_number
= num
;
385 new_line
->l
.u
.offset
= offset
;
391 coff_add_linesym (sym
)
396 coffsymbol (current_lineno_sym
->bsym
)->lineno
= (alent
*) line_nos
;
400 current_lineno_sym
= sym
;
404 obj_coff_ln (appline
)
409 if (! appline
&& def_symbol_in_progress
!= NULL
)
411 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
412 demand_empty_rest_of_line ();
416 l
= get_absolute_expression ();
419 add_lineno (frag_now
, frag_now_fix (), l
);
423 new_logical_line ((char *) NULL
, l
- 1);
432 l
+= coff_line_base
- 1;
433 listing_source_line (l
);
438 demand_empty_rest_of_line ();
444 * Handle .def directives.
446 * One might ask : why can't we symbol_new if the symbol does not
447 * already exist and fill it with debug information. Because of
448 * the C_EFCN special symbol. It would clobber the value of the
449 * function symbol before we have a chance to notice that it is
450 * a C_EFCN. And a second reason is that the code is more clear this
451 * way. (at least I think it is :-).
455 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
456 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
457 *input_line_pointer == '\t') \
458 input_line_pointer++;
464 char name_end
; /* Char after the end of name */
465 char *symbol_name
; /* Name of the debug symbol */
466 char *symbol_name_copy
; /* Temporary copy of the name */
467 unsigned int symbol_name_length
;
469 if (def_symbol_in_progress
!= NULL
)
471 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
472 demand_empty_rest_of_line ();
474 } /* if not inside .def/.endef */
478 symbol_name
= input_line_pointer
;
479 #ifdef STRIP_UNDERSCORE
480 if (symbol_name
[0] == '_' && symbol_name
[1] != 0)
482 #endif /* STRIP_UNDERSCORE */
484 name_end
= get_symbol_end ();
485 symbol_name_length
= strlen (symbol_name
);
486 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
487 strcpy (symbol_name_copy
, symbol_name
);
488 #ifdef tc_canonicalize_symbol_name
489 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
492 /* Initialize the new symbol */
493 def_symbol_in_progress
= symbol_make (symbol_name_copy
);
494 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
495 S_SET_VALUE (def_symbol_in_progress
, 0);
497 if (S_IS_STRING (def_symbol_in_progress
))
498 SF_SET_STRING (def_symbol_in_progress
);
500 *input_line_pointer
= name_end
;
502 demand_empty_rest_of_line ();
505 unsigned int dim_index
;
508 obj_coff_endef (ignore
)
513 /* DIM BUG FIX sac@cygnus.com */
515 if (def_symbol_in_progress
== NULL
)
517 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
518 demand_empty_rest_of_line ();
520 } /* if not inside .def/.endef */
522 /* Set the section number according to storage class. */
523 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
528 SF_SET_TAG (def_symbol_in_progress
);
529 /* intentional fallthrough */
532 SF_SET_DEBUG (def_symbol_in_progress
);
533 S_SET_SEGMENT (def_symbol_in_progress
, fetch_coff_debug_section ());
537 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
538 /* intentional fallthrough */
540 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
541 /* intentional fallthrough */
545 S_SET_SEGMENT (def_symbol_in_progress
, text_section
);
547 name
= bfd_asymbol_name (def_symbol_in_progress
->bsym
);
548 if (name
[1] == 'b' && name
[2] == 'f')
550 if (! in_function ())
551 as_warn (_("`%s' symbol without preceding function"), name
);
552 /* SA_SET_SYM_LNNO (def_symbol_in_progress, 12345);*/
553 /* Will need relocating */
554 SF_SET_PROCESS (def_symbol_in_progress
);
562 #endif /* C_AUTOARG */
568 SF_SET_DEBUG (def_symbol_in_progress
);
569 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
576 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
582 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
589 as_warn (_("unexpected storage class %d"),
590 S_GET_STORAGE_CLASS (def_symbol_in_progress
));
592 } /* switch on storage class */
594 /* Now that we have built a debug symbol, try to find if we should
595 merge with an existing symbol or not. If a symbol is C_EFCN or
596 SEG_ABSOLUTE or untagged SEG_DEBUG it never merges. */
598 /* Two cases for functions. Either debug followed by definition or
599 definition followed by debug. For definition first, we will
600 merge the debug symbol into the definition. For debug first, the
601 lineno entry MUST point to the definition function or else it
602 will point off into space when obj_crawl_symbol_chain() merges
603 the debug symbol into the real symbol. Therefor, let's presume
604 the debug symbol is a real function reference. */
606 /* FIXME-SOON If for some reason the definition label/symbol is
607 never seen, this will probably leave an undefined symbol at link
610 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
611 || (!strcmp (bfd_get_section_name (stdoutput
,
612 S_GET_SEGMENT (def_symbol_in_progress
)),
614 && !SF_GET_TAG (def_symbol_in_progress
))
615 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
616 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
)
618 if (def_symbol_in_progress
!= symbol_lastP
)
619 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
624 /* This symbol already exists, merge the newly created symbol
625 into the old one. This is not mandatory. The linker can
626 handle duplicate symbols correctly. But I guess that it save
627 a *lot* of space if the assembly file defines a lot of
630 /* The debug entry (def_symbol_in_progress) is merged into the
631 previous definition. */
633 c_symbol_merge (def_symbol_in_progress
, symbolP
);
634 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
636 def_symbol_in_progress
= symbolP
;
638 if (SF_GET_FUNCTION (def_symbol_in_progress
)
639 || SF_GET_TAG (def_symbol_in_progress
)
640 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
642 /* For functions, and tags, and static symbols, the symbol
643 *must* be where the debug symbol appears. Move the
644 existing symbol to the current place. */
645 /* If it already is at the end of the symbol list, do nothing */
646 if (def_symbol_in_progress
!= symbol_lastP
)
648 symbol_remove (def_symbol_in_progress
, &symbol_rootP
, &symbol_lastP
);
649 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
654 if (SF_GET_TAG (def_symbol_in_progress
))
658 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
660 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
661 tag_insert (S_GET_NAME (def_symbol_in_progress
),
662 def_symbol_in_progress
);
665 if (SF_GET_FUNCTION (def_symbol_in_progress
))
667 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
668 set_function (def_symbol_in_progress
);
669 SF_SET_PROCESS (def_symbol_in_progress
);
673 /* That is, if this is the first time we've seen the
675 symbol_table_insert (def_symbol_in_progress
);
676 } /* definition follows debug */
677 } /* Create the line number entry pointing to the function being defined */
679 def_symbol_in_progress
= NULL
;
680 demand_empty_rest_of_line ();
684 obj_coff_dim (ignore
)
689 if (def_symbol_in_progress
== NULL
)
691 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
692 demand_empty_rest_of_line ();
694 } /* if not inside .def/.endef */
696 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
698 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
701 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
702 get_absolute_expression ());
704 switch (*input_line_pointer
)
707 input_line_pointer
++;
711 as_warn (_("badly formed .dim directive ignored"));
712 /* intentional fallthrough */
720 demand_empty_rest_of_line ();
724 obj_coff_line (ignore
)
729 if (def_symbol_in_progress
== NULL
)
731 /* Probably stabs-style line? */
736 this_base
= get_absolute_expression ();
737 if (!strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)))
738 coff_line_base
= this_base
;
740 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
741 SA_SET_SYM_LNNO (def_symbol_in_progress
, coff_line_base
);
743 demand_empty_rest_of_line ();
746 if (strcmp (".bf", S_GET_NAME (def_symbol_in_progress
)) == 0)
751 listing_source_line ((unsigned int) coff_line_base
);
757 obj_coff_size (ignore
)
760 if (def_symbol_in_progress
== NULL
)
762 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
763 demand_empty_rest_of_line ();
765 } /* if not inside .def/.endef */
767 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
768 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
769 demand_empty_rest_of_line ();
773 obj_coff_scl (ignore
)
776 if (def_symbol_in_progress
== NULL
)
778 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
779 demand_empty_rest_of_line ();
781 } /* if not inside .def/.endef */
783 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
784 demand_empty_rest_of_line ();
788 obj_coff_tag (ignore
)
794 if (def_symbol_in_progress
== NULL
)
796 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
797 demand_empty_rest_of_line ();
801 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
802 symbol_name
= input_line_pointer
;
803 name_end
= get_symbol_end ();
805 #ifdef tc_canonicalize_symbol_name
806 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
809 /* Assume that the symbol referred to by .tag is always defined.
810 This was a bad assumption. I've added find_or_make. xoxorich. */
811 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
812 tag_find_or_make (symbol_name
));
813 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
815 as_warn (_("tag not found for .tag %s"), symbol_name
);
818 SF_SET_TAGGED (def_symbol_in_progress
);
819 *input_line_pointer
= name_end
;
821 demand_empty_rest_of_line ();
825 obj_coff_type (ignore
)
828 if (def_symbol_in_progress
== NULL
)
830 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
831 demand_empty_rest_of_line ();
833 } /* if not inside .def/.endef */
835 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
837 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
838 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
840 SF_SET_FUNCTION (def_symbol_in_progress
);
841 } /* is a function */
843 demand_empty_rest_of_line ();
847 obj_coff_val (ignore
)
850 if (def_symbol_in_progress
== NULL
)
852 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
853 demand_empty_rest_of_line ();
855 } /* if not inside .def/.endef */
857 if (is_name_beginner (*input_line_pointer
))
859 char *symbol_name
= input_line_pointer
;
860 char name_end
= get_symbol_end ();
862 #ifdef tc_canonicalize_symbol_name
863 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
865 if (!strcmp (symbol_name
, "."))
867 def_symbol_in_progress
->sy_frag
= frag_now
;
868 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
869 /* If the .val is != from the .def (e.g. statics) */
871 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
873 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
874 def_symbol_in_progress
->sy_value
.X_add_symbol
=
875 symbol_find_or_make (symbol_name
);
876 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
877 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
879 /* If the segment is undefined when the forward reference is
880 resolved, then copy the segment id from the forward
882 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
884 /* Otherwise, it is the name of a non debug symbol and its value will be calculated later. */
885 *input_line_pointer
= name_end
;
889 S_SET_VALUE (def_symbol_in_progress
, get_absolute_expression ());
890 } /* if symbol based */
892 demand_empty_rest_of_line ();
896 coff_obj_read_begin_hook ()
898 /* These had better be the same. Usually 18 bytes. */
900 know (sizeof (SYMENT
) == sizeof (AUXENT
));
901 know (SYMESZ
== AUXESZ
);
907 symbolS
*coff_last_function
;
908 static symbolS
*coff_last_bf
;
911 coff_frob_symbol (symp
, punt
)
915 static symbolS
*last_tagP
;
916 static stack
*block_stack
;
917 static symbolS
*set_end
;
918 symbolS
*next_set_end
= NULL
;
920 if (symp
== &abs_symbol
)
926 if (current_lineno_sym
)
927 coff_add_linesym ((symbolS
*) 0);
930 block_stack
= stack_init (512, sizeof (symbolS
*));
932 if (!S_IS_DEFINED (symp
) && S_GET_STORAGE_CLASS (symp
) != C_STAT
)
933 S_SET_STORAGE_CLASS (symp
, C_EXT
);
935 if (!SF_GET_DEBUG (symp
))
938 if (!SF_GET_LOCAL (symp
)
939 && !SF_GET_STATICS (symp
)
940 && (real
= symbol_find_base (S_GET_NAME (symp
), DO_NOT_STRIP
))
943 c_symbol_merge (symp
, real
);
946 if (!S_IS_DEFINED (symp
) && !SF_GET_LOCAL (symp
))
948 assert (S_GET_VALUE (symp
) == 0);
949 S_SET_EXTERNAL (symp
);
951 else if (S_GET_STORAGE_CLASS (symp
) == C_NULL
)
953 if (S_GET_SEGMENT (symp
) == text_section
954 && symp
!= seg_info (text_section
)->sym
)
955 S_SET_STORAGE_CLASS (symp
, C_LABEL
);
957 S_SET_STORAGE_CLASS (symp
, C_STAT
);
959 if (SF_GET_PROCESS (symp
))
961 if (S_GET_STORAGE_CLASS (symp
) == C_BLOCK
)
963 if (!strcmp (S_GET_NAME (symp
), ".bb"))
964 stack_push (block_stack
, (char *) &symp
);
968 begin
= *(symbolS
**) stack_pop (block_stack
);
970 as_warn (_("mismatched .eb"));
972 next_set_end
= begin
;
975 if (coff_last_function
== 0 && SF_GET_FUNCTION (symp
))
977 union internal_auxent
*auxp
;
978 coff_last_function
= symp
;
979 if (S_GET_NUMBER_AUXILIARY (symp
) < 1)
980 S_SET_NUMBER_AUXILIARY (symp
, 1);
981 auxp
= &coffsymbol (symp
->bsym
)->native
[1].u
.auxent
;
982 memset (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
, 0,
983 sizeof (auxp
->x_sym
.x_fcnary
.x_ary
.x_dimen
));
985 if (S_GET_STORAGE_CLASS (symp
) == C_EFCN
)
987 if (coff_last_function
== 0)
988 as_fatal (_("C_EFCN symbol out of scope"));
989 SA_SET_SYM_FSIZE (coff_last_function
,
990 (long) (S_GET_VALUE (symp
)
991 - S_GET_VALUE (coff_last_function
)));
992 next_set_end
= coff_last_function
;
993 coff_last_function
= 0;
996 if (S_IS_EXTERNAL (symp
))
997 S_SET_STORAGE_CLASS (symp
, C_EXT
);
998 else if (SF_GET_LOCAL (symp
))
1001 if (SF_GET_FUNCTION (symp
))
1002 symp
->bsym
->flags
|= BSF_FUNCTION
;
1007 if (SF_GET_TAG (symp
))
1009 else if (S_GET_STORAGE_CLASS (symp
) == C_EOS
)
1010 next_set_end
= last_tagP
;
1013 /* This is pretty horrible, but we have to set *punt correctly in
1014 order to call SA_SET_SYM_ENDNDX correctly. */
1015 if (! symp
->sy_used_in_reloc
1016 && ((symp
->bsym
->flags
& BSF_SECTION_SYM
) != 0
1017 || (! S_IS_EXTERNAL (symp
)
1018 && ! symp
->sy_tc
.output
1019 && S_GET_STORAGE_CLASS (symp
) != C_FILE
)))
1023 if (set_end
!= (symbolS
*) NULL
1025 && ((symp
->bsym
->flags
& BSF_NOT_AT_END
) != 0
1026 || (S_IS_DEFINED (symp
)
1027 && ! S_IS_COMMON (symp
)
1028 && (! S_IS_EXTERNAL (symp
) || SF_GET_FUNCTION (symp
)))))
1030 SA_SET_SYM_ENDNDX (set_end
, symp
);
1034 if (next_set_end
!= NULL
1036 set_end
= next_set_end
;
1039 && S_GET_STORAGE_CLASS (symp
) == C_FCN
1040 && strcmp (S_GET_NAME (symp
), ".bf") == 0)
1042 if (coff_last_bf
!= NULL
)
1043 SA_SET_SYM_ENDNDX (coff_last_bf
, symp
);
1044 coff_last_bf
= symp
;
1047 if (coffsymbol (symp
->bsym
)->lineno
)
1050 struct line_no
*lptr
;
1053 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1054 for (i
= 0; lptr
; lptr
= lptr
->next
)
1056 lptr
= (struct line_no
*) coffsymbol (symp
->bsym
)->lineno
;
1058 /* We need i entries for line numbers, plus 1 for the first
1059 entry which BFD will override, plus 1 for the last zero
1060 entry (a marker for BFD). */
1061 l
= (alent
*) xmalloc ((i
+ 2) * sizeof (alent
));
1062 coffsymbol (symp
->bsym
)->lineno
= l
;
1063 l
[i
+ 1].line_number
= 0;
1064 l
[i
+ 1].u
.sym
= NULL
;
1068 lptr
->l
.u
.offset
+= lptr
->frag
->fr_address
;
1076 coff_adjust_section_syms (abfd
, sec
, x
)
1082 segment_info_type
*seginfo
= seg_info (sec
);
1083 int nlnno
, nrelocs
= 0;
1085 /* RS/6000 gas creates a .debug section manually in ppc_frob_file in
1086 tc-ppc.c. Do not get confused by it. */
1087 if (seginfo
== NULL
)
1090 if (!strcmp (sec
->name
, ".text"))
1091 nlnno
= coff_n_line_nos
;
1095 /* @@ Hope that none of the fixups expand to more than one reloc
1097 fixS
*fixp
= seginfo
->fix_root
;
1100 if (! fixp
->fx_done
)
1102 fixp
= fixp
->fx_next
;
1105 if (bfd_get_section_size_before_reloc (sec
) == 0
1108 && sec
!= text_section
1109 && sec
!= data_section
1110 && sec
!= bss_section
)
1112 secsym
= section_symbol (sec
);
1113 SA_SET_SCN_NRELOC (secsym
, nrelocs
);
1114 SA_SET_SCN_NLINNO (secsym
, nlnno
);
1118 coff_frob_file_after_relocs ()
1120 bfd_map_over_sections (stdoutput
, coff_adjust_section_syms
, (char*) 0);
1124 * implement the .section pseudo op:
1125 * .section name {, "flags"}
1127 * | +--- optional flags: 'b' for bss
1129 * +-- section name 'l' for lib
1133 * 'd' (apparently m88k for data)
1135 * 'r' for read-only data
1136 * But if the argument is not a quoted string, treat it as a
1137 * subsegment number.
1141 obj_coff_section (ignore
)
1144 /* Strip out the section name */
1160 section_name
= input_line_pointer
;
1161 c
= get_symbol_end ();
1163 name
= xmalloc (input_line_pointer
- section_name
+ 1);
1164 strcpy (name
, section_name
);
1166 *input_line_pointer
= c
;
1171 flags
= SEC_NO_FLAGS
;
1173 if (*input_line_pointer
== ',')
1175 ++input_line_pointer
;
1177 if (*input_line_pointer
!= '"')
1178 exp
= get_absolute_expression ();
1181 ++input_line_pointer
;
1182 while (*input_line_pointer
!= '"'
1183 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
1185 switch (*input_line_pointer
)
1187 case 'b': flags
|= SEC_ALLOC
; flags
&=~ SEC_LOAD
; break;
1188 case 'n': flags
&=~ SEC_LOAD
; break;
1190 case 'w': flags
&=~ SEC_READONLY
; break;
1191 case 'x': flags
|= SEC_CODE
; break;
1192 case 'r': flags
|= SEC_READONLY
; break;
1194 case 'i': /* STYP_INFO */
1195 case 'l': /* STYP_LIB */
1196 case 'o': /* STYP_OVER */
1197 as_warn (_("unsupported section attribute '%c'"),
1198 *input_line_pointer
);
1202 as_warn(_("unknown section attribute '%c'"),
1203 *input_line_pointer
);
1206 ++input_line_pointer
;
1208 if (*input_line_pointer
== '"')
1209 ++input_line_pointer
;
1213 sec
= subseg_new (name
, (subsegT
) exp
);
1215 if (flags
!= SEC_NO_FLAGS
)
1217 if (! bfd_set_section_flags (stdoutput
, sec
, flags
))
1218 as_warn (_("error setting flags for \"%s\": %s"),
1219 bfd_section_name (stdoutput
, sec
),
1220 bfd_errmsg (bfd_get_error ()));
1223 demand_empty_rest_of_line ();
1227 coff_adjust_symtab ()
1229 if (symbol_rootP
== NULL
1230 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
1231 c_dot_file_symbol ("fake");
1235 coff_frob_section (sec
)
1241 bfd_vma size
, n_entries
, mask
;
1243 /* The COFF back end in BFD requires that all section sizes be
1244 rounded up to multiples of the corresponding section alignments.
1245 Seems kinda silly to me, but that's the way it is. */
1246 size
= bfd_get_section_size_before_reloc (sec
);
1247 mask
= ((bfd_vma
) 1 << (bfd_vma
) sec
->alignment_power
) - 1;
1250 size
= (size
+ mask
) & ~mask
;
1251 bfd_set_section_size (stdoutput
, sec
, size
);
1254 /* If the section size is non-zero, the section symbol needs an aux
1255 entry associated with it, indicating the size. We don't know
1256 all the values yet; coff_frob_symbol will fill them in later. */
1258 || sec
== text_section
1259 || sec
== data_section
1260 || sec
== bss_section
)
1262 symbolS
*secsym
= section_symbol (sec
);
1264 S_SET_STORAGE_CLASS (secsym
, C_STAT
);
1265 S_SET_NUMBER_AUXILIARY (secsym
, 1);
1266 SF_SET_STATICS (secsym
);
1267 SA_SET_SCN_SCNLEN (secsym
, size
);
1270 /* @@ these should be in a "stabs.h" file, or maybe as.h */
1271 #ifndef STAB_SECTION_NAME
1272 #define STAB_SECTION_NAME ".stab"
1274 #ifndef STAB_STRING_SECTION_NAME
1275 #define STAB_STRING_SECTION_NAME ".stabstr"
1277 if (strcmp (STAB_STRING_SECTION_NAME
, sec
->name
))
1281 sec
= subseg_get (STAB_SECTION_NAME
, 0);
1282 /* size is already rounded up, since other section will be listed first */
1283 size
= bfd_get_section_size_before_reloc (strsec
);
1285 n_entries
= bfd_get_section_size_before_reloc (sec
) / 12 - 1;
1287 /* Find first non-empty frag. It should be large enough. */
1288 fragp
= seg_info (sec
)->frchainP
->frch_root
;
1289 while (fragp
&& fragp
->fr_fix
== 0)
1290 fragp
= fragp
->fr_next
;
1291 assert (fragp
!= 0 && fragp
->fr_fix
>= 12);
1293 /* Store the values. */
1294 p
= fragp
->fr_literal
;
1295 bfd_h_put_16 (stdoutput
, n_entries
, (bfd_byte
*) p
+ 6);
1296 bfd_h_put_32 (stdoutput
, size
, (bfd_byte
*) p
+ 8);
1300 obj_coff_init_stab_section (seg
)
1306 unsigned int stroff
;
1308 /* Make space for this first symbol. */
1312 as_where (&file
, (unsigned int *) NULL
);
1313 stabstr_name
= (char *) alloca (strlen (seg
->name
) + 4);
1314 strcpy (stabstr_name
, seg
->name
);
1315 strcat (stabstr_name
, "str");
1316 stroff
= get_stab_string_offset (file
, stabstr_name
);
1318 md_number_to_chars (p
, stroff
, 4);
1327 return ((s
== NULL
) ? "(NULL)" : S_GET_NAME (s
));
1335 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
1337 printf(_("0x%lx: \"%s\" type = %ld, class = %d, segment = %d\n"),
1338 (unsigned long) symbolP
,
1339 S_GET_NAME(symbolP
),
1340 (long) S_GET_DATA_TYPE(symbolP
),
1341 S_GET_STORAGE_CLASS(symbolP
),
1342 (int) S_GET_SEGMENT(symbolP
));
1348 #else /* not BFD_ASSEMBLER */
1351 /* This is needed because we include internal bfd things. */
1355 #include "libcoff.h"
1358 #include "coff/pe.h"
1361 /* The NOP_OPCODE is for the alignment fill value. Fill with nop so
1362 that we can stick sections together without causing trouble. */
1364 #define NOP_OPCODE 0x00
1367 /* The zeroes if symbol name is longer than 8 chars */
1368 #define S_SET_ZEROES(s,v) ((s)->sy_symbol.ost_entry.n_zeroes = (v))
1370 #define MIN(a,b) ((a) < (b)? (a) : (b))
1371 /* This vector is used to turn an internal segment into a section #
1372 suitable for insertion into a coff symbol table
1375 const short seg_N_TYPE
[] =
1376 { /* in: segT out: N_TYPE bits */
1378 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
1379 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1380 21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
1381 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
1382 C_UNDEF_SECTION
, /* SEG_UNKNOWN */
1383 C_UNDEF_SECTION
, /* SEG_GOOF */
1384 C_UNDEF_SECTION
, /* SEG_EXPR */
1385 C_DEBUG_SECTION
, /* SEG_DEBUG */
1386 C_NTV_SECTION
, /* SEG_NTV */
1387 C_PTV_SECTION
, /* SEG_PTV */
1388 C_REGISTER_SECTION
, /* SEG_REGISTER */
1391 int function_lineoff
= -1; /* Offset in line#s where the last function
1392 started (the odd entry for line #0) */
1394 /* structure used to keep the filenames which
1395 are too long around so that we can stick them
1396 into the string table */
1397 struct filename_list
1400 struct filename_list
*next
;
1403 static struct filename_list
*filename_list_head
;
1404 static struct filename_list
*filename_list_tail
;
1406 static symbolS
*last_line_symbol
;
1408 /* Add 4 to the real value to get the index and compensate the
1409 negatives. This vector is used by S_GET_SEGMENT to turn a coff
1410 section number into a segment number
1412 static symbolS
*previous_file_symbol
;
1413 void c_symbol_merge ();
1414 static int line_base
;
1416 symbolS
*c_section_symbol ();
1419 static void fixup_segment
PARAMS ((segment_info_type
*segP
,
1420 segT this_segment_type
));
1423 static void fixup_mdeps
PARAMS ((fragS
*,
1428 static void fill_section
PARAMS ((bfd
* abfd
,
1433 static int c_line_new
PARAMS ((symbolS
* symbol
, long paddr
,
1438 static void w_symbols
PARAMS ((bfd
* abfd
, char *where
,
1439 symbolS
* symbol_rootP
));
1441 static void adjust_stab_section
PARAMS ((bfd
*abfd
, segT seg
));
1443 static void obj_coff_lcomm
PARAMS ((int));
1444 static void obj_coff_text
PARAMS ((int));
1445 static void obj_coff_data
PARAMS ((int));
1446 static void obj_coff_ident
PARAMS ((int));
1447 void obj_coff_section
PARAMS ((int));
1451 We allow more than just the standard 3 sections, infact, we allow
1452 40 sections, (though the usual three have to be there).
1454 This structure performs the mappings for us:
1464 static const seg_info_type seg_info_off_by_4
[] =
1471 {SEG_E0
}, {SEG_E1
}, {SEG_E2
}, {SEG_E3
}, {SEG_E4
},
1472 {SEG_E5
}, {SEG_E6
}, {SEG_E7
}, {SEG_E8
}, {SEG_E9
},
1473 {SEG_E10
},{SEG_E11
},{SEG_E12
},{SEG_E13
},{SEG_E14
},
1474 {SEG_E15
},{SEG_E16
},{SEG_E17
},{SEG_E18
},{SEG_E19
},
1475 {SEG_E20
},{SEG_E21
},{SEG_E22
},{SEG_E23
},{SEG_E24
},
1476 {SEG_E25
},{SEG_E26
},{SEG_E27
},{SEG_E28
},{SEG_E29
},
1477 {SEG_E30
},{SEG_E31
},{SEG_E32
},{SEG_E33
},{SEG_E34
},
1478 {SEG_E35
},{SEG_E36
},{SEG_E37
},{SEG_E38
},{SEG_E39
},
1493 #define SEG_INFO_FROM_SECTION_NUMBER(x) (seg_info_off_by_4[(x)+4])
1495 static relax_addressT
1496 relax_align (address
, alignment
)
1497 relax_addressT address
;
1500 relax_addressT mask
;
1501 relax_addressT new_address
;
1503 mask
= ~((~0) << alignment
);
1504 new_address
= (address
+ mask
) & (~mask
);
1505 return (new_address
- address
);
1513 return SEG_INFO_FROM_SECTION_NUMBER (x
->sy_symbol
.ost_entry
.n_scnum
).seg_t
;
1516 /* calculate the size of the frag chain and fill in the section header
1517 to contain all of it, also fill in the addr of the sections */
1519 size_section (abfd
, idx
)
1524 unsigned int size
= 0;
1525 fragS
*frag
= segment_info
[idx
].frchainP
->frch_root
;
1528 size
= frag
->fr_address
;
1529 if (frag
->fr_address
!= size
)
1531 fprintf (stderr
, _("Out of step\n"));
1532 size
= frag
->fr_address
;
1535 switch (frag
->fr_type
)
1537 #ifdef TC_COFF_SIZEMACHDEP
1538 case rs_machine_dependent
:
1539 size
+= TC_COFF_SIZEMACHDEP (frag
);
1543 assert (frag
->fr_symbol
== 0);
1546 size
+= frag
->fr_fix
;
1547 size
+= frag
->fr_offset
* frag
->fr_var
;
1554 size
+= frag
->fr_fix
;
1555 off
= relax_align (size
, frag
->fr_offset
);
1556 if (frag
->fr_subtype
!= 0 && off
> frag
->fr_subtype
)
1562 BAD_CASE (frag
->fr_type
);
1565 frag
= frag
->fr_next
;
1567 segment_info
[idx
].scnhdr
.s_size
= size
;
1573 count_entries_in_chain (idx
)
1576 unsigned int nrelocs
;
1579 /* Count the relocations */
1580 fixup_ptr
= segment_info
[idx
].fix_root
;
1582 while (fixup_ptr
!= (fixS
*) NULL
)
1584 if (fixup_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fixup_ptr
))
1587 if (fixup_ptr
->fx_r_type
== RELOC_CONSTH
)
1596 fixup_ptr
= fixup_ptr
->fx_next
;
1603 static int compare_external_relocs
PARAMS ((const PTR
, const PTR
));
1605 /* AUX's ld expects relocations to be sorted */
1607 compare_external_relocs (x
, y
)
1611 struct external_reloc
*a
= (struct external_reloc
*) x
;
1612 struct external_reloc
*b
= (struct external_reloc
*) y
;
1613 bfd_vma aadr
= bfd_getb32 (a
->r_vaddr
);
1614 bfd_vma badr
= bfd_getb32 (b
->r_vaddr
);
1615 return (aadr
< badr
? -1 : badr
< aadr
? 1 : 0);
1620 /* output all the relocations for a section */
1622 do_relocs_for (abfd
, h
, file_cursor
)
1625 unsigned long *file_cursor
;
1627 unsigned int nrelocs
;
1629 unsigned long reloc_start
= *file_cursor
;
1631 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
1633 if (segment_info
[idx
].scnhdr
.s_name
[0])
1635 struct external_reloc
*ext_ptr
;
1636 struct external_reloc
*external_reloc_vec
;
1637 unsigned int external_reloc_size
;
1638 unsigned int base
= segment_info
[idx
].scnhdr
.s_paddr
;
1639 fixS
*fix_ptr
= segment_info
[idx
].fix_root
;
1640 nrelocs
= count_entries_in_chain (idx
);
1643 /* Bypass this stuff if no relocs. This also incidentally
1644 avoids a SCO bug, where free(malloc(0)) tends to crash. */
1646 external_reloc_size
= nrelocs
* RELSZ
;
1647 external_reloc_vec
=
1648 (struct external_reloc
*) malloc (external_reloc_size
);
1650 ext_ptr
= external_reloc_vec
;
1652 /* Fill in the internal coff style reloc struct from the
1653 internal fix list. */
1656 struct internal_reloc intr
;
1658 /* Only output some of the relocations */
1659 if (fix_ptr
->fx_done
== 0 && TC_COUNT_RELOC (fix_ptr
))
1661 #ifdef TC_RELOC_MANGLE
1662 TC_RELOC_MANGLE (&segment_info
[idx
], fix_ptr
, &intr
,
1667 symbolS
*symbol_ptr
= fix_ptr
->fx_addsy
;
1669 intr
.r_type
= TC_COFF_FIX2RTYPE (fix_ptr
);
1671 base
+ fix_ptr
->fx_frag
->fr_address
+ fix_ptr
->fx_where
;
1673 #ifdef TC_KEEP_FX_OFFSET
1674 intr
.r_offset
= fix_ptr
->fx_offset
;
1679 while (symbol_ptr
->sy_value
.X_op
== O_symbol
1680 && (! S_IS_DEFINED (symbol_ptr
)
1681 || S_IS_COMMON (symbol_ptr
)))
1685 /* We must avoid looping, as that can occur
1686 with a badly written program. */
1687 n
= symbol_ptr
->sy_value
.X_add_symbol
;
1688 if (n
== symbol_ptr
)
1693 /* Turn the segment of the symbol into an offset. */
1696 resolve_symbol_value (symbol_ptr
, 1);
1697 if (! symbol_ptr
->sy_resolved
)
1702 if (expr_symbol_where (symbol_ptr
, &file
, &line
))
1703 as_bad_where (file
, line
,
1704 _("unresolved relocation"));
1706 as_bad (_("bad relocation: symbol `%s' not in symbol table"),
1707 S_GET_NAME (symbol_ptr
));
1709 dot
= segment_info
[S_GET_SEGMENT (symbol_ptr
)].dot
;
1712 intr
.r_symndx
= dot
->sy_number
;
1716 intr
.r_symndx
= symbol_ptr
->sy_number
;
1726 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1729 #if defined(TC_A29K)
1731 /* The 29k has a special kludge for the high 16 bit
1732 reloc. Two relocations are emited, R_IHIHALF,
1733 and R_IHCONST. The second one doesn't contain a
1734 symbol, but uses the value for offset. */
1736 if (intr
.r_type
== R_IHIHALF
)
1738 /* now emit the second bit */
1739 intr
.r_type
= R_IHCONST
;
1740 intr
.r_symndx
= fix_ptr
->fx_addnumber
;
1741 (void) bfd_coff_swap_reloc_out (abfd
, &intr
, ext_ptr
);
1747 fix_ptr
= fix_ptr
->fx_next
;
1751 /* Sort the reloc table */
1752 qsort ((PTR
) external_reloc_vec
, nrelocs
,
1753 sizeof (struct external_reloc
), compare_external_relocs
);
1756 /* Write out the reloc table */
1757 bfd_write ((PTR
) external_reloc_vec
, 1, external_reloc_size
,
1759 free (external_reloc_vec
);
1761 /* Fill in section header info. */
1762 segment_info
[idx
].scnhdr
.s_relptr
= *file_cursor
;
1763 *file_cursor
+= external_reloc_size
;
1764 segment_info
[idx
].scnhdr
.s_nreloc
= nrelocs
;
1769 segment_info
[idx
].scnhdr
.s_relptr
= 0;
1773 /* Set relocation_size field in file headers */
1774 H_SET_RELOCATION_SIZE (h
, *file_cursor
- reloc_start
, 0);
1778 /* run through a frag chain and write out the data to go with it, fill
1779 in the scnhdrs with the info on the file postions
1782 fill_section (abfd
, h
, file_cursor
)
1785 unsigned long *file_cursor
;
1789 unsigned int paddr
= 0;
1791 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
1793 unsigned int offset
= 0;
1794 struct internal_scnhdr
*s
= &(segment_info
[i
].scnhdr
);
1800 fragS
*frag
= segment_info
[i
].frchainP
->frch_root
;
1807 buffer
= xmalloc (s
->s_size
);
1808 s
->s_scnptr
= *file_cursor
;
1810 know (s
->s_paddr
== paddr
);
1812 if (strcmp (s
->s_name
, ".text") == 0)
1813 s
->s_flags
|= STYP_TEXT
;
1814 else if (strcmp (s
->s_name
, ".data") == 0)
1815 s
->s_flags
|= STYP_DATA
;
1816 else if (strcmp (s
->s_name
, ".bss") == 0)
1819 s
->s_flags
|= STYP_BSS
;
1821 /* @@ Should make the i386 and a29k coff targets define
1822 COFF_NOLOAD_PROBLEM, and have only one test here. */
1825 #ifndef COFF_NOLOAD_PROBLEM
1826 /* Apparently the SVR3 linker (and exec syscall) and UDI
1827 mondfe progrem are confused by noload sections. */
1828 s
->s_flags
|= STYP_NOLOAD
;
1833 else if (strcmp (s
->s_name
, ".lit") == 0)
1834 s
->s_flags
= STYP_LIT
| STYP_TEXT
;
1835 else if (strcmp (s
->s_name
, ".init") == 0)
1836 s
->s_flags
|= STYP_TEXT
;
1837 else if (strcmp (s
->s_name
, ".fini") == 0)
1838 s
->s_flags
|= STYP_TEXT
;
1839 else if (strncmp (s
->s_name
, ".comment", 8) == 0)
1840 s
->s_flags
|= STYP_INFO
;
1844 unsigned int fill_size
;
1845 switch (frag
->fr_type
)
1847 case rs_machine_dependent
:
1850 memcpy (buffer
+ frag
->fr_address
,
1852 (unsigned int) frag
->fr_fix
);
1853 offset
+= frag
->fr_fix
;
1858 assert (frag
->fr_symbol
== 0);
1865 memcpy (buffer
+ frag
->fr_address
,
1867 (unsigned int) frag
->fr_fix
);
1868 offset
+= frag
->fr_fix
;
1871 fill_size
= frag
->fr_var
;
1872 if (fill_size
&& frag
->fr_offset
> 0)
1875 unsigned int off
= frag
->fr_fix
;
1876 for (count
= frag
->fr_offset
; count
; count
--)
1878 if (fill_size
+ frag
->fr_address
+ off
<= s
->s_size
)
1880 memcpy (buffer
+ frag
->fr_address
+ off
,
1881 frag
->fr_literal
+ frag
->fr_fix
,
1884 offset
+= fill_size
;
1889 case rs_broken_word
:
1894 frag
= frag
->fr_next
;
1899 if (s
->s_scnptr
!= 0)
1901 bfd_write (buffer
, s
->s_size
, 1, abfd
);
1902 *file_cursor
+= s
->s_size
;
1911 /* Coff file generation & utilities */
1914 coff_header_append (abfd
, h
)
1921 #ifdef COFF_LONG_SECTION_NAMES
1922 unsigned long string_size
= 4;
1925 bfd_seek (abfd
, 0, 0);
1927 #ifndef OBJ_COFF_OMIT_OPTIONAL_HEADER
1928 H_SET_MAGIC_NUMBER (h
, COFF_MAGIC
);
1929 H_SET_VERSION_STAMP (h
, 0);
1930 H_SET_ENTRY_POINT (h
, 0);
1931 H_SET_TEXT_START (h
, segment_info
[SEG_E0
].frchainP
->frch_root
->fr_address
);
1932 H_SET_DATA_START (h
, segment_info
[SEG_E1
].frchainP
->frch_root
->fr_address
);
1933 H_SET_SIZEOF_OPTIONAL_HEADER (h
, bfd_coff_swap_aouthdr_out(abfd
, &h
->aouthdr
,
1935 #else /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1936 H_SET_SIZEOF_OPTIONAL_HEADER (h
, 0);
1937 #endif /* defined (OBJ_COFF_OMIT_OPTIONAL_HEADER) */
1939 i
= bfd_coff_swap_filehdr_out (abfd
, &h
->filehdr
, buffer
);
1941 bfd_write (buffer
, i
, 1, abfd
);
1942 bfd_write (buffero
, H_GET_SIZEOF_OPTIONAL_HEADER (h
), 1, abfd
);
1944 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
1946 if (segment_info
[i
].scnhdr
.s_name
[0])
1950 #ifdef COFF_LONG_SECTION_NAMES
1951 /* Support long section names as found in PE. This code
1952 must coordinate with that in write_object_file and
1954 if (strlen (segment_info
[i
].name
) > SCNNMLEN
)
1956 memset (segment_info
[i
].scnhdr
.s_name
, 0, SCNNMLEN
);
1957 sprintf (segment_info
[i
].scnhdr
.s_name
, "/%lu", string_size
);
1958 string_size
+= strlen (segment_info
[i
].name
) + 1;
1962 size
= bfd_coff_swap_scnhdr_out (abfd
,
1963 &(segment_info
[i
].scnhdr
),
1966 as_bad (_("bfd_coff_swap_scnhdr_out failed"));
1967 bfd_write (buffer
, size
, 1, abfd
);
1974 symbol_to_chars (abfd
, where
, symbolP
)
1979 unsigned int numaux
= symbolP
->sy_symbol
.ost_entry
.n_numaux
;
1983 /* Turn any symbols with register attributes into abs symbols */
1984 if (S_GET_SEGMENT (symbolP
) == reg_section
)
1986 S_SET_SEGMENT (symbolP
, absolute_section
);
1988 /* At the same time, relocate all symbols to their output value */
1991 val
= (segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_paddr
1992 + S_GET_VALUE (symbolP
));
1994 val
= S_GET_VALUE (symbolP
);
1997 S_SET_VALUE (symbolP
, val
);
1999 symbolP
->sy_symbol
.ost_entry
.n_value
= val
;
2001 where
+= bfd_coff_swap_sym_out (abfd
, &symbolP
->sy_symbol
.ost_entry
,
2004 for (i
= 0; i
< numaux
; i
++)
2006 where
+= bfd_coff_swap_aux_out (abfd
,
2007 &symbolP
->sy_symbol
.ost_auxent
[i
],
2008 S_GET_DATA_TYPE (symbolP
),
2009 S_GET_STORAGE_CLASS (symbolP
),
2017 coff_obj_symbol_new_hook (symbolP
)
2020 char underscore
= 0; /* Symbol has leading _ */
2022 /* Effective symbol */
2023 /* Store the pointer in the offset. */
2024 S_SET_ZEROES (symbolP
, 0L);
2025 S_SET_DATA_TYPE (symbolP
, T_NULL
);
2026 S_SET_STORAGE_CLASS (symbolP
, 0);
2027 S_SET_NUMBER_AUXILIARY (symbolP
, 0);
2028 /* Additional information */
2029 symbolP
->sy_symbol
.ost_flags
= 0;
2030 /* Auxiliary entries */
2031 memset ((char *) &symbolP
->sy_symbol
.ost_auxent
[0], 0, AUXESZ
);
2033 if (S_IS_STRING (symbolP
))
2034 SF_SET_STRING (symbolP
);
2035 if (!underscore
&& S_IS_LOCAL (symbolP
))
2036 SF_SET_LOCAL (symbolP
);
2040 * Handle .ln directives.
2044 obj_coff_ln (appline
)
2049 if (! appline
&& def_symbol_in_progress
!= NULL
)
2051 as_warn (_(".ln pseudo-op inside .def/.endef: ignored."));
2052 demand_empty_rest_of_line ();
2054 } /* wrong context */
2056 l
= get_absolute_expression ();
2057 c_line_new (0, frag_now_fix (), l
, frag_now
);
2060 new_logical_line ((char *) NULL
, l
- 1);
2070 listing_source_line ((unsigned int) l
);
2075 demand_empty_rest_of_line ();
2081 * Handle .def directives.
2083 * One might ask : why can't we symbol_new if the symbol does not
2084 * already exist and fill it with debug information. Because of
2085 * the C_EFCN special symbol. It would clobber the value of the
2086 * function symbol before we have a chance to notice that it is
2087 * a C_EFCN. And a second reason is that the code is more clear this
2088 * way. (at least I think it is :-).
2092 #define SKIP_SEMI_COLON() while (*input_line_pointer++ != ';')
2093 #define SKIP_WHITESPACES() while (*input_line_pointer == ' ' || \
2094 *input_line_pointer == '\t') \
2095 input_line_pointer++;
2101 char name_end
; /* Char after the end of name */
2102 char *symbol_name
; /* Name of the debug symbol */
2103 char *symbol_name_copy
; /* Temporary copy of the name */
2104 unsigned int symbol_name_length
;
2106 if (def_symbol_in_progress
!= NULL
)
2108 as_warn (_(".def pseudo-op used inside of .def/.endef: ignored."));
2109 demand_empty_rest_of_line ();
2111 } /* if not inside .def/.endef */
2113 SKIP_WHITESPACES ();
2115 def_symbol_in_progress
= (symbolS
*) obstack_alloc (¬es
, sizeof (*def_symbol_in_progress
));
2116 memset (def_symbol_in_progress
, 0, sizeof (*def_symbol_in_progress
));
2118 symbol_name
= input_line_pointer
;
2119 name_end
= get_symbol_end ();
2120 symbol_name_length
= strlen (symbol_name
);
2121 symbol_name_copy
= xmalloc (symbol_name_length
+ 1);
2122 strcpy (symbol_name_copy
, symbol_name
);
2123 #ifdef tc_canonicalize_symbol_name
2124 symbol_name_copy
= tc_canonicalize_symbol_name (symbol_name_copy
);
2127 /* Initialize the new symbol */
2128 #ifdef STRIP_UNDERSCORE
2129 S_SET_NAME (def_symbol_in_progress
, (*symbol_name_copy
== '_'
2130 ? symbol_name_copy
+ 1
2131 : symbol_name_copy
));
2132 #else /* STRIP_UNDERSCORE */
2133 S_SET_NAME (def_symbol_in_progress
, symbol_name_copy
);
2134 #endif /* STRIP_UNDERSCORE */
2135 /* free(symbol_name_copy); */
2136 def_symbol_in_progress
->sy_name_offset
= (unsigned long) ~0;
2137 def_symbol_in_progress
->sy_number
= ~0;
2138 def_symbol_in_progress
->sy_frag
= &zero_address_frag
;
2139 S_SET_VALUE (def_symbol_in_progress
, 0);
2141 if (S_IS_STRING (def_symbol_in_progress
))
2142 SF_SET_STRING (def_symbol_in_progress
);
2144 *input_line_pointer
= name_end
;
2146 demand_empty_rest_of_line ();
2149 unsigned int dim_index
;
2153 obj_coff_endef (ignore
)
2156 symbolS
*symbolP
= 0;
2157 /* DIM BUG FIX sac@cygnus.com */
2159 if (def_symbol_in_progress
== NULL
)
2161 as_warn (_(".endef pseudo-op used outside of .def/.endef: ignored."));
2162 demand_empty_rest_of_line ();
2164 } /* if not inside .def/.endef */
2166 /* Set the section number according to storage class. */
2167 switch (S_GET_STORAGE_CLASS (def_symbol_in_progress
))
2172 SF_SET_TAG (def_symbol_in_progress
);
2173 /* intentional fallthrough */
2176 SF_SET_DEBUG (def_symbol_in_progress
);
2177 S_SET_SEGMENT (def_symbol_in_progress
, SEG_DEBUG
);
2181 SF_SET_LOCAL (def_symbol_in_progress
); /* Do not emit this symbol. */
2182 /* intentional fallthrough */
2184 SF_SET_PROCESS (def_symbol_in_progress
); /* Will need processing before writing */
2185 /* intentional fallthrough */
2187 S_SET_SEGMENT (def_symbol_in_progress
, SEG_E0
);
2189 if (strcmp (S_GET_NAME (def_symbol_in_progress
), ".bf") == 0)
2191 if (function_lineoff
< 0)
2193 fprintf (stderr
, _("`.bf' symbol without preceding function\n"));
2194 } /* missing function symbol */
2195 SA_GET_SYM_LNNOPTR (last_line_symbol
) = function_lineoff
;
2197 SF_SET_PROCESS (last_line_symbol
);
2198 SF_SET_ADJ_LNNOPTR (last_line_symbol
);
2199 SF_SET_PROCESS (def_symbol_in_progress
);
2200 function_lineoff
= -1;
2202 /* Value is always set to . */
2203 def_symbol_in_progress
->sy_frag
= frag_now
;
2204 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2209 #endif /* C_AUTOARG */
2219 SF_SET_DEBUG (def_symbol_in_progress
);
2220 S_SET_SEGMENT (def_symbol_in_progress
, absolute_section
);
2226 /* Valid but set somewhere else (s_comm, s_lcomm, colon) */
2232 as_warn (_("unexpected storage class %d"), S_GET_STORAGE_CLASS (def_symbol_in_progress
));
2234 } /* switch on storage class */
2236 /* Now that we have built a debug symbol, try to find if we should
2237 merge with an existing symbol or not. If a symbol is C_EFCN or
2238 absolute_section or untagged SEG_DEBUG it never merges. We also
2239 don't merge labels, which are in a different namespace, nor
2240 symbols which have not yet been defined since they are typically
2241 unique, nor do we merge tags with non-tags. */
2243 /* Two cases for functions. Either debug followed by definition or
2244 definition followed by debug. For definition first, we will
2245 merge the debug symbol into the definition. For debug first, the
2246 lineno entry MUST point to the definition function or else it
2247 will point off into space when crawl_symbols() merges the debug
2248 symbol into the real symbol. Therefor, let's presume the debug
2249 symbol is a real function reference. */
2251 /* FIXME-SOON If for some reason the definition label/symbol is
2252 never seen, this will probably leave an undefined symbol at link
2255 if (S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_EFCN
2256 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_LABEL
2257 || (S_GET_SEGMENT (def_symbol_in_progress
) == SEG_DEBUG
2258 && !SF_GET_TAG (def_symbol_in_progress
))
2259 || S_GET_SEGMENT (def_symbol_in_progress
) == absolute_section
2260 || def_symbol_in_progress
->sy_value
.X_op
!= O_constant
2261 || (symbolP
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
), DO_NOT_STRIP
)) == NULL
2262 || (SF_GET_TAG (def_symbol_in_progress
) != SF_GET_TAG (symbolP
)))
2264 symbol_append (def_symbol_in_progress
, symbol_lastP
, &symbol_rootP
,
2269 /* This symbol already exists, merge the newly created symbol
2270 into the old one. This is not mandatory. The linker can
2271 handle duplicate symbols correctly. But I guess that it save
2272 a *lot* of space if the assembly file defines a lot of
2275 /* The debug entry (def_symbol_in_progress) is merged into the
2276 previous definition. */
2278 c_symbol_merge (def_symbol_in_progress
, symbolP
);
2279 /* FIXME-SOON Should *def_symbol_in_progress be free'd? xoxorich. */
2280 def_symbol_in_progress
= symbolP
;
2282 if (SF_GET_FUNCTION (def_symbol_in_progress
)
2283 || SF_GET_TAG (def_symbol_in_progress
)
2284 || S_GET_STORAGE_CLASS (def_symbol_in_progress
) == C_STAT
)
2286 /* For functions, and tags, and static symbols, the symbol
2287 *must* be where the debug symbol appears. Move the
2288 existing symbol to the current place. */
2289 /* If it already is at the end of the symbol list, do nothing */
2290 if (def_symbol_in_progress
!= symbol_lastP
)
2292 symbol_remove (def_symbol_in_progress
, &symbol_rootP
,
2294 symbol_append (def_symbol_in_progress
, symbol_lastP
,
2295 &symbol_rootP
, &symbol_lastP
);
2296 } /* if not already in place */
2298 } /* normal or mergable */
2300 if (SF_GET_TAG (def_symbol_in_progress
))
2304 oldtag
= symbol_find_base (S_GET_NAME (def_symbol_in_progress
),
2306 if (oldtag
== NULL
|| ! SF_GET_TAG (oldtag
))
2307 tag_insert (S_GET_NAME (def_symbol_in_progress
),
2308 def_symbol_in_progress
);
2311 if (SF_GET_FUNCTION (def_symbol_in_progress
))
2313 know (sizeof (def_symbol_in_progress
) <= sizeof (long));
2315 = c_line_new (def_symbol_in_progress
, 0, 0, &zero_address_frag
);
2317 SF_SET_PROCESS (def_symbol_in_progress
);
2319 if (symbolP
== NULL
)
2321 /* That is, if this is the first time we've seen the
2323 symbol_table_insert (def_symbol_in_progress
);
2324 } /* definition follows debug */
2325 } /* Create the line number entry pointing to the function being defined */
2327 def_symbol_in_progress
= NULL
;
2328 demand_empty_rest_of_line ();
2332 obj_coff_dim (ignore
)
2337 if (def_symbol_in_progress
== NULL
)
2339 as_warn (_(".dim pseudo-op used outside of .def/.endef: ignored."));
2340 demand_empty_rest_of_line ();
2342 } /* if not inside .def/.endef */
2344 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2346 for (dim_index
= 0; dim_index
< DIMNUM
; dim_index
++)
2348 SKIP_WHITESPACES ();
2349 SA_SET_SYM_DIMEN (def_symbol_in_progress
, dim_index
,
2350 get_absolute_expression ());
2352 switch (*input_line_pointer
)
2355 input_line_pointer
++;
2359 as_warn (_("badly formed .dim directive ignored"));
2360 /* intentional fallthrough */
2368 demand_empty_rest_of_line ();
2372 obj_coff_line (ignore
)
2378 if (def_symbol_in_progress
== NULL
)
2384 name
= S_GET_NAME (def_symbol_in_progress
);
2385 this_base
= get_absolute_expression ();
2387 /* Only .bf symbols indicate the use of a new base line number; the
2388 line numbers associated with .ef, .bb, .eb are relative to the
2389 start of the containing function. */
2390 if (!strcmp (".bf", name
))
2392 #if 0 /* XXX Can we ever have line numbers going backwards? */
2393 if (this_base
> line_base
)
2396 line_base
= this_base
;
2404 listing_source_line ((unsigned int) line_base
);
2410 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2411 SA_SET_SYM_LNNO (def_symbol_in_progress
, this_base
);
2413 demand_empty_rest_of_line ();
2417 obj_coff_size (ignore
)
2420 if (def_symbol_in_progress
== NULL
)
2422 as_warn (_(".size pseudo-op used outside of .def/.endef ignored."));
2423 demand_empty_rest_of_line ();
2425 } /* if not inside .def/.endef */
2427 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2428 SA_SET_SYM_SIZE (def_symbol_in_progress
, get_absolute_expression ());
2429 demand_empty_rest_of_line ();
2433 obj_coff_scl (ignore
)
2436 if (def_symbol_in_progress
== NULL
)
2438 as_warn (_(".scl pseudo-op used outside of .def/.endef ignored."));
2439 demand_empty_rest_of_line ();
2441 } /* if not inside .def/.endef */
2443 S_SET_STORAGE_CLASS (def_symbol_in_progress
, get_absolute_expression ());
2444 demand_empty_rest_of_line ();
2448 obj_coff_tag (ignore
)
2454 if (def_symbol_in_progress
== NULL
)
2456 as_warn (_(".tag pseudo-op used outside of .def/.endef ignored."));
2457 demand_empty_rest_of_line ();
2461 S_SET_NUMBER_AUXILIARY (def_symbol_in_progress
, 1);
2462 symbol_name
= input_line_pointer
;
2463 name_end
= get_symbol_end ();
2464 #ifdef tc_canonicalize_symbol_name
2465 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2468 /* Assume that the symbol referred to by .tag is always defined.
2469 This was a bad assumption. I've added find_or_make. xoxorich. */
2470 SA_SET_SYM_TAGNDX (def_symbol_in_progress
,
2471 (long) tag_find_or_make (symbol_name
));
2472 if (SA_GET_SYM_TAGNDX (def_symbol_in_progress
) == 0L)
2474 as_warn (_("tag not found for .tag %s"), symbol_name
);
2477 SF_SET_TAGGED (def_symbol_in_progress
);
2478 *input_line_pointer
= name_end
;
2480 demand_empty_rest_of_line ();
2484 obj_coff_type (ignore
)
2487 if (def_symbol_in_progress
== NULL
)
2489 as_warn (_(".type pseudo-op used outside of .def/.endef ignored."));
2490 demand_empty_rest_of_line ();
2492 } /* if not inside .def/.endef */
2494 S_SET_DATA_TYPE (def_symbol_in_progress
, get_absolute_expression ());
2496 if (ISFCN (S_GET_DATA_TYPE (def_symbol_in_progress
)) &&
2497 S_GET_STORAGE_CLASS (def_symbol_in_progress
) != C_TPDEF
)
2499 SF_SET_FUNCTION (def_symbol_in_progress
);
2500 } /* is a function */
2502 demand_empty_rest_of_line ();
2506 obj_coff_val (ignore
)
2509 if (def_symbol_in_progress
== NULL
)
2511 as_warn (_(".val pseudo-op used outside of .def/.endef ignored."));
2512 demand_empty_rest_of_line ();
2514 } /* if not inside .def/.endef */
2516 if (is_name_beginner (*input_line_pointer
))
2518 char *symbol_name
= input_line_pointer
;
2519 char name_end
= get_symbol_end ();
2521 #ifdef tc_canonicalize_symbol_name
2522 symbol_name
= tc_canonicalize_symbol_name (symbol_name
);
2525 if (!strcmp (symbol_name
, "."))
2527 def_symbol_in_progress
->sy_frag
= frag_now
;
2528 S_SET_VALUE (def_symbol_in_progress
, (valueT
) frag_now_fix ());
2529 /* If the .val is != from the .def (e.g. statics) */
2531 else if (strcmp (S_GET_NAME (def_symbol_in_progress
), symbol_name
))
2533 def_symbol_in_progress
->sy_value
.X_op
= O_symbol
;
2534 def_symbol_in_progress
->sy_value
.X_add_symbol
=
2535 symbol_find_or_make (symbol_name
);
2536 def_symbol_in_progress
->sy_value
.X_op_symbol
= NULL
;
2537 def_symbol_in_progress
->sy_value
.X_add_number
= 0;
2539 /* If the segment is undefined when the forward reference is
2540 resolved, then copy the segment id from the forward
2542 SF_SET_GET_SEGMENT (def_symbol_in_progress
);
2544 /* FIXME: gcc can generate address expressions
2545 here in unusual cases (search for "obscure"
2546 in sdbout.c). We just ignore the offset
2547 here, thus generating incorrect debugging
2548 information. We ignore the rest of the
2551 /* Otherwise, it is the name of a non debug symbol and
2552 its value will be calculated later. */
2553 *input_line_pointer
= name_end
;
2555 /* FIXME: this is to avoid an error message in the
2556 FIXME case mentioned just above. */
2557 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
2558 ++input_line_pointer
;
2562 S_SET_VALUE (def_symbol_in_progress
,
2563 (valueT
) get_absolute_expression ());
2564 } /* if symbol based */
2566 demand_empty_rest_of_line ();
2571 /* Handle the .linkonce pseudo-op. This is parsed by s_linkonce in
2572 read.c, which then calls this object file format specific routine. */
2575 obj_coff_pe_handle_link_once (type
)
2576 enum linkonce_type type
;
2578 seg_info (now_seg
)->scnhdr
.s_flags
|= IMAGE_SCN_LNK_COMDAT
;
2580 /* We store the type in the seg_info structure, and use it to set up
2581 the auxiliary entry for the section symbol in c_section_symbol. */
2582 seg_info (now_seg
)->linkonce
= type
;
2588 coff_obj_read_begin_hook ()
2590 /* These had better be the same. Usually 18 bytes. */
2592 know (sizeof (SYMENT
) == sizeof (AUXENT
));
2593 know (SYMESZ
== AUXESZ
);
2598 /* This function runs through the symbol table and puts all the
2599 externals onto another chain */
2601 /* The chain of globals. */
2602 symbolS
*symbol_globalP
;
2603 symbolS
*symbol_global_lastP
;
2605 /* The chain of externals */
2606 symbolS
*symbol_externP
;
2607 symbolS
*symbol_extern_lastP
;
2610 symbolS
*last_functionP
;
2611 static symbolS
*last_bfP
;
2618 unsigned int symbol_number
= 0;
2619 unsigned int last_file_symno
= 0;
2621 struct filename_list
*filename_list_scan
= filename_list_head
;
2623 for (symbolP
= symbol_rootP
;
2625 symbolP
= symbolP
? symbol_next (symbolP
) : symbol_rootP
)
2627 if (symbolP
->sy_mri_common
)
2629 if (S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2630 as_bad (_("%s: global symbols not supported in common sections"),
2631 S_GET_NAME (symbolP
));
2632 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2636 if (!SF_GET_DEBUG (symbolP
))
2638 /* Debug symbols do not need all this rubbish */
2639 symbolS
*real_symbolP
;
2641 /* L* and C_EFCN symbols never merge. */
2642 if (!SF_GET_LOCAL (symbolP
)
2643 && !SF_GET_STATICS (symbolP
)
2644 && S_GET_STORAGE_CLASS (symbolP
) != C_LABEL
2645 && symbolP
->sy_value
.X_op
== O_constant
2646 && (real_symbolP
= symbol_find_base (S_GET_NAME (symbolP
), DO_NOT_STRIP
))
2647 && real_symbolP
!= symbolP
)
2649 /* FIXME-SOON: where do dups come from?
2650 Maybe tag references before definitions? xoxorich. */
2651 /* Move the debug data from the debug symbol to the
2652 real symbol. Do NOT do the oposite (i.e. move from
2653 real symbol to debug symbol and remove real symbol from the
2654 list.) Because some pointers refer to the real symbol
2655 whereas no pointers refer to the debug symbol. */
2656 c_symbol_merge (symbolP
, real_symbolP
);
2657 /* Replace the current symbol by the real one */
2658 /* The symbols will never be the last or the first
2659 because : 1st symbol is .file and 3 last symbols are
2660 .text, .data, .bss */
2661 symbol_remove (real_symbolP
, &symbol_rootP
, &symbol_lastP
);
2662 symbol_insert (real_symbolP
, symbolP
, &symbol_rootP
, &symbol_lastP
);
2663 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2664 symbolP
= real_symbolP
;
2665 } /* if not local but dup'd */
2667 if (flag_readonly_data_in_text
&& (S_GET_SEGMENT (symbolP
) == SEG_E1
))
2669 S_SET_SEGMENT (symbolP
, SEG_E0
);
2670 } /* push data into text */
2672 resolve_symbol_value (symbolP
, 1);
2674 if (S_GET_STORAGE_CLASS (symbolP
) == C_NULL
)
2676 if (!S_IS_DEFINED (symbolP
) && !SF_GET_LOCAL (symbolP
))
2678 S_SET_EXTERNAL (symbolP
);
2680 else if (S_GET_SEGMENT (symbolP
) == SEG_E0
)
2682 S_SET_STORAGE_CLASS (symbolP
, C_LABEL
);
2686 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
2690 /* Mainly to speed up if not -g */
2691 if (SF_GET_PROCESS (symbolP
))
2693 /* Handle the nested blocks auxiliary info. */
2694 if (S_GET_STORAGE_CLASS (symbolP
) == C_BLOCK
)
2696 if (!strcmp (S_GET_NAME (symbolP
), ".bb"))
2697 stack_push (block_stack
, (char *) &symbolP
);
2700 register symbolS
*begin_symbolP
;
2701 begin_symbolP
= *(symbolS
**) stack_pop (block_stack
);
2702 if (begin_symbolP
== (symbolS
*) 0)
2703 as_warn (_("mismatched .eb"));
2705 SA_SET_SYM_ENDNDX (begin_symbolP
, symbol_number
+ 2);
2708 /* If we are able to identify the type of a function, and we
2709 are out of a function (last_functionP == 0) then, the
2710 function symbol will be associated with an auxiliary
2712 if (last_functionP
== (symbolS
*) 0 &&
2713 SF_GET_FUNCTION (symbolP
))
2715 last_functionP
= symbolP
;
2717 if (S_GET_NUMBER_AUXILIARY (symbolP
) < 1)
2719 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
2720 } /* make it at least 1 */
2722 /* Clobber possible stale .dim information. */
2724 /* Iffed out by steve - this fries the lnnoptr info too */
2725 bzero (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
,
2726 sizeof (symbolP
->sy_symbol
.ost_auxent
[0].x_sym
.x_fcnary
.x_ary
.x_dimen
));
2729 if (S_GET_STORAGE_CLASS (symbolP
) == C_FCN
)
2731 if (strcmp (S_GET_NAME (symbolP
), ".bf") == 0)
2733 if (last_bfP
!= NULL
)
2734 SA_SET_SYM_ENDNDX (last_bfP
, symbol_number
);
2738 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EFCN
)
2740 /* I don't even know if this is needed for sdb. But
2741 the standard assembler generates it, so... */
2742 if (last_functionP
== (symbolS
*) 0)
2743 as_fatal (_("C_EFCN symbol out of scope"));
2744 SA_SET_SYM_FSIZE (last_functionP
,
2745 (long) (S_GET_VALUE (symbolP
) -
2746 S_GET_VALUE (last_functionP
)));
2747 SA_SET_SYM_ENDNDX (last_functionP
, symbol_number
);
2748 last_functionP
= (symbolS
*) 0;
2752 else if (SF_GET_TAG (symbolP
))
2754 /* First descriptor of a structure must point to
2755 the first slot after the structure description. */
2756 last_tagP
= symbolP
;
2759 else if (S_GET_STORAGE_CLASS (symbolP
) == C_EOS
)
2761 /* +2 take in account the current symbol */
2762 SA_SET_SYM_ENDNDX (last_tagP
, symbol_number
+ 2);
2764 else if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
)
2766 /* If the filename was too long to fit in the
2767 auxent, put it in the string table */
2768 if (SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
2769 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
2771 SA_SET_FILE_FNAME_OFFSET (symbolP
, string_byte_count
);
2772 string_byte_count
+= strlen (filename_list_scan
->filename
) + 1;
2773 filename_list_scan
= filename_list_scan
->next
;
2775 if (S_GET_VALUE (symbolP
))
2777 S_SET_VALUE (symbolP
, last_file_symno
);
2778 last_file_symno
= symbol_number
;
2779 } /* no one points at the first .file symbol */
2780 } /* if debug or tag or eos or file */
2782 #ifdef tc_frob_coff_symbol
2783 tc_frob_coff_symbol (symbolP
);
2786 /* We must put the external symbols apart. The loader
2787 does not bomb if we do not. But the references in
2788 the endndx field for a .bb symbol are not corrected
2789 if an external symbol is removed between .bb and .be.
2790 I.e in the following case :
2791 [20] .bb endndx = 22
2794 ld will move the symbol 21 to the end of the list but
2795 endndx will still be 22 instead of 21. */
2798 if (SF_GET_LOCAL (symbolP
))
2800 /* remove C_EFCN and LOCAL (L...) symbols */
2801 /* next pointer remains valid */
2802 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2805 else if (symbolP
->sy_value
.X_op
== O_symbol
2806 && (! S_IS_DEFINED (symbolP
) || S_IS_COMMON (symbolP
)))
2808 /* Skip symbols which were equated to undefined or common
2810 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2812 else if (!S_IS_DEFINED (symbolP
)
2813 && !S_IS_DEBUG (symbolP
)
2814 && !SF_GET_STATICS (symbolP
) &&
2815 S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2816 { /* C_EXT && !SF_GET_FUNCTION(symbolP)) */
2817 /* if external, Remove from the list */
2818 symbolS
*hold
= symbol_previous (symbolP
);
2820 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2821 symbol_clear_list_pointers (symbolP
);
2822 symbol_append (symbolP
, symbol_extern_lastP
, &symbol_externP
, &symbol_extern_lastP
);
2825 else if (! S_IS_DEBUG (symbolP
)
2826 && ! SF_GET_STATICS (symbolP
)
2827 && ! SF_GET_FUNCTION (symbolP
)
2828 && S_GET_STORAGE_CLASS (symbolP
) == C_EXT
)
2830 symbolS
*hold
= symbol_previous (symbolP
);
2832 /* The O'Reilly COFF book says that defined global symbols
2833 come at the end of the symbol table, just before
2834 undefined global symbols. */
2836 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
2837 symbol_clear_list_pointers (symbolP
);
2838 symbol_append (symbolP
, symbol_global_lastP
, &symbol_globalP
,
2839 &symbol_global_lastP
);
2844 if (SF_GET_STRING (symbolP
))
2846 symbolP
->sy_name_offset
= string_byte_count
;
2847 string_byte_count
+= strlen (S_GET_NAME (symbolP
)) + 1;
2851 symbolP
->sy_name_offset
= 0;
2852 } /* fix "long" names */
2854 symbolP
->sy_number
= symbol_number
;
2855 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2856 } /* if local symbol */
2857 } /* traverse the symbol list */
2858 return symbol_number
;
2864 glue_symbols (head
, tail
)
2868 unsigned int symbol_number
= 0;
2870 while (*head
!= NULL
)
2872 symbolS
*tmp
= *head
;
2875 symbol_remove (tmp
, head
, tail
);
2876 symbol_append (tmp
, symbol_lastP
, &symbol_rootP
, &symbol_lastP
);
2879 if (SF_GET_STRING (tmp
))
2881 tmp
->sy_name_offset
= string_byte_count
;
2882 string_byte_count
+= strlen (S_GET_NAME (tmp
)) + 1;
2886 tmp
->sy_name_offset
= 0;
2887 } /* fix "long" names */
2889 tmp
->sy_number
= symbol_number
;
2890 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (tmp
);
2891 } /* append the entire extern chain */
2893 return symbol_number
;
2899 unsigned int symbol_number
= 0;
2902 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
2904 symbolP
->sy_number
= symbol_number
;
2906 if (SF_GET_TAGGED (symbolP
))
2910 ((symbolS
*) SA_GET_SYM_TAGNDX (symbolP
))->sy_number
);
2913 symbol_number
+= 1 + S_GET_NUMBER_AUXILIARY (symbolP
);
2916 return symbol_number
;
2920 crawl_symbols (h
, abfd
)
2926 /* Initialize the stack used to keep track of the matching .bb .be */
2928 block_stack
= stack_init (512, sizeof (symbolS
*));
2930 /* The symbol list should be ordered according to the following sequence
2933 * . debug entries for functions
2934 * . fake symbols for the sections, including .text .data and .bss
2936 * . undefined symbols
2937 * But this is not mandatory. The only important point is to put the
2938 * undefined symbols at the end of the list.
2941 /* Is there a .file symbol ? If not insert one at the beginning. */
2942 if (symbol_rootP
== NULL
2943 || S_GET_STORAGE_CLASS (symbol_rootP
) != C_FILE
)
2945 c_dot_file_symbol ("fake");
2949 * Build up static symbols for the sections, they are filled in later
2953 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2954 if (segment_info
[i
].scnhdr
.s_name
[0])
2955 segment_info
[i
].dot
= c_section_symbol (segment_info
[i
].name
,
2958 /* Take all the externals out and put them into another chain */
2959 H_SET_SYMBOL_TABLE_SIZE (h
, yank_symbols ());
2960 /* Take the externals and glue them onto the end.*/
2961 H_SET_SYMBOL_TABLE_SIZE (h
,
2962 (H_GET_SYMBOL_COUNT (h
)
2963 + glue_symbols (&symbol_globalP
,
2964 &symbol_global_lastP
)
2965 + glue_symbols (&symbol_externP
,
2966 &symbol_extern_lastP
)));
2968 H_SET_SYMBOL_TABLE_SIZE (h
, tie_tags ());
2969 know (symbol_globalP
== NULL
);
2970 know (symbol_global_lastP
== NULL
);
2971 know (symbol_externP
== NULL
);
2972 know (symbol_extern_lastP
== NULL
);
2976 * Find strings by crawling along symbol table chain.
2984 struct filename_list
*filename_list_scan
= filename_list_head
;
2986 /* Gotta do md_ byte-ordering stuff for string_byte_count first - KWK */
2987 md_number_to_chars (where
, (valueT
) string_byte_count
, 4);
2990 #ifdef COFF_LONG_SECTION_NAMES
2991 /* Support long section names as found in PE. This code must
2992 coordinate with that in coff_header_append and write_object_file. */
2996 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
2998 if (segment_info
[i
].scnhdr
.s_name
[0]
2999 && strlen (segment_info
[i
].name
) > SCNNMLEN
)
3003 size
= strlen (segment_info
[i
].name
) + 1;
3004 memcpy (where
, segment_info
[i
].name
, size
);
3009 #endif /* COFF_LONG_SECTION_NAMES */
3011 for (symbolP
= symbol_rootP
;
3013 symbolP
= symbol_next (symbolP
))
3017 if (SF_GET_STRING (symbolP
))
3019 size
= strlen (S_GET_NAME (symbolP
)) + 1;
3020 memcpy (where
, S_GET_NAME (symbolP
), size
);
3023 if (S_GET_STORAGE_CLASS (symbolP
) == C_FILE
3024 && SA_GET_FILE_FNAME_ZEROS (symbolP
) == 0
3025 && SA_GET_FILE_FNAME_OFFSET (symbolP
) != 0)
3027 size
= strlen (filename_list_scan
->filename
) + 1;
3028 memcpy (where
, filename_list_scan
->filename
, size
);
3029 filename_list_scan
= filename_list_scan
->next
;
3036 do_linenos_for (abfd
, h
, file_cursor
)
3039 unsigned long *file_cursor
;
3042 unsigned long start
= *file_cursor
;
3044 for (idx
= SEG_E0
; idx
< SEG_LAST
; idx
++)
3046 segment_info_type
*s
= segment_info
+ idx
;
3049 if (s
->scnhdr
.s_nlnno
!= 0)
3051 struct lineno_list
*line_ptr
;
3053 struct external_lineno
*buffer
=
3054 (struct external_lineno
*) xmalloc (s
->scnhdr
.s_nlnno
* LINESZ
);
3056 struct external_lineno
*dst
= buffer
;
3058 /* Run through the table we've built and turn it into its external
3059 form, take this chance to remove duplicates */
3061 for (line_ptr
= s
->lineno_list_head
;
3062 line_ptr
!= (struct lineno_list
*) NULL
;
3063 line_ptr
= line_ptr
->next
)
3066 if (line_ptr
->line
.l_lnno
== 0)
3068 /* Turn a pointer to a symbol into the symbols' index */
3069 line_ptr
->line
.l_addr
.l_symndx
=
3070 ((symbolS
*) line_ptr
->line
.l_addr
.l_symndx
)->sy_number
;
3074 line_ptr
->line
.l_addr
.l_paddr
+= ((struct frag
*) (line_ptr
->frag
))->fr_address
;
3078 (void) bfd_coff_swap_lineno_out (abfd
, &(line_ptr
->line
), dst
);
3083 s
->scnhdr
.s_lnnoptr
= *file_cursor
;
3085 bfd_write (buffer
, 1, s
->scnhdr
.s_nlnno
* LINESZ
, abfd
);
3088 *file_cursor
+= s
->scnhdr
.s_nlnno
* LINESZ
;
3091 H_SET_LINENO_SIZE (h
, *file_cursor
- start
);
3095 /* Now we run through the list of frag chains in a segment and
3096 make all the subsegment frags appear at the end of the
3097 list, as if the seg 0 was extra long */
3104 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3106 frchainS
*head
= segment_info
[i
].frchainP
;
3108 fragS
*prev_frag
= &dummy
;
3110 while (head
&& head
->frch_seg
== i
)
3112 prev_frag
->fr_next
= head
->frch_root
;
3113 prev_frag
= head
->frch_last
;
3114 head
= head
->frch_next
;
3116 prev_frag
->fr_next
= 0;
3120 unsigned long machine
;
3123 write_object_file ()
3127 struct frchain
*frchain_ptr
;
3129 object_headers headers
;
3130 unsigned long file_cursor
;
3133 abfd
= bfd_openw (out_file_name
, TARGET_FORMAT
);
3138 as_perror (_("FATAL: Can't create %s"), out_file_name
);
3139 exit (EXIT_FAILURE
);
3141 bfd_set_format (abfd
, bfd_object
);
3142 bfd_set_arch_mach (abfd
, BFD_ARCH
, machine
);
3144 string_byte_count
= 4;
3146 for (frchain_ptr
= frchain_root
;
3147 frchain_ptr
!= (struct frchain
*) NULL
;
3148 frchain_ptr
= frchain_ptr
->frch_next
)
3150 /* Run through all the sub-segments and align them up. Also
3151 close any open frags. We tack a .fill onto the end of the
3152 frag chain so that any .align's size can be worked by looking
3153 at the next frag. */
3155 subseg_set (frchain_ptr
->frch_seg
, frchain_ptr
->frch_subseg
);
3156 #ifndef SUB_SEGMENT_ALIGN
3157 #define SUB_SEGMENT_ALIGN(SEG) 1
3160 md_do_align (SUB_SEGMENT_ALIGN (now_seg
), (char *) NULL
, 0, 0,
3163 frag_align (SUB_SEGMENT_ALIGN (now_seg
), NOP_OPCODE
, 0);
3167 frag_wane (frag_now
);
3168 frag_now
->fr_fix
= 0;
3169 know (frag_now
->fr_next
== NULL
);
3176 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3178 relax_segment (segment_info
[i
].frchainP
->frch_root
, i
);
3181 H_SET_NUMBER_OF_SECTIONS (&headers
, 0);
3183 /* Find out how big the sections are, and set the addresses. */
3185 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3189 segment_info
[i
].scnhdr
.s_paddr
= addr
;
3190 segment_info
[i
].scnhdr
.s_vaddr
= addr
;
3192 if (segment_info
[i
].scnhdr
.s_name
[0])
3194 H_SET_NUMBER_OF_SECTIONS (&headers
,
3195 H_GET_NUMBER_OF_SECTIONS (&headers
) + 1);
3197 #ifdef COFF_LONG_SECTION_NAMES
3198 /* Support long section names as found in PE. This code
3199 must coordinate with that in coff_header_append and
3204 len
= strlen (segment_info
[i
].name
);
3206 string_byte_count
+= len
+ 1;
3208 #endif /* COFF_LONG_SECTION_NAMES */
3211 size
= size_section (abfd
, (unsigned int) i
);
3214 /* I think the section alignment is only used on the i960; the
3215 i960 needs it, and it should do no harm on other targets. */
3216 #ifdef ALIGNMENT_IN_S_FLAGS
3217 segment_info
[i
].scnhdr
.s_flags
|= (section_alignment
[i
] & 0xF) << 8;
3219 segment_info
[i
].scnhdr
.s_align
= 1 << section_alignment
[i
];
3223 H_SET_TEXT_SIZE (&headers
, size
);
3224 else if (i
== SEG_E1
)
3225 H_SET_DATA_SIZE (&headers
, size
);
3226 else if (i
== SEG_E2
)
3227 H_SET_BSS_SIZE (&headers
, size
);
3230 /* Turn the gas native symbol table shape into a coff symbol table */
3231 crawl_symbols (&headers
, abfd
);
3233 if (string_byte_count
== 4)
3234 string_byte_count
= 0;
3236 H_SET_STRING_SIZE (&headers
, string_byte_count
);
3242 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3244 fixup_mdeps (segment_info
[i
].frchainP
->frch_root
, &headers
, i
);
3245 fixup_segment (&segment_info
[i
], i
);
3248 /* Look for ".stab" segments and fill in their initial symbols
3250 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
3252 name
= segment_info
[i
].name
;
3255 && strncmp (".stab", name
, 5) == 0
3256 && strncmp (".stabstr", name
, 8) != 0)
3257 adjust_stab_section (abfd
, i
);
3260 file_cursor
= H_GET_TEXT_FILE_OFFSET (&headers
);
3262 bfd_seek (abfd
, (file_ptr
) file_cursor
, 0);
3264 /* Plant the data */
3266 fill_section (abfd
, &headers
, &file_cursor
);
3268 do_relocs_for (abfd
, &headers
, &file_cursor
);
3270 do_linenos_for (abfd
, &headers
, &file_cursor
);
3272 H_SET_FILE_MAGIC_NUMBER (&headers
, COFF_MAGIC
);
3273 #ifndef OBJ_COFF_OMIT_TIMESTAMP
3274 H_SET_TIME_STAMP (&headers
, (long)time((time_t *)0));
3276 H_SET_TIME_STAMP (&headers
, 0);
3278 #ifdef TC_COFF_SET_MACHINE
3279 TC_COFF_SET_MACHINE (&headers
);
3283 #define COFF_FLAGS 0
3286 #ifdef KEEP_RELOC_INFO
3287 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3288 COFF_FLAGS
| coff_flags
));
3290 H_SET_FLAGS (&headers
, ((H_GET_LINENO_SIZE(&headers
) ? 0 : F_LNNO
) |
3291 (H_GET_RELOCATION_SIZE(&headers
) ? 0 : F_RELFLG
) |
3292 COFF_FLAGS
| coff_flags
));
3296 unsigned int symtable_size
= H_GET_SYMBOL_TABLE_SIZE (&headers
);
3297 char *buffer1
= xmalloc (symtable_size
+ string_byte_count
+ 1);
3299 H_SET_SYMBOL_TABLE_POINTER (&headers
, bfd_tell (abfd
));
3300 w_symbols (abfd
, buffer1
, symbol_rootP
);
3301 if (string_byte_count
> 0)
3302 w_strings (buffer1
+ symtable_size
);
3303 bfd_write (buffer1
, 1, symtable_size
+ string_byte_count
, abfd
);
3307 coff_header_append (abfd
, &headers
);
3309 /* Recent changes to write need this, but where it should
3310 go is up to Ken.. */
3311 if (bfd_close_all_done (abfd
) == false)
3312 as_fatal (_("Can't close %s: %s"), out_file_name
,
3313 bfd_errmsg (bfd_get_error ()));
3316 extern bfd
*stdoutput
;
3323 /* Add a new segment. This is called from subseg_new via the
3324 obj_new_segment macro. */
3327 obj_coff_add_segment (name
)
3332 #ifndef COFF_LONG_SECTION_NAMES
3333 char buf
[SCNNMLEN
+ 1];
3335 strncpy (buf
, name
, SCNNMLEN
);
3336 buf
[SCNNMLEN
] = '\0';
3340 for (i
= SEG_E0
; i
< SEG_LAST
&& segment_info
[i
].scnhdr
.s_name
[0]; i
++)
3341 if (strcmp (name
, segment_info
[i
].name
) == 0)
3346 as_bad (_("Too many new sections; can't add \"%s\""), name
);
3350 /* Add a new section. */
3351 strncpy (segment_info
[i
].scnhdr
.s_name
, name
,
3352 sizeof (segment_info
[i
].scnhdr
.s_name
));
3353 segment_info
[i
].scnhdr
.s_flags
= STYP_REG
;
3354 segment_info
[i
].name
= xstrdup (name
);
3360 * implement the .section pseudo op:
3361 * .section name {, "flags"}
3363 * | +--- optional flags: 'b' for bss
3365 * +-- section name 'l' for lib
3369 * 'd' (apparently m88k for data)
3371 * 'r' for read-only data
3372 * But if the argument is not a quoted string, treat it as a
3373 * subsegment number.
3377 obj_coff_section (ignore
)
3380 /* Strip out the section name */
3381 char *section_name
, *name
;
3394 else if (type
== 'D')
3396 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3401 section_name
= input_line_pointer
;
3402 c
= get_symbol_end ();
3404 name
= xmalloc (input_line_pointer
- section_name
+ 1);
3405 strcpy (name
, section_name
);
3407 *input_line_pointer
= c
;
3413 if (*input_line_pointer
== ',')
3415 ++input_line_pointer
;
3418 if (*input_line_pointer
!= '"')
3419 exp
= get_absolute_expression ();
3422 ++input_line_pointer
;
3423 while (*input_line_pointer
!= '"'
3424 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
3426 switch (*input_line_pointer
)
3428 case 'b': flags
|= STYP_BSS
; break;
3429 case 'i': flags
|= STYP_INFO
; break;
3430 case 'l': flags
|= STYP_LIB
; break;
3431 case 'n': flags
|= STYP_NOLOAD
; break;
3432 case 'o': flags
|= STYP_OVER
; break;
3434 case 'w': flags
|= STYP_DATA
; break;
3435 case 'x': flags
|= STYP_TEXT
; break;
3436 case 'r': flags
|= STYP_LIT
; break;
3438 as_warn(_("unknown section attribute '%c'"),
3439 *input_line_pointer
);
3442 ++input_line_pointer
;
3444 if (*input_line_pointer
== '"')
3445 ++input_line_pointer
;
3449 subseg_new (name
, (subsegT
) exp
);
3451 segment_info
[now_seg
].scnhdr
.s_flags
|= flags
;
3453 demand_empty_rest_of_line ();
3458 obj_coff_text (ignore
)
3461 subseg_new (".text", get_absolute_expression ());
3466 obj_coff_data (ignore
)
3469 if (flag_readonly_data_in_text
)
3470 subseg_new (".text", get_absolute_expression () + 1000);
3472 subseg_new (".data", get_absolute_expression ());
3476 obj_coff_ident (ignore
)
3479 segT current_seg
= now_seg
; /* save current seg */
3480 subsegT current_subseg
= now_subseg
;
3481 subseg_new (".comment", 0); /* .comment seg */
3482 stringer (1); /* read string */
3483 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3487 c_symbol_merge (debug
, normal
)
3491 S_SET_DATA_TYPE (normal
, S_GET_DATA_TYPE (debug
));
3492 S_SET_STORAGE_CLASS (normal
, S_GET_STORAGE_CLASS (debug
));
3494 if (S_GET_NUMBER_AUXILIARY (debug
) > S_GET_NUMBER_AUXILIARY (normal
))
3496 S_SET_NUMBER_AUXILIARY (normal
, S_GET_NUMBER_AUXILIARY (debug
));
3497 } /* take the most we have */
3499 if (S_GET_NUMBER_AUXILIARY (debug
) > 0)
3501 memcpy ((char *) &normal
->sy_symbol
.ost_auxent
[0],
3502 (char *) &debug
->sy_symbol
.ost_auxent
[0],
3503 (unsigned int) (S_GET_NUMBER_AUXILIARY (debug
) * AUXESZ
));
3504 } /* Move all the auxiliary information */
3506 /* Move the debug flags. */
3507 SF_SET_DEBUG_FIELD (normal
, SF_GET_DEBUG_FIELD (debug
));
3508 } /* c_symbol_merge() */
3511 c_line_new (symbol
, paddr
, line_number
, frag
)
3517 struct lineno_list
*new_line
=
3518 (struct lineno_list
*) xmalloc (sizeof (struct lineno_list
));
3520 segment_info_type
*s
= segment_info
+ now_seg
;
3521 new_line
->line
.l_lnno
= line_number
;
3523 if (line_number
== 0)
3525 last_line_symbol
= symbol
;
3526 new_line
->line
.l_addr
.l_symndx
= (long) symbol
;
3530 new_line
->line
.l_addr
.l_paddr
= paddr
;
3533 new_line
->frag
= (char *) frag
;
3534 new_line
->next
= (struct lineno_list
*) NULL
;
3537 if (s
->lineno_list_head
== (struct lineno_list
*) NULL
)
3539 s
->lineno_list_head
= new_line
;
3543 s
->lineno_list_tail
->next
= new_line
;
3545 s
->lineno_list_tail
= new_line
;
3546 return LINESZ
* s
->scnhdr
.s_nlnno
++;
3550 c_dot_file_symbol (filename
)
3555 symbolP
= symbol_new (".file",
3558 &zero_address_frag
);
3560 S_SET_STORAGE_CLASS (symbolP
, C_FILE
);
3561 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3563 if (strlen (filename
) > FILNMLEN
)
3565 /* Filename is too long to fit into an auxent,
3566 we stick it into the string table instead. We keep
3567 a linked list of the filenames we find so we can emit
3569 struct filename_list
*f
= ((struct filename_list
*)
3570 xmalloc (sizeof (struct filename_list
)));
3572 f
->filename
= filename
;
3575 SA_SET_FILE_FNAME_ZEROS (symbolP
, 0);
3576 SA_SET_FILE_FNAME_OFFSET (symbolP
, 1);
3578 if (filename_list_tail
)
3579 filename_list_tail
->next
= f
;
3581 filename_list_head
= f
;
3582 filename_list_tail
= f
;
3586 SA_SET_FILE_FNAME (symbolP
, filename
);
3593 listing_source_file (filename
);
3599 SF_SET_DEBUG (symbolP
);
3600 S_SET_VALUE (symbolP
, (valueT
) previous_file_symbol
);
3602 previous_file_symbol
= symbolP
;
3604 /* Make sure that the symbol is first on the symbol chain */
3605 if (symbol_rootP
!= symbolP
)
3607 symbol_remove (symbolP
, &symbol_rootP
, &symbol_lastP
);
3608 symbol_insert (symbolP
, symbol_rootP
, &symbol_rootP
, &symbol_lastP
);
3610 } /* c_dot_file_symbol() */
3613 * Build a 'section static' symbol.
3617 c_section_symbol (name
, idx
)
3623 symbolP
= symbol_new (name
, idx
,
3625 &zero_address_frag
);
3627 S_SET_STORAGE_CLASS (symbolP
, C_STAT
);
3628 S_SET_NUMBER_AUXILIARY (symbolP
, 1);
3630 SF_SET_STATICS (symbolP
);
3633 /* manfred@s-direktnet.de: section symbols *must* have the LOCAL bit cleared,
3634 which is set by the new definition of LOCAL_LABEL in tc-m68k.h. */
3635 SF_CLEAR_LOCAL (symbolP
);
3638 /* If the .linkonce pseudo-op was used for this section, we must
3639 store the information in the auxiliary entry for the section
3641 if (segment_info
[idx
].linkonce
!= LINKONCE_UNSET
)
3645 switch (segment_info
[idx
].linkonce
)
3649 case LINKONCE_DISCARD
:
3650 type
= IMAGE_COMDAT_SELECT_ANY
;
3652 case LINKONCE_ONE_ONLY
:
3653 type
= IMAGE_COMDAT_SELECT_NODUPLICATES
;
3655 case LINKONCE_SAME_SIZE
:
3656 type
= IMAGE_COMDAT_SELECT_SAME_SIZE
;
3658 case LINKONCE_SAME_CONTENTS
:
3659 type
= IMAGE_COMDAT_SELECT_EXACT_MATCH
;
3663 SYM_AUXENT (symbolP
)->x_scn
.x_comdat
= type
;
3668 } /* c_section_symbol() */
3671 w_symbols (abfd
, where
, symbol_rootP
)
3674 symbolS
* symbol_rootP
;
3679 /* First fill in those values we have only just worked out */
3680 for (i
= SEG_E0
; i
< SEG_LAST
; i
++)
3682 symbolP
= segment_info
[i
].dot
;
3685 SA_SET_SCN_SCNLEN (symbolP
, segment_info
[i
].scnhdr
.s_size
);
3686 SA_SET_SCN_NRELOC (symbolP
, segment_info
[i
].scnhdr
.s_nreloc
);
3687 SA_SET_SCN_NLINNO (symbolP
, segment_info
[i
].scnhdr
.s_nlnno
);
3692 * Emit all symbols left in the symbol chain.
3694 for (symbolP
= symbol_rootP
; symbolP
; symbolP
= symbol_next (symbolP
))
3696 /* Used to save the offset of the name. It is used to point
3697 to the string in memory but must be a file offset. */
3698 register char *temp
;
3700 /* We can't fix the lnnoptr field in yank_symbols with the other
3701 adjustments, because we have to wait until we know where they
3703 if (SF_GET_ADJ_LNNOPTR (symbolP
))
3705 SA_GET_SYM_LNNOPTR (symbolP
) +=
3706 segment_info
[S_GET_SEGMENT (symbolP
)].scnhdr
.s_lnnoptr
;
3709 tc_coff_symbol_emit_hook (symbolP
);
3711 temp
= S_GET_NAME (symbolP
);
3712 if (SF_GET_STRING (symbolP
))
3714 S_SET_OFFSET (symbolP
, symbolP
->sy_name_offset
);
3715 S_SET_ZEROES (symbolP
, 0);
3719 memset (symbolP
->sy_symbol
.ost_entry
.n_name
, 0, SYMNMLEN
);
3720 strncpy (symbolP
->sy_symbol
.ost_entry
.n_name
, temp
, SYMNMLEN
);
3722 where
= symbol_to_chars (abfd
, where
, symbolP
);
3723 S_SET_NAME (symbolP
, temp
);
3729 obj_coff_lcomm (ignore
)
3742 name
= input_line_pointer
;
3744 c
= get_symbol_end ();
3745 p
= input_line_pointer
;
3748 if (*input_line_pointer
!= ',')
3750 as_bad (_("Expected comma after name"));
3751 ignore_rest_of_line ();
3754 if (*input_line_pointer
== '\n')
3756 as_bad (_("Missing size expression"));
3759 input_line_pointer
++;
3760 if ((temp
= get_absolute_expression ()) < 0)
3762 as_warn (_("lcomm length (%d.) <0! Ignored."), temp
);
3763 ignore_rest_of_line ();
3768 symbolP
= symbol_find_or_make(name
);
3770 if (S_GET_SEGMENT(symbolP
) == SEG_UNKNOWN
&&
3771 S_GET_VALUE(symbolP
) == 0)
3776 segT current_seg
= now_seg
; /* save current seg */
3777 subsegT current_subseg
= now_subseg
;
3779 subseg_set (SEG_E2
, 1);
3780 symbolP
->sy_frag
= frag_now
;
3781 p
= frag_var(rs_org
, 1, 1, (relax_substateT
)0, symbolP
,
3782 (offsetT
) temp
, (char *) 0);
3784 subseg_set (current_seg
, current_subseg
); /* restore current seg */
3785 S_SET_SEGMENT(symbolP
, SEG_E2
);
3786 S_SET_STORAGE_CLASS(symbolP
, C_STAT
);
3790 as_bad(_("Symbol %s already defined"), name
);
3792 demand_empty_rest_of_line();
3797 fixup_mdeps (frags
, h
, this_segment
)
3802 subseg_change (this_segment
, 0);
3805 switch (frags
->fr_type
)
3811 HANDLE_ALIGN (frags
);
3813 frags
->fr_type
= rs_fill
;
3815 ((frags
->fr_next
->fr_address
- frags
->fr_address
- frags
->fr_fix
)
3818 case rs_machine_dependent
:
3819 md_convert_frag (h
, this_segment
, frags
);
3825 frags
= frags
->fr_next
;
3831 #ifndef TC_FORCE_RELOCATION
3832 #define TC_FORCE_RELOCATION(fix) 0
3836 fixup_segment (segP
, this_segment_type
)
3837 segment_info_type
* segP
;
3838 segT this_segment_type
;
3840 register fixS
* fixP
;
3841 register symbolS
*add_symbolP
;
3842 register symbolS
*sub_symbolP
;
3845 register char *place
;
3846 register long where
;
3847 register char pcrel
;
3848 register fragS
*fragP
;
3849 register segT add_symbol_segment
= absolute_section
;
3851 for (fixP
= segP
->fix_root
; fixP
; fixP
= fixP
->fx_next
)
3853 fragP
= fixP
->fx_frag
;
3855 where
= fixP
->fx_where
;
3856 place
= fragP
->fr_literal
+ where
;
3857 size
= fixP
->fx_size
;
3858 add_symbolP
= fixP
->fx_addsy
;
3859 sub_symbolP
= fixP
->fx_subsy
;
3860 add_number
= fixP
->fx_offset
;
3861 pcrel
= fixP
->fx_pcrel
;
3863 /* We want function-relative stabs to work on systems which
3864 may use a relaxing linker; thus we must handle the sym1-sym2
3865 fixups function-relative stabs generates.
3867 Of course, if you actually enable relaxing in the linker, the
3868 line and block scoping information is going to be incorrect
3869 in some cases. The only way to really fix this is to support
3870 a reloc involving the difference of two symbols. */
3872 && (!sub_symbolP
|| pcrel
))
3876 if (fixP
->fx_tcbit
&& SF_GET_CALLNAME (add_symbolP
))
3878 /* Relocation should be done via the associated 'bal' entry
3881 if (!SF_GET_BALNAME (tc_get_bal_of_call (add_symbolP
)))
3883 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3884 _("No 'bal' entry point for leafproc %s"),
3885 S_GET_NAME (add_symbolP
));
3888 fixP
->fx_addsy
= add_symbolP
= tc_get_bal_of_call (add_symbolP
);
3892 /* Make sure the symbols have been resolved; this may not have
3893 happened if these are expression symbols. */
3894 if (add_symbolP
!= NULL
&& ! add_symbolP
->sy_resolved
)
3895 resolve_symbol_value (add_symbolP
, 1);
3897 if (add_symbolP
!= NULL
)
3899 /* If this fixup is against a symbol which has been equated
3900 to another symbol, convert it to the other symbol. */
3901 if (add_symbolP
->sy_value
.X_op
== O_symbol
3902 && (! S_IS_DEFINED (add_symbolP
)
3903 || S_IS_COMMON (add_symbolP
)))
3905 while (add_symbolP
->sy_value
.X_op
== O_symbol
3906 && (! S_IS_DEFINED (add_symbolP
)
3907 || S_IS_COMMON (add_symbolP
)))
3911 /* We must avoid looping, as that can occur with a
3912 badly written program. */
3913 n
= add_symbolP
->sy_value
.X_add_symbol
;
3914 if (n
== add_symbolP
)
3916 add_number
+= add_symbolP
->sy_value
.X_add_number
;
3919 fixP
->fx_addsy
= add_symbolP
;
3920 fixP
->fx_offset
= add_number
;
3924 if (sub_symbolP
!= NULL
&& ! sub_symbolP
->sy_resolved
)
3925 resolve_symbol_value (sub_symbolP
, 1);
3927 if (add_symbolP
!= NULL
3928 && add_symbolP
->sy_mri_common
)
3930 know (add_symbolP
->sy_value
.X_op
== O_symbol
);
3931 add_number
+= S_GET_VALUE (add_symbolP
);
3932 fixP
->fx_offset
= add_number
;
3933 add_symbolP
= fixP
->fx_addsy
= add_symbolP
->sy_value
.X_add_symbol
;
3938 add_symbol_segment
= S_GET_SEGMENT (add_symbolP
);
3939 } /* if there is an addend */
3943 if (add_symbolP
== NULL
|| add_symbol_segment
== absolute_section
)
3945 if (add_symbolP
!= NULL
)
3947 add_number
+= S_GET_VALUE (add_symbolP
);
3949 fixP
->fx_addsy
= NULL
;
3952 /* It's just -sym. */
3953 if (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)
3955 add_number
-= S_GET_VALUE (sub_symbolP
);
3962 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3963 _("Negative of non-absolute symbol %s"),
3964 S_GET_NAME (sub_symbolP
));
3966 add_number
-= S_GET_VALUE (sub_symbolP
);
3967 } /* not absolute */
3969 /* if sub_symbol is in the same segment that add_symbol
3970 and add_symbol is either in DATA, TEXT, BSS or ABSOLUTE */
3972 else if (S_GET_SEGMENT (sub_symbolP
) == add_symbol_segment
3973 && SEG_NORMAL (add_symbol_segment
))
3975 /* Difference of 2 symbols from same segment. Can't
3976 make difference of 2 undefineds: 'value' means
3977 something different for N_UNDF. */
3979 /* Makes no sense to use the difference of 2 arbitrary symbols
3980 as the target of a call instruction. */
3983 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3984 _("callj to difference of 2 symbols"));
3986 #endif /* TC_I960 */
3987 add_number
+= S_GET_VALUE (add_symbolP
) -
3988 S_GET_VALUE (sub_symbolP
);
3991 if (!TC_FORCE_RELOCATION (fixP
))
3993 fixP
->fx_addsy
= NULL
;
3994 fixP
->fx_subsy
= NULL
;
3996 #ifdef TC_M68K /* is this right? */
4004 /* Different segments in subtraction. */
4005 know (!(S_IS_EXTERNAL (sub_symbolP
) && (S_GET_SEGMENT (sub_symbolP
) == absolute_section
)));
4007 if ((S_GET_SEGMENT (sub_symbolP
) == absolute_section
))
4009 add_number
-= S_GET_VALUE (sub_symbolP
);
4012 else if (S_GET_SEGMENT (sub_symbolP
) == this_segment_type
4013 #if 0 /* Okay for 68k, at least... */
4018 /* Make it pc-relative. */
4019 add_number
+= (md_pcrel_from (fixP
)
4020 - S_GET_VALUE (sub_symbolP
));
4029 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4030 _("Can't emit reloc {- %s-seg symbol \"%s\"} @ file address %ld."),
4031 segment_name (S_GET_SEGMENT (sub_symbolP
)),
4032 S_GET_NAME (sub_symbolP
),
4033 (long) (fragP
->fr_address
+ where
));
4036 } /* if sub_symbolP */
4040 if (add_symbol_segment
== this_segment_type
&& pcrel
)
4043 * This fixup was made when the symbol's segment was
4044 * SEG_UNKNOWN, but it is now in the local segment.
4045 * So we know how to do the address without relocation.
4048 /* reloc_callj() may replace a 'call' with a 'calls' or a 'bal',
4049 * in which cases it modifies *fixP as appropriate. In the case
4050 * of a 'calls', no further work is required, and *fixP has been
4051 * set up to make the rest of the code below a no-op.
4054 #endif /* TC_I960 */
4056 add_number
+= S_GET_VALUE (add_symbolP
);
4057 add_number
-= md_pcrel_from (fixP
);
4060 add_number -= segP->scnhdr.s_vaddr;
4061 if defined (TC_I386) || defined (TE_LYNX). I now
4062 think that was an error propagated from the case when
4063 we are going to emit the relocation. If we are not
4064 going to emit the relocation, then we just want to
4065 set add_number to the difference between the symbols.
4066 This is a case that would only arise when there is a
4067 PC relative reference from a section other than .text
4068 to a symbol defined in the same section, and the
4069 reference is not relaxed. Since jump instructions on
4070 the i386 are relaxed, this could only arise with a
4071 call instruction. */
4073 pcrel
= 0; /* Lie. Don't want further pcrel processing. */
4074 if (!TC_FORCE_RELOCATION (fixP
))
4076 fixP
->fx_addsy
= NULL
;
4082 switch (add_symbol_segment
)
4084 case absolute_section
:
4086 reloc_callj (fixP
); /* See comment about reloc_callj() above*/
4087 #endif /* TC_I960 */
4088 add_number
+= S_GET_VALUE (add_symbolP
);
4091 if (!TC_FORCE_RELOCATION (fixP
))
4093 fixP
->fx_addsy
= NULL
;
4100 #if defined(TC_A29K) || (defined(TE_PE) && defined(TC_I386)) || defined(TC_M88K)
4101 /* This really should be handled in the linker, but
4102 backward compatibility forbids. */
4103 add_number
+= S_GET_VALUE (add_symbolP
);
4105 add_number
+= S_GET_VALUE (add_symbolP
) +
4106 segment_info
[S_GET_SEGMENT (add_symbolP
)].scnhdr
.s_paddr
;
4112 if ((int) fixP
->fx_bit_fixP
== 13)
4114 /* This is a COBR instruction. They have only a
4115 * 13-bit displacement and are only to be used
4116 * for local branches: flag as error, don't generate
4119 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4120 _("can't use COBR format with external label"));
4121 fixP
->fx_addsy
= NULL
;
4125 #endif /* TC_I960 */
4126 #if ((defined (TC_I386) || defined (TE_LYNX) || defined (TE_AUX)) && !defined(TE_PE)) || defined (COFF_COMMON_ADDEND)
4127 /* 386 COFF uses a peculiar format in which the
4128 value of a common symbol is stored in the .text
4129 segment (I've checked this on SVR3.2 and SCO
4130 3.2.2) Ian Taylor <ian@cygnus.com>. */
4131 /* This is also true for 68k COFF on sysv machines
4132 (Checked on Motorola sysv68 R3V6 and R3V7.1, and also on
4133 UNIX System V/M68000, Release 1.0 from ATT/Bell Labs)
4134 Philippe De Muyter <phdm@info.ucl.ac.be>. */
4135 if (S_IS_COMMON (add_symbolP
))
4136 add_number
+= S_GET_VALUE (add_symbolP
);
4141 } /* switch on symbol seg */
4142 } /* if not in local seg */
4143 } /* if there was a + symbol */
4147 #if !defined(TC_M88K) && !(defined(TE_PE) && defined(TC_I386)) && !defined(TC_A29K)
4148 /* This adjustment is not correct on the m88k, for which the
4149 linker does all the computation. */
4150 add_number
-= md_pcrel_from (fixP
);
4152 if (add_symbolP
== 0)
4154 fixP
->fx_addsy
= &abs_symbol
;
4155 } /* if there's an add_symbol */
4156 #if defined (TC_I386) || defined (TE_LYNX) || defined (TC_I960) || defined (TC_M68K)
4157 /* On the 386 we must adjust by the segment vaddr as well.
4160 I changed the i960 to work this way as well. This is
4161 compatible with the current GNU linker behaviour. I do
4162 not know what other i960 COFF assemblers do. This is not
4163 a common case: normally, only assembler code will contain
4164 a PC relative reloc, and only branches which do not
4165 originate in the .text section will have a non-zero
4168 I changed the m68k to work this way as well. This will
4169 break existing PC relative relocs from sections which do
4170 not start at address 0, but it will make ld -r work.
4171 Ian Taylor, 4 Oct 96. */
4173 add_number
-= segP
->scnhdr
.s_vaddr
;
4177 if (!fixP
->fx_bit_fixP
&& ! fixP
->fx_no_overflow
)
4180 /* The m88k uses the offset field of the reloc to get around
4183 && ((add_number
& ~0xFF)
4184 || (fixP
->fx_signed
&& (add_number
& 0x80)))
4185 && ((add_number
& ~0xFF) != (-1 & ~0xFF)
4186 || (add_number
& 0x80) == 0))
4188 && ((add_number
& ~0xFFFF)
4189 || (fixP
->fx_signed
&& (add_number
& 0x8000)))
4190 && ((add_number
& ~0xFFFF) != (-1 & ~0xFFFF)
4191 || (add_number
& 0x8000) == 0)))
4193 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4194 _("Value of %ld too large for field of %d bytes at 0x%lx"),
4195 (long) add_number
, size
,
4196 (unsigned long) (fragP
->fr_address
+ where
));
4199 #ifdef WARN_SIGNED_OVERFLOW_WORD
4200 /* Warn if a .word value is too large when treated as a
4201 signed number. We already know it is not too negative.
4202 This is to catch over-large switches generated by gcc on
4204 if (!flag_signed_overflow_ok
4206 && add_number
> 0x7fff)
4207 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
4208 _("Signed .word overflow; switch may be too large; %ld at 0x%lx"),
4210 (unsigned long) (fragP
->fr_address
+ where
));
4212 } /* not a bit fix */
4213 /* Once this fix has been applied, we don't have to output
4214 anything nothing more need be done. */
4215 #ifdef MD_APPLY_FIX3
4216 md_apply_fix3 (fixP
, (valueT
*) &add_number
, this_segment_type
);
4218 md_apply_fix (fixP
, add_number
);
4220 } /* For each fixS in this segment. */
4221 } /* fixup_segment() */
4225 /* The first entry in a .stab section is special. */
4228 obj_coff_init_stab_section (seg
)
4234 unsigned int stroff
;
4236 /* Make space for this first symbol. */
4240 as_where (&file
, (unsigned int *) NULL
);
4241 stabstr_name
= (char *) alloca (strlen (segment_info
[seg
].name
) + 4);
4242 strcpy (stabstr_name
, segment_info
[seg
].name
);
4243 strcat (stabstr_name
, "str");
4244 stroff
= get_stab_string_offset (file
, stabstr_name
);
4246 md_number_to_chars (p
, stroff
, 4);
4249 /* Fill in the counts in the first entry in a .stab section. */
4252 adjust_stab_section(abfd
, seg
)
4256 segT stabstrseg
= SEG_UNKNOWN
;
4257 const char *secname
, *name2
;
4260 int i
, strsz
= 0, nsyms
;
4261 fragS
*frag
= segment_info
[seg
].frchainP
->frch_root
;
4263 /* Look for the associated string table section. */
4265 secname
= segment_info
[seg
].name
;
4266 name
= (char *) alloca (strlen (secname
) + 4);
4267 strcpy (name
, secname
);
4268 strcat (name
, "str");
4270 for (i
= SEG_E0
; i
< SEG_UNKNOWN
; i
++)
4272 name2
= segment_info
[i
].name
;
4273 if (name2
!= NULL
&& strncmp(name2
, name
, 8) == 0)
4280 /* If we found the section, get its size. */
4281 if (stabstrseg
!= SEG_UNKNOWN
)
4282 strsz
= size_section (abfd
, stabstrseg
);
4284 nsyms
= size_section (abfd
, seg
) / 12 - 1;
4286 /* Look for the first frag of sufficient size for the initial stab
4287 symbol, and collect a pointer to it. */
4288 while (frag
&& frag
->fr_fix
< 12)
4289 frag
= frag
->fr_next
;
4291 p
= frag
->fr_literal
;
4294 /* Write in the number of stab symbols and the size of the string
4296 bfd_h_put_16 (abfd
, (bfd_vma
) nsyms
, (bfd_byte
*) p
+ 6);
4297 bfd_h_put_32 (abfd
, (bfd_vma
) strsz
, (bfd_byte
*) p
+ 8);
4300 #endif /* not BFD_ASSEMBLER */
4302 const pseudo_typeS obj_pseudo_table
[] =
4304 {"def", obj_coff_def
, 0},
4305 {"dim", obj_coff_dim
, 0},
4306 {"endef", obj_coff_endef
, 0},
4307 {"line", obj_coff_line
, 0},
4308 {"ln", obj_coff_ln
, 0},
4309 {"appline", obj_coff_ln
, 1},
4310 {"scl", obj_coff_scl
, 0},
4311 {"size", obj_coff_size
, 0},
4312 {"tag", obj_coff_tag
, 0},
4313 {"type", obj_coff_type
, 0},
4314 {"val", obj_coff_val
, 0},
4315 {"section", obj_coff_section
, 0},
4316 {"sect", obj_coff_section
, 0},
4317 /* FIXME: We ignore the MRI short attribute. */
4318 {"section.s", obj_coff_section
, 0},
4319 {"sect.s", obj_coff_section
, 0},
4320 /* We accept the .bss directive for backward compatibility with
4321 earlier versions of gas. */
4322 {"bss", obj_coff_bss
, 0},
4323 #ifndef BFD_ASSEMBLER
4324 {"use", obj_coff_section
, 0},
4325 {"text", obj_coff_text
, 0},
4326 {"data", obj_coff_data
, 0},
4327 {"lcomm", obj_coff_lcomm
, 0},
4328 {"ident", obj_coff_ident
, 0},
4330 {"optim", s_ignore
, 0}, /* For sun386i cc (?) */
4331 {"ident", s_ignore
, 0}, /* we don't yet handle this. */
4333 {"version", s_ignore
, 0},
4334 {"ABORT", s_abort
, 0},
4336 /* The m88k uses sdef instead of def. */
4337 {"sdef", obj_coff_def
, 0},
4339 {NULL
} /* end sentinel */
4340 }; /* obj_pseudo_table */
4342 #ifdef BFD_ASSEMBLER
4344 /* Support for a COFF emulation. */
4349 pop_insert (obj_pseudo_table
);
4353 coff_sec_sym_ok_for_reloc (sec
)
4365 const struct format_ops coff_format_ops
=
4367 bfd_target_coff_flavour
,
4372 coff_frob_file_after_relocs
,
4377 obj_generate_asm_lineno
,
4386 coff_sec_sym_ok_for_reloc
,
4393 coff_obj_read_begin_hook
,
4394 coff_obj_symbol_new_hook
,